mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-22 01:13:00 +02:00
confd: Wi-Fi: Rename RSSI to signal-strength
RSSI is a vendor-specific relative index (0-255), while dBm is an absolute power measurement. Since we report dBm values from iw, rename the leaf to signal-strength for accuracy.
This commit is contained in:
@@ -322,7 +322,7 @@ def parse_stations(ifname):
|
||||
try:
|
||||
if key == 'signal':
|
||||
# Format: "-42 dBm" or "-42 [-44, -45] dBm"
|
||||
current['rssi'] = int(value.split()[0])
|
||||
current['signal-strength'] = int(value.split()[0])
|
||||
elif key == 'connected time':
|
||||
# Format: "123 seconds"
|
||||
current['connected-time'] = int(value.split()[0])
|
||||
@@ -500,7 +500,7 @@ def parse_link(ifname):
|
||||
# signal: -42 dBm
|
||||
elif stripped.startswith('signal: '):
|
||||
try:
|
||||
result['rssi'] = int(stripped.split()[1])
|
||||
result['signal-strength'] = int(stripped.split()[1])
|
||||
except (ValueError, IndexError):
|
||||
pass
|
||||
|
||||
|
||||
+2
-2
@@ -238,8 +238,8 @@ CoffeeShop 00:1a:2b:3c:4d:5e Open bad 1
|
||||
</code></pre>
|
||||
|
||||
In the CLI, signal strength is reported as: excellent, good, fair or bad.
|
||||
For precise RSSI values in dBm, use NETCONF or RESTCONF to access the
|
||||
operational datastore directly.
|
||||
For precise signal strength values in dBm, use NETCONF or RESTCONF to access
|
||||
the `signal-strength` leaf in the operational datastore.
|
||||
|
||||
## Station Mode (Client)
|
||||
|
||||
|
||||
@@ -204,12 +204,12 @@ submodule infix-if-wifi {
|
||||
|
||||
/* Operational state */
|
||||
|
||||
leaf rssi {
|
||||
leaf signal-strength {
|
||||
config false;
|
||||
type int16;
|
||||
units "dBm";
|
||||
description
|
||||
"Current received signal strength indication (RSSI) in dBm.
|
||||
"Current signal strength in dBm.
|
||||
|
||||
More negative values indicate weaker signal.
|
||||
|
||||
@@ -269,7 +269,7 @@ submodule infix-if-wifi {
|
||||
description "BSSID (MAC address) of the AP.";
|
||||
}
|
||||
|
||||
leaf rssi {
|
||||
leaf signal-strength {
|
||||
type int16;
|
||||
units "dBm";
|
||||
description "Signal strength of the network.";
|
||||
@@ -418,7 +418,7 @@ submodule infix-if-wifi {
|
||||
description "Client MAC address.";
|
||||
}
|
||||
|
||||
leaf rssi {
|
||||
leaf signal-strength {
|
||||
type int16;
|
||||
units "dBm";
|
||||
description "Client signal strength in dBm.";
|
||||
|
||||
@@ -565,12 +565,12 @@ class Decore():
|
||||
print(txt)
|
||||
|
||||
|
||||
def rssi_to_status(rssi):
|
||||
if rssi <= -75:
|
||||
def signal_to_status(signal):
|
||||
if signal >= -50:
|
||||
status = Decore.bright_green("excellent")
|
||||
elif rssi <= -65:
|
||||
elif signal <= -65:
|
||||
status = Decore.green("good")
|
||||
elif rssi <= -50:
|
||||
elif signal <= -50:
|
||||
status = Decore.yellow("poor")
|
||||
else:
|
||||
status = Decore.red("bad")
|
||||
@@ -1249,7 +1249,7 @@ class Iface:
|
||||
ssid = result.get('ssid', 'Hidden')
|
||||
bssid = result.get("bssid", "unknown")
|
||||
encstr = ", ".join(result.get("encryption", ["Unknown"]))
|
||||
status = rssi_to_status(result.get("rssi", -100))
|
||||
status = signal_to_status(result.get("signal-strength", -100))
|
||||
channel = result.get("channel", "?")
|
||||
|
||||
ssid_table.row(ssid, bssid, encstr, status, channel)
|
||||
@@ -1283,8 +1283,8 @@ class Iface:
|
||||
|
||||
for station in stations:
|
||||
mac = station.get("mac-address", "unknown")
|
||||
rssi = station.get("rssi")
|
||||
signal_str = rssi_to_status(rssi) if rssi is not None else "------"
|
||||
signal = station.get("signal-strength")
|
||||
signal_str = signal_to_status(signal) if signal is not None else "------"
|
||||
|
||||
conn_time = station.get("connected-time", 0)
|
||||
time_str = f"{conn_time}s"
|
||||
@@ -1310,11 +1310,11 @@ class Iface:
|
||||
row = self._pr_proto_common("ethernet", True, pipe);
|
||||
print(row)
|
||||
ssid = None
|
||||
rssi = None
|
||||
signal = None
|
||||
mode = None
|
||||
|
||||
if self.wifi:
|
||||
# Detect mode: AP has "stations", Station has "rssi" or "scan-results"
|
||||
# Detect mode: AP has "stations", Station has "signal-strength" or "scan-results"
|
||||
ap=self.wifi.get("access-point", {})
|
||||
if ap:
|
||||
ssid = ap.get("ssid", "------")
|
||||
@@ -1326,11 +1326,11 @@ class Iface:
|
||||
else:
|
||||
station=self.wifi.get("station", {})
|
||||
ssid = station.get("ssid", "------")
|
||||
rssi = station.get("rssi")
|
||||
signal = station.get("signal-strength")
|
||||
mode = "Station"
|
||||
if rssi is not None:
|
||||
signal = rssi_to_status(rssi)
|
||||
data_str = f"{mode}, ssid: {ssid}, signal: {signal}"
|
||||
if signal is not None:
|
||||
signal_str = signal_to_status(signal)
|
||||
data_str = f"{mode}, ssid: {ssid}, signal: {signal_str}"
|
||||
else:
|
||||
data_str = f"{mode}, ssid: {ssid}"
|
||||
else:
|
||||
@@ -1618,7 +1618,7 @@ class Iface:
|
||||
print(f"{'out-octets':<{20}}: {self.out_octets}")
|
||||
|
||||
if self.wifi:
|
||||
# Detect mode: AP has "stations", Station has "rssi" or "scan-results"
|
||||
# Detect mode: AP has "stations", Station has "signal-strength" or "scan-results"
|
||||
ap = self.wifi.get('access-point')
|
||||
if ap:
|
||||
mode = "access-point"
|
||||
@@ -1632,13 +1632,13 @@ class Iface:
|
||||
else:
|
||||
mode = "station"
|
||||
station = self.wifi.get('station', {})
|
||||
rssi = station.get('rssi')
|
||||
signal = station.get('signal-strength')
|
||||
ssid = station.get('ssid', "----")
|
||||
print(f"{'mode':<{20}}: {mode}")
|
||||
print(f"{'ssid':<{20}}: {ssid}")
|
||||
if rssi is not None:
|
||||
signal_status = rssi_to_status(rssi)
|
||||
print(f"{'signal':<{20}}: {rssi} dBm ({signal_status})")
|
||||
if signal is not None:
|
||||
signal_status = signal_to_status(signal)
|
||||
print(f"{'signal':<{20}}: {signal} dBm ({signal_status})")
|
||||
rx_speed = station.get('rx-speed')
|
||||
tx_speed = station.get('tx-speed')
|
||||
if rx_speed is not None:
|
||||
|
||||
@@ -62,14 +62,14 @@ def wifi_station(ifname):
|
||||
"""Get operational data for Station mode using iw + wpa_cli for scanning"""
|
||||
station_data = {}
|
||||
|
||||
# Get link info (includes SSID and RSSI when connected)
|
||||
# Get link info (includes SSID and signal strength when connected)
|
||||
link = get_iw_link(ifname)
|
||||
|
||||
if link.get('connected'):
|
||||
if link.get('ssid'):
|
||||
station_data['ssid'] = link['ssid']
|
||||
if link.get('rssi') is not None:
|
||||
station_data['rssi'] = link['rssi']
|
||||
if link.get('signal-strength') is not None:
|
||||
station_data['signal-strength'] = link['signal-strength']
|
||||
if link.get('rx-speed') is not None:
|
||||
station_data['rx-speed'] = link['rx-speed']
|
||||
if link.get('tx-speed') is not None:
|
||||
@@ -130,21 +130,21 @@ def parse_wpa_scan_result(scan_output):
|
||||
encryption = extract_encryption(flags)
|
||||
channel = frequency_to_channel(frequency)
|
||||
|
||||
# Keep best RSSI per SSID
|
||||
if ssid not in networks or rssi > networks[ssid]['rssi']:
|
||||
# Keep best signal per SSID
|
||||
if ssid not in networks or rssi > networks[ssid]['signal-strength']:
|
||||
networks[ssid] = {
|
||||
'bssid': bssid,
|
||||
'ssid': ssid,
|
||||
'rssi': rssi,
|
||||
'signal-strength': rssi,
|
||||
'encryption': encryption,
|
||||
'channel': channel
|
||||
}
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
# Sort by RSSI (best first)
|
||||
# Sort by signal strength (best first)
|
||||
result = list(networks.values())
|
||||
result.sort(key=lambda x: x['rssi'], reverse=True)
|
||||
result.sort(key=lambda x: x['signal-strength'], reverse=True)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
Reference in New Issue
Block a user