• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  *  Copyright 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_gatts_co.h"
20 
21 #include <stdlib.h>
22 #include <string.h>
23 
24 #include "bta_api.h"
25 #include "btif_util.h"
26 #include "osi/include/osi.h"
27 #include "stack/include/gatt_api.h"
28 #include "types/raw_address.h"
29 
30 /*****************************************************************************
31  *  Local type definitions
32  ****************************************************************************/
33 
34 #define BTIF_GATTS_MAX_SRV_CHG_CLT_SIZE 50
35 
36 typedef struct {
37   bool enable;
38   uint8_t num_clients;
39   tGATTS_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   btif_gatts_srv_chg_cb_t* p_cb = &btif_gatts_srv_chg_cb;
54 
55   if (!p_cb->enable) {
56     memset(p_cb, 0, sizeof(btif_gatts_srv_chg_cb_t));
57     p_cb->enable = true;
58   }
59 }
60 
61 /*****************************************************************************
62  *  Externally called functions
63  ****************************************************************************/
64 
btif_gatts_add_bonded_dev_from_nv(const RawAddress & bda)65 void btif_gatts_add_bonded_dev_from_nv(const RawAddress& bda) {
66   btif_gatts_srv_chg_cb_t* p_cb = &btif_gatts_srv_chg_cb;
67   bool found = false;
68   uint8_t i;
69 
70   btif_gatts_check_init();
71 
72   for (i = 0; i != p_cb->num_clients; ++i) {
73     if (p_cb->srv_chg[i].bda == bda) {
74       found = true;
75       break;
76     }
77   }
78 
79   if (!found) {
80     if (p_cb->num_clients < BTIF_GATTS_MAX_SRV_CHG_CLT_SIZE) {
81       p_cb->srv_chg[p_cb->num_clients].bda = bda;
82       p_cb->srv_chg[p_cb->num_clients].srv_changed = false;
83       p_cb->num_clients++;
84     }
85   }
86 }
87