Skip to contentSkip to conversation

Configure default wifi through kconfig

PATCH Superseded Angelo Compagnucci 1 participant 6 messages Jun 28, 2022

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Configure default wifi through kconfig

This series was born while adding support for a board and feeling the necessity to have the networking options available in .config. I understand that something like that could be done by adding an overlay, but it requires a lot of boilerplate only to be able to connect to a wifi network.

Angelo Compagnucci (5):
system: adding options for configuring wifi package/wpa_supplicant: configure wifi on systemv when enabled package/wpa_supplicant: configure wifi on systemd when enabled package/ifupdown-scripts: add wifi configuration when enabled package/initscripts: add service to load kernel modules at boot

 package/ifupdown-scripts/ifupdown-scripts.mk |  2 +
 package/initscripts/init.d/S11modules        | 59 ++++++++++++++++++++
 package/wpa_supplicant/wpa_supplicant.mk     | 24 ++++++++
 system/Config.in                             | 16 ++++++
 4 files changed, 101 insertions(+)
 create mode 100644 package/initscripts/init.d/S11modules
Signature · 6 lines
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

PATCH v2 1/5 system: adding options for configuring wifi

These options can be used by packages to configure a wifi card to connect at boot.

---
 system/Config.in | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
system/Config.in +15 -0
index 888c24ce81..9a5bdb2932 100644
@@ -418,6 +418,21 @@ comment "automatic network configuration via DHCP needs ifupdown or busybox or n
 	depends on !(BR2_PACKAGE_BUSYBOX || BR2_PACKAGE_IFUPDOWN || \
 		BR2_PACKAGE_SYSTEMD_NETWORKD || BR2_PACKAGE_NETIFRC)
 
+config BR2_SYSTEM_CONNECT_WIFI
+	bool "Connect to a default wifi access point"
+	default n
+	depends on BR2_PACKAGE_WPA_SUPPLICANT
+
+config BR2_SYSTEM_CONNECT_WIFI_SSID
+	string "Access point SSID"
+	default ""
+	depends on BR2_SYSTEM_CONNECT_WIFI
+
+config BR2_SYSTEM_CONNECT_WIFI_PASSWORD
+	string "Access point password"
+	default ""
+	depends on BR2_SYSTEM_CONNECT_WIFI
+
 endif # BR2_ROOTFS_SKELETON_DEFAULT
 
 config BR2_SYSTEM_DEFAULT_PATH
Signature · 6 lines
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw

PATCH v2 2/5 package/wpa_supplicant: configure wifi on systemv when enabled

In reply to Angelo Compagnucci

Configure a default basic wifi setup able to automatically connect to the selected access point.

---
 package/wpa_supplicant/wpa_supplicant.mk | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
package/wpa_supplicant/wpa_supplicant.mk +14 -0
index afcd6502e3..09971654fe 100644
@@ -264,6 +264,19 @@ define WPA_SUPPLICANT_INSTALL_IFUP_SCRIPTS
 endef
 endif
 
+ifeq ($(BR2_SYSTEM_CONNECT_WIFI),y)
+define WPA_SUPPLICANT_ENABLE_WIFI
+	$(SED) '/network={/,/}/d' $(TARGET_DIR)/etc/wpa_supplicant.conf; \
+	(	echo "network={"; \
+		echo "  scan_ssid=1"; \
+		echo "  key_mgmt=WPA-PSK"; \
+		echo "  ssid=\"$(BR2_SYSTEM_CONNECT_WIFI_SSID)\""; \
+		echo "  psk=\"$(BR2_SYSTEM_CONNECT_WIFI_PASSWORD)\""; \
+		echo "}"; \
+	) >> $(TARGET_DIR)/etc/wpa_supplicant.conf
+endef
+endif
+
 define WPA_SUPPLICANT_INSTALL_TARGET_CMDS
 	$(INSTALL) -m 0755 -D $(@D)/$(WPA_SUPPLICANT_SUBDIR)/wpa_supplicant \
 		$(TARGET_DIR)/usr/sbin/wpa_supplicant
@@ -275,6 +288,7 @@ define WPA_SUPPLICANT_INSTALL_TARGET_CMDS
 	$(WPA_SUPPLICANT_INSTALL_WPA_CLIENT_SO)
 	$(WPA_SUPPLICANT_INSTALL_IFUP_SCRIPTS)
 	$(WPA_SUPPLICANT_ENABLE_CTRL_IFACE)
+	$(WPA_SUPPLICANT_ENABLE_WIFI)
 endef
 
 define WPA_SUPPLICANT_INSTALL_INIT_SYSTEMD
Signature · 6 lines
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#3 lore raw

PATCH v2 3/5 package/wpa_supplicant: configure wifi on systemd when enabled

In reply to Angelo Compagnucci

Configure a default basic wifi setup able to automatically connect to the selected access point.

---
 package/wpa_supplicant/wpa_supplicant.mk | 10 ++++++++++
 system/Config.in                         |  1 +
 2 files changed, 11 insertions(+)
package/wpa_supplicant/wpa_supplicant.mk +10 -0
index 09971654fe..157d45ee7f 100644
@@ -275,6 +275,15 @@ define WPA_SUPPLICANT_ENABLE_WIFI
 		echo "}"; \
 	) >> $(TARGET_DIR)/etc/wpa_supplicant.conf
 endef
