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 contains the APIs related to the GATT Server functionalities.
25 * Creation of the GattServer with the characteristics. Enabling the
26 * advertisement and updating the characteristics for the response and
27 * notifying the change of characteristcs for the request will be done here.
28 * LE adapter will interact with this sub module.
31 #ifndef TZ_BLE_SERVER_H_
32 #define TZ_BLE_SERVER_H_
34 #include <bluetooth.h>
35 #include <bluetooth_type.h>
37 #include <bluetooth_product.h>
39 #include "caadapterinterface.h"
41 #include "cathreadpool.h"
42 #include "caleinterface.h"
44 #if defined(__TIZEN__) && defined(LE_ADAPTER) && defined(BLE_CUSTOM_ADVERTISE)
46 * Used to Start Server advertise send data
48 CAResult_t CAsetServerAdvertisementData(const char *data, int length);
51 * Used to set advertisement data getter callback.
52 * @param[in] getter Bluetooth advertisement data getter callback.
54 void CAsetServerAdvertisementDataGetter(CAAdvertisementDataGetterCB getter);
57 * Used to set auto advertisement feature on and off.
59 * @param[in] auto_advertisement Boolean flag to turn auto advertisement feature on and off.
61 void CAsetServerAutoAdvertisement(bool auto_advertisement);
64 * Used to Start Server send response data
66 CAResult_t CAsetServerSanResponseData(const char *data, int length);
70 * Used to initialize gatt server.
72 * @return ::CA_STATUS_OK or Appropriate error code.
73 * @retval ::CA_STATUS_OK Successful.
74 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
75 * @retval ::CA_STATUS_FAILED Operation failed.
77 CAResult_t CAInitLEGattServer();
80 * Used to de-initialize gatt service and destroy the GATT server.
82 * @return ::CA_STATUS_OK or Appropriate error code.
83 * @retval ::CA_STATUS_OK Successful.
84 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
85 * @retval ::CA_STATUS_FAILED Operation failed.
87 CAResult_t CADeInitLEGattServer();
90 * Used to initialize all required mutex variables for GATT server implementation.
92 * @return ::CA_STATUS_OK or Appropriate error code.
93 * @retval ::CA_STATUS_OK Successful.
94 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
95 * @retval ::CA_STATUS_FAILED Operation failed.
97 CAResult_t CAInitGattServerMutexVariables();
100 * Used to start advertising.
102 * @return ::CA_STATUS_OK or Appropriate error code.
103 * @retval ::CA_STATUS_OK Successful.
104 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
105 * @retval ::CA_STATUS_FAILED Operation failed.
107 CAResult_t CALEStartAdvertise();
110 * Used to start advertising with service UUID.
112 * @return ::CA_STATUS_OK or Appropriate error code.
113 * @retval ::CA_STATUS_OK Successful.
114 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
115 * @retval ::CA_STATUS_FAILED Operation failed.
117 CAResult_t CALEStartAdvertiseImpl(const char *serviceUUID);
120 * Used to stop advertising.
122 * @return ::CA_STATUS_OK or Appropriate error code.
123 * @retval ::CA_STATUS_OK Successful.
124 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
125 * @retval ::CA_STATUS_FAILED Operation failed.
127 CAResult_t CALEStopAdvertise();
130 * Used to terminate all required mutex variables for GATT server implementation.
132 void CATerminateGattServerMutexVariables();
135 * Used to add new OIC service in GATT server using bt_gatt_add_service api and
136 * internally store service path(outparam) in global variable.
138 * @param[in] serviceUUID unique identifier for BLE OIC service.
140 * @return ::CA_STATUS_OK or Appropriate error code.
141 * @retval ::CA_STATUS_OK Successful.
142 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
143 * @retval ::CA_STATUS_FAILED Operation failed.
145 CAResult_t CAAddNewLEServiceInGattServer(const char *serviceUUID);
148 * Used to register the service in Gatt Server using bt_gatt_register_service api.
150 * @param[in] svcPath unique identifier for BLE OIC service which is outparam of
151 * bt_gatt_service_create api.
152 * @return ::CA_STATUS_OK or Appropriate error code.
153 * @retval ::CA_STATUS_OK Successful.
154 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
155 * @retval ::CA_STATUS_FAILED Operation failed.
157 CAResult_t CARegisterLEServicewithGattServer(const bt_gatt_h svcPath);
160 * Used to add new characteristics(Read/Write) to the service in Gatt Server using
161 * bt_gatt_add_characteristic api.
162 * @param[in] svcPath Service path to which this characteristic belongs to.
163 * @param[in] charUUID Gatt characteristic uuid.
164 * @param[in] charValue Gatt characteristic value.
165 * @param[in] charValueLen Characteristic value length.
166 * @param[in] read Boolean variable for checking whether read characteristics or
167 * write characteristics.
168 * @return ::CA_STATUS_OK or Appropriate error code.
170 CAResult_t CAAddNewCharacteristicsToGattServer(const bt_gatt_h svcPath, const char *charUUID,
171 const char *charValue, int charValueLen, bool read);
174 * This is the callback which will be called when client update one of the characteristics
176 * @param[in] remote_address The address of the remote device which requests a change
177 * @param[in] server The GATT server handle
178 * @param[in] gatt_handle The characteristic or descriptor's GATT handle which has an old value
179 * @param[in] offset The requested offset from where the @a gatt_handle value will be updated
180 * @param[in] value The new value
181 * @param[in] len The length of @a value
182 * @param[in] user_data The user data passed from the registration function
185 void CALEGattRemoteCharacteristicWriteCb(const char *remoteAddress, int request_id,
186 bt_gatt_server_h server, bt_gatt_h gatt_handle,
187 bool response_needed, int offset, const char *charValue,
188 int charLen, void *userData);
190 void CALEGattRemoteCharacteristicWriteCb(char *remoteAddress, bt_gatt_server_h server,
191 bt_gatt_h gatt_handle, int offset, char *charValue,
192 int charLen, void *userData);
196 * Setting the connection state changed callback.
197 * @param[in] connStateCb callback for receiving the changed network info.
199 void CASetLEConnectionStateChangedCallback(CALEConnectionStateChangedCallback connStateCb);
202 * check connection status.
203 * @param[in] address the address of the remote device.
204 * @return true or false.
206 bool CALEServerIsConnected(const char* address);
210 * @param[in] address the address of the remote device.
211 * @return mtu size negotiated from remote device.
213 uint16_t CALEServerGetMtuSize(const char* address);
215 #endif /* TZ_BLE_SERVER_H_ */