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