hcicmds.cc 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446
  1. /******************************************************************************
  2. *
  3. * Copyright 1999-2012 Broadcom Corporation
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at:
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. ******************************************************************************/
  18. /******************************************************************************
  19. *
  20. * This file contains function of the HCIC unit to format and send HCI
  21. * commands.
  22. *
  23. ******************************************************************************/
  24. #include "bt_common.h"
  25. #include "bt_target.h"
  26. #include "btu.h"
  27. #include "hcidefs.h"
  28. #include "hcimsgs.h"
  29. #include <stddef.h>
  30. #include <string.h>
  31. #include "btm_int.h" /* Included for UIPC_* macro definitions */
  32. void btsnd_hcic_inquiry(const LAP inq_lap, uint8_t duration,
  33. uint8_t response_cnt) {
  34. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  35. uint8_t* pp = (uint8_t*)(p + 1);
  36. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_INQUIRY;
  37. p->offset = 0;
  38. UINT16_TO_STREAM(pp, HCI_INQUIRY);
  39. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_INQUIRY);
  40. LAP_TO_STREAM(pp, inq_lap);
  41. UINT8_TO_STREAM(pp, duration);
  42. UINT8_TO_STREAM(pp, response_cnt);
  43. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  44. }
  45. void btsnd_hcic_inq_cancel(void) {
  46. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  47. uint8_t* pp = (uint8_t*)(p + 1);
  48. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_INQ_CANCEL;
  49. p->offset = 0;
  50. UINT16_TO_STREAM(pp, HCI_INQUIRY_CANCEL);
  51. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_INQ_CANCEL);
  52. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  53. }
  54. void btsnd_hcic_per_inq_mode(uint16_t max_period, uint16_t min_period,
  55. const LAP inq_lap, uint8_t duration,
  56. uint8_t response_cnt) {
  57. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  58. uint8_t* pp = (uint8_t*)(p + 1);
  59. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PER_INQ_MODE;
  60. p->offset = 0;
  61. UINT16_TO_STREAM(pp, HCI_PERIODIC_INQUIRY_MODE);
  62. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PER_INQ_MODE);
  63. UINT16_TO_STREAM(pp, max_period);
  64. UINT16_TO_STREAM(pp, min_period);
  65. LAP_TO_STREAM(pp, inq_lap);
  66. UINT8_TO_STREAM(pp, duration);
  67. UINT8_TO_STREAM(pp, response_cnt);
  68. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  69. }
  70. void btsnd_hcic_exit_per_inq(void) {
  71. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  72. uint8_t* pp = (uint8_t*)(p + 1);
  73. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_EXIT_PER_INQ;
  74. p->offset = 0;
  75. UINT16_TO_STREAM(pp, HCI_EXIT_PERIODIC_INQUIRY_MODE);
  76. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_EXIT_PER_INQ);
  77. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  78. }
  79. void btsnd_hcic_create_conn(const RawAddress& dest, uint16_t packet_types,
  80. uint8_t page_scan_rep_mode, uint8_t page_scan_mode,
  81. uint16_t clock_offset, uint8_t allow_switch) {
  82. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  83. uint8_t* pp = (uint8_t*)(p + 1);
  84. #ifndef BT_10A
  85. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CREATE_CONN;
  86. #else
  87. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CREATE_CONN - 1;
  88. #endif
  89. p->offset = 0;
  90. UINT16_TO_STREAM(pp, HCI_CREATE_CONNECTION);
  91. #ifndef BT_10A
  92. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CREATE_CONN);
  93. #else
  94. UINT8_TO_STREAM(pp, (HCIC_PARAM_SIZE_CREATE_CONN - 1));
  95. #endif
  96. BDADDR_TO_STREAM(pp, dest);
  97. UINT16_TO_STREAM(pp, packet_types);
  98. UINT8_TO_STREAM(pp, page_scan_rep_mode);
  99. UINT8_TO_STREAM(pp, page_scan_mode);
  100. UINT16_TO_STREAM(pp, clock_offset);
  101. #if !defined(BT_10A)
  102. UINT8_TO_STREAM(pp, allow_switch);
  103. #endif
  104. btm_acl_paging(p, dest);
  105. }
  106. void btsnd_hcic_disconnect(uint16_t handle, uint8_t reason) {
  107. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  108. uint8_t* pp = (uint8_t*)(p + 1);
  109. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_DISCONNECT;
  110. p->offset = 0;
  111. UINT16_TO_STREAM(pp, HCI_DISCONNECT);
  112. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_DISCONNECT);
  113. UINT16_TO_STREAM(pp, handle);
  114. UINT8_TO_STREAM(pp, reason);
  115. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  116. }
  117. void btsnd_hcic_add_SCO_conn(uint16_t handle, uint16_t packet_types) {
  118. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  119. uint8_t* pp = (uint8_t*)(p + 1);
  120. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ADD_SCO_CONN;
  121. p->offset = 0;
  122. UINT16_TO_STREAM(pp, HCI_ADD_SCO_CONNECTION);
  123. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ADD_SCO_CONN);
  124. UINT16_TO_STREAM(pp, handle);
  125. UINT16_TO_STREAM(pp, packet_types);
  126. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  127. }
  128. void btsnd_hcic_create_conn_cancel(const RawAddress& dest) {
  129. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  130. uint8_t* pp = (uint8_t*)(p + 1);
  131. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CREATE_CONN_CANCEL;
  132. p->offset = 0;
  133. UINT16_TO_STREAM(pp, HCI_CREATE_CONNECTION_CANCEL);
  134. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CREATE_CONN_CANCEL);
  135. BDADDR_TO_STREAM(pp, dest);
  136. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  137. }
  138. void btsnd_hcic_accept_conn(const RawAddress& dest, uint8_t role) {
  139. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  140. uint8_t* pp = (uint8_t*)(p + 1);
  141. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ACCEPT_CONN;
  142. p->offset = 0;
  143. UINT16_TO_STREAM(pp, HCI_ACCEPT_CONNECTION_REQUEST);
  144. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ACCEPT_CONN);
  145. BDADDR_TO_STREAM(pp, dest);
  146. UINT8_TO_STREAM(pp, role);
  147. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  148. }
  149. void btsnd_hcic_reject_conn(const RawAddress& dest, uint8_t reason) {
  150. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  151. uint8_t* pp = (uint8_t*)(p + 1);
  152. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REJECT_CONN;
  153. p->offset = 0;
  154. UINT16_TO_STREAM(pp, HCI_REJECT_CONNECTION_REQUEST);
  155. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_REJECT_CONN);
  156. BDADDR_TO_STREAM(pp, dest);
  157. UINT8_TO_STREAM(pp, reason);
  158. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  159. }
  160. void btsnd_hcic_link_key_req_reply(const RawAddress& bd_addr,
  161. const LinkKey& link_key) {
  162. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  163. uint8_t* pp = (uint8_t*)(p + 1);
  164. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LINK_KEY_REQ_REPLY;
  165. p->offset = 0;
  166. UINT16_TO_STREAM(pp, HCI_LINK_KEY_REQUEST_REPLY);
  167. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_LINK_KEY_REQ_REPLY);
  168. BDADDR_TO_STREAM(pp, bd_addr);
  169. ARRAY16_TO_STREAM(pp, link_key.data());
  170. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  171. }
  172. void btsnd_hcic_link_key_neg_reply(const RawAddress& bd_addr) {
  173. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  174. uint8_t* pp = (uint8_t*)(p + 1);
  175. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LINK_KEY_NEG_REPLY;
  176. p->offset = 0;
  177. UINT16_TO_STREAM(pp, HCI_LINK_KEY_REQUEST_NEG_REPLY);
  178. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_LINK_KEY_NEG_REPLY);
  179. BDADDR_TO_STREAM(pp, bd_addr);
  180. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  181. }
  182. void btsnd_hcic_pin_code_req_reply(const RawAddress& bd_addr,
  183. uint8_t pin_code_len, PIN_CODE pin_code) {
  184. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  185. uint8_t* pp = (uint8_t*)(p + 1);
  186. int i;
  187. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PIN_CODE_REQ_REPLY;
  188. p->offset = 0;
  189. UINT16_TO_STREAM(pp, HCI_PIN_CODE_REQUEST_REPLY);
  190. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PIN_CODE_REQ_REPLY);
  191. BDADDR_TO_STREAM(pp, bd_addr);
  192. UINT8_TO_STREAM(pp, pin_code_len);
  193. for (i = 0; i < pin_code_len; i++) *pp++ = *pin_code++;
  194. for (; i < PIN_CODE_LEN; i++) *pp++ = 0;
  195. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  196. }
  197. void btsnd_hcic_pin_code_neg_reply(const RawAddress& bd_addr) {
  198. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  199. uint8_t* pp = (uint8_t*)(p + 1);
  200. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PIN_CODE_NEG_REPLY;
  201. p->offset = 0;
  202. UINT16_TO_STREAM(pp, HCI_PIN_CODE_REQUEST_NEG_REPLY);
  203. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PIN_CODE_NEG_REPLY);
  204. BDADDR_TO_STREAM(pp, bd_addr);
  205. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  206. }
  207. void btsnd_hcic_change_conn_type(uint16_t handle, uint16_t packet_types) {
  208. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  209. uint8_t* pp = (uint8_t*)(p + 1);
  210. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CHANGE_CONN_TYPE;
  211. p->offset = 0;
  212. UINT16_TO_STREAM(pp, HCI_CHANGE_CONN_PACKET_TYPE);
  213. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CHANGE_CONN_TYPE);
  214. UINT16_TO_STREAM(pp, handle);
  215. UINT16_TO_STREAM(pp, packet_types);
  216. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  217. }
  218. void btsnd_hcic_auth_request(uint16_t handle) {
  219. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  220. uint8_t* pp = (uint8_t*)(p + 1);
  221. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
  222. p->offset = 0;
  223. UINT16_TO_STREAM(pp, HCI_AUTHENTICATION_REQUESTED);
  224. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE);
  225. UINT16_TO_STREAM(pp, handle);
  226. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  227. }
  228. void btsnd_hcic_set_conn_encrypt(uint16_t handle, bool enable) {
  229. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  230. uint8_t* pp = (uint8_t*)(p + 1);
  231. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_CONN_ENCRYPT;
  232. p->offset = 0;
  233. UINT16_TO_STREAM(pp, HCI_SET_CONN_ENCRYPTION);
  234. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SET_CONN_ENCRYPT);
  235. UINT16_TO_STREAM(pp, handle);
  236. UINT8_TO_STREAM(pp, enable);
  237. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  238. }
  239. void btsnd_hcic_rmt_name_req(const RawAddress& bd_addr,
  240. uint8_t page_scan_rep_mode, uint8_t page_scan_mode,
  241. uint16_t clock_offset) {
  242. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  243. uint8_t* pp = (uint8_t*)(p + 1);
  244. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_RMT_NAME_REQ;
  245. p->offset = 0;
  246. UINT16_TO_STREAM(pp, HCI_RMT_NAME_REQUEST);
  247. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_RMT_NAME_REQ);
  248. BDADDR_TO_STREAM(pp, bd_addr);
  249. UINT8_TO_STREAM(pp, page_scan_rep_mode);
  250. UINT8_TO_STREAM(pp, page_scan_mode);
  251. UINT16_TO_STREAM(pp, clock_offset);
  252. btm_acl_paging(p, bd_addr);
  253. }
  254. void btsnd_hcic_rmt_name_req_cancel(const RawAddress& bd_addr) {
  255. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  256. uint8_t* pp = (uint8_t*)(p + 1);
  257. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_RMT_NAME_REQ_CANCEL;
  258. p->offset = 0;
  259. UINT16_TO_STREAM(pp, HCI_RMT_NAME_REQUEST_CANCEL);
  260. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_RMT_NAME_REQ_CANCEL);
  261. BDADDR_TO_STREAM(pp, bd_addr);
  262. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  263. }
  264. void btsnd_hcic_rmt_features_req(uint16_t handle) {
  265. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  266. uint8_t* pp = (uint8_t*)(p + 1);
  267. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
  268. p->offset = 0;
  269. UINT16_TO_STREAM(pp, HCI_READ_RMT_FEATURES);
  270. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE);
  271. UINT16_TO_STREAM(pp, handle);
  272. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  273. }
  274. void btsnd_hcic_rmt_ext_features(uint16_t handle, uint8_t page_num) {
  275. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  276. uint8_t* pp = (uint8_t*)(p + 1);
  277. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_RMT_EXT_FEATURES;
  278. p->offset = 0;
  279. UINT16_TO_STREAM(pp, HCI_READ_RMT_EXT_FEATURES);
  280. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_RMT_EXT_FEATURES);
  281. UINT16_TO_STREAM(pp, handle);
  282. UINT8_TO_STREAM(pp, page_num);
  283. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  284. }
  285. void btsnd_hcic_rmt_ver_req(uint16_t handle) {
  286. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  287. uint8_t* pp = (uint8_t*)(p + 1);
  288. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
  289. p->offset = 0;
  290. UINT16_TO_STREAM(pp, HCI_READ_RMT_VERSION_INFO);
  291. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE);
  292. UINT16_TO_STREAM(pp, handle);
  293. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  294. }
  295. void btsnd_hcic_read_rmt_clk_offset(uint16_t handle) {
  296. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  297. uint8_t* pp = (uint8_t*)(p + 1);
  298. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
  299. p->offset = 0;
  300. UINT16_TO_STREAM(pp, HCI_READ_RMT_CLOCK_OFFSET);
  301. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE);
  302. UINT16_TO_STREAM(pp, handle);
  303. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  304. }
  305. void btsnd_hcic_read_lmp_handle(uint16_t handle) {
  306. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  307. uint8_t* pp = (uint8_t*)(p + 1);
  308. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
  309. p->offset = 0;
  310. UINT16_TO_STREAM(pp, HCI_READ_LMP_HANDLE);
  311. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE);
  312. UINT16_TO_STREAM(pp, handle);
  313. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  314. }
  315. void btsnd_hcic_setup_esco_conn(uint16_t handle, uint32_t transmit_bandwidth,
  316. uint32_t receive_bandwidth,
  317. uint16_t max_latency, uint16_t voice,
  318. uint8_t retrans_effort, uint16_t packet_types) {
  319. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  320. uint8_t* pp = (uint8_t*)(p + 1);
  321. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SETUP_ESCO;
  322. p->offset = 0;
  323. UINT16_TO_STREAM(pp, HCI_SETUP_ESCO_CONNECTION);
  324. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SETUP_ESCO);
  325. UINT16_TO_STREAM(pp, handle);
  326. UINT32_TO_STREAM(pp, transmit_bandwidth);
  327. UINT32_TO_STREAM(pp, receive_bandwidth);
  328. UINT16_TO_STREAM(pp, max_latency);
  329. UINT16_TO_STREAM(pp, voice);
  330. UINT8_TO_STREAM(pp, retrans_effort);
  331. UINT16_TO_STREAM(pp, packet_types);
  332. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  333. }
  334. void btsnd_hcic_accept_esco_conn(const RawAddress& bd_addr,
  335. uint32_t transmit_bandwidth,
  336. uint32_t receive_bandwidth,
  337. uint16_t max_latency, uint16_t content_fmt,
  338. uint8_t retrans_effort,
  339. uint16_t packet_types) {
  340. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  341. uint8_t* pp = (uint8_t*)(p + 1);
  342. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ACCEPT_ESCO;
  343. p->offset = 0;
  344. UINT16_TO_STREAM(pp, HCI_ACCEPT_ESCO_CONNECTION);
  345. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ACCEPT_ESCO);
  346. BDADDR_TO_STREAM(pp, bd_addr);
  347. UINT32_TO_STREAM(pp, transmit_bandwidth);
  348. UINT32_TO_STREAM(pp, receive_bandwidth);
  349. UINT16_TO_STREAM(pp, max_latency);
  350. UINT16_TO_STREAM(pp, content_fmt);
  351. UINT8_TO_STREAM(pp, retrans_effort);
  352. UINT16_TO_STREAM(pp, packet_types);
  353. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  354. }
  355. void btsnd_hcic_reject_esco_conn(const RawAddress& bd_addr, uint8_t reason) {
  356. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  357. uint8_t* pp = (uint8_t*)(p + 1);
  358. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REJECT_ESCO;
  359. p->offset = 0;
  360. UINT16_TO_STREAM(pp, HCI_REJECT_ESCO_CONNECTION);
  361. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_REJECT_ESCO);
  362. BDADDR_TO_STREAM(pp, bd_addr);
  363. UINT8_TO_STREAM(pp, reason);
  364. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  365. }
  366. void btsnd_hcic_hold_mode(uint16_t handle, uint16_t max_hold_period,
  367. uint16_t min_hold_period) {
  368. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  369. uint8_t* pp = (uint8_t*)(p + 1);
  370. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_HOLD_MODE;
  371. p->offset = 0;
  372. UINT16_TO_STREAM(pp, HCI_HOLD_MODE);
  373. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_HOLD_MODE);
  374. UINT16_TO_STREAM(pp, handle);
  375. UINT16_TO_STREAM(pp, max_hold_period);
  376. UINT16_TO_STREAM(pp, min_hold_period);
  377. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  378. }
  379. void btsnd_hcic_sniff_mode(uint16_t handle, uint16_t max_sniff_period,
  380. uint16_t min_sniff_period, uint16_t sniff_attempt,
  381. uint16_t sniff_timeout) {
  382. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  383. uint8_t* pp = (uint8_t*)(p + 1);
  384. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SNIFF_MODE;
  385. p->offset = 0;
  386. UINT16_TO_STREAM(pp, HCI_SNIFF_MODE);
  387. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SNIFF_MODE);
  388. UINT16_TO_STREAM(pp, handle);
  389. UINT16_TO_STREAM(pp, max_sniff_period);
  390. UINT16_TO_STREAM(pp, min_sniff_period);
  391. UINT16_TO_STREAM(pp, sniff_attempt);
  392. UINT16_TO_STREAM(pp, sniff_timeout);
  393. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  394. }
  395. void btsnd_hcic_exit_sniff_mode(uint16_t handle) {
  396. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  397. uint8_t* pp = (uint8_t*)(p + 1);
  398. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
  399. p->offset = 0;
  400. UINT16_TO_STREAM(pp, HCI_EXIT_SNIFF_MODE);
  401. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE);
  402. UINT16_TO_STREAM(pp, handle);
  403. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  404. }
  405. void btsnd_hcic_park_mode(uint16_t handle, uint16_t beacon_max_interval,
  406. uint16_t beacon_min_interval) {
  407. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  408. uint8_t* pp = (uint8_t*)(p + 1);
  409. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PARK_MODE;
  410. p->offset = 0;
  411. UINT16_TO_STREAM(pp, HCI_PARK_MODE);
  412. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_PARK_MODE);
  413. UINT16_TO_STREAM(pp, handle);
  414. UINT16_TO_STREAM(pp, beacon_max_interval);
  415. UINT16_TO_STREAM(pp, beacon_min_interval);
  416. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  417. }
  418. void btsnd_hcic_exit_park_mode(uint16_t handle) {
  419. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  420. uint8_t* pp = (uint8_t*)(p + 1);
  421. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
  422. p->offset = 0;
  423. UINT16_TO_STREAM(pp, HCI_EXIT_PARK_MODE);
  424. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE);
  425. UINT16_TO_STREAM(pp, handle);
  426. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  427. }
  428. void btsnd_hcic_qos_setup(uint16_t handle, uint8_t flags, uint8_t service_type,
  429. uint32_t token_rate, uint32_t peak, uint32_t latency,
  430. uint32_t delay_var) {
  431. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  432. uint8_t* pp = (uint8_t*)(p + 1);
  433. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_QOS_SETUP;
  434. p->offset = 0;
  435. UINT16_TO_STREAM(pp, HCI_QOS_SETUP);
  436. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_QOS_SETUP);
  437. UINT16_TO_STREAM(pp, handle);
  438. UINT8_TO_STREAM(pp, flags);
  439. UINT8_TO_STREAM(pp, service_type);
  440. UINT32_TO_STREAM(pp, token_rate);
  441. UINT32_TO_STREAM(pp, peak);
  442. UINT32_TO_STREAM(pp, latency);
  443. UINT32_TO_STREAM(pp, delay_var);
  444. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  445. }
  446. void btsnd_hcic_switch_role(const RawAddress& bd_addr, uint8_t role) {
  447. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  448. uint8_t* pp = (uint8_t*)(p + 1);
  449. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SWITCH_ROLE;
  450. p->offset = 0;
  451. UINT16_TO_STREAM(pp, HCI_SWITCH_ROLE);
  452. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SWITCH_ROLE);
  453. BDADDR_TO_STREAM(pp, bd_addr);
  454. UINT8_TO_STREAM(pp, role);
  455. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  456. }
  457. void btsnd_hcic_write_policy_set(uint16_t handle, uint16_t settings) {
  458. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  459. uint8_t* pp = (uint8_t*)(p + 1);
  460. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_POLICY_SET;
  461. p->offset = 0;
  462. UINT16_TO_STREAM(pp, HCI_WRITE_POLICY_SETTINGS);
  463. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_POLICY_SET);
  464. UINT16_TO_STREAM(pp, handle);
  465. UINT16_TO_STREAM(pp, settings);
  466. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  467. }
  468. void btsnd_hcic_write_def_policy_set(uint16_t settings) {
  469. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  470. uint8_t* pp = (uint8_t*)(p + 1);
  471. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_DEF_POLICY_SET;
  472. p->offset = 0;
  473. UINT16_TO_STREAM(pp, HCI_WRITE_DEF_POLICY_SETTINGS);
  474. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_DEF_POLICY_SET);
  475. UINT16_TO_STREAM(pp, settings);
  476. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  477. }
  478. void btsnd_hcic_set_event_filter(uint8_t filt_type, uint8_t filt_cond_type,
  479. uint8_t* filt_cond, uint8_t filt_cond_len) {
  480. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  481. uint8_t* pp = (uint8_t*)(p + 1);
  482. p->offset = 0;
  483. UINT16_TO_STREAM(pp, HCI_SET_EVENT_FILTER);
  484. if (filt_type) {
  485. p->len = (uint16_t)(HCIC_PREAMBLE_SIZE + 2 + filt_cond_len);
  486. UINT8_TO_STREAM(pp, (uint8_t)(2 + filt_cond_len));
  487. UINT8_TO_STREAM(pp, filt_type);
  488. UINT8_TO_STREAM(pp, filt_cond_type);
  489. if (filt_cond_type == HCI_FILTER_COND_DEVICE_CLASS) {
  490. DEVCLASS_TO_STREAM(pp, filt_cond);
  491. filt_cond += DEV_CLASS_LEN;
  492. DEVCLASS_TO_STREAM(pp, filt_cond);
  493. filt_cond += DEV_CLASS_LEN;
  494. filt_cond_len -= (2 * DEV_CLASS_LEN);
  495. } else if (filt_cond_type == HCI_FILTER_COND_BD_ADDR) {
  496. BDADDR_TO_STREAM(pp, *((RawAddress*)filt_cond));
  497. filt_cond += BD_ADDR_LEN;
  498. filt_cond_len -= BD_ADDR_LEN;
  499. }
  500. if (filt_cond_len) ARRAY_TO_STREAM(pp, filt_cond, filt_cond_len);
  501. } else {
  502. p->len = (uint16_t)(HCIC_PREAMBLE_SIZE + 1);
  503. UINT8_TO_STREAM(pp, 1);
  504. UINT8_TO_STREAM(pp, filt_type);
  505. }
  506. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  507. }
  508. void btsnd_hcic_write_pin_type(uint8_t type) {
  509. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  510. uint8_t* pp = (uint8_t*)(p + 1);
  511. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1;
  512. p->offset = 0;
  513. UINT16_TO_STREAM(pp, HCI_WRITE_PIN_TYPE);
  514. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM1);
  515. UINT8_TO_STREAM(pp, type);
  516. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  517. }
  518. void btsnd_hcic_delete_stored_key(const RawAddress& bd_addr,
  519. bool delete_all_flag) {
  520. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  521. uint8_t* pp = (uint8_t*)(p + 1);
  522. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_DELETE_STORED_KEY;
  523. p->offset = 0;
  524. UINT16_TO_STREAM(pp, HCI_DELETE_STORED_LINK_KEY);
  525. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_DELETE_STORED_KEY);
  526. BDADDR_TO_STREAM(pp, bd_addr);
  527. UINT8_TO_STREAM(pp, delete_all_flag);
  528. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  529. }
  530. void btsnd_hcic_change_name(BD_NAME name) {
  531. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  532. uint8_t* pp = (uint8_t*)(p + 1);
  533. uint16_t len = strlen((char*)name) + 1;
  534. memset(pp, 0, HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CHANGE_NAME);
  535. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CHANGE_NAME;
  536. p->offset = 0;
  537. UINT16_TO_STREAM(pp, HCI_CHANGE_LOCAL_NAME);
  538. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CHANGE_NAME);
  539. if (len > HCIC_PARAM_SIZE_CHANGE_NAME) len = HCIC_PARAM_SIZE_CHANGE_NAME;
  540. ARRAY_TO_STREAM(pp, name, len);
  541. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  542. }
  543. void btsnd_hcic_read_name(void) {
  544. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  545. uint8_t* pp = (uint8_t*)(p + 1);
  546. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
  547. p->offset = 0;
  548. UINT16_TO_STREAM(pp, HCI_READ_LOCAL_NAME);
  549. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CMD);
  550. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  551. }
  552. void btsnd_hcic_write_page_tout(uint16_t timeout) {
  553. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  554. uint8_t* pp = (uint8_t*)(p + 1);
  555. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM2;
  556. p->offset = 0;
  557. UINT16_TO_STREAM(pp, HCI_WRITE_PAGE_TOUT);
  558. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM2);
  559. UINT16_TO_STREAM(pp, timeout);
  560. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  561. }
  562. void btsnd_hcic_write_scan_enable(uint8_t flag) {
  563. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  564. uint8_t* pp = (uint8_t*)(p + 1);
  565. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1;
  566. p->offset = 0;
  567. UINT16_TO_STREAM(pp, HCI_WRITE_SCAN_ENABLE);
  568. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM1);
  569. UINT8_TO_STREAM(pp, flag);
  570. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  571. }
  572. void btsnd_hcic_write_pagescan_cfg(uint16_t interval, uint16_t window) {
  573. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  574. uint8_t* pp = (uint8_t*)(p + 1);
  575. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PAGESCAN_CFG;
  576. p->offset = 0;
  577. UINT16_TO_STREAM(pp, HCI_WRITE_PAGESCAN_CFG);
  578. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PAGESCAN_CFG);
  579. UINT16_TO_STREAM(pp, interval);
  580. UINT16_TO_STREAM(pp, window);
  581. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  582. }
  583. void btsnd_hcic_write_inqscan_cfg(uint16_t interval, uint16_t window) {
  584. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  585. uint8_t* pp = (uint8_t*)(p + 1);
  586. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_INQSCAN_CFG;
  587. p->offset = 0;
  588. UINT16_TO_STREAM(pp, HCI_WRITE_INQUIRYSCAN_CFG);
  589. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_INQSCAN_CFG);
  590. UINT16_TO_STREAM(pp, interval);
  591. UINT16_TO_STREAM(pp, window);
  592. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  593. }
  594. void btsnd_hcic_write_auth_enable(uint8_t flag) {
  595. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  596. uint8_t* pp = (uint8_t*)(p + 1);
  597. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1;
  598. p->offset = 0;
  599. UINT16_TO_STREAM(pp, HCI_WRITE_AUTHENTICATION_ENABLE);
  600. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM1);
  601. UINT8_TO_STREAM(pp, flag);
  602. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  603. }
  604. void btsnd_hcic_write_dev_class(DEV_CLASS dev_class) {
  605. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  606. uint8_t* pp = (uint8_t*)(p + 1);
  607. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM3;
  608. p->offset = 0;
  609. UINT16_TO_STREAM(pp, HCI_WRITE_CLASS_OF_DEVICE);
  610. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM3);
  611. DEVCLASS_TO_STREAM(pp, dev_class);
  612. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  613. }
  614. void btsnd_hcic_write_voice_settings(uint16_t flags) {
  615. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  616. uint8_t* pp = (uint8_t*)(p + 1);
  617. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM2;
  618. p->offset = 0;
  619. UINT16_TO_STREAM(pp, HCI_WRITE_VOICE_SETTINGS);
  620. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM2);
  621. UINT16_TO_STREAM(pp, flags);
  622. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  623. }
  624. void btsnd_hcic_write_auto_flush_tout(uint16_t handle, uint16_t tout) {
  625. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  626. uint8_t* pp = (uint8_t*)(p + 1);
  627. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_AUTOMATIC_FLUSH_TIMEOUT;
  628. p->offset = 0;
  629. UINT16_TO_STREAM(pp, HCI_WRITE_AUTOMATIC_FLUSH_TIMEOUT);
  630. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_AUTOMATIC_FLUSH_TIMEOUT);
  631. UINT16_TO_STREAM(pp, handle);
  632. UINT16_TO_STREAM(pp, tout);
  633. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  634. }
  635. void btsnd_hcic_read_tx_power(uint16_t handle, uint8_t type) {
  636. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  637. uint8_t* pp = (uint8_t*)(p + 1);
  638. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_TX_POWER;
  639. p->offset = 0;
  640. UINT16_TO_STREAM(pp, HCI_READ_TRANSMIT_POWER_LEVEL);
  641. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_TX_POWER);
  642. UINT16_TO_STREAM(pp, handle);
  643. UINT8_TO_STREAM(pp, type);
  644. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  645. }
  646. void btsnd_hcic_host_num_xmitted_pkts(uint8_t num_handles, uint16_t* handle,
  647. uint16_t* num_pkts) {
  648. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  649. uint8_t* pp = (uint8_t*)(p + 1);
  650. p->len = HCIC_PREAMBLE_SIZE + 1 + (num_handles * 4);
  651. p->offset = 0;
  652. UINT16_TO_STREAM(pp, HCI_HOST_NUM_PACKETS_DONE);
  653. UINT8_TO_STREAM(pp, p->len - HCIC_PREAMBLE_SIZE);
  654. UINT8_TO_STREAM(pp, num_handles);
  655. for (int i = 0; i < num_handles; i++) {
  656. UINT16_TO_STREAM(pp, handle[i]);
  657. UINT16_TO_STREAM(pp, num_pkts[i]);
  658. }
  659. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  660. }
  661. void btsnd_hcic_write_link_super_tout(uint8_t local_controller_id,
  662. uint16_t handle, uint16_t timeout) {
  663. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  664. uint8_t* pp = (uint8_t*)(p + 1);
  665. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_LINK_SUPER_TOUT;
  666. p->offset = 0;
  667. UINT16_TO_STREAM(pp, HCI_WRITE_LINK_SUPER_TOUT);
  668. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_LINK_SUPER_TOUT);
  669. UINT16_TO_STREAM(pp, handle);
  670. UINT16_TO_STREAM(pp, timeout);
  671. btu_hcif_send_cmd(local_controller_id, p);
  672. }
  673. void btsnd_hcic_write_cur_iac_lap(uint8_t num_cur_iac, LAP* const iac_lap) {
  674. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  675. uint8_t* pp = (uint8_t*)(p + 1);
  676. p->len = HCIC_PREAMBLE_SIZE + 1 + (LAP_LEN * num_cur_iac);
  677. p->offset = 0;
  678. UINT16_TO_STREAM(pp, HCI_WRITE_CURRENT_IAC_LAP);
  679. UINT8_TO_STREAM(pp, p->len - HCIC_PREAMBLE_SIZE);
  680. UINT8_TO_STREAM(pp, num_cur_iac);
  681. for (int i = 0; i < num_cur_iac; i++) LAP_TO_STREAM(pp, iac_lap[i]);
  682. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  683. }
  684. /******************************************
  685. * Lisbon Features
  686. ******************************************/
  687. #if (BTM_SSR_INCLUDED == TRUE)
  688. void btsnd_hcic_sniff_sub_rate(uint16_t handle, uint16_t max_lat,
  689. uint16_t min_remote_lat,
  690. uint16_t min_local_lat) {
  691. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  692. uint8_t* pp = (uint8_t*)(p + 1);
  693. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SNIFF_SUB_RATE;
  694. p->offset = 0;
  695. UINT16_TO_STREAM(pp, HCI_SNIFF_SUB_RATE);
  696. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SNIFF_SUB_RATE);
  697. UINT16_TO_STREAM(pp, handle);
  698. UINT16_TO_STREAM(pp, max_lat);
  699. UINT16_TO_STREAM(pp, min_remote_lat);
  700. UINT16_TO_STREAM(pp, min_local_lat);
  701. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  702. }
  703. #endif /* BTM_SSR_INCLUDED */
  704. /**** Extended Inquiry Response Commands ****/
  705. void btsnd_hcic_write_ext_inquiry_response(void* buffer, uint8_t fec_req) {
  706. BT_HDR* p = (BT_HDR*)buffer;
  707. uint8_t* pp = (uint8_t*)(p + 1);
  708. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_EXT_INQ_RESP;
  709. p->offset = 0;
  710. UINT16_TO_STREAM(pp, HCI_WRITE_EXT_INQ_RESPONSE);
  711. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_EXT_INQ_RESP);
  712. UINT8_TO_STREAM(pp, fec_req);
  713. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  714. }
  715. void btsnd_hcic_io_cap_req_reply(const RawAddress& bd_addr, uint8_t capability,
  716. uint8_t oob_present, uint8_t auth_req) {
  717. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  718. uint8_t* pp = (uint8_t*)(p + 1);
  719. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_IO_CAP_RESP;
  720. p->offset = 0;
  721. UINT16_TO_STREAM(pp, HCI_IO_CAPABILITY_REQUEST_REPLY);
  722. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_IO_CAP_RESP);
  723. BDADDR_TO_STREAM(pp, bd_addr);
  724. UINT8_TO_STREAM(pp, capability);
  725. UINT8_TO_STREAM(pp, oob_present);
  726. UINT8_TO_STREAM(pp, auth_req);
  727. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  728. }
  729. void btsnd_hcic_enhanced_set_up_synchronous_connection(
  730. uint16_t conn_handle, enh_esco_params_t* p_params) {
  731. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  732. uint8_t* pp = (uint8_t*)(p + 1);
  733. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ENH_SET_ESCO_CONN;
  734. p->offset = 0;
  735. UINT16_TO_STREAM(pp, HCI_ENH_SETUP_ESCO_CONNECTION);
  736. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ENH_SET_ESCO_CONN);
  737. UINT16_TO_STREAM(pp, conn_handle);
  738. UINT32_TO_STREAM(pp, p_params->transmit_bandwidth);
  739. UINT32_TO_STREAM(pp, p_params->receive_bandwidth);
  740. UINT8_TO_STREAM(pp, p_params->transmit_coding_format.coding_format);
  741. UINT16_TO_STREAM(pp, p_params->transmit_coding_format.company_id);
  742. UINT16_TO_STREAM(pp,
  743. p_params->transmit_coding_format.vendor_specific_codec_id);
  744. UINT8_TO_STREAM(pp, p_params->receive_coding_format.coding_format);
  745. UINT16_TO_STREAM(pp, p_params->receive_coding_format.company_id);
  746. UINT16_TO_STREAM(pp,
  747. p_params->receive_coding_format.vendor_specific_codec_id);
  748. UINT16_TO_STREAM(pp, p_params->transmit_codec_frame_size);
  749. UINT16_TO_STREAM(pp, p_params->receive_codec_frame_size);
  750. UINT32_TO_STREAM(pp, p_params->input_bandwidth);
  751. UINT32_TO_STREAM(pp, p_params->output_bandwidth);
  752. UINT8_TO_STREAM(pp, p_params->input_coding_format.coding_format);
  753. UINT16_TO_STREAM(pp, p_params->input_coding_format.company_id);
  754. UINT16_TO_STREAM(pp, p_params->input_coding_format.vendor_specific_codec_id);
  755. UINT8_TO_STREAM(pp, p_params->output_coding_format.coding_format);
  756. UINT16_TO_STREAM(pp, p_params->output_coding_format.company_id);
  757. UINT16_TO_STREAM(pp, p_params->output_coding_format.vendor_specific_codec_id);
  758. UINT16_TO_STREAM(pp, p_params->input_coded_data_size);
  759. UINT16_TO_STREAM(pp, p_params->output_coded_data_size);
  760. UINT8_TO_STREAM(pp, p_params->input_pcm_data_format);
  761. UINT8_TO_STREAM(pp, p_params->output_pcm_data_format);
  762. UINT8_TO_STREAM(pp, p_params->input_pcm_payload_msb_position);
  763. UINT8_TO_STREAM(pp, p_params->output_pcm_payload_msb_position);
  764. UINT8_TO_STREAM(pp, p_params->input_data_path);
  765. UINT8_TO_STREAM(pp, p_params->output_data_path);
  766. UINT8_TO_STREAM(pp, p_params->input_transport_unit_size);
  767. UINT8_TO_STREAM(pp, p_params->output_transport_unit_size);
  768. UINT16_TO_STREAM(pp, p_params->max_latency_ms);
  769. UINT16_TO_STREAM(pp, p_params->packet_types);
  770. UINT8_TO_STREAM(pp, p_params->retransmission_effort);
  771. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  772. }
  773. void btsnd_hcic_enhanced_accept_synchronous_connection(
  774. const RawAddress& bd_addr, enh_esco_params_t* p_params) {
  775. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  776. uint8_t* pp = (uint8_t*)(p + 1);
  777. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ENH_ACC_ESCO_CONN;
  778. p->offset = 0;
  779. UINT16_TO_STREAM(pp, HCI_ENH_ACCEPT_ESCO_CONNECTION);
  780. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ENH_ACC_ESCO_CONN);
  781. BDADDR_TO_STREAM(pp, bd_addr);
  782. UINT32_TO_STREAM(pp, p_params->transmit_bandwidth);
  783. UINT32_TO_STREAM(pp, p_params->receive_bandwidth);
  784. UINT8_TO_STREAM(pp, p_params->transmit_coding_format.coding_format);
  785. UINT16_TO_STREAM(pp, p_params->transmit_coding_format.company_id);
  786. UINT16_TO_STREAM(pp,
  787. p_params->transmit_coding_format.vendor_specific_codec_id);
  788. UINT8_TO_STREAM(pp, p_params->receive_coding_format.coding_format);
  789. UINT16_TO_STREAM(pp, p_params->receive_coding_format.company_id);
  790. UINT16_TO_STREAM(pp,
  791. p_params->receive_coding_format.vendor_specific_codec_id);
  792. UINT16_TO_STREAM(pp, p_params->transmit_codec_frame_size);
  793. UINT16_TO_STREAM(pp, p_params->receive_codec_frame_size);
  794. UINT32_TO_STREAM(pp, p_params->input_bandwidth);
  795. UINT32_TO_STREAM(pp, p_params->output_bandwidth);
  796. UINT8_TO_STREAM(pp, p_params->input_coding_format.coding_format);
  797. UINT16_TO_STREAM(pp, p_params->input_coding_format.company_id);
  798. UINT16_TO_STREAM(pp, p_params->input_coding_format.vendor_specific_codec_id);
  799. UINT8_TO_STREAM(pp, p_params->output_coding_format.coding_format);
  800. UINT16_TO_STREAM(pp, p_params->output_coding_format.company_id);
  801. UINT16_TO_STREAM(pp, p_params->output_coding_format.vendor_specific_codec_id);
  802. UINT16_TO_STREAM(pp, p_params->input_coded_data_size);
  803. UINT16_TO_STREAM(pp, p_params->output_coded_data_size);
  804. UINT8_TO_STREAM(pp, p_params->input_pcm_data_format);
  805. UINT8_TO_STREAM(pp, p_params->output_pcm_data_format);
  806. UINT8_TO_STREAM(pp, p_params->input_pcm_payload_msb_position);
  807. UINT8_TO_STREAM(pp, p_params->output_pcm_payload_msb_position);
  808. UINT8_TO_STREAM(pp, p_params->input_data_path);
  809. UINT8_TO_STREAM(pp, p_params->output_data_path);
  810. UINT8_TO_STREAM(pp, p_params->input_transport_unit_size);
  811. UINT8_TO_STREAM(pp, p_params->output_transport_unit_size);
  812. UINT16_TO_STREAM(pp, p_params->max_latency_ms);
  813. UINT16_TO_STREAM(pp, p_params->packet_types);
  814. UINT8_TO_STREAM(pp, p_params->retransmission_effort);
  815. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  816. }
  817. void btsnd_hcic_io_cap_req_neg_reply(const RawAddress& bd_addr,
  818. uint8_t err_code) {
  819. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  820. uint8_t* pp = (uint8_t*)(p + 1);
  821. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_IO_CAP_NEG_REPLY;
  822. p->offset = 0;
  823. UINT16_TO_STREAM(pp, HCI_IO_CAP_REQ_NEG_REPLY);
  824. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_IO_CAP_NEG_REPLY);
  825. BDADDR_TO_STREAM(pp, bd_addr);
  826. UINT8_TO_STREAM(pp, err_code);
  827. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  828. }
  829. void btsnd_hcic_read_local_oob_data(void) {
  830. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  831. uint8_t* pp = (uint8_t*)(p + 1);
  832. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_R_LOCAL_OOB;
  833. p->offset = 0;
  834. UINT16_TO_STREAM(pp, HCI_READ_LOCAL_OOB_DATA);
  835. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_R_LOCAL_OOB);
  836. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  837. }
  838. void btsnd_hcic_user_conf_reply(const RawAddress& bd_addr, bool is_yes) {
  839. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  840. uint8_t* pp = (uint8_t*)(p + 1);
  841. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_UCONF_REPLY;
  842. p->offset = 0;
  843. if (!is_yes) {
  844. /* Negative reply */
  845. UINT16_TO_STREAM(pp, HCI_USER_CONF_VALUE_NEG_REPLY);
  846. } else {
  847. /* Confirmation */
  848. UINT16_TO_STREAM(pp, HCI_USER_CONF_REQUEST_REPLY);
  849. }
  850. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_UCONF_REPLY);
  851. BDADDR_TO_STREAM(pp, bd_addr);
  852. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  853. }
  854. void btsnd_hcic_user_passkey_reply(const RawAddress& bd_addr, uint32_t value) {
  855. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  856. uint8_t* pp = (uint8_t*)(p + 1);
  857. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_U_PKEY_REPLY;
  858. p->offset = 0;
  859. UINT16_TO_STREAM(pp, HCI_USER_PASSKEY_REQ_REPLY);
  860. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_U_PKEY_REPLY);
  861. BDADDR_TO_STREAM(pp, bd_addr);
  862. UINT32_TO_STREAM(pp, value);
  863. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  864. }
  865. void btsnd_hcic_user_passkey_neg_reply(const RawAddress& bd_addr) {
  866. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  867. uint8_t* pp = (uint8_t*)(p + 1);
  868. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_U_PKEY_NEG_REPLY;
  869. p->offset = 0;
  870. UINT16_TO_STREAM(pp, HCI_USER_PASSKEY_REQ_NEG_REPLY);
  871. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_U_PKEY_NEG_REPLY);
  872. BDADDR_TO_STREAM(pp, bd_addr);
  873. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  874. }
  875. void btsnd_hcic_rem_oob_reply(const RawAddress& bd_addr, const Octet16& c,
  876. const Octet16& r) {
  877. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  878. uint8_t* pp = (uint8_t*)(p + 1);
  879. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REM_OOB_REPLY;
  880. p->offset = 0;
  881. UINT16_TO_STREAM(pp, HCI_REM_OOB_DATA_REQ_REPLY);
  882. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_REM_OOB_REPLY);
  883. BDADDR_TO_STREAM(pp, bd_addr);
  884. ARRAY16_TO_STREAM(pp, c.data());
  885. ARRAY16_TO_STREAM(pp, r.data());
  886. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  887. }
  888. void btsnd_hcic_rem_oob_neg_reply(const RawAddress& bd_addr) {
  889. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  890. uint8_t* pp = (uint8_t*)(p + 1);
  891. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REM_OOB_NEG_REPLY;
  892. p->offset = 0;
  893. UINT16_TO_STREAM(pp, HCI_REM_OOB_DATA_REQ_NEG_REPLY);
  894. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_REM_OOB_NEG_REPLY);
  895. BDADDR_TO_STREAM(pp, bd_addr);
  896. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  897. }
  898. void btsnd_hcic_read_inq_tx_power(void) {
  899. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  900. uint8_t* pp = (uint8_t*)(p + 1);
  901. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_R_TX_POWER;
  902. p->offset = 0;
  903. UINT16_TO_STREAM(pp, HCI_READ_INQ_TX_POWER_LEVEL);
  904. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_R_TX_POWER);
  905. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  906. }
  907. void btsnd_hcic_send_keypress_notif(const RawAddress& bd_addr, uint8_t notif) {
  908. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  909. uint8_t* pp = (uint8_t*)(p + 1);
  910. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SEND_KEYPRESS_NOTIF;
  911. p->offset = 0;
  912. UINT16_TO_STREAM(pp, HCI_SEND_KEYPRESS_NOTIF);
  913. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SEND_KEYPRESS_NOTIF);
  914. BDADDR_TO_STREAM(pp, bd_addr);
  915. UINT8_TO_STREAM(pp, notif);
  916. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  917. }
  918. /**** end of Simple Pairing Commands ****/
  919. #if (L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE)
  920. void btsnd_hcic_enhanced_flush(uint16_t handle, uint8_t packet_type) {
  921. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  922. uint8_t* pp = (uint8_t*)(p + 1);
  923. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ENHANCED_FLUSH;
  924. p->offset = 0;
  925. UINT16_TO_STREAM(pp, HCI_ENHANCED_FLUSH);
  926. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_ENHANCED_FLUSH);
  927. UINT16_TO_STREAM(pp, handle);
  928. UINT8_TO_STREAM(pp, packet_type);
  929. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  930. }
  931. #endif
  932. /*************************
  933. * End of Lisbon Commands
  934. *************************/
  935. void btsnd_hcic_get_link_quality(uint16_t handle) {
  936. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  937. uint8_t* pp = (uint8_t*)(p + 1);
  938. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
  939. p->offset = 0;
  940. UINT16_TO_STREAM(pp, HCI_GET_LINK_QUALITY);
  941. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE);
  942. UINT16_TO_STREAM(pp, handle);
  943. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  944. }
  945. void btsnd_hcic_read_rssi(uint16_t handle) {
  946. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  947. uint8_t* pp = (uint8_t*)(p + 1);
  948. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
  949. p->offset = 0;
  950. UINT16_TO_STREAM(pp, HCI_READ_RSSI);
  951. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE);
  952. UINT16_TO_STREAM(pp, handle);
  953. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  954. }
  955. static void read_encryption_key_size_complete(ReadEncKeySizeCb cb, uint8_t* return_parameters,
  956. uint16_t return_parameters_length) {
  957. uint8_t status;
  958. uint16_t handle;
  959. uint8_t key_size;
  960. STREAM_TO_UINT8(status, return_parameters);
  961. STREAM_TO_UINT16(handle, return_parameters);
  962. STREAM_TO_UINT8(key_size, return_parameters);
  963. std::move(cb).Run(status, handle, key_size);
  964. }
  965. void btsnd_hcic_read_encryption_key_size(uint16_t handle, ReadEncKeySizeCb cb) {
  966. constexpr uint8_t len = 2;
  967. uint8_t param[len];
  968. memset(param, 0, len);
  969. uint8_t* p = param;
  970. UINT16_TO_STREAM(p, handle);
  971. btu_hcif_send_cmd_with_cb(FROM_HERE, HCI_READ_ENCR_KEY_SIZE, param, len,
  972. base::Bind(&read_encryption_key_size_complete, base::Passed(&cb)));
  973. }
  974. void btsnd_hcic_read_failed_contact_counter(uint16_t handle) {
  975. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  976. uint8_t* pp = (uint8_t*)(p + 1);
  977. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
  978. p->offset = 0;
  979. UINT16_TO_STREAM(pp, HCI_READ_FAILED_CONTACT_COUNTER);
  980. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE);
  981. UINT16_TO_STREAM(pp, handle);
  982. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  983. }
  984. void btsnd_hcic_read_automatic_flush_timeout(uint16_t handle) {
  985. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  986. uint8_t* pp = (uint8_t*)(p + 1);
  987. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
  988. p->offset = 0;
  989. UINT16_TO_STREAM(pp, HCI_READ_AUTOMATIC_FLUSH_TIMEOUT);
  990. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CMD_HANDLE);
  991. UINT16_TO_STREAM(pp, handle);
  992. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  993. }
  994. void btsnd_hcic_enable_test_mode(void) {
  995. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  996. uint8_t* pp = (uint8_t*)(p + 1);
  997. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
  998. p->offset = 0;
  999. UINT16_TO_STREAM(pp, HCI_ENABLE_DEV_UNDER_TEST_MODE);
  1000. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_CMD);
  1001. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  1002. }
  1003. void btsnd_hcic_write_inqscan_type(uint8_t type) {
  1004. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  1005. uint8_t* pp = (uint8_t*)(p + 1);
  1006. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1;
  1007. p->offset = 0;
  1008. UINT16_TO_STREAM(pp, HCI_WRITE_INQSCAN_TYPE);
  1009. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM1);
  1010. UINT8_TO_STREAM(pp, type);
  1011. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  1012. }
  1013. void btsnd_hcic_write_inquiry_mode(uint8_t mode) {
  1014. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  1015. uint8_t* pp = (uint8_t*)(p + 1);
  1016. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1;
  1017. p->offset = 0;
  1018. UINT16_TO_STREAM(pp, HCI_WRITE_INQUIRY_MODE);
  1019. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM1);
  1020. UINT8_TO_STREAM(pp, mode);
  1021. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  1022. }
  1023. void btsnd_hcic_write_pagescan_type(uint8_t type) {
  1024. BT_HDR* p = (BT_HDR*)osi_malloc(HCI_CMD_BUF_SIZE);
  1025. uint8_t* pp = (uint8_t*)(p + 1);
  1026. p->len = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1;
  1027. p->offset = 0;
  1028. UINT16_TO_STREAM(pp, HCI_WRITE_PAGESCAN_TYPE);
  1029. UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_PARAM1);
  1030. UINT8_TO_STREAM(pp, type);
  1031. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  1032. }
  1033. /* Must have room to store BT_HDR + max VSC length + callback pointer */
  1034. #if (HCI_CMD_BUF_SIZE < 268)
  1035. #error "HCI_CMD_BUF_SIZE must be larger than 268"
  1036. #endif
  1037. void btsnd_hcic_vendor_spec_cmd(void* buffer, uint16_t opcode, uint8_t len,
  1038. uint8_t* p_data, void* p_cmd_cplt_cback) {
  1039. BT_HDR* p = (BT_HDR*)buffer;
  1040. uint8_t* pp = (uint8_t*)(p + 1);
  1041. p->len = HCIC_PREAMBLE_SIZE + len;
  1042. p->offset = sizeof(void*);
  1043. *((void**)pp) =
  1044. p_cmd_cplt_cback; /* Store command complete callback in buffer */
  1045. pp += sizeof(void*); /* Skip over callback pointer */
  1046. UINT16_TO_STREAM(pp, HCI_GRP_VENDOR_SPECIFIC | opcode);
  1047. UINT8_TO_STREAM(pp, len);
  1048. ARRAY_TO_STREAM(pp, p_data, len);
  1049. btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p);
  1050. }