#ifndef TZ_BLE_SERVER_H_
#define TZ_BLE_SERVER_H_
+#include <bluetooth.h>
+#include <bluetooth_type.h>
+#include <bluetooth_internal.h>
+#ifdef BLE_MCD
+#include <bluetooth_product.h>
+#endif
#include "caadapterinterface.h"
#include "logger.h"
#include "cathreadpool.h"
#include "caleinterface.h"
+#if defined(__TIZEN__) && defined(LE_ADAPTER) && defined(BLE_CUSTOM_ADVERTISE)
/**
- * This is thread which will be used for creating ble service and advertise ble service.
- * 1. Create New OIC Service 2. Add two read & write characteristics to service.
- * 3. Register Service 4. Advertise service.
- *
- * @param[in] data Currently it will be NULL.
+ * Used to Start Server advertise send data
*/
-void CAStartBleGattServerThread(void *data);
+CAResult_t CAsetServerAdvertisementData(const char *data, int length);
+
/**
- * Used to initialize gatt service using _bt_gatt_init_service api.
+ * Used to Start Server send response data
+ */
+CAResult_t CAsetServerSanResponseData(const char *data, int length);
+#endif
+
+/**
+ * Used to initialize gatt server.
*
* @return ::CA_STATUS_OK or Appropriate error code.
* @retval ::CA_STATUS_OK Successful.
* @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
* @retval ::CA_STATUS_FAILED Operation failed.
*/
-CAResult_t CAInitBleGattService();
+CAResult_t CAInitLEGattServer();
/**
- * Used to de-initialize gatt service using _bt_gatt_deinit_service api.
+ * Used to de-initialize gatt service and destroy the GATT server.
*
* @return ::CA_STATUS_OK or Appropriate error code.
* @retval ::CA_STATUS_OK Successful.
* @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
* @retval ::CA_STATUS_FAILED Operation failed.
*/
-CAResult_t CADeInitBleGattService();
+CAResult_t CADeInitLEGattServer();
/**
* Used to initialize all required mutex variables for GATT server implementation.
*/
CAResult_t CAInitGattServerMutexVariables();
-
/**
- * Used to terminate all required mutex variables for GATT server implementation.
+ * Used to start advertising.
+ *
+ * @return ::CA_STATUS_OK or Appropriate error code.
+ * @retval ::CA_STATUS_OK Successful.
+ * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
+ * @retval ::CA_STATUS_FAILED Operation failed.
*/
-void CATerminateGattServerMutexVariables();
+CAResult_t CALEStartAdvertise();
/**
- * Used to add new OIC service in GATT server using bt_gatt_add_service api and
- * internally store service path(outparam) in global variable.
- *
- * @param[in] serviceUUID unique identifier for BLE OIC service.
+ * Used to start advertising with service UUID.
*
* @return ::CA_STATUS_OK or Appropriate error code.
* @retval ::CA_STATUS_OK Successful.
* @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
* @retval ::CA_STATUS_FAILED Operation failed.
*/
-CAResult_t CAAddNewBleServiceInGattServer(const char *serviceUUID);
+CAResult_t CALEStartAdvertiseImpl(const char *serviceUUID);
/**
- * Used to remove already registered service from Gatt Server using
- * bt_gatt_remove_service api.
- * @param[in] svcPath unique identifier for BLE OIC service which is outparam of
- * bt_gatt_add_service api.
+ * Used to stop advertising.
+ *
* @return ::CA_STATUS_OK or Appropriate error code.
* @retval ::CA_STATUS_OK Successful.
* @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
* @retval ::CA_STATUS_FAILED Operation failed.
*/
-CAResult_t CARemoveBleServiceFromGattServer(const char *svcPath);
+CAResult_t CALEStopAdvertise();
+
+/**
+ * Used to terminate all required mutex variables for GATT server implementation.
+ */
+void CATerminateGattServerMutexVariables();
/**
- * Used to remove all the registered service from Gatt Server using
- * bt_gatt_delete_services api.
+ * Used to add new OIC service in GATT server using bt_gatt_add_service api and
+ * internally store service path(outparam) in global variable.
+ *
+ * @param[in] serviceUUID unique identifier for BLE OIC service.
+ *
* @return ::CA_STATUS_OK or Appropriate error code.
* @retval ::CA_STATUS_OK Successful.
* @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
* @retval ::CA_STATUS_FAILED Operation failed.
*/
-CAResult_t CARemoveAllBleServicesFromGattServer();
+CAResult_t CAAddNewLEServiceInGattServer(const char *serviceUUID);
/**
* Used to register the service in Gatt Server using bt_gatt_register_service api.
*
* @param[in] svcPath unique identifier for BLE OIC service which is outparam of
- * bt_gatt_add_service api.
+ * bt_gatt_service_create api.
* @return ::CA_STATUS_OK or Appropriate error code.
* @retval ::CA_STATUS_OK Successful.
* @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
* @retval ::CA_STATUS_FAILED Operation failed.
*/
-CAResult_t CARegisterBleServicewithGattServer(const char *svcPath);
+CAResult_t CARegisterLEServicewithGattServer(const bt_gatt_h svcPath);
/**
* Used to add new characteristics(Read/Write) to the service in Gatt Server using
* write characteristics.
* @return ::CA_STATUS_OK or Appropriate error code.
*/
-CAResult_t CAAddNewCharacteristicsToGattServer(const char *svcPath, const char *charUUID,
- const uint8_t *charValue, int charValueLen,
- bool read);
-
-/**
- * Used to remove characteristics(Read/Write) from the service in Gatt Server.
- *
- * @param[in] charPath Characteristic path registered on the interface and unique identifier
- * for added characteristics.
- *
- * @return ::CA_STATUS_OK or Appropriate error code.
- * @retval ::CA_STATUS_OK Successful.
- * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
- * @retval ::CA_STATUS_FAILED Operation failed.
- */
-CAResult_t CARemoveCharacteristicsFromGattServer(const char *charPath);
+CAResult_t CAAddNewCharacteristicsToGattServer(const bt_gatt_h svcPath, const char *charUUID,
+ const char *charValue, int charValueLen, bool read);
/**
* This is the callback which will be called when client update one of the characteristics
* with data.
- * @param[in] charPath characteristic path registered on the interface and unique
- * identifier for added characteristics.
- * @param[in] charValue data which is send by client.
- * @param[in] charValueLen length of the data.
- * @param[in] remoteAddress remote device bluetooth address in which data is received.
- * @param[in] userData user data.
-
+ * @param[in] remote_address The address of the remote device which requests a change
+ * @param[in] server The GATT server handle
+ * @param[in] gatt_handle The characteristic or descriptor's GATT handle which has an old value
+ * @param[in] offset The requested offset from where the @a gatt_handle value will be updated
+ * @param[in] value The new value
+ * @param[in] len The length of @a value
+ * @param[in] user_data The user data passed from the registration function
*/
-void CABleGattRemoteCharacteristicWriteCb(char *charPath, unsigned char *charValue,
- int charValueLen, const char *remoteAddress,
- void *userData);
+#ifdef BLE_TIZEN_30
+void CALEGattRemoteCharacteristicWriteCb(const char *remoteAddress, int request_id,
+ bt_gatt_server_h server, bt_gatt_h gatt_handle,
+ bool response_needed, int offset, const char *charValue,
+ int charLen, void *userData);
+#else
+void CALEGattRemoteCharacteristicWriteCb(char *remoteAddress, bt_gatt_server_h server,
+ bt_gatt_h gatt_handle, int offset, char *charValue,
+ int charLen, void *userData);
+#endif
/**
- * This is the callback which will be called whenever there is change in gatt connection
- * with Client(Connected/Disconnected).
- *
- * @param[in] result The result of discovering.
- * @param[in] connected State of connection.
- * @param[in] remoteAddress Mac address of the remote device in which we made connection.
- * @param[in] userData The user data passed from the request function.
-
+ * Setting the connection state changed callback.
+ * @param[in] connStateCb callback for receiving the changed network info.
*/
-void CABleGattServerConnectionStateChangedCb(int result, bool connected,
- const char *remoteAddress, void *userData);
+void CASetLEConnectionStateChangedCallback(CALEConnectionStateChangedCallback connStateCb);
/**
- * Synchronous function for reading characteristic value.
- *
- * @return ::CA_STATUS_OK or Appropriate error code.
- * @retval ::CA_STATUS_OK Successful.
- * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
- * @retval ::CA_STATUS_FAILED Operation failed.
- */
-CAResult_t CALEReadDataFromLEServer();
-
-/**
- * Used to enqueue the message into sender queue using CAAdapterEnqueueMessage and make
- * signal to the thread to process.
- *
- * @param[in] remoteEndpoint Remote device information.
- * @param[in] data Data to be sent to remote device.
- * @param[in] dataLen Length of data.
- *
- * @return ::CA_STATUS_OK or Appropriate error code.
- * @retval ::CA_STATUS_OK Successful.
- * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
- * @retval ::CA_STATUS_FAILED Operation failed.
+ * check connection status.
+ * @param[in] address the address of the remote device.
+ * @return true or false.
*/
-CAResult_t CABleServerSenderQueueEnqueueMessage
- (const CAEndpoint_t *remoteEndpoint, const uint8_t *data, uint32_t dataLen);
+bool CALEServerIsConnected(const char* address);
/**
- * This is the thread which will be used for processing receiver queue.
+ * get MTU size.
+ * @param[in] address the address of the remote device.
+ * @return mtu size negotiated from remote device.
*/
-void *CABleServerSenderQueueProcessor();
+uint16_t CALEServerGetMtuSize(const char* address);
#endif /* TZ_BLE_SERVER_H_ */