caedrinterface.h 8.81 KB
Newer Older
1
/******************************************************************
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * Copyright 2014 Samsung Electronics All Rights Reserved.
 *
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 ******************************************************************/

/**
22 23 24 25
 * @file
 *
 * This file provides APIs for EDR adapter - client, server, network monitor
 * modules.
26 27
 */

28 29
#ifndef CA_EDR_INTERFACE_H_
#define CA_EDR_INTERFACE_H_
30 31 32 33 34 35 36 37 38 39 40 41

#include "caedradapter.h"

#ifdef __cplusplus
extern "C"
{
#endif

#ifndef OIC_EDR_SERVICE_ID
#define OIC_EDR_SERVICE_ID "12341234-1C25-481F-9DFB-59193D238280"
#endif //OIC_EDR_SERVICE_ID

42 43
typedef enum
{
44 45
    STATE_DISCONNECTED, /**< State is Disconnected */
    STATE_CONNECTED /**< State is Connected */
46
} CAConnectedState_t;
47

48 49
typedef struct connected_state
{
50 51
    uint8_t address[CA_MACADDR_SIZE];
    CAConnectedState_t state;
52 53 54
} state_t;

/**
55
 * @enum  CAAdapterServerType_t
56 57 58 59
 * @brief Enum for defining different server types.
 */
typedef enum
{
60 61 62
    CA_UNICAST_SERVER = 0,    /**< Unicast Server */
    CA_MULTICAST_SERVER,      /**< Multicast Server */
    CA_SECURED_UNICAST_SERVER /**< Secured Unicast Server */
63 64
} CAAdapterServerType_t;

65 66
/**
 * @struct CAEDRData
67
 * @brief  Structure to maintain the information of data in message queue.
68 69 70 71 72 73 74 75 76 77
 */
typedef struct
{
    CARemoteEndpoint_t *remoteEndpoint; /**< Remote Endpoint */
    void *data;                         /**< Data to be sent */
    uint32_t dataLen;                   /**< Length of the data to be sent */
} CAEDRData;

/**
 * @struct CAEDRNetworkEvent
78
 * @brief  Structure to maintain the adapter information and its status.
79 80 81
 */
typedef struct
{
82 83
    CALocalConnectivity_t *info; /**< Local Connectivity Information */
    CANetworkStatus_t status;    /**< Network Status */
84 85 86 87
} CAEDRNetworkEvent;

/**
 * @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 90
 * @param data          [IN] Data received
 * @param dataLength    [IN] Length of the Data received
91
 * @param sentLength    [OUT] Length of the sent data
92 93 94
 * @return NONE
 * @pre Callback must be registered using CAEDRSetPacketReceivedCallback()
 */
95 96
typedef void (*CAEDRDataReceivedCallback)(const char *remoteAddress, const void *data,
                                          uint32_t dataLength, uint32_t *sentLength);
97 98 99

/**
 * @brief This will be used during change in network status.
100
 * @param status        [IN] Network Status of the adapter
101 102 103 104 105 106
 * @return NONE
 */
typedef void (*CAEDRNetworkStatusCallback)(CANetworkStatus_t status);

/**
 * @brief  Initialize the network monitor module
107
 * @param  threadPool   [IN] Threadpool Handle
108 109 110 111 112 113 114
 * @return #CA_STATUS_OK or Appropriate error code
 * @retval #CA_STATUS_OK  Successful
 * @retval #CA_ADAPTER_NOT_ENABLED Initialization is successful, but bluetooth adapter is
 *                                 not enabled.
 * @retval #CA_STATUS_FAILED Operation failed
 * @see  CAEDRTerminateNetworkMonitor()
 */
115
CAResult_t CAEDRInitializeNetworkMonitor(const ca_thread_pool_t threadPool);
116 117 118 119

/**
 * @brief  Deinitialize with bluetooth adapter.
 * @return NONE
120 121
 * @pre    CAEDRInitializeNetworkMonitor() should be invoked before using this API.
 * @see    CAEDRInitializeNetworkMonitor()
122
 */
123
void CAEDRTerminateNetworkMonitor();
124 125

/**
126
 * @brief  Start Network Monitoring Process
127 128 129 130 131
 * @return #CA_STATUS_OK or Appropriate error code
 */
CAResult_t CAEDRStartNetworkMonitor();

/**
132
 * @brief  Stop Network Monitoring Process
133 134 135 136 137 138 139 140 141 142 143
 * @return #CA_STATUS_OK or Appropriate error code
 */
CAResult_t CAEDRStopNetworkMonitor();

/**
 * @brief  Sets the callback and Starts discovery for nearby OIC bluetooth devices.
 *
 * @return #CA_STATUS_OK or Appropriate error code
 * @retval #CA_STATUS_OK  Successful
 * @retval #CA_STATUS_FAILED Operation failed
 */
144
CAResult_t CAEDRClientSetCallbacks();
145 146 147 148

/**
 * @brief  Resetting callbacks with bluetooth framework and stop OIC device discovery.
 * @return NONE
149 150
 * @pre    CAEDRClientSetCallbacks() should be invoked before using this API.
 * @see    CAEDRClientSetCallbacks()
151
 */
152
void CAEDRClientUnsetCallbacks();
153 154

/**
155
 * @brief  Used to initialize the EDR client module where mutex is initialized
156 157
 * @return NONE
 */
158
void CAEDRInitializeClient(ca_thread_pool_t handle);
159 160

/**
161
 * @brief  Destroys the Device list and mutex.
162 163
 * @return NONE
 */
164
void CAEDRClientTerminate();
165 166

/**
167
 * @brief  Closes all the client connection to peer bluetooth devices.
168 169
 * @return NONE
 */
170
void CAEDRClientDisconnectAll();
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192

/**
 * @brief  Register callback to send the received packets from remote bluetooth device to BTAdapter.
 *
 * @param  packetReceivedCallback [IN] Callback function to register for sending network
 *                                     packets to EDR Adapter.
 * @return NONE
 */
void CAEDRSetPacketReceivedCallback(CAEDRDataReceivedCallback packetReceivedCallback);

/**
 * @brief  Register callback for receiving local bluetooth adapter state.
 *
 * @param  networkStateChangeCallback [IN] Callback function to register for receiving local
 *                                         bluetooth adapter status.
 * @return NONE
 */
void CAEDRSetNetworkChangeCallback(CAEDRNetworkStatusCallback networkStateChangeCallback);

/**
 * @brief  Get the local bluetooth adapter information.
 *
193
 * @param  info [OUT] Local bluetooth adapter information
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
 *
 * @return #CA_STATUS_OK or Appropriate error code
 * @retval #CA_STATUS_OK  Successful
 * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
 * @retval #CA_STATUS_FAILED Operation failed
 *
 * @see #CALocalConnectivity_t
 *
 */
CAResult_t CAEDRGetInterfaceInformation(CALocalConnectivity_t **info);

/**
 * @brief  Start RFCOMM server for given service UUID
 *
 * @param  serviceUUID  [IN] The UUID of service with which RFCOMM server needs to be started.
 * @param  serverFD     [IN] The RFCOMM server socket file descriptor.
210
 * @param  handle       [IN] Threadpool Handle
211 212 213 214 215 216 217
 *
 * @return #CA_STATUS_OK or Appropriate error code
 * @retval #CA_STATUS_OK  Successful
 * @retval #CA_STATUS_INVALID_PARAM  Invalid input argumets
 * @retval #CA_STATUS_FAILED Operation failed
 *
 */
218
CAResult_t CAEDRServerStart(const char *serviceUUID, int *serverFD, ca_thread_pool_t handle);
219 220 221 222 223 224 225 226 227 228

/**
 * @brief  Stop RFCOMM server
 *
 * @param  serverFD [IN] The RFCOMM server socket file descriptor which needs to be stopped.
 *
 * @return #CA_STATUS_OK or Appropriate error code
 * @retval #CA_STATUS_OK  Successful
 * @retval #CA_STATUS_FAILED Operation failed
 */
229 230 231 232 233 234 235
CAResult_t CAEDRServerStop(int serverFD);

/**
 * @brief   Terminate server for EDR
 * @return  None
 */
void CAEDRServerTerminate();
236 237 238 239 240 241 242 243 244

/**
 * @brief  All received data will be notified to upper layer.
 *
 * @return #CA_STATUS_OK or Appropriate error code
 * @retval #CA_STATUS_OK  Successful
 * @retval #CA_STATUS_FAILED Operation failed
 *
 */
245
CAResult_t CAEDRManagerReadData();
246 247

/**
248 249
 * @brief  This function gets bluetooth adapter enable state.
 * @param  state    [OUT] State of the Adapter.
250 251
 * @return #CA_STATUS_OK or Appropriate error code
 */
252
CAResult_t CAEDRGetAdapterEnableState(bool *state);
253 254

/**
255 256 257 258 259 260
 * @brief  This function sends data to specified remote bluetooth device.
 * @param  remoteAddress   [IN] Remote EDR Address
 * @param  serviceUUID     [IN] Service UUID of the device
 * @param  data            [IN] Data to be sent
 * @param  dataLength      [IN] Length of the data to be sent
 * @param  sentLength      [OUT] Length of the actual sent data
261 262 263
 * @return #CA_STATUS_OK or Appropriate error code
 */
CAResult_t CAEDRClientSendUnicastData(const char *remoteAddress, const char *serviceUUID,
264
                                      const void *data, uint32_t dataLength, uint32_t *sentLength);
265 266

/**
267 268 269 270 271
 * @brief  This function sends data to all bluetooth devices running OIC service.
 * @param  serviceUUID     [IN] Service UUID of the device
 * @param  data            [IN] Data to be sent
 * @param  dataLength      [IN] Length of the data to be sent
 * @param  sentLength      [OUT] Length of the actual sent data
272 273
 * @return #CA_STATUS_OK or Appropriate error code
 */
274
CAResult_t CAEDRClientSendMulticastData(const char *serviceUUID, const void *data,
275 276
                                        uint32_t dataLength, uint32_t *sentLength);

277 278 279 280 281 282
/**
 * @brief This function gets bonded bluetooth device list
 * @return #CA_STATUS_OK or Appropriate error code
 */
CAResult_t CAEDRGetBondedDeviceList();

283 284 285 286
#ifdef __cplusplus
} /* extern "C" */
#endif

287
#endif /* CA_EDR_INTERFACE_H_ */
288