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