Konrad, 2026-11-13: "panel fehlt, top leiste is lila", the network settings "zu rudimentaer, keine ip config, kein dns", the global menu only while a program that has one is in front. The bar (and the launcher, the drop-down terminal, the login items) came from Xsession.d, before dtsession had loaded the session's resources and the colour server: dtbar took *background from ~/.Xdefaults (#6e1e7d, the user's base16 theme; dtbar PID 1270788 started before dtsession 1270795). Restarting dtbar in the running session gave the palette's colours. Now dtsession runs sys.sessionetc -- the first of CDE_CONFIGURATION_TOP/config and CDE_INSTALLATION_TOP/config, as sys.session is found -- before the user's sessionetc (SmRestore.c, StartEtc); it sources config/sessionetc.d, where 0080.dtlaunch, 0085.dtdropdown, 0090.dtbar and 0095.loginitems moved. The bar takes colour set 5, the programs' background, not set 6 of a menu bar (Dtbar*secondaryColorSetId: 5; measured #c6b2a8 with Default.dp). dtwm publishes the focused client as _NET_ACTIVE_WINDOW (EWMH, WmEwmh.c SetNetActiveWindow from SetKeyboardFocus and where the focus is dropped); dtbar shows a program's menus only while the active window is the menus' owner, a dialog of it (WM_TRANSIENT_FOR) or a window of the same program (WM_CLIENT_LEADER). Measured on Xvfb with dtwm, dtbar, dtpad and xterm, clicking: dtpad -> its menus, xterm -> M only, dtpad -> its menus again. Network (dtsystemsettings/network.c, docs/reference/netconfig.txt): Show: Network Status (a light and a sentence per card, Configure...) or one card with the tabs TCP/IP (Using DHCP, with manual address, Manually, Off; address, mask, router, DHCP client ID, Renew DHCP Lease; IPv6), DNS (servers, search domains, what resolv.conf has now), Wi-Fi and Ethernet; the lock and Apply Now as Accounts. McdeSys mcde_sys_net_config, _configure, _renew (replacing mcde_sys_net_dhcp, which was declared and implemented nowhere): NetBSD one block per interface in dhcpcd.conf, as ifconfig.if(5) recommends, sysinst's static address in ifconfig.IF read and moved there, applied with dhcpcd -n IF (cross-compiled with the tree's x86_64--netbsd-gcc, not run); Linux the NetworkManager profile (nmcli). mcde_sys_interfaces took the last IPv4 address (the secondary one), now the first. Measured on this host, read only: the pane shows the three cards, 172.20.10.2/28 by DHCP, router 172.20.10.1, DNS 1.1.1.1, MAC, MTU 1500; test_sysinfo (new checks: settings read, 300.1.2.3 refused) exit 0. Nothing was applied on the development host. From the review of 2026-11-12's commits: libDtTerm links libMcdeSound (977a7347c made the bell call McdeSoundEvent; dtcodegen did not link); the PLIST lacked dtphoto, dtpaint, dttoolbox, mcdesoundd, libMcdeSound, their data and the sound themes (51 entries, from the installed tree); mcdesoundd was started by nothing (sessionetc.d/0075.mcdesoundd) and took the selection from a running server; dttoolbox kept only the first line of the Selected menu and rebuilt it every 500 ms, and NewMenu returned an uninitialised pointer past 64 menus. Built and installed with make mcde-host MCDE_DIRS=install, exit 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
276 lines
7.2 KiB
C
276 lines
7.2 KiB
C
/*
|
|
* wifi.c -- dtsystemsettings: the Wi-Fi networks in reach, and joining one
|
|
*
|
|
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
|
|
*
|
|
* The Wi-Fi tab of a card in the Network pane: the networks McdeSys
|
|
* finds (mcde_sys_wifi_scan) with their signal and whether they are
|
|
* secured; "Scan" looks again, "Join..." joins the one chosen. Joining
|
|
* changes the system (mcde_sys_wifi_join, root), so it runs in a terminal
|
|
* where su(1) asks for the administrator's password -- the way Software
|
|
* Update and the time zone do -- and there dtsystemsettings -join-wifi IF
|
|
* [SSID] asks for the network's password without echo. The SSID goes on
|
|
* that command line as hexadecimal, so no name a network may have reaches a
|
|
* shell; the password goes on no command line of MCDE's. Without an SSID
|
|
* the terminal looks for the networks itself, as root -- on NetBSD a user
|
|
* cannot scan while wpa_supplicant does not run.
|
|
*
|
|
* C99, POSIX, Xt and Motif only (ext/src/mcde/AGENTS.md).
|
|
*/
|
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <termios.h>
|
|
#include <unistd.h>
|
|
|
|
#include <X11/Intrinsic.h>
|
|
#include <Xm/Xm.h>
|
|
#include <Xm/List.h>
|
|
#include <Xm/RowColumn.h>
|
|
|
|
#include <Mcde/McdeSys.h>
|
|
|
|
#include "ui.h"
|
|
|
|
#define MAX_NETS 64
|
|
|
|
static Widget netList, wifiNote;
|
|
static McdeSysWifi nets[MAX_NETS];
|
|
static int nnets;
|
|
static char wifiIf[32];
|
|
|
|
static void
|
|
Hex(const char *s, char *buf, size_t len)
|
|
{
|
|
size_t i, n = 0;
|
|
|
|
for (i = 0; s[i] != '\0' && n + 3 < len; i++)
|
|
n += (size_t) snprintf(buf + n, len - n, "%02x",
|
|
(unsigned char) s[i]);
|
|
buf[n] = '\0';
|
|
}
|
|
|
|
static int
|
|
Unhex(const char *h, char *buf, size_t len)
|
|
{
|
|
size_t n = 0;
|
|
unsigned int c;
|
|
|
|
while (h[0] != '\0' && h[1] != '\0' && n + 1 < len) {
|
|
if (sscanf(h, "%2x", &c) != 1)
|
|
return 0;
|
|
buf[n++] = (char) c;
|
|
h += 2;
|
|
}
|
|
buf[n] = '\0';
|
|
return h[0] == '\0' && n > 0;
|
|
}
|
|
|
|
static void
|
|
Scan(void)
|
|
{
|
|
char text[128];
|
|
int i;
|
|
|
|
XmListDeleteAllItems(netList);
|
|
nnets = mcde_sys_wifi_scan(wifiIf, nets, MAX_NETS);
|
|
if (nnets < 0) {
|
|
nnets = 0;
|
|
SetText(wifiNote, mcde_sys_error());
|
|
return;
|
|
}
|
|
for (i = 0; i < nnets; i++) {
|
|
XmString s;
|
|
|
|
snprintf(text, sizeof text, "%-32s %3d%%%s", nets[i].ssid,
|
|
nets[i].signal, nets[i].secured ? " secured" : "");
|
|
s = XmStringCreateLocalized(text);
|
|
XmListAddItemUnselected(netList, s, 0);
|
|
XmStringFree(s);
|
|
}
|
|
snprintf(text, sizeof text, nnets == 1 ? "%d network in reach." :
|
|
"%d networks in reach.", nnets);
|
|
SetText(wifiNote, text);
|
|
}
|
|
|
|
/* the scan takes seconds (nmcli looks again when its list is older than 30
|
|
* seconds): after the pane is drawn, not before */
|
|
static void
|
|
ScanLater(XtPointer data, XtIntervalId *id)
|
|
{
|
|
(void) data;
|
|
(void) id;
|
|
if (netList != NULL)
|
|
Scan();
|
|
}
|
|
|
|
static void
|
|
WifiGone(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
netList = NULL;
|
|
}
|
|
|
|
static void
|
|
ScanClicked(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
Scan();
|
|
}
|
|
|
|
static void
|
|
JoinClicked(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
int *pos = NULL, n = 0;
|
|
char hex[80] = "", inner[160], cmd[512];
|
|
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
if (XmListGetSelectedPos(netList, &pos, &n) && n > 0 &&
|
|
pos[0] >= 1 && pos[0] <= nnets)
|
|
Hex(nets[pos[0] - 1].ssid, hex, sizeof hex);
|
|
XtFree((char *) pos);
|
|
snprintf(inner, sizeof inner, "dtsystemsettings -join-wifi %s%s%s",
|
|
wifiIf, hex[0] != '\0' ? " " : "", hex);
|
|
AsRoot("Join a Wi-Fi Network", inner, cmd, sizeof cmd);
|
|
Spawn(cmd);
|
|
SetText(wifiNote, "The passwords are asked for in the window that "
|
|
"opened.");
|
|
}
|
|
|
|
/* the Wi-Fi tab of a card in the Network pane (IFNAME, or the first Wi-Fi
|
|
* card when NULL); NULL when there is no Wi-Fi card */
|
|
Widget
|
|
MakeWifi(Widget parent, const char *ifname)
|
|
{
|
|
McdeSysInterface ifs[32];
|
|
int n = ifname != NULL ? 0 : mcde_sys_interfaces(ifs, 32), i;
|
|
Widget box, row;
|
|
Arg a[4];
|
|
char text[96];
|
|
|
|
wifiIf[0] = '\0';
|
|
if (ifname != NULL)
|
|
snprintf(wifiIf, sizeof wifiIf, "%s", ifname);
|
|
for (i = 0; i < n; i++)
|
|
if (ifs[i].kind == MCDE_NET_WIFI) {
|
|
snprintf(wifiIf, sizeof wifiIf, "%s", ifs[i].name);
|
|
break;
|
|
}
|
|
if (wifiIf[0] == '\0')
|
|
return NULL;
|
|
box = XtVaCreateManagedWidget("wifi", xmRowColumnWidgetClass, parent,
|
|
XmNspacing, 6, NULL);
|
|
snprintf(text, sizeof text, "Wi-Fi networks in reach of %s:", wifiIf);
|
|
(void) Text(box, "label", text);
|
|
XtSetArg(a[0], XmNvisibleItemCount, 7);
|
|
XtSetArg(a[1], XmNselectionPolicy, XmBROWSE_SELECT);
|
|
XtSetArg(a[2], XmNwidth, 460);
|
|
netList = XmCreateScrolledList(box, "networks", a, 3);
|
|
XtManageChild(netList);
|
|
row = XtVaCreateManagedWidget("buttons", xmRowColumnWidgetClass, box,
|
|
XmNorientation, XmHORIZONTAL, XmNmarginWidth, 0, NULL);
|
|
(void) Button(row, "Scan", ScanClicked, NULL);
|
|
(void) Button(row, "Join...", JoinClicked, NULL);
|
|
wifiNote = Text(box, "note", "Looking for networks ...");
|
|
XtAddCallback(box, XmNdestroyCallback, WifiGone, NULL);
|
|
XtAppAddTimeOut(app, 300, ScanLater, NULL);
|
|
return box;
|
|
}
|
|
|
|
/* ---- dtsystemsettings -join-wifi IF [SSID-IN-HEX], in the terminal ------- */
|
|
|
|
static void
|
|
ReadSecret(const char *prompt, char *buf, size_t len)
|
|
{
|
|
struct termios t, quiet;
|
|
int tty = tcgetattr(STDIN_FILENO, &t) == 0;
|
|
|
|
printf("%s", prompt);
|
|
fflush(stdout);
|
|
if (tty) {
|
|
quiet = t;
|
|
quiet.c_lflag &= (tcflag_t) ~ECHO;
|
|
(void) tcsetattr(STDIN_FILENO, TCSAFLUSH, &quiet);
|
|
}
|
|
if (fgets(buf, (int) len, stdin) == NULL)
|
|
buf[0] = '\0';
|
|
buf[strcspn(buf, "\r\n")] = '\0';
|
|
if (tty)
|
|
(void) tcsetattr(STDIN_FILENO, TCSAFLUSH, &t);
|
|
printf("\n");
|
|
}
|
|
|
|
static int
|
|
Finish(int r)
|
|
{
|
|
printf("\nPress Return to close this window.\n");
|
|
fflush(stdout);
|
|
(void) getchar();
|
|
return r;
|
|
}
|
|
|
|
int
|
|
JoinWifiCommand(const char *ifname, const char *hexssid)
|
|
{
|
|
static McdeSysWifi found[MAX_NETS];
|
|
char ssid[64], line[64], pass[128];
|
|
int secured = 1, n, i, r;
|
|
|
|
if (hexssid != NULL) {
|
|
if (!Unhex(hexssid, ssid, sizeof ssid)) {
|
|
printf("That is no network name.\n");
|
|
return Finish(1);
|
|
}
|
|
n = mcde_sys_wifi_scan(ifname, found, MAX_NETS);
|
|
for (i = 0; i < n; i++)
|
|
if (strcmp(found[i].ssid, ssid) == 0)
|
|
secured = found[i].secured;
|
|
} else {
|
|
printf("Looking for Wi-Fi networks on %s ...\n", ifname);
|
|
fflush(stdout);
|
|
n = mcde_sys_wifi_scan(ifname, found, MAX_NETS);
|
|
if (n <= 0) {
|
|
printf("No network found%s%s\n", n < 0 ? ": " : ".",
|
|
n < 0 ? mcde_sys_error() : "");
|
|
return Finish(1);
|
|
}
|
|
for (i = 0; i < n; i++)
|
|
printf("%3d %-32s %3d%%%s\n", i + 1, found[i].ssid,
|
|
found[i].signal,
|
|
found[i].secured ? " secured" : "");
|
|
printf("\nNumber of the network to join: ");
|
|
fflush(stdout);
|
|
if (fgets(line, sizeof line, stdin) == NULL ||
|
|
(i = atoi(line)) < 1 || i > n) {
|
|
printf("Nothing joined.\n");
|
|
return Finish(1);
|
|
}
|
|
snprintf(ssid, sizeof ssid, "%s", found[i - 1].ssid);
|
|
secured = found[i - 1].secured;
|
|
}
|
|
pass[0] = '\0';
|
|
if (secured) {
|
|
printf("Network \"%s\"\n", ssid);
|
|
ReadSecret("Its password (not shown): ", pass, sizeof pass);
|
|
}
|
|
printf("Joining \"%s\" ...\n", ssid);
|
|
fflush(stdout);
|
|
r = mcde_sys_wifi_join(ifname, ssid, pass[0] != '\0' ? pass : NULL);
|
|
memset(pass, 0, sizeof pass);
|
|
if (r == MCDE_SYS_OK)
|
|
printf("Joined \"%s\"; the computer joins it at every start.\n",
|
|
ssid);
|
|
else
|
|
printf("Not joined: %s\n", mcde_sys_error());
|
|
return Finish(r == MCDE_SYS_OK ? 0 : 1);
|
|
}
|