2017-04-08 22:21:20 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* wireless/ieee802154/mac802154_netdev.c
|
|
|
|
*
|
2024-09-11 09:04:25 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-19 09:38:00 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
2021-02-19 09:38:00 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
2021-02-19 09:38:00 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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>
|
2017-05-07 16:47:48 +02:00
|
|
|
#include <nuttx/kmalloc.h>
|
2017-10-07 18:57:09 +02:00
|
|
|
#include <nuttx/signal.h>
|
2017-04-08 22:21:20 +02:00
|
|
|
#include <nuttx/wqueue.h>
|
2022-09-06 08:18:45 +02:00
|
|
|
#include <nuttx/mutex.h>
|
2017-05-09 15:34:59 +02:00
|
|
|
#include <nuttx/mm/iob.h>
|
2017-04-08 22:21:20 +02:00
|
|
|
#include <nuttx/net/netdev.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-08 22:21:20 +02:00
|
|
|
#include <nuttx/net/sixlowpan.h>
|
2017-05-07 16:47:48 +02:00
|
|
|
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2017-04-14 19:24:40 +02:00
|
|
|
#include "mac802154.h"
|
|
|
|
|
2017-08-20 19:14:43 +02:00
|
|
|
#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_IEEE802154)
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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)
|
2018-11-21 14:57:26 +01:00
|
|
|
#endif
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2018-11-21 14:57:26 +01:00
|
|
|
/* The low priority work queue is preferred. If it is not enabled, LPWORK
|
|
|
|
* will be the same as HPWORK.
|
|
|
|
*
|
|
|
|
* NOTE: However, the network should NEVER run on the high priority work
|
|
|
|
* queue! That queue is intended only to service short back end interrupt
|
|
|
|
* processing that never suspends. Suspending the high priority work queue
|
|
|
|
* may bring the system to its knees!
|
|
|
|
*/
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2018-11-21 14:57:26 +01:00
|
|
|
#define WPANWORK LPWORK
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2020-04-23 11:51:21 +02:00
|
|
|
/* CONFIG_IEEE802154_NETDEV_NINTERFACES determines the number of physical
|
|
|
|
* interfaces that will be supported.
|
2017-04-08 22:21:20 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_IEEE802154_NETDEV_NINTERFACES
|
2023-05-20 00:32:34 +02:00
|
|
|
# define CONFIG_IEEE802154_NETDEV_NINTERFACES 1
|
2017-04-08 22:21:20 +02:00
|
|
|
#endif
|
|
|
|
|
2017-08-20 19:14:43 +02:00
|
|
|
/* Preferred address size */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
|
|
|
# define MACNET_ADDRSIZE IEEE802154_EADDRSIZE
|
|
|
|
#else
|
|
|
|
# define MACNET_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 MACNET_FRAMELEN CONFIG_NET_IEEE802154_FRAMELEN
|
|
|
|
#else
|
|
|
|
# define MACNET_FRAMELEN IEEE802154_MAX_PHY_PACKET_SIZE
|
|
|
|
#endif
|
|
|
|
|
2019-08-16 03:28:26 +02:00
|
|
|
#if (CONFIG_MAC802154_NTXDESC < CONFIG_IOB_NBUFFERS)
|
2019-08-19 17:17:01 +02:00
|
|
|
# warning "CONFIG_MAC802154_NTXDESC should probably be equal to" \
|
|
|
|
"CONFIG_IOB_NBUFFERS to avoid waiting on req_data"
|
2019-08-16 03:28:26 +02:00
|
|
|
#endif
|
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-03-31 18:37:34 +02:00
|
|
|
/* This is our private version of the MAC callback structure */
|
2017-04-13 20:17:36 +02:00
|
|
|
|
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 */
|
|
|
|
|
2017-06-18 19:00:47 +02:00
|
|
|
struct mac802154_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-11-01 21:15:21 +01:00
|
|
|
struct radio_driver_s md_dev; /* Interface understood by the network */
|
|
|
|
/* Cast compatible with struct macnet_driver_s */
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
/* For internal use by this driver */
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
mutex_t md_lock; /* Exclusive access to struct */
|
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 */
|
|
|
|
struct work_s md_pollwork; /* Defer poll work to the work queue */
|
2017-09-15 16:04:38 +02:00
|
|
|
|
|
|
|
/* Hold a list of events */
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
bool md_enableevents : 1; /* Are events enabled? */
|
|
|
|
bool md_eventpending : 1; /* Is there a get event using the semaphore? */
|
|
|
|
sem_t md_eventsem; /* Signaling semaphore for waiting get event */
|
|
|
|
sq_queue_t primitive_queue; /* For holding primitives to pass along */
|
2017-09-15 16:04:38 +02:00
|
|
|
|
|
|
|
/* MAC Service notification information */
|
|
|
|
|
|
|
|
bool md_notify_registered;
|
|
|
|
pid_t md_notify_pid;
|
2019-01-27 15:53:12 +01:00
|
|
|
struct sigevent md_notify_event;
|
2019-01-27 16:28:59 +01:00
|
|
|
struct sigwork_s md_notify_work;
|
2019-08-10 19:51:05 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
struct sixlowpan_reassbuf_s md_iobuffer;
|
|
|
|
#endif
|
2017-04-08 22:21:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-06-18 23:26:56 +02:00
|
|
|
/* Utility functions ********************************************************/
|
|
|
|
|
2019-08-10 19:02:26 +02:00
|
|
|
static int macnet_update_nvaddr(FAR struct net_driver_s *dev);
|
2017-06-18 23:26:56 +02:00
|
|
|
static inline void macnet_netmask(FAR struct net_driver_s *dev);
|
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
/* IEE802.15.4 MAC callback functions ***************************************/
|
2017-04-19 17:30:39 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
static int macnet_notify(FAR struct mac802154_maccb_s *maccb,
|
|
|
|
FAR struct ieee802154_primitive_s *primitive);
|
|
|
|
static int macnet_rxframe(FAR struct macnet_driver_s *maccb,
|
2017-05-16 03:44:51 +02:00
|
|
|
FAR struct ieee802154_data_ind_s *ind);
|
2017-04-19 17:30:39 +02:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
/* Network interface support ************************************************/
|
2019-12-24 17:37:30 +01:00
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
/* Common TX logic */
|
|
|
|
|
2017-05-07 16:47:48 +02:00
|
|
|
static int macnet_txpoll_callback(FAR struct net_driver_s *dev);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2017-08-05 17:13:29 +02:00
|
|
|
/* IOCTL support */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_STARPOINT
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
2017-08-19 16:48:52 +02:00
|
|
|
static int macnet_coord_eaddr(FAR struct radio_driver_s *radio,
|
2017-08-05 18:18:34 +02:00
|
|
|
FAR uint8_t *eaddr);
|
2017-08-05 17:13:29 +02:00
|
|
|
#else
|
2017-08-19 16:48:52 +02:00
|
|
|
static int macnet_coord_saddr(FAR struct radio_driver_s *radio,
|
2017-08-05 18:18:34 +02:00
|
|
|
FAR uint8_t *saddr);
|
2017-08-05 18:09:09 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
2017-08-05 17:13:29 +02:00
|
|
|
|
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
|
|
|
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
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-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
|
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-08-19 16:48:52 +02:00
|
|
|
static int macnet_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 macnet_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 macnet_properties(FAR struct radio_driver_s *netdev,
|
2017-08-20 15:10:48 +02:00
|
|
|
FAR struct radiodev_properties_s *properties);
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2017-08-26 18:00:47 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-06-18 23:26:56 +02:00
|
|
|
/****************************************************************************
|
2019-08-10 19:02:26 +02:00
|
|
|
* Name: macnet_update_nvaddr
|
2017-06-18 23:26:56 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Advertise the MAC and IPv6 address for this node.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-08-10 19:02:26 +02:00
|
|
|
static int macnet_update_nvaddr(FAR struct net_driver_s *dev)
|
2017-06-18 23:26:56 +02:00
|
|
|
{
|
2017-08-05 18:09:09 +02:00
|
|
|
FAR struct macnet_driver_s *priv;
|
|
|
|
union ieee802154_macarg_u arg;
|
2017-06-18 23:26:56 +02:00
|
|
|
int ret;
|
|
|
|
|
2017-08-05 18:09:09 +02:00
|
|
|
DEBUGASSERT(dev != NULL && dev->d_private != NULL);
|
|
|
|
priv = (FAR struct macnet_driver_s *)dev->d_private;
|
|
|
|
|
2019-08-10 19:02:26 +02:00
|
|
|
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
|
|
|
|
2017-06-18 23:26:56 +02:00
|
|
|
/* Get the eaddr from the MAC */
|
|
|
|
|
2017-08-05 17:13:29 +02:00
|
|
|
arg.getreq.attr = IEEE802154_ATTR_MAC_EADDR;
|
2017-08-05 18:09:09 +02:00
|
|
|
ret = mac802154_ioctl(priv->md_mac, MAC802154IOC_MLME_GET_REQUEST,
|
|
|
|
(unsigned long)((uintptr_t)&arg));
|
2017-06-18 23:26:56 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
wlerr("ERROR: MAC802154IOC_MLME_GET_REQUEST failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-23 11:51:21 +02:00
|
|
|
IEEE802154_EADDRCOPY(dev->d_mac.radio.nv_addr,
|
|
|
|
arg.getreq.attrval.mac.eaddr);
|
2017-08-20 19:14:43 +02:00
|
|
|
dev->d_mac.radio.nv_addrlen = IEEE802154_EADDRSIZE;
|
2017-06-18 23:26:56 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
2017-06-19 15:31:52 +02:00
|
|
|
uint8_t *saddr;
|
|
|
|
|
2017-06-18 23:26:56 +02:00
|
|
|
/* Get the saddr from the MAC */
|
|
|
|
|
2017-08-05 17:13:29 +02:00
|
|
|
arg.getreq.attr = IEEE802154_ATTR_MAC_SADDR;
|
2017-08-05 18:09:09 +02:00
|
|
|
ret = mac802154_ioctl(priv->md_mac, MAC802154IOC_MLME_GET_REQUEST,
|
|
|
|
(unsigned long)((uintptr_t)&arg));
|
2017-06-18 23:26:56 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
wlerr("ERROR: MAC802154IOC_MLME_GET_REQUEST failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-22 19:42:52 +02:00
|
|
|
/* Set the MAC address as the saddr */
|
|
|
|
|
2017-08-05 17:13:29 +02:00
|
|
|
saddr = arg.getreq.attrval.mac.saddr;
|
2018-12-18 16:06:41 +01:00
|
|
|
|
|
|
|
/* Network layers expect address in Network Order (Big Endian) */
|
|
|
|
|
|
|
|
dev->d_mac.radio.nv_addr[0] = saddr[1];
|
|
|
|
dev->d_mac.radio.nv_addr[1] = saddr[0];
|
|
|
|
|
2017-08-20 19:14:43 +02:00
|
|
|
dev->d_mac.radio.nv_addrlen = IEEE802154_SADDRSIZE;
|
2017-06-18 23:26:56 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: macnet_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
|
|
|
|
* ---- ---- ---- ---- ---- ---- ---- ----
|
2020-04-23 11:51:21 +02:00
|
|
|
* 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
|
2017-06-18 23:26:56 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static inline void macnet_netmask(FAR struct net_driver_s *dev)
|
|
|
|
{
|
|
|
|
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-04-19 17:53:32 +02:00
|
|
|
/****************************************************************************
|
2017-05-16 03:44:51 +02:00
|
|
|
* Name: macnet_notify
|
2017-04-19 17:53:32 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
static int macnet_notify(FAR struct mac802154_maccb_s *maccb,
|
|
|
|
FAR struct ieee802154_primitive_s *primitive)
|
2017-04-19 17:30:39 +02:00
|
|
|
{
|
2017-05-07 16:47:48 +02:00
|
|
|
FAR struct macnet_callback_s *cb =
|
|
|
|
(FAR struct macnet_callback_s *)maccb;
|
2017-04-19 17:30:39 +02:00
|
|
|
FAR struct macnet_driver_s *priv;
|
|
|
|
|
|
|
|
DEBUGASSERT(cb != NULL && cb->mc_priv != NULL);
|
|
|
|
priv = cb->mc_priv;
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
/* Handle the special case for data indications or "incoming frames" */
|
2017-09-15 16:04:38 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
if (primitive->type == IEEE802154_PRIMITIVE_IND_DATA)
|
|
|
|
{
|
|
|
|
return macnet_rxframe(priv, &primitive->u.dataind);
|
|
|
|
}
|
2017-09-15 16:04:38 +02:00
|
|
|
|
2020-04-23 11:51:21 +02:00
|
|
|
/* If there is a registered notification receiver, queue the event and
|
|
|
|
* signal the receiver. Events should be popped from the queue from the
|
|
|
|
* application at a reasonable rate in order for the MAC layer to be able
|
|
|
|
* to allocate new notifications.
|
2017-09-15 16:04:38 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (priv->md_enableevents)
|
2017-04-19 17:30:39 +02:00
|
|
|
{
|
2020-04-23 11:51:21 +02:00
|
|
|
/* Get exclusive access to the driver structure.
|
|
|
|
* We don't care about any signals so if we see one, just go
|
|
|
|
* back to trying to get access again
|
2017-11-01 21:15:21 +01:00
|
|
|
*/
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
while (nxmutex_lock(&priv->md_lock) < 0);
|
2017-11-01 21:15:21 +01:00
|
|
|
|
|
|
|
sq_addlast((FAR sq_entry_t *)primitive, &priv->primitive_queue);
|
2017-09-15 16:04:38 +02:00
|
|
|
|
|
|
|
/* Check if there is a read waiting for data */
|
|
|
|
|
|
|
|
if (priv->md_eventpending)
|
2017-05-16 03:44:51 +02:00
|
|
|
{
|
2017-09-15 16:04:38 +02:00
|
|
|
/* Wake the thread waiting for the data transmission */
|
|
|
|
|
|
|
|
priv->md_eventpending = false;
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_post(&priv->md_eventsem);
|
2017-05-16 03:44:51 +02:00
|
|
|
}
|
2017-04-19 17:30:39 +02:00
|
|
|
|
2017-09-15 16:04:38 +02:00
|
|
|
if (priv->md_notify_registered)
|
|
|
|
{
|
2019-01-27 15:53:12 +01:00
|
|
|
priv->md_notify_event.sigev_value.sival_int = primitive->type;
|
|
|
|
nxsig_notification(priv->md_notify_pid, &priv->md_notify_event,
|
2019-01-27 16:28:59 +01:00
|
|
|
SI_QUEUE, &priv->md_notify_work);
|
2017-09-15 16:04:38 +02:00
|
|
|
}
|
2017-11-03 16:24:16 +01:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->md_lock);
|
2017-11-03 17:08:17 +01:00
|
|
|
return OK;
|
2017-09-15 16:04:38 +02:00
|
|
|
}
|
2017-06-18 21:33:07 +02:00
|
|
|
|
2020-04-23 11:51:21 +02:00
|
|
|
/* By returning a negative value, we let the MAC know that we don't want
|
|
|
|
* the primitive and it will free it for us
|
2017-11-03 17:08:17 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
return -1;
|
2017-04-19 17:30:39 +02:00
|
|
|
}
|
|
|
|
|
2017-04-19 17:53:32 +02:00
|
|
|
/****************************************************************************
|
2017-05-16 03:44:51 +02:00
|
|
|
* Name: macnet_rxframe
|
2017-04-19 17:53:32 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-06-18 19:00:47 +02:00
|
|
|
* Handle received frames forward by the IEEE 802.15.4 MAC.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; a negated errno value is returned on
|
|
|
|
* any failure. On success, the ind and its contained iob will be freed.
|
|
|
|
* The ind will be intact if this function returns a failure.
|
2017-04-19 17:53:32 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
static int macnet_rxframe(FAR struct macnet_driver_s *priv,
|
2017-06-18 19:00:47 +02:00
|
|
|
FAR struct ieee802154_data_ind_s *ind)
|
2017-04-19 17:30:39 +02:00
|
|
|
{
|
2017-05-16 03:44:51 +02:00
|
|
|
FAR struct iob_s *iob;
|
2017-08-20 19:14:43 +02:00
|
|
|
int ret;
|
2017-04-19 17:30:39 +02:00
|
|
|
|
2017-06-18 19:00:47 +02:00
|
|
|
/* Ignore the frame if the network is not up */
|
|
|
|
|
|
|
|
if (!priv->md_bifup)
|
|
|
|
{
|
2017-06-20 21:30:17 +02:00
|
|
|
wlwarn("WARNING: Dropped... Network is down\n");
|
2017-06-18 19:00:47 +02:00
|
|
|
return -ENETDOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Peek the IOB contained the frame in the struct ieee802154_data_ind_s */
|
2017-04-19 17:53:32 +02:00
|
|
|
|
2017-05-16 03:44:51 +02:00
|
|
|
DEBUGASSERT(priv != NULL && ind != NULL && ind->frame != NULL);
|
2017-06-18 19:00:47 +02:00
|
|
|
iob = ind->frame;
|
|
|
|
|
|
|
|
/* Remove the IOB containing the frame. */
|
|
|
|
|
2017-05-16 03:44:51 +02:00
|
|
|
ind->frame = NULL;
|
2017-04-19 17:53:32 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
net_lock();
|
|
|
|
|
2017-05-16 03:44:51 +02:00
|
|
|
/* Transfer the frame to the network logic */
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2017-08-20 19:14:43 +02:00
|
|
|
ret = ieee802154_input(&priv->md_dev, iob, (FAR void *)ind);
|
|
|
|
if (ret < 0)
|
2017-08-19 20:32:56 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
{
|
2017-08-20 19:14:43 +02:00
|
|
|
/* If the frame is not a 6LoWPAN frame, then return an error. The
|
|
|
|
* first byte following the MAC head at the io_offset should be a
|
|
|
|
* valid IPHC header.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ((iob->io_data[iob->io_offset] & SIXLOWPAN_DISPATCH_NALP_MASK) ==
|
|
|
|
SIXLOWPAN_DISPATCH_NALP)
|
|
|
|
{
|
|
|
|
wlwarn("WARNING: Dropped... Not a 6LoWPAN frame: %02x\n",
|
|
|
|
iob->io_data[iob->io_offset]);
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-26 18:00:47 +02:00
|
|
|
/* Make sure the our single packet buffer is attached */
|
|
|
|
|
2019-08-10 19:51:05 +02:00
|
|
|
priv->md_dev.r_dev.d_buf = priv->md_iobuffer.rb_buf;
|
2017-08-26 18:00:47 +02:00
|
|
|
|
|
|
|
/* And give the packet to 6LoWPAN */
|
|
|
|
|
2017-08-20 19:14:43 +02:00
|
|
|
ret = sixlowpan_input(&priv->md_dev, iob, (FAR void *)ind);
|
|
|
|
}
|
2017-08-19 20:32:56 +02:00
|
|
|
}
|
2017-08-20 19:14:43 +02:00
|
|
|
|
|
|
|
if (ret < 0)
|
2017-08-19 20:32:56 +02:00
|
|
|
#endif
|
2017-08-20 19:14:43 +02:00
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
net_unlock();
|
2017-08-20 19:14:43 +02:00
|
|
|
ind->frame = iob;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Increment statistics */
|
|
|
|
|
|
|
|
NETDEV_RXPACKETS(&priv->md_dev.r_dev);
|
|
|
|
NETDEV_RXIPV6(&priv->md_dev.r_dev);
|
2017-05-16 03:44:51 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
net_unlock();
|
|
|
|
|
2017-05-16 03:44:51 +02:00
|
|
|
/* sixlowpan_input() will free the IOB, but we must free the struct
|
2017-11-01 21:15:21 +01:00
|
|
|
* ieee802154_primitive_s container here.
|
2017-05-16 03:44:51 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
ieee802154_primitive_free((FAR struct ieee802154_primitive_s *)ind);
|
2017-06-18 19:00:47 +02:00
|
|
|
return OK;
|
2017-04-19 17:30:39 +02:00
|
|
|
}
|
|
|
|
|
2017-04-08 22:21:20 +02:00
|
|
|
/****************************************************************************
|
2017-05-07 16:47:48 +02:00
|
|
|
* Name: macnet_txpoll_callback
|
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
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-08 22:21:20 +02:00
|
|
|
* 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-05-07 16:47:48 +02:00
|
|
|
static int macnet_txpoll_callback(FAR struct net_driver_s *dev)
|
2017-04-08 22:21:20 +02:00
|
|
|
{
|
2020-04-23 11:51:21 +02:00
|
|
|
/* If zero is returned, the polling will continue until all connections
|
|
|
|
* have been examined.
|
2017-04-08 22:21:20 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-05 17:13:29 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: macnet_coord_eaddr
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get the extended address of the PAN coordinator.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2017-08-05 17:13:29 +02:00
|
|
|
* radio - Reference to a radio network driver state instance.
|
|
|
|
* eaddr - The location in which to return the extended address.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) on success; a negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_STARPOINT) && defined(CONFIG_NET_6LOWPAN_EXTENDEDADDR)
|
2017-08-19 16:48:52 +02:00
|
|
|
static int macnet_coord_eaddr(FAR struct radio_driver_s *radio,
|
2017-08-05 18:18:34 +02:00
|
|
|
FAR uint8_t *eaddr)
|
2017-08-05 17:13:29 +02:00
|
|
|
{
|
2017-08-05 18:09:09 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)radio;
|
|
|
|
union ieee802154_macarg_u arg;
|
2017-08-05 17:13:29 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
arg.getreq.attr = IEEE802154_ATTR_MAC_COORD_EADDR ;
|
|
|
|
ret = mac802154_ioctl(priv->md_mac, MAC802154IOC_MLME_GET_REQUEST,
|
|
|
|
(unsigned long)((uintptr_t)&arg));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
nerr("ERROR: MAC802154IOC_MLME_GET_REQUEST failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
IEEE802154_EADDRCOPY(eaddr, arg.getreq.attrval.mac.eaddr);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: macnet_coord_saddr
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Get the short address of the PAN coordinator.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2017-08-05 17:13:29 +02:00
|
|
|
* radio - Reference to a radio network driver state instance.
|
|
|
|
* saddr - The location in which to return the short address.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) on success; a negated errno value on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_STARPOINT) && !defined(CONFIG_NET_6LOWPAN_EXTENDEDADDR)
|
2017-08-19 16:48:52 +02:00
|
|
|
static int macnet_coord_saddr(FAR struct radio_driver_s *radio,
|
2017-08-05 18:18:34 +02:00
|
|
|
FAR uint8_t *saddr)
|
2017-08-05 17:13:29 +02:00
|
|
|
{
|
2017-08-05 18:09:09 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)radio;
|
|
|
|
union ieee802154_macarg_u arg;
|
2017-08-05 17:13:29 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
arg.getreq.attr = IEEE802154_ATTR_MAC_COORD_SADDR ;
|
|
|
|
ret = mac802154_ioctl(priv->md_mac, MAC802154IOC_MLME_GET_REQUEST,
|
|
|
|
(unsigned long)((uintptr_t)&arg));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
nerr("ERROR: MAC802154IOC_MLME_GET_REQUEST failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
IEEE802154_SADDRCOPY(saddr, arg.getreq.attrval.mac.saddr);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
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:
|
2019-08-10 19:02:26 +02:00
|
|
|
* Creates a MAC-based IP address from the IEEE 802.15.14 short or extended
|
|
|
|
* address assigned to the node.
|
|
|
|
*
|
|
|
|
* 128 112 96 80 64 48 32 16
|
|
|
|
* ---- ---- ---- ---- ---- ---- ---- ----
|
2020-04-23 11:51:21 +02:00
|
|
|
* 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
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-08 22:21:20 +02:00
|
|
|
* 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-06-18 23:26:56 +02:00
|
|
|
FAR struct macnet_driver_s *priv =
|
|
|
|
(FAR struct macnet_driver_s *)dev->d_private;
|
|
|
|
int ret;
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2019-08-10 19:02:26 +02:00
|
|
|
ret = macnet_update_nvaddr(dev);
|
|
|
|
if (ret == OK)
|
2017-06-18 23:26:56 +02:00
|
|
|
{
|
2019-08-10 19:02:26 +02:00
|
|
|
uint8_t *nvaddr = dev->d_mac.radio.nv_addr;
|
|
|
|
|
|
|
|
/* Set the IP address based on the addressing assigned to the node */
|
|
|
|
|
|
|
|
dev->d_ipv6addr[0] = HTONS(CONFIG_IEEE802154_NETDEV_DEFAULT_PREFIX_0);
|
|
|
|
dev->d_ipv6addr[1] = HTONS(CONFIG_IEEE802154_NETDEV_DEFAULT_PREFIX_1);
|
|
|
|
dev->d_ipv6addr[2] = HTONS(CONFIG_IEEE802154_NETDEV_DEFAULT_PREFIX_2);
|
|
|
|
dev->d_ipv6addr[3] = HTONS(CONFIG_IEEE802154_NETDEV_DEFAULT_PREFIX_3);
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
2020-04-23 11:51:21 +02:00
|
|
|
dev->d_ipv6addr[4] = HTONS((uint16_t)nvaddr[0] << 8 |
|
|
|
|
(uint16_t)nvaddr[1]);
|
|
|
|
dev->d_ipv6addr[5] = HTONS((uint16_t)nvaddr[2] << 8 |
|
|
|
|
(uint16_t)nvaddr[3]);
|
|
|
|
dev->d_ipv6addr[6] = HTONS((uint16_t)nvaddr[4] << 8 |
|
|
|
|
(uint16_t)nvaddr[5]);
|
|
|
|
dev->d_ipv6addr[7] = HTONS((uint16_t)nvaddr[6] << 8 |
|
|
|
|
(uint16_t)nvaddr[7]);
|
2019-08-10 19:02:26 +02:00
|
|
|
|
|
|
|
/* Invert the U/L bit */
|
|
|
|
|
|
|
|
dev->d_ipv6addr[4] ^= HTONS(0x0200);
|
|
|
|
#else
|
|
|
|
|
|
|
|
dev->d_ipv6addr[4] = 0;
|
|
|
|
dev->d_ipv6addr[5] = HTONS(0x00ff);
|
|
|
|
dev->d_ipv6addr[6] = HTONS(0xfe00);
|
2020-04-23 11:51:21 +02:00
|
|
|
dev->d_ipv6addr[7] = HTONS((uint16_t)nvaddr[0] << 8 |
|
|
|
|
(uint16_t)nvaddr[1]);
|
2019-08-10 19:02:26 +02:00
|
|
|
#endif
|
|
|
|
|
2017-06-20 18:37:32 +02:00
|
|
|
wlinfo("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]);
|
2017-06-18 23:26:56 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
2017-06-20 18:37:32 +02:00
|
|
|
wlinfo(" Node: %02x:%02x:%02x:%02x:%02x:%02x:%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-18 23:26:56 +02:00
|
|
|
#else
|
2017-06-20 18:37:32 +02:00
|
|
|
wlinfo(" Node: %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-18 23:26:56 +02:00
|
|
|
#endif
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2017-06-18 23:26:56 +02:00
|
|
|
ret = OK;
|
|
|
|
}
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2019-08-10 19:02:26 +02:00
|
|
|
/* The interface is now up */
|
|
|
|
|
|
|
|
priv->md_bifup = true;
|
2017-06-18 23:26:56 +02:00
|
|
|
return ret;
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
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.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-08 22:21:20 +02:00
|
|
|
* 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
|
|
|
{
|
2020-04-23 11:51:21 +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;
|
|
|
|
|
2017-05-07 16:47:48 +02:00
|
|
|
/* Disable interruption */
|
2017-04-08 22:21:20 +02:00
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-08 22:21:20 +02:00
|
|
|
* 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
|
|
|
|
2017-06-20 18:37:32 +02:00
|
|
|
wlinfo("ifup=%u\n", priv->md_bifup);
|
|
|
|
|
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
|
|
|
{
|
2017-08-26 18:00:47 +02:00
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
/* Make sure the our single packet buffer is attached */
|
|
|
|
|
2019-08-10 19:51:05 +02:00
|
|
|
priv->md_dev.r_dev.d_buf = priv->md_iobuffer.rb_buf;
|
2017-08-26 18:00:47 +02:00
|
|
|
#endif
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2017-08-26 18:00:47 +02:00
|
|
|
/* Then poll the network for new XMIT data */
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
devif_poll(&priv->md_dev.r_dev, macnet_txpoll_callback);
|
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.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-08 22:21:20 +02:00
|
|
|
* 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
|
|
|
{
|
2020-04-23 11:51:21 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)
|
|
|
|
dev->d_private;
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2017-06-20 18:37:32 +02:00
|
|
|
wlinfo("Available=%u\n", work_available(&priv->md_pollwork));
|
|
|
|
|
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-05-07 16:47:48 +02:00
|
|
|
work_queue(WPANWORK, &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
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-08 22:21:20 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
* mac - The MAC address to be added
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
2020-04-23 11:51:21 +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
|
|
|
{
|
2020-04-23 11:51:21 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)
|
|
|
|
dev->d_private;
|
|
|
|
/* Add the MAC address to the hardware multicast routing table.
|
|
|
|
* Not used with IEEE 802.15.4 radios.
|
2017-05-08 16:34:21 +02:00
|
|
|
*/
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2023-12-13 05:39:43 +01:00
|
|
|
UNUSED(priv);
|
2017-05-08 16:34:21 +02:00
|
|
|
return -ENOSYS;
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-14 18:38:46 +02:00
|
|
|
* Name: macnet_rmmac
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2020-04-23 11:51:21 +02:00
|
|
|
* NuttX Callback: Remove the specified MAC address from the hardware
|
|
|
|
* multicast address filtering
|
2017-04-08 22:21:20 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-08 22:21:20 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
* mac - The MAC address to be removed
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
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
|
|
|
{
|
2020-04-23 11:51:21 +02:00
|
|
|
FAR struct macnet_driver_s *priv = (FAR struct macnet_driver_s *)
|
|
|
|
dev->d_private;
|
|
|
|
/* Remove the MAC address from the hardware multicast routing table
|
|
|
|
* Not used with IEEE 802.15.4 radios.
|
2017-04-08 22:21:20 +02:00
|
|
|
*/
|
|
|
|
|
2023-12-13 05:39:43 +01:00
|
|
|
UNUSED(priv);
|
2017-05-08 16:34:21 +02:00
|
|
|
return -ENOSYS;
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
2017-05-08 16:34:21 +02:00
|
|
|
#endif
|
2017-04-08 22:21:20 +02:00
|
|
|
|
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.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-13 18:18:57 +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
|
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
|
|
|
{
|
2020-04-23 11:51:21 +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;
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&priv->md_lock);
|
2017-09-15 16:04:38 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
wlerr("ERROR: nxmutex_lock failed: %d\n", ret);
|
2017-09-15 16:04:38 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-13 18:18:57 +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;
|
|
|
|
|
|
|
|
if (netmac != NULL)
|
|
|
|
{
|
|
|
|
unsigned long macarg = (unsigned int)((uintptr_t)&netmac->u);
|
2017-09-15 16:04:38 +02:00
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
/* Command: MAC802154IOC_NOTIFY_REGISTER
|
2020-04-23 11:51:21 +02:00
|
|
|
* Description: Register to receive a signal whenever there is
|
|
|
|
* a event primitive sent from the MAC layer.
|
2017-09-15 16:04:38 +02:00
|
|
|
* Argument: A read-only pointer to an instance of struct
|
|
|
|
* macnet_notify_s
|
2020-04-23 11:51:21 +02:00
|
|
|
* Return: Zero (OK) on success.
|
|
|
|
* Minus one will be returned on failure with the
|
|
|
|
* errno value set appropriately.
|
2017-09-15 16:04:38 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
case MAC802154IOC_NOTIFY_REGISTER:
|
|
|
|
{
|
|
|
|
/* Save the notification events */
|
|
|
|
|
2019-01-27 15:53:12 +01:00
|
|
|
priv->md_notify_event = netmac->u.event;
|
2023-02-01 11:05:58 +01:00
|
|
|
priv->md_notify_pid = nxsched_getpid();
|
2017-09-15 16:04:38 +02:00
|
|
|
priv->md_notify_registered = true;
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
break;
|
2017-10-04 23:22:27 +02:00
|
|
|
|
2017-09-15 16:04:38 +02:00
|
|
|
case MAC802154IOC_GET_EVENT:
|
|
|
|
{
|
2017-11-01 21:15:21 +01:00
|
|
|
FAR struct ieee802154_primitive_s *primitive;
|
2017-09-15 16:04:38 +02:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
/* Try popping an event off the queue */
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
primitive = (FAR struct ieee802154_primitive_s *)
|
2017-11-03 15:42:21 +01:00
|
|
|
sq_remfirst(&priv->primitive_queue);
|
2017-09-15 16:04:38 +02:00
|
|
|
|
2020-04-23 11:51:21 +02:00
|
|
|
/* If there was an event to pop off, copy it into the
|
|
|
|
* user data and free it from the MAC layer's memory.
|
2017-09-15 16:04:38 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
if (primitive != NULL)
|
2017-09-15 16:04:38 +02:00
|
|
|
{
|
2017-11-03 15:42:21 +01:00
|
|
|
memcpy(&netmac->u, primitive,
|
|
|
|
sizeof(struct ieee802154_primitive_s));
|
2017-09-15 16:04:38 +02:00
|
|
|
|
2017-11-03 15:42:21 +01:00
|
|
|
/* Free the event */
|
2017-09-15 16:04:38 +02:00
|
|
|
|
2017-11-03 15:42:21 +01:00
|
|
|
ieee802154_primitive_free(primitive);
|
2017-09-15 16:04:38 +02:00
|
|
|
ret = OK;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* There can only be one getevent pending at a time */
|
|
|
|
|
|
|
|
if (priv->md_eventpending)
|
|
|
|
{
|
|
|
|
ret = -EAGAIN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->md_eventpending = true;
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->md_lock);
|
2017-09-15 16:04:38 +02:00
|
|
|
|
|
|
|
/* Wait to be signaled when an event is queued */
|
|
|
|
|
2017-10-04 23:22:27 +02:00
|
|
|
ret = nxsem_wait(&priv->md_eventsem);
|
|
|
|
if (ret < 0)
|
2017-09-15 16:04:38 +02:00
|
|
|
{
|
|
|
|
priv->md_eventpending = false;
|
2017-10-04 23:22:27 +02:00
|
|
|
return ret;
|
2017-09-15 16:04:38 +02:00
|
|
|
}
|
|
|
|
|
2020-04-23 11:51:21 +02:00
|
|
|
/* Get exclusive access again, then loop back around
|
|
|
|
* and try and pop an event off the queue
|
2017-09-15 16:04:38 +02:00
|
|
|
*/
|
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = nxmutex_lock(&priv->md_lock);
|
2017-09-15 16:04:38 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2022-09-06 08:18:45 +02:00
|
|
|
wlerr("ERROR: nxmutex_lock failed: %d\n", ret);
|
2017-09-15 16:04:38 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2017-10-04 23:22:27 +02:00
|
|
|
|
2017-09-15 16:04:38 +02:00
|
|
|
case MAC802154IOC_ENABLE_EVENTS:
|
|
|
|
{
|
|
|
|
priv->md_enableevents = netmac->u.enable;
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
break;
|
2017-10-04 23:22:27 +02:00
|
|
|
|
2017-09-15 16:04:38 +02:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
ret = mac802154_ioctl(priv->md_mac, cmd, macarg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
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-05-07 16:47:48 +02:00
|
|
|
ret = mac802154_ioctl(priv->md_mac, cmd, arg);
|
2017-04-13 18:18:57 +02:00
|
|
|
}
|
2017-05-07 16:47:48 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_unlock(&priv->md_lock);
|
2017-09-15 16:04:38 +02:00
|
|
|
return ret;
|
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.
|
|
|
|
*
|
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 macnet_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
|
|
|
{
|
2017-08-05 18:09:09 +02:00
|
|
|
FAR struct macnet_driver_s *priv =
|
|
|
|
(FAR struct macnet_driver_s *)netdev;
|
|
|
|
FAR const struct ieee802154_frame_meta_s *pktmeta =
|
|
|
|
(FAR const struct ieee802154_frame_meta_s *)meta;
|
2017-07-31 03:10:51 +02:00
|
|
|
|
2017-08-05 18:09:09 +02:00
|
|
|
DEBUGASSERT(priv != NULL && priv->md_mac != NULL && pktmeta != NULL);
|
2017-07-31 03:10:51 +02:00
|
|
|
return mac802154_get_mhrlen(priv->md_mac, pktmeta);
|
2017-05-03 00:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: macnet_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 macnet_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
|
|
|
{
|
2017-08-05 18:09:09 +02:00
|
|
|
FAR struct macnet_driver_s *priv =
|
|
|
|
(FAR struct macnet_driver_s *)netdev;
|
|
|
|
FAR const struct ieee802154_frame_meta_s *pktmeta =
|
|
|
|
(FAR const struct ieee802154_frame_meta_s *)meta;
|
2017-05-03 00:03:26 +02:00
|
|
|
FAR struct iob_s *iob;
|
|
|
|
int ret;
|
|
|
|
|
2017-06-20 18:37:32 +02:00
|
|
|
wlinfo("Received framelist\n");
|
|
|
|
|
2017-08-05 18:09:09 +02:00
|
|
|
DEBUGASSERT(priv != NULL && pktmeta != NULL && framelist != NULL);
|
2017-05-07 16:47:48 +02:00
|
|
|
|
2017-05-03 00:03:26 +02:00
|
|
|
/* 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 */
|
|
|
|
|
2017-07-29 21:42:26 +02:00
|
|
|
NETDEV_TXPACKETS(&priv->md_dev.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;
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
/* Transfer the frame to the MAC. */
|
2017-05-03 00:03:26 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
ret = mac802154_req_data(priv->md_mac, pktmeta, iob);
|
2017-05-03 00:03:26 +02:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
wlerr("ERROR: mac802154_req_data failed: %d\n", ret);
|
|
|
|
|
2022-08-08 04:21:03 +02:00
|
|
|
iob_free(iob);
|
2017-05-07 16:47:48 +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;
|
2022-08-08 04:21:03 +02:00
|
|
|
iob_free(iob);
|
2017-05-03 00:03:26 +02:00
|
|
|
}
|
|
|
|
|
2017-07-29 21:42:26 +02:00
|
|
|
NETDEV_TXERRORS(&priv->md_dev.r_dev);
|
2017-05-03 00:03:26 +02:00
|
|
|
return ret;
|
|
|
|
}
|
2017-06-25 19:18:27 +02:00
|
|
|
|
2017-07-29 21:42:26 +02:00
|
|
|
NETDEV_TXDONE(&priv->md_dev.r_dev);
|
2017-05-03 00:03:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2017-07-31 03:10:51 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: macnet_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 macnet_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 = MACNET_ADDRSIZE; /* Length of an address */
|
|
|
|
properties->sp_framelen = MACNET_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.
|
|
|
|
*
|
|
|
|
* If this node is a "point" in a star topology, then the hub node
|
|
|
|
* MAC address is the address of the hub/PAN coordinator.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN_EXTENDEDADDR
|
2020-01-02 17:49:34 +01:00
|
|
|
macnet_coord_eaddr(netdev, properties->sp_hubnode.nv_addr);
|
2017-08-20 19:14:43 +02:00
|
|
|
properties->sp_hubnode.nv_addrlen = IEEE802154_EADDRSIZE;
|
2017-08-05 17:13:29 +02:00
|
|
|
#else
|
2020-01-02 17:49:34 +01:00
|
|
|
macnet_coord_saddr(netdev, properties->sp_hubnode.nv_addr);
|
2017-08-20 19:14:43 +02:00
|
|
|
properties->sp_hubnode.nv_addrlen = IEEE802154_SADDRSIZE;
|
2017-08-05 17:13:29 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-07-31 03:10:51 +02:00
|
|
|
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
|
2017-06-18 19:00:47 +02:00
|
|
|
* 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
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2017-04-09 03:11:57 +02:00
|
|
|
* 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-08-19 16:48:52 +02:00
|
|
|
FAR struct radio_driver_s *radio;
|
2017-05-03 00:03:26 +02:00
|
|
|
FAR struct net_driver_s *dev;
|
2017-05-16 03:44:51 +02:00
|
|
|
FAR struct mac802154_maccb_s *maccb;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the driver structure */
|
|
|
|
|
2017-07-29 21:42:26 +02:00
|
|
|
radio = &priv->md_dev;
|
|
|
|
dev = &radio->r_dev;
|
2017-05-03 00:03:26 +02:00
|
|
|
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 */
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
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
|
2020-08-04 12:31:31 +02:00
|
|
|
dev->d_private = priv; /* Used to recover private state from dev */
|
2017-05-03 00:03:26 +02:00
|
|
|
priv->md_mac = mac; /* Save the MAC interface instance */
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
/* Setup a locking mutex for exclusive device driver access */
|
2017-09-15 16:04:38 +02:00
|
|
|
|
2022-09-06 08:18:45 +02:00
|
|
|
nxmutex_init(&priv->md_lock);
|
2017-09-15 16:04:38 +02:00
|
|
|
|
2017-06-18 23:26:56 +02:00
|
|
|
/* Set the network mask. */
|
|
|
|
|
|
|
|
macnet_netmask(dev);
|
|
|
|
|
2017-05-03 00:03:26 +02:00
|
|
|
/* Initialize the Network frame-related callbacks */
|
|
|
|
|
2017-07-31 03:10:51 +02:00
|
|
|
radio->r_get_mhrlen = macnet_get_mhrlen; /* Get MAC header length */
|
|
|
|
radio->r_req_data = macnet_req_data; /* Enqueue frame for transmission */
|
2018-03-31 18:37:34 +02:00
|
|
|
radio->r_properties = macnet_properties; /* Return radio properties */
|
2017-05-03 00:03:26 +02:00
|
|
|
|
2017-09-15 16:04:38 +02:00
|
|
|
/* Initialize fields related to MAC event handling */
|
|
|
|
|
|
|
|
priv->md_eventpending = false;
|
2017-10-03 20:51:15 +02:00
|
|
|
nxsem_init(&priv->md_eventsem, 0, 0);
|
2017-09-15 16:04:38 +02:00
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
sq_init(&priv->primitive_queue);
|
2017-09-15 16:04:38 +02:00
|
|
|
|
|
|
|
priv->md_enableevents = false;
|
|
|
|
priv->md_notify_registered = false;
|
|
|
|
|
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;
|
|
|
|
|
2017-05-16 03:44:51 +02:00
|
|
|
maccb = &priv->md_cb.mc_cb;
|
2017-06-18 19:00:47 +02:00
|
|
|
maccb->flink = NULL;
|
|
|
|
maccb->prio = CONFIG_IEEE802154_NETDEV_RECVRPRIO;
|
2017-05-16 03:44:51 +02:00
|
|
|
maccb->notify = macnet_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);
|
2017-05-07 16:47:48 +02:00
|
|
|
if (ret < 0)
|
2017-04-13 20:17:36 +02:00
|
|
|
{
|
|
|
|
nerr("ERROR: Failed to bind the MAC callbacks: %d\n", ret);
|
2019-08-10 19:02:26 +02:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = macnet_update_nvaddr(&priv->md_dev.r_dev);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
nerr("ERROR: Failed updating nvaddr: %d\n", ret);
|
|
|
|
goto errout;
|
|
|
|
}
|
2017-04-13 20:17:36 +02:00
|
|
|
|
2019-08-10 20:22:39 +02:00
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
2020-04-23 11:51:21 +02:00
|
|
|
/* Make sure the our single packet buffer is attached.
|
|
|
|
* We must do this before registering the device since,
|
|
|
|
* once the device is registered, a packet may
|
2019-08-10 20:22:39 +02:00
|
|
|
* be attempted to be forwarded and require the buffer.
|
|
|
|
*/
|
|
|
|
|
|
|
|
priv->md_dev.r_dev.d_buf = priv->md_iobuffer.rb_buf;
|
|
|
|
#endif
|
|
|
|
|
2019-08-10 19:02:26 +02:00
|
|
|
/* Register the device with the OS so that socket IOCTLs can be performed */
|
2017-04-13 20:17:36 +02:00
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
netdev_register(&priv->md_dev.r_dev, NET_LL_IEEE802154);
|
2017-04-13 20:17:36 +02:00
|
|
|
|
2020-04-23 11:51:21 +02:00
|
|
|
/* Put the network in the DOWN state, let the user decide when to bring
|
|
|
|
* it up
|
|
|
|
*/
|
2017-05-07 16:47:48 +02:00
|
|
|
|
2019-08-10 19:02:26 +02:00
|
|
|
return macnet_ifdown(&priv->md_dev.r_dev);
|
2017-04-13 20:17:36 +02:00
|
|
|
|
2019-08-10 19:02:26 +02:00
|
|
|
errout:
|
2022-10-16 18:50:59 +02:00
|
|
|
nxmutex_destroy(&priv->md_lock);
|
2019-12-24 17:37:30 +01:00
|
|
|
|
2019-08-10 19:02:26 +02:00
|
|
|
/* Free memory and return the error */
|
2017-04-08 22:21:20 +02:00
|
|
|
|
2019-08-10 19:02:26 +02:00
|
|
|
kmm_free(priv);
|
|
|
|
return ret;
|
2017-04-08 22:21:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET && CONFIG_NET_skeleton */
|