diff --git a/drivers/wireless/bluetooth/bt_uart.c b/drivers/wireless/bluetooth/bt_uart.c index 3f15c1e999..22373a48a5 100644 --- a/drivers/wireless/bluetooth/bt_uart.c +++ b/drivers/wireless/bluetooth/bt_uart.c @@ -326,3 +326,39 @@ int btuart_ioctl(FAR struct bt_driver_s *dev, return -ENOTTY; } } + +/**************************************************************************** + * Name: btuart_register + * + * Description: + * Register the UART-based bluetooth driver. + * + * Input Parameters: + * lower - an instance of the lower half driver interface + * + * Returned Value: + * Zero is returned on success; a negated errno value is returned on any + * failure. + * + ****************************************************************************/ + +int btuart_register(FAR const struct btuart_lowerhalf_s *lower) +{ + FAR struct bt_driver_s *driver; + int ret; + + ret = btuart_create(lower, &driver); + if (ret < 0) + { + return ret; + } + + ret = bt_netdev_register(driver); + if (ret < 0) + { + wlerr("ERROR: bt_netdev_register failed: %d\n", ret); + kmm_free(driver); + } + + return ret; +} diff --git a/drivers/wireless/bluetooth/bt_uart_bcm4343x.c b/drivers/wireless/bluetooth/bt_uart_bcm4343x.c index 3d9f91689c..fca7969a8f 100644 --- a/drivers/wireless/bluetooth/bt_uart_bcm4343x.c +++ b/drivers/wireless/bluetooth/bt_uart_bcm4343x.c @@ -379,10 +379,9 @@ load_bcm4343x_firmware_finished: ****************************************************************************/ /**************************************************************************** - * Name: btuart_register + * Name: btuart_create * - * Create the UART-based Bluetooth device and register it with the - * Bluetooth stack. + * Create the UART-based bluetooth device. * * Input Parameters: * lower - an instance of the lower half driver interface @@ -393,7 +392,8 @@ load_bcm4343x_firmware_finished: * ****************************************************************************/ -int btuart_register(FAR const struct btuart_lowerhalf_s *lower) +int btuart_create(FAR const struct btuart_lowerhalf_s *lower, + FAR struct bt_driver_s **driver) { FAR struct btuart_upperhalf_s *upper; int ret; @@ -436,14 +436,6 @@ int btuart_register(FAR const struct btuart_lowerhalf_s *lower) return -EINVAL; } - /* And register the driver with the network and the Bluetooth stack. */ - - ret = bt_netdev_register(&upper->dev); - if (ret < 0) - { - wlerr("ERROR: bt_netdev_register failed: %d\n", ret); - kmm_free(upper); - } - + *driver = &upper->dev; return ret; } diff --git a/drivers/wireless/bluetooth/bt_uart_cc2564.c b/drivers/wireless/bluetooth/bt_uart_cc2564.c index aa2c1da688..79fa40468a 100644 --- a/drivers/wireless/bluetooth/bt_uart_cc2564.c +++ b/drivers/wireless/bluetooth/bt_uart_cc2564.c @@ -145,11 +145,9 @@ int load_cc2564_firmware(FAR const struct btuart_lowerhalf_s *lower) } /**************************************************************************** - * Name: btuart_register + * Name: btuart_create * - * Description: - * Create the UART-based Bluetooth device and register it with the - * Bluetooth stack. + * Create the UART-based bluetooth device. * * Input Parameters: * lower - an instance of the lower half driver interface @@ -160,7 +158,8 @@ int load_cc2564_firmware(FAR const struct btuart_lowerhalf_s *lower) * ****************************************************************************/ -int btuart_register(FAR const struct btuart_lowerhalf_s *lower) +int btuart_create(FAR const struct btuart_lowerhalf_s *lower, + FAR struct bt_driver_s **driver) { FAR struct btuart_upperhalf_s *upper; int ret; @@ -203,14 +202,6 @@ int btuart_register(FAR const struct btuart_lowerhalf_s *lower) return -EINVAL; } - /* And register the driver with the network and the Bluetooth stack. */ - - ret = bt_netdev_register(&upper->dev); - if (ret < 0) - { - wlerr("ERROR: bt_netdev_register failed: %d\n", ret); - kmm_free(upper); - } - + *driver = &upper->dev; return ret; } diff --git a/drivers/wireless/bluetooth/bt_uart_generic.c b/drivers/wireless/bluetooth/bt_uart_generic.c index 6b462cf2ff..90255ae8c1 100644 --- a/drivers/wireless/bluetooth/bt_uart_generic.c +++ b/drivers/wireless/bluetooth/bt_uart_generic.c @@ -39,11 +39,9 @@ ****************************************************************************/ /**************************************************************************** - * Name: btuart_register + * Name: btuart_create * - * Description: - * Create the UART-based Bluetooth device and register it with the - * Bluetooth stack. + * Create the UART-based bluetooth device. * * Input Parameters: * lower - an instance of the lower half driver interface @@ -54,10 +52,10 @@ * ****************************************************************************/ -int btuart_register(FAR const struct btuart_lowerhalf_s *lower) +int btuart_create(FAR const struct btuart_lowerhalf_s *lower, + FAR struct bt_driver_s **driver) { FAR struct btuart_upperhalf_s *upper; - int ret; wlinfo("lower %p\n", lower); @@ -87,14 +85,6 @@ int btuart_register(FAR const struct btuart_lowerhalf_s *lower) upper->dev.ioctl = btuart_ioctl; upper->lower = lower; - /* And register the driver with the network and the Bluetooth stack. */ - - ret = bt_netdev_register(&upper->dev); - if (ret < 0) - { - wlerr("ERROR: bt_netdev_registe failed: %d\n", ret); - kmm_free(upper); - } - - return ret; + *driver = &upper->dev; + return OK; } diff --git a/include/nuttx/wireless/bluetooth/bt_uart.h b/include/nuttx/wireless/bluetooth/bt_uart.h index c74b6955a6..a6184e5115 100644 --- a/include/nuttx/wireless/bluetooth/bt_uart.h +++ b/include/nuttx/wireless/bluetooth/bt_uart.h @@ -148,12 +148,28 @@ struct btuart_lowerhalf_s * Public Function Prototypes ****************************************************************************/ +/**************************************************************************** + * Name: btuart_create + * + * Create the UART-based Bluetooth device. + * + * Input Parameters: + * lower - an instance of the lower half driver interface + * + * Returned Value: + * Zero is returned on success; a negated errno value is returned on any + * failure. + * + ****************************************************************************/ + +int btuart_create(FAR const struct btuart_lowerhalf_s *lower, + FAR struct bt_driver_s **driver); + /**************************************************************************** * Name: btuart_register * * Description: - * Create the generic UART-based Bluetooth device and register it with the - * Bluetooth stack. + * Register the generic UART-based bluetooth driver. * * Input Parameters: * lower - an instance of the lower half driver interface