Corrected @file tags and restored 'Files' section.
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caleinterface.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 provides APIs for BLE modules.
25  */
26
27 #ifndef _CA_LE_INTERFACE_H_
28 #define _CA_LE_INTERFACE_H_
29
30 #include <stdbool.h>
31
32 #include "cacommon.h"
33 #include "caleadapter.h"
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39
40 /**
41  * @enum CALETransferType_t
42  * @brief Provide info about different mode of data transfer
43  *        This enum is used to differentiate between unicast and multicast data transfer.
44  */
45 typedef enum
46 {
47     LE_MULTICAST,    /**< When this enum is selected, data will be updated to all OIC servers. */
48     LE_UNICAST       /**< When this enum is selected, data will be updated to desired OIC Server. */
49 } CALETransferType_t;
50
51
52 /**
53  * @brief  Initialize the LE adapter layer. This will be invoked from the CA layer.
54  *
55  * @return #CA_STATUS_OK or Appropriate error code
56  * @retval #CA_STATUS_OK  Successful
57  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
58  * @retval #CA_STATUS_FAILED Operation failed
59  */
60 CAResult_t CAInitializeLEAdapter();
61
62 /**
63  * @brief  Used to get the current state of the LE adapter.
64  *
65  * @return #CA_STATUS_OK or Appropriate error code
66  * @retval #CA_STATUS_OK  Successful
67  * @retval #CA_ADAPTER_NOT_ENABLED  adapter not enabled
68  * @retval #CA_STATUS_FAILED Operation failed
69  */
70 CAResult_t CAGetLEAdapterState();
71
72 /**
73  * @brief  Used to initialize the network monitor layer of the LE adapter. Mutex variables required
74  *         to operate in this layer and other paramters can be initialized in this function.
75  *
76  * @return #CA_STATUS_OK or Appropriate error code
77  * @retval #CA_STATUS_OK  Successful
78  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
79  * @retval #CA_STATUS_FAILED Operation failed
80  */
81 CAResult_t CAInitializeLENetworkMonitor();
82
83 /**
84  * @brief  Used to terminate the network monitor layer of the LE adapter. The variables intialized
85  *         in CAInitializeLEAdapterController() must be cleared in this function.
86  * @return NONE
87  */
88 void CATerminateLENetworkMonitor();
89
90 /**
91  * @brief  This function is used to set the callback for the Device state changes in the adapter.
92  *
93  * @param  callback  [IN] Callback to notify the Device state change to the CA Layer
94  *
95  * @return #CA_STATUS_OK or Appropriate error code
96  * @retval #CA_STATUS_OK  Successful
97  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
98  * @retval #CA_STATUS_FAILED Operation failed
99  */
100 CAResult_t CASetLEAdapterStateChangedCb(CALEDeviceStateChangedCallback callback);
101
102 /**
103  * @brief  Used to initilaze all the mutex variables required to operate the LE network monitor
104  *         layer.
105  * @return #CA_STATUS_OK or Appropriate error code
106  * @retval #CA_STATUS_OK  Successful
107  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
108  * @retval #CA_STATUS_FAILED Operation failed
109  */
110 CAResult_t CAInitLENetworkMonitorMutexVariables();
111
112 /**
113  * @brief  Used to terminate all the mutex variables required to operate the LE network monitor
114  *         layer.
115  * @return NONE
116  */
117 void CATerminateLENetworkMonitorMutexVariables();
118
119 /**
120  * @brief  Provides the BD address of the local adapter.
121  * @param  local_address [IN] pointer to the location where bd address needs to be stored.
122  *
123  * @return NONE
124  */
125 void CAGetLEAddress(char **local_address);
126
127 /**
128  * @brief  Used to start Gatt Server thread for service creation and advertise ble service.
129  *
130  * @return #CA_STATUS_OK or Appropriate error code
131  * @retval #CA_STATUS_OK  Successful
132  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
133  * @retval #CA_STATUS_FAILED Operation failed
134  */
135 CAResult_t CAStartBleGattServer();
136
137 /**
138  * @brief  Used to stop BLE Gatt Service.
139  *
140  * @return #CA_STATUS_OK or Appropriate error code
141  * @retval #CA_STATUS_OK  Successful
142  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
143  * @retval #CA_STATUS_FAILED Operation failed
144  */
145 CAResult_t CAStopBleGattServer();
146
147 /**
148  * @brief  Used to stop Gatt Server thread and remove service registration, stop advertising.
149  * @return NONE
150  */
151 void CATerminateBleGattServer();
152
153 /**
154  * @brief  Used to store upper layer callback locally which will be used to send the data to
155  *         application
156  * @param  callback [IN] Callback function to pass the data to CA layer.
157  * @return NONE
158  */
159 void CASetBLEReqRespServerCallback(CABLEServerDataReceivedCallback callback);
160
161 /**
162  * @brief  Used to update characteristics(Read/Write) value that we want to send to particular
163  *         client. Both unicast and multicast will use the same api. In mulicast, we will be
164  *         sending in loop to all clients.
165  *
166  * @param  charValue     [IN] Data that we want to send to client(unicast)/clients(multicast)
167  * @param  charValueLen  [IN] Length of the data.
168  *
169  * @return #CA_STATUS_OK or Appropriate error code
170  * @retval #CA_STATUS_OK  Successful
171  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
172  * @retval #CA_STATUS_FAILED Operation failed
173  */
174 CAResult_t CAUpdateCharacteristicsInGattServer(const char *charValue, const uint32_t charValueLen);
175
176 /**
177  * @brief  Used to start CAStartBleGattClientThread for initializing Gatt Client
178  *
179  * @return #CA_STATUS_OK or Appropriate error code
180  * @retval #CA_STATUS_OK  Successful
181  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
182  * @retval #CA_STATUS_FAILED Operation failed
183  */
184 CAResult_t CAStartBLEGattClient();
185
186 /**
187  * @brief  Used to stop Gatt Client gracefully in turn it will call CATerminateBLEGattClient
188  *         function.
189  * @return #CA_STATUS_OK or Appropriate error code
190  * @retval #CA_STATUS_OK  Successful
191  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
192  * @retval #CA_STATUS_FAILED Operation failed
193  */
194 void CAStopBLEGattClient();
195
196 /**
197  * @brief  Used to unset all the callbacks and stop service discovery
198  * @return NONE
199  */
200 void CATerminateBLEGattClient();
201
202 /**
203  * @brief  Sets the value of characteristic and update the value to GATTServer(unicast).
204  *
205  * @param  remoteAddress [IN] The address of the remote device
206  * @param  data          [IN] The value of characteristic (byte array)
207  * @param  dataLen       [IN] The length of value
208  * @param  type          [IN] Type of the transfer(#CALETransferType_t)
209  * @param  position      [IN] The unique index of each ble server. Used for multicast feature.
210  *
211  * @return #CA_STATUS_OK or Appropriate error code
212  * @retval #CA_STATUS_OK  Successful
213  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
214  * @retval #CA_STATUS_FAILED Operation failed
215  */
216 CAResult_t  CAUpdateCharacteristicsToGattServer(const char *remoteAddress, const char  *data,
217                                                 const int32_t dataLen, CALETransferType_t type,
218                                                 const int32_t position);
219
220 /**
221  * @brief  Sets the value of characteristic and update the value to all registered
222  *         GATTServer -> Multicast
223  * @param  data     [IN] The value of characteristic (byte array)
224  * @param  dataLen  [IN] The length of value
225  *
226  * @return #CA_STATUS_OK or Appropriate error code
227  * @retval #CA_STATUS_OK  Successful
228  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
229  * @retval #CA_STATUS_FAILED Operation failed
230  */
231 CAResult_t  CAUpdateCharacteristicsToAllGattServers(const char  *data, int32_t dataLen);
232
233 /**
234  * @brief  Used to store upper layer callback locally which will be used to send the data to
235  *         application
236  * @param  callback  [IN] Callback function to pass the data to CA layer.
237  *
238  * @return  void
239  */
240 void CASetBLEReqRespClientCallback(CABLEClientDataReceivedCallback callback);
241
242 /**
243  * @brief  Used to Set the gThreadPool handle which is required for spawning new thread.
244  *
245  * @param handle [IN] Thread pool handle which is given by above layer for using thread
246  *                    creation task.
247  * @return #CA_STATUS_OK or Appropriate error code
248  * @retval #CA_STATUS_OK  Successful
249  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
250  * @retval #CA_STATUS_FAILED Operation failed
251  */
252 void CASetBleServerThreadPoolHandle(u_thread_pool_t handle);
253
254 /**
255 * @brief  Used to Set the gThreadPool handle which is required for spawning new thread.
256 * @param handle [IN] Thread pool handle which is given by above layer for using thread creation
257 *                    task.
258 * @return NONE
259 */
260 void CASetBleClientThreadPoolHandle(u_thread_pool_t handle);
261
262 /**
263  * @brief  Used to unset the callback of adapter connection state change.
264  *
265  * @return #CA_STATUS_OK or Appropriate error code
266  * @retval #CA_STATUS_OK  Successful
267  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
268  * @retval #CA_STATUS_FAILED Operation failed
269  */
270 CAResult_t CAUnSetLEAdapterStateChangedCb();
271 #ifdef __cplusplus
272 }
273 #endif
274
275 #endif //_CA_LE_INTERFACE_H_
276