# aosp/wpa_supplicant_8 architecture

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

- Interactive diagram: https://gitdiagram.com/aosp/wpa_supplicant_8
- Repository: https://github.com/aosp/wpa_supplicant_8

## Overview

##### Project type and purpose
- This is a system-level, C-language suite providing Wi-Fi authentication services:
– hostapd: Access Point (AP) daemon implementing WPA/WPA2/WPS/HS2.0/P2P on the AP side
– wpa_supplicant: Client/Supplicant daemon implementing WPA/WPA2/WPS/HS2.0/P2P on the station side
- It is not a web app or microservices system but a monolithic, plugin-based networking daemon with a rich internal architecture.

##### File structure
- Top-level directories:
– hostapd/ and wpa_supplicant/: each contains the build configuration, main.c, control interfaces, protocol handlers, example configs and scripts
– src/: common code shared by both daemons, organized into subdirectories for ap (hostapd core), common, crypto, drivers, eap_common, eap_peer, eap_server, p2p, utils, tls, wps, radius, etc.
– hs20/: Hotspot 2.0 specific client/server examples and CA tools
- Patterns:
– Modular plugins for EAP methods, TLS back-ends, drivers, P2P, WPS
– Clear layering: core daemon ← protocol stacks (EAP, IEEE802.11) ← crypto & TLS libs ← OS driver interface ← kernel/firmware
– Control interfaces: Unix sockets, named pipes, UDP, Windows named pipes, DBus

##### Key insights from README
- Two separate build targets (hostapd and wpa_supplicant) sharing the same codebase via src/
- Build by entering the respective subdirectory, generating .config, then make
- BSD licensing, contributions guidelines

