Skip to content

Commit a9db053

Browse files
committed
Wrap prints with #ifdef _BLE_TRACE_
1 parent 8692fb9 commit a9db053

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

src/utility/HCI.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ void HCIClass::leAddResolvingAddress(uint8_t addressType, uint8_t* peerAddress,
482482
addDevice.peerIRK[15-i] = peerIrk[i];
483483
addDevice.localIRK[15-i] = localIrk[i];
484484
}
485+
#ifdef _BLE_TRACE_
485486
Serial.print("ADDTYPE :");
486487
btct.printBytes(&addDevice.peerAddressType,1);
487488
Serial.print("adddddd :");
@@ -490,6 +491,7 @@ void HCIClass::leAddResolvingAddress(uint8_t addressType, uint8_t* peerAddress,
490491
btct.printBytes(addDevice.peerIRK,16);
491492
Serial.print("localIRK :");
492493
btct.printBytes(addDevice.localIRK,16);
494+
#endif
493495
sendCommand(OGF_LE_CTL << 10 | 0x27, sizeof(addDevice), &addDevice);
494496

495497
leStartResolvingAddresses();
@@ -512,17 +514,21 @@ int HCIClass::leReadPeerResolvableAddress(uint8_t peerAddressType, uint8_t* peer
512514

513515

514516
int res = sendCommand(OGF_LE_CTL << 10 | 0x2B, sizeof(request), &request);
517+
#ifdef _BLE_TRACE_
515518
Serial.print("res: 0x");
516519
Serial.println(res, HEX);
520+
#endif
517521
if(res==0){
518522
struct __attribute__ ((packed)) Response {
519523
uint8_t status;
520524
uint8_t peerResolvableAddress[6];
521525
} *response = (Response*)_cmdResponse;
526+
#ifdef _BLE_TRACE_
522527
Serial.print("Address resolution status: 0x");
523528
Serial.println(response->status, HEX);
524529
Serial.print("peer resolvable address: ");
525530
btct.printBytes(response->peerResolvableAddress,6);
531+
#endif
526532
}
527533
return res;
528534
}
@@ -562,7 +568,9 @@ int HCIClass::tryResolveAddress(uint8_t* BDAddr, uint8_t* address){
562568

563569

564570
if(!HCI._getIRKs(&nIRKs, BDAddrType, BADDRs, IRKs)){
571+
#ifdef _BLE_TRACE_
565572
Serial.println("error getting IRKs.");
573+
#endif
566574
}
567575
for(int i=0; i<nIRKs; i++){
568576
if(!foundMatch){

src/utility/btct.cpp

+14-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ unsigned char const_Rb[16] = {
2626
#define LEN_LTK 16
2727
#define LEN_MAC_KEY 16
2828

29+
#ifdef _BLE_TRACE_
2930
void BluetoothCryptoToolbox::printBytes(uint8_t bytes[], uint8_t length){
3031
for(int i=0; i<length; i++){
3132
if(i>0){
@@ -37,6 +38,8 @@ void BluetoothCryptoToolbox::printBytes(uint8_t bytes[], uint8_t length){
3738
}
3839
Serial.print('\n');
3940
}
41+
#endif
42+
4043
int BluetoothCryptoToolbox::f5(uint8_t DHKey[],uint8_t N_master[], uint8_t N_slave[],
4144
uint8_t BD_ADDR_master[], uint8_t BD_ADDR_slave[], uint8_t MacKey[], uint8_t LTK[])
4245
{
@@ -128,15 +131,15 @@ void BluetoothCryptoToolbox::testAh()
128131
{
129132
uint8_t irk[16] = {0xec,0x02,0x34,0xa3,0x57,0xc8,0xad,0x05,0x34,0x10,0x10,0xa6,0x0a,0x39,0x7d,0x9b};
130133
uint8_t expected_final[3] = {0x0d,0xfb,0xaa};
131-
132134
uint8_t ourResult[3];
133135
ah(irk, expected_final, ourResult);
134136

135-
137+
#ifdef _BLE_TRACE_
136138
Serial.print("Expected : ");
137139
printBytes(&expected_final[3], 3);
138140
Serial.print("Actual : ");
139141
printBytes(ourResult, 3);
142+
#endif
140143
}
141144

142145
int BluetoothCryptoToolbox::g2(uint8_t U[], uint8_t V[], uint8_t X[], uint8_t Y[], uint8_t out[4])
@@ -160,19 +163,19 @@ void BluetoothCryptoToolbox::testg2(){
160163
uint8_t X[16] = {0xd5,0xcb,0x84,0x54,0xd1,0x77,0x73,0x3e,0xff,0xff,0xb2,0xec,0x71,0x2b,0xae,0xab};
161164
uint8_t Y[16] = {0xa6,0xe8,0xe7,0xcc,0x25,0xa7,0x5f,0x6e,0x21,0x65,0x83,0xf7,0xff,0x3d,0xc4,0xcf};
162165
uint8_t out[4];
163-
164-
166+
165167
uint32_t expected = 0;
166168
g2(U,V,X,Y,out);
167169
uint32_t result = 0;
168170
for(int i=0; i<4; i++) result += out[i] << 8*i;
169171

172+
#ifdef _BLE_TRACE_
170173
Serial.print("Expected : ");
171174
Serial.println(expected);
172175
Serial.print("Result : ");
173176
Serial.println(result);
174177
Serial.println();
175-
178+
#endif
176179
}
177180

178181
void BluetoothCryptoToolbox::AES_CMAC ( unsigned char *key, unsigned char *input, int length,
@@ -264,16 +267,20 @@ int BluetoothCryptoToolbox::AES_128(uint8_t* key, uint8_t* data_in, uint8_t* dat
264267
int n = 0;
265268
int tries = 30;
266269
while(HCI.leEncrypt(key,data_in, &status, data_out)!=1&&n<tries){
270+
#ifdef _BLE_TRACE_
267271
Serial.print("AES failed... retrying: ");
268272
Serial.println(n);
273+
#endif
269274
BLE.end();
270275
delay(200);
271276
BLE.begin();
272277
n++;
273278
delay(100*n);
274279
}
275280
if(n==tries){
281+
#ifdef _BLE_TRACE_
276282
Serial.println("something went wrong with AES.");
283+
#endif
277284
return 0;
278285
}
279286
return 1;
@@ -288,7 +295,7 @@ void BluetoothCryptoToolbox::test(){
288295

289296
for ( i=0; i<16; i++ ) Z[i] = 0x00;
290297
uint8_t k[16] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
291-
298+
292299
Serial.println("AES Plaintext:");
293300
for(int i=0; i<16; i++){
294301
Serial.print(" 0x");
@@ -352,7 +359,7 @@ void BluetoothCryptoToolbox::test(){
352359
}
353360
Serial.println(".");
354361
}
355-
#endif
362+
#endif //_BLE_TRACE_
356363
// From RFC
357364
void BluetoothCryptoToolbox::leftshift_onebit(unsigned char *input,unsigned char *output)
358365
{

src/utility/btct.h

+2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
class BluetoothCryptoToolbox{
77
public:
88
BluetoothCryptoToolbox();
9+
#ifdef _BLE_TRACE_
910
void printBytes(uint8_t bytes[], uint8_t length);
11+
#endif
1012
void generateSubkey(uint8_t* K, uint8_t* K1, uint8_t* K2);
1113
void AES_CMAC ( unsigned char *key, unsigned char *input, int length,
1214
unsigned char *mac );

0 commit comments

Comments
 (0)