Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/networking.py
diff options
context:
space:
mode:
authorAnton Hvornum <anton@hvornum.se>2021-01-25 23:32:10 +0100
committerGitHub <noreply@github.com>2021-01-25 23:32:10 +0100
commit190ec7ad42bc59b7238b77dc4d7f3128e2f1eb78 (patch)
treecb8cf3e77dd59bd3a3dc3eb630934d34fef2376f /archinstall/lib/networking.py
parent0c92710c56eb29b43e08e8623b2c893e1ee5e2dc (diff)
parent3db8e3abbc8133ecb1875465f5cb3a1ea8557e86 (diff)
Merge pull request #96 from Torxed/hardware-n-wifi
Added wifi-configuration support (basic) by copying existing `iwd` configurations. Also added some hardware detection helpers such as `UEFI` detection and wifi hardware as well as detection for three common graphic cards.
Diffstat (limited to 'archinstall/lib/networking.py')
-rw-r--r--archinstall/lib/networking.py49
1 files changed, 47 insertions, 2 deletions
diff --git a/archinstall/lib/networking.py b/archinstall/lib/networking.py
index 4829a58b..882bcff3 100644
--- a/archinstall/lib/networking.py
+++ b/archinstall/lib/networking.py
@@ -1,8 +1,11 @@
+import os
import fcntl
import socket
import struct
from collections import OrderedDict
-
+from .exceptions import *
+from .general import sys_command
+from .storage import storage
def getHwAddr(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -19,5 +22,47 @@ def list_interfaces(skip_loopback=True):
interfaces[mac] = iface
return interfaces
+def enrichIfaceTypes(interfaces :dict):
+ result = {}
+ for iface in interfaces:
+ if os.path.isdir(f"/sys/class/net/{iface}/bridge/"):
+ result[iface] = 'BRIDGE'
+ elif os.path.isfile(f"/sys/class/net/{iface}/tun_flags"):
+ # ethtool -i {iface}
+ result[iface] = 'TUN/TAP'
+ elif os.path.isdir(f"/sys/class/net/{iface}/device"):
+ if os.path.isdir(f"/sys/class/net/{iface}/wireless/"):
+ result[iface] = 'WIRELESS'
+ else:
+ result[iface] = 'PHYSICAL'
+ else:
+ result[iface] = 'UNKNOWN'
+ return result
+
def get_interface_from_mac(mac):
- return list_interfaces().get(mac.lower(), None) \ No newline at end of file
+ return list_interfaces().get(mac.lower(), None)
+
+def wirelessScan(interface):
+ interfaces = enrichIfaceTypes(list_interfaces().values())
+ if interfaces[interface] != 'WIRELESS':
+ raise HardwareIncompatibilityError(f"Interface {interface} is not a wireless interface: {interfaces}")
+
+ sys_command(f"iwctl station {interface} scan")
+
+ if not '_WIFI' in storage:
+ storage['_WIFI'] = {}
+ if not interface in storage['_WIFI']:
+ storage['_WIFI'][interface] = {}
+
+ storage['_WIFI'][interface]['scanning'] = True
+
+# TOOD: Full WiFi experience might get evolved in the future, pausing for now 2021-01-25
+def getWirelessNetworks(interface):
+ # TODO: Make this oneliner pritter to check if the interface is scanning or not.
+ if not '_WIFI' in storage or interface not in storage['_WIFI'] or storage['_WIFI'][interface].get('scanning', False) is False:
+ import time
+ wirelessScan(interface)
+ time.sleep(5)
+
+ for line in sys_command(f"iwctl station {interface} get-networks"):
+ print(line) \ No newline at end of file