4747#include "shared-bindings/_bleio/Service.h"
4848#include "shared-bindings/_bleio/UUID.h"
4949
50+ #include "common-hal/_bleio/bonding.h"
51+
5052#define BLE_ADV_LENGTH_FIELD_SIZE 1
5153#define BLE_ADV_AD_TYPE_FIELD_SIZE 1
5254#define BLE_AD_TYPE_FLAGS_DATA_SIZE 1
@@ -212,7 +214,7 @@ bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in) {
212214 ble_gap_evt_auth_status_t * status = & ble_evt -> evt .gap_evt .params .auth_status ;
213215 self -> sec_status = status -> auth_status ;
214216 if (status -> auth_status == BLE_GAP_SEC_STATUS_SUCCESS ) {
215- self -> ediv = bonding_keys -> own_enc .master_id .ediv ;
217+ self -> ediv = self -> bonding_keys . own_enc .master_id .ediv ;
216218 self -> pair_status = PAIR_PAIRED ;
217219 bonding_save_keys (self -> is_central , self -> conn_handle , & self -> bonding_keys );
218220 } else {
@@ -227,13 +229,12 @@ bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in) {
227229 // - Else return NULL --> Initiate key exchange
228230 ble_gap_evt_sec_info_request_t * sec_info_request = & ble_evt -> evt .gap_evt .params .sec_info_request ;
229231 (void ) sec_info_request ;
230- bond_keys bond_keys_t ;
231232 if ( bonding_load_keys (self -> is_central , sec_info_request -> master_id .ediv , & self -> bonding_keys ) ) {
232- sd_ble_gap_sec_info_reply (self -> conn_handle
233+ sd_ble_gap_sec_info_reply (self -> conn_handle ,
233234 & self -> bonding_keys .own_enc .enc_info ,
234235 & self -> bonding_keys .peer_id .id_info ,
235236 NULL );
236- self -> ediv = bond_keys .own_enc .master_id .ediv ;
237+ self -> ediv = self -> bonding_keys .own_enc .master_id .ediv ;
237238 } else {
238239 sd_ble_gap_sec_info_reply (self -> conn_handle , NULL , NULL , NULL );
239240 }
@@ -249,12 +250,10 @@ bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in) {
249250 // mode >=1 and/or level >=1 means encryption is set up
250251 self -> pair_status = PAIR_NOT_PAIRED ;
251252 } else {
252- uint8_t * sys_attr ;
253- uint16_t sys_attr_len ;
254- if (bonding_load_cccd_info (self -> is_central , self -> conn_handle , self -> ediv , sys_attr , sys_attr_len )) {
255- sd_ble_gatts_sys_attr_set (self -> conn_handle , sys_attr , sys_attr_len , SVC_CONTEXT_FLAG );
256- // Not quite paired yet: wait for BLE_GAP_EVT_AUTH_STATUS SUCCESS.
257- self -> ediv = self -> bonding_keys .own_enc .master_id .ediv ;
253+ // Does an sd_ble_gatts_sys_attr_set() with the stored values.
254+ if (bonding_load_cccd_info (self -> is_central , self -> conn_handle , self -> ediv )) {
255+ // Not quite paired yet: wait for BLE_GAP_EVT_AUTH_STATUS SUCCESS.
256+ self -> ediv = self -> bonding_keys .own_enc .master_id .ediv ;
258257 } else {
259258 // No matching bonding found, so use fresh system attributes.
260259 sd_ble_gatts_sys_attr_set (self -> conn_handle , NULL , 0 , 0 );
@@ -263,10 +262,6 @@ bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in) {
263262 break ;
264263 }
265264
266- case BLE_GATTS_EVT_WRITE : {
267- if (self -> pair_status == PAIR_PAIRED ) & &
268-
269-
270265 default :
271266 return false;
272267 }
@@ -278,7 +273,7 @@ void bleio_connection_clear(bleio_connection_internal_t *self) {
278273
279274 self -> conn_handle = BLE_CONN_HANDLE_INVALID ;
280275 self -> pair_status = PAIR_NOT_PAIRED ;
281- bonding_clear_keys (self );
276+ bonding_clear_keys (& self -> bonding_keys );
282277}
283278
284279bool common_hal_bleio_connection_get_paired (bleio_connection_obj_t * self ) {
0 commit comments