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