1*dd843e54Smartijn /* $OpenBSD: smi.h,v 1.4 2020/12/14 07:44:26 martijn Exp $ */ 2442e4f4fSmartijn 3442e4f4fSmartijn /* 4442e4f4fSmartijn * Copyright (c) 2019 Martijn van Duren <martijn@openbsd.org> 5442e4f4fSmartijn * Copyright (c) 2007, 2008 Reyk Floeter <reyk@openbsd.org> 6442e4f4fSmartijn * 7442e4f4fSmartijn * Permission to use, copy, modify, and distribute this software for any 8442e4f4fSmartijn * purpose with or without fee is hereby granted, provided that the above 9442e4f4fSmartijn * copyright notice and this permission notice appear in all copies. 10442e4f4fSmartijn * 11442e4f4fSmartijn * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12442e4f4fSmartijn * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13442e4f4fSmartijn * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14442e4f4fSmartijn * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15442e4f4fSmartijn * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16442e4f4fSmartijn * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17442e4f4fSmartijn * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18442e4f4fSmartijn */ 19442e4f4fSmartijn 20442e4f4fSmartijn #include <sys/tree.h> 21442e4f4fSmartijn #include <sys/queue.h> 22442e4f4fSmartijn 23442e4f4fSmartijn #define OID_ROOT 0x00 24442e4f4fSmartijn #define OID_RD 0x01 25442e4f4fSmartijn #define OID_WR 0x02 26442e4f4fSmartijn #define OID_IFSET 0x04 /* only if user-specified value */ 27442e4f4fSmartijn #define OID_DYNAMIC 0x08 /* free allocated data */ 28442e4f4fSmartijn #define OID_TABLE 0x10 /* dynamic sub-elements */ 29442e4f4fSmartijn #define OID_MIB 0x20 /* root-OID of a supported MIB */ 30442e4f4fSmartijn #define OID_KEY 0x40 /* lookup tables */ 31442e4f4fSmartijn #define OID_REGISTERED 0x80 /* OID registered by subagent */ 32442e4f4fSmartijn 33442e4f4fSmartijn #define OID_RS (OID_RD|OID_IFSET) 34442e4f4fSmartijn #define OID_WS (OID_WR|OID_IFSET) 35442e4f4fSmartijn #define OID_RW (OID_RD|OID_WR) 36442e4f4fSmartijn #define OID_RWS (OID_RW|OID_IFSET) 37442e4f4fSmartijn 38442e4f4fSmartijn #define OID_TRD (OID_RD|OID_TABLE) 39442e4f4fSmartijn #define OID_TWR (OID_WR|OID_TABLE) 40442e4f4fSmartijn #define OID_TRS (OID_RD|OID_IFSET|OID_TABLE) 41442e4f4fSmartijn #define OID_TWS (OID_WR|OID_IFSET|OID_TABLE) 42442e4f4fSmartijn #define OID_TRW (OID_RD|OID_WR|OID_TABLE) 43442e4f4fSmartijn #define OID_TRWS (OID_RW|OID_IFSET|OID_TABLE) 44442e4f4fSmartijn 45442e4f4fSmartijn enum smi_output_string { 46442e4f4fSmartijn smi_os_default, 47442e4f4fSmartijn smi_os_hex, 48442e4f4fSmartijn smi_os_ascii 49442e4f4fSmartijn }; 50442e4f4fSmartijn 51442e4f4fSmartijn enum smi_oid_lookup { 52442e4f4fSmartijn smi_oidl_numeric, 53442e4f4fSmartijn smi_oidl_short, 54442e4f4fSmartijn smi_oidl_full 55442e4f4fSmartijn }; 56442e4f4fSmartijn 57442e4f4fSmartijn struct oid { 58442e4f4fSmartijn struct ber_oid o_id; 59442e4f4fSmartijn #define o_oid o_id.bo_id 60442e4f4fSmartijn #define o_oidlen o_id.bo_n 61442e4f4fSmartijn 621248928aSmartijn const char *o_name; 631248928aSmartijn const char *o_tcname; 641248928aSmartijn struct textconv *o_textconv; 65442e4f4fSmartijn 66442e4f4fSmartijn RB_ENTRY(oid) o_element; 67442e4f4fSmartijn RB_ENTRY(oid) o_keyword; 68442e4f4fSmartijn }; 69442e4f4fSmartijn 70*dd843e54Smartijn struct textconv_enum { 71*dd843e54Smartijn uint32_t tce_number; 72*dd843e54Smartijn const char *tce_name; 73*dd843e54Smartijn }; 74*dd843e54Smartijn 751248928aSmartijn struct textconv { 761248928aSmartijn const char *tc_name; 771248928aSmartijn unsigned int tc_syntax; 78*dd843e54Smartijn const char *tc_display_hint; 79*dd843e54Smartijn struct textconv_enum *tc_enum; 801248928aSmartijn RB_ENTRY(textconv) tc_entry; 811248928aSmartijn }; 821248928aSmartijn 83442e4f4fSmartijn int smi_init(void); 84442e4f4fSmartijn unsigned int smi_application(struct ber_element *); 85442e4f4fSmartijn int smi_string2oid(const char *, struct ber_oid *); 86442e4f4fSmartijn char *smi_oid2string(struct ber_oid *, char *, size_t, enum smi_oid_lookup); 87442e4f4fSmartijn void smi_mibtree(struct oid *); 881248928aSmartijn void smi_textconvtree(struct textconv *); 899265c3a7Smartijn struct oid *smi_foreach(struct oid *); 901248928aSmartijn void smi_debug_elements(struct ber_element *, int); 911248928aSmartijn char *smi_print_element(struct ber_oid *, struct ber_element *, int, 921248928aSmartijn enum smi_output_string, enum smi_oid_lookup, int); 93