BLE Adapter implementation for Arduino
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caleinterface_singlethread.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_SINGLETHREAD_H_
28 #define _CA_LE_INTERFACE_SINGLETHREAD_H_
29
30 #include <stdbool.h>
31
32 #include "cacommon.h"
33 #include "caleadapter_singlethread.h"
34
35 #ifdef __cplusplus
36 extern "C"
37 {
38 #endif
39
40 /**
41  * @enum CALETransferType_t
42  * @brief Provide information 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  Used to get the current state of the LE adapter.
54  *
55  * @return #CA_STATUS_OK or Appropriate error code
56  * @retval #CA_STATUS_OK  Successful
57  * @retval #CA_ADAPTER_NOT_ENABLED  adapter not enabled
58  * @retval #CA_STATUS_FAILED Operation failed
59  */
60 CAResult_t CAGetLEAdapterState();
61
62 /**
63  * @brief  Used to initialize the network monitor layer of the LE adapter.
64  *
65  * @return #CA_STATUS_OK or Appropriate error code
66  * @retval #CA_STATUS_OK  Successful
67  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
68  * @retval #CA_STATUS_FAILED Operation failed
69  */
70 CAResult_t CALEInitializeNetworkMonitor();
71
72 /**
73  * @brief  Used to terminate the network monitor layer of the LE adapter.
74  * @return NONE
75  */
76 void CALETerminateNetworkMonitor();
77
78 /**
79  * @brief  This function is used to set the callback for the Device state changes in the adapter.
80  *
81  * @param  callback  [IN]  Callback to notify the Device state change to the CA Layer
82  *
83  * @return #CA_STATUS_OK or Appropriate error code
84  * @retval #CA_STATUS_OK  Successful
85  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
86  * @retval #CA_STATUS_FAILED Operation failed
87  */
88 CAResult_t CASetLEAdapterStateChangedCb(CALEDeviceStateChangedCallback callback);
89
90 /**
91  * @brief  Provides the BD address of the local adapter.
92  * @param  local_address [OUT] pointer to the location where bd address needs to be stored.
93  *
94  * @return #CA_STATUS_OK or Appropriate error code
95  * @retval #CA_STATUS_OK  Successful
96  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
97  * @retval #CA_STATUS_FAILED Operation failed
98  */
99 CAResult_t CAGetLEAddress(char **local_address);
100
101 /**
102  * @brief  Used to start Gatt Server thread for service creation and advertise ble service.
103  *
104  * @return #CA_STATUS_OK or Appropriate error code
105  * @retval #CA_STATUS_OK  Successful
106  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
107  * @retval #CA_STATUS_FAILED Operation failed
108  */
109 CAResult_t CAStartBleGattServer();
110
111 /**
112  * @brief  Used to stop BLE Gatt Service.
113  *
114  * @return #CA_STATUS_OK or Appropriate error code
115  * @retval #CA_STATUS_OK  Successful
116  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
117  * @retval #CA_STATUS_FAILED Operation failed
118  */
119 CAResult_t CAStopBleGattServer();
120
121 /**
122  * @brief  Used to store upper layer callback locally which will be used to send the data to
123  *         application
124  * @param  callback [IN] Callback function to pass the data to CA layer.
125  * @return NONE
126  */
127 void CASetBLEReqRespServerCallback(CABLEServerDataReceivedCallback callback);
128
129 /**
130  * @brief  Used to update characteristics(Read/Write) value that we want to send to particular
131  *         client. Both unicast and multicast will use the same api. In mulicast, we will be
132  *         sending in loop to all clients.
133  *
134  * @param  charValue     [IN] Data that we want to send to client(unicast)/clients(multicast)
135  * @param  charValueLen  [IN] Length of the data.
136  *
137  * @return #CA_STATUS_OK or Appropriate error code
138  * @retval #CA_STATUS_OK  Successful
139  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
140  * @retval #CA_STATUS_FAILED Operation failed
141  */
142 CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue,
143                                                    uint8_t charValueLen);
144
145 /**
146  * @brief  Used to start CAStartBleGattClientThread for initializing Gatt Client
147  *
148  * @return #CA_STATUS_OK or Appropriate error code
149  * @retval #CA_STATUS_OK  Successful
150  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
151  * @retval #CA_STATUS_FAILED Operation failed
152  */
153 CAResult_t CAStartBLEGattClient();
154
155 /**
156  * @brief  Used to stop Gatt Client gracefully in turn it will call CATerminateBLEGattClient
157  *         function.
158  * @return #CA_STATUS_OK or Appropriate error code
159  * @retval #CA_STATUS_OK  Successful
160  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
161  * @retval #CA_STATUS_FAILED Operation failed
162  */
163 void CAStopBLEGattClient();
164
165 /**
166  * @brief  Used to unset all the callbacks and stop service discovery
167  * @return NONE
168  */
169 void CATerminateBLEGattClient();
170
171 /**
172  * @brief  Sets the value of characteristic and update the value to GATTServer(unicast).
173  *
174  * @param  remoteAddress [IN] The address of the remote device
175  * @param  data          [IN] The value of characteristic (byte array)
176  * @param  dataLen       [IN] The length of value
177  * @param  type          [IN] Type of the transfer(#CALETransferType_t)
178  * @param  position      [IN] The unique index of each ble server. Used for multicast feature.
179  *
180  * @return #CA_STATUS_OK or Appropriate error code
181  * @retval #CA_STATUS_OK  Successful
182  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
183  * @retval #CA_STATUS_FAILED Operation failed
184  */
185 CAResult_t  CAUpdateCharacteristicsToGattServer(const char *remoteAddress, const char  *data,
186                                                 const uint32_t dataLen, CALETransferType_t type,
187                                                 const int32_t position);
188
189 /**
190  * @brief  Sets the value of characteristic and update the value to all registered
191  *         GATTServer -> Multicast
192  * @param  data     [IN] The value of characteristic (byte array)
193  * @param  dataLen  [IN] The length of value
194  *
195  * @return #CA_STATUS_OK or Appropriate error code
196  * @retval #CA_STATUS_OK  Successful
197  * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
198  * @retval #CA_STATUS_FAILED Operation failed
199  */
200 CAResult_t  CAUpdateCharacteristicsToAllGattServers(const char  *data, uint32_t dataLen);
201
202 /**
203  * @brief  Used to store upper layer callback locally which will be used to send the data to
204  *         application
205  * @param  callback  [IN] Callback function to pass the data to CA layer.
206  *
207  * @return  void
208  */
209 void CASetBLEReqRespClientCallback(CABLEClientDataReceivedCallback callback);
210
211 #ifdef __cplusplus
212 }
213 #endif
214
215 #endif //_CA_LE_INTERFACE_SINGLETHREAD_H_
216