@@ -63,7 +63,7 @@ int bleio_connection_event_cb(struct ble_gap_event *event, void *connection_in)
63
63
connection -> pair_status = PAIR_NOT_PAIRED ;
64
64
65
65
#if CIRCUITPY_VERBOSE_BLE
66
- mp_printf (& mp_plat_print , "disconnected %02x \n" , event -> disconnect .reason );
66
+ mp_printf (& mp_plat_print , "event->disconnect.reason: 0x%x \n" , event -> disconnect .reason );
67
67
#endif
68
68
if (connection -> connection_obj != mp_const_none ) {
69
69
bleio_connection_obj_t * obj = connection -> connection_obj ;
@@ -128,6 +128,7 @@ bool common_hal_bleio_connection_get_connected(bleio_connection_obj_t *self) {
128
128
}
129
129
130
130
void common_hal_bleio_connection_disconnect (bleio_connection_internal_t * self ) {
131
+ // Second argument is an HCI reason, not an HS error code.
131
132
ble_gap_terminate (self -> conn_handle , BLE_ERR_REM_USER_CONN_TERM );
132
133
}
133
134
@@ -162,9 +163,9 @@ STATIC int _discovered_service_cb(uint16_t conn_handle,
162
163
void * arg ) {
163
164
bleio_connection_internal_t * self = (bleio_connection_internal_t * )arg ;
164
165
165
- if (error -> status != BLE_ERR_SUCCESS ) {
166
+ if (error -> status != 0 ) {
166
167
// Keep the first error in case it's due to memory.
167
- if (_last_discovery_status == BLE_ERR_SUCCESS ) {
168
+ if (_last_discovery_status == 0 ) {
168
169
_last_discovery_status = error -> status ;
169
170
xTaskNotifyGive (discovery_task );
170
171
}
@@ -173,7 +174,7 @@ STATIC int _discovered_service_cb(uint16_t conn_handle,
173
174
174
175
// If any of these memory allocations fail, we set _last_discovery_status
175
176
// and let the process continue.
176
- if (_last_discovery_status != BLE_ERR_SUCCESS ) {
177
+ if (_last_discovery_status != 0 ) {
177
178
return 0 ;
178
179
}
179
180
bleio_service_obj_t * service = mp_obj_malloc (bleio_service_obj_t , & bleio_service_type );
@@ -202,16 +203,17 @@ STATIC int _discovered_characteristic_cb(uint16_t conn_handle,
202
203
void * arg ) {
203
204
bleio_service_obj_t * service = (bleio_service_obj_t * )arg ;
204
205
205
- if (error -> status != BLE_ERR_SUCCESS ) {
206
+ if (error -> status != 0 ) {
206
207
// Keep the first error in case it's due to memory.
207
- if (_last_discovery_status == BLE_ERR_SUCCESS ) {
208
+ if (_last_discovery_status == 0 ) {
208
209
_last_discovery_status = error -> status ;
209
210
xTaskNotifyGive (discovery_task );
210
211
}
212
+ return 0 ;
211
213
}
212
214
// If any of these memory allocations fail, we set _last_discovery_status
213
215
// and let the process continue.
214
- if (_last_discovery_status != BLE_ERR_SUCCESS ) {
216
+ if (_last_discovery_status != 0 ) {
215
217
return 0 ;
216
218
}
217
219
@@ -232,11 +234,14 @@ STATIC int _discovered_characteristic_cb(uint16_t conn_handle,
232
234
((chr -> properties & BLE_GATT_CHR_PROP_WRITE_NO_RSP ) != 0 ? CHAR_PROP_WRITE_NO_RESPONSE : 0 );
233
235
234
236
// Call common_hal_bleio_characteristic_construct() to initialize some fields and set up evt handler.
237
+ mp_buffer_info_t mp_const_empty_bytes_bufinfo ;
238
+ mp_get_buffer_raise (mp_const_empty_bytes , & mp_const_empty_bytes_bufinfo , MP_BUFFER_READ );
239
+
235
240
common_hal_bleio_characteristic_construct (
236
241
characteristic , service , chr -> val_handle , uuid ,
237
242
props , SECURITY_MODE_OPEN , SECURITY_MODE_OPEN ,
238
243
0 , false, // max_length, fixed_length: values don't matter for gattc
239
- mp_const_empty_bytes ,
244
+ & mp_const_empty_bytes_bufinfo ,
240
245
NULL );
241
246
// Set def_handle directly since it is only used in discovery.
242
247
characteristic -> def_handle = chr -> def_handle ;
@@ -253,16 +258,17 @@ STATIC int _discovered_descriptor_cb(uint16_t conn_handle,
253
258
void * arg ) {
254
259
bleio_characteristic_obj_t * characteristic = (bleio_characteristic_obj_t * )arg ;
255
260
256
- if (error -> status != BLE_ERR_SUCCESS ) {
261
+ if (error -> status != 0 ) {
257
262
// Keep the first error in case it's due to memory.
258
- if (_last_discovery_status == BLE_ERR_SUCCESS ) {
263
+ if (_last_discovery_status == 0 ) {
259
264
_last_discovery_status = error -> status ;
260
265
}
261
266
xTaskNotifyGive (discovery_task );
267
+ return 0 ;
262
268
}
263
269
// If any of these memory allocations fail, we set _last_discovery_status
264
270
// and let the process continue.
265
- if (_last_discovery_status != BLE_ERR_SUCCESS ) {
271
+ if (_last_discovery_status != 0 ) {
266
272
return 0 ;
267
273
}
268
274
@@ -306,7 +312,7 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
306
312
307
313
discovery_task = xTaskGetCurrentTaskHandle ();
308
314
if (service_uuids_whitelist == mp_const_none ) {
309
- _last_discovery_status = BLE_ERR_SUCCESS ;
315
+ _last_discovery_status = 0 ;
310
316
CHECK_NIMBLE_ERROR (ble_gattc_disc_all_svcs (self -> conn_handle , _discovered_service_cb , self ));
311
317
312
318
// Wait for sync.
@@ -324,7 +330,7 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
324
330
}
325
331
bleio_uuid_obj_t * uuid = MP_OBJ_TO_PTR (uuid_obj );
326
332
327
- _last_discovery_status = BLE_ERR_SUCCESS ;
333
+ _last_discovery_status = 0 ;
328
334
// Make sure we start with a clean notification state
329
335
ulTaskNotifyValueClear (discovery_task , 0xffffffff );
330
336
CHECK_NIMBLE_ERROR (ble_gattc_disc_svc_by_uuid (self -> conn_handle , & uuid -> nimble_ble_uuid .u ,
@@ -340,7 +346,7 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
340
346
for (size_t i = 0 ; i < self -> remote_service_list -> len ; i ++ ) {
341
347
bleio_service_obj_t * service = MP_OBJ_TO_PTR (self -> remote_service_list -> items [i ]);
342
348
343
- _last_discovery_status = BLE_ERR_SUCCESS ;
349
+ _last_discovery_status = 0 ;
344
350
CHECK_NIMBLE_ERROR (ble_gattc_disc_all_chrs (self -> conn_handle ,
345
351
service -> start_handle ,
346
352
service -> end_handle ,
@@ -375,7 +381,7 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
375
381
continue ;
376
382
}
377
383
378
- _last_discovery_status = BLE_ERR_SUCCESS ;
384
+ _last_discovery_status = 0 ;
379
385
CHECK_NIMBLE_ERROR (ble_gattc_disc_all_dscs (self -> conn_handle , characteristic -> handle ,
380
386
end_handle ,
381
387
_discovered_descriptor_cb , characteristic ));
0 commit comments