Nut/OS  4.10.3
API Reference
asn1.h File Reference

Definitions for Abstract Syntax Notation One, ASN.1. More...

#include <sys/types.h>
#include <stdint.h>
Include dependency graph for asn1.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  UNSIGNED64

Defines

#define MAX_OID_LEN   32
#define MAX_SUBID   0xFFFFFFFF
#define MIN_OID_LEN   2
#define ASN_BOOLEAN   0x01
#define ASN_INTEGER   0x02
#define ASN_BIT_STR   0x03
#define ASN_OCTET_STR   0x04
#define ASN_NULL   0x05
#define ASN_OBJECT_ID   0x06
#define ASN_SEQUENCE   0x10
#define ASN_SET   0x11
#define ASN_UNIVERSAL   0x00
#define ASN_APPLICATION   0x40
#define ASN_CONTEXT   0x80
#define ASN_PRIVATE   0xC0
#define ASN_PRIMITIVE   0x00
#define ASN_CONSTRUCTOR   0x20
#define ASN_LONG_LEN   0x80
#define ASN_EXTENSION_ID   0x1F
#define ASN_IPADDRESS   (ASN_APPLICATION | 0)
#define ASN_COUNTER   (ASN_APPLICATION | 1)
#define ASN_GAUGE   (ASN_APPLICATION | 2)
#define ASN_UNSIGNED   (ASN_APPLICATION | 2)
#define ASN_TIMETICKS   (ASN_APPLICATION | 3)
#define ASN_OPAQUE   (ASN_APPLICATION | 4)
#define ASN_NSAP   (ASN_APPLICATION | 5)
#define ASN_COUNTER64   (ASN_APPLICATION | 6)
#define ASN_UINTEGER   (ASN_APPLICATION | 7)
#define ACL_RONLY   0xAAAA
#define ACL_RWRITE   0xAABA
#define ACL_NOACCESS   0x0000
#define ASN_BIT8   0x80

Typedefs

typedef uint32_t OID

Functions

CONST uint8_tAsnHeaderParse (CONST uint8_t *, size_t *, uint8_t *)
 Interpret the ID and length of the next object.
uint8_tAsnHeaderBuild (uint8_t *, size_t *, uint8_t, size_t)
 Build an ASN header for an object with a given ID and length.
CONST uint8_tAsnSequenceParse (CONST uint8_t *, size_t *, uint8_t)
 Check the type and get the length of the next object.
uint8_tAsnSequenceBuild (uint8_t *, size_t *, uint8_t, size_t)
 Build an ASN header for a sequence with a given type and length.
CONST uint8_tAsnIntegerParse (CONST uint8_t *, size_t *, uint8_t *, long *)
 Pull a long out of an ASN integer type.
uint8_tAsnIntegerBuild (uint8_t *, size_t *, uint8_t, long *)
 Build an ASN object containing an integer.
CONST uint8_tAsnUnsignedParse (CONST uint8_t *, size_t *, uint8_t *, uint32_t *)
 Pull an unsigned long out of an ASN integer type.
uint8_tAsnUnsignedBuild (uint8_t *, size_t *, uint8_t, uint32_t *)
 Build an ASN object containing an unsigned integer.
CONST uint8_tAsnOctetStringParse (CONST uint8_t *, size_t *, uint8_t *, uint8_t *, size_t *)
 Pulls a string out of an ASN octet string type.
uint8_tAsnOctetStringBuild (uint8_t *, size_t *, uint8_t, CONST uint8_t *, size_t)
 Build an ASN object containing an octet string.
CONST uint8_tAsnOidParse (CONST uint8_t *, size_t *, uint8_t *, OID *, size_t *)
 Pulls an object identifier out of an ASN object ID type.
uint8_tAsnOidBuild (uint8_t *, size_t *, uint8_t, CONST OID *, size_t)
 Build an ASN object identifier.
CONST uint8_tAsnNullParse (CONST uint8_t *, size_t *, uint8_t *)
 Parse an ASN null type.
uint8_tAsnNullBuild (uint8_t *, size_t *, uint8_t)
 Build an ASN null object.
CONST uint8_tAsnBitStringParse (CONST uint8_t *, size_t *, uint8_t *, uint8_t *, size_t *)
 Pull a bitstring out of an ASN bitstring type.
uint8_tAsnBitStringBuild (uint8_t *, size_t *, uint8_t, CONST uint8_t *, size_t)
 Build an ASN bit string.
