TSCH: bugfix in frame encryption
Header IEs shouldn't be encrypted since they are part of the header.
@@ -138,6 +138,7 @@ tsch_security_secure_frame(uint8_t *hdr, uint8_t *outbuf,
uint8_t with_encryption;
uint8_t mic_len;
uint8_t nonce[16];
+ struct ieee802154_ies ies;
uint8_t a_len;
uint8_t m_len;
@@ -151,6 +152,13 @@ tsch_security_secure_frame(uint8_t *hdr, uint8_t *outbuf,
return 0;
}
+ memset(&ies, 0, sizeof(ies));
+ if(frame802154e_parse_information_elements(hdr + hdrlen, datalen, &ies) > 0) {
+ /* put Header IEs into the header part which is not encrypted */
+ hdrlen += ies.ie_payload_ie_offset;
+ datalen -= ies.ie_payload_ie_offset;
+ }
+
if(!frame.fcf.security_enabled) {
/* Security is not enabled for this frame, we're done */
return 0;
@@ -204,6 +212,7 @@ tsch_security_parse_frame(const uint8_t *hdr, int hdrlen, int datalen,
uint8_t nonce[16];
uint8_t a_len;
uint8_t m_len;
+ struct ieee802154_ies ies;
if(frame == NULL || hdr == NULL || hdrlen < 0 || datalen < 0) {
return 0;
@@ -229,6 +238,12 @@ tsch_security_parse_frame(const uint8_t *hdr, int hdrlen, int datalen,
return 0;
}
+ memset(&ies, 0, sizeof(ies));
+ (void)frame802154e_parse_information_elements(hdr + hdrlen, datalen, &ies);
+ /* put Header IEs into the header part which is not encrypted */
+ hdrlen += ies.ie_payload_ie_offset;
+ datalen -= ies.ie_payload_ie_offset;
+
tsch_security_init_nonce(nonce, sender, asn);
if(with_encryption) {
