Skip to content

Commit 35372d8

Browse files
committed
rename bond_data to bond_keys
1 parent 751195f commit 35372d8

File tree

5 files changed

+62
-52
lines changed

5 files changed

+62
-52
lines changed

libraries/Bluefruit52Lib/src/BLEGap.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,13 @@ bool BLEGap::requestPairing(uint16_t conn_hdl)
159159
if ( peer->role == BLE_GAP_ROLE_CENTRAL )
160160
{
161161
// Check to see if we did bonded with current prph previously
162-
bond_data_t bdata;
162+
bond_keys_t bkeys;
163163

164-
if ( bond_find_cntr(&peer->addr, &bdata) )
164+
if ( bond_find_cntr(&peer->addr, &bkeys) )
165165
{
166-
cntr_ediv = bdata.peer_enc.master_id.ediv;
166+
cntr_ediv = bkeys.peer_enc.master_id.ediv;
167167
LOG_LV2("BOND", "Load Keys from file " BOND_FNAME_CNTR, cntr_ediv);
168-
VERIFY_STATUS( sd_ble_gap_encrypt(conn_hdl, &bdata.peer_enc.master_id, &bdata.peer_enc.enc_info), false);
168+
VERIFY_STATUS( sd_ble_gap_encrypt(conn_hdl, &bkeys.peer_enc.master_id, &bkeys.peer_enc.enc_info), false);
169169

170170
}else
171171
{
@@ -284,11 +284,11 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
284284
case BLE_GAP_EVT_SEC_PARAMS_REQUEST:
285285
{
286286
// Pairing in progress, Peer asking for our info
287-
peer->bond_data = (bond_data_t*) rtos_malloc( sizeof(bond_data_t));
288-
VERIFY(peer->bond_data, );
287+
peer->bond_keys = (bond_keys_t*) rtos_malloc( sizeof(bond_keys_t));
288+
VERIFY(peer->bond_keys, );
289289

290-
bond_data_t* bdata = peer->bond_data;
291-
memclr(bdata, sizeof(bond_data_t));
290+
bond_keys_t* bkeys = peer->bond_keys;
291+
memclr(bkeys, sizeof(bond_keys_t));
292292

293293
peer->ediv = 0xFFFF; // invalid value for ediv
294294

@@ -309,15 +309,15 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
309309
ble_gap_sec_keyset_t keyset =
310310
{
311311
.keys_own = {
312-
.p_enc_key = &bdata->own_enc,
312+
.p_enc_key = &bkeys->own_enc,
313313
.p_id_key = NULL,
314314
.p_sign_key = NULL,
315315
.p_pk = NULL
316316
},
317317

318318
.keys_peer = {
319-
.p_enc_key = &bdata->peer_enc,
320-
.p_id_key = &bdata->peer_id,
319+
.p_enc_key = &bkeys->peer_enc,
320+
.p_id_key = &bkeys->peer_id,
321321
.p_sign_key = NULL,
322322
.p_pk = NULL
323323
}
@@ -340,16 +340,16 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
340340
if (BLE_GAP_SEC_STATUS_SUCCESS == status->auth_status)
341341
{
342342
peer->paired = true;
343-
peer->ediv = peer->bond_data->own_enc.master_id.ediv;
343+
peer->ediv = peer->bond_keys->own_enc.master_id.ediv;
344344

345-
bond_save_keys(peer->role, conn_hdl, peer->bond_data);
345+
bond_save_keys(peer->role, conn_hdl, peer->bond_keys);
346346
}else
347347
{
348348
PRINT_HEX(status->auth_status);
349349
}
350350

351-
rtos_free(peer->bond_data);
352-
peer->bond_data = NULL;
351+
rtos_free(peer->bond_keys);
352+
peer->bond_keys = NULL;
353353
}
354354
break;
355355

@@ -360,14 +360,14 @@ void BLEGap::_eventHandler(ble_evt_t* evt)
360360
// - Else return NULL --> Initiate key exchange
361361
ble_gap_evt_sec_info_request_t* sec_req = (ble_gap_evt_sec_info_request_t*) &evt->evt.gap_evt.params.sec_info_request;
362362

363-
bond_data_t bdata;
364-
varclr(&bdata);
363+
bond_keys_t bkeys;
364+
varclr(&bkeys);
365365

366-
if ( bond_load_keys(peer->role, sec_req->master_id.ediv, &bdata) )
366+
if ( bond_load_keys(peer->role, sec_req->master_id.ediv, &bkeys) )
367367
{
368-
sd_ble_gap_sec_info_reply(evt->evt.gap_evt.conn_handle, &bdata.own_enc.enc_info, &bdata.peer_id.id_info, NULL);
368+
sd_ble_gap_sec_info_reply(evt->evt.gap_evt.conn_handle, &bkeys.own_enc.enc_info, &bkeys.peer_id.id_info, NULL);
369369

370-
peer->ediv = bdata.own_enc.master_id.ediv;
370+
peer->ediv = bkeys.own_enc.master_id.ediv;
371371
} else
372372
{
373373
sd_ble_gap_sec_info_reply(evt->evt.gap_evt.conn_handle, NULL, NULL, NULL);

libraries/Bluefruit52Lib/src/BLEGap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class BLEGap
100100
ble_gap_addr_t addr;
101101

102102
uint16_t ediv;
103-
bond_data_t* bond_data; // Shared keys with bonded device, size ~ 80 bytes
103+
bond_keys_t* bond_keys; // Shared keys with bonded device, size ~ 80 bytes
104104

105105
SemaphoreHandle_t hvn_tx_sem;
106106
SemaphoreHandle_t wrcmd_tx_sem;

libraries/Bluefruit52Lib/src/services/BLEDfu.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ static void bledfu_control_wr_authorize_cb(BLECharacteristic& chr, ble_gatts_evt
139139

140140
if ( Bluefruit.Gap.paired(conn_hdl) )
141141
{
142-
bond_data_t bdata;
142+
bond_keys_t bkeys;
143143

144-
if ( bond_load_keys( BLE_GAP_ROLE_PERIPH, Bluefruit.Gap._get_peer(conn_hdl)->ediv, &bdata ) )
144+
if ( bond_load_keys( BLE_GAP_ROLE_PERIPH, Bluefruit.Gap._get_peer(conn_hdl)->ediv, &bkeys ) )
145145
{
146-
peer_data->addr = bdata.peer_id.id_addr_info;
147-
peer_data->irk = bdata.peer_id.id_info;
148-
peer_data->enc_key = bdata.own_enc;
146+
peer_data->addr = bkeys.peer_id.id_addr_info;
147+
peer_data->irk = bkeys.peer_id.id_info;
148+
peer_data->enc_key = bkeys.own_enc;
149149
}
150150
}
151151

libraries/Bluefruit52Lib/src/utility/bonding.cpp

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ static void get_fname (char* fname, uint8_t role, uint16_t ediv)
6363
sprintf(fname, (role == BLE_GAP_ROLE_PERIPH) ? BOND_FNAME_PRPH : BOND_FNAME_CNTR, ediv);
6464
}
6565

66+
static bool skip_data_field(File* f)
67+
{
68+
int len = f->read();
69+
VERIFY(len > 0);
70+
71+
f->seek(len + f->position());
72+
return true;
73+
}
74+
6675
void bond_init(void)
6776
{
6877
InternalFS.begin();
@@ -75,9 +84,9 @@ void bond_init(void)
7584
/*------------------------------------------------------------------*/
7685
/* Keys
7786
*------------------------------------------------------------------*/
78-
static void bond_save_keys_dfr (uint8_t role, uint16_t conn_hdl, bond_data_t* bdata)
87+
static void bond_save_keys_dfr (uint8_t role, uint16_t conn_hdl, bond_keys_t* bkeys)
7988
{
80-
uint16_t const ediv = (role == BLE_GAP_ROLE_PERIPH) ? bdata->own_enc.master_id.ediv : bdata->peer_enc.master_id.ediv;
89+
uint16_t const ediv = (role == BLE_GAP_ROLE_PERIPH) ? bkeys->own_enc.master_id.ediv : bkeys->peer_enc.master_id.ediv;
8190

8291
char filename[BOND_FNAME_LEN];
8392
get_fname(filename, role, ediv);
@@ -89,8 +98,8 @@ static void bond_save_keys_dfr (uint8_t role, uint16_t conn_hdl, bond_data_t* bd
8998
VERIFY(file,);
9099

91100
//------------- save keys -------------//
92-
file.write(sizeof(bond_data_t));
93-
file.write((uint8_t*) bdata, sizeof(bond_data_t));
101+
file.write(sizeof(bond_keys_t));
102+
file.write((uint8_t*) bkeys, sizeof(bond_keys_t));
94103

95104
//------------- save device name -------------//
96105
char devname[CFG_MAX_DEVNAME_LEN] = { 0 };
@@ -99,7 +108,7 @@ static void bond_save_keys_dfr (uint8_t role, uint16_t conn_hdl, bond_data_t* bd
99108
// If couldn't get devname then use peer mac address
100109
if ( !devname[0] )
101110
{
102-
uint8_t* mac = bdata->peer_id.id_addr_info.addr;
111+
uint8_t* mac = bkeys->peer_id.id_addr_info.addr;
103112
sprintf(devname, "%02X:%02X:%02X:%02X:%02X:%02X", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
104113
}
105114

@@ -112,20 +121,20 @@ static void bond_save_keys_dfr (uint8_t role, uint16_t conn_hdl, bond_data_t* bd
112121
file.close();
113122
}
114123

115-
bool bond_save_keys (uint8_t role, uint16_t conn_hdl, bond_data_t* bdata)
124+
bool bond_save_keys (uint8_t role, uint16_t conn_hdl, bond_keys_t* bkeys)
116125
{
117-
uint8_t* buf = (uint8_t*) rtos_malloc( sizeof(bond_data_t) );
126+
uint8_t* buf = (uint8_t*) rtos_malloc( sizeof(bond_keys_t) );
118127
VERIFY(buf);
119128

120-
memcpy(buf, bdata, sizeof(bond_data_t));
129+
memcpy(buf, bkeys, sizeof(bond_keys_t));
121130

122131
// queue to execute in Ada Callback thread
123132
ada_callback(buf, bond_save_keys_dfr, role, conn_hdl, buf);
124133

125134
return true;
126135
}
127136

128-
bool bond_load_keys(uint8_t role, uint16_t ediv, bond_data_t* bdata)
137+
bool bond_load_keys(uint8_t role, uint16_t ediv, bond_keys_t* bkeys)
129138
{
130139
char filename[BOND_FNAME_LEN];
131140
get_fname(filename, role, ediv);
@@ -134,9 +143,9 @@ bool bond_load_keys(uint8_t role, uint16_t ediv, bond_data_t* bdata)
134143
VERIFY(file);
135144

136145
int keylen = file.read();
137-
VERIFY(keylen == sizeof(bond_data_t));
146+
VERIFY(keylen == sizeof(bond_keys_t));
138147

139-
file.read(bdata, keylen);
148+
file.read(bkeys, keylen);
140149
file.close();
141150

142151
BOND_LOG("Loaded keys from file %s", filename);
@@ -240,15 +249,16 @@ void bond_print_list(uint8_t role)
240249

241250
while ( (file = dir.openNextFile(FILE_READ)) )
242251
{
243-
file.seek(file.read() + file.position()); // skip key
244-
245-
int len = file.read();
246-
if ( len > 0 )
252+
if ( skip_data_field(&file) ) // skip key
247253
{
248-
char devname[len];
249-
file.read(devname, len);
254+
int len = file.read();
255+
if ( len > 0 )
256+
{
257+
char devname[len];
258+
file.read(devname, len);
250259

251-
cprintf(" %s : %s (%d bytes)\n", file.name(), devname, file.size());
260+
cprintf(" %s : %s (%d bytes)\n", file.name(), devname, file.size());
261+
}
252262
}
253263
file.close();
254264
}
@@ -260,7 +270,7 @@ void bond_print_list(uint8_t role)
260270
}
261271

262272

263-
bool bond_find_cntr(ble_gap_addr_t* addr, bond_data_t* bdata)
273+
bool bond_find_cntr(ble_gap_addr_t* addr, bond_keys_t* bkeys)
264274
{
265275
bool found = false;
266276

@@ -271,12 +281,12 @@ bool bond_find_cntr(ble_gap_addr_t* addr, bond_data_t* bdata)
271281
{
272282
// Read bond data of each stored file
273283
int keylen = file.read();
274-
if ( keylen == sizeof(bond_data_t) )
284+
if ( keylen == sizeof(bond_keys_t) )
275285
{
276-
file.read((uint8_t*) bdata, keylen);
286+
file.read((uint8_t*) bkeys, keylen);
277287

278288
// Compare static address
279-
if ( !memcmp(addr->addr, bdata->peer_id.id_addr_info.addr, 6) )
289+
if ( !memcmp(addr->addr, bkeys->peer_id.id_addr_info.addr, 6) )
280290
{
281291
found = true;
282292
}

libraries/Bluefruit52Lib/src/utility/bonding.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ typedef struct
5050
ble_gap_enc_key_t own_enc;
5151
ble_gap_enc_key_t peer_enc;
5252
ble_gap_id_key_t peer_id;
53-
} bond_data_t;
53+
} bond_keys_t;
5454

5555
void bond_init(void);
5656
void bond_clear_prph(void);
@@ -59,15 +59,15 @@ void bond_clear_all(void);
5959

6060
void bond_remove_key(uint8_t role, uint16_t ediv);
6161

62-
bool bond_save_keys (uint8_t role, uint16_t conn_hdl, bond_data_t* bdata);
63-
bool bond_load_keys(uint8_t role, uint16_t ediv, bond_data_t* bdata);
62+
bool bond_save_keys (uint8_t role, uint16_t conn_hdl, bond_keys_t* bkeys);
63+
bool bond_load_keys(uint8_t role, uint16_t ediv, bond_keys_t* bkeys);
6464

6565
bool bond_save_cccd (uint8_t role, uint16_t conn_hdl, uint16_t ediv);
6666
bool bond_load_cccd (uint8_t role, uint16_t conn_hdl, uint16_t ediv);
6767

6868
void bond_print_list(uint8_t role);
6969

70-
bool bond_find_cntr(ble_gap_addr_t* addr, bond_data_t* bdata);
70+
bool bond_find_cntr(ble_gap_addr_t* addr, bond_keys_t* bkeys);
7171

7272

7373

0 commit comments

Comments
 (0)