diff --git a/sys/include/net/netdev_test.h b/sys/include/net/netdev_test.h index 9ea4fb5b99..22723b3cc2 100644 --- a/sys/include/net/netdev_test.h +++ b/sys/include/net/netdev_test.h @@ -46,7 +46,7 @@ * ipv6_addr_t dst = IPV6_ADDR_UNSPECIFIED; * * netdev_test_setup(&dev, NULL); - * dev->driver->init((netdev_t *)&dev) + * dev->driver->init(&dev->netdev->netdev) * // initialize stack and connect `dev` to it * // ... * mutex_lock(&wait); @@ -80,10 +80,7 @@ #include "mutex.h" -#ifdef MODULE_NETDEV_IEEE802154 #include "net/netdev/ieee802154.h" -#endif - #include "net/netdev.h" #ifdef __cplusplus diff --git a/sys/net/netdev_test/netdev_test.c b/sys/net/netdev_test/netdev_test.c index 69883c1be2..0256a9e890 100644 --- a/sys/net/netdev_test/netdev_test.c +++ b/sys/net/netdev_test/netdev_test.c @@ -33,7 +33,8 @@ void netdev_test_reset(netdev_test_t *dev) static int _send(netdev_t *netdev, const iolist_t *iolist) { - netdev_test_t *dev = (netdev_test_t *)netdev; + netdev_test_t *dev = container_of(container_of(netdev, netdev_ieee802154_t, netdev), + netdev_test_t, netdev); int res = -EINVAL; mutex_lock(&dev->mutex); @@ -46,7 +47,8 @@ static int _send(netdev_t *netdev, const iolist_t *iolist) static int _recv(netdev_t *netdev, void *buf, size_t len, void *info) { - netdev_test_t *dev = (netdev_test_t *)netdev; + netdev_test_t *dev = container_of(container_of(netdev, netdev_ieee802154_t, netdev), + netdev_test_t, netdev); int res = (buf == NULL) ? 0 : len; /* assume everything would be fine */ mutex_lock(&dev->mutex); @@ -63,7 +65,8 @@ static int _recv(netdev_t *netdev, void *buf, size_t len, void *info) static int _init(netdev_t *netdev) { - netdev_test_t *dev = (netdev_test_t *)netdev; + netdev_test_t *dev = container_of(container_of(netdev, netdev_ieee802154_t, netdev), + netdev_test_t, netdev); int res = 0; /* assume everything would be fine */ mutex_lock(&dev->mutex); @@ -76,7 +79,8 @@ static int _init(netdev_t *netdev) static void _isr(netdev_t *netdev) { - netdev_test_t *dev = (netdev_test_t *)netdev; + netdev_test_t *dev = container_of(container_of(netdev, netdev_ieee802154_t, netdev), + netdev_test_t, netdev); mutex_lock(&dev->mutex); if (dev->isr_cb != NULL) { @@ -90,7 +94,8 @@ static void _isr(netdev_t *netdev) static int _get(netdev_t *netdev, netopt_t opt, void *value, size_t max_len) { - netdev_test_t *dev = (netdev_test_t *)netdev; + netdev_test_t *dev = container_of(container_of(netdev, netdev_ieee802154_t, netdev), + netdev_test_t, netdev); int res = -ENOTSUP; /* option assumed to be not supported */ mutex_lock(&dev->mutex); @@ -103,7 +108,8 @@ static int _get(netdev_t *netdev, netopt_t opt, void *value, size_t max_len) static int _set(netdev_t *netdev, netopt_t opt, const void *value, size_t value_len) { - netdev_test_t *dev = (netdev_test_t *)netdev; + netdev_test_t *dev = container_of(container_of(netdev, netdev_ieee802154_t, netdev), + netdev_test_t, netdev); int res = -ENOTSUP; /* option assumed to be not supported */ mutex_lock(&dev->mutex); @@ -125,9 +131,7 @@ static const netdev_driver_t _driver = { void netdev_test_setup(netdev_test_t *dev, void *state) { - netdev_t *netdev = (netdev_t *)dev; - - netdev->driver = &_driver; + dev->netdev.netdev.driver = &_driver; dev->state = state; mutex_init(&dev->mutex); netdev_test_reset(dev); diff --git a/tests/netdev_test/main.c b/tests/netdev_test/main.c index e0c231e390..9efeb7b2ae 100644 --- a/tests/netdev_test/main.c +++ b/tests/netdev_test/main.c @@ -138,7 +138,7 @@ static int test_receive(void) thread_getpid()); msg_t msg; - if (_dev.netdev.event_callback == NULL) { + if (_dev.netdev.netdev.event_callback == NULL) { puts("Device's event_callback not set"); return 0; } @@ -154,7 +154,7 @@ static int test_receive(void) /* register for GNRC_NETTYPE_UNDEF */ gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &me); /* fire ISR event */ - netdev_trigger_event_isr((netdev_t *)&_dev.netdev); + netdev_trigger_event_isr(&_dev.netdev.netdev); /* wait for packet from MAC layer*/ msg_receive(&msg); /* check message */ @@ -261,7 +261,7 @@ int main(void) netdev_test_set_get_cb(&_dev, NETOPT_ADDRESS, _dev_get_addr); netdev_test_set_set_cb(&_dev, NETOPT_ADDRESS, _dev_set_addr); gnrc_netif_ethernet_create(&_netif, _mac_stack, _MAC_STACKSIZE, _MAC_PRIO, - "netdev_test", (netdev_t *)&_dev); + "netdev_test", &_dev.netdev.netdev); _mac_pid = _netif.pid; /* test execution */