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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [snmp/] [lib/] [v2_0/] [include/] [asn1.h] - Blame information for rev 773

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

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

powered by: WebSVN 2.1.0

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