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.Network; 24 import android.net.wifi.IWifiConnectedNetworkScorer; 25 import android.net.wifi.WifiAnnotations; 26 import android.net.wifi.WifiConfiguration; 27 import android.net.wifi.WifiInfo; 28 import android.net.wifi.hotspot2.IProvisioningCallback; 29 import android.net.wifi.hotspot2.OsuProvider; 30 import android.net.wifi.nl80211.DeviceWiphyCapabilities; 31 import android.net.wifi.nl80211.WifiNl80211Manager; 32 import android.os.IBinder; 33 import android.os.Message; 34 import android.os.WorkSource; 35 36 import com.android.server.wifi.WifiNative.RxFateReport; 37 import com.android.server.wifi.WifiNative.TxFateReport; 38 import com.android.server.wifi.util.ActionListenerWrapper; 39 40 import java.io.FileDescriptor; 41 import java.io.PrintWriter; 42 import java.lang.annotation.Retention; 43 import java.lang.annotation.RetentionPolicy; 44 import java.util.List; 45 import java.util.Set; 46 47 /** 48 * This interface is used to respond to calls independent of a STA's current mode. 49 * If the STA is in scan only mode, ClientMode is implemented using {@link ScanOnlyModeImpl}. 50 * If the STA is in client mode, ClientMode is implemented using {@link ClientModeImpl}. 51 */ 52 public interface ClientMode { dump(FileDescriptor fd, PrintWriter pw, String[] args)53 void dump(FileDescriptor fd, PrintWriter pw, String[] args); 54 enableVerboseLogging(boolean verbose)55 void enableVerboseLogging(boolean verbose); 56 connectNetwork(NetworkUpdateResult result, ActionListenerWrapper wrapper, int callingUid)57 void connectNetwork(NetworkUpdateResult result, ActionListenerWrapper wrapper, int callingUid); 58 saveNetwork(NetworkUpdateResult result, ActionListenerWrapper wrapper, int callingUid)59 void saveNetwork(NetworkUpdateResult result, ActionListenerWrapper wrapper, int callingUid); 60 disconnect()61 void disconnect(); 62 reconnect(WorkSource ws)63 void reconnect(WorkSource ws); 64 reassociate()65 void reassociate(); 66 startConnectToNetwork(int networkId, int uid, String bssid)67 void startConnectToNetwork(int networkId, int uid, String bssid); 68 startRoamToNetwork(int networkId, String bssid)69 void startRoamToNetwork(int networkId, String bssid); 70 setWifiConnectedNetworkScorer(IBinder binder, IWifiConnectedNetworkScorer scorer)71 boolean setWifiConnectedNetworkScorer(IBinder binder, IWifiConnectedNetworkScorer scorer); 72 clearWifiConnectedNetworkScorer()73 void clearWifiConnectedNetworkScorer(); 74 resetSimAuthNetworks(@lientModeImpl.ResetSimReason int resetReason)75 void resetSimAuthNetworks(@ClientModeImpl.ResetSimReason int resetReason); 76 77 /** 78 * Notification that the Bluetooth connection state changed. The latest connection state can be 79 * fetched from {@link WifiGlobals#isBluetoothConnected()}. 80 */ onBluetoothConnectionStateChanged()81 void onBluetoothConnectionStateChanged(); 82 syncRequestConnectionInfo()83 WifiInfo syncRequestConnectionInfo(); 84 syncQueryPasspointIcon(long bssid, String fileName)85 boolean syncQueryPasspointIcon(long bssid, String fileName); 86 syncGetCurrentNetwork()87 Network syncGetCurrentNetwork(); 88 syncGetDhcpResultsParcelable()89 DhcpResultsParcelable syncGetDhcpResultsParcelable(); 90 91 /** Get the supported feature set synchronously */ getSupportedFeatures()92 long getSupportedFeatures(); 93 syncStartSubscriptionProvisioning(int callingUid, OsuProvider provider, IProvisioningCallback callback)94 boolean syncStartSubscriptionProvisioning(int callingUid, OsuProvider provider, 95 IProvisioningCallback callback); 96 isWifiStandardSupported(@ifiAnnotations.WifiStandard int standard)97 boolean isWifiStandardSupported(@WifiAnnotations.WifiStandard int standard); 98 enableTdls(String remoteMacAddress, boolean enable)99 void enableTdls(String remoteMacAddress, boolean enable); 100 dumpIpClient(FileDescriptor fd, PrintWriter pw, String[] args)101 void dumpIpClient(FileDescriptor fd, PrintWriter pw, String[] args); 102 dumpWifiScoreReport(FileDescriptor fd, PrintWriter pw, String[] args)103 void dumpWifiScoreReport(FileDescriptor fd, PrintWriter pw, String[] args); 104 getFactoryMacAddress()105 String getFactoryMacAddress(); 106 107 /** 108 * Returns WifiConfiguration object corresponding to the currently connected network, null if 109 * not connected. 110 */ 111 @Nullable getConnectedWifiConfiguration()112 WifiConfiguration getConnectedWifiConfiguration(); 113 114 /** 115 * Returns WifiConfiguration object corresponding to the currently connecting network, null if 116 * not connecting. 117 */ getConnectingWifiConfiguration()118 @Nullable WifiConfiguration getConnectingWifiConfiguration(); 119 120 /** 121 * Returns bssid corresponding to the currently connected network, null if not connected. 122 */ getConnectedBssid()123 @Nullable String getConnectedBssid(); 124 125 /** 126 * Returns bssid corresponding to the currently connecting network, null if not connecting. 127 */ getConnectingBssid()128 @Nullable String getConnectingBssid(); 129 getWifiLinkLayerStats()130 WifiLinkLayerStats getWifiLinkLayerStats(); 131 setPowerSave(boolean ps)132 boolean setPowerSave(boolean ps); 133 setLowLatencyMode(boolean enabled)134 boolean setLowLatencyMode(boolean enabled); 135 getMcastLockManagerFilterController()136 WifiMulticastLockManager.FilterController getMcastLockManagerFilterController(); 137 isConnected()138 boolean isConnected(); 139 isConnecting()140 boolean isConnecting(); 141 isRoaming()142 boolean isRoaming(); 143 isDisconnected()144 boolean isDisconnected(); 145 isSupplicantTransientState()146 boolean isSupplicantTransientState(); 147 onCellularConnectivityChanged(@ifiDataStall.CellularDataStatusCode int status)148 void onCellularConnectivityChanged(@WifiDataStall.CellularDataStatusCode int status); 149 150 /** Result callback for {@link #probeLink(LinkProbeCallback, int)} */ 151 interface LinkProbeCallback extends WifiNl80211Manager.SendMgmtFrameCallback { 152 153 @Retention(RetentionPolicy.SOURCE) 154 @IntDef(prefix = {"LINK_PROBE_ERROR_"}, 155 value = {LINK_PROBE_ERROR_NOT_CONNECTED}) 156 @interface LinkProbeFailure {} 157 158 /** Attempted to send a link probe when not connected to Wifi. */ 159 // Note: this is a restriction in the Wifi framework since link probing is defined to be 160 // targeted at the currently connected AP. Driver/firmware has no problems with sending 161 // management frames to arbitrary APs whether connected or disconnected. 162 int LINK_PROBE_ERROR_NOT_CONNECTED = 1000; 163 164 /** 165 * Called when the link probe failed. 166 * @param reason The error code for the failure. One of 167 * {@link WifiNl80211Manager.SendMgmtFrameError} or {@link LinkProbeFailure}. 168 */ onFailure(int reason)169 void onFailure(int reason); 170 failureReasonToString(int reason)171 static String failureReasonToString(int reason) { 172 switch (reason) { 173 case WifiNl80211Manager.SEND_MGMT_FRAME_ERROR_UNKNOWN: 174 return "SEND_MGMT_FRAME_ERROR_UNKNOWN"; 175 case WifiNl80211Manager.SEND_MGMT_FRAME_ERROR_MCS_UNSUPPORTED: 176 return "SEND_MGMT_FRAME_ERROR_MCS_UNSUPPORTED"; 177 case WifiNl80211Manager.SEND_MGMT_FRAME_ERROR_NO_ACK: 178 return "SEND_MGMT_FRAME_ERROR_NO_ACK"; 179 case WifiNl80211Manager.SEND_MGMT_FRAME_ERROR_TIMEOUT: 180 return "SEND_MGMT_FRAME_ERROR_TIMEOUT"; 181 case WifiNl80211Manager.SEND_MGMT_FRAME_ERROR_ALREADY_STARTED: 182 return "SEND_MGMT_FRAME_ERROR_ALREADY_STARTED"; 183 case LINK_PROBE_ERROR_NOT_CONNECTED: 184 return "LINK_PROBE_ERROR_NOT_CONNECTED"; 185 default: 186 return "Unrecognized error"; 187 } 188 } 189 } 190 191 /** Send a link probe */ probeLink(LinkProbeCallback callback, int mcs)192 void probeLink(LinkProbeCallback callback, int mcs); 193 194 /** Send a {@link Message} to ClientModeImpl's StateMachine. */ sendMessageToClientModeImpl(Message msg)195 void sendMessageToClientModeImpl(Message msg); 196 197 /** Unique ID for this ClientMode instance, used for debugging. */ getId()198 long getId(); 199 200 /** 201 * Set MBO cellular data status 202 * @param available cellular data status, true means cellular data available, false otherwise. 203 */ setMboCellularDataStatus(boolean available)204 void setMboCellularDataStatus(boolean available); 205 206 /** 207 * Query the firmware roaming capabilities. 208 * @return Roaming Capabilities on success, null on failure. 209 */ 210 @Nullable getRoamingCapabilities()211 WifiNative.RoamingCapabilities getRoamingCapabilities(); 212 213 /** Set firmware roaming configurations. */ configureRoaming(WifiNative.RoamingConfig config)214 boolean configureRoaming(WifiNative.RoamingConfig config); 215 216 /** Enable/Disable firmware roaming. */ enableRoaming(boolean enabled)217 boolean enableRoaming(boolean enabled); 218 219 /** 220 * Set country code. 221 * 222 * @param countryCode 2 byte ASCII string. For ex: US, CA. 223 * @return true if request is sent successfully, false otherwise. 224 */ setCountryCode(String countryCode)225 boolean setCountryCode(String countryCode); 226 227 /** 228 * Fetch the most recent TX packet fates from the HAL. Fails unless HAL is started. 229 * @return TxFateReport list on success, empty list on failure. Never returns null. 230 */ 231 @NonNull getTxPktFates()232 List<TxFateReport> getTxPktFates(); 233 234 /** 235 * Fetch the most recent RX packet fates from the HAL. Fails unless HAL is started. 236 * @return RxFateReport list on success, empty list on failure. Never returns null. 237 */ 238 @NonNull getRxPktFates()239 List<RxFateReport> getRxPktFates(); 240 241 /** 242 * Get the Wiphy capabilities of a device for a given interface 243 * If the interface is not associated with one, 244 * it will be read from the device through wificond 245 * 246 * @return the device capabilities for this interface, or null if not available 247 */ 248 @Nullable getDeviceWiphyCapabilities()249 DeviceWiphyCapabilities getDeviceWiphyCapabilities(); 250 251 /** 252 * Initiate ANQP query. 253 * 254 * @param bssid BSSID of the AP to be queried 255 * @param anqpIds Set of anqp IDs. 256 * @param hs20Subtypes Set of HS20 subtypes. 257 * @return true on success, false otherwise. 258 */ requestAnqp(String bssid, Set<Integer> anqpIds, Set<Integer> hs20Subtypes)259 boolean requestAnqp(String bssid, Set<Integer> anqpIds, Set<Integer> hs20Subtypes); 260 261 /** 262 * Initiate Venue URL ANQP query. 263 * 264 * @param bssid BSSID of the AP to be queried 265 * @return true on success, false otherwise. 266 */ requestVenueUrlAnqp(String bssid)267 boolean requestVenueUrlAnqp(String bssid); 268 269 /** 270 * Request a passpoint icon file |filename| from the specified AP |bssid|. 271 * 272 * @param bssid BSSID of the AP 273 * @param fileName name of the icon file 274 * @return true if request is sent successfully, false otherwise 275 */ requestIcon(String bssid, String fileName)276 boolean requestIcon(String bssid, String fileName); 277 278 /** 279 * If set to true, the NetworkAgent score for connections established on this ClientModeManager 280 * will be artificially reduced so that ConnectivityService will prefer any other connection. 281 */ setShouldReduceNetworkScore(boolean shouldReduceNetworkScore)282 void setShouldReduceNetworkScore(boolean shouldReduceNetworkScore); 283 } 284