Revision 483f5a4f
Added by Neels Hofmeyr about 4 years ago
sim-applet/src/org/osmocom/IMSIPseudo/IMSIPseudo.java | ||
---|---|---|
19 | 19 |
private static final byte[] title = { 'I', 'M', 'S', 'I', ' ', 'P', 's', 'e', 'u', 'd', 'o', 'n', 'y', 'm', |
20 | 20 |
'i', 'z', 'a', 't', 'i', 'o', 'n'}; |
21 | 21 |
private static final byte[] showLU = {'S', 'h', 'o', 'w', ' ', 'L', 'U', ' ', 'c', 'o', 'u', 'n', 't', 'e', 'r'}; |
22 |
private static final byte[] showIMSI = {'S', 'h', 'o', 'w', ' ', 'I', 'M', 'S', 'I'}; |
|
23 |
private static final byte[] changeIMSI = {'C', 'h', 'a', 'n', 'g', 'e', ' ', 'I', 'M', 'S', 'I', ' '}; |
|
24 |
private final Object[] itemListMain = {title, showLU, showIMSI, changeIMSI}; |
|
25 |
|
|
26 |
/* Change IMSI menu */ |
|
27 |
private static final byte[] enterIMSI = {'E', 'n', 't', 'e', 'r', ' ', 'I', 'M', 'S', 'I' }; |
|
28 |
private static final byte[] setDigit1 = {'S', 'e', 't', ' ', '1', ' ', 'a', 's', ' ', 'l', 'a', 's', 't', ' ', |
|
29 |
'd', 'i', 'g', 'i', 't'}; |
|
30 |
private static final byte[] setDigit2 = {'S', 'e', 't', ' ', '2', ' ', 'a', 's', ' ', 'l', 'a', 's', 't', ' ', |
|
31 |
'd', 'i', 'g', 'i', 't'}; |
|
32 |
private final Object[] itemListChangeIMSI = {changeIMSI, enterIMSI, setDigit1, setDigit2}; |
|
22 |
private static final byte[] changeIMSI = {'C', 'h', 'a', 'n', 'g', 'e', ' ', 'I', 'M', 'S', 'I'}; |
|
23 |
private static final byte[] invalidIMSI = {'I', 'n', 'v', 'a', 'l', 'i', 'd', ' ', 'I', 'M', 'S', 'I'}; |
|
24 |
private static final byte[] noChange = {'N', 'o', ' ', 'c', 'h', 'a', 'n', 'g', 'e'}; |
|
25 |
private static final byte[] changed = {'I', 'M', 'S', 'I', ' ', 'c', 'h', 'a', 'n', 'g', 'e', 'd', '!'}; |
|
26 |
private static final byte error[] = {'E', 'R', 'R', 'O', 'R' }; |
|
27 |
private final Object[] itemListMain = {title, showLU, changeIMSI}; |
|
33 | 28 |
|
34 | 29 |
private IMSIPseudo() { |
35 | 30 |
gsmFile = SIMSystem.getTheSIMView(); |
... | ... | |
172 | 167 |
showMsg(msg); |
173 | 168 |
} |
174 | 169 |
|
175 |
|
|
176 |
private void showIMSI() { |
|
177 |
/* 3GPP TS 31.102 4.2.2: IMSI */ |
|
178 |
byte[] msg = {'C', 'u', 'r', 'r', 'e', 'n', 't', ' ', 'I', 'M', 'S', 'I', ':', ' ', |
|
179 |
' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}; |
|
180 |
|
|
181 |
try { |
|
182 |
byte IMSI[] = readIMSI(); |
|
183 |
MobileIdentity.mi2str(msg, (byte)14, (byte)16, IMSI, false); |
|
184 |
showMsgAndWaitKey(msg); |
|
185 |
} catch (SIMViewException e) { |
|
186 |
showError(e.getReason()); |
|
187 |
} |
|
188 |
} |
|
189 |
|
|
190 | 170 |
private void handleMenuResponseMain() { |
191 | 171 |
ProactiveResponseHandler rspHdlr = ProactiveResponseHandler.getTheHandler(); |
192 | 172 |
|
... | ... | |
194 | 174 |
case 1: /* Show LU counter */ |
195 | 175 |
showMsg(LUCounter); |
196 | 176 |
break; |
197 |
case 2: /* Show IMSI */ |
|
198 |
showIMSI(); |
|
199 |
break; |
|
200 |
case 3: /* Change IMSI */ |
|
201 |
showMenu(itemListChangeIMSI); |
|
202 |
handleMenuResponseChangeIMSI(); |
|
177 |
case 2: /* Change IMSI */ |
|
178 |
byte prevIMSI_mi[] = readIMSI(); |
|
179 |
byte prevIMSI_str[] = MobileIdentity.mi2str(prevIMSI_mi); |
|
180 |
promptIMSI(prevIMSI_str); |
|
203 | 181 |
break; |
204 | 182 |
} |
205 | 183 |
} |
206 | 184 |
|
207 |
private void handleMenuResponseChangeIMSI() { |
|
208 |
ProactiveResponseHandler rspHdlr = ProactiveResponseHandler.getTheHandler(); |
|
209 |
switch (rspHdlr.getItemIdentifier()) { |
|
210 |
case 1: /* enter IMSI */ |
|
211 |
promptIMSI(); |
|
212 |
break; |
|
213 |
case 2: /* set last digit to 1 */ |
|
214 |
promptIMSI(); |
|
215 |
break; |
|
216 |
case 3: /* set last digit to 2 */ |
|
217 |
promptIMSI(); |
|
218 |
break; |
|
185 |
private void promptIMSI(byte prevIMSI_str[]) |
|
186 |
{ |
|
187 |
byte newIMSI_str[] = prevIMSI_str; |
|
188 |
|
|
189 |
try { |
|
190 |
newIMSI_str = prompt(changeIMSI, newIMSI_str, (short)0, (short)15); |
|
191 |
} catch (Exception e) { |
|
192 |
showError((short)40); |
|
193 |
return; |
|
194 |
} |
|
195 |
|
|
196 |
if (newIMSI_str.length < 6 || newIMSI_str.length > 15 |
|
197 |
|| !Bytes.isDigit(newIMSI_str)) { |
|
198 |
showMsg(invalidIMSI); |
|
199 |
return; |
|
200 |
} |
|
201 |
|
|
202 |
if (Bytes.equals(newIMSI_str, prevIMSI_str)) { |
|
203 |
showMsg(noChange); |
|
204 |
return; |
|
219 | 205 |
} |
220 |
} |
|
221 | 206 |
|
222 |
private void promptIMSI() |
|
223 |
{ |
|
224 |
byte[] msg = {'N', 'e', 'w', ' ', 'I', 'M', 'S', 'I', '?'}; |
|
225 |
byte imsi[] = prompt(msg, (short)0, (short)15); |
|
226 |
/* The IMSI file should be 9 bytes long, even if the IMSI is shorter */ |
|
227 | 207 |
byte mi[]; |
228 | 208 |
try { |
229 |
mi = MobileIdentity.str2mi(imsi, MobileIdentity.MI_IMSI, (byte)9); |
|
209 |
/* The IMSI file should be 9 bytes long, even if the IMSI is shorter */ |
|
210 |
mi = MobileIdentity.str2mi(newIMSI_str, MobileIdentity.MI_IMSI, (byte)9); |
|
230 | 211 |
writeIMSI(mi); |
212 |
showMsg(changed); |
|
231 | 213 |
} catch (Exception e) { |
232 |
byte err[] = {'E', 'R', 'R' }; |
|
233 |
showMsgAndWaitKey(err); |
|
214 |
showError((short)42); |
|
234 | 215 |
} |
235 | 216 |
} |
236 | 217 |
|
Also available in: Unified diff
refactor the menu, the mi2str() implementation, and tests
Instead of a sub-menu for changing the IMSI, just offer a dialog with the
current IMSI pre-filled in an edit field.
"Show IMSI" becomes just "Change IMSI" without changing anything.
Change mi2str() so that it simply returns a byte[] of the right size.
Test new mi2str()