1 /* ****************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
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
32 #ifndef TZ_BLE_UTIL_H_
33 #define TZ_BLE_UTIL_H_
35 #include <bluetooth.h>
45 typedef struct _LEDataList
48 struct _LEDataList *next;
53 LE_STATUS_INVALID = 0,
54 LE_STATUS_UNICAST_PENDING,
56 LE_STATUS_CONNECTION_INITIATED,
58 LE_STATUS_SERVICES_DISCOVERED
64 bt_gatt_client_h clientHandle;
65 bt_gatt_h serviceHandle;
69 LEDataList *pendingDataList;
71 LEDeviceStatus status;
74 typedef struct _LEServerInfoList
76 LEServerInfo *serverInfo;
77 struct _LEServerInfoList *next;
80 typedef struct _LEClientInfoList
83 struct _LEClientInfoList *next;
87 * Different characteristics types.
89 * This provides information of different characteristics
90 * which will be added to OIC service.
94 BLE_GATT_WRITE_CHAR = 0, /**< write_char This will be used to get the unicast response. */
95 BLE_GATT_READ_CHAR, /**< read_char This will be used update value to OIC server. */
96 BLE_GATT_NOTIFY_CHAR /**< Reserved char for the time being. */
100 * Used to increment the registered service count.
102 CAResult_t CAAddLEDataToList(LEDataList **dataList, const void *data, uint32_t dataLength);
104 * Used to decrement the registered service count.
107 void CARemoveLEDataFromList(LEDataList **dataList);
109 * Used to reset the registered service count.
112 void CADestroyLEDataList(LEDataList **dataList);
114 * Used to get the total registered service count.
115 * @return Total registered service count.
118 void CADestroyLEData(LEData *data);
120 * Used to add the serverListInfo structure to the Server List.
122 * @param[in] serverList Pointer to the ble server list which holds the info of list of
123 * servers registered by the client.
124 * @param[in] leServerInfo Pointer where serverInfo structure needs to be appended with
126 * @return ::CA_STATUS_OK or Appropriate error code.
127 * @retval ::CA_STATUS_OK Successful.
128 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
129 * @retval ::CA_STATUS_FAILED Operation failed.
131 CAResult_t CAAddLEServerInfoToList(LEServerInfoList **serverList,
132 LEServerInfo *leServerInfo);
135 * Used to remove the serverListInfo structure from the Server List.
137 * @param[in,out] serverList Pointer to the ble server list which holds the info of list of
138 * servers registered by the client.
139 * @param[in] remoteAddress Remote address to be removed from the client list.
141 void CARemoveLEServerInfoFromList(LEServerInfoList **serverList,
142 const char *remoteAddress);
145 * Used to get the serviceInfo from the list.
147 * @param[in] serverList Pointer to the ble service list which holds the info of list
148 * of servers registered by the client.
149 * @param[in] leAddress BD address of the device where GATTServer information is required.
150 * @param[out] leServerInfo Info of service and characteristic handle of the given BD address
151 * registered by client.
152 * @return ::CA_STATUS_OK or Appropriate error code.
153 * @retval ::CA_STATUS_OK Successful.
154 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
155 * @retval ::CA_STATUS_FAILED Operation failed.
157 CAResult_t CAGetLEServerInfo(LEServerInfoList *serverList, const char *leAddress,
158 LEServerInfo **leServerInfo);
161 * Used to get the clientInfo from the list by position.
163 * @param[in] serverList Pointer to the ble service list which holds the info of list
164 * of servers registered by the client.
165 * @param[in] position The service information of particular position in the list.
166 * @param[out] leServerInfo Info of service and characteristic handle of the given BD address
167 * registered by client.
168 * @return ::CA_STATUS_OK or Appropriate error code.
169 * @retval ::CA_STATUS_OK Successful.
170 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
171 * @retval ::CA_STATUS_FAILED Operation failed.
176 * Used to clear BLE service list.
178 * @param[in] serverList Pointer to the ble service list which holds the info of list of
179 * servers registered by the client.
181 void CAFreeLEServerList(LEServerInfoList *serverList);
184 * @brief Used to get remove particular BLE service info from list
185 * @param[in] bleServerInfo Pointer to the structure which needs to be cleared.
187 void CAFreeLEServerInfo(LEServerInfo *bleServerInfo);
190 * Used to add the client address to the Client List.
192 * @param[in] clientList Pointer to the ble client list which holds the info of list of
193 * clients connected to the server.
194 * @param[in] clientAddress Client remote address.
195 * @return ::CA_STATUS_OK or Appropriate error code.
196 * @retval ::CA_STATUS_OK Successful.
197 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
198 * @retval ::CA_STATUS_FAILED Operation failed.
200 CAResult_t CAAddLEClientInfoToList(LEClientInfoList **clientList,
201 char *clientAddress);
204 * Used to remove the client address from the Client List.
206 * @param[in,out] clientList Pointer to the ble client list which holds the info of list of
207 * clients connected by the server.
208 * @param[in] clientAddress Remote address to be removed from the client list.
210 void CARemoveLEClientInfoFromList(LEClientInfoList **clientList,
211 const char *clientAddress);
214 * Used to check if client address is present in the list.
216 * @param[in] clientList Pointer to the ble client list which holds the info of list of
217 * clients connected by the server.
218 * @param[in] clientAddress Remote address to be searched in the client list.
219 * @return ::CA_STATUS_OK if client address is found in the list, otherwise CA_STATUS_FAILED.
221 CAResult_t CAIsLEClientInfoInList(LEClientInfoList *clientList,
222 const char *clientAddress);
225 * Used to disconnect all the clients connected to the server.
227 * @param[in,out] clientList Pointer to the ble client list which holds the info of list of
228 * clients connected by the server.
230 void CADisconnectAllClient(LEClientInfoList *clientList);
233 * Used to get the Error message.
234 * @param[in] err Error code(::bt_error_e).
235 * @return Error string corresponding to the BT error code.
237 const char *CALEGetErrorMsg(bt_error_e err);
239 #endif /* TZ_BLE_UTIL_H_ */