Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion scanner/Sources/WifiScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,14 @@ func mapBand(_ b: CWChannelBand) -> UInt8 {
switch b.rawValue { case 1: return 1; case 2: return 2; case 3: return 3; default: return 0 }
}
func mapWidth(_ w: CWChannelWidth) -> UInt16 {
switch w.rawValue { case 0: return 20; case 1: return 40; case 2: return 80; case 3: return 160; default: return 0 }
switch w {
case .widthUnknown: return 0
case .width20MHz: return 20
case .width40MHz: return 40
case .width80MHz: return 80
case .width160MHz: return 160
@unknown default: return 0
}
}
func detectSecurity(_ n: CWNetwork) -> UInt8 {
let probes: [(CWSecurity, UInt8)] = [
Expand Down
20 changes: 20 additions & 0 deletions scanner/Tests/WifiScannerTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Darwin
import Foundation
import CoreWLAN

struct TestFailure: Error, CustomStringConvertible {
let message: String
Expand Down Expand Up @@ -107,6 +108,24 @@ func testParseBSSIDRejectsMissingInvalidOrShortValues() throws {
try expectEqual(parseBSSID("01:23:45:67:89:xx"), Data(), "invalid BSSID should parse as empty data")
}

func testMapWidthUsesCoreWLANChannelWidthConstants() throws {
let cases: [(CWChannelWidth, UInt16, String)] = [
(.widthUnknown, 0, "unknown"),
(.width20MHz, 20, "20 MHz"),
(.width40MHz, 40, "40 MHz"),
(.width80MHz, 80, "80 MHz"),
(.width160MHz, 160, "160 MHz"),
]

for (width, expectedWidth, name) in cases {
try expectEqual(
mapWidth(width),
expectedWidth,
"mapWidth should convert CoreWLAN \(name) channel width"
)
}
}

func testEncodePasswordResponseMatchesWireFormat() throws {
let response = encodePasswordResponse(password: "secret", error: "denied")

Expand Down Expand Up @@ -180,6 +199,7 @@ struct WifiScannerTestRunner {
("writeAll writes full payloads", testWriteAllWritesFullPayload),
("parseBSSID accepts valid hex octets", testParseBSSIDAcceptsHexOctets),
("parseBSSID rejects invalid values", testParseBSSIDRejectsMissingInvalidOrShortValues),
("mapWidth uses CoreWLAN channel width constants", testMapWidthUsesCoreWLANChannelWidthConstants),
("encodePasswordResponse matches wire format", testEncodePasswordResponseMatchesWireFormat),
("encodeScanResponse matches wire format", testEncodeScanResponseMatchesWireFormat),
]
Expand Down
Loading