Skip to content

Commit

Permalink
fixup! netdev/ieee802154_submac: add compatibility layer
Browse files Browse the repository at this point in the history
  • Loading branch information
jia200x committed Sep 8, 2020
1 parent 837f945 commit 0ad1e04
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions drivers/netdev_ieee802154_submac/netdev_ieee802154_submac.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,59 @@ static void _ack_timeout(void *arg)
netdev->event_callback(netdev, NETDEV_EVENT_ISR);
}

static netopt_state_t _get_submac_state(ieee802154_submac_t *submac)
{
ieee802154_submac_state_t state = ieee802154_get_state(submac);

netopt_state_t netopt_state;
switch (state) {
case IEEE802154_STATE_OFF:
netopt_state = NETOPT_STATE_SLEEP;
break;
case IEEE802154_STATE_IDLE:
netopt_state = NETOPT_STATE_STANDBY;
break;
case IEEE802154_STATE_LISTEN:
default:
netopt_state = NETOPT_STATE_IDLE;
break;
}

return netopt_state;
}

static int _get(netdev_t *netdev, netopt_t opt, void *value, size_t max_len)
{
netdev_ieee802154_submac_t *netdev_submac =
(netdev_ieee802154_submac_t *)netdev;
ieee802154_submac_t *submac = &netdev_submac->submac;

switch (opt) {
case NETOPT_STATE:
*((netopt_state_t*) value) = _get_submac_state(submac);
return 0;
default:
break;
}

return netdev_ieee802154_get((netdev_ieee802154_t *)netdev, opt,
value, max_len);
}

static int _set_submac_state(ieee802154_submac_t *submac, netopt_state_t state)
{
switch (state) {
case NETOPT_STATE_STANDBY:
return ieee802154_set_state(submac, IEEE802154_STATE_IDLE);
case NETOPT_STATE_SLEEP:
return ieee802154_set_state(submac, IEEE802154_STATE_OFF);
case NETOPT_STATE_IDLE:
return ieee802154_set_state(submac, IEEE802154_STATE_LISTEN);
default:
return -ENOTSUP;
}
}

static int _set(netdev_t *netdev, netopt_t opt, const void *value,
size_t value_len)
{
Expand Down Expand Up @@ -52,6 +99,8 @@ static int _set(netdev_t *netdev, netopt_t opt, const void *value,
netdev_submac->dev.txpower = tx_power;
}
return res;
case NETOPT_STATE:
return _set_submac_state(submac, *((netopt_state_t*) value));
default:
break;
}
Expand Down

0 comments on commit 0ad1e04

Please sign in to comment.