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 functionalities of GATT Client. Functionalities
25 * like LE device discovery, connecting to the LE device with OIC service,
26 * registering to the service and there characteristics, registering to the
27 * change in the charateristics, setting the value of the characteristcs
28 * for the request and response will be done here.
31 #ifndef TZ_BLE_CLIENT_H_
32 #define TZ_BLE_CLIENT_H_
34 #include <bluetooth.h>
35 #include <bluetooth_type.h>
37 #include "caadapterutils.h"
39 #include "caadapterinterface.h"
41 #include "cathreadpool.h"
42 #include "caleinterface.h"
43 #include "oic_malloc.h"
47 * This callback is called when a characteristic value is changed by the GATT server.
49 * @param[in] characteristic The attribute handle of characteristic.
50 * @param[in] value Value of the characteristics of a service.
51 * @param[in] valueLen Length of data.
52 * @param[in] userData The user data passed from the request function.
54 void CALEGattCharacteristicChangedCb(bt_gatt_h characteristic,
55 char *value, int valueLen, void *userData);
57 * This callback will be called when the client write request is completed.
59 * @param[in] result Result of write value.
60 * @param[in] reqHandle The request GATT handle.
61 * @param[in] userData User context
63 void CALEGattCharacteristicWriteCb(int result, bt_gatt_h reqHandle, void *userData);
66 * This is the callback which will be called when LE advertisement is found.
68 * @param[in] result The result of Scanning
69 * @param[in] scanInfo Remote Device information.
70 * @param[in] userData The user data passed from the request function
72 void CALEAdapterScanResultCb(int result, bt_adapter_le_device_scan_result_info_s *scanInfo,
76 * This thread will be used to Start the timer for scanning.
78 * @param[in] data Currently it will be NULL(no parameter)
80 void CAStartTimerThread(void *data);
82 void CALEClientScanThread();
85 * Used to initialize all required mutex variable for Gatt Client implementation.
87 * @return ::CA_STATUS_OK or Appropriate error code.
88 * @retval ::CA_STATUS_OK Successful.
89 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
90 * @retval ::CA_STATUS_FAILED Operation failed.
92 CAResult_t CAInitGattClientMutexVariables();
95 * Used to terminate all required mutex variable for Gatt Client implementation.
97 void CATerminateGattClientMutexVariables();
100 * Used to register required callbacks to LE platform(connection, discovery, etc).
102 * @return ::CA_STATUS_OK or Appropriate error code.
103 * @retval ::CA_STATUS_OK Successful.
104 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
105 * @retval ::CA_STATUS_FAILED Operation failed.
107 CAResult_t CALEGattSetCallbacks();
110 * Used to unset all the registerd callbacks to BLE platform.
112 void CALEGattUnSetCallbacks();
115 * Used to start LE Scanning.
117 * @return ::CA_STATUS_OK or Appropriate error code.
118 * @retval ::CA_STATUS_OK Successful.
119 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
120 * @retval ::CA_STATUS_FAILED Operation failed.
122 CAResult_t CALEGattStartDeviceScanning();
125 * Used to stop LE discovery for BLE devices.
127 void CALEGattStopDeviceScanning();
130 * This is the thread which will be used for making gatt connection with
132 * @param[in] remoteAddress MAC address of remote device to connect.
134 void CAGattConnectThread (void *remoteAddress);
137 * Used to do connection with remote device.
139 * @param[in] remoteAddress Remote address inwhich we wants to connect with.
141 * @return ::CA_STATUS_OK or Appropriate error code.
142 * @retval ::CA_STATUS_OK Successful.
143 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
144 * @retval ::CA_STATUS_FAILED Operation failed.
146 CAResult_t CALEGattConnect(const char *remoteAddress);
149 * Used to do disconnection with remote device.
150 * @param[in] remoteAddress Remote address inwhich we wants to disconnect with.
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 CALEGattDisConnect(const char *remoteAddress);
160 * This is thread which will be spawned for discovering ble services. Once
161 * called discover api, then it will be terminated.
162 * @param[in] remoteAddress Mac address of the remote device in which we
163 * want to search services.
165 void CADiscoverLEServicesThread (void *remoteAddress);
168 * Used to discover the services and characteristics that is advertised by Gatt
171 * @param[in] remoteAddress MAC address of remote device in which we want to discover
172 * the services and characteristics.
174 * @return ::CA_STATUS_OK or Appropriate error code.
175 * @retval ::CA_STATUS_OK Successful.
176 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
177 * @retval ::CA_STATUS_FAILED Operation failed.
179 CAResult_t CALEGattDiscoverServices(const char *remoteAddress);
182 * check connection status.
183 * @param[in] address the address of the remote device.
184 * @return true or false.
186 bool CALEClientIsConnected(const char* address);
190 * @param[in] address the address of the remote device.
191 * @return mtu size negotiated from remote device.
193 uint16_t CALEClientGetMtuSize(const char* address);
196 * This function is used to set MTU size
197 * which negotiated between client and server device.
198 * @param[in] address remote address.
199 * @param[in] mtuSize MTU size.
200 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
202 CAResult_t CALEClientSetMtuSize(const char* address, uint16_t mtuSize);
205 * Send negotiation message after gatt connection is done.
206 * @param[in] address remote address.
207 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
209 CAResult_t CALEClientSendNegotiationMessage(const char* address);
210 #endif /* TZ_BLE_CLIENT_H_ */