openwrt/mt76

repository·master·Indexed 21 days ago

https://github.com/openwrt/mt76

Drivers and utilities for MediaTek wireless chipsets, including support for MT7603, MT7615, MT76x0, and MT7915. Features the mt76-test utility for low-level Rx/Tx calibration, statistics dumping, and EEPROM data preparation. Provides implementations of the ieee80211_ops interface for Linux wireless subsystem (mac80211) management, including TSF timestamps, antenna configuration, AMPDU actions, and encryption key setup.

Tokens
13.4K
Snippets
44
Records
61
Agent score
74%

What's inside openwrt-mt76

  1. Use the MT76 testmode utility

    master

    The mt76-test utility is used for Rx/Tx calibration support functions, similar to the ATE command set of the SDK driver. It allows you to set test parameters, dump statistics, and prepare modified EEPROM data for flash writing.

    Prerequisites for running tests:

    1. Disable all normal interfaces.
    2. Set up a monitor mode interface.
    3. Configure the interface to the specific channel and bandwidth intended for testing.
    mt76-test phy0 set <parameter>=<value>
  2. How test states work in mt76-test

    master

    The state parameter controls the operational mode of the test utility. Setting a state activates it immediately, even if the value is identical to the current state.

    Supported state values:

    • off: Normal operation (default).
    • idle: Testmode is enabled, but no specific test is currently active.
    • tx_frames: Triggers the immediate sending of a specified number of packets with configurable rate and transmit power.
    • rx_frames: Enables receive mode to show RSSI and packet count/PER (Packet Error Rate). This mode can also be used to clear existing RX statistics.
    mt76-test phy0 set state=tx_frames
  3. Use the mt76 testmode utility CLI

    master

    The mt76 utility is a command-line tool used to interact with the MT76 driver's testmode features via the nl80211 interface. It allows users to set test parameters, dump test data/statistics, and manage EEPROM settings.

    Basic Syntax: mt76 <command> <phyX> <subcommand> [args...]

    Where <phyX> is the name of the wireless physical device (e.g., phy0).

    # Example: Set a test parameter
    mt76 set phy0 var1=val1 var2=val2
    
    # Example: Dump test data
    mt76 dump phy0
    
    # Example: Dump statistics
    mt76 dump phy0 stats
    
    # Example: EEPROM operations
    mt76 eeprom phy0 file my_eeprom.bin
  4. Reference mt76-test parameters

    master

    The following parameters can be configured using the set command. Some parameters map to specific ATE (Automatic Test Equipment) command names used in the SDK driver.

    | Parameter name | ATE parameter | Description |
    |--|--|--|
    | `state` | `ATE` | Test state |
    | `tx_count` | `ATETXCNT` | Number of packets to send |
    | `tx_length` | `ATETXLEN` | Length of packets to send |
    | `tx_rate_mode` | `ATETXMODE` | PHY mode (possible values: `cck`, `ofdm`, `ht`, `vht`) |
    | `tx_rate_nss` | | Number of spatial streams (VHT only) |
    | `tx_rate_idx` | `ATETXMCS` | MCS or legacy rate index |
    | `tx_rate_sgi` | `ATETXGI` | Enable short guard interval |
    | `tx_rate_ldpc` | `ATETXLDPC` | Enable LDPC |
    | `tx_power_control` | `ATETXPOWERCTRL` | Firmware transmit power control feature |
    | `tx_power` | `ATETXPOW0-3` | Per-chain half-dBm transmit power, `0` means default value, e.g. `10,0,0,0` |
    | `tx_antenna` | `ATETXANT` | Transmit antenna bitmask |
    | `freq_offset` | `ATETXFREQOFFSET` | Frequency offset |
  5. Basic syntax for mt76-test

    master

    The utility operates on a specific physical interface (e.g., phy0). Use the following command patterns:

    • Set a parameter: mt76-test <interface> set <parameter>=<value>
    • Show current parameter set: mt76-test <interface> dump
    • Show statistics: mt76-test <interface> dump stats
    mt76-test phy0 set state=idle
    mt76-test phy0 dump
    mt76-test phy0 dump stats
  6. Configure MT7996 RTS threshold

    master

    The set_rts_threshold function allows setting the Request-to-Send (RTS) threshold for the radios. This value determines the packet size threshold above which RTS/CTS frames are used to mitigate the hidden node problem.

    Parameters:

    • hw: The hardware pointer.
    • radio_idx: The radio index.
    • val: The threshold value.

    This function iterates through all available radios on the device and applies the threshold via mt7996_mcu_set_rts_thresh.

  7. Configure MT7996 hardware encryption keys

    master

    The function mt7996_set_hw_key is used to set or remove encryption keys for a specific link. It handles both standard keys and 'BIGTK' (Big Transient Key) scenarios.

    Key Management Logic:

    • Command Types: Uses enum set_key_cmd (e.g., SET_KEY) to determine if a key is being added or removed.
    • BIGTK Support: If the key index is 6 or 7, it is treated as a BIGTK, which may require additional flags like IEEE80211_KEY_FLAG_GENERATE_MMIE and specific hardware key index slots (hw_key_idx2).
    • Cipher Support: Certain ciphers (like WLAN_CIPHER_SUITE_AES_CMAC) are handled specifically for BIGTK. If a cipher is unsupported by hardware, the driver may fall back to software encryption.
    • Beacon Protection: When setting a BIGTK key, the driver may automatically re-add the beacon to enable beacon protection.
    /* Sets or removes hardware keys for a link */
    static int mt7996_set_hw_key(
        struct ieee80211_hw *hw, 
        enum set_key_cmd cmd, 
        struct ieee80211_vif *vif, 
        struct ieee80211_sta *sta, 
        unsigned int link_id, 
        struct ieee80211_key_conf *key
    );
  8. Configure hardware scanning and scheduled scanning

    master

    The driver supports both standard hardware scanning and scheduled scanning via the MCU.

    • Hardware Scan: mt7921_hw_scan initiates a scan request. Use mt7921_cancel_hw_scan to abort an ongoing scan.
    • Scheduled Scan: mt7921_start_sched_scan and mt7921_stop_sched_scan manage the enablement of scheduled scanning via the MCU.
    /* Hardware Scanning */
    int mt7921_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_scan_request *req);
    void mt7921_cancel_hw_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
    
    /* Scheduled Scanning */
    int mt7921_start_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct cfg80211_sched_scan_request *req, struct ieee80211_scan_ies *ies);
    int mt7921_stop_sched_scan(struct ieee80211_hw *hw, struct ieee80211_vif *vif);
  9. Synchronously abort ROC with mt7925_roc_abort_sync()

    master

    The mt7925_roc_abort_sync() function provides a way to synchronously abort a Rest of Channel (ROC) operation. It deletes the ROC timer, cancels pending ROC work, and iterates through all interfaces to abort the ROC for each one.

    void mt7925_roc_abort_sync(struct mt792x_dev *dev);
  10. Configure Antenna and Stream Capabilities

    master

    The driver supports configuring antenna masks and stream capabilities. This is used to define which antennas are active for transmission and reception, which is critical for MIMO operations. The function updates the hardware's antenna mask and recalculates stream capabilities (VHT/HE) based on the selected antennas.

    /* Set the antenna mask for TX and RX */
    static int mt7915_set_antenna(struct ieee80211_hw *hw, int radio_idx, u32 tx_ant, u32 rx_ant);
  11. Configure MT7915 Station (STA) parameters

    master

    The mt7915_ops structure defines several station-specific configuration methods that can be invoked via the cfg80211 interface:

    • sta_set_4addr: Enables or disables 4-address mode for a station.
    • sta_set_decap_offload: Enables or disables header decap offload.
    • sta_set_airtime_weight: Sets the airtime weight for a station (used in VOW/Airtime fairness).
    • sta_set_txpwr: Configures the transmission power for the station.
    • sta_set_bitrate_mask: Sets the allowed bitrates for the station.
    • sta_set_coverage_class: Sets the coverage class for the station.
  12. Configure antenna mask

    master

    Use mt7925_set_antenna to configure the transmit (tx_ant) and receive (rx_ant) antenna masks. The function validates that the requested antennas are available and that the bitmask is valid for the hardware's maximum number of spatial streams (NSS). It updates the hardware's antenna and chain masks and triggers updates for stream capabilities.

    /* Example usage within the driver context */
    static int
    mt7925_set_antenna(struct ieee80211_hw *hw, int radio_idx, 
    		   u32 tx_ant, u32 rx_ant)
    {
        // ... implementation details ...
    }