@@ -123,6 +123,17 @@ bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in) {
123
123
break ;
124
124
}
125
125
126
+ case BLE_GATTS_EVT_WRITE :
127
+ // A client wrote a value.
128
+ // If we are bonded and it's a CCCD (UUID 0x2902), store the CCCD value.
129
+ if (self -> conn_handle != BLE_CONN_HANDLE_INVALID &&
130
+ self -> pair_status == PAIR_PAIRED &&
131
+ ble_evt -> evt .gatts_evt .params .write .uuid .type == BLE_UUID_TYPE_BLE &&
132
+ ble_evt -> evt .gatts_evt .params .write .uuid .uuid == 0x2902 ) {
133
+ bonding_save_cccd_info (self -> is_central , self -> conn_handle , self -> ediv );
134
+ }
135
+ break ;
136
+
126
137
case BLE_GATTS_EVT_SYS_ATTR_MISSING :
127
138
sd_ble_gatts_sys_attr_set (self -> conn_handle , NULL , 0 , 0 );
128
139
break ;
@@ -223,7 +234,7 @@ bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in) {
223
234
224
235
case BLE_GAP_EVT_AUTH_STATUS : { // 0x19
225
236
CONNECTION_DEBUG_PRINTF ("BLE_GAP_EVT_AUTH_STATUS\n" );
226
- // Pairing process completed
237
+ // Key exchange completed.
227
238
ble_gap_evt_auth_status_t * status = & ble_evt -> evt .gap_evt .params .auth_status ;
228
239
self -> sec_status = status -> auth_status ;
229
240
if (status -> auth_status == BLE_GAP_SEC_STATUS_SUCCESS ) {
@@ -264,8 +275,10 @@ bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in) {
264
275
}
265
276
266
277
case BLE_GAP_EVT_CONN_SEC_UPDATE : { // 0x1a
267
- CONNECTION_DEBUG_PRINTF ( "BLE_GAP_EVT_CONN_SEC_UPDATE\n" );
278
+ // We get this both on first-time pairing and on subsequent pairings using stored keys.
268
279
ble_gap_conn_sec_t * conn_sec = & ble_evt -> evt .gap_evt .params .conn_sec_update .conn_sec ;
280
+ CONNECTION_DEBUG_PRINTF ("BLE_GAP_EVT_CONN_SEC_UPDATE, sm: %d, lv: %d\n" ,
281
+ conn_sec -> sec_mode .sm , conn_sec -> sec_mode .lv );
269
282
if (conn_sec -> sec_mode .sm <= 1 && conn_sec -> sec_mode .lv <= 1 ) {
270
283
// Security setup did not succeed:
271
284
// mode 0, level 0 means no access
@@ -282,6 +295,7 @@ bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in) {
282
295
CONNECTION_DEBUG_PRINTF ("bonding_load_cccd_info() failed\n" );
283
296
sd_ble_gatts_sys_attr_set (self -> conn_handle , NULL , 0 , 0 );
284
297
}
298
+ self -> pair_status = PAIR_PAIRED ;
285
299
}
286
300
break ;
287
301
}
0 commit comments