1 /*
2 * Copyright (c) 2017-2018 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <stdlib.h>
8 #include <string.h>
9 #include <zephyr/kernel.h>
10 #include <zephyr/shell/shell.h>
11 #include <zephyr/sys/printk.h>
12 #include <zephyr/sys/byteorder.h>
13
14 #include <zephyr/bluetooth/hci.h>
15 #include <zephyr/bluetooth/hci_vs.h>
16 #include <zephyr/bluetooth/conn.h>
17
18 #include "../host/hci_core.h"
19
20 #if defined(CONFIG_BT_HCI_MESH_EXT)
cmd_mesh_adv(const struct shell * sh,size_t argc,char * argv[])21 int cmd_mesh_adv(const struct shell *sh, size_t argc, char *argv[])
22 {
23 struct net_buf *buf;
24 int err;
25
26 if (argc < 2) {
27 return -EINVAL;
28 }
29
30 if (!strcmp(argv[1], "on")) {
31 struct bt_hci_cp_mesh_advertise *cp;
32
33 buf = bt_hci_cmd_create(BT_HCI_OP_VS_MESH,
34 sizeof(struct bt_hci_cp_mesh) +
35 sizeof(*cp));
36 if (!buf) {
37 return -ENOBUFS;
38 }
39
40 net_buf_add_u8(buf, BT_HCI_OC_MESH_ADVERTISE);
41
42 /* TODO: fetch and fill cmdline params */
43 cp = net_buf_add(buf, sizeof(*cp));
44 cp->adv_slot = 0U;
45 cp->own_addr_type = 0x01;
46 memset(&cp->random_addr, 0, sizeof(bt_addr_t));
47 cp->ch_map = 0x07;
48 cp->tx_power = 0;
49 cp->min_tx_delay = 0U;
50 cp->max_tx_delay = 0x32;
51 cp->retx_count = 0x07;
52 cp->retx_interval = 0x00;
53 cp->scan_delay = 0x0a;
54 cp->scan_duration = sys_cpu_to_le16(0x0064);
55 cp->scan_filter = 0x00;
56 cp->data_len = 0U;
57 memset(cp->data, 0, sizeof(cp->data));
58 } else if (!strcmp(argv[1], "off")) {
59 struct bt_hci_cp_mesh_advertise_cancel *cp;
60
61 buf = bt_hci_cmd_create(BT_HCI_OP_VS_MESH,
62 sizeof(struct bt_hci_cp_mesh) +
63 sizeof(*cp));
64 if (!buf) {
65 return -ENOBUFS;
66 }
67
68 net_buf_add_u8(buf, BT_HCI_OC_MESH_ADVERTISE_CANCEL);
69
70 cp = net_buf_add(buf, sizeof(*cp));
71 cp->adv_slot = 0U;
72 } else {
73 return -EINVAL;
74 }
75
76 err = bt_hci_cmd_send_sync(BT_HCI_OP_VS_MESH, buf, NULL);
77
78 return err;
79 }
80 #endif /* CONFIG_BT_HCI_MESH_EXT */
81