Add support for displaying memory usage via "pico-fido-tool.py memory" command.
Fixes #82. Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Submodule pico-keys-sdk updated: e627b3fc86...ffaf20da5d
@@ -266,6 +266,24 @@ int cbor_vendor_generic(uint8_t cmd, const uint8_t *data, size_t len) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
else if (cmd == CTAP_VENDOR_MEMORY) {
|
||||||
|
if (vendorCmd == 0x01) {
|
||||||
|
CBOR_CHECK(cbor_encoder_create_map(&encoder, &mapEncoder, 5));
|
||||||
|
CBOR_CHECK(cbor_encode_uint(&mapEncoder, 0x01));
|
||||||
|
CBOR_CHECK(cbor_encode_uint(&mapEncoder, flash_free_space()));
|
||||||
|
CBOR_CHECK(cbor_encode_uint(&mapEncoder, 0x02));
|
||||||
|
CBOR_CHECK(cbor_encode_uint(&mapEncoder, flash_used_space()));
|
||||||
|
CBOR_CHECK(cbor_encode_uint(&mapEncoder, 0x03));
|
||||||
|
CBOR_CHECK(cbor_encode_uint(&mapEncoder, flash_total_space()));
|
||||||
|
CBOR_CHECK(cbor_encode_uint(&mapEncoder, 0x04));
|
||||||
|
CBOR_CHECK(cbor_encode_uint(&mapEncoder, flash_num_files()));
|
||||||
|
CBOR_CHECK(cbor_encode_uint(&mapEncoder, 0x05));
|
||||||
|
CBOR_CHECK(cbor_encode_uint(&mapEncoder, flash_size()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
CBOR_ERROR(CTAP2_ERR_UNSUPPORTED_OPTION);
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
CBOR_ERROR(CTAP2_ERR_UNSUPPORTED_OPTION);
|
CBOR_ERROR(CTAP2_ERR_UNSUPPORTED_OPTION);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ typedef struct {
|
|||||||
#define CTAP_VENDOR_UNLOCK 0x03
|
#define CTAP_VENDOR_UNLOCK 0x03
|
||||||
#define CTAP_VENDOR_EA 0x04
|
#define CTAP_VENDOR_EA 0x04
|
||||||
#define CTAP_VENDOR_PHY_OPTS 0x05
|
#define CTAP_VENDOR_PHY_OPTS 0x05
|
||||||
|
#define CTAP_VENDOR_MEMORY 0x06
|
||||||
|
|
||||||
#define CTAP_PERMISSION_MC 0x01 // MakeCredential
|
#define CTAP_PERMISSION_MC 0x01 // MakeCredential
|
||||||
#define CTAP_PERMISSION_GA 0x02 // GetAssertion
|
#define CTAP_PERMISSION_GA 0x02 // GetAssertion
|
||||||
|
|||||||
@@ -233,6 +233,7 @@ class Vendor:
|
|||||||
VENDOR_UNLOCK = 0x03
|
VENDOR_UNLOCK = 0x03
|
||||||
VENDOR_EA = 0x04
|
VENDOR_EA = 0x04
|
||||||
VENDOR_PHY = 0x05
|
VENDOR_PHY = 0x05
|
||||||
|
VENDOR_MEMORY = 0x06
|
||||||
|
|
||||||
@unique
|
@unique
|
||||||
class PARAM(IntEnum):
|
class PARAM(IntEnum):
|
||||||
@@ -475,6 +476,13 @@ class Vendor:
|
|||||||
Vendor.SUBCMD.ENABLE,
|
Vendor.SUBCMD.ENABLE,
|
||||||
)[Vendor.RESP.PARAM]
|
)[Vendor.RESP.PARAM]
|
||||||
|
|
||||||
|
def memory(self):
|
||||||
|
resp = self._call(
|
||||||
|
Vendor.CMD.VENDOR_MEMORY,
|
||||||
|
Vendor.SUBCMD.ENABLE,
|
||||||
|
)
|
||||||
|
return { 'free': resp[1], 'used': resp[2], 'total': resp[3], 'files': resp[4], 'size': resp[5] }
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
subparser = parser.add_subparsers(title="commands", dest="command")
|
subparser = parser.add_subparsers(title="commands", dest="command")
|
||||||
@@ -503,6 +511,8 @@ def parse_args():
|
|||||||
parser_phy_optdimm = subparser_phy.add_parser('led_dimmable', help='Enable/Disable LED dimming.')
|
parser_phy_optdimm = subparser_phy.add_parser('led_dimmable', help='Enable/Disable LED dimming.')
|
||||||
parser_phy_optdimm.add_argument('value', choices=['enable', 'disable'], help='Enable/Disable LED dimming.', nargs='?')
|
parser_phy_optdimm.add_argument('value', choices=['enable', 'disable'], help='Enable/Disable LED dimming.', nargs='?')
|
||||||
|
|
||||||
|
parser_mem = subparser.add_parser('memory', help='Get current memory usage.')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
return args
|
return args
|
||||||
|
|
||||||
@@ -560,9 +570,17 @@ def phy(vdr, args):
|
|||||||
else:
|
else:
|
||||||
print('Command executed successfully. Please, restart your Pico Key.')
|
print('Command executed successfully. Please, restart your Pico Key.')
|
||||||
|
|
||||||
|
def memory(vdr, args):
|
||||||
|
mem = vdr.memory()
|
||||||
|
print(f'Memory usage:')
|
||||||
|
print(f'\tFree: {mem["free"]/1024:.2f} kilobytes ({mem["free"]*100/mem["total"]:.2f}%)')
|
||||||
|
print(f'\tUsed: {mem["used"]/1024:.2f} kilobytes ({mem["used"]*100/mem["total"]:.2f}%)')
|
||||||
|
print(f'\tTotal: {mem["total"]/1024:.2f} kilobytes')
|
||||||
|
print(f'\tFlash size: {mem["size"]/1024:.2f} kilobytes')
|
||||||
|
print(f'\tFiles: {mem["files"]}')
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
print('Pico Fido Tool v1.8')
|
print('Pico Fido Tool v1.10')
|
||||||
print('Author: Pol Henarejos')
|
print('Author: Pol Henarejos')
|
||||||
print('Report bugs to https://github.com/polhenarejos/pico-fido/issues')
|
print('Report bugs to https://github.com/polhenarejos/pico-fido/issues')
|
||||||
print('')
|
print('')
|
||||||
@@ -582,6 +600,8 @@ def main(args):
|
|||||||
attestation(vdr, args)
|
attestation(vdr, args)
|
||||||
elif (args.command == 'phy'):
|
elif (args.command == 'phy'):
|
||||||
phy(vdr, args)
|
phy(vdr, args)
|
||||||
|
elif (args.command == 'memory'):
|
||||||
|
memory(vdr, args)
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
|||||||
Reference in New Issue
Block a user