Skip to content

Commit ca64efb

Browse files
committed
do_not_merge: Just for verifying CI
Temporary commit for CI testing. The contents of this will be squashed into the respective other commits that they belong to (once CI is green). Signed-off-by: Johan Hedberg <[email protected]>
1 parent 5484227 commit ca64efb

File tree

30 files changed

+166
-161
lines changed

30 files changed

+166
-161
lines changed

doc/releases/migration-guide-4.2.rst

-4
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,6 @@ Bluetooth HCI
241241
have been deprecated, but are still usable, with the exception that they can only be
242242
called once per buffer.
243243

244-
* As part of the HCI buffer encoding change, since packet type values are no longer independent
245-
bits, the callback used by :c:func:`bt_buf_rx_freed_cb_set` has been changed to take a bitmask
246-
that's constructed using bitwise or of ``BIT(type)``` values.
247-
248244
Bluetooth Host
249245
==============
250246

drivers/bluetooth/hci/hci_ifx_cyw208xx.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -270,18 +270,18 @@ static int cyw208xx_send(const struct device *dev, struct net_buf *buf)
270270
LOG_DBG("buf %p type %u len %u", buf, type, buf->len);
271271

272272
switch (type) {
273-
case BT_BUF_ACL_OUT:
273+
case BT_HCI_H4_ACL:
274274
uint8_t *bt_msg = host_stack_get_acl_to_lower_buffer(BT_TRANSPORT_LE, buf->len);
275275

276276
memcpy(bt_msg, buf->data, buf->len);
277277
ret = host_stack_send_acl_to_lower(BT_TRANSPORT_LE, bt_msg, buf->len);
278278
break;
279279

280-
case BT_BUF_CMD:
280+
case BT_HCI_H4_CMD:
281281
ret = host_stack_send_cmd_to_lower(buf->data, buf->len);
282282
break;
283283

284-
case BT_BUF_ISO_OUT:
284+
case BT_HCI_H4_ISO:
285285
ret = host_stack_send_iso_to_lower(buf->data, buf->len);
286286
break;
287287

drivers/bluetooth/hci/hci_stm32wb0.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ static int bt_hci_stm32wb0_send(const struct device *dev, struct net_buf *buf)
377377
ARG_UNUSED(dev);
378378

379379
switch (type) {
380-
case BT_BUF_ACL_OUT: {
380+
case BT_HCI_H4_ACL: {
381381
uint16_t connection_handle;
382382
uint16_t data_len;
383383
uint8_t *pdu;
@@ -393,7 +393,7 @@ static int bt_hci_stm32wb0_send(const struct device *dev, struct net_buf *buf)
393393
break;
394394
}
395395
#if defined(CONFIG_BT_ISO)
396-
case BT_BUF_ISO_OUT: {
396+
case BT_HCI_H4_ISO: {
397397
uint16_t connection_handle;
398398
uint16_t iso_data_load_len;
399399
uint8_t *iso_data_load;
@@ -410,7 +410,7 @@ static int bt_hci_stm32wb0_send(const struct device *dev, struct net_buf *buf)
410410
break;
411411
}
412412
#endif /* CONFIG_BT_ISO */
413-
case BT_BUF_CMD:
413+
case BT_HCI_H4_CMD:
414414
process_command(hci_buffer, buf->len, buffer_out_mem, sizeof(buffer_out_mem));
415415
send_event(buffer_out_mem, 0, 0);
416416
break;

drivers/bluetooth/hci/ipm_stm32wb.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,14 @@ static int bt_ipm_send(const struct device *dev, struct net_buf *buf)
362362
k_sem_take(&ipm_busy, K_FOREVER);
363363

364364
switch (buf->data[0]) {
365-
case BT_BUF_ACL_OUT:
365+
case BT_HCI_H4_ACL:
366366
LOG_DBG("ACL: buf %p type %u len %u", buf, buf->data[0], buf->len);
367367
k_sem_take(&acl_data_ack, K_FOREVER);
368368
memcpy((void *)&((TL_AclDataPacket_t *)HciAclDataBuffer)->AclDataSerial,
369369
buf->data, buf->len);
370370
TL_BLE_SendAclData(NULL, 0);
371371
break;
372-
case BT_BUF_CMD:
372+
case BT_HCI_H4_CMD:
373373
LOG_DBG("CMD: buf %p type %u len %u", buf, buf->data[0], buf->len);
374374
ble_cmd_buff->cmdserial.type = net_buf_pull_u8(buf);
375375
ble_cmd_buff->cmdserial.cmd.plen = buf->len;

include/zephyr/bluetooth/buf.h

+69-10
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,75 @@ extern "C" {
3535
#endif
3636

3737
/** Possible types of buffers passed around the Bluetooth stack in a form of bitmask. */
38-
enum __packed bt_buf_type {
38+
enum bt_buf_type {
39+
/** Invalid value, used for error checking */
40+
BT_BUF_TYPE_INVALID = 0,
3941
/** HCI command */
40-
BT_BUF_CMD = BT_HCI_H4_CMD,
42+
BT_BUF_CMD = BIT(0),
4143
/** HCI event */
42-
BT_BUF_EVT = BT_HCI_H4_EVT,
44+
BT_BUF_EVT = BIT(1),
4345
/** Outgoing ACL data */
44-
BT_BUF_ACL_OUT = BT_HCI_H4_ACL,
46+
BT_BUF_ACL_OUT = BIT(2),
4547
/** Incoming ACL data */
46-
BT_BUF_ACL_IN = BT_HCI_H4_ACL,
48+
BT_BUF_ACL_IN = BIT(3),
4749
/** Outgoing ISO data */
48-
BT_BUF_ISO_OUT = BT_HCI_H4_ISO,
50+
BT_BUF_ISO_OUT = BIT(4),
4951
/** Incoming ISO data */
50-
BT_BUF_ISO_IN = BT_HCI_H4_ISO,
52+
BT_BUF_ISO_IN = BIT(5),
5153
};
5254

55+
/** Direction of HCI packets */
56+
enum bt_buf_dir {
57+
BT_BUF_IN,
58+
BT_BUF_OUT,
59+
};
60+
61+
/** Convert from bt_buf_type to H:4 type.
62+
*
63+
* @param type The bt_buf_type to convert
64+
* @return The H:4 type
65+
*/
66+
static inline uint8_t bt_buf_type_to_h4(enum bt_buf_type type)
67+
{
68+
switch (type) {
69+
case BT_BUF_CMD:
70+
return BT_HCI_H4_CMD;
71+
case BT_BUF_ACL_IN:
72+
case BT_BUF_ACL_OUT:
73+
return BT_HCI_H4_ACL;
74+
case BT_BUF_ISO_IN:
75+
case BT_BUF_ISO_OUT:
76+
return BT_HCI_H4_ISO;
77+
case BT_BUF_EVT:
78+
return BT_HCI_H4_EVT;
79+
default:
80+
__ASSERT_NO_MSG(false);
81+
return 0;
82+
}
83+
}
84+
85+
/** Convert from H:4 type to bt_buf_type.
86+
*
87+
* @param h4_type The H:4 type to convert
88+
* @param dir The direction of the packet
89+
* @return The bt_buf_type
90+
*/
91+
static inline enum bt_buf_type bt_buf_type_from_h4(uint8_t h4_type, enum bt_buf_dir dir)
92+
{
93+
switch (h4_type) {
94+
case BT_HCI_H4_CMD:
95+
return BT_BUF_CMD;
96+
case BT_HCI_H4_ACL:
97+
return dir == BT_BUF_OUT ? BT_BUF_ACL_OUT : BT_BUF_ACL_IN;
98+
case BT_HCI_H4_EVT:
99+
return BT_BUF_EVT;
100+
case BT_HCI_H4_ISO:
101+
return dir == BT_BUF_OUT ? BT_BUF_ISO_OUT : BT_BUF_ISO_IN;
102+
default:
103+
return BT_BUF_TYPE_INVALID;
104+
}
105+
}
106+
53107
/* Headroom reserved in buffers, primarily for HCI transport encoding purposes */
54108
#define BT_BUF_RESERVE 1
55109

@@ -151,7 +205,7 @@ struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout);
151205
* any action that makes the current thread unready. This callback must only be used for very
152206
* short non-blocking operation (e.g. submitting a work item).
153207
*
154-
* @param type_mask A bit mask of buffer types (BIT(type)) that have been freed.
208+
* @param type_mask A bit mask of buffer types that have been freed.
155209
*/
156210
typedef void (*bt_buf_rx_freed_cb_t)(enum bt_buf_type type_mask);
157211

@@ -197,9 +251,10 @@ struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable, k_timeout_t timeou
197251
static inline void __deprecated bt_buf_set_type(struct net_buf *buf, enum bt_buf_type type)
198252
{
199253
__ASSERT_NO_MSG(net_buf_headroom(buf) >= 1);
200-
net_buf_push_u8(buf, type);
254+
net_buf_push_u8(buf, bt_buf_type_to_h4(type));
201255
}
202256

257+
203258
/** Get the buffer type. This pulls the H:4 byte prefix from the payload, which means
204259
* that the call can be done only once per buffer.
205260
*
@@ -209,7 +264,11 @@ static inline void __deprecated bt_buf_set_type(struct net_buf *buf, enum bt_buf
209264
*/
210265
static inline enum bt_buf_type __deprecated bt_buf_get_type(struct net_buf *buf)
211266
{
212-
return net_buf_pull_u8(buf);
267+
/* We have to assume the direction since the H:4 type doesn't tell us
268+
* if the buffer is incoming or outgoing. The common use case of this API is for outgoing
269+
* buffers, so we assume that.
270+
*/
271+
return bt_buf_type_from_h4(net_buf_pull_u8(buf), BT_BUF_OUT);
213272
}
214273

215274
/**

samples/bluetooth/hci_uart/src/main.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ static void rx_isr(void)
150150
* interrupt. On failed allocation state machine
151151
* is reset.
152152
*/
153-
buf = bt_buf_get_tx(type, K_NO_WAIT, NULL, 0);
153+
buf = bt_buf_get_tx(bt_buf_type_from_h4(type, BT_BUF_OUT),
154+
K_NO_WAIT, NULL, 0);
154155
if (!buf) {
155156
LOG_ERR("No available command buffers!");
156157
state = ST_IDLE;

samples/bluetooth/hci_uart_3wire/src/main.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ static void bt_uart_isr(const struct device *unused, void *user_data)
479479
case HCI_COMMAND_PKT:
480480
case HCI_ACLDATA_PKT:
481481
case HCI_ISODATA_PKT:
482-
h5.rx_buf = bt_buf_get_tx(type, K_NO_WAIT, NULL, 0);
482+
h5.rx_buf = bt_buf_get_tx(bt_buf_type_from_h4(type),
483+
K_NO_WAIT, NULL, 0);
483484
if (!h5.rx_buf) {
484485
LOG_WRN("No available data buffers");
485486
h5_reset_rx();

samples/bluetooth/hci_uart_async/src/hci_uart_async.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ static void h2c_h4_transport(void)
219219
LOG_DBG("h2c: h4_type %d", h4_type);
220220

221221
/* Allocate buf. */
222-
buf = bt_buf_get_tx(h4_type, K_FOREVER, NULL, 0);
222+
buf = bt_buf_get_tx(bt_buf_type_from_h4(h4_type, BT_BUF_OUT), K_FOREVER, NULL, 0);
223223
LOG_DBG("h2c: buf %p", buf);
224224

225225
if (!buf) {

samples/boards/st/bluetooth/interactive_gui/src/main.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -213,26 +213,26 @@ static int hdr_len(uint8_t type)
213213

214214
static struct net_buf *alloc_tx_buf(uint8_t type)
215215
{
216-
enum bt_buf_type alloc_type = type;
217-
struct net_buf *buf;
216+
enum bt_buf_type alloc_type;
218217

219218
switch (type) {
220219
case H4_ST_EXT_CMD:
221220
case BT_HCI_H4_CMD:
222221
case H4_ST_VND_CMD:
223-
alloc_type = BT_HCI_H4_CMD;
222+
alloc_type = BT_BUF_CMD;
224223
break;
225224
case BT_HCI_H4_ISO:
225+
alloc_type = BT_BUF_ISO_OUT;
226+
break;
226227
case BT_HCI_H4_ACL:
228+
alloc_type = BT_BUF_ACL_OUT;
227229
break;
228230
default:
229231
LOG_ERR("Invalid type: %u", type);
230232
return NULL;
231233
}
232234

233-
buf = bt_buf_get_tx(alloc_type, K_NO_WAIT, NULL, 0);
234-
235-
return buf;
235+
return bt_buf_get_tx(alloc_type, K_NO_WAIT, NULL, 0);
236236
}
237237

238238
static void rx_isr(void)

subsys/bluetooth/controller/hci/hci.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5237,7 +5237,7 @@ static struct net_buf *vs_err_evt_create(uint8_t subevt, uint8_t len)
52375237
struct bt_hci_evt_le_meta_event *me;
52385238
struct bt_hci_evt_hdr *hdr;
52395239

5240-
net_buf_add_u8(buf, BT_BUF_EVT);
5240+
net_buf_add_u8(buf, BT_HCI_H4_EVT);
52415241

52425242
hdr = net_buf_add(buf, sizeof(*hdr));
52435243
hdr->evt = BT_HCI_EVT_VENDOR;

subsys/bluetooth/controller/hci/hci_driver.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ isoal_status_t sink_sdu_emit_hci(const struct isoal_sink *sink_ctx,
198198
hdr->handle = sys_cpu_to_le16(handle_packed);
199199
hdr->len = sys_cpu_to_le16(len);
200200

201-
net_buf_push_u8(buf, BT_BUF_ISO_IN);
201+
net_buf_push_u8(buf, BT_HCI_H4_ISO);
202202

203203
/* send fragment up the chain */
204204
data->recv(dev, buf);
@@ -271,7 +271,7 @@ static int bt_recv_prio(const struct device *dev, struct net_buf *buf)
271271
{
272272
const struct hci_driver_data *data = dev->data;
273273

274-
if (buf->data[0] == BT_BUF_EVT) {
274+
if (buf->data[0] == BT_HCI_H4_EVT) {
275275
struct bt_hci_evt_hdr *hdr = (void *)(buf->data + 1);
276276
uint8_t evt_flags = bt_hci_evt_get_flags(hdr->evt);
277277

@@ -956,7 +956,7 @@ static int iso_handle(const struct device *dev, struct net_buf *buf)
956956

957957
static int hci_driver_send(const struct device *dev, struct net_buf *buf)
958958
{
959-
enum bt_buf_type type;
959+
uint8_t type;
960960
int err;
961961

962962
LOG_DBG("enter");
@@ -969,15 +969,15 @@ static int hci_driver_send(const struct device *dev, struct net_buf *buf)
969969
type = net_buf_pull_u8(buf);
970970
switch (type) {
971971
#if defined(CONFIG_BT_CONN)
972-
case BT_BUF_ACL_OUT:
972+
case BT_HCI_H4_ACL:
973973
err = acl_handle(dev, buf);
974974
break;
975975
#endif /* CONFIG_BT_CONN */
976-
case BT_BUF_CMD:
976+
case BT_HCI_H4_CMD:
977977
err = cmd_handle(dev, buf);
978978
break;
979979
#if defined(CONFIG_BT_CTLR_ADV_ISO) || defined(CONFIG_BT_CTLR_CONN_ISO)
980-
case BT_BUF_ISO_OUT:
980+
case BT_HCI_H4_ISO:
981981
err = iso_handle(dev, buf);
982982
break;
983983
#endif /* CONFIG_BT_CTLR_ADV_ISO || CONFIG_BT_CTLR_CONN_ISO */

subsys/bluetooth/host/buf.c

+6-9
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929

3030
LOG_MODULE_REGISTER(bt_buf, CONFIG_BT_LOG_LEVEL);
3131

32-
BUILD_ASSERT(sizeof(enum bt_buf_type) == sizeof(uint8_t),
33-
"bt_buf_type must fit in a byte");
34-
3532
/* Events have a length field of 1 byte. This size fits all events.
3633
*
3734
* It's true that we don't put all kinds of events there (yet). However, the
@@ -55,7 +52,7 @@ static void buf_rx_freed_notify(enum bt_buf_type mask)
5552
#if defined(CONFIG_BT_ISO_RX)
5653
static void iso_rx_freed_cb(void)
5754
{
58-
buf_rx_freed_notify(BIT(BT_BUF_ISO_IN));
55+
buf_rx_freed_notify(BT_BUF_ISO_IN);
5956
}
6057
#endif
6158

@@ -77,13 +74,13 @@ NET_BUF_POOL_FIXED_DEFINE(discardable_pool, CONFIG_BT_BUF_EVT_DISCARDABLE_COUNT,
7774
static void acl_in_pool_destroy(struct net_buf *buf)
7875
{
7976
bt_hci_host_num_completed_packets(buf);
80-
buf_rx_freed_notify(BIT(BT_BUF_ACL_IN));
77+
buf_rx_freed_notify(BT_BUF_ACL_IN);
8178
}
8279

8380
static void evt_pool_destroy(struct net_buf *buf)
8481
{
8582
net_buf_destroy(buf);
86-
buf_rx_freed_notify(BIT(BT_BUF_EVT));
83+
buf_rx_freed_notify(BT_BUF_EVT);
8784
}
8885

8986
NET_BUF_POOL_DEFINE(acl_in_pool, (BT_BUF_ACL_RX_COUNT_EXTRA + BT_BUF_HCI_ACL_RX_COUNT),
@@ -101,7 +98,7 @@ static void hci_rx_pool_destroy(struct net_buf *buf)
10198
* Therefore the callback will always notify about both types of buffers, BT_BUF_EVT and
10299
* BT_BUF_ACL_IN.
103100
*/
104-
buf_rx_freed_notify(BIT(BT_BUF_EVT) | BIT(BT_BUF_ACL_IN));
101+
buf_rx_freed_notify(BT_BUF_EVT | BT_BUF_ACL_IN);
105102
}
106103

107104
NET_BUF_POOL_FIXED_DEFINE(hci_rx_pool, BT_BUF_RX_COUNT, BT_BUF_RX_SIZE, sizeof(struct acl_data),
@@ -129,7 +126,7 @@ struct net_buf *bt_buf_get_rx(enum bt_buf_type type, k_timeout_t timeout)
129126
buf = net_buf_alloc(&hci_rx_pool, timeout);
130127
#endif
131128
if (buf) {
132-
net_buf_add_u8(buf, type);
129+
net_buf_add_u8(buf, bt_buf_type_to_h4(type));
133130
}
134131

135132
return buf;
@@ -170,7 +167,7 @@ struct net_buf *bt_buf_get_evt(uint8_t evt, bool discardable,
170167
}
171168

172169
if (buf) {
173-
net_buf_add_u8(buf, BT_BUF_EVT);
170+
net_buf_add_u8(buf, BT_HCI_H4_EVT);
174171
}
175172

176173
return buf;

subsys/bluetooth/host/conn.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ static int send_acl(struct bt_conn *conn, struct net_buf *buf, uint8_t flags)
551551
hdr->handle = sys_cpu_to_le16(bt_acl_handle_pack(conn->handle, flags));
552552
hdr->len = sys_cpu_to_le16(buf->len - sizeof(*hdr));
553553

554-
net_buf_push_u8(buf, BT_BUF_ACL_OUT);
554+
net_buf_push_u8(buf, BT_HCI_H4_ACL);
555555

556556
return bt_send(buf);
557557
}
@@ -609,7 +609,7 @@ static int send_iso(struct bt_conn *conn, struct net_buf *buf, uint8_t flags)
609609
hdr->handle = sys_cpu_to_le16(bt_iso_handle_pack(conn->handle, flags, ts));
610610
hdr->len = sys_cpu_to_le16(buf->len - sizeof(*hdr));
611611

612-
net_buf_push_u8(buf, BT_BUF_ISO_OUT);
612+
net_buf_push_u8(buf, BT_HCI_H4_ISO);
613613

614614
return bt_send(buf);
615615
}

0 commit comments

Comments
 (0)