/net/bluetooth/hci_event.c

http://github.com/mirrors/linux · C · 6167 lines · 4315 code · 1438 blank · 414 comment · 824 complexity · 20943b43737aa6ea0cb07baf7990615a MD5 · raw file

Large files are truncated click here to view the full file

  1. /*
  2. BlueZ - Bluetooth protocol stack for Linux
  3. Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved.
  4. Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License version 2 as
  7. published by the Free Software Foundation;
  8. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  9. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  10. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
  11. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
  12. CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
  13. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  14. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
  17. COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
  18. SOFTWARE IS DISCLAIMED.
  19. */
  20. /* Bluetooth HCI event handling. */
  21. #include <asm/unaligned.h>
  22. #include <net/bluetooth/bluetooth.h>
  23. #include <net/bluetooth/hci_core.h>
  24. #include <net/bluetooth/mgmt.h>
  25. #include "hci_request.h"
  26. #include "hci_debugfs.h"
  27. #include "a2mp.h"
  28. #include "amp.h"
  29. #include "smp.h"
  30. #define ZERO_KEY "\x00\x00\x00\x00\x00\x00\x00\x00" \
  31. "\x00\x00\x00\x00\x00\x00\x00\x00"
  32. /* Handle HCI Event packets */
  33. static void hci_cc_inquiry_cancel(struct hci_dev *hdev, struct sk_buff *skb)
  34. {
  35. __u8 status = *((__u8 *) skb->data);
  36. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  37. if (status)
  38. return;
  39. clear_bit(HCI_INQUIRY, &hdev->flags);
  40. smp_mb__after_atomic(); /* wake_up_bit advises about this barrier */
  41. wake_up_bit(&hdev->flags, HCI_INQUIRY);
  42. hci_dev_lock(hdev);
  43. /* Set discovery state to stopped if we're not doing LE active
  44. * scanning.
  45. */
  46. if (!hci_dev_test_flag(hdev, HCI_LE_SCAN) ||
  47. hdev->le_scan_type != LE_SCAN_ACTIVE)
  48. hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
  49. hci_dev_unlock(hdev);
  50. hci_conn_check_pending(hdev);
  51. }
  52. static void hci_cc_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
  53. {
  54. __u8 status = *((__u8 *) skb->data);
  55. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  56. if (status)
  57. return;
  58. hci_dev_set_flag(hdev, HCI_PERIODIC_INQ);
  59. }
  60. static void hci_cc_exit_periodic_inq(struct hci_dev *hdev, struct sk_buff *skb)
  61. {
  62. __u8 status = *((__u8 *) skb->data);
  63. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  64. if (status)
  65. return;
  66. hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ);
  67. hci_conn_check_pending(hdev);
  68. }
  69. static void hci_cc_remote_name_req_cancel(struct hci_dev *hdev,
  70. struct sk_buff *skb)
  71. {
  72. BT_DBG("%s", hdev->name);
  73. }
  74. static void hci_cc_role_discovery(struct hci_dev *hdev, struct sk_buff *skb)
  75. {
  76. struct hci_rp_role_discovery *rp = (void *) skb->data;
  77. struct hci_conn *conn;
  78. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  79. if (rp->status)
  80. return;
  81. hci_dev_lock(hdev);
  82. conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
  83. if (conn)
  84. conn->role = rp->role;
  85. hci_dev_unlock(hdev);
  86. }
  87. static void hci_cc_read_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
  88. {
  89. struct hci_rp_read_link_policy *rp = (void *) skb->data;
  90. struct hci_conn *conn;
  91. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  92. if (rp->status)
  93. return;
  94. hci_dev_lock(hdev);
  95. conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
  96. if (conn)
  97. conn->link_policy = __le16_to_cpu(rp->policy);
  98. hci_dev_unlock(hdev);
  99. }
  100. static void hci_cc_write_link_policy(struct hci_dev *hdev, struct sk_buff *skb)
  101. {
  102. struct hci_rp_write_link_policy *rp = (void *) skb->data;
  103. struct hci_conn *conn;
  104. void *sent;
  105. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  106. if (rp->status)
  107. return;
  108. sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LINK_POLICY);
  109. if (!sent)
  110. return;
  111. hci_dev_lock(hdev);
  112. conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
  113. if (conn)
  114. conn->link_policy = get_unaligned_le16(sent + 2);
  115. hci_dev_unlock(hdev);
  116. }
  117. static void hci_cc_read_def_link_policy(struct hci_dev *hdev,
  118. struct sk_buff *skb)
  119. {
  120. struct hci_rp_read_def_link_policy *rp = (void *) skb->data;
  121. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  122. if (rp->status)
  123. return;
  124. hdev->link_policy = __le16_to_cpu(rp->policy);
  125. }
  126. static void hci_cc_write_def_link_policy(struct hci_dev *hdev,
  127. struct sk_buff *skb)
  128. {
  129. __u8 status = *((__u8 *) skb->data);
  130. void *sent;
  131. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  132. if (status)
  133. return;
  134. sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_LINK_POLICY);
  135. if (!sent)
  136. return;
  137. hdev->link_policy = get_unaligned_le16(sent);
  138. }
  139. static void hci_cc_reset(struct hci_dev *hdev, struct sk_buff *skb)
  140. {
  141. __u8 status = *((__u8 *) skb->data);
  142. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  143. clear_bit(HCI_RESET, &hdev->flags);
  144. if (status)
  145. return;
  146. /* Reset all non-persistent flags */
  147. hci_dev_clear_volatile_flags(hdev);
  148. hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
  149. hdev->inq_tx_power = HCI_TX_POWER_INVALID;
  150. hdev->adv_tx_power = HCI_TX_POWER_INVALID;
  151. memset(hdev->adv_data, 0, sizeof(hdev->adv_data));
  152. hdev->adv_data_len = 0;
  153. memset(hdev->scan_rsp_data, 0, sizeof(hdev->scan_rsp_data));
  154. hdev->scan_rsp_data_len = 0;
  155. hdev->le_scan_type = LE_SCAN_PASSIVE;
  156. hdev->ssp_debug_mode = 0;
  157. hci_bdaddr_list_clear(&hdev->le_white_list);
  158. hci_bdaddr_list_clear(&hdev->le_resolv_list);
  159. }
  160. static void hci_cc_read_stored_link_key(struct hci_dev *hdev,
  161. struct sk_buff *skb)
  162. {
  163. struct hci_rp_read_stored_link_key *rp = (void *)skb->data;
  164. struct hci_cp_read_stored_link_key *sent;
  165. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  166. sent = hci_sent_cmd_data(hdev, HCI_OP_READ_STORED_LINK_KEY);
  167. if (!sent)
  168. return;
  169. if (!rp->status && sent->read_all == 0x01) {
  170. hdev->stored_max_keys = rp->max_keys;
  171. hdev->stored_num_keys = rp->num_keys;
  172. }
  173. }
  174. static void hci_cc_delete_stored_link_key(struct hci_dev *hdev,
  175. struct sk_buff *skb)
  176. {
  177. struct hci_rp_delete_stored_link_key *rp = (void *)skb->data;
  178. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  179. if (rp->status)
  180. return;
  181. if (rp->num_keys <= hdev->stored_num_keys)
  182. hdev->stored_num_keys -= rp->num_keys;
  183. else
  184. hdev->stored_num_keys = 0;
  185. }
  186. static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
  187. {
  188. __u8 status = *((__u8 *) skb->data);
  189. void *sent;
  190. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  191. sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LOCAL_NAME);
  192. if (!sent)
  193. return;
  194. hci_dev_lock(hdev);
  195. if (hci_dev_test_flag(hdev, HCI_MGMT))
  196. mgmt_set_local_name_complete(hdev, sent, status);
  197. else if (!status)
  198. memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH);
  199. hci_dev_unlock(hdev);
  200. }
  201. static void hci_cc_read_local_name(struct hci_dev *hdev, struct sk_buff *skb)
  202. {
  203. struct hci_rp_read_local_name *rp = (void *) skb->data;
  204. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  205. if (rp->status)
  206. return;
  207. if (hci_dev_test_flag(hdev, HCI_SETUP) ||
  208. hci_dev_test_flag(hdev, HCI_CONFIG))
  209. memcpy(hdev->dev_name, rp->name, HCI_MAX_NAME_LENGTH);
  210. }
  211. static void hci_cc_write_auth_enable(struct hci_dev *hdev, struct sk_buff *skb)
  212. {
  213. __u8 status = *((__u8 *) skb->data);
  214. void *sent;
  215. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  216. sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_ENABLE);
  217. if (!sent)
  218. return;
  219. hci_dev_lock(hdev);
  220. if (!status) {
  221. __u8 param = *((__u8 *) sent);
  222. if (param == AUTH_ENABLED)
  223. set_bit(HCI_AUTH, &hdev->flags);
  224. else
  225. clear_bit(HCI_AUTH, &hdev->flags);
  226. }
  227. if (hci_dev_test_flag(hdev, HCI_MGMT))
  228. mgmt_auth_enable_complete(hdev, status);
  229. hci_dev_unlock(hdev);
  230. }
  231. static void hci_cc_write_encrypt_mode(struct hci_dev *hdev, struct sk_buff *skb)
  232. {
  233. __u8 status = *((__u8 *) skb->data);
  234. __u8 param;
  235. void *sent;
  236. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  237. if (status)
  238. return;
  239. sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_ENCRYPT_MODE);
  240. if (!sent)
  241. return;
  242. param = *((__u8 *) sent);
  243. if (param)
  244. set_bit(HCI_ENCRYPT, &hdev->flags);
  245. else
  246. clear_bit(HCI_ENCRYPT, &hdev->flags);
  247. }
  248. static void hci_cc_write_scan_enable(struct hci_dev *hdev, struct sk_buff *skb)
  249. {
  250. __u8 status = *((__u8 *) skb->data);
  251. __u8 param;
  252. void *sent;
  253. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  254. sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SCAN_ENABLE);
  255. if (!sent)
  256. return;
  257. param = *((__u8 *) sent);
  258. hci_dev_lock(hdev);
  259. if (status) {
  260. hdev->discov_timeout = 0;
  261. goto done;
  262. }
  263. if (param & SCAN_INQUIRY)
  264. set_bit(HCI_ISCAN, &hdev->flags);
  265. else
  266. clear_bit(HCI_ISCAN, &hdev->flags);
  267. if (param & SCAN_PAGE)
  268. set_bit(HCI_PSCAN, &hdev->flags);
  269. else
  270. clear_bit(HCI_PSCAN, &hdev->flags);
  271. done:
  272. hci_dev_unlock(hdev);
  273. }
  274. static void hci_cc_read_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
  275. {
  276. struct hci_rp_read_class_of_dev *rp = (void *) skb->data;
  277. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  278. if (rp->status)
  279. return;
  280. memcpy(hdev->dev_class, rp->dev_class, 3);
  281. BT_DBG("%s class 0x%.2x%.2x%.2x", hdev->name,
  282. hdev->dev_class[2], hdev->dev_class[1], hdev->dev_class[0]);
  283. }
  284. static void hci_cc_write_class_of_dev(struct hci_dev *hdev, struct sk_buff *skb)
  285. {
  286. __u8 status = *((__u8 *) skb->data);
  287. void *sent;
  288. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  289. sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_CLASS_OF_DEV);
  290. if (!sent)
  291. return;
  292. hci_dev_lock(hdev);
  293. if (status == 0)
  294. memcpy(hdev->dev_class, sent, 3);
  295. if (hci_dev_test_flag(hdev, HCI_MGMT))
  296. mgmt_set_class_of_dev_complete(hdev, sent, status);
  297. hci_dev_unlock(hdev);
  298. }
  299. static void hci_cc_read_voice_setting(struct hci_dev *hdev, struct sk_buff *skb)
  300. {
  301. struct hci_rp_read_voice_setting *rp = (void *) skb->data;
  302. __u16 setting;
  303. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  304. if (rp->status)
  305. return;
  306. setting = __le16_to_cpu(rp->voice_setting);
  307. if (hdev->voice_setting == setting)
  308. return;
  309. hdev->voice_setting = setting;
  310. BT_DBG("%s voice setting 0x%4.4x", hdev->name, setting);
  311. if (hdev->notify)
  312. hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
  313. }
  314. static void hci_cc_write_voice_setting(struct hci_dev *hdev,
  315. struct sk_buff *skb)
  316. {
  317. __u8 status = *((__u8 *) skb->data);
  318. __u16 setting;
  319. void *sent;
  320. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  321. if (status)
  322. return;
  323. sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_VOICE_SETTING);
  324. if (!sent)
  325. return;
  326. setting = get_unaligned_le16(sent);
  327. if (hdev->voice_setting == setting)
  328. return;
  329. hdev->voice_setting = setting;
  330. BT_DBG("%s voice setting 0x%4.4x", hdev->name, setting);
  331. if (hdev->notify)
  332. hdev->notify(hdev, HCI_NOTIFY_VOICE_SETTING);
  333. }
  334. static void hci_cc_read_num_supported_iac(struct hci_dev *hdev,
  335. struct sk_buff *skb)
  336. {
  337. struct hci_rp_read_num_supported_iac *rp = (void *) skb->data;
  338. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  339. if (rp->status)
  340. return;
  341. hdev->num_iac = rp->num_iac;
  342. BT_DBG("%s num iac %d", hdev->name, hdev->num_iac);
  343. }
  344. static void hci_cc_write_ssp_mode(struct hci_dev *hdev, struct sk_buff *skb)
  345. {
  346. __u8 status = *((__u8 *) skb->data);
  347. struct hci_cp_write_ssp_mode *sent;
  348. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  349. sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_MODE);
  350. if (!sent)
  351. return;
  352. hci_dev_lock(hdev);
  353. if (!status) {
  354. if (sent->mode)
  355. hdev->features[1][0] |= LMP_HOST_SSP;
  356. else
  357. hdev->features[1][0] &= ~LMP_HOST_SSP;
  358. }
  359. if (hci_dev_test_flag(hdev, HCI_MGMT))
  360. mgmt_ssp_enable_complete(hdev, sent->mode, status);
  361. else if (!status) {
  362. if (sent->mode)
  363. hci_dev_set_flag(hdev, HCI_SSP_ENABLED);
  364. else
  365. hci_dev_clear_flag(hdev, HCI_SSP_ENABLED);
  366. }
  367. hci_dev_unlock(hdev);
  368. }
  369. static void hci_cc_write_sc_support(struct hci_dev *hdev, struct sk_buff *skb)
  370. {
  371. u8 status = *((u8 *) skb->data);
  372. struct hci_cp_write_sc_support *sent;
  373. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  374. sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SC_SUPPORT);
  375. if (!sent)
  376. return;
  377. hci_dev_lock(hdev);
  378. if (!status) {
  379. if (sent->support)
  380. hdev->features[1][0] |= LMP_HOST_SC;
  381. else
  382. hdev->features[1][0] &= ~LMP_HOST_SC;
  383. }
  384. if (!hci_dev_test_flag(hdev, HCI_MGMT) && !status) {
  385. if (sent->support)
  386. hci_dev_set_flag(hdev, HCI_SC_ENABLED);
  387. else
  388. hci_dev_clear_flag(hdev, HCI_SC_ENABLED);
  389. }
  390. hci_dev_unlock(hdev);
  391. }
  392. static void hci_cc_read_local_version(struct hci_dev *hdev, struct sk_buff *skb)
  393. {
  394. struct hci_rp_read_local_version *rp = (void *) skb->data;
  395. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  396. if (rp->status)
  397. return;
  398. if (hci_dev_test_flag(hdev, HCI_SETUP) ||
  399. hci_dev_test_flag(hdev, HCI_CONFIG)) {
  400. hdev->hci_ver = rp->hci_ver;
  401. hdev->hci_rev = __le16_to_cpu(rp->hci_rev);
  402. hdev->lmp_ver = rp->lmp_ver;
  403. hdev->manufacturer = __le16_to_cpu(rp->manufacturer);
  404. hdev->lmp_subver = __le16_to_cpu(rp->lmp_subver);
  405. }
  406. }
  407. static void hci_cc_read_local_commands(struct hci_dev *hdev,
  408. struct sk_buff *skb)
  409. {
  410. struct hci_rp_read_local_commands *rp = (void *) skb->data;
  411. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  412. if (rp->status)
  413. return;
  414. if (hci_dev_test_flag(hdev, HCI_SETUP) ||
  415. hci_dev_test_flag(hdev, HCI_CONFIG))
  416. memcpy(hdev->commands, rp->commands, sizeof(hdev->commands));
  417. }
  418. static void hci_cc_read_auth_payload_timeout(struct hci_dev *hdev,
  419. struct sk_buff *skb)
  420. {
  421. struct hci_rp_read_auth_payload_to *rp = (void *)skb->data;
  422. struct hci_conn *conn;
  423. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  424. if (rp->status)
  425. return;
  426. hci_dev_lock(hdev);
  427. conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
  428. if (conn)
  429. conn->auth_payload_timeout = __le16_to_cpu(rp->timeout);
  430. hci_dev_unlock(hdev);
  431. }
  432. static void hci_cc_write_auth_payload_timeout(struct hci_dev *hdev,
  433. struct sk_buff *skb)
  434. {
  435. struct hci_rp_write_auth_payload_to *rp = (void *)skb->data;
  436. struct hci_conn *conn;
  437. void *sent;
  438. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  439. if (rp->status)
  440. return;
  441. sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_AUTH_PAYLOAD_TO);
  442. if (!sent)
  443. return;
  444. hci_dev_lock(hdev);
  445. conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
  446. if (conn)
  447. conn->auth_payload_timeout = get_unaligned_le16(sent + 2);
  448. hci_dev_unlock(hdev);
  449. }
  450. static void hci_cc_read_local_features(struct hci_dev *hdev,
  451. struct sk_buff *skb)
  452. {
  453. struct hci_rp_read_local_features *rp = (void *) skb->data;
  454. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  455. if (rp->status)
  456. return;
  457. memcpy(hdev->features, rp->features, 8);
  458. /* Adjust default settings according to features
  459. * supported by device. */
  460. if (hdev->features[0][0] & LMP_3SLOT)
  461. hdev->pkt_type |= (HCI_DM3 | HCI_DH3);
  462. if (hdev->features[0][0] & LMP_5SLOT)
  463. hdev->pkt_type |= (HCI_DM5 | HCI_DH5);
  464. if (hdev->features[0][1] & LMP_HV2) {
  465. hdev->pkt_type |= (HCI_HV2);
  466. hdev->esco_type |= (ESCO_HV2);
  467. }
  468. if (hdev->features[0][1] & LMP_HV3) {
  469. hdev->pkt_type |= (HCI_HV3);
  470. hdev->esco_type |= (ESCO_HV3);
  471. }
  472. if (lmp_esco_capable(hdev))
  473. hdev->esco_type |= (ESCO_EV3);
  474. if (hdev->features[0][4] & LMP_EV4)
  475. hdev->esco_type |= (ESCO_EV4);
  476. if (hdev->features[0][4] & LMP_EV5)
  477. hdev->esco_type |= (ESCO_EV5);
  478. if (hdev->features[0][5] & LMP_EDR_ESCO_2M)
  479. hdev->esco_type |= (ESCO_2EV3);
  480. if (hdev->features[0][5] & LMP_EDR_ESCO_3M)
  481. hdev->esco_type |= (ESCO_3EV3);
  482. if (hdev->features[0][5] & LMP_EDR_3S_ESCO)
  483. hdev->esco_type |= (ESCO_2EV5 | ESCO_3EV5);
  484. }
  485. static void hci_cc_read_local_ext_features(struct hci_dev *hdev,
  486. struct sk_buff *skb)
  487. {
  488. struct hci_rp_read_local_ext_features *rp = (void *) skb->data;
  489. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  490. if (rp->status)
  491. return;
  492. if (hdev->max_page < rp->max_page)
  493. hdev->max_page = rp->max_page;
  494. if (rp->page < HCI_MAX_PAGES)
  495. memcpy(hdev->features[rp->page], rp->features, 8);
  496. }
  497. static void hci_cc_read_flow_control_mode(struct hci_dev *hdev,
  498. struct sk_buff *skb)
  499. {
  500. struct hci_rp_read_flow_control_mode *rp = (void *) skb->data;
  501. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  502. if (rp->status)
  503. return;
  504. hdev->flow_ctl_mode = rp->mode;
  505. }
  506. static void hci_cc_read_buffer_size(struct hci_dev *hdev, struct sk_buff *skb)
  507. {
  508. struct hci_rp_read_buffer_size *rp = (void *) skb->data;
  509. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  510. if (rp->status)
  511. return;
  512. hdev->acl_mtu = __le16_to_cpu(rp->acl_mtu);
  513. hdev->sco_mtu = rp->sco_mtu;
  514. hdev->acl_pkts = __le16_to_cpu(rp->acl_max_pkt);
  515. hdev->sco_pkts = __le16_to_cpu(rp->sco_max_pkt);
  516. if (test_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks)) {
  517. hdev->sco_mtu = 64;
  518. hdev->sco_pkts = 8;
  519. }
  520. hdev->acl_cnt = hdev->acl_pkts;
  521. hdev->sco_cnt = hdev->sco_pkts;
  522. BT_DBG("%s acl mtu %d:%d sco mtu %d:%d", hdev->name, hdev->acl_mtu,
  523. hdev->acl_pkts, hdev->sco_mtu, hdev->sco_pkts);
  524. }
  525. static void hci_cc_read_bd_addr(struct hci_dev *hdev, struct sk_buff *skb)
  526. {
  527. struct hci_rp_read_bd_addr *rp = (void *) skb->data;
  528. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  529. if (rp->status)
  530. return;
  531. if (test_bit(HCI_INIT, &hdev->flags))
  532. bacpy(&hdev->bdaddr, &rp->bdaddr);
  533. if (hci_dev_test_flag(hdev, HCI_SETUP))
  534. bacpy(&hdev->setup_addr, &rp->bdaddr);
  535. }
  536. static void hci_cc_read_page_scan_activity(struct hci_dev *hdev,
  537. struct sk_buff *skb)
  538. {
  539. struct hci_rp_read_page_scan_activity *rp = (void *) skb->data;
  540. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  541. if (rp->status)
  542. return;
  543. if (test_bit(HCI_INIT, &hdev->flags)) {
  544. hdev->page_scan_interval = __le16_to_cpu(rp->interval);
  545. hdev->page_scan_window = __le16_to_cpu(rp->window);
  546. }
  547. }
  548. static void hci_cc_write_page_scan_activity(struct hci_dev *hdev,
  549. struct sk_buff *skb)
  550. {
  551. u8 status = *((u8 *) skb->data);
  552. struct hci_cp_write_page_scan_activity *sent;
  553. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  554. if (status)
  555. return;
  556. sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_PAGE_SCAN_ACTIVITY);
  557. if (!sent)
  558. return;
  559. hdev->page_scan_interval = __le16_to_cpu(sent->interval);
  560. hdev->page_scan_window = __le16_to_cpu(sent->window);
  561. }
  562. static void hci_cc_read_page_scan_type(struct hci_dev *hdev,
  563. struct sk_buff *skb)
  564. {
  565. struct hci_rp_read_page_scan_type *rp = (void *) skb->data;
  566. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  567. if (rp->status)
  568. return;
  569. if (test_bit(HCI_INIT, &hdev->flags))
  570. hdev->page_scan_type = rp->type;
  571. }
  572. static void hci_cc_write_page_scan_type(struct hci_dev *hdev,
  573. struct sk_buff *skb)
  574. {
  575. u8 status = *((u8 *) skb->data);
  576. u8 *type;
  577. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  578. if (status)
  579. return;
  580. type = hci_sent_cmd_data(hdev, HCI_OP_WRITE_PAGE_SCAN_TYPE);
  581. if (type)
  582. hdev->page_scan_type = *type;
  583. }
  584. static void hci_cc_read_data_block_size(struct hci_dev *hdev,
  585. struct sk_buff *skb)
  586. {
  587. struct hci_rp_read_data_block_size *rp = (void *) skb->data;
  588. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  589. if (rp->status)
  590. return;
  591. hdev->block_mtu = __le16_to_cpu(rp->max_acl_len);
  592. hdev->block_len = __le16_to_cpu(rp->block_len);
  593. hdev->num_blocks = __le16_to_cpu(rp->num_blocks);
  594. hdev->block_cnt = hdev->num_blocks;
  595. BT_DBG("%s blk mtu %d cnt %d len %d", hdev->name, hdev->block_mtu,
  596. hdev->block_cnt, hdev->block_len);
  597. }
  598. static void hci_cc_read_clock(struct hci_dev *hdev, struct sk_buff *skb)
  599. {
  600. struct hci_rp_read_clock *rp = (void *) skb->data;
  601. struct hci_cp_read_clock *cp;
  602. struct hci_conn *conn;
  603. BT_DBG("%s", hdev->name);
  604. if (skb->len < sizeof(*rp))
  605. return;
  606. if (rp->status)
  607. return;
  608. hci_dev_lock(hdev);
  609. cp = hci_sent_cmd_data(hdev, HCI_OP_READ_CLOCK);
  610. if (!cp)
  611. goto unlock;
  612. if (cp->which == 0x00) {
  613. hdev->clock = le32_to_cpu(rp->clock);
  614. goto unlock;
  615. }
  616. conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
  617. if (conn) {
  618. conn->clock = le32_to_cpu(rp->clock);
  619. conn->clock_accuracy = le16_to_cpu(rp->accuracy);
  620. }
  621. unlock:
  622. hci_dev_unlock(hdev);
  623. }
  624. static void hci_cc_read_local_amp_info(struct hci_dev *hdev,
  625. struct sk_buff *skb)
  626. {
  627. struct hci_rp_read_local_amp_info *rp = (void *) skb->data;
  628. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  629. if (rp->status)
  630. return;
  631. hdev->amp_status = rp->amp_status;
  632. hdev->amp_total_bw = __le32_to_cpu(rp->total_bw);
  633. hdev->amp_max_bw = __le32_to_cpu(rp->max_bw);
  634. hdev->amp_min_latency = __le32_to_cpu(rp->min_latency);
  635. hdev->amp_max_pdu = __le32_to_cpu(rp->max_pdu);
  636. hdev->amp_type = rp->amp_type;
  637. hdev->amp_pal_cap = __le16_to_cpu(rp->pal_cap);
  638. hdev->amp_assoc_size = __le16_to_cpu(rp->max_assoc_size);
  639. hdev->amp_be_flush_to = __le32_to_cpu(rp->be_flush_to);
  640. hdev->amp_max_flush_to = __le32_to_cpu(rp->max_flush_to);
  641. }
  642. static void hci_cc_read_inq_rsp_tx_power(struct hci_dev *hdev,
  643. struct sk_buff *skb)
  644. {
  645. struct hci_rp_read_inq_rsp_tx_power *rp = (void *) skb->data;
  646. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  647. if (rp->status)
  648. return;
  649. hdev->inq_tx_power = rp->tx_power;
  650. }
  651. static void hci_cc_read_def_err_data_reporting(struct hci_dev *hdev,
  652. struct sk_buff *skb)
  653. {
  654. struct hci_rp_read_def_err_data_reporting *rp = (void *)skb->data;
  655. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  656. if (rp->status)
  657. return;
  658. hdev->err_data_reporting = rp->err_data_reporting;
  659. }
  660. static void hci_cc_write_def_err_data_reporting(struct hci_dev *hdev,
  661. struct sk_buff *skb)
  662. {
  663. __u8 status = *((__u8 *)skb->data);
  664. struct hci_cp_write_def_err_data_reporting *cp;
  665. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  666. if (status)
  667. return;
  668. cp = hci_sent_cmd_data(hdev, HCI_OP_WRITE_DEF_ERR_DATA_REPORTING);
  669. if (!cp)
  670. return;
  671. hdev->err_data_reporting = cp->err_data_reporting;
  672. }
  673. static void hci_cc_pin_code_reply(struct hci_dev *hdev, struct sk_buff *skb)
  674. {
  675. struct hci_rp_pin_code_reply *rp = (void *) skb->data;
  676. struct hci_cp_pin_code_reply *cp;
  677. struct hci_conn *conn;
  678. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  679. hci_dev_lock(hdev);
  680. if (hci_dev_test_flag(hdev, HCI_MGMT))
  681. mgmt_pin_code_reply_complete(hdev, &rp->bdaddr, rp->status);
  682. if (rp->status)
  683. goto unlock;
  684. cp = hci_sent_cmd_data(hdev, HCI_OP_PIN_CODE_REPLY);
  685. if (!cp)
  686. goto unlock;
  687. conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
  688. if (conn)
  689. conn->pin_length = cp->pin_len;
  690. unlock:
  691. hci_dev_unlock(hdev);
  692. }
  693. static void hci_cc_pin_code_neg_reply(struct hci_dev *hdev, struct sk_buff *skb)
  694. {
  695. struct hci_rp_pin_code_neg_reply *rp = (void *) skb->data;
  696. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  697. hci_dev_lock(hdev);
  698. if (hci_dev_test_flag(hdev, HCI_MGMT))
  699. mgmt_pin_code_neg_reply_complete(hdev, &rp->bdaddr,
  700. rp->status);
  701. hci_dev_unlock(hdev);
  702. }
  703. static void hci_cc_le_read_buffer_size(struct hci_dev *hdev,
  704. struct sk_buff *skb)
  705. {
  706. struct hci_rp_le_read_buffer_size *rp = (void *) skb->data;
  707. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  708. if (rp->status)
  709. return;
  710. hdev->le_mtu = __le16_to_cpu(rp->le_mtu);
  711. hdev->le_pkts = rp->le_max_pkt;
  712. hdev->le_cnt = hdev->le_pkts;
  713. BT_DBG("%s le mtu %d:%d", hdev->name, hdev->le_mtu, hdev->le_pkts);
  714. }
  715. static void hci_cc_le_read_local_features(struct hci_dev *hdev,
  716. struct sk_buff *skb)
  717. {
  718. struct hci_rp_le_read_local_features *rp = (void *) skb->data;
  719. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  720. if (rp->status)
  721. return;
  722. memcpy(hdev->le_features, rp->features, 8);
  723. }
  724. static void hci_cc_le_read_adv_tx_power(struct hci_dev *hdev,
  725. struct sk_buff *skb)
  726. {
  727. struct hci_rp_le_read_adv_tx_power *rp = (void *) skb->data;
  728. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  729. if (rp->status)
  730. return;
  731. hdev->adv_tx_power = rp->tx_power;
  732. }
  733. static void hci_cc_user_confirm_reply(struct hci_dev *hdev, struct sk_buff *skb)
  734. {
  735. struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
  736. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  737. hci_dev_lock(hdev);
  738. if (hci_dev_test_flag(hdev, HCI_MGMT))
  739. mgmt_user_confirm_reply_complete(hdev, &rp->bdaddr, ACL_LINK, 0,
  740. rp->status);
  741. hci_dev_unlock(hdev);
  742. }
  743. static void hci_cc_user_confirm_neg_reply(struct hci_dev *hdev,
  744. struct sk_buff *skb)
  745. {
  746. struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
  747. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  748. hci_dev_lock(hdev);
  749. if (hci_dev_test_flag(hdev, HCI_MGMT))
  750. mgmt_user_confirm_neg_reply_complete(hdev, &rp->bdaddr,
  751. ACL_LINK, 0, rp->status);
  752. hci_dev_unlock(hdev);
  753. }
  754. static void hci_cc_user_passkey_reply(struct hci_dev *hdev, struct sk_buff *skb)
  755. {
  756. struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
  757. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  758. hci_dev_lock(hdev);
  759. if (hci_dev_test_flag(hdev, HCI_MGMT))
  760. mgmt_user_passkey_reply_complete(hdev, &rp->bdaddr, ACL_LINK,
  761. 0, rp->status);
  762. hci_dev_unlock(hdev);
  763. }
  764. static void hci_cc_user_passkey_neg_reply(struct hci_dev *hdev,
  765. struct sk_buff *skb)
  766. {
  767. struct hci_rp_user_confirm_reply *rp = (void *) skb->data;
  768. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  769. hci_dev_lock(hdev);
  770. if (hci_dev_test_flag(hdev, HCI_MGMT))
  771. mgmt_user_passkey_neg_reply_complete(hdev, &rp->bdaddr,
  772. ACL_LINK, 0, rp->status);
  773. hci_dev_unlock(hdev);
  774. }
  775. static void hci_cc_read_local_oob_data(struct hci_dev *hdev,
  776. struct sk_buff *skb)
  777. {
  778. struct hci_rp_read_local_oob_data *rp = (void *) skb->data;
  779. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  780. }
  781. static void hci_cc_read_local_oob_ext_data(struct hci_dev *hdev,
  782. struct sk_buff *skb)
  783. {
  784. struct hci_rp_read_local_oob_ext_data *rp = (void *) skb->data;
  785. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  786. }
  787. static void hci_cc_le_set_random_addr(struct hci_dev *hdev, struct sk_buff *skb)
  788. {
  789. __u8 status = *((__u8 *) skb->data);
  790. bdaddr_t *sent;
  791. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  792. if (status)
  793. return;
  794. sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_RANDOM_ADDR);
  795. if (!sent)
  796. return;
  797. hci_dev_lock(hdev);
  798. bacpy(&hdev->random_addr, sent);
  799. hci_dev_unlock(hdev);
  800. }
  801. static void hci_cc_le_set_default_phy(struct hci_dev *hdev, struct sk_buff *skb)
  802. {
  803. __u8 status = *((__u8 *) skb->data);
  804. struct hci_cp_le_set_default_phy *cp;
  805. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  806. if (status)
  807. return;
  808. cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_DEFAULT_PHY);
  809. if (!cp)
  810. return;
  811. hci_dev_lock(hdev);
  812. hdev->le_tx_def_phys = cp->tx_phys;
  813. hdev->le_rx_def_phys = cp->rx_phys;
  814. hci_dev_unlock(hdev);
  815. }
  816. static void hci_cc_le_set_adv_set_random_addr(struct hci_dev *hdev,
  817. struct sk_buff *skb)
  818. {
  819. __u8 status = *((__u8 *) skb->data);
  820. struct hci_cp_le_set_adv_set_rand_addr *cp;
  821. struct adv_info *adv_instance;
  822. if (status)
  823. return;
  824. cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR);
  825. if (!cp)
  826. return;
  827. hci_dev_lock(hdev);
  828. if (!hdev->cur_adv_instance) {
  829. /* Store in hdev for instance 0 (Set adv and Directed advs) */
  830. bacpy(&hdev->random_addr, &cp->bdaddr);
  831. } else {
  832. adv_instance = hci_find_adv_instance(hdev,
  833. hdev->cur_adv_instance);
  834. if (adv_instance)
  835. bacpy(&adv_instance->random_addr, &cp->bdaddr);
  836. }
  837. hci_dev_unlock(hdev);
  838. }
  839. static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb)
  840. {
  841. __u8 *sent, status = *((__u8 *) skb->data);
  842. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  843. if (status)
  844. return;
  845. sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_ENABLE);
  846. if (!sent)
  847. return;
  848. hci_dev_lock(hdev);
  849. /* If we're doing connection initiation as peripheral. Set a
  850. * timeout in case something goes wrong.
  851. */
  852. if (*sent) {
  853. struct hci_conn *conn;
  854. hci_dev_set_flag(hdev, HCI_LE_ADV);
  855. conn = hci_lookup_le_connect(hdev);
  856. if (conn)
  857. queue_delayed_work(hdev->workqueue,
  858. &conn->le_conn_timeout,
  859. conn->conn_timeout);
  860. } else {
  861. hci_dev_clear_flag(hdev, HCI_LE_ADV);
  862. }
  863. hci_dev_unlock(hdev);
  864. }
  865. static void hci_cc_le_set_ext_adv_enable(struct hci_dev *hdev,
  866. struct sk_buff *skb)
  867. {
  868. struct hci_cp_le_set_ext_adv_enable *cp;
  869. __u8 status = *((__u8 *) skb->data);
  870. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  871. if (status)
  872. return;
  873. cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE);
  874. if (!cp)
  875. return;
  876. hci_dev_lock(hdev);
  877. if (cp->enable) {
  878. struct hci_conn *conn;
  879. hci_dev_set_flag(hdev, HCI_LE_ADV);
  880. conn = hci_lookup_le_connect(hdev);
  881. if (conn)
  882. queue_delayed_work(hdev->workqueue,
  883. &conn->le_conn_timeout,
  884. conn->conn_timeout);
  885. } else {
  886. hci_dev_clear_flag(hdev, HCI_LE_ADV);
  887. }
  888. hci_dev_unlock(hdev);
  889. }
  890. static void hci_cc_le_set_scan_param(struct hci_dev *hdev, struct sk_buff *skb)
  891. {
  892. struct hci_cp_le_set_scan_param *cp;
  893. __u8 status = *((__u8 *) skb->data);
  894. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  895. if (status)
  896. return;
  897. cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_PARAM);
  898. if (!cp)
  899. return;
  900. hci_dev_lock(hdev);
  901. hdev->le_scan_type = cp->type;
  902. hci_dev_unlock(hdev);
  903. }
  904. static void hci_cc_le_set_ext_scan_param(struct hci_dev *hdev,
  905. struct sk_buff *skb)
  906. {
  907. struct hci_cp_le_set_ext_scan_params *cp;
  908. __u8 status = *((__u8 *) skb->data);
  909. struct hci_cp_le_scan_phy_params *phy_param;
  910. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  911. if (status)
  912. return;
  913. cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_SCAN_PARAMS);
  914. if (!cp)
  915. return;
  916. phy_param = (void *)cp->data;
  917. hci_dev_lock(hdev);
  918. hdev->le_scan_type = phy_param->type;
  919. hci_dev_unlock(hdev);
  920. }
  921. static bool has_pending_adv_report(struct hci_dev *hdev)
  922. {
  923. struct discovery_state *d = &hdev->discovery;
  924. return bacmp(&d->last_adv_addr, BDADDR_ANY);
  925. }
  926. static void clear_pending_adv_report(struct hci_dev *hdev)
  927. {
  928. struct discovery_state *d = &hdev->discovery;
  929. bacpy(&d->last_adv_addr, BDADDR_ANY);
  930. d->last_adv_data_len = 0;
  931. }
  932. static void store_pending_adv_report(struct hci_dev *hdev, bdaddr_t *bdaddr,
  933. u8 bdaddr_type, s8 rssi, u32 flags,
  934. u8 *data, u8 len)
  935. {
  936. struct discovery_state *d = &hdev->discovery;
  937. bacpy(&d->last_adv_addr, bdaddr);
  938. d->last_adv_addr_type = bdaddr_type;
  939. d->last_adv_rssi = rssi;
  940. d->last_adv_flags = flags;
  941. memcpy(d->last_adv_data, data, len);
  942. d->last_adv_data_len = len;
  943. }
  944. static void le_set_scan_enable_complete(struct hci_dev *hdev, u8 enable)
  945. {
  946. hci_dev_lock(hdev);
  947. switch (enable) {
  948. case LE_SCAN_ENABLE:
  949. hci_dev_set_flag(hdev, HCI_LE_SCAN);
  950. if (hdev->le_scan_type == LE_SCAN_ACTIVE)
  951. clear_pending_adv_report(hdev);
  952. break;
  953. case LE_SCAN_DISABLE:
  954. /* We do this here instead of when setting DISCOVERY_STOPPED
  955. * since the latter would potentially require waiting for
  956. * inquiry to stop too.
  957. */
  958. if (has_pending_adv_report(hdev)) {
  959. struct discovery_state *d = &hdev->discovery;
  960. mgmt_device_found(hdev, &d->last_adv_addr, LE_LINK,
  961. d->last_adv_addr_type, NULL,
  962. d->last_adv_rssi, d->last_adv_flags,
  963. d->last_adv_data,
  964. d->last_adv_data_len, NULL, 0);
  965. }
  966. /* Cancel this timer so that we don't try to disable scanning
  967. * when it's already disabled.
  968. */
  969. cancel_delayed_work(&hdev->le_scan_disable);
  970. hci_dev_clear_flag(hdev, HCI_LE_SCAN);
  971. /* The HCI_LE_SCAN_INTERRUPTED flag indicates that we
  972. * interrupted scanning due to a connect request. Mark
  973. * therefore discovery as stopped. If this was not
  974. * because of a connect request advertising might have
  975. * been disabled because of active scanning, so
  976. * re-enable it again if necessary.
  977. */
  978. if (hci_dev_test_and_clear_flag(hdev, HCI_LE_SCAN_INTERRUPTED))
  979. hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
  980. else if (!hci_dev_test_flag(hdev, HCI_LE_ADV) &&
  981. hdev->discovery.state == DISCOVERY_FINDING)
  982. hci_req_reenable_advertising(hdev);
  983. break;
  984. default:
  985. bt_dev_err(hdev, "use of reserved LE_Scan_Enable param %d",
  986. enable);
  987. break;
  988. }
  989. hci_dev_unlock(hdev);
  990. }
  991. static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
  992. struct sk_buff *skb)
  993. {
  994. struct hci_cp_le_set_scan_enable *cp;
  995. __u8 status = *((__u8 *) skb->data);
  996. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  997. if (status)
  998. return;
  999. cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_SCAN_ENABLE);
  1000. if (!cp)
  1001. return;
  1002. le_set_scan_enable_complete(hdev, cp->enable);
  1003. }
  1004. static void hci_cc_le_set_ext_scan_enable(struct hci_dev *hdev,
  1005. struct sk_buff *skb)
  1006. {
  1007. struct hci_cp_le_set_ext_scan_enable *cp;
  1008. __u8 status = *((__u8 *) skb->data);
  1009. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1010. if (status)
  1011. return;
  1012. cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_SCAN_ENABLE);
  1013. if (!cp)
  1014. return;
  1015. le_set_scan_enable_complete(hdev, cp->enable);
  1016. }
  1017. static void hci_cc_le_read_num_adv_sets(struct hci_dev *hdev,
  1018. struct sk_buff *skb)
  1019. {
  1020. struct hci_rp_le_read_num_supported_adv_sets *rp = (void *) skb->data;
  1021. BT_DBG("%s status 0x%2.2x No of Adv sets %u", hdev->name, rp->status,
  1022. rp->num_of_sets);
  1023. if (rp->status)
  1024. return;
  1025. hdev->le_num_of_adv_sets = rp->num_of_sets;
  1026. }
  1027. static void hci_cc_le_read_white_list_size(struct hci_dev *hdev,
  1028. struct sk_buff *skb)
  1029. {
  1030. struct hci_rp_le_read_white_list_size *rp = (void *) skb->data;
  1031. BT_DBG("%s status 0x%2.2x size %u", hdev->name, rp->status, rp->size);
  1032. if (rp->status)
  1033. return;
  1034. hdev->le_white_list_size = rp->size;
  1035. }
  1036. static void hci_cc_le_clear_white_list(struct hci_dev *hdev,
  1037. struct sk_buff *skb)
  1038. {
  1039. __u8 status = *((__u8 *) skb->data);
  1040. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1041. if (status)
  1042. return;
  1043. hci_bdaddr_list_clear(&hdev->le_white_list);
  1044. }
  1045. static void hci_cc_le_add_to_white_list(struct hci_dev *hdev,
  1046. struct sk_buff *skb)
  1047. {
  1048. struct hci_cp_le_add_to_white_list *sent;
  1049. __u8 status = *((__u8 *) skb->data);
  1050. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1051. if (status)
  1052. return;
  1053. sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_WHITE_LIST);
  1054. if (!sent)
  1055. return;
  1056. hci_bdaddr_list_add(&hdev->le_white_list, &sent->bdaddr,
  1057. sent->bdaddr_type);
  1058. }
  1059. static void hci_cc_le_del_from_white_list(struct hci_dev *hdev,
  1060. struct sk_buff *skb)
  1061. {
  1062. struct hci_cp_le_del_from_white_list *sent;
  1063. __u8 status = *((__u8 *) skb->data);
  1064. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1065. if (status)
  1066. return;
  1067. sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_WHITE_LIST);
  1068. if (!sent)
  1069. return;
  1070. hci_bdaddr_list_del(&hdev->le_white_list, &sent->bdaddr,
  1071. sent->bdaddr_type);
  1072. }
  1073. static void hci_cc_le_read_supported_states(struct hci_dev *hdev,
  1074. struct sk_buff *skb)
  1075. {
  1076. struct hci_rp_le_read_supported_states *rp = (void *) skb->data;
  1077. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  1078. if (rp->status)
  1079. return;
  1080. memcpy(hdev->le_states, rp->le_states, 8);
  1081. }
  1082. static void hci_cc_le_read_def_data_len(struct hci_dev *hdev,
  1083. struct sk_buff *skb)
  1084. {
  1085. struct hci_rp_le_read_def_data_len *rp = (void *) skb->data;
  1086. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  1087. if (rp->status)
  1088. return;
  1089. hdev->le_def_tx_len = le16_to_cpu(rp->tx_len);
  1090. hdev->le_def_tx_time = le16_to_cpu(rp->tx_time);
  1091. }
  1092. static void hci_cc_le_write_def_data_len(struct hci_dev *hdev,
  1093. struct sk_buff *skb)
  1094. {
  1095. struct hci_cp_le_write_def_data_len *sent;
  1096. __u8 status = *((__u8 *) skb->data);
  1097. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1098. if (status)
  1099. return;
  1100. sent = hci_sent_cmd_data(hdev, HCI_OP_LE_WRITE_DEF_DATA_LEN);
  1101. if (!sent)
  1102. return;
  1103. hdev->le_def_tx_len = le16_to_cpu(sent->tx_len);
  1104. hdev->le_def_tx_time = le16_to_cpu(sent->tx_time);
  1105. }
  1106. static void hci_cc_le_add_to_resolv_list(struct hci_dev *hdev,
  1107. struct sk_buff *skb)
  1108. {
  1109. struct hci_cp_le_add_to_resolv_list *sent;
  1110. __u8 status = *((__u8 *) skb->data);
  1111. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1112. if (status)
  1113. return;
  1114. sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_RESOLV_LIST);
  1115. if (!sent)
  1116. return;
  1117. hci_bdaddr_list_add_with_irk(&hdev->le_resolv_list, &sent->bdaddr,
  1118. sent->bdaddr_type, sent->peer_irk,
  1119. sent->local_irk);
  1120. }
  1121. static void hci_cc_le_del_from_resolv_list(struct hci_dev *hdev,
  1122. struct sk_buff *skb)
  1123. {
  1124. struct hci_cp_le_del_from_resolv_list *sent;
  1125. __u8 status = *((__u8 *) skb->data);
  1126. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1127. if (status)
  1128. return;
  1129. sent = hci_sent_cmd_data(hdev, HCI_OP_LE_DEL_FROM_RESOLV_LIST);
  1130. if (!sent)
  1131. return;
  1132. hci_bdaddr_list_del_with_irk(&hdev->le_resolv_list, &sent->bdaddr,
  1133. sent->bdaddr_type);
  1134. }
  1135. static void hci_cc_le_clear_resolv_list(struct hci_dev *hdev,
  1136. struct sk_buff *skb)
  1137. {
  1138. __u8 status = *((__u8 *) skb->data);
  1139. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1140. if (status)
  1141. return;
  1142. hci_bdaddr_list_clear(&hdev->le_resolv_list);
  1143. }
  1144. static void hci_cc_le_read_resolv_list_size(struct hci_dev *hdev,
  1145. struct sk_buff *skb)
  1146. {
  1147. struct hci_rp_le_read_resolv_list_size *rp = (void *) skb->data;
  1148. BT_DBG("%s status 0x%2.2x size %u", hdev->name, rp->status, rp->size);
  1149. if (rp->status)
  1150. return;
  1151. hdev->le_resolv_list_size = rp->size;
  1152. }
  1153. static void hci_cc_le_set_addr_resolution_enable(struct hci_dev *hdev,
  1154. struct sk_buff *skb)
  1155. {
  1156. __u8 *sent, status = *((__u8 *) skb->data);
  1157. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1158. if (status)
  1159. return;
  1160. sent = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE);
  1161. if (!sent)
  1162. return;
  1163. hci_dev_lock(hdev);
  1164. if (*sent)
  1165. hci_dev_set_flag(hdev, HCI_LL_RPA_RESOLUTION);
  1166. else
  1167. hci_dev_clear_flag(hdev, HCI_LL_RPA_RESOLUTION);
  1168. hci_dev_unlock(hdev);
  1169. }
  1170. static void hci_cc_le_read_max_data_len(struct hci_dev *hdev,
  1171. struct sk_buff *skb)
  1172. {
  1173. struct hci_rp_le_read_max_data_len *rp = (void *) skb->data;
  1174. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  1175. if (rp->status)
  1176. return;
  1177. hdev->le_max_tx_len = le16_to_cpu(rp->tx_len);
  1178. hdev->le_max_tx_time = le16_to_cpu(rp->tx_time);
  1179. hdev->le_max_rx_len = le16_to_cpu(rp->rx_len);
  1180. hdev->le_max_rx_time = le16_to_cpu(rp->rx_time);
  1181. }
  1182. static void hci_cc_write_le_host_supported(struct hci_dev *hdev,
  1183. struct sk_buff *skb)
  1184. {
  1185. struct hci_cp_write_le_host_supported *sent;
  1186. __u8 status = *((__u8 *) skb->data);
  1187. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1188. if (status)
  1189. return;
  1190. sent = hci_sent_cmd_data(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED);
  1191. if (!sent)
  1192. return;
  1193. hci_dev_lock(hdev);
  1194. if (sent->le) {
  1195. hdev->features[1][0] |= LMP_HOST_LE;
  1196. hci_dev_set_flag(hdev, HCI_LE_ENABLED);
  1197. } else {
  1198. hdev->features[1][0] &= ~LMP_HOST_LE;
  1199. hci_dev_clear_flag(hdev, HCI_LE_ENABLED);
  1200. hci_dev_clear_flag(hdev, HCI_ADVERTISING);
  1201. }
  1202. if (sent->simul)
  1203. hdev->features[1][0] |= LMP_HOST_LE_BREDR;
  1204. else
  1205. hdev->features[1][0] &= ~LMP_HOST_LE_BREDR;
  1206. hci_dev_unlock(hdev);
  1207. }
  1208. static void hci_cc_set_adv_param(struct hci_dev *hdev, struct sk_buff *skb)
  1209. {
  1210. struct hci_cp_le_set_adv_param *cp;
  1211. u8 status = *((u8 *) skb->data);
  1212. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1213. if (status)
  1214. return;
  1215. cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_ADV_PARAM);
  1216. if (!cp)
  1217. return;
  1218. hci_dev_lock(hdev);
  1219. hdev->adv_addr_type = cp->own_address_type;
  1220. hci_dev_unlock(hdev);
  1221. }
  1222. static void hci_cc_set_ext_adv_param(struct hci_dev *hdev, struct sk_buff *skb)
  1223. {
  1224. struct hci_rp_le_set_ext_adv_params *rp = (void *) skb->data;
  1225. struct hci_cp_le_set_ext_adv_params *cp;
  1226. struct adv_info *adv_instance;
  1227. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  1228. if (rp->status)
  1229. return;
  1230. cp = hci_sent_cmd_data(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS);
  1231. if (!cp)
  1232. return;
  1233. hci_dev_lock(hdev);
  1234. hdev->adv_addr_type = cp->own_addr_type;
  1235. if (!hdev->cur_adv_instance) {
  1236. /* Store in hdev for instance 0 */
  1237. hdev->adv_tx_power = rp->tx_power;
  1238. } else {
  1239. adv_instance = hci_find_adv_instance(hdev,
  1240. hdev->cur_adv_instance);
  1241. if (adv_instance)
  1242. adv_instance->tx_power = rp->tx_power;
  1243. }
  1244. /* Update adv data as tx power is known now */
  1245. hci_req_update_adv_data(hdev, hdev->cur_adv_instance);
  1246. hci_dev_unlock(hdev);
  1247. }
  1248. static void hci_cc_read_rssi(struct hci_dev *hdev, struct sk_buff *skb)
  1249. {
  1250. struct hci_rp_read_rssi *rp = (void *) skb->data;
  1251. struct hci_conn *conn;
  1252. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  1253. if (rp->status)
  1254. return;
  1255. hci_dev_lock(hdev);
  1256. conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
  1257. if (conn)
  1258. conn->rssi = rp->rssi;
  1259. hci_dev_unlock(hdev);
  1260. }
  1261. static void hci_cc_read_tx_power(struct hci_dev *hdev, struct sk_buff *skb)
  1262. {
  1263. struct hci_cp_read_tx_power *sent;
  1264. struct hci_rp_read_tx_power *rp = (void *) skb->data;
  1265. struct hci_conn *conn;
  1266. BT_DBG("%s status 0x%2.2x", hdev->name, rp->status);
  1267. if (rp->status)
  1268. return;
  1269. sent = hci_sent_cmd_data(hdev, HCI_OP_READ_TX_POWER);
  1270. if (!sent)
  1271. return;
  1272. hci_dev_lock(hdev);
  1273. conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(rp->handle));
  1274. if (!conn)
  1275. goto unlock;
  1276. switch (sent->type) {
  1277. case 0x00:
  1278. conn->tx_power = rp->tx_power;
  1279. break;
  1280. case 0x01:
  1281. conn->max_tx_power = rp->tx_power;
  1282. break;
  1283. }
  1284. unlock:
  1285. hci_dev_unlock(hdev);
  1286. }
  1287. static void hci_cc_write_ssp_debug_mode(struct hci_dev *hdev, struct sk_buff *skb)
  1288. {
  1289. u8 status = *((u8 *) skb->data);
  1290. u8 *mode;
  1291. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1292. if (status)
  1293. return;
  1294. mode = hci_sent_cmd_data(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE);
  1295. if (mode)
  1296. hdev->ssp_debug_mode = *mode;
  1297. }
  1298. static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
  1299. {
  1300. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1301. if (status) {
  1302. hci_conn_check_pending(hdev);
  1303. return;
  1304. }
  1305. set_bit(HCI_INQUIRY, &hdev->flags);
  1306. }
  1307. static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status)
  1308. {
  1309. struct hci_cp_create_conn *cp;
  1310. struct hci_conn *conn;
  1311. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1312. cp = hci_sent_cmd_data(hdev, HCI_OP_CREATE_CONN);
  1313. if (!cp)
  1314. return;
  1315. hci_dev_lock(hdev);
  1316. conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
  1317. BT_DBG("%s bdaddr %pMR hcon %p", hdev->name, &cp->bdaddr, conn);
  1318. if (status) {
  1319. if (conn && conn->state == BT_CONNECT) {
  1320. if (status != 0x0c || conn->attempt > 2) {
  1321. conn->state = BT_CLOSED;
  1322. hci_connect_cfm(conn, status);
  1323. hci_conn_del(conn);
  1324. } else
  1325. conn->state = BT_CONNECT2;
  1326. }
  1327. } else {
  1328. if (!conn) {
  1329. conn = hci_conn_add(hdev, ACL_LINK, &cp->bdaddr,
  1330. HCI_ROLE_MASTER);
  1331. if (!conn)
  1332. bt_dev_err(hdev, "no memory for new connection");
  1333. }
  1334. }
  1335. hci_dev_unlock(hdev);
  1336. }
  1337. static void hci_cs_add_sco(struct hci_dev *hdev, __u8 status)
  1338. {
  1339. struct hci_cp_add_sco *cp;
  1340. struct hci_conn *acl, *sco;
  1341. __u16 handle;
  1342. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1343. if (!status)
  1344. return;
  1345. cp = hci_sent_cmd_data(hdev, HCI_OP_ADD_SCO);
  1346. if (!cp)
  1347. return;
  1348. handle = __le16_to_cpu(cp->handle);
  1349. BT_DBG("%s handle 0x%4.4x", hdev->name, handle);
  1350. hci_dev_lock(hdev);
  1351. acl = hci_conn_hash_lookup_handle(hdev, handle);
  1352. if (acl) {
  1353. sco = acl->link;
  1354. if (sco) {
  1355. sco->state = BT_CLOSED;
  1356. hci_connect_cfm(sco, status);
  1357. hci_conn_del(sco);
  1358. }
  1359. }
  1360. hci_dev_unlock(hdev);
  1361. }
  1362. static void hci_cs_auth_requested(struct hci_dev *hdev, __u8 status)
  1363. {
  1364. struct hci_cp_auth_requested *cp;
  1365. struct hci_conn *conn;
  1366. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1367. if (!status)
  1368. return;
  1369. cp = hci_sent_cmd_data(hdev, HCI_OP_AUTH_REQUESTED);
  1370. if (!cp)
  1371. return;
  1372. hci_dev_lock(hdev);
  1373. conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
  1374. if (conn) {
  1375. if (conn->state == BT_CONFIG) {
  1376. hci_connect_cfm(conn, status);
  1377. hci_conn_drop(conn);
  1378. }
  1379. }
  1380. hci_dev_unlock(hdev);
  1381. }
  1382. static void hci_cs_set_conn_encrypt(struct hci_dev *hdev, __u8 status)
  1383. {
  1384. struct hci_cp_set_conn_encrypt *cp;
  1385. struct hci_conn *conn;
  1386. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1387. if (!status)
  1388. return;
  1389. cp = hci_sent_cmd_data(hdev, HCI_OP_SET_CONN_ENCRYPT);
  1390. if (!cp)
  1391. return;
  1392. hci_dev_lock(hdev);
  1393. conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
  1394. if (conn) {
  1395. if (conn->state == BT_CONFIG) {
  1396. hci_connect_cfm(conn, status);
  1397. hci_conn_drop(conn);
  1398. }
  1399. }
  1400. hci_dev_unlock(hdev);
  1401. }
  1402. static int hci_outgoing_auth_needed(struct hci_dev *hdev,
  1403. struct hci_conn *conn)
  1404. {
  1405. if (conn->state != BT_CONFIG || !conn->out)
  1406. return 0;
  1407. if (conn->pending_sec_level == BT_SECURITY_SDP)
  1408. return 0;
  1409. /* Only request authentication for SSP connections or non-SSP
  1410. * devices with sec_level MEDIUM or HIGH or if MITM protection
  1411. * is requested.
  1412. */
  1413. if (!hci_conn_ssp_enabled(conn) && !(conn->auth_type & 0x01) &&
  1414. conn->pending_sec_level != BT_SECURITY_FIPS &&
  1415. conn->pending_sec_level != BT_SECURITY_HIGH &&
  1416. conn->pending_sec_level != BT_SECURITY_MEDIUM)
  1417. return 0;
  1418. return 1;
  1419. }
  1420. static int hci_resolve_name(struct hci_dev *hdev,
  1421. struct inquiry_entry *e)
  1422. {
  1423. struct hci_cp_remote_name_req cp;
  1424. memset(&cp, 0, sizeof(cp));
  1425. bacpy(&cp.bdaddr, &e->data.bdaddr);
  1426. cp.pscan_rep_mode = e->data.pscan_rep_mode;
  1427. cp.pscan_mode = e->data.pscan_mode;
  1428. cp.clock_offset = e->data.clock_offset;
  1429. return hci_send_cmd(hdev, HCI_OP_REMOTE_NAME_REQ, sizeof(cp), &cp);
  1430. }
  1431. static bool hci_resolve_next_name(struct hci_dev *hdev)
  1432. {
  1433. struct discovery_state *discov = &hdev->discovery;
  1434. struct inquiry_entry *e;
  1435. if (list_empty(&discov->resolve))
  1436. return false;
  1437. e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, NAME_NEEDED);
  1438. if (!e)
  1439. return false;
  1440. if (hci_resolve_name(hdev, e) == 0) {
  1441. e->name_state = NAME_PENDING;
  1442. return true;
  1443. }
  1444. return false;
  1445. }
  1446. static void hci_check_pending_name(struct hci_dev *hdev, struct hci_conn *conn,
  1447. bdaddr_t *bdaddr, u8 *name, u8 name_len)
  1448. {
  1449. struct discovery_state *discov = &hdev->discovery;
  1450. struct inquiry_entry *e;
  1451. /* Update the mgmt connected state if necessary. Be careful with
  1452. * conn objects that exist but are not (yet) connected however.
  1453. * Only those in BT_CONFIG or BT_CONNECTED states can be
  1454. * considered connected.
  1455. */
  1456. if (conn &&
  1457. (conn->state == BT_CONFIG || conn->state == BT_CONNECTED) &&
  1458. !test_and_set_bit(HCI_CONN_MGMT_CONNECTED, &conn->flags))
  1459. mgmt_device_connected(hdev, conn, 0, name, name_len);
  1460. if (discov->state == DISCOVERY_STOPPED)
  1461. return;
  1462. if (discov->state == DISCOVERY_STOPPING)
  1463. goto discov_complete;
  1464. if (discov->state != DISCOVERY_RESOLVING)
  1465. return;
  1466. e = hci_inquiry_cache_lookup_resolve(hdev, bdaddr, NAME_PENDING);
  1467. /* If the device was not found in a list of found devices names of which
  1468. * are pending. there is no need to continue resolving a next name as it
  1469. * will be done upon receiving another Remote Name Request Complete
  1470. * Event */
  1471. if (!e)
  1472. return;
  1473. list_del(&e->list);
  1474. if (name) {
  1475. e->name_state = NAME_KNOWN;
  1476. mgmt_remote_name(hdev, bdaddr, ACL_LINK, 0x00,
  1477. e->data.rssi, name, name_len);
  1478. } else {
  1479. e->name_state = NAME_NOT_KNOWN;
  1480. }
  1481. if (hci_resolve_next_name(hdev))
  1482. return;
  1483. discov_complete:
  1484. hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
  1485. }
  1486. static void hci_cs_remote_name_req(struct hci_dev *hdev, __u8 status)
  1487. {
  1488. struct hci_cp_remote_name_req *cp;
  1489. struct hci_conn *conn;
  1490. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1491. /* If successful wait for the name req complete event before
  1492. * checking for the need to do authentication */
  1493. if (!status)
  1494. return;
  1495. cp = hci_sent_cmd_data(hdev, HCI_OP_REMOTE_NAME_REQ);
  1496. if (!cp)
  1497. return;
  1498. hci_dev_lock(hdev);
  1499. conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &cp->bdaddr);
  1500. if (hci_dev_test_flag(hdev, HCI_MGMT))
  1501. hci_check_pending_name(hdev, conn, &cp->bdaddr, NULL, 0);
  1502. if (!conn)
  1503. goto unlock;
  1504. if (!hci_outgoing_auth_needed(hdev, conn))
  1505. goto unlock;
  1506. if (!test_and_set_bit(HCI_CONN_AUTH_PEND, &conn->flags)) {
  1507. struct hci_cp_auth_requested auth_cp;
  1508. set_bit(HCI_CONN_AUTH_INITIATOR, &conn->flags);
  1509. auth_cp.handle = __cpu_to_le16(conn->handle);
  1510. hci_send_cmd(hdev, HCI_OP_AUTH_REQUESTED,
  1511. sizeof(auth_cp), &auth_cp);
  1512. }
  1513. unlock:
  1514. hci_dev_unlock(hdev);
  1515. }
  1516. static void hci_cs_read_remote_features(struct hci_dev *hdev, __u8 status)
  1517. {
  1518. struct hci_cp_read_remote_features *cp;
  1519. struct hci_conn *conn;
  1520. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1521. if (!status)
  1522. return;
  1523. cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_FEATURES);
  1524. if (!cp)
  1525. return;
  1526. hci_dev_lock(hdev);
  1527. conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
  1528. if (conn) {
  1529. if (conn->state == BT_CONFIG) {
  1530. hci_connect_cfm(conn, status);
  1531. hci_conn_drop(conn);
  1532. }
  1533. }
  1534. hci_dev_unlock(hdev);
  1535. }
  1536. static void hci_cs_read_remote_ext_features(struct hci_dev *hdev, __u8 status)
  1537. {
  1538. struct hci_cp_read_remote_ext_features *cp;
  1539. struct hci_conn *conn;
  1540. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1541. if (!status)
  1542. return;
  1543. cp = hci_sent_cmd_data(hdev, HCI_OP_READ_REMOTE_EXT_FEATURES);
  1544. if (!cp)
  1545. return;
  1546. hci_dev_lock(hdev);
  1547. conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
  1548. if (conn) {
  1549. if (conn->state == BT_CONFIG) {
  1550. hci_connect_cfm(conn, status);
  1551. hci_conn_drop(conn);
  1552. }
  1553. }
  1554. hci_dev_unlock(hdev);
  1555. }
  1556. static void hci_cs_setup_sync_conn(struct hci_dev *hdev, __u8 status)
  1557. {
  1558. struct hci_cp_setup_sync_conn *cp;
  1559. struct hci_conn *acl, *sco;
  1560. __u16 handle;
  1561. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1562. if (!status)
  1563. return;
  1564. cp = hci_sent_cmd_data(hdev, HCI_OP_SETUP_SYNC_CONN);
  1565. if (!cp)
  1566. return;
  1567. handle = __le16_to_cpu(cp->handle);
  1568. BT_DBG("%s handle 0x%4.4x", hdev->name, handle);
  1569. hci_dev_lock(hdev);
  1570. acl = hci_conn_hash_lookup_handle(hdev, handle);
  1571. if (acl) {
  1572. sco = acl->link;
  1573. if (sco) {
  1574. sco->state = BT_CLOSED;
  1575. hci_connect_cfm(sco, status);
  1576. hci_conn_del(sco);
  1577. }
  1578. }
  1579. hci_dev_unlock(hdev);
  1580. }
  1581. static void hci_cs_sniff_mode(struct hci_dev *hdev, __u8 status)
  1582. {
  1583. struct hci_cp_sniff_mode *cp;
  1584. struct hci_conn *conn;
  1585. BT_DBG("%s status 0x%2.2x", hdev->name, status);
  1586. if (!status)
  1587. return;
  1588. cp = hci_sent_cmd_data(hdev, HCI_OP_SNIFF_MODE);
  1589. if (!cp)
  1590. return;
  1591. hci_dev_lock(hdev);
  1592. conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
  1593. if (conn) {
  1594. clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags);
  1595. if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags))
  1596. hci_sco_setup(c