Loading system/stack/btm/btm_ble.c +29 −47 Original line number Diff line number Diff line Loading @@ -72,50 +72,32 @@ extern void gatt_notify_enc_cmpl(BD_ADDR bd_addr); BOOLEAN BTM_SecAddBleDevice (BD_ADDR bd_addr, BD_NAME bd_name, tBT_DEVICE_TYPE dev_type, tBLE_ADDR_TYPE addr_type) { tBTM_SEC_DEV_REC *p_dev_rec; UINT8 i = 0; tBTM_INQ_INFO *p_info=NULL; BTM_TRACE_DEBUG ("BTM_SecAddBleDevice dev_type=0x%x", dev_type); p_dev_rec = btm_find_dev (bd_addr); BTM_TRACE_DEBUG ("%s: dev_type=0x%x", __func__, dev_type); tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(bd_addr); if (!p_dev_rec) { BTM_TRACE_DEBUG("Add a new device"); if (!p_dev_rec) { if (list_length(btm_cb.sec_dev_rec) > BTM_SEC_MAX_DEVICE_RECORDS) { BTM_TRACE_ERROR("%s: %d max devices reached!", __func__, BTM_SEC_MAX_DEVICE_RECORDS); return FALSE; } /* There is no device record, allocate one. * If we can not find an empty spot for this one, let it fail. */ for (i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i++) { if (!(btm_cb.sec_dev_rec[i].sec_flags & BTM_SEC_IN_USE)) { BTM_TRACE_DEBUG ("allocate a new dev rec idx=0x%x ", i ); p_dev_rec = &btm_cb.sec_dev_rec[i]; p_dev_rec = osi_malloc(sizeof(tBTM_SEC_DEV_REC)); /* Mark this record as in use and initialize */ /* Initialize this record */ memset(p_dev_rec, 0, sizeof (tBTM_SEC_DEV_REC)); p_dev_rec->sec_flags = BTM_SEC_IN_USE; list_append(btm_cb.sec_dev_rec, p_dev_rec); memcpy(p_dev_rec->bd_addr, bd_addr, BD_ADDR_LEN); p_dev_rec->hci_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_BR_EDR); p_dev_rec->ble_hci_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_LE); /* update conn params, use default value for background connection params */ p_dev_rec->conn_params.min_conn_int = p_dev_rec->conn_params.max_conn_int = p_dev_rec->conn_params.supervision_tout = p_dev_rec->conn_params.min_conn_int = BTM_BLE_CONN_PARAM_UNDEF; p_dev_rec->conn_params.max_conn_int = BTM_BLE_CONN_PARAM_UNDEF; p_dev_rec->conn_params.supervision_tout = BTM_BLE_CONN_PARAM_UNDEF; p_dev_rec->conn_params.slave_latency = BTM_BLE_CONN_PARAM_UNDEF; BTM_TRACE_DEBUG ("hci_handl=0x%x ", p_dev_rec->ble_hci_handle ); break; } } if (!p_dev_rec) return(FALSE); } else { BTM_TRACE_DEBUG("Device already exist"); BTM_TRACE_DEBUG("%s: Device added, handle=0x%x ", __func__, p_dev_rec->ble_hci_handle); } memset(p_dev_rec->sec_bd_name, 0, sizeof(tBTM_BD_NAME)); Loading @@ -131,7 +113,7 @@ BOOLEAN BTM_SecAddBleDevice (BD_ADDR bd_addr, BD_NAME bd_name, tBT_DEVICE_TYPE d memcpy(p_dev_rec->ble.pseudo_addr, bd_addr, BD_ADDR_LEN); /* sync up with the Inq Data base*/ p_info = BTM_InqDbRead(bd_addr); tBTM_INQ_INFO *p_info = BTM_InqDbRead(bd_addr); if (p_info) { p_info->results.ble_addr_type = p_dev_rec->ble.ble_addr_type ; Loading @@ -140,7 +122,7 @@ BOOLEAN BTM_SecAddBleDevice (BD_ADDR bd_addr, BD_NAME bd_name, tBT_DEVICE_TYPE d p_info->results.device_type, p_info->results.ble_addr_type); } return(TRUE); return TRUE; } /******************************************************************************* Loading system/stack/btm/btm_ble_addr.c +32 −82 Original line number Diff line number Diff line Loading @@ -207,38 +207,12 @@ void btm_gen_non_resolvable_private_addr (tBTM_BLE_ADDR_CBACK *p_cback, void *p) *******************************************************************************/ /******************************************************************************* ** ** Function btm_ble_resolve_address_cmpl ** ** Description This function sends the random address resolving complete ** callback. ** ** Returns None. ** *******************************************************************************/ static void btm_ble_resolve_address_cmpl(void) { tBTM_LE_RANDOM_CB *p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; tBTM_SEC_DEV_REC *p_dev_rec = NULL; BTM_TRACE_EVENT ("btm_ble_resolve_address_cmpl p_mgnt_cb->index = %d", p_mgnt_cb->index); if (p_mgnt_cb->index < BTM_SEC_MAX_DEVICE_RECORDS) { p_dev_rec = &btm_cb.sec_dev_rec[p_mgnt_cb->index]; } p_mgnt_cb->busy = FALSE; (* p_mgnt_cb->p_resolve_cback)(p_dev_rec, p_mgnt_cb->p); } /******************************************************************************* ** ** Function btm_ble_proc_resolve_x ** ** Description This function compares the X with random address 3 MSO bytes ** to find a match, if not match, continue for next record. ** to find a match. ** ** Returns None. ** Returns TRUE on match, FALSE otherwise ** *******************************************************************************/ static BOOLEAN btm_ble_proc_resolve_x(tSMP_ENC *p) Loading @@ -257,7 +231,6 @@ static BOOLEAN btm_ble_proc_resolve_x(tSMP_ENC *p) { /* match is found */ BTM_TRACE_EVENT ("match is found"); btm_ble_resolve_address_cmpl(); return TRUE; } } Loading Loading @@ -342,7 +315,7 @@ BOOLEAN btm_ble_addr_resolvable (BD_ADDR rpa, tBTM_SEC_DEV_REC *p_dev_rec) ** Returns None. ** *******************************************************************************/ static BOOLEAN btm_ble_match_random_bda(UINT16 rec_index) static BOOLEAN btm_ble_match_random_bda(void *data, void *context) { #if (BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE) /* use the 3 MSB of bd address as prand */ Loading @@ -353,36 +326,23 @@ static BOOLEAN btm_ble_match_random_bda(UINT16 rec_index) rand[1] = p_mgnt_cb->random_bda[1]; rand[2] = p_mgnt_cb->random_bda[0]; BTM_TRACE_EVENT("%s rec_index = %d", __func__, rec_index); BTM_TRACE_EVENT("%s next iteration", __func__); if (rec_index < BTM_SEC_MAX_DEVICE_RECORDS) { tSMP_ENC output; tBTM_SEC_DEV_REC *p_dev_rec; p_dev_rec = &btm_cb.sec_dev_rec[rec_index]; tBTM_SEC_DEV_REC *p_dev_rec = data; BTM_TRACE_DEBUG("sec_flags = %02x device_type = %d", p_dev_rec->sec_flags, p_dev_rec->device_type); if ((p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) && (p_dev_rec->ble.key_type & BTM_LE_KEY_PID)) { if (!(p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) || !(p_dev_rec->ble.key_type & BTM_LE_KEY_PID)) return TRUE; /* generate X = E irk(R0, R1, R2) and R is random address 3 LSO */ SMP_Encrypt(p_dev_rec->ble.keys.irk, BT_OCTET16_LEN, &rand[0], 3, &output); return btm_ble_proc_resolve_x(&output); } else { // not completed return FALSE; } } else /* no match found */ { btm_ble_resolve_address_cmpl(); return TRUE; } // if it was match, finish iteration, otherwise continue return !btm_ble_proc_resolve_x(&output); #endif } Loading @@ -400,29 +360,25 @@ void btm_ble_resolve_random_addr(BD_ADDR random_bda, tBTM_BLE_RESOLVE_CBACK * p_ { tBTM_LE_RANDOM_CB *p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; BTM_TRACE_EVENT ("btm_ble_resolve_random_addr"); if ( !p_mgnt_cb->busy) { BTM_TRACE_EVENT("%s", __func__); if ( !p_mgnt_cb->busy) { p_mgnt_cb->p = p; p_mgnt_cb->busy = TRUE; p_mgnt_cb->index = 0; p_mgnt_cb->p_resolve_cback = p_cback; memcpy(p_mgnt_cb->random_bda, random_bda, BD_ADDR_LEN); /* start to resolve random address */ /* check for next security record */ while (TRUE) { if (btm_ble_match_random_bda(p_mgnt_cb->index)) { /* atch found or went through the list */ break; } p_mgnt_cb->index ++; } } else list_node_t * n = list_foreach(btm_cb.sec_dev_rec, btm_ble_match_random_bda, NULL); tBTM_SEC_DEV_REC *p_dev_rec = n ? list_node(n) : NULL; BTM_TRACE_EVENT("%s: %sresolved", __func__, (p_dev_rec == NULL ? "not " : "")); p_mgnt_cb->busy = FALSE; (*p_cback)(p_dev_rec, p); } else { (*p_cback)(NULL, p); } } #endif /******************************************************************************* Loading @@ -438,20 +394,14 @@ void btm_ble_resolve_random_addr(BD_ADDR random_bda, tBTM_BLE_RESOLVE_CBACK * p_ tBTM_SEC_DEV_REC* btm_find_dev_by_identity_addr(BD_ADDR bd_addr, UINT8 addr_type) { #if BLE_PRIVACY_SPT == TRUE UINT8 i; tBTM_SEC_DEV_REC *p_dev_rec = &btm_cb.sec_dev_rec[0]; for (i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i ++, p_dev_rec ++) { if ((p_dev_rec->sec_flags & BTM_SEC_IN_USE) && memcmp(p_dev_rec->ble.static_addr, bd_addr, BD_ADDR_LEN) == 0) { list_node_t *end = list_end(btm_cb.sec_dev_rec); for (list_node_t *node = list_begin(btm_cb.sec_dev_rec); node != end; node = list_next(node)) { tBTM_SEC_DEV_REC *p_dev_rec = list_node(node); if (memcmp(p_dev_rec->ble.static_addr, bd_addr, BD_ADDR_LEN) == 0) { if ((p_dev_rec->ble.static_addr_type & (~BLE_ADDR_TYPE_ID_BIT)) != (addr_type & (~BLE_ADDR_TYPE_ID_BIT))) { BTM_TRACE_WARNING("%s find pseudo->random match with diff addr type: %d vs %d", __func__, p_dev_rec->ble.static_addr_type, addr_type); } /* found the match */ return p_dev_rec; Loading system/stack/btm/btm_ble_gap.c +18 −13 Original line number Diff line number Diff line Loading @@ -920,6 +920,16 @@ tBTM_STATUS BTM_BleSetConnectableMode(tBTM_BLE_CONN_MODE connectable_mode) return btm_ble_set_connectability( p_cb->connectable_mode); } static bool is_resolving_list_bit_set(void *data, void *context) { tBTM_SEC_DEV_REC *p_dev_rec = data; if (p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT != 0) return false; return true; } /******************************************************************************* ** ** Function btm_set_conn_mode_adv_init_addr Loading Loading @@ -984,24 +994,19 @@ static UINT8 btm_set_conn_mode_adv_init_addr(tBTM_BLE_INQ_CB *p_cb, if ((btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_1_2 && p_cb->afp != AP_SCAN_CONN_ALL) || btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_MIXED) { list_node_t *n = list_foreach(btm_cb.sec_dev_rec, is_resolving_list_bit_set, NULL); if (n) { /* if enhanced privacy is required, set Identity address and matching IRK peer */ for (i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i ++) { if ((btm_cb.sec_dev_rec[i].sec_flags & BTM_SEC_IN_USE) != 0 && (btm_cb.sec_dev_rec[i].ble.in_controller_list & BTM_RESOLVING_LIST_BIT) != 0) { memcpy(p_peer_addr_ptr, btm_cb.sec_dev_rec[i].ble.static_addr, BD_ADDR_LEN); *p_peer_addr_type = btm_cb.sec_dev_rec[i].ble.static_addr_type; break; } } tBTM_SEC_DEV_REC *p_dev_rec = list_node(n); memcpy(p_peer_addr_ptr, p_dev_rec->ble.static_addr, BD_ADDR_LEN); *p_peer_addr_type = p_dev_rec->ble.static_addr_type; if (i != BTM_SEC_MAX_DEVICE_RECORDS) *p_own_addr_type = BLE_ADDR_RANDOM_ID; else } else { /* resolving list is empty, not enabled */ *p_own_addr_type = BLE_ADDR_RANDOM; } } /* privacy 1.1, or privacy 1.2, general discoverable/connectable mode, disable privacy in */ /* controller fall back to host based privacy */ else if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE) Loading system/stack/btm/btm_ble_int.h +0 −2 Original line number Diff line number Diff line Loading @@ -180,8 +180,6 @@ typedef struct BD_ADDR private_addr; BD_ADDR random_bda; BOOLEAN busy; UINT16 index; tBTM_BLE_RESOLVE_CBACK *p_resolve_cback; tBTM_BLE_ADDR_CBACK *p_generate_cback; void *p; alarm_t *refresh_raddr_timer; Loading system/stack/btm/btm_ble_privacy.c +25 −14 Original line number Diff line number Diff line Loading @@ -214,6 +214,13 @@ void btm_ble_update_resolving_list(BD_ADDR pseudo_bda, BOOLEAN add) } } bool clear_resolving_list_bit(void *data, void *context) { tBTM_SEC_DEV_REC *p_dev_rec = data; p_dev_rec->ble.in_controller_list &= ~BTM_RESOLVING_LIST_BIT; return true; } /******************************************************************************* ** ** Function btm_ble_clear_resolving_list_complete Loading Loading @@ -256,8 +263,7 @@ void btm_ble_clear_resolving_list_complete(UINT8 *p, UINT16 evt_len) BTM_TRACE_DEBUG("%s resolving_list_avail_size=%d", __func__, btm_cb.ble_ctr_cb.resolving_list_avail_size); for (UINT8 i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; ++i) btm_cb.sec_dev_rec[i].ble.in_controller_list &= ~BTM_RESOLVING_LIST_BIT; list_foreach(btm_cb.sec_dev_rec, clear_resolving_list_bit, NULL); } } Loading Loading @@ -769,7 +775,6 @@ BOOLEAN btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec) /* only add RPA enabled device into resolving list */ if (p_dev_rec != NULL && /* RPA is being used and PID is known */ (p_dev_rec->sec_flags & BTM_SEC_IN_USE) != 0 && ((p_dev_rec->ble.key_type & BTM_LE_KEY_PID) != 0 || (p_dev_rec->ble.key_type & BTM_LE_KEY_LID) != 0)) { Loading Loading @@ -922,6 +927,18 @@ BOOLEAN btm_ble_resolving_list_empty(void) btm_cb.ble_ctr_cb.resolving_list_avail_size); } bool is_on_resolving_list(void *data, void *context) { tBTM_SEC_DEV_REC *p_dev = data; if ((p_dev->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) && (p_dev->ble.in_controller_list & BTM_WHITE_LIST_BIT)) return false; return true; } /******************************************************************************* ** ** Function btm_ble_enable_resolving_list_for_platform Loading Loading @@ -949,16 +966,10 @@ void btm_ble_enable_resolving_list_for_platform (UINT8 rl_mask) return; } tBTM_SEC_DEV_REC *p_dev = &btm_cb.sec_dev_rec[0]; for (UINT8 i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i ++, p_dev ++) { if ((p_dev->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) && (p_dev->ble.in_controller_list & BTM_WHITE_LIST_BIT)) { list_node_t *n = list_foreach(btm_cb.sec_dev_rec, is_on_resolving_list, NULL); if (n) btm_ble_enable_resolving_list(rl_mask); return; } } else btm_ble_disable_resolving_list(rl_mask, TRUE); } Loading Loading
system/stack/btm/btm_ble.c +29 −47 Original line number Diff line number Diff line Loading @@ -72,50 +72,32 @@ extern void gatt_notify_enc_cmpl(BD_ADDR bd_addr); BOOLEAN BTM_SecAddBleDevice (BD_ADDR bd_addr, BD_NAME bd_name, tBT_DEVICE_TYPE dev_type, tBLE_ADDR_TYPE addr_type) { tBTM_SEC_DEV_REC *p_dev_rec; UINT8 i = 0; tBTM_INQ_INFO *p_info=NULL; BTM_TRACE_DEBUG ("BTM_SecAddBleDevice dev_type=0x%x", dev_type); p_dev_rec = btm_find_dev (bd_addr); BTM_TRACE_DEBUG ("%s: dev_type=0x%x", __func__, dev_type); tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(bd_addr); if (!p_dev_rec) { BTM_TRACE_DEBUG("Add a new device"); if (!p_dev_rec) { if (list_length(btm_cb.sec_dev_rec) > BTM_SEC_MAX_DEVICE_RECORDS) { BTM_TRACE_ERROR("%s: %d max devices reached!", __func__, BTM_SEC_MAX_DEVICE_RECORDS); return FALSE; } /* There is no device record, allocate one. * If we can not find an empty spot for this one, let it fail. */ for (i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i++) { if (!(btm_cb.sec_dev_rec[i].sec_flags & BTM_SEC_IN_USE)) { BTM_TRACE_DEBUG ("allocate a new dev rec idx=0x%x ", i ); p_dev_rec = &btm_cb.sec_dev_rec[i]; p_dev_rec = osi_malloc(sizeof(tBTM_SEC_DEV_REC)); /* Mark this record as in use and initialize */ /* Initialize this record */ memset(p_dev_rec, 0, sizeof (tBTM_SEC_DEV_REC)); p_dev_rec->sec_flags = BTM_SEC_IN_USE; list_append(btm_cb.sec_dev_rec, p_dev_rec); memcpy(p_dev_rec->bd_addr, bd_addr, BD_ADDR_LEN); p_dev_rec->hci_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_BR_EDR); p_dev_rec->ble_hci_handle = BTM_GetHCIConnHandle(bd_addr, BT_TRANSPORT_LE); /* update conn params, use default value for background connection params */ p_dev_rec->conn_params.min_conn_int = p_dev_rec->conn_params.max_conn_int = p_dev_rec->conn_params.supervision_tout = p_dev_rec->conn_params.min_conn_int = BTM_BLE_CONN_PARAM_UNDEF; p_dev_rec->conn_params.max_conn_int = BTM_BLE_CONN_PARAM_UNDEF; p_dev_rec->conn_params.supervision_tout = BTM_BLE_CONN_PARAM_UNDEF; p_dev_rec->conn_params.slave_latency = BTM_BLE_CONN_PARAM_UNDEF; BTM_TRACE_DEBUG ("hci_handl=0x%x ", p_dev_rec->ble_hci_handle ); break; } } if (!p_dev_rec) return(FALSE); } else { BTM_TRACE_DEBUG("Device already exist"); BTM_TRACE_DEBUG("%s: Device added, handle=0x%x ", __func__, p_dev_rec->ble_hci_handle); } memset(p_dev_rec->sec_bd_name, 0, sizeof(tBTM_BD_NAME)); Loading @@ -131,7 +113,7 @@ BOOLEAN BTM_SecAddBleDevice (BD_ADDR bd_addr, BD_NAME bd_name, tBT_DEVICE_TYPE d memcpy(p_dev_rec->ble.pseudo_addr, bd_addr, BD_ADDR_LEN); /* sync up with the Inq Data base*/ p_info = BTM_InqDbRead(bd_addr); tBTM_INQ_INFO *p_info = BTM_InqDbRead(bd_addr); if (p_info) { p_info->results.ble_addr_type = p_dev_rec->ble.ble_addr_type ; Loading @@ -140,7 +122,7 @@ BOOLEAN BTM_SecAddBleDevice (BD_ADDR bd_addr, BD_NAME bd_name, tBT_DEVICE_TYPE d p_info->results.device_type, p_info->results.ble_addr_type); } return(TRUE); return TRUE; } /******************************************************************************* Loading
system/stack/btm/btm_ble_addr.c +32 −82 Original line number Diff line number Diff line Loading @@ -207,38 +207,12 @@ void btm_gen_non_resolvable_private_addr (tBTM_BLE_ADDR_CBACK *p_cback, void *p) *******************************************************************************/ /******************************************************************************* ** ** Function btm_ble_resolve_address_cmpl ** ** Description This function sends the random address resolving complete ** callback. ** ** Returns None. ** *******************************************************************************/ static void btm_ble_resolve_address_cmpl(void) { tBTM_LE_RANDOM_CB *p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; tBTM_SEC_DEV_REC *p_dev_rec = NULL; BTM_TRACE_EVENT ("btm_ble_resolve_address_cmpl p_mgnt_cb->index = %d", p_mgnt_cb->index); if (p_mgnt_cb->index < BTM_SEC_MAX_DEVICE_RECORDS) { p_dev_rec = &btm_cb.sec_dev_rec[p_mgnt_cb->index]; } p_mgnt_cb->busy = FALSE; (* p_mgnt_cb->p_resolve_cback)(p_dev_rec, p_mgnt_cb->p); } /******************************************************************************* ** ** Function btm_ble_proc_resolve_x ** ** Description This function compares the X with random address 3 MSO bytes ** to find a match, if not match, continue for next record. ** to find a match. ** ** Returns None. ** Returns TRUE on match, FALSE otherwise ** *******************************************************************************/ static BOOLEAN btm_ble_proc_resolve_x(tSMP_ENC *p) Loading @@ -257,7 +231,6 @@ static BOOLEAN btm_ble_proc_resolve_x(tSMP_ENC *p) { /* match is found */ BTM_TRACE_EVENT ("match is found"); btm_ble_resolve_address_cmpl(); return TRUE; } } Loading Loading @@ -342,7 +315,7 @@ BOOLEAN btm_ble_addr_resolvable (BD_ADDR rpa, tBTM_SEC_DEV_REC *p_dev_rec) ** Returns None. ** *******************************************************************************/ static BOOLEAN btm_ble_match_random_bda(UINT16 rec_index) static BOOLEAN btm_ble_match_random_bda(void *data, void *context) { #if (BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE) /* use the 3 MSB of bd address as prand */ Loading @@ -353,36 +326,23 @@ static BOOLEAN btm_ble_match_random_bda(UINT16 rec_index) rand[1] = p_mgnt_cb->random_bda[1]; rand[2] = p_mgnt_cb->random_bda[0]; BTM_TRACE_EVENT("%s rec_index = %d", __func__, rec_index); BTM_TRACE_EVENT("%s next iteration", __func__); if (rec_index < BTM_SEC_MAX_DEVICE_RECORDS) { tSMP_ENC output; tBTM_SEC_DEV_REC *p_dev_rec; p_dev_rec = &btm_cb.sec_dev_rec[rec_index]; tBTM_SEC_DEV_REC *p_dev_rec = data; BTM_TRACE_DEBUG("sec_flags = %02x device_type = %d", p_dev_rec->sec_flags, p_dev_rec->device_type); if ((p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) && (p_dev_rec->ble.key_type & BTM_LE_KEY_PID)) { if (!(p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) || !(p_dev_rec->ble.key_type & BTM_LE_KEY_PID)) return TRUE; /* generate X = E irk(R0, R1, R2) and R is random address 3 LSO */ SMP_Encrypt(p_dev_rec->ble.keys.irk, BT_OCTET16_LEN, &rand[0], 3, &output); return btm_ble_proc_resolve_x(&output); } else { // not completed return FALSE; } } else /* no match found */ { btm_ble_resolve_address_cmpl(); return TRUE; } // if it was match, finish iteration, otherwise continue return !btm_ble_proc_resolve_x(&output); #endif } Loading @@ -400,29 +360,25 @@ void btm_ble_resolve_random_addr(BD_ADDR random_bda, tBTM_BLE_RESOLVE_CBACK * p_ { tBTM_LE_RANDOM_CB *p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; BTM_TRACE_EVENT ("btm_ble_resolve_random_addr"); if ( !p_mgnt_cb->busy) { BTM_TRACE_EVENT("%s", __func__); if ( !p_mgnt_cb->busy) { p_mgnt_cb->p = p; p_mgnt_cb->busy = TRUE; p_mgnt_cb->index = 0; p_mgnt_cb->p_resolve_cback = p_cback; memcpy(p_mgnt_cb->random_bda, random_bda, BD_ADDR_LEN); /* start to resolve random address */ /* check for next security record */ while (TRUE) { if (btm_ble_match_random_bda(p_mgnt_cb->index)) { /* atch found or went through the list */ break; } p_mgnt_cb->index ++; } } else list_node_t * n = list_foreach(btm_cb.sec_dev_rec, btm_ble_match_random_bda, NULL); tBTM_SEC_DEV_REC *p_dev_rec = n ? list_node(n) : NULL; BTM_TRACE_EVENT("%s: %sresolved", __func__, (p_dev_rec == NULL ? "not " : "")); p_mgnt_cb->busy = FALSE; (*p_cback)(p_dev_rec, p); } else { (*p_cback)(NULL, p); } } #endif /******************************************************************************* Loading @@ -438,20 +394,14 @@ void btm_ble_resolve_random_addr(BD_ADDR random_bda, tBTM_BLE_RESOLVE_CBACK * p_ tBTM_SEC_DEV_REC* btm_find_dev_by_identity_addr(BD_ADDR bd_addr, UINT8 addr_type) { #if BLE_PRIVACY_SPT == TRUE UINT8 i; tBTM_SEC_DEV_REC *p_dev_rec = &btm_cb.sec_dev_rec[0]; for (i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i ++, p_dev_rec ++) { if ((p_dev_rec->sec_flags & BTM_SEC_IN_USE) && memcmp(p_dev_rec->ble.static_addr, bd_addr, BD_ADDR_LEN) == 0) { list_node_t *end = list_end(btm_cb.sec_dev_rec); for (list_node_t *node = list_begin(btm_cb.sec_dev_rec); node != end; node = list_next(node)) { tBTM_SEC_DEV_REC *p_dev_rec = list_node(node); if (memcmp(p_dev_rec->ble.static_addr, bd_addr, BD_ADDR_LEN) == 0) { if ((p_dev_rec->ble.static_addr_type & (~BLE_ADDR_TYPE_ID_BIT)) != (addr_type & (~BLE_ADDR_TYPE_ID_BIT))) { BTM_TRACE_WARNING("%s find pseudo->random match with diff addr type: %d vs %d", __func__, p_dev_rec->ble.static_addr_type, addr_type); } /* found the match */ return p_dev_rec; Loading
system/stack/btm/btm_ble_gap.c +18 −13 Original line number Diff line number Diff line Loading @@ -920,6 +920,16 @@ tBTM_STATUS BTM_BleSetConnectableMode(tBTM_BLE_CONN_MODE connectable_mode) return btm_ble_set_connectability( p_cb->connectable_mode); } static bool is_resolving_list_bit_set(void *data, void *context) { tBTM_SEC_DEV_REC *p_dev_rec = data; if (p_dev_rec->ble.in_controller_list & BTM_RESOLVING_LIST_BIT != 0) return false; return true; } /******************************************************************************* ** ** Function btm_set_conn_mode_adv_init_addr Loading Loading @@ -984,24 +994,19 @@ static UINT8 btm_set_conn_mode_adv_init_addr(tBTM_BLE_INQ_CB *p_cb, if ((btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_1_2 && p_cb->afp != AP_SCAN_CONN_ALL) || btm_cb.ble_ctr_cb.privacy_mode == BTM_PRIVACY_MIXED) { list_node_t *n = list_foreach(btm_cb.sec_dev_rec, is_resolving_list_bit_set, NULL); if (n) { /* if enhanced privacy is required, set Identity address and matching IRK peer */ for (i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i ++) { if ((btm_cb.sec_dev_rec[i].sec_flags & BTM_SEC_IN_USE) != 0 && (btm_cb.sec_dev_rec[i].ble.in_controller_list & BTM_RESOLVING_LIST_BIT) != 0) { memcpy(p_peer_addr_ptr, btm_cb.sec_dev_rec[i].ble.static_addr, BD_ADDR_LEN); *p_peer_addr_type = btm_cb.sec_dev_rec[i].ble.static_addr_type; break; } } tBTM_SEC_DEV_REC *p_dev_rec = list_node(n); memcpy(p_peer_addr_ptr, p_dev_rec->ble.static_addr, BD_ADDR_LEN); *p_peer_addr_type = p_dev_rec->ble.static_addr_type; if (i != BTM_SEC_MAX_DEVICE_RECORDS) *p_own_addr_type = BLE_ADDR_RANDOM_ID; else } else { /* resolving list is empty, not enabled */ *p_own_addr_type = BLE_ADDR_RANDOM; } } /* privacy 1.1, or privacy 1.2, general discoverable/connectable mode, disable privacy in */ /* controller fall back to host based privacy */ else if (btm_cb.ble_ctr_cb.privacy_mode != BTM_PRIVACY_NONE) Loading
system/stack/btm/btm_ble_int.h +0 −2 Original line number Diff line number Diff line Loading @@ -180,8 +180,6 @@ typedef struct BD_ADDR private_addr; BD_ADDR random_bda; BOOLEAN busy; UINT16 index; tBTM_BLE_RESOLVE_CBACK *p_resolve_cback; tBTM_BLE_ADDR_CBACK *p_generate_cback; void *p; alarm_t *refresh_raddr_timer; Loading
system/stack/btm/btm_ble_privacy.c +25 −14 Original line number Diff line number Diff line Loading @@ -214,6 +214,13 @@ void btm_ble_update_resolving_list(BD_ADDR pseudo_bda, BOOLEAN add) } } bool clear_resolving_list_bit(void *data, void *context) { tBTM_SEC_DEV_REC *p_dev_rec = data; p_dev_rec->ble.in_controller_list &= ~BTM_RESOLVING_LIST_BIT; return true; } /******************************************************************************* ** ** Function btm_ble_clear_resolving_list_complete Loading Loading @@ -256,8 +263,7 @@ void btm_ble_clear_resolving_list_complete(UINT8 *p, UINT16 evt_len) BTM_TRACE_DEBUG("%s resolving_list_avail_size=%d", __func__, btm_cb.ble_ctr_cb.resolving_list_avail_size); for (UINT8 i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; ++i) btm_cb.sec_dev_rec[i].ble.in_controller_list &= ~BTM_RESOLVING_LIST_BIT; list_foreach(btm_cb.sec_dev_rec, clear_resolving_list_bit, NULL); } } Loading Loading @@ -769,7 +775,6 @@ BOOLEAN btm_ble_resolving_list_load_dev(tBTM_SEC_DEV_REC *p_dev_rec) /* only add RPA enabled device into resolving list */ if (p_dev_rec != NULL && /* RPA is being used and PID is known */ (p_dev_rec->sec_flags & BTM_SEC_IN_USE) != 0 && ((p_dev_rec->ble.key_type & BTM_LE_KEY_PID) != 0 || (p_dev_rec->ble.key_type & BTM_LE_KEY_LID) != 0)) { Loading Loading @@ -922,6 +927,18 @@ BOOLEAN btm_ble_resolving_list_empty(void) btm_cb.ble_ctr_cb.resolving_list_avail_size); } bool is_on_resolving_list(void *data, void *context) { tBTM_SEC_DEV_REC *p_dev = data; if ((p_dev->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) && (p_dev->ble.in_controller_list & BTM_WHITE_LIST_BIT)) return false; return true; } /******************************************************************************* ** ** Function btm_ble_enable_resolving_list_for_platform Loading Loading @@ -949,16 +966,10 @@ void btm_ble_enable_resolving_list_for_platform (UINT8 rl_mask) return; } tBTM_SEC_DEV_REC *p_dev = &btm_cb.sec_dev_rec[0]; for (UINT8 i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i ++, p_dev ++) { if ((p_dev->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) && (p_dev->ble.in_controller_list & BTM_WHITE_LIST_BIT)) { list_node_t *n = list_foreach(btm_cb.sec_dev_rec, is_on_resolving_list, NULL); if (n) btm_ble_enable_resolving_list(rl_mask); return; } } else btm_ble_disable_resolving_list(rl_mask, TRUE); } Loading