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 ******************************************************************/
22 * @file caedrinterface.h
23 * @brief This file provides APIs for EDR adapter - client, server, network monitor modules
26 #ifndef __CA_EDR_INTERFACE_H_
27 #define __CA_EDR_INTERFACE_H_
30 #include "caedradapter.h"
37 #ifndef OIC_EDR_SERVICE_ID
38 #define OIC_EDR_SERVICE_ID "12341234-1C25-481F-9DFB-59193D238280"
39 #endif //OIC_EDR_SERVICE_ID
43 * @brief Structure to maintain the information of data in message queue.
47 CARemoteEndpoint_t *remoteEndpoint; /**< Remote Endpoint */
48 void *data; /**< Data to be sent */
49 uint32_t dataLen; /**< Length of the data to be sent */
53 * @struct CAEDRNetworkEvent
54 * @brief Structure to maintain the adapter information and its status.
58 CALocalConnectivity_t *info; /**< Local Connectivity Information */
59 CANetworkStatus_t status; /**< Network Status */
63 * @brief This will be used during the recive of network requests and response.
64 * @param remoteAddress [IN] EDR address of remote OIC device
65 * @param data [IN] Data received
66 * @param dataLength [IN] Length of the Data received
67 * @param sentLength [IN] Length of the sent data
69 * @pre Callback must be registered using CAEDRSetPacketReceivedCallback()
71 typedef void (*CAEDRDataReceivedCallback)(const char *remoteAddress, void *data, uint32_t dataLength,
72 uint32_t *sentLength);
75 * @brief This will be used during change in network status.
76 * @param status [IN] Network Status of the adapter
79 typedef void (*CAEDRNetworkStatusCallback)(CANetworkStatus_t status);
82 * @brief Initialize the network monitor module
84 * @return #CA_STATUS_OK or Appropriate error code
85 * @retval #CA_STATUS_OK Successful
86 * @retval #CA_ADAPTER_NOT_ENABLED Initialization is successful, but bluetooth adapter is
88 * @retval #CA_STATUS_FAILED Operation failed
89 * @see CAEDRTerminateNetworkMonitor()
91 CAResult_t CAEDRInitializeNetworkMonitor();
94 * @brief Deinitialize with bluetooth adapter.
96 * @pre CAEDRInitializeNetworkMonitor() should be invoked before using this API.
97 * @see CAEDRInitializeNetworkMonitor()
99 void CAEDRTerminateNetworkMonitor(void);
102 * @brief Start Network Monitoring Process
103 * @return #CA_STATUS_OK or Appropriate error code
105 CAResult_t CAEDRStartNetworkMonitor();
108 * @brief Stop Network Monitoring Process
109 * @return #CA_STATUS_OK or Appropriate error code
111 CAResult_t CAEDRStopNetworkMonitor();
114 * @brief Sets the callback and Starts discovery for nearby OIC bluetooth devices.
116 * @return #CA_STATUS_OK or Appropriate error code
117 * @retval #CA_STATUS_OK Successful
118 * @retval #CA_STATUS_FAILED Operation failed
120 CAResult_t CAEDRClientSetCallbacks(void);
123 * @brief Resetting callbacks with bluetooth framework and stop OIC device discovery.
125 * @pre CAEDRClientSetCallbacks() should be invoked before using this API.
126 * @see CAEDRClientSetCallbacks()
128 void CAEDRClientUnsetCallbacks(void);
131 * @brief Used to initialize the EDR client module where mutex is initialized
134 void CAEDRInitializeClient();
137 * @brief Destroys the Device list and mutex.
140 void CAEDRTerminateClient();
143 * @brief Closes all the client connection to peer bluetooth devices.
146 void CAEDRClientDisconnectAll(void);
149 * @brief Register callback to send the received packets from remote bluetooth device to BTAdapter.
151 * @param packetReceivedCallback [IN] Callback function to register for sending network
152 * packets to EDR Adapter.
155 void CAEDRSetPacketReceivedCallback(CAEDRDataReceivedCallback packetReceivedCallback);
158 * @brief Register callback for receiving local bluetooth adapter state.
160 * @param networkStateChangeCallback [IN] Callback function to register for receiving local
161 * bluetooth adapter status.
164 void CAEDRSetNetworkChangeCallback(CAEDRNetworkStatusCallback networkStateChangeCallback);
168 * @brief Get the local bluetooth adapter information.
170 * @param info [IN] Local bluetooth adapter information
172 * @return #CA_STATUS_OK or Appropriate error code
173 * @retval #CA_STATUS_OK Successful
174 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
175 * @retval #CA_STATUS_FAILED Operation failed
177 * @see #CALocalConnectivity_t
180 CAResult_t CAEDRGetInterfaceInformation(CALocalConnectivity_t **info);
183 * @brief Start RFCOMM server for given service UUID
185 * @param serviceUUID [IN] The UUID of service with which RFCOMM server needs to be started.
186 * @param serverFD [IN] The RFCOMM server socket file descriptor.
188 * @return #CA_STATUS_OK or Appropriate error code
189 * @retval #CA_STATUS_OK Successful
190 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
191 * @retval #CA_STATUS_FAILED Operation failed
194 CAResult_t CAEDRServerStart(const char *serviceUUID, int32_t *serverFD);
197 * @brief Stop RFCOMM server
199 * @param serverFD [IN] The RFCOMM server socket file descriptor which needs to be stopped.
201 * @return #CA_STATUS_OK or Appropriate error code
202 * @retval #CA_STATUS_OK Successful
203 * @retval #CA_STATUS_FAILED Operation failed
205 CAResult_t CAEDRServerStop(const int32_t serverFD);
208 * @brief All received data will be notified to upper layer.
210 * @return #CA_STATUS_OK or Appropriate error code
211 * @retval #CA_STATUS_OK Successful
212 * @retval #CA_STATUS_FAILED Operation failed
215 CAResult_t CAEDRManagerReadData(void);
218 * @brief This function gets bluetooth adapter enable state.
219 * @param state [OUT] State of the Adapter.
220 * @return #CA_STATUS_OK or Appropriate error code
222 CAResult_t CAEDRGetAdapterEnableState(CABool_t *state);
225 * @brief This function sends data to specified remote bluetooth device.
226 * @param remoteAddress [IN] Remote EDR Address
227 * @param serviceUUID [IN] Service UUID of the device
228 * @param data [IN] Data to be sent
229 * @param dataLength [IN] Length of the data to be sent
230 * @param sentLength [IN] Length of the actual sent data
231 * @return #CA_STATUS_OK or Appropriate error code
233 CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress, const char *serviceUUID,
234 void *data, uint32_t dataLength, uint32_t *sentLength);
237 * @brief This function sends data to all bluetooth devices running OIC service.
238 * @param serviceUUID [IN] Service UUID of the device
239 * @param data [IN] Data to be sent
240 * @param dataLength [IN] Length of the data to be sent
241 * @param sentLength [IN] Length of the actual sent data
242 * @return #CA_STATUS_OK or Appropriate error code
244 CAResult_t CAEDRClientSendMulticastData(const char *serviceUUID, void *data,
245 uint32_t dataLength, uint32_t *sentLength);
251 #endif //__CA_EDR_INTERFACE_H_