Skip to content
Commits on Source (23)
......@@ -43,7 +43,9 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This is part of revision 2.1.0.12573 of the Tiva Peripheral Driver Library.
* This is part of revision 2.1.0.12573 of the Tiva Peripheral Driver
* Library.
*
****************************************************************************/
/****************************************************************************
......@@ -82,13 +84,8 @@
(((((div) << ADC_CC_CLKDIV_SHIFT) & ADC_CC_CLKDIV_MASK) | \
((src) & ADC_CC_CS_MASK)) & (ADC_CC_CLKDIV_MASK + ADC_CC_CS_MASK))
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
#define INTERNAL_VREF 0x00
#define EXTERNAL_VREF 0x01
/****************************************************************************
* Private Data
......@@ -180,14 +177,6 @@ static uint32_t ain2gpio[] =
#endif
};
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
......@@ -220,18 +209,19 @@ void tiva_adc_one_time_init(uint32_t clock, uint8_t sample_rate)
if (one_time_init == false)
{
ainfo("performing ADC one-time initialization...\n");
/* set clock */
/* Set clock */
tiva_adc_clock(clock);
/* set sampling rate */
/* Set sampling rate */
tiva_adc_sample_rate(sample_rate);
#ifdef CONFIG_ARCH_CHIP_TM4C129
/* voltage reference */
/* Voltage reference */
tiva_adc_vref();
tiva_adc_vref(INTERNAL_VREF);
#endif
one_time_init = true;
}
......@@ -247,8 +237,8 @@ void tiva_adc_one_time_init(uint32_t clock, uint8_t sample_rate)
* Name: tiva_adc_configure
*
* Description:
* Performs configuration of a single ADC, it's valid sample sequencers and
* available steps.
* Performs configuration of a single ADC, it's valid sample sequencers
* and available steps.
*
****************************************************************************/
......@@ -298,14 +288,14 @@ void tiva_adc_configure(struct tiva_adc_cfg_s *cfg)
void tiva_adc_sse_cfg(uint8_t adc, uint8_t sse,
struct tiva_adc_sse_cfg_s *ssecfg)
{
uint8_t priority = ssecfg->priority;
uint8_t trigger = ssecfg->trigger;
ainfo("configure ADC%d SSE%d...\n", adc, sse);
#ifdef CONFIG_DEBUG_ANALOG
ainfo("priority=%d trigger=%d...\n", ssecfg->priority, ssecfg->trigger);
#endif
uint8_t priority = ssecfg->priority;
uint8_t trigger = ssecfg->trigger;
/* Ensure SSE is disabled before configuring */
tiva_adc_sse_enable(adc, sse, false);
......@@ -326,11 +316,6 @@ void tiva_adc_sse_cfg(uint8_t adc, uint8_t sse,
void tiva_adc_step_cfg(struct tiva_adc_step_cfg_s *stepcfg)
{
#ifdef CONFIG_DEBUG_ANALOG
ainfo(" shold=0x%02x flags=0x%02x ain=%d...\n",
stepcfg->shold, stepcfg->flags, stepcfg->ain);
#endif
uint8_t adc = stepcfg->adc;
uint8_t sse = stepcfg->sse;
uint8_t step = stepcfg->step;
......@@ -342,8 +327,12 @@ void tiva_adc_step_cfg(struct tiva_adc_step_cfg_s *stepcfg)
uint32_t gpio = ain2gpio[stepcfg->ain];
ainfo("configure ADC%d SSE%d STEP%d...\n", adc, sse, step);
#ifdef CONFIG_DEBUG_ANALOG
ainfo(" shold=0x%02x flags=0x%02x ain=%d...\n",
stepcfg->shold, stepcfg->flags, stepcfg->ain);
#endif
/* Configure the AIN GPIO for analog input if not flagged to be muxed to
/* Configure the AIN GPIO for analog input if not flagged to be mux'ed to
* the internal temperature sensor
*/
......@@ -356,7 +345,7 @@ void tiva_adc_step_cfg(struct tiva_adc_step_cfg_s *stepcfg)
tiva_adc_sse_register_chn(adc, sse, step, ain);
tiva_adc_sse_differential(adc, sse, step, 0); /* TODO: update when differential
* support is added. */
* support is added. */
#ifdef CONFIG_EXPERIMENTAL
tiva_adc_sse_sample_hold_time(adc, sse, step, shold);
#endif
......@@ -393,8 +382,6 @@ uint8_t tiva_adc_get_ain(uint8_t adc, uint8_t sse, uint8_t step)
return (ssmux >> ADC_SSMUX_MUX_SHIFT(step));
}
/* IRQS *********************************************************************/
/****************************************************************************
* Name: tiva_adc_irq_attach
*
......@@ -464,8 +451,6 @@ int tiva_adc_getirq(uint8_t adc, uint8_t sse)
return sse2irq[SSE_IDX(adc, sse)];
}
/* Peripheral (base) level **************************************************/
/****************************************************************************
* Name: tiva_adc_enable
*
......@@ -538,32 +523,34 @@ void tiva_adc_clock(uint32_t freq)
modifyreg32(ccreg, ADC_CC_CS_MASK, (ADC_CC_CS_PIOSC & ADC_CC_CS_MASK));
#elif defined (CONFIG_ARCH_CHIP_TM4C129)
/* check clock bounds and specific match cases */
/* Check clock bounds and specific match cases */
uint32_t clk_src = 0;
uint32_t div = 0;
uintptr_t ccreg;
if (freq > TIVA_ADC_CLOCK_MAX)
{
clk_src = ADC_CC_CS_SYSPLL;
div = (BOARD_FVCO_FREQUENCY / TIVA_ADC_CLOCK_MAX);
div = (BOARD_FVCO_FREQUENCY / TIVA_ADC_CLOCK_MAX);
}
else if (freq < TIVA_ADC_CLOCK_MIN)
{
clk_src = ADC_CC_CS_PIOSC;
div = 1;
div = 1;
}
else if (freq == XTAL_FREQUENCY)
{
clk_src = ADC_CC_CS_MOSC;
div = 1;
div = 1;
}
else
{
clk_src = ADC_CC_CS_SYSPLL;
div = (BOARD_FVCO_FREQUENCY / freq);
div = (BOARD_FVCO_FREQUENCY / freq);
}
uintptr_t ccreg = (TIVA_ADC0_BASE + TIVA_ADC_CC_OFFSET);
ccreg = (TIVA_ADC0_BASE + TIVA_ADC_CC_OFFSET);
modifyreg32(ccreg, ADC_CC_CLKDIV_MASK, CLOCK_CONFIG(div, clk_src));
#else
# error Unsupported architecture reported
......@@ -661,8 +648,6 @@ uint32_t tiva_adc_int_status(uint8_t adc)
return ris;
}
/* Sample sequencer (SSE) functions *****************************************/
/****************************************************************************
* Name: tiva_adc_sse_enable
*
......@@ -682,9 +667,10 @@ uint32_t tiva_adc_int_status(uint8_t adc)
uint8_t tiva_adc_sse_enable(uint8_t adc, uint8_t sse, bool state)
{
uintptr_t actssreg = TIVA_ADC_ACTSS(adc);
ainfo("ADC%d SSE%d=%01d\n", adc, sse, state);
uintptr_t actssreg = TIVA_ADC_ACTSS(adc);
if (state == true)
{
modifyreg32(actssreg, 0, (1 << sse));
......@@ -797,7 +783,7 @@ void tiva_adc_sse_int_enable(uint8_t adc, uint8_t sse, bool state)
* Name: tiva_adc_sse_int_status
*
* Description:
* Returns interrupt status for the specificed SSE
* Returns interrupt status for the specified SSE
*
* Input Parameters:
* adc - which ADC peripherals' interrupt status to retrieve
......@@ -819,8 +805,8 @@ bool tiva_adc_sse_int_status(uint8_t adc, uint8_t sse)
* Clears the interrupt bit for the SSE.
*
* Input Parameters:
* adc - peripheral state
* sse - sample sequencer
* adc - peripheral state
* sse - sample sequencer
* state - sample sequencer
*
****************************************************************************/
......@@ -881,8 +867,8 @@ uint8_t tiva_adc_sse_data(uint8_t adc, uint8_t sse, int32_t *buf)
* the lowest. There can be no duplicate values.
*
* Input Parameters:
* adc - peripheral state
* sse - sample sequencer
* adc - peripheral state
* sse - sample sequencer
* priority - conversion priority
*
****************************************************************************/
......
/****************************************************************************
* arch/arm/src/tiva/tiva_adclow.c
*
* Copyright (C) 2016-2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2016-2018 Gregory Nutt. All rights reserved.
* Copyright (C) 2015 TRD2 Inc. All rights reserved.
* Author: Calvin Maguranis <calvin.maguranis@trd2inc.com>
* Gregory Nutt <gnutt@nuttx.org>
......@@ -129,11 +129,6 @@
#define SEM_PROCESS_PRIVATE 0
#define SEM_PROCESS_SHARED 1
/* DEBUG ********************************************************************/
#ifdef CONFIG_DEBUG_ANALOG
#endif
/****************************************************************************
* Public Functions
* **************************************************************************/
......@@ -179,12 +174,12 @@ struct tiva_adc_s
struct tiva_adc_sse_s
{
sem_t exclsem; /* Mutual exclusion semaphore */
struct work_s work; /* Supports the interrupt handling "bottom half" */
bool cfg; /* Configuration state */
bool ena; /* Sample sequencer operation state */
uint8_t adc; /* Parent peripheral */
uint8_t num; /* SSE number */
sem_t exclsem; /* Mutual exclusion semaphore */
struct work_s work; /* Supports the interrupt handling "bottom half" */
bool cfg; /* Configuration state */
bool ena; /* Sample sequencer operation state */
uint8_t adc; /* Parent peripheral */
uint8_t num; /* SSE number */
};
/****************************************************************************
......@@ -414,12 +409,12 @@ static int tiva_adc_bind(FAR struct adc_dev_s *dev,
static void tiva_adc_reset(struct adc_dev_s *dev)
{
ainfo("Resetting...\n");
struct tiva_adc_s *priv = (struct tiva_adc_s *)dev->ad_priv;
struct tiva_adc_sse_s *sse;
uint8_t s;
ainfo("Resetting...\n");
tiva_adc_rxint(dev, false);
for (s = 0; s < 4; ++s)
......@@ -446,12 +441,12 @@ static void tiva_adc_reset(struct adc_dev_s *dev)
static int tiva_adc_setup(struct adc_dev_s *dev)
{
ainfo("Setup\n");
struct tiva_adc_s *priv = (struct tiva_adc_s *)dev->ad_priv;
struct tiva_adc_sse_s *sse;
uint8_t s = 0;
ainfo("Setup\n");
priv->ena = true;
for (s = 0; s < 4; ++s)
......@@ -480,8 +475,8 @@ static int tiva_adc_setup(struct adc_dev_s *dev)
static void tiva_adc_shutdown(struct adc_dev_s *dev)
{
struct tiva_adc_s *priv = (struct tiva_adc_s *)dev->ad_priv;
ainfo("Shutdown\n");
ainfo("Shutdown\n");
DEBUGASSERT(priv->ena);
/* Resetting the ADC peripheral disables interrupts and all SSEs */
......@@ -515,13 +510,12 @@ static void tiva_adc_shutdown(struct adc_dev_s *dev)
static void tiva_adc_rxint(struct adc_dev_s *dev, bool enable)
{
ainfo("RXINT=%d\n", enable);
struct tiva_adc_s *priv = (struct tiva_adc_s *)dev->ad_priv;
struct tiva_adc_sse_s *sse;
uint32_t trigger;
uint8_t s = 0;
ainfo("RXINT=%d\n", enable);
DEBUGASSERT(priv->ena);
for (s = 0; s < 4; ++s)
......@@ -665,6 +659,7 @@ static int tiva_adc_ioctl(struct adc_dev_s *dev, int cmd, unsigned long arg)
static void tiva_adc_read(void *arg)
{
struct tiva_adc_s *priv;
struct tiva_adc_sse_s *sse = (struct tiva_adc_sse_s *)arg;
struct adc_dev_s *dev = 0;
int irq = tiva_adc_getirq(sse->adc, sse->num);
......@@ -694,6 +689,8 @@ static void tiva_adc_read(void *arg)
return;
}
priv = (struct tiva_adc_s *)dev->ad_priv;
/* Verify that the upper-half driver has bound its callback functions */
if (priv->cb != NULL)
......@@ -737,7 +734,7 @@ static void tiva_adc_interrupt(struct tiva_adc_sse_s *sse)
DEBUGASSERT(sse->ena == true);
/* disable further interrupts. Interrupts will be re-enabled
/* Disable further interrupts. Interrupts will be re-enabled
* after the worker thread executes.
*/
......@@ -946,14 +943,14 @@ int tiva_adc_initialize(const char *devpath, struct tiva_adc_cfg_s *cfg,
void tiva_adc_lock(FAR struct tiva_adc_s *priv, int sse)
{
ainfo("Locking...\n");
struct tiva_adc_sse_s *s = g_sses[SSE_IDX(priv->devno, sse)];
int ret;
#ifdef CONFIG_DEBUG_ANALOG
uint16_t loop_count = 0;
#endif
ainfo("Locking...\n");
do
{
ret = nxsem_wait(&s->exclsem);
......@@ -986,13 +983,11 @@ void tiva_adc_lock(FAR struct tiva_adc_s *priv, int sse)
void tiva_adc_unlock(FAR struct tiva_adc_s *priv, int sse)
{
ainfo("Unlocking\n");
struct tiva_adc_sse_s *s = g_sses[SSE_IDX(priv->devno, sse)];
ainfo("Unlocking\n");
nxsem_post(&s->exclsem);
}
/* DEBUG ********************************************************************/
#ifdef CONFIG_DEBUG_ANALOG
/****************************************************************************
......@@ -1041,6 +1036,7 @@ static void tiva_adc_runtimeobj_vals(void)
{
struct tiva_adc_sse_s *sse;
uint8_t s;
# ifdef CONFIG_TIVA_ADC0
ainfo("ADC0 [0x%08x] cfg=%d ena=%d devno=%d\n",
&adc0, adc0.cfg, adc0.ena, adc0.devno);
......
......@@ -148,10 +148,10 @@ static FAR struct bt_buf_s *btuart_evt_recv(FAR struct btuart_upperhalf_s *upper
*remaining = hdr.len;
buf = bt_buf_get(BT_EVT, 0);
buf = bt_buf_alloc(BT_EVT, NULL, 0);
if (buf != NULL)
{
memcpy(bt_buf_add(buf, sizeof(struct bt_hci_evt_hdr_s)), &hdr,
memcpy(bt_buf_extend(buf, sizeof(struct bt_hci_evt_hdr_s)), &hdr,
sizeof(struct bt_hci_evt_hdr_s));
}
else
......@@ -181,10 +181,10 @@ static FAR struct bt_buf_s *btuart_acl_recv(FAR struct btuart_upperhalf_s *upper
return NULL;
}
buf = bt_buf_get(BT_ACL_IN, 0);
buf = bt_buf_alloc(BT_ACL_IN, NULL, 0);
if (buf)
{
memcpy(bt_buf_add(buf, sizeof(struct bt_hci_acl_hdr_s)), &hdr,
memcpy(bt_buf_extend(buf, sizeof(struct bt_hci_acl_hdr_s)), &hdr,
sizeof(struct bt_hci_acl_hdr_s));
}
else
......@@ -268,14 +268,14 @@ static void btuart_interrupt(FAR const struct btuart_lowerhalf_s *lower,
/* Pass buffer to the stack */
bt_recv(buf);
bt_hci_receive(buf);
buf = NULL;
}
return;
failed:
bt_buf_put(buf);
bt_buf_release(buf);
remaining = 0;
buf = NULL;
return;
......@@ -299,7 +299,7 @@ static int btuart_send(FAR const struct bt_driver_s *dev,
return -EINVAL;
}
type = bt_buf_push(buf, 1);
type = bt_buf_provide(buf, 1);
switch (buf->type)
{
......
/****************************************************************************
* include/netpacket/bluetooth.h
*
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_NETPACKET_BLUETOOTH_H
#define __INCLUDE_NETPACKET_BLUETOOTH_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <sys/types.h>
#include <stdint.h>
#include <nuttx/wireless/bt_hci.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Well known addresses: */
#define BT_ADDR_ANY {0, 0, 0, 0, 0, 0}
#define BT_ADDR_LOCAL {0, 0, 0, 0xff, 0xff, 0xff}
/* Any channel, any PSM */
#define BT_CHANNEL_ANY 0
#define BT_PSM_ANY 0
/* Socket protocols.
*
* All Bluetooth sockets should select address family = AF_BLUETOOTH and
* type = SOCK_RAW. Protocol options are listed here (from NetBSD):
*
* BTPROTO_HCI
* This gives raw access to the Host Controller Interface of local devices
* using the HCI protocol as described in the Bluetooth Core Specification.
* The local address specified by bind() may be used to select the device
* that the socket will receive packets from. If BDADDR_ANY is specified
* then the socket will receive packets from all devices on the system.
* connect() may be used to create connections such that packets sent with
* send() will be delivered to the specified device, otherwise sendto()
* should be used.
* BTPROTO_L2CAP
* L2CAP sockets give sequential packet access over channels to other
* Bluetooth devices and make use of the bt_psm field in the sockaddr_bt_s
* structure to select the Protocol/Sevice Multiplexer to specify when
* making connections. If the special value of L2CAP_PSM_ANY is bound
* when the listen() call is made, the next available PSM from the
* dynamic range above 0x1001 will be selected and may be discovered
* using the getsockname() call.
* BTPROTO_RFCOMM
* RFCOMM sockets provide streamed data over Bluetooth connection and
* make use of the bt_psm, and bt_channel fields in the sockaddr_bt_s
* structure. The channel number must be between 1 and 30 inclusive
* except that if the special value RFCOMM_CHANNEL_ANY is bound, when
* the listen() call is made, the first unused channel for the relevant
* bdaddr will be allocated and may be discovered using the
* getsockname(2) call. If no PSM is specified, a default value of
* L2CAP_PSM_RFCOMM (0x0003) will be used.
*
* NOTE: All protocol values currently ignored. Only BTPROTO_L2CAP is
* supported by default.
*/
#define BTPROTO_L2CAP 0
#define BTPROTO_HCI 1
#define BTPROTO_SCO 2
#define BTPROTO_RFCOMM 3
#define BTPROTO_BNEP 4
#define BTPROTO_CMTP 5
#define BTPROTO_HIDP 6
#define BTPROTO_AVDTP 7
/* HCI socket options (SOL_HCI, see include/sys/socket.h):
*
* SO_HCI_EVT_FILTER
* Controls which events will be received at the socket. By default,
* Command_Complete and Command_Status events only are enabled.
* SO_HCI_PKT_FILTER [struct hci_filter]
* This filter controls the type of packets that will be received at
* the socket. By default, Event packets only are enabled.
* SO_HCI_DIRECTION [int]
* When set, this enables control messages on packets received at the
* socket indicating the direction of travel of the packet.
*/
#define SO_HCI_EVT_FILTER (__SO_PROTOCOL + 0)
#define SO_HCI_PKT_FILTER (__SO_PROTOCOL + 1)
#define SO_HCI_DIRECTION (__SO_PROTOCOL + 2)
/* L2CAP socket options (SOL_L2CAP, see include/sys/socket.h):
* SO_L2CAP_IMTU [uint16_t]
* Incoming MTU
* SO_L2CAP_OMTU [uint16_t]
* Outgoing MTU (read-only)
* SO_L2CAP_LM [int]
* Link Mode. The following bits may be set:
*
* L2CAP_LM_AUTH Request authentication (pairing).
* L2CAP_LM_ENCRYPT Request encryption (includes authentication).
* L2CAP_LM_SECURE Request secured link (encryption, plus
* change link key).
*
* Link mode settings will be applied to the baseband link during L2CAP
* connection establishment. If the L2CAP connection is already
* established, EINPROGRESS may be returned, and it is not possible to
* guarantee that data already queued (from either end) will not be
* delivered. If the mode change fails, the L2CAP connection will be
* aborted.
*/
#define SO_L2CAP_IMTU (__SO_PROTOCOL + 3)
#define SO_L2CAP_OMTU (__SO_PROTOCOL + 4)
#define SO_L2CAP_LM (__SO_PROTOCOL + 5)
# define L2CAP_LM_AUTH (1 << 0)
# define L2CAP_LM_ENCRYPT (1 << 1)
# define L2CAP_LM_SECURE (1 << 2)
/* RFCOMM socket options (SOL_RFCOMM, see include/sys/socket.h):
*
* SO_RFCOMM_MTU [uint16_t]
* Maximum Frame Size to use for this link.
* SO_RFCOMM_LM [int]
* Link Mode. The following bits may be set at any time:
*
* RFCOMM_LM_AUTH Request authentication (pairing).
* RFCOMM_LM_ENCRYPT Request encryption (includes authentication).
* RFCOMM_LM_SECURE Request secured link (encryption, plus
* change link key).
*
* Link mode settings will be applied to the baseband link during RFCOMM
* connection establishment. If the RFCOMM connection is already
* established, EINPROGRESS may be returned, and it is not possible to
* guarantee that data already queued (from either end) will not be
* delivered. If the mode change fails, the RFCOMM connection will be
* aborted.
*/
#define SO_RFCOMM_MTU (__SO_PROTOCOL + 6)
#define SO_RFCOMM_LM (__SO_PROTOCOL + 7)
# define RFCOMM_LM_AUTH (1 << 0)
# define RFCOMM_LM_ENCRYPT (1 << 1)
# define RFCOMM_LM_SECURE (1 << 2)
/* SCO socket options (SOL_SCO, see include/sys/socket.h):
*
* SO_SCO_MTU [uint16_t]
* Maximum packet size for use on this link. This is read-only and will
* be set by the protocol code when a connection is made.
* SO_SCO_HANDLE [uint16_t]
* Connection handle for this link. This is read-only and provided for
* informational purposes only.
*/
#define SO_SCO_MTU (__SO_PROTOCOL + 8)
#define SO_SCO_HANDLE (__SO_PROTOCOL + 9)
/* The CID name space for the ACL-U, ASB-C, and AMP-U logical links is as
* follows:
*/
#define BT_CID_NULL 0x0000 /* Null identifier */
#define BT_CID_L2CAP 0x0001 /* L2CAP Signaling channel */
#define BT_CID_CONNECTIONLESS 0x0002 /* Connectionless channel */
#define BT_CID_AMP 0x0003 /* AMP Manager Protocol */
/* 0x0004-0x0006 Reserved for future
* use */
#define BT_CID_BREDR 0x0007 /* BR/EDR Security Manager */
/* 0x0008-0x003e Reserved for future
* use */
#define BT_CID_AMPTEST 0x003f /* AMP Test Manager */
/* 0x0040-0xffff Dynamically
* allocated */
/* The CID name space for the LE-U logical link is as follows:
*
* NOTE: 0x0004, 0x0005, and 0x0006 are used internally by ATT, L2CAP, and
* and SMP. These are unavailable for use use in socket connection.
*/
#define BT_LE_CID_NULL 0x0000 /* Null identifier */
/* 0x0001-0x0003 Reserved for future
* use */
#define BT_LE_CID_ATT 0x0004 /* Attribute Protocol */
#define BT_LE_CID_L2CAP 0x0005 /* Low Energy L2CAP Signaling channel */
#define BT_LE_CID_SMP 0x0006 /* Security Manager Protocol
/* 0x0007-0x001f Reserved for future
/* 0x0020-0x003e Assigned Numbers
/* 0x003f Reserved for future use */
/* 0x0040-0x007f Dynamically allocated
* using the L2CAP LE credit based
* connection mechanism
/* Others reserved for future use */
/* Protocol and Service Multiplexers (PSMs) */
#define BT_PSM_SDP 0x0001 /* Bluetooth Service Discovery
* Protocol (SDP), Bluetooth SIG */
#define BT_PSM_RFCOMM 0x0003 /* RFCOMM with TS 07.10, Bluetooth
* SIG */
#define BT_PSM_TCS_BIN 0x0005 /* Bluetooth Telephony Control
* Specification / TCS Binary,
* Bluetooth SIG */
#define BT_PSM_TCS_BIN_CORDLESS 0x0007 /* Bluetooth Telephony Control
* Specification / TCS Binary,
* Bluetooth SIG */
#define BT_PSM_BNEP 0x000f /* Bluetooth Network Encapsulation
* Protocol, Bluetooth SIG */
#define BT_PSM_HID_CTRL 0x0011 /* Human Interface Device, Bluetooth
* SIG */
#define BT_PSM_HID_INT 0x0013 /* Human Interface Device, Bluetooth
* SIG */
#define BT_PSM_UPnP 0x0015 /* [ESDP] , Bluetooth SIG */
#define BT_PSM_AVCTP 0x0017 /* Audio/Video Control Transport
* Protocol, Bluetooth SIG */
#define BT_PSM_AVDTP 0x0019 /* Audio/Video Distribution Transport
* Protocol, Bluetooth SIG */
#define BT_PSM_AVCTP_BROWSING 0x001b /* Audio/Video Remote Control
* Profile, Bluetooth SIG */
#define BT_PSM_UDI_CPLANE 0x001d /* Unrestricted Digital Information
* Profile [UDI], Bluetooth SIG */
#define BT_PSM_ATT 0x001f /* Bluetooth Core Specification */
#define BT_PSM_3DSP 0x0021 /* 3D Synchronization Profile,
* Bluetooth SIG. */
#define BT_PSM_LE_PSM_IPSP 0x0023 /* Internet Protocol Support Profile
* (IPSP), Bluetooth SIG */
#define BT_PSM_OTS 0x0025 /* Object Transfer Service (OTS),
* Bluetooth SIG */
/****************************************************************************
* Public Type Definitions
****************************************************************************/
/* See include/nuttx/wireless/bt_hci.h for address definitions. In
* particular, type bt_addr_t
*/
/* Socket address used with:
*
* bind() - Associates local address with socket
* connect() - Associates a remote address with the socket (for send())
* sendto() - Send to specified remote address
* recvfrom()- Receive from indicated remote address.
*
* REVISIT: Some protocols would require a bt_psm field as well.
*/
struct sockaddr_bt_s
{
sa_family_t bt_family; /* Must be AF_BLUETOOTH */
bt_addr_t bt_bdaddr; /* 6-byte Bluetooth address */
uint8_t bt_channel; /* Channel identifier (CID) */
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#endif /* __INCLUDE_NETPACKET_BLUETOOTH_H */
/****************************************************************************
* include/nuttx/net/bluetooth.h
*
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_NET_BLUETOOTH_H
#define __INCLUDE_NUTTX_NET_BLUETOOTH_H
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#include <nuttx/wireless/bt_hci.h>
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* BLUETOOTH_MAX_FRAMELEN
* Maximum amount of data that can fit in a buffer.
*
* The biggest foreseeable buffer size requirement right now comes from
* the Bluetooth 4.2 SMP MTU which is 65. This then become 65 + 4 (L2CAP
* header) + 4 (ACL header) + 1 (H4 header) = 74. This also covers the
* biggest HCI commands and events which are a bit under the 70 byte
* mark.
*/
#define BLUETOOTH_SMP_MTU 65
#define BLUETOOTH_L2CAP_HDRLEN 4 /* Size of L2CAP header */
#define BLUETOOTH_ACL_HDRLEN 4 /* Size of ACL header */
#define BLUETOOTH_H4_HDRLEN 1 /* Size of H4 header */
#define BLUETOOTH_FRAME_HDRLEN \
(BLUETOOTH_L2CAP_HDRLEN + BLUETOOTH_ACL_HDRLEN + BLUETOOTH_H4_HDRLEN)
#define BLUETOOTH_MAX_FRAMELEN (BLUETOOTH_SMP_MTU + BLUETOOTH_FRAME_HDRLEN)
#define BLUETOOTH_ADDRSIZE 6
#define BLUETOOTH_ADDRCOPY(d,s) memcpy((d),(s),BLUETOOTH_ADDRSIZE)
#define BLUETOOTH_ADDRCMP(a,b) (memcmp((a),(b),BLUETOOTH_ADDRSIZE) == 0)
/****************************************************************************
* Public Types
****************************************************************************/
/* This is the form of the meta-data that accompanies frames received from
* the Bluetooth stack.
*/
struct bluetooth_frame_meta_s
{
bt_addr_t bm_raddr; /* Connected remote address */
uint8_t bm_channel; /* Connection channel */
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: bluetooth_input
*
* Description:
* Handle incoming Bluetooth input
*
* This function is called when the radio device driver has received an
* frame from the network. The frame from the device driver must be
* provided in by the IOB frame argument of the function call:
*
* - The frame data is in the IOB io_data[] buffer,
* - The length of the frame is in the IOB io_len field, and
* - The offset past and radio MAC header is provided in the io_offset
* field.
*
* The frame argument may refer to a single frame (a list of length one)
* or may it be the head of a list of multiple frames.
*
* - The io_flink field points to the next frame in the list (if enable)
* - The last frame in the list will have io_flink == NULL.
*
* Input Parameters:
* radio The radio network driver interface.
* framelist - The head of an incoming list of frames. Normally this
* would be a single frame. A list may be provided if
* appropriate, however.
* meta - Meta data characterizing the received frame.
*
* If there are multiple frames in the list, this metadata
* must apply to all of the frames in the list.
*
* Returned Value:
* OK The Bluetooth has been processed and can be deleted
* ERROR Hold the Bluetooth and try again later. There is a listening
* socket but no recv in place to catch the Bluetooth yet.
* Useful when a packet arrives before a recv call is in place.
*
* Assumptions:
* Called from the network diver with the network locked.
*
****************************************************************************/
struct radio_driver_s; /* Forward reference */
struct bluetooth_data_ind_s; /* Forward reference */
struct iob_s; /* Forward reference */
int bluetooth_input(FAR struct radio_driver_s *radio,
FAR struct iob_s *framelist,
FAR struct bluetooth_frame_meta_s *meta);
#endif /* __INCLUDE_NUTTX_NET_BLUETOOTH_H */
......@@ -68,7 +68,7 @@
* appropriate, however.
* meta - Meta data characterizing the received frame.
*
* If there are multilple frames in the list, this metadata
* If there are multiple frames in the list, this metadata
* must apply to all of the frames in the list.
*
* Returned Value:
......
......@@ -116,6 +116,7 @@ enum net_lltype_e
NET_LL_LOOPBACK, /* Local loopback */
NET_LL_SLIP, /* Serial Line Internet Protocol (SLIP) */
NET_LL_TUN, /* TUN Virtual Network Device */
NET_LL_BLUETOOTH, /* Bluetooth */
NET_LL_IEEE80211, /* IEEE 802.11 */
NET_LL_IEEE802154, /* IEEE 802.15.4 MAC */
NET_LL_PKTRADIO /* Non-standard packet radio */
......
......@@ -77,6 +77,12 @@
# endif
#elif defined(CONFIG_WIRELESS_IEEE802154)
# define RADIO_MAX_ADDRLEN 8
#elif defined(CONFIG_WIRELESS_BLUETOOTH)
# if CONFIG_PKTRADIO_ADDRLEN > 6
# define RADIO_MAX_ADDRLEN CONFIG_PKTRADIO_ADDRLEN
# else
# define RADIO_MAX_ADDRLEN 6
# endif
#else /* if defined(CONFIG_WIRELESS_PKTRADIO) */
# define RADIO_MAX_ADDRLEN CONFIG_PKTRADIO_ADDRLEN
#endif
......@@ -182,9 +188,13 @@ struct netdev_statistics_s
};
#endif
#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_IEEE802154)
#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_BLUETOOTH) || \
defined(CONFIG_NET_IEEE802154)
/* This structure is used to represent addresses of varying length. This
* structure is used to represent the address assigned to a radio.
*
* NOTE: the Bluetooth address is not variable, but shares struct
* radio_driver_s which depends on this type.
*/
struct netdev_maxaddr_s
......@@ -237,7 +247,7 @@ struct net_driver_s
#endif
#if defined(CONFIG_NET_ETHERNET) || defined(CONFIG_NET_6LOWPAN) || \
defined(CONFIG_NET_IEEE802154)
defined(CONFIG_NET_BLUETOOTH) || defined(CONFIG_NET_IEEE802154)
/* Link layer address */
......@@ -249,13 +259,14 @@ struct net_driver_s
struct ether_addr ether; /* Device Ethernet MAC address */
#endif
#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_IEEE802154)
#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_BLUETOOTH) || \
defined(CONFIG_NET_IEEE802154)
/* The address assigned to an IEEE 802.15.4 or generic packet radio. */
struct netdev_varaddr_s radio;
#endif /* CONFIG_NET_6LOWPAN || CONFIG_NET_IEEE802154 */
#endif
} d_mac;
#endif /* CONFIG_NET_ETHERNET || CONFIG_NET_6LOWPAN || CONFIG_NET_IEEE802154 */
#endif /* CONFIG_NET_ETHERNET || CONFIG_NET_6LOWPAN ... || CONFIG_NET_IEEE802154 */
/* Network identity */
......
......@@ -44,7 +44,8 @@
#include <nuttx/net/netdev.h>
#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_IEEE802154)
#if defined(CONFIG_NET_6LOWPAN) || defined(CONFIG_NET_BLUETOOTH) || \
defined (CONFIG_NET_IEEE802154)
/****************************************************************************
* Public Types
......@@ -155,7 +156,7 @@ struct iob_s; /* Forward reference */
struct radio_driver_s
{
/* This definitiona must appear first in the structure definition to
/* This definition must appear first in the structure definition to
* assure cast compatibility.
*/
......@@ -251,5 +252,5 @@ struct radio_driver_s
* Public Function Prototypes
****************************************************************************/
#endif /* CONFIG_NET_6LOWPAN || CONFIG_NET_IEEE802154 */
#endif /* CONFIG_NET_6LOWPAN || CONFIG_NET_BLUETOOTH || CONFIG_NET_IEEE802154 */
#endif /* __INCLUDE_NUTTX_NET_RADIODEV_H */
/****************************************************************************
* wireless/bluetooth/bt_att.h
* include/nuttx/wireless/bt_buf.h
* Bluetooth buffer management.
*
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
......@@ -49,22 +49,6 @@
#include <stddef.h>
#include <stdint.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* BT_BUF_MAX_DATA
* Maximum amount of data that can fit in a buffer.
*
* The biggest foreseeable buffer size requirement right now comes from
* the Bluetooth 4.2 SMP MTU which is 65. This then become 65 + 4 (L2CAP
* header) + 4 (ACL header) + 1 (H4 header) = 74. This also covers the
* biggest HCI commands and events which are a bit under the 70 byte
* mark.
*/
#define BT_BUF_MAX_DATA 74
/****************************************************************************
* Public Types
****************************************************************************/
......@@ -103,9 +87,12 @@ struct bt_buf_acl_data_s
uint16_t handle;
};
struct iob_s; /* Forward reference */
struct bt_buf_s
{
FAR struct iob_s *iob; /* IOB container of the buffer */
FAR struct bt_buf_s *flink;
union
{
struct bt_buf_hci_data_s hci;
......@@ -114,12 +101,13 @@ struct bt_buf_s
FAR uint8_t *data; /* Start of data in the buffer */
uint8_t len; /* Length of data in the buffer */
uint8_t ref : 5; /* Reference count */
uint8_t type : 3; /* Type of data contained in the buffer */
uint8_t pool; /* Memory pool */
uint8_t ref; /* Reference count */
uint8_t type; /* Type of data contained in the buffer */
/* The full available buffer. */
uint8_t buf[BT_BUF_MAX_DATA];
FAR struct iob_s *frame;
};
/****************************************************************************
......@@ -127,43 +115,60 @@ struct bt_buf_s
****************************************************************************/
/****************************************************************************
* Name: bt_buf_get
* Name: bt_buf_alloc
*
* Description:
* Get buffer from the available buffers pool with specified type and
* reserved headroom.
* The bt_buf_alloc function will get a free buffer for use by the
* Bluetooth stack with specified type and reserved headroom. The
* reference count is initially set to one.
*
* Interrupt handling logic will first attempt to allocate from the
* g_buf_free list. If that list is empty, it will attempt to allocate
* from its reserve, g_buf_free_irq. If that list is empty, then the
* allocation fails (NULL is returned).
*
* Non-interrupt handler logic will attempt to allocate from g_buf_free
* list. If that the list is empty, then the buffer structure will be
* allocated from the dynamic memory pool with some performance hit.
*
* Input Parameters:
* type - Buffer type.
* iob - The raw I/O buffer. If NULL, then bt_buf_alloc will
* allocate.
* reserve_head - How much headroom to reserve.
*
* Returned Value:
* New buffer or NULL if out of buffers.
*
* WARNING: If there are no available buffers and the function is
* called from a task or thread the call will block until a buffer
* becomes available in the pool.
* A reference to the allocated buffer structure. All user fields in this
* structure have been zeroed. On a failure to allocate, NULL is
* returned.
*
****************************************************************************/
FAR struct bt_buf_s *bt_buf_get(enum bt_buf_type_e type, size_t reserve_head);
struct iob_s; /* Forward reference */
FAR struct bt_buf_s *bt_buf_alloc(enum bt_buf_type_e type,
FAR struct iob_s *iob,
size_t reserve_head);
/****************************************************************************
* Name: bt_buf_put
* Name: bt_buf_release
*
* Description:
* Decrements the reference count of a buffer and puts it back into the
* pool if the count reaches zero.
* Decrements the reference count of a buffer and returns the buffer to the
* memory pool if the count decrements zero.
*
* Input Parameters:
* buf - Buffer.
*
* Returned Value:
* None
*
****************************************************************************/
void bt_buf_put(FAR struct bt_buf_s *buf);
void bt_buf_release(FAR struct bt_buf_s *buf);
/****************************************************************************
* Name: bt_buf_hold
* Name: bt_buf_addref
*
* Description:
* Increment the reference count of a buffer.
......@@ -173,14 +178,14 @@ void bt_buf_put(FAR struct bt_buf_s *buf);
*
****************************************************************************/
FAR struct bt_buf_s *bt_buf_hold(FAR struct bt_buf_s *buf);
FAR struct bt_buf_s *bt_buf_addref(FAR struct bt_buf_s *buf);
/****************************************************************************
* Name: bt_buf_add
* Name: bt_buf_extend
*
* Description:
* Increments the data length of a buffer to account for more data
* at the end.
* at the end of the buffer.
*
* Input Parameters:
* buf - Buffer to update.
......@@ -191,10 +196,10 @@ FAR struct bt_buf_s *bt_buf_hold(FAR struct bt_buf_s *buf);
*
****************************************************************************/
FAR void *bt_buf_add(FAR struct bt_buf_s *buf, size_t len);
FAR void *bt_buf_extend(FAR struct bt_buf_s *buf, size_t len);
/****************************************************************************
* Name: bt_buf_add_le16
* Name: bt_buf_put_le16
*
* Description:
* Adds 16-bit value in little endian format at the end of buffer.
......@@ -210,10 +215,10 @@ FAR void *bt_buf_add(FAR struct bt_buf_s *buf, size_t len);
*
****************************************************************************/
void bt_buf_add_le16(FAR struct bt_buf_s *buf, uint16_t value);
void bt_buf_put_le16(FAR struct bt_buf_s *buf, uint16_t value);
/****************************************************************************
* Name: bt_buf_push
* Name: bt_buf_provide
*
* Description:
* Modifies the data pointer and buffer length to account for more data
......@@ -228,10 +233,10 @@ void bt_buf_add_le16(FAR struct bt_buf_s *buf, uint16_t value);
*
****************************************************************************/
FAR void *bt_buf_push(FAR struct bt_buf_s *buf, size_t len);
FAR void *bt_buf_provide(FAR struct bt_buf_s *buf, size_t len);
/****************************************************************************
* Name: bt_buf_pull
* Name: bt_buf_consume
*
* Description:
* Removes data from the beginning of the buffer by modifying the data
......@@ -245,10 +250,10 @@ FAR void *bt_buf_push(FAR struct bt_buf_s *buf, size_t len);
*
****************************************************************************/
FAR void *bt_buf_pull(FAR struct bt_buf_s *buf, size_t len);
FAR void *bt_buf_consume(FAR struct bt_buf_s *buf, size_t len);
/****************************************************************************
* Name: bt_buf_pull_le16
* Name: bt_buf_get_le16
*
* Description:
* Same idea as with bt_buf_pull(), but a helper for operating on
......@@ -262,7 +267,7 @@ FAR void *bt_buf_pull(FAR struct bt_buf_s *buf, size_t len);
*
****************************************************************************/
uint16_t bt_buf_pull_le16(FAR struct bt_buf_s *buf);
uint16_t bt_buf_get_le16(FAR struct bt_buf_s *buf);
/****************************************************************************
* Name: bt_buf_tailroom
......@@ -306,22 +311,4 @@ size_t bt_buf_headroom(FAR struct bt_buf_s *buf);
#define bt_buf_tail(buf) ((buf)->data + (buf)->len)
/****************************************************************************
* Name: bt_buf_init
*
* Description:
* Initialize the buffers with specified amount of incoming and outgoing
* ACL buffers. The HCI command and event buffers will be allocated from
* whatever is left over.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero on success or (negative) error code on failure.
*
****************************************************************************/
int bt_buf_init(void);
#endif /* __INCLUDE_NUTTX_WIRELESS_BT_BUF_H */
......@@ -146,28 +146,6 @@ enum bt_security_e
* encryption. */
};
/****************************************************************************
* Name: bt_le_scan_cb_t
*
* Description:
* A function of this type will be called back when user application
* triggers active LE scan. The caller will populate all needed
* parameters based on data coming from scan result.
* Such function can be set by user when LE active scan API is used.
*
* Input Parameters:
* addr - Advertiser LE address and type.
* rssi - Strength of advertiser signal.
* adv_type - Type of advertising response from advertiser.
* adv_data - Address of buffer containing advertiser data.
* len - Length of advertiser data contained in buffer.
*
****************************************************************************/
typedef CODE void bt_le_scan_cb_t(FAR const bt_addr_le_t *addr, int8_t rssi,
uint8_t adv_type,
FAR const uint8_t *adv_data, uint8_t len);
/****************************************************************************
* Inline Functions
****************************************************************************/
......@@ -216,7 +194,7 @@ static inline int bt_addr_to_str(FAR const bt_addr_t *addr, FAR char *str,
*
****************************************************************************/
static inline int bt_addr_le_to_str(const bt_addr_le_t *addr, char *str,
static inline int bt_addr_le_to_str(FAR const bt_addr_le_t *addr, char *str,
size_t len)
{
char type[7];
......@@ -245,83 +223,4 @@ static inline int bt_addr_le_to_str(const bt_addr_le_t *addr, char *str,
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: bt_init
*
* Description:
* Initialize Bluetooth. Must be the called before anything else.
*
* Returned Value:
* Zero on success or (negative) error code otherwise.
*
****************************************************************************/
int bt_init(void);
/****************************************************************************
* Name: bt_start_advertising
*
* Description:
* Set advertisement data, scan response data, advertisement parameters
* and start advertising.
*
* Input Parameters:
* type - Advertising type.
* ad - Data to be used in advertisement packets.
* sd - Data to be used in scan response packets.
*
* Returned Value:
* Zero on success or (negative) error code otherwise.
*
****************************************************************************/
int bt_start_advertising(uint8_t type, FAR const struct bt_eir_s *ad,
FAR const struct bt_eir_s *sd);
/****************************************************************************
* Name: bt_stop_advertising
*
* Description:
* Stops ongoing advertising.
*
* Returned Value:
* Zero on success or (negative) error code otherwise.
*
****************************************************************************/
int bt_stop_advertising(void);
/****************************************************************************
* Name: bt_start_scanning
*
* Description:
* Start LE scanning with and provide results through the specified
* callback.
*
* Input Parameters:
* filter_dups - Enable duplicate filtering (or not).
* cb - Callback to notify scan results.
*
* Returned Value:
* Zero on success or error code otherwise, positive in case
* of protocol error or negative (POSIX) in case of stack internal error
*
****************************************************************************/
int bt_start_scanning(uint8_t filter_dups, bt_le_scan_cb_t cb);
/****************************************************************************
* Name: bt_stop_scanning
*
* Description:
* Stops ongoing LE scanning.
*
* Returned Value:
* Zero on success or error code otherwise, positive in case
* of protocol error or negative (POSIX) in case of stack internal error
*
****************************************************************************/
int bt_stop_scanning(void);
#endif /* __INCLUDE_NUTTX_WIRELESS_BT_CORE_H */
......@@ -72,16 +72,60 @@ struct bt_driver_s
* Public Function Prototypes
****************************************************************************/
/* Register a new HCI driver to the Bluetooth stack */
/****************************************************************************
* Name: bt_driver_register
*
* Description:
* Register the Bluetooth low-level driver with the Bluetooth stack.
* This is called from the low-level driver and is part of the driver
* interface prototyped in include/nuttx/wireless/bt_driver.h
*
* Input Parameters:
* dev - An instance of the low-level drivers interface structure.
*
* Returned Value:
* Zero is returned on success; a negated errno value is returned on any
* failure.
*
****************************************************************************/
int bt_driver_register(FAR const struct bt_driver_s *dev);
/* Unregister a previously registered HCI driver */
/****************************************************************************
* Name: bt_driver_unregister
*
* Description:
* Unregister a Bluetooth low-level driver previously registered with
* bt_driver_register. This may be called from the low-level driver and
* is part of the driver interface prototyped in
* include/nuttx/wireless/bt_driver.h
*
* Input Parameters:
* dev - An instance of the low-level drivers interface structure.
*
* Returned Value:
* None
*
****************************************************************************/
void bt_driver_unregister(FAR const struct bt_driver_s *dev);
/* Receive data from the controller/HCI driver */
/****************************************************************************
* Name: bt_hci_receive
*
* Description:
* Called by the Bluetooth low-level driver when new data is received from
* the radio. This may be called from the low-level driver and is part of
* the driver interface prototyped in include/nuttx/wireless/bt_driver.h
*
* Input Parameters:
* buf - An instance of the buffer structure providing the received frame.
*
* Returned Value:
* None
*
****************************************************************************/
void bt_recv(FAR struct bt_buf_s *buf);
void bt_hci_receive(FAR struct bt_buf_s *buf);
#endif /* __INCLUDE_NUTTX_WIRELESS_BT_DRIVER_H */
......@@ -46,7 +46,6 @@
* Included Files
****************************************************************************/
#include <nuttx/wireless/bt_conn.h>
#include <nuttx/wireless/bt_uuid.h>
/****************************************************************************
......
/****************************************************************************
* wireless/bluetooth/bt_ioctl.h
* Bluetooth Network IOCTL commands.
*
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Ported from the Intel/Zephyr arduino101_firmware_source-v1.tar package
* where the code was released with a compatible 3-clause BSD license:
*
* Copyright (c) 2016, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_WIRELESS_BT_IOCTL_H
#define __INCLUDE_NUTTX_WIRELESS_BT_IOCTL_H 1
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/wireless/bt_core.h>
#include <nuttx/wireless/bt_hci.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define HCI_DEVNAME_SIZE 32 /* Maximum size of node name */
#define HCI_FEATURES_SIZE 8 /* LMP features */
/* Bluetooth network device IOCTL commands. */
#ifndef WL_BLUETOOTHCMDS != 15
# error Incorrect setting for number of Bluetooth IOCTL commands
#endif
/* NetBSD IOCTL commands ****************************************************/
/* All of the following use an argument of type struct btreg_s:
*
* SIOCGBTINFO
* Get Bluetooth device Info. Given the device name, fill in the btreq_s
* structure including the address field for use with socket addressing as
* above.
* SIOCGBTINFOA
* Get Bluetooth device Info from Address. Given the device address, fill
* in the btreq_s structure including the name field.
* SIOCNBTINFO
* Next Bluetooth device Info. If name field is empty, the first device
* will be returned. Otherwise, the next device will be returned until
* no more devices are found when the call will fail, with error ENXIO.
* Thus, you can cycle through all devices in the system.
* SIOCSBTFLAGS
* Set Bluetooth device Flags. Not all flags are settable.
* SIOCGBTFEAT
* Get Bluetooth device Features. This returns the cached basic (page 0)
* and extended (page 1 & 2) features.
* SIOCSBTPOLICY
* Set Bluetooth device Link Policy bits.
* SIOCSBTPTYPE
* Set Bluetooth device Packet Types. You can only set packet types that
* the device supports.
* SIOCGBTSTATS
* Read device statistics.
* SIOCZBTSTATS
* Read device statistics, and zero them.
*
* NOTE: These are here for reference. None of the NetBSD IOCTL commands
* have been implemented in NuttX.
*/
#define SIOCGBTINFO _WLIOC(WL_BLUETOOTHFIRST + 0)
#define SIOCGBTINFOA _WLIOC(WL_BLUETOOTHFIRST + 1)
#define SIOCNBTINFO _WLIOC(WL_BLUETOOTHFIRST + 2)
#define SIOCSBTFLAGS _WLIOC(WL_BLUETOOTHFIRST + 3)
#define SIOCGBTFEAT _WLIOC(WL_BLUETOOTHFIRST + 4)
#define SIOCSBTPOLICY _WLIOC(WL_BLUETOOTHFIRST + 5)
#define SIOCSBTPTYPE _WLIOC(WL_BLUETOOTHFIRST + 6)
#define SIOCGBTSTATS _WLIOC(WL_BLUETOOTHFIRST + 7)
#define SIOCZBTSTATS _WLIOC(WL_BLUETOOTHFIRST + 8)
/* NuttX-specific IOCTL commands. *******************************************/
/* SIOCBT_ADVERTISESTART
* Description: Set advertisement data, scan response data,
* advertisement parameters and start advertising.
* Input: Pointer to read-write instance of struct
* bt_advertisestart_s.
* Output: None
*/
#define SIOCBT_ADVERTISESTART _WLIOC(WL_BLUETOOTHFIRST + 9)
/* SIOCBT_ADVERTISESTOP
* Description: Stop advertising.
* Input: A reference to a write-able instance of struct
* bt_scanstop_s.
* Output: None
*/
#define SIOCBT_ADVERTISESTOP _WLIOC(WL_BLUETOOTHFIRST + 10)
/* SIOCBT_SCANSTART
* Description: Start LE scanning. Buffered scan results may be
* obtained via SIOCBT_SCANGET
* Input: A read-only referent to struct bt_scanstart_s.
* Output: None
*/
#define SIOCBT_SCANSTART _WLIOC(WL_BLUETOOTHFIRST + 11)
/* SIOCBT_SCANGET
* Description: Return scan results buffered since the call time that
* the SIOCBT_SCANGET command was invoked.
* Input: A reference to a write-able instance of struct
* bt_scanresult_s.
* Output: Buffered scan result results are returned in the user-
* provided buffer space.
*/
#define SIOCBT_SCANGET _WLIOC(WL_BLUETOOTHFIRST + 12)
/* SIOCBT_SCANSTOP
* Description: Stop LE scanning and discard any buffered results.
* Input: A reference to a write-able instance of struct
* bt_scanstop_s.
* Output: None
*/
#define SIOCBT_SCANSTOP _WLIOC(WL_BLUETOOTHFIRST + 13)
/* SIOCBT_SECURITY
* Description: Enable security for a connection.
* Input: A reference to a write-able instance of struct
* bt_security_s.
* Output: None
*/
#define SIOCBT_SECURITY _WLIOC(WL_BLUETOOTHFIRST + 14)
/* Definitions associated with struct btreg_s *******************************/
/* struct btreq_s union field accessors */
#define btr_flags btru.btri.btri_flags
#define btr_bdaddr btru.btri.btri_bdaddr
#define btr_num_cmd btru.btri.btri_num_cmd
#define btr_num_acl btru.btri.btri_num_acl
#define btr_num_sco btru.btri.btri_num_sco
#define btr_acl_mtu btru.btri.btri_acl_mtu
#define btr_sco_mtu btru.btri.btri_sco_mtu
#define btr_link_policy btru.btri.btri_link_policy
#define btr_packet_type btru.btri.btri_packet_type
#define btr_max_acl btru.btri.btri_max_acl
#define btr_max_sco btru.btri.btri_max_sco
#define btr_features0 btru.btrf.btrf_page0
#define btr_features1 btru.btrf.btrf_page1
#define btr_features2 btru.btrf.btrf_page2
#define btr_stats btru.btrs
/* btr_flags */
#define BTF_UP (1 << 0) /* Unit is up */
#define BTF_RUNNING (1 << 1) /* Unit is running */
#define BTF_XMIT_CMD (1 << 2) /* Transmitting CMD packets */
#define BTF_XMIT_ACL (1 << 3) /* Transmitting ACL packets */
#define BTF_XMIT_SCO (1 << 4) /* Transmitting SCO packets */
#define BTF_INIT_BDADDR (1 << 5) /* Waiting for bdaddr */
#define BTF_INIT_BUFFER_SIZE (1 << 6) /* Waiting for buffer size */
#define BTF_INIT_FEATURES (1 << 7) /* Waiting for features */
#define BTF_NOOP_ON_RESET (1 << 8) /* Wait for No-op on reset */
#define BTF_INIT_COMMANDS (1 << 9) /* Waiting for supported commands */
#define BTF_MASTER (1 << 10) /* Request Master role */
/****************************************************************************
* Public Types
****************************************************************************/
/* Common structure for Bluetooth IOCTL commands */
struct bt_stats
{
uint32_t err_tx;
uint32_t err_rx;
uint32_t cmd_tx;
uint32_t evt_rx;
uint32_t acl_tx;
uint32_t acl_rx;
uint32_t sco_tx;
uint32_t sco_rx;
uint32_t byte_tx;
uint32_t byte_rx;
};
struct btreq_s
{
char btr_name[HCI_DEVNAME_SIZE]; /* Device name */
union
{
struct
{
bt_addr_t btri_bdaddr; /* Device bdaddr */
uint16_t btri_flags; /* flags */
uint16_t btri_num_cmd; /* # of free cmd buffers */
uint16_t btri_num_acl; /* # of free ACL buffers */
uint16_t btri_num_sco; /* # of free SCO buffers */
uint16_t btri_acl_mtu; /* ACL mtu */
uint16_t btri_sco_mtu; /* SCO mtu */
uint16_t btri_link_policy; /* Link Policy */
uint16_t btri_packet_type; /* Packet Type */
uint16_t btri_max_acl; /* max ACL buffers */
uint16_t btri_max_sco; /* max SCO buffers */
} btri;
struct
{
uint8_t btrf_page0[HCI_FEATURES_SIZE]; /* basic */
uint8_t btrf_page1[HCI_FEATURES_SIZE]; /* extended page 1 */
uint8_t btrf_page2[HCI_FEATURES_SIZE]; /* extended page 2 */
} btrf;
struct bt_stats btrs; /* unit stats */
} btru;
};
/* Read-only data that accompanies the SIOCBT_ADVERTISESTART IOCTL command.
* Advertising types are defined in bt_hci.h.
*/
struct bt_advertisestart_s
{
char as_name[HCI_DEVNAME_SIZE]; /* Device name */
uint8_t as_type; /* Advertising type */
FAR struct bt_eir_s as_ad; /* Data for advertisement packets */
FAR struct bt_eir_s as_sd; /* Data for scan response packets */
};
/* The read-only data that accompanies the SIOCBT_SCANSTOP IOCTL command */
struct bt_advertisestop_s
{
char at_name[HCI_DEVNAME_SIZE]; /* Device name */
};
/* The read-only data that accompanies the SIOCBT_SCANSTART IOCTL command */
struct bt_scanstart_s
{
char ss_name[HCI_DEVNAME_SIZE]; /* Device name */
bool ss_dupenable; /* True: enable duplicate filtering */
};
/* The read-only data that accompanies the SIOCBT_SCANSTOP IOCTL command */
struct bt_scanstop_s
{
char st_name[HCI_DEVNAME_SIZE]; /* Device name */
};
/* Write-able data that accompanies the SIOCBT_SCANGET IOCTL command */
struct bt_scanresponse_s
{
char sr_name[HCI_DEVNAME_SIZE]; /* Device name */
bt_addr_le_t sr_addr; /* Advertiser LE address and type */
int8_t sr_rssi; /* Strength of advertiser signal */
uint8_t sr_type; /* Type of advertising response */
uint8_t sr_len; /* Length of advertiser data */
uint8_t sr_data[CONFIG_BLUETOOTH_MAXSCANDATA];
};
struct bt_scanresult_s
{
char sr_name[HCI_DEVNAME_SIZE]; /* Device name */
uint8_t sr_nrsp; /* Input: Max number of responses
* Return: Actual number of responses */
struct bt_scanresponse_s sr_rsp[1];
};
#define SIZEOF_BT_SCANRESULT_S(n) \
(sizeof(struct bt_scanresult_s) + \
((n) - 1) * sizeof(struct bt_scanresponse_s))
/* Read-only data that accompanies the SIOCBT_SECURITY IOCTL command */
struct bt_security_s
{
char se_name[HCI_DEVNAME_SIZE]; /* Device name */
bt_addr_le_t se_addr; /* BLE address */
enum bt_security_e se_level; /* Security level */
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#endif /* __INCLUDE_NUTTX_WIRELESS_BT_IOCTL_H */
......@@ -53,6 +53,7 @@
/****************************************************************************
* Public Types
****************************************************************************/
/* This is the type of the Bluetooth UART upper-half driver interrupt
* handler used with the struct btuart_lowerhalf_s attach() method.
*/
......
......@@ -2,7 +2,7 @@
* include/nuttx/wireless/wireless.h
* Wireless network IOCTL commands
*
* Copyright (C) 2011-2013, 2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2011-2013, 2017-2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
......@@ -159,12 +159,20 @@
#define WL_NETFIRST 0x0001 /* First network command */
#define WL_NNETCMDS 0x0032 /* Number of network commands */
/* Reserved for Bluetooth network devices (see bt_ioctls.h) */
#define WL_BLUETOOTHFIRST (WL_NETFIRST + WL_NNETCMDS)
#define WL_BLUETOOTHCMDS (15)
#define WL_IBLUETOOTHCMD(cmd) (_WLIOCVALID(cmd) && \
_IOC_NR(cmd) >= WL_BLUETOOTHFIRST && \
_IOC_NR(cmd) < (WL_BLUETOOTHFIRST + WL_BLUETOOTHCMDS))
/* Reserved for IEEE802.15.4 wireless network devices
* NOTE: Not used. Currently logic uses IOCTL commands from the IEEE802.15.4
* character driver space.
*/
#define WL_802154FIRST (WL_NETFIRST + WL_NNETCMDS)
#define WL_802154FIRST (WL_BLUETOOTHFIRST + WL_BLUETOOTHCMDS)
#define WL_N802154CMDS (3)
#define WL_IS802154CMD(cmd) (_WLIOCVALID(cmd) && \
_IOC_NR(cmd) >= WL_802154FIRST && \
......@@ -178,25 +186,25 @@
_IOC_NR(cmd) >= WL_PKTRADIOFIRST && \
_IOC_NR(cmd) < (WL_PKTRADIOFIRST + WL_NPKTRADIOCMDS))
/* ------------------------------- WIRELESS EVENTS ------------------------------- */
/* ------------------------------ WIRELESS EVENTS -------------------------------- */
/* Those are *NOT* ioctls, do not issue request on them !!! */
/* Most events use the same identifier as ioctl requests */
#define IWEVTXDROP 0x8C00 /* Packet dropped to excessive retry */
#define IWEVQUAL 0x8C01 /* Quality part of statistics (scan) */
#define IWEVCUSTOM 0x8C02 /* Driver specific ascii string */
#define IWEVREGISTERED 0x8C03 /* Discovered a new node (AP mode) */
#define IWEVEXPIRED 0x8C04 /* Expired a node (AP mode) */
#define IWEVGENIE 0x8C05 /* Generic IE (WPA, RSN, WMM, ..)
#define IWEVTXDROP 0x8c00 /* Packet dropped to excessive retry */
#define IWEVQUAL 0x8c01 /* Quality part of statistics (scan) */
#define IWEVCUSTOM 0x8c02 /* Driver specific ascii string */
#define IWEVREGISTERED 0x8c03 /* Discovered a new node (AP mode) */
#define IWEVEXPIRED 0x8c04 /* Expired a node (AP mode) */
#define IWEVGENIE 0x8c05 /* Generic IE (WPA, RSN, WMM, ..)
* (scan results); This includes id and
* length fields. One IWEVGENIE may
* contain more than one IE. Scan
* results may contain one or more
* IWEVGENIE events. */
#define IWEVMICHAELMICFAILURE 0x8C06 /* Michael MIC failure
#define IWEVMICHAELMICFAILURE 0x8c06 /* Michael MIC failure
* (struct iw_michaelmicfailure)
*/
#define IWEVASSOCREQIE 0x8C07 /* IEs used in (Re)Association Request.
#define IWEVASSOCREQIE 0x8c07 /* IEs used in (Re)Association Request.
* The data includes id and length
* fields and may contain more than one
* IE. This event is required in
......@@ -205,18 +213,18 @@
* should be sent just before
* IWEVREGISTERED event for the
* association. */
#define IWEVASSOCRESPIE 0x8C08 /* IEs used in (Re)Association
#define IWEVASSOCRESPIE 0x8c08 /* IEs used in (Re)Association
* Response. The data includes id and
* length fields and may contain more
* than one IE. This may be sent
* between IWEVASSOCREQIE and
* IWEVREGISTERED events for the
* association. */
#define IWEVPMKIDCAND 0x8C09 /* PMKID candidate for RSN
#define IWEVPMKIDCAND 0x8c09 /* PMKID candidate for RSN
* pre-authentication
* (struct iw_pmkid_cand) */
#define IWEVFIRST 0x8C00
#define IWEVFIRST 0x8c00
#define IW_EVENT_IDX(cmd) ((cmd) - IWEVFIRST)
/* Other Common Wireless Definitions ***********************************************/
......
......@@ -59,8 +59,9 @@
#define PF_INET 2 /* IPv4 Internet protocols */
#define PF_INET6 3 /* IPv6 Internet protocols */
#define PF_PACKET 4 /* Low level packet interface */
#define PF_IEEE802154 5 /* Low level IEEE 802.15.4 radio frame interface */
#define PF_PKTRADIO 6 /* Low level packet radio interface */
#define PF_BLUETOOTH 5 /* Bluetooth sockets */
#define PF_IEEE802154 6 /* Low level IEEE 802.15.4 radio frame interface */
#define PF_PKTRADIO 7 /* Low level packet radio interface */
/* Supported Address Families. Opengroup.org requires only AF_UNSPEC,
* AF_UNIX, AF_INET and AF_INET6.
......@@ -72,6 +73,7 @@
#define AF_INET PF_INET
#define AF_INET6 PF_INET6
#define AF_PACKET PF_PACKET
#define AF_BLUETOOTH PF_BLUETOOTH
#define AF_IEEE802154 PF_IEEE802154
#define AF_PKTRADIO PF_PKTRADIO
......@@ -156,6 +158,10 @@
#define SOL_IPV6 2 /* See options in include/netinet/ip6.h */
#define SOL_TCP 3 /* See options in include/netinet/tcp.h */
#define SOL_UDP 4 /* See options in include/netinit/udp.h */
#define SOL_HCI 5 /* See options in include/netpacket/bluetooth.h */
#define SOL_L2CAP 6 /* See options in include/netpacket/bluetooth.h */
#define SOL_SCO 7 /* See options in include/netpacket/bluetooth.h */
#define SOL_RFCOMM 8 /* See options in include/netpacket/bluetooth.h */
/* Protocol-level socket options may begin with this value */
......
......@@ -294,6 +294,7 @@ source "net/pkt/Kconfig"
source "net/local/Kconfig"
source "net/tcp/Kconfig"
source "net/udp/Kconfig"
source "net/bluetooth/Kconfig"
source "net/ieee802154/Kconfig"
source "net/icmp/Kconfig"
source "net/icmpv6/Kconfig"
......
############################################################################
# net/Makefile
#
# Copyright (C) 2007, 2008, 2011-2017 Gregory Nutt. All rights reserved.
# Copyright (C) 2007, 2008, 2011-2018 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
......@@ -68,6 +68,7 @@ include local/Make.defs
include tcp/Make.defs
include udp/Make.defs
include sixlowpan/Make.defs
include bluetooth/Make.defs
include ieee802154/Make.defs
include devif/Make.defs
include ipforward/Make.defs
......
......@@ -9,6 +9,7 @@ Directory Structure
`- net/
|
+- arp - Address resolution protocol (IPv4)
+- bluetooth - PF_BLUETOOTH socket interface
+- devif - Stack/device interface layer
+- icmp - Internet Control Message Protocol (IPv4)
+- icmpv6 - Internet Control Message Protocol (IPv6)
......@@ -28,7 +29,6 @@ Directory Structure
+- usrsock - User socket API for user-space networking stack
`- utils - Miscellaneous utility functions
+-------------------------------------------------------------------++------------------------+
| Application layer || usrsock daemon |
+-------------------------------------------------------------------++------------------------+
......