diff --git a/bootstrap/startup.json.default b/bootstrap/startup.json.default index 6d7fab2c9f..2d3cff5226 100644 --- a/bootstrap/startup.json.default +++ b/bootstrap/startup.json.default @@ -14,8 +14,8 @@ "bind": "/sys/", "mode": "rw" }, - "/var/run/wpa_supplicant/wlan0": { - "bind": "/var/run/wpa_supplicant/wlan0", + "/var/run/wpa_supplicant": { + "bind": "/var/run/wpa_supplicant", "mode": "rw" }, "/tmp/wpa_playground": { diff --git a/core/services/wifi/main.py b/core/services/wifi/main.py index c6e950b629..f0b7bec2bb 100755 --- a/core/services/wifi/main.py +++ b/core/services/wifi/main.py @@ -4,6 +4,7 @@ import asyncio import logging import os +import stat import sys from pathlib import Path from typing import Any, List, Optional @@ -231,10 +232,29 @@ def get_hotspot_credentials() -> Any: socket_name = args.socket_name else: logger.info("Connecting via default socket.") - available_sockets = os.listdir(wpa_socket_folder) + + def is_socket(file_path: str) -> bool: + try: + mode = os.stat(file_path).st_mode + return stat.S_ISSOCK(mode) + except Exception as error: + logger.warning(f"Could not check if '{file_path}' is a socket: {error}") + return False + + # We are going to sort and get the latest file, since this in theory will be an external interface + # added by the user + entries = os.scandir(wpa_socket_folder) + available_sockets = sorted( + [ + entry.path + for entry in entries + if entry.name.startswith(("wlan", "wifi", "wlp")) and is_socket(entry.path) + ] + ) if not available_sockets: raise RuntimeError("No wifi sockets available.") - socket_name = available_sockets[0] + socket_name = available_sockets[-1] + logger.info(f"Going to use {socket_name} file") WLAN_SOCKET = os.path.join(wpa_socket_folder, socket_name) wifi_manager.connect(WLAN_SOCKET) except Exception as socket_connection_error: diff --git a/core/tools/blueos_startup_update/blueos_startup_update.py b/core/tools/blueos_startup_update/blueos_startup_update.py index 6ead85f655..c8a63a1d64 100755 --- a/core/tools/blueos_startup_update/blueos_startup_update.py +++ b/core/tools/blueos_startup_update/blueos_startup_update.py @@ -25,16 +25,17 @@ DELTA_JSON = { "core": { "binds": { - "/run/udev": {"bind": "/run/udev", "mode": "ro"}, "/etc/blueos": {"bind": "/etc/blueos", "mode": "rw"}, - "/etc/machine-id": {"bind": "/etc/machine-id", "mode": "ro"}, "/etc/dhcpcd.conf": {"bind": "/etc/dhcpcd.conf", "mode": "rw"}, - "/usr/blueos/userdata": {"bind": "/usr/blueos/userdata", "mode": "rw"}, - "/usr/blueos/extensions": {"bind": "/usr/blueos/extensions", "mode": "rw"}, - "/usr/blueos/bin": {"bind": "/usr/blueos/bin", "mode": "rw"}, + "/etc/machine-id": {"bind": "/etc/machine-id", "mode": "ro"}, "/etc/resolv.conf.host": {"bind": "/etc/resolv.conf.host", "mode": "ro"}, "/home/pi/.ssh": {"bind": "/home/pi/.ssh", "mode": "rw"}, + "/run/udev": {"bind": "/run/udev", "mode": "ro"}, "/sys/": {"bind": "/sys/", "mode": "rw"}, + "/usr/blueos/bin": {"bind": "/usr/blueos/bin", "mode": "rw"}, + "/usr/blueos/extensions": {"bind": "/usr/blueos/extensions", "mode": "rw"}, + "/usr/blueos/userdata": {"bind": "/usr/blueos/userdata", "mode": "rw"}, + "/var/run/wpa_supplicant": {"bind": "/var/run/wpa_supplicant", "mode": "rw"}, } } }