bc96a97e4dccb96ec71ad287169490f8f2e5bfd0
[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 <bluetooth.h>
35 #include <bluetooth_type.h>
36 #ifdef BLE_MCD
37 #include <bluetooth_product.h>
38 #endif
39 #include "caadapterinterface.h"
40 #include "logger.h"
41 #include "cathreadpool.h"
42 #include "caleinterface.h"
43
44 #if defined(__TIZEN__) && defined(LE_ADAPTER) && defined(BLE_CUSTOM_ADVERTISE)
45 /**
46  * Used to Start Server advertise send data
47  */
48 CAResult_t CAsetServerAdvertisementData(const char *data, int length);
49
50 /**
51  * Used to set advertisement data getter callback.
52  * @param[in]   getter    Bluetooth advertisement data getter callback.
53  */
54 void CAsetServerAdvertisementDataGetter(CAAdvertisementDataGetterCB getter);
55
56 /**
57  * Used to Start/Stop  auto advertisement feature.
58  *
59  * @param[in]   auto_advertisement    Boolean flag to turn auto advertisement feature on and off.
60  */
61 void CAsetServerAutoAdvertisement(bool autoAdvertisement);
62
63 /**
64  * Used to Start Server  send  response data
65  */
66 CAResult_t CAsetServerSanResponseData(const char *data, int length);
67 #endif
68
69 /**
70  * Used to initialize gatt server.
71  *
72  * @return  ::CA_STATUS_OK or Appropriate error code.
73  * @retval  ::CA_STATUS_OK  Successful.
74  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
75  * @retval  ::CA_STATUS_FAILED Operation failed.
76  */
77 CAResult_t CAInitLEGattServer();
78
79 /**
80  * Used to de-initialize gatt service and destroy the GATT server.
81  *
82  * @return  ::CA_STATUS_OK or Appropriate error code.
83  * @retval  ::CA_STATUS_OK  Successful.
84  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
85  * @retval  ::CA_STATUS_FAILED Operation failed.
86  */
87 CAResult_t CADeInitLEGattServer();
88
89 /**
90  * Used to initialize all required mutex variables for GATT server implementation.
91  *
92  * @return  ::CA_STATUS_OK or Appropriate error code.
93  * @retval  ::CA_STATUS_OK  Successful.
94  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
95  * @retval  ::CA_STATUS_FAILED Operation failed.
96  */
97 CAResult_t CAInitGattServerMutexVariables();
98
99 /**
100  * Used to start advertising.
101  *
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 CALEStartAdvertise();
108
109 /**
110  * Used to start advertising with service UUID.
111  *
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 CALEStartAdvertiseImpl(const char *serviceUUID);
118
119 /**
120  * Used to stop advertising.
121  *
122  * @return  ::CA_STATUS_OK or Appropriate error code.
123  * @retval  ::CA_STATUS_OK  Successful.
124  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
125  * @retval  ::CA_STATUS_FAILED Operation failed.
126  */
127 CAResult_t CALEStopAdvertise();
128
129 /**
130  * Used to terminate all required mutex variables for GATT server implementation.
131  */
132 void CATerminateGattServerMutexVariables();
133
134 /**
135  * Used to add new OIC service in GATT server using bt_gatt_add_service api and
136  * internally store service path(outparam) in global variable.
137  *
138  * @param[in]  serviceUUID  unique identifier for BLE OIC service.
139  *
140  * @return  ::CA_STATUS_OK or Appropriate error code.
141  * @retval  ::CA_STATUS_OK  Successful.
142  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
143  * @retval  ::CA_STATUS_FAILED Operation failed.
144  */
145 CAResult_t CAAddNewLEServiceInGattServer(const char *serviceUUID);
146
147 /**
148  * Used to register the service in Gatt Server using bt_gatt_register_service api.
149  *
150  * @param[in] svcPath  unique identifier for BLE OIC service which is outparam of
151  *                     bt_gatt_service_create api.
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 CARegisterLEServicewithGattServer(const bt_gatt_h svcPath);
158
159 /**
160  * Used to add new characteristics(Read/Write) to the service in Gatt Server using
161  * bt_gatt_add_characteristic api.
162  * @param[in] svcPath         Service path to which this characteristic belongs to.
163  * @param[in] charUUID        Gatt characteristic uuid.
164  * @param[in] charValue       Gatt characteristic value.
165  * @param[in] charValueLen    Characteristic value length.
166  * @param[in] read            Boolean variable for checking whether read characteristics or
167  *                            write characteristics.
168  * @return  ::CA_STATUS_OK or Appropriate error code.
169  */
170 CAResult_t CAAddNewCharacteristicsToGattServer(const bt_gatt_h svcPath, const char *charUUID,
171                                                const char *charValue, int charValueLen, bool read);
172
173 /**
174  * This is the callback which will be called when client update one of the characteristics
175  * with data.
176  * @param[in] remote_address The address of the remote device which requests a change
177  * @param[in] server         The GATT server handle
178  * @param[in] gatt_handle    The characteristic or descriptor's GATT handle which has an old value
179  * @param[in] offset         The requested offset from where the @a gatt_handle value will be updated
180  * @param[in] value          The new value
181  * @param[in] len            The length of @a value
182  * @param[in] user_data      The user data passed from the registration function
183  */
184 #ifdef BLE_TIZEN_30
185 void CALEGattRemoteCharacteristicWriteCb(const char *remoteAddress, int request_id,
186                                          bt_gatt_server_h server, bt_gatt_h gatt_handle,
187                                          bool response_needed, int offset, const char *charValue,
188                                          int charLen, void *userData);
189 #else
190 void CALEGattRemoteCharacteristicWriteCb(char *remoteAddress, bt_gatt_server_h server,
191                                          bt_gatt_h gatt_handle, int offset, char *charValue,
192                                          int charLen, void *userData);
193 #endif
194
195 /**
196  * Setting the connection state changed callback.
197  * @param[in] connStateCb      callback for receiving the changed network info.
198  */
199 void CASetLEConnectionStateChangedCallback(CALEConnectionStateChangedCallback connStateCb);
200
201 /**
202  * check connection status.
203  * @param[in] address      the address of the remote device.
204  * @return  true or false.
205  */
206 bool CALEServerIsConnected(const char* address);
207
208 /**
209  * get MTU size.
210  * @param[in] address      the address of the remote device.
211  * @return  mtu size negotiated from remote device.
212  */
213 uint16_t CALEServerGetMtuSize(const char* address);
214
215 #endif /* TZ_BLE_SERVER_H_ */
216