SupplicantStaIfaceHal.java revision 24250365afbd9a20b2e03364eddf2025c8f1138a
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";
7598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private static final String SERVICE_MANAGER_NAME = "manager";
765f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
775f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Regex pattern for extracting the wps device type bytes.
785f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Matches a strings like the following: "<categ>-<OUI>-<subcateg>";
795f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
805f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    private static final Pattern WPS_DEVICE_TYPE_PATTERN =
815f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            Pattern.compile("^(\\d{1,2})-([0-9a-fA-F]{8})-(\\d{1,2})$");
825f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
83511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius    private boolean mVerboseLoggingEnabled = false;
8498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private IServiceManager mIServiceManager = null;
8598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    // Supplicant HAL interface objects
8698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private ISupplicant mISupplicant;
8798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private ISupplicantStaIface mISupplicantStaIface;
88b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius    private ISupplicantStaIfaceCallback mISupplicantStaIfaceCallback;
8903fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius    private String mIfaceName;
907c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    // Currently configured network in wpa_supplicant
917c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    private SupplicantStaNetworkHal mCurrentNetwork;
927c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    // Currently configured network's framework network Id.
935a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius    private int mFrameworkNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
94240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    private final Object mLock = new Object();
95c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius    private final Context mContext;
96c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius    private final WifiMonitor mWifiMonitor;
977c0ec884188660f72977c8a80366049705c48ffaRoshan Pius
98c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius    public SupplicantStaIfaceHal(Context context, WifiMonitor monitor) {
99c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius        mContext = context;
100c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius        mWifiMonitor = monitor;
101b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius        mISupplicantStaIfaceCallback = new SupplicantStaIfaceHalCallback();
1028c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius    }
103240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
104240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    /**
105511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius     * Enable/Disable verbose logging.
106511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius     *
107511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius     * @param enable true to enable, false to disable.
108511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius     */
109511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius    void enableVerboseLogging(boolean enable) {
110511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius        mVerboseLoggingEnabled = enable;
111511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius    }
112511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius
113511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius    /**
11498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     * Registers a service notification for the ISupplicant service, which triggers intialization of
11598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     * the ISupplicantStaIface
116240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne     * @return true if the service notification was successfully registered
117240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne     */
118240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    public boolean initialize() {
119511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius        if (mVerboseLoggingEnabled) Log.i(TAG, "Registering ISupplicant service ready callback.");
120240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        synchronized (mLock) {
12198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicant = null;
12298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicantStaIface = null;
12398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            if (mIServiceManager != null) {
12498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                // Already have an IServiceManager and serviceNotification registered, don't
12598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                // don't register another.
12698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                return true;
12798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            }
128240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            try {
12998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                mIServiceManager = getServiceManagerMockable();
13098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                if (mIServiceManager == null) {
131240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    Log.e(TAG, "Failed to get HIDL Service Manager");
132240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    return false;
133240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }
13498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                if (!mIServiceManager.linkToDeath(cookie -> {
135240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    Log.wtf(TAG, "IServiceManager died: cookie=" + cookie);
136240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    synchronized (mLock) {
137240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        supplicantServiceDiedHandler();
13898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                        mIServiceManager = null; // Will need to register a new ServiceNotification
139240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    }
140240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }, 0)) {
141240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    Log.wtf(TAG, "Error on linkToDeath on IServiceManager");
142240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    supplicantServiceDiedHandler();
14398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                    mIServiceManager = null; // Will need to register a new ServiceNotification
144240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    return false;
145240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }
146240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                IServiceNotification serviceNotificationCb = new IServiceNotification.Stub() {
147240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    public void onRegistration(String fqName, String name, boolean preexisting) {
14898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                        synchronized (mLock) {
149511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius                            if (mVerboseLoggingEnabled) {
15098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                                Log.i(TAG, "IServiceNotification.onRegistration for: " + fqName
15198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                                        + ", " + name + " preexisting=" + preexisting);
15298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                            }
15398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                            if (!initSupplicantService() || !initSupplicantStaIface()) {
15498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                                Log.e(TAG, "initalizing ISupplicantIfaces failed.");
15598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                                supplicantServiceDiedHandler();
15698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                            } else {
15798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                                Log.i(TAG, "Completed initialization of ISupplicant interfaces.");
15898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                            }
159240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        }
160240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    }
161240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                };
162240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                /* TODO(b/33639391) : Use the new ISupplicant.registerForNotifications() once it
163240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                   exists */
16498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                if (!mIServiceManager.registerForNotifications(ISupplicant.kInterfaceName,
165240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        "", serviceNotificationCb)) {
166240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    Log.e(TAG, "Failed to register for notifications to "
167240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                            + ISupplicant.kInterfaceName);
16898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                    mIServiceManager = null; // Will need to register a new ServiceNotification
169240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    return false;
170240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }
171240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            } catch (RemoteException e) {
172240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "Exception while trying to register a listener for ISupplicant service: "
173240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        + e);
17498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                supplicantServiceDiedHandler();
175240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
176240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            return true;
177240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
178240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
179240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
18098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private boolean initSupplicantService() {
181240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        synchronized (mLock) {
182240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            try {
18398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                mISupplicant = getSupplicantMockable();
184240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            } catch (RemoteException e) {
185240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "ISupplicant.getService exception: " + e);
186240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                return false;
187240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
18898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            if (mISupplicant == null) {
189240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "Got null ISupplicant service. Stopping supplicant HIDL startup");
190240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                return false;
191240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
192240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
193240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        return true;
194240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
195240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
19698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private boolean initSupplicantStaIface() {
197240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        synchronized (mLock) {
198240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            /** List all supplicant Ifaces */
199240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            final ArrayList<ISupplicant.IfaceInfo> supplicantIfaces = new ArrayList<>();
200240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            try {
20198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                mISupplicant.listInterfaces((SupplicantStatus status,
202240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        ArrayList<ISupplicant.IfaceInfo> ifaces) -> {
203240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    if (status.code != SupplicantStatusCode.SUCCESS) {
204240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        Log.e(TAG, "Getting Supplicant Interfaces failed: " + status.code);
205240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        return;
206240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    }
207240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    supplicantIfaces.addAll(ifaces);
208240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                });
209240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            } catch (RemoteException e) {
210240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "ISupplicant.listInterfaces exception: " + e);
21198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                return false;
212240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
213240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            if (supplicantIfaces.size() == 0) {
214240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                Log.e(TAG, "Got zero HIDL supplicant ifaces. Stopping supplicant HIDL startup.");
21598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                return false;
216240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
217240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            Mutable<ISupplicantIface> supplicantIface = new Mutable<>();
21803fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius            Mutable<String> ifaceName = new Mutable<>();
219240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            for (ISupplicant.IfaceInfo ifaceInfo : supplicantIfaces) {
22098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                if (ifaceInfo.type == IfaceType.STA) {
221240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    try {
22298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                        mISupplicant.getInterface(ifaceInfo,
223240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                (SupplicantStatus status, ISupplicantIface iface) -> {
224240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                if (status.code != SupplicantStatusCode.SUCCESS) {
225240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                    Log.e(TAG, "Failed to get ISupplicantIface " + status.code);
226240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                    return;
227240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                }
228240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                                supplicantIface.value = iface;
229240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                            });
230240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    } catch (RemoteException e) {
231240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                        Log.e(TAG, "ISupplicant.getInterface exception: " + e);
23298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                        return false;
233240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    }
23403fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius                    ifaceName.value = ifaceInfo.name;
235240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                    break;
236240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                }
237240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
23898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            if (supplicantIface.value == null) {
23998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne                Log.e(TAG, "initSupplicantStaIface got null iface");
240240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne                return false;
241240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            }
24298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicantStaIface = getStaIfaceMockable(supplicantIface.value);
24303fea88ccab149c07391d38f3c406bb04ab0a3a9Roshan Pius            mIfaceName = ifaceName.value;
244b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            if (!registerCallback(mISupplicantStaIfaceCallback)) {
245c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                return false;
246c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            }
247240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            return true;
248240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
249240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
250240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
25198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    private void supplicantServiceDiedHandler() {
252240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        synchronized (mLock) {
25398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicant = null;
25498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne            mISupplicantStaIface = null;
2555317e7c11c99d5cc8417c65cc73cf548f8f52b87Roshan Pius            mWifiMonitor.broadcastSupplicantDisconnectionEvent(mIfaceName);
256240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
257240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
258240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
25998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    /**
26024250365afbd9a20b2e03364eddf2025c8f1138aRoshan Pius     * Signals whether Initialization completed successfully.
26124250365afbd9a20b2e03364eddf2025c8f1138aRoshan Pius     */
26224250365afbd9a20b2e03364eddf2025c8f1138aRoshan Pius    public boolean isInitializationStarted() {
26324250365afbd9a20b2e03364eddf2025c8f1138aRoshan Pius        return mIServiceManager != null;
26424250365afbd9a20b2e03364eddf2025c8f1138aRoshan Pius    }
26524250365afbd9a20b2e03364eddf2025c8f1138aRoshan Pius
26624250365afbd9a20b2e03364eddf2025c8f1138aRoshan Pius    /**
26724250365afbd9a20b2e03364eddf2025c8f1138aRoshan Pius     * Signals whether Initialization completed successfully.
26898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     */
26998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    public boolean isInitializationComplete() {
27098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne        return mISupplicantStaIface != null;
2718c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius    }
2728c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius
2738c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius    /**
27498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne     * Wrapper functions to access static HAL methods, created to be mockable in unit tests
2758c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius     */
27698152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    protected IServiceManager getServiceManagerMockable() throws RemoteException {
27798152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne        return IServiceManager.getService(SERVICE_MANAGER_NAME);
27898152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    }
27998152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne
28098152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    protected ISupplicant getSupplicantMockable() throws RemoteException {
28198152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne        return ISupplicant.getService();
28298152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    }
28398152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne
28498152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne    protected ISupplicantStaIface getStaIfaceMockable(ISupplicantIface iface) {
28598152bd4a4e36ea2097abd474248a4c7884f55b5Glen Kuhne        return ISupplicantStaIface.asInterface(iface.asBinder());
2868c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius    }
2878c6d09c03532b3936fab2fed6f8b84c895333565Roshan Pius
28896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
2897c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * Add a network configuration to wpa_supplicant.
290d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
29166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     * @param config Config corresponding to the network.
29266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     * @return SupplicantStaNetwork of the added network in wpa_supplicant.
29366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     */
294d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    private SupplicantStaNetworkHal addNetwork(WifiConfiguration config) {
29566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        logi("addSupplicantStaNetwork via HIDL");
29666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        if (config == null) {
29766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Cannot add NULL network!");
29866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return null;
29966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
30066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        SupplicantStaNetworkHal network = addNetwork();
30166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        if (network == null) {
30266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Failed to add a network!");
30366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return null;
30466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
305f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius        if (!network.saveWifiConfiguration(config)) {
30666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Failed to save variables for: " + config.configKey());
307f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius            if (!removeAllNetworks()) {
308f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius                loge("Failed to remove all networks on failure.");
309f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius            }
31066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return null;
31166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
312f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius        return network;
31366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
31466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
31566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    /**
3167c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * Add the provided network configuration to wpa_supplicant and initiate connection to it.
3177c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * This method does the following:
3187c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 1. Triggers disconnect command to wpa_supplicant (if |shouldDisconnect| is true).
3197c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 2. Remove any existing network in wpa_supplicant.
3207c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 3. Add a new network to wpa_supplicant.
3217c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 4. Save the provided configuration to wpa_supplicant.
3227c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 5. Select the new network in wpa_supplicant.
323d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
3247c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @param config WifiConfiguration parameters for the provided network.
3257c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @param shouldDisconnect whether to trigger a disconnection or not.
3267c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @return {@code true} if it succeeds, {@code false} otherwise
32766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     */
328d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean connectToNetwork(WifiConfiguration config, boolean shouldDisconnect) {
3297c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        mFrameworkNetworkId = WifiConfiguration.INVALID_NETWORK_ID;
3307c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        mCurrentNetwork = null;
331d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        logd("connectToNetwork " + config.configKey()
33266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                + " (shouldDisconnect " + shouldDisconnect + ")");
33366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        if (shouldDisconnect && !disconnect()) {
33466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Failed to trigger disconnect");
33566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return false;
33666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
33766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        if (!removeAllNetworks()) {
33866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            loge("Failed to remove existing networks");
33966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return false;
34066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
3417c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        mCurrentNetwork = addNetwork(config);
3427c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (mCurrentNetwork == null) {
343d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius            loge("Failed to add/save network configuration: " + config.configKey());
34466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return false;
34566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
3467c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (!mCurrentNetwork.select()) {
347d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius            loge("Failed to select network configuration: " + config.configKey());
34866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            return false;
34966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
3507c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        mFrameworkNetworkId = config.networkId;
3517c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        return true;
3527c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    }
3537c0ec884188660f72977c8a80366049705c48ffaRoshan Pius
3547c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    /**
3557c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * Initiates roaming to the already configured network in wpa_supplicant. If the network
3567c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * configuration provided does not match the already configured network, then this triggers
3577c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * a new connection attempt (instead of roam).
3587c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 1. First check if we're attempting to connect to the same network as we currently have
3597c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * configured.
3607c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 2. Set the new bssid for the network in wpa_supplicant.
3617c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * 3. Trigger reassociate command to wpa_supplicant.
3627c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     *
3637c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @param config WifiConfiguration parameters for the provided network.
3647c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     * @return {@code true} if it succeeds, {@code false} otherwise
3657c0ec884188660f72977c8a80366049705c48ffaRoshan Pius     */
3667c0ec884188660f72977c8a80366049705c48ffaRoshan Pius    public boolean roamToNetwork(WifiConfiguration config) {
3677c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (mFrameworkNetworkId != config.networkId || mCurrentNetwork == null) {
3687c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            Log.w(TAG, "Cannot roam to a different network, initiate new connection. "
3697c0ec884188660f72977c8a80366049705c48ffaRoshan Pius                    + "Current network ID: " + mFrameworkNetworkId);
3707c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            return connectToNetwork(config, false);
3717c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        }
3727c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        String bssid = config.getNetworkSelectionStatus().getNetworkSelectionBSSID();
3737c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        logd("roamToNetwork" + config.configKey() + " (bssid " + bssid + ")");
3747c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (!mCurrentNetwork.setBssid(bssid)) {
3757c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            loge("Failed to set new bssid on network: " + config.configKey());
3767c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            return false;
3777c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        }
3787c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        if (!reassociate()) {
3797c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            loge("Failed to trigger reassociate");
3807c0ec884188660f72977c8a80366049705c48ffaRoshan Pius            return false;
3817c0ec884188660f72977c8a80366049705c48ffaRoshan Pius        }
38266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        return true;
38366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
38466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
38566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    /**
386f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * Load all the configured networks from wpa_supplicant.
387f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     *
388f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @param configs       Map of configuration key to configuration objects corresponding to all
389f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     *                      the networks.
390f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @param networkExtras Map of extra configuration parameters stored in wpa_supplicant.conf
391f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @return true if succeeds, false otherwise.
392f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     */
393f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    public boolean loadNetworks(Map<String, WifiConfiguration> configs,
394f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                                SparseArray<Map<String, String>> networkExtras) {
395f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        List<Integer> networkIds = listNetworks();
396f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        if (networkIds == null) {
397f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            Log.e(TAG, "Failed to list networks");
398f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            return false;
399f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        }
400f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        for (Integer networkId : networkIds) {
401f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            SupplicantStaNetworkHal network = getNetwork(networkId);
402f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            if (network == null) {
403f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                Log.e(TAG, "Failed to get network with ID: " + networkId);
404f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                return false;
405f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            }
406f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            WifiConfiguration config = new WifiConfiguration();
407f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            Map<String, String> networkExtra = new HashMap<>();
408f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            if (!network.loadWifiConfiguration(config, networkExtra)) {
409f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                Log.e(TAG, "Failed to load wifi configuration for network with ID: " + networkId);
410f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                return false;
411f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            }
412f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            // Set the default IP assignments.
413f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            config.setIpAssignment(IpConfiguration.IpAssignment.DHCP);
414f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            config.setProxySettings(IpConfiguration.ProxySettings.NONE);
415f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius
416f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            networkExtras.put(networkId, networkExtra);
417f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            String configKey = networkExtra.get(SupplicantStaNetworkHal.ID_STRING_KEY_CONFIG_KEY);
418f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            final WifiConfiguration duplicateConfig = configs.put(configKey, config);
419f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            if (duplicateConfig != null) {
420f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                // The network is already known. Overwrite the duplicate entry.
421f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                Log.i(TAG, "Replacing duplicate network: " + duplicateConfig.networkId);
422f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                removeNetwork(duplicateConfig.networkId);
423f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius                networkExtras.remove(duplicateConfig.networkId);
424f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius            }
425f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        }
426f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius        return true;
427f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    }
428f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius
429f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    /**
43066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     * Remove all networks from supplicant
43166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne     */
43266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    public boolean removeAllNetworks() {
43366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        synchronized (mLock) {
43466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            ArrayList<Integer> networks = listNetworks();
43566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            if (networks == null) {
43666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                Log.e(TAG, "removeAllNetworks failed, got null networks");
43766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                return false;
43866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            }
43966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            for (int id : networks) {
44066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                if (!removeNetwork(id)) {
44166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                    Log.e(TAG, "removeAllNetworks failed to remove network: " + id);
44266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                    return false;
44366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne                }
44466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne            }
44566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        }
44666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        return true;
44766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
44866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
44966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    /**
4500a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * Set the currently configured network's bssid.
4510a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     *
4520a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * @param bssidStr Bssid to set in the form of "XX:XX:XX:XX:XX:XX"
4530a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * @return true if succeeds, false otherwise.
4540a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     */
4550a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    public boolean setCurrentNetworkBssid(String bssidStr) {
4560a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius        if (mCurrentNetwork == null) return false;
4570a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius        return mCurrentNetwork.setBssid(bssidStr);
4580a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    }
4590a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius
4600a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    /**
4610a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * Get the currently configured network's WPS NFC token.
4620a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     *
4630a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     * @return Hex string corresponding to the WPS NFC token.
4640a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius     */
4650a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    public String getCurrentNetworkWpsNfcConfigurationToken() {
4660a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius        if (mCurrentNetwork == null) return null;
4670a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius        return mCurrentNetwork.getWpsNfcConfigurationToken();
4680a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    }
4690a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius
4700a3dcd72290481cb1fcbaaec268cccf343e4ff48Roshan Pius    /**
4718aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap identity response for the currently configured network.
4728aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
4738aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @param identityStr String to send.
4748aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
4758aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
4768aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapIdentityResponse(String identityStr) {
4778aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
4788aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapIdentityResponse(identityStr);
4798aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
4808aad61408adef866a177857b79a979cf77a0a662Roshan Pius
4818aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
4828aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap sim gsm auth response for the currently configured network.
4838aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
4848aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @param paramsStr String to send.
4858aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
4868aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
4878aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapSimGsmAuthResponse(String paramsStr) {
4888aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
4898aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapSimGsmAuthResponse(paramsStr);
4908aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
4918aad61408adef866a177857b79a979cf77a0a662Roshan Pius
4928aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
4938aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap sim gsm auth failure for the currently configured network.
4948aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
4958aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
4968aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
4978aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapSimGsmAuthFailure() {
4988aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
4998aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapSimGsmAuthFailure();
5008aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
5018aad61408adef866a177857b79a979cf77a0a662Roshan Pius
5028aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
5038aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap sim umts auth response for the currently configured network.
5048aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
5058aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @param paramsStr String to send.
5068aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
5078aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
5088aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapSimUmtsAuthResponse(String paramsStr) {
5098aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
5108aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapSimUmtsAuthResponse(paramsStr);
5118aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
5128aad61408adef866a177857b79a979cf77a0a662Roshan Pius
5138aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
5148aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap sim umts auts response for the currently configured network.
5158aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
5168aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @param paramsStr String to send.
5178aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
5188aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
5198aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapSimUmtsAutsResponse(String paramsStr) {
5208aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
5218aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapSimUmtsAutsResponse(paramsStr);
5228aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
5238aad61408adef866a177857b79a979cf77a0a662Roshan Pius
5248aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
5258aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * Send the eap sim umts auth failure for the currently configured network.
5268aad61408adef866a177857b79a979cf77a0a662Roshan Pius     *
5278aad61408adef866a177857b79a979cf77a0a662Roshan Pius     * @return true if succeeds, false otherwise.
5288aad61408adef866a177857b79a979cf77a0a662Roshan Pius     */
5298aad61408adef866a177857b79a979cf77a0a662Roshan Pius    public boolean sendCurrentNetworkEapSimUmtsAuthFailure() {
5308aad61408adef866a177857b79a979cf77a0a662Roshan Pius        if (mCurrentNetwork == null) return false;
5318aad61408adef866a177857b79a979cf77a0a662Roshan Pius        return mCurrentNetwork.sendNetworkEapSimUmtsAuthFailure();
5328aad61408adef866a177857b79a979cf77a0a662Roshan Pius    }
5338aad61408adef866a177857b79a979cf77a0a662Roshan Pius
5348aad61408adef866a177857b79a979cf77a0a662Roshan Pius    /**
535d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Adds a new network.
536d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
53796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * @return The ISupplicantNetwork object for the new network, or null if the call fails
53896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
53996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private SupplicantStaNetworkHal addNetwork() {
54096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
54196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "addNetwork";
54296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
5433aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            Mutable<ISupplicantNetwork> newNetwork = new Mutable<>();
54496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
54596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                mISupplicantStaIface.addNetwork((SupplicantStatus status,
54696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        ISupplicantNetwork network) -> {
5473aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius                    if (checkStatusAndLogFailure(status, methodStr)) {
54896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        newNetwork.value = network;
54996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                    }
55096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                });
55196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
552b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
55396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
5543aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            if (newNetwork.value != null) {
555c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius                return getStaNetworkMockable(
556c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius                        ISupplicantStaNetwork.asInterface(newNetwork.value.asBinder()));
55796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } else {
55896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return null;
55996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
56096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
56196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
562d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
56396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
56496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Remove network from supplicant with network Id
565d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
566d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
56796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
56896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean removeNetwork(int id) {
56996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
57096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "removeNetwork";
57196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
57296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
57396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.removeNetwork(id);
57496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
57596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
576b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
57796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
57896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
57996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
58096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
581d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
58296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
583f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * Use this to mock the creation of SupplicantStaNetworkHal instance.
584f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     *
585f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @param iSupplicantStaNetwork ISupplicantStaNetwork instance retrieved from HIDL.
586f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * @return The ISupplicantNetwork object for the given SupplicantNetworkId int, returns null if
587f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     * the call fails
588f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius     */
589f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    protected SupplicantStaNetworkHal getStaNetworkMockable(
590c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius            ISupplicantStaNetwork iSupplicantStaNetwork) {
591511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius        SupplicantStaNetworkHal network =
592511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius                new SupplicantStaNetworkHal(iSupplicantStaNetwork, mIfaceName, mContext,
593511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius                        mWifiMonitor);
594511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius        if (network != null) {
595511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius            network.enableVerboseLogging(mVerboseLoggingEnabled);
596511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius        }
597511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius        return network;
598f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    }
599f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius
600f180b0109b3fce79609b03ae2f7fbeff02d96b80Roshan Pius    /**
60196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * @return The ISupplicantNetwork object for the given SupplicantNetworkId int, returns null if
60296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * the call fails
60396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
60496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private SupplicantStaNetworkHal getNetwork(int id) {
60596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
60696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "getNetwork";
6073aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            Mutable<ISupplicantNetwork> gotNetwork = new Mutable<>();
60896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
60996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
61096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                mISupplicantStaIface.getNetwork(id, (SupplicantStatus status,
61196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        ISupplicantNetwork network) -> {
6123aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius                    if (checkStatusAndLogFailure(status, methodStr)) {
61396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        gotNetwork.value = network;
61496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                    }
61596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                });
61696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
617b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
61896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
6193aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            if (gotNetwork.value != null) {
620c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius                return getStaNetworkMockable(
621c7a4b6706fa09042bb36a64036d86d88eb6e4126Roshan Pius                        ISupplicantStaNetwork.asInterface(gotNetwork.value.asBinder()));
62296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } else {
62396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return null;
62496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
62596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
62696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
62796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
628c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    /** See ISupplicantStaNetwork.hal for documentation */
629c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    private boolean registerCallback(ISupplicantStaIfaceCallback callback) {
630c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        synchronized (mLock) {
631c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            final String methodStr = "registerCallback";
632c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
633c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            try {
634c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                SupplicantStatus status =  mISupplicantStaIface.registerCallback(callback);
635c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                return checkStatusAndLogFailure(status, methodStr);
636c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            } catch (RemoteException e) {
637b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
638c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                return false;
639c224fb554deca894818490c9416ff35d18a79d76Roshan Pius            }
640c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
641c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    }
642c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
64396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
64496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * @return a list of SupplicantNetworkID ints for all networks controlled by supplicant, returns
64596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * null if the call fails
64696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
64796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private java.util.ArrayList<Integer> listNetworks() {
64896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
64996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "listNetworks";
6503aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            Mutable<ArrayList<Integer>> networkIdList = new Mutable<>();
65196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
65296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
65396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                mISupplicantStaIface.listNetworks((SupplicantStatus status,
65496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        java.util.ArrayList<Integer> networkIds) -> {
6553aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius                    if (checkStatusAndLogFailure(status, methodStr)) {
65696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        networkIdList.value = networkIds;
65796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                    }
65896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                });
65996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
660b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
66196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
6623aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            return networkIdList.value;
66396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
66496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
665d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
6665f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
6675f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS device name.
6685f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
6695f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param name String to be set.
6705f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
6715f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
6725f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsDeviceName(String name) {
6737651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
6747651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsDeviceName";
6757651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
6767651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
6777651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsDeviceName(name);
6787651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
6797651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
680b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
6817651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
6827651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
6837651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
6847651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
6857651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
6865f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
6875f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS device type.
6885f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
6895f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param typeStr Type specified as a string. Used format: <categ>-<OUI>-<subcateg>
6905f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
6915f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
6925f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsDeviceType(String typeStr) {
6935f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        Matcher match = WPS_DEVICE_TYPE_PATTERN.matcher(typeStr);
6945f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        if (!match.find() || match.groupCount() != 3) {
6955f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            Log.e(TAG, "Malformed WPS device type " + typeStr);
6965f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            return false;
6975f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        }
6985f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        short categ = Short.parseShort(match.group(1));
6995f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byte[] oui = NativeUtil.hexStringToByteArray(match.group(2));
7005f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        short subCateg = Short.parseShort(match.group(3));
7015f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
7025f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byte[] bytes = new byte[8];
7035f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        ByteBuffer byteBuffer = ByteBuffer.wrap(bytes).order(ByteOrder.BIG_ENDIAN);
7045f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byteBuffer.putShort(categ);
7055f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byteBuffer.put(oui);
7065f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        byteBuffer.putShort(subCateg);
7075f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return setWpsDeviceType(bytes);
7085f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
7095f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
7107651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private boolean setWpsDeviceType(byte[/* 8 */] type) {
7117651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
7127651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsDeviceType";
7137651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
7147651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
7157651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsDeviceType(type);
7167651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
7177651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
718b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
7197651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
7207651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
7217651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
7227651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
7237651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
7245f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
7255f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS manufacturer.
7265f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
7275f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param manufacturer String to be set.
7285f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
7295f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
7305f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsManufacturer(String manufacturer) {
7317651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
7327651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsManufacturer";
7337651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
7347651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
7357651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsManufacturer(manufacturer);
7367651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
7377651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
738b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
7397651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
7407651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
7417651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
7427651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
7437651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
7445f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
7455f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS model name.
7465f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
7475f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param modelName String to be set.
7485f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
7495f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
7505f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsModelName(String modelName) {
7517651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
7527651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsModelName";
7537651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
7547651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
7557651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsModelName(modelName);
7567651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
7577651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
758b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
7597651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
7607651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
7617651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
7627651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
7637651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
7645f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
7655f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS model number.
7665f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
7675f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param modelNumber String to be set.
7685f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
7695f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
7705f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsModelNumber(String modelNumber) {
7717651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
7727651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsModelNumber";
7737651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
7747651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
7757651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsModelNumber(modelNumber);
7767651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
7777651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
778b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
7797651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
7807651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
7817651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
7827651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
7837651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
7845f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
7855f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS serial number.
7865f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
7875f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param serialNumber String to be set.
7885f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
7895f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
7905f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsSerialNumber(String serialNumber) {
7917651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
7927651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsSerialNumber";
7937651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
7947651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
7957651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsSerialNumber(serialNumber);
7967651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
7977651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
798b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
7997651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
8007651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
8017651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
8027651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
8037651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
8045f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
8055f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Set WPS config methods
8065f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
8075f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param configMethodsStr List of config methods.
8085f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
8095f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
8105f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setWpsConfigMethods(String configMethodsStr) {
8115f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        short configMethodsMask = 0;
8125f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        String[] configMethodsStrArr = configMethodsStr.split("\\s+");
8135f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        for (int i = 0; i < configMethodsStrArr.length; i++) {
8145f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            configMethodsMask |= stringToWpsConfigMethod(configMethodsStrArr[i]);
8155f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        }
8165f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return setWpsConfigMethods(configMethodsMask);
8175f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
8185f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
8197651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private boolean setWpsConfigMethods(short configMethods) {
8207651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
8217651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setWpsConfigMethods";
8227651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
8237651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
8247651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setWpsConfigMethods(configMethods);
8257651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
8267651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
827b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
8287651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
8297651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
8307651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
8317651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
8327651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
833d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
834d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Trigger a reassociation even if the iface is currently connected.
835d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
836d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
837d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
838d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean reassociate() {
83996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
84096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "reassociate";
84196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
84296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
84396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.reassociate();
84496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
84596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
846b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
84796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
84896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
84996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
85096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
851d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
852d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
853d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Trigger a reconnection if the iface is disconnected.
854d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
855d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
856d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
857d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean reconnect() {
85896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
85996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "reconnect";
86096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
86196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
86296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.reconnect();
86396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
86496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
865b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
86696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
86796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
86896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
86996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
870d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
871d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
872d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Trigger a disconnection from the currently connected network.
873d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
874d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
875d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
876d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean disconnect() {
87796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
87896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "disconnect";
87996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
88096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
88196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.disconnect();
88296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
88396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
884b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
88596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
88696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
88796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
88896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
889d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
890d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
891d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Enable or disable power save mode.
892d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
893d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param enable true to enable, false to disable.
894d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
895d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
896d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setPowerSave(boolean enable) {
89796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
89896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setPowerSave";
89996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
90096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
90196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.setPowerSave(enable);
90296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
90396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
904b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
90596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
90696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
90796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
90896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
909d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
910d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
911d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Initiate TDLS discover with the specified AP.
912d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
913d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param macAddress MAC Address of the AP.
914d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
915d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
916d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateTdlsDiscover(String macAddress) {
917d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateTdlsDiscover(NativeUtil.macAddressToByteArray(macAddress));
918d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
919b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
92096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateTdlsDiscover(byte[/* 6 */] macAddress) {
92196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
92296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateTdlsDiscover";
92396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
92496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
92596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateTdlsDiscover(macAddress);
92696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
92796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
928b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
92996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
93096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
93196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
93296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
933d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
934d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
935d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Initiate TDLS setup with the specified AP.
936d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
937d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param macAddress MAC Address of the AP.
938d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
939d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
940d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateTdlsSetup(String macAddress) {
941d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateTdlsSetup(NativeUtil.macAddressToByteArray(macAddress));
942d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
943b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
94496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateTdlsSetup(byte[/* 6 */] macAddress) {
94596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
94696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateTdlsSetup";
94796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
94896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
94996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateTdlsSetup(macAddress);
95096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
95196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
952b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
95396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
95496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
95596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
95696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
957d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
958d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
959d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Initiate TDLS teardown with the specified AP.
960d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param macAddress MAC Address of the AP.
961d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
962d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
963d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateTdlsTeardown(String macAddress) {
964d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateTdlsTeardown(NativeUtil.macAddressToByteArray(macAddress));
965d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
966d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
967b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
96896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateTdlsTeardown(byte[/* 6 */] macAddress) {
96996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
97096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateTdlsTeardown";
97196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
97296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
97396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateTdlsTeardown(macAddress);
97496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
97596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
976b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
97796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
97896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
97996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
98096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
981d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
982d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
983d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Request the specified ANQP elements |elements| from the specified AP |bssid|.
984d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
985d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param bssid BSSID of the AP
986d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param infoElements ANQP elements to be queried. Refer to ISupplicantStaIface.AnqpInfoId.
987d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param hs20SubTypes HS subtypes to be queried. Refer to ISupplicantStaIface.Hs20AnqpSubTypes.
988d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
989d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
990d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateAnqpQuery(String bssid, ArrayList<Short> infoElements,
991d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius                                     ArrayList<Integer> hs20SubTypes) {
992d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateAnqpQuery(
993d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius                NativeUtil.macAddressToByteArray(bssid), infoElements, hs20SubTypes);
994d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
995d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
996b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
99796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateAnqpQuery(byte[/* 6 */] macAddress,
99896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            java.util.ArrayList<Short> infoElements, java.util.ArrayList<Integer> subTypes) {
99996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
100096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateAnqpQuery";
100196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
100296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
100396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateAnqpQuery(macAddress,
100496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        infoElements, subTypes);
100596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
100696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1007b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
100896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
100996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
101096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
101196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1012d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1013d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1014d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Request the specified ANQP ICON from the specified AP |bssid|.
1015d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1016d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param bssid BSSID of the AP
1017d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param fileName Name of the file to request.
1018d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1019d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1020d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean initiateHs20IconQuery(String bssid, String fileName) {
1021d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return initiateHs20IconQuery(NativeUtil.macAddressToByteArray(bssid), fileName);
1022d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
1023d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1024b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
102596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean initiateHs20IconQuery(byte[/* 6 */] macAddress, String fileName) {
102696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
102796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "initiateHs20IconQuery";
102896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
102996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
103096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.initiateHs20IconQuery(macAddress,
103196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        fileName);
103296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
103396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1034b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
103596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
103696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
103796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
103896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1039d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
104096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
104196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Makes a callback to HIDL to getMacAddress from supplicant
1042d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
104396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * @return string containing the MAC address, or null on a failed call
104496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
1045d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public String getMacAddress() {
104696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
104796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "getMacAddress";
104896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
104996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            Mutable<String> gotMac = new Mutable<>();
105096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
105196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                mISupplicantStaIface.getMacAddress((SupplicantStatus status,
105296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        byte[/* 6 */] macAddr) -> {
10533aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius                    if (checkStatusAndLogFailure(status, methodStr)) {
1054d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius                        gotMac.value = NativeUtil.macAddressFromByteArray(macAddr);
105596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                    }
105696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                });
105796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1058b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
105996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
10603aa9b7e616f685ded8fade523317e96cedcdcc2dRoshan Pius            return gotMac.value;
106196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
106296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1063d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1064d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1065d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Start using the added RX filters.
1066d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1067d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1068d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1069d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean startRxFilter() {
107096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
107196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "startRxFilter";
107296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
107396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
107496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.startRxFilter();
107596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
107696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1077b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
107896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
107996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
108096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
108196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1082d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1083d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1084d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Stop using the added RX filters.
1085d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1086d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1087d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1088d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean stopRxFilter() {
108996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
109096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "stopRxFilter";
109196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
109296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
109396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.stopRxFilter();
109496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
109596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1096b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
109796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
109896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
109996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
110096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1101d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1102d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte RX_FILTER_TYPE_V4_MULTICAST =
1103d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius            ISupplicantStaIface.RxFilterType.V6_MULTICAST;
1104d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte RX_FILTER_TYPE_V6_MULTICAST =
1105d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius            ISupplicantStaIface.RxFilterType.V6_MULTICAST;
1106d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1107d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Add an RX filter.
1108d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1109d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param type one of {@link #RX_FILTER_TYPE_V4_MULTICAST} or
1110d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *        {@link #RX_FILTER_TYPE_V6_MULTICAST} values.
1111d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1112d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1113f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius    public boolean addRxFilter(byte type) {
111496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
111596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "addRxFilter";
111696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
111796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
111896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.addRxFilter(type);
111996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
112096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1121b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
112296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
112396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
112496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
112596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1126d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1127d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1128d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Remove an RX filter.
1129d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1130d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param type one of {@link #RX_FILTER_TYPE_V4_MULTICAST} or
1131d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *        {@link #RX_FILTER_TYPE_V6_MULTICAST} values.
1132d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1133d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1134f0c2cbd00fe77a8f2b94f3f0d7c28e3e5fdc1fc4Roshan Pius    public boolean removeRxFilter(byte type) {
113596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
113696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "removeRxFilter";
113796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
113896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
113996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.removeRxFilter(type);
114096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
114196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1142b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
114396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
114496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
114596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
114696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1147d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1148d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte BT_COEX_MODE_ENABLED = ISupplicantStaIface.BtCoexistenceMode.ENABLED;
1149d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte BT_COEX_MODE_DISABLED = ISupplicantStaIface.BtCoexistenceMode.DISABLED;
1150d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public static final byte BT_COEX_MODE_SENSE = ISupplicantStaIface.BtCoexistenceMode.SENSE;
1151d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1152d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Set Bt co existense mode.
1153d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1154d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param mode one of the above {@link #BT_COEX_MODE_ENABLED}, {@link #BT_COEX_MODE_DISABLED}
1155d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *             or {@link #BT_COEX_MODE_SENSE} values.
1156d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1157d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1158d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setBtCoexistenceMode(byte mode) {
115996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
116096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setBtCoexistenceMode";
116196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
116296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
116396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.setBtCoexistenceMode(mode);
116496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
116596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1166b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
116796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
116896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
116996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
117096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1171d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1172d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /** Enable or disable BT coexistence mode.
1173d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1174d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param enable true to enable, false to disable.
1175d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1176d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1177d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setBtCoexistenceScanModeEnabled(boolean enable) {
117896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
117996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setBtCoexistenceScanModeEnabled";
118096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
118196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
118296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status =
118396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                        mISupplicantStaIface.setBtCoexistenceScanModeEnabled(enable);
118496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
118596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1186b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
118796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
118896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
118996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
119096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1191d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1192d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1193d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Enable or disable suspend mode optimizations.
1194d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1195d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param enable true to enable, false otherwise.
11965f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
1197d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1198d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setSuspendModeEnabled(boolean enable) {
119996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
120096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setSuspendModeEnabled";
120196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
120296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
120396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.setSuspendModeEnabled(enable);
120496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
120596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1206b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
120796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
120896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
120996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
121096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
1211d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1212d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    /**
1213d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * Set country code.
1214d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     *
1215d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @param codeStr 2 byte ASCII string. For ex: US, CA.
1216d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     * @return true if request is sent successfully, false otherwise.
1217d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius     */
1218d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    public boolean setCountryCode(String codeStr) {
1219d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius        return setCountryCode(NativeUtil.stringToByteArray(codeStr));
1220d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius    }
1221d95fa596d07855b70ff18a50a48e773155a919f5Roshan Pius
1222b4419d876beda78c29836726e43d80203b4a656cRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
122396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean setCountryCode(byte[/* 2 */] code) {
122496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        synchronized (mLock) {
122596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr = "setCountryCode";
122696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
122796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            try {
122896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                SupplicantStatus status = mISupplicantStaIface.setCountryCode(code);
122996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return checkStatusAndLogFailure(status, methodStr);
123096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            } catch (RemoteException e) {
1231b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
123296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return false;
123396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            }
123496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
123596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
123696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
12375f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
12385f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Start WPS pin registrar operation with the specified peer and pin.
12395f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
12405f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param bssidStr BSSID of the peer.
12415f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param pin Pin to be used.
12425f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
12435f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
12445f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean startWpsRegistrar(String bssidStr, String pin) {
12455f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return startWpsRegistrar(NativeUtil.macAddressToByteArray(bssidStr), pin);
12465f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
12475f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
12487651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
12497651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private boolean startWpsRegistrar(byte[/* 6 */] bssid, String pin) {
12507651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
12517651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "startWpsRegistrar";
12527651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
12537651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
12547651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.startWpsRegistrar(bssid, pin);
12557651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
12567651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1257b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
12587651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
12597651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
12607651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
12617651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
12627651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
12635f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
12645f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Start WPS pin display operation with the specified peer.
12655f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
12665f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param bssidStr BSSID of the peer.
12675f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
12685f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
12695f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean startWpsPbc(String bssidStr) {
12705f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return startWpsPbc(NativeUtil.macAddressToByteArray(bssidStr));
12715f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
12725f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
12737651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
12747651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private boolean startWpsPbc(byte[/* 6 */] bssid) {
12757651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
12767651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "startWpsPbc";
12777651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
12787651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
12797651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.startWpsPbc(bssid);
12807651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
12817651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1282b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
12837651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
12847651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
12857651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
12867651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
12877651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
12885f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
12895f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Start WPS pin keypad operation with the specified pin.
12905f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
12915f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param pin Pin to be used.
12925f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
12935f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
12945f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean startWpsPinKeypad(String pin) {
12957651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
12967651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "startWpsPinKeypad";
12977651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
12987651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
12997651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.startWpsPinKeypad(pin);
13007651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
13017651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1302b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
13037651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
13047651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
13057651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
13067651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
13077651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
13085f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
13095f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Start WPS pin display operation with the specified peer.
13105f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
13115f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param bssidStr BSSID of the peer.
13125f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return new pin generated on success, null otherwise.
13135f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
13145f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public String startWpsPinDisplay(String bssidStr) {
13155f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        return startWpsPinDisplay(NativeUtil.macAddressToByteArray(bssidStr));
13165f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
13175f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
13187651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    /** See ISupplicantStaIface.hal for documentation */
13197651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    private String startWpsPinDisplay(byte[/* 6 */] bssid) {
13207651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
13217651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "startWpsPinDisplay";
13227651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return null;
13237651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final Mutable<String> gotPin = new Mutable<>();
13247651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
13257651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                mISupplicantStaIface.startWpsPinDisplay(bssid,
13267651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                        (SupplicantStatus status, String pin) -> {
13277651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                            if (checkStatusAndLogFailure(status, methodStr)) {
13287651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                                gotPin.value = pin;
13297651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                            }
13307651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                        });
13317651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1332b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
13337651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
13347651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            return gotPin.value;
13357651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
13367651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
13377651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
13385f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
13395f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Cancels any ongoing WPS requests.
13405f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
13415f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
13425f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
13435f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean cancelWps() {
13447651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
13457651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "cancelWps";
13467651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
13477651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
13487651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.cancelWps();
13497651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
13507651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1351b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
13527651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
13537651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
13547651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
13557651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
13567651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
13575f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
13585f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Sets whether to use external sim for SIM/USIM processing.
13595f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     *
13605f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @param useExternalSim true to enable, false otherwise.
13615f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * @return true if request is sent successfully, false otherwise.
13625f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
13635f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    public boolean setExternalSim(boolean useExternalSim) {
13647651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        synchronized (mLock) {
13657651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            final String methodStr = "setExternalSim";
13667651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            if (!checkSupplicantStaIfaceAndLogFailure(methodStr)) return false;
13677651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            try {
13687651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                SupplicantStatus status = mISupplicantStaIface.setExternalSim(useExternalSim);
13697651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return checkStatusAndLogFailure(status, methodStr);
13707651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            } catch (RemoteException e) {
1371b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
13727651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius                return false;
13737651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius            }
13747651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius        }
13757651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius    }
13767651e69b6f5e2b28a4fee7284ac2522faa002c9fRoshan Pius
1377cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_EXCESSIVE = ISupplicant.DebugLevel.EXCESSIVE;
1378cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_MSGDUMP = ISupplicant.DebugLevel.MSGDUMP;
1379cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_DEBUG = ISupplicant.DebugLevel.DEBUG;
1380cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_INFO = ISupplicant.DebugLevel.INFO;
1381cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_WARNING = ISupplicant.DebugLevel.WARNING;
1382cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public static final int LOG_LEVEL_ERROR = ISupplicant.DebugLevel.ERROR;
1383cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /**
1384cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * Set the debug log level for wpa_supplicant
1385cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * @param level One of the above {@link #LOG_LEVEL_EXCESSIVE} - {@link #LOG_LEVEL_ERROR} value.
1386cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * @return true if request is sent successfully, false otherwise.
1387cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     */
1388cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public boolean setLogLevel(int level) {
1389cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        return setDebugParams(level, false, false);
1390cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1391cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
1392cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /** See ISupplicant.hal for documentation */
1393cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    private boolean setDebugParams(int level, boolean showTimestamp, boolean showKeys) {
1394cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        synchronized (mLock) {
1395cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            final String methodStr = "setDebugParams";
1396cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            if (!checkSupplicantAndLogFailure(methodStr)) return false;
1397cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            try {
1398cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                SupplicantStatus status =
1399cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                        mISupplicant.setDebugParams(level, showTimestamp, showKeys);
1400cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                return checkStatusAndLogFailure(status, methodStr);
1401cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            } catch (RemoteException e) {
1402b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
1403cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                return false;
1404cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            }
1405cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        }
1406cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1407cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
1408cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /**
1409cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * Set concurrency priority between P2P & STA operations.
1410cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     *
1411cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * @param isStaHigherPriority Set to true to prefer STA over P2P during concurrency operations,
1412cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     *                            false otherwise.
1413cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * @return true if request is sent successfully, false otherwise.
1414cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     */
1415cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    public boolean setConcurrencyPriority(boolean isStaHigherPriority) {
1416cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        if (isStaHigherPriority) {
1417cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            return setConcurrencyPriority(IfaceType.STA);
1418cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        } else {
1419cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            return setConcurrencyPriority(IfaceType.P2P);
1420cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        }
1421cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1422cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
1423cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /** See ISupplicant.hal for documentation */
1424cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    private boolean setConcurrencyPriority(int type) {
1425cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        synchronized (mLock) {
1426cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            final String methodStr = "setConcurrencyPriority";
1427cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            if (!checkSupplicantAndLogFailure(methodStr)) return false;
1428cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            try {
1429cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                SupplicantStatus status = mISupplicant.setConcurrencyPriority(type);
1430cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                return checkStatusAndLogFailure(status, methodStr);
1431cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            } catch (RemoteException e) {
1432b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                handleRemoteException(e, methodStr);
1433cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius                return false;
1434cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            }
1435cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        }
1436cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1437cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
1438cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    /**
1439cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     * Returns false if Supplicant is null, and logs failure to call methodStr
1440cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius     */
1441cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    private boolean checkSupplicantAndLogFailure(final String methodStr) {
1442cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        if (mISupplicant == null) {
1443cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            Log.e(TAG, "Can't call " + methodStr + ", ISupplicant is null");
1444cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius            return false;
1445cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        }
1446cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius        return true;
1447cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius    }
1448cb9565f0cb8fa92346549bcacdfbf91cdf8e6bd3Roshan Pius
144996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
145096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Returns false if SupplicantStaIface is null, and logs failure to call methodStr
145196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
145296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    private boolean checkSupplicantStaIfaceAndLogFailure(final String methodStr) {
145396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        if (mISupplicantStaIface == null) {
145496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            Log.e(TAG, "Can't call " + methodStr + ", ISupplicantStaIface is null");
145596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            return false;
145696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
145796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        return true;
145896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
145996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
146096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
146196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Returns true if provided status code is SUCCESS, logs debug message and returns false
146296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * otherwise
146396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
1464511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius    private boolean checkStatusAndLogFailure(SupplicantStatus status,
146596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            final String methodStr) {
146696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        if (status.code != SupplicantStatusCode.SUCCESS) {
1467b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius            Log.e(TAG, "ISupplicantStaIface." + methodStr + " failed: "
1468b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius                    + supplicantStatusCodeToString(status.code) + ", " + status.debugMessage);
146996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            return false;
1470b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius        } else {
1471511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius            if (mVerboseLoggingEnabled) {
1472b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                Log.d(TAG, "ISupplicantStaIface." + methodStr + " succeeded");
1473511c6a204fefd7d295cb3728e6d4665106a29ae7Roshan Pius            }
1474b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius            return true;
147596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
1476b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius    }
1477b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius
1478b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius    /**
1479b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius     * Helper function to log callbacks.
1480b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius     */
1481b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius    private void logCallback(final String methodStr) {
1482b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius        if (mVerboseLoggingEnabled) {
1483b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            Log.d(TAG, "ISupplicantStaIfaceCallback." + methodStr + " received");
1484b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius        }
1485b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius    }
1486b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius
1487b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius
1488b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius    private void handleRemoteException(RemoteException e, String methodStr) {
1489b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius        supplicantServiceDiedHandler();
1490b850a6ae6fe8470fd9338bbc9978caadc7ca2c4bRoshan Pius        Log.e(TAG, "ISupplicantStaIface." + methodStr + " failed with exception", e);
149196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
149296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
149396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    /**
149496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * Converts SupplicantStatus code values to strings for debug logging
149596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     * TODO(b/34811152) Remove this, or make it more break resistance
149696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne     */
149796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    public static String supplicantStatusCodeToString(int code) {
149896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        switch (code) {
149996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 0:
150096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "SUCCESS";
150196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 1:
150296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_UNKNOWN";
150396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 2:
150496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_ARGS_INVALID";
150596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 3:
150696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_INVALID";
150796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 4:
150896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_UNKNOWN";
150996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 5:
151096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_EXISTS";
151196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 6:
151296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_DISABLED";
151396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 7:
151496013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_IFACE_NOT_DISCONNECTED";
151596013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 8:
151696013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_NETWORK_INVALID";
151796013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            case 9:
151896013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "FAILURE_NETWORK_UNKNOWN";
151996013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne            default:
152096013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne                return "??? UNKNOWN_CODE";
152196013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne        }
152296013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne    }
152396013ebe01c095e2bac5ff7a490a2f9b69876e3cGlen Kuhne
15245f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
15255f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    /**
15265f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     * Converts the Wps config method string to the equivalent enum value.
15275f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius     */
15285f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    private static short stringToWpsConfigMethod(String configMethod) {
15295f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        switch (configMethod) {
15305f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "usba":
15315f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.USBA;
15325f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "ethernet":
15335f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.ETHERNET;
15345f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "label":
15355f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.LABEL;
15365f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "display":
15375f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.DISPLAY;
15385f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "int_nfc_token":
15395f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.INT_NFC_TOKEN;
15405f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "ext_nfc_token":
15415f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.EXT_NFC_TOKEN;
15425f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "nfc_interface":
15435f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.NFC_INTERFACE;
15445f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "push_button":
15455f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.PUSHBUTTON;
15465f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "keypad":
15475f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.KEYPAD;
15485f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "virtual_push_button":
15495f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.VIRT_PUSHBUTTON;
15505f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "physical_push_button":
15515f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.PHY_PUSHBUTTON;
15525f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "p2ps":
15535f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.P2PS;
15545f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "virtual_display":
15555f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.VIRT_DISPLAY;
15565f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            case "physical_display":
15575f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                return WpsConfigMethods.PHY_DISPLAY;
15585f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius            default:
15595f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                throw new IllegalArgumentException(
15605f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius                        "Invalid WPS config method: " + configMethod);
15615f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius        }
15625f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius    }
15635f39baacf16b55c5551574bd1d973cdb14f70c45Roshan Pius
156482c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius    /**
156582c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius     * Converts the supplicant state received from HIDL to the equivalent framework state.
156682c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius     */
156782c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius    private static SupplicantState supplicantHidlStateToFrameworkState(int state) {
156882c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius        switch (state) {
156982c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.DISCONNECTED:
157082c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.DISCONNECTED;
157182c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.IFACE_DISABLED:
157282c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.INTERFACE_DISABLED;
157382c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.INACTIVE:
157482c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.INACTIVE;
157582c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.SCANNING:
157682c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.SCANNING;
157782c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.AUTHENTICATING:
157882c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.AUTHENTICATING;
157982c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.ASSOCIATING:
158082c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.ASSOCIATING;
158182c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.ASSOCIATED:
158282c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.ASSOCIATED;
158382c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.FOURWAY_HANDSHAKE:
158482c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.FOUR_WAY_HANDSHAKE;
158582c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.GROUP_HANDSHAKE:
158682c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.GROUP_HANDSHAKE;
158782c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            case ISupplicantStaIfaceCallback.State.COMPLETED:
158882c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                return SupplicantState.COMPLETED;
158982c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            default:
159082c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius                throw new IllegalArgumentException("Invalid state: " + state);
159182c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius        }
159282c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius    }
159382c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius
1594240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    private static class Mutable<E> {
1595240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        public E value;
1596240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
1597240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        Mutable() {
1598240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            value = null;
1599240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
1600240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne
1601240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        Mutable(E value) {
1602240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne            this.value = value;
1603240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne        }
1604240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne    }
160566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
1606c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    private class SupplicantStaIfaceHalCallback extends ISupplicantStaIfaceCallback.Stub {
16075a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        /**
16085a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * Parses the provided payload into an ANQP element.
16095a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         *
16105a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param infoID  Element type.
16115a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param payload Raw payload bytes.
16125a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @return AnqpElement instance on success, null on failure.
16135a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         */
16145a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        private ANQPElement parseAnqpElement(Constants.ANQPElementType infoID,
16155a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                                             ArrayList<Byte> payload) {
16165a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            try {
16175a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                return Constants.getANQPElementID(infoID) != null
16185a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        ? ANQPParser.parseElement(
16195a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        infoID, ByteBuffer.wrap(NativeUtil.byteArrayFromArrayList(payload)))
16205a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        : ANQPParser.parseHS20Element(
16215a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        infoID, ByteBuffer.wrap(NativeUtil.byteArrayFromArrayList(payload)));
16225a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            } catch (IOException | BufferUnderflowException e) {
16235a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                Log.e(TAG, "Failed parsing ANQP element payload: " + infoID, e);
16245a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                return null;
16255a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            }
16265a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        }
16275a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius
16285a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        /**
16295a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * Parse the ANQP element data and add to the provided elements map if successful.
16305a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         *
16315a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param elementsMap Map to add the parsed out element to.
16325a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param infoID  Element type.
16335a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * @param payload Raw payload bytes.
16345a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         */
16355a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        private void addAnqpElementToMap(Map<Constants.ANQPElementType, ANQPElement> elementsMap,
16365a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                                         Constants.ANQPElementType infoID,
16375a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                                         ArrayList<Byte> payload) {
16385a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            if (payload == null || payload.isEmpty()) return;
16395a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            ANQPElement element = parseAnqpElement(infoID, payload);
16405a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            if (element != null) {
16415a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                elementsMap.put(infoID, element);
16425a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            }
16435a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        }
16445a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius
16455a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        /**
16465a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         * Helper utility to convert the bssid bytes to long.
16475a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius         */
16485a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        private Long toLongBssid(byte[] bssidBytes) {
16495a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            try {
16505a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                return ByteBufferReader.readInteger(
16515a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                        ByteBuffer.wrap(bssidBytes), ByteOrder.BIG_ENDIAN, bssidBytes.length);
16525a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            } catch (BufferUnderflowException | IllegalArgumentException e) {
16535a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                return 0L;
16545a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius            }
16555a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        }
16565a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius
1657c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1658c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onNetworkAdded(int id) {
1659b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onNetworkAdded");
1660c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1661c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1662c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1663c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onNetworkRemoved(int id) {
1664b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onNetworkRemoved");
1665c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1666c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1667c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1668c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onStateChanged(int newState, byte[/* 6 */] bssid, int id,
1669c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                                   ArrayList<Byte> ssid) {
1670b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onStateChanged");
1671b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1672b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                SupplicantState newSupplicantState = supplicantHidlStateToFrameworkState(newState);
1673b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                WifiSsid wifiSsid =
1674b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        WifiSsid.createFromByteArray(NativeUtil.byteArrayFromArrayList(ssid));
1675b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                String bssidStr = NativeUtil.macAddressFromByteArray(bssid);
1676b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastSupplicantStateChangeEvent(
1677b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        mIfaceName, mFrameworkNetworkId, wifiSsid, bssidStr, newSupplicantState);
1678b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                if (newSupplicantState == SupplicantState.ASSOCIATED) {
1679b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                    mWifiMonitor.broadcastAssociationSuccesfulEvent(mIfaceName, bssidStr);
1680b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                } else if (newSupplicantState == SupplicantState.COMPLETED) {
1681b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                    mWifiMonitor.broadcastNetworkConnectionEvent(
1682b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                            mIfaceName, mFrameworkNetworkId, bssidStr);
1683b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                }
168482c5c5f2ee520a1066cf5d6421885bb53bbfe269Roshan Pius            }
1685c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1686c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1687c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
16885a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        public void onAnqpQueryDone(byte[/* 6 */] bssid,
1689c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                                    ISupplicantStaIfaceCallback.AnqpData data,
1690c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                                    ISupplicantStaIfaceCallback.Hs20AnqpData hs20Data) {
1691b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onAnqpQueryDone");
1692b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1693b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                Map<Constants.ANQPElementType, ANQPElement> elementsMap = new HashMap<>();
1694b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, ANQPVenueName, data.venueName);
1695b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, ANQPRoamingConsortium, data.roamingConsortium);
1696b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(
1697b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        elementsMap, ANQPIPAddrAvailability, data.ipAddrTypeAvailability);
1698b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, ANQPNAIRealm, data.naiRealm);
1699b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, ANQP3GPPNetwork, data.anqp3gppCellularNetwork);
1700b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, ANQPDomName, data.domainName);
1701b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, HSFriendlyName, hs20Data.operatorFriendlyName);
1702b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, HSWANMetrics, hs20Data.wanMetrics);
1703b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, HSConnCapability, hs20Data.connectionCapability);
1704b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                addAnqpElementToMap(elementsMap, HSOSUProviders, hs20Data.osuProvidersList);
1705b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastAnqpDoneEvent(
1706b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        mIfaceName, new AnqpEvent(toLongBssid(bssid), elementsMap));
1707b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1708c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1709c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1710c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
17115a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        public void onHs20IconQueryDone(byte[/* 6 */] bssid, String fileName,
1712c224fb554deca894818490c9416ff35d18a79d76Roshan Pius                                        ArrayList<Byte> data) {
1713b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onHs20IconQueryDone");
1714b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1715b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastIconDoneEvent(
1716b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        mIfaceName,
1717b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        new IconEvent(toLongBssid(bssid), fileName, data.size(),
1718b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                                NativeUtil.byteArrayFromArrayList(data)));
1719b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1720c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1721c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1722c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
17235a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        public void onHs20SubscriptionRemediation(byte[/* 6 */] bssid, byte osuMethod, String url) {
1724b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onHs20SubscriptionRemediation");
1725b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1726b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastWnmEvent(
1727b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        mIfaceName, new WnmData(toLongBssid(bssid), url, osuMethod));
1728b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1729c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1730c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1731c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
17325a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius        public void onHs20DeauthImminentNotice(byte[/* 6 */] bssid, int reasonCode,
17335a1adfdef3025a595544b3d17e1d5d9afca7673bRoshan Pius                                               int reAuthDelayInSec, String url) {
1734b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onHs20DeauthImminentNotice");
1735b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1736b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastWnmEvent(
1737b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        mIfaceName,
1738b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        new WnmData(toLongBssid(bssid), url, reasonCode == WnmData.ESS,
1739b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                                reAuthDelayInSec));
1740b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1741c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1742c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1743c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1744c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onDisconnected(byte[/* 6 */] bssid, boolean locallyGenerated, int reasonCode) {
1745b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onDisconnected");
1746b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1747b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastNetworkDisconnectionEvent(
1748b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        mIfaceName, locallyGenerated ? 1 : 0, reasonCode,
1749b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        NativeUtil.macAddressFromByteArray(bssid));
1750b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1751c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1752c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1753c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1754c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onAssociationRejected(byte[/* 6 */] bssid, int statusCode) {
1755b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onAssociationRejected");
1756b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1757b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                // TODO(b/35464954): Need to figure out when to trigger
1758b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                // |WifiMonitor.AUTHENTICATION_FAILURE_REASON_WRONG_PSWD|
1759b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastAssociationRejectionEvent(mIfaceName, statusCode,
1760b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        NativeUtil.macAddressFromByteArray(bssid));
1761b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1762c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1763c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1764c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1765c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onAuthenticationTimeout(byte[/* 6 */] bssid) {
1766b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onAuthenticationTimeout");
1767b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1768b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastAuthenticationFailureEvent(
1769b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        mIfaceName, WifiMonitor.AUTHENTICATION_FAILURE_REASON_TIMEOUT);
1770b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1771c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1772c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1773c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1774c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onEapFailure() {
1775b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onEapFailure");
1776b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1777b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastAuthenticationFailureEvent(
1778b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        mIfaceName, WifiMonitor.AUTHENTICATION_FAILURE_REASON_EAP_FAILURE);
1779b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1780c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1781c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1782c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1783c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onWpsEventSuccess() {
1784b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onWpsEventSuccess");
1785b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1786b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastWpsSuccessEvent(mIfaceName);
1787b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1788c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1789c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1790c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1791c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onWpsEventFail(byte[/* 6 */] bssid, short configError, short errorInd) {
1792b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onWpsEventFail");
1793b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1794b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                if (configError == WpsConfigError.MSG_TIMEOUT
1795b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                        && errorInd == WpsErrorIndication.NO_ERROR) {
1796b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                    mWifiMonitor.broadcastWpsTimeoutEvent(mIfaceName);
1797b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                } else {
1798b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                    mWifiMonitor.broadcastWpsFailEvent(mIfaceName, configError, errorInd);
1799b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                }
1800bcf35be52f93d09a3f2ac8d4272a6d66467309b9Roshan Pius            }
1801c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1802c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1803c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1804c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onWpsEventPbcOverlap() {
1805b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onWpsEventPbcOverlap");
1806b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            synchronized (mLock) {
1807b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius                mWifiMonitor.broadcastWpsOverlapEvent(mIfaceName);
1808b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            }
1809c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1810c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1811c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1812c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onExtRadioWorkStart(int id) {
1813b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onExtRadioWorkStart");
1814c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1815c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
1816c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        @Override
1817c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        public void onExtRadioWorkTimeout(int id) {
1818b70d1e046a5eb7e87c6b96beec30bcb985ee9c3cRoshan Pius            logCallback("onExtRadioWorkTimeout");
1819c224fb554deca894818490c9416ff35d18a79d76Roshan Pius        }
1820c224fb554deca894818490c9416ff35d18a79d76Roshan Pius    }
1821c224fb554deca894818490c9416ff35d18a79d76Roshan Pius
182266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    private void logd(String s) {
182366e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        Log.d(TAG, s);
182466e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
182566e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
182666e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    private void logi(String s) {
182766e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        Log.i(TAG, s);
182866e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
182966e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne
183066e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    private void loge(String s) {
183166e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne        Log.e(TAG, s);
183266e9f4ab597136cbf4accadb8e009fc68ff071a7Glen Kuhne    }
1833240671db659a4f7ca7e217d41c7aee9d85e22c33Glen Kuhne}
1834