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_state
50 uint8_t address[CA_MACADDR_SIZE];
51 CAConnectedState_t state;
55 * Enum for defining different server types.
59 CA_UNICAST_SERVER = 0, /**< Unicast Server. */
60 CA_MULTICAST_SERVER, /**< Multicast Server. */
61 CA_SECURED_UNICAST_SERVER /**< Secured Unicast Server. */
62 } CAAdapterServerType_t;
65 * Structure to maintain the information of data in message queue.
69 CAEndpoint_t *remoteEndpoint; /**< Remote Endpoint. */
70 void *data; /**< Data to be sent. */
71 uint32_t dataLen; /**< Length of the data to be sent. */
75 * Structure to maintain the adapter information and its status.
79 CAEndpoint_t *info; /**< Local Connectivity Information. */
80 CANetworkStatus_t status; /**< Network Status. */
84 * This will be used during the Receiver of network requests and response.
85 * @param[in] remoteAddress EDR address of remote OIC device from which data received.
86 * @param[in] data Data received.
87 * @param[in] dataLength Length of the Data received.
88 * @param[out] sentLength Length of the sent data.
89 * @pre Callback must be registered using CAEDRSetPacketReceivedCallback().
91 typedef void (*CAEDRDataReceivedCallback)(const char *remoteAddress, const void *data,
92 uint32_t dataLength, uint32_t *sentLength);
95 * This will be used during change in network status.
96 * @param[in] status Network Status of the adapter.
98 typedef void (*CAEDRNetworkStatusCallback)(CANetworkStatus_t status);
101 * Callback to notify the error in the EDR adapter.
102 * @param[in] remoteAddress Remote EDR Address.
103 * @param[in] serviceUUID Service UUID of the device.
104 * @param[in] data data containing token, uri and coap data.
105 * @param[in] dataLength length of data.
106 * @param[in] result error code as defined in ::CAResult_t.
107 * @pre Callback must be registered using CAEDRSetPacketReceivedCallback().
109 typedef void (*CAEDRErrorHandleCallback)(const char *remoteAddress, const char *serviceUUID,
110 const void *data, uint32_t dataLength, CAResult_t result);
113 * Initialize the network monitor module
114 * @param[in] threadPool Threadpool Handle.
115 * @return ::CA_STATUS_OK or Appropriate error code.
116 * @retval ::CA_STATUS_OK Successful.
117 * @retval ::CA_ADAPTER_NOT_ENABLED Initialization is successful, but
118 * bluetooth adapter is not enabled.
119 * @retval ::CA_STATUS_FAILED Operation failed.
120 * @see CAEDRTerminateNetworkMonitor().
122 CAResult_t CAEDRInitializeNetworkMonitor(const ca_thread_pool_t threadPool);
125 * Deinitialize with bluetooth adapter.
126 * @pre CAEDRInitializeNetworkMonitor() should be invoked before using
128 * @see CAEDRInitializeNetworkMonitor().
130 void CAEDRTerminateNetworkMonitor();
133 * Start Network Monitoring Process.
134 * @return ::CA_STATUS_OK or Appropriate error code.
136 CAResult_t CAEDRStartNetworkMonitor();
139 * Stop Network Monitoring Process.
140 * @return ::CA_STATUS_OK or Appropriate error code.
142 CAResult_t CAEDRStopNetworkMonitor();
145 * Sets the callback and Starts discovery for nearby OIC bluetooth devices.
147 * @return ::CA_STATUS_OK or Appropriate error code.
148 * @retval ::CA_STATUS_OK Successful.
149 * @retval ::CA_STATUS_FAILED Operation failed.
151 CAResult_t CAEDRClientSetCallbacks();
154 * Resetting callbacks with bluetooth framework and stop OIC device discovery.
155 * @pre CAEDRClientSetCallbacks() should be invoked before using this API.
156 * @see CAEDRClientSetCallbacks().
158 void CAEDRClientUnsetCallbacks();
161 * Used to initialize the EDR client module where mutex is initialized.
163 void CAEDRInitializeClient(ca_thread_pool_t handle);
166 * Destroys the Device list and mutex.
168 void CAEDRClientTerminate();
171 * Closes all the client connection to peer bluetooth devices.
173 void CAEDRClientDisconnectAll();
176 * Register callback to send the received packets from remote bluetooth
177 * device to BTAdapter.
179 * @param[in] packetReceivedCallback Callback function to register for
180 * sending network packets to EDR Adapter.
182 void CAEDRSetPacketReceivedCallback(CAEDRDataReceivedCallback packetReceivedCallback);
185 * Register callback for receiving local bluetooth adapter state.
187 * @param[in] networkStateChangeCallback Callback function to register
188 * for receiving local bluetooth adapter status.
190 void CAEDRSetNetworkChangeCallback(CAEDRNetworkStatusCallback networkStateChangeCallback);
193 * set error callback to notify error in EDR adapter.
195 * @param[in] errorHandleCallback Callback function to notify the error
196 * in the EDR adapter.
198 void CAEDRSetErrorHandler(CAEDRErrorHandleCallback errorHandleCallback);
202 * Get the local bluetooth adapter information.
204 * @param[out] info Local bluetooth adapter information.
206 * @return ::CA_STATUS_OK or Appropriate error code.
207 * @retval ::CA_STATUS_OK Successful.
208 * @retval ::CA_STATUS_INVALID_PARAM Invalid input argumets.
209 * @retval ::CA_STATUS_FAILED Operation failed.
211 * @see CALocalConnectivity_t
214 CAResult_t CAEDRGetInterfaceInformation(CAEndpoint_t **info);
217 * Start RFCOMM server for given service UUID
219 * @param[in] serviceUUID The UUID of service with which RFCOMM server
220 * needs to be started.
221 * @param[in] serverFD The RFCOMM server socket file descriptor.
222 * @param[in] handle Threadpool Handle.
224 * @return ::CA_STATUS_OK or Appropriate error code.
225 * @retval ::CA_STATUS_OK Successful.
226 * @retval ::CA_STATUS_INVALID_PARAM Invalid input argumets.
227 * @retval ::CA_STATUS_FAILED Operation failed.
230 CAResult_t CAEDRServerStart(const char *serviceUUID, int *serverFD, ca_thread_pool_t handle);
235 * @param[in] serverFD The RFCOMM server socket file descriptor which
236 * needs to be stopped.
238 * @return ::CA_STATUS_OK or Appropriate error code.
239 * @retval ::CA_STATUS_OK Successful.
240 * @retval ::CA_STATUS_FAILED Operation failed.
242 CAResult_t CAEDRServerStop(int serverFD);
245 * Terminate server for EDR.
247 void CAEDRServerTerminate();
250 * All received data will be notified to upper layer.
252 * @return ::CA_STATUS_OK or Appropriate error code.
253 * @retval ::CA_STATUS_OK Successful.
254 * @retval ::CA_STATUS_FAILED Operation failed.
257 CAResult_t CAEDRManagerReadData();
260 * This function gets bluetooth adapter enable state.
261 * @param[out] state State of the Adapter.
262 * @return ::CA_STATUS_OK or Appropriate error code.
264 CAResult_t CAEDRGetAdapterEnableState(bool *state);
267 * This function sends data to specified remote bluetooth device.
268 * @param[in] remoteAddress Remote EDR Address.
269 * @param[in] serviceUUID Service UUID of the device.
270 * @param[in] data Data to be sent.
271 * @param[in] dataLength Length of the data to be sent.
272 * @return ::CA_STATUS_OK or Appropriate error code.
274 CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress, const char *serviceUUID,
275 const void *data, uint32_t dataLength);
278 * This function sends data to all bluetooth devices running OIC service.
279 * @param[in] serviceUUID Service UUID of the device.
280 * @param[in] data Data to be sent.
281 * @param[in] dataLength Length of the data to be sent.
282 * @return ::CA_STATUS_OK or Appropriate error code.
284 CAResult_t CAEDRClientSendMulticastData(const char *serviceUUID, const void *data,
285 uint32_t dataLength);
288 * This function gets bonded bluetooth device list
289 * @return ::CA_STATUS_OK or Appropriate error code.
291 CAResult_t CAEDRGetBondedDeviceList();
297 #endif /* CA_EDR_INTERFACE_H_ */