added AP support in naxalnet.py and iwd.py

This commit is contained in:
Pranav Jerry 2021-07-21 14:36:23 +05:30
parent af5fc0e285
commit b2f30bad62
Signed by: pranav
GPG Key ID: F1DCDC4FED0A0C5B
2 changed files with 32 additions and 7 deletions

View File

@ -188,7 +188,8 @@ class Device:
def start_adhoc_open(self, name: str):
"""
Create ad-hoc network with name, changing mode to ad-hoc
if it isn't already on ad-hoc
if it isn't already on ad-hoc and power onn the device
if it is off
"""
if self.get_mode() != "ad-hoc":
self.set_mode("ad-hoc")
@ -196,8 +197,8 @@ class Device:
if not self.is_powered_on():
self.power_on()
if self.is_adhoc_started():
self.stop_adhoc()
# Stop adhoc if already started
self.stop_adhoc()
self._proxy.StartOpen(name)
@ -207,6 +208,29 @@ class Device:
self._proxy.Stop()
self.reload()
def start_ap(self, ssid, passwd):
"""
Create ap network, changing mode to ap
if it isn't already on ap and turning
on the device if it is off
"""
if self.get_mode() != "ap":
self.set_mode("ap")
if not self.is_powered_on():
self.power_on()
# Stop ap if already started
self.stop_ap()
self._proxy.Start(ssid, passwd)
def stop_ap(self):
"""stop ap if an ap is started"""
if self.is_ap_started():
self._proxy.Stop()
self.reload()
class Adapter:
"""represents an adapter as a python object"""
@ -243,7 +267,7 @@ class Adapter:
def supports_mode(self, mode: str) -> bool:
"""
Returns True if the adapter supports the mode
Returns True if the adapter supports the mode.
mode can be "ad-hoc", "ap" or "station"
"""
return mode in self.supported_modes

View File

@ -82,10 +82,11 @@ try:
# ie, we have more devices
if len(ap_devices) != 0:
print("Working on AP")
ap_device = ap_devices.pop()
ap_device = Device(ap_devices.pop())
# _TODO: start ap after implementing in in iwd.py
except DBusError as e:
print(e)
ap_device.start_ap(AP_SSID, AP_PASSWD)
except DBusError as error:
print(error)
sys.exit("An error occured while communicating with iwd")
print("Bye")