7bd4ed0cd2ccb8ec81f0851e3d136a5f96b0d116
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / tizen / caleutil.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 typedef struct
40 {
41     void *data;
42     uint32_t dataLength;
43 } LEData;
44
45 typedef struct _LEDataList
46 {
47     LEData *data;
48     struct _LEDataList *next;
49 } LEDataList;
50
51 typedef enum
52 {
53     LE_STATUS_INVALID = 0,
54     LE_STATUS_UNICAST_PENDING,
55     LE_STATUS_DISCOVERED,
56     LE_STATUS_CONNECTION_INITIATED,
57     LE_STATUS_CONNECTED,
58     LE_STATUS_SERVICES_DISCOVERED
59 } LEDeviceStatus;
60
61
62 typedef struct
63 {
64     bt_gatt_client_h clientHandle;
65     bt_gatt_h serviceHandle;
66     bt_gatt_h readChar;
67     bt_gatt_h writeChar;
68     char *remoteAddress;
69     LEDataList *pendingDataList;
70     uint16_t mtu_size;
71     LEDeviceStatus status;
72 } LEServerInfo;
73
74 typedef struct _LEServerInfoList
75 {
76     LEServerInfo *serverInfo;
77     struct _LEServerInfoList *next;
78 } LEServerInfoList;
79
80 typedef struct _LEClientInfoList
81 {
82     char *remoteAddress;
83     uint16_t mtuSize;
84     struct _LEClientInfoList *next;
85 } LEClientInfoList;
86
87 /**
88  * Different characteristics types.
89  *
90  * This provides information of different characteristics
91  * which will be added to OIC service.
92  */
93 typedef enum
94 {
95     BLE_GATT_WRITE_CHAR = 0, /**< write_char This will be used to get the unicast response. */
96     BLE_GATT_READ_CHAR,      /**< read_char This will be used update value to OIC server. */
97     BLE_GATT_NOTIFY_CHAR     /**< Reserved char for the time being. */
98 } CHAR_TYPE;
99
100 /**
101  * Used to increment the registered service count.
102  */
103 CAResult_t CAAddLEDataToList(LEDataList **dataList, const void *data, uint32_t dataLength);
104 /**
105  * Used to decrement the registered service count.
106  */
107
108 void CARemoveLEDataFromList(LEDataList **dataList);
109 /**
110  * Used to reset the registered service count.
111  */
112
113 void CADestroyLEDataList(LEDataList **dataList);
114 /**
115  * Used to get the total registered service count.
116  * @return  Total registered service count.
117  */
118
119 void CADestroyLEData(LEData *data);
120 /**
121  * Used to add the serverListInfo structure to the Server List.
122  *
123  * @param[in] serverList     Pointer to the ble server list which holds the info of list of
124  *                           servers registered by the client.
125  * @param[in] leServerInfo   Pointer where serverInfo structure needs to be appended with
126  *                           serverList.
127  * @return ::CA_STATUS_OK or Appropriate error code.
128  * @retval ::CA_STATUS_OK  Successful.
129  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
130  * @retval ::CA_STATUS_FAILED Operation failed.
131  */
132 CAResult_t CAAddLEServerInfoToList(LEServerInfoList **serverList,
133                                    LEServerInfo *leServerInfo);
134
135 /**
136  * Used to remove the serverListInfo structure from the Server List.
137  *
138  * @param[in,out] serverList     Pointer to the ble server list which holds the info of list of
139  *                               servers registered by the client.
140  * @param[in]     remoteAddress  Remote address to be removed from the client list.
141  */
142 void CARemoveLEServerInfoFromList(LEServerInfoList **serverList,
143                                         const char *remoteAddress);
144
145 /**
146  * Used to get the serviceInfo from the list.
147  *
148  * @param[in]  serverList       Pointer to the ble service list which holds the info of list
149  *                              of servers registered by the client.
150  * @param[in]  leAddress        BD address of the device where GATTServer information is required.
151  * @param[out] leServerInfo     Info of service and characteristic handle of the given BD address
152  *                              registered by client.
153  * @return ::CA_STATUS_OK or Appropriate error code.
154  * @retval ::CA_STATUS_OK  Successful.
155  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
156  * @retval ::CA_STATUS_FAILED Operation failed.
157  */
158 CAResult_t CAGetLEServerInfo(LEServerInfoList *serverList, const char *leAddress,
159                              LEServerInfo **leServerInfo);
160
161 /**
162  * Used to get the clientInfo from the list by position.
163  *
164  * @param[in]  serverList      Pointer to the ble service list which holds the info of list
165  *                             of servers registered by the client.
166  * @param[in]  position        The service information of particular position in the list.
167  * @param[out] leServerInfo    Info of service and characteristic handle of the given BD address
168  *                              registered by client.
169  * @return ::CA_STATUS_OK or Appropriate error code.
170  * @retval ::CA_STATUS_OK  Successful.
171  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
172  * @retval ::CA_STATUS_FAILED Operation failed.
173  */
174
175
176 /**
177  * Used to clear BLE service list.
178  *
179  * @param[in]  serverList   Pointer to the ble service list which holds the info of list of
180  *                          servers registered by the client.
181  */
182 void CAFreeLEServerList(LEServerInfoList *serverList);
183
184 /**
185  * @brief Used to get remove particular BLE service info from list
186  * @param[in] bleServerInfo Pointer to the structure which needs to be cleared.
187  */
188 void CAFreeLEServerInfo(LEServerInfo *bleServerInfo);
189
190 /**
191  * Used to add the client address to the Client List.
192  *
193  * @param[in] clientList     Pointer to the ble client list which holds the info of list of
194  *                           clients connected to the server.
195  * @param[in] clientAddress  Client remote address.
196  * @return ::CA_STATUS_OK or Appropriate error code.
197  * @retval ::CA_STATUS_OK  Successful.
198  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
199  * @retval ::CA_STATUS_FAILED Operation failed.
200  */
201 CAResult_t CAAddLEClientInfoToList(LEClientInfoList **clientList,
202                                    char *clientAddress);
203
204 /**
205  * Used to remove the client address from the Client List.
206  *
207  * @param[in,out] clientList     Pointer to the ble client list which holds the info of list of
208  *                               clients connected by the server.
209  * @param[in]     clientAddress  Remote address to be removed from the client list.
210  */
211 void CARemoveLEClientInfoFromList(LEClientInfoList **clientList,
212                                         const char *clientAddress);
213
214 /**
215  * Used to check if client address is present in the list.
216  *
217  * @param[in]    clientList     Pointer to the ble client list which holds the info of list of
218  *                              clients connected by the server.
219  * @param[in]    clientAddress  Remote address to be searched in the client list.
220  * @return ::CA_STATUS_OK if client address is found in the list, otherwise CA_STATUS_FAILED.
221  */
222 CAResult_t CAIsLEClientInfoInList(LEClientInfoList *clientList,
223                                         const char *clientAddress);
224
225 /**
226  * Used to disconnect all the clients connected to the server.
227  *
228  * @param[in,out] clientList     Pointer to the ble client list which holds the info of list of
229  *                               clients connected by the server.
230  */
231 void CADisconnectAllClient(LEClientInfoList *clientList);
232
233 /**
234  * Used to get the Error message.
235  * @param[in] err   Error code(::bt_error_e).
236  * @return  Error string corresponding to the BT error code.
237  */
238 const char *CALEGetErrorMsg(bt_error_e err);
239
240 uint16_t CAClientInfoGetMTUSize(LEClientInfoList *clientList, const char *clientAddress);
241
242 CAResult_t CAClientInfoUpdateMTUSize(LEClientInfoList *clientList, const char *clientAddress, uint16_t mtu_size);
243
244 #endif /* TZ_BLE_UTIL_H_ */