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