1 /* ****************************************************************
3 * Copyright 2016 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>
23 #include <bluetooth_internal.h>
25 #include "camanagerleinterface.h"
27 #include "caleserver.h"
28 #include "cagattservice.h"
31 #define TAG "OIC_CA_MANAGER_TZ_LE"
33 static CAAdapterStateChangedCB g_adapterStateCB = NULL;
34 static CAConnectionStateChangedCB g_connStateCB = NULL;
36 static void CAManagerAdapterMonitorHandler(const CAEndpoint_t *info, CANetworkStatus_t status);
37 static void CAManagerConnectionMonitorHandler(CATransportAdapter_t adapter,
38 const char *remoteAddress, bool connected);
40 void CASetLENetworkMonitorCallbacks(CAAdapterStateChangedCB adapterStateCB,
41 CAConnectionStateChangedCB connStateCB)
43 OIC_LOG(DEBUG, TAG, "CASetLENetworkMonitorCallbacks");
45 g_adapterStateCB = adapterStateCB;
46 CASetNetworkMonitorCallback(CAManagerAdapterMonitorHandler);
48 g_connStateCB = connStateCB;
49 CASetLEConnectionStateChangedCallback(CAManagerConnectionMonitorHandler);
52 void CAStartServerLEAdvertising()
54 OIC_LOG(DEBUG, TAG, "CAStartServerLEAdvertising");
56 CAResult_t res = CALEStartAdvertise(CA_GATT_SERVICE_UUID);
57 if (CA_STATUS_OK != res)
59 OIC_LOG_V(ERROR, TAG, "Failed to start le advertising [%d]", res);
64 void CAStopServerLEAdvertising()
66 OIC_LOG(DEBUG, TAG, "CAStopServerLEAdvertising");
68 CAResult_t res = CALEStopAdvertise();
69 if (CA_STATUS_OK != res)
71 OIC_LOG_V(ERROR, TAG, "Failed to stop le advertising [%d]", res);
76 CAResult_t CASetLEClientAutoConnectionDeviceInfo(const char * address)
78 OIC_LOG(DEBUG, TAG, "CASetLEClientAutoConnectionDeviceInfo");
79 return CA_NOT_SUPPORTED;
82 CAResult_t CAUnsetLEClientAutoConnectionDeviceInfo(const char * address)
84 OIC_LOG(DEBUG, TAG, "CAUnsetLEClientAutoConnectionDeviceInfo");
85 return CA_NOT_SUPPORTED;
88 static void CAManagerAdapterMonitorHandler(const CAEndpoint_t *info, CANetworkStatus_t status)
93 if (CA_INTERFACE_DOWN == status)
95 g_adapterStateCB(info->adapter, false);
96 OIC_LOG(DEBUG, TAG, "Pass the disabled adapter state to upper layer");
98 else if (CA_INTERFACE_UP == status)
100 g_adapterStateCB(info->adapter, true);
101 OIC_LOG(DEBUG, TAG, "Pass the enabled adapter state to upper layer");
105 static void CAManagerConnectionMonitorHandler(CATransportAdapter_t adapter,
106 const char *remoteAddress, bool connected)
110 OIC_LOG(ERROR, TAG, "remoteAddress is NULL");
118 g_connStateCB(CA_ADAPTER_GATT_BTLE, remoteAddress, true);
119 OIC_LOG(DEBUG, TAG, "Pass the connected device info to upper layer");
121 // stop le advertising
122 CAStopServerLEAdvertising();
129 g_connStateCB(CA_ADAPTER_GATT_BTLE, remoteAddress, false);
130 OIC_LOG(DEBUG, TAG, "Pass the disconnected device info to upper layer");
132 // start le advertising to receive new connection request.
133 CAStartServerLEAdvertising();