comparison src/gpf3/ccd/asn1_octet.c @ 2:c41a534f33c6

src/gpf3: preened GPF goo from TCS3.2
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 25 Sep 2016 23:52:50 +0000
parents
children
comparison
equal deleted inserted replaced
1:864b8cc0cf63 2:c41a534f33c6
1 /*
2 +-----------------------------------------------------------------------------
3 | Project :
4 | Modul : asn1_octet.c
5 +-----------------------------------------------------------------------------
6 | Copyright 2002 Texas Instruments Berlin, AG
7 | All rights reserved.
8 |
9 | This file is confidential and a trade secret of Texas
10 | Instruments Berlin, AG
11 | The receipt of or possession of this file does not convey
12 | any rights to reproduce or disclose its contents or to
13 | manufacture, use, or sell anything it may describe, in
14 | whole, or in part, without the specific written consent of
15 | Texas Instruments Berlin, AG.
16 +-----------------------------------------------------------------------------
17 | Purpose : Definition of encoding and decoding functions for ASN1_OCTET
18 | elements
19 +-----------------------------------------------------------------------------
20 */
21
22
23 /*
24 * standard definitions like GLOBAL, UCHAR, ERROR etc.
25 */
26 #include "typedefs.h"
27 #include "header.h"
28
29 /*
30 * Prototypes of ccd (USE_DRIVER EQ undef) for prototypes only
31 * look at ccdapi.h
32 */
33 #undef USE_DRIVER
34 #include "ccdapi.h"
35
36 /*
37 * Types and functions for bit access and manipulation
38 */
39 #include "ccd_globs.h"
40 #include "bitfun.h"
41
42 /*
43 * Prototypes of ccd internal functions
44 */
45 #include "ccd.h"
46
47 /*
48 * Declaration of coder/decoder tables
49 */
50 #include "ccdtable.h"
51 #include "ccddata.h"
52
53 #ifndef RUN_INT_RAM
54 /*
55 +--------------------------------------------------------------------+
56 | PROJECT : CCD (6144) MODULE : CDC_GSM |
57 | STATE : code ROUTINE : cdc_asn1_octet_decode |
58 +--------------------------------------------------------------------+
59
60 PURPOSE : UNALIGNED PER decoding for the octet string type (UMTS)
61 The coded octets are preceded by a length indicator, if
62 they are not of fixed length. The length indicator is
63 decoded as an ASN1_INTEGER type.
64 */
65 SHORT cdc_asn1_octet_decode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs)
66 {
67 ULONG repeat;
68 U8 *old_pstruct = NULL;
69
70 #ifdef DEBUG_CCD
71 #ifndef CCD_SYMBOLS
72 TRACE_CCD (globs, "cdc_asn1_octet_decode()");
73 #else
74 TRACE_CCD (globs, "cdc_asn1_octet_decode() %s", ccddata_get_alias((USHORT) e_ref, 1));
75 #endif
76 #endif
77
78 /*
79 * Set pstrcutOffs and maxRep.
80 * Check the valid flag in case of optional elements.
81 */
82 if (PER_CommonBegin (e_ref, &repeat, globs) NEQ ccdOK)
83 return 1;
84
85 #ifdef DYNAMIC_ARRAYS
86 /*
87 * Check for pointer types, and allocate memory if necessary.
88 * May overwrite globs->pstruct (and initialize globs->pstructOffs to 0).
89 */
90 if ( is_pointer_type(e_ref) )
91 {
92 old_pstruct = globs->pstruct;
93 if ( PER_allocmem_and_update(e_ref, repeat, globs) NEQ ccdOK)
94 /* No memory - Return. Error already set in function call above. */
95 return 1;
96 }
97 #endif
98
99 bf_readBitStr_PER ((USHORT)(repeat << 3), globs);
100
101 #ifdef DYNAMIC_ARRAYS
102 if (old_pstruct NEQ NULL)
103 globs->pstruct = old_pstruct;
104 #endif
105
106 return 1;
107 }
108 #endif /* !RUN_INT_RAM */
109
110 #ifndef RUN_INT_RAM
111 /*
112 +--------------------------------------------------------------------+
113 | PROJECT : CCD (6144) MODULE : CDC_GSM |
114 | STATE : code ROUTINE : cdc_asn1_octet_encode |
115 +--------------------------------------------------------------------+
116
117 PURPOSE : UNALIGNED PER encoding for the octet string type (UMTS)
118 The coded octets are preceded by a length indicator, if
119 they are not of fixed length. The length indicator is
120 encoded as an ASN1_INTEGER type.
121 */
122 SHORT cdc_asn1_octet_encode (const ULONG c_ref, const ULONG e_ref, T_CCD_Globs *globs)
123 {
124 ULONG repeat;
125 U8 *old_pstruct = NULL;
126
127 #ifdef DEBUG_CCD
128 #ifndef CCD_SYMBOLS
129 TRACE_CCD (globs, "cdc_asn1_octet_encode()");
130 #else
131 TRACE_CCD (globs, "cdc_asn1_octet_encode() %s", ccddata_get_alias((USHORT) e_ref, 1));
132 #endif
133 #endif
134
135 /*
136 * Set pstrcutOffs and maxRep. Check the valid flag in case of optional elements.
137 */
138 if (PER_CommonBegin (e_ref, &repeat, globs) NEQ ccdOK)
139 return 1;
140
141 #ifdef DYNAMIC_ARRAYS
142 if ( is_pointer_type(e_ref) ) {
143 old_pstruct = globs->pstruct;
144 globs->pstruct = *(U8 **)(globs->pstruct + globs->pstructOffs);
145
146 if (ccd_check_pointer(globs->pstruct) == ccdOK)
147 {
148 globs->pstructOffs = 0;
149 }
150 else
151 {
152 ccd_recordFault (globs, ERR_INVALID_PTR, BREAK, (USHORT) e_ref,
153 &globs->pstruct[globs->pstructOffs]);
154 return 1;
155 }
156 }
157 #endif
158
159 bf_writeBitStr_PER ((USHORT)(repeat << 3), globs);
160
161 #ifdef DYNAMIC_ARRAYS
162 if ( old_pstruct NEQ NULL )
163 globs->pstruct = old_pstruct;
164 #endif
165
166 return 1;
167 }
168 #endif /* !RUN_INT_RAM */