@@ -128,6 +128,7 @@ bool common_hal_bleio_connection_get_connected(bleio_connection_obj_t *self) {
128128}
129129
130130void common_hal_bleio_connection_disconnect (bleio_connection_internal_t * self ) {
131+ // Second argument is an HCI reason, not an HS error code.
131132 ble_gap_terminate (self -> conn_handle , BLE_ERR_REM_USER_CONN_TERM );
132133}
133134
@@ -162,9 +163,9 @@ STATIC int _discovered_service_cb(uint16_t conn_handle,
162163 void * arg ) {
163164 bleio_connection_internal_t * self = (bleio_connection_internal_t * )arg ;
164165
165- if (error -> status != BLE_ERR_SUCCESS ) {
166+ if (error -> status != 0 ) {
166167 // 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 ) {
168169 _last_discovery_status = error -> status ;
169170 xTaskNotifyGive (discovery_task );
170171 }
@@ -173,7 +174,7 @@ STATIC int _discovered_service_cb(uint16_t conn_handle,
173174
174175 // If any of these memory allocations fail, we set _last_discovery_status
175176 // and let the process continue.
176- if (_last_discovery_status != BLE_ERR_SUCCESS ) {
177+ if (_last_discovery_status != 0 ) {
177178 return 0 ;
178179 }
179180 bleio_service_obj_t * service = mp_obj_malloc (bleio_service_obj_t , & bleio_service_type );
@@ -202,16 +203,16 @@ STATIC int _discovered_characteristic_cb(uint16_t conn_handle,
202203 void * arg ) {
203204 bleio_service_obj_t * service = (bleio_service_obj_t * )arg ;
204205
205- if (error -> status != BLE_ERR_SUCCESS ) {
206+ if (error -> status != 0 ) {
206207 // 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 ) {
208209 _last_discovery_status = error -> status ;
209210 xTaskNotifyGive (discovery_task );
210211 }
211212 }
212213 // If any of these memory allocations fail, we set _last_discovery_status
213214 // and let the process continue.
214- if (_last_discovery_status != BLE_ERR_SUCCESS ) {
215+ if (_last_discovery_status != 0 ) {
215216 return 0 ;
216217 }
217218
@@ -253,16 +254,16 @@ STATIC int _discovered_descriptor_cb(uint16_t conn_handle,
253254 void * arg ) {
254255 bleio_characteristic_obj_t * characteristic = (bleio_characteristic_obj_t * )arg ;
255256
256- if (error -> status != BLE_ERR_SUCCESS ) {
257+ if (error -> status != 0 ) {
257258 // Keep the first error in case it's due to memory.
258- if (_last_discovery_status == BLE_ERR_SUCCESS ) {
259+ if (_last_discovery_status == 0 ) {
259260 _last_discovery_status = error -> status ;
260261 }
261262 xTaskNotifyGive (discovery_task );
262263 }
263264 // If any of these memory allocations fail, we set _last_discovery_status
264265 // and let the process continue.
265- if (_last_discovery_status != BLE_ERR_SUCCESS ) {
266+ if (_last_discovery_status != 0 ) {
266267 return 0 ;
267268 }
268269
@@ -306,7 +307,7 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
306307
307308 discovery_task = xTaskGetCurrentTaskHandle ();
308309 if (service_uuids_whitelist == mp_const_none ) {
309- _last_discovery_status = BLE_ERR_SUCCESS ;
310+ _last_discovery_status = 0 ;
310311 CHECK_NIMBLE_ERROR (ble_gattc_disc_all_svcs (self -> conn_handle , _discovered_service_cb , self ));
311312
312313 // Wait for sync.
@@ -324,7 +325,7 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
324325 }
325326 bleio_uuid_obj_t * uuid = MP_OBJ_TO_PTR (uuid_obj );
326327
327- _last_discovery_status = BLE_ERR_SUCCESS ;
328+ _last_discovery_status = 0 ;
328329 // Make sure we start with a clean notification state
329330 ulTaskNotifyValueClear (discovery_task , 0xffffffff );
330331 CHECK_NIMBLE_ERROR (ble_gattc_disc_svc_by_uuid (self -> conn_handle , & uuid -> nimble_ble_uuid .u ,
@@ -340,7 +341,7 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
340341 for (size_t i = 0 ; i < self -> remote_service_list -> len ; i ++ ) {
341342 bleio_service_obj_t * service = MP_OBJ_TO_PTR (self -> remote_service_list -> items [i ]);
342343
343- _last_discovery_status = BLE_ERR_SUCCESS ;
344+ _last_discovery_status = 0 ;
344345 CHECK_NIMBLE_ERROR (ble_gattc_disc_all_chrs (self -> conn_handle ,
345346 service -> start_handle ,
346347 service -> end_handle ,
@@ -375,7 +376,7 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
375376 continue ;
376377 }
377378
378- _last_discovery_status = BLE_ERR_SUCCESS ;
379+ _last_discovery_status = 0 ;
379380 CHECK_NIMBLE_ERROR (ble_gattc_disc_all_dscs (self -> conn_handle , characteristic -> handle ,
380381 end_handle ,
381382 _discovered_descriptor_cb , characteristic ));
0 commit comments