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>
40 * @struct BLEServiceInfo
41 * @brief Information regarding the GATTServer
43 * This structure holds the infomation about the GATTServer
44 * in the service and the characteristic level
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.
51 bt_gatt_attribute_h write_char; /**< GATT attribute handler for OIC write characteristic.
53 char *bdAddress; /**< BD address where OIC service is running. */
57 * @struct BLEServiceList
58 * @brief List of the BLEServiceInfo structures.
60 * A list of BLEServiceInfo and gives the info about all the
61 * the registered services from the client side.
63 typedef struct _BLEServiceList
65 BLEServiceInfo *serviceInfo; /**< BLEServiceInfo structure from an OIC Server */
66 struct _BLEServiceList *next; /**< Next reference to the List*/
71 * @brief Different characteristics types.
73 * This provides information of different characteristics
74 * which will be added to OIC service.
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. */
84 * @struct stGattCharDescriptor_t
85 * @brief Stores the information required to set the descriptor value of the Service.
87 typedef struct gattCharDescriptor
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;
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.
98 * @def CA_BLE_READ_CHAR_UUID
99 * @brief UUID of read characteristic. This UUID is common across all platform for LE transport.
101 #define CA_BLE_READ_CHAR_UUID "E9241982-4580-42C4-8831-95048216B256"
104 * @def CA_BLE_WRITE_CHAR_UUID
105 * @brief UUID of write characteristic. This UUID is common across all platform for LE transport.
107 #define CA_BLE_WRITE_CHAR_UUID "AD7B334F-4637-4B86-90B6-9D787F03D218"
110 * @brief Used to increment the registered service count.
113 void CAIncrementRegisteredServiceCount();
116 * @brief Used to decrement the registered service count.
120 void CADecrementRegisteredServiceCount();
123 * @brief Used to reset the registered service count.
126 void CAResetRegisteredServiceCount();
129 * @brief Used to get the total registered service count.
130 * @return Total registered service count.
132 int32_t CAGetRegisteredServiceCount();
135 * @brief Used to create BLEServiceInfo structure with server handler and BD address will be
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
146 CAResult_t CACreateBLEServiceInfo(const char *bdAddress, bt_gatt_attribute_h service,
147 BLEServiceInfo **bleServiceInfo);
150 * @brief Used to append the characteristic info to the already created serviceInfo structure.
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
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
161 CAResult_t CAAppendBLECharInfo(bt_gatt_attribute_h characteristic, CHAR_TYPE type,
162 BLEServiceInfo *bleServiceInfo);
165 * @brief Used to add the ServiceInfo structure to the Service List.
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
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
176 CAResult_t CAAddBLEServiceInfoToList(BLEServiceList **serviceList,
177 BLEServiceInfo *bleServiceInfo);
180 * @brief Used to remove the ServiceInfo structure from the Service List.
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
186 * @param bdAddress [IN] BD address of the device where GATTServer is disconnected.
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
193 CAResult_t CARemoveBLEServiceInfoToList(BLEServiceList **serviceList,
194 BLEServiceInfo *bleServiceInfo,
195 const char *bdAddress);
198 * @brief Used to get the serviceInfo from the list.
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
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
210 CAResult_t CAGetBLEServiceInfo(BLEServiceList *serviceList, const char *bdAddress,
211 BLEServiceInfo **bleServiceInfo);
214 * @brief Used to get the serviceInfo from the list by position.
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
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
226 CAResult_t CAGetBLEServiceInfoByPosition(BLEServiceList *serviceList, int32_t position,
227 BLEServiceInfo **bleServiceInfo);
230 * @brief Used to clear BLE service list
232 * @param serviceList [IN] Pointer to the ble service list which holds the info of list of
233 * service registered from client.
236 void CAFreeBLEServiceList(BLEServiceList *serviceList);
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.
244 void CAFreeBLEServiceInfo(BLEServiceInfo *bleServiceInfo);
247 * @brief Used to check whether found handle is OIC service handle or not.
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
255 CAResult_t CAVerifyOICServiceByServiceHandle(bt_gatt_attribute_h serviceHandle);
258 * @brief Used to check whether UUID of the discovered device is OIC service or not.
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
266 CAResult_t CAVerifyOICServiceByUUID(const char* serviceUUID);
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.
273 const char *CABTGetErrorMsg(bt_error_e err);
275 #endif /* TZ_BLE_UTIL_H_ */