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 void CALEClientScanThread();
83
84 /**
85  * Used to initialize all required mutex variable for Gatt Client implementation.
86  *
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.
91  */
92 CAResult_t CAInitGattClientMutexVariables();
93
94 /**
95  * Used to terminate all required mutex variable for Gatt Client implementation.
96  */
97 void CATerminateGattClientMutexVariables();
98
99 /**
100  * Used to register required callbacks to LE platform(connection, discovery, etc).
101  *
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.
106  */
107 CAResult_t CALEGattSetCallbacks();
108
109 /**
110  * Used to unset all the registerd callbacks to BLE platform.
111  */
112 void CALEGattUnSetCallbacks();
113
114 /**
115  * Used to start LE Scanning.
116  *
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.
121  */
122 CAResult_t CALEGattStartDeviceScanning();
123
124 /**
125  * Used to stop LE discovery for BLE  devices.
126  */
127 void CALEGattStopDeviceScanning();
128
129 /**
130  * This is the thread  which will be used for making gatt connection with
131  * remote devices.
132  * @param[in] remoteAddress MAC address of remote device to connect.
133  */
134 void CAGattConnectThread (void *remoteAddress);
135
136 /**
137  * Used to do connection with remote device.
138  *
139  * @param[in] remoteAddress Remote address inwhich we wants to connect with.
140  *
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.
145  */
146 CAResult_t CALEGattConnect(const char *remoteAddress);
147
148 /**
149  * Used to do disconnection with remote device.
150  * @param[in] remoteAddress Remote address inwhich we wants to disconnect with.
151  *
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.
156  */
157 CAResult_t CALEGattDisConnect(const char *remoteAddress);
158
159 /**
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.
164  */
165 void CADiscoverLEServicesThread (void *remoteAddress);
166
167 /**
168  * Used to discover the services and characteristics that is advertised by Gatt
169  * Server.
170  *
171  * @param[in] remoteAddress MAC address of remote device in which we want to discover
172  *                      the services and characteristics.
173  *
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.
178  */
179 CAResult_t CALEGattDiscoverServices(const char *remoteAddress);
180
181 /**
182  * check connection status.
183  * @param[in] address      the address of the remote device.
184  * @return  true or false.
185  */
186 bool CALEClientIsConnected(const char* address);
187
188 /**
189  * get MTU size.
190  * @param[in] address      the address of the remote device.
191  * @return  mtu size negotiated from remote device.
192  */
193 uint16_t CALEClientGetMtuSize(const char* address);
194
195 /**
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).
201  */
202 CAResult_t CALEClientSetMtuSize(const char* address, uint16_t mtuSize);
203
204 /**
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).
208  */
209 CAResult_t CALEClientSendNegotiationMessage(const char* address);
210 #endif /* TZ_BLE_CLIENT_H_ */