• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright (C) 2009-2013 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 #include <string.h>
20 #include "bt_target.h"
21 #include "bt_utils.h"
22 #include "gap_int.h"
23 
24 /*******************************************************************************
25  *
26  * Function         gap_allocate_cb
27  *
28  * Description      Look through the GAP Control Blocks for a free one.
29  *
30  * Returns          Pointer to the control block or NULL if not found
31  *
32  ******************************************************************************/
gap_allocate_cb(void)33 tGAP_INFO* gap_allocate_cb(void) {
34   tGAP_INFO* p_cb = &gap_cb.blk[0];
35   uint8_t x;
36 
37   for (x = 0; x < GAP_MAX_BLOCKS; x++, p_cb++) {
38     if (!p_cb->in_use) {
39       memset(p_cb, 0, sizeof(tGAP_INFO));
40 
41       p_cb->in_use = true;
42       p_cb->index = x;
43       p_cb->p_data = (void*)NULL;
44       return (p_cb);
45     }
46   }
47 
48   /* If here, no free control blocks found */
49   return (NULL);
50 }
51 
52 /*******************************************************************************
53  *
54  * Function         gap_free_cb
55  *
56  * Description      Release GAP control block.
57  *
58  * Returns          Pointer to the control block or NULL if not found
59  *
60  ******************************************************************************/
gap_free_cb(tGAP_INFO * p_cb)61 void gap_free_cb(tGAP_INFO* p_cb) {
62   if (p_cb) {
63     p_cb->gap_cback = NULL;
64     p_cb->in_use = false;
65   }
66 }
67 
68 /*******************************************************************************
69  *
70  * Function         gap_is_service_busy
71  *
72  * Description      Look through the GAP Control Blocks that are in use
73  *                  and check to see if the event waiting for is the command
74  *                  requested.
75  *
76  * Returns          true if already in use
77  *                  false if not busy
78  *
79  ******************************************************************************/
gap_is_service_busy(uint16_t request)80 bool gap_is_service_busy(uint16_t request) {
81   tGAP_INFO* p_cb = &gap_cb.blk[0];
82   uint8_t x;
83 
84   for (x = 0; x < GAP_MAX_BLOCKS; x++, p_cb++) {
85     if (p_cb->in_use && p_cb->event == request) return (true);
86   }
87 
88   /* If here, service is not busy */
89   return (false);
90 }
91 
92 /*******************************************************************************
93  *
94  * Function         gap_convert_btm_status
95  *
96  * Description      Converts a BTM error status into a GAP error status
97  *
98  *
99  * Returns          GAP_UNKNOWN_BTM_STATUS is returned if not recognized
100  *
101  ******************************************************************************/
gap_convert_btm_status(tBTM_STATUS btm_status)102 uint16_t gap_convert_btm_status(tBTM_STATUS btm_status) {
103   switch (btm_status) {
104     case BTM_SUCCESS:
105       return (BT_PASS);
106 
107     case BTM_CMD_STARTED:
108       return (GAP_CMD_INITIATED);
109 
110     case BTM_BUSY:
111       return (GAP_ERR_BUSY);
112 
113     case BTM_MODE_UNSUPPORTED:
114     case BTM_ILLEGAL_VALUE:
115       return (GAP_ERR_ILL_PARM);
116 
117     case BTM_WRONG_MODE:
118       return (GAP_DEVICE_NOT_UP);
119 
120     case BTM_UNKNOWN_ADDR:
121       return (GAP_BAD_BD_ADDR);
122 
123     case BTM_DEVICE_TIMEOUT:
124       return (GAP_ERR_TIMEOUT);
125 
126     default:
127       return (GAP_ERR_PROCESSING);
128   }
129 }
130