Imported Upstream version 1.0.0
[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  * Information regarding the GATTServer.
41  *
42  * This structure holds the infomation about the GATTServer
43  * in the service and the characteristic level.
44  */
45 typedef struct
46 {
47     bt_gatt_attribute_h service_clone; /**< GATT attribute handler for the OIC service. */
48     bt_gatt_attribute_h read_char;     /**< GATT attribute handler for OIC read characteristic.
49                                             Server will read.*/
50     bt_gatt_attribute_h write_char;    /**< GATT attribute handler for OIC write characteristic.
51                                             server will write*/
52     char *bdAddress;                   /**< BD address where OIC service is running. */
53 } BLEServiceInfo;
54
55 /**
56  * List of the BLEServiceInfo structures.
57  *
58  * A list of BLEServiceInfo and gives the info about all the
59  * the registered services from the client side.
60  */
61 typedef struct _BLEServiceList
62 {
63     BLEServiceInfo *serviceInfo;    /**< BLEServiceInfo structure from an OIC Server. */
64     struct _BLEServiceList *next;   /**< Next reference to the List. */
65 } BLEServiceList;
66
67 /**
68  * Different characteristics types.
69  *
70  * This provides information of different characteristics
71  * which will be added to OIC service.
72  */
73 typedef enum
74 {
75     BLE_GATT_WRITE_CHAR = 0, /**< write_char This will be used to get the unicast response. */
76     BLE_GATT_READ_CHAR,      /**< read_char This will be used update value to OIC server. */
77     BLE_GATT_NOTIFY_CHAR     /**< Reserved char for the time being. */
78 } CHAR_TYPE;
79
80 /**
81  * Stores the information required to set the descriptor value of the Service.
82  */
83 typedef struct gattCharDescriptor
84 {
85     bt_gatt_attribute_h characteristic; /**< The attribute handle of descriptor. */
86     uint8_t *desc;                      /**< Descriptor handle of characteristic, in byte array. */
87     int total;                          /**< The total number of descriptor in a characteristic. */
88 } stGattCharDescriptor_t;
89
90 /**
91  * Used to increment the registered service count.
92  */
93 void CAIncrementRegisteredServiceCount();
94
95 /**
96  * Used to decrement the registered service count.
97  */
98 void CADecrementRegisteredServiceCount();
99
100 /**
101  * Used to reset the registered service count.
102  */
103 void CAResetRegisteredServiceCount();
104
105 /**
106  * Used to get the total registered service count.
107  * @return  Total registered service count.
108  */
109 int32_t  CAGetRegisteredServiceCount();
110
111 /**
112  * Used to create BLEServiceInfo structure with server handler and BD address will be
113  * created.
114  * @param[in] bdAddress        BD address of the device where GATTServer is running.
115  * @param[in] service          service attribute handler.
116  * @param[in] bleServiceInfo   Pointer where serviceInfo structure needs to be stored.
117  *                             Memory will be allocated here and needs to be cleared by caller.
118  * @return ::CA_STATUS_OK or Appropriate error code.
119  * @retval ::CA_STATUS_OK  Successful.
120  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
121  * @retval ::CA_STATUS_FAILED Operation failed.
122  */
123 CAResult_t CACreateBLEServiceInfo(const char *bdAddress, bt_gatt_attribute_h service,
124                                   BLEServiceInfo **bleServiceInfo);
125
126 /**
127  * Used to append the characteristic info to the already created serviceInfo structure.
128  *
129  * @param[in] characteristic   Charecteristic attribute handler.
130  * @param[in] type             Specifies whether its BLE_GATT_READ_CHAR or BLE_GATT_WRITE_CHAR
131  * @param[in] bleServiceInfo   Pointer where serviceInfo structure needs to be appended with
132  *                             char info.
133  * @return ::CA_STATUS_OK or Appropriate error code.
134  * @retval ::CA_STATUS_OK  Successful.
135  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
136  * @retval ::CA_STATUS_FAILED Operation failed.
137  */
138 CAResult_t CAAppendBLECharInfo(bt_gatt_attribute_h characteristic, CHAR_TYPE type,
139                                BLEServiceInfo *bleServiceInfo);
140
141 /**
142  * Used to add the ServiceInfo structure to the Service List.
143  *
144  * @param[in] serviceList      Pointer to the ble service list which holds the info of list of
145  *                             service registered from client.
146  * @param[in] bleServiceInfo   Pointer where serviceInfo structure needs to be appended with
147  *                             char info.
148  * @return ::CA_STATUS_OK or Appropriate error code.
149  * @retval ::CA_STATUS_OK  Successful.
150  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
151  * @retval ::CA_STATUS_FAILED Operation failed.
152  */
153 CAResult_t CAAddBLEServiceInfoToList(BLEServiceList **serviceList,
154                 BLEServiceInfo *bleServiceInfo);
155
156 /**
157  * Used to remove the ServiceInfo structure from the Service List.
158  *
159  * @param[in] serviceList      Pointer to the ble service list which holds the info of list of
160  *                             service registered from client.
161  * @param[in] bleServiceInfo   Pointer where serviceInfo structure needs to be appended with
162  *                             char info.
163  * @param[in] bdAddress        BD address of the device where GATTServer is disconnected.
164  *
165  * @return ::CA_STATUS_OK or Appropriate error code.
166  * @retval ::CA_STATUS_OK  Successful.
167  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
168  * @retval ::CA_STATUS_FAILED Operation failed.
169  */
170 CAResult_t CARemoveBLEServiceInfoToList(BLEServiceList **serviceList,
171                                         BLEServiceInfo *bleServiceInfo,
172                                         const char *bdAddress);
173
174 /**
175  * Used to get the serviceInfo from the list.
176  *
177  * @param[in] serviceList       Pointer to the ble service list which holds the info of list
178  *                              of service registered from client.
179  * @param[in] bdAddress         BD address of the device where GATTServer information is required.
180  * @param[out] bleServiceInfo   Pointer where serviceInfo structure needs to provide the service
181  *                              and char info.
182  * @return ::CA_STATUS_OK or Appropriate error code.
183  * @retval ::CA_STATUS_OK  Successful.
184  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
185  * @retval ::CA_STATUS_FAILED Operation failed.
186  */
187 CAResult_t CAGetBLEServiceInfo(BLEServiceList *serviceList, const char *bdAddress,
188                                BLEServiceInfo **bleServiceInfo);
189
190 /**
191  * Used to get the serviceInfo from the list by position.
192  *
193  * @param[in] serviceList      Pointer to the ble service list which holds the info of list
194  *                             of service registered from client.
195  * @param[in] position         The service information of particular position in the list.
196  * @param[out] bleServiceInfo  Pointer where serviceInfo structure needs to provide the service
197  *                             and char info.
198  * @return ::CA_STATUS_OK or Appropriate error code.
199  * @retval ::CA_STATUS_OK  Successful.
200  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
201  * @retval ::CA_STATUS_FAILED Operation failed.
202  */
203 CAResult_t CAGetBLEServiceInfoByPosition(BLEServiceList *serviceList, int32_t position,
204                                          BLEServiceInfo **bleServiceInfo);
205
206 /**
207  * Used to clear BLE service list.
208  *
209  * @param[in]  serviceList   Pointer to the ble service list which holds the info of list of
210  *                           service registered from client.
211  */
212 void CAFreeBLEServiceList(BLEServiceList *serviceList);
213
214 /**
215  * Used to get remove particular BLE service info from list.
216  * @param[in] serviceinfo   Pointer to the structure which needs to be cleared.
217  */
218 void CAFreeBLEServiceInfo(BLEServiceInfo *bleServiceInfo);
219
220 /**
221  * Used to check whether found handle is OIC service handle or not.
222  *
223  * @param[in] serviceHandle   Discovered service handle(unique identifier for service).
224  * @return  STATUS_OK or Appropriate error code.
225  * @retval ::CA_STATUS_OK  Successful.
226  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
227  * @retval ::CA_STATUS_FAILED Operation failed.
228  */
229 CAResult_t CAVerifyOICServiceByServiceHandle(bt_gatt_attribute_h serviceHandle);
230
231 /**
232  * Used to check whether UUID of the discovered device is OIC service or not.
233  *
234  * @param[in]  serviceUUID   Service UUID.
235  * @return ::CA_STATUS_OK or Appropriate error code.
236  * @retval ::CA_STATUS_OK  Successful.
237  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
238  * @retval ::CA_STATUS_FAILED Operation failed.
239  */
240 CAResult_t CAVerifyOICServiceByUUID(const char* serviceUUID);
241
242 /**
243  * Used to get the Error message.
244  * @param[in] err   Error code(::bt_error_e).
245  * @return  Error string corresponding to the BT error code.
246  */
247 const char *CABTGetErrorMsg(bt_error_e err);
248
249 #endif /* TZ_BLE_UTIL_H_ */