CONST uint8_tAsnUnsigned64Parse (CONST uint8_t *, size_t *, uint8_t *, UNSIGNED64 *)
 Pull a 64 bit unsigned long out of an ASN integer type.
uint8_tAsnUnsigned64Build (uint8_t *, size_t *, uint8_t, CONST UNSIGNED64 *)
 Build an ASN object containing a 64 bit unsigned integer.

Detailed Description

Definitions for Abstract Syntax Notation One, ASN.1.

 * $Id: asn1.h 2235 2008-08-11 07:00:36Z haraldkipp $
 * 

Definition in file asn1.h.


Define Documentation

#define MAX_OID_LEN   32

Definition at line 50 of file asn1.h.

Referenced by AsnOidBuild().

#define MAX_SUBID   0xFFFFFFFF

Definition at line 53 of file asn1.h.

#define MIN_OID_LEN   2

Definition at line 55 of file asn1.h.

#define ASN_BOOLEAN   0x01

Definition at line 57 of file asn1.h.

#define ASN_INTEGER   0x02

Definition at line 58 of file asn1.h.

Referenced by SnmpAgentProcessRequest(), SnmpAuthBuild(), SnmpPduAddVariable(), and SnmpVarBuild().

#define ASN_BIT_STR   0x03

Definition at line 59 of file asn1.h.

Referenced by SnmpVarBuild().

#define ASN_OCTET_STR   0x04

Definition at line 60 of file asn1.h.

Referenced by SnmpAuthBuild(), and SnmpVarBuild().

#define ASN_NULL   0x05

Definition at line 61 of file asn1.h.

Referenced by SnmpVarBuild().

#define ASN_OBJECT_ID   0x06

Definition at line 62 of file asn1.h.

Referenced by SnmpVarBuild(), and SnmpVarParse().

#define ASN_SEQUENCE   0x10

Definition at line 63 of file asn1.h.

Referenced by SnmpAuthBuild(), SnmpAuthParse(), SnmpVarBuild(), and SnmpVarParse().

#define ASN_SET   0x11

Definition at line 64 of file asn1.h.

#define ASN_UNIVERSAL   0x00

Definition at line 66 of file asn1.h.

Referenced by SnmpAgentProcessRequest(), SnmpAuthBuild(), SnmpVarBuild(), and SnmpVarParse().

#define ASN_APPLICATION   0x40

Definition at line 67 of file asn1.h.

#define ASN_CONTEXT   0x80

Definition at line 68 of file asn1.h.

#define ASN_PRIVATE   0xC0

Definition at line 69 of file asn1.h.

#define ASN_PRIMITIVE   0x00

Definition at line 71 of file asn1.h.

Referenced by SnmpAgentProcessRequest(), SnmpAuthBuild(), SnmpVarBuild(), and SnmpVarParse().

#define ASN_CONSTRUCTOR   0x20

Definition at line 72 of file asn1.h.

Referenced by SnmpAuthBuild(), SnmpAuthParse(), SnmpVarBuild(), and SnmpVarParse().

#define ASN_LONG_LEN   0x80

Definition at line 74 of file asn1.h.

#define ASN_EXTENSION_ID   0x1F

Definition at line 75 of file asn1.h.

Referenced by AsnHeaderParse().

#define ASN_IPADDRESS   (ASN_APPLICATION | 0)

Definition at line 78 of file asn1.h.

Referenced by SnmpVarBuild().

#define ASN_COUNTER   (ASN_APPLICATION | 1)

Definition at line 79 of file asn1.h.

Referenced by SnmpPduAddVariable(), and SnmpVarBuild().

#define ASN_GAUGE   (ASN_APPLICATION | 2)

Definition at line 80 of file asn1.h.

Referenced by SnmpPduAddVariable(), and SnmpVarBuild().

#define ASN_UNSIGNED   (ASN_APPLICATION | 2)

Definition at line 81 of file asn1.h.

#define ASN_TIMETICKS   (ASN_APPLICATION | 3)

Definition at line 82 of file asn1.h.

Referenced by SnmpPduAddVariable(), and SnmpVarBuild().

#define ASN_OPAQUE   (ASN_APPLICATION | 4)

Definition at line 83 of file asn1.h.

Referenced by SnmpVarBuild().

#define ASN_NSAP   (ASN_APPLICATION | 5)

Definition at line 86 of file asn1.h.

Referenced by SnmpVarBuild().

#define ASN_COUNTER64   (ASN_APPLICATION | 6)

Definition at line 87 of file asn1.h.

Referenced by SnmpVarBuild().

#define ASN_UINTEGER   (ASN_APPLICATION | 7)

