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_
29 #include "caedradapter.h"
36 #ifndef OIC_EDR_SERVICE_ID
37 #define OIC_EDR_SERVICE_ID "12341234-1C25-481F-9DFB-59193D238280"
38 #endif //OIC_EDR_SERVICE_ID
42 STATE_DISCONNECTED, /**< State is Disconnected */
43 STATE_CONNECTED /**< State is Connected */
46 typedef struct connected_state {
47 uint8_t address[CA_MACADDR_SIZE];
48 CAConnectedState_t state;
52 * @enum CAAdapterServerType_t
53 * @brief Enum for defining different server types.
57 CA_UNICAST_SERVER = 0, /**< Unicast Server */
58 CA_MULTICAST_SERVER, /**< Multicast Server */
59 CA_SECURED_UNICAST_SERVER /**< Secured Unicast Server */
60 } CAAdapterServerType_t;
64 * @brief Structure to maintain the information of data in message queue.
68 CARemoteEndpoint_t *remoteEndpoint; /**< Remote Endpoint */
69 void *data; /**< Data to be sent */
70 uint32_t dataLen; /**< Length of the data to be sent */
74 * @struct CAEDRNetworkEvent
75 * @brief Structure to maintain the adapter information and its status.
79 CALocalConnectivity_t *info; /**< Local Connectivity Information */
80 CANetworkStatus_t status; /**< Network Status */
84 * @brief This will be used during the recive of network requests and response.
85 * @param remoteAddress [IN] EDR address of remote OIC device from which data received.
86 * @param data [IN] Data received
87 * @param dataLength [IN] Length of the Data received
88 * @param sentLength [OUT] Length of the sent data
90 * @pre Callback must be registered using CAEDRSetPacketReceivedCallback()
92 typedef void (*CAEDRDataReceivedCallback)(const char *remoteAddress,
93 const void *data, uint32_t dataLength, uint32_t *sentLength);
96 * @brief This will be used during change in network status.
97 * @param status [IN] Network Status of the adapter
100 typedef void (*CAEDRNetworkStatusCallback)(CANetworkStatus_t status);
103 * @brief Initialize the network monitor module
105 * @return #CA_STATUS_OK or Appropriate error code
106 * @retval #CA_STATUS_OK Successful
107 * @retval #CA_ADAPTER_NOT_ENABLED Initialization is successful, but bluetooth adapter is
109 * @retval #CA_STATUS_FAILED Operation failed
110 * @see CAEDRTerminateNetworkMonitor()
112 CAResult_t CAEDRInitializeNetworkMonitor();
115 * @brief Deinitialize with bluetooth adapter.
117 * @pre CAEDRInitializeNetworkMonitor() should be invoked before using this API.
118 * @see CAEDRInitializeNetworkMonitor()
120 void CAEDRTerminateNetworkMonitor(void);
123 * @brief Start Network Monitoring Process
124 * @return #CA_STATUS_OK or Appropriate error code
126 CAResult_t CAEDRStartNetworkMonitor();
129 * @brief Stop Network Monitoring Process
130 * @return #CA_STATUS_OK or Appropriate error code
132 CAResult_t CAEDRStopNetworkMonitor();
135 * @brief Sets the callback and Starts discovery for nearby OIC bluetooth devices.
137 * @return #CA_STATUS_OK or Appropriate error code
138 * @retval #CA_STATUS_OK Successful
139 * @retval #CA_STATUS_FAILED Operation failed
141 CAResult_t CAEDRClientSetCallbacks(void);
144 * @brief Resetting callbacks with bluetooth framework and stop OIC device discovery.
146 * @pre CAEDRClientSetCallbacks() should be invoked before using this API.
147 * @see CAEDRClientSetCallbacks()
149 void CAEDRClientUnsetCallbacks(void);
152 * @brief Used to initialize the EDR client module where mutex is initialized
155 void CAEDRInitializeClient(u_thread_pool_t handle);
158 * @brief Destroys the Device list and mutex.
161 void CAEDRClientTerminate();
164 * @brief Closes all the client connection to peer bluetooth devices.
167 void CAEDRClientDisconnectAll(void);
170 * @brief Register callback to send the received packets from remote bluetooth device to BTAdapter.
172 * @param packetReceivedCallback [IN] Callback function to register for sending network
173 * packets to EDR Adapter.
176 void CAEDRSetPacketReceivedCallback(CAEDRDataReceivedCallback packetReceivedCallback);
179 * @brief Register callback for receiving local bluetooth adapter state.
181 * @param networkStateChangeCallback [IN] Callback function to register for receiving local
182 * bluetooth adapter status.
185 void CAEDRSetNetworkChangeCallback(CAEDRNetworkStatusCallback networkStateChangeCallback);
189 * @brief Get the local bluetooth adapter information.
191 * @param info [IN] Local bluetooth adapter information
193 * @return #CA_STATUS_OK or Appropriate error code
194 * @retval #CA_STATUS_OK Successful
195 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
196 * @retval #CA_STATUS_FAILED Operation failed
198 * @see #CALocalConnectivity_t
201 CAResult_t CAEDRGetInterfaceInformation(CALocalConnectivity_t **info);
204 * @brief Start RFCOMM server for given service UUID
206 * @param serviceUUID [IN] The UUID of service with which RFCOMM server needs to be started.
207 * @param serverFD [IN] The RFCOMM server socket file descriptor.
209 * @return #CA_STATUS_OK or Appropriate error code
210 * @retval #CA_STATUS_OK Successful
211 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
212 * @retval #CA_STATUS_FAILED Operation failed
215 CAResult_t CAEDRServerStart(const char *serviceUUID, int *serverFD, u_thread_pool_t handle);
218 * @brief Stop RFCOMM server
220 * @param serverFD [IN] The RFCOMM server socket file descriptor which needs to be stopped.
222 * @return #CA_STATUS_OK or Appropriate error code
223 * @retval #CA_STATUS_OK Successful
224 * @retval #CA_STATUS_FAILED Operation failed
226 CAResult_t CAEDRServerStop(int serverFD);
229 * @brief Terminate server for EDR
232 void CAEDRServerTerminate();
235 * @brief All received data will be notified to upper layer.
237 * @return #CA_STATUS_OK or Appropriate error code
238 * @retval #CA_STATUS_OK Successful
239 * @retval #CA_STATUS_FAILED Operation failed
242 CAResult_t CAEDRManagerReadData(void);
245 * @brief This function gets bluetooth adapter enable state.
246 * @param state [OUT] State of the Adapter.
247 * @return #CA_STATUS_OK or Appropriate error code
249 CAResult_t CAEDRGetAdapterEnableState(bool *state);
252 * @brief This function sends data to specified remote bluetooth device.
253 * @param remoteAddress [IN] Remote EDR Address
254 * @param serviceUUID [IN] Service UUID of the device
255 * @param data [IN] Data to be sent
256 * @param dataLength [IN] Length of the data to be sent
257 * @param sentLength [OUT] Length of the actual sent data
258 * @return #CA_STATUS_OK or Appropriate error code
260 CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress, const char *serviceUUID,
261 const void *data, uint32_t dataLength, uint32_t *sentLength);
264 * @brief This function sends data to all bluetooth devices running OIC service.
265 * @param serviceUUID [IN] Service UUID of the device
266 * @param data [IN] Data to be sent
267 * @param dataLength [IN] Length of the data to be sent
268 * @param sentLength [OUT] Length of the actual sent data
269 * @return #CA_STATUS_OK or Appropriate error code
271 CAResult_t CAEDRClientSendMulticastData(const char *serviceUUID, const void *data,
272 uint32_t dataLength, uint32_t *sentLength);
278 #endif //__CA_EDR_INTERFACE_H_