ieee802.15.4 netdev: Add IOCTL support.

This commit is contained in:
Gregory Nutt 2017-04-13 10:18:57 -06:00
parent 63b24bc686
commit fae1df31dc
2 changed files with 74 additions and 0 deletions

View File

@ -959,6 +959,11 @@ struct ieee802154_macops_s
CODE int (*rsp_orphan)(FAR struct ieee802154_mac_s *mac, CODE int (*rsp_orphan)(FAR struct ieee802154_mac_s *mac,
FAR uint8_t *orphanaddr, uint16_t saddr, FAR uint8_t *orphanaddr, uint16_t saddr,
bool associated); bool associated);
/* IOCTL support */
CODE int (*ioctl)(FAR struct ieee802154_mac_s *mac, int cmd,
unsigned long arg);
}; };
/* Notifications */ /* Notifications */

View File

@ -235,6 +235,9 @@ static int mac802154_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac
static void mac802154_ipv6multicast(FAR struct mac802154_driver_s *priv); static void mac802154_ipv6multicast(FAR struct mac802154_driver_s *priv);
#endif #endif
#endif #endif
#ifdef CONFIG_NETDEV_IOCTL
static int mac802154_ioctl(FAR struct net_driver_s *dev, int cmd, long arg);
#endif
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
@ -1344,6 +1347,69 @@ static void mac802154_ipv6multicast(FAR struct mac802154_driver_s *priv)
} }
#endif /* CONFIG_NET_ICMPv6 */ #endif /* CONFIG_NET_ICMPv6 */
/****************************************************************************
* Name: mac802154_ioctl
*
* Description:
* Handle network IOCTL commands directed to this device.
*
* Parameters:
* dev - Reference to the NuttX driver state structure
* cmd - The IOCTL command
* arg - The argument for the IOCTL command
*
* Returned Value:
* OK on success; Negated errno on failure.
*
* Assumptions:
*
****************************************************************************/
#ifdef CONFIG_NETDEV_IOCTL
static int mac802154_ioctl(FAR struct net_driver_s *dev, int cmd, long arg)
{
FAR struct mac802154_driver_s *priv = (FAR struct mac802154_driver_s *)dev->d_private;
int ret = -EINVAL;
/* Check for IOCTLs aimed at the IEEE802.15.4 MAC layer */
if (_MAC802154IOCVALID(cmd))
{
FAR struct ieee802154_netmac_s *netmac =
(FAR struct ieee802154_netmac_s *)arg;
if (netmac != NULL)
{
unsigned long macarg = (unsigned int)((uintptr_t)&netmac->u);
ret = priv->m8_mac.macops.ioctl(priv->m8_mac, cmd, macarg);
}
}
/* No, check for IOCTLs aimed at the IEEE802.15.4 radio layer */
else if (_PHY802154IOCVALID(cmd))
{
FAR struct ieee802154_netradio_s *netradio =
(FAR struct ieee802154_netradio_s *)arg;
if (netradio != NULL)
{
unsigned long radioarg = (unsigned int)((uintptr_t)&netradio->u);
ret = priv->m8_mac.macops.ioctl(priv->m8_mac, cmd, radioarg);
}
}
/* Okay, we have no idea what this command is.. just give to the
* IEEE802.15.4 MAC layer without modification.
*/
else
{
ret = priv->m8_mac.macops.ioctl(priv->m8_mac, cmd, arg);
}
}
#endif
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
@ -1406,6 +1472,9 @@ int mac802154netdev_register(FAR struct ieee802154_mac_s *mac);
#ifdef CONFIG_NET_IGMP #ifdef CONFIG_NET_IGMP
dev->d_addmac = mac802154_addmac; /* Add multicast MAC address */ dev->d_addmac = mac802154_addmac; /* Add multicast MAC address */
dev->d_rmmac = mac802154_rmmac; /* Remove multicast MAC address */ dev->d_rmmac = mac802154_rmmac; /* Remove multicast MAC address */
#endif
#ifdef CONFIG_NETDEV_IOCTL
dev->d_ioctl = mac802154_ioctl; /* Handle network IOCTL commands */
#endif #endif
dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */ dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */