-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtinySNMP.h
81 lines (70 loc) · 1.85 KB
/
tinySNMP.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef TINYSNMP_H
#define TINYSNMP_H
#include <Arduino.h>
#define SNMP_MAX_PACKET_LEN 127
#define SNMP_VERSION 1 //2c
#define SNMP_ERR_NO_ERROR 0
#define SNMP_ERR_TOO_BIG 1
#define SNMP_ERR_NO_SUCH_NAME 2
#define SNMP_ERR_BAD_VALUE 3
#define SNMP_ERR_READ_ONLY 4
#define SNMP_ERR_GEN_ERROR 5
#define SNMP_TYPE_BOOL 0x01
#define SNMP_TYPE_INT 0x02
#define SNMP_TYPE_BITS 0x03
#define SNMP_TYPE_OCTETS 0x04
#define SNMP_TYPE_NULL 0x05
#define SNMP_TYPE_OID 0x06
#define SNMP_PDU_GET 0xA0
#define SNMP_PDU_GET_NEXT 0xA1
#define SNMP_PDU_RESPONSE 0xA2
#define SNMP_PDU_SET 0xA3
#define SNMP_PDU_TRAP 0xA4
#define SNMP_COMM_MAX_SIZE 7
#define SNMP_MAX_OID_SIZE 20
#define SNMP_MAX_OID_VAL_SIZE 20
#define SNMP_MAX_ID 4
#define SNMP_MAX_MIB_SIZE SNMP_MAX_OID_SIZE
#define SNMP_MAX_MIB_VAL_SIZE SNMP_MAX_OID_VAL_SIZE+1
struct OID
{
//unsigned int SNMPsize;
//unsigned int SNMPver;
//community
unsigned int SNMPcommLen;
byte SNMPcomm[SNMP_COMM_MAX_SIZE];
//pdu
byte SNMPpduType;
//request id
byte SNMPridType;
unsigned int SNMPridLen;
byte SNMPrid[SNMP_MAX_ID];
//error
byte SNMPerrType;
unsigned int SNMPerrLen;
byte SNMPerr[SNMP_MAX_ID];
//error index
byte SNMPeriType;
unsigned int SNMPeriLen;
byte SNMPeri[SNMP_MAX_ID];
//object id
byte SNMPoidType;
unsigned int SNMPoidLen;
byte SNMPoid[SNMP_MAX_OID_SIZE];
//value
byte SNMPvalType;
unsigned int SNMPvalLen;
byte SNMPval[SNMP_MAX_OID_VAL_SIZE];
};
//print packet
void packetSNMPprint(byte packet[],int packet_size);
//check udp packet
//buffer,size
int packetSNMPcheck(byte packet[],int packet_size);
//return community name
int packetSNMPcommunity(byte packet[],int packet_size,char community[],int community_size);
//read packet to struct
int packetSNMPread(byte packet[],int packet_size, struct OID *oid);
//check oid
unsigned int checkOID( struct OID *oid);
#endif