1 /*
2  * Copyright (C) 2020 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 
17 package com.android.server.wifi;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.net.DhcpResultsParcelable;
23 import android.net.MacAddress;
24 import android.net.Network;
25 import android.net.wifi.IWifiConnectedNetworkScorer;
26 import android.net.wifi.WifiAnnotations;
27 import android.net.wifi.WifiConfiguration;
28 import android.net.wifi.WifiInfo;
29 import android.net.wifi.WifiManager.DeviceMobilityState;
30 import android.net.wifi.hotspot2.IProvisioningCallback;
31 import android.net.wifi.hotspot2.OsuProvider;
32 import android.net.wifi.nl80211.DeviceWiphyCapabilities;
33 import android.net.wifi.nl80211.WifiNl80211Manager;
34 import android.os.IBinder;
35 import android.os.Message;
36 import android.os.WorkSource;
37 
38 import com.android.server.wifi.WifiNative.RxFateReport;
39 import com.android.server.wifi.WifiNative.TxFateReport;
40 import com.android.server.wifi.util.ActionListenerWrapper;
41 
42 import java.io.FileDescriptor;
43 import java.io.PrintWriter;
44 import java.lang.annotation.Retention;
45 import java.lang.annotation.RetentionPolicy;
46 import java.util.List;
47 import java.util.Set;
48 
49 /**
50  * This interface is used to respond to calls independent of a STA's current mode.
51  * If the STA is in scan only mode, ClientMode is implemented using {@link ScanOnlyModeImpl}.
52  * If the STA is in client mode, ClientMode is implemented using {@link ClientModeImpl}.
53  */
54 public interface ClientMode {
55     @Retention(RetentionPolicy.SOURCE)
56     @IntDef(flag = true, prefix = {"POWER_SAVE_CLIENT_"},
57             value = {
58                     POWER_SAVE_CLIENT_DHCP,
59                     POWER_SAVE_CLIENT_WIFI_LOCK})
60     @interface PowerSaveClientType {}
61     int POWER_SAVE_CLIENT_DHCP = 0x1;
62     int POWER_SAVE_CLIENT_WIFI_LOCK = 0x2;
63 
dump(FileDescriptor fd, PrintWriter pw, String[] args)64     void dump(FileDescriptor fd, PrintWriter pw, String[] args);
65 
enableVerboseLogging(boolean verbose)66     void enableVerboseLogging(boolean verbose);
67 
connectNetwork(NetworkUpdateResult result, ActionListenerWrapper wrapper, int callingUid, @NonNull String packageName, @Nullable String attributionTag)68     void connectNetwork(NetworkUpdateResult result, ActionListenerWrapper wrapper, int callingUid,
69             @NonNull String packageName, @Nullable String attributionTag);
70 
saveNetwork(NetworkUpdateResult result, ActionListenerWrapper wrapper, int callingUid, @NonNull String packageName)71     void saveNetwork(NetworkUpdateResult result, ActionListenerWrapper wrapper, int callingUid,
72             @NonNull String packageName);
73 
disconnect()74     void disconnect();
75 
reconnect(WorkSource ws)76     void reconnect(WorkSource ws);
77 
reassociate()78     void reassociate();
79 
startConnectToNetwork(int networkId, int uid, String bssid)80     void startConnectToNetwork(int networkId, int uid, String bssid);
81 
startRoamToNetwork(int networkId, String bssid)82     void startRoamToNetwork(int networkId, String bssid);
83 
84     /** When the device mobility changes, update the RSSI polling interval accordingly */
onDeviceMobilityStateUpdated(@eviceMobilityState int newState)85     void onDeviceMobilityStateUpdated(@DeviceMobilityState int newState);
86 
87     /**
88      * Set the fixed link layer stats polling interval when it is overridden, or set the interval
89      * to be handled automatically by the framework
90      * @param newIntervalMs new link layer stats polling interval in milliseconds. Use value 0
91      *                      for automatic handling
92      */
setLinkLayerStatsPollingInterval(int newIntervalMs)93     void setLinkLayerStatsPollingInterval(int newIntervalMs);
94 
95     /**
96      * See {@link android.net.wifi.WifiManager#setWifiConnectedNetworkScorer(Executor,
97      * WifiManager.WifiConnectedNetworkScorer)}
98      */
setWifiConnectedNetworkScorer(IBinder binder, IWifiConnectedNetworkScorer scorer, int callerUid)99     boolean setWifiConnectedNetworkScorer(IBinder binder, IWifiConnectedNetworkScorer scorer,
100             int callerUid);
101 
clearWifiConnectedNetworkScorer()102     void clearWifiConnectedNetworkScorer();
103 
104     /**
105      * Notify the connected network scorer of the user accepting a network switch.
106      */
onNetworkSwitchAccepted(int targetNetworkId, String targetBssid)107     void onNetworkSwitchAccepted(int targetNetworkId, String targetBssid);
108 
109     /**
110      * Notify the connected network scorer of the user rejecting a network switch.
111      */
onNetworkSwitchRejected(int targetNetworkId, String targetBssid)112     void onNetworkSwitchRejected(int targetNetworkId, String targetBssid);
113 
resetSimAuthNetworks(@lientModeImpl.ResetSimReason int resetReason)114     void resetSimAuthNetworks(@ClientModeImpl.ResetSimReason int resetReason);
115 
116     /**
117      * Notification that the Bluetooth connection state changed. The latest connection state can be
118      * fetched from {@link WifiGlobals#isBluetoothConnected()}.
119      */
onBluetoothConnectionStateChanged()120     void onBluetoothConnectionStateChanged();
121 
122     /**
123      * Get current Wifi connection information
124      * @return Wifi info
125      */
getConnectionInfo()126     WifiInfo getConnectionInfo();
127 
syncQueryPasspointIcon(long bssid, String fileName)128     boolean syncQueryPasspointIcon(long bssid, String fileName);
129 
130     /**
131      * Get the current Wifi network information
132      * @return network
133      */
getCurrentNetwork()134     Network getCurrentNetwork();
135 
syncGetDhcpResultsParcelable()136     DhcpResultsParcelable syncGetDhcpResultsParcelable();
137 
138     /** Get the supported feature set synchronously */
getSupportedFeatures()139     long getSupportedFeatures();
140 
syncStartSubscriptionProvisioning(int callingUid, OsuProvider provider, IProvisioningCallback callback)141     boolean syncStartSubscriptionProvisioning(int callingUid, OsuProvider provider,
142             IProvisioningCallback callback);
143 
isWifiStandardSupported(@ifiAnnotations.WifiStandard int standard)144     boolean isWifiStandardSupported(@WifiAnnotations.WifiStandard int standard);
145 
146     /** Enable TDLS session with remote MAC address */
enableTdls(String remoteMacAddress, boolean enable)147     boolean enableTdls(String remoteMacAddress, boolean enable);
148 
149     /** Enable TDLS session with remote IP address */
enableTdlsWithRemoteIpAddress(String remoteIpAddress, boolean enable)150     boolean enableTdlsWithRemoteIpAddress(String remoteIpAddress, boolean enable);
151 
152     /** Check if a TDLS session can be established */
isTdlsOperationCurrentlyAvailable()153     boolean isTdlsOperationCurrentlyAvailable();
154 
155     /** The maximum number of TDLS sessions supported by the device */
getMaxSupportedConcurrentTdlsSessions()156     int getMaxSupportedConcurrentTdlsSessions();
157 
158     /** The number of Peer mac addresses configured in the device for establishing a TDLS session */
getNumberOfEnabledTdlsSessions()159     int getNumberOfEnabledTdlsSessions();
160 
dumpIpClient(FileDescriptor fd, PrintWriter pw, String[] args)161     void dumpIpClient(FileDescriptor fd, PrintWriter pw, String[] args);
162 
dumpWifiScoreReport(FileDescriptor fd, PrintWriter pw, String[] args)163     void dumpWifiScoreReport(FileDescriptor fd, PrintWriter pw, String[] args);
164 
getFactoryMacAddress()165     String getFactoryMacAddress();
166 
167     /**
168      * Returns WifiConfiguration object corresponding to the currently connected network, null if
169      * not connected.
170      */
171     @Nullable
getConnectedWifiConfiguration()172     WifiConfiguration getConnectedWifiConfiguration();
173 
174     /**
175      * Returns WifiConfiguration object corresponding to the currently connecting network, null if
176      * not connecting.
177      */
getConnectingWifiConfiguration()178     @Nullable WifiConfiguration getConnectingWifiConfiguration();
179 
180     /**
181      * Returns bssid corresponding to the currently connected network, null if not connected.
182      */
getConnectedBssid()183     @Nullable String getConnectedBssid();
184 
185     /**
186      * Returns bssid corresponding to the currently connecting network, null if not connecting.
187      */
getConnectingBssid()188     @Nullable String getConnectingBssid();
189 
getWifiLinkLayerStats()190     WifiLinkLayerStats getWifiLinkLayerStats();
191 
setPowerSave(@owerSaveClientType int client, boolean ps)192     boolean setPowerSave(@PowerSaveClientType int client, boolean ps);
enablePowerSave()193     boolean enablePowerSave();
194 
setLowLatencyMode(boolean enabled)195     boolean setLowLatencyMode(boolean enabled);
196 
getMcastLockManagerFilterController()197     WifiMulticastLockManager.FilterController getMcastLockManagerFilterController();
198 
isConnected()199     boolean isConnected();
200 
isConnecting()201     boolean isConnecting();
202 
isRoaming()203     boolean isRoaming();
204 
isDisconnected()205     boolean isDisconnected();
206 
isSupplicantTransientState()207     boolean isSupplicantTransientState();
208 
onCellularConnectivityChanged(@ifiDataStall.CellularDataStatusCode int status)209     void onCellularConnectivityChanged(@WifiDataStall.CellularDataStatusCode int status);
210 
211     /** returns whether the current network is labeled as local-only due to ip provision timeout */
isIpProvisioningTimedOut()212     boolean isIpProvisioningTimedOut();
213 
214     /** Result callback for {@link #probeLink(LinkProbeCallback, int)} */
215     interface LinkProbeCallback extends WifiNl80211Manager.SendMgmtFrameCallback {
216 
217         @Retention(RetentionPolicy.SOURCE)
218         @IntDef(prefix = {"LINK_PROBE_ERROR_"},
219                 value = {LINK_PROBE_ERROR_NOT_CONNECTED})
220         @interface LinkProbeFailure {}
221 
222         /** Attempted to send a link probe when not connected to Wifi. */
223         // Note: this is a restriction in the Wifi framework since link probing is defined to be
224         // targeted at the currently connected AP. Driver/firmware has no problems with sending
225         // management frames to arbitrary APs whether connected or disconnected.
226         int LINK_PROBE_ERROR_NOT_CONNECTED = 1000;
227 
228         /**
229          * Called when the link probe failed.
230          * @param reason The error code for the failure. One of
231          * {@link WifiNl80211Manager.SendMgmtFrameError} or {@link LinkProbeFailure}.
232          */
onFailure(int reason)233         void onFailure(int reason);
234 
failureReasonToString(int reason)235         static String failureReasonToString(int reason) {
236             switch (reason) {
237                 case WifiNl80211Manager.SEND_MGMT_FRAME_ERROR_UNKNOWN:
238                     return "SEND_MGMT_FRAME_ERROR_UNKNOWN";
239                 case WifiNl80211Manager.SEND_MGMT_FRAME_ERROR_MCS_UNSUPPORTED:
240                     return "SEND_MGMT_FRAME_ERROR_MCS_UNSUPPORTED";
241                 case WifiNl80211Manager.SEND_MGMT_FRAME_ERROR_NO_ACK:
242                     return "SEND_MGMT_FRAME_ERROR_NO_ACK";
243                 case WifiNl80211Manager.SEND_MGMT_FRAME_ERROR_TIMEOUT:
244                     return "SEND_MGMT_FRAME_ERROR_TIMEOUT";
245                 case WifiNl80211Manager.SEND_MGMT_FRAME_ERROR_ALREADY_STARTED:
246                     return "SEND_MGMT_FRAME_ERROR_ALREADY_STARTED";
247                 case LINK_PROBE_ERROR_NOT_CONNECTED:
248                     return "LINK_PROBE_ERROR_NOT_CONNECTED";
249                 default:
250                     return "Unrecognized error";
251             }
252         }
253     }
254 
255     /** Send a link probe */
probeLink(LinkProbeCallback callback, int mcs)256     void probeLink(LinkProbeCallback callback, int mcs);
257 
258     /** Send a {@link Message} to ClientModeImpl's StateMachine. */
sendMessageToClientModeImpl(Message msg)259     void sendMessageToClientModeImpl(Message msg);
260 
261     /** Unique ID for this ClientMode instance, used for debugging. */
getId()262     long getId();
263 
264     /**
265      * Set MBO cellular data status
266      * @param available cellular data status, true means cellular data available, false otherwise.
267      */
setMboCellularDataStatus(boolean available)268     void setMboCellularDataStatus(boolean available);
269 
270     /**
271      * Query the firmware roaming capabilities.
272      * @return Roaming Capabilities on success, null on failure.
273      */
274     @Nullable
getRoamingCapabilities()275     WifiNative.RoamingCapabilities getRoamingCapabilities();
276 
277     /** Set firmware roaming configurations. */
configureRoaming(WifiNative.RoamingConfig config)278     boolean configureRoaming(WifiNative.RoamingConfig config);
279 
280     /** Enable/Disable firmware roaming. */
enableRoaming(boolean enabled)281     boolean enableRoaming(boolean enabled);
282 
283     /**
284      * Set country code.
285      *
286      * @param countryCode 2 byte ASCII string. For ex: US, CA.
287      * @return true if request is sent successfully, false otherwise.
288      */
setCountryCode(String countryCode)289     boolean setCountryCode(String countryCode);
290 
291     /**
292      * Fetch the most recent TX packet fates from the HAL. Fails unless HAL is started.
293      * @return TxFateReport list on success, empty list on failure. Never returns null.
294      */
295     @NonNull
getTxPktFates()296     List<TxFateReport> getTxPktFates();
297 
298     /**
299      * Fetch the most recent RX packet fates from the HAL. Fails unless HAL is started.
300      * @return RxFateReport list on success, empty list on failure. Never returns null.
301      */
302     @NonNull
getRxPktFates()303     List<RxFateReport> getRxPktFates();
304 
305     /**
306      * Get the Wiphy capabilities of a device for a given interface
307      * If the interface is not associated with one,
308      * it will be read from the device through wificond
309      *
310      * @return the device capabilities for this interface, or null if not available
311      */
312     @Nullable
getDeviceWiphyCapabilities()313     DeviceWiphyCapabilities getDeviceWiphyCapabilities();
314 
315     /**
316      * Initiate ANQP query.
317      *
318      * @param bssid BSSID of the AP to be queried
319      * @param anqpIds Set of anqp IDs.
320      * @param hs20Subtypes Set of HS20 subtypes.
321      * @return true on success, false otherwise.
322      */
requestAnqp(String bssid, Set<Integer> anqpIds, Set<Integer> hs20Subtypes)323     boolean requestAnqp(String bssid, Set<Integer> anqpIds, Set<Integer> hs20Subtypes);
324 
325     /**
326      * Initiate Venue URL ANQP query.
327      *
328      * @param bssid BSSID of the AP to be queried
329      * @return true on success, false otherwise.
330      */
requestVenueUrlAnqp(String bssid)331     boolean requestVenueUrlAnqp(String bssid);
332 
333     /**
334      * Request a passpoint icon file |filename| from the specified AP |bssid|.
335      *
336      * @param bssid BSSID of the AP
337      * @param fileName name of the icon file
338      * @return true if request is sent successfully, false otherwise
339      */
requestIcon(String bssid, String fileName)340     boolean requestIcon(String  bssid, String fileName);
341 
342     /**
343      * If set to true, the NetworkAgent score for connections established on this ClientModeManager
344      * will be artificially reduced so that ConnectivityService will prefer any other connection.
345      */
setShouldReduceNetworkScore(boolean shouldReduceNetworkScore)346     void setShouldReduceNetworkScore(boolean shouldReduceNetworkScore);
347 
348 
349     /**
350      * update the capabilities
351      */
updateCapabilities()352     void updateCapabilities();
353 
354     /**
355      * Check if BSSID belongs to any of the affiliated link BSSID's.
356      * @param bssid BSSID of the AP
357      * @return true if BSSID matches to one of the affiliated link BSSIDs, false otherwise.
358      */
isAffiliatedLinkBssid(MacAddress bssid)359     boolean isAffiliatedLinkBssid(MacAddress bssid);
360 
361     /**
362      * Check if the connection is MLO (Multi-Link Operation).
363      * @return true if connection is MLO, otherwise false.
364      */
isMlo()365     boolean isMlo();
366 
367     /**
368      * Notify changes in PowerManager#isDeviceIdleMode
369      */
onIdleModeChanged(boolean isIdle)370     void onIdleModeChanged(boolean isIdle);
371 }
372