Revert "Fixes for scan in VD"
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / tizen / caleclient.h
1 /* ****************************************************************
2 *
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
4 *
5 *
6 *
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
10 *
11 *      http://www.apache.org/licenses/LICENSE-2.0
12 *
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.
18 *
19 ******************************************************************/
20
21 /**
22  * @file
23  *
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.
29  */
30
31 #ifndef TZ_BLE_CLIENT_H_
32 #define TZ_BLE_CLIENT_H_
33
34 #include <bluetooth.h>
35 #include <bluetooth_type.h>
36 #include "cacommon.h"
37 #include "caadapterutils.h"
38 #include "caleutil.h"
39 #include "caadapterinterface.h"
40 #include "logger.h"
41 #include "cathreadpool.h"
42 #include "caleinterface.h"
43 #include "oic_malloc.h"
44
45
46 /**
47  * This callback is called when a characteristic value is changed by the GATT server.
48  *
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.
53  */
54 void CALEGattCharacteristicChangedCb(bt_gatt_h characteristic,
55                                      char *value, int valueLen, void *userData);
56 /**
57  * This callback will be called when the client write request is completed.
58  *
59  * @param[in]  result    Result of write value.
60  * @param[in]  reqHandle The request GATT handle.
61  * @param[in]  userData  User context
62  */
63 void CALEGattCharacteristicWriteCb(int result, bt_gatt_h reqHandle, void *userData);
64
65 /**
66  * This is the callback which will be called when LE advertisement is found.
67  *
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
71  */
72 void CALEAdapterScanResultCb(int result, bt_adapter_le_device_scan_result_info_s *scanInfo,
73                              void *userData);
74
75 /**
76  * This thread will be used to Start the timer for scanning.
77  *
78  * @param[in] data Currently it will be NULL(no parameter)
79  */
80 void CAStartTimerThread(void *data);
81
82 /**
83  * Used to initialize all required mutex variable for Gatt Client implementation.
84  *
85  * @return ::CA_STATUS_OK or Appropriate error code.
86  * @retval ::CA_STATUS_OK  Successful.
87  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
88  * @retval ::CA_STATUS_FAILED Operation failed.
89  */
90 CAResult_t CAInitGattClientMutexVariables();
91
92 /**
93  * Used to terminate all required mutex variable for Gatt Client implementation.
94  */
95 void CATerminateGattClientMutexVariables();
96
97 /**
98  * Used to register required callbacks to LE platform(connection, discovery, etc).
99  *
100  * @return ::CA_STATUS_OK or Appropriate error code.
101  * @retval ::CA_STATUS_OK  Successful.
102  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
103  * @retval ::CA_STATUS_FAILED Operation failed.
104  */
105 CAResult_t CALEGattSetCallbacks();
106
107 /**
108  * Used to unset all the registerd callbacks to BLE platform.
109  */
110 void CALEGattUnSetCallbacks();
111
112 /**
113  * Used to start LE Scanning.
114  *
115  * @return ::CA_STATUS_OK or Appropriate error code.
116  * @retval ::CA_STATUS_OK  Successful.
117  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
118  * @retval ::CA_STATUS_FAILED Operation failed.
119  */
120 CAResult_t CALEGattStartDeviceScanning();
121
122 /**
123  * Used to stop LE discovery for BLE  devices.
124  */
125 void CALEGattStopDeviceScanning();
126
127 /**
128  * This is the thread  which will be used for making gatt connection with
129  * remote devices.
130  * @param[in] remoteAddress MAC address of remote device to connect.
131  */
132 void CAGattConnectThread (void *remoteAddress);
133
134 /**
135  * Used to do connection with remote device.
136  *
137  * @param[in] remoteAddress Remote address inwhich we wants to connect with.
138  *
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.
143  */
144 CAResult_t CALEGattConnect(const char *remoteAddress);
145
146 /**
147  * Used to do disconnection with remote device.
148  * @param[in] remoteAddress Remote address inwhich we wants to disconnect with.
149  *
150  * @return ::CA_STATUS_OK or Appropriate error code.
151  * @retval ::CA_STATUS_OK  Successful.
152  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
153  * @retval ::CA_STATUS_FAILED Operation failed.
154  */
155 CAResult_t CALEGattDisConnect(const char *remoteAddress);
156
157 /**
158  * This is thread which will be spawned for discovering ble services. Once
159  * called discover api, then it will be terminated.
160  * @param[in] remoteAddress Mac address of the remote device in which we
161  *                           want to search services.
162  */
163 void CADiscoverLEServicesThread (void *remoteAddress);
164
165 /**
166  * Used to discover the services and characteristics that is advertised by Gatt
167  * Server.
168  *
169  * @param[in] remoteAddress MAC address of remote device in which we want to discover
170  *                      the services and characteristics.
171  *
172  * @return ::CA_STATUS_OK or Appropriate error code.
173  * @retval ::CA_STATUS_OK  Successful.
174  * @retval ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
175  * @retval ::CA_STATUS_FAILED Operation failed.
176  */
177 CAResult_t CALEGattDiscoverServices(const char *remoteAddress);
178
179 /**
180  * check connection status.
181  * @param[in] address      the address of the remote device.
182  * @return  true or false.
183  */
184 bool CALEClientIsConnected(const char* address);
185
186 /**
187  * get MTU size.
188  * @param[in] address      the address of the remote device.
189  * @return  mtu size negotiated from remote device.
190  */
191 uint16_t CALEClientGetMtuSize(const char* address);
192
193 /**
194  * This function is used to set MTU size
195  * which negotiated between client and server device.
196  * @param[in]   address       remote address.
197  * @param[in]   mtuSize       MTU size.
198  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
199  */
200 CAResult_t CALEClientSetMtuSize(const char* address, uint16_t mtuSize);
201
202 /**
203  * Send negotiation message after gatt connection is done.
204  * @param[in]   address               remote address.
205  * @return  ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
206  */
207 CAResult_t CALEClientSendNegotiationMessage(const char* address);
208 #endif /* TZ_BLE_CLIENT_H_ */