From 46fd42af0c569972ced135cbf28c2402ae6d18f3 Mon Sep 17 00:00:00 2001 From: Harald Freudenberger Date: Fri, 18 Feb 2022 16:26:14 +0100 Subject: [PATCH] lszcrypt: new option to show the serial numbers of CCA and EP11 cards MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new option -s, long --serial shows the serial numbers of CCA and EP11 cards. Signed-off-by: Harald Freudenberger Signed-off-by: Jan Höppner --- zconf/zcrypt/lszcrypt.8 | 5 +++ zconf/zcrypt/lszcrypt.c | 88 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/zconf/zcrypt/lszcrypt.8 b/zconf/zcrypt/lszcrypt.8 index 1c53a80e..20354d23 100644 --- a/zconf/zcrypt/lszcrypt.8 +++ b/zconf/zcrypt/lszcrypt.8 @@ -32,6 +32,8 @@ lszcrypt \- display zcrypt device and configuration information .TP .B lszcrypt -h .TP +.B lszcrypt -s +.TP .B lszcrypt -v . TP .B @@ -113,6 +115,9 @@ B - indicate both (control and usage domain) .B -h, --help Displays help text and exits. .TP 8 +.B -s, --serial +Shows the serial numbers for CCA and EP11 crypto cards. +.TP 8 .B -v, --version Displays version information and exits. .TP 8 diff --git a/zconf/zcrypt/lszcrypt.c b/zconf/zcrypt/lszcrypt.c index a0884417..c0eadce8 100644 --- a/zconf/zcrypt/lszcrypt.c +++ b/zconf/zcrypt/lszcrypt.c @@ -151,6 +151,10 @@ static struct util_opt opt_vec[] = { .flags = UTIL_OPT_FLAG_NOSHORT, .desc = "Show only information from queues but no card info", }, + { + .option = {"serial", 0, NULL, 's'}, + .desc = "Show the serial numbers for CCA and EP11 crypto cards", + }, UTIL_OPT_HELP, UTIL_OPT_VERSION, UTIL_OPT_END @@ -285,6 +289,87 @@ static void show_domains(void) show_domains_util_rec(domain_array); } +/* + * Show serialnumbers + */ +static void show_serialnumbers(void) +{ + struct util_rec *rec = util_rec_new_wide("-"); + struct dirent **dev_vec; + int i, count; + char *ap, *path, *device, *grp_dev, card[16], buf[256]; + long config = -1, online = -1, chkstop = -1; + unsigned long facility; + + /* check if ap driver is available */ + ap = util_path_sysfs("bus/ap"); + if (!util_path_is_dir(ap)) + errx(EXIT_FAILURE, "Crypto device driver not available."); + + /* define the record */ + util_rec_def(rec, "card", UTIL_REC_ALIGN_LEFT, 8, "CARD.DOM"); + util_rec_def(rec, "type", UTIL_REC_ALIGN_LEFT, 5, "TYPE"); + util_rec_def(rec, "mode", UTIL_REC_ALIGN_LEFT, 11, "MODE"); + util_rec_def(rec, "status", UTIL_REC_ALIGN_LEFT, 10, "STATUS"); + util_rec_def(rec, "serialnr", UTIL_REC_ALIGN_LEFT, 8, "SERIALNR"); + + /* scan the devices */ + path = util_path_sysfs("devices/ap/"); + count = util_scandir(&dev_vec, alphasort, path, "card[0-9a-fA-F]+"); + if (count < 1) + errx(EXIT_FAILURE, "No crypto card devices found."); + util_rec_print_hdr(rec); + for (i = 0; i < count; i++) { + device = dev_vec[i]->d_name; + grp_dev = util_path_sysfs("devices/ap/%s", device); + if (!util_path_is_dir(grp_dev)) + errx(EXIT_FAILURE, "Error - cryptographic device %s does not exist.", device); + if (!util_path_is_readable("%s/type", grp_dev) || + !util_path_is_readable("%s/online", grp_dev)) + goto next; + strcpy(card, device + 4); + util_rec_set(rec, "card", card); + util_file_read_line(buf, sizeof(buf), "%s/type", grp_dev); + util_rec_set(rec, "type", buf); + util_file_read_ul(&facility, 16, "%s/ap_functions", grp_dev); + if (facility & MASK_COPRO) + util_rec_set(rec, "mode", "CCA-Coproc"); + else if (facility & MASK_EP11) + util_rec_set(rec, "mode", "EP11-Coproc"); + else + goto next; + if (util_path_is_readable("%s/config", grp_dev)) + util_file_read_l(&config, 10, "%s/config", grp_dev); + if (util_path_is_readable("%s/chkstop", grp_dev)) + util_file_read_l(&chkstop, 10, "%s/chkstop", grp_dev); + if (util_path_is_readable("%s/online", grp_dev)) + util_file_read_l(&online, 10, "%s/online", grp_dev); + if (config == 0) { + util_rec_set(rec, "status", "deconfig"); + } else { + if (chkstop > 0) + util_rec_set(rec, "status", "chkstop"); + else if (online > 0) + util_rec_set(rec, "status", "online"); + else if (online == 0) + util_rec_set(rec, "status", "offline"); + else + util_rec_set(rec, "status", "-"); + } + if (util_file_read_line(buf, sizeof(buf), "%s/serialnr", grp_dev)) + util_rec_set(rec, "serialnr", "-"); + else { + buf[8] = '\0'; + util_rec_set(rec, "serialnr", buf); + } + util_rec_print(rec); +next: + free(grp_dev); + } + + free(path); +} + /* * Show capability */ @@ -863,6 +948,9 @@ int main(int argc, char **argv) case 'd': show_domains(); return EXIT_SUCCESS; + case 's': + show_serialnumbers(); + return EXIT_SUCCESS; case 'V': l.verbose++; break;