Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / tizen / cableutil.h
1 /* ****************************************************************
2 *
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
4 *
5 *
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *      http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ******************************************************************/
20
21 /**
22  * @file
23  *
24  * This file contains the util function for LE adapter. This maintains the
25  * list of services an individual GATT Client connected to and operations on
26  * that list, such as getting the service info with BD address or with
27  * position etc. This is mainly useful for the multicast transmission of
28  * data where client needs to have the info of all the services to which it
29  * is connected.
30  */
31
32 #ifndef TZ_BLE_UTIL_H_
33 #define TZ_BLE_UTIL_H_
34
35 #include <bluetooth.h>
36
37 #include "cacommon.h"
38
39 /**
40  * @struct BLEServiceInfo
41  * @brief Information regarding the GATTServer
42  *
43  * This structure holds the infomation about the GATTServer
44  * in the service and the characteristic level
45  */
46 typedef struct
47 {
48     bt_gatt_attribute_h service_clone; /**< GATT attribute handler for the OIC service. */
49     bt_gatt_attribute_h read_char;     /**< GATT attribute handler for OIC read characteristic.
50                                             Server will read.*/
51     bt_gatt_attribute_h write_char;    /**< GATT attribute handler for OIC write characteristic.
52                                             server will write*/
53     char *bdAddress;                   /**< BD address where OIC service is running. */
54 } BLEServiceInfo;
55
56 /**
57  * @struct BLEServiceList
58  * @brief List of the BLEServiceInfo structures.
59  *
60  * A list of BLEServiceInfo and gives the info about all the
61  * the registered services from the client side.
62  */
63 typedef struct _BLEServiceList
64 {
65     BLEServiceInfo *serviceInfo;    /**< BLEServiceInfo structure from an OIC Server */
66     struct _BLEServiceList *next;   /**< Next reference to the List*/
67 } BLEServiceList;
68
69 /**
70  * @enum CHAR_TYPE
71  * @brief Different characteristics types.
72  *
73  *  This provides information of different characteristics
74  *  which will be added to OIC service.
75  */
76 typedef enum
77 {
78     BLE_GATT_WRITE_CHAR = 0, /**< write_char This will be used to get the unicast response */
79     BLE_GATT_READ_CHAR,      /**< read_char This will be used update value to OIC server */
80     BLE_GATT_NOTIFY_CHAR     /**< Reserved char for the time being. */
81 } CHAR_TYPE;
82
83 /**
84  * @struct stGattCharDescriptor_t
85  * @brief Stores the information required to set the descriptor value of the Service.
86  */
87 typedef struct gattCharDescriptor
88 {
89     bt_gatt_attribute_h characteristic; /**< The attribute handle of descriptor */
90     uint8_t *desc;                      /**< Descriptor handle of characteristic, in byte array*/
91     int total;                          /**< The total number of descriptor in a characteristic */
92 } stGattCharDescriptor_t;
93
94 #define OIC_BLE_SERVICE_ID "ADE3D529-C784-4F63-A987-EB69F70EE816"
95 ///TODO: OIC_BLE_SERVICE_ID  will be generated by invoking API in future.
96
97 /**
98  * @def CA_BLE_READ_CHAR_UUID
99  * @brief UUID of read characteristic. This UUID is common across all platform for LE transport.
100  */
101 #define CA_BLE_READ_CHAR_UUID "E9241982-4580-42C4-8831-95048216B256"
102
103 /**
104  * @def CA_BLE_WRITE_CHAR_UUID
105  * @brief UUID of write characteristic. This UUID is common across all platform for LE transport.
106  */
107 #define CA_BLE_WRITE_CHAR_UUID "AD7B334F-4637-4B86-90B6-9D787F03D218"
108
109 /**
110  * @brief  Used to increment the registered service count.
111  * @return NONE
112  */
113 void CAIncrementRegisteredServiceCount();
114
115 /**
116  * @brief  Used to decrement the registered service count.
117  *
118  * @return NONE.
119  */
120 void CADecrementRegisteredServiceCount();
121
122 /**
123  * @brief  Used to reset the registered service count.
124  * @return  NONE
125  */
126 void CAResetRegisteredServiceCount();
127
128 /**
129  * @brief  Used to get the total registered service count.
130  * @return  Total registered service count.
131  */
132 int32_t  CAGetRegisteredServiceCount();
133
134 /**
135  * @brief  Used to create BLEServiceInfo structure with server handler and BD address will be
136  *         created.
137  * @param bdAddress      [IN] BD address of the device where GATTServer is running.
138  * @param service        [IN] service attribute handler.
139  * @param bleServiceInfo [IN] Pointer where serviceInfo structure needs to be stored.
140  *                            Memory will be allocated here and needs to be cleared by caller.
141  * @return #CA_STATUS_OK or Appropriate error code
142  * @retval #CA_STATUS_OK  Successful
143  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
144  * @retval #CA_STATUS_FAILED Operation failed
145  */
146 CAResult_t CACreateBLEServiceInfo(const char *bdAddress, bt_gatt_attribute_h service,
147                                   BLEServiceInfo **bleServiceInfo);
148
149 /**
150  * @brief  Used to append the characteristic info to the already created serviceInfo structure.
151  *
152  * @param characteristic [IN] Charecteristic attribute handler.
153  * @param type           [IN] Specifies whether its BLE_GATT_READ_CHAR or BLE_GATT_WRITE_CHAR
154  * @param bleServiceInfo [IN] Pointer where serviceInfo structure needs to be appended with
155  *                            char info.
156  * @return #CA_STATUS_OK or Appropriate error code
157  * @retval #CA_STATUS_OK  Successful
158  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
159  * @retval #CA_STATUS_FAILED Operation failed
160  */
161 CAResult_t CAAppendBLECharInfo(bt_gatt_attribute_h characteristic, CHAR_TYPE type,
162                                BLEServiceInfo *bleServiceInfo);
163
164 /**
165  * @brief  Used to add the ServiceInfo structure to the Service List.
166  *
167  * @param serviceList    [IN] Pointer to the ble service list which holds the info of list of
168  *                            service registered from client.
169  * @param bleServiceInfo [IN] Pointer where serviceInfo structure needs to be appended with
170  *                            char info.
171  * @return #CA_STATUS_OK or Appropriate error code
172  * @retval #CA_STATUS_OK  Successful
173  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
174  * @retval #CA_STATUS_FAILED Operation failed
175  */
176 CAResult_t CAAddBLEServiceInfoToList(BLEServiceList **serviceList,
177                 BLEServiceInfo *bleServiceInfo);
178
179 /**
180  * @brief  Used to remove the ServiceInfo structure from the Service List.
181  *
182  * @param serviceList    [IN] Pointer to the ble service list which holds the info of list of
183  *                            service registered from client.
184  * @param bleServiceInfo [IN] Pointer where serviceInfo structure needs to be appended with
185  *                            char info.
186  * @param bdAddress      [IN] BD address of the device where GATTServer is disconnected.
187  *
188  * @return #CA_STATUS_OK or Appropriate error code
189  * @retval #CA_STATUS_OK  Successful
190  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
191  * @retval #CA_STATUS_FAILED Operation failed
192  */
193 CAResult_t CARemoveBLEServiceInfoToList(BLEServiceList **serviceList,
194                                         BLEServiceInfo *bleServiceInfo,
195                                         const char *bdAddress);
196
197 /**
198  * @brief  Used to get the serviceInfo from the list.
199  *
200  * @param serviceList    [IN]  Pointer to the ble service list which holds the info of list
201  *                             of service registered from client.
202  * @param bdAddress      [IN]  BD address of the device where GATTServer information is required.
203  * @param bleServiceInfo [OUT] Pointer where serviceInfo structure needs to provide the service
204  *                             and char info.
205  * @return #CA_STATUS_OK or Appropriate error code
206  * @retval #CA_STATUS_OK  Successful
207  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
208  * @retval #CA_STATUS_FAILED Operation failed
209  */
210 CAResult_t CAGetBLEServiceInfo(BLEServiceList *serviceList, const char *bdAddress,
211                                BLEServiceInfo **bleServiceInfo);
212
213 /**
214  * @brief  Used to get the serviceInfo from the list by position.
215  *
216  * @param serviceList    [IN]  Pointer to the ble service list which holds the info of list
217  *                             of service registered from client.
218  * @param position       [IN]  The service information of particular position in the list.
219  * @param bleServiceInfo [OUT] Pointer where serviceInfo structure needs to provide the service
220  *                             and char info.
221  * @return #CA_STATUS_OK or Appropriate error code
222  * @retval #CA_STATUS_OK  Successful
223  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
224  * @retval #CA_STATUS_FAILED Operation failed
225  */
226 CAResult_t CAGetBLEServiceInfoByPosition(BLEServiceList *serviceList, int32_t position,
227                                          BLEServiceInfo **bleServiceInfo);
228
229 /**
230  * @brief  Used to clear BLE service list
231  *
232  * @param  serviceList [IN] Pointer to the ble service list which holds the info of list of
233  *                          service registered from client.
234  * @return NONE
235  */
236 void CAFreeBLEServiceList(BLEServiceList *serviceList);
237
238 /**
239  * @brief Used to get remove particular BLE service info from list
240  * @param serviceinfo [IN] Pointer to the structure which needs to be cleared.
241  *
242  * @return NONE
243  */
244 void CAFreeBLEServiceInfo(BLEServiceInfo *bleServiceInfo);
245
246 /**
247  * @brief  Used to check whether found handle is OIC service handle or not.
248  *
249  * @param serviceHandle [IN] Discovered service handle(unique identifier for service)
250  * @return #CA_STATUS_OK or Appropriate error code
251  * @retval #CA_STATUS_OK  Successful
252  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
253  * @retval #CA_STATUS_FAILED Operation failed
254  */
255 CAResult_t CAVerifyOICServiceByServiceHandle(bt_gatt_attribute_h serviceHandle);
256
257 /**
258  * @brief  Used to check whether UUID of the discovered device is OIC service or not.
259  *
260  * @param  serviceUUID [IN] Service UUID
261  * @return #CA_STATUS_OK or Appropriate error code
262  * @retval #CA_STATUS_OK  Successful
263  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
264  * @retval #CA_STATUS_FAILED Operation failed
265  */
266 CAResult_t CAVerifyOICServiceByUUID(const char* serviceUUID);
267
268 /**
269  * @brief  Used to get the Error message.
270  * @param err [IN] Error code(#bt_error_e)
271  * @return  Error string corresponding to the BT error code.
272  */
273 const char *CABTGetErrorMsg(bt_error_e err);
274
275 #endif /* TZ_BLE_UTIL_H_ */