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>
36 #include <bluetooth_type_internal.h>
37 #include <bluetooth_internal.h>
40 #include "caadapterutils.h"
42 #include "caadapterinterface.h"
44 #include "cathreadpool.h"
45 #include "caleinterface.h"
46 #include "oic_malloc.h"
50 * This callback is called when a characteristic value is changed by the GATT server.
52 * @param[in] characteristic The attribute handle of characteristic.
53 * @param[in] value Value of the characteristics of a service.
54 * @param[in] valueLen Length of data.
55 * @param[in] userData The user data passed from the request function.
57 void CALEGattCharacteristicChangedCb(bt_gatt_h characteristic,
58 char *value, int valueLen, void *userData);
60 * This callback will be called when the client write request is completed.
62 * @param[in] result Result of write value.
63 * @param[in] reqHandle The request GATT handle.
64 * @param[in] userData User context
66 void CALEGattCharacteristicWriteCb(int result, bt_gatt_h reqHandle, void *userData);
69 * This is the callback which will be called whenever there is change in gatt connection
70 * with server(Connected/Disconnected)
72 * @param[in] result The result of connection state change.
73 * @param[in] connected State of connection
74 * @param[in] remoteAddress Mac address of the remote device in which we made connection.
75 * @param[in] userData The user data passed from the request function
77 void CALEGattConnectionStateChangedCb(int result, bool connected,
78 const char *remoteAddress,void *userData);
81 * This is the callback which will be called when LE advertisement is found.
83 * @param[in] result The result of Scanning
84 * @param[in] scanInfo Remote Device information.
85 * @param[in] userData The user data passed from the request function
87 void CALEAdapterScanResultCb(int result, bt_adapter_le_device_scan_result_info_s *scanInfo,
91 * This thread will be used to initialize the Gatt Client and start device discovery.
92 * 1. Setting neccessary callbacks for connection, characteristics changed and discovery.
93 * 2. Start device discovery
95 * @param[in] data Currently it will be NULL(no parameter)
97 void CAStartLEGattClientThread(void *data);
100 * This thread will be used to Start the timer for scanning.
102 * @param[in] data Currently it will be NULL(no parameter)
104 void CAStartTimerThread(void *data);
107 * Used to initialize all required mutex variable for Gatt Client implementation.
109 * @return ::CA_STATUS_OK or Appropriate error code.
110 * @retval ::CA_STATUS_OK Successful.
111 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
112 * @retval ::CA_STATUS_FAILED Operation failed.
114 CAResult_t CAInitGattClientMutexVariables();
117 * Used to terminate all required mutex variable for Gatt Client implementation.
119 void CATerminateGattClientMutexVariables();
122 * Used to register required callbacks to LE platform(connection, discovery, etc).
124 * @return ::CA_STATUS_OK or Appropriate error code.
125 * @retval ::CA_STATUS_OK Successful.
126 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
127 * @retval ::CA_STATUS_FAILED Operation failed.
129 CAResult_t CALEGattSetCallbacks();
132 * Used to unset all the registerd callbacks to BLE platform.
134 void CALEGattUnSetCallbacks();
137 * Used to start LE Scanning.
139 * @return ::CA_STATUS_OK or Appropriate error code.
140 * @retval ::CA_STATUS_OK Successful.
141 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
142 * @retval ::CA_STATUS_FAILED Operation failed.
144 CAResult_t CALEGattStartDeviceScanning();
147 * Used to stop LE discovery for BLE devices.
149 void CALEGattStopDeviceScanning();
152 * This is the thread which will be used for making gatt connection with
154 * @param[in] remoteAddress MAC address of remote device to connect.
156 void CAGattConnectThread (void *remoteAddress);
159 * Used to do connection with remote device.
161 * @param[in] remoteAddress Remote address inwhich we wants to connect with.
163 * @return ::CA_STATUS_OK or Appropriate error code.
164 * @retval ::CA_STATUS_OK Successful.
165 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
166 * @retval ::CA_STATUS_FAILED Operation failed.
168 CAResult_t CALEGattConnect(const char *remoteAddress);
171 * Used to do disconnection with remote device.
172 * @param[in] remoteAddress Remote address inwhich we wants to disconnect with.
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 CALEGattDisConnect(const char *remoteAddress);
182 * This is thread which will be spawned for discovering ble services. Once
183 * called discover api, then it will be terminated.
184 * @param[in] remoteAddress Mac address of the remote device in which we
185 * want to search services.
187 void CADiscoverLEServicesThread (void *remoteAddress);
190 * Used to discover the services and characteristics that is advertised by Gatt
193 * @param[in] remoteAddress MAC address of remote device in which we want to discover
194 * the services and characteristics.
196 * @return ::CA_STATUS_OK or Appropriate error code.
197 * @retval ::CA_STATUS_OK Successful.
198 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
199 * @retval ::CA_STATUS_FAILED Operation failed.
201 CAResult_t CALEGattDiscoverServices(const char *remoteAddress);
202 #endif /* TZ_BLE_CLIENT_H_ */