2017-04-24 18:23:31 +02:00
|
|
|
/****************************************************************************
|
2021-03-08 22:39:04 +01:00
|
|
|
* drivers/wireless/ieee80211/bcm43xxx/bcmf_netdev.c
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
2021-04-02 12:39:20 +02: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-24 18:23:31 +02:00
|
|
|
*
|
2021-04-02 12:39:20 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
2021-04-02 12:39:20 +02: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-24 18:23:31 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#if defined(CONFIG_NET) && defined(CONFIG_IEEE80211_BROADCOM_FULLMAC)
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <nuttx/arch.h>
|
|
|
|
#include <nuttx/irq.h>
|
|
|
|
#include <nuttx/wqueue.h>
|
|
|
|
#include <nuttx/net/arp.h>
|
|
|
|
#include <nuttx/net/netdev.h>
|
2017-04-26 20:30:18 +02:00
|
|
|
#include <nuttx/wireless/wireless.h>
|
2022-06-18 20:10:33 +02:00
|
|
|
#include <nuttx/wireless/ieee80211/bcmf_board.h>
|
2017-04-24 18:23:31 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_PKT
|
|
|
|
# include <nuttx/net/pkt.h>
|
|
|
|
#endif
|
|
|
|
|
2017-04-24 20:04:47 +02:00
|
|
|
#include "bcmf_driver.h"
|
|
|
|
#include "bcmf_cdc.h"
|
2017-04-30 20:29:48 +02:00
|
|
|
#include "bcmf_bdc.h"
|
2017-04-24 20:04:47 +02:00
|
|
|
#include "bcmf_ioctl.h"
|
2022-06-16 07:59:02 +02:00
|
|
|
#include "bcmf_netdev.h"
|
2017-04-24 20:04:47 +02:00
|
|
|
|
2017-04-24 18:23:31 +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-24 18:23:31 +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.
|
|
|
|
*
|
2022-06-19 14:48:31 +02:00
|
|
|
* Use high priority queue if the bcmf daemon task has a higher priority
|
|
|
|
* than HPWORK, which will bring better performance especially on devices
|
|
|
|
* that focus on real-time of network.
|
2018-11-21 14:57:26 +01:00
|
|
|
*/
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2022-06-19 14:48:31 +02:00
|
|
|
#if defined(CONFIG_SCHED_HPWORK) && \
|
|
|
|
(CONFIG_IEEE80211_BROADCOM_SCHED_PRIORITY >= CONFIG_SCHED_HPWORKPRIORITY)
|
|
|
|
# define BCMFWORK HPWORK
|
|
|
|
#else
|
|
|
|
# define BCMFWORK LPWORK
|
|
|
|
#endif
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
/* CONFIG_IEEE80211_BROADCOM_NINTERFACES determines the number of physical
|
|
|
|
* interfaces that will be supported.
|
2017-04-24 18:23:31 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_IEEE80211_BROADCOM_NINTERFACES
|
|
|
|
# define CONFIG_IEEE80211_BROADCOM_NINTERFACES 1
|
|
|
|
#endif
|
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
/* This is a helper pointer for accessing the contents of Ethernet header */
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2022-01-17 23:09:14 +01:00
|
|
|
#define BUF ((FAR struct eth_hdr_s *)priv->bc_dev.d_buf)
|
2017-04-24 18:23:31 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Common TX logic */
|
|
|
|
|
2018-04-26 16:10:23 +02:00
|
|
|
static int bcmf_transmit(FAR struct bcmf_dev_s *priv,
|
|
|
|
FAR struct bcmf_frame_s *frame);
|
2017-04-24 20:04:47 +02:00
|
|
|
static void bcmf_receive(FAR struct bcmf_dev_s *priv);
|
2017-04-30 20:29:48 +02:00
|
|
|
static int bcmf_txpoll(FAR struct net_driver_s *dev);
|
2021-10-02 05:26:43 +02:00
|
|
|
static void bcmf_rxpoll_work(FAR void *arg);
|
2017-04-24 18:23:31 +02:00
|
|
|
|
|
|
|
/* NuttX callback functions */
|
|
|
|
|
|
|
|
static int bcmf_ifup(FAR struct net_driver_s *dev);
|
|
|
|
static int bcmf_ifdown(FAR struct net_driver_s *dev);
|
|
|
|
|
|
|
|
static int bcmf_txavail(FAR struct net_driver_s *dev);
|
|
|
|
|
2018-10-31 22:03:51 +01:00
|
|
|
#if defined(CONFIG_NET_MCASTGROUP) || defined(CONFIG_NET_ICMPv6)
|
2017-04-24 18:23:31 +02:00
|
|
|
static int bcmf_addmac(FAR struct net_driver_s *dev,
|
2018-04-26 16:10:23 +02:00
|
|
|
FAR const uint8_t *mac);
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
2017-04-24 18:23:31 +02:00
|
|
|
static int bcmf_rmmac(FAR struct net_driver_s *dev,
|
2018-04-26 16:10:23 +02:00
|
|
|
FAR const uint8_t *mac);
|
2017-04-24 18:23:31 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_ICMPv6
|
2017-04-24 20:04:47 +02:00
|
|
|
static void bcmf_ipv6multicast(FAR struct bcmf_dev_s *priv);
|
2017-04-24 18:23:31 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NETDEV_IOCTL
|
|
|
|
static int bcmf_ioctl(FAR struct net_driver_s *dev, int cmd,
|
2018-04-26 16:10:23 +02:00
|
|
|
unsigned long arg);
|
2017-04-24 18:23:31 +02:00
|
|
|
#endif
|
|
|
|
|
2022-06-20 08:56:37 +02:00
|
|
|
#ifdef CONFIG_IEEE80211_BROADCOM_LOWPOWER
|
|
|
|
static void bcmf_lowpower_poll(FAR struct bcmf_dev_s *priv);
|
|
|
|
#endif
|
|
|
|
|
2017-04-24 18:23:31 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
int bcmf_netdev_alloc_tx_frame(FAR struct bcmf_dev_s *priv)
|
2017-04-24 18:23:31 +02:00
|
|
|
{
|
2017-04-30 20:29:48 +02:00
|
|
|
if (priv->cur_tx_frame != NULL)
|
|
|
|
{
|
|
|
|
/* Frame available */
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
return OK;
|
|
|
|
}
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
/* Allocate frame for TX */
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
priv->cur_tx_frame = bcmf_bdc_allocate_frame(priv,
|
|
|
|
MAX_NETDEV_PKTSIZE, true);
|
2017-04-30 20:29:48 +02:00
|
|
|
if (!priv->cur_tx_frame)
|
|
|
|
{
|
2017-05-14 16:39:53 +02:00
|
|
|
wlerr("ERROR: Cannot allocate TX frame\n");
|
2017-04-30 20:29:48 +02:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2022-06-16 07:59:02 +02:00
|
|
|
priv->bc_dev.d_buf = priv->cur_tx_frame->data;
|
|
|
|
priv->bc_dev.d_len = 0;
|
|
|
|
|
2017-04-24 18:23:31 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-30 20:29:48 +02:00
|
|
|
* Name: bcmf_transmit
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-04-30 20:29:48 +02:00
|
|
|
* Start hardware transmission. Called either from the txdone interrupt
|
|
|
|
* handling or from watchdog based polling.
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-30 20:29:48 +02:00
|
|
|
* priv - Reference to the driver state structure
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
|
|
|
* 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-04-30 20:29:48 +02:00
|
|
|
static int bcmf_transmit(FAR struct bcmf_dev_s *priv,
|
|
|
|
struct bcmf_frame_s *frame)
|
2017-04-24 18:23:31 +02:00
|
|
|
{
|
2017-04-30 20:29:48 +02:00
|
|
|
int ret;
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
frame->len = priv->bc_dev.d_len +
|
|
|
|
(unsigned int)(frame->data - frame->base);
|
2017-05-04 02:30:40 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
ret = bcmf_bdc_transmit_frame(priv, frame);
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
if (ret)
|
2017-04-24 18:23:31 +02:00
|
|
|
{
|
2017-05-14 16:39:53 +02:00
|
|
|
wlerr("ERROR: Failed to transmit frame\n");
|
2017-04-30 20:29:48 +02:00
|
|
|
return -EIO;
|
2017-04-24 18:23:31 +02:00
|
|
|
}
|
|
|
|
|
2019-09-21 15:16:37 +02:00
|
|
|
NETDEV_TXPACKETS(&priv->bc_dev);
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
return OK;
|
2017-04-24 18:23:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_receive
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* An interrupt was received indicating the availability of a new RX packet
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-24 18:23:31 +02:00
|
|
|
* priv - Reference to the driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The network is locked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-24 20:04:47 +02:00
|
|
|
static void bcmf_receive(FAR struct bcmf_dev_s *priv)
|
2017-04-24 18:23:31 +02:00
|
|
|
{
|
2017-04-30 20:29:48 +02:00
|
|
|
struct bcmf_frame_s *frame;
|
2018-04-26 16:10:23 +02:00
|
|
|
|
2017-04-24 18:23:31 +02:00
|
|
|
do
|
|
|
|
{
|
2017-04-30 20:29:48 +02:00
|
|
|
/* Request frame buffer from bus interface */
|
|
|
|
|
|
|
|
frame = bcmf_bdc_rx_frame(priv);
|
|
|
|
|
|
|
|
if (frame == NULL)
|
|
|
|
{
|
|
|
|
/* No more frame to process */
|
2018-04-26 16:10:23 +02:00
|
|
|
|
2022-06-16 07:59:02 +02:00
|
|
|
bcmf_netdev_notify_tx(priv);
|
2017-04-30 20:29:48 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-05-03 23:19:28 +02:00
|
|
|
if (!priv->bc_bifup)
|
|
|
|
{
|
|
|
|
/* Interface down, drop frame */
|
2018-04-26 16:10:23 +02:00
|
|
|
|
2017-05-03 23:19:28 +02:00
|
|
|
priv->bus->free_frame(priv, frame);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
priv->bc_dev.d_buf = frame->data;
|
2020-08-06 19:41:45 +02:00
|
|
|
priv->bc_dev.d_len = frame->len - (frame->data - frame->base);
|
2017-04-30 20:29:48 +02:00
|
|
|
|
2017-05-03 23:19:28 +02:00
|
|
|
wlinfo("Got frame %p %d\n", frame, priv->bc_dev.d_len);
|
2017-04-24 18:23:31 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_PKT
|
2020-08-06 19:41:45 +02:00
|
|
|
/* When packet sockets are enabled, feed the frame into the tap */
|
2017-04-24 18:23:31 +02:00
|
|
|
|
|
|
|
pkt_input(&priv->bc_dev);
|
|
|
|
#endif
|
|
|
|
|
2018-04-26 16:10:23 +02:00
|
|
|
/* Check if this is an 802.1Q VLAN tagged packet */
|
|
|
|
|
|
|
|
if (BUF->type == HTONS(TPID_8021QVLAN))
|
|
|
|
{
|
|
|
|
/* Need to remove the 4 octet VLAN Tag, by moving src and dest
|
|
|
|
* addresses 4 octets to the right, and then read the actual
|
|
|
|
* ethertype. The VLAN ID and priority fields are currently
|
|
|
|
* ignored.
|
|
|
|
*/
|
|
|
|
|
|
|
|
uint8_t temp_buffer[12];
|
2018-08-21 20:46:00 +02:00
|
|
|
memcpy(temp_buffer, frame->data, 12);
|
|
|
|
memcpy(frame->data + 4, temp_buffer, 12);
|
2018-04-26 16:10:23 +02:00
|
|
|
|
|
|
|
priv->bc_dev.d_buf = frame->data = frame->data + 4;
|
|
|
|
priv->bc_dev.d_len -= 4;
|
|
|
|
}
|
|
|
|
|
2017-04-24 18:23:31 +02:00
|
|
|
/* We only accept IP packets of the configured type and ARP packets */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
if (BUF->type == HTONS(ETHTYPE_IP))
|
|
|
|
{
|
2017-05-03 23:19:28 +02:00
|
|
|
ninfo("IPv4 frame\n");
|
2017-04-24 18:23:31 +02:00
|
|
|
NETDEV_RXIPV4(&priv->bc_dev);
|
|
|
|
|
|
|
|
/* Handle ARP on input then give the IPv4 packet to the network
|
|
|
|
* layer
|
|
|
|
*/
|
|
|
|
|
|
|
|
arp_ipin(&priv->bc_dev);
|
|
|
|
ipv4_input(&priv->bc_dev);
|
|
|
|
|
|
|
|
/* If the above function invocation resulted in data that should be
|
2020-08-06 19:41:45 +02:00
|
|
|
* sent out on the network, d_len field will set to a value > 0.
|
2017-04-24 18:23:31 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (priv->bc_dev.d_len > 0)
|
|
|
|
{
|
|
|
|
/* Update the Ethernet header with the correct MAC address */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
if (IFF_IS_IPv4(priv->bc_dev.d_flags))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
arp_out(&priv->bc_dev);
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
else
|
|
|
|
{
|
|
|
|
neighbor_out(&kel->bc_dev);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* And send the packet */
|
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
bcmf_transmit(priv, frame);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Release RX frame buffer */
|
|
|
|
|
|
|
|
priv->bus->free_frame(priv, frame);
|
2017-04-24 18:23:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
if (BUF->type == HTONS(ETHTYPE_IP6))
|
|
|
|
{
|
2020-03-03 16:11:57 +01:00
|
|
|
ninfo("IPv6 frame\n");
|
2017-04-24 18:23:31 +02:00
|
|
|
NETDEV_RXIPV6(&priv->bc_dev);
|
|
|
|
|
|
|
|
/* Give the IPv6 packet to the network layer */
|
|
|
|
|
|
|
|
ipv6_input(&priv->bc_dev);
|
|
|
|
|
|
|
|
/* If the above function invocation resulted in data that should be
|
2020-08-06 19:41:45 +02:00
|
|
|
* sent out on the network, d_len field will set to a value > 0.
|
2017-04-24 18:23:31 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (priv->bc_dev.d_len > 0)
|
2019-09-21 15:16:37 +02:00
|
|
|
{
|
2017-04-24 18:23:31 +02:00
|
|
|
/* Update the Ethernet header with the correct MAC address */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
if (IFF_IS_IPv4(priv->bc_dev.d_flags))
|
|
|
|
{
|
|
|
|
arp_out(&priv->bc_dev);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
{
|
|
|
|
neighbor_out(&priv->bc_dev);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* And send the packet */
|
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
bcmf_transmit(priv, frame);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Release RX frame buffer */
|
|
|
|
|
|
|
|
priv->bus->free_frame(priv, frame);
|
2017-04-24 18:23:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_ARP
|
2022-01-18 08:38:00 +01:00
|
|
|
if (BUF->type == HTONS(ETHTYPE_ARP))
|
2017-04-24 18:23:31 +02:00
|
|
|
{
|
|
|
|
arp_arpin(&priv->bc_dev);
|
|
|
|
NETDEV_RXARP(&priv->bc_dev);
|
|
|
|
|
|
|
|
/* If the above function invocation resulted in data that should be
|
2020-08-06 19:41:45 +02:00
|
|
|
* sent out on the network, d_len field will set to a value > 0.
|
2017-04-24 18:23:31 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (priv->bc_dev.d_len > 0)
|
|
|
|
{
|
2017-04-30 20:29:48 +02:00
|
|
|
bcmf_transmit(priv, frame);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Release RX frame buffer */
|
|
|
|
|
|
|
|
priv->bus->free_frame(priv, frame);
|
2017-04-24 18:23:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2018-04-26 16:10:23 +02:00
|
|
|
/* On some routers, it may constantly receive mysterious packet...
|
|
|
|
* https://www.wireshark.org/docs/wsar_html/epan/etypes_8h.html
|
|
|
|
* for more etypes definitions.
|
|
|
|
*/
|
|
|
|
|
2017-04-24 18:23:31 +02:00
|
|
|
NETDEV_RXDROPPED(&priv->bc_dev);
|
2017-05-03 23:19:28 +02:00
|
|
|
priv->bus->free_frame(priv, frame);
|
2017-04-24 18:23:31 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-24 20:04:47 +02:00
|
|
|
while (1); /* While there are more packets to be processed */
|
2017-04-24 18:23:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-30 20:29:48 +02:00
|
|
|
* Name: bcmf_txpoll
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-04-30 20:29:48 +02:00
|
|
|
* 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,
|
2018-08-21 20:46:00 +02:00
|
|
|
* 2. When the preceding TX packet send times out and the interface is
|
|
|
|
* reset
|
2017-04-30 20:29:48 +02:00
|
|
|
* 3. During normal TX polling
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-30 20:29:48 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2017-04-30 20:29:48 +02:00
|
|
|
* OK on success; a negated errno on failure
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
|
|
|
* Assumptions:
|
2017-04-30 20:29:48 +02:00
|
|
|
* May or may not be called from an interrupt handler. In either case,
|
|
|
|
* the network is locked.
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
static int bcmf_txpoll(FAR struct net_driver_s *dev)
|
2017-04-24 18:23:31 +02:00
|
|
|
{
|
2017-04-30 20:29:48 +02:00
|
|
|
FAR struct bcmf_dev_s *priv = (FAR struct bcmf_dev_s *)dev->d_private;
|
|
|
|
|
|
|
|
/* If the polling resulted in data that should be sent out on the network,
|
|
|
|
* the field d_len is set to a value > 0.
|
|
|
|
*/
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
if (priv->bc_dev.d_len > 0)
|
|
|
|
{
|
|
|
|
/* Look up the destination MAC address and add it to the Ethernet
|
|
|
|
* header.
|
|
|
|
*/
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
if (IFF_IS_IPv4(priv->bc_dev.d_flags))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
arp_out(&priv->bc_dev);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_IPv4 */
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
#ifdef CONFIG_NET_IPv4
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
neighbor_out(&priv->bc_dev);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_IPv6 */
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2018-08-25 16:33:21 +02:00
|
|
|
if (!devif_loopback(&priv->bc_dev))
|
2018-08-24 17:21:33 +02:00
|
|
|
{
|
|
|
|
/* Send the packet */
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2018-08-24 17:21:33 +02:00
|
|
|
bcmf_transmit(priv, priv->cur_tx_frame);
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
/* TODO: Check if there is room in the device to hold another
|
|
|
|
* packet. If not, return a non-zero value to terminate the poll.
|
2018-08-24 17:21:33 +02:00
|
|
|
*/
|
2018-08-21 20:46:00 +02:00
|
|
|
|
2018-08-24 17:21:33 +02:00
|
|
|
priv->cur_tx_frame = NULL;
|
|
|
|
return 1;
|
|
|
|
}
|
2017-04-30 20:29:48 +02:00
|
|
|
}
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
/* If zero is returned, the polling will continue until all connections
|
|
|
|
* have been examined.
|
2017-04-30 20:29:48 +02:00
|
|
|
*/
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
return 0;
|
2017-04-24 18:23:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2022-06-15 20:15:50 +02:00
|
|
|
* Function: bcmf_tx_poll_work
|
2021-10-02 05:26:43 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The function is called in order to perform an out-of-sequence TX poll.
|
|
|
|
* This is done:
|
|
|
|
*
|
2022-06-15 20:15:50 +02:00
|
|
|
* 1. After completion of a transmission (bcmf_netdev_notify_tx), and
|
2021-10-02 05:26:43 +02:00
|
|
|
* 2. When new TX data is available (bcmf_txavail).
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* arg - context of device to use
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-06-15 20:15:50 +02:00
|
|
|
static void bcmf_tx_poll_work(FAR void *arg)
|
2021-10-02 05:26:43 +02:00
|
|
|
{
|
|
|
|
FAR struct bcmf_dev_s *priv = (FAR struct bcmf_dev_s *)arg;
|
|
|
|
|
|
|
|
net_lock();
|
|
|
|
|
2022-06-15 20:15:50 +02:00
|
|
|
/* Ignore the notification if the interface is not yet up */
|
|
|
|
|
|
|
|
if (priv->bc_bifup)
|
2021-10-02 05:26:43 +02:00
|
|
|
{
|
2022-06-15 20:15:50 +02:00
|
|
|
/* Check if there is room in the hardware to hold another packet. */
|
2021-10-02 05:26:43 +02:00
|
|
|
|
2022-06-16 07:59:02 +02:00
|
|
|
while (bcmf_netdev_alloc_tx_frame(priv) == OK)
|
2022-06-15 20:15:50 +02:00
|
|
|
{
|
|
|
|
/* If so, then poll the network for new XMIT data */
|
|
|
|
|
|
|
|
devif_poll(&priv->bc_dev, bcmf_txpoll);
|
2022-06-16 07:59:02 +02:00
|
|
|
|
|
|
|
/* Break out the continuous send if :
|
|
|
|
* 1. IP stack has no data to send.
|
|
|
|
* 2. RX worker ready.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (priv->cur_tx_frame != NULL ||
|
|
|
|
!work_available(&priv->bc_rxwork))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2022-06-15 20:15:50 +02:00
|
|
|
}
|
2021-10-02 05:26:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
net_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_rxpoll_work
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-04-30 20:29:48 +02:00
|
|
|
* Process RX frames
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-30 20:29:48 +02:00
|
|
|
* arg - context of device to use
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-10-02 05:26:43 +02:00
|
|
|
static void bcmf_rxpoll_work(FAR void *arg)
|
2017-04-24 18:23:31 +02:00
|
|
|
{
|
2017-04-24 20:04:47 +02:00
|
|
|
FAR struct bcmf_dev_s *priv = (FAR struct bcmf_dev_s *)arg;
|
2022-06-16 07:59:02 +02:00
|
|
|
FAR void *oldbuf;
|
2017-04-24 18:23:31 +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();
|
|
|
|
|
2022-06-16 07:59:02 +02:00
|
|
|
/* Tx work will hold the d_buf until there is data to send,
|
|
|
|
* replace and cache the d_buf temporarily
|
|
|
|
*/
|
|
|
|
|
|
|
|
oldbuf = priv->bc_dev.d_buf;
|
|
|
|
|
2017-04-24 18:23:31 +02:00
|
|
|
bcmf_receive(priv);
|
|
|
|
|
2022-06-16 07:59:02 +02:00
|
|
|
priv->bc_dev.d_buf = oldbuf;
|
|
|
|
|
2017-04-24 18:23:31 +02:00
|
|
|
/* Check if a packet transmission just completed. If so, call bcmf_txdone.
|
|
|
|
* This may disable further Tx interrupts if there are no pending
|
|
|
|
* transmissions.
|
|
|
|
*/
|
|
|
|
|
2019-09-21 15:16:37 +02:00
|
|
|
#if 0
|
|
|
|
bcmf_txdone(priv);
|
|
|
|
#endif
|
2017-04-24 18:23:31 +02:00
|
|
|
net_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2022-06-15 20:15:50 +02:00
|
|
|
* Name: bcmf_netdev_notify_tx
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2022-06-15 20:15:50 +02:00
|
|
|
* Notify callback called when TX frame is avail or sent.
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-06-15 20:15:50 +02:00
|
|
|
void bcmf_netdev_notify_tx(FAR struct bcmf_dev_s *priv)
|
2017-04-24 18:23:31 +02:00
|
|
|
{
|
2018-08-22 21:51:53 +02:00
|
|
|
/* Schedule to perform a poll for new Tx data the worker thread. */
|
|
|
|
|
2021-10-02 05:26:43 +02:00
|
|
|
if (work_available(&priv->bc_pollwork))
|
|
|
|
{
|
|
|
|
work_queue(BCMFWORK, &priv->bc_pollwork,
|
2022-06-15 20:15:50 +02:00
|
|
|
bcmf_tx_poll_work, priv, 0);
|
2021-10-02 05:26:43 +02:00
|
|
|
}
|
2017-04-24 18:23:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-30 20:29:48 +02:00
|
|
|
* Name: bcmf_netdev_notify_rx
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-04-30 20:29:48 +02:00
|
|
|
* Notify callback called when RX frame is available
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
void bcmf_netdev_notify_rx(FAR struct bcmf_dev_s *priv)
|
2017-04-24 18:23:31 +02:00
|
|
|
{
|
2017-04-30 20:29:48 +02:00
|
|
|
/* Queue a job to process RX frames */
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2022-06-16 07:59:02 +02:00
|
|
|
if (work_available(&priv->bc_rxwork))
|
|
|
|
{
|
|
|
|
work_queue(BCMFWORK, &priv->bc_rxwork, bcmf_rxpoll_work, priv, 0);
|
|
|
|
}
|
2017-04-24 18:23:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_ifup
|
|
|
|
*
|
|
|
|
* 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-24 18:23:31 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int bcmf_ifup(FAR struct net_driver_s *dev)
|
|
|
|
{
|
2017-04-24 20:04:47 +02:00
|
|
|
FAR struct bcmf_dev_s *priv = (FAR struct bcmf_dev_s *)dev->d_private;
|
2022-06-18 22:43:36 +02:00
|
|
|
irqstate_t flags;
|
|
|
|
uint32_t out_len;
|
2022-06-24 20:31:21 +02:00
|
|
|
int ret = OK;
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2022-06-18 22:43:36 +02:00
|
|
|
/* Disable the hardware interrupt */
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
if (priv->bc_bifup)
|
|
|
|
{
|
|
|
|
goto errout_in_critical_section;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = bcmf_wl_active(priv, true);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
goto errout_in_critical_section;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable chip */
|
|
|
|
|
|
|
|
ret = bcmf_wl_enable(priv, true);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
goto errout_in_wl_active;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set customized MAC address */
|
|
|
|
|
|
|
|
if (bcmf_board_etheraddr(&priv->bc_dev.d_mac.ether))
|
|
|
|
{
|
|
|
|
out_len = ETHER_ADDR_LEN;
|
|
|
|
bcmf_cdc_iovar_request(priv, CHIP_STA_INTERFACE, true,
|
|
|
|
IOVAR_STR_CUR_ETHERADDR,
|
|
|
|
priv->bc_dev.d_mac.ether.ether_addr_octet,
|
|
|
|
&out_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Query MAC address */
|
|
|
|
|
|
|
|
out_len = ETHER_ADDR_LEN;
|
|
|
|
ret = bcmf_cdc_iovar_request(priv, CHIP_STA_INTERFACE, false,
|
|
|
|
IOVAR_STR_CUR_ETHERADDR,
|
|
|
|
priv->bc_dev.d_mac.ether.ether_addr_octet,
|
|
|
|
&out_len);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
|
|
|
goto errout_in_wl_active;
|
|
|
|
}
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2022-06-21 16:03:42 +02:00
|
|
|
if (strnlen(CONFIG_IEEE80211_BROADCOM_DEFAULT_COUNTRY, 2) == 2)
|
|
|
|
{
|
|
|
|
bcmf_wl_set_country_code(priv, CHIP_STA_INTERFACE,
|
|
|
|
CONFIG_IEEE80211_BROADCOM_DEFAULT_COUNTRY);
|
|
|
|
}
|
|
|
|
|
2020-08-06 19:41:45 +02:00
|
|
|
/* Instantiate MAC address from priv->bc_dev.d_mac.ether.ether_addr_octet */
|
2017-04-24 18:23:31 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ICMPv6
|
|
|
|
/* Set up IPv6 multicast address filtering */
|
|
|
|
|
|
|
|
bcmf_ipv6multicast(priv);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Enable the hardware interrupt */
|
|
|
|
|
|
|
|
priv->bc_bifup = true;
|
2022-06-18 22:43:36 +02:00
|
|
|
|
2022-06-20 08:56:37 +02:00
|
|
|
#ifdef CONFIG_IEEE80211_BROADCOM_LOWPOWER
|
|
|
|
bcmf_lowpower_poll(priv);
|
|
|
|
#endif
|
|
|
|
|
2022-06-18 22:43:36 +02:00
|
|
|
goto errout_in_critical_section;
|
|
|
|
|
|
|
|
errout_in_wl_active:
|
|
|
|
bcmf_wl_active(priv, false);
|
|
|
|
|
|
|
|
errout_in_critical_section:
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
|
2022-06-24 20:31:21 +02:00
|
|
|
return ret;
|
2017-04-24 18:23:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_ifdown
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Stop the interface.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-24 18:23:31 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int bcmf_ifdown(FAR struct net_driver_s *dev)
|
|
|
|
{
|
2017-04-24 20:04:47 +02:00
|
|
|
FAR struct bcmf_dev_s *priv = (FAR struct bcmf_dev_s *)dev->d_private;
|
2017-04-24 18:23:31 +02:00
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
/* Disable the hardware interrupt */
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
2022-06-18 22:43:36 +02:00
|
|
|
if (priv->bc_bifup)
|
|
|
|
{
|
2022-06-20 08:56:37 +02:00
|
|
|
#ifdef CONFIG_IEEE80211_BROADCOM_LOWPOWER
|
|
|
|
if (!work_available(&priv->lp_work))
|
|
|
|
{
|
|
|
|
work_cancel(LPWORK, &priv->lp_work);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-06-18 22:43:36 +02:00
|
|
|
bcmf_wl_enable(priv, false);
|
|
|
|
bcmf_wl_active(priv, false);
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2022-06-18 22:43:36 +02:00
|
|
|
/* Mark the device "down" */
|
|
|
|
|
|
|
|
priv->bc_bifup = false;
|
|
|
|
}
|
2017-04-24 18:23:31 +02:00
|
|
|
|
|
|
|
leave_critical_section(flags);
|
2022-06-18 22:43:36 +02:00
|
|
|
|
2017-04-24 18:23:31 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2022-06-20 08:56:37 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_lowpower_work
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Process low power saving dueto work timer expiration
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* arg - context of device to use
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_IEEE80211_BROADCOM_LOWPOWER
|
|
|
|
static void bcmf_lowpower_work(FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct bcmf_dev_s *priv = (FAR struct bcmf_dev_s *)arg;
|
|
|
|
irqstate_t flags;
|
|
|
|
clock_t ticks;
|
|
|
|
clock_t timeout;
|
|
|
|
|
|
|
|
if (priv->bc_bifup)
|
|
|
|
{
|
|
|
|
/* Disable the hardware interrupt */
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
ticks = clock_systime_ticks() - priv->lp_ticks;
|
|
|
|
timeout = SEC2TICK(CONFIG_IEEE80211_BROADCOM_LOWPOWER_TIMEOUT);
|
|
|
|
|
|
|
|
if (ticks >= timeout)
|
|
|
|
{
|
|
|
|
leave_critical_section(flags);
|
|
|
|
bcmf_wl_set_pm(priv, PM_MAX);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
work_queue(LPWORK, &priv->lp_work, bcmf_lowpower_work,
|
|
|
|
priv, timeout - ticks);
|
|
|
|
leave_critical_section(flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_lowpower_poll
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Polling low power
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* arg - context of device to use
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void bcmf_lowpower_poll(FAR struct bcmf_dev_s *priv)
|
|
|
|
{
|
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
if (priv->bc_bifup)
|
|
|
|
{
|
|
|
|
bcmf_wl_set_pm(priv, PM_FAST);
|
|
|
|
|
|
|
|
/* Disable the hardware interrupt */
|
|
|
|
|
|
|
|
flags = enter_critical_section();
|
|
|
|
|
|
|
|
priv->lp_ticks = clock_systime_ticks();
|
|
|
|
if (work_available(&priv->lp_work) && priv->lp_mode != PM_MAX)
|
|
|
|
{
|
|
|
|
work_queue(LPWORK, &priv->lp_work, bcmf_lowpower_work, priv,
|
|
|
|
SEC2TICK(CONFIG_IEEE80211_BROADCOM_LOWPOWER_TIMEOUT));
|
|
|
|
}
|
|
|
|
|
|
|
|
leave_critical_section(flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-04-24 18:23:31 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_txavail
|
|
|
|
*
|
|
|
|
* 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-24 18:23:31 +02:00
|
|
|
* dev - Reference to the NuttX driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called in normal user mode
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int bcmf_txavail(FAR struct net_driver_s *dev)
|
|
|
|
{
|
2017-04-24 20:04:47 +02:00
|
|
|
FAR struct bcmf_dev_s *priv = (FAR struct bcmf_dev_s *)dev->d_private;
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2022-06-20 08:56:37 +02:00
|
|
|
#ifdef CONFIG_IEEE80211_BROADCOM_LOWPOWER
|
|
|
|
bcmf_lowpower_poll(priv);
|
|
|
|
#endif
|
2022-06-15 20:15:50 +02:00
|
|
|
bcmf_netdev_notify_tx(priv);
|
2017-04-24 18:23:31 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_addmac
|
|
|
|
*
|
|
|
|
* 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-24 18:23:31 +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
|
|
|
#if defined(CONFIG_NET_MCASTGROUP) || defined(CONFIG_NET_ICMPv6)
|
2017-04-24 18:23:31 +02:00
|
|
|
static int bcmf_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac)
|
|
|
|
{
|
2017-04-24 20:04:47 +02:00
|
|
|
FAR struct bcmf_dev_s *priv = (FAR struct bcmf_dev_s *)dev->d_private;
|
2017-04-24 18:23:31 +02:00
|
|
|
|
|
|
|
/* Add the MAC address to the hardware multicast routing table */
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_rmmac
|
|
|
|
*
|
|
|
|
* Description:
|
2020-08-06 19:41:45 +02:00
|
|
|
* NuttX Callback: Remove the specified MAC address from the hardware
|
|
|
|
* multicast address filtering
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-24 18:23:31 +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-24 18:23:31 +02:00
|
|
|
static int bcmf_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac)
|
|
|
|
{
|
2017-04-24 20:04:47 +02:00
|
|
|
FAR struct bcmf_dev_s *priv = (FAR struct bcmf_dev_s *)dev->d_private;
|
2017-04-24 18:23:31 +02:00
|
|
|
|
|
|
|
/* Add the MAC address to the hardware multicast routing table */
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_ipv6multicast
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Configure the IPv6 multicast MAC address.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-24 18:23:31 +02:00
|
|
|
* priv - A reference to the private driver state structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; Negated errno on failure.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ICMPv6
|
2017-04-24 20:04:47 +02:00
|
|
|
static void bcmf_ipv6multicast(FAR struct bcmf_dev_s *priv)
|
2017-04-24 18:23:31 +02:00
|
|
|
{
|
|
|
|
FAR struct net_driver_s *dev;
|
|
|
|
uint16_t tmp16;
|
|
|
|
uint8_t mac[6];
|
|
|
|
|
|
|
|
/* For ICMPv6, we need to add the IPv6 multicast address
|
|
|
|
*
|
|
|
|
* For IPv6 multicast addresses, the Ethernet MAC is derived by
|
|
|
|
* the four low-order octets OR'ed with the MAC 33:33:00:00:00:00,
|
|
|
|
* so for example the IPv6 address FF02:DEAD:BEEF::1:3 would map
|
|
|
|
* to the Ethernet MAC address 33:33:00:01:00:03.
|
|
|
|
*
|
|
|
|
* NOTES: This appears correct for the ICMPv6 Router Solicitation
|
|
|
|
* Message, but the ICMPv6 Neighbor Solicitation message seems to
|
|
|
|
* use 33:33:ff:01:00:03.
|
|
|
|
*/
|
|
|
|
|
|
|
|
mac[0] = 0x33;
|
|
|
|
mac[1] = 0x33;
|
|
|
|
|
2017-11-01 13:58:33 +01:00
|
|
|
dev = &priv->bc_dev;
|
2017-04-24 18:23:31 +02:00
|
|
|
tmp16 = dev->d_ipv6addr[6];
|
|
|
|
mac[2] = 0xff;
|
|
|
|
mac[3] = tmp16 >> 8;
|
|
|
|
|
|
|
|
tmp16 = dev->d_ipv6addr[7];
|
|
|
|
mac[4] = tmp16 & 0xff;
|
|
|
|
mac[5] = tmp16 >> 8;
|
|
|
|
|
|
|
|
ninfo("IPv6 Multicast: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
|
|
|
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
bcmf_addmac(dev, mac);
|
2017-04-24 18:23:31 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
|
|
|
/* Add the IPv6 all link-local nodes Ethernet address. This is the
|
|
|
|
* address that we expect to receive ICMPv6 Router Advertisement
|
|
|
|
* packets.
|
|
|
|
*/
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
bcmf_addmac(dev, g_ipv6_ethallnodes.ether_addr_octet);
|
2017-04-24 18:23:31 +02:00
|
|
|
#endif /* CONFIG_NET_ICMPv6_AUTOCONF */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_ICMPv6_ROUTER
|
|
|
|
/* Add the IPv6 all link-local routers Ethernet address. This is the
|
|
|
|
* address that we expect to receive ICMPv6 Router Solicitation
|
|
|
|
* packets.
|
|
|
|
*/
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
bcmf_addmac(dev, g_ipv6_ethallrouters.ether_addr_octet);
|
2017-04-24 18:23:31 +02:00
|
|
|
#endif /* CONFIG_NET_ICMPv6_ROUTER */
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NET_ICMPv6 */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bcmf_ioctl
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Handle network IOCTL commands directed to this device.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-24 18:23:31 +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 bcmf_ioctl(FAR struct net_driver_s *dev, int cmd,
|
|
|
|
unsigned long arg)
|
|
|
|
{
|
2017-04-28 19:28:29 +02:00
|
|
|
FAR struct bcmf_dev_s *priv = (FAR struct bcmf_dev_s *)dev->d_private;
|
2022-06-18 22:43:36 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!priv->bc_bifup)
|
|
|
|
{
|
|
|
|
wlerr("ERROR: invaild state "
|
|
|
|
"(IFF_DOWN, unable to execute command: %x)\n", cmd);
|
|
|
|
return -EPERM;
|
|
|
|
}
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2022-06-20 08:56:37 +02:00
|
|
|
#ifdef CONFIG_IEEE80211_BROADCOM_LOWPOWER
|
|
|
|
bcmf_lowpower_poll(priv);
|
|
|
|
#endif
|
|
|
|
|
2017-04-24 18:23:31 +02:00
|
|
|
/* Decode and dispatch the driver-specific IOCTL command */
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
2017-04-28 19:28:29 +02:00
|
|
|
case SIOCSIWSCAN:
|
2017-05-14 16:39:53 +02:00
|
|
|
ret = bcmf_wl_start_scan(priv, (struct iwreq *)arg);
|
2017-04-28 19:28:29 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIWSCAN:
|
2017-05-14 16:39:53 +02:00
|
|
|
ret = bcmf_wl_get_scan_results(priv, (struct iwreq *)arg);
|
2017-04-28 19:28:29 +02:00
|
|
|
break;
|
|
|
|
|
2017-05-02 16:48:13 +02:00
|
|
|
case SIOCSIFHWADDR: /* Set device MAC address */
|
2017-05-04 02:20:57 +02:00
|
|
|
ret = bcmf_wl_set_mac_address(priv, (struct ifreq *)arg);
|
2017-04-30 20:29:48 +02:00
|
|
|
break;
|
|
|
|
|
2017-05-02 16:48:13 +02:00
|
|
|
case SIOCSIWAUTH:
|
2017-05-04 02:20:57 +02:00
|
|
|
ret = bcmf_wl_set_auth_param(priv, (struct iwreq *)arg);
|
2017-05-02 16:48:13 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIWENCODEEXT:
|
2017-05-04 02:20:57 +02:00
|
|
|
ret = bcmf_wl_set_encode_ext(priv, (struct iwreq *)arg);
|
2017-05-02 16:48:13 +02:00
|
|
|
break;
|
|
|
|
|
2017-04-26 20:30:18 +02:00
|
|
|
case SIOCSIWFREQ: /* Set channel/frequency (Hz) */
|
|
|
|
wlwarn("WARNING: SIOCSIWFREQ not implemented\n");
|
|
|
|
ret = -ENOSYS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIWFREQ: /* Get channel/frequency (Hz) */
|
2022-06-17 08:47:26 +02:00
|
|
|
ret = bcmf_wl_get_channel(priv, (struct iwreq *)arg);
|
2017-04-26 20:30:18 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIWMODE: /* Set operation mode */
|
2017-05-04 02:20:57 +02:00
|
|
|
ret = bcmf_wl_set_mode(priv, (struct iwreq *)arg);
|
2017-04-26 20:30:18 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIWMODE: /* Get operation mode */
|
2022-06-17 08:47:26 +02:00
|
|
|
ret = bcmf_wl_get_mode(priv, (struct iwreq *)arg);
|
2017-04-26 20:30:18 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIWAP: /* Set access point MAC addresses */
|
2022-06-17 08:47:26 +02:00
|
|
|
ret = bcmf_wl_set_bssid(priv, (struct iwreq *)arg);
|
2017-04-26 20:30:18 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIWAP: /* Get access point MAC addresses */
|
2022-06-17 08:47:26 +02:00
|
|
|
ret = bcmf_wl_get_bssid(priv, (struct iwreq *)arg);
|
2017-04-26 20:30:18 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIWESSID: /* Set ESSID (network name) */
|
2017-05-04 02:20:57 +02:00
|
|
|
ret = bcmf_wl_set_ssid(priv, (struct iwreq *)arg);
|
2017-04-26 20:30:18 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIWESSID: /* Get ESSID */
|
2022-06-17 08:47:26 +02:00
|
|
|
ret = bcmf_wl_get_ssid(priv, (struct iwreq *)arg);
|
2017-04-26 20:30:18 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIWRATE: /* Set default bit rate (bps) */
|
|
|
|
wlwarn("WARNING: SIOCSIWRATE not implemented\n");
|
|
|
|
ret = -ENOSYS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIWRATE: /* Get default bit rate (bps) */
|
2022-06-17 08:47:26 +02:00
|
|
|
ret = bcmf_wl_get_rate(priv, (struct iwreq *)arg);
|
2017-04-26 20:30:18 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIWTXPOW: /* Set transmit power (dBm) */
|
|
|
|
wlwarn("WARNING: SIOCSIWTXPOW not implemented\n");
|
|
|
|
ret = -ENOSYS;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIWTXPOW: /* Get transmit power (dBm) */
|
2022-06-17 08:47:26 +02:00
|
|
|
ret = bcmf_wl_get_txpower(priv, (struct iwreq *)arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIWSENS: /* Get transmit power (dBm) */
|
|
|
|
ret = bcmf_wl_get_rssi(priv, (struct iwreq *)arg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIWRANGE: /* Get range of parameters */
|
|
|
|
ret = bcmf_wl_get_iwrange(priv, (struct iwreq *)arg);
|
2017-04-26 20:30:18 +02:00
|
|
|
break;
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2022-06-21 16:03:42 +02:00
|
|
|
case SIOCSIWCOUNTRY: /* Set country code */
|
|
|
|
ret = bcmf_wl_set_country(priv, (struct iwreq *)arg);
|
|
|
|
break;
|
|
|
|
|
2022-06-23 08:42:08 +02:00
|
|
|
case SIOCGIWCOUNTRY: /* Get country code */
|
|
|
|
ret = bcmf_wl_get_country(priv, (struct iwreq *)arg);
|
|
|
|
break;
|
|
|
|
|
2017-04-24 18:23:31 +02:00
|
|
|
default:
|
2022-06-18 22:43:36 +02:00
|
|
|
nerr("ERROR: Unrecognized IOCTL command: %x\n", cmd);
|
2017-04-26 20:30:18 +02:00
|
|
|
ret = -ENOTTY; /* Special return value for this case */
|
|
|
|
break;
|
2017-04-24 18:23:31 +02:00
|
|
|
}
|
|
|
|
|
2017-04-26 20:30:18 +02:00
|
|
|
return ret;
|
2017-04-24 18:23:31 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-24 18:43:57 +02:00
|
|
|
* Name: bcmf_netdev_register
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-04-24 20:04:47 +02:00
|
|
|
* Register a network driver and set Broadcom chip in a proper state
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2017-04-24 20:04:47 +02:00
|
|
|
* priv - Broadcom driver device
|
2017-04-24 18:23:31 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; Negated errno on failure.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-24 20:04:47 +02:00
|
|
|
int bcmf_netdev_register(FAR struct bcmf_dev_s *priv)
|
2017-04-24 18:23:31 +02:00
|
|
|
{
|
2017-04-24 20:04:47 +02:00
|
|
|
/* Initialize network driver structure */
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2017-04-24 20:04:47 +02:00
|
|
|
memset(&priv->bc_dev, 0, sizeof(priv->bc_dev));
|
2017-04-24 18:23:31 +02:00
|
|
|
priv->bc_dev.d_ifup = bcmf_ifup; /* I/F up (new IP address) callback */
|
|
|
|
priv->bc_dev.d_ifdown = bcmf_ifdown; /* I/F down callback */
|
|
|
|
priv->bc_dev.d_txavail = bcmf_txavail; /* New TX data callback */
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
2017-04-24 18:23:31 +02:00
|
|
|
priv->bc_dev.d_addmac = bcmf_addmac; /* Add multicast MAC address */
|
|
|
|
priv->bc_dev.d_rmmac = bcmf_rmmac; /* Remove multicast MAC address */
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NETDEV_IOCTL
|
|
|
|
priv->bc_dev.d_ioctl = bcmf_ioctl; /* Handle network IOCTL commands */
|
|
|
|
#endif
|
2020-08-04 12:31:31 +02:00
|
|
|
priv->bc_dev.d_private = priv; /* Used to recover private state from dev */
|
2017-04-24 18:23:31 +02:00
|
|
|
|
2017-04-30 20:29:48 +02:00
|
|
|
/* Initialize network stack interface buffer */
|
|
|
|
|
2018-08-21 20:46:00 +02:00
|
|
|
priv->cur_tx_frame = NULL;
|
|
|
|
priv->bc_dev.d_buf = NULL;
|
2017-04-30 20:29:48 +02:00
|
|
|
|
2022-06-18 22:43:36 +02:00
|
|
|
/* Initialize MAC address */
|
2022-06-18 20:10:33 +02:00
|
|
|
|
2022-06-18 22:43:36 +02:00
|
|
|
bcmf_board_etheraddr(&priv->bc_dev.d_mac.ether);
|
2017-04-24 20:04:47 +02:00
|
|
|
|
2017-04-24 18:23:31 +02:00
|
|
|
/* Register the device with the OS so that socket IOCTLs can be performed */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
netdev_register(&priv->bc_dev, NET_LL_IEEE80211);
|
2017-04-24 18:23:31 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET && CONFIG_IEEE80211_BROADCOM_FULLMAC */
|