1 /*
2  * Copyright (C) 2017 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.server.wifi;
17 
18 import android.annotation.IntDef;
19 import android.annotation.NonNull;
20 import android.content.Context;
21 import android.net.MacAddress;
22 import android.net.wifi.MscsParams;
23 import android.net.wifi.QosPolicyParams;
24 import android.net.wifi.SecurityParams;
25 import android.net.wifi.WifiConfiguration;
26 import android.os.Handler;
27 import android.util.Log;
28 import android.util.Range;
29 
30 import com.android.internal.annotations.VisibleForTesting;
31 
32 import java.lang.annotation.Retention;
33 import java.lang.annotation.RetentionPolicy;
34 import java.net.InetAddress;
35 import java.net.UnknownHostException;
36 import java.util.ArrayList;
37 import java.util.List;
38 import java.util.Map;
39 
40 import javax.annotation.concurrent.ThreadSafe;
41 
42 /**
43  * To maintain thread-safety, the locking protocol is that every non-static method (regardless of
44  * access level) acquires mLock.
45  */
46 @ThreadSafe
47 public class SupplicantStaIfaceHal {
48     private static final String TAG = "SupplicantStaIfaceHal";
49     private final Object mLock = new Object();
50     private final Context mContext;
51     private final WifiMonitor mWifiMonitor;
52     private final FrameworkFacade mFrameworkFacade;
53     private final Handler mEventHandler;
54     private final Clock mClock;
55     private final WifiMetrics mWifiMetrics;
56     private final WifiGlobals mWifiGlobals;
57     private final @NonNull SsidTranslator mSsidTranslator;
58     private final WifiInjector mWifiInjector;
59 
60     // HAL interface object - might be implemented by HIDL or AIDL
61     private ISupplicantStaIfaceHal mStaIfaceHal;
62 
63     // Common enums declared here to be independent from HIDL/AIDL.
64     // See HAL comments for more information on each.
65     protected static class DppAkm {
66         public static final int PSK = 0;
67         public static final int PSK_SAE = 1;
68         public static final int SAE = 2;
69         public static final int DPP = 3;
70     }
71 
72     protected static class DppCurve {
73         public static final int PRIME256V1 = 0;
74         public static final int SECP384R1 = 1;
75         public static final int SECP521R1 = 2;
76         public static final int BRAINPOOLP256R1 = 3;
77         public static final int BRAINPOOLP384R1 = 4;
78         public static final int BRAINPOOLP512R1 = 5;
79     }
80 
81     protected static class DppNetRole {
82         public static final int STA = 0;
83         public static final int AP = 1;
84     }
85 
86     protected static class DppEventType {
87         public static final int CONFIGURATION_SENT = 0;
88         public static final int CONFIGURATION_APPLIED = 1;
89     }
90 
91     protected static class DppFailureCode {
92         public static final int INVALID_URI = 0;
93         public static final int AUTHENTICATION = 1;
94         public static final int NOT_COMPATIBLE = 2;
95         public static final int CONFIGURATION = 3;
96         public static final int BUSY = 4;
97         public static final int TIMEOUT = 5;
98         public static final int FAILURE = 6;
99         public static final int NOT_SUPPORTED = 7;
100         public static final int CONFIGURATION_REJECTED = 8;
101         public static final int CANNOT_FIND_NETWORK = 9;
102         public static final int ENROLLEE_AUTHENTICATION = 10;
103         public static final int URI_GENERATION = 11;
104     }
105 
106     protected static class DppProgressCode {
107         public static final int AUTHENTICATION_SUCCESS = 0;
108         public static final int RESPONSE_PENDING = 1;
109         public static final int CONFIGURATION_SENT_WAITING_RESPONSE = 2;
110         public static final int CONFIGURATION_ACCEPTED = 3;
111     }
112 
113     protected static class MboAssocDisallowedReasonCode {
114         public static final byte RESERVED = 0;
115         public static final byte UNSPECIFIED = 1;
116         public static final byte MAX_NUM_STA_ASSOCIATED = 2;
117         public static final byte AIR_INTERFACE_OVERLOADED = 3;
118         public static final byte AUTH_SERVER_OVERLOADED = 4;
119         public static final byte INSUFFICIENT_RSSI = 5;
120     }
121 
122     protected static class StaIfaceReasonCode {
123         public static final int UNSPECIFIED = 1;
124         public static final int PREV_AUTH_NOT_VALID = 2;
125         public static final int DEAUTH_LEAVING = 3;
126         public static final int DISASSOC_DUE_TO_INACTIVITY = 4;
127         public static final int DISASSOC_AP_BUSY = 5;
128         public static final int CLASS2_FRAME_FROM_NONAUTH_STA = 6;
129         public static final int CLASS3_FRAME_FROM_NONASSOC_STA = 7;
130         public static final int DISASSOC_STA_HAS_LEFT = 8;
131         public static final int STA_REQ_ASSOC_WITHOUT_AUTH = 9;
132         public static final int PWR_CAPABILITY_NOT_VALID = 10;
133         public static final int SUPPORTED_CHANNEL_NOT_VALID = 11;
134         public static final int BSS_TRANSITION_DISASSOC = 12;
135         public static final int INVALID_IE = 13;
136         public static final int MICHAEL_MIC_FAILURE = 14;
137         public static final int FOURWAY_HANDSHAKE_TIMEOUT = 15;
138         public static final int GROUP_KEY_UPDATE_TIMEOUT = 16;
139         public static final int IE_IN_4WAY_DIFFERS = 17;
140         public static final int GROUP_CIPHER_NOT_VALID = 18;
141         public static final int PAIRWISE_CIPHER_NOT_VALID = 19;
142         public static final int AKMP_NOT_VALID = 20;
143         public static final int UNSUPPORTED_RSN_IE_VERSION = 21;
144         public static final int INVALID_RSN_IE_CAPAB = 22;
145         public static final int IEEE_802_1X_AUTH_FAILED = 23;
146         public static final int CIPHER_SUITE_REJECTED = 24;
147         public static final int TDLS_TEARDOWN_UNREACHABLE = 25;
148         public static final int TDLS_TEARDOWN_UNSPECIFIED = 26;
149         public static final int SSP_REQUESTED_DISASSOC = 27;
150         public static final int NO_SSP_ROAMING_AGREEMENT = 28;
151         public static final int BAD_CIPHER_OR_AKM = 29;
152         public static final int NOT_AUTHORIZED_THIS_LOCATION = 30;
153         public static final int SERVICE_CHANGE_PRECLUDES_TS = 31;
154         public static final int UNSPECIFIED_QOS_REASON = 32;
155         public static final int NOT_ENOUGH_BANDWIDTH = 33;
156         public static final int DISASSOC_LOW_ACK = 34;
157         public static final int EXCEEDED_TXOP = 35;
158         public static final int STA_LEAVING = 36;
159         public static final int END_TS_BA_DLS = 37;
160         public static final int UNKNOWN_TS_BA = 38;
161         public static final int TIMEOUT = 39;
162         public static final int PEERKEY_MISMATCH = 45;
163         public static final int AUTHORIZED_ACCESS_LIMIT_REACHED = 46;
164         public static final int EXTERNAL_SERVICE_REQUIREMENTS = 47;
165         public static final int INVALID_FT_ACTION_FRAME_COUNT = 48;
166         public static final int INVALID_PMKID = 49;
167         public static final int INVALID_MDE = 50;
168         public static final int INVALID_FTE = 51;
169         public static final int MESH_PEERING_CANCELLED = 52;
170         public static final int MESH_MAX_PEERS = 53;
171         public static final int MESH_CONFIG_POLICY_VIOLATION = 54;
172         public static final int MESH_CLOSE_RCVD = 55;
173         public static final int MESH_MAX_RETRIES = 56;
174         public static final int MESH_CONFIRM_TIMEOUT = 57;
175         public static final int MESH_INVALID_GTK = 58;
176         public static final int MESH_INCONSISTENT_PARAMS = 59;
177         public static final int MESH_INVALID_SECURITY_CAP = 60;
178         public static final int MESH_PATH_ERROR_NO_PROXY_INFO = 61;
179         public static final int MESH_PATH_ERROR_NO_FORWARDING_INFO = 62;
180         public static final int MESH_PATH_ERROR_DEST_UNREACHABLE = 63;
181         public static final int MAC_ADDRESS_ALREADY_EXISTS_IN_MBSS = 64;
182         public static final int MESH_CHANNEL_SWITCH_REGULATORY_REQ = 65;
183         public static final int MESH_CHANNEL_SWITCH_UNSPECIFIED = 66;
184 
toString(int code)185         public static String toString(int code) {
186             switch(code) {
187                 case UNSPECIFIED:
188                     return "UNSPECIFIED";
189                 case PREV_AUTH_NOT_VALID:
190                     return "PREV_AUTH_NOT_VALID";
191                 case DEAUTH_LEAVING:
192                     return "DEAUTH_LEAVING";
193                 case DISASSOC_DUE_TO_INACTIVITY:
194                     return "DISASSOC_DUE_TO_INACTIVITY";
195                 case DISASSOC_AP_BUSY:
196                     return "DISASSOC_AP_BUSY";
197                 case CLASS2_FRAME_FROM_NONAUTH_STA:
198                     return "CLASS2_FRAME_FROM_NONAUTH_STA";
199                 case CLASS3_FRAME_FROM_NONASSOC_STA:
200                     return "CLASS3_FRAME_FROM_NONASSOC_STA";
201                 case DISASSOC_STA_HAS_LEFT:
202                     return "DISASSOC_STA_HAS_LEFT";
203                 case STA_REQ_ASSOC_WITHOUT_AUTH:
204                     return "STA_REQ_ASSOC_WITHOUT_AUTH";
205                 case PWR_CAPABILITY_NOT_VALID:
206                     return "PWR_CAPABILITY_NOT_VALID";
207                 case SUPPORTED_CHANNEL_NOT_VALID:
208                     return "SUPPORTED_CHANNEL_NOT_VALID";
209                 case BSS_TRANSITION_DISASSOC:
210                     return "BSS_TRANSITION_DISASSOC";
211                 case INVALID_IE:
212                     return "INVALID_IE";
213                 case MICHAEL_MIC_FAILURE:
214                     return "MICHAEL_MIC_FAILURE";
215                 case FOURWAY_HANDSHAKE_TIMEOUT:
216                     return "FOURWAY_HANDSHAKE_TIMEOUT";
217                 case GROUP_KEY_UPDATE_TIMEOUT:
218                     return "GROUP_KEY_UPDATE_TIMEOUT";
219                 case IE_IN_4WAY_DIFFERS:
220                     return "IE_IN_4WAY_DIFFERS";
221                 case GROUP_CIPHER_NOT_VALID:
222                     return "GROUP_CIPHER_NOT_VALID";
223                 case PAIRWISE_CIPHER_NOT_VALID:
224                     return "PAIRWISE_CIPHER_NOT_VALID";
225                 case AKMP_NOT_VALID:
226                     return "AKMP_NOT_VALID";
227                 case UNSUPPORTED_RSN_IE_VERSION:
228                     return "UNSUPPORTED_RSN_IE_VERSION";
229                 case INVALID_RSN_IE_CAPAB:
230                     return "INVALID_RSN_IE_CAPAB";
231                 case IEEE_802_1X_AUTH_FAILED:
232                     return "IEEE_802_1X_AUTH_FAILED";
233                 case CIPHER_SUITE_REJECTED:
234                     return "CIPHER_SUITE_REJECTED";
235                 case TDLS_TEARDOWN_UNREACHABLE:
236                     return "TDLS_TEARDOWN_UNREACHABLE";
237                 case TDLS_TEARDOWN_UNSPECIFIED:
238                     return "TDLS_TEARDOWN_UNSPECIFIED";
239                 case SSP_REQUESTED_DISASSOC:
240                     return "SSP_REQUESTED_DISASSOC";
241                 case NO_SSP_ROAMING_AGREEMENT:
242                     return "NO_SSP_ROAMING_AGREEMENT";
243                 case BAD_CIPHER_OR_AKM:
244                     return "BAD_CIPHER_OR_AKM";
245                 case NOT_AUTHORIZED_THIS_LOCATION:
246                     return "NOT_AUTHORIZED_THIS_LOCATION";
247                 case SERVICE_CHANGE_PRECLUDES_TS:
248                     return "SERVICE_CHANGE_PRECLUDES_TS";
249                 case UNSPECIFIED_QOS_REASON:
250                     return "UNSPECIFIED_QOS_REASON";
251                 case NOT_ENOUGH_BANDWIDTH:
252                     return "NOT_ENOUGH_BANDWIDTH";
253                 case DISASSOC_LOW_ACK:
254                     return "DISASSOC_LOW_ACK";
255                 case EXCEEDED_TXOP:
256                     return "EXCEEDED_TXOP";
257                 case STA_LEAVING:
258                     return "STA_LEAVING";
259                 case END_TS_BA_DLS:
260                     return "END_TS_BA_DLS";
261                 case UNKNOWN_TS_BA:
262                     return "UNKNOWN_TS_BA";
263                 case TIMEOUT:
264                     return "TIMEOUT";
265                 case PEERKEY_MISMATCH:
266                     return "PEERKEY_MISMATCH";
267                 case AUTHORIZED_ACCESS_LIMIT_REACHED:
268                     return "AUTHORIZED_ACCESS_LIMIT_REACHED";
269                 case EXTERNAL_SERVICE_REQUIREMENTS:
270                     return "EXTERNAL_SERVICE_REQUIREMENTS";
271                 case INVALID_FT_ACTION_FRAME_COUNT:
272                     return "INVALID_FT_ACTION_FRAME_COUNT";
273                 case INVALID_PMKID:
274                     return "INVALID_PMKID";
275                 case INVALID_MDE:
276                     return "INVALID_MDE";
277                 case INVALID_FTE:
278                     return "INVALID_FTE";
279                 case MESH_PEERING_CANCELLED:
280                     return "MESH_PEERING_CANCELLED";
281                 case MESH_MAX_PEERS:
282                     return "MESH_MAX_PEERS";
283                 case MESH_CONFIG_POLICY_VIOLATION:
284                     return "MESH_CONFIG_POLICY_VIOLATION";
285                 case MESH_CLOSE_RCVD:
286                     return "MESH_CLOSE_RCVD";
287                 case MESH_MAX_RETRIES:
288                     return "MESH_MAX_RETRIES";
289                 case MESH_CONFIRM_TIMEOUT:
290                     return "MESH_CONFIRM_TIMEOUT";
291                 case MESH_INVALID_GTK:
292                     return "MESH_INVALID_GTK";
293                 case MESH_INCONSISTENT_PARAMS:
294                     return "MESH_INCONSISTENT_PARAMS";
295                 case MESH_INVALID_SECURITY_CAP:
296                     return "MESH_INVALID_SECURITY_CAP";
297                 case MESH_PATH_ERROR_NO_PROXY_INFO:
298                     return "MESH_PATH_ERROR_NO_PROXY_INFO";
299                 case MESH_PATH_ERROR_NO_FORWARDING_INFO:
300                     return "MESH_PATH_ERROR_NO_FORWARDING_INFO";
301                 case MESH_PATH_ERROR_DEST_UNREACHABLE:
302                     return "MESH_PATH_ERROR_DEST_UNREACHABLE";
303                 case MAC_ADDRESS_ALREADY_EXISTS_IN_MBSS:
304                     return "MAC_ADDRESS_ALREADY_EXISTS_IN_MBSS";
305                 case MESH_CHANNEL_SWITCH_REGULATORY_REQ:
306                     return "MESH_CHANNEL_SWITCH_REGULATORY_REQ";
307                 case MESH_CHANNEL_SWITCH_UNSPECIFIED:
308                     return "MESH_CHANNEL_SWITCH_UNSPECIFIED";
309                 default:
310                     return "Unknown StaIfaceReasonCode: " + code;
311             }
312         }
313     }
314 
315     protected static class StaIfaceStatusCode {
316         public static final int SUCCESS = 0;
317         public static final int UNSPECIFIED_FAILURE = 1;
318         public static final int TDLS_WAKEUP_ALTERNATE = 2;
319         public static final int TDLS_WAKEUP_REJECT = 3;
320         public static final int SECURITY_DISABLED = 5;
321         public static final int UNACCEPTABLE_LIFETIME = 6;
322         public static final int NOT_IN_SAME_BSS = 7;
323         public static final int CAPS_UNSUPPORTED = 10;
324         public static final int REASSOC_NO_ASSOC = 11;
325         public static final int ASSOC_DENIED_UNSPEC = 12;
326         public static final int NOT_SUPPORTED_AUTH_ALG = 13;
327         public static final int UNKNOWN_AUTH_TRANSACTION = 14;
328         public static final int CHALLENGE_FAIL = 15;
329         public static final int AUTH_TIMEOUT = 16;
330         public static final int AP_UNABLE_TO_HANDLE_NEW_STA = 17;
331         public static final int ASSOC_DENIED_RATES = 18;
332         public static final int ASSOC_DENIED_NOSHORT = 19;
333         public static final int SPEC_MGMT_REQUIRED = 22;
334         public static final int PWR_CAPABILITY_NOT_VALID = 23;
335         public static final int SUPPORTED_CHANNEL_NOT_VALID = 24;
336         public static final int ASSOC_DENIED_NO_SHORT_SLOT_TIME = 25;
337         public static final int ASSOC_DENIED_NO_HT = 27;
338         public static final int R0KH_UNREACHABLE = 28;
339         public static final int ASSOC_DENIED_NO_PCO = 29;
340         public static final int ASSOC_REJECTED_TEMPORARILY = 30;
341         public static final int ROBUST_MGMT_FRAME_POLICY_VIOLATION = 31;
342         public static final int UNSPECIFIED_QOS_FAILURE = 32;
343         public static final int DENIED_INSUFFICIENT_BANDWIDTH = 33;
344         public static final int DENIED_POOR_CHANNEL_CONDITIONS = 34;
345         public static final int DENIED_QOS_NOT_SUPPORTED = 35;
346         public static final int REQUEST_DECLINED = 37;
347         public static final int INVALID_PARAMETERS = 38;
348         public static final int REJECTED_WITH_SUGGESTED_CHANGES = 39;
349         public static final int INVALID_IE = 40;
350         public static final int GROUP_CIPHER_NOT_VALID = 41;
351         public static final int PAIRWISE_CIPHER_NOT_VALID = 42;
352         public static final int AKMP_NOT_VALID = 43;
353         public static final int UNSUPPORTED_RSN_IE_VERSION = 44;
354         public static final int INVALID_RSN_IE_CAPAB = 45;
355         public static final int CIPHER_REJECTED_PER_POLICY = 46;
356         public static final int TS_NOT_CREATED = 47;
357         public static final int DIRECT_LINK_NOT_ALLOWED = 48;
358         public static final int DEST_STA_NOT_PRESENT = 49;
359         public static final int DEST_STA_NOT_QOS_STA = 50;
360         public static final int ASSOC_DENIED_LISTEN_INT_TOO_LARGE = 51;
361         public static final int INVALID_FT_ACTION_FRAME_COUNT = 52;
362         public static final int INVALID_PMKID = 53;
363         public static final int INVALID_MDIE = 54;
364         public static final int INVALID_FTIE = 55;
365         public static final int REQUESTED_TCLAS_NOT_SUPPORTED = 56;
366         public static final int INSUFFICIENT_TCLAS_PROCESSING_RESOURCES = 57;
367         public static final int TRY_ANOTHER_BSS = 58;
368         public static final int GAS_ADV_PROTO_NOT_SUPPORTED = 59;
369         public static final int NO_OUTSTANDING_GAS_REQ = 60;
370         public static final int GAS_RESP_NOT_RECEIVED = 61;
371         public static final int STA_TIMED_OUT_WAITING_FOR_GAS_RESP = 62;
372         public static final int GAS_RESP_LARGER_THAN_LIMIT = 63;
373         public static final int REQ_REFUSED_HOME = 64;
374         public static final int ADV_SRV_UNREACHABLE = 65;
375         public static final int REQ_REFUSED_SSPN = 67;
376         public static final int REQ_REFUSED_UNAUTH_ACCESS = 68;
377         public static final int INVALID_RSNIE = 72;
378         public static final int U_APSD_COEX_NOT_SUPPORTED = 73;
379         public static final int U_APSD_COEX_MODE_NOT_SUPPORTED = 74;
380         public static final int BAD_INTERVAL_WITH_U_APSD_COEX = 75;
381         public static final int ANTI_CLOGGING_TOKEN_REQ = 76;
382         public static final int FINITE_CYCLIC_GROUP_NOT_SUPPORTED = 77;
383         public static final int CANNOT_FIND_ALT_TBTT = 78;
384         public static final int TRANSMISSION_FAILURE = 79;
385         public static final int REQ_TCLAS_NOT_SUPPORTED = 80;
386         public static final int TCLAS_RESOURCES_EXCHAUSTED = 81;
387         public static final int REJECTED_WITH_SUGGESTED_BSS_TRANSITION = 82;
388         public static final int REJECT_WITH_SCHEDULE = 83;
389         public static final int REJECT_NO_WAKEUP_SPECIFIED = 84;
390         public static final int SUCCESS_POWER_SAVE_MODE = 85;
391         public static final int PENDING_ADMITTING_FST_SESSION = 86;
392         public static final int PERFORMING_FST_NOW = 87;
393         public static final int PENDING_GAP_IN_BA_WINDOW = 88;
394         public static final int REJECT_U_PID_SETTING = 89;
395         public static final int REFUSED_EXTERNAL_REASON = 92;
396         public static final int REFUSED_AP_OUT_OF_MEMORY = 93;
397         public static final int REJECTED_EMERGENCY_SERVICE_NOT_SUPPORTED = 94;
398         public static final int QUERY_RESP_OUTSTANDING = 95;
399         public static final int REJECT_DSE_BAND = 96;
400         public static final int TCLAS_PROCESSING_TERMINATED = 97;
401         public static final int TS_SCHEDULE_CONFLICT = 98;
402         public static final int DENIED_WITH_SUGGESTED_BAND_AND_CHANNEL = 99;
403         public static final int MCCAOP_RESERVATION_CONFLICT = 100;
404         public static final int MAF_LIMIT_EXCEEDED = 101;
405         public static final int MCCA_TRACK_LIMIT_EXCEEDED = 102;
406         public static final int DENIED_DUE_TO_SPECTRUM_MANAGEMENT = 103;
407         public static final int ASSOC_DENIED_NO_VHT = 104;
408         public static final int ENABLEMENT_DENIED = 105;
409         public static final int RESTRICTION_FROM_AUTHORIZED_GDB = 106;
410         public static final int AUTHORIZATION_DEENABLED = 107;
411         public static final int FILS_AUTHENTICATION_FAILURE = 112;
412         public static final int UNKNOWN_AUTHENTICATION_SERVER = 113;
413 
toString(int code)414         public static String toString(int code) {
415             switch(code) {
416                 case SUCCESS:
417                     return "SUCCESS";
418                 case UNSPECIFIED_FAILURE:
419                     return "UNSPECIFIED_FAILURE";
420                 case TDLS_WAKEUP_ALTERNATE:
421                     return "TDLS_WAKEUP_ALTERNATE";
422                 case TDLS_WAKEUP_REJECT:
423                     return "TDLS_WAKEUP_REJECT";
424                 case SECURITY_DISABLED:
425                     return "SECURITY_DISABLED";
426                 case UNACCEPTABLE_LIFETIME:
427                     return "UNACCEPTABLE_LIFETIME";
428                 case NOT_IN_SAME_BSS:
429                     return "NOT_IN_SAME_BSS";
430                 case CAPS_UNSUPPORTED:
431                     return "CAPS_UNSUPPORTED";
432                 case REASSOC_NO_ASSOC:
433                     return "REASSOC_NO_ASSOC";
434                 case ASSOC_DENIED_UNSPEC:
435                     return "ASSOC_DENIED_UNSPEC";
436                 case NOT_SUPPORTED_AUTH_ALG:
437                     return "NOT_SUPPORTED_AUTH_ALG";
438                 case UNKNOWN_AUTH_TRANSACTION:
439                     return "UNKNOWN_AUTH_TRANSACTION";
440                 case CHALLENGE_FAIL:
441                     return "CHALLENGE_FAIL";
442                 case AUTH_TIMEOUT:
443                     return "AUTH_TIMEOUT";
444                 case AP_UNABLE_TO_HANDLE_NEW_STA:
445                     return "AP_UNABLE_TO_HANDLE_NEW_STA";
446                 case ASSOC_DENIED_RATES:
447                     return "ASSOC_DENIED_RATES";
448                 case ASSOC_DENIED_NOSHORT:
449                     return "ASSOC_DENIED_NOSHORT";
450                 case SPEC_MGMT_REQUIRED:
451                     return "SPEC_MGMT_REQUIRED";
452                 case PWR_CAPABILITY_NOT_VALID:
453                     return "PWR_CAPABILITY_NOT_VALID";
454                 case SUPPORTED_CHANNEL_NOT_VALID:
455                     return "SUPPORTED_CHANNEL_NOT_VALID";
456                 case ASSOC_DENIED_NO_SHORT_SLOT_TIME:
457                     return "ASSOC_DENIED_NO_SHORT_SLOT_TIME";
458                 case ASSOC_DENIED_NO_HT:
459                     return "ASSOC_DENIED_NO_HT";
460                 case R0KH_UNREACHABLE:
461                     return "R0KH_UNREACHABLE";
462                 case ASSOC_DENIED_NO_PCO:
463                     return "ASSOC_DENIED_NO_PCO";
464                 case ASSOC_REJECTED_TEMPORARILY:
465                     return "ASSOC_REJECTED_TEMPORARILY";
466                 case ROBUST_MGMT_FRAME_POLICY_VIOLATION:
467                     return "ROBUST_MGMT_FRAME_POLICY_VIOLATION";
468                 case UNSPECIFIED_QOS_FAILURE:
469                     return "UNSPECIFIED_QOS_FAILURE";
470                 case DENIED_INSUFFICIENT_BANDWIDTH:
471                     return "DENIED_INSUFFICIENT_BANDWIDTH";
472                 case DENIED_POOR_CHANNEL_CONDITIONS:
473                     return "DENIED_POOR_CHANNEL_CONDITIONS";
474                 case DENIED_QOS_NOT_SUPPORTED:
475                     return "DENIED_QOS_NOT_SUPPORTED";
476                 case REQUEST_DECLINED:
477                     return "REQUEST_DECLINED";
478                 case INVALID_PARAMETERS:
479                     return "INVALID_PARAMETERS";
480                 case REJECTED_WITH_SUGGESTED_CHANGES:
481                     return "REJECTED_WITH_SUGGESTED_CHANGES";
482                 case INVALID_IE:
483                     return "INVALID_IE";
484                 case GROUP_CIPHER_NOT_VALID:
485                     return "GROUP_CIPHER_NOT_VALID";
486                 case PAIRWISE_CIPHER_NOT_VALID:
487                     return "PAIRWISE_CIPHER_NOT_VALID";
488                 case AKMP_NOT_VALID:
489                     return "AKMP_NOT_VALID";
490                 case UNSUPPORTED_RSN_IE_VERSION:
491                     return "UNSUPPORTED_RSN_IE_VERSION";
492                 case INVALID_RSN_IE_CAPAB:
493                     return "INVALID_RSN_IE_CAPAB";
494                 case CIPHER_REJECTED_PER_POLICY:
495                     return "CIPHER_REJECTED_PER_POLICY";
496                 case TS_NOT_CREATED:
497                     return "TS_NOT_CREATED";
498                 case DIRECT_LINK_NOT_ALLOWED:
499                     return "DIRECT_LINK_NOT_ALLOWED";
500                 case DEST_STA_NOT_PRESENT:
501                     return "DEST_STA_NOT_PRESENT";
502                 case DEST_STA_NOT_QOS_STA:
503                     return "DEST_STA_NOT_QOS_STA";
504                 case ASSOC_DENIED_LISTEN_INT_TOO_LARGE:
505                     return "ASSOC_DENIED_LISTEN_INT_TOO_LARGE";
506                 case INVALID_FT_ACTION_FRAME_COUNT:
507                     return "INVALID_FT_ACTION_FRAME_COUNT";
508                 case INVALID_PMKID:
509                     return "INVALID_PMKID";
510                 case INVALID_MDIE:
511                     return "INVALID_MDIE";
512                 case INVALID_FTIE:
513                     return "INVALID_FTIE";
514                 case REQUESTED_TCLAS_NOT_SUPPORTED:
515                     return "REQUESTED_TCLAS_NOT_SUPPORTED";
516                 case INSUFFICIENT_TCLAS_PROCESSING_RESOURCES:
517                     return "INSUFFICIENT_TCLAS_PROCESSING_RESOURCES";
518                 case TRY_ANOTHER_BSS:
519                     return "TRY_ANOTHER_BSS";
520                 case GAS_ADV_PROTO_NOT_SUPPORTED:
521                     return "GAS_ADV_PROTO_NOT_SUPPORTED";
522                 case NO_OUTSTANDING_GAS_REQ:
523                     return "NO_OUTSTANDING_GAS_REQ";
524                 case GAS_RESP_NOT_RECEIVED:
525                     return "GAS_RESP_NOT_RECEIVED";
526                 case STA_TIMED_OUT_WAITING_FOR_GAS_RESP:
527                     return "STA_TIMED_OUT_WAITING_FOR_GAS_RESP";
528                 case GAS_RESP_LARGER_THAN_LIMIT:
529                     return "GAS_RESP_LARGER_THAN_LIMIT";
530                 case REQ_REFUSED_HOME:
531                     return "REQ_REFUSED_HOME";
532                 case ADV_SRV_UNREACHABLE:
533                     return "ADV_SRV_UNREACHABLE";
534                 case REQ_REFUSED_SSPN:
535                     return "REQ_REFUSED_SSPN";
536                 case REQ_REFUSED_UNAUTH_ACCESS:
537                     return "REQ_REFUSED_UNAUTH_ACCESS";
538                 case INVALID_RSNIE:
539                     return "INVALID_RSNIE";
540                 case U_APSD_COEX_NOT_SUPPORTED:
541                     return "U_APSD_COEX_NOT_SUPPORTED";
542                 case U_APSD_COEX_MODE_NOT_SUPPORTED:
543                     return "U_APSD_COEX_MODE_NOT_SUPPORTED";
544                 case BAD_INTERVAL_WITH_U_APSD_COEX:
545                     return "BAD_INTERVAL_WITH_U_APSD_COEX";
546                 case ANTI_CLOGGING_TOKEN_REQ:
547                     return "ANTI_CLOGGING_TOKEN_REQ";
548                 case FINITE_CYCLIC_GROUP_NOT_SUPPORTED:
549                     return "FINITE_CYCLIC_GROUP_NOT_SUPPORTED";
550                 case CANNOT_FIND_ALT_TBTT:
551                     return "CANNOT_FIND_ALT_TBTT";
552                 case TRANSMISSION_FAILURE:
553                     return "TRANSMISSION_FAILURE";
554                 case REQ_TCLAS_NOT_SUPPORTED:
555                     return "REQ_TCLAS_NOT_SUPPORTED";
556                 case TCLAS_RESOURCES_EXCHAUSTED:
557                     return "TCLAS_RESOURCES_EXCHAUSTED";
558                 case REJECTED_WITH_SUGGESTED_BSS_TRANSITION:
559                     return "REJECTED_WITH_SUGGESTED_BSS_TRANSITION";
560                 case REJECT_WITH_SCHEDULE:
561                     return "REJECT_WITH_SCHEDULE";
562                 case REJECT_NO_WAKEUP_SPECIFIED:
563                     return "REJECT_NO_WAKEUP_SPECIFIED";
564                 case SUCCESS_POWER_SAVE_MODE:
565                     return "SUCCESS_POWER_SAVE_MODE";
566                 case PENDING_ADMITTING_FST_SESSION:
567                     return "PENDING_ADMITTING_FST_SESSION";
568                 case PERFORMING_FST_NOW:
569                     return "PERFORMING_FST_NOW";
570                 case PENDING_GAP_IN_BA_WINDOW:
571                     return "PENDING_GAP_IN_BA_WINDOW";
572                 case REJECT_U_PID_SETTING:
573                     return "REJECT_U_PID_SETTING";
574                 case REFUSED_EXTERNAL_REASON:
575                     return "REFUSED_EXTERNAL_REASON";
576                 case REFUSED_AP_OUT_OF_MEMORY:
577                     return "REFUSED_AP_OUT_OF_MEMORY";
578                 case REJECTED_EMERGENCY_SERVICE_NOT_SUPPORTED:
579                     return "REJECTED_EMERGENCY_SERVICE_NOT_SUPPORTED";
580                 case QUERY_RESP_OUTSTANDING:
581                     return "QUERY_RESP_OUTSTANDING";
582                 case REJECT_DSE_BAND:
583                     return "REJECT_DSE_BAND";
584                 case TCLAS_PROCESSING_TERMINATED:
585                     return "TCLAS_PROCESSING_TERMINATED";
586                 case TS_SCHEDULE_CONFLICT:
587                     return "TS_SCHEDULE_CONFLICT";
588                 case DENIED_WITH_SUGGESTED_BAND_AND_CHANNEL:
589                     return "DENIED_WITH_SUGGESTED_BAND_AND_CHANNEL";
590                 case MCCAOP_RESERVATION_CONFLICT:
591                     return "MCCAOP_RESERVATION_CONFLICT";
592                 case MAF_LIMIT_EXCEEDED:
593                     return "MAF_LIMIT_EXCEEDED";
594                 case MCCA_TRACK_LIMIT_EXCEEDED:
595                     return "MCCA_TRACK_LIMIT_EXCEEDED";
596                 case DENIED_DUE_TO_SPECTRUM_MANAGEMENT:
597                     return "DENIED_DUE_TO_SPECTRUM_MANAGEMENT";
598                 case ASSOC_DENIED_NO_VHT:
599                     return "ASSOC_DENIED_NO_VHT";
600                 case ENABLEMENT_DENIED:
601                     return "ENABLEMENT_DENIED";
602                 case RESTRICTION_FROM_AUTHORIZED_GDB:
603                     return "RESTRICTION_FROM_AUTHORIZED_GDB";
604                 case AUTHORIZATION_DEENABLED:
605                     return "AUTHORIZATION_DEENABLED";
606                 case FILS_AUTHENTICATION_FAILURE:
607                     return "FILS_AUTHENTICATION_FAILURE";
608                 case UNKNOWN_AUTHENTICATION_SERVER:
609                     return "UNKNOWN_AUTHENTICATION_SERVER";
610                 default:
611                     return "Unknown StaIfaceStatusCode: " + code;
612             }
613         }
614     }
615 
616     protected static final int SUPPLICANT_EVENT_CONNECTED = 0;
617     protected static final int SUPPLICANT_EVENT_DISCONNECTED = 1;
618     protected static final int SUPPLICANT_EVENT_ASSOCIATING = 2;
619     protected static final int SUPPLICANT_EVENT_ASSOCIATED = 3;
620     protected static final int SUPPLICANT_EVENT_EAP_METHOD_SELECTED = 4;
621     protected static final int SUPPLICANT_EVENT_EAP_FAILURE = 5;
622     protected static final int SUPPLICANT_EVENT_SSID_TEMP_DISABLED = 6;
623     protected static final int SUPPLICANT_EVENT_OPEN_SSL_FAILURE = 7;
624 
625     @IntDef(prefix = { "SUPPLICANT_EVENT_" }, value = {
626             SUPPLICANT_EVENT_CONNECTED,
627             SUPPLICANT_EVENT_DISCONNECTED,
628             SUPPLICANT_EVENT_ASSOCIATING,
629             SUPPLICANT_EVENT_ASSOCIATED,
630             SUPPLICANT_EVENT_EAP_METHOD_SELECTED,
631             SUPPLICANT_EVENT_EAP_FAILURE,
632             SUPPLICANT_EVENT_SSID_TEMP_DISABLED,
633             SUPPLICANT_EVENT_OPEN_SSL_FAILURE,
634     })
635     @Retention(RetentionPolicy.SOURCE)
636     protected @interface SupplicantEventCode {}
637 
supplicantEventCodeToString(@upplicantEventCode int eventCode)638     protected static String supplicantEventCodeToString(@SupplicantEventCode int eventCode) {
639         switch (eventCode) {
640             case SUPPLICANT_EVENT_CONNECTED:
641                 return "CONNECTED";
642             case SUPPLICANT_EVENT_DISCONNECTED:
643                 return "DISCONNECTED";
644             case SUPPLICANT_EVENT_ASSOCIATING:
645                 return "ASSOCIATING";
646             case SUPPLICANT_EVENT_ASSOCIATED:
647                 return "ASSOCIATED";
648             case SUPPLICANT_EVENT_EAP_METHOD_SELECTED:
649                 return "EAP_METHOD_SELECTED";
650             case SUPPLICANT_EVENT_EAP_FAILURE:
651                 return "EAP_FAILURE";
652             case SUPPLICANT_EVENT_SSID_TEMP_DISABLED:
653                 return "SSID_TEMP_DISABLED";
654             case SUPPLICANT_EVENT_OPEN_SSL_FAILURE:
655                 return "OPEN_SSL_FAILURE";
656             default:
657                 return "Invalid SupplicantEventCode: " + eventCode;
658         }
659     }
660 
661     protected static final int QOS_POLICY_REQUEST_ADD = 0;
662     protected static final int QOS_POLICY_REQUEST_REMOVE = 1;
663 
664     @IntDef(prefix = { "QOS_POLICY_REQUEST_" }, value = {
665             QOS_POLICY_REQUEST_ADD,
666             QOS_POLICY_REQUEST_REMOVE
667     })
668     @Retention(RetentionPolicy.SOURCE)
669     protected @interface QosPolicyRequestType {}
670 
671     protected static class QosPolicyRequest {
672         public final byte policyId;
673         public final @QosPolicyRequestType int requestType;
674         public final byte dscp;
675         public final QosPolicyClassifierParams classifierParams;
676 
QosPolicyRequest(byte halPolicyId, @QosPolicyRequestType int halRequestType, byte halDscp, @NonNull QosPolicyClassifierParams frameworkClassifierParams)677         public QosPolicyRequest(byte halPolicyId, @QosPolicyRequestType int halRequestType,
678                 byte halDscp, @NonNull QosPolicyClassifierParams frameworkClassifierParams) {
679             policyId = halPolicyId;
680             dscp = halDscp;
681             requestType = halRequestType;
682             classifierParams = frameworkClassifierParams;
683         }
684 
isAddRequest()685         public boolean isAddRequest() {
686             return requestType == QOS_POLICY_REQUEST_ADD;
687         }
688 
isRemoveRequest()689         public boolean isRemoveRequest() {
690             return requestType == QOS_POLICY_REQUEST_REMOVE;
691         }
692 
693         @Override
toString()694         public String toString() {
695             return "policyId: " + policyId + ", isAddRequest: " + this.isAddRequest()
696                     + ", isRemoveRequest: " + this.isRemoveRequest() + ", dscp: " + dscp
697                     + ", classifierParams: {" + classifierParams + "}";
698         }
699     }
700 
701     protected static class QosPolicyClassifierParams {
702         public InetAddress srcIp = null;
703         public InetAddress dstIp = null;
704         public Range dstPortRange = null;
705         public final int srcPort;
706         public final int protocol;
707 
708         public final boolean hasSrcIp;
709         public final boolean hasDstIp;
710         public boolean isValid = true;
711 
QosPolicyClassifierParams(boolean halHasSrcIp, byte[] halSrcIp, boolean halHasDstIp, byte[] halDstIp, int halSrcPort, int[] halDstPortRange, int halProtocol)712         public QosPolicyClassifierParams(boolean halHasSrcIp, byte[] halSrcIp, boolean halHasDstIp,
713                 byte[] halDstIp, int halSrcPort, int[] halDstPortRange, int halProtocol) {
714             srcPort = halSrcPort;
715             protocol = halProtocol;
716 
717             hasSrcIp = halHasSrcIp;
718             if (hasSrcIp) {
719                 try {
720                     srcIp = InetAddress.getByAddress(halSrcIp);
721                 } catch (UnknownHostException e) {
722                     isValid = false;
723                 }
724             }
725 
726             hasDstIp = halHasDstIp;
727             if (hasDstIp) {
728                 try {
729                     dstIp = InetAddress.getByAddress(halDstIp);
730                 } catch (UnknownHostException e) {
731                     isValid = false;
732                 }
733             }
734 
735             if (halDstPortRange != null) {
736                 if (halDstPortRange[0] > halDstPortRange[1]) {
737                     isValid = false;
738                 } else {
739                     dstPortRange = new Range(halDstPortRange[0], halDstPortRange[1]);
740                 }
741             }
742         }
743 
744         @Override
toString()745         public String toString() {
746             return "isValid: " + isValid + ", hasSrcIp: " + hasSrcIp + ", hasDstIp: " + hasDstIp
747                     + ", srcIp: " + srcIp + ", dstIp: " + dstIp + ", dstPortRange: " + dstPortRange
748                     + ", srcPort: " + srcPort + ", protocol: " + protocol;
749         }
750     }
751 
752     protected static class QosPolicyStatus {
753         public final int policyId;
754         public final int statusCode;
755 
QosPolicyStatus(int id, int status)756         public QosPolicyStatus(int id, int status) {
757             policyId = id;
758             statusCode = status;
759         }
760 
761         @Override
toString()762         public String toString() {
763             return "{policyId: " + policyId + ", statusCode: " + statusCode + "}";
764         }
765     }
766 
767     protected static final int QOS_POLICY_SCS_REQUEST_STATUS_ERROR_UNKNOWN = -1;
768     protected static final int QOS_POLICY_SCS_REQUEST_STATUS_SENT = 0;
769     protected static final int QOS_POLICY_SCS_REQUEST_STATUS_ALREADY_ACTIVE = 1;
770     protected static final int QOS_POLICY_SCS_REQUEST_STATUS_NOT_EXIST = 2;
771     protected static final int QOS_POLICY_SCS_REQUEST_STATUS_INVALID = 3;
772 
773     @IntDef(prefix = { "QOS_POLICY_SCS_REQUEST_STATUS_" }, value = {
774             QOS_POLICY_SCS_REQUEST_STATUS_ERROR_UNKNOWN,
775             QOS_POLICY_SCS_REQUEST_STATUS_SENT,
776             QOS_POLICY_SCS_REQUEST_STATUS_ALREADY_ACTIVE,
777             QOS_POLICY_SCS_REQUEST_STATUS_NOT_EXIST,
778             QOS_POLICY_SCS_REQUEST_STATUS_INVALID
779     })
780     @Retention(RetentionPolicy.SOURCE)
781     protected @interface QosPolicyScsRequestStatusCode {}
782 
783     protected static final int QOS_POLICY_SCS_RESPONSE_STATUS_ERROR_UNKNOWN = -1;
784     protected static final int QOS_POLICY_SCS_RESPONSE_STATUS_SUCCESS = 0;
785     protected static final int QOS_POLICY_SCS_RESPONSE_STATUS_TCLAS_REQUEST_DECLINED = 1;
786     protected static final int QOS_POLICY_SCS_RESPONSE_STATUS_TCLAS_NOT_SUPPORTED_BY_AP = 2;
787     protected static final int QOS_POLICY_SCS_RESPONSE_STATUS_TCLAS_INSUFFICIENT_RESOURCES = 3;
788     protected static final int QOS_POLICY_SCS_RESPONSE_STATUS_TCLAS_RESOURCES_EXHAUSTED = 4;
789     protected static final int
790             QOS_POLICY_SCS_RESPONSE_STATUS_TCLAS_PROCESSING_TERMINATED_INSUFFICIENT_QOS = 5;
791     protected static final int
792             QOS_POLICY_SCS_RESPONSE_STATUS_TCLAS_PROCESSING_TERMINATED_POLICY_CONFLICT = 6;
793     protected static final int QOS_POLICY_SCS_RESPONSE_STATUS_TCLAS_PROCESSING_TERMINATED = 7;
794     protected static final int QOS_POLICY_SCS_RESPONSE_STATUS_TIMEOUT = 8;
795 
796     @IntDef(prefix = { "QOS_POLICY_SCS_RESPONSE_STATUS_" }, value = {
797             QOS_POLICY_SCS_RESPONSE_STATUS_ERROR_UNKNOWN,
798             QOS_POLICY_SCS_RESPONSE_STATUS_SUCCESS,
799             QOS_POLICY_SCS_RESPONSE_STATUS_TCLAS_REQUEST_DECLINED,
800             QOS_POLICY_SCS_RESPONSE_STATUS_TCLAS_NOT_SUPPORTED_BY_AP,
801             QOS_POLICY_SCS_RESPONSE_STATUS_TCLAS_INSUFFICIENT_RESOURCES,
802             QOS_POLICY_SCS_RESPONSE_STATUS_TCLAS_RESOURCES_EXHAUSTED,
803             QOS_POLICY_SCS_RESPONSE_STATUS_TCLAS_PROCESSING_TERMINATED_INSUFFICIENT_QOS,
804             QOS_POLICY_SCS_RESPONSE_STATUS_TCLAS_PROCESSING_TERMINATED_POLICY_CONFLICT,
805             QOS_POLICY_SCS_RESPONSE_STATUS_TCLAS_PROCESSING_TERMINATED,
806             QOS_POLICY_SCS_RESPONSE_STATUS_TIMEOUT
807     })
808     @Retention(RetentionPolicy.SOURCE)
809     protected @interface QosPolicyScsResponseStatusCode {}
810 
811     /**
812      * Callback to receive responses for QoS SCS transactions.
813      */
814     protected interface QosScsResponseCallback {
815         /**
816          * Called to indicate a response from the AP.
817          *
818          * @param ifaceName Name of the interface where the event occurred.
819          * @param statusList List of {@link QosPolicyStatus} objects. Status code will be
820          *                   one of {@link QosPolicyScsResponseStatusCode}.
821          */
onApResponse(String ifaceName, List<QosPolicyStatus> statusList)822         void onApResponse(String ifaceName, List<QosPolicyStatus> statusList);
823     }
824 
SupplicantStaIfaceHal(Context context, WifiMonitor monitor, FrameworkFacade frameworkFacade, Handler handler, Clock clock, WifiMetrics wifiMetrics, WifiGlobals wifiGlobals, @NonNull SsidTranslator ssidTranslator, WifiInjector wifiInjector)825     public SupplicantStaIfaceHal(Context context, WifiMonitor monitor,
826             FrameworkFacade frameworkFacade, Handler handler,
827             Clock clock, WifiMetrics wifiMetrics,
828             WifiGlobals wifiGlobals,
829             @NonNull SsidTranslator ssidTranslator, WifiInjector wifiInjector) {
830         mContext = context;
831         mWifiMonitor = monitor;
832         mFrameworkFacade = frameworkFacade;
833         mEventHandler = handler;
834         mClock = clock;
835         mWifiMetrics = wifiMetrics;
836         mWifiGlobals = wifiGlobals;
837         mSsidTranslator = ssidTranslator;
838         mWifiInjector = wifiInjector;
839         mStaIfaceHal = createStaIfaceHalMockable();
840         if (mStaIfaceHal == null) {
841             Log.wtf(TAG, "Failed to get internal ISupplicantStaIfaceHal instance.");
842         }
843     }
844 
845     /**
846      * Check whether the HAL service is using AIDL.
847      *
848      * @return true if the AIDL service is being used, false otherwise.
849      */
isAidlService()850     public boolean isAidlService() {
851         return mStaIfaceHal != null && mStaIfaceHal instanceof SupplicantStaIfaceHalAidlImpl;
852     }
853 
854     /**
855      * Check whether the AIDL service is running at least the expected version.
856      *
857      * @param expectedVersion Version number to check.
858      * @return true if the AIDL service is available and >= the expected version, false otherwise.
859      */
isAidlServiceVersionAtLeast(int expectedVersion)860     public boolean isAidlServiceVersionAtLeast(int expectedVersion) {
861         return isAidlService() && ((SupplicantStaIfaceHalAidlImpl) mStaIfaceHal)
862                 .isServiceVersionAtLeast(expectedVersion);
863     }
864 
865     /**
866      * Enable/Disable verbose logging.
867      */
enableVerboseLogging(boolean verboseEnabled, boolean halVerboseEnabled)868     void enableVerboseLogging(boolean verboseEnabled, boolean halVerboseEnabled) {
869         synchronized (mLock) {
870             if (mStaIfaceHal != null) {
871                 mStaIfaceHal.enableVerboseLogging(verboseEnabled, halVerboseEnabled);
872             }
873         }
874     }
875 
876     /**
877      * Initialize the STA Iface HAL. Creates the internal ISupplicantStaIfaceHal
878      * object and calls its initialize method.
879      *
880      * @return true if the initialization succeeded
881      */
initialize()882     public boolean initialize() {
883         synchronized (mLock) {
884             if (mStaIfaceHal == null) {
885                 Log.wtf(TAG, "Internal ISupplicantStaIfaceHal instance does not exist.");
886                 return false;
887             }
888             if (!mStaIfaceHal.initialize()) {
889                 Log.e(TAG, "Failed to init ISupplicantStaIfaceHal, stopping startup.");
890                 return false;
891             }
892             return true;
893         }
894     }
895 
896     /**
897      * Wrapper function to create the ISupplicantStaIfaceHal object.
898      * Created to be mockable in unit tests.
899      */
900     @VisibleForTesting
createStaIfaceHalMockable()901     protected ISupplicantStaIfaceHal createStaIfaceHalMockable() {
902         synchronized (mLock) {
903             // Prefer AIDL implementation if service is declared.
904             if (SupplicantStaIfaceHalAidlImpl.serviceDeclared()) {
905                 Log.i(TAG, "Initializing SupplicantStaIfaceHal using AIDL implementation.");
906                 return new SupplicantStaIfaceHalAidlImpl(mContext, mWifiMonitor,
907                         mEventHandler, mClock, mWifiMetrics, mWifiGlobals, mSsidTranslator,
908                         mWifiInjector);
909 
910             } else if (SupplicantStaIfaceHalHidlImpl.serviceDeclared()) {
911                 Log.i(TAG, "Initializing SupplicantStaIfaceHal using HIDL implementation.");
912                 return new SupplicantStaIfaceHalHidlImpl(mContext, mWifiMonitor, mFrameworkFacade,
913                         mEventHandler, mClock, mWifiMetrics, mWifiGlobals, mSsidTranslator);
914             }
915             Log.e(TAG, "No HIDL or AIDL service available for SupplicantStaIfaceHal.");
916             return null;
917         }
918     }
919 
920     /**
921      * Setup a STA interface for the specified iface name.
922      *
923      * @param ifaceName Name of the interface.
924      * @return true on success, false otherwise.
925      */
setupIface(@onNull String ifaceName)926     public boolean setupIface(@NonNull String ifaceName) {
927         synchronized (mLock) {
928             String methodStr = "setupIface";
929             if (mStaIfaceHal == null) {
930                 return handleNullHal(methodStr);
931             }
932             return mStaIfaceHal.setupIface(ifaceName);
933         }
934     }
935 
936     /**
937      * Teardown a STA interface for the specified iface name.
938      *
939      * @param ifaceName Name of the interface.
940      * @return true on success, false otherwise.
941      */
teardownIface(@onNull String ifaceName)942     public boolean teardownIface(@NonNull String ifaceName) {
943         synchronized (mLock) {
944             String methodStr = "teardownIface";
945             if (mStaIfaceHal == null) {
946                 return handleNullHal(methodStr);
947             }
948             return mStaIfaceHal.teardownIface(ifaceName);
949         }
950     }
951 
952     /**
953      * Registers a death notification for supplicant.
954      * @return Returns true on success.
955      */
registerDeathHandler(@onNull WifiNative.SupplicantDeathEventHandler handler)956     public boolean registerDeathHandler(@NonNull WifiNative.SupplicantDeathEventHandler handler) {
957         synchronized (mLock) {
958             String methodStr = "registerDeathHandler";
959             if (mStaIfaceHal == null) {
960                 return handleNullHal(methodStr);
961             }
962             return mStaIfaceHal.registerDeathHandler(handler);
963         }
964     }
965 
966     /**
967      * Deregisters a death notification for supplicant.
968      * @return Returns true on success.
969      */
deregisterDeathHandler()970     public boolean deregisterDeathHandler() {
971         synchronized (mLock) {
972             String methodStr = "deregisterDeathHandler";
973             if (mStaIfaceHal == null) {
974                 return handleNullHal(methodStr);
975             }
976             return mStaIfaceHal.deregisterDeathHandler();
977         }
978     }
979 
980     /**
981      * Signals whether initialization started successfully.
982      */
isInitializationStarted()983     public boolean isInitializationStarted() {
984         synchronized (mLock) {
985             String methodStr = "isInitializationStarted";
986             if (mStaIfaceHal == null) {
987                 return handleNullHal(methodStr);
988             }
989             return mStaIfaceHal.isInitializationStarted();
990         }
991     }
992 
993     /**
994      * Signals whether initialization completed successfully.
995      */
isInitializationComplete()996     public boolean isInitializationComplete() {
997         synchronized (mLock) {
998             String methodStr = "isInitializationComplete";
999             if (mStaIfaceHal == null) {
1000                 return handleNullHal(methodStr);
1001             }
1002             return mStaIfaceHal.isInitializationComplete();
1003         }
1004     }
1005 
1006     /**
1007      * Start the supplicant daemon.
1008      *
1009      * @return true on success, false otherwise.
1010      */
startDaemon()1011     public boolean startDaemon() {
1012         synchronized (mLock) {
1013             String methodStr = "startDaemon";
1014             if (mStaIfaceHal == null) {
1015                 return handleNullHal(methodStr);
1016             }
1017             return mStaIfaceHal.startDaemon();
1018         }
1019     }
1020 
1021     /**
1022      * Terminate the supplicant daemon & wait for its death.
1023      */
terminate()1024     public void terminate() {
1025         synchronized (mLock) {
1026             String methodStr = "terminate";
1027             if (mStaIfaceHal == null) {
1028                 handleNullHal(methodStr);
1029                 return;
1030             }
1031             mStaIfaceHal.terminate();
1032         }
1033     }
1034 
1035     /**
1036      * Add the provided network configuration to wpa_supplicant and initiate connection to it.
1037      * This method does the following:
1038      * 1. If |config| is different to the current supplicant network, removes all supplicant
1039      * networks and saves |config|.
1040      * 2. Select the new network in wpa_supplicant.
1041      *
1042      * @param ifaceName Name of the interface.
1043      * @param config WifiConfiguration parameters for the provided network.
1044      * @return {@code true} if it succeeds, {@code false} otherwise
1045      */
connectToNetwork(@onNull String ifaceName, @NonNull WifiConfiguration config)1046     public boolean connectToNetwork(@NonNull String ifaceName, @NonNull WifiConfiguration config) {
1047         synchronized (mLock) {
1048             String methodStr = "connectToNetwork";
1049             if (mStaIfaceHal == null) {
1050                 return handleNullHal(methodStr);
1051             }
1052             return mStaIfaceHal.connectToNetwork(ifaceName, config);
1053         }
1054     }
1055 
1056     /**
1057      * Initiates roaming to the already configured network in wpa_supplicant. If the network
1058      * configuration provided does not match the already configured network, then this triggers
1059      * a new connection attempt (instead of roam).
1060      *
1061      * @param ifaceName Name of the interface.
1062      * @param config WifiConfiguration parameters for the provided network.
1063      * @return {@code true} if it succeeds, {@code false} otherwise
1064      */
roamToNetwork(@onNull String ifaceName, WifiConfiguration config)1065     public boolean roamToNetwork(@NonNull String ifaceName, WifiConfiguration config) {
1066         synchronized (mLock) {
1067             String methodStr = "roamToNetwork";
1068             if (mStaIfaceHal == null) {
1069                 return handleNullHal(methodStr);
1070             }
1071             return mStaIfaceHal.roamToNetwork(ifaceName, config);
1072         }
1073     }
1074 
1075     /**
1076      * Clean HAL cached data for |networkId| in the framework.
1077      *
1078      * @param networkId Network id of the network to be removed from supplicant.
1079      */
removeNetworkCachedData(int networkId)1080     public void removeNetworkCachedData(int networkId) {
1081         synchronized (mLock) {
1082             String methodStr = "removeNetworkCachedData";
1083             if (mStaIfaceHal == null) {
1084                 handleNullHal(methodStr);
1085                 return;
1086             }
1087             mStaIfaceHal.removeNetworkCachedData(networkId);
1088         }
1089     }
1090 
1091     /**
1092      * Clear HAL cached data if MAC address is changed.
1093      *
1094      * @param networkId Network id of the network to be checked.
1095      * @param curMacAddress Current MAC address
1096      */
removeNetworkCachedDataIfNeeded(int networkId, MacAddress curMacAddress)1097     public void removeNetworkCachedDataIfNeeded(int networkId, MacAddress curMacAddress) {
1098         synchronized (mLock) {
1099             String methodStr = "removeNetworkCachedDataIfNeeded";
1100             if (mStaIfaceHal == null) {
1101                 handleNullHal(methodStr);
1102                 return;
1103             }
1104             mStaIfaceHal.removeNetworkCachedDataIfNeeded(networkId, curMacAddress);
1105         }
1106     }
1107 
1108     /**
1109      * Remove all networks from supplicant
1110      *
1111      * @param ifaceName Name of the interface.
1112      */
removeAllNetworks(@onNull String ifaceName)1113     public boolean removeAllNetworks(@NonNull String ifaceName) {
1114         synchronized (mLock) {
1115             String methodStr = "removeAllNetworks";
1116             if (mStaIfaceHal == null) {
1117                 return handleNullHal(methodStr);
1118             }
1119             return mStaIfaceHal.removeAllNetworks(ifaceName);
1120         }
1121     }
1122 
1123     /**
1124      * Disable the current network in supplicant
1125      *
1126      * @param ifaceName Name of the interface.
1127      */
disableCurrentNetwork(@onNull String ifaceName)1128     public boolean disableCurrentNetwork(@NonNull String ifaceName) {
1129         synchronized (mLock) {
1130             String methodStr = "disableCurrentNetwork";
1131             if (mStaIfaceHal == null) {
1132                 return handleNullHal(methodStr);
1133             }
1134             return mStaIfaceHal.disableCurrentNetwork(ifaceName);
1135         }
1136     }
1137 
1138     /**
1139      * Set the currently configured network's bssid.
1140      *
1141      * @param ifaceName Name of the interface.
1142      * @param bssidStr Bssid to set in the form of "XX:XX:XX:XX:XX:XX"
1143      * @return true if succeeds, false otherwise.
1144      */
setCurrentNetworkBssid(@onNull String ifaceName, String bssidStr)1145     public boolean setCurrentNetworkBssid(@NonNull String ifaceName, String bssidStr) {
1146         synchronized (mLock) {
1147             String methodStr = "setCurrentNetworkBssid";
1148             if (mStaIfaceHal == null) {
1149                 return handleNullHal(methodStr);
1150             }
1151             return mStaIfaceHal.setCurrentNetworkBssid(ifaceName, bssidStr);
1152         }
1153     }
1154 
1155     /**
1156      * Get the currently configured network's WPS NFC token.
1157      *
1158      * @param ifaceName Name of the interface.
1159      * @return Hex string corresponding to the WPS NFC token.
1160      */
getCurrentNetworkWpsNfcConfigurationToken(@onNull String ifaceName)1161     public String getCurrentNetworkWpsNfcConfigurationToken(@NonNull String ifaceName) {
1162         synchronized (mLock) {
1163             String methodStr = "getCurrentNetworkWpsNfcConfigurationToken";
1164             if (mStaIfaceHal == null) {
1165                 handleNullHal(methodStr);
1166                 return null;
1167             }
1168             return mStaIfaceHal.getCurrentNetworkWpsNfcConfigurationToken(ifaceName);
1169         }
1170     }
1171 
1172     /**
1173      * Get the eap anonymous identity for the currently configured network.
1174      *
1175      * @param ifaceName Name of the interface.
1176      * @return anonymous identity string if succeeds, null otherwise.
1177      */
getCurrentNetworkEapAnonymousIdentity(@onNull String ifaceName)1178     public String getCurrentNetworkEapAnonymousIdentity(@NonNull String ifaceName) {
1179         synchronized (mLock) {
1180             String methodStr = "getCurrentNetworkEapAnonymousIdentity";
1181             if (mStaIfaceHal == null) {
1182                 handleNullHal(methodStr);
1183                 return null;
1184             }
1185             return mStaIfaceHal.getCurrentNetworkEapAnonymousIdentity(ifaceName);
1186         }
1187     }
1188 
1189     /**
1190      * Send the eap identity response for the currently configured network.
1191      *
1192      * @param ifaceName Name of the interface.
1193      * @param identity Identity used for EAP-Identity
1194      * @param encryptedIdentity Encrypted identity used for EAP-AKA/EAP-SIM
1195      * @return true if succeeds, false otherwise.
1196      */
sendCurrentNetworkEapIdentityResponse( @onNull String ifaceName, @NonNull String identity, String encryptedIdentity)1197     public boolean sendCurrentNetworkEapIdentityResponse(
1198             @NonNull String ifaceName, @NonNull String identity, String encryptedIdentity) {
1199         synchronized (mLock) {
1200             String methodStr = "sendCurrentNetworkEapIdentityResponse";
1201             if (mStaIfaceHal == null) {
1202                 return handleNullHal(methodStr);
1203             }
1204             return mStaIfaceHal.sendCurrentNetworkEapIdentityResponse(
1205                     ifaceName, identity, encryptedIdentity);
1206         }
1207     }
1208 
1209     /**
1210      * Send the eap sim gsm auth response for the currently configured network.
1211      *
1212      * @param ifaceName Name of the interface.
1213      * @param paramsStr String to send.
1214      * @return true if succeeds, false otherwise.
1215      */
sendCurrentNetworkEapSimGsmAuthResponse( @onNull String ifaceName, String paramsStr)1216     public boolean sendCurrentNetworkEapSimGsmAuthResponse(
1217             @NonNull String ifaceName, String paramsStr) {
1218         synchronized (mLock) {
1219             String methodStr = "sendCurrentNetworkEapSimGsmAuthResponse";
1220             if (mStaIfaceHal == null) {
1221                 return handleNullHal(methodStr);
1222             }
1223             return mStaIfaceHal.sendCurrentNetworkEapSimGsmAuthResponse(ifaceName, paramsStr);
1224         }
1225     }
1226 
1227     /**
1228      * Send the eap sim gsm auth failure for the currently configured network.
1229      *
1230      * @param ifaceName Name of the interface.
1231      * @return true if succeeds, false otherwise.
1232      */
sendCurrentNetworkEapSimGsmAuthFailure(@onNull String ifaceName)1233     public boolean sendCurrentNetworkEapSimGsmAuthFailure(@NonNull String ifaceName) {
1234         synchronized (mLock) {
1235             String methodStr = "sendCurrentNetworkEapSimGsmAuthFailure";
1236             if (mStaIfaceHal == null) {
1237                 return handleNullHal(methodStr);
1238             }
1239             return mStaIfaceHal.sendCurrentNetworkEapSimGsmAuthFailure(ifaceName);
1240         }
1241     }
1242 
1243     /**
1244      * Send the eap sim umts auth response for the currently configured network.
1245      *
1246      * @param ifaceName Name of the interface.
1247      * @param paramsStr String to send.
1248      * @return true if succeeds, false otherwise.
1249      */
sendCurrentNetworkEapSimUmtsAuthResponse( @onNull String ifaceName, String paramsStr)1250     public boolean sendCurrentNetworkEapSimUmtsAuthResponse(
1251             @NonNull String ifaceName, String paramsStr) {
1252         synchronized (mLock) {
1253             String methodStr = "sendCurrentNetworkEapSimUmtsAuthResponse";
1254             if (mStaIfaceHal == null) {
1255                 return handleNullHal(methodStr);
1256             }
1257             return mStaIfaceHal.sendCurrentNetworkEapSimUmtsAuthResponse(ifaceName, paramsStr);
1258         }
1259     }
1260 
1261     /**
1262      * Send the eap sim umts auts response for the currently configured network.
1263      *
1264      * @param ifaceName Name of the interface.
1265      * @param paramsStr String to send.
1266      * @return true if succeeds, false otherwise.
1267      */
sendCurrentNetworkEapSimUmtsAutsResponse( @onNull String ifaceName, String paramsStr)1268     public boolean sendCurrentNetworkEapSimUmtsAutsResponse(
1269             @NonNull String ifaceName, String paramsStr) {
1270         synchronized (mLock) {
1271             String methodStr = "sendCurrentNetworkEapSimUmtsAutsResponse";
1272             if (mStaIfaceHal == null) {
1273                 return handleNullHal(methodStr);
1274             }
1275             return mStaIfaceHal.sendCurrentNetworkEapSimUmtsAutsResponse(ifaceName, paramsStr);
1276         }
1277     }
1278 
1279     /**
1280      * Send the eap sim umts auth failure for the currently configured network.
1281      *
1282      * @param ifaceName Name of the interface.
1283      * @return true if succeeds, false otherwise.
1284      */
sendCurrentNetworkEapSimUmtsAuthFailure(@onNull String ifaceName)1285     public boolean sendCurrentNetworkEapSimUmtsAuthFailure(@NonNull String ifaceName) {
1286         synchronized (mLock) {
1287             String methodStr = "sendCurrentNetworkEapSimUmtsAuthFailure";
1288             if (mStaIfaceHal == null) {
1289                 return handleNullHal(methodStr);
1290             }
1291             return mStaIfaceHal.sendCurrentNetworkEapSimUmtsAuthFailure(ifaceName);
1292         }
1293     }
1294 
1295     /**
1296      * Set WPS device name.
1297      *
1298      * @param ifaceName Name of the interface.
1299      * @param deviceName String to be set.
1300      * @return true if request is sent successfully, false otherwise.
1301      */
setWpsDeviceName(@onNull String ifaceName, String deviceName)1302     public boolean setWpsDeviceName(@NonNull String ifaceName, String deviceName) {
1303         synchronized (mLock) {
1304             String methodStr = "setWpsDeviceName";
1305             if (mStaIfaceHal == null) {
1306                 return handleNullHal(methodStr);
1307             }
1308             return mStaIfaceHal.setWpsDeviceName(ifaceName, deviceName);
1309         }
1310     }
1311 
1312     /**
1313      * Set WPS device type.
1314      *
1315      * @param ifaceName Name of the interface.
1316      * @param typeStr Type specified as a string. Used format: <categ>-<OUI>-<subcateg>
1317      * @return true if request is sent successfully, false otherwise.
1318      */
setWpsDeviceType(@onNull String ifaceName, String typeStr)1319     public boolean setWpsDeviceType(@NonNull String ifaceName, String typeStr) {
1320         synchronized (mLock) {
1321             String methodStr = "setWpsDeviceType";
1322             if (mStaIfaceHal == null) {
1323                 return handleNullHal(methodStr);
1324             }
1325             return mStaIfaceHal.setWpsDeviceType(ifaceName, typeStr);
1326         }
1327     }
1328 
1329     /**
1330      * Set WPS manufacturer.
1331      *
1332      * @param ifaceName Name of the interface.
1333      * @param manufacturer String to be set.
1334      * @return true if request is sent successfully, false otherwise.
1335      */
setWpsManufacturer(@onNull String ifaceName, String manufacturer)1336     public boolean setWpsManufacturer(@NonNull String ifaceName, String manufacturer) {
1337         synchronized (mLock) {
1338             String methodStr = "setWpsManufacturer";
1339             if (mStaIfaceHal == null) {
1340                 return handleNullHal(methodStr);
1341             }
1342             return mStaIfaceHal.setWpsManufacturer(ifaceName, manufacturer);
1343         }
1344     }
1345 
1346     /**
1347      * Set WPS model name.
1348      *
1349      * @param ifaceName Name of the interface.
1350      * @param modelName String to be set.
1351      * @return true if request is sent successfully, false otherwise.
1352      */
setWpsModelName(@onNull String ifaceName, String modelName)1353     public boolean setWpsModelName(@NonNull String ifaceName, String modelName) {
1354         synchronized (mLock) {
1355             String methodStr = "setWpsModelName";
1356             if (mStaIfaceHal == null) {
1357                 return handleNullHal(methodStr);
1358             }
1359             return mStaIfaceHal.setWpsModelName(ifaceName, modelName);
1360         }
1361     }
1362 
1363     /**
1364      * Set WPS model number.
1365      *
1366      * @param ifaceName Name of the interface.
1367      * @param modelNumber String to be set.
1368      * @return true if request is sent successfully, false otherwise.
1369      */
setWpsModelNumber(@onNull String ifaceName, String modelNumber)1370     public boolean setWpsModelNumber(@NonNull String ifaceName, String modelNumber) {
1371         synchronized (mLock) {
1372             String methodStr = "setWpsModelNumber";
1373             if (mStaIfaceHal == null) {
1374                 return handleNullHal(methodStr);
1375             }
1376             return mStaIfaceHal.setWpsModelNumber(ifaceName, modelNumber);
1377         }
1378     }
1379 
1380     /**
1381      * Set WPS serial number.
1382      *
1383      * @param ifaceName Name of the interface.
1384      * @param serialNumber String to be set.
1385      * @return true if request is sent successfully, false otherwise.
1386      */
setWpsSerialNumber(@onNull String ifaceName, String serialNumber)1387     public boolean setWpsSerialNumber(@NonNull String ifaceName, String serialNumber) {
1388         synchronized (mLock) {
1389             String methodStr = "setWpsSerialNumber";
1390             if (mStaIfaceHal == null) {
1391                 return handleNullHal(methodStr);
1392             }
1393             return mStaIfaceHal.setWpsSerialNumber(ifaceName, serialNumber);
1394         }
1395     }
1396 
1397     /**
1398      * Set WPS config methods
1399      *
1400      * @param ifaceName Name of the interface.
1401      * @param configMethodsStr List of config methods.
1402      * @return true if request is sent successfully, false otherwise.
1403      */
setWpsConfigMethods(@onNull String ifaceName, String configMethodsStr)1404     public boolean setWpsConfigMethods(@NonNull String ifaceName, String configMethodsStr) {
1405         synchronized (mLock) {
1406             String methodStr = "setWpsConfigMethods";
1407             if (mStaIfaceHal == null) {
1408                 return handleNullHal(methodStr);
1409             }
1410             return mStaIfaceHal.setWpsConfigMethods(ifaceName, configMethodsStr);
1411         }
1412     }
1413 
1414     /**
1415      * Trigger a reassociation even if the iface is currently connected.
1416      *
1417      * @param ifaceName Name of the interface.
1418      * @return true if request is sent successfully, false otherwise.
1419      */
reassociate(@onNull String ifaceName)1420     public boolean reassociate(@NonNull String ifaceName) {
1421         synchronized (mLock) {
1422             String methodStr = "reassociate";
1423             if (mStaIfaceHal == null) {
1424                 return handleNullHal(methodStr);
1425             }
1426             return mStaIfaceHal.reassociate(ifaceName);
1427         }
1428     }
1429 
1430     /**
1431      * Trigger a reconnection if the iface is disconnected.
1432      *
1433      * @param ifaceName Name of the interface.
1434      * @return true if request is sent successfully, false otherwise.
1435      */
reconnect(@onNull String ifaceName)1436     public boolean reconnect(@NonNull String ifaceName) {
1437         synchronized (mLock) {
1438             String methodStr = "reconnect";
1439             if (mStaIfaceHal == null) {
1440                 return handleNullHal(methodStr);
1441             }
1442             return mStaIfaceHal.reconnect(ifaceName);
1443         }
1444     }
1445 
1446     /**
1447      * Trigger a disconnection from the currently connected network.
1448      *
1449      * @param ifaceName Name of the interface.
1450      * @return true if request is sent successfully, false otherwise.
1451      */
disconnect(@onNull String ifaceName)1452     public boolean disconnect(@NonNull String ifaceName) {
1453         synchronized (mLock) {
1454             String methodStr = "disconnect";
1455             if (mStaIfaceHal == null) {
1456                 return handleNullHal(methodStr);
1457             }
1458             return mStaIfaceHal.disconnect(ifaceName);
1459         }
1460     }
1461 
1462     /**
1463      * Enable or disable power save mode.
1464      *
1465      * @param ifaceName Name of the interface.
1466      * @param enable true to enable, false to disable.
1467      * @return true if request is sent successfully, false otherwise.
1468      */
setPowerSave(@onNull String ifaceName, boolean enable)1469     public boolean setPowerSave(@NonNull String ifaceName, boolean enable) {
1470         synchronized (mLock) {
1471             String methodStr = "setPowerSave";
1472             if (mStaIfaceHal == null) {
1473                 return handleNullHal(methodStr);
1474             }
1475             return mStaIfaceHal.setPowerSave(ifaceName, enable);
1476         }
1477     }
1478 
1479     /**
1480      * Initiate TDLS discover with the specified AP.
1481      *
1482      * @param ifaceName Name of the interface.
1483      * @param macAddress MAC Address of the AP.
1484      * @return true if request is sent successfully, false otherwise.
1485      */
initiateTdlsDiscover(@onNull String ifaceName, String macAddress)1486     public boolean initiateTdlsDiscover(@NonNull String ifaceName, String macAddress) {
1487         synchronized (mLock) {
1488             String methodStr = "initiateTdlsDiscover";
1489             if (mStaIfaceHal == null) {
1490                 return handleNullHal(methodStr);
1491             }
1492             return mStaIfaceHal.initiateTdlsDiscover(ifaceName, macAddress);
1493         }
1494     }
1495 
1496     /**
1497      * Initiate TDLS setup with the specified AP.
1498      *
1499      * @param ifaceName Name of the interface.
1500      * @param macAddress MAC Address of the AP.
1501      * @return true if request is sent successfully, false otherwise.
1502      */
initiateTdlsSetup(@onNull String ifaceName, String macAddress)1503     public boolean initiateTdlsSetup(@NonNull String ifaceName, String macAddress) {
1504         synchronized (mLock) {
1505             String methodStr = "initiateTdlsSetup";
1506             if (mStaIfaceHal == null) {
1507                 return handleNullHal(methodStr);
1508             }
1509             return mStaIfaceHal.initiateTdlsSetup(ifaceName, macAddress);
1510         }
1511     }
1512 
1513     /**
1514      * Initiate TDLS teardown with the specified AP.
1515      * @param ifaceName Name of the interface.
1516      * @param macAddress MAC Address of the AP.
1517      * @return true if request is sent successfully, false otherwise.
1518      */
initiateTdlsTeardown(@onNull String ifaceName, String macAddress)1519     public boolean initiateTdlsTeardown(@NonNull String ifaceName, String macAddress) {
1520         synchronized (mLock) {
1521             String methodStr = "initiateTdlsTeardown";
1522             if (mStaIfaceHal == null) {
1523                 return handleNullHal(methodStr);
1524             }
1525             return mStaIfaceHal.initiateTdlsTeardown(ifaceName, macAddress);
1526         }
1527     }
1528 
1529     /**
1530      * Request the specified ANQP elements |elements| from the specified AP |bssid|.
1531      *
1532      * @param ifaceName Name of the interface.
1533      * @param bssid BSSID of the AP
1534      * @param infoElements ANQP elements to be queried. Refer to ISupplicantStaIface.AnqpInfoId.
1535      * @param hs20SubTypes HS subtypes to be queried. Refer to ISupplicantStaIface.Hs20AnqpSubTypes.
1536      * @return true if request is sent successfully, false otherwise.
1537      */
initiateAnqpQuery(@onNull String ifaceName, String bssid, ArrayList<Short> infoElements, ArrayList<Integer> hs20SubTypes)1538     public boolean initiateAnqpQuery(@NonNull String ifaceName, String bssid,
1539             ArrayList<Short> infoElements,
1540             ArrayList<Integer> hs20SubTypes) {
1541         synchronized (mLock) {
1542             String methodStr = "initiateAnqpQuery";
1543             if (mStaIfaceHal == null) {
1544                 return handleNullHal(methodStr);
1545             }
1546             return mStaIfaceHal.initiateAnqpQuery(ifaceName, bssid, infoElements, hs20SubTypes);
1547         }
1548     }
1549 
1550     /**
1551      * Request Venue URL ANQP element from the specified AP |bssid|.
1552      *
1553      * @param ifaceName Name of the interface.
1554      * @param bssid BSSID of the AP
1555      * @return true if request is sent successfully, false otherwise.
1556      */
initiateVenueUrlAnqpQuery(@onNull String ifaceName, String bssid)1557     public boolean initiateVenueUrlAnqpQuery(@NonNull String ifaceName, String bssid) {
1558         synchronized (mLock) {
1559             String methodStr = "initiateVenueUrlAnqpQuery";
1560             if (mStaIfaceHal == null) {
1561                 return handleNullHal(methodStr);
1562             }
1563             return mStaIfaceHal.initiateVenueUrlAnqpQuery(ifaceName, bssid);
1564         }
1565     }
1566 
1567     /**
1568      * Request the specified ANQP ICON from the specified AP |bssid|.
1569      *
1570      * @param ifaceName Name of the interface.
1571      * @param bssid BSSID of the AP
1572      * @param fileName Name of the file to request.
1573      * @return true if request is sent successfully, false otherwise.
1574      */
initiateHs20IconQuery(@onNull String ifaceName, String bssid, String fileName)1575     public boolean initiateHs20IconQuery(@NonNull String ifaceName, String bssid, String fileName) {
1576         synchronized (mLock) {
1577             String methodStr = "initiateHs20IconQuery";
1578             if (mStaIfaceHal == null) {
1579                 return handleNullHal(methodStr);
1580             }
1581             return mStaIfaceHal.initiateHs20IconQuery(ifaceName, bssid, fileName);
1582         }
1583     }
1584 
1585     /**
1586      * Gets MAC address from the supplicant.
1587      *
1588      * @param ifaceName Name of the interface.
1589      * @return string containing the MAC address, or null on a failed call
1590      */
getMacAddress(@onNull String ifaceName)1591     public String getMacAddress(@NonNull String ifaceName) {
1592         synchronized (mLock) {
1593             String methodStr = "getMacAddress";
1594             if (mStaIfaceHal == null) {
1595                 handleNullHal(methodStr);
1596                 return null;
1597             }
1598             return mStaIfaceHal.getMacAddress(ifaceName);
1599         }
1600     }
1601 
1602     /**
1603      * Start using the added RX filters.
1604      *
1605      * @param ifaceName Name of the interface.
1606      * @return true if request is sent successfully, false otherwise.
1607      */
startRxFilter(@onNull String ifaceName)1608     public boolean startRxFilter(@NonNull String ifaceName) {
1609         synchronized (mLock) {
1610             String methodStr = "startRxFilter";
1611             if (mStaIfaceHal == null) {
1612                 return handleNullHal(methodStr);
1613             }
1614             return mStaIfaceHal.startRxFilter(ifaceName);
1615         }
1616     }
1617 
1618     /**
1619      * Stop using the added RX filters.
1620      *
1621      * @param ifaceName Name of the interface.
1622      * @return true if request is sent successfully, false otherwise.
1623      */
stopRxFilter(@onNull String ifaceName)1624     public boolean stopRxFilter(@NonNull String ifaceName) {
1625         synchronized (mLock) {
1626             String methodStr = "stopRxFilter";
1627             if (mStaIfaceHal == null) {
1628                 return handleNullHal(methodStr);
1629             }
1630             return mStaIfaceHal.stopRxFilter(ifaceName);
1631         }
1632     }
1633 
1634     /**
1635      * Add an RX filter.
1636      *
1637      * @param ifaceName Name of the interface.
1638      * @param type one of {@link WifiNative#RX_FILTER_TYPE_V4_MULTICAST}
1639      *        {@link WifiNative#RX_FILTER_TYPE_V6_MULTICAST} values.
1640      * @return true if request is sent successfully, false otherwise.
1641      */
addRxFilter(@onNull String ifaceName, int type)1642     public boolean addRxFilter(@NonNull String ifaceName, int type) {
1643         synchronized (mLock) {
1644             String methodStr = "addRxFilter";
1645             if (mStaIfaceHal == null) {
1646                 return handleNullHal(methodStr);
1647             }
1648             return mStaIfaceHal.addRxFilter(ifaceName, type);
1649         }
1650     }
1651 
1652     /**
1653      * Remove an RX filter.
1654      *
1655      * @param ifaceName Name of the interface.
1656      * @param type one of {@link WifiNative#RX_FILTER_TYPE_V4_MULTICAST}
1657      *        {@link WifiNative#RX_FILTER_TYPE_V6_MULTICAST} values.
1658      * @return true if request is sent successfully, false otherwise.
1659      */
removeRxFilter(@onNull String ifaceName, int type)1660     public boolean removeRxFilter(@NonNull String ifaceName, int type) {
1661         synchronized (mLock) {
1662             String methodStr = "removeRxFilter";
1663             if (mStaIfaceHal == null) {
1664                 return handleNullHal(methodStr);
1665             }
1666             return mStaIfaceHal.removeRxFilter(ifaceName, type);
1667         }
1668     }
1669 
1670     /**
1671      * Set Bt coexistence mode.
1672      *
1673      * @param ifaceName Name of the interface.
1674      * @param mode one of the above {@link WifiNative#BLUETOOTH_COEXISTENCE_MODE_DISABLED},
1675      *             {@link WifiNative#BLUETOOTH_COEXISTENCE_MODE_ENABLED} or
1676      *             {@link WifiNative#BLUETOOTH_COEXISTENCE_MODE_SENSE}.
1677      * @return true if request is sent successfully, false otherwise.
1678      */
setBtCoexistenceMode(@onNull String ifaceName, int mode)1679     public boolean setBtCoexistenceMode(@NonNull String ifaceName, int mode) {
1680         synchronized (mLock) {
1681             String methodStr = "setBtCoexistenceMode";
1682             if (mStaIfaceHal == null) {
1683                 return handleNullHal(methodStr);
1684             }
1685             return mStaIfaceHal.setBtCoexistenceMode(ifaceName, mode);
1686         }
1687     }
1688 
1689     /** Enable or disable BT coexistence mode.
1690      *
1691      * @param ifaceName Name of the interface.
1692      * @param enable true to enable, false to disable.
1693      * @return true if request is sent successfully, false otherwise.
1694      */
setBtCoexistenceScanModeEnabled(@onNull String ifaceName, boolean enable)1695     public boolean setBtCoexistenceScanModeEnabled(@NonNull String ifaceName, boolean enable) {
1696         synchronized (mLock) {
1697             String methodStr = "setBtCoexistenceScanModeEnabled";
1698             if (mStaIfaceHal == null) {
1699                 return handleNullHal(methodStr);
1700             }
1701             return mStaIfaceHal.setBtCoexistenceScanModeEnabled(ifaceName, enable);
1702         }
1703     }
1704 
1705     /**
1706      * Enable or disable suspend mode optimizations.
1707      *
1708      * @param ifaceName Name of the interface.
1709      * @param enable true to enable, false otherwise.
1710      * @return true if request is sent successfully, false otherwise.
1711      */
setSuspendModeEnabled(@onNull String ifaceName, boolean enable)1712     public boolean setSuspendModeEnabled(@NonNull String ifaceName, boolean enable) {
1713         synchronized (mLock) {
1714             String methodStr = "setSuspendModeEnabled";
1715             if (mStaIfaceHal == null) {
1716                 return handleNullHal(methodStr);
1717             }
1718             return mStaIfaceHal.setSuspendModeEnabled(ifaceName, enable);
1719         }
1720     }
1721 
1722     /**
1723      * Set country code.
1724      *
1725      * @param ifaceName Name of the interface.
1726      * @param codeStr 2 byte ASCII string. For ex: US, CA.
1727      * @return true if request is sent successfully, false otherwise.
1728      */
setCountryCode(@onNull String ifaceName, String codeStr)1729     public boolean setCountryCode(@NonNull String ifaceName, String codeStr) {
1730         synchronized (mLock) {
1731             String methodStr = "setCountryCode";
1732             if (mStaIfaceHal == null) {
1733                 return handleNullHal(methodStr);
1734             }
1735             return mStaIfaceHal.setCountryCode(ifaceName, codeStr);
1736         }
1737     }
1738 
1739     /**
1740      * Flush all previously configured HLPs.
1741      *
1742      * @param ifaceName Name of the interface.
1743      * @return true if request is sent successfully, false otherwise.
1744      */
flushAllHlp(@onNull String ifaceName)1745     public boolean flushAllHlp(@NonNull String ifaceName) {
1746         synchronized (mLock) {
1747             String methodStr = "flushAllHlp";
1748             if (mStaIfaceHal == null) {
1749                 return handleNullHal(methodStr);
1750             }
1751             return mStaIfaceHal.flushAllHlp(ifaceName);
1752         }
1753     }
1754 
1755     /**
1756      * Set FILS HLP packet.
1757      *
1758      * @param ifaceName Name of the interface.
1759      * @param dst Destination MAC address.
1760      * @param hlpPacket Hlp Packet data in hex.
1761      * @return true if request is sent successfully, false otherwise.
1762      */
addHlpReq(@onNull String ifaceName, byte [] dst, byte [] hlpPacket)1763     public boolean addHlpReq(@NonNull String ifaceName, byte [] dst, byte [] hlpPacket) {
1764         synchronized (mLock) {
1765             String methodStr = "addHlpReq";
1766             if (mStaIfaceHal == null) {
1767                 return handleNullHal(methodStr);
1768             }
1769             return mStaIfaceHal.addHlpReq(ifaceName, dst, hlpPacket);
1770         }
1771     }
1772 
1773     /**
1774      * Start WPS pin registrar operation with the specified peer and pin.
1775      *
1776      * @param ifaceName Name of the interface.
1777      * @param bssidStr BSSID of the peer.
1778      * @param pin Pin to be used.
1779      * @return true if request is sent successfully, false otherwise.
1780      */
startWpsRegistrar(@onNull String ifaceName, String bssidStr, String pin)1781     public boolean startWpsRegistrar(@NonNull String ifaceName, String bssidStr, String pin) {
1782         synchronized (mLock) {
1783             String methodStr = "startWpsRegistrar";
1784             if (mStaIfaceHal == null) {
1785                 return handleNullHal(methodStr);
1786             }
1787             return mStaIfaceHal.startWpsRegistrar(ifaceName, bssidStr, pin);
1788         }
1789     }
1790 
1791     /**
1792      * Start WPS pin display operation with the specified peer.
1793      *
1794      * @param ifaceName Name of the interface.
1795      * @param bssidStr BSSID of the peer. Use empty bssid to indicate wildcard.
1796      * @return true if request is sent successfully, false otherwise.
1797      */
startWpsPbc(@onNull String ifaceName, String bssidStr)1798     public boolean startWpsPbc(@NonNull String ifaceName, String bssidStr) {
1799         synchronized (mLock) {
1800             String methodStr = "startWpsPbc";
1801             if (mStaIfaceHal == null) {
1802                 return handleNullHal(methodStr);
1803             }
1804             return mStaIfaceHal.startWpsPbc(ifaceName, bssidStr);
1805         }
1806     }
1807 
1808     /**
1809      * Start WPS pin keypad operation with the specified pin.
1810      *
1811      * @param ifaceName Name of the interface.
1812      * @param pin Pin to be used.
1813      * @return true if request is sent successfully, false otherwise.
1814      */
startWpsPinKeypad(@onNull String ifaceName, String pin)1815     public boolean startWpsPinKeypad(@NonNull String ifaceName, String pin) {
1816         synchronized (mLock) {
1817             String methodStr = "startWpsPinKeypad";
1818             if (mStaIfaceHal == null) {
1819                 return handleNullHal(methodStr);
1820             }
1821             return mStaIfaceHal.startWpsPinKeypad(ifaceName, pin);
1822         }
1823     }
1824 
1825     /**
1826      * Start WPS pin display operation with the specified peer.
1827      *
1828      * @param ifaceName Name of the interface.
1829      * @param bssidStr BSSID of the peer. Use empty bssid to indicate wildcard.
1830      * @return new pin generated on success, null otherwise.
1831      */
startWpsPinDisplay(@onNull String ifaceName, String bssidStr)1832     public String startWpsPinDisplay(@NonNull String ifaceName, String bssidStr) {
1833         synchronized (mLock) {
1834             String methodStr = "startWpsPinDisplay";
1835             if (mStaIfaceHal == null) {
1836                 handleNullHal(methodStr);
1837                 return null;
1838             }
1839             return mStaIfaceHal.startWpsPinDisplay(ifaceName, bssidStr);
1840         }
1841     }
1842 
1843     /**
1844      * Cancels any ongoing WPS requests.
1845      *
1846      * @param ifaceName Name of the interface.
1847      * @return true if request is sent successfully, false otherwise.
1848      */
cancelWps(@onNull String ifaceName)1849     public boolean cancelWps(@NonNull String ifaceName) {
1850         synchronized (mLock) {
1851             String methodStr = "cancelWps";
1852             if (mStaIfaceHal == null) {
1853                 return handleNullHal(methodStr);
1854             }
1855             return mStaIfaceHal.cancelWps(ifaceName);
1856         }
1857     }
1858 
1859     /**
1860      * Sets whether to use external sim for SIM/USIM processing.
1861      *
1862      * @param ifaceName Name of the interface.
1863      * @param useExternalSim true to enable, false otherwise.
1864      * @return true if request is sent successfully, false otherwise.
1865      */
setExternalSim(@onNull String ifaceName, boolean useExternalSim)1866     public boolean setExternalSim(@NonNull String ifaceName, boolean useExternalSim) {
1867         synchronized (mLock) {
1868             String methodStr = "setExternalSim";
1869             if (mStaIfaceHal == null) {
1870                 return handleNullHal(methodStr);
1871             }
1872             return mStaIfaceHal.setExternalSim(ifaceName, useExternalSim);
1873         }
1874     }
1875 
1876     /**
1877      * Enable/Disable auto reconnect to networks.
1878      * Use this to prevent wpa_supplicant from trying to connect to networks
1879      * on its own.
1880      *
1881      * @param enable true to enable, false to disable.
1882      * @return true if no exceptions occurred, false otherwise
1883      */
enableAutoReconnect(@onNull String ifaceName, boolean enable)1884     public boolean enableAutoReconnect(@NonNull String ifaceName, boolean enable) {
1885         synchronized (mLock) {
1886             String methodStr = "enableAutoReconnect";
1887             if (mStaIfaceHal == null) {
1888                 return handleNullHal(methodStr);
1889             }
1890             return mStaIfaceHal.enableAutoReconnect(ifaceName, enable);
1891         }
1892     }
1893 
1894     /**
1895      * Set the debug log level for wpa_supplicant
1896      *
1897      * @param turnOnVerbose Whether to turn on verbose logging or not.
1898      * @return true if request is sent successfully, false otherwise.
1899      */
setLogLevel(boolean turnOnVerbose)1900     public boolean setLogLevel(boolean turnOnVerbose) {
1901         synchronized (mLock) {
1902             String methodStr = "setLogLevel";
1903             if (mStaIfaceHal == null) {
1904                 return handleNullHal(methodStr);
1905             }
1906             return mStaIfaceHal.setLogLevel(turnOnVerbose);
1907         }
1908     }
1909 
1910     /**
1911      * Set concurrency priority between P2P & STA operations.
1912      *
1913      * @param isStaHigherPriority Set to true to prefer STA over P2P during concurrency operations,
1914      *                            false otherwise.
1915      * @return true if request is sent successfully, false otherwise.
1916      */
setConcurrencyPriority(boolean isStaHigherPriority)1917     public boolean setConcurrencyPriority(boolean isStaHigherPriority) {
1918         synchronized (mLock) {
1919             String methodStr = "setConcurrencyPriority";
1920             if (mStaIfaceHal == null) {
1921                 return handleNullHal(methodStr);
1922             }
1923             return mStaIfaceHal.setConcurrencyPriority(isStaHigherPriority);
1924         }
1925     }
1926 
1927 
1928     /**
1929      * Returns a bitmask of advanced capabilities: WPA3 SAE/SUITE B and OWE
1930      * Bitmask used is:
1931      * - WIFI_FEATURE_WPA3_SAE
1932      * - WIFI_FEATURE_WPA3_SUITE_B
1933      * - WIFI_FEATURE_OWE
1934      *
1935      *  On error, or if these features are not supported, 0 is returned.
1936      */
getAdvancedCapabilities(@onNull String ifaceName)1937     public long getAdvancedCapabilities(@NonNull String ifaceName) {
1938         synchronized (mLock) {
1939             String methodStr = "getAdvancedCapabilities";
1940             if (mStaIfaceHal == null) {
1941                 handleNullHal(methodStr);
1942                 return 0;
1943             }
1944             return mStaIfaceHal.getAdvancedCapabilities(ifaceName);
1945         }
1946     }
1947 
1948     /**
1949      * Get the driver supported features through supplicant.
1950      *
1951      * @param ifaceName Name of the interface.
1952      * @return bitmask defined by WifiManager.WIFI_FEATURE_*.
1953      */
getWpaDriverFeatureSet(@onNull String ifaceName)1954     public long getWpaDriverFeatureSet(@NonNull String ifaceName) {
1955         synchronized (mLock) {
1956             String methodStr = "getWpaDriverFeatureSet";
1957             if (mStaIfaceHal == null) {
1958                 handleNullHal(methodStr);
1959                 return 0;
1960             }
1961             return mStaIfaceHal.getWpaDriverFeatureSet(ifaceName);
1962         }
1963     }
1964 
1965     /**
1966      * Returns connection capabilities of the current network
1967      *
1968      * @param ifaceName Name of the interface.
1969      * @return connection capabilities of the current network
1970      */
getConnectionCapabilities(@onNull String ifaceName)1971     public WifiNative.ConnectionCapabilities getConnectionCapabilities(@NonNull String ifaceName) {
1972         synchronized (mLock) {
1973             String methodStr = "getConnectionCapabilities";
1974             if (mStaIfaceHal == null) {
1975                 handleNullHal(methodStr);
1976                 return new WifiNative.ConnectionCapabilities();
1977             }
1978             return mStaIfaceHal.getConnectionCapabilities(ifaceName);
1979         }
1980     }
1981 
1982     /**
1983      * Returns signal poll results for all Wi-Fi links of the interface.
1984      *
1985      * @param ifaceName Name of the interface.
1986      * @return Signal poll results.
1987      */
getSignalPollResults(@onNull String ifaceName)1988     public WifiSignalPollResults getSignalPollResults(@NonNull String ifaceName) {
1989         synchronized (mLock) {
1990             String methodStr = "getSignalPollResults";
1991             if (mStaIfaceHal == null) {
1992                 handleNullHal(methodStr);
1993                 return null;
1994             }
1995             return mStaIfaceHal.getSignalPollResults(ifaceName);
1996         }
1997     }
1998 
1999     /**
2000      * Returns connection MLO links info.
2001      *
2002      * @param ifaceName Name of the interface.
2003      * @return connection MLO links info
2004      */
getConnectionMloLinksInfo(@onNull String ifaceName)2005     public WifiNative.ConnectionMloLinksInfo getConnectionMloLinksInfo(@NonNull String ifaceName) {
2006         synchronized (mLock) {
2007             String methodStr = "getConnectionMloLinksInfo";
2008             if (mStaIfaceHal == null) {
2009                 handleNullHal(methodStr);
2010                 return null;
2011             }
2012             return mStaIfaceHal.getConnectionMloLinksInfo(ifaceName);
2013         }
2014     }
2015 
2016     /**
2017      * Adds a DPP peer URI to the URI list.
2018      *
2019      * Returns an ID to be used later to refer to this URI (>0).
2020      * On error, or if these features are not supported, -1 is returned.
2021      */
addDppPeerUri(@onNull String ifaceName, @NonNull String uri)2022     public int addDppPeerUri(@NonNull String ifaceName, @NonNull String uri) {
2023         synchronized (mLock) {
2024             String methodStr = "addDppPeerUri";
2025             if (mStaIfaceHal == null) {
2026                 handleNullHal(methodStr);
2027                 return -1;
2028             }
2029             return mStaIfaceHal.addDppPeerUri(ifaceName, uri);
2030         }
2031     }
2032 
2033     /**
2034      * Removes a DPP URI to the URI list given an ID.
2035      *
2036      * Returns true when operation is successful
2037      * On error, or if these features are not supported, false is returned.
2038      */
removeDppUri(@onNull String ifaceName, int bootstrapId)2039     public boolean removeDppUri(@NonNull String ifaceName, int bootstrapId) {
2040         synchronized (mLock) {
2041             String methodStr = "removeDppUri";
2042             if (mStaIfaceHal == null) {
2043                 return handleNullHal(methodStr);
2044             }
2045             return mStaIfaceHal.removeDppUri(ifaceName, bootstrapId);
2046         }
2047     }
2048 
2049     /**
2050      * Stops/aborts DPP Initiator request
2051      *
2052      * Returns true when operation is successful
2053      * On error, or if these features are not supported, false is returned.
2054      */
stopDppInitiator(@onNull String ifaceName)2055     public boolean stopDppInitiator(@NonNull String ifaceName) {
2056         synchronized (mLock) {
2057             String methodStr = "stopDppInitiator";
2058             if (mStaIfaceHal == null) {
2059                 return handleNullHal(methodStr);
2060             }
2061             return mStaIfaceHal.stopDppInitiator(ifaceName);
2062         }
2063     }
2064 
2065     /**
2066      * Starts DPP Configurator-Initiator request
2067      *
2068      * Returns true when operation is successful
2069      * On error, or if these features are not supported, false is returned.
2070      */
startDppConfiguratorInitiator(@onNull String ifaceName, int peerBootstrapId, int ownBootstrapId, @NonNull String ssid, String password, String psk, int netRole, int securityAkm, byte[] privEcKey)2071     public boolean startDppConfiguratorInitiator(@NonNull String ifaceName, int peerBootstrapId,
2072             int ownBootstrapId, @NonNull String ssid, String password, String psk,
2073             int netRole, int securityAkm, byte[] privEcKey) {
2074         synchronized (mLock) {
2075             String methodStr = "startDppConfiguratorInitiator";
2076             if (mStaIfaceHal == null) {
2077                 return handleNullHal(methodStr);
2078             }
2079             return mStaIfaceHal.startDppConfiguratorInitiator(ifaceName, peerBootstrapId,
2080                     ownBootstrapId, ssid, password, psk, netRole, securityAkm, privEcKey);
2081         }
2082     }
2083 
2084     /**
2085      * Starts DPP Enrollee-Initiator request
2086      *
2087      * Returns true when operation is successful
2088      * On error, or if these features are not supported, false is returned.
2089      */
startDppEnrolleeInitiator(@onNull String ifaceName, int peerBootstrapId, int ownBootstrapId)2090     public boolean startDppEnrolleeInitiator(@NonNull String ifaceName, int peerBootstrapId,
2091             int ownBootstrapId) {
2092         synchronized (mLock) {
2093             String methodStr = "startDppEnrolleeInitiator";
2094             if (mStaIfaceHal == null) {
2095                 return handleNullHal(methodStr);
2096             }
2097             return mStaIfaceHal.startDppEnrolleeInitiator(
2098                     ifaceName, peerBootstrapId, ownBootstrapId);
2099         }
2100     }
2101 
2102     /**
2103      * Generate a DPP QR code based on boot strap info
2104      *
2105      * Returns DppBootstrapQrCodeInfo
2106      */
generateDppBootstrapInfoForResponder( @onNull String ifaceName, String macAddress, @NonNull String deviceInfo, int dppCurve)2107     public WifiNative.DppBootstrapQrCodeInfo generateDppBootstrapInfoForResponder(
2108             @NonNull String ifaceName, String macAddress, @NonNull String deviceInfo,
2109             int dppCurve) {
2110         synchronized (mLock) {
2111             String methodStr = "generateDppBootstrapInfoForResponder";
2112             if (mStaIfaceHal == null) {
2113                 handleNullHal(methodStr);
2114                 return new WifiNative.DppBootstrapQrCodeInfo();
2115             }
2116             return mStaIfaceHal.generateDppBootstrapInfoForResponder(
2117                     ifaceName, macAddress, deviceInfo, dppCurve);
2118         }
2119     }
2120 
2121     /**
2122      * Starts DPP Enrollee-Responder request
2123      *
2124      * Returns true when operation is successful
2125      * On error, or if these features are not supported, false is returned.
2126      */
startDppEnrolleeResponder(@onNull String ifaceName, int listenChannel)2127     public boolean startDppEnrolleeResponder(@NonNull String ifaceName, int listenChannel) {
2128         synchronized (mLock) {
2129             String methodStr = "startDppEnrolleeResponder";
2130             if (mStaIfaceHal == null) {
2131                 return handleNullHal(methodStr);
2132             }
2133             return mStaIfaceHal.startDppEnrolleeResponder(ifaceName, listenChannel);
2134         }
2135     }
2136 
2137     /**
2138      * Stops/aborts DPP Responder request.
2139      *
2140      * Returns true when operation is successful
2141      * On error, or if these features are not supported, false is returned.
2142      */
stopDppResponder(@onNull String ifaceName, int ownBootstrapId)2143     public boolean stopDppResponder(@NonNull String ifaceName, int ownBootstrapId) {
2144         synchronized (mLock) {
2145             String methodStr = "stopDppResponder";
2146             if (mStaIfaceHal == null) {
2147                 return handleNullHal(methodStr);
2148             }
2149             return mStaIfaceHal.stopDppResponder(ifaceName, ownBootstrapId);
2150         }
2151     }
2152 
2153     /**
2154      * Register callbacks for DPP events.
2155      *
2156      * @param dppCallback DPP callback object.
2157      */
registerDppCallback(WifiNative.DppEventCallback dppCallback)2158     public void registerDppCallback(WifiNative.DppEventCallback dppCallback) {
2159         synchronized (mLock) {
2160             String methodStr = "registerDppCallback";
2161             if (mStaIfaceHal == null) {
2162                 handleNullHal(methodStr);
2163                 return;
2164             }
2165             mStaIfaceHal.registerDppCallback(dppCallback);
2166         }
2167     }
2168 
2169     /**
2170      * Set MBO cellular data availability.
2171      *
2172      * @param ifaceName Name of the interface.
2173      * @param available true means cellular data available, false otherwise.
2174      * Returns true when operation is successful
2175      */
setMboCellularDataStatus(@onNull String ifaceName, boolean available)2176     public boolean setMboCellularDataStatus(@NonNull String ifaceName, boolean available) {
2177         synchronized (mLock) {
2178             String methodStr = "setMboCellularDataStatus";
2179             if (mStaIfaceHal == null) {
2180                 return handleNullHal(methodStr);
2181             }
2182             return mStaIfaceHal.setMboCellularDataStatus(ifaceName, available);
2183         }
2184     }
2185 
2186     /**
2187      * Set whether the network-centric QoS policy feature is enabled or not for this interface.
2188      *
2189      * @param ifaceName name of the interface.
2190      * @param isEnabled true if feature is enabled, false otherwise.
2191      * @return true if operation is successful, false otherwise.
2192      */
setNetworkCentricQosPolicyFeatureEnabled(@onNull String ifaceName, boolean isEnabled)2193     public boolean setNetworkCentricQosPolicyFeatureEnabled(@NonNull String ifaceName,
2194             boolean isEnabled) {
2195         synchronized (mLock) {
2196             String methodStr = "setNetworkCentricQosPolicyFeatureEnabled";
2197             if (mStaIfaceHal == null) {
2198                 return handleNullHal(methodStr);
2199             }
2200             return mStaIfaceHal.setNetworkCentricQosPolicyFeatureEnabled(ifaceName, isEnabled);
2201         }
2202     }
2203 
2204     /**
2205      * Check if we've roamed to a linked network and make the linked network the current network
2206      * if we have.
2207      *
2208      * @param ifaceName Name of the interface.
2209      * @param newNetworkId Network id of the new network we've roamed to. If fromFramework is
2210      *                     {@code true}, this will be a framework network id. Otherwise, this will
2211      *                     be a remote network id.
2212      * @param fromFramework {@code true} if the network id is a framework network id, {@code false}
2213                             if the network id is a remote network id.
2214      * @return true if we've roamed to a linked network, false if not.
2215      */
updateOnLinkedNetworkRoaming( @onNull String ifaceName, int newNetworkId, boolean fromFramework)2216     public boolean updateOnLinkedNetworkRoaming(
2217             @NonNull String ifaceName, int newNetworkId, boolean fromFramework) {
2218         synchronized (mLock) {
2219             String methodStr = "updateOnLinkedNetworkRoaming";
2220             if (mStaIfaceHal == null) {
2221                 return handleNullHal(methodStr);
2222             }
2223             return mStaIfaceHal.updateOnLinkedNetworkRoaming(
2224                     ifaceName, newNetworkId, fromFramework);
2225         }
2226     }
2227 
2228     /**
2229      * Updates the linked networks for the current network and sends them to the supplicant.
2230      *
2231      * @param ifaceName Name of the interface.
2232      * @param networkId Network id of the network to link the configurations to.
2233      * @param linkedConfigurations Map of config profile key to config for linking.
2234      * @return true if networks were successfully linked, false otherwise.
2235      */
updateLinkedNetworks(@onNull String ifaceName, int networkId, Map<String, WifiConfiguration> linkedConfigurations)2236     public boolean updateLinkedNetworks(@NonNull String ifaceName, int networkId,
2237             Map<String, WifiConfiguration> linkedConfigurations) {
2238         synchronized (mLock) {
2239             String methodStr = "updateLinkedNetworks";
2240             if (mStaIfaceHal == null) {
2241                 return handleNullHal(methodStr);
2242             }
2243             return mStaIfaceHal.updateLinkedNetworks(ifaceName, networkId, linkedConfigurations);
2244         }
2245     }
2246 
2247     /**
2248      * Gets the security params of the current network associated with this interface
2249      *
2250      * @param ifaceName Name of the interface
2251      * @return Security params of the current network associated with the interface
2252      */
getCurrentNetworkSecurityParams(@onNull String ifaceName)2253     public SecurityParams getCurrentNetworkSecurityParams(@NonNull String ifaceName) {
2254         synchronized (mLock) {
2255             String methodStr = "getCurrentNetworkSecurityParams";
2256             if (mStaIfaceHal == null) {
2257                 handleNullHal(methodStr);
2258                 return null;
2259             }
2260             return mStaIfaceHal.getCurrentNetworkSecurityParams(ifaceName);
2261         }
2262     }
2263 
2264     /**
2265      * Sends a QoS policy response.
2266      *
2267      * @param ifaceName Name of the interface.
2268      * @param qosPolicyRequestId Dialog token to identify the request.
2269      * @param morePolicies Flag to indicate more QoS policies can be accommodated.
2270      * @param qosPolicyStatusList List of framework QosPolicyStatus objects.
2271      * @return true if response is sent successfully, false otherwise.
2272      */
sendQosPolicyResponse(String ifaceName, int qosPolicyRequestId, boolean morePolicies, @NonNull List<QosPolicyStatus> qosPolicyStatusList)2273     public boolean sendQosPolicyResponse(String ifaceName, int qosPolicyRequestId,
2274             boolean morePolicies, @NonNull List<QosPolicyStatus> qosPolicyStatusList) {
2275         String methodStr = "sendQosPolicyResponse";
2276         if (mStaIfaceHal == null) {
2277             handleNullHal(methodStr);
2278             return false;
2279         }
2280         return mStaIfaceHal.sendQosPolicyResponse(ifaceName, qosPolicyRequestId,
2281                 morePolicies, qosPolicyStatusList);
2282     }
2283 
2284     /**
2285      * Indicates the removal of all active QoS policies configured by the AP.
2286      *
2287      * @param ifaceName Name of the interface.
2288      */
removeAllQosPolicies(String ifaceName)2289     public boolean removeAllQosPolicies(String ifaceName) {
2290         String methodStr = "removeAllQosPolicies";
2291         if (mStaIfaceHal == null) {
2292             return handleNullHal(methodStr);
2293         }
2294         return mStaIfaceHal.removeAllQosPolicies(ifaceName);
2295     }
2296 
2297     /**
2298      * See comments for {@link ISupplicantStaIfaceHal#addQosPolicyRequestForScs(String, List)}
2299      */
addQosPolicyRequestForScs( @onNull String ifaceName, @NonNull List<QosPolicyParams> policies)2300     public List<QosPolicyStatus> addQosPolicyRequestForScs(
2301             @NonNull String ifaceName, @NonNull List<QosPolicyParams> policies) {
2302         String methodStr = "addQosPolicyRequestForScs";
2303         if (mStaIfaceHal == null) {
2304             handleNullHal(methodStr);
2305             return null;
2306         }
2307         return mStaIfaceHal.addQosPolicyRequestForScs(ifaceName, policies);
2308     }
2309 
2310     /**
2311      * See comments for {@link ISupplicantStaIfaceHal#removeQosPolicyForScs(String, List)}
2312      */
removeQosPolicyForScs( @onNull String ifaceName, @NonNull List<Byte> policyIds)2313     public List<QosPolicyStatus> removeQosPolicyForScs(
2314             @NonNull String ifaceName, @NonNull List<Byte> policyIds) {
2315         String methodStr = "removeQosPolicyForScs";
2316         if (mStaIfaceHal == null) {
2317             handleNullHal(methodStr);
2318             return null;
2319         }
2320         return mStaIfaceHal.removeQosPolicyForScs(ifaceName, policyIds);
2321     }
2322 
2323     /**
2324      * See comments for
2325      * {@link ISupplicantStaIfaceHal#registerQosScsResponseCallback(QosScsResponseCallback)}
2326      */
registerQosScsResponseCallback(@onNull QosScsResponseCallback callback)2327     public void registerQosScsResponseCallback(@NonNull QosScsResponseCallback callback) {
2328         String methodStr = "registerQosScsResponseCallback";
2329         if (mStaIfaceHal == null) {
2330             handleNullHal(methodStr);
2331             return;
2332         }
2333         mStaIfaceHal.registerQosScsResponseCallback(callback);
2334     }
2335 
2336     /**
2337      * Generate DPP credential for network access
2338      *
2339      * @param ifaceName Name of the interface.
2340      * @param ssid ssid of the network
2341      * @param privEcKey Private EC Key for DPP Configurator
2342      * Returns true when operation is successful. On error, false is returned.
2343      */
generateSelfDppConfiguration(@onNull String ifaceName, @NonNull String ssid, byte[] privEcKey)2344     public boolean generateSelfDppConfiguration(@NonNull String ifaceName, @NonNull String ssid,
2345             byte[] privEcKey) {
2346         synchronized (mLock) {
2347             String methodStr = "generateSelfDppConfiguration";
2348             if (mStaIfaceHal == null) {
2349                 return handleNullHal(methodStr);
2350             }
2351             return mStaIfaceHal.generateSelfDppConfiguration(ifaceName, ssid, privEcKey);
2352         }
2353     }
2354 
2355     /**
2356      * This set anonymous identity to supplicant.
2357      *
2358      * @param ifaceName Name of the interface.
2359      * @param anonymousIdentity the anonymouns identity.
2360      * @param updateToNativeService write the data to the native service.
2361      * @return true if succeeds, false otherwise.
2362      */
setEapAnonymousIdentity(@onNull String ifaceName, String anonymousIdentity, boolean updateToNativeService)2363     public boolean setEapAnonymousIdentity(@NonNull String ifaceName, String anonymousIdentity,
2364             boolean updateToNativeService) {
2365         String methodStr = "setEapAnonymousIdentity";
2366         if (mStaIfaceHal == null) {
2367             return handleNullHal(methodStr);
2368         }
2369         return mStaIfaceHal.setEapAnonymousIdentity(ifaceName, anonymousIdentity,
2370                 updateToNativeService);
2371     }
2372 
2373     /**
2374      * See comments for {@link ISupplicantStaIfaceHal#enableMscs(MscsParams, String)}
2375      */
enableMscs(@onNull MscsParams mscsParams, String ifaceName)2376     public void enableMscs(@NonNull MscsParams mscsParams, String ifaceName) {
2377         String methodStr = "enableMscs";
2378         if (mStaIfaceHal == null) {
2379             handleNullHal(methodStr);
2380             return;
2381         }
2382         mStaIfaceHal.enableMscs(mscsParams, ifaceName);
2383     }
2384 
2385     /**
2386      * See comments for {@link ISupplicantStaIfaceHal#resendMscs(String)}
2387      */
resendMscs(String ifaceName)2388     public void resendMscs(String ifaceName) {
2389         String methodStr = "resendMscs";
2390         if (mStaIfaceHal == null) {
2391             handleNullHal(methodStr);
2392             return;
2393         }
2394         mStaIfaceHal.resendMscs(ifaceName);
2395     }
2396 
2397     /**
2398      * See comments for {@link ISupplicantStaIfaceHal#disableMscs(String)}
2399      */
disableMscs(String ifaceName)2400     public void disableMscs(String ifaceName) {
2401         String methodStr = "disableMscs";
2402         if (mStaIfaceHal == null) {
2403             handleNullHal(methodStr);
2404             return;
2405         }
2406         mStaIfaceHal.disableMscs(ifaceName);
2407     }
2408 
handleNullHal(String methodStr)2409     private boolean handleNullHal(String methodStr) {
2410         Log.e(TAG, "Cannot call " + methodStr + " because HAL object is null.");
2411         return false;
2412     }
2413 }
2414