From aae0d92598b14a6f760e7e7baf191b59387d539c Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 1 Apr 2018 15:21:58 -0600 Subject: [PATCH] wireless/bluetooth and net/bluetooth: Clean up some garbage left in Kconfig file that broke 'make menuconfig'. Clean up some craziness with Bluetooth frame length definitions. --- include/nuttx/net/bluetooth.h | 26 ++++++++++++++++++++++---- include/nuttx/wireless/bt_buf.h | 16 ---------------- net/bluetooth/Kconfig | 11 ----------- net/bluetooth/bluetooth.h | 22 ---------------------- net/bluetooth/bluetooth_sendto.c | 4 ++-- net/netdev/netdev_register.c | 9 +++++---- wireless/bluetooth/Kconfig | 12 ------------ wireless/bluetooth/bt_att.c | 7 ++++--- wireless/bluetooth/bt_buf.c | 3 ++- wireless/bluetooth/bt_hcicore.c | 3 ++- wireless/bluetooth/bt_netdev.c | 31 +++++++------------------------ 11 files changed, 44 insertions(+), 100 deletions(-) diff --git a/include/nuttx/net/bluetooth.h b/include/nuttx/net/bluetooth.h index 293b8f59cf..f3a0a3c479 100644 --- a/include/nuttx/net/bluetooth.h +++ b/include/nuttx/net/bluetooth.h @@ -46,13 +46,31 @@ * Public Function Prototypes ****************************************************************************/ -/* REVISIT: Is there any header on the Bluetooth data as received by the - * network stack? +/**************************************************************************** + * 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. */ -#warning REVISIT +#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_HDRLEN 8 /* Size of L2CAP header */ #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) diff --git a/include/nuttx/wireless/bt_buf.h b/include/nuttx/wireless/bt_buf.h index 6170e7ed77..24f01eddb5 100644 --- a/include/nuttx/wireless/bt_buf.h +++ b/include/nuttx/wireless/bt_buf.h @@ -49,22 +49,6 @@ #include #include -/**************************************************************************** - * 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 ****************************************************************************/ diff --git a/net/bluetooth/Kconfig b/net/bluetooth/Kconfig index 49f1e8d1ed..96b6db8545 100644 --- a/net/bluetooth/Kconfig +++ b/net/bluetooth/Kconfig @@ -22,17 +22,6 @@ config NET_BLUETOOTH if NET_BLUETOOTH -config NET_BLUETOOTH_FRAMELEN - int "Bluetooth Frame Length" - default 127 - range 1 999999 - ---help--- - For standard Bluetooth radios, this should always be 127 bytes. - However, some Bluetooth radios may non-standard frame lengths. - - This setting is currently used only for detection data transfers - that would exceed the radio frame length. - config NET_BLUETOOTH_NCONNS int "Max Bluetooth sockets" default 4 diff --git a/net/bluetooth/bluetooth.h b/net/bluetooth/bluetooth.h index 01910b1350..f08e3f18c9 100644 --- a/net/bluetooth/bluetooth.h +++ b/net/bluetooth/bluetooth.h @@ -65,28 +65,6 @@ #define BLUETOOTH_POOL_PREALLOCATED 0 #define BLUETOOTH_POOL_DYNAMIC 1 -/* Frame size */ - -/* This maximum size of an Bluetooth frame. Certain, non-standard - * devices may exceed this value, however. - */ - -#define BLUETOOTH_MAC_STDFRAME 127 - -/* Space for a two byte FCS must be reserved at the end of the frame */ - -#define BLUETOOTH_MAC_FCSSIZE 2 - -/* This, then, is the usable size of the frame... */ - -#if defined(CONFIG_NET_BLUETOOTH_FRAMELEN) -# define BLUETOOTH_MAX_FRAMELEN CONFIG_NET_BLUETOOTH_FRAMELEN -#else -# define BLUETOOTH_MAX_FRAMELEN BLUETOOTH_MAC_STDFRAME -#endif - -#define BLUETOOTH_FRAMELEN (BLUETOOTH_MAX_FRAMELEN - BLUETOOTH_MAC_FCSSIZE) - /**************************************************************************** * Public Type Definitions ****************************************************************************/ diff --git a/net/bluetooth/bluetooth_sendto.c b/net/bluetooth/bluetooth_sendto.c index 8751aaeb83..92cc0f783d 100644 --- a/net/bluetooth/bluetooth_sendto.c +++ b/net/bluetooth/bluetooth_sendto.c @@ -146,8 +146,8 @@ static uint16_t bluetooth_sendto_eventhandler(FAR struct net_driver_s *dev, * MAC header. */ - DEBUGASSERT(CONFIG_NET_BLUETOOTH_FRAMELEN <= CONFIG_IOB_BUFSIZE); - if (pstate->is_buflen + hdrlen > BLUETOOTH_FRAMELEN) + DEBUGASSERT(BLUETOOTH_MAX_FRAMELEN <= CONFIG_IOB_BUFSIZE); + if (pstate->is_buflen + hdrlen > BLUETOOTH_MAX_FRAMELEN) { nerr("ERROR: User buffer will not fit into the frame: %u > %u\n", (unsigned int)(pstate->is_buflen + hdrlen), diff --git a/net/netdev/netdev_register.c b/net/netdev/netdev_register.c index b9e77b9488..8131b1912e 100644 --- a/net/netdev/netdev_register.c +++ b/net/netdev/netdev_register.c @@ -1,7 +1,8 @@ /**************************************************************************** * net/netdev/netdev_register.c * - * Copyright (C) 2007-2012, 2014-2015, 2017 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2012, 2014-2015, 2017-2018 Gregory Nutt. All rights + * reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -220,13 +221,13 @@ int netdev_register(FAR struct net_driver_s *dev, enum net_lltype_e lltype) #ifdef CONFIG_NET_BLUETOOTH case NET_LL_BLUETOOTH: /* Bluetooth */ - dev->d_llhdrlen = BLUETOOTH_HDRLEN; + dev->d_llhdrlen = BLUETOOTH_FRAME_HDRLEN; #ifdef CONFIG_NET_6LOWPAN # warning Missing logic - dev->d_mtu = ???; + dev->d_mtu = CONFIG_NET_6LOWPAN_MTU; #ifdef CONFIG_NET_TCP # warning Missing logic - dev->d_recvwndo = ???; + dev->d_recvwndo = CONFIG_NET_6LOWPAN_TCP_RECVWNDO; #endif #endif devfmt = NETDEV_BNEP_FORMAT; diff --git a/wireless/bluetooth/Kconfig b/wireless/bluetooth/Kconfig index b2a4b5de22..3c67ffebbd 100644 --- a/wireless/bluetooth/Kconfig +++ b/wireless/bluetooth/Kconfig @@ -96,18 +96,6 @@ config BLUETOOTH_MAXSCANRESULT This contributes to a static memory allocation that will be greater than CONFIG_BLUETOOTH_MAXSCANDATA * CONFIG_BLUETOOTH_MAXSCANRESULT -#if !defined(CONFIG_BLUETOOTH_BUFFER_PREALLOC) || \ - CONFIG_BLUETOOTH_BUFFER_PREALLOC < 0 -# undef CONFIG_BLUETOOTH_BUFFER_PREALLOC -# define CONFIG_BLUETOOTH_BUFFER_PREALLOC 20 -#endif - -#if !defined(CONFIG_) || \ - CONFIG_BLUETOOTH_BUFFER_IRQRESERVE < 0 -# undef CONFIG_BLUETOOTH_BUFFER_IRQRESERVE -# define CONFIG_BLUETOOTH_BUFFER_IRQRESERVE 0 -#endif - config BLUETOOTH_BUFFER_PREALLOC int "Number of pre-allocated buffer structures" default 20 diff --git a/wireless/bluetooth/bt_att.c b/wireless/bluetooth/bt_att.c index 0540f0c7ea..9e86686d6f 100644 --- a/wireless/bluetooth/bt_att.c +++ b/wireless/bluetooth/bt_att.c @@ -50,6 +50,7 @@ #include #include +#include #include #include #include @@ -559,9 +560,9 @@ static uint8_t att_mtu_rsp(FAR struct bt_conn_s *conn, FAR struct bt_buf_s *buf) * L2CAP, ACL and driver headers. */ - maxmtu = BT_BUF_MAX_DATA - (sizeof(struct bt_l2cap_hdr_s) + - sizeof(struct bt_hci_acl_hdr_s) + - g_btdev.dev->head_reserve); + maxmtu = BLUETOOTH_MAX_FRAMELEN - (sizeof(struct bt_l2cap_hdr_s) + + sizeof(struct bt_hci_acl_hdr_s) + + g_btdev.dev->head_reserve); if (mtu > maxmtu) { mtu = maxmtu; diff --git a/wireless/bluetooth/bt_buf.c b/wireless/bluetooth/bt_buf.c index ad8b7b4a96..e4b66ff9a0 100644 --- a/wireless/bluetooth/bt_buf.c +++ b/wireless/bluetooth/bt_buf.c @@ -53,6 +53,7 @@ #include #include #include +#include #include #include #include @@ -641,5 +642,5 @@ size_t bt_buf_headroom(FAR struct bt_buf_s *buf) size_t bt_buf_tailroom(FAR struct bt_buf_s * buf) { - return BT_BUF_MAX_DATA - bt_buf_headroom(buf) - buf->len; + return BLUETOOTH_MAX_FRAMELEN - bt_buf_headroom(buf) - buf->len; } diff --git a/wireless/bluetooth/bt_hcicore.c b/wireless/bluetooth/bt_hcicore.c index 8eef66b202..6962e75410 100644 --- a/wireless/bluetooth/bt_hcicore.c +++ b/wireless/bluetooth/bt_hcicore.c @@ -54,6 +54,7 @@ #include #include +#include #include #include @@ -1102,7 +1103,7 @@ static int hci_init(void) hbs = bt_buf_extend(buf, sizeof(*hbs)); memset(hbs, 0, sizeof(*hbs)); - hbs->acl_mtu = BT_HOST2LE16(BT_BUF_MAX_DATA - + hbs->acl_mtu = BT_HOST2LE16(BLUETOOTH_MAX_FRAMELEN - sizeof(struct bt_hci_acl_hdr_s) - g_btdev.dev->head_reserve); hbs->acl_pkts = BT_HOST2LE16(CONFIG_BLUETOOTH_RXTHREAD_NMSGS); diff --git a/wireless/bluetooth/bt_netdev.c b/wireless/bluetooth/bt_netdev.c index b83326faf3..aa2da5ed66 100644 --- a/wireless/bluetooth/bt_netdev.c +++ b/wireless/bluetooth/bt_netdev.c @@ -85,10 +85,8 @@ /* Frame size */ -#if defined(CONFIG_NET_BLUETOOTH_FRAMELEN) -# define MACNET_FRAMELEN CONFIG_NET_BLUETOOTH_FRAMELEN -#else -# define MACNET_FRAMELEN BLUETOOTH_MAX_PHY_PACKET_SIZE +#if BLUETOOTH_MAX_FRAMELEN > CONFIG_IOB_BUFSIZE +# error CONFIG_IOB_BUFSIZE to small for max Bluetooth frame #endif /* TX poll delay = 1 seconds. CLK_TCK is the number of clock ticks per second */ @@ -861,7 +859,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) { - return sizeof(struct bt_l2cap_hdr_s); + return BLUETOOTH_FRAME_HDRLEN; } /**************************************************************************** @@ -919,7 +917,7 @@ static int btnet_req_data(FAR struct radio_driver_s *netdev, /* Allocate a buffer to contain the IOB */ - buf = bt_buf_alloc(BT_ACL_OUT, iob, sizeof(struct bt_l2cap_hdr_s)); + buf = bt_buf_alloc(BT_ACL_OUT, iob, BLUETOOTH_FRAME_HDRLEN); if (buf == NULL) { wlerr("ERROR: Failed to allocate buffer container\n"); @@ -962,25 +960,10 @@ static int btnet_properties(FAR struct radio_driver_s *netdev, /* General */ - properties->sp_addrlen = BLUETOOTH_ADDRSIZE; /* Length of an address */ - properties->sp_framelen = MACNET_FRAMELEN; /* Fixed frame length */ + properties->sp_addrlen = BLUETOOTH_ADDRSIZE; /* Length of an address */ + properties->sp_framelen = BLUETOOTH_MAX_FRAMELEN; /* Fixed frame length */ - /* Multicast address -- not supported */ - - properties->sp_mcast.nv_addrlen = BLUETOOTH_ADDRSIZE; - memset(properties->sp_mcast.nv_addr, 0xff, RADIO_MAX_ADDRLEN); - - /* Broadcast address -- not supported */ - - properties->sp_bcast.nv_addrlen = BLUETOOTH_ADDRSIZE; - memset(properties->sp_mcast.nv_addr, 0xff, RADIO_MAX_ADDRLEN); - -#ifdef CONFIG_NET_STARPOINT - /* Star hub node address -- not supported. */ - - properties->sp_hubnode.nv_addrlen = BLUETOOTH_ADDRSIZE; - memset(properties->sp_hubnode.nv_addr, RADIO_MAX_ADDRLEN); -#endif + /* Multicast, multicast, and star hub node addresses not supported */ return OK; }