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 Initialize the network monitor module
107 * @param threadPool [IN] Threadpool Handle
108 * @return #CA_STATUS_OK or Appropriate error code
109 * @retval #CA_STATUS_OK Successful
110 * @retval #CA_ADAPTER_NOT_ENABLED Initialization is successful, but bluetooth adapter is
112 * @retval #CA_STATUS_FAILED Operation failed
113 * @see CAEDRTerminateNetworkMonitor()
115 CAResult_t CAEDRInitializeNetworkMonitor(const ca_thread_pool_t threadPool);
118 * @brief Deinitialize with bluetooth adapter.
120 * @pre CAEDRInitializeNetworkMonitor() should be invoked before using this API.
121 * @see CAEDRInitializeNetworkMonitor()
123 void CAEDRTerminateNetworkMonitor();
126 * @brief Start Network Monitoring Process
127 * @return #CA_STATUS_OK or Appropriate error code
129 CAResult_t CAEDRStartNetworkMonitor();
132 * @brief Stop Network Monitoring Process
133 * @return #CA_STATUS_OK or Appropriate error code
135 CAResult_t CAEDRStopNetworkMonitor();
138 * @brief Sets the callback and Starts discovery for nearby OIC bluetooth devices.
140 * @return #CA_STATUS_OK or Appropriate error code
141 * @retval #CA_STATUS_OK Successful
142 * @retval #CA_STATUS_FAILED Operation failed
144 CAResult_t CAEDRClientSetCallbacks();
147 * @brief Resetting callbacks with bluetooth framework and stop OIC device discovery.
149 * @pre CAEDRClientSetCallbacks() should be invoked before using this API.
150 * @see CAEDRClientSetCallbacks()
152 void CAEDRClientUnsetCallbacks();
155 * @brief Used to initialize the EDR client module where mutex is initialized
158 void CAEDRInitializeClient(ca_thread_pool_t handle);
161 * @brief Destroys the Device list and mutex.
164 void CAEDRClientTerminate();
167 * @brief Closes all the client connection to peer bluetooth devices.
170 void CAEDRClientDisconnectAll();
173 * @brief Register callback to send the received packets from remote bluetooth device to BTAdapter.
175 * @param packetReceivedCallback [IN] Callback function to register for sending network
176 * packets to EDR Adapter.
179 void CAEDRSetPacketReceivedCallback(CAEDRDataReceivedCallback packetReceivedCallback);
182 * @brief Register callback for receiving local bluetooth adapter state.
184 * @param networkStateChangeCallback [IN] Callback function to register for receiving local
185 * bluetooth adapter status.
188 void CAEDRSetNetworkChangeCallback(CAEDRNetworkStatusCallback networkStateChangeCallback);
191 * @brief Get the local bluetooth adapter information.
193 * @param info [OUT] Local bluetooth adapter information
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
200 * @see #CALocalConnectivity_t
203 CAResult_t CAEDRGetInterfaceInformation(CAEndpoint_t **info);
206 * @brief Start RFCOMM server for given service UUID
208 * @param serviceUUID [IN] The UUID of service with which RFCOMM server needs to be started.
209 * @param serverFD [IN] The RFCOMM server socket file descriptor.
210 * @param handle [IN] Threadpool Handle
212 * @return #CA_STATUS_OK or Appropriate error code
213 * @retval #CA_STATUS_OK Successful
214 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
215 * @retval #CA_STATUS_FAILED Operation failed
218 CAResult_t CAEDRServerStart(const char *serviceUUID, int *serverFD, ca_thread_pool_t handle);
221 * @brief Stop RFCOMM server
223 * @param serverFD [IN] The RFCOMM server socket file descriptor which needs to be stopped.
225 * @return #CA_STATUS_OK or Appropriate error code
226 * @retval #CA_STATUS_OK Successful
227 * @retval #CA_STATUS_FAILED Operation failed
229 CAResult_t CAEDRServerStop(int serverFD);
232 * @brief Terminate server for EDR
235 void CAEDRServerTerminate();
238 * @brief All received data will be notified to upper layer.
240 * @return #CA_STATUS_OK or Appropriate error code
241 * @retval #CA_STATUS_OK Successful
242 * @retval #CA_STATUS_FAILED Operation failed
245 CAResult_t CAEDRManagerReadData();
248 * @brief This function gets bluetooth adapter enable state.
249 * @param state [OUT] State of the Adapter.
250 * @return #CA_STATUS_OK or Appropriate error code
252 CAResult_t CAEDRGetAdapterEnableState(bool *state);
255 * @brief This function sends data to specified remote bluetooth device.
256 * @param remoteAddress [IN] Remote EDR Address
257 * @param serviceUUID [IN] Service UUID of the device
258 * @param data [IN] Data to be sent
259 * @param dataLength [IN] Length of the data to be sent
260 * @param sentLength [OUT] Length of the actual sent data
261 * @return #CA_STATUS_OK or Appropriate error code
263 CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress, const char *serviceUUID,
264 const void *data, uint32_t dataLength, uint32_t *sentLength);
267 * @brief This function sends data to all bluetooth devices running OIC service.
268 * @param serviceUUID [IN] Service UUID of the device
269 * @param data [IN] Data to be sent
270 * @param dataLength [IN] Length of the data to be sent
271 * @param sentLength [OUT] Length of the actual sent data
272 * @return #CA_STATUS_OK or Appropriate error code
274 CAResult_t CAEDRClientSendMulticastData(const char *serviceUUID, const void *data,
275 uint32_t dataLength, uint32_t *sentLength);
278 * @brief This function gets bonded bluetooth device list
279 * @return #CA_STATUS_OK or Appropriate error code
281 CAResult_t CAEDRGetBondedDeviceList();
287 #endif /* CA_EDR_INTERFACE_H_ */