drivers: ieee802154: cc13/26xx_subg: fix header len const

The length field in the header refers to the size of the MAC so it
shouldn't rely on constants describing PHY header length. While
currently both constants have the same value this will no longer be true
for enhanced PHYs and/or MAC frames as the number of FCS bytes may then
be four.

Also introduces an assertion that ensures that the given package buffer
does not exceed the TX buffer's length. An assertion is enough as the
package buffer is allocated at compile time.

Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
This commit is contained in:
Florian Grandel 2023-06-09 16:18:49 +02:00 committed by Carles Cufí
parent ea89a1f9b5
commit 122a10fdaa

View file

@ -542,11 +542,13 @@ static int ieee802154_cc13xx_cc26xx_subg_tx(const struct device *dev,
/* Prepend data with the SUN FSK PHY header, /* Prepend data with the SUN FSK PHY header,
* see IEEE 802.15.4, section 19.2.4. * see IEEE 802.15.4, section 19.2.4.
*/ */
drv_data->tx_data[0] = buf->len + IEEE802154_PHY_SUN_FSK_PHR_LEN; drv_data->tx_data[0] = buf->len + IEEE802154_FCS_LENGTH;
drv_data->tx_data[1] = 0; drv_data->tx_data[1] = 0;
drv_data->tx_data[1] |= BIT(3); /* FCS Type: 2-octet FCS */ drv_data->tx_data[1] |= BIT(3); /* FCS Type: 2-octet FCS */
drv_data->tx_data[1] |= BIT(4); /* DW: Enable Data Whitening */ drv_data->tx_data[1] |= BIT(4); /* DW: Enable Data Whitening */
/* TODO: Zero-copy TX, see discussion in #49775. */ /* TODO: Zero-copy TX, see discussion in #49775. */
__ASSERT_NO_MSG(buf->len + IEEE802154_PHY_SUN_FSK_PHR_LEN <= CC13XX_CC26XX_TX_BUF_SIZE);
memcpy(&drv_data->tx_data[IEEE802154_PHY_SUN_FSK_PHR_LEN], buf->data, buf->len); memcpy(&drv_data->tx_data[IEEE802154_PHY_SUN_FSK_PHR_LEN], buf->data, buf->len);
/* Set TX data */ /* Set TX data */