1 /******************************************************************************
2  *
3  *  Copyright (C) 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  *
21  *  This file contains function of the HCIC unit to format and send HCI
22  *  commands.
23  *
24  ******************************************************************************/
25 
26 #include "common/bt_target.h"
27 #include "osi/allocator.h"
28 #include "stack/hcidefs.h"
29 #include "stack/hcimsgs.h"
30 #include "stack/hcidefs.h"
31 #include "stack/btu.h"
32 
33 #include <stddef.h>
34 #include <string.h>
35 
36 #include "btm_int.h"    /* Included for UIPC_* macro definitions */
37 
btsnd_hcic_inquiry(const LAP inq_lap,UINT8 duration,UINT8 response_cnt)38 BOOLEAN btsnd_hcic_inquiry(const LAP inq_lap, UINT8 duration, UINT8 response_cnt)
39 {
40     BT_HDR *p;
41     UINT8 *pp;
42 
43     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_INQUIRY)) == NULL) {
44         return (FALSE);
45     }
46 
47     pp = (UINT8 *)(p + 1);
48 
49     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_INQUIRY;
50     p->offset = 0;
51 
52     UINT16_TO_STREAM (pp, HCI_INQUIRY);
53     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_INQUIRY);
54 
55     LAP_TO_STREAM   (pp, inq_lap);
56     UINT8_TO_STREAM (pp, duration);
57     UINT8_TO_STREAM (pp, response_cnt);
58 
59     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
60     return (TRUE);
61 }
62 
btsnd_hcic_inq_cancel(void)63 BOOLEAN btsnd_hcic_inq_cancel(void)
64 {
65     BT_HDR *p;
66     UINT8 *pp;
67 
68     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_INQ_CANCEL)) == NULL) {
69         return (FALSE);
70     }
71 
72     pp = (UINT8 *)(p + 1);
73 
74     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_INQ_CANCEL;
75     p->offset = 0;
76     UINT16_TO_STREAM (pp, HCI_INQUIRY_CANCEL);
77     UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_INQ_CANCEL);
78 
79     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
80     return (TRUE);
81 }
82 
btsnd_hcic_per_inq_mode(UINT16 max_period,UINT16 min_period,const LAP inq_lap,UINT8 duration,UINT8 response_cnt)83 BOOLEAN btsnd_hcic_per_inq_mode (UINT16 max_period, UINT16 min_period,
84                                  const LAP inq_lap, UINT8 duration, UINT8 response_cnt)
85 {
86     BT_HDR *p;
87     UINT8 *pp;
88 
89     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_PER_INQ_MODE)) == NULL) {
90         return (FALSE);
91     }
92 
93     pp = (UINT8 *)(p + 1);
94 
95     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PER_INQ_MODE;
96     p->offset = 0;
97 
98     UINT16_TO_STREAM (pp, HCI_PERIODIC_INQUIRY_MODE);
99     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_PER_INQ_MODE);
100 
101     UINT16_TO_STREAM (pp, max_period);
102     UINT16_TO_STREAM (pp, min_period);
103     LAP_TO_STREAM    (pp, inq_lap);
104     UINT8_TO_STREAM  (pp, duration);
105     UINT8_TO_STREAM  (pp, response_cnt);
106 
107     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
108     return (TRUE);
109 }
110 
btsnd_hcic_exit_per_inq(void)111 BOOLEAN btsnd_hcic_exit_per_inq (void)
112 {
113     BT_HDR *p;
114     UINT8 *pp;
115 
116     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_EXIT_PER_INQ)) == NULL) {
117         return (FALSE);
118     }
119 
120     pp = (UINT8 *)(p + 1);
121 
122     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_EXIT_PER_INQ;
123     p->offset = 0;
124     UINT16_TO_STREAM (pp, HCI_EXIT_PERIODIC_INQUIRY_MODE);
125     UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_EXIT_PER_INQ);
126 
127     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
128     return (TRUE);
129 }
130 
131 
btsnd_hcic_create_conn(BD_ADDR dest,UINT16 packet_types,UINT8 page_scan_rep_mode,UINT8 page_scan_mode,UINT16 clock_offset,UINT8 allow_switch)132 BOOLEAN btsnd_hcic_create_conn(BD_ADDR dest, UINT16 packet_types,
133                                UINT8 page_scan_rep_mode, UINT8 page_scan_mode,
134                                UINT16 clock_offset, UINT8 allow_switch)
135 {
136     BT_HDR *p;
137     UINT8 *pp;
138 
139     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_CREATE_CONN)) == NULL) {
140         return (FALSE);
141     }
142 
143     pp = (UINT8 *)(p + 1);
144 
145 #ifndef BT_10A
146     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CREATE_CONN;
147 #else
148     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CREATE_CONN - 1;
149 #endif
150     p->offset = 0;
151 
152     UINT16_TO_STREAM (pp, HCI_CREATE_CONNECTION);
153 #ifndef BT_10A
154     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_CREATE_CONN);
155 #else
156     UINT8_TO_STREAM  (pp, (HCIC_PARAM_SIZE_CREATE_CONN - 1));
157 #endif
158     BDADDR_TO_STREAM (pp, dest);
159     UINT16_TO_STREAM (pp, packet_types);
160     UINT8_TO_STREAM  (pp, page_scan_rep_mode);
161     UINT8_TO_STREAM  (pp, page_scan_mode);
162     UINT16_TO_STREAM (pp, clock_offset);
163 #if !defined (BT_10A)
164     UINT8_TO_STREAM  (pp, allow_switch);
165 #endif
166 #if (SMP_INCLUDED == TRUE && CLASSIC_BT_INCLUDED == TRUE)
167     btm_acl_paging (p, dest);
168 #endif  ///SMP_INCLUDED == TRUE && CLASSIC_BT_INCLUDED == TRUE
169     return (TRUE);
170 }
171 
btsnd_hcic_disconnect(UINT16 handle,UINT8 reason)172 BOOLEAN btsnd_hcic_disconnect (UINT16 handle, UINT8 reason)
173 {
174     BT_HDR *p;
175     UINT8 *pp;
176 
177     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_DISCONNECT)) == NULL) {
178         return (FALSE);
179     }
180 
181     pp = (UINT8 *)(p + 1);
182 
183     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_DISCONNECT;
184     p->offset = 0;
185 
186     UINT16_TO_STREAM (pp, HCI_DISCONNECT);
187     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_DISCONNECT);
188     UINT16_TO_STREAM (pp, handle);
189     UINT8_TO_STREAM  (pp, reason);
190 
191     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
192     HCI_TRACE_WARNING("hci cmd send: disconnect: hdl 0x%x, rsn:0x%x", handle, reason);
193     return (TRUE);
194 }
195 
196 #if BTM_SCO_INCLUDED == TRUE
btsnd_hcic_add_SCO_conn(UINT16 handle,UINT16 packet_types)197 BOOLEAN btsnd_hcic_add_SCO_conn (UINT16 handle, UINT16 packet_types)
198 {
199     BT_HDR *p;
200     UINT8 *pp;
201 
202     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_ADD_SCO_CONN)) == NULL) {
203         return (FALSE);
204     }
205 
206     pp = (UINT8 *)(p + 1);
207 
208     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ADD_SCO_CONN;
209     p->offset = 0;
210 
211     UINT16_TO_STREAM (pp, HCI_ADD_SCO_CONNECTION);
212     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_ADD_SCO_CONN);
213 
214     UINT16_TO_STREAM (pp, handle);
215     UINT16_TO_STREAM (pp, packet_types);
216 
217     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
218     return (TRUE);
219 }
220 #endif /* BTM_SCO_INCLUDED */
221 
btsnd_hcic_create_conn_cancel(BD_ADDR dest)222 BOOLEAN btsnd_hcic_create_conn_cancel(BD_ADDR dest)
223 {
224     BT_HDR *p;
225     UINT8 *pp;
226 
227     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_CREATE_CONN_CANCEL)) == NULL) {
228         return (FALSE);
229     }
230 
231     pp = (UINT8 *)(p + 1);
232 
233     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CREATE_CONN_CANCEL;
234     p->offset = 0;
235 
236     UINT16_TO_STREAM (pp, HCI_CREATE_CONNECTION_CANCEL);
237     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_CREATE_CONN_CANCEL);
238 
239     BDADDR_TO_STREAM (pp, dest);
240 
241     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
242     return (TRUE);
243 }
244 
btsnd_hcic_accept_conn(BD_ADDR dest,UINT8 role)245 BOOLEAN btsnd_hcic_accept_conn (BD_ADDR dest, UINT8 role)
246 {
247     BT_HDR *p;
248     UINT8 *pp;
249 
250     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_ACCEPT_CONN)) == NULL) {
251         return (FALSE);
252     }
253 
254     pp = (UINT8 *)(p + 1);
255 
256     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ACCEPT_CONN;
257     p->offset = 0;
258 
259     UINT16_TO_STREAM (pp, HCI_ACCEPT_CONNECTION_REQUEST);
260     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_ACCEPT_CONN);
261     BDADDR_TO_STREAM (pp, dest);
262     UINT8_TO_STREAM  (pp, role);
263 
264     //counter_add("hci.conn.accept", 1);
265 
266     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
267     return (TRUE);
268 }
269 
btsnd_hcic_reject_conn(BD_ADDR dest,UINT8 reason)270 BOOLEAN btsnd_hcic_reject_conn (BD_ADDR dest, UINT8 reason)
271 {
272     BT_HDR *p;
273     UINT8 *pp;
274 
275     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_REJECT_CONN)) == NULL) {
276         return (FALSE);
277     }
278 
279     pp = (UINT8 *)(p + 1);
280 
281     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REJECT_CONN;
282     p->offset = 0;
283 
284     UINT16_TO_STREAM (pp, HCI_REJECT_CONNECTION_REQUEST);
285     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_REJECT_CONN);
286 
287     BDADDR_TO_STREAM (pp, dest);
288     UINT8_TO_STREAM (pp, reason);
289 
290     //counter_add("hci.conn.reject", 1);
291 
292     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
293     return (TRUE);
294 }
295 
btsnd_hcic_link_key_req_reply(BD_ADDR bd_addr,LINK_KEY link_key)296 BOOLEAN btsnd_hcic_link_key_req_reply (BD_ADDR bd_addr, LINK_KEY link_key)
297 {
298     BT_HDR *p;
299     UINT8 *pp;
300 
301     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_LINK_KEY_REQ_REPLY)) == NULL) {
302         return (FALSE);
303     }
304 
305     pp = (UINT8 *)(p + 1);
306 
307     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LINK_KEY_REQ_REPLY;
308     p->offset = 0;
309 
310     UINT16_TO_STREAM  (pp, HCI_LINK_KEY_REQUEST_REPLY);
311     UINT8_TO_STREAM   (pp, HCIC_PARAM_SIZE_LINK_KEY_REQ_REPLY);
312 
313     BDADDR_TO_STREAM  (pp, bd_addr);
314     ARRAY16_TO_STREAM (pp, link_key);
315 
316     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
317     return (TRUE);
318 }
319 
btsnd_hcic_link_key_neg_reply(BD_ADDR bd_addr)320 BOOLEAN btsnd_hcic_link_key_neg_reply (BD_ADDR bd_addr)
321 {
322     BT_HDR *p;
323     UINT8 *pp;
324 
325     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_LINK_KEY_NEG_REPLY)) == NULL) {
326         return (FALSE);
327     }
328 
329     pp = (UINT8 *)(p + 1);
330 
331     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_LINK_KEY_NEG_REPLY;
332     p->offset = 0;
333 
334     UINT16_TO_STREAM (pp, HCI_LINK_KEY_REQUEST_NEG_REPLY);
335     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_LINK_KEY_NEG_REPLY);
336 
337     BDADDR_TO_STREAM (pp, bd_addr);
338 
339     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
340     return (TRUE);
341 }
342 
btsnd_hcic_pin_code_req_reply(BD_ADDR bd_addr,UINT8 pin_code_len,PIN_CODE pin_code)343 BOOLEAN btsnd_hcic_pin_code_req_reply (BD_ADDR bd_addr, UINT8 pin_code_len,
344                                        PIN_CODE pin_code)
345 {
346     BT_HDR *p;
347     UINT8  *pp;
348     int     i;
349 
350     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_PIN_CODE_REQ_REPLY)) == NULL) {
351         return (FALSE);
352     }
353 
354     pp = (UINT8 *)(p + 1);
355 
356     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PIN_CODE_REQ_REPLY;
357     p->offset = 0;
358 
359     UINT16_TO_STREAM  (pp, HCI_PIN_CODE_REQUEST_REPLY);
360     UINT8_TO_STREAM   (pp, HCIC_PARAM_SIZE_PIN_CODE_REQ_REPLY);
361 
362     BDADDR_TO_STREAM  (pp, bd_addr);
363     UINT8_TO_STREAM   (pp, pin_code_len);
364 
365     for (i = 0; i < pin_code_len; i++) {
366         *pp++ = *pin_code++;
367     }
368 
369     for (; i < PIN_CODE_LEN; i++) {
370         *pp++ = 0;
371     }
372 
373 
374     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
375     return (TRUE);
376 }
377 
btsnd_hcic_pin_code_neg_reply(BD_ADDR bd_addr)378 BOOLEAN btsnd_hcic_pin_code_neg_reply (BD_ADDR bd_addr)
379 {
380     BT_HDR *p;
381     UINT8 *pp;
382 
383     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_PIN_CODE_NEG_REPLY)) == NULL) {
384         return (FALSE);
385     }
386 
387     pp = (UINT8 *)(p + 1);
388 
389     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PIN_CODE_NEG_REPLY;
390     p->offset = 0;
391 
392     UINT16_TO_STREAM (pp, HCI_PIN_CODE_REQUEST_NEG_REPLY);
393     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_PIN_CODE_NEG_REPLY);
394 
395     BDADDR_TO_STREAM (pp, bd_addr);
396 
397     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
398     return (TRUE);
399 }
400 
btsnd_hcic_change_conn_type(UINT16 handle,UINT16 packet_types)401 BOOLEAN btsnd_hcic_change_conn_type (UINT16 handle, UINT16 packet_types)
402 {
403     BT_HDR *p;
404     UINT8 *pp;
405 
406     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_CHANGE_CONN_TYPE)) == NULL) {
407         return (FALSE);
408     }
409 
410     pp = (UINT8 *)(p + 1);
411 
412     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CHANGE_CONN_TYPE;
413     p->offset = 0;
414 
415     UINT16_TO_STREAM (pp, HCI_CHANGE_CONN_PACKET_TYPE);
416     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_CHANGE_CONN_TYPE);
417 
418     UINT16_TO_STREAM (pp, handle);
419     UINT16_TO_STREAM (pp, packet_types);
420 
421     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
422     return (TRUE);
423 }
424 
btsnd_hcic_auth_request(UINT16 handle)425 BOOLEAN btsnd_hcic_auth_request (UINT16 handle)
426 {
427     BT_HDR *p;
428     UINT8 *pp;
429 
430     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_CMD_HANDLE)) == NULL) {
431         return (FALSE);
432     }
433 
434     pp = (UINT8 *)(p + 1);
435 
436     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
437     p->offset = 0;
438 
439     UINT16_TO_STREAM (pp, HCI_AUTHENTICATION_REQUESTED);
440     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_CMD_HANDLE);
441 
442     UINT16_TO_STREAM (pp, handle);
443 
444     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
445     return (TRUE);
446 }
447 
btsnd_hcic_set_conn_encrypt(UINT16 handle,BOOLEAN enable)448 BOOLEAN btsnd_hcic_set_conn_encrypt (UINT16 handle, BOOLEAN enable)
449 {
450     BT_HDR *p;
451     UINT8 *pp;
452 
453     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_SET_CONN_ENCRYPT)) == NULL) {
454         return (FALSE);
455     }
456 
457     pp = (UINT8 *)(p + 1);
458 
459     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_CONN_ENCRYPT;
460     p->offset = 0;
461 
462     UINT16_TO_STREAM (pp, HCI_SET_CONN_ENCRYPTION);
463     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_SET_CONN_ENCRYPT);
464 
465     UINT16_TO_STREAM (pp, handle);
466     UINT8_TO_STREAM  (pp, enable);
467 
468     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
469     return (TRUE);
470 }
471 
btsnd_hcic_rmt_name_req(BD_ADDR bd_addr,UINT8 page_scan_rep_mode,UINT8 page_scan_mode,UINT16 clock_offset)472 BOOLEAN btsnd_hcic_rmt_name_req (BD_ADDR bd_addr, UINT8 page_scan_rep_mode,
473                                  UINT8 page_scan_mode, UINT16 clock_offset)
474 {
475     BT_HDR *p;
476     UINT8 *pp;
477 
478     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_RMT_NAME_REQ)) == NULL) {
479         return (FALSE);
480     }
481 
482     pp = (UINT8 *)(p + 1);
483 
484     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_RMT_NAME_REQ;
485     p->offset = 0;
486 
487     UINT16_TO_STREAM (pp, HCI_RMT_NAME_REQUEST);
488     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_RMT_NAME_REQ);
489 
490     BDADDR_TO_STREAM (pp, bd_addr);
491     UINT8_TO_STREAM  (pp, page_scan_rep_mode);
492     UINT8_TO_STREAM  (pp, page_scan_mode);
493     UINT16_TO_STREAM (pp, clock_offset);
494 #if (SMP_INCLUDED == TRUE && CLASSIC_BT_INCLUDED == TRUE)
495     btm_acl_paging (p, bd_addr);
496 #endif  ///SMP_INCLUDED == TRUE && CLASSIC_BT_INCLUDED == TRUE
497     return (TRUE);
498 }
499 
btsnd_hcic_rmt_name_req_cancel(BD_ADDR bd_addr)500 BOOLEAN btsnd_hcic_rmt_name_req_cancel (BD_ADDR bd_addr)
501 {
502     BT_HDR *p;
503     UINT8 *pp;
504 
505     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_RMT_NAME_REQ_CANCEL)) == NULL) {
506         return (FALSE);
507     }
508 
509     pp = (UINT8 *)(p + 1);
510 
511     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_RMT_NAME_REQ_CANCEL;
512     p->offset = 0;
513 
514     UINT16_TO_STREAM (pp, HCI_RMT_NAME_REQUEST_CANCEL);
515     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_RMT_NAME_REQ_CANCEL);
516 
517     BDADDR_TO_STREAM (pp, bd_addr);
518 
519     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
520     return (TRUE);
521 }
522 
btsnd_hcic_rmt_features_req(UINT16 handle)523 BOOLEAN btsnd_hcic_rmt_features_req (UINT16 handle)
524 {
525     BT_HDR *p;
526     UINT8 *pp;
527 
528     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_CMD_HANDLE)) == NULL) {
529         return (FALSE);
530     }
531 
532     pp = (UINT8 *)(p + 1);
533 
534     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
535     p->offset = 0;
536 
537     UINT16_TO_STREAM (pp, HCI_READ_RMT_FEATURES);
538     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_CMD_HANDLE);
539 
540     UINT16_TO_STREAM (pp, handle);
541 
542     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
543     return (TRUE);
544 }
545 
btsnd_hcic_rmt_ext_features(UINT16 handle,UINT8 page_num)546 BOOLEAN btsnd_hcic_rmt_ext_features (UINT16 handle, UINT8 page_num)
547 {
548     BT_HDR *p;
549     UINT8 *pp;
550 
551     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_RMT_EXT_FEATURES)) == NULL) {
552         return (FALSE);
553     }
554 
555     pp = (UINT8 *)(p + 1);
556 
557     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_RMT_EXT_FEATURES;
558     p->offset = 0;
559 
560     UINT16_TO_STREAM (pp, HCI_READ_RMT_EXT_FEATURES);
561     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_RMT_EXT_FEATURES);
562 
563     UINT16_TO_STREAM (pp, handle);
564     UINT8_TO_STREAM (pp, page_num);
565 
566     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
567     return (TRUE);
568 }
569 
btsnd_hcic_rmt_ver_req(UINT16 handle)570 BOOLEAN btsnd_hcic_rmt_ver_req (UINT16 handle)
571 {
572     BT_HDR *p;
573     UINT8 *pp;
574 
575     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_CMD_HANDLE)) == NULL) {
576         return (FALSE);
577     }
578 
579     pp = (UINT8 *)(p + 1);
580 
581     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
582     p->offset = 0;
583 
584     UINT16_TO_STREAM (pp, HCI_READ_RMT_VERSION_INFO);
585     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_CMD_HANDLE);
586 
587     UINT16_TO_STREAM (pp, handle);
588 
589     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID, p);
590     return (TRUE);
591 }
592 
btsnd_hcic_read_rmt_clk_offset(UINT16 handle)593 BOOLEAN btsnd_hcic_read_rmt_clk_offset (UINT16 handle)
594 {
595     BT_HDR *p;
596     UINT8 *pp;
597 
598     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_CMD_HANDLE)) == NULL) {
599         return (FALSE);
600     }
601 
602     pp = (UINT8 *)(p + 1);
603 
604     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
605     p->offset = 0;
606 
607     UINT16_TO_STREAM (pp, HCI_READ_RMT_CLOCK_OFFSET);
608     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_CMD_HANDLE);
609 
610     UINT16_TO_STREAM (pp, handle);
611 
612     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
613     return (TRUE);
614 }
615 
btsnd_hcic_read_lmp_handle(UINT16 handle)616 BOOLEAN btsnd_hcic_read_lmp_handle (UINT16 handle)
617 {
618     BT_HDR *p;
619     UINT8 *pp;
620 
621     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_CMD_HANDLE)) == NULL) {
622         return (FALSE);
623     }
624 
625     pp = (UINT8 *)(p + 1);
626 
627     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
628     p->offset = 0;
629 
630     UINT16_TO_STREAM (pp, HCI_READ_LMP_HANDLE);
631     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_CMD_HANDLE);
632 
633     UINT16_TO_STREAM (pp, handle);
634 
635     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
636     return (TRUE);
637 }
638 
btsnd_hcic_setup_esco_conn(UINT16 handle,UINT32 tx_bw,UINT32 rx_bw,UINT16 max_latency,UINT16 voice,UINT8 retrans_effort,UINT16 packet_types)639 BOOLEAN btsnd_hcic_setup_esco_conn (UINT16 handle, UINT32 tx_bw,
640                                     UINT32 rx_bw, UINT16 max_latency, UINT16 voice,
641                                     UINT8 retrans_effort, UINT16 packet_types)
642 {
643     BT_HDR *p;
644     UINT8 *pp;
645 
646     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_SETUP_ESCO)) == NULL) {
647         return (FALSE);
648     }
649 
650     pp = (UINT8 *)(p + 1);
651 
652     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SETUP_ESCO;
653     p->offset = 0;
654 
655     UINT16_TO_STREAM (pp, HCI_SETUP_ESCO_CONNECTION);
656     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_SETUP_ESCO);
657 
658     UINT16_TO_STREAM (pp, handle);
659     UINT32_TO_STREAM (pp, tx_bw);
660     UINT32_TO_STREAM (pp, rx_bw);
661     UINT16_TO_STREAM (pp, max_latency);
662     UINT16_TO_STREAM (pp, voice);
663     UINT8_TO_STREAM  (pp, retrans_effort);
664     UINT16_TO_STREAM (pp, packet_types);
665 
666     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
667     return (TRUE);
668 }
669 
btsnd_hcic_accept_esco_conn(BD_ADDR bd_addr,UINT32 tx_bw,UINT32 rx_bw,UINT16 max_latency,UINT16 content_fmt,UINT8 retrans_effort,UINT16 packet_types)670 BOOLEAN btsnd_hcic_accept_esco_conn (BD_ADDR bd_addr, UINT32 tx_bw,
671                                      UINT32 rx_bw, UINT16 max_latency,
672                                      UINT16 content_fmt, UINT8 retrans_effort,
673                                      UINT16 packet_types)
674 {
675     BT_HDR *p;
676     UINT8 *pp;
677 
678     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_ACCEPT_ESCO)) == NULL) {
679         return (FALSE);
680     }
681 
682     pp = (UINT8 *)(p + 1);
683 
684     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ACCEPT_ESCO;
685     p->offset = 0;
686 
687     UINT16_TO_STREAM (pp, HCI_ACCEPT_ESCO_CONNECTION);
688     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_ACCEPT_ESCO);
689 
690     BDADDR_TO_STREAM (pp, bd_addr);
691     UINT32_TO_STREAM (pp, tx_bw);
692     UINT32_TO_STREAM (pp, rx_bw);
693     UINT16_TO_STREAM (pp, max_latency);
694     UINT16_TO_STREAM (pp, content_fmt);
695     UINT8_TO_STREAM  (pp, retrans_effort);
696     UINT16_TO_STREAM (pp, packet_types);
697 
698     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
699     return (TRUE);
700 }
701 
btsnd_hcic_reject_esco_conn(BD_ADDR bd_addr,UINT8 reason)702 BOOLEAN btsnd_hcic_reject_esco_conn (BD_ADDR bd_addr, UINT8 reason)
703 {
704     BT_HDR *p;
705     UINT8 *pp;
706 
707     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_REJECT_ESCO)) == NULL) {
708         return (FALSE);
709     }
710 
711     pp = (UINT8 *)(p + 1);
712 
713     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REJECT_ESCO;
714     p->offset = 0;
715 
716     UINT16_TO_STREAM (pp, HCI_REJECT_ESCO_CONNECTION);
717     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_REJECT_ESCO);
718 
719     BDADDR_TO_STREAM (pp, bd_addr);
720     UINT8_TO_STREAM  (pp, reason);
721 
722     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
723     return (TRUE);
724 }
725 
btsnd_hcic_hold_mode(UINT16 handle,UINT16 max_hold_period,UINT16 min_hold_period)726 BOOLEAN btsnd_hcic_hold_mode (UINT16 handle, UINT16 max_hold_period,
727                               UINT16 min_hold_period)
728 {
729     BT_HDR *p;
730     UINT8 *pp;
731 
732     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_HOLD_MODE)) == NULL) {
733         return (FALSE);
734     }
735 
736     pp = (UINT8 *)(p + 1);
737 
738     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_HOLD_MODE;
739     p->offset = 0;
740 
741     UINT16_TO_STREAM (pp, HCI_HOLD_MODE);
742     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_HOLD_MODE);
743 
744     UINT16_TO_STREAM (pp, handle);
745     UINT16_TO_STREAM (pp, max_hold_period);
746     UINT16_TO_STREAM (pp, min_hold_period);
747 
748     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
749     return (TRUE);
750 }
751 
btsnd_hcic_sniff_mode(UINT16 handle,UINT16 max_sniff_period,UINT16 min_sniff_period,UINT16 sniff_attempt,UINT16 sniff_timeout)752 BOOLEAN btsnd_hcic_sniff_mode (UINT16 handle, UINT16 max_sniff_period,
753                                UINT16 min_sniff_period, UINT16 sniff_attempt,
754                                UINT16 sniff_timeout)
755 {
756     BT_HDR *p;
757     UINT8 *pp;
758 
759     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_SNIFF_MODE)) == NULL) {
760         return (FALSE);
761     }
762 
763     pp = (UINT8 *)(p + 1);
764 
765     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SNIFF_MODE;
766     p->offset = 0;
767 
768     UINT16_TO_STREAM (pp, HCI_SNIFF_MODE);
769     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_SNIFF_MODE);
770 
771     UINT16_TO_STREAM (pp, handle);
772     UINT16_TO_STREAM (pp, max_sniff_period);
773     UINT16_TO_STREAM (pp, min_sniff_period);
774     UINT16_TO_STREAM (pp, sniff_attempt);
775     UINT16_TO_STREAM (pp, sniff_timeout);
776 
777     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
778     HCI_TRACE_WARNING("hci cmd send: sniff: hdl 0x%x, intv(%d %d)",
779                     handle, min_sniff_period, max_sniff_period);
780     return (TRUE);
781 }
782 
btsnd_hcic_exit_sniff_mode(UINT16 handle)783 BOOLEAN btsnd_hcic_exit_sniff_mode (UINT16 handle)
784 {
785     BT_HDR *p;
786     UINT8 *pp;
787 
788     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_CMD_HANDLE)) == NULL) {
789         return (FALSE);
790     }
791 
792     pp = (UINT8 *)(p + 1);
793 
794     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
795     p->offset = 0;
796 
797     UINT16_TO_STREAM (pp, HCI_EXIT_SNIFF_MODE);
798     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_CMD_HANDLE);
799 
800     UINT16_TO_STREAM (pp, handle);
801 
802     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
803     HCI_TRACE_WARNING("hci cmd send: unsniff: hdl 0x%x", handle);
804     return TRUE;
805 }
806 
btsnd_hcic_park_mode(UINT16 handle,UINT16 beacon_max_interval,UINT16 beacon_min_interval)807 BOOLEAN btsnd_hcic_park_mode (UINT16 handle, UINT16 beacon_max_interval,
808                               UINT16 beacon_min_interval)
809 {
810     BT_HDR *p;
811     UINT8 *pp;
812 
813     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_PARK_MODE)) == NULL) {
814         return (FALSE);
815     }
816 
817     pp = (UINT8 *)(p + 1);
818 
819     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_PARK_MODE;
820     p->offset = 0;
821 
822     UINT16_TO_STREAM (pp, HCI_PARK_MODE);
823     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_PARK_MODE);
824 
825     UINT16_TO_STREAM (pp, handle);
826     UINT16_TO_STREAM (pp, beacon_max_interval);
827     UINT16_TO_STREAM (pp, beacon_min_interval);
828 
829     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
830     return (TRUE);
831 }
832 
btsnd_hcic_exit_park_mode(UINT16 handle)833 BOOLEAN btsnd_hcic_exit_park_mode (UINT16 handle)
834 {
835     BT_HDR *p;
836     UINT8 *pp;
837 
838     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_CMD_HANDLE)) == NULL) {
839         return (FALSE);
840     }
841 
842     pp = (UINT8 *)(p + 1);
843 
844     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
845     p->offset = 0;
846 
847     UINT16_TO_STREAM (pp, HCI_EXIT_PARK_MODE);
848     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_CMD_HANDLE);
849 
850     UINT16_TO_STREAM (pp, handle);
851 
852     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
853     return TRUE;
854 }
855 
btsnd_hcic_qos_setup(UINT16 handle,UINT8 flags,UINT8 service_type,UINT32 token_rate,UINT32 peak,UINT32 latency,UINT32 delay_var)856 BOOLEAN btsnd_hcic_qos_setup (UINT16 handle, UINT8 flags, UINT8 service_type,
857                               UINT32 token_rate, UINT32 peak, UINT32 latency,
858                               UINT32 delay_var)
859 {
860     BT_HDR *p;
861     UINT8 *pp;
862 
863     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_QOS_SETUP)) == NULL) {
864         return (FALSE);
865     }
866 
867     pp = (UINT8 *)(p + 1);
868 
869     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_QOS_SETUP;
870     p->offset = 0;
871 
872     UINT16_TO_STREAM (pp, HCI_QOS_SETUP);
873     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_QOS_SETUP);
874 
875     UINT16_TO_STREAM (pp, handle);
876     UINT8_TO_STREAM  (pp, flags);
877     UINT8_TO_STREAM  (pp, service_type);
878     UINT32_TO_STREAM (pp, token_rate);
879     UINT32_TO_STREAM (pp, peak);
880     UINT32_TO_STREAM (pp, latency);
881     UINT32_TO_STREAM (pp, delay_var);
882 
883     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
884     return (TRUE);
885 }
886 
btsnd_hcic_switch_role(BD_ADDR bd_addr,UINT8 role)887 BOOLEAN btsnd_hcic_switch_role (BD_ADDR bd_addr, UINT8 role)
888 {
889     BT_HDR *p;
890     UINT8 *pp;
891 
892     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_SWITCH_ROLE)) == NULL) {
893         return (FALSE);
894     }
895 
896     pp = (UINT8 *)(p + 1);
897 
898     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SWITCH_ROLE;
899     p->offset = 0;
900 
901     UINT16_TO_STREAM (pp, HCI_SWITCH_ROLE);
902     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_SWITCH_ROLE);
903 
904     BDADDR_TO_STREAM (pp, bd_addr);
905     UINT8_TO_STREAM  (pp, role);
906 
907     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
908     return (TRUE);
909 }
910 
btsnd_hcic_write_policy_set(UINT16 handle,UINT16 settings)911 BOOLEAN btsnd_hcic_write_policy_set (UINT16 handle, UINT16 settings)
912 {
913     BT_HDR *p;
914     UINT8 *pp;
915 
916     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_POLICY_SET)) == NULL) {
917         return (FALSE);
918     }
919 
920     pp = (UINT8 *)(p + 1);
921 
922     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_POLICY_SET;
923     p->offset = 0;
924     UINT16_TO_STREAM (pp, HCI_WRITE_POLICY_SETTINGS);
925     UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_POLICY_SET);
926 
927     UINT16_TO_STREAM (pp, handle);
928     UINT16_TO_STREAM (pp, settings);
929 
930     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
931     return (TRUE);
932 }
933 
btsnd_hcic_write_def_policy_set(UINT16 settings)934 BOOLEAN btsnd_hcic_write_def_policy_set (UINT16 settings)
935 {
936     BT_HDR *p;
937     UINT8 *pp;
938 
939     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_DEF_POLICY_SET)) == NULL) {
940         return (FALSE);
941     }
942 
943     pp = (UINT8 *)(p + 1);
944 
945     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_DEF_POLICY_SET;
946     p->offset = 0;
947     UINT16_TO_STREAM (pp, HCI_WRITE_DEF_POLICY_SETTINGS);
948     UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_DEF_POLICY_SET);
949 
950     UINT16_TO_STREAM (pp, settings);
951 
952     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
953     return (TRUE);
954 }
955 
btsnd_hcic_set_event_filter(UINT8 filt_type,UINT8 filt_cond_type,UINT8 * filt_cond,UINT8 filt_cond_len)956 BOOLEAN btsnd_hcic_set_event_filter (UINT8 filt_type, UINT8 filt_cond_type,
957                                      UINT8 *filt_cond, UINT8 filt_cond_len)
958 {
959     BT_HDR *p;
960     UINT8 *pp;
961 
962     /* Use buffer large enough to hold all sizes in this command */
963     if ((p = HCI_GET_CMD_BUF(2 + filt_cond_len)) == NULL) {
964         return (FALSE);
965     }
966 
967     pp = (UINT8 *)(p + 1);
968 
969     p->offset = 0;
970 
971     UINT16_TO_STREAM (pp, HCI_SET_EVENT_FILTER);
972 
973     if (filt_type) {
974         p->len = (UINT16)(HCIC_PREAMBLE_SIZE + 2 + filt_cond_len);
975         UINT8_TO_STREAM (pp, (UINT8)(2 + filt_cond_len));
976 
977         UINT8_TO_STREAM (pp, filt_type);
978         UINT8_TO_STREAM (pp, filt_cond_type);
979 
980         if (filt_cond_type == HCI_FILTER_COND_DEVICE_CLASS) {
981             DEVCLASS_TO_STREAM (pp, filt_cond);
982             filt_cond += DEV_CLASS_LEN;
983             DEVCLASS_TO_STREAM (pp, filt_cond);
984             filt_cond += DEV_CLASS_LEN;
985 
986             filt_cond_len -= (2 * DEV_CLASS_LEN);
987         } else if (filt_cond_type == HCI_FILTER_COND_BD_ADDR) {
988             BDADDR_TO_STREAM (pp, filt_cond);
989             filt_cond += BD_ADDR_LEN;
990 
991             filt_cond_len -= BD_ADDR_LEN;
992         }
993 
994         if (filt_cond_len) {
995             ARRAY_TO_STREAM (pp, filt_cond, filt_cond_len);
996         }
997     } else {
998         p->len = (UINT16)(HCIC_PREAMBLE_SIZE + 1);
999         UINT8_TO_STREAM (pp, 1);
1000 
1001         UINT8_TO_STREAM (pp, filt_type);
1002     }
1003 
1004     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1005     return (TRUE);
1006 }
1007 
btsnd_hcic_write_pin_type(UINT8 type)1008 BOOLEAN btsnd_hcic_write_pin_type (UINT8 type)
1009 {
1010     BT_HDR *p;
1011     UINT8 *pp;
1012 
1013     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1)) == NULL) {
1014         return (FALSE);
1015     }
1016 
1017     pp = (UINT8 *)(p + 1);
1018 
1019     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1;
1020     p->offset = 0;
1021 
1022     UINT16_TO_STREAM (pp, HCI_WRITE_PIN_TYPE);
1023     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_PARAM1);
1024 
1025     UINT8_TO_STREAM (pp, type);
1026 
1027     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1028     return (TRUE);
1029 }
1030 
btsnd_hcic_delete_stored_key(BD_ADDR bd_addr,BOOLEAN delete_all_flag)1031 BOOLEAN btsnd_hcic_delete_stored_key (BD_ADDR bd_addr, BOOLEAN delete_all_flag)
1032 {
1033     BT_HDR *p;
1034     UINT8 *pp;
1035 
1036     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_DELETE_STORED_KEY)) == NULL) {
1037         return (FALSE);
1038     }
1039 
1040     pp = (UINT8 *)(p + 1);
1041 
1042     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_DELETE_STORED_KEY;
1043     p->offset = 0;
1044 
1045     UINT16_TO_STREAM (pp, HCI_DELETE_STORED_LINK_KEY);
1046     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_DELETE_STORED_KEY);
1047 
1048     BDADDR_TO_STREAM (pp, bd_addr);
1049     UINT8_TO_STREAM  (pp, delete_all_flag);
1050 
1051     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1052     return (TRUE);
1053 }
1054 
btsnd_hcic_change_name(const UINT8 * name)1055 BOOLEAN btsnd_hcic_change_name (const UINT8 *name)
1056 {
1057     BT_HDR *p;
1058     UINT8 *pp;
1059     UINT16 len = strlen ((char *)name) + 1;
1060 
1061     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_CHANGE_NAME)) == NULL) {
1062         return (FALSE);
1063     }
1064 
1065     pp = (UINT8 *)(p + 1);
1066     memset(pp, 0, HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CHANGE_NAME);
1067 
1068     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CHANGE_NAME;
1069     p->offset = 0;
1070 
1071     UINT16_TO_STREAM (pp, HCI_CHANGE_LOCAL_NAME);
1072     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_CHANGE_NAME);
1073 
1074     if (len > HCIC_PARAM_SIZE_CHANGE_NAME) {
1075         len = HCIC_PARAM_SIZE_CHANGE_NAME;
1076     }
1077 
1078     ARRAY_TO_STREAM (pp, name, len);
1079 
1080     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1081     return (TRUE);
1082 }
1083 
btsnd_hcic_read_name(void)1084 BOOLEAN btsnd_hcic_read_name (void)
1085 {
1086     BT_HDR *p;
1087     UINT8 *pp;
1088 
1089     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CMD)) == NULL) {
1090         return (FALSE);
1091     }
1092 
1093     pp = (UINT8 *)(p + 1);
1094 
1095     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
1096     p->offset = 0;
1097 
1098     UINT16_TO_STREAM (pp, HCI_READ_LOCAL_NAME);
1099     UINT8_TO_STREAM  (pp,  HCIC_PARAM_SIZE_READ_CMD);
1100 
1101     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1102     return (TRUE);
1103 }
1104 
btsnd_hcic_write_page_tout(UINT16 timeout)1105 BOOLEAN btsnd_hcic_write_page_tout (UINT16 timeout)
1106 {
1107     BT_HDR *p;
1108     UINT8 *pp;
1109 
1110     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM2)) == NULL) {
1111         return (FALSE);
1112     }
1113 
1114     pp = (UINT8 *)(p + 1);
1115 
1116     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM2;
1117     p->offset = 0;
1118 
1119     UINT16_TO_STREAM (pp, HCI_WRITE_PAGE_TOUT);
1120     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_PARAM2);
1121 
1122     UINT16_TO_STREAM  (pp, timeout);
1123 
1124     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1125     return (TRUE);
1126 }
1127 
btsnd_hcic_write_scan_enable(UINT8 flag)1128 BOOLEAN btsnd_hcic_write_scan_enable (UINT8 flag)
1129 {
1130     BT_HDR *p;
1131     UINT8 *pp;
1132 
1133     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1)) == NULL) {
1134         return (FALSE);
1135     }
1136 
1137     pp = (UINT8 *)(p + 1);
1138 
1139     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1;
1140     p->offset = 0;
1141 
1142     UINT16_TO_STREAM (pp, HCI_WRITE_SCAN_ENABLE);
1143     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_PARAM1);
1144 
1145     UINT8_TO_STREAM  (pp, flag);
1146 
1147     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1148     return (TRUE);
1149 }
1150 
btsnd_hcic_write_pagescan_cfg(UINT16 interval,UINT16 window)1151 BOOLEAN btsnd_hcic_write_pagescan_cfg(UINT16 interval, UINT16 window)
1152 {
1153     BT_HDR *p;
1154     UINT8 *pp;
1155 
1156     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PAGESCAN_CFG)) == NULL) {
1157         return (FALSE);
1158     }
1159 
1160     pp = (UINT8 *)(p + 1);
1161 
1162     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PAGESCAN_CFG;
1163     p->offset = 0;
1164 
1165     UINT16_TO_STREAM (pp, HCI_WRITE_PAGESCAN_CFG);
1166     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_PAGESCAN_CFG);
1167 
1168     UINT16_TO_STREAM (pp, interval);
1169     UINT16_TO_STREAM (pp, window);
1170 
1171     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1172     return (TRUE);
1173 }
1174 
btsnd_hcic_write_inqscan_cfg(UINT16 interval,UINT16 window)1175 BOOLEAN btsnd_hcic_write_inqscan_cfg(UINT16 interval, UINT16 window)
1176 {
1177     BT_HDR *p;
1178     UINT8 *pp;
1179 
1180     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_INQSCAN_CFG)) == NULL) {
1181         return (FALSE);
1182     }
1183 
1184     pp = (UINT8 *)(p + 1);
1185 
1186     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_INQSCAN_CFG;
1187     p->offset = 0;
1188 
1189     UINT16_TO_STREAM (pp, HCI_WRITE_INQUIRYSCAN_CFG);
1190     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_INQSCAN_CFG);
1191 
1192     UINT16_TO_STREAM (pp, interval);
1193     UINT16_TO_STREAM (pp, window);
1194 
1195     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1196     return (TRUE);
1197 }
1198 
btsnd_hcic_write_auth_enable(UINT8 flag)1199 BOOLEAN btsnd_hcic_write_auth_enable (UINT8 flag)
1200 {
1201     BT_HDR *p;
1202     UINT8 *pp;
1203 
1204     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1)) == NULL) {
1205         return (FALSE);
1206     }
1207 
1208     pp = (UINT8 *)(p + 1);
1209 
1210     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1;
1211     p->offset = 0;
1212 
1213     UINT16_TO_STREAM (pp, HCI_WRITE_AUTHENTICATION_ENABLE);
1214     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_PARAM1);
1215 
1216     UINT8_TO_STREAM (pp, flag);
1217 
1218     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1219     return (TRUE);
1220 }
1221 
btsnd_hcic_write_dev_class(DEV_CLASS dev_class)1222 BOOLEAN btsnd_hcic_write_dev_class(DEV_CLASS dev_class)
1223 {
1224     BT_HDR *p;
1225     UINT8 *pp;
1226 
1227     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM3)) == NULL) {
1228         return (FALSE);
1229     }
1230 
1231     pp = (UINT8 *)(p + 1);
1232 
1233     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM3;
1234     p->offset = 0;
1235 
1236     UINT16_TO_STREAM (pp, HCI_WRITE_CLASS_OF_DEVICE);
1237     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_PARAM3);
1238 
1239     DEVCLASS_TO_STREAM (pp, dev_class);
1240 
1241     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1242     return (TRUE);
1243 }
1244 
btsnd_hcic_write_voice_settings(UINT16 flags)1245 BOOLEAN btsnd_hcic_write_voice_settings(UINT16 flags)
1246 {
1247     BT_HDR *p;
1248     UINT8 *pp;
1249 
1250     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM2)) == NULL) {
1251         return (FALSE);
1252     }
1253 
1254     pp = (UINT8 *)(p + 1);
1255 
1256     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM2;
1257     p->offset = 0;
1258 
1259     UINT16_TO_STREAM (pp, HCI_WRITE_VOICE_SETTINGS);
1260     UINT8_TO_STREAM (pp, HCIC_PARAM_SIZE_WRITE_PARAM2);
1261 
1262     UINT16_TO_STREAM (pp, flags);
1263 
1264     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1265     return (TRUE);
1266 }
1267 
btsnd_hcic_write_auto_flush_tout(UINT16 handle,UINT16 tout)1268 BOOLEAN btsnd_hcic_write_auto_flush_tout (UINT16 handle, UINT16 tout)
1269 {
1270     BT_HDR *p;
1271     UINT8 *pp;
1272 
1273     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_AUTO_FLUSH_TOUT)) == NULL) {
1274         return (FALSE);
1275     }
1276 
1277     pp = (UINT8 *)(p + 1);
1278 
1279     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_AUTO_FLUSH_TOUT;
1280     p->offset = 0;
1281 
1282     UINT16_TO_STREAM (pp, HCI_WRITE_AUTO_FLUSH_TOUT);
1283     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_AUTO_FLUSH_TOUT);
1284 
1285     UINT16_TO_STREAM (pp, handle);
1286     UINT16_TO_STREAM (pp, tout);
1287 
1288     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1289     return (TRUE);
1290 }
1291 
btsnd_hcic_read_tx_power(UINT16 handle,UINT8 type)1292 BOOLEAN btsnd_hcic_read_tx_power (UINT16 handle, UINT8 type)
1293 {
1294     BT_HDR *p;
1295     UINT8 *pp;
1296 
1297     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_TX_POWER)) == NULL) {
1298         return (FALSE);
1299     }
1300 
1301     pp = (UINT8 *)(p + 1);
1302 
1303     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_TX_POWER;
1304     p->offset = 0;
1305 
1306     UINT16_TO_STREAM (pp, HCI_READ_TRANSMIT_POWER_LEVEL);
1307     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_READ_TX_POWER);
1308 
1309     UINT16_TO_STREAM (pp, handle);
1310     UINT8_TO_STREAM  (pp, type);
1311 
1312     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1313     return (TRUE);
1314 }
1315 
btsnd_hcic_host_num_xmitted_pkts(UINT8 num_handles,UINT16 * handle,UINT16 * num_pkts)1316 BOOLEAN btsnd_hcic_host_num_xmitted_pkts (UINT8 num_handles, UINT16 *handle,
1317         UINT16 *num_pkts)
1318 {
1319     BT_HDR *p;
1320     UINT8 *pp;
1321     int j;
1322 
1323     if ((p = HCI_GET_CMD_BUF(1 + (num_handles * 4))) == NULL) {
1324         return (FALSE);
1325     }
1326 
1327     pp = (UINT8 *)(p + 1);
1328 
1329     p->len    = HCIC_PREAMBLE_SIZE + 1 + (num_handles * 4);
1330     p->offset = 0;
1331 
1332     hci_cmd_metadata_t *metadata = HCI_GET_CMD_METAMSG(p);
1333     metadata->flags_src |= HCI_CMD_MSG_F_SRC_NOACK;
1334 
1335     UINT16_TO_STREAM (pp, HCI_HOST_NUM_PACKETS_DONE);
1336     UINT8_TO_STREAM  (pp, p->len - HCIC_PREAMBLE_SIZE);
1337 
1338     UINT8_TO_STREAM (pp, num_handles);
1339 
1340     for (j = 0; j < num_handles; j++) {
1341         UINT16_TO_STREAM (pp, handle[j]);
1342         UINT16_TO_STREAM (pp, num_pkts[j]);
1343     }
1344 
1345     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1346     return (TRUE);
1347 }
1348 
btsnd_hcic_write_link_super_tout(UINT8 local_controller_id,UINT16 handle,UINT16 timeout)1349 BOOLEAN btsnd_hcic_write_link_super_tout (UINT8 local_controller_id, UINT16 handle, UINT16 timeout)
1350 {
1351     BT_HDR *p;
1352     UINT8 *pp;
1353 
1354     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_LINK_SUPER_TOUT)) == NULL) {
1355         return (FALSE);
1356     }
1357 
1358     pp = (UINT8 *)(p + 1);
1359 
1360     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_LINK_SUPER_TOUT;
1361     p->offset = 0;
1362 
1363     UINT16_TO_STREAM (pp, HCI_WRITE_LINK_SUPER_TOUT);
1364     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_LINK_SUPER_TOUT);
1365 
1366     UINT16_TO_STREAM (pp, handle);
1367     UINT16_TO_STREAM (pp, timeout);
1368 
1369     btu_hcif_send_cmd (local_controller_id,  p);
1370     return (TRUE);
1371 }
1372 
btsnd_hcic_write_cur_iac_lap(UINT8 num_cur_iac,LAP * const iac_lap)1373 BOOLEAN btsnd_hcic_write_cur_iac_lap (UINT8 num_cur_iac, LAP *const iac_lap)
1374 {
1375     BT_HDR *p;
1376     UINT8 *pp;
1377     int i;
1378 
1379     if ((p = HCI_GET_CMD_BUF(1 + (LAP_LEN * num_cur_iac))) == NULL) {
1380         return (FALSE);
1381     }
1382 
1383     pp = (UINT8 *)(p + 1);
1384 
1385     p->len    = HCIC_PREAMBLE_SIZE + 1 + (LAP_LEN * num_cur_iac);
1386     p->offset = 0;
1387 
1388     UINT16_TO_STREAM (pp, HCI_WRITE_CURRENT_IAC_LAP);
1389     UINT8_TO_STREAM  (pp, p->len - HCIC_PREAMBLE_SIZE);
1390 
1391     UINT8_TO_STREAM (pp, num_cur_iac);
1392 
1393     for (i = 0; i < num_cur_iac; i++) {
1394         LAP_TO_STREAM (pp, iac_lap[i]);
1395     }
1396 
1397     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1398     return (TRUE);
1399 }
1400 
1401 /******************************************
1402 **    Lisbon Features
1403 *******************************************/
1404 #if BTM_SSR_INCLUDED == TRUE
1405 
btsnd_hcic_sniff_sub_rate(UINT16 handle,UINT16 max_lat,UINT16 min_remote_lat,UINT16 min_local_lat)1406 BOOLEAN btsnd_hcic_sniff_sub_rate(UINT16 handle, UINT16 max_lat,
1407                                   UINT16 min_remote_lat, UINT16 min_local_lat)
1408 {
1409     BT_HDR *p;
1410     UINT8 *pp;
1411 
1412     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_SNIFF_SUB_RATE)) == NULL) {
1413         return (FALSE);
1414     }
1415 
1416     pp = (UINT8 *)(p + 1);
1417 
1418     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SNIFF_SUB_RATE;
1419     p->offset = 0;
1420 
1421     UINT16_TO_STREAM (pp, HCI_SNIFF_SUB_RATE);
1422     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_SNIFF_SUB_RATE);
1423 
1424     UINT16_TO_STREAM  (pp, handle);
1425     UINT16_TO_STREAM  (pp, max_lat);
1426     UINT16_TO_STREAM  (pp, min_remote_lat);
1427     UINT16_TO_STREAM  (pp, min_local_lat);
1428 
1429     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1430     return (TRUE);
1431 }
1432 #endif /* BTM_SSR_INCLUDED */
1433 
1434 /**** Extended Inquiry Response Commands ****/
btsnd_hcic_write_ext_inquiry_response(BT_HDR * buffer,UINT8 fec_req)1435 void btsnd_hcic_write_ext_inquiry_response (BT_HDR *buffer, UINT8 fec_req)
1436 {
1437     BT_HDR *p;
1438     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_EXT_INQ_RESP)) == NULL) {
1439         return;
1440     }
1441 
1442     UINT8 *pp = (UINT8 *)(p + 1);
1443 
1444     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_EXT_INQ_RESP;
1445     p->offset = 0;
1446 
1447     UINT16_TO_STREAM (pp, HCI_WRITE_EXT_INQ_RESPONSE);
1448     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_EXT_INQ_RESP);
1449     UINT8_TO_STREAM (pp, fec_req);
1450 
1451     memcpy(pp, buffer->data + 4, p->len - 4);
1452 
1453     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1454 }
1455 
btsnd_hcic_io_cap_req_reply(BD_ADDR bd_addr,UINT8 capability,UINT8 oob_present,UINT8 auth_req)1456 BOOLEAN btsnd_hcic_io_cap_req_reply (BD_ADDR bd_addr, UINT8 capability,
1457                                      UINT8 oob_present, UINT8 auth_req)
1458 {
1459     BT_HDR *p;
1460     UINT8 *pp;
1461 
1462     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_IO_CAP_RESP)) == NULL) {
1463         return (FALSE);
1464     }
1465 
1466     pp = (UINT8 *)(p + 1);
1467 
1468     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_IO_CAP_RESP;
1469     p->offset = 0;
1470 
1471     UINT16_TO_STREAM (pp, HCI_IO_CAPABILITY_REQUEST_REPLY);
1472     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_IO_CAP_RESP);
1473 
1474     BDADDR_TO_STREAM (pp, bd_addr);
1475     UINT8_TO_STREAM  (pp, capability);
1476     UINT8_TO_STREAM  (pp, oob_present);
1477     UINT8_TO_STREAM  (pp, auth_req);
1478 
1479     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1480     return (TRUE);
1481 }
1482 
btsnd_hcic_io_cap_req_neg_reply(BD_ADDR bd_addr,UINT8 err_code)1483 BOOLEAN btsnd_hcic_io_cap_req_neg_reply (BD_ADDR bd_addr, UINT8 err_code)
1484 {
1485     BT_HDR *p;
1486     UINT8 *pp;
1487 
1488     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_IO_CAP_NEG_REPLY)) == NULL) {
1489         return (FALSE);
1490     }
1491 
1492     pp = (UINT8 *)(p + 1);
1493 
1494     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_IO_CAP_NEG_REPLY;
1495     p->offset = 0;
1496 
1497     UINT16_TO_STREAM (pp, HCI_IO_CAP_REQ_NEG_REPLY);
1498     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_IO_CAP_NEG_REPLY);
1499 
1500     BDADDR_TO_STREAM (pp, bd_addr);
1501     UINT8_TO_STREAM  (pp, err_code);
1502 
1503     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1504     return (TRUE);
1505 }
1506 
btsnd_hcic_read_local_oob_data(void)1507 BOOLEAN btsnd_hcic_read_local_oob_data (void)
1508 {
1509     BT_HDR *p;
1510     UINT8 *pp;
1511 
1512     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_R_LOCAL_OOB)) == NULL) {
1513         return (FALSE);
1514     }
1515 
1516     pp = (UINT8 *)(p + 1);
1517 
1518     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_R_LOCAL_OOB;
1519     p->offset = 0;
1520 
1521     UINT16_TO_STREAM (pp, HCI_READ_LOCAL_OOB_DATA);
1522     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_R_LOCAL_OOB);
1523 
1524     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1525     return (TRUE);
1526 }
1527 
btsnd_hcic_user_conf_reply(BD_ADDR bd_addr,BOOLEAN is_yes)1528 BOOLEAN btsnd_hcic_user_conf_reply (BD_ADDR bd_addr, BOOLEAN is_yes)
1529 {
1530     BT_HDR *p;
1531     UINT8 *pp;
1532 
1533     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_UCONF_REPLY)) == NULL) {
1534         return (FALSE);
1535     }
1536 
1537     pp = (UINT8 *)(p + 1);
1538 
1539     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_UCONF_REPLY;
1540     p->offset = 0;
1541 
1542     if (!is_yes) {
1543         /* Negative reply */
1544         UINT16_TO_STREAM (pp, HCI_USER_CONF_VALUE_NEG_REPLY);
1545     } else {
1546         /* Confirmation */
1547         UINT16_TO_STREAM (pp, HCI_USER_CONF_REQUEST_REPLY);
1548     }
1549 
1550     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_UCONF_REPLY);
1551 
1552     BDADDR_TO_STREAM (pp, bd_addr);
1553 
1554     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1555     return (TRUE);
1556 }
1557 
btsnd_hcic_user_passkey_reply(BD_ADDR bd_addr,UINT32 value)1558 BOOLEAN btsnd_hcic_user_passkey_reply (BD_ADDR bd_addr, UINT32 value)
1559 {
1560     BT_HDR *p;
1561     UINT8 *pp;
1562 
1563     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_U_PKEY_REPLY)) == NULL) {
1564         return (FALSE);
1565     }
1566 
1567     pp = (UINT8 *)(p + 1);
1568 
1569     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_U_PKEY_REPLY;
1570     p->offset = 0;
1571 
1572     UINT16_TO_STREAM (pp, HCI_USER_PASSKEY_REQ_REPLY);
1573     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_U_PKEY_REPLY);
1574 
1575     BDADDR_TO_STREAM (pp, bd_addr);
1576     UINT32_TO_STREAM (pp, value);
1577 
1578     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1579     return (TRUE);
1580 }
1581 
btsnd_hcic_user_passkey_neg_reply(BD_ADDR bd_addr)1582 BOOLEAN btsnd_hcic_user_passkey_neg_reply (BD_ADDR bd_addr)
1583 {
1584     BT_HDR *p;
1585     UINT8 *pp;
1586 
1587     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_U_PKEY_NEG_REPLY)) == NULL) {
1588         return (FALSE);
1589     }
1590 
1591     pp = (UINT8 *)(p + 1);
1592 
1593     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_U_PKEY_NEG_REPLY;
1594     p->offset = 0;
1595 
1596     UINT16_TO_STREAM (pp, HCI_USER_PASSKEY_REQ_NEG_REPLY);
1597     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_U_PKEY_NEG_REPLY);
1598 
1599     BDADDR_TO_STREAM (pp, bd_addr);
1600 
1601     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1602     return (TRUE);
1603 }
1604 
btsnd_hcic_rem_oob_reply(BD_ADDR bd_addr,UINT8 * p_c,UINT8 * p_r)1605 BOOLEAN btsnd_hcic_rem_oob_reply (BD_ADDR bd_addr, UINT8 *p_c, UINT8 *p_r)
1606 {
1607     BT_HDR *p;
1608     UINT8 *pp;
1609 
1610     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_REM_OOB_REPLY)) == NULL) {
1611         return (FALSE);
1612     }
1613 
1614     pp = (UINT8 *)(p + 1);
1615 
1616     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REM_OOB_REPLY;
1617     p->offset = 0;
1618 
1619     UINT16_TO_STREAM (pp, HCI_REM_OOB_DATA_REQ_REPLY);
1620     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_REM_OOB_REPLY);
1621 
1622     BDADDR_TO_STREAM (pp, bd_addr);
1623     ARRAY16_TO_STREAM (pp, p_c);
1624     ARRAY16_TO_STREAM (pp, p_r);
1625 
1626     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1627     return (TRUE);
1628 }
1629 
btsnd_hcic_rem_oob_neg_reply(BD_ADDR bd_addr)1630 BOOLEAN btsnd_hcic_rem_oob_neg_reply (BD_ADDR bd_addr)
1631 {
1632     BT_HDR *p;
1633     UINT8 *pp;
1634 
1635     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_REM_OOB_NEG_REPLY)) == NULL) {
1636         return (FALSE);
1637     }
1638 
1639     pp = (UINT8 *)(p + 1);
1640 
1641     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_REM_OOB_NEG_REPLY;
1642     p->offset = 0;
1643 
1644     UINT16_TO_STREAM (pp, HCI_REM_OOB_DATA_REQ_NEG_REPLY);
1645     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_REM_OOB_NEG_REPLY);
1646 
1647     BDADDR_TO_STREAM (pp, bd_addr);
1648 
1649     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1650     return (TRUE);
1651 }
1652 
1653 
btsnd_hcic_read_inq_tx_power(void)1654 BOOLEAN btsnd_hcic_read_inq_tx_power (void)
1655 {
1656     BT_HDR *p;
1657     UINT8 *pp;
1658 
1659     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_R_TX_POWER)) == NULL) {
1660         return (FALSE);
1661     }
1662 
1663     pp = (UINT8 *)(p + 1);
1664 
1665     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_R_TX_POWER;
1666     p->offset = 0;
1667 
1668     UINT16_TO_STREAM (pp, HCI_READ_INQ_TX_POWER_LEVEL);
1669     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_R_TX_POWER);
1670 
1671     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1672     return (TRUE);
1673 }
1674 
btsnd_hcic_send_keypress_notif(BD_ADDR bd_addr,UINT8 notif)1675 BOOLEAN btsnd_hcic_send_keypress_notif (BD_ADDR bd_addr, UINT8 notif)
1676 {
1677     BT_HDR *p;
1678     UINT8 *pp;
1679 
1680     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_SEND_KEYPRESS_NOTIF)) == NULL) {
1681         return (FALSE);
1682     }
1683 
1684     pp = (UINT8 *)(p + 1);
1685 
1686     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SEND_KEYPRESS_NOTIF;
1687     p->offset = 0;
1688 
1689     UINT16_TO_STREAM (pp, HCI_SEND_KEYPRESS_NOTIF);
1690     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_SEND_KEYPRESS_NOTIF);
1691 
1692     BDADDR_TO_STREAM (pp, bd_addr);
1693     UINT8_TO_STREAM (pp, notif);
1694 
1695     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1696     return (TRUE);
1697 }
1698 
1699 /**** end of Simple Pairing Commands ****/
1700 
1701 #if L2CAP_NON_FLUSHABLE_PB_INCLUDED == TRUE
btsnd_hcic_enhanced_flush(UINT16 handle,UINT8 packet_type)1702 BOOLEAN btsnd_hcic_enhanced_flush (UINT16 handle, UINT8 packet_type)
1703 {
1704     BT_HDR *p;
1705     UINT8 *pp;
1706 
1707     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_ENHANCED_FLUSH)) == NULL) {
1708         return (FALSE);
1709     }
1710 
1711     pp = (UINT8 *)(p + 1);
1712 
1713     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_ENHANCED_FLUSH;
1714     p->offset = 0;
1715     UINT16_TO_STREAM (pp, HCI_ENHANCED_FLUSH);
1716     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_ENHANCED_FLUSH);
1717 
1718     UINT16_TO_STREAM (pp, handle);
1719     UINT8_TO_STREAM  (pp, packet_type);
1720 
1721     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1722     return (TRUE);
1723 }
1724 #endif
1725 
1726 /*************************
1727 ** End of Lisbon Commands
1728 **************************/
1729 
btsnd_hcic_get_link_quality(UINT16 handle)1730 BOOLEAN btsnd_hcic_get_link_quality (UINT16 handle)
1731 {
1732     BT_HDR *p;
1733     UINT8 *pp;
1734 
1735     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_CMD_HANDLE)) == NULL) {
1736         return (FALSE);
1737     }
1738 
1739     pp = (UINT8 *)(p + 1);
1740 
1741     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
1742     p->offset = 0;
1743 
1744     UINT16_TO_STREAM (pp, HCI_GET_LINK_QUALITY);
1745     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_CMD_HANDLE);
1746 
1747     UINT16_TO_STREAM (pp, handle);
1748 
1749     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1750     return (TRUE);
1751 }
1752 
btsnd_hcic_read_rssi(UINT16 handle)1753 BOOLEAN btsnd_hcic_read_rssi (UINT16 handle)
1754 {
1755     BT_HDR *p;
1756     UINT8 *pp;
1757 
1758     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_CMD_HANDLE)) == NULL) {
1759         return (FALSE);
1760     }
1761 
1762     pp = (UINT8 *)(p + 1);
1763 
1764     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_CMD_HANDLE;
1765     p->offset = 0;
1766 
1767     UINT16_TO_STREAM (pp, HCI_READ_RSSI);
1768     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_CMD_HANDLE);
1769 
1770     UINT16_TO_STREAM (pp, handle);
1771 
1772     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1773     return (TRUE);
1774 }
1775 
btsnd_hcic_enable_test_mode(void)1776 BOOLEAN btsnd_hcic_enable_test_mode (void)
1777 {
1778     BT_HDR *p;
1779     UINT8 *pp;
1780 
1781     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_READ_CMD)) == NULL) {
1782         return (FALSE);
1783     }
1784 
1785     pp = (UINT8 *)(p + 1);
1786 
1787     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_READ_CMD;
1788     p->offset = 0;
1789 
1790     UINT16_TO_STREAM (pp, HCI_ENABLE_DEV_UNDER_TEST_MODE);
1791     UINT8_TO_STREAM  (pp,  HCIC_PARAM_SIZE_READ_CMD);
1792 
1793     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1794     return (TRUE);
1795 }
1796 
btsnd_hcic_write_inqscan_type(UINT8 type)1797 BOOLEAN btsnd_hcic_write_inqscan_type (UINT8 type)
1798 {
1799     BT_HDR *p;
1800     UINT8 *pp;
1801 
1802     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1)) == NULL) {
1803         return (FALSE);
1804     }
1805 
1806     pp = (UINT8 *)(p + 1);
1807 
1808     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1;
1809     p->offset = 0;
1810 
1811     UINT16_TO_STREAM (pp, HCI_WRITE_INQSCAN_TYPE);
1812     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_PARAM1);
1813 
1814     UINT8_TO_STREAM  (pp, type);
1815 
1816     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1817     return (TRUE);
1818 }
1819 
btsnd_hcic_write_inquiry_mode(UINT8 mode)1820 BOOLEAN btsnd_hcic_write_inquiry_mode (UINT8 mode)
1821 {
1822     BT_HDR *p;
1823     UINT8 *pp;
1824 
1825     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1)) == NULL) {
1826         return (FALSE);
1827     }
1828 
1829     pp = (UINT8 *)(p + 1);
1830 
1831     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1;
1832     p->offset = 0;
1833 
1834     UINT16_TO_STREAM (pp, HCI_WRITE_INQUIRY_MODE);
1835     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_PARAM1);
1836 
1837     UINT8_TO_STREAM  (pp, mode);
1838 
1839     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1840     return (TRUE);
1841 }
1842 
btsnd_hcic_write_pagescan_type(UINT8 type)1843 BOOLEAN btsnd_hcic_write_pagescan_type (UINT8 type)
1844 {
1845     BT_HDR *p;
1846     UINT8 *pp;
1847 
1848     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_WRITE_PARAM1)) == NULL) {
1849         return (FALSE);
1850     }
1851 
1852     pp = (UINT8 *)(p + 1);
1853 
1854     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_WRITE_PARAM1;
1855     p->offset = 0;
1856 
1857     UINT16_TO_STREAM (pp, HCI_WRITE_PAGESCAN_TYPE);
1858     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_WRITE_PARAM1);
1859 
1860     UINT8_TO_STREAM  (pp, type);
1861 
1862     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1863     return (TRUE);
1864 }
1865 
1866 /* Must have room to store BT_HDR + max VSC length + callback pointer */
1867 #if (HCI_CMD_BUF_SIZE < 268)
1868 #error "HCI_CMD_POOL_BUF_SIZE must be larger than 268"
1869 #endif
1870 
btsnd_hcic_vendor_spec_cmd(BT_HDR * buffer,UINT16 opcode,UINT8 len,UINT8 * p_data,void * p_cmd_cplt_cback)1871 void btsnd_hcic_vendor_spec_cmd (BT_HDR *buffer, UINT16 opcode, UINT8 len,
1872                                  UINT8 *p_data, void *p_cmd_cplt_cback)
1873 {
1874     BT_HDR *p = buffer;
1875     UINT8 *pp = (UINT8 *)(p + 1);
1876 
1877     p->len    = HCIC_PREAMBLE_SIZE + len;
1878     p->offset = 0;
1879 
1880     hci_cmd_metadata_t * metadata = HCI_GET_CMD_METAMSG(p);
1881     metadata->context = p_cmd_cplt_cback;
1882 
1883     UINT16_TO_STREAM (pp, HCI_GRP_VENDOR_SPECIFIC | opcode);
1884     UINT8_TO_STREAM  (pp, len);
1885     ARRAY_TO_STREAM  (pp, p_data, len);
1886 
1887     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1888 }
1889 
1890 #if (CLASSIC_BT_INCLUDED == TRUE)
btsnd_hcic_set_afh_channels(AFH_CHANNELS channels)1891 BOOLEAN btsnd_hcic_set_afh_channels (AFH_CHANNELS channels)
1892 {
1893     BT_HDR *p;
1894     UINT8 *pp;
1895 
1896     if ((p = HCI_GET_CMD_BUF(HCIC_PARAM_SIZE_SET_AFH_CHANNELS)) == NULL) {
1897         return (FALSE);
1898     }
1899 
1900     pp = (UINT8 *)(p + 1);
1901 
1902     p->len    = HCIC_PREAMBLE_SIZE + HCIC_PARAM_SIZE_SET_AFH_CHANNELS;
1903     p->offset = 0;
1904 
1905     UINT16_TO_STREAM (pp, HCI_SET_AFH_CHANNELS);
1906     UINT8_TO_STREAM  (pp, HCIC_PARAM_SIZE_SET_AFH_CHANNELS);
1907 
1908     ARRAY_TO_STREAM  (pp, channels, HCIC_PARAM_SIZE_SET_AFH_CHANNELS);
1909 
1910     btu_hcif_send_cmd (LOCAL_BR_EDR_CONTROLLER_ID,  p);
1911     return (TRUE);
1912 }
1913 #endif /// CLASSIC_BT_INCLUDED == TRUE
1914