diff --git a/HACKING.md b/HACKING.md index ad2d033..ccac949 100644 --- a/HACKING.md +++ b/HACKING.md @@ -1,6 +1,9 @@ # Hacking -## Reporting issues and ideas +Everyone is welcome to [hack][] naxalnet. +See below for how to hack. + +## Reporting issues and suggesting ideas To report a bug or suggest an idea, create a new issue at with a @@ -21,3 +24,5 @@ your username to: naxalnet needs distro packages in Debian, Fedora, openSUSE, and nixos. If you know/like to package it to your distro, post to issue #6. + +[hack]: https://catb.org/jargon/html/H/hack.html diff --git a/naxalnet/iwd.py b/naxalnet/iwd.py index ffe68cc..5a18f40 100644 --- a/naxalnet/iwd.py +++ b/naxalnet/iwd.py @@ -17,7 +17,12 @@ class IWD: """Manage iwd via dbus""" def __init__(self, bus=SystemMessageBus()): + # self._bus and self._proxy are meant for use only in this file self._bus = bus + self.reload() + + def reload(self): + """reload the proxy""" self._proxy = self._bus.get_proxy(IWD_BUS, IWD_ROOT_PATH) def get_name_from_path(self, path: str) -> str: @@ -32,6 +37,7 @@ class IWD: proxy = self._bus.get_proxy(IWD_BUS, i) if proxy.Name == name: return i + # If no devices were found, return None return None def get_adapter_path_from_name(self, name: str) -> str: @@ -41,6 +47,7 @@ class IWD: proxy = self._bus.get_proxy(IWD_BUS, i) if proxy.Name == name: return i + # If no adapters were found return None def get_all_device_paths(self) -> list: @@ -92,20 +99,38 @@ class IWD: class Device: - """control devices with iwd""" + """ + control devices with iwd + name: name of device + adapter: name of adapter (str) + """ def __init__(self, name: str, bus=SystemMessageBus()): self._iwd = IWD(bus) self._bus = self._iwd._bus self._path = self._iwd.get_device_path_from_name(name) - self._proxy = self._bus.get_proxy(IWD_BUS, self._path) + self.reload() self.name = self._proxy.Name adapter_path = self._proxy.Adapter self.adapter = self._iwd.get_name_from_path(adapter_path) + def reload(self): + """reload the proxy after changing mode""" + self._proxy = self._bus.get_proxy(IWD_BUS, self._path) + def get_mode(self) -> str: """ returns the mode in which the device is in example: "ap" """ return self._proxy.Mode + + def set_mode(self, mode: str): + """change the device mode to mode""" + self._proxy.Mode = mode + self.reload() + + def start_adhoc_open(self, name): + if self.get_mode() != "ad-hoc": + self.set_mode("ad-hoc") + # TODO: connect to network