xref: /illumos-gate/usr/src/test/util-tests/tests/libsff/libsff_conn.c (revision 2a6e99a0f1f7d22c0396e8b2ce9b9babbd1056cf)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright (c) 2017, Joyent, Inc.
14  */
15 
16 /*
17  * Print all SFF Connector values
18  */
19 
20 #include <stdio.h>
21 #include <errno.h>
22 #include <strings.h>
23 #include <err.h>
24 #include <libsff.h>
25 
26 /*
27  * Pick up private sff header file with offsets from lib/libsff.
28  */
29 #include "sff.h"
30 
31 int
32 main(void)
33 {
34 	uint_t i;
35 	uint8_t buf[256];
36 
37 	bzero(buf, sizeof (buf));
38 	for (i = 0; i < UINT8_MAX; i++) {
39 		int ret;
40 		nvlist_t *nvl;
41 		char *val;
42 
43 		buf[SFF_8472_CONNECTOR] = i;
44 		if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
45 			errx(1, "TEST FAILED: failed to parse SFP connector "
46 			    "%d: %s\n", i, strerror(ret));
47 		}
48 
49 		if ((ret = nvlist_lookup_string(nvl, LIBSFF_KEY_CONNECTOR,
50 		    &val)) != 0) {
51 			errx(1, "TEST FAILED: failed to find key %s with "
52 			    "value %d: %s", LIBSFF_KEY_CONNECTOR, i,
53 			    strerror(ret));
54 		}
55 
56 		(void) puts(val);
57 		nvlist_free(nvl);
58 	}
59 
60 	/*
61 	 * Now for QSFP+
62 	 */
63 	(void) puts("\n\nQSFP\n");
64 	bzero(buf, sizeof (buf));
65 	buf[SFF_8472_IDENTIFIER] = SFF_8024_ID_QSFP;
66 	for (i = 0; i < UINT8_MAX; i++) {
67 		int ret;
68 		nvlist_t *nvl;
69 		char *val;
70 
71 		buf[SFF_8636_CONNECTOR] = i;
72 		if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) {
73 			errx(1, "TEST FAILED: failed to parse QSFP connector "
74 			    "%d: %s\n", i, strerror(errno));
75 		}
76 
77 		if ((ret = nvlist_lookup_string(nvl, LIBSFF_KEY_CONNECTOR,
78 		    &val)) != 0) {
79 			errx(1, "TEST FAILED: failed to find key %s with "
80 			    "value %d: %s", LIBSFF_KEY_CONNECTOR, i,
81 			    strerror(ret));
82 		}
83 
84 		(void) puts(val);
85 		nvlist_free(nvl);
86 	}
87 
88 	return (0);
89 }
90