SupplicantStaIfaceHal.java revision 5a1adfdef3025a595544b3d17e1d5d9afca7673b
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;
4366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhneimport android.net.wifi.WifiConfiguration;
44240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.os.RemoteException;
45240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.util.Log;
46f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Piusimport android.util.SparseArray;
4796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
485a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.AnqpEvent;
495a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.IconEvent;
505a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.WnmData;
515a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.anqp.ANQPElement;
525a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.anqp.ANQPParser;
535a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.anqp.Constants;
54d95fa596d07855b70ff18a50a48e773155a919f5Roshan Piusimport com.android.server.wifi.util.NativeUtil;
55240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
565a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport java.io.IOException;
575a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport java.nio.BufferUnderflowException;
585f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Piusimport java.nio.ByteBuffer;
595f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Piusimport java.nio.ByteOrder;
60240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport java.util.ArrayList;
61f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Piusimport java.util.HashMap;
62f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Piusimport java.util.List;
63f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Piusimport java.util.Map;
645f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Piusimport java.util.regex.Matcher;
655f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Piusimport java.util.regex.Pattern;
66d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
67240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne/**
68240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * Hal calls for bring up/shut down of the supplicant daemon and for
69240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * sending requests to the supplicant daemon
70240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne */
71b4419d876beda78c29836726e43d80203b4a656cRoshan Piuspublic class SupplicantStaIfaceHal {
72240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    private static final boolean DBG = false;
73b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    private static final String TAG = "SupplicantStaIfaceHal";
7498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private static final String SERVICE_MANAGER_NAME = "manager";
755f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
765f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Regex pattern for extracting the wps device type bytes.
775f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Matches a strings like the following: "<categ>-<OUI>-<subcateg>";
785f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
795f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    private static final Pattern WPS_DEVICE_TYPE_PATTERN =
805f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            Pattern.compile("^(\\d{1,2})-([0-9a-fA-F]{8})-(\\d{1,2})$");
815f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
8298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private IServiceManager mIServiceManager = null;
8398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    // Supplicant HAL interface objects
8498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private ISupplicant mISupplicant;
8598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private ISupplicantStaIface mISupplicantStaIface;
8603fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius    private String mIfaceName;
877c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    // Currently configured network in wpa_supplicant
887c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    private SupplicantStaNetworkHal mCurrentNetwork;
897c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    // Currently configured network's framework network Id.
905a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius    private int mFrameworkNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
91240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    private final Object mLock = new Object();
92c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius    private final Context mContext;
93c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius    private final WifiMonitor mWifiMonitor;
947c0ec884188660f72977c8a80366049705c48ffaRoshan Pius
95c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius    public SupplicantStaIfaceHal(Context context, WifiMonitor monitor) {
96c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius        mContext = context;
97c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius        mWifiMonitor = monitor;
988c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius    }
99240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
100240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    /**
10198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     * Registers a service notification for the ISupplicant service, which triggers intialization of
10298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     * the ISupplicantStaIface
103240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne     * @return true if the service notification was successfully registered
104240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne     */
105240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    public boolean initialize() {
10698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne        if (DBG) Log.i(TAG, "Registering ISupplicant service ready callback.");
107240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        synchronized (mLock) {
10898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicant = null;
10998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicantStaIface = null;
11098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            if (mIServiceManager != null) {
11198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                // Already have an IServiceManager and serviceNotification registered, don't
11298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                // don't register another.
11398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                return true;
11498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            }
115240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            try {
11698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                mIServiceManager = getServiceManagerMockable();
11798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                if (mIServiceManager == null) {
118240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    Log.e(TAG, "Failed to get HIDL Service Manager");
119240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    return false;
120240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }
12198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                if (!mIServiceManager.linkToDeath(cookie -> {
122240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    Log.wtf(TAG, "IServiceManager died: cookie=" + cookie);
123240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    synchronized (mLock) {
124240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        supplicantServiceDiedHandler();
12598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                        mIServiceManager = null; // Will need to register a new ServiceNotification
126240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    }
127240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }, 0)) {
128240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    Log.wtf(TAG, "Error on linkToDeath on IServiceManager");
129240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    supplicantServiceDiedHandler();
13098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                    mIServiceManager = null; // Will need to register a new ServiceNotification
131240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    return false;
132240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }
133240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                IServiceNotification serviceNotificationCb = new IServiceNotification.Stub() {
134240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    public void onRegistration(String fqName, String name, boolean preexisting) {
13598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                        synchronized (mLock) {
13698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                            if (DBG) {
13798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                                Log.i(TAG, "IServiceNotification.onRegistration for: " + fqName
13898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                                        + ", " + name + " preexisting=" + preexisting);
13998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                            }
14098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                            if (!initSupplicantService() || !initSupplicantStaIface()) {
14198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                                Log.e(TAG, "initalizing ISupplicantIfaces failed.");
14298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                                supplicantServiceDiedHandler();
14398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                            } else {
14498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                                Log.i(TAG, "Completed initialization of ISupplicant interfaces.");
14598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                            }
146240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        }
147240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    }
148240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                };
149240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                /* TODO(b/33639391) : Use the new ISupplicant.registerForNotifications() once it
150240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                   exists */
15198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                if (!mIServiceManager.registerForNotifications(ISupplicant.kInterfaceName,
152240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        "", serviceNotificationCb)) {
153240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    Log.e(TAG, "Failed to register for notifications to "
154240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                            + ISupplicant.kInterfaceName);
15598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                    mIServiceManager = null; // Will need to register a new ServiceNotification
156240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    return false;
157240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }
158240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            } catch (RemoteException e) {
159240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "Exception while trying to register a listener for ISupplicant service: "
160240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        + e);
16198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                supplicantServiceDiedHandler();
162240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
163240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            return true;
164240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
165240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
166240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
16798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private boolean initSupplicantService() {
168240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        synchronized (mLock) {
169240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            try {
17098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                mISupplicant = getSupplicantMockable();
171240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            } catch (RemoteException e) {
172240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "ISupplicant.getService exception: " + e);
173240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                return false;
174240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
17598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            if (mISupplicant == null) {
176240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "Got null ISupplicant service. Stopping supplicant HIDL startup");
177240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                return false;
178240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
179240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
180240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        return true;
181240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
182240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
18398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private boolean initSupplicantStaIface() {
184240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        synchronized (mLock) {
185240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            /** List all supplicant Ifaces */
186240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            final ArrayList<ISupplicant.IfaceInfo> supplicantIfaces = new ArrayList<>();
187240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            try {
18898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                mISupplicant.listInterfaces((SupplicantStatus status,
189240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        ArrayList<ISupplicant.IfaceInfo> ifaces) -> {
190240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    if (status.code != SupplicantStatusCode.SUCCESS) {
191240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        Log.e(TAG, "Getting Supplicant Interfaces failed: " + status.code);
192240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        return;
193240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    }
194240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    supplicantIfaces.addAll(ifaces);
195240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                });
196240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            } catch (RemoteException e) {
197240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "ISupplicant.listInterfaces exception: " + e);
19898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                return false;
199240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
200240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            if (supplicantIfaces.size() == 0) {
201240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "Got zero HIDL supplicant ifaces. Stopping supplicant HIDL startup.");
20298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                return false;
203240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
204240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            Mutable<ISupplicantIface> supplicantIface = new Mutable<>();
20503fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius            Mutable<String> ifaceName = new Mutable<>();
206240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            for (ISupplicant.IfaceInfo ifaceInfo : supplicantIfaces) {
20798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                if (ifaceInfo.type == IfaceType.STA) {
208240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    try {
20998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                        mISupplicant.getInterface(ifaceInfo,
210240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                (SupplicantStatus status, ISupplicantIface iface) -> {
211240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                if (status.code != SupplicantStatusCode.SUCCESS) {
212240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                    Log.e(TAG, "Failed to get ISupplicantIface " + status.code);
213240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                    return;
214240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                }
215240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                supplicantIface.value = iface;
216240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                            });
217240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    } catch (RemoteException e) {
218240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        Log.e(TAG, "ISupplicant.getInterface exception: " + e);
21998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                        return false;
220240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    }
22103fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius                    ifaceName.value = ifaceInfo.name;
222240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    break;
223240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }
224240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
22598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            if (supplicantIface.value == null) {
22698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                Log.e(TAG, "initSupplicantStaIface got null iface");
227240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                return false;
228240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
22998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicantStaIface = getStaIfaceMockable(supplicantIface.value);
23003fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius            mIfaceName = ifaceName.value;
231c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            if (!registerCallback(new SupplicantStaIfaceHalCallback())) {
232c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                return false;
233c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            }
234240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            return true;
235240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
236240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
237240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
23898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private void supplicantServiceDiedHandler() {
239240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        synchronized (mLock) {
24098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicant = null;
24198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicantStaIface = null;
242240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
243240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
244240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
24598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    /**
24698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     * Signals whether Initialization completed successfully. Only necessary for testing, is not
24798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     * needed to guard calls etc.
24898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     */
24998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    public boolean isInitializationComplete() {
25098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne        return mISupplicantStaIface != null;
2518c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius    }
2528c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius
2538c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius    /**
25498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     * Wrapper functions to access static HAL methods, created to be mockable in unit tests
2558c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius     */
25698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    protected IServiceManager getServiceManagerMockable() throws RemoteException {
25798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne        return IServiceManager.getService(SERVICE_MANAGER_NAME);
25898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    }
25998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne
26098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    protected ISupplicant getSupplicantMockable() throws RemoteException {
26198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne        return ISupplicant.getService();
26298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    }
26398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne
26498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    protected ISupplicantStaIface getStaIfaceMockable(ISupplicantIface iface) {
26598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne        return ISupplicantStaIface.asInterface(iface.asBinder());
2668c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius    }
2678c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius
26896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
2697c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * Add a network configuration to wpa_supplicant.
270d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
27166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     * @param config Config corresponding to the network.
27266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     * @return SupplicantStaNetwork of the added network in wpa_supplicant.
27366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     */
274d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    private SupplicantStaNetworkHal addNetwork(WifiConfiguration config) {
27566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        logi("addSupplicantStaNetwork via HIDL");
27666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        if (config == null) {
27766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Cannot add NULL network!");
27866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return null;
27966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
28066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        SupplicantStaNetworkHal network = addNetwork();
28166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        if (network == null) {
28266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Failed to add a network!");
28366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return null;
28466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
28566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        if (network.saveWifiConfiguration(config)) {
28666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return network;
28766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        } else {
28866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Failed to save variables for: " + config.configKey());
28966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return null;
29066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
29166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
29266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
29366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    /**
2947c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * Add the provided network configuration to wpa_supplicant and initiate connection to it.
2957c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * This method does the following:
2967c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 1. Triggers disconnect command to wpa_supplicant (if |shouldDisconnect| is true).
2977c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 2. Remove any existing network in wpa_supplicant.
2987c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 3. Add a new network to wpa_supplicant.
2997c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 4. Save the provided configuration to wpa_supplicant.
3007c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 5. Select the new network in wpa_supplicant.
301d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
3027c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @param config WifiConfiguration parameters for the provided network.
3037c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @param shouldDisconnect whether to trigger a disconnection or not.
3047c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @return {@code true} if it succeeds, {@code false} otherwise
30566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     */
306d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean connectToNetwork(WifiConfiguration config, boolean shouldDisconnect) {
3077c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        mFrameworkNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
3087c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        mCurrentNetwork = null;
309d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        logd("connectToNetwork " + config.configKey()
31066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                + " (shouldDisconnect " + shouldDisconnect + ")");
31166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        if (shouldDisconnect && !disconnect()) {
31266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Failed to trigger disconnect");
31366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return false;
31466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
31566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        if (!removeAllNetworks()) {
31666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Failed to remove existing networks");
31766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return false;
31866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
3197c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        mCurrentNetwork = addNetwork(config);
3207c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (mCurrentNetwork == null) {
321d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius            loge("Failed to add/save network configuration: " + config.configKey());
32266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return false;
32366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
3247c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (!mCurrentNetwork.select()) {
325d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius            loge("Failed to select network configuration: " + config.configKey());
32666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return false;
32766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
3287c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        mFrameworkNetworkId = config.networkId;
3297c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        return true;
3307c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    }
3317c0ec884188660f72977c8a80366049705c48ffaRoshan Pius
3327c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    /**
3337c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * Initiates roaming to the already configured network in wpa_supplicant. If the network
3347c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * configuration provided does not match the already configured network, then this triggers
3357c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * a new connection attempt (instead of roam).
3367c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 1. First check if we're attempting to connect to the same network as we currently have
3377c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * configured.
3387c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 2. Set the new bssid for the network in wpa_supplicant.
3397c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 3. Trigger reassociate command to wpa_supplicant.
3407c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     *
3417c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @param config WifiConfiguration parameters for the provided network.
3427c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @return {@code true} if it succeeds, {@code false} otherwise
3437c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     */
3447c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    public boolean roamToNetwork(WifiConfiguration config) {
3457c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (mFrameworkNetworkId != config.networkId || mCurrentNetwork == null) {
3467c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            Log.w(TAG, "Cannot roam to a different network, initiate new connection. "
3477c0ec884188660f72977c8a80366049705c48ffaRoshan Pius                    + "Current network ID: " + mFrameworkNetworkId);
3487c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            return connectToNetwork(config, false);
3497c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        }
3507c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        String bssid = config.getNetworkSelectionStatus().getNetworkSelectionBSSID();
3517c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        logd("roamToNetwork" + config.configKey() + " (bssid " + bssid + ")");
3527c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (!mCurrentNetwork.setBssid(bssid)) {
3537c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            loge("Failed to set new bssid on network: " + config.configKey());
3547c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            return false;
3557c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        }
3567c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (!reassociate()) {
3577c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            loge("Failed to trigger reassociate");
3587c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            return false;
3597c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        }
36066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        return true;
36166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
36266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
36366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    /**
364f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * Load all the configured networks from wpa_supplicant.
365f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     *
366f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @param configs       Map of configuration key to configuration objects corresponding to all
367f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     *                      the networks.
368f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @param networkExtras Map of extra configuration parameters stored in wpa_supplicant.conf
369f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @return true if succeeds, false otherwise.
370f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     */
371f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    public boolean loadNetworks(Map<String, WifiConfiguration> configs,
372f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                                SparseArray<Map<String, String>> networkExtras) {
373f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        List<Integer> networkIds = listNetworks();
374f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        if (networkIds == null) {
375f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            Log.e(TAG, "Failed to list networks");
376f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            return false;
377f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        }
378f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        for (Integer networkId : networkIds) {
379f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            SupplicantStaNetworkHal network = getNetwork(networkId);
380f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            if (network == null) {
381f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                Log.e(TAG, "Failed to get network with ID: " + networkId);
382f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                return false;
383f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            }
384f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            WifiConfiguration config = new WifiConfiguration();
385f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            Map<String, String> networkExtra = new HashMap<>();
386f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            if (!network.loadWifiConfiguration(config, networkExtra)) {
387f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                Log.e(TAG, "Failed to load wifi configuration for network with ID: " + networkId);
388f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                return false;
389f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            }
390f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            // Set the default IP assignments.
391f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            config.setIpAssignment(IpConfiguration.IpAssignment.DHCP);
392f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            config.setProxySettings(IpConfiguration.ProxySettings.NONE);
393f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius
394f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            networkExtras.put(networkId, networkExtra);
395f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            String configKey = networkExtra.get(SupplicantStaNetworkHal.ID_STRING_KEY_CONFIG_KEY);
396f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            final WifiConfiguration duplicateConfig = configs.put(configKey, config);
397f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            if (duplicateConfig != null) {
398f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                // The network is already known. Overwrite the duplicate entry.
399f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                Log.i(TAG, "Replacing duplicate network: " + duplicateConfig.networkId);
400f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                removeNetwork(duplicateConfig.networkId);
401f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                networkExtras.remove(duplicateConfig.networkId);
402f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            }
403f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        }
404f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        return true;
405f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    }
406f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius
407f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    /**
40866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     * Remove all networks from supplicant
40966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     */
41066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    public boolean removeAllNetworks() {
41166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        synchronized (mLock) {
41266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            ArrayList<Integer> networks = listNetworks();
41366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            if (networks == null) {
41466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                Log.e(TAG, "removeAllNetworks failed, got null networks");
41566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                return false;
41666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            }
41766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            for (int id : networks) {
41866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                if (!removeNetwork(id)) {
41966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                    Log.e(TAG, "removeAllNetworks failed to remove network: " + id);
42066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                    return false;
42166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                }
42266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            }
42366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
42466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        return true;
42566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
42666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
42766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    /**
4280a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * Set the currently configured network's bssid.
4290a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     *
4300a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * @param bssidStr Bssid to set in the form of "XX:XX:XX:XX:XX:XX"
4310a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * @return true if succeeds, false otherwise.
4320a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     */
4330a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    public boolean setCurrentNetworkBssid(String bssidStr) {
4340a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius        if (mCurrentNetwork == null) return false;
4350a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius        return mCurrentNetwork.setBssid(bssidStr);
4360a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    }
4370a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius
4380a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    /**
4390a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * Get the currently configured network's WPS NFC token.
4400a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     *
4410a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * @return Hex string corresponding to the WPS NFC token.
4420a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     */
4430a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    public String getCurrentNetworkWpsNfcConfigurationToken() {
4440a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius        if (mCurrentNetwork == null) return null;
4450a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius        return mCurrentNetwork.getWpsNfcConfigurationToken();
4460a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    }
4470a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius
4480a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    /**
449d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Adds a new network.
450d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
45196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * @return The ISupplicantNetwork object for the new network, or null if the call fails
45296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
45396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private SupplicantStaNetworkHal addNetwork() {
45496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
45596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "addNetwork";
45696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
45796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
4583aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            Mutable<ISupplicantNetwork> newNetwork = new Mutable<>();
45996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
46096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                mISupplicantStaIface.addNetwork((SupplicantStatus status,
46196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        ISupplicantNetwork network) -> {
4623aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius                    if (checkStatusAndLogFailure(status, methodStr)) {
46396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        newNetwork.value = network;
46496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                    }
46596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                });
46696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
46796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception: " + e);
46896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
46996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
4703aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            if (newNetwork.value != null) {
471c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius                return getStaNetworkMockable(
472c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius                        ISupplicantStaNetwork.asInterface(newNetwork.value.asBinder()));
47396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } else {
47496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return null;
47596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
47696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
47796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
478d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
47996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
48096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Remove network from supplicant with network Id
481d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
482d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
48396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
48496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean removeNetwork(int id) {
48596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
48696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "removeNetwork";
48796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
48896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
48996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
49096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.removeNetwork(id);
49196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
49296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
49396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
49496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
49596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
49696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
49796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
49896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
499d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
50096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
501f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * Use this to mock the creation of SupplicantStaNetworkHal instance.
502f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     *
503f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @param iSupplicantStaNetwork ISupplicantStaNetwork instance retrieved from HIDL.
504f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @return The ISupplicantNetwork object for the given SupplicantNetworkId int, returns null if
505f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * the call fails
506f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     */
507f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    protected SupplicantStaNetworkHal getStaNetworkMockable(
508c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius            ISupplicantStaNetwork iSupplicantStaNetwork) {
50903fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius        return new SupplicantStaNetworkHal(
51003fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius                iSupplicantStaNetwork, mIfaceName, mContext, mWifiMonitor);
511f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    }
512f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius
513f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    /**
51496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * @return The ISupplicantNetwork object for the given SupplicantNetworkId int, returns null if
51596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * the call fails
51696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
51796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private SupplicantStaNetworkHal getNetwork(int id) {
51896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
51996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "getNetwork";
52096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
5213aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            Mutable<ISupplicantNetwork> gotNetwork = new Mutable<>();
52296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
52396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
52496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                mISupplicantStaIface.getNetwork(id, (SupplicantStatus status,
52596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        ISupplicantNetwork network) -> {
5263aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius                    if (checkStatusAndLogFailure(status, methodStr)) {
52796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        gotNetwork.value = network;
52896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                    }
52996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                });
53096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
53196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception: " + e);
53296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
53396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
5343aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            if (gotNetwork.value != null) {
535c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius                return getStaNetworkMockable(
536c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius                        ISupplicantStaNetwork.asInterface(gotNetwork.value.asBinder()));
53796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } else {
53896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return null;
53996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
54096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
54196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
54296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
543c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    /** See ISupplicantStaNetwork.hal for documentation */
544c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    private boolean registerCallback(ISupplicantStaIfaceCallback callback) {
545c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        synchronized (mLock) {
546c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            final String methodStr = "registerCallback";
547c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
548c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            try {
549c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                SupplicantStatus status =  mISupplicantStaIface.registerCallback(callback);
550c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                return checkStatusAndLogFailure(status, methodStr);
551c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            } catch (RemoteException e) {
552c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                supplicantServiceDiedHandler();
553c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                return false;
554c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            }
555c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
556c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    }
557c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
55896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
55996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * @return a list of SupplicantNetworkID ints for all networks controlled by supplicant, returns
56096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * null if the call fails
56196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
56296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private java.util.ArrayList<Integer> listNetworks() {
56396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
56496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "listNetworks";
56596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
5663aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            Mutable<ArrayList<Integer>> networkIdList = new Mutable<>();
56796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
56896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
56996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                mISupplicantStaIface.listNetworks((SupplicantStatus status,
57096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        java.util.ArrayList<Integer> networkIds) -> {
5713aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius                    if (checkStatusAndLogFailure(status, methodStr)) {
57296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        networkIdList.value = networkIds;
57396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                    }
57496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                });
57596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
57696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception: " + e);
57796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
57896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
5793aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            return networkIdList.value;
58096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
58196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
582d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
5835f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
5845f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS device name.
5855f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
5865f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param name String to be set.
5875f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
5885f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
5895f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsDeviceName(String name) {
5907651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
5917651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsDeviceName";
5927651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (DBG) Log.i(TAG, methodStr);
5937651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
5947651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
5957651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsDeviceName(name);
5967651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
5977651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
5987651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
5997651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                supplicantServiceDiedHandler();
6007651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
6017651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
6027651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
6037651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
6047651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
6055f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
6065f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS device type.
6075f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
6085f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param typeStr Type specified as a string. Used format: <categ>-<OUI>-<subcateg>
6095f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
6105f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
6115f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsDeviceType(String typeStr) {
6125f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        Matcher match = WPS_DEVICE_TYPE_PATTERN.matcher(typeStr);
6135f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        if (!match.find() || match.groupCount() != 3) {
6145f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            Log.e(TAG, "Malformed WPS device type " + typeStr);
6155f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            return false;
6165f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        }
6175f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        short categ = Short.parseShort(match.group(1));
6185f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byte[] oui = NativeUtil.hexStringToByteArray(match.group(2));
6195f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        short subCateg = Short.parseShort(match.group(3));
6205f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
6215f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byte[] bytes = new byte[8];
6225f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        ByteBuffer byteBuffer = ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN);
6235f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byteBuffer.putShort(categ);
6245f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byteBuffer.put(oui);
6255f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byteBuffer.putShort(subCateg);
6265f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return setWpsDeviceType(bytes);
6275f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
6285f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
6297651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private boolean setWpsDeviceType(byte[/* 8 */] type) {
6307651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
6317651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsDeviceType";
6327651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (DBG) Log.i(TAG, methodStr);
6337651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
6347651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
6357651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsDeviceType(type);
6367651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
6377651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
6387651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
6397651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                supplicantServiceDiedHandler();
6407651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
6417651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
6427651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
6437651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
6447651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
6455f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
6465f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS manufacturer.
6475f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
6485f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param manufacturer String to be set.
6495f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
6505f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
6515f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsManufacturer(String manufacturer) {
6527651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
6537651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsManufacturer";
6547651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (DBG) Log.i(TAG, methodStr);
6557651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
6567651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
6577651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsManufacturer(manufacturer);
6587651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
6597651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
6607651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
6617651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                supplicantServiceDiedHandler();
6627651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
6637651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
6647651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
6657651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
6667651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
6675f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
6685f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS model name.
6695f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
6705f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param modelName String to be set.
6715f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
6725f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
6735f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsModelName(String modelName) {
6747651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
6757651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsModelName";
6767651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (DBG) Log.i(TAG, methodStr);
6777651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
6787651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
6797651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsModelName(modelName);
6807651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
6817651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
6827651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
6837651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                supplicantServiceDiedHandler();
6847651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
6857651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
6867651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
6877651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
6887651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
6895f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
6905f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS model number.
6915f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
6925f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param modelNumber String to be set.
6935f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
6945f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
6955f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsModelNumber(String modelNumber) {
6967651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
6977651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsModelNumber";
6987651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (DBG) Log.i(TAG, methodStr);
6997651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
7007651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
7017651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsModelNumber(modelNumber);
7027651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
7037651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
7047651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
7057651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                supplicantServiceDiedHandler();
7067651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
7077651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
7087651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
7097651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
7107651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
7115f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
7125f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS serial number.
7135f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
7145f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param serialNumber String to be set.
7155f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
7165f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
7175f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsSerialNumber(String serialNumber) {
7187651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
7197651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsSerialNumber";
7207651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (DBG) Log.i(TAG, methodStr);
7217651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
7227651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
7237651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsSerialNumber(serialNumber);
7247651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
7257651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
7267651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
7277651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                supplicantServiceDiedHandler();
7287651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
7297651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
7307651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
7317651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
7327651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
7335f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
7345f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS config methods
7355f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
7365f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param configMethodsStr List of config methods.
7375f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
7385f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
7395f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsConfigMethods(String configMethodsStr) {
7405f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        short configMethodsMask = 0;
7415f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        String[] configMethodsStrArr = configMethodsStr.split("\\s+");
7425f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        for (int i = 0; i < configMethodsStrArr.length; i++) {
7435f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            configMethodsMask |= stringToWpsConfigMethod(configMethodsStrArr[i]);
7445f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        }
7455f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return setWpsConfigMethods(configMethodsMask);
7465f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
7475f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
7487651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private boolean setWpsConfigMethods(short configMethods) {
7497651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
7507651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsConfigMethods";
7517651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (DBG) Log.i(TAG, methodStr);
7527651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
7537651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
7547651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsConfigMethods(configMethods);
7557651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
7567651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
7577651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
7587651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                supplicantServiceDiedHandler();
7597651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
7607651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
7617651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
7627651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
7637651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
764d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
765d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Trigger a reassociation even if the iface is currently connected.
766d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
767d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
768d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
769d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean reassociate() {
77096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
77196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "reassociate";
77296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
77396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
77496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
77596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.reassociate();
77696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
77796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
77896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
77996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
78096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
78196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
78296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
78396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
784d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
785d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
786d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Trigger a reconnection if the iface is disconnected.
787d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
788d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
789d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
790d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean reconnect() {
79196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
79296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "reconnect";
79396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
79496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
79596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
79696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.reconnect();
79796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
79896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
79996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
80096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
80196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
80296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
80396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
80496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
805d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
806d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
807d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Trigger a disconnection from the currently connected network.
808d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
809d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
810d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
811d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean disconnect() {
81296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
81396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "disconnect";
81496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
81596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
81696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
81796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.disconnect();
81896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
81996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
82096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
82196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
82296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
82396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
82496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
82596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
826d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
827d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
828d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Enable or disable power save mode.
829d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
830d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param enable true to enable, false to disable.
831d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
832d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
833d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setPowerSave(boolean enable) {
83496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
83596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setPowerSave";
83696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
83796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
83896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
83996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.setPowerSave(enable);
84096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
84196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
84296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
84396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
84496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
84596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
84696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
84796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
848d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
849d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
850d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Initiate TDLS discover with the specified AP.
851d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
852d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param macAddress MAC Address of the AP.
853d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
854d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
855d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateTdlsDiscover(String macAddress) {
856d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateTdlsDiscover(NativeUtil.macAddressToByteArray(macAddress));
857d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
858b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
85996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateTdlsDiscover(byte[/* 6 */] macAddress) {
86096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
86196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateTdlsDiscover";
86296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
86396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
86496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
86596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateTdlsDiscover(macAddress);
86696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
86796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
86896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
86996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
87096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
87196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
87296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
87396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
874d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
875d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
876d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Initiate TDLS setup with the specified AP.
877d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
878d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param macAddress MAC Address of the AP.
879d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
880d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
881d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateTdlsSetup(String macAddress) {
882d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateTdlsSetup(NativeUtil.macAddressToByteArray(macAddress));
883d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
884b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
88596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateTdlsSetup(byte[/* 6 */] macAddress) {
88696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
88796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateTdlsSetup";
88896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
88996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
89096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
89196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateTdlsSetup(macAddress);
89296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
89396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
89496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
89596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
89696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
89796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
89896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
89996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
900d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
901d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
902d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Initiate TDLS teardown with the specified AP.
903d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param macAddress MAC Address of the AP.
904d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
905d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
906d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateTdlsTeardown(String macAddress) {
907d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateTdlsTeardown(NativeUtil.macAddressToByteArray(macAddress));
908d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
909d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
910b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
91196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateTdlsTeardown(byte[/* 6 */] macAddress) {
91296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
91396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateTdlsTeardown";
91496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
91596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
91696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
91796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateTdlsTeardown(macAddress);
91896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
91996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
92096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
92196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
92296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
92396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
92496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
92596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
926d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
927d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
928d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Request the specified ANQP elements |elements| from the specified AP |bssid|.
929d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
930d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param bssid BSSID of the AP
931d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param infoElements ANQP elements to be queried. Refer to ISupplicantStaIface.AnqpInfoId.
932d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param hs20SubTypes HS subtypes to be queried. Refer to ISupplicantStaIface.Hs20AnqpSubTypes.
933d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
934d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
935d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateAnqpQuery(String bssid, ArrayList<Short> infoElements,
936d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius                                     ArrayList<Integer> hs20SubTypes) {
937d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateAnqpQuery(
938d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius                NativeUtil.macAddressToByteArray(bssid), infoElements, hs20SubTypes);
939d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
940d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
941b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
94296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateAnqpQuery(byte[/* 6 */] macAddress,
94396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            java.util.ArrayList<Short> infoElements, java.util.ArrayList<Integer> subTypes) {
94496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
94596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateAnqpQuery";
94696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
94796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
94896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
94996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateAnqpQuery(macAddress,
95096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        infoElements, subTypes);
95196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
95296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
95396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
95496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
95596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
95696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
95796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
95896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
959d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
960d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
961d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Request the specified ANQP ICON from the specified AP |bssid|.
962d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
963d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param bssid BSSID of the AP
964d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param fileName Name of the file to request.
965d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
966d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
967d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateHs20IconQuery(String bssid, String fileName) {
968d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateHs20IconQuery(NativeUtil.macAddressToByteArray(bssid), fileName);
969d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
970d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
971b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
97296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateHs20IconQuery(byte[/* 6 */] macAddress, String fileName) {
97396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
97496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateHs20IconQuery";
97596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
97696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
97796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
97896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateHs20IconQuery(macAddress,
97996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        fileName);
98096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
98196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
98296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
98396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
98496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
98596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
98696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
98796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
988d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
98996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
99096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Makes a callback to HIDL to getMacAddress from supplicant
991d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
99296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * @return string containing the MAC address, or null on a failed call
99396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
994d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public String getMacAddress() {
99596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
99696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "getMacAddress";
99796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
99896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
99996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            Mutable<String> gotMac = new Mutable<>();
100096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
100196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                mISupplicantStaIface.getMacAddress((SupplicantStatus status,
100296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        byte[/* 6 */] macAddr) -> {
10033aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius                    if (checkStatusAndLogFailure(status, methodStr)) {
1004d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius                        gotMac.value = NativeUtil.macAddressFromByteArray(macAddr);
100596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                    }
100696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                });
100796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
100896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception: " + e);
100996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
101096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
10113aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            return gotMac.value;
101296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
101396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1014d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1015d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1016d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Start using the added RX filters.
1017d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1018d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1019d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1020d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean startRxFilter() {
102196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
102296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "startRxFilter";
102396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
102496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
102596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
102696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.startRxFilter();
102796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
102896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
102996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
103096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
103196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
103296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
103396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
103496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1035d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1036d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1037d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Stop using the added RX filters.
1038d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1039d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1040d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1041d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean stopRxFilter() {
104296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
104396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "stopRxFilter";
104496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
104596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
104696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
104796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.stopRxFilter();
104896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
104996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
105096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
105196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
105296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
105396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
105496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
105596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1056d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1057d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte RX_FILTER_TYPE_V4_MULTICAST =
1058d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius            ISupplicantStaIface.RxFilterType.V6_MULTICAST;
1059d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte RX_FILTER_TYPE_V6_MULTICAST =
1060d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius            ISupplicantStaIface.RxFilterType.V6_MULTICAST;
1061d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1062d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Add an RX filter.
1063d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1064d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param type one of {@link #RX_FILTER_TYPE_V4_MULTICAST} or
1065d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *        {@link #RX_FILTER_TYPE_V6_MULTICAST} values.
1066d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1067d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
106896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean addRxFilter(byte type) {
106996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
107096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "addRxFilter";
107196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
107296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
107396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
107496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.addRxFilter(type);
107596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
107696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
107796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
107896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
107996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
108096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
108196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
108296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1083d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1084d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1085d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Remove 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     */
109196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean removeRxFilter(byte type) {
109296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
109396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "removeRxFilter";
109496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
109596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
109696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
109796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.removeRxFilter(type);
109896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
109996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
110096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
110196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
110296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
110396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
110496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
110596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1106d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1107d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte BT_COEX_MODE_ENABLED = ISupplicantStaIface.BtCoexistenceMode.ENABLED;
1108d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte BT_COEX_MODE_DISABLED = ISupplicantStaIface.BtCoexistenceMode.DISABLED;
1109d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte BT_COEX_MODE_SENSE = ISupplicantStaIface.BtCoexistenceMode.SENSE;
1110d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1111d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Set Bt co existense mode.
1112d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1113d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param mode one of the above {@link #BT_COEX_MODE_ENABLED}, {@link #BT_COEX_MODE_DISABLED}
1114d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *             or {@link #BT_COEX_MODE_SENSE} values.
1115d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1116d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1117d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setBtCoexistenceMode(byte mode) {
111896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
111996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setBtCoexistenceMode";
112096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
112196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
112296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
112396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.setBtCoexistenceMode(mode);
112496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
112596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
112696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
112796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
112896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
112996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
113096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
113196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1132d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1133d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /** Enable or disable BT coexistence mode.
1134d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1135d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param enable true to enable, false to disable.
1136d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1137d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1138d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setBtCoexistenceScanModeEnabled(boolean enable) {
113996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
114096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setBtCoexistenceScanModeEnabled";
114196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
114296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
114396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
114496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status =
114596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        mISupplicantStaIface.setBtCoexistenceScanModeEnabled(enable);
114696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
114796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
114896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
114996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
115096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
115196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
115296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
115396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1154d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1155d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1156d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Enable or disable suspend mode optimizations.
1157d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1158d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param enable true to enable, false otherwise.
11595f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
1160d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1161d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setSuspendModeEnabled(boolean enable) {
116296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
116396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setSuspendModeEnabled";
116496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
116596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
116696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
116796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.setSuspendModeEnabled(enable);
116896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
116996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
117096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
117196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
117296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
117396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
117496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
117596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1176d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1177d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1178d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Set country code.
1179d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1180d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param codeStr 2 byte ASCII string. For ex: US, CA.
1181d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1182d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1183d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setCountryCode(String codeStr) {
1184d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return setCountryCode(NativeUtil.stringToByteArray(codeStr));
1185d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
1186d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1187b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
118896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean setCountryCode(byte[/* 2 */] code) {
118996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
119096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setCountryCode";
119196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (DBG) Log.i(TAG, methodStr);
119296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
119396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
119496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.setCountryCode(code);
119596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
119696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
119796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
119896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                supplicantServiceDiedHandler();
119996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
120096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
120196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
120296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
120396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
12045f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
12055f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Start WPS pin registrar operation with the specified peer and pin.
12065f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
12075f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param bssidStr BSSID of the peer.
12085f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param pin Pin to be used.
12095f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
12105f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
12115f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean startWpsRegistrar(String bssidStr, String pin) {
12125f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return startWpsRegistrar(NativeUtil.macAddressToByteArray(bssidStr), pin);
12135f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
12145f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
12157651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
12167651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private boolean startWpsRegistrar(byte[/* 6 */] bssid, String pin) {
12177651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
12187651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "startWpsRegistrar";
12197651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (DBG) Log.i(TAG, methodStr);
12207651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
12217651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
12227651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.startWpsRegistrar(bssid, pin);
12237651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
12247651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
12257651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
12267651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                supplicantServiceDiedHandler();
12277651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
12287651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
12297651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
12307651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
12317651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
12325f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
12335f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Start WPS pin display operation with the specified peer.
12345f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
12355f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param bssidStr BSSID of the peer.
12365f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
12375f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
12385f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean startWpsPbc(String bssidStr) {
12395f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return startWpsPbc(NativeUtil.macAddressToByteArray(bssidStr));
12405f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
12415f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
12427651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
12437651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private boolean startWpsPbc(byte[/* 6 */] bssid) {
12447651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
12457651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "startWpsPbc";
12467651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (DBG) Log.i(TAG, methodStr);
12477651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
12487651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
12497651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.startWpsPbc(bssid);
12507651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
12517651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
12527651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
12537651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                supplicantServiceDiedHandler();
12547651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
12557651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
12567651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
12577651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
12587651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
12595f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
12605f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Start WPS pin keypad operation with the specified pin.
12615f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
12625f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param pin Pin to be used.
12635f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
12645f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
12655f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean startWpsPinKeypad(String pin) {
12667651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
12677651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "startWpsPinKeypad";
12687651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (DBG) Log.i(TAG, methodStr);
12697651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
12707651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
12717651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.startWpsPinKeypad(pin);
12727651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
12737651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
12747651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
12757651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                supplicantServiceDiedHandler();
12767651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
12777651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
12787651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
12797651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
12807651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
12815f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
12825f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Start WPS pin display operation with the specified peer.
12835f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
12845f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param bssidStr BSSID of the peer.
12855f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return new pin generated on success, null otherwise.
12865f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
12875f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public String startWpsPinDisplay(String bssidStr) {
12885f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return startWpsPinDisplay(NativeUtil.macAddressToByteArray(bssidStr));
12895f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
12905f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
12917651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
12927651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private String startWpsPinDisplay(byte[/* 6 */] bssid) {
12937651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
12947651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "startWpsPinDisplay";
12957651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (DBG) Log.i(TAG, methodStr);
12967651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
12977651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final Mutable<String> gotPin = new Mutable<>();
12987651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
12997651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                mISupplicantStaIface.startWpsPinDisplay(bssid,
13007651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                        (SupplicantStatus status, String pin) -> {
13017651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                            if (checkStatusAndLogFailure(status, methodStr)) {
13027651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                                gotPin.value = pin;
13037651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                            }
13047651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                        });
13057651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
13067651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
13077651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                supplicantServiceDiedHandler();
13087651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
13097651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            return gotPin.value;
13107651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
13117651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
13127651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
13135f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
13145f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Cancels any ongoing WPS requests.
13155f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
13165f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
13175f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
13185f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean cancelWps() {
13197651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
13207651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "cancelWps";
13217651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (DBG) Log.i(TAG, methodStr);
13227651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
13237651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
13247651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.cancelWps();
13257651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
13267651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
13277651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
13287651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                supplicantServiceDiedHandler();
13297651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
13307651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
13317651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
13327651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
13337651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
13345f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
13355f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Sets whether to use external sim for SIM/USIM processing.
13365f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
13375f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param useExternalSim true to enable, false otherwise.
13385f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
13395f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
13405f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setExternalSim(boolean useExternalSim) {
13417651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
13427651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setExternalSim";
13437651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (DBG) Log.i(TAG, methodStr);
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) {
13497651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                Log.e(TAG, "ISupplicantStaIface." + methodStr + ": exception:" + e);
13507651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                supplicantServiceDiedHandler();
13517651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
13527651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
13537651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
13547651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
13557651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
1356cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_EXCESSIVE = ISupplicant.DebugLevel.EXCESSIVE;
1357cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_MSGDUMP = ISupplicant.DebugLevel.MSGDUMP;
1358cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_DEBUG = ISupplicant.DebugLevel.DEBUG;
1359cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_INFO = ISupplicant.DebugLevel.INFO;
1360cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_WARNING = ISupplicant.DebugLevel.WARNING;
1361cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_ERROR = ISupplicant.DebugLevel.ERROR;
1362cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /**
1363cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * Set the debug log level for wpa_supplicant
1364cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * @param level One of the above {@link #LOG_LEVEL_EXCESSIVE} - {@link #LOG_LEVEL_ERROR} value.
1365cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * @return true if request is sent successfully, false otherwise.
1366cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     */
1367cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public boolean setLogLevel(int level) {
1368cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        return setDebugParams(level, false, false);
1369cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1370cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
1371cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /** See ISupplicant.hal for documentation */
1372cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    private boolean setDebugParams(int level, boolean showTimestamp, boolean showKeys) {
1373cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        synchronized (mLock) {
1374cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            final String methodStr = "setDebugParams";
1375cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            if (DBG) Log.i(TAG, methodStr);
1376cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            if (!checkSupplicantAndLogFailure(methodStr)) return false;
1377cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            try {
1378cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                SupplicantStatus status =
1379cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                        mISupplicant.setDebugParams(level, showTimestamp, showKeys);
1380cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                return checkStatusAndLogFailure(status, methodStr);
1381cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            } catch (RemoteException e) {
1382cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                Log.e(TAG, "ISupplicant." + methodStr + ": exception:" + e);
1383cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                supplicantServiceDiedHandler();
1384cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                return false;
1385cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            }
1386cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        }
1387cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1388cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
1389cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /**
1390cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * Set concurrency priority between P2P & STA operations.
1391cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     *
1392cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * @param isStaHigherPriority Set to true to prefer STA over P2P during concurrency operations,
1393cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     *                            false otherwise.
1394cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * @return true if request is sent successfully, false otherwise.
1395cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     */
1396cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public boolean setConcurrencyPriority(boolean isStaHigherPriority) {
1397cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        if (isStaHigherPriority) {
1398cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            return setConcurrencyPriority(IfaceType.STA);
1399cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        } else {
1400cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            return setConcurrencyPriority(IfaceType.P2P);
1401cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        }
1402cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1403cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
1404cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /** See ISupplicant.hal for documentation */
1405cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    private boolean setConcurrencyPriority(int type) {
1406cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        synchronized (mLock) {
1407cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            final String methodStr = "setConcurrencyPriority";
1408cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            if (DBG) Log.i(TAG, methodStr);
1409cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            if (!checkSupplicantAndLogFailure(methodStr)) return false;
1410cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            try {
1411cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                SupplicantStatus status = mISupplicant.setConcurrencyPriority(type);
1412cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                return checkStatusAndLogFailure(status, methodStr);
1413cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            } catch (RemoteException e) {
1414cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                Log.e(TAG, "ISupplicant." + methodStr + ": exception:" + e);
1415cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                supplicantServiceDiedHandler();
1416cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                return false;
1417cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            }
1418cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        }
1419cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1420cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
1421cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /**
1422cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * Returns false if Supplicant is null, and logs failure to call methodStr
1423cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     */
1424cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    private boolean checkSupplicantAndLogFailure(final String methodStr) {
1425cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        if (DBG) Log.i(TAG, methodStr);
1426cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        if (mISupplicant == null) {
1427cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            Log.e(TAG, "Can't call " + methodStr + ", ISupplicant is null");
1428cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            return false;
1429cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        }
1430cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        return true;
1431cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1432cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
143396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
143496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Returns false if SupplicantStaIface is null, and logs failure to call methodStr
143596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
143696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean checkSupplicantStaIfaceAndLogFailure(final String methodStr) {
143796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        if (DBG) Log.i(TAG, methodStr);
143896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        if (mISupplicantStaIface == null) {
143996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            Log.e(TAG, "Can't call " + methodStr + ", ISupplicantStaIface is null");
144096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            return false;
144196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
144296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        return true;
144396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
144496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
144596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
144696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Returns true if provided status code is SUCCESS, logs debug message and returns false
144796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * otherwise
144896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
144996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private static boolean checkStatusAndLogFailure(SupplicantStatus status,
145096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr) {
145196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        if (DBG) Log.i(TAG, methodStr);
145296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        if (status.code != SupplicantStatusCode.SUCCESS) {
145396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            Log.e(TAG, methodStr + " failed: " + supplicantStatusCodeToString(status.code) + ", "
145496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                    + status.debugMessage);
145596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            return false;
145696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
145796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        return true;
145896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
145996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
146096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
146196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Converts SupplicantStatus code values to strings for debug logging
146296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * TODO(b/34811152) Remove this, or make it more break resistance
146396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
146496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    public static String supplicantStatusCodeToString(int code) {
146596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        switch (code) {
146696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 0:
146796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "SUCCESS";
146896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 1:
146996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_UNKNOWN";
147096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 2:
147196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_ARGS_INVALID";
147296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 3:
147396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_INVALID";
147496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 4:
147596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_UNKNOWN";
147696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 5:
147796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_EXISTS";
147896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 6:
147996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_DISABLED";
148096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 7:
148196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_NOT_DISCONNECTED";
148296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 8:
148396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_NETWORK_INVALID";
148496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 9:
148596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_NETWORK_UNKNOWN";
148696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            default:
148796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "??? UNKNOWN_CODE";
148896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
148996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
149096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
14915f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
14925f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
14935f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Converts the Wps config method string to the equivalent enum value.
14945f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
14955f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    private static short stringToWpsConfigMethod(String configMethod) {
14965f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        switch (configMethod) {
14975f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "usba":
14985f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.USBA;
14995f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "ethernet":
15005f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.ETHERNET;
15015f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "label":
15025f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.LABEL;
15035f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "display":
15045f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.DISPLAY;
15055f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "int_nfc_token":
15065f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.INT_NFC_TOKEN;
15075f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "ext_nfc_token":
15085f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.EXT_NFC_TOKEN;
15095f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "nfc_interface":
15105f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.NFC_INTERFACE;
15115f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "push_button":
15125f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.PUSHBUTTON;
15135f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "keypad":
15145f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.KEYPAD;
15155f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "virtual_push_button":
15165f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.VIRT_PUSHBUTTON;
15175f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "physical_push_button":
15185f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.PHY_PUSHBUTTON;
15195f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "p2ps":
15205f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.P2PS;
15215f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "virtual_display":
15225f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.VIRT_DISPLAY;
15235f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "physical_display":
15245f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.PHY_DISPLAY;
15255f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            default:
15265f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                throw new IllegalArgumentException(
15275f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                        "Invalid WPS config method: " + configMethod);
15285f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        }
15295f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
15305f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
1531240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    private static class Mutable<E> {
1532240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        public E value;
1533240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
1534240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        Mutable() {
1535240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            value = null;
1536240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
1537240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
1538240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        Mutable(E value) {
1539240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            this.value = value;
1540240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
1541240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
154266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
1543c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    private class SupplicantStaIfaceHalCallback extends ISupplicantStaIfaceCallback.Stub {
15445a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        /**
15455a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * Parses the provided payload into an ANQP element.
15465a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         *
15475a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param infoID  Element type.
15485a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param payload Raw payload bytes.
15495a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @return AnqpElement instance on success, null on failure.
15505a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         */
15515a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        private ANQPElement parseAnqpElement(Constants.ANQPElementType infoID,
15525a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                                             ArrayList<Byte> payload) {
15535a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            try {
15545a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                return Constants.getANQPElementID(infoID) != null
15555a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        ? ANQPParser.parseElement(
15565a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        infoID, ByteBuffer.wrap(NativeUtil.byteArrayFromArrayList(payload)))
15575a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        : ANQPParser.parseHS20Element(
15585a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        infoID, ByteBuffer.wrap(NativeUtil.byteArrayFromArrayList(payload)));
15595a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            } catch (IOException | BufferUnderflowException e) {
15605a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                Log.e(TAG, "Failed parsing ANQP element payload: " + infoID, e);
15615a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                return null;
15625a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            }
15635a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        }
15645a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius
15655a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        /**
15665a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * Parse the ANQP element data and add to the provided elements map if successful.
15675a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         *
15685a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param elementsMap Map to add the parsed out element to.
15695a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param infoID  Element type.
15705a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param payload Raw payload bytes.
15715a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         */
15725a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        private void addAnqpElementToMap(Map<Constants.ANQPElementType, ANQPElement> elementsMap,
15735a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                                         Constants.ANQPElementType infoID,
15745a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                                         ArrayList<Byte> payload) {
15755a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            if (payload == null || payload.isEmpty()) return;
15765a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            ANQPElement element = parseAnqpElement(infoID, payload);
15775a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            if (element != null) {
15785a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                elementsMap.put(infoID, element);
15795a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            }
15805a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        }
15815a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius
15825a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        /**
15835a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * Helper utility to convert the bssid bytes to long.
15845a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         */
15855a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        private Long toLongBssid(byte[] bssidBytes) {
15865a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            try {
15875a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                return ByteBufferReader.readInteger(
15885a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        ByteBuffer.wrap(bssidBytes), ByteOrder.BIG_ENDIAN, bssidBytes.length);
15895a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            } catch (BufferUnderflowException | IllegalArgumentException e) {
15905a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                return 0L;
15915a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            }
15925a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        }
15935a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius
1594c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1595c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onNetworkAdded(int id) {
1596c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1597c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1598c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1599c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onNetworkRemoved(int id) {
1600c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1601c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1602c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1603c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onStateChanged(int newState, byte[/* 6 */] bssid, int id,
1604c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                                   ArrayList<Byte> ssid) {
1605c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1606c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1607c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
16085a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        public void onAnqpQueryDone(byte[/* 6 */] bssid,
1609c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                                    ISupplicantStaIfaceCallback.AnqpData data,
1610c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                                    ISupplicantStaIfaceCallback.Hs20AnqpData hs20Data) {
16115a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            Map<Constants.ANQPElementType, ANQPElement> elementsMap = new HashMap<>();
16125a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, ANQPVenueName, data.venueName);
16135a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, ANQPRoamingConsortium, data.roamingConsortium);
16145a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, ANQPIPAddrAvailability, data.ipAddrTypeAvailability);
16155a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, ANQPNAIRealm, data.naiRealm);
16165a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, ANQP3GPPNetwork, data.anqp3gppCellularNetwork);
16175a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, ANQPDomName, data.domainName);
16185a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, HSFriendlyName, hs20Data.operatorFriendlyName);
16195a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, HSWANMetrics, hs20Data.wanMetrics);
16205a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, HSConnCapability, hs20Data.connectionCapability);
16215a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            addAnqpElementToMap(elementsMap, HSOSUProviders, hs20Data.osuProvidersList);
16225a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            mWifiMonitor.broadcastAnqpDoneEvent(
16235a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                    mIfaceName, new AnqpEvent(toLongBssid(bssid), elementsMap));
1624c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1625c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1626c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
16275a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        public void onHs20IconQueryDone(byte[/* 6 */] bssid, String fileName,
1628c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                                        ArrayList<Byte> data) {
16295a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            mWifiMonitor.broadcastIconDoneEvent(
16305a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                    mIfaceName,
16315a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                    new IconEvent(toLongBssid(bssid), fileName, data.size(),
16325a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                            NativeUtil.byteArrayFromArrayList(data)));
1633c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1634c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1635c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
16365a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        public void onHs20SubscriptionRemediation(byte[/* 6 */] bssid, byte osuMethod, String url) {
16375a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            mWifiMonitor.broadcastWnmEvent(
16385a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                    mIfaceName, new WnmData(toLongBssid(bssid), url, osuMethod));
1639c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1640c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1641c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
16425a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        public void onHs20DeauthImminentNotice(byte[/* 6 */] bssid, int reasonCode,
16435a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                                               int reAuthDelayInSec, String url) {
16445a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            mWifiMonitor.broadcastWnmEvent(
16455a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                    mIfaceName,
16465a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                    new WnmData(toLongBssid(bssid), url, reasonCode == WnmData.ESS,
16475a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                            reAuthDelayInSec));
1648c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1649c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1650c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1651c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onDisconnected(byte[/* 6 */] bssid, boolean locallyGenerated, int reasonCode) {
1652c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1653c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1654c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1655c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onAssociationRejected(byte[/* 6 */] bssid, int statusCode) {
1656c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1657c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1658c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1659c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onAuthenticationTimeout(byte[/* 6 */] bssid) {
1660c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1661c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1662c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1663c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onEapFailure() {
1664c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1665c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1666c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1667c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onWpsEventSuccess() {
1668c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1669c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1670c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1671c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onWpsEventFail(byte[/* 6 */] bssid, short configError, short errorInd) {
1672c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1673c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1674c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1675c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onWpsEventPbcOverlap() {
1676c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1677c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1678c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1679c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onExtRadioWorkStart(int id) {
1680c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1681c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1682c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1683c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onExtRadioWorkTimeout(int id) {
1684c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1685c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    }
1686c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
168766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    private void logd(String s) {
168866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        Log.d(TAG, s);
168966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
169066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
169166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    private void logi(String s) {
169266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        Log.i(TAG, s);
169366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
169466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
169566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    private void loge(String s) {
169666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        Log.e(TAG, s);
169766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
1698240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne}
1699