Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / tizen / cableserver.h
1 /* ****************************************************************
2 *
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
4 *
5 *
6 *
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
10 *
11 *      http://www.apache.org/licenses/LICENSE-2.0
12 *
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.
18 *
19 ******************************************************************/
20
21 /**
22  * @file
23  *
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.
29  */
30
31 #ifndef TZ_BLE_SERVER_H_
32 #define TZ_BLE_SERVER_H_
33
34 #include "caadapterinterface.h"
35 #include "logger.h"
36 #include "cathreadpool.h"
37 #include "caleinterface.h"
38
39 /**
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.
43  *
44  * @param data [IN] Currently it will be NULL.
45  * @return  NONE
46  */
47 void CAStartBleGattServerThread(void *data);
48
49 /**
50  * @brief  Used to initialize gatt service using _bt_gatt_init_service api.
51  *
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
56  */
57 CAResult_t CAInitBleGattService();
58
59 /**
60  * @brief  Used to de-initialize gatt service using _bt_gatt_deinit_service api.
61  *
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
66  */
67 CAResult_t CADeInitBleGattService();
68
69 /**
70  * @brief  Used to initialize all required mutex variables for GATT server implementation.
71  *
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
76  */
77 CAResult_t CAInitGattServerMutexVariables();
78
79
80 /**
81  * @brief  Used to terminate all required mutex variables for GATT server implementation.
82  * @return NONE
83  */
84 void CATerminateGattServerMutexVariables();
85
86 /**
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.
89  *
90  * @param  serviceUUID [IN] unique identifier for BLE OIC service.
91  *
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
96  */
97 CAResult_t CAAddNewBleServiceInGattServer(const char *serviceUUID);
98
99 /**
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
108  */
109 CAResult_t CARemoveBleServiceFromGattServer(const char *svcPath);
110
111 /**
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
118  */
119 CAResult_t CARemoveAllBleServicesFromGattServer();
120
121 /**
122  * @brief  Used to register the service in Gatt Server using bt_gatt_register_service api.
123  *
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
130  */
131 CAResult_t CARegisterBleServicewithGattServer(const char *svcPath);
132
133 /**
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
143  */
144 CAResult_t CAAddNewCharacteristicsToGattServer(const char *svcPath, const char *charUUID,
145                                                const char *charValue, int charValueLen,
146                                                bool read);
147
148 /**
149  * @brief  Used to remove characteristics(Read/Write) from the service in Gatt Server.
150  *
151  * @param  charPath  [IN] Characteristic path registered on the interface and unique identifier
152  *                        for added characteristics.
153  *
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
158  */
159 CAResult_t CARemoveCharacteristicsFromGattServer(const char *charPath);
160
161 /**
162  * @brief  This is the callback which will be called when client update one of the characteristics
163  *         with data.
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
170  *
171  * @return NONE
172  */
173 void CABleGattRemoteCharacteristicWriteCb(char *charPath, unsigned char *charValue,
174                                           int charValueLen, const char  *remoteAddress,
175                                           void *userData);
176
177 /**
178  * @brief  This is the callback which will be called whenever there is change in gatt connection
179  *         with Client(Connected/Disconnected).
180  *
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.
185  *
186  * @return  NONE
187  */
188 void CABleGattServerConnectionStateChangedCb(int result, bool connected,
189                                              const char *remoteAddress, void *userData);
190
191 /**
192  * @brief  Synchronous function for reading characteristic value.
193  *
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
198  */
199 CAResult_t CALEReadDataFromLEServer();
200
201 /**
202  * @brief  Used to enqueue the message into sender queue using CAAdapterEnqueueMessage and make
203  *         signal to the thread to process.
204  *
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.
208  *
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
213  */
214 CAResult_t CABleServerSenderQueueEnqueueMessage
215                 (const CAEndpoint_t *remoteEndpoint, const void *data, uint32_t dataLen);
216
217 /**
218  * @brief  This is the thread which will be used for processing receiver queue.
219  * @return NONE
220  */
221 void *CABleServerSenderQueueProcessor();
222
223 #endif /* TZ_BLE_SERVER_H_ */
224