1 /******************************************************************************
3 * Copyright (C) 2009-2013 Broadcom Corporation
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:
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 ******************************************************************************/
21 #include "bt_target.h"
28 /*******************************************************************************
30 ** Function GAP_SetDiscoverableMode
32 ** Description This function is called to allow or disallow a service to
33 ** discovered (Inquiry Scans).
35 ** Parameters: mode - GAP_NON_DISCOVERABLE, GAP_LIMITED_DISCOVERABLE,
36 ** or GAP_GENERAL_DISCOVERABLE
38 ** duration - Amount of time for the duration of an inquiry scan.
39 ** The step size is in 0.625 msec intervals.
40 ** Range: 0x0012 - 0x1000 (11.25 - 2560 msecs)
42 ** If a value of '0' is entered the default of
43 ** 0x0012 (11.25 msecs) will be used.
44 ** Note: The duration must be less than or equal to
47 ** interval - Amount of time between the start of two inquiry scans.
48 ** The step size is in 0.625 msec intervals.
49 ** Range: 0x0012 - 0x1000 (11.25 - 2560 msecs)
50 ** If a value of '0' is entered the default of
51 ** 0x800 (1.28 secs) will be used.
54 ** Returns BT_PASS (0) if successful,
55 ** GAP_ERR_ILL_PARM if a bad parameter is detected,
56 ** GAP_DEVICE_NOT_UP if the device is not active,
57 ** GAP_ERR_PROCESSING if not enough resources to carry out request
59 *******************************************************************************/
60 UINT16 GAP_SetDiscoverableMode (UINT16 mode, UINT16 duration, UINT16 interval)
64 status = BTM_SetDiscoverability(mode, duration, interval);
66 return (gap_convert_btm_status (status));
70 /*******************************************************************************
72 ** Function GAP_ReadDiscoverableMode
74 ** Description This function is called to retrieve the current discoverable mode
75 ** for the local device.
77 ** Parameters: duration - pointer to the amount of time of an inquiry scan.
78 ** The step size is in 0.625 msec intervals.
79 ** Range: 0x0012 - 0x1000 (11.25 - 2560 msecs)
81 ** interval - pointer to the amount of time between the start of
83 ** The step size is in 0.625 msec intervals.
84 ** Range: 0x0012 - 0x1000 (11.25 - 2560 msecs)
87 ** Returns GAP_NON_DISCOVERABLE, GAP_LIMITED_DISCOVERABLE, or
88 ** GAP_GENERAL_DISCOVERABLE
90 *******************************************************************************/
91 UINT16 GAP_ReadDiscoverableMode (UINT16 *duration, UINT16 *interval)
93 return (BTM_ReadDiscoverability(duration, interval));
97 /*******************************************************************************
99 ** Function GAP_SetConnectableMode
101 ** Description This function is called to allow or disallow a
102 ** connections on the local device.
104 ** Parameters: mode - GAP_NON_CONNECTABLE, GAP_CONNECTABLE,
106 ** duration - Amount of time for the duration of a page scan.
107 ** The step size is in 0.625 msec intervals.
108 ** Range: 0x0012 - 0x1000 (11.25 - 2560 msecs)
110 ** If a value of '0' is entered the default of
111 ** 0x0012 (11.25 msecs) will be used.
112 ** Note: The duration must be less than or equal to
115 ** interval - Amount of time between the start of two page scans.
116 ** The step size is in 0.625 msec intervals.
117 ** Range: 0x0012 - 0x1000 (11.25 - 2560 msecs)
118 ** If a value of '0' is entered the default of
119 ** 0x800 (1.28 secs) will be used.
122 ** Returns BT_PASS (0) if successful,
123 ** GAP_ERR_ILL_PARM if a bad parameter is detected,
124 ** GAP_DEVICE_NOT_UP if the device is not active,
125 ** GAP_ERR_PROCESSING if not enough resources to carry out request
127 *******************************************************************************/
128 UINT16 GAP_SetConnectableMode (UINT16 mode, UINT16 duration, UINT16 interval)
132 status = BTM_SetConnectability(mode, duration, interval);
134 return (gap_convert_btm_status (status));
138 /*******************************************************************************
140 ** Function GAP_FindAddrByName
142 ** Description This function is called to retrieve a device address given
143 ** a device name. It first looks in the current local inquiry
144 ** database for the device with the specified name. If not found
145 ** it initiates a general inquiry. Upon completion, it retrieves
146 ** the name for each device until a match is found or all devices
147 ** have been checked. Note: This process can take a while to
150 ** Parameters: devname -
152 ** inqparms - pointer to the inquiry information
153 ** mode - GAP_GENERAL_INQUIRY or GAP_LIMITED_INQUIRY inquiry
154 ** duration - length in 1.28 sec intervals
155 ** max_resps - maximum amount of devices to search for before ending the inquiry
156 ** filter_cond_type - GAP_CLR_INQUIRY_FILTER, GAP_FILTER_COND_DEVICE_CLASS, or
157 ** GAP_FILTER_COND_BD_ADDR
158 ** filter_cond - value for the filter (based on filter_cond_type)
161 ** Returns BT_PASS if the name was immediately available. (BD_ADDR is returned)
162 ** GAP_CMD_INITIATED if an inquiry has been initiated
164 *******************************************************************************/
165 UINT16 GAP_FindAddrByName (BD_NAME devname, tGAP_INQ_PARMS *p_inq_parms, tGAP_CALLBACK *p_addr_cb,
169 tBTM_STATUS btm_status;
172 /* If the remote name is retrieved automatically during an inquiry search the local db first */
173 if ((status = gap_find_local_addr_by_name (devname, bd_addr)) != BT_PASS)
175 /* If this code is used, the name wasn't in the current inquiry database */
176 /* A general inquiry must now be initiated */
177 if (gap_cb.findaddr_cb.in_use == FALSE)
179 gap_cb.findaddr_cb.p_cback = p_addr_cb;
180 gap_cb.findaddr_cb.p_cur_inq = (tBTM_INQ_INFO *) NULL; /* Reset to the beginning of the database */
181 BCM_STRNCPY_S ((char *)gap_cb.findaddr_cb.results.devname, sizeof(gap_cb.findaddr_cb.results.devname), (char *)devname, BTM_MAX_REM_BD_NAME_LEN);
183 /* make sure we have an end of string char */
184 gap_cb.findaddr_cb.results.devname[BTM_MAX_REM_BD_NAME_LEN] = 0;
186 btm_status = BTM_StartInquiry (p_inq_parms, (tBTM_INQ_RESULTS_CB *) NULL,
187 (tBTM_CMPL_CB *) gap_find_addr_inq_cb);
188 gap_cb.findaddr_cb.in_use = TRUE;
190 /* convert the error code into a GAP code and check the results for any errors */
191 if ((status = gap_convert_btm_status (btm_status)) == GAP_CMD_INITIATED)
192 gap_cb.findaddr_cb.in_use = TRUE;
195 status = GAP_ERR_BUSY;
202 /*******************************************************************************
204 ** Function GAP_ReadConnectableMode
206 ** Description This function is called to retrieve the current connectability
207 ** mode for the local device.
209 ** Parameters: duration - pointer to the amount of time of an page scan.
210 ** The step size is in 0.625 msec intervals.
211 ** Range: 0x0012 - 0x1000 (11.25 - 2560 msecs)
213 ** interval - pointer to the amount of time between the start of
215 ** The step size is in 0.625 msec intervals.
216 ** Range: 0x0012 - 0x1000 (11.25 - 2560 msecs)
219 ** Returns GAP_NON_CONNECTABLE, GAP_CONNECTABLE
221 *******************************************************************************/
223 UINT16 GAP_ReadConnectableMode (UINT16 *duration, UINT16 *interval)
225 return (BTM_ReadConnectability(duration, interval));
229 /*******************************************************************************
231 ** Function GAP_SetSecurityMode
233 ** Description Set security mode for the device
237 *******************************************************************************/
238 void GAP_SetSecurityMode (UINT8 sec_mode)
240 BTM_SetSecurityMode (sec_mode);
244 /*******************************************************************************
248 ** Description This function is called to perform bonding with peer device
250 ** Parameters: bd_addr - Address of the device to bond
251 ** pin_len - length in bytes of the PIN Code
252 ** p_pin - pointer to array with the PIN Code
253 ** trusted_mask - bitwise OR of trusted services (array of UINT32)
255 *******************************************************************************/
256 UINT8 GAP_Bond (BD_ADDR bd_addr, UINT8 pin_len, UINT8 *p_pin, UINT32 trusted_mask[])
258 return ((UINT8) BTM_SecBond (bd_addr, pin_len, p_pin, trusted_mask));
262 /*******************************************************************************
264 ** Function GAP_SecRegister
266 ** Description Application manager calls this function to register for
267 ** security services. There can be one and only one application
268 ** saving link keys. BTM allows only first registration.
270 ** Returns TRUE if registered OK, else FALSE
272 *******************************************************************************/
273 BOOLEAN GAP_SecRegister (tBTM_APPL_INFO *p_cb_info)
275 return (BTM_SecRegister (p_cb_info));
279 /*******************************************************************************
281 ** Function GAP_PinRsp
283 ** Description This function is called from UI after Security Manager submitted
286 ** Parameters: bd_addr - Address of the device for which PIN was requested
287 ** res - result of the operation BTM_SUCCESS if success
288 ** pin_len - length in bytes of the PIN Code
289 ** p_pin - pointer to array with the PIN Code
290 ** trusted_mask - bitwise OR of trusted services (array of UINT32)
292 *******************************************************************************/
293 void GAP_PinRsp (BD_ADDR bd_addr, UINT8 res, UINT8 pin_len, UINT8 *p_pin, UINT32 trusted_mask[])
295 BTM_PINCodeReply (bd_addr, res, pin_len, p_pin, trusted_mask);
299 /*******************************************************************************
301 ** Function GAP_AuthorizeRsp
303 ** Description This function is called from UI after Security Manager submitted
304 ** authorization request
306 ** Parameters: bd_addr - Address of the device for which PIN was requested
307 ** res - result of the operation BTM_SUCCESS if success
308 ** trusted_mask - bitwise OR of trusted services (array of UINT32)
310 *******************************************************************************/
311 void GAP_AuthorizeRsp (BD_ADDR bd_addr, UINT8 res, UINT32 trusted_mask[])
313 BTM_DeviceAuthorized (bd_addr, res, trusted_mask);
317 /*******************************************************************************
319 ** Function GAP_SetPairableMode
321 ** Description This function is called to allow or disallow pairing
322 ** on the local device.
324 ** Parameters: mode - GAP_ALLOW_PAIRING, GAP_DISALLOW_PAIRING
325 ** connect_only_pairable - TRUE or FALSE connect only to paired devices
327 ** callback - The callback is called when a pin number is requested.
329 ** Returns BT_PASS (0) if successful, or a non-zero error code
331 *******************************************************************************/
333 UINT16 GAP_SetPairableMode (UINT16 mode, BOOLEAN connect_only_paired)
335 tBTM_STATUS btm_status;
336 UINT16 status = BT_PASS;
338 if (mode == GAP_ALLOW_PAIRING)
340 btm_status = BTM_SetConnectability(BTM_CONNECTABLE, 0, 0);
342 if ((status = gap_convert_btm_status (btm_status)) == BT_PASS)
343 BTM_SetPairableMode (TRUE, connect_only_paired);
345 else if (mode == GAP_DISALLOW_PAIRING)
347 BTM_SetPairableMode (FALSE, connect_only_paired);
351 GAP_TRACE_ERROR1 ("GAP_SetPairableMode: illegal mode %d", mode);
352 status = GAP_ERR_ILL_MODE;
358 /*******************************************************************************
360 ** Function GAP_StartInquiry
362 ** Description This function initiates a single inquiry.
364 ** Parameters: p_inqparms - pointer to the inquiry information
365 ** mode - GAP_GENERAL_INQUIRY or GAP_LIMITED_INQUIRY inquiry
366 ** duration - length in 1.28 sec intervals
367 ** max_resps - maximum amount of devices to search for before ending the inquiry
368 ** filter_cond_type - GAP_CLR_INQUIRY_FILTER, GAP_FILTER_COND_DEVICE_CLASS, or
369 ** GAP_FILTER_COND_BD_ADDR
370 ** filter_cond - value for the filter (based on filter_cond_type)
372 ** p_results_cb - Pointer to the callback routine which gets called
373 ** upon receipt of an inquiry result. If this field is
374 ** NULL, the application is not notified.
376 ** p_cmpl_cb - Pointer to the callback routine which gets called
377 ** upon completion. If this field is NULL, the
378 ** application is not notified when completed.
381 ** Returns BT_PASS (0) if successful,
382 ** GAP_ERR_ILL_MODE if a bad mode parameter was passed
383 ** GAP_ERR_ILL_INQ_TIME if a bad interval or duration was passed
384 ** GAP_ERR_NO_CTRL_BLK if out of control blocks
385 ** GAP_ERR_ILL_PARM if a bad parameter was detected in BTM
386 ** GAP_ERR_BUSY if the device already has an iquiry active
387 ** GAP_DEVICE_NOT_UP if the device is not initialized yet
388 ** GAP_ERR_PROCESSING if any other BTM error was returned
390 *******************************************************************************/
391 UINT16 GAP_StartInquiry (tGAP_INQ_PARMS *p_inq_parms, tGAP_CALLBACK *p_results_cb, tGAP_CALLBACK *p_cmpl_cb)
394 tBTM_STATUS btm_status;
397 /*** Make sure the parameters are valid before continuing ***/
398 if (p_inq_parms->mode != GAP_GENERAL_INQUIRY && p_inq_parms->mode != GAP_LIMITED_INQUIRY)
399 return (GAP_ERR_ILL_MODE);
401 if (p_inq_parms->duration < GAP_MIN_INQUIRY_LEN ||
402 p_inq_parms->duration > GAP_MAX_INQUIRY_LENGTH)
403 return (GAP_ERR_ILL_INQ_TIME);
405 /*** get a control block for this operation ***/
406 if ((p_cb = gap_allocate_cb()) != NULL)
408 p_cb->gap_cback = p_cmpl_cb;
409 p_cb->gap_inq_rslt_cback = p_results_cb;
410 p_cb->event = GAP_EVT_INQUIRY_COMPLETE; /* Return event expected */
412 btm_status = BTM_StartInquiry(p_inq_parms, gap_inq_results_cb,
413 (tBTM_CMPL_CB *) gap_cb.btm_cback[p_cb->index]);
415 /* convert the error code into a GAP code and check the results for any errors */
416 if ((retval = gap_convert_btm_status (btm_status)) != GAP_CMD_INITIATED)
417 gap_free_cb(p_cb); /* Error starting the inquiry */
420 retval = GAP_ERR_NO_CTRL_BLK;
426 /*******************************************************************************
428 ** Function GAP_StartPeriodicInquiry
430 ** Description This function initiates a periodic inquiry.
432 ** Parameters: p_inqparms - pointer to the inquiry information
433 ** mode - GAP_GENERAL_INQUIRY or GAP_LIMITED_INQUIRY inquiry
434 ** duration - length in 1.28 sec intervals
435 ** max_resps - maximum amount of devices to search for before ending the inquiry
436 ** filter_cond_type - GAP_CLR_INQUIRY_FILTER, GAP_FILTER_COND_DEVICE_CLASS, or
437 ** GAP_FILTER_COND_BD_ADDR
438 ** filter_cond - value for the filter (based on filter_cond_type)
440 ** min_time - Minimum amount of time between consecutive inquiries.
441 ** The value is in 1.28 second intervals.
442 ** Range: 0x0002 - 0xFFFE (2.56 - 83883.52 seconds)
444 ** max_time - Maximum amount of time between consecutive inquiries.
445 ** The value is in 1.28 sec intervals.
446 ** Range: 0x0003 - 0xFFFF (3.84 - 83884.8 seconds)
448 ** p_results_cb - Pointer to the callback routine which gets called
449 ** upon receipt of an inquiry result. If this field is
450 ** NULL, the application is not notified.
453 ** Returns BT_PASS (0) if successful,
454 ** GAP_ERR_ILL_MODE if a bad mode parameter was passed
455 ** GAP_ERR_ILL_INQ_TIME if a bad interval or duration was passed
456 ** GAP_ERR_NO_CTRL_BLK if out of control blocks
457 ** GAP_ERR_ILL_PARM if a bad parameter was detected in BTM
458 ** GAP_ERR_BUSY if the device already has an iquiry active
459 ** GAP_DEVICE_NOT_UP if the device is not initialized yet
460 ** GAP_ERR_PROCESSING if any other BTM error was returned
462 *******************************************************************************/
464 UINT16 GAP_StartPeriodicInquiry (tGAP_INQ_PARMS *p_inq_parms, UINT16 min_time,
465 UINT16 max_time, tGAP_CALLBACK *p_results_cb)
468 tBTM_STATUS btm_status;
469 UINT16 retval = BT_PASS;
471 /*** Make sure the parameters are valid before continuing ***/
472 if (p_inq_parms->mode != GAP_GENERAL_INQUIRY && p_inq_parms->mode != GAP_LIMITED_INQUIRY)
473 return (GAP_ERR_ILL_MODE);
475 if (p_inq_parms->duration < GAP_MIN_INQUIRY_LEN ||
476 p_inq_parms->duration > GAP_MAX_INQUIRY_LENGTH ||
477 min_time <= p_inq_parms->duration ||
478 min_time < GAP_PER_INQ_MIN_MIN_PERIOD ||
479 min_time > GAP_PER_INQ_MAX_MIN_PERIOD ||
480 max_time <= min_time ||
481 max_time < GAP_PER_INQ_MIN_MAX_PERIOD)
483 return (GAP_ERR_ILL_INQ_TIME);
486 /*** get a control block for this operation ***/
487 if ((p_cb = gap_allocate_cb()) != NULL)
489 p_cb->gap_inq_rslt_cback = p_results_cb;
490 p_cb->event = GAP_EVT_INQUIRY_COMPLETE; /* mark the inquiry event active */
492 btm_status = BTM_SetPeriodicInquiryMode(p_inq_parms, max_time, min_time,
495 /* convert the error code into a GAP code and check the results for any errors */
496 if ((retval = gap_convert_btm_status (btm_status)) != GAP_CMD_INITIATED)
497 gap_free_cb(p_cb); /* Error starting the inquiry */
500 retval = GAP_ERR_NO_CTRL_BLK;
506 /*******************************************************************************
508 ** Function GAP_CancelInquiry
510 ** Description This function cancels a single inquiry (if in progress)
514 ** Returns BOOLEAN (TRUE if successful, otherwise FALSE)
516 *******************************************************************************/
517 UINT16 GAP_CancelInquiry(void)
519 tGAP_INFO *p_cb = &gap_cb.blk[0];
521 tBTM_STATUS btm_status;
524 btm_status = BTM_CancelInquiry();
525 if ((status = gap_convert_btm_status (btm_status)) == BT_PASS)
527 /* Free the control block that is waiting for the inquiry complete event */
528 for (x = 0; x < GAP_MAX_BLOCKS; x++, p_cb++)
530 if (p_cb->in_use && p_cb->event == GAP_EVT_INQUIRY_COMPLETE)
537 /* If here the control block was not found */
538 status = GAP_ERR_NO_CTRL_BLK;
545 /*******************************************************************************
547 ** Function GAP_CancelPeriodicInquiry
549 ** Description This function cancels a periodic inquiry (if in progress)
553 ** Returns BOOLEAN: (TRUE if successful, otherwise FALSE)
555 *******************************************************************************/
556 UINT16 GAP_CancelPeriodicInquiry(void)
558 tGAP_INFO *p_cb = &gap_cb.blk[0];
560 tBTM_STATUS btm_status;
563 btm_status = BTM_CancelPeriodicInquiry();
564 if ((status = gap_convert_btm_status (btm_status)) == BT_PASS)
566 /* Free the control block that is waiting for the inquiry complete event */
567 for (x = 0; x < GAP_MAX_BLOCKS; x++, p_cb++)
569 if (p_cb->in_use && p_cb->event == GAP_EVT_INQUIRY_COMPLETE)
576 /* If here the control block was not found */
577 status = GAP_ERR_NO_CTRL_BLK;
584 /*******************************************************************************
586 ** Function GAP_GetFirstInquiryResult
588 ** Description This function retrieves the first valid inquiry result.
590 ** Parameters: p_results - pointer to the inquiry results
592 ** Returns BT_PASS (0) if successful, or a non-zero error code
593 ** GAP_EOINQDB if no more entries in the database.
595 *******************************************************************************/
596 UINT16 GAP_GetFirstInquiryResult(tGAP_INQ_RESULTS *p_results)
600 gap_cb.cur_inqptr = BTM_InqFirstResult();
602 if (gap_cb.cur_inqptr != NULL)
604 memcpy(p_results, &gap_cb.cur_inqptr->results, sizeof(tBTM_INQ_RESULTS));
606 ptr = (UINT8 *)gap_cb.cur_inqptr->results.remote_bd_addr;
607 GAP_TRACE_EVENT6("GAP_GetFirstInqResult %02x%02x%02x%02x%02x%02x",
608 ptr[0],ptr[1],ptr[2],ptr[3],ptr[4],ptr[5]);
613 GAP_TRACE_EVENT0("GAP_FirstInqResults: No BD_ADDRs Found");
614 memset(p_results, 0, sizeof(tBTM_INQ_RESULTS));
620 /*******************************************************************************
622 ** Function GAP_GetNextInquiryResult
624 ** Description This function retrieves the next valid inquiry result.
626 ** Parameters: p_results - pointer to the inquiry results
628 ** Returns BT_PASS (0) if successful, or a non-zero status code
629 ** GAP_EOINQDB if no more entries in the database.
631 *******************************************************************************/
632 UINT16 GAP_GetNextInquiryResult(tGAP_INQ_RESULTS *p_results)
636 /*** if the current inquiry db pointer is NULL then call the first entry ***/
637 if (gap_cb.cur_inqptr)
639 gap_cb.cur_inqptr = BTM_InqNextResult(gap_cb.cur_inqptr);
640 if (gap_cb.cur_inqptr != NULL)
642 memcpy(p_results, &gap_cb.cur_inqptr->results,
643 sizeof(tGAP_INQ_RESULTS));
645 ptr = (UINT8 *)gap_cb.cur_inqptr->results.remote_bd_addr;
646 GAP_TRACE_EVENT6("GAP_GetNextInqResult %02x%02x%02x%02x%02x%02x",
647 ptr[0],ptr[1],ptr[2],ptr[3],ptr[4],ptr[5]);
653 GAP_TRACE_EVENT0("GAP_NextInqResults: No BD_ADDRs Found");
654 memset(p_results, 0, sizeof(tBTM_INQ_RESULTS));
659 return (GAP_GetFirstInquiryResult(p_results));
663 /*******************************************************************************
665 ** Function GAP_ReadLocalDeviceInfo
667 ** Description This function retrieves local device information to the caller.
669 ** Parameters: name - (output) pointer to the UTF-8 encoded string representing
672 ** addr - (output) pointer to the Bluetooth device address (BD_ADDR).
674 ** verinfo - (output) pointer to the LMP version information.
676 ** features - (output) pointer to the LMP features for the device.
678 ** NOTE: Return parameters that are set to NULL are not retrieved.
680 ** Returns BT_PASS (0) if successful, or a non-zero error code
682 *******************************************************************************/
684 UINT16 GAP_ReadLocalDeviceInfo(UINT8 *name, BD_ADDR *addr, tGAP_LMP_VERSION *verinfo,
685 tGAP_LMP_FEATURES *features)
691 return (GAP_UNSUPPORTED);
696 /*******************************************************************************
698 ** Function GAP_GetRemoteDeviceName
700 ** Description The remote name is retrieved from the specified remote device. If
701 ** GAP_CMD_INITIATED is returned by the function, the command was
702 ** successfully sent to the controller. The GAP_EVT_NAME_RESP event
703 ** is passed in the callback when the remote device name has been retrieved.
705 ** Parameters: addr - The Bluetooth device address (BD_ADDR) of the remote
708 ** callback - pointer to the callback which is called after the
709 ** remote device has been retrieved.
710 ** p_data in the callback points to the structure containing the
711 ** status, device name length, and the UTF-8 encoded
712 ** device name. (type tBTM_REMOTE_DEV_NAME)
713 ** The event field in the callback is set to GAP_EVT_REM_NAME_COMPLETE.
714 ** The callback is not called unless (GAP_CMD_INITIATED) is returned.
718 ** GAP_CMD_INITIATED if remote search successfully initiated
719 ** GAP_ERR_BUSY if a remote name request is already in progress,
720 ** GAP_ERR_NO_CTRL_BLK if out of control blocks (too many commands pending)
721 ** GAP_BAD_BD_ADDR if the device address is bad,
722 ** GAP_DEVICE_NOT_UP if the device has not been initialized yet
723 ** GAP_ERR_PROCESSING if any other BTM error has been returned
725 *******************************************************************************/
726 UINT16 GAP_GetRemoteDeviceName (BD_ADDR addr, tGAP_CALLBACK *callback)
730 tBTM_STATUS btm_status;
732 if ((p_cb = gap_allocate_cb()) != NULL)
734 p_cb->gap_cback = callback;
735 p_cb->event = GAP_EVT_REM_NAME_COMPLETE; /* Return event expected */
737 btm_status = BTM_ReadRemoteDeviceName (addr, gap_cb.btm_cback[p_cb->index], BT_TRANSPORT_BR_EDR);
739 /* If the name was not returned immediately, or if an error occurred, release the control block */
740 if ((retval = gap_convert_btm_status (btm_status)) != GAP_CMD_INITIATED)
744 retval = GAP_ERR_NO_CTRL_BLK;
749 /*******************************************************************************
751 ** Function GAP_SetDeviceClass
753 ** Description This function updates the local Device Class.
756 ** p_cod - Pointer to the device class to set to
758 ** cmd - the fields of the device class to update.
759 ** GAP_SET_COD_MAJOR_MINOR, - overwrite major, minor class
760 ** GAP_SET_COD_SERVICE_CLASS - set the bits in the input
761 ** GAP_CLR_COD_SERVICE_CLASS - clear the bits in the input
762 ** GAP_SET_COD_ALL - overwrite major, minor, set the bits in service class
763 ** GAP_INIT_COD - overwrite major, minor, and service class
765 ** Returns BT_PASS (0) if successful,
766 ** GAP_ERR_BUSY if a discovery is already in progress
767 ** GAP_ERR_ILL_PARM if an illegal parameter was detected
768 ** GAP_ERR_PROCESSING if any other BTM error has been returned
770 *******************************************************************************/
771 UINT16 GAP_SetDeviceClass(tGAP_COD *p_cod, UINT8 cmd)
773 tBTM_STATUS btm_status;
779 dev = BTM_ReadDeviceClass();
780 BTM_COD_SERVICE_CLASS( service, dev );
781 BTM_COD_MINOR_CLASS(minor, dev );
782 BTM_COD_MAJOR_CLASS(major, dev );
786 case GAP_SET_COD_MAJOR_MINOR:
787 minor = p_cod->minor & BTM_COD_MINOR_CLASS_MASK;
788 major = p_cod->major & BTM_COD_MAJOR_CLASS_MASK;
791 case GAP_SET_COD_SERVICE_CLASS:
792 /* clear out the bits that is not SERVICE_CLASS bits */
793 p_cod->service &= BTM_COD_SERVICE_CLASS_MASK;
794 service = service | p_cod->service;
797 case GAP_CLR_COD_SERVICE_CLASS:
798 p_cod->service &= BTM_COD_SERVICE_CLASS_MASK;
799 service = service & (~p_cod->service);
802 case GAP_SET_COD_ALL:
803 minor = p_cod->minor & BTM_COD_MINOR_CLASS_MASK;
804 major = p_cod->major & BTM_COD_MAJOR_CLASS_MASK;
805 p_cod->service &= BTM_COD_SERVICE_CLASS_MASK;
806 service = service | p_cod->service;
810 minor = p_cod->minor & BTM_COD_MINOR_CLASS_MASK;
811 major = p_cod->major & BTM_COD_MAJOR_CLASS_MASK;
812 service = p_cod->service & BTM_COD_SERVICE_CLASS_MASK;
816 return GAP_ERR_ILL_PARM;
819 /* convert the fields into the device class type */
820 FIELDS_TO_COD(dev_class, minor, major, service);
822 btm_status = BTM_SetDeviceClass(dev_class);
823 return (gap_convert_btm_status (btm_status));
826 /*******************************************************************************
828 ** Function GAP_ReadDeviceClass
830 ** Description This function reads the local Device Class.
836 *******************************************************************************/
837 UINT16 GAP_ReadDeviceClass(tGAP_COD *p_cod)
841 dev = BTM_ReadDeviceClass();
843 BTM_COD_SERVICE_CLASS( p_cod->service, dev );
844 BTM_COD_MINOR_CLASS( p_cod->minor, dev );
845 BTM_COD_MAJOR_CLASS( p_cod->major, dev );
850 /*******************************************************************************
852 ** Function GAP_SetTraceLevel
854 ** Description This function sets the trace level for GAP. If called with
855 ** a value of 0xFF, it simply returns the current trace level.
857 ** Returns The new or current trace level
859 *******************************************************************************/
860 UINT8 GAP_SetTraceLevel (UINT8 new_level)
862 if (new_level != 0xFF)
863 gap_cb.trace_level = new_level;
865 return (gap_cb.trace_level);
868 /*******************************************************************************
872 ** Description Initializes the control blocks used by GAP.
874 ** This routine should not be called except once per
879 *******************************************************************************/
882 memset (&gap_cb, 0, sizeof (tGAP_CB));
884 /*** Initialize the callbacks for BTM; Needs to be one per GAP_MAX_BLOCKS ***/
885 gap_cb.btm_cback[0] = gap_btm_cback0;
886 #if GAP_MAX_BLOCKS > 1
887 gap_cb.btm_cback[1] = gap_btm_cback1;
889 #if GAP_MAX_BLOCKS > 2
890 gap_cb.btm_cback[2] = gap_btm_cback2;
893 #if defined(GAP_INITIAL_TRACE_LEVEL)
894 gap_cb.trace_level = GAP_INITIAL_TRACE_LEVEL;
896 gap_cb.trace_level = BT_TRACE_LEVEL_NONE; /* No traces */
899 /* Initialize the connection control block if included in build */
900 #if GAP_CONN_INCLUDED == TRUE
902 #endif /* GAP_CONN_INCLUDED */
904 #if BLE_INCLUDED == TRUE