1 /* 2 * Copyright (C) 2022 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.hal; 18 19 import android.annotation.Nullable; 20 import android.hardware.wifi.WifiStatusCode; 21 import android.net.MacAddress; 22 import android.net.apf.ApfCapabilities; 23 import android.net.wifi.WifiManager.RoamingMode; 24 import android.net.wifi.WifiScanner; 25 import android.net.wifi.twt.TwtRequest; 26 import android.os.Bundle; 27 28 import com.android.server.wifi.WifiLinkLayerStats; 29 import com.android.server.wifi.WifiLoggerHal; 30 import com.android.server.wifi.WifiNative; 31 32 import java.util.List; 33 34 /** Abstraction of WifiStaIface */ 35 public interface IWifiStaIface { 36 /** 37 * Register for event callbacks. 38 * 39 * @param callback Instance of {@link WifiStaIface.Callback} 40 * @return true if successful, false otherwise. 41 */ registerFrameworkCallback(WifiStaIface.Callback callback)42 boolean registerFrameworkCallback(WifiStaIface.Callback callback); 43 44 /** 45 * Get the name of this interface. 46 * 47 * @return Name of this interface, or null on error. 48 */ 49 @Nullable getName()50 String getName(); 51 52 /** 53 * Configure roaming control parameters. 54 * 55 * @param bssidBlocklist List of BSSIDs that are blocklisted for roaming. 56 * @param ssidAllowlist List of SSIDs that are allowlisted for roaming. 57 * @return true if successful, false otherwise. 58 */ configureRoaming(List<MacAddress> bssidBlocklist, List<byte[]> ssidAllowlist)59 boolean configureRoaming(List<MacAddress> bssidBlocklist, List<byte[]> ssidAllowlist); 60 61 /** 62 * Enable link layer stats collection. 63 * 64 * Radio statistics (once started) must not stop until disabled. 65 * Iface statistics (once started) reset and start afresh after each 66 * connection until disabled. 67 * 68 * @param debug true to enable field debug mode, false to disable. Driver 69 * must collect all statistics regardless of performance impact. 70 * @return true if successful, false otherwise. 71 */ enableLinkLayerStatsCollection(boolean debug)72 boolean enableLinkLayerStatsCollection(boolean debug); 73 74 /** 75 * Enable/disable the neighbor discovery offload functionality in the firmware. 76 * 77 * @param enable true to enable, false to disable. 78 * @return true if successful, false otherwise. 79 */ enableNdOffload(boolean enable)80 boolean enableNdOffload(boolean enable); 81 82 /** 83 * Used to query additional information about the chip's APF capabilities. 84 * 85 * @return Instance of {@link ApfCapabilities}. 86 */ getApfPacketFilterCapabilities()87 ApfCapabilities getApfPacketFilterCapabilities(); 88 89 /** 90 * Used to query additional information about the chip's Background Scan capabilities. 91 * 92 * @return Instance of {@link WifiNative.ScanCapabilities}, or null on error. 93 */ 94 @Nullable getBackgroundScanCapabilities()95 WifiNative.ScanCapabilities getBackgroundScanCapabilities(); 96 97 /** 98 * Get the capabilities supported by this STA iface. 99 * 100 * @return Bitset of WifiManager.WIFI_FEATURE_* values. 101 */ getCapabilities()102 long getCapabilities(); 103 104 /** 105 * Retrieve the fates of inbound packets. 106 * Reports the inbound frames for the most recent association (space allowing). 107 * 108 * @return List of RxFateReports up to size {@link WifiLoggerHal#MAX_FATE_LOG_LEN}, 109 * or empty list on failure. 110 */ getDebugRxPacketFates()111 List<WifiNative.RxFateReport> getDebugRxPacketFates(); 112 113 /** 114 * Retrieve fates of outbound packets. 115 * Reports the outbound frames for the most recent association (space allowing). 116 * 117 * @return List of TxFateReports up to size {@link WifiLoggerHal#MAX_FATE_LOG_LEN}, 118 * or empty list on failure. 119 */ getDebugTxPacketFates()120 List<WifiNative.TxFateReport> getDebugTxPacketFates(); 121 122 /** 123 * Get the factory MAC address of the STA interface. 124 * 125 * @return Factory MAC address of the STA interface, or null on error. 126 */ 127 @Nullable getFactoryMacAddress()128 MacAddress getFactoryMacAddress(); 129 130 /** 131 * Retrieve the cached scan data. 132 * 133 * @return Instance of {@link ScanData}, or null on error. 134 */ 135 @Nullable getCachedScanData()136 WifiScanner.ScanData getCachedScanData(); 137 138 /** 139 * Retrieve the latest link layer stats. 140 * Note: will fail if link layer stats collection has not been explicitly enabled. 141 * 142 * @return Instance of {@link WifiLinkLayerStats}, or null on error. 143 */ 144 @Nullable getLinkLayerStats()145 WifiLinkLayerStats getLinkLayerStats(); 146 147 /** 148 * Get roaming control capabilities. 149 * 150 * @return Instance of {@link WifiNative.RoamingCapabilities}, or null on error. 151 */ 152 @Nullable getRoamingCapabilities()153 WifiNative.RoamingCapabilities getRoamingCapabilities(); 154 155 /** 156 * Install an APF program on this interface, replacing any existing program. 157 * 158 * @param program APF Program to be set. 159 * @return true if successful, false otherwise. 160 */ installApfPacketFilter(byte[] program)161 boolean installApfPacketFilter(byte[] program); 162 163 /** 164 * Read the APF program and data buffer on this interface. 165 * 166 * @return Buffer returned by the driver, or null if an error occurred. 167 */ 168 @Nullable readApfPacketFilterData()169 byte[] readApfPacketFilterData(); 170 171 /** 172 * Changes the MAC address of the interface to the given MAC address. 173 * 174 * @param mac MAC address to change to. 175 * @return true if successful, false otherwise. 176 */ setMacAddress(MacAddress mac)177 boolean setMacAddress(MacAddress mac); 178 179 /** 180 * Enable/disable firmware roaming. 181 * 182 * @param state State of the roaming control. 183 * @return SET_FIRMWARE_ROAMING_SUCCESS, SET_FIRMWARE_ROAMING_FAILURE, 184 * or SET_FIRMWARE_ROAMING_BUSY 185 */ setRoamingState(@ifiNative.RoamingEnableState int state)186 @WifiNative.RoamingEnableStatus int setRoamingState(@WifiNative.RoamingEnableState int state); 187 188 /** 189 * Enable/disable scan-only mode for this interface. 190 * 191 * @param enable True to enable scan only mode, false to disable. 192 * @return true if successful, false otherwise. 193 */ setScanMode(boolean enable)194 boolean setScanMode(boolean enable); 195 196 /** 197 * Starts a background scan. 198 * Note: any ongoing scan will be stopped first. 199 * 200 * @param cmdId Command ID to use for this invocation. 201 * @param params Background scan parameters. 202 * @return true if successful, false otherwise. 203 */ startBackgroundScan(int cmdId, WifiStaIface.StaBackgroundScanParameters params)204 boolean startBackgroundScan(int cmdId, WifiStaIface.StaBackgroundScanParameters params); 205 206 /** 207 * Start packet fate monitoring. Once started, monitoring remains active until 208 * the HAL is unloaded. 209 * 210 * @return true if successful, false otherwise. 211 */ startDebugPacketFateMonitoring()212 boolean startDebugPacketFateMonitoring(); 213 214 /** 215 * Start RSSI monitoring on the currently connected access point. 216 * 217 * @param cmdId Command ID to use for this invocation. 218 * @param maxRssi Maximum RSSI threshold. 219 * @param minRssi Minimum RSSI threshold. 220 * @return true if successful, false otherwise. 221 */ startRssiMonitoring(int cmdId, int maxRssi, int minRssi)222 boolean startRssiMonitoring(int cmdId, int maxRssi, int minRssi); 223 224 /** 225 * Start sending the specified keep-alive packets periodically. 226 * 227 * @param cmdId Command ID to use for this invocation. 228 * @param ipPacketData IP packet contents to be transmitted. 229 * @param etherType Ether type to be set in the ethernet frame transmitted. 230 * @param srcAddress Source MAC address of the packet. 231 * @param dstAddress Destination MAC address of the packet. 232 * @param periodInMs Interval at which this packet must be transmitted. 233 * @return true if successful, false otherwise. 234 */ startSendingKeepAlivePackets(int cmdId, byte[] ipPacketData, int etherType, MacAddress srcAddress, MacAddress dstAddress, int periodInMs)235 boolean startSendingKeepAlivePackets(int cmdId, byte[] ipPacketData, int etherType, 236 MacAddress srcAddress, MacAddress dstAddress, int periodInMs); 237 238 /** 239 * Stop the current background scan. 240 * 241 * @param cmdId Command ID corresponding to the request. 242 * @return true if successful, false otherwise. 243 */ stopBackgroundScan(int cmdId)244 boolean stopBackgroundScan(int cmdId); 245 246 /** 247 * Stop RSSI monitoring. 248 * 249 * @param cmdId Command ID corresponding to the request. 250 * @return true if successful, false otherwise. 251 */ stopRssiMonitoring(int cmdId)252 boolean stopRssiMonitoring(int cmdId); 253 254 /** 255 * Stop sending the specified keep-alive packets. 256 * 257 * @param cmdId Command ID corresponding to the request. 258 * @return true if successful, false otherwise. 259 */ stopSendingKeepAlivePackets(int cmdId)260 boolean stopSendingKeepAlivePackets(int cmdId); 261 262 /** 263 * Set maximum acceptable DTIM multiplier to hardware driver. Any multiplier larger than the 264 * maximum value must not be accepted, it will cause packet loss higher than what the system 265 * can accept, which will cause unexpected behavior for apps, and may interrupt the network 266 * connection. 267 * 268 * @param multiplier maximum DTIM multiplier value to set. 269 * @return true if successful, false otherwise. 270 */ setDtimMultiplier(int multiplier)271 boolean setDtimMultiplier(int multiplier); 272 273 /** 274 * Set the roaming mode. 275 * 276 * @param roamingMode {@link android.net.wifi.WifiManager.RoamingMode}. 277 * @return {@link WifiStatusCode#SUCCESS} if success, otherwise error code. 278 */ setRoamingMode(@oamingMode int roamingMode)279 @WifiStatusCode int setRoamingMode(@RoamingMode int roamingMode); 280 281 /** 282 * Get target wake time (TWT) capabilities. 283 * 284 * @return TWT capabilities as Bundle 285 */ getTwtCapabilities()286 default Bundle getTwtCapabilities() { 287 return null; 288 } 289 290 /** 291 * Set up a TWT session 292 * 293 * @param cmdId Command ID to use for this invocation. 294 * @param twtRequest TWT request configuration to setup TWT session 295 * @return true if successful, false otherwise. 296 */ setupTwtSession(int cmdId, TwtRequest twtRequest)297 default boolean setupTwtSession(int cmdId, TwtRequest twtRequest) { 298 return false; 299 } 300 301 /** 302 * Teardown a TWT session. 303 * 304 * @param cmdId Command ID to use for this invocation. 305 * @param sessionId TWT session identifier 306 * @return true if successful, false otherwise. 307 */ tearDownTwtSession(int cmdId, int sessionId)308 default boolean tearDownTwtSession(int cmdId, int sessionId) { 309 return false; 310 } 311 312 /** 313 * Get stats for the TWT session. 314 * 315 * @param cmdId Command ID to use for this invocation. 316 * @param sessionId TWT session identifier 317 * @return true if successful, false otherwise. 318 */ getStatsTwtSession(int cmdId, int sessionId)319 default boolean getStatsTwtSession(int cmdId, int sessionId) { 320 return false; 321 } 322 } 323