diff options
author | Nara Huang <nara.huang@canonical.com> | 2019-05-30 15:13:48 +0800 |
---|---|---|
committer | Nara Huang <nara.huang@canonical.com> | 2019-05-30 16:45:30 +0800 |
commit | 8914dd275f3e0dc19728aaea366666534366a0ae (patch) | |
tree | e0b704bb91d37277ec95aeb7401656085494869b | |
parent | f163933ce9e5d4411a8818073cf3ce5585e47583 (diff) |
Add function to check SMBIOS token for MAC address pass-through
-rwxr-xr-x | bin/mac-passthrough.py | 34 | ||||
-rw-r--r-- | debian/control | 3 |
2 files changed, 32 insertions, 5 deletions
diff --git a/bin/mac-passthrough.py b/bin/mac-passthrough.py index f4750d7..624d522 100755 --- a/bin/mac-passthrough.py +++ b/bin/mac-passthrough.py @@ -5,11 +5,12 @@ import subprocess import glob import os import shutil +MAC_PASS_SMBIOS_TOKEN = '0x49b' def get_system_mac(): """ Get mac addresses from ethernet devices Returns: - List: Mac addresses of ethernet devices + List: Mac addresses of ethernet devices """ mac_addresses = [] for interface in glob.glob("/sys/class/net/en*/address"): @@ -19,14 +20,15 @@ def get_system_mac(): mac = mac.strip() mac = mac.replace(':','') mac_addresses.append(mac) - except IOError as err: - print(err) + except Exception as err: + raise SystemExit(err) return mac_addresses # Since system could have multiple ethernet interfaces, the return value is a list def get_pass_through_mac(): """ Get pass-through mac address from BIOS ACPI DSDT table iasl command is included in acpica-tools package Returns: + String: Pass-through MAC address from DSDT table """ tmp_path = os.environ.get("SNAP_USER_DATA", "/tmp") aml_path = os.path.join(tmp_path, 'dsdt.aml') @@ -45,6 +47,12 @@ def get_pass_through_mac(): raise SystemExit(err) def check_mac_passthrough(mac, bios_mac): + """ Compare pass-through MAC address from BIOS DSDT table and system MAC address, + To check if the pass-through function works. + Args: + mac: A list contains MAC addresses from system + bios_mac: A string of MAC address from BIOS DSDT table + """ if len(mac) == 2 and mac[0] == mac[1]: print('AUXMAC in DSDT table is identical to onboard NIC MAC, which means in BIOS setting, it is set to "Integrated NIC 1 MAC Address".') return 0 @@ -55,7 +63,27 @@ def check_mac_passthrough(mac, bios_mac): raise SystemExit('MAC address pass-through is not working, maybe the dock is not connected?') # If a system enables mac pass-through function, but not connected with a dock, it goes here +def check_smbios_token(index): + """ Check SMBIOS for BIOS MAC address pass-through setting. + If it shows "false", then the function is enabled in BIOS setting. + This function requires command "smbios-token-ctl", which comes with package "smbios-utils" + Args: + index: A string for SMBIOS token index + """ + smbios_token_cmd = ['smbios-token-ctl', '--token-id='] + smbios_token_cmd[1] += index + try: + out = subprocess.check_output(smbios_token_cmd) + for line in out.decode("utf-8").splitlines(): + if 'value: bool' in line: + if 'true' in line: + raise SystemExit('MAC address pass-through is disabled in BIOS setting.') + except Exception as err: + raise SystemExit(err) + print('MAC address pass-through is enabled in BIOS setting.') + def main(): + check_smbios_token(MAC_PASS_SMBIOS_TOKEN) pasthrough_mac_addresses = get_pass_through_mac() os_mac_addresses = get_system_mac() check_mac_passthrough(os_mac_addresses, pasthrough_mac_addresses) diff --git a/debian/control b/debian/control index c03fba8..4df4901 100644 --- a/debian/control +++ b/debian/control @@ -17,7 +17,7 @@ Homepage: https://code.launchpad.net/~oem-qa/oem-qa-checkbox/+git/oem-plainbox Package: plainbox-provider-oem Architecture: all -Depends: ${shlibs:Depends}, ${misc:Depends}, ${plainbox:Depends}, plainbox-provider-certification-client, plainbox-insecure-policy, plainbox-provider-sru, acpica-tools +Depends: ${shlibs:Depends}, ${misc:Depends}, ${plainbox:Depends}, plainbox-provider-certification-client, plainbox-insecure-policy, plainbox-provider-sru, acpica-tools, smbios-utils Recommends: ${plainbox:Recommends} Suggests: ${plainbox:Suggests} X-Plainbox-Provider: yes @@ -51,4 +51,3 @@ Depends: ${shlibs:Depends}, ${misc:Depends}, plainbox-provider-oem (= ${source:V Conflicts: plainbox-provider-oem-kittyhawk, plainbox-provider-oem-sutton, plainbox-provider-oem-stella Description: plainbox oem provider for somerville Plainbox OEM provider to run OEM-specific jobs and test plans (Somerville) - |