Wi-Fi on NetBSD (and Linux): what McdeSys mcde_sys_wifi_scan/_join follow.  Collected 2026-11-11.

== src/sbin/ifconfig/ifconfig.8:447-456 (list scan)
.It Cm list scan
.Pq IEEE 802.11 devices only
Display the access points and/or ad-hoc neighbors
located in the vicinity.
The
.Fl v
flag may be used to display long SSIDs.
.Fl v
also causes received information elements to be displayed symbolically.
The interface must be up before any scanning operation.

== src/sbin/ifconfig/ieee80211.c:811-835 (the scan table: SSID padded, BSSID, CHAN, RATE, S:N, INT, CAPS)
	printf("%-*.*s  %-17.17s  %4s %4s  %-7s %3s %4s\n"
		, ssidmax, ssidmax, "SSID"
		, "BSSID"
		, "CHAN"
		, "RATE"
		, "S:N"
		, "INT"
		, "CAPS"
	);
	cp = buf;
	while (len >= (int)sizeof(*sr)) {
		const uint8_t *vp;

		sr = (const struct ieee80211req_scan_result *) cp;
		vp = (const u_int8_t *)(sr+1);
		(void)copy_essid(ssid, sizeof(ssid), vp, sr->isr_ssid_len);
		printf("%-*.*s  %s  %3d  %3dM %3d:%-3d  %3d %-4.4s"
			, ssidmax, ssidmax, ssid
			, ether_ntoa((const struct ether_addr *) sr->isr_bssid)
			, ieee80211_mhz2ieee(sr->isr_freq, sr->isr_flags)
			, getmaxrate(sr->isr_rates, sr->isr_nrates)
			, sr->isr_rssi, sr->isr_noise
			, sr->isr_intval
			, getcaps(sr->isr_capinfo)
		);

== src/usr.sbin/sysinst/net.c:1200-1209, 1233-1276 (how the installer joins a network)
		 * Start dhcpcd quietly and in master mode, but restrict
		 * it to our interface
		 */
		add_rc_conf("dhcpcd=YES\n");
		add_rc_conf("dhcpcd_flags=\"-qM %s\"\n", net_dev);
        }

	if (net_ssid[0] != '\0') {
		add_rc_conf("wpa_supplicant=YES\n");
		add_rc_conf("wpa_supplicant_flags=\"-B -s -i %s -D bsd -c /etc/wpa_supplicant.conf\"\n", net_dev);
	msg_prompt_add(MSG_net_ssid, net_ssid, net_ssid,
			sizeof net_ssid);
	if (net_ssid[0] == '\0')
		return 0;

	msg_prompt_noecho(MSG_net_passphrase, net_passphrase, net_passphrase,
			sizeof net_passphrase);

	wpa_conf = fopen("/etc/wpa_supplicant.conf", "a");
	if (wpa_conf == NULL)
		return 0;

	scripting_fprintf(NULL,
	    "cat <<EOF >>%s/etc/wpa_supplicant.conf\n",
	    target_prefix());
	scripting_fprintf(wpa_conf, "\n#\n");
	scripting_fprintf(wpa_conf, "# Added by NetBSD sysinst\n");
	scripting_fprintf(wpa_conf, "#\n");
	scripting_fprintf(wpa_conf, "network={\n");
	scripting_fprintf(wpa_conf,
	    "\tssid=\"%s\"\n", net_ssid);
	if (net_passphrase[0] != '\0') {
		scripting_fprintf(wpa_conf, "\tpsk=\"%s\"\n",
		    net_passphrase);
	} else {
		scripting_fprintf(wpa_conf, "\tkey_mgmt=NONE\n");
	}
	scripting_fprintf(wpa_conf, "\tscan_ssid=1\n");
	scripting_fprintf(wpa_conf, "}\n");
	(void)fclose(wpa_conf);
	scripting_fprintf(NULL, "EOF\n");

	if (run_program(RUN_DISPLAY | RUN_PROGRESS,
	    "/sbin/ifconfig %s up", inter) != 0)
		return 0;

	/*
	 * have to use system() here to avoid the server process dying
	 */
	if (snprintf(wpa_cmd, sizeof(wpa_cmd),
	    WPA_SUPPLICANT
	    " -B -s -i %s -D bsd -c /etc/wpa_supplicant.conf", inter) < 0)
		return 0;
	(void)do_system(wpa_cmd);

== src/etc/rc.d/wpa_supplicant (reload: wpa_cli reconfigure)
name="wpa_supplicant"
rcvar=$name
command="/usr/sbin/wpa_supplicant"
reload_cmd="/usr/sbin/wpa_cli reconfigure"
extra_commands="reload"
start_precmd="wpa_supplicant_precmd"

wpa_supplicant_precmd()
{
    if [ ! -d /var/run/wpa_supplicant ]; then
        mkdir -p -m 755 /var/run/wpa_supplicant
    fi
    rc_flags="-B $rc_flags"
}

load_rc_config $name

== src/etc/defaults/rc.conf:331
wpa_supplicant=NO	wpa_supplicant_flags="-Ms -c /etc/wpa_supplicant.conf"

== src/share/examples/wpa_supplicant/wpa_supplicant.conf:1-30 (ctrl_interface for wpa_cli, group wheel)
# $NetBSD: wpa_supplicant.conf,v 1.5 2023/10/10 07:21:00 nia Exp $
#
# example wpa_supplicant config
#
# please refer to the wpa_supplicant.conf man page

# wpa_cli and dhcpcd won't work well if you have no ctrl_interface set
# the value must be a directory, the sockets will be named after the interfaces
ctrl_interface=/var/run/wpa_supplicant/

# if non-root should be allowed to send wpa_supplicant commands via wpa_cli
# name a group whose members will be Allowed(tm)
ctrl_interface_group=wheel

# an unencrypted network
network={
	ssid="Freifunk"
	key_mgmt=NONE
	priority=10
}

# simple WPA-PSK, a favourite with conferences and hotel networks
network={
	ssid="SomeConference"
	key_mgmt=WPA-PSK
	psk="secretKey"
	priority=20
}

# a private WPA-PSK that doesn't broadcast its SSID
