1 /*
2 * Copyright (c) 2020 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <stdint.h>
8 #include <zephyr/sys/byteorder.h>
9 #include <zephyr/drivers/bluetooth.h>
10 #include "common/assert.h"
11
bt_hci_evt_create(uint8_t evt,uint8_t len)12 struct net_buf *bt_hci_evt_create(uint8_t evt, uint8_t len)
13 {
14 struct bt_hci_evt_hdr *hdr;
15 struct net_buf *buf;
16
17 buf = bt_buf_get_evt(evt, false, K_FOREVER);
18
19 BT_ASSERT(buf);
20
21 hdr = net_buf_add(buf, sizeof(*hdr));
22 hdr->evt = evt;
23 hdr->len = len;
24
25 return buf;
26 }
27
bt_hci_cmd_complete_create(uint16_t op,uint8_t plen)28 struct net_buf *bt_hci_cmd_complete_create(uint16_t op, uint8_t plen)
29 {
30 struct net_buf *buf;
31 struct bt_hci_evt_cmd_complete *cc;
32
33 buf = bt_hci_evt_create(BT_HCI_EVT_CMD_COMPLETE, sizeof(*cc) + plen);
34
35 cc = net_buf_add(buf, sizeof(*cc));
36 cc->ncmd = 1U;
37 cc->opcode = sys_cpu_to_le16(op);
38
39 return buf;
40 }
41
bt_hci_cmd_status_create(uint16_t op,uint8_t status)42 struct net_buf *bt_hci_cmd_status_create(uint16_t op, uint8_t status)
43 {
44 struct net_buf *buf;
45 struct bt_hci_evt_cmd_status *cs;
46
47 buf = bt_hci_evt_create(BT_HCI_EVT_CMD_STATUS, sizeof(*cs));
48
49 cs = net_buf_add(buf, sizeof(*cs));
50 cs->status = status;
51 cs->ncmd = 1U;
52 cs->opcode = sys_cpu_to_le16(op);
53
54 return buf;
55 }
56