2017-04-08 22:21:20 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* wireless/ieee802154/mac802154_netdev.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/irq.h>
|
|
|
|
#include <nuttx/wdog.h>
|
|
|
|
#include <nuttx/wqueue.h>
|
|
|
|
#include <nuttx/net/iob.h>
|
|
|
|
#include <nuttx/net/arp.h>
|
|
|
|
#include <nuttx/net/netdev.h>
|
|
|
|
#include <nuttx/net/sixlowpan.h>
|
|
|
|
#include <nuttx/wireless/ieee80154_device.h>
|
|
|
|
#include <nuttx/wireless/ieee80154_mac.h>
|
|
|
|
|
2017-04-14 19:24:40 +02:00
|
|
|
#include "mac802154.h"
|
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* If processing is not done at the interrupt level, then work queue support
|
|
|
|
* is required.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if !defined(CONFIG_SCHED_WORKQUEUE)
|
|
|
|
# error Work queue support is required in this configuration (CONFIG_SCHED_WORKQUEUE)
|
|
|
|
#else
|
|
|
|
|
|
|
|
/* Use the selected work queue */
|
|
|
|
|
|
|
|
# if defined(CONFIG_IEEE802154_NETDEV_HPWORK)
|
|
|
|
# define ETHWORK HPWORK
|
|
|
|
# elif defined(CONFIG_IEEE802154_NETDEV_LPWORK)
|
|
|
|
# define ETHWORK LPWORK
|
|
|
|
# else
|
|
|
|
# error Neither CONFIG_IEEE802154_NETDEV_HPWORK nor CONFIG_IEEE802154_NETDEV_LPWORK defined
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* CONFIG_IEEE802154_NETDEV_NINTERFACES determines the number of physical interfaces
|
|
|
|
* that will be supported.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_IEEE802154_NETDEV_NINTERFACES
|
|
|
|
# define CONFIG_IEEE802154_NETDEV_NINTERFACES 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */
|
|
|
|
|
|
|
|
#define skeleton_WDDELAY (1*CLK_TCK)
|
|
|
|
|
|
|
|
/* TX timeout = 1 minute */
|
|
|
|
|
|
|
|
#define skeleton_TXTIMEOUT (60*CLK_TCK)
|
|
|
|
|
|
|
|
/* This is a helper pointer for accessing the contents of the Ethernet header */
|
|
|
|
|
2017-04-13 20:17:36 +02:00
|
|
|
#define BUF ((struct eth_hdr_s *)priv->md_dev.d_buf)
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-13 20:17:36 +02:00
|
|
|
/* This is our private version of the MAC callback stucture */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
struct macnet_callback_s
|
2017-04-13 20:17:36 +02:00
|
|
|
{
|
|
|
|
/* This holds the information visible to the MAC layer */
|
|
|
|
|
|
|
|
struct ieee802154_maccb_s mc_cb; /* Interface understood by the MAC layer */
|
2017-04-14 18:38:46 +02:00
|
|
|
FAR struct macnet_driver_s *mc_priv; /* Our priv data */
|
2017-04-13 20:17:36 +02:00
|
|
|
};
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
/* The macnet_driver_s encapsulates all state information for a single
|
2017-04-09 14:15:55 +02:00
|
|
|
* IEEE802.15.4 MAC interface.
|
2017-04-08 22:21:20 +02:00
|
|
|
*/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
struct macnet_driver_s
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
|
|
|
/* This holds the information visible to the NuttX network */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
struct ieee802154_driver_s md_dev; /* Interface understood by the network */
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* For internal use by this driver */
|
|
|
|
|
2017-04-16 15:50:11 +02:00
|
|
|
struct macnet_callback_s md_cb; /* Callback information */
|
|
|
|
MACHANDLE md_mac; /* Contained MAC interface */
|
|
|
|
bool md_bifup; /* true:ifup false:ifdown */
|
|
|
|
WDOG_ID md_txpoll; /* TX poll timer */
|
|
|
|
WDOG_ID md_txtimeout; /* TX timeout timer */
|
|
|
|
struct work_s md_irqwork; /* Defer interupt work to the work queue */
|
|
|
|
struct work_s md_pollwork; /* Defer poll work to the work queue */
|
2017-04-08 22:21:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* IEE802.15.4 MAC callback functions ***************************************/
|
2017-04-19 17:30:39 +02:00
|
|
|
|
|
|
|
static void macnet_mlme_notify(FAR struct ieee802154_maccb_s *maccb,
|
|
|
|
enum ieee802154_macnotify_e notif,
|
|
|
|
FAR union ieee802154_mlme_notify_u *arg);
|
|
|
|
|
|
|
|
static void macnet_mcps_notify(FAR struct ieee802154_maccb_s *maccb,
|
|
|
|
enum ieee802154_macnotify_e notif,
|
|
|
|
FAR union ieee802154_mcps_notify_u *arg);
|
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
/* Asynchronous confirmations to requests */
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_data(FAR struct macnet_driver_s *priv,
|
2017-04-08 22:21:20 +02:00
|
|
|
FAR struct ieee802154_data_conf_s *conf);
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_purge(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_purge_conf_s *conf);
|
|
|
|
static void macnet_conf_associate(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_assoc_conf_s *conf);
|
|
|
|
static void macnet_conf_disassociate(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_disassoc_conf_s *conf);
|
|
|
|
static void macnet_conf_get(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_get_conf_s *conf);
|
|
|
|
static void macnet_conf_gts(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_gts_conf_s *conf);
|
|
|
|
static void macnet_conf_reset(FAR struct macnet_driver_s *priv,
|
2017-04-21 21:21:43 +02:00
|
|
|
FAR struct ieee802154_reset_conf_s *conf);
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_rxenable(FAR struct macnet_driver_s *priv,
|
2017-04-21 21:21:43 +02:00
|
|
|
FAR struct ieee802154_rxenable_conf_s *conf);
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_scan(FAR struct macnet_driver_s *priv,
|
2017-04-21 21:21:43 +02:00
|
|
|
FAR struct ieee802154_scan_conf_s *conf);
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_set(FAR struct macnet_driver_s *priv,
|
2017-04-21 21:21:43 +02:00
|
|
|
FAR struct ieee802154_set_conf_s *conf);
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_start(FAR struct macnet_driver_s *priv,
|
2017-04-21 21:21:43 +02:00
|
|
|
FAR struct ieee802154_start_conf_s *conf);
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_poll(FAR struct macnet_driver_s *priv,
|
2017-04-21 21:21:43 +02:00
|
|
|
FAR struct ieee802154_poll_conf_s *conf);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Asynchronous event indications, replied to synchronously with responses */
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_ind_data(FAR struct macnet_driver_s *priv,
|
2017-04-21 21:21:43 +02:00
|
|
|
FAR struct ieee802154_data_ind_s *conf);
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_ind_associate(FAR struct macnet_driver_s *priv,
|
2017-04-21 21:21:43 +02:00
|
|
|
FAR struct ieee802154_assoc_ind_s *conf);
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_ind_disassociate(FAR struct macnet_driver_s *priv,
|
2017-04-21 21:21:43 +02:00
|
|
|
FAR struct ieee802154_disassoc_ind_s *conf);
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_ind_beaconnotify(FAR struct macnet_driver_s *priv,
|
2017-04-21 21:21:43 +02:00
|
|
|
FAR struct ieee802154_beaconnotify_ind_s *conf);
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_ind_gts(FAR struct macnet_driver_s *priv,
|
2017-04-21 21:21:43 +02:00
|
|
|
FAR struct ieee802154_gts_ind_s *conf);
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_ind_orphan(FAR struct macnet_driver_s *priv,
|
2017-04-21 21:21:43 +02:00
|
|
|
FAR struct ieee802154_orphan_ind_s *conf);
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_ind_commstatus(FAR struct macnet_driver_s *priv,
|
2017-04-21 21:21:43 +02:00
|
|
|
FAR struct ieee802154_commstatus_ind_s *conf);
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_ind_syncloss(FAR struct macnet_driver_s *priv,
|
2017-04-21 21:21:43 +02:00
|
|
|
FAR struct ieee802154_syncloss_ind_s *conf);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Network interface support ************************************************/
|
|
|
|
/* Common TX logic */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static int macnet_transmit(FAR struct macnet_driver_s *priv);
|
|
|
|
static int macnet_txpoll(FAR struct net_driver_s *dev);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Frame transfer */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static void macnet_receive(FAR struct macnet_driver_s *priv);
|
|
|
|
static void macnet_txdone(FAR struct macnet_driver_s *priv);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static void macnet_transfer_work(FAR void *arg);
|
|
|
|
static int macnet_transfer(int irq, FAR void *context, FAR void *arg);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Watchdog timer expirations */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static void macnet_txtimeout_work(FAR void *arg);
|
|
|
|
static void macnet_txtimeout_expiry(int argc, wdparm_t arg, ...);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static void macnet_poll_work(FAR void *arg);
|
|
|
|
static void macnet_poll_expiry(int argc, wdparm_t arg, ...);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* NuttX callback functions */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static int macnet_ifup(FAR struct net_driver_s *dev);
|
|
|
|
static int macnet_ifdown(FAR struct net_driver_s *dev);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static void macnet_txavail_work(FAR void *arg);
|
|
|
|
static int macnet_txavail(FAR struct net_driver_s *dev);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
#if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6)
|
2017-04-14 18:38:46 +02:00
|
|
|
static int macnet_addmac(FAR struct net_driver_s *dev,
|
2017-04-14 18:47:46 +02:00
|
|
|
FAR const uint8_t *mac);
|
2017-04-08 22:21:20 +02:00
|
|
|
#ifdef CONFIG_NET_IGMP
|
2017-04-14 18:38:46 +02:00
|
|
|
static int macnet_rmmac(FAR struct net_driver_s *dev,
|
2017-04-14 18:47:46 +02:00
|
|
|
FAR const uint8_t *mac);
|
2017-04-08 22:21:20 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_ICMPv6
|
2017-04-14 18:38:46 +02:00
|
|
|
static void macnet_ipv6multicast(FAR struct macnet_driver_s *priv);
|
2017-04-08 22:21:20 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
2017-04-13 18:18:57 +02:00
|
|
|
#ifdef CONFIG_NETDEV_IOCTL
|
2017-04-14 18:47:46 +02:00
|
|
|
static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd,
|
|
|
|
unsigned long arg);
|
2017-04-13 18:18:57 +02:00
|
|
|
#endif
|
2017-05-03 00:03:26 +02:00
|
|
|
static int macnet_get_mhrlen(FAR struct ieee802154_driver_s *netdev,
|
2017-05-03 17:40:42 +02:00
|
|
|
FAR const struct ieee802154_frame_meta_s *meta);
|
2017-05-03 00:03:26 +02:00
|
|
|
static int macnet_req_data(FAR struct ieee802154_driver_s *netdev,
|
2017-05-03 17:40:42 +02:00
|
|
|
FAR const struct ieee802154_frame_meta_s *meta,
|
2017-05-03 19:13:07 +02:00
|
|
|
FAR struct iob_s *framelist);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:53:32 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: macnet_mlme_notify
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_mlme_notify(FAR struct ieee802154_maccb_s *maccb,
|
|
|
|
enum ieee802154_macnotify_e notif,
|
|
|
|
FAR union ieee802154_mlme_notify_u *arg)
|
|
|
|
{
|
|
|
|
FAR struct macdev_callback_s *cb =
|
|
|
|
(FAR struct macdev_callback_s *)maccb;
|
|
|
|
FAR struct macnet_driver_s *priv;
|
|
|
|
|
|
|
|
DEBUGASSERT(cb != NULL && cb->mc_priv != NULL);
|
|
|
|
priv = cb->mc_priv;
|
|
|
|
|
|
|
|
switch (notif)
|
|
|
|
{
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 17:53:32 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: macnet_mcps_notify
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_mcps_notify(FAR struct ieee802154_maccb_s *maccb,
|
|
|
|
enum ieee802154_macnotify_e notif,
|
|
|
|
FAR union ieee802154_mcps_notify_u *arg)
|
|
|
|
{
|
|
|
|
FAR struct macdev_callback_s *cb =
|
|
|
|
(FAR struct macdev_callback_s *)maccb;
|
|
|
|
FAR struct macdev_driver_s *priv;
|
|
|
|
|
|
|
|
DEBUGASSERT(cb != NULL && cb->mc_priv != NULL);
|
|
|
|
priv = cb->mc_priv;
|
|
|
|
|
|
|
|
switch (notif)
|
|
|
|
{
|
|
|
|
case IEEE802154_NOTIFY_CONF_DATA:
|
|
|
|
{
|
|
|
|
macnet_conf_data(priv, &arg->dataconf);
|
|
|
|
}
|
|
|
|
break;
|
2017-04-19 17:53:32 +02:00
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
case IEEE802154_NOTIFY_CONF_PURGE:
|
|
|
|
{
|
|
|
|
macnet_conf_purge(priv, &arg->purgeconf);
|
|
|
|
}
|
|
|
|
break;
|
2017-04-19 17:53:32 +02:00
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
case IEEE802154_NOTIFY_IND_DATA:
|
|
|
|
{
|
|
|
|
macnet_ind_data(priv, &arg->dataind);
|
|
|
|
}
|
|
|
|
break;
|
2017-04-19 17:53:32 +02:00
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_conf_data
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Data frame was received by remote device
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_data(FAR struct macnet_driver_s *priv,
|
2017-04-14 18:38:46 +02:00
|
|
|
FAR struct ieee802154_data_conf_s *conf)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_conf_purge
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Data frame was purged
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_purge(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_purge_conf_s *conf)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_conf_associate
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Association request completed
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_associate(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_assoc_conf_s *conf)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_conf_disassociate
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Disassociation request completed
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_disassociate(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_disassoc_conf_s *conf)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_conf_get
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-04-19 17:30:39 +02:00
|
|
|
* PIB data returned
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_get(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_get_conf_s *conf)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_conf_gts
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-04-19 17:30:39 +02:00
|
|
|
* GTS management completed
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_gts(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_gts_conf_s *conf)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_conf_reset
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-04-19 17:30:39 +02:00
|
|
|
* MAC reset completed
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_reset(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_reset_conf_s *conf)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_conf_rxenable
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_rxenable(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_rxenable_conf_s *conf)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_conf_scan
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_scan(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_scan_conf_s *conf)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_conf_set
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_set(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_set_conf_s *conf)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_conf_start
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_start(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_start_conf_s *conf)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_conf_poll
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_conf_poll(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_poll_conf_s *conf)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_ind_data
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Data frame received
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_ind_data(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_data_ind_s *ind)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_ind_associate
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Association request received
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_ind_associate(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_assoc_ind_s *ind)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_ind_disassociate
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Disassociation request received
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_ind_disassociate(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_disassoc_ind_s *ind)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_ind_beaconnotify
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Beacon notification
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_ind_beaconnotify(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_beaconnotify_ind_s *ind)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_ind_gts
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* GTS management request received
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_ind_gts(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_gts_ind_s *ind)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_ind_orphan
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Orphan device detected
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_ind_orphan(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_orphan_ind_s *ind)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_ind_commstatus
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_ind_commstatus(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_commstatus_ind_s *ind)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_ind_syncloss
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
static void macnet_ind_syncloss(FAR struct macnet_driver_s *priv,
|
|
|
|
FAR struct ieee802154_syncloss_ind_s *ind)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-09 14:15:55 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_transmit
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-04-16 15:50:11 +02:00
|
|
|
* This function is called from the lower MAC layer when thre radio device
|
|
|
|
* is ready to accept another outgoing frame. It removes one of the
|
|
|
|
* previously queued fram IOBs and provides that to the MAC layer.
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; a negated errno on failure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
2017-04-16 15:50:11 +02:00
|
|
|
* May or may not be called from an interrupt handler.
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static int macnet_transmit(FAR struct macnet_driver_s *priv)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-16 15:50:11 +02:00
|
|
|
/* Cancel the TX timeout watchdog
|
|
|
|
*
|
|
|
|
* REVISIT: Is there not a race condition here? Might the TX timeout
|
|
|
|
* already be queued?.
|
2017-04-08 22:21:20 +02:00
|
|
|
*/
|
|
|
|
|
2017-04-16 15:50:11 +02:00
|
|
|
wd_cancel(priv->md_txtimeout);
|
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
/* Increment statistics */
|
|
|
|
|
2017-04-13 20:17:36 +02:00
|
|
|
NETDEV_TXPACKETS(priv->md_dev);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2017-04-16 15:50:11 +02:00
|
|
|
/* Provide the pre-formatted packet to the radio device (via the lower MAC
|
|
|
|
* layer).
|
|
|
|
*/
|
|
|
|
#warning Missing logic
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Setup the TX timeout watchdog (perhaps restarting the timer) */
|
|
|
|
|
2017-04-13 20:17:36 +02:00
|
|
|
(void)wd_start(priv->md_txtimeout, skeleton_TXTIMEOUT,
|
2017-04-14 18:38:46 +02:00
|
|
|
macnet_txtimeout_expiry, 1, (wdparm_t)priv);
|
2017-04-08 22:21:20 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_txpoll
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The transmitter is available, check if the network has any outgoing
|
|
|
|
* packets ready to send. This is a callback from devif_poll().
|
|
|
|
* devif_poll() may be called:
|
|
|
|
*
|
|
|
|
* 1. When the preceding TX packet send is complete,
|
|
|
|
* 2. When the preceding TX packet send timesout and the interface is reset
|
|
|
|
* 3. During normal TX polling
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; a negated errno on failure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
2017-05-03 17:40:42 +02:00
|
|
|
* The network is locked.
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static int macnet_txpoll(FAR struct net_driver_s *dev)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
|
|
|
/* If zero is returned, the polling will continue until all connections have
|
|
|
|
* been examined.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_receive
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* An interrupt was received indicating the availability of a new RX packet
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The network is locked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static void macnet_receive(FAR struct macnet_driver_s *priv)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
|
|
|
FAR struct iob_s *iob;
|
|
|
|
FAR struct iob_s *fptr;
|
|
|
|
|
|
|
|
/* Allocate an IOB to hold the frame */
|
|
|
|
|
|
|
|
net_lock();
|
|
|
|
iob = iob_alloc(false);
|
2017-05-03 17:40:42 +02:00
|
|
|
#warning Allocated by radio layer, right?
|
2017-04-08 22:21:20 +02:00
|
|
|
if (iob == NULL)
|
|
|
|
{
|
|
|
|
nerr("ERROR: Failed to allocate an IOB\n")
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the frame data into the IOB.
|
|
|
|
* REVISIT: Can a copy be avoided?
|
|
|
|
*/
|
|
|
|
|
|
|
|
fptr = iob->io_data;
|
|
|
|
#warning Missing logic
|
|
|
|
|
|
|
|
/* Transfer the frame to the network logic */
|
|
|
|
|
2017-05-04 19:33:22 +02:00
|
|
|
sixlowpan_input(&priv->md_dev, iob, NULL);
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_txdone
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* An interrupt was received indicating that the last TX packet(s) is done
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The network is locked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static void macnet_txdone(FAR struct macnet_driver_s *priv)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
|
|
|
int delay;
|
|
|
|
|
|
|
|
/* Check for errors and update statistics */
|
|
|
|
|
2017-04-13 20:17:36 +02:00
|
|
|
NETDEV_TXDONE(priv->md_dev);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Check if there are pending transmissions */
|
|
|
|
|
|
|
|
/* If no further transmissions are pending, then cancel the TX timeout and
|
|
|
|
* disable further Tx interrupts.
|
|
|
|
*/
|
|
|
|
|
2017-04-13 20:17:36 +02:00
|
|
|
wd_cancel(priv->md_txtimeout);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* And disable further TX interrupts. */
|
|
|
|
|
|
|
|
/* In any event, poll the network for new TX data */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
(void)devif_poll(&priv->md_dev, macnet_txpoll);
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_transfer_work
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform interrupt related work from the worker thread
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* arg - The argument passed when work_queue() was called.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The network is locked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static void macnet_transfer_work(FAR void *arg)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-14 18:38:46 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg;
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Lock the network and serialize driver operations if necessary.
|
|
|
|
* NOTE: Serialization is only required in the case where the driver work
|
|
|
|
* is performed on an LP worker thread and where more than one LP worker
|
|
|
|
* thread has been configured.
|
|
|
|
*/
|
|
|
|
|
|
|
|
net_lock();
|
|
|
|
|
|
|
|
/* Process pending Ethernet interrupts */
|
|
|
|
|
|
|
|
/* Get and clear interrupt status bits */
|
|
|
|
|
|
|
|
/* Handle interrupts according to status bit settings */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
/* Check if we received an incoming packet, if so, call macnet_receive() */
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
macnet_receive(priv);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
/* Check if a packet transmission just completed. If so, call macnet_txdone.
|
2017-04-08 22:21:20 +02:00
|
|
|
* This may disable further Tx interrupts if there are no pending
|
|
|
|
* transmissions.
|
|
|
|
*/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
macnet_txdone(priv);
|
2017-04-08 22:21:20 +02:00
|
|
|
net_unlock();
|
|
|
|
|
|
|
|
/* Re-enable Ethernet interrupts */
|
|
|
|
|
|
|
|
up_enable_irq(CONFIG_IEEE802154_NETDEV_IRQ);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_transfer
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Hardware interrupt handler
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* irq - Number of the IRQ that generated the interrupt
|
|
|
|
* context - Interrupt register state save info (architecture-specific)
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static int macnet_transfer(int irq, FAR void *context, FAR void *arg)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-14 18:38:46 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg;
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Disable further Ethernet interrupts. Because Ethernet interrupts are
|
|
|
|
* also disabled if the TX timeout event occurs, there can be no race
|
|
|
|
* condition here.
|
|
|
|
*/
|
|
|
|
|
|
|
|
up_disable_irq(CONFIG_IEEE802154_NETDEV_IRQ);
|
|
|
|
|
|
|
|
/* TODO: Determine if a TX transfer just completed */
|
|
|
|
|
|
|
|
{
|
|
|
|
/* If a TX transfer just completed, then cancel the TX timeout so
|
|
|
|
* there will be no race condition between any subsequent timeout
|
|
|
|
* expiration and the deferred interrupt processing.
|
|
|
|
*/
|
|
|
|
|
2017-04-13 20:17:36 +02:00
|
|
|
wd_cancel(priv->md_txtimeout);
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Schedule to perform the interrupt processing on the worker thread. */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
work_queue(ETHWORK, &priv->md_irqwork, macnet_transfer_work, priv, 0);
|
2017-04-08 22:21:20 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_txtimeout_work
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform TX timeout related work from the worker thread
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* arg - The argument passed when work_queue() as called.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The network is locked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static void macnet_txtimeout_work(FAR void *arg)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-14 18:38:46 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg;
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Lock the network and serialize driver operations if necessary.
|
|
|
|
* NOTE: Serialization is only required in the case where the driver work
|
|
|
|
* is performed on an LP worker thread and where more than one LP worker
|
|
|
|
* thread has been configured.
|
|
|
|
*/
|
|
|
|
|
|
|
|
net_lock();
|
|
|
|
|
|
|
|
/* Increment statistics and dump debug info */
|
|
|
|
|
2017-04-13 20:17:36 +02:00
|
|
|
NETDEV_TXTIMEOUTS(priv->md_dev);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Then reset the hardware */
|
|
|
|
|
|
|
|
/* Then poll the network for new XMIT data */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
(void)devif_poll(&priv->md_dev, macnet_txpoll);
|
2017-04-08 22:21:20 +02:00
|
|
|
net_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_txtimeout_expiry
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Our TX watchdog timed out. Called from the timer interrupt handler.
|
|
|
|
* The last TX never completed. Reset the hardware and start again.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* argc - The number of available arguments
|
|
|
|
* arg - The first argument
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Global interrupts are disabled by the watchdog logic.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static void macnet_txtimeout_expiry(int argc, wdparm_t arg, ...)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-14 18:38:46 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg;
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Disable further Ethernet interrupts. This will prevent some race
|
|
|
|
* conditions with interrupt work. There is still a potential race
|
|
|
|
* condition with interrupt work that is already queued and in progress.
|
|
|
|
*/
|
|
|
|
|
|
|
|
up_disable_irq(CONFIG_IEEE802154_NETDEV_IRQ);
|
|
|
|
|
|
|
|
/* Schedule to perform the TX timeout processing on the worker thread. */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
work_queue(ETHWORK, &priv->md_irqwork, macnet_txtimeout_work, priv, 0);
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_poll_process
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform the periodic poll. This may be called either from watchdog
|
|
|
|
* timer logic or from the worker thread, depending upon the configuration.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static inline void macnet_poll_process(FAR struct macnet_driver_s *priv)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_poll_work
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform periodic polling from the worker thread
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* arg - The argument passed when work_queue() as called.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The network is locked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static void macnet_poll_work(FAR void *arg)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-14 18:38:46 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg;
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Lock the network and serialize driver operations if necessary.
|
|
|
|
* NOTE: Serialization is only required in the case where the driver work
|
|
|
|
* is performed on an LP worker thread and where more than one LP worker
|
|
|
|
* thread has been configured.
|
|
|
|
*/
|
|
|
|
|
|
|
|
net_lock();
|
|
|
|
|
|
|
|
/* Perform the poll */
|
|
|
|
|
|
|
|
/* Check if there is room in the send another TX packet. We cannot perform
|
|
|
|
* the TX poll if he are unable to accept another packet for transmission.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* If so, update TCP timing states and poll the network for new XMIT data.
|
|
|
|
* Hmmm.. might be bug here. Does this mean if there is a transmit in
|
|
|
|
* progress, we will missing TCP time state updates?
|
|
|
|
*/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
(void)devif_timer(&priv->md_dev, macnet_txpoll);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Setup the watchdog poll timer again */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
(void)wd_start(priv->md_txpoll, skeleton_WDDELAY, macnet_poll_expiry, 1,
|
2017-04-08 22:21:20 +02:00
|
|
|
(wdparm_t)priv);
|
|
|
|
net_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_poll_expiry
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Periodic timer handler. Called from the timer interrupt handler.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* argc - The number of available arguments
|
|
|
|
* arg - The first argument
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Global interrupts are disabled by the watchdog logic.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static void macnet_poll_expiry(int argc, wdparm_t arg, ...)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-14 18:38:46 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg;
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Schedule to perform the interrupt processing on the worker thread. */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
work_queue(ETHWORK, &priv->md_pollwork, macnet_poll_work, priv, 0);
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_ifup
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Bring up the Ethernet interface when an IP address is
|
|
|
|
* provided
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static int macnet_ifup(FAR struct net_driver_s *dev)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-14 18:38:46 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private;
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
ninfo("Bringing up: %d.%d.%d.%d\n",
|
|
|
|
dev->d_ipaddr & 0xff, (dev->d_ipaddr >> 8) & 0xff,
|
|
|
|
(dev->d_ipaddr >> 16) & 0xff, dev->d_ipaddr >> 24);
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
ninfo("Bringing up: %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
|
|
|
dev->d_ipv6addr[0], dev->d_ipv6addr[1], dev->d_ipv6addr[2],
|
|
|
|
dev->d_ipv6addr[3], dev->d_ipv6addr[4], dev->d_ipv6addr[5],
|
|
|
|
dev->d_ipv6addr[6], dev->d_ipv6addr[7]);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Initialize PHYs, the Ethernet interface, and setup up Ethernet interrupts */
|
|
|
|
|
2017-04-13 20:17:36 +02:00
|
|
|
/* Instantiate the MAC address from priv->md_dev.d_mac.ether_addr_octet */
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ICMPv6
|
|
|
|
/* Set up IPv6 multicast address filtering */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
macnet_ipv6multicast(priv);
|
2017-04-08 22:21:20 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Set and activate a timer process */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
(void)wd_start(priv->md_txpoll, skeleton_WDDELAY, macnet_poll_expiry, 1,
|
2017-04-08 22:21:20 +02:00
|
|
|
(wdparm_t)priv);
|
|
|
|
|
|
|
|
/* Enable the Ethernet interrupt */
|
|
|
|
|
2017-04-13 20:17:36 +02:00
|
|
|
priv->md_bifup = true;
|
2017-04-08 22:21:20 +02:00
|
|
|
up_enable_irq(CONFIG_IEEE802154_NETDEV_IRQ);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_ifdown
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Stop the interface.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static int macnet_ifdown(FAR struct net_driver_s *dev)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-14 18:38:46 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private;
|
2017-04-08 22:21:20 +02:00
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
/* Disable the Ethernet interrupt */
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
up_disable_irq(CONFIG_IEEE802154_NETDEV_IRQ);
|
|
|
|
|
|
|
|
/* Cancel the TX poll timer and TX timeout timers */
|
|
|
|
|
2017-04-13 20:17:36 +02:00
|
|
|
wd_cancel(priv->md_txpoll);
|
|
|
|
wd_cancel(priv->md_txtimeout);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Put the EMAC in its reset, non-operational state. This should be
|
2017-04-14 18:38:46 +02:00
|
|
|
* a known configuration that will guarantee the macnet_ifup() always
|
2017-04-08 22:21:20 +02:00
|
|
|
* successfully brings the interface back up.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Mark the device "down" */
|
|
|
|
|
2017-04-13 20:17:36 +02:00
|
|
|
priv->md_bifup = false;
|
2017-04-08 22:21:20 +02:00
|
|
|
leave_critical_section(flags);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_txavail_work
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform an out-of-cycle poll on the worker thread.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* arg - Reference to the NuttX driver state structure (cast to void*)
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called on the higher priority worker thread.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static void macnet_txavail_work(FAR void *arg)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-14 18:38:46 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)arg;
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Lock the network and serialize driver operations if necessary.
|
|
|
|
* NOTE: Serialization is only required in the case where the driver work
|
|
|
|
* is performed on an LP worker thread and where more than one LP worker
|
|
|
|
* thread has been configured.
|
|
|
|
*/
|
|
|
|
|
|
|
|
net_lock();
|
|
|
|
|
|
|
|
/* Ignore the notification if the interface is not yet up */
|
|
|
|
|
2017-04-13 20:17:36 +02:00
|
|
|
if (priv->md_bifup)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
|
|
|
/* Check if there is room in the hardware to hold another outgoing packet. */
|
|
|
|
|
|
|
|
/* If so, then poll the network for new XMIT data */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
(void)devif_poll(&priv->md_dev, macnet_txpoll);
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
net_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_txavail
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Driver callback invoked when new TX data is available. This is a
|
|
|
|
* stimulus perform an out-of-cycle poll and, thereby, reduce the TX
|
|
|
|
* latency.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called in normal user mode
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
static int macnet_txavail(FAR struct net_driver_s *dev)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-14 18:38:46 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private;
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Is our single work structure available? It may not be if there are
|
|
|
|
* pending interrupt actions and we will have to ignore the Tx
|
|
|
|
* availability action.
|
|
|
|
*/
|
|
|
|
|
2017-04-13 20:17:36 +02:00
|
|
|
if (work_available(&priv->md_pollwork))
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
|
|
|
/* Schedule to serialize the poll on the worker thread. */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
work_queue(ETHWORK, &priv->md_pollwork, macnet_txavail_work, priv, 0);
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_addmac
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Add the specified MAC address to the hardware multicast
|
|
|
|
* address filtering
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
* mac - The MAC address to be added
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_IGMP) || defined(CONFIG_NET_ICMPv6)
|
2017-04-14 18:38:46 +02:00
|
|
|
static int macnet_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-14 18:38:46 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private;
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Add the MAC address to the hardware multicast routing table */
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_rmmac
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Remove the specified MAC address from the hardware multicast
|
|
|
|
* address filtering
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
* mac - The MAC address to be removed
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IGMP
|
2017-04-14 18:38:46 +02:00
|
|
|
static int macnet_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-14 18:38:46 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private;
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Add the MAC address to the hardware multicast routing table */
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_ipv6multicast
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Configure the IPv6 multicast MAC address.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* priv - A reference to the private driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; Negated errno on failure.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ICMPv6
|
2017-04-14 18:38:46 +02:00
|
|
|
static void macnet_ipv6multicast(FAR struct macnet_driver_s *priv)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
uint16_t tmp16;
|
|
|
|
uint8_t mac[6];
|
|
|
|
|
|
|
|
/* For ICMPv6, we need to add the IPv6 multicast address
|
|
|
|
*
|
|
|
|
* For IPv6 multicast addresses, the Ethernet MAC is derived by
|
|
|
|
* the four low-order octets OR'ed with the MAC 33:33:00:00:00:00,
|
|
|
|
* so for example the IPv6 address FF02:DEAD:BEEF::1:3 would map
|
|
|
|
* to the Ethernet MAC address 33:33:00:01:00:03.
|
|
|
|
*
|
|
|
|
* NOTES: This appears correct for the ICMPv6 Router Solicitation
|
|
|
|
* Message, but the ICMPv6 Neighbor Solicitation message seems to
|
|
|
|
* use 33:33:ff:01:00:03.
|
|
|
|
*/
|
|
|
|
|
|
|
|
mac[0] = 0x33;
|
|
|
|
mac[1] = 0x33;
|
|
|
|
|
|
|
|
dev = &priv->dev;
|
|
|
|
tmp16 = dev->d_ipv6addr[6];
|
|
|
|
mac[2] = 0xff;
|
|
|
|
mac[3] = tmp16 >> 8;
|
|
|
|
|
|
|
|
tmp16 = dev->d_ipv6addr[7];
|
|
|
|
mac[4] = tmp16 & 0xff;
|
|
|
|
mac[5] = tmp16 >> 8;
|
|
|
|
|
|
|
|
ninfo("IPv6 Multicast: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
|
|
|
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
(void)macnet_addmac(dev, mac);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
|
|
|
/* Add the IPv6 all link-local nodes Ethernet address. This is the
|
|
|
|
* address that we expect to receive ICMPv6 Router Advertisement
|
|
|
|
* packets.
|
|
|
|
*/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
(void)macnet_addmac(dev, g_ipv6_ethallnodes.ether_addr_octet);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
#endif /* CONFIG_NET_ICMPv6_AUTOCONF */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ICMPv6_ROUTER
|
|
|
|
/* Add the IPv6 all link-local routers Ethernet address. This is the
|
|
|
|
* address that we expect to receive ICMPv6 Router Solicitation
|
|
|
|
* packets.
|
|
|
|
*/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
(void)macnet_addmac(dev, g_ipv6_ethallrouters.ether_addr_octet);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
#endif /* CONFIG_NET_ICMPv6_ROUTER */
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_ICMPv6 */
|
|
|
|
|
2017-04-13 18:18:57 +02:00
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_ioctl
|
2017-04-13 18:18:57 +02:00
|
|
|
*
|
|
|
|
* 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
|
2017-04-14 18:47:46 +02:00
|
|
|
static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd,
|
|
|
|
unsigned long arg)
|
2017-04-13 18:18:57 +02:00
|
|
|
{
|
2017-04-14 18:38:46 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)dev->d_private;
|
2017-04-13 18:18:57 +02:00
|
|
|
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);
|
2017-04-13 20:17:36 +02:00
|
|
|
ret = priv->md_mac.macops.ioctl(priv->md_mac, cmd, macarg);
|
2017-04-13 18:18:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Okay, we have no idea what this command is.. just give to the
|
|
|
|
* IEEE802.15.4 MAC layer without modification.
|
|
|
|
*/
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
2017-04-13 20:17:36 +02:00
|
|
|
ret = priv->md_mac.macops.ioctl(priv->md_mac, cmd, arg);
|
2017-04-13 18:18:57 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-03 00:03:26 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: macnet_get_mhrlen
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Calculate the MAC header length given the frame meta-data.
|
|
|
|
*
|
2017-05-03 19:13:07 +02:00
|
|
|
* Input parameters:
|
|
|
|
* netdev - The networkd device that will mediate the MAC interface
|
|
|
|
* meta - Meta data needed to recreate the MAC header
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* A non-negative MAC headeer length is returned on success; a negated
|
|
|
|
* errno value is returned on any failure.
|
|
|
|
*
|
2017-05-03 00:03:26 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int macnet_get_mhrlen(FAR struct ieee802154_driver_s *netdev,
|
2017-05-03 17:40:42 +02:00
|
|
|
FAR const struct ieee802154_frame_meta_s *meta)
|
2017-05-03 00:03:26 +02:00
|
|
|
{
|
|
|
|
FAR struct macnet_driver_s *priv;
|
|
|
|
|
|
|
|
DEBUGASSERT(netdev != NULL && netdev->i_dev.d_private != NULL && iob != NULL);
|
|
|
|
priv = (FAR struct macnet_driver_s *)netdev->i_dev.d_private;
|
|
|
|
|
|
|
|
return mac802154_get_mhrlen(priv->md_mac, meta);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: macnet_req_data
|
|
|
|
*
|
|
|
|
* Description:
|
2017-05-03 19:13:07 +02:00
|
|
|
* Requests the transfer of a list of frames to the MAC.
|
|
|
|
*
|
|
|
|
* Input parameters:
|
|
|
|
* netdev - The networkd device that will mediate the MAC interface
|
|
|
|
* meta - Meta data needed to recreate the MAC header
|
|
|
|
* framelist - Head of a list of frames to be transferred.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) returned on success; a negated errno value is returned on
|
|
|
|
* any failure.
|
2017-05-03 00:03:26 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int macnet_req_data(FAR struct ieee802154_driver_s *netdev,
|
2017-05-03 17:40:42 +02:00
|
|
|
FAR const struct ieee802154_frame_meta_s *meta,
|
2017-05-03 19:13:07 +02:00
|
|
|
FAR struct iob_s *framelist)
|
2017-05-03 00:03:26 +02:00
|
|
|
{
|
|
|
|
FAR struct macnet_driver_s *priv;
|
|
|
|
struct ieee802154_data_req_s req;
|
|
|
|
FAR struct iob_s *iob;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
DEBUGASSERT(netdev != NULL && netdev->i_dev.d_private != NULL && iob != NULL);
|
|
|
|
priv = (FAR struct macnet_driver_s *)netdev->i_dev.d_private;
|
|
|
|
|
|
|
|
/* Add the incoming list of frames to the MAC's outgoing queue */
|
|
|
|
|
2017-05-03 19:13:07 +02:00
|
|
|
for (iob = framelist; iob != NULL; iob = framelist)
|
2017-05-03 00:03:26 +02:00
|
|
|
{
|
|
|
|
/* Increment statistics */
|
|
|
|
|
|
|
|
NETDEV_RXPACKETS(&priv->lo_ieee.i_dev);
|
|
|
|
|
|
|
|
/* Remove the IOB from the queue */
|
|
|
|
|
2017-05-03 19:13:07 +02:00
|
|
|
framelist = iob->io_flink;
|
2017-05-03 00:03:26 +02:00
|
|
|
iob->io_flink = NULL;
|
|
|
|
|
|
|
|
/* Transfer the frame to the MAC */
|
|
|
|
|
|
|
|
req.meta = mets;
|
|
|
|
req.frame = iob;
|
|
|
|
ret = mac802154_req_data(priv->md_mac, req);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
wlerr("ERROR: mac802154_req_data failed: %d\n", ret);
|
|
|
|
|
|
|
|
iob_free(iob);
|
2017-05-03 19:13:07 +02:00
|
|
|
for (iob = framelist; ; iob != NULL; iob = framelist)
|
2017-05-03 00:03:26 +02:00
|
|
|
{
|
|
|
|
/* Remove the IOB from the queue and free */
|
|
|
|
|
2017-05-03 19:13:07 +02:00
|
|
|
framelist = iob->io_flink;
|
2017-05-03 00:03:26 +02:00
|
|
|
iob_free(iob);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-09 03:11:57 +02:00
|
|
|
* Name: mac802154netdev_register
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-04-09 03:11:57 +02:00
|
|
|
* Register a network driver to access the IEEE 802.15.4 MAC layer from
|
|
|
|
* a socket using 6loWPAN
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
2017-04-09 03:11:57 +02:00
|
|
|
* Input Parameters:
|
|
|
|
* mac - Pointer to the mac layer struct to be registered.
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
2017-04-09 03:11:57 +02:00
|
|
|
* Returned Values:
|
|
|
|
* Zero (OK) is returned on success. Otherwise a negated errno value is
|
|
|
|
* returned to indicate the nature of the failure.
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
int mac802154netdev_register(MACHANDLE mac)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2017-04-14 18:38:46 +02:00
|
|
|
FAR struct macnet_driver_s *priv;
|
2017-05-03 00:03:26 +02:00
|
|
|
FAR struct ieee802154_driver_s *ieee;
|
|
|
|
FAR struct net_driver_s *dev;
|
2017-04-19 17:30:39 +02:00
|
|
|
FAR struct ieee802154_maccb_s *maccb;
|
2017-04-08 22:21:20 +02:00
|
|
|
FAR uint8_t *pktbuf;
|
2017-04-13 20:17:36 +02:00
|
|
|
int ret;
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
DEBUGASSERT(mac != NULL);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Get the interface structure associated with this interface number. */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
priv = (FAR struct macnet_driver_s *)
|
|
|
|
kmm_zalloc(sizeof(struct macnet_driver_s));
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
if (priv == NULL)
|
|
|
|
{
|
|
|
|
nerr("ERROR: Failed to allocate the device structure\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a packet buffer (not used by this driver, but need by the
|
|
|
|
* upper networking layer)
|
|
|
|
*/
|
|
|
|
|
|
|
|
pktbuf = (FAR uint8_t *)kmm_malloc(CONFIG_NET_6LOWPAN_MTU + CONFIG_NET_GUARDSIZE);
|
|
|
|
if (pktbuf == NULL
|
|
|
|
{
|
|
|
|
nerr("ERROR: Failed to allocate the packet buffer\n");
|
|
|
|
kmm_free(priv);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the driver structure */
|
|
|
|
|
2017-05-03 00:03:26 +02:00
|
|
|
ieee = &priv->lo_ieee;
|
|
|
|
dev = &ieee->i_dev;
|
|
|
|
dev->d_buf = pktbuf; /* Single packet buffer */
|
|
|
|
dev->d_ifup = macnet_ifup; /* I/F up (new IP address) callback */
|
|
|
|
dev->d_ifdown = macnet_ifdown; /* I/F down callback */
|
|
|
|
dev->d_txavail = macnet_txavail; /* New TX data callback */
|
2017-04-08 22:21:20 +02:00
|
|
|
#ifdef CONFIG_NET_IGMP
|
2017-05-03 00:03:26 +02:00
|
|
|
dev->d_addmac = macnet_addmac; /* Add multicast MAC address */
|
|
|
|
dev->d_rmmac = macnet_rmmac; /* Remove multicast MAC address */
|
2017-04-13 18:18:57 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NETDEV_IOCTL
|
2017-05-03 00:03:26 +02:00
|
|
|
dev->d_ioctl = macnet_ioctl; /* Handle network IOCTL commands */
|
2017-04-08 22:21:20 +02:00
|
|
|
#endif
|
2017-05-03 00:03:26 +02:00
|
|
|
dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Create a watchdog for timing polling for and timing of transmisstions */
|
|
|
|
|
2017-05-03 00:03:26 +02:00
|
|
|
priv->md_mac = mac; /* Save the MAC interface instance */
|
|
|
|
priv->md_txpoll = wd_create(); /* Create periodic poll timer */
|
|
|
|
priv->md_txtimeout = wd_create(); /* Create TX timeout timer */
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2017-04-13 20:17:36 +02:00
|
|
|
DEBUGASSERT(priv->md_txpoll != NULL && priv->md_txtimeout != NULL);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2017-05-03 00:03:26 +02:00
|
|
|
/* Initialize the Network frame-related callbacks */
|
|
|
|
|
|
|
|
ieee->i_get_mhrlen = macnet_get_mhrlen; /* Get MAC header length */
|
|
|
|
ieee->i_req_data = macnet_req_data; /* Enqueue frame for transmission */
|
|
|
|
|
2017-04-09 03:11:57 +02:00
|
|
|
/* Initialize the MAC callbacks */
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
priv->md_cb.mc_priv = priv;
|
|
|
|
|
|
|
|
maccb = &priv->md_cb.mc_cb;
|
2017-04-21 21:21:43 +02:00
|
|
|
maccb->mlme_notify = macdev_mlme_notify;
|
|
|
|
maccb->mcps_notify = macdev_mcps_notify;
|
2017-04-09 03:11:57 +02:00
|
|
|
|
2017-04-13 20:17:36 +02:00
|
|
|
/* Bind the callback structure */
|
|
|
|
|
2017-04-19 17:30:39 +02:00
|
|
|
ret = mac802154_bind(mac, maccb);
|
|
|
|
if (ret < 0
|
2017-04-13 20:17:36 +02:00
|
|
|
{
|
|
|
|
nerr("ERROR: Failed to bind the MAC callbacks: %d\n", ret);
|
|
|
|
|
|
|
|
/* Release wdog timers */
|
|
|
|
|
|
|
|
wd_delete(priv->md_txpoll);
|
|
|
|
wd_delete(priv->md_txtimeout);
|
|
|
|
|
|
|
|
/* Free memory and return the error */
|
|
|
|
kmm_free(pktbuf);
|
|
|
|
kmm_free(priv);
|
2017-04-19 17:30:39 +02:00
|
|
|
return ret;
|
2017-04-13 20:17:36 +02:00
|
|
|
}
|
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
/* Put the interface in the down state. */
|
|
|
|
|
2017-04-14 18:38:46 +02:00
|
|
|
macnet_ifdown(dev);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* Register the device with the OS so that socket IOCTLs can be performed */
|
|
|
|
|
2017-04-13 20:17:36 +02:00
|
|
|
(void)netdev_register(&priv->md_dev, NET_LL_IEEE802154);
|
2017-04-08 22:21:20 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET && CONFIG_NET_skeleton */
|