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 <bluetooth.h>
35 #include <bluetooth_type.h>
36 #include <bluetooth_internal.h>
38 #include "caadapterinterface.h"
40 #include "cathreadpool.h"
41 #include "caleinterface.h"
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.
48 * @param[in] data Currently it will be NULL.
50 void CAStartLEGattServerThread(void *data);
53 * Used to initialize gatt server.
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.
60 CAResult_t CAInitLEGattServer();
63 * Used to de-initialize gatt service and destroy the GATT server.
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.
70 CAResult_t CADeInitLEGattServer();
73 * Used to initialize all required mutex variables for GATT server implementation.
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.
80 CAResult_t CAInitGattServerMutexVariables();
83 * Used to start advertising.
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.
90 CAResult_t CALEStartAdvertise(const char *serviceUUID);
93 * Used to stop advertising.
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.
100 CAResult_t CALEStopAdvertise();
103 * Used to terminate all required mutex variables for GATT server implementation.
105 void CATerminateGattServerMutexVariables();
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.
111 * @param[in] serviceUUID unique identifier for BLE OIC service.
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.
118 CAResult_t CAAddNewLEServiceInGattServer(const char *serviceUUID);
121 * Used to register the service in Gatt Server using bt_gatt_register_service api.
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.
130 CAResult_t CARegisterLEServicewithGattServer(const bt_gatt_h svcPath);
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.
143 CAResult_t CAAddNewCharacteristicsToGattServer(const bt_gatt_h svcPath, const char *charUUID,
144 const char *charValue, int charValueLen, bool read);
147 * This is the callback which will be called when client update one of the characteristics
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
157 void CALEGattRemoteCharacteristicWriteCb(char *remoteAddress, bt_gatt_server_h server,
158 bt_gatt_h charPath, int offset, char *charValue,
159 int charValueLen, void *userData);
162 * This is the callback which will be called whenever there is change in gatt connection
163 * with Client(Connected/Disconnected).
165 * @param[in] connected State of connection.
166 * @param[in] remoteAddress Mac address of the remote device in which we made connection.
168 void CALEGattServerConnectionStateChanged(bool connected, const char *remoteAddress);
171 * Setting the connection state changed callback.
172 * @param[in] connStateCb callback for receiving the changed network info.
174 void CASetLEConnectionStateChangedCallback(CALEConnectionStateChangedCallback connStateCb);
176 #endif /* TZ_BLE_SERVER_H_ */