1 /* ****************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
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.
31 #ifndef TZ_BLE_SERVER_H_
32 #define TZ_BLE_SERVER_H_
34 #include "caadapterinterface.h"
36 #include "cathreadpool.h"
37 #include "caleinterface.h"
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.
44 * @param[in] data Currently it will be NULL.
46 void CAStartLEGattServerThread(void *data);
49 * Used to initialize gatt server.
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.
56 CAResult_t CAInitLEGattServer();
59 * Used to de-initialize gatt service and destroy the GATT server.
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.
66 CAResult_t CADeInitLEGattServer();
69 * Used to initialize all required mutex variables for GATT server implementation.
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.
76 CAResult_t CAInitGattServerMutexVariables();
79 * Used to start advertising.
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.
86 CAResult_t CALEStartAdvertise(const char *serviceUUID);
89 * Used to stop advertising.
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.
96 CAResult_t CALEStopAdvertise();
99 * Used to terminate all required mutex variables for GATT server implementation.
101 void CATerminateGattServerMutexVariables();
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.
107 * @param[in] serviceUUID unique identifier for BLE OIC service.
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.
114 CAResult_t CAAddNewLEServiceInGattServer(const char *serviceUUID);
117 * Used to register the service in Gatt Server using bt_gatt_register_service api.
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.
126 CAResult_t CARegisterLEServicewithGattServer(const bt_gatt_h svcPath);
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.
139 CAResult_t CAAddNewCharacteristicsToGattServer(const bt_gatt_h svcPath, const char *charUUID,
140 const char *charValue, int charValueLen, bool read);
143 * This is the callback which will be called when client update one of the characteristics
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
153 void CALEGattRemoteCharacteristicWriteCb(char *remoteAddress, bt_gatt_server_h server,
154 bt_gatt_h charPath, int offset, char *charValue,
155 int charValueLen, void *userData);
158 * This is the callback which will be called whenever there is change in gatt connection
159 * with Client(Connected/Disconnected).
161 * @param[in] connected State of connection.
162 * @param[in] remoteAddress Mac address of the remote device in which we made connection.
164 void CALEGattServerConnectionStateChanged(bool connected, const char *remoteAddress);
167 * Setting the connection state changed callback.
168 * @param[in] connStateCb callback for receiving the changed network info.
170 void CASetLEConnectionStateChangedCallback(CALEConnectionStateChangedCallback connStateCb);
172 #endif /* TZ_BLE_SERVER_H_ */