summaryrefslogtreecommitdiffabout
path: root/gammu/emb/common/phone/nokia/dct3/dct3func.c
Unidiff
Diffstat (limited to 'gammu/emb/common/phone/nokia/dct3/dct3func.c') (more/less context) (show whitespace changes)
-rw-r--r--gammu/emb/common/phone/nokia/dct3/dct3func.c1535
1 files changed, 1535 insertions, 0 deletions
diff --git a/gammu/emb/common/phone/nokia/dct3/dct3func.c b/gammu/emb/common/phone/nokia/dct3/dct3func.c
new file mode 100644
index 0000000..beef33c
--- a/dev/null
+++ b/gammu/emb/common/phone/nokia/dct3/dct3func.c
@@ -0,0 +1,1535 @@
1/* (c) 2001-2004 by Marcin Wiacek */
2/* based on some work from Markus Plail, Pavel Janik, others and Gnokii */
3/* resetting DCT4 phones settings (c) by Walek */
4
5#include <string.h> /* memcpy only */
6#include <stdio.h>
7#include <ctype.h>
8
9#include "../../../gsmstate.h"
10#include "../../../misc/coding/coding.h"
11#include "../../../service/sms/gsmsms.h"
12#include "../../pfunc.h"
13#include "../nfunc.h"
14#include "dct3func.h"
15
16#ifdef GSM_ENABLE_NOKIA_DCT3
17
18GSM_Error DCT3_DeleteWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
19{
20 GSM_Error error;
21
22 /* We have to enable WAP frames in phone */
23 error=DCT3DCT4_EnableWAPFunctions(s);
24 if (error!=ERR_NONE) return error;
25
26 return DCT3DCT4_DeleteWAPBookmarkPart(s,bookmark);
27}
28
29GSM_Error DCT3_GetWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
30{
31 GSM_Error error;
32
33 /* We have to enable WAP frames in phone */
34 error=DCT3DCT4_EnableWAPFunctions(s);
35 if (error!=ERR_NONE) return error;
36
37 return DCT3DCT4_GetWAPBookmarkPart(s,bookmark);
38}
39
40GSM_Error DCT3_ReplyPressKey(GSM_Protocol_Message msg, GSM_StateMachine *s)
41{
42 GSM_Phone_Data *Data = &s->Phone.Data;
43
44 switch (msg.Buffer[2]) {
45 case 0x46:
46 smprintf(s, "Pressing key OK\n");
47 if (Data->PressKey) return ERR_NONE;
48 break;
49 case 0x47:
50 smprintf(s, "Releasing key OK\n");
51 if (!Data->PressKey) return ERR_NONE;
52 break;
53 }
54 return ERR_UNKNOWNRESPONSE;
55}
56
57GSM_Error DCT3_PressKey(GSM_StateMachine *s, GSM_KeyCode Key, bool Press)
58{
59 unsigned char PressReq[] = {0x00, 0x01, 0x46, 0x00, 0x01,
60 0x0a}; /* Key code */
61 unsigned char ReleaseReq[] = {0x00, 0x01, 0x47, 0x00, 0x01, 0x0c};
62
63 if (Press) {
64 PressReq[5] = Key;
65 s->Phone.Data.PressKey = true;
66 smprintf(s, "Pressing key\n");
67 return GSM_WaitFor (s, PressReq, 6, 0xd1, 4, ID_PressKey);
68 } else {
69 s->Phone.Data.PressKey = false;
70 smprintf(s, "Releasing key\n");
71 return GSM_WaitFor (s, ReleaseReq, 6, 0xd1, 4, ID_PressKey);
72 }
73}
74
75GSM_Error DCT3_ReplyPlayTone(GSM_Protocol_Message msg, GSM_StateMachine *s)
76{
77 smprintf(s, "Tone played\n");
78 return ERR_NONE;
79}
80
81GSM_Error DCT3_PlayTone(GSM_StateMachine *s, int Herz, unsigned char Volume, bool start)
82{
83 GSM_Error error;
84 unsigned char req[] = {0x00,0x01,0x8f,
85 0x00, /* Volume */
86 0x00, /* HerzLo */
87 0x00}; /* HerzHi */
88
89 if (start) {
90 error=DCT3_EnableSecurity (s, 0x01);
91 if (error!=ERR_NONE) return error;
92 }
93
94 /* For Herz==255*255 we have silent */
95 if (Herz!=255*255) {
96 req[3]=Volume;
97 req[5]=Herz%256;
98 req[4]=Herz/256;
99 } else {
100 req[3]=0;
101 req[5]=0;
102 req[4]=0;
103 }
104
105 return GSM_WaitFor (s, req, 6, 0x40, 4, ID_PlayTone);
106}
107
108#ifdef GSM_ENABLE_CELLBROADCAST
109
110GSM_Error DCT3_ReplyIncomingCB(GSM_Protocol_Message msg, GSM_StateMachine *s)
111{
112 GSM_CBMessage CB;
113 int i;
114 char Buffer[300];
115
116 smprintf(s, "CB received\n");
117 CB.Channel = msg.Buffer[7];
118 i = GSM_UnpackEightBitsToSeven(0, msg.Buffer[9], msg.Buffer[9], msg.Buffer+10, Buffer);
119 i = msg.Buffer[9] - 1;
120 while (i!=0) {
121 if (Buffer[i] == 13) i = i - 1; else break;
122 }
123 DecodeDefault(CB.Text, Buffer, i + 1, false, NULL);
124 smprintf(s, "Channel %i, text \"%s\"\n",CB.Channel,DecodeUnicodeString(CB.Text));
125 if (s->Phone.Data.EnableIncomingCB && s->User.IncomingCB!=NULL) {
126 s->User.IncomingCB(s->CurrentConfig->Device,CB);
127 }
128 return ERR_NONE;
129}
130
131GSM_Error DCT3_ReplySetIncomingCB(GSM_Protocol_Message msg, GSM_StateMachine *s)
132{
133 switch (msg.Buffer[3]) {
134 case 0x21:
135 smprintf(s, "CB set\n");
136 return ERR_NONE;
137 case 0x22:
138 smprintf(s, "CB not set\n");
139 return ERR_UNKNOWN;
140 case 0xCA:
141 smprintf(s, "No network and no CB\n");
142 return ERR_SECURITYERROR;
143 }
144 return ERR_UNKNOWNRESPONSE;
145}
146
147#endif
148
149GSM_Error DCT3_SetIncomingCB(GSM_StateMachine *s, bool enable)
150{
151#ifdef GSM_ENABLE_CELLBROADCAST
152 unsigned char reqOn[] = {N6110_FRAME_HEADER, 0x20, 0x01,
153 0x01, 0x00, 0x00, 0x01, 0x01};
154 unsigned char reqOff[] = {N6110_FRAME_HEADER, 0x20, 0x00,
155 0x00, 0x00, 0x00, 0x00, 0x00};
156
157 if (s->Phone.Data.EnableIncomingCB!=enable) {
158 s->Phone.Data.EnableIncomingCB = enable;
159 if (enable) {
160 smprintf(s, "Enabling incoming CB\n");
161 return GSM_WaitFor(s, reqOn, 10, 0x02, 4, ID_SetIncomingCB);
162 } else {
163 smprintf(s, "Disabling incoming CB\n");
164 return GSM_WaitFor(s, reqOff, 10, 0x02, 4, ID_SetIncomingCB);
165 }
166 }
167 return ERR_NONE;
168#else
169 return ERR_SOURCENOTAVAILABLE;
170#endif
171}
172
173GSM_Error DCT3_ReplySetSMSC(GSM_Protocol_Message msg, GSM_StateMachine *s)
174{
175 smprintf(s, "SMSC set\n");
176 return ERR_NONE;
177}
178
179GSM_Error DCT3_SetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc)
180{
181 unsigned char req[100] = {N6110_FRAME_HEADER, 0x30, 0x64};
182
183 memset(req+6,100-6,0);
184
185 /* SMSC location */
186 req[5] = smsc->Location;
187
188 /* SMSC format */
189 switch (smsc->Format) {
190 case SMS_FORMAT_Text : req[7] = 0x00; break;
191 case SMS_FORMAT_Fax : req[7] = 0x22; break;
192 case SMS_FORMAT_Pager : req[7] = 0x26; break;
193 case SMS_FORMAT_Email : req[7] = 0x32; break;
194 }
195
196 /* SMS validity */
197 req[9] = smsc->Validity.Relative;
198
199 /* Default number for SMS messages */
200 req[10] = GSM_PackSemiOctetNumber(smsc->DefaultNumber, req+11, true);
201
202 /* SMSC number */
203 req[22] = GSM_PackSemiOctetNumber(smsc->Number, req+23, false);
204
205 /* SMSC name */
206 memcpy(req + 34, DecodeUnicodeString(smsc->Name),UnicodeLength(smsc->Name));
207
208 smprintf(s, "Setting SMSC\n");
209 return GSM_WaitFor (s, req, 35+UnicodeLength(smsc->Name), 0x02, 4, ID_SetSMSC);
210}
211
212GSM_Error DCT3_ReplyEnableSecurity(GSM_Protocol_Message msg, GSM_StateMachine *s)
213{
214 smprintf(s, "State of security commands set\n");
215 return ERR_NONE;
216}
217
218/* If you set make some things (for example, change Security Code from
219 * phone's menu, disable and enable phone), it won't answer for 0x40 frames
220 * and you won't be able to play tones, get netmonitor, etc.
221 * This function do thing called "Enabling extended security commands"
222 * and it enables 0x40 frame functions.
223 * This frame can also some other things - see below
224 */
225GSM_Error DCT3_EnableSecurity (GSM_StateMachine *s, unsigned char status)
226{
227 unsigned char req[] = {0x00, 0x01, 0x64,
228 0x01};/* 0x00/0x01 - off/on,
229 * 0x03/0x04 - soft/hard reset,
230 * 0x06 - CONTACT SERVICE
231 */
232
233 /* 0x06 MAKES CONTACT SERVICE! BE CAREFULL! */
234 /* When use 0x03 and had during session changed time & date
235 * some phones (like 6150 or 6210) can ask for time & date after reset
236 * or disable clock on the screen
237 */
238 if (status!=0x06) req[3] = status;
239 smprintf(s, "Setting state of security commands\n");
240 return GSM_WaitFor (s, req, 4, 0x40, 4, ID_EnableSecurity);
241}
242
243GSM_Error DCT3_ReplyGetIMEI(GSM_Protocol_Message msg, GSM_StateMachine *s)
244{
245 memcpy(s->Phone.Data.IMEI,msg.Buffer + 4, 16);
246 smprintf(s, "Received IMEI %s\n",s->Phone.Data.IMEI);
247 return ERR_NONE;
248}
249
250GSM_Error DCT3_GetIMEI (GSM_StateMachine *s)
251{
252 unsigned char req[] = {0x00, 0x01, 0x66, 0x00};
253 GSM_Error error;
254
255 if (strlen(s->Phone.Data.IMEI)!=0) return ERR_NONE;
256
257 error=DCT3_EnableSecurity (s, 0x01);
258 if (error!=ERR_NONE) return error;
259
260 smprintf(s, "Getting IMEI\n");
261 return GSM_WaitFor (s, req, 4, 0x40, 2, ID_GetIMEI);
262}
263
264GSM_Error DCT3_ReplySIMLogin(GSM_Protocol_Message msg, GSM_StateMachine *s)
265{
266 smprintf(s, "Login for SIM card\n");
267 return ERR_NONE;
268}
269
270GSM_Error DCT3_ReplySIMLogout(GSM_Protocol_Message msg, GSM_StateMachine *s)
271{
272 smprintf(s, "Logout for SIM card\n");
273 return ERR_NONE;
274}
275
276GSM_Error DCT3_ReplyGetDateTime(GSM_Protocol_Message msg, GSM_StateMachine *s)
277{
278 smprintf(s, "Date & time received\n");
279 if (msg.Buffer[4]==0x01) {
280 NOKIA_DecodeDateTime(s, msg.Buffer+8, s->Phone.Data.DateTime);
281 return ERR_NONE;
282 }
283 smprintf(s, "Not set in phone\n");
284 return ERR_EMPTY;
285}
286
287GSM_Error DCT3_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time, unsigned char msgtype)
288{
289 unsigned char req[] = {N6110_FRAME_HEADER, 0x62};
290
291 s->Phone.Data.DateTime=date_time;
292 smprintf(s, "Getting date & time\n");
293 return GSM_WaitFor (s, req, 4, msgtype, 4, ID_GetDateTime);
294}
295
296GSM_Error DCT3_ReplyGetAlarm(GSM_Protocol_Message msg, GSM_StateMachine *s)
297{
298 GSM_Phone_Data*Data = &s->Phone.Data;
299
300 smprintf(s, "Alarm: ");
301 if (msg.Buffer[8]==0x02) {
302 smprintf(s, "set to %02i:%02i\n", msg.Buffer[9], msg.Buffer[10]);
303 Data->Alarm->Repeating = true;
304 Data->Alarm->Text[0] = 0;
305 Data->Alarm->Text[1] = 0;
306 Data->Alarm->DateTime.Hour= msg.Buffer[9];
307 Data->Alarm->DateTime.Minute= msg.Buffer[10];
308 Data->Alarm->DateTime.Second= 0;
309 return ERR_NONE;
310 }
311 smprintf(s, "not set\n");
312 return ERR_EMPTY;
313}
314
315GSM_Error DCT3_GetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm, unsigned char msgtype)
316{
317 unsigned char req[] = {N6110_FRAME_HEADER, 0x6d};
318
319 if (alarm->Location!=1) return ERR_NOTSUPPORTED;
320
321 s->Phone.Data.Alarm=alarm;
322 smprintf(s, "Getting alarm\n");
323 return GSM_WaitFor (s, req, 4, msgtype, 4, ID_GetAlarm);
324}
325
326GSM_Error DCT3_ReplySetDateTime(GSM_Protocol_Message msg, GSM_StateMachine *s)
327{
328 smprintf(s, "Date & time: ");
329 if (msg.Buffer[4]==0x01) {
330 smprintf(s, "set OK\n");
331 return ERR_NONE;
332 }
333 smprintf(s, "error setting\n");
334 return ERR_UNKNOWN;
335}
336
337GSM_Error DCT3_SetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time, unsigned char msgtype)
338{
339 unsigned char req[] = {N6110_FRAME_HEADER, 0x60, 0x01, 0x01, 0x07,
340 0x00, 0x00, /* Year */
341 0x00, /* Month */
342 0x00, /* Day */
343 0x00, /* Hour */
344 0x00, /* Minute */
345 0x00}; /* Unknown. Not seconds */
346
347 NOKIA_EncodeDateTime(s, req+7, date_time);
348 smprintf(s, "Setting date & time\n");
349 return GSM_WaitFor (s, req, 14, msgtype, 4, ID_SetDateTime);
350}
351
352GSM_Error DCT3_ReplySetAlarm(GSM_Protocol_Message msg, GSM_StateMachine *s)
353{
354 smprintf(s, "Alarm: ");
355 if (msg.Buffer[4]==0x01) {
356 smprintf(s, "set OK\n");
357 return ERR_NONE;
358 }
359 smprintf(s, "error setting\n");
360 return ERR_UNKNOWN;
361}
362
363GSM_Error DCT3_SetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm, unsigned char msgtype)
364{
365 unsigned char req[] = {N6110_FRAME_HEADER, 0x6b, 0x01, 0x20, 0x03,
366 0x02, /* Unknown. Not for enabling/disabling */
367 0x00, /* Hour */
368 0x00, /* Minute */
369 0x00}; /* Unknown. Not seconds */
370
371 if (alarm->Location != 1) return ERR_NOTSUPPORTED;
372
373 req[8] = alarm->DateTime.Hour;
374 req[9] = alarm->DateTime.Minute;
375
376 smprintf(s, "Setting alarm\n");
377 return GSM_WaitFor (s, req, 11, msgtype, 4, ID_SetAlarm);
378}
379
380GSM_Error DCT3_ReplyGetSMSC(GSM_Protocol_Message msg, GSM_StateMachine *s)
381{
382 int i;
383 GSM_Phone_Data*Data = &s->Phone.Data;
384
385 switch (msg.Buffer[3]) {
386 case 0x34:
387 smprintf(s, "SMSC received\n");
388 Data->SMSC->Format = SMS_FORMAT_Text;
389 switch (msg.Buffer[6]) {
390 case 0x00: Data->SMSC->Format = SMS_FORMAT_Text; break;
391 case 0x22: Data->SMSC->Format = SMS_FORMAT_Fax; break;
392 case 0x26: Data->SMSC->Format = SMS_FORMAT_Pager;break;
393 case 0x32: Data->SMSC->Format = SMS_FORMAT_Email;break;
394 }
395 Data->SMSC->Validity.Format = SMS_Validity_RelativeFormat;
396 Data->SMSC->Validity.Relative= msg.Buffer[8];
397
398 i=33;
399 while (msg.Buffer[i]!=0) {i++;}
400 i=i-33;
401 if (i>GSM_MAX_SMSC_NAME_LENGTH) {
402 smprintf(s, "Too long name\n");
403 return ERR_UNKNOWNRESPONSE;
404 }
405 EncodeUnicode(Data->SMSC->Name,msg.Buffer+33,i);
406 smprintf(s, "Name \"%s\"\n", DecodeUnicodeString(Data->SMSC->Name));
407
408 GSM_UnpackSemiOctetNumber(Data->SMSC->DefaultNumber,msg.Buffer+9,true);
409 smprintf(s, "Default number \"%s\"\n", DecodeUnicodeString(Data->SMSC->DefaultNumber));
410
411 GSM_UnpackSemiOctetNumber(Data->SMSC->Number,msg.Buffer+21,false);
412 smprintf(s, "Number \"%s\"\n", DecodeUnicodeString(Data->SMSC->Number));
413
414 return ERR_NONE;
415 case 0x35:
416 smprintf(s, "Getting SMSC failed\n");
417 return ERR_INVALIDLOCATION;
418 }
419 return ERR_UNKNOWNRESPONSE;
420}
421
422GSM_Error DCT3_GetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc)
423{
424 unsigned char req[] = {N6110_FRAME_HEADER, 0x33, 0x64,
425 0x00}; /* Location */
426
427 if (smsc->Location==0x00) return ERR_INVALIDLOCATION;
428
429 req[5]=smsc->Location;
430
431 s->Phone.Data.SMSC=smsc;
432 smprintf(s, "Getting SMSC\n");
433 return GSM_WaitFor (s, req, 6, 0x02, 4, ID_GetSMSC);
434}
435
436GSM_Error DCT3_ReplyGetNetworkInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
437{
438 int count;
439 GSM_Phone_Data*Data = &s->Phone.Data;
440#ifdef DEBUG
441 GSM_NetworkInfo NetInfo;
442 char name[100];
443
444 smprintf(s, "Network info received\n");
445 smprintf(s, " Status : ");
446 switch (msg.Buffer[8]) {
447 case 0x01: smprintf(s, "home network"); break;
448 case 0x02: smprintf(s, "roaming network"); break;
449 case 0x03: smprintf(s, "requesting network"); break;
450 case 0x04: smprintf(s, "not registered in the network");break;
451 default : smprintf(s, "unknown");
452 }
453 smprintf(s, "\n");
454 smprintf(s, "Network selection : %s\n", msg.Buffer[9]==1?"manual":"automatic");
455 if (msg.Buffer[8]<0x03) {
456 sprintf(NetInfo.CID, "%02x%02x", msg.Buffer[10], msg.Buffer[11]);
457 smprintf(s, "CID : %s\n", NetInfo.CID);
458
459 sprintf(NetInfo.LAC, "%02x%02x", msg.Buffer[12], msg.Buffer[13]);
460 smprintf(s, "LAC : %s\n", NetInfo.LAC);
461
462 smprintf(s, "Network code : %s\n", NetInfo.NetworkCode);
463 NOKIA_DecodeNetworkCode(msg.Buffer+14,NetInfo.NetworkCode);
464 smprintf(s, "Network name for Gammu : %s ",
465 DecodeUnicodeString(GSM_GetNetworkName(NetInfo.NetworkCode)));
466 smprintf(s, "(%s)\n",DecodeUnicodeString(GSM_GetCountryName(NetInfo.NetworkCode)));
467
468 if (msg.Length>18) {
469 if (msg.Buffer[18]==0x00) {
470 /* In 6210 name is in "normal" Unicode */
471 memcpy(name,msg.Buffer+18,msg.Buffer[17]*2);
472 name[msg.Buffer[17]*2]=0x00;
473 name[msg.Buffer[17]*2+1]=0x00;
474 smprintf(s, "Network name for phone : %s\n",DecodeUnicodeString(name));
475 } else {
476 /* In 9210 first 0x00 is cut from Unicode string */
477 name[0] = 0;
478 memcpy(name+1,msg.Buffer+18,msg.Buffer[17]*2);
479 name[msg.Buffer[17]*2+1]=0x00;
480 name[msg.Buffer[17]*2+2]=0x00;
481 smprintf(s, "Network name for phone : %s\n",DecodeUnicodeString(name));
482 }
483 }
484 }
485#endif
486 if (Data->RequestID==ID_GetNetworkInfo) {
487 Data->NetworkInfo->NetworkName[0] = 0x00;
488 Data->NetworkInfo->NetworkName[1] = 0x00;
489 Data->NetworkInfo->State = 0;
490 switch (msg.Buffer[8]) {
491 case 0x01: Data->NetworkInfo->State = GSM_HomeNetwork; break;
492 case 0x02: Data->NetworkInfo->State = GSM_RoamingNetwork;break;
493 case 0x03: Data->NetworkInfo->State = GSM_RequestingNetwork;break;
494 case 0x04: Data->NetworkInfo->State = GSM_NoNetwork; break;
495 }
496 if (Data->NetworkInfo->State == GSM_HomeNetwork || Data->NetworkInfo->State == GSM_RoamingNetwork) {
497 if (msg.Buffer[18]==0x00) {
498 /* In 6210 name is in "normal" Unicode */
499 memcpy(Data->NetworkInfo->NetworkName,msg.Buffer+18,msg.Buffer[17]*2);
500 Data->NetworkInfo->NetworkName[msg.Buffer[17]*2] = 0x00;
501 Data->NetworkInfo->NetworkName[msg.Buffer[17]*2+1] = 0x00;
502 } else {
503 /* In 9210 first 0x00 is cut from Unicode string */
504 Data->NetworkInfo->NetworkName[0] = 0;
505 memcpy(Data->NetworkInfo->NetworkName+1,msg.Buffer+18,msg.Buffer[17]*2);
506 Data->NetworkInfo->NetworkName[msg.Buffer[17]*2+1]=0x00;
507 Data->NetworkInfo->NetworkName[msg.Buffer[17]*2+2]=0x00;
508 }
509 NOKIA_DecodeNetworkCode(msg.Buffer+14,Data->NetworkInfo->NetworkCode);
510 sprintf(Data->NetworkInfo->CID, "%02x%02x", msg.Buffer[10], msg.Buffer[11]);
511 sprintf(Data->NetworkInfo->LAC, "%02x%02x", msg.Buffer[12], msg.Buffer[13]);
512 }
513 }
514 /* 6210/6250/7110 */
515 if (Data->RequestID==ID_GetBitmap) {
516 if (msg.Buffer[4]==0x02) {
517 smprintf(s, "Operator logo available\n");
518 count = 7;
519 /* skip network info */
520 count += msg.Buffer[count];
521 count ++;
522 Data->Bitmap->BitmapWidth= msg.Buffer[count++];
523 Data->Bitmap->BitmapHeight= msg.Buffer[count++];
524 count+=4;
525 PHONE_DecodeBitmap(GSM_Nokia7110OperatorLogo,msg.Buffer+count,Data->Bitmap);
526 NOKIA_DecodeNetworkCode(msg.Buffer+14,Data->Bitmap->NetworkCode);
527 } else {
528 Data->Bitmap->BitmapWidth= 78;
529 Data->Bitmap->BitmapHeight= 21;
530 GSM_ClearBitmap(Data->Bitmap);
531 strcpy(Data->Bitmap->NetworkCode,"000 00");
532 }
533 }
534 return ERR_NONE;
535}
536
537GSM_Error DCT3_GetNetworkInfo(GSM_StateMachine *s, GSM_NetworkInfo *netinfo)
538{
539 unsigned char req[] = {N6110_FRAME_HEADER, 0x70};
540
541 s->Phone.Data.NetworkInfo=netinfo;
542 smprintf(s, "Getting network info\n");
543 return GSM_WaitFor (s, req, 4, 0x0a, 4, ID_GetNetworkInfo);
544}
545
546GSM_Error DCT3_ReplyDialCommand(GSM_Protocol_Message msg, GSM_StateMachine *s)
547{
548 smprintf(s, "Answer for call commands\n");
549 return ERR_NONE;
550}
551
552GSM_Error DCT3_DialVoice(GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber)
553{
554 unsigned inti = 0;
555 GSM_Errorerror;
556 unsigned char req[100] = {0x00, 0x01, 0x7c,
557 0x01}; /* call command */
558
559 if (ShowNumber != GSM_CALL_DefaultNumberPresence) return ERR_NOTSUPPORTED;
560
561 error=DCT3_EnableSecurity (s, 0x01);
562 if (error!=ERR_NONE) return error;
563
564 for (i=0; i < strlen(number); i++) req[4+i]=number[i];
565 req[4+i+1]=0;
566
567 smprintf(s, "Making voice call\n");
568 return GSM_WaitFor (s, req, 4+strlen(number)+1, 0x40, 4, ID_DialVoice);
569}
570
571static GSM_Error DCT3_CancelAllCalls(GSM_StateMachine *s)
572{
573 GSM_Errorerror;
574 unsigned char req[] = {0x00, 0x01, 0x7c,
575 0x03}; /* call command */
576
577 error=DCT3_EnableSecurity (s, 0x01);
578 if (error!=ERR_NONE) return error;
579
580 smprintf(s, "Canceling calls\n");
581 return GSM_WaitFor (s, req, 4, 0x40, 4, ID_CancelCall);
582}
583
584GSM_Error DCT3_CancelCall(GSM_StateMachine *s, int ID, bool all)
585{
586 if (!all) return DCT3DCT4_CancelCall(s,ID);
587 return DCT3_CancelAllCalls(s);
588}
589
590GSM_Error DCT3_AnswerAllCalls(GSM_StateMachine *s)
591{
592 GSM_Errorerror;
593 unsigned char req[] = {0x00, 0x01, 0x7c,
594 0x02}; /* call command */
595
596 error=DCT3_EnableSecurity (s, 0x01);
597 if (error!=ERR_NONE) return error;
598
599 smprintf(s, "Answering calls\n");
600 return GSM_WaitFor (s, req, 4, 0x40, 4, ID_AnswerCall);
601}
602
603GSM_Error DCT3_Reset(GSM_StateMachine *s, bool hard)
604{
605 GSM_Error error;
606
607 if (hard) {
608 error=DCT3_EnableSecurity(s, 0x04);
609 } else {
610 error=DCT3_EnableSecurity(s, 0x03);
611 }
612 if (error == ERR_NONE) {
613 s->Phone.Data.EnableIncomingSMS = false;
614 s->Phone.Data.EnableIncomingCB = false;
615 }
616 return error;
617}
618
619GSM_Error DCT3_ReplyGetWAPBookmark(GSM_Protocol_Message msg, GSM_StateMachine *s)
620{
621 return DCT3DCT4_ReplyGetWAPBookmark (msg,s,false);
622}
623
624GSM_Error DCT3_SetWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
625{
626 GSM_Error error;
627 int count = 4, location;
628 unsigned char req[600] = {N6110_FRAME_HEADER, 0x09};
629
630 /* We have to enable WAP frames in phone */
631 error=DCT3DCT4_EnableWAPFunctions(s);
632 if (error!=ERR_NONE) return error;
633
634 location = bookmark->Location - 1;
635 if (bookmark->Location == 0) location = 0xffff;
636 req[count++] = (location & 0xff00) >> 8;
637 req[count++] = location & 0x00ff;
638
639 count += NOKIA_SetUnicodeString(s, req+count, bookmark->Title, false);
640 count += NOKIA_SetUnicodeString(s, req+count, bookmark->Address, false);
641
642 /* unknown */
643 req[count++] = 0x01; req[count++] = 0x80; req[count++] = 0x00;
644 req[count++] = 0x00; req[count++] = 0x00; req[count++] = 0x00;
645 req[count++] = 0x00; req[count++] = 0x00; req[count++] = 0x00;
646
647 smprintf(s, "Setting WAP bookmark\n");
648 error = GSM_WaitFor (s, req, count, 0x3f, 4, ID_SetWAPBookmark);
649 if (error != ERR_NONE) {
650 if (error == ERR_INSIDEPHONEMENU || error == ERR_EMPTY || error == ERR_FULL) {
651 DCT3DCT4_DisableConnectionFunctions(s);
652 }
653 return error;
654 }
655
656 return DCT3DCT4_DisableConnectionFunctions(s);
657}
658
659GSM_Error DCT3_ReplyGetWAPSettings(GSM_Protocol_Message msg, GSM_StateMachine *s)
660{
661 int tmp,Number;
662 // int tmp2;
663 GSM_Phone_Data *Data = &s->Phone.Data;
664#ifdef GSM_ENABLE_NOKIA6110
665 GSM_Phone_N6110Data *Priv6110 = &s->Phone.Data.Priv.N6110;
666#endif
667#ifdef GSM_ENABLE_NOKIA7110
668 GSM_Phone_N7110Data *Priv7110 = &s->Phone.Data.Priv.N7110;
669#endif
670
671 switch(msg.Buffer[3]) {
672 case 0x16:
673 smprintf(s, "WAP settings part 1 received OK\n");
674
675 tmp = 4;
676
677 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[0].Title,false);
678 smprintf(s, "Title: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[0].Title));
679
680 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[0].HomePage,false);
681 smprintf(s, "Homepage: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[0].HomePage));
682#ifdef DEBUG
683 smprintf(s, "Connection type: ");
684 switch (msg.Buffer[tmp]) {
685 case 0x00: smprintf(s, "temporary\n"); break;
686 case 0x01: smprintf(s, "continuous\n"); break;
687 default: smprintf(s, "unknown\n");
688 }
689 smprintf(s, "Connection security: ");
690 switch (msg.Buffer[tmp+13]) {
691 case 0x00: smprintf(s, "off\n");break;
692 case 0x01: smprintf(s, "on\n"); break;
693 default: smprintf(s, "unknown\n");
694 }
695#endif
696 Data->WAPSettings->Settings[0].IsContinuous = false;
697 if (msg.Buffer[tmp] == 0x01) Data->WAPSettings->Settings[0].IsContinuous = true;
698 Data->WAPSettings->Settings[0].IsSecurity = false;
699 if (msg.Buffer[tmp+13] == 0x01) Data->WAPSettings->Settings[0].IsSecurity = true;
700
701 /* I'm not sure here. Experimental values from 6210 5.56 */
702 // tmp2 = DecodeUnicodeLength(Data->WAPSettings->Settings[0].Title);
703 // if (tmp2 != 0) tmp2 --;
704 // tmp2 += tmp;
705 if (!(UnicodeLength(Data->WAPSettings->Settings[0].Title)) % 2) tmp++;
706 if (UnicodeLength(Data->WAPSettings->Settings[0].HomePage)!=0) tmp++;
707
708 smprintf(s, "ID for writing %i\n",msg.Buffer[tmp+5]);
709
710 smprintf(s, "Current set location in phone %i\n",msg.Buffer[tmp+6]);
711
712 smprintf(s, "1 location %i\n",msg.Buffer[tmp+8]);
713 smprintf(s, "2 location %i\n",msg.Buffer[tmp+9]);
714 smprintf(s, "3 location %i\n",msg.Buffer[tmp+10]);
715 smprintf(s, "4 location %i\n",msg.Buffer[tmp+11]);
716#ifdef GSM_ENABLE_NOKIA7110
717 if (strstr(N7110Phone.models, Data->ModelInfo->model) != NULL) {
718 Priv7110->WAPLocations.ID = msg.Buffer[tmp+5];
719 Priv7110->WAPLocations.CurrentLocation= msg.Buffer[tmp+6];
720 Priv7110->WAPLocations.Locations[0] = msg.Buffer[tmp+8];
721 Priv7110->WAPLocations.Locations[1] = msg.Buffer[tmp+9];
722 Priv7110->WAPLocations.Locations[2] = msg.Buffer[tmp+10];
723 Priv7110->WAPLocations.Locations[3] = msg.Buffer[tmp+11];
724
725 // Priv7110->WAPLocations.CurrentLocation= msg.Buffer[tmp2+1];
726 // Priv7110->WAPLocations.Locations[0] = msg.Buffer[tmp2+3];
727 // Priv7110->WAPLocations.Locations[1] = msg.Buffer[tmp2+4];
728 // Priv7110->WAPLocations.Locations[2] = msg.Buffer[tmp2+5];
729 // Priv7110->WAPLocations.Locations[3] = msg.Buffer[tmp2+6];
730 }
731#endif
732#ifdef GSM_ENABLE_NOKIA6110
733 if (strstr(N6110Phone.models, Data->ModelInfo->model) != NULL) {
734 Priv6110->WAPLocations.ID = msg.Buffer[tmp+5];
735 Priv6110->WAPLocations.CurrentLocation= msg.Buffer[tmp+6];
736 Priv6110->WAPLocations.Locations[0] = msg.Buffer[tmp+8];
737 Priv6110->WAPLocations.Locations[1] = msg.Buffer[tmp+9];
738 Priv6110->WAPLocations.Locations[2] = msg.Buffer[tmp+10];
739 Priv6110->WAPLocations.Locations[3] = msg.Buffer[tmp+11];
740 }
741#endif
742 return ERR_NONE;
743 case 0x17:
744 smprintf(s, "WAP settings part 1 receiving error\n");
745 switch (msg.Buffer[4]) {
746 case 0x01:
747 smprintf(s, "Security error. Inside WAP settings menu\n");
748 return ERR_INSIDEPHONEMENU;
749 case 0x02:
750 smprintf(s, "Invalid or empty\n");
751 return ERR_INVALIDLOCATION;
752 default:
753 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]);
754 return ERR_UNKNOWNRESPONSE;
755 }
756 break;
757 case 0x1c:
758 smprintf(s, "WAP settings part 2 received OK\n");
759 Number = Data->WAPSettings->Number;
760 switch (msg.Buffer[5]) {
761 case 0x00:
762 Data->WAPSettings->Settings[Number].Bearer = WAPSETTINGS_BEARER_SMS;
763 smprintf(s, "Settings for SMS bearer:\n");
764 tmp = 6;
765
766 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[Number].Service,false);
767 smprintf(s, "Service number: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].Service));
768
769 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[Number].Server,false);
770 smprintf(s, "Server number: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].Server));
771 break;
772 case 0x01:
773 Data->WAPSettings->Settings[Number].Bearer = WAPSETTINGS_BEARER_DATA;
774 smprintf(s, "Settings for data bearer:\n");
775 Data->WAPSettings->Settings[Number].ManualLogin = false;
776 tmp = 10;
777
778 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[Number].IPAddress,false);
779 smprintf(s, "IP address: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].IPAddress));
780
781 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[Number].DialUp,false);
782 smprintf(s, "Dial-up number: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].DialUp));
783
784 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[Number].User,false);
785 smprintf(s, "User name: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].User));
786
787 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[Number].Password,false);
788 smprintf(s, "Password: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].Password));
789#ifdef DEBUG
790 smprintf(s, "Authentication type: ");
791 switch (msg.Buffer[6]) {
792 case 0x00: smprintf(s, "normal\n"); break;
793 case 0x01: smprintf(s, "secure\n"); break;
794 default: smprintf(s, "unknown\n"); break;
795 }
796 smprintf(s, "Data call type: ");
797 switch (msg.Buffer[7]) {
798 case 0x00: smprintf(s, "analogue\n"); break;
799 case 0x01: smprintf(s, "ISDN\n"); break;
800 default: smprintf(s, "unknown\n"); break;
801 }
802 smprintf(s, "Data call speed: ");
803 switch (msg.Buffer[9]) {
804 case 0x01: smprintf(s, "9600\n"); break;
805 case 0x02: smprintf(s, "14400\n"); break;
806 default: smprintf(s, "unknown\n"); break;
807 }
808#endif
809 Data->WAPSettings->Settings[Number].IsNormalAuthentication=true;
810 if (msg.Buffer[6]==0x01) Data->WAPSettings->Settings[Number].IsNormalAuthentication=false;
811 Data->WAPSettings->Settings[Number].IsISDNCall=false;
812 if (msg.Buffer[7]==0x01) Data->WAPSettings->Settings[Number].IsISDNCall=true;
813 Data->WAPSettings->Settings[Number].Speed = WAPSETTINGS_SPEED_9600;
814 if (msg.Buffer[9]==0x02) Data->WAPSettings->Settings[Number].Speed = WAPSETTINGS_SPEED_14400;
815 break;
816 case 0x02:
817 Data->WAPSettings->Settings[Number].Bearer=WAPSETTINGS_BEARER_USSD;
818 smprintf(s, "Settings for USSD bearer:\n");
819 tmp = 7;
820 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[Number].Service,false);
821#ifdef DEBUG
822 if (msg.Buffer[6]==0x01)
823 smprintf(s, "Service number: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].Service));
824 else
825 smprintf(s, "IP address: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].Service));
826#endif
827 Data->WAPSettings->Settings[Number].IsIP=true;
828 if (msg.Buffer[6]==0x01) Data->WAPSettings->Settings[Number].IsIP=false;
829 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[Number].Code,false);
830 smprintf(s, "Service code: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].Code));
831 }
832 Data->WAPSettings->Number++;
833 return ERR_NONE;
834 case 0x1d:
835 smprintf(s, "Incorrect WAP settings location\n");
836 return ERR_NONE;
837 }
838 return ERR_UNKNOWNRESPONSE;
839}
840
841GSM_Error DCT3_GetWAPSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings)
842{
843#ifdef GSM_ENABLE_NOKIA6110
844 GSM_Phone_N6110Data *Priv6110 = &s->Phone.Data.Priv.N6110;
845#endif
846#ifdef GSM_ENABLE_NOKIA7110
847 GSM_Phone_N7110Data *Priv7110 = &s->Phone.Data.Priv.N7110;
848#endif
849 GSM_Error error;
850 int i;
851 unsigned char req[] = {N6110_FRAME_HEADER,0x15,
852 0x00}; /* Location */
853 unsigned char req2[] = {N6110_FRAME_HEADER,0x1b,
854 0x00}; /* Location */
855
856 /* We have to enable WAP frames in phone */
857 error=DCT3DCT4_EnableWAPFunctions(s);
858 if (error!=ERR_NONE) return error;
859
860 s->Phone.Data.WAPSettings = settings;
861 settings->Number = 0;
862 settings->ReadOnly = false;
863
864 req[4] = settings->Location-1;
865 smprintf(s, "Getting WAP settings part 1\n");
866 error = GSM_WaitFor (s, req, 5, 0x3f, 4, ID_GetConnectSet);
867 if (error != ERR_NONE) return error;
868
869#ifdef GSM_ENABLE_NOKIA7110
870 if (strstr(N7110Phone.models, s->Phone.Data.ModelInfo->model) != NULL) {
871 for (i=0;i<4;i++) {
872 req2[4] = Priv7110->WAPLocations.Locations[i];
873 smprintf(s, "Getting WAP settings part 2\n");
874 error=GSM_WaitFor (s, req2, 5, 0x3f, 4, ID_GetConnectSet);
875 if (error != ERR_NONE) return error;
876 if (Priv7110->WAPLocations.Locations[i] == Priv7110->WAPLocations.CurrentLocation) {
877 settings->ActiveBearer = settings->Settings[settings->Number-1].Bearer;
878 }
879 }
880 }
881#endif
882#ifdef GSM_ENABLE_NOKIA6110
883 if (strstr(N6110Phone.models, s->Phone.Data.ModelInfo->model) != NULL) {
884 for (i=0;i<4;i++) {
885 req2[4] = Priv6110->WAPLocations.Locations[i];
886 smprintf(s, "Getting WAP settings part 2\n");
887 error=GSM_WaitFor (s, req2, 5, 0x3f, 4, ID_GetConnectSet);
888 if (error != ERR_NONE) return error;
889 if (Priv6110->WAPLocations.Locations[i] == Priv6110->WAPLocations.CurrentLocation) {
890 settings->ActiveBearer = settings->Settings[settings->Number-1].Bearer;
891 }
892 }
893 }
894#endif
895 if (error == ERR_NONE) {
896 for (i=1;i<3;i++) {
897 CopyUnicodeString(settings->Settings[i].Title,settings->Settings[0].Title);
898 CopyUnicodeString(settings->Settings[i].HomePage,settings->Settings[0].HomePage);
899 settings->Settings[i].IsContinuous = settings->Settings[0].IsContinuous;
900 settings->Settings[i].IsSecurity = settings->Settings[0].IsSecurity;
901
902 settings->Settings[i].IsContinuous = settings->Settings[0].IsContinuous;
903 settings->Settings[i].IsSecurity = settings->Settings[0].IsSecurity;
904 }
905 error = DCT3DCT4_GetActiveConnectSet(s);
906 }
907 if (error != ERR_NONE) return error;
908
909 settings->Proxy[0] = 0x00;
910 settings->Proxy[1] = 0x00;
911 settings->ProxyPort = 8080;
912
913 settings->Proxy2[0] = 0x00;
914 settings->Proxy2[1] = 0x00;
915 settings->Proxy2Port = 8080;
916
917 return DCT3DCT4_DisableConnectionFunctions(s);
918}
919
920GSM_Error DCT3_ReplySetWAPSettings(GSM_Protocol_Message msg, GSM_StateMachine *s)
921{
922 switch(msg.Buffer[3]) {
923 case 0x19:
924 smprintf(s, "WAP settings part 1 set OK\n");
925 return ERR_NONE;
926 case 0x1a:
927 smprintf(s, "WAP settings part 1 setting error\n");
928 switch (msg.Buffer[4]) {
929 case 0x01:
930 smprintf(s, "Security error. Inside WAP settings menu\n");
931 return ERR_INSIDEPHONEMENU;
932 case 0x02:
933 smprintf(s, "Incorrect data\n");
934 return ERR_UNKNOWN;
935 default:
936 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]);
937 return ERR_UNKNOWNRESPONSE;
938 }
939 case 0x1F:
940 smprintf(s, "WAP settings part 2 set OK\n");
941 return ERR_NONE;
942 }
943 return ERR_UNKNOWNRESPONSE;
944}
945
946GSM_Error DCT3_SetWAPSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings)
947{
948#ifdef GSM_ENABLE_NOKIA6110
949 GSM_Phone_N6110Data *Priv6110 = &s->Phone.Data.Priv.N6110;
950#endif
951#ifdef GSM_ENABLE_NOKIA7110
952 GSM_Phone_N7110Data *Priv7110 = &s->Phone.Data.Priv.N7110;
953#endif
954 GSM_Error error;
955 GSM_MultiWAPSettingssettings2;
956 int i,pos,phone1=-1,phone2=-1,phone3=-1;
957 int ID=0,locations[4],loc1=-1,loc2=-1,loc3=-1;
958 unsigned char req[] = {N6110_FRAME_HEADER,0x15,
959 0x00};/* Location */
960 unsigned char req2[] = {N6110_FRAME_HEADER,0x1b,
961 0x00};/* Location */
962 unsigned char SetReq[200] = {N7110_FRAME_HEADER, 0x18,
963 0x00}; /* Location */
964 unsigned char SetReq2[200] = {N7110_FRAME_HEADER, 0x1e,
965 0x00}; /* Location */
966
967 /* We have to enable WAP frames in phone */
968 error=DCT3DCT4_EnableWAPFunctions(s);
969 if (error!=ERR_NONE) return error;
970
971 s->Phone.Data.WAPSettings = &settings2;
972 settings2.Number = 0;
973
974 req[4] = settings->Location-1;
975 smprintf(s, "Getting WAP settings part 1\n");
976 error = GSM_WaitFor (s, req, 6, 0x3f, 4, ID_GetConnectSet);
977 if (error != ERR_NONE) return error;
978
979#ifdef GSM_ENABLE_NOKIA6110
980 if (strstr(N6110Phone.models, s->Phone.Data.ModelInfo->model) != NULL) {
981 for (i=0;i<4;i++) locations[i] = Priv6110->WAPLocations.Locations[i];
982 ID = Priv6110->WAPLocations.ID;
983 }
984#endif
985#ifdef GSM_ENABLE_NOKIA7110
986 if (strstr(N7110Phone.models, s->Phone.Data.ModelInfo->model) != NULL) {
987 for (i=0;i<4;i++) locations[i] = Priv7110->WAPLocations.Locations[i];
988 ID = Priv7110->WAPLocations.ID;
989 }
990#endif
991
992 /* Now we get info about supported types by phone and their locations */
993 for (i=0;i<4;i++) {
994 settings2.Number = 0;
995 settings2.Settings[0].Bearer = 0;
996 req2[4] = locations[i];
997 smprintf(s, "Getting WAP settings part 2\n");
998 error=GSM_WaitFor (s, req2, 6, 0x3f, 4, ID_GetConnectSet);
999 if (error != ERR_NONE) return error;
1000 switch (settings2.Settings[0].Bearer) {
1001 case WAPSETTINGS_BEARER_DATA: phone1 = locations[i]; break;
1002 case WAPSETTINGS_BEARER_SMS : phone2 = locations[i]; break;
1003 case WAPSETTINGS_BEARER_USSD: phone3 = locations[i]; break;
1004 default : break;
1005 }
1006 if (error != ERR_NONE) return error;
1007 }
1008
1009 /* We have some phone locations and some data to set. We try to
1010 * find info about locations in phone used to write concrete bearers
1011 */
1012 for (i=0;i<settings->Number;i++) {
1013 if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_DATA) {
1014 if (phone1 != -1) loc1=i;
1015 }
1016 if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_SMS) {
1017 if (phone2 != -1) loc2=i;
1018 }
1019 if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_USSD) {
1020 if (phone3 != -1) loc3=i;
1021 }
1022 }
1023
1024 pos = 5;
1025 memset(SetReq + pos, 0, 200 - pos);
1026 SetReq[4] = settings->Location - 1;
1027 if (loc1 != -1) {
1028 /* Name */
1029 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc1].Title, false);
1030 /* HomePage */
1031 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc1].HomePage, false);
1032 if (settings->Settings[loc1].IsContinuous) SetReq[pos] = 0x01;
1033 pos++;
1034 SetReq[pos++] = ID;
1035
1036 SetReq[pos] = phone1; /* bearer */
1037 switch (settings->ActiveBearer) {
1038 case WAPSETTINGS_BEARER_DATA:
1039 if (loc1 != -1) SetReq[pos] = phone1;
1040 break;
1041 case WAPSETTINGS_BEARER_SMS:
1042 if (loc2 != -1) SetReq[pos] = phone2;
1043 break;
1044 case WAPSETTINGS_BEARER_USSD:
1045 if (loc3 != -1) SetReq[pos] = phone3;
1046 break;
1047 default: break;
1048 }
1049 pos++;
1050
1051 if (settings->Settings[loc1].IsSecurity) SetReq[pos] = 0x01;
1052 pos++;
1053 } else if (loc2 != -1) {
1054 /* Name */
1055 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc2].Title, false);
1056 /* HomePage */
1057 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc2].HomePage, false);
1058 if (settings->Settings[loc2].IsContinuous) SetReq[pos] = 0x01;
1059 pos++;
1060 SetReq[pos++] = ID;
1061
1062 SetReq[pos] = phone2; /* bearer */
1063 switch (settings->ActiveBearer) {
1064 case WAPSETTINGS_BEARER_DATA:
1065 if (loc1 != -1) SetReq[pos] = phone1;
1066 break;
1067 case WAPSETTINGS_BEARER_SMS:
1068 if (loc2 != -1) SetReq[pos] = phone2;
1069 break;
1070 case WAPSETTINGS_BEARER_USSD:
1071 if (loc3 != -1) SetReq[pos] = phone3;
1072 break;
1073 default: break;
1074 }
1075 pos++;
1076
1077 if (settings->Settings[loc2].IsSecurity) SetReq[pos] = 0x01;
1078 pos++;
1079 } else if (loc3 != -1) {
1080 /* Name */
1081 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc3].Title, false);
1082 /* HomePage */
1083 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc3].HomePage, false);
1084 if (settings->Settings[loc3].IsContinuous) SetReq[pos] = 0x01;
1085 pos++;
1086 SetReq[pos++] = ID;
1087
1088 SetReq[pos] = phone3; /* bearer */
1089 switch (settings->ActiveBearer) {
1090 case WAPSETTINGS_BEARER_DATA:
1091 if (loc1 != -1) SetReq[pos] = phone1;
1092 break;
1093 case WAPSETTINGS_BEARER_SMS:
1094 if (loc2 != -1) SetReq[pos] = phone2;
1095 break;
1096 case WAPSETTINGS_BEARER_USSD:
1097 if (loc3 != -1) SetReq[pos] = phone3;
1098 break;
1099 default: break;
1100 }
1101 pos++;
1102
1103 if (settings->Settings[loc3].IsSecurity) SetReq[pos] = 0x01;
1104 pos++;
1105 } else {
1106 return ERR_UNKNOWN;/* We have to have write something known */
1107 }
1108 memcpy(SetReq + pos, "\x01\x80\x00\x00\x00\x00\x00\x00\x00", 9);
1109 pos += 9;
1110
1111 smprintf(s, "Writing WAP settings part 1\n");
1112 error=GSM_WaitFor (s, SetReq, pos, 0x3f, 4, ID_SetConnectSet);
1113 if (error != ERR_NONE) return error;
1114
1115 /* Data */
1116 if (phone1 != -1) {
1117 pos = 4;
1118 memset(SetReq2 + pos, 0, 200 - pos);
1119 SetReq2[pos++] = phone1;
1120 SetReq2[pos++] = 0x02;
1121 SetReq2[pos++] = 0x01; /* GSMdata */
1122 if (loc1 != -1) {
1123 if (!settings->Settings[loc1].IsNormalAuthentication) SetReq2[pos] = 0x01;
1124 }
1125 pos++;
1126 if (loc1 != -1) {
1127 if (settings->Settings[loc1].IsISDNCall) SetReq2[pos] = 0x01;
1128 }
1129 pos++;
1130 if (loc1 != -1) {
1131 switch (settings->Settings[loc1].Speed) {
1132 case WAPSETTINGS_SPEED_9600 : SetReq2[pos++] = 0x01; break;
1133 case WAPSETTINGS_SPEED_14400 : SetReq2[pos++] = 0x02; break;
1134 default : SetReq2[pos++] = 0x02; break;
1135 }
1136 switch (settings->Settings[loc1].Speed) {
1137 case WAPSETTINGS_SPEED_9600 : SetReq2[pos++] = 0x01; break;
1138 case WAPSETTINGS_SPEED_14400 : SetReq2[pos++] = 0x02; break;
1139 default : SetReq2[pos++] = 0x02; break;
1140 }
1141 } else pos+=2;
1142 if (loc1 != -1) {
1143 /* IP */
1144 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc1].IPAddress, false);
1145 /* Number */
1146 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc1].DialUp, false);
1147 /* Username */
1148 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc1].User, false);
1149 /* Password */
1150 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc1].Password, false);
1151 } else pos+=5;
1152 memcpy(SetReq2 + pos, "\x80\x00\x00\x00\x00\x00\x00\x00", 8);
1153 pos += 8;
1154 smprintf(s, "Writing WAP settings part 2 (Data bearer)\n");
1155 error=GSM_WaitFor (s, SetReq2, pos, 0x3f, 4, ID_SetConnectSet);
1156 if (error != ERR_NONE) return error;
1157 }
1158 /* SMS */
1159 if (phone2 != -1) {
1160 pos = 4;
1161 memset(SetReq2 + pos, 0, 200 - pos);
1162 SetReq2[pos++] = phone2;
1163 SetReq2[pos++] = 0x02;
1164 SetReq2[pos++] = 0x00; /* SMS */
1165 if (loc2 != -1) {
1166 /* Service number */
1167 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc2].Service, false);
1168 /* Server number */
1169 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc2].Server, false);
1170 } else pos += 2;
1171 memcpy(SetReq2 + pos, "\x80\x00\x00\x00\x00\x00\x00\x00", 8);
1172 pos += 8;
1173 smprintf(s, "Writing WAP settings part 2 (SMS bearer)\n");
1174 error=GSM_WaitFor (s, SetReq2, pos, 0x3f, 4, ID_SetConnectSet);
1175 if (error != ERR_NONE) return error;
1176 }
1177 /* USSD */
1178 if (phone3 != -1) {
1179 pos = 4;
1180 memset(SetReq2 + pos, 0, 200 - pos);
1181 SetReq2[pos++] = phone3;
1182 SetReq2[pos++] = 0x02;
1183 SetReq2[pos++] = 0x02; /* USSD */
1184 if (loc3 != -1) {
1185 if (!settings->Settings[loc3].IsIP) SetReq2[pos] = 0x01;
1186 }
1187 pos++;
1188 if (loc3 != -1) {
1189 /* Service number or IP address */
1190 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc3].Service, false);
1191 /* Code number */
1192 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc3].Code, false);
1193 } else pos+=2;
1194 memcpy(SetReq2 + pos, "\x80\x00\x00\x00\x00\x00\x00\x00", 8);
1195 pos += 8;
1196 smprintf(s, "Writing WAP settings part 2 (USSD bearer)\n");
1197 error=GSM_WaitFor (s, SetReq2, pos, 0x3f, 4, ID_SetConnectSet);
1198 if (error != ERR_NONE) return error;
1199 }
1200 error = DCT3DCT4_SetActiveConnectSet(s, settings);
1201 if (error != ERR_NONE) return error;
1202
1203 return DCT3DCT4_DisableConnectionFunctions(s);
1204}
1205
1206GSM_Error DCT3_ReplySendSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s)
1207{
1208 switch (msg.Buffer[3]) {
1209 case 0x02:
1210 smprintf(s, "SMS sent OK\n");
1211 if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s->CurrentConfig->Device,0,0);
1212 return ERR_NONE;
1213 case 0x03:
1214 smprintf(s, "Error %i\n",msg.Buffer[6]);
1215 if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s->CurrentConfig->Device,msg.Buffer[6],0);
1216 return ERR_NONE;
1217 }
1218 return ERR_UNKNOWNRESPONSE;
1219}
1220
1221GSM_Error DCT3_SendSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms)
1222{
1223 int length;
1224 GSM_Error error;
1225 unsigned char req[256] = {N6110_FRAME_HEADER, 0x01, 0x02, 0x00};
1226
1227 error=PHONE_EncodeSMSFrame(s,sms,req+6,PHONE_SMSSubmit,&length, true);
1228 if (error != ERR_NONE) return error;
1229
1230 smprintf(s, "Sending sms\n");
1231 return s->Protocol.Functions->WriteMessage(s, req, 6+length, 0x02);
1232}
1233
1234GSM_Error DCT3_ReplyNetmonitor(GSM_Protocol_Message msg, GSM_StateMachine *s)
1235{
1236 switch (msg.Buffer[3]) {
1237 case 0x00:
1238 smprintf(s, "Netmonitor correctly set\n");
1239 break;
1240 default:
1241 smprintf(s, "Menu %i\n",msg.Buffer[3]);
1242 smprintf(s, "%s\n",msg.Buffer+4);
1243 strcpy(s->Phone.Data.Netmonitor,msg.Buffer+4);
1244 break;
1245 }
1246 return ERR_NONE;
1247}
1248
1249GSM_Error DCT3_Netmonitor(GSM_StateMachine *s, int testnumber, char *value)
1250{
1251 GSM_Error error;
1252 unsigned char req[] = {0x00, 0x01, 0x7e,
1253 0x00}; /* Test number */
1254
1255 value[0] = 0;
1256
1257 error=DCT3_EnableSecurity (s, 0x01);
1258 if (error != ERR_NONE) return error;
1259
1260 req[3] = testnumber;
1261
1262 smprintf(s, "Getting netmonitor test\n");
1263 s->Phone.Data.Netmonitor = value;
1264 return GSM_WaitFor (s, req, 4, 0x40, 4, ID_Netmonitor);
1265}
1266
1267GSM_Error DCT3_GetManufactureMonth(GSM_StateMachine *s, char *value)
1268{
1269 GSM_Error error;
1270
1271 error=DCT3_EnableSecurity (s, 0x01);
1272 if (error != ERR_NONE) return error;
1273 return NOKIA_GetPhoneString(s,"\x00\x01\xCC\x02",4,0x40,value,ID_GetManufactureMonth,5);
1274}
1275
1276GSM_Error DCT3_GetProductCode(GSM_StateMachine *s, char *value)
1277{
1278 GSM_Error error;
1279
1280 if (strlen(s->Phone.Data.ProductCodeCache)!=0) {
1281 strcpy(value,s->Phone.Data.ProductCodeCache);
1282 return ERR_NONE;
1283 }
1284
1285 error=DCT3_EnableSecurity (s, 0x01);
1286 if (error != ERR_NONE) return error;
1287 return NOKIA_GetPhoneString(s,"\x00\x01\xCA\x01",4,0x40,value,ID_GetProductCode,5);
1288}
1289
1290GSM_Error DCT3_GetOriginalIMEI(GSM_StateMachine *s, char *value)
1291{
1292 GSM_Error error;
1293
1294 error=DCT3_EnableSecurity (s, 0x01);
1295 if (error != ERR_NONE) return error;
1296 return NOKIA_GetPhoneString(s,"\x00\x01\xCC\x01",4,0x40,value,ID_GetOriginalIMEI,5);
1297}
1298
1299GSM_Error DCT3_GetHardware(GSM_StateMachine *s, char *value)
1300{
1301 GSM_Error error;
1302
1303 if (strlen(s->Phone.Data.HardwareCache)!=0) {
1304 strcpy(value,s->Phone.Data.HardwareCache);
1305 return ERR_NONE;
1306 }
1307
1308 error=DCT3_EnableSecurity (s, 0x01);
1309 if (error != ERR_NONE) return error;
1310 return NOKIA_GetPhoneString(s,"\x00\x01\xC8\x05",4,0x40,value,ID_GetHardware,5);
1311}
1312
1313GSM_Error DCT3_GetPPM(GSM_StateMachine *s, char *value)
1314{
1315 GSM_Error error;
1316
1317 error=DCT3_EnableSecurity (s, 0x01);
1318 if (error != ERR_NONE) return error;
1319 return NOKIA_GetPhoneString(s,"\x00\x01\xC8\x12",4,0x40,value,ID_GetPPM,5);
1320}
1321
1322GSM_Error DCT3_GetSMSStatus(GSM_StateMachine *s, GSM_SMSMemoryStatus *status)
1323{
1324 unsigned char req[] = {N6110_FRAME_HEADER, 0x36, 0x64};
1325
1326 s->Phone.Data.SMSStatus=status;
1327 smprintf(s, "Getting SMS status\n");
1328 return GSM_WaitFor (s, req, 5, 0x14, 2, ID_GetSMSStatus);
1329
1330 /* 6210 family doesn't show in frame with SMS status info
1331 * about Templates. We get separately info about this SMS folder.
1332 */
1333}
1334
1335GSM_Error DCT3_ReplyDeleteSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s)
1336{
1337 switch(msg.Buffer[3]) {
1338 case 0x0b:
1339 smprintf(s, "SMS deleted\n");
1340 return ERR_NONE;
1341 case 0x0c:
1342 smprintf(s, "Error deleting SMS\n");
1343 switch (msg.Buffer[4]) {
1344 case 0x00:
1345 /* Not tested on 6210 */
1346 smprintf(s, "Unknown meaning, SMS seems to be deleted\n");
1347 return ERR_NONE;
1348 case 0x02:
1349 /* Not tested on 6210 */
1350 smprintf(s, "Invalid location\n");
1351 return ERR_INVALIDLOCATION;
1352 case 0x06:
1353 /* Not tested on 6210 */
1354 smprintf(s, "Phone is OFF\n");
1355 return ERR_PHONEOFF;
1356 default:
1357 smprintf(s, "Unknown error: %02x\n",msg.Buffer[4]);
1358 return ERR_UNKNOWNRESPONSE;
1359 }
1360 }
1361 return ERR_UNKNOWNRESPONSE;
1362}
1363
1364GSM_Error N71_92_ReplyGetSignalQuality(GSM_Protocol_Message msg, GSM_StateMachine *s)
1365{
1366 GSM_Phone_Data *Data = &s->Phone.Data;
1367
1368 smprintf(s, "Network level received: %i\n",msg.Buffer[4]);
1369 Data->SignalQuality->SignalStrength = -1;
1370 Data->SignalQuality->SignalPercent = ((int)msg.Buffer[4]);
1371 Data->SignalQuality->BitErrorRate = -1;
1372 return ERR_NONE;
1373}
1374
1375GSM_Error N71_92_GetSignalQuality(GSM_StateMachine *s, GSM_SignalQuality *sig)
1376{
1377 unsigned char req[] = {N6110_FRAME_HEADER, 0x81};
1378
1379 s->Phone.Data.SignalQuality = sig;
1380 smprintf(s, "Getting network level\n");
1381 return GSM_WaitFor (s, req, 4, 0x0a, 4, ID_GetSignalQuality);
1382}
1383
1384GSM_Error N71_92_ReplyGetBatteryCharge(GSM_Protocol_Message msg, GSM_StateMachine *s)
1385{
1386 GSM_Phone_Data *Data = &s->Phone.Data;
1387
1388 smprintf(s, "Battery level received: %i\n",msg.Buffer[5]);
1389 Data->BatteryCharge->BatteryPercent = ((int)msg.Buffer[5]);
1390 Data->BatteryCharge->ChargeState = 0;
1391 return ERR_NONE;
1392}
1393
1394GSM_Error N71_92_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat)
1395{
1396 unsigned char req[] = {N6110_FRAME_HEADER, 0x02};
1397
1398 s->Phone.Data.BatteryCharge = bat;
1399 smprintf(s, "Getting battery level\n");
1400 return GSM_WaitFor (s, req, 4, 0x17, 4, ID_GetBatteryCharge);
1401}
1402
1403GSM_Error N71_92_ReplyPhoneSetting(GSM_Protocol_Message msg, GSM_StateMachine *s)
1404{
1405 GSM_Phone_Bitmap_TypesBmpType;
1406 GSM_Phone_Data *Data = &s->Phone.Data;
1407
1408 switch (msg.Buffer[4]) {
1409 case 0x02:
1410 if (Data->RequestID == ID_GetBitmap || Data->RequestID == ID_EachFrame) {
1411 smprintf(s, "Welcome note text received\n");
1412 CopyUnicodeString(Data->Bitmap->Text,msg.Buffer+6);
1413 smprintf(s, "Text is \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Text));
1414 return ERR_NONE;
1415 }
1416 if (Data->RequestID == ID_SetBitmap || Data->RequestID == ID_EachFrame) {
1417 smprintf(s, "Startup text set\n");
1418 return ERR_NONE;
1419 }
1420 case 0x15:
1421 if (Data->RequestID == ID_GetBitmap || Data->RequestID == ID_EachFrame) {
1422 smprintf(s, "Startup logo received\n");
1423 BmpType=GSM_Nokia7110StartupLogo;
1424 if (msg.Buffer[17]==0x60) BmpType=GSM_Nokia6210StartupLogo;
1425 if (msg.Buffer[17]==0xc0) BmpType=GSM_NokiaStartupLogo;
1426 PHONE_DecodeBitmap(BmpType, msg.Buffer+22, Data->Bitmap);
1427 return ERR_NONE;
1428 }
1429 if (Data->RequestID == ID_SetBitmap || Data->RequestID == ID_EachFrame) {
1430 smprintf(s, "Startup logo set\n");
1431 return ERR_NONE;
1432 }
1433 case 0x17:
1434 if (Data->RequestID == ID_GetBitmap || Data->RequestID == ID_EachFrame) {
1435 smprintf(s, "Dealer note text received\n");
1436 CopyUnicodeString(Data->Bitmap->Text,msg.Buffer+6);
1437 smprintf(s, "Text is \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Text));
1438 return ERR_NONE;
1439 }
1440 if (Data->RequestID == ID_SetBitmap || Data->RequestID == ID_EachFrame) {
1441 smprintf(s, "Dealer text set\n");
1442 return ERR_NONE;
1443 }
1444 }
1445 return ERR_UNKNOWNRESPONSE;
1446}
1447
1448GSM_Error N71_92_GetPhoneSetting(GSM_StateMachine *s, int Request, int Setting)
1449{
1450 unsigned char req[] = {N7110_FRAME_HEADER, 0xee,
1451 0x1c}; /* Setting */
1452
1453 req[4]=Setting;
1454 return GSM_WaitFor (s, req, 5, 0x7a, 4, Request);
1455}
1456
1457GSM_Error N71_92_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
1458{
1459 return DCT3_GetDateTime(s, date_time, 0x19);
1460}
1461
1462GSM_Error N71_92_SetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
1463{
1464 return DCT3_SetDateTime(s, date_time, 0x19);
1465}
1466
1467GSM_Error DCT3_DecodeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *SMS, unsigned char *buffer)
1468{
1469 switch (buffer[12] & 0x03) {
1470 case 0x00:
1471 smprintf(s, "SMS type - deliver\n");
1472 SMS->PDU = SMS_Deliver;
1473 return GSM_DecodeSMSFrame(SMS,buffer,PHONE_SMSDeliver);
1474 case 0x01:
1475 smprintf(s, "SMS type - submit\n");
1476 SMS->PDU = SMS_Submit;
1477 return GSM_DecodeSMSFrame(SMS,buffer,PHONE_SMSSubmit);
1478 case 0x02:
1479 smprintf(s, "SMS type - delivery report\n");
1480 SMS->PDU = SMS_Status_Report;
1481 return GSM_DecodeSMSFrame(SMS,buffer,PHONE_SMSStatusReport);
1482 }
1483 return ERR_UNKNOWN;
1484}
1485
1486GSM_Error N61_91_ReplySetOpLogo(GSM_Protocol_Message msg, GSM_StateMachine *s)
1487{
1488 switch (msg.Buffer[3]) {
1489 case 0x31:
1490 smprintf(s, "Operator logo set OK\n");
1491 return ERR_NONE;
1492 case 0x32:
1493 smprintf(s, "Error setting operator logo\n");
1494 switch (msg.Buffer[4]) {
1495 case 0x7d:
1496 smprintf(s, "Too high location ?\n");
1497 return ERR_INVALIDLOCATION;
1498 default:
1499 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]);
1500 }
1501 }
1502 return ERR_UNKNOWNRESPONSE;
1503}
1504
1505GSM_Error N61_71_ReplyResetPhoneSettings(GSM_Protocol_Message msg, GSM_StateMachine *s)
1506{
1507 smprintf(s, "Phone settings cleaned OK\n");
1508 return ERR_NONE;
1509}
1510
1511GSM_Error N61_71_ResetPhoneSettings(GSM_StateMachine *s, GSM_ResetSettingsType Type)
1512{
1513 GSM_Errorerror;
1514 unsigned char req[] = {0x00, 0x01, 0x65,
1515 0x01}; /* Reset type */
1516
1517 switch (Type) {
1518 case GSM_RESET_PHONESETTINGS : req[3] = 0x01; break;
1519 case GSM_RESET_DEVICE : req[3] = 0x02; break;
1520 case GSM_RESET_USERINTERFACE : req[3] = 0x08; break;
1521 case GSM_RESET_USERINTERFACE_PHONESETTINGS: req[3] = 0x38; break;
1522 case GSM_RESET_FULLFACTORY : req[3] = 0xff; break;
1523 }
1524
1525 error=DCT3_EnableSecurity (s, 0x01);
1526 if (error != ERR_NONE) return error;
1527
1528 return GSM_WaitFor (s, req, 4, 0x40, 4, ID_ResetPhoneSettings);
1529}
1530
1531#endif
1532
1533/* How should editor hadle tabs in this file? Add editor commands here.
1534 * vim: noexpandtab sw=8 ts=8 sts=8:
1535 */