@@ -138,9 +138,9 @@ STATIC int ble_gattc_attr_write_cb(uint16_t conn_handle, const struct ble_gatt_e
138
138
139
139
#if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
140
140
// 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 );
144
144
#endif
145
145
146
146
STATIC int ble_hs_err_to_errno (int err ) {
@@ -604,6 +604,12 @@ int mp_bluetooth_init(void) {
604
604
ble_hs_cfg .gatts_register_cb = gatts_register_cb ;
605
605
ble_hs_cfg .store_status_cb = ble_store_util_status_rr ;
606
606
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
+
607
613
MP_STATE_PORT (bluetooth_nimble_root_pointers ) = m_new0 (mp_bluetooth_nimble_root_pointers_t , 1 );
608
614
mp_bluetooth_gatts_db_create (& MP_STATE_PORT (bluetooth_nimble_root_pointers )-> gatts_db );
609
615
@@ -1826,8 +1832,8 @@ int mp_bluetooth_hci_cmd(uint16_t ogf, uint16_t ocf, const uint8_t *req, size_t
1826
1832
1827
1833
#if MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
1828
1834
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 );
1831
1837
const uint8_t * key_data ;
1832
1838
size_t key_data_len ;
1833
1839
@@ -1861,7 +1867,7 @@ STATIC int ble_store_ram_read(int obj_type, const union ble_store_key *key, unio
1861
1867
}
1862
1868
case BLE_STORE_OBJ_TYPE_CCCD : {
1863
1869
// 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" );
1865
1871
return -1 ;
1866
1872
}
1867
1873
default :
@@ -1871,18 +1877,18 @@ STATIC int ble_store_ram_read(int obj_type, const union ble_store_key *key, unio
1871
1877
const uint8_t * value_data ;
1872
1878
size_t value_data_len ;
1873
1879
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 );
1875
1881
return BLE_HS_ENOENT ;
1876
1882
}
1877
1883
1878
1884
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 ));
1880
1886
return BLE_HS_ENOENT ;
1881
1887
}
1882
1888
1883
1889
memcpy ((uint8_t * )& value -> sec , value_data , sizeof (struct ble_store_value_sec ));
1884
1890
1885
- DEBUG_printf ("ble_store_ram_read : found secret\n" );
1891
+ DEBUG_printf ("ble_secret_store_read : found secret\n" );
1886
1892
1887
1893
if (obj_type == BLE_STORE_OBJ_TYPE_OUR_SEC ) {
1888
1894
// 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
1891
1897
return 0 ;
1892
1898
}
1893
1899
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 );
1896
1902
switch (obj_type ) {
1897
1903
case BLE_STORE_OBJ_TYPE_PEER_SEC :
1898
1904
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) {
1910
1916
return BLE_HS_ESTORE_CAP ;
1911
1917
}
1912
1918
1913
- DEBUG_printf ("ble_store_ram_write : wrote secret\n" );
1919
+ DEBUG_printf ("ble_secret_store_write : wrote secret\n" );
1914
1920
1915
1921
return 0 ;
1916
1922
}
1917
1923
case BLE_STORE_OBJ_TYPE_CCCD : {
1918
1924
// 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" );
1920
1926
// Just pretend we wrote it.
1921
1927
return 0 ;
1922
1928
}
@@ -1925,8 +1931,8 @@ STATIC int ble_store_ram_write(int obj_type, const union ble_store_value *val) {
1925
1931
}
1926
1932
}
1927
1933
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 );
1930
1936
switch (obj_type ) {
1931
1937
case BLE_STORE_OBJ_TYPE_PEER_SEC :
1932
1938
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) {
1940
1946
return BLE_HS_ENOENT ;
1941
1947
}
1942
1948
1943
- DEBUG_printf ("ble_store_ram_delete : deleted secret\n" );
1949
+ DEBUG_printf ("ble_secret_store_delete : deleted secret\n" );
1944
1950
1945
1951
return 0 ;
1946
1952
}
1947
1953
case BLE_STORE_OBJ_TYPE_CCCD : {
1948
1954
// 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" );
1950
1956
// Just pretend it wasn't there.
1951
1957
return BLE_HS_ENOENT ;
1952
1958
}
@@ -1955,15 +1961,6 @@ STATIC int ble_store_ram_delete(int obj_type, const union ble_store_key *key) {
1955
1961
}
1956
1962
}
1957
1963
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
-
1967
1964
#endif // MICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING
1968
1965
1969
1966
#endif // MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_NIMBLE
0 commit comments