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>
36 #include <bluetooth_internal.h>
38 #include <bluetooth_product.h>
40 #include "caadapterinterface.h"
42 #include "cathreadpool.h"
43 #include "caleinterface.h"
45 #if defined(__TIZEN__) && defined(LE_ADAPTER) && defined(BLE_CUSTOM_ADVERTISE)
47 * Used to Start Server advertise send data
49 CAResult_t CAsetServerAdvertisementData(const char *data, int length);
53 * Used to Start Server send response data
55 CAResult_t CAsetServerSanResponseData(const char *data, int length);
59 * Used to initialize gatt server.
61 * @return ::CA_STATUS_OK or Appropriate error code.
62 * @retval ::CA_STATUS_OK Successful.
63 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
64 * @retval ::CA_STATUS_FAILED Operation failed.
66 CAResult_t CAInitLEGattServer();
69 * Used to de-initialize gatt service and destroy the GATT server.
71 * @return ::CA_STATUS_OK or Appropriate error code.
72 * @retval ::CA_STATUS_OK Successful.
73 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
74 * @retval ::CA_STATUS_FAILED Operation failed.
76 CAResult_t CADeInitLEGattServer();
79 * Used to initialize all required mutex variables for GATT server implementation.
81 * @return ::CA_STATUS_OK or Appropriate error code.
82 * @retval ::CA_STATUS_OK Successful.
83 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
84 * @retval ::CA_STATUS_FAILED Operation failed.
86 CAResult_t CAInitGattServerMutexVariables();
89 * Used to start advertising.
91 * @return ::CA_STATUS_OK or Appropriate error code.
92 * @retval ::CA_STATUS_OK Successful.
93 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
94 * @retval ::CA_STATUS_FAILED Operation failed.
96 CAResult_t CALEStartAdvertise();
99 * Used to start advertising with service UUID.
101 * @return ::CA_STATUS_OK or Appropriate error code.
102 * @retval ::CA_STATUS_OK Successful.
103 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
104 * @retval ::CA_STATUS_FAILED Operation failed.
106 CAResult_t CALEStartAdvertiseImpl(const char *serviceUUID);
109 * Used to stop advertising.
111 * @return ::CA_STATUS_OK or Appropriate error code.
112 * @retval ::CA_STATUS_OK Successful.
113 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
114 * @retval ::CA_STATUS_FAILED Operation failed.
116 CAResult_t CALEStopAdvertise();
119 * Used to terminate all required mutex variables for GATT server implementation.
121 void CATerminateGattServerMutexVariables();
124 * Used to add new OIC service in GATT server using bt_gatt_add_service api and
125 * internally store service path(outparam) in global variable.
127 * @param[in] serviceUUID unique identifier for BLE OIC service.
129 * @return ::CA_STATUS_OK or Appropriate error code.
130 * @retval ::CA_STATUS_OK Successful.
131 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
132 * @retval ::CA_STATUS_FAILED Operation failed.
134 CAResult_t CAAddNewLEServiceInGattServer(const char *serviceUUID);
137 * Used to register the service in Gatt Server using bt_gatt_register_service api.
139 * @param[in] svcPath unique identifier for BLE OIC service which is outparam of
140 * bt_gatt_service_create api.
141 * @return ::CA_STATUS_OK or Appropriate error code.
142 * @retval ::CA_STATUS_OK Successful.
143 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
144 * @retval ::CA_STATUS_FAILED Operation failed.
146 CAResult_t CARegisterLEServicewithGattServer(const bt_gatt_h svcPath);
149 * Used to add new characteristics(Read/Write) to the service in Gatt Server using
150 * bt_gatt_add_characteristic api.
151 * @param[in] svcPath Service path to which this characteristic belongs to.
152 * @param[in] charUUID Gatt characteristic uuid.
153 * @param[in] charValue Gatt characteristic value.
154 * @param[in] charValueLen Characteristic value length.
155 * @param[in] read Boolean variable for checking whether read characteristics or
156 * write characteristics.
157 * @return ::CA_STATUS_OK or Appropriate error code.
159 CAResult_t CAAddNewCharacteristicsToGattServer(const bt_gatt_h svcPath, const char *charUUID,
160 const char *charValue, int charValueLen, bool read);
163 * This is the callback which will be called when client update one of the characteristics
165 * @param[in] remote_address The address of the remote device which requests a change
166 * @param[in] server The GATT server handle
167 * @param[in] gatt_handle The characteristic or descriptor's GATT handle which has an old value
168 * @param[in] offset The requested offset from where the @a gatt_handle value will be updated
169 * @param[in] value The new value
170 * @param[in] len The length of @a value
171 * @param[in] user_data The user data passed from the registration function
174 void CALEGattRemoteCharacteristicWriteCb(const char *remoteAddress, int request_id,
175 bt_gatt_server_h server, bt_gatt_h gatt_handle,
176 bool response_needed, int offset, const char *charValue,
177 int charLen, void *userData);
179 void CALEGattRemoteCharacteristicWriteCb(char *remoteAddress, bt_gatt_server_h server,
180 bt_gatt_h gatt_handle, int offset, char *charValue,
181 int charLen, void *userData);
185 * Setting the connection state changed callback.
186 * @param[in] connStateCb callback for receiving the changed network info.
188 void CASetLEConnectionStateChangedCallback(CALEConnectionStateChangedCallback connStateCb);
191 * check connection status.
192 * @param[in] address the address of the remote device.
193 * @return true or false.
195 bool CALEServerIsConnected(const char* address);
199 * @param[in] address the address of the remote device.
200 * @return mtu size negotiated from remote device.
202 uint16_t CALEServerGetMtuSize(const char* address);
204 #endif /* TZ_BLE_SERVER_H_ */