2017-04-03 00:29:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* wireless/iee802154/mac802154_loopback.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 <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
|
|
|
|
#include <nuttx/wdog.h>
|
|
|
|
#include <nuttx/wqueue.h>
|
2017-08-26 18:00:47 +02:00
|
|
|
#include <nuttx/mm/iob.h>
|
2017-04-03 00:29:02 +02:00
|
|
|
#include <nuttx/net/net.h>
|
|
|
|
#include <nuttx/net/ip.h>
|
2017-08-20 15:10:48 +02:00
|
|
|
#include <nuttx/net/radiodev.h>
|
2017-08-19 20:32:56 +02:00
|
|
|
#include <nuttx/net/ieee802154.h>
|
2017-04-03 17:15:00 +02:00
|
|
|
#include <nuttx/net/sixlowpan.h>
|
|
|
|
#include <nuttx/wireless/ieee802154/ieee802154_loopback.h>
|
2017-04-03 00:29:02 +02:00
|
|
|
|
2017-04-14 19:24:40 +02:00
|
|
|
#include "mac802154.h"
|
|
|
|
|
2017-04-03 00:29:02 +02:00
|
|
|
#ifdef CONFIG_IEEE802154_LOOPBACK
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* We need to have the work queue to handle SPI interrupts */
|
|
|
|
|
|
|
|
#if !defined(CONFIG_SCHED_WORKQUEUE)
|
|
|
|
# error Worker thread support is required (CONFIG_SCHED_WORKQUEUE)
|
|
|
|
#else
|
|
|
|
# if defined(CONFIG_IEEE802154_LOOPBACK_HPWORK)
|
|
|
|
# define LPBKWORK HPWORK
|
|
|
|
# elif defined(CONFIG_IEEE802154_LOOPBACK_LPWORK)
|
|
|
|
# define LPBKWORK LPWORK
|
|
|
|
# else
|
|
|
|
# error Neither CONFIG_IEEE802154_LOOPBACK_HPWORK nor CONFIG_IEEE802154_LOOPBACK_LPWORK defined
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2017-08-20 19:14:43 +02:00
|
|
|
/* Preferred address size */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
|
|
|
# define LO_ADDRSIZE IEEE802154_EADDRSIZE
|
|
|
|
#else
|
|
|
|
# define LO_ADDRSIZE IEEE802154_SADDRSIZE
|
|
|
|
#endif
|
|
|
|
|
2017-09-10 19:40:54 +02:00
|
|
|
/* Frame size */
|
2017-08-20 19:14:43 +02:00
|
|
|
|
2017-09-10 19:40:54 +02:00
|
|
|
#if defined(CONFIG_NET_IEEE802154_FRAMELEN)
|
2017-08-20 19:14:43 +02:00
|
|
|
# define LO_FRAMELEN CONFIG_NET_IEEE802154_FRAMELEN
|
|
|
|
#else
|
|
|
|
# define LO_FRAMELEN IEEE802154_MAX_PHY_PACKET_SIZE
|
|
|
|
#endif
|
|
|
|
|
2017-04-03 00:29:02 +02:00
|
|
|
/* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */
|
|
|
|
|
|
|
|
#define LO_WDDELAY (1*CLK_TCK)
|
|
|
|
|
2017-05-03 00:03:26 +02:00
|
|
|
/* Fake value for MAC header length */
|
|
|
|
|
|
|
|
#define MAC_HDRLEN 9
|
|
|
|
|
2017-04-03 00:29:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* The lo_driver_s encapsulates all state information for a single hardware
|
|
|
|
* interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct lo_driver_s
|
|
|
|
{
|
|
|
|
bool lo_bifup; /* true:ifup false:ifdown */
|
2017-05-03 19:13:07 +02:00
|
|
|
bool lo_pending; /* True: TX poll pending */
|
2017-06-19 11:55:28 +02:00
|
|
|
uint8_t lo_panid[2]; /* Fake PAN ID for testing */
|
2017-04-03 00:29:02 +02:00
|
|
|
WDOG_ID lo_polldog; /* TX poll timer */
|
|
|
|
struct work_s lo_work; /* For deferring poll work to the work queue */
|
2017-05-03 17:40:42 +02:00
|
|
|
FAR struct iob_s *lo_head; /* Head of IOBs queued for loopback */
|
|
|
|
FAR struct iob_s *lo_tail; /* Tail of IOBs queued for loopback */
|
2017-04-03 00:29:02 +02:00
|
|
|
|
|
|
|
/* This holds the information visible to the NuttX network */
|
|
|
|
|
2017-08-19 16:48:52 +02:00
|
|
|
struct radio_driver_s lo_radio; /* Interface understood by the network */
|
2017-04-03 00:29:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static struct lo_driver_s g_loopback;
|
2017-08-20 19:14:43 +02:00
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
2017-08-26 18:00:47 +02:00
|
|
|
static struct sixlowpan_reassbuf_s g_iobuffer;
|
2017-08-20 19:14:43 +02:00
|
|
|
#endif
|
2017-04-03 00:29:02 +02:00
|
|
|
|
2017-06-19 11:55:28 +02:00
|
|
|
static uint8_t g_eaddr[IEEE802154_EADDRSIZE] =
|
2017-06-17 16:54:50 +02:00
|
|
|
{
|
2017-06-22 21:55:08 +02:00
|
|
|
0x0c, 0xfa, 0xde, 0x00, 0xde, 0xad, 0xbe, 0xef
|
2017-06-17 16:54:50 +02:00
|
|
|
};
|
|
|
|
|
2017-06-19 11:55:28 +02:00
|
|
|
static uint8_t g_saddr[IEEE802154_SADDRSIZE] =
|
|
|
|
{
|
2017-06-19 15:04:08 +02:00
|
|
|
0xab, 0xcd
|
2017-06-19 11:55:28 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static uint8_t g_panid[IEEE802154_PANIDSIZE] =
|
|
|
|
{
|
2017-06-19 15:04:08 +02:00
|
|
|
0xca, 0xfe
|
2017-06-19 11:55:28 +02:00
|
|
|
};
|
2017-06-17 16:54:50 +02:00
|
|
|
|
2017-04-03 00:29:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-06-18 23:26:56 +02:00
|
|
|
/* Utility functions */
|
2017-06-17 16:54:50 +02:00
|
|
|
|
|
|
|
static void lo_addr2ip(FAR struct net_driver_s *dev);
|
2017-06-18 23:26:56 +02:00
|
|
|
static inline void lo_netmask(FAR struct net_driver_s *dev);
|
2017-06-17 16:54:50 +02:00
|
|
|
|
2017-04-03 00:29:02 +02:00
|
|
|
/* Polling logic */
|
|
|
|
|
2017-05-03 00:03:26 +02:00
|
|
|
static int lo_loopback(FAR struct net_driver_s *dev);
|
|
|
|
static void lo_loopback_work(FAR void *arg);
|
2017-04-03 00:29:02 +02:00
|
|
|
static void lo_poll_work(FAR void *arg);
|
|
|
|
static void lo_poll_expiry(int argc, wdparm_t arg, ...);
|
|
|
|
|
|
|
|
/* NuttX callback functions */
|
|
|
|
|
2017-05-03 00:03:26 +02:00
|
|
|
static int lo_ifup(FAR struct net_driver_s *dev);
|
|
|
|
static int lo_ifdown(FAR struct net_driver_s *dev);
|
2017-04-03 00:29:02 +02:00
|
|
|
static void lo_txavail_work(FAR void *arg);
|
2017-05-03 00:03:26 +02:00
|
|
|
static int lo_txavail(FAR struct net_driver_s *dev);
|
2017-04-03 00:29:02 +02:00
|
|
|
#ifdef CONFIG_NET_IGMP
|
2017-07-31 15:28:42 +02:00
|
|
|
static int lo_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac);
|
2017-05-03 00:03:26 +02:00
|
|
|
static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac);
|
2017-04-03 00:29:02 +02:00
|
|
|
#endif
|
2017-04-22 00:23:40 +02:00
|
|
|
#ifdef CONFIG_NETDEV_IOCTL
|
|
|
|
static int lo_ioctl(FAR struct net_driver_s *dev, int cmd,
|
|
|
|
unsigned long arg);
|
|
|
|
#endif
|
2017-08-19 16:48:52 +02:00
|
|
|
static int lo_get_mhrlen(FAR struct radio_driver_s *netdev,
|
2017-07-31 03:10:51 +02:00
|
|
|
FAR const void *meta);
|
2017-08-19 16:48:52 +02:00
|
|
|
static int lo_req_data(FAR struct radio_driver_s *netdev,
|
2017-07-31 03:10:51 +02:00
|
|
|
FAR const void *meta, FAR struct iob_s *framelist);
|
2017-08-19 16:48:52 +02:00
|
|
|
static int lo_properties(FAR struct radio_driver_s *netdev,
|
2017-08-20 15:10:48 +02:00
|
|
|
FAR struct radiodev_properties_s *properties);
|
2017-04-03 00:29:02 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-06-17 16:54:50 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: lo_addr2ip
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Create a MAC-based IP address from the IEEE 802.15.14 short or extended
|
2017-06-18 23:26:56 +02:00
|
|
|
* address assigned to the node.
|
2017-06-17 16:54:50 +02:00
|
|
|
*
|
|
|
|
* 128 112 96 80 64 48 32 16
|
|
|
|
* ---- ---- ---- ---- ---- ---- ---- ----
|
|
|
|
* fe80 0000 0000 0000 0000 00ff fe00 xxxx 2-byte short address IEEE 48-bit MAC
|
|
|
|
* fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte extended address IEEE EUI-64
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
|
|
|
static void lo_addr2ip(FAR struct net_driver_s *dev)
|
|
|
|
{
|
2017-06-22 19:42:52 +02:00
|
|
|
/* Set the MAC address as the eaddr */
|
|
|
|
|
2017-08-20 19:14:43 +02:00
|
|
|
dev->d_mac.radio.nv_addrlen = IEEE802154_EADDRSIZE;
|
2017-08-19 16:48:52 +02:00
|
|
|
IEEE802154_EADDRCOPY(dev->d_mac.radio.nv_addr, g_eaddr);
|
2017-06-22 19:42:52 +02:00
|
|
|
|
2017-08-20 19:14:43 +02:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
2017-06-22 19:42:52 +02:00
|
|
|
/* Set the IP address based on the eaddr */
|
|
|
|
|
2017-06-17 16:54:50 +02:00
|
|
|
dev->d_ipv6addr[0] = HTONS(0xfe80);
|
|
|
|
dev->d_ipv6addr[1] = 0;
|
|
|
|
dev->d_ipv6addr[2] = 0;
|
|
|
|
dev->d_ipv6addr[3] = 0;
|
2017-06-23 17:44:36 +02:00
|
|
|
dev->d_ipv6addr[4] = (uint16_t)g_eaddr[0] << 8 | (uint16_t)g_eaddr[1];
|
|
|
|
dev->d_ipv6addr[5] = (uint16_t)g_eaddr[2] << 8 | (uint16_t)g_eaddr[3];
|
|
|
|
dev->d_ipv6addr[6] = (uint16_t)g_eaddr[4] << 8 | (uint16_t)g_eaddr[5];
|
2017-06-23 18:08:03 +02:00
|
|
|
dev->d_ipv6addr[7] = (uint16_t)g_eaddr[6] << 8 | (uint16_t)g_eaddr[7];
|
2017-06-18 23:26:56 +02:00
|
|
|
dev->d_ipv6addr[4] ^= 0x200;
|
2017-06-17 16:54:50 +02:00
|
|
|
}
|
2017-08-20 19:14:43 +02:00
|
|
|
#endif
|
2017-06-17 16:54:50 +02:00
|
|
|
#else
|
|
|
|
static void lo_addr2ip(FAR struct net_driver_s *dev)
|
|
|
|
{
|
2017-06-22 19:42:52 +02:00
|
|
|
/* Set the MAC address as the saddr */
|
|
|
|
|
2017-08-20 19:14:43 +02:00
|
|
|
dev->d_mac.radio.nv_addrlen = IEEE802154_SADDRSIZE;
|
2017-08-19 16:48:52 +02:00
|
|
|
IEEE802154_SADDRCOPY(dev->d_mac.radio.nv_addr, g_saddr);
|
2017-06-22 19:42:52 +02:00
|
|
|
|
2017-08-20 19:14:43 +02:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
2017-06-22 19:42:52 +02:00
|
|
|
/* Set the IP address based on the saddr */
|
|
|
|
|
2017-06-17 16:54:50 +02:00
|
|
|
dev->d_ipv6addr[0] = HTONS(0xfe80);
|
|
|
|
dev->d_ipv6addr[1] = 0;
|
|
|
|
dev->d_ipv6addr[2] = 0;
|
|
|
|
dev->d_ipv6addr[3] = 0;
|
|
|
|
dev->d_ipv6addr[4] = 0;
|
|
|
|
dev->d_ipv6addr[5] = HTONS(0x00ff);
|
2017-06-18 23:26:56 +02:00
|
|
|
dev->d_ipv6addr[6] = HTONS(0xfe00);
|
2017-06-23 17:44:36 +02:00
|
|
|
dev->d_ipv6addr[7] = (uint16_t)g_saddr[0] << 8 | (uint16_t)g_saddr[1];
|
2017-06-18 23:26:56 +02:00
|
|
|
dev->d_ipv6addr[7] ^= 0x200;
|
2017-08-20 19:14:43 +02:00
|
|
|
#endif
|
2017-06-17 16:54:50 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-06-18 23:26:56 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: lo_netmask
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Create a netmask of a MAC-based IP address which may be based on either
|
|
|
|
* the IEEE 802.15.14 short or extended address of the MAC.
|
|
|
|
*
|
|
|
|
* 128 112 96 80 64 48 32 16
|
|
|
|
* ---- ---- ---- ---- ---- ---- ---- ----
|
|
|
|
* fe80 0000 0000 0000 0000 00ff fe00 xxxx 2-byte short address IEEE 48-bit MAC
|
|
|
|
* fe80 0000 0000 0000 xxxx xxxx xxxx xxxx 8-byte extended address IEEE EUI-64
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void lo_netmask(FAR struct net_driver_s *dev)
|
|
|
|
{
|
2017-08-20 19:14:43 +02:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
2017-06-18 23:26:56 +02:00
|
|
|
dev->d_ipv6netmask[0] = 0xffff;
|
|
|
|
dev->d_ipv6netmask[1] = 0xffff;
|
|
|
|
dev->d_ipv6netmask[2] = 0xffff;
|
|
|
|
dev->d_ipv6netmask[3] = 0xffff;
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
|
|
|
dev->d_ipv6netmask[4] = 0;
|
|
|
|
dev->d_ipv6netmask[5] = 0;
|
|
|
|
dev->d_ipv6netmask[6] = 0;
|
|
|
|
dev->d_ipv6netmask[7] = 0;
|
|
|
|
#else
|
|
|
|
dev->d_ipv6netmask[4] = 0xffff;
|
|
|
|
dev->d_ipv6netmask[5] = 0xffff;
|
|
|
|
dev->d_ipv6netmask[6] = 0xffff;
|
|
|
|
dev->d_ipv6netmask[7] = 0;
|
|
|
|
#endif
|
2017-08-20 19:14:43 +02:00
|
|
|
#endif
|
2017-06-18 23:26:56 +02:00
|
|
|
}
|
|
|
|
|
2017-04-03 00:29:02 +02:00
|
|
|
/****************************************************************************
|
2017-05-03 00:03:26 +02:00
|
|
|
* Name: lo_loopback
|
2017-04-03 00:29:02 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check if the network has any outgoing packets ready to send. This is
|
|
|
|
* a callback from devif_poll() or devif_timer(). devif_poll() will be
|
|
|
|
* called only during normal TX polling.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-03 00:29:02 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; a negated errno on failure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* May or may not be called from an interrupt handler. In either case,
|
|
|
|
* the network is locked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-05-03 00:03:26 +02:00
|
|
|
static int lo_loopback(FAR struct net_driver_s *dev)
|
2017-04-03 00:29:02 +02:00
|
|
|
{
|
|
|
|
FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private;
|
2017-05-05 19:36:16 +02:00
|
|
|
struct ieee802154_data_ind_s ind;
|
2017-04-03 00:29:02 +02:00
|
|
|
FAR struct iob_s *iob;
|
|
|
|
int ret;
|
|
|
|
|
2017-06-22 21:55:08 +02:00
|
|
|
/* Create some fake metadata */
|
|
|
|
|
2017-05-05 19:36:16 +02:00
|
|
|
memset(&ind, 0, sizeof(struct ieee802154_data_ind_s));
|
|
|
|
|
2017-06-22 21:55:08 +02:00
|
|
|
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
|
|
|
ind.src.mode = IEEE802154_ADDRMODE_EXTENDED;
|
|
|
|
ind.dest.mode = IEEE802154_ADDRMODE_EXTENDED;
|
|
|
|
#else
|
|
|
|
ind.src.mode = IEEE802154_ADDRMODE_SHORT;
|
|
|
|
ind.dest.mode = IEEE802154_ADDRMODE_SHORT;
|
|
|
|
#endif
|
|
|
|
|
2017-06-25 02:29:07 +02:00
|
|
|
/* On loopback the local address is both the source and destination. */
|
2017-06-23 00:04:40 +02:00
|
|
|
|
2017-06-22 21:55:08 +02:00
|
|
|
IEEE802154_PANIDCOPY(ind.src.panid, g_panid);
|
2017-06-25 02:29:07 +02:00
|
|
|
IEEE802154_SADDRCOPY(ind.src.saddr, g_saddr);
|
|
|
|
IEEE802154_EADDRCOPY(ind.src.eaddr, g_eaddr);
|
2017-06-22 21:55:08 +02:00
|
|
|
|
|
|
|
IEEE802154_PANIDCOPY(ind.dest.panid, g_panid);
|
|
|
|
IEEE802154_SADDRCOPY(ind.dest.saddr, g_saddr);
|
|
|
|
IEEE802154_EADDRCOPY(ind.dest.eaddr, g_eaddr);
|
|
|
|
|
2017-05-03 19:13:07 +02:00
|
|
|
/* Loop while there framelist to be sent, i.e., while the freme list is not
|
2017-05-03 17:40:42 +02:00
|
|
|
* emtpy. Sending, of course, just means relaying back through the network
|
2017-04-03 00:29:02 +02:00
|
|
|
* for this driver.
|
|
|
|
*/
|
|
|
|
|
2017-05-03 17:40:42 +02:00
|
|
|
while (priv->lo_head != NULL)
|
2017-04-03 00:29:02 +02:00
|
|
|
{
|
2017-05-03 19:13:07 +02:00
|
|
|
ninfo("Looping frame IOB %p\n", iob);
|
|
|
|
|
2017-04-08 20:34:08 +02:00
|
|
|
/* Increment statistics */
|
2017-04-03 00:29:02 +02:00
|
|
|
|
2017-07-31 15:28:42 +02:00
|
|
|
NETDEV_RXPACKETS(&priv->lo_radio.r_dev);
|
2017-04-03 00:29:02 +02:00
|
|
|
|
2017-04-08 20:34:08 +02:00
|
|
|
/* Remove the IOB from the queue */
|
2017-04-03 00:29:02 +02:00
|
|
|
|
2017-05-03 17:40:42 +02:00
|
|
|
iob = priv->lo_head;
|
|
|
|
priv->lo_head = iob->io_flink;
|
2017-04-08 20:34:08 +02:00
|
|
|
iob->io_flink = NULL;
|
2017-04-03 00:29:02 +02:00
|
|
|
|
2017-05-03 17:40:42 +02:00
|
|
|
/* Did the framelist become empty? */
|
2017-04-03 00:29:02 +02:00
|
|
|
|
2017-05-03 17:40:42 +02:00
|
|
|
if (priv->lo_head == NULL)
|
2017-04-08 20:34:08 +02:00
|
|
|
{
|
2017-05-03 17:40:42 +02:00
|
|
|
priv->lo_tail = NULL;
|
2017-04-08 20:34:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the next frame to the network */
|
|
|
|
|
2017-05-03 17:40:42 +02:00
|
|
|
ninfo("Send frame %p to the network: Offset=%u Length=%u\n",
|
|
|
|
iob, iob->io_offset, iob->io_len);
|
2017-04-08 20:34:08 +02:00
|
|
|
|
2017-08-19 20:32:56 +02:00
|
|
|
#ifdef CONFIG_NET_IEEE802154
|
|
|
|
/* Invoke the PF_IEEE802154 tap first. If the frame matches
|
|
|
|
* with a connected PF_IEEE802145 socket, it will take the
|
|
|
|
* frame and return success.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret = ieee802154_input(&priv->lo_radio, iob, (FAR void *)&ind);
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
/* If PF_IEEE802154 was not interested in the frame, then
|
|
|
|
* give it to 6LoWPAN.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
{
|
2017-08-26 18:00:47 +02:00
|
|
|
/* Make sure the our single packet buffer is attached */
|
|
|
|
|
|
|
|
priv->lo_radio.r_dev.d_buf = g_iobuffer.rb_buf;
|
|
|
|
|
|
|
|
/* Then give the frame to 6LoWPAN */
|
|
|
|
|
2017-08-19 20:32:56 +02:00
|
|
|
ret = sixlowpan_input(&priv->lo_radio, iob, (FAR void *)&ind);
|
|
|
|
}
|
|
|
|
#endif
|
2017-04-08 20:34:08 +02:00
|
|
|
|
|
|
|
/* Increment statistics */
|
|
|
|
|
2017-07-31 15:28:42 +02:00
|
|
|
NETDEV_TXPACKETS(&priv->lo_radio.r_dev);
|
2017-04-03 00:29:02 +02:00
|
|
|
|
2017-04-08 20:34:08 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
nerr("ERROR: sixlowpan_input returned %d\n", ret);
|
2017-07-31 15:28:42 +02:00
|
|
|
NETDEV_TXERRORS(&priv->lo_radio.r_dev);
|
|
|
|
NETDEV_ERRORS(&priv->lo_radio.r_dev);
|
2017-04-08 20:34:08 +02:00
|
|
|
}
|
2017-04-03 00:29:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-05-03 00:03:26 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: lo_loopback_work
|
|
|
|
*
|
|
|
|
* Description:
|
2017-05-03 19:13:07 +02:00
|
|
|
* Perform loopback of received framelist.
|
2017-05-03 00:03:26 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-05-03 00:03:26 +02:00
|
|
|
* arg - The argument passed when work_queue() as called.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The network is locked
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void lo_loopback_work(FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)arg;
|
|
|
|
|
|
|
|
/* Perform the loopback */
|
|
|
|
|
|
|
|
net_lock();
|
2017-07-31 15:28:42 +02:00
|
|
|
(void)lo_loopback(&priv->lo_radio.r_dev);
|
2017-05-03 00:03:26 +02:00
|
|
|
net_unlock();
|
|
|
|
}
|
|
|
|
|
2017-04-03 00:29:02 +02:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: lo_poll_work
|
2017-04-03 00:29:02 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform periodic polling from the worker thread
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-03 00:29:02 +02:00
|
|
|
* arg - The argument passed when work_queue() as called.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The network is locked
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void lo_poll_work(FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)arg;
|
|
|
|
|
|
|
|
/* Perform the poll */
|
|
|
|
|
|
|
|
net_lock();
|
2017-08-26 18:00:47 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
/* Make sure the our single packet buffer is attached */
|
|
|
|
|
|
|
|
priv->lo_radio.r_dev.d_buf = g_iobuffer.rb_buf;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Then perform the poll */
|
|
|
|
|
2017-07-31 15:28:42 +02:00
|
|
|
(void)devif_timer(&priv->lo_radio.r_dev, lo_loopback);
|
2017-04-03 00:29:02 +02:00
|
|
|
|
|
|
|
/* Setup the watchdog poll timer again */
|
|
|
|
|
|
|
|
(void)wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry, 1, priv);
|
|
|
|
net_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: lo_poll_expiry
|
2017-04-03 00:29:02 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Periodic timer handler. Called from the timer interrupt handler.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-03 00:29:02 +02:00
|
|
|
* argc - The number of available arguments
|
|
|
|
* arg - The first argument
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The network is locked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void lo_poll_expiry(int argc, wdparm_t arg, ...)
|
|
|
|
{
|
|
|
|
FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)arg;
|
|
|
|
|
2017-05-03 19:13:07 +02:00
|
|
|
if (!work_available(&priv->lo_work) || priv->lo_head != NULL)
|
2017-04-03 20:01:04 +02:00
|
|
|
{
|
|
|
|
nwarn("WARNING: lo_work NOT available\n");
|
2017-05-03 19:13:07 +02:00
|
|
|
priv->lo_pending = true;
|
2017-04-03 20:01:04 +02:00
|
|
|
}
|
2017-05-03 19:13:07 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Schedule to perform the interrupt processing on the worker thread. */
|
2017-04-03 20:01:04 +02:00
|
|
|
|
2017-05-03 19:13:07 +02:00
|
|
|
priv->lo_pending = false;
|
|
|
|
work_queue(LPBKWORK, &priv->lo_work, lo_poll_work, priv, 0);
|
|
|
|
}
|
2017-04-03 00:29:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: lo_ifup
|
2017-04-03 00:29:02 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Bring up the Ethernet interface when an IP address is
|
|
|
|
* provided
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-03 00:29:02 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int lo_ifup(FAR struct net_driver_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private;
|
|
|
|
|
2017-08-20 19:14:43 +02:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
2017-04-03 20:01:04 +02:00
|
|
|
ninfo("Bringing up: IPv6 %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
2017-04-03 00:29:02 +02:00
|
|
|
dev->d_ipv6addr[0], dev->d_ipv6addr[1], dev->d_ipv6addr[2],
|
|
|
|
dev->d_ipv6addr[3], dev->d_ipv6addr[4], dev->d_ipv6addr[5],
|
2017-04-03 20:01:04 +02:00
|
|
|
dev->d_ipv6addr[6], dev->d_ipv6addr[7]);
|
2017-05-04 16:20:59 +02:00
|
|
|
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
2017-06-19 11:55:28 +02:00
|
|
|
ninfo(" Node: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x PANID=%02x:%02x\n",
|
2017-08-19 16:48:52 +02:00
|
|
|
dev->d_mac.radio.nv_addr[0], dev->d_mac.radio.nv_addr[1],
|
|
|
|
dev->d_mac.radio.nv_addr[2], dev->d_mac.radio.nv_addr[3],
|
|
|
|
dev->d_mac.radio.nv_addr[4], dev->d_mac.radio.nv_addr[5],
|
|
|
|
dev->d_mac.radio.nv_addr[6], dev->d_mac.radio.nv_addr[7],
|
2017-06-19 11:55:28 +02:00
|
|
|
priv->lo_panid[0], priv->lo_panid[1]);
|
2017-04-08 20:34:08 +02:00
|
|
|
#else
|
2017-06-19 11:55:28 +02:00
|
|
|
ninfo(" Node: %02x:%02x PANID=%02x:%02x\n",
|
2017-08-19 16:48:52 +02:00
|
|
|
dev->d_mac.radio.nv_addr[0], dev->d_mac.radio.nv_addr[1],
|
2017-06-19 11:55:28 +02:00
|
|
|
priv->lo_panid[0], priv->lo_panid[1]);
|
2017-04-03 00:29:02 +02:00
|
|
|
#endif
|
2017-08-20 19:14:43 +02:00
|
|
|
#else
|
|
|
|
if (dev->d_mac.radio.nv_addrlen == 8)
|
|
|
|
{
|
|
|
|
ninfo("Bringing up: Node: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x PANID=%02x:%02x\n",
|
|
|
|
dev->d_mac.radio.nv_addr[0], dev->d_mac.radio.nv_addr[1],
|
|
|
|
dev->d_mac.radio.nv_addr[2], dev->d_mac.radio.nv_addr[3],
|
|
|
|
dev->d_mac.radio.nv_addr[4], dev->d_mac.radio.nv_addr[5],
|
|
|
|
dev->d_mac.radio.nv_addr[6], dev->d_mac.radio.nv_addr[7],
|
|
|
|
priv->lo_panid[0], priv->lo_panid[1]);
|
|
|
|
}
|
|
|
|
else if (dev->d_mac.radio.nv_addrlen == 2)
|
|
|
|
{
|
|
|
|
ninfo("Bringing up: Node: %02x:%02x PANID=%02x:%02x\n",
|
|
|
|
dev->d_mac.radio.nv_addr[0], dev->d_mac.radio.nv_addr[1],
|
|
|
|
priv->lo_panid[0], priv->lo_panid[1]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nerr("ERROR: No address assigned\n");
|
|
|
|
}
|
|
|
|
#endif
|
2017-04-03 00:29:02 +02:00
|
|
|
|
|
|
|
/* Set and activate a timer process */
|
|
|
|
|
|
|
|
(void)wd_start(priv->lo_polldog, LO_WDDELAY, lo_poll_expiry,
|
|
|
|
1, (wdparm_t)priv);
|
|
|
|
|
|
|
|
priv->lo_bifup = true;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: lo_ifdown
|
2017-04-03 00:29:02 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Stop the interface.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-03 00:29:02 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int lo_ifdown(FAR struct net_driver_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private;
|
|
|
|
|
2017-04-03 20:01:04 +02:00
|
|
|
ninfo("IP up: %u\n", priv->lo_bifup);
|
|
|
|
|
2017-04-03 00:29:02 +02:00
|
|
|
/* Cancel the TX poll timer and TX timeout timers */
|
|
|
|
|
|
|
|
wd_cancel(priv->lo_polldog);
|
|
|
|
|
|
|
|
/* Mark the device "down" */
|
|
|
|
|
|
|
|
priv->lo_bifup = false;
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: lo_txavail_work
|
2017-04-03 00:29:02 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform an out-of-cycle poll on the worker thread.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-03 00:29:02 +02:00
|
|
|
* arg - Reference to the NuttX driver state structure (cast to void*)
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called on the higher priority worker thread.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void lo_txavail_work(FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)arg;
|
|
|
|
|
2017-05-03 19:13:07 +02:00
|
|
|
ninfo("TX available work. IP up: %u\n", priv->lo_bifup);
|
2017-04-03 20:01:04 +02:00
|
|
|
|
2017-04-03 00:29:02 +02:00
|
|
|
/* Ignore the notification if the interface is not yet up */
|
|
|
|
|
|
|
|
net_lock();
|
|
|
|
if (priv->lo_bifup)
|
|
|
|
{
|
2017-05-03 19:13:07 +02:00
|
|
|
/* If so, then poll the network for new XMIT data */
|
2017-04-03 00:29:02 +02:00
|
|
|
|
2017-08-26 18:00:47 +02:00
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
/* Make sure the our single packet buffer is attached */
|
|
|
|
|
|
|
|
priv->lo_radio.r_dev.d_buf = g_iobuffer.rb_buf;
|
|
|
|
#endif
|
|
|
|
|
2017-07-31 15:28:42 +02:00
|
|
|
(void)devif_poll(&priv->lo_radio.r_dev, lo_loopback);
|
2017-04-03 00:29:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
net_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: lo_txavail
|
2017-04-03 00:29:02 +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.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-03 00:29:02 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called in normal user mode
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int lo_txavail(FAR struct net_driver_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct lo_driver_s *priv = (FAR struct lo_driver_s *)dev->d_private;
|
|
|
|
|
2017-04-03 20:01:04 +02:00
|
|
|
ninfo("Available: %u\n", work_available(&priv->lo_work));
|
|
|
|
|
2017-04-03 00:29:02 +02:00
|
|
|
/* Is our single work structure available? It may not be if there are
|
2017-05-03 00:03:26 +02:00
|
|
|
* pending actions and we will have to ignore the Tx availability
|
|
|
|
* action.
|
2017-04-03 00:29:02 +02:00
|
|
|
*/
|
|
|
|
|
2017-05-03 19:13:07 +02:00
|
|
|
if (!work_available(&priv->lo_work) || priv->lo_head != NULL)
|
|
|
|
{
|
|
|
|
nwarn("WARNING: lo_work NOT available\n");
|
|
|
|
priv->lo_pending = true;
|
|
|
|
}
|
|
|
|
else
|
2017-04-03 00:29:02 +02:00
|
|
|
{
|
2017-05-03 19:13:07 +02:00
|
|
|
/* Schedule to perform the interrupt processing on the worker thread. */
|
2017-04-03 00:29:02 +02:00
|
|
|
|
2017-05-03 19:13:07 +02:00
|
|
|
priv->lo_pending = false;
|
2017-04-03 00:29:02 +02:00
|
|
|
work_queue(LPBKWORK, &priv->lo_work, lo_txavail_work, priv, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: lo_addmac
|
2017-04-03 00:29:02 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Add the specified MAC address to the hardware multicast
|
|
|
|
* address filtering
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-03 00:29:02 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
* mac - The MAC address to be added
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-07-31 15:28:42 +02:00
|
|
|
#ifdef CONFIG_NET_IGMP
|
2017-04-03 00:29:02 +02:00
|
|
|
static int lo_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac)
|
|
|
|
{
|
2017-05-04 16:20:59 +02:00
|
|
|
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
2017-04-03 20:01:04 +02:00
|
|
|
ninfo("MAC: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
|
|
|
|
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], mac[6], mac[7]);
|
2017-04-08 20:34:08 +02:00
|
|
|
#else
|
|
|
|
ninfo("MAC: %02x:%02x\n",
|
|
|
|
mac[0], mac[1]);
|
2017-04-03 20:01:04 +02:00
|
|
|
#endif
|
|
|
|
|
2017-04-03 00:29:02 +02:00
|
|
|
/* There is no multicast support in the loopback driver */
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: lo_rmmac
|
2017-04-03 00:29:02 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Remove the specified MAC address from the hardware multicast
|
|
|
|
* address filtering
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-03 00:29:02 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
* mac - The MAC address to be removed
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IGMP
|
|
|
|
static int lo_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac)
|
|
|
|
{
|
2017-05-04 16:20:59 +02:00
|
|
|
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
2017-04-03 20:01:04 +02:00
|
|
|
ninfo("MAC: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
|
|
|
|
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5], mac[6], mac[7]);
|
2017-04-08 20:34:08 +02:00
|
|
|
#else
|
|
|
|
ninfo("MAC: %02x:%02x\n",
|
|
|
|
mac[0], mac[1]);
|
2017-04-03 20:01:04 +02:00
|
|
|
#endif
|
|
|
|
|
2017-04-03 00:29:02 +02:00
|
|
|
/* There is no multicast support in the loopback driver */
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-04-22 00:23:40 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: macnet_ioctl
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Handle network IOCTL commands directed to this device.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-22 00:23:40 +02:00
|
|
|
* 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 lo_ioctl(FAR struct net_driver_s *dev, int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
2017-06-17 16:54:50 +02:00
|
|
|
FAR struct lo_driver_s *priv;
|
|
|
|
|
|
|
|
DEBUGASSERT(dev != NULL && dev->d_private != NULL);
|
|
|
|
priv = (FAR struct lo_driver_s *)dev->d_private;
|
|
|
|
|
|
|
|
UNUSED(priv);
|
2017-04-22 00:23:40 +02:00
|
|
|
|
|
|
|
/* 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;
|
2017-06-17 16:54:50 +02:00
|
|
|
|
|
|
|
DEBUGASSERT(netmac != NULL);
|
|
|
|
|
|
|
|
if (cmd == MAC802154IOC_MLME_SET_REQUEST)
|
|
|
|
{
|
|
|
|
FAR struct ieee802154_set_req_s *setreq = &netmac->u.setreq;
|
|
|
|
|
|
|
|
switch (setreq->attr)
|
|
|
|
{
|
|
|
|
case IEEE802154_ATTR_MAC_PANID:
|
2017-06-19 11:55:28 +02:00
|
|
|
IEEE802154_PANIDCOPY(g_panid, setreq->attrval.mac.panid);
|
2017-06-17 16:54:50 +02:00
|
|
|
break;
|
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
case IEEE802154_ATTR_MAC_EADDR:
|
2017-06-19 11:55:28 +02:00
|
|
|
IEEE802154_EADDRCOPY(g_eaddr, setreq->attrval.mac.eaddr);
|
2017-06-17 16:54:50 +02:00
|
|
|
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
|
|
|
lo_addr2ip(dev);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
case IEEE802154_ATTR_MAC_SADDR:
|
2017-06-19 11:55:28 +02:00
|
|
|
IEEE802154_SADDRCOPY(g_saddr, setreq->attrval.mac.saddr);
|
2017-06-17 16:54:50 +02:00
|
|
|
#ifndef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
|
|
|
lo_addr2ip(dev);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
else if (cmd == MAC802154IOC_MLME_GET_REQUEST)
|
|
|
|
{
|
|
|
|
FAR struct ieee802154_get_req_s *getreq = &netmac->u.getreq;
|
2017-06-17 17:04:09 +02:00
|
|
|
|
2017-06-17 16:54:50 +02:00
|
|
|
switch (getreq->attr)
|
|
|
|
{
|
|
|
|
case IEEE802154_ATTR_MAC_PANID:
|
2017-06-19 11:55:28 +02:00
|
|
|
IEEE802154_PANIDCOPY(getreq->attrval.mac.panid, g_panid);
|
2017-06-17 16:54:50 +02:00
|
|
|
break;
|
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
case IEEE802154_ATTR_MAC_EADDR:
|
2017-06-19 11:55:28 +02:00
|
|
|
IEEE802154_EADDRCOPY(getreq->attrval.mac.eaddr, g_eaddr);
|
2017-06-17 16:54:50 +02:00
|
|
|
break;
|
|
|
|
|
2017-06-26 00:07:50 +02:00
|
|
|
case IEEE802154_ATTR_MAC_SADDR:
|
2017-06-19 11:55:28 +02:00
|
|
|
IEEE802154_SADDRCOPY(getreq->attrval.mac.saddr, g_saddr);
|
2017-06-17 16:54:50 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Not a supported IEEE 802.15.4 MAC IOCTL command */
|
|
|
|
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
2017-04-22 00:23:40 +02:00
|
|
|
}
|
|
|
|
else
|
2017-05-05 18:00:18 +02:00
|
|
|
{
|
|
|
|
/* Not a valid IEEE 802.15.4 MAC IOCTL command */
|
|
|
|
|
|
|
|
return -ENOTTY;
|
|
|
|
}
|
2017-04-22 00:23:40 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-05-03 00:03:26 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: lo_get_mhrlen
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Calculate the MAC header length given the frame meta-data.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2018-03-31 01:43:58 +02:00
|
|
|
* netdev - The network device that will mediate the MAC interface
|
2017-07-31 03:10:51 +02:00
|
|
|
* meta - Obfuscated metadata structure needed to create the radio
|
|
|
|
* MAC header
|
2017-05-03 19:13:07 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2018-03-31 01:43:58 +02:00
|
|
|
* A non-negative MAC header length is returned on success; a negated
|
2017-05-03 19:13:07 +02:00
|
|
|
* errno value is returned on any failure.
|
|
|
|
*
|
2017-05-03 00:03:26 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-08-19 16:48:52 +02:00
|
|
|
static int lo_get_mhrlen(FAR struct radio_driver_s *netdev,
|
2017-07-31 03:10:51 +02:00
|
|
|
FAR const void *meta)
|
2017-05-03 00:03:26 +02:00
|
|
|
{
|
|
|
|
return MAC_HDRLEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: lo_req_data
|
|
|
|
*
|
|
|
|
* Description:
|
2017-05-03 19:13:07 +02:00
|
|
|
* Requests the transfer of a list of frames to the MAC.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2018-03-31 01:43:58 +02:00
|
|
|
* netdev - The network device that will mediate the MAC interface
|
2017-07-31 03:10:51 +02:00
|
|
|
* meta - Obfuscated metadata structure needed to create the radio
|
|
|
|
* MAC header
|
2017-05-03 19:13:07 +02:00
|
|
|
* 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
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-08-19 16:48:52 +02:00
|
|
|
static int lo_req_data(FAR struct radio_driver_s *netdev,
|
2017-07-31 03:10:51 +02:00
|
|
|
FAR const void *meta, FAR struct iob_s *framelist)
|
2017-05-03 00:03:26 +02:00
|
|
|
{
|
|
|
|
FAR struct lo_driver_s *priv;
|
|
|
|
FAR struct iob_s *iob;
|
|
|
|
|
2017-07-31 03:10:51 +02:00
|
|
|
DEBUGASSERT(netdev != NULL && netdev->r_dev.d_private != NULL);
|
2017-07-29 21:42:26 +02:00
|
|
|
priv = (FAR struct lo_driver_s *)netdev->r_dev.d_private;
|
2017-05-03 00:03:26 +02:00
|
|
|
|
2017-07-31 03:10:51 +02:00
|
|
|
DEBUGASSERT(meta != NULL && framelist != NULL);
|
|
|
|
|
2017-05-03 19:13:07 +02:00
|
|
|
/* Add the incoming list of framelist to queue of framelist to loopback */
|
2017-05-03 00:03:26 +02:00
|
|
|
|
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 */
|
|
|
|
|
2017-07-31 15:28:42 +02:00
|
|
|
NETDEV_RXPACKETS(&priv->lo_radio.r_dev);
|
2017-05-03 00:03:26 +02:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2017-05-03 19:13:07 +02:00
|
|
|
ninfo("Queuing frame IOB %p\n", iob);
|
|
|
|
|
2017-05-03 00:03:26 +02:00
|
|
|
/* Just zero the MAC header for test purposes */
|
|
|
|
|
|
|
|
DEBUGASSERT(iob->io_offset == MAC_HDRLEN);
|
|
|
|
memset(iob->io_data, 0, MAC_HDRLEN);
|
|
|
|
|
2017-05-03 19:13:07 +02:00
|
|
|
/* Add the IOB to the tail of the queue of framelist to be looped back */
|
2017-05-03 00:03:26 +02:00
|
|
|
|
2017-05-03 17:40:42 +02:00
|
|
|
if (priv->lo_tail == NULL)
|
2017-05-03 00:03:26 +02:00
|
|
|
{
|
2017-05-03 17:40:42 +02:00
|
|
|
priv->lo_head = iob;
|
2017-05-03 00:03:26 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-03 17:40:42 +02:00
|
|
|
priv->lo_tail->io_flink = iob;
|
2017-05-03 00:03:26 +02:00
|
|
|
}
|
|
|
|
|
2017-05-03 17:40:42 +02:00
|
|
|
priv->lo_tail = iob;
|
2017-05-03 00:03:26 +02:00
|
|
|
}
|
|
|
|
|
2017-05-03 19:13:07 +02:00
|
|
|
/* Schedule to serialize the poll on the worker thread. */
|
2017-05-03 00:03:26 +02:00
|
|
|
|
2017-05-03 19:13:07 +02:00
|
|
|
work_queue(LPBKWORK, &priv->lo_work, lo_loopback_work, priv, 0);
|
2017-05-03 00:03:26 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-07-31 03:10:51 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: lo_properties
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Different packet radios may have different properties. If there are
|
|
|
|
* multiple packet radios, then those properties have to be queried at
|
|
|
|
* run time. This information is provided to the 6LoWPAN network via the
|
|
|
|
* following structure.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2017-07-31 03:10:51 +02:00
|
|
|
* netdev - The network device to be queried
|
2018-03-31 01:43:58 +02:00
|
|
|
* properties - Location where radio properties will be returned.
|
2017-07-31 03:10:51 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) returned on success; a negated errno value is returned on
|
|
|
|
* any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-08-19 16:48:52 +02:00
|
|
|
static int lo_properties(FAR struct radio_driver_s *netdev,
|
2017-08-20 15:10:48 +02:00
|
|
|
FAR struct radiodev_properties_s *properties)
|
2017-07-31 03:10:51 +02:00
|
|
|
{
|
|
|
|
DEBUGASSERT(netdev != NULL && properties != NULL);
|
2017-08-20 15:10:48 +02:00
|
|
|
memset(properties, 0, sizeof(struct radiodev_properties_s));
|
2017-08-04 18:58:29 +02:00
|
|
|
|
|
|
|
/* General */
|
2017-07-31 03:10:51 +02:00
|
|
|
|
2017-09-10 18:13:33 +02:00
|
|
|
properties->sp_addrlen = LO_ADDRSIZE; /* Length of an address */
|
|
|
|
properties->sp_framelen = LO_FRAMELEN; /* Fixed frame length */
|
2017-08-04 18:58:29 +02:00
|
|
|
|
|
|
|
/* Multicast address (uses broadcast address)
|
|
|
|
*
|
2017-08-06 21:50:48 +02:00
|
|
|
* For meshes (only) a multicast address candetermined by the first 3 bits
|
|
|
|
* of a short address (RFC 4944):
|
2017-08-04 18:58:29 +02:00
|
|
|
*
|
2017-08-06 21:50:48 +02:00
|
|
|
* 0xxxxxxx xxxxxxxx: Unicast address
|
|
|
|
* 100xxxxx xxxxxxxx: Multicast address
|
|
|
|
* 101xxxxx xxxxxxxx: Reserved
|
|
|
|
* 110xxxxx xxxxxxxx: Reserved
|
|
|
|
* 111xxxxx xxxxxxxx: Reserved
|
|
|
|
*
|
|
|
|
* Otherwise, Multicast is implemented with the broadcast address
|
|
|
|
* (qualified by the destination PANID).
|
2017-08-04 18:58:29 +02:00
|
|
|
*/
|
|
|
|
|
2017-08-20 19:14:43 +02:00
|
|
|
properties->sp_mcast.nv_addrlen = IEEE802154_SADDRSIZE;
|
2017-08-04 18:58:29 +02:00
|
|
|
memset(properties->sp_mcast.nv_addr, 0xff, RADIO_MAX_ADDRLEN);
|
|
|
|
|
|
|
|
/* Broadcast address */
|
|
|
|
|
2017-08-20 19:14:43 +02:00
|
|
|
properties->sp_bcast.nv_addrlen = IEEE802154_SADDRSIZE;
|
2017-08-04 18:58:29 +02:00
|
|
|
memset(properties->sp_mcast.nv_addr, 0xff, RADIO_MAX_ADDRLEN);
|
2017-08-05 17:13:29 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_STARPOINT
|
|
|
|
/* Star hub node address -- Not supported*/
|
|
|
|
#endif
|
|
|
|
|
2017-07-31 03:10:51 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-04-03 00:29:02 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: ieee8021514_loopback
|
2017-04-03 00:29:02 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-04-03 17:15:00 +02:00
|
|
|
* Initialize and register the Ieee802.15.4 MAC loopback network driver.
|
2017-04-03 00:29:02 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-03 17:15:00 +02:00
|
|
|
* None
|
2017-04-03 00:29:02 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; Negated errno on failure.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-03 17:15:00 +02:00
|
|
|
int ieee8021514_loopback(void)
|
2017-04-03 00:29:02 +02:00
|
|
|
{
|
2017-05-03 00:03:26 +02:00
|
|
|
FAR struct lo_driver_s *priv;
|
2017-08-19 16:48:52 +02:00
|
|
|
FAR struct radio_driver_s *radio;
|
2017-04-03 00:29:02 +02:00
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
|
2017-04-03 20:01:04 +02:00
|
|
|
ninfo("Initializing\n");
|
|
|
|
|
2017-04-03 00:29:02 +02:00
|
|
|
/* Get the interface structure associated with this interface number. */
|
|
|
|
|
|
|
|
priv = &g_loopback;
|
|
|
|
|
|
|
|
/* Initialize the driver structure */
|
|
|
|
|
|
|
|
memset(priv, 0, sizeof(struct lo_driver_s));
|
|
|
|
|
2017-07-31 15:28:42 +02:00
|
|
|
radio = &priv->lo_radio;
|
2017-07-29 21:42:26 +02:00
|
|
|
dev = &radio->r_dev;
|
|
|
|
dev->d_ifup = lo_ifup; /* I/F up (new IP address) callback */
|
|
|
|
dev->d_ifdown = lo_ifdown; /* I/F down callback */
|
|
|
|
dev->d_txavail = lo_txavail; /* New TX data callback */
|
2017-04-03 00:29:02 +02:00
|
|
|
#ifdef CONFIG_NET_IGMP
|
2017-07-29 21:42:26 +02:00
|
|
|
dev->d_addmac = lo_addmac; /* Add multicast MAC address */
|
|
|
|
dev->d_rmmac = lo_rmmac; /* Remove multicast MAC address */
|
2017-04-22 00:23:40 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NETDEV_IOCTL
|
2017-07-29 21:42:26 +02:00
|
|
|
dev->d_ioctl = lo_ioctl; /* Handle network IOCTL commands */
|
2017-08-20 19:14:43 +02:00
|
|
|
#endif
|
2017-07-29 21:42:26 +02:00
|
|
|
dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */
|
2017-04-03 00:29:02 +02:00
|
|
|
|
2017-06-18 23:26:56 +02:00
|
|
|
/* Set the network mask and advertise our MAC-based IP address */
|
2017-06-17 16:54:50 +02:00
|
|
|
|
2017-06-18 23:26:56 +02:00
|
|
|
lo_netmask(dev);
|
2017-06-17 16:54:50 +02:00
|
|
|
lo_addr2ip(dev);
|
|
|
|
|
2017-05-03 00:03:26 +02:00
|
|
|
/* Initialize the Network frame-related callbacks */
|
|
|
|
|
2017-07-29 21:42:26 +02:00
|
|
|
radio->r_get_mhrlen = lo_get_mhrlen; /* Get MAC header length */
|
|
|
|
radio->r_req_data = lo_req_data; /* Enqueue frame for transmission */
|
2017-07-31 03:10:51 +02:00
|
|
|
radio->r_properties = lo_properties; /* Returns radio properties */
|
2017-05-03 00:03:26 +02:00
|
|
|
|
|
|
|
/* Create a watchdog for timing polling for and timing of transmissions */
|
2017-04-29 16:23:59 +02:00
|
|
|
|
2017-07-29 21:42:26 +02:00
|
|
|
priv->lo_polldog = wd_create(); /* Create periodic poll timer */
|
2017-04-29 16:23:59 +02:00
|
|
|
|
2017-05-03 19:13:07 +02:00
|
|
|
/* Register the loopabck device with the OS so that socket IOCTLs can be
|
2017-04-03 00:29:02 +02:00
|
|
|
* performed.
|
|
|
|
*/
|
|
|
|
|
2017-07-31 15:28:42 +02:00
|
|
|
(void)netdev_register(&priv->lo_radio.r_dev, NET_LL_IEEE802154);
|
2017-04-03 00:29:02 +02:00
|
|
|
|
|
|
|
/* Put the network in the UP state */
|
|
|
|
|
|
|
|
dev->d_flags = IFF_UP;
|
2017-07-31 15:28:42 +02:00
|
|
|
return lo_ifup(&priv->lo_radio.r_dev);
|
2017-04-03 00:29:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_IEEE802154_LOOPBACK */
|