浏览代码

Fix network menu password entry and WiFi list

Make the network status icon the rightmost bar item so a full
temperature/battery/AC cluster cannot squeeze it out, and include
image.bin in `make all` so a manual boot cannot pick up a stale copy.

The WiFi list built its labels with a non-terminating sput(), so a
shorter SSID retained the tail of the previous one and the security
shortcut showed leftover characters.  Terminate every string sput()
builds, collapse BSSIDs that share an SSID and security (strongest wins,
active BSSID preferred) and omit hidden networks the menu cannot join.

ngui_text_input() unmasks a secret field again after drawing, so
ngui_input_value() must read in->text; reading the temporary
secret_save returned an empty password and the menu kept saying
"Enter the WPA2 passphrase".

Docs and AGENTS.md updated.
Johannes Zellner 1 周之前
父节点
当前提交
61c3117a04
共有 8 个文件被更改,包括 90 次插入 和 43 次删除
  1. 10 7
      AGENTS.md
  2. 1 1
      Makefile
  3. 9 9
      docs/graphics.html
  4. 3 1
      docs/network.html
  5. 1 1
      docs/userland.html
  6. 6 11
      ngui.c
  7. 44 0
      ucmd_netmenu.c
  8. 16 13
      ucmd_wm.c

+ 10 - 7
AGENTS.md

@@ -320,12 +320,13 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   The right-aligned date/time text is itself a click target: `draw_bar()`
   records its rectangle, the pointer highlights it, and a click spawns
   `/ramfs/bin/settime` (the `Clock` launcher still opens the analog clock).
-  A network status icon sits to its left (before the temperature/AC/battery
-  status): a cable for a wired netdev, signal bars for an associated WiFi
-  link, a USB mark for RNDIS tethering, and a red X otherwise.  The WM polls
-  `SYS_NET_INFO` (and `SYS_WIFI_STATUS` only while WiFi is active) at 1 Hz;
-  clicking the icon spawns one `/ramfs/bin/netmenu` window and anchors it
-  under the icon once its window exists (`u_wm_set_geom`).
+  A network status icon is the rightmost bar item (the date/time, temperature
+  and AC/battery cluster sits to its left): a cable for a wired netdev,
+  signal bars for an associated WiFi link, a USB mark for RNDIS tethering,
+  and a red X otherwise.  The WM polls `SYS_NET_INFO` (and
+  `SYS_WIFI_STATUS` only while WiFi is active) at 1 Hz; clicking the icon
+  spawns one `/ramfs/bin/netmenu` window and anchors it under the icon once
+  its window exists (`u_wm_set_geom`).
   The last launcher, `Chat`, spawns `/ramfs/bin/chat`; `WM_BTN_END_X`
   (`wm_abi.h`) is the launchers' right edge, and the bar notice and the
   right-aligned status never draw left of it.
