Skip to content

Commit fe05be8

Browse files
authored
Merge pull request #2362 from tannewt/fix_service_list_crash
Check connection validity after service discovery.
2 parents 559ce6a + da0ea97 commit fe05be8

File tree

5 files changed

+9
-15
lines changed

5 files changed

+9
-15
lines changed

ports/nrf/bluetooth/ble_drv.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,6 @@ void SD_EVT_IRQHandler(void) {
153153
ble_gatts_evt_write_t* write_evt = &event->evt.gatts_evt.params.write;
154154
mp_printf(&mp_plat_print, "Write to: UUID(0x%04x) handle %x of length %d auth %x\n", write_evt->uuid.uuid, write_evt->handle, write_evt->len, write_evt->auth_required);
155155
}
156-
if (!done) {
157-
mp_printf(&mp_plat_print, "Unhandled ble event: 0x%04x\n", event->header.evt_id);
158-
159-
}
160156
#endif
161157
}
162158
}

ports/nrf/common-hal/_bleio/Connection.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,6 @@ bool connection_on_ble_evt(ble_evt_t *ble_evt, void *self_in) {
248248

249249

250250
default:
251-
// For debugging.
252-
#if CIRCUITPY_VERBOSE_BLE
253-
mp_printf(&mp_plat_print, "Unhandled connection event: 0x%04x\n", ble_evt->header.evt_id);
254-
#endif
255-
256251
return false;
257252
}
258253
return true;
@@ -659,6 +654,7 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t
659654

660655
mp_obj_tuple_t *common_hal_bleio_connection_discover_remote_services(bleio_connection_obj_t *self, mp_obj_t service_uuids_whitelist) {
661656
discover_remote_services(self->connection, service_uuids_whitelist);
657+
bleio_connection_ensure_connected(self);
662658
// Convert to a tuple and then clear the list so the callee will take ownership.
663659
mp_obj_tuple_t *services_tuple = service_linked_list_to_tuple(self->connection->remote_service_list);
664660
self->connection->remote_service_list = NULL;

shared-bindings/_bleio/Connection.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
//| connection = _bleio.adapter.connect(my_entry.address, timeout=10)
6767
//|
6868

69-
STATIC void ensure_connected(bleio_connection_obj_t *self) {
69+
void bleio_connection_ensure_connected(bleio_connection_obj_t *self) {
7070
if (!common_hal_bleio_connection_get_connected(self)) {
7171
mp_raise_bleio_ConnectionError(translate("Connection has been disconnected and can no longer be used. Create a new connection."));
7272
}
@@ -106,7 +106,7 @@ STATIC mp_obj_t bleio_connection_pair(mp_uint_t n_args, const mp_obj_t *pos_args
106106
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
107107
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
108108

109-
ensure_connected(self);
109+
bleio_connection_ensure_connected(self);
110110

111111
common_hal_bleio_connection_pair(self->connection, args[ARG_bond].u_bool);
112112
return mp_const_none;
@@ -148,7 +148,7 @@ STATIC mp_obj_t bleio_connection_discover_remote_services(mp_uint_t n_args, cons
148148
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
149149
mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
150150

151-
ensure_connected(self);
151+
bleio_connection_ensure_connected(self);
152152

153153
return MP_OBJ_FROM_PTR(common_hal_bleio_connection_discover_remote_services(
154154
self,
@@ -209,7 +209,7 @@ const mp_obj_property_t bleio_connection_paired_obj = {
209209
STATIC mp_obj_t bleio_connection_get_connection_interval(mp_obj_t self_in) {
210210
bleio_connection_obj_t *self = MP_OBJ_TO_PTR(self_in);
211211

212-
ensure_connected(self);
212+
bleio_connection_ensure_connected(self);
213213
return mp_obj_new_float(common_hal_bleio_connection_get_connection_interval(self->connection));
214214
}
215215
STATIC MP_DEFINE_CONST_FUN_OBJ_1(bleio_connection_get_connection_interval_obj, bleio_connection_get_connection_interval);
@@ -219,7 +219,7 @@ STATIC mp_obj_t bleio_connection_set_connection_interval(mp_obj_t self_in, mp_ob
219219

220220
mp_float_t interval = mp_obj_get_float(interval_in);
221221

222-
ensure_connected(self);
222+
bleio_connection_ensure_connected(self);
223223
common_hal_bleio_connection_set_connection_interval(self->connection, interval);
224224

225225
return mp_const_none;

shared-bindings/_bleio/Connection.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ extern mp_obj_tuple_t *common_hal_bleio_connection_discover_remote_services(blei
4343
mp_float_t common_hal_bleio_connection_get_connection_interval(bleio_connection_internal_t *self);
4444
void common_hal_bleio_connection_set_connection_interval(bleio_connection_internal_t *self, mp_float_t new_interval);
4545

46+
void bleio_connection_ensure_connected(bleio_connection_obj_t *self);
47+
4648
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_BLEIO_CONNECTION_H

shared-bindings/_bleio/Service.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ const mp_obj_property_t bleio_service_secondary_obj = {
136136
//| .. attribute:: uuid
137137
//|
138138
//| The UUID of this service. (read-only)
139-
//|
139+
//|
140140
//| Will be ``None`` if the 128-bit UUID for this service is not known.
141141
//|
142142
STATIC mp_obj_t bleio_service_get_uuid(mp_obj_t self_in) {

0 commit comments

Comments
 (0)