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/hci_driver.h>
10 
bt_hci_evt_create(uint8_t evt,uint8_t len)11 struct net_buf *bt_hci_evt_create(uint8_t evt, uint8_t len)
12 {
13 	struct bt_hci_evt_hdr *hdr;
14 	struct net_buf *buf;
15 
16 	buf = bt_buf_get_evt(evt, false, K_FOREVER);
17 
18 	hdr = net_buf_add(buf, sizeof(*hdr));
19 	hdr->evt = evt;
20 	hdr->len = len;
21 
22 	return buf;
23 }
24 
bt_hci_cmd_complete_create(uint16_t op,uint8_t plen)25 struct net_buf *bt_hci_cmd_complete_create(uint16_t op, uint8_t plen)
26 {
27 	struct net_buf *buf;
28 	struct bt_hci_evt_cmd_complete *cc;
29 
30 	buf = bt_hci_evt_create(BT_HCI_EVT_CMD_COMPLETE, sizeof(*cc) + plen);
31 
32 	cc = net_buf_add(buf, sizeof(*cc));
33 	cc->ncmd = 1U;
34 	cc->opcode = sys_cpu_to_le16(op);
35 
36 	return buf;
37 }
38 
bt_hci_cmd_status_create(uint16_t op,uint8_t status)39 struct net_buf *bt_hci_cmd_status_create(uint16_t op, uint8_t status)
40 {
41 	struct net_buf *buf;
42 	struct bt_hci_evt_cmd_status *cs;
43 
44 	buf = bt_hci_evt_create(BT_HCI_EVT_CMD_STATUS, sizeof(*cs));
45 
46 	cs = net_buf_add(buf, sizeof(*cs));
47 	cs->status = status;
48 	cs->ncmd = 1U;
49 	cs->opcode = sys_cpu_to_le16(op);
50 
51 	return buf;
52 }
53