f8bd414c821d4ba9a68d034bbe48ddb9ae4b642a
[platform/upstream/iotivity.git] / resource / csdk / connectivity / src / bt_le_adapter / tizen / caleserver.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  * 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[in] data  Currently it will be NULL.
45  */
46 void CAStartBleGattServerThread(void *data);
47
48 /**
49  * Used to initialize gatt service using _bt_gatt_init_service api.
50  *
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.
55  */
56 CAResult_t CAInitBleGattService();
57
58 /**
59  * Used to de-initialize gatt service using _bt_gatt_deinit_service api.
60  *
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.
65  */
66 CAResult_t CADeInitBleGattService();
67
68 /**
69  * Used to initialize all required mutex variables for GATT server implementation.
70  *
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.
75  */
76 CAResult_t CAInitGattServerMutexVariables();
77
78
79 /**
80  * Used to terminate all required mutex variables for GATT server implementation.
81  */
82 void CATerminateGattServerMutexVariables();
83
84 /**
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.
87  *
88  * @param[in]  serviceUUID  unique identifier for BLE OIC service.
89  *
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.
94  */
95 CAResult_t CAAddNewBleServiceInGattServer(const char *serviceUUID);
96
97 /**
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.
106  */
107 CAResult_t CARemoveBleServiceFromGattServer(const char *svcPath);
108
109 /**
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.
116  */
117 CAResult_t CARemoveAllBleServicesFromGattServer();
118
119 /**
120  * Used to register the service in Gatt Server using bt_gatt_register_service api.
121  *
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.
128  */
129 CAResult_t CARegisterBleServicewithGattServer(const char *svcPath);
130
131 /**
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.
141  */
142 CAResult_t CAAddNewCharacteristicsToGattServer(const char *svcPath, const char *charUUID,
143                                                const uint8_t *charValue, int charValueLen,
144                                                bool read);
145
146 /**
147  * Used to remove characteristics(Read/Write) from the service in Gatt Server.
148  *
149  * @param[in]  charPath   Characteristic path registered on the interface and unique identifier
150  *                        for added characteristics.
151  *
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.
156  */
157 CAResult_t CARemoveCharacteristicsFromGattServer(const char *charPath);
158
159 /**
160  * This is the callback which will be called when client update one of the characteristics
161  * with data.
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.
168
169  */
170 void CABleGattRemoteCharacteristicWriteCb(char *charPath, unsigned char *charValue,
171                                           int charValueLen, const char  *remoteAddress,
172                                           void *userData);
173
174 /**
175  * This is the callback which will be called whenever there is change in gatt connection
176  * with Client(Connected/Disconnected).
177  *
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.
182
183  */
184 void CABleGattServerConnectionStateChangedCb(int result, bool connected,
185                                              const char *remoteAddress, void *userData);
186
187 /**
188  * Synchronous function for reading characteristic value.
189  *
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.
194  */
195 CAResult_t CALEReadDataFromLEServer();
196
197 /**
198  * Used to enqueue the message into sender queue using CAAdapterEnqueueMessage and make
199  * signal to the thread to process.
200  *
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.
204  *
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.
209  */
210 CAResult_t CABleServerSenderQueueEnqueueMessage
211                 (const CAEndpoint_t *remoteEndpoint, const uint8_t *data, uint32_t dataLen);
212
213 /**
214  * This is the thread which will be used for processing receiver queue.
215  */
216 void *CABleServerSenderQueueProcessor();
217
218 #endif /* TZ_BLE_SERVER_H_ */
219