Ieee802.15.4 MAC network driver. A little more logic (but still only partial). Add interface definitions to header file.

This commit is contained in:
Gregory Nutt 2017-04-08 19:11:57 -06:00
parent 11bd9afe53
commit 51cd421ce7
4 changed files with 86 additions and 45 deletions

View File

@ -264,20 +264,33 @@ static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv)
wlerr("ERROR: Failed to initialize IEEE802.15.4 MAC\n");
return -ENODEV;
}
#endif
#if defined(CONFIG_IEEE802154_MAC_DEV)
/* If want to call these APIs from userspace, you have to wrap your mac
* in a character device via mac802154_device.c.
#if defined(CONFIG_IEEE802154_NETDEV)
/* Use the IEEE802.15.4 MAC interface instance to create a 6loWPAN
* network interface by wrapping the MAC intrface instance in a
* network device driver via mac802154dev_register().
*/
ret = mac802154netdev_register(mac);
if (ret < 0)
{
wlerr("ERROR: Failed to register the MAC network driver wpan%d: %d\n",
0, ret);
return ret;
}
#elif defined(CONFIG_IEEE802154_MAC_DEV)
/* If want to call these APIs from userspace, you have to wrap the MAC
* interface in a character device viamac802154dev_register().
*/
ret = mac802154dev_register(mac, 0);
if (ret < 0)
{
wlerr("ERROR: Failed to register the MAC character driver ieee%d: %d\n",
wlerr("ERROR: Failed to register the MAC character driver /dev/ieee%d: %d\n",
0, ret);
return ret;
}
#endif
#elif defined(CONFIG_IEEE802154_DEV)
/* Register a character driver to access the IEEE 802.15.4 radio from
* user-space
@ -290,7 +303,7 @@ static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv)
RADIO_DEVNAME, ret);
return ret;
}
#endif
#endif /* CONFIG_IEEE802154_MAC */
return OK;
}

View File

@ -918,11 +918,11 @@ struct ieee802154_maccb_s
CODE void (*ind_syncloss)(FAR struct ieee802154_mac_s *mac, int reason);
};
struct ieee802154_radio_s; /* Forware reference */
struct ieee802154_radio_s; /* Forward reference */
struct ieee802154_mac_s
{
struct ieee802154_radio_s *radio;
FAR struct ieee802154_radio_s *radio;
struct ieee802154_macops_s ops;
struct ieee802154_maccb_s cbs;
};
@ -947,9 +947,9 @@ extern "C"
*
* The returned MAC structure should be passed to either the next highest
* layer in the network stack, or registered with a mac802154dev character
* driver. In either of these scenarios, the next highest layer should
* register a set of callbacks with the MAC layer by setting the mac->cbs
* member.
* or network drivers. In any of these scenarios, the next highest layer
* should register a set of callbacks with the MAC layer by setting the
* mac->cbs member.
*
* NOTE: This API does not create any device accessible to userspace. If you
* want to call these APIs from userspace, you have to wrap your mac in a
@ -975,7 +975,7 @@ FAR struct ieee802154_mac_s *
* user-space
*
* Input Parameters:
* mac - Pointer to the mac layer struct to be registerd.
* mac - Pointer to the mac layer struct to be registered.
* minor - The device minor number. The IEEE802.15.4 MAC character device
* will be registered as /dev/ieeeN where N is the minor number
*
@ -987,6 +987,24 @@ FAR struct ieee802154_mac_s *
int mac802154dev_register(FAR struct ieee802154_mac_s *mac, int minor);
/****************************************************************************
* Name: mac802154netdev_register
*
* Description:
* Register a network driver to access the IEEE 802.15.4 MAC layer from
* a socket using 6loWPAN
*
* Input Parameters:
* mac - Pointer to the mac layer struct to be registered.
*
* Returned Values:
* Zero (OK) is returned on success. Otherwise a negated errno value is
* returned to indicate the nature of the failure.
*
****************************************************************************/
int mac802154netdev_register(FAR struct ieee802154_mac_s *mac);
#undef EXTERN
#ifdef __cplusplus
}

View File

