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 CAAdapterServerType_t
56 * @brief Enum for defining different server types.
60 CA_UNICAST_SERVER = 0, /**< Unicast Server */
61 CA_MULTICAST_SERVER, /**< Multicast Server */
62 CA_SECURED_UNICAST_SERVER /**< Secured Unicast Server */
63 } CAAdapterServerType_t;
67 * @brief Structure to maintain the information of data in message queue.
71 CAEndpoint_t *remoteEndpoint; /**< Remote Endpoint */
72 void *data; /**< Data to be sent */
73 uint32_t dataLen; /**< Length of the data to be sent */
77 * @struct CAEDRNetworkEvent
78 * @brief Structure to maintain the adapter information and its status.
82 CAEndpoint_t *info; /**< Local Connectivity Information */
83 CANetworkStatus_t status; /**< Network Status */
87 * @brief This will be used during the recive of network requests and response.
88 * @param remoteAddress [IN] EDR address of remote OIC device from which data received.
89 * @param data [IN] Data received
90 * @param dataLength [IN] Length of the Data received
91 * @param sentLength [OUT] Length of the sent data
93 * @pre Callback must be registered using CAEDRSetPacketReceivedCallback()
95 typedef void (*CAEDRDataReceivedCallback)(const char *remoteAddress, const void *data,
96 uint32_t dataLength, uint32_t *sentLength);
99 * @brief This will be used during change in network status.
100 * @param status [IN] Network Status of the adapter
103 typedef void (*CAEDRNetworkStatusCallback)(CANetworkStatus_t status);
106 * @brief Callback to notify the error in the EDR adapter
107 * @param remoteAddress [IN] Remote EDR Address
108 * @param serviceUUID [IN] Service UUID of the device
109 * @param data [IN] data containing token, uri and coap data
110 * @param dataLength [IN] length of data
111 * @param result [IN] error code as defined in CAResult_t
113 * @pre Callback must be registered using CAEDRSetPacketReceivedCallback()
115 typedef void (*CAEDRErrorHandleCallback)(const char *remoteAddress, const char *serviceUUID,
116 const void *data, uint32_t dataLength, CAResult_t result);
119 * @brief Initialize the network monitor module
120 * @param threadPool [IN] Threadpool Handle
121 * @return #CA_STATUS_OK or Appropriate error code
122 * @retval #CA_STATUS_OK Successful
123 * @retval #CA_ADAPTER_NOT_ENABLED Initialization is successful, but bluetooth adapter is
125 * @retval #CA_STATUS_FAILED Operation failed
126 * @see CAEDRTerminateNetworkMonitor()
128 CAResult_t CAEDRInitializeNetworkMonitor(const ca_thread_pool_t threadPool);
131 * @brief Deinitialize with bluetooth adapter.
133 * @pre CAEDRInitializeNetworkMonitor() should be invoked before using this API.
134 * @see CAEDRInitializeNetworkMonitor()
136 void CAEDRTerminateNetworkMonitor();
139 * @brief Start Network Monitoring Process
140 * @return #CA_STATUS_OK or Appropriate error code
142 CAResult_t CAEDRStartNetworkMonitor();
145 * @brief Stop Network Monitoring Process
146 * @return #CA_STATUS_OK or Appropriate error code
148 CAResult_t CAEDRStopNetworkMonitor();
151 * @brief Sets the callback and Starts discovery for nearby OIC bluetooth devices.
153 * @return #CA_STATUS_OK or Appropriate error code
154 * @retval #CA_STATUS_OK Successful
155 * @retval #CA_STATUS_FAILED Operation failed
157 CAResult_t CAEDRClientSetCallbacks();
160 * @brief Resetting callbacks with bluetooth framework and stop OIC device discovery.
162 * @pre CAEDRClientSetCallbacks() should be invoked before using this API.
163 * @see CAEDRClientSetCallbacks()
165 void CAEDRClientUnsetCallbacks();
168 * @brief Used to initialize the EDR client module where mutex is initialized
171 void CAEDRInitializeClient(ca_thread_pool_t handle);
174 * @brief Destroys the Device list and mutex.
177 void CAEDRClientTerminate();
180 * @brief Closes all the client connection to peer bluetooth devices.
183 void CAEDRClientDisconnectAll();
186 * @brief Register callback to send the received packets from remote bluetooth device to BTAdapter.
188 * @param packetReceivedCallback [IN] Callback function to register for sending network
189 * packets to EDR Adapter.
192 void CAEDRSetPacketReceivedCallback(CAEDRDataReceivedCallback packetReceivedCallback);
195 * @brief Register callback for receiving local bluetooth adapter state.
197 * @param networkStateChangeCallback [IN] Callback function to register for receiving local
198 * bluetooth adapter status.
201 void CAEDRSetNetworkChangeCallback(CAEDRNetworkStatusCallback networkStateChangeCallback);
204 * @brief set error callback to notify error in EDR adapter
206 * @param errorHandleCallback [IN] Callback function to notify the error in the EDR adapter
209 void CAEDRSetErrorHandler(CAEDRErrorHandleCallback errorHandleCallback);
213 * @brief Get the local bluetooth adapter information.
215 * @param info [OUT] Local bluetooth adapter information
217 * @return #CA_STATUS_OK or Appropriate error code
218 * @retval #CA_STATUS_OK Successful
219 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
220 * @retval #CA_STATUS_FAILED Operation failed
222 * @see #CALocalConnectivity_t
225 CAResult_t CAEDRGetInterfaceInformation(CAEndpoint_t **info);
228 * @brief Start RFCOMM server for given service UUID
230 * @param serviceUUID [IN] The UUID of service with which RFCOMM server needs to be started.
231 * @param serverFD [IN] The RFCOMM server socket file descriptor.
232 * @param handle [IN] Threadpool Handle
234 * @return #CA_STATUS_OK or Appropriate error code
235 * @retval #CA_STATUS_OK Successful
236 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
237 * @retval #CA_STATUS_FAILED Operation failed
240 CAResult_t CAEDRServerStart(const char *serviceUUID, int *serverFD, ca_thread_pool_t handle);
243 * @brief Stop RFCOMM server
245 * @param serverFD [IN] The RFCOMM server socket file descriptor which needs to be stopped.
247 * @return #CA_STATUS_OK or Appropriate error code
248 * @retval #CA_STATUS_OK Successful
249 * @retval #CA_STATUS_FAILED Operation failed
251 CAResult_t CAEDRServerStop(int serverFD);
254 * @brief Terminate server for EDR
257 void CAEDRServerTerminate();
260 * @brief All received data will be notified to upper layer.
262 * @return #CA_STATUS_OK or Appropriate error code
263 * @retval #CA_STATUS_OK Successful
264 * @retval #CA_STATUS_FAILED Operation failed
267 CAResult_t CAEDRManagerReadData();
270 * @brief This function gets bluetooth adapter enable state.
271 * @param state [OUT] State of the Adapter.
272 * @return #CA_STATUS_OK or Appropriate error code
274 CAResult_t CAEDRGetAdapterEnableState(bool *state);
277 * @brief This function sends data to specified remote bluetooth device.
278 * @param remoteAddress [IN] Remote EDR Address
279 * @param serviceUUID [IN] Service UUID of the device
280 * @param data [IN] Data to be sent
281 * @param dataLength [IN] Length of the data to be sent
282 * @param sentLength [OUT] Length of the actual sent data
283 * @return #CA_STATUS_OK or Appropriate error code
285 CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress, const char *serviceUUID,
286 const void *data, uint32_t dataLength, uint32_t *sentLength);
289 * @brief This function sends data to all bluetooth devices running OIC service.
290 * @param serviceUUID [IN] Service UUID of the device
291 * @param data [IN] Data to be sent
292 * @param dataLength [IN] Length of the data to be sent
293 * @param sentLength [OUT] Length of the actual sent data
294 * @return #CA_STATUS_OK or Appropriate error code
296 CAResult_t CAEDRClientSendMulticastData(const char *serviceUUID, const void *data,
297 uint32_t dataLength, uint32_t *sentLength);
300 * @brief This function gets bonded bluetooth device list
301 * @return #CA_STATUS_OK or Appropriate error code
303 CAResult_t CAEDRGetBondedDeviceList();
309 #endif /* CA_EDR_INTERFACE_H_ */