From f0a684b81a5b6353df81da50c6adc0907d16859d Mon Sep 17 00:00:00 2001 From: Jiraiya43 <11227856+Jiraiya43@users.noreply.github.com> Date: Sun, 15 Nov 2026 22:06:21 +0100 Subject: [PATCH] =?UTF-8?q?fix(journaux):=20mesure=20Wi-Fi=20sans=20faux?= =?UTF-8?q?=20signal=20=C3=A0=200=20dBm=20ni=20d=C3=A9bit=20invent=C3=A9?= =?UTF-8?q?=20(#80)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La ligne [WifiLink] écrivait « signal 0 dBm » et « to the phone 1.0 Mbit/s » sur toutes les voitures, G20 comprise. - Le niveau du dernier paquet vaut 0 quand la puce WL18xx ne l'a pas mesuré : 0 dBm n'est jamais un niveau reçu, il devient « pas de chiffre » et seule la moyenne est écrite (« average signal »). - Le débit vers le téléphone est choisi par le microprogramme de la puce ; le pilote wlcore ne le connaît pas et donne 1 Mbit/s. Il n'est plus écrit. Le débit venant du téléphone, juste, reste. --- docs/MAINTENANCE.md | 6 +++--- platform/wifi_link.cpp | 18 +++++++++--------- platform/wifi_link.hpp | 8 +++++--- tests/test_wifi_link.cpp | 25 ++++++++++++++++++++----- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/docs/MAINTENANCE.md b/docs/MAINTENANCE.md index 7b73b10..cd973c4 100644 --- a/docs/MAINTENANCE.md +++ b/docs/MAINTENANCE.md @@ -86,15 +86,15 @@ Journaux activés, le service écrit une ligne `[WifiLink]` quand le téléphone les 10 secondes jusqu'à la fin de la session : ```text -[WifiLink] 5180 MHz; signal -52 dBm (average -51); to the phone 150.0 Mbit/s; from the phone 135.0 Mbit/s; +[WifiLink] 5180 MHz; signal -52 dBm (average -51); from the phone 135.0 Mbit/s; in 10 s: 812 frames sent, 35 retried, 0 lost; on the Wi-Fi for 135 s; TCP round trip 4.2 ms, 0 segment(s) sent again ``` | Partie | Sens | |---|---| | `5180 MHz` | Fréquence du Wi-Fi de la voiture : vers 2400, la bande 2,4 GHz, partagée avec le Bluetooth ; vers 5000, la bande 5 GHz | -| `signal` | Niveau reçu du téléphone, et sa moyenne. Plus le nombre est bas, plus la liaison est fragile (-50 : bon, -80 : faible) | -| `to the phone`, `from the phone` | Débit radio choisi dans chaque sens | +| `signal` | Niveau reçu du téléphone, et sa moyenne. Plus le nombre est bas, plus la liaison est fragile (-50 : bon, -80 : faible). Quand la puce n'a pas mesuré la dernière trame, seule la moyenne est écrite (`average signal`) | +| `from the phone` | Débit radio choisi par le téléphone. Le débit vers le téléphone n'est pas écrit : la puce Wi-Fi le choisit seule et le pilote ne le connaît pas | | `frames sent, retried, lost` | Trames envoyées au téléphone depuis la ligne précédente, réémises, puis abandonnées | | `on the Wi-Fi for` | Temps depuis que le téléphone a rejoint le Wi-Fi. S'il repart de zéro, le téléphone l'a quitté puis rejoint | | `TCP round trip`, `sent again` | Temps d'aller-retour de la connexion Android Auto, et morceaux qu'il a fallu renvoyer | diff --git a/platform/wifi_link.cpp b/platform/wifi_link.cpp index 061232e..48a8dca 100644 --- a/platform/wifi_link.cpp +++ b/platform/wifi_link.cpp @@ -78,9 +78,14 @@ int64_t number(const Attr& a) { return kNoFigure; } -// A signal level: one signed byte, in dBm. +// A signal level: one signed byte, in dBm. mac80211 copies the level the chip gave with the last frame received, and +// the WL18xx leaves it at 0 for frames it did not measure: 0 dBm is never a level received from a phone. int64_t level(const Attr& a) { - return a.len == 1 ? static_cast(a.data[0]) : kNoFigure; + if (a.len != 1) { + return kNoFigure; + } + const int8_t dbm = static_cast(a.data[0]); + return dbm < 0 ? dbm : kNoFigure; } int64_t bitrate(const Attr& nested) { @@ -107,9 +112,6 @@ void stationFigures(const Attr& nested, WifiStation& out) { case NL80211_STA_INFO_SIGNAL_AVG: out.signalAvgDbm = level(a); break; - case NL80211_STA_INFO_TX_BITRATE: - out.txRate = bitrate(a); - break; case NL80211_STA_INFO_RX_BITRATE: out.rxRate = bitrate(a); break; @@ -330,7 +332,6 @@ bool continues(const WifiStation& now, const WifiStation& before) { WifiStation::WifiStation() : signalDbm(kNoFigure), signalAvgDbm(kNoFigure), - txRate(kNoFigure), rxRate(kNoFigure), txFrames(kNoFigure), txRetries(kNoFigure), @@ -396,9 +397,8 @@ std::string describeWifiLink(const WifiSample& now, const WifiSample* before) { add(line, "; ", "signal %lld dBm (average %lld)", phone.signalDbm, phone.signalAvgDbm); } else if (phone.signalDbm != kNoFigure) { add(line, "; ", "signal %lld dBm", phone.signalDbm); - } - if (phone.txRate != kNoFigure) { - add(line, "; ", "to the phone %lld.%lld Mbit/s", phone.txRate / 10, phone.txRate % 10); + } else if (phone.signalAvgDbm != kNoFigure) { + add(line, "; ", "average signal %lld dBm", phone.signalAvgDbm); } if (phone.rxRate != kNoFigure) { add(line, "; ", "from the phone %lld.%lld Mbit/s", phone.rxRate / 10, phone.rxRate % 10); diff --git a/platform/wifi_link.hpp b/platform/wifi_link.hpp index d7c143e..7bee56f 100644 --- a/platform/wifi_link.hpp +++ b/platform/wifi_link.hpp @@ -4,8 +4,10 @@ // Everything here only reads. Two sources, both the kernel's own figures: // - nl80211 (generic netlink), the interface `iw` uses: the phone's station entry on the car's access point (signal, -// bitrates, frames sent, retried and lost) and the access point's frequency; +// bitrate from the phone, frames sent, retried and lost) and the access point's frequency; // https://www.kernel.org/doc/html/latest/userspace-api/netlink/intro.html, include/uapi/linux/nl80211.h +// The rate towards the phone is left out: the WL18xx firmware chooses it, and the driver (wlcore) reported +// 1 Mbit/s on every car, the reference G20 included, whatever was sent. // - TCP_INFO on the Android Auto connection: round trip time and segments sent again. // Nothing identifies the phone in the log: no address is written. #ifndef ENTRY_AAD_PLATFORM_WIFI_LINK_HPP @@ -25,8 +27,8 @@ const int64_t kNoFigure = -0x7fffffffffffffffLL - 1; // a figure the driver did // One phone on the access point, as nl80211 reports it. struct WifiStation { uint8_t mac[6]; - int64_t signalDbm, signalAvgDbm; - int64_t txRate, rxRate; // in 100 kbit/s + int64_t signalDbm, signalAvgDbm; // signalDbm: the last frame received, when the chip measured it + int64_t rxRate; // in 100 kbit/s int64_t txFrames, txRetries, txFailed; // since the phone joined int64_t connectedS; // how long ago that was WifiStation(); diff --git a/tests/test_wifi_link.cpp b/tests/test_wifi_link.cpp index 51f7651..ab9ea57 100644 --- a/tests/test_wifi_link.cpp +++ b/tests/test_wifi_link.cpp @@ -86,7 +86,7 @@ evo::WifiStation station(uint32_t frames, uint32_t retries, uint32_t failed, uin void stationMessages() { const evo::WifiStation s = station(5000, 300, 2, 125); CHECK(!memcmp(s.mac, kPhone, sizeof(kPhone))); - CHECK(s.signalDbm == -52 && s.signalAvgDbm == -51 && s.txRate == 1500 && s.rxRate == 1350); + CHECK(s.signalDbm == -52 && s.signalAvgDbm == -51 && s.rxRate == 1350); CHECK(s.txFrames == 5000 && s.txRetries == 300 && s.txFailed == 2 && s.connectedS == 125); // A driver that gives little: what is missing stays "no figure". @@ -98,9 +98,19 @@ void stationMessages() { bare.nested(NL80211_ATTR_STA_INFO, info); evo::WifiStation little; CHECK(evo::parseWifiStation(&bare.bytes[0], bare.bytes.size(), little)); - CHECK(little.signalDbm == -70 && little.signalAvgDbm == evo::kNoFigure && little.txRate == evo::kNoFigure && + CHECK(little.signalDbm == -70 && little.signalAvgDbm == evo::kNoFigure && little.rxRate == evo::kNoFigure && little.txFrames == evo::kNoFigure && little.connectedS == evo::kNoFigure); + // A level of 0 dBm is the WL18xx's "not measured" (seen in every car log): no figure. + Attrs zero; + Attrs zeroInfo; + zeroInfo.u8(NL80211_STA_INFO_SIGNAL, 0); + zeroInfo.u8(NL80211_STA_INFO_SIGNAL_AVG, static_cast(-68)); + zero.put(NL80211_ATTR_MAC, kPhone, sizeof(kPhone)); + zero.nested(NL80211_ATTR_STA_INFO, zeroInfo); + CHECK(evo::parseWifiStation(&zero.bytes[0], zero.bytes.size(), little)); + CHECK(little.signalDbm == evo::kNoFigure && little.signalAvgDbm == -68); + // No station address: not a station. Attrs anonymous; anonymous.nested(NL80211_ATTR_STA_INFO, info); @@ -150,13 +160,13 @@ evo::WifiSample sample(uint32_t atMs, uint32_t frames, uint32_t retries, uint32_ void logLines() { const evo::WifiSample first = sample(1000, 5000, 300, 2, 125, 4250, 3); CHECK(evo::describeWifiLink(first, nullptr) == - "5180 MHz; signal -52 dBm (average -51); to the phone 150.0 Mbit/s; from the phone 135.0 Mbit/s; " + "5180 MHz; signal -52 dBm (average -51); from the phone 135.0 Mbit/s; " "since it joined: 5000 frames sent, 300 retried, 2 lost; on the Wi-Fi for 125 s; " "TCP round trip 4.2 ms, 3 segment(s) sent again since it opened"); // Ten seconds later: what happened in between. const evo::WifiSample second = sample(11040, 5812, 335, 2, 135, 38900, 9); CHECK(evo::describeWifiLink(second, &first) == - "5180 MHz; signal -52 dBm (average -51); to the phone 150.0 Mbit/s; from the phone 135.0 Mbit/s; " + "5180 MHz; signal -52 dBm (average -51); from the phone 135.0 Mbit/s; " "in 10 s: 812 frames sent, 35 retried, 0 lost; on the Wi-Fi for 135 s; " "TCP round trip 38.9 ms, 6 segment(s) sent again"); // The phone left the Wi-Fi and came back: its counters started again, nothing is subtracted. @@ -189,7 +199,12 @@ void logLines() { bare.station.txFrames = bare.station.txRetries = bare.station.txFailed = bare.station.connectedS = evo::kNoFigure; bare.station.signalAvgDbm = bare.station.rxRate = evo::kNoFigure; bare.hasTcp = false; - CHECK(evo::describeWifiLink(bare, nullptr) == "5180 MHz; signal -52 dBm; to the phone 150.0 Mbit/s"); + CHECK(evo::describeWifiLink(bare, nullptr) == "5180 MHz; signal -52 dBm"); + // The chip did not measure the last frame: the average alone. + evo::WifiSample unmeasured = first; + unmeasured.station.signalDbm = evo::kNoFigure; + unmeasured.hasTcp = false; + CHECK(evo::describeWifiLink(unmeasured, nullptr).find("5180 MHz; average signal -51 dBm; from the phone") == 0); } // A TCP connection on loopback: the car's end in car, the phone's in phone.