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 ******************************************************************/
23 * @brief This file provides the APIs to control Bluetooth transport
26 #ifndef __CA_BT_MANAGER_H_
27 #define __CA_BT_MANAGER_H_
31 #include <bluetooth.h>
33 #include "caedradapter.h"
41 * @fn CABTManagerInitialize
42 * @brief Initializes Bluetooth adapter
44 * @param threadPool Thread pool for handling asynchronous tasks
46 * @return CA_STATUS_OK or CA_ADAPTER_NOT_ENABLED on success otherwise proper error code.
47 * @retval CA_STATUS_OK Successful
48 * @retval CA_ADAPTER_NOT_ENABLED Initialization is successful, but bluetooth adapter is
50 * @retval CA_STATUS_FAILED Operation failed
53 CAResult_t CABTManagerInitialize(u_thread_pool_t threadPool);
56 * @fn CABTManagerTerminate
57 * @brief Deinitialize with bluetooth adapter
59 * @see CABTManagerIntialize
62 void CABTManagerTerminate(void);
65 * @fn CABTManagerStart
66 * @brief Start bluetooth adapter which includes start searching for nearby OIC devices
68 * @return CA_STATUS_OK on success otherwise proper error code.
69 * @retval CA_STATUS_OK Successful
70 * @retval CA_STATUS_FAILED Operation failed
72 * @pre CABTManagerIntialize should be invoked before using this API
74 * @see CABTManagerIntialize
77 CAResult_t CABTManagerStart(void);
81 * @brief Stop bluetooth adapter which includes stoping searching for nearby OIC devices
83 * @pre CABTManagerIntialize should be invoked before using this API
85 * @see CABTManagerIntialize
86 * @see CABTManagerStart
89 void CABTManagerStop(void);
92 * @fn CABTManagerSetPacketReceivedCallback
93 * @brief Register callback for receiving packets from remote Bluetooth device.
95 * @param packetReceivedCallback Callback function to register for receiving network packets
99 * @see CBNetworkPacketReceived
102 void CABTManagerSetPacketReceivedCallback(CANetworkPacketReceivedCallback packetReceivedCallback);
105 * @fn CABTManagerSetNetworkChangeCallback
106 * @brief Register callback for receiving network chang state of local Bluetooth adapter.
108 * @param networkChangeCallback Callback function to register for receiving network adapter status
112 * @see CBNetworkChange
115 void CABTManagerSetNetworkChangeCallback(CANetworkChangeCallback networkChangeCallback);
118 * @fn CABTManagerSendData
119 * @brief Send unicast/multicast data to remote bluetooth device
121 * @param remoteAddress The address of remote bluetooth device to which data needs to be sent.
122 * This will be NULL in case of sending multicast data.
123 * @param serviceUUID The UUID of service to which RFCOMM connection needs to established
124 * @param data The data needs to be send to remote bluetooth device
125 * @param dataLength Length of data
126 * @param sentLength Length of data actually sent or added to pending list for sending
128 * @return CA_STATUS_OK on success otherwise proper error code.
129 * @retval CA_STATUS_OK Successful
130 * @retval CA_STATUS_INVALID_PARAM Invalid input argumets
131 * @retval CA_STATUS_FAILED Operation failed
134 CAResult_t CABTManagerSendData(const char *remoteAddress, const char *serviceUUID,
135 void *data, uint32_t dataLength, uint32_t *sentLength);
138 * @fn CABTManagerStartServer
139 * @brief Start RFCOMM server for given service UUID
141 * @param serviceUUID The UUID of service with which RFCOMM server needs to be started
142 * @param serverID The ID for the server which started
144 * @return CA_STATUS_OK on success otherwise proper error code.
145 * @retval CA_STATUS_OK Successful
146 * @retval CA_SERVER_STARTED_ALREADY Service on the specified UUID is already running.
147 * @retval CA_STATUS_INVALID_PARAM Invalid input argumets
148 * @retval CA_STATUS_FAILED Operation failed
151 CAResult_t CABTManagerStartServer(const char *serviceUUID, int32_t *serverID);
154 * @fn CABTManagerStopServer
155 * @brief Stop RFCOMM server
157 * @param serverID The ID of server which needs to be stopped
159 * @return CA_STATUS_OK on success otherwise proper error code.
160 * @retval CA_STATUS_OK Successful
161 * @retval CA_STATUS_FAILED Operation failed
164 CAResult_t CABTManagerStopServer(const int32_t serverID);
167 * @fn CABTManagerGetInterface
168 * @brief Get the local bluetooth adapter information.
170 * @param info Local bluetooth adapter information
172 * @return CA_STATUS_OK on success otherwise proper 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 CABTManagerGetInterface(CALocalConnectivity_t **info);
183 * @fn CABTManagerReadData
184 * @brief All received data will be notified to upper layer.
186 * @return CA_STATUS_OK on success otherwise proper error code.
187 * @retval CA_STATUS_OK Successful
188 * @retval CA_STATUS_FAILED Operation failed
191 CAResult_t CABTManagerReadData(void);
197 #endif //__CA_BT_MANAGER_H_