Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
604cb61870 | ||
|
|
69e370f964 | ||
|
|
6eb7eeea40 |
@@ -8,10 +8,12 @@ from logging import getLogger
|
||||
from .revpi_config import (
|
||||
ConfigActions,
|
||||
configure_avahi_daemon,
|
||||
configure_bluetooth,
|
||||
configure_con_can,
|
||||
configure_dphys_swapfile,
|
||||
configure_external_antenna,
|
||||
configure_gui,
|
||||
configure_wifi,
|
||||
simple_systemd,
|
||||
)
|
||||
from ..dbus_helper import DbusInterface
|
||||
@@ -91,8 +93,8 @@ AVAILABLE_FEATURES = {
|
||||
simple_systemd, ["noderedrevpinodes-server.service"]
|
||||
),
|
||||
"revpipyload": FeatureFunction(simple_systemd, ["revpipyload.service"]),
|
||||
"bluetooth": False,
|
||||
"ieee80211": False,
|
||||
"bluetooth": FeatureFunction(configure_bluetooth, []),
|
||||
"ieee80211": FeatureFunction(configure_wifi, []),
|
||||
"avahi": FeatureFunction(configure_avahi_daemon, []),
|
||||
"external-antenna": FeatureFunction(configure_external_antenna, []),
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ log = getLogger(__name__)
|
||||
|
||||
ConfigVariable = namedtuple("ConfigVariable", ["name", "value", "line_index"])
|
||||
|
||||
LINUX_BT_CLASS_PATH = "/sys/class/bluetooth"
|
||||
LINUX_WIFI_CLASS_PATH = "/sys/class/ieee80211"
|
||||
CONFIG_TXT_LOCATIONS = ("/boot/firmware/config.txt", "/boot/config.txt")
|
||||
|
||||
@@ -44,11 +45,9 @@ class RevPiConfig:
|
||||
|
||||
def __init__(self):
|
||||
self._cm_type = ComputeModuleTypes.UNKNOWN
|
||||
self._cm_with_wifi = False
|
||||
|
||||
self._revpi_with_con_bridge = False
|
||||
self._wlan_class_path = ""
|
||||
self._wlan_rfkill_index = None
|
||||
|
||||
self.serial = ""
|
||||
self.model = ""
|
||||
@@ -86,26 +85,16 @@ class RevPiConfig:
|
||||
could_have_wifi = self._cm_type in (ComputeModuleTypes.CM4, ComputeModuleTypes.CM5)
|
||||
if could_have_wifi:
|
||||
wifi_interface = join(LINUX_WIFI_CLASS_PATH, "phy0")
|
||||
lst_grep = grep("DRIVER=brcmfmac", join(wifi_interface, "device", "uevent"))
|
||||
self._cm_with_wifi = len(lst_grep) > 0
|
||||
if grep("DRIVER=brcmfmac", join(wifi_interface, "device", "uevent")):
|
||||
self._wlan_class_path = wifi_interface
|
||||
|
||||
# If no build in Wi-Fi on the CM, detect third party Wi-Fi on RevPi Flat
|
||||
if not self._cm_with_wifi and grep("revpi-flat", "/proc/device-tree/compatible"):
|
||||
if not self._wlan_class_path and grep("revpi-flat", "/proc/device-tree/compatible"):
|
||||
lst_wifi_interfaces = glob("/sys/class/ieee80211/*")
|
||||
for wifi_interface in lst_wifi_interfaces:
|
||||
if grep("DRIVER=mwifiex_sdio", join(wifi_interface, "device", "uevent")):
|
||||
self._cm_with_wifi = True
|
||||
self._wlan_class_path = wifi_interface
|
||||
|
||||
# Detect rfkill index of the integrated Wi-Fi device
|
||||
if self._wlan_class_path:
|
||||
for rfkill_path in glob(join(self._wlan_class_path, "rfkill*")):
|
||||
match_index = re.match(r"^/.+/rfkill(?P<index>\d+)$", rfkill_path)
|
||||
if match_index:
|
||||
self._wlan_rfkill_index = int(match_index.group("index"))
|
||||
break
|
||||
|
||||
# Detect ConBridge
|
||||
could_have_con_bridge = self._cm_type in (ComputeModuleTypes.CM3, ComputeModuleTypes.CM4S)
|
||||
if could_have_con_bridge:
|
||||
@@ -113,12 +102,12 @@ class RevPiConfig:
|
||||
self._revpi_with_con_bridge = len(lst_grep) > 0
|
||||
|
||||
@property
|
||||
def cm_type(self) -> ComputeModuleTypes:
|
||||
return self._cm_type
|
||||
def class_path_wifi(self) -> str:
|
||||
return self._wlan_class_path
|
||||
|
||||
@property
|
||||
def rfkill_index(self) -> Optional[int]:
|
||||
return self._wlan_rfkill_index
|
||||
def cm_type(self) -> ComputeModuleTypes:
|
||||
return self._cm_type
|
||||
|
||||
@property
|
||||
def with_con_bridge(self) -> bool:
|
||||
@@ -126,7 +115,7 @@ class RevPiConfig:
|
||||
|
||||
@property
|
||||
def with_wifi(self) -> bool:
|
||||
return self._cm_with_wifi
|
||||
return bool(self._wlan_class_path)
|
||||
|
||||
|
||||
class ConfigTxt:
|
||||
@@ -224,6 +213,40 @@ def configure_avahi_daemon(action: ConfigActions):
|
||||
return return_value
|
||||
|
||||
|
||||
def configure_bluetooth(action: ConfigActions):
|
||||
hci_device = join(LINUX_BT_CLASS_PATH, "hci0")
|
||||
bt_rfkill_index = get_rfkill_index(hci_device)
|
||||
|
||||
# If the bluetooth device is not present, the device should have been
|
||||
# brought up by revpi-bluetooth's udev rules or vendor magic (devices
|
||||
# based on CM4 and newer). Nothing we can do here, so treat the interface
|
||||
# as disabled.
|
||||
|
||||
if action is ConfigActions.ENABLE:
|
||||
if bt_rfkill_index is not None:
|
||||
subprocess.call(["rfkill", "unblock", str(bt_rfkill_index)])
|
||||
|
||||
elif action is ConfigActions.DISABLE:
|
||||
if bt_rfkill_index is not None:
|
||||
subprocess.call(["rfkill", "block", str(bt_rfkill_index)])
|
||||
|
||||
elif action is ConfigActions.STATUS:
|
||||
if bt_rfkill_index is None:
|
||||
return False
|
||||
|
||||
with open(f"/sys/class/rfkill/rfkill{bt_rfkill_index}/soft", "r") as f:
|
||||
buffer = f.read().strip()
|
||||
return buffer == "0"
|
||||
|
||||
elif action is ConfigActions.AVAILABLE:
|
||||
return bt_rfkill_index is not None
|
||||
|
||||
else:
|
||||
raise ValueError(f"action {action} not supported")
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def configure_con_can(action: ConfigActions):
|
||||
revpi = RevPiConfig()
|
||||
if action is ConfigActions.AVAILABLE:
|
||||
@@ -314,6 +337,47 @@ def configure_gui(action: ConfigActions):
|
||||
raise ValueError(f"action {action} not supported")
|
||||
|
||||
|
||||
def configure_wifi(action: ConfigActions):
|
||||
revpi = RevPiConfig()
|
||||
|
||||
if action is ConfigActions.ENABLE:
|
||||
if revpi.with_wifi:
|
||||
wifi_rfkill_index = get_rfkill_index(revpi.class_path_wifi)
|
||||
subprocess.call(["rfkill", "unblock", str(wifi_rfkill_index)])
|
||||
|
||||
elif action is ConfigActions.DISABLE:
|
||||
if revpi.with_wifi:
|
||||
wifi_rfkill_index = get_rfkill_index(revpi.class_path_wifi)
|
||||
subprocess.call(["rfkill", "block", str(wifi_rfkill_index)])
|
||||
|
||||
elif action is ConfigActions.AVAILABLE:
|
||||
return revpi.with_wifi
|
||||
|
||||
elif action is ConfigActions.STATUS:
|
||||
if not revpi.with_wifi:
|
||||
return False
|
||||
|
||||
wifi_rfkill_index = get_rfkill_index(revpi.class_path_wifi)
|
||||
with open(f"/sys/class/rfkill/rfkill{wifi_rfkill_index}/soft", "r") as f:
|
||||
buffer = f.read().strip()
|
||||
return buffer == "0"
|
||||
|
||||
else:
|
||||
raise ValueError(f"action {action} not supported")
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_rfkill_index(device_class_path: str) -> Optional[int]:
|
||||
re_rfkill_index = re.compile(r"^/.+/rfkill(?P<index>\d+)$")
|
||||
for rfkill_path in glob(join(device_class_path, "rfkill*")):
|
||||
match_index = re_rfkill_index.match(rfkill_path)
|
||||
if match_index:
|
||||
return int(match_index.group("index"))
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def simple_systemd(action: ConfigActions, unit: str):
|
||||
bus = SystemBus()
|
||||
systemd_manager = bus.get(".systemd1")
|
||||
@@ -358,7 +422,8 @@ if __name__ == "__main__":
|
||||
print("CM Type: ", rc.cm_type.name)
|
||||
print("With wifi: ", rc.with_wifi)
|
||||
if rc.with_wifi:
|
||||
print(" rfkill index: ", rc.rfkill_index)
|
||||
print(" class path: ", rc.class_path_wifi)
|
||||
print(" rfkill index: ", get_rfkill_index(rc.class_path_wifi))
|
||||
print("With con-bridge:", rc.with_con_bridge)
|
||||
|
||||
config_txt = ConfigTxt()
|
||||
|
||||
Reference in New Issue
Block a user