• Home
  • Raw
  • Download

Lines Matching refs:hdev

53 static void hci_notify(struct hci_dev *hdev, int event)  in hci_notify()  argument
55 hci_sock_dev_event(hdev, event); in hci_notify()
60 static void hci_req_sync_complete(struct hci_dev *hdev, u8 result) in hci_req_sync_complete() argument
62 BT_DBG("%s result 0x%2.2x", hdev->name, result); in hci_req_sync_complete()
64 if (hdev->req_status == HCI_REQ_PEND) { in hci_req_sync_complete()
65 hdev->req_result = result; in hci_req_sync_complete()
66 hdev->req_status = HCI_REQ_DONE; in hci_req_sync_complete()
67 wake_up_interruptible(&hdev->req_wait_q); in hci_req_sync_complete()
71 static void hci_req_cancel(struct hci_dev *hdev, int err) in hci_req_cancel() argument
73 BT_DBG("%s err 0x%2.2x", hdev->name, err); in hci_req_cancel()
75 if (hdev->req_status == HCI_REQ_PEND) { in hci_req_cancel()
76 hdev->req_result = err; in hci_req_cancel()
77 hdev->req_status = HCI_REQ_CANCELED; in hci_req_cancel()
78 wake_up_interruptible(&hdev->req_wait_q); in hci_req_cancel()
82 static struct sk_buff *hci_get_cmd_complete(struct hci_dev *hdev, u16 opcode, in hci_get_cmd_complete() argument
89 hci_dev_lock(hdev); in hci_get_cmd_complete()
91 skb = hdev->recv_evt; in hci_get_cmd_complete()
92 hdev->recv_evt = NULL; in hci_get_cmd_complete()
94 hci_dev_unlock(hdev); in hci_get_cmd_complete()
137 struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_ev() argument
144 BT_DBG("%s", hdev->name); in __hci_cmd_sync_ev()
146 hci_req_init(&req, hdev); in __hci_cmd_sync_ev()
150 hdev->req_status = HCI_REQ_PEND; in __hci_cmd_sync_ev()
156 add_wait_queue(&hdev->req_wait_q, &wait); in __hci_cmd_sync_ev()
161 remove_wait_queue(&hdev->req_wait_q, &wait); in __hci_cmd_sync_ev()
166 switch (hdev->req_status) { in __hci_cmd_sync_ev()
168 err = -bt_to_errno(hdev->req_result); in __hci_cmd_sync_ev()
172 err = -hdev->req_result; in __hci_cmd_sync_ev()
180 hdev->req_status = hdev->req_result = 0; in __hci_cmd_sync_ev()
182 BT_DBG("%s end: err %d", hdev->name, err); in __hci_cmd_sync_ev()
187 return hci_get_cmd_complete(hdev, opcode, event); in __hci_cmd_sync_ev()
191 struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync() argument
194 return __hci_cmd_sync_ev(hdev, opcode, plen, param, 0, timeout); in __hci_cmd_sync()
199 static int __hci_req_sync(struct hci_dev *hdev, in __hci_req_sync() argument
208 BT_DBG("%s start", hdev->name); in __hci_req_sync()
210 hci_req_init(&req, hdev); in __hci_req_sync()
212 hdev->req_status = HCI_REQ_PEND; in __hci_req_sync()
218 hdev->req_status = 0; in __hci_req_sync()
231 add_wait_queue(&hdev->req_wait_q, &wait); in __hci_req_sync()
236 remove_wait_queue(&hdev->req_wait_q, &wait); in __hci_req_sync()
241 switch (hdev->req_status) { in __hci_req_sync()
243 err = -bt_to_errno(hdev->req_result); in __hci_req_sync()
247 err = -hdev->req_result; in __hci_req_sync()
255 hdev->req_status = hdev->req_result = 0; in __hci_req_sync()
257 BT_DBG("%s end: err %d", hdev->name, err); in __hci_req_sync()
262 static int hci_req_sync(struct hci_dev *hdev, in hci_req_sync() argument
269 if (!test_bit(HCI_UP, &hdev->flags)) in hci_req_sync()
273 hci_req_lock(hdev); in hci_req_sync()
274 ret = __hci_req_sync(hdev, req, opt, timeout); in hci_req_sync()
275 hci_req_unlock(hdev); in hci_req_sync()
282 BT_DBG("%s %ld", req->hdev->name, opt); in hci_reset_req()
285 set_bit(HCI_RESET, &req->hdev->flags); in hci_reset_req()
291 req->hdev->flow_ctl_mode = HCI_FLOW_CTL_MODE_PACKET_BASED; in bredr_init()
305 req->hdev->flow_ctl_mode = HCI_FLOW_CTL_MODE_BLOCK_BASED; in amp_init()
319 struct hci_dev *hdev = req->hdev; in hci_init1_req() local
321 BT_DBG("%s %ld", hdev->name, opt); in hci_init1_req()
324 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) in hci_init1_req()
327 switch (hdev->dev_type) { in hci_init1_req()
337 BT_ERR("Unknown device type %d", hdev->dev_type); in hci_init1_req()
368 if (req->hdev->hci_ver > BLUETOOTH_VER_1_1) { in bredr_setup()
376 struct hci_dev *hdev = req->hdev; in le_setup() local
394 if (!lmp_bredr_capable(hdev)) in le_setup()
395 set_bit(HCI_LE_ENABLED, &hdev->dev_flags); in le_setup()
398 static u8 hci_get_inquiry_mode(struct hci_dev *hdev) in hci_get_inquiry_mode() argument
400 if (lmp_ext_inq_capable(hdev)) in hci_get_inquiry_mode()
403 if (lmp_inq_rssi_capable(hdev)) in hci_get_inquiry_mode()
406 if (hdev->manufacturer == 11 && hdev->hci_rev == 0x00 && in hci_get_inquiry_mode()
407 hdev->lmp_subver == 0x0757) in hci_get_inquiry_mode()
410 if (hdev->manufacturer == 15) { in hci_get_inquiry_mode()
411 if (hdev->hci_rev == 0x03 && hdev->lmp_subver == 0x6963) in hci_get_inquiry_mode()
413 if (hdev->hci_rev == 0x09 && hdev->lmp_subver == 0x6963) in hci_get_inquiry_mode()
415 if (hdev->hci_rev == 0x00 && hdev->lmp_subver == 0x6965) in hci_get_inquiry_mode()
419 if (hdev->manufacturer == 31 && hdev->hci_rev == 0x2005 && in hci_get_inquiry_mode()
420 hdev->lmp_subver == 0x1805) in hci_get_inquiry_mode()
430 mode = hci_get_inquiry_mode(req->hdev); in hci_setup_inquiry_mode()
437 struct hci_dev *hdev = req->hdev; in hci_setup_event_mask() local
448 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_setup_event_mask()
451 if (lmp_bredr_capable(hdev)) { in hci_setup_event_mask()
459 if (lmp_inq_rssi_capable(hdev)) in hci_setup_event_mask()
462 if (lmp_sniffsubr_capable(hdev)) in hci_setup_event_mask()
465 if (lmp_pause_enc_capable(hdev)) in hci_setup_event_mask()
468 if (lmp_ext_inq_capable(hdev)) in hci_setup_event_mask()
471 if (lmp_no_flush_capable(hdev)) in hci_setup_event_mask()
474 if (lmp_lsto_capable(hdev)) in hci_setup_event_mask()
477 if (lmp_ssp_capable(hdev)) { in hci_setup_event_mask()
491 if (lmp_le_capable(hdev)) in hci_setup_event_mask()
496 if (lmp_le_capable(hdev)) { in hci_setup_event_mask()
506 struct hci_dev *hdev = req->hdev; in hci_init2_req() local
508 if (lmp_bredr_capable(hdev)) in hci_init2_req()
511 if (lmp_le_capable(hdev)) in hci_init2_req()
516 if (hdev->hci_ver > BLUETOOTH_VER_1_1) in hci_init2_req()
519 if (lmp_ssp_capable(hdev)) { in hci_init2_req()
520 if (test_bit(HCI_SSP_ENABLED, &hdev->dev_flags)) { in hci_init2_req()
527 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_init2_req()
534 if (lmp_inq_rssi_capable(hdev)) in hci_init2_req()
537 if (lmp_inq_tx_pwr_capable(hdev)) in hci_init2_req()
540 if (lmp_ext_feat_capable(hdev)) { in hci_init2_req()
548 if (test_bit(HCI_LINK_SECURITY, &hdev->dev_flags)) { in hci_init2_req()
557 struct hci_dev *hdev = req->hdev; in hci_setup_link_policy() local
561 if (lmp_rswitch_capable(hdev)) in hci_setup_link_policy()
563 if (lmp_hold_capable(hdev)) in hci_setup_link_policy()
565 if (lmp_sniff_capable(hdev)) in hci_setup_link_policy()
567 if (lmp_park_capable(hdev)) in hci_setup_link_policy()
576 struct hci_dev *hdev = req->hdev; in hci_set_le_support() local
580 if (!lmp_bredr_capable(hdev)) in hci_set_le_support()
585 if (test_bit(HCI_LE_ENABLED, &hdev->dev_flags)) { in hci_set_le_support()
587 cp.simul = lmp_le_br_capable(hdev); in hci_set_le_support()
590 if (cp.le != lmp_host_le_capable(hdev)) in hci_set_le_support()
597 struct hci_dev *hdev = req->hdev; in hci_init3_req() local
601 if (hdev->commands[6] & 0x80) { in hci_init3_req()
610 if (hdev->commands[5] & 0x10) in hci_init3_req()
613 if (lmp_le_capable(hdev)) { in hci_init3_req()
619 for (p = 2; p < HCI_MAX_PAGES && p <= hdev->max_page; p++) { in hci_init3_req()
628 static int __hci_init(struct hci_dev *hdev) in __hci_init() argument
632 err = __hci_req_sync(hdev, hci_init1_req, 0, HCI_INIT_TIMEOUT); in __hci_init()
640 if (hdev->dev_type != HCI_BREDR) in __hci_init()
643 err = __hci_req_sync(hdev, hci_init2_req, 0, HCI_INIT_TIMEOUT); in __hci_init()
647 return __hci_req_sync(hdev, hci_init3_req, 0, HCI_INIT_TIMEOUT); in __hci_init()
654 BT_DBG("%s %x", req->hdev->name, scan); in hci_scan_req()
664 BT_DBG("%s %x", req->hdev->name, auth); in hci_auth_req()
674 BT_DBG("%s %x", req->hdev->name, encrypt); in hci_encrypt_req()
684 BT_DBG("%s %x", req->hdev->name, policy); in hci_linkpol_req()
694 struct hci_dev *hdev = NULL, *d; in hci_dev_get() local
704 hdev = hci_dev_hold(d); in hci_dev_get()
709 return hdev; in hci_dev_get()
714 bool hci_discovery_active(struct hci_dev *hdev) in hci_discovery_active() argument
716 struct discovery_state *discov = &hdev->discovery; in hci_discovery_active()
728 void hci_discovery_set_state(struct hci_dev *hdev, int state) in hci_discovery_set_state() argument
730 BT_DBG("%s state %u -> %u", hdev->name, hdev->discovery.state, state); in hci_discovery_set_state()
732 if (hdev->discovery.state == state) in hci_discovery_set_state()
737 if (hdev->discovery.state != DISCOVERY_STARTING) in hci_discovery_set_state()
738 mgmt_discovering(hdev, 0); in hci_discovery_set_state()
743 mgmt_discovering(hdev, 1); in hci_discovery_set_state()
751 hdev->discovery.state = state; in hci_discovery_set_state()
754 static void inquiry_cache_flush(struct hci_dev *hdev) in inquiry_cache_flush() argument
756 struct discovery_state *cache = &hdev->discovery; in inquiry_cache_flush()
768 struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, in hci_inquiry_cache_lookup() argument
771 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup()
784 struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev, in hci_inquiry_cache_lookup_unknown() argument
787 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup_unknown()
800 struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev, in hci_inquiry_cache_lookup_resolve() argument
804 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup_resolve()
819 void hci_inquiry_cache_update_resolve(struct hci_dev *hdev, in hci_inquiry_cache_update_resolve() argument
822 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_update_resolve()
838 bool hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data, in hci_inquiry_cache_update() argument
841 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_update()
846 hci_remove_remote_oob_data(hdev, &data->bdaddr); in hci_inquiry_cache_update()
851 ie = hci_inquiry_cache_lookup(hdev, &data->bdaddr); in hci_inquiry_cache_update()
859 hci_inquiry_cache_update_resolve(hdev, ie); in hci_inquiry_cache_update()
896 static int inquiry_cache_dump(struct hci_dev *hdev, int num, __u8 *buf) in inquiry_cache_dump() argument
898 struct discovery_state *cache = &hdev->discovery; in inquiry_cache_dump()
927 struct hci_dev *hdev = req->hdev; in hci_inq_req() local
930 BT_DBG("%s", hdev->name); in hci_inq_req()
932 if (test_bit(HCI_INQUIRY, &hdev->flags)) in hci_inq_req()
952 struct hci_dev *hdev; in hci_inquiry() local
960 hdev = hci_dev_get(ir.dev_id); in hci_inquiry()
961 if (!hdev) in hci_inquiry()
964 hci_dev_lock(hdev); in hci_inquiry()
965 if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX || in hci_inquiry()
966 inquiry_cache_empty(hdev) || ir.flags & IREQ_CACHE_FLUSH) { in hci_inquiry()
967 inquiry_cache_flush(hdev); in hci_inquiry()
970 hci_dev_unlock(hdev); in hci_inquiry()
975 err = hci_req_sync(hdev, hci_inq_req, (unsigned long) &ir, in hci_inquiry()
983 if (wait_on_bit(&hdev->flags, HCI_INQUIRY, wait_inquiry, in hci_inquiry()
1002 hci_dev_lock(hdev); in hci_inquiry()
1003 ir.num_rsp = inquiry_cache_dump(hdev, max_rsp, buf); in hci_inquiry()
1004 hci_dev_unlock(hdev); in hci_inquiry()
1019 hci_dev_put(hdev); in hci_inquiry()
1023 static u8 create_ad(struct hci_dev *hdev, u8 *ptr) in create_ad() argument
1028 if (test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags)) in create_ad()
1031 if (!lmp_bredr_capable(hdev)) in create_ad()
1034 if (lmp_le_br_capable(hdev)) in create_ad()
1037 if (lmp_host_le_br_capable(hdev)) in create_ad()
1051 if (hdev->adv_tx_power != HCI_TX_POWER_INVALID) { in create_ad()
1054 ptr[2] = (u8) hdev->adv_tx_power; in create_ad()
1060 name_len = strlen(hdev->dev_name); in create_ad()
1072 memcpy(ptr + 2, hdev->dev_name, name_len); in create_ad()
1083 struct hci_dev *hdev = req->hdev; in hci_update_ad() local
1087 if (!lmp_le_capable(hdev)) in hci_update_ad()
1092 len = create_ad(hdev, cp.data); in hci_update_ad()
1094 if (hdev->adv_data_len == len && in hci_update_ad()
1095 memcmp(cp.data, hdev->adv_data, len) == 0) in hci_update_ad()
1098 memcpy(hdev->adv_data, cp.data, sizeof(cp.data)); in hci_update_ad()
1099 hdev->adv_data_len = len; in hci_update_ad()
1110 struct hci_dev *hdev; in hci_dev_open() local
1113 hdev = hci_dev_get(dev); in hci_dev_open()
1114 if (!hdev) in hci_dev_open()
1117 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_open()
1119 hci_req_lock(hdev); in hci_dev_open()
1121 if (test_bit(HCI_UNREGISTER, &hdev->dev_flags)) { in hci_dev_open()
1126 if (hdev->rfkill && rfkill_blocked(hdev->rfkill)) { in hci_dev_open()
1131 if (test_bit(HCI_UP, &hdev->flags)) { in hci_dev_open()
1136 if (hdev->open(hdev)) { in hci_dev_open()
1141 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_open()
1142 set_bit(HCI_INIT, &hdev->flags); in hci_dev_open()
1144 if (hdev->setup && test_bit(HCI_SETUP, &hdev->dev_flags)) in hci_dev_open()
1145 ret = hdev->setup(hdev); in hci_dev_open()
1151 if (hdev->dev_type != HCI_BREDR && !enable_hs) in hci_dev_open()
1152 set_bit(HCI_RAW, &hdev->flags); in hci_dev_open()
1154 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in hci_dev_open()
1155 set_bit(HCI_RAW, &hdev->flags); in hci_dev_open()
1157 if (!test_bit(HCI_RAW, &hdev->flags)) in hci_dev_open()
1158 ret = __hci_init(hdev); in hci_dev_open()
1161 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_open()
1164 hci_dev_hold(hdev); in hci_dev_open()
1165 set_bit(HCI_UP, &hdev->flags); in hci_dev_open()
1166 hci_notify(hdev, HCI_DEV_UP); in hci_dev_open()
1167 if (!test_bit(HCI_SETUP, &hdev->dev_flags) && in hci_dev_open()
1168 mgmt_valid_hdev(hdev)) { in hci_dev_open()
1169 hci_dev_lock(hdev); in hci_dev_open()
1170 mgmt_powered(hdev, 1); in hci_dev_open()
1171 hci_dev_unlock(hdev); in hci_dev_open()
1175 flush_work(&hdev->tx_work); in hci_dev_open()
1176 flush_work(&hdev->cmd_work); in hci_dev_open()
1177 flush_work(&hdev->rx_work); in hci_dev_open()
1179 skb_queue_purge(&hdev->cmd_q); in hci_dev_open()
1180 skb_queue_purge(&hdev->rx_q); in hci_dev_open()
1182 if (hdev->flush) in hci_dev_open()
1183 hdev->flush(hdev); in hci_dev_open()
1185 if (hdev->sent_cmd) { in hci_dev_open()
1186 kfree_skb(hdev->sent_cmd); in hci_dev_open()
1187 hdev->sent_cmd = NULL; in hci_dev_open()
1190 hdev->close(hdev); in hci_dev_open()
1191 hdev->flags = 0; in hci_dev_open()
1195 hci_req_unlock(hdev); in hci_dev_open()
1196 hci_dev_put(hdev); in hci_dev_open()
1200 static int hci_dev_do_close(struct hci_dev *hdev) in hci_dev_do_close() argument
1202 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_close()
1204 cancel_work_sync(&hdev->le_scan); in hci_dev_do_close()
1206 cancel_delayed_work(&hdev->power_off); in hci_dev_do_close()
1208 hci_req_cancel(hdev, ENODEV); in hci_dev_do_close()
1209 hci_req_lock(hdev); in hci_dev_do_close()
1211 if (!test_and_clear_bit(HCI_UP, &hdev->flags)) { in hci_dev_do_close()
1212 del_timer_sync(&hdev->cmd_timer); in hci_dev_do_close()
1213 hci_req_unlock(hdev); in hci_dev_do_close()
1218 flush_work(&hdev->tx_work); in hci_dev_do_close()
1219 flush_work(&hdev->rx_work); in hci_dev_do_close()
1221 if (hdev->discov_timeout > 0) { in hci_dev_do_close()
1222 cancel_delayed_work(&hdev->discov_off); in hci_dev_do_close()
1223 hdev->discov_timeout = 0; in hci_dev_do_close()
1224 clear_bit(HCI_DISCOVERABLE, &hdev->dev_flags); in hci_dev_do_close()
1227 if (test_and_clear_bit(HCI_SERVICE_CACHE, &hdev->dev_flags)) in hci_dev_do_close()
1228 cancel_delayed_work(&hdev->service_cache); in hci_dev_do_close()
1230 cancel_delayed_work_sync(&hdev->le_scan_disable); in hci_dev_do_close()
1232 hci_dev_lock(hdev); in hci_dev_do_close()
1233 inquiry_cache_flush(hdev); in hci_dev_do_close()
1234 hci_conn_hash_flush(hdev); in hci_dev_do_close()
1235 hci_dev_unlock(hdev); in hci_dev_do_close()
1237 hci_notify(hdev, HCI_DEV_DOWN); in hci_dev_do_close()
1239 if (hdev->flush) in hci_dev_do_close()
1240 hdev->flush(hdev); in hci_dev_do_close()
1243 skb_queue_purge(&hdev->cmd_q); in hci_dev_do_close()
1244 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_do_close()
1245 if (!test_bit(HCI_RAW, &hdev->flags) && in hci_dev_do_close()
1246 test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) { in hci_dev_do_close()
1247 set_bit(HCI_INIT, &hdev->flags); in hci_dev_do_close()
1248 __hci_req_sync(hdev, hci_reset_req, 0, HCI_CMD_TIMEOUT); in hci_dev_do_close()
1249 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_do_close()
1253 flush_work(&hdev->cmd_work); in hci_dev_do_close()
1256 skb_queue_purge(&hdev->rx_q); in hci_dev_do_close()
1257 skb_queue_purge(&hdev->cmd_q); in hci_dev_do_close()
1258 skb_queue_purge(&hdev->raw_q); in hci_dev_do_close()
1261 if (hdev->sent_cmd) { in hci_dev_do_close()
1262 del_timer_sync(&hdev->cmd_timer); in hci_dev_do_close()
1263 kfree_skb(hdev->sent_cmd); in hci_dev_do_close()
1264 hdev->sent_cmd = NULL; in hci_dev_do_close()
1267 kfree_skb(hdev->recv_evt); in hci_dev_do_close()
1268 hdev->recv_evt = NULL; in hci_dev_do_close()
1272 hdev->close(hdev); in hci_dev_do_close()
1275 hdev->flags = 0; in hci_dev_do_close()
1276 hdev->dev_flags &= ~HCI_PERSISTENT_MASK; in hci_dev_do_close()
1278 if (!test_and_clear_bit(HCI_AUTO_OFF, &hdev->dev_flags) && in hci_dev_do_close()
1279 mgmt_valid_hdev(hdev)) { in hci_dev_do_close()
1280 hci_dev_lock(hdev); in hci_dev_do_close()
1281 mgmt_powered(hdev, 0); in hci_dev_do_close()
1282 hci_dev_unlock(hdev); in hci_dev_do_close()
1286 hdev->amp_status = 0; in hci_dev_do_close()
1288 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_dev_do_close()
1289 memset(hdev->dev_class, 0, sizeof(hdev->dev_class)); in hci_dev_do_close()
1291 hci_req_unlock(hdev); in hci_dev_do_close()
1293 hci_dev_put(hdev); in hci_dev_do_close()
1299 struct hci_dev *hdev; in hci_dev_close() local
1302 hdev = hci_dev_get(dev); in hci_dev_close()
1303 if (!hdev) in hci_dev_close()
1306 if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->dev_flags)) in hci_dev_close()
1307 cancel_delayed_work(&hdev->power_off); in hci_dev_close()
1309 err = hci_dev_do_close(hdev); in hci_dev_close()
1311 hci_dev_put(hdev); in hci_dev_close()
1317 struct hci_dev *hdev; in hci_dev_reset() local
1320 hdev = hci_dev_get(dev); in hci_dev_reset()
1321 if (!hdev) in hci_dev_reset()
1324 hci_req_lock(hdev); in hci_dev_reset()
1326 if (!test_bit(HCI_UP, &hdev->flags)) in hci_dev_reset()
1330 skb_queue_purge(&hdev->rx_q); in hci_dev_reset()
1331 skb_queue_purge(&hdev->cmd_q); in hci_dev_reset()
1333 hci_dev_lock(hdev); in hci_dev_reset()
1334 inquiry_cache_flush(hdev); in hci_dev_reset()
1335 hci_conn_hash_flush(hdev); in hci_dev_reset()
1336 hci_dev_unlock(hdev); in hci_dev_reset()
1338 if (hdev->flush) in hci_dev_reset()
1339 hdev->flush(hdev); in hci_dev_reset()
1341 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_reset()
1342 hdev->acl_cnt = 0; hdev->sco_cnt = 0; hdev->le_cnt = 0; in hci_dev_reset()
1344 if (!test_bit(HCI_RAW, &hdev->flags)) in hci_dev_reset()
1345 ret = __hci_req_sync(hdev, hci_reset_req, 0, HCI_INIT_TIMEOUT); in hci_dev_reset()
1348 hci_req_unlock(hdev); in hci_dev_reset()
1349 hci_dev_put(hdev); in hci_dev_reset()
1355 struct hci_dev *hdev; in hci_dev_reset_stat() local
1358 hdev = hci_dev_get(dev); in hci_dev_reset_stat()
1359 if (!hdev) in hci_dev_reset_stat()
1362 memset(&hdev->stat, 0, sizeof(struct hci_dev_stats)); in hci_dev_reset_stat()
1364 hci_dev_put(hdev); in hci_dev_reset_stat()
1371 struct hci_dev *hdev; in hci_dev_cmd() local
1378 hdev = hci_dev_get(dr.dev_id); in hci_dev_cmd()
1379 if (!hdev) in hci_dev_cmd()
1384 err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt, in hci_dev_cmd()
1389 if (!lmp_encrypt_capable(hdev)) { in hci_dev_cmd()
1394 if (!test_bit(HCI_AUTH, &hdev->flags)) { in hci_dev_cmd()
1396 err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt, in hci_dev_cmd()
1402 err = hci_req_sync(hdev, hci_encrypt_req, dr.dev_opt, in hci_dev_cmd()
1407 err = hci_req_sync(hdev, hci_scan_req, dr.dev_opt, in hci_dev_cmd()
1412 err = hci_req_sync(hdev, hci_linkpol_req, dr.dev_opt, in hci_dev_cmd()
1417 hdev->link_mode = ((__u16) dr.dev_opt) & in hci_dev_cmd()
1422 hdev->pkt_type = (__u16) dr.dev_opt; in hci_dev_cmd()
1426 hdev->acl_mtu = *((__u16 *) &dr.dev_opt + 1); in hci_dev_cmd()
1427 hdev->acl_pkts = *((__u16 *) &dr.dev_opt + 0); in hci_dev_cmd()
1431 hdev->sco_mtu = *((__u16 *) &dr.dev_opt + 1); in hci_dev_cmd()
1432 hdev->sco_pkts = *((__u16 *) &dr.dev_opt + 0); in hci_dev_cmd()
1440 hci_dev_put(hdev); in hci_dev_cmd()
1446 struct hci_dev *hdev; in hci_get_dev_list() local
1467 list_for_each_entry(hdev, &hci_dev_list, list) { in hci_get_dev_list()
1468 if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->dev_flags)) in hci_get_dev_list()
1469 cancel_delayed_work(&hdev->power_off); in hci_get_dev_list()
1471 if (!test_bit(HCI_MGMT, &hdev->dev_flags)) in hci_get_dev_list()
1472 set_bit(HCI_PAIRABLE, &hdev->dev_flags); in hci_get_dev_list()
1474 (dr + n)->dev_id = hdev->id; in hci_get_dev_list()
1475 (dr + n)->dev_opt = hdev->flags; in hci_get_dev_list()
1493 struct hci_dev *hdev; in hci_get_dev_info() local
1500 hdev = hci_dev_get(di.dev_id); in hci_get_dev_info()
1501 if (!hdev) in hci_get_dev_info()
1504 if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->dev_flags)) in hci_get_dev_info()
1505 cancel_delayed_work_sync(&hdev->power_off); in hci_get_dev_info()
1507 if (!test_bit(HCI_MGMT, &hdev->dev_flags)) in hci_get_dev_info()
1508 set_bit(HCI_PAIRABLE, &hdev->dev_flags); in hci_get_dev_info()
1510 strcpy(di.name, hdev->name); in hci_get_dev_info()
1511 di.bdaddr = hdev->bdaddr; in hci_get_dev_info()
1512 di.type = (hdev->bus & 0x0f) | (hdev->dev_type << 4); in hci_get_dev_info()
1513 di.flags = hdev->flags; in hci_get_dev_info()
1514 di.pkt_type = hdev->pkt_type; in hci_get_dev_info()
1515 if (lmp_bredr_capable(hdev)) { in hci_get_dev_info()
1516 di.acl_mtu = hdev->acl_mtu; in hci_get_dev_info()
1517 di.acl_pkts = hdev->acl_pkts; in hci_get_dev_info()
1518 di.sco_mtu = hdev->sco_mtu; in hci_get_dev_info()
1519 di.sco_pkts = hdev->sco_pkts; in hci_get_dev_info()
1521 di.acl_mtu = hdev->le_mtu; in hci_get_dev_info()
1522 di.acl_pkts = hdev->le_pkts; in hci_get_dev_info()
1526 di.link_policy = hdev->link_policy; in hci_get_dev_info()
1527 di.link_mode = hdev->link_mode; in hci_get_dev_info()
1529 memcpy(&di.stat, &hdev->stat, sizeof(di.stat)); in hci_get_dev_info()
1530 memcpy(&di.features, &hdev->features, sizeof(di.features)); in hci_get_dev_info()
1535 hci_dev_put(hdev); in hci_get_dev_info()
1544 struct hci_dev *hdev = data; in hci_rfkill_set_block() local
1546 BT_DBG("%p name %s blocked %d", hdev, hdev->name, blocked); in hci_rfkill_set_block()
1551 hci_dev_do_close(hdev); in hci_rfkill_set_block()
1562 struct hci_dev *hdev = container_of(work, struct hci_dev, power_on); in hci_power_on() local
1565 BT_DBG("%s", hdev->name); in hci_power_on()
1567 err = hci_dev_open(hdev->id); in hci_power_on()
1569 mgmt_set_powered_failed(hdev, err); in hci_power_on()
1573 if (test_bit(HCI_AUTO_OFF, &hdev->dev_flags)) in hci_power_on()
1574 queue_delayed_work(hdev->req_workqueue, &hdev->power_off, in hci_power_on()
1577 if (test_and_clear_bit(HCI_SETUP, &hdev->dev_flags)) in hci_power_on()
1578 mgmt_index_added(hdev); in hci_power_on()
1583 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_power_off() local
1586 BT_DBG("%s", hdev->name); in hci_power_off()
1588 hci_dev_do_close(hdev); in hci_power_off()
1593 struct hci_dev *hdev; in hci_discov_off() local
1596 hdev = container_of(work, struct hci_dev, discov_off.work); in hci_discov_off()
1598 BT_DBG("%s", hdev->name); in hci_discov_off()
1600 hci_dev_lock(hdev); in hci_discov_off()
1602 hci_send_cmd(hdev, HCI_OP_WRITE_SCAN_ENABLE, sizeof(scan), &scan); in hci_discov_off()
1604 hdev->discov_timeout = 0; in hci_discov_off()
1606 hci_dev_unlock(hdev); in hci_discov_off()
1609 int hci_uuids_clear(struct hci_dev *hdev) in hci_uuids_clear() argument
1613 list_for_each_entry_safe(uuid, tmp, &hdev->uuids, list) { in hci_uuids_clear()
1621 int hci_link_keys_clear(struct hci_dev *hdev) in hci_link_keys_clear() argument
1625 list_for_each_safe(p, n, &hdev->link_keys) { in hci_link_keys_clear()
1637 int hci_smp_ltks_clear(struct hci_dev *hdev) in hci_smp_ltks_clear() argument
1641 list_for_each_entry_safe(k, tmp, &hdev->long_term_keys, list) { in hci_smp_ltks_clear()
1649 struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) in hci_find_link_key() argument
1653 list_for_each_entry(k, &hdev->link_keys, list) in hci_find_link_key()
1660 static bool hci_persistent_key(struct hci_dev *hdev, struct hci_conn *conn, in hci_persistent_key() argument
1696 struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, __le16 ediv, u8 rand[8]) in hci_find_ltk() argument
1700 list_for_each_entry(k, &hdev->long_term_keys, list) { in hci_find_ltk()
1711 struct smp_ltk *hci_find_ltk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_find_ltk_by_addr() argument
1716 list_for_each_entry(k, &hdev->long_term_keys, list) in hci_find_ltk_by_addr()
1724 int hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, int new_key, in hci_add_link_key() argument
1731 old_key = hci_find_link_key(hdev, bdaddr); in hci_add_link_key()
1740 list_add(&key->list, &hdev->link_keys); in hci_add_link_key()
1743 BT_DBG("%s key for %pMR type %u", hdev->name, bdaddr, type); in hci_add_link_key()
1767 persistent = hci_persistent_key(hdev, conn, type, old_key_type); in hci_add_link_key()
1769 mgmt_new_link_key(hdev, key, persistent); in hci_add_link_key()
1777 int hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type, u8 type, in hci_add_ltk() argument
1786 old_key = hci_find_ltk_by_addr(hdev, bdaddr, addr_type); in hci_add_ltk()
1793 list_add(&key->list, &hdev->long_term_keys); in hci_add_ltk()
1809 mgmt_new_ltk(hdev, key, 1); in hci_add_ltk()
1814 int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) in hci_remove_link_key() argument
1818 key = hci_find_link_key(hdev, bdaddr); in hci_remove_link_key()
1822 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_link_key()
1830 int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr) in hci_remove_ltk() argument
1834 list_for_each_entry_safe(k, tmp, &hdev->long_term_keys, list) { in hci_remove_ltk()
1838 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_ltk()
1850 struct hci_dev *hdev = (void *) arg; in hci_cmd_timeout() local
1852 if (hdev->sent_cmd) { in hci_cmd_timeout()
1853 struct hci_command_hdr *sent = (void *) hdev->sent_cmd->data; in hci_cmd_timeout()
1856 BT_ERR("%s command 0x%4.4x tx timeout", hdev->name, opcode); in hci_cmd_timeout()
1858 BT_ERR("%s command tx timeout", hdev->name); in hci_cmd_timeout()
1861 atomic_set(&hdev->cmd_cnt, 1); in hci_cmd_timeout()
1862 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_cmd_timeout()
1865 struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, in hci_find_remote_oob_data() argument
1870 list_for_each_entry(data, &hdev->remote_oob_data, list) in hci_find_remote_oob_data()
1877 int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr) in hci_remove_remote_oob_data() argument
1881 data = hci_find_remote_oob_data(hdev, bdaddr); in hci_remove_remote_oob_data()
1885 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_remote_oob_data()
1893 int hci_remote_oob_data_clear(struct hci_dev *hdev) in hci_remote_oob_data_clear() argument
1897 list_for_each_entry_safe(data, n, &hdev->remote_oob_data, list) { in hci_remote_oob_data_clear()
1905 int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash, in hci_add_remote_oob_data() argument
1910 data = hci_find_remote_oob_data(hdev, bdaddr); in hci_add_remote_oob_data()
1918 list_add(&data->list, &hdev->remote_oob_data); in hci_add_remote_oob_data()
1924 BT_DBG("%s for %pMR", hdev->name, bdaddr); in hci_add_remote_oob_data()
1929 struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr) in hci_blacklist_lookup() argument
1933 list_for_each_entry(b, &hdev->blacklist, list) in hci_blacklist_lookup()
1940 int hci_blacklist_clear(struct hci_dev *hdev) in hci_blacklist_clear() argument
1944 list_for_each_safe(p, n, &hdev->blacklist) { in hci_blacklist_clear()
1956 int hci_blacklist_add(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type) in hci_blacklist_add() argument
1963 if (hci_blacklist_lookup(hdev, bdaddr)) in hci_blacklist_add()
1972 list_add(&entry->list, &hdev->blacklist); in hci_blacklist_add()
1974 return mgmt_device_blocked(hdev, bdaddr, type); in hci_blacklist_add()
1977 int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type) in hci_blacklist_del() argument
1982 return hci_blacklist_clear(hdev); in hci_blacklist_del()
1984 entry = hci_blacklist_lookup(hdev, bdaddr); in hci_blacklist_del()
1991 return mgmt_device_unblocked(hdev, bdaddr, type); in hci_blacklist_del()
2018 static int hci_do_le_scan(struct hci_dev *hdev, u8 type, u16 interval, in hci_do_le_scan() argument
2025 BT_DBG("%s", hdev->name); in hci_do_le_scan()
2027 if (test_bit(HCI_LE_SCAN, &hdev->dev_flags)) in hci_do_le_scan()
2034 hci_req_lock(hdev); in hci_do_le_scan()
2036 err = __hci_req_sync(hdev, le_scan_param_req, (unsigned long) &param, in hci_do_le_scan()
2039 err = __hci_req_sync(hdev, le_scan_enable_req, 0, timeo); in hci_do_le_scan()
2041 hci_req_unlock(hdev); in hci_do_le_scan()
2046 queue_delayed_work(hdev->workqueue, &hdev->le_scan_disable, in hci_do_le_scan()
2052 int hci_cancel_le_scan(struct hci_dev *hdev) in hci_cancel_le_scan() argument
2054 BT_DBG("%s", hdev->name); in hci_cancel_le_scan()
2056 if (!test_bit(HCI_LE_SCAN, &hdev->dev_flags)) in hci_cancel_le_scan()
2059 if (cancel_delayed_work(&hdev->le_scan_disable)) { in hci_cancel_le_scan()
2064 hci_send_cmd(hdev, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp); in hci_cancel_le_scan()
2072 struct hci_dev *hdev = container_of(work, struct hci_dev, in le_scan_disable_work() local
2076 BT_DBG("%s", hdev->name); in le_scan_disable_work()
2080 hci_send_cmd(hdev, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp); in le_scan_disable_work()
2085 struct hci_dev *hdev = container_of(work, struct hci_dev, le_scan); in le_scan_work() local
2086 struct le_scan_params *param = &hdev->le_scan_params; in le_scan_work()
2088 BT_DBG("%s", hdev->name); in le_scan_work()
2090 hci_do_le_scan(hdev, param->type, param->interval, param->window, in le_scan_work()
2094 int hci_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window, in hci_le_scan() argument
2097 struct le_scan_params *param = &hdev->le_scan_params; in hci_le_scan()
2099 BT_DBG("%s", hdev->name); in hci_le_scan()
2101 if (test_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags)) in hci_le_scan()
2104 if (work_busy(&hdev->le_scan)) in hci_le_scan()
2112 queue_work(system_long_wq, &hdev->le_scan); in hci_le_scan()
2120 struct hci_dev *hdev; in hci_alloc_dev() local
2122 hdev = kzalloc(sizeof(struct hci_dev), GFP_KERNEL); in hci_alloc_dev()
2123 if (!hdev) in hci_alloc_dev()
2126 hdev->pkt_type = (HCI_DM1 | HCI_DH1 | HCI_HV1); in hci_alloc_dev()
2127 hdev->esco_type = (ESCO_HV1); in hci_alloc_dev()
2128 hdev->link_mode = (HCI_LM_ACCEPT); in hci_alloc_dev()
2129 hdev->io_capability = 0x03; /* No Input No Output */ in hci_alloc_dev()
2130 hdev->inq_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev()
2131 hdev->adv_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev()
2133 hdev->sniff_max_interval = 800; in hci_alloc_dev()
2134 hdev->sniff_min_interval = 80; in hci_alloc_dev()
2136 mutex_init(&hdev->lock); in hci_alloc_dev()
2137 mutex_init(&hdev->req_lock); in hci_alloc_dev()
2139 INIT_LIST_HEAD(&hdev->mgmt_pending); in hci_alloc_dev()
2140 INIT_LIST_HEAD(&hdev->blacklist); in hci_alloc_dev()
2141 INIT_LIST_HEAD(&hdev->uuids); in hci_alloc_dev()
2142 INIT_LIST_HEAD(&hdev->link_keys); in hci_alloc_dev()
2143 INIT_LIST_HEAD(&hdev->long_term_keys); in hci_alloc_dev()
2144 INIT_LIST_HEAD(&hdev->remote_oob_data); in hci_alloc_dev()
2145 INIT_LIST_HEAD(&hdev->conn_hash.list); in hci_alloc_dev()
2147 INIT_WORK(&hdev->rx_work, hci_rx_work); in hci_alloc_dev()
2148 INIT_WORK(&hdev->cmd_work, hci_cmd_work); in hci_alloc_dev()
2149 INIT_WORK(&hdev->tx_work, hci_tx_work); in hci_alloc_dev()
2150 INIT_WORK(&hdev->power_on, hci_power_on); in hci_alloc_dev()
2151 INIT_WORK(&hdev->le_scan, le_scan_work); in hci_alloc_dev()
2153 INIT_DELAYED_WORK(&hdev->power_off, hci_power_off); in hci_alloc_dev()
2154 INIT_DELAYED_WORK(&hdev->discov_off, hci_discov_off); in hci_alloc_dev()
2155 INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable_work); in hci_alloc_dev()
2157 skb_queue_head_init(&hdev->rx_q); in hci_alloc_dev()
2158 skb_queue_head_init(&hdev->cmd_q); in hci_alloc_dev()
2159 skb_queue_head_init(&hdev->raw_q); in hci_alloc_dev()
2161 init_waitqueue_head(&hdev->req_wait_q); in hci_alloc_dev()
2163 setup_timer(&hdev->cmd_timer, hci_cmd_timeout, (unsigned long) hdev); in hci_alloc_dev()
2165 hci_init_sysfs(hdev); in hci_alloc_dev()
2166 discovery_init(hdev); in hci_alloc_dev()
2168 return hdev; in hci_alloc_dev()
2173 void hci_free_dev(struct hci_dev *hdev) in hci_free_dev() argument
2176 put_device(&hdev->dev); in hci_free_dev()
2181 int hci_register_dev(struct hci_dev *hdev) in hci_register_dev() argument
2185 if (!hdev->open || !hdev->close) in hci_register_dev()
2191 switch (hdev->dev_type) { in hci_register_dev()
2205 sprintf(hdev->name, "hci%d", id); in hci_register_dev()
2206 hdev->id = id; in hci_register_dev()
2208 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); in hci_register_dev()
2211 list_add(&hdev->list, &hci_dev_list); in hci_register_dev()
2214 hdev->workqueue = alloc_workqueue(hdev->name, WQ_HIGHPRI | WQ_UNBOUND | in hci_register_dev()
2216 if (!hdev->workqueue) { in hci_register_dev()
2221 hdev->req_workqueue = alloc_workqueue(hdev->name, in hci_register_dev()
2224 if (!hdev->req_workqueue) { in hci_register_dev()
2225 destroy_workqueue(hdev->workqueue); in hci_register_dev()
2230 error = hci_add_sysfs(hdev); in hci_register_dev()
2234 hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev, in hci_register_dev()
2236 hdev); in hci_register_dev()
2237 if (hdev->rfkill) { in hci_register_dev()
2238 if (rfkill_register(hdev->rfkill) < 0) { in hci_register_dev()
2239 rfkill_destroy(hdev->rfkill); in hci_register_dev()
2240 hdev->rfkill = NULL; in hci_register_dev()
2244 set_bit(HCI_SETUP, &hdev->dev_flags); in hci_register_dev()
2246 if (hdev->dev_type != HCI_AMP) in hci_register_dev()
2247 set_bit(HCI_AUTO_OFF, &hdev->dev_flags); in hci_register_dev()
2249 hci_notify(hdev, HCI_DEV_REG); in hci_register_dev()
2250 hci_dev_hold(hdev); in hci_register_dev()
2252 queue_work(hdev->req_workqueue, &hdev->power_on); in hci_register_dev()
2257 destroy_workqueue(hdev->workqueue); in hci_register_dev()
2258 destroy_workqueue(hdev->req_workqueue); in hci_register_dev()
2260 ida_simple_remove(&hci_index_ida, hdev->id); in hci_register_dev()
2262 list_del(&hdev->list); in hci_register_dev()
2270 void hci_unregister_dev(struct hci_dev *hdev) in hci_unregister_dev() argument
2274 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); in hci_unregister_dev()
2276 set_bit(HCI_UNREGISTER, &hdev->dev_flags); in hci_unregister_dev()
2278 id = hdev->id; in hci_unregister_dev()
2281 list_del(&hdev->list); in hci_unregister_dev()
2284 hci_dev_do_close(hdev); in hci_unregister_dev()
2287 kfree_skb(hdev->reassembly[i]); in hci_unregister_dev()
2289 cancel_work_sync(&hdev->power_on); in hci_unregister_dev()
2291 if (!test_bit(HCI_INIT, &hdev->flags) && in hci_unregister_dev()
2292 !test_bit(HCI_SETUP, &hdev->dev_flags)) { in hci_unregister_dev()
2293 hci_dev_lock(hdev); in hci_unregister_dev()
2294 mgmt_index_removed(hdev); in hci_unregister_dev()
2295 hci_dev_unlock(hdev); in hci_unregister_dev()
2300 BUG_ON(!list_empty(&hdev->mgmt_pending)); in hci_unregister_dev()
2302 hci_notify(hdev, HCI_DEV_UNREG); in hci_unregister_dev()
2304 if (hdev->rfkill) { in hci_unregister_dev()
2305 rfkill_unregister(hdev->rfkill); in hci_unregister_dev()
2306 rfkill_destroy(hdev->rfkill); in hci_unregister_dev()
2309 hci_del_sysfs(hdev); in hci_unregister_dev()
2311 destroy_workqueue(hdev->workqueue); in hci_unregister_dev()
2312 destroy_workqueue(hdev->req_workqueue); in hci_unregister_dev()
2314 hci_dev_lock(hdev); in hci_unregister_dev()
2315 hci_blacklist_clear(hdev); in hci_unregister_dev()
2316 hci_uuids_clear(hdev); in hci_unregister_dev()
2317 hci_link_keys_clear(hdev); in hci_unregister_dev()
2318 hci_smp_ltks_clear(hdev); in hci_unregister_dev()
2319 hci_remote_oob_data_clear(hdev); in hci_unregister_dev()
2320 hci_dev_unlock(hdev); in hci_unregister_dev()
2322 hci_dev_put(hdev); in hci_unregister_dev()
2329 int hci_suspend_dev(struct hci_dev *hdev) in hci_suspend_dev() argument
2331 hci_notify(hdev, HCI_DEV_SUSPEND); in hci_suspend_dev()
2337 int hci_resume_dev(struct hci_dev *hdev) in hci_resume_dev() argument
2339 hci_notify(hdev, HCI_DEV_RESUME); in hci_resume_dev()
2347 struct hci_dev *hdev = (struct hci_dev *) skb->dev; in hci_recv_frame() local
2348 if (!hdev || (!test_bit(HCI_UP, &hdev->flags) in hci_recv_frame()
2349 && !test_bit(HCI_INIT, &hdev->flags))) { in hci_recv_frame()
2360 skb_queue_tail(&hdev->rx_q, skb); in hci_recv_frame()
2361 queue_work(hdev->workqueue, &hdev->rx_work); in hci_recv_frame()
2367 static int hci_reassembly(struct hci_dev *hdev, int type, void *data, in hci_reassembly() argument
2380 skb = hdev->reassembly[index]; in hci_reassembly()
2406 skb->dev = (void *) hdev; in hci_reassembly()
2407 hdev->reassembly[index] = skb; in hci_reassembly()
2429 hdev->reassembly[index] = NULL; in hci_reassembly()
2442 hdev->reassembly[index] = NULL; in hci_reassembly()
2455 hdev->reassembly[index] = NULL; in hci_reassembly()
2468 hdev->reassembly[index] = NULL; in hci_reassembly()
2476 int hci_recv_fragment(struct hci_dev *hdev, int type, void *data, int count) in hci_recv_fragment() argument
2484 rem = hci_reassembly(hdev, type, data, count, type - 1); in hci_recv_fragment()
2498 int hci_recv_stream_fragment(struct hci_dev *hdev, void *data, int count) in hci_recv_stream_fragment() argument
2504 struct sk_buff *skb = hdev->reassembly[STREAM_REASSEMBLY]; in hci_recv_stream_fragment()
2518 rem = hci_reassembly(hdev, type, data, count, in hci_recv_stream_fragment()
2559 struct hci_dev *hdev = (struct hci_dev *) skb->dev; in hci_send_frame() local
2561 if (!hdev) { in hci_send_frame()
2566 BT_DBG("%s type %d len %d", hdev->name, bt_cb(skb)->pkt_type, skb->len); in hci_send_frame()
2572 hci_send_to_monitor(hdev, skb); in hci_send_frame()
2574 if (atomic_read(&hdev->promisc)) { in hci_send_frame()
2576 hci_send_to_sock(hdev, skb); in hci_send_frame()
2582 return hdev->send(skb); in hci_send_frame()
2585 void hci_req_init(struct hci_request *req, struct hci_dev *hdev) in hci_req_init() argument
2588 req->hdev = hdev; in hci_req_init()
2594 struct hci_dev *hdev = req->hdev; in hci_req_run() local
2615 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in hci_req_run()
2616 skb_queue_splice_tail(&req->cmd_q, &hdev->cmd_q); in hci_req_run()
2617 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in hci_req_run()
2619 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_req_run()
2624 static struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode, in hci_prepare_cmd() argument
2645 skb->dev = (void *) hdev; in hci_prepare_cmd()
2651 int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, in hci_send_cmd() argument
2656 BT_DBG("%s opcode 0x%4.4x plen %d", hdev->name, opcode, plen); in hci_send_cmd()
2658 skb = hci_prepare_cmd(hdev, opcode, plen, param); in hci_send_cmd()
2660 BT_ERR("%s no memory for command", hdev->name); in hci_send_cmd()
2669 skb_queue_tail(&hdev->cmd_q, skb); in hci_send_cmd()
2670 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_send_cmd()
2679 struct hci_dev *hdev = req->hdev; in hci_req_add_ev() local
2682 BT_DBG("%s opcode 0x%4.4x plen %d", hdev->name, opcode, plen); in hci_req_add_ev()
2690 skb = hci_prepare_cmd(hdev, opcode, plen, param); in hci_req_add_ev()
2693 hdev->name, opcode); in hci_req_add_ev()
2713 void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode) in hci_sent_cmd_data() argument
2717 if (!hdev->sent_cmd) in hci_sent_cmd_data()
2720 hdr = (void *) hdev->sent_cmd->data; in hci_sent_cmd_data()
2725 BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode); in hci_sent_cmd_data()
2727 return hdev->sent_cmd->data + HCI_COMMAND_HDR_SIZE; in hci_sent_cmd_data()
2747 struct hci_dev *hdev = conn->hdev; in hci_queue_acl() local
2755 switch (hdev->dev_type) { in hci_queue_acl()
2763 BT_ERR("%s unknown dev_type %d", hdev->name, hdev->dev_type); in hci_queue_acl()
2770 BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
2775 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
2789 skb->dev = (void *) hdev; in hci_queue_acl()
2793 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
2804 struct hci_dev *hdev = chan->conn->hdev; in hci_send_acl() local
2806 BT_DBG("%s chan %p flags 0x%4.4x", hdev->name, chan, flags); in hci_send_acl()
2808 skb->dev = (void *) hdev; in hci_send_acl()
2812 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_acl()
2818 struct hci_dev *hdev = conn->hdev; in hci_send_sco() local
2821 BT_DBG("%s len %d", hdev->name, skb->len); in hci_send_sco()
2830 skb->dev = (void *) hdev; in hci_send_sco()
2834 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_sco()
2840 static struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, in hci_low_sent() argument
2843 struct hci_conn_hash *h = &hdev->conn_hash; in hci_low_sent()
2866 if (hci_conn_num(hdev, type) == num) in hci_low_sent()
2877 cnt = hdev->acl_cnt; in hci_low_sent()
2881 cnt = hdev->sco_cnt; in hci_low_sent()
2884 cnt = hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt; in hci_low_sent()
2900 static void hci_link_tx_to(struct hci_dev *hdev, __u8 type) in hci_link_tx_to() argument
2902 struct hci_conn_hash *h = &hdev->conn_hash; in hci_link_tx_to()
2905 BT_ERR("%s link tx timeout", hdev->name); in hci_link_tx_to()
2913 hdev->name, &c->dst); in hci_link_tx_to()
2921 static struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type, in hci_chan_sent() argument
2924 struct hci_conn_hash *h = &hdev->conn_hash; in hci_chan_sent()
2930 BT_DBG("%s", hdev->name); in hci_chan_sent()
2969 if (hci_conn_num(hdev, type) == conn_num) in hci_chan_sent()
2980 cnt = hdev->acl_cnt; in hci_chan_sent()
2983 cnt = hdev->block_cnt; in hci_chan_sent()
2987 cnt = hdev->sco_cnt; in hci_chan_sent()
2990 cnt = hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt; in hci_chan_sent()
3003 static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type) in hci_prio_recalculate() argument
3005 struct hci_conn_hash *h = &hdev->conn_hash; in hci_prio_recalculate()
3009 BT_DBG("%s", hdev->name); in hci_prio_recalculate()
3045 if (hci_conn_num(hdev, type) == num) in hci_prio_recalculate()
3053 static inline int __get_blocks(struct hci_dev *hdev, struct sk_buff *skb) in __get_blocks() argument
3056 return DIV_ROUND_UP(skb->len - HCI_ACL_HDR_SIZE, hdev->block_len); in __get_blocks()
3059 static void __check_timeout(struct hci_dev *hdev, unsigned int cnt) in __check_timeout() argument
3061 if (!test_bit(HCI_RAW, &hdev->flags)) { in __check_timeout()
3064 if (!cnt && time_after(jiffies, hdev->acl_last_tx + in __check_timeout()
3066 hci_link_tx_to(hdev, ACL_LINK); in __check_timeout()
3070 static void hci_sched_acl_pkt(struct hci_dev *hdev) in hci_sched_acl_pkt() argument
3072 unsigned int cnt = hdev->acl_cnt; in hci_sched_acl_pkt()
3077 __check_timeout(hdev, cnt); in hci_sched_acl_pkt()
3079 while (hdev->acl_cnt && in hci_sched_acl_pkt()
3080 (chan = hci_chan_sent(hdev, ACL_LINK, &quote))) { in hci_sched_acl_pkt()
3096 hdev->acl_last_tx = jiffies; in hci_sched_acl_pkt()
3098 hdev->acl_cnt--; in hci_sched_acl_pkt()
3104 if (cnt != hdev->acl_cnt) in hci_sched_acl_pkt()
3105 hci_prio_recalculate(hdev, ACL_LINK); in hci_sched_acl_pkt()
3108 static void hci_sched_acl_blk(struct hci_dev *hdev) in hci_sched_acl_blk() argument
3110 unsigned int cnt = hdev->block_cnt; in hci_sched_acl_blk()
3116 __check_timeout(hdev, cnt); in hci_sched_acl_blk()
3118 BT_DBG("%s", hdev->name); in hci_sched_acl_blk()
3120 if (hdev->dev_type == HCI_AMP) in hci_sched_acl_blk()
3125 while (hdev->block_cnt > 0 && in hci_sched_acl_blk()
3126 (chan = hci_chan_sent(hdev, type, &quote))) { in hci_sched_acl_blk()
3140 blocks = __get_blocks(hdev, skb); in hci_sched_acl_blk()
3141 if (blocks > hdev->block_cnt) in hci_sched_acl_blk()
3148 hdev->acl_last_tx = jiffies; in hci_sched_acl_blk()
3150 hdev->block_cnt -= blocks; in hci_sched_acl_blk()
3158 if (cnt != hdev->block_cnt) in hci_sched_acl_blk()
3159 hci_prio_recalculate(hdev, type); in hci_sched_acl_blk()
3162 static void hci_sched_acl(struct hci_dev *hdev) in hci_sched_acl() argument
3164 BT_DBG("%s", hdev->name); in hci_sched_acl()
3167 if (!hci_conn_num(hdev, ACL_LINK) && hdev->dev_type == HCI_BREDR) in hci_sched_acl()
3171 if (!hci_conn_num(hdev, AMP_LINK) && hdev->dev_type == HCI_AMP) in hci_sched_acl()
3174 switch (hdev->flow_ctl_mode) { in hci_sched_acl()
3176 hci_sched_acl_pkt(hdev); in hci_sched_acl()
3180 hci_sched_acl_blk(hdev); in hci_sched_acl()
3186 static void hci_sched_sco(struct hci_dev *hdev) in hci_sched_sco() argument
3192 BT_DBG("%s", hdev->name); in hci_sched_sco()
3194 if (!hci_conn_num(hdev, SCO_LINK)) in hci_sched_sco()
3197 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, SCO_LINK, &quote))) { in hci_sched_sco()
3209 static void hci_sched_esco(struct hci_dev *hdev) in hci_sched_esco() argument
3215 BT_DBG("%s", hdev->name); in hci_sched_esco()
3217 if (!hci_conn_num(hdev, ESCO_LINK)) in hci_sched_esco()
3220 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, ESCO_LINK, in hci_sched_esco()
3233 static void hci_sched_le(struct hci_dev *hdev) in hci_sched_le() argument
3239 BT_DBG("%s", hdev->name); in hci_sched_le()
3241 if (!hci_conn_num(hdev, LE_LINK)) in hci_sched_le()
3244 if (!test_bit(HCI_RAW, &hdev->flags)) { in hci_sched_le()
3247 if (!hdev->le_cnt && hdev->le_pkts && in hci_sched_le()
3248 time_after(jiffies, hdev->le_last_tx + HZ * 45)) in hci_sched_le()
3249 hci_link_tx_to(hdev, LE_LINK); in hci_sched_le()
3252 cnt = hdev->le_pkts ? hdev->le_cnt : hdev->acl_cnt; in hci_sched_le()
3254 while (cnt && (chan = hci_chan_sent(hdev, LE_LINK, &quote))) { in hci_sched_le()
3267 hdev->le_last_tx = jiffies; in hci_sched_le()
3275 if (hdev->le_pkts) in hci_sched_le()
3276 hdev->le_cnt = cnt; in hci_sched_le()
3278 hdev->acl_cnt = cnt; in hci_sched_le()
3281 hci_prio_recalculate(hdev, LE_LINK); in hci_sched_le()
3286 struct hci_dev *hdev = container_of(work, struct hci_dev, tx_work); in hci_tx_work() local
3289 BT_DBG("%s acl %d sco %d le %d", hdev->name, hdev->acl_cnt, in hci_tx_work()
3290 hdev->sco_cnt, hdev->le_cnt); in hci_tx_work()
3294 hci_sched_acl(hdev); in hci_tx_work()
3296 hci_sched_sco(hdev); in hci_tx_work()
3298 hci_sched_esco(hdev); in hci_tx_work()
3300 hci_sched_le(hdev); in hci_tx_work()
3303 while ((skb = skb_dequeue(&hdev->raw_q))) in hci_tx_work()
3310 static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_acldata_packet() argument
3322 BT_DBG("%s len %d handle 0x%4.4x flags 0x%4.4x", hdev->name, skb->len, in hci_acldata_packet()
3325 hdev->stat.acl_rx++; in hci_acldata_packet()
3327 hci_dev_lock(hdev); in hci_acldata_packet()
3328 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_acldata_packet()
3329 hci_dev_unlock(hdev); in hci_acldata_packet()
3339 hdev->name, handle); in hci_acldata_packet()
3346 static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_scodata_packet() argument
3356 BT_DBG("%s len %d handle 0x%4.4x", hdev->name, skb->len, handle); in hci_scodata_packet()
3358 hdev->stat.sco_rx++; in hci_scodata_packet()
3360 hci_dev_lock(hdev); in hci_scodata_packet()
3361 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_scodata_packet()
3362 hci_dev_unlock(hdev); in hci_scodata_packet()
3370 hdev->name, handle); in hci_scodata_packet()
3376 static bool hci_req_is_complete(struct hci_dev *hdev) in hci_req_is_complete() argument
3380 skb = skb_peek(&hdev->cmd_q); in hci_req_is_complete()
3387 static void hci_resend_last(struct hci_dev *hdev) in hci_resend_last() argument
3393 if (!hdev->sent_cmd) in hci_resend_last()
3396 sent = (void *) hdev->sent_cmd->data; in hci_resend_last()
3401 skb = skb_clone(hdev->sent_cmd, GFP_KERNEL); in hci_resend_last()
3405 skb_queue_head(&hdev->cmd_q, skb); in hci_resend_last()
3406 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_resend_last()
3409 void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status) in hci_req_cmd_complete() argument
3420 if (!hci_sent_cmd_data(hdev, opcode)) { in hci_req_cmd_complete()
3427 if (test_bit(HCI_INIT, &hdev->flags) && opcode == HCI_OP_RESET) in hci_req_cmd_complete()
3428 hci_resend_last(hdev); in hci_req_cmd_complete()
3436 if (!status && !hci_req_is_complete(hdev)) in hci_req_cmd_complete()
3443 if (hdev->sent_cmd) { in hci_req_cmd_complete()
3444 req_complete = bt_cb(hdev->sent_cmd)->req.complete; in hci_req_cmd_complete()
3450 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in hci_req_cmd_complete()
3451 while ((skb = __skb_dequeue(&hdev->cmd_q))) { in hci_req_cmd_complete()
3453 __skb_queue_head(&hdev->cmd_q, skb); in hci_req_cmd_complete()
3460 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in hci_req_cmd_complete()
3464 req_complete(hdev, status); in hci_req_cmd_complete()
3469 struct hci_dev *hdev = container_of(work, struct hci_dev, rx_work); in hci_rx_work() local
3472 BT_DBG("%s", hdev->name); in hci_rx_work()
3474 while ((skb = skb_dequeue(&hdev->rx_q))) { in hci_rx_work()
3476 hci_send_to_monitor(hdev, skb); in hci_rx_work()
3478 if (atomic_read(&hdev->promisc)) { in hci_rx_work()
3480 hci_send_to_sock(hdev, skb); in hci_rx_work()
3483 if (test_bit(HCI_RAW, &hdev->flags)) { in hci_rx_work()
3488 if (test_bit(HCI_INIT, &hdev->flags)) { in hci_rx_work()
3501 BT_DBG("%s Event packet", hdev->name); in hci_rx_work()
3502 hci_event_packet(hdev, skb); in hci_rx_work()
3506 BT_DBG("%s ACL data packet", hdev->name); in hci_rx_work()
3507 hci_acldata_packet(hdev, skb); in hci_rx_work()
3511 BT_DBG("%s SCO data packet", hdev->name); in hci_rx_work()
3512 hci_scodata_packet(hdev, skb); in hci_rx_work()
3524 struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_work); in hci_cmd_work() local
3527 BT_DBG("%s cmd_cnt %d cmd queued %d", hdev->name, in hci_cmd_work()
3528 atomic_read(&hdev->cmd_cnt), skb_queue_len(&hdev->cmd_q)); in hci_cmd_work()
3531 if (atomic_read(&hdev->cmd_cnt)) { in hci_cmd_work()
3532 skb = skb_dequeue(&hdev->cmd_q); in hci_cmd_work()
3536 kfree_skb(hdev->sent_cmd); in hci_cmd_work()
3538 hdev->sent_cmd = skb_clone(skb, GFP_ATOMIC); in hci_cmd_work()
3539 if (hdev->sent_cmd) { in hci_cmd_work()
3540 atomic_dec(&hdev->cmd_cnt); in hci_cmd_work()
3542 if (test_bit(HCI_RESET, &hdev->flags)) in hci_cmd_work()
3543 del_timer(&hdev->cmd_timer); in hci_cmd_work()
3545 mod_timer(&hdev->cmd_timer, in hci_cmd_work()
3548 skb_queue_head(&hdev->cmd_q, skb); in hci_cmd_work()
3549 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_cmd_work()
3554 int hci_do_inquiry(struct hci_dev *hdev, u8 length) in hci_do_inquiry() argument
3560 BT_DBG("%s", hdev->name); in hci_do_inquiry()
3562 if (test_bit(HCI_INQUIRY, &hdev->flags)) in hci_do_inquiry()
3565 inquiry_cache_flush(hdev); in hci_do_inquiry()
3571 return hci_send_cmd(hdev, HCI_OP_INQUIRY, sizeof(cp), &cp); in hci_do_inquiry()
3574 int hci_cancel_inquiry(struct hci_dev *hdev) in hci_cancel_inquiry() argument
3576 BT_DBG("%s", hdev->name); in hci_cancel_inquiry()
3578 if (!test_bit(HCI_INQUIRY, &hdev->flags)) in hci_cancel_inquiry()
3581 return hci_send_cmd(hdev, HCI_OP_INQUIRY_CANCEL, 0, NULL); in hci_cancel_inquiry()