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