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 and tests SFF length 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 int ret; 35 uint8_t buf[256]; 36 nvlist_t *nvl; 37 char *val; 38 uint_t i; 39 const char *lengths_8472[] = { LIBSFF_KEY_LENGTH_SMF_KM, 40 LIBSFF_KEY_LENGTH_SMF, LIBSFF_KEY_LENGTH_OM2, LIBSFF_KEY_LENGTH_OM1, 41 LIBSFF_KEY_LENGTH_COPPER, LIBSFF_KEY_LENGTH_OM3, NULL }; 42 const char *lengths_8636[] = { LIBSFF_KEY_LENGTH_SMF_KM, 43 LIBSFF_KEY_LENGTH_OM2, LIBSFF_KEY_LENGTH_OM1, 44 LIBSFF_KEY_LENGTH_COPPER, LIBSFF_KEY_LENGTH_OM3, NULL }; 45 46 /* 47 * Make sure if lengths are zero that they don't show up. 48 */ 49 bzero(buf, sizeof (buf)); 50 if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) { 51 errx(1, "TEST FAILED: failed to parse SFP length " 52 "values: %s\n", strerror(ret)); 53 } 54 55 for (i = 0; lengths_8472[i] != NULL; i++) { 56 if ((ret = nvlist_lookup_string(nvl, lengths_8472[i], &val)) != 57 ENOENT) { 58 errx(1, "TEST FALIED: found unexpected return value " 59 "for key %s: %d\n", lengths_8472[i], ret); 60 } 61 } 62 63 nvlist_free(nvl); 64 65 buf[SFF_8472_LENGTH_SMF_KM] = 0x23; 66 buf[SFF_8472_LENGTH_SMF] = 0x24; 67 buf[SFF_8472_LENGTH_50UM] = 0x25; 68 buf[SFF_8472_LENGTH_62UM] = 0x26; 69 buf[SFF_8472_LENGTH_COPPER] = 0x27; 70 buf[SFF_8472_LENGTH_OM3] = 0x28; 71 72 if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) { 73 errx(1, "TEST FAILED: failed to parse SFP length " 74 "values: %s\n", strerror(ret)); 75 } 76 77 for (i = 0; lengths_8472[i] != NULL; i++) { 78 if ((ret = nvlist_lookup_string(nvl, lengths_8472[i], &val)) != 79 0) { 80 errx(1, "TEST FALIED: failed to find length for key " 81 "%s: %d\n", lengths_8472[i], ret); 82 } 83 (void) printf("%s: %s\n", lengths_8472[i], val); 84 } 85 86 nvlist_free(nvl); 87 88 /* 89 * Now for QSFP+ 90 */ 91 (void) puts("\n\nQSFP\n"); 92 bzero(buf, sizeof (buf)); 93 buf[SFF_8472_IDENTIFIER] = SFF_8024_ID_QSFP; 94 95 if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) { 96 errx(1, "TEST FAILED: failed to parse QSFP length " 97 "values: %s\n", strerror(ret)); 98 } 99 100 for (i = 0; lengths_8472[i] != NULL; i++) { 101 if ((ret = nvlist_lookup_string(nvl, lengths_8472[i], &val)) != 102 ENOENT) { 103 errx(1, "TEST FALIED: found unexpected return value " 104 "for key %s: %d\n", lengths_8472[i], ret); 105 } 106 } 107 108 nvlist_free(nvl); 109 110 buf[SFF_8636_LENGTH_SMF] = 0x23; 111 buf[SFF_8636_LENGTH_OM3] = 0x24; 112 buf[SFF_8636_LENGTH_OM2] = 0x25; 113 buf[SFF_8636_LENGTH_OM1] = 0x26; 114 buf[SFF_8636_LENGTH_COPPER] = 0x27; 115 116 if ((ret = libsff_parse(buf, sizeof (buf), 0xa0, &nvl)) != 0) { 117 errx(1, "TEST FAILED: failed to parse QSFP length " 118 "values: %s\n", strerror(ret)); 119 } 120 121 for (i = 0; lengths_8636[i] != NULL; i++) { 122 if ((ret = nvlist_lookup_string(nvl, lengths_8636[i], &val)) != 123 0) { 124 errx(1, "TEST FALIED: failed to find length for key " 125 "%s: %d\n", lengths_8472[i], ret); 126 } 127 (void) printf("%s: %s\n", lengths_8636[i], val); 128 } 129 130 nvlist_free(nvl); 131 132 return (0); 133 } 134