Loading system/btif/src/btif_pan.c +65 −68 Original line number Diff line number Diff line Loading @@ -85,7 +85,9 @@ btpan_cb_t btpan_cb; static int jni_initialized, stack_initialized; static bool jni_initialized; static bool stack_initialized; static bt_status_t btpan_jni_init(const btpan_callbacks_t* callbacks); static void btpan_jni_cleanup(); static bt_status_t btpan_connect(const bt_bdaddr_t *bd_addr, int local_role, int remote_role); Loading Loading @@ -125,15 +127,15 @@ btpan_interface_t *btif_pan_get_interface() void btif_pan_init() { BTIF_TRACE_DEBUG("jni_initialized = %d, btpan_cb.enabled:%d", jni_initialized, btpan_cb.enabled); stack_initialized = TRUE; stack_initialized = true; if (jni_initialized && !btpan_cb.enabled) { BTIF_TRACE_DEBUG("Enabling PAN...."); memset(&btpan_cb, 0, sizeof(btpan_cb)); btpan_cb.tap_fd = INVALID_FD; btpan_cb.flow = 1; int i; for(i = 0; i < MAX_PAN_CONNS; i++) for (int i = 0; i < MAX_PAN_CONNS; i++) btpan_cleanup_conn(&btpan_cb.conns[i]); BTA_PanEnable(bta_pan_callback); btpan_cb.enabled = 1; Loading @@ -157,23 +159,23 @@ static void pan_disable() void btif_pan_cleanup() { if(stack_initialized) { //bt is shuting down, invalid all bta pan handles int i; for(i = 0; i < MAX_PAN_CONNS; i++) if (!stack_initialized) return; // Bluetooth is shuting down, invalidate all BTA PAN handles for (int i = 0; i < MAX_PAN_CONNS; i++) btpan_cleanup_conn(&btpan_cb.conns[i]); pan_disable(); } stack_initialized = FALSE; stack_initialized = false; } static btpan_callbacks_t callback; static bt_status_t btpan_jni_init(const btpan_callbacks_t* callbacks) { BTIF_TRACE_DEBUG("stack_initialized = %d, btpan_cb.enabled:%d", stack_initialized, btpan_cb.enabled); jni_initialized = TRUE; if (stack_initialized && !btpan_cb.enabled) jni_initialized = true; if (!stack_initialized && !btpan_cb.enabled) btif_pan_init(); callback = *callbacks; return BT_STATUS_SUCCESS; Loading @@ -182,7 +184,7 @@ static bt_status_t btpan_jni_init(const btpan_callbacks_t* callbacks) static void btpan_jni_cleanup() { pan_disable(); jni_initialized = FALSE; jni_initialized = false; } static inline int bta_role_to_btpan(int bta_pan_role) Loading @@ -190,13 +192,9 @@ static inline int bta_role_to_btpan(int bta_pan_role) int btpan_role = 0; BTIF_TRACE_DEBUG("bta_pan_role:0x%x", bta_pan_role); if (bta_pan_role & PAN_ROLE_NAP_SERVER) { btpan_role |= BTPAN_ROLE_PANNAP; } if (bta_pan_role & PAN_ROLE_CLIENT) { btpan_role |= BTPAN_ROLE_PANU; } return btpan_role; } Loading @@ -205,13 +203,9 @@ static inline int btpan_role_to_bta(int btpan_role) int bta_pan_role = PAN_ROLE_INACTIVE; BTIF_TRACE_DEBUG("btpan_role:0x%x", btpan_role); if (btpan_role & BTPAN_ROLE_PANNAP) { bta_pan_role |= PAN_ROLE_NAP_SERVER; } if (btpan_role & BTPAN_ROLE_PANU) { bta_pan_role |= PAN_ROLE_CLIENT; } return bta_pan_role; } Loading Loading @@ -407,8 +401,8 @@ int btpan_tap_open() /* open the clone device */ if( (fd = open(clonedev, O_RDWR)) < 0 ) { if ((fd = open(clonedev, O_RDWR)) < 0) { BTIF_TRACE_DEBUG("could not open %s, err:%d", clonedev, errno); return fd; } Loading Loading @@ -476,19 +470,21 @@ int btpan_tap_close(int fd) btpan_conn_t * btpan_find_conn_handle(UINT16 handle) { int i; for(i = 0; i < MAX_PAN_CONNS; i++) for (int i = 0; i < MAX_PAN_CONNS; i++) { if (btpan_cb.conns[i].handle == handle) return &btpan_cb.conns[i]; } return NULL; } btpan_conn_t* btpan_find_conn_addr(const BD_ADDR addr) { int i; for(i = 0; i < MAX_PAN_CONNS; i++) for (int i = 0; i < MAX_PAN_CONNS; i++) { if (memcmp(btpan_cb.conns[i].peer, addr, sizeof(BD_ADDR)) == 0) return &btpan_cb.conns[i]; } return NULL; } Loading @@ -506,8 +502,7 @@ 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; for(i = 0; i < MAX_PAN_CONNS; i++) for (int i = 0; i < MAX_PAN_CONNS; i++) { BTIF_TRACE_DEBUG("conns[%d]:%d", i, btpan_cb.conns[i].handle); if (btpan_cb.conns[i].handle == -1) Loading Loading @@ -545,10 +540,10 @@ static inline bool should_forward(tETH_HDR* hdr) static int forward_bnep(tETH_HDR* eth_hdr, BT_HDR *hdr) { int broadcast = eth_hdr->h_dest[0] & 1; int i; // Find the right connection to send this frame over. for (i = 0; i < MAX_PAN_CONNS; i++) { for (int i = 0; i < MAX_PAN_CONNS; i++) { UINT16 handle = btpan_cb.conns[i].handle; if (handle != (UINT16)-1 && (broadcast || memcmp(btpan_cb.conns[i].eth_addr, eth_hdr->h_dest, sizeof(BD_ADDR)) == 0 Loading @@ -571,6 +566,7 @@ static int forward_bnep(tETH_HDR* eth_hdr, BT_HDR *hdr) { static void bta_pan_callback_transfer(UINT16 event, char *p_param) { tBTA_PAN *p_data = (tBTA_PAN *)p_param; switch(event) { case BTA_PAN_ENABLE_EVT: Loading Loading @@ -738,14 +734,15 @@ static void btu_exec_tap_fd_read(void *p_param) { } static void btif_pan_close_all_conns() { int i; if (!stack_initialized) return; for (i = 0; i < MAX_PAN_CONNS; ++i) for (int i = 0; i < MAX_PAN_CONNS; ++i) { if (btpan_cb.conns[i].handle != -1) BTA_PanClose(btpan_cb.conns[i].handle); } } static void btpan_tap_fd_signaled(int fd, int type, int flags, uint32_t user_id) { assert(btpan_cb.tap_fd == INVALID_FD || btpan_cb.tap_fd == fd); Loading Loading
system/btif/src/btif_pan.c +65 −68 Original line number Diff line number Diff line Loading @@ -85,7 +85,9 @@ btpan_cb_t btpan_cb; static int jni_initialized, stack_initialized; static bool jni_initialized; static bool stack_initialized; static bt_status_t btpan_jni_init(const btpan_callbacks_t* callbacks); static void btpan_jni_cleanup(); static bt_status_t btpan_connect(const bt_bdaddr_t *bd_addr, int local_role, int remote_role); Loading Loading @@ -125,15 +127,15 @@ btpan_interface_t *btif_pan_get_interface() void btif_pan_init() { BTIF_TRACE_DEBUG("jni_initialized = %d, btpan_cb.enabled:%d", jni_initialized, btpan_cb.enabled); stack_initialized = TRUE; stack_initialized = true; if (jni_initialized && !btpan_cb.enabled) { BTIF_TRACE_DEBUG("Enabling PAN...."); memset(&btpan_cb, 0, sizeof(btpan_cb)); btpan_cb.tap_fd = INVALID_FD; btpan_cb.flow = 1; int i; for(i = 0; i < MAX_PAN_CONNS; i++) for (int i = 0; i < MAX_PAN_CONNS; i++) btpan_cleanup_conn(&btpan_cb.conns[i]); BTA_PanEnable(bta_pan_callback); btpan_cb.enabled = 1; Loading @@ -157,23 +159,23 @@ static void pan_disable() void btif_pan_cleanup() { if(stack_initialized) { //bt is shuting down, invalid all bta pan handles int i; for(i = 0; i < MAX_PAN_CONNS; i++) if (!stack_initialized) return; // Bluetooth is shuting down, invalidate all BTA PAN handles for (int i = 0; i < MAX_PAN_CONNS; i++) btpan_cleanup_conn(&btpan_cb.conns[i]); pan_disable(); } stack_initialized = FALSE; stack_initialized = false; } static btpan_callbacks_t callback; static bt_status_t btpan_jni_init(const btpan_callbacks_t* callbacks) { BTIF_TRACE_DEBUG("stack_initialized = %d, btpan_cb.enabled:%d", stack_initialized, btpan_cb.enabled); jni_initialized = TRUE; if (stack_initialized && !btpan_cb.enabled) jni_initialized = true; if (!stack_initialized && !btpan_cb.enabled) btif_pan_init(); callback = *callbacks; return BT_STATUS_SUCCESS; Loading @@ -182,7 +184,7 @@ static bt_status_t btpan_jni_init(const btpan_callbacks_t* callbacks) static void btpan_jni_cleanup() { pan_disable(); jni_initialized = FALSE; jni_initialized = false; } static inline int bta_role_to_btpan(int bta_pan_role) Loading @@ -190,13 +192,9 @@ static inline int bta_role_to_btpan(int bta_pan_role) int btpan_role = 0; BTIF_TRACE_DEBUG("bta_pan_role:0x%x", bta_pan_role); if (bta_pan_role & PAN_ROLE_NAP_SERVER) { btpan_role |= BTPAN_ROLE_PANNAP; } if (bta_pan_role & PAN_ROLE_CLIENT) { btpan_role |= BTPAN_ROLE_PANU; } return btpan_role; } Loading @@ -205,13 +203,9 @@ static inline int btpan_role_to_bta(int btpan_role) int bta_pan_role = PAN_ROLE_INACTIVE; BTIF_TRACE_DEBUG("btpan_role:0x%x", btpan_role); if (btpan_role & BTPAN_ROLE_PANNAP) { bta_pan_role |= PAN_ROLE_NAP_SERVER; } if (btpan_role & BTPAN_ROLE_PANU) { bta_pan_role |= PAN_ROLE_CLIENT; } return bta_pan_role; } Loading Loading @@ -407,8 +401,8 @@ int btpan_tap_open() /* open the clone device */ if( (fd = open(clonedev, O_RDWR)) < 0 ) { if ((fd = open(clonedev, O_RDWR)) < 0) { BTIF_TRACE_DEBUG("could not open %s, err:%d", clonedev, errno); return fd; } Loading Loading @@ -476,19 +470,21 @@ int btpan_tap_close(int fd) btpan_conn_t * btpan_find_conn_handle(UINT16 handle) { int i; for(i = 0; i < MAX_PAN_CONNS; i++) for (int i = 0; i < MAX_PAN_CONNS; i++) { if (btpan_cb.conns[i].handle == handle) return &btpan_cb.conns[i]; } return NULL; } btpan_conn_t* btpan_find_conn_addr(const BD_ADDR addr) { int i; for(i = 0; i < MAX_PAN_CONNS; i++) for (int i = 0; i < MAX_PAN_CONNS; i++) { if (memcmp(btpan_cb.conns[i].peer, addr, sizeof(BD_ADDR)) == 0) return &btpan_cb.conns[i]; } return NULL; } Loading @@ -506,8 +502,7 @@ 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; for(i = 0; i < MAX_PAN_CONNS; i++) for (int i = 0; i < MAX_PAN_CONNS; i++) { BTIF_TRACE_DEBUG("conns[%d]:%d", i, btpan_cb.conns[i].handle); if (btpan_cb.conns[i].handle == -1) Loading Loading @@ -545,10 +540,10 @@ static inline bool should_forward(tETH_HDR* hdr) static int forward_bnep(tETH_HDR* eth_hdr, BT_HDR *hdr) { int broadcast = eth_hdr->h_dest[0] & 1; int i; // Find the right connection to send this frame over. for (i = 0; i < MAX_PAN_CONNS; i++) { for (int i = 0; i < MAX_PAN_CONNS; i++) { UINT16 handle = btpan_cb.conns[i].handle; if (handle != (UINT16)-1 && (broadcast || memcmp(btpan_cb.conns[i].eth_addr, eth_hdr->h_dest, sizeof(BD_ADDR)) == 0 Loading @@ -571,6 +566,7 @@ static int forward_bnep(tETH_HDR* eth_hdr, BT_HDR *hdr) { static void bta_pan_callback_transfer(UINT16 event, char *p_param) { tBTA_PAN *p_data = (tBTA_PAN *)p_param; switch(event) { case BTA_PAN_ENABLE_EVT: Loading Loading @@ -738,14 +734,15 @@ static void btu_exec_tap_fd_read(void *p_param) { } static void btif_pan_close_all_conns() { int i; if (!stack_initialized) return; for (i = 0; i < MAX_PAN_CONNS; ++i) for (int i = 0; i < MAX_PAN_CONNS; ++i) { if (btpan_cb.conns[i].handle != -1) BTA_PanClose(btpan_cb.conns[i].handle); } } static void btpan_tap_fd_signaled(int fd, int type, int flags, uint32_t user_id) { assert(btpan_cb.tap_fd == INVALID_FD || btpan_cb.tap_fd == fd); Loading