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 provides APIs for EDR adapter - client, server, network monitor
28 #ifndef CA_EDR_INTERFACE_H_
29 #define CA_EDR_INTERFACE_H_
31 #include "caedradapter.h"
38 #ifndef OIC_EDR_SERVICE_ID
39 #define OIC_EDR_SERVICE_ID "12341234-1C25-481F-9DFB-59193D238280"
40 #endif //OIC_EDR_SERVICE_ID
44 STATE_DISCONNECTED, /**< State is Disconnected. */
45 STATE_CONNECTED /**< State is Connected. */
48 typedef struct connected_device
50 uint8_t address[CA_MACADDR_SIZE];
51 CAConnectedState_t state;
55 } CAConnectedDeviceInfo_t;
58 * Enum for defining different server types.
62 CA_UNICAST_SERVER = 0, /**< Unicast Server. */
63 CA_MULTICAST_SERVER, /**< Multicast Server. */
64 CA_SECURED_UNICAST_SERVER /**< Secured Unicast Server. */
65 } CAAdapterServerType_t;
68 * Structure to maintain the information of data in message queue.
72 CAEndpoint_t *remoteEndpoint; /**< Remote Endpoint. */
73 uint8_t *data; /**< Data to be sent. */
74 uint32_t dataLen; /**< Length of the data to be sent. */
78 * Structure to maintain the adapter information and its status.
82 CAEndpoint_t *info; /**< Local Connectivity Information. */
83 CANetworkStatus_t status; /**< Network Status. */
87 * This will be used during the Receiver of network requests and response.
88 * @param[in] remoteAddress EDR address of remote OIC device from which data received.
89 * @param[in] data Data received.
90 * @param[in] dataLength Length of the Data received.
91 * @param[out] sentLength Length of the sent data.
92 * @pre Callback must be registered using CAEDRSetPacketReceivedCallback().
94 typedef void (*CAEDRDataReceivedCallback)(const char *remoteAddress, const uint8_t *data,
95 uint32_t dataLength, uint32_t *sentLength);
98 * This will be used during change in network status.
99 * @param[in] status Network Status of the adapter.
101 typedef void (*CAEDRNetworkStatusCallback)(CANetworkStatus_t status);
104 * Callback to notify the error in the EDR adapter.
105 * @param[in] remoteAddress Remote EDR Address.
106 * @param[in] data data containing token, uri and coap data.
107 * @param[in] dataLength length of data.
108 * @param[in] result error code as defined in ::CAResult_t.
109 * @pre Callback must be registered using CAEDRSetPacketReceivedCallback().
111 typedef void (*CAEDRErrorHandleCallback)(const char *remoteAddress,
117 * Initialize the network monitor module
118 * @param[in] threadPool Threadpool Handle.
119 * @return ::CA_STATUS_OK or Appropriate error code.
120 * @retval ::CA_STATUS_OK Successful.
121 * @retval ::CA_ADAPTER_NOT_ENABLED Initialization is successful, but
122 * bluetooth adapter is not enabled.
123 * @retval ::CA_STATUS_FAILED Operation failed.
124 * @see CAEDRTerminateNetworkMonitor().
126 CAResult_t CAEDRInitializeNetworkMonitor(const ca_thread_pool_t threadPool);
129 * Deinitialize with bluetooth adapter.
130 * @pre CAEDRInitializeNetworkMonitor() should be invoked before using
132 * @see CAEDRInitializeNetworkMonitor().
134 void CAEDRTerminateNetworkMonitor();
137 * Start Network Monitoring Process.
138 * @return ::CA_STATUS_OK or Appropriate error code.
140 CAResult_t CAEDRStartNetworkMonitor();
143 * Stop Network Monitoring Process.
144 * @return ::CA_STATUS_OK or Appropriate error code.
146 CAResult_t CAEDRStopNetworkMonitor();
149 * Sets the callback and Starts discovery for nearby OIC bluetooth devices.
151 * @return ::CA_STATUS_OK or Appropriate error code.
152 * @retval ::CA_STATUS_OK Successful.
153 * @retval ::CA_STATUS_FAILED Operation failed.
155 CAResult_t CAEDRClientSetCallbacks();
158 * Resetting callbacks with bluetooth framework and stop OIC device discovery.
159 * @pre CAEDRClientSetCallbacks() should be invoked before using this API.
160 * @see CAEDRClientSetCallbacks().
162 void CAEDRClientUnsetCallbacks();
165 * Used to initialize the EDR client module where mutex is initialized.
166 * @return ::CA_STATUS_OK or Appropriate error code.
168 CAResult_t CAEDRClientInitialize();
171 * Destroys the Device list and mutex.
173 void CAEDRClientTerminate();
176 * Closes all the client connection to peer bluetooth devices.
178 void CAEDRClientDisconnectAll();
181 * Register callback to send the received packets from remote bluetooth
182 * device to BTAdapter.
184 * @param[in] packetReceivedCallback Callback function to register for
185 * sending network packets to EDR Adapter.
187 void CAEDRSetPacketReceivedCallback(CAEDRDataReceivedCallback packetReceivedCallback);
190 * Register callback for receiving local bluetooth adapter state.
192 * @param[in] networkStateChangeCallback Callback function to register
193 * for receiving local bluetooth adapter status.
195 void CAEDRSetNetworkChangeCallback(CAEDRNetworkStatusCallback networkStateChangeCallback);
198 * set error callback to notify error in EDR adapter.
200 * @param[in] errorHandleCallback Callback function to notify the error
201 * in the EDR adapter.
203 void CAEDRSetErrorHandler(CAEDRErrorHandleCallback errorHandleCallback);
207 * Get the local bluetooth adapter information.
209 * @param[out] info Local bluetooth adapter information.
211 * @return ::CA_STATUS_OK or Appropriate error code.
212 * @retval ::CA_STATUS_OK Successful.
213 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
214 * @retval ::CA_STATUS_FAILED Operation failed.
216 * @see CALocalConnectivity_t
219 CAResult_t CAEDRGetInterfaceInformation(CAEndpoint_t **info);
222 * Start RFCOMM server for given service UUID
224 * @return ::CA_STATUS_OK or Appropriate error code.
225 * @retval ::CA_STATUS_OK Successful.
226 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
227 * @retval ::CA_STATUS_FAILED Operation failed.
230 CAResult_t CAEDRServerStart();
235 * @return ::CA_STATUS_OK or Appropriate error code.
236 * @retval ::CA_STATUS_OK Successful.
237 * @retval ::CA_STATUS_FAILED Operation failed.
239 CAResult_t CAEDRServerStop();
242 * Used to initialize the EDR server module where mutex is initialized.
243 * @param[in] threadPool Threadpool Handle.
244 * @return ::CA_STATUS_OK or Appropriate error code.
246 CAResult_t CAEDRServerInitialize(ca_thread_pool_t handle);
249 * Terminate server for EDR.
251 void CAEDRServerTerminate();
254 * All received data will be notified to upper layer.
256 * @return ::CA_STATUS_OK or Appropriate error code.
257 * @retval ::CA_STATUS_OK Successful.
258 * @retval ::CA_STATUS_FAILED Operation failed.
261 CAResult_t CAEDRManagerReadData();
264 * This function gets bluetooth adapter enable state.
265 * @param[out] state State of the Adapter.
266 * @return ::CA_STATUS_OK or Appropriate error code.
268 CAResult_t CAEDRGetAdapterEnableState(bool *state);
271 * This function sends data to specified remote bluetooth device.
272 * @param[in] remoteAddress Remote EDR Address.
273 * @param[in] data Data to be sent.
274 * @param[in] dataLength Length of the data to be sent.
275 * @return ::CA_STATUS_OK or Appropriate error code.
277 CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress,
279 uint32_t dataLength);
282 * This function sends data to all bluetooth devices running OIC service.
283 * @param[in] data Data to be sent.
284 * @param[in] dataLength Length of the data to be sent.
285 * @return ::CA_STATUS_OK or Appropriate error code.
287 CAResult_t CAEDRClientSendMulticastData(const uint8_t *data,
288 uint32_t dataLength);
291 * This function gets bonded bluetooth device list
292 * @return ::CA_STATUS_OK or Appropriate error code.
294 CAResult_t CAEDRGetBondedDeviceList();
298 * This function starts device discovery.
300 CAResult_t CAEDRStartDeviceDiscovery(void);
307 #endif /* CA_EDR_INTERFACE_H_ */