Bluefruit based blemesh implementation wont send packets

For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
YogurtMafia
 
Posts: 6
Joined: Fri Jan 14, 2022 3:57 pm

Bluefruit based blemesh implementation wont send packets

Post by YogurtMafia »

Im building a blemesh network of smoke detectors for a school project. Im using bluefruit as my scanner and advertiser to process packets. The first packet will always send but if i try to change the packet length only certain sizes will transmit. For example, if i send a message packet of 31 bytes, that message length will always work, but if i then try to send a 24 byte secure beacon it wont transmit. If i reset the device and send the beacon first, the beacon will work but not the 31 byte packet. (see attached pictures). I cant post my code because the entirety is over 3000 lines at this point, but i can include my network_publish function to demonstrate how i implemented it. The packet variable is a global stored 31 byte buffer.
//Encrypts Network Layer, Adds and Obfusicates Header, Advertises Data
bool network_publish(CRYS_AESCCM_Key_t netKey,uint8_t data[],uint8_t length,volatile uint8_t ttl,volatile uint8_t seq1,volatile uint8_t seq2,volatile uint8_t seq3,volatile uint8_t src[],volatile uint8_t dst[],
enum packetType type = ACCESS)
{
bumpSeq(seq_ptr); // increment seq value by one
uint8_t SZMIC = 4;//access packets have 4 byte MIC
if(type == CTL){ttl = ttl|128; SZMIC = 8;}//control packets have 8 byte MIC
uint8_t netData[length+2] = {dst[0],dst[1]};
memcpy(&netData[2],data,length);
uint8_t encryptKey[16];
uint8_t privacyKey[16];
uint8_t IVI_NID = k2(netKey,encryptKey,privacyKey);
uint8_t netPDU[length+ 11 + SZMIC] = {length+10+SZMIC,0x2A,IVI_NID,ttl,seq1,seq2,seq3,src[0],src[1]};// add header

generate_netIV(netIV,ttl,seq1,seq2,seq3,src[0],src[1],ivIndex);
uint32_t err = CC_AESCCM(encrypt,encryptKey,KeySize,netIV,(uint8_t)13,0,(uint8_t)0,netData,(uint32_t)sizeof(netData),&netPDU[9],SZMIC,&netPDU[length+11],ccmmode);
if(err != CRYS_OK)
{
Serial.print(F("NETWORK LAYER ENCRYPTION ERROR: "));
Serial.println(err);
return false;
}
//Obfusicate Header
uint8_t privacyRandom[16]= {0x00,0x00,0x00,0x00,0x00,ivIndex[0],ivIndex[1],ivIndex[2],ivIndex[3]};
memcpy(&privacyRandom[9], &netPDU[9] ,7 * sizeof(uint8_t));
uint8_t PECB[16];
e(privacyRandom, privacyKey, PECB, SASI_AES_ENCRYPT);
for(int i = 3; i < 9; i++)
{
netPDU = netPDU ^ PECB[i-3];
}
//Add Encrypted Data to Packet
memcpy(packet,netPDU,sizeof(netPDU));
Bluefruit.Advertising.setData(packet,31);//currently only 31 byte packets are supported
Serial.print("packet sent: ");
Serial.printBuffer(packet,sizeof(packet), '-');
Serial.println();
Bluefruit.Advertising.start(ADV_PERIOD);
return true;
}
Attachments
beacon being sent first, received by the server
beacon being sent first, received by the server
Screenshot from 2022-01-23 17-40-14.png (116.34 KiB) Viewed 105 times
sending a beacon after a sensor get, no response from the server
sending a beacon after a sensor get, no response from the server
Screenshot from 2022-01-23 17-39-46.png (142.11 KiB) Viewed 105 times
sending a sensor get, response from server
sending a sensor get, response from server
Screenshot from 2022-01-23 17-39-17.png (131.34 KiB) Viewed 105 times

Locked
Please be positive and constructive with your questions and comments.

Return to “Wireless: WiFi and Bluetooth”