Various fixes/changes from intial testing of the HCI UART on the STM32F4-Discovery board. Re-organized how the Blutetooth network driver is initialized. Added lots of new debug output. Add a new STM32 F4 Discovery configuration for testing the HCI UART. Various fixes to get through initialization (still does not).

This commit is contained in:
Gregory Nutt 2018-04-14 09:23:08 -06:00
parent ee6264df4e
commit fa287e8863
8 changed files with 437 additions and 295 deletions

View file

@ -1215,7 +1215,7 @@ static ssize_t hciuart_copyfromrxbuffer(const struct hciuart_config_s *config,
static ssize_t hciuart_copytotxfifo(const struct hciuart_config_s *config)
{
struct hciuart_state_s *state;
ssize_t nbytes = 0;
ssize_t nbytes;
uint16_t txhead;
uint16_t txtail;
uint8_t txbyte;
@ -1225,6 +1225,7 @@ static ssize_t hciuart_copytotxfifo(const struct hciuart_config_s *config)
state = config->state;
txhead = state->txhead;
txtail = state->txtail;
nbytes = 0;
/* Compare the Tx buffer head and tail indices. If the Tx buffer is
* empty, then we finished with the copy.
@ -1258,7 +1259,8 @@ static ssize_t hciuart_copytotxfifo(const struct hciuart_config_s *config)
nbytes++;
}
wlinfo("nbytes %ld\n", (long)nbytes);
wlinfo("txhead %u txtail %u nbytes %ld\n", txhead, txtail, (long)nbytes);
state->txhead = txhead;
return nbytes;
}
@ -2103,10 +2105,10 @@ static ssize_t hciuart_write(const struct btuart_lowerhalf_s *lower,
hciuart_disableints(config, USART_CR1_TXEIE);
spin_unlock_irqrestore(flags);
/* Loop until all of the user data have been moved to the Tx buffer */
/* Loop until all of the user data have been moved to the Tx buffer */
src = buffer;
remaining = buflen;
src = buffer;
remaining = buflen;
while (remaining > 0)
{
@ -2187,7 +2189,7 @@ static ssize_t hciuart_write(const struct btuart_lowerhalf_s *lower,
if (state->txhead != state->txtail)
{
flags = spin_lock_irqsave();
hciuart_disableints(config, USART_CR1_TXEIE);
hciuart_enableints(config, USART_CR1_TXEIE);
spin_unlock_irqrestore(flags);
}

View file

@ -1034,6 +1034,9 @@ Just type helloxx:
Configurations
==============
Common Information
------------------
Each STM32F4Discovery configuration is maintained in a sub-directory and
can be selected as follow:
@ -1041,7 +1044,21 @@ can be selected as follow:
./configure.sh STM32F4Discovery/<subdir>
cd -
Where <subdir> is one of the following:
Where <subdir> is one of the sub-directories listed in the next paragraph
NOTES (common for all configurations):
1. This configuration uses the mconf-based configuration tool. To
change this configuration using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
Configuration Sub-directories
-------------------------
cxxtest:
-------
@ -1060,16 +1077,7 @@ Where <subdir> is one of the following:
NuttX uClibc++ GIT repository. See the README.txt file there for
instructions on how to install uClibc++
2. This configuration uses the mconf-based configuration tool. To
change this configuration using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
3. Ideally, you should build with a toolchain based on GLIBC or
2. Ideally, you should build with a toolchain based on GLIBC or
uClibc++. It you use a toolchain based on newlib, you may see
an error like the following:
@ -1098,7 +1106,7 @@ Where <subdir> is one of the following:
arm-none-eabi-ar.exe rcs libsupc++.a vterminate.o
4. Exceptions are enabled and workking (CONFIG_UCLIBCXX_EXCEPTION=y)
3. Exceptions are enabled and workking (CONFIG_UCLIBCXX_EXCEPTION=y)
elf:
---
@ -1108,34 +1116,25 @@ Where <subdir> is one of the following:
NOTES:
1. This configuration uses the mconf-based configuration tool. To
change this configuration using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
2. Default platform/toolchain:
1. Default platform/toolchain:
CONFIG_HOST_WINDOWS=y : Windows
CONFIG_WINDOWS_CYGWIN=y : Cygwin environment on Windows
CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y : CodeSourcery under Windows
3. By default, this project assumes that you are *NOT* using the DFU
2. By default, this project assumes that you are *NOT* using the DFU
bootloader.
4. It appears that you cannot execute from CCM RAM. This is why the
3. It appears that you cannot execute from CCM RAM. This is why the
following definition appears in the defconfig file:
CONFIG_STM32_CCMEXCLUDE=y
5. This configuration requires that you have the genromfs tool installed
4. This configuration requires that you have the genromfs tool installed
on your system and that you have the full path to the installed genromfs
executable in PATH variable (see apps/examples/README.txt)
6. This configuration can be extended to use the hello++4 example and to
5. This configuration can be extended to use the hello++4 example and to
build uClibc with the following additions to to the configuration file
(from Leo aloe3132):
@ -1150,7 +1149,7 @@ Where <subdir> is one of the following:
CONFIG_EXAMPLES_ELF_CXXINITIALIZE=y
CONFIG_EXAMPLES_ELF_UCLIBCXX=y
7. By default, this configuration uses the ROMFS file system. It can also
6. By default, this configuration uses the ROMFS file system. It can also
be modified to use the compressed CROMFS:
-CONFIG_PATH_INITIAL="/mnt/romfs"
@ -1162,7 +1161,7 @@ Where <subdir> is one of the following:
-CONFIG_EXAMPLES_ELF_ROMFS=y
+CONFIG_EXAMPLES_ELF_CROMFS=y
8. The network initialization thread is enabled in this configuration.
7. The network initialization thread is enabled in this configuration.
As a result, networking initialization is performed asynchronously with
NSH bring-up.
@ -1173,6 +1172,37 @@ Where <subdir> is one of the following:
OUT mode. In that mode, the PHY interrupt is not supported. The NINT
pin serves as REFLCK0 in that case.
hciuart:
-------
This configuration was used for test the HCI UART driver. The HCI UART
is enabled on USART3 as well as the test application at
apps/wireless/bluetoot/btsak.
NOTES:
1. This configuration assumes that that you are using the STM32F4DIS-BB
base board with serial console on USART6. If you are not using the
STM32F4DIS-BB, then you will want to disable support for the base
board.
-CONFIG_STM32F4DISBB=y
+# CONFIG_STM32F4DISBB is not set
You may also want to reconfigure the serial console to USART1.
2. The HCI UART is assume to connect to the UART3 on the following pins:
USART3 TX : PB10
USART3 RX : PB11
USART3 CTS: PB13
USART3 RTS: PB14
The HCI UART selection can be changed by re-configuring and assigning
the different U[S]ART to the HCI. The U[S]ART pin selections can be
changed by modifying the disambiguation definitions in
configs/stm32f4discovery/include/board.h
ipv6:
----
This is another version of the NuttShell configuration for the
@ -1273,16 +1303,7 @@ Where <subdir> is one of the following:
NOTES:
1. This configuration uses the mconf-based configuration tool. To
change this configuration using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
2. This is the default platform/toolchain in the configuration:
1. This is the default platform/toolchain in the configuration:
CONFIG_HOST_WINDOWS=y : Windows
CONFIG_WINDOWS_CYGWIN=y : Cygwin environment on Windows
@ -1290,7 +1311,7 @@ Where <subdir> is one of the following:
This is easily changed by modifying the configuration.
3. At the end of the build, there will be several files in the top-level
2. At the end of the build, there will be several files in the top-level
NuttX build directory:
PASS1:
@ -1303,7 +1324,7 @@ Where <subdir> is one of the following:
nuttx.hex - The pass2 Intel HEX file (selected in defconfig)
System.map - Symbols in the kernel-space ELF file
4. Combining .hex files. If you plan to use the STM32 ST-Link Utility to
3. Combining .hex files. If you plan to use the STM32 ST-Link Utility to
load the .hex files into FLASH, then you need to combine the two hex
files into a single .hex file. Here is how you can do that.
@ -1402,16 +1423,7 @@ Where <subdir> is one of the following:
NOTES:
1. This configuration uses the mconf-based configuration tool. To
change this configuration using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
2. By default, this configuration uses the CodeSourcery toolchain
1. By default, this configuration uses the CodeSourcery toolchain
for Windows and builds under Cygwin (or probably MSYS). That
can easily be reconfigured, of course.
@ -1419,7 +1431,7 @@ Where <subdir> is one of the following:
CONFIG_WINDOWS_CYGWIN=y : Using Cygwin
CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y : CodeSourcery for Windows
3. To use this configuration with the STM32F4DIS-BB baseboard you
2. To use this configuration with the STM32F4DIS-BB baseboard you
should:
- Select the STM32F4DIS-BB baseboard in the board configuration
@ -1429,7 +1441,7 @@ Where <subdir> is one of the following:
- Select USART6 as the serial console at 115200 8N1 in the
Drivers menus
4. This example supports the PWM test (apps/examples/pwm) but this must
3. This example supports the PWM test (apps/examples/pwm) but this must
be manually enabled by selecting:
CONFIG_PWM=y : Enable the generic PWM infrastructure
@ -1442,7 +1454,7 @@ Where <subdir> is one of the following:
CONFIG_DEBUG_PWM_INFO
5. This example supports the Quadrature Encode test (apps/examples/qencoder)
4. This example supports the Quadrature Encode test (apps/examples/qencoder)
but this must be manually enabled by selecting:
CONFIG_EXAMPLES_QENCODER=y : Enable the apps/examples/qencoder
@ -1457,7 +1469,7 @@ Where <subdir> is one of the following:
CONFIG_DEBUG_SENSORS
6. This example supports the watchdog timer test (apps/examples/watchdog)
5. This example supports the watchdog timer test (apps/examples/watchdog)
but this must be manually enabled by selecting:
CONFIG_EXAMPLES_WATCHDOG=y : Enable the apps/examples/watchdog
@ -1474,7 +1486,7 @@ Where <subdir> is one of the following:
The IWDG timer has a range of about 35 seconds and should not be an issue.
7. USB Support (CDC/ACM device)
6. USB Support (CDC/ACM device)
CONFIG_STM32_OTGFS=y : STM32 OTG FS support
CONFIG_USBDEV=y : USB device support must be enabled
@ -1482,7 +1494,7 @@ Where <subdir> is one of the following:
CONFIG_NSH_BUILTIN_APPS=y : NSH built-in application support must be enabled
CONFIG_NSH_ARCHINIT=y : To perform USB initialization
8. Using the USB console.
7. Using the USB console.
The STM32F4Discovery NSH configuration can be set up to use a USB CDC/ACM
(or PL2303) USB console. The normal way that you would configure the
@ -1499,7 +1511,7 @@ Where <subdir> is one of the following:
times before NSH starts. The logic does this to prevent sending USB data
before there is anything on the host side listening for USB serial input.
9. Here is an alternative USB console configuration. The following
8. Here is an alternative USB console configuration. The following
configuration will also create a NSH USB console but this version
will use /dev/console. Instead, it will use the normal /dev/ttyACM0
USB serial device for the console:
@ -1538,7 +1550,7 @@ Where <subdir> is one of the following:
See the usbnsh configuration below for more information on configuring
USB trace output and the USB monitor.
10. USB OTG FS Host Support. The following changes will enable support for
9. USB OTG FS Host Support. The following changes will enable support for
a USB host on the STM32F4Discovery, including support for a mass storage
class driver:
@ -1613,7 +1625,7 @@ Where <subdir> is one of the following:
nsh> umount /mnt/stuff
11. I used this configuration to test the USB hub class. I did this
10. I used this configuration to test the USB hub class. I did this
testing with the following changes to the configuration (in addition
to those listed above for base USB host/mass storage class support):
@ -1646,7 +1658,7 @@ Where <subdir> is one of the following:
2015-04-30
Appears to be fully functional.
12. Using USB Device as a Mass Storage for the host computer:
11. Using USB Device as a Mass Storage for the host computer:
System Type --->
STM32 Peripheral Support --->
@ -1734,16 +1746,7 @@ Where <subdir> is one of the following:
1. As of this writing, I have not seen the LCD work!
2. This configuration uses the mconf-based configuration tool. To
change this configuration using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
3. This configured can be re-configured to use either the
2. This configured can be re-configured to use either the
UG-2864AMBAG01 or UG-2864HSWEG01 0.96 inch OLEDs by adding
or changing the following items in the configuration (using
'make menuconfig'):
@ -1799,23 +1802,14 @@ Where <subdir> is one of the following:
NOTES:
1. This configuration uses the mconf-based configuration tool. To
change this configuration using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
2. Default configuration is Cygwin under windows using the CodeSourcery
1. Default configuration is Cygwin under windows using the CodeSourcery
toolchain:
CONFIG_HOST_WINDOWS=y : Windows
CONFIG_WINDOWS_CYGWIN=y : Cygwin
CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y : CodeSourcery under Windows
3. CONFIG_ARCH_CUSTOM_PMINIT and CONFIG_ARCH_IDLE_CUSTOM are necessary
2. CONFIG_ARCH_CUSTOM_PMINIT and CONFIG_ARCH_IDLE_CUSTOM are necessary
parts of the PM configuration:
CONFIG_ARCH_CUSTOM_PMINIT=y
@ -1836,7 +1830,7 @@ Where <subdir> is one of the following:
normal STM32 IDLE loop (of arch/arm/src/stm32/stm32_idle.c) and replace
this with our own custom IDLE loop (at configs/stm3210-eval/src/up_idle.c).
4. Here are some additional things to note in the configuration:
3. Here are some additional things to note in the configuration:
CONFIG_PM_BUTTONS=y
@ -1859,22 +1853,13 @@ Where <subdir> is one of the following:
NOTES:
1. This configuration uses the mconf-based configuration tool. To
change this configuration using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
2. Default toolchain:
1. Default toolchain:
CONFIG_HOST_WINDOWS=y : Builds under windows
CONFIG_WINDOWS_CYGWIN=y : Using Cygwin and
CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y : The native Windows CodeSourcery toolchain
3. By default, this project assumes that you are *NOT* using the DFU
2. By default, this project assumes that you are *NOT* using the DFU
bootloader.
pseudoterm:
@ -1921,16 +1906,7 @@ Where <subdir> is one of the following:
NOTES:
1. This configuration uses the mconf-based configuration tool. To
change this configuration using that tool, you should:
a. Build and install the kconfig-mconf tool. See nuttx/README.txt
see additional README.txt files in the NuttX tools repository.
b. Execute 'make menuconfig' in nuttx/ in order to start the
reconfiguration process.
2. By default, this configuration uses the CodeSourcery toolchain
1. By default, this configuration uses the CodeSourcery toolchain
for Windows and builds under Cygwin (or probably MSYS). That
can easily be reconfigured, of course.
@ -1938,7 +1914,7 @@ Where <subdir> is one of the following:
CONFIG_WINDOWS_CYGWIN=y : Using Cygwin
CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y : CodeSourcery for Windows
3. This configuration does have USART2 output enabled and set up as
2. This configuration does have USART2 output enabled and set up as
the system logging device:
CONFIG_SYSLOG_CHAR=y : Use a character device for system logging
@ -1954,7 +1930,7 @@ Where <subdir> is one of the following:
USB device controller driver. Instead, use the USB monitor with
USB debug off and USB trace on (see below).
4. Enabling USB monitor SYSLOG output. If tracing is enabled, the USB
3. Enabling USB monitor SYSLOG output. If tracing is enabled, the USB
device will save encoded trace output in in-memory buffer; if the
USB monitor is enabled, that trace buffer will be periodically
emptied and dumped to the system logging device (USART2 in this
@ -1975,7 +1951,7 @@ Where <subdir> is one of the following:
CONFIG_USBMONITOR_TRACECONTROLLER=y
CONFIG_USBMONITOR_TRACEINTERRUPTS=y
5. By default, this project assumes that you are *NOT* using the DFU
4. By default, this project assumes that you are *NOT* using the DFU
bootloader.
Using the Prolifics PL2303 Emulation

View file

@ -0,0 +1,86 @@
# CONFIG_ARCH_FPU is not set
# CONFIG_MMCSD_MMCSUPPORT is not set
# CONFIG_MMCSD_SPI is not set
# CONFIG_NET_IPv4 is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_CMDPARMS is not set
# CONFIG_NSH_NETINIT is not set
CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y
CONFIG_ARCH_BOARD="stm32f4discovery"
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CHIP_STM32=y
CONFIG_ARCH_CHIP_STM32F407VG=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARCH="arm"
CONFIG_ARMV7M_TOOLCHAIN_CODESOURCERYW=y
CONFIG_BLUETOOTH_MAX_CONN=2
CONFIG_BLUETOOTH_MAX_PAIRED=2
CONFIG_BLUETOOTH_UART=y
CONFIG_BOARD_LOOPSPERMSEC=16717
CONFIG_BOARDCTL_RESET=y
CONFIG_BTSAK=y
CONFIG_BUILTIN=y
CONFIG_DRIVERS_BLUETOOTH=y
CONFIG_DRIVERS_WIRELESS=y
CONFIG_EXAMPLES_NSH_CXXINITIALIZE=y
CONFIG_EXAMPLES_NSH=y
CONFIG_EXPERIMENTAL=y
CONFIG_FAT_LCNAMES=y
CONFIG_FAT_LFN=y
CONFIG_FS_FAT=y
CONFIG_FS_PROCFS=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_INTELHEX_BINARY=y
CONFIG_IOB_NBUFFERS=36
CONFIG_IOB_NCHAINS=8
CONFIG_IOB_THROTTLE=8
CONFIG_MAX_TASKS=16
CONFIG_MAX_WDOGPARMS=2
CONFIG_MMCSD_MULTIBLOCK_DISABLE=y
CONFIG_MMCSD_SDIO=y
CONFIG_MMCSD=y
CONFIG_NET_BLUETOOTH=y
CONFIG_NET_HOSTNAME="STM32F4-Discovery"
CONFIG_NET_SOCKOPTS=y
CONFIG_NET_SOLINGER=y
CONFIG_NET=y
CONFIG_NETDEV_LATEINIT=y
CONFIG_NETDEV_PHY_IOCTL=y
CONFIG_NETDEVICES=y
CONFIG_NFILE_DESCRIPTORS=8
CONFIG_NFILE_STREAMS=8
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_MQ_MSGS=64
CONFIG_PREALLOC_TIMERS=4
CONFIG_PREALLOC_WDOGS=16
CONFIG_RAM_SIZE=114688
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_HPWORK=y
CONFIG_SCHED_HPWORKPRIORITY=192
CONFIG_SCHED_WAITPID=y
CONFIG_SDCLONE_DISABLE=y
CONFIG_START_DAY=13
CONFIG_START_MONTH=9
CONFIG_START_YEAR=2014
CONFIG_STM32_DMA2=y
CONFIG_STM32_DMACAPABLE=y
CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_PWR=y
CONFIG_STM32_SDIO=y
CONFIG_STM32_SPI1=y
CONFIG_STM32_USART3_HCIUART=y
CONFIG_STM32_USART3=y
CONFIG_STM32_USART6=y
CONFIG_STM32F4DISBB=y
CONFIG_USART6_SERIAL_CONSOLE=y
CONFIG_USER_ENTRYPOINT="nsh_main"
CONFIG_WIRELESS_BLUETOOTH=y
CONFIG_WIRELESS=y

View file

@ -91,9 +91,7 @@ int hciuart_dev_initialize(void)
return -ENODEV;
}
/* Then iniatialize the HCI UART upper half driver and register it as a
* network device.
*/
/* Then initialize the HCI UART upper half driver with the bluetooth stack */
ret = btuart_register(lower);
if (ret < 0)

View file

@ -382,6 +382,8 @@ int btuart_register(FAR const struct btuart_lowerhalf_s *lower)
FAR struct btuart_upperhalf_s *upper;
int ret;
wlinfo("lower %p\n", lower);
DEBUGASSERT(lower != NULL);
/* Allocate a new instance of the upper half driver state structure */
@ -406,13 +408,30 @@ int btuart_register(FAR const struct btuart_lowerhalf_s *lower)
lower->rxattach(lower, btuart_rxcallback, upper);
/* And register the driver with the Bluetooth stack */
/* And register the driver with the Bluetooth stack.
*
* REVISIT: Wouldn't it be cleaner to have a single call to
* bt_netdev_register() that handled all of the following?
*/
ret = bt_driver_register(&upper->dev);
if (ret < 0)
{
wlerr("ERROR: bt_driver_register failed: %d\n", ret);
kmm_free(upper);
}
else
{
/* And bring up the network driver to serve this device */
ret = bt_netdev_register(&upper->dev);
if (ret < 0)
{
wlerr("ERROR: bt_driver_register failed: %d\n", ret);
bt_driver_unregister(&upper->dev);
kmm_free(upper);
}
}
return ret;
}

View file

@ -60,11 +60,11 @@ struct bt_driver_s
/* Open the HCI transport */
CODE int (*open)(FAR const struct bt_driver_s *dev);
CODE int (*open)(FAR const struct bt_driver_s *btdev);
/* Send data to HCI */
CODE int (*send)(FAR const struct bt_driver_s *dev,
CODE int (*send)(FAR const struct bt_driver_s *btdev,
FAR struct bt_buf_s *buf);
};
@ -72,27 +72,6 @@ struct bt_driver_s
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: bt_netdev_register
*
* Description:
* Register a network driver to access the Bluetooth layer using a 6LoWPAN
* IPv6 or AF_BLUETOOTH socket.
*
* This function should be called only once from board bring-up logic
* *AFTER* any Bluetooth devices have been registered.
*
* Input Parameters:
* None
*
* 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_register(void);
/****************************************************************************
* Name: bt_driver_register
*
@ -101,8 +80,15 @@ int bt_netdev_register(void);
* This is called from the low-level driver and is part of the driver
* interface prototyped in include/nuttx/wireless/bt_driver.h
*
* This function associates the Bluetooth driver with the Bluetooth stack.
* It must be called *BEFORE* bt_netdev_register().
*
* REVISIT: This probably should be re-partitioned. It would may more
* sense for the Bluetooth driver to just call bt_netdev_register() and
* have that function call bt_driver_register().
*
* Input Parameters:
* dev - An instance of the low-level drivers interface structure.
* btdev - An instance of the low-level drivers interface structure.
*
* Returned Value:
* Zero is returned on success; a negated errno value is returned on any
@ -110,7 +96,7 @@ int bt_netdev_register(void);
*
****************************************************************************/
int bt_driver_register(FAR const struct bt_driver_s *dev);
int bt_driver_register(FAR const struct bt_driver_s *btdev);
/****************************************************************************
* Name: bt_driver_unregister
@ -122,14 +108,40 @@ int bt_driver_register(FAR const struct bt_driver_s *dev);
* include/nuttx/wireless/bt_driver.h
*
* Input Parameters:
* dev - An instance of the low-level drivers interface structure.
* btdev - An instance of the low-level drivers interface structure.
*
* Returned Value:
* None
*
****************************************************************************/
void bt_driver_unregister(FAR const struct bt_driver_s *dev);
void bt_driver_unregister(FAR const struct bt_driver_s *btdev);
/****************************************************************************
* Name: bt_netdev_register
*
* Description:
* Register a network driver to access the Bluetooth layer using a 6LoWPAN
* IPv6 or AF_BLUETOOTH socket.
*
* This function should be called by the Bluetooth driver *AFTER* it has
* called bt_driver_register(). This function assocated the Bluetooth
* driver with the highe level network stack.
*
* REVISIT: This probably should be re-partitioned. It would may more
* sense for the Bluetooth driver to just call bt_driver_register() and
* let this function performed the Bluetooth stack configuration.
*
* Input Parameters:
* btdev - An instance of the low-level drivers 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_register(FAR const struct bt_driver_s *btdev);
/****************************************************************************
* Name: bt_hci_receive

View file

@ -139,7 +139,7 @@ static void hci_acl(FAR struct bt_buf_s *buf)
if (buf->len != len)
{
wlerr("ERROR: ACL data length mismatch (%u != %u)\n", buf->len, len);
wlerr("ERROR: ACL data length mismatch (%u != %u)\n", buf->len, len);
bt_buf_release(buf);
return;
}
@ -147,7 +147,7 @@ static void hci_acl(FAR struct bt_buf_s *buf)
conn = bt_conn_lookup_handle(buf->u.acl.handle);
if (!conn)
{
wlerr("ERROR: Unable to find conn for handle %u\n", buf->u.acl.handle);
wlerr("ERROR: Unable to find conn for handle %u\n", buf->u.acl.handle);
bt_buf_release(buf);
return;
}
@ -175,7 +175,7 @@ static void hci_encrypt_change(FAR struct bt_buf_s *buf)
conn = bt_conn_lookup_handle(handle);
if (!conn)
{
wlerr("ERROR: Unable to look up conn with handle %u\n", handle);
wlerr("ERROR: Unable to look up conn with handle %u\n", handle);
return;
}
@ -213,7 +213,7 @@ static void hci_cmd_done(uint16_t opcode, uint8_t status,
if (g_btdev.sent_cmd->u.hci.opcode != opcode)
{
wlerr("ERROR: Unexpected completion of opcode 0x%04x\n", opcode);
wlerr("ERROR: Unexpected completion of opcode 0x%04x\n", opcode);
return;
}
@ -350,7 +350,7 @@ static void hci_encrypt_key_refresh_complete(FAR struct bt_buf_s *buf)
conn = bt_conn_lookup_handle(handle);
if (!conn)
{
wlerr("ERROR: Unable to look up conn with handle %u\n", handle);
wlerr("ERROR: Unable to look up conn with handle %u\n", handle);
return;
}
@ -388,11 +388,12 @@ static int bt_hci_start_scanning(uint8_t scan_type, uint8_t scan_filter)
FAR struct bt_buf_s *rsp;
FAR struct bt_hci_cp_le_set_scan_params_s *set_param;
FAR struct bt_hci_cp_le_set_scan_enable_s *scan_enable;
int err;
int ret;
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_SCAN_PARAMS, sizeof(*set_param));
if (!buf)
if (buf == NULL)
{
wlerr("ERROR: Failed to create buffer\n");
return -ENOBUFS;
}
@ -411,8 +412,9 @@ static int bt_hci_start_scanning(uint8_t scan_type, uint8_t scan_filter)
bt_hci_cmd_send(BT_HCI_OP_LE_SET_SCAN_PARAMS, buf);
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_SCAN_ENABLE, sizeof(*scan_enable));
if (!buf)
if (buf == NULL)
{
wlerr("ERROR: Failed to create buffer\n");
return -ENOBUFS;
}
@ -421,39 +423,42 @@ static int bt_hci_start_scanning(uint8_t scan_type, uint8_t scan_filter)
scan_enable->filter_dup = scan_filter;
scan_enable->enable = BT_LE_SCAN_ENABLE;
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_SCAN_ENABLE, buf, &rsp);
if (err)
ret = bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_SCAN_ENABLE, buf, &rsp);
if (ret < 0)
{
return err;
wlerr("ERROR: bt_hci_cmd_send_sync failed: %d\n", ret);
return ret;
}
/* Update scan state in case of success (0) status */
err = rsp->data[0];
if (!err)
ret = rsp->data[0];
if (!ret)
{
g_btdev.scan_enable = BT_LE_SCAN_ENABLE;
}
bt_buf_release(rsp);
return err;
return ret;
}
static int bt_hci_stop_scanning(void)
{
FAR struct bt_buf_s *buf, *rsp;
FAR struct bt_hci_cp_le_set_scan_enable_s *scan_enable;
int err;
int ret;
if (g_btdev.scan_enable == BT_LE_SCAN_DISABLE)
{
wlwarn("WARNING: Scan already disabled\n");
return -EALREADY;
}
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_SCAN_ENABLE,
sizeof(*scan_enable));
if (!buf)
if (buf == NULL)
{
wlerr("ERROR: Failed to create buffer\n");
return -ENOBUFS;
}
@ -462,22 +467,23 @@ static int bt_hci_stop_scanning(void)
scan_enable->filter_dup = 0x00;
scan_enable->enable = BT_LE_SCAN_DISABLE;
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_SCAN_ENABLE, buf, &rsp);
if (err)
ret = bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_SCAN_ENABLE, buf, &rsp);
if (ret < 0)
{
return err;
wlerr("ERROR: bt_hci_cmd_send_sync failed: %d\n", ret);
return ret;
}
/* Update scan state in case of success (0) status */
err = rsp->data[0];
if (!err)
ret = rsp->data[0];
if (!ret)
{
g_btdev.scan_enable = BT_LE_SCAN_DISABLE;
}
bt_buf_release(rsp);
return err;
return ret;
}
static int hci_le_create_conn(FAR const bt_addr_le_t *addr)
@ -486,8 +492,9 @@ static int hci_le_create_conn(FAR const bt_addr_le_t *addr)
FAR struct bt_hci_cp_le_create_conn_s *cp;
buf = bt_hci_cmd_create(BT_HCI_OP_LE_CREATE_CONN, sizeof(*cp));
if (!buf)
if (buf == NULL)
{
wlerr("ERROR: Failed to create buffer\n");
return -ENOBUFS;
}
@ -519,7 +526,7 @@ static void hci_disconn_complete(FAR struct bt_buf_s *buf)
conn = bt_conn_lookup_handle(handle);
if (!conn)
{
wlerr("ERROR: Unable to look up conn with handle %u\n", handle);
wlerr("ERROR: Unable to look up conn with handle %u\n", handle);
return;
}
@ -596,7 +603,7 @@ static void le_conn_complete(FAR struct bt_buf_s *buf)
if (!conn)
{
wlerr("ERROR: Unable to add new conn for handle %u\n", handle);
wlerr("ERROR: Unable to add new conn for handle %u\n", handle);
return;
}
@ -722,7 +729,7 @@ static void le_ltk_request(FAR struct bt_buf_s *buf)
conn = bt_conn_lookup_handle(handle);
if (!conn)
{
wlerr("ERROR: Unable to lookup conn for handle %u\n", handle);
wlerr("ERROR: Unable to lookup conn for handle %u\n", handle);
return;
}
@ -740,7 +747,7 @@ static void le_ltk_request(FAR struct bt_buf_s *buf)
buf = bt_hci_cmd_create(BT_HCI_OP_LE_LTK_REQ_REPLY, sizeof(*cp));
if (!buf)
{
wlerr("ERROR: Out of command buffers\n");
wlerr("ERROR: Out of command buffers\n");
goto done;
}
@ -757,7 +764,7 @@ static void le_ltk_request(FAR struct bt_buf_s *buf)
buf = bt_hci_cmd_create(BT_HCI_OP_LE_LTK_REQ_NEG_REPLY, sizeof(*cp));
if (!buf)
{
wlerr("ERROR: Out of command buffers\n");
wlerr("ERROR: Out of command buffers\n");
goto done;
}
@ -836,7 +843,7 @@ static void hci_event(FAR struct bt_buf_s *buf)
break;
default:
wlwarn("Unhandled event 0x%02x\n", hdr->evt);
wlwarn("WARNING: Unhandled event 0x%02x\n", hdr->evt);
break;
}
@ -882,7 +889,7 @@ static int hci_tx_kthread(int argc, FAR char *argv[])
if (g_btdev.sent_cmd)
{
wlerr("ERROR: Uncleared pending sent_cmd\n");
wlerr("ERROR: Uncleared pending sent_cmd\n");
bt_buf_release(g_btdev.sent_cmd);
g_btdev.sent_cmd = NULL;
}
@ -905,7 +912,7 @@ static int hci_rx_kthread(int argc, FAR char *argv[])
ret = bt_queue_receive(g_btdev.rx_queue, &buf);
if (ret < 0)
{
wlerr("ERROR: bt_queue_receive() failed: %d\n", ret);
wlerr("ERROR: bt_queue_receive() failed: %d\n", ret);
continue;
}
@ -922,7 +929,7 @@ static int hci_rx_kthread(int argc, FAR char *argv[])
break;
default:
wlerr("ERROR: Unknown buf type %u\n", buf->type);
wlerr("ERROR: Unknown buf type %u\n", buf->type);
bt_buf_release(buf);
break;
}
@ -1003,7 +1010,7 @@ static int hci_initialize(void)
FAR struct bt_buf_s *buf;
FAR struct bt_buf_s *rsp;
FAR uint8_t *enable;
int err;
int ret;
/* Send HCI_RESET */
@ -1011,10 +1018,11 @@ static int hci_initialize(void)
/* Read Local Supported Features */
err = bt_hci_cmd_send_sync(BT_HCI_OP_READ_LOCAL_FEATURES, NULL, &rsp);
if (err)
ret = bt_hci_cmd_send_sync(BT_HCI_OP_READ_LOCAL_FEATURES, NULL, &rsp);
if (ret < 0)
{
return err;
wlerr("ERROR: bt_hci_cmd_send_sync failed: %d\n", ret);
return ret;
}
read_local_features_complete(rsp);
@ -1022,10 +1030,11 @@ static int hci_initialize(void)
/* Read Local Version Information */
err = bt_hci_cmd_send_sync(BT_HCI_OP_READ_LOCAL_VERSION_INFO, NULL, &rsp);
if (err)
ret = bt_hci_cmd_send_sync(BT_HCI_OP_READ_LOCAL_VERSION_INFO, NULL, &rsp);
if (ret < 0)
{
return err;
wlerr("ERROR: bt_hci_cmd_send_sync failed: %d\n", ret);
return ret;
}
read_local_ver_complete(rsp);
@ -1033,10 +1042,11 @@ static int hci_initialize(void)
/* Read Bluetooth Address */
err = bt_hci_cmd_send_sync(BT_HCI_OP_READ_BD_ADDR, NULL, &rsp);
if (err)
ret = bt_hci_cmd_send_sync(BT_HCI_OP_READ_BD_ADDR, NULL, &rsp);
if (ret < 0)
{
return err;
wlerr("ERROR: bt_hci_cmd_send_sync failed: %d\n", ret);
return ret;
}
read_bdaddr_complete(rsp);
@ -1046,16 +1056,17 @@ static int hci_initialize(void)
if (!lmp_le_capable(g_btdev))
{
wlerr("ERROR: Non-LE capable controller detected!\n");
wlerr("ERROR: Non-LE capable controller detected!\n");
return -ENODEV;
}
/* Read Low Energy Supported Features */
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_READ_LOCAL_FEATURES, NULL, &rsp);
if (err)
ret = bt_hci_cmd_send_sync(BT_HCI_OP_LE_READ_LOCAL_FEATURES, NULL, &rsp);
if (ret < 0)
{
return err;
wlerr("ERROR: bt_hci_cmd_send_sync failed: %d\n", ret);
return ret;
}
read_le_features_complete(rsp);
@ -1063,18 +1074,20 @@ static int hci_initialize(void)
/* Read LE Buffer Size */
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_READ_BUFFER_SIZE, NULL, &rsp);
if (err)
ret = bt_hci_cmd_send_sync(BT_HCI_OP_LE_READ_BUFFER_SIZE, NULL, &rsp);
if (ret < 0)
{
return err;
wlerr("ERROR: bt_hci_cmd_send_sync failed: %d\n", ret);
return ret;
}
le_read_buffer_size_complete(rsp);
bt_buf_release(rsp);
buf = bt_hci_cmd_create(BT_HCI_OP_SET_EVENT_MASK, sizeof(*ev));
if (!buf)
if (buf == NULL)
{
wlerr("ERROR: Failed to create buffer\n");
return -ENOBUFS;
}
@ -1098,8 +1111,9 @@ static int hci_initialize(void)
bt_hci_cmd_send_sync(BT_HCI_OP_SET_EVENT_MASK, buf, NULL);
buf = bt_hci_cmd_create(BT_HCI_OP_HOST_BUFFER_SIZE, sizeof(*hbs));
if (!buf)
if (buf == NULL)
{
wlerr("ERROR: Failed to create buffer\n");
return -ENOBUFS;
}
@ -1110,39 +1124,43 @@ static int hci_initialize(void)
g_btdev.dev->head_reserve);
hbs->acl_pkts = BT_HOST2LE16(CONFIG_BLUETOOTH_RXTHREAD_NMSGS);
err = bt_hci_cmd_send(BT_HCI_OP_HOST_BUFFER_SIZE, buf);
if (err)
ret = bt_hci_cmd_send(BT_HCI_OP_HOST_BUFFER_SIZE, buf);
if (ret < 0)
{
return err;
wlerr("ERROR: bt_hci_cmd_send failed: %d\n", ret);
return ret;
}
buf = bt_hci_cmd_create(BT_HCI_OP_SET_CTL_TO_HOST_FLOW, 1);
if (!buf)
if (buf == NULL)
{
wlerr("ERROR: Failed to create buffer\n");
return -ENOBUFS;
}
enable = bt_buf_extend(buf, sizeof(*enable));
*enable = 0x01;
err = bt_hci_cmd_send_sync(BT_HCI_OP_SET_CTL_TO_HOST_FLOW, buf, NULL);
if (err)
ret = bt_hci_cmd_send_sync(BT_HCI_OP_SET_CTL_TO_HOST_FLOW, buf, NULL);
if (ret < 0)
{
return err;
wlerr("ERROR: bt_hci_cmd_send_sync failed: %d\n", ret);
return ret;
}
if (lmp_bredr_capable(g_btdev))
{
struct bt_hci_cp_write_le_host_supp_s *cp;
FAR struct bt_hci_cp_write_le_host_supp_s *cp;
/* Use BR/EDR buffer size if LE reports zero buffers */
if (!g_btdev.le_mtu)
{
err = bt_hci_cmd_send_sync(BT_HCI_OP_READ_BUFFER_SIZE, NULL, &rsp);
if (err)
ret = bt_hci_cmd_send_sync(BT_HCI_OP_READ_BUFFER_SIZE, NULL, &rsp);
if (ret < 0)
{
return err;
wlerr("ERROR: bt_hci_cmd_send_sync failed: %d\n", ret);
return ret;
}
read_buffer_size_complete(rsp);
@ -1150,8 +1168,9 @@ static int hci_initialize(void)
}
buf = bt_hci_cmd_create(BT_HCI_OP_LE_WRITE_LE_HOST_SUPP, sizeof(*cp));
if (!buf)
if (buf == NULL)
{
wlerr("ERROR: Failed to create buffer\n");
return -ENOBUFS;
}
@ -1244,7 +1263,7 @@ static void rx_queue_init(void)
int bt_initialize(void)
{
FAR const struct bt_driver_s *dev = g_btdev.dev;
int err;
int ret;
DEBUGASSERT(dev != NULL);
bt_buf_initialize();
@ -1252,17 +1271,18 @@ int bt_initialize(void)
cmd_queue_init();
rx_queue_init();
err = dev->open(dev);
if (err)
ret = dev->open(dev);
if (ret < 0)
{
wlerr("ERROR: HCI driver open failed (%d)\n", err);
return err;
wlerr("ERROR: HCI driver open failed (%d)\n", ret);
return ret;
}
err = hci_initialize();
if (err)
ret = hci_initialize();
if (ret < 0)
{
return err;
wlerr("ERROR: hci_initialize failed: %d\n", ret);
return ret;
}
return bt_l2cap_init();
@ -1276,6 +1296,13 @@ int bt_initialize(void)
* This is called from the low-level driver and is part of the driver
* interface prototyped in include/nuttx/wireless/bt_driver.h
*
* This function associates the Bluetooth driver with the Bluetooth stack.
* It must be called *BEFORE* bt_netdev_register().
*
* REVISIT: This probably should be re-partitioned. It would may more
* sense for the Bluetooth driver to just call bt_netdev_register() and
* have that function call bt_driver_register().
*
* Input Parameters:
* dev - An instance of the low-level drivers interface structure.
*
@ -1291,6 +1318,7 @@ int bt_driver_register(FAR const struct bt_driver_s *dev)
if (g_btdev.dev != NULL)
{
wlwarn("WARNING: Already registered\n");
return -EALREADY;
}
@ -1416,8 +1444,9 @@ int bt_hci_cmd_send(uint16_t opcode, FAR struct bt_buf_s *buf)
if (buf == NULL)
{
buf = bt_hci_cmd_create(opcode, 0);
if (!buf)
if (buf == NULL)
{
wlerr("ERROR: Failed to create buffer\n");
return -ENOBUFS;
}
}
@ -1458,8 +1487,9 @@ int bt_hci_cmd_send_sync(uint16_t opcode, FAR struct bt_buf_s *buf,
if (buf == NULL)
{
buf = bt_hci_cmd_create(opcode, 0);
if (!buf)
if (buf == NULL)
{
wlerr("ERROR: Failed to create buffer\n");
return -ENOBUFS;
}
}
@ -1491,6 +1521,7 @@ int bt_hci_cmd_send_sync(uint16_t opcode, FAR struct bt_buf_s *buf,
{
if (buf->u.hci.sync == NULL)
{
wlerr("ERROR: Failed get return parameters\n");
ret = -EIO;
}
else
@ -1544,8 +1575,9 @@ int bt_start_advertising(uint8_t type, FAR const struct bt_eir_s *ad,
}
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_DATA, sizeof(*set_data));
if (!buf)
if (buf == NULL)
{
wlerr("ERROR: Failed to create buffer\n");
return -ENOBUFS;
}
@ -1576,8 +1608,9 @@ send_scan_rsp:
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_SCAN_RSP_DATA,
sizeof(*scan_rsp));
if (!buf)
if (buf == NULL)
{
wlerr("ERROR: Failed to create buffer\n");
return -ENOBUFS;
}
@ -1603,8 +1636,9 @@ send_scan_rsp:
send_set_param:
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_PARAMETERS,
sizeof(*set_param));
if (!buf)
if (buf == NULL)
{
wlerr("ERROR: Failed to create buffer\n");
return -ENOBUFS;
}
@ -1619,8 +1653,9 @@ send_set_param:
bt_hci_cmd_send(BT_HCI_OP_LE_SET_ADV_PARAMETERS, buf);
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_ENABLE, 1);
if (!buf)
if (buf == NULL)
{
wlerr("ERROR: Failed to create buffer\n");
return -ENOBUFS;
}
@ -1647,12 +1682,14 @@ int bt_stop_advertising(void)
if (!g_btdev.adv_enable)
{
wlwarn("WARNING: Already advertising\n");
return -EALREADY;
}
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_ENABLE, 1);
if (!buf)
if (buf == NULL)
{
wlerr("ERROR: Failed to create buffer\n");
return -ENOBUFS;
}
@ -1685,6 +1722,7 @@ int bt_start_scanning(uint8_t scan_filter, bt_le_scan_cb_t cb)
if (g_scan_dev_found_cb)
{
wlwarn("WARNING: Already scanning\n");
return -EALREADY;
}
@ -1710,8 +1748,9 @@ int bt_stop_scanning(void)
{
/* Return if active scanning is already disabled */
if (!g_scan_dev_found_cb)
if (g_scan_dev_found_cb == NULL)
{
wlwarn("WARNING: Not scanning\n");
return -EALREADY;
}

View file

@ -133,8 +133,8 @@ struct btnet_driver_s
/* Utility functions ********************************************************/
static int btnet_advertise(FAR struct net_driver_s *dev);
static inline void btnet_netmask(FAR struct net_driver_s *dev);
static int btnet_advertise(FAR struct net_driver_s *netdev);
static inline void btnet_netmask(FAR struct net_driver_s *netdev);
/* Bluetooth callback functions ***************************************/
@ -159,22 +159,22 @@ static void btnet_hci_disconnected(FAR struct bt_conn_s *conn,
/* Network interface support ************************************************/
/* Common TX logic */
static int btnet_txpoll_callback(FAR struct net_driver_s *dev);
static int btnet_txpoll_callback(FAR struct net_driver_s *netdev);
static void btnet_txpoll_work(FAR void *arg);
static void btnet_txpoll_expiry(int argc, wdparm_t arg, ...);
/* NuttX callback functions */
static int btnet_ifup(FAR struct net_driver_s *dev);
static int btnet_ifdown(FAR struct net_driver_s *dev);
static int btnet_ifup(FAR struct net_driver_s *netdev);
static int btnet_ifdown(FAR struct net_driver_s *netdev);
static void btnet_txavail_work(FAR void *arg);
static int btnet_txavail(FAR struct net_driver_s *dev);
static int btnet_txavail(FAR struct net_driver_s *netdev);
#ifdef CONFIG_NET_IGMP
static int btnet_addmac(FAR struct net_driver_s *dev,
static int btnet_addmac(FAR struct net_driver_s *netdev,
FAR const uint8_t *mac);
static int btnet_rmmac(FAR struct net_driver_s *dev,
static int btnet_rmmac(FAR struct net_driver_s *netdev,
FAR const uint8_t *mac);
#endif
static int btnet_get_mhrlen(FAR struct radio_driver_s *netdev,
@ -211,11 +211,11 @@ static struct sixlowpan_reassbuf_s g_iobuffer;
*
****************************************************************************/
static int btnet_advertise(FAR struct net_driver_s *dev)
static int btnet_advertise(FAR struct net_driver_s *netdev)
{
FAR uint8_t *addr;
DEBUGASSERT(dev != NULL && dev->d_private != NULL);
DEBUGASSERT(netdev != NULL && netdev->d_private != NULL);
/* Get the 6-byte local address from the device.
*
@ -227,20 +227,20 @@ static int btnet_advertise(FAR struct net_driver_s *dev)
/* Set the MAC address using 6-byte local address from the device. */
BLUETOOTH_ADDRCOPY(dev->d_mac.radio.nv_addr, addr);
dev->d_mac.radio.nv_addrlen = BLUETOOTH_ADDRSIZE;
BLUETOOTH_ADDRCOPY(netdev->d_mac.radio.nv_addr, addr);
netdev->d_mac.radio.nv_addrlen = BLUETOOTH_ADDRSIZE;
#ifdef CONFIG_NET_IPv6
/* Set the IP address based on the 6-byte address */
dev->d_ipv6addr[0] = HTONS(0xfe80);
dev->d_ipv6addr[1] = 0;
dev->d_ipv6addr[2] = 0;
dev->d_ipv6addr[3] = 0;
dev->d_ipv6addr[4] = HTONS(0x0200);
dev->d_ipv6addr[5] = (uint16_t)addr[0] << 8 | (uint16_t)addr[1];
dev->d_ipv6addr[6] = (uint16_t)addr[2] << 8 | (uint16_t)addr[3];
dev->d_ipv6addr[7] = (uint16_t)addr[4] << 8 | (uint16_t)addr[5];
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];
#endif
return OK;
@ -259,17 +259,17 @@ static int btnet_advertise(FAR struct net_driver_s *dev)
*
****************************************************************************/
static inline void btnet_netmask(FAR struct net_driver_s *dev)
static inline void btnet_netmask(FAR struct net_driver_s *netdev)
{
#ifdef CONFIG_NET_IPv6
dev->d_ipv6netmask[0] = 0xffff;
dev->d_ipv6netmask[1] = 0xffff;
dev->d_ipv6netmask[2] = 0xffff;
dev->d_ipv6netmask[3] = 0xffff;
dev->d_ipv6netmask[4] = 0;
dev->d_ipv6netmask[5] = 0;
dev->d_ipv6netmask[6] = 0;
dev->d_ipv6netmask[7] = 0;
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;
#endif
}
@ -486,7 +486,7 @@ static void btnet_hci_disconnected(FAR struct bt_conn_s *conn,
* 3. During normal TX polling
*
* Input Parameters:
* dev - Reference to the NuttX driver state structure
* netdev - Reference to the NuttX driver state structure
*
* Returned Value:
* OK on success; a negated errno on failure
@ -496,7 +496,7 @@ static void btnet_hci_disconnected(FAR struct bt_conn_s *conn,
*
****************************************************************************/
static int btnet_txpoll_callback(FAR struct net_driver_s *dev)
static int btnet_txpoll_callback(FAR struct net_driver_s *netdev)
{
/* If zero is returned, the polling will continue until all connections have
* been examined.
@ -586,7 +586,7 @@ static void btnet_txpoll_expiry(int argc, wdparm_t arg, ...)
* is provided
*
* Input Parameters:
* dev - Reference to the NuttX driver state structure
* netdev - Reference to the NuttX driver state structure
*
* Returned Value:
* None
@ -595,32 +595,33 @@ static void btnet_txpoll_expiry(int argc, wdparm_t arg, ...)
*
****************************************************************************/
static int btnet_ifup(FAR struct net_driver_s *dev)
static int btnet_ifup(FAR struct net_driver_s *netdev)
{
FAR struct btnet_driver_s *priv =
(FAR struct btnet_driver_s *)dev->d_private;
(FAR struct btnet_driver_s *)netdev->d_private;
int ret;
/* Set the IP address based on the addressing assigned to the node */
ret = btnet_advertise(dev);
ret = btnet_advertise(netdev);
if (ret >= 0)
{
#ifdef CONFIG_NET_IPv6
wlinfo("Bringing up: IP %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
dev->d_ipv6addr[0], dev->d_ipv6addr[1], dev->d_ipv6addr[2],
dev->d_ipv6addr[3], dev->d_ipv6addr[4], dev->d_ipv6addr[5],
dev->d_ipv6addr[6], dev->d_ipv6addr[7]);
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]);
wlinfo(" ADDR %02x:%02x:%02x:%02x:%02x:%02x\n",
dev->d_mac.radio.nv_addr[0], dev->d_mac.radio.nv_addr[1],
dev->d_mac.radio.nv_addr[2], dev->d_mac.radio.nv_addr[3],
dev->d_mac.radio.nv_addr[4], dev->d_mac.radio.nv_addr[5]);
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]);
#else
wlinfo("Bringing up: %02x:%02x:%02x:%02x:%02x:%02x\n",
dev->d_mac.radio.nv_addr[0], dev->d_mac.radio.nv_addr[1],
dev->d_mac.radio.nv_addr[2], dev->d_mac.radio.nv_addr[3],
dev->d_mac.radio.nv_addr[4], dev->d_mac.radio.nv_addr[5]);
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]);
#endif
/* Set and activate a timer process */
@ -644,7 +645,7 @@ static int btnet_ifup(FAR struct net_driver_s *dev)
* NuttX Callback: Stop the interface.
*
* Input Parameters:
* dev - Reference to the NuttX driver state structure
* netdev - Reference to the NuttX driver state structure
*
* Returned Value:
* None
@ -653,9 +654,10 @@ static int btnet_ifup(FAR struct net_driver_s *dev)
*
****************************************************************************/
static int btnet_ifdown(FAR struct net_driver_s *dev)
static int btnet_ifdown(FAR struct net_driver_s *netdev)
{
FAR struct btnet_driver_s *priv = (FAR struct btnet_driver_s *)dev->d_private;
FAR struct btnet_driver_s *priv =
(FAR struct btnet_driver_s *)netdev->d_private;
irqstate_t flags;
/* Disable interruption */
@ -736,7 +738,7 @@ static void btnet_txavail_work(FAR void *arg)
* latency.
*
* Input Parameters:
* dev - Reference to the NuttX driver state structure
* netdev - Reference to the NuttX driver state structure
*
* Returned Value:
* None
@ -746,9 +748,10 @@ static void btnet_txavail_work(FAR void *arg)
*
****************************************************************************/
static int btnet_txavail(FAR struct net_driver_s *dev)
static int btnet_txavail(FAR struct net_driver_s *netdev)
{
FAR struct btnet_driver_s *priv = (FAR struct btnet_driver_s *)dev->d_private;
FAR struct btnet_driver_s *priv =
(FAR struct btnet_driver_s *)netdev->d_private;
wlinfo("Available=%u\n", work_available(&priv->bd_pollwork));
@ -775,7 +778,7 @@ static int btnet_txavail(FAR struct net_driver_s *dev)
* address filtering
*
* Input Parameters:
* dev - Reference to the NuttX driver state structure
* netdev - Reference to the NuttX driver state structure
* mac - The MAC address to be added
*
* Returned Value:
@ -786,7 +789,8 @@ static int btnet_txavail(FAR struct net_driver_s *dev)
****************************************************************************/
#ifdef CONFIG_NET_IGMP
static int btnet_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac)
static int btnet_addmac(FAR struct net_driver_s *netdev,
FAR const uint8_t *mac)
{
/* Add the MAC address to the hardware multicast routing table. Not used
* with Bluetooth.
@ -804,7 +808,7 @@ static int btnet_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac)
* address filtering
*
* Input Parameters:
* dev - Reference to the NuttX driver state structure
* netdev - Reference to the NuttX driver state structure
* mac - The MAC address to be removed
*
* Returned Value:
@ -815,7 +819,8 @@ static int btnet_addmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac)
****************************************************************************/
#ifdef CONFIG_NET_IGMP
static int btnet_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac)
static int btnet_rmmac(FAR struct net_driver_s *netdev,
FAR const uint8_t *mac)
{
/* Remove the MAC address from the hardware multicast routing table Not used
* with Bluetooth.
@ -832,9 +837,9 @@ static int btnet_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac)
* Calculate the MAC header length given the frame meta-data.
*
* Input Parameters:
* netdev - The networkd device that will mediate the MAC interface
* meta - Obfuscated meta-data structure needed to create the radio
* MAC header
* netdev - The networkd device that will mediate the MAC interface
* meta - Obfuscated meta-data structure needed to create the radio
* MAC header
*
* Returned Value:
* A non-negative MAC header length is returned on success; a negated
@ -843,7 +848,7 @@ static int btnet_rmmac(FAR struct net_driver_s *dev, FAR const uint8_t *mac)
****************************************************************************/
static int btnet_get_mhrlen(FAR struct radio_driver_s *netdev,
FAR const void *meta)
FAR const void *meta)
{
/* Always report the maximum frame length. */
@ -988,11 +993,16 @@ static int btnet_properties(FAR struct radio_driver_s *netdev,
* Register a network driver to access the Bluetooth layer using a 6LoWPAN
* IPv6 or AF_BLUETOOTH socket.
*
* This function should be called only once from board bring-up logic
* *AFTER* any Bluetooth devices have been registered.
* This function should be called by the Bluetooth driver *AFTER* it has
* called bt_driver_register(). This function assocated the Bluetooth
* driver with the highe level network stack.
*
* REVISIT: This probably should be re-partitioned. It would may more
* sense for the Bluetooth driver to just call bt_driver_register() and
* let this function performed the Bluetooth stack configuration.
*
* Input Parameters:
* None
* btdev - An instance of the low-level drivers interface structure.
*
* Returned Value:
* Zero (OK) is returned on success. Otherwise a negated errno value is
@ -1000,11 +1010,11 @@ static int btnet_properties(FAR struct radio_driver_s *netdev,
*
****************************************************************************/
int bt_netdev_register(void)
int bt_netdev_register(FAR const struct bt_driver_s *btdev)
{
FAR struct btnet_driver_s *priv;
FAR struct radio_driver_s *radio;
FAR struct net_driver_s *dev;
FAR struct net_driver_s *netdev;
FAR struct bt_conn_cb_s *hcicb;
FAR struct bt_l2cap_chan_s *l2capcb;
int ret;
@ -1023,18 +1033,18 @@ int bt_netdev_register(void)
/* Initialize the driver structure */
radio = &priv->bd_dev;
dev = &radio->r_dev;
dev->d_ifup = btnet_ifup; /* I/F up (new IP address) callback */
dev->d_ifdown = btnet_ifdown; /* I/F down callback */
dev->d_txavail = btnet_txavail; /* New TX data callback */
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 */
#ifdef CONFIG_NET_IGMP
dev->d_addmac = btnet_addmac; /* Add multicast MAC address */
dev->d_rmmac = btnet_rmmac; /* Remove multicast MAC address */
netdev->d_addmac = btnet_addmac; /* Add multicast MAC address */
netdev->d_rmmac = btnet_rmmac; /* Remove multicast MAC address */
#endif
#ifdef CONFIG_NETDEV_IOCTL
dev->d_ioctl = btnet_ioctl; /* Handle network IOCTL commands */
netdev->d_ioctl = btnet_ioctl; /* Handle network IOCTL commands */
#endif
dev->d_private = (FAR void *)priv; /* Used to recover private state from dev */
netdev->d_private = (FAR void *)priv; /* Used to recover private state from netdev */
/* Connection status change callbacks */
@ -1068,7 +1078,7 @@ int bt_netdev_register(void)
/* Set the network mask. */
btnet_netmask(dev);
btnet_netmask(netdev);
/* Initialize the Network frame-related callbacks */
@ -1087,7 +1097,7 @@ int bt_netdev_register(void)
/* Put the interface in the down state. */
btnet_ifdown(dev);
btnet_ifdown(netdev);
/* Register the device with the OS so that socket IOCTLs can be performed */