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