Diffstat (limited to 'gammu/emb/gammu/depend/nokia/dct3.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | gammu/emb/gammu/depend/nokia/dct3.c | 801 |
1 files changed, 801 insertions, 0 deletions
diff --git a/gammu/emb/gammu/depend/nokia/dct3.c b/gammu/emb/gammu/depend/nokia/dct3.c new file mode 100644 index 0000000..d4a55da --- a/dev/null +++ b/gammu/emb/gammu/depend/nokia/dct3.c | |||
@@ -0,0 +1,801 @@ | |||
1 | /* (c) 2002-2004 by Marcin Wiacek */ | ||
2 | /* MSID by Walek */ | ||
3 | |||
4 | #include "../../../common/gsmstate.h" | ||
5 | |||
6 | #ifdef GSM_ENABLE_NOKIA_DCT3 | ||
7 | |||
8 | #include <string.h> | ||
9 | #include <signal.h> | ||
10 | |||
11 | #include "../../../common/misc/coding/coding.h" | ||
12 | #include "../../../common/gsmcomon.h" | ||
13 | #include "../../../common/service/gsmpbk.h" | ||
14 | #include "../../../common/phone/nokia/dct3/dct3func.h" | ||
15 | #include "../../../common/phone/pfunc.h" | ||
16 | #include "../../gammu.h" | ||
17 | |||
18 | extern GSM_Reply_Function UserReplyFunctions3[]; | ||
19 | |||
20 | /* ------- some usefull functions ----------------------------------------- */ | ||
21 | |||
22 | GSM_Error CheckDCT3Only() | ||
23 | { | ||
24 | bool found = false; | ||
25 | |||
26 | /* Checking if phone is DCT3 */ | ||
27 | #ifdef GSM_ENABLE_NOKIA6110 | ||
28 | if (strstr(N6110Phone.models, s.Phone.Data.ModelInfo->model) != NULL) found = true; | ||
29 | #endif | ||
30 | #ifdef GSM_ENABLE_NOKIA7110 | ||
31 | if (strstr(N7110Phone.models, s.Phone.Data.ModelInfo->model) != NULL) found = true; | ||
32 | #endif | ||
33 | #ifdef GSM_ENABLE_NOKIA9210 | ||
34 | if (strstr(N9210Phone.models, s.Phone.Data.ModelInfo->model) != NULL) found = true; | ||
35 | #endif | ||
36 | if (!found) return ERR_NOTSUPPORTED; | ||
37 | |||
38 | if (s.ConnectionType!=GCT_MBUS2 && s.ConnectionType!=GCT_FBUS2 && | ||
39 | s.ConnectionType!=GCT_FBUS2DLR3 && s.ConnectionType!=GCT_FBUS2BLUE && | ||
40 | s.ConnectionType!=GCT_FBUS2IRDA && s.ConnectionType!=GCT_IRDAPHONET && | ||
41 | s.ConnectionType!=GCT_BLUEFBUS2) { | ||
42 | return ERR_OTHERCONNECTIONREQUIRED; | ||
43 | } | ||
44 | return ERR_NONE; | ||
45 | } | ||
46 | |||
47 | static void CheckDCT3() | ||
48 | { | ||
49 | GSM_Error error; | ||
50 | |||
51 | error = CheckDCT3Only(); | ||
52 | switch (error) { | ||
53 | case ERR_NOTSUPPORTED: | ||
54 | Print_Error(ERR_NOTSUPPORTED); | ||
55 | break; | ||
56 | case ERR_OTHERCONNECTIONREQUIRED: | ||
57 | printf("Can't do it with current phone protocol\n"); | ||
58 | GSM_TerminateConnection(&s); | ||
59 | exit(-1); | ||
60 | default: | ||
61 | break; | ||
62 | } | ||
63 | } | ||
64 | |||
65 | static bool answer_yes3(char *text) | ||
66 | { | ||
67 | int len; | ||
68 | char ans[99]; | ||
69 | |||
70 | while (1) { | ||
71 | printf("%s (yes/no) ? ",text); | ||
72 | len=GetLine(stdin, ans, 99); | ||
73 | if (len==-1) exit(-1); | ||
74 | if (mystrncasecmp(ans, "yes",0)) return true; | ||
75 | if (mystrncasecmp(ans, "no" ,0)) return false; | ||
76 | } | ||
77 | } | ||
78 | |||
79 | /* ------------------- functions ------------------------------------------- */ | ||
80 | |||
81 | static FILE *DCT3T9File; | ||
82 | |||
83 | static GSM_Error DCT3_ReplyGetT9(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
84 | { | ||
85 | int DCT3T9Size; | ||
86 | |||
87 | DCT3T9Size = msg.Length - 6; | ||
88 | fwrite(msg.Buffer+6,1,DCT3T9Size,DCT3T9File); | ||
89 | return ERR_NONE; | ||
90 | } | ||
91 | |||
92 | void DCT3GetT9(int argc, char *argv[]) | ||
93 | { | ||
94 | int i; | ||
95 | unsigned char req[] = {0x00, 0x01, 0xAE, 0x02, 0x00, | ||
96 | 0x00};/* Part number */ | ||
97 | |||
98 | //"00 01 AE 00" gets some control values | ||
99 | |||
100 | if (CheckDCT3Only()!=ERR_NONE) return; | ||
101 | |||
102 | DCT3T9File = fopen("T9", "w"); | ||
103 | if (DCT3T9File == NULL) return; | ||
104 | |||
105 | s.User.UserReplyFunctions=UserReplyFunctions3; | ||
106 | |||
107 | for (i=0;i<5;i++) { | ||
108 | req[5] = i; | ||
109 | error=GSM_WaitFor (&s, req, 6, 0x40, 4, ID_User3); | ||
110 | Print_Error(error); | ||
111 | } | ||
112 | |||
113 | fclose(DCT3T9File); | ||
114 | } | ||
115 | |||
116 | void DCT3VibraTest(int argc, char *argv[]) | ||
117 | { | ||
118 | unsigned char ans[200]; | ||
119 | unsigned char SetLevel[4] = {0x00, 0x01, 0xA3, | ||
120 | 0xff};/* Level */ | ||
121 | |||
122 | if (CheckDCT3Only()!=ERR_NONE) return; | ||
123 | |||
124 | s.User.UserReplyFunctions=UserReplyFunctions3; | ||
125 | |||
126 | error=DCT3_EnableSecurity (&s, 0x01); | ||
127 | Print_Error(error); | ||
128 | |||
129 | error=GSM_WaitFor (&s, SetLevel, 4, 0x40, 4, ID_User3); | ||
130 | Print_Error(error); | ||
131 | |||
132 | printf("Press any key to continue...\n"); | ||
133 | GetLine(stdin, ans, 99); | ||
134 | |||
135 | SetLevel[3] = 0x00; | ||
136 | error=GSM_WaitFor (&s, SetLevel, 4, 0x40, 4, ID_User3); | ||
137 | } | ||
138 | |||
139 | static GSM_Error DCT3_ReplyPhoneTests(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
140 | { | ||
141 | int i; | ||
142 | |||
143 | for (i=0;i<msg.Buffer[3];i++) { | ||
144 | switch (i) { | ||
145 | case 0: printf("Unknown(%02i) ",i);break; | ||
146 | case 1: printf("MCU ROM checksum (startup)");break; | ||
147 | case 2: printf("MCU RAM interface (startup)");break; | ||
148 | case 3: printf("MCU RAM component ");break; | ||
149 | case 4: printf("MCU EEPROM interface (startup)");break; | ||
150 | case 5: printf("MCU EEPROM component ");break; | ||
151 | case 6: printf("Real Time Clock battery (startup)");break; | ||
152 | case 7: printf("CCONT interface (startup)");break; | ||
153 | case 8: printf("AD converter (startup)");break; | ||
154 | case 9: printf("SW Reset ");break; | ||
155 | case 10:printf("Power Off ");break; | ||
156 | case 11:printf("Security Data ");break; | ||
157 | case 12:printf("EEPROM Tune checksum (startup)");break; | ||
158 | case 13:printf("PPM checksum (startup)");break; | ||
159 | case 14:printf("MCU download DSP (startup)");break; | ||
160 | case 15:printf("DSP alive (startup)");break; | ||
161 | case 16:printf("COBBA serial (startup)");break; | ||
162 | case 17:printf("COBBA paraller (startup)");break; | ||
163 | case 18:printf("EEPROM security checksum (startup)");break; | ||
164 | case 19:printf("PPM validity (startup)");break; | ||
165 | case 20:printf("Warranty state (startup)");break; | ||
166 | case 21:printf("Simlock check/SW version (startup)");break; | ||
167 | case 22:printf("IMEI check? ");break;/*from PC-Locals1.3.is OK?*/ | ||
168 | default:printf("Unknown(%02i) ",i);break; | ||
169 | } | ||
170 | switch (msg.Buffer[4+i]) { | ||
171 | case 0: printf(" : passed"); break; | ||
172 | case 0xff:printf(" : not executed"); break; | ||
173 | case 254: printf(" : fail"); break; | ||
174 | default: printf(" : result unknown(%i)",msg.Buffer[4+i]);break; | ||
175 | } | ||
176 | printf("\n"); | ||
177 | } | ||
178 | |||
179 | return ERR_NONE; | ||
180 | } | ||
181 | |||
182 | void DCT3SelfTests(int argc, char *argv[]) | ||
183 | { | ||
184 | unsigned char buffer[3] = {0x00,0x01,0xcf}; | ||
185 | unsigned char buffer3[8] = {0x00,0x01,0xce,0x1d,0xfe,0x23,0x00,0x00}; | ||
186 | int i; | ||
187 | |||
188 | if (CheckDCT3Only()!=ERR_NONE) return; | ||
189 | |||
190 | error=DCT3_EnableSecurity (&s, 0x01); | ||
191 | Print_Error(error); | ||
192 | |||
193 | if (answer_yes3("Run all tests now ?")) { | ||
194 | /* make almost all tests */ | ||
195 | error = s.Protocol.Functions->WriteMessage(&s, buffer3, 8, 0x40); | ||
196 | Print_Error(error); | ||
197 | |||
198 | GSM_Terminate(); | ||
199 | |||
200 | while (!false) { | ||
201 | GSM_Init(false); | ||
202 | if (error==ERR_NONE) break; | ||
203 | GSM_Terminate(); | ||
204 | } | ||
205 | |||
206 | my_sleep(400); | ||
207 | } | ||
208 | |||
209 | s.User.UserReplyFunctions=UserReplyFunctions3; | ||
210 | |||
211 | for (i=0;i<10;i++) { | ||
212 | error=GSM_WaitFor (&s, buffer, 3, 0x40, 4, ID_User1); | ||
213 | if (error == ERR_NONE) break; | ||
214 | } | ||
215 | } | ||
216 | |||
217 | struct DCT3ADCInfo { | ||
218 | char *name; | ||
219 | char *unit; | ||
220 | int x; | ||
221 | intpos1; | ||
222 | intpos2; | ||
223 | }; | ||
224 | |||
225 | static struct DCT3ADCInfo DCT3ADC[] = { | ||
226 | {"Battery voltage:", "mV", 1, 3, 2}, | ||
227 | // {"Charger voltage:", "mV", 1, -1, 7}, | ||
228 | // {"Charger current:", "mA", 1, -1, 5}, | ||
229 | {"Battery type:", "mAh", 1, 4, 3}, | ||
230 | {"Battery temperature:", "mK", 10, 5, 4}, | ||
231 | // {"Accessory detection:", "mV", 1, -1, -1}, | ||
232 | {"RSSI:", "", 1, 2, -1}, | ||
233 | // {"VCXO temperature:", "mV", 1, -1, -1}, | ||
234 | // {"Hook information:", "mV", 1, -1, -1}, | ||
235 | |||
236 | {"", "", 1, -1, -1} | ||
237 | }; | ||
238 | |||
239 | unsigned char DCT3ADCBuf[200]; | ||
240 | int DCT3ADCInt; | ||
241 | |||
242 | static GSM_Error DCT3_ReplyGetADC(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
243 | { | ||
244 | switch (msg.Buffer[2]) { | ||
245 | case 0x68: | ||
246 | memcpy(DCT3ADCBuf,msg.Buffer+4,msg.Length-4); | ||
247 | return ERR_NONE; | ||
248 | case 0x91: | ||
249 | DCT3ADCInt = msg.Buffer[4]*256+msg.Buffer[5]; | ||
250 | return ERR_NONE; | ||
251 | } | ||
252 | return ERR_UNKNOWNRESPONSE; | ||
253 | } | ||
254 | |||
255 | void DCT3GetADC(int argc, char *argv[]) | ||
256 | { | ||
257 | int i = 0; | ||
258 | unsigned charGetRaw[] = {0x00, 0x01, 0x68}; | ||
259 | unsigned charGetUnit[] = {0x00, 0x01, 0x91, | ||
260 | 0x02}; /* Test number */ | ||
261 | |||
262 | if (CheckDCT3Only()!=ERR_NONE) return; | ||
263 | |||
264 | s.User.UserReplyFunctions=UserReplyFunctions3; | ||
265 | |||
266 | error=DCT3_EnableSecurity (&s, 0x02); | ||
267 | Print_Error(error); | ||
268 | |||
269 | error=GSM_WaitFor (&s, GetRaw, 3, 0x40, 6, ID_User3); | ||
270 | Print_Error(error); | ||
271 | |||
272 | while (1) { | ||
273 | printf(" %30s ",DCT3ADC[i].name); | ||
274 | if (DCT3ADC[i].pos1 != -1) { | ||
275 | printf("raw "); | ||
276 | printf("%10i ", | ||
277 | DCT3ADCBuf[(DCT3ADC[i].pos1-1)*2]*256+ | ||
278 | DCT3ADCBuf[(DCT3ADC[i].pos1-1)*2+1]); | ||
279 | } | ||
280 | if (DCT3ADC[i].pos2 != -1) { | ||
281 | printf("unit result "); | ||
282 | GetUnit[3] = DCT3ADC[i].pos2; | ||
283 | error=GSM_WaitFor (&s, GetUnit, 6, 0x40, 4, ID_User3); | ||
284 | Print_Error(error); | ||
285 | printf("%10i ",DCT3ADCInt*DCT3ADC[i].x); | ||
286 | printf("%s\n",DCT3ADC[i].unit); | ||
287 | } | ||
288 | i++; | ||
289 | if (DCT3ADC[i].name[0] == 0x00) break; | ||
290 | } | ||
291 | |||
292 | error=DCT3_EnableSecurity (&s, 0x01); | ||
293 | Print_Error(error); | ||
294 | } | ||
295 | |||
296 | void DCT3DisplayTest(int argc, char *argv[]) | ||
297 | { | ||
298 | unsigned char ans[200]; | ||
299 | unsigned char req[] = {0x00, 0x01, 0xD3, | ||
300 | 0x03, /* 3=set, 2=clear */ | ||
301 | 0x03}; /* test number */ | ||
302 | |||
303 | if (CheckDCT3Only()!=ERR_NONE) return; | ||
304 | |||
305 | if (atoi(argv[2]) != 1 && atoi(argv[2]) != 2) { | ||
306 | printf("Give 1 or 2 as test number\n"); | ||
307 | } | ||
308 | |||
309 | s.User.UserReplyFunctions=UserReplyFunctions3; | ||
310 | |||
311 | req[4] = atoi(argv[2]); | ||
312 | s.Protocol.Functions->WriteMessage(&s, req, 5, 0x40); | ||
313 | |||
314 | printf("Press any key to continue...\n"); | ||
315 | GetLine(stdin, ans, 99); | ||
316 | |||
317 | req[3] = 0x02; | ||
318 | req[4] = 0x03; | ||
319 | s.Protocol.Functions->WriteMessage(&s, req, 5, 0x40); | ||
320 | |||
321 | error=DCT3_EnableSecurity (&s, 0x03); | ||
322 | Print_Error(error); | ||
323 | } | ||
324 | |||
325 | void DCT3netmonitor(int argc, char *argv[]) | ||
326 | { | ||
327 | char value[100]; | ||
328 | |||
329 | GSM_Init(true); | ||
330 | |||
331 | CheckDCT3(); | ||
332 | |||
333 | error=DCT3_Netmonitor(&s, atoi(argv[2]), value); | ||
334 | Print_Error(error); | ||
335 | |||
336 | printf("%s\n",value); | ||
337 | #ifdef GSM_ENABLE_BEEP | ||
338 | if (atoi(argv[2]) == 243) GSM_PhoneBeep(); | ||
339 | #endif | ||
340 | GSM_Terminate(); | ||
341 | } | ||
342 | |||
343 | static GSM_Error DCT3_ReplyGetMSID(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
344 | { | ||
345 | int i; | ||
346 | |||
347 | printf("MSID : "); | ||
348 | for (i=5;i<18;i++) printf("%02x",msg.Buffer[i]); | ||
349 | printf("\n"); | ||
350 | return ERR_NONE; | ||
351 | } | ||
352 | |||
353 | static GSM_Error DCT3_ReplyGetDSPROM(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
354 | { | ||
355 | printf("DSP ROM : %c\n",msg.Buffer[5]); | ||
356 | return ERR_NONE; | ||
357 | } | ||
358 | |||
359 | static GSM_Error DCT3_ReplySimlockInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
360 | { | ||
361 | inti, j; | ||
362 | charuni[100], buffer[50]; | ||
363 | |||
364 | j=0; | ||
365 | for (i=0; i < 12; i++) { | ||
366 | if (j<24) { | ||
367 | uni[j]='0' + (msg.Buffer[9+i] >> 4); | ||
368 | j++; | ||
369 | } | ||
370 | if (j!=15) { | ||
371 | if (j<24) { | ||
372 | uni[j]='0' + (msg.Buffer[9+i] & 0x0f); | ||
373 | j++; | ||
374 | } | ||
375 | } else j++; | ||
376 | } | ||
377 | |||
378 | strncpy(buffer,uni,5); | ||
379 | buffer[5]=0; | ||
380 | printf("Simlock 1 : MCC+MNC %10s, %s, %s, counter %i\n", | ||
381 | buffer, | ||
382 | ((msg.Buffer[6] & 1) == 1)==0?"opened":"CLOSED", | ||
383 | ((msg.Buffer[5] & 1) != 1)==0?"user ":"factory", | ||
384 | msg.Buffer[21]); | ||
385 | |||
386 | strncpy(buffer,uni+16,4); | ||
387 | buffer[4]=0; | ||
388 | printf("Simlock 2 : GID1 %10s, %s, %s, counter %i\n", | ||
389 | buffer, | ||
390 | ((msg.Buffer[6] & 4) == 4)==0?"opened":"CLOSED", | ||
391 | ((msg.Buffer[5] & 4) != 4)==0?"user ":"factory", | ||
392 | msg.Buffer[23]); | ||
393 | |||
394 | strncpy(buffer,uni+20,4); | ||
395 | buffer[4]=0; | ||
396 | printf("Simlock 3 : GID2 %10s, %s, %s, counter %i\n", | ||
397 | buffer, | ||
398 | ((msg.Buffer[6] & 8) == 8)==0?"opened":"CLOSED", | ||
399 | ((msg.Buffer[5] & 8) != 8)==0?"user ":"factory", | ||
400 | msg.Buffer[24]); | ||
401 | |||
402 | strncpy(buffer,uni+5,10); | ||
403 | buffer[10]=0; | ||
404 | printf("Simlock 4 : MSIN %10s, %s, %s, counter %i\n", | ||
405 | buffer, | ||
406 | ((msg.Buffer[6] & 2) == 2)==0?"opened":"CLOSED", | ||
407 | ((msg.Buffer[5] & 2) != 2)==0?"user ":"factory", | ||
408 | msg.Buffer[22]); | ||
409 | |||
410 | return ERR_NONE; | ||
411 | } | ||
412 | |||
413 | static GSM_Error DCT3_ReplyGetMCUchkSum(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
414 | { | ||
415 | int i; | ||
416 | |||
417 | if (msg.Buffer[3] == 0x12) printf("Language Pack: %c\n",msg.Buffer[5]); | ||
418 | if (msg.Buffer[3] == 0x02) { | ||
419 | printf("MCU checksum : "); | ||
420 | for (i=5;i<9;i++) printf("%c",msg.Buffer[i]); | ||
421 | printf("\n"); | ||
422 | } | ||
423 | return ERR_NONE; | ||
424 | } | ||
425 | |||
426 | static unsigned char MSID1; | ||
427 | |||
428 | GSM_Error DCT3_ReplyEnableSecurity2(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
429 | { | ||
430 | smprintf(s, "State of security commands set\n"); | ||
431 | MSID1 = msg.Buffer[5]; | ||
432 | return ERR_NONE; | ||
433 | } | ||
434 | |||
435 | void DCT3Info(int argc, char *argv[]) | ||
436 | { | ||
437 | unsigned char req[] = {0x00, 0x01, 0x8A, 0x00}; /* Get simlock info */ | ||
438 | unsigned char req2[] = {0x00, 0x01, 0xb4, 0x00, 0x00}; /* Get MSID */ | ||
439 | unsigned char req3[] = {0x00, 0x01, 0xc8, 0x02}; /* Get MCU chksum */ | ||
440 | unsigned char req4[] = {0x00, 0x01, 0xc8, 0x09}; /* Get DSP ROM */ | ||
441 | |||
442 | if (CheckDCT3Only()!=ERR_NONE) return; | ||
443 | |||
444 | s.User.UserReplyFunctions=UserReplyFunctions3; | ||
445 | |||
446 | error=DCT3_EnableSecurity (&s, 0x01); | ||
447 | Print_Error(error); | ||
448 | |||
449 | error=GSM_WaitFor (&s, req, 4, 0x40, 4, ID_User3); | ||
450 | Print_Error(error); | ||
451 | |||
452 | req2[3] = MSID1; | ||
453 | req2[4] = req2[2] + req2[3]; | ||
454 | error=GSM_WaitFor (&s, req2, 5, 0x40, 4, ID_User8); | ||
455 | Print_Error(error); | ||
456 | |||
457 | error=GSM_WaitFor (&s, req3, 4, 0x40, 4, ID_User9); | ||
458 | Print_Error(error); | ||
459 | |||
460 | error=GSM_WaitFor (&s, req4, 4, 0x40, 4, ID_User10); | ||
461 | Print_Error(error); | ||
462 | } | ||
463 | |||
464 | static GSM_Error DCT3_ReplyResetTest36(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
465 | { | ||
466 | printf("Netmonitor test 36 cleaned OK\n"); | ||
467 | return ERR_NONE; | ||
468 | } | ||
469 | |||
470 | void DCT3ResetTest36(int argc, char *argv[]) | ||
471 | { | ||
472 | unsigned char req[] = {0x00, 0x01, 0x65, 0x40, 0x00}; /* Reset test 36 in netmon */ | ||
473 | |||
474 | GSM_Init(true); | ||
475 | |||
476 | CheckDCT3(); | ||
477 | |||
478 | error=DCT3_EnableSecurity (&s, 0x01); | ||
479 | Print_Error(error); | ||
480 | |||
481 | s.User.UserReplyFunctions=UserReplyFunctions3; | ||
482 | |||
483 | error=GSM_WaitFor (&s, req, 5, 0x40, 4, ID_User2); | ||
484 | Print_Error(error); | ||
485 | |||
486 | #ifdef GSM_ENABLE_BEEP | ||
487 | GSM_PhoneBeep(); | ||
488 | #endif | ||
489 | GSM_Terminate(); | ||
490 | } | ||
491 | |||
492 | static unsigned char PPS[32]; /* Product Profile Settings */ | ||
493 | |||
494 | static GSM_Error DCT3_ReplyGetPPS(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
495 | { | ||
496 | int i,j,z; | ||
497 | |||
498 | #ifdef DEBUG | ||
499 | dbgprintf("Product Profile Settings received -"); | ||
500 | for (i=0;i<4;i++) dbgprintf(" %02x",msg.Buffer[3+i]); | ||
501 | dbgprintf("\n"); | ||
502 | #endif | ||
503 | j=128;z=0; | ||
504 | for (i=0;i<32;i++) { | ||
505 | PPS[i]='0'; | ||
506 | if (msg.Buffer[z+3]&j) PPS[i]='1'; | ||
507 | if (j==1) { | ||
508 | j=128; | ||
509 | z++; | ||
510 | } else j=j/2; | ||
511 | } | ||
512 | #ifdef DEBUG | ||
513 | dbgprintf("After decoding: "); | ||
514 | for (i=0;i<32;i++) dbgprintf("%c",PPS[i]); | ||
515 | dbgprintf("\n"); | ||
516 | #endif | ||
517 | return ERR_NONE; | ||
518 | } | ||
519 | |||
520 | static GSM_Error DCT3_ReplySetPPS(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
521 | { | ||
522 | printf("Setting done OK\n"); | ||
523 | return ERR_NONE; | ||
524 | } | ||
525 | |||
526 | void DCT3SetPhoneMenus(int argc, char *argv[]) | ||
527 | { | ||
528 | char value[100]; | ||
529 | int i,j,z; | ||
530 | unsigned char reqGet[] = {0x00, 0x01, 0x6a}; | ||
531 | unsigned char reqSet[] = { | ||
532 | 0x00, 0x01, 0x6b, | ||
533 | 0x00, 0x00, 0x00, 0x00 }; /* bytes with Product Profile Setings */ | ||
534 | |||
535 | if (CheckDCT3Only()!=ERR_NONE) return; | ||
536 | |||
537 | error=DCT3_EnableSecurity (&s, 0x01); | ||
538 | Print_Error(error); | ||
539 | |||
540 | s.User.UserReplyFunctions=UserReplyFunctions3; | ||
541 | |||
542 | error=GSM_WaitFor (&s, reqGet, 3, 0x40, 4, ID_User4); | ||
543 | Print_Error(error); | ||
544 | |||
545 | printf("ALS : enabling menu\n"); | ||
546 | PPS[10] = '1'; | ||
547 | |||
548 | if (!strcmp(s.Phone.Data.ModelInfo->model,"3310") && s.Phone.Data.VerNum>5.87) { | ||
549 | printf("3310: enabling control of SMS charsets\n"); | ||
550 | PPS[11] = '0';//0 = ON, 1 = OFF | ||
551 | } | ||
552 | if (!strcmp(s.Phone.Data.ModelInfo->model,"6150")) { | ||
553 | printf("6150: enabling WellMate menu\n"); | ||
554 | PPS[18] = '1'; | ||
555 | } | ||
556 | /* FIXME */ | ||
557 | if (!strcmp(s.Phone.Data.ModelInfo->model,"3210")) { | ||
558 | printf("3210: enabling vibra menu\n"); | ||
559 | PPS[24] = '1'; | ||
560 | } | ||
561 | if (!strcmp(s.Phone.Data.ModelInfo->model,"3310") && s.Phone.Data.VerNum>5.13) { | ||
562 | printf("3310: enabling 3315 features\n"); | ||
563 | PPS[25] = '1'; | ||
564 | } | ||
565 | /* FIXME */ | ||
566 | if (!strcmp(s.Phone.Data.ModelInfo->model,"3210") && s.Phone.Data.VerNum>=5.31) { | ||
567 | printf("3210: enabling React and Logic game\n"); | ||
568 | PPS[26] = '1'; | ||
569 | } | ||
570 | |||
571 | #ifdef DEBUG | ||
572 | dbgprintf("After settings: "); | ||
573 | for (i=0;i<32;i++) dbgprintf("%c",PPS[i]); | ||
574 | dbgprintf("\n"); | ||
575 | #endif | ||
576 | |||
577 | j=128;z=0; | ||
578 | for (i=0;i<32;i++) { | ||
579 | if (PPS[i]=='1') reqSet[z+3]=reqSet[z+3]+j; | ||
580 | if (j==1) { | ||
581 | j=128; | ||
582 | z++; | ||
583 | } else j=j/2; | ||
584 | } | ||
585 | |||
586 | //reqSet[3]=0xe7; | ||
587 | //reqSet[4]=0x25; | ||
588 | //reqSet[5]=0x00; | ||
589 | //reqSet[6]=0xe0; | ||
590 | |||
591 | error=GSM_WaitFor (&s, reqSet, 7, 0x40, 4, ID_User4); | ||
592 | Print_Error(error); | ||
593 | |||
594 | printf("Enabling netmonitor\n"); | ||
595 | error=DCT3_Netmonitor(&s, 243, value); | ||
596 | Print_Error(error); | ||
597 | } | ||
598 | |||
599 | static GSM_Error DCT3_Reply61GetSecurityCode(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
600 | { | ||
601 | printf("Security Code is \"%s\"\n",msg.Buffer+5); | ||
602 | return ERR_NONE; | ||
603 | } | ||
604 | |||
605 | static GSM_Error DCT3_Reply7191GetSecurityCode(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
606 | { | ||
607 | printf("Security Code is \"%s\"\n",msg.Buffer+6); | ||
608 | return ERR_NONE; | ||
609 | } | ||
610 | |||
611 | void DCT3GetSecurityCode(int argc, char *argv[]) | ||
612 | { | ||
613 | unsigned char req6110[] = {0x00, 0x01, 0x6e, | ||
614 | 0x01};/* Code type */ | ||
615 | unsigned char req71_91[] = {N7110_FRAME_HEADER, 0xee, | ||
616 | 0x1c};/* Setting */ | ||
617 | |||
618 | if (CheckDCT3Only()!=ERR_NONE) return; | ||
619 | |||
620 | error=DCT3_EnableSecurity (&s, 0x01); | ||
621 | Print_Error(error); | ||
622 | |||
623 | s.User.UserReplyFunctions=UserReplyFunctions3; | ||
624 | |||
625 | #ifdef GSM_ENABLE_NOKIA6110 | ||
626 | if (strstr(N6110Phone.models, s.Phone.Data.ModelInfo->model) != NULL) { | ||
627 | error=GSM_WaitFor (&s, req6110, 4, 0x40, 4, ID_User6); | ||
628 | } | ||
629 | #endif | ||
630 | #ifdef GSM_ENABLE_NOKIA7110 | ||
631 | if (strstr(N7110Phone.models, s.Phone.Data.ModelInfo->model) != NULL) { | ||
632 | error=GSM_WaitFor (&s, req71_91, 5, 0x7a, 4, ID_User6); | ||
633 | } | ||
634 | #endif | ||
635 | #ifdef GSM_ENABLE_NOKIA9210 | ||
636 | if (strstr(N9210Phone.models, s.Phone.Data.ModelInfo->model) != NULL) { | ||
637 | error=GSM_WaitFor (&s, req71_91, 5, 0x7a, 4, ID_User6); | ||
638 | } | ||
639 | #endif | ||
640 | Print_Error(error); | ||
641 | } | ||
642 | |||
643 | #ifdef GSM_ENABLE_NOKIA6110 | ||
644 | |||
645 | static GSM_Error DCT3_ReplyGetOperatorName(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
646 | { | ||
647 | unsigned char buffer[10]; | ||
648 | |||
649 | NOKIA_DecodeNetworkCode(msg.Buffer+5, buffer); | ||
650 | buffer[6] = 0; | ||
651 | printf("Network : %s (%s ",buffer,DecodeUnicodeString(GSM_GetNetworkName(buffer))); | ||
652 | printf(", %s)\n", DecodeUnicodeString(GSM_GetCountryName(buffer))); | ||
653 | printf("Name : \"%s\"\n",msg.Buffer+8); | ||
654 | |||
655 | return ERR_NONE; | ||
656 | } | ||
657 | |||
658 | void DCT3GetOperatorName(int argc, char *argv[]) | ||
659 | { | ||
660 | unsigned char req[] = {0x00,0x01,0x8c,0x00}; | ||
661 | |||
662 | GSM_Init(true); | ||
663 | |||
664 | if (strstr(N6110Phone.models, s.Phone.Data.ModelInfo->model) == NULL) Print_Error(ERR_NOTSUPPORTED); | ||
665 | CheckDCT3(); | ||
666 | |||
667 | error=DCT3_EnableSecurity (&s, 0x01); | ||
668 | Print_Error(error); | ||
669 | |||
670 | s.User.UserReplyFunctions=UserReplyFunctions3; | ||
671 | |||
672 | error=GSM_WaitFor (&s, req, 4, 0x40, 4, ID_User5); | ||
673 | Print_Error(error); | ||
674 | |||
675 | GSM_Terminate(); | ||
676 | } | ||
677 | |||
678 | static GSM_Error DCT3_ReplySetOperatorName(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
679 | { | ||
680 | printf("Operator name set OK\n"); | ||
681 | return ERR_NONE; | ||
682 | } | ||
683 | |||
684 | void DCT3SetOperatorName(int argc, char *argv[]) | ||
685 | { | ||
686 | int i = 0; | ||
687 | unsigned char req[256] = {0x00,0x01,0x8b,0x00, | ||
688 | 0x00,0x00, /* MCC */ | ||
689 | 0x00}; /* MNC */ | ||
690 | |||
691 | GSM_Init(true); | ||
692 | |||
693 | if (strstr(N6110Phone.models, s.Phone.Data.ModelInfo->model) == NULL) Print_Error(ERR_NOTSUPPORTED); | ||
694 | CheckDCT3(); | ||
695 | |||
696 | error=DCT3_EnableSecurity (&s, 0x01); | ||
697 | Print_Error(error); | ||
698 | |||
699 | s.User.UserReplyFunctions=UserReplyFunctions3; | ||
700 | |||
701 | switch (argc) { | ||
702 | case 2: | ||
703 | case 3:NOKIA_EncodeNetworkCode(req+4,"000 00"); | ||
704 | req[7] = 0x00; | ||
705 | i = 1; | ||
706 | break; | ||
707 | case 4: NOKIA_EncodeNetworkCode(req+4,argv[2]); | ||
708 | strncpy(req+7,argv[3],200); | ||
709 | i = strlen(argv[3]); | ||
710 | } | ||
711 | |||
712 | error=GSM_WaitFor (&s, req, 8+i, 0x40, 4, ID_User7); | ||
713 | Print_Error(error); | ||
714 | |||
715 | GSM_Terminate(); | ||
716 | } | ||
717 | |||
718 | static GSM_Error DCT3_ReplyDisplayOutput(GSM_Protocol_Message msg, GSM_StateMachine *s) | ||
719 | { | ||
720 | unsigned char buf[100]; | ||
721 | |||
722 | switch (msg.Buffer[3]) { | ||
723 | case 0x50: | ||
724 | dbgprintf("Display string received\n"); | ||
725 | memcpy(buf,msg.Buffer+8,msg.Buffer[7]*2); | ||
726 | buf[msg.Buffer[7]*2] = 0; | ||
727 | buf[msg.Buffer[7]*2+1] = 0; | ||
728 | printf("X=%i, Y=%i, Text=\"%s\"\n",msg.Buffer[6],msg.Buffer[5],DecodeUnicodeString(buf)); | ||
729 | return ERR_NONE; | ||
730 | case 0x54: | ||
731 | dbgprintf("Display output set\n"); | ||
732 | return ERR_NONE; | ||
733 | } | ||
734 | return ERR_UNKNOWNRESPONSE; | ||
735 | } | ||
736 | |||
737 | void DCT3DisplayOutput(int argc, char *argv[]) | ||
738 | { | ||
739 | unsigned char req[] = {N6110_FRAME_HEADER, 0x53, | ||
740 | 0x01}; //1 = enable, 2 = disable | ||
741 | |||
742 | GSM_Init(true); | ||
743 | |||
744 | if (strstr(N6110Phone.models, s.Phone.Data.ModelInfo->model) == NULL) Print_Error(ERR_NOTSUPPORTED); | ||
745 | CheckDCT3(); | ||
746 | |||
747 | s.User.UserReplyFunctions=UserReplyFunctions3; | ||
748 | |||
749 | error=GSM_WaitFor (&s, req, 5, 0x0d, 4, ID_User7); | ||
750 | Print_Error(error); | ||
751 | |||
752 | signal(SIGINT, interrupt); | ||
753 | printf("Press Ctrl+C to break...\n"); | ||
754 | printf("Entering monitor mode...\n\n"); | ||
755 | |||
756 | while (!gshutdown) { | ||
757 | GSM_ReadDevice(&s,true); | ||
758 | my_sleep(10); | ||
759 | } | ||
760 | |||
761 | req[4] = 0x02; | ||
762 | error=GSM_WaitFor (&s, req, 5, 0x0d, 4, ID_User7); | ||
763 | Print_Error(error); | ||
764 | |||
765 | GSM_Terminate(); | ||
766 | } | ||
767 | #endif | ||
768 | |||
769 | static GSM_Reply_Function UserReplyFunctions3[] = { | ||
770 | {DCT3_ReplyDisplayOutput, "\x0D",0x03,0x50,ID_IncomingFrame}, | ||
771 | {DCT3_ReplyDisplayOutput, "\x0D",0x03,0x54,ID_User7 }, | ||
772 | |||
773 | {DCT3_ReplyEnableSecurity2, "\x40",0x02,0x64,ID_EnableSecurity}, | ||
774 | {DCT3_ReplyResetTest36, "\x40",0x02,0x65,ID_User2 }, | ||
775 | {DCT3_ReplyGetADC, "\x40",0x02,0x68,ID_User3 }, | ||
776 | {DCT3_ReplyGetPPS, "\x40",0x02,0x6A,ID_User4 }, | ||
777 | {DCT3_ReplySetPPS, "\x40",0x02,0x6B,ID_User4 }, | ||
778 | {DCT3_Reply61GetSecurityCode, "\x40",0x02,0x6E,ID_User6 }, | ||
779 | {DCT3_ReplySimlockInfo, "\x40",0x02,0x8A,ID_User3 }, | ||
780 | #ifdef GSM_ENABLE_NOKIA6110 | ||
781 | {DCT3_ReplySetOperatorName, "\x40",0x02,0x8B,ID_User7 }, | ||
782 | {DCT3_ReplyGetOperatorName, "\x40",0x02,0x8C,ID_User5 }, | ||
783 | #endif | ||
784 | {DCT3_ReplyGetADC, "\x40",0x02,0x91,ID_User3 }, | ||
785 | {NoneReply, "\x40",0x02,0xA3,ID_User3 }, | ||
786 | {DCT3_ReplyGetT9, "\x40",0x02,0xAE,ID_User3 }, | ||
787 | {DCT3_ReplyGetMSID, "\x40",0x02,0xb5,ID_User8 }, | ||
788 | {DCT3_ReplyGetDSPROM, "\x40",0x02,0xC8,ID_User10 }, | ||
789 | {DCT3_ReplyGetMCUchkSum, "\x40",0x02,0xC8,ID_User9 }, | ||
790 | {DCT3_ReplyPhoneTests, "\x40",0x02,0xCF,ID_User1 }, | ||
791 | |||
792 | {DCT3_Reply7191GetSecurityCode, "\x7a",0x04,0x1C,ID_User6 }, | ||
793 | |||
794 | {NULL, "\x00",0x00,0x00,ID_None } | ||
795 | }; | ||
796 | |||
797 | #endif | ||
798 | |||
799 | /* How should editor hadle tabs in this file? Add editor commands here. | ||
800 | * vim: noexpandtab sw=8 ts=8 sts=8: | ||
801 | */ | ||