Skip to content

Commit

Permalink
Merge pull request #302 from roleroz/master
Browse files Browse the repository at this point in the history
Fix warnings
  • Loading branch information
facchinm authored Aug 4, 2023
2 parents 8ca5415 + 1dfbf62 commit 675fc91
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 55 deletions.
4 changes: 2 additions & 2 deletions src/local/BLELocalCharacteristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
BLELocalCharacteristic::BLELocalCharacteristic(const char* uuid, uint16_t permissions, int valueSize, bool fixedLength) :
BLELocalAttribute(uuid),
_properties((uint8_t)(permissions&0x000FF)),
_permissions((uint8_t)((permissions&0xFF00)>>8)),
_valueSize(min(valueSize, 512)),
_valueLength(0),
_fixedLength(fixedLength),
_handle(0x0000),
_broadcast(false),
_written(false),
_cccdValue(0x0000),
_permissions((uint8_t)((permissions&0xFF00)>>8))
_cccdValue(0x0000)
{
memset(_eventHandlers, 0x00, sizeof(_eventHandlers));

Expand Down
35 changes: 1 addition & 34 deletions src/utility/HCI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,16 +553,12 @@ int HCIClass::readStoredLK(uint8_t BD_ADDR[], uint8_t read_all ){
}

int HCIClass::tryResolveAddress(uint8_t* BDAddr, uint8_t* address){
uint8_t iphone[16] = {0xA6, 0xD2, 0xD, 0xD3, 0x4F, 0x13, 0x42, 0x4F, 0xE1, 0xC1, 0xFD, 0x22, 0x2E, 0xC5, 0x6A, 0x2D};
uint8_t irk[16];
for(int i=0; i<16; i++) irk[15-i] = iphone[i];
bool foundMatch = false;
if(HCI._getIRKs!=0){
uint8_t nIRKs = 0;
uint8_t** BDAddrType = new uint8_t*;
uint8_t*** BADDRs = new uint8_t**;
uint8_t*** IRKs = new uint8_t**;
uint8_t* memcheck;


if(!HCI._getIRKs(&nIRKs, BDAddrType, BADDRs, IRKs)){
Expand Down Expand Up @@ -971,33 +967,12 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[])
data += 2;
}
}
else if(eventHdr->evt == EVT_RETURN_LINK_KEYS)
{
uint8_t num_keys = (uint8_t)pdata[sizeof(HCIEventHdr)];
// Serial.print("N keys: ");
// Serial.println(num_keys);
uint8_t BD_ADDRs[num_keys][6];
uint8_t LKs[num_keys][16];
auto nAddresss = [pdata](uint8_t nAddr)->uint8_t*{
return (uint8_t*) &pdata[sizeof(HCIEventHdr)] + 1 + nAddr*6 + nAddr*16;
};
auto nLK = [pdata](uint8_t nLK)->uint8_t*{
return (uint8_t*) &pdata[sizeof(HCIEventHdr)] + 1 + (nLK+1)*6 + nLK*16;
};
// Serial.println("Stored LKs are: ");
// for(int i=0; i<num_keys; i++){
// Serial.print("Address : ");
// btct.printBytes(nAddresss(i),6);
// Serial.print("LK : ");
// btct.printBytes(nLK(i),16);
// }
}
else if(eventHdr->evt == 0x10)
{
#ifdef _BLE_TRACE_
struct __attribute__ ((packed)) CmdHardwareError {
uint8_t hardwareCode;
} *cmdHardwareError = (CmdHardwareError*)&pdata[sizeof(HCIEventHdr)];
#ifdef _BLE_TRACE_
Serial.print("Bluetooth hardware error.");
Serial.print(" Code: 0x");
Serial.println(cmdHardwareError->hardwareCode, HEX);
Expand Down Expand Up @@ -1096,9 +1071,6 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[])
leConnectionComplete->supervisionTimeout,
leConnectionComplete->masterClockAccuracy);
}
uint8_t address[6];
uint8_t BDAddr[6];
for(int i=0; i<6; i++) BDAddr[5-i] = leConnectionComplete->peerBdaddr[i];
// leReadPeerResolvableAddress(leConnectionComplete->peerBdaddrType,BDAddr,address);
// Serial.print("Resolving address: ");
// btct.printBytes(BDAddr, 6);
Expand Down Expand Up @@ -1325,11 +1297,6 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[])

// Send Pairing confirm response
HCI.sendAclPkt(connectionHandle, SECURITY_CID, sizeof(pairingConfirm), &pairingConfirm);
// Start calculating DH Key
uint8_t remotePublicKeyReversed[sizeof(HCI.remotePublicKeyBuffer)];
for(int i=0; i<sizeof(HCI.remotePublicKeyBuffer); i++){
remotePublicKeyReversed[sizeof(HCI.remotePublicKeyBuffer)-i] = HCI.remotePublicKeyBuffer[i];
}

