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.NonNull; 20 import android.annotation.Nullable; 21 import android.hardware.wifi.WifiStatusCode; 22 import android.net.wifi.CoexUnsafeChannel; 23 import android.net.wifi.OuiKeyedData; 24 import android.net.wifi.WifiAvailableChannel; 25 import android.net.wifi.WifiManager; 26 import android.net.wifi.WifiScanner; 27 28 import com.android.server.wifi.SarInfo; 29 import com.android.server.wifi.WifiNative; 30 import com.android.server.wifi.WlanWakeReasonAndCounts; 31 32 import java.util.List; 33 34 /** Abstraction of WifiChip */ 35 public interface IWifiChip { 36 /** 37 * Configure the chip. 38 * 39 * @param modeId Mode that the chip must switch to, corresponding to the 40 * id property of the target ChipMode. 41 * @return true if successful, false otherwise. 42 */ configureChip(int modeId)43 boolean configureChip(int modeId); 44 45 /** 46 * Create an AP interface on the chip. 47 * 48 * @param vendorData List of {@link OuiKeyedData} containing vendor-provided 49 * configuration data. Empty list indicates no vendor data. 50 * @return {@link WifiApIface} object, or null if a failure occurred. 51 */ 52 @Nullable createApIface(@onNull List<OuiKeyedData> vendorData)53 WifiApIface createApIface(@NonNull List<OuiKeyedData> vendorData); 54 55 /** 56 * Create a bridged AP interface on the chip. 57 * 58 * @param vendorData List of {@link OuiKeyedData} containing vendor-provided 59 * configuration data. Empty list indicates no vendor data. 60 * @return {@link WifiApIface} object, or null if a failure occurred. 61 */ 62 @Nullable createBridgedApIface(@onNull List<OuiKeyedData> vendorData)63 WifiApIface createBridgedApIface(@NonNull List<OuiKeyedData> vendorData); 64 65 /** 66 * Create a NAN interface on the chip. 67 * 68 * @return {@link WifiNanIface} object, or null if a failure occurred. 69 */ 70 @Nullable createNanIface()71 WifiNanIface createNanIface(); 72 73 /** 74 * Create a P2P interface on the chip. 75 * 76 * @return {@link WifiP2pIface} object, or null if a failure occurred. 77 */ 78 @Nullable createP2pIface()79 WifiP2pIface createP2pIface(); 80 81 /** 82 * Create an RTTController instance. Implementation will decide the iface to use for 83 * RTT operations. 84 * 85 * @return {@link WifiRttController} object, or null if a failure occurred. 86 */ 87 @Nullable createRttController()88 WifiRttController createRttController(); 89 90 /** 91 * Create a STA iface on the chip. 92 * 93 * @return {@link WifiStaIface} object, or null if a failure occurred. 94 */ 95 @Nullable createStaIface()96 WifiStaIface createStaIface(); 97 98 /** 99 * Enable/disable alert notifications from the chip. 100 * 101 * @param enable true to enable, false to disable. 102 * @return true if successful, false otherwise. 103 */ enableDebugErrorAlerts(boolean enable)104 boolean enableDebugErrorAlerts(boolean enable); 105 106 /** 107 * Flush debug ring buffer data to files. 108 * 109 * @return true if successful, false otherwise. 110 */ flushRingBufferToFile()111 boolean flushRingBufferToFile(); 112 113 /** 114 * Force dump data into the corresponding ring buffer. 115 * 116 * @param ringName Name of the ring for which data collection should be forced. 117 * @return true if successful, false otherwise. 118 */ forceDumpToDebugRingBuffer(String ringName)119 boolean forceDumpToDebugRingBuffer(String ringName); 120 121 /** 122 * Get the AP interface corresponding to the provided ifaceName. 123 * 124 * @param ifaceName Name of the interface. 125 * @return {@link WifiApIface} if the interface exists, null otherwise. 126 */ 127 @Nullable getApIface(String ifaceName)128 WifiApIface getApIface(String ifaceName); 129 130 /** 131 * List all the AP iface names configured on the chip. 132 * The corresponding |WifiApIface| object for any iface 133 * can be retrieved using the |getApIface| method. 134 * 135 * @return List of all AP interface names on the chip, or null if an error occurred. 136 */ 137 @Nullable getApIfaceNames()138 List<String> getApIfaceNames(); 139 140 /** 141 * Get the set of operation modes that the chip supports. 142 * 143 * @return List of modes supported by the device, or null if an error occurred. 144 */ 145 @Nullable getAvailableModes()146 List<WifiChip.ChipMode> getAvailableModes(); 147 148 /** 149 * Get the capabilities supported by this chip. 150 * Call if no interfaces have been created on this chip. 151 * 152 * Note: This method can still be called safely after ifaces have been created, 153 * but it is recommended to use {@link #getCapabilitiesAfterIfacesExist()} once 154 * any ifaces are up. 155 * 156 * @return {@link WifiChip.Response} where the value is a bitset of 157 * WifiManager.WIFI_FEATURE_* values. 158 */ getCapabilitiesBeforeIfacesExist()159 WifiChip.Response<Long> getCapabilitiesBeforeIfacesExist(); 160 161 /** 162 * Get the capabilities supported by this chip. 163 * Call if interfaces have been created on this chip. 164 * 165 * @return {@link WifiChip.Response} where the value is a bitset of 166 * WifiManager.WIFI_FEATURE_* values. 167 */ getCapabilitiesAfterIfacesExist()168 WifiChip.Response<Long> getCapabilitiesAfterIfacesExist(); 169 170 /** 171 * Retrieve the Wi-Fi wakeup reason stats for debugging. 172 * 173 * @return {@link WlanWakeReasonAndCounts} object, or null if an error occurred. 174 */ 175 @Nullable getDebugHostWakeReasonStats()176 WlanWakeReasonAndCounts getDebugHostWakeReasonStats(); 177 178 /** 179 * Get the status of all ring buffers supported by driver. 180 * 181 * @return List of {@link WifiNative.RingBufferStatus} corresponding to the 182 * status of each ring buffer on the device, or null if an error occurred. 183 */ 184 @Nullable getDebugRingBuffersStatus()185 List<WifiNative.RingBufferStatus> getDebugRingBuffersStatus(); 186 187 /** 188 * Get the ID assigned to this chip. 189 * 190 * @return Chip ID, or -1 if an error occurred. 191 */ getId()192 int getId(); 193 194 /** 195 * Get the current mode that the chip is in. 196 * 197 * @return {@link WifiChip.Response} where the value is the mode that the chip 198 * is currently configured to. 199 */ getMode()200 WifiChip.Response<Integer> getMode(); 201 202 /** 203 * Get the NAN interface corresponding to the provided ifaceName. 204 * 205 * @param ifaceName Name of the interface. 206 * @return {@link WifiNanIface} if the interface exists, null otherwise. 207 */ 208 @Nullable getNanIface(String ifaceName)209 WifiNanIface getNanIface(String ifaceName); 210 211 /** 212 * List all the NAN iface names configured on the chip. 213 * The corresponding |WifiNanIface| object for any iface 214 * can be retrieved using the |getNanIface| method. 215 * 216 * @return List of all NAN interface names on the chip, or null if an error occurred. 217 */ 218 @Nullable getNanIfaceNames()219 List<String> getNanIfaceNames(); 220 221 /** 222 * Get the P2P interface corresponding to the provided ifaceName. 223 * 224 * @param ifaceName Name of the interface. 225 * @return {@link WifiP2pIface} if the interface exists, null otherwise. 226 */ 227 @Nullable getP2pIface(String ifaceName)228 WifiP2pIface getP2pIface(String ifaceName); 229 230 /** 231 * List all the P2P iface names configured on the chip. 232 * The corresponding |WifiP2pIface| object for any iface 233 * can be retrieved using the |getP2pIface| method. 234 * 235 * @return List of all P2P interface names on the chip, or null if an error occurred. 236 */ 237 @Nullable getP2pIfaceNames()238 List<String> getP2pIfaceNames(); 239 240 /** 241 * Get the STA interface corresponding to the provided ifaceName. 242 * 243 * @param ifaceName Name of the interface. 244 * @return {@link WifiStaIface} if the interface exists, null otherwise. 245 */ 246 @Nullable getStaIface(String ifaceName)247 WifiStaIface getStaIface(String ifaceName); 248 249 /** 250 * List all the STA iface names configured on the chip. 251 * The corresponding |WifiStaIface| object for any iface 252 * can be retrieved using the |getStaIface| method. 253 * 254 * @return List of all P2P interface names on the chip, or null if an error occurred. 255 */ 256 @Nullable getStaIfaceNames()257 List<String> getStaIfaceNames(); 258 259 /** 260 * Retrieve the list of all the possible radio combinations supported by this chip. 261 * 262 * @return List of all possible radio combinations, or null if an error occurred. 263 */ 264 @Nullable getSupportedRadioCombinations()265 List<WifiChip.WifiRadioCombination> getSupportedRadioCombinations(); 266 267 /** 268 * Retrieve the chip capabilities. 269 * 270 * @return |WifiChipCapabilities| representation of wifi chip capabilities or null if 271 * an error occurred or not available. 272 */ getWifiChipCapabilities()273 WifiChip.WifiChipCapabilities getWifiChipCapabilities(); 274 275 /** 276 * Retrieve a list of usable Wifi channels for the specified band and operational modes. 277 * 278 * @param band Band for which the list of usable channels is requested. 279 * @param mode Bitmask of modes that the caller is interested in. 280 * @param filter Bitmask of filters. Specifies whether driver should filter 281 * channels based on additional criteria. If no filter is specified, 282 * then the driver should return usable channels purely based on 283 * regulatory constraints. 284 * @return List of channels represented by {@link WifiAvailableChannel}, 285 * or null if an error occurred. 286 */ 287 @Nullable getUsableChannels(@ifiScanner.WifiBand int band, @WifiAvailableChannel.OpMode int mode, @WifiAvailableChannel.Filter int filter)288 List<WifiAvailableChannel> getUsableChannels(@WifiScanner.WifiBand int band, 289 @WifiAvailableChannel.OpMode int mode, @WifiAvailableChannel.Filter int filter); 290 291 /** 292 * Register for chip event callbacks. 293 * 294 * @param callback Instance of {@link WifiChip.Callback} 295 * @return true if successful, false otherwise. 296 */ registerCallback(WifiChip.Callback callback)297 boolean registerCallback(WifiChip.Callback callback); 298 299 /** 300 * Removes the AP interface with the provided ifaceName. 301 * 302 * @param ifaceName Name of the iface. 303 * @return true if successful, false otherwise. 304 */ removeApIface(String ifaceName)305 boolean removeApIface(String ifaceName); 306 307 /** 308 * Removes an instance of AP iface with name |ifaceName| from the 309 * bridged AP with name |brIfaceName|. 310 * 311 * Note: Use {@link #removeApIface(String)} with the |brIfaceName| to remove the bridged iface. 312 * 313 * @param brIfaceName Name of the bridged AP iface. 314 * @param ifaceName Name of the AP instance. 315 * @return true if successful, false otherwise. 316 */ removeIfaceInstanceFromBridgedApIface(String brIfaceName, String ifaceName)317 boolean removeIfaceInstanceFromBridgedApIface(String brIfaceName, String ifaceName); 318 319 /** 320 * Removes the NAN interface with the provided ifaceName. 321 * 322 * @param ifaceName Name of the iface. 323 * @return true if successful, false otherwise. 324 */ removeNanIface(String ifaceName)325 boolean removeNanIface(String ifaceName); 326 327 /** 328 * Removes the P2P interface with the provided ifaceName. 329 * 330 * @param ifaceName Name of the iface. 331 * @return true if successful, false otherwise. 332 */ removeP2pIface(String ifaceName)333 boolean removeP2pIface(String ifaceName); 334 335 /** 336 * Removes the STA interface with the provided ifaceName. 337 * 338 * @param ifaceName Name of the iface. 339 * @return true if successful, false otherwise. 340 */ removeStaIface(String ifaceName)341 boolean removeStaIface(String ifaceName); 342 343 /** 344 * Request information about the chip. 345 * 346 * @return Instance of {@link WifiChip.ChipDebugInfo}, or null if an error occurred. 347 */ 348 @Nullable requestChipDebugInfo()349 WifiChip.ChipDebugInfo requestChipDebugInfo(); 350 351 /** 352 * Request vendor debug info from the driver. 353 * 354 * @return Byte array retrieved from the driver, or null if an error occurred. 355 */ 356 @Nullable requestDriverDebugDump()357 byte[] requestDriverDebugDump(); 358 359 /** 360 * Request vendor debug info from the firmware. 361 * 362 * @return Byte array retrieved from the firmware, or null if an error occurred. 363 */ 364 @Nullable requestFirmwareDebugDump()365 byte[] requestFirmwareDebugDump(); 366 367 /** 368 * Select one of the preset TX power scenarios. 369 * 370 * @param sarInfo SarInfo to select the proper scenario. 371 * @return true if successful, false otherwise. 372 */ selectTxPowerScenario(SarInfo sarInfo)373 boolean selectTxPowerScenario(SarInfo sarInfo); 374 375 /** 376 * Set the current coex unsafe channels to avoid and their restrictions. 377 * 378 * @param unsafeChannels List of {@link CoexUnsafeChannel} to avoid. 379 * @param restrictions int containing a bitwise-OR combination of 380 * {@link android.net.wifi.WifiManager.CoexRestriction}. 381 * @return true if successful, false otherwise. 382 */ setCoexUnsafeChannels(List<CoexUnsafeChannel> unsafeChannels, int restrictions)383 boolean setCoexUnsafeChannels(List<CoexUnsafeChannel> unsafeChannels, int restrictions); 384 385 /** 386 * Set the country code for this Wifi chip. 387 * 388 * @param code 2-byte country code to set (as defined in ISO 3166). 389 * @return true if successful, false otherwise. 390 */ setCountryCode(byte[] code)391 boolean setCountryCode(byte[] code); 392 393 /** 394 * Enable/disable low-latency mode. 395 * 396 * @param enable true to enable, false to disable. 397 * @return true if successful, false otherwise. 398 */ setLowLatencyMode(boolean enable)399 boolean setLowLatencyMode(boolean enable); 400 401 /** 402 * Set primary connection when multiple STA ifaces are active. 403 * 404 * @param ifaceName Name of the interface. 405 * @return true if successful, false otherwise. 406 */ setMultiStaPrimaryConnection(String ifaceName)407 boolean setMultiStaPrimaryConnection(String ifaceName); 408 409 /** 410 * Set use-case when multiple STA ifaces are active. 411 * 412 * @param useCase use case from {@link WifiNative.MultiStaUseCase}. 413 * @return true if successful, false otherwise. 414 */ setMultiStaUseCase(@ifiNative.MultiStaUseCase int useCase)415 boolean setMultiStaUseCase(@WifiNative.MultiStaUseCase int useCase); 416 417 /** 418 * Control debug data collection. 419 * 420 * @param ringName Name of the ring for which data collection is to start. 421 * @param verboseLevel 0 to 3, inclusive. 0 stops logging. 422 * @param maxIntervalInSec Maximum interval between reports; ignore if 0. 423 * @param minDataSizeInBytes Minimum data size in buffer for report; ignore if 0. 424 * @return true if successful, false otherwise. 425 */ startLoggingToDebugRingBuffer(String ringName, int verboseLevel, int maxIntervalInSec, int minDataSizeInBytes)426 boolean startLoggingToDebugRingBuffer(String ringName, int verboseLevel, int maxIntervalInSec, 427 int minDataSizeInBytes); 428 429 /** 430 * Stop the debug data collection for all ring buffers. 431 * 432 * @return true if successful, false otherwise. 433 */ stopLoggingToDebugRingBuffer()434 boolean stopLoggingToDebugRingBuffer(); 435 436 /** 437 * Trigger subsystem restart. 438 * 439 * Use if the framework detects a problem (e.g. connection failure), 440 * in order to attempt recovery. 441 * 442 * @return true if successful, false otherwise. 443 */ triggerSubsystemRestart()444 boolean triggerSubsystemRestart(); 445 446 /** 447 * Set MLO mode for the chip. See {@link WifiManager#setMloMode(int, Executor, Consumer)} and 448 * {@link android.net.wifi.WifiManager.MloMode}. 449 * 450 * @param mode MLO mode {@link android.net.wifi.WifiManager.MloMode} 451 * @return {@code true} if success, otherwise false. 452 */ setMloMode(@ifiManager.MloMode int mode)453 @WifiStatusCode int setMloMode(@WifiManager.MloMode int mode); 454 455 /** 456 * Enable/disable the feature of allowing current STA-connected channel for WFA GO, SAP and 457 * Aware when the regulatory allows. 458 * 459 * @param enableIndoorChannel enable or disable indoor channel. 460 * @param enableDfsChannel enable or disable DFS channel. 461 * @return true if successful, false otherwise. 462 */ enableStaChannelForPeerNetwork(boolean enableIndoorChannel, boolean enableDfsChannel)463 boolean enableStaChannelForPeerNetwork(boolean enableIndoorChannel, boolean enableDfsChannel); 464 465 /** 466 * Sends the AFC allowed channels and frequencies to the driver. 467 * 468 * @param afcChannelAllowance the allowed frequencies and channels received from 469 * querying the AFC server. 470 * @return whether the channel allowance was set successfully. 471 */ setAfcChannelAllowance(WifiChip.AfcChannelAllowance afcChannelAllowance)472 boolean setAfcChannelAllowance(WifiChip.AfcChannelAllowance afcChannelAllowance); 473 474 /** 475 * Sets the wifi VoIP mode. 476 * 477 * @param mode Voip mode as defined by the enum |WifiVoipMode| 478 * @return true if successful, false otherwise. 479 */ setVoipMode(@ifiChip.WifiVoipMode int mode)480 default boolean setVoipMode(@WifiChip.WifiVoipMode int mode) { 481 return false; 482 } 483 } 484