1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 #ifndef GENERICPER 19 #define GENERICPER 20 21 #include "oscl_base.h" 22 #include "per_common.h" 23 24 /*========================================*/ 25 /*========== MISCELLANEOUS DEFS ==========*/ 26 /*========================================*/ 27 28 #define EPASS (void (*)(uint8*,PS_OutStream)) 29 30 31 /*=========================================================*/ 32 /*========== STRUCTURE DEFINITIONS (Generic PER) ==========*/ 33 /*=========================================================*/ 34 35 typedef struct _OCTETSTRING /* ASN OCTET STRING */ 36 { 37 uint16 size; 38 uint8* data; 39 } S_OCTETSTRING; 40 typedef S_OCTETSTRING *PS_OCTETSTRING; 41 42 typedef struct _BITSTRING /* ASN BIT STRING */ 43 { 44 uint16 size; 45 uint8* data; 46 } S_BITSTRING; 47 48 typedef S_BITSTRING *PS_BITSTRING; 49 50 typedef struct _int8STRING /* ASN int8 STRING */ 51 { 52 uint16 size; 53 uint8* data; 54 } S_int8STRING; 55 56 typedef S_int8STRING *PS_int8STRING; 57 58 typedef struct _OBJECTIDENT /* ASN OBJECT IDENTIFIER */ 59 { 60 uint16 size; 61 uint8* data; 62 } S_OBJECTIDENT; 63 64 typedef S_OBJECTIDENT *PS_OBJECTIDENT; 65 66 typedef struct _UnknownSigMap /* Unknown SigMap */ 67 { 68 uint16 size; 69 uint8* optionFlags; 70 uint16 extensionsRead; 71 } S_UnknownSigMap; 72 73 typedef S_UnknownSigMap *PS_UnknownSigMap; 74 75 typedef struct _InStream /* Input Stream */ 76 { 77 uint8* data; /* Current byte in stream */ 78 uint8 bitIndex; /* Next bit within the byte */ 79 } S_InStream; 80 81 typedef S_InStream *PS_InStream; 82 83 typedef struct _OutStream /* Output Stream */ 84 { 85 uint8* data; /* Start of allocated space */ 86 uint16 size; /* Size of allocated space */ 87 uint16 byteIndex; /* Index: next byte to write */ 88 uint16 bitIndex; /* Index: next bit to write */ 89 uint8 buildByte; /* Next byte, under construction */ 90 } S_OutStream; 91 92 typedef S_OutStream *PS_OutStream; 93 94 /*=========================================================*/ 95 /*============ DECODING ROUTINES (Generic PER) ============*/ 96 /*=========================================================*/ 97 /* ------------- LOW LEVEL STREAM -------------- */ 98 uint8 ReadBits(uint32 number, PS_InStream stream); 99 void ReadRemainingBits(PS_InStream stream); 100 void ReadOctets(uint32 number, uint8* octets, uint8 reorder, PS_InStream stream); 101 102 /* ------------- HIGH LEVEL ASN DATA ------------- */ 103 uint8 GetBoolean(PS_InStream stream); 104 uint32 GetInteger(uint32 lower, uint32 upper, PS_InStream stream); 105 int32 GetSignedInteger(int32 lower, int32 upper, PS_InStream stream); 106 uint32 GetUnboundedInteger(PS_InStream stream); 107 uint32 GetExtendedInteger(uint32 lower, uint32 upper, PS_InStream stream); 108 void GetOctetString(uint8 unbounded, uint32 min, uint32 max, 109 PS_OCTETSTRING x, PS_InStream stream); 110 void GetBitString(uint8 unbounded, uint32 min, uint32 max, 111 PS_BITSTRING x, PS_InStream stream); 112 void GetCharString(const char *stringName, 113 uint8 unbounded, uint32 min, uint32 max, const char *from, 114 PS_int8STRING x, PS_InStream stream); 115 void GetObjectID(PS_OBJECTIDENT x, PS_InStream stream); 116 117 /* ------------- OTHER CALLS ----------------*/ 118 uint32 GetLengthDet(PS_InStream stream); 119 /* General length det, e.g. for extension wrapper */ 120 uint32 GetNormSmallLength(PS_InStream stream); 121 /* e.g. for length of extensions SigMap */ 122 uint32 GetNormSmallValue(PS_InStream stream); 123 /* e.g. for choice index when extension is ON */ 124 void SkipOneExtension(PS_InStream stream); 125 /* Reads a General Length Det, skips that many octets. */ 126 void SkipAllExtensions(PS_InStream stream); 127 /* Reads SigMap including length. Skips each */ 128 /* extension which SigMap says is present. */ 129 /* NOTE: Not generated by MiniParser. Delete? */ 130 uint16 GetChoiceIndex(uint32 rootnum, uint8 extmarker, PS_InStream stream); 131 /* Gets (possibly extended) choice index */ 132 PS_UnknownSigMap GetUnknownSigMap(PS_InStream stream); 133 /* Gets the unknown sig-map for SEQUENCE extensions */ 134 uint8 SigMapValue(uint32 index, PS_UnknownSigMap map); 135 /* Reads a value from the unknown sig-map */ 136 void ExtensionPrep(PS_UnknownSigMap map, PS_InStream stream); 137 /* Does ++map->extensionsRead */ 138 /* Also calls GetLengthDet(stream) to skip wrapper */ 139 uint32 SkipUnreadExtensions(PS_UnknownSigMap, PS_InStream stream); 140 /* Use map->extensionsRead to determine how many have */ 141 /* been read, and how many are left to be read. */ 142 /* Skips unread exts via calls to SkipOneExtension() */ 143 /* Frees the map */ 144 /* Returns the number of exts skipped. */ 145 void SkipOneOctet(PS_InStream stream); 146 147 /*=========================================================*/ 148 /*============ ENCODING ROUTINES (Generic PER) ============*/ 149 /*=========================================================*/ 150 151 /* ------------- LOW LEVEL STREAM -------------- */ 152 void WriteBits(uint32 number, uint8 bits, PS_OutStream stream); 153 void WriteRemainingBits(PS_OutStream stream); 154 void WriteOctets(uint32 number, uint8* octets, uint8 reorder, PS_OutStream stream); 155 PS_OutStream NewOutStream(void); 156 void ExpandOutStream(PS_OutStream x); 157 void FreeOutStream(PS_OutStream x); 158 159 /* ------------- HIGH LEVEL ASN DATA ------------- */ 160 void PutBoolean(uint32 value, PS_OutStream stream); 161 void PutInteger(uint32 lower, uint32 upper, uint32 value, PS_OutStream stream); 162 void PutSignedInteger(int32 lower, int32 upper, int32 value, PS_OutStream stream); 163 void PutUnboundedInteger(uint32 value, PS_OutStream stream); 164 void PutExtendedInteger(uint32 lower, uint32 upper, uint32 value, PS_OutStream stream); 165 void PutOctetString(uint8 unbounded, 166 uint32 min, uint32 max, PS_OCTETSTRING x, PS_OutStream stream); 167 void PutBitString(uint8 unbounded, 168 uint32 min, uint32 max, PS_BITSTRING x, PS_OutStream stream); 169 void PutCharString(const char *stringName, 170 uint8 unbounded, uint32 min, uint32 max, const char *from, 171 PS_int8STRING x, PS_OutStream stream); 172 void PutObjectID(PS_OBJECTIDENT x, PS_OutStream stream); 173 void PutExtensionNull(PS_OutStream stream); 174 void PutExtensionBoolean(uint32 value, PS_OutStream stream); 175 void PutExtensionInteger(uint32 lower, uint32 upper, uint32 value, PS_OutStream stream); 176 void PutExtensionOctetString(uint8 unbounded, 177 uint32 min, uint32 max, PS_OCTETSTRING x, PS_OutStream stream); 178 179 /* ------------- OTHER CALLS ----------------*/ 180 void PutNormSmallValue(uint32 value, PS_OutStream stream); 181 /* e.g. for choice index when extension is ON */ 182 void PutChoiceIndex(uint32 rootnum, uint8 extmarker, uint32 index, PS_OutStream stream); 183 /* Writes extension bit, choice index */ 184 void PutNormSmallLength(uint32 value, PS_OutStream stream); 185 /* e.g. for length of extensions SigMap */ 186 void PutLengthDet(uint32 value, PS_OutStream stream); 187 /* General length det, e.g. for extension wrapper */ 188 void PutExtensionItem( 189 void (*Func)(uint8* x, PS_OutStream stream), 190 uint8* x, PS_OutStream stream); 191 /* Write extension item, including length det */ 192 void PutTempStream(PS_OutStream tempStream, PS_OutStream stream); 193 /* Copy contents of tempStream to the real one */ 194 195 /*======================================================*/ 196 /*============ OTHER ROUTINES (Generic PER) ============*/ 197 /*======================================================*/ 198 void ErrorMessage(const char *msg); 199 void ErrorMessageAndLeave(const char *msg); 200 /* Generic error call. Just print it for now */ 201 PS_InStream ConvertOutstreamToInstream(PS_OutStream outstream); 202 PS_OCTETSTRING NewOctetString(void); 203 PS_BITSTRING NewBitString(void); 204 PS_int8STRING NewCharString(void); 205 PS_OBJECTIDENT NewObjectID(void); 206 void InitOctetString(PS_OCTETSTRING x); 207 void InitBitString(PS_BITSTRING x); 208 void InitCharString(PS_int8STRING x); 209 void InitObjectid(PS_OBJECTIDENT x); 210 void FreeOctetString(PS_OCTETSTRING x); 211 void FreeBitString(PS_BITSTRING x); 212 void FreeCharString(PS_int8STRING x); 213 void FreeObjectID(PS_OBJECTIDENT x); 214 #endif 215 216