hci_request.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289
  1. /*
  2. BlueZ - Bluetooth protocol stack for Linux
  3. Copyright (C) 2014 Intel Corporation
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License version 2 as
  6. published by the Free Software Foundation;
  7. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  8. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  9. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
  10. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
  11. CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
  12. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
  16. COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
  17. SOFTWARE IS DISCLAIMED.
  18. */
  19. #include <net/bluetooth/bluetooth.h>
  20. #include <net/bluetooth/hci_core.h>
  21. #include "smp.h"
  22. #include "hci_request.h"
  23. #define HCI_REQ_DONE 0
  24. #define HCI_REQ_PEND 1
  25. #define HCI_REQ_CANCELED 2
  26. void hci_req_init(struct hci_request *req, struct hci_dev *hdev)
  27. {
  28. skb_queue_head_init(&req->cmd_q);
  29. req->hdev = hdev;
  30. req->err = 0;
  31. }
  32. static int req_run(struct hci_request *req, hci_req_complete_t complete,
  33. hci_req_complete_skb_t complete_skb)
  34. {
  35. struct hci_dev *hdev = req->hdev;
  36. struct sk_buff *skb;
  37. unsigned long flags;
  38. BT_DBG("length %u", skb_queue_len(&req->cmd_q));
  39. /* If an error occurred during request building, remove all HCI
  40. * commands queued on the HCI request queue.
  41. */
  42. if (req->err) {
  43. skb_queue_purge(&req->cmd_q);
  44. return req->err;
  45. }
  46. /* Do not allow empty requests */
  47. if (skb_queue_empty(&req->cmd_q))
  48. return -ENODATA;
  49. skb = skb_peek_tail(&req->cmd_q);
  50. if (complete) {
  51. bt_cb(skb)->hci.req_complete = complete;
  52. } else if (complete_skb) {
  53. bt_cb(skb)->hci.req_complete_skb = complete_skb;
  54. bt_cb(skb)->hci.req_flags |= HCI_REQ_SKB;
  55. }
  56. spin_lock_irqsave(&hdev->cmd_q.lock, flags);
  57. skb_queue_splice_tail(&req->cmd_q, &hdev->cmd_q);
  58. spin_unlock_irqrestore(&hdev->cmd_q.lock, flags);
  59. queue_work(hdev->workqueue, &hdev->cmd_work);
  60. return 0;
  61. }
  62. int hci_req_run(struct hci_request *req, hci_req_complete_t complete)
  63. {
  64. return req_run(req, complete, NULL);
  65. }
  66. int hci_req_run_skb(struct hci_request *req, hci_req_complete_skb_t complete)
  67. {
  68. return req_run(req, NULL, complete);
  69. }
  70. static void hci_req_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode,
  71. struct sk_buff *skb)
  72. {
  73. BT_DBG("%s result 0x%2.2x", hdev->name, result);
  74. if (hdev->req_status == HCI_REQ_PEND) {
  75. hdev->req_result = result;
  76. hdev->req_status = HCI_REQ_DONE;
  77. if (skb)
  78. hdev->req_skb = skb_get(skb);
  79. wake_up_interruptible(&hdev->req_wait_q);
  80. }
  81. }
  82. void hci_req_sync_cancel(struct hci_dev *hdev, int err)
  83. {
  84. BT_DBG("%s err 0x%2.2x", hdev->name, err);
  85. if (hdev->req_status == HCI_REQ_PEND) {
  86. hdev->req_result = err;
  87. hdev->req_status = HCI_REQ_CANCELED;
  88. wake_up_interruptible(&hdev->req_wait_q);
  89. }
  90. }
  91. struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen,
  92. const void *param, u8 event, u32 timeout)
  93. {
  94. DECLARE_WAITQUEUE(wait, current);
  95. struct hci_request req;
  96. struct sk_buff *skb;
  97. int err = 0;
  98. BT_DBG("%s", hdev->name);
  99. hci_req_init(&req, hdev);
  100. hci_req_add_ev(&req, opcode, plen, param, event);
  101. hdev->req_status = HCI_REQ_PEND;
  102. add_wait_queue(&hdev->req_wait_q, &wait);
  103. set_current_state(TASK_INTERRUPTIBLE);
  104. err = hci_req_run_skb(&req, hci_req_sync_complete);
  105. if (err < 0) {
  106. remove_wait_queue(&hdev->req_wait_q, &wait);
  107. set_current_state(TASK_RUNNING);
  108. return ERR_PTR(err);
  109. }
  110. schedule_timeout(timeout);
  111. remove_wait_queue(&hdev->req_wait_q, &wait);
  112. if (signal_pending(current))
  113. return ERR_PTR(-EINTR);
  114. switch (hdev->req_status) {
  115. case HCI_REQ_DONE:
  116. err = -bt_to_errno(hdev->req_result);
  117. break;
  118. case HCI_REQ_CANCELED:
  119. err = -hdev->req_result;
  120. break;
  121. default:
  122. err = -ETIMEDOUT;
  123. break;
  124. }
  125. hdev->req_status = hdev->req_result = 0;
  126. skb = hdev->req_skb;
  127. hdev->req_skb = NULL;
  128. BT_DBG("%s end: err %d", hdev->name, err);
  129. if (err < 0) {
  130. kfree_skb(skb);
  131. return ERR_PTR(err);
  132. }
  133. if (!skb)
  134. return ERR_PTR(-ENODATA);
  135. return skb;
  136. }
  137. EXPORT_SYMBOL(__hci_cmd_sync_ev);
  138. struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
  139. const void *param, u32 timeout)
  140. {
  141. return __hci_cmd_sync_ev(hdev, opcode, plen, param, 0, timeout);
  142. }
  143. EXPORT_SYMBOL(__hci_cmd_sync);
  144. /* Execute request and wait for completion. */
  145. int __hci_req_sync(struct hci_dev *hdev, int (*func)(struct hci_request *req,
  146. unsigned long opt),
  147. unsigned long opt, u32 timeout, u8 *hci_status)
  148. {
  149. struct hci_request req;
  150. DECLARE_WAITQUEUE(wait, current);
  151. int err = 0;
  152. BT_DBG("%s start", hdev->name);
  153. hci_req_init(&req, hdev);
  154. hdev->req_status = HCI_REQ_PEND;
  155. err = func(&req, opt);
  156. if (err) {
  157. if (hci_status)
  158. *hci_status = HCI_ERROR_UNSPECIFIED;
  159. return err;
  160. }
  161. add_wait_queue(&hdev->req_wait_q, &wait);
  162. set_current_state(TASK_INTERRUPTIBLE);
  163. err = hci_req_run_skb(&req, hci_req_sync_complete);
  164. if (err < 0) {
  165. hdev->req_status = 0;
  166. remove_wait_queue(&hdev->req_wait_q, &wait);
  167. set_current_state(TASK_RUNNING);
  168. /* ENODATA means the HCI request command queue is empty.
  169. * This can happen when a request with conditionals doesn't
  170. * trigger any commands to be sent. This is normal behavior
  171. * and should not trigger an error return.
  172. */
  173. if (err == -ENODATA)
  174. return 0;
  175. return err;
  176. }
  177. schedule_timeout(timeout);
  178. remove_wait_queue(&hdev->req_wait_q, &wait);
  179. if (signal_pending(current))
  180. return -EINTR;
  181. switch (hdev->req_status) {
  182. case HCI_REQ_DONE:
  183. err = -bt_to_errno(hdev->req_result);
  184. if (hci_status)
  185. *hci_status = hdev->req_result;
  186. break;
  187. case HCI_REQ_CANCELED:
  188. err = -hdev->req_result;
  189. if (hci_status)
  190. *hci_status = HCI_ERROR_UNSPECIFIED;
  191. break;
  192. default:
  193. err = -ETIMEDOUT;
  194. if (hci_status)
  195. *hci_status = HCI_ERROR_UNSPECIFIED;
  196. break;
  197. }
  198. hdev->req_status = hdev->req_result = 0;
  199. BT_DBG("%s end: err %d", hdev->name, err);
  200. return err;
  201. }
  202. int hci_req_sync(struct hci_dev *hdev, int (*req)(struct hci_request *req,
  203. unsigned long opt),
  204. unsigned long opt, u32 timeout, u8 *hci_status)
  205. {
  206. int ret;
  207. if (!test_bit(HCI_UP, &hdev->flags))
  208. return -ENETDOWN;
  209. /* Serialize all requests */
  210. hci_req_sync_lock(hdev);
  211. ret = __hci_req_sync(hdev, req, opt, timeout, hci_status);
  212. hci_req_sync_unlock(hdev);
  213. return ret;
  214. }
  215. struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode, u32 plen,
  216. const void *param)
  217. {
  218. int len = HCI_COMMAND_HDR_SIZE + plen;
  219. struct hci_command_hdr *hdr;
  220. struct sk_buff *skb;
  221. skb = bt_skb_alloc(len, GFP_ATOMIC);
  222. if (!skb)
  223. return NULL;
  224. hdr = (struct hci_command_hdr *) skb_put(skb, HCI_COMMAND_HDR_SIZE);
  225. hdr->opcode = cpu_to_le16(opcode);
  226. hdr->plen = plen;
  227. if (plen)
  228. memcpy(skb_put(skb, plen), param, plen);
  229. BT_DBG("skb len %d", skb->len);
  230. hci_skb_pkt_type(skb) = HCI_COMMAND_PKT;
  231. hci_skb_opcode(skb) = opcode;
  232. return skb;
  233. }
  234. /* Queue a command to an asynchronous HCI request */
  235. void hci_req_add_ev(struct hci_request *req, u16 opcode, u32 plen,
  236. const void *param, u8 event)
  237. {
  238. struct hci_dev *hdev = req->hdev;
  239. struct sk_buff *skb;
  240. BT_DBG("%s opcode 0x%4.4x plen %d", hdev->name, opcode, plen);
  241. /* If an error occurred during request building, there is no point in
  242. * queueing the HCI command. We can simply return.
  243. */
  244. if (req->err)
  245. return;
  246. skb = hci_prepare_cmd(hdev, opcode, plen, param);
  247. if (!skb) {
  248. BT_ERR("%s no memory for command (opcode 0x%4.4x)",
  249. hdev->name, opcode);
  250. req->err = -ENOMEM;
  251. return;
  252. }
  253. if (skb_queue_empty(&req->cmd_q))
  254. bt_cb(skb)->hci.req_flags |= HCI_REQ_START;
  255. bt_cb(skb)->hci.req_event = event;
  256. skb_queue_tail(&req->cmd_q, skb);
  257. }
  258. void hci_req_add(struct hci_request *req, u16 opcode, u32 plen,
  259. const void *param)
  260. {
  261. hci_req_add_ev(req, opcode, plen, param, 0);
  262. }
  263. void hci_req_add_le_scan_disable(struct hci_request *req)
  264. {
  265. struct hci_cp_le_set_scan_enable cp;
  266. memset(&cp, 0, sizeof(cp));
  267. cp.enable = LE_SCAN_DISABLE;
  268. hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
  269. }
  270. static void add_to_white_list(struct hci_request *req,
  271. struct hci_conn_params *params)
  272. {
  273. struct hci_cp_le_add_to_white_list cp;
  274. cp.bdaddr_type = params->addr_type;
  275. bacpy(&cp.bdaddr, &params->addr);
  276. hci_req_add(req, HCI_OP_LE_ADD_TO_WHITE_LIST, sizeof(cp), &cp);
  277. }
  278. static u8 update_white_list(struct hci_request *req)
  279. {
  280. struct hci_dev *hdev = req->hdev;
  281. struct hci_conn_params *params;
  282. struct bdaddr_list *b;
  283. uint8_t white_list_entries = 0;
  284. /* Go through the current white list programmed into the
  285. * controller one by one and check if that address is still
  286. * in the list of pending connections or list of devices to
  287. * report. If not present in either list, then queue the
  288. * command to remove it from the controller.
  289. */
  290. list_for_each_entry(b, &hdev->le_white_list, list) {
  291. struct hci_cp_le_del_from_white_list cp;
  292. if (hci_pend_le_action_lookup(&hdev->pend_le_conns,
  293. &b->bdaddr, b->bdaddr_type) ||
  294. hci_pend_le_action_lookup(&hdev->pend_le_reports,
  295. &b->bdaddr, b->bdaddr_type)) {
  296. white_list_entries++;
  297. continue;
  298. }
  299. cp.bdaddr_type = b->bdaddr_type;
  300. bacpy(&cp.bdaddr, &b->bdaddr);
  301. hci_req_add(req, HCI_OP_LE_DEL_FROM_WHITE_LIST,
  302. sizeof(cp), &cp);
  303. }
  304. /* Since all no longer valid white list entries have been
  305. * removed, walk through the list of pending connections
  306. * and ensure that any new device gets programmed into
  307. * the controller.
  308. *
  309. * If the list of the devices is larger than the list of
  310. * available white list entries in the controller, then
  311. * just abort and return filer policy value to not use the
  312. * white list.
  313. */
  314. list_for_each_entry(params, &hdev->pend_le_conns, action) {
  315. if (hci_bdaddr_list_lookup(&hdev->le_white_list,
  316. &params->addr, params->addr_type))
  317. continue;
  318. if (white_list_entries >= hdev->le_white_list_size) {
  319. /* Select filter policy to accept all advertising */
  320. return 0x00;
  321. }
  322. if (hci_find_irk_by_addr(hdev, &params->addr,
  323. params->addr_type)) {
  324. /* White list can not be used with RPAs */
  325. return 0x00;
  326. }
  327. white_list_entries++;
  328. add_to_white_list(req, params);
  329. }
  330. /* After adding all new pending connections, walk through
  331. * the list of pending reports and also add these to the
  332. * white list if there is still space.
  333. */
  334. list_for_each_entry(params, &hdev->pend_le_reports, action) {
  335. if (hci_bdaddr_list_lookup(&hdev->le_white_list,
  336. &params->addr, params->addr_type))
  337. continue;
  338. if (white_list_entries >= hdev->le_white_list_size) {
  339. /* Select filter policy to accept all advertising */
  340. return 0x00;
  341. }
  342. if (hci_find_irk_by_addr(hdev, &params->addr,
  343. params->addr_type)) {
  344. /* White list can not be used with RPAs */
  345. return 0x00;
  346. }
  347. white_list_entries++;
  348. add_to_white_list(req, params);
  349. }
  350. /* Select filter policy to use white list */
  351. return 0x01;
  352. }
  353. void hci_req_add_le_passive_scan(struct hci_request *req)
  354. {
  355. struct hci_cp_le_set_scan_param param_cp;
  356. struct hci_cp_le_set_scan_enable enable_cp;
  357. struct hci_dev *hdev = req->hdev;
  358. u8 own_addr_type;
  359. u8 filter_policy;
  360. /* Set require_privacy to false since no SCAN_REQ are send
  361. * during passive scanning. Not using an non-resolvable address
  362. * here is important so that peer devices using direct
  363. * advertising with our address will be correctly reported
  364. * by the controller.
  365. */
  366. if (hci_update_random_address(req, false, &own_addr_type))
  367. return;
  368. /* Adding or removing entries from the white list must
  369. * happen before enabling scanning. The controller does
  370. * not allow white list modification while scanning.
  371. */
  372. filter_policy = update_white_list(req);
  373. /* When the controller is using random resolvable addresses and
  374. * with that having LE privacy enabled, then controllers with
  375. * Extended Scanner Filter Policies support can now enable support
  376. * for handling directed advertising.
  377. *
  378. * So instead of using filter polices 0x00 (no whitelist)
  379. * and 0x01 (whitelist enabled) use the new filter policies
  380. * 0x02 (no whitelist) and 0x03 (whitelist enabled).
  381. */
  382. if (hci_dev_test_flag(hdev, HCI_PRIVACY) &&
  383. (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY))
  384. filter_policy |= 0x02;
  385. memset(&param_cp, 0, sizeof(param_cp));
  386. param_cp.type = LE_SCAN_PASSIVE;
  387. param_cp.interval = cpu_to_le16(hdev->le_scan_interval);
  388. param_cp.window = cpu_to_le16(hdev->le_scan_window);
  389. param_cp.own_address_type = own_addr_type;
  390. param_cp.filter_policy = filter_policy;
  391. hci_req_add(req, HCI_OP_LE_SET_SCAN_PARAM, sizeof(param_cp),
  392. &param_cp);
  393. memset(&enable_cp, 0, sizeof(enable_cp));
  394. enable_cp.enable = LE_SCAN_ENABLE;
  395. enable_cp.filter_dup = LE_SCAN_FILTER_DUP_ENABLE;
  396. hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(enable_cp),
  397. &enable_cp);
  398. }
  399. static void set_random_addr(struct hci_request *req, bdaddr_t *rpa)
  400. {
  401. struct hci_dev *hdev = req->hdev;
  402. /* If we're advertising or initiating an LE connection we can't
  403. * go ahead and change the random address at this time. This is
  404. * because the eventual initiator address used for the
  405. * subsequently created connection will be undefined (some
  406. * controllers use the new address and others the one we had
  407. * when the operation started).
  408. *
  409. * In this kind of scenario skip the update and let the random
  410. * address be updated at the next cycle.
  411. */
  412. if (hci_dev_test_flag(hdev, HCI_LE_ADV) ||
  413. hci_lookup_le_connect(hdev)) {
  414. BT_DBG("Deferring random address update");
  415. hci_dev_set_flag(hdev, HCI_RPA_EXPIRED);
  416. return;
  417. }
  418. hci_req_add(req, HCI_OP_LE_SET_RANDOM_ADDR, 6, rpa);
  419. }
  420. int hci_update_random_address(struct hci_request *req, bool require_privacy,
  421. u8 *own_addr_type)
  422. {
  423. struct hci_dev *hdev = req->hdev;
  424. int err;
  425. /* If privacy is enabled use a resolvable private address. If
  426. * current RPA has expired or there is something else than
  427. * the current RPA in use, then generate a new one.
  428. */
  429. if (hci_dev_test_flag(hdev, HCI_PRIVACY)) {
  430. int to;
  431. *own_addr_type = ADDR_LE_DEV_RANDOM;
  432. if (!hci_dev_test_and_clear_flag(hdev, HCI_RPA_EXPIRED) &&
  433. !bacmp(&hdev->random_addr, &hdev->rpa))
  434. return 0;
  435. err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa);
  436. if (err < 0) {
  437. BT_ERR("%s failed to generate new RPA", hdev->name);
  438. return err;
  439. }
  440. set_random_addr(req, &hdev->rpa);
  441. to = msecs_to_jiffies(hdev->rpa_timeout * 1000);
  442. queue_delayed_work(hdev->workqueue, &hdev->rpa_expired, to);
  443. return 0;
  444. }
  445. /* In case of required privacy without resolvable private address,
  446. * use an non-resolvable private address. This is useful for active
  447. * scanning and non-connectable advertising.
  448. */
  449. if (require_privacy) {
  450. bdaddr_t nrpa;
  451. while (true) {
  452. /* The non-resolvable private address is generated
  453. * from random six bytes with the two most significant
  454. * bits cleared.
  455. */
  456. get_random_bytes(&nrpa, 6);
  457. nrpa.b[5] &= 0x3f;
  458. /* The non-resolvable private address shall not be
  459. * equal to the public address.
  460. */
  461. if (bacmp(&hdev->bdaddr, &nrpa))
  462. break;
  463. }
  464. *own_addr_type = ADDR_LE_DEV_RANDOM;
  465. set_random_addr(req, &nrpa);
  466. return 0;
  467. }
  468. /* If forcing static address is in use or there is no public
  469. * address use the static address as random address (but skip
  470. * the HCI command if the current random address is already the
  471. * static one.
  472. *
  473. * In case BR/EDR has been disabled on a dual-mode controller
  474. * and a static address has been configured, then use that
  475. * address instead of the public BR/EDR address.
  476. */
  477. if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) ||
  478. !bacmp(&hdev->bdaddr, BDADDR_ANY) ||
  479. (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) &&
  480. bacmp(&hdev->static_addr, BDADDR_ANY))) {
  481. *own_addr_type = ADDR_LE_DEV_RANDOM;
  482. if (bacmp(&hdev->static_addr, &hdev->random_addr))
  483. hci_req_add(req, HCI_OP_LE_SET_RANDOM_ADDR, 6,
  484. &hdev->static_addr);
  485. return 0;
  486. }
  487. /* Neither privacy nor static address is being used so use a
  488. * public address.
  489. */
  490. *own_addr_type = ADDR_LE_DEV_PUBLIC;
  491. return 0;
  492. }
  493. static bool disconnected_whitelist_entries(struct hci_dev *hdev)
  494. {
  495. struct bdaddr_list *b;
  496. list_for_each_entry(b, &hdev->whitelist, list) {
  497. struct hci_conn *conn;
  498. conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &b->bdaddr);
  499. if (!conn)
  500. return true;
  501. if (conn->state != BT_CONNECTED && conn->state != BT_CONFIG)
  502. return true;
  503. }
  504. return false;
  505. }
  506. void __hci_update_page_scan(struct hci_request *req)
  507. {
  508. struct hci_dev *hdev = req->hdev;
  509. u8 scan;
  510. if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED))
  511. return;
  512. if (!hdev_is_powered(hdev))
  513. return;
  514. if (mgmt_powering_down(hdev))
  515. return;
  516. if (hci_dev_test_flag(hdev, HCI_CONNECTABLE) ||
  517. disconnected_whitelist_entries(hdev))
  518. scan = SCAN_PAGE;
  519. else
  520. scan = SCAN_DISABLED;
  521. if (test_bit(HCI_PSCAN, &hdev->flags) == !!(scan & SCAN_PAGE))
  522. return;
  523. if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE))
  524. scan |= SCAN_INQUIRY;
  525. hci_req_add(req, HCI_OP_WRITE_SCAN_ENABLE, 1, &scan);
  526. }
  527. void hci_update_page_scan(struct hci_dev *hdev)
  528. {
  529. struct hci_request req;
  530. hci_req_init(&req, hdev);
  531. __hci_update_page_scan(&req);
  532. hci_req_run(&req, NULL);
  533. }
  534. /* This function controls the background scanning based on hdev->pend_le_conns
  535. * list. If there are pending LE connection we start the background scanning,
  536. * otherwise we stop it.
  537. *
  538. * This function requires the caller holds hdev->lock.
  539. */
  540. static void __hci_update_background_scan(struct hci_request *req)
  541. {
  542. struct hci_dev *hdev = req->hdev;
  543. if (!test_bit(HCI_UP, &hdev->flags) ||
  544. test_bit(HCI_INIT, &hdev->flags) ||
  545. hci_dev_test_flag(hdev, HCI_SETUP) ||
  546. hci_dev_test_flag(hdev, HCI_CONFIG) ||
  547. hci_dev_test_flag(hdev, HCI_AUTO_OFF) ||
  548. hci_dev_test_flag(hdev, HCI_UNREGISTER))
  549. return;
  550. /* No point in doing scanning if LE support hasn't been enabled */
  551. if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED))
  552. return;
  553. /* If discovery is active don't interfere with it */
  554. if (hdev->discovery.state != DISCOVERY_STOPPED)
  555. return;
  556. /* Reset RSSI and UUID filters when starting background scanning
  557. * since these filters are meant for service discovery only.
  558. *
  559. * The Start Discovery and Start Service Discovery operations
  560. * ensure to set proper values for RSSI threshold and UUID
  561. * filter list. So it is safe to just reset them here.
  562. */
  563. hci_discovery_filter_clear(hdev);
  564. if (list_empty(&hdev->pend_le_conns) &&
  565. list_empty(&hdev->pend_le_reports)) {
  566. /* If there is no pending LE connections or devices
  567. * to be scanned for, we should stop the background
  568. * scanning.
  569. */
  570. /* If controller is not scanning we are done. */
  571. if (!hci_dev_test_flag(hdev, HCI_LE_SCAN))
  572. return;
  573. hci_req_add_le_scan_disable(req);
  574. BT_DBG("%s stopping background scanning", hdev->name);
  575. } else {
  576. /* If there is at least one pending LE connection, we should
  577. * keep the background scan running.
  578. */
  579. /* If controller is connecting, we should not start scanning
  580. * since some controllers are not able to scan and connect at
  581. * the same time.
  582. */
  583. if (hci_lookup_le_connect(hdev))
  584. return;
  585. /* If controller is currently scanning, we stop it to ensure we
  586. * don't miss any advertising (due to duplicates filter).
  587. */
  588. if (hci_dev_test_flag(hdev, HCI_LE_SCAN))
  589. hci_req_add_le_scan_disable(req);
  590. hci_req_add_le_passive_scan(req);
  591. BT_DBG("%s starting background scanning", hdev->name);
  592. }
  593. }
  594. void __hci_abort_conn(struct hci_request *req, struct hci_conn *conn,
  595. u8 reason)
  596. {
  597. switch (conn->state) {
  598. case BT_CONNECTED:
  599. case BT_CONFIG:
  600. if (conn->type == AMP_LINK) {
  601. struct hci_cp_disconn_phy_link cp;
  602. cp.phy_handle = HCI_PHY_HANDLE(conn->handle);
  603. cp.reason = reason;
  604. hci_req_add(req, HCI_OP_DISCONN_PHY_LINK, sizeof(cp),
  605. &cp);
  606. } else {
  607. struct hci_cp_disconnect dc;
  608. dc.handle = cpu_to_le16(conn->handle);
  609. dc.reason = reason;
  610. hci_req_add(req, HCI_OP_DISCONNECT, sizeof(dc), &dc);
  611. }
  612. conn->state = BT_DISCONN;
  613. break;
  614. case BT_CONNECT:
  615. if (conn->type == LE_LINK) {
  616. if (test_bit(HCI_CONN_SCANNING, &conn->flags))
  617. break;
  618. hci_req_add(req, HCI_OP_LE_CREATE_CONN_CANCEL,
  619. 0, NULL);
  620. } else if (conn->type == ACL_LINK) {
  621. if (req->hdev->hci_ver < BLUETOOTH_VER_1_2)
  622. break;
  623. hci_req_add(req, HCI_OP_CREATE_CONN_CANCEL,
  624. 6, &conn->dst);
  625. }
  626. break;
  627. case BT_CONNECT2:
  628. if (conn->type == ACL_LINK) {
  629. struct hci_cp_reject_conn_req rej;
  630. bacpy(&rej.bdaddr, &conn->dst);
  631. rej.reason = reason;
  632. hci_req_add(req, HCI_OP_REJECT_CONN_REQ,
  633. sizeof(rej), &rej);
  634. } else if (conn->type == SCO_LINK || conn->type == ESCO_LINK) {
  635. struct hci_cp_reject_sync_conn_req rej;
  636. bacpy(&rej.bdaddr, &conn->dst);
  637. /* SCO rejection has its own limited set of
  638. * allowed error values (0x0D-0x0F) which isn't
  639. * compatible with most values passed to this
  640. * function. To be safe hard-code one of the
  641. * values that's suitable for SCO.
  642. */
  643. rej.reason = HCI_ERROR_REMOTE_LOW_RESOURCES;
  644. hci_req_add(req, HCI_OP_REJECT_SYNC_CONN_REQ,
  645. sizeof(rej), &rej);
  646. }
  647. break;
  648. default:
  649. conn->state = BT_CLOSED;
  650. break;
  651. }
  652. }
  653. static void abort_conn_complete(struct hci_dev *hdev, u8 status, u16 opcode)
  654. {
  655. if (status)
  656. BT_DBG("Failed to abort connection: status 0x%2.2x", status);
  657. }
  658. int hci_abort_conn(struct hci_conn *conn, u8 reason)
  659. {
  660. struct hci_request req;
  661. int err;
  662. hci_req_init(&req, conn->hdev);
  663. __hci_abort_conn(&req, conn, reason);
  664. err = hci_req_run(&req, abort_conn_complete);
  665. if (err && err != -ENODATA) {
  666. BT_ERR("Failed to run HCI request: err %d", err);
  667. return err;
  668. }
  669. return 0;
  670. }
  671. static int update_bg_scan(struct hci_request *req, unsigned long opt)
  672. {
  673. hci_dev_lock(req->hdev);
  674. __hci_update_background_scan(req);
  675. hci_dev_unlock(req->hdev);
  676. return 0;
  677. }
  678. static void bg_scan_update(struct work_struct *work)
  679. {
  680. struct hci_dev *hdev = container_of(work, struct hci_dev,
  681. bg_scan_update);
  682. struct hci_conn *conn;
  683. u8 status;
  684. int err;
  685. err = hci_req_sync(hdev, update_bg_scan, 0, HCI_CMD_TIMEOUT, &status);
  686. if (!err)
  687. return;
  688. hci_dev_lock(hdev);
  689. conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT);
  690. if (conn)
  691. hci_le_conn_failed(conn, status);
  692. hci_dev_unlock(hdev);
  693. }
  694. static int le_scan_disable(struct hci_request *req, unsigned long opt)
  695. {
  696. hci_req_add_le_scan_disable(req);
  697. return 0;
  698. }
  699. static int bredr_inquiry(struct hci_request *req, unsigned long opt)
  700. {
  701. u8 length = opt;
  702. /* General inquiry access code (GIAC) */
  703. u8 lap[3] = { 0x33, 0x8b, 0x9e };
  704. struct hci_cp_inquiry cp;
  705. BT_DBG("%s", req->hdev->name);
  706. hci_dev_lock(req->hdev);
  707. hci_inquiry_cache_flush(req->hdev);
  708. hci_dev_unlock(req->hdev);
  709. memset(&cp, 0, sizeof(cp));
  710. memcpy(&cp.lap, lap, sizeof(cp.lap));
  711. cp.length = length;
  712. hci_req_add(req, HCI_OP_INQUIRY, sizeof(cp), &cp);
  713. return 0;
  714. }
  715. static void le_scan_disable_work(struct work_struct *work)
  716. {
  717. struct hci_dev *hdev = container_of(work, struct hci_dev,
  718. le_scan_disable.work);
  719. u8 status;
  720. BT_DBG("%s", hdev->name);
  721. if (!hci_dev_test_flag(hdev, HCI_LE_SCAN))
  722. return;
  723. cancel_delayed_work(&hdev->le_scan_restart);
  724. hci_req_sync(hdev, le_scan_disable, 0, HCI_CMD_TIMEOUT, &status);
  725. if (status) {
  726. BT_ERR("Failed to disable LE scan: status 0x%02x", status);
  727. return;
  728. }
  729. hdev->discovery.scan_start = 0;
  730. /* If we were running LE only scan, change discovery state. If
  731. * we were running both LE and BR/EDR inquiry simultaneously,
  732. * and BR/EDR inquiry is already finished, stop discovery,
  733. * otherwise BR/EDR inquiry will stop discovery when finished.
  734. * If we will resolve remote device name, do not change
  735. * discovery state.
  736. */
  737. if (hdev->discovery.type == DISCOV_TYPE_LE)
  738. goto discov_stopped;
  739. if (hdev->discovery.type != DISCOV_TYPE_INTERLEAVED)
  740. return;
  741. if (test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks)) {
  742. if (!test_bit(HCI_INQUIRY, &hdev->flags) &&
  743. hdev->discovery.state != DISCOVERY_RESOLVING)
  744. goto discov_stopped;
  745. return;
  746. }
  747. hci_req_sync(hdev, bredr_inquiry, DISCOV_INTERLEAVED_INQUIRY_LEN,
  748. HCI_CMD_TIMEOUT, &status);
  749. if (status) {
  750. BT_ERR("Inquiry failed: status 0x%02x", status);
  751. goto discov_stopped;
  752. }
  753. return;
  754. discov_stopped:
  755. hci_dev_lock(hdev);
  756. hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
  757. hci_dev_unlock(hdev);
  758. }
  759. static void le_scan_restart_work_complete(struct hci_dev *hdev, u8 status)
  760. {
  761. unsigned long timeout, duration, scan_start, now;
  762. BT_DBG("%s", hdev->name);
  763. if (status) {
  764. BT_ERR("Failed to restart LE scan: status %d", status);
  765. return;
  766. }
  767. hci_dev_lock(hdev);
  768. if (!test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) ||
  769. !hdev->discovery.scan_start)
  770. goto unlock;
  771. /* When the scan was started, hdev->le_scan_disable has been queued
  772. * after duration from scan_start. During scan restart this job
  773. * has been canceled, and we need to queue it again after proper
  774. * timeout, to make sure that scan does not run indefinitely.
  775. */
  776. duration = hdev->discovery.scan_duration;
  777. scan_start = hdev->discovery.scan_start;
  778. now = jiffies;
  779. if (now - scan_start <= duration) {
  780. int elapsed;
  781. if (now >= scan_start)
  782. elapsed = now - scan_start;
  783. else
  784. elapsed = ULONG_MAX - scan_start + now;
  785. timeout = duration - elapsed;
  786. } else {
  787. timeout = 0;
  788. }
  789. queue_delayed_work(hdev->req_workqueue,
  790. &hdev->le_scan_disable, timeout);
  791. unlock:
  792. hci_dev_unlock(hdev);
  793. }
  794. static int le_scan_restart(struct hci_request *req, unsigned long opt)
  795. {
  796. struct hci_dev *hdev = req->hdev;
  797. struct hci_cp_le_set_scan_enable cp;
  798. /* If controller is not scanning we are done. */
  799. if (!hci_dev_test_flag(hdev, HCI_LE_SCAN))
  800. return 0;
  801. hci_req_add_le_scan_disable(req);
  802. memset(&cp, 0, sizeof(cp));
  803. cp.enable = LE_SCAN_ENABLE;
  804. cp.filter_dup = LE_SCAN_FILTER_DUP_ENABLE;
  805. hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
  806. return 0;
  807. }
  808. static void le_scan_restart_work(struct work_struct *work)
  809. {
  810. struct hci_dev *hdev = container_of(work, struct hci_dev,
  811. le_scan_restart.work);
  812. u8 status;
  813. int err;
  814. BT_DBG("%s", hdev->name);
  815. err = hci_req_sync(hdev, le_scan_restart, 0, HCI_CMD_TIMEOUT, &status);
  816. if (err)
  817. return;
  818. le_scan_restart_work_complete(hdev, status);
  819. }
  820. static void cancel_adv_timeout(struct hci_dev *hdev)
  821. {
  822. if (hdev->adv_instance_timeout) {
  823. hdev->adv_instance_timeout = 0;
  824. cancel_delayed_work(&hdev->adv_instance_expire);
  825. }
  826. }
  827. static void disable_advertising(struct hci_request *req)
  828. {
  829. u8 enable = 0x00;
  830. hci_req_add(req, HCI_OP_LE_SET_ADV_ENABLE, sizeof(enable), &enable);
  831. }
  832. static int active_scan(struct hci_request *req, unsigned long opt)
  833. {
  834. uint16_t interval = opt;
  835. struct hci_dev *hdev = req->hdev;
  836. struct hci_cp_le_set_scan_param param_cp;
  837. struct hci_cp_le_set_scan_enable enable_cp;
  838. u8 own_addr_type;
  839. int err;
  840. BT_DBG("%s", hdev->name);
  841. if (hci_dev_test_flag(hdev, HCI_LE_ADV)) {
  842. hci_dev_lock(hdev);
  843. /* Don't let discovery abort an outgoing connection attempt
  844. * that's using directed advertising.
  845. */
  846. if (hci_lookup_le_connect(hdev)) {
  847. hci_dev_unlock(hdev);
  848. return -EBUSY;
  849. }
  850. cancel_adv_timeout(hdev);
  851. hci_dev_unlock(hdev);
  852. disable_advertising(req);
  853. }
  854. /* If controller is scanning, it means the background scanning is
  855. * running. Thus, we should temporarily stop it in order to set the
  856. * discovery scanning parameters.
  857. */
  858. if (hci_dev_test_flag(hdev, HCI_LE_SCAN))
  859. hci_req_add_le_scan_disable(req);
  860. /* All active scans will be done with either a resolvable private
  861. * address (when privacy feature has been enabled) or non-resolvable
  862. * private address.
  863. */
  864. err = hci_update_random_address(req, true, &own_addr_type);
  865. if (err < 0)
  866. own_addr_type = ADDR_LE_DEV_PUBLIC;
  867. memset(&param_cp, 0, sizeof(param_cp));
  868. param_cp.type = LE_SCAN_ACTIVE;
  869. param_cp.interval = cpu_to_le16(interval);
  870. param_cp.window = cpu_to_le16(DISCOV_LE_SCAN_WIN);
  871. param_cp.own_address_type = own_addr_type;
  872. hci_req_add(req, HCI_OP_LE_SET_SCAN_PARAM, sizeof(param_cp),
  873. &param_cp);
  874. memset(&enable_cp, 0, sizeof(enable_cp));
  875. enable_cp.enable = LE_SCAN_ENABLE;
  876. enable_cp.filter_dup = LE_SCAN_FILTER_DUP_ENABLE;
  877. hci_req_add(req, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(enable_cp),
  878. &enable_cp);
  879. return 0;
  880. }
  881. static int interleaved_discov(struct hci_request *req, unsigned long opt)
  882. {
  883. int err;
  884. BT_DBG("%s", req->hdev->name);
  885. err = active_scan(req, opt);
  886. if (err)
  887. return err;
  888. return bredr_inquiry(req, DISCOV_BREDR_INQUIRY_LEN);
  889. }
  890. static void start_discovery(struct hci_dev *hdev, u8 *status)
  891. {
  892. unsigned long timeout;
  893. BT_DBG("%s type %u", hdev->name, hdev->discovery.type);
  894. switch (hdev->discovery.type) {
  895. case DISCOV_TYPE_BREDR:
  896. if (!hci_dev_test_flag(hdev, HCI_INQUIRY))
  897. hci_req_sync(hdev, bredr_inquiry,
  898. DISCOV_BREDR_INQUIRY_LEN, HCI_CMD_TIMEOUT,
  899. status);
  900. return;
  901. case DISCOV_TYPE_INTERLEAVED:
  902. /* When running simultaneous discovery, the LE scanning time
  903. * should occupy the whole discovery time sine BR/EDR inquiry
  904. * and LE scanning are scheduled by the controller.
  905. *
  906. * For interleaving discovery in comparison, BR/EDR inquiry
  907. * and LE scanning are done sequentially with separate
  908. * timeouts.
  909. */
  910. if (test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY,
  911. &hdev->quirks)) {
  912. timeout = msecs_to_jiffies(DISCOV_LE_TIMEOUT);
  913. /* During simultaneous discovery, we double LE scan
  914. * interval. We must leave some time for the controller
  915. * to do BR/EDR inquiry.
  916. */
  917. hci_req_sync(hdev, interleaved_discov,
  918. DISCOV_LE_SCAN_INT * 2, HCI_CMD_TIMEOUT,
  919. status);
  920. break;
  921. }
  922. timeout = msecs_to_jiffies(hdev->discov_interleaved_timeout);
  923. hci_req_sync(hdev, active_scan, DISCOV_LE_SCAN_INT,
  924. HCI_CMD_TIMEOUT, status);
  925. break;
  926. case DISCOV_TYPE_LE:
  927. timeout = msecs_to_jiffies(DISCOV_LE_TIMEOUT);
  928. hci_req_sync(hdev, active_scan, DISCOV_LE_SCAN_INT,
  929. HCI_CMD_TIMEOUT, status);
  930. break;
  931. default:
  932. *status = HCI_ERROR_UNSPECIFIED;
  933. return;
  934. }
  935. if (*status)
  936. return;
  937. BT_DBG("%s timeout %u ms", hdev->name, jiffies_to_msecs(timeout));
  938. /* When service discovery is used and the controller has a
  939. * strict duplicate filter, it is important to remember the
  940. * start and duration of the scan. This is required for
  941. * restarting scanning during the discovery phase.
  942. */
  943. if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) &&
  944. hdev->discovery.result_filtering) {
  945. hdev->discovery.scan_start = jiffies;
  946. hdev->discovery.scan_duration = timeout;
  947. }
  948. queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_disable,
  949. timeout);
  950. }
  951. bool hci_req_stop_discovery(struct hci_request *req)
  952. {
  953. struct hci_dev *hdev = req->hdev;
  954. struct discovery_state *d = &hdev->discovery;
  955. struct hci_cp_remote_name_req_cancel cp;
  956. struct inquiry_entry *e;
  957. bool ret = false;
  958. BT_DBG("%s state %u", hdev->name, hdev->discovery.state);
  959. if (d->state == DISCOVERY_FINDING || d->state == DISCOVERY_STOPPING) {
  960. if (test_bit(HCI_INQUIRY, &hdev->flags))
  961. hci_req_add(req, HCI_OP_INQUIRY_CANCEL, 0, NULL);
  962. if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) {
  963. cancel_delayed_work(&hdev->le_scan_disable);
  964. hci_req_add_le_scan_disable(req);
  965. }
  966. ret = true;
  967. } else {
  968. /* Passive scanning */
  969. if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) {
  970. hci_req_add_le_scan_disable(req);
  971. ret = true;
  972. }
  973. }
  974. /* No further actions needed for LE-only discovery */
  975. if (d->type == DISCOV_TYPE_LE)
  976. return ret;
  977. if (d->state == DISCOVERY_RESOLVING || d->state == DISCOVERY_STOPPING) {
  978. e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY,
  979. NAME_PENDING);
  980. if (!e)
  981. return ret;
  982. bacpy(&cp.bdaddr, &e->data.bdaddr);
  983. hci_req_add(req, HCI_OP_REMOTE_NAME_REQ_CANCEL, sizeof(cp),
  984. &cp);
  985. ret = true;
  986. }
  987. return ret;
  988. }
  989. static int stop_discovery(struct hci_request *req, unsigned long opt)
  990. {
  991. hci_dev_lock(req->hdev);
  992. hci_req_stop_discovery(req);
  993. hci_dev_unlock(req->hdev);
  994. return 0;
  995. }
  996. static void discov_update(struct work_struct *work)
  997. {
  998. struct hci_dev *hdev = container_of(work, struct hci_dev,
  999. discov_update);
  1000. u8 status = 0;
  1001. switch (hdev->discovery.state) {
  1002. case DISCOVERY_STARTING:
  1003. start_discovery(hdev, &status);
  1004. mgmt_start_discovery_complete(hdev, status);
  1005. if (status)
  1006. hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
  1007. else
  1008. hci_discovery_set_state(hdev, DISCOVERY_FINDING);
  1009. break;
  1010. case DISCOVERY_STOPPING:
  1011. hci_req_sync(hdev, stop_discovery, 0, HCI_CMD_TIMEOUT, &status);
  1012. mgmt_stop_discovery_complete(hdev, status);
  1013. if (!status)
  1014. hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
  1015. break;
  1016. case DISCOVERY_STOPPED:
  1017. default:
  1018. return;
  1019. }
  1020. }
  1021. void hci_request_setup(struct hci_dev *hdev)
  1022. {
  1023. INIT_WORK(&hdev->discov_update, discov_update);
  1024. INIT_WORK(&hdev->bg_scan_update, bg_scan_update);
  1025. INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable_work);
  1026. INIT_DELAYED_WORK(&hdev->le_scan_restart, le_scan_restart_work);
  1027. }
  1028. void hci_request_cancel_all(struct hci_dev *hdev)
  1029. {
  1030. cancel_work_sync(&hdev->discov_update);
  1031. cancel_work_sync(&hdev->bg_scan_update);
  1032. cancel_delayed_work_sync(&hdev->le_scan_disable);
  1033. cancel_delayed_work_sync(&hdev->le_scan_restart);
  1034. }