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 "caadapterinterface.h"
36 #include "cathreadpool.h"
37 #include "caleinterface.h"
40 * This is thread which will be used for creating ble service and advertise ble service.
41 * 1. Create New OIC Service 2. Add two read & write characteristics to service.
42 * 3. Register Service 4. Advertise service.
44 * @param[in] data Currently it will be NULL.
46 void CAStartBleGattServerThread(void *data);
49 * Used to initialize gatt service using _bt_gatt_init_service api.
51 * @return ::CA_STATUS_OK or Appropriate error code.
52 * @retval ::CA_STATUS_OK Successful.
53 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
54 * @retval ::CA_STATUS_FAILED Operation failed.
56 CAResult_t CAInitBleGattService();
59 * Used to de-initialize gatt service using _bt_gatt_deinit_service api.
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 CADeInitBleGattService();
69 * Used to initialize all required mutex variables for GATT server implementation.
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 CAInitGattServerMutexVariables();
80 * Used to terminate all required mutex variables for GATT server implementation.
82 void CATerminateGattServerMutexVariables();
85 * Used to add new OIC service in GATT server using bt_gatt_add_service api and
86 * internally store service path(outparam) in global variable.
88 * @param[in] serviceUUID unique identifier for BLE OIC service.
90 * @return ::CA_STATUS_OK or Appropriate error code.
91 * @retval ::CA_STATUS_OK Successful.
92 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
93 * @retval ::CA_STATUS_FAILED Operation failed.
95 CAResult_t CAAddNewBleServiceInGattServer(const char *serviceUUID);
98 * Used to remove already registered service from Gatt Server using
99 * bt_gatt_remove_service api.
100 * @param[in] svcPath unique identifier for BLE OIC service which is outparam of
101 * bt_gatt_add_service api.
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 CARemoveBleServiceFromGattServer(const char *svcPath);
110 * Used to remove all the registered service from Gatt Server using
111 * bt_gatt_delete_services api.
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 CARemoveAllBleServicesFromGattServer();
120 * Used to register the service in Gatt Server using bt_gatt_register_service api.
122 * @param[in] svcPath unique identifier for BLE OIC service which is outparam of
123 * bt_gatt_add_service api.
124 * @return ::CA_STATUS_OK or Appropriate error code.
125 * @retval ::CA_STATUS_OK Successful.
126 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
127 * @retval ::CA_STATUS_FAILED Operation failed.
129 CAResult_t CARegisterBleServicewithGattServer(const char *svcPath);
132 * Used to add new characteristics(Read/Write) to the service in Gatt Server using
133 * bt_gatt_add_characteristic api.
134 * @param[in] svcPath Service path to which this characteristic belongs to.
135 * @param[in] charUUID Gatt characteristic uuid.
136 * @param[in] charValue Gatt characteristic value.
137 * @param[in] charValueLen Characteristic value length.
138 * @param[in] read Boolean variable for checking whether read characteristics or
139 * write characteristics.
140 * @return ::CA_STATUS_OK or Appropriate error code.
142 CAResult_t CAAddNewCharacteristicsToGattServer(const char *svcPath, const char *charUUID,
143 const uint8_t *charValue, int charValueLen,
147 * Used to remove characteristics(Read/Write) from the service in Gatt Server.
149 * @param[in] charPath Characteristic path registered on the interface and unique identifier
150 * for added characteristics.
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 CARemoveCharacteristicsFromGattServer(const char *charPath);
160 * This is the callback which will be called when client update one of the characteristics
162 * @param[in] charPath characteristic path registered on the interface and unique
163 * identifier for added characteristics.
164 * @param[in] charValue data which is send by client.
165 * @param[in] charValueLen length of the data.
166 * @param[in] remoteAddress remote device bluetooth address in which data is received.
167 * @param[in] userData user data.
170 void CABleGattRemoteCharacteristicWriteCb(char *charPath, unsigned char *charValue,
171 int charValueLen, const char *remoteAddress,
175 * This is the callback which will be called whenever there is change in gatt connection
176 * with Client(Connected/Disconnected).
178 * @param[in] result The result of discovering.
179 * @param[in] connected State of connection.
180 * @param[in] remoteAddress Mac address of the remote device in which we made connection.
181 * @param[in] userData The user data passed from the request function.
184 void CABleGattServerConnectionStateChangedCb(int result, bool connected,
185 const char *remoteAddress, void *userData);
188 * Synchronous function for reading characteristic value.
190 * @return ::CA_STATUS_OK or Appropriate error code.
191 * @retval ::CA_STATUS_OK Successful.
192 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
193 * @retval ::CA_STATUS_FAILED Operation failed.
195 CAResult_t CALEReadDataFromLEServer();
198 * Used to enqueue the message into sender queue using CAAdapterEnqueueMessage and make
199 * signal to the thread to process.
201 * @param[in] remoteEndpoint Remote device information.
202 * @param[in] data Data to be sent to remote device.
203 * @param[in] dataLen Length of data.
205 * @return ::CA_STATUS_OK or Appropriate error code.
206 * @retval ::CA_STATUS_OK Successful.
207 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
208 * @retval ::CA_STATUS_FAILED Operation failed.
210 CAResult_t CABleServerSenderQueueEnqueueMessage
211 (const CAEndpoint_t *remoteEndpoint, const uint8_t *data, uint32_t dataLen);
214 * This is the thread which will be used for processing receiver queue.
216 void *CABleServerSenderQueueProcessor();
218 #endif /* TZ_BLE_SERVER_H_ */