STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
snmp_msg.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without modification,
11  * are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  * 3. The name of the author may not be used to endorse or promote products
19  * derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30  * OF SUCH DAMAGE.
31  *
32  * Author: Christiaan Simons <christiaan.simons@axon.tv>
33  * Martin Hentschel <info@cl-soft.de>
34  */
35 
36 #ifndef LWIP_HDR_APPS_SNMP_MSG_H
37 #define LWIP_HDR_APPS_SNMP_MSG_H
38 
39 #include "lwip/apps/snmp_opts.h"
40 
41 #if LWIP_SNMP
42 
43 #include "lwip/apps/snmp.h"
44 #include "lwip/apps/snmp_core.h"
45 #include "snmp_pbuf_stream.h"
46 #include "lwip/ip_addr.h"
47 #include "lwip/err.h"
48 
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 /* The listen port of the SNMP agent. Clients have to make their requests to
55  this port. Most standard clients won't work if you change this! */
56 #ifndef SNMP_IN_PORT
57 #define SNMP_IN_PORT 161
58 #endif
59 /* The remote port the SNMP agent sends traps to. Most standard trap sinks won't
60  work if you change this! */
61 #ifndef SNMP_TRAP_PORT
62 #define SNMP_TRAP_PORT 162
63 #endif
64 
65 /* version defines used in PDU */
66 #define SNMP_VERSION_1 0
67 #define SNMP_VERSION_2c 1
68 
69 struct snmp_varbind
70 {
71  /* object identifier */
72  struct snmp_obj_id oid;
73 
74  /* value ASN1 type */
75  u8_t type;
76  /* object value length */
77  u16_t value_len;
78  /* object value */
79  void *value;
80 };
81 
82 struct snmp_varbind_enumerator
83 {
84  struct snmp_pbuf_stream pbuf_stream;
85  u16_t varbind_count;
86 };
87 
88 typedef u8_t snmp_vb_enumerator_err_t;
89 #define SNMP_VB_ENUMERATOR_ERR_OK 0
90 #define SNMP_VB_ENUMERATOR_ERR_EOVB 1
91 #define SNMP_VB_ENUMERATOR_ERR_ASN1ERROR 2
92 #define SNMP_VB_ENUMERATOR_ERR_INVALIDLENGTH 3
93 
94 void snmp_vb_enumerator_init(struct snmp_varbind_enumerator* enumerator, struct pbuf* p, u16_t offset, u16_t length);
95 snmp_vb_enumerator_err_t snmp_vb_enumerator_get_next(struct snmp_varbind_enumerator* enumerator, struct snmp_varbind* varbind);
96 
97 struct snmp_request
98 {
99  /* Communication handle */
100  void *handle;
101  /* source IP address */
102  const ip_addr_t *source_ip;
103  /* source UDP port */
104  u16_t source_port;
105  /* incoming snmp version */
106  u8_t version;
107  /* community name (zero terminated) */
108  u8_t community[SNMP_MAX_COMMUNITY_STR_LEN + 1];
109  /* community string length (exclusive zero term) */
110  u16_t community_strlen;
111  /* request type */
112  u8_t request_type;
113  /* request ID */
114  s32_t request_id;
115  /* error status */
116  s32_t error_status;
117  /* error index */
118  s32_t error_index;
119  /* non-repeaters (getBulkRequest (SNMPv2c)) */
120  s32_t non_repeaters;
121  /* max-repetitions (getBulkRequest (SNMPv2c)) */
122  s32_t max_repetitions;
123 
124  struct pbuf *inbound_pbuf;
125  struct snmp_varbind_enumerator inbound_varbind_enumerator;
126  u16_t inbound_varbind_offset;
127  u16_t inbound_varbind_len;
128 
129  struct pbuf *outbound_pbuf;
130  struct snmp_pbuf_stream outbound_pbuf_stream;
131  u16_t outbound_pdu_offset;
132  u16_t outbound_error_status_offset;
133  u16_t outbound_error_index_offset;
134  u16_t outbound_varbind_offset;
135 
136  u8_t value_buffer[SNMP_MAX_VALUE_SIZE];
137 };
138 
140 extern const char *snmp_community;
142 extern const char *snmp_community_write;
144 extern void* snmp_traps_handle;
145 
146 void snmp_receive(void *handle, struct pbuf *p, const ip_addr_t *source_ip, u16_t port);
147 err_t snmp_sendto(void *handle, struct pbuf *p, const ip_addr_t *dst, u16_t port);
148 u8_t snmp_get_local_ip_for_dst(void* handle, const ip_addr_t *dst, ip_addr_t *result);
149 
150 #ifdef __cplusplus
151 }
152 #endif
153 
154 #endif /* LWIP_SNMP */
155 
156 #endif /* LWIP_HDR_APPS_SNMP_MSG_H */
Definition: pbuf.h:108
s8_t err_t
Definition: err.h:47
#define SNMP_MAX_COMMUNITY_STR_LEN
Definition: snmp_opts.h:160
unsigned char u8_t
Definition: cc.h:38
ip6_addr_t ip_addr_t
Definition: ip_addr.h:194
signed long s32_t
Definition: cc.h:43
#define SNMP_MAX_VALUE_SIZE
Definition: snmp_opts.h:128
unsigned short u16_t
Definition: cc.h:40