diff options
Diffstat (limited to 'btif')
-rw-r--r-- | btif/co/bta_hh_co.c | 169 | ||||
-rw-r--r-- | btif/include/btif_common.h | 2 | ||||
-rw-r--r-- | btif/include/btif_hh.h | 4 | ||||
-rw-r--r-- | btif/src/btif_config.c | 120 | ||||
-rw-r--r-- | btif/src/btif_config_util.cpp | 2 | ||||
-rw-r--r-- | btif/src/btif_hh.c | 51 | ||||
-rw-r--r-- | btif/src/btif_pan.c | 136 | ||||
-rw-r--r-- | btif/src/btif_sock.c | 39 | ||||
-rw-r--r-- | btif/src/btif_sock_rfc.c | 20 | ||||
-rw-r--r-- | btif/src/btif_sock_sdp.c | 8 | ||||
-rw-r--r-- | btif/src/btif_sock_util.c | 17 | ||||
-rwxr-xr-x | btif/src/btif_storage.c | 31 |
12 files changed, 406 insertions, 193 deletions
diff --git a/btif/co/bta_hh_co.c b/btif/co/bta_hh_co.c index 81414d2..b4ea4c2 100644 --- a/btif/co/bta_hh_co.c +++ b/btif/co/bta_hh_co.c @@ -20,6 +20,8 @@ #include <ctype.h> #include <fcntl.h> +#include <sys/poll.h> +#include <pthread.h> #include <stdio.h> #include <string.h> #include <stdint.h> @@ -41,7 +43,7 @@ static int uhid_write(int fd, const struct uhid_event *ev) ret = write(fd, ev, sizeof(*ev)); if (ret < 0){ int rtn = -errno; - APPL_TRACE_ERROR2("%s: Cannot write to uhid:%s",__FUNCTION__,strerror(errno)); + APPL_TRACE_ERROR2("%s: Cannot write to uhid:%s", __FUNCTION__, strerror(errno)); return rtn; } else if (ret != sizeof(*ev)) { APPL_TRACE_ERROR3("%s: Wrong size written to uhid: %ld != %lu", @@ -52,6 +54,144 @@ static int uhid_write(int fd, const struct uhid_event *ev) } } +/* Internal function to parse the events received from UHID driver*/ +static int uhid_event(btif_hh_device_t *p_dev) +{ + struct uhid_event ev; + ssize_t ret; + memset(&ev, 0, sizeof(ev)); + if(!p_dev) + APPL_TRACE_ERROR1("%s: Device not found",__FUNCTION__) + ret = read(p_dev->fd, &ev, sizeof(ev)); + if (ret == 0) { + APPL_TRACE_ERROR2("%s: Read HUP on uhid-cdev %s", __FUNCTION__, + strerror(errno)); + return -EFAULT; + } else if (ret < 0) { + APPL_TRACE_ERROR2("%s:Cannot read uhid-cdev: %s", __FUNCTION__, + strerror(errno)); + return -errno; + } else if (ret != sizeof(ev)) { + APPL_TRACE_ERROR3("%s:Invalid size read from uhid-dev: %ld != %lu", + __FUNCTION__, ret, sizeof(ev)); + return -EFAULT; + } + + switch (ev.type) { + case UHID_START: + APPL_TRACE_DEBUG0("UHID_START from uhid-dev\n"); + break; + case UHID_STOP: + APPL_TRACE_DEBUG0("UHID_STOP from uhid-dev\n"); + break; + case UHID_OPEN: + APPL_TRACE_DEBUG0("UHID_OPEN from uhid-dev\n"); + break; + case UHID_CLOSE: + APPL_TRACE_DEBUG0("UHID_CLOSE from uhid-dev\n"); + break; + case UHID_OUTPUT: + APPL_TRACE_DEBUG0("UHID_OUTPUT from uhid-dev\n"); + APPL_TRACE_DEBUG2("UHID_OUTPUT: Report type = %d, report_size = %d" + ,ev.u.output.rtype, ev.u.output.size); + //Send SET_REPORT with feature report if the report type in output event is FEATURE + if(ev.u.output.rtype == UHID_FEATURE_REPORT) + btif_hh_setreport(p_dev,BTHH_FEATURE_REPORT,ev.u.output.size,ev.u.output.data); + else if(ev.u.output.rtype == UHID_OUTPUT_REPORT) + btif_hh_setreport(p_dev,BTHH_OUTPUT_REPORT,ev.u.output.size,ev.u.output.data); + else + btif_hh_setreport(p_dev,BTHH_INPUT_REPORT,ev.u.output.size,ev.u.output.data); + break; + case UHID_OUTPUT_EV: + APPL_TRACE_DEBUG0("UHID_OUTPUT_EV from uhid-dev\n"); + break; + case UHID_FEATURE: + APPL_TRACE_DEBUG0("UHID_FEATURE from uhid-dev\n"); + break; + case UHID_FEATURE_ANSWER: + APPL_TRACE_DEBUG0("UHID_FEATURE_ANSWER from uhid-dev\n"); + break; + + default: + APPL_TRACE_DEBUG1("Invalid event from uhid-dev: %u\n", ev.type); + } + + return 0; +} + +/******************************************************************************* +** +** Function create_thread +** +** Description creat a select loop +** +** Returns pthread_t +** +*******************************************************************************/ +static inline pthread_t create_thread(void *(*start_routine)(void *), void * arg){ + APPL_TRACE_DEBUG0("create_thread: entered"); + pthread_attr_t thread_attr; + + pthread_attr_init(&thread_attr); + pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE); + pthread_t thread_id = -1; + if ( pthread_create(&thread_id, &thread_attr, start_routine, arg)!=0 ) + { + APPL_TRACE_ERROR1("pthread_create : %s", strerror(errno)); + return -1; + } + APPL_TRACE_DEBUG0("create_thread: thread created successfully"); + return thread_id; +} + +/******************************************************************************* +** +** Function btif_hh_poll_event_thread +** +** Description the polling thread which polls for event from UHID driver +** +** Returns void +** +*******************************************************************************/ +static void *btif_hh_poll_event_thread(void *arg) +{ + + btif_hh_device_t *p_dev = arg; + APPL_TRACE_DEBUG2("%s: Thread created fd = %d", __FUNCTION__, p_dev->fd); + struct pollfd pfds[1]; + int ret; + pfds[0].fd = p_dev->fd; + pfds[0].events = POLLIN; + + while(p_dev->hh_keep_polling){ + ret = poll(pfds, 1, 500); + if (ret < 0) { + APPL_TRACE_ERROR2("%s: Cannot poll for fds: %s\n", __FUNCTION__, strerror(errno)); + break; + } + if (pfds[0].revents & POLLIN) { + APPL_TRACE_DEBUG0("btif_hh_poll_event_thread: POLLIN"); + ret = uhid_event(p_dev); + if (ret){ + break; + } + } + } + + p_dev->hh_poll_thread_id = -1; + return 0; +} + +static inline void btif_hh_close_poll_thread(btif_hh_device_t *p_dev) +{ + APPL_TRACE_DEBUG1("%s", __FUNCTION__); + p_dev->hh_keep_polling = 0; + if(p_dev->hh_poll_thread_id > 0) + pthread_join(p_dev->hh_poll_thread_id,NULL); + + return; +} + void bta_hh_co_destroy(int fd) { struct uhid_event ev; @@ -119,7 +259,8 @@ void bta_hh_co_open(UINT8 dev_handle, UINT8 sub_class, tBTA_HH_ATTR_MASK attr_ma }else APPL_TRACE_DEBUG2("%s: uhid fd = %d", __FUNCTION__, p_dev->fd); } - + p_dev->hh_keep_polling = 1; + p_dev->hh_poll_thread_id = create_thread(btif_hh_poll_event_thread, p_dev); break; } p_dev = NULL; @@ -141,8 +282,11 @@ void bta_hh_co_open(UINT8 dev_handle, UINT8 sub_class, tBTA_HH_ATTR_MASK attr_ma if (p_dev->fd < 0){ APPL_TRACE_ERROR2("%s: Error: failed to open uhid, err:%s", __FUNCTION__,strerror(errno)); - }else + }else{ APPL_TRACE_DEBUG2("%s: uhid fd = %d", __FUNCTION__, p_dev->fd); + p_dev->hh_keep_polling = 1; + p_dev->hh_poll_thread_id = create_thread(btif_hh_poll_event_thread, p_dev); + } break; @@ -174,7 +318,26 @@ void bta_hh_co_open(UINT8 dev_handle, UINT8 sub_class, tBTA_HH_ATTR_MASK attr_ma *******************************************************************************/ void bta_hh_co_close(UINT8 dev_handle, UINT8 app_id) { + UINT32 i; + btif_hh_device_t *p_dev = NULL; + APPL_TRACE_WARNING3("%s: dev_handle = %d, app_id = %d", __FUNCTION__, dev_handle, app_id); + if (dev_handle == BTA_HH_INVALID_HANDLE) { + APPL_TRACE_WARNING2("%s: Oops, dev_handle (%d) is invalid...", __FUNCTION__, dev_handle); + return; + } + + for (i = 0; i < BTIF_HH_MAX_HID; i++) { + p_dev = &btif_hh_cb.devices[i]; + if (p_dev->dev_status != BTHH_CONN_STATE_UNKNOWN && p_dev->dev_handle == dev_handle) { + APPL_TRACE_WARNING3("%s: Found an existing device with the same handle " + "dev_status = %d, dev_handle =%d",__FUNCTION__, + p_dev->dev_status,p_dev->dev_handle); + btif_hh_close_poll_thread(p_dev); + break; + } + } + } diff --git a/btif/include/btif_common.h b/btif/include/btif_common.h index 7f3b039..6bf885f 100644 --- a/btif/include/btif_common.h +++ b/btif/include/btif_common.h @@ -54,7 +54,7 @@ extern bt_callbacks_t *bt_hal_cbacks; #define HAL_CBACK(P_CB, P_CBACK, ...)\ if (P_CB && P_CB->P_CBACK) { \ - ALOGD("HAL %s->%s", #P_CB, #P_CBACK); \ + BTIF_TRACE_API2("HAL %s->%s", #P_CB, #P_CBACK); \ P_CB->P_CBACK(__VA_ARGS__); \ } \ else { \ diff --git a/btif/include/btif_hh.h b/btif/include/btif_hh.h index 4f31002..25063eb 100644 --- a/btif/include/btif_hh.h +++ b/btif/include/btif_hh.h @@ -62,6 +62,8 @@ typedef struct UINT8 app_id; int fd; BT_HDR *p_buf; + UINT32 hh_poll_thread_id; + UINT8 hh_keep_polling; } btif_hh_device_t; /* Control block to maintain properties of devices */ @@ -96,6 +98,8 @@ extern btif_hh_device_t *btif_hh_find_connected_dev_by_handle(UINT8 handle); extern void btif_hh_remove_device(bt_bdaddr_t bd_addr); extern bt_status_t btif_hh_virtual_unplug(bt_bdaddr_t *bd_addr); extern void btif_hh_disconnect(bt_bdaddr_t *bd_addr); +extern void btif_hh_setreport(btif_hh_device_t *p_dev, bthh_report_type_t r_type, + UINT16 size, UINT8* report); BOOLEAN btif_hh_add_added_dev(bt_bdaddr_t bd_addr, tBTA_HH_ATTR_MASK attr_mask); diff --git a/btif/src/btif_config.c b/btif/src/btif_config.c index 00e40bd..356cee0 100644 --- a/btif/src/btif_config.c +++ b/btif/src/btif_config.c @@ -41,20 +41,16 @@ #include <stdlib.h> #include <private/android_filesystem_config.h> -#define LOG_TAG "btif_config.c" +#define LOG_TAG "btif_config" #include <hardware/bluetooth.h> +#include "btif_api.h" #include "btif_config.h" #include "btif_config_util.h" #include "btif_sock_thread.h" #include "btif_sock_util.h" -#include <cutils/log.h> -#define info(fmt, ...) ALOGI ("%s(L%d): " fmt,__FUNCTION__, __LINE__, ## __VA_ARGS__) -#define debug(fmt, ...) ALOGD ("%s(L%d): " fmt,__FUNCTION__, __LINE__, ## __VA_ARGS__) -#define warn(fmt, ...) ALOGW ("## WARNING : %s(L%d): " fmt "##",__FUNCTION__, __LINE__, ## __VA_ARGS__) -#define error(fmt, ...) ALOGE ("## ERROR : %s(L%d): " fmt "##",__FUNCTION__, __LINE__, ## __VA_ARGS__) -#define asrt(s) if(!(s)) ALOGE ("## %s assert %s failed at line:%d ##",__FUNCTION__, #s, __LINE__) +#define asrt(s) if(!(s)) BTIF_TRACE_ERROR3 ("## %s assert %s failed at line:%d ##",__FUNCTION__, #s, __LINE__) //#define UNIT_TEST #define CFG_PATH "/data/misc/bluedroid/" #define CFG_FILE_NAME "bt_config" @@ -112,22 +108,24 @@ static void cfg_test_read(); #endif static inline void dump_node(const char* title, const cfg_node* p) { - if(p) - debug("%s, p->name:%s, child/value:%p, bytes:%d, p->used:%d, type:%x, p->flag:%d", - title, p->name, p->child, p->bytes, p->used, p->type, p->flag); - else debug("%s is NULL", title); + if(p) { + BTIF_TRACE_DEBUG4("%s, p->name:%s, child/value:%p, bytes:%d", + title, p->name, p->child, p->bytes); + BTIF_TRACE_DEBUG3("p->used:%d, type:%x, p->flag:%d", + p->used, p->type, p->flag); + } else BTIF_TRACE_DEBUG1("%s is NULL", title); } //////////////////////////////////////////////////////////////////////////////////////////////////////////// int btif_config_init() { static int initialized; - debug("in initialized:%d", initialized); + BTIF_TRACE_DEBUG1("in initialized:%d", initialized); if(!initialized) { initialized = 1; struct stat st; if(stat(CFG_PATH, &st) != 0) - error("%s does not exist, need provision", CFG_PATH); + BTIF_TRACE_ERROR1("%s does not exist, need provision", CFG_PATH); btsock_thread_init(); init_slot_lock(&slot_lock); lock_slot(&slot_lock); @@ -180,8 +178,6 @@ int btif_config_exist(const char* section, const char* key, const char* name) } int btif_config_get(const char* section, const char* key, const char* name, char* value, int* bytes, int* type) { - //debug("in"); - int ret = FALSE; asrt(section && *section && key && *key && name && *name && bytes && type); //debug("section:%s, key:%s, name:%s, value:%p, bytes:%d, type:%d", @@ -204,9 +200,11 @@ int btif_config_get(const char* section, const char* key, const char* name, char if(ret != TRUE) { if(*type != node->type) - error("value:%s, wrong type:%d, need to be type: %d", name, *type, node->type); + BTIF_TRACE_ERROR3("value:%s, wrong type:%d, need to be type: %d", + name, *type, node->type); if(value && *bytes < node->used) - error("value:%s, not enough size: %d bytes, need %d bytes", name, node->used, *bytes); + BTIF_TRACE_ERROR3("value:%s, not enough size: %d bytes, need %d bytes", + name, node->used, *bytes); } } unlock_slot(&slot_lock); @@ -354,7 +352,7 @@ static inline short alloc_node(cfg_node* p, short grow) //debug("out"); return old_bytes;//return the previous size } - else error("realloc failed, old_bytes:%d, grow:%d, total:%d", p->bytes, grow, p->bytes + grow); + else BTIF_TRACE_ERROR3("realloc failed, old_bytes:%d, grow:%d, total:%d", p->bytes, grow, p->bytes + grow); } //debug("out, alloc failed"); return -1; @@ -462,7 +460,7 @@ static int set_node(const char* section, const char* key, const char* name, value_node->bytes = bytes; else { - error("not enough memory!"); + BTIF_TRACE_ERROR0("not enough memory!"); value_node->bytes = 0; return FALSE; } @@ -575,7 +573,6 @@ static int remove_node(const char* section, const char* key, const char* name) } static int save_cfg() { - debug("in"); const char* file_name = CFG_PATH CFG_FILE_NAME CFG_FILE_EXT; const char* file_name_new = CFG_PATH CFG_FILE_NAME CFG_FILE_EXT_NEW; const char* file_name_old = CFG_PATH CFG_FILE_NAME CFG_FILE_EXT_OLD; @@ -593,8 +590,7 @@ static int save_cfg() rename(file_name_new, file_name); ret = TRUE; } - else error("btif_config_save_file failed"); - debug("out"); + else BTIF_TRACE_ERROR0("btif_config_save_file failed"); return ret; } @@ -612,6 +608,45 @@ static void remove_bluez_cfg() { rename(BLUEZ_PATH, BLUEZ_PATH_BAK); } +static void clean_newline_char() +{ + char kname[128], vname[128]; + short kpos = 0; + int kname_size, vname_size; + vname[0] = 0; + vname_size = sizeof(vname); + //BTIF_TRACE_DEBUG0("removing newline at the end of the adapter and device name"); + if(btif_config_get_str("Local", "Adapter", "Name", vname, &vname_size) && + vname_size > 2) + { + if(vname[vname_size - 2] == '\n') + { + BTIF_TRACE_DEBUG1("remove newline at the end of the adapter name:%s", vname); + vname[vname_size - 2] = 0; + btif_config_set_str("Local", "Adapter", "Name", vname); + } + } + do + { + kname_size = sizeof(kname); + kname[0] = 0; + kpos = btif_config_next_key(kpos, "Remote", kname, &kname_size); + //BTIF_TRACE_DEBUG2("Remote device:%s, size:%d", kname, kname_size); + vname_size = sizeof(vname); + vname[0] = 0; + if(btif_config_get_str("Remote", kname, "Name", vname, &vname_size) && + vname_size > 2) + { + BTIF_TRACE_DEBUG1("remote device name:%s", vname); + if(vname[vname_size - 2] == '\n') + { + BTIF_TRACE_DEBUG1("remove newline at the end of the device name:%s", vname); + vname[vname_size - 2] = 0; + btif_config_set_str("Remote", kname, "Name", vname); + } + } + } while(kpos != -1); +} static void load_cfg() { const char* file_name = CFG_PATH CFG_FILE_NAME CFG_FILE_EXT; @@ -627,10 +662,19 @@ static void load_cfg() remove_bluez_cfg(); } } + int bluez_migration_done = 0; + btif_config_get_int("Local", "Adapter", "BluezMigrationDone", &bluez_migration_done); + if(!bluez_migration_done) + { + //clean the new line char at the end of the device name. Caused by bluez config import bug + clean_newline_char(); + btif_config_set_int("Local", "Adapter", "BluezMigrationDone", 1); + btif_config_save(); + } } static void cfg_cmd_callback(int cmd_fd, int type, int size, uint32_t user_id) { - debug("cmd type:%d, size:%d", type, size); + //BTIF_TRACE_DEBUG2("cmd type:%d, size:%d", type, size); switch(type) { case CFG_CMD_SAVE: @@ -647,15 +691,14 @@ static void cfg_test_load() char kname[128], vname[128]; short kpos, vpos; int kname_size, vname_size; - debug("in"); - debug("list all remote devices values:"); + BTIF_TRACE_DEBUG0("list all remote devices values:"); kname_size = sizeof(kname); kname[0] = 0; kpos = 0; do { kpos = btif_config_next_key(kpos, "Remote Devices", kname, &kname_size); - debug("Remote devices:%s, size:%d", kname, kname_size); + BTIF_TRACE_DEBUG2("Remote devices:%s, size:%d", kname, kname_size); vpos = 0; vname[0] = 0; vname_size = sizeof(vname); @@ -665,8 +708,8 @@ static void cfg_test_load() int vtype = BTIF_CFG_TYPE_STR; int vsize = sizeof(v); int ret = btif_config_get("Remote Devices", kname, vname, v, &vsize, &vtype); - debug("btif_config_get return:%d, Remote devices:%s, value name:%s, value:%s, value size:%d, type:0x%x", - ret, kname, vname, v, vsize, vtype); + BTIF_TRACE_DEBUG6("btif_config_get return:%d, Remote devices:%s, value name:%s, value:%s, value size:%d, type:0x%x", + ret, kname, vname, v, vsize, vtype); vname[0] = 0; vname_size = sizeof(vname); @@ -674,11 +717,9 @@ static void cfg_test_load() kname[0] = 0; kname_size = sizeof(kname); } while(kpos != -1); - debug("out"); } static void cfg_test_write() { - debug("in"); int i; char key[128]; @@ -696,11 +737,10 @@ static void cfg_test_write() btif_config_set_int(section, key, "connect time out", i); } btif_config_save(); - debug("out"); } static void cfg_test_read() { - debug("in"); + //debug("in"); char class[128] = {0}; char link_key[128] = {0}; int size, type; @@ -713,32 +753,32 @@ static void cfg_test_read() section = "Remote Devices"; size = sizeof(class); ret = btif_config_get_str(section, key, "class", class, &size); - debug("btif_config_get_str return:%d, Remote devices:%s, class:%s", ret, key, class); + BTIF_TRACE_DEBUG3("btif_config_get_str return:%d, Remote devices:%s, class:%s", ret, key, class); size = sizeof(link_key); type = BTIF_CFG_TYPE_BIN; ret = btif_config_get(section, key, "link keys", link_key, &size, &type); - debug("btif_config_get return:%d, Remote devices:%s, link key:%x, %x", - ret, key, *(int *)link_key, *((int *)link_key + 1)); + //debug("btif_config_get return:%d, Remote devices:%s, link key:%x, %x", + // ret, key, *(int *)link_key, *((int *)link_key + 1)); int timeout; ret = btif_config_get_int(section, key, "connect time out", &timeout); - debug("btif_config_get_int return:%d, Remote devices:%s, connect time out:%d", ret, key, timeout); + //debug("btif_config_get_int return:%d, Remote devices:%s, connect time out:%d", ret, key, timeout); } - debug("testing btif_config_remove"); + // debug("testing btif_config_remove"); size = sizeof(class); type = BTIF_CFG_TYPE_STR; btif_config_set("Remote Devices", "00:22:5F:97:56:04", "Class Delete", class, strlen(class) + 1, BTIF_CFG_TYPE_STR); btif_config_get("Remote Devices", "00:22:5F:97:56:04", "Class Delete", class, &size, &type); - debug("Remote devices, 00:22:5F:97:56:04 Class Delete:%s", class); + // debug("Remote devices, 00:22:5F:97:56:04 Class Delete:%s", class); btif_config_remove("Remote Devices", "00:22:5F:97:56:04", "Class Delete"); size = sizeof(class); type = BTIF_CFG_TYPE_STR; ret = btif_config_get("Remote Devices", "00:22:5F:97:56:04", "Class Delete", class, &size, &type); - debug("after removed, btif_config_get ret:%d, Remote devices, 00:22:5F:97:56:04 Class Delete:%s", ret, class); - debug("out"); + // debug("after removed, btif_config_get ret:%d, Remote devices, 00:22:5F:97:56:04 Class Delete:%s", ret, class); + // debug("out"); } #endif diff --git a/btif/src/btif_config_util.cpp b/btif/src/btif_config_util.cpp index 19fa30b..885f5c2 100644 --- a/btif/src/btif_config_util.cpp +++ b/btif/src/btif_config_util.cpp @@ -391,9 +391,9 @@ static int read_file_line(const char* map, int start_pos, int size, int* line_si int i; for(i = start_pos; i < size; i++) { - ++*line_size; if(map[i] == '\r' || map[i] == '\n') break; + ++*line_size; } //debug("out, ret:%d, start pos:%d, size:%d, line_size:%d", i, start_pos, size, *line_size); return i + 1; diff --git a/btif/src/btif_hh.c b/btif/src/btif_hh.c index 61432b8..004f2ef 100644 --- a/btif/src/btif_hh.c +++ b/btif/src/btif_hh.c @@ -487,6 +487,9 @@ void btif_hh_remove_device(bt_bdaddr_t bd_addr) GKI_freebuf(p_dev->p_buf); p_dev->p_buf = NULL; } + + p_dev->hh_keep_polling = 0; + p_dev->hh_poll_thread_id = -1; BTIF_TRACE_DEBUG2("%s: uhid fd = %d", __FUNCTION__, p_dev->fd); if (p_dev->fd >= 0) { bta_hh_co_destroy(p_dev->fd); @@ -648,6 +651,47 @@ void btif_hh_disconnect(bt_bdaddr_t *bd_addr) BTIF_TRACE_DEBUG1("%s-- Error: device not connected:",__FUNCTION__); } + +/******************************************************************************* +** +** Function btif_btif_hh_setreport +** +** Description setreport initiated from the BTIF thread context +** +** Returns void +** +*******************************************************************************/ + +void btif_hh_setreport(btif_hh_device_t *p_dev, bthh_report_type_t r_type, UINT16 size, + UINT8* report) +{ + UINT8 hexbuf[20]; + UINT16 len = size; + int i = 0; + if (p_dev->p_buf != NULL) { + GKI_freebuf(p_dev->p_buf); + } + p_dev->p_buf = GKI_getbuf((UINT16) (len + BTA_HH_MIN_OFFSET + sizeof(BT_HDR))); + if (p_dev->p_buf == NULL) { + APPL_TRACE_ERROR2("%s: Error, failed to allocate RPT buffer, len = %d", __FUNCTION__, len); + return; + } + + p_dev->p_buf->len = len; + p_dev->p_buf->offset = BTA_HH_MIN_OFFSET; + + //Build a SetReport data buffer + memset(hexbuf, 0, 20); + for(i=0; i<len; i++) + hexbuf[i] = report[i]; + + UINT8* pbuf_data; + pbuf_data = (UINT8*) (p_dev->p_buf + 1) + p_dev->p_buf->offset; + memcpy(pbuf_data, hexbuf, len); + BTA_HhSetReport(p_dev->dev_handle, r_type, p_dev->p_buf); + +} + /***************************************************************************** ** Section name (Group of functions) *****************************************************************************/ @@ -731,7 +775,10 @@ static void btif_hh_upstreams_evt(UINT16 event, char* p_param) BTIF_TRACE_WARNING1("BTA_HH_OPEN_EVT: Found device...Getting dscp info for handle ... %d",p_data->conn.handle); memcpy(&(p_dev->bd_addr), p_data->conn.bda, BD_ADDR_LEN); btif_hh_cb.status = BTIF_HH_DEV_CONNECTED; - BTA_HhSetIdle(p_data->conn.handle, 0); + // Send set_idle if the peer_device is a keyboard + if (check_cod((bt_bdaddr_t*)p_data->conn.bda, COD_HID_KEYBOARD )|| + check_cod((bt_bdaddr_t*)p_data->conn.bda, COD_HID_COMBO)) + BTA_HhSetIdle(p_data->conn.handle, 0); btif_hh_cb.p_curr_dev = btif_hh_find_connected_dev_by_handle(p_data->conn.handle); BTA_HhGetDscpInfo(p_data->conn.handle); p_dev->dev_status = BTHH_CONN_STATE_CONNECTED; @@ -1563,6 +1610,8 @@ static void cleanup( void ) BTIF_TRACE_DEBUG2("%s: Closing uhid fd = %d", __FUNCTION__, p_dev->fd); bta_hh_co_destroy(p_dev->fd); p_dev->fd = -1; + p_dev->hh_keep_polling = 0; + p_dev->hh_poll_thread_id = -1; } } diff --git a/btif/src/btif_pan.c b/btif/src/btif_pan.c index 2f6c932..633f6ef 100644 --- a/btif/src/btif_pan.c +++ b/btif/src/btif_pan.c @@ -69,16 +69,7 @@ #define BTPAN_LOCAL_ROLE (BTPAN_ROLE_PANU | BTPAN_ROLE_PANNAP) #endif - - -#include <cutils/log.h> -#define info(fmt, ...) ALOGI ("btif_pan: %s(L%d): " fmt,__FUNCTION__, __LINE__, ## __VA_ARGS__) -#define debug(fmt, ...) ALOGD ("btif_pan: %s(L%d): " fmt,__FUNCTION__, __LINE__, ## __VA_ARGS__) -#define warn(fmt, ...) ALOGW ("btif_pan: ## WARNING : %s(L%d): " fmt "##",__FUNCTION__, __LINE__, ## __VA_ARGS__) -#define error(fmt, ...) ALOGE ("btif_pan: ## ERROR : %s(L%d): " fmt "##",__FUNCTION__, __LINE__, ## __VA_ARGS__) -#define asrt(s) if(!(s)) ALOGE ("btif_pan: ## %s assert %s failed at line:%d ##",__FUNCTION__, #s, __LINE__) - - +#define asrt(s) if(!(s)) BTIF_TRACE_ERROR3("btif_pan: ## %s assert %s failed at line:%d ##",__FUNCTION__, #s, __LINE__) btpan_cb_t btpan_cb; @@ -118,11 +109,11 @@ btpan_interface_t *btif_pan_get_interface() } void btif_pan_init() { - debug("jni_initialized = %d, btpan_cb.enabled:%d", jni_initialized, btpan_cb.enabled); + BTIF_TRACE_DEBUG2("jni_initialized = %d, btpan_cb.enabled:%d", jni_initialized, btpan_cb.enabled); stack_initialized = TRUE; if (jni_initialized && !btpan_cb.enabled) { - debug("Enabling PAN...."); + BTIF_TRACE_DEBUG0("Enabling PAN...."); memset(&btpan_cb, 0, sizeof(btpan_cb)); btpan_cb.tap_fd = -1; int i; @@ -132,7 +123,6 @@ void btif_pan_init() btpan_cb.enabled = 1; btpan_enable(BTPAN_LOCAL_ROLE); } - debug("leaving"); } static void pan_disable() { @@ -157,7 +147,6 @@ void btif_pan_cleanup() for(i = 0; i < MAX_PAN_CONNS; i++) btpan_cleanup_conn(&btpan_cb.conns[i]); pan_disable(); - debug("leaving"); } stack_initialized = FALSE; } @@ -165,12 +154,11 @@ void btif_pan_cleanup() static btpan_callbacks_t callback; static bt_status_t btpan_jni_init(const btpan_callbacks_t* callbacks) { - debug("stack_initialized = %d, btpan_cb.enabled:%d", stack_initialized, btpan_cb.enabled); + BTIF_TRACE_DEBUG2("stack_initialized = %d, btpan_cb.enabled:%d", stack_initialized, btpan_cb.enabled); jni_initialized = TRUE; if(stack_initialized && !btpan_cb.enabled) btif_pan_init(); callback = *callbacks; - debug(" leaving"); return BT_STATUS_SUCCESS; } @@ -178,20 +166,17 @@ static void btpan_jni_cleanup() { pan_disable(); jni_initialized = FALSE; - debug("leaving"); } static inline int bta_role_to_btpan(int bta_pan_role) { int btpan_role = 0; - debug("bta_pan_role:0x%x", bta_pan_role); + BTIF_TRACE_DEBUG1("bta_pan_role:0x%x", bta_pan_role); if(bta_pan_role & PAN_ROLE_NAP_SERVER) { - debug("BTPAN_ROLE_PANNAP"); btpan_role |= BTPAN_ROLE_PANNAP; } if(bta_pan_role & PAN_ROLE_CLIENT) { - debug("BTPAN_ROLE_PANU"); btpan_role |= BTPAN_ROLE_PANU; } return btpan_role; @@ -199,15 +184,13 @@ static inline int bta_role_to_btpan(int bta_pan_role) static inline int btpan_role_to_bta(int btpan_role) { int bta_pan_role = PAN_ROLE_INACTIVE; - debug("btpan_role:0x%x", btpan_role); + BTIF_TRACE_DEBUG1("btpan_role:0x%x", btpan_role); if(btpan_role & BTPAN_ROLE_PANNAP) { - debug("BTPAN_ROLE_PANNAP"); bta_pan_role |= PAN_ROLE_NAP_SERVER; } if(btpan_role & BTPAN_ROLE_PANU) { - debug("BTPAN_ROLE_CLIENT"); bta_pan_role |= PAN_ROLE_CLIENT; } return bta_pan_role; @@ -219,7 +202,7 @@ static tBTA_PAN_ROLE_INFO bta_pan_nap_info = {PAN_NAP_SERVICE_NAME, 0, PAN_SECUR static bt_status_t btpan_enable(int local_role) { int bta_pan_role; - debug("local_role:%d", local_role); + BTIF_TRACE_DEBUG1("local_role:%d", local_role); bta_pan_role = btpan_role_to_bta(local_role); BTA_PanSetRole(bta_pan_role, &bta_panu_info, NULL, &bta_pan_nap_info); btpan_dev_local_role = local_role; @@ -227,12 +210,12 @@ static bt_status_t btpan_enable(int local_role) } static int btpan_get_local_role() { - debug("btpan_dev_local_role:%d", btpan_dev_local_role); + BTIF_TRACE_DEBUG1("btpan_dev_local_role:%d", btpan_dev_local_role); return btpan_dev_local_role; } static bt_status_t btpan_connect(const bt_bdaddr_t *bd_addr, int local_role, int remote_role) { - debug("local_role:%d, remote_role:%d", local_role, remote_role); + BTIF_TRACE_DEBUG2("local_role:%d, remote_role:%d", local_role, remote_role); int bta_local_role = btpan_role_to_bta(local_role); int bta_remote_role = btpan_role_to_bta(remote_role); btpan_new_conn(-1, bd_addr->address, bta_local_role, bta_remote_role); @@ -266,7 +249,6 @@ static void btif_in_pan_generic_evt(UINT16 event, char *p_param) } static bt_status_t btpan_disconnect(const bt_bdaddr_t *bd_addr) { - debug("in"); btpan_conn_t* conn = btpan_find_conn_addr(bd_addr->address); if(conn && conn->handle >= 0) { @@ -281,7 +263,6 @@ static bt_status_t btpan_disconnect(const bt_bdaddr_t *bd_addr) static int pth = -1; void create_tap_read_thread(int tap_fd) { - debug("in"); if(pth < 0) { pth = btsock_thread_create(btpan_tap_fd_signaled, NULL); @@ -310,23 +291,23 @@ static int tap_if_up(const char *devname, BD_ADDR addr) err = ioctl(sk, SIOCGIFHWADDR, &ifr); if(err < 0) { - error("Could not get network hardware for interface:%s, errno:%s", devname, strerror(errno)); + BTIF_TRACE_ERROR2("Could not get network hardware for interface:%s, errno:%s", devname, strerror(errno)); close(sk); return -1; } - debug("found mac address for interface:%s = %02x:%02x:%02x:%02x:%02x:%02x", devname, - ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1], ifr.ifr_hwaddr.sa_data[2], - ifr.ifr_hwaddr.sa_data[3], ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]); + /* debug("found mac address for interface:%s = %02x:%02x:%02x:%02x:%02x:%02x", devname, */ + /* ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1], ifr.ifr_hwaddr.sa_data[2], */ + /* ifr.ifr_hwaddr.sa_data[3], ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]); */ strncpy(ifr.ifr_name, devname, IFNAMSIZ - 1); memcpy(ifr.ifr_hwaddr.sa_data, addr, 6); - debug("setting bt address for interface:%s = %02x:%02x:%02x:%02x:%02x:%02x", devname, - ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1], ifr.ifr_hwaddr.sa_data[2], - ifr.ifr_hwaddr.sa_data[3], ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]); + /* debug("setting bt address for interface:%s = %02x:%02x:%02x:%02x:%02x:%02x", devname, */ + /* ifr.ifr_hwaddr.sa_data[0], ifr.ifr_hwaddr.sa_data[1], ifr.ifr_hwaddr.sa_data[2], */ + /* ifr.ifr_hwaddr.sa_data[3], ifr.ifr_hwaddr.sa_data[4], ifr.ifr_hwaddr.sa_data[5]); */ err = ioctl(sk, SIOCSIFHWADDR, (caddr_t)&ifr); if (err < 0) { - error("Could not set bt address for interface:%s, errno:%s", devname, strerror(errno)); + BTIF_TRACE_ERROR2("Could not set bt address for interface:%s, errno:%s", devname, strerror(errno)); close(sk); return -1; } @@ -342,12 +323,12 @@ static int tap_if_up(const char *devname, BD_ADDR addr) if (err < 0) { - error("Could not bring up network interface:%s, errno:%d", devname, errno); + BTIF_TRACE_ERROR2("Could not bring up network interface:%s, errno:%d", devname, errno); close(sk); return -1; } close(sk); - debug("network interface: %s is up", devname); + BTIF_TRACE_DEBUG1("network interface: %s is up", devname); return 0; } @@ -371,7 +352,6 @@ static int tap_if_down(const char *devname) } int btpan_tap_open() { - debug("in"); struct ifreq ifr; int fd, err; const char *clonedev = "/dev/tun"; @@ -381,7 +361,7 @@ int btpan_tap_open() //system("insmod /system/lib/modules/tun.ko"); if( (fd = open(clonedev, O_RDWR)) < 0 ) { - debug("could not open %s, err:%d", clonedev, errno); + BTIF_TRACE_DEBUG2("could not open %s, err:%d", clonedev, errno); return fd; } @@ -393,7 +373,7 @@ int btpan_tap_open() /* try to create the device */ if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 )//|| tap_setup_ip(TAP_IF_NAME) == FALSE) { - debug("ioctl error:%d, errno:%s", err, strerror(errno)); + BTIF_TRACE_DEBUG2("ioctl error:%d, errno:%s", err, strerror(errno)); close(fd); return err; } @@ -402,25 +382,13 @@ int btpan_tap_open() { return fd; } - error("can not bring up tap interface:%s", TAP_IF_NAME); + BTIF_TRACE_ERROR1("can not bring up tap interface:%s", TAP_IF_NAME); close(fd); return -1; } int btpan_tap_send(int tap_fd, const BD_ADDR src, const BD_ADDR dst, UINT16 proto, const char* buf, UINT16 len, BOOLEAN ext, BOOLEAN forward) { - debug("in"); - debug("SRC ADDR = %02x:%02x:%02x:%02x:%02x:%02x", - src[0], src[1], src[2], src[3], - src[4], src[5]); - debug("DST ADDR = %02x:%02x:%02x:%02x:%02x:%02x", - dst[0], dst[1], dst[2], dst[3], - dst[4], dst[5]); - - debug("Protocol = 0x%x", proto); - debug("Ext = 0x%x", ext); - debug("Forward = 0x%x", forward); - debug("Len = %d", len); if(tap_fd != -1) { tETH_HDR eth_hdr; @@ -443,7 +411,7 @@ int btpan_tap_send(int tap_fd, const BD_ADDR src, const BD_ADDR dst, UINT16 prot //btnet_send(btpan_cb.conn[i].sock.sock, &buffer, (len + sizeof(tETH_HDR))); //dump_bin("packet to network", packet, len + sizeof(tETH_HDR)); int ret = write(tap_fd, packet, len + sizeof(tETH_HDR)); - debug("ret:%d", ret); + BTIF_TRACE_DEBUG1("ret:%d", ret); return ret; } return -1; @@ -451,7 +419,6 @@ int btpan_tap_send(int tap_fd, const BD_ADDR src, const BD_ADDR dst, UINT16 prot } int btpan_tap_close(int fd) { - debug("in"); tap_if_down(TAP_IF_NAME); close(fd); return 0; @@ -486,13 +453,12 @@ static void btpan_cleanup_conn(btpan_conn_t* conn) btpan_conn_t* btpan_new_conn(int handle, const BD_ADDR addr, int local_role, int remote_role ) { int i; - debug("in"); for(i = 0; i < MAX_PAN_CONNS; i++) { - debug("conns[%d]:%d", i, btpan_cb.conns[i].handle); + BTIF_TRACE_DEBUG2("conns[%d]:%d", i, btpan_cb.conns[i].handle); if(btpan_cb.conns[i].handle == -1) { - debug("handle:%d, local_role:%d, remote_role:%d", handle, local_role, remote_role); + BTIF_TRACE_DEBUG3("handle:%d, local_role:%d, remote_role:%d", handle, local_role, remote_role); btpan_cb.conns[i].handle = handle; bdcpy(btpan_cb.conns[i].peer, addr); @@ -501,13 +467,13 @@ btpan_conn_t* btpan_new_conn(int handle, const BD_ADDR addr, int local_role, int return &btpan_cb.conns[i]; } } - debug("MAX_PAN_CONNS:%d exceeded, return NULL as failed", MAX_PAN_CONNS); + BTIF_TRACE_DEBUG1("MAX_PAN_CONNS:%d exceeded, return NULL as failed", MAX_PAN_CONNS); return NULL; } void btpan_close_handle(btpan_conn_t *p) { - debug("btpan_close_handle : close handle %d", p->handle); + BTIF_TRACE_DEBUG1("btpan_close_handle : close handle %d", p->handle); p->handle = -1; p->local_role = -1; p->remote_role = -1; @@ -517,7 +483,7 @@ static inline int should_forward(tETH_HDR* hdr) { if(ntohs(hdr->h_proto) == ETH_P_IP || ntohs(hdr->h_proto) == ETH_P_ARP) return TRUE; - debug("unknown proto:%x", ntohs(hdr->h_proto)); + BTIF_TRACE_DEBUG1("unknown proto:%x", ntohs(hdr->h_proto)); return FALSE; } extern void bta_pan_ci_rx_write(UINT16 handle, BD_ADDR dst, BD_ADDR src, UINT16 protocol, @@ -533,7 +499,7 @@ static void forward_bnep(tETH_HDR* eth_hdr, char * packet, int size) (broadcast || memcmp(btpan_cb.conns[i].eth_addr, eth_hdr->h_dest, sizeof(BD_ADDR)) == 0 || memcmp(btpan_cb.conns[i].peer, eth_hdr->h_dest, sizeof(BD_ADDR)) == 0)) { - debug("calling bta_pan_ci_rx_write, handle:%d", handle); + BTIF_TRACE_DEBUG1("calling bta_pan_ci_rx_write, handle:%d", handle); bta_pan_ci_rx_write(handle, eth_hdr->h_dest, eth_hdr->h_src, ntohs(eth_hdr->h_proto), (UINT8*)packet, size, 0); break; @@ -547,7 +513,7 @@ static void bta_pan_callback_transfer(UINT16 event, char *p_param) switch(event) { case BTA_PAN_ENABLE_EVT: - debug("BTA_PAN_ENABLE_EVT"); + BTIF_TRACE_DEBUG0("BTA_PAN_ENABLE_EVT"); break; case BTA_PAN_SET_ROLE_EVT: { @@ -562,7 +528,7 @@ static void bta_pan_callback_transfer(UINT16 event, char *p_param) btpan_conn_t* conn; bdstr_t bds; bd2str((bt_bdaddr_t*)p_data->opening.bd_addr, &bds); - debug("BTA_PAN_OPENING_EVT handle %d, addr: %s", p_data->opening.handle, bds); + BTIF_TRACE_DEBUG2("BTA_PAN_OPENING_EVT handle %d, addr: %s", p_data->opening.handle, bds); conn = btpan_find_conn_addr(p_data->opening.bd_addr); asrt(conn != NULL); @@ -575,15 +541,15 @@ static void bta_pan_callback_transfer(UINT16 event, char *p_param) (const bt_bdaddr_t*)p_data->opening.bd_addr, btpan_conn_local_role, btpan_remote_role); } else - error("connection not found"); + BTIF_TRACE_ERROR0("connection not found"); break; } case BTA_PAN_OPEN_EVT: { - debug("BTA_PAN_OPEN_EVT, open status:%d, bd_addr = [%02X:%02X:%02X:%02X:%02X:%02X]", - p_data->open.status, - p_data->open.bd_addr[0], p_data->open.bd_addr[1], p_data->open.bd_addr[2], - p_data->open.bd_addr[3], p_data->open.bd_addr[4], p_data->open.bd_addr[5]); + /* debug("BTA_PAN_OPEN_EVT, open status:%d, bd_addr = [%02X:%02X:%02X:%02X:%02X:%02X]", */ + /* p_data->open.status, */ + /* p_data->open.bd_addr[0], p_data->open.bd_addr[1], p_data->open.bd_addr[2], */ + /* p_data->open.bd_addr[3], p_data->open.bd_addr[4], p_data->open.bd_addr[5]); */ btpan_connection_state_t state; bt_status_t status; if(p_data->open.status == BTA_PAN_SUCCESS) @@ -597,10 +563,10 @@ static void bta_pan_callback_transfer(UINT16 event, char *p_param) status = BT_STATUS_FAIL; } btpan_conn_t* conn = btpan_find_conn_handle(p_data->open.handle); - debug("BTA_PAN_OPEN_EVT handle:%d, conn:%p", p_data->open.handle, conn); - debug("conn bta local_role:%d, bta remote role:%d", conn->local_role, conn->remote_role); + /* debug("BTA_PAN_OPEN_EVT handle:%d, conn:%p", p_data->open.handle, conn); */ + /* debug("conn bta local_role:%d, bta remote role:%d", conn->local_role, conn->remote_role); */ int btpan_conn_local_role = bta_role_to_btpan(p_data->open.local_role); - debug("bta local_role:%d, bta remote role:%d", p_data->open.local_role, p_data->open.peer_role); + /* debug("bta local_role:%d, bta remote role:%d", p_data->open.local_role, p_data->open.peer_role); */ int btpan_remote_role = bta_role_to_btpan(p_data->open.peer_role); callback.connection_state_cb(state, status, (const bt_bdaddr_t*)p_data->open.bd_addr, btpan_conn_local_role, btpan_remote_role); @@ -614,7 +580,7 @@ static void bta_pan_callback_transfer(UINT16 event, char *p_param) if(conn && conn->handle >= 0) { - debug("BTA_PAN_CLOSE_EVT, conn local_role:%d, remote_role:%d", conn->local_role, conn->remote_role); + /* debug("BTA_PAN_CLOSE_EVT, conn local_role:%d, remote_role:%d", conn->local_role, conn->remote_role); */ int btpan_conn_local_role = bta_role_to_btpan(conn->local_role); int btpan_remote_role = bta_role_to_btpan(conn->remote_role); callback.connection_state_cb(BTPAN_STATE_DISCONNECTED, 0, (const bt_bdaddr_t*)conn->peer, @@ -622,11 +588,11 @@ static void bta_pan_callback_transfer(UINT16 event, char *p_param) btpan_cleanup_conn(conn); } else - error("pan handle not found (%d)", p_data->close.handle); + BTIF_TRACE_ERROR1("pan handle not found (%d)", p_data->close.handle); break; } default: - debug("Unknown pan event %d", event); + BTIF_TRACE_WARNING1("Unknown pan event %d", event); break; } } @@ -642,20 +608,20 @@ static void btpan_tap_fd_signaled(int fd, int type, int flags, uint32_t user_id) tETH_HDR eth_hdr; if(flags & SOCK_THREAD_FD_EXCEPTION) { - error("pan tap fd:%d exception", fd); + BTIF_TRACE_ERROR1("pan tap fd:%d exception", fd); } else if(flags & SOCK_THREAD_FD_RD) { - debug("tab fd read trigged, data"); + /* debug("tab fd read trigged, data"); */ int size = read(fd, packet, MAX_PACKET_SIZE); - debug("tap fd read trigged, read size:%d", size); + /* debug("tap fd read trigged, read size:%d", size); */ memcpy(ð_hdr, &packet, sizeof(tETH_HDR)); - debug("eth src = %02x:%02x:%02x:%02x:%02x:%02x", - eth_hdr.h_src[0], eth_hdr.h_src[1], eth_hdr.h_src[2], eth_hdr.h_src[3], - eth_hdr.h_src[4], eth_hdr.h_src[5]); - debug("eth dest = %02x:%02x:%02x:%02x:%02x:%02x", - eth_hdr.h_dest[0], eth_hdr.h_dest[1], eth_hdr.h_dest[2], eth_hdr.h_dest[3], - eth_hdr.h_dest[4], eth_hdr.h_dest[5]); + /* debug("eth src = %02x:%02x:%02x:%02x:%02x:%02x", */ + /* eth_hdr.h_src[0], eth_hdr.h_src[1], eth_hdr.h_src[2], eth_hdr.h_src[3], */ + /* eth_hdr.h_src[4], eth_hdr.h_src[5]); */ + /* debug("eth dest = %02x:%02x:%02x:%02x:%02x:%02x", */ + /* eth_hdr.h_dest[0], eth_hdr.h_dest[1], eth_hdr.h_dest[2], eth_hdr.h_dest[3], */ + /* eth_hdr.h_dest[4], eth_hdr.h_dest[5]); */ //dump_bin("eth packet received", packet, size); if(should_forward(ð_hdr)) { diff --git a/btif/src/btif_sock.c b/btif/src/btif_sock.c index a2c799a..621a91e 100644 --- a/btif/src/btif_sock.c +++ b/btif/src/btif_sock.c @@ -38,11 +38,6 @@ #include "bta_api.h" #include "btif_sock_thread.h" #include "btif_sock_rfc.h" -#include <cutils/log.h> -#define info(fmt, ...) ALOGI ("btif_sock: %s: " fmt,__FUNCTION__, ## __VA_ARGS__) -#define debug(fmt, ...) ALOGD ("btif_sock: %s: " fmt,__FUNCTION__, ## __VA_ARGS__) -#define error(fmt, ...) ALOGE ("btif_sock: ## ERROR : %s: " fmt "##",__FUNCTION__, ## __VA_ARGS__) -#define asrt(s) if(!(s)) ALOGE ("btif_sock: ## %s assert %s failed at line:%d ##",__FUNCTION__, #s, __LINE__) static bt_status_t btsock_listen(btsock_type_t type, const char* service_name, const uint8_t* uuid, int channel, int* sock_fd, int flags); @@ -71,31 +66,27 @@ btsock_interface_t *btif_sock_get_interface() } bt_status_t btif_sock_init() { - debug(""); - - static volatile int binit; if(!binit) { //fix me, the process doesn't exit right now. don't set the init flag for now //binit = 1; - debug("btsock initializing..."); + BTIF_TRACE_DEBUG0("btsock initializing..."); btsock_thread_init(); int handle = btsock_thread_create(btsock_signaled, NULL); if(handle >= 0 && btsock_rfc_init(handle) == BT_STATUS_SUCCESS) { - debug("btsock successfully initialized"); + BTIF_TRACE_DEBUG0("btsock successfully initialized"); return BT_STATUS_SUCCESS; } } - else error("btsock interface already initialized"); + else BTIF_TRACE_ERROR0("btsock interface already initialized"); return BT_STATUS_FAIL; } void btif_sock_cleanup() { - debug(""); btsock_rfc_cleanup(); - debug("leaving"); + BTIF_TRACE_DEBUG0("leaving"); } static bt_status_t btsock_listen(btsock_type_t type, const char* service_name, @@ -103,7 +94,7 @@ static bt_status_t btsock_listen(btsock_type_t type, const char* service_name, { if((service_uuid == NULL && channel <= 0) || sock_fd == NULL) { - error("invalid parameters, uuid:%p, channel:%d, sock_fd:%p", service_uuid, channel, sock_fd); + BTIF_TRACE_ERROR3("invalid parameters, uuid:%p, channel:%d, sock_fd:%p", service_uuid, channel, sock_fd); return BT_STATUS_PARM_INVALID; } *sock_fd = -1; @@ -114,15 +105,15 @@ static bt_status_t btsock_listen(btsock_type_t type, const char* service_name, status = btsock_rfc_listen(service_name, service_uuid, channel, sock_fd, flags); break; case BTSOCK_L2CAP: - error("bt l2cap socket type not supported, type:%d", type); + BTIF_TRACE_ERROR1("bt l2cap socket type not supported, type:%d", type); status = BT_STATUS_UNSUPPORTED; break; case BTSOCK_SCO: - error("bt sco socket not supported, type:%d", type); + BTIF_TRACE_ERROR1("bt sco socket not supported, type:%d", type); status = BT_STATUS_UNSUPPORTED; break; default: - error("unknown bt socket type:%d", type); + BTIF_TRACE_ERROR1("unknown bt socket type:%d", type); status = BT_STATUS_UNSUPPORTED; break; } @@ -133,7 +124,7 @@ static bt_status_t btsock_connect(const bt_bdaddr_t *bd_addr, btsock_type_t type { if((uuid == NULL && channel <= 0) || bd_addr == NULL || sock_fd == NULL) { - error("invalid parameters, bd_addr:%p, uuid:%p, channel:%d, sock_fd:%p", + BTIF_TRACE_ERROR4("invalid parameters, bd_addr:%p, uuid:%p, channel:%d, sock_fd:%p", bd_addr, uuid, channel, sock_fd); return BT_STATUS_PARM_INVALID; } @@ -145,15 +136,15 @@ static bt_status_t btsock_connect(const bt_bdaddr_t *bd_addr, btsock_type_t type status = btsock_rfc_connect(bd_addr, uuid, channel, sock_fd, flags); break; case BTSOCK_L2CAP: - error("bt l2cap socket type not supported, type:%d", type); + BTIF_TRACE_ERROR1("bt l2cap socket type not supported, type:%d", type); status = BT_STATUS_UNSUPPORTED; break; case BTSOCK_SCO: - error("bt sco socket not supported, type:%d", type); + BTIF_TRACE_ERROR1("bt sco socket not supported, type:%d", type); status = BT_STATUS_UNSUPPORTED; break; default: - error("unknown bt socket type:%d", type); + BTIF_TRACE_ERROR1("unknown bt socket type:%d", type); status = BT_STATUS_UNSUPPORTED; break; } @@ -167,13 +158,13 @@ static void btsock_signaled(int fd, int type, int flags, uint32_t user_id) btsock_rfc_signaled(fd, flags, user_id); break; case BTSOCK_L2CAP: - error("bt l2cap socket type not supported, fd:%d, flags:%d", fd, flags); + BTIF_TRACE_ERROR2("bt l2cap socket type not supported, fd:%d, flags:%d", fd, flags); break; case BTSOCK_SCO: - error("bt sco socket type not supported, fd:%d, flags:%d", fd, flags); + BTIF_TRACE_ERROR2("bt sco socket type not supported, fd:%d, flags:%d", fd, flags); break; default: - error("unknown socket type:%d, fd:%d, flags:%d", type, fd, flags); + BTIF_TRACE_ERROR3("unknown socket type:%d, fd:%d, flags:%d", type, fd, flags); break; } } diff --git a/btif/src/btif_sock_rfc.c b/btif/src/btif_sock_rfc.c index 650549f..0e52c1b 100644 --- a/btif/src/btif_sock_rfc.c +++ b/btif/src/btif_sock_rfc.c @@ -305,6 +305,8 @@ static inline rfc_slot_t* create_srv_accept_rfc_slot(rfc_slot_t* srv_rs, const b bt_status_t btsock_rfc_listen(const char* service_name, const uint8_t* service_uuid, int channel, int* sock_fd, int flags) { + + APPL_TRACE_DEBUG1("btsock_rfc_listen, service_name:%s", service_name); if(sock_fd == NULL || (service_uuid == NULL && (channel < 1 || channel > 30))) { APPL_TRACE_ERROR3("invalid rfc channel:%d or sock_fd:%p, uuid:%p", channel, sock_fd, service_uuid); @@ -329,6 +331,7 @@ bt_status_t btsock_rfc_listen(const char* service_name, const uint8_t* service_u rfc_slot_t* rs = alloc_rfc_slot(NULL, service_name, service_uuid, channel, flags, TRUE); if(rs) { + APPL_TRACE_DEBUG1("BTA_JvCreateRecordByUser:%s", service_name); BTA_JvCreateRecordByUser((void *)rs->id); *sock_fd = rs->app_fd; rs->app_fd = -1; //the fd ownership is transferred to app @@ -466,18 +469,19 @@ static inline void free_rfc_slot_scn(rfc_slot_t* rs) { if(rs->scn > 0) { - if(rs->f.server && !rs->f.closing) + if(rs->f.server && !rs->f.closing && rs->rfc_handle) { BTA_JvRfcommStopServer(rs->rfc_handle); rs->rfc_handle = 0; } - BTM_FreeSCN(rs->scn); + if(rs->f.server) + BTM_FreeSCN(rs->scn); rs->scn = 0; } } static void cleanup_rfc_slot(rfc_slot_t* rs) { - APPL_TRACE_DEBUG3("cleanup slot:%d, fd:%d, scn:%d", rs->id, rs->fd, rs->scn); + APPL_TRACE_DEBUG4("cleanup slot:%d, fd:%d, scn:%d, sdp_handle:0x%x", rs->id, rs->fd, rs->scn, rs->sdp_handle); if(rs->fd != -1) { shutdown(rs->fd, 2); @@ -695,6 +699,7 @@ static void *rfcomm_cback(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_data) break; case BTA_JV_RFCOMM_CLOSE_EVT: + APPL_TRACE_DEBUG1("BTA_JV_RFCOMM_CLOSE_EVT: user_data:%d", (uint32_t)user_data); on_rfc_close(&p_data->rfc_close, (uint32_t)user_data); break; @@ -724,7 +729,7 @@ static void *rfcomm_cback(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_data) static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_data) { uint32_t id = (uint32_t)user_data; - APPL_TRACE_DEBUG2("event:%d, slot id:%d", event, id); + APPL_TRACE_DEBUG2("jv_dm_cback: event:%d, slot id:%d", event, id); switch(event) { case BTA_JV_CREATE_RECORD_EVT: @@ -737,6 +742,11 @@ static void jv_dm_cback(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_data) BTA_JvRfcommStartServer(rs->security, rs->role, rs->scn, MAX_RFC_SESSION, rfcomm_cback, (void*)rs->id); } + else if(rs) + { + APPL_TRACE_ERROR1("jv_dm_cback: cannot start server, slot found:%p", rs); + cleanup_rfc_slot(rs); + } unlock_slot(&slot_lock); break; } @@ -896,7 +906,7 @@ void btsock_rfc_signaled(int fd, int flags, uint32_t user_id) APPL_TRACE_DEBUG1("SOCK_THREAD_FD_EXCEPTION, flags:%x", flags); rs->f.closing = TRUE; if(rs->f.server) - BTA_JvRfcommStopServer(rs->rfc_handle); + BTA_JvRfcommStopServer(rs->rfc_handle); else BTA_JvRfcommClose(rs->rfc_handle); } diff --git a/btif/src/btif_sock_sdp.c b/btif/src/btif_sock_sdp.c index cf55e8a..a1ec6df 100644 --- a/btif/src/btif_sock_sdp.c +++ b/btif/src/btif_sock_sdp.c @@ -51,6 +51,7 @@ #include "utl.h" #include "../bta/pb/bta_pbs_int.h" #include "../include/bta_op_api.h" +#include "bta_jv_api.h" #include <cutils/log.h> #define RESERVED_SCN_PBS 19 @@ -113,7 +114,7 @@ static int add_sdp_by_uuid(const char *name, const uint8_t *service_uuid, UINT1 } } } - + else APPL_TRACE_ERROR1("failed to create sdp record, service_name:%s", name); return 0; } @@ -142,7 +143,7 @@ static int add_pbap_sdp(const char* p_service_name, int scn) UINT32 sdp_handle = 0; tBTA_PBS_CFG *p_bta_pbs_cfg = (tBTA_PBS_CFG *)&bta_pbs_cfg; - APPL_TRACE_DEBUG2("scn %d, service name %s", scn, p_service_name); + APPL_TRACE_DEBUG2("add_pbap_sdd:scn %d, service name %s", scn, p_service_name); if ((sdp_handle = SDP_CreateRecord()) == 0) { @@ -437,7 +438,8 @@ int add_rfc_sdp_rec(const char* name, const uint8_t* uuid, int scn) void del_rfc_sdp_rec(int handle) { + APPL_TRACE_DEBUG1("del_rfc_sdp_rec: handle:0x%x", handle); if(handle != -1 && handle != 0) - SDP_DeleteRecord( handle ); + BTA_JvDeleteRecord( handle ); } diff --git a/btif/src/btif_sock_util.c b/btif/src/btif_sock_util.c index 09df03e..5b5de69 100644 --- a/btif/src/btif_sock_util.c +++ b/btif/src/btif_sock_util.c @@ -66,12 +66,7 @@ #include "bta_jv_co.h" #include "port_api.h" -#include <cutils/log.h> - -#define info(fmt, ...) ALOGI ("%s: " fmt,__FUNCTION__, ## __VA_ARGS__) -#define debug(fmt, ...) ALOGD ("%s: " fmt,__FUNCTION__, ## __VA_ARGS__) -#define error(fmt, ...) ALOGE ("## ERROR : %s: " fmt "##",__FUNCTION__, ## __VA_ARGS__) -#define asrt(s) if(!(s)) ALOGE ("## %s assert %s failed at line:%d ##",__FUNCTION__, #s, __LINE__) +#define asrt(s) if(!(s)) BTIF_TRACE_ERROR3("## %s assert %s failed at line:%d ##",__FUNCTION__, #s, __LINE__) int sock_send_all(int sock_fd, const uint8_t* buf, int len) @@ -84,7 +79,7 @@ int sock_send_all(int sock_fd, const uint8_t* buf, int len) while(ret < 0 && errno == EINTR); if(ret <= 0) { - error("sock fd:%d send errno:%d, ret:%d", sock_fd, errno, ret); + BTIF_TRACE_ERROR3("sock fd:%d send errno:%d, ret:%d", sock_fd, errno, ret); return -1; } buf += ret; @@ -102,7 +97,7 @@ int sock_recv_all(int sock_fd, uint8_t* buf, int len) while(ret < 0 && errno == EINTR); if(ret <= 0) { - error("sock fd:%d recv errno:%d, ret:%d", sock_fd, errno, ret); + BTIF_TRACE_ERROR3("sock fd:%d recv errno:%d, ret:%d", sock_fd, errno, ret); return -1; } buf += ret; @@ -150,8 +145,8 @@ int sock_send_fd(int sock_fd, const uint8_t* buf, int len, int send_fd) } while (ret < 0 && errno == EINTR); if (ret < 0) { - error("fd:%d, send_fd:%d, sendmsg ret:%d, errno:%d, %s", - sock_fd, send_fd, (int)ret, errno, strerror(errno)); + BTIF_TRACE_ERROR5("fd:%d, send_fd:%d, sendmsg ret:%d, errno:%d, %s", + sock_fd, send_fd, (int)ret, errno, strerror(errno)); ret_len = -1; break; } @@ -162,7 +157,7 @@ int sock_send_fd(int sock_fd, const uint8_t* buf, int len, int send_fd) // Wipes out any msg_control too memset(&msg, 0, sizeof(msg)); } - debug("close fd:%d after sent", send_fd); + BTIF_TRACE_DEBUG1("close fd:%d after sent", send_fd); close(send_fd); return ret_len; } diff --git a/btif/src/btif_storage.c b/btif/src/btif_storage.c index 6d702a7..2190b1c 100755 --- a/btif/src/btif_storage.c +++ b/btif/src/btif_storage.c @@ -46,11 +46,6 @@ #include "btif_hh.h" #include <cutils/log.h> -#define info(fmt, ...) ALOGI ("%s(L%d): " fmt,__FUNCTION__, __LINE__, ## __VA_ARGS__) -#define debug(fmt, ...) ALOGD ("%s(L%d): " fmt,__FUNCTION__, __LINE__, ## __VA_ARGS__) -#define warn(fmt, ...) ALOGW ("## WARNING : %s(L%d): " fmt "##",__FUNCTION__, __LINE__, ## __VA_ARGS__) -#define error(fmt, ...) ALOGE ("## ERROR : %s(L%d): " fmt "##",__FUNCTION__, __LINE__, ## __VA_ARGS__) -#define asrt(s) if(!(s)) ALOGE ("## %s assert %s failed at line:%d ##",__FUNCTION__, #s, __LINE__) /************************************************************************************ ** Constants & Macros @@ -236,11 +231,11 @@ static int prop2cfg(bt_bdaddr_t *remote_bd_addr, bt_property_t *prop) bdstr_t bdstr = {0}; if(remote_bd_addr) bd2str(remote_bd_addr, &bdstr); - debug("in, bd addr:%s, prop type:%d, len:%d", bdstr, prop->type, prop->len); + BTIF_TRACE_DEBUG3("in, bd addr:%s, prop type:%d, len:%d", bdstr, prop->type, prop->len); char value[1024]; if(prop->len <= 0 || prop->len > (int)sizeof(value) - 1) { - error("property type:%d, len:%d is invalid", prop->type, prop->len); + BTIF_TRACE_ERROR2("property type:%d, len:%d is invalid", prop->type, prop->len); return FALSE; } switch(prop->type) @@ -298,7 +293,7 @@ static int prop2cfg(bt_bdaddr_t *remote_bd_addr, bt_property_t *prop) break; } default: - error("Unknow prop type:%d", prop->type); + BTIF_TRACE_ERROR1("Unknow prop type:%d", prop->type); return FALSE; } return TRUE; @@ -308,10 +303,10 @@ static int cfg2prop(bt_bdaddr_t *remote_bd_addr, bt_property_t *prop) bdstr_t bdstr = {0}; if(remote_bd_addr) bd2str(remote_bd_addr, &bdstr); - debug("in, bd addr:%s, prop type:%d, len:%d", bdstr, prop->type, prop->len); + BTIF_TRACE_DEBUG3("in, bd addr:%s, prop type:%d, len:%d", bdstr, prop->type, prop->len); if(prop->len <= 0) { - error("property type:%d, len:%d is invalid", prop->type, prop->len); + BTIF_TRACE_ERROR2("property type:%d, len:%d is invalid", prop->type, prop->len); return FALSE; } int ret = FALSE; @@ -389,7 +384,7 @@ static int cfg2prop(bt_bdaddr_t *remote_bd_addr, bt_property_t *prop) break; } default: - error("Unknow prop type:%d", prop->type); + BTIF_TRACE_ERROR1("Unknow prop type:%d", prop->type); return FALSE; } return ret; @@ -408,7 +403,7 @@ static int cfg2prop(bt_bdaddr_t *remote_bd_addr, bt_property_t *prop) *******************************************************************************/ static bt_status_t btif_in_fetch_bonded_devices(btif_bonded_devices_t *p_bonded_devices, int add) { - debug("in add:%d", add); + BTIF_TRACE_DEBUG1("in add:%d", add); memset(p_bonded_devices, 0, sizeof(btif_bonded_devices_t)); char kname[128], vname[128]; @@ -420,7 +415,7 @@ static bt_status_t btif_in_fetch_bonded_devices(btif_bonded_devices_t *p_bonded_ do { kpos = btif_config_next_key(kpos, "Remote", kname, &kname_size); - debug("Remote device:%s, size:%d", kname, kname_size); + BTIF_TRACE_DEBUG2("Remote device:%s, size:%d", kname, kname_size); int type = BTIF_CFG_TYPE_BIN; LINK_KEY link_key; int size = sizeof(link_key); @@ -443,13 +438,12 @@ static bt_status_t btif_in_fetch_bonded_devices(btif_bonded_devices_t *p_bonded_ } memcpy(&p_bonded_devices->devices[p_bonded_devices->num_devices++], &bd_addr, sizeof(bt_bdaddr_t)); } - else error("bounded device:%s, LinkKeyType or PinLength is invalid", kname); + else BTIF_TRACE_ERROR1("bounded device:%s, LinkKeyType or PinLength is invalid", kname); } - else debug("Remote device:%s, no link key", kname); + else BTIF_TRACE_DEBUG1("Remote device:%s, no link key", kname); kname_size = sizeof(kname); kname[0] = 0; } while(kpos != -1); - debug("out"); return BT_STATUS_SUCCESS; } @@ -717,7 +711,7 @@ bt_status_t btif_storage_remove_bonded_device(bt_bdaddr_t *remote_bd_addr) { bdstr_t bdstr; bd2str(remote_bd_addr, &bdstr); - debug("in bd addr:%s", bdstr); + BTIF_TRACE_DEBUG1("in bd addr:%s", bdstr); int ret = btif_config_remove("Remote", bdstr, "LinkKeyType"); ret &= btif_config_remove("Remote", bdstr, "PinLength"); ret &= btif_config_remove("Remote", bdstr, "LinkKey"); @@ -895,7 +889,6 @@ bt_status_t btif_storage_add_hid_device_info(bt_bdaddr_t *remote_bd_addr, *******************************************************************************/ bt_status_t btif_storage_load_bonded_hid_info(void) { - debug("in"); bt_bdaddr_t bd_addr; tBTA_HH_DEV_DSCP_INFO dscp_info; uint32_t i; @@ -913,7 +906,7 @@ bt_status_t btif_storage_load_bonded_hid_info(void) do { kpos = btif_config_next_key(kpos, "Remote", kname, &kname_size); - debug("Remote device:%s, size:%d", kname, kname_size); + BTIF_TRACE_DEBUG2("Remote device:%s, size:%d", kname, kname_size); int value; if(btif_config_get_int("Remote", kname, "HidAttrMask", &value)) { |