1*94cba803SRyan Moeller /*- 2*94cba803SRyan Moeller * Copyright (c) 2020, Ryan Moeller <freqlabs@FreeBSD.org> 3*94cba803SRyan Moeller * 4*94cba803SRyan Moeller * Redistribution and use in source and binary forms, with or without 5*94cba803SRyan Moeller * modification, are permitted provided that the following conditions 6*94cba803SRyan Moeller * are met: 7*94cba803SRyan Moeller * 1. Redistributions of source code must retain the above copyright 8*94cba803SRyan Moeller * notice, this list of conditions and the following disclaimer. 9*94cba803SRyan Moeller * 2. Redistributions in binary form must reproduce the above copyright 10*94cba803SRyan Moeller * notice, this list of conditions and the following disclaimer in the 11*94cba803SRyan Moeller * documentation and/or other materials provided with the distribution. 12*94cba803SRyan Moeller * 13*94cba803SRyan Moeller * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14*94cba803SRyan Moeller * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15*94cba803SRyan Moeller * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16*94cba803SRyan Moeller * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17*94cba803SRyan Moeller * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18*94cba803SRyan Moeller * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19*94cba803SRyan Moeller * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20*94cba803SRyan Moeller * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21*94cba803SRyan Moeller * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22*94cba803SRyan Moeller * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23*94cba803SRyan Moeller * SUCH DAMAGE. 24*94cba803SRyan Moeller */ 25*94cba803SRyan Moeller 26*94cba803SRyan Moeller {# THIS IS A TEMPLATE PROCESSED BY lib/libifconfig/sfp.lua #} 27*94cba803SRyan Moeller 28*94cba803SRyan Moeller #pragma once 29*94cba803SRyan Moeller 30*94cba803SRyan Moeller #include <stdint.h> 31*94cba803SRyan Moeller 32*94cba803SRyan Moeller {% 33*94cba803SRyan Moeller for _, ent in ipairs(enums) do 34*94cba803SRyan Moeller if type(ent) == "string" then 35*94cba803SRyan Moeller %} 36*94cba803SRyan Moeller /* 37*94cba803SRyan Moeller * {*ent*} 38*94cba803SRyan Moeller */ 39*94cba803SRyan Moeller 40*94cba803SRyan Moeller {% 41*94cba803SRyan Moeller else 42*94cba803SRyan Moeller local enum = ent 43*94cba803SRyan Moeller local name = "sfp_"..enum.name 44*94cba803SRyan Moeller local num, sym, desc, disp 45*94cba803SRyan Moeller %} 46*94cba803SRyan Moeller /** {*enum.description*} */ 47*94cba803SRyan Moeller enum {*name*} { 48*94cba803SRyan Moeller {% 49*94cba803SRyan Moeller for _, item in ipairs(enum.values) do 50*94cba803SRyan Moeller val, sym, desc, disp = table.unpack(item) 51*94cba803SRyan Moeller local symbol = string.upper(name).."_"..sym 52*94cba803SRyan Moeller %} 53*94cba803SRyan Moeller {*symbol*} = {*val*}, /**< {*desc*} */ 54*94cba803SRyan Moeller {% 55*94cba803SRyan Moeller end 56*94cba803SRyan Moeller %} 57*94cba803SRyan Moeller }; 58*94cba803SRyan Moeller 59*94cba803SRyan Moeller /** Get the symbolic name of a given {*name*} value */ 60*94cba803SRyan Moeller const char *ifconfig_{*name*}_symbol(enum {*name*}); 61*94cba803SRyan Moeller 62*94cba803SRyan Moeller /** Get a brief description of a given {*name*} value */ 63*94cba803SRyan Moeller const char *ifconfig_{*name*}_description(enum {*name*}); 64*94cba803SRyan Moeller 65*94cba803SRyan Moeller {% 66*94cba803SRyan Moeller if disp then 67*94cba803SRyan Moeller %} 68*94cba803SRyan Moeller /** Get a shortened user-friendly display name for a given {*name*} value */ 69*94cba803SRyan Moeller const char *ifconfig_{*name*}_display(enum {*name*}); 70*94cba803SRyan Moeller 71*94cba803SRyan Moeller {% 72*94cba803SRyan Moeller end 73*94cba803SRyan Moeller end 74*94cba803SRyan Moeller end 75*94cba803SRyan Moeller %} 76*94cba803SRyan Moeller /* 77*94cba803SRyan Moeller * Descriptions of each enum 78*94cba803SRyan Moeller */ 79*94cba803SRyan Moeller 80*94cba803SRyan Moeller {% 81*94cba803SRyan Moeller for _, ent in ipairs(enums) do 82*94cba803SRyan Moeller if type(ent) == "table" then 83*94cba803SRyan Moeller local enum = ent 84*94cba803SRyan Moeller local name = "sfp_"..enum.name 85*94cba803SRyan Moeller %} 86*94cba803SRyan Moeller /** Get a brief description of the {*name*} enum */ 87*94cba803SRyan Moeller static inline const char * 88*94cba803SRyan Moeller ifconfig_enum_{*name*}_description(void) 89*94cba803SRyan Moeller { 90*94cba803SRyan Moeller return ("{*enum.description*}"); 91*94cba803SRyan Moeller } 92*94cba803SRyan Moeller 93*94cba803SRyan Moeller {% 94*94cba803SRyan Moeller end 95*94cba803SRyan Moeller end 96*94cba803SRyan Moeller %} 97*94cba803SRyan Moeller /* 98*94cba803SRyan Moeller * Info struct definitions 99*94cba803SRyan Moeller */ 100*94cba803SRyan Moeller 101*94cba803SRyan Moeller struct ifconfig_sfp_info { 102*94cba803SRyan Moeller {% 103*94cba803SRyan Moeller for _, ent in ipairs(enums) do 104*94cba803SRyan Moeller if type(ent) == "table" then 105*94cba803SRyan Moeller local enum = ent 106*94cba803SRyan Moeller local name = "sfp_"..enum.name 107*94cba803SRyan Moeller local t = string.format("uint%d_t", enum.bits) 108*94cba803SRyan Moeller %} 109*94cba803SRyan Moeller {*t*} {*name*}; /**< {*enum.description*} */ 110*94cba803SRyan Moeller {% 111*94cba803SRyan Moeller end 112*94cba803SRyan Moeller end 113*94cba803SRyan Moeller %} 114*94cba803SRyan Moeller }; 115*94cba803SRyan Moeller 116*94cba803SRyan Moeller struct ifconfig_sfp_info_strings { 117*94cba803SRyan Moeller {% 118*94cba803SRyan Moeller for _, ent in ipairs(enums) do 119*94cba803SRyan Moeller if type(ent) == "table" then 120*94cba803SRyan Moeller local enum = ent 121*94cba803SRyan Moeller local name = "sfp_"..enum.name 122*94cba803SRyan Moeller %} 123*94cba803SRyan Moeller const char *{*name*}; /**< {*enum.description*} */ 124*94cba803SRyan Moeller {% 125*94cba803SRyan Moeller end 126*94cba803SRyan Moeller end 127*94cba803SRyan Moeller %} 128*94cba803SRyan Moeller }; 129