Definition at line 88 of file asn1.h.

Referenced by SnmpPduAddVariable(), and SnmpVarBuild().

#define ACL_RONLY   0xAAAA

Definition at line 90 of file asn1.h.

#define ACL_RWRITE   0xAABA

Definition at line 91 of file asn1.h.

#define ACL_NOACCESS   0x0000

Definition at line 92 of file asn1.h.

#define ASN_BIT8   0x80

Definition at line 94 of file asn1.h.

Referenced by AsnOidParse().


Typedef Documentation

typedef uint32_t OID

Definition at line 96 of file asn1.h.


Function Documentation

CONST uint8_t* AsnHeaderParse ( CONST uint8_t data,
size_t *  datalength,
uint8_t type 
)

Interpret the ID and length of the next object.

Parameters:
dataPointer to start of the object.
datalengthContains the number of valid bytes following the start of the object. On exit, it is returned as the number of valid bytes following the ID and length.
typePointer to the variable that receives the ASN type of the object.
Returns:
A pointer to the first byte following ID and length (aka the start of the data field). Returns NULL on any error.

Definition at line 136 of file asn1.c.

References ASN_EXTENSION_ID, and CONST.

Referenced by AsnSequenceParse(), SnmpAgentProcessRequest(), and SnmpVarParse().

uint8_t* AsnHeaderBuild ( uint8_t data,
size_t *  datalength,
uint8_t  type,
size_t  length 
)

Build an ASN header for an object with a given ID and length.

This only works on data types < 30, i.e. no extension octets. The maximum length is 0xFFFF;

Parameters:
dataPointer to start of object.
datalengthContains the number of available bytes following the start of the object. On exit, it is returned as the number of available bytes following the encoded ID and length of this object.
typeASN type of the object.
lengthLength of object.
Returns:
Returns a pointer to the first byte of the contents of this object. Returns NULL on any error.

Definition at line 189 of file asn1.c.

Referenced by AsnBitStringBuild(), AsnIntegerBuild(), AsnNullBuild(), AsnOctetStringBuild(), AsnOidBuild(), AsnUnsigned64Build(), and AsnUnsignedBuild().

CONST uint8_t* AsnSequenceParse ( CONST uint8_t data,
size_t *  datalength,
uint8_t  type 
)

Check the type and get the length of the next object.

Similare to AsnHeaderParse, but tests for expected type.

Parameters:
dataPointer to start of the object.
datalengthContains the number of valid bytes following the start of the object. On exit, it is returned as the number of valid bytes following the ID and length.
typeThe expected ASN type of the object.
Returns:
A pointer to the first byte following ID and length (aka the start of the data field). Returns NULL on any error.

Definition at line 215 of file asn1.c.

References AsnHeaderParse().

Referenced by SnmpAuthParse(), and SnmpVarParse().

Here is the call graph for this function:

uint8_t* AsnSequenceBuild ( uint8_t data,
size_t *  datalength,
uint8_t  type,
size_t  length 
)

Build an ASN header for a sequence with a given type and length.

This only works on data types < 30, i.e. no extension octets. The maximum length is 0xFFFF;

Parameters:
dataPointer to start of object.
datalengthContains the number of available bytes following the start of the object. On exit, it is returned as the number of available bytes following the encoded ID and length of this object.
typeASN type of the object.
lengthLength of object.
Returns:
Returns a pointer to the first byte of the contents of this object. Returns NULL on any error.

Definition at line 244 of file asn1.c.

Referenced by SnmpAgentProcessRequest(), SnmpAuthBuild(), and SnmpVarBuild().

CONST uint8_t* AsnIntegerParse ( CONST uint8_t data,
size_t *  datalength,
uint8_t type,
long *  intp 
)

Pull a long out of an ASN integer type.

Parameters:
dataPointer to start of the object.
datalengthContains the number of valid bytes following the start of the object. On exit, it is returned as the number of valid bytes following the end of this object.
typePointer to the variable that receives the ASN type of the object.
intpPointer to the variable that receives the value of the object.
Returns:
Pointer to the first byte past the end of this object (i.e. the start of the next object). Returns NULL on any error.

Definition at line 277 of file asn1.c.

References CONST.

Referenced by SnmpAgentProcessRequest(), and SnmpAuthParse().

uint8_t* AsnIntegerBuild ( uint8_t data,
size_t *  datalength,
uint8_t  type,
long *  intp 
)

Build an ASN object containing an integer.

