|
|
|
@@ -20,6 +20,7 @@ log = getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
ConfigVariable = namedtuple("ConfigVariable", ["name", "value", "line_index"])
|
|
|
|
ConfigVariable = namedtuple("ConfigVariable", ["name", "value", "line_index"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LINUX_BT_CLASS_PATH = "/sys/class/bluetooth"
|
|
|
|
LINUX_WIFI_CLASS_PATH = "/sys/class/ieee80211"
|
|
|
|
LINUX_WIFI_CLASS_PATH = "/sys/class/ieee80211"
|
|
|
|
CONFIG_TXT_LOCATIONS = ("/boot/firmware/config.txt", "/boot/config.txt")
|
|
|
|
CONFIG_TXT_LOCATIONS = ("/boot/firmware/config.txt", "/boot/config.txt")
|
|
|
|
|
|
|
|
|
|
|
|
@@ -44,11 +45,9 @@ class RevPiConfig:
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
def __init__(self):
|
|
|
|
self._cm_type = ComputeModuleTypes.UNKNOWN
|
|
|
|
self._cm_type = ComputeModuleTypes.UNKNOWN
|
|
|
|
self._cm_with_wifi = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self._revpi_with_con_bridge = False
|
|
|
|
self._revpi_with_con_bridge = False
|
|
|
|
self._wlan_class_path = ""
|
|
|
|
self._wlan_class_path = ""
|
|
|
|
self._wlan_rfkill_index = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
self.serial = ""
|
|
|
|
self.serial = ""
|
|
|
|
self.model = ""
|
|
|
|
self.model = ""
|
|
|
|
@@ -86,26 +85,16 @@ class RevPiConfig:
|
|
|
|
could_have_wifi = self._cm_type in (ComputeModuleTypes.CM4, ComputeModuleTypes.CM5)
|
|
|
|
could_have_wifi = self._cm_type in (ComputeModuleTypes.CM4, ComputeModuleTypes.CM5)
|
|
|
|
if could_have_wifi:
|
|
|
|
if could_have_wifi:
|
|
|
|
wifi_interface = join(LINUX_WIFI_CLASS_PATH, "phy0")
|
|
|
|
wifi_interface = join(LINUX_WIFI_CLASS_PATH, "phy0")
|
|
|
|
lst_grep = grep("DRIVER=brcmfmac", join(wifi_interface, "device", "uevent"))
|
|
|
|
if grep("DRIVER=brcmfmac", join(wifi_interface, "device", "uevent")):
|
|
|
|
self._cm_with_wifi = len(lst_grep) > 0
|
|
|
|
|
|
|
|
self._wlan_class_path = wifi_interface
|
|
|
|
self._wlan_class_path = wifi_interface
|
|
|
|
|
|
|
|
|
|
|
|
# If no build in Wi-Fi on the CM, detect third party Wi-Fi on RevPi Flat
|
|
|
|
# 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/*")
|
|
|
|
lst_wifi_interfaces = glob("/sys/class/ieee80211/*")
|
|
|
|
for wifi_interface in lst_wifi_interfaces:
|
|
|
|
for wifi_interface in lst_wifi_interfaces:
|
|
|
|
if grep("DRIVER=mwifiex_sdio", join(wifi_interface, "device", "uevent")):
|
|
|
|
if grep("DRIVER=mwifiex_sdio", join(wifi_interface, "device", "uevent")):
|
|
|
|
self._cm_with_wifi = True
|
|
|
|
|
|
|
|
self._wlan_class_path = wifi_interface
|
|
|
|
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
|
|
|
|
# Detect ConBridge
|
|
|
|
could_have_con_bridge = self._cm_type in (ComputeModuleTypes.CM3, ComputeModuleTypes.CM4S)
|
|
|
|
could_have_con_bridge = self._cm_type in (ComputeModuleTypes.CM3, ComputeModuleTypes.CM4S)
|
|
|
|
if could_have_con_bridge:
|
|
|
|
if could_have_con_bridge:
|
|
|
|
@@ -113,12 +102,12 @@ class RevPiConfig:
|
|
|
|
self._revpi_with_con_bridge = len(lst_grep) > 0
|
|
|
|
self._revpi_with_con_bridge = len(lst_grep) > 0
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def cm_type(self) -> ComputeModuleTypes:
|
|
|
|
def class_path_wifi(self) -> str:
|
|
|
|
return self._cm_type
|
|
|
|
return self._wlan_class_path
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def rfkill_index(self) -> Optional[int]:
|
|
|
|
def cm_type(self) -> ComputeModuleTypes:
|
|
|
|
return self._wlan_rfkill_index
|
|
|
|
return self._cm_type
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def with_con_bridge(self) -> bool:
|
|
|
|
def with_con_bridge(self) -> bool:
|
|
|
|
@@ -126,7 +115,7 @@ class RevPiConfig:
|
|
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@property
|
|
|
|
def with_wifi(self) -> bool:
|
|
|
|
def with_wifi(self) -> bool:
|
|
|
|
return self._cm_with_wifi
|
|
|
|
return bool(self._wlan_class_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ConfigTxt:
|
|
|
|
class ConfigTxt:
|
|
|
|
@@ -224,6 +213,40 @@ def configure_avahi_daemon(action: ConfigActions):
|
|
|
|
return return_value
|
|
|
|
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):
|
|
|
|
def configure_con_can(action: ConfigActions):
|
|
|
|
revpi = RevPiConfig()
|
|
|
|
revpi = RevPiConfig()
|
|
|
|
if action is ConfigActions.AVAILABLE:
|
|
|
|
if action is ConfigActions.AVAILABLE:
|
|
|
|
@@ -314,6 +337,47 @@ def configure_gui(action: ConfigActions):
|
|
|
|
raise ValueError(f"action {action} not supported")
|
|
|
|
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):
|
|
|
|
def simple_systemd(action: ConfigActions, unit: str):
|
|
|
|
bus = SystemBus()
|
|
|
|
bus = SystemBus()
|
|
|
|
systemd_manager = bus.get(".systemd1")
|
|
|
|
systemd_manager = bus.get(".systemd1")
|
|
|
|
@@ -358,7 +422,8 @@ if __name__ == "__main__":
|
|
|
|
print("CM Type: ", rc.cm_type.name)
|
|
|
|
print("CM Type: ", rc.cm_type.name)
|
|
|
|
print("With wifi: ", rc.with_wifi)
|
|
|
|
print("With wifi: ", rc.with_wifi)
|
|
|
|
if 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)
|
|
|
|
print("With con-bridge:", rc.with_con_bridge)
|
|
|
|
|
|
|
|
|
|
|
|
config_txt = ConfigTxt()
|
|
|
|
config_txt = ConfigTxt()
|
|
|
|
|