1/******************************************************************************
2 *
3 *  Copyright 1999-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#ifndef SRVC_DIS_API_H
20#define SRVC_DIS_API_H
21
22#include "bt_target.h"
23#include "gatt_api.h"
24#include "gattdefs.h"
25
26#define DIS_SUCCESS GATT_SUCCESS
27#define DIS_ILLEGAL_PARAM GATT_ILLEGAL_PARAMETER
28#define DIS_NO_RESOURCES GATT_NO_RESOURCES
29typedef uint8_t tDIS_STATUS;
30
31/*****************************************************************************
32 *  Data structure for DIS
33 ****************************************************************************/
34
35#define DIS_ATTR_SYS_ID_BIT 0x0001
36#define DIS_ATTR_MODEL_NUM_BIT 0x0002
37#define DIS_ATTR_SERIAL_NUM_BIT 0x0004
38#define DIS_ATTR_FW_NUM_BIT 0x0008
39#define DIS_ATTR_HW_NUM_BIT 0x0010
40#define DIS_ATTR_SW_NUM_BIT 0x0020
41#define DIS_ATTR_MANU_NAME_BIT 0x0040
42#define DIS_ATTR_IEEE_DATA_BIT 0x0080
43#define DIS_ATTR_PNP_ID_BIT 0x0100
44typedef uint16_t tDIS_ATTR_MASK;
45
46#define DIS_ATTR_ALL_MASK 0xffff
47
48typedef tDIS_ATTR_MASK tDIS_ATTR_BIT;
49
50typedef struct {
51  uint16_t len;
52  uint8_t* p_data;
53} tDIS_STRING;
54
55typedef struct {
56  uint16_t vendor_id;
57  uint16_t product_id;
58  uint16_t product_version;
59  uint8_t vendor_id_src;
60
61} tDIS_PNP_ID;
62
63typedef union {
64  uint64_t system_id;
65  tDIS_PNP_ID pnp_id;
66  tDIS_STRING data_str;
67} tDIS_ATTR;
68
69#define DIS_MAX_STRING_DATA 7
70
71typedef struct {
72  uint16_t attr_mask;
73  uint64_t system_id;
74  tDIS_PNP_ID pnp_id;
75  uint8_t* data_string[DIS_MAX_STRING_DATA];
76} tDIS_VALUE;
77
78typedef void(tDIS_READ_CBACK)(const RawAddress& addr, tDIS_VALUE* p_dis_value);
79
80/*****************************************************************************
81 *  Data structure used by Battery Service
82 ****************************************************************************/
83typedef struct {
84  RawAddress remote_bda;
85  bool need_rsp;
86  uint16_t clt_cfg;
87} tBA_WRITE_DATA;
88
89#define BA_READ_CLT_CFG_REQ 1
90#define BA_READ_PRE_FMT_REQ 2
91#define BA_READ_RPT_REF_REQ 3
92#define BA_READ_LEVEL_REQ 4
93#define BA_WRITE_CLT_CFG_REQ 5
94
95typedef void(tBA_CBACK)(uint8_t app_id, uint8_t event, tBA_WRITE_DATA* p_data);
96
97#define BA_LEVEL_NOTIFY 0x01
98#define BA_LEVEL_PRE_FMT 0x02
99#define BA_LEVEL_RPT_REF 0x04
100typedef uint8_t tBA_LEVEL_DESCR;
101
102typedef struct {
103  bool is_pri;
104  tBA_LEVEL_DESCR ba_level_descr;
105  tGATT_TRANSPORT transport;
106  tBA_CBACK* p_cback;
107
108} tBA_REG_INFO;
109
110typedef union {
111  uint8_t ba_level;
112  uint16_t clt_cfg;
113  tGATT_CHAR_RPT_REF rpt_ref;
114  tGATT_CHAR_PRES pres_fmt;
115} tBA_RSP_DATA;
116
117/*****************************************************************************
118 *  External Function Declarations
119 ****************************************************************************/
120/*****************************************************************************
121 *  Service Engine API
122 ****************************************************************************/
123/*******************************************************************************
124 *
125 * Function         srvc_eng_init
126 *
127 * Description      Initializa the GATT Service engine, register a GATT
128 *                  application as for a central service management.
129 *
130 ******************************************************************************/
131extern tGATT_STATUS srvc_eng_init(void);
132
133/*****************************************************************************
134 *  DIS Server Function
135 ****************************************************************************/
136
137/*******************************************************************************
138 *
139 * Function         DIS_SrInit
140 *
141 * Description      Initializa the Device Information Service Server.
142 *
143 ******************************************************************************/
144extern tDIS_STATUS DIS_SrInit(tDIS_ATTR_MASK dis_attr_mask);
145/*******************************************************************************
146 *
147 * Function         DIS_SrUpdate
148 *
149 * Description      Update the DIS server attribute values
150 *
151 ******************************************************************************/
152extern tDIS_STATUS DIS_SrUpdate(tDIS_ATTR_BIT dis_attr_bit, tDIS_ATTR* p_info);
153/*****************************************************************************
154 *  DIS Client Function
155 ****************************************************************************/
156/*******************************************************************************
157 *
158 * Function         DIS_ReadDISInfo
159 *
160 * Description      Read remote device DIS information.
161 *
162 * Returns          void
163 *
164 ******************************************************************************/
165extern bool DIS_ReadDISInfo(const RawAddress& peer_bda,
166                            tDIS_READ_CBACK* p_cback, tDIS_ATTR_MASK mask);
167
168/*******************************************************************************
169 *      BATTERY SERVICE API
170 ******************************************************************************/
171/*******************************************************************************
172 *
173 * Function         Battery_Instantiate
174 *
175 * Description      Instantiate a Battery service
176 *
177 ******************************************************************************/
178extern uint16_t Battery_Instantiate(uint8_t app_id, tBA_REG_INFO* p_reg_info);
179
180/*******************************************************************************
181 *
182 * Function         Battery_Rsp
183 *
184 * Description      Respond to a battery service request
185 *
186 ******************************************************************************/
187extern void Battery_Rsp(uint8_t app_id, tGATT_STATUS st, uint8_t event,
188                        tBA_RSP_DATA* p_rsp);
189/*******************************************************************************
190 *
191 * Function         Battery_Notify
192 *
193 * Description      Send battery level notification
194 *
195 ******************************************************************************/
196extern void Battery_Notify(uint8_t app_id, const RawAddress& remote_bda,
197                           uint8_t battery_level);
198
199#endif
200