1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "wificond/ap_interface_binder.h"
18
19 #include <android-base/logging.h>
20
21 #include "wificond/ap_interface_impl.h"
22
23 using android::net::wifi::nl80211::IApInterfaceEventCallback;
24 using android::net::wifi::nl80211::NativeWifiClient;
25
26 namespace android {
27 namespace wificond {
28
ApInterfaceBinder(ApInterfaceImpl * impl)29 ApInterfaceBinder::ApInterfaceBinder(ApInterfaceImpl* impl)
30 : impl_{impl}, ap_interface_event_callback_(nullptr) {}
31
~ApInterfaceBinder()32 ApInterfaceBinder::~ApInterfaceBinder() {
33 }
34
NotifyConnectedClientsChanged(const NativeWifiClient client,bool isConnected)35 void ApInterfaceBinder::NotifyConnectedClientsChanged(const NativeWifiClient client, bool isConnected) {
36 if (ap_interface_event_callback_ != nullptr) {
37 ap_interface_event_callback_->onConnectedClientsChanged(client, isConnected);
38 }
39 }
40
NotifySoftApChannelSwitched(int frequency,ChannelBandwidth channel_bandwidth)41 void ApInterfaceBinder::NotifySoftApChannelSwitched(
42 int frequency, ChannelBandwidth channel_bandwidth) {
43 if (ap_interface_event_callback_ == nullptr) {
44 return;
45 }
46
47 int bandwidth;
48 switch (channel_bandwidth) {
49 case ChannelBandwidth::BW_INVALID:
50 bandwidth = IApInterfaceEventCallback::BANDWIDTH_INVALID;
51 break;
52 case ChannelBandwidth::BW_20_NOHT:
53 bandwidth = IApInterfaceEventCallback::BANDWIDTH_20_NOHT;
54 break;
55 case ChannelBandwidth::BW_20:
56 bandwidth = IApInterfaceEventCallback::BANDWIDTH_20;
57 break;
58 case ChannelBandwidth::BW_40:
59 bandwidth = IApInterfaceEventCallback::BANDWIDTH_40;
60 break;
61 case ChannelBandwidth::BW_80:
62 bandwidth = IApInterfaceEventCallback::BANDWIDTH_80;
63 break;
64 case ChannelBandwidth::BW_80P80:
65 bandwidth = IApInterfaceEventCallback::BANDWIDTH_80P80;
66 break;
67 case ChannelBandwidth::BW_160:
68 bandwidth = IApInterfaceEventCallback::BANDWIDTH_160;
69 break;
70 case ChannelBandwidth::BW_320:
71 bandwidth = IApInterfaceEventCallback::BANDWIDTH_320;
72 break;
73 default:
74 bandwidth = IApInterfaceEventCallback::BANDWIDTH_INVALID;
75 }
76 ap_interface_event_callback_->onSoftApChannelSwitched(frequency, bandwidth);
77 }
78
registerCallback(const sp<IApInterfaceEventCallback> & callback,bool * out_success)79 binder::Status ApInterfaceBinder::registerCallback(
80 const sp<IApInterfaceEventCallback>& callback, bool* out_success) {
81 *out_success = true;
82 ap_interface_event_callback_ = callback;
83 return binder::Status::ok();
84 }
85
getInterfaceName(std::string * out_name)86 binder::Status ApInterfaceBinder::getInterfaceName(std::string* out_name) {
87 *out_name = impl_->GetInterfaceName();
88 return binder::Status::ok();
89 }
90
91 } // namespace wificond
92 } // namespace android
93