SupplicantStaIfaceHal.java revision 006eb17e06a7843e3da3bf939833b94e58a5a034
1240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne/*
298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne * Copyright (C) 2017 The Android Open Source Project
3240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne *
4240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * Licensed under the Apache License, Version 2.0 (the "License");
5240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * you may not use this file except in compliance with the License.
6240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * You may obtain a copy of the License at
7240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne *
8240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne *      http://www.apache.org/licenses/LICENSE-2.0
9240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne *
10240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * Unless required by applicable law or agreed to in writing, software
11240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * distributed under the License is distributed on an "AS IS" BASIS,
12240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * See the License for the specific language governing permissions and
14240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * limitations under the License.
15240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne */
16240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhnepackage com.android.server.wifi;
17240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
185a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.ANQP3GPPNetwork;
195a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.ANQPDomName;
205a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.ANQPIPAddrAvailability;
215a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.ANQPNAIRealm;
225a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.ANQPRoamingConsortium;
235a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.ANQPVenueName;
245a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.HSConnCapability;
255a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.HSFriendlyName;
265a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.HSOSUProviders;
275a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport static com.android.server.wifi.hotspot2.anqp.Constants.ANQPElementType.HSWANMetrics;
285a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius
29c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Piusimport android.content.Context;
30240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.hardware.wifi.supplicant.V1_0.ISupplicant;
31240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.hardware.wifi.supplicant.V1_0.ISupplicantIface;
3296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhneimport android.hardware.wifi.supplicant.V1_0.ISupplicantNetwork;
33240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.hardware.wifi.supplicant.V1_0.ISupplicantStaIface;
34c224fb554deca894818490c9416ff35d18a79d76Roshan Piusimport android.hardware.wifi.supplicant.V1_0.ISupplicantStaIfaceCallback;
3596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhneimport android.hardware.wifi.supplicant.V1_0.ISupplicantStaNetwork;
36240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.hardware.wifi.supplicant.V1_0.IfaceType;
37240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.hardware.wifi.supplicant.V1_0.SupplicantStatus;
38240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.hardware.wifi.supplicant.V1_0.SupplicantStatusCode;
395f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Piusimport android.hardware.wifi.supplicant.V1_0.WpsConfigMethods;
40240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.hidl.manager.V1_0.IServiceManager;
41240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.hidl.manager.V1_0.IServiceNotification;
42f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Piusimport android.net.IpConfiguration;
4382c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Piusimport android.net.wifi.SupplicantState;
4466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhneimport android.net.wifi.WifiConfiguration;
4582c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Piusimport android.net.wifi.WifiSsid;
46240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.os.RemoteException;
47240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport android.util.Log;
48f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Piusimport android.util.SparseArray;
4996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
505a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.AnqpEvent;
515a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.IconEvent;
525a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.WnmData;
535a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.anqp.ANQPElement;
545a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.anqp.ANQPParser;
555a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport com.android.server.wifi.hotspot2.anqp.Constants;
56d95fa596d07855b70ff18a50a48e773155a919f5Roshan Piusimport com.android.server.wifi.util.NativeUtil;
57240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
585a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport java.io.IOException;
595a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Piusimport java.nio.BufferUnderflowException;
605f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Piusimport java.nio.ByteBuffer;
615f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Piusimport java.nio.ByteOrder;
62240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhneimport java.util.ArrayList;
63f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Piusimport java.util.HashMap;
64f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Piusimport java.util.List;
65f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Piusimport java.util.Map;
665f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Piusimport java.util.regex.Matcher;
675f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Piusimport java.util.regex.Pattern;
68d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
69240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne/**
70240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * Hal calls for bring up/shut down of the supplicant daemon and for
71240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne * sending requests to the supplicant daemon
72240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne */
73b4419d876beda78c29836726e43d80203b4a656cRoshan Piuspublic class SupplicantStaIfaceHal {
74b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    private static final String TAG = "SupplicantStaIfaceHal";
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
82511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius    private boolean mVerboseLoggingEnabled = false;
8398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private IServiceManager mIServiceManager = null;
8498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    // Supplicant HAL interface objects
8598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private ISupplicant mISupplicant;
8698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private ISupplicantStaIface mISupplicantStaIface;
87b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius    private ISupplicantStaIfaceCallback mISupplicantStaIfaceCallback;
881c353f3fca322aab2fff5369a55876a91a112775Roshan Pius    private final IServiceNotification mServiceNotificationCallback =
891c353f3fca322aab2fff5369a55876a91a112775Roshan Pius            new IServiceNotification.Stub() {
901c353f3fca322aab2fff5369a55876a91a112775Roshan Pius        public void onRegistration(String fqName, String name, boolean preexisting) {
911c353f3fca322aab2fff5369a55876a91a112775Roshan Pius            synchronized (mLock) {
921c353f3fca322aab2fff5369a55876a91a112775Roshan Pius                if (mVerboseLoggingEnabled) {
931c353f3fca322aab2fff5369a55876a91a112775Roshan Pius                    Log.i(TAG, "IServiceNotification.onRegistration for: " + fqName
941c353f3fca322aab2fff5369a55876a91a112775Roshan Pius                            + ", " + name + " preexisting=" + preexisting);
951c353f3fca322aab2fff5369a55876a91a112775Roshan Pius                }
961c353f3fca322aab2fff5369a55876a91a112775Roshan Pius                if (!initSupplicantService() || !initSupplicantStaIface()) {
971c353f3fca322aab2fff5369a55876a91a112775Roshan Pius                    Log.e(TAG, "initalizing ISupplicantIfaces failed.");
981c353f3fca322aab2fff5369a55876a91a112775Roshan Pius                    supplicantServiceDiedHandler();
991c353f3fca322aab2fff5369a55876a91a112775Roshan Pius                } else {
1001c353f3fca322aab2fff5369a55876a91a112775Roshan Pius                    Log.i(TAG, "Completed initialization of ISupplicant interfaces.");
1011c353f3fca322aab2fff5369a55876a91a112775Roshan Pius                }
1021c353f3fca322aab2fff5369a55876a91a112775Roshan Pius            }
1031c353f3fca322aab2fff5369a55876a91a112775Roshan Pius        }
1041c353f3fca322aab2fff5369a55876a91a112775Roshan Pius    };
10503fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius    private String mIfaceName;
1067c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    // Currently configured network in wpa_supplicant
1077c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    private SupplicantStaNetworkHal mCurrentNetwork;
1087c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    // Currently configured network's framework network Id.
1095a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius    private int mFrameworkNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
110240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    private final Object mLock = new Object();
111c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius    private final Context mContext;
112c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius    private final WifiMonitor mWifiMonitor;
1137c0ec884188660f72977c8a80366049705c48ffaRoshan Pius
114c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius    public SupplicantStaIfaceHal(Context context, WifiMonitor monitor) {
115c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius        mContext = context;
116c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius        mWifiMonitor = monitor;
117b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius        mISupplicantStaIfaceCallback = new SupplicantStaIfaceHalCallback();
1188c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius    }
119240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
120240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    /**
121511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius     * Enable/Disable verbose logging.
122511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius     *
123511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius     * @param enable true to enable, false to disable.
124511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius     */
125511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius    void enableVerboseLogging(boolean enable) {
126511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius        mVerboseLoggingEnabled = enable;
127511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius    }
128511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius
129ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius    private boolean linkToServiceManagerDeath() {
130ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius        if (mIServiceManager == null) return false;
131ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius        try {
132ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            if (!mIServiceManager.linkToDeath(cookie -> {
133ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                Log.w(TAG, "IServiceManager died: cookie=" + cookie);
134ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                synchronized (mLock) {
135ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                    supplicantServiceDiedHandler();
136ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                    mIServiceManager = null; // Will need to register a new ServiceNotification
137ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                }
138ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            }, 0)) {
139ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                Log.wtf(TAG, "Error on linkToDeath on IServiceManager");
140ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                supplicantServiceDiedHandler();
141ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                mIServiceManager = null; // Will need to register a new ServiceNotification
142ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                return false;
143ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            }
144ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius        } catch (RemoteException e) {
145ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            Log.e(TAG, "IServiceManager.linkToDeath exception", e);
146ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            return false;
147ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius        }
148ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius        return true;
149ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius    }
150ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius
151511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius    /**
15298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     * Registers a service notification for the ISupplicant service, which triggers intialization of
15398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     * the ISupplicantStaIface
154240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne     * @return true if the service notification was successfully registered
155240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne     */
156240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    public boolean initialize() {
157511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius        if (mVerboseLoggingEnabled) Log.i(TAG, "Registering ISupplicant service ready callback.");
158240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        synchronized (mLock) {
15998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicant = null;
16098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicantStaIface = null;
16198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            if (mIServiceManager != null) {
16298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                // Already have an IServiceManager and serviceNotification registered, don't
16398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                // don't register another.
16498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                return true;
16598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            }
166240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            try {
16798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                mIServiceManager = getServiceManagerMockable();
16898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                if (mIServiceManager == null) {
169240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    Log.e(TAG, "Failed to get HIDL Service Manager");
170240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    return false;
171240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }
172ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                if (!linkToServiceManagerDeath()) {
173240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    return false;
174240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }
175240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                /* TODO(b/33639391) : Use the new ISupplicant.registerForNotifications() once it
176240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                   exists */
1771c353f3fca322aab2fff5369a55876a91a112775Roshan Pius                if (!mIServiceManager.registerForNotifications(
1781c353f3fca322aab2fff5369a55876a91a112775Roshan Pius                        ISupplicant.kInterfaceName, "", mServiceNotificationCallback)) {
179240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    Log.e(TAG, "Failed to register for notifications to "
180240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                            + ISupplicant.kInterfaceName);
18198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                    mIServiceManager = null; // Will need to register a new ServiceNotification
182240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    return false;
183240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }
184240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            } catch (RemoteException e) {
185240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "Exception while trying to register a listener for ISupplicant service: "
186240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        + e);
18798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                supplicantServiceDiedHandler();
188240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
189240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            return true;
190240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
191240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
192240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
193ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius    private boolean linkToSupplicantDeath() {
194ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius        if (mISupplicant == null) return false;
195ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius        try {
196ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            if (!mISupplicant.linkToDeath(cookie -> {
197ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                Log.w(TAG, "ISupplicant died: cookie=" + cookie);
198ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                synchronized (mLock) {
199ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                    supplicantServiceDiedHandler();
200ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                }
201ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            }, 0)) {
202ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                Log.wtf(TAG, "Error on linkToDeath on ISupplicant");
203ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                supplicantServiceDiedHandler();
204ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                return false;
205ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            }
206ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius        } catch (RemoteException e) {
207ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            Log.e(TAG, "ISupplicant.linkToDeath exception", e);
208ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            return false;
209ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius        }
210ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius        return true;
211ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius    }
212ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius
21398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private boolean initSupplicantService() {
214240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        synchronized (mLock) {
215240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            try {
21698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                mISupplicant = getSupplicantMockable();
217240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            } catch (RemoteException e) {
218240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "ISupplicant.getService exception: " + e);
219240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                return false;
220240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
22198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            if (mISupplicant == null) {
222240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "Got null ISupplicant service. Stopping supplicant HIDL startup");
223240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                return false;
224240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
225ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            if (!linkToSupplicantDeath()) {
226ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                return false;
227ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            }
228ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius        }
229ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius        return true;
230ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius    }
231ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius
232ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius    private boolean linkToSupplicantStaIfaceDeath() {
233ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius        if (mISupplicantStaIface == null) return false;
234ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius        try {
235ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            if (!mISupplicantStaIface.linkToDeath(cookie -> {
236ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                Log.w(TAG, "ISupplicantStaIface died: cookie=" + cookie);
237ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                synchronized (mLock) {
238ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                    supplicantServiceDiedHandler();
239ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                }
240ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            }, 0)) {
241ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                Log.wtf(TAG, "Error on linkToDeath on ISupplicantStaIface");
242ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                supplicantServiceDiedHandler();
243ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                return false;
244ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            }
245ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius        } catch (RemoteException e) {
246ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            Log.e(TAG, "ISupplicantStaIface.linkToDeath exception", e);
247ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            return false;
248240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
249240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        return true;
250240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
251240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
25298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private boolean initSupplicantStaIface() {
253240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        synchronized (mLock) {
254240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            /** List all supplicant Ifaces */
255240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            final ArrayList<ISupplicant.IfaceInfo> supplicantIfaces = new ArrayList<>();
256240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            try {
25798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                mISupplicant.listInterfaces((SupplicantStatus status,
258240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        ArrayList<ISupplicant.IfaceInfo> ifaces) -> {
259240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    if (status.code != SupplicantStatusCode.SUCCESS) {
260240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        Log.e(TAG, "Getting Supplicant Interfaces failed: " + status.code);
261240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        return;
262240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    }
263240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    supplicantIfaces.addAll(ifaces);
264240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                });
265240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            } catch (RemoteException e) {
266240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "ISupplicant.listInterfaces exception: " + e);
26798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                return false;
268240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
269240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            if (supplicantIfaces.size() == 0) {
270240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "Got zero HIDL supplicant ifaces. Stopping supplicant HIDL startup.");
27198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                return false;
272240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
273240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            Mutable<ISupplicantIface> supplicantIface = new Mutable<>();
27403fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius            Mutable<String> ifaceName = new Mutable<>();
275240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            for (ISupplicant.IfaceInfo ifaceInfo : supplicantIfaces) {
27698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                if (ifaceInfo.type == IfaceType.STA) {
277240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    try {
27898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                        mISupplicant.getInterface(ifaceInfo,
279240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                (SupplicantStatus status, ISupplicantIface iface) -> {
280240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                if (status.code != SupplicantStatusCode.SUCCESS) {
281240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                    Log.e(TAG, "Failed to get ISupplicantIface " + status.code);
282240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                    return;
283240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                }
284240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                supplicantIface.value = iface;
285240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                            });
286240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    } catch (RemoteException e) {
287240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        Log.e(TAG, "ISupplicant.getInterface exception: " + e);
28898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                        return false;
289240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    }
29003fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius                    ifaceName.value = ifaceInfo.name;
291240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    break;
292240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }
293240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
29498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            if (supplicantIface.value == null) {
29598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                Log.e(TAG, "initSupplicantStaIface got null iface");
296240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                return false;
297240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
29898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicantStaIface = getStaIfaceMockable(supplicantIface.value);
29903fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius            mIfaceName = ifaceName.value;
300ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            if (!linkToSupplicantStaIfaceDeath()) {
301ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius                return false;
302ca919e89a95472f2785b3ee951f9779544d19f7fRoshan Pius            }
303b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            if (!registerCallback(mISupplicantStaIfaceCallback)) {
304c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                return false;
305c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            }
306240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            return true;
307240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
308240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
309240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
31098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private void supplicantServiceDiedHandler() {
311240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        synchronized (mLock) {
31298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicant = null;
31398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicantStaIface = null;
3145317e7c11c99d5cc8417c65cc73cf548f8f52b87Roshan Pius            mWifiMonitor.broadcastSupplicantDisconnectionEvent(mIfaceName);
315240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
316240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
317240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
31898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    /**
31924250365afbd9a20b2e03364eddf2025c8f1138aRoshan Pius     * Signals whether Initialization completed successfully.
32024250365afbd9a20b2e03364eddf2025c8f1138aRoshan Pius     */
32124250365afbd9a20b2e03364eddf2025c8f1138aRoshan Pius    public boolean isInitializationStarted() {
32224250365afbd9a20b2e03364eddf2025c8f1138aRoshan Pius        return mIServiceManager != null;
32324250365afbd9a20b2e03364eddf2025c8f1138aRoshan Pius    }
32424250365afbd9a20b2e03364eddf2025c8f1138aRoshan Pius
32524250365afbd9a20b2e03364eddf2025c8f1138aRoshan Pius    /**
32624250365afbd9a20b2e03364eddf2025c8f1138aRoshan Pius     * Signals whether Initialization completed successfully.
32798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     */
32898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    public boolean isInitializationComplete() {
32998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne        return mISupplicantStaIface != null;
3308c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius    }
3318c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius
3328c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius    /**
33398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     * Wrapper functions to access static HAL methods, created to be mockable in unit tests
3348c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius     */
33598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    protected IServiceManager getServiceManagerMockable() throws RemoteException {
336006eb17e06a7843e3da3bf939833b94e58a5a034Yifan Hong        return IServiceManager.getService();
33798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    }
33898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne
33998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    protected ISupplicant getSupplicantMockable() throws RemoteException {
34098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne        return ISupplicant.getService();
34198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    }
34298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne
34398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    protected ISupplicantStaIface getStaIfaceMockable(ISupplicantIface iface) {
34498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne        return ISupplicantStaIface.asInterface(iface.asBinder());
3458c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius    }
3468c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius
34796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
3487c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * Add a network configuration to wpa_supplicant.
349d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
35066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     * @param config Config corresponding to the network.
35166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     * @return SupplicantStaNetwork of the added network in wpa_supplicant.
35266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     */
353d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    private SupplicantStaNetworkHal addNetwork(WifiConfiguration config) {
35466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        logi("addSupplicantStaNetwork via HIDL");
35566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        if (config == null) {
35666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Cannot add NULL network!");
35766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return null;
35866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
35966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        SupplicantStaNetworkHal network = addNetwork();
36066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        if (network == null) {
36166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Failed to add a network!");
36266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return null;
36366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
364f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius        if (!network.saveWifiConfiguration(config)) {
36566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Failed to save variables for: " + config.configKey());
366f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius            if (!removeAllNetworks()) {
367f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius                loge("Failed to remove all networks on failure.");
368f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius            }
36966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return null;
37066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
371f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius        return network;
37266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
37366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
37466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    /**
3757c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * Add the provided network configuration to wpa_supplicant and initiate connection to it.
3767c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * This method does the following:
3777c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 1. Triggers disconnect command to wpa_supplicant (if |shouldDisconnect| is true).
3787c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 2. Remove any existing network in wpa_supplicant.
3797c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 3. Add a new network to wpa_supplicant.
3807c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 4. Save the provided configuration to wpa_supplicant.
3817c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 5. Select the new network in wpa_supplicant.
382d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
3837c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @param config WifiConfiguration parameters for the provided network.
3847c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @param shouldDisconnect whether to trigger a disconnection or not.
3857c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @return {@code true} if it succeeds, {@code false} otherwise
38666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     */
387d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean connectToNetwork(WifiConfiguration config, boolean shouldDisconnect) {
3887c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        mFrameworkNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
3897c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        mCurrentNetwork = null;
390d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        logd("connectToNetwork " + config.configKey()
39166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                + " (shouldDisconnect " + shouldDisconnect + ")");
39266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        if (shouldDisconnect && !disconnect()) {
39366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Failed to trigger disconnect");
39466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return false;
39566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
39666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        if (!removeAllNetworks()) {
39766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Failed to remove existing networks");
39866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return false;
39966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
4007c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        mCurrentNetwork = addNetwork(config);
4017c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (mCurrentNetwork == null) {
402d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius            loge("Failed to add/save network configuration: " + config.configKey());
40366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return false;
40466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
4057c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (!mCurrentNetwork.select()) {
406d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius            loge("Failed to select network configuration: " + config.configKey());
40766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return false;
40866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
4097c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        mFrameworkNetworkId = config.networkId;
4107c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        return true;
4117c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    }
4127c0ec884188660f72977c8a80366049705c48ffaRoshan Pius
4137c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    /**
4147c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * Initiates roaming to the already configured network in wpa_supplicant. If the network
4157c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * configuration provided does not match the already configured network, then this triggers
4167c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * a new connection attempt (instead of roam).
4177c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 1. First check if we're attempting to connect to the same network as we currently have
4187c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * configured.
4197c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 2. Set the new bssid for the network in wpa_supplicant.
4207c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 3. Trigger reassociate command to wpa_supplicant.
4217c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     *
4227c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @param config WifiConfiguration parameters for the provided network.
4237c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @return {@code true} if it succeeds, {@code false} otherwise
4247c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     */
4257c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    public boolean roamToNetwork(WifiConfiguration config) {
4267c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (mFrameworkNetworkId != config.networkId || mCurrentNetwork == null) {
4277c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            Log.w(TAG, "Cannot roam to a different network, initiate new connection. "
4287c0ec884188660f72977c8a80366049705c48ffaRoshan Pius                    + "Current network ID: " + mFrameworkNetworkId);
4297c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            return connectToNetwork(config, false);
4307c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        }
4317c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        String bssid = config.getNetworkSelectionStatus().getNetworkSelectionBSSID();
4327c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        logd("roamToNetwork" + config.configKey() + " (bssid " + bssid + ")");
4337c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (!mCurrentNetwork.setBssid(bssid)) {
4347c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            loge("Failed to set new bssid on network: " + config.configKey());
4357c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            return false;
4367c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        }
4377c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (!reassociate()) {
4387c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            loge("Failed to trigger reassociate");
4397c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            return false;
4407c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        }
44166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        return true;
44266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
44366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
44466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    /**
445f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * Load all the configured networks from wpa_supplicant.
446f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     *
447f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @param configs       Map of configuration key to configuration objects corresponding to all
448f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     *                      the networks.
449f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @param networkExtras Map of extra configuration parameters stored in wpa_supplicant.conf
450f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @return true if succeeds, false otherwise.
451f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     */
452f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    public boolean loadNetworks(Map<String, WifiConfiguration> configs,
453f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                                SparseArray<Map<String, String>> networkExtras) {
454f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        List<Integer> networkIds = listNetworks();
455f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        if (networkIds == null) {
456f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            Log.e(TAG, "Failed to list networks");
457f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            return false;
458f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        }
459f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        for (Integer networkId : networkIds) {
460f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            SupplicantStaNetworkHal network = getNetwork(networkId);
461f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            if (network == null) {
462f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                Log.e(TAG, "Failed to get network with ID: " + networkId);
463f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                return false;
464f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            }
465f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            WifiConfiguration config = new WifiConfiguration();
466f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            Map<String, String> networkExtra = new HashMap<>();
467f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            if (!network.loadWifiConfiguration(config, networkExtra)) {
468f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                Log.e(TAG, "Failed to load wifi configuration for network with ID: " + networkId);
469f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                return false;
470f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            }
471f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            // Set the default IP assignments.
472f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            config.setIpAssignment(IpConfiguration.IpAssignment.DHCP);
473f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            config.setProxySettings(IpConfiguration.ProxySettings.NONE);
474f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius
475f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            networkExtras.put(networkId, networkExtra);
476f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            String configKey = networkExtra.get(SupplicantStaNetworkHal.ID_STRING_KEY_CONFIG_KEY);
477f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            final WifiConfiguration duplicateConfig = configs.put(configKey, config);
478f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            if (duplicateConfig != null) {
479f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                // The network is already known. Overwrite the duplicate entry.
480f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                Log.i(TAG, "Replacing duplicate network: " + duplicateConfig.networkId);
481f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                removeNetwork(duplicateConfig.networkId);
482f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                networkExtras.remove(duplicateConfig.networkId);
483f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            }
484f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        }
485f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        return true;
486f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    }
487f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius
488f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    /**
48966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     * Remove all networks from supplicant
49066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     */
49166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    public boolean removeAllNetworks() {
49266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        synchronized (mLock) {
49366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            ArrayList<Integer> networks = listNetworks();
49466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            if (networks == null) {
49566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                Log.e(TAG, "removeAllNetworks failed, got null networks");
49666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                return false;
49766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            }
49866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            for (int id : networks) {
49966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                if (!removeNetwork(id)) {
50066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                    Log.e(TAG, "removeAllNetworks failed to remove network: " + id);
50166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                    return false;
50266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                }
50366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            }
50466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
50566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        return true;
50666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
50766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
50866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    /**
5090a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * Set the currently configured network's bssid.
5100a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     *
5110a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * @param bssidStr Bssid to set in the form of "XX:XX:XX:XX:XX:XX"
5120a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * @return true if succeeds, false otherwise.
5130a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     */
5140a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    public boolean setCurrentNetworkBssid(String bssidStr) {
5150a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius        if (mCurrentNetwork == null) return false;
5160a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius        return mCurrentNetwork.setBssid(bssidStr);
5170a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    }
5180a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius
5190a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    /**
5200a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * Get the currently configured network's WPS NFC token.
5210a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     *
5220a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * @return Hex string corresponding to the WPS NFC token.
5230a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     */
5240a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    public String getCurrentNetworkWpsNfcConfigurationToken() {
5250a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius        if (mCurrentNetwork == null) return null;
5260a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius        return mCurrentNetwork.getWpsNfcConfigurationToken();
5270a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    }
5280a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius
5290a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    /**
5308aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap identity response for the currently configured network.
5318aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
5328aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @param identityStr String to send.
5338aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
5348aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
5358aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapIdentityResponse(String identityStr) {
5368aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
5378aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapIdentityResponse(identityStr);
5388aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
5398aad61408adef866a177857b79a979cf77a0a662Roshan Pius
5408aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
5418aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap sim gsm auth response for the currently configured network.
5428aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
5438aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @param paramsStr String to send.
5448aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
5458aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
5468aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapSimGsmAuthResponse(String paramsStr) {
5478aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
5488aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapSimGsmAuthResponse(paramsStr);
5498aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
5508aad61408adef866a177857b79a979cf77a0a662Roshan Pius
5518aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
5528aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap sim gsm auth failure for the currently configured network.
5538aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
5548aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
5558aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
5568aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapSimGsmAuthFailure() {
5578aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
5588aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapSimGsmAuthFailure();
5598aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
5608aad61408adef866a177857b79a979cf77a0a662Roshan Pius
5618aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
5628aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap sim umts auth response for the currently configured network.
5638aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
5648aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @param paramsStr String to send.
5658aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
5668aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
5678aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapSimUmtsAuthResponse(String paramsStr) {
5688aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
5698aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapSimUmtsAuthResponse(paramsStr);
5708aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
5718aad61408adef866a177857b79a979cf77a0a662Roshan Pius
5728aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
5738aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap sim umts auts response for the currently configured network.
5748aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
5758aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @param paramsStr String to send.
5768aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
5778aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
5788aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapSimUmtsAutsResponse(String paramsStr) {
5798aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
5808aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapSimUmtsAutsResponse(paramsStr);
5818aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
5828aad61408adef866a177857b79a979cf77a0a662Roshan Pius
5838aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
5848aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap sim umts auth failure for the currently configured network.
5858aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
5868aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
5878aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
5888aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapSimUmtsAuthFailure() {
5898aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
5908aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapSimUmtsAuthFailure();
5918aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
5928aad61408adef866a177857b79a979cf77a0a662Roshan Pius
5938aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
594d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Adds a new network.
595d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
59696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * @return The ISupplicantNetwork object for the new network, or null if the call fails
59796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
59896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private SupplicantStaNetworkHal addNetwork() {
59996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
60096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "addNetwork";
60196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
6023aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            Mutable<ISupplicantNetwork> newNetwork = new Mutable<>();
60396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
60496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                mISupplicantStaIface.addNetwork((SupplicantStatus status,
60596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        ISupplicantNetwork network) -> {
6063aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius                    if (checkStatusAndLogFailure(status, methodStr)) {
60796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        newNetwork.value = network;
60896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                    }
60996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                });
61096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
611b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
61296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
6133aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            if (newNetwork.value != null) {
614c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius                return getStaNetworkMockable(
615c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius                        ISupplicantStaNetwork.asInterface(newNetwork.value.asBinder()));
61696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } else {
61796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return null;
61896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
61996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
62096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
621d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
62296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
62396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Remove network from supplicant with network Id
624d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
625d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
62696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
62796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean removeNetwork(int id) {
62896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
62996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "removeNetwork";
63096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
63196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
63296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.removeNetwork(id);
63396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
63496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
635b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
63696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
63796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
63896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
63996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
640d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
64196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
642f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * Use this to mock the creation of SupplicantStaNetworkHal instance.
643f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     *
644f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @param iSupplicantStaNetwork ISupplicantStaNetwork instance retrieved from HIDL.
645f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @return The ISupplicantNetwork object for the given SupplicantNetworkId int, returns null if
646f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * the call fails
647f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     */
648f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    protected SupplicantStaNetworkHal getStaNetworkMockable(
649c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius            ISupplicantStaNetwork iSupplicantStaNetwork) {
650511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius        SupplicantStaNetworkHal network =
651511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius                new SupplicantStaNetworkHal(iSupplicantStaNetwork, mIfaceName, mContext,
652511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius                        mWifiMonitor);
653511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius        if (network != null) {
654511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius            network.enableVerboseLogging(mVerboseLoggingEnabled);
655511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius        }
656511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius        return network;
657f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    }
658f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius
659f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    /**
66096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * @return The ISupplicantNetwork object for the given SupplicantNetworkId int, returns null if
66196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * the call fails
66296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
66396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private SupplicantStaNetworkHal getNetwork(int id) {
66496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
66596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "getNetwork";
6663aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            Mutable<ISupplicantNetwork> gotNetwork = new Mutable<>();
66796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
66896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
66996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                mISupplicantStaIface.getNetwork(id, (SupplicantStatus status,
67096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        ISupplicantNetwork network) -> {
6713aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius                    if (checkStatusAndLogFailure(status, methodStr)) {
67296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        gotNetwork.value = network;
67396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                    }
67496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                });
67596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
676b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
67796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
6783aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            if (gotNetwork.value != null) {
679c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius                return getStaNetworkMockable(
680c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius                        ISupplicantStaNetwork.asInterface(gotNetwork.value.asBinder()));
68196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } else {
68296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return null;
68396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
68496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
68596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
68696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
687c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    /** See ISupplicantStaNetwork.hal for documentation */
688c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    private boolean registerCallback(ISupplicantStaIfaceCallback callback) {
689c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        synchronized (mLock) {
690c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            final String methodStr = "registerCallback";
691c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
692c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            try {
693c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                SupplicantStatus status =  mISupplicantStaIface.registerCallback(callback);
694c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                return checkStatusAndLogFailure(status, methodStr);
695c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            } catch (RemoteException e) {
696b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
697c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                return false;
698c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            }
699c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
700c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    }
701c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
70296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
70396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * @return a list of SupplicantNetworkID ints for all networks controlled by supplicant, returns
70496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * null if the call fails
70596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
70696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private java.util.ArrayList<Integer> listNetworks() {
70796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
70896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "listNetworks";
7093aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            Mutable<ArrayList<Integer>> networkIdList = new Mutable<>();
71096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
71196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
71296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                mISupplicantStaIface.listNetworks((SupplicantStatus status,
71396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        java.util.ArrayList<Integer> networkIds) -> {
7143aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius                    if (checkStatusAndLogFailure(status, methodStr)) {
71596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        networkIdList.value = networkIds;
71696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                    }
71796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                });
71896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
719b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
72096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
7213aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            return networkIdList.value;
72296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
72396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
724d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
7255f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
7265f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS device name.
7275f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
7285f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param name String to be set.
7295f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
7305f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
7315f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsDeviceName(String name) {
7327651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
7337651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsDeviceName";
7347651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
7357651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
7367651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsDeviceName(name);
7377651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
7387651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
739b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
7407651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
7417651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
7427651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
7437651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
7447651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
7455f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
7465f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS device type.
7475f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
7485f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param typeStr Type specified as a string. Used format: <categ>-<OUI>-<subcateg>
7495f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
7505f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
7515f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsDeviceType(String typeStr) {
7525f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        Matcher match = WPS_DEVICE_TYPE_PATTERN.matcher(typeStr);
7535f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        if (!match.find() || match.groupCount() != 3) {
7545f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            Log.e(TAG, "Malformed WPS device type " + typeStr);
7555f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            return false;
7565f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        }
7575f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        short categ = Short.parseShort(match.group(1));
7585f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byte[] oui = NativeUtil.hexStringToByteArray(match.group(2));
7595f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        short subCateg = Short.parseShort(match.group(3));
7605f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
7615f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byte[] bytes = new byte[8];
7625f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        ByteBuffer byteBuffer = ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN);
7635f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byteBuffer.putShort(categ);
7645f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byteBuffer.put(oui);
7655f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byteBuffer.putShort(subCateg);
7665f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return setWpsDeviceType(bytes);
7675f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
7685f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
7697651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private boolean setWpsDeviceType(byte[/* 8 */] type) {
7707651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
7717651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsDeviceType";
7727651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
7737651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
7747651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsDeviceType(type);
7757651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
7767651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
777b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
7787651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
7797651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
7807651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
7817651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
7827651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
7835f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
7845f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS manufacturer.
7855f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
7865f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param manufacturer String to be set.
7875f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
7885f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
7895f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsManufacturer(String manufacturer) {
7907651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
7917651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsManufacturer";
7927651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
7937651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
7947651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsManufacturer(manufacturer);
7957651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
7967651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
797b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
7987651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
7997651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
8007651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
8017651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
8027651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
8035f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
8045f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS model name.
8055f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
8065f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param modelName String to be set.
8075f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
8085f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
8095f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsModelName(String modelName) {
8107651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
8117651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsModelName";
8127651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
8137651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
8147651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsModelName(modelName);
8157651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
8167651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
817b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
8187651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
8197651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
8207651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
8217651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
8227651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
8235f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
8245f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS model number.
8255f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
8265f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param modelNumber String to be set.
8275f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
8285f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
8295f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsModelNumber(String modelNumber) {
8307651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
8317651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsModelNumber";
8327651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
8337651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
8347651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsModelNumber(modelNumber);
8357651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
8367651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
837b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
8387651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
8397651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
8407651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
8417651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
8427651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
8435f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
8445f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS serial number.
8455f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
8465f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param serialNumber String to be set.
8475f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
8485f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
8495f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsSerialNumber(String serialNumber) {
8507651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
8517651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsSerialNumber";
8527651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
8537651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
8547651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsSerialNumber(serialNumber);
8557651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
8567651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
857b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
8587651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
8597651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
8607651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
8617651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
8627651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
8635f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
8645f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS config methods
8655f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
8665f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param configMethodsStr List of config methods.
8675f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
8685f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
8695f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsConfigMethods(String configMethodsStr) {
8705f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        short configMethodsMask = 0;
8715f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        String[] configMethodsStrArr = configMethodsStr.split("\\s+");
8725f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        for (int i = 0; i < configMethodsStrArr.length; i++) {
8735f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            configMethodsMask |= stringToWpsConfigMethod(configMethodsStrArr[i]);
8745f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        }
8755f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return setWpsConfigMethods(configMethodsMask);
8765f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
8775f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
8787651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private boolean setWpsConfigMethods(short configMethods) {
8797651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
8807651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsConfigMethods";
8817651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
8827651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
8837651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsConfigMethods(configMethods);
8847651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
8857651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
886b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
8877651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
8887651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
8897651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
8907651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
8917651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
892d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
893d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Trigger a reassociation even if the iface is currently connected.
894d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
895d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
896d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
897d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean reassociate() {
89896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
89996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "reassociate";
90096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
90196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
90296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.reassociate();
90396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
90496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
905b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
90696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
90796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
90896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
90996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
910d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
911d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
912d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Trigger a reconnection if the iface is disconnected.
913d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
914d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
915d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
916d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean reconnect() {
91796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
91896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "reconnect";
91996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
92096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
92196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.reconnect();
92296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
92396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
924b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
92596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
92696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
92796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
92896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
929d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
930d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
931d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Trigger a disconnection from the currently connected network.
932d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
933d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
934d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
935d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean disconnect() {
93696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
93796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "disconnect";
93896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
93996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
94096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.disconnect();
94196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
94296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
943b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
94496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
94596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
94696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
94796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
948d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
949d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
950d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Enable or disable power save mode.
951d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
952d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param enable true to enable, false to disable.
953d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
954d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
955d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setPowerSave(boolean enable) {
95696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
95796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setPowerSave";
95896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
95996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
96096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.setPowerSave(enable);
96196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
96296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
963b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
96496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
96596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
96696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
96796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
968d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
969d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
970d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Initiate TDLS discover with the specified AP.
971d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
972d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param macAddress MAC Address of the AP.
973d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
974d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
975d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateTdlsDiscover(String macAddress) {
976d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateTdlsDiscover(NativeUtil.macAddressToByteArray(macAddress));
977d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
978b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
97996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateTdlsDiscover(byte[/* 6 */] macAddress) {
98096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
98196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateTdlsDiscover";
98296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
98396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
98496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateTdlsDiscover(macAddress);
98596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
98696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
987b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
98896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
98996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
99096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
99196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
992d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
993d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
994d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Initiate TDLS setup with the specified AP.
995d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
996d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param macAddress MAC Address of the AP.
997d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
998d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
999d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateTdlsSetup(String macAddress) {
1000d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateTdlsSetup(NativeUtil.macAddressToByteArray(macAddress));
1001d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
1002b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
100396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateTdlsSetup(byte[/* 6 */] macAddress) {
100496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
100596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateTdlsSetup";
100696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
100796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
100896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateTdlsSetup(macAddress);
100996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
101096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1011b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
101296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
101396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
101496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
101596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1016d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1017d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1018d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Initiate TDLS teardown with the specified AP.
1019d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param macAddress MAC Address of the AP.
1020d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1021d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1022d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateTdlsTeardown(String macAddress) {
1023d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateTdlsTeardown(NativeUtil.macAddressToByteArray(macAddress));
1024d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
1025d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1026b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
102796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateTdlsTeardown(byte[/* 6 */] macAddress) {
102896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
102996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateTdlsTeardown";
103096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
103196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
103296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateTdlsTeardown(macAddress);
103396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
103496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1035b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
103696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
103796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
103896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
103996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1040d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1041d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1042d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Request the specified ANQP elements |elements| from the specified AP |bssid|.
1043d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1044d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param bssid BSSID of the AP
1045d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param infoElements ANQP elements to be queried. Refer to ISupplicantStaIface.AnqpInfoId.
1046d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param hs20SubTypes HS subtypes to be queried. Refer to ISupplicantStaIface.Hs20AnqpSubTypes.
1047d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1048d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1049d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateAnqpQuery(String bssid, ArrayList<Short> infoElements,
1050d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius                                     ArrayList<Integer> hs20SubTypes) {
1051d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateAnqpQuery(
1052d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius                NativeUtil.macAddressToByteArray(bssid), infoElements, hs20SubTypes);
1053d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
1054d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1055b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
105696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateAnqpQuery(byte[/* 6 */] macAddress,
105796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            java.util.ArrayList<Short> infoElements, java.util.ArrayList<Integer> subTypes) {
105896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
105996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateAnqpQuery";
106096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
106196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
106296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateAnqpQuery(macAddress,
106396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        infoElements, subTypes);
106496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
106596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1066b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
106796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
106896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
106996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
107096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1071d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1072d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1073d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Request the specified ANQP ICON from the specified AP |bssid|.
1074d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1075d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param bssid BSSID of the AP
1076d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param fileName Name of the file to request.
1077d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1078d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1079d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateHs20IconQuery(String bssid, String fileName) {
1080d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateHs20IconQuery(NativeUtil.macAddressToByteArray(bssid), fileName);
1081d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
1082d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1083b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
108496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateHs20IconQuery(byte[/* 6 */] macAddress, String fileName) {
108596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
108696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateHs20IconQuery";
108796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
108896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
108996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateHs20IconQuery(macAddress,
109096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        fileName);
109196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
109296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1093b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
109496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
109596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
109696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
109796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1098d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
109996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
110096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Makes a callback to HIDL to getMacAddress from supplicant
1101d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
110296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * @return string containing the MAC address, or null on a failed call
110396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
1104d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public String getMacAddress() {
110596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
110696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "getMacAddress";
110796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
110896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            Mutable<String> gotMac = new Mutable<>();
110996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
111096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                mISupplicantStaIface.getMacAddress((SupplicantStatus status,
111196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        byte[/* 6 */] macAddr) -> {
11123aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius                    if (checkStatusAndLogFailure(status, methodStr)) {
1113d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius                        gotMac.value = NativeUtil.macAddressFromByteArray(macAddr);
111496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                    }
111596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                });
111696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1117b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
111896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
11193aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            return gotMac.value;
112096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
112196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1122d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1123d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1124d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Start using the added RX filters.
1125d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1126d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1127d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1128d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean startRxFilter() {
112996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
113096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "startRxFilter";
113196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
113296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
113396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.startRxFilter();
113496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
113596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1136b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
113796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
113896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
113996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
114096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1141d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1142d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1143d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Stop using the added RX filters.
1144d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1145d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1146d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1147d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean stopRxFilter() {
114896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
114996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "stopRxFilter";
115096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
115196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
115296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.stopRxFilter();
115396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
115496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1155b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
115696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
115796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
115896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
115996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1160d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1161d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte RX_FILTER_TYPE_V4_MULTICAST =
1162d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius            ISupplicantStaIface.RxFilterType.V6_MULTICAST;
1163d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte RX_FILTER_TYPE_V6_MULTICAST =
1164d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius            ISupplicantStaIface.RxFilterType.V6_MULTICAST;
1165d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1166d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Add an RX filter.
1167d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1168d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param type one of {@link #RX_FILTER_TYPE_V4_MULTICAST} or
1169d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *        {@link #RX_FILTER_TYPE_V6_MULTICAST} values.
1170d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1171d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1172f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius    public boolean addRxFilter(byte type) {
117396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
117496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "addRxFilter";
117596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
117696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
117796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.addRxFilter(type);
117896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
117996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1180b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
118196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
118296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
118396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
118496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1185d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1186d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1187d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Remove an RX filter.
1188d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1189d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param type one of {@link #RX_FILTER_TYPE_V4_MULTICAST} or
1190d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *        {@link #RX_FILTER_TYPE_V6_MULTICAST} values.
1191d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1192d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1193f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius    public boolean removeRxFilter(byte type) {
119496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
119596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "removeRxFilter";
119696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
119796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
119896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.removeRxFilter(type);
119996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
120096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1201b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
120296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
120396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
120496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
120596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1206d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1207d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte BT_COEX_MODE_ENABLED = ISupplicantStaIface.BtCoexistenceMode.ENABLED;
1208d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte BT_COEX_MODE_DISABLED = ISupplicantStaIface.BtCoexistenceMode.DISABLED;
1209d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte BT_COEX_MODE_SENSE = ISupplicantStaIface.BtCoexistenceMode.SENSE;
1210d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1211d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Set Bt co existense mode.
1212d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1213d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param mode one of the above {@link #BT_COEX_MODE_ENABLED}, {@link #BT_COEX_MODE_DISABLED}
1214d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *             or {@link #BT_COEX_MODE_SENSE} values.
1215d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1216d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1217d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setBtCoexistenceMode(byte mode) {
121896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
121996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setBtCoexistenceMode";
122096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
122196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
122296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.setBtCoexistenceMode(mode);
122396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
122496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1225b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
122696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
122796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
122896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
122996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1230d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1231d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /** Enable or disable BT coexistence mode.
1232d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1233d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param enable true to enable, false to disable.
1234d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1235d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1236d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setBtCoexistenceScanModeEnabled(boolean enable) {
123796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
123896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setBtCoexistenceScanModeEnabled";
123996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
124096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
124196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status =
124296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        mISupplicantStaIface.setBtCoexistenceScanModeEnabled(enable);
124396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
124496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1245b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
124696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
124796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
124896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
124996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1250d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1251d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1252d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Enable or disable suspend mode optimizations.
1253d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1254d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param enable true to enable, false otherwise.
12555f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
1256d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1257d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setSuspendModeEnabled(boolean enable) {
125896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
125996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setSuspendModeEnabled";
126096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
126196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
126296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.setSuspendModeEnabled(enable);
126396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
126496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1265b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
126696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
126796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
126896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
126996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1270d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1271d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1272d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Set country code.
1273d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1274d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param codeStr 2 byte ASCII string. For ex: US, CA.
1275d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1276d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1277d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setCountryCode(String codeStr) {
1278d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return setCountryCode(NativeUtil.stringToByteArray(codeStr));
1279d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
1280d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1281b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
128296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean setCountryCode(byte[/* 2 */] code) {
128396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
128496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setCountryCode";
128596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
128696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
128796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.setCountryCode(code);
128896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
128996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1290b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
129196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
129296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
129396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
129496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
129596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
12965f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
12975f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Start WPS pin registrar operation with the specified peer and pin.
12985f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
12995f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param bssidStr BSSID of the peer.
13005f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param pin Pin to be used.
13015f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
13025f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
13035f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean startWpsRegistrar(String bssidStr, String pin) {
13045f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return startWpsRegistrar(NativeUtil.macAddressToByteArray(bssidStr), pin);
13055f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
13065f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
13077651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
13087651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private boolean startWpsRegistrar(byte[/* 6 */] bssid, String pin) {
13097651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
13107651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "startWpsRegistrar";
13117651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
13127651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
13137651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.startWpsRegistrar(bssid, pin);
13147651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
13157651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1316b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
13177651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
13187651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
13197651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
13207651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
13217651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
13225f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
13235f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Start WPS pin display operation with the specified peer.
13245f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
13255f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param bssidStr BSSID of the peer.
13265f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
13275f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
13285f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean startWpsPbc(String bssidStr) {
13295f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return startWpsPbc(NativeUtil.macAddressToByteArray(bssidStr));
13305f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
13315f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
13327651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
13337651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private boolean startWpsPbc(byte[/* 6 */] bssid) {
13347651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
13357651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "startWpsPbc";
13367651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
13377651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
13387651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.startWpsPbc(bssid);
13397651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
13407651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1341b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
13427651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
13437651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
13447651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
13457651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
13467651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
13475f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
13485f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Start WPS pin keypad operation with the specified pin.
13495f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
13505f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param pin Pin to be used.
13515f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
13525f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
13535f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean startWpsPinKeypad(String pin) {
13547651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
13557651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "startWpsPinKeypad";
13567651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
13577651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
13587651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.startWpsPinKeypad(pin);
13597651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
13607651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1361b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
13627651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
13637651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
13647651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
13657651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
13667651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
13675f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
13685f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Start WPS pin display operation with the specified peer.
13695f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
13705f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param bssidStr BSSID of the peer.
13715f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return new pin generated on success, null otherwise.
13725f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
13735f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public String startWpsPinDisplay(String bssidStr) {
13745f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return startWpsPinDisplay(NativeUtil.macAddressToByteArray(bssidStr));
13755f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
13765f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
13777651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
13787651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private String startWpsPinDisplay(byte[/* 6 */] bssid) {
13797651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
13807651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "startWpsPinDisplay";
13817651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
13827651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final Mutable<String> gotPin = new Mutable<>();
13837651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
13847651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                mISupplicantStaIface.startWpsPinDisplay(bssid,
13857651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                        (SupplicantStatus status, String pin) -> {
13867651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                            if (checkStatusAndLogFailure(status, methodStr)) {
13877651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                                gotPin.value = pin;
13887651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                            }
13897651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                        });
13907651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1391b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
13927651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
13937651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            return gotPin.value;
13947651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
13957651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
13967651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
13975f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
13985f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Cancels any ongoing WPS requests.
13995f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
14005f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
14015f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
14025f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean cancelWps() {
14037651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
14047651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "cancelWps";
14057651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
14067651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
14077651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.cancelWps();
14087651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
14097651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1410b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
14117651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
14127651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
14137651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
14147651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
14157651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
14165f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
14175f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Sets whether to use external sim for SIM/USIM processing.
14185f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
14195f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param useExternalSim true to enable, false otherwise.
14205f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
14215f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
14225f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setExternalSim(boolean useExternalSim) {
14237651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
14247651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setExternalSim";
14257651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
14267651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
14277651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setExternalSim(useExternalSim);
14287651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
14297651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1430b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
14317651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
14327651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
14337651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
14347651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
14357651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
1436cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_EXCESSIVE = ISupplicant.DebugLevel.EXCESSIVE;
1437cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_MSGDUMP = ISupplicant.DebugLevel.MSGDUMP;
1438cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_DEBUG = ISupplicant.DebugLevel.DEBUG;
1439cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_INFO = ISupplicant.DebugLevel.INFO;
1440cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_WARNING = ISupplicant.DebugLevel.WARNING;
1441cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_ERROR = ISupplicant.DebugLevel.ERROR;
1442cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /**
1443cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * Set the debug log level for wpa_supplicant
1444cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * @param level One of the above {@link #LOG_LEVEL_EXCESSIVE} - {@link #LOG_LEVEL_ERROR} value.
1445cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * @return true if request is sent successfully, false otherwise.
1446cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     */
1447cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public boolean setLogLevel(int level) {
1448cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        return setDebugParams(level, false, false);
1449cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1450cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
1451cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /** See ISupplicant.hal for documentation */
1452cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    private boolean setDebugParams(int level, boolean showTimestamp, boolean showKeys) {
1453cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        synchronized (mLock) {
1454cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            final String methodStr = "setDebugParams";
1455cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            if (!checkSupplicantAndLogFailure(methodStr)) return false;
1456cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            try {
1457cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                SupplicantStatus status =
1458cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                        mISupplicant.setDebugParams(level, showTimestamp, showKeys);
1459cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                return checkStatusAndLogFailure(status, methodStr);
1460cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            } catch (RemoteException e) {
1461b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
1462cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                return false;
1463cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            }
1464cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        }
1465cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1466cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
1467cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /**
1468cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * Set concurrency priority between P2P & STA operations.
1469cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     *
1470cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * @param isStaHigherPriority Set to true to prefer STA over P2P during concurrency operations,
1471cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     *                            false otherwise.
1472cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * @return true if request is sent successfully, false otherwise.
1473cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     */
1474cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public boolean setConcurrencyPriority(boolean isStaHigherPriority) {
1475cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        if (isStaHigherPriority) {
1476cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            return setConcurrencyPriority(IfaceType.STA);
1477cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        } else {
1478cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            return setConcurrencyPriority(IfaceType.P2P);
1479cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        }
1480cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1481cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
1482cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /** See ISupplicant.hal for documentation */
1483cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    private boolean setConcurrencyPriority(int type) {
1484cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        synchronized (mLock) {
1485cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            final String methodStr = "setConcurrencyPriority";
1486cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            if (!checkSupplicantAndLogFailure(methodStr)) return false;
1487cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            try {
1488cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                SupplicantStatus status = mISupplicant.setConcurrencyPriority(type);
1489cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                return checkStatusAndLogFailure(status, methodStr);
1490cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            } catch (RemoteException e) {
1491b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
1492cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                return false;
1493cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            }
1494cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        }
1495cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1496cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
1497cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /**
1498cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * Returns false if Supplicant is null, and logs failure to call methodStr
1499cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     */
1500cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    private boolean checkSupplicantAndLogFailure(final String methodStr) {
1501cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        if (mISupplicant == null) {
1502cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            Log.e(TAG, "Can't call " + methodStr + ", ISupplicant is null");
1503cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            return false;
1504cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        }
1505cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        return true;
1506cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1507cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
150896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
150996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Returns false if SupplicantStaIface is null, and logs failure to call methodStr
151096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
151196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean checkSupplicantStaIfaceAndLogFailure(final String methodStr) {
151296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        if (mISupplicantStaIface == null) {
151396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            Log.e(TAG, "Can't call " + methodStr + ", ISupplicantStaIface is null");
151496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            return false;
151596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
151696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        return true;
151796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
151896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
151996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
152096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Returns true if provided status code is SUCCESS, logs debug message and returns false
152196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * otherwise
152296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
1523511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius    private boolean checkStatusAndLogFailure(SupplicantStatus status,
152496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr) {
152596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        if (status.code != SupplicantStatusCode.SUCCESS) {
1526b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius            Log.e(TAG, "ISupplicantStaIface." + methodStr + " failed: "
1527b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                    + supplicantStatusCodeToString(status.code) + ", " + status.debugMessage);
152896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            return false;
1529b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius        } else {
1530511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius            if (mVerboseLoggingEnabled) {
1531b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                Log.d(TAG, "ISupplicantStaIface." + methodStr + " succeeded");
1532511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius            }
1533b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius            return true;
153496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
1535b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius    }
1536b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius
1537b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius    /**
1538b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius     * Helper function to log callbacks.
1539b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius     */
1540b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius    private void logCallback(final String methodStr) {
1541b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius        if (mVerboseLoggingEnabled) {
1542b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            Log.d(TAG, "ISupplicantStaIfaceCallback." + methodStr + " received");
1543b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius        }
1544b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius    }
1545b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius
1546b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius
1547b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius    private void handleRemoteException(RemoteException e, String methodStr) {
1548b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius        supplicantServiceDiedHandler();
1549b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius        Log.e(TAG, "ISupplicantStaIface." + methodStr + " failed with exception", e);
155096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
155196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
155296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
155396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Converts SupplicantStatus code values to strings for debug logging
155496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * TODO(b/34811152) Remove this, or make it more break resistance
155596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
155696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    public static String supplicantStatusCodeToString(int code) {
155796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        switch (code) {
155896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 0:
155996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "SUCCESS";
156096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 1:
156196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_UNKNOWN";
156296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 2:
156396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_ARGS_INVALID";
156496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 3:
156596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_INVALID";
156696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 4:
156796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_UNKNOWN";
156896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 5:
156996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_EXISTS";
157096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 6:
157196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_DISABLED";
157296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 7:
157396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_NOT_DISCONNECTED";
157496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 8:
157596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_NETWORK_INVALID";
157696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 9:
157796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_NETWORK_UNKNOWN";
157896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            default:
157996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "??? UNKNOWN_CODE";
158096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
158196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
158296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
15835f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
15845f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
15855f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Converts the Wps config method string to the equivalent enum value.
15865f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
15875f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    private static short stringToWpsConfigMethod(String configMethod) {
15885f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        switch (configMethod) {
15895f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "usba":
15905f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.USBA;
15915f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "ethernet":
15925f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.ETHERNET;
15935f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "label":
15945f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.LABEL;
15955f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "display":
15965f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.DISPLAY;
15975f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "int_nfc_token":
15985f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.INT_NFC_TOKEN;
15995f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "ext_nfc_token":
16005f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.EXT_NFC_TOKEN;
16015f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "nfc_interface":
16025f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.NFC_INTERFACE;
16035f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "push_button":
16045f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.PUSHBUTTON;
16055f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "keypad":
16065f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.KEYPAD;
16075f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "virtual_push_button":
16085f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.VIRT_PUSHBUTTON;
16095f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "physical_push_button":
16105f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.PHY_PUSHBUTTON;
16115f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "p2ps":
16125f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.P2PS;
16135f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "virtual_display":
16145f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.VIRT_DISPLAY;
16155f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "physical_display":
16165f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.PHY_DISPLAY;
16175f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            default:
16185f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                throw new IllegalArgumentException(
16195f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                        "Invalid WPS config method: " + configMethod);
16205f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        }
16215f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
16225f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
162382c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius    /**
162482c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius     * Converts the supplicant state received from HIDL to the equivalent framework state.
162582c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius     */
162682c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius    private static SupplicantState supplicantHidlStateToFrameworkState(int state) {
162782c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius        switch (state) {
162882c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.DISCONNECTED:
162982c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.DISCONNECTED;
163082c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.IFACE_DISABLED:
163182c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.INTERFACE_DISABLED;
163282c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.INACTIVE:
163382c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.INACTIVE;
163482c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.SCANNING:
163582c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.SCANNING;
163682c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.AUTHENTICATING:
163782c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.AUTHENTICATING;
163882c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.ASSOCIATING:
163982c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.ASSOCIATING;
164082c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.ASSOCIATED:
164182c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.ASSOCIATED;
164282c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.FOURWAY_HANDSHAKE:
164382c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.FOUR_WAY_HANDSHAKE;
164482c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.GROUP_HANDSHAKE:
164582c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.GROUP_HANDSHAKE;
164682c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.COMPLETED:
164782c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.COMPLETED;
164882c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            default:
164982c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                throw new IllegalArgumentException("Invalid state: " + state);
165082c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius        }
165182c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius    }
165282c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius
1653240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    private static class Mutable<E> {
1654240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        public E value;
1655240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
1656240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        Mutable() {
1657240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            value = null;
1658240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
1659240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
1660240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        Mutable(E value) {
1661240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            this.value = value;
1662240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
1663240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
166466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
1665c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    private class SupplicantStaIfaceHalCallback extends ISupplicantStaIfaceCallback.Stub {
16665a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        /**
16675a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * Parses the provided payload into an ANQP element.
16685a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         *
16695a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param infoID  Element type.
16705a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param payload Raw payload bytes.
16715a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @return AnqpElement instance on success, null on failure.
16725a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         */
16735a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        private ANQPElement parseAnqpElement(Constants.ANQPElementType infoID,
16745a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                                             ArrayList<Byte> payload) {
16755a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            try {
16765a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                return Constants.getANQPElementID(infoID) != null
16775a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        ? ANQPParser.parseElement(
16785a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        infoID, ByteBuffer.wrap(NativeUtil.byteArrayFromArrayList(payload)))
16795a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        : ANQPParser.parseHS20Element(
16805a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        infoID, ByteBuffer.wrap(NativeUtil.byteArrayFromArrayList(payload)));
16815a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            } catch (IOException | BufferUnderflowException e) {
16825a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                Log.e(TAG, "Failed parsing ANQP element payload: " + infoID, e);
16835a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                return null;
16845a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            }
16855a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        }
16865a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius
16875a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        /**
16885a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * Parse the ANQP element data and add to the provided elements map if successful.
16895a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         *
16905a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param elementsMap Map to add the parsed out element to.
16915a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param infoID  Element type.
16925a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param payload Raw payload bytes.
16935a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         */
16945a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        private void addAnqpElementToMap(Map<Constants.ANQPElementType, ANQPElement> elementsMap,
16955a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                                         Constants.ANQPElementType infoID,
16965a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                                         ArrayList<Byte> payload) {
16975a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            if (payload == null || payload.isEmpty()) return;
16985a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            ANQPElement element = parseAnqpElement(infoID, payload);
16995a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            if (element != null) {
17005a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                elementsMap.put(infoID, element);
17015a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            }
17025a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        }
17035a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius
17045a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        /**
17055a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * Helper utility to convert the bssid bytes to long.
17065a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         */
17075a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        private Long toLongBssid(byte[] bssidBytes) {
17085a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            try {
17095a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                return ByteBufferReader.readInteger(
17105a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        ByteBuffer.wrap(bssidBytes), ByteOrder.BIG_ENDIAN, bssidBytes.length);
17115a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            } catch (BufferUnderflowException | IllegalArgumentException e) {
17125a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                return 0L;
17135a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            }
17145a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        }
17155a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius
1716c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1717c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onNetworkAdded(int id) {
1718b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onNetworkAdded");
1719c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1720c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1721c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1722c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onNetworkRemoved(int id) {
1723b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onNetworkRemoved");
1724c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1725c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1726c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1727c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onStateChanged(int newState, byte[/* 6 */] bssid, int id,
1728c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                                   ArrayList<Byte> ssid) {
1729b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onStateChanged");
1730b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1731b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                SupplicantState newSupplicantState = supplicantHidlStateToFrameworkState(newState);
1732b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                WifiSsid wifiSsid =
1733b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        WifiSsid.createFromByteArray(NativeUtil.byteArrayFromArrayList(ssid));
1734b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                String bssidStr = NativeUtil.macAddressFromByteArray(bssid);
1735b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastSupplicantStateChangeEvent(
1736b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        mIfaceName, mFrameworkNetworkId, wifiSsid, bssidStr, newSupplicantState);
1737b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                if (newSupplicantState == SupplicantState.ASSOCIATED) {
1738b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                    mWifiMonitor.broadcastAssociationSuccesfulEvent(mIfaceName, bssidStr);
1739b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                } else if (newSupplicantState == SupplicantState.COMPLETED) {
1740b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                    mWifiMonitor.broadcastNetworkConnectionEvent(
1741b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                            mIfaceName, mFrameworkNetworkId, bssidStr);
1742b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                }
174382c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            }
1744c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1745c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1746c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
17475a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        public void onAnqpQueryDone(byte[/* 6 */] bssid,
1748c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                                    ISupplicantStaIfaceCallback.AnqpData data,
1749c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                                    ISupplicantStaIfaceCallback.Hs20AnqpData hs20Data) {
1750b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onAnqpQueryDone");
1751b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1752b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                Map<Constants.ANQPElementType, ANQPElement> elementsMap = new HashMap<>();
1753b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, ANQPVenueName, data.venueName);
1754b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, ANQPRoamingConsortium, data.roamingConsortium);
1755b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(
1756b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        elementsMap, ANQPIPAddrAvailability, data.ipAddrTypeAvailability);
1757b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, ANQPNAIRealm, data.naiRealm);
1758b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, ANQP3GPPNetwork, data.anqp3gppCellularNetwork);
1759b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, ANQPDomName, data.domainName);
1760b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, HSFriendlyName, hs20Data.operatorFriendlyName);
1761b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, HSWANMetrics, hs20Data.wanMetrics);
1762b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, HSConnCapability, hs20Data.connectionCapability);
1763b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, HSOSUProviders, hs20Data.osuProvidersList);
1764b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastAnqpDoneEvent(
1765b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        mIfaceName, new AnqpEvent(toLongBssid(bssid), elementsMap));
1766b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1767c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1768c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1769c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
17705a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        public void onHs20IconQueryDone(byte[/* 6 */] bssid, String fileName,
1771c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                                        ArrayList<Byte> data) {
1772b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onHs20IconQueryDone");
1773b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1774b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastIconDoneEvent(
1775b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        mIfaceName,
1776b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        new IconEvent(toLongBssid(bssid), fileName, data.size(),
1777b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                                NativeUtil.byteArrayFromArrayList(data)));
1778b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1779c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1780c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1781c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
17825a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        public void onHs20SubscriptionRemediation(byte[/* 6 */] bssid, byte osuMethod, String url) {
1783b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onHs20SubscriptionRemediation");
1784b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1785b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastWnmEvent(
1786b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        mIfaceName, new WnmData(toLongBssid(bssid), url, osuMethod));
1787b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1788c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1789c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1790c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
17915a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        public void onHs20DeauthImminentNotice(byte[/* 6 */] bssid, int reasonCode,
17925a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                                               int reAuthDelayInSec, String url) {
1793b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onHs20DeauthImminentNotice");
1794b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1795b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastWnmEvent(
1796b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        mIfaceName,
1797b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        new WnmData(toLongBssid(bssid), url, reasonCode == WnmData.ESS,
1798b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                                reAuthDelayInSec));
1799b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1800c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1801c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1802c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1803c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onDisconnected(byte[/* 6 */] bssid, boolean locallyGenerated, int reasonCode) {
1804b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onDisconnected");
1805b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1806b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastNetworkDisconnectionEvent(
1807b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        mIfaceName, locallyGenerated ? 1 : 0, reasonCode,
1808b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        NativeUtil.macAddressFromByteArray(bssid));
1809b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1810c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1811c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1812c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1813c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onAssociationRejected(byte[/* 6 */] bssid, int statusCode) {
1814b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onAssociationRejected");
1815b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1816b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                // TODO(b/35464954): Need to figure out when to trigger
1817b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                // |WifiMonitor.AUTHENTICATION_FAILURE_REASON_WRONG_PSWD|
1818b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastAssociationRejectionEvent(mIfaceName, statusCode,
1819b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        NativeUtil.macAddressFromByteArray(bssid));
1820b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1821c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1822c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1823c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1824c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onAuthenticationTimeout(byte[/* 6 */] bssid) {
1825b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onAuthenticationTimeout");
1826b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1827b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastAuthenticationFailureEvent(
1828b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        mIfaceName, WifiMonitor.AUTHENTICATION_FAILURE_REASON_TIMEOUT);
1829b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1830c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1831c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1832c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1833c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onEapFailure() {
1834b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onEapFailure");
1835b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1836b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastAuthenticationFailureEvent(
1837b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        mIfaceName, WifiMonitor.AUTHENTICATION_FAILURE_REASON_EAP_FAILURE);
1838b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1839c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1840c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1841c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1842c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onWpsEventSuccess() {
1843b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onWpsEventSuccess");
1844b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1845b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastWpsSuccessEvent(mIfaceName);
1846b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1847c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1848c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1849c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1850c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onWpsEventFail(byte[/* 6 */] bssid, short configError, short errorInd) {
1851b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onWpsEventFail");
1852b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1853b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                if (configError == WpsConfigError.MSG_TIMEOUT
1854b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        && errorInd == WpsErrorIndication.NO_ERROR) {
1855b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                    mWifiMonitor.broadcastWpsTimeoutEvent(mIfaceName);
1856b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                } else {
1857b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                    mWifiMonitor.broadcastWpsFailEvent(mIfaceName, configError, errorInd);
1858b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                }
1859bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius            }
1860c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1861c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1862c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1863c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onWpsEventPbcOverlap() {
1864b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onWpsEventPbcOverlap");
1865b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1866b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastWpsOverlapEvent(mIfaceName);
1867b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1868c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1869c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1870c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1871c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onExtRadioWorkStart(int id) {
1872b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onExtRadioWorkStart");
1873c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1874c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1875c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1876c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onExtRadioWorkTimeout(int id) {
1877b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onExtRadioWorkTimeout");
1878c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1879c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    }
1880c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
188166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    private void logd(String s) {
188266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        Log.d(TAG, s);
188366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
188466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
188566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    private void logi(String s) {
188666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        Log.i(TAG, s);
188766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
188866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
188966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    private void loge(String s) {
189066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        Log.e(TAG, s);
189166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
1892240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne}
1893