| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2019-2025, Jacques Gagnon | ||
| 3 | * SPDX-License-Identifier: Apache-2.0 | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include <stdio.h> | ||
| 7 | #include <freertos/FreeRTOS.h> | ||
| 8 | #include <freertos/task.h> | ||
| 9 | #include <freertos/ringbuf.h> | ||
| 10 | #include "host.h" | ||
| 11 | #include "l2cap.h" | ||
| 12 | #include "mon.h" | ||
| 13 | #include "hci.h" | ||
| 14 | #include "att.h" | ||
| 15 | #include "att_hid.h" | ||
| 16 | #include "smp.h" | ||
| 17 | #include "tools/util.h" | ||
| 18 | #include "system/led.h" | ||
| 19 | #include "adapter/config.h" | ||
| 20 | #include "wired/wired_bare.h" | ||
| 21 | #include "zephyr/uuid.h" | ||
| 22 | |||
| 23 | #define BT_INQUIRY_MAX 10 | ||
| 24 | |||
| 25 | typedef void (*bt_cmd_func_t)(void *param); | ||
| 26 | |||
| 27 | struct bt_hci_cmd_cp { | ||
| 28 | bt_cmd_func_t cmd; | ||
| 29 | void *cp; | ||
| 30 | }; | ||
| 31 | |||
| 32 | struct bt_hci_le_cb { | ||
| 33 | struct bt_dev *device; | ||
| 34 | bt_hci_le_cb_t callback; | ||
| 35 | }; | ||
| 36 | |||
| 37 | static const char bt_default_pin[][5] = { | ||
| 38 | "0000", | ||
| 39 | "1234", | ||
| 40 | "1111", | ||
| 41 | }; | ||
| 42 | |||
| 43 | static const struct bt_hci_cp_set_event_filter clr_evt_filter = { | ||
| 44 | .filter_type = BT_BREDR_FILTER_TYPE_CLEAR, | ||
| 45 | }; | ||
| 46 | |||
| 47 | static const struct bt_hci_cp_set_event_filter inquiry_evt_filter = { | ||
| 48 | .filter_type = BT_BREDR_FILTER_TYPE_INQUIRY, | ||
| 49 | .condition_type = BT_BDEDR_COND_TYPE_CLASS, | ||
| 50 | .inquiry_class.dev_class = {0x00, 0x05, 0x00}, | ||
| 51 | .inquiry_class.dev_class_mask = {0x00, 0x1F, 0x00}, | ||
| 52 | }; | ||
| 53 | |||
| 54 | static const struct bt_hci_cp_set_event_filter conn_evt_filter = { | ||
| 55 | .filter_type = BT_BREDR_FILTER_TYPE_CONN, | ||
| 56 | .condition_type = BT_BDEDR_COND_TYPE_CLASS, | ||
| 57 | .conn_class.dev_class = {0x00, 0x05, 0x00}, | ||
| 58 | .conn_class.dev_class_mask = {0x00, 0x1F, 0x00}, | ||
| 59 | .conn_class.auto_accept_flag = BT_BREDR_AUTO_OFF, | ||
| 60 | }; | ||
| 61 | |||
| 62 | static uint32_t bt_hci_pkt_retry = 0; | ||
| 63 | static uint32_t bt_nb_inquiry = 0; | ||
| 64 | static uint8_t local_bdaddr[6]; | ||
| 65 | static uint32_t bt_config_state = 0; | ||
| 66 | static uint32_t inquiry_state = 0; | ||
| 67 | static uint32_t inquiry_override = 0; | ||
| 68 | static RingbufHandle_t randq_hdl, encryptq_hdl; | ||
| 69 | static char local_name[24] = "BlueRetro"; | ||
| 70 | |||
| 71 | static void bt_hci_cmd(uint16_t opcode, uint32_t cp_len); | ||
| 72 | //static void bt_hci_cmd_inquiry(void *cp); | ||
| 73 | //static void bt_hci_cmd_inquiry_cancel(void *cp); | ||
| 74 | static void bt_hci_cmd_periodic_inquiry(void *cp); | ||
| 75 | static void bt_hci_cmd_exit_periodic_inquiry(void *cp); | ||
| 76 | static void bt_hci_cmd_connect(void *bdaddr); | ||
| 77 | static void bt_hci_cmd_disconnect(void *handle, uint8_t reason); | ||
| 78 | static void bt_hci_cmd_accept_conn_req(void *bdaddr); | ||
| 79 | static void bt_hci_cmd_link_key_neg_reply(void *bdaddr); | ||
| 80 | static void bt_hci_cmd_pin_code_reply(void *cp); | ||
| 81 | //static void bt_hci_cmd_pin_code_neg_reply(void *bdaddr); | ||
| 82 | static void bt_hci_cmd_auth_requested(void *handle); | ||
| 83 | static void bt_hci_cmd_set_conn_encrypt(void *handle); | ||
| 84 | static void bt_hci_cmd_remote_name_request(void *bdaddr); | ||
| 85 | static void bt_hci_cmd_read_remote_features(void *handle); | ||
| 86 | static void bt_hci_cmd_read_remote_ext_features(void *handle); | ||
| 87 | //static void bt_hci_cmd_read_remote_version_info(uint16_t handle); | ||
| 88 | static void bt_hci_cmd_io_capability_reply(void *bdaddr); | ||
| 89 | static void bt_hci_cmd_user_confirm_reply(void *bdaddr); | ||
| 90 | static void bt_hci_cmd_sniff_mode(void *handle, uint16_t interval); | ||
| 91 | static void bt_hci_cmd_exit_sniff_mode(void *handle); | ||
| 92 | static void bt_hci_cmd_switch_role(void *cp); | ||
| 93 | //static void bt_hci_cmd_read_link_policy(void *handle); | ||
| 94 | //static void bt_hci_cmd_write_link_policy(void *cp); | ||
| 95 | //static void bt_hci_cmd_read_default_link_policy(void *cp); | ||
| 96 | static void bt_hci_cmd_write_default_link_policy(void *cp); | ||
| 97 | static void bt_hci_cmd_set_event_mask(void *cp); | ||
| 98 | static void bt_hci_cmd_reset(void *cp); | ||
| 99 | static void bt_hci_cmd_set_event_filter(void *cp); | ||
| 100 | static void bt_hci_cmd_read_stored_link_key(void *cp); | ||
| 101 | static void bt_hci_cmd_delete_stored_link_key(void *cp); | ||
| 102 | static void bt_hci_cmd_write_local_name(void *cp); | ||
| 103 | static void bt_hci_cmd_read_local_name(void *cp); | ||
| 104 | static void bt_hci_cmd_write_conn_accept_timeout(void *cp); | ||
| 105 | static void bt_hci_cmd_write_page_scan_timeout(void *cp); | ||
| 106 | static void bt_hci_cmd_write_scan_enable(void *cp); | ||
| 107 | static void bt_hci_cmd_write_page_scan_activity(void *cp); | ||
| 108 | static void bt_hci_cmd_write_inquiry_scan_activity(void *cp); | ||
| 109 | static void bt_hci_cmd_write_auth_enable(void *cp); | ||
| 110 | static void bt_hci_cmd_read_page_scan_activity(void *cp); | ||
| 111 | static void bt_hci_cmd_read_class_of_device(void *cp); | ||
| 112 | static void bt_hci_cmd_write_class_of_device(void *cp); | ||
| 113 | static void bt_hci_cmd_read_voice_setting(void *cp); | ||
| 114 | static void bt_hci_cmd_write_hold_mode_act(void *cp); | ||
| 115 | static void bt_hci_cmd_read_num_supported_iac(void *cp); | ||
| 116 | static void bt_hci_cmd_read_current_iac_lap(void *cp); | ||
| 117 | static void bt_hci_cmd_write_inquiry_mode(void *cp); | ||
| 118 | static void bt_hci_cmd_read_page_scan_type(void *cp); | ||
| 119 | static void bt_hci_cmd_write_page_scan_type(void *cp); | ||
| 120 | static void bt_hci_cmd_write_ssp_mode(void *cp); | ||
| 121 | static void bt_hci_cmd_read_inquiry_rsp_tx_pwr_lvl(void *cp); | ||
| 122 | static void bt_hci_cmd_write_le_host_supp(void *cp); | ||
| 123 | static void bt_hci_cmd_read_local_version_info(void *cp); | ||
| 124 | static void bt_hci_cmd_read_supported_commands(void *cp); | ||
| 125 | static void bt_hci_cmd_read_local_features(void *cp); | ||
| 126 | static void bt_hci_cmd_read_local_ext_features(void *cp); | ||
| 127 | static void bt_hci_cmd_read_buffer_size(void *cp); | ||
| 128 | static void bt_hci_cmd_read_bd_addr(void *cp); | ||
| 129 | //static void bt_hci_cmd_read_data_block_size(void *cp); | ||
| 130 | //static void bt_hci_cmd_read_local_codecs(void *cp); | ||
| 131 | //static void bt_hci_cmd_read_local_sp_options(void *cp); | ||
| 132 | #ifdef CONFIG_BLUERETRO_BT_SSP_DBG | ||
| 133 | static void bt_hci_cmd_write_ssp_dbg_mode(void *cp); | ||
| 134 | #endif | ||
| 135 | static void bt_hci_cmd_le_read_buffer_size(void *cp); | ||
| 136 | static void bt_hci_cmd_le_set_adv_param(void *cp); | ||
| 137 | static void bt_hci_cmd_le_set_adv_data(void *cp); | ||
| 138 | static void bt_hci_cmd_le_set_scan_rsp_data(void *cp); | ||
| 139 | static void bt_hci_cmd_le_set_adv_enable(void *cp); | ||
| 140 | static void bt_hci_cmd_le_set_scan_param_active(void); | ||
| 141 | static void bt_hci_cmd_le_set_scan_param_passive(void); | ||
| 142 | static void bt_hci_cmd_le_set_scan_enable(uint32_t enable); | ||
| 143 | static void bt_hci_cmd_le_create_conn(void *bdaddr_le); | ||
| 144 | static void bt_hci_cmd_le_read_wl_size(void *cp); | ||
| 145 | static void bt_hci_cmd_le_clear_wl(void *cp); | ||
| 146 | static void bt_hci_cmd_le_add_dev_to_wl(void *bdaddr_le); | ||
| 147 | static void bt_hci_cmd_le_conn_update(struct hci_cp_le_conn_update *cp); | ||
| 148 | //static void bt_hci_cmd_le_read_remote_features(uint16_t handle); | ||
| 149 | static void bt_hci_cmd_le_encrypt(const uint8_t *key, uint8_t *plaintext); | ||
| 150 | static void bt_hci_cmd_le_rand(void); | ||
| 151 | static void bt_hci_cmd_le_start_encryption(uint16_t handle, uint64_t rand, uint16_t ediv, uint8_t *ltk); | ||
| 152 | //static void bt_hci_cmd_le_set_ext_scan_param(void *cp); | ||
| 153 | //static void bt_hci_cmd_le_set_ext_scan_enable(void *cp); | ||
| 154 | static void bt_hci_le_meta_evt_hdlr(struct bt_hci_pkt *bt_hci_evt_pkt); | ||
| 155 | static void bt_hci_start_inquiry_cfg_check(void *cp); | ||
| 156 | static void bt_hci_load_le_accept_list(void *cp); | ||
| 157 | static void bt_hci_set_device_name(void); | ||
| 158 | |||
| 159 | static const struct bt_hci_cmd_cp bt_hci_config[] = { | ||
| 160 | {bt_hci_cmd_reset, NULL}, | ||
| 161 | {bt_hci_cmd_read_local_features, NULL}, | ||
| 162 | {bt_hci_cmd_read_local_version_info, NULL}, | ||
| 163 | {bt_hci_cmd_read_bd_addr, NULL}, | ||
| 164 | {bt_hci_cmd_read_buffer_size, NULL}, | ||
| 165 | {bt_hci_cmd_read_class_of_device, NULL}, | ||
| 166 | {bt_hci_cmd_read_local_name, NULL}, | ||
| 167 | {bt_hci_cmd_read_voice_setting, NULL}, | ||
| 168 | {bt_hci_cmd_read_num_supported_iac, NULL}, | ||
| 169 | {bt_hci_cmd_read_current_iac_lap, NULL}, | ||
| 170 | {bt_hci_cmd_set_event_filter, (void *)&clr_evt_filter}, | ||
| 171 | {bt_hci_cmd_write_conn_accept_timeout, NULL}, | ||
| 172 | {bt_hci_cmd_read_supported_commands, NULL}, | ||
| 173 | {bt_hci_cmd_write_ssp_mode, NULL}, | ||
| 174 | {bt_hci_cmd_write_inquiry_mode, NULL}, | ||
| 175 | {bt_hci_cmd_read_inquiry_rsp_tx_pwr_lvl, NULL}, | ||
| 176 | {bt_hci_cmd_read_local_ext_features, NULL}, | ||
| 177 | {bt_hci_cmd_read_stored_link_key, NULL}, | ||
| 178 | {bt_hci_cmd_read_page_scan_activity, NULL}, | ||
| 179 | {bt_hci_cmd_read_page_scan_type, NULL}, | ||
| 180 | {bt_hci_cmd_write_le_host_supp, NULL}, | ||
| 181 | {bt_hci_cmd_le_read_wl_size, NULL}, | ||
| 182 | {bt_hci_cmd_le_clear_wl, NULL}, | ||
| 183 | {bt_hci_load_le_accept_list, NULL}, | ||
| 184 | {bt_hci_cmd_delete_stored_link_key, NULL}, | ||
| 185 | {bt_hci_cmd_write_class_of_device, NULL}, | ||
| 186 | {bt_hci_cmd_write_local_name, NULL}, | ||
| 187 | {bt_hci_cmd_set_event_filter, (void *)&inquiry_evt_filter}, | ||
| 188 | {bt_hci_cmd_set_event_filter, (void *)&conn_evt_filter}, | ||
| 189 | {bt_hci_cmd_write_auth_enable, NULL}, | ||
| 190 | {bt_hci_cmd_set_event_mask, NULL}, | ||
| 191 | {bt_hci_cmd_write_page_scan_activity, NULL}, | ||
| 192 | {bt_hci_cmd_write_inquiry_scan_activity, NULL}, | ||
| 193 | {bt_hci_cmd_write_page_scan_type, NULL}, | ||
| 194 | {bt_hci_cmd_write_page_scan_timeout, NULL}, | ||
| 195 | {bt_hci_cmd_write_hold_mode_act, NULL}, | ||
| 196 | {bt_hci_cmd_write_scan_enable, NULL}, | ||
| 197 | {bt_hci_cmd_write_default_link_policy, NULL}, | ||
| 198 | #ifdef CONFIG_BLUERETRO_BT_SSP_DBG | ||
| 199 | {bt_hci_cmd_write_ssp_dbg_mode, NULL}, | ||
| 200 | #endif | ||
| 201 | {bt_hci_cmd_le_read_buffer_size, NULL}, | ||
| 202 | {bt_hci_cmd_le_set_adv_param, NULL}, | ||
| 203 | {bt_hci_cmd_le_set_adv_data, NULL}, | ||
| 204 | {bt_hci_cmd_le_set_scan_rsp_data, NULL}, | ||
| 205 | {bt_hci_cmd_le_set_adv_enable, NULL}, | ||
| 206 | {bt_hci_start_inquiry_cfg_check, NULL}, | ||
| 207 | }; | ||
| 208 | |||
| 209 | ✗ | static void bt_hci_q_conf(uint32_t next) { | |
| 210 | ✗ | if (next) { | |
| 211 | ✗ | bt_config_state++; | |
| 212 | } | ||
| 213 | ✗ | if (bt_config_state < ARRAY_SIZE(bt_hci_config)) { | |
| 214 | ✗ | bt_hci_config[bt_config_state].cmd(bt_hci_config[bt_config_state].cp); | |
| 215 | } | ||
| 216 | ✗ | } | |
| 217 | |||
| 218 | ✗ | static void bt_hci_cmd(uint16_t opcode, uint32_t cp_len) { | |
| 219 | ✗ | uint32_t packet_len = BT_HCI_H4_HDR_SIZE + BT_HCI_CMD_HDR_SIZE + cp_len; | |
| 220 | |||
| 221 | ✗ | bt_hci_pkt_tmp.h4_hdr.type = BT_HCI_H4_TYPE_CMD; | |
| 222 | |||
| 223 | ✗ | bt_hci_pkt_tmp.cmd_hdr.opcode = opcode; | |
| 224 | ✗ | bt_hci_pkt_tmp.cmd_hdr.param_len = cp_len; | |
| 225 | |||
| 226 | ✗ | bt_host_txq_add((uint8_t *)&bt_hci_pkt_tmp, packet_len); | |
| 227 | ✗ | } | |
| 228 | |||
| 229 | #if 0 | ||
| 230 | static void bt_hci_cmd_inquiry(void *cp) { | ||
| 231 | struct bt_hci_cp_inquiry *inquiry = (struct bt_hci_cp_inquiry *)&bt_hci_pkt_tmp.cp; | ||
| 232 | printf("# %s\n", __FUNCTION__); | ||
| 233 | |||
| 234 | inquiry->lap[0] = 0x33; | ||
| 235 | inquiry->lap[1] = 0x8B; | ||
| 236 | inquiry->lap[2] = 0x9E; | ||
| 237 | inquiry->length = 0x20; | ||
| 238 | inquiry->num_rsp = 0xFF; | ||
| 239 | |||
| 240 | bt_hci_cmd(BT_HCI_OP_INQUIRY, sizeof(*inquiry)); | ||
| 241 | } | ||
| 242 | |||
| 243 | static void bt_hci_cmd_inquiry_cancel(void *cp) { | ||
| 244 | printf("# %s\n", __FUNCTION__); | ||
| 245 | |||
| 246 | bt_hci_cmd(BT_HCI_OP_INQUIRY_CANCEL, 0); | ||
| 247 | } | ||
| 248 | #endif | ||
| 249 | |||
| 250 | ✗ | static void bt_hci_cmd_periodic_inquiry(void *cp) { | |
| 251 | ✗ | struct bt_hci_cp_periodic_inquiry *periodic_inquiry = (struct bt_hci_cp_periodic_inquiry *)&bt_hci_pkt_tmp.cp; | |
| 252 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 253 | |||
| 254 | ✗ | periodic_inquiry->max_period_length = 0x0A; | |
| 255 | ✗ | periodic_inquiry->min_period_length = 0x08; | |
| 256 | ✗ | periodic_inquiry->lap[0] = 0x33; | |
| 257 | ✗ | periodic_inquiry->lap[1] = 0x8B; | |
| 258 | ✗ | periodic_inquiry->lap[2] = 0x9E; | |
| 259 | ✗ | periodic_inquiry->length = 0x03; /* 0x03 * 1.28 s = 3.84 s */ | |
| 260 | ✗ | periodic_inquiry->num_rsp = 0xFF; | |
| 261 | |||
| 262 | ✗ | bt_hci_cmd(BT_HCI_OP_PERIODIC_INQUIRY, sizeof(*periodic_inquiry)); | |
| 263 | ✗ | } | |
| 264 | |||
| 265 | ✗ | static void bt_hci_cmd_exit_periodic_inquiry(void *cp) { | |
| 266 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 267 | |||
| 268 | ✗ | bt_hci_cmd(BT_HCI_OP_EXIT_PERIODIC_INQUIRY, 0); | |
| 269 | ✗ | } | |
| 270 | |||
| 271 | ✗ | static void bt_hci_cmd_connect(void *bdaddr) { | |
| 272 | ✗ | struct bt_hci_cp_connect *connect = (struct bt_hci_cp_connect *)&bt_hci_pkt_tmp.cp; | |
| 273 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 274 | |||
| 275 | ✗ | memcpy((void *)&connect->bdaddr, bdaddr, sizeof(connect->bdaddr)); | |
| 276 | ✗ | connect->packet_type = 0xCC18; /* DH5, DM5, DH3, DM3, DH1 & DM1 */ | |
| 277 | ✗ | connect->pscan_rep_mode = 0x00; /* R1 */ | |
| 278 | ✗ | connect->reserved = 0x00; | |
| 279 | ✗ | connect->clock_offset = 0x0000; | |
| 280 | ✗ | connect->allow_role_switch = 0x01; | |
| 281 | |||
| 282 | ✗ | bt_hci_cmd(BT_HCI_OP_CONNECT, sizeof(*connect)); | |
| 283 | ✗ | } | |
| 284 | |||
| 285 | ✗ | static void bt_hci_cmd_disconnect(void *handle, uint8_t reason) { | |
| 286 | ✗ | struct bt_hci_cp_disconnect *disconnect = (struct bt_hci_cp_disconnect *)&bt_hci_pkt_tmp.cp; | |
| 287 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 288 | |||
| 289 | ✗ | disconnect->handle = *(uint16_t *)handle; | |
| 290 | ✗ | disconnect->reason = reason; | |
| 291 | |||
| 292 | ✗ | bt_hci_cmd(BT_HCI_OP_DISCONNECT, sizeof(*disconnect)); | |
| 293 | ✗ | } | |
| 294 | |||
| 295 | ✗ | static void bt_hci_cmd_accept_conn_req(void *bdaddr) { | |
| 296 | ✗ | struct bt_hci_cp_accept_conn_req *accept_conn_req = (struct bt_hci_cp_accept_conn_req *)&bt_hci_pkt_tmp.cp; | |
| 297 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 298 | |||
| 299 | ✗ | memcpy((void *)&accept_conn_req->bdaddr, bdaddr, sizeof(accept_conn_req->bdaddr)); | |
| 300 | ✗ | accept_conn_req->role = 0x00; /* Become master */ | |
| 301 | |||
| 302 | ✗ | bt_hci_cmd(BT_HCI_OP_ACCEPT_CONN_REQ, sizeof(*accept_conn_req)); | |
| 303 | ✗ | } | |
| 304 | |||
| 305 | ✗ | static void bt_hci_cmd_link_key_reply(void *cp) { | |
| 306 | ✗ | struct bt_hci_cp_link_key_reply *link_key_reply = (struct bt_hci_cp_link_key_reply *)&bt_hci_pkt_tmp.cp; | |
| 307 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 308 | |||
| 309 | ✗ | memcpy((void *)link_key_reply, cp, sizeof(*link_key_reply)); | |
| 310 | |||
| 311 | ✗ | bt_hci_cmd(BT_HCI_OP_LINK_KEY_REPLY, sizeof(*link_key_reply)); | |
| 312 | ✗ | } | |
| 313 | |||
| 314 | ✗ | static void bt_hci_cmd_link_key_neg_reply(void *bdaddr) { | |
| 315 | ✗ | struct bt_hci_cp_link_key_neg_reply *link_key_neg_reply = (struct bt_hci_cp_link_key_neg_reply *)&bt_hci_pkt_tmp.cp; | |
| 316 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 317 | |||
| 318 | ✗ | memcpy((void *)&link_key_neg_reply->bdaddr, bdaddr, sizeof(link_key_neg_reply->bdaddr)); | |
| 319 | |||
| 320 | ✗ | bt_hci_cmd(BT_HCI_OP_LINK_KEY_NEG_REPLY, sizeof(*link_key_neg_reply)); | |
| 321 | ✗ | } | |
| 322 | |||
| 323 | ✗ | static void bt_hci_cmd_pin_code_reply(void *cp) { | |
| 324 | ✗ | struct bt_hci_cp_pin_code_reply *pin_code_reply = (struct bt_hci_cp_pin_code_reply *)&bt_hci_pkt_tmp.cp; | |
| 325 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 326 | |||
| 327 | ✗ | memcpy((void *)pin_code_reply, cp, sizeof(*pin_code_reply)); | |
| 328 | |||
| 329 | ✗ | bt_hci_cmd(BT_HCI_OP_PIN_CODE_REPLY, sizeof(*pin_code_reply)); | |
| 330 | ✗ | } | |
| 331 | |||
| 332 | #if 0 | ||
| 333 | static void bt_hci_cmd_pin_code_neg_reply(void *bdaddr) { | ||
| 334 | struct bt_hci_cp_pin_code_neg_reply *pin_code_neg_reply = (struct bt_hci_cp_pin_code_neg_reply *)&bt_hci_pkt_tmp.cp; | ||
| 335 | printf("# %s\n", __FUNCTION__); | ||
| 336 | |||
| 337 | memcpy((void *)&pin_code_neg_reply->bdaddr, bdaddr, sizeof(pin_code_neg_reply->bdaddr)); | ||
| 338 | |||
| 339 | bt_hci_cmd(BT_HCI_OP_PIN_CODE_NEG_REPLY, sizeof(*pin_code_neg_reply)); | ||
| 340 | } | ||
| 341 | #endif | ||
| 342 | |||
| 343 | ✗ | static void bt_hci_cmd_auth_requested(void *handle) { | |
| 344 | ✗ | struct bt_hci_cp_auth_requested *auth_requested = (struct bt_hci_cp_auth_requested *)&bt_hci_pkt_tmp.cp; | |
| 345 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 346 | |||
| 347 | ✗ | auth_requested->handle = *(uint16_t *)handle; | |
| 348 | |||
| 349 | ✗ | bt_hci_cmd(BT_HCI_OP_AUTH_REQUESTED, sizeof(*auth_requested)); | |
| 350 | ✗ | } | |
| 351 | |||
| 352 | ✗ | static void bt_hci_cmd_set_conn_encrypt(void *handle) { | |
| 353 | ✗ | struct bt_hci_cp_set_conn_encrypt *set_conn_encrypt = (struct bt_hci_cp_set_conn_encrypt *)&bt_hci_pkt_tmp.cp; | |
| 354 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 355 | |||
| 356 | ✗ | set_conn_encrypt->handle = *(uint16_t *)handle; | |
| 357 | ✗ | set_conn_encrypt->encrypt = 0x01; | |
| 358 | |||
| 359 | ✗ | bt_hci_cmd(BT_HCI_OP_SET_CONN_ENCRYPT, sizeof(*set_conn_encrypt)); | |
| 360 | ✗ | } | |
| 361 | |||
| 362 | ✗ | static void bt_hci_cmd_remote_name_request(void *bdaddr) { | |
| 363 | ✗ | struct bt_hci_cp_remote_name_request *remote_name_request = (struct bt_hci_cp_remote_name_request *)&bt_hci_pkt_tmp.cp; | |
| 364 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 365 | |||
| 366 | ✗ | memcpy((void *)&remote_name_request->bdaddr, bdaddr, sizeof(remote_name_request->bdaddr)); | |
| 367 | ✗ | remote_name_request->pscan_rep_mode = 0x01; /* R1 */ | |
| 368 | ✗ | remote_name_request->reserved = 0x00; | |
| 369 | ✗ | remote_name_request->clock_offset = 0x0000; | |
| 370 | |||
| 371 | ✗ | bt_hci_cmd(BT_HCI_OP_REMOTE_NAME_REQUEST, sizeof(*remote_name_request)); | |
| 372 | ✗ | } | |
| 373 | |||
| 374 | ✗ | static void bt_hci_cmd_read_remote_features(void *handle) { | |
| 375 | ✗ | struct bt_hci_cp_read_remote_features *read_remote_features = (struct bt_hci_cp_read_remote_features *)&bt_hci_pkt_tmp.cp; | |
| 376 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 377 | |||
| 378 | ✗ | read_remote_features->handle = *(uint16_t *)handle; | |
| 379 | |||
| 380 | ✗ | bt_hci_cmd(BT_HCI_OP_READ_REMOTE_FEATURES, sizeof(*read_remote_features)); | |
| 381 | ✗ | } | |
| 382 | |||
| 383 | ✗ | static void bt_hci_cmd_read_remote_ext_features(void *handle) { | |
| 384 | ✗ | struct bt_hci_cp_read_remote_ext_features *read_remote_ext_features = (struct bt_hci_cp_read_remote_ext_features *)&bt_hci_pkt_tmp.cp; | |
| 385 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 386 | |||
| 387 | ✗ | read_remote_ext_features->handle = *(uint16_t *)handle; | |
| 388 | ✗ | read_remote_ext_features->page = 0x01; | |
| 389 | |||
| 390 | ✗ | bt_hci_cmd(BT_HCI_OP_READ_REMOTE_EXT_FEATURES, sizeof(*read_remote_ext_features)); | |
| 391 | ✗ | } | |
| 392 | |||
| 393 | #if 0 | ||
| 394 | static void bt_hci_cmd_read_remote_version_info(uint16_t handle) { | ||
| 395 | struct bt_hci_cp_read_remote_version_info *read_remote_version_info = (struct bt_hci_cp_read_remote_version_info *)&bt_hci_pkt_tmp.cp; | ||
| 396 | printf("# %s\n", __FUNCTION__); | ||
| 397 | |||
| 398 | read_remote_version_info->handle = handle; | ||
| 399 | |||
| 400 | bt_hci_cmd(BT_HCI_OP_READ_REMOTE_VERSION_INFO, sizeof(*read_remote_version_info)); | ||
| 401 | } | ||
| 402 | #endif | ||
| 403 | |||
| 404 | ✗ | static void bt_hci_cmd_io_capability_reply(void *bdaddr) { | |
| 405 | ✗ | struct bt_hci_cp_io_capability_reply *io_capability_reply = (struct bt_hci_cp_io_capability_reply *)&bt_hci_pkt_tmp.cp; | |
| 406 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 407 | |||
| 408 | ✗ | memcpy((void *)&io_capability_reply->bdaddr, bdaddr, sizeof(io_capability_reply->bdaddr)); | |
| 409 | ✗ | io_capability_reply->capability = 0x03; | |
| 410 | ✗ | io_capability_reply->oob_data = 0x00; | |
| 411 | ✗ | io_capability_reply->authentication = 0x00; | |
| 412 | |||
| 413 | ✗ | bt_hci_cmd(BT_HCI_OP_IO_CAPABILITY_REPLY, sizeof(*io_capability_reply)); | |
| 414 | ✗ | } | |
| 415 | |||
| 416 | ✗ | static void bt_hci_cmd_user_confirm_reply(void *bdaddr) { | |
| 417 | ✗ | struct bt_hci_cp_user_confirm_reply *user_confirm_reply = (struct bt_hci_cp_user_confirm_reply *)&bt_hci_pkt_tmp.cp; | |
| 418 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 419 | |||
| 420 | ✗ | memcpy((void *)&user_confirm_reply->bdaddr, bdaddr, sizeof(user_confirm_reply->bdaddr)); | |
| 421 | |||
| 422 | ✗ | bt_hci_cmd(BT_HCI_OP_USER_CONFIRM_REPLY, sizeof(*user_confirm_reply)); | |
| 423 | ✗ | } | |
| 424 | |||
| 425 | ✗ | static void bt_hci_cmd_sniff_mode(void *handle, uint16_t interval) { | |
| 426 | ✗ | struct bt_hci_cp_sniff_mode *sniff_mode = (struct bt_hci_cp_sniff_mode *)&bt_hci_pkt_tmp.cp; | |
| 427 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 428 | |||
| 429 | ✗ | sniff_mode->handle = *(uint16_t *)handle; | |
| 430 | ✗ | sniff_mode->max_interval = interval; | |
| 431 | ✗ | sniff_mode->min_interval = interval; | |
| 432 | ✗ | sniff_mode->attempt = 1; | |
| 433 | ✗ | sniff_mode->timeout = 1; | |
| 434 | |||
| 435 | ✗ | bt_hci_cmd(BT_HCI_OP_SNIFF_MODE, sizeof(*sniff_mode)); | |
| 436 | ✗ | } | |
| 437 | |||
| 438 | ✗ | static void bt_hci_cmd_exit_sniff_mode(void *handle) { | |
| 439 | ✗ | struct bt_hci_cp_exit_sniff_mode *exit_sniff_mode = (struct bt_hci_cp_exit_sniff_mode *)&bt_hci_pkt_tmp.cp; | |
| 440 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 441 | |||
| 442 | ✗ | exit_sniff_mode->handle = *(uint16_t *)handle; | |
| 443 | |||
| 444 | ✗ | bt_hci_cmd(BT_HCI_OP_EXIT_SNIFF_MODE, sizeof(*exit_sniff_mode)); | |
| 445 | ✗ | } | |
| 446 | |||
| 447 | ✗ | static void bt_hci_cmd_switch_role(void *cp) { | |
| 448 | ✗ | struct bt_hci_cp_switch_role *switch_role = (struct bt_hci_cp_switch_role *)&bt_hci_pkt_tmp.cp; | |
| 449 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 450 | |||
| 451 | ✗ | memcpy((void *)switch_role, cp, sizeof(*switch_role)); | |
| 452 | |||
| 453 | ✗ | bt_hci_cmd(BT_HCI_OP_SWITCH_ROLE, sizeof(*switch_role)); | |
| 454 | ✗ | } | |
| 455 | |||
| 456 | #if 0 | ||
| 457 | static void bt_hci_cmd_read_link_policy(void *handle) { | ||
| 458 | struct bt_hci_cp_read_link_policy *read_link_policy = (struct bt_hci_cp_read_link_policy *)&bt_hci_pkt_tmp.cp; | ||
| 459 | printf("# %s\n", __FUNCTION__); | ||
| 460 | |||
| 461 | read_link_policy->handle = *(uint16_t *)handle; | ||
| 462 | |||
| 463 | bt_hci_cmd(BT_HCI_OP_READ_LINK_POLICY, sizeof(*read_link_policy)); | ||
| 464 | } | ||
| 465 | |||
| 466 | static void bt_hci_cmd_write_link_policy(void *cp) { | ||
| 467 | struct bt_hci_cp_write_link_policy *write_link_policy = (struct bt_hci_cp_write_link_policy *)&bt_hci_pkt_tmp.cp; | ||
| 468 | printf("# %s\n", __FUNCTION__); | ||
| 469 | |||
| 470 | memcpy((void *)write_link_policy, cp, sizeof(*write_link_policy)); | ||
| 471 | |||
| 472 | bt_hci_cmd(BT_HCI_OP_WRITE_LINK_POLICY, sizeof(*write_link_policy)); | ||
| 473 | } | ||
| 474 | |||
| 475 | static void bt_hci_cmd_read_default_link_policy(void *cp) { | ||
| 476 | printf("# %s\n", __FUNCTION__); | ||
| 477 | |||
| 478 | bt_hci_cmd(BT_HCI_OP_READ_DEFAULT_LINK_POLICY, 0); | ||
| 479 | } | ||
| 480 | #endif | ||
| 481 | |||
| 482 | ✗ | static void bt_hci_cmd_write_default_link_policy(void *cp) { | |
| 483 | ✗ | struct bt_hci_cp_write_default_link_policy *write_default_link_policy = (struct bt_hci_cp_write_default_link_policy *)&bt_hci_pkt_tmp.cp; | |
| 484 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 485 | |||
| 486 | ✗ | write_default_link_policy->link_policy = 0x000F; | |
| 487 | |||
| 488 | ✗ | bt_hci_cmd(BT_HCI_OP_WRITE_DEFAULT_LINK_POLICY, sizeof(*write_default_link_policy)); | |
| 489 | ✗ | } | |
| 490 | |||
| 491 | ✗ | static void bt_hci_cmd_set_event_mask(void *cp) { | |
| 492 | ✗ | struct bt_hci_cp_set_event_mask *set_event_mask = (struct bt_hci_cp_set_event_mask *)&bt_hci_pkt_tmp.cp; | |
| 493 | ✗ | uint8_t events[8] = {0xff, 0xff, 0xfb, 0xff, 0x07, 0xf8, 0xbf, 0x3d}; | |
| 494 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 495 | |||
| 496 | ✗ | memcpy(set_event_mask->events, events, sizeof(*set_event_mask)); | |
| 497 | |||
| 498 | ✗ | bt_hci_cmd(BT_HCI_OP_SET_EVENT_MASK, sizeof(*set_event_mask)); | |
| 499 | ✗ | } | |
| 500 | |||
| 501 | ✗ | static void bt_hci_cmd_reset(void *cp) { | |
| 502 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 503 | |||
| 504 | ✗ | bt_hci_cmd(BT_HCI_OP_RESET, 0); | |
| 505 | ✗ | } | |
| 506 | |||
| 507 | ✗ | static void bt_hci_cmd_set_event_filter(void *cp) { | |
| 508 | ✗ | struct bt_hci_cp_set_event_filter *set_event_filter = (struct bt_hci_cp_set_event_filter *)&bt_hci_pkt_tmp.cp; | |
| 509 | ✗ | uint32_t len = 1; | |
| 510 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 511 | |||
| 512 | ✗ | memcpy((void *)set_event_filter, cp, sizeof(*set_event_filter)); | |
| 513 | |||
| 514 | ✗ | if (set_event_filter->filter_type == BT_BREDR_FILTER_TYPE_INQUIRY) { | |
| 515 | len += 1; | ||
| 516 | } | ||
| 517 | ✗ | else if (set_event_filter->filter_type == BT_BREDR_FILTER_TYPE_CONN) { | |
| 518 | ✗ | len += 2; | |
| 519 | } | ||
| 520 | ✗ | if (set_event_filter->condition_type) { | |
| 521 | ✗ | len += 6; | |
| 522 | } | ||
| 523 | |||
| 524 | ✗ | bt_hci_cmd(BT_HCI_OP_SET_EVENT_FILTER, len); | |
| 525 | ✗ | } | |
| 526 | |||
| 527 | ✗ | static void bt_hci_cmd_read_stored_link_key(void *cp) { | |
| 528 | ✗ | struct bt_hci_cp_read_stored_link_key *read_stored_link_key = (struct bt_hci_cp_read_stored_link_key *)&bt_hci_pkt_tmp.cp; | |
| 529 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 530 | |||
| 531 | ✗ | memset((void *)&read_stored_link_key->bdaddr, 0, sizeof(read_stored_link_key->bdaddr)); | |
| 532 | ✗ | read_stored_link_key->read_all_flag = 0x01; | |
| 533 | |||
| 534 | ✗ | bt_hci_cmd(BT_HCI_OP_READ_STORED_LINK_KEY, sizeof(*read_stored_link_key)); | |
| 535 | ✗ | } | |
| 536 | |||
| 537 | ✗ | static void bt_hci_cmd_delete_stored_link_key(void *cp) { | |
| 538 | ✗ | struct bt_hci_cp_delete_stored_link_key *delete_stored_link_key = (struct bt_hci_cp_delete_stored_link_key *)&bt_hci_pkt_tmp.cp; | |
| 539 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 540 | |||
| 541 | ✗ | memset((void *)&delete_stored_link_key->bdaddr, 0, sizeof(delete_stored_link_key->bdaddr)); | |
| 542 | ✗ | delete_stored_link_key->delete_all_flag = 0x01; | |
| 543 | |||
| 544 | ✗ | bt_hci_cmd(BT_HCI_OP_DELETE_STORED_LINK_KEY, sizeof(*delete_stored_link_key)); | |
| 545 | ✗ | } | |
| 546 | |||
| 547 | ✗ | static void bt_hci_cmd_write_local_name(void *cp) { | |
| 548 | ✗ | struct bt_hci_cp_write_local_name *write_local_name = (struct bt_hci_cp_write_local_name *)&bt_hci_pkt_tmp.cp; | |
| 549 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 550 | |||
| 551 | ✗ | memset((void *)write_local_name, 0, sizeof(*write_local_name)); | |
| 552 | ✗ | snprintf((char *)write_local_name->local_name, sizeof(write_local_name->local_name), "Nintendo"); | |
| 553 | |||
| 554 | ✗ | bt_hci_cmd(BT_HCI_OP_WRITE_LOCAL_NAME, sizeof(*write_local_name)); | |
| 555 | ✗ | } | |
| 556 | |||
| 557 | ✗ | static void bt_hci_cmd_read_local_name(void *cp) { | |
| 558 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 559 | |||
| 560 | ✗ | bt_hci_cmd(BT_HCI_OP_READ_LOCAL_NAME, 0); | |
| 561 | ✗ | } | |
| 562 | |||
| 563 | ✗ | static void bt_hci_cmd_write_conn_accept_timeout(void *cp) { | |
| 564 | ✗ | struct bt_hci_cp_write_conn_accept_timeout *write_conn_accept_timeout = (struct bt_hci_cp_write_conn_accept_timeout *)&bt_hci_pkt_tmp.cp; | |
| 565 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 566 | |||
| 567 | ✗ | write_conn_accept_timeout->conn_accept_timeout = 0x7d00; | |
| 568 | |||
| 569 | ✗ | bt_hci_cmd(BT_HCI_OP_WRITE_CONN_ACCEPT_TIMEOUT, sizeof(*write_conn_accept_timeout)); | |
| 570 | ✗ | } | |
| 571 | |||
| 572 | ✗ | static void bt_hci_cmd_write_page_scan_timeout(void *cp) { | |
| 573 | ✗ | struct bt_hci_cp_write_page_scan_timeout *write_page_scan_timeout = (struct bt_hci_cp_write_page_scan_timeout *)&bt_hci_pkt_tmp.cp; | |
| 574 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 575 | |||
| 576 | ✗ | write_page_scan_timeout->timeout = 0x2000; | |
| 577 | |||
| 578 | ✗ | bt_hci_cmd(BT_HCI_OP_WRITE_PAGE_TIMEOUT, sizeof(*write_page_scan_timeout)); | |
| 579 | ✗ | } | |
| 580 | |||
| 581 | ✗ | static void bt_hci_cmd_write_scan_enable(void *cp) { | |
| 582 | ✗ | struct bt_hci_cp_write_scan_enable *write_scan_enable = (struct bt_hci_cp_write_scan_enable *)&bt_hci_pkt_tmp.cp; | |
| 583 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 584 | |||
| 585 | ✗ | write_scan_enable->scan_enable = BT_BREDR_SCAN_PAGE; | |
| 586 | |||
| 587 | ✗ | bt_hci_cmd(BT_HCI_OP_WRITE_SCAN_ENABLE, sizeof(*write_scan_enable)); | |
| 588 | ✗ | } | |
| 589 | |||
| 590 | ✗ | static void bt_hci_cmd_write_page_scan_activity(void *cp) { | |
| 591 | ✗ | struct bt_hci_cp_write_page_scan_activity *write_page_scan_activity = (struct bt_hci_cp_write_page_scan_activity *)&bt_hci_pkt_tmp.cp; | |
| 592 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 593 | |||
| 594 | ✗ | write_page_scan_activity->interval = 0x50; | |
| 595 | ✗ | write_page_scan_activity->window = 0x12; | |
| 596 | |||
| 597 | ✗ | bt_hci_cmd(BT_HCI_OP_WRITE_PAGE_SCAN_ACTIVITY, sizeof(*write_page_scan_activity)); | |
| 598 | ✗ | } | |
| 599 | |||
| 600 | ✗ | static void bt_hci_cmd_write_inquiry_scan_activity(void *cp) { | |
| 601 | ✗ | struct bt_hci_cp_write_inquiry_scan_activity *write_inquiry_scan_activity = (struct bt_hci_cp_write_inquiry_scan_activity *)&bt_hci_pkt_tmp.cp; | |
| 602 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 603 | |||
| 604 | ✗ | write_inquiry_scan_activity->interval = 0x50; | |
| 605 | ✗ | write_inquiry_scan_activity->window = 0x12; | |
| 606 | |||
| 607 | ✗ | bt_hci_cmd(BT_HCI_OP_WRITE_INQUIRY_SCAN_ACTIVITY, sizeof(*write_inquiry_scan_activity)); | |
| 608 | ✗ | } | |
| 609 | |||
| 610 | ✗ | static void bt_hci_cmd_write_auth_enable(void *cp) { | |
| 611 | ✗ | struct bt_hci_cp_write_auth_enable *write_auth_enable = (struct bt_hci_cp_write_auth_enable *)&bt_hci_pkt_tmp.cp; | |
| 612 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 613 | |||
| 614 | ✗ | write_auth_enable->auth_enable = 0x00; | |
| 615 | |||
| 616 | ✗ | bt_hci_cmd(BT_HCI_OP_WRITE_AUTH_ENABLE, sizeof(*write_auth_enable)); | |
| 617 | ✗ | } | |
| 618 | |||
| 619 | ✗ | static void bt_hci_cmd_read_page_scan_activity(void *cp) { | |
| 620 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 621 | |||
| 622 | ✗ | bt_hci_cmd(BT_HCI_OP_READ_PAGE_SCAN_ACTIVITY, 0); | |
| 623 | ✗ | } | |
| 624 | |||
| 625 | ✗ | static void bt_hci_cmd_read_class_of_device(void *cp) { | |
| 626 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 627 | |||
| 628 | ✗ | bt_hci_cmd(BT_HCI_OP_READ_CLASS_OF_DEVICE, 0); | |
| 629 | ✗ | } | |
| 630 | |||
| 631 | ✗ | static void bt_hci_cmd_write_class_of_device(void *cp) { | |
| 632 | ✗ | struct bt_hci_cp_write_class_of_device *write_class_of_device = (struct bt_hci_cp_write_class_of_device *)&bt_hci_pkt_tmp.cp; | |
| 633 | ✗ | uint8_t local_class[3] = {0x0c, 0x01, 0x1c}; /* Laptop */ | |
| 634 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 635 | |||
| 636 | ✗ | memcpy((void *)write_class_of_device->dev_class, (void *)local_class, sizeof(local_class)); | |
| 637 | |||
| 638 | ✗ | bt_hci_cmd(BT_HCI_OP_WRITE_CLASS_OF_DEVICE, sizeof(*write_class_of_device)); | |
| 639 | ✗ | } | |
| 640 | |||
| 641 | ✗ | static void bt_hci_cmd_read_voice_setting(void *cp) { | |
| 642 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 643 | |||
| 644 | ✗ | bt_hci_cmd(BT_HCI_OP_READ_VOICE_SETTING, 0); | |
| 645 | ✗ | } | |
| 646 | |||
| 647 | ✗ | static void bt_hci_cmd_write_hold_mode_act(void *cp) { | |
| 648 | ✗ | struct bt_hci_cp_write_hold_mode_act *write_hold_mode_act = (struct bt_hci_cp_write_hold_mode_act *)&bt_hci_pkt_tmp.cp; | |
| 649 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 650 | |||
| 651 | ✗ | write_hold_mode_act->activity = 0x00; | |
| 652 | |||
| 653 | ✗ | bt_hci_cmd(BT_HCI_OP_WRITE_HOLD_MODE_ACT, sizeof(*write_hold_mode_act)); | |
| 654 | ✗ | } | |
| 655 | |||
| 656 | ✗ | static void bt_hci_cmd_write_link_supervision_to(void *handle) { | |
| 657 | ✗ | struct bt_hci_cp_write_link_supervision_to *cp = (struct bt_hci_cp_write_link_supervision_to *)&bt_hci_pkt_tmp.cp; | |
| 658 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 659 | |||
| 660 | ✗ | cp->handle = *(uint16_t *)handle; | |
| 661 | ✗ | cp->timeout = 3200; | |
| 662 | |||
| 663 | ✗ | bt_hci_cmd(BT_HCI_OP_WRITE_LINK_SUPERVISION_TO, sizeof(*cp)); | |
| 664 | ✗ | } | |
| 665 | |||
| 666 | ✗ | static void bt_hci_cmd_read_num_supported_iac(void *cp) { | |
| 667 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 668 | |||
| 669 | ✗ | bt_hci_cmd(BT_HCI_OP_READ_NUM_SUPPORTED_IAC, 0); | |
| 670 | ✗ | } | |
| 671 | |||
| 672 | ✗ | static void bt_hci_cmd_read_current_iac_lap(void *cp) { | |
| 673 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 674 | |||
| 675 | ✗ | bt_hci_cmd(BT_HCI_OP_READ_CURRENT_IAC_LAP, 0); | |
| 676 | ✗ | } | |
| 677 | |||
| 678 | ✗ | static void bt_hci_cmd_write_inquiry_mode(void *cp) { | |
| 679 | ✗ | struct bt_hci_cp_write_inquiry_mode *write_inquiry_mode = (struct bt_hci_cp_write_inquiry_mode *)&bt_hci_pkt_tmp.cp; | |
| 680 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 681 | |||
| 682 | ✗ | write_inquiry_mode->mode = 0x02; | |
| 683 | |||
| 684 | ✗ | bt_hci_cmd(BT_HCI_OP_WRITE_INQUIRY_MODE, sizeof(*write_inquiry_mode)); | |
| 685 | ✗ | } | |
| 686 | |||
| 687 | ✗ | static void bt_hci_cmd_read_page_scan_type(void *cp) { | |
| 688 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 689 | |||
| 690 | ✗ | bt_hci_cmd(BT_HCI_OP_READ_PAGE_SCAN_TYPE, 0); | |
| 691 | ✗ | } | |
| 692 | |||
| 693 | ✗ | static void bt_hci_cmd_write_page_scan_type(void *cp) { | |
| 694 | ✗ | struct bt_hci_cp_write_page_scan_type *write_page_scan_type = (struct bt_hci_cp_write_page_scan_type *)&bt_hci_pkt_tmp.cp; | |
| 695 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 696 | |||
| 697 | ✗ | write_page_scan_type->type = 0x01; | |
| 698 | |||
| 699 | ✗ | bt_hci_cmd(BT_HCI_OP_WRITE_PAGE_SCAN_TYPE, sizeof(*write_page_scan_type)); | |
| 700 | ✗ | } | |
| 701 | |||
| 702 | ✗ | static void bt_hci_cmd_write_ssp_mode(void *cp) { | |
| 703 | ✗ | struct bt_hci_cp_write_ssp_mode *write_ssp_mode = (struct bt_hci_cp_write_ssp_mode *)&bt_hci_pkt_tmp.cp; | |
| 704 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 705 | |||
| 706 | ✗ | write_ssp_mode->mode = 0x01; | |
| 707 | |||
| 708 | ✗ | bt_hci_cmd(BT_HCI_OP_WRITE_SSP_MODE, sizeof(*write_ssp_mode)); | |
| 709 | ✗ | } | |
| 710 | |||
| 711 | ✗ | static void bt_hci_cmd_read_inquiry_rsp_tx_pwr_lvl(void *cp) { | |
| 712 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 713 | |||
| 714 | ✗ | bt_hci_cmd(BT_HCI_OP_READ_INQUIRY_RSP_TX_PWR_LVL, 0); | |
| 715 | ✗ | } | |
| 716 | |||
| 717 | ✗ | static void bt_hci_cmd_write_le_host_supp(void *cp) { | |
| 718 | ✗ | struct bt_hci_cp_write_le_host_supp *write_le_host_supp = (struct bt_hci_cp_write_le_host_supp *)&bt_hci_pkt_tmp.cp; | |
| 719 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 720 | |||
| 721 | ✗ | write_le_host_supp->le = 0x01; | |
| 722 | ✗ | write_le_host_supp->simul = 0x00; | |
| 723 | |||
| 724 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_WRITE_LE_HOST_SUPP, sizeof(*write_le_host_supp)); | |
| 725 | ✗ | } | |
| 726 | |||
| 727 | ✗ | static void bt_hci_cmd_read_local_version_info(void *cp) { | |
| 728 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 729 | |||
| 730 | ✗ | bt_hci_cmd(BT_HCI_OP_READ_LOCAL_VERSION_INFO, 0); | |
| 731 | ✗ | } | |
| 732 | |||
| 733 | ✗ | static void bt_hci_cmd_read_supported_commands(void *cp) { | |
| 734 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 735 | |||
| 736 | ✗ | bt_hci_cmd(BT_HCI_OP_READ_SUPPORTED_COMMANDS, 0); | |
| 737 | ✗ | } | |
| 738 | |||
| 739 | ✗ | static void bt_hci_cmd_read_local_features(void *cp) { | |
| 740 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 741 | |||
| 742 | ✗ | bt_hci_cmd(BT_HCI_OP_READ_LOCAL_FEATURES, 0); | |
| 743 | ✗ | } | |
| 744 | |||
| 745 | ✗ | static void bt_hci_cmd_read_local_ext_features(void *cp) { | |
| 746 | ✗ | struct bt_hci_cp_read_local_ext_features *read_local_ext_features = (struct bt_hci_cp_read_local_ext_features *)&bt_hci_pkt_tmp.cp; | |
| 747 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 748 | |||
| 749 | ✗ | read_local_ext_features->page = 0x01; | |
| 750 | |||
| 751 | ✗ | bt_hci_cmd(BT_HCI_OP_READ_LOCAL_EXT_FEATURES, sizeof(*read_local_ext_features)); | |
| 752 | ✗ | } | |
| 753 | |||
| 754 | ✗ | static void bt_hci_cmd_read_buffer_size(void *cp) { | |
| 755 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 756 | |||
| 757 | ✗ | bt_hci_cmd(BT_HCI_OP_READ_BUFFER_SIZE, 0); | |
| 758 | ✗ | } | |
| 759 | |||
| 760 | ✗ | static void bt_hci_cmd_read_bd_addr(void *cp) { | |
| 761 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 762 | |||
| 763 | ✗ | bt_hci_cmd(BT_HCI_OP_READ_BD_ADDR, 0); | |
| 764 | ✗ | } | |
| 765 | |||
| 766 | #if 0 | ||
| 767 | static void bt_hci_cmd_read_data_block_size(void *cp) { | ||
| 768 | printf("# %s\n", __FUNCTION__); | ||
| 769 | |||
| 770 | bt_hci_cmd(BT_HCI_OP_READ_DATA_BLOCK_SIZE, 0); | ||
| 771 | } | ||
| 772 | |||
| 773 | static void bt_hci_cmd_read_local_codecs(void *cp) { | ||
| 774 | printf("# %s\n", __FUNCTION__); | ||
| 775 | |||
| 776 | bt_hci_cmd(BT_HCI_OP_READ_LOCAL_CODECS, 0); | ||
| 777 | } | ||
| 778 | |||
| 779 | static void bt_hci_cmd_read_local_sp_options(void *cp) { | ||
| 780 | printf("# %s\n", __FUNCTION__); | ||
| 781 | |||
| 782 | bt_hci_cmd(BT_HCI_OP_READ_LOCAL_SP_OPTIONS, 0); | ||
| 783 | } | ||
| 784 | #endif | ||
| 785 | |||
| 786 | #ifdef CONFIG_BLUERETRO_BT_SSP_DBG | ||
| 787 | static void bt_hci_cmd_write_ssp_dbg_mode(void *cp) { | ||
| 788 | struct bt_hci_cp_write_ssp_dbg_mode *write_ssp_dbg_mode = (struct bt_hci_cp_write_ssp_dbg_mode *)&bt_hci_pkt_tmp.cp; | ||
| 789 | printf("# %s\n", __FUNCTION__); | ||
| 790 | |||
| 791 | write_ssp_dbg_mode->mode = 0x01; | ||
| 792 | |||
| 793 | bt_hci_cmd(BT_HCI_OP_WRITE_SSP_DBG_MODE, sizeof(*write_ssp_dbg_mode)); | ||
| 794 | } | ||
| 795 | #endif | ||
| 796 | |||
| 797 | ✗ | static void bt_hci_cmd_le_read_buffer_size(void *cp) { | |
| 798 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 799 | |||
| 800 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_READ_BUFFER_SIZE, 0); | |
| 801 | ✗ | } | |
| 802 | |||
| 803 | ✗ | static void bt_hci_cmd_le_set_adv_param(void *cp) { | |
| 804 | ✗ | struct bt_hci_cp_le_set_adv_param *le_set_adv_param = (struct bt_hci_cp_le_set_adv_param *)&bt_hci_pkt_tmp.cp; | |
| 805 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 806 | |||
| 807 | ✗ | le_set_adv_param->min_interval = 0x00A0; | |
| 808 | ✗ | le_set_adv_param->max_interval = 0x00A0; | |
| 809 | ✗ | le_set_adv_param->type = 0x00; | |
| 810 | ✗ | le_set_adv_param->own_addr_type = 0x00; | |
| 811 | ✗ | memset((void *)&le_set_adv_param->direct_addr, 0, sizeof(le_set_adv_param->direct_addr)); | |
| 812 | ✗ | le_set_adv_param->channel_map = 0x07; | |
| 813 | ✗ | le_set_adv_param->filter_policy = 0x00; | |
| 814 | |||
| 815 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_SET_ADV_PARAM, sizeof(*le_set_adv_param)); | |
| 816 | ✗ | } | |
| 817 | |||
| 818 | ✗ | static void bt_hci_cmd_le_set_adv_data(void *cp) { | |
| 819 | ✗ | uint8_t adv_data[32] = { | |
| 820 | 0x02, BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR), | ||
| 821 | 0x03, BT_DATA_UUID16_SOME, 0x0f, 0x18, | ||
| 822 | 0x0a, BT_DATA_NAME_COMPLETE, 0x00 | ||
| 823 | }; | ||
| 824 | ✗ | struct bt_hci_cp_le_set_adv_data *le_set_adv_data = (struct bt_hci_cp_le_set_adv_data *)&bt_hci_pkt_tmp.cp; | |
| 825 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 826 | |||
| 827 | ✗ | adv_data[7] = strlen(bt_hci_get_device_name()) + 1; | |
| 828 | ✗ | strncat((char *)adv_data, bt_hci_get_device_name(), 22); | |
| 829 | |||
| 830 | ✗ | memset(le_set_adv_data->data, 0, sizeof(le_set_adv_data->data)); | |
| 831 | ✗ | le_set_adv_data->len = strlen((char *)adv_data); | |
| 832 | ✗ | memcpy(le_set_adv_data->data, adv_data, strlen((char *)adv_data)); | |
| 833 | |||
| 834 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_SET_ADV_DATA, sizeof(*le_set_adv_data)); | |
| 835 | ✗ | } | |
| 836 | |||
| 837 | ✗ | static void bt_hci_cmd_le_set_scan_rsp_data(void *cp) { | |
| 838 | ✗ | uint8_t scan_rsp[] = { | |
| 839 | 0x11, BT_DATA_UUID128_ALL, 0x56, 0x9a, 0x79, 0x76, 0xa1, 0x2f, 0x4b, 0x31, 0xb0, 0xfa, 0x80, 0x51, 0x56, 0x0f, 0x83, 0x00 | ||
| 840 | }; | ||
| 841 | ✗ | struct bt_hci_cp_le_set_scan_rsp_data *le_set_scan_rsp_data = (struct bt_hci_cp_le_set_scan_rsp_data *)&bt_hci_pkt_tmp.cp; | |
| 842 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 843 | |||
| 844 | ✗ | memset(le_set_scan_rsp_data->data, 0, sizeof(le_set_scan_rsp_data->data)); | |
| 845 | ✗ | le_set_scan_rsp_data->len = sizeof(scan_rsp); | |
| 846 | ✗ | memcpy(le_set_scan_rsp_data->data, scan_rsp, sizeof(scan_rsp)); | |
| 847 | |||
| 848 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_SET_SCAN_RSP_DATA, sizeof(*le_set_scan_rsp_data)); | |
| 849 | ✗ | } | |
| 850 | |||
| 851 | ✗ | static void bt_hci_cmd_le_set_adv_enable(void *cp) { | |
| 852 | ✗ | struct bt_hci_cp_le_set_adv_enable *le_set_adv_enable = (struct bt_hci_cp_le_set_adv_enable *)&bt_hci_pkt_tmp.cp; | |
| 853 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 854 | |||
| 855 | ✗ | le_set_adv_enable->enable = 0x01; | |
| 856 | |||
| 857 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_SET_ADV_ENABLE, sizeof(*le_set_adv_enable)); | |
| 858 | ✗ | } | |
| 859 | |||
| 860 | ✗ | static void bt_hci_cmd_le_set_adv_disable(void *cp) { | |
| 861 | ✗ | struct bt_hci_cp_le_set_adv_enable *le_set_adv_enable = (struct bt_hci_cp_le_set_adv_enable *)&bt_hci_pkt_tmp.cp; | |
| 862 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 863 | |||
| 864 | ✗ | le_set_adv_enable->enable = 0x00; | |
| 865 | |||
| 866 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_SET_ADV_ENABLE, sizeof(*le_set_adv_enable)); | |
| 867 | ✗ | } | |
| 868 | |||
| 869 | ✗ | static void bt_hci_cmd_le_set_scan_param_active(void) { | |
| 870 | ✗ | struct bt_hci_cp_le_set_scan_param *le_set_scan_param = (struct bt_hci_cp_le_set_scan_param *)&bt_hci_pkt_tmp.cp; | |
| 871 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 872 | |||
| 873 | ✗ | le_set_scan_param->scan_type = BT_HCI_LE_SCAN_ACTIVE; | |
| 874 | ✗ | le_set_scan_param->interval = 36; | |
| 875 | ✗ | le_set_scan_param->window = 18; | |
| 876 | ✗ | le_set_scan_param->addr_type = 0x00; | |
| 877 | ✗ | le_set_scan_param->filter_policy = 0x00; | |
| 878 | |||
| 879 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_SET_SCAN_PARAM, sizeof(*le_set_scan_param)); | |
| 880 | ✗ | } | |
| 881 | |||
| 882 | ✗ | static void bt_hci_cmd_le_set_scan_param_passive(void) { | |
| 883 | ✗ | struct bt_hci_cp_le_set_scan_param *le_set_scan_param = (struct bt_hci_cp_le_set_scan_param *)&bt_hci_pkt_tmp.cp; | |
| 884 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 885 | |||
| 886 | ✗ | le_set_scan_param->scan_type = BT_HCI_LE_SCAN_PASSIVE; | |
| 887 | ✗ | le_set_scan_param->interval = 1024; | |
| 888 | ✗ | le_set_scan_param->window = 18; | |
| 889 | ✗ | le_set_scan_param->addr_type = 0x00; | |
| 890 | ✗ | le_set_scan_param->filter_policy = 0x01; | |
| 891 | |||
| 892 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_SET_SCAN_PARAM, sizeof(*le_set_scan_param)); | |
| 893 | ✗ | } | |
| 894 | |||
| 895 | ✗ | static void bt_hci_cmd_le_set_scan_enable(uint32_t enable) { | |
| 896 | ✗ | struct bt_hci_cp_le_set_scan_enable *le_set_scan_enable = (struct bt_hci_cp_le_set_scan_enable *)&bt_hci_pkt_tmp.cp; | |
| 897 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 898 | |||
| 899 | ✗ | le_set_scan_enable->enable = enable; | |
| 900 | ✗ | le_set_scan_enable->filter_dup = 0x01; | |
| 901 | |||
| 902 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_SET_SCAN_ENABLE, sizeof(*le_set_scan_enable)); | |
| 903 | ✗ | } | |
| 904 | |||
| 905 | ✗ | static void bt_hci_cmd_le_create_conn(void *bdaddr_le) { | |
| 906 | ✗ | struct bt_hci_cp_le_create_conn *le_create_conn = (struct bt_hci_cp_le_create_conn *)&bt_hci_pkt_tmp.cp; | |
| 907 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 908 | |||
| 909 | ✗ | memcpy((void *)&le_create_conn->peer_addr, bdaddr_le, sizeof(le_create_conn->peer_addr)); | |
| 910 | |||
| 911 | ✗ | le_create_conn->scan_interval = 18; | |
| 912 | ✗ | le_create_conn->scan_window = 18; | |
| 913 | ✗ | le_create_conn->filter_policy = 0x00; | |
| 914 | ✗ | le_create_conn->own_addr_type = 0x00; | |
| 915 | ✗ | le_create_conn->conn_interval_min = 6; | |
| 916 | ✗ | le_create_conn->conn_interval_max = 12; | |
| 917 | ✗ | le_create_conn->conn_latency = 0; | |
| 918 | ✗ | le_create_conn->supervision_timeout = 300; | |
| 919 | ✗ | le_create_conn->min_ce_len = 0; | |
| 920 | ✗ | le_create_conn->max_ce_len = 0; | |
| 921 | |||
| 922 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_CREATE_CONN, sizeof(*le_create_conn)); | |
| 923 | ✗ | } | |
| 924 | |||
| 925 | ✗ | static void bt_hci_cmd_le_read_wl_size(void *cp) { | |
| 926 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 927 | |||
| 928 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_READ_WL_SIZE, 0); | |
| 929 | ✗ | } | |
| 930 | |||
| 931 | ✗ | static void bt_hci_cmd_le_clear_wl(void *cp) { | |
| 932 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 933 | |||
| 934 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_CLEAR_WL, 0); | |
| 935 | ✗ | } | |
| 936 | |||
| 937 | ✗ | static void bt_hci_cmd_le_add_dev_to_wl(void *bdaddr_le) { | |
| 938 | ✗ | struct bt_hci_cp_le_add_dev_to_wl *le_add_dev_to_wl = (struct bt_hci_cp_le_add_dev_to_wl *)&bt_hci_pkt_tmp.cp; | |
| 939 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 940 | |||
| 941 | ✗ | memcpy((void *)&le_add_dev_to_wl->addr, bdaddr_le, sizeof(le_add_dev_to_wl->addr)); | |
| 942 | |||
| 943 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_ADD_DEV_TO_WL, sizeof(*le_add_dev_to_wl)); | |
| 944 | ✗ | } | |
| 945 | |||
| 946 | ✗ | static void bt_hci_cmd_le_conn_update(struct hci_cp_le_conn_update *cp) { | |
| 947 | ✗ | struct hci_cp_le_conn_update *le_conn_update = (struct hci_cp_le_conn_update *)&bt_hci_pkt_tmp.cp; | |
| 948 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 949 | |||
| 950 | ✗ | memcpy((uint8_t *)le_conn_update, (uint8_t *)cp, sizeof(*le_conn_update)); | |
| 951 | |||
| 952 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_CONN_UPDATE, sizeof(*le_conn_update)); | |
| 953 | ✗ | } | |
| 954 | |||
| 955 | #if 0 | ||
| 956 | static void bt_hci_cmd_le_read_remote_features(uint16_t handle) { | ||
| 957 | struct bt_hci_cp_le_read_remote_features *le_read_remote_features = | ||
| 958 | (struct bt_hci_cp_le_read_remote_features *)&bt_hci_pkt_tmp.cp; | ||
| 959 | printf("# %s\n", __FUNCTION__); | ||
| 960 | |||
| 961 | le_read_remote_features->handle = handle; | ||
| 962 | |||
| 963 | bt_hci_cmd(BT_HCI_OP_LE_READ_REMOTE_FEATURES, sizeof(*le_read_remote_features)); | ||
| 964 | } | ||
| 965 | #endif | ||
| 966 | |||
| 967 | ✗ | static void bt_hci_cmd_le_encrypt(const uint8_t *key, uint8_t *plaintext) { | |
| 968 | ✗ | struct bt_hci_cp_le_encrypt *le_encrypt = (struct bt_hci_cp_le_encrypt *)&bt_hci_pkt_tmp.cp; | |
| 969 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 970 | |||
| 971 | ✗ | memcpy((void *)&le_encrypt->key, key, sizeof(le_encrypt->key)); | |
| 972 | ✗ | memcpy((void *)&le_encrypt->plaintext, plaintext, sizeof(le_encrypt->plaintext)); | |
| 973 | |||
| 974 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_ENCRYPT, sizeof(*le_encrypt)); | |
| 975 | ✗ | } | |
| 976 | |||
| 977 | ✗ | static void bt_hci_cmd_le_rand(void) { | |
| 978 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 979 | |||
| 980 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_RAND, 0); | |
| 981 | ✗ | } | |
| 982 | |||
| 983 | ✗ | static void bt_hci_cmd_le_start_encryption(uint16_t handle, uint64_t rand, uint16_t ediv, uint8_t *ltk) { | |
| 984 | ✗ | struct bt_hci_cp_le_start_encryption *le_start_encryption = (struct bt_hci_cp_le_start_encryption *)&bt_hci_pkt_tmp.cp; | |
| 985 | ✗ | printf("# %s\n", __FUNCTION__); | |
| 986 | |||
| 987 | ✗ | le_start_encryption->handle = handle; | |
| 988 | ✗ | le_start_encryption->rand = rand; | |
| 989 | ✗ | le_start_encryption->ediv = ediv; | |
| 990 | ✗ | memcpy((void *)&le_start_encryption->ltk, ltk, sizeof(le_start_encryption->ltk)); | |
| 991 | |||
| 992 | ✗ | bt_hci_cmd(BT_HCI_OP_LE_START_ENCRYPTION, sizeof(*le_start_encryption)); | |
| 993 | ✗ | } | |
| 994 | |||
| 995 | #if 0 | ||
| 996 | static void bt_hci_cmd_le_set_ext_scan_param(void *cp) { | ||
| 997 | struct bt_hci_cp_le_set_ext_scan_param *le_set_ext_scan_param = (struct bt_hci_cp_le_set_ext_scan_param *)&bt_hci_pkt_tmp.cp; | ||
| 998 | printf("# %s\n", __FUNCTION__); | ||
| 999 | |||
| 1000 | le_set_ext_scan_param->own_addr_type = 0x01; | ||
| 1001 | le_set_ext_scan_param->filter_policy = 0x00; | ||
| 1002 | le_set_ext_scan_param->phys = BT_HCI_LE_EXT_SCAN_PHY_1M; | ||
| 1003 | le_set_ext_scan_param->p[0].type = 0x01; | ||
| 1004 | le_set_ext_scan_param->p[0].interval = 6553; | ||
| 1005 | le_set_ext_scan_param->p[0].window = 1638; | ||
| 1006 | |||
| 1007 | bt_hci_cmd(BT_HCI_OP_LE_SET_EXT_SCAN_PARAM, sizeof(*le_set_ext_scan_param) - sizeof(le_set_ext_scan_param->p) + sizeof(*le_set_ext_scan_param->p)); | ||
| 1008 | } | ||
| 1009 | |||
| 1010 | static void bt_hci_cmd_le_set_ext_scan_enable(void *cp) { | ||
| 1011 | struct bt_hci_cp_le_set_ext_scan_enable *le_set_ext_scan_enable = (struct bt_hci_cp_le_set_ext_scan_enable *)&bt_hci_pkt_tmp.cp; | ||
| 1012 | printf("# %s\n", __FUNCTION__); | ||
| 1013 | |||
| 1014 | le_set_ext_scan_enable->enable = (uint32_t)cp; | ||
| 1015 | le_set_ext_scan_enable->filter_dup = 0x01; | ||
| 1016 | le_set_ext_scan_enable->duration = 0x00; | ||
| 1017 | le_set_ext_scan_enable->period = 0x00; | ||
| 1018 | |||
| 1019 | bt_hci_cmd(BT_HCI_OP_LE_SET_EXT_SCAN_ENABLE, sizeof(*le_set_ext_scan_enable)); | ||
| 1020 | } | ||
| 1021 | #endif | ||
| 1022 | |||
| 1023 | ✗ | static void bt_hci_le_meta_evt_hdlr(struct bt_hci_pkt *bt_hci_evt_pkt) { | |
| 1024 | ✗ | struct bt_hci_evt_le_meta_event *le_meta_event = (struct bt_hci_evt_le_meta_event *)bt_hci_evt_pkt->evt_data; | |
| 1025 | ✗ | struct bt_dev *device = NULL; | |
| 1026 | |||
| 1027 | ✗ | switch (le_meta_event->subevent) { | |
| 1028 | ✗ | case BT_HCI_EVT_LE_CONN_COMPLETE: | |
| 1029 | case BT_HCI_EVT_LE_ENH_CONN_COMPLETE: | ||
| 1030 | { | ||
| 1031 | ✗ | struct bt_hci_evt_le_conn_complete *le_conn_complete = | |
| 1032 | ✗ | (struct bt_hci_evt_le_conn_complete *)(bt_hci_evt_pkt->evt_data + sizeof(struct bt_hci_evt_le_meta_event)); | |
| 1033 | ✗ | printf("# BT_HCI_EVT_LE_CONN_COMPLETE\n"); | |
| 1034 | ✗ | bt_host_get_dev_from_bdaddr(le_conn_complete->peer_addr.a.val, &device); | |
| 1035 | ✗ | if (device) { | |
| 1036 | ✗ | if (le_conn_complete->status) { | |
| 1037 | ✗ | device->pkt_retry++; | |
| 1038 | ✗ | printf("# dev: %ld error: 0x%02X\n", device->ids.id, le_conn_complete->status); | |
| 1039 | ✗ | if (!atomic_test_bit(&device->flags, BT_DEV_PAGE) && device->pkt_retry < BT_MAX_RETRY) { | |
| 1040 | ✗ | bt_hci_cmd_le_create_conn((void *)&le_conn_complete->peer_addr); | |
| 1041 | } | ||
| 1042 | else { | ||
| 1043 | ✗ | bt_host_reset_dev(device); | |
| 1044 | ✗ | if (config.global_cfg.inquiry_mode == INQ_AUTO && bt_host_get_active_dev(&device) == BT_NONE) { | |
| 1045 | ✗ | bt_hci_start_inquiry();; | |
| 1046 | } | ||
| 1047 | else { | ||
| 1048 | ✗ | bt_hci_cmd_le_set_scan_enable(0); | |
| 1049 | ✗ | bt_hci_cmd_le_set_scan_param_passive(); | |
| 1050 | ✗ | bt_hci_cmd_le_set_scan_enable(1); | |
| 1051 | } | ||
| 1052 | } | ||
| 1053 | } | ||
| 1054 | else { | ||
| 1055 | ✗ | struct bt_smp_encrypt_info encrypt_info = {0}; | |
| 1056 | ✗ | struct bt_smp_master_ident master_ident = {0}; | |
| 1057 | ✗ | bt_nb_inquiry = BT_INQUIRY_MAX; | |
| 1058 | ✗ | device->acl_handle = le_conn_complete->handle; | |
| 1059 | ✗ | device->pkt_retry = 0; | |
| 1060 | ✗ | printf("dev: %ld acl_handle: 0x%04X\n", device->ids.id, device->acl_handle); | |
| 1061 | ✗ | bt_mon_log(true, "dev: %ld acl_handle: 0x%04X\n", device->ids.id, device->acl_handle); | |
| 1062 | ✗ | atomic_set_bit(&device->flags, BT_DEV_IS_BLE); | |
| 1063 | ✗ | if (bt_host_load_le_ltk(&device->le_remote_bdaddr, &encrypt_info, &master_ident) == 0) { | |
| 1064 | ✗ | bt_hci_start_encryption(device->acl_handle, *(uint64_t *)master_ident.rand, *(uint16_t *)master_ident.ediv, encrypt_info.ltk); | |
| 1065 | } | ||
| 1066 | else { | ||
| 1067 | ✗ | bt_smp_pairing_start(device); | |
| 1068 | } | ||
| 1069 | ✗ | bt_hci_cmd_le_set_scan_enable(0); | |
| 1070 | ✗ | bt_hci_cmd_le_set_scan_param_active(); | |
| 1071 | ✗ | bt_hci_cmd_le_set_scan_enable(1); | |
| 1072 | } | ||
| 1073 | } | ||
| 1074 | else { | ||
| 1075 | ✗ | bt_host_get_dev_conf(&device); | |
| 1076 | |||
| 1077 | ✗ | if (!le_conn_complete->status && !atomic_test_bit(&device->flags, BT_DEV_DEVICE_FOUND)) { | |
| 1078 | ✗ | atomic_set_bit(&device->flags, BT_DEV_DEVICE_FOUND); | |
| 1079 | ✗ | device->acl_handle = le_conn_complete->handle; | |
| 1080 | } | ||
| 1081 | else { | ||
| 1082 | ✗ | printf("# dev NULL!\n"); | |
| 1083 | } | ||
| 1084 | } | ||
| 1085 | break; | ||
| 1086 | } | ||
| 1087 | ✗ | case BT_HCI_EVT_LE_ADVERTISING_REPORT: | |
| 1088 | { | ||
| 1089 | ✗ | struct bt_hci_evt_le_advertising_report *le_adv_report = | |
| 1090 | ✗ | (struct bt_hci_evt_le_advertising_report *)(bt_hci_evt_pkt->evt_data + sizeof(struct bt_hci_evt_le_meta_event)); | |
| 1091 | ✗ | uint8_t *data = le_adv_report->adv_info[0].data; | |
| 1092 | ✗ | uint8_t *end = data + le_adv_report->adv_info[0].length; | |
| 1093 | ✗ | uint8_t len, type; | |
| 1094 | ✗ | uint16_t value; | |
| 1095 | |||
| 1096 | ✗ | printf("# BT_HCI_EVT_LE_ADVERTISING_REPORT\n"); | |
| 1097 | |||
| 1098 | ✗ | if (le_adv_report->adv_info[0].evt_type == BT_LE_ADV_IND) { | |
| 1099 | ✗ | if (bt_host_load_le_ltk(&le_adv_report->adv_info[0].addr, NULL, NULL) == 0) { | |
| 1100 | ✗ | goto connect; | |
| 1101 | } | ||
| 1102 | } | ||
| 1103 | ✗ | if (le_adv_report->adv_info[0].evt_type == BT_LE_ADV_DIRECT_IND) { | |
| 1104 | ✗ | goto connect; | |
| 1105 | } | ||
| 1106 | |||
| 1107 | /* Filter HID device */ | ||
| 1108 | ✗ | while (data < end) { | |
| 1109 | ✗ | len = *data++; | |
| 1110 | ✗ | type = *data; | |
| 1111 | ✗ | switch (type) { | |
| 1112 | ✗ | case BT_DATA_GAP_APPEARANCE: | |
| 1113 | /* HID category */ | ||
| 1114 | ✗ | value = *(uint16_t *)&data[1]; | |
| 1115 | ✗ | if ((value >> 6) == 0x00F && (value & 0x3F) > 0 && (value & 0x3F) < 5) { | |
| 1116 | ✗ | goto connect; | |
| 1117 | } | ||
| 1118 | else { | ||
| 1119 | ✗ | goto skip; | |
| 1120 | } | ||
| 1121 | ✗ | break; | |
| 1122 | ✗ | case BT_DATA_MANUFACTURER_DATA: | |
| 1123 | /* Manufacturer Specific Data */ | ||
| 1124 | ✗ | value = *(uint16_t *)&data[1]; | |
| 1125 | ✗ | if (value == 0x0553) { | |
| 1126 | ✗ | uint16_t vid = *(uint16_t *)&data[6]; | |
| 1127 | ✗ | if (vid == 0x057e) { | |
| 1128 | ✗ | goto connect; | |
| 1129 | } | ||
| 1130 | } | ||
| 1131 | break; | ||
| 1132 | } | ||
| 1133 | ✗ | data += len; | |
| 1134 | } | ||
| 1135 | ✗ | goto skip; | |
| 1136 | ✗ | connect: | |
| 1137 | ✗ | bt_host_get_dev_from_bdaddr(le_adv_report->adv_info[0].addr.a.val, &device); | |
| 1138 | ✗ | if (device == NULL) { | |
| 1139 | ✗ | (void)bt_host_get_new_dev(&device); | |
| 1140 | ✗ | if (device) { | |
| 1141 | ✗ | bt_host_reset_dev(device); | |
| 1142 | ✗ | memcpy((uint8_t *)&device->le_remote_bdaddr, (uint8_t *)&le_adv_report->adv_info[0].addr, sizeof(device->le_remote_bdaddr)); | |
| 1143 | ✗ | device->ids.type = BT_HID_GENERIC; | |
| 1144 | ✗ | bt_l2cap_init_dev_scid(device); | |
| 1145 | ✗ | atomic_set_bit(&device->flags, BT_DEV_DEVICE_FOUND); | |
| 1146 | ✗ | bt_hci_cmd_le_set_scan_enable(0); | |
| 1147 | ✗ | bt_hci_cmd_le_set_adv_disable(NULL); | |
| 1148 | ✗ | bt_hci_cmd_le_create_conn((void *)&le_adv_report->adv_info[0].addr); | |
| 1149 | ✗ | printf("LE ADV dev: %ld type: %ld bdaddr: %02X - %02X:%02X:%02X:%02X:%02X:%02X\n", device->ids.id, device->ids.type, device->le_remote_bdaddr.type, | |
| 1150 | ✗ | device->remote_bdaddr[5], device->remote_bdaddr[4], device->remote_bdaddr[3], | |
| 1151 | ✗ | device->remote_bdaddr[2], device->remote_bdaddr[1], device->remote_bdaddr[0]); | |
| 1152 | ✗ | bt_mon_log(true, "LE ADV dev: %ld type: %ld bdaddr: %02X - %02X:%02X:%02X:%02X:%02X:%02X\n", device->ids.id, device->ids.type, device->le_remote_bdaddr.type, | |
| 1153 | ✗ | device->remote_bdaddr[5], device->remote_bdaddr[4], device->remote_bdaddr[3], | |
| 1154 | ✗ | device->remote_bdaddr[2], device->remote_bdaddr[1], device->remote_bdaddr[0]); | |
| 1155 | } | ||
| 1156 | } | ||
| 1157 | ✗ | skip: | |
| 1158 | break; | ||
| 1159 | } | ||
| 1160 | ✗ | case BT_HCI_EVT_LE_CONN_UPDATE_COMPLETE: | |
| 1161 | { | ||
| 1162 | ✗ | struct bt_hci_evt_le_conn_update_complete *conn = | |
| 1163 | ✗ | (struct bt_hci_evt_le_conn_update_complete *)(bt_hci_evt_pkt->evt_data + sizeof(struct bt_hci_evt_le_meta_event)); | |
| 1164 | ✗ | printf("# BT_HCI_EVT_LE_CONN_UPDATE_COMPLETE sts: %d, int: %d, lat: %d, tout: %d\n", | |
| 1165 | ✗ | conn->status, conn->interval, conn->latency, conn->supv_timeout); | |
| 1166 | ✗ | if (device) { | |
| 1167 | ✗ | atomic_set_bit(&device->flags, BT_DEV_PPCP_DONE); | |
| 1168 | } | ||
| 1169 | break; | ||
| 1170 | } | ||
| 1171 | ✗ | case BT_HCI_EV_LE_REMOTE_FEAT_COMPLETE: | |
| 1172 | { | ||
| 1173 | ✗ | struct bt_hci_evt_le_remote_feat_complete *le_remote_feat = | |
| 1174 | ✗ | (struct bt_hci_evt_le_remote_feat_complete *)(bt_hci_evt_pkt->evt_data + sizeof(struct bt_hci_evt_le_meta_event)); | |
| 1175 | ✗ | printf("# BT_HCI_EVT_LE_REMOTE_FEAT_COMPLETE\n"); | |
| 1176 | ✗ | bt_host_get_dev_from_handle(le_remote_feat->handle, &device); | |
| 1177 | ✗ | if (device) { | |
| 1178 | ✗ | if (le_remote_feat->status) { | |
| 1179 | ✗ | printf("# dev: %ld error: 0x%02X\n", device->ids.id, le_remote_feat->status); | |
| 1180 | } | ||
| 1181 | } | ||
| 1182 | else { | ||
| 1183 | ✗ | printf("# dev NULL!\n"); | |
| 1184 | } | ||
| 1185 | break; | ||
| 1186 | } | ||
| 1187 | } | ||
| 1188 | ✗ | } | |
| 1189 | |||
| 1190 | ✗ | static void bt_hci_start_inquiry_cfg_check(void *cp) { | |
| 1191 | ✗ | if (config.global_cfg.inquiry_mode == INQ_AUTO) { | |
| 1192 | ✗ | bt_hci_start_inquiry(); | |
| 1193 | } | ||
| 1194 | else { | ||
| 1195 | ✗ | bt_hci_cmd_le_set_scan_enable(0); | |
| 1196 | ✗ | bt_hci_cmd_le_set_scan_param_passive(); | |
| 1197 | ✗ | bt_hci_cmd_le_set_scan_enable(1); | |
| 1198 | } | ||
| 1199 | ✗ | } | |
| 1200 | |||
| 1201 | ✗ | static void bt_hci_load_le_accept_list(void *cp) { | |
| 1202 | ✗ | bt_addr_le_t le_bdaddr; | |
| 1203 | ✗ | if (bt_host_get_next_accept_le_bdaddr(&le_bdaddr) == 0) { | |
| 1204 | ✗ | bt_hci_cmd_le_add_dev_to_wl(&le_bdaddr); | |
| 1205 | } | ||
| 1206 | else { | ||
| 1207 | ✗ | bt_hci_pkt_retry = 0; | |
| 1208 | ✗ | bt_hci_q_conf(1); | |
| 1209 | } | ||
| 1210 | ✗ | } | |
| 1211 | |||
| 1212 | ✗ | static int32_t bt_hci_get_random_context(struct bt_dev **device, bt_hci_le_cb_t *cb) { | |
| 1213 | ✗ | size_t len; | |
| 1214 | ✗ | struct bt_hci_le_cb *tmp = (struct bt_hci_le_cb *)xRingbufferReceive(randq_hdl, &len, 0); | |
| 1215 | ✗ | if (tmp) { | |
| 1216 | ✗ | *device = tmp->device; | |
| 1217 | ✗ | *cb = tmp->callback; | |
| 1218 | ✗ | vRingbufferReturnItem(randq_hdl, (void *)tmp); | |
| 1219 | ✗ | return 0; | |
| 1220 | } | ||
| 1221 | return -1; | ||
| 1222 | } | ||
| 1223 | |||
| 1224 | ✗ | static int32_t bt_hci_get_encrypt_context(struct bt_dev **device, bt_hci_le_cb_t *cb) { | |
| 1225 | ✗ | size_t len; | |
| 1226 | ✗ | struct bt_hci_le_cb *tmp = (struct bt_hci_le_cb *)xRingbufferReceive(encryptq_hdl, &len, 0); | |
| 1227 | ✗ | if (tmp) { | |
| 1228 | ✗ | *device = tmp->device; | |
| 1229 | ✗ | *cb = tmp->callback; | |
| 1230 | ✗ | vRingbufferReturnItem(encryptq_hdl, (void *)tmp); | |
| 1231 | ✗ | return 0; | |
| 1232 | } | ||
| 1233 | return -1; | ||
| 1234 | } | ||
| 1235 | |||
| 1236 | ✗ | static void bt_hci_set_device_name(void) { | |
| 1237 | ✗ | strcat(local_name, "_"); | |
| 1238 | ✗ | strncat(local_name, wired_get_sys_name(), 6); | |
| 1239 | ✗ | strcat(local_name, "_"); | |
| 1240 | ✗ | snprintf(local_name + strlen(local_name), 5, "%02X%02X", local_bdaddr[1], local_bdaddr[0]); | |
| 1241 | ✗ | printf("# local_name: %s\n", local_name); | |
| 1242 | ✗ | } | |
| 1243 | |||
| 1244 | ✗ | int32_t bt_hci_init(void) { | |
| 1245 | ✗ | randq_hdl = xRingbufferCreate(sizeof(struct bt_hci_le_cb) * 8, RINGBUF_TYPE_NOSPLIT); | |
| 1246 | ✗ | if (randq_hdl == NULL) { | |
| 1247 | ✗ | printf("# Failed to create randq ring buffer\n"); | |
| 1248 | ✗ | return -1; | |
| 1249 | } | ||
| 1250 | |||
| 1251 | ✗ | encryptq_hdl = xRingbufferCreate(sizeof(struct bt_hci_le_cb) * 8, RINGBUF_TYPE_NOSPLIT); | |
| 1252 | ✗ | if (encryptq_hdl == NULL) { | |
| 1253 | ✗ | printf("# Failed to create randq ring buffer\n"); | |
| 1254 | ✗ | return -1; | |
| 1255 | } | ||
| 1256 | |||
| 1257 | ✗ | bt_config_state = 0; | |
| 1258 | ✗ | bt_hci_q_conf(0); | |
| 1259 | |||
| 1260 | ✗ | return 0; | |
| 1261 | } | ||
| 1262 | |||
| 1263 | ✗ | const char *bt_hci_get_device_name(void) { | |
| 1264 | ✗ | return local_name; | |
| 1265 | } | ||
| 1266 | |||
| 1267 | ✗ | void bt_hci_start_inquiry(void) { | |
| 1268 | ✗ | if (!inquiry_override) { | |
| 1269 | ✗ | err_led_pulse(); | |
| 1270 | ✗ | inquiry_state = 1; | |
| 1271 | ✗ | bt_nb_inquiry = 0; | |
| 1272 | ✗ | bt_hci_cmd_le_set_scan_enable(0); | |
| 1273 | ✗ | bt_hci_cmd_le_set_scan_param_active(); | |
| 1274 | ✗ | bt_hci_cmd_le_set_scan_enable(1); | |
| 1275 | ✗ | bt_hci_cmd_periodic_inquiry(NULL); | |
| 1276 | } | ||
| 1277 | ✗ | } | |
| 1278 | |||
| 1279 | ✗ | void bt_hci_stop_inquiry(void) { | |
| 1280 | ✗ | bt_hci_cmd_exit_periodic_inquiry(NULL); | |
| 1281 | ✗ | bt_hci_cmd_le_set_scan_enable(0); | |
| 1282 | ✗ | bt_hci_cmd_le_set_scan_param_passive(); | |
| 1283 | ✗ | bt_hci_cmd_le_set_scan_enable(1); | |
| 1284 | ✗ | inquiry_state = 0; | |
| 1285 | ✗ | err_led_clear(); | |
| 1286 | ✗ | } | |
| 1287 | |||
| 1288 | ✗ | uint32_t bt_hci_get_inquiry(void) { | |
| 1289 | ✗ | return inquiry_state; | |
| 1290 | } | ||
| 1291 | |||
| 1292 | ✗ | void bt_hci_inquiry_override(uint32_t state) { | |
| 1293 | ✗ | inquiry_override = state; | |
| 1294 | ✗ | } | |
| 1295 | |||
| 1296 | ✗ | void bt_hci_disconnect(struct bt_dev *device) { | |
| 1297 | ✗ | if (atomic_test_bit(&device->flags, BT_DEV_DEVICE_FOUND)) { | |
| 1298 | ✗ | bt_hci_cmd_disconnect(&device->acl_handle, BT_HCI_ERR_REMOTE_POWER_OFF); | |
| 1299 | } | ||
| 1300 | ✗ | } | |
| 1301 | |||
| 1302 | ✗ | void bt_hci_sniff_mode(struct bt_dev *device, uint16_t interval) { | |
| 1303 | ✗ | bt_hci_cmd_sniff_mode((void *)&device->acl_handle, interval); | |
| 1304 | ✗ | } | |
| 1305 | |||
| 1306 | ✗ | void bt_hci_exit_sniff_mode(struct bt_dev *device) { | |
| 1307 | ✗ | bt_hci_cmd_exit_sniff_mode((void *)&device->acl_handle); | |
| 1308 | ✗ | } | |
| 1309 | |||
| 1310 | ✗ | void bt_hci_write_link_supervision_timeout(struct bt_dev *device) { | |
| 1311 | ✗ | bt_hci_cmd_write_link_supervision_to((void *)&device->acl_handle); | |
| 1312 | ✗ | } | |
| 1313 | |||
| 1314 | ✗ | void bt_hci_get_le_local_addr(bt_addr_le_t *le_local) { | |
| 1315 | ✗ | memcpy(le_local->a.val, local_bdaddr, sizeof(le_local->a.val)); | |
| 1316 | ✗ | le_local->type = 0x00; | |
| 1317 | ✗ | } | |
| 1318 | |||
| 1319 | ✗ | int32_t bt_hci_get_random(struct bt_dev *device, bt_hci_le_cb_t cb) { | |
| 1320 | ✗ | struct bt_hci_le_cb le_cb = { | |
| 1321 | .device = device, | ||
| 1322 | .callback = cb, | ||
| 1323 | }; | ||
| 1324 | ✗ | UBaseType_t ret = xRingbufferSend(randq_hdl, (void *)&le_cb, sizeof(le_cb), 0); | |
| 1325 | ✗ | if (ret != pdTRUE) { | |
| 1326 | ✗ | printf("# %s randq full!\n", __FUNCTION__); | |
| 1327 | ✗ | return -1; | |
| 1328 | } | ||
| 1329 | |||
| 1330 | ✗ | bt_hci_cmd_le_rand(); | |
| 1331 | ✗ | return 0; | |
| 1332 | } | ||
| 1333 | |||
| 1334 | ✗ | int32_t bt_hci_get_encrypt(struct bt_dev *device, bt_hci_le_cb_t cb, const uint8_t *key, uint8_t *plaintext) { | |
| 1335 | ✗ | struct bt_hci_le_cb le_cb = { | |
| 1336 | .device = device, | ||
| 1337 | .callback = cb, | ||
| 1338 | }; | ||
| 1339 | ✗ | UBaseType_t ret = xRingbufferSend(encryptq_hdl, (void *)&le_cb, sizeof(le_cb), 0); | |
| 1340 | ✗ | if (ret != pdTRUE) { | |
| 1341 | ✗ | printf("# %s encryptq full!\n", __FUNCTION__); | |
| 1342 | ✗ | return -1; | |
| 1343 | } | ||
| 1344 | |||
| 1345 | /* We hope here that the BT ctrl process encrypt req FIFO */ | ||
| 1346 | ✗ | bt_hci_cmd_le_encrypt(key, plaintext); | |
| 1347 | ✗ | return 0; | |
| 1348 | } | ||
| 1349 | |||
| 1350 | ✗ | void bt_hci_start_encryption(uint16_t handle, uint64_t rand, uint16_t ediv, uint8_t *ltk) { | |
| 1351 | ✗ | bt_hci_cmd_le_start_encryption(handle, rand, ediv, ltk); | |
| 1352 | ✗ | } | |
| 1353 | |||
| 1354 | ✗ | void bt_hci_add_to_accept_list(bt_addr_le_t *le_bdaddr) { | |
| 1355 | ✗ | bt_hci_cmd_le_add_dev_to_wl(le_bdaddr); | |
| 1356 | ✗ | } | |
| 1357 | |||
| 1358 | ✗ | void bt_hci_le_conn_update(struct hci_cp_le_conn_update *cp) { | |
| 1359 | ✗ | bt_hci_cmd_le_conn_update(cp); | |
| 1360 | ✗ | } | |
| 1361 | |||
| 1362 | ✗ | void bt_hci_evt_hdlr(struct bt_hci_pkt *bt_hci_evt_pkt) { | |
| 1363 | ✗ | struct bt_dev *device = NULL; | |
| 1364 | |||
| 1365 | ✗ | switch (bt_hci_evt_pkt->evt_hdr.evt) { | |
| 1366 | ✗ | case BT_HCI_EVT_INQUIRY_COMPLETE: | |
| 1367 | ✗ | printf("# BT_HCI_EVT_INQUIRY_COMPLETE\n"); | |
| 1368 | ✗ | bt_nb_inquiry++; | |
| 1369 | ✗ | if (bt_host_get_active_dev(&device) > -1 && bt_nb_inquiry > BT_INQUIRY_MAX) { | |
| 1370 | ✗ | bt_hci_stop_inquiry(); | |
| 1371 | } | ||
| 1372 | break; | ||
| 1373 | ✗ | case BT_HCI_EVT_INQUIRY_RESULT: | |
| 1374 | case BT_HCI_EVT_INQUIRY_RESULT_WITH_RSSI: | ||
| 1375 | case BT_HCI_EVT_EXTENDED_INQUIRY_RESULT: | ||
| 1376 | { | ||
| 1377 | ✗ | struct bt_hci_evt_inquiry_result *inquiry_result = (struct bt_hci_evt_inquiry_result *)bt_hci_evt_pkt->evt_data; | |
| 1378 | ✗ | printf("# BT_HCI_EVT_INQUIRY_RESULT\n"); | |
| 1379 | ✗ | printf("# Number of responce: %d\n", inquiry_result->num_reports); | |
| 1380 | ✗ | for (uint8_t i = 1; i <= inquiry_result->num_reports; i++) { | |
| 1381 | ✗ | bt_host_get_dev_from_bdaddr((uint8_t *)inquiry_result + 1, &device); | |
| 1382 | ✗ | if (device == NULL) { | |
| 1383 | ✗ | (void)bt_host_get_new_dev(&device); | |
| 1384 | ✗ | if (device) { | |
| 1385 | ✗ | bt_host_reset_dev(device); | |
| 1386 | ✗ | memcpy(device->remote_bdaddr, (uint8_t *)inquiry_result + 1, sizeof(device->remote_bdaddr)); | |
| 1387 | ✗ | device->ids.type = BT_HID_GENERIC; | |
| 1388 | ✗ | bt_l2cap_init_dev_scid(device); | |
| 1389 | ✗ | atomic_set_bit(&device->flags, BT_DEV_DEVICE_FOUND); | |
| 1390 | ✗ | bt_hci_cmd_connect(device->remote_bdaddr); | |
| 1391 | ✗ | printf("Inquiry dev: %ld type: %ld bdaddr: %02X:%02X:%02X:%02X:%02X:%02X\n", device->ids.id, device->ids.type, | |
| 1392 | ✗ | device->remote_bdaddr[5], device->remote_bdaddr[4], device->remote_bdaddr[3], | |
| 1393 | ✗ | device->remote_bdaddr[2], device->remote_bdaddr[1], device->remote_bdaddr[0]); | |
| 1394 | ✗ | bt_mon_log(true, "Inquiry dev: %ld type: %ld bdaddr: %02X:%02X:%02X:%02X:%02X:%02X\n", device->ids.id, device->ids.type, | |
| 1395 | ✗ | device->remote_bdaddr[5], device->remote_bdaddr[4], device->remote_bdaddr[3], | |
| 1396 | ✗ | device->remote_bdaddr[2], device->remote_bdaddr[1], device->remote_bdaddr[0]); | |
| 1397 | } | ||
| 1398 | } | ||
| 1399 | break; /* Only support one result for now */ | ||
| 1400 | } | ||
| 1401 | break; | ||
| 1402 | } | ||
| 1403 | ✗ | case BT_HCI_EVT_CONN_COMPLETE: | |
| 1404 | { | ||
| 1405 | ✗ | struct bt_hci_evt_conn_complete *conn_complete = (struct bt_hci_evt_conn_complete *)bt_hci_evt_pkt->evt_data; | |
| 1406 | ✗ | printf("# BT_HCI_EVT_CONN_COMPLETE\n"); | |
| 1407 | ✗ | bt_host_get_dev_from_bdaddr(conn_complete->bdaddr.val, &device); | |
| 1408 | ✗ | if (device) { | |
| 1409 | ✗ | if (conn_complete->status) { | |
| 1410 | ✗ | device->pkt_retry++; | |
| 1411 | ✗ | printf("# dev: %ld error: 0x%02X\n", device->ids.id, conn_complete->status); | |
| 1412 | ✗ | if (!atomic_test_bit(&device->flags, BT_DEV_PAGE) && device->pkt_retry < BT_MAX_RETRY) { | |
| 1413 | ✗ | bt_hci_cmd_connect(device->remote_bdaddr); | |
| 1414 | } | ||
| 1415 | else { | ||
| 1416 | ✗ | bt_host_reset_dev(device); | |
| 1417 | ✗ | if (config.global_cfg.inquiry_mode == INQ_AUTO && bt_host_get_active_dev(&device) == BT_NONE) { | |
| 1418 | ✗ | bt_hci_start_inquiry(); | |
| 1419 | } | ||
| 1420 | } | ||
| 1421 | } | ||
| 1422 | else { | ||
| 1423 | ✗ | bt_nb_inquiry = BT_INQUIRY_MAX; | |
| 1424 | ✗ | device->acl_handle = conn_complete->handle; | |
| 1425 | ✗ | device->pkt_retry = 0; | |
| 1426 | ✗ | printf("dev: %ld acl_handle: 0x%04X\n", device->ids.id, device->acl_handle); | |
| 1427 | ✗ | bt_mon_log(true, "dev: %ld acl_handle: 0x%04X\n", device->ids.id, device->acl_handle); | |
| 1428 | ✗ | bt_hci_cmd_le_set_adv_disable(NULL); | |
| 1429 | ✗ | bt_hci_cmd_remote_name_request(device->remote_bdaddr); | |
| 1430 | } | ||
| 1431 | } | ||
| 1432 | else { | ||
| 1433 | ✗ | printf("# dev NULL!\n"); | |
| 1434 | } | ||
| 1435 | break; | ||
| 1436 | } | ||
| 1437 | ✗ | case BT_HCI_EVT_CONN_REQUEST: | |
| 1438 | { | ||
| 1439 | ✗ | struct bt_hci_evt_conn_request *conn_request = (struct bt_hci_evt_conn_request *)bt_hci_evt_pkt->evt_data; | |
| 1440 | ✗ | printf("# BT_HCI_EVT_CONN_REQUEST\n"); | |
| 1441 | ✗ | bt_host_get_dev_from_bdaddr(conn_request->bdaddr.val, &device); | |
| 1442 | ✗ | if (device == NULL) { | |
| 1443 | ✗ | (void)bt_host_get_new_dev(&device); | |
| 1444 | ✗ | if (device) { | |
| 1445 | ✗ | bt_host_reset_dev(device); | |
| 1446 | ✗ | memcpy(device->remote_bdaddr, (void *)&conn_request->bdaddr, sizeof(device->remote_bdaddr)); | |
| 1447 | ✗ | device->ids.type = BT_HID_GENERIC;; | |
| 1448 | ✗ | bt_l2cap_init_dev_scid(device); | |
| 1449 | ✗ | atomic_set_bit(&device->flags, BT_DEV_DEVICE_FOUND); | |
| 1450 | ✗ | atomic_set_bit(&device->flags, BT_DEV_PAGE); | |
| 1451 | ✗ | bt_hci_cmd_accept_conn_req(device->remote_bdaddr); | |
| 1452 | ✗ | printf("Page dev: %ld type: %ld bdaddr: %02X:%02X:%02X:%02X:%02X:%02X\n", device->ids.id, device->ids.type, | |
| 1453 | ✗ | device->remote_bdaddr[5], device->remote_bdaddr[4], device->remote_bdaddr[3], | |
| 1454 | ✗ | device->remote_bdaddr[2], device->remote_bdaddr[1], device->remote_bdaddr[0]); | |
| 1455 | ✗ | bt_mon_log(true, "Page dev: %ld type: %ld bdaddr: %02X:%02X:%02X:%02X:%02X:%02X\n", device->ids.id, device->ids.type, | |
| 1456 | ✗ | device->remote_bdaddr[5], device->remote_bdaddr[4], device->remote_bdaddr[3], | |
| 1457 | ✗ | device->remote_bdaddr[2], device->remote_bdaddr[1], device->remote_bdaddr[0]); | |
| 1458 | } | ||
| 1459 | } | ||
| 1460 | break; | ||
| 1461 | } | ||
| 1462 | ✗ | case BT_HCI_EVT_DISCONN_COMPLETE: | |
| 1463 | { | ||
| 1464 | ✗ | struct bt_hci_evt_disconn_complete *disconn_complete = (struct bt_hci_evt_disconn_complete *)bt_hci_evt_pkt->evt_data; | |
| 1465 | ✗ | printf("# BT_HCI_EVT_DISCONN_COMPLETE\n"); | |
| 1466 | ✗ | bt_host_get_dev_from_handle(disconn_complete->handle, &device); | |
| 1467 | ✗ | if (device) { | |
| 1468 | ✗ | printf("# DISCONN from dev: %ld\n", device->ids.id); | |
| 1469 | ✗ | bt_host_reset_dev(device); | |
| 1470 | ✗ | if (bt_host_get_active_dev(&device) == BT_NONE) { | |
| 1471 | ✗ | if (config.global_cfg.inquiry_mode == INQ_AUTO) { | |
| 1472 | ✗ | bt_hci_start_inquiry(); | |
| 1473 | } | ||
| 1474 | ✗ | bt_hci_cmd_le_set_adv_enable(NULL); | |
| 1475 | } | ||
| 1476 | } | ||
| 1477 | else { | ||
| 1478 | ✗ | bt_host_get_dev_conf(&device); | |
| 1479 | ✗ | if (device && disconn_complete->handle == device->acl_handle) { | |
| 1480 | ✗ | printf("# DISCONN from BLE config interface\n"); | |
| 1481 | ✗ | if (atomic_test_bit(&device->flags, BT_DEV_DEVICE_FOUND)) { | |
| 1482 | ✗ | bt_host_reset_dev(device); | |
| 1483 | ✗ | if (bt_host_get_active_dev(&device) == BT_NONE) { | |
| 1484 | ✗ | bt_hci_cmd_le_set_adv_enable(NULL); | |
| 1485 | } | ||
| 1486 | } | ||
| 1487 | } | ||
| 1488 | else { | ||
| 1489 | ✗ | printf("# DISCONN for non existing device handle: %04X\n", disconn_complete->handle); | |
| 1490 | } | ||
| 1491 | } | ||
| 1492 | break; | ||
| 1493 | } | ||
| 1494 | ✗ | case BT_HCI_EVT_AUTH_COMPLETE: | |
| 1495 | { | ||
| 1496 | ✗ | struct bt_hci_evt_auth_complete *auth_complete = (struct bt_hci_evt_auth_complete *)bt_hci_evt_pkt->evt_data; | |
| 1497 | ✗ | printf("# BT_HCI_EVT_AUTH_COMPLETE\n"); | |
| 1498 | ✗ | bt_host_get_dev_from_handle(auth_complete->handle, &device); | |
| 1499 | ✗ | if (device) { | |
| 1500 | ✗ | if (auth_complete->status) { | |
| 1501 | ✗ | printf("# dev: %ld error: 0x%02X\n", device->ids.id, auth_complete->status); | |
| 1502 | } | ||
| 1503 | else { | ||
| 1504 | ✗ | printf("# dev: %ld Pairing done\n", device->ids.id); | |
| 1505 | ✗ | if (!atomic_test_bit(&device->flags, BT_DEV_PAGE)) { | |
| 1506 | ✗ | if (atomic_test_bit(&device->flags, BT_DEV_ENCRYPTION)) { | |
| 1507 | ✗ | bt_hci_cmd_set_conn_encrypt(&device->acl_handle); | |
| 1508 | } | ||
| 1509 | ✗ | bt_l2cap_cmd_hid_ctrl_conn_req(device); | |
| 1510 | } | ||
| 1511 | } | ||
| 1512 | } | ||
| 1513 | else { | ||
| 1514 | ✗ | printf("# dev NULL!\n"); | |
| 1515 | } | ||
| 1516 | break; | ||
| 1517 | } | ||
| 1518 | ✗ | case BT_HCI_EVT_REMOTE_NAME_REQ_COMPLETE: | |
| 1519 | { | ||
| 1520 | ✗ | struct bt_hci_evt_remote_name_req_complete *remote_name_req_complete = (struct bt_hci_evt_remote_name_req_complete *)bt_hci_evt_pkt->evt_data; | |
| 1521 | ✗ | printf("# BT_HCI_EVT_REMOTE_NAME_REQ_COMPLETE:\n"); | |
| 1522 | ✗ | bt_host_get_dev_from_bdaddr(remote_name_req_complete->bdaddr.val, &device); | |
| 1523 | ✗ | if (device) { | |
| 1524 | ✗ | if (remote_name_req_complete->status) { | |
| 1525 | ✗ | device->pkt_retry++; | |
| 1526 | ✗ | printf("# dev: %ld error: 0x%02X\n", device->ids.id, remote_name_req_complete->status); | |
| 1527 | ✗ | if (device->pkt_retry < BT_MAX_RETRY) { | |
| 1528 | ✗ | bt_hci_cmd_remote_name_request(device->remote_bdaddr); | |
| 1529 | } | ||
| 1530 | else { | ||
| 1531 | ✗ | bt_host_reset_dev(device); | |
| 1532 | ✗ | if (config.global_cfg.inquiry_mode == INQ_AUTO && bt_host_get_active_dev(&device) == BT_NONE) { | |
| 1533 | ✗ | bt_hci_start_inquiry(); | |
| 1534 | } | ||
| 1535 | } | ||
| 1536 | } | ||
| 1537 | else { | ||
| 1538 | ✗ | bt_hid_set_type_flags_from_name(device, (char *)remote_name_req_complete->name); | |
| 1539 | ✗ | bt_hci_stop_inquiry(); | |
| 1540 | ✗ | if (device->ids.type == BT_HID_GENERIC || device->ids.type == BT_SW) { | |
| 1541 | ✗ | bt_hci_cmd_read_remote_features(&device->acl_handle); | |
| 1542 | } | ||
| 1543 | ✗ | if (device->ids.type == BT_PS3 || device->ids.subtype == BT_WIIU_PRO) { | |
| 1544 | ✗ | struct bt_hci_cp_switch_role switch_role = { | |
| 1545 | .role = 0x01, | ||
| 1546 | }; | ||
| 1547 | ✗ | memcpy((void *)&switch_role.bdaddr, remote_name_req_complete->bdaddr.val, sizeof(remote_name_req_complete->bdaddr.val)); | |
| 1548 | ✗ | bt_hci_cmd_switch_role(&switch_role); | |
| 1549 | } | ||
| 1550 | ✗ | if (!atomic_test_bit(&device->flags, BT_DEV_PAGE)) { | |
| 1551 | ✗ | if (device->ids.type == BT_PS) { | |
| 1552 | ✗ | bt_host_q_wait_pkt(20); | |
| 1553 | } | ||
| 1554 | ✗ | bt_hci_cmd_auth_requested(&device->acl_handle); | |
| 1555 | } | ||
| 1556 | ✗ | printf("dev: %ld type: %ld:%ld %s\n", device->ids.id, device->ids.type, device->ids.subtype, remote_name_req_complete->name); | |
| 1557 | ✗ | bt_mon_log(true, "dev: %ld type: %ld:%ld %s\n", device->ids.id, device->ids.type, device->ids.subtype, remote_name_req_complete->name); | |
| 1558 | } | ||
| 1559 | } | ||
| 1560 | else { | ||
| 1561 | ✗ | printf("# dev NULL!\n"); | |
| 1562 | } | ||
| 1563 | break; | ||
| 1564 | } | ||
| 1565 | ✗ | case BT_HCI_EVT_ENCRYPT_CHANGE: | |
| 1566 | { | ||
| 1567 | ✗ | struct bt_hci_evt_encrypt_change *encrypt_change = (struct bt_hci_evt_encrypt_change *)bt_hci_evt_pkt->evt_data; | |
| 1568 | ✗ | printf("# BT_HCI_EVT_ENCRYPT_CHANGE\n"); | |
| 1569 | ✗ | bt_host_get_dev_from_handle(encrypt_change->handle, &device); | |
| 1570 | ✗ | if (device) { | |
| 1571 | ✗ | if (encrypt_change->status) { | |
| 1572 | ✗ | printf("# dev: %ld error: 0x%02X\n", device->ids.id, encrypt_change->status); | |
| 1573 | ✗ | if (atomic_test_bit(&device->flags, BT_DEV_IS_BLE)) { | |
| 1574 | ✗ | bt_host_clear_le_ltk(&device->le_remote_bdaddr); | |
| 1575 | ✗ | bt_hci_cmd_disconnect(&device->acl_handle, BT_HCI_ERR_AUTHENTICATION_FAIL); | |
| 1576 | } | ||
| 1577 | } | ||
| 1578 | ✗ | else if (atomic_test_bit(&device->flags, BT_DEV_IS_BLE)) { | |
| 1579 | ✗ | bt_att_hid_init(device); | |
| 1580 | } | ||
| 1581 | } | ||
| 1582 | else { | ||
| 1583 | ✗ | printf("# dev NULL!\n"); | |
| 1584 | } | ||
| 1585 | break; | ||
| 1586 | } | ||
| 1587 | ✗ | case BT_HCI_EVT_REMOTE_FEATURES: | |
| 1588 | { | ||
| 1589 | ✗ | struct bt_hci_evt_remote_features *remote_features = (struct bt_hci_evt_remote_features *)bt_hci_evt_pkt->evt_data; | |
| 1590 | ✗ | printf("# BT_HCI_EVT_REMOTE_FEATURES\n"); | |
| 1591 | ✗ | bt_host_get_dev_from_handle(remote_features->handle, &device); | |
| 1592 | ✗ | if (device) { | |
| 1593 | ✗ | if (remote_features->status) { | |
| 1594 | ✗ | printf("# dev: %ld error: 0x%02X\n", device->ids.id, remote_features->status); | |
| 1595 | } | ||
| 1596 | else { | ||
| 1597 | ✗ | if (remote_features->features[7] & 0x80) { | |
| 1598 | ✗ | bt_hci_cmd_read_remote_ext_features(&device->acl_handle); | |
| 1599 | } | ||
| 1600 | ✗ | if (remote_features->features[0] & 0x04) { | |
| 1601 | ✗ | atomic_set_bit(&device->flags, BT_DEV_ENCRYPTION); | |
| 1602 | } | ||
| 1603 | } | ||
| 1604 | ✗ | bt_l2cap_cmd_ext_feat_mask_req(device); | |
| 1605 | } | ||
| 1606 | else { | ||
| 1607 | ✗ | printf("# dev NULL!\n"); | |
| 1608 | } | ||
| 1609 | break; | ||
| 1610 | } | ||
| 1611 | ✗ | case BT_HCI_EVT_REMOTE_VERSION_INFO: | |
| 1612 | { | ||
| 1613 | ✗ | struct bt_hci_evt_remote_version_info *remote_version_info = (struct bt_hci_evt_remote_version_info *)bt_hci_evt_pkt->evt_data; | |
| 1614 | ✗ | printf("# BT_HCI_EVT_REMOTE_VERSION_INFO\n"); | |
| 1615 | ✗ | bt_host_get_dev_from_handle(remote_version_info->handle, &device); | |
| 1616 | ✗ | if (device) { | |
| 1617 | ✗ | if (remote_version_info->status) { | |
| 1618 | ✗ | printf("# dev: %ld error: 0x%02X\n", device->ids.id, remote_version_info->status); | |
| 1619 | } | ||
| 1620 | } | ||
| 1621 | else { | ||
| 1622 | ✗ | printf("# dev NULL!\n"); | |
| 1623 | } | ||
| 1624 | break; | ||
| 1625 | } | ||
| 1626 | ✗ | case BT_HCI_EVT_CMD_COMPLETE: | |
| 1627 | { | ||
| 1628 | ✗ | struct bt_hci_evt_cmd_complete *cmd_complete = (struct bt_hci_evt_cmd_complete *)bt_hci_evt_pkt->evt_data; | |
| 1629 | ✗ | uint8_t status = bt_hci_evt_pkt->evt_data[sizeof(*cmd_complete)]; | |
| 1630 | ✗ | printf("# BT_HCI_EVT_CMD_COMPLETE\n"); | |
| 1631 | ✗ | if (status != BT_HCI_ERR_SUCCESS && status != BT_HCI_ERR_UNKNOWN_CMD) { | |
| 1632 | ✗ | printf("# opcode: 0x%04X error: 0x%02X retry: %ld\n", cmd_complete->opcode, status, bt_hci_pkt_retry); | |
| 1633 | ✗ | switch (cmd_complete->opcode) { | |
| 1634 | ✗ | case BT_HCI_OP_READ_BD_ADDR: | |
| 1635 | case BT_HCI_OP_RESET: | ||
| 1636 | case BT_HCI_OP_READ_LOCAL_FEATURES: | ||
| 1637 | case BT_HCI_OP_READ_LOCAL_VERSION_INFO: | ||
| 1638 | case BT_HCI_OP_READ_BUFFER_SIZE: | ||
| 1639 | case BT_HCI_OP_READ_CLASS_OF_DEVICE: | ||
| 1640 | case BT_HCI_OP_READ_LOCAL_NAME: | ||
| 1641 | case BT_HCI_OP_READ_VOICE_SETTING: | ||
| 1642 | case BT_HCI_OP_READ_NUM_SUPPORTED_IAC: | ||
| 1643 | case BT_HCI_OP_READ_CURRENT_IAC_LAP: | ||
| 1644 | case BT_HCI_OP_SET_EVENT_FILTER: | ||
| 1645 | case BT_HCI_OP_WRITE_CONN_ACCEPT_TIMEOUT: | ||
| 1646 | case BT_HCI_OP_READ_SUPPORTED_COMMANDS: | ||
| 1647 | case BT_HCI_OP_WRITE_SSP_MODE: | ||
| 1648 | case BT_HCI_OP_WRITE_INQUIRY_MODE: | ||
| 1649 | case BT_HCI_OP_READ_INQUIRY_RSP_TX_PWR_LVL: | ||
| 1650 | case BT_HCI_OP_READ_LOCAL_EXT_FEATURES: | ||
| 1651 | case BT_HCI_OP_READ_STORED_LINK_KEY: | ||
| 1652 | case BT_HCI_OP_READ_PAGE_SCAN_ACTIVITY: | ||
| 1653 | case BT_HCI_OP_READ_PAGE_SCAN_TYPE: | ||
| 1654 | case BT_HCI_OP_LE_READ_BUFFER_SIZE: | ||
| 1655 | case BT_HCI_OP_LE_WRITE_LE_HOST_SUPP: | ||
| 1656 | case BT_HCI_OP_LE_READ_WL_SIZE: | ||
| 1657 | case BT_HCI_OP_LE_CLEAR_WL: | ||
| 1658 | case BT_HCI_OP_LE_ADD_DEV_TO_WL: | ||
| 1659 | case BT_HCI_OP_DELETE_STORED_LINK_KEY: | ||
| 1660 | case BT_HCI_OP_WRITE_CLASS_OF_DEVICE: | ||
| 1661 | case BT_HCI_OP_WRITE_LOCAL_NAME: | ||
| 1662 | case BT_HCI_OP_WRITE_AUTH_ENABLE: | ||
| 1663 | case BT_HCI_OP_SET_EVENT_MASK: | ||
| 1664 | case BT_HCI_OP_WRITE_PAGE_SCAN_ACTIVITY: | ||
| 1665 | case BT_HCI_OP_WRITE_INQUIRY_SCAN_ACTIVITY: | ||
| 1666 | case BT_HCI_OP_WRITE_PAGE_SCAN_TYPE: | ||
| 1667 | case BT_HCI_OP_WRITE_PAGE_TIMEOUT: | ||
| 1668 | case BT_HCI_OP_WRITE_HOLD_MODE_ACT: | ||
| 1669 | case BT_HCI_OP_WRITE_SCAN_ENABLE: | ||
| 1670 | case BT_HCI_OP_WRITE_DEFAULT_LINK_POLICY: | ||
| 1671 | case BT_HCI_OP_LE_SET_SCAN_PARAM: | ||
| 1672 | case BT_HCI_OP_LE_SET_SCAN_ENABLE: | ||
| 1673 | case BT_HCI_OP_LE_SET_ADV_PARAM: | ||
| 1674 | case BT_HCI_OP_LE_SET_ADV_DATA: | ||
| 1675 | case BT_HCI_OP_LE_SET_SCAN_RSP_DATA: | ||
| 1676 | case BT_HCI_OP_LE_SET_ADV_ENABLE: | ||
| 1677 | ✗ | bt_hci_pkt_retry++; | |
| 1678 | ✗ | if (bt_hci_pkt_retry > BT_MAX_RETRY) { | |
| 1679 | ✗ | bt_hci_pkt_retry = 0; | |
| 1680 | ✗ | bt_hci_init(); | |
| 1681 | } | ||
| 1682 | else { | ||
| 1683 | ✗ | bt_hci_q_conf(0); | |
| 1684 | } | ||
| 1685 | break; | ||
| 1686 | } | ||
| 1687 | } | ||
| 1688 | else { | ||
| 1689 | ✗ | switch (cmd_complete->opcode) { | |
| 1690 | ✗ | case BT_HCI_OP_LE_READ_BUFFER_SIZE: | |
| 1691 | { | ||
| 1692 | ✗ | struct bt_hci_rp_le_read_buffer_size *le_read_buffer_size = (struct bt_hci_rp_le_read_buffer_size *)&bt_hci_evt_pkt->evt_data[sizeof(*cmd_complete)]; | |
| 1693 | ✗ | bt_att_set_le_max_mtu(le_read_buffer_size->le_max_len - sizeof(struct bt_l2cap_hdr)); | |
| 1694 | ✗ | bt_hci_pkt_retry = 0; | |
| 1695 | ✗ | bt_hci_q_conf(1); | |
| 1696 | ✗ | break; | |
| 1697 | } | ||
| 1698 | ✗ | case BT_HCI_OP_LE_READ_WL_SIZE: | |
| 1699 | { | ||
| 1700 | //struct bt_hci_rp_le_read_wl_size *le_read_wl_size = (struct bt_hci_rp_le_read_wl_size *)&bt_hci_evt_pkt->evt_data[sizeof(*cmd_complete)]; | ||
| 1701 | //TODO use value | ||
| 1702 | ✗ | bt_hci_pkt_retry = 0; | |
| 1703 | ✗ | bt_hci_q_conf(1); | |
| 1704 | ✗ | break; | |
| 1705 | } | ||
| 1706 | ✗ | case BT_HCI_OP_LE_ADD_DEV_TO_WL: | |
| 1707 | { | ||
| 1708 | ✗ | bt_addr_le_t le_bdaddr; | |
| 1709 | ✗ | if (bt_host_get_next_accept_le_bdaddr(&le_bdaddr) == 0) { | |
| 1710 | ✗ | bt_hci_cmd_le_add_dev_to_wl(&le_bdaddr); | |
| 1711 | } | ||
| 1712 | else { | ||
| 1713 | ✗ | bt_hci_pkt_retry = 0; | |
| 1714 | ✗ | bt_hci_q_conf(1); | |
| 1715 | } | ||
| 1716 | ✗ | break; | |
| 1717 | } | ||
| 1718 | ✗ | case BT_HCI_OP_READ_BD_ADDR: | |
| 1719 | { | ||
| 1720 | ✗ | struct bt_hci_rp_read_bd_addr *read_bd_addr = (struct bt_hci_rp_read_bd_addr *)&bt_hci_evt_pkt->evt_data[sizeof(*cmd_complete)]; | |
| 1721 | ✗ | memcpy((void *)local_bdaddr, (void *)&read_bd_addr->bdaddr, sizeof(local_bdaddr)); | |
| 1722 | ✗ | bt_hci_set_device_name(); | |
| 1723 | ✗ | printf("local_bdaddr: %02X:%02X:%02X:%02X:%02X:%02X\n", | |
| 1724 | ✗ | local_bdaddr[5], local_bdaddr[4], local_bdaddr[3], | |
| 1725 | ✗ | local_bdaddr[2], local_bdaddr[1], local_bdaddr[0]); | |
| 1726 | ✗ | bt_mon_log(true, "local_bdaddr: %02X:%02X:%02X:%02X:%02X:%02X\n", | |
| 1727 | ✗ | local_bdaddr[5], local_bdaddr[4], local_bdaddr[3], | |
| 1728 | ✗ | local_bdaddr[2], local_bdaddr[1], local_bdaddr[0]); | |
| 1729 | } | ||
| 1730 | /* Fall-through */ | ||
| 1731 | ✗ | case BT_HCI_OP_RESET: | |
| 1732 | case BT_HCI_OP_READ_LOCAL_FEATURES: | ||
| 1733 | case BT_HCI_OP_READ_LOCAL_VERSION_INFO: | ||
| 1734 | case BT_HCI_OP_READ_BUFFER_SIZE: | ||
| 1735 | case BT_HCI_OP_READ_CLASS_OF_DEVICE: | ||
| 1736 | case BT_HCI_OP_READ_LOCAL_NAME: | ||
| 1737 | case BT_HCI_OP_READ_VOICE_SETTING: | ||
| 1738 | case BT_HCI_OP_READ_NUM_SUPPORTED_IAC: | ||
| 1739 | case BT_HCI_OP_READ_CURRENT_IAC_LAP: | ||
| 1740 | case BT_HCI_OP_SET_EVENT_FILTER: | ||
| 1741 | case BT_HCI_OP_WRITE_CONN_ACCEPT_TIMEOUT: | ||
| 1742 | case BT_HCI_OP_READ_SUPPORTED_COMMANDS: | ||
| 1743 | case BT_HCI_OP_WRITE_SSP_MODE: | ||
| 1744 | case BT_HCI_OP_WRITE_INQUIRY_MODE: | ||
| 1745 | case BT_HCI_OP_READ_INQUIRY_RSP_TX_PWR_LVL: | ||
| 1746 | case BT_HCI_OP_READ_LOCAL_EXT_FEATURES: | ||
| 1747 | case BT_HCI_OP_READ_STORED_LINK_KEY: | ||
| 1748 | case BT_HCI_OP_READ_PAGE_SCAN_ACTIVITY: | ||
| 1749 | case BT_HCI_OP_READ_PAGE_SCAN_TYPE: | ||
| 1750 | case BT_HCI_OP_LE_WRITE_LE_HOST_SUPP: | ||
| 1751 | case BT_HCI_OP_LE_CLEAR_WL: | ||
| 1752 | case BT_HCI_OP_DELETE_STORED_LINK_KEY: | ||
| 1753 | case BT_HCI_OP_WRITE_CLASS_OF_DEVICE: | ||
| 1754 | case BT_HCI_OP_WRITE_LOCAL_NAME: | ||
| 1755 | case BT_HCI_OP_WRITE_AUTH_ENABLE: | ||
| 1756 | case BT_HCI_OP_SET_EVENT_MASK: | ||
| 1757 | case BT_HCI_OP_WRITE_PAGE_SCAN_ACTIVITY: | ||
| 1758 | case BT_HCI_OP_WRITE_INQUIRY_SCAN_ACTIVITY: | ||
| 1759 | case BT_HCI_OP_WRITE_PAGE_SCAN_TYPE: | ||
| 1760 | case BT_HCI_OP_WRITE_PAGE_TIMEOUT: | ||
| 1761 | case BT_HCI_OP_WRITE_HOLD_MODE_ACT: | ||
| 1762 | case BT_HCI_OP_WRITE_SCAN_ENABLE: | ||
| 1763 | case BT_HCI_OP_WRITE_DEFAULT_LINK_POLICY: | ||
| 1764 | case BT_HCI_OP_LE_SET_SCAN_PARAM: | ||
| 1765 | case BT_HCI_OP_LE_SET_SCAN_ENABLE: | ||
| 1766 | case BT_HCI_OP_LE_SET_ADV_PARAM: | ||
| 1767 | case BT_HCI_OP_LE_SET_ADV_DATA: | ||
| 1768 | case BT_HCI_OP_LE_SET_SCAN_RSP_DATA: | ||
| 1769 | case BT_HCI_OP_LE_SET_ADV_ENABLE: | ||
| 1770 | ✗ | bt_hci_pkt_retry = 0; | |
| 1771 | ✗ | bt_hci_q_conf(1); | |
| 1772 | ✗ | break; | |
| 1773 | ✗ | case BT_HCI_OP_LE_RAND: | |
| 1774 | { | ||
| 1775 | ✗ | struct bt_hci_rp_le_rand *le_rand = | |
| 1776 | (struct bt_hci_rp_le_rand *)&bt_hci_evt_pkt->evt_data[sizeof(*cmd_complete)]; | ||
| 1777 | ✗ | bt_hci_le_cb_t callback = NULL; | |
| 1778 | ✗ | bt_hci_get_random_context(&device, &callback); | |
| 1779 | ✗ | if (callback) { | |
| 1780 | ✗ | callback(device, le_rand->rand, sizeof(le_rand->rand)); | |
| 1781 | } | ||
| 1782 | ✗ | break; | |
| 1783 | } | ||
| 1784 | ✗ | case BT_HCI_OP_LE_ENCRYPT: | |
| 1785 | { | ||
| 1786 | ✗ | struct bt_hci_rp_le_encrypt *le_encrypt = | |
| 1787 | (struct bt_hci_rp_le_encrypt *)&bt_hci_evt_pkt->evt_data[sizeof(*cmd_complete)]; | ||
| 1788 | ✗ | bt_hci_le_cb_t callback = NULL; | |
| 1789 | ✗ | bt_hci_get_encrypt_context(&device, &callback); | |
| 1790 | ✗ | if (callback) { | |
| 1791 | ✗ | callback(device, le_encrypt->enc_data, sizeof(le_encrypt->enc_data)); | |
| 1792 | } | ||
| 1793 | ✗ | break; | |
| 1794 | } | ||
| 1795 | } | ||
| 1796 | } | ||
| 1797 | break; | ||
| 1798 | } | ||
| 1799 | ✗ | case BT_HCI_EVT_CMD_STATUS: | |
| 1800 | { | ||
| 1801 | ✗ | struct bt_hci_evt_cmd_status *cmd_status = (struct bt_hci_evt_cmd_status *)bt_hci_evt_pkt->evt_data; | |
| 1802 | ✗ | printf("# BT_HCI_EVT_CMD_STATUS\n"); | |
| 1803 | ✗ | if (cmd_status->status) { | |
| 1804 | ✗ | printf("# opcode: 0x%04X error: 0x%02X\n", cmd_status->opcode, cmd_status->status); | |
| 1805 | } | ||
| 1806 | break; | ||
| 1807 | } | ||
| 1808 | ✗ | case BT_HCI_EVT_ROLE_CHANGE: | |
| 1809 | { | ||
| 1810 | ✗ | struct bt_hci_evt_role_change *role_change = (struct bt_hci_evt_role_change *)bt_hci_evt_pkt->evt_data; | |
| 1811 | ✗ | printf("# BT_HCI_EVT_ROLE_CHANGE\n"); | |
| 1812 | ✗ | bt_host_get_dev_from_bdaddr(role_change->bdaddr.val, &device); | |
| 1813 | ✗ | if (device) { | |
| 1814 | ✗ | if (role_change->status) { | |
| 1815 | ✗ | atomic_set_bit(&device->flags, BT_DEV_ROLE_SW_FAIL); | |
| 1816 | } | ||
| 1817 | else { | ||
| 1818 | ✗ | atomic_clear_bit(&device->flags, BT_DEV_ROLE_SW_FAIL); | |
| 1819 | } | ||
| 1820 | } | ||
| 1821 | else { | ||
| 1822 | ✗ | printf("# dev NULL!\n"); | |
| 1823 | } | ||
| 1824 | break; | ||
| 1825 | } | ||
| 1826 | ✗ | case BT_HCI_EVT_MODE_CHANGE: | |
| 1827 | { | ||
| 1828 | ✗ | struct bt_hci_evt_mode_change *evt = (struct bt_hci_evt_mode_change *)bt_hci_evt_pkt->evt_data; | |
| 1829 | ✗ | bt_host_get_dev_from_handle(evt->handle, &device); | |
| 1830 | ✗ | printf("# BT_HCI_EVT_MODE_CHANGE dev: %ld status: %d mode: %d interval %d\n", device->ids.id, evt->status, evt->mode, evt->interval); | |
| 1831 | ✗ | break; | |
| 1832 | } | ||
| 1833 | ✗ | case BT_HCI_EVT_PIN_CODE_REQ: | |
| 1834 | { | ||
| 1835 | ✗ | struct bt_hci_evt_pin_code_req *pin_code_req = (struct bt_hci_evt_pin_code_req *)bt_hci_evt_pkt->evt_data; | |
| 1836 | ✗ | struct bt_hci_cp_pin_code_reply pin_code_reply = {0}; | |
| 1837 | ✗ | printf("# BT_HCI_EVT_PIN_CODE_REQ\n"); | |
| 1838 | ✗ | bt_host_get_dev_from_bdaddr(pin_code_req->bdaddr.val, &device); | |
| 1839 | ✗ | memcpy((void *)&pin_code_reply.bdaddr, device->remote_bdaddr, sizeof(pin_code_reply.bdaddr)); | |
| 1840 | ✗ | if (device->ids.type == BT_WII) { | |
| 1841 | ✗ | memcpy(pin_code_reply.pin_code, local_bdaddr, sizeof(local_bdaddr)); | |
| 1842 | ✗ | pin_code_reply.pin_len = sizeof(local_bdaddr); | |
| 1843 | } | ||
| 1844 | else { | ||
| 1845 | ✗ | memcpy(pin_code_reply.pin_code, bt_default_pin[0], strlen(bt_default_pin[0])); | |
| 1846 | ✗ | pin_code_reply.pin_len = strlen(bt_default_pin[0]); | |
| 1847 | } | ||
| 1848 | ✗ | bt_hci_cmd_pin_code_reply(&pin_code_reply); | |
| 1849 | ✗ | break; | |
| 1850 | } | ||
| 1851 | ✗ | case BT_HCI_EVT_LINK_KEY_REQ: | |
| 1852 | { | ||
| 1853 | ✗ | struct bt_hci_evt_link_key_req *link_key_req = (struct bt_hci_evt_link_key_req *)bt_hci_evt_pkt->evt_data; | |
| 1854 | ✗ | struct bt_hci_cp_link_key_reply link_key_reply; | |
| 1855 | ✗ | printf("# BT_HCI_EVT_LINK_KEY_REQ\n"); | |
| 1856 | ✗ | bt_host_get_dev_from_bdaddr(link_key_req->bdaddr.val, &device); | |
| 1857 | ✗ | memcpy((void *)&link_key_reply.bdaddr, (void *)&link_key_req->bdaddr, sizeof(link_key_reply.bdaddr)); | |
| 1858 | ✗ | if (atomic_test_bit(&device->flags, BT_DEV_PAGE) && bt_host_load_link_key(&link_key_reply) == 0) { | |
| 1859 | ✗ | bt_hci_cmd_link_key_reply((void *)&link_key_reply); | |
| 1860 | } | ||
| 1861 | else { | ||
| 1862 | ✗ | bt_hci_cmd_link_key_neg_reply((void *)device->remote_bdaddr); | |
| 1863 | } | ||
| 1864 | ✗ | break; | |
| 1865 | } | ||
| 1866 | ✗ | case BT_HCI_EVT_LINK_KEY_NOTIFY: | |
| 1867 | { | ||
| 1868 | ✗ | struct bt_hci_evt_link_key_notify *link_key_notify = (struct bt_hci_evt_link_key_notify *)bt_hci_evt_pkt->evt_data; | |
| 1869 | ✗ | printf("# BT_HCI_EVT_LINK_KEY_NOTIFY\n"); | |
| 1870 | ✗ | bt_host_get_dev_from_bdaddr(link_key_notify->bdaddr.val, &device); | |
| 1871 | ✗ | bt_host_store_link_key(link_key_notify); | |
| 1872 | ✗ | break; | |
| 1873 | } | ||
| 1874 | ✗ | case BT_HCI_EVT_REMOTE_EXT_FEATURES: | |
| 1875 | { | ||
| 1876 | ✗ | struct bt_hci_evt_remote_ext_features *remote_ext_features = (struct bt_hci_evt_remote_ext_features *)bt_hci_evt_pkt->evt_data; | |
| 1877 | ✗ | printf("# BT_HCI_EVT_REMOTE_EXT_FEATURES\n"); | |
| 1878 | ✗ | bt_host_get_dev_from_handle(remote_ext_features->handle, &device); | |
| 1879 | ✗ | if (device) { | |
| 1880 | ✗ | if (remote_ext_features->status) { | |
| 1881 | ✗ | printf("# dev: %ld error: 0x%02X\n", device->ids.id, remote_ext_features->status); | |
| 1882 | } | ||
| 1883 | } | ||
| 1884 | else { | ||
| 1885 | ✗ | printf("# dev NULL!\n"); | |
| 1886 | } | ||
| 1887 | break; | ||
| 1888 | } | ||
| 1889 | ✗ | case BT_HCI_EVT_IO_CAPA_REQ: | |
| 1890 | { | ||
| 1891 | ✗ | struct bt_hci_evt_io_capa_req *io_capa_req = (struct bt_hci_evt_io_capa_req *)bt_hci_evt_pkt->evt_data; | |
| 1892 | ✗ | printf("# BT_HCI_EVT_IO_CAPA_REQ\n"); | |
| 1893 | ✗ | bt_host_get_dev_from_bdaddr(io_capa_req->bdaddr.val, &device); | |
| 1894 | ✗ | if (device) { | |
| 1895 | ✗ | bt_hci_cmd_io_capability_reply((void *)device->remote_bdaddr); | |
| 1896 | } | ||
| 1897 | break; | ||
| 1898 | } | ||
| 1899 | ✗ | case BT_HCI_EVT_USER_CONFIRM_REQ: | |
| 1900 | { | ||
| 1901 | ✗ | struct bt_hci_evt_user_confirm_req *user_confirm_req = (struct bt_hci_evt_user_confirm_req *)bt_hci_evt_pkt->evt_data; | |
| 1902 | ✗ | printf("# BT_HCI_EVT_USER_CONFIRM_REQ\n"); | |
| 1903 | ✗ | bt_host_get_dev_from_bdaddr(user_confirm_req->bdaddr.val, &device); | |
| 1904 | ✗ | if (device) { | |
| 1905 | ✗ | bt_hci_cmd_user_confirm_reply((void *)device->remote_bdaddr); | |
| 1906 | } | ||
| 1907 | break; | ||
| 1908 | } | ||
| 1909 | ✗ | case BT_HCI_EVT_LE_META_EVENT: | |
| 1910 | ✗ | bt_hci_le_meta_evt_hdlr(bt_hci_evt_pkt); | |
| 1911 | ✗ | break; | |
| 1912 | } | ||
| 1913 | ✗ | } | |
| 1914 |