Skip to content

Commit a47677d

Browse files
edmontcarlescufi
authored andcommitted
net: openthread: add CSL transmitter API
This commit implements the OpenThread APIs to pass MAC keys and frame counter to the radio layer in order to process the transmission security. This is needed for the correct functioning of a CSL transmitter. Signed-off-by: Eduardo Montoya <[email protected]>
1 parent a4d2e06 commit a47677d

File tree

5 files changed

+181
-3
lines changed

5 files changed

+181
-3
lines changed

drivers/ieee802154/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ endif # IEEE802154_UPIPE_RANDOM_MAC
130130

131131
endif # IEEE802154_UPIPE
132132

133+
config IEEE802154_2015
134+
bool "Enable support for IEEE 802.15.4-2015 frames"
135+
help
136+
Enable radio driver support for IEEE 802.15.4-2015 frames, including security handling of frames and ACKs.
137+
133138
module = IEEE802154_DRIVER
134139
module-str = IEEE 802.15.4 driver
135140
module-help = Sets log level for IEEE 802.15.4 Device Drivers.

include/net/ieee802154_radio.h

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ enum ieee802154_hw_caps {
5555
IEEE802154_HW_ENERGY_SCAN = BIT(7), /* Energy scan supported */
5656
IEEE802154_HW_TXTIME = BIT(8), /* TX at specified time supported */
5757
IEEE802154_HW_SLEEP_TO_TX = BIT(9), /* TX directly from sleep supported */
58+
IEEE802154_HW_TX_SEC = BIT(10), /* TX security hadling supported */
5859
};
5960

6061
enum ieee802154_filter_type {
@@ -150,7 +151,13 @@ enum ieee802154_config_type {
150151
/** Specifies new radio event handler. Specifying NULL as a handler
151152
* will disable radio events notification.
152153
*/
153-
IEEE802154_CONFIG_EVENT_HANDLER
154+
IEEE802154_CONFIG_EVENT_HANDLER,
155+
156+
/** Updates MAC keys and key index for radios supporting transmit security. */
157+
IEEE802154_CONFIG_MAC_KEYS,
158+
159+
/** Sets the current MAC frame counter value for radios supporting transmit security. */
160+
IEEE802154_CONFIG_FRAME_COUNTER,
154161
};
155162

156163
/** IEEE802.15.4 driver configuration data. */
@@ -178,6 +185,18 @@ struct ieee802154_config {
178185

179186
/** ``IEEE802154_CONFIG_EVENT_HANDLER`` */
180187
ieee802154_event_cb_t event_handler;
188+
189+
/** ``IEEE802154_CONFIG_MAC_KEYS`` */
190+
struct {
191+
uint8_t key_id_mode;
192+
uint8_t key_id;
193+
uint8_t *prev_key;
194+
uint8_t *curr_key;
195+
uint8_t *next_key;
196+
} mac_keys;
197+
198+
/** ``IEEE802154_CONFIG_FRAME_COUNTER`` */
199+
uint32_t frame_counter;
181200
};
182201
};
183202

