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 "camessagehandler.h"
28 #include "caleserver.h"
29 #include "cagattservice.h"
32 #define TAG "OIC_CA_MANAGER_TZ_LE"
34 static CAAdapterStateChangedCB g_adapterStateCB = NULL;
35 static CAConnectionStateChangedCB g_connStateCB = NULL;
37 static void CAManagerAdapterMonitorHandler(const CAEndpoint_t *info, CANetworkStatus_t status);
38 static void CAManagerConnectionMonitorHandler(CATransportAdapter_t adapter,
39 const char *remoteAddress, bool connected);
41 void CASetLENetworkMonitorCallbacks(CAAdapterStateChangedCB adapterStateCB,
42 CAConnectionStateChangedCB connStateCB)
44 OIC_LOG(DEBUG, TAG, "CASetLENetworkMonitorCallbacks");
46 g_adapterStateCB = adapterStateCB;
47 CASetNetworkMonitorCallback(CAManagerAdapterMonitorHandler);
49 g_connStateCB = connStateCB;
50 CASetLEConnectionStateChangedCallback(CAManagerConnectionMonitorHandler);
53 void CAStartServerLEAdvertising()
55 OIC_LOG(DEBUG, TAG, "CAStartServerLEAdvertising");
57 CAResult_t res = CALEStartAdvertise(CA_GATT_SERVICE_UUID);
58 if (CA_STATUS_OK != res)
60 OIC_LOG_V(ERROR, TAG, "Failed to start le advertising [%d]", res);
65 void CAStopServerLEAdvertising()
67 OIC_LOG(DEBUG, TAG, "CAStopServerLEAdvertising");
69 CAResult_t res = CALEStopAdvertise();
70 if (CA_STATUS_OK != res)
72 OIC_LOG_V(ERROR, TAG, "Failed to stop le advertising [%d]", res);
77 CAResult_t CASetLEClientAutoConnectionDeviceInfo(const char * address)
79 OIC_LOG(DEBUG, TAG, "CASetLEClientAutoConnectionDeviceInfo");
81 return CA_NOT_SUPPORTED;
84 CAResult_t CAUnsetLEClientAutoConnectionDeviceInfo(const char * address)
86 OIC_LOG(DEBUG, TAG, "CAUnsetLEClientAutoConnectionDeviceInfo");
88 return CA_NOT_SUPPORTED;
91 static void CAManagerAdapterMonitorHandler(const CAEndpoint_t *info, CANetworkStatus_t status)
93 if (CA_INTERFACE_DOWN == status)
95 if (info && g_adapterStateCB)
97 g_adapterStateCB(info->adapter, false);
98 OIC_LOG(DEBUG, TAG, "Pass the disabled adapter state to upper layer");
101 else if (CA_INTERFACE_UP == status)
103 if (info && g_adapterStateCB)
105 g_adapterStateCB(info->adapter, true);
106 OIC_LOG(DEBUG, TAG, "Pass the enabled adapter state to upper layer");
111 static void CAManagerConnectionMonitorHandler(CATransportAdapter_t adapter,
112 const char *remoteAddress, bool connected)
118 OIC_LOG(ERROR, TAG, "remoteAddress is NULL");
126 g_connStateCB(CA_ADAPTER_GATT_BTLE, remoteAddress, true);
127 OIC_LOG(DEBUG, TAG, "Pass the connected device info to upper layer");
129 // stop le advertising
130 CAStopServerLEAdvertising();
137 g_connStateCB(CA_ADAPTER_GATT_BTLE, remoteAddress, false);
138 OIC_LOG(DEBUG, TAG, "Pass the disconnected device info to upper layer");
140 // start le advertising to receive new connection request.
141 CAStartServerLEAdvertising();