Set the Key Source field for 802.15.4 Key ID Mode 2. (#821)

This commit is contained in:
Jonathan Hui
2016-10-17 09:17:43 -07:00
committed by GitHub
parent aaf5a57ea2
commit 1a4e884e5a
4 changed files with 99 additions and 22 deletions
+4
View File
@@ -647,11 +647,15 @@ void Mac::ProcessTransmitSecurity(Frame &aFrame)
break;
case Frame::kKeyIdMode2:
{
const uint8_t keySource[] = {0xff, 0xff, 0xff, 0xff};
key = sMode2Key;
frameCounter = 0xffffffff;
aFrame.SetKeySource(keySource);
aFrame.SetKeyId(0xff);
extAddress = static_cast<const ExtAddress *>(&sMode2ExtAddress);
break;
}
default:
assert(false);
+71 -13
View File
@@ -111,25 +111,25 @@ ThreadError Frame::InitMacHeader(uint16_t aFcf, uint8_t aSecurityControl)
if (aSecurityControl & kSecLevelMask)
{
length += 5;
length += kSecurityControlSize + kFrameCounterSize;
}
switch (aSecurityControl & kKeyIdModeMask)
{
case kKeyIdMode0:
length += kKeyIdLengthMode0;
length += kKeySourceSizeMode0;
break;
case kKeyIdMode1:
length += kKeyIdLengthMode1;
length += kKeySourceSizeMode1 + kKeyIndexSize;
break;
case kKeyIdMode2:
length += kKeyIdLengthMode2;
length += kKeySourceSizeMode2 + kKeyIndexSize;
break;
case kKeyIdMode3:
length += kKeyIdLengthMode3;
length += kKeySourceSizeMode3 + kKeyIndexSize;
break;
}
}
@@ -606,15 +606,71 @@ ThreadError Frame::SetFrameCounter(uint32_t aFrameCounter)
return kThreadError_None;
}
const uint8_t *Frame::GetKeySource(void)
{
uint8_t *buf;
buf = FindSecurityHeader();
assert(buf != NULL);
// Security Control
buf += kSecurityControlSize + kFrameCounterSize;
return buf;
}
uint8_t Frame::GetKeySourceLength(uint8_t aKeyIdMode)
{
uint8_t rval = 0;
switch (aKeyIdMode)
{
case kKeyIdMode0:
rval = kKeySourceSizeMode0;
break;
case kKeyIdMode1:
rval = kKeySourceSizeMode1;
break;
case kKeyIdMode2:
rval = kKeySourceSizeMode2;
break;
case kKeyIdMode3:
rval = kKeySourceSizeMode3;
break;
}
return rval;
}
void Frame::SetKeySource(const uint8_t *aKeySource)
{
uint8_t keySourceLength;
uint8_t *buf;
buf = FindSecurityHeader();
assert(buf != NULL);
keySourceLength = GetKeySourceLength(buf[0] & kKeyIdModeMask);
buf += kSecurityControlSize + kFrameCounterSize;
memcpy(buf, aKeySource, keySourceLength);
}
ThreadError Frame::GetKeyId(uint8_t &aKeyId)
{
ThreadError error = kThreadError_None;
uint8_t keySourceLength;
uint8_t *buf;
VerifyOrExit((buf = FindSecurityHeader()) != NULL, error = kThreadError_Parse);
// Security Control + Frame Counter
buf += kSecurityControlSize + kFrameCounterSize;
keySourceLength = GetKeySourceLength(buf[0] & kKeyIdModeMask);
buf += kSecurityControlSize + kFrameCounterSize + keySourceLength;
aKeyId = buf[0];
@@ -624,13 +680,15 @@ exit:
ThreadError Frame::SetKeyId(uint8_t aKeyId)
{
uint8_t keySourceLength;
uint8_t *buf;
buf = FindSecurityHeader();
assert(buf != NULL);
// Security Control + Frame Counter
buf += kSecurityControlSize + kFrameCounterSize;
keySourceLength = GetKeySourceLength(buf[0] & kKeyIdModeMask);
buf += kSecurityControlSize + kFrameCounterSize + keySourceLength;
buf[0] = aKeyId;
@@ -805,19 +863,19 @@ uint8_t *Frame::GetPayload(void)
switch (securityControl & kKeyIdModeMask)
{
case kKeyIdMode0:
cur += kKeyIdLengthMode0;
cur += kKeySourceSizeMode0;
break;
case kKeyIdMode1:
cur += kKeyIdLengthMode1;
cur += kKeySourceSizeMode1 + kKeyIndexSize;
break;
case kKeyIdMode2:
cur += kKeyIdLengthMode2;
cur += kKeySourceSizeMode2 + kKeyIndexSize;
break;
case kKeyIdMode3:
cur += kKeyIdLengthMode3;
cur += kKeySourceSizeMode3 + kKeyIndexSize;
break;
}
}
+24 -8
View File
@@ -219,6 +219,13 @@ public:
kKeyIdMode3 = 3 << 3,
kKeyIdModeMask = 3 << 3,
kKeySourceSizeMode0 = 0,
kKeySourceSizeMode1 = 0,
kKeySourceSizeMode2 = 4,
kKeySourceSizeMode3 = 8,
kKeyIndexSize = sizeof(uint8_t),
kMacCmdAssociationRequest = 1,
kMacCmdAssociationResponse = 2,
kMacCmdDisassociationNotification = 3,
@@ -449,6 +456,22 @@ public:
*/
ThreadError SetFrameCounter(uint32_t aFrameCounter);
/**
* This method returns a pointer to the Key Source.
*
* @returns A pointer to the Key Source.
*
*/
const uint8_t *GetKeySource(void);
/**
* This method sets the Key Source.
*
* @param[in] aKeySource A pointer to the Key Source value.
*
*/
void SetKeySource(const uint8_t *aKeySource);
/**
* This method gets the Key Identifier.
*
@@ -663,20 +686,13 @@ public:
uint8_t *GetFooter(void);
private:
enum
{
kKeyIdLengthMode0 = 0, ///< Mode 0 Key ID Length in bytes (IEEE 802.15.4-2006)
kKeyIdLengthMode1 = 1, ///< Mode 1 Key ID Length in bytes (IEEE 802.15.4-2006)
kKeyIdLengthMode2 = 5, ///< Mode 2 Key ID Length in bytes (IEEE 802.15.4-2006)
kKeyIdLengthMode3 = 9, ///< Mode 3 Key ID Length in bytes (IEEE 802.15.4-2006)
};
uint8_t *FindSequence(void);
uint8_t *FindDstPanId(void);
uint8_t *FindDstAddr(void);
uint8_t *FindSrcPanId(void);
uint8_t *FindSrcAddr(void);
uint8_t *FindSecurityHeader(void);
static uint8_t GetKeySourceLength(uint8_t aKeyIdMode);
};
/**
-1
View File
@@ -1421,7 +1421,6 @@ ThreadError Mle::SendAnnounce(uint8_t aChannel)
PanIdTlv panid;
Ip6::Address destination;
Message *message;
(void)aChannel;
VerifyOrExit((message = mSocket.NewMessage(0)) != NULL, ;);
message->SetSubType(Message::kSubTypeMleAnnounce);