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