ed51602d8a00a97a1abf274c0a0803e74bdfd4d5
[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     bt_gatt_client_h clientHandle;
42     bt_gatt_h serviceHandle;
43     bt_gatt_h readChar;
44     bt_gatt_h writeChar;
45     char *remoteAddress;
46 } LEServerInfo;
47
48 typedef struct _LEServerInfoList
49 {
50     LEServerInfo *serverInfo;
51     struct _LEServerInfoList *next;
52 }LEServerInfoList;
53
54 typedef struct _LEClientInfoList
55 {
56     char *remoteAddress;
57     struct _LEClientInfoList *next;
58 } LEClientInfoList;
59
60 /**
61  * Different characteristics types.
62  *
63  * This provides information of different characteristics
64  * which will be added to OIC service.
65  */
66 typedef enum
67 {
68     BLE_GATT_WRITE_CHAR = 0, /**< write_char This will be used to get the unicast response. */
69     BLE_GATT_READ_CHAR,      /**< read_char This will be used update value to OIC server. */
70     BLE_GATT_NOTIFY_CHAR     /**< Reserved char for the time being. */
71 } CHAR_TYPE;
72
73 /**
74  * Used to increment the registered service count.
75  */
76 void CAIncrementRegisteredServiceCount();
77
78 /**
79  * Used to decrement the registered service count.
80  */
81 void CADecrementRegisteredServiceCount();
82
83 /**
84  * Used to reset the registered service count.
85  */
86 void CAResetRegisteredServiceCount();
87
88 /**
89  * Used to get the total registered service count.
90  * @return  Total registered service count.
91  */
92 int32_t  CAGetRegisteredServiceCount();
93
94 /**
95  * Used to add the serverListInfo structure to the Server List.
96  *
97  * @param[in] serverList     Pointer to the ble server list which holds the info of list of
98  *                           servers registered by the client.
99  * @param[in] leServerInfo   Pointer where serverInfo structure needs to be appended with
100  *                           serverList.
101  * @return ::CA_STATUS_OK or Appropriate error code.
102  * @retval ::CA_STATUS_OK  Successful.
103  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
104  * @retval ::CA_STATUS_FAILED Operation failed.
105  */
106 CAResult_t CAAddLEServerInfoToList(LEServerInfoList **serverList,
107                                    LEServerInfo *leServerInfo);
108
109 /**
110  * Used to remove the serverListInfo structure from the Server List.
111  *
112  * @param[in,out] serverList     Pointer to the ble server list which holds the info of list of
113  *                               servers registered by the client.
114  * @param[in]     remoteAddress  Remote address to be removed from the client list.
115  */
116 void CARemoveLEServerInfoFromList(LEServerInfoList **serverList,
117                                         const char *remoteAddress);
118
119 /**
120  * Used to get the serviceInfo from the list.
121  *
122  * @param[in]  serverList       Pointer to the ble service list which holds the info of list
123  *                              of servers registered by the client.
124  * @param[in]  leAddress        BD address of the device where GATTServer information is required.
125  * @param[out] leServerInfo     Info of service and characteristic handle of the given BD address
126  *                              registered by client.
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 CAGetLEServerInfo(LEServerInfoList *serverList, const char *leAddress,
133                              LEServerInfo **leServerInfo);
134
135 /**
136  * Used to get the clientInfo from the list by position.
137  *
138  * @param[in]  serverList      Pointer to the ble service list which holds the info of list
139  *                             of servers registered by the client.
140  * @param[in]  position        The service information of particular position in the list.
141  * @param[out] leServerInfo    Info of service and characteristic handle of the given BD address
142  *                              registered by client.
143  * @return ::CA_STATUS_OK or Appropriate error code.
144  * @retval ::CA_STATUS_OK  Successful.
145  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
146  * @retval ::CA_STATUS_FAILED Operation failed.
147  */
148 CAResult_t CAGetLEServerInfoByPosition(LEServerInfoList *serverList, int32_t position,
149                                        LEServerInfo **leServerInfo);
150
151 /**
152  * Used to clear BLE service list.
153  *
154  * @param[in]  serverList   Pointer to the ble service list which holds the info of list of
155  *                          servers registered by the client.
156  */
157 void CAFreeLEServerList(LEServerInfoList *serverList);
158
159 /**
160  * @brief Used to get remove particular BLE service info from list
161  * @param[in] bleServerInfo Pointer to the structure which needs to be cleared.
162  */
163 void CAFreeLEServerInfo(LEServerInfo *bleServerInfo);
164
165 /**
166  * Used to add the client address to the Client List.
167  *
168  * @param[in] clientList     Pointer to the ble client list which holds the info of list of
169  *                           clients connected to the server.
170  * @param[in] clientAddress  Client remote address.
171  * @return ::CA_STATUS_OK or Appropriate error code.
172  * @retval ::CA_STATUS_OK  Successful.
173  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
174  * @retval ::CA_STATUS_FAILED Operation failed.
175  */
176 CAResult_t CAAddLEClientInfoToList(LEClientInfoList **clientList,
177                                    char *clientAddress);
178
179 /**
180  * Used to remove the client address from the Client List.
181  *
182  * @param[in,out] clientList     Pointer to the ble client list which holds the info of list of
183  *                               clients connected by the server.
184  * @param[in]     clientAddress  Remote address to be removed from the client list.
185  */
186 void CARemoveLEClientInfoFromList(LEClientInfoList **clientList,
187                                         const char *clientAddress);
188
189 /**
190  * Used to disconnect all the clients connected to the server.
191  *
192  * @param[in,out] clientList     Pointer to the ble client list which holds the info of list of
193  *                               clients connected by the server.
194  */
195 void CADisconnectAllClient(LEClientInfoList *clientList);
196
197 /**
198  * Used to get the Error message.
199  * @param[in] err   Error code(::bt_error_e).
200  * @return  Error string corresponding to the BT error code.
201  */
202 const char *CALEGetErrorMsg(bt_error_e err);
203
204 #endif /* TZ_BLE_UTIL_H_ */