SupplicantStaIfaceHal.java revision b850a6ae6fe8470fd9338bbc9978caadc7ca2c4b
1240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne/*
298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne * Copyright (C) 2017 The Android Open Source Project
3240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne *
4240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * Licensed under the Apache License, Version 2.0 (the "License");
5240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * you may not use this file except in compliance with the License.
6240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * You may obtain a copy of the License at
7240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne *
8240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne *      http://www.apache.org/licenses/LICENSE-2.0
9240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne *
10240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * Unless required by applicable law or agreed to in writing, software
11240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * distributed under the License is distributed on an "AS IS" BASIS,
12240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * See the License for the specific language governing permissions and
14240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * limitations under the License.
15240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne */
16240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhnepackage com.android.server.wifi;
17240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
185a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.ANQP3GPPNetwork;
195a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.ANQPDomName;
205a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.ANQPIPAddrAvailability;
215a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.ANQPNAIRealm;
225a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.ANQPRoamingConsortium;
235a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.ANQPVenueName;
245a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.HSConnCapability;
255a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.HSFriendlyName;
265a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.HSOSUProviders;
275a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.HSWANMetrics;
285a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius
29c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Piusimport android.content.Context;
30240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.hardware.wifi.supplicant.V1_0.ISupplicant;
31240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.hardware.wifi.supplicant.V1_0.ISupplicantIface;
3296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhneimport android.hardware.wifi.supplicant.V1_0.ISupplicantNetwork;
33240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.hardware.wifi.supplicant.V1_0.ISupplicantStaIface;
34c224fb554deca894818490c9416ff35d18a79d76Roshan Piusimport android.hardware.wifi.supplicant.V1_0.ISupplicantStaIfaceCallback;
3596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhneimport android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetwork;
36240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.hardware.wifi.supplicant.V1_0.IfaceType;
37240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.hardware.wifi.supplicant.V1_0.SupplicantStatus;
38240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.hardware.wifi.supplicant.V1_0.SupplicantStatusCode;
395f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Piusimport android.hardware.wifi.supplicant.V1_0.WpsConfigMethods;
40240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.hidl.manager.V1_0.IServiceManager;
41240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.hidl.manager.V1_0.IServiceNotification;
42f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Piusimport android.net.IpConfiguration;
4382c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Piusimport android.net.wifi.SupplicantState;
4466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhneimport android.net.wifi.WifiConfiguration;
4582c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Piusimport android.net.wifi.WifiSsid;
46240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.os.RemoteException;
47240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.util.Log;
48f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Piusimport android.util.SparseArray;
4996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
505a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.AnqpEvent;
515a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.IconEvent;
525a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.WnmData;
535a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.anqp.ANQPElement;
545a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.anqp.ANQPParser;
555a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.anqp.Constants;
56d95fa596d07855b70ff18a50a48e773155a919f5Roshan Piusimport com.android.server.wifi.util.NativeUtil;
57240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
585a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport java.io.IOException;
595a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport java.nio.BufferUnderflowException;
605f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Piusimport java.nio.ByteBuffer;
615f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Piusimport java.nio.ByteOrder;
62240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport java.util.ArrayList;
63f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Piusimport java.util.HashMap;
64f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Piusimport java.util.List;
65f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Piusimport java.util.Map;
665f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Piusimport java.util.regex.Matcher;
675f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Piusimport java.util.regex.Pattern;
68d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
69240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne/**
70240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * Hal calls for bring up/shut down of the supplicant daemon and for
71240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * sending requests to the supplicant daemon
72240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne */
73b4419d876beda78c29836726e43d80203b4a656cRoshan Piuspublic class SupplicantStaIfaceHal {
74240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    private static final boolean DBG = false;
75b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    private static final String TAG = "SupplicantStaIfaceHal";
7698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private static final String SERVICE_MANAGER_NAME = "manager";
775f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
785f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Regex pattern for extracting the wps device type bytes.
795f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Matches a strings like the following: "<categ>-<OUI>-<subcateg>";
805f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
815f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    private static final Pattern WPS_DEVICE_TYPE_PATTERN =
825f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            Pattern.compile("^(\\d{1,2})-([0-9a-fA-F]{8})-(\\d{1,2})$");
835f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
8498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private IServiceManager mIServiceManager = null;
8598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    // Supplicant HAL interface objects
8698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private ISupplicant mISupplicant;
8798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private ISupplicantStaIface mISupplicantStaIface;
8803fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius    private String mIfaceName;
897c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    // Currently configured network in wpa_supplicant
907c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    private SupplicantStaNetworkHal mCurrentNetwork;
917c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    // Currently configured network's framework network Id.
925a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius    private int mFrameworkNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
93240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    private final Object mLock = new Object();
94c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius    private final Context mContext;
95c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius    private final WifiMonitor mWifiMonitor;
967c0ec884188660f72977c8a80366049705c48ffaRoshan Pius
97c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius    public SupplicantStaIfaceHal(Context context, WifiMonitor monitor) {
98c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius        mContext = context;
99c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius        mWifiMonitor = monitor;
1008c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius    }
101240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
102240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    /**
10398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     * Registers a service notification for the ISupplicant service, which triggers intialization of
10498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     * the ISupplicantStaIface
105240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne     * @return true if the service notification was successfully registered
106240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne     */
107240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    public boolean initialize() {
10898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne        if (DBG) Log.i(TAG, "Registering ISupplicant service ready callback.");
109240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        synchronized (mLock) {
11098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicant = null;
11198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicantStaIface = null;
11298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            if (mIServiceManager != null) {
11398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                // Already have an IServiceManager and serviceNotification registered, don't
11498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                // don't register another.
11598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                return true;
11698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            }
117240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            try {
11898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                mIServiceManager = getServiceManagerMockable();
11998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                if (mIServiceManager == null) {
120240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    Log.e(TAG, "Failed to get HIDL Service Manager");
121240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    return false;
122240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }
12398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                if (!mIServiceManager.linkToDeath(cookie -> {
124240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    Log.wtf(TAG, "IServiceManager died: cookie=" + cookie);
125240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    synchronized (mLock) {
126240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        supplicantServiceDiedHandler();
12798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                        mIServiceManager = null; // Will need to register a new ServiceNotification
128240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    }
129240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }, 0)) {
130240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    Log.wtf(TAG, "Error on linkToDeath on IServiceManager");
131240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    supplicantServiceDiedHandler();
13298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                    mIServiceManager = null; // Will need to register a new ServiceNotification
133240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    return false;
134240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }
135240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                IServiceNotification serviceNotificationCb = new IServiceNotification.Stub() {
136240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    public void onRegistration(String fqName, String name, boolean preexisting) {
13798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                        synchronized (mLock) {
13898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                            if (DBG) {
13998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                                Log.i(TAG, "IServiceNotification.onRegistration for: " + fqName
14098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                                        + ", " + name + " preexisting=" + preexisting);
14198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                            }
14298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                            if (!initSupplicantService() || !initSupplicantStaIface()) {
14398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                                Log.e(TAG, "initalizing ISupplicantIfaces failed.");
14498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                                supplicantServiceDiedHandler();
14598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                            } else {
14698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                                Log.i(TAG, "Completed initialization of ISupplicant interfaces.");
14798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                            }
148240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        }
149240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    }
150240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                };
151240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                /* TODO(b/33639391) : Use the new ISupplicant.registerForNotifications() once it
152240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                   exists */
15398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                if (!mIServiceManager.registerForNotifications(ISupplicant.kInterfaceName,
154240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        "", serviceNotificationCb)) {
155240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    Log.e(TAG, "Failed to register for notifications to "
156240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                            + ISupplicant.kInterfaceName);
15798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                    mIServiceManager = null; // Will need to register a new ServiceNotification
158240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    return false;
159240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }
160240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            } catch (RemoteException e) {
161240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "Exception while trying to register a listener for ISupplicant service: "
162240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        + e);
16398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                supplicantServiceDiedHandler();
164240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
165240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            return true;
166240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
167240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
168240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
16998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private boolean initSupplicantService() {
170240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        synchronized (mLock) {
171240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            try {
17298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                mISupplicant = getSupplicantMockable();
173240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            } catch (RemoteException e) {
174240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "ISupplicant.getService exception: " + e);
175240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                return false;
176240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
17798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            if (mISupplicant == null) {
178240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "Got null ISupplicant service. Stopping supplicant HIDL startup");
179240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                return false;
180240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
181240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
182240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        return true;
183240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
184240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
18598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private boolean initSupplicantStaIface() {
186240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        synchronized (mLock) {
187240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            /** List all supplicant Ifaces */
188240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            final ArrayList<ISupplicant.IfaceInfo> supplicantIfaces = new ArrayList<>();
189240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            try {
19098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                mISupplicant.listInterfaces((SupplicantStatus status,
191240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        ArrayList<ISupplicant.IfaceInfo> ifaces) -> {
192240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    if (status.code != SupplicantStatusCode.SUCCESS) {
193240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        Log.e(TAG, "Getting Supplicant Interfaces failed: " + status.code);
194240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        return;
195240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    }
196240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    supplicantIfaces.addAll(ifaces);
197240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                });
198240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            } catch (RemoteException e) {
199240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "ISupplicant.listInterfaces exception: " + e);
20098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                return false;
201240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
202240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            if (supplicantIfaces.size() == 0) {
203240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "Got zero HIDL supplicant ifaces. Stopping supplicant HIDL startup.");
20498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                return false;
205240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
206240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            Mutable<ISupplicantIface> supplicantIface = new Mutable<>();
20703fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius            Mutable<String> ifaceName = new Mutable<>();
208240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            for (ISupplicant.IfaceInfo ifaceInfo : supplicantIfaces) {
20998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                if (ifaceInfo.type == IfaceType.STA) {
210240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    try {
21198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                        mISupplicant.getInterface(ifaceInfo,
212240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                (SupplicantStatus status, ISupplicantIface iface) -> {
213240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                if (status.code != SupplicantStatusCode.SUCCESS) {
214240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                    Log.e(TAG, "Failed to get ISupplicantIface " + status.code);
215240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                    return;
216240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                }
217240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                supplicantIface.value = iface;
218240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                            });
219240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    } catch (RemoteException e) {
220240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        Log.e(TAG, "ISupplicant.getInterface exception: " + e);
22198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                        return false;
222240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    }
22303fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius                    ifaceName.value = ifaceInfo.name;
224240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    break;
225240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }
226240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
22798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            if (supplicantIface.value == null) {
22898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                Log.e(TAG, "initSupplicantStaIface got null iface");
229240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                return false;
230240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
23198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicantStaIface = getStaIfaceMockable(supplicantIface.value);
23203fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius            mIfaceName = ifaceName.value;
233c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            if (!registerCallback(new SupplicantStaIfaceHalCallback())) {
234c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                return false;
235c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            }
236240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            return true;
237240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
238240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
239240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
24098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private void supplicantServiceDiedHandler() {
241240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        synchronized (mLock) {
24298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicant = null;
24398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicantStaIface = null;
2445317e7c11c99d5cc8417c65cc73cf548f8f52b87Roshan Pius            mWifiMonitor.broadcastSupplicantDisconnectionEvent(mIfaceName);
245240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
246240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
247240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
24898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    /**
24998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     * Signals whether Initialization completed successfully. Only necessary for testing, is not
25098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     * needed to guard calls etc.
25198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     */
25298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    public boolean isInitializationComplete() {
25398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne        return mISupplicantStaIface != null;
2548c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius    }
2558c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius
2568c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius    /**
25798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     * Wrapper functions to access static HAL methods, created to be mockable in unit tests
2588c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius     */
25998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    protected IServiceManager getServiceManagerMockable() throws RemoteException {
26098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne        return IServiceManager.getService(SERVICE_MANAGER_NAME);
26198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    }
26298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne
26398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    protected ISupplicant getSupplicantMockable() throws RemoteException {
26498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne        return ISupplicant.getService();
26598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    }
26698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne
26798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    protected ISupplicantStaIface getStaIfaceMockable(ISupplicantIface iface) {
26898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne        return ISupplicantStaIface.asInterface(iface.asBinder());
2698c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius    }
2708c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius
27196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
2727c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * Add a network configuration to wpa_supplicant.
273d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
27466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     * @param config Config corresponding to the network.
27566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     * @return SupplicantStaNetwork of the added network in wpa_supplicant.
27666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     */
277d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    private SupplicantStaNetworkHal addNetwork(WifiConfiguration config) {
27866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        logi("addSupplicantStaNetwork via HIDL");
27966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        if (config == null) {
28066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Cannot add NULL network!");
28166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return null;
28266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
28366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        SupplicantStaNetworkHal network = addNetwork();
28466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        if (network == null) {
28566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Failed to add a network!");
28666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return null;
28766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
288f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius        if (!network.saveWifiConfiguration(config)) {
28966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Failed to save variables for: " + config.configKey());
290f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius            if (!removeAllNetworks()) {
291f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius                loge("Failed to remove all networks on failure.");
292f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius            }
29366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return null;
29466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
295f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius        return network;
29666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
29766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
29866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    /**
2997c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * Add the provided network configuration to wpa_supplicant and initiate connection to it.
3007c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * This method does the following:
3017c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 1. Triggers disconnect command to wpa_supplicant (if |shouldDisconnect| is true).
3027c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 2. Remove any existing network in wpa_supplicant.
3037c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 3. Add a new network to wpa_supplicant.
3047c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 4. Save the provided configuration to wpa_supplicant.
3057c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 5. Select the new network in wpa_supplicant.
306d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
3077c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @param config WifiConfiguration parameters for the provided network.
3087c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @param shouldDisconnect whether to trigger a disconnection or not.
3097c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @return {@code true} if it succeeds, {@code false} otherwise
31066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     */
311d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean connectToNetwork(WifiConfiguration config, boolean shouldDisconnect) {
3127c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        mFrameworkNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
3137c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        mCurrentNetwork = null;
314d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        logd("connectToNetwork " + config.configKey()
31566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                + " (shouldDisconnect " + shouldDisconnect + ")");
31666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        if (shouldDisconnect && !disconnect()) {
31766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Failed to trigger disconnect");
31866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return false;
31966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
32066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        if (!removeAllNetworks()) {
32166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Failed to remove existing networks");
32266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return false;
32366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
3247c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        mCurrentNetwork = addNetwork(config);
3257c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (mCurrentNetwork == null) {
326d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius            loge("Failed to add/save network configuration: " + config.configKey());
32766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return false;
32866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
3297c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (!mCurrentNetwork.select()) {
330d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius            loge("Failed to select network configuration: " + config.configKey());
33166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return false;
33266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
3337c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        mFrameworkNetworkId = config.networkId;
3347c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        return true;
3357c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    }
3367c0ec884188660f72977c8a80366049705c48ffaRoshan Pius
3377c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    /**
3387c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * Initiates roaming to the already configured network in wpa_supplicant. If the network
3397c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * configuration provided does not match the already configured network, then this triggers
3407c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * a new connection attempt (instead of roam).
3417c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 1. First check if we're attempting to connect to the same network as we currently have
3427c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * configured.
3437c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 2. Set the new bssid for the network in wpa_supplicant.
3447c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 3. Trigger reassociate command to wpa_supplicant.
3457c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     *
3467c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @param config WifiConfiguration parameters for the provided network.
3477c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @return {@code true} if it succeeds, {@code false} otherwise
3487c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     */
3497c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    public boolean roamToNetwork(WifiConfiguration config) {
3507c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (mFrameworkNetworkId != config.networkId || mCurrentNetwork == null) {
3517c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            Log.w(TAG, "Cannot roam to a different network, initiate new connection. "
3527c0ec884188660f72977c8a80366049705c48ffaRoshan Pius                    + "Current network ID: " + mFrameworkNetworkId);
3537c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            return connectToNetwork(config, false);
3547c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        }
3557c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        String bssid = config.getNetworkSelectionStatus().getNetworkSelectionBSSID();
3567c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        logd("roamToNetwork" + config.configKey() + " (bssid " + bssid + ")");
3577c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (!mCurrentNetwork.setBssid(bssid)) {
3587c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            loge("Failed to set new bssid on network: " + config.configKey());
3597c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            return false;
3607c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        }
3617c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (!reassociate()) {
3627c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            loge("Failed to trigger reassociate");
3637c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            return false;
3647c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        }
36566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        return true;
36666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
36766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
36866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    /**
369f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * Load all the configured networks from wpa_supplicant.
370f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     *
371f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @param configs       Map of configuration key to configuration objects corresponding to all
372f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     *                      the networks.
373f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @param networkExtras Map of extra configuration parameters stored in wpa_supplicant.conf
374f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @return true if succeeds, false otherwise.
375f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     */
376f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    public boolean loadNetworks(Map<String, WifiConfiguration> configs,
377f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                                SparseArray<Map<String, String>> networkExtras) {
378f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        List<Integer> networkIds = listNetworks();
379f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        if (networkIds == null) {
380f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            Log.e(TAG, "Failed to list networks");
381f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            return false;
382f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        }
383f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        for (Integer networkId : networkIds) {
384f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            SupplicantStaNetworkHal network = getNetwork(networkId);
385f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            if (network == null) {
386f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                Log.e(TAG, "Failed to get network with ID: " + networkId);
387f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                return false;
388f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            }
389f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            WifiConfiguration config = new WifiConfiguration();
390f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            Map<String, String> networkExtra = new HashMap<>();
391f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            if (!network.loadWifiConfiguration(config, networkExtra)) {
392f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                Log.e(TAG, "Failed to load wifi configuration for network with ID: " + networkId);
393f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                return false;
394f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            }
395f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            // Set the default IP assignments.
396f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            config.setIpAssignment(IpConfiguration.IpAssignment.DHCP);
397f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            config.setProxySettings(IpConfiguration.ProxySettings.NONE);
398f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius
399f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            networkExtras.put(networkId, networkExtra);
400f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            String configKey = networkExtra.get(SupplicantStaNetworkHal.ID_STRING_KEY_CONFIG_KEY);
401f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            final WifiConfiguration duplicateConfig = configs.put(configKey, config);
402f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            if (duplicateConfig != null) {
403f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                // The network is already known. Overwrite the duplicate entry.
404f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                Log.i(TAG, "Replacing duplicate network: " + duplicateConfig.networkId);
405f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                removeNetwork(duplicateConfig.networkId);
406f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                networkExtras.remove(duplicateConfig.networkId);
407f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            }
408f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        }
409f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        return true;
410f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    }
411f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius
412f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    /**
41366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     * Remove all networks from supplicant
41466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     */
41566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    public boolean removeAllNetworks() {
41666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        synchronized (mLock) {
41766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            ArrayList<Integer> networks = listNetworks();
41866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            if (networks == null) {
41966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                Log.e(TAG, "removeAllNetworks failed, got null networks");
42066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                return false;
42166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            }
42266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            for (int id : networks) {
42366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                if (!removeNetwork(id)) {
42466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                    Log.e(TAG, "removeAllNetworks failed to remove network: " + id);
42566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                    return false;
42666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                }
42766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            }
42866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
42966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        return true;
43066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
43166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
43266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    /**
4330a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * Set the currently configured network's bssid.
4340a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     *
4350a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * @param bssidStr Bssid to set in the form of "XX:XX:XX:XX:XX:XX"
4360a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * @return true if succeeds, false otherwise.
4370a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     */
4380a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    public boolean setCurrentNetworkBssid(String bssidStr) {
4390a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius        if (mCurrentNetwork == null) return false;
4400a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius        return mCurrentNetwork.setBssid(bssidStr);
4410a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    }
4420a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius
4430a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    /**
4440a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * Get the currently configured network's WPS NFC token.
4450a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     *
4460a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * @return Hex string corresponding to the WPS NFC token.
4470a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     */
4480a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    public String getCurrentNetworkWpsNfcConfigurationToken() {
4490a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius        if (mCurrentNetwork == null) return null;
4500a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius        return mCurrentNetwork.getWpsNfcConfigurationToken();
4510a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    }
4520a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius
4530a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    /**
4548aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap identity response for the currently configured network.
4558aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
4568aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @param identityStr String to send.
4578aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
4588aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
4598aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapIdentityResponse(String identityStr) {
4608aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
4618aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapIdentityResponse(identityStr);
4628aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
4638aad61408adef866a177857b79a979cf77a0a662Roshan Pius
4648aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
4658aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap sim gsm auth response for the currently configured network.
4668aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
4678aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @param paramsStr String to send.
4688aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
4698aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
4708aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapSimGsmAuthResponse(String paramsStr) {
4718aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
4728aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapSimGsmAuthResponse(paramsStr);
4738aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
4748aad61408adef866a177857b79a979cf77a0a662Roshan Pius
4758aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
4768aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap sim gsm auth failure for the currently configured network.
4778aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
4788aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
4798aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
4808aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapSimGsmAuthFailure() {
4818aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
4828aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapSimGsmAuthFailure();
4838aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
4848aad61408adef866a177857b79a979cf77a0a662Roshan Pius
4858aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
4868aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap sim umts auth response for the currently configured network.
4878aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
4888aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @param paramsStr String to send.
4898aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
4908aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
4918aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapSimUmtsAuthResponse(String paramsStr) {
4928aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
4938aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapSimUmtsAuthResponse(paramsStr);
4948aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
4958aad61408adef866a177857b79a979cf77a0a662Roshan Pius
4968aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
4978aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap sim umts auts response for the currently configured network.
4988aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
4998aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @param paramsStr String to send.
5008aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
5018aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
5028aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapSimUmtsAutsResponse(String paramsStr) {
5038aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
5048aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapSimUmtsAutsResponse(paramsStr);
5058aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
5068aad61408adef866a177857b79a979cf77a0a662Roshan Pius
5078aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
5088aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap sim umts auth failure for the currently configured network.
5098aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
5108aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
5118aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
5128aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapSimUmtsAuthFailure() {
5138aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
5148aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapSimUmtsAuthFailure();
5158aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
5168aad61408adef866a177857b79a979cf77a0a662Roshan Pius
5178aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
518d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Adds a new network.
519d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
52096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * @return The ISupplicantNetwork object for the new network, or null if the call fails
52196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
52296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private SupplicantStaNetworkHal addNetwork() {
52396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
52496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "addNetwork";
52596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
5263aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            Mutable<ISupplicantNetwork> newNetwork = new Mutable<>();
52796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
52896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                mISupplicantStaIface.addNetwork((SupplicantStatus status,
52996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        ISupplicantNetwork network) -> {
5303aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius                    if (checkStatusAndLogFailure(status, methodStr)) {
53196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        newNetwork.value = network;
53296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                    }
53396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                });
53496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
535b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
53696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
5373aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            if (newNetwork.value != null) {
538c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius                return getStaNetworkMockable(
539c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius                        ISupplicantStaNetwork.asInterface(newNetwork.value.asBinder()));
54096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } else {
54196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return null;
54296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
54396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
54496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
545d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
54696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
54796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Remove network from supplicant with network Id
548d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
549d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
55096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
55196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean removeNetwork(int id) {
55296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
55396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "removeNetwork";
55496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
55596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
55696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.removeNetwork(id);
55796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
55896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
559b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
56096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
56196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
56296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
56396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
564d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
56596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
566f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * Use this to mock the creation of SupplicantStaNetworkHal instance.
567f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     *
568f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @param iSupplicantStaNetwork ISupplicantStaNetwork instance retrieved from HIDL.
569f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @return The ISupplicantNetwork object for the given SupplicantNetworkId int, returns null if
570f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * the call fails
571f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     */
572f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    protected SupplicantStaNetworkHal getStaNetworkMockable(
573c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius            ISupplicantStaNetwork iSupplicantStaNetwork) {
57403fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius        return new SupplicantStaNetworkHal(
57503fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius                iSupplicantStaNetwork, mIfaceName, mContext, mWifiMonitor);
576f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    }
577f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius
578f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    /**
57996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * @return The ISupplicantNetwork object for the given SupplicantNetworkId int, returns null if
58096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * the call fails
58196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
58296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private SupplicantStaNetworkHal getNetwork(int id) {
58396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
58496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "getNetwork";
5853aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            Mutable<ISupplicantNetwork> gotNetwork = new Mutable<>();
58696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
58796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
58896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                mISupplicantStaIface.getNetwork(id, (SupplicantStatus status,
58996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        ISupplicantNetwork network) -> {
5903aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius                    if (checkStatusAndLogFailure(status, methodStr)) {
59196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        gotNetwork.value = network;
59296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                    }
59396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                });
59496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
595b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
59696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
5973aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            if (gotNetwork.value != null) {
598c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius                return getStaNetworkMockable(
599c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius                        ISupplicantStaNetwork.asInterface(gotNetwork.value.asBinder()));
60096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } else {
60196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return null;
60296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
60396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
60496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
60596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
606c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    /** See ISupplicantStaNetwork.hal for documentation */
607c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    private boolean registerCallback(ISupplicantStaIfaceCallback callback) {
608c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        synchronized (mLock) {
609c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            final String methodStr = "registerCallback";
610c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
611c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            try {
612c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                SupplicantStatus status =  mISupplicantStaIface.registerCallback(callback);
613c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                return checkStatusAndLogFailure(status, methodStr);
614c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            } catch (RemoteException e) {
615b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
616c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                return false;
617c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            }
618c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
619c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    }
620c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
62196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
62296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * @return a list of SupplicantNetworkID ints for all networks controlled by supplicant, returns
62396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * null if the call fails
62496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
62596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private java.util.ArrayList<Integer> listNetworks() {
62696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
62796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "listNetworks";
6283aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            Mutable<ArrayList<Integer>> networkIdList = new Mutable<>();
62996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
63096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
63196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                mISupplicantStaIface.listNetworks((SupplicantStatus status,
63296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        java.util.ArrayList<Integer> networkIds) -> {
6333aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius                    if (checkStatusAndLogFailure(status, methodStr)) {
63496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        networkIdList.value = networkIds;
63596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                    }
63696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                });
63796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
638b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
63996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
6403aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            return networkIdList.value;
64196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
64296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
643d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
6445f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
6455f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS device name.
6465f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
6475f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param name String to be set.
6485f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
6495f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
6505f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsDeviceName(String name) {
6517651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
6527651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsDeviceName";
6537651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
6547651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
6557651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsDeviceName(name);
6567651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
6577651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
658b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
6597651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
6607651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
6617651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
6627651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
6637651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
6645f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
6655f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS device type.
6665f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
6675f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param typeStr Type specified as a string. Used format: <categ>-<OUI>-<subcateg>
6685f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
6695f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
6705f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsDeviceType(String typeStr) {
6715f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        Matcher match = WPS_DEVICE_TYPE_PATTERN.matcher(typeStr);
6725f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        if (!match.find() || match.groupCount() != 3) {
6735f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            Log.e(TAG, "Malformed WPS device type " + typeStr);
6745f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            return false;
6755f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        }
6765f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        short categ = Short.parseShort(match.group(1));
6775f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byte[] oui = NativeUtil.hexStringToByteArray(match.group(2));
6785f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        short subCateg = Short.parseShort(match.group(3));
6795f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
6805f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byte[] bytes = new byte[8];
6815f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        ByteBuffer byteBuffer = ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN);
6825f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byteBuffer.putShort(categ);
6835f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byteBuffer.put(oui);
6845f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byteBuffer.putShort(subCateg);
6855f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return setWpsDeviceType(bytes);
6865f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
6875f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
6887651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private boolean setWpsDeviceType(byte[/* 8 */] type) {
6897651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
6907651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsDeviceType";
6917651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
6927651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
6937651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsDeviceType(type);
6947651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
6957651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
696b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
6977651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
6987651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
6997651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
7007651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
7017651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
7025f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
7035f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS manufacturer.
7045f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
7055f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param manufacturer String to be set.
7065f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
7075f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
7085f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsManufacturer(String manufacturer) {
7097651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
7107651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsManufacturer";
7117651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
7127651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
7137651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsManufacturer(manufacturer);
7147651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
7157651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
716b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
7177651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
7187651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
7197651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
7207651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
7217651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
7225f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
7235f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS model name.
7245f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
7255f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param modelName String to be set.
7265f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
7275f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
7285f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsModelName(String modelName) {
7297651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
7307651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsModelName";
7317651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
7327651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
7337651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsModelName(modelName);
7347651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
7357651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
736b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
7377651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
7387651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
7397651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
7407651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
7417651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
7425f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
7435f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS model number.
7445f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
7455f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param modelNumber String to be set.
7465f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
7475f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
7485f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsModelNumber(String modelNumber) {
7497651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
7507651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsModelNumber";
7517651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
7527651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
7537651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsModelNumber(modelNumber);
7547651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
7557651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
756b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
7577651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
7587651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
7597651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
7607651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
7617651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
7625f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
7635f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS serial number.
7645f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
7655f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param serialNumber String to be set.
7665f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
7675f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
7685f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsSerialNumber(String serialNumber) {
7697651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
7707651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsSerialNumber";
7717651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
7727651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
7737651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsSerialNumber(serialNumber);
7747651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
7757651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
776b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
7777651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
7787651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
7797651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
7807651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
7817651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
7825f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
7835f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS config methods
7845f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
7855f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param configMethodsStr List of config methods.
7865f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
7875f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
7885f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsConfigMethods(String configMethodsStr) {
7895f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        short configMethodsMask = 0;
7905f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        String[] configMethodsStrArr = configMethodsStr.split("\\s+");
7915f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        for (int i = 0; i < configMethodsStrArr.length; i++) {
7925f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            configMethodsMask |= stringToWpsConfigMethod(configMethodsStrArr[i]);
7935f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        }
7945f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return setWpsConfigMethods(configMethodsMask);
7955f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
7965f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
7977651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private boolean setWpsConfigMethods(short configMethods) {
7987651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
7997651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsConfigMethods";
8007651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
8017651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
8027651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsConfigMethods(configMethods);
8037651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
8047651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
805b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
8067651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
8077651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
8087651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
8097651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
8107651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
811d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
812d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Trigger a reassociation even if the iface is currently connected.
813d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
814d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
815d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
816d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean reassociate() {
81796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
81896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "reassociate";
81996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
82096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
82196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.reassociate();
82296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
82396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
824b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
82596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
82696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
82796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
82896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
829d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
830d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
831d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Trigger a reconnection if the iface is disconnected.
832d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
833d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
834d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
835d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean reconnect() {
83696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
83796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "reconnect";
83896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
83996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
84096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.reconnect();
84196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
84296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
843b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
84496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
84596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
84696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
84796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
848d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
849d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
850d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Trigger a disconnection from the currently connected network.
851d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
852d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
853d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
854d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean disconnect() {
85596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
85696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "disconnect";
85796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
85896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
85996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.disconnect();
86096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
86196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
862b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
86396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
86496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
86596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
86696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
867d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
868d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
869d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Enable or disable power save mode.
870d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
871d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param enable true to enable, false to disable.
872d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
873d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
874d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setPowerSave(boolean enable) {
87596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
87696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setPowerSave";
87796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
87896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
87996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.setPowerSave(enable);
88096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
88196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
882b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
88396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
88496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
88596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
88696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
887d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
888d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
889d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Initiate TDLS discover with the specified AP.
890d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
891d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param macAddress MAC Address of the AP.
892d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
893d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
894d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateTdlsDiscover(String macAddress) {
895d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateTdlsDiscover(NativeUtil.macAddressToByteArray(macAddress));
896d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
897b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
89896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateTdlsDiscover(byte[/* 6 */] macAddress) {
89996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
90096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateTdlsDiscover";
90196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
90296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
90396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateTdlsDiscover(macAddress);
90496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
90596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
906b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
90796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
90896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
90996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
91096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
911d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
912d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
913d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Initiate TDLS setup with the specified AP.
914d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
915d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param macAddress MAC Address of the AP.
916d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
917d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
918d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateTdlsSetup(String macAddress) {
919d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateTdlsSetup(NativeUtil.macAddressToByteArray(macAddress));
920d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
921b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
92296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateTdlsSetup(byte[/* 6 */] macAddress) {
92396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
92496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateTdlsSetup";
92596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
92696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
92796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateTdlsSetup(macAddress);
92896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
92996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
930b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
93196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
93296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
93396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
93496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
935d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
936d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
937d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Initiate TDLS teardown with the specified AP.
938d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param macAddress MAC Address of the AP.
939d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
940d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
941d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateTdlsTeardown(String macAddress) {
942d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateTdlsTeardown(NativeUtil.macAddressToByteArray(macAddress));
943d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
944d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
945b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
94696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateTdlsTeardown(byte[/* 6 */] macAddress) {
94796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
94896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateTdlsTeardown";
94996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
95096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
95196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateTdlsTeardown(macAddress);
95296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
95396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
954b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
95596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
95696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
95796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
95896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
959d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
960d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
961d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Request the specified ANQP elements |elements| from the specified AP |bssid|.
962d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
963d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param bssid BSSID of the AP
964d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param infoElements ANQP elements to be queried. Refer to ISupplicantStaIface.AnqpInfoId.
965d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param hs20SubTypes HS subtypes to be queried. Refer to ISupplicantStaIface.Hs20AnqpSubTypes.
966d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
967d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
968d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateAnqpQuery(String bssid, ArrayList<Short> infoElements,
969d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius                                     ArrayList<Integer> hs20SubTypes) {
970d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateAnqpQuery(
971d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius                NativeUtil.macAddressToByteArray(bssid), infoElements, hs20SubTypes);
972d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
973d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
974b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
97596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateAnqpQuery(byte[/* 6 */] macAddress,
97696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            java.util.ArrayList<Short> infoElements, java.util.ArrayList<Integer> subTypes) {
97796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
97896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateAnqpQuery";
97996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
98096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
98196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateAnqpQuery(macAddress,
98296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        infoElements, subTypes);
98396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
98496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
985b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
98696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
98796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
98896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
98996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
990d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
991d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
992d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Request the specified ANQP ICON from the specified AP |bssid|.
993d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
994d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param bssid BSSID of the AP
995d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param fileName Name of the file to request.
996d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
997d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
998d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateHs20IconQuery(String bssid, String fileName) {
999d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateHs20IconQuery(NativeUtil.macAddressToByteArray(bssid), fileName);
1000d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
1001d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1002b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
100396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateHs20IconQuery(byte[/* 6 */] macAddress, String fileName) {
100496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
100596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateHs20IconQuery";
100696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
100796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
100896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateHs20IconQuery(macAddress,
100996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        fileName);
101096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
101196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1012b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
101396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
101496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
101596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
101696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1017d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
101896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
101996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Makes a callback to HIDL to getMacAddress from supplicant
1020d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
102196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * @return string containing the MAC address, or null on a failed call
102296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
1023d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public String getMacAddress() {
102496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
102596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "getMacAddress";
102696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
102796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            Mutable<String> gotMac = new Mutable<>();
102896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
102996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                mISupplicantStaIface.getMacAddress((SupplicantStatus status,
103096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        byte[/* 6 */] macAddr) -> {
10313aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius                    if (checkStatusAndLogFailure(status, methodStr)) {
1032d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius                        gotMac.value = NativeUtil.macAddressFromByteArray(macAddr);
103396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                    }
103496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                });
103596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1036b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
103796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
10383aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            return gotMac.value;
103996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
104096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1041d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1042d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1043d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Start using the added RX filters.
1044d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1045d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1046d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1047d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean startRxFilter() {
104896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
104996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "startRxFilter";
105096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
105196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
105296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.startRxFilter();
105396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
105496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1055b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
105696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
105796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
105896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
105996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1060d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1061d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1062d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Stop using the added RX filters.
1063d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1064d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1065d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1066d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean stopRxFilter() {
106796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
106896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "stopRxFilter";
106996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
107096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
107196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.stopRxFilter();
107296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
107396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1074b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
107596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
107696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
107796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
107896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1079d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1080d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte RX_FILTER_TYPE_V4_MULTICAST =
1081d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius            ISupplicantStaIface.RxFilterType.V6_MULTICAST;
1082d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte RX_FILTER_TYPE_V6_MULTICAST =
1083d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius            ISupplicantStaIface.RxFilterType.V6_MULTICAST;
1084d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1085d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Add an RX filter.
1086d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1087d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param type one of {@link #RX_FILTER_TYPE_V4_MULTICAST} or
1088d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *        {@link #RX_FILTER_TYPE_V6_MULTICAST} values.
1089d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1090d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1091f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius    public boolean addRxFilter(byte type) {
109296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
109396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "addRxFilter";
109496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
109596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
109696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.addRxFilter(type);
109796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
109896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1099b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
110096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
110196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
110296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
110396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1104d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1105d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1106d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Remove an RX filter.
1107d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1108d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param type one of {@link #RX_FILTER_TYPE_V4_MULTICAST} or
1109d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *        {@link #RX_FILTER_TYPE_V6_MULTICAST} values.
1110d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1111d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1112f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius    public boolean removeRxFilter(byte type) {
111396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
111496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "removeRxFilter";
111596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
111696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
111796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.removeRxFilter(type);
111896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
111996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1120b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
112196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
112296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
112396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
112496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1125d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1126d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte BT_COEX_MODE_ENABLED = ISupplicantStaIface.BtCoexistenceMode.ENABLED;
1127d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte BT_COEX_MODE_DISABLED = ISupplicantStaIface.BtCoexistenceMode.DISABLED;
1128d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte BT_COEX_MODE_SENSE = ISupplicantStaIface.BtCoexistenceMode.SENSE;
1129d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1130d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Set Bt co existense mode.
1131d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1132d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param mode one of the above {@link #BT_COEX_MODE_ENABLED}, {@link #BT_COEX_MODE_DISABLED}
1133d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *             or {@link #BT_COEX_MODE_SENSE} values.
1134d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1135d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1136d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setBtCoexistenceMode(byte mode) {
113796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
113896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setBtCoexistenceMode";
113996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
114096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
114196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.setBtCoexistenceMode(mode);
114296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
114396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1144b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
114596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
114696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
114796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
114896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1149d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1150d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /** Enable or disable BT coexistence mode.
1151d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1152d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param enable true to enable, false to disable.
1153d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1154d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1155d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setBtCoexistenceScanModeEnabled(boolean enable) {
115696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
115796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setBtCoexistenceScanModeEnabled";
115896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
115996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
116096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status =
116196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        mISupplicantStaIface.setBtCoexistenceScanModeEnabled(enable);
116296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
116396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1164b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
116596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
116696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
116796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
116896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1169d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1170d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1171d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Enable or disable suspend mode optimizations.
1172d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1173d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param enable true to enable, false otherwise.
11745f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
1175d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1176d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setSuspendModeEnabled(boolean enable) {
117796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
117896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setSuspendModeEnabled";
117996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
118096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
118196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.setSuspendModeEnabled(enable);
118296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
118396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1184b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
118596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
118696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
118796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
118896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1189d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1190d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1191d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Set country code.
1192d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1193d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param codeStr 2 byte ASCII string. For ex: US, CA.
1194d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1195d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1196d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setCountryCode(String codeStr) {
1197d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return setCountryCode(NativeUtil.stringToByteArray(codeStr));
1198d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
1199d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1200b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
120196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean setCountryCode(byte[/* 2 */] code) {
120296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
120396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setCountryCode";
120496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
120596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
120696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.setCountryCode(code);
120796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
120896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1209b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
121096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
121196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
121296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
121396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
121496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
12155f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
12165f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Start WPS pin registrar operation with the specified peer and pin.
12175f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
12185f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param bssidStr BSSID of the peer.
12195f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param pin Pin to be used.
12205f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
12215f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
12225f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean startWpsRegistrar(String bssidStr, String pin) {
12235f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return startWpsRegistrar(NativeUtil.macAddressToByteArray(bssidStr), pin);
12245f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
12255f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
12267651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
12277651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private boolean startWpsRegistrar(byte[/* 6 */] bssid, String pin) {
12287651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
12297651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "startWpsRegistrar";
12307651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
12317651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
12327651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.startWpsRegistrar(bssid, pin);
12337651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
12347651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1235b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
12367651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
12377651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
12387651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
12397651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
12407651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
12415f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
12425f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Start WPS pin display operation with the specified peer.
12435f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
12445f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param bssidStr BSSID of the peer.
12455f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
12465f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
12475f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean startWpsPbc(String bssidStr) {
12485f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return startWpsPbc(NativeUtil.macAddressToByteArray(bssidStr));
12495f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
12505f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
12517651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
12527651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private boolean startWpsPbc(byte[/* 6 */] bssid) {
12537651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
12547651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "startWpsPbc";
12557651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
12567651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
12577651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.startWpsPbc(bssid);
12587651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
12597651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1260b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
12617651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
12627651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
12637651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
12647651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
12657651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
12665f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
12675f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Start WPS pin keypad operation with the specified pin.
12685f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
12695f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param pin Pin to be used.
12705f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
12715f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
12725f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean startWpsPinKeypad(String pin) {
12737651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
12747651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "startWpsPinKeypad";
12757651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
12767651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
12777651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.startWpsPinKeypad(pin);
12787651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
12797651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1280b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
12817651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
12827651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
12837651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
12847651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
12857651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
12865f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
12875f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Start WPS pin display operation with the specified peer.
12885f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
12895f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param bssidStr BSSID of the peer.
12905f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return new pin generated on success, null otherwise.
12915f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
12925f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public String startWpsPinDisplay(String bssidStr) {
12935f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return startWpsPinDisplay(NativeUtil.macAddressToByteArray(bssidStr));
12945f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
12955f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
12967651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
12977651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private String startWpsPinDisplay(byte[/* 6 */] bssid) {
12987651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
12997651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "startWpsPinDisplay";
13007651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
13017651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final Mutable<String> gotPin = new Mutable<>();
13027651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
13037651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                mISupplicantStaIface.startWpsPinDisplay(bssid,
13047651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                        (SupplicantStatus status, String pin) -> {
13057651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                            if (checkStatusAndLogFailure(status, methodStr)) {
13067651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                                gotPin.value = pin;
13077651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                            }
13087651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                        });
13097651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1310b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
13117651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
13127651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            return gotPin.value;
13137651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
13147651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
13157651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
13165f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
13175f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Cancels any ongoing WPS requests.
13185f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
13195f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
13205f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
13215f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean cancelWps() {
13227651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
13237651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "cancelWps";
13247651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
13257651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
13267651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.cancelWps();
13277651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
13287651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1329b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
13307651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
13317651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
13327651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
13337651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
13347651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
13355f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
13365f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Sets whether to use external sim for SIM/USIM processing.
13375f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
13385f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param useExternalSim true to enable, false otherwise.
13395f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
13405f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
13415f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setExternalSim(boolean useExternalSim) {
13427651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
13437651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setExternalSim";
13447651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
13457651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
13467651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setExternalSim(useExternalSim);
13477651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
13487651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1349b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
13507651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
13517651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
13527651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
13537651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
13547651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
1355cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_EXCESSIVE = ISupplicant.DebugLevel.EXCESSIVE;
1356cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_MSGDUMP = ISupplicant.DebugLevel.MSGDUMP;
1357cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_DEBUG = ISupplicant.DebugLevel.DEBUG;
1358cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_INFO = ISupplicant.DebugLevel.INFO;
1359cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_WARNING = ISupplicant.DebugLevel.WARNING;
1360cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_ERROR = ISupplicant.DebugLevel.ERROR;
1361cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /**
1362cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * Set the debug log level for wpa_supplicant
1363cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * @param level One of the above {@link #LOG_LEVEL_EXCESSIVE} - {@link #LOG_LEVEL_ERROR} value.
1364cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * @return true if request is sent successfully, false otherwise.
1365cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     */
1366cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public boolean setLogLevel(int level) {
1367cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        return setDebugParams(level, false, false);
1368cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1369cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
1370cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /** See ISupplicant.hal for documentation */
1371cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    private boolean setDebugParams(int level, boolean showTimestamp, boolean showKeys) {
1372cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        synchronized (mLock) {
1373cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            final String methodStr = "setDebugParams";
1374cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            if (!checkSupplicantAndLogFailure(methodStr)) return false;
1375cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            try {
1376cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                SupplicantStatus status =
1377cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                        mISupplicant.setDebugParams(level, showTimestamp, showKeys);
1378cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                return checkStatusAndLogFailure(status, methodStr);
1379cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            } catch (RemoteException e) {
1380b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
1381cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                return false;
1382cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            }
1383cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        }
1384cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1385cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
1386cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /**
1387cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * Set concurrency priority between P2P & STA operations.
1388cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     *
1389cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * @param isStaHigherPriority Set to true to prefer STA over P2P during concurrency operations,
1390cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     *                            false otherwise.
1391cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * @return true if request is sent successfully, false otherwise.
1392cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     */
1393cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public boolean setConcurrencyPriority(boolean isStaHigherPriority) {
1394cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        if (isStaHigherPriority) {
1395cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            return setConcurrencyPriority(IfaceType.STA);
1396cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        } else {
1397cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            return setConcurrencyPriority(IfaceType.P2P);
1398cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        }
1399cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1400cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
1401cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /** See ISupplicant.hal for documentation */
1402cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    private boolean setConcurrencyPriority(int type) {
1403cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        synchronized (mLock) {
1404cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            final String methodStr = "setConcurrencyPriority";
1405cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            if (!checkSupplicantAndLogFailure(methodStr)) return false;
1406cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            try {
1407cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                SupplicantStatus status = mISupplicant.setConcurrencyPriority(type);
1408cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                return checkStatusAndLogFailure(status, methodStr);
1409cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            } catch (RemoteException e) {
1410b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
1411cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                return false;
1412cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            }
1413cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        }
1414cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1415cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
1416cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /**
1417cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * Returns false if Supplicant is null, and logs failure to call methodStr
1418cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     */
1419cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    private boolean checkSupplicantAndLogFailure(final String methodStr) {
1420cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        if (mISupplicant == null) {
1421cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            Log.e(TAG, "Can't call " + methodStr + ", ISupplicant is null");
1422cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            return false;
1423cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        }
1424cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        return true;
1425cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1426cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
142796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
142896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Returns false if SupplicantStaIface is null, and logs failure to call methodStr
142996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
143096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean checkSupplicantStaIfaceAndLogFailure(final String methodStr) {
143196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        if (mISupplicantStaIface == null) {
143296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            Log.e(TAG, "Can't call " + methodStr + ", ISupplicantStaIface is null");
143396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            return false;
143496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
143596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        return true;
143696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
143796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
143896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
143996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Returns true if provided status code is SUCCESS, logs debug message and returns false
144096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * otherwise
144196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
144296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private static boolean checkStatusAndLogFailure(SupplicantStatus status,
144396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr) {
144496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        if (status.code != SupplicantStatusCode.SUCCESS) {
1445b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius            Log.e(TAG, "ISupplicantStaIface." + methodStr + " failed: "
1446b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                    + supplicantStatusCodeToString(status.code) + ", " + status.debugMessage);
144796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            return false;
1448b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius        } else {
1449b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius            if (DBG) Log.i(TAG, "ISupplicantStaIface." + methodStr + " succeeded");
1450b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius            return true;
145196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
1452b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius    }
1453b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius
1454b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius    private void handleRemoteException(RemoteException e, String methodStr) {
1455b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius        supplicantServiceDiedHandler();
1456b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius        Log.e(TAG, "ISupplicantStaIface." + methodStr + " failed with exception", e);
145796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
145896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
145996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
146096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Converts SupplicantStatus code values to strings for debug logging
146196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * TODO(b/34811152) Remove this, or make it more break resistance
146296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
146396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    public static String supplicantStatusCodeToString(int code) {
146496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        switch (code) {
146596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 0:
146696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "SUCCESS";
146796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 1:
146896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_UNKNOWN";
146996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 2:
147096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_ARGS_INVALID";
147196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 3:
147296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_INVALID";
147396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 4:
147496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_UNKNOWN";
147596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 5:
147696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_EXISTS";
147796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 6:
147896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_DISABLED";
147996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 7:
148096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_NOT_DISCONNECTED";
148196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 8:
148296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_NETWORK_INVALID";
148396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 9:
148496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_NETWORK_UNKNOWN";
148596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            default:
148696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "??? UNKNOWN_CODE";
148796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
148896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
148996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
14905f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
14915f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
14925f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Converts the Wps config method string to the equivalent enum value.
14935f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
14945f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    private static short stringToWpsConfigMethod(String configMethod) {
14955f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        switch (configMethod) {
14965f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "usba":
14975f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.USBA;
14985f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "ethernet":
14995f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.ETHERNET;
15005f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "label":
15015f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.LABEL;
15025f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "display":
15035f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.DISPLAY;
15045f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "int_nfc_token":
15055f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.INT_NFC_TOKEN;
15065f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "ext_nfc_token":
15075f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.EXT_NFC_TOKEN;
15085f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "nfc_interface":
15095f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.NFC_INTERFACE;
15105f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "push_button":
15115f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.PUSHBUTTON;
15125f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "keypad":
15135f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.KEYPAD;
15145f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "virtual_push_button":
15155f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.VIRT_PUSHBUTTON;
15165f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "physical_push_button":
15175f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.PHY_PUSHBUTTON;
15185f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "p2ps":
15195f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.P2PS;
15205f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "virtual_display":
15215f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.VIRT_DISPLAY;
15225f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "physical_display":
15235f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.PHY_DISPLAY;
15245f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            default:
15255f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                throw new IllegalArgumentException(
15265f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                        "Invalid WPS config method: " + configMethod);
15275f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        }
15285f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
15295f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
153082c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius    /**
153182c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius     * Converts the supplicant state received from HIDL to the equivalent framework state.
153282c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius     */
153382c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius    private static SupplicantState supplicantHidlStateToFrameworkState(int state) {
153482c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius        switch (state) {
153582c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.DISCONNECTED:
153682c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.DISCONNECTED;
153782c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.IFACE_DISABLED:
153882c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.INTERFACE_DISABLED;
153982c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.INACTIVE:
154082c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.INACTIVE;
154182c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.SCANNING:
154282c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.SCANNING;
154382c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.AUTHENTICATING:
154482c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.AUTHENTICATING;
154582c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.ASSOCIATING:
154682c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.ASSOCIATING;
154782c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.ASSOCIATED:
154882c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.ASSOCIATED;
154982c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.FOURWAY_HANDSHAKE:
155082c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.FOUR_WAY_HANDSHAKE;
155182c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.GROUP_HANDSHAKE:
155282c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.GROUP_HANDSHAKE;
155382c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.COMPLETED:
155482c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.COMPLETED;
155582c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            default:
155682c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                throw new IllegalArgumentException("Invalid state: " + state);
155782c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius        }
155882c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius    }
155982c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius
1560240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    private static class Mutable<E> {
1561240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        public E value;
1562240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
1563240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        Mutable() {
1564240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            value = null;
1565240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
1566240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
1567240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        Mutable(E value) {
1568240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            this.value = value;
1569240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
1570240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
157166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
1572c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    private class SupplicantStaIfaceHalCallback extends ISupplicantStaIfaceCallback.Stub {
15735a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        /**
15745a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * Parses the provided payload into an ANQP element.
15755a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         *
15765a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param infoID  Element type.
15775a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param payload Raw payload bytes.
15785a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @return AnqpElement instance on success, null on failure.
15795a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         */
15805a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        private ANQPElement parseAnqpElement(Constants.ANQPElementType infoID,
15815a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                                             ArrayList<Byte> payload) {
15825a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            try {
15835a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                return Constants.getANQPElementID(infoID) != null
15845a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        ? ANQPParser.parseElement(
15855a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        infoID, ByteBuffer.wrap(NativeUtil.byteArrayFromArrayList(payload)))
15865a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        : ANQPParser.parseHS20Element(
15875a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        infoID, ByteBuffer.wrap(NativeUtil.byteArrayFromArrayList(payload)));
15885a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            } catch (IOException | BufferUnderflowException e) {
15895a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                Log.e(TAG, "Failed parsing ANQP element payload: " + infoID, e);
15905a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                return null;
15915a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            }
15925a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        }
15935a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius
15945a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        /**
15955a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * Parse the ANQP element data and add to the provided elements map if successful.
15965a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         *
15975a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param elementsMap Map to add the parsed out element to.
15985a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param infoID  Element type.
15995a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param payload Raw payload bytes.
16005a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         */
16015a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        private void addAnqpElementToMap(Map<Constants.ANQPElementType, ANQPElement> elementsMap,
16025a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                                         Constants.ANQPElementType infoID,
16035a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                                         ArrayList<Byte> payload) {
16045a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            if (payload == null || payload.isEmpty()) return;
16055a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            ANQPElement element = parseAnqpElement(infoID, payload);
16065a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            if (element != null) {
16075a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                elementsMap.put(infoID, element);
16085a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            }
16095a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        }
16105a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius
16115a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        /**
16125a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * Helper utility to convert the bssid bytes to long.
16135a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         */
16145a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        private Long toLongBssid(byte[] bssidBytes) {
16155a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            try {
16165a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                return ByteBufferReader.readInteger(
16175a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        ByteBuffer.wrap(bssidBytes), ByteOrder.BIG_ENDIAN, bssidBytes.length);
16185a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            } catch (BufferUnderflowException | IllegalArgumentException e) {
16195a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                return 0L;
16205a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            }
16215a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        }
16225a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius
1623c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1624c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onNetworkAdded(int id) {
1625c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1626c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1627c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1628c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onNetworkRemoved(int id) {
1629c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1630c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1631c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1632c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onStateChanged(int newState, byte[/* 6 */] bssid, int id,
1633c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                                   ArrayList<Byte> ssid) {
163482c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            SupplicantState newSupplicantState = supplicantHidlStateToFrameworkState(newState);
163582c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            WifiSsid wifiSsid =
163682c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                    WifiSsid.createFromByteArray(NativeUtil.byteArrayFromArrayList(ssid));
163782c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            String bssidStr = NativeUtil.macAddressFromByteArray(bssid);
163882c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            mWifiMonitor.broadcastSupplicantStateChangeEvent(
163982c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                    mIfaceName, mFrameworkNetworkId, wifiSsid, bssidStr, newSupplicantState);
164082c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            if (newSupplicantState == SupplicantState.ASSOCIATED) {
164182c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                mWifiMonitor.broadcastAssociationSuccesfulEvent(mIfaceName, bssidStr);
164282c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            } else if (newSupplicantState == SupplicantState.COMPLETED) {
164382c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                mWifiMonitor.broadcastNetworkConnectionEvent(
164482c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                        mIfaceName, mFrameworkNetworkId, bssidStr);
164582c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            }
1646c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1647c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1648c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
16495a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        public void onAnqpQueryDone(byte[/* 6 */] bssid,
1650c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                                    ISupplicantStaIfaceCallback.AnqpData data,
1651c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                                    ISupplicantStaIfaceCallback.Hs20AnqpData hs20Data) {
16525a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            Map<Constants.ANQPElementType, ANQPElement> elementsMap = new HashMap<>();
16535a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, ANQPVenueName, data.venueName);
16545a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, ANQPRoamingConsortium, data.roamingConsortium);
16555a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, ANQPIPAddrAvailability, data.ipAddrTypeAvailability);
16565a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, ANQPNAIRealm, data.naiRealm);
16575a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, ANQP3GPPNetwork, data.anqp3gppCellularNetwork);
16585a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, ANQPDomName, data.domainName);
16595a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, HSFriendlyName, hs20Data.operatorFriendlyName);
16605a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, HSWANMetrics, hs20Data.wanMetrics);
16615a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, HSConnCapability, hs20Data.connectionCapability);
16625a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, HSOSUProviders, hs20Data.osuProvidersList);
16635a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            mWifiMonitor.broadcastAnqpDoneEvent(
16645a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                    mIfaceName, new AnqpEvent(toLongBssid(bssid), elementsMap));
1665c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1666c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1667c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
16685a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        public void onHs20IconQueryDone(byte[/* 6 */] bssid, String fileName,
1669c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                                        ArrayList<Byte> data) {
16705a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            mWifiMonitor.broadcastIconDoneEvent(
16715a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                    mIfaceName,
16725a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                    new IconEvent(toLongBssid(bssid), fileName, data.size(),
16735a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                            NativeUtil.byteArrayFromArrayList(data)));
1674c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1675c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1676c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
16775a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        public void onHs20SubscriptionRemediation(byte[/* 6 */] bssid, byte osuMethod, String url) {
16785a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            mWifiMonitor.broadcastWnmEvent(
16795a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                    mIfaceName, new WnmData(toLongBssid(bssid), url, osuMethod));
1680c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1681c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1682c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
16835a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        public void onHs20DeauthImminentNotice(byte[/* 6 */] bssid, int reasonCode,
16845a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                                               int reAuthDelayInSec, String url) {
16855a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            mWifiMonitor.broadcastWnmEvent(
16865a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                    mIfaceName,
16875a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                    new WnmData(toLongBssid(bssid), url, reasonCode == WnmData.ESS,
16885a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                            reAuthDelayInSec));
1689c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1690c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1691c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1692c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onDisconnected(byte[/* 6 */] bssid, boolean locallyGenerated, int reasonCode) {
1693bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius            mWifiMonitor.broadcastNetworkDisconnectionEvent(
1694bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius                    mIfaceName, locallyGenerated ? 1 : 0, reasonCode,
1695bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius                    NativeUtil.macAddressFromByteArray(bssid));
1696c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1697c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1698c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1699c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onAssociationRejected(byte[/* 6 */] bssid, int statusCode) {
1700bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius            // TODO(b/35464954): Need to figure out when to trigger
1701bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius            // |WifiMonitor.AUTHENTICATION_FAILURE_REASON_WRONG_PSWD|
1702bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius            mWifiMonitor.broadcastAssociationRejectionEvent(mIfaceName, statusCode,
1703bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius                    NativeUtil.macAddressFromByteArray(bssid));
1704c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1705c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1706c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1707c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onAuthenticationTimeout(byte[/* 6 */] bssid) {
1708bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius            mWifiMonitor.broadcastAuthenticationFailureEvent(
1709bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius                    mIfaceName, WifiMonitor.AUTHENTICATION_FAILURE_REASON_TIMEOUT);
1710c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1711c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1712c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1713c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onEapFailure() {
1714bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius            mWifiMonitor.broadcastAuthenticationFailureEvent(
1715bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius                    mIfaceName, WifiMonitor.AUTHENTICATION_FAILURE_REASON_EAP_FAILURE);
1716c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1717c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1718c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1719c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onWpsEventSuccess() {
1720bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius            mWifiMonitor.broadcastWpsSuccessEvent(mIfaceName);
1721c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1722c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1723c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1724c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onWpsEventFail(byte[/* 6 */] bssid, short configError, short errorInd) {
1725bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius            if (configError == WpsConfigError.MSG_TIMEOUT
1726bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius                    && errorInd == WpsErrorIndication.NO_ERROR) {
1727bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius                mWifiMonitor.broadcastWpsTimeoutEvent(mIfaceName);
1728bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius            } else {
1729bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius                mWifiMonitor.broadcastWpsFailEvent(mIfaceName, configError, errorInd);
1730bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius            }
1731c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1732c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1733c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1734c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onWpsEventPbcOverlap() {
1735bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius            mWifiMonitor.broadcastWpsOverlapEvent(mIfaceName);
1736c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1737c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1738c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1739c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onExtRadioWorkStart(int id) {
1740c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1741c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1742c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1743c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onExtRadioWorkTimeout(int id) {
1744c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1745c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    }
1746c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
174766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    private void logd(String s) {
174866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        Log.d(TAG, s);
174966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
175066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
175166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    private void logi(String s) {
175266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        Log.i(TAG, s);
175366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
175466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
175566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    private void loge(String s) {
175666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        Log.e(TAG, s);
175766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
1758240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne}
1759