1/******************************************************************************
2 *
3 *  Copyright (C) 2014  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
20#ifndef BTIF_GATT_MULTI_ADV_UTIL_H
21#define BTIF_GATT_MULTI_ADV_UTIL_H
22
23#include <hardware/bluetooth.h>
24#include "bta_api.h"
25
26#define CLNT_IF_IDX 0
27#define INST_ID_IDX 1
28#define INST_ID_IDX_MAX (INST_ID_IDX + 1)
29#define INVALID_ADV_INST -1
30#define STD_ADV_INSTID 0
31
32/* Default ADV flags for general and limited discoverability */
33#define ADV_FLAGS_LIMITED BTA_DM_LIMITED_DISC
34#define ADV_FLAGS_GENERAL BTA_DM_GENERAL_DISC
35
36typedef struct
37{
38    int client_if;
39    BOOLEAN set_scan_rsp;
40    BOOLEAN include_name;
41    BOOLEAN include_txpower;
42    int min_interval;
43    int max_interval;
44    int appearance;
45    uint16_t manufacturer_len;
46    uint8_t* p_manufacturer_data;
47    uint16_t service_data_len;
48    uint8_t* p_service_data;
49    uint16_t service_uuid_len;
50    uint8_t* p_service_uuid;
51} btif_adv_data_t;
52
53typedef struct
54{
55    BOOLEAN is_scan_rsp;
56    UINT8 client_if;
57    UINT16 service_uuid_len;
58    tBTA_BLE_AD_MASK mask;
59    tBTA_BLE_ADV_DATA data;
60    tBTA_BLE_ADV_PARAMS param;
61    TIMER_LIST_ENT tle_limited_timer;
62    int timeout_s;
63}btgatt_multi_adv_inst_cb;
64
65typedef struct
66{
67     INT8 *clntif_map;
68    // Includes the stored data for standard LE instance
69    btgatt_multi_adv_inst_cb *inst_cb;
70
71} btgatt_multi_adv_common_data;
72
73extern btgatt_multi_adv_common_data *btif_obtain_multi_adv_data_cb();
74extern void btif_gattc_incr_app_count(void);
75extern void btif_gattc_decr_app_count(void);
76extern int btif_multi_adv_add_instid_map(int client_if, int inst_id,
77        BOOLEAN gen_temp_instid);
78extern int btif_multi_adv_instid_for_clientif(int client_if);
79extern int btif_gattc_obtain_idx_for_datacb(int value, int clnt_inst_index);
80extern void btif_gattc_clear_clientif(int client_if, BOOLEAN stop_timer);
81extern void btif_gattc_cleanup_inst_cb(int inst_id, BOOLEAN stop_timer);
82extern void btif_gattc_cleanup_multi_inst_cb(btgatt_multi_adv_inst_cb *p_inst_cb,
83                                                    BOOLEAN stop_timer);
84// Free a buffer and reset *buf to NULL.
85extern void btif_gattc_cleanup(void** buf);
86extern BOOLEAN btif_gattc_copy_datacb(int arrindex, const btif_adv_data_t *p_adv_data,
87                                            BOOLEAN bInstData);
88extern void btif_gattc_adv_data_packager(int client_if, bool set_scan_rsp,
89                bool include_name, bool include_txpower, int min_interval, int max_interval,
90                int appearance, int manufacturer_len, char* manufacturer_data,
91                int service_data_len, char* service_data, int service_uuid_len,
92                char* service_uuid, btif_adv_data_t *p_multi_adv_inst);
93extern void btif_gattc_adv_data_cleanup(const btif_adv_data_t* adv);
94void btif_multi_adv_timer_ctrl(int client_if, TIMER_CBACK cb);
95#endif
96
97
98