Merge branch 'easysetup'
[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 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 CAStartLEGattServerThread(void *data);
47
48 /**
49  * Used to initialize gatt server.
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 CAInitLEGattServer();
57
58 /**
59  * Used to de-initialize gatt service and destroy the 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 CADeInitLEGattServer();
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  * Used to start advertising.
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 CALEStartAdvertise(const char *serviceUUID);
87
88 /**
89  * Used to stop 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 CALEStopAdvertise();
97
98 /**
99  * Used to terminate all required mutex variables for GATT server implementation.
100  */
101 void CATerminateGattServerMutexVariables();
102
103 /**
104  * Used to add new OIC service in GATT server using bt_gatt_add_service api and
105  * internally store service path(outparam) in global variable.
106  *
107  * @param[in]  serviceUUID  unique identifier for BLE OIC service.
108  *
109  * @return  ::CA_STATUS_OK or Appropriate error code.
110  * @retval  ::CA_STATUS_OK  Successful.
111  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
112  * @retval  ::CA_STATUS_FAILED Operation failed.
113  */
114 CAResult_t CAAddNewLEServiceInGattServer(const char *serviceUUID);
115
116 /**
117  * Used to register the service in Gatt Server using bt_gatt_register_service api.
118  *
119  * @param[in] svcPath  unique identifier for BLE OIC service which is outparam of
120  *                     bt_gatt_service_create api.
121  * @return  ::CA_STATUS_OK or Appropriate error code.
122  * @retval  ::CA_STATUS_OK  Successful.
123  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
124  * @retval  ::CA_STATUS_FAILED Operation failed.
125  */
126 CAResult_t CARegisterLEServicewithGattServer(const bt_gatt_h svcPath);
127
128 /**
129  * Used to add new characteristics(Read/Write) to the service in Gatt Server using
130  * bt_gatt_add_characteristic api.
131  * @param[in] svcPath         Service path to which this characteristic belongs to.
132  * @param[in] charUUID        Gatt characteristic uuid.
133  * @param[in] charValue       Gatt characteristic value.
134  * @param[in] charValueLen    Characteristic value length.
135  * @param[in] read            Boolean variable for checking whether read characteristics or
136  *                            write characteristics.
137  * @return  ::CA_STATUS_OK or Appropriate error code.
138  */
139 CAResult_t CAAddNewCharacteristicsToGattServer(const bt_gatt_h svcPath, const char *charUUID,
140                                                const char *charValue, int charValueLen, bool read);
141
142 /**
143  * This is the callback which will be called when client update one of the characteristics
144  * with data.
145  * @param[in] remote_address The address of the remote device which requests a change
146  * @param[in] server         The GATT server handle
147  * @param[in] gatt_handle    The characteristic or descriptor's GATT handle which has an old value
148  * @param[in] offset         The requested offset from where the @a gatt_handle value will be updated
149  * @param[in] value          The new value
150  * @param[in] len            The length of @a value
151  * @param[in] user_data      The user data passed from the registration function
152  */
153 void CALEGattRemoteCharacteristicWriteCb(char *remoteAddress, bt_gatt_server_h server,
154                                          bt_gatt_h charPath, int offset, char *charValue,
155                                          int charValueLen, void *userData);
156
157 /**
158  * This is the callback which will be called whenever there is change in gatt connection
159  * with Client(Connected/Disconnected).
160  *
161  * @param[in]  connected      State of connection.
162  * @param[in]  remoteAddress  Mac address of the remote device in which we made connection.
163  */
164 void CALEGattServerConnectionStateChanged(bool connected, const char *remoteAddress);
165
166 /**
167  * Setting the connection state changed callback.
168  * @param[in] connStateCb      callback for receiving the changed network info.
169  */
170 void CASetLEConnectionStateChangedCallback(CALEConnectionStateChangedCallback connStateCb);
171
172 #endif /* TZ_BLE_SERVER_H_ */
173