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 * Information regarding the GATTServer.
42 * This structure holds the infomation about the GATTServer
43 * in the service and the characteristic level.
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.
50 bt_gatt_attribute_h write_char; /**< GATT attribute handler for OIC write characteristic.
52 char *bdAddress; /**< BD address where OIC service is running. */
56 * List of the BLEServiceInfo structures.
58 * A list of BLEServiceInfo and gives the info about all the
59 * the registered services from the client side.
61 typedef struct _BLEServiceList
63 BLEServiceInfo *serviceInfo; /**< BLEServiceInfo structure from an OIC Server. */
64 struct _BLEServiceList *next; /**< Next reference to the List. */
68 * Different characteristics types.
70 * This provides information of different characteristics
71 * which will be added to OIC service.
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. */
81 * Stores the information required to set the descriptor value of the Service.
83 typedef struct gattCharDescriptor
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;
91 * Used to increment the registered service count.
93 void CAIncrementRegisteredServiceCount();
96 * Used to decrement the registered service count.
98 void CADecrementRegisteredServiceCount();
101 * Used to reset the registered service count.
103 void CAResetRegisteredServiceCount();
106 * Used to get the total registered service count.
107 * @return Total registered service count.
109 int32_t CAGetRegisteredServiceCount();
112 * Used to create BLEServiceInfo structure with server handler and BD address will be
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.
123 CAResult_t CACreateBLEServiceInfo(const char *bdAddress, bt_gatt_attribute_h service,
124 BLEServiceInfo **bleServiceInfo);
127 * Used to append the characteristic info to the already created serviceInfo structure.
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
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.
138 CAResult_t CAAppendBLECharInfo(bt_gatt_attribute_h characteristic, CHAR_TYPE type,
139 BLEServiceInfo *bleServiceInfo);
142 * Used to add the ServiceInfo structure to the Service List.
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
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.
153 CAResult_t CAAddBLEServiceInfoToList(BLEServiceList **serviceList,
154 BLEServiceInfo *bleServiceInfo);
157 * Used to remove the ServiceInfo structure from the Service List.
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
163 * @param[in] bdAddress BD address of the device where GATTServer is disconnected.
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.
170 CAResult_t CARemoveBLEServiceInfoToList(BLEServiceList **serviceList,
171 BLEServiceInfo *bleServiceInfo,
172 const char *bdAddress);
175 * Used to get the serviceInfo from the list.
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
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.
187 CAResult_t CAGetBLEServiceInfo(BLEServiceList *serviceList, const char *bdAddress,
188 BLEServiceInfo **bleServiceInfo);
191 * Used to get the serviceInfo from the list by position.
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
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.
203 CAResult_t CAGetBLEServiceInfoByPosition(BLEServiceList *serviceList, int32_t position,
204 BLEServiceInfo **bleServiceInfo);
207 * Used to clear BLE service list.
209 * @param[in] serviceList Pointer to the ble service list which holds the info of list of
210 * service registered from client.
212 void CAFreeBLEServiceList(BLEServiceList *serviceList);
215 * Used to get remove particular BLE service info from list.
216 * @param[in] serviceinfo Pointer to the structure which needs to be cleared.
218 void CAFreeBLEServiceInfo(BLEServiceInfo *bleServiceInfo);
221 * Used to check whether found handle is OIC service handle or not.
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.
229 CAResult_t CAVerifyOICServiceByServiceHandle(bt_gatt_attribute_h serviceHandle);
232 * Used to check whether UUID of the discovered device is OIC service or not.
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.
240 CAResult_t CAVerifyOICServiceByUUID(const char* serviceUUID);
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.
247 const char *CABTGetErrorMsg(bt_error_e err);
249 #endif /* TZ_BLE_UTIL_H_ */