Loading system/stack/btm/btm_ble.c +47 −29 Original line number Diff line number Diff line Loading @@ -72,32 +72,50 @@ 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) { BTM_TRACE_DEBUG ("%s: dev_type=0x%x", __func__, dev_type); tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(bd_addr); tBTM_SEC_DEV_REC *p_dev_rec; UINT8 i = 0; tBTM_INQ_INFO *p_info=NULL; 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; } BTM_TRACE_DEBUG ("BTM_SecAddBleDevice dev_type=0x%x", dev_type); p_dev_rec = btm_find_dev (bd_addr); p_dev_rec = osi_malloc(sizeof(tBTM_SEC_DEV_REC)); if (!p_dev_rec) { BTM_TRACE_DEBUG("Add a new device"); /* Initialize this record */ memset(p_dev_rec, 0, sizeof (tBTM_SEC_DEV_REC)); list_append(btm_cb.sec_dev_rec, p_dev_rec); /* 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]; /* Mark this record as in use and initialize */ memset (p_dev_rec, 0, sizeof (tBTM_SEC_DEV_REC)); p_dev_rec->sec_flags = BTM_SEC_IN_USE; 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 = 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.min_conn_int = p_dev_rec->conn_params.max_conn_int = p_dev_rec->conn_params.supervision_tout = p_dev_rec->conn_params.slave_latency = BTM_BLE_CONN_PARAM_UNDEF; BTM_TRACE_DEBUG("%s: Device added, handle=0x%x ", __func__, p_dev_rec->ble_hci_handle); 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"); } memset(p_dev_rec->sec_bd_name, 0, sizeof(tBTM_BD_NAME)); Loading @@ -113,7 +131,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*/ tBTM_INQ_INFO *p_info = BTM_InqDbRead(bd_addr); p_info = BTM_InqDbRead(bd_addr); if (p_info) { p_info->results.ble_addr_type = p_dev_rec->ble.ble_addr_type ; Loading @@ -122,7 +140,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 +84 −32 Original line number Diff line number Diff line Loading @@ -207,12 +207,38 @@ 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. ** to find a match, if not match, continue for next record. ** ** Returns TRUE on match, FALSE otherwise ** Returns None. ** *******************************************************************************/ static BOOLEAN btm_ble_proc_resolve_x(tSMP_ENC *p) Loading @@ -231,6 +257,7 @@ 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 @@ -315,8 +342,9 @@ BOOLEAN btm_ble_addr_resolvable (BD_ADDR rpa, tBTM_SEC_DEV_REC *p_dev_rec) ** Returns None. ** *******************************************************************************/ static BOOLEAN btm_ble_match_random_bda(void *data, void *context) static BOOLEAN btm_ble_match_random_bda(UINT16 rec_index) { #if (BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE) /* use the 3 MSB of bd address as prand */ tBTM_LE_RANDOM_CB *p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; Loading @@ -325,23 +353,37 @@ static BOOLEAN btm_ble_match_random_bda(void *data, void *context) rand[1] = p_mgnt_cb->random_bda[1]; rand[2] = p_mgnt_cb->random_bda[0]; BTM_TRACE_EVENT("%s next iteration", __func__); BTM_TRACE_EVENT("%s rec_index = %d", __func__, rec_index); if (rec_index < BTM_SEC_MAX_DEVICE_RECORDS) { tSMP_ENC output; tBTM_SEC_DEV_REC *p_dev_rec = data; tBTM_SEC_DEV_REC *p_dev_rec; p_dev_rec = &btm_cb.sec_dev_rec[rec_index]; 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)) return TRUE; if ((p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) && (p_dev_rec->ble.key_type & BTM_LE_KEY_PID)) { /* 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); // if it was match, finish iteration, otherwise continue return !btm_ble_proc_resolve_x(&output); return btm_ble_proc_resolve_x(&output); } else { // not completed return FALSE; } } else /* no match found */ { btm_ble_resolve_address_cmpl(); return TRUE; } #endif } /******************************************************************************* Loading @@ -358,24 +400,28 @@ 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("%s", __func__); if ( !p_mgnt_cb->busy) { BTM_TRACE_EVENT ("btm_ble_resolve_random_addr"); 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 */ 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); 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 (*p_cback)(NULL, p); } #endif Loading @@ -392,14 +438,20 @@ 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 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) { 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) { 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 +13 −18 Original line number Diff line number Diff line Loading @@ -920,16 +920,6 @@ 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 @@ -994,19 +984,24 @@ 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 */ 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; 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; } } 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 +2 −0 Original line number Diff line number Diff line Loading @@ -180,6 +180,8 @@ 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 +13 −25 Original line number Diff line number Diff line Loading @@ -214,13 +214,6 @@ 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 @@ -263,7 +256,8 @@ 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); list_foreach(btm_cb.sec_dev_rec, clear_resolving_list_bit, NULL); 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; } } Loading Loading @@ -928,18 +922,6 @@ 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 @@ -967,10 +949,16 @@ void btm_ble_enable_resolving_list_for_platform (UINT8 rl_mask) return; } list_node_t *n = list_foreach(btm_cb.sec_dev_rec, is_on_resolving_list, NULL); if (n) 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)) { btm_ble_enable_resolving_list(rl_mask); else return; } } btm_ble_disable_resolving_list(rl_mask, TRUE); } Loading Loading
system/stack/btm/btm_ble.c +47 −29 Original line number Diff line number Diff line Loading @@ -72,32 +72,50 @@ 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) { BTM_TRACE_DEBUG ("%s: dev_type=0x%x", __func__, dev_type); tBTM_SEC_DEV_REC *p_dev_rec = btm_find_dev(bd_addr); tBTM_SEC_DEV_REC *p_dev_rec; UINT8 i = 0; tBTM_INQ_INFO *p_info=NULL; 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; } BTM_TRACE_DEBUG ("BTM_SecAddBleDevice dev_type=0x%x", dev_type); p_dev_rec = btm_find_dev (bd_addr); p_dev_rec = osi_malloc(sizeof(tBTM_SEC_DEV_REC)); if (!p_dev_rec) { BTM_TRACE_DEBUG("Add a new device"); /* Initialize this record */ memset(p_dev_rec, 0, sizeof (tBTM_SEC_DEV_REC)); list_append(btm_cb.sec_dev_rec, p_dev_rec); /* 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]; /* Mark this record as in use and initialize */ memset (p_dev_rec, 0, sizeof (tBTM_SEC_DEV_REC)); p_dev_rec->sec_flags = BTM_SEC_IN_USE; 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 = 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.min_conn_int = p_dev_rec->conn_params.max_conn_int = p_dev_rec->conn_params.supervision_tout = p_dev_rec->conn_params.slave_latency = BTM_BLE_CONN_PARAM_UNDEF; BTM_TRACE_DEBUG("%s: Device added, handle=0x%x ", __func__, p_dev_rec->ble_hci_handle); 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"); } memset(p_dev_rec->sec_bd_name, 0, sizeof(tBTM_BD_NAME)); Loading @@ -113,7 +131,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*/ tBTM_INQ_INFO *p_info = BTM_InqDbRead(bd_addr); p_info = BTM_InqDbRead(bd_addr); if (p_info) { p_info->results.ble_addr_type = p_dev_rec->ble.ble_addr_type ; Loading @@ -122,7 +140,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 +84 −32 Original line number Diff line number Diff line Loading @@ -207,12 +207,38 @@ 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. ** to find a match, if not match, continue for next record. ** ** Returns TRUE on match, FALSE otherwise ** Returns None. ** *******************************************************************************/ static BOOLEAN btm_ble_proc_resolve_x(tSMP_ENC *p) Loading @@ -231,6 +257,7 @@ 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 @@ -315,8 +342,9 @@ BOOLEAN btm_ble_addr_resolvable (BD_ADDR rpa, tBTM_SEC_DEV_REC *p_dev_rec) ** Returns None. ** *******************************************************************************/ static BOOLEAN btm_ble_match_random_bda(void *data, void *context) static BOOLEAN btm_ble_match_random_bda(UINT16 rec_index) { #if (BLE_INCLUDED == TRUE && SMP_INCLUDED == TRUE) /* use the 3 MSB of bd address as prand */ tBTM_LE_RANDOM_CB *p_mgnt_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb; Loading @@ -325,23 +353,37 @@ static BOOLEAN btm_ble_match_random_bda(void *data, void *context) rand[1] = p_mgnt_cb->random_bda[1]; rand[2] = p_mgnt_cb->random_bda[0]; BTM_TRACE_EVENT("%s next iteration", __func__); BTM_TRACE_EVENT("%s rec_index = %d", __func__, rec_index); if (rec_index < BTM_SEC_MAX_DEVICE_RECORDS) { tSMP_ENC output; tBTM_SEC_DEV_REC *p_dev_rec = data; tBTM_SEC_DEV_REC *p_dev_rec; p_dev_rec = &btm_cb.sec_dev_rec[rec_index]; 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)) return TRUE; if ((p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) && (p_dev_rec->ble.key_type & BTM_LE_KEY_PID)) { /* 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); // if it was match, finish iteration, otherwise continue return !btm_ble_proc_resolve_x(&output); return btm_ble_proc_resolve_x(&output); } else { // not completed return FALSE; } } else /* no match found */ { btm_ble_resolve_address_cmpl(); return TRUE; } #endif } /******************************************************************************* Loading @@ -358,24 +400,28 @@ 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("%s", __func__); if ( !p_mgnt_cb->busy) { BTM_TRACE_EVENT ("btm_ble_resolve_random_addr"); 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 */ 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); 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 (*p_cback)(NULL, p); } #endif Loading @@ -392,14 +438,20 @@ 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 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) { 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) { 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 +13 −18 Original line number Diff line number Diff line Loading @@ -920,16 +920,6 @@ 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 @@ -994,19 +984,24 @@ 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 */ 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; 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; } } 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 +2 −0 Original line number Diff line number Diff line Loading @@ -180,6 +180,8 @@ 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 +13 −25 Original line number Diff line number Diff line Loading @@ -214,13 +214,6 @@ 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 @@ -263,7 +256,8 @@ 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); list_foreach(btm_cb.sec_dev_rec, clear_resolving_list_bit, NULL); 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; } } Loading Loading @@ -928,18 +922,6 @@ 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 @@ -967,10 +949,16 @@ void btm_ble_enable_resolving_list_for_platform (UINT8 rl_mask) return; } list_node_t *n = list_foreach(btm_cb.sec_dev_rec, is_on_resolving_list, NULL); if (n) 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)) { btm_ble_enable_resolving_list(rl_mask); else return; } } btm_ble_disable_resolving_list(rl_mask, TRUE); } Loading