1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

link_layer/gomach: avoid explicit cast to netdev

This commit is contained in:
Jose Alamos 2021-06-22 11:02:34 +02:00
parent eebf5de051
commit 5de141227b
No known key found for this signature in database
GPG Key ID: F483EB800EF89DD9
2 changed files with 26 additions and 14 deletions

View File

@ -81,7 +81,7 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif)
{
netdev_t *dev = netif->dev;
netdev_ieee802154_rx_info_t rx_info;
netdev_ieee802154_t *state = (netdev_ieee802154_t *)netif->dev;
netdev_ieee802154_t *state = container_of(dev, netdev_ieee802154_t, netdev);
gnrc_pktsnip_t *pkt = NULL;
int bytes_expected = dev->driver->recv(dev, NULL, 0, NULL);
@ -538,7 +538,8 @@ static void gomach_t2k_trans_in_cp(gnrc_netif_t *netif)
/* If we are retransmitting the packet, use the same sequence number for the
* packet to avoid duplicate packet reception at the receiver side. */
if ((netif->mac.tx.no_ack_counter > 0) || (netif->mac.tx.tx_busy_count > 0)) {
netdev_ieee802154_t *device_state = (netdev_ieee802154_t *)netif->dev;
netdev_t *netdev = netif->dev;
netdev_ieee802154_t *device_state = container_of(netdev, netdev_ieee802154_t, netdev);
device_state->seq = netif->mac.tx.tx_seq;
}
@ -627,7 +628,8 @@ static bool _cp_tx_busy(gnrc_netif_t *netif)
/* Store the TX sequence number for this packet. Always use the same
* sequence number for sending the same packet, to avoid duplicated
* packet reception at the receiver. */
netdev_ieee802154_t *device_state = (netdev_ieee802154_t *)netif->dev;
netdev_t *netdev = netif->dev;
netdev_ieee802154_t *device_state = container_of(netdev, netdev_ieee802154_t, netdev);
netif->mac.tx.tx_seq = device_state->seq - 1;
netif->mac.tx.t2k_state = GNRC_GOMACH_T2K_TRANS_IN_CP;
@ -645,7 +647,8 @@ static void _cp_tx_default(gnrc_netif_t *netif)
/* This packet will be retried. Store the TX sequence number for this packet.
* Always use the same sequence number for sending the same packet. */
netdev_ieee802154_t *device_state = (netdev_ieee802154_t *)netif->dev;
netdev_t *netdev = netif->dev;
netdev_ieee802154_t *device_state = container_of(netdev, netdev_ieee802154_t, netdev);
netif->mac.tx.tx_seq = device_state->seq - 1;
/* If no_ack_counter reaches the threshold, regarded as phase-lock failed. So
@ -668,7 +671,8 @@ static void gomach_t2k_wait_cp_txfeedback(gnrc_netif_t *netif)
/* No TX-ISR, go to sleep. */
netif->mac.tx.no_ack_counter++;
netdev_ieee802154_t *device_state = (netdev_ieee802154_t *)netif->dev;
netdev_t *netdev = netif->dev;
netdev_ieee802154_t *device_state = container_of(netdev, netdev_ieee802154_t, netdev);
netif->mac.tx.tx_seq = device_state->seq - 1;
/* Here, we don't queue the packet again, but keep it in tx.packet. */
@ -798,7 +802,8 @@ static void gomach_t2k_trans_in_slots(gnrc_netif_t *netif)
{
/* If this packet is being retransmitted, use the same recorded MAC sequence number. */
if (netif->mac.tx.no_ack_counter > 0) {
netdev_ieee802154_t *device_state = (netdev_ieee802154_t *)netif->dev;
netdev_t *netdev = netif->dev;
netdev_ieee802154_t *device_state = container_of(netdev, netdev_ieee802154_t, netdev);
device_state->seq = netif->mac.tx.tx_seq;
}
@ -866,7 +871,8 @@ static void _t2k_wait_vtdma_tx_default(gnrc_netif_t *netif)
* the following cycle. */
netif->mac.tx.no_ack_counter = 1;
netdev_ieee802154_t *device_state = (netdev_ieee802154_t *)netif->dev;
netdev_t *netdev = netif->dev;
netdev_ieee802154_t *device_state = container_of(netdev, netdev_ieee802154_t, netdev);
netif->mac.tx.tx_seq = device_state->seq - 1;
/* Do not release the packet here, continue sending the same packet. ***/
@ -890,7 +896,8 @@ static void gomach_t2k_wait_vtdma_transfeedback(gnrc_netif_t *netif)
/* No TX-ISR, go to sleep. */
netif->mac.tx.no_ack_counter++;
netdev_ieee802154_t *device_state = (netdev_ieee802154_t *)netif->dev;
netdev_t *netdev = netif->dev;
netdev_ieee802154_t *device_state = container_of(netdev, netdev_ieee802154_t, netdev);
netif->mac.tx.tx_seq = device_state->seq - 1;
/* Here, we don't queue the packet again, but keep it in tx.packet. */
@ -1251,7 +1258,8 @@ static void gomach_t2u_send_data(gnrc_netif_t *netif)
{
/* If we are retrying to send the data, reload its original MAC sequence. */
if (netif->mac.tx.no_ack_counter > 0) {
netdev_ieee802154_t *device_state = (netdev_ieee802154_t *)netif->dev;
netdev_t *netdev = netif->dev;
netdev_ieee802154_t *device_state = container_of(netdev, netdev_ieee802154_t, netdev);
device_state->seq = netif->mac.tx.tx_seq;
}
@ -1326,7 +1334,8 @@ static void _t2u_data_tx_fail(gnrc_netif_t *netif)
else {
/* Record the MAC sequence of the data, retry t2u in next cycle. */
netif->mac.tx.no_ack_counter = CONFIG_GNRC_GOMACH_REPHASELOCK_THRESHOLD;
netdev_ieee802154_t *device_state = (netdev_ieee802154_t *)netif->dev;
netdev_t *netdev = netif->dev;
netdev_ieee802154_t *device_state = container_of(netdev, netdev_ieee802154_t, netdev);
netif->mac.tx.tx_seq = device_state->seq - 1;
LOG_DEBUG("[GOMACH] t2u send data failed on channel %d.\n",
@ -1345,7 +1354,8 @@ static void gomach_t2u_wait_tx_feedback(gnrc_netif_t *netif)
netif->mac.tx.t2u_retry_counter++;
netif->mac.tx.no_ack_counter = CONFIG_GNRC_GOMACH_REPHASELOCK_THRESHOLD;
netdev_ieee802154_t *device_state = (netdev_ieee802154_t *)netif->dev;
netdev_t *netdev = netif->dev;
netdev_ieee802154_t *device_state = container_of(netdev, netdev_ieee802154_t, netdev);
netif->mac.tx.tx_seq = device_state->seq - 1;
gnrc_gomach_set_quit_cycle(netif, true);
@ -2174,7 +2184,8 @@ static void _gomach_init(gnrc_netif_t *netif)
netif->mac.rx.check_dup_pkt.queue_head = 0;
netif->mac.tx.last_tx_neighbor_id = 0;
netdev_ieee802154_t *device_state = (netdev_ieee802154_t *)netif->dev;
netdev_t *netdev = netif->dev;
netdev_ieee802154_t *device_state = container_of(netdev, netdev_ieee802154_t, netdev);
device_state->seq = netif->l2addr[netif->l2addr_len - 1];
/* Initialize GoMacH's duplicate-check scheme. */

View File

@ -49,7 +49,7 @@
int _gnrc_gomach_transmit(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt)
{
netdev_t *dev = netif->dev;
netdev_ieee802154_t *state = (netdev_ieee802154_t *)netif->dev;
netdev_ieee802154_t *state = container_of(dev, netdev_ieee802154_t, netdev);
gnrc_netif_hdr_t *netif_hdr;
const uint8_t *src, *dst = NULL;
int res = 0;
@ -159,7 +159,8 @@ static int _parse_packet(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt,
assert(info != NULL);
assert(pkt != NULL);
netdev_ieee802154_t *state = (netdev_ieee802154_t *)netif->dev;
netdev_t *dev = netif->dev;
netdev_ieee802154_t *state = container_of(dev, netdev_ieee802154_t, netdev);
/* Get the packet sequence number */
info->seq = ieee802154_get_seq(pkt->next->data);