1195972f6Sopenharmony_ci/**
2195972f6Sopenharmony_ci * @file
3195972f6Sopenharmony_ci * Management Information Base II (RFC1213) SYSTEM objects and functions.
4195972f6Sopenharmony_ci */
5195972f6Sopenharmony_ci
6195972f6Sopenharmony_ci/*
7195972f6Sopenharmony_ci * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
8195972f6Sopenharmony_ci * All rights reserved.
9195972f6Sopenharmony_ci *
10195972f6Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification,
11195972f6Sopenharmony_ci * are permitted provided that the following conditions are met:
12195972f6Sopenharmony_ci *
13195972f6Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice,
14195972f6Sopenharmony_ci *    this list of conditions and the following disclaimer.
15195972f6Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice,
16195972f6Sopenharmony_ci *    this list of conditions and the following disclaimer in the documentation
17195972f6Sopenharmony_ci *    and/or other materials provided with the distribution.
18195972f6Sopenharmony_ci * 3. The name of the author may not be used to endorse or promote products
19195972f6Sopenharmony_ci *    derived from this software without specific prior written permission.
20195972f6Sopenharmony_ci *
21195972f6Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22195972f6Sopenharmony_ci * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23195972f6Sopenharmony_ci * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24195972f6Sopenharmony_ci * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25195972f6Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26195972f6Sopenharmony_ci * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27195972f6Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28195972f6Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29195972f6Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30195972f6Sopenharmony_ci * OF SUCH DAMAGE.
31195972f6Sopenharmony_ci *
32195972f6Sopenharmony_ci * Author: Dirk Ziegelmeier <dziegel@gmx.de>
33195972f6Sopenharmony_ci *         Christiaan Simons <christiaan.simons@axon.tv>
34195972f6Sopenharmony_ci */
35195972f6Sopenharmony_ci
36195972f6Sopenharmony_ci#include "lwip/snmp.h"
37195972f6Sopenharmony_ci#include "lwip/apps/snmp.h"
38195972f6Sopenharmony_ci#include "lwip/apps/snmp_core.h"
39195972f6Sopenharmony_ci#include "lwip/apps/snmp_mib2.h"
40195972f6Sopenharmony_ci#include "lwip/apps/snmp_table.h"
41195972f6Sopenharmony_ci#include "lwip/apps/snmp_scalar.h"
42195972f6Sopenharmony_ci#include "lwip/sys.h"
43195972f6Sopenharmony_ci
44195972f6Sopenharmony_ci#include <string.h>
45195972f6Sopenharmony_ci
46195972f6Sopenharmony_ci#if LWIP_SNMP && SNMP_LWIP_MIB2
47195972f6Sopenharmony_ci
48195972f6Sopenharmony_ci#if SNMP_USE_NETCONN
49195972f6Sopenharmony_ci#define SYNC_NODE_NAME(node_name) node_name ## _synced
50195972f6Sopenharmony_ci#define CREATE_LWIP_SYNC_NODE(oid, node_name) \
51195972f6Sopenharmony_ci   static const struct snmp_threadsync_node node_name ## _synced = SNMP_CREATE_THREAD_SYNC_NODE(oid, &node_name.node, &snmp_mib2_lwip_locks);
52195972f6Sopenharmony_ci#else
53195972f6Sopenharmony_ci#define SYNC_NODE_NAME(node_name) node_name
54195972f6Sopenharmony_ci#define CREATE_LWIP_SYNC_NODE(oid, node_name)
55195972f6Sopenharmony_ci#endif
56195972f6Sopenharmony_ci
57195972f6Sopenharmony_ci/* --- system .1.3.6.1.2.1.1 ----------------------------------------------------- */
58195972f6Sopenharmony_ci
59195972f6Sopenharmony_ci/** mib-2.system.sysDescr */
60195972f6Sopenharmony_cistatic const u8_t   sysdescr_default[] = SNMP_LWIP_MIB2_SYSDESC;
61195972f6Sopenharmony_cistatic const u8_t  *sysdescr           = sysdescr_default;
62195972f6Sopenharmony_cistatic const u16_t *sysdescr_len       = NULL; /* use strlen for determining len */
63195972f6Sopenharmony_ci
64195972f6Sopenharmony_ci/** mib-2.system.sysContact */
65195972f6Sopenharmony_cistatic const u8_t   syscontact_default[]     = SNMP_LWIP_MIB2_SYSCONTACT;
66195972f6Sopenharmony_cistatic const u8_t  *syscontact               = syscontact_default;
67195972f6Sopenharmony_cistatic const u16_t *syscontact_len           = NULL; /* use strlen for determining len */
68195972f6Sopenharmony_cistatic u8_t        *syscontact_wr            = NULL; /* if writable, points to the same buffer as syscontact (required for correct constness) */
69195972f6Sopenharmony_cistatic u16_t       *syscontact_wr_len        = NULL; /* if writable, points to the same buffer as syscontact_len (required for correct constness) */
70195972f6Sopenharmony_cistatic u16_t        syscontact_bufsize       = 0;    /* 0=not writable */
71195972f6Sopenharmony_ci
72195972f6Sopenharmony_ci/** mib-2.system.sysName */
73195972f6Sopenharmony_cistatic const u8_t   sysname_default[]        = SNMP_LWIP_MIB2_SYSNAME;
74195972f6Sopenharmony_cistatic const u8_t  *sysname                  = sysname_default;
75195972f6Sopenharmony_cistatic const u16_t *sysname_len              = NULL; /* use strlen for determining len */
76195972f6Sopenharmony_cistatic u8_t        *sysname_wr               = NULL; /* if writable, points to the same buffer as sysname (required for correct constness) */
77195972f6Sopenharmony_cistatic u16_t       *sysname_wr_len           = NULL; /* if writable, points to the same buffer as sysname_len (required for correct constness) */
78195972f6Sopenharmony_cistatic u16_t        sysname_bufsize          = 0;    /* 0=not writable */
79195972f6Sopenharmony_ci
80195972f6Sopenharmony_ci/** mib-2.system.sysLocation */
81195972f6Sopenharmony_cistatic const u8_t   syslocation_default[]    = SNMP_LWIP_MIB2_SYSLOCATION;
82195972f6Sopenharmony_cistatic const u8_t  *syslocation              = syslocation_default;
83195972f6Sopenharmony_cistatic const u16_t *syslocation_len           = NULL; /* use strlen for determining len */
84195972f6Sopenharmony_cistatic u8_t        *syslocation_wr            = NULL; /* if writable, points to the same buffer as syslocation (required for correct constness) */
85195972f6Sopenharmony_cistatic u16_t       *syslocation_wr_len        = NULL; /* if writable, points to the same buffer as syslocation_len (required for correct constness) */
86195972f6Sopenharmony_cistatic u16_t        syslocation_bufsize       = 0;    /* 0=not writable */
87195972f6Sopenharmony_ci
88195972f6Sopenharmony_ci/**
89195972f6Sopenharmony_ci * @ingroup snmp_mib2
90195972f6Sopenharmony_ci * Initializes sysDescr pointers.
91195972f6Sopenharmony_ci *
92195972f6Sopenharmony_ci * @param str if non-NULL then copy str pointer
93195972f6Sopenharmony_ci * @param len points to string length, excluding zero terminator
94195972f6Sopenharmony_ci */
95195972f6Sopenharmony_civoid
96195972f6Sopenharmony_cisnmp_mib2_set_sysdescr(const u8_t *str, const u16_t *len)
97195972f6Sopenharmony_ci{
98195972f6Sopenharmony_ci  if (str != NULL) {
99195972f6Sopenharmony_ci    sysdescr     = str;
100195972f6Sopenharmony_ci    sysdescr_len = len;
101195972f6Sopenharmony_ci  }
102195972f6Sopenharmony_ci}
103195972f6Sopenharmony_ci
104195972f6Sopenharmony_ci/**
105195972f6Sopenharmony_ci * @ingroup snmp_mib2
106195972f6Sopenharmony_ci * Initializes sysContact pointers
107195972f6Sopenharmony_ci *
108195972f6Sopenharmony_ci * @param ocstr if non-NULL then copy str pointer
109195972f6Sopenharmony_ci * @param ocstrlen points to string length, excluding zero terminator.
110195972f6Sopenharmony_ci *        if set to NULL it is assumed that ocstr is NULL-terminated.
111195972f6Sopenharmony_ci * @param bufsize size of the buffer in bytes.
112195972f6Sopenharmony_ci *        (this is required because the buffer can be overwritten by snmp-set)
113195972f6Sopenharmony_ci *        if ocstrlen is NULL buffer needs space for terminating 0 byte.
114195972f6Sopenharmony_ci *        otherwise complete buffer is used for string.
115195972f6Sopenharmony_ci *        if bufsize is set to 0, the value is regarded as read-only.
116195972f6Sopenharmony_ci */
117195972f6Sopenharmony_civoid
118195972f6Sopenharmony_cisnmp_mib2_set_syscontact(u8_t *ocstr, u16_t *ocstrlen, u16_t bufsize)
119195972f6Sopenharmony_ci{
120195972f6Sopenharmony_ci  if (ocstr != NULL) {
121195972f6Sopenharmony_ci    syscontact         = ocstr;
122195972f6Sopenharmony_ci    syscontact_wr      = ocstr;
123195972f6Sopenharmony_ci    syscontact_len     = ocstrlen;
124195972f6Sopenharmony_ci    syscontact_wr_len  = ocstrlen;
125195972f6Sopenharmony_ci    syscontact_bufsize = bufsize;
126195972f6Sopenharmony_ci  }
127195972f6Sopenharmony_ci}
128195972f6Sopenharmony_ci
129195972f6Sopenharmony_ci/**
130195972f6Sopenharmony_ci * @ingroup snmp_mib2
131195972f6Sopenharmony_ci * see \ref snmp_mib2_set_syscontact but set pointer to readonly memory
132195972f6Sopenharmony_ci */
133195972f6Sopenharmony_civoid
134195972f6Sopenharmony_cisnmp_mib2_set_syscontact_readonly(const u8_t *ocstr, const u16_t *ocstrlen)
135195972f6Sopenharmony_ci{
136195972f6Sopenharmony_ci  if (ocstr != NULL) {
137195972f6Sopenharmony_ci    syscontact         = ocstr;
138195972f6Sopenharmony_ci    syscontact_len     = ocstrlen;
139195972f6Sopenharmony_ci    syscontact_wr      = NULL;
140195972f6Sopenharmony_ci    syscontact_wr_len  = NULL;
141195972f6Sopenharmony_ci    syscontact_bufsize = 0;
142195972f6Sopenharmony_ci  }
143195972f6Sopenharmony_ci}
144195972f6Sopenharmony_ci
145195972f6Sopenharmony_ci
146195972f6Sopenharmony_ci/**
147195972f6Sopenharmony_ci * @ingroup snmp_mib2
148195972f6Sopenharmony_ci * Initializes sysName pointers
149195972f6Sopenharmony_ci *
150195972f6Sopenharmony_ci * @param ocstr if non-NULL then copy str pointer
151195972f6Sopenharmony_ci * @param ocstrlen points to string length, excluding zero terminator.
152195972f6Sopenharmony_ci *        if set to NULL it is assumed that ocstr is NULL-terminated.
153195972f6Sopenharmony_ci * @param bufsize size of the buffer in bytes.
154195972f6Sopenharmony_ci *        (this is required because the buffer can be overwritten by snmp-set)
155195972f6Sopenharmony_ci *        if ocstrlen is NULL buffer needs space for terminating 0 byte.
156195972f6Sopenharmony_ci *        otherwise complete buffer is used for string.
157195972f6Sopenharmony_ci *        if bufsize is set to 0, the value is regarded as read-only.
158195972f6Sopenharmony_ci */
159195972f6Sopenharmony_civoid
160195972f6Sopenharmony_cisnmp_mib2_set_sysname(u8_t *ocstr, u16_t *ocstrlen, u16_t bufsize)
161195972f6Sopenharmony_ci{
162195972f6Sopenharmony_ci  if (ocstr != NULL) {
163195972f6Sopenharmony_ci    sysname         = ocstr;
164195972f6Sopenharmony_ci    sysname_wr      = ocstr;
165195972f6Sopenharmony_ci    sysname_len     = ocstrlen;
166195972f6Sopenharmony_ci    sysname_wr_len  = ocstrlen;
167195972f6Sopenharmony_ci    sysname_bufsize = bufsize;
168195972f6Sopenharmony_ci  }
169195972f6Sopenharmony_ci}
170195972f6Sopenharmony_ci
171195972f6Sopenharmony_ci/**
172195972f6Sopenharmony_ci * @ingroup snmp_mib2
173195972f6Sopenharmony_ci * see \ref snmp_mib2_set_sysname but set pointer to readonly memory
174195972f6Sopenharmony_ci */
175195972f6Sopenharmony_civoid
176195972f6Sopenharmony_cisnmp_mib2_set_sysname_readonly(const u8_t *ocstr, const u16_t *ocstrlen)
177195972f6Sopenharmony_ci{
178195972f6Sopenharmony_ci  if (ocstr != NULL) {
179195972f6Sopenharmony_ci    sysname         = ocstr;
180195972f6Sopenharmony_ci    sysname_len     = ocstrlen;
181195972f6Sopenharmony_ci    sysname_wr      = NULL;
182195972f6Sopenharmony_ci    sysname_wr_len  = NULL;
183195972f6Sopenharmony_ci    sysname_bufsize = 0;
184195972f6Sopenharmony_ci  }
185195972f6Sopenharmony_ci}
186195972f6Sopenharmony_ci
187195972f6Sopenharmony_ci/**
188195972f6Sopenharmony_ci * @ingroup snmp_mib2
189195972f6Sopenharmony_ci * Initializes sysLocation pointers
190195972f6Sopenharmony_ci *
191195972f6Sopenharmony_ci * @param ocstr if non-NULL then copy str pointer
192195972f6Sopenharmony_ci * @param ocstrlen points to string length, excluding zero terminator.
193195972f6Sopenharmony_ci *        if set to NULL it is assumed that ocstr is NULL-terminated.
194195972f6Sopenharmony_ci * @param bufsize size of the buffer in bytes.
195195972f6Sopenharmony_ci *        (this is required because the buffer can be overwritten by snmp-set)
196195972f6Sopenharmony_ci *        if ocstrlen is NULL buffer needs space for terminating 0 byte.
197195972f6Sopenharmony_ci *        otherwise complete buffer is used for string.
198195972f6Sopenharmony_ci *        if bufsize is set to 0, the value is regarded as read-only.
199195972f6Sopenharmony_ci */
200195972f6Sopenharmony_civoid
201195972f6Sopenharmony_cisnmp_mib2_set_syslocation(u8_t *ocstr, u16_t *ocstrlen, u16_t bufsize)
202195972f6Sopenharmony_ci{
203195972f6Sopenharmony_ci  if (ocstr != NULL) {
204195972f6Sopenharmony_ci    syslocation         = ocstr;
205195972f6Sopenharmony_ci    syslocation_wr      = ocstr;
206195972f6Sopenharmony_ci    syslocation_len     = ocstrlen;
207195972f6Sopenharmony_ci    syslocation_wr_len  = ocstrlen;
208195972f6Sopenharmony_ci    syslocation_bufsize = bufsize;
209195972f6Sopenharmony_ci  }
210195972f6Sopenharmony_ci}
211195972f6Sopenharmony_ci
212195972f6Sopenharmony_ci/**
213195972f6Sopenharmony_ci * @ingroup snmp_mib2
214195972f6Sopenharmony_ci * see \ref snmp_mib2_set_syslocation but set pointer to readonly memory
215195972f6Sopenharmony_ci */
216195972f6Sopenharmony_civoid
217195972f6Sopenharmony_cisnmp_mib2_set_syslocation_readonly(const u8_t *ocstr, const u16_t *ocstrlen)
218195972f6Sopenharmony_ci{
219195972f6Sopenharmony_ci  if (ocstr != NULL) {
220195972f6Sopenharmony_ci    syslocation         = ocstr;
221195972f6Sopenharmony_ci    syslocation_len     = ocstrlen;
222195972f6Sopenharmony_ci    syslocation_wr      = NULL;
223195972f6Sopenharmony_ci    syslocation_wr_len  = NULL;
224195972f6Sopenharmony_ci    syslocation_bufsize = 0;
225195972f6Sopenharmony_ci  }
226195972f6Sopenharmony_ci}
227195972f6Sopenharmony_ci
228195972f6Sopenharmony_ci
229195972f6Sopenharmony_cistatic s16_t
230195972f6Sopenharmony_cisystem_get_value(const struct snmp_scalar_array_node_def *node, void *value)
231195972f6Sopenharmony_ci{
232195972f6Sopenharmony_ci  const u8_t  *var = NULL;
233195972f6Sopenharmony_ci  const s16_t *var_len;
234195972f6Sopenharmony_ci  u16_t result;
235195972f6Sopenharmony_ci
236195972f6Sopenharmony_ci  switch (node->oid) {
237195972f6Sopenharmony_ci    case 1: /* sysDescr */
238195972f6Sopenharmony_ci      var     = sysdescr;
239195972f6Sopenharmony_ci      var_len = (const s16_t *)sysdescr_len;
240195972f6Sopenharmony_ci      break;
241195972f6Sopenharmony_ci    case 2: { /* sysObjectID */
242195972f6Sopenharmony_ci      const struct snmp_obj_id *dev_enterprise_oid = snmp_get_device_enterprise_oid();
243195972f6Sopenharmony_ci      MEMCPY(value, dev_enterprise_oid->id, dev_enterprise_oid->len * sizeof(u32_t));
244195972f6Sopenharmony_ci      return dev_enterprise_oid->len * sizeof(u32_t);
245195972f6Sopenharmony_ci    }
246195972f6Sopenharmony_ci    case 3: /* sysUpTime */
247195972f6Sopenharmony_ci      MIB2_COPY_SYSUPTIME_TO((u32_t *)value);
248195972f6Sopenharmony_ci      return sizeof(u32_t);
249195972f6Sopenharmony_ci    case 4: /* sysContact */
250195972f6Sopenharmony_ci      var     = syscontact;
251195972f6Sopenharmony_ci      var_len = (const s16_t *)syscontact_len;
252195972f6Sopenharmony_ci      break;
253195972f6Sopenharmony_ci    case 5: /* sysName */
254195972f6Sopenharmony_ci      var     = sysname;
255195972f6Sopenharmony_ci      var_len = (const s16_t *)sysname_len;
256195972f6Sopenharmony_ci      break;
257195972f6Sopenharmony_ci    case 6: /* sysLocation */
258195972f6Sopenharmony_ci      var     = syslocation;
259195972f6Sopenharmony_ci      var_len = (const s16_t *)syslocation_len;
260195972f6Sopenharmony_ci      break;
261195972f6Sopenharmony_ci    case 7: /* sysServices */
262195972f6Sopenharmony_ci      *(s32_t *)value = SNMP_SYSSERVICES;
263195972f6Sopenharmony_ci      return sizeof(s32_t);
264195972f6Sopenharmony_ci    default:
265195972f6Sopenharmony_ci      LWIP_DEBUGF(SNMP_MIB_DEBUG, ("system_get_value(): unknown id: %"S32_F"\n", node->oid));
266195972f6Sopenharmony_ci      return 0;
267195972f6Sopenharmony_ci  }
268195972f6Sopenharmony_ci
269195972f6Sopenharmony_ci  /* handle string values (OID 1,4,5 and 6) */
270195972f6Sopenharmony_ci  LWIP_ASSERT("", (value != NULL));
271195972f6Sopenharmony_ci  if (var_len == NULL) {
272195972f6Sopenharmony_ci    result = (s16_t)strlen((const char *)var);
273195972f6Sopenharmony_ci  } else {
274195972f6Sopenharmony_ci    result = *var_len;
275195972f6Sopenharmony_ci  }
276195972f6Sopenharmony_ci  MEMCPY(value, var, result);
277195972f6Sopenharmony_ci  return result;
278195972f6Sopenharmony_ci}
279195972f6Sopenharmony_ci
280195972f6Sopenharmony_cistatic snmp_err_t
281195972f6Sopenharmony_cisystem_set_test(const struct snmp_scalar_array_node_def *node, u16_t len, void *value)
282195972f6Sopenharmony_ci{
283195972f6Sopenharmony_ci  snmp_err_t ret = SNMP_ERR_WRONGVALUE;
284195972f6Sopenharmony_ci  const u16_t *var_bufsize  = NULL;
285195972f6Sopenharmony_ci  const u16_t *var_wr_len;
286195972f6Sopenharmony_ci
287195972f6Sopenharmony_ci  LWIP_UNUSED_ARG(value);
288195972f6Sopenharmony_ci
289195972f6Sopenharmony_ci  switch (node->oid) {
290195972f6Sopenharmony_ci    case 4: /* sysContact */
291195972f6Sopenharmony_ci      var_bufsize  = &syscontact_bufsize;
292195972f6Sopenharmony_ci      var_wr_len   = syscontact_wr_len;
293195972f6Sopenharmony_ci      break;
294195972f6Sopenharmony_ci    case 5: /* sysName */
295195972f6Sopenharmony_ci      var_bufsize  = &sysname_bufsize;
296195972f6Sopenharmony_ci      var_wr_len   = sysname_wr_len;
297195972f6Sopenharmony_ci      break;
298195972f6Sopenharmony_ci    case 6: /* sysLocation */
299195972f6Sopenharmony_ci      var_bufsize  = &syslocation_bufsize;
300195972f6Sopenharmony_ci      var_wr_len   = syslocation_wr_len;
301195972f6Sopenharmony_ci      break;
302195972f6Sopenharmony_ci    default:
303195972f6Sopenharmony_ci      LWIP_DEBUGF(SNMP_MIB_DEBUG, ("system_set_test(): unknown id: %"S32_F"\n", node->oid));
304195972f6Sopenharmony_ci      return ret;
305195972f6Sopenharmony_ci  }
306195972f6Sopenharmony_ci
307195972f6Sopenharmony_ci  /* check if value is writable at all */
308195972f6Sopenharmony_ci  if (*var_bufsize > 0) {
309195972f6Sopenharmony_ci    if (var_wr_len == NULL) {
310195972f6Sopenharmony_ci      /* we have to take the terminating 0 into account */
311195972f6Sopenharmony_ci      if (len < *var_bufsize) {
312195972f6Sopenharmony_ci        ret = SNMP_ERR_NOERROR;
313195972f6Sopenharmony_ci      }
314195972f6Sopenharmony_ci    } else {
315195972f6Sopenharmony_ci      if (len <= *var_bufsize) {
316195972f6Sopenharmony_ci        ret = SNMP_ERR_NOERROR;
317195972f6Sopenharmony_ci      }
318195972f6Sopenharmony_ci    }
319195972f6Sopenharmony_ci  } else {
320195972f6Sopenharmony_ci    ret = SNMP_ERR_NOTWRITABLE;
321195972f6Sopenharmony_ci  }
322195972f6Sopenharmony_ci
323195972f6Sopenharmony_ci  return ret;
324195972f6Sopenharmony_ci}
325195972f6Sopenharmony_ci
326195972f6Sopenharmony_cistatic snmp_err_t
327195972f6Sopenharmony_cisystem_set_value(const struct snmp_scalar_array_node_def *node, u16_t len, void *value)
328195972f6Sopenharmony_ci{
329195972f6Sopenharmony_ci  u8_t  *var_wr = NULL;
330195972f6Sopenharmony_ci  u16_t *var_wr_len;
331195972f6Sopenharmony_ci
332195972f6Sopenharmony_ci  switch (node->oid) {
333195972f6Sopenharmony_ci    case 4: /* sysContact */
334195972f6Sopenharmony_ci      var_wr     = syscontact_wr;
335195972f6Sopenharmony_ci      var_wr_len = syscontact_wr_len;
336195972f6Sopenharmony_ci      break;
337195972f6Sopenharmony_ci    case 5: /* sysName */
338195972f6Sopenharmony_ci      var_wr     = sysname_wr;
339195972f6Sopenharmony_ci      var_wr_len = sysname_wr_len;
340195972f6Sopenharmony_ci      break;
341195972f6Sopenharmony_ci    case 6: /* sysLocation */
342195972f6Sopenharmony_ci      var_wr     = syslocation_wr;
343195972f6Sopenharmony_ci      var_wr_len = syslocation_wr_len;
344195972f6Sopenharmony_ci      break;
345195972f6Sopenharmony_ci    default:
346195972f6Sopenharmony_ci      LWIP_DEBUGF(SNMP_MIB_DEBUG, ("system_set_value(): unknown id: %"S32_F"\n", node->oid));
347195972f6Sopenharmony_ci      return SNMP_ERR_GENERROR;
348195972f6Sopenharmony_ci  }
349195972f6Sopenharmony_ci
350195972f6Sopenharmony_ci  /* no need to check size of target buffer, this was already done in set_test method */
351195972f6Sopenharmony_ci  LWIP_ASSERT("", var_wr != NULL);
352195972f6Sopenharmony_ci  MEMCPY(var_wr, value, len);
353195972f6Sopenharmony_ci
354195972f6Sopenharmony_ci  if (var_wr_len == NULL) {
355195972f6Sopenharmony_ci    /* add terminating 0 */
356195972f6Sopenharmony_ci    var_wr[len] = 0;
357195972f6Sopenharmony_ci  } else {
358195972f6Sopenharmony_ci    *var_wr_len = len;
359195972f6Sopenharmony_ci  }
360195972f6Sopenharmony_ci
361195972f6Sopenharmony_ci  return SNMP_ERR_NOERROR;
362195972f6Sopenharmony_ci}
363195972f6Sopenharmony_ci
364195972f6Sopenharmony_cistatic const struct snmp_scalar_array_node_def system_nodes[] = {
365195972f6Sopenharmony_ci  {1, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_ONLY},  /* sysDescr */
366195972f6Sopenharmony_ci  {2, SNMP_ASN1_TYPE_OBJECT_ID,    SNMP_NODE_INSTANCE_READ_ONLY},  /* sysObjectID */
367195972f6Sopenharmony_ci  {3, SNMP_ASN1_TYPE_TIMETICKS,    SNMP_NODE_INSTANCE_READ_ONLY},  /* sysUpTime */
368195972f6Sopenharmony_ci  {4, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_WRITE}, /* sysContact */
369195972f6Sopenharmony_ci  {5, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_WRITE}, /* sysName */
370195972f6Sopenharmony_ci  {6, SNMP_ASN1_TYPE_OCTET_STRING, SNMP_NODE_INSTANCE_READ_WRITE}, /* sysLocation */
371195972f6Sopenharmony_ci  {7, SNMP_ASN1_TYPE_INTEGER,      SNMP_NODE_INSTANCE_READ_ONLY}   /* sysServices */
372195972f6Sopenharmony_ci};
373195972f6Sopenharmony_ci
374195972f6Sopenharmony_ciconst struct snmp_scalar_array_node snmp_mib2_system_node = SNMP_SCALAR_CREATE_ARRAY_NODE(1, system_nodes, system_get_value, system_set_test, system_set_value);
375195972f6Sopenharmony_ci
376195972f6Sopenharmony_ci#endif /* LWIP_SNMP && SNMP_LWIP_MIB2 */
377