41 snmp_err_t snmp_table_get_instance(
const u32_t *root_oid,
u8_t root_oid_len,
struct snmp_node_instance* instance)
43 snmp_err_t ret = SNMP_ERR_NOSUCHINSTANCE;
44 const struct snmp_table_node* table_node = (
const struct snmp_table_node*)instance->node;
51 if ((instance->instance_oid.len >= 3) && (instance->instance_oid.id[0] == 1))
54 const struct snmp_table_col_def* col_def = table_node->columns;
55 u16_t i = table_node->column_count;
58 if (col_def->index == instance->instance_oid.id[1])
70 instance->asn1_type = col_def->asn1_type;
71 instance->access = col_def->access;
72 instance->get_value = table_node->get_value;
73 instance->set_test = table_node->set_test;
74 instance->set_value = table_node->set_value;
76 ret = table_node->get_cell_instance(
77 &(instance->instance_oid.id[1]),
78 &(instance->instance_oid.id[2]),
79 instance->instance_oid.len-2,
87 snmp_err_t snmp_table_get_next_instance(
const u32_t *root_oid,
u8_t root_oid_len,
struct snmp_node_instance* instance)
89 const struct snmp_table_node* table_node = (
const struct snmp_table_node*)instance->node;
90 const struct snmp_table_col_def* col_def;
91 struct snmp_obj_id row_oid;
99 if ((instance->instance_oid.len > 0) && (instance->instance_oid.id[0] > 1))
101 return SNMP_ERR_NOSUCHINSTANCE;
103 if (instance->instance_oid.len > 1)
105 column = instance->instance_oid.id[1];
107 if (instance->instance_oid.len > 2)
109 snmp_oid_assign(&row_oid, &(instance->instance_oid.id[2]), instance->instance_oid.len - 2);
116 instance->get_value = table_node->get_value;
117 instance->set_test = table_node->set_test;
118 instance->set_value = table_node->set_value;
124 const struct snmp_table_col_def* next_col_def =
NULL;
125 col_def = table_node->columns;
127 for (i=0; i<table_node->column_count; i++)
129 if (col_def->index == column)
131 next_col_def = col_def;
134 else if ((col_def->index > column) && ((next_col_def ==
NULL) || (col_def->index < next_col_def->index)))
136 next_col_def = col_def;
141 if (next_col_def ==
NULL)
144 return SNMP_ERR_NOSUCHINSTANCE;
147 instance->asn1_type = next_col_def->asn1_type;
148 instance->access = next_col_def->access;
150 result = table_node->get_next_cell_instance(
151 &next_col_def->index,
155 if (result == SNMP_ERR_NOERROR)
157 col_def = next_col_def;
162 column = next_col_def->index + 1;
167 instance->instance_oid.len = 2;
168 instance->instance_oid.id[0] = 1;
169 instance->instance_oid.id[1] = col_def->index;
170 snmp_oid_append(&instance->instance_oid, row_oid.id, row_oid.len);
172 return SNMP_ERR_NOERROR;
176 snmp_err_t snmp_table_simple_get_instance(
const u32_t *root_oid,
u8_t root_oid_len,
struct snmp_node_instance* instance)
178 snmp_err_t ret = SNMP_ERR_NOSUCHINSTANCE;
179 const struct snmp_table_simple_node* table_node = (
const struct snmp_table_simple_node*)instance->node;
186 if ((instance->instance_oid.len >= 3) && (instance->instance_oid.id[0] == 1))
188 ret = table_node->get_cell_value(
189 &(instance->instance_oid.id[1]),
190 &(instance->instance_oid.id[2]),
191 instance->instance_oid.len-2,
192 &instance->reference,
193 &instance->reference_len);
195 if (ret == SNMP_ERR_NOERROR)
198 const struct snmp_table_simple_col_def* col_def = table_node->columns;
199 u32_t i = table_node->column_count;
202 if (col_def->index == instance->instance_oid.id[1])
213 instance->asn1_type = col_def->asn1_type;
214 instance->access = SNMP_NODE_INSTANCE_READ_ONLY;
215 instance->set_test =
NULL;
216 instance->set_value =
NULL;
218 switch (col_def->data_type)
220 case SNMP_VARIANT_VALUE_TYPE_U32: instance->get_value = snmp_table_extract_value_from_u32ref;
break;
221 case SNMP_VARIANT_VALUE_TYPE_S32: instance->get_value = snmp_table_extract_value_from_s32ref;
break;
222 case SNMP_VARIANT_VALUE_TYPE_PTR:
223 case SNMP_VARIANT_VALUE_TYPE_CONST_PTR: instance->get_value = snmp_table_extract_value_from_refconstptr;
break;
225 LWIP_DEBUGF(
SNMP_DEBUG, (
"snmp_table_simple_get_instance(): unknown column data_type: %d\n", col_def->data_type));
226 return SNMP_ERR_GENERROR;
229 ret = SNMP_ERR_NOERROR;
233 ret = SNMP_ERR_NOSUCHINSTANCE;
241 snmp_err_t snmp_table_simple_get_next_instance(
const u32_t *root_oid,
u8_t root_oid_len,
struct snmp_node_instance* instance)
243 const struct snmp_table_simple_node* table_node = (
const struct snmp_table_simple_node*)instance->node;
244 const struct snmp_table_simple_col_def* col_def;
245 struct snmp_obj_id row_oid;
253 if ((instance->instance_oid.len > 0) && (instance->instance_oid.id[0] > 1))
255 return SNMP_ERR_NOSUCHINSTANCE;
257 if (instance->instance_oid.len > 1)
259 column = instance->instance_oid.id[1];
261 if (instance->instance_oid.len > 2)
263 snmp_oid_assign(&row_oid, &(instance->instance_oid.id[2]), instance->instance_oid.len - 2);
274 const struct snmp_table_simple_col_def* next_col_def =
NULL;
275 col_def = table_node->columns;
277 for (i=0; i<table_node->column_count; i++)
279 if (col_def->index == column)
281 next_col_def = col_def;
284 else if ((col_def->index > column) && ((next_col_def ==
NULL) || (col_def->index < next_col_def->index)))
286 next_col_def = col_def;
291 if (next_col_def ==
NULL)
294 return SNMP_ERR_NOSUCHINSTANCE;
297 result = table_node->get_next_cell_instance_and_value(
298 &next_col_def->index,
300 &instance->reference,
301 &instance->reference_len);
303 if (result == SNMP_ERR_NOERROR)
305 col_def = next_col_def;
310 column = next_col_def->index + 1;
314 instance->asn1_type = col_def->asn1_type;
315 instance->access = SNMP_NODE_INSTANCE_READ_ONLY;
316 instance->set_test =
NULL;
317 instance->set_value =
NULL;
319 switch (col_def->data_type)
321 case SNMP_VARIANT_VALUE_TYPE_U32: instance->get_value = snmp_table_extract_value_from_u32ref;
break;
322 case SNMP_VARIANT_VALUE_TYPE_S32: instance->get_value = snmp_table_extract_value_from_s32ref;
break;
323 case SNMP_VARIANT_VALUE_TYPE_PTR:
324 case SNMP_VARIANT_VALUE_TYPE_CONST_PTR: instance->get_value = snmp_table_extract_value_from_refconstptr;
break;
326 LWIP_DEBUGF(
SNMP_DEBUG, (
"snmp_table_simple_get_instance(): unknown column data_type: %d\n", col_def->data_type));
327 return SNMP_ERR_GENERROR;
331 instance->instance_oid.len = 2;
332 instance->instance_oid.id[0] = 1;
333 instance->instance_oid.id[1] = col_def->index;
334 snmp_oid_append(&instance->instance_oid, row_oid.id, row_oid.len);
336 return SNMP_ERR_NOERROR;
341 snmp_table_extract_value_from_s32ref(
struct snmp_node_instance* instance,
void* value)
344 *dst = instance->reference.s32;
349 snmp_table_extract_value_from_u32ref(
struct snmp_node_instance* instance,
void* value)
352 *dst = instance->reference.u32;
357 snmp_table_extract_value_from_refconstptr(
struct snmp_node_instance* instance,
void* value)
359 MEMCPY(value, instance->reference.const_ptr, instance->reference_len);
360 return (
u16_t)instance->reference_len;
#define MEMCPY(dst, src, len)
#define LWIP_DEBUGF(debug, message)
#define LWIP_UNUSED_ARG(x)