Skip to content
Draft
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
39 changes: 9 additions & 30 deletions modules/openthread/platform/border_agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,11 @@ static struct otInstance *ot_instance_ptr;
static bool border_agent_is_init;

#if defined(CONFIG_OPENTHREAD_BORDER_AGENT_EPHEMERAL_KEY_ENABLE)
/* Byte values, 9 bytes for the key, one for null terminator. */
static uint8_t ephemeral_key_string[10];
static otBorderAgentEphemeralKeyTap eph_passcode;

static uint32_t ephemeral_key_timeout;
static bool epskc_active;

static otError generate_ephemeral_key(void);
static void handle_border_agent_ephemeral_key_callback(void *context);
static otError border_agent_enable_epskc_service(uint32_t timeout);

Expand Down Expand Up @@ -125,29 +123,6 @@ __weak void print_ephemeral_key_expired_message(void)
otCliOutputFormat("\r\nEphemeral Key disabled.\r\n");
}

static otError generate_ephemeral_key(void)
{
otError error = OT_ERROR_NONE;
uint8_t i = 0;
uint32_t random;
char verhoeff_checksum;

memset(ephemeral_key_string, 0, sizeof(ephemeral_key_string));

VerifyOrExit(otPlatEntropyGet((uint8_t *)&random, sizeof(random)) == OT_ERROR_NONE,
error = OT_ERROR_FAILED);
random %= 100000000;
i += snprintf((char *)ephemeral_key_string, sizeof(ephemeral_key_string),
"%08u", random);
VerifyOrExit(otVerhoeffChecksumCalculate((const char *)ephemeral_key_string,
&verhoeff_checksum) == OT_ERROR_NONE,
error = OT_ERROR_FAILED);
snprintf((char *)&ephemeral_key_string[i], sizeof(ephemeral_key_string) - i,
"%c", verhoeff_checksum);
exit:
return error;
}

static void handle_border_agent_ephemeral_key_callback(void *context)
{
char formatted_epskc[12] = {0};
Expand All @@ -165,8 +140,8 @@ static void handle_border_agent_ephemeral_key_callback(void *context)

case OT_BORDER_AGENT_STATE_STARTED:
snprintf(formatted_epskc, sizeof(formatted_epskc), "%.3s %.3s %.3s",
ephemeral_key_string, ephemeral_key_string + 3,
ephemeral_key_string + 6);
eph_passcode.mTap, eph_passcode.mTap + 3,
eph_passcode.mTap + 6);
print_ephemeral_key(formatted_epskc, (uint32_t)(ephemeral_key_timeout / 1000UL));
epskc_active = true;
break;
Expand All @@ -189,9 +164,13 @@ static otError border_agent_enable_epskc_service(uint32_t timeout)
timeout <= OT_BORDER_AGENT_MAX_EPHEMERAL_KEY_TIMEOUT) ?
timeout : OT_BORDER_AGENT_DEFAULT_EPHEMERAL_KEY_TIMEOUT;

VerifyOrExit((generate_ephemeral_key() == OT_ERROR_NONE), error = OT_ERROR_FAILED);
VerifyOrExit(otBorderAgentEphemeralKeyGenerateTap(&eph_passcode) == OT_ERROR_NONE,
error = OT_ERROR_FAILED);
VerifyOrExit(otBorderAgentEphemeralKeyValidateTap(&eph_passcode) == OT_ERROR_NONE,
error = OT_ERROR_FAILED);

error = otBorderAgentEphemeralKeyStart(ot_instance_ptr,
(const char *)ephemeral_key_string,
(const char *)eph_passcode.mTap,
ephemeral_key_timeout, 0);

exit:
Expand Down
3 changes: 1 addition & 2 deletions modules/openthread/platform/udp.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ otError otPlatUdpSend(otUdpSocket *aUdpSocket,
peer.sin6_port = net_htons(aMessageInfo->mPeerPort);
memcpy(&peer.sin6_addr, &aMessageInfo->mPeerAddr, sizeof(otIp6Address));

if ((aMessageInfo->mPeerAddr.mFields.m8[0] == 0xfe) &&
((aMessageInfo->mPeerAddr.mFields.m8[1] & 0xc0) == 0x80)) {
if (otIp6IsLinkLocalUnicast((const otIp6Address *)&aMessageInfo->mPeerAddr)) {
if (aMessageInfo->mIsHostInterface) {
peer.sin6_scope_id = ail_iface_index;
} else {
Expand Down
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ manifest:
revision: c30a6d8b92fcebdb797fc1a7698e8729e250f637
path: modules/lib/open-amp
- name: openthread
revision: 2bc7712f57af22058770d1ef131ad3da79a0c764
revision: pull/215/head
path: modules/lib/openthread
- name: percepio
path: modules/debug/percepio
Expand Down
Loading