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