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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [snmp/] [agent/] [current/] [src/] [mibgroup/] [snmpv3/] [snmpEngine.c] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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