luat_nimble_mode_central.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "luat_base.h"
  5. #if (defined(TLS_CONFIG_CPU_XT804) || defined(AIR103))
  6. #include "FreeRTOS.h"
  7. #else
  8. #include "freertos/FreeRTOS.h"
  9. #endif
  10. #include "host/ble_hs.h"
  11. #include "host/ble_uuid.h"
  12. #include "host/util/util.h"
  13. #include "services/gap/ble_svc_gap.h"
  14. #include "services/gatt/ble_svc_gatt.h"
  15. #include "luat_msgbus.h"
  16. #include "luat_malloc.h"
  17. #include "luat_nimble.h"
  18. /* BLE */
  19. #include "nimble/nimble_port.h"
  20. // #define LUAT_NIMBLE_DEBUG 0
  21. // #if LUAT_NIMBLE_DEBUG == 0
  22. // #undef LLOGD
  23. // #define LLOGD(...)
  24. // #endif
  25. static int ble_gatt_svc_counter = 0;
  26. struct ble_hs_cfg;
  27. struct ble_gatt_register_ctxt;
  28. typedef struct luat_nimble_scan_result
  29. {
  30. uint16_t uuids_16[16];
  31. uint32_t uuids_32[16];
  32. uint8_t uuids_128[16][16];
  33. uint8_t mfg_data[128];
  34. char name[64];
  35. char addr[7]; // 地址类型 + MAC地址
  36. uint8_t mfg_data_len;
  37. }luat_nimble_scan_result_t;
  38. void rand_bytes(uint8_t *data, int len);
  39. void print_bytes(const uint8_t *bytes, int len);
  40. void print_addr(const void *addr);
  41. void print_mbuf(const struct os_mbuf *om);
  42. char *addr_str(const void *addr);
  43. void print_uuid(const ble_uuid_t *uuid);
  44. void print_conn_desc(const struct ble_gap_conn_desc *desc);
  45. void print_adv_fields(const struct ble_hs_adv_fields *fields);
  46. extern uint16_t g_ble_conn_handle;
  47. extern uint16_t g_ble_state;
  48. #define LUAT_LOG_TAG "nimble"
  49. #include "luat_log.h"
  50. static char selfname[32];
  51. // extern uint16_t g_ble_conn_handle;
  52. // static uint16_t g_ble_state;
  53. void ble_store_config_init(void);
  54. static int blecent_gap_event(struct ble_gap_event *event, void *arg);
  55. static void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg) {
  56. LLOGD("gatt_svr_register_cb op %d", ctxt->op);
  57. }
  58. /**
  59. * Initiates the GAP general discovery procedure.
  60. */
  61. int luat_nimble_blecent_scan(int timeout)
  62. {
  63. uint8_t own_addr_type;
  64. struct ble_gap_disc_params disc_params = {0};
  65. int rc;
  66. /* Figure out address to use while advertising (no privacy for now) */
  67. rc = ble_hs_id_infer_auto(0, &own_addr_type);
  68. if (rc != 0) {
  69. LLOGE("error determining address type; rc=%d", rc);
  70. return rc;
  71. }
  72. /* Tell the controller to filter duplicates; we don't want to process
  73. * repeated advertisements from the same device.
  74. */
  75. disc_params.filter_duplicates = 1;
  76. /**
  77. * Perform a passive scan. I.e., don't send follow-up scan requests to
  78. * each advertiser.
  79. */
  80. disc_params.passive = 0;
  81. /* Use defaults for the rest of the parameters. */
  82. disc_params.itvl = 0;
  83. disc_params.window = 0;
  84. disc_params.filter_policy = 0;
  85. disc_params.limited = 0;
  86. rc = ble_gap_disc(own_addr_type, timeout*1000, &disc_params,
  87. blecent_gap_event, NULL);
  88. if (rc != 0) {
  89. LLOGE("Error initiating GAP discovery procedure; rc=%d", rc);
  90. }
  91. return rc;
  92. }
  93. // static const char *tag = "NimBLE_BLE_PRPH";
  94. static int bleprph_gap_event(struct ble_gap_event *event, void *arg);
  95. // #if CONFIG_EXAMPLE_RANDOM_ADDR
  96. // static uint8_t own_addr_type = BLE_OWN_ADDR_RANDOM;
  97. // #else
  98. // static uint8_t own_addr_type;
  99. // #endif
  100. #define ADDR_FMT "%02X%02X%02X%02X%02X%02X"
  101. #define ADDR_T(addr) addr[0],addr[1],addr[2],addr[3],addr[4],addr[5]
  102. static void
  103. bleprph_print_conn_desc(struct ble_gap_conn_desc *desc)
  104. {
  105. LLOGI("handle=%d our_ota_addr_type=%d our_ota_addr=" ADDR_FMT, desc->conn_handle, desc->our_ota_addr.type, ADDR_T(desc->our_ota_addr.val));
  106. LLOGI(" our_id_addr_type=%d our_id_addr=" ADDR_FMT, desc->our_id_addr.type, ADDR_T(desc->our_id_addr.val));
  107. LLOGI(" peer_ota_addr_type=%d peer_ota_addr=" ADDR_FMT, desc->peer_ota_addr.type, ADDR_T(desc->peer_ota_addr.val));
  108. LLOGI(" peer_id_addr_type=%d peer_id_addr=" ADDR_FMT, desc->peer_id_addr.type, ADDR_T(desc->peer_id_addr.val));
  109. LLOGI(" conn_itvl=%d conn_latency=%d supervision_timeout=%d "
  110. "encrypted=%d authenticated=%d bonded=%d",
  111. desc->conn_itvl, desc->conn_latency,
  112. desc->supervision_timeout,
  113. desc->sec_state.encrypted,
  114. desc->sec_state.authenticated,
  115. desc->sec_state.bonded);
  116. }
  117. // int luat_nimble_connect(ble_addr_t *addr) {
  118. int luat_nimble_blecent_connect(const char* _addr){
  119. uint8_t own_addr_type;
  120. int rc;
  121. ble_addr_t *addr;
  122. addr = (ble_addr_t *)_addr;
  123. ble_gatt_svc_counter = 0;
  124. // 首先, 停止搜索
  125. rc = ble_gap_disc_cancel();
  126. LLOGD("ble_gap_disc_cancel %d", rc);
  127. rc = ble_hs_id_infer_auto(0, &own_addr_type);
  128. LLOGD("ble_hs_id_infer_auto %d", rc);
  129. rc = ble_gap_connect(own_addr_type, addr, 30000, NULL, blecent_gap_event, NULL);
  130. LLOGD("ble_gap_connect %d", rc);
  131. return rc;
  132. }
  133. int luat_nimble_scan_cb(lua_State*L, void*ptr) {
  134. luat_nimble_scan_result_t* res = (luat_nimble_scan_result_t*)ptr;
  135. lua_getglobal(L,"sys_pub");
  136. lua_pushliteral(L, "BLE_SCAN_RESULT");
  137. lua_pushlstring(L, (const char*)res->addr, 7);
  138. if (res->name[0]) {
  139. lua_pushstring(L, res->name);
  140. }
  141. else {
  142. lua_pushliteral(L, ""); // 设备没有名字
  143. }
  144. lua_newtable(L);
  145. // char buff[64];
  146. if (res->uuids_16[0]) {
  147. lua_newtable(L);
  148. for (size_t i = 0; i < 16; i++)
  149. {
  150. if (res->uuids_16[i] == 0)
  151. break;
  152. //lua_pushlstring(L, (const char*)&res->uuids_16[i], 2);
  153. lua_pushinteger(L, res->uuids_16[i]);
  154. lua_seti(L, -2, i+1);
  155. }
  156. lua_setfield(L, -2, "uuids16");
  157. }
  158. // if (res->uuids_32[0]) {
  159. // lua_newtable(L);
  160. // for (size_t i = 0; i < 16; i++)
  161. // {
  162. // if (res->uuids_32[i] == 0)
  163. // break;
  164. // lua_pushlstring(L, (const char*)&res->uuids_32[i], 4);
  165. // lua_pushinteger(L, res->uuids_32[i]);
  166. // lua_seti(L, -2, i+1);
  167. // }
  168. // lua_setfield(L, -2, "uuids32");
  169. // }
  170. // if (res->uuids_128[0][0]) {
  171. // lua_newtable(L);
  172. // for (size_t i = 0; i < 16; i++)
  173. // {
  174. // if (res->uuids_32[i] == 0)
  175. // break;
  176. // lua_pushlstring(L, (const char*)res->uuids_128[i], 16);
  177. // lua_seti(L, -2, i+1);
  178. // }
  179. // lua_setfield(L, -2, "uuids128");
  180. // }
  181. if (res->mfg_data_len) {
  182. lua_pushlstring(L, (const char*)res->mfg_data, res->mfg_data_len);
  183. }
  184. else {
  185. lua_pushnil(L);
  186. }
  187. luat_heap_free(res);
  188. lua_call(L, 5, 0);
  189. return 0;
  190. }
  191. static int svc_disced(uint16_t conn_handle,
  192. const struct ble_gatt_error *error,
  193. const struct ble_gatt_svc *service,
  194. void *arg) {
  195. LLOGD("ble_gatt_error status %d", error->status);
  196. if (error->status == BLE_HS_EDONE) {
  197. LLOGD("service discovery done count %d", ble_gatt_svc_counter);
  198. return 0;
  199. }
  200. if (error->status != 0) {
  201. return error->status;
  202. }
  203. char buff[64] = {0};
  204. ble_gatt_svc_counter ++;
  205. LLOGD("service->start_handle %04X", service->start_handle);
  206. LLOGD("service->end_handle %04X", service->end_handle);
  207. LLOGD("service->uuid %s", ble_uuid_to_str(&service->uuid, buff));
  208. return 0;
  209. }
  210. static int blecent_gap_event(struct ble_gap_event *event, void *arg)
  211. {
  212. struct ble_hs_adv_fields fields;
  213. struct ble_gap_conn_desc desc;
  214. int rc = 0;
  215. int i = 0;
  216. rtos_msg_t msg = {.handler=luat_nimble_scan_cb};
  217. // LLOGD("blecent_gap_event %d", event->type);
  218. switch (event->type) {
  219. case BLE_GAP_EVENT_DISC_COMPLETE:
  220. LLOGD("ble scan complete");
  221. return 0;
  222. case BLE_GAP_EVENT_DISC:
  223. rc = ble_hs_adv_parse_fields(&fields, event->disc.data,
  224. event->disc.length_data);
  225. if (rc != 0) {
  226. LLOGI("ble_hs_adv_parse_fields rc %d", rc);
  227. return 0;
  228. }
  229. // if (event->disc.event_type != BLE_HCI_ADV_RPT_EVTYPE_ADV_IND &&
  230. // event->disc.event_type != BLE_HCI_ADV_RPT_EVTYPE_DIR_IND) {
  231. // LLOGI("disc event_type Not ADC or DIR %d", event->disc.event_type);
  232. // return 0;
  233. // }
  234. luat_nimble_scan_result_t* res = luat_heap_malloc(sizeof(luat_nimble_scan_result_t));
  235. if (res == NULL) {
  236. LLOGI("out of memory when malloc luat_nimble_scan_result_t");
  237. return 0;
  238. }
  239. memset(res, 0, sizeof(luat_nimble_scan_result_t));
  240. // char tmpbuff[64] = {0};
  241. for (i = 0; i < fields.num_uuids16 && i < 16; i++) {
  242. // LLOGD("uuids_16 %s", ble_uuid_to_str(&fields.uuids16[i], tmpbuff));
  243. res->uuids_16[i] = fields.uuids16[i].value;
  244. }
  245. for (i = 0; i < fields.num_uuids32 && i < 16; i++) {
  246. // LLOGD("uuids_32 %s", ble_uuid_to_str(&fields.uuids32[i], tmpbuff));
  247. res->uuids_32[i] = fields.uuids32[i].value;
  248. }
  249. for (i = 0; i < fields.num_uuids128 && i < 16; i++) {
  250. // LLOGD("uuids_128 %s", ble_uuid_to_str(&fields.uuids128[i], tmpbuff));
  251. // memcpy(res->uuids_128[i], fields.uuids128[i].value, 16);
  252. }
  253. memcpy(res->addr, &event->disc.addr, 7);
  254. memcpy(res->name, fields.name, fields.name_len);
  255. if (fields.mfg_data_len) {
  256. memcpy(res->mfg_data, fields.mfg_data, fields.mfg_data_len);
  257. res->mfg_data_len = fields.mfg_data_len;
  258. }
  259. // LLOGD("addr %02X%02X%02X%02X%02X%02X", event->disc.addr.val[0], event->disc.addr.val[1], event->disc.addr.val[2],
  260. // event->disc.addr.val[3], event->disc.addr.val[4], event->disc.addr.val[5]);
  261. // for (i = 0; i < fields.num_uuids128 && i < 16; i++) {
  262. // res->uuids_128[i] = fields.num_uuids128.value >> 32;
  263. // }
  264. // LLOGD("uuids 16=%d 32=%d 128=%d", fields.num_uuids16, fields.num_uuids32, fields.num_uuids128);
  265. msg.ptr = res;
  266. luat_msgbus_put(&msg, 0);
  267. /* An advertisment report was received during GAP discovery. */
  268. print_adv_fields(&fields);
  269. /* Try to connect to the advertiser if it looks interesting. */
  270. //blecent_connect_if_interesting(&event->disc);
  271. return 0;
  272. case BLE_GAP_EVENT_CONNECT:
  273. /* A new connection was established or a connection attempt failed. */
  274. LLOGI("connection %s; status=%d ",
  275. event->connect.status == 0 ? "established" : "failed",
  276. event->connect.status);
  277. if (event->connect.status == 0) {
  278. g_ble_conn_handle = event->connect.conn_handle;
  279. rc = ble_gap_conn_find(event->connect.conn_handle, &desc);
  280. if (rc == 0)
  281. bleprph_print_conn_desc(&desc);
  282. g_ble_state = BT_STATE_CONNECTED;
  283. /* Perform service discovery. */
  284. rc = ble_gattc_disc_all_svcs(event->connect.conn_handle, svc_disced, NULL);
  285. }
  286. else {
  287. g_ble_state = BT_STATE_DISCONNECT;
  288. }
  289. return 0;
  290. case BLE_GAP_EVENT_DISCONNECT:
  291. g_ble_state = BT_STATE_DISCONNECT;
  292. LLOGI("disconnect; reason=%d ", event->disconnect.reason);
  293. bleprph_print_conn_desc(&event->disconnect.conn);
  294. return 0;
  295. case BLE_GAP_EVENT_CONN_UPDATE:
  296. /* The central has updated the connection parameters. */
  297. LLOGI("connection updated; status=%d ", event->conn_update.status);
  298. rc = ble_gap_conn_find(event->conn_update.conn_handle, &desc);
  299. if (rc == 0)
  300. bleprph_print_conn_desc(&desc);
  301. // LLOGI("");
  302. return 0;
  303. case BLE_GAP_EVENT_ENC_CHANGE:
  304. /* Encryption has been enabled or disabled for this connection. */
  305. LLOGI("encryption change event; status=%d ",
  306. event->enc_change.status);
  307. rc = ble_gap_conn_find(event->enc_change.conn_handle, &desc);
  308. if (rc == 0)
  309. bleprph_print_conn_desc(&desc);
  310. // LLOGI("");
  311. return 0;
  312. case BLE_GAP_EVENT_SUBSCRIBE:
  313. LLOGI("subscribe event; conn_handle=%d attr_handle=%d "
  314. "reason=%d prevn=%d curn=%d previ=%d curi=%d",
  315. event->subscribe.conn_handle,
  316. event->subscribe.attr_handle,
  317. event->subscribe.reason,
  318. event->subscribe.prev_notify,
  319. event->subscribe.cur_notify,
  320. event->subscribe.prev_indicate,
  321. event->subscribe.cur_indicate);
  322. return 0;
  323. case BLE_GAP_EVENT_MTU:
  324. LLOGI("mtu update event; conn_handle=%d cid=%d mtu=%d",
  325. event->mtu.conn_handle,
  326. event->mtu.channel_id,
  327. event->mtu.value);
  328. return 0;
  329. case BLE_GAP_EVENT_REPEAT_PAIRING:
  330. /* We already have a bond with the peer, but it is attempting to
  331. * establish a new secure link. This app sacrifices security for
  332. * convenience: just throw away the old bond and accept the new link.
  333. */
  334. /* Delete the old bond. */
  335. rc = ble_gap_conn_find(event->repeat_pairing.conn_handle, &desc);
  336. assert(rc == 0);
  337. ble_store_util_delete_peer(&desc.peer_id_addr);
  338. /* Return BLE_GAP_REPEAT_PAIRING_RETRY to indicate that the host should
  339. * continue with the pairing operation.
  340. */
  341. return BLE_GAP_REPEAT_PAIRING_RETRY;
  342. case BLE_GAP_EVENT_PASSKEY_ACTION:
  343. LLOGI("PASSKEY_ACTION_EVENT started");
  344. return 0;
  345. }
  346. return 0;
  347. }
  348. static void
  349. blecent_on_reset(int reason)
  350. {
  351. g_ble_state = BT_STATE_OFF;
  352. LLOGE("Resetting state; reason=%d", reason);
  353. //app_adapter_state_changed_callback(WM_BT_STATE_OFF);
  354. }
  355. static void
  356. blecent_on_sync(void)
  357. {
  358. // int rc;
  359. /* Make sure we have proper identity address set (public preferred) */
  360. ble_hs_util_ensure_addr(0);
  361. }
  362. int luat_nimble_init_central(uint8_t uart_idx, char* name, int mode) {
  363. // int rc = 0;
  364. nimble_port_init();
  365. if (name == NULL || strlen(name) == 0) {
  366. if (selfname[0] == 0) {
  367. memcpy(selfname, "LuatOS", strlen("LuatOS") + 1);
  368. }
  369. }
  370. else {
  371. memcpy(selfname, name, strlen(name) + 1);
  372. }
  373. /* Set the default device name. */
  374. if (strlen(selfname))
  375. ble_svc_gap_device_name_set((const char*)selfname);
  376. /* Initialize the NimBLE host configuration. */
  377. ble_hs_cfg.reset_cb = blecent_on_reset;
  378. ble_hs_cfg.sync_cb = blecent_on_sync;
  379. ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb;
  380. ble_hs_cfg.store_status_cb = ble_store_util_status_rr;
  381. ble_hs_cfg.sm_io_cap = BLE_SM_IO_CAP_NO_IO;
  382. ble_hs_cfg.sm_sc = 0;
  383. ble_svc_gap_init();
  384. ble_svc_gatt_init();
  385. // rc = gatt_svr_init();
  386. // LLOGD("gatt_svr_init rc %d", rc);
  387. /* XXX Need to have template for store */
  388. ble_store_config_init();
  389. return 0;
  390. }
  391. //-----------------------------------
  392. // helper
  393. //-----------------------------------
  394. /**
  395. * Utility function to log an array of bytes.
  396. */
  397. void
  398. print_bytes(const uint8_t *bytes, int len)
  399. {
  400. int i;
  401. char buff[256 + 1] = {0};
  402. for (i = 0; i < len; i++) {
  403. sprintf_(buff + strlen(buff), "%02X", bytes[i]);
  404. // LLOGD("%s0x%02x", i != 0 ? ":" : "", bytes[i]);
  405. }
  406. LLOGD("%s", buff);
  407. }
  408. char *
  409. addr_str(const void *addr)
  410. {
  411. static char buf[6 * 2 + 5 + 1];
  412. const uint8_t *u8p;
  413. u8p = addr;
  414. sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x",
  415. u8p[5], u8p[4], u8p[3], u8p[2], u8p[1], u8p[0]);
  416. return buf;
  417. }
  418. void
  419. print_uuid(const ble_uuid_t *uuid)
  420. {
  421. char buf[BLE_UUID_STR_LEN];
  422. LLOGD("%s", ble_uuid_to_str(uuid, buf));
  423. }
  424. /**
  425. * Logs information about a connection to the console.
  426. */
  427. void
  428. print_conn_desc(const struct ble_gap_conn_desc *desc)
  429. {
  430. LLOGD("handle=%d our_ota_addr_type=%d our_ota_addr=%s ",
  431. desc->conn_handle, desc->our_ota_addr.type,
  432. addr_str(desc->our_ota_addr.val));
  433. LLOGD("our_id_addr_type=%d our_id_addr=%s ",
  434. desc->our_id_addr.type, addr_str(desc->our_id_addr.val));
  435. LLOGD("peer_ota_addr_type=%d peer_ota_addr=%s ",
  436. desc->peer_ota_addr.type, addr_str(desc->peer_ota_addr.val));
  437. LLOGD("peer_id_addr_type=%d peer_id_addr=%s ",
  438. desc->peer_id_addr.type, addr_str(desc->peer_id_addr.val));
  439. LLOGD("conn_itvl=%d conn_latency=%d supervision_timeout=%d "
  440. "encrypted=%d authenticated=%d bonded=%d",
  441. desc->conn_itvl, desc->conn_latency,
  442. desc->supervision_timeout,
  443. desc->sec_state.encrypted,
  444. desc->sec_state.authenticated,
  445. desc->sec_state.bonded);
  446. }
  447. void
  448. print_adv_fields(const struct ble_hs_adv_fields *fields)
  449. {
  450. // char s[BLE_HS_ADV_MAX_SZ];
  451. // const uint8_t *u8p;
  452. // int i;
  453. // if (fields->flags != 0) {
  454. // LLOGD(" flags=0x%02x", fields->flags);
  455. // }
  456. // if (fields->uuids16 != NULL) {
  457. // LLOGD(" uuids16(%scomplete)=",
  458. // fields->uuids16_is_complete ? "" : "in");
  459. // for (i = 0; i < fields->num_uuids16; i++) {
  460. // print_uuid(&fields->uuids16[i].u);
  461. // //LLOGD(" ");
  462. // }
  463. // }
  464. // if (fields->uuids32 != NULL) {
  465. // LLOGD(" uuids32(%scomplete)=",
  466. // fields->uuids32_is_complete ? "" : "in");
  467. // for (i = 0; i < fields->num_uuids32; i++) {
  468. // print_uuid(&fields->uuids32[i].u);
  469. // //LLOGD(" ");
  470. // }
  471. // }
  472. // if (fields->uuids128 != NULL) {
  473. // LLOGD(" uuids128(%scomplete)=",
  474. // fields->uuids128_is_complete ? "" : "in");
  475. // for (i = 0; i < fields->num_uuids128; i++) {
  476. // print_uuid(&fields->uuids128[i].u);
  477. // LLOGD(" ");
  478. // }
  479. // //LLOGD("");
  480. // }
  481. // if (fields->name != NULL) {
  482. // assert(fields->name_len < sizeof s - 1);
  483. // memcpy(s, fields->name, fields->name_len);
  484. // s[fields->name_len] = '\0';
  485. // LLOGD(" name(%scomplete)=%s",
  486. // fields->name_is_complete ? "" : "in", s);
  487. // }
  488. // if (fields->tx_pwr_lvl_is_present) {
  489. // LLOGD(" tx_pwr_lvl=%d", fields->tx_pwr_lvl);
  490. // }
  491. // if (fields->slave_itvl_range != NULL) {
  492. // LLOGD(" slave_itvl_range=");
  493. // print_bytes(fields->slave_itvl_range, BLE_HS_ADV_SLAVE_ITVL_RANGE_LEN);
  494. // }
  495. // if (fields->svc_data_uuid16 != NULL) {
  496. // LLOGD(" svc_data_uuid16=");
  497. // print_bytes(fields->svc_data_uuid16, fields->svc_data_uuid16_len);
  498. // }
  499. // if (fields->public_tgt_addr != NULL) {
  500. // LLOGD(" public_tgt_addr=");
  501. // u8p = fields->public_tgt_addr;
  502. // for (i = 0; i < fields->num_public_tgt_addrs; i++) {
  503. // LLOGD("public_tgt_addr=%s ", addr_str(u8p));
  504. // u8p += BLE_HS_ADV_PUBLIC_TGT_ADDR_ENTRY_LEN;
  505. // }
  506. // // LLOGD("");
  507. // }
  508. // if (fields->appearance_is_present) {
  509. // LLOGD(" appearance=0x%04x", fields->appearance);
  510. // }
  511. // if (fields->adv_itvl_is_present) {
  512. // LLOGD(" adv_itvl=0x%04x", fields->adv_itvl);
  513. // }
  514. // if (fields->svc_data_uuid32 != NULL) {
  515. // LLOGD(" svc_data_uuid32=");
  516. // print_bytes(fields->svc_data_uuid32, fields->svc_data_uuid32_len);
  517. // LLOGD("");
  518. // }
  519. // if (fields->svc_data_uuid128 != NULL) {
  520. // LLOGD(" svc_data_uuid128=");
  521. // print_bytes(fields->svc_data_uuid128, fields->svc_data_uuid128_len);
  522. // LLOGD("");
  523. // }
  524. // if (fields->uri != NULL) {
  525. // LLOGD(" uri=");
  526. // print_bytes(fields->uri, fields->uri_len);
  527. // LLOGD("");
  528. // }
  529. // if (fields->mfg_data != NULL) {
  530. // LLOGD(" mfg_data=");
  531. // print_bytes(fields->mfg_data, fields->mfg_data_len);
  532. // LLOGD("");
  533. // }
  534. }