Parameters:
dataPointer to start of output buffer
datalengthContains the number of available bytes following the start of the object. On exit, it is returned as the number of available bytes following the end of this object.
typeASN type of the object.
intpValue of the object.
Returns:
A pointer to the first byte past the end of this object (i.e. the start of the next object). Returns NULL on any error.

Definition at line 323 of file asn1.c.

References AsnHeaderBuild().

Referenced by SnmpAgentProcessRequest(), SnmpAuthBuild(), and SnmpVarBuild().

Here is the call graph for this function:

CONST uint8_t* AsnUnsignedParse ( CONST uint8_t data,
size_t *  datalength,
uint8_t type,
uint32_t intp 
)

Pull an unsigned long out of an ASN integer type.

Parameters:
dataPointer to start of the object.
datalengthContains the number of valid bytes following the start of the object. On exit, it is returned as the number of valid bytes following the end of this object.
typePointer to the variable that receives the ASN type of the object.
intpPointer to the variable that receives the value of the object.
Returns:
Pointer to the first byte past the end of this object (i.e. the start of the next object). Returns NULL on any error.

Definition at line 375 of file asn1.c.

References CONST.

uint8_t* AsnUnsignedBuild ( uint8_t data,
size_t *  datalength,
uint8_t  type,
uint32_t intp 
)

Build an ASN object containing an unsigned integer.

Parameters:
dataPointer to start of output buffer
datalengthContains the number of available bytes following the start of the object. On exit, it is returned as the number of available bytes following the end of this object.
typeASN type of the object.
intpValue of the object.
Returns:
A pointer to the first byte past the end of this object (i.e. the start of the next object). Returns NULL on any error.

Definition at line 425 of file asn1.c.

References AsnHeaderBuild().

Referenced by SnmpVarBuild().

Here is the call graph for this function:

CONST uint8_t* AsnOctetStringParse ( CONST uint8_t data,
size_t *  datalength,
uint8_t type,
uint8_t string,
size_t *  strlength 
)

Pulls a string out of an ASN octet string type.

Parameters:
dataPointer to start of the object.
datalengthContains the number of valid bytes following the start of the object. On exit, it is returned as the number of valid bytes following the end of this object.
typePointer to the variable that receives the ASN type of the object.
stringPointer to the variable that receives the value of the object.
strlengthContains the size of the string buffer on entry. On exit, it is returned as the number of bytes stored in the string buffer.
Returns:
Pointer to the first byte past the end of this object (i.e. the start of the next object). Returns NULL on any error.

Definition at line 491 of file asn1.c.

References CONST, and memcpy().

Referenced by SnmpAuthParse().

Here is the call graph for this function:

uint8_t* AsnOctetStringBuild ( uint8_t data,
size_t *  datalength,
uint8_t  type,
CONST uint8_t string,
size_t  strlength 
)

Build an ASN object containing an octet string.

Parameters:
dataPointer to start of output buffer
datalengthContains the number of available bytes following the start of the object. On exit, it is returned as the number of available bytes following the end of this object.
typeASN type of the object.
stringPointer to the value. If NULL, the octet string will be filled with zeros.
strlengthNumber of bytes in the string value.
Returns:
A pointer to the first byte past the end of this object (i.e. the start of the next object). Returns NULL on any error.

Definition at line 533 of file asn1.c.

References AsnHeaderBuild(), memcpy(), and memset().

Referenced by SnmpAuthBuild(), and SnmpVarBuild().

Here is the call graph for this function:

CONST uint8_t* AsnOidParse ( CONST uint8_t data,
size_t *  datalength,
uint8_t type,
OID objid,
size_t *  objidlength 
)

Pulls an object identifier out of an ASN object ID type.

Parameters:
dataPointer to start of the object.
datalengthContains the number of valid bytes following the start of the object. On exit, it is returned as the number of valid bytes following the end of this object.
typePointer to the variable that receives the ASN type of the object.
objidPointer to the variable that receives the object identifier.
objidlengthPoints to a variable that contains the size of the output buffer on entry. On exit, it is returned as the number of sub IDs stored in the output buffer.
Returns:
Pointer to the first byte past the end of this object (i.e. the start of the next object). Returns NULL on any error.

Definition at line 574 of file asn1.c.

References ASN_BIT8, and CONST.

Referenced by SnmpVarParse().

uint8_t* AsnOidBuild ( uint8_t data,
size_t *  datalength,
uint8_t  type,
CONST OID objid,
size_t  objidlength 
)

Build an ASN object identifier.

