# nxp-imx/mwifiex architecture

> Architecture diagram of the GitHub repository nxp-imx/mwifiex, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nxp-imx/mwifiex
- Repository: https://github.com/nxp-imx/mwifiex

## Overview

Based on our analysis of the file tree and the extensive README, this project is a Wi-Fi driver (the MXM Wi-Fi Driver from NXP) that supports a wide range of wireless functionalities (STA, uAP, Wi-Fi Direct, NAN, etc.) and integrates deeply with the Linux kernel. The codebase is split into two primary directories:
- The “mlan” directory – containing the core driver source files with various functionalities (scanning, joining, command handling, aggregation, and data transmission) that directly interface with the wireless chipset.
- The “mlinux” directory – containing Linux-specific adaptations (such as cfg80211 and WEXT integration), initialization routines, and the OS-level glue (e.g., PCIe, SDIO, USB support) to enable communication between the driver and the Linux kernel.
The README further details build, installation, and runtime parameters, as well as debug and test interfaces via proc files.

a. Core Driver Module (mlan)
– Show sub-modules for various functionalities such as scanning (mlan_scan), joining (mlan_join), TX/RX (mlan_txrx), aggregation (mlan_11n_aggr), and other operational code (initialization, host commands, and event handling).
b. OS Integration Layer (mlinux)
– Represent components like “moal_cfg80211”, “moal_eth_ioctl”, “moal_init”, “moal_pcie”, “moal_usb”, and their corresponding Linux kernel interfaces.
c. Hardware Abstraction and Bus Interfaces
– Include separate sub-components for supporting different hardware interfaces (e.g., PCIe, SDIO, USB). These are implemented in both directories (for example, mlan_pcie.c in mlan and moal_pcie.c in mlinux) which manage the low-level communication.
d. Firmware & Configuration Management
– Represent the firmware loader, configuration file parsers (like wifi_mod_para.conf), and the mechanism that copies firmware into /lib/firmware/nxp/ as described in the README.
e. User Space/Debug/Proc Interface
– Include the proc interface for runtime control and debugging (commands for scanning, issuing commands, firmware reload, and RF test mode operations).

##### Interactions and Data Flow
a. Out how the OS integration layer (mlinux) communicates with the core driver (mlan) via shared header files and module interfaces.
– From the Linux Kernel Networking Stack (and user commands via ioctls/proc interface) to the mlinux layer.
– From mlinux to the lower-level mlan driver handling hardware-specific operations.
– From mlan to the wireless hardware (firmware) with bidirectional data/instruction flow.
– Also account for debug/diagnostic flows (e.g., the proc interface outputs as specified in the README).
c. How configuration settings (passed as module parameters when loading the driver) influence the data/control flow.

##### Architectural Patterns and Design Principles
a. Modularity: The clear separation between the hardware abstraction (mlan) and Linux-specific integration (mlinux) should be highlighted.
b. Layered Design: Demonstrate how the driver articulates a hardware-agnostic API (via mlan) that is adapted by the linux-specific “moal” modules.
c. Separation of Concerns: Different subcomponents (scanning, joining, TX/RX, debug, etc.) are isolated to allow easy maintenance and extensibility.
d. Use of Proc and IOCTL interfaces: Clearly denote the control interface that enables configuration, debugging, and testing.

