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 ******************************************************************/
21 #include <bluetooth.h>
22 #include <bluetooth_type.h>
24 #include "caleserver.h"
27 #include "caadapterutils.h"
30 #include "caqueueingthread.h"
31 #include "caadapterutils.h"
32 #include "cafragmentation.h"
33 #include "cagattservice.h"
35 #include "oic_string.h"
36 #include "oic_malloc.h"
39 * @def TZ_BLE_SERVER_TAG
40 * @brief Logging tag for module name
42 #define TZ_BLE_SERVER_TAG "OIC_CA_LE_SERVER"
44 void CABleGattServerConnectionStateChangedCb(int result, bool connected,
45 const char *remoteAddress, void *userData)
47 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
49 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
52 CAResult_t CAStartLEGattServer()
54 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
55 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
59 void CAStartBleGattServerThread(void *data)
61 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
63 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
66 CAResult_t CAStopLEGattServer()
68 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
70 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
74 void CATerminateLEGattServer()
76 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
78 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
81 CAResult_t CAInitializeLEGattServer()
83 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
85 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
89 CAResult_t CAInitBleGattService()
91 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
93 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
97 CAResult_t CADeInitBleGattService()
99 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
101 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
105 void CASetLEServerThreadPoolHandle(ca_thread_pool_t handle)
107 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
108 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
111 CAResult_t CAAddNewBleServiceInGattServer(const char *serviceUUID)
113 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
114 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
118 CAResult_t CARemoveBleServiceFromGattServer(const char *svcPath)
120 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
121 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
125 CAResult_t CARemoveAllBleServicesFromGattServer()
127 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
128 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
132 void CABleGattRemoteCharacteristicWriteCb(char *charPath,
133 unsigned char *charValue,
135 const char *remoteAddress,
138 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
139 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
142 CAResult_t CARegisterBleServicewithGattServer(const char *svcPath)
144 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
145 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
149 CAResult_t CAAddNewCharacteristicsToGattServer(const char *svcPath, const char *charUUID,
150 const uint8_t *charValue, int charValueLen, bool read)
153 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
154 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
158 CAResult_t CARemoveCharacteristicsFromGattServer(const char *charPath)
160 ///TODO: There is no api provided in bluetooth.h for removing characteristics.
164 CAResult_t CAUpdateCharacteristicsToGattClient(const char *address,
165 const uint8_t *charValue,
166 uint32_t charValueLen)
168 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
170 OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "OUT");
174 CAResult_t CAUpdateCharacteristicsToAllGattClients(const uint8_t *charValue, uint32_t charValueLen)
176 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
178 OIC_LOG(ERROR, TZ_BLE_SERVER_TAG, "OUT");
182 void CASetLEReqRespServerCallback(CABLEDataReceivedCallback callback)
184 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
186 OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
189 void CASetBLEServerErrorHandleCallback(CABLEErrorHandleCallback callback)