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