100ea9b262c399eb08c74925c07eef07ee168df4
[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
38 #include "caadapterinterface.h"
39 #include "logger.h"
40 #include "cathreadpool.h"
41 #include "caleinterface.h"
42
43 /**
44  * This is thread which will be used for creating ble service and advertise ble service.
45  * 1. Create New OIC Service 2. Add read & write characteristics to service.
46  * 3. Register Service       4. Advertise service.
47  *
48  * @param[in] data  Currently it will be NULL.
49  */
50 void CAStartLEGattServerThread(void *data);
51
52 /**
53  * Used to initialize gatt server.
54  *
55  * @return  ::CA_STATUS_OK or Appropriate error code.
56  * @retval  ::CA_STATUS_OK  Successful.
57  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
58  * @retval  ::CA_STATUS_FAILED Operation failed.
59  */
60 CAResult_t CAInitLEGattServer();
61
62 /**
63  * Used to de-initialize gatt service and destroy the GATT server.
64  *
65  * @return  ::CA_STATUS_OK or Appropriate error code.
66  * @retval  ::CA_STATUS_OK  Successful.
67  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
68  * @retval  ::CA_STATUS_FAILED Operation failed.
69  */
70 CAResult_t CADeInitLEGattServer();
71
72 /**
73  * Used to initialize all required mutex variables for GATT server implementation.
74  *
75  * @return  ::CA_STATUS_OK or Appropriate error code.
76  * @retval  ::CA_STATUS_OK  Successful.
77  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
78  * @retval  ::CA_STATUS_FAILED Operation failed.
79  */
80 CAResult_t CAInitGattServerMutexVariables();
81
82 /**
83  * Used to start advertising.
84  *
85  * @return  ::CA_STATUS_OK or Appropriate error code.
86  * @retval  ::CA_STATUS_OK  Successful.
87  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
88  * @retval  ::CA_STATUS_FAILED Operation failed.
89  */
90 CAResult_t CALEStartAdvertise(const char *serviceUUID);
91
92 /**
93  * Used to stop advertising.
94  *
95  * @return  ::CA_STATUS_OK or Appropriate error code.
96  * @retval  ::CA_STATUS_OK  Successful.
97  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
98  * @retval  ::CA_STATUS_FAILED Operation failed.
99  */
100 CAResult_t CALEStopAdvertise();
101
102 /**
103  * Used to terminate all required mutex variables for GATT server implementation.
104  */
105 void CATerminateGattServerMutexVariables();
106
107 /**
108  * Used to add new OIC service in GATT server using bt_gatt_add_service api and
109  * internally store service path(outparam) in global variable.
110  *
111  * @param[in]  serviceUUID  unique identifier for BLE OIC service.
112  *
113  * @return  ::CA_STATUS_OK or Appropriate error code.
114  * @retval  ::CA_STATUS_OK  Successful.
115  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
116  * @retval  ::CA_STATUS_FAILED Operation failed.
117  */
118 CAResult_t CAAddNewLEServiceInGattServer(const char *serviceUUID);
119
120 /**
121  * Used to register the service in Gatt Server using bt_gatt_register_service api.
122  *
123  * @param[in] svcPath  unique identifier for BLE OIC service which is outparam of
124  *                     bt_gatt_service_create api.
125  * @return  ::CA_STATUS_OK or Appropriate error code.
126  * @retval  ::CA_STATUS_OK  Successful.
127  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
128  * @retval  ::CA_STATUS_FAILED Operation failed.
129  */
130 CAResult_t CARegisterLEServicewithGattServer(const bt_gatt_h svcPath);
131
132 /**
133  * Used to add new characteristics(Read/Write) to the service in Gatt Server using
134  * bt_gatt_add_characteristic api.
135  * @param[in] svcPath         Service path to which this characteristic belongs to.
136  * @param[in] charUUID        Gatt characteristic uuid.
137  * @param[in] charValue       Gatt characteristic value.
138  * @param[in] charValueLen    Characteristic value length.
139  * @param[in] read            Boolean variable for checking whether read characteristics or
140  *                            write characteristics.
141  * @return  ::CA_STATUS_OK or Appropriate error code.
142  */
143 CAResult_t CAAddNewCharacteristicsToGattServer(const bt_gatt_h svcPath, const char *charUUID,
144                                                const char *charValue, int charValueLen, bool read);
145
146 /**
147  * This is the callback which will be called when client update one of the characteristics
148  * with data.
149  * @param[in] remote_address The address of the remote device which requests a change
150  * @param[in] server         The GATT server handle
151  * @param[in] gatt_handle    The characteristic or descriptor's GATT handle which has an old value
152  * @param[in] offset         The requested offset from where the @a gatt_handle value will be updated
153  * @param[in] value          The new value
154  * @param[in] len            The length of @a value
155  * @param[in] user_data      The user data passed from the registration function
156  */
157 void CALEGattRemoteCharacteristicWriteCb(char *remoteAddress, bt_gatt_server_h server,
158                                          bt_gatt_h charPath, int offset, char *charValue,
159                                          int charValueLen, void *userData);
160
161 /**
162  * This is the callback which will be called whenever there is change in gatt connection
163  * with Client(Connected/Disconnected).
164  *
165  * @param[in]  connected      State of connection.
166  * @param[in]  remoteAddress  Mac address of the remote device in which we made connection.
167  */
168 void CALEGattServerConnectionStateChanged(bool connected, const char *remoteAddress);
169
170 /**
171  * Setting the connection state changed callback.
172  * @param[in] connStateCb      callback for receiving the changed network info.
173  */
174 void CASetLEConnectionStateChangedCallback(CALEConnectionStateChangedCallback connStateCb);
175
176 #endif /* TZ_BLE_SERVER_H_ */
177