Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers snmp_msg.h Source File

snmp_msg.h

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * SNMP Agent message handling structures (internal API, do not use in client code).
00004  */
00005 
00006 /*
00007  * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
00008  * Copyright (c) 2016 Elias Oenal.
00009  * All rights reserved.
00010  *
00011  * Redistribution and use in source and binary forms, with or without modification,
00012  * are permitted provided that the following conditions are met:
00013  *
00014  * 1. Redistributions of source code must retain the above copyright notice,
00015  *    this list of conditions and the following disclaimer.
00016  * 2. Redistributions in binary form must reproduce the above copyright notice,
00017  *    this list of conditions and the following disclaimer in the documentation
00018  *    and/or other materials provided with the distribution.
00019  * 3. The name of the author may not be used to endorse or promote products
00020  *    derived from this software without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00023  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00024  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00025  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00026  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00027  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00030  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00031  * OF SUCH DAMAGE.
00032  *
00033  * Author: Christiaan Simons <christiaan.simons@axon.tv>
00034  *         Martin Hentschel <info@cl-soft.de>
00035  *         Elias Oenal <lwip@eliasoenal.com>
00036  */
00037 
00038 #ifndef LWIP_HDR_APPS_SNMP_MSG_H
00039 #define LWIP_HDR_APPS_SNMP_MSG_H
00040 
00041 #include "lwip/apps/snmp_opts.h"
00042 
00043 #if LWIP_SNMP
00044 
00045 #include "lwip/apps/snmp.h"
00046 #include "lwip/apps/snmp_core.h"
00047 #include "snmp_pbuf_stream.h"
00048 #include "lwip/ip_addr.h"
00049 #include "lwip/err.h"
00050 
00051 #if LWIP_SNMP_V3
00052 #include "snmpv3_priv.h"
00053 #endif
00054 
00055 
00056 #ifdef __cplusplus
00057 extern "C" {
00058 #endif
00059 
00060 /* The listen port of the SNMP agent. Clients have to make their requests to
00061    this port. Most standard clients won't work if you change this! */
00062 #ifndef SNMP_IN_PORT
00063 #define SNMP_IN_PORT 161
00064 #endif
00065 /* The remote port the SNMP agent sends traps to. Most standard trap sinks won't
00066    work if you change this! */
00067 #ifndef SNMP_TRAP_PORT
00068 #define SNMP_TRAP_PORT 162
00069 #endif
00070 
00071 /* version defines used in PDU */
00072 #define SNMP_VERSION_1  0
00073 #define SNMP_VERSION_2c 1
00074 #define SNMP_VERSION_3  3
00075 
00076 struct snmp_varbind_enumerator
00077 {
00078   struct snmp_pbuf_stream pbuf_stream;
00079   u16_t varbind_count;
00080 };
00081 
00082 typedef enum {
00083   SNMP_VB_ENUMERATOR_ERR_OK            = 0,
00084   SNMP_VB_ENUMERATOR_ERR_EOVB          = 1,
00085   SNMP_VB_ENUMERATOR_ERR_ASN1ERROR     = 2,
00086   SNMP_VB_ENUMERATOR_ERR_INVALIDLENGTH = 3
00087 } snmp_vb_enumerator_err_t;
00088 
00089 void snmp_vb_enumerator_init(struct snmp_varbind_enumerator* enumerator, struct pbuf* p, u16_t offset, u16_t length);
00090 snmp_vb_enumerator_err_t snmp_vb_enumerator_get_next(struct snmp_varbind_enumerator* enumerator, struct snmp_varbind* varbind);
00091 
00092 struct snmp_request
00093 {
00094   /* Communication handle */
00095   void *handle;
00096   /* source IP address */
00097   const ip_addr_t *source_ip;
00098   /* source UDP port */
00099   u16_t source_port;
00100   /* incoming snmp version */
00101   u8_t version;
00102   /* community name (zero terminated) */
00103   u8_t community[SNMP_MAX_COMMUNITY_STR_LEN + 1];
00104   /* community string length (exclusive zero term) */
00105   u16_t community_strlen;
00106   /* request type */
00107   u8_t request_type;
00108   /* request ID */
00109   s32_t request_id;
00110   /* error status */
00111   s32_t error_status;
00112   /* error index */
00113   s32_t error_index;
00114   /* non-repeaters (getBulkRequest (SNMPv2c)) */
00115   s32_t non_repeaters;
00116   /* max-repetitions (getBulkRequest (SNMPv2c)) */
00117   s32_t max_repetitions;
00118   
00119 #if LWIP_SNMP_V3
00120   s32_t msg_id;
00121   s32_t msg_max_size;
00122   u8_t  msg_flags;
00123   s32_t msg_security_model;
00124   u8_t  msg_authoritative_engine_id[SNMP_V3_MAX_ENGINE_ID_LENGTH];
00125   u8_t  msg_authoritative_engine_id_len;
00126   s32_t msg_authoritative_engine_boots;
00127   s32_t msg_authoritative_engine_time;
00128   u8_t  msg_user_name[SNMP_V3_MAX_USER_LENGTH];
00129   u8_t  msg_user_name_len;
00130   u8_t  msg_authentication_parameters[SNMP_V3_MAX_AUTH_PARAM_LENGTH];
00131   u8_t  msg_privacy_parameters[SNMP_V3_MAX_PRIV_PARAM_LENGTH];
00132   u8_t  context_engine_id[SNMP_V3_MAX_ENGINE_ID_LENGTH];
00133   u8_t  context_engine_id_len;
00134   u8_t  context_name[SNMP_V3_MAX_ENGINE_ID_LENGTH];
00135   u8_t  context_name_len;
00136 #endif
00137 
00138   struct pbuf *inbound_pbuf;
00139   struct snmp_varbind_enumerator inbound_varbind_enumerator;
00140   u16_t inbound_varbind_offset;
00141   u16_t inbound_varbind_len;
00142   u16_t inbound_padding_len;
00143 
00144   struct pbuf *outbound_pbuf;
00145   struct snmp_pbuf_stream outbound_pbuf_stream;
00146   u16_t outbound_pdu_offset;
00147   u16_t outbound_error_status_offset;
00148   u16_t outbound_error_index_offset;
00149   u16_t outbound_varbind_offset;
00150 #if LWIP_SNMP_V3
00151   u16_t outbound_msg_global_data_offset;
00152   u16_t outbound_msg_global_data_end;
00153   u16_t outbound_msg_security_parameters_str_offset;
00154   u16_t outbound_msg_security_parameters_seq_offset;
00155   u16_t outbound_msg_security_parameters_end;
00156   u16_t outbound_msg_authentication_parameters_offset;
00157   u16_t outbound_scoped_pdu_seq_offset;
00158   u16_t outbound_scoped_pdu_string_offset;
00159 #endif
00160 
00161   u8_t value_buffer[SNMP_MAX_VALUE_SIZE];
00162 };
00163 
00164 /** A helper struct keeping length information about varbinds */
00165 struct snmp_varbind_len
00166 {
00167   u8_t  vb_len_len;
00168   u16_t vb_value_len;
00169   u8_t  oid_len_len;
00170   u16_t oid_value_len;
00171   u8_t  value_len_len;
00172   u16_t value_value_len;
00173 };
00174 
00175 /** Agent community string */
00176 extern const char *snmp_community;
00177 /** Agent community string for write access */
00178 extern const char *snmp_community_write;
00179 /** handle for sending traps */
00180 extern void* snmp_traps_handle;
00181 
00182 void snmp_receive(void *handle, struct pbuf *p, const ip_addr_t *source_ip, u16_t port);
00183 err_t snmp_sendto(void *handle, struct pbuf *p, const ip_addr_t *dst, u16_t port);
00184 u8_t snmp_get_local_ip_for_dst(void* handle, const ip_addr_t *dst, ip_addr_t *result);
00185 err_t snmp_varbind_length(struct snmp_varbind *varbind, struct snmp_varbind_len *len);
00186 err_t snmp_append_outbound_varbind(struct snmp_pbuf_stream *pbuf_stream, struct snmp_varbind* varbind);
00187 
00188 #ifdef __cplusplus
00189 }
00190 #endif
00191 
00192 #endif /* LWIP_SNMP */
00193 
00194 #endif /* LWIP_HDR_APPS_SNMP_MSG_H */