Parameters:
dataPointer to start of the object.
datalengthContains the number of available bytes following the start of the object. On exit, it is returned as the number of available bytes following the end of this object.
typeASN type of the object.
objidPointer to the object identifier.
objidlengthNumber of sub IDs in the object identifier.
Returns:
Pointer to the first byte past the end of this object (i.e. the start of the next object). Returns NULL on any error.

Definition at line 650 of file asn1.c.

References AsnHeaderBuild(), CONST, free(), malloc(), and MAX_OID_LEN.

Referenced by SnmpVarBuild().

Here is the call graph for this function:

CONST uint8_t* AsnNullParse ( CONST uint8_t data,
size_t *  datalength,
uint8_t type 
)

Parse an ASN null type.

Parameters:
dataPointer to start of the object.
datalengthContains the number of valid bytes following the start of the object. On exit, it is returned as the number of valid bytes following the end of this object.
typePointer to the variable that receives the ASN type of the object.
Returns:
Pointer to the first byte past the end of this object (i.e. the start of the next object). Returns NULL on any error.

Definition at line 775 of file asn1.c.

References CONST.

uint8_t* AsnNullBuild ( uint8_t data,
size_t *  datalength,
uint8_t  type 
)

Build an ASN null object.

Parameters:
dataPointer to start of the object.
datalengthContains the number of available bytes following the start of the object. On exit, it is returned as the number of available bytes following the end of this object.
typeASN type of the object.
Returns:
Pointer to the first byte past the end of this object (i.e. the start of the next object). Returns NULL on any error.

Definition at line 806 of file asn1.c.

References AsnHeaderBuild().

Referenced by SnmpVarBuild().

Here is the call graph for this function:

CONST uint8_t* AsnBitStringParse ( CONST uint8_t data,
size_t *  datalength,
uint8_t type,
uint8_t string,
size_t *  strlength 
)

Pull a bitstring out of an ASN bitstring type.

Parameters:
dataPointer to start of the object.
datalengthContains the number of valid bytes following the start of the object. On exit, it is returned as the number of valid bytes following the end of this object.
typePointer to the variable that receives the ASN type of the object.
stringPointer to the variable that receives the value of the object.
strlengthContains the size of the string buffer on entry. On exit, it is returned as the number of bytes stored in the string buffer.
Returns:
Pointer to the first byte past the end of this object (i.e. the start of the next object). Returns NULL on any error.

Definition at line 831 of file asn1.c.

References CONST, and memcpy().

Here is the call graph for this function:

uint8_t* AsnBitStringBuild ( uint8_t data,
size_t *  datalength,
uint8_t  type,
CONST uint8_t string,
size_t  strlength 
)

Build an ASN bit string.

Parameters:
dataPointer to start of output buffer
datalengthContains the number of available bytes following the start of the object. On exit, it is returned as the number of available bytes following the end of this object.
typeASN type of the object.
stringPointer to the value. If NULL, the octet string will be filled with zeros.
strlengthNumber of bytes in the string value.
Returns:
A pointer to the first byte past the end of this object (i.e. the start of the next object). Returns NULL on any error.

Definition at line 873 of file asn1.c.

References AsnHeaderBuild(), and memcpy().

Referenced by SnmpVarBuild().

Here is the call graph for this function:

CONST uint8_t* AsnUnsigned64Parse ( CONST uint8_t data,
size_t *  datalength,
uint8_t type,
UNSIGNED64 cp 
)

Pull a 64 bit unsigned long out of an ASN integer type.

Parameters:
dataPointer to start of the object.
datalengthContains the number of valid bytes following the start of the object. On exit, it is returned as the number of valid bytes following the end of this object.
typePointer to the variable that receives the ASN type of the object.
intpPointer to the variable that receives the value of the object.
Returns:
Pointer to the first byte past the end of this object (i.e. the start of the next object). Returns NULL on any error.

Definition at line 906 of file asn1.c.

References CONST, UNSIGNED64::high, and UNSIGNED64::low.

uint8_t* AsnUnsigned64Build ( uint8_t data,
size_t *  datalength,
uint8_t  type,
CONST UNSIGNED64 cp 
)

Build an ASN object containing a 64 bit unsigned integer.

Parameters:
dataPointer to start of output buffer
datalengthContains the number of available bytes following the start of the object. On exit, it is returned as the number of available bytes following the end of this object.
typeASN type of the object.
intpValue of the object.
Returns:
A pointer to the first byte past the end of this object (i.e. the start of the next object). Returns NULL on any error.

Definition at line 953 of file asn1.c.

References AsnHeaderBuild().

Referenced by SnmpVarBuild().

Here is the call graph for this function: