2018-03-31 22:55:03 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* wireless/bluetooth/bt_netdev.c
|
2024-09-11 09:04:25 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
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
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
2021-02-19 09:38:00 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-03-31 22:55:03 +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.
|
2018-03-31 22:55:03 +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>
|
|
|
|
|
2021-05-14 04:03:23 +02:00
|
|
|
#include <nuttx/spinlock.h>
|
2018-03-31 22:55:03 +02:00
|
|
|
#include <nuttx/kmalloc.h>
|
|
|
|
#include <nuttx/signal.h>
|
|
|
|
#include <nuttx/wqueue.h>
|
|
|
|
#include <nuttx/mm/iob.h>
|
|
|
|
#include <nuttx/net/netdev.h>
|
|
|
|
#include <nuttx/net/radiodev.h>
|
|
|
|
#include <nuttx/net/bluetooth.h>
|
|
|
|
#include <nuttx/net/sixlowpan.h>
|
2018-04-29 20:43:09 +02:00
|
|
|
#include <nuttx/wireless/bluetooth/bt_core.h>
|
2020-09-20 21:45:09 +02:00
|
|
|
#include <netpacket/bluetooth.h>
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
#include "bt_hcicore.h"
|
2020-09-20 21:45:09 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_WIRELESS_BLUETOOTH_HOST
|
2018-04-01 20:25:30 +02:00
|
|
|
#include "bt_l2cap.h"
|
|
|
|
#include "bt_conn.h"
|
2020-09-20 21:45:09 +02:00
|
|
|
#endif
|
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
#include "bt_ioctl.h"
|
|
|
|
|
|
|
|
#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_BLUETOOTH)
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* 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)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Frame size */
|
|
|
|
|
2018-04-01 23:21:58 +02:00
|
|
|
#if BLUETOOTH_MAX_FRAMELEN > CONFIG_IOB_BUFSIZE
|
|
|
|
# error CONFIG_IOB_BUFSIZE to small for max Bluetooth frame
|
2018-03-31 22:55:03 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* This is our private version of the MAC callback structure */
|
|
|
|
|
|
|
|
struct btnet_callback_s
|
|
|
|
{
|
|
|
|
/* This holds the information visible to the MAC layer */
|
|
|
|
|
|
|
|
FAR struct btnet_driver_s *bc_priv; /* Our priv data */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The btnet_driver_s encapsulates all state information for a single
|
|
|
|
* Bluetooth device interface.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct btnet_driver_s
|
|
|
|
{
|
|
|
|
/* This holds the information visible to the NuttX network */
|
|
|
|
|
2018-04-01 20:25:30 +02:00
|
|
|
struct radio_driver_s bd_dev; /* Interface understood by the network */
|
|
|
|
/* Cast compatible with struct btnet_driver_s */
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
/* For internal use by this driver */
|
|
|
|
|
2018-04-01 20:25:30 +02:00
|
|
|
bool bd_bifup; /* true:ifup false:ifdown */
|
|
|
|
struct work_s bd_pollwork; /* Defer poll work to the work queue */
|
2020-09-20 21:45:09 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_WIRELESS_BLUETOOTH_HOST
|
2018-04-01 20:25:30 +02:00
|
|
|
struct bt_conn_cb_s bd_hcicb; /* HCI connection status callbacks */
|
|
|
|
struct bt_l2cap_chan_s bd_l2capcb; /* L2CAP status callbacks */
|
2020-09-20 21:45:09 +02:00
|
|
|
#else
|
|
|
|
struct bt_hci_cb_s bd_hcicb; /* HCI RAW packet callbacks */
|
|
|
|
#endif
|
2018-03-31 22:55:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* Utility functions ********************************************************/
|
|
|
|
|
2018-04-14 17:23:08 +02:00
|
|
|
static int btnet_advertise(FAR struct net_driver_s *netdev);
|
|
|
|
static inline void btnet_netmask(FAR struct net_driver_s *netdev);
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2020-04-23 08:31:46 +02:00
|
|
|
/* Bluetooth callback functions *********************************************/
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2020-09-20 21:45:09 +02:00
|
|
|
#ifdef CONFIG_WIRELESS_BLUETOOTH_HOST
|
2018-04-01 20:25:30 +02:00
|
|
|
/* L2CAP callbacks */
|
|
|
|
|
|
|
|
static void btnet_l2cap_connected(FAR struct bt_conn_s *conn,
|
|
|
|
FAR void *context, uint16_t cid);
|
|
|
|
static void btnet_l2cap_disconnected(FAR struct bt_conn_s *conn,
|
|
|
|
FAR void *context, uint16_t cid);
|
|
|
|
static void btnet_l2cap_encrypt_change(FAR struct bt_conn_s *conn,
|
|
|
|
FAR void *context, uint16_t cid);
|
|
|
|
static void btnet_l2cap_receive(FAR struct bt_conn_s *conn,
|
|
|
|
FAR struct bt_buf_s *buf, FAR void *context, uint16_t cid);
|
|
|
|
|
|
|
|
/* HCI callbacks */
|
|
|
|
|
|
|
|
static void btnet_hci_connected(FAR struct bt_conn_s *conn,
|
|
|
|
FAR void *context);
|
|
|
|
static void btnet_hci_disconnected(FAR struct bt_conn_s *conn,
|
|
|
|
FAR void *context);
|
2020-09-20 21:45:09 +02:00
|
|
|
#else
|
|
|
|
static void btnet_hci_received(FAR struct bt_buf_s *buf, FAR void *context);
|
|
|
|
#endif
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
/* Network interface support ************************************************/
|
2019-12-24 17:37:30 +01:00
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
/* Common TX logic */
|
|
|
|
|
2018-04-14 17:23:08 +02:00
|
|
|
static int btnet_txpoll_callback(FAR struct net_driver_s *netdev);
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
/* NuttX callback functions */
|
|
|
|
|
2018-04-14 17:23:08 +02:00
|
|
|
static int btnet_ifup(FAR struct net_driver_s *netdev);
|
|
|
|
static int btnet_ifdown(FAR struct net_driver_s *netdev);
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
static void btnet_txavail_work(FAR void *arg);
|
2018-04-14 17:23:08 +02:00
|
|
|
static int btnet_txavail(FAR struct net_driver_s *netdev);
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
2018-04-14 17:23:08 +02:00
|
|
|
static int btnet_addmac(FAR struct net_driver_s *netdev,
|
2018-03-31 22:55:03 +02:00
|
|
|
FAR const uint8_t *mac);
|
2018-04-14 17:23:08 +02:00
|
|
|
static int btnet_rmmac(FAR struct net_driver_s *netdev,
|
2018-03-31 22:55:03 +02:00
|
|
|
FAR const uint8_t *mac);
|
|
|
|
#endif
|
|
|
|
static int btnet_get_mhrlen(FAR struct radio_driver_s *netdev,
|
|
|
|
FAR const void *meta);
|
|
|
|
static int btnet_req_data(FAR struct radio_driver_s *netdev,
|
|
|
|
FAR const void *meta, FAR struct iob_s *framelist);
|
|
|
|
static int btnet_properties(FAR struct radio_driver_s *netdev,
|
|
|
|
FAR struct radiodev_properties_s *properties);
|
|
|
|
|
2020-09-20 21:45:09 +02:00
|
|
|
#ifdef CONFIG_WIRELESS_BLUETOOTH_HOST
|
|
|
|
static int btnet_req_l2cap_data(FAR struct btnet_driver_s *priv,
|
|
|
|
FAR struct bluetooth_frame_meta_s *meta,
|
|
|
|
FAR struct iob_s *framelist);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int btnet_req_hci_data(FAR struct btnet_driver_s *priv,
|
|
|
|
FAR struct bluetooth_frame_meta_s *meta,
|
|
|
|
FAR struct iob_s *framelist);
|
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
static struct sixlowpan_reassbuf_s g_iobuffer;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btnet_advertise
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Advertise the MAC and IPv6 address for this node.
|
|
|
|
*
|
|
|
|
* Creates a MAC-based IP address from the 6-byte address address assigned
|
|
|
|
* to the device.
|
|
|
|
*
|
|
|
|
* 128 112 96 80 64 48 32 16
|
|
|
|
* ---- ---- ---- ---- ---- ---- ---- ----
|
|
|
|
* fe80 0000 0000 0000 0200 xxxx xxxx xxxx
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-14 17:23:08 +02:00
|
|
|
static int btnet_advertise(FAR struct net_driver_s *netdev)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
|
|
|
FAR uint8_t *addr;
|
|
|
|
|
2018-04-14 17:23:08 +02:00
|
|
|
DEBUGASSERT(netdev != NULL && netdev->d_private != NULL);
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-04-04 18:57:36 +02:00
|
|
|
/* Get the 6-byte local address from the device.
|
|
|
|
*
|
|
|
|
* REVISIT: The use of the g_btdev global restricts the implementation to
|
|
|
|
* a single Bluetooth device.
|
|
|
|
*/
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-04-06 00:38:53 +02:00
|
|
|
addr = g_btdev.bdaddr.val;
|
2018-04-04 18:57:36 +02:00
|
|
|
|
|
|
|
/* Set the MAC address using 6-byte local address from the device. */
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-04-14 17:23:08 +02:00
|
|
|
BLUETOOTH_ADDRCOPY(netdev->d_mac.radio.nv_addr, addr);
|
|
|
|
netdev->d_mac.radio.nv_addrlen = BLUETOOTH_ADDRSIZE;
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
|
|
|
/* Set the IP address based on the 6-byte address */
|
|
|
|
|
2018-04-14 17:23:08 +02:00
|
|
|
netdev->d_ipv6addr[0] = HTONS(0xfe80);
|
|
|
|
netdev->d_ipv6addr[1] = 0;
|
|
|
|
netdev->d_ipv6addr[2] = 0;
|
|
|
|
netdev->d_ipv6addr[3] = 0;
|
|
|
|
netdev->d_ipv6addr[4] = HTONS(0x0200);
|
|
|
|
netdev->d_ipv6addr[5] = (uint16_t)addr[0] << 8 | (uint16_t)addr[1];
|
|
|
|
netdev->d_ipv6addr[6] = (uint16_t)addr[2] << 8 | (uint16_t)addr[3];
|
|
|
|
netdev->d_ipv6addr[7] = (uint16_t)addr[4] << 8 | (uint16_t)addr[5];
|
2018-03-31 22:55:03 +02:00
|
|
|
#endif
|
2018-04-04 18:57:36 +02:00
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btnet_netmask
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Create a netmask of a MAC-based IP address which is based on the 6-byte
|
|
|
|
* Bluetooth address.
|
|
|
|
*
|
|
|
|
* 128 112 96 80 64 48 32 16
|
|
|
|
* ---- ---- ---- ---- ---- ---- ---- ----
|
|
|
|
* fe80 0000 0000 0000 xxxx xxxx xxxx xxxx
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-14 17:23:08 +02:00
|
|
|
static inline void btnet_netmask(FAR struct net_driver_s *netdev)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2018-04-14 17:23:08 +02:00
|
|
|
netdev->d_ipv6netmask[0] = 0xffff;
|
|
|
|
netdev->d_ipv6netmask[1] = 0xffff;
|
|
|
|
netdev->d_ipv6netmask[2] = 0xffff;
|
|
|
|
netdev->d_ipv6netmask[3] = 0xffff;
|
|
|
|
netdev->d_ipv6netmask[4] = 0;
|
|
|
|
netdev->d_ipv6netmask[5] = 0;
|
|
|
|
netdev->d_ipv6netmask[6] = 0;
|
|
|
|
netdev->d_ipv6netmask[7] = 0;
|
2018-03-31 22:55:03 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-09-20 21:45:09 +02:00
|
|
|
#ifdef CONFIG_WIRELESS_BLUETOOTH_HOST
|
2018-03-31 22:55:03 +02:00
|
|
|
/****************************************************************************
|
2018-04-01 20:25:30 +02:00
|
|
|
* Name: btnet_hci_connect/disconnect/encrypt_change
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* There are callbacks that are involved by the core HCI layer when a
|
|
|
|
* change is detected in the connection status or encryption.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* conn - The connection whose
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* No assumption should be made about the thread of execution that these
|
|
|
|
* are called from
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void btnet_l2cap_connected(FAR struct bt_conn_s *conn,
|
|
|
|
FAR void *context, uint16_t cid)
|
|
|
|
{
|
|
|
|
wlinfo("Connected\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void btnet_l2cap_disconnected(FAR struct bt_conn_s *conn,
|
|
|
|
FAR void *context, uint16_t cid)
|
|
|
|
{
|
|
|
|
wlinfo("Disconnected\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void btnet_l2cap_encrypt_change(FAR struct bt_conn_s *conn,
|
|
|
|
FAR void *context, uint16_t cid)
|
|
|
|
{
|
|
|
|
wlinfo("Encryption change\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btnet_l2cap_receive
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2018-04-01 20:25:30 +02:00
|
|
|
* Handle received frames forward by the Bluetooth L2CAP layer.
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; a negated errno value is returned on
|
|
|
|
* any failure. On success, the meta data and its contained iob will be
|
|
|
|
* freed. The meta data will be intact if this function returns a
|
|
|
|
* failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-01 20:25:30 +02:00
|
|
|
static void btnet_l2cap_receive(FAR struct bt_conn_s *conn,
|
|
|
|
FAR struct bt_buf_s *buf,
|
|
|
|
FAR void *context, uint16_t cid)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
2018-04-01 20:25:30 +02:00
|
|
|
FAR struct btnet_driver_s *priv;
|
|
|
|
FAR struct iob_s *frame;
|
|
|
|
struct bluetooth_frame_meta_s meta;
|
|
|
|
int ret = -ENODEV;
|
|
|
|
|
|
|
|
wlinfo("Received frame\n");
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-04-01 20:25:30 +02:00
|
|
|
DEBUGASSERT(conn != NULL && buf != NULL && buf->frame != NULL &&
|
|
|
|
context != NULL && cid < UINT8_MAX);
|
|
|
|
|
|
|
|
/* Detach the IOB frame from the buffer structure */
|
|
|
|
|
|
|
|
frame = buf->frame;
|
|
|
|
buf->frame = NULL;
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
/* Ignore the frame if the network is not up */
|
|
|
|
|
2018-04-01 20:25:30 +02:00
|
|
|
priv = (FAR struct btnet_driver_s *)context;
|
2018-03-31 22:55:03 +02:00
|
|
|
if (!priv->bd_bifup)
|
|
|
|
{
|
|
|
|
wlwarn("WARNING: Dropped... Network is down\n");
|
2018-04-01 20:25:30 +02:00
|
|
|
goto drop;
|
2018-03-31 22:55:03 +02:00
|
|
|
}
|
|
|
|
|
2018-04-01 20:25:30 +02:00
|
|
|
/* Make sure that the size/offset data matches the buffer structure data.
|
|
|
|
* REVISIT: Wouldn't it be better to just have one copy rather than having
|
|
|
|
* to synchronize?
|
|
|
|
*/
|
|
|
|
|
|
|
|
frame->io_len = buf->len;
|
|
|
|
frame->io_pktlen = buf->len;
|
|
|
|
frame->io_offset = (unsigned int)
|
|
|
|
((uintptr_t)buf->data - (uintptr_t)frame->io_data);
|
|
|
|
|
|
|
|
DEBUGASSERT(frame->io_len <= CONFIG_IOB_BUFSIZE);
|
|
|
|
DEBUGASSERT(frame->io_offset < CONFIG_IOB_BUFSIZE);
|
|
|
|
|
|
|
|
/* Construct the frame meta data.
|
|
|
|
* REVISIT: Where do we get the channel number?
|
|
|
|
*/
|
|
|
|
|
|
|
|
BLUETOOTH_ADDRCOPY(meta.bm_raddr.val, conn->src.val);
|
|
|
|
meta.bm_channel = cid;
|
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
/* Transfer the frame to the network logic */
|
|
|
|
|
|
|
|
net_lock();
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_BLUETOOTH
|
|
|
|
/* Invoke the PF_BLUETOOTH tap first. If the frame matches
|
|
|
|
* with a connected PF_BLUETOOTH socket, it will take the
|
|
|
|
* frame and return success.
|
|
|
|
*/
|
|
|
|
|
2018-04-01 20:25:30 +02:00
|
|
|
ret = bluetooth_input(&priv->bd_dev, frame, (FAR void *)&meta);
|
2018-03-31 22:55:03 +02:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
2018-04-01 20:25:30 +02:00
|
|
|
if (ret < 0)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
2018-04-01 20:25:30 +02:00
|
|
|
/* If the frame is not a 6LoWPAN frame, then thefirst byte at the
|
|
|
|
* io_offset should be a valid IPHC header.
|
2018-03-31 22:55:03 +02:00
|
|
|
*/
|
|
|
|
|
2022-02-07 10:13:27 +01:00
|
|
|
if ((frame->io_data[frame->io_offset] &
|
|
|
|
SIXLOWPAN_DISPATCH_NALP_MASK) == SIXLOWPAN_DISPATCH_NALP)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
|
|
|
wlwarn("WARNING: Dropped... Not a 6LoWPAN frame: %02x\n",
|
2022-02-07 10:13:27 +01:00
|
|
|
frame->io_data[frame->io_offset]);
|
2018-03-31 22:55:03 +02:00
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Make sure the our single packet buffer is attached */
|
|
|
|
|
|
|
|
priv->bd_dev.r_dev.d_buf = g_iobuffer.rb_buf;
|
|
|
|
|
|
|
|
/* And give the packet to 6LoWPAN */
|
|
|
|
|
2022-02-07 10:13:27 +01:00
|
|
|
ret = sixlowpan_input(&priv->bd_dev, frame, (FAR void *)&meta);
|
2018-03-31 22:55:03 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-01 20:25:30 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
drop:
|
|
|
|
|
|
|
|
/* Handle errors */
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2022-08-08 04:21:03 +02:00
|
|
|
iob_free(frame);
|
2018-04-01 20:25:30 +02:00
|
|
|
|
|
|
|
/* Increment statistics */
|
|
|
|
|
|
|
|
NETDEV_RXDROPPED(&priv->bd_dev.r_dev);
|
2018-03-31 22:55:03 +02:00
|
|
|
}
|
2018-04-01 20:25:30 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Increment statistics */
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-04-01 20:25:30 +02:00
|
|
|
NETDEV_RXPACKETS(&priv->bd_dev.r_dev);
|
|
|
|
NETDEV_RXIPV6(&priv->bd_dev.r_dev);
|
|
|
|
}
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-04-01 20:25:30 +02:00
|
|
|
/* Release our reference on the buffer */
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-04-01 20:25:30 +02:00
|
|
|
bt_buf_release(buf);
|
2018-03-31 22:55:03 +02:00
|
|
|
net_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2018-04-01 20:25:30 +02:00
|
|
|
* Name: btnet_hci_connect/disconnect
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* There are callbacks that are involved by the core HCI layer when a
|
|
|
|
* change is detected in the connection status.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* conn - The connection whose
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* No assumption should be made about the thread of execution that these
|
|
|
|
* are called from
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-01 20:25:30 +02:00
|
|
|
static void btnet_hci_connected(FAR struct bt_conn_s *conn,
|
|
|
|
FAR void *context)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
2018-04-01 20:25:30 +02:00
|
|
|
wlinfo("Connected\n");
|
2018-03-31 22:55:03 +02:00
|
|
|
}
|
|
|
|
|
2018-04-01 20:25:30 +02:00
|
|
|
static void btnet_hci_disconnected(FAR struct bt_conn_s *conn,
|
|
|
|
FAR void *context)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
2018-04-01 20:25:30 +02:00
|
|
|
wlinfo("Disconnected\n");
|
2018-03-31 22:55:03 +02:00
|
|
|
}
|
2020-09-20 21:45:09 +02:00
|
|
|
#else
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btnet_hci_received
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This callback is called from the RX queue handling when an HCI
|
|
|
|
* packet is received from controller.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* buf - The packet
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* No assumption should be made about the thread of execution that these
|
|
|
|
* are called from
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void btnet_hci_received(FAR struct bt_buf_s *buf, FAR void *context)
|
|
|
|
{
|
|
|
|
FAR struct btnet_driver_s *priv;
|
|
|
|
FAR struct iob_s *frame;
|
|
|
|
struct bluetooth_frame_meta_s meta;
|
|
|
|
int ret = -ENODEV;
|
|
|
|
|
|
|
|
wlinfo("Received frame\n");
|
|
|
|
|
|
|
|
DEBUGASSERT(buf != NULL && buf->frame != NULL);
|
|
|
|
|
|
|
|
/* Detach the IOB frame from the buffer structure */
|
|
|
|
|
|
|
|
frame = buf->frame;
|
|
|
|
buf->frame = NULL;
|
|
|
|
|
2022-08-04 13:57:43 +02:00
|
|
|
net_lock();
|
|
|
|
|
2020-09-20 21:45:09 +02:00
|
|
|
/* Ignore the frame if the network is not up */
|
|
|
|
|
|
|
|
priv = (FAR struct btnet_driver_s *)context;
|
|
|
|
if (!priv->bd_bifup)
|
|
|
|
{
|
|
|
|
wlwarn("WARNING: Dropped... Network is down\n");
|
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure that the size/offset data matches the buffer structure data. */
|
|
|
|
|
|
|
|
DEBUGASSERT(frame->io_offset == BLUETOOTH_H4_HDRLEN);
|
|
|
|
|
|
|
|
/* Rearrange IOB to consider H4 header */
|
|
|
|
|
|
|
|
frame->io_len = buf->len + frame->io_offset;
|
|
|
|
frame->io_pktlen = buf->len + frame->io_offset;
|
|
|
|
frame->io_offset = 0;
|
|
|
|
|
|
|
|
DEBUGASSERT(frame->io_len <= CONFIG_IOB_BUFSIZE);
|
|
|
|
|
|
|
|
/* Write H4 header */
|
|
|
|
|
|
|
|
switch (buf->type)
|
|
|
|
{
|
|
|
|
case BT_EVT:
|
|
|
|
frame->io_data[0] = HCI_EVENT_PKT;
|
|
|
|
break;
|
|
|
|
case BT_ACL_IN:
|
|
|
|
frame->io_data[0] = HCI_ACLDATA_PKT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
wlerr("Bad HCI type: %i\n", buf->type);
|
|
|
|
goto drop;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Construct the frame meta data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
meta.bm_channel = HCI_CHANNEL_RAW;
|
|
|
|
meta.bm_proto = BTPROTO_HCI;
|
|
|
|
|
|
|
|
/* Transfer the frame to the network logic */
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_BLUETOOTH
|
|
|
|
/* Invoke the PF_BLUETOOTH tap first. If the frame matches
|
|
|
|
* with a connected PF_BLUETOOTH socket, it will take the
|
|
|
|
* frame and return success.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret = bluetooth_input(&priv->bd_dev, frame, (FAR void *)&meta);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
drop:
|
|
|
|
|
|
|
|
/* Handle errors */
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2022-08-08 04:21:03 +02:00
|
|
|
iob_free(frame);
|
2020-09-20 21:45:09 +02:00
|
|
|
|
|
|
|
/* Increment statistics */
|
|
|
|
|
|
|
|
NETDEV_RXDROPPED(&priv->bd_dev.r_dev);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Increment statistics */
|
|
|
|
|
|
|
|
NETDEV_RXPACKETS(&priv->bd_dev.r_dev);
|
|
|
|
NETDEV_RXIPV6(&priv->bd_dev.r_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release our reference on the buffer */
|
|
|
|
|
|
|
|
net_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btnet_txpoll_callback
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2018-04-14 17:23:08 +02:00
|
|
|
* netdev - Reference to the NuttX driver state structure
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* OK on success; a negated errno on failure
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The network is locked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-14 17:23:08 +02:00
|
|
|
static int btnet_txpoll_callback(FAR struct net_driver_s *netdev)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
2020-04-23 08:31:46 +02:00
|
|
|
/* If zero is returned, the polling will continue until all connections
|
|
|
|
* have been examined.
|
2018-03-31 22:55:03 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btnet_ifup
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Bring up the Bluetooth interface when an IP address
|
|
|
|
* is provided
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2018-04-14 17:23:08 +02:00
|
|
|
* netdev - Reference to the NuttX driver state structure
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-14 17:23:08 +02:00
|
|
|
static int btnet_ifup(FAR struct net_driver_s *netdev)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
|
|
|
FAR struct btnet_driver_s *priv =
|
2018-04-14 17:23:08 +02:00
|
|
|
(FAR struct btnet_driver_s *)netdev->d_private;
|
2018-03-31 22:55:03 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Set the IP address based on the addressing assigned to the node */
|
|
|
|
|
2018-04-14 17:23:08 +02:00
|
|
|
ret = btnet_advertise(netdev);
|
2018-03-31 22:55:03 +02:00
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_NET_IPv6
|
2018-04-03 18:00:56 +02:00
|
|
|
wlinfo("Bringing up: IP %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
2018-04-14 17:23:08 +02:00
|
|
|
netdev->d_ipv6addr[0], netdev->d_ipv6addr[1],
|
|
|
|
netdev->d_ipv6addr[2], netdev->d_ipv6addr[3],
|
|
|
|
netdev->d_ipv6addr[4], netdev->d_ipv6addr[5],
|
|
|
|
netdev->d_ipv6addr[6], netdev->d_ipv6addr[7]);
|
2018-04-03 18:00:56 +02:00
|
|
|
wlinfo(" ADDR %02x:%02x:%02x:%02x:%02x:%02x\n",
|
2018-04-14 17:23:08 +02:00
|
|
|
netdev->d_mac.radio.nv_addr[0], netdev->d_mac.radio.nv_addr[1],
|
|
|
|
netdev->d_mac.radio.nv_addr[2], netdev->d_mac.radio.nv_addr[3],
|
|
|
|
netdev->d_mac.radio.nv_addr[4], netdev->d_mac.radio.nv_addr[5]);
|
2018-04-03 18:00:56 +02:00
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
#else
|
2018-04-03 18:00:56 +02:00
|
|
|
wlinfo("Bringing up: %02x:%02x:%02x:%02x:%02x:%02x\n",
|
2018-04-14 17:23:08 +02:00
|
|
|
netdev->d_mac.radio.nv_addr[0], netdev->d_mac.radio.nv_addr[1],
|
|
|
|
netdev->d_mac.radio.nv_addr[2], netdev->d_mac.radio.nv_addr[3],
|
|
|
|
netdev->d_mac.radio.nv_addr[4], netdev->d_mac.radio.nv_addr[5]);
|
2018-03-31 22:55:03 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* The interface is now up */
|
|
|
|
|
|
|
|
priv->bd_bifup = true;
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btnet_ifdown
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Stop the interface.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2018-04-14 17:23:08 +02:00
|
|
|
* netdev - Reference to the NuttX driver state structure
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-14 17:23:08 +02:00
|
|
|
static int btnet_ifdown(FAR struct net_driver_s *netdev)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
2018-04-14 17:23:08 +02:00
|
|
|
FAR struct btnet_driver_s *priv =
|
|
|
|
(FAR struct btnet_driver_s *)netdev->d_private;
|
2018-03-31 22:55:03 +02:00
|
|
|
irqstate_t flags;
|
|
|
|
|
|
|
|
/* Disable interruption */
|
|
|
|
|
arch, boards, drivers, include, sched, wireless: Change spinlock APIs.
Summary:
- This commit changes spinlock APIs (spin_lock_irqsave/spin_unlock_irqrestore)
- In the previous implementation, the global spinlock (i.e. g_irq_spin) was used.
- This commit allows to use caller specific spinlock but also supports to use
g_irq_spin for backword compatibility (In this case, NULL must be specified)
Impact:
- None
Testing:
- Tested with the following configurations
- spresnse:wifi, spresense:wifi_smp
- esp32-devkitc:smp (QEMU), sabre6-quad:smp (QEMU)
- maxi-bit:smp (QEMU), sim:smp
- stm32f4discovery:wifi
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-02-08 01:21:26 +01:00
|
|
|
flags = spin_lock_irqsave(NULL);
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
/* Put the EMAC in its reset, non-operational state. This should be
|
|
|
|
* a known configuration that will guarantee the btnet_ifup() always
|
|
|
|
* successfully brings the interface back up.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Mark the device "down" */
|
|
|
|
|
|
|
|
priv->bd_bifup = false;
|
arch, boards, drivers, include, sched, wireless: Change spinlock APIs.
Summary:
- This commit changes spinlock APIs (spin_lock_irqsave/spin_unlock_irqrestore)
- In the previous implementation, the global spinlock (i.e. g_irq_spin) was used.
- This commit allows to use caller specific spinlock but also supports to use
g_irq_spin for backword compatibility (In this case, NULL must be specified)
Impact:
- None
Testing:
- Tested with the following configurations
- spresnse:wifi, spresense:wifi_smp
- esp32-devkitc:smp (QEMU), sabre6-quad:smp (QEMU)
- maxi-bit:smp (QEMU), sim:smp
- stm32f4discovery:wifi
Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-02-08 01:21:26 +01:00
|
|
|
spin_unlock_irqrestore(NULL, flags);
|
2018-03-31 22:55:03 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btnet_txavail_work
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform an out-of-cycle poll on the worker thread.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* arg - Reference to the NuttX driver state structure (cast to void*)
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called on the higher priority worker thread.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void btnet_txavail_work(FAR void *arg)
|
|
|
|
{
|
|
|
|
FAR struct btnet_driver_s *priv = (FAR struct btnet_driver_s *)arg;
|
|
|
|
|
|
|
|
wlinfo("ifup=%u\n", priv->bd_bifup);
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
|
|
|
|
if (priv->bd_bifup)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
/* Make sure the our single packet buffer is attached */
|
|
|
|
|
|
|
|
priv->bd_dev.r_dev.d_buf = g_iobuffer.rb_buf;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Then poll the network for new XMIT data */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
devif_poll(&priv->bd_dev.r_dev, btnet_txpoll_callback);
|
2018-03-31 22:55:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
net_unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btnet_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.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2018-04-14 17:23:08 +02:00
|
|
|
* netdev - Reference to the NuttX driver state structure
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called in normal user mode
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-04-14 17:23:08 +02:00
|
|
|
static int btnet_txavail(FAR struct net_driver_s *netdev)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
2018-04-14 17:23:08 +02:00
|
|
|
FAR struct btnet_driver_s *priv =
|
|
|
|
(FAR struct btnet_driver_s *)netdev->d_private;
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
wlinfo("Available=%u\n", work_available(&priv->bd_pollwork));
|
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (work_available(&priv->bd_pollwork))
|
|
|
|
{
|
|
|
|
/* Schedule to serialize the poll on the worker thread. */
|
|
|
|
|
|
|
|
work_queue(LPWORK, &priv->bd_pollwork, btnet_txavail_work, priv, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btnet_addmac
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* NuttX Callback: Add the specified MAC address to the hardware multicast
|
|
|
|
* address filtering
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2018-04-14 17:23:08 +02:00
|
|
|
* netdev - Reference to the NuttX driver state structure
|
2018-03-31 22:55:03 +02:00
|
|
|
* mac - The MAC address to be added
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
2018-04-14 17:23:08 +02:00
|
|
|
static int btnet_addmac(FAR struct net_driver_s *netdev,
|
|
|
|
FAR const uint8_t *mac)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
2020-04-23 08:31:46 +02:00
|
|
|
/* Add the MAC address to the hardware multicast routing table.
|
|
|
|
* Not used with Bluetooth.
|
2018-03-31 22:55:03 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btnet_rmmac
|
|
|
|
*
|
|
|
|
* Description:
|
2020-04-23 08:31:46 +02:00
|
|
|
* NuttX Callback: Remove the specified MAC address from the hardware
|
|
|
|
* multicast address filtering
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
|
|
|
* Input Parameters:
|
2018-04-14 17:23:08 +02:00
|
|
|
* netdev - Reference to the NuttX driver state structure
|
2018-03-31 22:55:03 +02:00
|
|
|
* mac - The MAC address to be removed
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
2018-04-14 17:23:08 +02:00
|
|
|
static int btnet_rmmac(FAR struct net_driver_s *netdev,
|
|
|
|
FAR const uint8_t *mac)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
2020-04-23 08:31:46 +02:00
|
|
|
/* Remove the MAC address from the hardware multicast routing table
|
|
|
|
* Not used with Bluetooth.
|
2018-03-31 22:55:03 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btnet_get_mhrlen
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Calculate the MAC header length given the frame meta-data.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2018-04-14 17:23:08 +02:00
|
|
|
* netdev - The networkd device that will mediate the MAC interface
|
|
|
|
* meta - Obfuscated meta-data structure needed to create the radio
|
|
|
|
* MAC header
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* A non-negative MAC header length is returned on success; a negated
|
|
|
|
* errno value is returned on any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int btnet_get_mhrlen(FAR struct radio_driver_s *netdev,
|
2018-04-14 17:23:08 +02:00
|
|
|
FAR const void *meta)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
2020-09-20 21:45:09 +02:00
|
|
|
const struct bluetooth_frame_meta_s *btmeta = meta;
|
|
|
|
|
|
|
|
if (btmeta->bm_proto == BTPROTO_HCI)
|
|
|
|
{
|
|
|
|
/* the net device only requires the H4 header, the rest is already
|
|
|
|
* part of the packet
|
|
|
|
*/
|
|
|
|
|
|
|
|
return BLUETOOTH_H4_HDRLEN;
|
|
|
|
}
|
|
|
|
else if (btmeta->bm_proto == BTPROTO_L2CAP)
|
|
|
|
{
|
|
|
|
/* Report the complete header size, since H4 + ACL + L2CAP header
|
|
|
|
* will not be part of the packet
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* TODO: correct? */
|
|
|
|
|
|
|
|
return BLUETOOTH_MAX_HDRLEN;
|
|
|
|
}
|
2018-04-06 00:38:53 +02:00
|
|
|
|
|
|
|
return BLUETOOTH_MAX_HDRLEN;
|
2018-03-31 22:55:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btnet_req_data
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Requests the transfer of a list of frames to the MAC.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* netdev - The networkd device that will mediate the MAC interface
|
|
|
|
* meta - Obfuscated metadata structure needed to create the radio
|
|
|
|
* MAC header
|
|
|
|
* framelist - Head of a list of frames to be transferred.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) returned on success; a negated errno value is returned on
|
|
|
|
* any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int btnet_req_data(FAR struct radio_driver_s *netdev,
|
|
|
|
FAR const void *meta, FAR struct iob_s *framelist)
|
|
|
|
{
|
2018-04-01 22:00:40 +02:00
|
|
|
FAR struct btnet_driver_s *priv;
|
|
|
|
FAR struct bluetooth_frame_meta_s *btmeta;
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-04-01 22:00:40 +02:00
|
|
|
priv = (FAR struct btnet_driver_s *)netdev;
|
|
|
|
btmeta = (FAR struct bluetooth_frame_meta_s *)meta;
|
|
|
|
|
2020-10-29 03:47:00 +01:00
|
|
|
wlinfo("Received framelist\n");
|
|
|
|
DEBUGASSERT(priv != NULL && meta != NULL && framelist != NULL);
|
|
|
|
|
2020-09-20 21:45:09 +02:00
|
|
|
if (btmeta->bm_proto == BTPROTO_HCI)
|
|
|
|
{
|
|
|
|
return btnet_req_hci_data(priv, btmeta, framelist);
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_WIRELESS_BLUETOOTH_HOST
|
|
|
|
else if (btmeta->bm_proto == BTPROTO_L2CAP)
|
|
|
|
{
|
|
|
|
return btnet_req_l2cap_data(priv, btmeta, framelist);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_WIRELESS_BLUETOOTH_HOST
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btnet_req_l2cap_data
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Requests the transfer of a list of L2CAP frames to the MAC.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - Bluetooth network device
|
|
|
|
* btmeta - Bluetooth frame metadata
|
|
|
|
* framelist - Head of a list of L2CAP frames to be transferred.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) returned on success; a negated errno value is returned on
|
|
|
|
* any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int btnet_req_l2cap_data(FAR struct btnet_driver_s *priv,
|
|
|
|
FAR struct bluetooth_frame_meta_s *btmeta,
|
|
|
|
FAR struct iob_s *framelist)
|
|
|
|
{
|
|
|
|
FAR struct bt_conn_s *conn;
|
|
|
|
bt_addr_le_t peer;
|
|
|
|
FAR struct iob_s *iob;
|
|
|
|
FAR struct bt_buf_s *buf;
|
|
|
|
UNUSED(priv);
|
|
|
|
|
2018-04-01 22:00:40 +02:00
|
|
|
/* Create a connection structure for this peer if one does not already
|
|
|
|
* exist.
|
|
|
|
*
|
2018-04-02 14:38:31 +02:00
|
|
|
* Assumptions to REVISIT:
|
|
|
|
*
|
|
|
|
* 1. Role is Master (see bt_conn_create_le())
|
|
|
|
* 2. Address type is BT_ADDR_LE_PUBLIC (vs. BT_ADDR_LE_RANDOM)
|
2018-04-01 22:00:40 +02:00
|
|
|
*/
|
2018-04-02 14:38:31 +02:00
|
|
|
|
|
|
|
BLUETOOTH_ADDRCOPY(peer.val, btmeta->bm_raddr.val);
|
|
|
|
peer.type = BT_ADDR_LE_PUBLIC;
|
|
|
|
|
|
|
|
conn = bt_conn_create_le(&peer);
|
|
|
|
if (conn == NULL)
|
|
|
|
{
|
|
|
|
/* bt_conn_create_le() can fail if (1) the connection exists, but is
|
|
|
|
* in a bad state or (2) CONFIG_BLUETOOTH_MAX_CONN has been exceeded.
|
|
|
|
* Assume the latter.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
/* Add the incoming list of frames to the MAC's outgoing queue */
|
|
|
|
|
|
|
|
for (iob = framelist; iob != NULL; iob = framelist)
|
|
|
|
{
|
|
|
|
/* Increment statistics */
|
|
|
|
|
|
|
|
NETDEV_TXPACKETS(&priv->bd_dev.r_dev);
|
|
|
|
|
|
|
|
/* Remove the IOB from the queue */
|
|
|
|
|
|
|
|
framelist = iob->io_flink;
|
|
|
|
iob->io_flink = NULL;
|
|
|
|
|
2018-04-06 00:38:53 +02:00
|
|
|
DEBUGASSERT(iob->io_offset == BLUETOOTH_MAX_HDRLEN &&
|
|
|
|
iob->io_len >= BLUETOOTH_MAX_HDRLEN);
|
2018-04-01 23:45:35 +02:00
|
|
|
|
2018-04-01 22:00:40 +02:00
|
|
|
/* Allocate a buffer to contain the IOB */
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-04-06 00:38:53 +02:00
|
|
|
buf = bt_buf_alloc(BT_ACL_OUT, iob, BLUETOOTH_MAX_HDRLEN);
|
2018-04-01 22:00:40 +02:00
|
|
|
if (buf == NULL)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
2018-04-01 22:00:40 +02:00
|
|
|
wlerr("ERROR: Failed to allocate buffer container\n");
|
|
|
|
return -ENOMEM;
|
2018-03-31 22:55:03 +02:00
|
|
|
}
|
|
|
|
|
2018-04-01 22:00:40 +02:00
|
|
|
/* Transfer the frame to the Bluetooth stack. */
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-04-01 22:00:40 +02:00
|
|
|
bt_l2cap_send(conn, (uint16_t)btmeta->bm_channel, buf);
|
2018-03-31 22:55:03 +02:00
|
|
|
NETDEV_TXDONE(&priv->bd_dev.r_dev);
|
|
|
|
}
|
|
|
|
|
2020-09-20 21:45:09 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btnet_req_hci_data
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Requests the transfer of a list of HCI frames to the MAC.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* priv - Bluetooth network device
|
|
|
|
* btmeta - Bluetooth frame metadata
|
|
|
|
* framelist - Head of a list of HCI frames to be transferred.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) returned on success; a negated errno value is returned on
|
|
|
|
* any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int btnet_req_hci_data(FAR struct btnet_driver_s *priv,
|
|
|
|
FAR struct bluetooth_frame_meta_s *meta,
|
|
|
|
FAR struct iob_s *framelist)
|
|
|
|
{
|
|
|
|
FAR struct iob_s *iob;
|
|
|
|
FAR struct bt_buf_s *buf;
|
|
|
|
|
|
|
|
/* Add the incoming list of frames to the MAC's outgoing queue */
|
|
|
|
|
|
|
|
for (iob = framelist; iob != NULL; iob = framelist)
|
|
|
|
{
|
|
|
|
/* Increment statistics */
|
|
|
|
|
|
|
|
NETDEV_TXPACKETS(&priv->bd_dev.r_dev);
|
|
|
|
|
|
|
|
/* Remove the IOB from the queue */
|
|
|
|
|
|
|
|
framelist = iob->io_flink;
|
|
|
|
iob->io_flink = NULL;
|
|
|
|
|
|
|
|
DEBUGASSERT(iob->io_offset == BLUETOOTH_H4_HDRLEN &&
|
|
|
|
iob->io_len >= BLUETOOTH_H4_HDRLEN);
|
|
|
|
|
|
|
|
/* Allocate a buffer to contain the IOB */
|
|
|
|
|
|
|
|
switch (iob->io_data[iob->io_offset])
|
|
|
|
{
|
|
|
|
case HCI_ACLDATA_PKT:
|
|
|
|
iob->io_offset += 1;
|
|
|
|
buf = bt_buf_alloc(BT_ACL_OUT, iob, 0);
|
|
|
|
break;
|
|
|
|
case HCI_COMMAND_PKT:
|
|
|
|
iob->io_offset += 1;
|
|
|
|
buf = bt_buf_alloc(BT_CMD, iob, 0);
|
|
|
|
break;
|
|
|
|
case HCI_EVENT_PKT:
|
|
|
|
iob->io_offset += 1;
|
|
|
|
buf = bt_buf_alloc(BT_EVT, iob, 0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (buf == NULL)
|
|
|
|
{
|
|
|
|
wlerr("ERROR: Failed to allocate buffer container\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2020-12-21 01:57:06 +01:00
|
|
|
bt_send(g_btdev.btdev, buf);
|
|
|
|
bt_buf_release(buf);
|
2020-09-20 21:45:09 +02:00
|
|
|
|
|
|
|
/* Transfer the frame to the Bluetooth stack. */
|
|
|
|
|
|
|
|
NETDEV_TXDONE(&priv->bd_dev.r_dev);
|
|
|
|
}
|
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: btnet_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.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* netdev - The network device to be queried
|
|
|
|
* properties - Location where radio properties will be returned.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) returned on success; a negated errno value is returned on
|
|
|
|
* any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int btnet_properties(FAR struct radio_driver_s *netdev,
|
|
|
|
FAR struct radiodev_properties_s *properties)
|
|
|
|
{
|
|
|
|
DEBUGASSERT(netdev != NULL && properties != NULL);
|
|
|
|
memset(properties, 0, sizeof(struct radiodev_properties_s));
|
|
|
|
|
|
|
|
/* General */
|
|
|
|
|
2018-04-01 23:21:58 +02:00
|
|
|
properties->sp_addrlen = BLUETOOTH_ADDRSIZE; /* Length of an address */
|
|
|
|
properties->sp_framelen = BLUETOOTH_MAX_FRAMELEN; /* Fixed frame length */
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2018-04-01 23:21:58 +02:00
|
|
|
/* Multicast, multicast, and star hub node addresses not supported */
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bt_netdev_register
|
|
|
|
*
|
|
|
|
* Description:
|
2018-04-03 18:00:56 +02:00
|
|
|
* Register a network driver to access the Bluetooth layer using a 6LoWPAN
|
|
|
|
* IPv6 or AF_BLUETOOTH socket.
|
|
|
|
*
|
2018-03-31 22:55:03 +02:00
|
|
|
* Input Parameters:
|
2018-04-14 17:23:08 +02:00
|
|
|
* btdev - An instance of the low-level drivers interface structure.
|
2018-03-31 22:55:03 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success. Otherwise a negated errno value is
|
|
|
|
* returned to indicate the nature of the failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-05-18 15:45:01 +02:00
|
|
|
int bt_netdev_register(FAR struct bt_driver_s *btdev)
|
2018-03-31 22:55:03 +02:00
|
|
|
{
|
|
|
|
FAR struct btnet_driver_s *priv;
|
|
|
|
FAR struct radio_driver_s *radio;
|
2018-04-14 17:23:08 +02:00
|
|
|
FAR struct net_driver_s *netdev;
|
2020-09-20 21:45:09 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_WIRELESS_BLUETOOTH_HOST
|
2018-03-31 22:55:03 +02:00
|
|
|
FAR struct bt_conn_cb_s *hcicb;
|
2018-04-01 20:25:30 +02:00
|
|
|
FAR struct bt_l2cap_chan_s *l2capcb;
|
2020-09-20 21:45:09 +02:00
|
|
|
#else
|
|
|
|
FAR struct bt_hci_cb_s *hcicb;
|
|
|
|
#endif
|
2018-03-31 22:55:03 +02:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Get the interface structure associated with this interface number. */
|
|
|
|
|
2023-04-26 22:28:13 +02:00
|
|
|
btdev->bt_net = priv = (FAR struct btnet_driver_s *)
|
2018-03-31 22:55:03 +02:00
|
|
|
kmm_zalloc(sizeof(struct btnet_driver_s));
|
|
|
|
|
|
|
|
if (priv == NULL)
|
|
|
|
{
|
|
|
|
nerr("ERROR: Failed to allocate the device structure\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the driver structure */
|
|
|
|
|
|
|
|
radio = &priv->bd_dev;
|
2018-04-14 17:23:08 +02:00
|
|
|
netdev = &radio->r_dev;
|
|
|
|
netdev->d_ifup = btnet_ifup; /* I/F up (new IP address) callback */
|
|
|
|
netdev->d_ifdown = btnet_ifdown; /* I/F down callback */
|
|
|
|
netdev->d_txavail = btnet_txavail; /* New TX data callback */
|
2018-10-31 22:03:51 +01:00
|
|
|
#ifdef CONFIG_NET_MCASTGROUP
|
2018-04-14 17:23:08 +02:00
|
|
|
netdev->d_addmac = btnet_addmac; /* Add multicast MAC address */
|
|
|
|
netdev->d_rmmac = btnet_rmmac; /* Remove multicast MAC address */
|
2018-03-31 22:55:03 +02:00
|
|
|
#endif
|
2020-09-20 21:45:09 +02:00
|
|
|
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_WIRELESS_BLUETOOTH_HOST)
|
2018-04-14 17:23:08 +02:00
|
|
|
netdev->d_ioctl = btnet_ioctl; /* Handle network IOCTL commands */
|
2018-03-31 22:55:03 +02:00
|
|
|
#endif
|
2020-08-04 12:31:31 +02:00
|
|
|
netdev->d_private = priv; /* Used to recover private state from netdev */
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
/* Connection status change callbacks */
|
|
|
|
|
2020-09-20 21:45:09 +02:00
|
|
|
#ifdef CONFIG_WIRELESS_BLUETOOTH_HOST
|
2018-03-31 22:55:03 +02:00
|
|
|
hcicb = &priv->bd_hcicb;
|
2018-04-01 20:25:30 +02:00
|
|
|
hcicb->context = priv;
|
|
|
|
hcicb->connected = btnet_hci_connected;
|
|
|
|
hcicb->disconnected = btnet_hci_disconnected;
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
bt_conn_cb_register(hcicb);
|
|
|
|
|
2018-04-01 20:25:30 +02:00
|
|
|
/* L2CAP status change callbacks */
|
|
|
|
|
|
|
|
l2capcb = &priv->bd_l2capcb;
|
|
|
|
l2capcb->context = priv;
|
|
|
|
l2capcb->connected = btnet_l2cap_connected;
|
|
|
|
l2capcb->disconnected = btnet_l2cap_disconnected;
|
|
|
|
l2capcb->encrypt_change = btnet_l2cap_encrypt_change;
|
|
|
|
l2capcb->receive = btnet_l2cap_receive;
|
|
|
|
|
|
|
|
bt_l2cap_chan_default(l2capcb);
|
2020-09-20 21:45:09 +02:00
|
|
|
#else
|
|
|
|
hcicb = &priv->bd_hcicb;
|
|
|
|
hcicb->context = priv;
|
|
|
|
hcicb->received = btnet_hci_received;
|
|
|
|
|
|
|
|
bt_hci_cb_register(hcicb);
|
|
|
|
#endif
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
/* Set the network mask. */
|
|
|
|
|
2018-04-14 17:23:08 +02:00
|
|
|
btnet_netmask(netdev);
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
/* Initialize the Network frame-related callbacks */
|
|
|
|
|
|
|
|
radio->r_get_mhrlen = btnet_get_mhrlen; /* Get MAC header length */
|
|
|
|
radio->r_req_data = btnet_req_data; /* Enqueue frame for transmission */
|
|
|
|
radio->r_properties = btnet_properties; /* Return radio properties */
|
|
|
|
|
2021-05-18 15:45:01 +02:00
|
|
|
btdev->receive = bt_receive;
|
|
|
|
|
2018-04-14 19:33:29 +02:00
|
|
|
/* Associate the driver in with the Bluetooth stack.
|
|
|
|
*
|
|
|
|
* REVISIT: We will eventually need to remember which Bluetooth device
|
|
|
|
* we a serving. Not a problem now because only a single BLE device is
|
|
|
|
* supported.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ret = bt_driver_register(btdev);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
nerr("ERROR: bt_driver_register() failed: %d\n", ret);
|
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize the Bluetooth stack.
|
|
|
|
*
|
|
|
|
* REVISIT: This function should be called only once after all BLE
|
|
|
|
* drivers are registered. Not a problem now because only a single
|
|
|
|
* BLE device is supported.
|
|
|
|
*/
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
ret = bt_initialize();
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2018-04-14 19:33:29 +02:00
|
|
|
nerr("ERROR: bt_initialize() failed: %d\n", ret);
|
2018-03-31 22:55:03 +02:00
|
|
|
goto errout;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Put the interface in the down state. */
|
|
|
|
|
2018-04-14 17:23:08 +02:00
|
|
|
btnet_ifdown(netdev);
|
2018-03-31 22:55:03 +02:00
|
|
|
|
2019-08-10 20:22:39 +02:00
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
2020-04-23 08:31:46 +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 be attempted to be forwarded and require the
|
|
|
|
* buffer.
|
2019-08-10 20:22:39 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
priv->bd_dev.r_dev.d_buf = g_iobuffer.rb_buf;
|
|
|
|
#endif
|
|
|
|
|
2023-06-03 04:47:14 +02:00
|
|
|
#ifdef CONFIG_WIRELESS_BLUETOOTH_HOST
|
|
|
|
bt_add_services();
|
|
|
|
#endif
|
|
|
|
|
2018-04-14 19:33:29 +02:00
|
|
|
/* Register the network device with the OS so that socket IOCTLs can be
|
|
|
|
* performed
|
|
|
|
*/
|
2018-03-31 22:55:03 +02:00
|
|
|
|
|
|
|
ret = netdev_register(&priv->bd_dev.r_dev, NET_LL_BLUETOOTH);
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2018-04-14 19:33:29 +02:00
|
|
|
nerr("ERROR: netdev_register() failed: %d\n", ret);
|
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
errout:
|
2019-12-24 17:37:30 +01:00
|
|
|
|
2023-05-03 19:05:45 +02:00
|
|
|
btnet_ifdown(netdev);
|
|
|
|
bt_driver_unregister(btdev);
|
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
/* Free memory and return the error */
|
|
|
|
|
2023-05-03 19:05:45 +02:00
|
|
|
kmm_free(btdev->bt_net);
|
|
|
|
btdev->bt_net = NULL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: bt_netdev_unregister
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Unregister a network a driver registered by bt_netdev_register.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* btdev - An instance of the low-level driver interface structure.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success. Otherwise a negated errno value is
|
|
|
|
* returned to indicate the nature of the failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int bt_netdev_unregister(FAR struct bt_driver_s *btdev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
FAR struct btnet_driver_s *priv;
|
|
|
|
|
|
|
|
if (!btdev)
|
|
|
|
{
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv = (FAR struct btnet_driver_s *)btdev->bt_net;
|
|
|
|
if (!priv)
|
|
|
|
{
|
|
|
|
nerr("ERROR: bt_driver_s is probably not registered\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
btnet_ifdown(&priv->bd_dev.r_dev);
|
|
|
|
|
|
|
|
ret = netdev_unregister(&priv->bd_dev.r_dev);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
nerr("ERROR: netdev_unregister bfailed: %d\n", ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
bt_deinitialize();
|
|
|
|
|
|
|
|
bt_driver_unregister(btdev);
|
|
|
|
|
|
|
|
kmm_free(btdev->bt_net);
|
|
|
|
btdev->bt_net = NULL;
|
|
|
|
|
2018-03-31 22:55:03 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET && CONFIG_NET_skeleton */
|