Added connectivity files for full code review
[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 cableserver.h
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.
27  */
28
29 #ifndef __TZ_BLE_SERVER_H_
30 #define __TZ_BLE_SERVER_H_
31
32 #include "caadapterinterface.h"
33 #include "logger.h"
34 #include "uthreadpool.h"
35 #include "caleinterface.h"
36
37 /**
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.
41  *
42  * @param data [IN] Currently it will be NULL.
43  * @return  NONE
44  */
45 void CAStartBleGattServerThread(void *data);
46
47 /**
48  * @brief  Used to initialize gatt service using _bt_gatt_init_service api.
49  *
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
54  */
55 CAResult_t CAInitBleGattService();
56
57 /**
58  * @brief  Used to de-initialize gatt service using _bt_gatt_deinit_service api.
59  *
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
64  */
65 CAResult_t CADeInitBleGattService();
66
67 /**
68  * @brief  Used to initialize all required mutex variables for GATT server implementation.
69  *
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
74  */
75 CAResult_t CAInitGattServerMutexVariables();
76
77
78 /**
79  * @brief  Used to terminate all required mutex variables for GATT server implementation.
80  * @return NONE
81  */
82 void CATerminateGattServerMutexVariables();
83
84 /**
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.
87  *
88  * @param  serviceUUID [IN] 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 argumets
93  * @retval #CA_STATUS_FAILED Operation failed
94  */
95 CAResult_t CAAddNewBleServiceInGattServer(const char *serviceUUID);
96
97 /**
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
106  */
107 CAResult_t CARemoveBleServiceFromGattServer(const char *svcPath);
108
109 /**
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
116  */
117 CAResult_t CARemoveAllBleServicesFromGattServer();
118
119 /**
120  * @brief  Used to register the service in Gatt Server using bt_gatt_register_service api.
121  *
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
128  */
129 CAResult_t CARegisterBleServicewithGattServer(const char *svcPath);
130
131 /**
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
141  */
142 CAResult_t CAAddNewCharacteristicsToGattServer(const char *svcPath, const char *charUUID,
143                                                const char *charValue, int charValueLen,
144                                                bool read);
145
146 /**
147  * @brief  Used to remove characteristics(Read/Write) from the service in Gatt Server.
148  *
149  * @param  charPath  [IN] 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 argumets
155  * @retval #CA_STATUS_FAILED Operation failed
156  */
157 CAResult_t CARemoveCharacteristicsFromGattServer(const char *charPath);
158
159 /**
160  * @brief  This is the callback which will be called when client update one of the characteristics
161  *         with data.
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
167  *
168  * @return NONE
169  */
170 void CABleGattRemoteCharacteristicWriteCb(char *charPath, unsigned char *charValue,
171                                           int charValueLen, void *userData);
172
173 /**
174  * @brief  This is the callback which will be called whenever there is change in gatt connection
175  *         with Client(Connected/Disconnected).
176  *
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.
181  *
182  * @return  NONE
183  */
184 void CABleGattServerConnectionStateChangedCb(int result, bool connected,
185                                              const char *remoteAddress, void *userData);
186
187 /**
188  * @brief  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 argumets
193  * @retval #CA_STATUS_FAILED Operation failed
194  */
195 CAResult_t CALEReadDataFromLEServer();
196
197 /**
198  * @brief  Used to enqueue the message into sender queue using CAAdapterEnqueueMessage and make
199  *         signal to the thread to process.
200  *
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.
204  *
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
209  */
210 CAResult_t CABleServerSenderQueueEnqueueMessage
211                 (const CARemoteEndpoint_t *remoteEndpoint, const void *data, uint32_t dataLen);
212
213 /**
214  * @brief  This is the thread which will be used for processing receiver queue.
215  * @return NONE
216  */
217 void *CABleServerSenderQueueProcessor();
218
219 #endif //#ifndef __TZ_BLE_SERVER_H_
220