feat(ath9k): WPA2-PSK crypto core + connect path (auth/assoc/4-way)

wpa2_crypto.{c,h} (new): self-contained, verified crypto base for the
ath9k STA connect path. No heap, no SSE, DKM-freestanding.
- SHA1 (RFC 3174), HMAC-SHA1 (RFC 2202), PBKDF2-HMAC-SHA1 (RFC 2898)
- PRF-512 (802.11i H.4) for PMK -> PTK
- AES-128 encrypt/decrypt (FIPS-197)
- RFC 3394 AES key unwrap (KEK -> GTK)
- CCMP (RFC 3610 + 802.11i): MIC verify + CTR decrypt, and encrypt for TX
- wpa2_kat(): 7 in-driver known-answer/reference cases (SHA1/HMAC/PBKDF2/
  AES x2/CCMP round-trip+tamper/unwrap). Panics ATH-E02 if any case fails.

ath9k.c: connect path built on the crypto base.
- TX descriptor ring + ath9k_tx_frame (AR9002 minimal field set; bit
  layout to be reconciled with HAL initvals during hardware bring-up)
- management frames: auth (open) / assoc request with WPA2-PSK RSN IE
- EAPOL-Key builder with HMAC-SHA1-128 MIC; M2 and M4 senders
- 4-way state machine driven from RX: M1 (ANonce) -> derive PTK ->
  M2 -> M3 (MIC verify, GTK unwrap) -> M4 -> CONNECTED
- ath9k_tx_impl for data frames (CCMP encrypt); data TX before key
  install panics ATH-E04 (zero-degradation rule)
- netdev now registers tx/connect/disconnect callbacks

build.ps1: Build-DkmDriverMulti to compile+ld -r ath9k.c with wpa2_crypto.c.

Verified on host: all wpa2_kat cases pass (AES-128 = FIPS-197 C.1
69c4e0d8..., RFC 3394 C.1 unwrap = 0011..eeff, CCMP round-trip + tamper).
Hardware bring-up (AR9285 initvals, TX/RX descriptor bit layout, key
install into the MAC) still requires real-hardware iteration.
This commit is contained in:
Linehu
2026-10-06 15:11:22 +08:00
parent b780a6b868
commit 8e6506721d
4 changed files with 1309 additions and 11 deletions
+18 -1
View File
@@ -120,6 +120,22 @@ function Build-DkmDriver([string]$SourcePath, [string]$OutputPath) {
Write-Host "[build] DKM driver Output: $OutputPath"
}
# 多源 DKM 驱动(如 ath9k + wpa2_crypto):逐文件编译后 ld -r 合并
function Build-DkmDriverMulti([string[]]$SourcePaths, [string]$OutputPath) {
$outDir = Split-Path -Parent $OutputPath
if (-not (Test-Path $outDir)) { New-Item -ItemType Directory -Force -Path $outDir | Out-Null }
$objs = @()
foreach ($src in $SourcePaths) {
$obj = Join-Path $BuildTmp (([System.IO.Path]::GetFileNameWithoutExtension($src)) + '.o')
& $clang -target x86_64-unknown-none -std=c11 -ffreestanding -fno-builtin -fno-stack-protector -fno-pic -fno-pie -mcmodel=kernel -mno-red-zone -mno-sse -mno-sse2 -mno-mmx -msoft-float -m64 -Wall -Wextra -O2 -c $src -o $obj
if ($LASTEXITCODE -ne 0) { throw "failed to compile DKM driver source: $src" }
$objs += $obj
}
& $lld -r -o $OutputPath @objs
if ($LASTEXITCODE -ne 0) { throw "failed to link DKM driver: $OutputPath" }
Write-Host "[build] DKM driver Output: $OutputPath"
}
function Set-Le16([byte[]]$Buffer, [int]$Offset, [int]$Value) {
$Buffer[$Offset] = [byte]($Value -band 0xff)
$Buffer[$Offset + 1] = [byte](($Value -shr 8) -band 0xff)
@@ -1037,7 +1053,8 @@ Build-DkmDriver (Join-Path $Root 'CODE\DKM\devfs\devfs.c') (Join-Path $SystemD
Write-Host '[build] Building DKM network drivers...'
Build-DkmDriver (Join-Path $Root 'CODE\DKM\e1000\e1000.c') (Join-Path $SystemDir 'driver\net\e1000.drv')
Build-DkmDriver (Join-Path $Root 'CODE\DKM\virtio_net\virtio_net.c') (Join-Path $SystemDir 'driver\net\virtio_net.drv')
Build-DkmDriver (Join-Path $Root 'CODE\DKM\ath9k\ath9k.c') (Join-Path $SystemDir 'driver\net\ath9k.drv')
Build-DkmDriverMulti @((Join-Path $Root 'CODE\DKM\ath9k\ath9k.c'),
(Join-Path $Root 'CODE\DKM\ath9k\wpa2_crypto.c')) (Join-Path $SystemDir 'driver\net\ath9k.drv')
Build-DkmDriver (Join-Path $Root 'CODE\DKM\wlan\wlan.c') (Join-Path $SystemDir 'driver\net\wlan.drv')
# stage3: input — ps2kbd 注册 IRQ1。