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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [snmp/] [lib/] [current/] [include/] [asn1.h] - Blame information for rev 844

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      ./lib/current/include/asn1.h
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):    hmt
56
// Contributors: hmt
57
// Date:         2000-05-30
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
#ifndef ASN1_H
92
#define ASN1_H
93
 
94
#ifdef __cplusplus
95
extern "C" {
96
#endif
97
 
98
#define PARSE_PACKET    0
99
#define DUMP_PACKET     1
100
 
101
/*
102
 * Definitions for Abstract Syntax Notation One, ASN.1
103
 * As defined in ISO/IS 8824 and ISO/IS 8825
104
 *
105
 *
106
 */
107
/***********************************************************
108
        Copyright 1988, 1989 by Carnegie Mellon University
109
 
110
                      All Rights Reserved
111
 
112
Permission to use, copy, modify, and distribute this software and its
113
documentation for any purpose and without fee is hereby granted,
114
provided that the above copyright notice appear in all copies and that
115
both that copyright notice and this permission notice appear in
116
supporting documentation, and that the name of CMU not be
117
used in advertising or publicity pertaining to distribution of the
118
software without specific, written prior permission.
119
 
120
CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
121
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
122
CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
123
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
124
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
125
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
126
SOFTWARE.
127
******************************************************************/
128
 
129
#ifndef EIGHTBIT_SUBIDS
130
typedef u_long  oid;
131
#define MAX_SUBID   0xFFFFFFFF
132
#else
133
typedef u_char  oid;
134
#define MAX_SUBID   0xFF
135
#endif
136
 
137
#define MIN_OID_LEN         2
138
#define MAX_OID_LEN         128 /* max subid's in an oid */
139
#ifndef MAX_NAME_LEN                      /* conflicts with some libraries */
140
#define MAX_NAME_LEN        MAX_OID_LEN   /* obsolete. use MAX_OID_LEN */
141
#endif
142
 
143
#define ASN_BOOLEAN         ((u_char)0x01)
144
#define ASN_INTEGER         ((u_char)0x02)
145
#define ASN_BIT_STR         ((u_char)0x03)
146
#define ASN_OCTET_STR       ((u_char)0x04)
147
#define ASN_NULL            ((u_char)0x05)
148
#define ASN_OBJECT_ID       ((u_char)0x06)
149
#define ASN_SEQUENCE        ((u_char)0x10)
150
#define ASN_SET             ((u_char)0x11)
151
 
152
#define ASN_UNIVERSAL       ((u_char)0x00)
153
#define ASN_APPLICATION     ((u_char)0x40)
154
#define ASN_CONTEXT         ((u_char)0x80)
155
#define ASN_PRIVATE         ((u_char)0xC0)
156
 
157
#define ASN_PRIMITIVE       ((u_char)0x00)
158
#define ASN_CONSTRUCTOR     ((u_char)0x20)
159
 
160
#define ASN_LONG_LEN        (0x80)
161
#define ASN_EXTENSION_ID    (0x1F)
162
#define ASN_BIT8            (0x80)
163
 
164
#define IS_CONSTRUCTOR(byte)    ((byte) & ASN_CONSTRUCTOR)
165
#define IS_EXTENSION_ID(byte)   (((byte) & ASN_EXTENSION_ID) == ASN_EXTENSION_ID)
166
 
167
struct counter64 {
168
    u_long high;
169
    u_long low;
170
};
171
 
172
#ifdef OPAQUE_SPECIAL_TYPES
173
typedef struct counter64 integer64;
174
typedef struct counter64 unsigned64;
175
 
176
/* The BER inside an OPAQUE is an context specific with a value of 48 (0x30)
177
   plus the "normal" tag. For a Counter64, the tag is 0x46 (i.e., an
178
   applications specific tag with value 6). So the value for a 64 bit
179
   counter is 0x46 + 0x30, or 0x76 (118 base 10). However, values
180
   greater than 30 can not be encoded in one octet. So the first octet
181
   has the class, in this case context specific (ASN_CONTEXT), and
182
   the special value (i.e., 31) to indicate that the real value follows
183
   in one or more octets. The high order bit of each following octet
184
   indicates if the value is encoded in additional octets. A high order
185
   bit of zero, indicates the last. For this "hack", only one octet
186
   will be used for the value. */
187
 
188
  /* first octet of the tag */
189
#define ASN_OPAQUE_TAG1 (ASN_CONTEXT | ASN_EXTENSION_ID)
190
/* base value for the second octet of the tag - the
191
   second octet was the value for the tag */
192
#define ASN_OPAQUE_TAG2 ((u_char)0x30) 
193
 
194
#define ASN_OPAQUE_TAG2U ((u_char)0x2f) /* second octet of tag for union */
195
 
196
/* All the ASN.1 types for SNMP "should have been" defined in this file,
197
   but they were not. (They are defined in snmp_impl.h)  Thus, the tag for
198
   Opaque and Counter64 is defined, again, here with a different names. */
199
#define ASN_APP_OPAQUE (ASN_APPLICATION | 4)
200
#define ASN_APP_COUNTER64 (ASN_APPLICATION | 6)
201
#define ASN_APP_FLOAT (ASN_APPLICATION | 8)
202
#define ASN_APP_DOUBLE (ASN_APPLICATION | 9)
203
#define ASN_APP_I64 (ASN_APPLICATION | 10)
204
#define ASN_APP_U64 (ASN_APPLICATION | 11)
205
#define ASN_APP_UNION (ASN_PRIVATE | 1)         /* or ASN_PRIV_UNION ? */
206
 
207
/* value for Counter64 */
208
#define ASN_OPAQUE_COUNTER64 (ASN_OPAQUE_TAG2 + ASN_APP_COUNTER64)
209
/* max size of BER encoding of Counter64 */
210
#define ASN_OPAQUE_COUNTER64_MX_BER_LEN 12  
211
 
212
/* value for Float */
213
#define ASN_OPAQUE_FLOAT (ASN_OPAQUE_TAG2 + ASN_APP_FLOAT)
214
/* size of BER encoding of Float */
215
#define ASN_OPAQUE_FLOAT_BER_LEN 7    
216
 
217
/* value for Double */
218
#define ASN_OPAQUE_DOUBLE (ASN_OPAQUE_TAG2 + ASN_APP_DOUBLE)
219
/* size of BER encoding of Double */
220
#define ASN_OPAQUE_DOUBLE_BER_LEN 11  
221
 
222
/* value for Integer64 */
223
#define ASN_OPAQUE_I64 (ASN_OPAQUE_TAG2 + ASN_APP_I64)
224
/* max size of BER encoding of Integer64 */
225
#define ASN_OPAQUE_I64_MX_BER_LEN 11
226
 
227
/* value for Unsigned64 */
228
#define ASN_OPAQUE_U64 (ASN_OPAQUE_TAG2 + ASN_APP_U64) 
229
/* max size of BER encoding of Unsigned64 */
230
#define ASN_OPAQUE_U64_MX_BER_LEN 12
231
 
232
#endif /* OPAQUE_SPECIAL_TYPES */
233
 
234
 
235
#define ASN_PRIV_INCL_RANGE (ASN_PRIVATE | 2)
236
#define ASN_PRIV_EXCL_RANGE (ASN_PRIVATE | 3)
237
#define ASN_PRIV_DELEGATED  (ASN_PRIVATE | 4)
238
#define IS_DELEGATED(x)   ((x) == ASN_PRIV_DELEGATED)
239
 
240
 
241
int      asn_check_packet (u_char *, size_t);
242
u_char  *asn_parse_int (u_char *, size_t *, u_char *, long *, size_t);
243
u_char  *asn_build_int (u_char *, size_t *, u_char, long *, size_t);
244
u_char  *asn_parse_unsigned_int (u_char *, size_t *, u_char *, u_long *, size_t);
245
u_char  *asn_build_unsigned_int (u_char *, size_t *, u_char, u_long *, size_t);
246
u_char  *asn_parse_string (u_char *, size_t *, u_char *, u_char *, size_t *);
247
u_char  *asn_build_string (u_char *, size_t *, u_char, const u_char *, size_t);
248
u_char  *asn_parse_header (u_char *, size_t *, u_char *);
249
u_char  *asn_parse_sequence(u_char *, size_t *, u_char *,
250
                 u_char expected_type,  /* must be this type */
251
                 const char *estr);     /* error message prefix */
252
u_char  *asn_build_header (u_char *, size_t *, u_char, size_t);
253
u_char  *asn_build_sequence (u_char *, size_t *, u_char, size_t);
254
u_char  *asn_parse_length (u_char *, u_long *);
255
u_char  *asn_build_length (u_char *, size_t *, size_t);
256
u_char  *asn_parse_objid (u_char *, size_t *, u_char *, oid *, size_t *);
257
u_char  *asn_build_objid (u_char *, size_t *, u_char, oid *, size_t);
258
u_char  *asn_parse_null (u_char *, size_t *, u_char *);
259
u_char  *asn_build_null (u_char *, size_t *, u_char);
260
u_char  *asn_parse_bitstring (u_char *, size_t *, u_char *, u_char *, size_t *);
261
u_char  *asn_build_bitstring (u_char *, size_t *, u_char, u_char *, size_t);
262
u_char  *asn_parse_unsigned_int64 (u_char *, size_t *, u_char *,
263
                                       struct counter64 *, size_t);
264
u_char  *asn_build_unsigned_int64 (u_char *, size_t *, u_char,
265
                                       struct counter64 *, size_t);
266
u_char  *asn_parse_signed_int64 (u_char *, size_t *, u_char *,
267
                                       struct counter64 *, size_t);
268
u_char  *asn_build_signed_int64 (u_char *, size_t *, u_char,
269
                                       struct counter64 *, size_t);
270
u_char  *asn_build_float (u_char *, size_t *, u_char, float *,
271
                              size_t);
272
u_char  *asn_parse_float (u_char *, size_t *, u_char *, float *, size_t);
273
u_char  *asn_build_double (u_char *, size_t *, u_char, double *,
274
                               size_t);
275
u_char  *asn_parse_double (u_char *, size_t *, u_char *, double *, size_t);
276
 
277
#ifdef __cplusplus
278
}
279
#endif
280
#endif /* ASN1_H */

powered by: WebSVN 2.1.0

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