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 {
49 uint8_t address[CA_MACADDR_SIZE];
50 CAConnectedState_t state;
54 * @enum CAAdapterServerType_t
55 * @brief Enum for defining different server types.
59 CA_UNICAST_SERVER = 0, /**< Unicast Server */
60 CA_MULTICAST_SERVER, /**< Multicast Server */
61 CA_SECURED_UNICAST_SERVER /**< Secured Unicast Server */
62 } CAAdapterServerType_t;
66 * @brief Structure to maintain the information of data in message queue.
70 CARemoteEndpoint_t *remoteEndpoint; /**< Remote Endpoint */
71 void *data; /**< Data to be sent */
72 uint32_t dataLen; /**< Length of the data to be sent */
76 * @struct CAEDRNetworkEvent
77 * @brief Structure to maintain the adapter information and its status.
81 CALocalConnectivity_t *info; /**< Local Connectivity Information */
82 CANetworkStatus_t status; /**< Network Status */
86 * @brief This will be used during the recive of network requests and response.
87 * @param remoteAddress [IN] EDR address of remote OIC device from which data received.
88 * @param data [IN] Data received
89 * @param dataLength [IN] Length of the Data received
90 * @param sentLength [OUT] Length of the sent data
92 * @pre Callback must be registered using CAEDRSetPacketReceivedCallback()
94 typedef void (*CAEDRDataReceivedCallback)(const char *remoteAddress,
95 const void *data, uint32_t dataLength, uint32_t *sentLength);
98 * @brief This will be used during change in network status.
99 * @param status [IN] Network Status of the adapter
102 typedef void (*CAEDRNetworkStatusCallback)(CANetworkStatus_t status);
105 * @brief Initialize the network monitor module
107 * @return #CA_STATUS_OK or Appropriate error code
108 * @retval #CA_STATUS_OK Successful
109 * @retval #CA_ADAPTER_NOT_ENABLED Initialization is successful, but bluetooth adapter is
111 * @retval #CA_STATUS_FAILED Operation failed
112 * @see CAEDRTerminateNetworkMonitor()
114 CAResult_t CAEDRInitializeNetworkMonitor();
117 * @brief Deinitialize with bluetooth adapter.
119 * @pre CAEDRInitializeNetworkMonitor() should be invoked before using this API.
120 * @see CAEDRInitializeNetworkMonitor()
122 void CAEDRTerminateNetworkMonitor(void);
125 * @brief Start Network Monitoring Process
126 * @return #CA_STATUS_OK or Appropriate error code
128 CAResult_t CAEDRStartNetworkMonitor();
131 * @brief Stop Network Monitoring Process
132 * @return #CA_STATUS_OK or Appropriate error code
134 CAResult_t CAEDRStopNetworkMonitor();
137 * @brief Sets the callback and Starts discovery for nearby OIC bluetooth devices.
139 * @return #CA_STATUS_OK or Appropriate error code
140 * @retval #CA_STATUS_OK Successful
141 * @retval #CA_STATUS_FAILED Operation failed
143 CAResult_t CAEDRClientSetCallbacks(void);
146 * @brief Resetting callbacks with bluetooth framework and stop OIC device discovery.
148 * @pre CAEDRClientSetCallbacks() should be invoked before using this API.
149 * @see CAEDRClientSetCallbacks()
151 void CAEDRClientUnsetCallbacks(void);
154 * @brief Used to initialize the EDR client module where mutex is initialized
157 void CAEDRInitializeClient(ca_thread_pool_t handle);
160 * @brief Destroys the Device list and mutex.
163 void CAEDRClientTerminate();
166 * @brief Closes all the client connection to peer bluetooth devices.
169 void CAEDRClientDisconnectAll(void);
172 * @brief Register callback to send the received packets from remote bluetooth device to BTAdapter.
174 * @param packetReceivedCallback [IN] Callback function to register for sending network
175 * packets to EDR Adapter.
178 void CAEDRSetPacketReceivedCallback(CAEDRDataReceivedCallback packetReceivedCallback);
181 * @brief Register callback for receiving local bluetooth adapter state.
183 * @param networkStateChangeCallback [IN] Callback function to register for receiving local
184 * bluetooth adapter status.
187 void CAEDRSetNetworkChangeCallback(CAEDRNetworkStatusCallback networkStateChangeCallback);
191 * @brief Get the local bluetooth adapter information.
193 * @param info [IN] 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(CALocalConnectivity_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.
211 * @return #CA_STATUS_OK or Appropriate error code
212 * @retval #CA_STATUS_OK Successful
213 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
214 * @retval #CA_STATUS_FAILED Operation failed
217 CAResult_t CAEDRServerStart(const char *serviceUUID, int *serverFD, ca_thread_pool_t handle);
220 * @brief Stop RFCOMM server
222 * @param serverFD [IN] The RFCOMM server socket file descriptor which needs to be stopped.
224 * @return #CA_STATUS_OK or Appropriate error code
225 * @retval #CA_STATUS_OK Successful
226 * @retval #CA_STATUS_FAILED Operation failed
228 CAResult_t CAEDRServerStop(int serverFD);
231 * @brief Terminate server for EDR
234 void CAEDRServerTerminate();
237 * @brief All received data will be notified to upper layer.
239 * @return #CA_STATUS_OK or Appropriate error code
240 * @retval #CA_STATUS_OK Successful
241 * @retval #CA_STATUS_FAILED Operation failed
244 CAResult_t CAEDRManagerReadData(void);
247 * @brief This function gets bluetooth adapter enable state.
248 * @param state [OUT] State of the Adapter.
249 * @return #CA_STATUS_OK or Appropriate error code
251 CAResult_t CAEDRGetAdapterEnableState(bool *state);
254 * @brief This function sends data to specified remote bluetooth device.
255 * @param remoteAddress [IN] Remote EDR Address
256 * @param serviceUUID [IN] Service UUID of the device
257 * @param data [IN] Data to be sent
258 * @param dataLength [IN] Length of the data to be sent
259 * @param sentLength [OUT] Length of the actual sent data
260 * @return #CA_STATUS_OK or Appropriate error code
262 CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress, const char *serviceUUID,
263 const void *data, uint32_t dataLength, uint32_t *sentLength);
266 * @brief This function sends data to all bluetooth devices running OIC service.
267 * @param serviceUUID [IN] Service UUID of the device
268 * @param data [IN] Data to be sent
269 * @param dataLength [IN] Length of the data to be sent
270 * @param sentLength [OUT] Length of the actual sent data
271 * @return #CA_STATUS_OK or Appropriate error code
273 CAResult_t CAEDRClientSendMulticastData(const char *serviceUUID, const void *data,
274 uint32_t dataLength, uint32_t *sentLength);
280 #endif //__CA_EDR_INTERFACE_H_