2021-06-27 14:25:36 +05:30
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
"""Manage wifi adapter via iwd D-Bus api"""
|
|
|
|
|
2021-06-30 21:50:39 +05:30
|
|
|
from dasbus.connection import SystemMessageBus
|
|
|
|
|
|
|
|
IWD_BUS = "net.connman.iwd"
|
|
|
|
IWD_ROOT_PATH = "/"
|
|
|
|
|
|
|
|
# If you are new to D-Bus, you might want to use a program
|
|
|
|
# such as D-Feet (https://wiki.gnome.org/Apps/DFeet) for reference.
|
|
|
|
|
2021-06-27 14:25:36 +05:30
|
|
|
|
|
|
|
class IWD:
|
|
|
|
"""Manage iwd via dbus"""
|
|
|
|
|
2021-06-30 21:50:39 +05:30
|
|
|
def __init__(self, bus=SystemMessageBus()):
|
|
|
|
self._bus = bus
|
|
|
|
self._proxy = self._bus.get_proxy(IWD_BUS, IWD_ROOT_PATH)
|
|
|
|
|
|
|
|
def get_name_from_path(self, path: str) -> str:
|
|
|
|
"""returns device name when d-bus path is given as arg"""
|
|
|
|
|
|
|
|
def get_device_path_from_name(self, name: str) -> str:
|
|
|
|
"""returns path of device as str"""
|
|
|
|
|
|
|
|
def get_adapter_path_from_name(self, name: str) -> str:
|
|
|
|
"""returns path of adapter as str"""
|
|
|
|
|
|
|
|
def get_all_object_paths(self) -> list:
|
|
|
|
"""returns a list of path names of all objects"""
|
2021-06-27 14:25:36 +05:30
|
|
|
|
2021-06-30 21:50:39 +05:30
|
|
|
def get_all_device_paths(self) -> list:
|
|
|
|
"""returns list of paths of all devices"""
|
|
|
|
|
|
|
|
def get_all_adapter_paths(self) -> list:
|
|
|
|
"""returns list of paths of all adapters"""
|
|
|
|
|
|
|
|
def get_devices(self) -> list:
|
2021-06-27 14:25:36 +05:30
|
|
|
"""
|
|
|
|
returns list of device names as str
|
|
|
|
example: ["wlan0", "wlan1"]
|
|
|
|
"""
|
|
|
|
|
2021-06-30 21:50:39 +05:30
|
|
|
def get_adapters(self) -> list:
|
2021-06-27 14:25:36 +05:30
|
|
|
"""
|
|
|
|
returns list of adapters
|
|
|
|
example: ["phy0","phy1"]
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
class Device:
|
|
|
|
"""control devices with iwd"""
|
|
|
|
|
2021-06-30 21:50:39 +05:30
|
|
|
def __init__(self, name: str, bus=SystemMessageBus()):
|
|
|
|
self._iwd = IWD(bus)
|
|
|
|
self._bus = self._iwd._bus
|
|
|
|
self._path = self._iwd.get_path_from_name(name)
|
|
|
|
self._proxy = self._bus.get_proxy(IWD_BUS, self._path)
|
|
|
|
self.name = self._proxy.Name
|
|
|
|
|
|
|
|
def get_mode(self) -> str:
|
|
|
|
"""
|
|
|
|
returns the mode in which the device is in
|
|
|
|
example: "ap"
|
|
|
|
"""
|
|
|
|
return self._proxy.Mode
|
|
|
|
|
|
|
|
def get_adapter_name(self) -> str:
|
|
|
|
"""returns the name of the adapter as str"""
|