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 contains the APIs related to the GATT Server functionalities.
24 * Creation of the GattServer with the characteristics. Enabling the advertisement and
25 * updating the characteristics for the response and notifying the change of characteristcs
26 * for the request will be done here. LE adapter will interact with this sub module.
29 #ifndef __TZ_BLE_SERVER_H_
30 #define __TZ_BLE_SERVER_H_
32 #include "caadapterinterface.h"
34 #include "uthreadpool.h"
35 #include "caleinterface.h"
38 * @brief This is thread which will be used for creating ble service and advertise ble service.
39 * 1. Create New OIC Service 2. Add two read & write characteristics to service.
40 * 3. Register Service 4. Advertise service.
42 * @param data [IN] Currently it will be NULL.
45 void CAStartBleGattServerThread(void *data);
48 * @brief Used to initialize gatt service using _bt_gatt_init_service api.
50 * @return #CA_STATUS_OK or Appropriate error code
51 * @retval #CA_STATUS_OK Successful
52 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
53 * @retval #CA_STATUS_FAILED Operation failed
55 CAResult_t CAInitBleGattService();
58 * @brief Used to de-initialize gatt service using _bt_gatt_deinit_service api.
60 * @return #CA_STATUS_OK or Appropriate error code
61 * @retval #CA_STATUS_OK Successful
62 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
63 * @retval #CA_STATUS_FAILED Operation failed
65 CAResult_t CADeInitBleGattService();
68 * @brief Used to initialize all required mutex variables for GATT server implementation.
70 * @return #CA_STATUS_OK or Appropriate error code
71 * @retval #CA_STATUS_OK Successful
72 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
73 * @retval #CA_STATUS_FAILED Operation failed
75 CAResult_t CAInitGattServerMutexVariables();
79 * @brief Used to terminate all required mutex variables for GATT server implementation.
82 void CATerminateGattServerMutexVariables();
85 * @brief 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 serviceUUID [IN] 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 argumets
93 * @retval #CA_STATUS_FAILED Operation failed
95 CAResult_t CAAddNewBleServiceInGattServer(const char *serviceUUID);
98 * @brief Used to remove already registered service from Gatt Server using
99 * bt_gatt_remove_service api.
100 * @param svcPath [IN] 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 argumets
105 * @retval #CA_STATUS_FAILED Operation failed
107 CAResult_t CARemoveBleServiceFromGattServer(const char *svcPath);
110 * @brief 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 argumets
115 * @retval #CA_STATUS_FAILED Operation failed
117 CAResult_t CARemoveAllBleServicesFromGattServer();
120 * @brief Used to register the service in Gatt Server using bt_gatt_register_service api.
122 * @param svcPath [IN] 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 argumets
127 * @retval #CA_STATUS_FAILED Operation failed
129 CAResult_t CARegisterBleServicewithGattServer(const char *svcPath);
132 * @brief Used to add new characteristics(Read/Write) to the service in Gatt Server using
133 * bt_gatt_add_characteristic api.
134 * @param svcPath [IN] Service path to which this characteristic belongs to.
135 * @param charUUID [IN] Gatt characteristic uuid.
136 * @param charValue [IN] Gatt characteristic value.
137 * @param charValueLen [IN] Characteristic value length.
138 * @param read [IN] 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 char *charValue, int charValueLen,
147 * @brief Used to remove characteristics(Read/Write) from the service in Gatt Server.
149 * @param charPath [IN] 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 argumets
155 * @retval #CA_STATUS_FAILED Operation failed
157 CAResult_t CARemoveCharacteristicsFromGattServer(const char *charPath);
160 * @brief This is the callback which will be called when client update one of the characteristics
162 * @param charPath [IN] characteristic path registered on the interface and unique
163 * identifier for added characteristics.
164 * @param charValue [IN] data which is send by client.
165 * @param charValueLen [IN] length of the data.
166 * @param userData [IN] user data
170 void CABleGattRemoteCharacteristicWriteCb(char *charPath, unsigned char *charValue,
171 int charValueLen, void *userData);
174 * @brief This is the callback which will be called whenever there is change in gatt connection
175 * with Client(Connected/Disconnected).
177 * @param result [IN] The result of discovering.
178 * @param connected [IN] State of connection.
179 * @param remoteAddress [IN] Mac address of the remote device in which we made connection.
180 * @param userData [IN] The user data passed from the request function.
184 void CABleGattServerConnectionStateChangedCb(int result, bool connected,
185 const char *remoteAddress, void *userData);
188 * @brief 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 argumets
193 * @retval #CA_STATUS_FAILED Operation failed
195 CAResult_t CALEReadDataFromLEServer();
198 * @brief Used to enqueue the message into sender queue using CAAdapterEnqueueMessage and make
199 * signal to the thread to process.
201 * @param remoteEndpoint [IN] Remote device information.
202 * @param data [IN] Data to be sent to remote device.
203 * @param dataLen [IN] 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 argumets
208 * @retval #CA_STATUS_FAILED Operation failed
210 CAResult_t CABleServerSenderQueueEnqueueMessage
211 (const CARemoteEndpoint_t *remoteEndpoint, const void *data, uint32_t dataLen);
214 * @brief This is the thread which will be used for processing receiver queue.
217 void *CABleServerSenderQueueProcessor();
219 #endif //#ifndef __TZ_BLE_SERVER_H_