Revision 98462704
Added by Neels Hofmeyr about 4 years ago
sim-applet/src/org/osmocom/IMSIPseudo/IMSIPseudo.java | ||
---|---|---|
29 | 29 |
'd', 'i', 'g', 'i', 't'}; |
30 | 30 |
private final Object[] itemListChangeIMSI = {changeIMSI, setDigit1, setDigit2}; |
31 | 31 |
|
32 |
private static final byte MI_IMSI = 1; |
|
33 |
|
|
32 | 34 |
private IMSIPseudo() { |
33 | 35 |
gsmFile = SIMSystem.getTheSIMView(); |
34 | 36 |
|
... | ... | |
139 | 141 |
return (byte)('A' + (bcd - 0xa)); |
140 | 142 |
} |
141 | 143 |
|
144 |
private byte char2bcd(byte c) |
|
145 |
{ |
|
146 |
if (c >= '0' && c <= '9') |
|
147 |
return (byte)(c - '0'); |
|
148 |
else if (c >= 'A' && c <= 'F') |
|
149 |
return (byte)(0xa + (c - 'A')); |
|
150 |
else if (c >= 'a' && c <= 'f') |
|
151 |
return (byte)(0xa + (c - 'a')); |
|
152 |
else |
|
153 |
return 0; |
|
154 |
} |
|
155 |
|
|
142 | 156 |
/* Convert BCD to string. |
143 | 157 |
* The given nibble offsets are interpreted in BCD order, i.e. nibble 0 is bcd[0] & 0xf, nibble 1 is bcd[0] >> 4, nibble |
144 | 158 |
* 3 is bcd[1] & 0xf, etc.. |
... | ... | |
174 | 188 |
return rc; |
175 | 189 |
} |
176 | 190 |
|
177 |
private boolean mi2str(byte dst[], byte dst_ofs, byte dst_len,
|
|
178 |
byte mi[], boolean allow_hex)
|
|
191 |
private byte mi2str(byte dst[], byte dst_ofs, byte dst_len,
|
|
192 |
byte mi[], boolean allow_hex) |
|
179 | 193 |
{ |
180 | 194 |
/* The IMSI byte array by example: |
181 | 195 |
* 08 99 10 07 00 00 10 74 90 |
... | ... | |
214 | 228 |
boolean odd_nr_of_digits = ((mi_type & 0x08) != 0); |
215 | 229 |
byte start_nibble = 2 + 1; // 2 to skip the bytelen, 1 to skip the mi_type |
216 | 230 |
byte end_nibble = (byte)(2 + bytelen * 2 - (odd_nr_of_digits ? 0 : 1)); |
217 |
return bcd2str(dst, dst_ofs, dst_len, mi, start_nibble, end_nibble, allow_hex); |
|
231 |
bcd2str(dst, dst_ofs, dst_len, mi, start_nibble, end_nibble, allow_hex); |
|
232 |
return (byte)(end_nibble - start_nibble); |
|
233 |
} |
|
234 |
|
|
235 |
private byte[] str2mi(byte str[], byte mi_type) |
|
236 |
{ |
|
237 |
/* 1 byte of MI length. |
|
238 |
* 1 nibble of mi_type. |
|
239 |
* str.length nibbles of MI BCD. |
|
240 |
* The first MI digit is in the high-nibble of the mi_type, so an odd amount of digits becomes |
|
241 |
* (1 + str.length)/2 bytes; an even amount of digits has same amount of bytes with the last |
|
242 |
* nibble unused (0xf0). */ |
|
243 |
byte len = (byte)(1 + (byte)(1 + str.length)/2); |
|
244 |
byte mi[] = new byte[1 + len]; |
|
245 |
mi[0] = len; |
|
246 |
|
|
247 |
boolean odd_digits = ((str.length & 1) != 0); |
|
248 |
mi_type = (byte)(mi_type & 0x07); |
|
249 |
if (odd_digits) |
|
250 |
mi_type |= 0x08; |
|
251 |
mi[1] = (byte)((char2bcd(str[0]) << 4) + mi_type); |
|
252 |
byte str_i = 1; |
|
253 |
for (byte bcd_i = 1; bcd_i < len; bcd_i++) { |
|
254 |
byte data = char2bcd(str[str_i]); |
|
255 |
str_i++; |
|
256 |
if (str_i < str.length) { |
|
257 |
data |= char2bcd(str[str_i]) << 4; |
|
258 |
str_i++; |
|
259 |
} else |
|
260 |
data |= 0xf0; |
|
261 |
mi[1 + bcd_i] = data; |
|
262 |
} |
|
263 |
return mi; |
|
218 | 264 |
} |
219 | 265 |
|
220 | 266 |
private void showIMSI() { |
Also available in: Unified diff
Mobile Identity routines