SNMP agent attached to SPI slave

Dependencies:   mbed

Committer:
lorcansmith
Date:
Mon Aug 13 15:07:40 2012 +0000
Revision:
0:2a53a4c3238c
Child:
2:25e12a7fe0aa
v1.1 release includes ioAlarm traps

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lorcansmith 0:2a53a4c3238c 1 /*****************************************************************************
lorcansmith 0:2a53a4c3238c 2 * Copyright Field Electronics Ltd
lorcansmith 0:2a53a4c3238c 3 * File: private_mib.c
lorcansmith 0:2a53a4c3238c 4 * Reference: 3000-A3600-SRC-private_mib
lorcansmith 0:2a53a4c3238c 5 * Content: Header file for private MIB tree structures
lorcansmith 0:2a53a4c3238c 6 * Version: 1.6
lorcansmith 0:2a53a4c3238c 7 * System: mbed gnu compiler
lorcansmith 0:2a53a4c3238c 8 * Target Hardware: mbed LPC1768
lorcansmith 0:2a53a4c3238c 9 * Amendment Record:
lorcansmith 0:2a53a4c3238c 10 * Author: L. Smith for all versions unless otherwise specified
lorcansmith 0:2a53a4c3238c 11 * Initial release
lorcansmith 0:2a53a4c3238c 12 * 0.1 23/11/11: L. Smith
lorcansmith 0:2a53a4c3238c 13 Derived from snmp_structs.h by Christiaan Simons <christiaan.simons@axon.tv>
lorcansmith 0:2a53a4c3238c 14 * 0.2 28/11/11: L. Smith
lorcansmith 0:2a53a4c3238c 15 Add f3k_cpu_version & f3k_mbed_version to scalar values
lorcansmith 0:2a53a4c3238c 16 * 0.3 01/12/11: L. Smith
lorcansmith 0:2a53a4c3238c 17 Replace lwIP SNMP_ENTERPRISE_ID by Field PEN - see http://www.iana.org/assignments/enterprise-numbers
lorcansmith 0:2a53a4c3238c 18 * 0.4 13/12/11: L. Smith
lorcansmith 0:2a53a4c3238c 19 Increase function calls for number of I/O nodes to 32
lorcansmith 0:2a53a4c3238c 20 * 0.5 21/12/11: L. Smith
lorcansmith 0:2a53a4c3238c 21 Increase f3k_system nodes from 3 to 5
lorcansmith 0:2a53a4c3238c 22 * 0.6 22/12/11: L. Smith
lorcansmith 0:2a53a4c3238c 23 Add f3k_comms_set_value() and f3k_comms_set_test() to enable UID change
lorcansmith 0:2a53a4c3238c 24 * 0.7 27/12/11: L. Smith
lorcansmith 0:2a53a4c3238c 25 Add f3k_sys_set_value() and f3k_sys_set_test() to enable UID change
lorcansmith 0:2a53a4c3238c 26 * 0.8 29/12/11: L. Smith
lorcansmith 0:2a53a4c3238c 27 Update f3k_sys_set_value() and f3k_sys_set_test() to enable net address change
lorcansmith 0:2a53a4c3238c 28 * 0.9 30/12/11: L. Smith
lorcansmith 0:2a53a4c3238c 29 Read least sig. (alternate) bytes from I/O channels in snmp_get_f3k_IO_value()
lorcansmith 0:2a53a4c3238c 30 * 1.0 11/01/12: L. Smith
lorcansmith 0:2a53a4c3238c 31 Add breaks in case statement to fix f3k_speed reporting error
lorcansmith 0:2a53a4c3238c 32 * 1.1 30/01/12: L. Smith
lorcansmith 0:2a53a4c3238c 33 Add f3k_SPI_count as f3k_sys_object 5 before f3k_run_scan
lorcansmith 0:2a53a4c3238c 34 * 1.2 02/05/12: L. Smith
lorcansmith 0:2a53a4c3238c 35 Change pointers for RTU unit ID from s32_t to u16_t
lorcansmith 0:2a53a4c3238c 36 * 1.3 19/06/12: L. Smith
lorcansmith 0:2a53a4c3238c 37 Add f3k_IO_mask as R/W f3k_sys_object 7 - hex formatted string
lorcansmith 0:2a53a4c3238c 38 * 1.4 20/06/12: L. Smith
lorcansmith 0:2a53a4c3238c 39 Add snmp_trh_addrs[4] as R/W f3k_comms 8 - trap host SNMP_ASN1_IPADDR
lorcansmith 0:2a53a4c3238c 40 * 1.5 25/07/12: L. Smith
lorcansmith 0:2a53a4c3238c 41 Add snmp_publiccommunity as 9th f3k_comms variable with R/W ability
lorcansmith 0:2a53a4c3238c 42 * 1.6 08/08/12: L. Smith
lorcansmith 0:2a53a4c3238c 43 Add f3k_IO_alarm & f3k_al_mask nodes for I/O alarm strings
lorcansmith 0:2a53a4c3238c 44 *******************************************************************************/
lorcansmith 0:2a53a4c3238c 45
lorcansmith 0:2a53a4c3238c 46 #include "lwip/opt.h"
lorcansmith 0:2a53a4c3238c 47
lorcansmith 0:2a53a4c3238c 48 #if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */
lorcansmith 0:2a53a4c3238c 49
lorcansmith 0:2a53a4c3238c 50 #include <stdlib.h>
lorcansmith 0:2a53a4c3238c 51 #include <string.h>
lorcansmith 0:2a53a4c3238c 52
lorcansmith 0:2a53a4c3238c 53 #include "lwip/snmp.h"
lorcansmith 0:2a53a4c3238c 54 #include "lwip/udp.h"
lorcansmith 0:2a53a4c3238c 55 #include "lwip/snmp_asn1.h"
lorcansmith 0:2a53a4c3238c 56 #include "lwip/snmp_structs.h"
lorcansmith 0:2a53a4c3238c 57 #include "lwip/snmp_msg.h"
lorcansmith 0:2a53a4c3238c 58 #include "IO_file.h"
lorcansmith 0:2a53a4c3238c 59 #include "private_mib.h"
lorcansmith 0:2a53a4c3238c 60
lorcansmith 0:2a53a4c3238c 61 /* mib_f3k integers derived from 3000 CPU */
lorcansmith 0:2a53a4c3238c 62 static u16_t f3k_error = 0,
lorcansmith 0:2a53a4c3238c 63 f3k_num_cards = 0,
lorcansmith 0:2a53a4c3238c 64 f3k_SPI_count = 0,
lorcansmith 0:2a53a4c3238c 65 f3k_run_scan = 0,
lorcansmith 0:2a53a4c3238c 66 f3k_uid = 0,
lorcansmith 0:2a53a4c3238c 67 f3k_protocol = 0;
lorcansmith 0:2a53a4c3238c 68 static u32_t f3k_speed = 0;
lorcansmith 0:2a53a4c3238c 69 static char f3k_fw_version[ 4 ] = {0,0,0,0};
lorcansmith 0:2a53a4c3238c 70 /* v1.3: I/O mask is read/written in SNMP protocol as 8 byte hex string */
lorcansmith 0:2a53a4c3238c 71 static char f3k_IO_mask[ 8 ] = {0,0,0,0,0,0,0,0};
lorcansmith 0:2a53a4c3238c 72
lorcansmith 0:2a53a4c3238c 73 /* lengths of ethernet address strings */
lorcansmith 0:2a53a4c3238c 74 static u16_t snmp_ip_len = 0,
lorcansmith 0:2a53a4c3238c 75 snmp_net_len = 0,
lorcansmith 0:2a53a4c3238c 76 snmp_gwy_len = 0,
lorcansmith 0:2a53a4c3238c 77 snmp_trh_len = 0,
lorcansmith 0:2a53a4c3238c 78 snmp_dns_len = 0;
lorcansmith 0:2a53a4c3238c 79 /* ethernet address strings */
lorcansmith 0:2a53a4c3238c 80 static char snmp_ip_addrs[ 16 ] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
lorcansmith 0:2a53a4c3238c 81 static char snmp_net_mask[ 16 ] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
lorcansmith 0:2a53a4c3238c 82 static char snmp_gwy_addrs[ 16 ] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
lorcansmith 0:2a53a4c3238c 83 static char snmp_dns_addrs[ 16 ] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
lorcansmith 0:2a53a4c3238c 84 static char snmp_trh_addrs[ 16 ] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
lorcansmith 0:2a53a4c3238c 85 //static char snmp_trh_addrs[ 4 ] = {0,0,0,0}; // v1.4: Trap host address
lorcansmith 0:2a53a4c3238c 86
lorcansmith 0:2a53a4c3238c 87
lorcansmith 0:2a53a4c3238c 88 static void f3k_amask_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
lorcansmith 0:2a53a4c3238c 89 static void f3k_amask_get_value(struct obj_def *od, u16_t len, void *value);
lorcansmith 0:2a53a4c3238c 90 static u8_t f3k_amask_set_test(struct obj_def *od, u16_t len, void *value);
lorcansmith 0:2a53a4c3238c 91 static void f3k_amask_set_value(struct obj_def *od, u16_t len, void *value);
lorcansmith 0:2a53a4c3238c 92 static void f3k_alarm_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
lorcansmith 0:2a53a4c3238c 93 static void f3k_alarm_get_value(struct obj_def *od, u16_t len, void *value);
lorcansmith 0:2a53a4c3238c 94 static u8_t f3k_alarm_set_test(struct obj_def *od, u16_t len, void *value);
lorcansmith 0:2a53a4c3238c 95 static void f3k_alarm_set_value(struct obj_def *od, u16_t len, void *value);
lorcansmith 0:2a53a4c3238c 96 static void f3k_IO_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
lorcansmith 0:2a53a4c3238c 97 static void f3k_IO_get_value(struct obj_def *od, u16_t len, void *value);
lorcansmith 0:2a53a4c3238c 98 static void f3k_comms_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
lorcansmith 0:2a53a4c3238c 99 static void f3k_comms_get_value(struct obj_def *od, u16_t len, void *value);
lorcansmith 0:2a53a4c3238c 100 static u8_t f3k_comms_set_test(struct obj_def *od, u16_t len, void *value);
lorcansmith 0:2a53a4c3238c 101 static void f3k_comms_set_value(struct obj_def *od, u16_t len, void *value);
lorcansmith 0:2a53a4c3238c 102 static void f3k_sys_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
lorcansmith 0:2a53a4c3238c 103 static void f3k_sys_get_value(struct obj_def *od, u16_t len, void *value);
lorcansmith 0:2a53a4c3238c 104 static u8_t f3k_sys_set_test(struct obj_def *od, u16_t len, void *value);
lorcansmith 0:2a53a4c3238c 105 static void f3k_sys_set_value(struct obj_def *od, u16_t len, void *value);
lorcansmith 0:2a53a4c3238c 106 void snmp_get_f3k_data( void );
lorcansmith 0:2a53a4c3238c 107 u32_t snmp_get_f3k_IO_value( u8_t index );
lorcansmith 0:2a53a4c3238c 108 void snmp_update_net_addrs( void );
lorcansmith 0:2a53a4c3238c 109 int update_addrs_from_string( char * adrs_str, unsigned char * num_array );
lorcansmith 0:2a53a4c3238c 110
lorcansmith 0:2a53a4c3238c 111 /* the following routines are not used as no tables are used for F3000
lorcansmith 0:2a53a4c3238c 112 static void f3kentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
lorcansmith 0:2a53a4c3238c 113 static void f3kentry_get_value(struct obj_def *od, u16_t len, void *value);
lorcansmith 0:2a53a4c3238c 114
lorcansmith 0:2a53a4c3238c 115 // mib_f3k .1.3.6.1.4.1.SNMP_ENTERPRISE_ID
lorcansmith 0:2a53a4c3238c 116 // index root node for f3kTable
lorcansmith 0:2a53a4c3238c 117 struct mib_list_rootnode f3k_root = {
lorcansmith 0:2a53a4c3238c 118 &f3kentry_get_object_def,
lorcansmith 0:2a53a4c3238c 119 &f3kentry_get_value,
lorcansmith 0:2a53a4c3238c 120 &noleafs_set_test,
lorcansmith 0:2a53a4c3238c 121 &noleafs_set_value,
lorcansmith 0:2a53a4c3238c 122 MIB_NODE_LR,
lorcansmith 0:2a53a4c3238c 123 0,
lorcansmith 0:2a53a4c3238c 124 NULL,
lorcansmith 0:2a53a4c3238c 125 NULL,
lorcansmith 0:2a53a4c3238c 126 0
lorcansmith 0:2a53a4c3238c 127 };
lorcansmith 0:2a53a4c3238c 128
lorcansmith 0:2a53a4c3238c 129 const s32_t f3kentry_ids[2] = { 1, 2 };
lorcansmith 0:2a53a4c3238c 130 struct mib_node* const f3kentry_nodes[2] = {
lorcansmith 0:2a53a4c3238c 131 (struct mib_node*)&f3k_root, (struct mib_node*)&f3k_root,
lorcansmith 0:2a53a4c3238c 132 };
lorcansmith 0:2a53a4c3238c 133 const struct mib_array_node f3kentry = {
lorcansmith 0:2a53a4c3238c 134 &noleafs_get_object_def,
lorcansmith 0:2a53a4c3238c 135 &noleafs_get_value,
lorcansmith 0:2a53a4c3238c 136 &noleafs_set_test,
lorcansmith 0:2a53a4c3238c 137 &noleafs_set_value,
lorcansmith 0:2a53a4c3238c 138 MIB_NODE_AR,
lorcansmith 0:2a53a4c3238c 139 2,
lorcansmith 0:2a53a4c3238c 140 f3kentry_ids,
lorcansmith 0:2a53a4c3238c 141 f3kentry_nodes
lorcansmith 0:2a53a4c3238c 142 };
lorcansmith 0:2a53a4c3238c 143
lorcansmith 0:2a53a4c3238c 144 s32_t f3ktable_id = 1;
lorcansmith 0:2a53a4c3238c 145 struct mib_node* f3ktable_node = (struct mib_node*)&f3kentry;
lorcansmith 0:2a53a4c3238c 146 struct mib_ram_array_node f3ktable = {
lorcansmith 0:2a53a4c3238c 147 &noleafs_get_object_def,
lorcansmith 0:2a53a4c3238c 148 &noleafs_get_value,
lorcansmith 0:2a53a4c3238c 149 &noleafs_set_test,
lorcansmith 0:2a53a4c3238c 150 &noleafs_set_value,
lorcansmith 0:2a53a4c3238c 151 MIB_NODE_RA,
lorcansmith 0:2a53a4c3238c 152 0,
lorcansmith 0:2a53a4c3238c 153 &f3ktable_id,
lorcansmith 0:2a53a4c3238c 154 &f3ktable_node
lorcansmith 0:2a53a4c3238c 155 };
lorcansmith 0:2a53a4c3238c 156 */
lorcansmith 0:2a53a4c3238c 157
lorcansmith 0:2a53a4c3238c 158 /* f3k_al_mask nodes */
lorcansmith 0:2a53a4c3238c 159 const mib_scalar_node f3k_amask_scalar = {
lorcansmith 0:2a53a4c3238c 160 &f3k_amask_get_object_def,
lorcansmith 0:2a53a4c3238c 161 &f3k_amask_get_value,
lorcansmith 0:2a53a4c3238c 162 &f3k_amask_set_test,
lorcansmith 0:2a53a4c3238c 163 &f3k_amask_set_value,
lorcansmith 0:2a53a4c3238c 164 MIB_NODE_SC,
lorcansmith 0:2a53a4c3238c 165 0
lorcansmith 0:2a53a4c3238c 166 };
lorcansmith 0:2a53a4c3238c 167
lorcansmith 0:2a53a4c3238c 168 const s32_t f3k_amask_ids[MAX_ALARM_ID] = { 1, 2, 3, 4, 5, 6, 7, MAX_ALARM_ID };
lorcansmith 0:2a53a4c3238c 169 struct mib_node* const f3k_amask_nodes[MAX_ALARM_ID] = {
lorcansmith 0:2a53a4c3238c 170 (struct mib_node*)&f3k_amask_scalar, (struct mib_node*)&f3k_amask_scalar,
lorcansmith 0:2a53a4c3238c 171 (struct mib_node*)&f3k_amask_scalar, (struct mib_node*)&f3k_amask_scalar,
lorcansmith 0:2a53a4c3238c 172 (struct mib_node*)&f3k_amask_scalar, (struct mib_node*)&f3k_amask_scalar,
lorcansmith 0:2a53a4c3238c 173 (struct mib_node*)&f3k_amask_scalar, (struct mib_node*)&f3k_amask_scalar
lorcansmith 0:2a53a4c3238c 174 };
lorcansmith 0:2a53a4c3238c 175
lorcansmith 0:2a53a4c3238c 176 /* v1.6: f3k_al_mask .1.3.6.1.4.1.SNMP_ENTERPRISE_ID.mib_f3k */
lorcansmith 0:2a53a4c3238c 177 const struct mib_array_node f3k_al_mask = {
lorcansmith 0:2a53a4c3238c 178 &noleafs_get_object_def,
lorcansmith 0:2a53a4c3238c 179 &noleafs_get_value,
lorcansmith 0:2a53a4c3238c 180 &noleafs_set_test,
lorcansmith 0:2a53a4c3238c 181 &noleafs_set_value,
lorcansmith 0:2a53a4c3238c 182 MIB_NODE_AR,
lorcansmith 0:2a53a4c3238c 183 MAX_ALARM_ID,
lorcansmith 0:2a53a4c3238c 184 f3k_amask_ids,
lorcansmith 0:2a53a4c3238c 185 f3k_amask_nodes
lorcansmith 0:2a53a4c3238c 186 };
lorcansmith 0:2a53a4c3238c 187
lorcansmith 0:2a53a4c3238c 188
lorcansmith 0:2a53a4c3238c 189 /* f3k_IO_alarm nodes */
lorcansmith 0:2a53a4c3238c 190 const mib_scalar_node f3k_alarm_scalar = {
lorcansmith 0:2a53a4c3238c 191 &f3k_alarm_get_object_def,
lorcansmith 0:2a53a4c3238c 192 &f3k_alarm_get_value,
lorcansmith 0:2a53a4c3238c 193 &f3k_alarm_set_test,
lorcansmith 0:2a53a4c3238c 194 &f3k_alarm_set_value,
lorcansmith 0:2a53a4c3238c 195 MIB_NODE_SC,
lorcansmith 0:2a53a4c3238c 196 0
lorcansmith 0:2a53a4c3238c 197 };
lorcansmith 0:2a53a4c3238c 198
lorcansmith 0:2a53a4c3238c 199 const s32_t f3k_alarm_ids[MAX_ALARM_ID] = { 1, 2, 3, 4, 5, 6, 7, MAX_ALARM_ID };
lorcansmith 0:2a53a4c3238c 200 struct mib_node* const f3k_alarm_nodes[MAX_ALARM_ID] = {
lorcansmith 0:2a53a4c3238c 201 (struct mib_node*)&f3k_alarm_scalar, (struct mib_node*)&f3k_alarm_scalar,
lorcansmith 0:2a53a4c3238c 202 (struct mib_node*)&f3k_alarm_scalar, (struct mib_node*)&f3k_alarm_scalar,
lorcansmith 0:2a53a4c3238c 203 (struct mib_node*)&f3k_alarm_scalar, (struct mib_node*)&f3k_alarm_scalar,
lorcansmith 0:2a53a4c3238c 204 (struct mib_node*)&f3k_alarm_scalar, (struct mib_node*)&f3k_alarm_scalar
lorcansmith 0:2a53a4c3238c 205 };
lorcansmith 0:2a53a4c3238c 206
lorcansmith 0:2a53a4c3238c 207 /* v1.6: f3k_IO_alarm .1.3.6.1.4.1.SNMP_ENTERPRISE_ID.mib_f3k */
lorcansmith 0:2a53a4c3238c 208 const struct mib_array_node f3k_IO_alarm = {
lorcansmith 0:2a53a4c3238c 209 &noleafs_get_object_def,
lorcansmith 0:2a53a4c3238c 210 &noleafs_get_value,
lorcansmith 0:2a53a4c3238c 211 &noleafs_set_test,
lorcansmith 0:2a53a4c3238c 212 &noleafs_set_value,
lorcansmith 0:2a53a4c3238c 213 MIB_NODE_AR,
lorcansmith 0:2a53a4c3238c 214 MAX_ALARM_ID,
lorcansmith 0:2a53a4c3238c 215 f3k_alarm_ids,
lorcansmith 0:2a53a4c3238c 216 f3k_alarm_nodes
lorcansmith 0:2a53a4c3238c 217 };
lorcansmith 0:2a53a4c3238c 218
lorcansmith 0:2a53a4c3238c 219
lorcansmith 0:2a53a4c3238c 220 /* f3k_IO nodes */
lorcansmith 0:2a53a4c3238c 221 const mib_scalar_node f3k_IO_scalar = {
lorcansmith 0:2a53a4c3238c 222 &f3k_IO_get_object_def,
lorcansmith 0:2a53a4c3238c 223 &f3k_IO_get_value,
lorcansmith 0:2a53a4c3238c 224 &noleafs_set_test,
lorcansmith 0:2a53a4c3238c 225 &noleafs_set_value,
lorcansmith 0:2a53a4c3238c 226 MIB_NODE_SC,
lorcansmith 0:2a53a4c3238c 227 0
lorcansmith 0:2a53a4c3238c 228 };
lorcansmith 0:2a53a4c3238c 229
lorcansmith 0:2a53a4c3238c 230 const s32_t f3k_IO_ids[32] = { 1, 2, 3, 4, 5, 6, 7, 8,
lorcansmith 0:2a53a4c3238c 231 9, 10, 11, 12, 13, 14, 15, 16,
lorcansmith 0:2a53a4c3238c 232 17, 18, 19, 20, 21, 22, 23, 24,
lorcansmith 0:2a53a4c3238c 233 25, 26, 27, 28, 29, 30, 31, 32 };
lorcansmith 0:2a53a4c3238c 234 struct mib_node* const f3k_IO_nodes[32] = {
lorcansmith 0:2a53a4c3238c 235 (struct mib_node*)&f3k_IO_scalar, (struct mib_node*)&f3k_IO_scalar,
lorcansmith 0:2a53a4c3238c 236 (struct mib_node*)&f3k_IO_scalar, (struct mib_node*)&f3k_IO_scalar,
lorcansmith 0:2a53a4c3238c 237 (struct mib_node*)&f3k_IO_scalar, (struct mib_node*)&f3k_IO_scalar,
lorcansmith 0:2a53a4c3238c 238 (struct mib_node*)&f3k_IO_scalar, (struct mib_node*)&f3k_IO_scalar,
lorcansmith 0:2a53a4c3238c 239 (struct mib_node*)&f3k_IO_scalar, (struct mib_node*)&f3k_IO_scalar,
lorcansmith 0:2a53a4c3238c 240 (struct mib_node*)&f3k_IO_scalar, (struct mib_node*)&f3k_IO_scalar,
lorcansmith 0:2a53a4c3238c 241 (struct mib_node*)&f3k_IO_scalar, (struct mib_node*)&f3k_IO_scalar,
lorcansmith 0:2a53a4c3238c 242 (struct mib_node*)&f3k_IO_scalar, (struct mib_node*)&f3k_IO_scalar,
lorcansmith 0:2a53a4c3238c 243 (struct mib_node*)&f3k_IO_scalar, (struct mib_node*)&f3k_IO_scalar,
lorcansmith 0:2a53a4c3238c 244 (struct mib_node*)&f3k_IO_scalar, (struct mib_node*)&f3k_IO_scalar,
lorcansmith 0:2a53a4c3238c 245 (struct mib_node*)&f3k_IO_scalar, (struct mib_node*)&f3k_IO_scalar,
lorcansmith 0:2a53a4c3238c 246 (struct mib_node*)&f3k_IO_scalar, (struct mib_node*)&f3k_IO_scalar,
lorcansmith 0:2a53a4c3238c 247 (struct mib_node*)&f3k_IO_scalar, (struct mib_node*)&f3k_IO_scalar,
lorcansmith 0:2a53a4c3238c 248 (struct mib_node*)&f3k_IO_scalar, (struct mib_node*)&f3k_IO_scalar,
lorcansmith 0:2a53a4c3238c 249 (struct mib_node*)&f3k_IO_scalar, (struct mib_node*)&f3k_IO_scalar,
lorcansmith 0:2a53a4c3238c 250 (struct mib_node*)&f3k_IO_scalar, (struct mib_node*)&f3k_IO_scalar
lorcansmith 0:2a53a4c3238c 251 };
lorcansmith 0:2a53a4c3238c 252 /* v0.3: f3k_IO .1.3.6.1.4.1.SNMP_ENTERPRISE_ID.mib_f3k */
lorcansmith 0:2a53a4c3238c 253 const struct mib_array_node f3k_IO = {
lorcansmith 0:2a53a4c3238c 254 &noleafs_get_object_def,
lorcansmith 0:2a53a4c3238c 255 &noleafs_get_value,
lorcansmith 0:2a53a4c3238c 256 &noleafs_set_test,
lorcansmith 0:2a53a4c3238c 257 &noleafs_set_value,
lorcansmith 0:2a53a4c3238c 258 MIB_NODE_AR,
lorcansmith 0:2a53a4c3238c 259 32,
lorcansmith 0:2a53a4c3238c 260 f3k_IO_ids,
lorcansmith 0:2a53a4c3238c 261 f3k_IO_nodes
lorcansmith 0:2a53a4c3238c 262 };
lorcansmith 0:2a53a4c3238c 263
lorcansmith 0:2a53a4c3238c 264
lorcansmith 0:2a53a4c3238c 265 /* f3k_comms nodes */
lorcansmith 0:2a53a4c3238c 266 const mib_scalar_node f3k_comms_scalar = {
lorcansmith 0:2a53a4c3238c 267 &f3k_comms_get_object_def,
lorcansmith 0:2a53a4c3238c 268 &f3k_comms_get_value,
lorcansmith 0:2a53a4c3238c 269 &f3k_comms_set_test,
lorcansmith 0:2a53a4c3238c 270 &f3k_comms_set_value,
lorcansmith 0:2a53a4c3238c 271 MIB_NODE_SC,
lorcansmith 0:2a53a4c3238c 272 0
lorcansmith 0:2a53a4c3238c 273 };
lorcansmith 0:2a53a4c3238c 274
lorcansmith 0:2a53a4c3238c 275 const s32_t f3k_comms_ids[MAX_COMMS_ID] = { 1, 2, 3, 4, 5, 6, 7, 8, MAX_COMMS_ID };
lorcansmith 0:2a53a4c3238c 276 struct mib_node* const f3k_comms_nodes[MAX_COMMS_ID] = {
lorcansmith 0:2a53a4c3238c 277 (struct mib_node*)&f3k_comms_scalar, (struct mib_node*)&f3k_comms_scalar,
lorcansmith 0:2a53a4c3238c 278 (struct mib_node*)&f3k_comms_scalar, (struct mib_node*)&f3k_comms_scalar,
lorcansmith 0:2a53a4c3238c 279 (struct mib_node*)&f3k_comms_scalar, (struct mib_node*)&f3k_comms_scalar,
lorcansmith 0:2a53a4c3238c 280 (struct mib_node*)&f3k_comms_scalar, (struct mib_node*)&f3k_comms_scalar,
lorcansmith 0:2a53a4c3238c 281 (struct mib_node*)&f3k_comms_scalar
lorcansmith 0:2a53a4c3238c 282 };
lorcansmith 0:2a53a4c3238c 283 /* v0.3: f3k_comms .1.3.6.1.4.1.SNMP_ENTERPRISE_ID.mib_f3k */
lorcansmith 0:2a53a4c3238c 284 const struct mib_array_node f3k_comms = {
lorcansmith 0:2a53a4c3238c 285 &noleafs_get_object_def,
lorcansmith 0:2a53a4c3238c 286 &noleafs_get_value,
lorcansmith 0:2a53a4c3238c 287 &noleafs_set_test,
lorcansmith 0:2a53a4c3238c 288 &noleafs_set_value,
lorcansmith 0:2a53a4c3238c 289 MIB_NODE_AR,
lorcansmith 0:2a53a4c3238c 290 MAX_COMMS_ID,
lorcansmith 0:2a53a4c3238c 291 f3k_comms_ids,
lorcansmith 0:2a53a4c3238c 292 f3k_comms_nodes
lorcansmith 0:2a53a4c3238c 293 };
lorcansmith 0:2a53a4c3238c 294
lorcansmith 0:2a53a4c3238c 295
lorcansmith 0:2a53a4c3238c 296 /* f3k_system nodes */
lorcansmith 0:2a53a4c3238c 297 const mib_scalar_node f3k_sys_scalar = {
lorcansmith 0:2a53a4c3238c 298 &f3k_sys_get_object_def,
lorcansmith 0:2a53a4c3238c 299 &f3k_sys_get_value,
lorcansmith 0:2a53a4c3238c 300 &f3k_sys_set_test,
lorcansmith 0:2a53a4c3238c 301 &f3k_sys_set_value,
lorcansmith 0:2a53a4c3238c 302 MIB_NODE_SC,
lorcansmith 0:2a53a4c3238c 303 0
lorcansmith 0:2a53a4c3238c 304 };
lorcansmith 0:2a53a4c3238c 305
lorcansmith 0:2a53a4c3238c 306 const s32_t f3k_sys_ids[7] = { 1, 2, 3, 4, 5, 6, 7 };
lorcansmith 0:2a53a4c3238c 307 struct mib_node* const f3k_sys_nodes[7] = {
lorcansmith 0:2a53a4c3238c 308 (struct mib_node*)&f3k_sys_scalar, (struct mib_node*)&f3k_sys_scalar,
lorcansmith 0:2a53a4c3238c 309 (struct mib_node*)&f3k_sys_scalar, (struct mib_node*)&f3k_sys_scalar,
lorcansmith 0:2a53a4c3238c 310 (struct mib_node*)&f3k_sys_scalar, (struct mib_node*)&f3k_sys_scalar,
lorcansmith 0:2a53a4c3238c 311 (struct mib_node*)&f3k_sys_scalar
lorcansmith 0:2a53a4c3238c 312 /*, (struct mib_node*)&f3ktable */
lorcansmith 0:2a53a4c3238c 313 };
lorcansmith 0:2a53a4c3238c 314 /* v0.3: f3k_system .1.3.6.1.4.1.SNMP_ENTERPRISE_ID.mib_f3k */
lorcansmith 0:2a53a4c3238c 315 const struct mib_array_node f3k_system = {
lorcansmith 0:2a53a4c3238c 316 &noleafs_get_object_def,
lorcansmith 0:2a53a4c3238c 317 &noleafs_get_value,
lorcansmith 0:2a53a4c3238c 318 &noleafs_set_test,
lorcansmith 0:2a53a4c3238c 319 &noleafs_set_value,
lorcansmith 0:2a53a4c3238c 320 MIB_NODE_AR,
lorcansmith 0:2a53a4c3238c 321 7,
lorcansmith 0:2a53a4c3238c 322 f3k_sys_ids,
lorcansmith 0:2a53a4c3238c 323 f3k_sys_nodes
lorcansmith 0:2a53a4c3238c 324 };
lorcansmith 0:2a53a4c3238c 325
lorcansmith 0:2a53a4c3238c 326 /* 1.6 Add f3k_IO_alarm & f3k_al_mask nodes for I/O alarm strings */
lorcansmith 0:2a53a4c3238c 327 const s32_t f3k_ids[5] = { 1, 2, 3, 4, 5 };
lorcansmith 0:2a53a4c3238c 328 struct mib_node* const f3k_nodes[5] = {
lorcansmith 0:2a53a4c3238c 329 (struct mib_node*)&f3k_system,
lorcansmith 0:2a53a4c3238c 330 (struct mib_node*)&f3k_comms,
lorcansmith 0:2a53a4c3238c 331 (struct mib_node*)&f3k_IO,
lorcansmith 0:2a53a4c3238c 332 (struct mib_node*)&f3k_IO_alarm,
lorcansmith 0:2a53a4c3238c 333 (struct mib_node*)&f3k_al_mask
lorcansmith 0:2a53a4c3238c 334 };
lorcansmith 0:2a53a4c3238c 335 /* v0.3: mib_f3k .1.3.6.1.4.1.SNMP_ENTERPRISE_ID */
lorcansmith 0:2a53a4c3238c 336 /* f3k private node called from mib_array_node mib_link */
lorcansmith 0:2a53a4c3238c 337 const struct mib_array_node mib_f3k = {
lorcansmith 0:2a53a4c3238c 338 &noleafs_get_object_def,
lorcansmith 0:2a53a4c3238c 339 &noleafs_get_value,
lorcansmith 0:2a53a4c3238c 340 &noleafs_set_test,
lorcansmith 0:2a53a4c3238c 341 &noleafs_set_value,
lorcansmith 0:2a53a4c3238c 342 MIB_NODE_AR,
lorcansmith 0:2a53a4c3238c 343 5,
lorcansmith 0:2a53a4c3238c 344 f3k_ids,
lorcansmith 0:2a53a4c3238c 345 f3k_nodes
lorcansmith 0:2a53a4c3238c 346 };
lorcansmith 0:2a53a4c3238c 347
lorcansmith 0:2a53a4c3238c 348
lorcansmith 0:2a53a4c3238c 349 /* link from enterprises node to SNMP system calls via mib_private */
lorcansmith 0:2a53a4c3238c 350 /* v0.2: SNMP_ENTERPRISE_ID .1.3.6.1.4.1
lorcansmith 0:2a53a4c3238c 351 const s32_t private_ids[1] = { SNMP_ENTERPRISE_ID };
lorcansmith 0:2a53a4c3238c 352 struct mib_node* const private_nodes[1] = { (struct mib_node*)&mib_f3k };
lorcansmith 0:2a53a4c3238c 353 const struct mib_array_node mib_enterprise = {
lorcansmith 0:2a53a4c3238c 354 &noleafs_get_object_def,
lorcansmith 0:2a53a4c3238c 355 &noleafs_get_value,
lorcansmith 0:2a53a4c3238c 356 &noleafs_set_test,
lorcansmith 0:2a53a4c3238c 357 &noleafs_set_value,
lorcansmith 0:2a53a4c3238c 358 MIB_NODE_AR,
lorcansmith 0:2a53a4c3238c 359 1,
lorcansmith 0:2a53a4c3238c 360 private_ids,
lorcansmith 0:2a53a4c3238c 361 private_nodes
lorcansmith 0:2a53a4c3238c 362 };
lorcansmith 0:2a53a4c3238c 363 */
lorcansmith 0:2a53a4c3238c 364
lorcansmith 0:2a53a4c3238c 365 /* internet .1.3.6.1 */
lorcansmith 0:2a53a4c3238c 366 /* When using a private MIB, you have to create a file 'private_mib.h' that contains
lorcansmith 0:2a53a4c3238c 367 * a 'struct mib_array_node mib_private' which contains your MIB.
lorcansmith 0:2a53a4c3238c 368 s32_t internet_ids[2] = { 2, 4 };
lorcansmith 0:2a53a4c3238c 369 struct mib_node* const internet_nodes[2] = { (struct mib_node*)&mgmt, (struct mib_node*)&mib_private };
lorcansmith 0:2a53a4c3238c 370 const struct mib_array_node internet = {
lorcansmith 0:2a53a4c3238c 371 &noleafs_get_object_def,
lorcansmith 0:2a53a4c3238c 372 &noleafs_get_value,
lorcansmith 0:2a53a4c3238c 373 &noleafs_set_test,
lorcansmith 0:2a53a4c3238c 374 &noleafs_set_value,
lorcansmith 0:2a53a4c3238c 375 MIB_NODE_AR,
lorcansmith 0:2a53a4c3238c 376 2,
lorcansmith 0:2a53a4c3238c 377 internet_ids,
lorcansmith 0:2a53a4c3238c 378 internet_nodes
lorcansmith 0:2a53a4c3238c 379 };
lorcansmith 0:2a53a4c3238c 380 */
lorcansmith 0:2a53a4c3238c 381
lorcansmith 0:2a53a4c3238c 382
lorcansmith 0:2a53a4c3238c 383 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 384 /* snmp_get_f3k_data:
lorcansmith 0:2a53a4c3238c 385 * Description: Updates SNMP data from data array written by F3000 SPI
lorcansmith 0:2a53a4c3238c 386 * Called by f3k_sys_get_value()
lorcansmith 0:2a53a4c3238c 387 * Parameters: NONE
lorcansmith 0:2a53a4c3238c 388 * Returns: NONE
lorcansmith 0:2a53a4c3238c 389 */
lorcansmith 0:2a53a4c3238c 390 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 391 void snmp_get_f3k_data(void)
lorcansmith 0:2a53a4c3238c 392 {
lorcansmith 0:2a53a4c3238c 393 u8_t comm_cfg;
lorcansmith 0:2a53a4c3238c 394 u8_t f3k_version;
lorcansmith 0:2a53a4c3238c 395
lorcansmith 0:2a53a4c3238c 396 f3k_error = fsvr.get_error();
lorcansmith 0:2a53a4c3238c 397 f3k_num_cards = (u16_t)fsvr.get_byte( NUM_CARD_IDX );
lorcansmith 0:2a53a4c3238c 398 f3k_SPI_count = fsvr.get_SPI_count();
lorcansmith 0:2a53a4c3238c 399 f3k_run_scan = (u16_t)fsvr.get_byte( RUN_SCAN_IDX );
lorcansmith 0:2a53a4c3238c 400 strncpy( f3k_IO_mask, get_hex_mask( mask4_IO_registers ), 8 ); // v1.3: copy mask4_IO_registers as hex
lorcansmith 0:2a53a4c3238c 401 f3k_uid = (u16_t)fsvr.get_byte( UNIT_ID_IDX );
lorcansmith 0:2a53a4c3238c 402 comm_cfg = (u8_t)fsvr.get_byte( COMMS_IDX );
lorcansmith 0:2a53a4c3238c 403 f3k_protocol = (u16_t)(comm_cfg / 16);
lorcansmith 0:2a53a4c3238c 404 switch (comm_cfg & 0x0f)
lorcansmith 0:2a53a4c3238c 405 {
lorcansmith 0:2a53a4c3238c 406 case 2 :
lorcansmith 0:2a53a4c3238c 407 f3k_speed = 600;
lorcansmith 0:2a53a4c3238c 408 break;
lorcansmith 0:2a53a4c3238c 409 case 3 :
lorcansmith 0:2a53a4c3238c 410 f3k_speed = 1200;
lorcansmith 0:2a53a4c3238c 411 break;
lorcansmith 0:2a53a4c3238c 412 case 4 :
lorcansmith 0:2a53a4c3238c 413 f3k_speed = 2400;
lorcansmith 0:2a53a4c3238c 414 break;
lorcansmith 0:2a53a4c3238c 415 case 5 :
lorcansmith 0:2a53a4c3238c 416 f3k_speed = 4800;
lorcansmith 0:2a53a4c3238c 417 break;
lorcansmith 0:2a53a4c3238c 418 case 6 :
lorcansmith 0:2a53a4c3238c 419 f3k_speed = 9600;
lorcansmith 0:2a53a4c3238c 420 break;
lorcansmith 0:2a53a4c3238c 421 case 7 :
lorcansmith 0:2a53a4c3238c 422 f3k_speed = 19200;
lorcansmith 0:2a53a4c3238c 423 break;
lorcansmith 0:2a53a4c3238c 424 case 8 :
lorcansmith 0:2a53a4c3238c 425 f3k_speed = 38400;
lorcansmith 0:2a53a4c3238c 426 break;
lorcansmith 0:2a53a4c3238c 427 case 9 :
lorcansmith 0:2a53a4c3238c 428 f3k_speed = 76800;
lorcansmith 0:2a53a4c3238c 429 break;
lorcansmith 0:2a53a4c3238c 430 default :
lorcansmith 0:2a53a4c3238c 431 f3k_speed = 9600;
lorcansmith 0:2a53a4c3238c 432 break;
lorcansmith 0:2a53a4c3238c 433 }
lorcansmith 0:2a53a4c3238c 434 f3k_version = (u8_t)fsvr.get_byte( VERSION_IDX );
lorcansmith 0:2a53a4c3238c 435 f3k_fw_version[0] = (f3k_version / 16) + '0';
lorcansmith 0:2a53a4c3238c 436 f3k_fw_version[1] = '.';
lorcansmith 0:2a53a4c3238c 437 if ( (f3k_version & 0xf) < 0xa )
lorcansmith 0:2a53a4c3238c 438 {
lorcansmith 0:2a53a4c3238c 439 f3k_fw_version[2] = (f3k_version & 0xf) + '0';
lorcansmith 0:2a53a4c3238c 440 }
lorcansmith 0:2a53a4c3238c 441 else
lorcansmith 0:2a53a4c3238c 442 {
lorcansmith 0:2a53a4c3238c 443 f3k_fw_version[2] = (f3k_version & 0xf) - 0xa + 'A';
lorcansmith 0:2a53a4c3238c 444 }
lorcansmith 0:2a53a4c3238c 445 }
lorcansmith 0:2a53a4c3238c 446
lorcansmith 0:2a53a4c3238c 447 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 448 /* snmp_get_f3k_IO_value:
lorcansmith 0:2a53a4c3238c 449 * Description: Updates SNMP data from I/O data in array written by F3000 SPI
lorcansmith 0:2a53a4c3238c 450 * Called by f3kentry_get_value()
lorcansmith 0:2a53a4c3238c 451 * Parameters: IN: u8_t 1-based index into 0-based Field SPI server array
lorcansmith 0:2a53a4c3238c 452 * Returns: u32_t io_value from Field SPI server array
lorcansmith 0:2a53a4c3238c 453 */
lorcansmith 0:2a53a4c3238c 454 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 455 u32_t snmp_get_f3k_IO_value( u8_t index )
lorcansmith 0:2a53a4c3238c 456 {
lorcansmith 0:2a53a4c3238c 457 unsigned short io_value;
lorcansmith 0:2a53a4c3238c 458
lorcansmith 0:2a53a4c3238c 459 index = index > 0 ? 2 * (index - 1) : index; // index range is 1 to 32
lorcansmith 0:2a53a4c3238c 460 io_value = 256 * fsvr.get_byte( index ); // v0.9: read ms byte from I/O
lorcansmith 0:2a53a4c3238c 461 io_value += fsvr.get_byte( index + 1 ); // v0.9: add ls byte from I/O
lorcansmith 0:2a53a4c3238c 462 return (u32_t)io_value;
lorcansmith 0:2a53a4c3238c 463 }
lorcansmith 0:2a53a4c3238c 464
lorcansmith 0:2a53a4c3238c 465 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 466 /* snmp_update_net_addrs:
lorcansmith 0:2a53a4c3238c 467 * Description: Updates SNMP address strings from ethernet addresses
lorcansmith 0:2a53a4c3238c 468 * v1.4: Add trap host address conversion
lorcansmith 0:2a53a4c3238c 469 * Called by f3k_comms_get_object_def()
lorcansmith 0:2a53a4c3238c 470 * Parameters: NONE
lorcansmith 0:2a53a4c3238c 471 * Returns: NONE
lorcansmith 0:2a53a4c3238c 472 */
lorcansmith 0:2a53a4c3238c 473 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 474 void snmp_update_net_addrs( void )
lorcansmith 0:2a53a4c3238c 475 {
lorcansmith 0:2a53a4c3238c 476 char i;
lorcansmith 0:2a53a4c3238c 477
lorcansmith 0:2a53a4c3238c 478 for ( i = 0; i < 16; i++ )
lorcansmith 0:2a53a4c3238c 479 { // ensure string terminated by 0
lorcansmith 0:2a53a4c3238c 480 snmp_ip_addrs[ i ] = 0;
lorcansmith 0:2a53a4c3238c 481 snmp_net_mask[ i ] = 0;
lorcansmith 0:2a53a4c3238c 482 snmp_gwy_addrs[ i ] = 0;
lorcansmith 0:2a53a4c3238c 483 snmp_dns_addrs[ i ] = 0;
lorcansmith 0:2a53a4c3238c 484 snmp_trh_addrs[ i ] = 0;
lorcansmith 0:2a53a4c3238c 485 }
lorcansmith 0:2a53a4c3238c 486 sprintf( snmp_ip_addrs, "%d.%d.%d.%d", ip_ad[0], ip_ad[1], ip_ad[2], ip_ad[3] );
lorcansmith 0:2a53a4c3238c 487 snmp_ip_len = strlen( snmp_ip_addrs );
lorcansmith 0:2a53a4c3238c 488 sprintf( snmp_net_mask, "%d.%d.%d.%d", msk_ad[0], msk_ad[1], msk_ad[2], msk_ad[3] );
lorcansmith 0:2a53a4c3238c 489 snmp_net_len = strlen( snmp_net_mask );
lorcansmith 0:2a53a4c3238c 490 sprintf( snmp_gwy_addrs, "%d.%d.%d.%d", gwy_ad[0], gwy_ad[1], gwy_ad[2], gwy_ad[3] );
lorcansmith 0:2a53a4c3238c 491 snmp_gwy_len = strlen( snmp_gwy_addrs );
lorcansmith 0:2a53a4c3238c 492 sprintf( snmp_dns_addrs, "%d.%d.%d.%d", dns_ad[0], dns_ad[1], dns_ad[2], dns_ad[3] );
lorcansmith 0:2a53a4c3238c 493 snmp_dns_len = strlen( snmp_dns_addrs );
lorcansmith 0:2a53a4c3238c 494 sprintf( snmp_trh_addrs, "%d.%d.%d.%d", th_ad[0], th_ad[1], th_ad[2], th_ad[3] );
lorcansmith 0:2a53a4c3238c 495 snmp_trh_len = strlen( snmp_trh_addrs );
lorcansmith 0:2a53a4c3238c 496 /* for ( i = 0; i < 4; i++ )
lorcansmith 0:2a53a4c3238c 497 { // copy IP addresses to string
lorcansmith 0:2a53a4c3238c 498 snmp_trh_addrs[ i ] = th_ad[ i ];
lorcansmith 0:2a53a4c3238c 499 } */
lorcansmith 0:2a53a4c3238c 500 }
lorcansmith 0:2a53a4c3238c 501
lorcansmith 0:2a53a4c3238c 502 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 503 /* update_addrs_from_string:
lorcansmith 0:2a53a4c3238c 504 * Description: Reads data from adrs_str into num_array
lorcansmith 0:2a53a4c3238c 505 * Globals used: NONE
lorcansmith 0:2a53a4c3238c 506 * Parameters: IN: char * adrs_str
lorcansmith 0:2a53a4c3238c 507 * OUT: unsigned char * num_array
lorcansmith 0:2a53a4c3238c 508 * Returns: Returns set_ok = 1 if able to set value, 0 otherwise
lorcansmith 0:2a53a4c3238c 509 */
lorcansmith 0:2a53a4c3238c 510 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 511 int update_addrs_from_string( char * adrs_str, unsigned char * num_array )
lorcansmith 0:2a53a4c3238c 512 {
lorcansmith 0:2a53a4c3238c 513 unsigned char c, i, j, digit_found, number_completed;
lorcansmith 0:2a53a4c3238c 514 int set_ok, new_num;
lorcansmith 0:2a53a4c3238c 515
lorcansmith 0:2a53a4c3238c 516 set_ok = 1; // default is good value
lorcansmith 0:2a53a4c3238c 517 new_num = 0;
lorcansmith 0:2a53a4c3238c 518 i = j = 0;
lorcansmith 0:2a53a4c3238c 519 number_completed = digit_found = false;
lorcansmith 0:2a53a4c3238c 520 while ( ((c = adrs_str[ i ]) != 0) && (i++ < 16) )
lorcansmith 0:2a53a4c3238c 521 {
lorcansmith 0:2a53a4c3238c 522 num_array[ j ] = 0;
lorcansmith 0:2a53a4c3238c 523 if ( c < '0' || c > '9' )
lorcansmith 0:2a53a4c3238c 524 { // not a numeric character
lorcansmith 0:2a53a4c3238c 525 if ( digit_found )
lorcansmith 0:2a53a4c3238c 526 {
lorcansmith 0:2a53a4c3238c 527 number_completed = true;
lorcansmith 0:2a53a4c3238c 528 }
lorcansmith 0:2a53a4c3238c 529 }
lorcansmith 0:2a53a4c3238c 530 else // numeric character
lorcansmith 0:2a53a4c3238c 531 {
lorcansmith 0:2a53a4c3238c 532 digit_found = true;
lorcansmith 0:2a53a4c3238c 533 if ( number_completed )
lorcansmith 0:2a53a4c3238c 534 { // test for valid data
lorcansmith 0:2a53a4c3238c 535 if ( (new_num <= 255) && (j < 4) )
lorcansmith 0:2a53a4c3238c 536 { // save number into array
lorcansmith 0:2a53a4c3238c 537 num_array[ j++ ] = new_num;
lorcansmith 0:2a53a4c3238c 538 }
lorcansmith 0:2a53a4c3238c 539 else
lorcansmith 0:2a53a4c3238c 540 {
lorcansmith 0:2a53a4c3238c 541 set_ok = 0;
lorcansmith 0:2a53a4c3238c 542 break;
lorcansmith 0:2a53a4c3238c 543 }
lorcansmith 0:2a53a4c3238c 544 new_num = 0;
lorcansmith 0:2a53a4c3238c 545 }
lorcansmith 0:2a53a4c3238c 546 new_num = 10*new_num + c - '0';
lorcansmith 0:2a53a4c3238c 547 number_completed = false;
lorcansmith 0:2a53a4c3238c 548 } // else numeric character
lorcansmith 0:2a53a4c3238c 549 } // end while
lorcansmith 0:2a53a4c3238c 550 if ( number_completed || (c == 0) )
lorcansmith 0:2a53a4c3238c 551 { // test for valid data
lorcansmith 0:2a53a4c3238c 552 if ( (new_num <= 255) && (j < 4) && (i <= 16) )
lorcansmith 0:2a53a4c3238c 553 { // save last number into array
lorcansmith 0:2a53a4c3238c 554 num_array[ j ] = new_num;
lorcansmith 0:2a53a4c3238c 555 }
lorcansmith 0:2a53a4c3238c 556 else
lorcansmith 0:2a53a4c3238c 557 {
lorcansmith 0:2a53a4c3238c 558 set_ok = 0;
lorcansmith 0:2a53a4c3238c 559 }
lorcansmith 0:2a53a4c3238c 560 }
lorcansmith 0:2a53a4c3238c 561 return set_ok;
lorcansmith 0:2a53a4c3238c 562 }
lorcansmith 0:2a53a4c3238c 563
lorcansmith 0:2a53a4c3238c 564
lorcansmith 0:2a53a4c3238c 565 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 566 /* f3k_sys_get_object_def:
lorcansmith 0:2a53a4c3238c 567 * Description: get definition for F3000 scalar objects
lorcansmith 0:2a53a4c3238c 568 * Called via mib_scalar_node f3k_sys_scalar
lorcansmith 0:2a53a4c3238c 569 * Parameters: IN: u8_t ident_len - length of ID in...
lorcansmith 0:2a53a4c3238c 570 * IN: s32_t *ident - array holding ID
lorcansmith 0:2a53a4c3238c 571 * OUT: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 572 * Returns: NONE
lorcansmith 0:2a53a4c3238c 573 */
lorcansmith 0:2a53a4c3238c 574 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 575 static void
lorcansmith 0:2a53a4c3238c 576 f3k_sys_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
lorcansmith 0:2a53a4c3238c 577 {
lorcansmith 0:2a53a4c3238c 578 u8_t id;
lorcansmith 0:2a53a4c3238c 579
lorcansmith 0:2a53a4c3238c 580 /* return to object name, adding index depth (1) */
lorcansmith 0:2a53a4c3238c 581 ident_len += 1;
lorcansmith 0:2a53a4c3238c 582 ident -= 1;
lorcansmith 0:2a53a4c3238c 583 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 7));
lorcansmith 0:2a53a4c3238c 584 if ((ident_len == 2) &&
lorcansmith 0:2a53a4c3238c 585 (ident[0] > 0) && (ident[0] <= MAX_PRIVATE_ID))
lorcansmith 0:2a53a4c3238c 586 {
lorcansmith 0:2a53a4c3238c 587 od->id_inst_len = ident_len;
lorcansmith 0:2a53a4c3238c 588 od->id_inst_ptr = ident;
lorcansmith 0:2a53a4c3238c 589
lorcansmith 0:2a53a4c3238c 590 id = (u8_t)ident[0];
lorcansmith 0:2a53a4c3238c 591 // printf("\r\nf3k_sys_get_object_def: ident_len %d, id %d\r\n", ident_len, id);
lorcansmith 0:2a53a4c3238c 592 switch (id)
lorcansmith 0:2a53a4c3238c 593 {
lorcansmith 0:2a53a4c3238c 594 case 1: /* f3k_fw_version */
lorcansmith 0:2a53a4c3238c 595 od->instance = MIB_OBJECT_SCALAR;
lorcansmith 0:2a53a4c3238c 596 od->access = MIB_OBJECT_READ_ONLY;
lorcansmith 0:2a53a4c3238c 597 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
lorcansmith 0:2a53a4c3238c 598 od->v_len = 3;
lorcansmith 0:2a53a4c3238c 599 break;
lorcansmith 0:2a53a4c3238c 600 case 2: /* snmp_fw_version */
lorcansmith 0:2a53a4c3238c 601 od->instance = MIB_OBJECT_SCALAR;
lorcansmith 0:2a53a4c3238c 602 od->access = MIB_OBJECT_READ_ONLY;
lorcansmith 0:2a53a4c3238c 603 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
lorcansmith 0:2a53a4c3238c 604 od->v_len = 4;
lorcansmith 0:2a53a4c3238c 605 break;
lorcansmith 0:2a53a4c3238c 606 case 3: /* f3k_error */
lorcansmith 0:2a53a4c3238c 607 case 4: /* f3k_num_cards */
lorcansmith 0:2a53a4c3238c 608 od->instance = MIB_OBJECT_SCALAR;
lorcansmith 0:2a53a4c3238c 609 od->access = MIB_OBJECT_READ_ONLY;
lorcansmith 0:2a53a4c3238c 610 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
lorcansmith 0:2a53a4c3238c 611 od->v_len = sizeof(u32_t);
lorcansmith 0:2a53a4c3238c 612 break;
lorcansmith 0:2a53a4c3238c 613 case 5: /* f3k_SPI_count */
lorcansmith 0:2a53a4c3238c 614 od->instance = MIB_OBJECT_SCALAR;
lorcansmith 0:2a53a4c3238c 615 od->access = MIB_OBJECT_READ_ONLY;
lorcansmith 0:2a53a4c3238c 616 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE);
lorcansmith 0:2a53a4c3238c 617 od->v_len = sizeof(u32_t);
lorcansmith 0:2a53a4c3238c 618 break;
lorcansmith 0:2a53a4c3238c 619 case 6: /* f3k_run_scan */
lorcansmith 0:2a53a4c3238c 620 od->instance = MIB_OBJECT_SCALAR;
lorcansmith 0:2a53a4c3238c 621 od->access = MIB_OBJECT_READ_WRITE;
lorcansmith 0:2a53a4c3238c 622 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
lorcansmith 0:2a53a4c3238c 623 od->v_len = sizeof(u32_t);
lorcansmith 0:2a53a4c3238c 624 break;
lorcansmith 0:2a53a4c3238c 625 case 7: /* v1.3: f3k_IO_mask */
lorcansmith 0:2a53a4c3238c 626 od->instance = MIB_OBJECT_SCALAR;
lorcansmith 0:2a53a4c3238c 627 od->access = MIB_OBJECT_READ_WRITE;
lorcansmith 0:2a53a4c3238c 628 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
lorcansmith 0:2a53a4c3238c 629 od->v_len = 8;
lorcansmith 0:2a53a4c3238c 630 break;
lorcansmith 0:2a53a4c3238c 631 } // end switch
lorcansmith 0:2a53a4c3238c 632 }
lorcansmith 0:2a53a4c3238c 633 else
lorcansmith 0:2a53a4c3238c 634 {
lorcansmith 0:2a53a4c3238c 635 LWIP_DEBUGF(SNMP_MIB_DEBUG,("f3k_sys_get_object_def: no scalar\n"));
lorcansmith 0:2a53a4c3238c 636 od->instance = MIB_OBJECT_NONE;
lorcansmith 0:2a53a4c3238c 637 }
lorcansmith 0:2a53a4c3238c 638 }
lorcansmith 0:2a53a4c3238c 639
lorcansmith 0:2a53a4c3238c 640 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 641 /* f3k_sys_get_value:
lorcansmith 0:2a53a4c3238c 642 * Description: Returns f3k scalar object value
lorcansmith 0:2a53a4c3238c 643 * @param ident points to objectname.0 (object id trailer)
lorcansmith 0:2a53a4c3238c 644 * Parameters: IN: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 645 * IN: u16_t len - return value space (in bytes)
lorcansmith 0:2a53a4c3238c 646 * OUT: void *value - points to (varbind) space to copy value into
lorcansmith 0:2a53a4c3238c 647 * Returns: NONE
lorcansmith 0:2a53a4c3238c 648 */
lorcansmith 0:2a53a4c3238c 649 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 650 static void
lorcansmith 0:2a53a4c3238c 651 f3k_sys_get_value(struct obj_def *od, u16_t len, void *value)
lorcansmith 0:2a53a4c3238c 652 {
lorcansmith 0:2a53a4c3238c 653 u32_t *uint_ptr = (u32_t*)value;
lorcansmith 0:2a53a4c3238c 654 u8_t *uchr_ptr = (u8_t*)value;
lorcansmith 0:2a53a4c3238c 655 u8_t id;
lorcansmith 0:2a53a4c3238c 656 u8_t i = 0; // character pointer for copying unterminated strings
lorcansmith 0:2a53a4c3238c 657
lorcansmith 0:2a53a4c3238c 658 LWIP_UNUSED_ARG(len);
lorcansmith 0:2a53a4c3238c 659 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= MAX_PRIVATE_ID));
lorcansmith 0:2a53a4c3238c 660 snmp_get_f3k_data(); // read the data from the SPI array
lorcansmith 0:2a53a4c3238c 661 id = (u8_t)od->id_inst_ptr[0];
lorcansmith 0:2a53a4c3238c 662 switch ( id )
lorcansmith 0:2a53a4c3238c 663 {
lorcansmith 0:2a53a4c3238c 664 case 1: /* f3k_fw_version */
lorcansmith 0:2a53a4c3238c 665 while (i < len) {
lorcansmith 0:2a53a4c3238c 666 *(uchr_ptr++) = f3k_fw_version[ i++ ];
lorcansmith 0:2a53a4c3238c 667 }
lorcansmith 0:2a53a4c3238c 668 break;
lorcansmith 0:2a53a4c3238c 669 case 2: /* snmp_fw_version */
lorcansmith 0:2a53a4c3238c 670 while (i < len) {
lorcansmith 0:2a53a4c3238c 671 *(uchr_ptr++) = snmp_fw_version[ i++ ];
lorcansmith 0:2a53a4c3238c 672 }
lorcansmith 0:2a53a4c3238c 673 break;
lorcansmith 0:2a53a4c3238c 674 case 3: /* f3k_error */
lorcansmith 0:2a53a4c3238c 675 *uint_ptr = f3k_error;
lorcansmith 0:2a53a4c3238c 676 break;
lorcansmith 0:2a53a4c3238c 677 case 4: /* f3k_num_cards */
lorcansmith 0:2a53a4c3238c 678 *uint_ptr = f3k_num_cards;
lorcansmith 0:2a53a4c3238c 679 break;
lorcansmith 0:2a53a4c3238c 680 case 5: /* f3k_SPI_count */
lorcansmith 0:2a53a4c3238c 681 *uint_ptr = f3k_SPI_count;
lorcansmith 0:2a53a4c3238c 682 break;
lorcansmith 0:2a53a4c3238c 683 case 6: /* f3k_run_scan */
lorcansmith 0:2a53a4c3238c 684 *uint_ptr = f3k_run_scan;
lorcansmith 0:2a53a4c3238c 685 break;
lorcansmith 0:2a53a4c3238c 686 case 7: /* v1.3: f3k_IO_mask */
lorcansmith 0:2a53a4c3238c 687 while (i < len) {
lorcansmith 0:2a53a4c3238c 688 *(uchr_ptr++) = f3k_IO_mask[ i++ ];
lorcansmith 0:2a53a4c3238c 689 }
lorcansmith 0:2a53a4c3238c 690 break;
lorcansmith 0:2a53a4c3238c 691 }
lorcansmith 0:2a53a4c3238c 692 }
lorcansmith 0:2a53a4c3238c 693
lorcansmith 0:2a53a4c3238c 694 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 695 /* f3k_sys_set_test:
lorcansmith 0:2a53a4c3238c 696 * Description: Test f3k_ object value before setting
lorcansmith 0:2a53a4c3238c 697 * Parameters: IN: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 698 * IN: u16_t len - return value space (in bytes) - NOT USED
lorcansmith 0:2a53a4c3238c 699 * OUT: void *value - points to (varbind) space to copy value from
lorcansmith 0:2a53a4c3238c 700 * Returns: Returns set_ok = 1 if able to set value, 0 otherwise
lorcansmith 0:2a53a4c3238c 701 */
lorcansmith 0:2a53a4c3238c 702 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 703 static u8_t
lorcansmith 0:2a53a4c3238c 704 f3k_sys_set_test(struct obj_def *od, u16_t len, void *value)
lorcansmith 0:2a53a4c3238c 705 {
lorcansmith 0:2a53a4c3238c 706 u8_t id, set_ok;
lorcansmith 0:2a53a4c3238c 707 u8_t i = 0;
lorcansmith 0:2a53a4c3238c 708 u8_t * uc_ptr = (u8_t*)value; // char pointer to first byte in value
lorcansmith 0:2a53a4c3238c 709
lorcansmith 0:2a53a4c3238c 710 LWIP_UNUSED_ARG(len);
lorcansmith 0:2a53a4c3238c 711 set_ok = 0;
lorcansmith 0:2a53a4c3238c 712 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 7));
lorcansmith 0:2a53a4c3238c 713 id = (u8_t)od->id_inst_ptr[0];
lorcansmith 0:2a53a4c3238c 714 // printf("\r\nf3k_sys_set_test: id %d\r\n", id);
lorcansmith 0:2a53a4c3238c 715 if ( id == 6 )
lorcansmith 0:2a53a4c3238c 716 { /* f3k_run_scan */
lorcansmith 0:2a53a4c3238c 717 s32_t *sint_ptr = (s32_t*)value;
lorcansmith 0:2a53a4c3238c 718
lorcansmith 0:2a53a4c3238c 719 if ( (*sint_ptr == 0) || (*sint_ptr == 1) )
lorcansmith 0:2a53a4c3238c 720 {
lorcansmith 0:2a53a4c3238c 721 set_ok = 1;
lorcansmith 0:2a53a4c3238c 722 }
lorcansmith 0:2a53a4c3238c 723 }
lorcansmith 0:2a53a4c3238c 724 else if ( id == 7 )
lorcansmith 0:2a53a4c3238c 725 { /* v1.3: f3k_IO_mask */
lorcansmith 0:2a53a4c3238c 726 if ( len <= 8 )
lorcansmith 0:2a53a4c3238c 727 { // ensure all digits are hexadecimal
lorcansmith 0:2a53a4c3238c 728 set_ok = 1;
lorcansmith 0:2a53a4c3238c 729 for ( i = 0; i < len; i++ )
lorcansmith 0:2a53a4c3238c 730 {
lorcansmith 0:2a53a4c3238c 731 if ( !isxdigit( *(uc_ptr++) ) )
lorcansmith 0:2a53a4c3238c 732 {
lorcansmith 0:2a53a4c3238c 733 set_ok = 0; // invalid hexadecimal digit
lorcansmith 0:2a53a4c3238c 734 break; // so quit
lorcansmith 0:2a53a4c3238c 735 }
lorcansmith 0:2a53a4c3238c 736 }
lorcansmith 0:2a53a4c3238c 737 }
lorcansmith 0:2a53a4c3238c 738 }
lorcansmith 0:2a53a4c3238c 739 return set_ok;
lorcansmith 0:2a53a4c3238c 740 }
lorcansmith 0:2a53a4c3238c 741
lorcansmith 0:2a53a4c3238c 742 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 743 /* f3k_sys_set_value:
lorcansmith 0:2a53a4c3238c 744 * Description: Returns f3k scalar object value
lorcansmith 0:2a53a4c3238c 745 * Parameters: IN: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 746 * IN: u16_t len - return value space (in bytes) - NOT USED
lorcansmith 0:2a53a4c3238c 747 * OUT: void *value - points to (varbind) space to copy value from
lorcansmith 0:2a53a4c3238c 748 * Returns: NONE
lorcansmith 0:2a53a4c3238c 749 */
lorcansmith 0:2a53a4c3238c 750 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 751 static void
lorcansmith 0:2a53a4c3238c 752 f3k_sys_set_value(struct obj_def *od, u16_t len, void *value)
lorcansmith 0:2a53a4c3238c 753 {
lorcansmith 0:2a53a4c3238c 754 u8_t id;
lorcansmith 0:2a53a4c3238c 755 u8_t * uc_ptr = (u8_t*)value; // char pointer to first byte in value
lorcansmith 0:2a53a4c3238c 756
lorcansmith 0:2a53a4c3238c 757 // LWIP_UNUSED_ARG(len);
lorcansmith 0:2a53a4c3238c 758 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 7));
lorcansmith 0:2a53a4c3238c 759 id = (u8_t)od->id_inst_ptr[0];
lorcansmith 0:2a53a4c3238c 760 if ( id == 6 )
lorcansmith 0:2a53a4c3238c 761 { /* f3k_run_scan */
lorcansmith 0:2a53a4c3238c 762 cmd_buf[ RUN_SCAN_CMD ] = *uc_ptr;
lorcansmith 0:2a53a4c3238c 763 cmd_buf[ 0 ] = cmd_buf[ RUN_SCAN_CMD ]; // tell the 3000 cpu data available
lorcansmith 0:2a53a4c3238c 764 new_cmd_idx = RUN_SCAN_CMD;
lorcansmith 0:2a53a4c3238c 765 fsvr.put_byte( RUN_SCAN_IDX, cmd_buf[ RUN_SCAN_CMD ] );
lorcansmith 0:2a53a4c3238c 766 }
lorcansmith 0:2a53a4c3238c 767 else if ( id == 7 )
lorcansmith 0:2a53a4c3238c 768 { /* v1.3: f3k_IO_mask */
lorcansmith 0:2a53a4c3238c 769 mask4_IO_registers = convert2decimal( uc_ptr, len );
lorcansmith 0:2a53a4c3238c 770 net_addrs_set = true; // save mask to file system
lorcansmith 0:2a53a4c3238c 771 }
lorcansmith 0:2a53a4c3238c 772 }
lorcansmith 0:2a53a4c3238c 773
lorcansmith 0:2a53a4c3238c 774
lorcansmith 0:2a53a4c3238c 775 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 776 /* f3k_comms_get_object_def:
lorcansmith 0:2a53a4c3238c 777 * Description: get definition for F3000 scalar objects
lorcansmith 0:2a53a4c3238c 778 * Called via mib_scalar_node f3k_comms_scalar
lorcansmith 0:2a53a4c3238c 779 * Parameters: IN: u8_t ident_len - length of ID in...
lorcansmith 0:2a53a4c3238c 780 * IN: s32_t *ident - array holding ID
lorcansmith 0:2a53a4c3238c 781 * OUT: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 782 * Returns: NONE
lorcansmith 0:2a53a4c3238c 783 */
lorcansmith 0:2a53a4c3238c 784 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 785 static void
lorcansmith 0:2a53a4c3238c 786 f3k_comms_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
lorcansmith 0:2a53a4c3238c 787 {
lorcansmith 0:2a53a4c3238c 788 u8_t id;
lorcansmith 0:2a53a4c3238c 789 /* return to object name, adding index depth (1) */
lorcansmith 0:2a53a4c3238c 790 ident_len += 1;
lorcansmith 0:2a53a4c3238c 791 ident -= 1;
lorcansmith 0:2a53a4c3238c 792 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
lorcansmith 0:2a53a4c3238c 793 if ((ident_len == 2) &&
lorcansmith 0:2a53a4c3238c 794 (ident[0] > 0) && (ident[0] <= MAX_COMMS_ID)) // v1.5: change from MAX_PRIVATE_ID
lorcansmith 0:2a53a4c3238c 795 {
lorcansmith 0:2a53a4c3238c 796 od->id_inst_len = ident_len;
lorcansmith 0:2a53a4c3238c 797 od->id_inst_ptr = ident;
lorcansmith 0:2a53a4c3238c 798 id = (u8_t)ident[0];
lorcansmith 0:2a53a4c3238c 799 // printf("\r\nf3k_comms_get_object_def: ident_len %d, id %d\r\n", ident_len, id);
lorcansmith 0:2a53a4c3238c 800 snmp_update_net_addrs();
lorcansmith 0:2a53a4c3238c 801 switch (id)
lorcansmith 0:2a53a4c3238c 802 {
lorcansmith 0:2a53a4c3238c 803 case 1: /* RTU unit ID */
lorcansmith 0:2a53a4c3238c 804 od->instance = MIB_OBJECT_SCALAR;
lorcansmith 0:2a53a4c3238c 805 od->access = MIB_OBJECT_READ_WRITE;
lorcansmith 0:2a53a4c3238c 806 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
lorcansmith 0:2a53a4c3238c 807 od->v_len = sizeof(u16_t); // v1.2: changed from u32_t
lorcansmith 0:2a53a4c3238c 808 break;
lorcansmith 0:2a53a4c3238c 809 case 2: /* RTU baud rate */
lorcansmith 0:2a53a4c3238c 810 case 3: /* RTU protocol */
lorcansmith 0:2a53a4c3238c 811 od->instance = MIB_OBJECT_SCALAR;
lorcansmith 0:2a53a4c3238c 812 od->access = MIB_OBJECT_READ_ONLY;
lorcansmith 0:2a53a4c3238c 813 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
lorcansmith 0:2a53a4c3238c 814 od->v_len = sizeof(u16_t); // v1.2: changed from u32_t
lorcansmith 0:2a53a4c3238c 815 break;
lorcansmith 0:2a53a4c3238c 816 case 4: /* IP address */
lorcansmith 0:2a53a4c3238c 817 od->instance = MIB_OBJECT_SCALAR;
lorcansmith 0:2a53a4c3238c 818 od->access = MIB_OBJECT_READ_WRITE;
lorcansmith 0:2a53a4c3238c 819 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
lorcansmith 0:2a53a4c3238c 820 od->v_len = snmp_ip_len;
lorcansmith 0:2a53a4c3238c 821 break;
lorcansmith 0:2a53a4c3238c 822 case 5: /* net mask */
lorcansmith 0:2a53a4c3238c 823 od->instance = MIB_OBJECT_SCALAR;
lorcansmith 0:2a53a4c3238c 824 od->access = MIB_OBJECT_READ_WRITE;
lorcansmith 0:2a53a4c3238c 825 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
lorcansmith 0:2a53a4c3238c 826 od->v_len = snmp_net_len;
lorcansmith 0:2a53a4c3238c 827 break;
lorcansmith 0:2a53a4c3238c 828 case 6: /* Gateway address */
lorcansmith 0:2a53a4c3238c 829 od->instance = MIB_OBJECT_SCALAR;
lorcansmith 0:2a53a4c3238c 830 od->access = MIB_OBJECT_READ_WRITE;
lorcansmith 0:2a53a4c3238c 831 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
lorcansmith 0:2a53a4c3238c 832 od->v_len = snmp_gwy_len;
lorcansmith 0:2a53a4c3238c 833 break;
lorcansmith 0:2a53a4c3238c 834 case 7: /* DNS address */
lorcansmith 0:2a53a4c3238c 835 od->instance = MIB_OBJECT_SCALAR;
lorcansmith 0:2a53a4c3238c 836 od->access = MIB_OBJECT_READ_WRITE;
lorcansmith 0:2a53a4c3238c 837 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
lorcansmith 0:2a53a4c3238c 838 od->v_len = snmp_dns_len;
lorcansmith 0:2a53a4c3238c 839 break;
lorcansmith 0:2a53a4c3238c 840 case 8: /* v1.4: Trap host address */
lorcansmith 0:2a53a4c3238c 841 od->instance = MIB_OBJECT_SCALAR;
lorcansmith 0:2a53a4c3238c 842 od->access = MIB_OBJECT_READ_WRITE;
lorcansmith 0:2a53a4c3238c 843 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
lorcansmith 0:2a53a4c3238c 844 od->v_len = snmp_trh_len;
lorcansmith 0:2a53a4c3238c 845 break;
lorcansmith 0:2a53a4c3238c 846 case 9: /* v1.5: community string */
lorcansmith 0:2a53a4c3238c 847 od->instance = MIB_OBJECT_SCALAR;
lorcansmith 0:2a53a4c3238c 848 od->access = MIB_OBJECT_READ_WRITE;
lorcansmith 0:2a53a4c3238c 849 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
lorcansmith 0:2a53a4c3238c 850 od->v_len = strlen(snmp_publiccommunity);
lorcansmith 0:2a53a4c3238c 851 break;
lorcansmith 0:2a53a4c3238c 852 } // end switch
lorcansmith 0:2a53a4c3238c 853 }
lorcansmith 0:2a53a4c3238c 854 else
lorcansmith 0:2a53a4c3238c 855 {
lorcansmith 0:2a53a4c3238c 856 LWIP_DEBUGF(SNMP_MIB_DEBUG,("f3k_comms_get_object_def: no scalar\n"));
lorcansmith 0:2a53a4c3238c 857 od->instance = MIB_OBJECT_NONE;
lorcansmith 0:2a53a4c3238c 858 }
lorcansmith 0:2a53a4c3238c 859 }
lorcansmith 0:2a53a4c3238c 860
lorcansmith 0:2a53a4c3238c 861 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 862 /* f3k_comms_get_value:
lorcansmith 0:2a53a4c3238c 863 * Description: Returns f3k scalar object value
lorcansmith 0:2a53a4c3238c 864 * @param ident points to objectname.0 (object id trailer)
lorcansmith 0:2a53a4c3238c 865 * Parameters: IN: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 866 * IN: u16_t len - return value space (in bytes)
lorcansmith 0:2a53a4c3238c 867 * OUT: void *value - points to (varbind) space to copy value into
lorcansmith 0:2a53a4c3238c 868 * Returns: NONE
lorcansmith 0:2a53a4c3238c 869 */
lorcansmith 0:2a53a4c3238c 870 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 871 static void
lorcansmith 0:2a53a4c3238c 872 f3k_comms_get_value(struct obj_def *od, u16_t len, void *value)
lorcansmith 0:2a53a4c3238c 873 {
lorcansmith 0:2a53a4c3238c 874 u32_t *uint_ptr = (u32_t*)value;
lorcansmith 0:2a53a4c3238c 875 u8_t * uchr_ptr = (u8_t*)value;
lorcansmith 0:2a53a4c3238c 876 u8_t id;
lorcansmith 0:2a53a4c3238c 877 u8_t i = 0;
lorcansmith 0:2a53a4c3238c 878
lorcansmith 0:2a53a4c3238c 879 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= MAX_COMMS_ID));
lorcansmith 0:2a53a4c3238c 880 snmp_get_f3k_data(); // read the data from the SPI array
lorcansmith 0:2a53a4c3238c 881 id = (u8_t)od->id_inst_ptr[0];
lorcansmith 0:2a53a4c3238c 882 switch (id)
lorcansmith 0:2a53a4c3238c 883 {
lorcansmith 0:2a53a4c3238c 884 case 1: /* RTU unit ID */
lorcansmith 0:2a53a4c3238c 885 *uint_ptr = f3k_uid;
lorcansmith 0:2a53a4c3238c 886 break;
lorcansmith 0:2a53a4c3238c 887 case 2: /* RTU baud rate */
lorcansmith 0:2a53a4c3238c 888 *uint_ptr = f3k_speed;
lorcansmith 0:2a53a4c3238c 889 break;
lorcansmith 0:2a53a4c3238c 890 case 3: /* RTU protocol */
lorcansmith 0:2a53a4c3238c 891 *uint_ptr = f3k_protocol;
lorcansmith 0:2a53a4c3238c 892 break;
lorcansmith 0:2a53a4c3238c 893 case 4: /* IP address */
lorcansmith 0:2a53a4c3238c 894 while (i < len) {
lorcansmith 0:2a53a4c3238c 895 *(uchr_ptr++) = snmp_ip_addrs[ i++ ];
lorcansmith 0:2a53a4c3238c 896 }
lorcansmith 0:2a53a4c3238c 897 break;
lorcansmith 0:2a53a4c3238c 898 case 5: /* net mask */
lorcansmith 0:2a53a4c3238c 899 while (i < len) {
lorcansmith 0:2a53a4c3238c 900 *(uchr_ptr++) = snmp_net_mask[ i++ ];
lorcansmith 0:2a53a4c3238c 901 }
lorcansmith 0:2a53a4c3238c 902 break;
lorcansmith 0:2a53a4c3238c 903 case 6: /* Gateway address */
lorcansmith 0:2a53a4c3238c 904 while (i < len) {
lorcansmith 0:2a53a4c3238c 905 *(uchr_ptr++) = snmp_gwy_addrs[ i++ ];
lorcansmith 0:2a53a4c3238c 906 }
lorcansmith 0:2a53a4c3238c 907 break;
lorcansmith 0:2a53a4c3238c 908 case 7: /* DNS address */
lorcansmith 0:2a53a4c3238c 909 while (i < len) {
lorcansmith 0:2a53a4c3238c 910 *(uchr_ptr++) = snmp_dns_addrs[ i++ ];
lorcansmith 0:2a53a4c3238c 911 }
lorcansmith 0:2a53a4c3238c 912 break;
lorcansmith 0:2a53a4c3238c 913 case 8: /* v1.4: Trap host address */
lorcansmith 0:2a53a4c3238c 914 while (i < len) {
lorcansmith 0:2a53a4c3238c 915 *(uchr_ptr++) = snmp_trh_addrs[ i++ ];
lorcansmith 0:2a53a4c3238c 916 }
lorcansmith 0:2a53a4c3238c 917 case 9: /* v1.5: community string */
lorcansmith 0:2a53a4c3238c 918 while (i < len) {
lorcansmith 0:2a53a4c3238c 919 *(uchr_ptr++) = snmp_publiccommunity[ i++ ];
lorcansmith 0:2a53a4c3238c 920 }
lorcansmith 0:2a53a4c3238c 921 break;
lorcansmith 0:2a53a4c3238c 922 }
lorcansmith 0:2a53a4c3238c 923 }
lorcansmith 0:2a53a4c3238c 924
lorcansmith 0:2a53a4c3238c 925 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 926 /* f3k_comms_set_test:
lorcansmith 0:2a53a4c3238c 927 * Description: Test f3k_comms object value before setting
lorcansmith 0:2a53a4c3238c 928 * Parameters: IN: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 929 * IN: u16_t len - return value space (in bytes) - NOT USED
lorcansmith 0:2a53a4c3238c 930 * OUT: void *value - points to (varbind) space to copy value from
lorcansmith 0:2a53a4c3238c 931 * Returns: Returns set_ok = 1 if able to set value, 0 otherwise
lorcansmith 0:2a53a4c3238c 932 */
lorcansmith 0:2a53a4c3238c 933 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 934 static u8_t
lorcansmith 0:2a53a4c3238c 935 f3k_comms_set_test(struct obj_def *od, u16_t len, void *value)
lorcansmith 0:2a53a4c3238c 936 {
lorcansmith 0:2a53a4c3238c 937 u8_t id, set_ok, i;
lorcansmith 0:2a53a4c3238c 938 u8_t * uc_ptr;
lorcansmith 0:2a53a4c3238c 939 u16_t *uint_ptr = (u16_t*)value; // v1.2: changed from s32_t
lorcansmith 0:2a53a4c3238c 940 char test_addrs[16];
lorcansmith 0:2a53a4c3238c 941 unsigned char test_ad[4];
lorcansmith 0:2a53a4c3238c 942
lorcansmith 0:2a53a4c3238c 943 set_ok = i = 0;
lorcansmith 0:2a53a4c3238c 944 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= MAX_COMMS_ID));
lorcansmith 0:2a53a4c3238c 945 uc_ptr = (u8_t*)value; // char pointer to first byte in value
lorcansmith 0:2a53a4c3238c 946 id = (u8_t)od->id_inst_ptr[0];
lorcansmith 0:2a53a4c3238c 947 // printf("\r\nf3k_comms_set_test: id %d, len %d\r\n", id, len);
lorcansmith 0:2a53a4c3238c 948 switch ( id )
lorcansmith 0:2a53a4c3238c 949 {
lorcansmith 0:2a53a4c3238c 950 case 1: /* RTU unit ID */
lorcansmith 0:2a53a4c3238c 951 if ( *uint_ptr < 255 )
lorcansmith 0:2a53a4c3238c 952 {
lorcansmith 0:2a53a4c3238c 953 set_ok = 1;
lorcansmith 0:2a53a4c3238c 954 }
lorcansmith 0:2a53a4c3238c 955 break;
lorcansmith 0:2a53a4c3238c 956 case 4: /* IP address */
lorcansmith 0:2a53a4c3238c 957 case 5: /* net mask */
lorcansmith 0:2a53a4c3238c 958 case 6: /* Gateway address */
lorcansmith 0:2a53a4c3238c 959 case 7: /* DNS address */
lorcansmith 0:2a53a4c3238c 960 case 8: /* v1.4: Trap host address */
lorcansmith 0:2a53a4c3238c 961 if ( len <= 16 )
lorcansmith 0:2a53a4c3238c 962 {
lorcansmith 0:2a53a4c3238c 963 while ( i < 16 )
lorcansmith 0:2a53a4c3238c 964 {
lorcansmith 0:2a53a4c3238c 965 test_addrs[ i++ ] = i < len ? *(uc_ptr++) : 0;
lorcansmith 0:2a53a4c3238c 966 }
lorcansmith 0:2a53a4c3238c 967 set_ok = update_addrs_from_string( test_addrs, test_ad );
lorcansmith 0:2a53a4c3238c 968 }
lorcansmith 0:2a53a4c3238c 969 break;
lorcansmith 0:2a53a4c3238c 970 case 9: /* v1.5: community string */
lorcansmith 0:2a53a4c3238c 971 if ( (len >= MIN_COMMUNITY) && (len < MAX_COMMUNITY) )
lorcansmith 0:2a53a4c3238c 972 {
lorcansmith 0:2a53a4c3238c 973 set_ok = 1;
lorcansmith 0:2a53a4c3238c 974 while ( i++ < MAX_COMMUNITY )
lorcansmith 0:2a53a4c3238c 975 {
lorcansmith 0:2a53a4c3238c 976 if ( *(uc_ptr++) == ' ' )
lorcansmith 0:2a53a4c3238c 977 {
lorcansmith 0:2a53a4c3238c 978 set_ok = 0; // no spaces allowed in community string
lorcansmith 0:2a53a4c3238c 979 }
lorcansmith 0:2a53a4c3238c 980 }
lorcansmith 0:2a53a4c3238c 981 }
lorcansmith 0:2a53a4c3238c 982 break;
lorcansmith 0:2a53a4c3238c 983 } // end switch
lorcansmith 0:2a53a4c3238c 984 return set_ok;
lorcansmith 0:2a53a4c3238c 985 }
lorcansmith 0:2a53a4c3238c 986
lorcansmith 0:2a53a4c3238c 987 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 988 /* f3k_comms_set_value:
lorcansmith 0:2a53a4c3238c 989 * Description: Returns f3k scalar object value
lorcansmith 0:2a53a4c3238c 990 * Parameters: IN: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 991 * IN: u16_t len - return value space (in bytes) - NOT USED
lorcansmith 0:2a53a4c3238c 992 * OUT: void *value - points to (varbind) space to copy value from
lorcansmith 0:2a53a4c3238c 993 * Returns: NONE
lorcansmith 0:2a53a4c3238c 994 */
lorcansmith 0:2a53a4c3238c 995 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 996 static void
lorcansmith 0:2a53a4c3238c 997 f3k_comms_set_value(struct obj_def *od, u16_t len, void *value)
lorcansmith 0:2a53a4c3238c 998 {
lorcansmith 0:2a53a4c3238c 999 u8_t id, i;
lorcansmith 0:2a53a4c3238c 1000 u8_t * uc_ptr;
lorcansmith 0:2a53a4c3238c 1001
lorcansmith 0:2a53a4c3238c 1002 i = 0;
lorcansmith 0:2a53a4c3238c 1003 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= MAX_COMMS_ID));
lorcansmith 0:2a53a4c3238c 1004 uc_ptr = (u8_t*)value; // char pointer to first byte in value
lorcansmith 0:2a53a4c3238c 1005 id = (u8_t)od->id_inst_ptr[0];
lorcansmith 0:2a53a4c3238c 1006 switch (id)
lorcansmith 0:2a53a4c3238c 1007 {
lorcansmith 0:2a53a4c3238c 1008 case 1: /* RTU unit ID */
lorcansmith 0:2a53a4c3238c 1009 cmd_buf[ UNIT_ID_CMD ] = *uc_ptr;
lorcansmith 0:2a53a4c3238c 1010 cmd_buf[ 0 ] = cmd_buf[ UNIT_ID_CMD ]; // tell the 3000 cpu data available
lorcansmith 0:2a53a4c3238c 1011 new_cmd_idx = UNIT_ID_CMD;
lorcansmith 0:2a53a4c3238c 1012 fsvr.put_byte( UNIT_ID_IDX, cmd_buf[ UNIT_ID_CMD ] );
lorcansmith 0:2a53a4c3238c 1013 break;
lorcansmith 0:2a53a4c3238c 1014 case 4: /* IP address */
lorcansmith 0:2a53a4c3238c 1015 while ( i < 16 ) {
lorcansmith 0:2a53a4c3238c 1016 snmp_ip_addrs[ i++ ] = ( i < len ) ? *(uc_ptr++) : 0;
lorcansmith 0:2a53a4c3238c 1017 }
lorcansmith 0:2a53a4c3238c 1018 update_addrs_from_string( snmp_ip_addrs, ip_ad );
lorcansmith 0:2a53a4c3238c 1019 net_addrs_set = true;
lorcansmith 0:2a53a4c3238c 1020 break;
lorcansmith 0:2a53a4c3238c 1021 case 5: /* net mask */
lorcansmith 0:2a53a4c3238c 1022 while ( i < 16 ) {
lorcansmith 0:2a53a4c3238c 1023 snmp_net_mask[ i++ ] = ( i < len ) ? *(uc_ptr++) : 0;
lorcansmith 0:2a53a4c3238c 1024 }
lorcansmith 0:2a53a4c3238c 1025 update_addrs_from_string( snmp_net_mask, msk_ad );
lorcansmith 0:2a53a4c3238c 1026 net_addrs_set = true;
lorcansmith 0:2a53a4c3238c 1027 break;
lorcansmith 0:2a53a4c3238c 1028 case 6: /* Gateway address */
lorcansmith 0:2a53a4c3238c 1029 while ( i < 16 ) {
lorcansmith 0:2a53a4c3238c 1030 snmp_gwy_addrs[ i++ ] = ( i < len ) ? *(uc_ptr++) : 0;
lorcansmith 0:2a53a4c3238c 1031 }
lorcansmith 0:2a53a4c3238c 1032 update_addrs_from_string( snmp_gwy_addrs, gwy_ad );
lorcansmith 0:2a53a4c3238c 1033 net_addrs_set = true;
lorcansmith 0:2a53a4c3238c 1034 break;
lorcansmith 0:2a53a4c3238c 1035 case 7: /* DNS address */
lorcansmith 0:2a53a4c3238c 1036 while ( i < 16 ) {
lorcansmith 0:2a53a4c3238c 1037 snmp_dns_addrs[ i++ ] = ( i < len ) ? *(uc_ptr++) : 0;
lorcansmith 0:2a53a4c3238c 1038 }
lorcansmith 0:2a53a4c3238c 1039 update_addrs_from_string( snmp_dns_addrs, dns_ad );
lorcansmith 0:2a53a4c3238c 1040 net_addrs_set = true;
lorcansmith 0:2a53a4c3238c 1041 break;
lorcansmith 0:2a53a4c3238c 1042 case 8: /* v1.4: Trap host address */
lorcansmith 0:2a53a4c3238c 1043 while ( i < 16 ) {
lorcansmith 0:2a53a4c3238c 1044 snmp_trh_addrs[ i++ ] = ( i < len ) ? *(uc_ptr++) : 0;
lorcansmith 0:2a53a4c3238c 1045 }
lorcansmith 0:2a53a4c3238c 1046 update_addrs_from_string( snmp_trh_addrs, th_ad );
lorcansmith 0:2a53a4c3238c 1047 net_addrs_set = true;
lorcansmith 0:2a53a4c3238c 1048 break;
lorcansmith 0:2a53a4c3238c 1049 case 9: /* v1.5: community string */
lorcansmith 0:2a53a4c3238c 1050 while ( i < MAX_COMMUNITY ) {
lorcansmith 0:2a53a4c3238c 1051 snmp_publiccommunity[ i++ ] = ( i < len ) ? *(uc_ptr++) : 0;
lorcansmith 0:2a53a4c3238c 1052 }
lorcansmith 0:2a53a4c3238c 1053 net_addrs_set = true;
lorcansmith 0:2a53a4c3238c 1054 break;
lorcansmith 0:2a53a4c3238c 1055 }
lorcansmith 0:2a53a4c3238c 1056 }
lorcansmith 0:2a53a4c3238c 1057
lorcansmith 0:2a53a4c3238c 1058
lorcansmith 0:2a53a4c3238c 1059 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1060 /* f3k_IO_get_object_def:
lorcansmith 0:2a53a4c3238c 1061 * Description: get definition for F3000 scalar objects
lorcansmith 0:2a53a4c3238c 1062 * Called via mib_scalar_node f3k_IO_scalar
lorcansmith 0:2a53a4c3238c 1063 * Parameters: IN: u8_t ident_len - length of ID in...
lorcansmith 0:2a53a4c3238c 1064 * IN: s32_t *ident - array holding ID
lorcansmith 0:2a53a4c3238c 1065 * OUT: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 1066 * Returns: NONE
lorcansmith 0:2a53a4c3238c 1067 */
lorcansmith 0:2a53a4c3238c 1068 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1069 static void
lorcansmith 0:2a53a4c3238c 1070 f3k_IO_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
lorcansmith 0:2a53a4c3238c 1071 {
lorcansmith 0:2a53a4c3238c 1072 u8_t id;
lorcansmith 0:2a53a4c3238c 1073
lorcansmith 0:2a53a4c3238c 1074 /* return to object name, adding index depth (1) */
lorcansmith 0:2a53a4c3238c 1075 ident_len += 1;
lorcansmith 0:2a53a4c3238c 1076 ident -= 1;
lorcansmith 0:2a53a4c3238c 1077 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
lorcansmith 0:2a53a4c3238c 1078 if ((ident_len == 2) &&
lorcansmith 0:2a53a4c3238c 1079 (ident[0] > 0) && (ident[0] <= MAX_IO_TABLE))
lorcansmith 0:2a53a4c3238c 1080 {
lorcansmith 0:2a53a4c3238c 1081 od->id_inst_len = ident_len;
lorcansmith 0:2a53a4c3238c 1082 od->id_inst_ptr = ident;
lorcansmith 0:2a53a4c3238c 1083
lorcansmith 0:2a53a4c3238c 1084 id = (u8_t)ident[0];
lorcansmith 0:2a53a4c3238c 1085 printf("\r\nf3k_IO_get_object_def: ident_len %d, id %d\r\n", ident_len, id);
lorcansmith 0:2a53a4c3238c 1086
lorcansmith 0:2a53a4c3238c 1087 od->instance = MIB_OBJECT_SCALAR;
lorcansmith 0:2a53a4c3238c 1088 od->access = MIB_OBJECT_READ_ONLY;
lorcansmith 0:2a53a4c3238c 1089 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE);
lorcansmith 0:2a53a4c3238c 1090 od->v_len = sizeof(u32_t);
lorcansmith 0:2a53a4c3238c 1091 }
lorcansmith 0:2a53a4c3238c 1092 else
lorcansmith 0:2a53a4c3238c 1093 {
lorcansmith 0:2a53a4c3238c 1094 LWIP_DEBUGF(SNMP_MIB_DEBUG,("f3k_IO_get_object_def: no scalar\n"));
lorcansmith 0:2a53a4c3238c 1095 od->instance = MIB_OBJECT_NONE;
lorcansmith 0:2a53a4c3238c 1096 }
lorcansmith 0:2a53a4c3238c 1097 }
lorcansmith 0:2a53a4c3238c 1098
lorcansmith 0:2a53a4c3238c 1099 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1100 /* f3k_IO_get_value:
lorcansmith 0:2a53a4c3238c 1101 * Description: Returns f3k scalar object value
lorcansmith 0:2a53a4c3238c 1102 * @param ident points to objectname.0 (object id trailer)
lorcansmith 0:2a53a4c3238c 1103 * Parameters: IN: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 1104 * IN: u16_t len - return value space (in bytes)
lorcansmith 0:2a53a4c3238c 1105 * OUT: void *value - points to (varbind) space to copy value into
lorcansmith 0:2a53a4c3238c 1106 * Returns: NONE
lorcansmith 0:2a53a4c3238c 1107 */
lorcansmith 0:2a53a4c3238c 1108 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1109 static void
lorcansmith 0:2a53a4c3238c 1110 f3k_IO_get_value(struct obj_def *od, u16_t len, void *value)
lorcansmith 0:2a53a4c3238c 1111 {
lorcansmith 0:2a53a4c3238c 1112 u32_t *uint_ptr = (u32_t*)value;
lorcansmith 0:2a53a4c3238c 1113 u8_t id;
lorcansmith 0:2a53a4c3238c 1114
lorcansmith 0:2a53a4c3238c 1115 LWIP_UNUSED_ARG(len);
lorcansmith 0:2a53a4c3238c 1116 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
lorcansmith 0:2a53a4c3238c 1117 id = (u8_t)od->id_inst_ptr[0];
lorcansmith 0:2a53a4c3238c 1118 *uint_ptr = snmp_get_f3k_IO_value( id );
lorcansmith 0:2a53a4c3238c 1119 }
lorcansmith 0:2a53a4c3238c 1120
lorcansmith 0:2a53a4c3238c 1121 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1122 /* f3k_alarm_get_object_def:
lorcansmith 0:2a53a4c3238c 1123 * Description: get definition for F3000 scalar objects
lorcansmith 0:2a53a4c3238c 1124 * Called via mib_scalar_node f3k_alarm_scalar
lorcansmith 0:2a53a4c3238c 1125 * Parameters: IN: u8_t ident_len - length of ID in...
lorcansmith 0:2a53a4c3238c 1126 * IN: s32_t *ident - array holding ID
lorcansmith 0:2a53a4c3238c 1127 * OUT: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 1128 * Returns: NONE
lorcansmith 0:2a53a4c3238c 1129 */
lorcansmith 0:2a53a4c3238c 1130 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1131 static void
lorcansmith 0:2a53a4c3238c 1132 f3k_alarm_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
lorcansmith 0:2a53a4c3238c 1133 {
lorcansmith 0:2a53a4c3238c 1134 u8_t id;
lorcansmith 0:2a53a4c3238c 1135
lorcansmith 0:2a53a4c3238c 1136 /* return to object name, adding index depth (1) */
lorcansmith 0:2a53a4c3238c 1137 ident_len += 1;
lorcansmith 0:2a53a4c3238c 1138 ident -= 1;
lorcansmith 0:2a53a4c3238c 1139 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
lorcansmith 0:2a53a4c3238c 1140 if ((ident_len == 2) &&
lorcansmith 0:2a53a4c3238c 1141 (ident[0] > 0) && (ident[0] <= MAX_ALARM_ID))
lorcansmith 0:2a53a4c3238c 1142 {
lorcansmith 0:2a53a4c3238c 1143 od->id_inst_len = ident_len;
lorcansmith 0:2a53a4c3238c 1144 od->id_inst_ptr = ident;
lorcansmith 0:2a53a4c3238c 1145 id = (u8_t)ident[0];
lorcansmith 0:2a53a4c3238c 1146 printf("\r\nf3k_alarm_get_object_def: ident_len %d, id %d\r\n", ident_len, id);
lorcansmith 0:2a53a4c3238c 1147 /* alarm strings */
lorcansmith 0:2a53a4c3238c 1148 od->instance = MIB_OBJECT_SCALAR;
lorcansmith 0:2a53a4c3238c 1149 od->access = MIB_OBJECT_READ_WRITE;
lorcansmith 0:2a53a4c3238c 1150 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
lorcansmith 0:2a53a4c3238c 1151 od->v_len = strlen( (const char *)alarm_msg[ id-1 ] );
lorcansmith 0:2a53a4c3238c 1152 // printf("f3k_alarm_get_object_def: od->v_len = strlen( get_alarm_string(id-1) ) %d\r\n", od->v_len);
lorcansmith 0:2a53a4c3238c 1153 }
lorcansmith 0:2a53a4c3238c 1154 else
lorcansmith 0:2a53a4c3238c 1155 {
lorcansmith 0:2a53a4c3238c 1156 LWIP_DEBUGF(SNMP_MIB_DEBUG,("f3k_alarm_get_object_def: no scalar\n"));
lorcansmith 0:2a53a4c3238c 1157 od->instance = MIB_OBJECT_NONE;
lorcansmith 0:2a53a4c3238c 1158 }
lorcansmith 0:2a53a4c3238c 1159 }
lorcansmith 0:2a53a4c3238c 1160
lorcansmith 0:2a53a4c3238c 1161 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1162 /* f3k_alarm_get_value:
lorcansmith 0:2a53a4c3238c 1163 * Description: Returns f3k scalar object value
lorcansmith 0:2a53a4c3238c 1164 * @param ident points to objectname.0 (object id trailer)
lorcansmith 0:2a53a4c3238c 1165 * Parameters: IN: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 1166 * IN: u16_t len - return value space (in bytes)
lorcansmith 0:2a53a4c3238c 1167 * OUT: void *value - points to (varbind) space to copy value into
lorcansmith 0:2a53a4c3238c 1168 * Returns: NONE
lorcansmith 0:2a53a4c3238c 1169 */
lorcansmith 0:2a53a4c3238c 1170 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1171 static void
lorcansmith 0:2a53a4c3238c 1172 f3k_alarm_get_value(struct obj_def *od, u16_t len, void *value)
lorcansmith 0:2a53a4c3238c 1173 {
lorcansmith 0:2a53a4c3238c 1174 u8_t * uchr_ptr = (u8_t*)value;
lorcansmith 0:2a53a4c3238c 1175 u8_t id;
lorcansmith 0:2a53a4c3238c 1176 u8_t i = 0;
lorcansmith 0:2a53a4c3238c 1177
lorcansmith 0:2a53a4c3238c 1178 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= MAX_ALARM_ID));
lorcansmith 0:2a53a4c3238c 1179 id = (u8_t)od->id_inst_ptr[0];
lorcansmith 0:2a53a4c3238c 1180 // printf("\r\nf3k_alarm_get_value: id %d, len %d", id, len );
lorcansmith 0:2a53a4c3238c 1181 while ( i < len ) {
lorcansmith 0:2a53a4c3238c 1182 *(uchr_ptr++) = (u8_t)alarm_msg[ id-1 ][ i++ ];
lorcansmith 0:2a53a4c3238c 1183 }
lorcansmith 0:2a53a4c3238c 1184 }
lorcansmith 0:2a53a4c3238c 1185
lorcansmith 0:2a53a4c3238c 1186 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1187 /* f3k_alarm_set_test:
lorcansmith 0:2a53a4c3238c 1188 * Description: Test f3k_alarm object value before setting
lorcansmith 0:2a53a4c3238c 1189 * Parameters: IN: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 1190 * IN: u16_t len - return value space (in bytes) - NOT USED
lorcansmith 0:2a53a4c3238c 1191 * OUT: void *value - points to (varbind) space to copy value from
lorcansmith 0:2a53a4c3238c 1192 * Returns: Returns set_ok = 1 if able to set value, 0 otherwise
lorcansmith 0:2a53a4c3238c 1193 */
lorcansmith 0:2a53a4c3238c 1194 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1195 static u8_t
lorcansmith 0:2a53a4c3238c 1196 f3k_alarm_set_test(struct obj_def *od, u16_t len, void *value)
lorcansmith 0:2a53a4c3238c 1197 {
lorcansmith 0:2a53a4c3238c 1198 u8_t id, set_ok;
lorcansmith 0:2a53a4c3238c 1199
lorcansmith 0:2a53a4c3238c 1200 LWIP_UNUSED_ARG(value);
lorcansmith 0:2a53a4c3238c 1201 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= MAX_ALARM_ID));
lorcansmith 0:2a53a4c3238c 1202 id = (u8_t)od->id_inst_ptr[0];
lorcansmith 0:2a53a4c3238c 1203 set_ok = (len > 0) && (len < MSG_LNGTH) ? 1 : 0;
lorcansmith 0:2a53a4c3238c 1204 printf("\r\f3k_alarm_set_test: id %d, len %d set_ok %d\r\n", id, len, set_ok);
lorcansmith 0:2a53a4c3238c 1205 return set_ok;
lorcansmith 0:2a53a4c3238c 1206 }
lorcansmith 0:2a53a4c3238c 1207
lorcansmith 0:2a53a4c3238c 1208 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1209 /* f3k_alarm_set_value:
lorcansmith 0:2a53a4c3238c 1210 * Description: Sets f3k_alarm_scalar object value
lorcansmith 0:2a53a4c3238c 1211 * Parameters: IN: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 1212 * IN: u16_t len - return value space (in bytes) - NOT USED
lorcansmith 0:2a53a4c3238c 1213 * OUT: void *value - points to (varbind) space to copy value from
lorcansmith 0:2a53a4c3238c 1214 * Returns: NONE
lorcansmith 0:2a53a4c3238c 1215 */
lorcansmith 0:2a53a4c3238c 1216 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1217 static void
lorcansmith 0:2a53a4c3238c 1218 f3k_alarm_set_value(struct obj_def *od, u16_t len, void *value)
lorcansmith 0:2a53a4c3238c 1219 {
lorcansmith 0:2a53a4c3238c 1220 u8_t id, i;
lorcansmith 0:2a53a4c3238c 1221 u8_t * uc_ptr;
lorcansmith 0:2a53a4c3238c 1222
lorcansmith 0:2a53a4c3238c 1223 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= MAX_ALARM_ID));
lorcansmith 0:2a53a4c3238c 1224 id = (u8_t)od->id_inst_ptr[0];
lorcansmith 0:2a53a4c3238c 1225 uc_ptr = (u8_t*)value; // char pointer to first byte in value
lorcansmith 0:2a53a4c3238c 1226 i = 0;
lorcansmith 0:2a53a4c3238c 1227 // printf("\r\f3k_alarm_set_value: id %d, len %d uc_ptr %c\r\n", id, len, *uc_ptr);
lorcansmith 0:2a53a4c3238c 1228 while ( i < MSG_LNGTH ) {
lorcansmith 0:2a53a4c3238c 1229 alarm_msg[id-1][i] = ( i < len ) ? *(uc_ptr++) : 0;
lorcansmith 0:2a53a4c3238c 1230 i++;
lorcansmith 0:2a53a4c3238c 1231 }
lorcansmith 0:2a53a4c3238c 1232 alarm_str_set = id;
lorcansmith 0:2a53a4c3238c 1233 }
lorcansmith 0:2a53a4c3238c 1234
lorcansmith 0:2a53a4c3238c 1235 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1236 /* f3k_amask_get_object_def:
lorcansmith 0:2a53a4c3238c 1237 * Description: get definition for F3000 scalar objects
lorcansmith 0:2a53a4c3238c 1238 * Called via mib_scalar_node f3k_sys_scalar
lorcansmith 0:2a53a4c3238c 1239 * Parameters: IN: u8_t ident_len - length of ID in...
lorcansmith 0:2a53a4c3238c 1240 * IN: s32_t *ident - array holding ID
lorcansmith 0:2a53a4c3238c 1241 * OUT: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 1242 * Returns: NONE
lorcansmith 0:2a53a4c3238c 1243 */
lorcansmith 0:2a53a4c3238c 1244 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1245 static void
lorcansmith 0:2a53a4c3238c 1246 f3k_amask_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
lorcansmith 0:2a53a4c3238c 1247 {
lorcansmith 0:2a53a4c3238c 1248 u8_t id;
lorcansmith 0:2a53a4c3238c 1249
lorcansmith 0:2a53a4c3238c 1250 /* return to object name, adding index depth (1) */
lorcansmith 0:2a53a4c3238c 1251 ident_len += 1;
lorcansmith 0:2a53a4c3238c 1252 ident -= 1;
lorcansmith 0:2a53a4c3238c 1253 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= MAX_ALARM_ID));
lorcansmith 0:2a53a4c3238c 1254 if ((ident_len == 2) &&
lorcansmith 0:2a53a4c3238c 1255 (ident[0] > 0) && (ident[0] <= MAX_ALARM_ID))
lorcansmith 0:2a53a4c3238c 1256 {
lorcansmith 0:2a53a4c3238c 1257 od->id_inst_len = ident_len;
lorcansmith 0:2a53a4c3238c 1258 od->id_inst_ptr = ident;
lorcansmith 0:2a53a4c3238c 1259
lorcansmith 0:2a53a4c3238c 1260 id = (u8_t)ident[0];
lorcansmith 0:2a53a4c3238c 1261 printf("\r\nf3k_amask_get_object_def: ident_len %d, id %d\r\n", ident_len, id);
lorcansmith 0:2a53a4c3238c 1262 od->instance = MIB_OBJECT_SCALAR;
lorcansmith 0:2a53a4c3238c 1263 od->access = MIB_OBJECT_READ_WRITE;
lorcansmith 0:2a53a4c3238c 1264 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
lorcansmith 0:2a53a4c3238c 1265 od->v_len = 8; // 8 hex chars mask IO channels 1-32
lorcansmith 0:2a53a4c3238c 1266 }
lorcansmith 0:2a53a4c3238c 1267 else
lorcansmith 0:2a53a4c3238c 1268 {
lorcansmith 0:2a53a4c3238c 1269 LWIP_DEBUGF(SNMP_MIB_DEBUG,("\nf3k_amask_get_object_def: no scalar\n"));
lorcansmith 0:2a53a4c3238c 1270 od->instance = MIB_OBJECT_NONE;
lorcansmith 0:2a53a4c3238c 1271 }
lorcansmith 0:2a53a4c3238c 1272 }
lorcansmith 0:2a53a4c3238c 1273
lorcansmith 0:2a53a4c3238c 1274 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1275 /* f3k_amask_get_value:
lorcansmith 0:2a53a4c3238c 1276 * Description: Returns f3k_amask scalar object value
lorcansmith 0:2a53a4c3238c 1277 * @param ident points to objectname.0 (object id trailer)
lorcansmith 0:2a53a4c3238c 1278 * Parameters: IN: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 1279 * IN: u16_t len - return value space (in bytes)
lorcansmith 0:2a53a4c3238c 1280 * OUT: void *value - points to (varbind) space to copy value into
lorcansmith 0:2a53a4c3238c 1281 * Returns: NONE
lorcansmith 0:2a53a4c3238c 1282 */
lorcansmith 0:2a53a4c3238c 1283 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1284 static void
lorcansmith 0:2a53a4c3238c 1285 f3k_amask_get_value(struct obj_def *od, u16_t len, void *value)
lorcansmith 0:2a53a4c3238c 1286 {
lorcansmith 0:2a53a4c3238c 1287 u8_t * uchr_ptr = (u8_t*)value;
lorcansmith 0:2a53a4c3238c 1288 u8_t id;
lorcansmith 0:2a53a4c3238c 1289 u8_t i = 0;
lorcansmith 0:2a53a4c3238c 1290
lorcansmith 0:2a53a4c3238c 1291 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= MAX_ALARM_ID));
lorcansmith 0:2a53a4c3238c 1292 id = (u8_t)od->id_inst_ptr[0];
lorcansmith 0:2a53a4c3238c 1293 strncpy( f3k_IO_mask, get_hex_mask( io_mask[id-1] ), 8 ); // v1.3: copy numeric io_mask[]
lorcansmith 0:2a53a4c3238c 1294 while ( i < len ) {
lorcansmith 0:2a53a4c3238c 1295 *(uchr_ptr++) = f3k_IO_mask[ i++ ];
lorcansmith 0:2a53a4c3238c 1296 }
lorcansmith 0:2a53a4c3238c 1297 }
lorcansmith 0:2a53a4c3238c 1298
lorcansmith 0:2a53a4c3238c 1299 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1300 /* f3k_amask_set_test:
lorcansmith 0:2a53a4c3238c 1301 * Description: Test f3k_amask object value before setting
lorcansmith 0:2a53a4c3238c 1302 * Parameters: IN: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 1303 * IN: u16_t len - return value space (in bytes) - NOT USED
lorcansmith 0:2a53a4c3238c 1304 * OUT: void *value - points to (varbind) space to copy value from
lorcansmith 0:2a53a4c3238c 1305 * Returns: Returns set_ok = 1 if able to set value, 0 otherwise
lorcansmith 0:2a53a4c3238c 1306 */
lorcansmith 0:2a53a4c3238c 1307 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1308 static u8_t
lorcansmith 0:2a53a4c3238c 1309 f3k_amask_set_test(struct obj_def *od, u16_t len, void *value)
lorcansmith 0:2a53a4c3238c 1310 {
lorcansmith 0:2a53a4c3238c 1311 u8_t i, id, set_ok;
lorcansmith 0:2a53a4c3238c 1312 u8_t * uc_ptr = (u8_t*)value; // char pointer to first byte in value
lorcansmith 0:2a53a4c3238c 1313
lorcansmith 0:2a53a4c3238c 1314 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= MAX_ALARM_ID));
lorcansmith 0:2a53a4c3238c 1315 id = (u8_t)od->id_inst_ptr[0];
lorcansmith 0:2a53a4c3238c 1316 printf("\r\f3k_amask_set_test: id %d, len %d\r\n", id, len);
lorcansmith 0:2a53a4c3238c 1317 if ( (len > 0) && (len <= 8) )
lorcansmith 0:2a53a4c3238c 1318 { // ensure all digits are hexadecimal
lorcansmith 0:2a53a4c3238c 1319 set_ok = 1;
lorcansmith 0:2a53a4c3238c 1320 for ( i = 0; i < len; i++ )
lorcansmith 0:2a53a4c3238c 1321 {
lorcansmith 0:2a53a4c3238c 1322 if ( !isxdigit( *(uc_ptr++) ) )
lorcansmith 0:2a53a4c3238c 1323 {
lorcansmith 0:2a53a4c3238c 1324 set_ok = 0; // invalid hexadecimal digit
lorcansmith 0:2a53a4c3238c 1325 break; // so quit
lorcansmith 0:2a53a4c3238c 1326 }
lorcansmith 0:2a53a4c3238c 1327 }
lorcansmith 0:2a53a4c3238c 1328 }
lorcansmith 0:2a53a4c3238c 1329 return set_ok;
lorcansmith 0:2a53a4c3238c 1330 }
lorcansmith 0:2a53a4c3238c 1331
lorcansmith 0:2a53a4c3238c 1332 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1333 /* f3k_amask_set_value:
lorcansmith 0:2a53a4c3238c 1334 * Description: Sets f3k_alarm_scalar object value
lorcansmith 0:2a53a4c3238c 1335 * Parameters: IN: struct obj_def *od - object definition found
lorcansmith 0:2a53a4c3238c 1336 * IN: u16_t len - return value space (in bytes) - NOT USED
lorcansmith 0:2a53a4c3238c 1337 * OUT: void *value - points to (varbind) space to copy value from
lorcansmith 0:2a53a4c3238c 1338 * Returns: NONE
lorcansmith 0:2a53a4c3238c 1339 */
lorcansmith 0:2a53a4c3238c 1340 /****************************************************************************/
lorcansmith 0:2a53a4c3238c 1341 static void
lorcansmith 0:2a53a4c3238c 1342 f3k_amask_set_value(struct obj_def *od, u16_t len, void *value)
lorcansmith 0:2a53a4c3238c 1343 {
lorcansmith 0:2a53a4c3238c 1344 u8_t id;
lorcansmith 0:2a53a4c3238c 1345 u8_t * uc_ptr = (u8_t*)value; // char pointer to first byte in value
lorcansmith 0:2a53a4c3238c 1346
lorcansmith 0:2a53a4c3238c 1347 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= MAX_ALARM_ID));
lorcansmith 0:2a53a4c3238c 1348 id = (u8_t)od->id_inst_ptr[0];
lorcansmith 0:2a53a4c3238c 1349
lorcansmith 0:2a53a4c3238c 1350 io_mask[ id-1 ] = convert2decimal( uc_ptr, len );
lorcansmith 0:2a53a4c3238c 1351 alarm_str_set = id;
lorcansmith 0:2a53a4c3238c 1352 }
lorcansmith 0:2a53a4c3238c 1353
lorcansmith 0:2a53a4c3238c 1354 #endif /* LWIP_SNMP */