From 18fb5b443200548c142d5aa83c08cf873f9524d3 Mon Sep 17 00:00:00 2001 From: Thomas Friebel Date: Mon, 27 Apr 2020 10:21:42 +0200 Subject: [PATCH] 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. --- extmod/nimble/modbluetooth_nimble.c | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/extmod/nimble/modbluetooth_nimble.c b/extmod/nimble/modbluetooth_nimble.c index 69067e0776..e2e95aa74e 100644 --- a/extmod/nimble/modbluetooth_nimble.c +++ b/extmod/nimble/modbluetooth_nimble.c @@ -48,41 +48,25 @@ #define ERRNO_BLUETOOTH_NOT_ACTIVE MP_ENODEV +// Any BLE_HS_xxx code not in this table will default to MP_EIO. STATIC int8_t ble_hs_err_to_errno_table[] = { [BLE_HS_EAGAIN] = MP_EAGAIN, [BLE_HS_EALREADY] = MP_EALREADY, [BLE_HS_EINVAL] = MP_EINVAL, - [BLE_HS_EMSGSIZE] = MP_EIO, [BLE_HS_ENOENT] = MP_ENOENT, [BLE_HS_ENOMEM] = MP_ENOMEM, [BLE_HS_ENOTCONN] = MP_ENOTCONN, [BLE_HS_ENOTSUP] = MP_EOPNOTSUPP, - [BLE_HS_EAPP] = MP_EIO, - [BLE_HS_EBADDATA] = MP_EIO, - [BLE_HS_EOS] = MP_EIO, - [BLE_HS_ECONTROLLER] = MP_EIO, [BLE_HS_ETIMEOUT] = MP_ETIMEDOUT, [BLE_HS_EDONE] = MP_EIO, // TODO: Maybe should be MP_EISCONN (connect uses this for "already connected"). [BLE_HS_EBUSY] = MP_EBUSY, - [BLE_HS_EREJECT] = MP_EIO, - [BLE_HS_EUNKNOWN] = MP_EIO, - [BLE_HS_EROLE] = MP_EIO, - [BLE_HS_ETIMEOUT_HCI] = MP_EIO, - [BLE_HS_ENOMEM_EVT] = MP_EIO, - [BLE_HS_ENOADDR] = MP_EIO, - [BLE_HS_ENOTSYNCED] = MP_EIO, - [BLE_HS_EAUTHEN] = MP_EIO, - [BLE_HS_EAUTHOR] = MP_EIO, - [BLE_HS_EENCRYPT] = MP_EIO, - [BLE_HS_EENCRYPT_KEY_SZ] = MP_EIO, - [BLE_HS_ESTORE_CAP] = MP_EIO, - [BLE_HS_ESTORE_FAIL] = MP_EIO, - [BLE_HS_EPREEMPTED] = MP_EIO, - [BLE_HS_EDISABLED] = MP_EIO, }; STATIC int ble_hs_err_to_errno(int err) { - if (0 <= err && err < MP_ARRAY_SIZE(ble_hs_err_to_errno_table)) { + if (!err) { + return 0; + } + if (0 <= err && err < MP_ARRAY_SIZE(ble_hs_err_to_errno_table) && ble_hs_err_to_errno_table[err]) { return ble_hs_err_to_errno_table[err]; } else { return MP_EIO;