comparison src/g23m-aci/aci/plmn_decoder.c @ 1:fa8dc04885d8

src/g23m-*: import from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 16 Oct 2020 06:25:50 +0000
parents
children
comparison
equal deleted inserted replaced
0:4e78acac3d88 1:fa8dc04885d8
1 /* plmn_decoder.cpp : Defines the entry point for the console application. */
2
3 #include <assert.h>
4 #include <stdio.h>
5 #include <stddef.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 #ifdef TI_PS_OP_OPN_TAB_ROMBASED
10 #ifndef CMH_PLMN_DECODER_C
11 #define CMH_PLMN_DECODER_C
12 #endif
13
14 #include "aci_all.h"
15
16 /*==== INCLUDES ===================================================*/
17
18 #include "aci_cmh.h"
19 #include "ati_cmd.h"
20 #include "aci_cmd.h"
21 #include "aci_mem.h"
22 #include "pcm.h"
23
24 #ifdef TI_PS_OP_OPN_TAB_ROMBASED
25 #include "rom_tables.h"
26 #endif /* TI_PS_OP_OPN_TAB_ROMBASED */
27
28
29 #ifdef FAX_AND_DATA
30 #include "aci_fd.h"
31 #endif /* of #ifdef FAX_AND_DATA */
32
33 #include "aci.h"
34 #include "psa.h"
35 #include "psa_mm.h"
36 #include "psa_sim.h"
37 #include "psa_util.h"
38 #include "cmh.h"
39
40
41
42 #define PLMN_LONGNAME_LOOKUP 0xff
43
44 EXTERN void cmhSIM_getMncMccFrmPLMNsel( const UBYTE* ntry,
45 SHORT* mcc,
46 SHORT* mnc );
47
48 /* NHK:
49 * Once the tables plmn_compressed, plmn_dict_offset and plmn_dict go to ROM, their names below should match corresponding ROM addresses
50 * KSR: Moved to g23m\condat\com\src\drivers\rom_tables.c
51 */
52
53 /*
54 +----------------------------------------------------------------------------+
55 | PROJECT : GSM-PS (6147) MODULE : MM_MM |
56 | STATE : code ROUTINE : cmhMM_CompLongLength |
57 +----------------------------------------------------------------------------+
58
59 PURPOSE : This function gets the compressed length of the longName
60 from a compressed PLMN entry.
61
62 */
63 LOCAL USHORT cmhMM_CompLongLength (const UBYTE *plmn_comp_entry)
64 {
65 UBYTE length_byte;
66
67 length_byte = *(plmn_comp_entry + 3);
68
69 return ((length_byte >> 3) & 0x1f) + 1;
70 }
71
72 /*
73 +----------------------------------------------------------------------------+
74 | PROJECT : GSM-PS (6147) MODULE : MM_MM |
75 | STATE : code ROUTINE : cmhMM_CompShrtLength |
76 +----------------------------------------------------------------------------+
77
78 PURPOSE : This function gets the compressed length of the shrtName
79 from a compressed PLMN entry.
80
81 */
82 LOCAL USHORT cmhMM_CompShrtLength (const UBYTE *plmn_comp_entry)
83 {
84 UBYTE length_byte;
85
86 length_byte = *(plmn_comp_entry + 3);
87
88 return ((length_byte ) & 0x07) + 1;
89 }
90
91
92 /*
93 +----------------------------------------------------------------------------+
94 | PROJECT : GSM-PS (6147) MODULE : MM_MM |
95 | STATE : code ROUTINE : cmhMM_PlmnEntryLength |
96 +----------------------------------------------------------------------------+
97
98 PURPOSE : This function gets the length of a compressed PLMN entry.
99
100 */
101 GLOBAL USHORT cmhMM_PlmnEntryLength (const UBYTE *plmn_comp_entry)
102 {
103 return (4 + cmhMM_CompLongLength (plmn_comp_entry)
104 + cmhMM_CompShrtLength (plmn_comp_entry));
105 }
106
107
108 /*
109 +----------------------------------------------------------------------------+
110 | PROJECT : GSM-PS (6147) MODULE : MM_MM |
111 | STATE : code ROUTINE : cmhMM_Decompress |
112 +----------------------------------------------------------------------------+
113
114 PURPOSE : This function decompresses a compressed string.
115 If the decompressed string is the long PLMN name the longName
116 parameter is NULL, when the decompressed string is the short
117 PLMN name the longName parameter is the previously decompressed
118 PLMN long name, as in some cases the short PLMN name consists of
119 parts of the long PLMN name lookups within the decompressed long
120 name will be done when advised to do so by the compressed byte
121 string.
122 On success the function returns with zero, on detection of an
123 internal error a negative value is returned.
124
125 */
126 LOCAL SHORT cmhMM_Decompress (char *decomp_string,
127 const char *longName,
128 const UBYTE *comp_string,
129 USHORT comp_length)
130 {
131 USHORT offset;
132 USHORT length;
133
134 while (comp_length > 0)
135 {
136 if (*comp_string < 128)
137 {
138 /* GSM default alphabet. Take character 1:1 */
139 *decomp_string = *comp_string;
140 decomp_string++;
141 }
142 else if (*comp_string EQ PLMN_LONGNAME_LOOKUP)
143 {
144 if ((longName EQ NULL) OR (comp_length <= 1))
145 {
146 TRACE_ERROR ("Cannot process longName lookup");
147 return -1;
148 }
149
150 /* Decoding short name. Lookup into long name */
151
152 /* Skip PLMN_LONGNAME_LOOKUP */
153 comp_string++;
154 comp_length--;
155
156 /* Get offset and length of substring in long name */
157 offset = (*comp_string >> 3) & 0x1f;
158 length = (*comp_string & 0x07) + 1;
159 memcpy (decomp_string, longName + offset, length);
160 decomp_string += length;
161 }
162 else
163 {
164 /* Dictionary lookup */
165
166 /* Get offset of dictionary entry */
167 offset = *(ptr_plmn_dict_offset + (*comp_string - 128));
168
169 /* Get length of dictionary entry */
170 length = *(ptr_plmn_dict_offset + (*comp_string - 128 + 1)) - offset;
171 memcpy (decomp_string, ptr_plmn_dict + offset, length);
172 decomp_string += length;
173 }
174 comp_string++;
175 comp_length--;
176 }
177 decomp_string = '\0';
178 return 0;
179 }
180
181
182 /*
183 +----------------------------------------------------------------------------+
184 | PROJECT : GSM-PS (6147) MODULE : MM_MM |
185 | STATE : code ROUTINE : cmhMM_decodePlmn |
186 +----------------------------------------------------------------------------+
187
188 PURPOSE : This function decodes a compressed PLMN entry into a decompressed
189 T_OPER_ENTRY structure. On success this function returns with
190 zero, if during decompression an internal error is detected the
191 function returns with a negative value.
192
193 */
194 GLOBAL SHORT cmhMM_decodePlmn (T_OPER_ENTRY *oper, const UBYTE *plmn_comp_entry)
195 {
196 SHORT mcc; /* Mobile Country Code */
197 SHORT mnc; /* Mobile Network Code */
198 USHORT comp_Length; /* Compressed string length */
199 SHORT result; /* Decompression result */
200 const UBYTE *comp_ptr; /* Compressed PLMNs pointer */
201
202 memset (oper, 0, sizeof (T_OPER_ENTRY));
203
204 cmhSIM_getMncMccFrmPLMNsel (plmn_comp_entry, &mcc, &mnc);
205 oper->mcc = mcc;
206 oper->mnc = mnc;
207
208 if (mcc EQ -1)
209 return -1; /* Got end of list, not processing further */
210
211 /* Decompress longName */
212 comp_ptr = plmn_comp_entry + 4;
213 comp_Length = cmhMM_CompLongLength (plmn_comp_entry);
214 result = cmhMM_Decompress (oper->longName, NULL,
215 comp_ptr, comp_Length);
216 if (result < 0)
217 return result;
218
219 /* Decompress shrtName */
220 comp_ptr += comp_Length;
221 comp_Length = cmhMM_CompShrtLength (plmn_comp_entry);
222 result = cmhMM_Decompress (oper->shrtName, oper->longName,
223 comp_ptr, comp_Length);
224 return result;
225 }
226
227 #endif