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 "bta/bta_api.h"
20
21 #if( defined BLE_INCLUDED ) && (BLE_INCLUDED == TRUE)
22 #if( defined GATTS_INCLUDED ) && (GATTS_INCLUDED == TRUE)
23
24 #include <stdlib.h>
25 #include <string.h>
26 #include "bta/bta_gatts_co.h"
27 // #include "btif_util.h"
28
29 #if (defined(BTIF_INCLUDED) && BTIF_INCLUDED == TRUE)
30 /*****************************************************************************
31 ** Local type definitions
32 *****************************************************************************/
33
34 #define BTIF_GATTS_MAX_SRV_CHG_CLT_SIZE 50
35
36 typedef struct {
37 BOOLEAN enable;
38 UINT8 num_clients;
39 tBTA_GATTS_SRV_CHG srv_chg[BTIF_GATTS_MAX_SRV_CHG_CLT_SIZE];
40 } __attribute__((packed)) btif_gatts_srv_chg_cb_t;
41
42 /*****************************************************************************
43 ** Static variables
44 *****************************************************************************/
45
46 static btif_gatts_srv_chg_cb_t btif_gatts_srv_chg_cb;
47
48 /*****************************************************************************
49 ** Static functions
50 *****************************************************************************/
51
btif_gatts_check_init(void)52 static void btif_gatts_check_init(void)
53 {
54 btif_gatts_srv_chg_cb_t *p_cb = &btif_gatts_srv_chg_cb;
55
56 if (!p_cb->enable) {
57 memset(p_cb, 0, sizeof(btif_gatts_srv_chg_cb_t));
58 p_cb->enable = TRUE;
59 }
60 }
61
62 /*****************************************************************************
63 ** Externally called functions
64 *****************************************************************************/
65
btif_gatts_add_bonded_dev_from_nv(BD_ADDR bda)66 void btif_gatts_add_bonded_dev_from_nv(BD_ADDR bda)
67 {
68 btif_gatts_srv_chg_cb_t *p_cb = &btif_gatts_srv_chg_cb;
69 BOOLEAN found = FALSE;
70 UINT8 i;
71
72 btif_gatts_check_init();
73
74 for (i = 0; i != p_cb->num_clients; ++i) {
75 if (!memcmp(p_cb->srv_chg[i].bda, bda, sizeof(BD_ADDR))) {
76 found = TRUE;
77 break;
78 }
79 }
80
81 if (!found) {
82 if (p_cb->num_clients < BTIF_GATTS_MAX_SRV_CHG_CLT_SIZE) {
83 bdcpy(p_cb->srv_chg[p_cb->num_clients].bda, bda);
84 p_cb->srv_chg[p_cb->num_clients].srv_changed = FALSE;
85 p_cb->num_clients++;
86 }
87 }
88 }
89
90 #endif /* #if (defined(BTIF_INCLUDED) && BTIF_INCLUDED == TRUE) */
91 /*****************************************************************************
92 ** Call-out functions
93 *****************************************************************************/
94
95 /*******************************************************************************
96 **
97 ** Function bta_gatts_co_update_handle_range
98 **
99 ** Description This callout function is executed by GATTS when a GATT server
100 ** handle range ios to be added or removed.
101 **
102 ** Parameter is_add: true is to add a handle range; otherwise is to delete.
103 ** p_hndl_range: handle range.
104 **
105 ** Returns void.
106 **
107 *******************************************************************************/
bta_gatts_co_update_handle_range(BOOLEAN is_add,tBTA_GATTS_HNDL_RANGE * p_hndl_range)108 void bta_gatts_co_update_handle_range(BOOLEAN is_add, tBTA_GATTS_HNDL_RANGE *p_hndl_range)
109 {
110 UNUSED(is_add);
111 UNUSED(p_hndl_range);
112 }
113
114 /*******************************************************************************
115 **
116 ** Function bta_gatts_co_srv_chg
117 **
118 ** Description This call-out is to read/write/remove service change related
119 ** informaiton. The request consists of the cmd and p_req and the
120 ** response is returned in p_rsp
121 **
122 ** Parameter cmd - request command
123 ** p_req - request paramters
124 ** p_rsp - response data for the request
125 **
126 ** Returns TRUE - if the request is processed successfully and
127 ** the response is returned in p_rsp.
128 ** FALSE - if the request can not be processed
129 **
130 *******************************************************************************/
bta_gatts_co_srv_chg(tBTA_GATTS_SRV_CHG_CMD cmd,tBTA_GATTS_SRV_CHG_REQ * p_req,tBTA_GATTS_SRV_CHG_RSP * p_rsp)131 BOOLEAN bta_gatts_co_srv_chg(tBTA_GATTS_SRV_CHG_CMD cmd,
132 tBTA_GATTS_SRV_CHG_REQ *p_req,
133 tBTA_GATTS_SRV_CHG_RSP *p_rsp)
134 {
135 UNUSED(cmd);
136 UNUSED(p_req);
137 UNUSED(p_rsp);
138
139 return FALSE;
140 }
141
142 /*******************************************************************************
143 **
144 ** Function bta_gatts_co_load_handle_range
145 **
146 ** Description This callout function is executed by GATTS when a GATT server
147 ** handle range is requested to be loaded from NV.
148 **
149 ** Parameter
150 **
151 ** Returns void.
152 **
153 *******************************************************************************/
bta_gatts_co_load_handle_range(UINT8 index,tBTA_GATTS_HNDL_RANGE * p_handle_range)154 BOOLEAN bta_gatts_co_load_handle_range(UINT8 index,
155 tBTA_GATTS_HNDL_RANGE *p_handle_range)
156 {
157 UNUSED(index);
158 UNUSED(p_handle_range);
159
160 return FALSE;
161 }
162 #endif
163 #endif
164