bta_gatts_co.cc revision 84baa7f16e830394408278dbb8c508dd9fa02887
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 (BTA_GATT_INCLUDED == TRUE) 22 23#include <stdlib.h> 24#include <string.h> 25#include "bt_common.h" 26#include "bta_gatts_co.h" 27#include "btif_util.h" 28#include "osi/include/osi.h" 29 30/***************************************************************************** 31 * Local type definitions 32 ****************************************************************************/ 33 34#define BTIF_GATTS_MAX_SRV_CHG_CLT_SIZE 50 35 36typedef struct { 37 bool enable; 38 uint8_t 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 46static btif_gatts_srv_chg_cb_t btif_gatts_srv_chg_cb; 47 48/***************************************************************************** 49 * Static functions 50 ****************************************************************************/ 51 52static 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 65void btif_gatts_add_bonded_dev_from_nv(BD_ADDR 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 (!memcmp(p_cb->srv_chg[i].bda, bda, sizeof(BD_ADDR))) { 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 bdcpy(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 88/***************************************************************************** 89 * Call-out functions 90 ****************************************************************************/ 91 92/******************************************************************************* 93 * 94 * Function bta_gatts_co_update_handle_range 95 * 96 * Description This callout function is executed by GATTS when a GATT 97 * server handle range ios to be added or removed. 98 * 99 * Parameter is_add: true is to add a handle range; otherwise is to 100 * delete. 101 * p_hndl_range: handle range. 102 * 103 * Returns void. 104 * 105 ******************************************************************************/ 106void bta_gatts_co_update_handle_range(UNUSED_ATTR bool is_add, 107 UNUSED_ATTR tBTA_GATTS_HNDL_RANGE *p_hndl_range) { 108} 109 110/******************************************************************************* 111 * 112 * Function bta_gatts_co_srv_chg 113 * 114 * Description This call-out is to read/write/remove service change related 115 * informaiton. The request consists of the cmd and p_req and 116 * the response is returned in p_rsp 117 * 118 * Parameter cmd - request command 119 * p_req - request paramters 120 * p_rsp - response data for the request 121 * 122 * Returns true - if the request is processed successfully and 123 * the response is returned in p_rsp. 124 * false - if the request can not be processed 125 * 126 ******************************************************************************/ 127bool bta_gatts_co_srv_chg(UNUSED_ATTR tBTA_GATTS_SRV_CHG_CMD cmd, 128 UNUSED_ATTR tBTA_GATTS_SRV_CHG_REQ *p_req, 129 UNUSED_ATTR tBTA_GATTS_SRV_CHG_RSP *p_rsp) { 130 return false; 131} 132 133/******************************************************************************* 134 * 135 * Function bta_gatts_co_load_handle_range 136 * 137 * Description This callout function is executed by GATTS when a GATT 138 * server handle range is requested to be loaded from NV. 139 * 140 * Parameter 141 * 142 * Returns void. 143 * 144 ******************************************************************************/ 145bool bta_gatts_co_load_handle_range(UNUSED_ATTR uint8_t index, 146 UNUSED_ATTR tBTA_GATTS_HNDL_RANGE *p_handle_range) { 147 return false; 148} 149 150#endif // BTA_GATT_INCLUDED == TRUE 151