1195972f6Sopenharmony_ci/*
2195972f6Sopenharmony_ciGenerated by LwipMibCompiler
3195972f6Sopenharmony_ci*/
4195972f6Sopenharmony_ci
5195972f6Sopenharmony_ci#include "lwip/apps/snmp_opts.h"
6195972f6Sopenharmony_ci#if LWIP_SNMP && LWIP_SNMP_V3
7195972f6Sopenharmony_ci
8195972f6Sopenharmony_ci#include "lwip/apps/snmp_snmpv2_usm.h"
9195972f6Sopenharmony_ci#include "lwip/apps/snmp.h"
10195972f6Sopenharmony_ci#include "lwip/apps/snmp_core.h"
11195972f6Sopenharmony_ci#include "lwip/apps/snmp_scalar.h"
12195972f6Sopenharmony_ci#include "lwip/apps/snmp_table.h"
13195972f6Sopenharmony_ci#include "lwip/apps/snmpv3.h"
14195972f6Sopenharmony_ci#include "snmpv3_priv.h"
15195972f6Sopenharmony_ci
16195972f6Sopenharmony_ci#include "lwip/apps/snmp_snmpv2_framework.h"
17195972f6Sopenharmony_ci
18195972f6Sopenharmony_ci#include <string.h>
19195972f6Sopenharmony_ci
20195972f6Sopenharmony_ci/* --- usmUser 1.3.6.1.6.3.15.1.2 ----------------------------------------------------- */
21195972f6Sopenharmony_ci
22195972f6Sopenharmony_cistatic const struct snmp_oid_range usmUserTable_oid_ranges[] = {
23195972f6Sopenharmony_ci  { 0, 0xff }, { 0, 0xff }, { 0, 0xff }, { 0, 0xff },
24195972f6Sopenharmony_ci  { 0, 0xff }, { 0, 0xff }, { 0, 0xff }, { 0, 0xff },
25195972f6Sopenharmony_ci  { 0, 0xff }, { 0, 0xff }, { 0, 0xff }, { 0, 0xff },
26195972f6Sopenharmony_ci  { 0, 0xff }, { 0, 0xff }, { 0, 0xff }, { 0, 0xff },
27195972f6Sopenharmony_ci  { 0, 0xff }, { 0, 0xff }, { 0, 0xff }, { 0, 0xff },
28195972f6Sopenharmony_ci  { 0, 0xff }, { 0, 0xff }, { 0, 0xff }, { 0, 0xff },
29195972f6Sopenharmony_ci  { 0, 0xff }, { 0, 0xff }, { 0, 0xff }, { 0, 0xff },
30195972f6Sopenharmony_ci  { 0, 0xff }, { 0, 0xff }, { 0, 0xff }, { 0, 0xff }
31195972f6Sopenharmony_ci};
32195972f6Sopenharmony_ci
33195972f6Sopenharmony_cistatic void snmp_engineid_to_oid(const char *engineid, u32_t *oid, u32_t len)
34195972f6Sopenharmony_ci{
35195972f6Sopenharmony_ci  u8_t i;
36195972f6Sopenharmony_ci
37195972f6Sopenharmony_ci  for (i = 0; i < len; i++) {
38195972f6Sopenharmony_ci    oid[i] = engineid[i];
39195972f6Sopenharmony_ci  }
40195972f6Sopenharmony_ci}
41195972f6Sopenharmony_ci
42195972f6Sopenharmony_cistatic void snmp_oid_to_name(char *name, const u32_t *oid, size_t len)
43195972f6Sopenharmony_ci{
44195972f6Sopenharmony_ci  u8_t i;
45195972f6Sopenharmony_ci
46195972f6Sopenharmony_ci  for (i = 0; i < len; i++) {
47195972f6Sopenharmony_ci    name[i] = (char)oid[i];
48195972f6Sopenharmony_ci  }
49195972f6Sopenharmony_ci}
50195972f6Sopenharmony_ci
51195972f6Sopenharmony_cistatic void snmp_name_to_oid(const char *name, u32_t *oid, size_t len)
52195972f6Sopenharmony_ci{
53195972f6Sopenharmony_ci  u8_t i;
54195972f6Sopenharmony_ci
55195972f6Sopenharmony_ci  for (i = 0; i < len; i++) {
56195972f6Sopenharmony_ci    oid[i] = name[i];
57195972f6Sopenharmony_ci  }
58195972f6Sopenharmony_ci}
59195972f6Sopenharmony_ci
60195972f6Sopenharmony_cistatic const struct snmp_obj_id *snmp_auth_algo_to_oid(snmpv3_auth_algo_t algo)
61195972f6Sopenharmony_ci{
62195972f6Sopenharmony_ci  if (algo == SNMP_V3_AUTH_ALGO_MD5) {
63195972f6Sopenharmony_ci    return &usmHMACMD5AuthProtocol;
64195972f6Sopenharmony_ci  } else if (algo ==  SNMP_V3_AUTH_ALGO_SHA) {
65195972f6Sopenharmony_ci    return &usmHMACMD5AuthProtocol;
66195972f6Sopenharmony_ci  }
67195972f6Sopenharmony_ci
68195972f6Sopenharmony_ci  return &usmNoAuthProtocol;
69195972f6Sopenharmony_ci}
70195972f6Sopenharmony_ci
71195972f6Sopenharmony_cistatic const struct snmp_obj_id *snmp_priv_algo_to_oid(snmpv3_priv_algo_t algo)
72195972f6Sopenharmony_ci{
73195972f6Sopenharmony_ci  if (algo == SNMP_V3_PRIV_ALGO_DES) {
74195972f6Sopenharmony_ci    return &usmDESPrivProtocol;
75195972f6Sopenharmony_ci  } else if (algo == SNMP_V3_PRIV_ALGO_AES) {
76195972f6Sopenharmony_ci    return &usmAESPrivProtocol;
77195972f6Sopenharmony_ci  }
78195972f6Sopenharmony_ci
79195972f6Sopenharmony_ci  return &usmNoPrivProtocol;
80195972f6Sopenharmony_ci}
81195972f6Sopenharmony_ci
82195972f6Sopenharmony_cichar username[32];
83195972f6Sopenharmony_ci
84195972f6Sopenharmony_cistatic snmp_err_t usmusertable_get_instance(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, struct snmp_node_instance *cell_instance)
85195972f6Sopenharmony_ci{
86195972f6Sopenharmony_ci  const char *engineid;
87195972f6Sopenharmony_ci  u8_t eid_len;
88195972f6Sopenharmony_ci
89195972f6Sopenharmony_ci  u32_t engineid_oid[SNMP_V3_MAX_ENGINE_ID_LENGTH];
90195972f6Sopenharmony_ci
91195972f6Sopenharmony_ci  u8_t name_len;
92195972f6Sopenharmony_ci  u8_t engineid_len;
93195972f6Sopenharmony_ci
94195972f6Sopenharmony_ci  u8_t name_start;
95195972f6Sopenharmony_ci  u8_t engineid_start;
96195972f6Sopenharmony_ci
97195972f6Sopenharmony_ci  LWIP_UNUSED_ARG(column);
98195972f6Sopenharmony_ci
99195972f6Sopenharmony_ci  snmpv3_get_engine_id(&engineid, &eid_len);
100195972f6Sopenharmony_ci
101195972f6Sopenharmony_ci  engineid_len = (u8_t)row_oid[0];
102195972f6Sopenharmony_ci  engineid_start = 1;
103195972f6Sopenharmony_ci
104195972f6Sopenharmony_ci  if (engineid_len != eid_len) {
105195972f6Sopenharmony_ci    /* EngineID length does not match! */
106195972f6Sopenharmony_ci    return SNMP_ERR_NOSUCHINSTANCE;
107195972f6Sopenharmony_ci  }
108195972f6Sopenharmony_ci
109195972f6Sopenharmony_ci  if (engineid_len > row_oid_len) {
110195972f6Sopenharmony_ci    /* row OID doesn't contain enough data according to engineid_len.*/
111195972f6Sopenharmony_ci    return SNMP_ERR_NOSUCHINSTANCE;
112195972f6Sopenharmony_ci  }
113195972f6Sopenharmony_ci
114195972f6Sopenharmony_ci  /* check if incoming OID length and if values are in plausible range */
115195972f6Sopenharmony_ci  if (!snmp_oid_in_range(&row_oid[engineid_start], engineid_len, usmUserTable_oid_ranges, engineid_len)) {
116195972f6Sopenharmony_ci    return SNMP_ERR_NOSUCHINSTANCE;
117195972f6Sopenharmony_ci  }
118195972f6Sopenharmony_ci
119195972f6Sopenharmony_ci  snmp_engineid_to_oid(engineid, engineid_oid, engineid_len);
120195972f6Sopenharmony_ci
121195972f6Sopenharmony_ci  /* Verify EngineID */
122195972f6Sopenharmony_ci  if (snmp_oid_equal(&row_oid[engineid_start], engineid_len, engineid_oid, engineid_len)) {
123195972f6Sopenharmony_ci    return SNMP_ERR_NOSUCHINSTANCE;
124195972f6Sopenharmony_ci  }
125195972f6Sopenharmony_ci
126195972f6Sopenharmony_ci  name_len = (u8_t)row_oid[engineid_start + engineid_len];
127195972f6Sopenharmony_ci  name_start = engineid_start + engineid_len + 1;
128195972f6Sopenharmony_ci
129195972f6Sopenharmony_ci  if (name_len > SNMP_V3_MAX_USER_LENGTH) {
130195972f6Sopenharmony_ci    /* specified name is too long */
131195972f6Sopenharmony_ci    return SNMP_ERR_NOSUCHINSTANCE;
132195972f6Sopenharmony_ci  }
133195972f6Sopenharmony_ci
134195972f6Sopenharmony_ci  if (1 + engineid_len + 1 + name_len != row_oid_len) {
135195972f6Sopenharmony_ci    /* Length of EngineID and name does not match row oid length. (+2 for length fields)*/
136195972f6Sopenharmony_ci    return SNMP_ERR_NOSUCHINSTANCE;
137195972f6Sopenharmony_ci  }
138195972f6Sopenharmony_ci
139195972f6Sopenharmony_ci  /* check if incoming OID length and if values are in plausible range */
140195972f6Sopenharmony_ci  if (!snmp_oid_in_range(&row_oid[name_start], name_len, usmUserTable_oid_ranges, name_len)) {
141195972f6Sopenharmony_ci    return SNMP_ERR_NOSUCHINSTANCE;
142195972f6Sopenharmony_ci  }
143195972f6Sopenharmony_ci
144195972f6Sopenharmony_ci  /* Verify if user exists */
145195972f6Sopenharmony_ci  memset(username, 0, sizeof(username));
146195972f6Sopenharmony_ci  snmp_oid_to_name(username, &row_oid[name_start], name_len);
147195972f6Sopenharmony_ci  if (snmpv3_get_user(username, NULL, NULL, NULL, NULL) != ERR_OK) {
148195972f6Sopenharmony_ci    return SNMP_ERR_NOSUCHINSTANCE;
149195972f6Sopenharmony_ci  }
150195972f6Sopenharmony_ci
151195972f6Sopenharmony_ci  /* Save name in reference pointer to make it easier to handle later on */
152195972f6Sopenharmony_ci  cell_instance->reference.ptr = username;
153195972f6Sopenharmony_ci  cell_instance->reference_len = name_len;
154195972f6Sopenharmony_ci
155195972f6Sopenharmony_ci  /* user was found */
156195972f6Sopenharmony_ci  return SNMP_ERR_NOERROR;
157195972f6Sopenharmony_ci}
158195972f6Sopenharmony_ci
159195972f6Sopenharmony_ci/*
160195972f6Sopenharmony_ci * valid oid options
161195972f6Sopenharmony_ci * <oid>
162195972f6Sopenharmony_ci * <oid>.<EngineID length>
163195972f6Sopenharmony_ci * <oid>.<EngineID length>.<partial EngineID>
164195972f6Sopenharmony_ci * <oid>.<EngineID length>.<EngineID>
165195972f6Sopenharmony_ci * <oid>.<EngineID length>.<EngineID>.<UserName length>
166195972f6Sopenharmony_ci * <oid>.<EngineID length>.<EngineID>.<UserName length>.<partial UserName>
167195972f6Sopenharmony_ci * <oid>.<EngineID length>.<EngineID>.<UserName length>.<UserName>
168195972f6Sopenharmony_ci *
169195972f6Sopenharmony_ci */
170195972f6Sopenharmony_cistatic snmp_err_t usmusertable_get_next_instance(const u32_t *column, struct snmp_obj_id *row_oid, struct snmp_node_instance *cell_instance)
171195972f6Sopenharmony_ci{
172195972f6Sopenharmony_ci  const char *engineid;
173195972f6Sopenharmony_ci  u8_t eid_len;
174195972f6Sopenharmony_ci
175195972f6Sopenharmony_ci  u32_t engineid_oid[SNMP_V3_MAX_ENGINE_ID_LENGTH];
176195972f6Sopenharmony_ci
177195972f6Sopenharmony_ci  u8_t name_len;
178195972f6Sopenharmony_ci  u8_t engineid_len;
179195972f6Sopenharmony_ci
180195972f6Sopenharmony_ci  u8_t name_start;
181195972f6Sopenharmony_ci  u8_t engineid_start = 1;
182195972f6Sopenharmony_ci  u8_t i;
183195972f6Sopenharmony_ci
184195972f6Sopenharmony_ci  struct snmp_next_oid_state state;
185195972f6Sopenharmony_ci
186195972f6Sopenharmony_ci  u32_t result_temp[LWIP_ARRAYSIZE(usmUserTable_oid_ranges)];
187195972f6Sopenharmony_ci
188195972f6Sopenharmony_ci  LWIP_UNUSED_ARG(column);
189195972f6Sopenharmony_ci
190195972f6Sopenharmony_ci  snmpv3_get_engine_id(&engineid, &eid_len);
191195972f6Sopenharmony_ci
192195972f6Sopenharmony_ci  /* If EngineID might be given */
193195972f6Sopenharmony_ci  if (row_oid->len > 0) {
194195972f6Sopenharmony_ci    engineid_len = (u8_t)row_oid->id[0];
195195972f6Sopenharmony_ci    engineid_start = 1;
196195972f6Sopenharmony_ci
197195972f6Sopenharmony_ci    if (engineid_len != eid_len) {
198195972f6Sopenharmony_ci      /* EngineID length does not match! */
199195972f6Sopenharmony_ci      return SNMP_ERR_NOSUCHINSTANCE;
200195972f6Sopenharmony_ci    }
201195972f6Sopenharmony_ci
202195972f6Sopenharmony_ci    if (engineid_len > row_oid->len) {
203195972f6Sopenharmony_ci      /* Verify partial EngineID */
204195972f6Sopenharmony_ci      snmp_engineid_to_oid(engineid, engineid_oid, row_oid->len - 1);
205195972f6Sopenharmony_ci      if (!snmp_oid_equal(&row_oid->id[engineid_start], row_oid->len - 1, engineid_oid, row_oid->len - 1)) {
206195972f6Sopenharmony_ci        return SNMP_ERR_NOSUCHINSTANCE;
207195972f6Sopenharmony_ci      }
208195972f6Sopenharmony_ci    } else {
209195972f6Sopenharmony_ci      /* Verify complete EngineID */
210195972f6Sopenharmony_ci      snmp_engineid_to_oid(engineid, engineid_oid, engineid_len);
211195972f6Sopenharmony_ci      if (!snmp_oid_equal(&row_oid->id[engineid_start], engineid_len, engineid_oid, engineid_len)) {
212195972f6Sopenharmony_ci        return SNMP_ERR_NOSUCHINSTANCE;
213195972f6Sopenharmony_ci      }
214195972f6Sopenharmony_ci    }
215195972f6Sopenharmony_ci
216195972f6Sopenharmony_ci    /* At this point, the given EngineID (partially) matches the local EngineID.*/
217195972f6Sopenharmony_ci
218195972f6Sopenharmony_ci    /* If name might also be given */
219195972f6Sopenharmony_ci    if (row_oid->len > engineid_start + engineid_len) {
220195972f6Sopenharmony_ci      name_len = (u8_t)row_oid->id[engineid_start + engineid_len];
221195972f6Sopenharmony_ci      name_start = engineid_start + engineid_len + 1;
222195972f6Sopenharmony_ci
223195972f6Sopenharmony_ci      if (name_len > SNMP_V3_MAX_USER_LENGTH) {
224195972f6Sopenharmony_ci        /* specified name is too long, max length is 32 according to mib file.*/
225195972f6Sopenharmony_ci        return SNMP_ERR_NOSUCHINSTANCE;
226195972f6Sopenharmony_ci      }
227195972f6Sopenharmony_ci
228195972f6Sopenharmony_ci      if (row_oid->len < engineid_len + name_len + 2) {
229195972f6Sopenharmony_ci        /* Partial name given according to oid.*/
230195972f6Sopenharmony_ci        u8_t tmplen = row_oid->len - engineid_len - 2;
231195972f6Sopenharmony_ci        if (!snmp_oid_in_range(&row_oid->id[name_start], tmplen, usmUserTable_oid_ranges, tmplen)) {
232195972f6Sopenharmony_ci          return SNMP_ERR_NOSUCHINSTANCE;
233195972f6Sopenharmony_ci        }
234195972f6Sopenharmony_ci      } else {
235195972f6Sopenharmony_ci        /* Full name given according to oid. Also test for too much data.*/
236195972f6Sopenharmony_ci        u8_t tmplen = row_oid->len - engineid_len - 2;
237195972f6Sopenharmony_ci        if (!snmp_oid_in_range(&row_oid->id[name_start], name_len, usmUserTable_oid_ranges, tmplen)) {
238195972f6Sopenharmony_ci          return SNMP_ERR_NOSUCHINSTANCE;
239195972f6Sopenharmony_ci        }
240195972f6Sopenharmony_ci      }
241195972f6Sopenharmony_ci
242195972f6Sopenharmony_ci      /* At this point the EngineID and (partial) UserName match the local EngineID and UserName.*/
243195972f6Sopenharmony_ci    }
244195972f6Sopenharmony_ci  }
245195972f6Sopenharmony_ci
246195972f6Sopenharmony_ci  /* init struct to search next oid */
247195972f6Sopenharmony_ci  snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(usmUserTable_oid_ranges));
248195972f6Sopenharmony_ci
249195972f6Sopenharmony_ci  for (i = 0; i < snmpv3_get_amount_of_users(); i++) {
250195972f6Sopenharmony_ci    u32_t test_oid[LWIP_ARRAYSIZE(usmUserTable_oid_ranges)];
251195972f6Sopenharmony_ci
252195972f6Sopenharmony_ci    test_oid[0] = eid_len;
253195972f6Sopenharmony_ci    snmp_engineid_to_oid(engineid, &test_oid[1], eid_len);
254195972f6Sopenharmony_ci
255195972f6Sopenharmony_ci    snmpv3_get_username(username, i);
256195972f6Sopenharmony_ci
257195972f6Sopenharmony_ci    test_oid[1 + eid_len] = strlen(username);
258195972f6Sopenharmony_ci    snmp_name_to_oid(username, &test_oid[2 + eid_len], strlen(username));
259195972f6Sopenharmony_ci
260195972f6Sopenharmony_ci    /* check generated OID: is it a candidate for the next one? */
261195972f6Sopenharmony_ci    snmp_next_oid_check(&state, test_oid, (u8_t)(1 + eid_len + 1 + strlen(username)), LWIP_PTR_NUMERIC_CAST(void *, i));
262195972f6Sopenharmony_ci  }
263195972f6Sopenharmony_ci
264195972f6Sopenharmony_ci  /* did we find a next one? */
265195972f6Sopenharmony_ci  if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {
266195972f6Sopenharmony_ci    snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
267195972f6Sopenharmony_ci    /* store username for subsequent operations (get/test/set) */
268195972f6Sopenharmony_ci    memset(username, 0, sizeof(username));
269195972f6Sopenharmony_ci    snmpv3_get_username(username, LWIP_PTR_NUMERIC_CAST(u8_t, state.reference));
270195972f6Sopenharmony_ci    cell_instance->reference.ptr = username;
271195972f6Sopenharmony_ci    cell_instance->reference_len = strlen(username);
272195972f6Sopenharmony_ci    return SNMP_ERR_NOERROR;
273195972f6Sopenharmony_ci  }
274195972f6Sopenharmony_ci
275195972f6Sopenharmony_ci  /* not found */
276195972f6Sopenharmony_ci  return SNMP_ERR_NOSUCHINSTANCE;
277195972f6Sopenharmony_ci}
278195972f6Sopenharmony_ci
279195972f6Sopenharmony_cistatic s16_t usmusertable_get_value(struct snmp_node_instance *cell_instance, void *value)
280195972f6Sopenharmony_ci{
281195972f6Sopenharmony_ci  snmpv3_user_storagetype_t storage_type;
282195972f6Sopenharmony_ci
283195972f6Sopenharmony_ci  switch (SNMP_TABLE_GET_COLUMN_FROM_OID(cell_instance->instance_oid.id)) {
284195972f6Sopenharmony_ci    case 3: /* usmUserSecurityName */
285195972f6Sopenharmony_ci      MEMCPY(value, cell_instance->reference.ptr, cell_instance->reference_len);
286195972f6Sopenharmony_ci      return (s16_t)cell_instance->reference_len;
287195972f6Sopenharmony_ci    case 4: /* usmUserCloneFrom */
288195972f6Sopenharmony_ci      MEMCPY(value, snmp_zero_dot_zero.id, snmp_zero_dot_zero.len * sizeof(u32_t));
289195972f6Sopenharmony_ci      return snmp_zero_dot_zero.len * sizeof(u32_t);
290195972f6Sopenharmony_ci    case 5: { /* usmUserAuthProtocol */
291195972f6Sopenharmony_ci      const struct snmp_obj_id *auth_algo;
292195972f6Sopenharmony_ci      snmpv3_auth_algo_t auth_algo_val;
293195972f6Sopenharmony_ci      snmpv3_get_user((const char *)cell_instance->reference.ptr, &auth_algo_val, NULL, NULL, NULL);
294195972f6Sopenharmony_ci      auth_algo = snmp_auth_algo_to_oid(auth_algo_val);
295195972f6Sopenharmony_ci      MEMCPY(value, auth_algo->id, auth_algo->len * sizeof(u32_t));
296195972f6Sopenharmony_ci      return auth_algo->len * sizeof(u32_t);
297195972f6Sopenharmony_ci    }
298195972f6Sopenharmony_ci    case 6: /* usmUserAuthKeyChange */
299195972f6Sopenharmony_ci      return 0;
300195972f6Sopenharmony_ci    case 7: /* usmUserOwnAuthKeyChange */
301195972f6Sopenharmony_ci      return 0;
302195972f6Sopenharmony_ci    case 8: { /* usmUserPrivProtocol */
303195972f6Sopenharmony_ci      const struct snmp_obj_id *priv_algo;
304195972f6Sopenharmony_ci      snmpv3_priv_algo_t priv_algo_val;
305195972f6Sopenharmony_ci      snmpv3_get_user((const char *)cell_instance->reference.ptr, NULL, NULL, &priv_algo_val, NULL);
306195972f6Sopenharmony_ci      priv_algo = snmp_priv_algo_to_oid(priv_algo_val);
307195972f6Sopenharmony_ci      MEMCPY(value, priv_algo->id, priv_algo->len * sizeof(u32_t));
308195972f6Sopenharmony_ci      return priv_algo->len * sizeof(u32_t);
309195972f6Sopenharmony_ci    }
310195972f6Sopenharmony_ci    case 9: /* usmUserPrivKeyChange */
311195972f6Sopenharmony_ci      return 0;
312195972f6Sopenharmony_ci    case 10: /* usmUserOwnPrivKeyChange */
313195972f6Sopenharmony_ci      return 0;
314195972f6Sopenharmony_ci    case 11: /* usmUserPublic */
315195972f6Sopenharmony_ci      /* TODO: Implement usmUserPublic */
316195972f6Sopenharmony_ci      return 0;
317195972f6Sopenharmony_ci    case 12: /* usmUserStorageType */
318195972f6Sopenharmony_ci      snmpv3_get_user_storagetype((const char *)cell_instance->reference.ptr, &storage_type);
319195972f6Sopenharmony_ci      *(s32_t *)value = storage_type;
320195972f6Sopenharmony_ci      return sizeof(s32_t);
321195972f6Sopenharmony_ci    case 13: /* usmUserStatus */
322195972f6Sopenharmony_ci      *(s32_t *)value = 1; /* active */
323195972f6Sopenharmony_ci      return sizeof(s32_t);
324195972f6Sopenharmony_ci    default:
325195972f6Sopenharmony_ci      LWIP_DEBUGF(SNMP_MIB_DEBUG, ("usmusertable_get_value(): unknown id: %"S32_F"\n", SNMP_TABLE_GET_COLUMN_FROM_OID(cell_instance->instance_oid.id)));
326195972f6Sopenharmony_ci      return 0;
327195972f6Sopenharmony_ci  }
328195972f6Sopenharmony_ci}
329195972f6Sopenharmony_ci
330195972f6Sopenharmony_ci/* --- usmMIBObjects 1.3.6.1.6.3.15.1 ----------------------------------------------------- */
331195972f6Sopenharmony_cistatic s16_t usmstats_scalars_get_value(const struct snmp_scalar_array_node_def *node, void *value)
332195972f6Sopenharmony_ci{
333195972f6Sopenharmony_ci  u32_t *uint_ptr = (u32_t *)value;
334195972f6Sopenharmony_ci  switch (node->oid) {
335195972f6Sopenharmony_ci    case 1: /* usmStatsUnsupportedSecLevels */
336195972f6Sopenharmony_ci      *uint_ptr = snmp_stats.unsupportedseclevels;
337195972f6Sopenharmony_ci      break;
338195972f6Sopenharmony_ci    case 2: /* usmStatsNotInTimeWindows */
339195972f6Sopenharmony_ci      *uint_ptr = snmp_stats.notintimewindows;
340195972f6Sopenharmony_ci      break;
341195972f6Sopenharmony_ci    case 3: /* usmStatsUnknownUserNames */
342195972f6Sopenharmony_ci      *uint_ptr = snmp_stats.unknownusernames;
343195972f6Sopenharmony_ci      break;
344195972f6Sopenharmony_ci    case 4: /* usmStatsUnknownEngineIDs */
345195972f6Sopenharmony_ci      *uint_ptr = snmp_stats.unknownengineids;
346195972f6Sopenharmony_ci      break;
347195972f6Sopenharmony_ci    case 5: /* usmStatsWrongDigests */
348195972f6Sopenharmony_ci      *uint_ptr = snmp_stats.wrongdigests;
349195972f6Sopenharmony_ci      break;
350195972f6Sopenharmony_ci    case 6: /* usmStatsDecryptionErrors */
351195972f6Sopenharmony_ci      *uint_ptr = snmp_stats.decryptionerrors;
352195972f6Sopenharmony_ci      break;
353195972f6Sopenharmony_ci    default:
354195972f6Sopenharmony_ci      LWIP_DEBUGF(SNMP_MIB_DEBUG, ("usmstats_scalars_get_value(): unknown id: %"S32_F"\n", node->oid));
355195972f6Sopenharmony_ci      return 0;
356195972f6Sopenharmony_ci  }
357195972f6Sopenharmony_ci
358195972f6Sopenharmony_ci  return sizeof(*uint_ptr);
359195972f6Sopenharmony_ci}
360195972f6Sopenharmony_ci
361195972f6Sopenharmony_ci/* --- snmpUsmMIB  ----------------------------------------------------- */
362195972f6Sopenharmony_ci
363195972f6Sopenharmony_ci/* --- usmUser 1.3.6.1.6.3.15.1.2 ----------------------------------------------------- */
364195972f6Sopenharmony_ci
365195972f6Sopenharmony_cistatic const struct snmp_table_col_def usmusertable_columns[] = {
366195972f6Sopenharmony_ci  {3,  SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserSecurityName */
367195972f6Sopenharmony_ci  {4,  SNMP_ASN1_TYPE_OBJECT_ID,    SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserCloneFrom */
368195972f6Sopenharmony_ci  {5,  SNMP_ASN1_TYPE_OBJECT_ID,    SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserAuthProtocol */
369195972f6Sopenharmony_ci  {6,  SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserAuthKeyChange */
370195972f6Sopenharmony_ci  {7,  SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserOwnAuthKeyChange */
371195972f6Sopenharmony_ci  {8,  SNMP_ASN1_TYPE_OBJECT_ID,    SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserPrivProtocol */
372195972f6Sopenharmony_ci  {9,  SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserPrivKeyChange */
373195972f6Sopenharmony_ci  {10, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserOwnPrivKeyChange */
374195972f6Sopenharmony_ci  {11, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserPublic */
375195972f6Sopenharmony_ci  {12, SNMP_ASN1_TYPE_INTEGER,      SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserStorageType */
376195972f6Sopenharmony_ci  {13, SNMP_ASN1_TYPE_INTEGER,      SNMP_NODE_INSTANCE_READ_ONLY}, /* usmUserStatus */
377195972f6Sopenharmony_ci};
378195972f6Sopenharmony_cistatic const struct snmp_table_node usmusertable = SNMP_TABLE_CREATE(2, usmusertable_columns, usmusertable_get_instance, usmusertable_get_next_instance, usmusertable_get_value, NULL, NULL);
379195972f6Sopenharmony_ci
380195972f6Sopenharmony_cistatic const struct snmp_node *const usmuser_subnodes[] = {
381195972f6Sopenharmony_ci  &usmusertable.node.node
382195972f6Sopenharmony_ci};
383195972f6Sopenharmony_cistatic const struct snmp_tree_node usmuser_treenode = SNMP_CREATE_TREE_NODE(2, usmuser_subnodes);
384195972f6Sopenharmony_ci
385195972f6Sopenharmony_ci/* --- usmMIBObjects 1.3.6.1.6.3.15.1 ----------------------------------------------------- */
386195972f6Sopenharmony_cistatic const struct snmp_scalar_array_node_def usmstats_scalars_nodes[] = {
387195972f6Sopenharmony_ci  {1, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmStatsUnsupportedSecLevels */
388195972f6Sopenharmony_ci  {2, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmStatsNotInTimeWindows */
389195972f6Sopenharmony_ci  {3, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmStatsUnknownUserNames */
390195972f6Sopenharmony_ci  {4, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmStatsUnknownEngineIDs */
391195972f6Sopenharmony_ci  {5, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmStatsWrongDigests */
392195972f6Sopenharmony_ci  {6, SNMP_ASN1_TYPE_COUNTER, SNMP_NODE_INSTANCE_READ_ONLY}, /* usmStatsDecryptionErrors */
393195972f6Sopenharmony_ci};
394195972f6Sopenharmony_cistatic const struct snmp_scalar_array_node usmstats_scalars = SNMP_SCALAR_CREATE_ARRAY_NODE(1, usmstats_scalars_nodes, usmstats_scalars_get_value, NULL, NULL);
395195972f6Sopenharmony_ci
396195972f6Sopenharmony_cistatic const struct snmp_node *const usmmibobjects_subnodes[] = {
397195972f6Sopenharmony_ci  &usmstats_scalars.node.node,
398195972f6Sopenharmony_ci  &usmuser_treenode.node
399195972f6Sopenharmony_ci};
400195972f6Sopenharmony_cistatic const struct snmp_tree_node usmmibobjects_treenode = SNMP_CREATE_TREE_NODE(1, usmmibobjects_subnodes);
401195972f6Sopenharmony_ci
402195972f6Sopenharmony_ci/* --- snmpUsmMIB  ----------------------------------------------------- */
403195972f6Sopenharmony_cistatic const struct snmp_node *const snmpusmmib_subnodes[] = {
404195972f6Sopenharmony_ci  &usmmibobjects_treenode.node
405195972f6Sopenharmony_ci};
406195972f6Sopenharmony_cistatic const struct snmp_tree_node snmpusmmib_root = SNMP_CREATE_TREE_NODE(15, snmpusmmib_subnodes);
407195972f6Sopenharmony_cistatic const u32_t snmpusmmib_base_oid[] = {1, 3, 6, 1, 6, 3, 15};
408195972f6Sopenharmony_ciconst struct snmp_mib snmpusmmib = {snmpusmmib_base_oid, LWIP_ARRAYSIZE(snmpusmmib_base_oid), &snmpusmmib_root.node};
409195972f6Sopenharmony_ci
410195972f6Sopenharmony_ci#endif /* LWIP_SNMP */
411