+define WPA_SUPPLICANT_WIFI_INSTALL_INIT_SYSTEMD
+	$(INSTALL) -m 0755 -d $(TARGET_DIR)/etc/wpa_supplicant/
+	ln -sf ../wpa_supplicant.conf \
+		$(TARGET_DIR)/etc/wpa_supplicant/wpa_supplicant-$(BR2_SYSTEM_DHCP).conf
+endef
+define WPA_SUPPLICANT_WIFI_INSTALL_INIT_SYSTEMD_PRESET
+	$(HOST_DIR)/bin/systemctl --root=$(TARGET_DIR) preset wpa_supplicant\@$(BR2_SYSTEM_DHCP).service
+endef
+SYSTEMD_ROOTFS_PRE_CMD_HOOKS += WPA_SUPPLICANT_WIFI_INSTALL_INIT_SYSTEMD_PRESET
 endif
 
 define WPA_SUPPLICANT_INSTALL_TARGET_CMDS
@@ -302,6 +311,7 @@ define WPA_SUPPLICANT_INSTALL_INIT_SYSTEMD
 		$(TARGET_DIR)/usr/lib/systemd/system/[email protected]
 	$(INSTALL) -D -m 644 $(WPA_SUPPLICANT_PKGDIR)/50-wpa_supplicant.preset \
 		$(TARGET_DIR)/usr/lib/systemd/system-preset/50-wpa_supplicant.preset
+	$(WPA_SUPPLICANT_WIFI_INSTALL_INIT_SYSTEMD)
 endef
 
 $(eval $(generic-package))
system/Config.in +1 -0
index 9a5bdb2932..084340b1a4 100644
@@ -422,6 +422,7 @@ config BR2_SYSTEM_CONNECT_WIFI
 	bool "Connect to a default wifi access point"
 	default n
 	depends on BR2_PACKAGE_WPA_SUPPLICANT
+	select BR2_PACKAGE_WPA_SUPPLICANT_CTRL_IFACE if BR2_PACKAGE_SYSTEMD
 
 config BR2_SYSTEM_CONNECT_WIFI_SSID
 	string "Access point SSID"
Signature · 6 lines
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#4 lore raw

PATCH v2 4/5 package/ifupdown-scripts: add wifi configuration when enabled

In reply to Angelo Compagnucci

Add a proper wpa-conf line to the interfaces files to let the system bringup the wifi interface and the related wpa supplicant.

---
 package/ifupdown-scripts/ifupdown-scripts.mk | 2 ++
 1 file changed, 2 insertions(+)
package/ifupdown-scripts/ifupdown-scripts.mk +2 -0
index 5ef032142c..e3830aa1ad 100644
@@ -28,6 +28,8 @@ define IFUPDOWN_SCRIPTS_DHCP
 		echo "  pre-up /etc/network/nfs_check"; \
 		echo "  wait-delay 15"; \
 		echo "  hostname \$$(hostname)"; \
+		test -n "$(BR2_SYSTEM_CONNECT_WIFI)" && \
+			echo "  wpa-conf /etc/wpa_supplicant.conf"; \
 	) >> $(TARGET_DIR)/etc/network/interfaces
 endef
 define IFUPDOWN_SCRIPTS_DHCP_OPENRC
Signature · 6 lines
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#5 lore raw

PATCH v2 5/5 package/initscripts: add service to load kernel modules at boot

In reply to Angelo Compagnucci

In cases where no hotplug is available (by choice or by the lack of a proper hotplug method for a device), this service can be used to load kernel module drivers by reading the /etc/modules file.
The modules files matches the one used by systemd, which in turn has a builtin mechanism to load a module at boot, therefore making systemv init on par with systemd features.

---
Changes

v2:
* Moved script to initscripts (Arnout)
* Moved script to S11modules, after S10[mu]dev (Andreas)
* Use /etc/modules-load.d/ to share the same setup with systemd (me)

 package/initscripts/init.d/S11modules | 59 +++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 package/initscripts/init.d/S11modules
package/initscripts/init.d/S11modules new file +59 -0
new file mode 100644
index 0000000000..3937945596
@@ -0,0 +1,59 @@
+#!/bin/sh
+
+MODULES="*.conf"
+MODULES_DIR="/etc/modules-load.d"
+
+[ -z "$(ls -A ${MODULES_DIR}/${MODULES} 2> /dev/null)" ] && exit 0
+
+load_unload() {
+	for module_file in $(ls -1 ${MODULES_DIR}); do
+		while read module args; do
+
+			case "$module" in
+				""|"#"*) continue ;;
+			esac
+
+			if [ "$1" = "load" ]; then
+				modprobe -q ${module} ${args} >/dev/null && \
+					printf ' %s success,' "$module" ||
+					printf ' %s failed,' "$module"
+			else
+				rmmod ${module} >/dev/null
+			fi
+
+		done < ${MODULES_DIR}/${module_file}
+	done
+}
+
+start() {
+	printf 'Starting modules:'
+
+	load_unload load
+
+	echo ' OK'
+}
+
+stop() {
+	printf 'Stopping modules:'
+
+	load_unload unload
+
+	echo 'OK'
+}
+
+restart() {
+	stop
+	sleep 1
+	start
+}
+
+case "$1" in
+	start|stop|restart)
+		"$1";;
+	reload)
+		# Restart, since there is no true "reload" feature.
+		restart;;
+	*)
+		echo "Usage: $0 {start|stop|restart|reload}"
+		exit 1
+esac
Signature · 6 lines
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot