Skip to content
Merged
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
6 changes: 3 additions & 3 deletions docs/MAINTENANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
18 changes: 9 additions & 9 deletions platform/wifi_link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int8_t>(a.data[0]) : kNoFigure;
if (a.len != 1) {
return kNoFigure;
}
const int8_t dbm = static_cast<int8_t>(a.data[0]);
return dbm < 0 ? dbm : kNoFigure;
}

int64_t bitrate(const Attr& nested) {
Expand All @@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions platform/wifi_link.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
Expand Down
25 changes: 20 additions & 5 deletions tests/test_wifi_link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand All @@ -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<uint8_t>(-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);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down