@@ -562,7 +563,9 @@ it to `0x7E00`.  The kernel region itself only has one wall (`_end` below
   failure.  The top-bar network icon opens `ucmd_netmenu.c`, which lists every
   present driver through `SYS_NET_DEVLIST` (111), selects one through
   `SYS_NET_SELECT` (112) and runs DHCP; the same window lists scanned WiFi
-  networks and asks for the WPA2 passphrase.  `wifi.c` (the Intel
+  networks and asks for the WPA2 passphrase.  Hidden SSIDs are omitted, and
+  BSSIDs that share an SSID/security collapse to the strongest entry (the
+  active BSSID wins while connected).  `wifi.c` (the Intel
   7265D/3165 netdev, see the WiFi bullet) is
   last in the table; `struct netdev` has an optional `link_up()` hook, and
   the boot DHCP is skipped while it returns 0.  `net.c` — ARP + ICMP echo, IPv4/UDP

+ 1 - 1
Makefile

@@ -68,7 +68,7 @@ EFI_LDFLAGS = -nostdlib -Wl,--subsystem,10 -Wl,-e,efi_main \
 
 .PHONY: all clean run run-smp run-floppy run-usb run-uhci run-ehci run-ehci-asix run-xhci run-xhci-asix run-net run-rndis run-e1000 run-ahci test-usb test-install run-serial floppy usb uefi run-uefi test-uefi flash dev net-dev cmds-dev net-cmds browser-dev gallery-dev compat-serve netmon monitor test-crypto test-wpa test-ccmp test-images test-images-asan test-libc test-font test-font-asan test-touchpad test-chat test-chat-e2e fonts kernel-dev kernel-net-dev rootfs
 
-all: floppy.img usb.img final.bin root.img
+all: floppy.img usb.img final.bin root.img image.bin
 
 boot.o: boot.S
 	$(AS) $(ASFLAGS) -o $@ $<

+ 9 - 9
docs/graphics.html

@@ -143,15 +143,15 @@
 			and battery percentage, plus draggable
 			terminal and canvas windows with a title bar and close button.
 			Click-to-focus, drag-by-title-bar and close are routed through the
-			same pointer path. The right-aligned date/time text is also a
-			target: it highlights on hover and opens the Date &amp; Time editor
-			(<code>bin/settime</code>) on a click. To its left, a network status
-			icon shows a cable for wired Ethernet, signal bars for a connected
-			WiFi link, a USB mark for RNDIS tethering, or a red X when no link
-			is up. Clicking it opens the anchored <code>bin/netmenu</code>
-			window: present NICs can be selected (then DHCP runs), and scanned
-			WiFi networks can be joined, asking for the WPA2 passphrase first
-			when the AP requires one.
+			same pointer path. At the far right, a network status icon shows a
+			cable for wired Ethernet, signal bars for a connected WiFi link, a
+			USB mark for RNDIS tethering, or a red X when no link is up;
+			clicking it opens the anchored <code>bin/netmenu</code> window.
+			Present NICs can be selected (then DHCP runs), and scanned WiFi
+			networks can be joined, asking for the WPA2 passphrase first when
+			the AP requires one. The right-aligned date/time text sits to the
+			icon's left and is also a target: it highlights on hover and opens
+			the Date &amp; Time editor (<code>bin/settime</code>) on a click.
 		</p>
 		<p>
 			The WM is the ring-3 process loaded from

+ 3 - 1
docs/network.html

@@ -152,7 +152,9 @@
 			DHCP. The same window lists scanned WiFi networks; selecting a WPA2
 			network asks for the passphrase and starts the existing
 			<code>wifi</code> supplicant, which opens the data port and runs DHCP
-			itself.
+			itself. Mesh/repeater BSSIDs sharing one SSID are collapsed to the
+			strongest entry (the active BSSID wins when connected), and hidden
+			SSIDs are omitted because the menu cannot join them.
 		</p>
 		<p>
 			<span class="file">rndis.c</span> is the USB tethering path, not a

+ 1 - 1
docs/userland.html

@@ -342,7 +342,7 @@
 			<li><strong>edit</strong> — text editor that draws its own text with the 8x16 font.</li>
 			<li><strong>clock</strong> / <strong>colors</strong> — small window canvas demos.</li>
 			<li><strong>settime</strong> — Date &amp; Time editor opened by clicking the top-bar clock. It reads and writes the CMOS RTC through <code>SYS_RTC_GET</code>/<code>SYS_RTC_SET</code>; the <em>Sync NTP</em> button asks the kernel's SNTP client (<code>SYS_NTP_SYNC</code>, 106) for UTC and writes the result to the RTC. The two-digit RTC year is expanded over 1970–2069 so dead-battery defaults such as 1980/1990 can be corrected.</li>
-			<li><strong>netmenu</strong> — network menu opened by the top-bar status icon. Lists the present NICs from <code>SYS_NET_DEVLIST</code> (Ethernet, USB Ethernet, RNDIS tethering), selects one with <code>SYS_NET_SELECT</code> and runs DHCP. Its WiFi section scans through <code>SYS_WIFI_SCAN</code>/<code>RESULTS</code>, asks for a WPA2 passphrase when needed and starts the <code>wifi</code> helper through a <code>/share/netmenu.wifi</code> request, because the 64-byte <code>SYS_SPAWN</code> argument cannot hold a long SSID plus passphrase. The helper's terminal output is shown while it connects.</li>
+			<li><strong>netmenu</strong> — network menu opened by the top-bar status icon. Lists the present NICs from <code>SYS_NET_DEVLIST</code> (Ethernet, USB Ethernet, RNDIS tethering), selects one with <code>SYS_NET_SELECT</code> and runs DHCP. Its WiFi section scans through <code>SYS_WIFI_SCAN</code>/<code>RESULTS</code>, asks for a WPA2 passphrase when needed and starts the <code>wifi</code> helper through a <code>/share/netmenu.wifi</code> request, because the 64-byte <code>SYS_SPAWN</code> argument cannot hold a long SSID plus passphrase. The helper's terminal output is shown while it connects. Duplicate BSSIDs for one SSID are collapsed to the strongest entry (or the active one), and hidden networks are omitted.</li>
 			<li><strong>wm</strong> / <strong>term</strong> — the ring-3 window manager and terminal launcher used by the desktop.</li>
 		</ul>
 		<p>

+ 6 - 11
ngui.c

@@ -32,12 +32,6 @@ static unsigned int slen(const char *s)
 	return n;
 }
 
-/* Secret fields are measured and painted from a '*' mask: the real text is
- * swapped out for everything except the edit loop, so the caret, selection
- * and click positions all follow the masked width. */
-static char secret_save[NGUI_INPUT_MAX];
-static struct ngui_input *secret_owner;
-
 static void scopy(char *dst, const char *src, unsigned int cap)
 {
 	unsigned int i = 0;
@@ -1179,14 +1173,14 @@ void ngui_input_set(struct ngui_input *in, const char *s)
 void ngui_input_value(const struct ngui_input *in, char *out,
 		      unsigned int max)
 {
-	const char *src;
 	unsigned int i;
 
 	if (!in || !out || !max)
 		return;
-	src = (in->secret && in == secret_owner) ? secret_save : in->text;
-	for (i = 0; src[i] && i + 1 < max; i++)
-		out[i] = src[i];
+	/* ngui_text_input() unmasks a secret field again after drawing, so
+	 * in->text is the real value between calls. */
+	for (i = 0; in->text[i] && i + 1 < max; i++)
+		out[i] = in->text[i];
 	out[i] = '\0';
 }
 
@@ -1399,11 +1393,12 @@ static void input_scroll_to_cursor(struct ngui *ui, struct ngui_input *in,
 /* Secret fields are measured and painted from a '*' mask: the real text is
  * swapped out for everything except the edit loop, so the caret, selection
  * and click positions all follow the masked width. */
+static char secret_save[NGUI_INPUT_MAX];
+
 static void secret_mask(struct ngui_input *in)
 {
 	unsigned int i;
 
-	secret_owner = in;
 	for (i = 0; i <= in->len && i < NGUI_INPUT_MAX; i++) {
 		secret_save[i] = in->text[i];
 		in->text[i] = i < in->len ? '*' : '\0';

+ 44 - 0
ucmd_netmenu.c

@@ -99,6 +99,7 @@ static char *sput(char *p, const char *s)
 {
 	while (s && *s)
 		*p++ = *s++;
+	*p = '\0';
 	return p;
 }
 
@@ -269,6 +270,48 @@ static void sort_bss(void)
 		}
 }
 
+static int same_ssid(const struct sys_wifi_bss *a,
+		     const struct sys_wifi_bss *b)
+{
+	unsigned int i;
+
+	if (a->ssid_len == 0 || a->ssid_len != b->ssid_len)
+		return 0;
+	for (i = 0; i < a->ssid_len; i++)
+		if (a->ssid[i] != b->ssid[i])
+			return 0;
+	return 1;
+}
+
+/* Mesh/repeater setups often advertise one SSID from several BSSIDs.  The
+ * list is RSSI-sorted, so keep the strongest entry of each SSID/security
+ * pair (or the active BSSID when one of them is the current connection).
+ * Hidden-SSID entries are dropped: the menu cannot join them anyway. */
+static void filter_bss(void)
+{
+	int i, j, out = 0;
+
+	for (i = 0; i < nbss; i++) {
+		int dup = -1;
+
+		if (bss[i].ssid_len == 0)
+			continue;
+		for (j = 0; j < out; j++)
+			if (bss[i].security == bss[j].security &&
+			    same_ssid(&bss[i], &bss[j])) {
+				dup = j;
+				break;
+			}
+		if (dup < 0) {
+			bss[out++] = bss[i];
+		} else if (bss_is_active(&bss[i]) &&
+			   !bss_is_active(&bss[dup])) {
+			bss[dup] = bss[i];
+		}
+	}
+	nbss = out;
+}
+
 static void start_scan(void)
 {
 	int r;
@@ -317,6 +360,7 @@ static void poll_scan(void)
 	}
 	nbss = n;
 	sort_bss();
+	filter_bss();
 	if (nbss == 0)
 		set_status("No WiFi networks found", 1);
 	else

+ 16 - 13
ucmd_wm.c

@@ -418,6 +418,22 @@ static void draw_bar(void)
 		bar_clock_w = 0;
 		bar_net_x = -1;
 		bar_net_w = 0;
+		/* The network status is the rightmost item, so it survives
+		 * narrow screens and a full temperature/battery cluster. */
+		{
+			int nx = right - BAR_NET_W;
+
+			if (nx >= min_x) {
+				if (bar_net_hot)
+					usurf_fill(&screen, nx - 3, 2,
+						   BAR_NET_W + 6,
+						   WM_BAR_H - 4, 0x3A3A55u);
+				bar_draw_net_icon(nx, BAR_NET_Y);
+				bar_net_x = nx;
+				bar_net_w = BAR_NET_W;
+				right = nx - 8;
+			}
+		}
 		if (u_rtc_datetime(dt, sizeof(dt)) == 0) {
 			int tw = (int)usurf_text_width(&screen, dt);
 			int tx = right - tw;
@@ -481,19 +497,6 @@ static void draw_bar(void)
 				right = ax - 8;
 			}
 		}
-		{
-			int nx = right - BAR_NET_W;
-
-			if (nx >= min_x) {
-				if (bar_net_hot)
-					usurf_fill(&screen, nx - 3, 2,
-						   BAR_NET_W + 6,
-						   WM_BAR_H - 4, 0x3A3A55u);
-				bar_draw_net_icon(nx, BAR_NET_Y);
-				bar_net_x = nx;
-				bar_net_w = BAR_NET_W;
-			}
-		}
 	}
 }