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 ******************************************************************************/
20 #include "bt_target.h"
24 /*******************************************************************************
26 ** Function gap_allocate_cb
28 ** Description Look through the GAP Control Blocks for a free one.
30 ** Returns Pointer to the control block or NULL if not found
32 *******************************************************************************/
33 tGAP_INFO *gap_allocate_cb (void)
35 tGAP_INFO *p_cb = &gap_cb.blk[0];
38 for (x = 0; x < GAP_MAX_BLOCKS; x++, p_cb++)
42 memset (p_cb, 0, sizeof (tGAP_INFO));
46 p_cb->p_data = (void *)NULL;
51 /* If here, no free control blocks found */
56 /*******************************************************************************
58 ** Function gap_free_cb
60 ** Description Release GAP control block.
62 ** Returns Pointer to the control block or NULL if not found
64 *******************************************************************************/
65 void gap_free_cb (tGAP_INFO *p_cb)
69 p_cb->gap_cback = NULL;
75 /*******************************************************************************
77 ** Function gap_is_service_busy
79 ** Description Look through the GAP Control Blocks that are in use
80 ** and check to see if the event waiting for is the command
83 ** Returns TRUE if already in use
86 *******************************************************************************/
87 BOOLEAN gap_is_service_busy (UINT16 request)
89 tGAP_INFO *p_cb = &gap_cb.blk[0];
92 for (x = 0; x < GAP_MAX_BLOCKS; x++, p_cb++)
94 if (p_cb->in_use && p_cb->event == request)
98 /* If here, service is not busy */
103 /*******************************************************************************
105 ** Function gap_convert_btm_status
107 ** Description Converts a BTM error status into a GAP error status
110 ** Returns GAP_UNKNOWN_BTM_STATUS is returned if not recognized
112 *******************************************************************************/
113 UINT16 gap_convert_btm_status (tBTM_STATUS btm_status)
120 case BTM_CMD_STARTED:
121 return (GAP_CMD_INITIATED);
124 return (GAP_ERR_BUSY);
126 case BTM_MODE_UNSUPPORTED:
127 case BTM_ILLEGAL_VALUE:
128 return (GAP_ERR_ILL_PARM);
131 return (GAP_DEVICE_NOT_UP);
133 case BTM_UNKNOWN_ADDR:
134 return (GAP_BAD_BD_ADDR);
136 case BTM_DEVICE_TIMEOUT:
137 return (GAP_ERR_TIMEOUT);
140 return (GAP_ERR_PROCESSING);