include/net/net_pkt.h

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,14 @@ struct net_pkt {
244244
#if defined(CONFIG_IEEE802154)
245245
uint8_t ieee802154_rssi; /* Received Signal Strength Indication */
246246
uint8_t ieee802154_lqi; /* Link Quality Indicator */
247+
uint8_t ieee802154_arb : 1; /* ACK Request Bit is set in the frame */
247248
uint8_t ieee802154_ack_fpb : 1; /* Frame Pending Bit was set in the ACK */
249+
#if defined(CONFIG_IEEE802154_2015)
250+
uint8_t ieee802154_fv2015 : 1; /* Frame version is IEEE 802.15.4-2015 */
251+
uint8_t ieee802154_ack_seb : 1; /* Security Enabled Bit was set in the ACK */
252+
uint32_t ieee802154_ack_fc; /* Frame counter set in the ACK */
253+
uint8_t ieee802154_ack_keyid; /* Key index set in the ACK */
254+
#endif
248255
#endif
249256
#if defined(CONFIG_NET_L2_CANBUS)
250257
union {
@@ -991,6 +998,16 @@ static inline void net_pkt_set_ieee802154_lqi(struct net_pkt *pkt,
991998
pkt->ieee802154_lqi = lqi;
992999
}
9931000

1001+
static inline bool net_pkt_ieee802154_arb(struct net_pkt *pkt)
1002+
{
1003+
return pkt->ieee802154_arb;
1004+
}
1005+
1006+
static inline void net_pkt_set_ieee802154_arb(struct net_pkt *pkt, bool arb)
1007+
{
1008+
pkt->ieee802154_arb = arb;
1009+
}
1010+
9941011
static inline bool net_pkt_ieee802154_ack_fpb(struct net_pkt *pkt)
9951012
{
9961013
return pkt->ieee802154_ack_fpb;
@@ -1001,7 +1018,51 @@ static inline void net_pkt_set_ieee802154_ack_fpb(struct net_pkt *pkt,
10011018
{
10021019
pkt->ieee802154_ack_fpb = fpb;
10031020
}
1004-
#endif
1021+
1022+
#if defined(CONFIG_IEEE802154_2015)
1023+
static inline bool net_pkt_ieee802154_fv2015(struct net_pkt *pkt)
1024+
{
1025+
return pkt->ieee802154_fv2015;
1026+
}
1027+
1028+
static inline void net_pkt_set_ieee802154_fv2015(struct net_pkt *pkt, bool fv2015)
1029+
{
1030+
pkt->ieee802154_fv2015 = fv2015;
1031+
}
1032+
1033+
static inline bool net_pkt_ieee802154_ack_seb(struct net_pkt *pkt)
1034+
{
1035+
return pkt->ieee802154_ack_seb;
1036+
}
1037+
1038+
static inline void net_pkt_set_ieee802154_ack_seb(struct net_pkt *pkt, bool seb)
1039+
{
1040+
pkt->ieee802154_ack_seb = seb;
1041+
}
1042+
1043+
static inline uint32_t net_pkt_ieee802154_ack_fc(struct net_pkt *pkt)
1044+
{
1045+
return pkt->ieee802154_ack_fc;
1046+
}
1047+
1048+
static inline void net_pkt_set_ieee802154_ack_fc(struct net_pkt *pkt,
1049+
uint32_t fc)
1050+
{
1051+
pkt->ieee802154_ack_fc = fc;
1052+
}
1053+
1054+
static inline uint8_t net_pkt_ieee802154_ack_keyid(struct net_pkt *pkt)
1055+
{
1056+
return pkt->ieee802154_ack_keyid;
1057+
}
1058+
1059+
static inline void net_pkt_set_ieee802154_ack_keyid(struct net_pkt *pkt,
1060+
uint8_t keyid)
1061+
{
1062+
pkt->ieee802154_ack_keyid = keyid;
1063+
}
1064+
#endif /* CONFIG_IEEE802154_2015 */
1065+
#endif /* CONFIG_IEEE802154 || CONFIG_IEEE802154_RAW_MODE */
10051066

10061067
#if defined(CONFIG_NET_IPV4_AUTO)
10071068
static inline bool net_pkt_ipv4_auto(struct net_pkt *pkt)

subsys/net/lib/openthread/platform/openthread-core-zephyr-config.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,37 @@
9191
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE 1
9292
#endif
9393

94+
/**
95+
* @def OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE
96+
*
97+
* Define to 1 to enable software transmission target time logic.
98+
*
99+
*/
100+
#ifndef OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE
101+
#define OPENTHREAD_CONFIG_MAC_SOFTWARE_TX_TIMING_ENABLE \
102+
(OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
103+
#endif
104+
105+
/**
106+
* @def OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
107+
*
108+
* Define as 1 to support IEEE 802.15.4-2015 Header IE (Information Element) generation and parsing,
109+
* it must be set to support following features:
110+
* 1. Time synchronization service feature (i.e., OPENTHREAD_CONFIG_TIME_SYNC_ENABLE is set).
111+
* 2. Thread 1.2.
112+
*
113+
* @note If it's enabled, platform must support interrupt context and concurrent access AES.
114+
*
115+
*/
116+
#ifndef OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT
117+
#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE || \
118+
(OPENTHREAD_CONFIG_THREAD_VERSION >= OT_THREAD_VERSION_1_2)
119+
#define OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT 1
120+
#else
121+
#define OPENTHREAD_CONFIG_MAC_HEADER_IE_SUPPORT 0
122+
#endif
123+
#endif
124+
94125
/**
95126
* @def OPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE
96127
*

subsys/net/lib/openthread/platform/radio.c

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, CONFIG_OPENTHREAD_L2_LOG_LEVEL);
3939
#define SHORT_ADDRESS_SIZE 2
4040

4141
#define FCS_SIZE 2
42+
#if defined(CONFIG_IEEE802154_2015)
43+
#define ACK_PKT_LENGTH 127
44+
#else
4245
#define ACK_PKT_LENGTH 3
46+
#endif
4347

4448
#define FRAME_TYPE_MASK 0x07
4549
#define FRAME_TYPE_ACK 0x02
@@ -131,7 +135,7 @@ enum net_verdict ieee802154_radio_handle_ack(struct net_if *iface,
131135

132136
size_t ack_len = net_pkt_get_len(pkt);
133137

134-
if (ack_len != ACK_PKT_LENGTH) {
138+
if (ack_len > ACK_PKT_LENGTH) {
135139
return NET_CONTINUE;
136140
}
137141

@@ -328,6 +332,17 @@ static void openthread_handle_received_frame(otInstance *instance,
328332
time->second * USEC_PER_SEC + time->nanosecond / NSEC_PER_USEC;
329333
#endif
330334

335+
#if defined(CONFIG_IEEE802154_2015)
336+
if (net_pkt_ieee802154_arb(pkt) && net_pkt_ieee802154_fv2015(pkt)) {
337+
recv_frame.mInfo.mRxInfo.mAckedWithSecEnhAck =
338+
net_pkt_ieee802154_ack_seb(pkt);
339+
recv_frame.mInfo.mRxInfo.mAckFrameCounter =
340+
net_pkt_ieee802154_ack_fc(pkt);
341+
recv_frame.mInfo.mRxInfo.mAckKeyId =
342+
net_pkt_ieee802154_ack_keyid(pkt);
343+
}
344+
#endif
345+
331346
if (IS_ENABLED(CONFIG_OPENTHREAD_DIAG) && otPlatDiagModeGet()) {
332347
otPlatDiagRadioReceiveDone(instance, &recv_frame, OT_ERROR_NONE);
333348
} else {
@@ -663,6 +678,18 @@ otRadioCaps otPlatRadioGetCaps(otInstance *aInstance)
663678
caps |= OT_RADIO_CAPS_SLEEP_TO_TX;
664679
}
665680

681+
#if defined(CONFIG_IEEE802154_2015)
682+
if (radio_caps & IEEE802154_HW_TX_SEC) {
683+
caps |= OT_RADIO_CAPS_TRANSMIT_SEC;
684+
}
685+
#endif
686+
687+
#if defined(CONFIG_NET_PKT_TXTIME)
688+
if (radio_caps & IEEE802154_HW_TXTIME) {
689+
caps |= OT_RADIO_CAPS_TRANSMIT_TIMING;
690+
}
691+
#endif
692+
666693
return caps;
667694
}
668695

@@ -888,9 +915,44 @@ otError otPlatRadioSetTransmitPower(otInstance *aInstance, int8_t aPower)
888915
return OT_ERROR_NONE;
889916
}
890917

918+
#if defined(CONFIG_NET_PKT_TXTIME)
891919
uint64_t otPlatRadioGetNow(otInstance *aInstance)
892920
{
893921
ARG_UNUSED(aInstance);
894922

895923
return radio_api->get_time(radio_dev);
896924
}
925+
#endif
926+
927+
#if defined(CONFIG_IEEE802154_2015)
928+
void otPlatRadioSetMacKey(otInstance *aInstance, uint8_t aKeyIdMode,
929+
uint8_t aKeyId, const otMacKey *aPrevKey,
930+
const otMacKey *aCurrKey, const otMacKey *aNextKey)
931+
{
932+
ARG_UNUSED(aInstance);
933+
__ASSERT_NO_MSG(aPrevKey != NULL && aCurrKey != NULL &&
934+
aNextKey != NULL);
935+
936+
struct ieee802154_config config = {
937+
.mac_keys.key_id_mode = aKeyIdMode,
938+
.mac_keys.key_id = aKeyId,
939+
.mac_keys.prev_key = (uint8_t *)aPrevKey->m8,
940+
.mac_keys.curr_key = (uint8_t *)aCurrKey->m8,
941+
.mac_keys.next_key = (uint8_t *)aNextKey->m8,
942+
};
943+
944+
(void)radio_api->configure(radio_dev, IEEE802154_CONFIG_MAC_KEYS,
945+
&config);
946+
}
947+
948+
void otPlatRadioSetMacFrameCounter(otInstance *aInstance,
949+
uint32_t aMacFrameCounter)
950+
{
951+
ARG_UNUSED(aInstance);
952+
953+
struct ieee802154_config config = { .frame_counter = aMacFrameCounter };
954+
955+
(void)radio_api->configure(radio_dev, IEEE802154_CONFIG_FRAME_COUNTER,
956+
&config);
957+
}
958+
#endif

0 commit comments

Comments
 (0)