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 } tDIS_PNP_ID;
63 
64 typedef union {
65   uint64_t system_id;
66   tDIS_PNP_ID pnp_id;
67   tDIS_STRING data_str;
68 } tDIS_ATTR;
69 
70 #define DIS_MAX_STRING_DATA 7
71 
72 typedef struct {
73   uint16_t attr_mask;
74   uint64_t system_id;
75   tDIS_PNP_ID pnp_id;
76   uint8_t* data_string[DIS_MAX_STRING_DATA];
77 } tDIS_VALUE;
78 
79 typedef void(tDIS_READ_CBACK)(const RawAddress& addr, tDIS_VALUE* p_dis_value);
80 
81 /*****************************************************************************
82  *  Data structure used by Battery Service
83  ****************************************************************************/
84 typedef struct {
85   RawAddress remote_bda;
86   bool need_rsp;
87   uint16_t clt_cfg;
88 } tBA_WRITE_DATA;
89 
90 #define BA_READ_CLT_CFG_REQ 1
91 #define BA_READ_PRE_FMT_REQ 2
92 #define BA_READ_RPT_REF_REQ 3
93 #define BA_READ_LEVEL_REQ 4
94 #define BA_WRITE_CLT_CFG_REQ 5
95 
96 typedef void(tBA_CBACK)(uint8_t app_id, uint8_t event, tBA_WRITE_DATA* p_data);
97 
98 #define BA_LEVEL_NOTIFY 0x01
99 #define BA_LEVEL_PRE_FMT 0x02
100 #define BA_LEVEL_RPT_REF 0x04
101 typedef uint8_t tBA_LEVEL_DESCR;
102 
103 typedef struct {
104   bool is_pri;
105   tBA_LEVEL_DESCR ba_level_descr;
106   tBT_TRANSPORT transport;
107   tBA_CBACK* p_cback;
108 } tBA_REG_INFO;
109 
110 typedef 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  ******************************************************************************/
131 tGATT_STATUS srvc_eng_init(void);
132 
133 /*****************************************************************************
134  *  DIS Client Function
135  ****************************************************************************/
136 /*******************************************************************************
137  *
138  * Function         DIS_ReadDISInfo
139  *
140  * Description      Read remote device DIS information.
141  *
142  * Returns          void
143  *
144  ******************************************************************************/
145 bool DIS_ReadDISInfo(const RawAddress& peer_bda, tDIS_READ_CBACK* p_cback, tDIS_ATTR_MASK mask);
146 
147 #endif
148