Skip to content

Commit 18fb5b4

Browse files
friebeldpgeorge
authored andcommitted
extmod/nimble: Make error code mapping default to MP_EIO.
Before this change, any NimBLE error that does not appear in the ble_hs_err_to_errno_table maps to return code 0, meaning success. If we miss adding an error code to the table we end up returning success in case of failure. Instead, handle the zero case explicitly and default to MP_EIO. This allows removing the now-redundant MP_EIO entries from the mapping.
1 parent c9611b2 commit 18fb5b4

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

extmod/nimble/modbluetooth_nimble.c

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,41 +48,25 @@
4848

4949
#define ERRNO_BLUETOOTH_NOT_ACTIVE MP_ENODEV
5050

51+
// Any BLE_HS_xxx code not in this table will default to MP_EIO.
5152
STATIC int8_t ble_hs_err_to_errno_table[] = {
5253
[BLE_HS_EAGAIN] = MP_EAGAIN,
5354
[BLE_HS_EALREADY] = MP_EALREADY,
5455
[BLE_HS_EINVAL] = MP_EINVAL,
55-
[BLE_HS_EMSGSIZE] = MP_EIO,
5656
[BLE_HS_ENOENT] = MP_ENOENT,
5757
[BLE_HS_ENOMEM] = MP_ENOMEM,
5858
[BLE_HS_ENOTCONN] = MP_ENOTCONN,
5959
[BLE_HS_ENOTSUP] = MP_EOPNOTSUPP,
60-
[BLE_HS_EAPP] = MP_EIO,
61-
[BLE_HS_EBADDATA] = MP_EIO,
62-
[BLE_HS_EOS] = MP_EIO,
63-
[BLE_HS_ECONTROLLER] = MP_EIO,
6460
[BLE_HS_ETIMEOUT] = MP_ETIMEDOUT,
6561
[BLE_HS_EDONE] = MP_EIO, // TODO: Maybe should be MP_EISCONN (connect uses this for "already connected").
6662
[BLE_HS_EBUSY] = MP_EBUSY,
67-
[BLE_HS_EREJECT] = MP_EIO,
68-
[BLE_HS_EUNKNOWN] = MP_EIO,
69-
[BLE_HS_EROLE] = MP_EIO,
70-
[BLE_HS_ETIMEOUT_HCI] = MP_EIO,
71-
[BLE_HS_ENOMEM_EVT] = MP_EIO,
72-
[BLE_HS_ENOADDR] = MP_EIO,
73-
[BLE_HS_ENOTSYNCED] = MP_EIO,
74-
[BLE_HS_EAUTHEN] = MP_EIO,
75-
[BLE_HS_EAUTHOR] = MP_EIO,
76-
[BLE_HS_EENCRYPT] = MP_EIO,
77-
[BLE_HS_EENCRYPT_KEY_SZ] = MP_EIO,
78-
[BLE_HS_ESTORE_CAP] = MP_EIO,
79-
[BLE_HS_ESTORE_FAIL] = MP_EIO,
80-
[BLE_HS_EPREEMPTED] = MP_EIO,
81-
[BLE_HS_EDISABLED] = MP_EIO,
8263
};
8364

8465
STATIC int ble_hs_err_to_errno(int err) {
85-
if (0 <= err && err < MP_ARRAY_SIZE(ble_hs_err_to_errno_table)) {
66+
if (!err) {
67+
return 0;
68+
}
69+
if (0 <= err && err < MP_ARRAY_SIZE(ble_hs_err_to_errno_table) && ble_hs_err_to_errno_table[err]) {
8670
return ble_hs_err_to_errno_table[err];
8771
} else {
8872
return MP_EIO;

0 commit comments

Comments
 (0)