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 * @return ::CA_STATUS_OK or ERROR CODES (::CAResult_t error codes in cacommon.h).
93 * @pre Callback must be registered using CAEDRSetPacketReceivedCallback().
95 typedef CAResult_t (*CAEDRDataReceivedCallback)(const char *remoteAddress, const uint8_t *data,
96 uint32_t dataLength, uint32_t *sentLength);
99 * This will be used during change in network status.
100 * @param[in] status Network Status of the adapter.
102 typedef void (*CAEDRNetworkStatusCallback)(CANetworkStatus_t status);
105 * Callback to notify the error in the EDR adapter.
106 * @param[in] remoteAddress Remote EDR Address.
107 * @param[in] data data containing token, uri and coap data.
108 * @param[in] dataLength length of data.
109 * @param[in] result error code as defined in ::CAResult_t.
110 * @pre Callback must be registered using CAEDRSetPacketReceivedCallback().
112 typedef void (*CAEDRErrorHandleCallback)(const char *remoteAddress,
118 * Initialize the network monitor module
119 * @param[in] threadPool Threadpool Handle.
120 * @return ::CA_STATUS_OK or Appropriate error code.
121 * @retval ::CA_STATUS_OK Successful.
122 * @retval ::CA_ADAPTER_NOT_ENABLED Initialization is successful, but
123 * bluetooth adapter is not enabled.
124 * @retval ::CA_STATUS_FAILED Operation failed.
125 * @see CAEDRTerminateNetworkMonitor().
127 CAResult_t CAEDRInitializeNetworkMonitor(const ca_thread_pool_t threadPool);
130 * Deinitialize with bluetooth adapter.
131 * @pre CAEDRInitializeNetworkMonitor() should be invoked before using
133 * @see CAEDRInitializeNetworkMonitor().
135 void CAEDRTerminateNetworkMonitor();
138 * Start Network Monitoring Process.
139 * @return ::CA_STATUS_OK or Appropriate error code.
141 CAResult_t CAEDRStartNetworkMonitor();
144 * Stop Network Monitoring Process.
145 * @return ::CA_STATUS_OK or Appropriate error code.
147 CAResult_t CAEDRStopNetworkMonitor();
150 * Sets the callback and Starts discovery for nearby OIC bluetooth devices.
152 * @return ::CA_STATUS_OK or Appropriate error code.
153 * @retval ::CA_STATUS_OK Successful.
154 * @retval ::CA_STATUS_FAILED Operation failed.
156 CAResult_t CAEDRClientSetCallbacks();
159 * Resetting callbacks with bluetooth framework and stop OIC device discovery.
160 * @pre CAEDRClientSetCallbacks() should be invoked before using this API.
161 * @see CAEDRClientSetCallbacks().
163 void CAEDRClientUnsetCallbacks();
166 * Used to initialize the EDR client module where mutex is initialized.
167 * @return ::CA_STATUS_OK or Appropriate error code.
169 CAResult_t CAEDRClientInitialize();
172 * Destroys the Device list and mutex.
174 void CAEDRClientTerminate();
177 * Closes all the client connection to peer bluetooth devices.
179 void CAEDRClientDisconnectAll();
182 * Register callback to send the received packets from remote bluetooth
183 * device to BTAdapter.
185 * @param[in] packetReceivedCallback Callback function to register for
186 * sending network packets to EDR Adapter.
188 void CAEDRSetPacketReceivedCallback(CAEDRDataReceivedCallback packetReceivedCallback);
191 * Register callback for receiving local bluetooth adapter state.
193 * @param[in] networkStateChangeCallback Callback function to register
194 * for receiving local bluetooth adapter status.
196 void CAEDRSetNetworkChangeCallback(CAEDRNetworkStatusCallback networkStateChangeCallback);
199 * set error callback to notify error in EDR adapter.
201 * @param[in] errorHandleCallback Callback function to notify the error
202 * in the EDR adapter.
204 void CAEDRSetErrorHandler(CAEDRErrorHandleCallback errorHandleCallback);
208 * Get the local bluetooth adapter information.
210 * @param[out] info Local bluetooth adapter information.
212 * @return ::CA_STATUS_OK or Appropriate error code.
213 * @retval ::CA_STATUS_OK Successful.
214 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
215 * @retval ::CA_STATUS_FAILED Operation failed.
217 * @see CALocalConnectivity_t
220 CAResult_t CAEDRGetInterfaceInformation(CAEndpoint_t **info);
223 * Start RFCOMM server for given service UUID
225 * @return ::CA_STATUS_OK or Appropriate error code.
226 * @retval ::CA_STATUS_OK Successful.
227 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
228 * @retval ::CA_STATUS_FAILED Operation failed.
231 CAResult_t CAEDRServerStart();
236 * @return ::CA_STATUS_OK or Appropriate error code.
237 * @retval ::CA_STATUS_OK Successful.
238 * @retval ::CA_STATUS_FAILED Operation failed.
240 CAResult_t CAEDRServerStop();
243 * Used to initialize the EDR server module where mutex is initialized.
244 * @param[in] threadPool Threadpool Handle.
245 * @return ::CA_STATUS_OK or Appropriate error code.
247 CAResult_t CAEDRServerInitialize(ca_thread_pool_t handle);
250 * Terminate server for EDR.
252 void CAEDRServerTerminate();
255 * All received data will be notified to upper layer.
257 * @return ::CA_STATUS_OK or Appropriate error code.
258 * @retval ::CA_STATUS_OK Successful.
259 * @retval ::CA_STATUS_FAILED Operation failed.
262 CAResult_t CAEDRManagerReadData();
265 * This function gets bluetooth adapter enable state.
266 * @param[out] state State of the Adapter.
267 * @return ::CA_STATUS_OK or Appropriate error code.
269 CAResult_t CAEDRGetAdapterEnableState(bool *state);
272 * This function sends data to specified remote bluetooth device.
273 * @param[in] remoteAddress Remote EDR Address.
274 * @param[in] data Data to be sent.
275 * @param[in] dataLength Length of the data to be sent.
276 * @return ::CA_STATUS_OK or Appropriate error code.
278 CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress,
280 uint32_t dataLength);
283 * This function sends data to all bluetooth devices running OIC service.
284 * @param[in] data Data to be sent.
285 * @param[in] dataLength Length of the data to be sent.
286 * @return ::CA_STATUS_OK or Appropriate error code.
288 CAResult_t CAEDRClientSendMulticastData(const uint8_t *data,
289 uint32_t dataLength);
292 * This function gets bonded bluetooth device list
293 * @return ::CA_STATUS_OK or Appropriate error code.
295 CAResult_t CAEDRGetBondedDeviceList();
299 * This function starts device discovery.
301 CAResult_t CAEDRStartDeviceDiscovery(void);
308 #endif /* CA_EDR_INTERFACE_H_ */