Verified Commit 723d34f4 authored by Vojtech Myslivec's avatar Vojtech Myslivec 🚀

Add support for MAC address query

parent f3176ca1
......@@ -13,3 +13,4 @@ SYSFS_ROOT = "/sys/devices/platform/soc/soc:internal-regs@d0000000/soc:internal-
PUBKEY_PATH = SYSFS_ROOT + "mox_pubkey"
SIGN_PATH = SYSFS_ROOT + "mox_do_sign"
SERIAL_PATH = SYSFS_ROOT + "mox_serial_number"
MAC_PATH = SYSFS_ROOT + "mox_mac_address1"
......@@ -5,11 +5,11 @@ Main entry point of MOX OTP package
import sys
from .argparser import parse_args
from .checks import check_serial, check_pubkey
from .checks import check_mac, check_serial, check_pubkey
from .exceptions import MoxOtpApiError, MoxOtpSetupError, MoxOtpUsageError
from .helpers import errprint, first_line_of_file, hash_type
from .__init__ import PUBKEY_PATH, SERIAL_PATH, SIGN_PATH
from .__init__ import MAC_PATH, PUBKEY_PATH, SERIAL_PATH, SIGN_PATH
# number of bytes to read at once
CHUNK_SIZE = 1024
......@@ -49,6 +49,13 @@ def do_serial():
print(first_line_of_file(SERIAL_PATH))
@check_mac
def do_mac():
"""print MAC address from OTP
"""
print(first_line_of_file(MAC_PATH))
@check_pubkey
def do_pubkey():
"""print public key from OTP
......@@ -81,6 +88,9 @@ def main():
if args.command in ["serial-number", "serial"]:
do_serial()
elif args.command in ["mac-address", "mac"]:
do_mac()
elif args.command in ["public-key", "pubkey", "key"]:
do_pubkey()
......
......@@ -56,6 +56,12 @@ def parse_args():
help="Print serial number of the device",
)
sub = subparsers.add_parser(
"mac-address",
aliases=["mac"],
help="Print MAC address of the first Ethernet port",
)
sub = subparsers.add_parser(
"public-key",
aliases=["pubkey", "key"],
......
......@@ -8,7 +8,7 @@ from functools import wraps
from .exceptions import MoxOtpApiError, MoxOtpSetupError
from .helpers import first_line_of_file
from .__init__ import PUBKEY_PATH, SERIAL_PATH, SYSFS_ROOT
from .__init__ import MAC_PATH, PUBKEY_PATH, SERIAL_PATH, SYSFS_ROOT
def check_sysfs():
......@@ -29,6 +29,19 @@ def check_serial(f):
return _checked
def check_mac(f):
@wraps(f)
def _checked(*args, **kwargs):
check_sysfs()
try:
first_line_of_file(MAC_PATH)
except (FileNotFoundError, PermissionError):
raise MoxOtpApiError("Could not find MOX MAC address file")
return f(*args, **kwargs)
return _checked
def check_pubkey(f):
@wraps(f)
def _checked(*args, **kwargs):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment