OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [snmp/] [agent/] [v2_0/] [src/] [mibgroup/] [snmpv3/] [snmpEngine.c] - Blame information for rev 27

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
//==========================================================================
2
//
3
//      ./agent/current/src/mibgroup/snmpv3/snmpEngine.c
4
//
5
//
6
//==========================================================================
7
//####ECOSGPLCOPYRIGHTBEGIN####
8
// -------------------------------------------
9
// This file is part of eCos, the Embedded Configurable Operating System.
10
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
11
//
12
// eCos is free software; you can redistribute it and/or modify it under
13
// the terms of the GNU General Public License as published by the Free
14
// Software Foundation; either version 2 or (at your option) any later version.
15
//
16
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
17
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19
// for more details.
20
//
21
// You should have received a copy of the GNU General Public License along
22
// with eCos; if not, write to the Free Software Foundation, Inc.,
23
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
24
//
25
// As a special exception, if other files instantiate templates or use macros
26
// or inline functions from this file, or you compile this file and link it
27
// with other works to produce a work based on this file, this file does not
28
// by itself cause the resulting work to be covered by the GNU General Public
29
// License. However the source code for this file must still be made available
30
// in accordance with section (3) of the GNU General Public License.
31
//
32
// This exception does not invalidate any other reasons why a work based on
33
// this file might be covered by the GNU General Public License.
34
//
35
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
36
// at http://sources.redhat.com/ecos/ecos-license/
37
// -------------------------------------------
38
//####ECOSGPLCOPYRIGHTEND####
39
//####UCDSNMPCOPYRIGHTBEGIN####
40
//
41
// -------------------------------------------
42
//
43
// Portions of this software may have been derived from the UCD-SNMP
44
// project,  <http://ucd-snmp.ucdavis.edu/>  from the University of
45
// California at Davis, which was originally based on the Carnegie Mellon
46
// University SNMP implementation.  Portions of this software are therefore
47
// covered by the appropriate copyright disclaimers included herein.
48
//
49
// The release used was version 4.1.2 of May 2000.  "ucd-snmp-4.1.2"
50
// -------------------------------------------
51
//
52
//####UCDSNMPCOPYRIGHTEND####
53
//==========================================================================
54
//#####DESCRIPTIONBEGIN####
55
//
56
// Author(s):    Andrew.Lunn@ascom.ch, Manu.Sharma@ascom.ch
57
// Contributors: hmt
58
// Date:         2001-05-29
59
// Purpose:      Port of UCD-SNMP distribution to eCos.
60
// Description:  
61
//              
62
//
63
//####DESCRIPTIONEND####
64
//
65
//==========================================================================
66
/********************************************************************
67
       Copyright 1989, 1991, 1992 by Carnegie Mellon University
68
 
69
                          Derivative Work -
70
Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
71
 
72
                         All Rights Reserved
73
 
74
Permission to use, copy, modify and distribute this software and its
75
documentation for any purpose and without fee is hereby granted,
76
provided that the above copyright notice appears in all copies and
77
that both that copyright notice and this permission notice appear in
78
supporting documentation, and that the name of CMU and The Regents of
79
the University of California not be used in advertising or publicity
80
pertaining to distribution of the software without specific written
81
permission.
82
 
83
CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL
84
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
85
WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL CMU OR
86
THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL,
87
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
88
FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
89
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
90
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
91
*********************************************************************/
92
/* snmpEngine.c: implements the SNMP-FRAMEWORK-MIB. */
93
 
94
#include <config.h>
95
 
96
#ifdef CYGPKG_SNMPAGENT_V3_SUPPORT
97
#if HAVE_WINSOCK_H
98
#include <winsock.h>
99
#endif
100
 
101
#include "mibincl.h"
102
#include "snmpv3.h"
103
//#include "util_funcs.h"
104
#include "lcd_time.h"
105
#include "mibgroup/mibII/sysORTable.h"
106
#include "snmpEngine.h"
107
 
108
struct variable2 snmpEngine_variables[] = {
109
  { SNMPENGINEID        , ASN_OCTET_STR  , RONLY , var_snmpEngine, 1, { 1 } },
110
#ifdef SNMP_TESTING_CODE 
111
  { SNMPENGINEBOOTS     , ASN_INTEGER    , RWRITE, var_snmpEngine, 1, { 2 } },
112
  { SNMPENGINETIME      , ASN_INTEGER    , RWRITE, var_snmpEngine, 1, { 3 } },
113
#else /* !SNMP_TESTING_CODE */ 
114
  { SNMPENGINEBOOTS     , ASN_INTEGER    , RONLY , var_snmpEngine, 1, { 2 } },
115
  { SNMPENGINETIME      , ASN_INTEGER    , RONLY , var_snmpEngine, 1, { 3 } },
116
#endif /* SNMP_TESTING_CODE */
117
  { SNMPENGINEMAXMESSAGESIZE, ASN_INTEGER, RONLY , var_snmpEngine, 1, { 4 } },
118
};
119
 
120
/* now load this mib into the agents mib table */
121
oid snmpEngine_variables_oid[] = {1,3,6,1,6,3,10,2,1};
122
 
123
void init_snmpEngine (void) {
124
#ifdef USING_MIBII_SYSORTABLE_MODULE
125
  static oid reg[] = {1,3,6,1,6,3,10,3,1,1};
126
  register_sysORTable(reg,10,"The SNMP Management Architecture MIB.");
127
#endif
128
 
129
  REGISTER_MIB("snmpv3/snmpEngine", snmpEngine_variables, variable2,
130
                 snmpEngine_variables_oid);
131
 
132
/* place any initialization routines needed here */
133
}
134
 
135
extern struct timeval starttime;
136
 
137
#ifdef SNMP_TESTING_CODE
138
int write_engineBoots(int, u_char *,u_char, size_t, u_char *,oid*, size_t);
139
int write_engineTime(int, u_char *,u_char, size_t, u_char *,oid*, size_t);
140
#endif /* SNMP_TESTING_CODE */
141
 
142
u_char *
143
var_snmpEngine(
144
    struct variable *vp,
145
    oid     *name,
146
    size_t  *length,
147
    int     exact,
148
    size_t  *var_len,
149
    WriteMethod **write_method)
150
{
151
 
152
  /* variables we may use later */
153
  static long long_ret;
154
  static unsigned char engineID[SNMP_MAXBUF];
155
 
156
  *write_method = 0;           /* assume it isnt writable for the time being */
157
  *var_len = sizeof(long_ret); /* assume an integer and change later if not */
158
 
159
  if (header_generic(vp,name,length,exact,var_len,write_method))
160
      return 0;
161
 
162
  /* this is where we do the value assignments for the mib results. */
163
  switch(vp->magic) {
164
 
165
    case SNMPENGINEID:
166
      *var_len = snmpv3_get_engineID(engineID, SNMP_MAXBUF);
167
      /* XXX  Set ERROR_MSG() upon error? */
168
      return (unsigned char *) engineID;
169
 
170
    case SNMPENGINEBOOTS:
171
#ifdef SNMP_TESTING_CODE
172
      *write_method = write_engineBoots;
173
#endif /* SNMP_TESTING_CODE */
174
      long_ret = snmpv3_local_snmpEngineBoots();
175
      return (unsigned char *) &long_ret;
176
 
177
    case SNMPENGINETIME:
178
#ifdef SNMP_TESTING_CODE
179
      *write_method = write_engineTime;
180
#endif /* SNMP_TESTING_CODE */
181
      long_ret = snmpv3_local_snmpEngineTime();
182
      return (unsigned char *) &long_ret;
183
 
184
    case SNMPENGINEMAXMESSAGESIZE:
185
      long_ret = 1500;
186
      return (unsigned char *) &long_ret;
187
 
188
    default:
189
      DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_snmpEngine\n", vp->magic));
190
  }
191
  return 0;
192
}
193
 
194
#ifdef SNMP_TESTING_CODE
195
/* write_engineBoots():
196
 
197
   This is technically not writable a writable mib object, but we
198
   allow it so we can run some time synchronization tests.
199
*/
200
int
201
write_engineBoots(
202
   int      action,
203
   u_char   *var_val,
204
   u_char   var_val_type,
205
   size_t   var_val_len,
206
   u_char   *statP,
207
   oid      *name,
208
   size_t   name_len)
209
{
210
  /* variables we may use later */
211
  static long long_ret;
212
  size_t size;
213
  int bigsize=SNMP_MAXBUF_MEDIUM;
214
  u_char engineIDBuf[SNMP_MAXBUF_MEDIUM];
215
  int engineIDBufLen = 0;
216
 
217
  if (var_val_type != ASN_INTEGER){
218
      DEBUGMSGTL(("snmpEngine","write to engineBoots not ASN_INTEGER\n"));
219
      return SNMP_ERR_WRONGTYPE;
220
  }
221
  if (var_val_len > sizeof(long_ret)){
222
      DEBUGMSGTL(("snmpEngine","write to engineBoots: bad length\n"));
223
      return SNMP_ERR_WRONGLENGTH;
224
  }
225
  long_ret = *((long *) var_val);
226
  if (action == COMMIT) {
227
    engineIDBufLen = snmpv3_get_engineID(engineIDBuf, SNMP_MAXBUF_MEDIUM);
228
    /* set our local engineTime in the LCD timing cache */
229
    snmpv3_set_engineBootsAndTime(long_ret, snmpv3_local_snmpEngineTime());
230
    set_enginetime(engineIDBuf, engineIDBufLen,
231
                   snmpv3_local_snmpEngineBoots(),
232
                   snmpv3_local_snmpEngineTime(),
233
                   TRUE);
234
  }
235
  return SNMP_ERR_NOERROR;
236
}
237
 
238
/* write_engineTime():
239
 
240
   This is technically not writable a writable mib object, but we
241
   allow it so we can run some time synchronization tests.
242
*/
243
int
244
write_engineTime(
245
   int      action,
246
   u_char   *var_val,
247
   u_char   var_val_type,
248
   size_t   var_val_len,
249
   u_char   *statP,
250
   oid      *name,
251
   size_t   name_len)
252
{
253
  /* variables we may use later */
254
  static long long_ret;
255
  size_t size;
256
  int bigsize=SNMP_MAXBUF_MEDIUM;
257
  u_char engineIDBuf[SNMP_MAXBUF_MEDIUM];
258
  int engineIDBufLen = 0;
259
 
260
  if (var_val_type != ASN_INTEGER){
261
      DEBUGMSGTL(("snmpEngine","write to engineTime not ASN_INTEGER\n"));
262
      return SNMP_ERR_WRONGTYPE;
263
  }
264
  if (var_val_len > sizeof(long_ret)){
265
      DEBUGMSGTL(("snmpEngine","write to engineTime: bad length\n"));
266
      return SNMP_ERR_WRONGLENGTH;
267
  }
268
  long_ret = *((long *) var_val);
269
  if (action == COMMIT) {
270
    engineIDBufLen = snmpv3_get_engineID(engineIDBuf, SNMP_MAXBUF_MEDIUM);
271
    /* set our local engineTime in the LCD timing cache */
272
    snmpv3_set_engineBootsAndTime(snmpv3_local_snmpEngineBoots(), long_ret);
273
    set_enginetime(engineIDBuf, engineIDBufLen,
274
                   snmpv3_local_snmpEngineBoots(),
275
                   snmpv3_local_snmpEngineTime(),
276
                   TRUE);
277
  }
278
  return SNMP_ERR_NOERROR;
279
}
280
 
281
#endif /* CYGPKG_SNMPAGENT_V3_SUPPORT */
282
#endif /* SNMP_TESTING_CODE */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.