drivers: ieee802154: fix configuring CSL IE in ACK

The code was assigning a pointer to a scoped buffer to
an object outside that scope. This would cause the driver
would receive garbage instead of a well-formatted IE and
would likely reject the IE. This in turn caused CSL IE
not being included in enhanced ACKs (verified with
wireshark).

Signed-off-by: Damian Krolik <damian.krolik@nordicsemi.no>
This commit is contained in:
Damian Krolik 2024-03-29 09:55:37 +01:00 committed by Johan Hedberg
parent 1ceceabad5
commit 42d928ee93

View file

@ -1277,7 +1277,10 @@ void otPlatRadioSetMacFrameCounterIfLarger(otInstance *aInstance, uint32_t aMacF
otError otPlatRadioEnableCsl(otInstance *aInstance, uint32_t aCslPeriod, otShortAddress aShortAddr, otError otPlatRadioEnableCsl(otInstance *aInstance, uint32_t aCslPeriod, otShortAddress aShortAddr,
const otExtAddress *aExtAddr) const otExtAddress *aExtAddr)
{ {
struct ieee802154_config config = { 0 }; struct ieee802154_config config;
/* CSL phase will be injected on-the-fly by the driver. */
struct ieee802154_header_ie header_ie =
IEEE802154_DEFINE_HEADER_IE_CSL_REDUCED(/* phase */ 0, aCslPeriod);
int result; int result;
ARG_UNUSED(aInstance); ARG_UNUSED(aInstance);
@ -1290,26 +1293,12 @@ otError otPlatRadioEnableCsl(otInstance *aInstance, uint32_t aCslPeriod, otShort
if (result) { if (result) {
return OT_ERROR_FAILED; return OT_ERROR_FAILED;
} }
config.ack_ie.short_addr = aShortAddr;
config.ack_ie.ext_addr = aExtAddr != NULL ? aExtAddr->m8 : NULL;
/* Configure the CSL IE. */ /* Configure the CSL IE. */
if (aCslPeriod > 0) { config.ack_ie.header_ie = aCslPeriod > 0 ? &header_ie : NULL;
uint8_t header_ie_buf[OT_IE_HEADER_SIZE + OT_CSL_IE_SIZE] = { config.ack_ie.short_addr = aShortAddr;
CSL_IE_HEADER_BYTES_LO, config.ack_ie.ext_addr = aExtAddr != NULL ? aExtAddr->m8 : NULL;
CSL_IE_HEADER_BYTES_HI, config.ack_ie.purge_ie = false;
};
struct ieee802154_header_ie *header_ie =
(struct ieee802154_header_ie *)header_ie_buf;
/* Write CSL period and leave CSL phase empty as it will be
* injected on-the-fly by the driver.
*/
header_ie->content.csl.reduced.csl_period = sys_cpu_to_le16(aCslPeriod);
config.ack_ie.header_ie = header_ie;
} else {
config.ack_ie.header_ie = NULL;
}
result = radio_api->configure(radio_dev, IEEE802154_CONFIG_ENH_ACK_HEADER_IE, &config); result = radio_api->configure(radio_dev, IEEE802154_CONFIG_ENH_ACK_HEADER_IE, &config);