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 * Used to initialize gatt server.
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.
51 CAResult_t CAInitLEGattServer();
54 * Used to de-initialize gatt service and destroy the GATT server.
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.
61 CAResult_t CADeInitLEGattServer();
64 * Used to initialize all required mutex variables for GATT server implementation.
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.
71 CAResult_t CAInitGattServerMutexVariables();
74 * Used to start advertising.
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.
81 CAResult_t CALEStartAdvertise(const char *serviceUUID);
84 * Used to stop advertising.
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.
91 CAResult_t CALEStopAdvertise();
94 * Used to terminate all required mutex variables for GATT server implementation.
96 void CATerminateGattServerMutexVariables();
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.
102 * @param[in] serviceUUID unique identifier for BLE OIC service.
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.
109 CAResult_t CAAddNewLEServiceInGattServer(const char *serviceUUID);
112 * Used to register the service in Gatt Server using bt_gatt_register_service api.
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.
121 CAResult_t CARegisterLEServicewithGattServer(const bt_gatt_h svcPath);
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.
134 CAResult_t CAAddNewCharacteristicsToGattServer(const bt_gatt_h svcPath, const char *charUUID,
135 const char *charValue, int charValueLen, bool read);
138 * This is the callback which will be called when client update one of the characteristics
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
148 void CALEGattRemoteCharacteristicWriteCb(char *remoteAddress, bt_gatt_server_h server,
149 bt_gatt_h charPath, int offset, char *charValue,
150 int charValueLen, void *userData);
153 * Setting the connection state changed callback.
154 * @param[in] connStateCb callback for receiving the changed network info.
156 void CASetLEConnectionStateChangedCallback(CALEConnectionStateChangedCallback connStateCb);
158 #endif /* TZ_BLE_SERVER_H_ */