Skip to content

Commit 948e328

Browse files
committed
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 <[email protected]>
1 parent 1244d7f commit 948e328

File tree

3 files changed

+29
-28
lines changed

3 files changed

+29
-28
lines changed

extmod/nimble/modbluetooth_nimble.c

+23-26
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ STATIC int ble_gattc_attr_write_cb(uint16_t conn_handle, const struct ble_gatt_e
138138

139139
#if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
140140
// Bonding store.
141-
STATIC int ble_store_ram_read(int obj_type, const union ble_store_key *key, union ble_store_value *value);
142-
STATIC int ble_store_ram_write(int obj_type, const union ble_store_value *val);
143-
STATIC int ble_store_ram_delete(int obj_type, const union ble_store_key *key);
141+
STATIC int ble_secret_store_read(int obj_type, const union ble_store_key *key, union ble_store_value *value);
142+
STATIC int ble_secret_store_write(int obj_type, const union ble_store_value *val);
143+
STATIC int ble_secret_store_delete(int obj_type, const union ble_store_key *key);
144144
#endif
145145

146146
STATIC int ble_hs_err_to_errno(int err) {
@@ -604,6 +604,12 @@ int mp_bluetooth_init(void) {
604604
ble_hs_cfg.gatts_register_cb = gatts_register_cb;
605605
ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
606606

607+
#if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
608+
ble_hs_cfg.store_read_cb = ble_secret_store_read;
609+
ble_hs_cfg.store_write_cb = ble_secret_store_write;
610+
ble_hs_cfg.store_delete_cb = ble_secret_store_delete;
611+
#endif // MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
612+
607613
MP_STATE_PORT(bluetooth_nimble_root_pointers) = m_new0(mp_bluetooth_nimble_root_pointers_t, 1);
608614
mp_bluetooth_gatts_db_create(&MP_STATE_PORT(bluetooth_nimble_root_pointers)->gatts_db);
609615

@@ -1826,8 +1832,8 @@ int mp_bluetooth_hci_cmd(uint16_t ogf, uint16_t ocf, const uint8_t *req, size_t
18261832

18271833
#if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
18281834

1829-
STATIC int ble_store_ram_read(int obj_type, const union ble_store_key *key, union ble_store_value *value) {
1830-
DEBUG_printf("ble_store_ram_read: %d\n", obj_type);
1835+
STATIC int ble_secret_store_read(int obj_type, const union ble_store_key *key, union ble_store_value *value) {
1836+
DEBUG_printf("ble_secret_store_read: %d\n", obj_type);
18311837
const uint8_t *key_data;
18321838
size_t key_data_len;
18331839

@@ -1861,7 +1867,7 @@ STATIC int ble_store_ram_read(int obj_type, const union ble_store_key *key, unio
18611867
}
18621868
case BLE_STORE_OBJ_TYPE_CCCD: {
18631869
// TODO: Implement CCCD persistence.
1864-
DEBUG_printf("ble_store_ram_read: CCCD not supported.\n");
1870+
DEBUG_printf("ble_secret_store_read: CCCD not supported.\n");
18651871
return -1;
18661872
}
18671873
default:
@@ -1871,18 +1877,18 @@ STATIC int ble_store_ram_read(int obj_type, const union ble_store_key *key, unio
18711877
const uint8_t *value_data;
18721878
size_t value_data_len;
18731879
if (!mp_bluetooth_gap_on_get_secret(obj_type, key->sec.idx, key_data, key_data_len, &value_data, &value_data_len)) {
1874-
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);
1880+
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);
18751881
return BLE_HS_ENOENT;
18761882
}
18771883

18781884
if (value_data_len != sizeof(struct ble_store_value_sec)) {
1879-
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));
1885+
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));
18801886
return BLE_HS_ENOENT;
18811887
}
18821888

18831889
memcpy((uint8_t *)&value->sec, value_data, sizeof(struct ble_store_value_sec));
18841890

1885-
DEBUG_printf("ble_store_ram_read: found secret\n");
1891+
DEBUG_printf("ble_secret_store_read: found secret\n");
18861892

18871893
if (obj_type == BLE_STORE_OBJ_TYPE_OUR_SEC) {
18881894
// 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
18911897
return 0;
18921898
}
18931899

1894-
STATIC int ble_store_ram_write(int obj_type, const union ble_store_value *val) {
1895-
DEBUG_printf("ble_store_ram_write: %d\n", obj_type);
1900+
STATIC int ble_secret_store_write(int obj_type, const union ble_store_value *val) {
1901+
DEBUG_printf("ble_secret_store_write: %d\n", obj_type);
18961902
switch (obj_type) {
18971903
case BLE_STORE_OBJ_TYPE_PEER_SEC:
18981904
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) {
19101916
return BLE_HS_ESTORE_CAP;
19111917
}
19121918

1913-
DEBUG_printf("ble_store_ram_write: wrote secret\n");
1919+
DEBUG_printf("ble_secret_store_write: wrote secret\n");
19141920

19151921
return 0;
19161922
}
19171923
case BLE_STORE_OBJ_TYPE_CCCD: {
19181924
// TODO: Implement CCCD persistence.
1919-
DEBUG_printf("ble_store_ram_write: CCCD not supported.\n");
1925+
DEBUG_printf("ble_secret_store_write: CCCD not supported.\n");
19201926
// Just pretend we wrote it.
19211927
return 0;
19221928
}
@@ -1925,8 +1931,8 @@ STATIC int ble_store_ram_write(int obj_type, const union ble_store_value *val) {
19251931
}
19261932
}
19271933

1928-
STATIC int ble_store_ram_delete(int obj_type, const union ble_store_key *key) {
1929-
DEBUG_printf("ble_store_ram_delete: %d\n", obj_type);
1934+
STATIC int ble_secret_store_delete(int obj_type, const union ble_store_key *key) {
1935+
DEBUG_printf("ble_secret_store_delete: %d\n", obj_type);
19301936
switch (obj_type) {
19311937
case BLE_STORE_OBJ_TYPE_PEER_SEC:
19321938
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) {
19401946
return BLE_HS_ENOENT;
19411947
}
19421948

1943-
DEBUG_printf("ble_store_ram_delete: deleted secret\n");
1949+
DEBUG_printf("ble_secret_store_delete: deleted secret\n");
19441950

19451951
return 0;
19461952
}
19471953
case BLE_STORE_OBJ_TYPE_CCCD: {
19481954
// TODO: Implement CCCD persistence.
1949-
DEBUG_printf("ble_store_ram_delete: CCCD not supported.\n");
1955+
DEBUG_printf("ble_secret_store_delete: CCCD not supported.\n");
19501956
// Just pretend it wasn't there.
19511957
return BLE_HS_ENOENT;
19521958
}
@@ -1955,15 +1961,6 @@ STATIC int ble_store_ram_delete(int obj_type, const union ble_store_key *key) {
19551961
}
19561962
}
19571963

1958-
// nimble_port_init always calls ble_store_ram_init. We provide this alternative
1959-
// implementation rather than the one in nimble/store/ram/src/ble_store_ram.c.
1960-
// TODO: Consider re-implementing nimble_port_init instead.
1961-
void ble_store_ram_init(void) {
1962-
ble_hs_cfg.store_read_cb = ble_store_ram_read;
1963-
ble_hs_cfg.store_write_cb = ble_store_ram_write;
1964-
ble_hs_cfg.store_delete_cb = ble_store_ram_delete;
1965-
}
1966-
19671964
#endif // MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
19681965

19691966
#endif // MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_NIMBLE

extmod/nimble/nimble/nimble_npl_os.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@
3535
// --- Configuration of NimBLE data structures --------------------------------
3636

3737
// This is used at runtime to align allocations correctly.
38-
#define BLE_NPL_OS_ALIGNMENT (sizeof(uintptr_t))
38+
#if __WORDSIZE == 64
39+
#define BLE_NPL_OS_ALIGNMENT 8
40+
#else
41+
#define BLE_NPL_OS_ALIGNMENT 4
42+
#endif
3943
#define BLE_NPL_TIME_FOREVER (0xffffffff)
4044

4145
// This is used at compile time to force struct member alignment. See

lib/mynewt-nimble

Submodule mynewt-nimble updated 342 files

0 commit comments

Comments
 (0)