1 /* 2 * Private SNMP definitions for CUPS. 3 * 4 * Copyright © 2020-2024 by OpenPrinting. 5 * Copyright © 2007-2014 by Apple Inc. 6 * Copyright © 2006-2007 by Easy Software Products, all rights reserved. 7 * 8 * Licensed under Apache License v2.0. See the file "LICENSE" for more 9 * information. 10 */ 11 12 #ifndef _CUPS_SNMP_PRIVATE_H_ 13 # define _CUPS_SNMP_PRIVATE_H_ 14 15 16 /* 17 * Include necessary headers. 18 */ 19 20 #include <cups/http.h> 21 22 23 /* 24 * Constants... 25 */ 26 27 #define CUPS_SNMP_PORT 161 /* SNMP well-known port */ 28 #define CUPS_SNMP_MAX_COMMUNITY 512 /* Maximum size of community name */ 29 #define CUPS_SNMP_MAX_OID 128 /* Maximum number of OID numbers */ 30 #define CUPS_SNMP_MAX_PACKET 1472 /* Maximum size of SNMP packet */ 31 #define CUPS_SNMP_MAX_STRING 1024 /* Maximum size of string */ 32 #define CUPS_SNMP_VERSION_1 0 /* SNMPv1 */ 33 34 35 /* 36 * Types... 37 */ 38 39 enum cups_asn1_e /**** ASN1 request/object types ****/ 40 { 41 CUPS_ASN1_END_OF_CONTENTS = 0x00, /* End-of-contents */ 42 CUPS_ASN1_BOOLEAN = 0x01, /* BOOLEAN */ 43 CUPS_ASN1_INTEGER = 0x02, /* INTEGER or ENUMERATION */ 44 CUPS_ASN1_BIT_STRING = 0x03, /* BIT STRING */ 45 CUPS_ASN1_OCTET_STRING = 0x04, /* OCTET STRING */ 46 CUPS_ASN1_NULL_VALUE = 0x05, /* NULL VALUE */ 47 CUPS_ASN1_OID = 0x06, /* OBJECT IDENTIFIER */ 48 CUPS_ASN1_SEQUENCE = 0x30, /* SEQUENCE */ 49 CUPS_ASN1_HEX_STRING = 0x40, /* Binary string aka Hex-STRING */ 50 CUPS_ASN1_COUNTER = 0x41, /* 32-bit unsigned aka Counter32 */ 51 CUPS_ASN1_GAUGE = 0x42, /* 32-bit unsigned aka Gauge32 */ 52 CUPS_ASN1_TIMETICKS = 0x43, /* 32-bit unsigned aka Timeticks32 */ 53 CUPS_ASN1_GET_REQUEST = 0xa0, /* GetRequest-PDU */ 54 CUPS_ASN1_GET_NEXT_REQUEST = 0xa1, /* GetNextRequest-PDU */ 55 CUPS_ASN1_GET_RESPONSE = 0xa2 /* GetResponse-PDU */ 56 }; 57 typedef enum cups_asn1_e cups_asn1_t; /**** ASN1 request/object types ****/ 58 59 typedef struct cups_snmp_string_s /**** String value ****/ 60 { 61 unsigned char bytes[CUPS_SNMP_MAX_STRING]; 62 /* Bytes in string */ 63 unsigned num_bytes; /* Number of bytes */ 64 } cups_snmp_string_t; 65 66 union cups_snmp_value_u /**** Object value ****/ 67 { 68 int boolean; /* Boolean value */ 69 int integer; /* Integer value */ 70 int counter; /* Counter value */ 71 unsigned gauge; /* Gauge value */ 72 unsigned timeticks; /* Timeticks value */ 73 int oid[CUPS_SNMP_MAX_OID]; /* OID value */ 74 cups_snmp_string_t string; /* String value */ 75 }; 76 77 typedef struct cups_snmp_s /**** SNMP data packet ****/ 78 { 79 const char *error; /* Encode/decode error */ 80 http_addr_t address; /* Source address */ 81 int version; /* Version number */ 82 char community[CUPS_SNMP_MAX_COMMUNITY]; 83 /* Community name */ 84 cups_asn1_t request_type; /* Request type */ 85 unsigned request_id; /* request-id value */ 86 int error_status; /* error-status value */ 87 int error_index; /* error-index value */ 88 int object_name[CUPS_SNMP_MAX_OID]; 89 /* object-name value */ 90 cups_asn1_t object_type; /* object-value type */ 91 union cups_snmp_value_u 92 object_value; /* object-value value */ 93 } cups_snmp_t; 94 95 typedef void (*cups_snmp_cb_t)(cups_snmp_t *packet, void *data); 96 97 /* 98 * Prototypes... 99 */ 100 101 # ifdef __cplusplus 102 extern "C" { 103 # endif /* __cplusplus */ 104 105 extern void _cupsSNMPClose(int fd) _CUPS_PRIVATE; 106 extern int *_cupsSNMPCopyOID(int *dst, const int *src, int dstsize) 107 _CUPS_PRIVATE; 108 extern const char *_cupsSNMPDefaultCommunity(void) _CUPS_PRIVATE; 109 extern int _cupsSNMPIsOID(cups_snmp_t *packet, const int *oid) 110 _CUPS_PRIVATE; 111 extern int _cupsSNMPIsOIDPrefixed(cups_snmp_t *packet, 112 const int *prefix) _CUPS_PRIVATE; 113 extern char *_cupsSNMPOIDToString(const int *src, char *dst, 114 size_t dstsize) _CUPS_PRIVATE; 115 extern int _cupsSNMPOpen(int family) _CUPS_PRIVATE; 116 extern cups_snmp_t *_cupsSNMPRead(int fd, cups_snmp_t *packet, 117 double timeout) _CUPS_PRIVATE; 118 extern void _cupsSNMPSetDebug(int level) _CUPS_PRIVATE; 119 extern int *_cupsSNMPStringToOID(const char *src, 120 int *dst, int dstsize) 121 _CUPS_PRIVATE; 122 extern int _cupsSNMPWalk(int fd, http_addr_t *address, int version, 123 const char *community, const int *prefix, 124 double timeout, cups_snmp_cb_t cb, 125 void *data) _CUPS_PRIVATE; 126 extern int _cupsSNMPWrite(int fd, http_addr_t *address, int version, 127 const char *community, 128 cups_asn1_t request_type, 129 const unsigned request_id, 130 const int *oid) _CUPS_PRIVATE; 131 132 # ifdef __cplusplus 133 } 134 # endif /* __cplusplus */ 135 #endif /* !_CUPS_SNMP_PRIVATE_H_ */ 136