@@ -1862,6 +1862,13 @@ STATIC int ble_store_ram_read(int obj_type, const union ble_store_key *key, unio
1862
1862
DEBUG_printf ("ble_store_ram_read: CCCD not supported.\n" );
1863
1863
return -1 ;
1864
1864
}
1865
+ case BLE_STORE_OBJ_TYPE_HASH : {
1866
+ assert (ble_addr_cmp (& key -> hash .peer_addr , BLE_ADDR_ANY )); // Must have address.
1867
+ assert (key -> hash .idx == 0 );
1868
+ key_data = (const uint8_t * )& key -> hash .peer_addr ;
1869
+ key_data_len = sizeof (ble_addr_t );
1870
+ break ;
1871
+ }
1865
1872
default :
1866
1873
return BLE_HS_ENOTSUP ;
1867
1874
}
@@ -1873,12 +1880,23 @@ STATIC int ble_store_ram_read(int obj_type, const union ble_store_key *key, unio
1873
1880
return BLE_HS_ENOENT ;
1874
1881
}
1875
1882
1876
- if (value_data_len != sizeof (struct ble_store_value_sec )) {
1877
- 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 ));
1883
+ size_t expected_len ;
1884
+ uint8_t * dest ;
1885
+ if (obj_type == BLE_STORE_OBJ_TYPE_HASH ){
1886
+ expected_len = sizeof (struct ble_store_value_hash );
1887
+ dest = (uint8_t * )& value -> hash ;
1888
+ }
1889
+ else {
1890
+ expected_len = sizeof (struct ble_store_value_sec );
1891
+ dest = (uint8_t * )& value -> sec ;
1892
+ }
1893
+
1894
+ if (value_data_len != expected_len ) {
1895
+ 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 ));
1878
1896
return BLE_HS_ENOENT ;
1879
1897
}
1880
1898
1881
- memcpy (( uint8_t * ) & value -> sec , value_data , sizeof ( struct ble_store_value_sec ) );
1899
+ memcpy (dest , value_data , expected_len );
1882
1900
1883
1901
DEBUG_printf ("ble_store_ram_read: found secret\n" );
1884
1902
@@ -1918,6 +1936,23 @@ STATIC int ble_store_ram_write(int obj_type, const union ble_store_value *val) {
1918
1936
// Just pretend we wrote it.
1919
1937
return 0 ;
1920
1938
}
1939
+ case BLE_STORE_OBJ_TYPE_HASH : {
1940
+ struct ble_store_key_hash key_hash ;
1941
+ const struct ble_store_value_hash * value_hash = & val -> hash ;
1942
+ ble_store_key_from_value_hash (& key_hash , value_hash );
1943
+
1944
+ assert (ble_addr_cmp (& key_hash .peer_addr , BLE_ADDR_ANY ));
1945
+
1946
+ if (!mp_bluetooth_gap_on_set_secret (obj_type , (const uint8_t * )& key_hash .peer_addr , sizeof (ble_addr_t ), (const uint8_t * )value_hash , sizeof (struct ble_store_value_hash ))) {
1947
+ DEBUG_printf ("Failed to write hash key: type=%d\n" , obj_type );
1948
+ return BLE_HS_ESTORE_CAP ;
1949
+ }
1950
+
1951
+ DEBUG_printf ("ble_secret_store_write: wrote hash\n" );
1952
+
1953
+ return 0 ;
1954
+
1955
+ }
1921
1956
default :
1922
1957
return BLE_HS_ENOTSUP ;
1923
1958
}
@@ -1948,6 +1983,19 @@ STATIC int ble_store_ram_delete(int obj_type, const union ble_store_key *key) {
1948
1983
// Just pretend it wasn't there.
1949
1984
return BLE_HS_ENOENT ;
1950
1985
}
1986
+ case BLE_STORE_OBJ_TYPE_HASH : {
1987
+ assert (ble_addr_cmp (& key -> hash .peer_addr , BLE_ADDR_ANY )); // Must have address.
1988
+
1989
+ if (!mp_bluetooth_gap_on_set_secret (obj_type , (const uint8_t * )& key -> hash .peer_addr , sizeof (ble_addr_t ), NULL , 0 )) {
1990
+ DEBUG_printf ("Failed to delete key: type=%d\n" , obj_type );
1991
+ return BLE_HS_ENOENT ;
1992
+ }
1993
+
1994
+ DEBUG_printf ("ble_secret_store_delete: deleted secret\n" );
1995
+
1996
+ return 0 ;
1997
+
1998
+ }
1951
1999
default :
1952
2000
return BLE_HS_ENOTSUP ;
1953
2001
}
0 commit comments