Skip to content

Fixed packet fragmentation #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/utility/HCI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,7 @@ void HCIClass::handleAclDataPkt(uint8_t /*plen*/, uint8_t pdata[])
uint16_t cid;
} *aclHdr = (HCIACLHdr*)pdata;

#ifdef _BLE_TRACE_
Serial.println("Received data");
#endif

uint16_t aclFlags = (aclHdr->handle & 0xf000) >> 12;

if ((aclHdr->dlen - 4) != aclHdr->len) {
Expand All @@ -729,6 +727,17 @@ void HCIClass::handleAclDataPkt(uint8_t /*plen*/, uint8_t pdata[])
}

if ((aclHdr->dlen - 4) != aclHdr->len) {
#ifdef _BLE_TRACE_
Serial.println("Don't have full packet yet");
Serial.print("Handle: ");
btct.printBytes((uint8_t*)&aclHdr->handle,2);
Serial.print("dlen: ");
btct.printBytes((uint8_t*)&aclHdr->dlen,2);
Serial.print("len: ");
btct.printBytes((uint8_t*)&aclHdr->len,2);
Serial.print("cid: ");
btct.printBytes((uint8_t*)&aclHdr->cid,2);
#endif
// don't have the full packet yet
return;
}
Expand All @@ -751,7 +760,11 @@ void HCIClass::handleAclDataPkt(uint8_t /*plen*/, uint8_t pdata[])
#ifdef _BLE_TRACE_
Serial.println("Security data");
#endif
L2CAPSignaling.handleSecurityData(aclHdr->handle & 0x0fff, aclHdr->len, &_recvBuffer[1 + sizeof(HCIACLHdr)]);
if (aclFlags == 0x1){
L2CAPSignaling.handleSecurityData(aclHdr->handle & 0x0fff, aclHdr->len, &_aclPktBuffer[sizeof(HCIACLHdr)]);
}else{
L2CAPSignaling.handleSecurityData(aclHdr->handle & 0x0fff, aclHdr->len, &_recvBuffer[1 + sizeof(HCIACLHdr)]);
}

}else {
struct __attribute__ ((packed)) {
Expand Down
13 changes: 11 additions & 2 deletions src/utility/L2CAPSignaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "btct.h"
#include "L2CAPSignaling.h"
#include "keyDistribution.h"

#include "bitDescriptions.h"
#define CONNECTION_PARAMETER_UPDATE_REQUEST 0x12
#define CONNECTION_PARAMETER_UPDATE_RESPONSE 0x13

Expand Down Expand Up @@ -143,6 +143,15 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t
ATT.remoteKeyDistribution = KeyDistribution(pairingRequest->initiatorKeyDistribution);
ATT.localKeyDistribution = KeyDistribution(pairingRequest->responderKeyDistribution);
KeyDistribution rkd(pairingRequest->responderKeyDistribution);
AuthReq req(pairingRequest->authReq);
#ifdef _BLE_TRACE_
Serial.print("Req has properties: ");
Serial.print(req.Bonding()?"bonding, ":"no bonding, ");
Serial.print(req.CT2()?"CT2, ":"no CT2, ");
Serial.print(req.KeyPress()?"KeyPress, ":"no KeyPress, ");
Serial.print(req.MITM()?"MITM, ":"no MITM, ");
Serial.print(req.SC()?"SC, ":"no SC, ");
#endif

uint8_t peerIOCap[3];
peerIOCap[0] = pairingRequest->authReq;
Expand All @@ -152,7 +161,7 @@ void L2CAPSignalingClass::handleSecurityData(uint16_t connectionHandle, uint8_t
ATT.setPeerEncryption(connectionHandle, ATT.getPeerEncryption(connectionHandle) | PEER_ENCRYPTION::PAIRING_REQUEST);
#ifdef _BLE_TRACE_
Serial.print("Peer encryption : 0b");
Serial.print(ATT.getPeerEncryption(connectionHandle), BIN);
Serial.println(ATT.getPeerEncryption(connectionHandle), BIN);
#endif
struct __attribute__ ((packed)) PairingResponse {
uint8_t code;
Expand Down
30 changes: 30 additions & 0 deletions src/utility/bitDescriptions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "bitDescriptions.h"


#define BONDING_BIT 0b00000001
#define MITM_BIT 0b00000100
#define SC_BIT 0b00001000
#define KEYPRESS_BIT 0b00010000
#define CT2_BIT 0b00100000


AuthReq::AuthReq(){}
AuthReq::AuthReq(uint8_t octet):_octet(octet){}
bool AuthReq::Bonding(){ return (_octet & BONDING_BIT)>0;}
bool AuthReq::MITM(){ return (_octet & MITM_BIT)>0;}
bool AuthReq::SC(){ return (_octet & SC_BIT)>0;}
bool AuthReq::KeyPress(){ return (_octet & KEYPRESS_BIT)>0;}
bool AuthReq::CT2(){ return (_octet & CT2_BIT)>0;}


void AuthReq::setBonding(bool state) { _octet= state? _octet|BONDING_BIT : _octet&~BONDING_BIT;}
void AuthReq::setMITM(bool state) { _octet= state? _octet|MITM_BIT : _octet&~MITM_BIT;}
void AuthReq::setSC(bool state){ _octet= state? _octet|SC_BIT : _octet&~SC_BIT;}
void AuthReq::setKeyPress(bool state){ _octet= state? _octet|KEYPRESS_BIT : _octet&~KEYPRESS_BIT;}
void AuthReq::setCT2(bool state){ _octet= state? _octet|CT2_BIT : _octet&~CT2_BIT;}

uint8_t _octet;


void AuthReq::setOctet( uint8_t octet){_octet = octet;}
uint8_t AuthReq::getOctet() {return _octet;}
41 changes: 41 additions & 0 deletions src/utility/bitDescriptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef _BIT_DESCRIPTIONS_H_
#define _BIT_DESCRIPTIONS_H_
#include <Arduino.h>

class AuthReq{
public:
AuthReq();
AuthReq(uint8_t octet);
void setOctet( uint8_t octet);
uint8_t getOctet();


// The Bonding_Flags field is a 2-bit field that indicates the type of bonding being requested by the initiating device
bool Bonding();
// The MITM field is a 1-bit flag that is set to one if the device is requesting MITM protection
bool MITM();
// The SC field is a 1 bit flag. If LE Secure Connections pairing is supported by the device, then the SC field shall be set to 1, otherwise it shall be set to 0.
bool SC();
// The keypress field is a 1-bit flag that is used only in the Passkey Entry protocol and shall be ignored in other protocols.
bool KeyPress();
// The CT2 field is a 1-bit flag that shall be set to 1 upon transmission to indicate support for the h7 function.
bool CT2();

void setBonding(bool state);
void setMITM(bool state);
void setSC(bool state);
void setKeyPress(bool state);
void setCT2(bool state);
private:
uint8_t _octet;
};

enum IOCap {
DisplayOnly,
DisplayYesNo,
KeyboardOnly,
NoInputNoOutput,
KeyboardDisplay
};

#endif
2 changes: 1 addition & 1 deletion src/utility/keyDistribution.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "keyDistribution.h"

KeyDistribution::KeyDistribution(){}
KeyDistribution::KeyDistribution():_octet(0){}
KeyDistribution::KeyDistribution(uint8_t octet):_octet(octet){}

#define ENCKEY 0b00000001
Expand Down