|
24 | 24 | #include "btct.h"
|
25 | 25 | #include "HCI.h"
|
26 | 26 |
|
| 27 | +//#define _BLE_TRACE_ |
| 28 | + |
27 | 29 | #define HCI_COMMAND_PKT 0x01
|
28 | 30 | #define HCI_ACLDATA_PKT 0x02
|
29 | 31 | #define HCI_EVENT_PKT 0x04
|
@@ -1408,13 +1410,34 @@ void HCIClass::handleEventPkt(uint8_t /*plen*/, uint8_t pdata[])
|
1408 | 1410 | btct.printBytes(MasterIOCap, 3);
|
1409 | 1411 | Serial.println("Send Eb Back.");
|
1410 | 1412 | #endif
|
1411 |
| - uint8_t ret[17]; |
1412 |
| - ret[0] = 0x0d; |
1413 |
| - for(int i=0; i<sizeof(Eb); i++){ |
1414 |
| - ret[sizeof(Eb)-i] = Eb[i]; |
| 1413 | + // Check if RemoteDHKeyCheck = Ea |
| 1414 | + bool EaCheck = true; |
| 1415 | + for(int i = 0; i < 16; i++){ |
| 1416 | + if (Ea[i] != HCI.remoteDHKeyCheckBuffer[i]){ |
| 1417 | + EaCheck = false; |
| 1418 | + } |
| 1419 | + } |
| 1420 | + |
| 1421 | + if (EaCheck){ |
| 1422 | + // Send our confirmation value to complete authentication stage 2 |
| 1423 | + uint8_t ret[17]; |
| 1424 | + ret[0] = CONNECTION_PAIRING_DHKEY_CHECK; |
| 1425 | + for(int i=0; i<sizeof(Eb); i++){ |
| 1426 | + ret[sizeof(Eb)-i] = Eb[i]; |
| 1427 | + } |
| 1428 | + HCI.sendAclPkt(connectionHandle, SECURITY_CID, sizeof(ret), ret ); |
| 1429 | + ATT.setPeerEncryption(connectionHandle, encryption | PEER_ENCRYPTION::SENT_DH_CHECK); |
| 1430 | + |
| 1431 | + } else { |
| 1432 | + // If check fails, abort |
| 1433 | +#ifdef _BLE_TRACE_ |
| 1434 | + Serial.println("Error: DHKey check failed - Aborting"); |
| 1435 | +#endif |
| 1436 | + uint8_t ret[2] = {CONNECTION_PAIRING_FAILED, 0x0B}; // DHKey Check Faile |
| 1437 | + HCI.sendAclPkt(connectionHandle, SECURITY_CID, sizeof(ret), ret); |
| 1438 | + ATT.setPeerEncryption(connectionHandle, NO_ENCRYPTION); |
1415 | 1439 | }
|
1416 |
| - HCI.sendAclPkt(connectionHandle, 0x06, sizeof(ret), ret ); |
1417 |
| - ATT.setPeerEncryption(connectionHandle, encryption | PEER_ENCRYPTION::SENT_DH_CHECK); |
| 1440 | + |
1418 | 1441 | }else{
|
1419 | 1442 | #ifdef _BLE_TRACE_
|
1420 | 1443 | Serial.println("Waiting on other DHKey check before calculating.");
|
|
0 commit comments