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 * @brief 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 data [IN] Currently it will be NULL.
47 void CAStartBleGattServerThread(void *data);
50 * @brief Used to initialize gatt service using _bt_gatt_init_service api.
52 * @return #CA_STATUS_OK or Appropriate error code
53 * @retval #CA_STATUS_OK Successful
54 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
55 * @retval #CA_STATUS_FAILED Operation failed
57 CAResult_t CAInitBleGattService();
60 * @brief Used to de-initialize gatt service using _bt_gatt_deinit_service api.
62 * @return #CA_STATUS_OK or Appropriate error code
63 * @retval #CA_STATUS_OK Successful
64 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
65 * @retval #CA_STATUS_FAILED Operation failed
67 CAResult_t CADeInitBleGattService();
70 * @brief Used to initialize all required mutex variables for GATT server implementation.
72 * @return #CA_STATUS_OK or Appropriate error code
73 * @retval #CA_STATUS_OK Successful
74 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
75 * @retval #CA_STATUS_FAILED Operation failed
77 CAResult_t CAInitGattServerMutexVariables();
81 * @brief Used to terminate all required mutex variables for GATT server implementation.
84 void CATerminateGattServerMutexVariables();
87 * @brief Used to add new OIC service in GATT server using bt_gatt_add_service api and
88 * internally store service path(outparam) in global variable.
90 * @param serviceUUID [IN] unique identifier for BLE OIC service.
92 * @return #CA_STATUS_OK or Appropriate error code
93 * @retval #CA_STATUS_OK Successful
94 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
95 * @retval #CA_STATUS_FAILED Operation failed
97 CAResult_t CAAddNewBleServiceInGattServer(const char *serviceUUID);
100 * @brief Used to remove already registered service from Gatt Server using
101 * bt_gatt_remove_service api.
102 * @param svcPath [IN] unique identifier for BLE OIC service which is outparam of
103 * bt_gatt_add_service api.
104 * @return #CA_STATUS_OK or Appropriate error code
105 * @retval #CA_STATUS_OK Successful
106 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
107 * @retval #CA_STATUS_FAILED Operation failed
109 CAResult_t CARemoveBleServiceFromGattServer(const char *svcPath);
112 * @brief Used to remove all the registered service from Gatt Server using
113 * bt_gatt_delete_services api.
114 * @return #CA_STATUS_OK or Appropriate error code
115 * @retval #CA_STATUS_OK Successful
116 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
117 * @retval #CA_STATUS_FAILED Operation failed
119 CAResult_t CARemoveAllBleServicesFromGattServer();
122 * @brief Used to register the service in Gatt Server using bt_gatt_register_service api.
124 * @param svcPath [IN] unique identifier for BLE OIC service which is outparam of
125 * bt_gatt_add_service api.
126 * @return #CA_STATUS_OK or Appropriate error code
127 * @retval #CA_STATUS_OK Successful
128 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
129 * @retval #CA_STATUS_FAILED Operation failed
131 CAResult_t CARegisterBleServicewithGattServer(const char *svcPath);
134 * @brief Used to add new characteristics(Read/Write) to the service in Gatt Server using
135 * bt_gatt_add_characteristic api.
136 * @param svcPath [IN] Service path to which this characteristic belongs to.
137 * @param charUUID [IN] Gatt characteristic uuid.
138 * @param charValue [IN] Gatt characteristic value.
139 * @param charValueLen [IN] Characteristic value length.
140 * @param read [IN] Boolean variable for checking whether read characteristics or
141 * write characteristics.
142 * @return #CA_STATUS_OK or Appropriate error code
144 CAResult_t CAAddNewCharacteristicsToGattServer(const char *svcPath, const char *charUUID,
145 const char *charValue, int charValueLen,
149 * @brief Used to remove characteristics(Read/Write) from the service in Gatt Server.
151 * @param charPath [IN] Characteristic path registered on the interface and unique identifier
152 * for added characteristics.
154 * @return #CA_STATUS_OK or Appropriate error code
155 * @retval #CA_STATUS_OK Successful
156 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
157 * @retval #CA_STATUS_FAILED Operation failed
159 CAResult_t CARemoveCharacteristicsFromGattServer(const char *charPath);
162 * @brief This is the callback which will be called when client update one of the characteristics
164 * @param charPath [IN] characteristic path registered on the interface and unique
165 * identifier for added characteristics.
166 * @param charValue [IN] data which is send by client.
167 * @param charValueLen [IN] length of the data.
168 * @param remoteAddress [IN] remote device bluetooth address in which data is received.
169 * @param userData [IN] user data
173 void CABleGattRemoteCharacteristicWriteCb(char *charPath, unsigned char *charValue,
174 int charValueLen, const char *remoteAddress,
178 * @brief This is the callback which will be called whenever there is change in gatt connection
179 * with Client(Connected/Disconnected).
181 * @param result [IN] The result of discovering.
182 * @param connected [IN] State of connection.
183 * @param remoteAddress [IN] Mac address of the remote device in which we made connection.
184 * @param userData [IN] The user data passed from the request function.
188 void CABleGattServerConnectionStateChangedCb(int result, bool connected,
189 const char *remoteAddress, void *userData);
192 * @brief Synchronous function for reading characteristic value.
194 * @return #CA_STATUS_OK or Appropriate error code
195 * @retval #CA_STATUS_OK Successful
196 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
197 * @retval #CA_STATUS_FAILED Operation failed
199 CAResult_t CALEReadDataFromLEServer();
202 * @brief Used to enqueue the message into sender queue using CAAdapterEnqueueMessage and make
203 * signal to the thread to process.
205 * @param remoteEndpoint [IN] Remote device information.
206 * @param data [IN] Data to be sent to remote device.
207 * @param dataLen [IN] Length of data.
209 * @return #CA_STATUS_OK or Appropriate error code
210 * @retval #CA_STATUS_OK Successful
211 * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
212 * @retval #CA_STATUS_FAILED Operation failed
214 CAResult_t CABleServerSenderQueueEnqueueMessage
215 (const CAEndpoint_t *remoteEndpoint, const void *data, uint32_t dataLen);
218 * @brief This is the thread which will be used for processing receiver queue.
221 void *CABleServerSenderQueueProcessor();
223 #endif /* TZ_BLE_SERVER_H_ */