extmod/nimble: Update to NimBLE v1.4.
We're using the MicroPython fork of NimBLE, which on the `micropython_1_4_0` branch re-adds support for 64-bit targets and fixes initialisation of g_msys_pool_list. Also updates modbluetooth_nimble.c to suit v1.4. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
parent
1244d7f0bd
commit
948e3289bf
|
@ -138,9 +138,9 @@ STATIC int ble_gattc_attr_write_cb(uint16_t conn_handle, const struct ble_gatt_e
|
|||
|
||||
#if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
|
||||
// Bonding store.
|
||||
STATIC int ble_store_ram_read(int obj_type, const union ble_store_key *key, union ble_store_value *value);
|
||||
STATIC int ble_store_ram_write(int obj_type, const union ble_store_value *val);
|
||||
STATIC int ble_store_ram_delete(int obj_type, const union ble_store_key *key);
|
||||
STATIC int ble_secret_store_read(int obj_type, const union ble_store_key *key, union ble_store_value *value);
|
||||
STATIC int ble_secret_store_write(int obj_type, const union ble_store_value *val);
|
||||
STATIC int ble_secret_store_delete(int obj_type, const union ble_store_key *key);
|
||||
#endif
|
||||
|
||||
STATIC int ble_hs_err_to_errno(int err) {
|
||||
|
@ -604,6 +604,12 @@ int mp_bluetooth_init(void) {
|
|||
ble_hs_cfg.gatts_register_cb = gatts_register_cb;
|
||||
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
|
||||
|
||||
#if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
|
||||
ble_hs_cfg.store_read_cb = ble_secret_store_read;
|
||||
ble_hs_cfg.store_write_cb = ble_secret_store_write;
|
||||
ble_hs_cfg.store_delete_cb = ble_secret_store_delete;
|
||||
#endif // MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
|
||||
|
||||
MP_STATE_PORT(bluetooth_nimble_root_pointers) = m_new0(mp_bluetooth_nimble_root_pointers_t, 1);
|
||||
mp_bluetooth_gatts_db_create(&MP_STATE_PORT(bluetooth_nimble_root_pointers)->gatts_db);
|
||||
|
||||
|
@ -1826,8 +1832,8 @@ int mp_bluetooth_hci_cmd(uint16_t ogf, uint16_t ocf, const uint8_t *req, size_t
|
|||
|
||||
#if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
|
||||
|
||||
STATIC int ble_store_ram_read(int obj_type, const union ble_store_key *key, union ble_store_value *value) {
|
||||
DEBUG_printf("ble_store_ram_read: %d\n", obj_type);
|
||||
STATIC int ble_secret_store_read(int obj_type, const union ble_store_key *key, union ble_store_value *value) {
|
||||
DEBUG_printf("ble_secret_store_read: %d\n", obj_type);
|
||||
const uint8_t *key_data;
|
||||
size_t key_data_len;
|
||||
|
||||
|
@ -1861,7 +1867,7 @@ STATIC int ble_store_ram_read(int obj_type, const union ble_store_key *key, unio
|
|||
}
|
||||
case BLE_STORE_OBJ_TYPE_CCCD: {
|
||||
// TODO: Implement CCCD persistence.
|
||||
DEBUG_printf("ble_store_ram_read: CCCD not supported.\n");
|
||||
DEBUG_printf("ble_secret_store_read: CCCD not supported.\n");
|
||||
return -1;
|
||||
}
|
||||
default:
|
||||
|
@ -1871,18 +1877,18 @@ STATIC int ble_store_ram_read(int obj_type, const union ble_store_key *key, unio
|
|||
const uint8_t *value_data;
|
||||
size_t value_data_len;
|
||||
if (!mp_bluetooth_gap_on_get_secret(obj_type, key->sec.idx, key_data, key_data_len, &value_data, &value_data_len)) {
|
||||
DEBUG_printf("ble_store_ram_read: Key not found: type=%d, index=%u, key=0x%p, len=" UINT_FMT "\n", obj_type, key->sec.idx, key_data, key_data_len);
|
||||
DEBUG_printf("ble_secret_store_read: Key not found: type=%d, index=%u, key=0x%p, len=" UINT_FMT "\n", obj_type, key->sec.idx, key_data, key_data_len);
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
if (value_data_len != sizeof(struct ble_store_value_sec)) {
|
||||
DEBUG_printf("ble_store_ram_read: Invalid key data: actual=" UINT_FMT " expected=" UINT_FMT "\n", value_data_len, sizeof(struct ble_store_value_sec));
|
||||
DEBUG_printf("ble_secret_store_read: Invalid key data: actual=" UINT_FMT " expected=" UINT_FMT "\n", value_data_len, sizeof(struct ble_store_value_sec));
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
memcpy((uint8_t *)&value->sec, value_data, sizeof(struct ble_store_value_sec));
|
||||
|
||||
DEBUG_printf("ble_store_ram_read: found secret\n");
|
||||
DEBUG_printf("ble_secret_store_read: found secret\n");
|
||||
|
||||
if (obj_type == BLE_STORE_OBJ_TYPE_OUR_SEC) {
|
||||
// TODO: Verify ediv_rand matches.
|
||||
|
@ -1891,8 +1897,8 @@ STATIC int ble_store_ram_read(int obj_type, const union ble_store_key *key, unio
|
|||
return 0;
|
||||
}
|
||||
|
||||
STATIC int ble_store_ram_write(int obj_type, const union ble_store_value *val) {
|
||||
DEBUG_printf("ble_store_ram_write: %d\n", obj_type);
|
||||
STATIC int ble_secret_store_write(int obj_type, const union ble_store_value *val) {
|
||||
DEBUG_printf("ble_secret_store_write: %d\n", obj_type);
|
||||
switch (obj_type) {
|
||||
case BLE_STORE_OBJ_TYPE_PEER_SEC:
|
||||
case BLE_STORE_OBJ_TYPE_OUR_SEC: {
|
||||
|
@ -1910,13 +1916,13 @@ STATIC int ble_store_ram_write(int obj_type, const union ble_store_value *val) {
|
|||
return BLE_HS_ESTORE_CAP;
|
||||
}
|
||||
|
||||
DEBUG_printf("ble_store_ram_write: wrote secret\n");
|
||||
DEBUG_printf("ble_secret_store_write: wrote secret\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
case BLE_STORE_OBJ_TYPE_CCCD: {
|
||||
// TODO: Implement CCCD persistence.
|
||||
DEBUG_printf("ble_store_ram_write: CCCD not supported.\n");
|
||||
DEBUG_printf("ble_secret_store_write: CCCD not supported.\n");
|
||||
// Just pretend we wrote it.
|
||||
return 0;
|
||||
}
|
||||
|
@ -1925,8 +1931,8 @@ STATIC int ble_store_ram_write(int obj_type, const union ble_store_value *val) {
|
|||
}
|
||||
}
|
||||
|
||||
STATIC int ble_store_ram_delete(int obj_type, const union ble_store_key *key) {
|
||||
DEBUG_printf("ble_store_ram_delete: %d\n", obj_type);
|
||||
STATIC int ble_secret_store_delete(int obj_type, const union ble_store_key *key) {
|
||||
DEBUG_printf("ble_secret_store_delete: %d\n", obj_type);
|
||||
switch (obj_type) {
|
||||
case BLE_STORE_OBJ_TYPE_PEER_SEC:
|
||||
case BLE_STORE_OBJ_TYPE_OUR_SEC: {
|
||||
|
@ -1940,13 +1946,13 @@ STATIC int ble_store_ram_delete(int obj_type, const union ble_store_key *key) {
|
|||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
||||
DEBUG_printf("ble_store_ram_delete: deleted secret\n");
|
||||
DEBUG_printf("ble_secret_store_delete: deleted secret\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
case BLE_STORE_OBJ_TYPE_CCCD: {
|
||||
// TODO: Implement CCCD persistence.
|
||||
DEBUG_printf("ble_store_ram_delete: CCCD not supported.\n");
|
||||
DEBUG_printf("ble_secret_store_delete: CCCD not supported.\n");
|
||||
// Just pretend it wasn't there.
|
||||
return BLE_HS_ENOENT;
|
||||
}
|
||||
|
@ -1955,15 +1961,6 @@ STATIC int ble_store_ram_delete(int obj_type, const union ble_store_key *key) {
|
|||
}
|
||||
}
|
||||
|
||||
// nimble_port_init always calls ble_store_ram_init. We provide this alternative
|
||||
// implementation rather than the one in nimble/store/ram/src/ble_store_ram.c.
|
||||
// TODO: Consider re-implementing nimble_port_init instead.
|
||||
void ble_store_ram_init(void) {
|
||||
ble_hs_cfg.store_read_cb = ble_store_ram_read;
|
||||
ble_hs_cfg.store_write_cb = ble_store_ram_write;
|
||||
ble_hs_cfg.store_delete_cb = ble_store_ram_delete;
|
||||
}
|
||||
|
||||
#endif // MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
|
||||
|
||||
#endif // MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_NIMBLE
|
||||
|
|
|
@ -35,7 +35,11 @@
|
|||
// --- Configuration of NimBLE data structures --------------------------------
|
||||
|
||||
// This is used at runtime to align allocations correctly.
|
||||
#define BLE_NPL_OS_ALIGNMENT (sizeof(uintptr_t))
|
||||
#if __WORDSIZE == 64
|
||||
#define BLE_NPL_OS_ALIGNMENT 8
|
||||
#else
|
||||
#define BLE_NPL_OS_ALIGNMENT 4
|
||||
#endif
|
||||
#define BLE_NPL_TIME_FOREVER (0xffffffff)
|
||||
|
||||
// This is used at compile time to force struct member alignment. See
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 97ce3eacaaa79e8ed6cf71717149ced4f5328ee7
|
||||
Subproject commit 42849560ba7906f023f61e5f7ff3709ba2c1dfca
|
Loading…
Reference in New Issue