Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | /** @file * @brief Bluetooth Link Layer functions * */ /* * Copyright (c) 2017-2018 Nordic Semiconductor ASA * * SPDX-License-Identifier: Apache-2.0 */ #include <stdlib.h> #include <string.h> #include <zephyr.h> #include <bluetooth/hci.h> #include <bluetooth/bluetooth.h> #include <bluetooth/conn.h> #include <shell/shell.h> #include "../controller/util/memq.h" #include "../controller/include/ll.h" #include "bt.h" int cmd_ll_addr_get(const struct shell *shell, size_t argc, char *argv[]) { u8_t addr_type; const char *str_type; bt_addr_t addr; char str_addr[BT_ADDR_STR_LEN]; if (argc < 2) { return -EINVAL; } str_type = argv[1]; if (!strcmp(str_type, "random")) { addr_type = 1U; } else if (!strcmp(str_type, "public")) { addr_type = 0U; } else { return -EINVAL; } (void)ll_addr_get(addr_type, addr.val); bt_addr_to_str(&addr, str_addr, sizeof(str_addr)); shell_print(shell, "Current %s address: %s", str_type, str_addr); return 0; } #if defined(CONFIG_BT_CTLR_DTM) #include "../controller/ll_sw/ll_test.h" int cmd_test_tx(const struct shell *shell, size_t argc, char *argv[]) { u8_t chan, len, type, phy; u32_t err; if (argc < 5) { return -EINVAL; } chan = strtoul(argv[1], NULL, 16); len = strtoul(argv[2], NULL, 16); type = strtoul(argv[3], NULL, 16); phy = strtoul(argv[4], NULL, 16); err = ll_test_tx(chan, len, type, phy); if (err) { return -EINVAL; } shell_print(shell, "test_tx..."); return 0; } int cmd_test_rx(const struct shell *shell, size_t argc, char *argv[]) { u8_t chan, phy, mod_idx; u32_t err; if (argc < 4) { return -EINVAL; } chan = strtoul(argv[1], NULL, 16); phy = strtoul(argv[2], NULL, 16); mod_idx = strtoul(argv[3], NULL, 16); err = ll_test_rx(chan, phy, mod_idx); if (err) { return -EINVAL; } shell_print(shell, "test_rx..."); return 0; } int cmd_test_end(const struct shell *shell, size_t argc, char *argv[]) { u16_t num_rx; u32_t err; err = ll_test_end(&num_rx); if (err) { return -EINVAL; } shell_print(shell, "num_rx= %u.", num_rx); return 0; } #endif /* CONFIG_BT_CTLR_DTM */ #if defined(CONFIG_BT_CTLR_ADV_EXT) #include "../controller/ll_sw/ll_adv_aux.h" #include "../controller/ll_sw/lll.h" #define OWN_ADDR_TYPE 1 #define PEER_ADDR_TYPE 0 #define PEER_ADDR NULL #define ADV_CHAN_MAP 0x07 #define FILTER_POLICY 0x00 #define ADV_TX_PWR NULL #define ADV_SEC_SKIP 0 #define ADV_PHY_S 0x01 #define ADV_SID 0 #define SCAN_REQ_NOT 0 #define AD_OP 0x03 #define AD_FRAG_PREF 0x00 #define AD_LEN 0x00 #define AD_DATA NULL #define SCAN_INTERVAL 0x0004 #define SCAN_WINDOW 0x0004 #define SCAN_OWN_ADDR_TYPE 1 #define SCAN_FILTER_POLICY 0 #if defined(CONFIG_BT_BROADCASTER) int cmd_advx(const struct shell *shell, size_t argc, char *argv[]) { u16_t adv_interval = 0x20; u16_t handle = 0U; u16_t evt_prop = 0U; u8_t adv_type; u8_t enable; u8_t phy_p; s32_t err; if (argc < 2) { return -EINVAL; } if (argc > 1) { if (!strcmp(argv[1], "on")) { adv_type = 0x05; /* Adv. Ext. */ enable = 1U; } else if (!strcmp(argv[1], "hdcd")) { adv_type = 0x01; /* Directed */ adv_interval = 0U; /* High Duty Cycle */ phy_p = BIT(0); enable = 1U; goto do_enable; } else if (!strcmp(argv[1], "ldcd")) { adv_type = 0x04; /* Directed */ enable = 1U; } else if (!strcmp(argv[1], "off")) { enable = 0U; } else { return -EINVAL; } } phy_p = BIT(0); if (argc > 2) { if (!strcmp(argv[2], "coded")) { phy_p = BIT(2); } else if (!strcmp(argv[2], "anon")) { evt_prop |= BIT(5); } else if (!strcmp(argv[2], "txp")) { evt_prop |= BIT(6); } else if (!strcmp(argv[2], "ad")) { } else { handle = strtoul(argv[2], NULL, 16); if (handle >= BT_CTLR_ADV_MAX) { return -EINVAL; } } } if (argc > 3) { if (!strcmp(argv[3], "anon")) { evt_prop |= BIT(5); } else if (!strcmp(argv[3], "txp")) { evt_prop |= BIT(6); } else if (!strcmp(argv[3], "ad")) { } else { handle = strtoul(argv[3], NULL, 16); if (handle >= BT_CTLR_ADV_MAX) { return -EINVAL; } } } if (argc > 4) { if (!strcmp(argv[4], "txp")) { evt_prop |= BIT(6); } else if (!strcmp(argv[4], "ad")) { } else { handle = strtoul(argv[4], NULL, 16); if (handle >= BT_CTLR_ADV_MAX) { return -EINVAL; } } } if (argc > 5) { if (!strcmp(argv[5], "ad")) { } else { handle = strtoul(argv[5], NULL, 16); if (handle >= BT_CTLR_ADV_MAX) { return -EINVAL; } } } if (argc > 6) { handle = strtoul(argv[6], NULL, 16); if (handle >= BT_CTLR_ADV_MAX) { return -EINVAL; } } if (!enable) { goto disable; } do_enable: shell_print(shell, "adv param set..."); err = ll_adv_params_set(handle, evt_prop, adv_interval, adv_type, OWN_ADDR_TYPE, PEER_ADDR_TYPE, PEER_ADDR, ADV_CHAN_MAP, FILTER_POLICY, ADV_TX_PWR, phy_p, ADV_SEC_SKIP, ADV_PHY_S, ADV_SID, SCAN_REQ_NOT); if (err) { goto exit; } #if defined(CONFIG_BT_LL_SW_SPLIT) shell_print(shell, "ad data set..."); err = ll_adv_aux_ad_data_set(handle, AD_OP, AD_FRAG_PREF, AD_LEN, AD_DATA); if (err) { goto exit; } #endif disable: shell_print(shell, "adv enable (%u)...", enable); #if defined(CONFIG_BT_HCI_MESH_EXT) err = ll_adv_enable(handle, enable, 0, 0, 0, 0, 0); #else /* !CONFIG_BT_HCI_MESH_EXT */ err = ll_adv_enable(handle, enable); #endif /* !CONFIG_BT_HCI_MESH_EXT */ if (err) { goto exit; } exit: shell_print(shell, "done (err= %d).", err); return 0; } #endif /* CONFIG_BT_BROADCASTER */ #if defined(CONFIG_BT_OBSERVER) int cmd_scanx(const struct shell *shell, size_t argc, char *argv[]) { u8_t type = 0U; u8_t enable; s32_t err; if (argc < 2) { return -EINVAL; } if (argc > 1) { if (!strcmp(argv[1], "on")) { enable = 1U; type = 1U; } else if (!strcmp(argv[1], "passive")) { enable = 1U; type = 0U; } else if (!strcmp(argv[1], "off")) { enable = 0U; goto disable; } else { return -EINVAL; } } type |= BIT(1); if (argc > 2) { if (!strcmp(argv[2], "coded")) { type &= BIT(0); type |= BIT(3); } else { return -EINVAL; } } shell_print(shell, "scan param set..."); err = ll_scan_params_set(type, SCAN_INTERVAL, SCAN_WINDOW, SCAN_OWN_ADDR_TYPE, SCAN_FILTER_POLICY); if (err) { goto exit; } disable: shell_print(shell, "scan enable (%u)...", enable); err = ll_scan_enable(enable); if (err) { goto exit; } exit: shell_print(shell, "done (err= %d).", err); return err; } #endif /* CONFIG_BT_OBSERVER */ #endif /* CONFIG_BT_CTLR_ADV_EXT */ #if defined(CONFIG_BT_LL_SW_SPLIT) int cmd_ull_reset(const struct shell *shell, size_t argc, char *argv[]) { ll_reset(); return 0; } #endif /* CONFIG_BT_LL_SW_SPLIT */ |