HCI.sendCommand( (OGF_LE_CTL << 10) | LE_COMMAND::GENERATE_DH_KEY_V1, sizeof(HCI.remotePublicKeyBuffer), HCI.remotePublicKeyBuffer);
}else{
Expand Down
9 changes: 2 additions & 7 deletions src/utility/L2CAPSignaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,12 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t
}
else if(code == CONNECTION_PAIRING_FAILED)
{
#ifdef _BLE_TRACE_
struct __attribute__ ((packed)) PairingFailed
{
uint8_t code;
uint8_t reason;
} *pairingFailed = (PairingFailed*)data;
#ifdef _BLE_TRACE_
Serial.print("Pairing failed with code: 0x");
Serial.println(pairingFailed->reason,HEX);
#endif
Expand All @@ -293,7 +293,7 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t
} *identityAddress = (IdentityAddress*)data;
// we can save this information now.
uint8_t peerAddress[6];
for(int i; i<6; i++) peerAddress[5-i] = identityAddress->address[i];
for(int i=0; i<6; i++) peerAddress[5-i] = identityAddress->address[i];

HCI.saveNewAddress(identityAddress->addressType, peerAddress, ATT.peerIRK, ATT.localIRK);
if(HCI._storeLTK!=0){
Expand All @@ -315,11 +315,6 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t
};
memcpy(generateDHKeyCommand.x,connectionPairingPublicKey->x,32);
memcpy(generateDHKeyCommand.y,connectionPairingPublicKey->y,32);
struct __attribute__ ((packed)) ReadPublicKeyCommand {
uint8_t code;
} readPublicKeyCommand = {
LE_COMMAND::READ_LOCAL_P256,
};

if(ATT.setPeerEncryption(connectionHandle, ATT.getPeerEncryption(connectionHandle) | PEER_ENCRYPTION::REQUESTED_ENCRYPTION)){
#ifdef _BLE_TRACE_
Expand Down
12 changes: 0 additions & 12 deletions src/utility/btct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,8 @@ int BluetoothCryptoToolbox::f5(uint8_t DHKey[],uint8_t N_master[], uint8_t N_sla
printBytes(BD_ADDR_slave, ADDR_LEN);
#endif

uint8_t ADD_M[7];
uint8_t ADD_S[7];
uint8_t T[16];

for(int i=0; i<6; i++){
ADD_M[1+i] = BD_ADDR_master[i];
ADD_M[0] = 0x00;
ADD_S[i+1] = BD_ADDR_slave[i];
ADD_S[0] = 0x00;
}
struct __attribute__ ((packed)) CmacInput
{
uint8_t counter;
Expand Down Expand Up @@ -135,11 +127,8 @@ int BluetoothCryptoToolbox::ah(uint8_t k[16], uint8_t r[3], uint8_t* result)
void BluetoothCryptoToolbox::testAh()
{
uint8_t irk[16] = {0xec,0x02,0x34,0xa3,0x57,0xc8,0xad,0x05,0x34,0x10,0x10,0xa6,0x0a,0x39,0x7d,0x9b};
uint8_t r[3] = {0x70,0x81,0x94};
uint8_t expected_AES[16] = {0x15,0x9d,0x5f,0xb7,0x2e,0xbe,0x23,0x11,0xa4,0x8c,0x1b,0xdc,0xc4,0x0d,0xfb,0xaa};
uint8_t expected_final[3] = {0x0d,0xfb,0xaa};

for(int i=0; i<3; i++) r[2-i] = expected_final[3+i];
uint8_t ourResult[3];
ah(irk, expected_final, ourResult);

Expand Down Expand Up @@ -170,7 +159,6 @@ void BluetoothCryptoToolbox::testg2(){
uint8_t V[32] = {0x55,0x18,0x8b,0x3d,0x32,0xf6,0xbb,0x9a,0x90,0x0a,0xfc,0xfb,0xee,0xd4,0xe7,0x2a,0x59,0xcb,0x9a,0xc2,0xf1,0x9d,0x7c,0xfb,0x6b,0x4f,0xdd,0x49,0xf4,0x7f,0xc5,0xfd};
uint8_t X[16] = {0xd5,0xcb,0x84,0x54,0xd1,0x77,0x73,0x3e,0xff,0xff,0xb2,0xec,0x71,0x2b,0xae,0xab};
uint8_t Y[16] = {0xa6,0xe8,0xe7,0xcc,0x25,0xa7,0x5f,0x6e,0x21,0x65,0x83,0xf7,0xff,0x3d,0xc4,0xcf};
uint8_t AES[16] = {0x15,0x36,0xd1,0x8d,0xe3,0xd2,0x0d,0xf9,0x9b,0x70,0x44,0xc1,0x2f,0x9e,0xd5,0xba};
uint8_t out[4];


Expand Down

0 comments on commit 675fc91

Please sign in to comment.