##### Incorporate the Relevant Technologies and Frameworks
a. C language (the implementation is in C, as seen by .c and .h files).
b. Linux Kernel Integration:
– cfg80211 and WEXT frameworks are used from the mlinux side for wireless management.
c. Bus Interfaces (PCIE, SDIO, USB): Part of the hardware abstraction layer.
d. Module parameter configuration and runtime debugging via the proc filesystem.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry point
    U1["Linux Kernel/User Commands"]:::entry

    %% OS Integration (mlinux) subgraph
    subgraph "OS Integration (mlinux)"
        O1["CFG80211 (moal_cfg80211)"]:::os
        O2["CFG80211 Util (moal_cfg80211_util)"]:::os
        O3["Ethernet IOCTL (moal_eth_ioctl)"]:::os
        O4["OS Init (moal_init)"]:::os
        O5["OS Main (moal_main)"]:::os
        O6["USB Support (moal_usb)"]:::os
        O7["Shim (moal_shim)"]:::os
        O8["WEXT (moal_wext)"]:::os
        O9["IOCTL Error Codes (ioctl_error_codes)"]:::os
        O10["PCIe (moal_pcie)"]:::os
        O11["SDIO MMC (moal_sdio_mmc)"]:::os
        O12["SDIO (moal_sdio)"]:::os
        O13["Proc Interface (moal_proc)"]:::os
        O14["Debug (moal_debug)"]:::os
        O15["Diagnostic IOCTL (moal_ioctl)"]:::os
    end

    %% Core Driver (mlan) subgraph
    subgraph "Core Driver (mlan)"
        M1["Scanning (mlan_scan)"]:::core
        M2["Joining (mlan_join)"]:::core
        M3["TX/RX (mlan_txrx)"]:::core
        M4["Aggregation (mlan_11n_aggr)"]:::core
        M5["Initialization (mlan_init)"]:::core
        M6["Command/Event (mlan_cmdevt)"]:::core
        M7["STA Cmd (mlan_sta_cmd)"]:::core
        M8["uAP Cmd/Event (mlan_uap_cmdevent)"]:::core
        M9["PCIe (mlan_pcie)"]:::core
        M10["SDIO (mlan_sdio)"]:::core
        M11["USB (mlan_usb)"]:::core
    end

    %% Hardware Interfaces subgraph
    subgraph "Hardware Interfaces"
        H1["PCIe Interface"]:::hardware
        H2["SDIO Interface"]:::hardware
        H3["USB Interface"]:::hardware
    end

    %% Firmware & Configuration Management
    F1["Firmware & Config Loader"]:::firmware

    %% Data Flow Connections
    U1 -->|"ioctl_calls"| O3
    U1 -->|"proc_commands"| O13

    %% OS Integration to Core Driver interactions
    O4 -->|"init_call"| M5
    O15 -->|"cmd_handling"| M6
    O10 -->|"PCIe_transfer"| M9
    O11 -->|"SDIO_transfer"| M10
    O6  -->|"USB_transfer"| M11

    %% Core Driver Hardware Bridges
    M9 -->|"data/instructions"| H1
    O10 -->|"data/instructions"| H1

    M10 -->|"data/instructions"| H2
    O12 -->|"data/instructions"| H2

    M11 -->|"data/instructions"| H3
    O6  -->|"data/instructions"| H3

    %% Firmware interactions
    O4 -->|"fw_download_req"| F1
    M5 -->|"fw_load_req"| F1
    F1 -- "fw_loaded" --> M5

    %% Styles
    classDef entry fill:#F5B7B1,stroke:#922B21,stroke-width:2px,color:black;
    classDef os fill:#F9E79F,stroke:#B7950B,stroke-width:2px,color:black;
    classDef core fill:#AED6F1,stroke:#1B4F72,stroke-width:2px,color:black;
    classDef hardware fill:#A9DFBF,stroke:#117A65,stroke-width:2px,color:black;
    classDef firmware fill:#FAD7A0,stroke:#D68910,stroke-width:2px,color:black;

    %% Click Events for Core Driver (mlan)
    click M1 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlan/mlan_scan.c"
    click M2 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlan/mlan_join.c"
    click M3 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlan/mlan_txrx.c"
    click M4 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlan/mlan_11n_aggr.c"
    click M5 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlan/mlan_init.c"
    click M6 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlan/mlan_cmdevt.c"
    click M7 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlan/mlan_sta_cmd.c"
    click M8 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlan/mlan_uap_cmdevent.c"
    click M9 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlan/mlan_pcie.c"
    click M10 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlan/mlan_sdio.c"
    click M11 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlan/mlan_usb.c"

    %% Click Events for OS Integration (mlinux)
    click O1 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlinux/moal_cfg80211.c"
    click O2 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlinux/moal_cfg80211_util.c"
    click O3 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlinux/moal_eth_ioctl.c"
    click O4 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlinux/moal_init.c"
    click O5 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlinux/moal_main.c"
    click O6 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlinux/moal_usb.c"
    click O7 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlinux/moal_shim.c"
    click O8 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlinux/moal_wext.c"
    click O9 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlinux/ioctl_error_codes.h"
    click O10 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlinux/moal_pcie.c"
    click O11 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlinux/moal_sdio_mmc.c"
    click O12 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlinux/moal_sdio.h"
    click O13 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlinux/moal_proc.c"
    click O14 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlinux/moal_debug.c"
    click O15 "https://github.com/nxp-imx/mwifiex/blob/lf-6.12.3_1.0.0/mlinux/moal_ioctl.c"
```