##### Main components
– hostapd daemon process
- ap core (src/ap/)
- IEEE802.11 authentication/state machines
- EAP-server modules (src/eap_server/)
- RADIUS client (src/radius/)
- WPS/P2P handling (src/wps/, src/p2p/)
- Control interface (hostapd/ctrl_iface.c, DBus, CLI)
- Driver abstraction layer (src/drivers/) → kernel via nl80211/hostap/…
– wpa_supplicant daemon process
- supplicant core (wpa_supplicant/*.c)
- EAP-peer modules (src/eap_peer/)
- IEEE802.11 state machines and WPA authenticator stub
- WPS/P2P handling
- Control interface (wpa_cli, DBus)
- Driver abstraction layer (src/drivers/)
– Shared libraries/layers
- Crypto/TLS (src/crypto/, src/tls/) – AES, SHA, RSA, PKCS#…
- Common helpers (src/common/, src/utils/) – state machine, event loop, logging, base64, XML, HTTP utils
– External services
- RADIUS Authentication/Accounting servers
- Certificate Authority (for HS2.0 EST)
- GUI/CLI front-ends (wpa_cli, wpa_gui, hostapd_cli)
- DBus clients (network managers)

##### Relationships and data flows
- Driver calls ←→ daemon core (Rx/Tx packets, ioctl/NETLINK)
- Daemon core ←→ Crypto/TLS library (EAP-TLS handshakes)
- Daemon core ←→ EAP modules ←→ RADIUS client/server over UDP
- Control interface ←→ daemon core (configuration reload, status queries)
- GUI/CLI/DBus ←→ control interface ←→ daemon core
- HS2.0 CA tools ←→ server-side components via HTTPS/EST

##### Architectural patterns and principles
- Layered modular architecture: keep protocol logic, crypto, drivers separate
- Plugin pattern: EAP, TLS, driver back-ends built/loaded as modules
- Event-driven core (eloop) for non-blocking I/O
- Abstraction of platform differences (Linux/Windows/Android/FreeBSD) via os_*.c and l2_packet

## Diagram (Mermaid)

```mermaid
graph TB
    %% Hostapd Process
    subgraph "hostapd Process"
        direction TB
        HA_DAEMON["hostapd daemon"]:::daemon
        HA_CTRL["Control Interface\n(hostapd/ctrl_iface.c)"]:::module
        HA_DRIVER["Driver Abstraction\n(src/drivers/)"]:::module
        HA_AP_CORE["AP Core\n(src/ap/)"]:::module
        HA_EAP_SRV["EAP-Server Modules\n(src/eap_server/)"]:::module
        HA_RADIUS["RADIUS Client\n(src/radius/)"]:::module
        HA_WPS["WPS Handling\n(src/wps/)"]:::module
        HA_P2P["P2P Handling\n(src/p2p/)"]:::module
    end

    click HA_DAEMON "https://github.com/aosp/wpa_supplicant_8/blob/master/hostapd/main.c"
    click HA_CTRL "https://github.com/aosp/wpa_supplicant_8/blob/master/hostapd/ctrl_iface.c"
    click HA_DRIVER "https://github.com/aosp/wpa_supplicant_8/tree/master/src/drivers/"
    click HA_AP_CORE "https://github.com/aosp/wpa_supplicant_8/tree/master/src/ap/"
    click HA_EAP_SRV "https://github.com/aosp/wpa_supplicant_8/tree/master/src/eap_server/"
    click HA_RADIUS "https://github.com/aosp/wpa_supplicant_8/tree/master/src/radius/"
    click HA_WPS "https://github.com/aosp/wpa_supplicant_8/tree/master/src/wps/"
    click HA_P2P "https://github.com/aosp/wpa_supplicant_8/tree/master/src/p2p/"

    %% Shared Libraries
    subgraph "Shared Libraries" 
        direction TB
        SH_CRYPTO["Crypto Library\n(src/crypto/)"]:::module
        SH_TLS["TLS Library\n(src/tls/)"]:::module
        SH_COMMON["Common Helpers\n(src/common/)"]:::module
        SH_UTILS["Utilities\n(src/utils/)"]:::module
        SH_L2["L2 Packet Interface\n(src/l2_packet/)"]:::module
    end

    click SH_CRYPTO "https://github.com/aosp/wpa_supplicant_8/tree/master/src/crypto/"
    click SH_TLS "https://github.com/aosp/wpa_supplicant_8/tree/master/src/tls/"
    click SH_COMMON "https://github.com/aosp/wpa_supplicant_8/tree/master/src/common/"
    click SH_UTILS "https://github.com/aosp/wpa_supplicant_8/tree/master/src/utils/"
    click SH_L2 "https://github.com/aosp/wpa_supplicant_8/tree/master/src/l2_packet/"

    %% Wpa_supplicant Process
    subgraph "wpa_supplicant Process"
        direction TB
        WP_DAEMON["wpa_supplicant daemon"]:::daemon
        WP_CTRL["Control Interface\n(wpa_supplicant/ctrl_iface.c)"]:::module
        WP_DBUS["DBus Interface\n(wpa_supplicant/dbus/)"]:::module
        WP_DRIVER["Driver Abstraction\n(src/drivers/)"]:::module
        WP_SUP_CORE["Supplicant Core\n(wpa_supplicant/*.c)"]:::module
        WP_EAP_PEER["EAP-Peer Modules\n(src/eap_peer/)"]:::module
        WP_IEEE11["IEEE802.11 & RSN\n(src/rsn_supp/, src/common/ieee802_11_common.c)"]:::module
        WP_WPS["WPS Handling\n(src/wps/)"]:::module
        WP_P2P["P2P Handling\n(src/p2p/)"]:::module
    end

    click WP_DAEMON "https://github.com/aosp/wpa_supplicant_8/blob/master/wpa_supplicant/main.c"
    click WP_DAEMON "https://github.com/aosp/wpa_supplicant_8/blob/master/wpa_supplicant/wpa_supplicant.c"
    click WP_CTRL "https://github.com/aosp/wpa_supplicant_8/blob/master/wpa_supplicant/ctrl_iface.c"
    click WP_DBUS "https://github.com/aosp/wpa_supplicant_8/tree/master/wpa_supplicant/dbus/"
    click WP_DRIVER "https://github.com/aosp/wpa_supplicant_8/tree/master/src/drivers/"
    click WP_SUP_CORE "https://github.com/aosp/wpa_supplicant_8/tree/master/wpa_supplicant/"
    click WP_EAP_PEER "https://github.com/aosp/wpa_supplicant_8/tree/master/src/eap_peer/"
    click WP_WPS "https://github.com/aosp/wpa_supplicant_8/tree/master/src/wps/"
    click WP_P2P "https://github.com/aosp/wpa_supplicant_8/tree/master/src/p2p/"

    %% External Systems
    RADIUS_SRV(["RADIUS Server"]):::external
    CA_SERVER(["Certificate Authority\n(HS2.0 EST)"]):::external
    CLIENT_GUI(["GUI/CLI/DBus Clients"]):::external
    NET_IF(["Network Interface\n(nl80211/kernel)"]):::external

    %% Flows Hostapd
    NET_IF -->|"Rx/Tx packets"| HA_DRIVER
    HA_DRIVER -->|"ioctl/NETLINK"| HA_AP_CORE
    HA_AP_CORE -->|"auth/state machine"| HA_EAP_SRV
    HA_EAP_SRV -->|"EAP-TLS over UDP"| SH_CRYPTO
    SH_CRYPTO --> SH_TLS
    HA_EAP_SRV -->|"EAP over UDP"| HA_RADIUS
    HA_RADIUS -->|"RADIUS Auth/Acct"| RADIUS_SRV
    CLIENT_GUI -->|"CLI/Unix Socket\nDBus"| HA_CTRL
    HA_CTRL -->|"config/status"| HA_DAEMON
    HA_DAEMON --> HA_AP_CORE
    HA_AP_CORE --> HA_WPS
    HA_AP_CORE --> HA_P2P

    %% Flows Shared
    HA_DAEMON --> SH_COMMON
    WP_DAEMON --> SH_COMMON
    HA_DAEMON --> SH_UTILS
    WP_DAEMON --> SH_UTILS

    %% Flows wpa_supplicant
    NET_IF -->|"Rx/Tx packets"| WP_DRIVER
    WP_DRIVER -->|"ioctl/NETLINK"| WP_SUP_CORE
    WP_SUP_CORE -->|"state machine"| WP_EAP_PEER
    WP_EAP_PEER -->|"EAP-TLS over UDP"| SH_CRYPTO
    SH_CRYPTO --> SH_TLS
    WP_EAP_PEER -->|"EAP over UDP"| RADIUS_SRV
    CLIENT_GUI -->|"CLI/Unix Socket\nDBus"| WP_CTRL
    CLIENT_GUI -->|"DBus"| WP_DBUS
    WP_CTRL -->|"config/status"| WP_DAEMON
    WP_DAEMON --> WP_SUP_CORE
    WP_SUP_CORE --> WP_WPS
    WP_SUP_CORE --> WP_P2P

    %% External CA
    CA_SERVER -->|"HTTPS/EST"| HA_DAEMON
    CA_SERVER -->|"HTTPS/EST"| WP_DAEMON

    %% Styles
    classDef daemon fill:#ffe0e0,stroke:#ff0000,stroke-width:2px;
    classDef module fill:#e0ffe0,stroke:#00a000;
    classDef external fill:#e0e0ff,stroke:#0000a0,stroke-dasharray: 5 5;
```