@ -518,9 +518,9 @@ static int mac802154_rsp_orphan(FAR struct ieee802154_mac_s *mac,
*
* The returned MAC structure should be passed to either the next highest
* layer in the network stack, or registered with a mac802154dev character
* driver. In either of these scenarios, the next highest layer should
* register a set of callbacks with the MAC layer by setting the mac->cbs
* member.
* or network drivers. In any of these scenarios, the next highest layer
* should register a set of callbacks with the MAC layer by setting the
* mac->cbs member.
*
* NOTE: This API does not create any device accessible to userspace. If you
* want to call these APIs from userspace, you have to wrap your mac in a

View File

@ -117,8 +117,8 @@ struct mac802154_driver_s
{
/* This holds the information visible to the NuttX network */
struct ieee802154_driver_s m8_dev; /* Interface understood by the network */
struct ieee802154_mac_s m8_mac; /* Interface understood by the MAC */
struct ieee802154_driver_s m8_dev; /* Interface understood by the network */
FAR struct ieee802154_mac_s *m8_mac; /* Contained MAC interface */
/* For internal use by this driver */
@ -129,19 +129,6 @@ struct mac802154_driver_s
struct work_s m8_pollwork; /* For deferring poll work to the work queue */
};
/****************************************************************************
* Private Data
****************************************************************************/
struct ieee802154_radio_s; /* Forware reference */
{
struct ieee802154_macops_s ops;
struct ieee802154_maccb_s cbs;
};
/****************************************************************************
* Private Data
****************************************************************************/
@ -1282,26 +1269,25 @@ static void mac802154_ipv6multicast(FAR struct mac802154_driver_s *priv)
****************************************************************************/
/****************************************************************************
* Name: mac802154_initialize
* Name: mac802154netdev_register
*
* Description:
* Initialize the Ethernet controller and driver
* Register a network driver to access the IEEE 802.15.4 MAC layer from
* a socket using 6loWPAN
*
* Parameters:
* intf - In the case where there are multiple EMACs, this value
* identifies which EMAC is to be initialized.
* Input Parameters:
* mac - Pointer to the mac layer struct to be registered.
*
* Returned Value:
* OK on success; Negated errno on failure.
*
* Assumptions:
* Returned Values:
* Zero (OK) is returned on success. Otherwise a negated errno value is
* returned to indicate the nature of the failure.
*
****************************************************************************/
int mac802154_initialize(FAR struct ieee802154_radio_s *radio)
int mac802154netdev_register(FAR struct ieee802154_mac_s *mac);
{
FAR struct mac802154_driver_s *priv;
FAR struct ieee802154_driver_s *ieee;
FAR truct ieee802154_maccb_s *macb;
FAR struct net_driver_s *dev;
FAR uint8_t *pktbuf;
@ -1332,9 +1318,7 @@ int mac802154_initialize(FAR struct ieee802154_radio_s *radio)
/* Initialize the driver structure */
ieee = &priv->m8_dev;
dev = &ieee->i_dev;
dev = &ieee->m8_dev.i_dev;
dev->d_buf = pktbuf; /* Single packet buffer */
dev->d_ifup = mac802154_ifup; /* I/F up (new IP address) callback */
dev->d_ifdown = mac802154_ifdown; /* I/F down callback */
@ -1347,11 +1331,37 @@ int mac802154_initialize(FAR struct ieee802154_radio_s *radio)
/* Create a watchdog for timing polling for and timing of transmisstions */
priv->m8_txpoll = wd_create(); /* Create periodic poll timer */
priv->m8_mac = mac; /* Save the MAC interface instance */
priv->m8_txpoll = wd_create(); /* Create periodic poll timer */
priv->m8_txtimeout = wd_create(); /* Create TX timeout timer */
DEBUGASSERT(priv->m8_txpoll != NULL && priv->m8_txtimeout != NULL);
/* Initialize the MAC callbacks */
maccb = &mac->cbs;
maccb->cb_context = priv;
maccb->conf_data = mac802154_conf_data;
maccb->conf_purge = mac802154_conf_purge;
maccb->conf_associate = mac802154_conf_associate;
maccb->conf_disassociate = mac802154_conf_disassociate;
maccb->conf_get = mac802154_conf_get;
maccb->conf_gts = mac802154_conf_gts;
maccb->conf_reset = mac802154_conf_reset;
maccb->conf_rxenable = mac802154_conf_rxenable;
maccb->conf_scan = mac802154_conf_scan;
maccb->conf_set = mac802154_conf_set;
maccb->conf_start = mac802154_conf_start;
maccb->conf_poll = mac802154_conf_poll;
maccb->ind_data = mac802154_ind_data;
maccb->ind_associate = mac802154_ind_associate;
maccb->ind_disassociate = mac802154_ind_disassociate;
maccb->ind_beaconnotify = mac802154_ind_beaconnotify;
maccb->ind_gts = mac802154_ind_gts;
maccb->ind_orphan = mac802154_ind_orphan;
maccb->ind_commstatus = mac802154_ind_commstatus;
maccb->ind_syncloss = mac802154_ind_syncloss;
/* Put the interface in the down state. */
mac802154_ifdown(dev);