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
42 typedef struct connected_state {
43 char address[CA_MACADDR_SIZE];
48 * @enum CAAdapterServerType_t
49 * @brief Enum for defining different server types.
53 CA_UNICAST_SERVER = 0, /**< Unicast Server */
54 CA_MULTICAST_SERVER, /**< Multicast Server */
55 CA_SECURED_UNICAST_SERVER /**< Secured Unicast Server */
56 } CAAdapterServerType_t;
60 * @brief Structure to maintain the information of data in message queue.
64 CARemoteEndpoint_t *remoteEndpoint; /**< Remote Endpoint */
65 void *data; /**< Data to be sent */
66 uint32_t dataLen; /**< Length of the data to be sent */
70 * @struct CAEDRNetworkEvent
71 * @brief Structure to maintain the adapter information and its status.
75 CALocalConnectivity_t *info; /**< Local Connectivity Information */
76 CANetworkStatus_t status; /**< Network Status */
80 * @brief This will be used during the recive of network requests and response.
81 * @param remoteAddress [IN] EDR address of remote OIC device
82 * @param data [IN] Data received
83 * @param dataLength [IN] Length of the Data received
84 * @param sentLength [IN] Length of the sent data
86 * @pre Callback must be registered using CAEDRSetPacketReceivedCallback()
88 typedef void (*CAEDRDataReceivedCallback)(const char *remoteAddress, void *data, uint32_t dataLength,
89 uint32_t *sentLength);
92 * @brief This will be used during change in network status.
93 * @param status [IN] Network Status of the adapter
96 typedef void (*CAEDRNetworkStatusCallback)(CANetworkStatus_t status);
99 * @brief Initialize the network monitor module
101 * @return #CA_STATUS_OK or Appropriate error code
102 * @retval #CA_STATUS_OK Successful
103 * @retval #CA_ADAPTER_NOT_ENABLED Initialization is successful, but bluetooth adapter is
105 * @retval #CA_STATUS_FAILED Operation failed
106 * @see CAEDRTerminateNetworkMonitor()
108 CAResult_t CAEDRInitializeNetworkMonitor();
111 * @brief Deinitialize with bluetooth adapter.
113 * @pre CAEDRInitializeNetworkMonitor() should be invoked before using this API.
114 * @see CAEDRInitializeNetworkMonitor()
116 void CAEDRTerminateNetworkMonitor(void);
119 * @brief Start Network Monitoring Process
120 * @return #CA_STATUS_OK or Appropriate error code
122 CAResult_t CAEDRStartNetworkMonitor();
125 * @brief Stop Network Monitoring Process
126 * @return #CA_STATUS_OK or Appropriate error code
128 CAResult_t CAEDRStopNetworkMonitor();
131 * @brief Sets the callback and Starts discovery for nearby OIC bluetooth devices.
133 * @return #CA_STATUS_OK or Appropriate error code
134 * @retval #CA_STATUS_OK Successful
135 * @retval #CA_STATUS_FAILED Operation failed
137 CAResult_t CAEDRClientSetCallbacks(void);
140 * @brief Resetting callbacks with bluetooth framework and stop OIC device discovery.
142 * @pre CAEDRClientSetCallbacks() should be invoked before using this API.
143 * @see CAEDRClientSetCallbacks()
145 void CAEDRClientUnsetCallbacks(void);
148 * @brief Used to initialize the EDR client module where mutex is initialized
151 void CAEDRInitializeClient(u_thread_pool_t handle);
154 * @brief Destroys the Device list and mutex.
157 void CAEDRTerminateClient();
160 * @brief Closes all the client connection to peer bluetooth devices.
163 void CAEDRClientDisconnectAll(void);
166 * @brief Register callback to send the received packets from remote bluetooth device to BTAdapter.
168 * @param packetReceivedCallback [IN] Callback function to register for sending network
169 * packets to EDR Adapter.
172 void CAEDRSetPacketReceivedCallback(CAEDRDataReceivedCallback packetReceivedCallback);
175 * @brief Register callback for receiving local bluetooth adapter state.
177 * @param networkStateChangeCallback [IN] Callback function to register for receiving local
178 * bluetooth adapter status.
181 void CAEDRSetNetworkChangeCallback(CAEDRNetworkStatusCallback networkStateChangeCallback);
185 * @brief Get the local bluetooth adapter information.
187 * @param info [IN] Local bluetooth adapter information
189 * @return #CA_STATUS_OK or Appropriate error code
190 * @retval #CA_STATUS_OK Successful
191 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
192 * @retval #CA_STATUS_FAILED Operation failed
194 * @see #CALocalConnectivity_t
197 CAResult_t CAEDRGetInterfaceInformation(CALocalConnectivity_t **info);
200 * @brief Start RFCOMM server for given service UUID
202 * @param serviceUUID [IN] The UUID of service with which RFCOMM server needs to be started.
203 * @param serverFD [IN] The RFCOMM server socket file descriptor.
205 * @return #CA_STATUS_OK or Appropriate error code
206 * @retval #CA_STATUS_OK Successful
207 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
208 * @retval #CA_STATUS_FAILED Operation failed
211 CAResult_t CAEDRServerStart(const char *serviceUUID, int32_t *serverFD, u_thread_pool_t handle);
214 * @brief Stop RFCOMM server
216 * @param serverFD [IN] The RFCOMM server socket file descriptor which needs to be stopped.
218 * @return #CA_STATUS_OK or Appropriate error code
219 * @retval #CA_STATUS_OK Successful
220 * @retval #CA_STATUS_FAILED Operation failed
222 CAResult_t CAEDRServerStop(const int32_t serverFD);
225 * @brief All received data will be notified to upper layer.
227 * @return #CA_STATUS_OK or Appropriate error code
228 * @retval #CA_STATUS_OK Successful
229 * @retval #CA_STATUS_FAILED Operation failed
232 CAResult_t CAEDRManagerReadData(void);
235 * @brief This function gets bluetooth adapter enable state.
236 * @param state [OUT] State of the Adapter.
237 * @return #CA_STATUS_OK or Appropriate error code
239 CAResult_t CAEDRGetAdapterEnableState(CABool_t *state);
242 * @brief This function sends data to specified remote bluetooth device.
243 * @param remoteAddress [IN] Remote EDR Address
244 * @param serviceUUID [IN] Service UUID of the device
245 * @param data [IN] Data to be sent
246 * @param dataLength [IN] Length of the data to be sent
247 * @param sentLength [IN] Length of the actual sent data
248 * @return #CA_STATUS_OK or Appropriate error code
250 CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress, const char *serviceUUID,
251 void *data, uint32_t dataLength, uint32_t *sentLength);
254 * @brief This function sends data to all bluetooth devices running OIC service.
255 * @param serviceUUID [IN] Service UUID of the device
256 * @param data [IN] Data to be sent
257 * @param dataLength [IN] Length of the data to be sent
258 * @param sentLength [IN] Length of the actual sent data
259 * @return #CA_STATUS_OK or Appropriate error code
261 CAResult_t CAEDRClientSendMulticastData(const char *serviceUUID, void *data,
262 uint32_t dataLength, uint32_t *sentLength);
268 #endif //__CA_EDR_INTERFACE_H_