1 /** @file
2 * @brief Bluetooth Link Layer functions
3 *
4 */
5
6 /*
7 * Copyright (c) 2017 Nordic Semiconductor ASA
8 *
9 * SPDX-License-Identifier: Apache-2.0
10 */
11
12 #include <stdlib.h>
13 #include <string.h>
14 #include <zephyr.h>
15 #include <shell/shell.h>
16 #include <misc/printk.h>
17
18 #include <bluetooth/hci.h>
19
20 #include "../controller/include/ll.h"
21
22 #if defined(CONFIG_BT_CTLR_DTM)
23 #include "../controller/ll_sw/ll_test.h"
24
cmd_test_tx(int argc,char * argv[])25 int cmd_test_tx(int argc, char *argv[])
26 {
27 u8_t chan, len, type, phy;
28 bt_u32_t err;
29
30 if (argc < 5) {
31 return -EINVAL;
32 }
33
34 chan = strtoul(argv[1], NULL, 16);
35 len = strtoul(argv[2], NULL, 16);
36 type = strtoul(argv[3], NULL, 16);
37 phy = strtoul(argv[4], NULL, 16);
38
39 err = ll_test_tx(chan, len, type, phy);
40 if (err) {
41 return -EINVAL;
42 }
43
44 printk("test_tx...\n");
45
46 return 0;
47 }
48
cmd_test_rx(int argc,char * argv[])49 int cmd_test_rx(int argc, char *argv[])
50 {
51 u8_t chan, phy, mod_idx;
52 bt_u32_t err;
53
54 if (argc < 4) {
55 return -EINVAL;
56 }
57
58 chan = strtoul(argv[1], NULL, 16);
59 phy = strtoul(argv[2], NULL, 16);
60 mod_idx = strtoul(argv[3], NULL, 16);
61
62 err = ll_test_rx(chan, phy, mod_idx);
63 if (err) {
64 return -EINVAL;
65 }
66
67 printk("test_rx...\n");
68
69 return 0;
70 }
71
cmd_test_end(int argc,char * argv[])72 int cmd_test_end(int argc, char *argv[])
73 {
74 u16_t num_rx;
75 bt_u32_t err;
76
77 err = ll_test_end(&num_rx);
78 if (err) {
79 return -EINVAL;
80 }
81
82 printk("num_rx= %u.\n", num_rx);
83
84 return 0;
85 }
86 #endif /* CONFIG_BT_CTLR_DTM */
87
88 #if defined(CONFIG_BT_CTLR_ADV_EXT)
89 #define ADV_INTERVAL 0x000020
90 #define ADV_TYPE 0x05 /* Adv. Ext. */
91 #define OWN_ADDR_TYPE 1
92 #define PEER_ADDR_TYPE 0
93 #define PEER_ADDR NULL
94 #define ADV_CHAN_MAP 0x07
95 #define FILTER_POLICY 0x00
96 #define ADV_TX_PWR NULL
97 #define ADV_SEC_SKIP 0
98 #define ADV_PHY_S 0x01
99 #define ADV_SID 0
100 #define SCAN_REQ_NOT 0
101
102 #define SCAN_INTERVAL 0x0004
103 #define SCAN_WINDOW 0x0004
104 #define SCAN_OWN_ADDR_TYPE 1
105 #define SCAN_FILTER_POLICY 0
106
cmd_advx(int argc,char * argv[])107 int cmd_advx(int argc, char *argv[])
108 {
109 u16_t evt_prop;
110 u8_t enable;
111 u8_t phy_p;
112 bt_s32_t err;
113
114 if (argc < 2) {
115 return -EINVAL;
116 }
117
118 if (argc > 1) {
119 if (!strcmp(argv[1], "on")) {
120 evt_prop = 0;
121 enable = 1;
122 } else if (!strcmp(argv[1], "off")) {
123 enable = 0;
124 goto disable;
125 } else {
126 return -EINVAL;
127 }
128 }
129
130 phy_p = BIT(0);
131
132 if (argc > 2) {
133 if (!strcmp(argv[2], "coded")) {
134 phy_p = BIT(2);
135 } else if (!strcmp(argv[2], "anon")) {
136 evt_prop |= BIT(5);
137 } else if (!strcmp(argv[2], "txp")) {
138 evt_prop |= BIT(6);
139 } else {
140 return -EINVAL;
141 }
142 }
143
144 if (argc > 3) {
145 if (!strcmp(argv[3], "anon")) {
146 evt_prop |= BIT(5);
147 } else if (!strcmp(argv[3], "txp")) {
148 evt_prop |= BIT(6);
149 } else {
150 return -EINVAL;
151 }
152 }
153
154 if (argc > 4) {
155 if (!strcmp(argv[4], "txp")) {
156 evt_prop |= BIT(6);
157 } else {
158 return -EINVAL;
159 }
160 }
161
162 printk("adv param set...");
163 err = ll_adv_params_set(0x00, evt_prop, ADV_INTERVAL, ADV_TYPE,
164 OWN_ADDR_TYPE, PEER_ADDR_TYPE, PEER_ADDR,
165 ADV_CHAN_MAP, FILTER_POLICY, ADV_TX_PWR,
166 phy_p, ADV_SEC_SKIP, ADV_PHY_S, ADV_SID,
167 SCAN_REQ_NOT);
168 if (err) {
169 goto exit;
170 }
171
172 disable:
173 printk("adv enable (%u)...", enable);
174 err = ll_adv_enable(enable);
175 if (err) {
176 goto exit;
177 }
178
179 exit:
180 printk("done (err= %d).\n", err);
181
182 return 0;
183 }
184
cmd_scanx(int argc,char * argv[])185 int cmd_scanx(int argc, char *argv[])
186 {
187 u8_t type = 0;
188 u8_t enable;
189 bt_s32_t err;
190
191 if (argc < 2) {
192 return -EINVAL;
193 }
194
195 if (argc > 1) {
196 if (!strcmp(argv[1], "on")) {
197 enable = 1;
198 type = 1;
199 } else if (!strcmp(argv[1], "passive")) {
200 enable = 1;
201 type = 0;
202 } else if (!strcmp(argv[1], "off")) {
203 enable = 0;
204 goto disable;
205 } else {
206 return -EINVAL;
207 }
208 }
209
210 type |= BIT(1);
211
212 if (argc > 2) {
213 if (!strcmp(argv[2], "coded")) {
214 type &= BIT(0);
215 type |= BIT(3);
216 } else {
217 return -EINVAL;
218 }
219 }
220
221 printk("scan param set...");
222 err = ll_scan_params_set(type, SCAN_INTERVAL, SCAN_WINDOW,
223 SCAN_OWN_ADDR_TYPE, SCAN_FILTER_POLICY);
224 if (err) {
225 goto exit;
226 }
227
228 disable:
229 printk("scan enable (%u)...", enable);
230 err = ll_scan_enable(enable);
231 if (err) {
232 goto exit;
233 }
234
235 exit:
236 printk("done (err= %d).\n", err);
237
238 return 0;
239 }
240 #endif /* CONFIG_BT_CTLR_ADV_EXT */
241