summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-10-05 11:13:51 (UTC)
committer zautrix <zautrix>2004-10-05 11:13:51 (UTC)
commit50ab40e1e02ad7c65c17a78d08116a808b1257aa (patch) (unidiff)
tree0d1939e2297fa7bbd8e1f2030f154463854164c6
parentcf8616f64f20e5448d4ff644f7cc15750cf3f85f (diff)
downloadkdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.zip
kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.tar.gz
kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.tar.bz2
updated to latest gammu version
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--gammu/emb/cfg/config.h2
-rw-r--r--gammu/emb/common/common.pro1
-rw-r--r--gammu/emb/common/commonE.pro1
-rw-r--r--gammu/emb/common/device/bluetoth/bluez.c29
-rw-r--r--gammu/emb/common/device/devfunc.c12
-rw-r--r--gammu/emb/common/device/irda/irda.c8
-rw-r--r--gammu/emb/common/device/irda/irda_unx.h2
-rw-r--r--gammu/emb/common/device/serial/ser_djg.c10
-rw-r--r--gammu/emb/common/device/serial/ser_unx.c38
-rw-r--r--gammu/emb/common/device/serial/ser_w32.c6
-rw-r--r--gammu/emb/common/gsmcomon.c21
-rw-r--r--gammu/emb/common/gsmcomon.h3
-rw-r--r--gammu/emb/common/gsmstate.c74
-rw-r--r--gammu/emb/common/gsmstate.h31
-rw-r--r--gammu/emb/common/misc/coding/coding.c177
-rw-r--r--gammu/emb/common/misc/coding/coding.h27
-rw-r--r--gammu/emb/common/misc/coding/md5.c2
-rw-r--r--gammu/emb/common/misc/misc.c19
-rw-r--r--gammu/emb/common/misc/misc.h8
-rw-r--r--gammu/emb/common/phone/alcatel/alcatel.c298
-rw-r--r--gammu/emb/common/phone/at/atgen.c295
-rw-r--r--gammu/emb/common/phone/at/atgen.h8
-rw-r--r--gammu/emb/common/phone/at/samsung.c447
-rw-r--r--gammu/emb/common/phone/at/samsung.h16
-rw-r--r--gammu/emb/common/phone/at/siemens.c74
-rw-r--r--gammu/emb/common/phone/at/sonyeric.c141
-rw-r--r--gammu/emb/common/phone/nokia/dct3/dct3func.c16
-rw-r--r--gammu/emb/common/phone/nokia/dct3/dct3func.h2
-rw-r--r--gammu/emb/common/phone/nokia/dct3/n6110.c17
-rw-r--r--gammu/emb/common/phone/nokia/dct3/n7110.c9
-rw-r--r--gammu/emb/common/phone/nokia/dct3/n9210.c3
-rw-r--r--gammu/emb/common/phone/nokia/dct4/n3320.c3
-rw-r--r--gammu/emb/common/phone/nokia/dct4/n3650.c3
-rw-r--r--gammu/emb/common/phone/nokia/dct4/n6510.c168
-rw-r--r--gammu/emb/common/phone/nokia/dct4/n6510.h2
-rw-r--r--gammu/emb/common/phone/nokia/nauto.c2
-rw-r--r--gammu/emb/common/phone/nokia/nfunc.c14
-rw-r--r--gammu/emb/common/phone/obex/obexgen.c3
-rw-r--r--gammu/emb/common/phone/obex/obexgen.h4
-rw-r--r--gammu/emb/common/phone/symbian/mroutgen.c3
-rw-r--r--gammu/emb/common/protocol/at/at.c6
-rw-r--r--gammu/emb/common/protocol/nokia/fbus2.c6
-rw-r--r--gammu/emb/common/protocol/nokia/fbus2.h6
-rw-r--r--gammu/emb/common/protocol/nokia/mbus2.c2
-rw-r--r--gammu/emb/common/protocol/nokia/mbus2.h2
-rw-r--r--gammu/emb/common/protocol/nokia/phonet.c5
-rw-r--r--gammu/emb/common/protocol/nokia/phonet.h5
-rw-r--r--gammu/emb/common/service/backup/backgen.h4
-rw-r--r--gammu/emb/common/service/backup/backtext.c229
-rw-r--r--gammu/emb/common/service/backup/gsmback.c36
-rw-r--r--gammu/emb/common/service/backup/gsmback.h2
-rw-r--r--gammu/emb/common/service/gsmcal.h2
-rw-r--r--gammu/emb/common/service/gsmdata.c124
-rw-r--r--gammu/emb/common/service/gsmdata.h2
-rw-r--r--gammu/emb/common/service/gsmlogo.c47
-rw-r--r--gammu/emb/common/service/gsmlogo.h28
-rw-r--r--gammu/emb/common/service/gsmmisc.h7
-rw-r--r--gammu/emb/common/service/gsmring.c45
-rw-r--r--gammu/emb/common/service/gsmring.h8
-rw-r--r--gammu/emb/common/service/sms/gsmmulti.c5
-rw-r--r--gammu/emb/common/service/sms/gsmmulti.h11
-rw-r--r--gammu/emb/common/service/sms/gsmsms.c5
-rw-r--r--gammu/emb/common/service/sms/gsmsms.h5
-rw-r--r--gammu/emb/gammu/depend/nokia/dct3.c6
-rw-r--r--gammu/emb/gammu/depend/nokia/dct4.c11
-rw-r--r--gammu/emb/gammu/depend/nokia/dct4.h13
-rw-r--r--gammu/emb/gammu/gammu.c662
-rw-r--r--gammu/emb/gammu/gammu.h8
-rw-r--r--gammu/emb/gammu/smsd/s_files.c81
-rw-r--r--gammu/emb/gammu/smsd/s_files.h2
-rw-r--r--gammu/emb/gammu/smsd/s_mysql.c608
-rw-r--r--gammu/emb/gammu/smsd/smsdcore.c180
-rw-r--r--gammu/emb/gammu/smsd/smsdcore.h37
-rw-r--r--libkcal/phoneformat.cpp4
74 files changed, 3210 insertions, 993 deletions
diff --git a/gammu/emb/cfg/config.h b/gammu/emb/cfg/config.h
index 1ba6365..62b4fcf 100644
--- a/gammu/emb/cfg/config.h
+++ b/gammu/emb/cfg/config.h
@@ -1,174 +1,174 @@
1/* config.h. Generated by configure. */ 1/* config.h. Generated by configure. */
2 2
3#ifndef _config_h_ 3#ifndef _config_h_
4#define _config_h_ 4#define _config_h_
5 5
6/* -------------------------- Gammu specific ---------------------------- */ 6/* -------------------------- Gammu specific ---------------------------- */
7 7
8/* Version of package */ 8/* Version of package */
9#define VERSION "0.97.0" 9#define VERSION "0.97.0"
10#define VERSION_WIN "0,97,0,0" 10#define VERSION_WIN "0,97,0,0"
11 11
12#ifndef _MSC_VER 12#ifndef _MSC_VER
13/* Define if want DEBUG info */ 13/* Define if want DEBUG info */
14/* #undef DEBUG */ 14/* #undef DEBUG */
15#endif 15#endif
16 16
17/* #undef ENABLE_LGPL */ 17/* #undef ENABLE_LGPL */
18 18
19/* ---------------------- Connections ---------------------------------- */ 19/* ---------------------- Connections ---------------------------------- */
20 20
21/* MBUS2 over cable */ 21/* MBUS2 over cable */
22#define GSM_ENABLE_MBUS2 1 22#define GSM_ENABLE_MBUS2 1
23 23
24/* FBUS2 over cable */ 24/* FBUS2 over cable */
25#define GSM_ENABLE_FBUS2 1 25#define GSM_ENABLE_FBUS2 1
26/* FBUS2 to use with DLR3 cable (init done using AT commands) */ 26/* FBUS2 to use with DLR3 cable (init done using AT commands) */
27#define GSM_ENABLE_FBUS2DLR3 1 27#define GSM_ENABLE_FBUS2DLR3 1
28/* FBUS2 to use with DKU5 cable (init done using AT commands) */ 28/* FBUS2 to use with DKU5 cable (init done using AT commands) */
29#define GSM_ENABLE_FBUS2DKU5 1 29#define GSM_ENABLE_FBUS2DKU5 1
30/* FBUS2 to use with cable with PL2303 chip (init done using AT commands) */ 30/* FBUS2 to use with cable with PL2303 chip (init done using AT commands) */
31#define GSM_ENABLE_FBUS2PL2303 1 31#define GSM_ENABLE_FBUS2PL2303 1
32/* FBUS2 to use with bluetooth legacy device (init done using AT commands) */ 32/* FBUS2 to use with bluetooth legacy device (init done using AT commands) */
33#define GSM_ENABLE_FBUS2BLUE 1 33#define GSM_ENABLE_FBUS2BLUE 1
34/* FBUS2 to use with direct infrared device */ 34/* FBUS2 to use with direct infrared device */
35#define GSM_ENABLE_FBUS2IRDA 1 35#define GSM_ENABLE_FBUS2IRDA 1
36 36
37/* PHONET FBUS to use with bluetooth legacy device */ 37/* PHONET FBUS to use with bluetooth legacy device */
38#define GSM_ENABLE_PHONETBLUE 1 38#define GSM_ENABLE_PHONETBLUE 1
39 39
40/* Symbian with m-router (TCPIP based) to use with bluetooth legacy device */ 40/* Symbian with m-router (TCPIP based) to use with bluetooth legacy device */
41#define GSM_ENABLE_MROUTERBLUE 1 41#define GSM_ENABLE_MROUTERBLUE 1
42 42
43/* AT protocol */ 43/* AT protocol */
44#define GSM_ENABLE_AT 1 44#define GSM_ENABLE_AT 1
45 45
46/* Alcatel protocol */ 46/* Alcatel protocol */
47#define GSM_ENABLE_ALCABUS 1 47#define GSM_ENABLE_ALCABUS 1
48 48
49/* Infrared. PHONET FBUS */ 49/* Infrared. PHONET FBUS */
50#define GSM_ENABLE_IRDAPHONET 1 50#define GSM_ENABLE_IRDAPHONET 1
51/* Infrared. AT commands */ 51/* Infrared. AT commands */
52#define GSM_ENABLE_IRDAAT 1 52#define GSM_ENABLE_IRDAAT 1
53/* Infrared. OBEX */ 53/* Infrared. OBEX */
54#define GSM_ENABLE_IRDAOBEX 1 54#define GSM_ENABLE_IRDAOBEX 1
55 55
56#ifdef WIN32 56#ifdef WIN32
57# define GSM_ENABLE_BLUEFBUS2 1 57# define GSM_ENABLE_BLUEFBUS2 1
58# define GSM_ENABLE_BLUEPHONET 1 58# define GSM_ENABLE_BLUEPHONET 1
59# define GSM_ENABLE_BLUEAT 1 59# define GSM_ENABLE_BLUEAT 1
60# define GSM_ENABLE_BLUEOBEX 1 60# define GSM_ENABLE_BLUEOBEX 1
61#else 61#else
62/* Bluetooth stack (like Bluez). FBUS2 (init done using AT commands) */ 62/* Bluetooth stack (like Bluez). FBUS2 (init done using AT commands) */
63//LR# define GSM_ENABLE_BLUEFBUS2 1 63//LR# define GSM_ENABLE_BLUEFBUS2 1
64/* Bluetooth stack (like Bluez). PHONET FBUS */ 64/* Bluetooth stack (like Bluez). PHONET FBUS */
65//LR# define GSM_ENABLE_BLUEPHONET 1 65//LR# define GSM_ENABLE_BLUEPHONET 1
66/* Blueooth stack (like Bluez). AT commands */ 66/* Blueooth stack (like Bluez). AT commands */
67//LR# define GSM_ENABLE_BLUEAT 1 67//LR# define GSM_ENABLE_BLUEAT 1
68/* Blueooth stack (like Bluez). OBEX */ 68/* Blueooth stack (like Bluez). OBEX */
69//LR# define GSM_ENABLE_BLUEOBEX 1 69//LR# define GSM_ENABLE_BLUEOBEX 1
70#endif 70#endif
71 71
72/* --------------------------- Phone modules (specific) ----------------- */ 72/* --------------------------- Phone modules (specific) ----------------- */
73 73
74/* n3320.c models */ 74/* n3320.c models */
75#define GSM_ENABLE_NOKIA3320 1 75#define GSM_ENABLE_NOKIA3320 1
76/* n6110.c models */ 76/* n6110.c models */
77#define GSM_ENABLE_NOKIA6110 1 77#define GSM_ENABLE_NOKIA6110 1
78 78
79/* n7110.c models */ 79/* n7110.c models */
80#define GSM_ENABLE_NOKIA7110 1 80#define GSM_ENABLE_NOKIA7110 1
81/* n9210.c models */ 81/* n9210.c models */
82#define GSM_ENABLE_NOKIA9210 1 82#define GSM_ENABLE_NOKIA9210 1
83/* It allows to show incoming call and SMS info for 7110 family phones. 83/* It allows to show incoming call and SMS info for 7110 family phones.
84 * By default commented: you can have some problems, when using it. 84 * By default commented: you can have some problems, when using it.
85 * Example: with my 6210 after using it info about incoming sms is shown much 85 * Example: with my 6210 after using it info about incoming sms is shown much
86 * earlier than sms in phone and phone restart (once and random) later after 86 * earlier than sms in phone and phone restart (once and random) later after
87 * connection. Seems phone firmware isn't too good here 87 * connection. Seems phone firmware isn't too good here
88 */ 88 */
89/* Show incoming Data for 7110/9210 */ 89/* Show incoming Data for 7110/9210 */
90/* #undef GSM_ENABLE_N71_92INCOMINGINFO */ 90/* #undef GSM_ENABLE_N71_92INCOMINGINFO */
91 91
92/* n6510.c (DCT4) models */ 92/* n6510.c (DCT4) models */
93#define GSM_ENABLE_NOKIA6510 1 93#define GSM_ENABLE_NOKIA6510 1
94/* Force using 6210 frames for calendar. Required by some older DCT4 */ 94/* Force using 6210 frames for calendar. Required by some older DCT4 */
95/* #undef GSM_FORCE_DCT4_CALENDAR_6210 */ 95/* #undef GSM_FORCE_DCT4_CALENDAR_6210 */
96 96
97/* n3650.c (DCT4 with Symbian) models */ 97/* n3650.c (DCT4 with Symbian) models */
98#define GSM_ENABLE_NOKIA3650 1 98#define GSM_ENABLE_NOKIA3650 1
99 99
100/* AT generic models */ 100/* AT generic models */
101#define GSM_ENABLE_ATGEN 1 101#define GSM_ENABLE_ATGEN 1
102 102
103/* Alcatel BE5 */ 103/* Alcatel BE5 */
104#define GSM_ENABLE_ALCATEL 1 104#define GSM_ENABLE_ALCATEL 1
105 105
106/* OBEX generic models */ 106/* OBEX generic models */
107#define GSM_ENABLE_OBEXGEN 1 107#define GSM_ENABLE_OBEXGEN 1
108 108
109/* Symbian with m-router generic models */ 109/* Symbian with m-router generic models */
110#define GSM_ENABLE_MROUTERGEN 1 110#define GSM_ENABLE_MROUTERGEN 1
111 111
112/* ---------------------- General settings -------------------------------- */ 112/* ---------------------- General settings -------------------------------- */
113 113
114/* By default commented: some people reported me (for example, with 6210 114/* By default commented: some people reported me (for example, with 6210
115 * and 3210), that their phones doesn't answer at all sometimes or answer 115 * and 3210), that their phones doesn't answer at all sometimes or answer
116 * with (too) long delay. Possible reason: firmware in phone is too slow 116 * with (too) long delay. Possible reason: firmware in phone is too slow
117 * I didn't have such problems personally with phone and PC with Celeron 800 117 * I didn't have such problems personally with phone and PC with Celeron 800
118 * Please also note, that CB function was always TO CHECK in MyGnokii/Gnokii 118 * Please also note, that CB function was always TO CHECK in MyGnokii/Gnokii
119 * too. 119 * too.
120 */ 120 */
121/* Enables cell broadcast */ 121/* Enables cell broadcast */
122/* #undef GSM_ENABLE_CELLBROADCAST */ 122/* #undef GSM_ENABLE_CELLBROADCAST */
123 123
124/* If you want backup/restore stuff. Some people wanted it - they required 124/* If you want backup/restore stuff. Some people wanted it - they required
125 * smalled library made from Gammu and didn't require it. Please note, 125 * smalled library made from Gammu and didn't require it. Please note,
126 * that backup/restore stuff can be easy separated from other things. 126 * that backup/restore stuff can be easy separated from other things.
127 */ 127 */
128#define GSM_ENABLE_BACKUP 1 128#define GSM_ENABLE_BACKUP 1
129 129
130/* Bu default commented: some parts of source are not ready or not tested 130/* Bu default commented: some parts of source are not ready or not tested
131 * at all (or aren't good tested). Uncomment, if want them 131 * at all (or aren't good tested). Uncomment, if want them
132 */ 132 */
133//#define DEVELOP 133//#define DEVELOP
134 134
135/* By default disabled. It allows to making short beep after such things 135/* By default disabled. It allows to making short beep after such things
136 * like changing logo in phone (like in Logo Manager) 136 * like changing logo in phone (like in Logo Manager)
137 */ 137 */
138//#define GSM_ENABLE_BEEP 138//#define GSM_ENABLE_BEEP
139 139
140/* ---------------------- C language specific --------------------------- */ 140/* ---------------------- C language specific --------------------------- */
141 141
142#ifndef WIN32 142#ifndef WIN32
143/* are the scandir functions available */ 143/* are the scandir functions available */
144# define HAVE_DIRENT_H 1 144# define HAVE_DIRENT_H 1
145# define HAVE_SCANDIR 1 145# define HAVE_SCANDIR 1
146# define HAVE_ALPHASORT 1 146# define HAVE_ALPHASORT 1
147 147
148# define HAVE_PTHREAD 1 148# define HAVE_PTHREAD 1
149# define HAVE_SYS_IOCTL_H 1 149# define HAVE_SYS_IOCTL_H 1
150# define HAVE_MYSQL_MYSQL_H 1 150//LR # define HAVE_MYSQL_MYSQL_H 1
151#endif 151#endif
152 152
153#define HAVE_ISWSPACE 1 153#define HAVE_ISWSPACE 1
154#define HAVE_TOWLOWER 1 154#define HAVE_TOWLOWER 1
155 155
156#ifndef WIN32 156#ifndef WIN32
157/* Will be used Bluez BT stack ? */ 157/* Will be used Bluez BT stack ? */
158// LR bluetooth disabled 158// LR bluetooth disabled
159//# define GSM_ENABLE_BLUEZ 1 159//# define GSM_ENABLE_BLUEZ 1
160/* Will be used Affix BT stack ? */ 160/* Will be used Affix BT stack ? */
161/* # undef GSM_ENABLE_AFFIX */ 161/* # undef GSM_ENABLE_AFFIX */
162#endif 162#endif
163 163
164/* Uncomment, if you want searching RF channel during each BT connection */ 164/* Uncomment, if you want searching RF channel during each BT connection */
165/* It can make connecting longer or connection less stable */ 165/* It can make connecting longer or connection less stable */
166/* With MS VC and MS BT stack required irprops.lib from MS Platform SDK to compile */ 166/* With MS VC and MS BT stack required irprops.lib from MS Platform SDK to compile */
167#ifndef WIN32 167#ifndef WIN32
168// LR bluetooth disabled 168// LR bluetooth disabled
169//# define BLUETOOTH_RF_SEARCHING 1 169//# define BLUETOOTH_RF_SEARCHING 1
170#else 170#else
171//# define BLUETOOTH_RF_SEARCHING 1 171//# define BLUETOOTH_RF_SEARCHING 1
172#endif 172#endif
173 173
174#endif 174#endif
diff --git a/gammu/emb/common/common.pro b/gammu/emb/common/common.pro
index 0e719ee..797199b 100644
--- a/gammu/emb/common/common.pro
+++ b/gammu/emb/common/common.pro
@@ -1,187 +1,188 @@
1###################################################################### 1######################################################################
2# Automatically generated by qmake (1.07a) Fri Jul 30 22:13:34 2004 2# Automatically generated by qmake (1.07a) Fri Jul 30 22:13:34 2004
3###################################################################### 3######################################################################
4 4
5TEMPLATE = lib 5TEMPLATE = lib
6DEPENDPATH += device \ 6DEPENDPATH += device \
7 misc \ 7 misc \
8 phone \ 8 phone \
9 protocol \ 9 protocol \
10 service \ 10 service \
11 device/bluetoth \ 11 device/bluetoth \
12 device/irda \ 12 device/irda \
13 device/serial \ 13 device/serial \
14 misc/coding \ 14 misc/coding \
15 phone/alcatel \ 15 phone/alcatel \
16 phone/at \ 16 phone/at \
17 phone/nokia \ 17 phone/nokia \
18 phone/obex \ 18 phone/obex \
19 phone/symbian \ 19 phone/symbian \
20 protocol/alcatel \ 20 protocol/alcatel \
21 protocol/at \ 21 protocol/at \
22 protocol/nokia \ 22 protocol/nokia \
23 protocol/obex \ 23 protocol/obex \
24 protocol/symbian \ 24 protocol/symbian \
25 service/backup \ 25 service/backup \
26 service/sms \ 26 service/sms \
27 phone/nokia/dct3 \ 27 phone/nokia/dct3 \
28 phone/nokia/dct4 28 phone/nokia/dct4
29INCLUDEPATH += . \ 29INCLUDEPATH += . \
30 misc/coding \ 30 misc/coding \
31 misc \ 31 misc \
32 device \ 32 device \
33 phone/nokia/dct4 \ 33 phone/nokia/dct4 \
34 phone/nokia/dct3 \ 34 phone/nokia/dct3 \
35 phone/at \ 35 phone/at \
36 phone/alcatel \ 36 phone/alcatel \
37 phone/obex \ 37 phone/obex \
38 phone/symbian \ 38 phone/symbian \
39 protocol \ 39 protocol \
40 protocol/nokia \ 40 protocol/nokia \
41 protocol/at \ 41 protocol/at \
42 protocol/alcatel \ 42 protocol/alcatel \
43 protocol/obex \ 43 protocol/obex \
44 protocol/symbian \ 44 protocol/symbian \
45 device/serial \ 45 device/serial \
46 device/irda \ 46 device/irda \
47 device/bluetoth \ 47 device/bluetoth \
48 service \ 48 service \
49 service/sms \ 49 service/sms \
50 service/backup \ 50 service/backup \
51 phone/nokia \ 51 phone/nokia \
52 phone 52 phone
53 53
54# Input 54# Input
55HEADERS += config.h \ 55HEADERS += config.h \
56 gammu.h \ 56 gammu.h \
57 gsmcomon.h \ 57 gsmcomon.h \
58 gsmstate.h \ 58 gsmstate.h \
59 device/devfunc.h \ 59 device/devfunc.h \
60 misc/cfg.h \ 60 misc/cfg.h \
61 misc/misc.h \ 61 misc/misc.h \
62 phone/pfunc.h \ 62 phone/pfunc.h \
63 protocol/protocol.h \ 63 protocol/protocol.h \
64 service/gsmcal.h \ 64 service/gsmcal.h \
65 service/gsmcall.h \ 65 service/gsmcall.h \
66 service/gsmdata.h \ 66 service/gsmdata.h \
67 service/gsmlogo.h \ 67 service/gsmlogo.h \
68 service/gsmmisc.h \ 68 service/gsmmisc.h \
69 service/gsmnet.h \ 69 service/gsmnet.h \
70 service/gsmpbk.h \ 70 service/gsmpbk.h \
71 service/gsmprof.h \ 71 service/gsmprof.h \
72 service/gsmring.h \ 72 service/gsmring.h \
73 device/bluetoth/affix.h \ 73 device/bluetoth/affix.h \
74 device/bluetoth/blue_w32.h \ 74 device/bluetoth/blue_w32.h \
75 device/bluetoth/bluetoth.h \ 75 device/bluetoth/bluetoth.h \
76 device/bluetoth/bluez.h \ 76 device/bluetoth/bluez.h \
77 device/irda/irda.h \ 77 device/irda/irda.h \
78 device/irda/irda_unx.h \ 78 device/irda/irda_unx.h \
79 device/irda/irda_w32.h \ 79 device/irda/irda_w32.h \
80 device/serial/ser_djg.h \ 80 device/serial/ser_djg.h \
81 device/serial/ser_unx.h \ 81 device/serial/ser_unx.h \
82 device/serial/ser_w32.h \ 82 device/serial/ser_w32.h \
83 misc/coding/coding.h \ 83 misc/coding/coding.h \
84 misc/coding/md5.h \ 84 misc/coding/md5.h \
85 phone/alcatel/alcatel.h \ 85 phone/alcatel/alcatel.h \
86 phone/at/atgen.h \ 86 phone/at/atgen.h \
87 phone/nokia/ncommon.h \ 87 phone/nokia/ncommon.h \
88 phone/nokia/nfunc.h \ 88 phone/nokia/nfunc.h \
89 phone/nokia/nfuncold.h \ 89 phone/nokia/nfuncold.h \
90 phone/obex/obexgen.h \ 90 phone/obex/obexgen.h \
91 phone/symbian/mroutgen.h \ 91 phone/symbian/mroutgen.h \
92 protocol/alcatel/alcabus.h \ 92 protocol/alcatel/alcabus.h \
93 protocol/at/at.h \ 93 protocol/at/at.h \
94 protocol/nokia/fbus2.h \ 94 protocol/nokia/fbus2.h \
95 protocol/nokia/mbus2.h \ 95 protocol/nokia/mbus2.h \
96 protocol/nokia/phonet.h \ 96 protocol/nokia/phonet.h \
97 protocol/obex/obex.h \ 97 protocol/obex/obex.h \
98 protocol/symbian/mrouter.h \ 98 protocol/symbian/mrouter.h \
99 service/backup/backgen.h \ 99 service/backup/backgen.h \
100 service/backup/backics.h \ 100 service/backup/backics.h \
101 service/backup/backldif.h \ 101 service/backup/backldif.h \
102 service/backup/backlmb.h \ 102 service/backup/backlmb.h \
103 service/backup/backtext.h \ 103 service/backup/backtext.h \
104 service/backup/backvcf.h \ 104 service/backup/backvcf.h \
105 service/backup/backvcs.h \ 105 service/backup/backvcs.h \
106 service/backup/gsmback.h \ 106 service/backup/gsmback.h \
107 service/sms/gsmems.h \ 107 service/sms/gsmems.h \
108 service/sms/gsmmulti.h \ 108 service/sms/gsmmulti.h \
109 service/sms/gsmsms.h \ 109 service/sms/gsmsms.h \
110 phone/nokia/dct3/dct3comm.h \ 110 phone/nokia/dct3/dct3comm.h \
111 phone/nokia/dct3/dct3func.h \ 111 phone/nokia/dct3/dct3func.h \
112 phone/nokia/dct3/n6110.h \ 112 phone/nokia/dct3/n6110.h \
113 phone/nokia/dct3/n7110.h \ 113 phone/nokia/dct3/n7110.h \
114 phone/nokia/dct3/n9210.h \ 114 phone/nokia/dct3/n9210.h \
115 phone/nokia/dct4/dct4func.h \ 115 phone/nokia/dct4/dct4func.h \
116 phone/nokia/dct4/n3320.h \ 116 phone/nokia/dct4/n3320.h \
117 phone/nokia/dct4/n3650.h \ 117 phone/nokia/dct4/n3650.h \
118 phone/nokia/dct4/n6510.h 118 phone/nokia/dct4/n6510.h
119SOURCES +=gsmcomon.c \ 119SOURCES +=gsmcomon.c \
120gsmstate.c \ 120gsmstate.c \
121misc/misc.c \ 121misc/misc.c \
122misc/cfg.c \ 122misc/cfg.c \
123misc/coding/coding.c \ 123misc/coding/coding.c \
124misc/coding/md5.c \ 124misc/coding/md5.c \
125service/sms/gsmsms.c \ 125service/sms/gsmsms.c \
126service/sms/gsmems.c \ 126service/sms/gsmems.c \
127service/sms/gsmmulti.c \ 127service/sms/gsmmulti.c \
128service/gsmcal.c \ 128service/gsmcal.c \
129service/gsmdata.c \ 129service/gsmdata.c \
130service/gsmpbk.c \ 130service/gsmpbk.c \
131service/gsmring.c \ 131service/gsmring.c \
132service/gsmlogo.c \ 132service/gsmlogo.c \
133service/gsmmisc.c \ 133service/gsmmisc.c \
134service/gsmnet.c \ 134service/gsmnet.c \
135service/backup/gsmback.c \ 135service/backup/gsmback.c \
136service/backup/backldif.c \ 136service/backup/backldif.c \
137service/backup/backlmb.c \ 137service/backup/backlmb.c \
138service/backup/backtext.c \ 138service/backup/backtext.c \
139service/backup/backvcs.c \ 139service/backup/backvcs.c \
140service/backup/backvcf.c \ 140service/backup/backvcf.c \
141service/backup/backics.c \ 141service/backup/backics.c \
142device/bluetoth/affix.c \ 142device/bluetoth/affix.c \
143device/bluetoth/bluez.c \ 143device/bluetoth/bluez.c \
144device/bluetoth/blue_w32.c \ 144device/bluetoth/blue_w32.c \
145device/bluetoth/bluetoth.c \ 145device/bluetoth/bluetoth.c \
146device/serial/ser_djg.c \ 146device/serial/ser_djg.c \
147device/irda/irda.c \ 147device/irda/irda.c \
148device/devfunc.c \ 148device/devfunc.c \
149protocol/at/at.c \ 149protocol/at/at.c \
150protocol/alcatel/alcabus.c \ 150protocol/alcatel/alcabus.c \
151protocol/nokia/mbus2.c \ 151protocol/nokia/mbus2.c \
152protocol/nokia/fbus2.c \ 152protocol/nokia/fbus2.c \
153protocol/nokia/phonet.c \ 153protocol/nokia/phonet.c \
154protocol/obex/obex.c \ 154protocol/obex/obex.c \
155protocol/symbian/mrouter.c \ 155protocol/symbian/mrouter.c \
156phone/pfunc.c \ 156phone/pfunc.c \
157phone/at/atgen.c \ 157phone/at/atgen.c \
158phone/at/siemens.c \ 158phone/at/siemens.c \
159phone/at/samsung.c \
159phone/at/sonyeric.c \ 160phone/at/sonyeric.c \
160phone/alcatel/alcatel.c \ 161phone/alcatel/alcatel.c \
161phone/nokia/dct3/n6110.c \ 162phone/nokia/dct3/n6110.c \
162phone/nokia/dct3/n7110.c \ 163phone/nokia/dct3/n7110.c \
163phone/nokia/dct3/n9210.c \ 164phone/nokia/dct3/n9210.c \
164phone/nokia/dct3/dct3func.c \ 165phone/nokia/dct3/dct3func.c \
165phone/nokia/dct4/n3320.c \ 166phone/nokia/dct4/n3320.c \
166phone/nokia/dct4/n3650.c \ 167phone/nokia/dct4/n3650.c \
167phone/nokia/dct4/n6510.c \ 168phone/nokia/dct4/n6510.c \
168phone/nokia/dct4/dct4func.c \ 169phone/nokia/dct4/dct4func.c \
169phone/nokia/nauto.c \ 170phone/nokia/nauto.c \
170phone/nokia/nfunc.c \ 171phone/nokia/nfunc.c \
171phone/nokia/nfuncold.c \ 172phone/nokia/nfuncold.c \
172phone/obex/obexgen.c \ 173phone/obex/obexgen.c \
173phone/symbian/mroutgen.c 174phone/symbian/mroutgen.c
174 175
175DEFINES += DESKTOP_VERSION 176DEFINES += DESKTOP_VERSION
176TARGET = microgammu 177TARGET = microgammu
177CONFIG = warn_off release console 178CONFIG = warn_off release console
178DESTDIR = ../../../bin 179DESTDIR = ../../../bin
179OBJECTS_DIR = obj/unix 180OBJECTS_DIR = obj/unix
180MOC_DIR = moc/unix 181MOC_DIR = moc/unix
181 182
182unix: { 183unix: {
183SOURCES += device/serial/ser_unx.c 184SOURCES += device/serial/ser_unx.c
184} 185}
185win32:{ 186win32:{
186SOURCES += device/serial/ser_w32.c 187SOURCES += device/serial/ser_w32.c
187} 188}
diff --git a/gammu/emb/common/commonE.pro b/gammu/emb/common/commonE.pro
index a36947b..f5b559d 100644
--- a/gammu/emb/common/commonE.pro
+++ b/gammu/emb/common/commonE.pro
@@ -1,180 +1,181 @@
1###################################################################### 1######################################################################
2# Automatically generated by qmake (1.07a) Fri Jul 30 22:13:34 2004 2# Automatically generated by qmake (1.07a) Fri Jul 30 22:13:34 2004
3###################################################################### 3######################################################################
4 4
5TEMPLATE = lib 5TEMPLATE = lib
6DEPENDPATH += device \ 6DEPENDPATH += device \
7 misc \ 7 misc \
8 phone \ 8 phone \
9 protocol \ 9 protocol \
10 service \ 10 service \
11 device/bluetoth \ 11 device/bluetoth \
12 device/irda \ 12 device/irda \
13 device/serial \ 13 device/serial \
14 misc/coding \ 14 misc/coding \
15 phone/alcatel \ 15 phone/alcatel \
16 phone/at \ 16 phone/at \
17 phone/nokia \ 17 phone/nokia \
18 phone/obex \ 18 phone/obex \
19 phone/symbian \ 19 phone/symbian \
20 protocol/alcatel \ 20 protocol/alcatel \
21 protocol/at \ 21 protocol/at \
22 protocol/nokia \ 22 protocol/nokia \
23 protocol/obex \ 23 protocol/obex \
24 protocol/symbian \ 24 protocol/symbian \
25 service/backup \ 25 service/backup \
26 service/sms \ 26 service/sms \
27 phone/nokia/dct3 \ 27 phone/nokia/dct3 \
28 phone/nokia/dct4 28 phone/nokia/dct4
29INCLUDEPATH += . \ 29INCLUDEPATH += . \
30 misc/coding \ 30 misc/coding \
31 misc \ 31 misc \
32 device \ 32 device \
33 phone/nokia/dct4 \ 33 phone/nokia/dct4 \
34 phone/nokia/dct3 \ 34 phone/nokia/dct3 \
35 phone/at \ 35 phone/at \
36 phone/alcatel \ 36 phone/alcatel \
37 phone/obex \ 37 phone/obex \
38 phone/symbian \ 38 phone/symbian \
39 protocol \ 39 protocol \
40 protocol/nokia \ 40 protocol/nokia \
41 protocol/at \ 41 protocol/at \
42 protocol/alcatel \ 42 protocol/alcatel \
43 protocol/obex \ 43 protocol/obex \
44 protocol/symbian \ 44 protocol/symbian \
45 device/serial \ 45 device/serial \
46 device/irda \ 46 device/irda \
47 device/bluetoth \ 47 device/bluetoth \
48 service \ 48 service \
49 service/sms \ 49 service/sms \
50 service/backup \ 50 service/backup \
51 phone/nokia \ 51 phone/nokia \
52 phone 52 phone
53 53
54# Input 54# Input
55HEADERS += config.h \ 55HEADERS += config.h \
56 gammu.h \ 56 gammu.h \
57 gsmcomon.h \ 57 gsmcomon.h \
58 gsmstate.h \ 58 gsmstate.h \
59 device/devfunc.h \ 59 device/devfunc.h \
60 misc/cfg.h \ 60 misc/cfg.h \
61 misc/misc.h \ 61 misc/misc.h \
62 phone/pfunc.h \ 62 phone/pfunc.h \
63 protocol/protocol.h \ 63 protocol/protocol.h \
64 service/gsmcal.h \ 64 service/gsmcal.h \
65 service/gsmcall.h \ 65 service/gsmcall.h \
66 service/gsmdata.h \ 66 service/gsmdata.h \
67 service/gsmlogo.h \ 67 service/gsmlogo.h \
68 service/gsmmisc.h \ 68 service/gsmmisc.h \
69 service/gsmnet.h \ 69 service/gsmnet.h \
70 service/gsmpbk.h \ 70 service/gsmpbk.h \
71 service/gsmprof.h \ 71 service/gsmprof.h \
72 service/gsmring.h \ 72 service/gsmring.h \
73 device/bluetoth/affix.h \ 73 device/bluetoth/affix.h \
74 device/bluetoth/blue_w32.h \ 74 device/bluetoth/blue_w32.h \
75 device/bluetoth/bluetoth.h \ 75 device/bluetoth/bluetoth.h \
76 device/bluetoth/bluez.h \ 76 device/bluetoth/bluez.h \
77 device/irda/irda.h \ 77 device/irda/irda.h \
78 device/irda/irda_unx.h \ 78 device/irda/irda_unx.h \
79 device/irda/irda_w32.h \ 79 device/irda/irda_w32.h \
80 device/serial/ser_djg.h \ 80 device/serial/ser_djg.h \
81 device/serial/ser_unx.h \ 81 device/serial/ser_unx.h \
82 device/serial/ser_w32.h \ 82 device/serial/ser_w32.h \
83 misc/coding/coding.h \ 83 misc/coding/coding.h \
84 misc/coding/md5.h \ 84 misc/coding/md5.h \
85 phone/alcatel/alcatel.h \ 85 phone/alcatel/alcatel.h \
86 phone/at/atgen.h \ 86 phone/at/atgen.h \
87 phone/nokia/ncommon.h \ 87 phone/nokia/ncommon.h \
88 phone/nokia/nfunc.h \ 88 phone/nokia/nfunc.h \
89 phone/nokia/nfuncold.h \ 89 phone/nokia/nfuncold.h \
90 phone/obex/obexgen.h \ 90 phone/obex/obexgen.h \
91 phone/symbian/mroutgen.h \ 91 phone/symbian/mroutgen.h \
92 protocol/alcatel/alcabus.h \ 92 protocol/alcatel/alcabus.h \
93 protocol/at/at.h \ 93 protocol/at/at.h \
94 protocol/nokia/fbus2.h \ 94 protocol/nokia/fbus2.h \
95 protocol/nokia/mbus2.h \ 95 protocol/nokia/mbus2.h \
96 protocol/nokia/phonet.h \ 96 protocol/nokia/phonet.h \
97 protocol/obex/obex.h \ 97 protocol/obex/obex.h \
98 protocol/symbian/mrouter.h \ 98 protocol/symbian/mrouter.h \
99 service/backup/backgen.h \ 99 service/backup/backgen.h \
100 service/backup/backics.h \ 100 service/backup/backics.h \
101 service/backup/backldif.h \ 101 service/backup/backldif.h \
102 service/backup/backlmb.h \ 102 service/backup/backlmb.h \
103 service/backup/backtext.h \ 103 service/backup/backtext.h \
104 service/backup/backvcf.h \ 104 service/backup/backvcf.h \
105 service/backup/backvcs.h \ 105 service/backup/backvcs.h \
106 service/backup/gsmback.h \ 106 service/backup/gsmback.h \
107 service/sms/gsmems.h \ 107 service/sms/gsmems.h \
108 service/sms/gsmmulti.h \ 108 service/sms/gsmmulti.h \
109 service/sms/gsmsms.h \ 109 service/sms/gsmsms.h \
110 phone/nokia/dct3/dct3comm.h \ 110 phone/nokia/dct3/dct3comm.h \
111 phone/nokia/dct3/dct3func.h \ 111 phone/nokia/dct3/dct3func.h \
112 phone/nokia/dct3/n6110.h \ 112 phone/nokia/dct3/n6110.h \
113 phone/nokia/dct3/n7110.h \ 113 phone/nokia/dct3/n7110.h \
114 phone/nokia/dct3/n9210.h \ 114 phone/nokia/dct3/n9210.h \
115 phone/nokia/dct4/dct4func.h \ 115 phone/nokia/dct4/dct4func.h \
116 phone/nokia/dct4/n3320.h \ 116 phone/nokia/dct4/n3320.h \
117 phone/nokia/dct4/n3650.h \ 117 phone/nokia/dct4/n3650.h \
118 phone/nokia/dct4/n6510.h 118 phone/nokia/dct4/n6510.h
119SOURCES +=gsmcomon.c \ 119SOURCES +=gsmcomon.c \
120gsmstate.c \ 120gsmstate.c \
121misc/misc.c \ 121misc/misc.c \
122misc/cfg.c \ 122misc/cfg.c \
123misc/coding/coding.c \ 123misc/coding/coding.c \
124misc/coding/md5.c \ 124misc/coding/md5.c \
125service/sms/gsmsms.c \ 125service/sms/gsmsms.c \
126service/sms/gsmems.c \ 126service/sms/gsmems.c \
127service/sms/gsmmulti.c \ 127service/sms/gsmmulti.c \
128service/gsmcal.c \ 128service/gsmcal.c \
129service/gsmdata.c \ 129service/gsmdata.c \
130service/gsmpbk.c \ 130service/gsmpbk.c \
131service/gsmring.c \ 131service/gsmring.c \
132service/gsmlogo.c \ 132service/gsmlogo.c \
133service/gsmmisc.c \ 133service/gsmmisc.c \
134service/gsmnet.c \ 134service/gsmnet.c \
135service/backup/gsmback.c \ 135service/backup/gsmback.c \
136service/backup/backldif.c \ 136service/backup/backldif.c \
137service/backup/backlmb.c \ 137service/backup/backlmb.c \
138service/backup/backtext.c \ 138service/backup/backtext.c \
139service/backup/backvcs.c \ 139service/backup/backvcs.c \
140service/backup/backvcf.c \ 140service/backup/backvcf.c \
141service/backup/backics.c \ 141service/backup/backics.c \
142device/bluetoth/affix.c \ 142device/bluetoth/affix.c \
143device/bluetoth/bluez.c \ 143device/bluetoth/bluez.c \
144device/bluetoth/blue_w32.c \ 144device/bluetoth/blue_w32.c \
145device/bluetoth/bluetoth.c \ 145device/bluetoth/bluetoth.c \
146device/serial/ser_unx.c \ 146device/serial/ser_unx.c \
147device/serial/ser_djg.c \ 147device/serial/ser_djg.c \
148device/irda/irda.c \ 148device/irda/irda.c \
149device/devfunc.c \ 149device/devfunc.c \
150protocol/at/at.c \ 150protocol/at/at.c \
151protocol/alcatel/alcabus.c \ 151protocol/alcatel/alcabus.c \
152protocol/nokia/mbus2.c \ 152protocol/nokia/mbus2.c \
153protocol/nokia/fbus2.c \ 153protocol/nokia/fbus2.c \
154protocol/nokia/phonet.c \ 154protocol/nokia/phonet.c \
155protocol/obex/obex.c \ 155protocol/obex/obex.c \
156protocol/symbian/mrouter.c \ 156protocol/symbian/mrouter.c \
157phone/pfunc.c \ 157phone/pfunc.c \
158phone/at/atgen.c \ 158phone/at/atgen.c \
159phone/at/siemens.c \ 159phone/at/siemens.c \
160phone/at/samsung.c \
160phone/at/sonyeric.c \ 161phone/at/sonyeric.c \
161phone/alcatel/alcatel.c \ 162phone/alcatel/alcatel.c \
162phone/nokia/dct3/n6110.c \ 163phone/nokia/dct3/n6110.c \
163phone/nokia/dct3/n7110.c \ 164phone/nokia/dct3/n7110.c \
164phone/nokia/dct3/n9210.c \ 165phone/nokia/dct3/n9210.c \
165phone/nokia/dct3/dct3func.c \ 166phone/nokia/dct3/dct3func.c \
166phone/nokia/dct4/n3320.c \ 167phone/nokia/dct4/n3320.c \
167phone/nokia/dct4/n3650.c \ 168phone/nokia/dct4/n3650.c \
168phone/nokia/dct4/n6510.c \ 169phone/nokia/dct4/n6510.c \
169phone/nokia/dct4/dct4func.c \ 170phone/nokia/dct4/dct4func.c \
170phone/nokia/nauto.c \ 171phone/nokia/nauto.c \
171phone/nokia/nfunc.c \ 172phone/nokia/nfunc.c \
172phone/nokia/nfuncold.c \ 173phone/nokia/nfuncold.c \
173phone/obex/obexgen.c \ 174phone/obex/obexgen.c \
174phone/symbian/mroutgen.c 175phone/symbian/mroutgen.c
175 176
176TARGET = kammu 177TARGET = kammu
177DESTDIR = $(QPEDIR)/lib 178DESTDIR = $(QPEDIR)/lib
178OBJECTS_DIR = obj/$(PLATFORM) 179OBJECTS_DIR = obj/$(PLATFORM)
179MOC_DIR = moc/$(PLATFORM) 180MOC_DIR = moc/$(PLATFORM)
180 CONFIG = warn_off release console 181 CONFIG = warn_off release console
diff --git a/gammu/emb/common/device/bluetoth/bluez.c b/gammu/emb/common/device/bluetoth/bluez.c
index 8a4807e..e7e8adf 100644
--- a/gammu/emb/common/device/bluetoth/bluez.c
+++ b/gammu/emb/common/device/bluetoth/bluez.c
@@ -1,207 +1,216 @@
1/* Based on work by Marcel Holtmann and other authors of Bluez */ 1/* Based on some work from Bluez (www.bluez.org)
2 * (C) 2000-2001 Qualcomm Incorporated
3 * (C) 2002-2003 Maxim Krasnyansky <maxk@qualcomm.com>
4 * (C) 2002-2004 Marcel Holtmann <marcel@holtmann.org>
5 * GNU GPL version 2
6 */
7/* based on some Marcel Holtmann work from Gnokii (www.gnokii.org)
8 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
9 * GNU GPL version 2 or later
10 */
2 11
3#include "../../gsmstate.h" 12#include "../../gsmstate.h"
4 13
5#ifdef GSM_ENABLE_BLUETOOTHDEVICE 14#ifdef GSM_ENABLE_BLUETOOTHDEVICE
6#ifdef GSM_ENABLE_BLUEZ 15#ifdef GSM_ENABLE_BLUEZ
7 16
8#include <stdlib.h> 17#include <stdlib.h>
9#include <stdio.h> 18#include <stdio.h>
10#include <fcntl.h> 19#include <fcntl.h>
11#include <errno.h> 20#include <errno.h>
12#include <string.h> 21#include <string.h>
13#include <sys/socket.h> 22#include <sys/socket.h>
14#include <sys/time.h> 23#include <sys/time.h>
15#include <unistd.h> 24#include <unistd.h>
16#include <bluetooth/bluetooth.h> 25#include <bluetooth/bluetooth.h>
17#include <bluetooth/rfcomm.h> 26#include <bluetooth/rfcomm.h>
18#include <bluetooth/sdp.h> 27#include <bluetooth/sdp.h>
19#include <bluetooth/sdp_lib.h> 28#include <bluetooth/sdp_lib.h>
20 29
21#include "../../gsmcomon.h" 30#include "../../gsmcomon.h"
22#include "../devfunc.h" 31#include "../devfunc.h"
23#include "bluetoth.h" 32#include "bluetoth.h"
24 33
25GSM_Error bluetooth_connect(GSM_StateMachine *s, int port, char *device) 34GSM_Error bluetooth_connect(GSM_StateMachine *s, int port, char *device)
26{ 35{
27 GSM_Device_BlueToothData *d = &s->Device.Data.BlueTooth; 36 GSM_Device_BlueToothData *d = &s->Device.Data.BlueTooth;
28 struct sockaddr_rc laddr, raddr; 37 struct sockaddr_rc laddr, raddr;
29 bdaddr_t bdaddr; 38 bdaddr_t bdaddr;
30 int fd; 39 int fd;
31 40
32 smprintf(s, "Connecting to RF channel %i\n",port); 41 smprintf(s, "Connecting to RF channel %i\n",port);
33 42
34 fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); 43 fd = socket(PF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
35 if (fd < 0) { 44 if (fd < 0) {
36 dbgprintf("Can't create socket\n"); 45 dbgprintf("Can't create socket\n");
37 return ERR_DEVICENODRIVER; 46 return ERR_DEVICENODRIVER;
38 } 47 }
39 48
40 bacpy(&laddr.rc_bdaddr, BDADDR_ANY); 49 bacpy(&laddr.rc_bdaddr, BDADDR_ANY);
41 laddr.rc_family = AF_BLUETOOTH; 50 laddr.rc_family = AF_BLUETOOTH;
42 laddr.rc_channel = 0; 51 laddr.rc_channel = 0;
43 52
44 if (bind(fd, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) { 53 if (bind(fd, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) {
45 dbgprintf("Can't bind socket\n"); 54 dbgprintf("Can't bind socket\n");
46 close(fd); 55 close(fd);
47 return ERR_DEVICEOPENERROR; 56 return ERR_DEVICEOPENERROR;
48 } 57 }
49 58
50 str2ba(device, &bdaddr); 59 str2ba(device, &bdaddr);
51 bacpy(&raddr.rc_bdaddr, &bdaddr); 60 bacpy(&raddr.rc_bdaddr, &bdaddr);
52 raddr.rc_family = AF_BLUETOOTH; 61 raddr.rc_family = AF_BLUETOOTH;
53 raddr.rc_channel = port; 62 raddr.rc_channel = port;
54 63
55 if (connect(fd, (struct sockaddr *)&raddr, sizeof(raddr)) < 0) { 64 if (connect(fd, (struct sockaddr *)&raddr, sizeof(raddr)) < 0) {
56 dbgprintf("Can't connect\n"); 65 dbgprintf("Can't connect\n");
57 close(fd); 66 close(fd);
58 return ERR_DEVICEOPENERROR; 67 return ERR_DEVICEOPENERROR;
59 } 68 }
60 69
61 d->hPhone = fd; 70 d->hPhone = fd;
62 return ERR_NONE; 71 return ERR_NONE;
63} 72}
64 73
65#ifdef BLUETOOTH_RF_SEARCHING 74#ifdef BLUETOOTH_RF_SEARCHING
66 75
67struct search_context { 76struct search_context {
68 char *svc; 77 char *svc;
69 uuid_t group; 78 uuid_t group;
70 int tree; 79 int tree;
71 uint32_t handle; 80 uint32_t handle;
72}; 81};
73 82
74static void print_service_desc(void *value, void *user) 83static void print_service_desc(void *value, void *user)
75{ 84{
76 sdp_data_t *p = (sdp_data_t *)value; 85 sdp_data_t *p = (sdp_data_t *)value;
77 int i = 0, proto = 0, *channel = (int *)user; 86 int i = 0, proto = 0, *channel = (int *)user;
78 87
79 for (; p; p = p->next, i++) { 88 for (; p; p = p->next, i++) {
80 switch (p->dtd) { 89 switch (p->dtd) {
81 case SDP_UUID16: 90 case SDP_UUID16:
82 case SDP_UUID32: 91 case SDP_UUID32:
83 case SDP_UUID128: 92 case SDP_UUID128:
84 proto = 1;//sdp_uuid_to_proto(&p->val.uuid); 93 proto = sdp_uuid_to_proto(&p->val.uuid);
85 break; 94 break;
86 case SDP_UINT8: 95 case SDP_UINT8:
87 if (proto == RFCOMM_UUID) { 96 if (proto == RFCOMM_UUID) {
88 (*channel) = p->val.uint8; 97 (*channel) = p->val.uint8;
89 return; 98 return;
90 } 99 }
91 break; 100 break;
92 } 101 }
93 } 102 }
94} 103}
95 104
96void print_access_protos(value, user) 105void print_access_protos(value, user)
97{ 106{
98 sdp_list_t *protDescSeq = (sdp_list_t *)value; 107 sdp_list_t *protDescSeq = (sdp_list_t *)value;
99 int *channel = (int *)user; 108 int *channel = (int *)user;
100 109
101 sdp_list_foreach(protDescSeq,print_service_desc,channel); 110 sdp_list_foreach(protDescSeq,print_service_desc,channel);
102} 111}
103 112
104static GSM_Error bluetooth_checkdevice(GSM_StateMachine *s, bdaddr_t *bdaddr, struct search_context *context) 113static GSM_Error bluetooth_checkdevice(GSM_StateMachine *s, bdaddr_t *bdaddr, struct search_context *context)
105{ 114{
106 sdp_session_t *sess; 115 sdp_session_t *sess;
107 sdp_list_t *attrid, *search, *seq, *next, *proto = 0;
108 uint32_t range = 0x0000ffff;
109 char str[20];
110 sdp_record_t *rec; 116 sdp_record_t *rec;
117 sdp_list_t *attrid, *search, *seq, *next, *proto = 0;
111 sdp_data_t *d; 118 sdp_data_t *d;
112 bdaddr_t interface; 119 bdaddr_t interface;
120 uint32_t range = 0x0000ffff;
113 struct search_context subcontext; 121 struct search_context subcontext;
122 char str[20];
114 int channel,channel2; 123 int channel,channel2;
115 124
116 bacpy(&interface,BDADDR_ANY); 125 bacpy(&interface,BDADDR_ANY);
117 126
118 ba2str(bdaddr, str); 127 ba2str(bdaddr, str);
119 smprintf(s,"%s\n", str); 128 smprintf(s,"%s\n", str);
120 129
121 sess = sdp_connect(&interface, bdaddr, SDP_RETRY_IF_BUSY); 130 sess = sdp_connect(&interface, bdaddr, SDP_RETRY_IF_BUSY);
122 if (!sess) { 131 if (!sess) {
123 dbgprintf("Failed to connect to SDP server on %s: %s\n", str, strerror(errno)); 132 dbgprintf("Failed to connect to SDP server on %s: %s\n", str, strerror(errno));
124 return ERR_UNKNOWN; 133 return ERR_UNKNOWN;
125 } 134 }
126 135
127 attrid = sdp_list_append(0, &range); 136 attrid = sdp_list_append(0, &range);
128 search = sdp_list_append(0, &context->group); 137 search = sdp_list_append(0, &context->group);
129 if (sdp_service_search_attr_req(sess, search, SDP_ATTR_REQ_RANGE, attrid, &seq)) { 138 if (sdp_service_search_attr_req(sess, search, SDP_ATTR_REQ_RANGE, attrid, &seq)) {
130 dbgprintf("Service Search failed: %s\n", strerror(errno)); 139 dbgprintf("Service Search failed: %s\n", strerror(errno));
131 sdp_close(sess); 140 sdp_close(sess);
132 return ERR_UNKNOWN; 141 return ERR_UNKNOWN;
133 } 142 }
134 sdp_list_free(attrid, 0); 143 sdp_list_free(attrid, 0);
135 sdp_list_free(search, 0); 144 sdp_list_free(search, 0);
136 145
137 channel2 = -1; 146 channel2 = -1;
138 for (; seq; seq = next) { 147 for (; seq; seq = next) {
139 rec = (sdp_record_t *) seq->data; 148 rec = (sdp_record_t *) seq->data;
140 149
141 if (channel2 == -1) { 150 if (channel2 == -1) {
142 if (!context->tree) { 151 if (!context->tree) {
143 d = sdp_data_get(rec,SDP_ATTR_SVCNAME_PRIMARY); 152 d = sdp_data_get(rec,SDP_ATTR_SVCNAME_PRIMARY);
144 153
145 if (false) { 154 if (sdp_get_access_protos(rec,&proto) == 0) {
146 channel = -1; 155 channel = -1;
147 sdp_list_foreach(proto,print_access_protos,&channel); 156 sdp_list_foreach(proto,print_access_protos,&channel);
148 //sdp_list_free(proto,(sdp_free_func_t)sdp_data_free); 157 sdp_list_free(proto,(sdp_free_func_t)sdp_data_free);
149 } 158 }
150 smprintf(s,"Channel %i",channel); 159 smprintf(s,"Channel %i",channel);
151 if (d) smprintf(s," - \"%s\"",d->val.str); 160 if (d) smprintf(s," - \"%s\"",d->val.str);
152 smprintf(s,"\n"); 161 smprintf(s,"\n");
153 if (channel2 == -1 && bluetooth_checkservicename(s, d->val.str) == ERR_NONE) { 162 if (channel2 == -1 && bluetooth_checkservicename(s, d->val.str) == ERR_NONE) {
154 channel2 = channel; 163 channel2 = channel;
155 } 164 }
156 } 165 }
157 if (sdp_get_group_id(rec,&subcontext.group) != -1) { 166 if (sdp_get_group_id(rec,&subcontext.group) != -1) {
158 memcpy(&subcontext, context, sizeof(struct search_context)); 167 memcpy(&subcontext, context, sizeof(struct search_context));
159 if (subcontext.group.value.uuid16 != context->group.value.uuid16) bluetooth_checkdevice(s,bdaddr,&subcontext); 168 if (subcontext.group.value.uuid16 != context->group.value.uuid16) bluetooth_checkdevice(s,bdaddr,&subcontext);
160 } 169 }
161 } 170 }
162 171
163 next = seq->next; 172 next = seq->next;
164 free(seq); 173 free(seq);
165 //sdp_record_free(rec); 174 sdp_record_free(rec);
166 } 175 }
167 sdp_close(sess); 176 sdp_close(sess);
168 177
169 if (channel2 != -1) return bluetooth_connect(s, channel2, str); 178 if (channel2 != -1) return bluetooth_connect(s, channel2, str);
170 179
171 return ERR_UNKNOWN; 180 return ERR_NOTSUPPORTED;
172} 181}
173 182
174GSM_Error bluetooth_findchannel(GSM_StateMachine *s) 183GSM_Error bluetooth_findchannel(GSM_StateMachine *s)
175{ 184{
176 inquiry_info ii[20]; 185 inquiry_info ii[20];
177 uint8_t count = 0; 186 uint8_t count = 0;
178 int i; 187 int i;
179 struct search_context context; 188 struct search_context context;
180 GSM_Error error = ERR_NOTSUPPORTED; 189 GSM_Error error = ERR_NOTSUPPORTED;
181 190
182 memset(&context, '\0', sizeof(struct search_context)); 191 memset(&context, '\0', sizeof(struct search_context));
183 //sdp_uuid16_create(&(context.group),PUBLIC_BROWSE_GROUP); 192 sdp_uuid16_create(&(context.group),PUBLIC_BROWSE_GROUP);
184 193
185 if (!strcmp(s->CurrentConfig->Device,"/dev/ttyS1")) { 194 if (!strcmp(s->CurrentConfig->Device,"/dev/ttyS1")) {
186 dbgprintf("Searching for devices\n"); 195 dbgprintf("Searching for devices\n");
187 if (sdp_general_inquiry(ii, 20, 8, &count) < 0) { 196 if (sdp_general_inquiry(ii, 20, 8, &count) < 0) {
188 return ERR_UNKNOWN; 197 return ERR_UNKNOWN;
189 } 198 }
190 } else { 199 } else {
191 count = 1; 200 count = 1;
192 str2ba(s->CurrentConfig->Device,&ii[0].bdaddr); 201 str2ba(s->CurrentConfig->Device,&ii[0].bdaddr);
193 } 202 }
194 for (i=0;i<count;i++) { 203 for (i=0;i<count;i++) {
195 error = bluetooth_checkdevice(s,&ii[i].bdaddr,&context); 204 error = bluetooth_checkdevice(s,&ii[i].bdaddr,&context);
196 if (error == ERR_NONE) return error; 205 if (error == ERR_NONE) return error;
197 } 206 }
198 return error; 207 return error;
199} 208}
200 209
201#endif 210#endif
202#endif 211#endif
203#endif 212#endif
204 213
205/* How should editor hadle tabs in this file? Add editor commands here. 214/* How should editor hadle tabs in this file? Add editor commands here.
206 * vim: noexpandtab sw=8 ts=8 sts=8: 215 * vim: noexpandtab sw=8 ts=8 sts=8:
207 */ 216 */
diff --git a/gammu/emb/common/device/devfunc.c b/gammu/emb/common/device/devfunc.c
index d31ebbf..c58a01f 100644
--- a/gammu/emb/common/device/devfunc.c
+++ b/gammu/emb/common/device/devfunc.c
@@ -1,266 +1,274 @@
1/* Some source from Gnokii (www.gnokii.org)
2 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
3 * GNU GPL version 2 or later
4 */
5/* Some source from Minicom (http://alioth.debian.org/projects/minicom)
6 * (C) 1991,1992,1993,1994,1995,1996 by Miquel van Smoorenburg
7 * GNU GPL version 2
8 */
1 9
2#include <string.h> 10#include <string.h>
3#ifdef WIN32 11#ifdef WIN32
4# include <io.h> 12# include <io.h>
5#else 13#else
6# include <errno.h> 14# include <errno.h>
7# include <signal.h> 15# include <signal.h>
8#endif 16#endif
9 17
10#include "../gsmstate.h" 18#include "../gsmstate.h"
11 19
12#ifdef GSM_ENABLE_BLUETOOTHDEVICE 20#ifdef GSM_ENABLE_BLUETOOTHDEVICE
13#ifdef BLUETOOTH_RF_SEARCHING 21#ifdef BLUETOOTH_RF_SEARCHING
14 22
15GSM_Error bluetooth_checkservicename(GSM_StateMachine *s, char *name) 23GSM_Error bluetooth_checkservicename(GSM_StateMachine *s, char *name)
16{ 24{
17 if (s->ConnectionType == GCT_BLUEPHONET && strstr(name,"Nokia PC Suite")!=NULL) return ERR_NONE; 25 if (s->ConnectionType == GCT_BLUEPHONET && strstr(name,"Nokia PC Suite")!=NULL) return ERR_NONE;
18 if (s->ConnectionType == GCT_BLUEOBEX && strstr(name,"OBEX") !=NULL) return ERR_NONE; 26 if (s->ConnectionType == GCT_BLUEOBEX && strstr(name,"OBEX") !=NULL) return ERR_NONE;
19 if (s->ConnectionType == GCT_BLUEAT && strstr(name,"COM 1") !=NULL) return ERR_NONE; 27 if (s->ConnectionType == GCT_BLUEAT && strstr(name,"COM 1") !=NULL) return ERR_NONE;
20 return ERR_UNKNOWN; 28 return ERR_UNKNOWN;
21} 29}
22 30
23#endif 31#endif
24#endif 32#endif
25 33
26#if defined (GSM_ENABLE_BLUETOOTHDEVICE) || defined (GSM_ENABLE_IRDADEVICE) 34#if defined (GSM_ENABLE_BLUETOOTHDEVICE) || defined (GSM_ENABLE_IRDADEVICE)
27 35
28int socket_read(GSM_StateMachine *s, void *buf, size_t nbytes, int hPhone) 36int socket_read(GSM_StateMachine *s, void *buf, size_t nbytes, int hPhone)
29{ 37{
30 fd_set readfds; 38 fd_set readfds;
31#ifdef WIN32 39#ifdef WIN32
32 struct timeval timer; 40 struct timeval timer;
33#endif 41#endif
34 42
35 FD_ZERO(&readfds); 43 FD_ZERO(&readfds);
36 FD_SET(hPhone, &readfds); 44 FD_SET(hPhone, &readfds);
37#ifndef WIN32 45#ifndef WIN32
38 if (select(hPhone+1, &readfds, NULL, NULL, 0)) { 46 if (select(hPhone+1, &readfds, NULL, NULL, 0)) {
39 return(read(hPhone, buf, nbytes)); 47 return(read(hPhone, buf, nbytes));
40 } 48 }
41#else 49#else
42 memset(&timer,0,sizeof(timer)); 50 memset(&timer,0,sizeof(timer));
43 if (select(0, &readfds, NULL, NULL, &timer) != 0) { 51 if (select(0, &readfds, NULL, NULL, &timer) != 0) {
44 return(recv(hPhone, buf, nbytes, 0)); 52 return(recv(hPhone, buf, nbytes, 0));
45 } 53 }
46#endif 54#endif
47 return 0; 55 return 0;
48} 56}
49 57
50#ifdef WIN32 58#ifdef WIN32
51int socket_write(GSM_StateMachine *s, unsigned char *buf, size_t nbytes, int hPhone) 59int socket_write(GSM_StateMachine *s, unsigned char *buf, size_t nbytes, int hPhone)
52#else 60#else
53int socket_write(GSM_StateMachine *s, void *buf, size_t nbytes, int hPhone) 61int socket_write(GSM_StateMachine *s, void *buf, size_t nbytes, int hPhone)
54#endif 62#endif
55{ 63{
56 int ret; 64 int ret;
57 size_t actual = 0; 65 size_t actual = 0;
58 66
59 do { 67 do {
60 ret = send(hPhone, buf, nbytes - actual, 0); 68 ret = send(hPhone, buf, nbytes - actual, 0);
61 if (ret < 0) { 69 if (ret < 0) {
62 if (actual != nbytes) GSM_OSErrorInfo(s,"socket_write"); 70 if (actual != nbytes) GSM_OSErrorInfo(s,"socket_write");
63 return actual; 71 return actual;
64 } 72 }
65 actual += ret; 73 actual += ret;
66 buf += ret; 74 buf += ret;
67 } while (actual < nbytes); 75 } while (actual < nbytes);
68 76
69 return actual; 77 return actual;
70} 78}
71 79
72GSM_Error socket_close(GSM_StateMachine *s, int hPhone) 80GSM_Error socket_close(GSM_StateMachine *s, int hPhone)
73{ 81{
74 shutdown(hPhone, 0); 82 shutdown(hPhone, 0);
75#ifdef WIN32 83#ifdef WIN32
76 closesocket(hPhone); /*FIXME: error checking */ 84 closesocket(hPhone); /*FIXME: error checking */
77#else 85#else
78 close(hPhone); /*FIXME: error checking */ 86 close(hPhone); /*FIXME: error checking */
79#endif 87#endif
80 return ERR_NONE; 88 return ERR_NONE;
81} 89}
82 90
83#endif 91#endif
84 92
85#ifdef ENABLE_LGPL 93#ifdef ENABLE_LGPL
86 94
87GSM_Error lock_device(const char* port, char **lock_device) 95GSM_Error lock_device(const char* port, char **lock_device)
88{ 96{
89 *lock_device = 0; 97 *lock_device = 0;
90 return ERR_NONE; 98 return ERR_NONE;
91} 99}
92 100
93bool unlock_device(char **lock_file) 101bool unlock_device(char **lock_file)
94{ 102{
95 return true; 103 return true;
96} 104}
97 105
98#else 106#else
99 107
100 #define max_buf_len 128 108 #define max_buf_len 128
101 #define lock_path "/var/lock/LCK.." 109 #define lock_path "/var/lock/LCK.."
102 110
103/* Lock the device. Allocated string with a lock name is returned 111/* Lock the device. Allocated string with a lock name is returned
104 * in lock_device 112 * in lock_device
105 */ 113 */
106GSM_Error lock_device(const char* port, char **lock_device) 114GSM_Error lock_device(const char* port, char **lock_device)
107{ 115{
108#ifndef WIN32 116#if !defined(WIN32) && !defined(DJGPP)
109 char *lock_file = NULL; 117 char *lock_file = NULL;
110 char buffer[max_buf_len]; 118 char buffer[max_buf_len];
111 const char *aux; 119 const char *aux;
112 int fd, len; 120 int fd, len;
113 GSM_Errorerror = ERR_NONE; 121 GSM_Errorerror = ERR_NONE;
114 122
115 dbgprintf("Locking device\n"); 123 dbgprintf("Locking device\n");
116 124
117 aux = strrchr(port, '/'); 125 aux = strrchr(port, '/');
118 /* Remove leading '/' */ 126 /* Remove leading '/' */
119 if (aux) { 127 if (aux) {
120 aux++; 128 aux++;
121 } else { 129 } else {
122 /* No / in port */ 130 /* No / in port */
123 aux = port; 131 aux = port;
124 } 132 }
125 len = strlen(aux) + strlen(lock_path); 133 len = strlen(aux) + strlen(lock_path);
126 134
127 memset(buffer, 0, sizeof(buffer)); 135 memset(buffer, 0, sizeof(buffer));
128 lock_file = calloc(len + 1, 1); 136 lock_file = calloc(len + 1, 1);
129 if (!lock_file) { 137 if (!lock_file) {
130 dbgprintf("Out of memory error while locking device\n"); 138 dbgprintf("Out of memory error while locking device\n");
131 return ERR_MOREMEMORY; 139 return ERR_MOREMEMORY;
132 } 140 }
133 /* I think we don't need to use strncpy, as we should have enough 141 /* I think we don't need to use strncpy, as we should have enough
134 * buffer due to strlen results 142 * buffer due to strlen results
135 */ 143 */
136 strcpy(lock_file, lock_path); 144 strcpy(lock_file, lock_path);
137 strcat(lock_file, aux); 145 strcat(lock_file, aux);
138 146
139 /* Check for the stale lockfile. 147 /* Check for the stale lockfile.
140 * The code taken from minicom by Miquel van Smoorenburg */ 148 * The code taken from minicom by Miquel van Smoorenburg */
141 if ((fd = open(lock_file, O_RDONLY)) >= 0) { 149 if ((fd = open(lock_file, O_RDONLY)) >= 0) {
142 char buf[max_buf_len]; 150 char buf[max_buf_len];
143 int pid, n = 0; 151 int pid, n = 0;
144 152
145 n = read(fd, buf, sizeof(buf) - 1); 153 n = read(fd, buf, sizeof(buf) - 1);
146 close(fd); 154 close(fd);
147 if (n > 0) { 155 if (n > 0) {
148 pid = -1; 156 pid = -1;
149 if (n == 4) 157 if (n == 4)
150 /* Kermit-style lockfile. */ 158 /* Kermit-style lockfile. */
151 pid = *(int *)buf; 159 pid = *(int *)buf;
152 else { 160 else {
153 /* Ascii lockfile. */ 161 /* Ascii lockfile. */
154 buf[n] = 0; 162 buf[n] = 0;
155 sscanf(buf, "%d", &pid); 163 sscanf(buf, "%d", &pid);
156 } 164 }
157 if (pid > 0 && kill((pid_t)pid, 0) < 0 && errno == ESRCH) { 165 if (pid > 0 && kill((pid_t)pid, 0) < 0 && errno == ESRCH) {
158 dbgprintf("Lockfile %s is stale. Overriding it..\n", lock_file); 166 dbgprintf("Lockfile %s is stale. Overriding it..\n", lock_file);
159 sleep(1); 167 sleep(1);
160 if (unlink(lock_file) == -1) { 168 if (unlink(lock_file) == -1) {
161 dbgprintf("Overriding failed, please check the permissions\n"); 169 dbgprintf("Overriding failed, please check the permissions\n");
162 dbgprintf("Cannot lock device\n"); 170 dbgprintf("Cannot lock device\n");
163 error = ERR_PERMISSION; 171 error = ERR_PERMISSION;
164 goto failed; 172 goto failed;
165 } 173 }
166 } else { 174 } else {
167 dbgprintf("Device already locked by PID %d.\n", pid); 175 dbgprintf("Device already locked by PID %d.\n", pid);
168 error = ERR_DEVICELOCKED; 176 error = ERR_DEVICELOCKED;
169 goto failed; 177 goto failed;
170 } 178 }
171 } 179 }
172 /* this must not happen. because we could open the file */ 180 /* this must not happen. because we could open the file */
173 /* no wrong permissions are set. only reason could be */ 181 /* no wrong permissions are set. only reason could be */
174 /* flock/lockf or a empty lockfile due to a broken binary */ 182 /* flock/lockf or a empty lockfile due to a broken binary */
175 /* which is more likely */ 183 /* which is more likely */
176 if (n == 0) { 184 if (n == 0) {
177 dbgprintf("Unable to read lockfile %s.\n", lock_file); 185 dbgprintf("Unable to read lockfile %s.\n", lock_file);
178 dbgprintf("Please check for reason and remove the lockfile by hand.\n"); 186 dbgprintf("Please check for reason and remove the lockfile by hand.\n");
179 dbgprintf("Cannot lock device\n"); 187 dbgprintf("Cannot lock device\n");
180 error = ERR_UNKNOWN; 188 error = ERR_UNKNOWN;
181 goto failed; 189 goto failed;
182 } 190 }
183 } 191 }
184 192
185 /* Try to create a new file, with 0644 mode */ 193 /* Try to create a new file, with 0644 mode */
186 fd = open(lock_file, O_CREAT | O_EXCL | O_WRONLY, 0644); 194 fd = open(lock_file, O_CREAT | O_EXCL | O_WRONLY, 0644);
187 if (fd == -1) { 195 if (fd == -1) {
188 if (errno == EEXIST) { 196 if (errno == EEXIST) {
189 dbgprintf("Device seems to be locked by unknown process\n"); 197 dbgprintf("Device seems to be locked by unknown process\n");
190 error = ERR_DEVICEOPENERROR; 198 error = ERR_DEVICEOPENERROR;
191 } else if (errno == EACCES) { 199 } else if (errno == EACCES) {
192 dbgprintf("Please check permission on lock directory\n"); 200 dbgprintf("Please check permission on lock directory\n");
193 error = ERR_PERMISSION; 201 error = ERR_PERMISSION;
194 } else if (errno == ENOENT) { 202 } else if (errno == ENOENT) {
195 dbgprintf("Cannot create lockfile %s. Please check for existence of path\n", lock_file); 203 dbgprintf("Cannot create lockfile %s. Please check for existence of path\n", lock_file);
196 error = ERR_UNKNOWN; 204 error = ERR_UNKNOWN;
197 } else { 205 } else {
198 dbgprintf("Unknown error with creating lockfile %s\n", lock_file); 206 dbgprintf("Unknown error with creating lockfile %s\n", lock_file);
199 error = ERR_UNKNOWN; 207 error = ERR_UNKNOWN;
200 } 208 }
201 goto failed; 209 goto failed;
202 } 210 }
203 sprintf(buffer, "%10ld gammu\n", (long)getpid()); 211 sprintf(buffer, "%10ld gammu\n", (long)getpid());
204 write(fd, buffer, strlen(buffer)); 212 write(fd, buffer, strlen(buffer));
205 close(fd); 213 close(fd);
206 *lock_device = lock_file; 214 *lock_device = lock_file;
207 return ERR_NONE; 215 return ERR_NONE;
208failed: 216failed:
209 free(lock_file); 217 free(lock_file);
210 *lock_device = 0; 218 *lock_device = 0;
211 return error; 219 return error;
212#else 220#else
213 *lock_device = 0; 221 *lock_device = 0;
214 return ERR_NONE; 222 return ERR_NONE;
215#endif 223#endif
216} 224}
217 225
218/* Removes lock and frees memory */ 226/* Removes lock and frees memory */
219bool unlock_device(char **lock_file) 227bool unlock_device(char **lock_file)
220{ 228{
221#ifndef WIN32 229#if !defined(WIN32) && !defined(DJGPP)
222 int err; 230 int err;
223 231
224 if (!lock_file) { 232 if (!lock_file) {
225 dbgprintf("Cannot unlock device\n"); 233 dbgprintf("Cannot unlock device\n");
226 return false; 234 return false;
227 } 235 }
228 err = unlink(*lock_file); 236 err = unlink(*lock_file);
229 free(*lock_file); 237 free(*lock_file);
230 *lock_file = NULL; 238 *lock_file = NULL;
231 return (err + 1); 239 return (err + 1);
232#else 240#else
233 return true; 241 return true;
234#endif 242#endif
235} 243}
236 244
237#endif 245#endif
238 246
239int FindSerialSpeed(char *buffer) 247int FindSerialSpeed(char *buffer)
240{ 248{
241 switch (atoi(buffer)) { 249 switch (atoi(buffer)) {
242 case 50 : return 50; 250 case 50 : return 50;
243 case 75 : return 75; 251 case 75 : return 75;
244 case 110: return 110; 252 case 110: return 110;
245 case 134: return 134; 253 case 134: return 134;
246 case 150: return 150; 254 case 150: return 150;
247 case 200: return 200; 255 case 200: return 200;
248 case 300: return 300; 256 case 300: return 300;
249 case 600: return 600; 257 case 600: return 600;
250 case 1200: return 1200; 258 case 1200: return 1200;
251 case 1800: return 1800; 259 case 1800: return 1800;
252 case 2400: return 2400; 260 case 2400: return 2400;
253 case 4800: return 4800; 261 case 4800: return 4800;
254 case 9600: return 9600; 262 case 9600: return 9600;
255 case 19200: return 19200; 263 case 19200: return 19200;
256 case 38400: return 38400; 264 case 38400: return 38400;
257 case 57600: return 57600; 265 case 57600: return 57600;
258 case 115200: return 115200; 266 case 115200: return 115200;
259 case 230400: return 230400; 267 case 230400: return 230400;
260 default : return 0; 268 default : return 0;
261 } 269 }
262} 270}
263 271
264/* How should editor hadle tabs in this file? Add editor commands here. 272/* How should editor hadle tabs in this file? Add editor commands here.
265 * vim: noexpandtab sw=8 ts=8 sts=8: 273 * vim: noexpandtab sw=8 ts=8 sts=8:
266 */ 274 */
diff --git a/gammu/emb/common/device/irda/irda.c b/gammu/emb/common/device/irda/irda.c
index fef50ac..e680377 100644
--- a/gammu/emb/common/device/irda/irda.c
+++ b/gammu/emb/common/device/irda/irda.c
@@ -1,187 +1,191 @@
1/* (c) 2001-2004 by Marcin Wiacek */ 1/* (c) 2001-2004 by Marcin Wiacek */
2/* based on some work from Ralf Thelen and MyGnokii */ 2/* based on some work from Ralf Thelen and MyGnokii (www.mwiacek.com) */
3/* based on some work from Gnokii and MSDN */ 3/* based on some work from MSDN */
4/* based on some work from Gnokii (www.gnokii.org)
5 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
6 * GNU GPL version 2 or later
7 */
4 8
5/* You have to include wsock32.lib library to MS VC project to compile it */ 9/* You have to include wsock32.lib library to MS VC project to compile it */
6 10
7#include "../../gsmstate.h" 11#include "../../gsmstate.h"
8 12
9#ifdef GSM_ENABLE_IRDADEVICE 13#ifdef GSM_ENABLE_IRDADEVICE
10#ifndef DJGPP 14#ifndef DJGPP
11 15
12#ifndef WIN32 16#ifndef WIN32
13# include <stdlib.h> 17# include <stdlib.h>
14# include <unistd.h> 18# include <unistd.h>
15# include <stdio.h> 19# include <stdio.h>
16# include <fcntl.h> 20# include <fcntl.h>
17# include <errno.h> 21# include <errno.h>
18# include <string.h> 22# include <string.h>
19# include <sys/time.h> 23# include <sys/time.h>
20# include <sys/poll.h> 24# include <sys/poll.h>
21# include <sys/socket.h> 25# include <sys/socket.h>
22# include <sys/ioctl.h> 26# include <sys/ioctl.h>
23#else 27#else
24# include <windows.h> 28# include <windows.h>
25# include <io.h> 29# include <io.h>
26#endif 30#endif
27 31
28#include "../../gsmcomon.h" 32#include "../../gsmcomon.h"
29#include "../devfunc.h" 33#include "../devfunc.h"
30#include "irda.h" 34#include "irda.h"
31 35
32static bool irda_discover_device(GSM_StateMachine *state) 36static bool irda_discover_device(GSM_StateMachine *state)
33{ 37{
34 GSM_Device_IrdaData *d = &state->Device.Data.Irda; 38 GSM_Device_IrdaData *d = &state->Device.Data.Irda;
35 struct irda_device_list*list; 39 struct irda_device_list*list;
36 unsigned char *buf; 40 unsigned char *buf;
37 unsigned int sec; 41 unsigned int sec;
38 int s, z, len, fd, i; 42 int s, z, len, fd, i;
39 GSM_DateTime Date; 43 GSM_DateTime Date;
40 bool founddevice = false; 44 bool founddevice = false;
41#ifdef WIN32 45#ifdef WIN32
42 int index; 46 int index;
43#endif 47#endif
44 48
45 fd = socket(AF_IRDA, SOCK_STREAM, 0); 49 fd = socket(AF_IRDA, SOCK_STREAM, 0);
46 50
47 /* can handle maximally 10 devices during discovering */ 51 /* can handle maximally 10 devices during discovering */
48 len = sizeof(struct irda_device_list) + sizeof(struct irda_device_info) * 10; 52 len = sizeof(struct irda_device_list) + sizeof(struct irda_device_info) * 10;
49 buf = malloc(len); 53 buf = malloc(len);
50 list = (struct irda_device_list *)buf; 54 list = (struct irda_device_list *)buf;
51 55
52 /* Trying to find device during 2 seconds */ 56 /* Trying to find device during 2 seconds */
53 for (z=0;z<2;z++) { 57 for (z=0;z<2;z++) {
54 GSM_GetCurrentDateTime (&Date); 58 GSM_GetCurrentDateTime (&Date);
55 sec = Date.Second; 59 sec = Date.Second;
56 while (sec==Date.Second) { 60 while (sec==Date.Second) {
57 s = len; 61 s = len;
58 memset(buf, 0, s); 62 memset(buf, 0, s);
59 63
60 if (getsockopt(fd, SOL_IRLMP, IRLMP_ENUMDEVICES, buf, &s) == 0) { 64 if (getsockopt(fd, SOL_IRLMP, IRLMP_ENUMDEVICES, buf, &s) == 0) {
61 for (i = 0; i < (int)list->numDevice; i++) { 65 for (i = 0; i < (int)list->numDevice; i++) {
62 dbgprintf("Irda: found device \"%s\" (address %x) - ",list->Device[i].irdaDeviceName,list->Device[i].irdaDeviceID); 66 dbgprintf("Irda: found device \"%s\" (address %x) - ",list->Device[i].irdaDeviceName,list->Device[i].irdaDeviceID);
63 if (strcmp(GetModelData(NULL,NULL,list->Device[i].irdaDeviceName)->number,"") != 0) { 67 if (strcmp(GetModelData(NULL,NULL,list->Device[i].irdaDeviceName)->number,"") != 0) {
64 founddevice = true; 68 founddevice = true;
65 /* Model AUTO */ 69 /* Model AUTO */
66 if (state->CurrentConfig->Model[0]==0) strcpy(state->Phone.Data.Model,GetModelData(NULL,NULL,list->Device[i].irdaDeviceName)->number); 70 if (state->CurrentConfig->Model[0]==0) strcpy(state->Phone.Data.Model,GetModelData(NULL,NULL,list->Device[i].irdaDeviceName)->number);
67 state->Phone.Data.ModelInfo = GetModelData(NULL,state->Phone.Data.Model,NULL); 71 state->Phone.Data.ModelInfo = GetModelData(NULL,state->Phone.Data.Model,NULL);
68 } 72 }
69 if (founddevice) { 73 if (founddevice) {
70 dbgprintf("correct\n"); 74 dbgprintf("correct\n");
71#ifdef WIN32 75#ifdef WIN32
72 for(index=0; index <= 3; index++) 76 for(index=0; index <= 3; index++)
73 d->peer.irdaDeviceID[index] = list->Device[i].irdaDeviceID[index]; 77 d->peer.irdaDeviceID[index] = list->Device[i].irdaDeviceID[index];
74#else 78#else
75 d->peer.irdaDeviceID = list->Device[i].irdaDeviceID; 79 d->peer.irdaDeviceID = list->Device[i].irdaDeviceID;
76#endif 80#endif
77 break; 81 break;
78 } 82 }
79 dbgprintf("\n"); 83 dbgprintf("\n");
80 } 84 }
81 } 85 }
82 if (founddevice) break; 86 if (founddevice) break;
83 my_sleep(10); 87 my_sleep(10);
84 GSM_GetCurrentDateTime(&Date); 88 GSM_GetCurrentDateTime(&Date);
85 } 89 }
86 if (founddevice) break; 90 if (founddevice) break;
87 } 91 }
88 free(buf); 92 free(buf);
89 close(fd); 93 close(fd);
90 94
91 return founddevice; 95 return founddevice;
92} 96}
93 97
94static GSM_Error irda_open (GSM_StateMachine *s) 98static GSM_Error irda_open (GSM_StateMachine *s)
95{ 99{
96 GSM_Device_IrdaData *d = &s->Device.Data.Irda; 100 GSM_Device_IrdaData *d = &s->Device.Data.Irda;
97 int fd = -1; 101 int fd = -1;
98#ifdef WIN32 102#ifdef WIN32
99 int Enable9WireMode = 1; 103 int Enable9WireMode = 1;
100 WSADATA wsaData; 104 WSADATA wsaData;
101 105
102 WSAStartup(MAKEWORD(1,1), &wsaData); 106 WSAStartup(MAKEWORD(1,1), &wsaData);
103#else 107#else
104 if (s->ConnectionType == GCT_IRDAAT) return ERR_SOURCENOTAVAILABLE; 108 if (s->ConnectionType == GCT_IRDAAT) return ERR_SOURCENOTAVAILABLE;
105#endif 109#endif
106 110
107 /* discovering devices */ 111 /* discovering devices */
108 if (irda_discover_device(s)==false) return ERR_TIMEOUT; 112 if (irda_discover_device(s)==false) return ERR_TIMEOUT;
109 113
110 /* Creating socket */ 114 /* Creating socket */
111 fd = socket(AF_IRDA, SOCK_STREAM, 0); 115 fd = socket(AF_IRDA, SOCK_STREAM, 0);
112 116
113 d->peer.irdaAddressFamily = AF_IRDA; 117 d->peer.irdaAddressFamily = AF_IRDA;
114#ifndef WIN32 118#ifndef WIN32
115 d->peer.sir_lsap_sel = LSAP_ANY; 119 d->peer.sir_lsap_sel = LSAP_ANY;
116#endif 120#endif
117 switch (s->ConnectionType) { 121 switch (s->ConnectionType) {
118 case GCT_IRDAAT: 122 case GCT_IRDAAT:
119 strcpy(d->peer.irdaServiceName, "IrDA:IrCOMM"); 123 strcpy(d->peer.irdaServiceName, "IrDA:IrCOMM");
120 124
121#ifdef WIN32 125#ifdef WIN32
122 if (setsockopt(fd, SOL_IRLMP, IRLMP_9WIRE_MODE, (const char *) &Enable9WireMode, 126 if (setsockopt(fd, SOL_IRLMP, IRLMP_9WIRE_MODE, (const char *) &Enable9WireMode,
123 sizeof(int))==SOCKET_ERROR) return ERR_UNKNOWN; 127 sizeof(int))==SOCKET_ERROR) return ERR_UNKNOWN;
124#endif 128#endif
125 break; 129 break;
126 case GCT_IRDAPHONET: 130 case GCT_IRDAPHONET:
127 strcpy(d->peer.irdaServiceName, "Nokia:PhoNet"); 131 strcpy(d->peer.irdaServiceName, "Nokia:PhoNet");
128 break; 132 break;
129 case GCT_IRDAOBEX: 133 case GCT_IRDAOBEX:
130 /* IrDA:OBEX not supported by N3650 */ 134 /* IrDA:OBEX not supported by N3650 */
131 // strcpy(d->peer.irdaServiceName, "IrDA:OBEX"); 135 // strcpy(d->peer.irdaServiceName, "IrDA:OBEX");
132 136
133 strcpy(d->peer.irdaServiceName, "OBEX"); 137 strcpy(d->peer.irdaServiceName, "OBEX");
134 138
135 /* Alternative server is "OBEX:IrXfer" */ 139 /* Alternative server is "OBEX:IrXfer" */
136 break; 140 break;
137 default: 141 default:
138 return ERR_UNKNOWN; 142 return ERR_UNKNOWN;
139 } 143 }
140 144
141 /* Connecting to service */ 145 /* Connecting to service */
142 if (connect(fd, (struct sockaddr *)&d->peer, sizeof(d->peer))) { 146 if (connect(fd, (struct sockaddr *)&d->peer, sizeof(d->peer))) {
143 dbgprintf("Can't connect to service %s\n",d->peer.irdaServiceName); 147 dbgprintf("Can't connect to service %s\n",d->peer.irdaServiceName);
144 close(fd); 148 close(fd);
145 return ERR_NOTSUPPORTED; 149 return ERR_NOTSUPPORTED;
146 } 150 }
147 151
148 d->hPhone=fd; 152 d->hPhone=fd;
149 153
150 return ERR_NONE; 154 return ERR_NONE;
151} 155}
152 156
153static int irda_read(GSM_StateMachine *s, void *buf, size_t nbytes) 157static int irda_read(GSM_StateMachine *s, void *buf, size_t nbytes)
154{ 158{
155 return socket_read(s, buf, nbytes, s->Device.Data.Irda.hPhone); 159 return socket_read(s, buf, nbytes, s->Device.Data.Irda.hPhone);
156} 160}
157 161
158#ifdef WIN32 162#ifdef WIN32
159static int irda_write(GSM_StateMachine *s, unsigned char *buf, size_t nbytes) 163static int irda_write(GSM_StateMachine *s, unsigned char *buf, size_t nbytes)
160#else 164#else
161static int irda_write(GSM_StateMachine *s, void *buf, size_t nbytes) 165static int irda_write(GSM_StateMachine *s, void *buf, size_t nbytes)
162#endif 166#endif
163{ 167{
164 return socket_write(s, buf, nbytes, s->Device.Data.Irda.hPhone); 168 return socket_write(s, buf, nbytes, s->Device.Data.Irda.hPhone);
165} 169}
166 170
167static GSM_Error irda_close(GSM_StateMachine *s) 171static GSM_Error irda_close(GSM_StateMachine *s)
168{ 172{
169 return socket_close(s, s->Device.Data.Irda.hPhone); 173 return socket_close(s, s->Device.Data.Irda.hPhone);
170} 174}
171 175
172GSM_Device_Functions IrdaDevice = { 176GSM_Device_Functions IrdaDevice = {
173 irda_open, 177 irda_open,
174 irda_close, 178 irda_close,
175 NONEFUNCTION, 179 NONEFUNCTION,
176 NONEFUNCTION, 180 NONEFUNCTION,
177 NONEFUNCTION, 181 NONEFUNCTION,
178 irda_read, 182 irda_read,
179 irda_write 183 irda_write
180}; 184};
181 185
182#endif 186#endif
183#endif 187#endif
184 188
185/* How should editor hadle tabs in this file? Add editor commands here. 189/* How should editor hadle tabs in this file? Add editor commands here.
186 * vim: noexpandtab sw=8 ts=8 sts=8: 190 * vim: noexpandtab sw=8 ts=8 sts=8:
187 */ 191 */
diff --git a/gammu/emb/common/device/irda/irda_unx.h b/gammu/emb/common/device/irda/irda_unx.h
index 8dbcb97..7a55273 100644
--- a/gammu/emb/common/device/irda/irda_unx.h
+++ b/gammu/emb/common/device/irda/irda_unx.h
@@ -1,61 +1,61 @@
1/* part of irda.h available in Linux kernel source */ 1/* part of irda.h available in Linux kernel source (www.kernel.org) */
2 2
3/********************************************************************* 3/*********************************************************************
4 * 4 *
5 * Filename: irda.h 5 * Filename: irda.h
6 * Version: 6 * Version:
7 * Description: 7 * Description:
8 * Status: Experimental. 8 * Status: Experimental.
9 * Author: Dag Brattli <dagb@cs.uit.no> 9 * Author: Dag Brattli <dagb@cs.uit.no>
10 * Created at: Mon Mar 8 14:06:12 1999 10 * Created at: Mon Mar 8 14:06:12 1999
11 * Modified at: Sat Dec 25 16:06:42 1999 11 * Modified at: Sat Dec 25 16:06:42 1999
12 * Modified by: Dag Brattli <dagb@cs.uit.no> 12 * Modified by: Dag Brattli <dagb@cs.uit.no>
13 * 13 *
14 * Copyright (c) 1999 Dag Brattli, All Rights Reserved. 14 * Copyright (c) 1999 Dag Brattli, All Rights Reserved.
15 * 15 *
16 * This program is free software; you can redistribute it and/or 16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as 17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation; either version 2 of 18 * published by the Free Software Foundation; either version 2 of
19 * the License, or (at your option) any later version. 19 * the License, or (at your option) any later version.
20 * 20 *
21 * Neither Dag Brattli nor University of Tromsø admit liability nor 21 * Neither Dag Brattli nor University of Tromsø admit liability nor
22 * provide warranty for any of this software. This material is 22 * provide warranty for any of this software. This material is
23 * provided "AS-IS" and at no charge. 23 * provided "AS-IS" and at no charge.
24 * 24 *
25 ********************************************************************/ 25 ********************************************************************/
26 26
27#ifndef __irda_unx_h 27#ifndef __irda_unx_h
28#define __irda_unx_h 28#define __irda_unx_h
29 29
30#include <sys/types.h> 30#include <sys/types.h>
31#include <sys/socket.h> 31#include <sys/socket.h>
32 32
33 #define SOL_IRLMP 266 /* Same as SOL_IRDA for now */ 33 #define SOL_IRLMP 266 /* Same as SOL_IRDA for now */
34 #define IRLMP_ENUMDEVICES 1 /* Return discovery log */ 34 #define IRLMP_ENUMDEVICES 1 /* Return discovery log */
35#define LSAP_ANY 0xff 35#define LSAP_ANY 0xff
36 36
37struct sockaddr_irda { 37struct sockaddr_irda {
38 sa_family_t irdaAddressFamily;/* AF_IRDA */ 38 sa_family_t irdaAddressFamily;/* AF_IRDA */
39 u_int8_t sir_lsap_sel; /* LSAP selector */ 39 u_int8_t sir_lsap_sel; /* LSAP selector */
40 u_int32_t irdaDeviceID; /* Device address */ 40 u_int32_t irdaDeviceID; /* Device address */
41 char irdaServiceName[25]; /* Usually <service>:IrDA:TinyTP */ 41 char irdaServiceName[25]; /* Usually <service>:IrDA:TinyTP */
42}; 42};
43 43
44struct irda_device_info { 44struct irda_device_info {
45 u_int32_t saddr; /* Address of local interface */ 45 u_int32_t saddr; /* Address of local interface */
46 u_int32_t irdaDeviceID; /* Address of remote device */ 46 u_int32_t irdaDeviceID; /* Address of remote device */
47 char irdaDeviceName[22]; /* Description */ 47 char irdaDeviceName[22]; /* Description */
48 u_int8_t charset; /* Charset used for description */ 48 u_int8_t charset; /* Charset used for description */
49 u_int8_t hints[2]; /* Hint bits */ 49 u_int8_t hints[2]; /* Hint bits */
50}; 50};
51 51
52struct irda_device_list { 52struct irda_device_list {
53 u_int32_t numDevice; 53 u_int32_t numDevice;
54 struct irda_device_info Device[1]; 54 struct irda_device_info Device[1];
55}; 55};
56 56
57#endif 57#endif
58 58
59/* How should editor hadle tabs in this file? Add editor commands here. 59/* How should editor hadle tabs in this file? Add editor commands here.
60 * vim: noexpandtab sw=8 ts=8 sts=8: 60 * vim: noexpandtab sw=8 ts=8 sts=8:
61 */ 61 */
diff --git a/gammu/emb/common/device/serial/ser_djg.c b/gammu/emb/common/device/serial/ser_djg.c
index ac9d7c8..2524187 100644
--- a/gammu/emb/common/device/serial/ser_djg.c
+++ b/gammu/emb/common/device/serial/ser_djg.c
@@ -1,74 +1,74 @@
1 1
2#include "../../gsmstate.h" 2#include "../../gsmstate.h"
3 3
4#ifdef GSM_ENABLE_SERIALDEVICE 4#ifdef GSM_ENABLE_SERIALDEVICE
5#ifdef DJGPP 5#ifdef DJGPP
6 6
7#include "../../gsmcomon.h" 7#include "../../gsmcomon.h"
8#include "ser_djg.h" 8#include "ser_djg.h"
9 9
10static GSM_Error serial_close(GSM_StateMachine *s) 10static GSM_Error serial_close(GSM_StateMachine *s)
11{ 11{
12 GSM_Device_SerialData *d = &s->Device.Data.Serial; 12 GSM_Device_SerialData *d = &s->Device.Data.Serial;
13 13
14 return ERR_NONE; 14 return ERR_NOTIMPLEMENTED;
15} 15}
16 16
17static GSM_Error serial_open (GSM_StateMachine *s) 17static GSM_Error serial_open (GSM_StateMachine *s)
18{ 18{
19 GSM_Device_SerialData *d = &s->Device.Data.Serial; 19 GSM_Device_SerialData *d = &s->Device.Data.Serial;
20 20
21 return ERR_NONE; 21 return ERR_NOTIMPLEMENTED;
22} 22}
23 23
24static GSM_Error serial_setparity(GSM_StateMachine *s, bool parity) 24static GSM_Error serial_setparity(GSM_StateMachine *s, bool parity)
25{ 25{
26 GSM_Device_SerialData *d = &s->Device.Data.Serial; 26 GSM_Device_SerialData *d = &s->Device.Data.Serial;
27 27
28 return ERR_NONE; 28 return ERR_NOTIMPLEMENTED;
29} 29}
30 30
31static GSM_Error serial_setdtrrts(GSM_StateMachine *s, bool dtr, bool rts) 31static GSM_Error serial_setdtrrts(GSM_StateMachine *s, bool dtr, bool rts)
32{ 32{
33 GSM_Device_SerialData *d = &s->Device.Data.Serial; 33 GSM_Device_SerialData *d = &s->Device.Data.Serial;
34 34
35 return ERR_NONE; 35 return ERR_NOTIMPLEMENTED;
36} 36}
37 37
38static GSM_Error serial_setspeed(GSM_StateMachine *s, int speed) 38static GSM_Error serial_setspeed(GSM_StateMachine *s, int speed)
39{ 39{
40 GSM_Device_SerialData *d = &s->Device.Data.Serial; 40 GSM_Device_SerialData *d = &s->Device.Data.Serial;
41 41
42 return ERR_NONE; 42 return ERR_NOTIMPLEMENTED;
43} 43}
44 44
45static int serial_read(GSM_StateMachine *s, void *buf, size_t nbytes) 45static int serial_read(GSM_StateMachine *s, void *buf, size_t nbytes)
46{ 46{
47 GSM_Device_SerialData *d = &s->Device.Data.Serial; 47 GSM_Device_SerialData *d = &s->Device.Data.Serial;
48 48
49 return 0; 49 return 0;
50} 50}
51 51
52static int serial_write(GSM_StateMachine *s, void *buf, size_t nbytes) 52static int serial_write(GSM_StateMachine *s, void *buf, size_t nbytes)
53{ 53{
54 GSM_Device_SerialData *d = &s->Device.Data.Serial; 54 GSM_Device_SerialData *d = &s->Device.Data.Serial;
55 55
56 return 0; 56 return 0;
57} 57}
58 58
59GSM_Device_Functions SerialDevice = { 59GSM_Device_Functions SerialDevice = {
60 serial_open, 60 serial_open,
61 serial_close, 61 serial_close,
62 serial_setparity, 62 serial_setparity,
63 serial_setdtrrts, 63 serial_setdtrrts,
64 serial_setspeed, 64 serial_setspeed,
65 serial_read, 65 serial_read,
66 serial_write 66 serial_write
67}; 67};
68 68
69#endif 69#endif
70#endif 70#endif
71 71
72/* How should editor hadle tabs in this file? Add editor commands here. 72/* How should editor hadle tabs in this file? Add editor commands here.
73 * vim: noexpandtab sw=8 ts=8 sts=8: 73 * vim: noexpandtab sw=8 ts=8 sts=8:
74 */ 74 */
diff --git a/gammu/emb/common/device/serial/ser_unx.c b/gammu/emb/common/device/serial/ser_unx.c
index 2a87b11..69c7515 100644
--- a/gammu/emb/common/device/serial/ser_unx.c
+++ b/gammu/emb/common/device/serial/ser_unx.c
@@ -1,291 +1,319 @@
1/* (c) 2002-2004 by Marcin Wiacek */ 1/* (c) 2002-2004 by Marcin Wiacek */
2/* locking device and settings all speeds by Michal Cihar */ 2/* locking device and settings all speeds by Michal Cihar */
3/* based on some work from Gnokii (www.gnokii.org)
4 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
5 * GNU GPL version 2 or later
6 */
3 7
4#include "../../gsmstate.h" 8#include "../../gsmstate.h"
5 9
6#ifdef GSM_ENABLE_SERIALDEVICE 10#ifdef GSM_ENABLE_SERIALDEVICE
7#ifndef WIN32 11#ifndef WIN32
8#ifndef DJGPP 12#ifndef DJGPP
9 13
10#include <sys/file.h> 14#include <sys/file.h>
11#include <sys/time.h> 15#include <sys/time.h>
12#include <string.h> 16#include <string.h>
13#include <termios.h> 17#include <termios.h>
14#include <errno.h> 18#include <errno.h>
15 19
16#include "../../gsmcomon.h" 20#include "../../gsmcomon.h"
17#include "ser_unx.h" 21#include "ser_unx.h"
18 22
23#ifndef O_NONBLOCK
24# define O_NONBLOCK 0
25#endif
26
27#ifdef __NetBSD__
28# define FNONBLOCK O_NONBLOCK
29
30# define B57600 0010001
31# define B115200 0010002
32# define B230400 0010003
33# define B460800 0010004
34# define B500000 0010005
35# define B576000 0010006
36# define B921600 0010007
37# define B1000000 0010010
38# define B1152000 0010011
39# define B1500000 0010012
40# define B2000000 0010013
41# define B2500000 0010014
42# define B3000000 0010015
43# define B3500000 0010016
44# define B4000000 0010017
45#endif
46
19static GSM_Error serial_close(GSM_StateMachine *s) 47static GSM_Error serial_close(GSM_StateMachine *s)
20{ 48{
21 GSM_Device_SerialData *d = &s->Device.Data.Serial; 49 GSM_Device_SerialData *d = &s->Device.Data.Serial;
22 50
23 /* Restores old settings */ 51 /* Restores old settings */
24 tcsetattr(d->hPhone, TCSANOW, &d->old_settings); 52 tcsetattr(d->hPhone, TCSANOW, &d->old_settings);
25 53
26 /* Closes device */ 54 /* Closes device */
27 close(d->hPhone); 55 close(d->hPhone);
28 56
29 return ERR_NONE; 57 return ERR_NONE;
30} 58}
31 59
32#ifndef O_NONBLOCK
33# define O_NONBLOCK 0
34#endif
35
36static GSM_Error serial_open (GSM_StateMachine *s) 60static GSM_Error serial_open (GSM_StateMachine *s)
37{ 61{
38 GSM_Device_SerialData *d = &s->Device.Data.Serial; 62 GSM_Device_SerialData *d = &s->Device.Data.Serial;
39 struct termios t; 63 struct termios t;
40 int i; 64 int i;
41 65
42 /* O_NONBLOCK MUST is required to avoid waiting for DCD */ 66 /* O_NONBLOCK MUST is required to avoid waiting for DCD */
43 d->hPhone = open(s->CurrentConfig->Device, O_RDWR | O_NOCTTY | O_NONBLOCK); 67 d->hPhone = open(s->CurrentConfig->Device, O_RDWR | O_NOCTTY | O_NONBLOCK);
44 if (d->hPhone < 0) { 68 if (d->hPhone < 0) {
45 i = errno; 69 i = errno;
46 GSM_OSErrorInfo(s,"open in serial_open"); 70 GSM_OSErrorInfo(s,"open in serial_open");
47 if (i == 2) return ERR_DEVICENOTEXIST; //no such file or directory 71 if (i == 2) return ERR_DEVICENOTEXIST; //no such file or directory
48 if (i == 13) return ERR_DEVICENOPERMISSION;//permission denied 72 if (i == 13) return ERR_DEVICENOPERMISSION;//permission denied
49 return ERR_DEVICEOPENERROR; 73 return ERR_DEVICEOPENERROR;
50 } 74 }
51 75
52#ifdef TIOCEXCL 76#ifdef TIOCEXCL
53 /* open() calls from other applications shall fail now */ 77 /* open() calls from other applications shall fail now */
54 ioctl(d->hPhone, TIOCEXCL, (char *) 0); 78 ioctl(d->hPhone, TIOCEXCL, (char *) 0);
55#endif 79#endif
56 80
57 if (tcgetattr(d->hPhone, &d->old_settings) == -1) { 81 if (tcgetattr(d->hPhone, &d->old_settings) == -1) {
58 close(d->hPhone); 82 close(d->hPhone);
59 GSM_OSErrorInfo(s,"tcgetattr in serial_open"); 83 GSM_OSErrorInfo(s,"tcgetattr in serial_open");
60 return ERR_DEVICEREADERROR; 84 return ERR_DEVICEREADERROR;
61 } 85 }
62 86
63 if (tcflush(d->hPhone, TCIOFLUSH) == -1) { 87 if (tcflush(d->hPhone, TCIOFLUSH) == -1) {
64 serial_close(s); 88 serial_close(s);
65 GSM_OSErrorInfo(s,"tcflush in serial_open"); 89 GSM_OSErrorInfo(s,"tcflush in serial_open");
66 return ERR_DEVICEOPENERROR; 90 return ERR_DEVICEOPENERROR;
67 } 91 }
68 92
69 memcpy(&t, &d->old_settings, sizeof(struct termios)); 93 memcpy(&t, &d->old_settings, sizeof(struct termios));
70 94
71 /* Opening without parity */ 95 /* Opening without parity */
72 t.c_iflag = IGNPAR; 96 t.c_iflag = IGNPAR;
73 t.c_oflag = 0; 97 t.c_oflag = 0;
74 /* disconnect line, 8 bits, enable receiver, 98 /* disconnect line, 8 bits, enable receiver,
75 * ignore modem lines,lower modem line after disconnect 99 * ignore modem lines,lower modem line after disconnect
76 */ 100 */
77 t.c_cflag = B0 | CS8 | CREAD | CLOCAL | HUPCL; 101 t.c_cflag = B0 | CS8 | CREAD | CLOCAL | HUPCL;
78 /* enable hardware (RTS/CTS) flow control (NON POSIX) */ 102 /* enable hardware (RTS/CTS) flow control (NON POSIX) */
79 /* t.c_cflag |= CRTSCTS; */ 103 /* t.c_cflag |= CRTSCTS; */
80 t.c_lflag = 0; 104 t.c_lflag = 0;
81 t.c_cc[VMIN] = 1; 105 t.c_cc[VMIN] = 1;
82 t.c_cc[VTIME] = 0; 106 t.c_cc[VTIME] = 0;
83 107
84 if (tcsetattr(d->hPhone, TCSANOW, &t) == -1) { 108 if (tcsetattr(d->hPhone, TCSANOW, &t) == -1) {
85 serial_close(s); 109 serial_close(s);
86 GSM_OSErrorInfo(s,"tcsetattr in serial_open"); 110 GSM_OSErrorInfo(s,"tcsetattr in serial_open");
87 return ERR_DEVICEOPENERROR; 111 return ERR_DEVICEOPENERROR;
88 } 112 }
89 113
90 /* Making file descriptor asynchronous. */ 114 /* Making file descriptor asynchronous. */
91 if (fcntl(d->hPhone, F_SETFL, FASYNC | FNONBLOCK) == -1) { 115 if (fcntl(d->hPhone, F_SETFL, FASYNC | FNONBLOCK) == -1) {
92 serial_close(s); 116 serial_close(s);
93 GSM_OSErrorInfo(s,"fcntl in serial_open"); 117 GSM_OSErrorInfo(s,"fcntl in serial_open");
94 return ERR_DEVICEOPENERROR; 118 return ERR_DEVICEOPENERROR;
95 } 119 }
96 120
97 return ERR_NONE; 121 return ERR_NONE;
98} 122}
99 123
100static GSM_Error serial_setparity(GSM_StateMachine *s, bool parity) 124static GSM_Error serial_setparity(GSM_StateMachine *s, bool parity)
101{ 125{
102 GSM_Device_SerialData *d = &s->Device.Data.Serial; 126 GSM_Device_SerialData *d = &s->Device.Data.Serial;
103 struct termios t; 127 struct termios t;
104 128
105 if (tcgetattr(d->hPhone, &t)) { 129 if (tcgetattr(d->hPhone, &t)) {
106 GSM_OSErrorInfo(s,"tcgetattr in serial_setparity"); 130 GSM_OSErrorInfo(s,"tcgetattr in serial_setparity");
107 return ERR_DEVICEREADERROR; 131 return ERR_DEVICEREADERROR;
108 } 132 }
109 133
110 if (parity) { 134 if (parity) {
111 t.c_cflag |= (PARENB | PARODD); 135 t.c_cflag |= (PARENB | PARODD);
112 t.c_iflag = 0; 136 t.c_iflag = 0;
113 } else { 137 } else {
114 t.c_iflag = IGNPAR; 138 t.c_iflag = IGNPAR;
115 } 139 }
116 140
117 if (tcsetattr(d->hPhone, TCSANOW, &t) == -1){ 141 if (tcsetattr(d->hPhone, TCSANOW, &t) == -1){
118 serial_close(s); 142 serial_close(s);
119 GSM_OSErrorInfo(s,"tcsetattr in serial_setparity"); 143 GSM_OSErrorInfo(s,"tcsetattr in serial_setparity");
120 return ERR_DEVICEPARITYERROR; 144 return ERR_DEVICEPARITYERROR;
121 } 145 }
122 146
123 return ERR_NONE; 147 return ERR_NONE;
124} 148}
125 149
126static GSM_Error serial_setdtrrts(GSM_StateMachine *s, bool dtr, bool rts) 150static GSM_Error serial_setdtrrts(GSM_StateMachine *s, bool dtr, bool rts)
127{ 151{
128 GSM_Device_SerialData *d = &s->Device.Data.Serial; 152 GSM_Device_SerialData *d = &s->Device.Data.Serial;
129 struct termios t; 153 struct termios t;
130 unsigned int flags; 154 unsigned int flags;
131 155
132 if (tcgetattr(d->hPhone, &t)) { 156 if (tcgetattr(d->hPhone, &t)) {
133 GSM_OSErrorInfo(s,"tcgetattr in serial_setdtrrts"); 157 GSM_OSErrorInfo(s,"tcgetattr in serial_setdtrrts");
134 return ERR_DEVICEREADERROR; 158 return ERR_DEVICEREADERROR;
135 } 159 }
136 160
137#ifdef CRTSCTS 161#ifdef CRTSCTS
138 /* Disabling hardware flow control */ 162 /* Disabling hardware flow control */
139 t.c_cflag &= ~CRTSCTS; 163 t.c_cflag &= ~CRTSCTS;
140#endif 164#endif
141 165
142 if (tcsetattr(d->hPhone, TCSANOW, &t) == -1) { 166 if (tcsetattr(d->hPhone, TCSANOW, &t) == -1) {
143 serial_close(s); 167 serial_close(s);
144 GSM_OSErrorInfo(s,"tcsetattr in serial_setdtrrts"); 168 GSM_OSErrorInfo(s,"tcsetattr in serial_setdtrrts");
145 return ERR_DEVICEDTRRTSERROR; 169 return ERR_DEVICEDTRRTSERROR;
146 } 170 }
147 171
148 flags = TIOCM_DTR; 172 flags = TIOCM_DTR;
149 if (dtr) { 173 if (dtr) {
150 ioctl(d->hPhone, TIOCMBIS, &flags); 174 ioctl(d->hPhone, TIOCMBIS, &flags);
151 } else { 175 } else {
152 ioctl(d->hPhone, TIOCMBIC, &flags); 176 ioctl(d->hPhone, TIOCMBIC, &flags);
153 } 177 }
154 178
155 flags = TIOCM_RTS; 179 flags = TIOCM_RTS;
156 if (rts) { 180 if (rts) {
157 ioctl(d->hPhone, TIOCMBIS, &flags); 181 ioctl(d->hPhone, TIOCMBIS, &flags);
158 } else { 182 } else {
159 ioctl(d->hPhone, TIOCMBIC, &flags); 183 ioctl(d->hPhone, TIOCMBIC, &flags);
160 } 184 }
161 185
162 flags = 0; 186 flags = 0;
163 ioctl(d->hPhone, TIOCMGET, &flags); 187 ioctl(d->hPhone, TIOCMGET, &flags);
164 188
165 dbgprintf("Serial device:"); 189 dbgprintf("Serial device:");
166 dbgprintf(" DTR is %s", flags&TIOCM_DTR?"up":"down"); 190 dbgprintf(" DTR is %s", flags&TIOCM_DTR?"up":"down");
167 dbgprintf(", RTS is %s", flags&TIOCM_RTS?"up":"down"); 191 dbgprintf(", RTS is %s", flags&TIOCM_RTS?"up":"down");
168 dbgprintf(", CAR is %s", flags&TIOCM_CAR?"up":"down"); 192 dbgprintf(", CAR is %s", flags&TIOCM_CAR?"up":"down");
169 dbgprintf(", CTS is %s\n", flags&TIOCM_CTS?"up":"down"); 193 dbgprintf(", CTS is %s\n", flags&TIOCM_CTS?"up":"down");
170 if (((flags&TIOCM_DTR)==TIOCM_DTR) != dtr) return ERR_DEVICEDTRRTSERROR; 194 if (((flags&TIOCM_DTR)==TIOCM_DTR) != dtr) return ERR_DEVICEDTRRTSERROR;
171 if (((flags&TIOCM_RTS)==TIOCM_RTS) != rts) return ERR_DEVICEDTRRTSERROR; 195 if (((flags&TIOCM_RTS)==TIOCM_RTS) != rts) return ERR_DEVICEDTRRTSERROR;
172 196
173 return ERR_NONE; 197 return ERR_NONE;
174} 198}
175 199
176static GSM_Error serial_setspeed(GSM_StateMachine *s, int speed) 200static GSM_Error serial_setspeed(GSM_StateMachine *s, int speed)
177{ 201{
178 GSM_Device_SerialData *d = &s->Device.Data.Serial; 202 GSM_Device_SerialData *d = &s->Device.Data.Serial;
179 struct termios t; 203 struct termios t;
180 int speed2 = B19200; 204 int speed2 = B19200;
181 205
182 if (tcgetattr(d->hPhone, &t)) { 206 if (tcgetattr(d->hPhone, &t)) {
183 GSM_OSErrorInfo(s,"tcgetattr in serial_setspeed"); 207 GSM_OSErrorInfo(s,"tcgetattr in serial_setspeed");
184 return ERR_DEVICEREADERROR; 208 return ERR_DEVICEREADERROR;
185 } 209 }
186 210
187 smprintf(s, "Setting speed to %d\n", speed); 211 smprintf(s, "Setting speed to %d\n", speed);
188 212
189 switch (speed) { 213 switch (speed) {
190 case 50: speed2 = B50; break; 214 case 50: speed2 = B50; break;
191 case 75: speed2 = B75; break; 215 case 75: speed2 = B75; break;
192 case 110: speed2 = B110; break; 216 case 110: speed2 = B110; break;
193 case 134: speed2 = B134; break; 217 case 134: speed2 = B134; break;
194 case 150: speed2 = B150; break; 218 case 150: speed2 = B150; break;
195 case 200: speed2 = B200; break; 219 case 200: speed2 = B200; break;
196 case 300: speed2 = B300; break; 220 case 300: speed2 = B300; break;
197 case 600: speed2 = B600; break; 221 case 600: speed2 = B600; break;
198 case 1200: speed2 = B1200; break; 222 case 1200: speed2 = B1200; break;
199 case 1800: speed2 = B1800; break; 223 case 1800: speed2 = B1800; break;
200 case 2400: speed2 = B2400; break; 224 case 2400: speed2 = B2400; break;
201 case 4800: speed2 = B4800; break; 225 case 4800: speed2 = B4800; break;
202 case 9600: speed2 = B9600; break; 226 case 9600: speed2 = B9600; break;
203 case 19200: speed2 = B19200;break; 227 case 19200: speed2 = B19200;break;
204 case 38400: speed2 = B38400;break; 228 case 38400: speed2 = B38400;break;
229#ifdef B57600
205 case 57600: speed2 = B57600;break; 230 case 57600: speed2 = B57600;break;
206 case 115200: speed2 = B115200;break; 231 case 115200: speed2 = B115200;break;
207 case 230400: speed2 = B230400;break; 232 case 230400: speed2 = B230400;break;
208 case 460800: speed2 = B460800;break; 233 case 460800: speed2 = B460800;break;
234#ifdef B500000
209 case 500000: speed2 = B500000;break; 235 case 500000: speed2 = B500000;break;
210 case 576000: speed2 = B576000;break; 236 case 576000: speed2 = B576000;break;
211 case 921600: speed2 = B921600;break; 237 case 921600: speed2 = B921600;break;
212 case 1000000: speed2 = B1000000;break; 238 case 1000000: speed2 = B1000000;break;
213 case 1152000: speed2 = B1152000;break; 239 case 1152000: speed2 = B1152000;break;
214 case 1500000: speed2 = B1500000;break; 240 case 1500000: speed2 = B1500000;break;
215 case 2000000: speed2 = B2000000;break; 241 case 2000000: speed2 = B2000000;break;
216 case 2500000: speed2 = B2500000;break; 242 case 2500000: speed2 = B2500000;break;
217 case 3000000: speed2 = B3000000;break; 243 case 3000000: speed2 = B3000000;break;
218 case 3500000: speed2 = B3500000;break; 244 case 3500000: speed2 = B3500000;break;
219 case 4000000: speed2 = B4000000; break; 245 case 4000000: speed2 = B4000000; break;
246#endif
247#endif
220 } 248 }
221 249
222 /* This should work on all systems because it is done according to POSIX */ 250 /* This should work on all systems because it is done according to POSIX */
223 cfsetispeed(&t, speed2); 251 cfsetispeed(&t, speed2);
224 cfsetospeed(&t, speed2); 252 cfsetospeed(&t, speed2);
225 253
226 if (tcsetattr(d->hPhone, TCSADRAIN, &t) == -1) { 254 if (tcsetattr(d->hPhone, TCSADRAIN, &t) == -1) {
227 serial_close(s); 255 serial_close(s);
228 GSM_OSErrorInfo(s,"tcsetattr in serial_setspeed"); 256 GSM_OSErrorInfo(s,"tcsetattr in serial_setspeed");
229 return ERR_DEVICECHANGESPEEDERROR; 257 return ERR_DEVICECHANGESPEEDERROR;
230 } 258 }
231 259
232 return ERR_NONE; 260 return ERR_NONE;
233} 261}
234 262
235static int serial_read(GSM_StateMachine *s, void *buf, size_t nbytes) 263static int serial_read(GSM_StateMachine *s, void *buf, size_t nbytes)
236{ 264{
237 GSM_Device_SerialData *d = &s->Device.Data.Serial; 265 GSM_Device_SerialData *d = &s->Device.Data.Serial;
238 struct timeval timeout2; 266 struct timeval timeout2;
239 fd_set readfds; 267 fd_set readfds;
240 int actual = 0; 268 int actual = 0;
241 269
242 FD_ZERO(&readfds); 270 FD_ZERO(&readfds);
243 FD_SET(d->hPhone, &readfds); 271 FD_SET(d->hPhone, &readfds);
244 272
245 timeout2.tv_sec = 0; 273 timeout2.tv_sec = 0;
246 timeout2.tv_usec = 1; 274 timeout2.tv_usec = 1;
247 275
248 if (select(d->hPhone+1, &readfds, NULL, NULL, &timeout2)) { 276 if (select(d->hPhone+1, &readfds, NULL, NULL, &timeout2)) {
249 actual = read(d->hPhone, buf, nbytes); 277 actual = read(d->hPhone, buf, nbytes);
250 if (actual == -1) GSM_OSErrorInfo(s,"serial_read"); 278 if (actual == -1) GSM_OSErrorInfo(s,"serial_read");
251 } 279 }
252 return actual; 280 return actual;
253} 281}
254 282
255static int serial_write(GSM_StateMachine *s, void *buf, size_t nbytes) 283static int serial_write(GSM_StateMachine *s, void *buf, size_t nbytes)
256{ 284{
257 GSM_Device_SerialData *d = &s->Device.Data.Serial; 285 GSM_Device_SerialData *d = &s->Device.Data.Serial;
258 int ret; 286 int ret;
259 size_t actual = 0; 287 size_t actual = 0;
260 288
261 do { 289 do {
262 ret = write(d->hPhone, (unsigned char *)buf, nbytes - actual); 290 ret = write(d->hPhone, (unsigned char *)buf, nbytes - actual);
263 if (ret < 0 && errno == EAGAIN) continue; 291 if (ret < 0 && errno == EAGAIN) continue;
264 if (ret < 0) { 292 if (ret < 0) {
265 if (actual != nbytes) GSM_OSErrorInfo(s,"serial_write"); 293 if (actual != nbytes) GSM_OSErrorInfo(s,"serial_write");
266 return actual; 294 return actual;
267 } 295 }
268 actual += ret; 296 actual += ret;
269 buf += ret; 297 buf += ret;
270 if (s->ConnectionType == GCT_FBUS2PL2303) my_sleep(1); 298 if (s->ConnectionType == GCT_FBUS2PL2303) my_sleep(1);
271 } while (actual < nbytes); 299 } while (actual < nbytes);
272 return actual; 300 return actual;
273} 301}
274 302
275GSM_Device_Functions SerialDevice = { 303GSM_Device_Functions SerialDevice = {
276 serial_open, 304 serial_open,
277 serial_close, 305 serial_close,
278 serial_setparity, 306 serial_setparity,
279 serial_setdtrrts, 307 serial_setdtrrts,
280 serial_setspeed, 308 serial_setspeed,
281 serial_read, 309 serial_read,
282 serial_write 310 serial_write
283}; 311};
284 312
285#endif 313#endif
286#endif 314#endif
287#endif 315#endif
288 316
289/* How should editor hadle tabs in this file? Add editor commands here. 317/* How should editor hadle tabs in this file? Add editor commands here.
290 * vim: noexpandtab sw=8 ts=8 sts=8: 318 * vim: noexpandtab sw=8 ts=8 sts=8:
291 */ 319 */
diff --git a/gammu/emb/common/device/serial/ser_w32.c b/gammu/emb/common/device/serial/ser_w32.c
index 9fa0135..7d88fc7 100644
--- a/gammu/emb/common/device/serial/ser_w32.c
+++ b/gammu/emb/common/device/serial/ser_w32.c
@@ -1,194 +1,198 @@
1/* (c) 2002-2004 by Marcin Wiacek */ 1/* (c) 2002-2004 by Marcin Wiacek */
2/* based on some work from Gnokii, MSDN and others */ 2/* based on some work from MSDN and others */
3/* based on some work from Gnokii (www.gnokii.org)
4 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
5 * GNU GPL version 2 or later
6 */
3 7
4#include "../../gsmstate.h" 8#include "../../gsmstate.h"
5 9
6#ifdef GSM_ENABLE_SERIALDEVICE 10#ifdef GSM_ENABLE_SERIALDEVICE
7#ifdef WIN32 11#ifdef WIN32
8 12
9#include <windows.h> 13#include <windows.h>
10#include <string.h> 14#include <string.h>
11#include <stdio.h> 15#include <stdio.h>
12#include <io.h> 16#include <io.h>
13#include <memory.h> 17#include <memory.h>
14 18
15#include "../../gsmcomon.h" 19#include "../../gsmcomon.h"
16#include "ser_w32.h" 20#include "ser_w32.h"
17 21
18static GSM_Error serial_close(GSM_StateMachine *s) 22static GSM_Error serial_close(GSM_StateMachine *s)
19{ 23{
20 GSM_Device_SerialData *d = &s->Device.Data.Serial; 24 GSM_Device_SerialData *d = &s->Device.Data.Serial;
21 25
22 /* Disables all monitored events for device */ 26 /* Disables all monitored events for device */
23 SetCommMask(d->hPhone, 0); 27 SetCommMask(d->hPhone, 0);
24 28
25 /* Discards all characters from input/output buffer and terminates 29 /* Discards all characters from input/output buffer and terminates
26 * pending read/write operations 30 * pending read/write operations
27 */ 31 */
28 PurgeComm(d->hPhone, PURGE_TXABORT | PURGE_RXABORT | 32 PurgeComm(d->hPhone, PURGE_TXABORT | PURGE_RXABORT |
29 PURGE_TXCLEAR | PURGE_RXCLEAR); 33 PURGE_TXCLEAR | PURGE_RXCLEAR);
30 34
31 /* Clears the DTR (data-terminal-ready) signal */ 35 /* Clears the DTR (data-terminal-ready) signal */
32 EscapeCommFunction(d->hPhone, CLRDTR); 36 EscapeCommFunction(d->hPhone, CLRDTR);
33 37
34 /* Restores old settings */ 38 /* Restores old settings */
35 if (SetCommState(d->hPhone, &d->old_settings)==0) { 39 if (SetCommState(d->hPhone, &d->old_settings)==0) {
36 GSM_OSErrorInfo(s, "SetCommState in serial_close"); 40 GSM_OSErrorInfo(s, "SetCommState in serial_close");
37 } 41 }
38 42
39 /* Closes device */ 43 /* Closes device */
40 if (CloseHandle(d->hPhone)==0) { 44 if (CloseHandle(d->hPhone)==0) {
41 GSM_OSErrorInfo(s, "CloseHandle in serial_close"); 45 GSM_OSErrorInfo(s, "CloseHandle in serial_close");
42 } 46 }
43 47
44 return ERR_NONE; 48 return ERR_NONE;
45} 49}
46 50
47static GSM_Error serial_open (GSM_StateMachine *s) 51static GSM_Error serial_open (GSM_StateMachine *s)
48{ 52{
49 GSM_Device_SerialData *d = &s->Device.Data.Serial; 53 GSM_Device_SerialData *d = &s->Device.Data.Serial;
50 DCB dcb; 54 DCB dcb;
51 unsigned char DeviceName[80],DeviceName2[80]; 55 unsigned char DeviceName[80],DeviceName2[80];
52 int i; 56 int i;
53#ifdef GSM_ENABLE_FBUS2DKU5 57#ifdef GSM_ENABLE_FBUS2DKU5
54 HKEY hKey; 58 HKEY hKey;
55 DWORD DeviceNameLen, KeyNameLen; 59 DWORD DeviceNameLen, KeyNameLen;
56 unsigned char KeyName[100]; 60 unsigned char KeyName[100];
57#endif 61#endif
58 62
59 strcpy(DeviceName2,s->CurrentConfig->Device); 63 strcpy(DeviceName2,s->CurrentConfig->Device);
60 64
61#ifdef GSM_ENABLE_FBUS2DKU5 65#ifdef GSM_ENABLE_FBUS2DKU5
62 if (s->ConnectionType == GCT_FBUS2DKU5) { 66 if (s->ConnectionType == GCT_FBUS2DKU5) {
63 smprintf(s,"Reading DKU5 device\n"); 67 smprintf(s,"Reading DKU5 device\n");
64 DeviceName2[0] = 0; 68 DeviceName2[0] = 0;
65 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) { 69 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) {
66 smprintf(s,"Error opening key\n"); 70 smprintf(s,"Error opening key\n");
67 return ERR_DEVICENOTWORK; 71 return ERR_DEVICENOTWORK;
68 } 72 }
69 i = 0; 73 i = 0;
70 while(1) { 74 while(1) {
71 DeviceNameLen = 80; 75 DeviceNameLen = 80;
72 KeyNameLen = 100; 76 KeyNameLen = 100;
73 if (RegEnumValue(hKey,i,KeyName,&KeyNameLen,NULL,NULL,DeviceName2,&DeviceNameLen) != ERROR_SUCCESS) { 77 if (RegEnumValue(hKey,i,KeyName,&KeyNameLen,NULL,NULL,DeviceName2,&DeviceNameLen) != ERROR_SUCCESS) {
74 smprintf(s,"Error reading key value\n"); 78 smprintf(s,"Error reading key value\n");
75 return ERR_DEVICENOTWORK; 79 return ERR_DEVICENOTWORK;
76 } 80 }
77 // smprintf(s,"Key name is %s, value is %s\n",KeyName,DeviceName2); 81 // smprintf(s,"Key name is %s, value is %s\n",KeyName,DeviceName2);
78 if (!strncmp(KeyName,"\\Device\\AtmelVirtualPort",24)) break; 82 if (!strncmp(KeyName,"\\Device\\AtmelVirtualPort",24)) break;
79 i++; 83 i++;
80 } 84 }
81 RegCloseKey(hKey); 85 RegCloseKey(hKey);
82 if (strlen(DeviceName2) == 0) return ERR_DEVICENOTWORK; 86 if (strlen(DeviceName2) == 0) return ERR_DEVICENOTWORK;
83 smprintf(s,"DKU5 device is \"%s\"\n",DeviceName2); 87 smprintf(s,"DKU5 device is \"%s\"\n",DeviceName2);
84 //nodriver 88 //nodriver
85 } 89 }
86#endif 90#endif
87 91
88 if ((s->ConnectionType == GCT_FBUS2DKU5) || 92 if ((s->ConnectionType == GCT_FBUS2DKU5) ||
89 (!strncmp(DeviceName2,"com",3) && strlen(DeviceName2)>3)) { 93 (!strncmp(DeviceName2,"com",3) && strlen(DeviceName2)>3)) {
90 sprintf(DeviceName,"\\\\.\\COM%i",atoi(DeviceName2+3)); 94 sprintf(DeviceName,"\\\\.\\COM%i",atoi(DeviceName2+3));
91 } else { 95 } else {
92 strcpy(DeviceName,DeviceName2); 96 strcpy(DeviceName,DeviceName2);
93 } 97 }
94 98
95 smprintf(s,"Device is %s\n",DeviceName); 99 smprintf(s,"Device is %s\n",DeviceName);
96 100
97 /* Allows for reading/writing, no device sharing */ 101 /* Allows for reading/writing, no device sharing */
98 d->hPhone = CreateFile(DeviceName, 102 d->hPhone = CreateFile(DeviceName,
99 GENERIC_READ | GENERIC_WRITE, 103 GENERIC_READ | GENERIC_WRITE,
100 0, 104 0,
101 0, 105 0,
102 OPEN_EXISTING, 106 OPEN_EXISTING,
103 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, 107 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
104 NULL); 108 NULL);
105 109
106 if (d->hPhone == INVALID_HANDLE_VALUE) { 110 if (d->hPhone == INVALID_HANDLE_VALUE) {
107 i = GetLastError(); 111 i = GetLastError();
108 GSM_OSErrorInfo(s, "CreateFile in serial_open"); 112 GSM_OSErrorInfo(s, "CreateFile in serial_open");
109 if (i == 2) return ERR_DEVICENOTWORK; //can't find specified file 113 if (i == 2) return ERR_DEVICENOTWORK; //can't find specified file
110 if (i == 5) return ERR_DEVICEBUSY; //access denied 114 if (i == 5) return ERR_DEVICEBUSY; //access denied
111 if (i == 31) return ERR_DEVICENOTWORK; //attached device not working 115 if (i == 31) return ERR_DEVICENOTWORK; //attached device not working
112 if (i == 123) return ERR_DEVICENOTEXIST; 116 if (i == 123) return ERR_DEVICENOTEXIST;
113 return ERR_DEVICEOPENERROR; 117 return ERR_DEVICEOPENERROR;
114 } 118 }
115 119
116 d->old_settings.DCBlength = sizeof(DCB); 120 d->old_settings.DCBlength = sizeof(DCB);
117 if (GetCommState(d->hPhone, &d->old_settings)==0) { 121 if (GetCommState(d->hPhone, &d->old_settings)==0) {
118 GSM_OSErrorInfo(s, "ReadDevice in serial_open"); 122 GSM_OSErrorInfo(s, "ReadDevice in serial_open");
119 return ERR_DEVICEREADERROR; 123 return ERR_DEVICEREADERROR;
120 } 124 }
121 125
122 /* When char will be received, we will receive notifications */ 126 /* When char will be received, we will receive notifications */
123 SetCommMask(d->hPhone, EV_RXCHAR); 127 SetCommMask(d->hPhone, EV_RXCHAR);
124 128
125 /* Sets size for input/output buffer */ 129 /* Sets size for input/output buffer */
126 SetupComm(d->hPhone, 4096, 4096); 130 SetupComm(d->hPhone, 4096, 4096);
127 131
128 /* Discards all characters from input/output buffer and terminates 132 /* Discards all characters from input/output buffer and terminates
129 * pending read/write operations 133 * pending read/write operations
130 */ 134 */
131 PurgeComm(d->hPhone, PURGE_TXABORT | PURGE_RXABORT | 135 PurgeComm(d->hPhone, PURGE_TXABORT | PURGE_RXABORT |
132 PURGE_TXCLEAR | PURGE_RXCLEAR); 136 PURGE_TXCLEAR | PURGE_RXCLEAR);
133 137
134 memcpy(&dcb, &d->old_settings, sizeof(DCB)); 138 memcpy(&dcb, &d->old_settings, sizeof(DCB));
135 139
136 dcb.ByteSize = 8; 140 dcb.ByteSize = 8;
137 dcb.Parity = NOPARITY; 141 dcb.Parity = NOPARITY;
138 dcb.StopBits = ONESTOPBIT; 142 dcb.StopBits = ONESTOPBIT;
139 143
140 /* No Xon/Xof flow control */ 144 /* No Xon/Xof flow control */
141 // dcb.fOutX = false; 145 // dcb.fOutX = false;
142 // dcb.fInX = false; 146 // dcb.fInX = false;
143 147
144 /* Hardware flow control */ 148 /* Hardware flow control */
145 //dcb.fOutxDsrFlow = true; 149 //dcb.fOutxDsrFlow = true;
146 //dcb.fOutxCtsFlow = true; 150 //dcb.fOutxCtsFlow = true;
147 //dcb.fDtrControl = DTR_CONTROL_HANDSHAKE; 151 //dcb.fDtrControl = DTR_CONTROL_HANDSHAKE;
148 //dcb.fRtsControl = RTS_CONTROL_HANDSHAKE; 152 //dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;
149 153
150 /* Initialise the port settings */ 154 /* Initialise the port settings */
151 if (SetCommState(d->hPhone, &dcb)==0) { 155 if (SetCommState(d->hPhone, &dcb)==0) {
152 GSM_OSErrorInfo(s, "WriteDevice in serial_open"); 156 GSM_OSErrorInfo(s, "WriteDevice in serial_open");
153 return ERR_DEVICEOPENERROR; 157 return ERR_DEVICEOPENERROR;
154 } 158 }
155 159
156 return ERR_NONE; 160 return ERR_NONE;
157} 161}
158 162
159static GSM_Error serial_setparity (GSM_StateMachine *s, bool parity) 163static GSM_Error serial_setparity (GSM_StateMachine *s, bool parity)
160{ 164{
161 DCB dcb; 165 DCB dcb;
162 GSM_Device_SerialData *d = &s->Device.Data.Serial; 166 GSM_Device_SerialData *d = &s->Device.Data.Serial;
163 167
164 dcb.DCBlength = sizeof(DCB); 168 dcb.DCBlength = sizeof(DCB);
165 if (GetCommState(d->hPhone, &dcb)==0) { 169 if (GetCommState(d->hPhone, &dcb)==0) {
166 GSM_OSErrorInfo(s, "ReadDevice in serial_setparity"); 170 GSM_OSErrorInfo(s, "ReadDevice in serial_setparity");
167 return ERR_DEVICEREADERROR; 171 return ERR_DEVICEREADERROR;
168 } 172 }
169 173
170 if (parity) { 174 if (parity) {
171 dcb.Parity = ODDPARITY; 175 dcb.Parity = ODDPARITY;
172 } else { 176 } else {
173 dcb.Parity = NOPARITY; 177 dcb.Parity = NOPARITY;
174 } 178 }
175 179
176 if (SetCommState(d->hPhone, &dcb)==0) { 180 if (SetCommState(d->hPhone, &dcb)==0) {
177 GSM_OSErrorInfo(s, "WriteDevice in serial_setparity"); 181 GSM_OSErrorInfo(s, "WriteDevice in serial_setparity");
178 return ERR_DEVICEPARITYERROR; 182 return ERR_DEVICEPARITYERROR;
179 } 183 }
180 184
181 return ERR_NONE; 185 return ERR_NONE;
182} 186}
183 187
184static GSM_Error serial_setdtrrts(GSM_StateMachine *s, bool dtr, bool rts) 188static GSM_Error serial_setdtrrts(GSM_StateMachine *s, bool dtr, bool rts)
185{ 189{
186 DCB dcb; 190 DCB dcb;
187 GSM_Device_SerialData *d = &s->Device.Data.Serial; 191 GSM_Device_SerialData *d = &s->Device.Data.Serial;
188 192
189 dcb.DCBlength = sizeof(DCB); 193 dcb.DCBlength = sizeof(DCB);
190 if (GetCommState(d->hPhone, &dcb)==0) { 194 if (GetCommState(d->hPhone, &dcb)==0) {
191 GSM_OSErrorInfo(s, "ReadDevice in serial_setdtrrts"); 195 GSM_OSErrorInfo(s, "ReadDevice in serial_setdtrrts");
192 return ERR_DEVICEREADERROR; 196 return ERR_DEVICEREADERROR;
193 } 197 }
194 198
diff --git a/gammu/emb/common/gsmcomon.c b/gammu/emb/common/gsmcomon.c
index d094ef3..445c3a6 100644
--- a/gammu/emb/common/gsmcomon.c
+++ b/gammu/emb/common/gsmcomon.c
@@ -1,260 +1,261 @@
1/* (c) 2002-2004 by Marcin Wiacek & Michal Cihar */ 1/* (c) 2002-2004 by Marcin Wiacek & Michal Cihar */
2 2
3#include <ctype.h> 3#include <ctype.h>
4#include <string.h> 4#include <string.h>
5#include <time.h> 5#include <time.h>
6#include <stdio.h> 6#include <stdio.h>
7#ifndef __OpenBSD__ 7#ifndef __OpenBSD__
8# include <wchar.h> 8# include <wchar.h>
9#endif 9#endif
10#ifdef WIN32 10#ifdef WIN32
11# include <windows.h> 11# include <windows.h>
12#else 12#else
13# include <stdlib.h> 13# include <stdlib.h>
14# include <errno.h> 14# include <errno.h>
15# include <fcntl.h> 15# include <fcntl.h>
16# include <signal.h> 16# include <signal.h>
17#endif 17#endif
18 18
19#include "gsmcomon.h" 19#include "gsmcomon.h"
20#include "misc/coding/coding.h" 20#include "misc/coding/coding.h"
21 21
22GSM_Error NoneFunction(void) 22GSM_Error NoneFunction(void)
23{ 23{
24 return ERR_NONE; 24 return ERR_NONE;
25} 25}
26 26
27GSM_Error NotImplementedFunction(void) 27GSM_Error NotImplementedFunction(void)
28{ 28{
29 return ERR_NOTIMPLEMENTED; 29 return ERR_NOTIMPLEMENTED;
30} 30}
31 31
32GSM_Error NotSupportedFunction(void) 32GSM_Error NotSupportedFunction(void)
33{ 33{
34 return ERR_NOTSUPPORTED; 34 return ERR_NOTSUPPORTED;
35} 35}
36 36
37unsigned char *GetMsg (INI_Section *cfg, unsigned char *default_string) 37unsigned char *GetMsg (INI_Section *cfg, unsigned char *default_string)
38{ 38{
39 unsigned char *retval, buffer[40], buff2[40], buff[2000]; 39 unsigned char *retval, buffer[40], buff2[40], buff[2000];
40 static unsigned chardef_str[2000]; 40 static unsigned chardef_str[2000];
41 INI_Entry *e; 41 INI_Entry *e;
42 INI_Section *h; 42 INI_Section *h;
43 int num; 43 int num;
44 int len; 44 int len;
45 45
46 if (cfg==NULL) return default_string; 46 if (cfg==NULL) return default_string;
47 47
48 EncodeUnicode (buff2, "common", 6); 48 EncodeUnicode (buff2, "common", 6);
49 49
50 /* Set all 0x0a to \n */ 50 /* Set all 0x0a to \n */
51 memset(def_str,0,sizeof(def_str)); 51 memset(def_str,0,sizeof(def_str));
52 for (num=0;num<((int)strlen(default_string));num++) { 52 for (num=0;num<((int)strlen(default_string));num++) {
53 if (default_string[num] == 0x0a) { 53 if (default_string[num] == 0x0a) {
54 def_str[strlen(def_str)] = '\\'; 54 def_str[strlen(def_str)] = '\\';
55 def_str[strlen(def_str)] = 'n'; 55 def_str[strlen(def_str)] = 'n';
56 } else def_str[strlen(def_str)] = default_string[num]; 56 } else def_str[strlen(def_str)] = default_string[num];
57 } 57 }
58 58
59 e = NULL; 59 e = NULL;
60 /* First find our section */ 60 /* First find our section */
61 for (h = cfg; h != NULL; h = h->Next) { 61 for (h = cfg; h != NULL; h = h->Next) {
62 if (mywstrncasecmp(buff2, h->SectionName, 0)) { 62 if (mywstrncasecmp(buff2, h->SectionName, 0)) {
63 e = h->SubEntries; 63 e = h->SubEntries;
64 break; 64 break;
65 } 65 }
66 } 66 }
67 while (e != NULL) { 67 while (e != NULL) {
68 num = -1; 68 num = -1;
69 DecodeUnicode(e->EntryName,buffer); 69 DecodeUnicode(e->EntryName,buffer);
70 if (strlen(buffer) == 5 && (buffer[0] == 'F' || buffer[0] == 'f')) { 70 if (strlen(buffer) == 5 && (buffer[0] == 'F' || buffer[0] == 'f')) {
71 num = atoi(buffer+2); 71 num = atoi(buffer+2);
72 } 72 }
73 if (num!=-1) { 73 if (num!=-1) {
74 DecodeUnicode(e->EntryValue,buff); 74 DecodeUnicode(e->EntryValue,buff);
75 /* Remove quotes */ 75 /* Remove quotes */
76 if (buff[0] == '"') { 76 if (buff[0] == '"') {
77 len = strlen(buff); 77 len = strlen(buff);
78 memmove(buff, buff + 1, len - 1); 78 memmove(buff, buff + 1, len - 1);
79 if (buff[len - 2] == '"') buff[len - 2] = 0; 79 if (buff[len - 2] == '"') buff[len - 2] = 0;
80 } 80 }
81 if (strcmp(buff, def_str) == 0) { 81 if (strcmp(buff, def_str) == 0) {
82 sprintf(buff,"T%04i",num); 82 sprintf(buff,"T%04i",num);
83 EncodeUnicode (buffer, buff, 5); 83 EncodeUnicode (buffer, buff, 5);
84 retval = INI_GetValue(cfg, buff2, buffer, true); 84 retval = INI_GetValue(cfg, buff2, buffer, true);
85 if (retval) { 85 if (retval) {
86 sprintf(buff,"%s",DecodeUnicodeConsole(retval+2)); 86 sprintf(buff,"%s",DecodeUnicodeConsole(retval+2));
87 buff[strlen(buff)-1] = 0; 87 buff[strlen(buff)-1] = 0;
88 /* Set all \n to 0x0a */ 88 /* Set all \n to 0x0a */
89 memset(def_str,0,sizeof(def_str)); 89 memset(def_str,0,sizeof(def_str));
90 num = 0; 90 num = 0;
91 while (num != (int)strlen(buff)) { 91 while (num != (int)strlen(buff)) {
92 if (num < (int)strlen(buff) - 1) { 92 if (num < (int)strlen(buff) - 1) {
93 if (buff[num] == '\\' && buff[num+1] == 'n') { 93 if (buff[num] == '\\' && buff[num+1] == 'n') {
94 def_str[strlen(def_str)] = 0x0a; 94 def_str[strlen(def_str)] = 0x0a;
95 num+=2; 95 num+=2;
96 } else { 96 } else {
97 def_str[strlen(def_str)] = buff[num++]; 97 def_str[strlen(def_str)] = buff[num++];
98 } 98 }
99 } else { 99 } else {
100 def_str[strlen(def_str)] = buff[num++]; 100 def_str[strlen(def_str)] = buff[num++];
101 } 101 }
102 } 102 }
103 retval = def_str; 103 retval = def_str;
104 } else { 104 } else {
105 retval = default_string; 105 retval = default_string;
106 } 106 }
107 return retval; 107 return retval;
108 } 108 }
109 } 109 }
110 e = e->Next; 110 e = e->Next;
111 } 111 }
112 return default_string; 112 return default_string;
113} 113}
114 114
115typedef struct { 115typedef struct {
116 GSM_Error ErrorNum; 116 GSM_Error ErrorNum;
117 unsigned char *ErrorText; 117 unsigned char *ErrorText;
118} PrintErrorEntry; 118} PrintErrorEntry;
119 119
120static PrintErrorEntry PrintErrorEntries[] = { 120static PrintErrorEntry PrintErrorEntries[] = {
121 {ERR_NONE, "No error."}, 121 {ERR_NONE, "No error."},
122 {ERR_DEVICEOPENERROR, "Error opening device. Unknown/busy or no permissions."}, 122 {ERR_DEVICEOPENERROR, "Error opening device. Unknown/busy or no permissions."},
123 {ERR_DEVICELOCKED, "Error opening device. Device locked."}, 123 {ERR_DEVICELOCKED, "Error opening device. Device locked."},
124 {ERR_DEVICENOTEXIST, "Error opening device. Not exist."}, 124 {ERR_DEVICENOTEXIST, "Error opening device. Doesn't exist."},
125 {ERR_DEVICEBUSY, "Error opening device. Already opened by other application."}, 125 {ERR_DEVICEBUSY, "Error opening device. Already opened by other application."},
126 {ERR_DEVICENOPERMISSION,"Error opening device. No permissions."}, 126 {ERR_DEVICENOPERMISSION,"Error opening device. No permissions."},
127 {ERR_DEVICENODRIVER, "Error opening device. No required driver in operating system."}, 127 {ERR_DEVICENODRIVER, "Error opening device. No required driver in operating system."},
128 {ERR_DEVICENOTWORK, "Error opening device. Some hardware not connected/wrong configured."}, 128 {ERR_DEVICENOTWORK, "Error opening device. Some hardware not connected/wrong configured."},
129 {ERR_DEVICEDTRRTSERROR, "Error setting device DTR or RTS."}, 129 {ERR_DEVICEDTRRTSERROR, "Error setting device DTR or RTS."},
130 {ERR_DEVICECHANGESPEEDERROR,"Error setting device speed. Maybe speed not supported."}, 130 {ERR_DEVICECHANGESPEEDERROR,"Error setting device speed. Maybe speed not supported."},
131 {ERR_DEVICEWRITEERROR, "Error writing device."}, 131 {ERR_DEVICEWRITEERROR, "Error writing device."},
132 {ERR_DEVICEREADERROR, "Error during reading device"}, 132 {ERR_DEVICEREADERROR, "Error during reading device."},
133 {ERR_DEVICEPARITYERROR, "Can't set parity on device"}, 133 {ERR_DEVICEPARITYERROR, "Can't set parity on device."},
134 {ERR_TIMEOUT, "No response in specified timeout. Probably phone not connected."}, 134 {ERR_TIMEOUT, "No response in specified timeout. Probably phone not connected."},
135 /* Some missed */ 135 /* Some missed */
136 {ERR_UNKNOWNRESPONSE, "Unknown response from phone. See readme.txt, how to report it."}, 136 {ERR_UNKNOWNRESPONSE, "Unknown response from phone. See readme.txt, how to report it."},
137 /* Some missed */ 137 /* Some missed */
138 {ERR_UNKNOWNCONNECTIONTYPESTRING,"Unknown connection type string. Check config file."}, 138 {ERR_UNKNOWNCONNECTIONTYPESTRING,"Unknown connection type string. Check config file."},
139 {ERR_UNKNOWNMODELSTRING,"Unknown model type string. Check config file."}, 139 {ERR_UNKNOWNMODELSTRING,"Unknown model type string. Check config file."},
140 {ERR_SOURCENOTAVAILABLE,"Some required functions not compiled for your OS. Please contact."}, 140 {ERR_SOURCENOTAVAILABLE,"Some required functions not compiled for your OS. Please contact."},
141 {ERR_NOTSUPPORTED, "Function not supported by phone."}, 141 {ERR_NOTSUPPORTED, "Function not supported by phone."},
142 {ERR_EMPTY, "Entry is empty"}, 142 {ERR_EMPTY, "Entry is empty"},
143 {ERR_SECURITYERROR, "Security error. Maybe no PIN ?"}, 143 {ERR_SECURITYERROR, "Security error. Maybe no PIN ?"},
144 {ERR_INVALIDLOCATION, "Invalid location. Maybe too high ?"}, 144 {ERR_INVALIDLOCATION, "Invalid location. Maybe too high ?"},
145 {ERR_NOTIMPLEMENTED, "Function not implemented. Help required."}, 145 {ERR_NOTIMPLEMENTED, "Function not implemented. Help required."},
146 {ERR_FULL, "Memory full."}, 146 {ERR_FULL, "Memory full."},
147 {ERR_UNKNOWN, "Unknown error."}, 147 {ERR_UNKNOWN, "Unknown error."},
148 /* Some missed */ 148 /* Some missed */
149 {ERR_CANTOPENFILE, "Can't open specified file. Read only ?"}, 149 {ERR_CANTOPENFILE, "Can't open specified file. Read only ?"},
150 {ERR_MOREMEMORY, "More memory required..."}, 150 {ERR_MOREMEMORY, "More memory required..."},
151 {ERR_PERMISSION, "Permission to file/device required..."}, 151 {ERR_PERMISSION, "Permission to file/device required..."},
152 {ERR_EMPTYSMSC, "Empty SMSC number. Set in phone or use -smscnumber"}, 152 {ERR_EMPTYSMSC, "Empty SMSC number. Set in phone or use -smscnumber."},
153 {ERR_INSIDEPHONEMENU, "You're inside phone menu (during editing ?). Leave it and try again."}, 153 {ERR_INSIDEPHONEMENU, "You're inside phone menu (during editing ?). Leave it and try again."},
154 {ERR_WORKINPROGRESS, "Function is during writing. If want help, please contact with authors."}, 154 {ERR_WORKINPROGRESS, "Function is during writing. If want help, please contact with authors."},
155 {ERR_PHONEOFF, "Phone is disabled and connected to charger"}, 155 {ERR_PHONEOFF, "Phone is disabled and connected to charger."},
156 {ERR_FILENOTSUPPORTED, "File format not supported by Gammu"}, 156 {ERR_FILENOTSUPPORTED, "File format not supported by Gammu."},
157 {ERR_BUG, "Nobody is perfect, some bug appeared in protocol implementation. Please contact authors."}, 157 {ERR_BUG, "Nobody is perfect, some bug appeared in protocol implementation. Please contact authors."},
158 {ERR_CANCELED, "Transfer was canceled by phone (you pressed cancel on phone?)."}, 158 {ERR_CANCELED, "Transfer was canceled by phone (you pressed cancel on phone?)"},
159 /* Some missed */ 159 /* Some missed */
160 {ERR_OTHERCONNECTIONREQUIRED,"Current connection type doesn't support called function."}, 160 {ERR_OTHERCONNECTIONREQUIRED,"Current connection type doesn't support called function."},
161 /* Some missed */ 161 {ERR_WRONGCRC, "CRC error."},
162 {ERR_INVALIDDATETIME, "Invalid date or time specified."}, 162 {ERR_INVALIDDATETIME, "Invalid date or time specified."},
163 {ERR_MEMORY, "Phone memory error, maybe it is read only"}, 163 {ERR_MEMORY, "Phone memory error, maybe it is read only."},
164 {ERR_INVALIDDATA, "Invalid data"}, 164 {ERR_INVALIDDATA, "Invalid data."},
165 {ERR_FILEALREADYEXIST, "File with specified name already exist."},
165 166
166 {0, ""} 167 {0, ""}
167}; 168};
168 169
169unsigned char *print_error(GSM_Error e, FILE *df, INI_Section *cfg) 170unsigned char *print_error(GSM_Error e, FILE *df, INI_Section *cfg)
170{ 171{
171 unsigned char *def = NULL; 172 unsigned char *def = NULL;
172 int i= 0; 173 int i= 0;
173 174
174 while (PrintErrorEntries[i].ErrorNum != 0) { 175 while (PrintErrorEntries[i].ErrorNum != 0) {
175 if (PrintErrorEntries[i].ErrorNum == e) { 176 if (PrintErrorEntries[i].ErrorNum == e) {
176 def = PrintErrorEntries[i].ErrorText; 177 def = PrintErrorEntries[i].ErrorText;
177 break; 178 break;
178 } 179 }
179 i++; 180 i++;
180 } 181 }
181 if (def == NULL) def = "Unknown error."; 182 if (def == NULL) def = "Unknown error.";
182 if (df!=NULL && di.dl!=0) fprintf(df,"[ERROR %i: %s]\n",e,def); 183 if (df!=NULL && di.dl!=0) fprintf(df,"[ERROR %i: %s]\n",e,def);
183 184
184 return GetMsg(cfg,def); 185 return GetMsg(cfg,def);
185} 186}
186 187
187const char *GetGammuLocalePath(void) 188const char *GetGammuLocalePath(void)
188{ 189{
189#ifdef LOCALE_PATH 190#ifdef LOCALE_PATH
190 static const char Buffer[] = LOCALE_PATH; 191 static const char Buffer[] = LOCALE_PATH;
191 return Buffer; 192 return Buffer;
192#else 193#else
193 return NULL; 194 return NULL;
194#endif 195#endif
195} 196}
196 197
197const char *GetGammuVersion(void) 198const char *GetGammuVersion(void)
198{ 199{
199 static const char Buffer[] = VERSION; 200 static const char Buffer[] = VERSION;
200 return Buffer; 201 return Buffer;
201} 202}
202 203
203GSM_Error GSM_SetDebugFile(char *info, Debug_Info *privdi) 204GSM_Error GSM_SetDebugFile(char *info, Debug_Info *privdi)
204{ 205{
205 FILE *testfile; 206 FILE *testfile;
206 207
207 /* If we should use global file descriptor, use it */ 208 /* If we should use global file descriptor, use it */
208 if (privdi->use_global) { 209 if (privdi->use_global) {
209 /* Aren't we the changing the global di? */ 210 /* Aren't we the changing the global di? */
210 if (privdi != &di) { 211 if (privdi != &di) {
211 if (privdi->df != di.df && 212 if (privdi->df != di.df &&
212 privdi->dl!=0 && 213 privdi->dl!=0 &&
213 fileno(privdi->df) != 1 && 214 fileno(privdi->df) != 1 &&
214 fileno(privdi->df) != 2) 215 fileno(privdi->df) != 2)
215 fclose(privdi->df); 216 fclose(privdi->df);
216 privdi->df = di.df; 217 privdi->df = di.df;
217 return ERR_NONE; 218 return ERR_NONE;
218 } 219 }
219 } else { 220 } else {
220 /* If we should not use global file descriptor, don't even try use it */ 221 /* If we should not use global file descriptor, don't even try use it */
221 if (privdi->df == di.df) privdi->df = stdout; 222 if (privdi->df == di.df) privdi->df = stdout;
222 } 223 }
223 224
224 if (info[0]!=0 && privdi->dl != 0) { 225 if (info[0]!=0 && privdi->dl != 0) {
225 switch (privdi->dl) { 226 switch (privdi->dl) {
226 case DL_BINARY: 227 case DL_BINARY:
227 testfile = fopen(info,"wcb"); 228 testfile = fopen(info,"wcb");
228 break; 229 break;
229 case DL_TEXTERROR: 230 case DL_TEXTERROR:
230 case DL_TEXTERRORDATE: 231 case DL_TEXTERRORDATE:
231 testfile = fopen(info,"ac"); 232 testfile = fopen(info,"ac");
232 if (!testfile) { 233 if (!testfile) {
233 dbgprintf("Can't open debug file\n"); 234 dbgprintf("Can't open debug file\n");
234 return ERR_CANTOPENFILE; 235 return ERR_CANTOPENFILE;
235 } 236 }
236 fseek(testfile, 0, SEEK_END); 237 fseek(testfile, 0, SEEK_END);
237 if (ftell(testfile) > 5000000) { 238 if (ftell(testfile) > 5000000) {
238 fclose(testfile); 239 fclose(testfile);
239 testfile = fopen(info,"wc"); 240 testfile = fopen(info,"wc");
240 } 241 }
241 break; 242 break;
242 default: 243 default:
243 testfile = fopen(info,"wc"); 244 testfile = fopen(info,"wc");
244 } 245 }
245 if (!testfile) { 246 if (!testfile) {
246 dbgprintf("Can't open debug file\n"); 247 dbgprintf("Can't open debug file\n");
247 return ERR_CANTOPENFILE; 248 return ERR_CANTOPENFILE;
248 } else { 249 } else {
249 if (privdi->df && privdi->df != stdout) { 250 if (privdi->df && privdi->df != stdout) {
250 fclose(privdi->df); 251 fclose(privdi->df);
251 } 252 }
252 privdi->df = testfile; 253 privdi->df = testfile;
253 } 254 }
254 } 255 }
255 return ERR_NONE; 256 return ERR_NONE;
256} 257}
257 258
258/* How should editor hadle tabs in this file? Add editor commands here. 259/* How should editor hadle tabs in this file? Add editor commands here.
259 * vim: noexpandtab sw=8 ts=8 sts=8: 260 * vim: noexpandtab sw=8 ts=8 sts=8:
260 */ 261 */
diff --git a/gammu/emb/common/gsmcomon.h b/gammu/emb/common/gsmcomon.h
index cd36708..e067955 100644
--- a/gammu/emb/common/gsmcomon.h
+++ b/gammu/emb/common/gsmcomon.h
@@ -1,92 +1,93 @@
1/* (c) 2002-2004 by Marcin Wiacek & Michal Cihar */ 1/* (c) 2002-2004 by Marcin Wiacek & Michal Cihar */
2 2
3#ifndef __gsm_comon_h 3#ifndef __gsm_comon_h
4#define __gsm_comon_h 4#define __gsm_comon_h
5 5
6#include <stdio.h> 6#include <stdio.h>
7#ifndef WIN32 7#ifndef WIN32
8# include <unistd.h> 8# include <unistd.h>
9#endif 9#endif
10 10
11#include "config.h" 11#include "config.h"
12#include "misc/misc.h" 12#include "misc/misc.h"
13#include "misc/cfg.h" 13#include "misc/cfg.h"
14 14
15 #define MAX_MANUFACTURER_LENGTH 50 15 #define MAX_MANUFACTURER_LENGTH 50
16 #define MAX_MODEL_LENGTH 50 16 #define MAX_MODEL_LENGTH 50
17 #define MAX_VERSION_LENGTH 50 17 #define MAX_VERSION_LENGTH 50
18 #define MAX_VERSION_DATE_LENGTH 50 18 #define MAX_VERSION_DATE_LENGTH 50
19 #define MAX_IMEI_LENGTH 20 19 #define MAX_IMEI_LENGTH 20
20 #define PHONE_MAXSMSINFOLDER 200 20 #define PHONE_MAXSMSINFOLDER 200
21 #define GSM_MAX_NUMBER_LENGTH 50 21 #define GSM_MAX_NUMBER_LENGTH 50
22 #define GSM_MAXCALENDARTODONOTES300 22 #define GSM_MAXCALENDARTODONOTES300
23 23
24/* GSM_Error is used to notify about errors */ 24/* GSM_Error is used to notify about errors */
25typedef enum { 25typedef enum {
26 /* 1*/ERR_NONE=1, 26 /* 1*/ERR_NONE=1,
27 ERR_DEVICEOPENERROR, /* Error during opening device */ 27 ERR_DEVICEOPENERROR, /* Error during opening device */
28 ERR_DEVICELOCKED, /* Device locked */ 28 ERR_DEVICELOCKED, /* Device locked */
29 ERR_DEVICENOTEXIST, 29 ERR_DEVICENOTEXIST,
30 ERR_DEVICEBUSY, 30 ERR_DEVICEBUSY,
31 ERR_DEVICENOPERMISSION, 31 ERR_DEVICENOPERMISSION,
32 ERR_DEVICENODRIVER, 32 ERR_DEVICENODRIVER,
33 ERR_DEVICENOTWORK, 33 ERR_DEVICENOTWORK,
34 ERR_DEVICEDTRRTSERROR, /* Error during setting DTR/RTS in device */ 34 ERR_DEVICEDTRRTSERROR, /* Error during setting DTR/RTS in device */
35 /*10*/ ERR_DEVICECHANGESPEEDERROR,/* Error during changing speed in device */ 35 /*10*/ ERR_DEVICECHANGESPEEDERROR,/* Error during changing speed in device */
36 ERR_DEVICEWRITEERROR, /* Error during writing device */ 36 ERR_DEVICEWRITEERROR, /* Error during writing device */
37 ERR_DEVICEREADERROR, /* Error during reading device */ 37 ERR_DEVICEREADERROR, /* Error during reading device */
38 ERR_DEVICEPARITYERROR, /* Can't set parity on device */ 38 ERR_DEVICEPARITYERROR, /* Can't set parity on device */
39 ERR_TIMEOUT, /* Command timed out */ 39 ERR_TIMEOUT, /* Command timed out */
40 ERR_FRAMENOTREQUESTED, /* Frame handled, but not requested in this moment */ 40 ERR_FRAMENOTREQUESTED, /* Frame handled, but not requested in this moment */
41 ERR_UNKNOWNRESPONSE, /* Response not handled by gammu */ 41 ERR_UNKNOWNRESPONSE, /* Response not handled by gammu */
42 ERR_UNKNOWNFRAME, /* Frame not handled by gammu */ 42 ERR_UNKNOWNFRAME, /* Frame not handled by gammu */
43 ERR_UNKNOWNCONNECTIONTYPESTRING,/* Unknown connection type given by user */ 43 ERR_UNKNOWNCONNECTIONTYPESTRING,/* Unknown connection type given by user */
44 ERR_UNKNOWNMODELSTRING, /* Unknown model given by user */ 44 ERR_UNKNOWNMODELSTRING, /* Unknown model given by user */
45 /*20*/ ERR_SOURCENOTAVAILABLE, /* Some functions not compiled in your OS */ 45 /*20*/ ERR_SOURCENOTAVAILABLE, /* Some functions not compiled in your OS */
46 ERR_NOTSUPPORTED, /* Not supported by phone */ 46 ERR_NOTSUPPORTED, /* Not supported by phone */
47 ERR_EMPTY, /* Empty phonebook entry, ... */ 47 ERR_EMPTY, /* Empty phonebook entry, ... */
48 ERR_SECURITYERROR, /* Not allowed */ 48 ERR_SECURITYERROR, /* Not allowed */
49 ERR_INVALIDLOCATION, /* Too high or too low location... */ 49 ERR_INVALIDLOCATION, /* Too high or too low location... */
50 ERR_NOTIMPLEMENTED, /* Function not implemented */ 50 ERR_NOTIMPLEMENTED, /* Function not implemented */
51 ERR_FULL, /* Memory is full */ 51 ERR_FULL, /* Memory is full */
52 ERR_UNKNOWN, 52 ERR_UNKNOWN,
53 ERR_CANTOPENFILE, /* Error during opening file */ 53 ERR_CANTOPENFILE, /* Error during opening file */
54 ERR_MOREMEMORY, /* More memory required */ 54 ERR_MOREMEMORY, /* More memory required */
55 /*30*/ ERR_PERMISSION, /* No permission */ 55 /*30*/ ERR_PERMISSION, /* No permission */
56 ERR_EMPTYSMSC, /* SMSC number is empty */ 56 ERR_EMPTYSMSC, /* SMSC number is empty */
57 ERR_INSIDEPHONEMENU, /* Inside phone menu - can't make something */ 57 ERR_INSIDEPHONEMENU, /* Inside phone menu - can't make something */
58 ERR_NOTCONNECTED, /* Phone NOT connected - can't make something */ 58 ERR_NOTCONNECTED, /* Phone NOT connected - can't make something */
59 ERR_WORKINPROGRESS, /* Work in progress */ 59 ERR_WORKINPROGRESS, /* Work in progress */
60 ERR_PHONEOFF, /* Phone is disabled and connected to charger */ 60 ERR_PHONEOFF, /* Phone is disabled and connected to charger */
61 ERR_FILENOTSUPPORTED, /* File format not supported by Gammu */ 61 ERR_FILENOTSUPPORTED, /* File format not supported by Gammu */
62 ERR_BUG, /* Found bug in implementation or phone */ 62 ERR_BUG, /* Found bug in implementation or phone */
63 ERR_CANCELED, /* Action was canceled by user */ 63 ERR_CANCELED, /* Action was canceled by user */
64 ERR_NEEDANOTHERANSWER, /* Inside Gammu: phone module need to send another answer frame */ 64 ERR_NEEDANOTHERANSWER, /* Inside Gammu: phone module need to send another answer frame */
65 /*40*/ERR_OTHERCONNECTIONREQUIRED, 65 /*40*/ERR_OTHERCONNECTIONREQUIRED,
66 ERR_WRONGCRC, 66 ERR_WRONGCRC,
67 ERR_INVALIDDATETIME, /* Invalid date/time */ 67 ERR_INVALIDDATETIME, /* Invalid date/time */
68 ERR_MEMORY, /* Phone memory error, maybe it is read only */ 68 ERR_MEMORY, /* Phone memory error, maybe it is read only */
69 ERR_INVALIDDATA /* Invalid data */ 69 ERR_INVALIDDATA, /* Invalid data */
70 ERR_FILEALREADYEXIST /* File with specified name already exist */
70} GSM_Error; 71} GSM_Error;
71 72
72 extern GSM_Error NoneFunction (void); 73 extern GSM_Error NoneFunction (void);
73 extern GSM_Error NotImplementedFunction(void); 74 extern GSM_Error NotImplementedFunction(void);
74 extern GSM_Error NotSupportedFunction(void); 75 extern GSM_Error NotSupportedFunction(void);
75 76
76 #define NONEFUNCTION (void *) NoneFunction 77 #define NONEFUNCTION (void *) NoneFunction
77 #define NOTIMPLEMENTED (void *) NotImplementedFunction 78 #define NOTIMPLEMENTED (void *) NotImplementedFunction
78 #define NOTSUPPORTED (void *) NotSupportedFunction 79 #define NOTSUPPORTED (void *) NotSupportedFunction
79 80
80 unsigned char *GetMsg (INI_Section *cfg, unsigned char *default_string); 81 unsigned char *GetMsg (INI_Section *cfg, unsigned char *default_string);
81 unsigned char *print_error(GSM_Error e, FILE *df, INI_Section *cfg); 82 unsigned char *print_error(GSM_Error e, FILE *df, INI_Section *cfg);
82 83
83GSM_Error GSM_SetDebugFile(char *info, Debug_Info *privdi); 84GSM_Error GSM_SetDebugFile(char *info, Debug_Info *privdi);
84 85
85const char *GetGammuLocalePath(void); 86const char *GetGammuLocalePath(void);
86const char *GetGammuVersion(void); 87const char *GetGammuVersion(void);
87 88
88#endif 89#endif
89 90
90/* How should editor hadle tabs in this file? Add editor commands here. 91/* How should editor hadle tabs in this file? Add editor commands here.
91 * vim: noexpandtab sw=8 ts=8 sts=8: 92 * vim: noexpandtab sw=8 ts=8 sts=8:
92 */ 93 */
diff --git a/gammu/emb/common/gsmstate.c b/gammu/emb/common/gsmstate.c
index b8f5f89..31e365d 100644
--- a/gammu/emb/common/gsmstate.c
+++ b/gammu/emb/common/gsmstate.c
@@ -1,1198 +1,1230 @@
1/* (c) 2002-2004 by Marcin Wiacek */ 1/* (c) 2002-2004 by Marcin Wiacek */
2/* Phones ID (c) partially by Walek */ 2/* Phones ID (c) partially by Walek */
3 3
4#include <stdarg.h> 4#include <stdarg.h>
5#include <string.h> 5#include <string.h>
6#include <errno.h> 6#include <errno.h>
7 7
8#include "gsmcomon.h" 8#include "gsmcomon.h"
9#include "gsmstate.h" 9#include "gsmstate.h"
10#include "misc/cfg.h" 10#include "misc/cfg.h"
11#include "misc/coding/coding.h" 11#include "misc/coding/coding.h"
12#include "device/devfunc.h" 12#include "device/devfunc.h"
13 13
14static void GSM_RegisterConnection(GSM_StateMachine *s, unsigned int connection, 14static void GSM_RegisterConnection(GSM_StateMachine *s, unsigned int connection,
15 GSM_Device_Functions *device, GSM_Protocol_Functions *protocol) 15 GSM_Device_Functions *device, GSM_Protocol_Functions *protocol)
16{ 16{
17 if ((unsigned int)s->ConnectionType == connection) { 17 if ((unsigned int)s->ConnectionType == connection) {
18 s->Device.Functions = device; 18 s->Device.Functions = device;
19 s->Protocol.Functions= protocol; 19 s->Protocol.Functions= protocol;
20 } 20 }
21} 21}
22 22
23static GSM_Error GSM_RegisterAllConnections(GSM_StateMachine *s, char *connection) 23static GSM_Error GSM_RegisterAllConnections(GSM_StateMachine *s, char *connection)
24{ 24{
25 /* We check here is used connection string type is correct for ANY 25 /* We check here is used connection string type is correct for ANY
26 * OS. If not, we return with error, that string is incorrect at all 26 * OS. If not, we return with error, that string is incorrect at all
27 */ 27 */
28 s->ConnectionType = 0; 28 s->ConnectionType = 0;
29 if (mystrncasecmp("mbus",connection,0)) s->ConnectionType = GCT_MBUS2; 29 if (mystrncasecmp("mbus",connection,0)) s->ConnectionType = GCT_MBUS2;
30 if (mystrncasecmp("fbus",connection,0)) s->ConnectionType = GCT_FBUS2; 30 if (mystrncasecmp("fbus",connection,0)) s->ConnectionType = GCT_FBUS2;
31 if (mystrncasecmp("fbusdlr3",connection,0)) s->ConnectionType = GCT_FBUS2DLR3; 31 if (mystrncasecmp("fbusdlr3",connection,0)) s->ConnectionType = GCT_FBUS2DLR3;
32 if (mystrncasecmp("fbusdku5",connection,0)) s->ConnectionType = GCT_FBUS2DKU5; 32 if (mystrncasecmp("fbusdku5",connection,0)) s->ConnectionType = GCT_FBUS2DKU5;
33 if (mystrncasecmp("fbuspl2303",connection,0)) s->ConnectionType = GCT_FBUS2PL2303; 33 if (mystrncasecmp("fbuspl2303",connection,0)) s->ConnectionType = GCT_FBUS2PL2303;
34 if (mystrncasecmp("fbusblue",connection,0)) s->ConnectionType = GCT_FBUS2BLUE; 34 if (mystrncasecmp("fbusblue",connection,0)) s->ConnectionType = GCT_FBUS2BLUE;
35 if (mystrncasecmp("fbusirda",connection,0)) s->ConnectionType = GCT_FBUS2IRDA; 35 if (mystrncasecmp("fbusirda",connection,0)) s->ConnectionType = GCT_FBUS2IRDA;
36 if (mystrncasecmp("phonetblue",connection,0)) s->ConnectionType = GCT_PHONETBLUE; 36 if (mystrncasecmp("phonetblue",connection,0)) s->ConnectionType = GCT_PHONETBLUE;
37 if (mystrncasecmp("mrouterblue",connection,0)) s->ConnectionType = GCT_MROUTERBLUE; 37 if (mystrncasecmp("mrouterblue",connection,0)) s->ConnectionType = GCT_MROUTERBLUE;
38 if (mystrncasecmp("irdaphonet",connection,0)) s->ConnectionType = GCT_IRDAPHONET; 38 if (mystrncasecmp("irdaphonet",connection,0)) s->ConnectionType = GCT_IRDAPHONET;
39 if (mystrncasecmp("irdaat",connection,0)) s->ConnectionType = GCT_IRDAAT; 39 if (mystrncasecmp("irdaat",connection,0)) s->ConnectionType = GCT_IRDAAT;
40 if (mystrncasecmp("irdaobex",connection,0)) s->ConnectionType = GCT_IRDAOBEX; 40 if (mystrncasecmp("irdaobex",connection,0)) s->ConnectionType = GCT_IRDAOBEX;
41 if (mystrncasecmp("blueobex",connection,0)) s->ConnectionType = GCT_BLUEOBEX; 41 if (mystrncasecmp("blueobex",connection,0)) s->ConnectionType = GCT_BLUEOBEX;
42 if (mystrncasecmp("bluefbus",connection,0)) s->ConnectionType = GCT_BLUEFBUS2; 42 if (mystrncasecmp("bluefbus",connection,0)) s->ConnectionType = GCT_BLUEFBUS2;
43 if (mystrncasecmp("bluephonet",connection,0)) s->ConnectionType = GCT_BLUEPHONET; 43 if (mystrncasecmp("bluephonet",connection,0)) s->ConnectionType = GCT_BLUEPHONET;
44 if (mystrncasecmp("blueat",connection,0)) s->ConnectionType = GCT_BLUEAT; 44 if (mystrncasecmp("blueat",connection,0)) s->ConnectionType = GCT_BLUEAT;
45 if (mystrncasecmp("bluerfobex",connection,0)) s->ConnectionType = GCT_BLUEOBEX; 45 if (mystrncasecmp("bluerfobex",connection,0)) s->ConnectionType = GCT_BLUEOBEX;
46 if (mystrncasecmp("bluerffbus",connection,0)) s->ConnectionType = GCT_BLUEFBUS2; 46 if (mystrncasecmp("bluerffbus",connection,0)) s->ConnectionType = GCT_BLUEFBUS2;
47 if (mystrncasecmp("bluerfphonet",connection,0)) s->ConnectionType = GCT_BLUEPHONET; 47 if (mystrncasecmp("bluerfphonet",connection,0)) s->ConnectionType = GCT_BLUEPHONET;
48 if (mystrncasecmp("bluerfat",connection,0)) s->ConnectionType = GCT_BLUEAT; 48 if (mystrncasecmp("bluerfat",connection,0)) s->ConnectionType = GCT_BLUEAT;
49 49
50 /* These are for compatibility only */ 50 /* These are for compatibility only */
51 if (mystrncasecmp("atblue",connection,0)) s->ConnectionType = GCT_BLUEAT; 51 if (mystrncasecmp("atblue",connection,0)) s->ConnectionType = GCT_BLUEAT;
52 if (mystrncasecmp("dlr3blue",connection,0)) s->ConnectionType = GCT_BLUEFBUS2; 52 if (mystrncasecmp("dlr3blue",connection,0)) s->ConnectionType = GCT_BLUEFBUS2;
53 if (mystrncasecmp("irda",connection,0)) s->ConnectionType = GCT_IRDAPHONET; 53 if (mystrncasecmp("irda",connection,0)) s->ConnectionType = GCT_IRDAPHONET;
54 if (mystrncasecmp("dlr3",connection,0)) s->ConnectionType = GCT_FBUS2DLR3; 54 if (mystrncasecmp("dlr3",connection,0)) s->ConnectionType = GCT_FBUS2DLR3;
55 if (mystrncasecmp("infrared",connection,0)) s->ConnectionType = GCT_FBUS2IRDA; 55 if (mystrncasecmp("infrared",connection,0)) s->ConnectionType = GCT_FBUS2IRDA;
56 56
57 if (mystrncasecmp("at" ,connection,2)) { 57 if (mystrncasecmp("at" ,connection,2)) {
58 /* Use some resonable default, when no speed defined */ 58 /* Use some resonable default, when no speed defined */
59 if (strlen(connection) == 2) { 59 if (strlen(connection) == 2) {
60 s->Speed = 19200; 60 s->Speed = 19200;
61 } else { 61 } else {
62 s->Speed = FindSerialSpeed(connection+2); 62 s->Speed = FindSerialSpeed(connection+2);
63 } 63 }
64 if (s->Speed != 0) s->ConnectionType = GCT_AT; 64 if (s->Speed != 0) s->ConnectionType = GCT_AT;
65 } 65 }
66 if (s->ConnectionType==0) return ERR_UNKNOWNCONNECTIONTYPESTRING; 66 if (s->ConnectionType==0) return ERR_UNKNOWNCONNECTIONTYPESTRING;
67 67
68 /* We check now if user gave connection type compiled & available 68 /* We check now if user gave connection type compiled & available
69 * for used OS (if not, we return, that source not available) 69 * for used OS (if not, we return, that source not available)
70 */ 70 */
71 s->Device.Functions = NULL; 71 s->Device.Functions = NULL;
72 s->Protocol.Functions= NULL; 72 s->Protocol.Functions= NULL;
73#ifdef GSM_ENABLE_MBUS2 73#ifdef GSM_ENABLE_MBUS2
74 GSM_RegisterConnection(s, GCT_MBUS2, &SerialDevice, &MBUS2Protocol); 74 GSM_RegisterConnection(s, GCT_MBUS2, &SerialDevice, &MBUS2Protocol);
75#endif 75#endif
76#ifdef GSM_ENABLE_FBUS2 76#ifdef GSM_ENABLE_FBUS2
77 GSM_RegisterConnection(s, GCT_FBUS2, &SerialDevice, &FBUS2Protocol); 77 GSM_RegisterConnection(s, GCT_FBUS2, &SerialDevice, &FBUS2Protocol);
78#endif 78#endif
79#ifdef GSM_ENABLE_FBUS2DLR3 79#ifdef GSM_ENABLE_FBUS2DLR3
80 GSM_RegisterConnection(s, GCT_FBUS2DLR3, &SerialDevice, &FBUS2Protocol); 80 GSM_RegisterConnection(s, GCT_FBUS2DLR3, &SerialDevice, &FBUS2Protocol);
81#endif 81#endif
82#ifdef GSM_ENABLE_FBUS2DKU5 82#ifdef GSM_ENABLE_FBUS2DKU5
83 GSM_RegisterConnection(s, GCT_FBUS2DKU5, &SerialDevice, &FBUS2Protocol); 83 GSM_RegisterConnection(s, GCT_FBUS2DKU5, &SerialDevice, &FBUS2Protocol);
84#endif 84#endif
85#ifdef GSM_ENABLE_FBUS2PL2303 85#ifdef GSM_ENABLE_FBUS2PL2303
86 GSM_RegisterConnection(s, GCT_FBUS2PL2303,&SerialDevice, &FBUS2Protocol); 86 GSM_RegisterConnection(s, GCT_FBUS2PL2303,&SerialDevice, &FBUS2Protocol);
87#endif 87#endif
88#ifdef GSM_ENABLE_FBUS2BLUE 88#ifdef GSM_ENABLE_FBUS2BLUE
89 GSM_RegisterConnection(s, GCT_FBUS2BLUE, &SerialDevice, &FBUS2Protocol); 89 GSM_RegisterConnection(s, GCT_FBUS2BLUE, &SerialDevice, &FBUS2Protocol);
90#endif 90#endif
91#ifdef GSM_ENABLE_FBUS2IRDA 91#ifdef GSM_ENABLE_FBUS2IRDA
92 GSM_RegisterConnection(s, GCT_FBUS2IRDA, &SerialDevice, &FBUS2Protocol); 92 GSM_RegisterConnection(s, GCT_FBUS2IRDA, &SerialDevice, &FBUS2Protocol);
93#endif 93#endif
94#ifdef GSM_ENABLE_PHONETBLUE 94#ifdef GSM_ENABLE_PHONETBLUE
95 GSM_RegisterConnection(s, GCT_PHONETBLUE,&SerialDevice, &PHONETProtocol); 95 GSM_RegisterConnection(s, GCT_PHONETBLUE,&SerialDevice, &PHONETProtocol);
96#endif 96#endif
97#ifdef GSM_ENABLE_MROUTERBLUE 97#ifdef GSM_ENABLE_MROUTERBLUE
98 GSM_RegisterConnection(s, GCT_MROUTERBLUE,&SerialDevice, &MROUTERProtocol); 98 GSM_RegisterConnection(s, GCT_MROUTERBLUE,&SerialDevice, &MROUTERProtocol);
99#endif 99#endif
100#ifdef GSM_ENABLE_IRDAPHONET 100#ifdef GSM_ENABLE_IRDAPHONET
101 GSM_RegisterConnection(s, GCT_IRDAPHONET,&IrdaDevice, &PHONETProtocol); 101 GSM_RegisterConnection(s, GCT_IRDAPHONET,&IrdaDevice, &PHONETProtocol);
102#endif 102#endif
103#ifdef GSM_ENABLE_BLUEFBUS2 103#ifdef GSM_ENABLE_BLUEFBUS2
104 GSM_RegisterConnection(s, GCT_BLUEFBUS2, &BlueToothDevice,&FBUS2Protocol); 104 GSM_RegisterConnection(s, GCT_BLUEFBUS2, &BlueToothDevice,&FBUS2Protocol);
105#endif 105#endif
106#ifdef GSM_ENABLE_BLUEPHONET 106#ifdef GSM_ENABLE_BLUEPHONET
107 GSM_RegisterConnection(s, GCT_BLUEPHONET,&BlueToothDevice,&PHONETProtocol); 107 GSM_RegisterConnection(s, GCT_BLUEPHONET,&BlueToothDevice,&PHONETProtocol);
108#endif 108#endif
109#ifdef GSM_ENABLE_BLUEAT 109#ifdef GSM_ENABLE_BLUEAT
110 GSM_RegisterConnection(s, GCT_BLUEAT, &BlueToothDevice,&ATProtocol); 110 GSM_RegisterConnection(s, GCT_BLUEAT, &BlueToothDevice,&ATProtocol);
111#endif 111#endif
112#ifdef GSM_ENABLE_AT 112#ifdef GSM_ENABLE_AT
113 GSM_RegisterConnection(s, GCT_AT, &SerialDevice, &ATProtocol); 113 GSM_RegisterConnection(s, GCT_AT, &SerialDevice, &ATProtocol);
114#endif 114#endif
115#ifdef GSM_ENABLE_IRDAAT 115#ifdef GSM_ENABLE_IRDAAT
116 GSM_RegisterConnection(s, GCT_IRDAAT, &IrdaDevice, &ATProtocol); 116 GSM_RegisterConnection(s, GCT_IRDAAT, &IrdaDevice, &ATProtocol);
117#endif 117#endif
118#ifdef GSM_ENABLE_IRDAOBEX 118#ifdef GSM_ENABLE_IRDAOBEX
119 GSM_RegisterConnection(s, GCT_IRDAOBEX, &IrdaDevice, &OBEXProtocol); 119 GSM_RegisterConnection(s, GCT_IRDAOBEX, &IrdaDevice, &OBEXProtocol);
120#endif 120#endif
121#ifdef GSM_ENABLE_BLUEOBEX 121#ifdef GSM_ENABLE_BLUEOBEX
122 GSM_RegisterConnection(s, GCT_BLUEOBEX, &BlueToothDevice,&OBEXProtocol); 122 GSM_RegisterConnection(s, GCT_BLUEOBEX, &BlueToothDevice,&OBEXProtocol);
123#endif 123#endif
124 if (s->Device.Functions==NULL || s->Protocol.Functions==NULL) 124 if (s->Device.Functions==NULL || s->Protocol.Functions==NULL)
125 return ERR_SOURCENOTAVAILABLE; 125 return ERR_SOURCENOTAVAILABLE;
126 return ERR_NONE; 126 return ERR_NONE;
127} 127}
128 128
129static void GSM_RegisterModule(GSM_StateMachine *s,GSM_Phone_Functions *phone) 129static void GSM_RegisterModule(GSM_StateMachine *s,GSM_Phone_Functions *phone)
130{ 130{
131 /* Auto model */ 131 /* Auto model */
132 if (s->CurrentConfig->Model[0] == 0) { 132 if (s->CurrentConfig->Model[0] == 0) {
133 if (strstr(phone->models,GetModelData(NULL,s->Phone.Data.Model,NULL)->model) != NULL) { 133 if (strstr(phone->models,GetModelData(NULL,s->Phone.Data.Model,NULL)->model) != NULL) {
134 smprintf(s,"[Module - \"%s\"]\n",phone->models); 134 smprintf(s,"[Module - \"%s\"]\n",phone->models);
135 s->Phone.Functions = phone; 135 s->Phone.Functions = phone;
136 } 136 }
137 } else { 137 } else {
138 if (strstr(phone->models,s->CurrentConfig->Model) != NULL) { 138 if (strstr(phone->models,s->CurrentConfig->Model) != NULL) {
139 smprintf(s,"[Module - \"%s\"]\n",phone->models); 139 smprintf(s,"[Module - \"%s\"]\n",phone->models);
140 s->Phone.Functions = phone; 140 s->Phone.Functions = phone;
141 } 141 }
142 } 142 }
143} 143}
144 144
145GSM_Error GSM_RegisterAllPhoneModules(GSM_StateMachine *s) 145GSM_Error GSM_RegisterAllPhoneModules(GSM_StateMachine *s)
146{ 146{
147 OnePhoneModel *model; 147 OnePhoneModel *model;
148 148
149 /* Auto model */ 149 /* Auto model */
150 if (s->CurrentConfig->Model[0] == 0) { 150 if (s->CurrentConfig->Model[0] == 0) {
151 model = GetModelData(NULL,s->Phone.Data.Model,NULL); 151 model = GetModelData(NULL,s->Phone.Data.Model,NULL);
152#ifdef GSM_ENABLE_ALCATEL 152#ifdef GSM_ENABLE_ALCATEL
153 if (model->model[0] != 0 && IsPhoneFeatureAvailable(model, F_ALCATEL)) { 153 if (model->model[0] != 0 && IsPhoneFeatureAvailable(model, F_ALCATEL)) {
154 smprintf(s,"[Module - \"%s\"]\n",ALCATELPhone.models); 154 smprintf(s,"[Module - \"%s\"]\n",ALCATELPhone.models);
155 s->Phone.Functions = &ALCATELPhone; 155 s->Phone.Functions = &ALCATELPhone;
156 return ERR_NONE; 156 return ERR_NONE;
157 } 157 }
158#endif 158#endif
159#ifdef GSM_ENABLE_ATGEN 159#ifdef GSM_ENABLE_ATGEN
160 /* With ATgen and auto model we can work with unknown models too */ 160 /* With ATgen and auto model we can work with unknown models too */
161 if (s->ConnectionType==GCT_AT || s->ConnectionType==GCT_BLUEAT || s->ConnectionType==GCT_IRDAAT) { 161 if (s->ConnectionType==GCT_AT || s->ConnectionType==GCT_BLUEAT || s->ConnectionType==GCT_IRDAAT) {
162 smprintf(s,"[Module - \"%s\"]\n",ATGENPhone.models); 162 smprintf(s,"[Module - \"%s\"]\n",ATGENPhone.models);
163 s->Phone.Functions = &ATGENPhone; 163 s->Phone.Functions = &ATGENPhone;
164 return ERR_NONE; 164 return ERR_NONE;
165 } 165 }
166#endif 166#endif
167 if (model->model[0] == 0) return ERR_UNKNOWNMODELSTRING; 167 if (model->model[0] == 0) return ERR_UNKNOWNMODELSTRING;
168 } 168 }
169 s->Phone.Functions=NULL; 169 s->Phone.Functions=NULL;
170#ifdef GSM_ENABLE_ATGEN 170#ifdef GSM_ENABLE_ATGEN
171 /* AT module can have the same models ID to "normal" Nokia modules */ 171 /* AT module can have the same models ID to "normal" Nokia modules */
172 if (s->ConnectionType==GCT_AT || s->ConnectionType==GCT_BLUEAT || s->ConnectionType==GCT_IRDAAT) { 172 if (s->ConnectionType==GCT_AT || s->ConnectionType==GCT_BLUEAT || s->ConnectionType==GCT_IRDAAT) {
173 GSM_RegisterModule(s,&ATGENPhone); 173 GSM_RegisterModule(s,&ATGENPhone);
174 if (s->Phone.Functions!=NULL) return ERR_NONE; 174 if (s->Phone.Functions!=NULL) return ERR_NONE;
175 } 175 }
176#endif 176#endif
177#ifdef GSM_ENABLE_OBEXGEN 177#ifdef GSM_ENABLE_OBEXGEN
178 GSM_RegisterModule(s,&OBEXGENPhone); 178 GSM_RegisterModule(s,&OBEXGENPhone);
179#endif 179#endif
180#ifdef GSM_ENABLE_MROUTERGEN 180#ifdef GSM_ENABLE_MROUTERGEN
181 GSM_RegisterModule(s,&MROUTERGENPhone); 181 GSM_RegisterModule(s,&MROUTERGENPhone);
182#endif 182#endif
183#ifdef GSM_ENABLE_NOKIA3320 183#ifdef GSM_ENABLE_NOKIA3320
184 GSM_RegisterModule(s,&N3320Phone); 184 GSM_RegisterModule(s,&N3320Phone);
185#endif 185#endif
186#ifdef GSM_ENABLE_NOKIA3650 186#ifdef GSM_ENABLE_NOKIA3650
187 GSM_RegisterModule(s,&N3650Phone); 187 GSM_RegisterModule(s,&N3650Phone);
188#endif 188#endif
189#ifdef GSM_ENABLE_NOKIA650
190 GSM_RegisterModule(s,&N650Phone);
191#endif
189#ifdef GSM_ENABLE_NOKIA6110 192#ifdef GSM_ENABLE_NOKIA6110
190 GSM_RegisterModule(s,&N6110Phone); 193 GSM_RegisterModule(s,&N6110Phone);
191#endif 194#endif
192#ifdef GSM_ENABLE_NOKIA6510 195#ifdef GSM_ENABLE_NOKIA6510
193 GSM_RegisterModule(s,&N6510Phone); 196 GSM_RegisterModule(s,&N6510Phone);
194#endif 197#endif
195#ifdef GSM_ENABLE_NOKIA7110 198#ifdef GSM_ENABLE_NOKIA7110
196 GSM_RegisterModule(s,&N7110Phone); 199 GSM_RegisterModule(s,&N7110Phone);
197#endif 200#endif
198#ifdef GSM_ENABLE_NOKIA9210 201#ifdef GSM_ENABLE_NOKIA9210
199 GSM_RegisterModule(s,&N9210Phone); 202 GSM_RegisterModule(s,&N9210Phone);
200#endif 203#endif
201#ifdef GSM_ENABLE_ALCATEL 204#ifdef GSM_ENABLE_ALCATEL
202 GSM_RegisterModule(s,&ALCATELPhone); 205 GSM_RegisterModule(s,&ALCATELPhone);
203#endif 206#endif
204 if (s->Phone.Functions==NULL) return ERR_UNKNOWNMODELSTRING; 207 if (s->Phone.Functions==NULL) return ERR_UNKNOWNMODELSTRING;
205 return ERR_NONE; 208 return ERR_NONE;
206} 209}
207 210
208GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum) 211GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum)
209{ 212{
210 GSM_Errorerror; 213 GSM_Errorerror;
211 GSM_DateTimetime; 214 GSM_DateTimetime;
212 int i; 215 int i;
213 char Buffer[80];
214 216
215 for (i=0;i<s->ConfigNum;i++) { 217 for (i=0;i<s->ConfigNum;i++) {
216 s->CurrentConfig = &s->Config[i]; 218 s->CurrentConfig = &s->Config[i];
217 219
218 s->Speed = 0; 220 s->Speed = 0;
219 s->ReplyNum = ReplyNum; 221 s->ReplyNum = ReplyNum;
220 s->Phone.Data.ModelInfo = GetModelData("unknown",NULL,NULL); 222 s->Phone.Data.ModelInfo = GetModelData("unknown",NULL,NULL);
221 s->Phone.Data.Manufacturer[0] = 0; 223 s->Phone.Data.Manufacturer[0] = 0;
222 s->Phone.Data.Model[0] = 0; 224 s->Phone.Data.Model[0] = 0;
223 s->Phone.Data.Version[0] = 0; 225 s->Phone.Data.Version[0] = 0;
224 s->Phone.Data.VerDate[0] = 0; 226 s->Phone.Data.VerDate[0] = 0;
225 s->Phone.Data.VerNum = 0; 227 s->Phone.Data.VerNum = 0;
226 s->Phone.Data.StartInfoCounter = 0; 228 s->Phone.Data.StartInfoCounter = 0;
227 s->Phone.Data.SentMsg = NULL; 229 s->Phone.Data.SentMsg = NULL;
228 230
229 s->Phone.Data.HardwareCache[0] = 0; 231 s->Phone.Data.HardwareCache[0] = 0;
230 s->Phone.Data.ProductCodeCache[0] = 0; 232 s->Phone.Data.ProductCodeCache[0] = 0;
231 s->Phone.Data.EnableIncomingCall = false; 233 s->Phone.Data.EnableIncomingCall = false;
232 s->Phone.Data.EnableIncomingSMS = false; 234 s->Phone.Data.EnableIncomingSMS = false;
233 s->Phone.Data.EnableIncomingCB = false; 235 s->Phone.Data.EnableIncomingCB = false;
234 s->Phone.Data.EnableIncomingUSSD = false; 236 s->Phone.Data.EnableIncomingUSSD = false;
235 s->User.UserReplyFunctions = NULL; 237 s->User.UserReplyFunctions = NULL;
236 s->User.IncomingCall = NULL; 238 s->User.IncomingCall = NULL;
237 s->User.IncomingSMS = NULL; 239 s->User.IncomingSMS = NULL;
238 s->User.IncomingCB = NULL; 240 s->User.IncomingCB = NULL;
239 s->User.IncomingUSSD = NULL; 241 s->User.IncomingUSSD = NULL;
240 s->User.SendSMSStatus = NULL; 242 s->User.SendSMSStatus = NULL;
241 s->LockFile = NULL; 243 s->LockFile = NULL;
242 s->opened = false; 244 s->opened = false;
243 s->Phone.Functions = NULL; 245 s->Phone.Functions = NULL;
244 246
245 s->di = di; 247 s->di = di;
246 s->di.use_global = s->CurrentConfig->UseGlobalDebugFile; 248 s->di.use_global = s->CurrentConfig->UseGlobalDebugFile;
247 GSM_SetDebugLevel(s->CurrentConfig->DebugLevel, &s->di); 249 GSM_SetDebugLevel(s->CurrentConfig->DebugLevel, &s->di);
248 error=GSM_SetDebugFile(s->CurrentConfig->DebugFile, &s->di); 250 error=GSM_SetDebugFile(s->CurrentConfig->DebugFile, &s->di);
249 if (error != ERR_NONE) return error; 251 if (error != ERR_NONE) return error;
250 252
251 if (s->di.dl == DL_TEXTALL || s->di.dl == DL_TEXT || s->di.dl == DL_TEXTERROR || 253 if (s->di.dl == DL_TEXTALL || s->di.dl == DL_TEXT || s->di.dl == DL_TEXTERROR ||
252 s->di.dl == DL_TEXTALLDATE || s->di.dl == DL_TEXTDATE || s->di.dl == DL_TEXTERRORDATE) { 254 s->di.dl == DL_TEXTALLDATE || s->di.dl == DL_TEXTDATE || s->di.dl == DL_TEXTERRORDATE) {
253 smprintf(s,"[Gammu - version %s built %s %s]\n",VERSION,__TIME__,__DATE__); 255 smprintf(s,"[Gammu - %s built %s %s",VERSION,__TIME__,__DATE__);
254 smprintf(s,"[Connection - \"%s\"]\n",s->CurrentConfig->Connection); 256 if (strlen(GetCompiler()) != 0) {
257 smprintf(s," in %s",GetCompiler());
258 }
259 smprintf(s,"]\n[Connection - \"%s\"]\n",s->CurrentConfig->Connection);
255 smprintf(s,"[Model type - \"%s\"]\n",s->CurrentConfig->Model); 260 smprintf(s,"[Model type - \"%s\"]\n",s->CurrentConfig->Model);
256 smprintf(s,"[Device - \"%s\"]\n",s->CurrentConfig->Device); 261 smprintf(s,"[Device - \"%s\"]\n",s->CurrentConfig->Device);
257 262 if (strlen(GetOS()) != 0) {
258 Buffer[0] = 0; 263 smprintf(s,"[Run on - %s]\n",GetOS());
259 if (strlen(GetOS()) != 0) sprintf(Buffer,"%s",GetOS());
260 if (strlen(GetCompiler()) != 0) {
261 if (Buffer[0] != 0) strcat(Buffer+strlen(Buffer),", ");
262 strcat(Buffer+strlen(Buffer),GetCompiler());
263 } 264 }
264 if (Buffer[0] != 0) smprintf(s,"[OS/compiler - %s]\n",Buffer);
265 } 265 }
266 if (s->di.dl==DL_BINARY) { 266 if (s->di.dl==DL_BINARY) {
267 smprintf(s,"%c",((unsigned char)strlen(VERSION))); 267 smprintf(s,"%c",((unsigned char)strlen(VERSION)));
268 smprintf(s,"%s",VERSION); 268 smprintf(s,"%s",VERSION);
269 } 269 }
270 270
271 error=GSM_RegisterAllConnections(s, s->CurrentConfig->Connection); 271 error=GSM_RegisterAllConnections(s, s->CurrentConfig->Connection);
272 if (error!=ERR_NONE) return error; 272 if (error!=ERR_NONE) return error;
273 273
274 /* Model auto */ 274 /* Model auto */
275 if (s->CurrentConfig->Model[0]==0) { 275 if (s->CurrentConfig->Model[0]==0) {
276 if (mystrncasecmp(s->CurrentConfig->LockDevice,"yes",0)) { 276 if (mystrncasecmp(s->CurrentConfig->LockDevice,"yes",0)) {
277 error = lock_device(s->CurrentConfig->Device, &(s->LockFile)); 277 error = lock_device(s->CurrentConfig->Device, &(s->LockFile));
278 if (error != ERR_NONE) return error; 278 if (error != ERR_NONE) return error;
279 } 279 }
280 280
281 /* Irda devices can set now model to some specific and 281 /* Irda devices can set now model to some specific and
282 * we don't have to make auto detection later */ 282 * we don't have to make auto detection later */
283 error=s->Device.Functions->OpenDevice(s); 283 error=s->Device.Functions->OpenDevice(s);
284 if (i != s->ConfigNum - 1) { 284 if (i != s->ConfigNum - 1) {
285 if (error == ERR_DEVICEOPENERROR) continue; 285 if (error == ERR_DEVICEOPENERROR) continue;
286 if (error == ERR_DEVICELOCKED) continue; 286 if (error == ERR_DEVICELOCKED) continue;
287 if (error == ERR_DEVICENOTEXIST) continue; 287 if (error == ERR_DEVICENOTEXIST) continue;
288 if (error == ERR_DEVICEBUSY) continue; 288 if (error == ERR_DEVICEBUSY) continue;
289 if (error == ERR_DEVICENOPERMISSION) continue; 289 if (error == ERR_DEVICENOPERMISSION) continue;
290 if (error == ERR_DEVICENODRIVER) continue; 290 if (error == ERR_DEVICENODRIVER) continue;
291 if (error == ERR_DEVICENOTWORK) continue; 291 if (error == ERR_DEVICENOTWORK) continue;
292 } 292 }
293 if (error!=ERR_NONE) { 293 if (error!=ERR_NONE) {
294 if (s->LockFile!=NULL) unlock_device(&(s->LockFile)); 294 if (s->LockFile!=NULL) unlock_device(&(s->LockFile));
295 return error; 295 return error;
296 } 296 }
297 297
298 s->opened = true; 298 s->opened = true;
299 299
300 error=s->Protocol.Functions->Initialise(s); 300 error=s->Protocol.Functions->Initialise(s);
301 if (error!=ERR_NONE) return error; 301 if (error!=ERR_NONE) return error;
302 302
303 /* If still auto model, try to get model by asking phone for it */ 303 /* If still auto model, try to get model by asking phone for it */
304 if (s->Phone.Data.Model[0]==0) { 304 if (s->Phone.Data.Model[0]==0) {
305 smprintf(s,"[Module - \"auto\"]\n"); 305 smprintf(s,"[Module - \"auto\"]\n");
306 switch (s->ConnectionType) { 306 switch (s->ConnectionType) {
307#ifdef GSM_ENABLE_ATGEN 307#ifdef GSM_ENABLE_ATGEN
308 case GCT_AT: 308 case GCT_AT:
309 case GCT_BLUEAT: 309 case GCT_BLUEAT:
310 case GCT_IRDAAT: 310 case GCT_IRDAAT:
311 s->Phone.Functions = &ATGENPhone; 311 s->Phone.Functions = &ATGENPhone;
312 break; 312 break;
313#endif 313#endif
314#ifdef GSM_ENABLE_OBEXGEN 314#ifdef GSM_ENABLE_OBEXGEN
315 case GCT_IRDAOBEX: 315 case GCT_IRDAOBEX:
316 case GCT_BLUEOBEX: 316 case GCT_BLUEOBEX:
317 s->Phone.Functions = &OBEXGENPhone; 317 s->Phone.Functions = &OBEXGENPhone;
318 break; 318 break;
319#endif 319#endif
320#ifdef GSM_ENABLE_MROUTERGEN 320#ifdef GSM_ENABLE_MROUTERGEN
321 case GCT_MROUTERBLUE: 321 case GCT_MROUTERBLUE:
322 s->Phone.Functions = &MROUTERGENPhone; 322 s->Phone.Functions = &MROUTERGENPhone;
323 break; 323 break;
324#endif 324#endif
325#if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4) 325#if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4)
326 case GCT_MBUS2: 326 case GCT_MBUS2:
327 case GCT_FBUS2: 327 case GCT_FBUS2:
328 case GCT_FBUS2DLR3: 328 case GCT_FBUS2DLR3:
329 case GCT_FBUS2DKU5: 329 case GCT_FBUS2DKU5:
330 case GCT_FBUS2PL2303: 330 case GCT_FBUS2PL2303:
331 case GCT_FBUS2BLUE: 331 case GCT_FBUS2BLUE:
332 case GCT_FBUS2IRDA: 332 case GCT_FBUS2IRDA:
333 case GCT_PHONETBLUE: 333 case GCT_PHONETBLUE:
334 case GCT_IRDAPHONET: 334 case GCT_IRDAPHONET:
335 case GCT_BLUEFBUS2: 335 case GCT_BLUEFBUS2:
336 case GCT_BLUEPHONET: 336 case GCT_BLUEPHONET:
337 s->Phone.Functions = &NAUTOPhone; 337 s->Phone.Functions = &NAUTOPhone;
338 break; 338 break;
339#endif 339#endif
340 default: 340 default:
341 s->Phone.Functions = NULL; 341 s->Phone.Functions = NULL;
342 } 342 }
343 if (s->Phone.Functions == NULL) return ERR_UNKNOWN; 343 if (s->Phone.Functions == NULL) return ERR_UNKNOWN;
344 344
345 /* Please note, that AT module need to send first 345 /* Please note, that AT module need to send first
346 * command for enabling echo 346 * command for enabling echo
347 */ 347 */
348 error=s->Phone.Functions->Initialise(s); 348 error=s->Phone.Functions->Initialise(s);
349 if (error == ERR_TIMEOUT && i != s->ConfigNum - 1) continue; 349 if (error == ERR_TIMEOUT && i != s->ConfigNum - 1) continue;
350 if (error != ERR_NONE) return error; 350 if (error != ERR_NONE) return error;
351 351
352 error=s->Phone.Functions->GetModel(s); 352 error=s->Phone.Functions->GetModel(s);
353 if (error == ERR_TIMEOUT && i != s->ConfigNum - 1) continue; 353 if (error == ERR_TIMEOUT && i != s->ConfigNum - 1) continue;
354 if (error != ERR_NONE) return error; 354 if (error != ERR_NONE) return error;
355 } 355 }
356 } 356 }
357 357
358 /* Switching to "correct" module */ 358 /* Switching to "correct" module */
359 error=GSM_RegisterAllPhoneModules(s); 359 error=GSM_RegisterAllPhoneModules(s);
360 if (error!=ERR_NONE) return error; 360 if (error!=ERR_NONE) return error;
361 361
362 /* We didn't open device earlier ? Make it now */ 362 /* We didn't open device earlier ? Make it now */
363 if (!s->opened) { 363 if (!s->opened) {
364 if (mystrncasecmp(s->CurrentConfig->LockDevice,"yes",0)) { 364 if (mystrncasecmp(s->CurrentConfig->LockDevice,"yes",0)) {
365 error = lock_device(s->CurrentConfig->Device, &(s->LockFile)); 365 error = lock_device(s->CurrentConfig->Device, &(s->LockFile));
366 if (error != ERR_NONE) return error; 366 if (error != ERR_NONE) return error;
367 } 367 }
368 368
369 error=s->Device.Functions->OpenDevice(s); 369 error=s->Device.Functions->OpenDevice(s);
370 if (i != s->ConfigNum - 1) { 370 if (i != s->ConfigNum - 1) {
371 if (error == ERR_DEVICEOPENERROR) continue; 371 if (error == ERR_DEVICEOPENERROR) continue;
372 if (error == ERR_DEVICELOCKED) continue; 372 if (error == ERR_DEVICELOCKED) continue;
373 if (error == ERR_DEVICENOTEXIST) continue; 373 if (error == ERR_DEVICENOTEXIST) continue;
374 if (error == ERR_DEVICEBUSY) continue; 374 if (error == ERR_DEVICEBUSY) continue;
375 if (error == ERR_DEVICENOPERMISSION) continue; 375 if (error == ERR_DEVICENOPERMISSION) continue;
376 if (error == ERR_DEVICENODRIVER) continue; 376 if (error == ERR_DEVICENODRIVER) continue;
377 if (error == ERR_DEVICENOTWORK) continue; 377 if (error == ERR_DEVICENOTWORK) continue;
378 } 378 }
379 if (error!=ERR_NONE) { 379 if (error!=ERR_NONE) {
380 if (s->LockFile!=NULL) unlock_device(&(s->LockFile)); 380 if (s->LockFile!=NULL) unlock_device(&(s->LockFile));
381 return error; 381 return error;
382 } 382 }
383 383
384 s->opened = true; 384 s->opened = true;
385 385
386 error=s->Protocol.Functions->Initialise(s); 386 error=s->Protocol.Functions->Initialise(s);
387 if (error!=ERR_NONE) return error; 387 if (error!=ERR_NONE) return error;
388 } 388 }
389 389
390 error=s->Phone.Functions->Initialise(s); 390 error=s->Phone.Functions->Initialise(s);
391 if (error == ERR_TIMEOUT && i != s->ConfigNum - 1) continue; 391 if (error == ERR_TIMEOUT && i != s->ConfigNum - 1) continue;
392 if (error != ERR_NONE) return error; 392 if (error != ERR_NONE) return error;
393 393
394 if (mystrncasecmp(s->CurrentConfig->StartInfo,"yes",0)) { 394 if (mystrncasecmp(s->CurrentConfig->StartInfo,"yes",0)) {
395 s->Phone.Functions->ShowStartInfo(s,true); 395 s->Phone.Functions->ShowStartInfo(s,true);
396 s->Phone.Data.StartInfoCounter = 30; 396 s->Phone.Data.StartInfoCounter = 30;
397 } 397 }
398 398
399 if (mystrncasecmp(s->CurrentConfig->SyncTime,"yes",0)) { 399 if (mystrncasecmp(s->CurrentConfig->SyncTime,"yes",0)) {
400 GSM_GetCurrentDateTime (&time); 400 GSM_GetCurrentDateTime (&time);
401 s->Phone.Functions->SetDateTime(s,&time); 401 s->Phone.Functions->SetDateTime(s,&time);
402 } 402 }
403 403
404 /* For debug it's good to have firmware and real model version and manufacturer */ 404 /* For debug it's good to have firmware and real model version and manufacturer */
405 error=s->Phone.Functions->GetManufacturer(s); 405 error=s->Phone.Functions->GetManufacturer(s);
406 if (error == ERR_TIMEOUT && i != s->ConfigNum - 1) continue; 406 if (error == ERR_TIMEOUT && i != s->ConfigNum - 1) continue;
407 if (error != ERR_NONE) return error; 407 if (error != ERR_NONE) return error;
408 error=s->Phone.Functions->GetModel(s); 408 error=s->Phone.Functions->GetModel(s);
409 if (error != ERR_NONE) return error; 409 if (error != ERR_NONE) return error;
410 error=s->Phone.Functions->GetFirmware(s); 410 error=s->Phone.Functions->GetFirmware(s);
411 if (error != ERR_NONE) return error; 411 if (error != ERR_NONE) return error;
412 return ERR_NONE; 412 return ERR_NONE;
413 } 413 }
414 return ERR_UNKNOWN; 414 return ERR_UNKNOWN;
415} 415}
416 416
417int GSM_ReadDevice (GSM_StateMachine *s, bool wait) 417int GSM_ReadDevice (GSM_StateMachine *s, bool wait)
418{ 418{
419 unsigned charbuff[255]; 419 unsigned charbuff[255];
420 int res = 0, count; 420 int res = 0, count;
421 421
422 unsigned inti; 422 unsigned inti;
423 GSM_DateTimeDate; 423 GSM_DateTimeDate;
424 424
425 GSM_GetCurrentDateTime (&Date); 425 GSM_GetCurrentDateTime (&Date);
426 i=Date.Second; 426 i=Date.Second;
427 while (i==Date.Second) { 427 while (i==Date.Second) {
428 res = s->Device.Functions->ReadDevice(s, buff, 255); 428 res = s->Device.Functions->ReadDevice(s, buff, 255);
429 if (!wait) break; 429 if (!wait) break;
430 if (res > 0) break; 430 if (res > 0) break;
431 my_sleep(5); 431 my_sleep(5);
432 GSM_GetCurrentDateTime(&Date); 432 GSM_GetCurrentDateTime(&Date);
433 } 433 }
434 434
435 for (count = 0; count < res; count++) 435 for (count = 0; count < res; count++)
436 s->Protocol.Functions->StateMachine(s,buff[count]); 436 s->Protocol.Functions->StateMachine(s,buff[count]);
437 437
438 return res; 438 return res;
439} 439}
440 440
441GSM_Error GSM_TerminateConnection(GSM_StateMachine *s) 441GSM_Error GSM_TerminateConnection(GSM_StateMachine *s)
442{ 442{
443 GSM_Error error; 443 GSM_Error error;
444 444
445 if (!s->opened) return ERR_UNKNOWN; 445 if (!s->opened) return ERR_UNKNOWN;
446 446
447 smprintf(s,"[Closing]\n"); 447 smprintf(s,"[Closing]\n");
448 448
449 if (mystrncasecmp(s->CurrentConfig->StartInfo,"yes",0)) { 449 if (mystrncasecmp(s->CurrentConfig->StartInfo,"yes",0)) {
450 if (s->Phone.Data.StartInfoCounter > 0) s->Phone.Functions->ShowStartInfo(s,false); 450 if (s->Phone.Data.StartInfoCounter > 0) s->Phone.Functions->ShowStartInfo(s,false);
451 } 451 }
452 452
453 if (s->Phone.Functions != NULL) { 453 if (s->Phone.Functions != NULL) {
454 error=s->Phone.Functions->Terminate(s); 454 error=s->Phone.Functions->Terminate(s);
455 if (error!=ERR_NONE) return error; 455 if (error!=ERR_NONE) return error;
456 } 456 }
457 457
458 error=s->Protocol.Functions->Terminate(s); 458 error=s->Protocol.Functions->Terminate(s);
459 if (error!=ERR_NONE) return error; 459 if (error!=ERR_NONE) return error;
460 460
461 error = s->Device.Functions->CloseDevice(s); 461 error = s->Device.Functions->CloseDevice(s);
462 if (error!=ERR_NONE) return error; 462 if (error!=ERR_NONE) return error;
463 463
464 s->Phone.Data.ModelInfo = NULL; 464 s->Phone.Data.ModelInfo = NULL;
465 s->Phone.Data.Manufacturer[0] = 0; 465 s->Phone.Data.Manufacturer[0] = 0;
466 s->Phone.Data.Model[0] = 0; 466 s->Phone.Data.Model[0] = 0;
467 s->Phone.Data.Version[0] = 0; 467 s->Phone.Data.Version[0] = 0;
468 s->Phone.Data.VerDate[0] = 0; 468 s->Phone.Data.VerDate[0] = 0;
469 s->Phone.Data.VerNum = 0; 469 s->Phone.Data.VerNum = 0;
470 470
471 if (s->LockFile!=NULL) unlock_device(&(s->LockFile)); 471 if (s->LockFile!=NULL) unlock_device(&(s->LockFile));
472 472
473 if (!s->di.use_global && s->di.dl!=0 && fileno(s->di.df) != 1 && fileno(s->di.df) != 2) fclose(s->di.df); 473 if (!s->di.use_global && s->di.dl!=0 && fileno(s->di.df) != 1 && fileno(s->di.df) != 2) fclose(s->di.df);
474 474
475 s->opened = false; 475 s->opened = false;
476 476
477 return ERR_NONE; 477 return ERR_NONE;
478} 478}
479 479
480GSM_Error GSM_WaitForOnce(GSM_StateMachine *s, unsigned char *buffer, 480GSM_Error GSM_WaitForOnce(GSM_StateMachine *s, unsigned char *buffer,
481 int length, unsigned char type, int time) 481 int length, unsigned char type, int time)
482{ 482{
483 GSM_Phone_Data *Phone = &s->Phone.Data; 483 GSM_Phone_Data *Phone = &s->Phone.Data;
484 GSM_Protocol_Message sentmsg; 484 GSM_Protocol_Message sentmsg;
485 int i; 485 int i;
486 486
487 i=0; 487 i=0;
488 do { 488 do {
489 if (length != 0) { 489 if (length != 0) {
490 sentmsg.Length = length; 490 sentmsg.Length = length;
491 sentmsg.Type= type; 491 sentmsg.Type= type;
492 sentmsg.Buffer = (unsigned char *)malloc(length); 492 sentmsg.Buffer = (unsigned char *)malloc(length);
493 memcpy(sentmsg.Buffer,buffer,length); 493 memcpy(sentmsg.Buffer,buffer,length);
494 Phone->SentMsg = &sentmsg; 494 Phone->SentMsg = &sentmsg;
495 } 495 }
496 496
497 /* Some data received. Reset timer */ 497 /* Some data received. Reset timer */
498 if (GSM_ReadDevice(s,true)!=0) i=0; 498 if (GSM_ReadDevice(s,true)!=0) i=0;
499 499
500 if (length != 0) { 500 if (length != 0) {
501 free (sentmsg.Buffer); 501 free (sentmsg.Buffer);
502 Phone->SentMsg = NULL; 502 Phone->SentMsg = NULL;
503 } 503 }
504 504
505 /* Request completed */ 505 /* Request completed */
506 if (Phone->RequestID==ID_None) return Phone->DispatchError; 506 if (Phone->RequestID==ID_None) return Phone->DispatchError;
507 507
508 i++; 508 i++;
509 } while (i<time); 509 } while (i<time);
510 510
511 return ERR_TIMEOUT; 511 return ERR_TIMEOUT;
512} 512}
513 513
514GSM_Error GSM_WaitFor (GSM_StateMachine *s, unsigned char *buffer, 514GSM_Error GSM_WaitFor (GSM_StateMachine *s, unsigned char *buffer,
515 int length, unsigned char type, int time, 515 int length, unsigned char type, int time,
516 GSM_Phone_RequestID request) 516 GSM_Phone_RequestID request)
517{ 517{
518 GSM_Phone_Data *Phone = &s->Phone.Data; 518 GSM_Phone_Data *Phone = &s->Phone.Data;
519 GSM_Error error; 519 GSM_Error error;
520 int reply; 520 int reply;
521 521
522 if (mystrncasecmp(s->CurrentConfig->StartInfo,"yes",0)) { 522 if (mystrncasecmp(s->CurrentConfig->StartInfo,"yes",0)) {
523 if (Phone->StartInfoCounter > 0) { 523 if (Phone->StartInfoCounter > 0) {
524 Phone->StartInfoCounter--; 524 Phone->StartInfoCounter--;
525 if (Phone->StartInfoCounter == 0) s->Phone.Functions->ShowStartInfo(s,false); 525 if (Phone->StartInfoCounter == 0) s->Phone.Functions->ShowStartInfo(s,false);
526 } 526 }
527 } 527 }
528 528
529 Phone->RequestID= request; 529 Phone->RequestID= request;
530 Phone->DispatchError= ERR_TIMEOUT; 530 Phone->DispatchError= ERR_TIMEOUT;
531 531
532 for (reply=0;reply<s->ReplyNum;reply++) { 532 for (reply=0;reply<s->ReplyNum;reply++) {
533 if (reply!=0) { 533 if (reply!=0) {
534 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl == DL_TEXTERROR || 534 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl == DL_TEXTERROR ||
535 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl == DL_TEXTERRORDATE) 535 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl == DL_TEXTERRORDATE)
536 { 536 {
537 smprintf(s, "[Retrying %i type 0x%02X]\n", reply, type); 537 smprintf(s, "[Retrying %i type 0x%02X]\n", reply, type);
538 } 538 }
539 } 539 }
540 error = s->Protocol.Functions->WriteMessage(s, buffer, length, type); 540 error = s->Protocol.Functions->WriteMessage(s, buffer, length, type);
541 if (error!=ERR_NONE) return error; 541 if (error!=ERR_NONE) return error;
542 542
543 error = GSM_WaitForOnce(s, buffer, length, type, time); 543 error = GSM_WaitForOnce(s, buffer, length, type, time);
544 if (error != ERR_TIMEOUT) return error; 544 if (error != ERR_TIMEOUT) return error;
545 } 545 }
546 546
547 return Phone->DispatchError; 547 return Phone->DispatchError;
548} 548}
549 549
550static GSM_Error CheckReplyFunctions(GSM_StateMachine *s, GSM_Reply_Function *Reply, int *reply) 550static GSM_Error CheckReplyFunctions(GSM_StateMachine *s, GSM_Reply_Function *Reply, int *reply)
551{ 551{
552 GSM_Phone_Data *Data = &s->Phone.Data; 552 GSM_Phone_Data *Data = &s->Phone.Data;
553 GSM_Protocol_Message *msg = s->Phone.Data.RequestMsg; 553 GSM_Protocol_Message *msg = s->Phone.Data.RequestMsg;
554 bool execute; 554 bool execute;
555 bool available = false; 555 bool available = false;
556 int i = 0; 556 int i = 0;
557 //int j;
557 558
558 while (Reply[i].requestID!=ID_None) { 559 while (Reply[i].requestID!=ID_None) {
559 execute=false; 560 execute=false;
560 /* Binary frames like in Nokia */ 561 /* Binary frames like in Nokia */
561 if (strlen(Reply[i].msgtype) < 2) { 562 if (strlen(Reply[i].msgtype) < 2) {
562 if (Reply[i].msgtype[0]==msg->Type) { 563 if (Reply[i].msgtype[0]==msg->Type) {
563 if (Reply[i].subtypechar!=0) { 564 if (Reply[i].subtypechar!=0) {
564 if (Reply[i].subtypechar<=msg->Length) { 565 if (Reply[i].subtypechar<=msg->Length) {
565 if (msg->Buffer[Reply[i].subtypechar]==Reply[i].subtype) 566 if (msg->Buffer[Reply[i].subtypechar]==Reply[i].subtype)
566 execute=true; 567 execute=true;
567 } 568 }
568 } else execute=true; 569 } else execute=true;
569 } 570 }
570 } else { 571 } else {
571 if (strncmp(Reply[i].msgtype,msg->Buffer,strlen(Reply[i].msgtype))==0) { 572 // printf("msg length %i %i\n",strlen(Reply[i].msgtype),msg->Length);
572 execute=true; 573 if ((int)strlen(Reply[i].msgtype)<msg->Length) {
574 // printf("Comparing \"%s\" and \"",Reply[i].msgtype);
575 // for (j=0;j<strlen(Reply[i].msgtype);j++) {
576 // if (msg->Buffer[j]!=13 && msg->Buffer[j]!=10) {
577 // printf("%c",msg->Buffer[j]);
578 // }
579 // }
580 // printf("\"\n");
581 if (strncmp(Reply[i].msgtype,msg->Buffer,strlen(Reply[i].msgtype))==0) {
582 execute=true;
583 }
573 } 584 }
574 } 585 }
575 586
576 if (execute) { 587 if (execute) {
577 *reply=i; 588 *reply=i;
578 if (Reply[i].requestID == ID_IncomingFrame || 589 if (Reply[i].requestID == ID_IncomingFrame ||
579 Reply[i].requestID == Data->RequestID || 590 Reply[i].requestID == Data->RequestID ||
580 Data->RequestID== ID_EachFrame) { 591 Data->RequestID== ID_EachFrame) {
581 return ERR_NONE; 592 return ERR_NONE;
582 } 593 }
583 available=true; 594 available=true;
584 } 595 }
585 i++; 596 i++;
586 } 597 }
587 598
588 if (available) { 599 if (available) {
589 return ERR_FRAMENOTREQUESTED; 600 return ERR_FRAMENOTREQUESTED;
590 } else { 601 } else {
591 return ERR_UNKNOWNFRAME; 602 return ERR_UNKNOWNFRAME;
592 } 603 }
593} 604}
594 605
595GSM_Error GSM_DispatchMessage(GSM_StateMachine *s) 606GSM_Error GSM_DispatchMessage(GSM_StateMachine *s)
596{ 607{
597 GSM_Error error= ERR_UNKNOWNFRAME; 608 GSM_Error error= ERR_UNKNOWNFRAME;
598 GSM_Protocol_Message *msg = s->Phone.Data.RequestMsg; 609 GSM_Protocol_Message *msg = s->Phone.Data.RequestMsg;
599 GSM_Phone_Data *Phone= &s->Phone.Data; 610 GSM_Phone_Data *Phone= &s->Phone.Data;
600 bool disp = false; 611 bool disp = false;
601 GSM_Reply_Function*Reply; 612 GSM_Reply_Function*Reply;
602 int reply, i; 613 int reply, i;
603 614
604 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || 615 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL ||
605 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) { 616 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) {
606 smprintf(s, "RECEIVED frame "); 617 smprintf(s, "RECEIVED frame ");
607 smprintf(s, "type 0x%02X/length 0x%02X/%i", msg->Type, msg->Length, msg->Length); 618 smprintf(s, "type 0x%02X/length 0x%02X/%i", msg->Type, msg->Length, msg->Length);
608 DumpMessage(s->di.use_global ? di.df : s->di.df, s->di.dl, msg->Buffer, msg->Length); 619 DumpMessage(s->di.use_global ? di.df : s->di.df, s->di.dl, msg->Buffer, msg->Length);
609 if (msg->Length == 0) smprintf(s, "\n"); 620 if (msg->Length == 0) smprintf(s, "\n");
610 fflush(s->di.df); 621 fflush(s->di.df);
611 } 622 }
612 if (s->di.dl==DL_BINARY) { 623 if (s->di.dl==DL_BINARY) {
613 smprintf(s,"%c",0x02);/* Receiving */ 624 smprintf(s,"%c",0x02);/* Receiving */
614 smprintf(s,"%c",msg->Type); 625 smprintf(s,"%c",msg->Type);
615 smprintf(s,"%c",msg->Length/256); 626 smprintf(s,"%c",msg->Length/256);
616 smprintf(s,"%c",msg->Length%256); 627 smprintf(s,"%c",msg->Length%256);
617 for (i=0;i<msg->Length;i++) { 628 for (i=0;i<msg->Length;i++) {
618 smprintf(s,"%c",msg->Buffer[i]); 629 smprintf(s,"%c",msg->Buffer[i]);
619 } 630 }
620 } 631 }
621 632
622 Reply=s->User.UserReplyFunctions; 633 Reply=s->User.UserReplyFunctions;
623 if (Reply!=NULL) error=CheckReplyFunctions(s,Reply,&reply); 634 if (Reply!=NULL) error=CheckReplyFunctions(s,Reply,&reply);
624 635
625 if (error==ERR_UNKNOWNFRAME) { 636 if (error==ERR_UNKNOWNFRAME) {
626 Reply=s->Phone.Functions->ReplyFunctions; 637 Reply=s->Phone.Functions->ReplyFunctions;
627 error=CheckReplyFunctions(s,Reply,&reply); 638 error=CheckReplyFunctions(s,Reply,&reply);
628 } 639 }
629 640
630 if (error==ERR_NONE) { 641 if (error==ERR_NONE) {
631 error=Reply[reply].Function(*msg, s); 642 error=Reply[reply].Function(*msg, s);
632 if (Reply[reply].requestID==Phone->RequestID) { 643 if (Reply[reply].requestID==Phone->RequestID) {
633 if (error == ERR_NEEDANOTHERANSWER) { 644 if (error == ERR_NEEDANOTHERANSWER) {
634 error = ERR_NONE; 645 error = ERR_NONE;
635 } else { 646 } else {
636 Phone->RequestID=ID_None; 647 Phone->RequestID=ID_None;
637 } 648 }
638 } 649 }
639 } 650 }
640 651
641 if (strcmp(s->Phone.Functions->models,"NAUTO")) { 652 if (strcmp(s->Phone.Functions->models,"NAUTO")) {
642 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || 653 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
643 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { 654 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) {
644 disp = true; 655 disp = true;
645 switch (error) { 656 switch (error) {
646 case ERR_UNKNOWNRESPONSE: 657 case ERR_UNKNOWNRESPONSE:
647 smprintf(s, "\nUNKNOWN response"); 658 smprintf(s, "\nUNKNOWN response");
648 break; 659 break;
649 case ERR_UNKNOWNFRAME: 660 case ERR_UNKNOWNFRAME:
650 smprintf(s, "\nUNKNOWN frame"); 661 smprintf(s, "\nUNKNOWN frame");
651 break; 662 break;
652 case ERR_FRAMENOTREQUESTED: 663 case ERR_FRAMENOTREQUESTED:
653 smprintf(s, "\nFrame not request now"); 664 smprintf(s, "\nFrame not request now");
654 break; 665 break;
655 default: 666 default:
656 disp = false; 667 disp = false;
657 } 668 }
658 } 669 }
659 670
660 if (error == ERR_UNKNOWNFRAME || error == ERR_FRAMENOTREQUESTED) { 671 if (error == ERR_UNKNOWNFRAME || error == ERR_FRAMENOTREQUESTED) {
661 error = ERR_TIMEOUT; 672 error = ERR_TIMEOUT;
662 } 673 }
663 } 674 }
664 675
665 if (disp) { 676 if (disp) {
666 smprintf(s,". If you can, PLEASE report it (see readme.txt). THANK YOU\n"); 677 smprintf(s,". If you can, PLEASE report it (see readme.txt). THANK YOU\n");
667 if (Phone->SentMsg != NULL) { 678 if (Phone->SentMsg != NULL) {
668 smprintf(s,"LAST SENT frame "); 679 smprintf(s,"LAST SENT frame ");
669 smprintf(s, "type 0x%02X/length %i", Phone->SentMsg->Type, Phone->SentMsg->Length); 680 smprintf(s, "type 0x%02X/length %i", Phone->SentMsg->Type, Phone->SentMsg->Length);
670 DumpMessage(s->di.use_global ? di.df : s->di.df, s->di.dl, Phone->SentMsg->Buffer, Phone->SentMsg->Length); 681 DumpMessage(s->di.use_global ? di.df : s->di.df, s->di.dl, Phone->SentMsg->Buffer, Phone->SentMsg->Length);
671 } 682 }
672 smprintf(s, "RECEIVED frame "); 683 smprintf(s, "RECEIVED frame ");
673 smprintf(s, "type 0x%02X/length 0x%02X/%i", msg->Type, msg->Length, msg->Length); 684 smprintf(s, "type 0x%02X/length 0x%02X/%i", msg->Type, msg->Length, msg->Length);
674 DumpMessage(s->di.use_global ? di.df : s->di.df, s->di.dl, msg->Buffer, msg->Length); 685 DumpMessage(s->di.use_global ? di.df : s->di.df, s->di.dl, msg->Buffer, msg->Length);
675 smprintf(s, "\n"); 686 smprintf(s, "\n");
676 } 687 }
677 688
678 return error; 689 return error;
679} 690}
680 691
681INI_Section *GSM_FindGammuRC(void) 692INI_Section *GSM_FindGammuRC(void)
682{ 693{
683 INI_Section*ini_file; 694 INI_Section*ini_file;
684 char *HomeDrive,*HomePath,*FileName=malloc(1); 695 char *HomeDrive,*HomePath,*FileName=malloc(1);
685 int FileNameUsed=1; 696 int FileNameUsed=1;
686 697
687 FileName[0] = 0; 698 FileName[0] = 0;
688#if defined(WIN32) || defined(DJGPP) 699#if defined(WIN32) || defined(DJGPP)
689 HomeDrive = getenv("HOMEDRIVE"); 700 HomeDrive = getenv("HOMEDRIVE");
690 if (HomeDrive) { 701 if (HomeDrive) {
691 FileName = realloc(FileName,FileNameUsed+strlen(HomeDrive)+1); 702 FileName = realloc(FileName,FileNameUsed+strlen(HomeDrive)+1);
692 FileName = strcat(FileName, HomeDrive); 703 FileName = strcat(FileName, HomeDrive);
693 FileNameUsed+= strlen(HomeDrive)+1; 704 FileNameUsed+= strlen(HomeDrive)+1;
694 } 705 }
695 HomePath = getenv("HOMEPATH"); 706 HomePath = getenv("HOMEPATH");
696 if (HomePath) { 707 if (HomePath) {
697 FileName = realloc(FileName,FileNameUsed+strlen(HomePath)+1); 708 FileName = realloc(FileName,FileNameUsed+strlen(HomePath)+1);
698 FileName = strcat(FileName, HomePath); 709 FileName = strcat(FileName, HomePath);
699 FileNameUsed+= strlen(HomePath)+1; 710 FileNameUsed+= strlen(HomePath)+1;
700 } 711 }
701 FileName = realloc(FileName,FileNameUsed+8+1); 712 FileName = realloc(FileName,FileNameUsed+8+1);
702 strcat(FileName, "\\gammurc"); 713 strcat(FileName, "\\gammurc");
703#else 714#else
704 HomeDrive = NULL; 715 HomeDrive = NULL;
705 HomePath = getenv("HOME"); 716 HomePath = getenv("HOME");
706 if (HomePath) { 717 if (HomePath) {
707 FileName = realloc(FileName,FileNameUsed+strlen(HomePath)+1); 718 FileName = realloc(FileName,FileNameUsed+strlen(HomePath)+1);
708 FileName = strcat(FileName, HomePath); 719 FileName = strcat(FileName, HomePath);
709 FileNameUsed+= strlen(HomePath)+1; 720 FileNameUsed+= strlen(HomePath)+1;
710 } 721 }
711 FileName = realloc(FileName,FileNameUsed+9+1); 722 FileName = realloc(FileName,FileNameUsed+9+1);
712 strcat(FileName, "/.gammurc"); 723 strcat(FileName, "/.gammurc");
713#endif 724#endif
714 //dbgprintf("\"%s\"\n",FileName); 725 //dbgprintf("\"%s\"\n",FileName);
715 726
716 ini_file = INI_ReadFile(FileName, false); 727 ini_file = INI_ReadFile(FileName, false);
717 free(FileName); 728 free(FileName);
718 if (ini_file == NULL) { 729 if (ini_file == NULL) {
719#if defined(WIN32) || defined(DJGPP) 730#if defined(WIN32) || defined(DJGPP)
720 ini_file = INI_ReadFile("gammurc", false); 731 ini_file = INI_ReadFile("gammurc", false);
721 if (ini_file == NULL) return NULL; 732 if (ini_file == NULL) return NULL;
722#else 733#else
723 ini_file = INI_ReadFile("/etc/gammurc", false); 734 ini_file = INI_ReadFile("/etc/gammurc", false);
724 if (ini_file == NULL) return NULL; 735 if (ini_file == NULL) return NULL;
725#endif 736#endif
726 } 737 }
727 738
728 return ini_file; 739 return ini_file;
729} 740}
730 741
731bool GSM_ReadConfig(INI_Section *cfg_info, GSM_Config *cfg, int num) 742bool GSM_ReadConfig(INI_Section *cfg_info, GSM_Config *cfg, int num)
732{ 743{
733 INI_Section *h; 744 INI_Section *h;
734 unsigned char section[50]; 745 unsigned char section[50];
735 bool found = false; 746 bool found = false;
736 747
737#if defined(WIN32) || defined(DJGPP) 748#if defined(WIN32) || defined(DJGPP)
738 char *DefaultPort = "com2:"; 749 char *DefaultPort = "com2:";
739#else 750#else
740 char *DefaultPort = "/dev/ttyS1"; 751 char *DefaultPort = "/dev/ttyS1";
741#endif 752#endif
742 char *DefaultModel = ""; 753 char *DefaultModel = "";
743 char *DefaultConnection = "fbus"; 754 char *DefaultConnection = "fbus";
744 char *DefaultSynchronizeTime= "no"; 755 char *DefaultSynchronizeTime= "no";
745 char *DefaultDebugFile = ""; 756 char *DefaultDebugFile = "";
746 char *DefaultDebugLevel = ""; 757 char *DefaultDebugLevel = "";
747 char *DefaultLockDevice = "no"; 758 char *DefaultLockDevice = "no";
748 char *DefaultStartInfo = "no"; 759 char *DefaultStartInfo = "no";
749 char *Temp; 760 char *Temp;
750 761
751 /* By default all debug output will go to one filedescriptor */ 762 /* By default all debug output will go to one filedescriptor */
752 bool DefaultUseGlobalDebugFile = true; 763 bool DefaultUseGlobalDebugFile = true;
753 764
754 cfg->Device = DefaultPort; 765 cfg->Device = DefaultPort;
755 cfg->Connection = DefaultConnection; 766 cfg->Connection = DefaultConnection;
756 cfg->SyncTime = DefaultSynchronizeTime; 767 cfg->SyncTime = DefaultSynchronizeTime;
757 cfg->DebugFile = DefaultDebugFile; 768 cfg->DebugFile = DefaultDebugFile;
758 strcpy(cfg->Model,DefaultModel); 769 strcpy(cfg->Model,DefaultModel);
759 strcpy(cfg->DebugLevel,DefaultDebugLevel); 770 strcpy(cfg->DebugLevel,DefaultDebugLevel);
760 cfg->LockDevice = DefaultLockDevice; 771 cfg->LockDevice = DefaultLockDevice;
761 cfg->StartInfo = DefaultStartInfo; 772 cfg->StartInfo = DefaultStartInfo;
762 cfg->DefaultDevice = true; 773 cfg->DefaultDevice = true;
763 cfg->DefaultModel = true; 774 cfg->DefaultModel = true;
764 cfg->DefaultConnection = true; 775 cfg->DefaultConnection = true;
765 cfg->DefaultSyncTime = true; 776 cfg->DefaultSyncTime = true;
766 cfg->DefaultDebugFile = true; 777 cfg->DefaultDebugFile = true;
767 cfg->DefaultDebugLevel = true; 778 cfg->DefaultDebugLevel = true;
768 cfg->DefaultLockDevice = true; 779 cfg->DefaultLockDevice = true;
769 cfg->DefaultStartInfo = true; 780 cfg->DefaultStartInfo = true;
770 781
771 cfg->UseGlobalDebugFile = DefaultUseGlobalDebugFile; 782 cfg->UseGlobalDebugFile = DefaultUseGlobalDebugFile;
772 783
773 if (cfg_info==NULL) return false; 784 if (cfg_info==NULL) return false;
774 785
775 if (num == 0) { 786 if (num == 0) {
776 sprintf(section,"gammu"); 787 sprintf(section,"gammu");
777 } else { 788 } else {
778 sprintf(section,"gammu%i",num); 789 sprintf(section,"gammu%i",num);
779 } 790 }
780 for (h = cfg_info; h != NULL; h = h->Next) { 791 for (h = cfg_info; h != NULL; h = h->Next) {
781 if (mystrncasecmp(section, h->SectionName, strlen(section))) { 792 if (mystrncasecmp(section, h->SectionName, strlen(section))) {
782 found = true; 793 found = true;
783 break; 794 break;
784 } 795 }
785 } 796 }
786 if (!found) return false; 797 if (!found) return false;
787 798
788 cfg->Device = INI_GetValue(cfg_info, section, "port", false); 799 cfg->Device = INI_GetValue(cfg_info, section, "port", false);
789 if (!cfg->Device) { 800 if (!cfg->Device) {
790 free(cfg->Device); 801 free(cfg->Device);
791 cfg->Device = strdup(DefaultPort); 802 cfg->Device = strdup(DefaultPort);
792 } else { 803 } else {
793 cfg->DefaultDevice = false; 804 cfg->DefaultDevice = false;
794 } 805 }
795 cfg->Connection = INI_GetValue(cfg_info, section, "connection", false); 806 cfg->Connection = INI_GetValue(cfg_info, section, "connection", false);
796 if (!cfg->Connection) { 807 if (!cfg->Connection) {
797 free(cfg->Connection); 808 free(cfg->Connection);
798 cfg->Connection = strdup(DefaultConnection); 809 cfg->Connection = strdup(DefaultConnection);
799 } else { 810 } else {
800 cfg->DefaultConnection = false; 811 cfg->DefaultConnection = false;
801 } 812 }
802 cfg->SyncTime = INI_GetValue(cfg_info, section, "synchronizetime",false); 813 cfg->SyncTime = INI_GetValue(cfg_info, section, "synchronizetime",false);
803 if (!cfg->SyncTime) { 814 if (!cfg->SyncTime) {
804 free(cfg->SyncTime); 815 free(cfg->SyncTime);
805 cfg->SyncTime = strdup(DefaultSynchronizeTime); 816 cfg->SyncTime = strdup(DefaultSynchronizeTime);
806 } else { 817 } else {
807 cfg->DefaultSyncTime = false; 818 cfg->DefaultSyncTime = false;
808 } 819 }
809 cfg->DebugFile = INI_GetValue(cfg_info, section, "logfile", false); 820 cfg->DebugFile = INI_GetValue(cfg_info, section, "logfile", false);
810 if (!cfg->DebugFile) { 821 if (!cfg->DebugFile) {
811 free(cfg->DebugFile); 822 free(cfg->DebugFile);
812 cfg->DebugFile = strdup(DefaultDebugFile); 823 cfg->DebugFile = strdup(DefaultDebugFile);
813 } else { 824 } else {
814 cfg->DefaultDebugFile = false; 825 cfg->DefaultDebugFile = false;
815 } 826 }
816 cfg->LockDevice = INI_GetValue(cfg_info, section, "use_locking", false); 827 cfg->LockDevice = INI_GetValue(cfg_info, section, "use_locking", false);
817 if (!cfg->LockDevice) { 828 if (!cfg->LockDevice) {
818 free(cfg->LockDevice); 829 free(cfg->LockDevice);
819 cfg->LockDevice = strdup(DefaultLockDevice); 830 cfg->LockDevice = strdup(DefaultLockDevice);
820 } else { 831 } else {
821 cfg->DefaultLockDevice = false; 832 cfg->DefaultLockDevice = false;
822 } 833 }
823 Temp = INI_GetValue(cfg_info, section, "model", false); 834 Temp = INI_GetValue(cfg_info, section, "model", false);
824 if (!Temp) { 835 if (!Temp) {
825 strcpy(cfg->Model,DefaultModel); 836 strcpy(cfg->Model,DefaultModel);
826 } else { 837 } else {
827 cfg->DefaultModel = false; 838 cfg->DefaultModel = false;
828 strcpy(cfg->Model,Temp); 839 strcpy(cfg->Model,Temp);
829 } 840 }
830 Temp = INI_GetValue(cfg_info, section, "logformat", false); 841 Temp = INI_GetValue(cfg_info, section, "logformat", false);
831 if (!Temp) { 842 if (!Temp) {
832 strcpy(cfg->DebugLevel,DefaultDebugLevel); 843 strcpy(cfg->DebugLevel,DefaultDebugLevel);
833 } else { 844 } else {
834 cfg->DefaultDebugLevel = false; 845 cfg->DefaultDebugLevel = false;
835 strcpy(cfg->DebugLevel,Temp); 846 strcpy(cfg->DebugLevel,Temp);
836 } 847 }
837 cfg->StartInfo = INI_GetValue(cfg_info, section, "startinfo", false); 848 cfg->StartInfo = INI_GetValue(cfg_info, section, "startinfo", false);
838 if (!cfg->StartInfo) { 849 if (!cfg->StartInfo) {
839 free(cfg->StartInfo); 850 free(cfg->StartInfo);
840 cfg->StartInfo = strdup(DefaultStartInfo); 851 cfg->StartInfo = strdup(DefaultStartInfo);
841 } else { 852 } else {
842 cfg->DefaultStartInfo = false; 853 cfg->DefaultStartInfo = false;
843 } 854 }
844 return true; 855 return true;
845} 856}
846 857
847static OnePhoneModel allmodels[] = { 858static OnePhoneModel allmodels[] = {
859#ifdef GSM_ENABLE_NOKIA650
860 {"0650" ,"THF-12","", {0}},
861#endif
848#ifdef GSM_ENABLE_NOKIA6510 862#ifdef GSM_ENABLE_NOKIA6510
849 {"1100", "RH-18" ,"", {0}}, 863 {"1100" ,"RH-18" ,"", {0}},
850 {"1100a","RH-38" ,"", {0}}, 864 {"1100a","RH-38" ,"", {0}},
851 {"1100b","RH-36" ,"", {0}}, 865 {"1100b","RH-36" ,"", {0}},
852#endif 866#endif
853#ifdef GSM_ENABLE_NOKIA6110 867#ifdef GSM_ENABLE_NOKIA6110
854 {"2100" ,"NAM-2" ,"", {F_NOWAP,F_NOCALLER,F_RING_SM,F_CAL33,F_POWER_BATT,F_PROFILES33,F_NOCALLINFO,F_NODTMF,0}},//quess 868 {"2100" ,"NAM-2" ,"", {F_NOWAP,F_NOCALLER,F_RING_SM,F_CAL33,F_POWER_BATT,F_PROFILES33,F_NOCALLINFO,F_NODTMF,0}},//quess
855#endif 869#endif
856#ifdef GSM_ENABLE_NOKIA6510 870#ifdef GSM_ENABLE_NOKIA6510
857 {"3100" ,"RH-19" ,"", {F_PBKTONEGAL,F_PBKSMSLIST,0}}, 871 {"3100" ,"RH-19" ,"", {F_PBKTONEGAL,F_PBKSMSLIST,0}},//fixme
858 {"3100b","RH-50" ,"", {F_PBKTONEGAL,F_PBKSMSLIST,0}}, 872 {"3100b","RH-50" ,"", {F_PBKTONEGAL,F_PBKSMSLIST,0}},//fixme
859 {"3108", "RH-6", "Nokia 3108",{0}}, //does it have irda ? 873 {"3108", "RH-6", "Nokia 3108",{0}}, //does it have irda ?
860 {"3200", "RH-30" ,"Nokia 3200",{F_PBKTONEGAL,0}}, 874 {"3200", "RH-30" ,"Nokia 3200",{F_PBKTONEGAL,0}},//fixme
861 {"3200a","RH-31" ,"Nokia 3200",{F_PBKTONEGAL,0}}, 875 {"3200a","RH-31" ,"Nokia 3200",{F_PBKTONEGAL,0}},//fixme
862#endif 876#endif
863#ifdef GSM_ENABLE_NOKIA6110 877#ifdef GSM_ENABLE_NOKIA6110
864 {"3210" ,"NSE-8" ,"", {F_NOWAP,F_NOCALLER,F_NOCALENDAR,F_NOPBKUNICODE,F_POWER_BATT,F_PROFILES51,F_NOPICTUREUNI,F_NOCALLINFO,F_NODTMF,0}}, 878 {"3210" ,"NSE-8" ,"", {F_NOWAP,F_NOCALLER,F_NOCALENDAR,F_NOPBKUNICODE,F_POWER_BATT,F_PROFILES51,F_NOPICTUREUNI,F_NOCALLINFO,F_NODTMF,0}},
865 {"3210" ,"NSE-9" ,"", {F_NOWAP,F_NOCALLER,F_NOCALENDAR,F_NOPBKUNICODE,F_POWER_BATT,F_PROFILES51,F_NOPICTUREUNI,F_NOCALLINFO,F_NODTMF,0}}, 879 {"3210" ,"NSE-9" ,"", {F_NOWAP,F_NOCALLER,F_NOCALENDAR,F_NOPBKUNICODE,F_POWER_BATT,F_PROFILES51,F_NOPICTUREUNI,F_NOCALLINFO,F_NODTMF,0}},
866#endif 880#endif
867#ifdef GSM_ENABLE_NOKIA6510 881#ifdef GSM_ENABLE_NOKIA6510
868 {"3300" ,"NEM-1" ,"Nokia 3300", {F_PBKTONEGAL,0}}, 882 {"3300" ,"NEM-1" ,"Nokia 3300", {F_PBKTONEGAL,0}},//fixme
869 {"3300" ,"NEM-2" ,"Nokia 3300", {F_PBKTONEGAL,0}}, 883 {"3300" ,"NEM-2" ,"Nokia 3300", {F_PBKTONEGAL,0}},//fixme
870#endif 884#endif
871#ifdef GSM_ENABLE_NOKIA6110 885#ifdef GSM_ENABLE_NOKIA6110
872 {"3310" ,"NHM-5" ,"", {F_NOWAP,F_NOCALLER,F_RING_SM,F_CAL33,F_POWER_BATT,F_PROFILES33,F_NOCALLINFO,F_NODTMF,0}}, 886 {"3310" ,"NHM-5" ,"", {F_NOWAP,F_NOCALLER,F_RING_SM,F_CAL33,F_POWER_BATT,F_PROFILES33,F_NOCALLINFO,F_NODTMF,0}},
873#endif 887#endif
874#ifdef GSM_ENABLE_NOKIA3320 888#ifdef GSM_ENABLE_NOKIA3320
875 {"3320" ,"NPC-1" ,"Nokia 3320", {F_CAL62,F_DAYMONTH,0}},//fixme 889 {"3320" ,"NPC-1" ,"Nokia 3320", {F_CAL62,F_DAYMONTH,0}},//fixme
876#endif 890#endif
877#ifdef GSM_ENABLE_NOKIA6110 891#ifdef GSM_ENABLE_NOKIA6110
878 {"3330" ,"NHM-6" ,"", {F_NOCALLER,F_RING_SM,F_CAL33,F_PROFILES33,F_NOPICTUREUNI,F_NOCALLINFO,F_NODTMF,0}}, 892 {"3330" ,"NHM-6" ,"", {F_NOCALLER,F_RING_SM,F_CAL33,F_PROFILES33,F_NOPICTUREUNI,F_NOCALLINFO,F_NODTMF,0}},
879 {"3390" ,"NPB-1" ,"", {F_NOWAP,F_NOCALLER,F_RING_SM,F_CAL33,F_PROFILES33,F_NOPICTUREUNI,F_NOCALLINFO,F_NODTMF,0}}, 893 {"3390" ,"NPB-1" ,"", {F_NOWAP,F_NOCALLER,F_RING_SM,F_CAL33,F_PROFILES33,F_NOPICTUREUNI,F_NOCALLINFO,F_NODTMF,0}},
880 {"3410" ,"NHM-2" ,"", {F_RING_SM,F_CAL33,F_PROFILES33,F_NOCALLINFO,F_NODTMF,0}}, 894 {"3410" ,"NHM-2" ,"", {F_RING_SM,F_CAL33,F_PROFILES33,F_NOCALLINFO,F_NODTMF,0}},
881#endif 895#endif
882#ifdef GSM_ENABLE_NOKIA6510 896#ifdef GSM_ENABLE_NOKIA6510
883 {"3510" ,"NHM-8" ,"", {F_CAL35,F_PBK35,F_NOGPRSPOINT,F_VOICETAGS,0}}, 897 {"3510" ,"NHM-8" ,"", {F_CAL35,F_PBK35,F_NOGPRSPOINT,F_VOICETAGS,0}},
884 {"3510i","RH-9" ,"", {F_CAL35,F_PBK35,F_NOGPRSPOINT,F_VOICETAGS,0}}, 898 {"3510i","RH-9" ,"", {F_CAL35,F_PBK35,F_NOGPRSPOINT,F_VOICETAGS,0}},
885 {"3530" ,"RH-9" ,"", {F_CAL35,F_PBK35,F_NOGPRSPOINT,F_VOICETAGS,0}}, 899 {"3530" ,"RH-9" ,"", {F_CAL35,F_PBK35,F_NOGPRSPOINT,F_VOICETAGS,0}},
886 {"3589i","RH-44" ,"", {F_VOICETAGS,0}}, 900 {"3589i","RH-44" ,"", {F_VOICETAGS,0}},
887 {"3590" ,"NPM-8" ,"", {0}},//irda? 901 {"3590" ,"NPM-8" ,"", {0}},//irda?
888 {"3595" ,"NPM-10" ,"", {0}},//irda? 902 {"3595" ,"NPM-10" ,"", {0}},//irda?
889#endif 903#endif
890#ifdef GSM_ENABLE_NOKIA6110 904#ifdef GSM_ENABLE_NOKIA6110
891 {"3610" ,"NAM-1" ,"", {F_NOCALLER,F_RING_SM,F_CAL33,F_POWER_BATT,F_PROFILES33,F_NOCALLINFO,F_NODTMF,0}},//quess 905 {"3610" ,"NAM-1" ,"", {F_NOCALLER,F_RING_SM,F_CAL33,F_POWER_BATT,F_PROFILES33,F_NOCALLINFO,F_NODTMF,0}},//quess
892#endif 906#endif
893#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA3650) 907#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA3650)
894 {"3650" ,"NHL-8" ,"Nokia 3650", {0}}, 908 {"3650" ,"NHL-8" ,"Nokia 3650", {0}},
895 {"NGAGE","NEM-4" ,"", {F_RADIO,0}}, 909 {"NGAGE","NEM-4" ,"", {F_RADIO,0}},
896#endif 910#endif
897#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510) 911#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
898 {"5100" ,"NPM-6" ,"Nokia 5100", {F_PBKTONEGAL,F_TODO66,F_RADIO,0}}, 912 {"5100" ,"NPM-6" ,"Nokia 5100", {F_PBKTONEGAL,F_TODO66,F_RADIO,0}},
899 {"5100" ,"NPM-6U","Nokia 5100", {F_PBKTONEGAL,F_TODO66,F_RADIO,0}}, 913 {"5100" ,"NPM-6U","Nokia 5100", {F_PBKTONEGAL,F_TODO66,F_RADIO,0}},
900 {"5100" ,"NPM-6X","Nokia 5100", {F_PBKTONEGAL,F_TODO66,F_RADIO,0}}, 914 {"5100" ,"NPM-6X","Nokia 5100", {F_PBKTONEGAL,F_TODO66,F_RADIO,0}},
915 {"5140" ,"NPL-4" ,"Nokia 5140", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKUSER,F_WAPMMSPROXY,0}},
916 {"5140" ,"NPL-5" ,"Nokia 5140", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKUSER,F_WAPMMSPROXY,0}},
901#endif 917#endif
902#ifdef GSM_ENABLE_NOKIA6110 918#ifdef GSM_ENABLE_NOKIA6110
903 {"5110" ,"NSE-1" ,"", {F_NOWAP,F_NOCALLER,F_NORING,F_NOPICTURE,F_NOSTARTUP,F_NOCALENDAR,F_NOPBKUNICODE,F_PROFILES51,F_MAGICBYTES,F_DISPSTATUS,0}}, 919 {"5110" ,"NSE-1" ,"", {F_NOWAP,F_NOCALLER,F_NORING,F_NOPICTURE,F_NOSTARTUP,F_NOCALENDAR,F_NOPBKUNICODE,F_PROFILES51,F_MAGICBYTES,F_DISPSTATUS,0}},
904 {"5110i","NSE-2" ,"", {F_NOWAP,F_NOCALLER,F_NORING,F_NOPICTURE,F_NOSTARTUP,F_NOCALENDAR,F_NOPBKUNICODE,F_PROFILES51,F_MAGICBYTES,F_DISPSTATUS,0}}, 920 {"5110i","NSE-2" ,"", {F_NOWAP,F_NOCALLER,F_NORING,F_NOPICTURE,F_NOSTARTUP,F_NOCALENDAR,F_NOPBKUNICODE,F_PROFILES51,F_MAGICBYTES,F_DISPSTATUS,0}},
905 {"5130" ,"NSK-1" ,"", {F_NOWAP,F_NOCALLER,F_NORING,F_NOPICTURE,F_NOSTARTUP,F_NOCALENDAR,F_NOPBKUNICODE,F_PROFILES51,F_MAGICBYTES,F_DISPSTATUS,0}}, 921 {"5130" ,"NSK-1" ,"", {F_NOWAP,F_NOCALLER,F_NORING,F_NOPICTURE,F_NOSTARTUP,F_NOCALENDAR,F_NOPBKUNICODE,F_PROFILES51,F_MAGICBYTES,F_DISPSTATUS,0}},
906 {"5190" ,"NSB-1" ,"", {F_NOWAP,F_NOCALLER,F_NORING,F_NOPICTURE,F_NOSTARTUP,F_NOCALENDAR,F_NOPBKUNICODE,F_PROFILES51,F_MAGICBYTES,F_DISPSTATUS,0}}, 922 {"5190" ,"NSB-1" ,"", {F_NOWAP,F_NOCALLER,F_NORING,F_NOPICTURE,F_NOSTARTUP,F_NOCALENDAR,F_NOPBKUNICODE,F_PROFILES51,F_MAGICBYTES,F_DISPSTATUS,0}},
907#endif 923#endif
908#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6110) 924#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6110)
909 {"5210" ,"NSM-5" ,"Nokia 5210", {F_CAL52,F_NOSTARTANI,F_NOPICTUREUNI,F_NODTMF,0}}, 925 {"5210" ,"NSM-5" ,"Nokia 5210", {F_CAL52,F_NOSTARTANI,F_NOPICTUREUNI,F_NODTMF,0}},
910#endif 926#endif
911#ifdef GSM_ENABLE_NOKIA6110 927#ifdef GSM_ENABLE_NOKIA6110
912 {"5510" ,"NPM-5" ,"", {F_NOCALLER,F_PROFILES33,F_NOPICTUREUNI,0}}, 928 {"5510" ,"NPM-5" ,"", {F_NOCALLER,F_PROFILES33,F_NOPICTUREUNI,0}},
913#endif 929#endif
914#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510) 930#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
915 {"6100" ,"NPL-2" ,"Nokia 6100", {F_PBKTONEGAL,F_TODO66,0}}, 931 {"6100" ,"NPL-2" ,"Nokia 6100", {F_PBKTONEGAL,F_TODO66,0}},
916#endif 932#endif
917#ifdef GSM_ENABLE_NOKIA6110 933#ifdef GSM_ENABLE_NOKIA6110
918 {"6110" ,"NSE-3" ,"", {F_NOWAP,F_NOPICTURE,F_NOSTARTANI,F_NOPBKUNICODE,F_MAGICBYTES,F_DISPSTATUS,0}}, 934 {"6110" ,"NSE-3" ,"", {F_NOWAP,F_NOPICTURE,F_NOSTARTANI,F_NOPBKUNICODE,F_MAGICBYTES,F_DISPSTATUS,0}},
919 {"6130" ,"NSK-3" ,"", {F_NOWAP,F_NOPICTURE,F_NOSTARTANI,F_NOPBKUNICODE,F_MAGICBYTES,F_DISPSTATUS,0}}, 935 {"6130" ,"NSK-3" ,"", {F_NOWAP,F_NOPICTURE,F_NOSTARTANI,F_NOPBKUNICODE,F_MAGICBYTES,F_DISPSTATUS,0}},
920 {"6150" ,"NSM-1" ,"", {F_NOWAP,F_NOSTARTANI,F_NOPBKUNICODE,F_MAGICBYTES,F_DISPSTATUS,F_NOPICTUREUNI,0}}, 936 {"6150" ,"NSM-1" ,"", {F_NOWAP,F_NOSTARTANI,F_NOPBKUNICODE,F_MAGICBYTES,F_DISPSTATUS,F_NOPICTUREUNI,0}},
921 {"6190" ,"NSB-3" ,"", {F_NOWAP,F_NOPICTURE,F_NOSTARTANI,F_NOPBKUNICODE,F_MAGICBYTES,F_DISPSTATUS,0}}, 937 {"6190" ,"NSB-3" ,"", {F_NOWAP,F_NOPICTURE,F_NOSTARTANI,F_NOPBKUNICODE,F_MAGICBYTES,F_DISPSTATUS,0}},
922#endif 938#endif
923#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510) 939#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
924 {"6200" ,"NPL-3" ,"Nokia 6200", {F_PBKTONEGAL,0}}, 940 {"6200" ,"NPL-3" ,"Nokia 6200", {F_PBKTONEGAL,0}},
925 {"6220" ,"RH-20" ,"Nokia 6220", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKSMSLIST,F_PBKUSER,F_WAPMMSPROXY,0}}, 941 {"6220" ,"RH-20" ,"Nokia 6220", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKSMSLIST,F_PBKUSER,F_WAPMMSPROXY,F_NOTES,0}},
926#endif 942#endif
927#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA7110) 943#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA7110)
928 {"6210" ,"NPE-3" ,"Nokia 6210", {F_VOICETAGS,F_CAL62,0}}, 944 {"6210" ,"NPE-3" ,"Nokia 6210", {F_VOICETAGS,F_CAL62,0}},
929 {"6250" ,"NHM-3" ,"Nokia 6250", {F_VOICETAGS,F_CAL62,0}}, 945 {"6250" ,"NHM-3" ,"Nokia 6250", {F_VOICETAGS,F_CAL62,0}},
930#endif 946#endif
931#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510) 947#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
932 {"6230" ,"RH-12" ,"Nokia 6230", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKSMSLIST,F_PBKUSER,0}}, 948 {"6230" ,"RH-12" ,"Nokia 6230", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKSMSLIST,F_PBKUSER,F_WAPMMSPROXY,F_NOTES,0}},
933 {"6310" ,"NPE-4" ,"Nokia 6310", {F_TODO63,F_CAL65,F_NOMIDI,F_NOMMS,F_VOICETAGS,0}}, 949 {"6310" ,"NPE-4" ,"Nokia 6310", {F_TODO63,F_CAL65,F_NOMIDI,F_NOMMS,F_VOICETAGS,0}},
934 {"6310i","NPL-1" ,"Nokia 6310i",{F_TODO63,F_CAL65,F_NOMIDI,F_BLUETOOTH,F_NOMMS,F_VOICETAGS,0}}, 950 {"6310i","NPL-1" ,"Nokia 6310i",{F_TODO63,F_CAL65,F_NOMIDI,F_BLUETOOTH,F_NOMMS,F_VOICETAGS,0}},
935 {"6385" ,"NHP-2AX","Nokia 6385",{F_TODO63,F_CAL65,F_NOMIDI,F_NOMMS,F_VOICETAGS,0}}, 951 {"6385" ,"NHP-2AX","Nokia 6385",{F_TODO63,F_CAL65,F_NOMIDI,F_NOMMS,F_VOICETAGS,0}},
936 {"6510" ,"NPM-9" ,"Nokia 6510", {F_TODO63,F_CAL65,F_NOMIDI,F_RADIO,F_NOFILESYSTEM,F_NOMMS,F_VOICETAGS,0}}, 952 {"6510" ,"NPM-9" ,"Nokia 6510", {F_TODO63,F_CAL65,F_NOMIDI,F_RADIO,F_NOFILESYSTEM,F_NOMMS,F_VOICETAGS,0}},
937 {"6610" ,"NHL-4U","Nokia 6610", {F_PBKTONEGAL,F_TODO66,F_RADIO,0}}, 953 {"6610" ,"NHL-4U","Nokia 6610", {F_PBKTONEGAL,F_TODO66,F_RADIO,0}},
954 {"6610i","RM-37" ,"Nokia 6610i",{F_PBKTONEGAL,F_TODO66,F_RADIO,0}},
938 {"6800" ,"NSB-9" ,"Nokia 6800", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKSMSLIST,0}}, 955 {"6800" ,"NSB-9" ,"Nokia 6800", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKSMSLIST,0}},
939 {"6800" ,"NHL-6" ,"Nokia 6800", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKSMSLIST,0}}, 956 {"6800" ,"NHL-6" ,"Nokia 6800", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKSMSLIST,0}},
957 {"6810" ,"RM-2" ,"Nokia 6810", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKSMSLIST,0}},//quess
958 {"6820" ,"NHL-9" ,"Nokia 6820", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKSMSLIST,0}},//quess
940#endif 959#endif
941#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA7110) 960#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA7110)
942 {"7110" ,"NSE-5" ,"Nokia 7110", {F_CAL62,0}}, 961 {"7110" ,"NSE-5" ,"Nokia 7110", {F_CAL62,0}},
943 {"7190" ,"NSB-5" ,"Nokia 7190", {F_CAL62,0}}, 962 {"7190" ,"NSB-5" ,"Nokia 7190", {F_CAL62,0}},
944#endif 963#endif
945#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510) 964#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
965 {"7200" ,"RH-23" ,"Nokia 7200", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKSMSLIST,F_PBKUSER,0}},//quess
946 {"7210" ,"NHL-4" ,"Nokia 7210", {F_PBKTONEGAL,F_TODO66,F_RADIO,0}}, 966 {"7210" ,"NHL-4" ,"Nokia 7210", {F_PBKTONEGAL,F_TODO66,F_RADIO,0}},
947 {"7250" ,"NHL-4J","Nokia 7250", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKIMG,0}}, 967 {"7250" ,"NHL-4J","Nokia 7250", {F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKIMG,0}},
948 {"7250i","NHL-4JX","Nokia 7250i",{F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKIMG,0}}, 968 {"7250i","NHL-4JX","Nokia 7250i",{F_PBKTONEGAL,F_TODO66,F_RADIO,F_PBKIMG,0}},
949 {"7600", "NMM-3", "Nokia 7600", {F_TODO66,0}}, 969 {"7600", "NMM-3", "Nokia 7600", {F_TODO66,0}},
950#endif 970#endif
951#if defined(GSM_ENABLE_ATGEN) 971#if defined(GSM_ENABLE_ATGEN)
952 {"7650" ,"NHL-2" ,"Nokia 7650", {0}}, 972 {"7650" ,"NHL-2" ,"Nokia 7650", {0}},
953#endif 973#endif
954#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6110) 974#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6110)
955 {"8210" ,"NSM-3" ,"Nokia 8210", {F_NOWAP,F_NOSTARTANI,F_NOPBKUNICODE,F_NOPICTUREUNI,0}}, 975 {"8210" ,"NSM-3" ,"Nokia 8210", {F_NOWAP,F_NOSTARTANI,F_NOPBKUNICODE,F_NOPICTUREUNI,0}},
956 {"8250" ,"NSM-3D","Nokia 8250", {F_NOWAP,F_NOSTARTANI,F_CAL82,F_NOPICTUREUNI,0}}, 976 {"8250" ,"NSM-3D","Nokia 8250", {F_NOWAP,F_NOSTARTANI,F_CAL82,F_NOPICTUREUNI,0}},
957 {"8290" ,"NSB-7" ,"Nokia 8290", {F_NOWAP,F_NOSTARTANI,F_NOPBKUNICODE,F_NOPICTUREUNI,0}}, 977 {"8290" ,"NSB-7" ,"Nokia 8290", {F_NOWAP,F_NOSTARTANI,F_NOPBKUNICODE,F_NOPICTUREUNI,0}},
958#endif 978#endif
959#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510) 979#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
960 {"8310" ,"NHM-7" ,"Nokia 8310", {F_CAL62,F_NOMIDI,F_RADIO,F_NOFILESYSTEM,F_NOMMS,F_VOICETAGS,0}}, 980 {"8310" ,"NHM-7" ,"Nokia 8310", {F_CAL62,F_NOMIDI,F_RADIO,F_NOFILESYSTEM,F_NOMMS,F_VOICETAGS,0}},
961 {"8390" ,"NSB-8" ,"Nokia 8390", {F_CAL62,F_NOMIDI,F_RADIO,F_NOFILESYSTEM,F_NOMMS,F_VOICETAGS,0}}, 981 {"8390" ,"NSB-8" ,"Nokia 8390", {F_CAL62,F_NOMIDI,F_RADIO,F_NOFILESYSTEM,F_NOMMS,F_VOICETAGS,0}},
962#endif 982#endif
963#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6110) 983#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6110)
964 {"8850" ,"NSM-2" ,"Nokia 8850", {0}}, 984 {"8850" ,"NSM-2" ,"Nokia 8850", {0}},
965 {"8855" ,"NSM-4" ,"Nokia 8855", {0}}, 985 {"8855" ,"NSM-4" ,"Nokia 8855", {0}},
966 {"8890" ,"NSB-6" ,"Nokia 8890", {0}}, 986 {"8890" ,"NSB-6" ,"Nokia 8890", {0}},
967#endif 987#endif
968#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510) 988#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_NOKIA6510)
969 {"8910" ,"NHM-4" ,"Nokia 8910", {F_CAL62,F_NOMIDI,F_NOFILESYSTEM,F_NOMMS,0}}, 989 {"8910" ,"NHM-4" ,"Nokia 8910", {F_CAL62,F_NOMIDI,F_NOFILESYSTEM,F_NOMMS,0}},
970 {"8910i","NHM-4" ,"Nokia 8910i",{F_CAL62,F_NOMIDI,F_NOFILESYSTEM,F_NOMMS,0}}, 990 {"8910i","NHM-4" ,"Nokia 8910i",{F_CAL62,F_NOMIDI,F_NOFILESYSTEM,F_NOMMS,0}},
971#endif 991#endif
972#ifdef GSM_ENABLE_NOKIA9210 992#ifdef GSM_ENABLE_NOKIA9210
973 {"9210" ,"RAE-3" ,"", {0}}, 993 {"9210" ,"RAE-3" ,"", {0}},
974 {"9210i","RAE-5" ,"", {0}}, 994 {"9210i","RAE-5" ,"", {0}},
975#endif 995#endif
976#ifdef GSM_ENABLE_ATGEN 996#ifdef GSM_ENABLE_ATGEN
977 {"at" , "at", "", {0}}, 997 {"at" , "at", "", {0}},
998 /* Siemens */
978 {"M20" , "M20", "", {F_M20SMS,F_SLOWWRITE,0}}, 999 {"M20" , "M20", "", {F_M20SMS,F_SLOWWRITE,0}},
979 {"MC35" , "MC35", "", {0}}, 1000 {"MC35" , "MC35", "", {0}},
1001 {"TC35" , "TC35", "", {0}},
980 {"S25", "S25", "SIEMENS S25", {0}}, 1002 {"S25", "S25", "SIEMENS S25", {0}},
981 {"C35i" , "C35i", "", {0}}, 1003 {"C35i" , "C35i", "", {0}},
982 {"S35i" , "S35i", "", {0}}, 1004 {"S35i" , "S35i", "", {0}},
983 {"M35i" , "M35i", "", {0}}, 1005 {"M35i" , "M35i", "", {0}},
984 {"S40" , "Siemens S40", "", {0}}, 1006 {"S40" , "Siemens S40", "", {0}},
985 {"C45" , "C45", "", {0}}, 1007 {"C45" , "C45", "", {0}},
986 {"S45" , "S45", "", {0}}, 1008 {"S45" , "S45", "", {0}},
987 {"ME45" , "ME45", "", {0}}, 1009 {"ME45" , "ME45", "", {0}},
988 {"SL45" , "SL45", "", {0}}, 1010 {"SL45" , "SL45", "", {0}},
989 {"SL45i" , "SL45i", "", {0}}, 1011 {"SL45i" , "SL45i", "", {0}},
990 {"M50" , "M50", "", {0}}, 1012 {"M50" , "M50", "", {0}},
991 {"S45" , "6618" , "", {0}}, 1013 {"S45" , "6618" , "", {0}},
992 {"ME45" , "3618" , "", {0}}, 1014 {"ME45" , "3618" , "", {0}},
993 {"S55" , "S55" , "", {0}}, 1015 {"S55" , "S55" , "", {0}},
1016 /* Samsung */
1017 {"S100" , "SGH-S100" , "", {0}},
1018 {"S200" , "SGH-S200" , "", {0}},
1019 {"S300" , "SGH-S300" , "", {0}},
1020 {"S500" , "SGH-S500" , "", {0}},
1021 {"V200" , "SGH-V200" , "", {0}},
1022 {"T100" , "SGH-T100" , "", {0}},
1023 {"E700" , "SGH-E700" , "", {0}},
1024 /* Ericsson/Sony Ericsson */
994 {"T28s", "1101101-BVT28s","", {0}}, 1025 {"T28s", "1101101-BVT28s","", {0}},
995 {"R320s" , "1101201-BV R320s","", {0}}, 1026 {"R320s" , "1101201-BV R320s","", {0}},
996 {"R380s", "7100101-BVR380s" ,"", {0}}, 1027 {"R380s", "7100101-BVR380s" ,"", {0}},
997 {"R520m", "1130101-BVR520m" ,"", {0}}, 1028 {"R520m", "1130101-BVR520m" ,"", {0}},
998 {"T39m", "1130102-BVT39m" ,"", {0}}, 1029 {"T39m", "1130102-BVT39m" ,"", {0}},
999 {"T65", "1101901-BVT65" , "", {0}}, 1030 {"T65", "1101901-BVT65" , "", {0}},
1000 {"T68", "1130201-BVT68" , "", {0}}, 1031 {"T68", "1130201-BVT68" , "", {0}},
1001 {"T68i", "1130202-BVT68" , "", {0}}, 1032 {"T68i", "1130202-BVT68" , "", {0}},
1002 {"R600", "102001-BVR600" , "", {0}}, 1033 {"R600", "102001-BVR600" , "", {0}},
1003 {"T200", "1130501-BVT200" ,"", {0}}, 1034 {"T200", "1130501-BVT200" ,"", {0}},
1004 {"T300", "1130601-BVT300" ,"T300", {0}}, 1035 {"T300", "1130601-BVT300" ,"T300", {0}},
1005 {"T310", "1130602-BVT310" ,"", {0}}, 1036 {"T310", "1130602-BVT310" ,"", {0}},
1006 {"P800", "7130501-BVP800" ,"", {0}}, 1037 {"P800", "7130501-BVP800" ,"", {0}},
1038 /* Other */
1007 {"iPAQ" , "iPAQ" , "" , {0}}, 1039 {"iPAQ" , "iPAQ" , "" , {0}},
1008 {"A2D" , "A2D" , "" , {0}}, 1040 {"A2D" , "A2D" , "" , {0}},
1009 {"9210" , "RAE-3", "Nokia Communicator GSM900/1800",{0}}, 1041 {"9210" , "RAE-3", "Nokia Communicator GSM900/1800",{0}},
1010 {"myV-65", "myV-65 GPRS", "", {F_SMSME900,0}}, 1042 {"myV-65", "myV-65 GPRS", "", {F_SMSME900,0}},
1011#endif 1043#endif
1012#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_ALCATEL) 1044#if defined(GSM_ENABLE_ATGEN) || defined(GSM_ENABLE_ALCATEL)
1013 {"BE5", "ONE TOUCH 500","", {F_ALCATEL,F_SMSONLYSENT,F_BROKENCPBS,0}}, 1045 {"BE5", "ONE TOUCH 500","", {F_ALCATEL,F_SMSONLYSENT,F_BROKENCPBS,0}},
1014 {"BH4", "ONE TOUCH 535","ALCATEL OT535", {F_ALCATEL,F_SMSONLYSENT,0}}, 1046 {"BH4", "ONE TOUCH 535","ALCATEL OT535", {F_ALCATEL,F_SMSONLYSENT,0}},
1015 {"BF5", "ONE TOUCH 715","ALCATEL OT715", {F_ALCATEL,F_SMSONLYSENT,F_BROKENCPBS,0}}, 1047 {"BF5", "ONE TOUCH 715","ALCATEL OT715", {F_ALCATEL,F_SMSONLYSENT,F_BROKENCPBS,0}},
1016#endif 1048#endif
1017 {"unknown", "" ,"", {0}} 1049 {"unknown", "" ,"", {0}}
1018}; 1050};
1019 1051
1020OnePhoneModel *GetModelData(char *model, char *number, char *irdamodel) 1052OnePhoneModel *GetModelData(char *model, char *number, char *irdamodel)
1021{ 1053{
1022 int i = 0; 1054 int i = 0;
1023 1055
1024 while (strcmp(allmodels[i].number,"") != 0) { 1056 while (strcmp(allmodels[i].number,"") != 0) {
1025 if (model !=NULL) { 1057 if (model !=NULL) {
1026 if (strcmp (model, allmodels[i].model) == 0) { 1058 if (strcmp (model, allmodels[i].model) == 0) {
1027 return (&allmodels[i]); 1059 return (&allmodels[i]);
1028 } 1060 }
1029 } 1061 }
1030 if (number !=NULL) { 1062 if (number !=NULL) {
1031 if (strcmp (number, allmodels[i].number) == 0) { 1063 if (strcmp (number, allmodels[i].number) == 0) {
1032 return (&allmodels[i]); 1064 return (&allmodels[i]);
1033 } 1065 }
1034 } 1066 }
1035 if (irdamodel !=NULL) { 1067 if (irdamodel !=NULL) {
1036 if (strcmp (irdamodel, allmodels[i].irdamodel) == 0) { 1068 if (strcmp (irdamodel, allmodels[i].irdamodel) == 0) {
1037 return (&allmodels[i]); 1069 return (&allmodels[i]);
1038 } 1070 }
1039 } 1071 }
1040 i++; 1072 i++;
1041 } 1073 }
1042 return (&allmodels[i]); 1074 return (&allmodels[i]);
1043} 1075}
1044 1076
1045bool IsPhoneFeatureAvailable(OnePhoneModel *model, Feature feature) 1077bool IsPhoneFeatureAvailable(OnePhoneModel *model, Feature feature)
1046{ 1078{
1047 int i= 0; 1079 int i= 0;
1048 boolretval = false; 1080 boolretval = false;
1049 1081
1050 while (model->features[i] != 0) { 1082 while (model->features[i] != 0) {
1051 if (model->features[i] == feature) { 1083 if (model->features[i] == feature) {
1052 retval = true; 1084 retval = true;
1053 break; 1085 break;
1054 } 1086 }
1055 i++; 1087 i++;
1056 } 1088 }
1057 return retval; 1089 return retval;
1058} 1090}
1059 1091
1060void GSM_DumpMessageLevel2(GSM_StateMachine *s, unsigned char *message, int messagesize, int type) 1092void GSM_DumpMessageLevel2(GSM_StateMachine *s, unsigned char *message, int messagesize, int type)
1061{ 1093{
1062 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || 1094 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL ||
1063 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) { 1095 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) {
1064 smprintf(s,"SENDING frame "); 1096 smprintf(s,"SENDING frame ");
1065 smprintf(s,"type 0x%02X/length 0x%02X/%i", type, messagesize, messagesize); 1097 smprintf(s,"type 0x%02X/length 0x%02X/%i", type, messagesize, messagesize);
1066 DumpMessage(s->di.use_global ? di.df : s->di.df, s->di.dl, message, messagesize); 1098 DumpMessage(s->di.use_global ? di.df : s->di.df, s->di.dl, message, messagesize);
1067 if (messagesize == 0) smprintf(s,"\n"); 1099 if (messagesize == 0) smprintf(s,"\n");
1068 if (s->di.df) fflush(s->di.df); 1100 if (s->di.df) fflush(s->di.df);
1069 } 1101 }
1070} 1102}
1071 1103
1072void GSM_DumpMessageLevel3(GSM_StateMachine *s, unsigned char *message, int messagesize, int type) 1104void GSM_DumpMessageLevel3(GSM_StateMachine *s, unsigned char *message, int messagesize, int type)
1073{ 1105{
1074 int i; 1106 int i;
1075 1107
1076 if (s->di.dl==DL_BINARY) { 1108 if (s->di.dl==DL_BINARY) {
1077 smprintf(s,"%c",0x01);/* Sending */ 1109 smprintf(s,"%c",0x01);/* Sending */
1078 smprintf(s,"%c",type); 1110 smprintf(s,"%c",type);
1079 smprintf(s,"%c",messagesize/256); 1111 smprintf(s,"%c",messagesize/256);
1080 smprintf(s,"%c",messagesize%256); 1112 smprintf(s,"%c",messagesize%256);
1081 for (i=0;i<messagesize;i++) smprintf(s,"%c",message[i]); 1113 for (i=0;i<messagesize;i++) smprintf(s,"%c",message[i]);
1082 } 1114 }
1083} 1115}
1084 1116
1085#ifdef __GNUC__ 1117#ifdef __GNUC__
1086__attribute__((format(printf, 2, 3))) 1118__attribute__((format(printf, 2, 3)))
1087#endif 1119#endif
1088int smprintf(GSM_StateMachine *s, const char *format, ...) 1120int smprintf(GSM_StateMachine *s, const char *format, ...)
1089{ 1121{
1090 va_list argp; 1122 va_list argp;
1091 int result=0; 1123 int result=0;
1092 unsigned charbuffer[2000]; 1124 unsigned charbuffer[2000];
1093 Debug_Leveldl; 1125 Debug_Leveldl;
1094 FILE *df; 1126 FILE *df;
1095 1127
1096 va_start(argp, format); 1128 va_start(argp, format);
1097 if (s == NULL) { 1129 if (s == NULL) {
1098 dl = di.dl; 1130 dl = di.dl;
1099 df = di.df; 1131 df = di.df;
1100 } else { 1132 } else {
1101 dl = s->di.dl; 1133 dl = s->di.dl;
1102 if (s->di.use_global) { 1134 if (s->di.use_global) {
1103 df = di.df; 1135 df = di.df;
1104 } else { 1136 } else {
1105 df = s->di.df; 1137 df = s->di.df;
1106 } 1138 }
1107 } 1139 }
1108 1140
1109 if (dl != 0) { 1141 if (dl != 0) {
1110 result = vsprintf(buffer, format, argp); 1142 result = vsprintf(buffer, format, argp);
1111 result = smfprintf(df, dl, "%s", buffer); 1143 result = smfprintf(df, dl, "%s", buffer);
1112 } 1144 }
1113 1145
1114 va_end(argp); 1146 va_end(argp);
1115 return result; 1147 return result;
1116} 1148}
1117 1149
1118void GSM_OSErrorInfo(GSM_StateMachine *s, char *description) 1150void GSM_OSErrorInfo(GSM_StateMachine *s, char *description)
1119{ 1151{
1120#ifdef WIN32 1152#ifdef WIN32
1121 int i; 1153 int i;
1122 unsigned char *lpMsgBuf; 1154 unsigned char *lpMsgBuf;
1123 1155
1124 /* We don't use errno in win32 - GetLastError gives better info */ 1156 /* We don't use errno in win32 - GetLastError gives better info */
1125 if (GetLastError()!=-1) { 1157 if (GetLastError()!=-1) {
1126 if (s->di.dl == DL_TEXTERROR || s->di.dl == DL_TEXT || s->di.dl == DL_TEXTALL || 1158 if (s->di.dl == DL_TEXTERROR || s->di.dl == DL_TEXT || s->di.dl == DL_TEXTALL ||
1127 s->di.dl == DL_TEXTERRORDATE || s->di.dl == DL_TEXTDATE || s->di.dl == DL_TEXTALLDATE) { 1159 s->di.dl == DL_TEXTERRORDATE || s->di.dl == DL_TEXTDATE || s->di.dl == DL_TEXTALLDATE) {
1128 FormatMessage( 1160 FormatMessage(
1129 FORMAT_MESSAGE_ALLOCATE_BUFFER | 1161 FORMAT_MESSAGE_ALLOCATE_BUFFER |
1130 FORMAT_MESSAGE_FROM_SYSTEM | 1162 FORMAT_MESSAGE_FROM_SYSTEM |
1131 FORMAT_MESSAGE_IGNORE_INSERTS, 1163 FORMAT_MESSAGE_IGNORE_INSERTS,
1132 NULL, 1164 NULL,
1133 GetLastError(), 1165 GetLastError(),
1134 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language 1166 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
1135 (LPTSTR) &lpMsgBuf, 1167 (LPTSTR) &lpMsgBuf,
1136 0, 1168 0,
1137 NULL 1169 NULL
1138 ); 1170 );
1139 for (i=0;i<(int)strlen(lpMsgBuf);i++) { 1171 for (i=0;i<(int)strlen(lpMsgBuf);i++) {
1140 if (lpMsgBuf[i] == 13 || lpMsgBuf[i] == 10) { 1172 if (lpMsgBuf[i] == 13 || lpMsgBuf[i] == 10) {
1141 lpMsgBuf[i] = ' '; 1173 lpMsgBuf[i] = ' ';
1142 } 1174 }
1143 } 1175 }
1144 smprintf(s,"[System error - %s, %i, \"%s\"]\n",description,GetLastError(),(LPCTSTR)lpMsgBuf); 1176 smprintf(s,"[System error - %s, %i, \"%s\"]\n",description,GetLastError(),(LPCTSTR)lpMsgBuf);
1145 LocalFree(lpMsgBuf); 1177 LocalFree(lpMsgBuf);
1146 } 1178 }
1147 } 1179 }
1148 return; 1180 return;
1149#endif 1181#endif
1150 1182
1151 if (errno!=-1) { 1183 if (errno!=-1) {
1152 if (s->di.dl == DL_TEXTERROR || s->di.dl == DL_TEXT || s->di.dl == DL_TEXTALL || 1184 if (s->di.dl == DL_TEXTERROR || s->di.dl == DL_TEXT || s->di.dl == DL_TEXTALL ||
1153 s->di.dl == DL_TEXTERRORDATE || s->di.dl == DL_TEXTDATE || s->di.dl == DL_TEXTALLDATE) { 1185 s->di.dl == DL_TEXTERRORDATE || s->di.dl == DL_TEXTDATE || s->di.dl == DL_TEXTALLDATE) {
1154 smprintf(s,"[System error - %s, %i, \"%s\"]\n",description,errno,strerror(errno)); 1186 smprintf(s,"[System error - %s, %i, \"%s\"]\n",description,errno,strerror(errno));
1155 } 1187 }
1156 } 1188 }
1157} 1189}
1158 1190
1159#ifdef GSM_ENABLE_BACKUP 1191#ifdef GSM_ENABLE_BACKUP
1160 1192
1161void GSM_GetPhoneFeaturesForBackup(GSM_StateMachine *s, GSM_Backup_Info *info) 1193void GSM_GetPhoneFeaturesForBackup(GSM_StateMachine *s, GSM_Backup_Info *info)
1162{ 1194{
1163 GSM_Error error; 1195 GSM_Error error;
1164 GSM_MemoryStatusMemStatus; 1196 GSM_MemoryStatusMemStatus;
1165 GSM_ToDoStatus ToDoStatus; 1197 GSM_ToDoStatus ToDoStatus;
1166 GSM_CalendarEntry Note; 1198 GSM_CalendarEntry Note;
1167 GSM_WAPBookmark Bookmark; 1199 GSM_WAPBookmark Bookmark;
1168 GSM_MultiWAPSettingsWAPSettings; 1200 GSM_MultiWAPSettingsWAPSettings;
1169 GSM_FMStation FMStation; 1201 GSM_FMStation FMStation;
1170 GSM_GPRSAccessPointGPRSPoint; 1202 GSM_GPRSAccessPointGPRSPoint;
1171 // GSM_Profile Profile; 1203 // GSM_Profile Profile;
1172 1204
1173 if (info->PhonePhonebook) { 1205 if (info->PhonePhonebook) {
1174 MemStatus.MemoryType = MEM_ME; 1206 MemStatus.MemoryType = MEM_ME;
1175 error=s->Phone.Functions->GetMemoryStatus(s, &MemStatus); 1207 error=s->Phone.Functions->GetMemoryStatus(s, &MemStatus);
1176 if (error==ERR_NONE && MemStatus.MemoryUsed != 0) { 1208 if (error==ERR_NONE && MemStatus.MemoryUsed != 0) {
1177 } else { 1209 } else {
1178 info->PhonePhonebook = false; 1210 info->PhonePhonebook = false;
1179 } 1211 }
1180 } 1212 }
1181 if (info->SIMPhonebook) { 1213 if (info->SIMPhonebook) {
1182 MemStatus.MemoryType = MEM_SM; 1214 MemStatus.MemoryType = MEM_SM;
1183 error=s->Phone.Functions->GetMemoryStatus(s, &MemStatus); 1215 error=s->Phone.Functions->GetMemoryStatus(s, &MemStatus);
1184 if (error==ERR_NONE && MemStatus.MemoryUsed != 0) { 1216 if (error==ERR_NONE && MemStatus.MemoryUsed != 0) {
1185 } else { 1217 } else {
1186 info->SIMPhonebook = false; 1218 info->SIMPhonebook = false;
1187 } 1219 }
1188 } 1220 }
1189 if (info->Calendar) { 1221 if (info->Calendar) {
1190 error=s->Phone.Functions->GetNextCalendar(s,&Note,true); 1222 error=s->Phone.Functions->GetNextCalendar(s,&Note,true);
1191 if (error!=ERR_NONE) info->Calendar = false; 1223 if (error!=ERR_NONE) info->Calendar = false;
1192 } 1224 }
1193 if (info->ToDo) { 1225 if (info->ToDo) {
1194 error=s->Phone.Functions->GetToDoStatus(s,&ToDoStatus); 1226 error=s->Phone.Functions->GetToDoStatus(s,&ToDoStatus);
1195 if (error == ERR_NONE && ToDoStatus.Used != 0) { 1227 if (error == ERR_NONE && ToDoStatus.Used != 0) {
1196 } else { 1228 } else {
1197 info->ToDo = false; 1229 info->ToDo = false;
1198 } 1230 }
diff --git a/gammu/emb/common/gsmstate.h b/gammu/emb/common/gsmstate.h
index cb17623..2b4806c 100644
--- a/gammu/emb/common/gsmstate.h
+++ b/gammu/emb/common/gsmstate.h
@@ -1,1562 +1,1579 @@
1/* (c) 2002-2004 by Marcin Wiacek & Michal Cihar */ 1/* (c) 2002-2004 by Marcin Wiacek & Michal Cihar */
2 2
3#ifndef __gsm_state_h 3#ifndef __gsm_state_h
4#define __gsm_state_h 4#define __gsm_state_h
5 5
6#include <time.h> 6#include <time.h>
7 7
8#include "config.h" 8#include "config.h"
9#include "misc/cfg.h" 9#include "misc/cfg.h"
10 10
11 typedef struct _GSM_StateMachine GSM_StateMachine;
12 typedef struct _GSM_User GSM_User;
13 typedef struct _OnePhoneModel OnePhoneModel;
14 typedef struct _GSM_Reply_FunctionGSM_Reply_Function;
15
11#ifdef GSM_ENABLE_NOKIA3320 16#ifdef GSM_ENABLE_NOKIA3320
12# include "phone/nokia/dct4/n3320.h" 17# include "phone/nokia/dct4/n3320.h"
13#endif 18#endif
14#ifdef GSM_ENABLE_NOKIA3650 19#ifdef GSM_ENABLE_NOKIA3650
15# include "phone/nokia/dct4/n3650.h" 20# include "phone/nokia/dct4/n3650.h"
16#endif 21#endif
22#ifdef GSM_ENABLE_NOKIA650
23# include "phone/nokia/dct3/n0650.h"
24#endif
17#ifdef GSM_ENABLE_NOKIA6110 25#ifdef GSM_ENABLE_NOKIA6110
18# include "phone/nokia/dct3/n6110.h" 26# include "phone/nokia/dct3/n6110.h"
19#endif 27#endif
20#ifdef GSM_ENABLE_NOKIA6510 28#ifdef GSM_ENABLE_NOKIA6510
21# include "phone/nokia/dct4/n6510.h" 29# include "phone/nokia/dct4/n6510.h"
22#endif 30#endif
23#ifdef GSM_ENABLE_NOKIA7110 31#ifdef GSM_ENABLE_NOKIA7110
24# include "phone/nokia/dct3/n7110.h" 32# include "phone/nokia/dct3/n7110.h"
25#endif 33#endif
26#ifdef GSM_ENABLE_NOKIA9210 34#ifdef GSM_ENABLE_NOKIA9210
27# include "phone/nokia/dct3/n9210.h" 35# include "phone/nokia/dct3/n9210.h"
28#endif 36#endif
29#ifdef GSM_ENABLE_ATGEN 37#ifdef GSM_ENABLE_ATGEN
30# include "phone/at/atgen.h" 38# include "phone/at/atgen.h"
31#endif 39#endif
32#ifdef GSM_ENABLE_ALCATEL 40#ifdef GSM_ENABLE_ALCATEL
33# include "phone/alcatel/alcatel.h" 41# include "phone/alcatel/alcatel.h"
34#endif 42#endif
35#ifdef GSM_ENABLE_OBEXGEN 43#ifdef GSM_ENABLE_OBEXGEN
36# include "phone/obex/obexgen.h" 44# include "phone/obex/obexgen.h"
37#endif 45#endif
38#ifdef GSM_ENABLE_MROUTERGEN 46#ifdef GSM_ENABLE_MROUTERGEN
39# include "phone/symbian/mroutgen.h" 47# include "phone/symbian/mroutgen.h"
40#endif 48#endif
41 49
42#ifndef GSM_USED_MBUS2 50#ifndef GSM_USED_MBUS2
43# undef GSM_ENABLE_MBUS2 51# undef GSM_ENABLE_MBUS2
44#endif 52#endif
45#ifndef GSM_USED_FBUS2 53#ifndef GSM_USED_FBUS2
46# undef GSM_ENABLE_FBUS2 54# undef GSM_ENABLE_FBUS2
47#endif 55#endif
48#ifndef GSM_USED_FBUS2DLR3 56#ifndef GSM_USED_FBUS2DLR3
49# undef GSM_ENABLE_FBUS2DLR3 57# undef GSM_ENABLE_FBUS2DLR3
50#endif 58#endif
51#ifndef GSM_USED_FBUS2DKU5 59#ifndef GSM_USED_FBUS2DKU5
52# undef GSM_ENABLE_FBUS2DKU5 60# undef GSM_ENABLE_FBUS2DKU5
53#endif 61#endif
54#ifndef GSM_USED_FBUS2PL2303 62#ifndef GSM_USED_FBUS2PL2303
55# undef GSM_ENABLE_FBUS2PL2303 63# undef GSM_ENABLE_FBUS2PL2303
56#endif 64#endif
57#ifndef GSM_USED_FBUS2BLUE 65#ifndef GSM_USED_FBUS2BLUE
58# undef GSM_ENABLE_FBUS2BLUE 66# undef GSM_ENABLE_FBUS2BLUE
59#endif 67#endif
60#ifndef GSM_USED_FBUS2IRDA 68#ifndef GSM_USED_FBUS2IRDA
61# undef GSM_ENABLE_FBUS2IRDA 69# undef GSM_ENABLE_FBUS2IRDA
62#endif 70#endif
63#ifndef GSM_USED_PHONETBLUE 71#ifndef GSM_USED_PHONETBLUE
64# undef GSM_ENABLE_PHONETBLUE 72# undef GSM_ENABLE_PHONETBLUE
65#endif 73#endif
66#ifndef GSM_USED_AT 74#ifndef GSM_USED_AT
67# undef GSM_ENABLE_AT 75# undef GSM_ENABLE_AT
68#endif 76#endif
69#ifndef GSM_USED_IRDAOBEX 77#ifndef GSM_USED_IRDAOBEX
70# undef GSM_ENABLE_IRDAOBEX 78# undef GSM_ENABLE_IRDAOBEX
71#endif 79#endif
72#ifndef GSM_USED_BLUEOBEX 80#ifndef GSM_USED_BLUEOBEX
73# undef GSM_ENABLE_BLUEOBEX 81# undef GSM_ENABLE_BLUEOBEX
74#endif 82#endif
75#ifndef GSM_USED_ALCABUS 83#ifndef GSM_USED_ALCABUS
76# undef GSM_ENABLE_ALCABUS 84# undef GSM_ENABLE_ALCABUS
77#endif 85#endif
78#ifndef GSM_USED_IRDAPHONET 86#ifndef GSM_USED_IRDAPHONET
79# undef GSM_ENABLE_IRDAPHONET 87# undef GSM_ENABLE_IRDAPHONET
80#endif 88#endif
81#ifndef GSM_USED_BLUEFBUS2 89#ifndef GSM_USED_BLUEFBUS2
82# undef GSM_ENABLE_BLUEFBUS2 90# undef GSM_ENABLE_BLUEFBUS2
83#endif 91#endif
84#ifndef GSM_USED_BLUEPHONET 92#ifndef GSM_USED_BLUEPHONET
85# undef GSM_ENABLE_BLUEPHONET 93# undef GSM_ENABLE_BLUEPHONET
86#endif 94#endif
87#ifndef GSM_USED_BLUEAT 95#ifndef GSM_USED_BLUEAT
88# undef GSM_ENABLE_BLUEAT 96# undef GSM_ENABLE_BLUEAT
89#endif 97#endif
90#ifndef GSM_USED_IRDAAT 98#ifndef GSM_USED_IRDAAT
91# undef GSM_ENABLE_IRDAAT 99# undef GSM_ENABLE_IRDAAT
92#endif 100#endif
93#ifndef GSM_USED_MROUTERBLUE 101#ifndef GSM_USED_MROUTERBLUE
94# undef GSM_ENABLE_MROUTERBLUE 102# undef GSM_ENABLE_MROUTERBLUE
95#endif 103#endif
96 104
97#if defined(GSM_ENABLE_NOKIA3320) || defined(GSM_ENABLE_NOKIA6110) || defined(GSM_ENABLE_NOKIA7110) || defined(GSM_ENABLE_NOKIA9210) 105#if defined(GSM_ENABLE_NOKIA3320) || defined(GSM_ENABLE_NOKIA650) || defined(GSM_ENABLE_NOKIA6110) || defined(GSM_ENABLE_NOKIA7110) || defined(GSM_ENABLE_NOKIA9210)
98# define GSM_ENABLE_NOKIA_DCT3 106# define GSM_ENABLE_NOKIA_DCT3
99#endif 107#endif
100#if defined(GSM_ENABLE_NOKIA3650) || defined(GSM_ENABLE_NOKIA6510) 108#if defined(GSM_ENABLE_NOKIA3650) || defined(GSM_ENABLE_NOKIA6510)
101# define GSM_ENABLE_NOKIA_DCT4 109# define GSM_ENABLE_NOKIA_DCT4
102#endif 110#endif
103 111
104#include "protocol/protocol.h" 112#include "protocol/protocol.h"
105#if defined(GSM_ENABLE_FBUS2) || defined(GSM_ENABLE_FBUS2IRDA) || defined(GSM_ENABLE_FBUS2DLR3) || defined(GSM_ENABLE_FBUS2BLUE) || defined(GSM_ENABLE_BLUEFBUS2) || defined(GSM_ENABLE_FBUS2DKU5) || defined(GSM_ENABLE_FBUS2PL2303) 113#if defined(GSM_ENABLE_FBUS2) || defined(GSM_ENABLE_FBUS2IRDA) || defined(GSM_ENABLE_FBUS2DLR3) || defined(GSM_ENABLE_FBUS2BLUE) || defined(GSM_ENABLE_BLUEFBUS2) || defined(GSM_ENABLE_FBUS2DKU5) || defined(GSM_ENABLE_FBUS2PL2303)
106# include "protocol/nokia/fbus2.h" 114# include "protocol/nokia/fbus2.h"
107#endif 115#endif
108#ifdef GSM_ENABLE_MBUS2 116#ifdef GSM_ENABLE_MBUS2
109# include "protocol/nokia/mbus2.h" 117# include "protocol/nokia/mbus2.h"
110#endif 118#endif
111#if defined(GSM_ENABLE_PHONETBLUE) || defined(GSM_ENABLE_IRDAPHONET) || defined(GSM_ENABLE_BLUEPHONET) 119#if defined(GSM_ENABLE_PHONETBLUE) || defined(GSM_ENABLE_IRDAPHONET) || defined(GSM_ENABLE_BLUEPHONET)
112# include "protocol/nokia/phonet.h" 120# include "protocol/nokia/phonet.h"
113#endif 121#endif
114#if defined(GSM_ENABLE_AT) || defined(GSM_ENABLE_BLUEAT) || defined(GSM_ENABLE_IRDAAT) 122#if defined(GSM_ENABLE_AT) || defined(GSM_ENABLE_BLUEAT) || defined(GSM_ENABLE_IRDAAT)
115# include "protocol/at/at.h" 123# include "protocol/at/at.h"
116#endif 124#endif
117#ifdef GSM_ENABLE_ALCABUS 125#ifdef GSM_ENABLE_ALCABUS
118# include "protocol/alcatel/alcabus.h" 126# include "protocol/alcatel/alcabus.h"
119#endif 127#endif
120#if defined(GSM_ENABLE_IRDAOBEX) || defined(GSM_ENABLE_BLUEOBEX) 128#if defined(GSM_ENABLE_IRDAOBEX) || defined(GSM_ENABLE_BLUEOBEX)
121# include "protocol/obex/obex.h" 129# include "protocol/obex/obex.h"
122#endif 130#endif
123#if defined(GSM_ENABLE_MROUTERBLUE) 131#if defined(GSM_ENABLE_MROUTERBLUE)
124# include "protocol/symbian/mrouter.h" 132# include "protocol/symbian/mrouter.h"
125#endif 133#endif
126 134
127#define GSM_ENABLE_SERIALDEVICE 135#define GSM_ENABLE_SERIALDEVICE
128#ifndef GSM_USED_SERIALDEVICE 136#ifndef GSM_USED_SERIALDEVICE
129# undef GSM_ENABLE_SERIALDEVICE 137# undef GSM_ENABLE_SERIALDEVICE
130#endif 138#endif
131#define GSM_ENABLE_IRDADEVICE 139#define GSM_ENABLE_IRDADEVICE
132#ifndef GSM_USED_IRDADEVICE 140#ifndef GSM_USED_IRDADEVICE
133# undef GSM_ENABLE_IRDADEVICE 141# undef GSM_ENABLE_IRDADEVICE
134#endif 142#endif
135#define GSM_ENABLE_BLUETOOTHDEVICE 143#define GSM_ENABLE_BLUETOOTHDEVICE
136#ifndef GSM_USED_BLUETOOTHDEVICE 144#ifndef GSM_USED_BLUETOOTHDEVICE
137# undef GSM_ENABLE_BLUETOOTHDEVICE 145# undef GSM_ENABLE_BLUETOOTHDEVICE
138#endif 146#endif
139 147
140#ifdef DJGPP 148#ifdef DJGPP
141# undef GSM_ENABLE_IRDADEVICE 149# undef GSM_ENABLE_IRDADEVICE
142# undef GSM_ENABLE_IRDAPHONET 150# undef GSM_ENABLE_IRDAPHONET
143# undef GSM_ENABLE_IRDAOBEX 151# undef GSM_ENABLE_IRDAOBEX
144# undef GSM_ENABLE_IRDAAT 152# undef GSM_ENABLE_IRDAAT
145# undef GSM_ENABLE_FBUS2IRDA 153# undef GSM_ENABLE_FBUS2IRDA
146 154
147# undef GSM_ENABLE_BLUETOOTHDEVICE 155# undef GSM_ENABLE_BLUETOOTHDEVICE
148# undef GSM_ENABLE_BLUEPHONET 156# undef GSM_ENABLE_BLUEPHONET
149# undef GSM_ENABLE_BLUEOBEX 157# undef GSM_ENABLE_BLUEOBEX
150# undef GSM_ENABLE_BLUEAT 158# undef GSM_ENABLE_BLUEAT
151# undef GSM_ENABLE_BLUEFBUS2 159# undef GSM_ENABLE_BLUEFBUS2
152# undef GSM_ENABLE_PHONETBLUE 160# undef GSM_ENABLE_PHONETBLUE
153# undef GSM_ENABLE_FBUS2BLUE 161# undef GSM_ENABLE_FBUS2BLUE
154# undef GSM_ENABLE_MROUTERBLUE 162# undef GSM_ENABLE_MROUTERBLUE
155#endif 163#endif
156 164
157#ifndef WIN32 165#ifndef WIN32
158# ifdef ENABLE_LGPL 166# ifdef ENABLE_LGPL
159# undef GSM_ENABLE_IRDADEVICE 167# undef GSM_ENABLE_IRDADEVICE
160# undef GSM_ENABLE_IRDAPHONET 168# undef GSM_ENABLE_IRDAPHONET
161# undef GSM_ENABLE_IRDAOBEX 169# undef GSM_ENABLE_IRDAOBEX
162# undef GSM_ENABLE_IRDAAT 170# undef GSM_ENABLE_IRDAAT
163# undef GSM_ENABLE_FBUS2IRDA 171# undef GSM_ENABLE_FBUS2IRDA
164 172
165# undef GSM_ENABLE_BLUETOOTHDEVICE 173# undef GSM_ENABLE_BLUETOOTHDEVICE
166# undef GSM_ENABLE_BLUEPHONET 174# undef GSM_ENABLE_BLUEPHONET
167# undef GSM_ENABLE_BLUEOBEX 175# undef GSM_ENABLE_BLUEOBEX
168# undef GSM_ENABLE_BLUEAT 176# undef GSM_ENABLE_BLUEAT
169# undef GSM_ENABLE_BLUEFBUS2 177# undef GSM_ENABLE_BLUEFBUS2
170# undef GSM_ENABLE_PHONETBLUE 178# undef GSM_ENABLE_PHONETBLUE
171# undef GSM_ENABLE_FBUS2BLUE 179# undef GSM_ENABLE_FBUS2BLUE
172# undef GSM_ENABLE_MROUTERBLUE 180# undef GSM_ENABLE_MROUTERBLUE
173# endif 181# endif
174#endif 182#endif
175 183
176#ifdef GSM_ENABLE_SERIALDEVICE 184#ifdef GSM_ENABLE_SERIALDEVICE
177# include "device/serial/ser_w32.h" 185# include "device/serial/ser_w32.h"
178# include "device/serial/ser_unx.h" 186# include "device/serial/ser_unx.h"
179# include "device/serial/ser_djg.h" 187# include "device/serial/ser_djg.h"
180#endif 188#endif
181#ifdef GSM_ENABLE_IRDADEVICE 189#ifdef GSM_ENABLE_IRDADEVICE
182# include "device/irda/irda.h" 190# include "device/irda/irda.h"
183#endif 191#endif
184#ifdef GSM_ENABLE_BLUETOOTHDEVICE 192#ifdef GSM_ENABLE_BLUETOOTHDEVICE
185# include "device/bluetoth/bluetoth.h" 193# include "device/bluetoth/bluetoth.h"
186#endif 194#endif
187 195
188#include "service/gsmpbk.h" 196#include "service/gsmpbk.h"
189#include "service/gsmnet.h" 197#include "service/gsmnet.h"
190#include "service/gsmring.h" 198#include "service/gsmring.h"
191#include "service/gsmcal.h" 199#include "service/gsmcal.h"
192#include "service/gsmdata.h" 200#include "service/gsmdata.h"
193#include "service/gsmlogo.h" 201#include "service/gsmlogo.h"
194#include "service/gsmmisc.h" 202#include "service/gsmmisc.h"
195#include "service/gsmprof.h" 203#include "service/gsmprof.h"
196#include "service/gsmcall.h" 204#include "service/gsmcall.h"
197#include "service/sms/gsmsms.h" 205#include "service/sms/gsmsms.h"
198#include "service/sms/gsmems.h" 206#include "service/sms/gsmems.h"
199#include "service/sms/gsmmulti.h" 207#include "service/sms/gsmmulti.h"
200#include "service/backup/gsmback.h" 208#include "service/backup/gsmback.h"
201 209
202typedef struct _GSM_StateMachine GSM_StateMachine;
203 typedef struct _GSM_User GSM_User;
204 typedef struct _OnePhoneModel OnePhoneModel;
205 210
206/* ------------------------- Device layer ---------------------------------- */ 211/* ------------------------- Device layer ---------------------------------- */
207 212
208/** 213/**
209 * Device functions, each device has to provide these. 214 * Device functions, each device has to provide these.
210 */ 215 */
211typedef struct { 216typedef struct {
212 /** 217 /**
213 * Opens device. 218 * Opens device.
214 */ 219 */
215 GSM_Error (*OpenDevice) (GSM_StateMachine *s); 220 GSM_Error (*OpenDevice) (GSM_StateMachine *s);
216 /** 221 /**
217 * Closes device. 222 * Closes device.
218 */ 223 */
219 GSM_Error (*CloseDevice) (GSM_StateMachine *s); 224 GSM_Error (*CloseDevice) (GSM_StateMachine *s);
220 /** 225 /**
221 * Sets parity for device. 226 * Sets parity for device.
222 */ 227 */
223 GSM_Error (*DeviceSetParity) (GSM_StateMachine *s, bool parity); 228 GSM_Error (*DeviceSetParity) (GSM_StateMachine *s, bool parity);
224 /** 229 /**
225 * Sets dtr (data to read) and rts (ready to send) flags. 230 * Sets dtr (data to read) and rts (ready to send) flags.
226 */ 231 */
227 GSM_Error (*DeviceSetDtrRts) (GSM_StateMachine *s, bool dtr, bool rts); 232 GSM_Error (*DeviceSetDtrRts) (GSM_StateMachine *s, bool dtr, bool rts);
228 /** 233 /**
229 * Sets device speed. 234 * Sets device speed.
230 */ 235 */
231 GSM_Error (*DeviceSetSpeed) (GSM_StateMachine *s, int speed); 236 GSM_Error (*DeviceSetSpeed) (GSM_StateMachine *s, int speed);
232 /** 237 /**
233 * Attempts to read nbytes from device. 238 * Attempts to read nbytes from device.
234 */ 239 */
235 int (*ReadDevice) (GSM_StateMachine *s, void *buf, size_t nbytes); 240 int (*ReadDevice) (GSM_StateMachine *s, void *buf, size_t nbytes);
236 /** 241 /**
237 * Attempts to read nbytes from device. 242 * Attempts to read nbytes from device.
238 */ 243 */
239 int (*WriteDevice) (GSM_StateMachine *s, void *buf, size_t nbytes); 244 int (*WriteDevice) (GSM_StateMachine *s, void *buf, size_t nbytes);
240} GSM_Device_Functions; 245} GSM_Device_Functions;
241 246
242#ifdef GSM_ENABLE_SERIALDEVICE 247#ifdef GSM_ENABLE_SERIALDEVICE
243 extern GSM_Device_Functions SerialDevice; 248 extern GSM_Device_Functions SerialDevice;
244#endif 249#endif
245#ifdef GSM_ENABLE_IRDADEVICE 250#ifdef GSM_ENABLE_IRDADEVICE
246 extern GSM_Device_Functions IrdaDevice; 251 extern GSM_Device_Functions IrdaDevice;
247#endif 252#endif
248#ifdef GSM_ENABLE_BLUETOOTHDEVICE 253#ifdef GSM_ENABLE_BLUETOOTHDEVICE
249 extern GSM_Device_Functions BlueToothDevice; 254 extern GSM_Device_Functions BlueToothDevice;
250#endif 255#endif
251 256
252/** 257/**
253 * Structure containing device specific data and pointer to device functions - 258 * Structure containing device specific data and pointer to device functions -
254 * @ref GSM_Device_Functions. The data are in a union, so you can use only 259 * @ref GSM_Device_Functions. The data are in a union, so you can use only
255 * one device at one time. 260 * one device at one time.
256 */ 261 */
257typedef struct { 262typedef struct {
258 union { 263 union {
259 char fake; 264 char fake;
260#ifdef GSM_ENABLE_SERIALDEVICE 265#ifdef GSM_ENABLE_SERIALDEVICE
261 GSM_Device_SerialData Serial; 266 GSM_Device_SerialData Serial;
262#endif 267#endif
263#ifdef GSM_ENABLE_IRDADEVICE 268#ifdef GSM_ENABLE_IRDADEVICE
264 GSM_Device_IrdaData Irda; 269 GSM_Device_IrdaData Irda;
265#endif 270#endif
266#ifdef GSM_ENABLE_BLUETOOTHDEVICE 271#ifdef GSM_ENABLE_BLUETOOTHDEVICE
267 GSM_Device_BlueToothDataBlueTooth; 272 GSM_Device_BlueToothDataBlueTooth;
268#endif 273#endif
269 } Data; 274 } Data;
270 GSM_Device_Functions *Functions; 275 GSM_Device_Functions *Functions;
271} GSM_Device; 276} GSM_Device;
272 277
273/* ---------------------- Protocol layer ----------------------------------- */ 278/* ---------------------- Protocol layer ----------------------------------- */
274 279
275/** 280/**
276 * Protocol functions, each protocol has to implement these. 281 * Protocol functions, each protocol has to implement these.
277 */ 282 */
278typedef struct { 283typedef struct {
279 /** 284 /**
280 * Writes message to device. 285 * Writes message to device.
281 */ 286 */
282 GSM_Error (*WriteMessage) (GSM_StateMachine *s, unsigned char *buffer, 287 GSM_Error (*WriteMessage) (GSM_StateMachine *s, unsigned char *buffer,
283 int length, unsigned char type); 288 int length, unsigned char type);
284 /** 289 /**
285 * This one is called when character is received from device. 290 * This one is called when character is received from device.
286 */ 291 */
287 GSM_Error (*StateMachine) (GSM_StateMachine *s, unsigned char rx_char); 292 GSM_Error (*StateMachine) (GSM_StateMachine *s, unsigned char rx_char);
288 /** 293 /**
289 * Protocol initialisation. 294 * Protocol initialisation.
290 */ 295 */
291 GSM_Error (*Initialise) (GSM_StateMachine *s); 296 GSM_Error (*Initialise) (GSM_StateMachine *s);
292 /** 297 /**
293 * Protocol termination. 298 * Protocol termination.
294 */ 299 */
295 GSM_Error (*Terminate) (GSM_StateMachine *s); 300 GSM_Error (*Terminate) (GSM_StateMachine *s);
296} GSM_Protocol_Functions; 301} GSM_Protocol_Functions;
297 302
298#ifdef GSM_ENABLE_MBUS2 303#ifdef GSM_ENABLE_MBUS2
299 extern GSM_Protocol_Functions MBUS2Protocol; 304 extern GSM_Protocol_Functions MBUS2Protocol;
300#endif 305#endif
301#if defined(GSM_ENABLE_FBUS2) || defined(GSM_ENABLE_FBUS2IRDA) || defined(GSM_ENABLE_FBUS2DLR3) || defined(GSM_ENABLE_FBUS2DKU5) || defined(GSM_ENABLE_FBUS2BLUE) || defined(GSM_ENABLE_BLUEFBUS2) || defined(GSM_ENABLE_FBUS2PL2303) 306#if defined(GSM_ENABLE_FBUS2) || defined(GSM_ENABLE_FBUS2IRDA) || defined(GSM_ENABLE_FBUS2DLR3) || defined(GSM_ENABLE_FBUS2DKU5) || defined(GSM_ENABLE_FBUS2BLUE) || defined(GSM_ENABLE_BLUEFBUS2) || defined(GSM_ENABLE_FBUS2PL2303)
302 extern GSM_Protocol_Functions FBUS2Protocol; 307 extern GSM_Protocol_Functions FBUS2Protocol;
303#endif 308#endif
304#if defined(GSM_ENABLE_PHONETBLUE) || defined(GSM_ENABLE_IRDAPHONET) || defined(GSM_ENABLE_BLUEPHONET) 309#if defined(GSM_ENABLE_PHONETBLUE) || defined(GSM_ENABLE_IRDAPHONET) || defined(GSM_ENABLE_BLUEPHONET)
305 extern GSM_Protocol_Functions PHONETProtocol; 310 extern GSM_Protocol_Functions PHONETProtocol;
306#endif 311#endif
307#if defined(GSM_ENABLE_AT) || defined(GSM_ENABLE_BLUEAT) || defined(GSM_ENABLE_IRDAAT) 312#if defined(GSM_ENABLE_AT) || defined(GSM_ENABLE_BLUEAT) || defined(GSM_ENABLE_IRDAAT)
308 extern GSM_Protocol_Functions ATProtocol; 313 extern GSM_Protocol_Functions ATProtocol;
309#endif 314#endif
310#ifdef GSM_ENABLE_ALCABUS 315#ifdef GSM_ENABLE_ALCABUS
311 extern GSM_Protocol_Functions ALCABUSProtocol; 316 extern GSM_Protocol_Functions ALCABUSProtocol;
312#endif 317#endif
313#if defined(GSM_ENABLE_IRDAOBEX) || defined(GSM_ENABLE_BLUEOBEX) 318#if defined(GSM_ENABLE_IRDAOBEX) || defined(GSM_ENABLE_BLUEOBEX)
314 extern GSM_Protocol_Functions OBEXProtocol; 319 extern GSM_Protocol_Functions OBEXProtocol;
315#endif 320#endif
316#if defined(GSM_ENABLE_MROUTERBLUE) 321#if defined(GSM_ENABLE_MROUTERBLUE)
317 extern GSM_Protocol_Functions MROUTERProtocol; 322 extern GSM_Protocol_Functions MROUTERProtocol;
318#endif 323#endif
319 324
320/** 325/**
321 * Structure containing protocol specific data and pointer to protocol 326 * Structure containing protocol specific data and pointer to protocol
322 * functions - @ref GSM_Protocol_Functions. The data are in a structure, so 327 * functions - @ref GSM_Protocol_Functions. The data are in a structure, so
323 * you may use more protocols at once and switch between them. 328 * you may use more protocols at once and switch between them.
324 */ 329 */
325typedef struct { 330typedef struct {
326 struct { 331 struct {
327 char fake; 332 char fake;
328#ifdef GSM_ENABLE_MBUS2 333#ifdef GSM_ENABLE_MBUS2
329 GSM_Protocol_MBUS2Data MBUS2; 334 GSM_Protocol_MBUS2Data MBUS2;
330#endif 335#endif
331#if defined(GSM_ENABLE_FBUS2) || defined(GSM_ENABLE_FBUS2IRDA) || defined(GSM_ENABLE_FBUS2DLR3) || defined(GSM_ENABLE_FBUS2DKU5) || defined(GSM_ENABLE_FBUS2PL2303) || defined(GSM_ENABLE_FBUS2BLUE) || defined(GSM_ENABLE_BLUEFBUS2) 336#if defined(GSM_ENABLE_FBUS2) || defined(GSM_ENABLE_FBUS2IRDA) || defined(GSM_ENABLE_FBUS2DLR3) || defined(GSM_ENABLE_FBUS2DKU5) || defined(GSM_ENABLE_FBUS2PL2303) || defined(GSM_ENABLE_FBUS2BLUE) || defined(GSM_ENABLE_BLUEFBUS2)
332 GSM_Protocol_FBUS2Data FBUS2; 337 GSM_Protocol_FBUS2Data FBUS2;
333#endif 338#endif
334#if defined(GSM_ENABLE_PHONETBLUE) || defined(GSM_ENABLE_IRDAPHONET) || defined(GSM_ENABLE_BLUEPHONET) 339#if defined(GSM_ENABLE_PHONETBLUE) || defined(GSM_ENABLE_IRDAPHONET) || defined(GSM_ENABLE_BLUEPHONET)
335 GSM_Protocol_PHONETData PHONET; 340 GSM_Protocol_PHONETData PHONET;
336#endif 341#endif
337#if defined(GSM_ENABLE_AT) || defined(GSM_ENABLE_BLUEAT) || defined(GSM_ENABLE_IRDAAT) 342#if defined(GSM_ENABLE_AT) || defined(GSM_ENABLE_BLUEAT) || defined(GSM_ENABLE_IRDAAT)
338 GSM_Protocol_ATData AT; 343 GSM_Protocol_ATData AT;
339#endif 344#endif
340#ifdef GSM_ENABLE_ALCABUS 345#ifdef GSM_ENABLE_ALCABUS
341 GSM_Protocol_ALCABUSDataALCABUS; 346 GSM_Protocol_ALCABUSDataALCABUS;
342#endif 347#endif
343#if defined(GSM_ENABLE_IRDAOBEX) || defined(GSM_ENABLE_BLUEOBEX) 348#if defined(GSM_ENABLE_IRDAOBEX) || defined(GSM_ENABLE_BLUEOBEX)
344 GSM_Protocol_OBEXData OBEX; 349 GSM_Protocol_OBEXData OBEX;
345#endif 350#endif
346#if defined(GSM_ENABLE_MROUTERBLUE) 351#if defined(GSM_ENABLE_MROUTERBLUE)
347 GSM_Protocol_MROUTERDataMROUTER; 352 GSM_Protocol_MROUTERDataMROUTER;
348#endif 353#endif
349 } Data; 354 } Data;
350 GSM_Protocol_Functions *Functions; 355 GSM_Protocol_Functions *Functions;
351} GSM_Protocol; 356} GSM_Protocol;
352 357
353/* -------------------------- Phone layer ---------------------------------- */ 358/* -------------------------- Phone layer ---------------------------------- */
354 359
355/** 360/**
356 * Phone requests identificators, these are used for internally identifying 361 * Phone requests identificators, these are used for internally identifying
357 * which operation is being performed. 362 * which operation is being performed.
358 */ 363 */
359typedef enum { 364typedef enum {
360 ID_None=1, 365 ID_None=1,
361 ID_GetModel, 366 ID_GetModel,
362 ID_GetFirmware, 367 ID_GetFirmware,
363 ID_EnableSecurity, 368 ID_EnableSecurity,
364 ID_GetIMEI, 369 ID_GetIMEI,
365 ID_GetDateTime, 370 ID_GetDateTime,
366 ID_GetAlarm, 371 ID_GetAlarm,
367 ID_GetMemory, 372 ID_GetMemory,
368 ID_GetMemoryStatus, 373 ID_GetMemoryStatus,
369 ID_GetSMSC, 374 ID_GetSMSC,
370 ID_GetSMSMessage, 375 ID_GetSMSMessage,
371 ID_EnableEcho, 376 ID_EnableEcho,
372 ID_EnableErrorInfo, 377 ID_EnableErrorInfo,
373 ID_SetOBEX, 378 ID_SetOBEX,
379 ID_SetUSSD,
380 ID_GetNote,
374 ID_GetSignalQuality, 381 ID_GetSignalQuality,
375 ID_GetBatteryCharge, 382 ID_GetBatteryCharge,
376 ID_GetSMSFolders, 383 ID_GetSMSFolders,
377 ID_GetSMSFolderStatus, 384 ID_GetSMSFolderStatus,
378 ID_GetSMSStatus, 385 ID_GetSMSStatus,
379 ID_AddSMSFolder, 386 ID_AddSMSFolder,
380 ID_GetNetworkInfo, 387 ID_GetNetworkInfo,
381 ID_GetRingtone, 388 ID_GetRingtone,
382 ID_DialVoice, 389 ID_DialVoice,
383 ID_GetCalendarNotesInfo, 390 ID_GetCalendarNotesInfo,
384 ID_GetCalendarNote, 391 ID_GetCalendarNote,
385 ID_GetSecurityCode, 392 ID_GetSecurityCode,
386 ID_GetWAPBookmark, 393 ID_GetWAPBookmark,
387 ID_GetBitmap, 394 ID_GetBitmap,
388 ID_SaveSMSMessage, 395 ID_SaveSMSMessage,
389 ID_CancelCall, 396 ID_CancelCall,
390 ID_SetDateTime, 397 ID_SetDateTime,
391 ID_SetAlarm, 398 ID_SetAlarm,
392 ID_DisableConnectFunc, 399 ID_DisableConnectFunc,
393 ID_EnableConnectFunc, 400 ID_EnableConnectFunc,
394 ID_AnswerCall, 401 ID_AnswerCall,
395 ID_SetBitmap, 402 ID_SetBitmap,
396 ID_SetRingtone, 403 ID_SetRingtone,
397 ID_DeleteSMSMessage, 404 ID_DeleteSMSMessage,
398 ID_DeleteCalendarNote, 405 ID_DeleteCalendarNote,
399 ID_SetPath, 406 ID_SetPath,
400 ID_SetSMSC, 407 ID_SetSMSC,
401 ID_SetProfile, 408 ID_SetProfile,
402 ID_SetMemory, 409 ID_SetMemory,
403 ID_DeleteMemory, 410 ID_DeleteMemory,
404 ID_SetCalendarNote, 411 ID_SetCalendarNote,
405 ID_SetIncomingSMS, 412 ID_SetIncomingSMS,
406 ID_SetIncomingCB, 413 ID_SetIncomingCB,
407 ID_GetCalendarNotePos, 414 ID_GetCalendarNotePos,
408 ID_Initialise, 415 ID_Initialise,
409 ID_GetConnectSet, 416 ID_GetConnectSet,
410 ID_SetWAPBookmark, 417 ID_SetWAPBookmark,
411 ID_GetLocale, 418 ID_GetLocale,
412 ID_SetLocale, 419 ID_SetLocale,
413 ID_GetCalendarSettings, 420 ID_GetCalendarSettings,
414 ID_SetCalendarSettings, 421 ID_SetCalendarSettings,
415 ID_GetGPRSPoint, 422 ID_GetGPRSPoint,
416 ID_SetGPRSPoint, 423 ID_SetGPRSPoint,
417 ID_EnableGPRSPoint, 424 ID_EnableGPRSPoint,
418 ID_DeleteWAPBookmark, 425 ID_DeleteWAPBookmark,
419 ID_Netmonitor, 426 ID_Netmonitor,
420 ID_HoldCall, 427 ID_HoldCall,
421 ID_UnholdCall, 428 ID_UnholdCall,
422 ID_ConferenceCall, 429 ID_ConferenceCall,
423 ID_SplitCall, 430 ID_SplitCall,
424 ID_TransferCall, 431 ID_TransferCall,
425 ID_SwitchCall, 432 ID_SwitchCall,
426 ID_GetManufactureMonth, 433 ID_GetManufactureMonth,
427 ID_GetProductCode, 434 ID_GetProductCode,
428 ID_GetOriginalIMEI, 435 ID_GetOriginalIMEI,
429 ID_GetHardware, 436 ID_GetHardware,
430 ID_GetPPM, 437 ID_GetPPM,
431 ID_GetSMSMode, 438 ID_GetSMSMode,
432 ID_GetSMSMemories, 439 ID_GetSMSMemories,
433 ID_GetManufacturer, 440 ID_GetManufacturer,
434 ID_SetMemoryType, 441 ID_SetMemoryType,
435 ID_SetMemoryCharset, 442 ID_SetMemoryCharset,
436 ID_GetMMSSettings, 443 ID_GetMMSSettings,
437 ID_SetSMSParameters, 444 ID_SetSMSParameters,
438 ID_GetFMStation, 445 ID_GetFMStation,
439 ID_SetFMStation, 446 ID_SetFMStation,
440 ID_GetLanguage, 447 ID_GetLanguage,
448 ID_SetFastSMSSending,
441 ID_Reset, 449 ID_Reset,
442 ID_GetToDo, 450 ID_GetToDo,
443 ID_PressKey, 451 ID_PressKey,
444 ID_DeleteAllToDo, 452 ID_DeleteAllToDo,
445 ID_SetLight, 453 ID_SetLight,
446 ID_Divert, 454 ID_Divert,
447 ID_SetToDo, 455 ID_SetToDo,
448 ID_PlayTone, 456 ID_PlayTone,
449 ID_GetChatSettings, 457 ID_GetChatSettings,
450 ID_GetSyncMLSettings, 458 ID_GetSyncMLSettings,
451 ID_GetSyncMLName, 459 ID_GetSyncMLName,
452 ID_GetSecurityStatus, 460 ID_GetSecurityStatus,
453 ID_EnterSecurityCode, 461 ID_EnterSecurityCode,
454 ID_GetProfile, 462 ID_GetProfile,
455 ID_GetRingtonesInfo, 463 ID_GetRingtonesInfo,
456 ID_MakeAuthentication, 464 ID_MakeAuthentication,
457 ID_GetSpeedDial, 465 ID_GetSpeedDial,
458 ID_ResetPhoneSettings, 466 ID_ResetPhoneSettings,
459 ID_SendDTMF, 467 ID_SendDTMF,
460 ID_GetDisplayStatus, 468 ID_GetDisplayStatus,
461 ID_SetAutoNetworkLogin, 469 ID_SetAutoNetworkLogin,
462 ID_SetConnectSet, 470 ID_SetConnectSet,
463 ID_SetMMSSettings, 471 ID_SetMMSSettings,
464 ID_GetSIMIMSI, 472 ID_GetSIMIMSI,
465 ID_GetFileInfo, 473 ID_GetFileInfo,
466 ID_FileSystemStatus, 474 ID_FileSystemStatus,
467 ID_GetFile, 475 ID_GetFile,
468 ID_AddFile, 476 ID_AddFile,
469 ID_AddFolder, 477 ID_AddFolder,
470 ID_DeleteFile, 478 ID_DeleteFile,
471#ifdef GSM_ENABLE_ALCATEL 479#ifdef GSM_ENABLE_ALCATEL
472 /* AT mode */ 480 /* AT mode */
473 ID_SetFlowControl, 481 ID_SetFlowControl,
474 ID_AlcatelConnect, 482 ID_AlcatelConnect,
475 ID_AlcatelProtocol, 483 ID_AlcatelProtocol,
476 484
477 /* Binary mode */ 485 /* Binary mode */
478 ID_AlcatelAttach, 486 ID_AlcatelAttach,
479 ID_AlcatelDetach, 487 ID_AlcatelDetach,
480 ID_AlcatelCommit, 488 ID_AlcatelCommit,
481 ID_AlcatelCommit2, 489 ID_AlcatelCommit2,
482 ID_AlcatelEnd, 490 ID_AlcatelEnd,
483 ID_AlcatelClose, 491 ID_AlcatelClose,
484 ID_AlcatelStart, 492 ID_AlcatelStart,
485 ID_AlcatelSelect1, 493 ID_AlcatelSelect1,
486 ID_AlcatelSelect2, 494 ID_AlcatelSelect2,
487 ID_AlcatelSelect3, 495 ID_AlcatelSelect3,
488 ID_AlcatelBegin1, 496 ID_AlcatelBegin1,
489 ID_AlcatelBegin2, 497 ID_AlcatelBegin2,
490 ID_AlcatelGetIds1, 498 ID_AlcatelGetIds1,
491 ID_AlcatelGetIds2, 499 ID_AlcatelGetIds2,
492 ID_AlcatelGetCategories1, 500 ID_AlcatelGetCategories1,
493 ID_AlcatelGetCategories2, 501 ID_AlcatelGetCategories2,
494 ID_AlcatelGetCategoryText1, 502 ID_AlcatelGetCategoryText1,
495 ID_AlcatelGetCategoryText2, 503 ID_AlcatelGetCategoryText2,
496 ID_AlcatelAddCategoryText1, 504 ID_AlcatelAddCategoryText1,
497 ID_AlcatelAddCategoryText2, 505 ID_AlcatelAddCategoryText2,
498 ID_AlcatelGetFields1, 506 ID_AlcatelGetFields1,
499 ID_AlcatelGetFields2, 507 ID_AlcatelGetFields2,
500 ID_AlcatelGetFieldValue1, 508 ID_AlcatelGetFieldValue1,
501 ID_AlcatelGetFieldValue2, 509 ID_AlcatelGetFieldValue2,
502 ID_AlcatelDeleteItem1, 510 ID_AlcatelDeleteItem1,
503 ID_AlcatelDeleteItem2, 511 ID_AlcatelDeleteItem2,
504 ID_AlcatelDeleteField, 512 ID_AlcatelDeleteField,
505 ID_AlcatelCreateField, 513 ID_AlcatelCreateField,
506 ID_AlcatelUpdateField, 514 ID_AlcatelUpdateField,
507#endif 515#endif
508 ID_IncomingFrame, 516 ID_IncomingFrame,
509 517
510 ID_User1, 518 ID_User1,
511 ID_User2, 519 ID_User2,
512 ID_User3, 520 ID_User3,
513 ID_User4, 521 ID_User4,
514 ID_User5, 522 ID_User5,
515 ID_User6, 523 ID_User6,
516 ID_User7, 524 ID_User7,
517 ID_User8, 525 ID_User8,
518 ID_User9, 526 ID_User9,
519 ID_User10, 527 ID_User10,
520 528
521 ID_EachFrame 529 ID_EachFrame
522} GSM_Phone_RequestID; 530} GSM_Phone_RequestID;
523 531
524/** 532/**
525 * Phone related data are stored here. 533 * Phone related data are stored here.
526 */ 534 */
527typedef struct { 535typedef struct {
528 /** 536 /**
529 * Phone IMEI (or serial number). 537 * Phone IMEI (or serial number).
530 */ 538 */
531 char IMEI[MAX_IMEI_LENGTH]; 539 char IMEI[MAX_IMEI_LENGTH];
532 /** 540 /**
533 * Phone manufacturer as reported by phone. 541 * Phone manufacturer as reported by phone.
534 */ 542 */
535 char Manufacturer[MAX_MANUFACTURER_LENGTH]; 543 char Manufacturer[MAX_MANUFACTURER_LENGTH];
536 /** 544 /**
537 * Phone model as reported by phone. 545 * Phone model as reported by phone.
538 */ 546 */
539 char Model[MAX_MODEL_LENGTH]; 547 char Model[MAX_MODEL_LENGTH];
540 /** 548 /**
541 * Model information, pointer to static @ref allmodels array. 549 * Model information, pointer to static @ref allmodels array.
542 */ 550 */
543 OnePhoneModel *ModelInfo; 551 OnePhoneModel *ModelInfo;
544 /** 552 /**
545 * Phone version as reported by phone. It doesn't have to be numerical 553 * Phone version as reported by phone. It doesn't have to be numerical
546 * at all. 554 * at all.
547 */ 555 */
548 char Version[MAX_VERSION_LENGTH]; 556 char Version[MAX_VERSION_LENGTH];
549 /** 557 /**
550 * Phone version date, might be empty for some models. 558 * Phone version date, might be empty for some models.
551 */ 559 */
552 char VerDate[MAX_VERSION_DATE_LENGTH]; 560 char VerDate[MAX_VERSION_DATE_LENGTH];
553 /** 561 /**
554 * Phone version as number, if applicable. 562 * Phone version as number, if applicable.
555 */ 563 */
556 double VerNum; 564 double VerNum;
557 /** 565 /**
558 * Cache for hardware version used by some modules. 566 * Cache for hardware version used by some modules.
559 */ 567 */
560 char HardwareCache[50]; 568 char HardwareCache[50];
561 /** 569 /**
562 * Cache for product code version used by some modules. 570 * Cache for product code version used by some modules.
563 */ 571 */
564 char ProductCodeCache[50]; 572 char ProductCodeCache[50];
565 573
566 /** 574 /**
567 * Counter used for disabling startup info on phone, see 575 * Counter used for disabling startup info on phone, see
568 * @ref GSM_Phone_Functions::ShowStartInfo . After this is 0, the startup info is hidden. 576 * @ref GSM_Phone_Functions::ShowStartInfo . After this is 0, the startup info is hidden.
569 */ 577 */
570 int StartInfoCounter; 578 int StartInfoCounter;
571 579
572 /** 580 /**
573 * Pointer to structure used internally by phone drivers. 581 * Pointer to structure used internally by phone drivers.
574 */ 582 */
575 GSM_GPRSAccessPoint*GPRSPoint; 583 GSM_GPRSAccessPoint*GPRSPoint;
576 /** 584 /**
577 * Pointer to structure used internally by phone drivers. 585 * Pointer to structure used internally by phone drivers.
578 */ 586 */
579 GSM_SpeedDial *SpeedDial; 587 GSM_SpeedDial *SpeedDial;
580 /** 588 /**
581 * Pointer to structure used internally by phone drivers. 589 * Pointer to structure used internally by phone drivers.
582 */ 590 */
583 GSM_DateTime *DateTime; 591 GSM_DateTime *DateTime;
584 /** 592 /**
585 * Pointer to structure used internally by phone drivers. 593 * Pointer to structure used internally by phone drivers.
586 */ 594 */
587 GSM_Alarm *Alarm; 595 GSM_Alarm *Alarm;
588 /** 596 /**
589 * Pointer to structure used internally by phone drivers. 597 * Pointer to structure used internally by phone drivers.
590 */ 598 */
591 GSM_MemoryEntry *Memory; 599 GSM_MemoryEntry *Memory;
592 /** 600 /**
593 * Pointer to structure used internally by phone drivers. 601 * Pointer to structure used internally by phone drivers.
594 */ 602 */
595 GSM_MemoryStatus*MemoryStatus; 603 GSM_MemoryStatus*MemoryStatus;
596 /** 604 /**
597 * Pointer to structure used internally by phone drivers. 605 * Pointer to structure used internally by phone drivers.
598 */ 606 */
599 GSM_SMSC *SMSC; 607 GSM_SMSC *SMSC;
600 /** 608 /**
601 * Pointer to structure used internally by phone drivers. 609 * Pointer to structure used internally by phone drivers.
602 */ 610 */
603 GSM_MultiSMSMessage*GetSMSMessage; 611 GSM_MultiSMSMessage*GetSMSMessage;
604 /** 612 /**
605 * Pointer to structure used internally by phone drivers. 613 * Pointer to structure used internally by phone drivers.
606 */ 614 */
607 GSM_SMSMessage *SaveSMSMessage; 615 GSM_SMSMessage *SaveSMSMessage;
608 /** 616 /**
609 * Pointer to structure used internally by phone drivers. 617 * Pointer to structure used internally by phone drivers.
610 */ 618 */
611 GSM_SMSMemoryStatus*SMSStatus; 619 GSM_SMSMemoryStatus*SMSStatus;
612 /** 620 /**
613 * Pointer to structure used internally by phone drivers. 621 * Pointer to structure used internally by phone drivers.
614 */ 622 */
615 GSM_SMSFolders *SMSFolders; 623 GSM_SMSFolders *SMSFolders;
616 /** 624 /**
617 * Used internally by phone drivers. 625 * Used internally by phone drivers.
618 */ 626 */
619 int *VoiceRecord; 627 int *VoiceRecord;
620 /** 628 /**
621 * Used internally by phone drivers. 629 * Used internally by phone drivers.
622 */ 630 */
623 int CallID; 631 int CallID;
624 /** 632 /**
625 * Pointer to structure used internally by phone drivers. 633 * Pointer to structure used internally by phone drivers.
626 */ 634 */
627 GSM_SignalQuality*SignalQuality; 635 GSM_SignalQuality*SignalQuality;
628 /** 636 /**
629 * Pointer to structure used internally by phone drivers. 637 * Pointer to structure used internally by phone drivers.
630 */ 638 */
631 GSM_BatteryCharge*BatteryCharge; 639 GSM_BatteryCharge*BatteryCharge;
632 /** 640 /**
633 * Pointer to structure used internally by phone drivers. 641 * Pointer to structure used internally by phone drivers.
634 */ 642 */
635 GSM_NetworkInfo *NetworkInfo; 643 GSM_NetworkInfo *NetworkInfo;
636 /** 644 /**
637 * Pointer to structure used internally by phone drivers. 645 * Pointer to structure used internally by phone drivers.
638 */ 646 */
639 GSM_Ringtone *Ringtone; 647 GSM_Ringtone *Ringtone;
640 /** 648 /**
641 * Pointer to structure used internally by phone drivers. 649 * Pointer to structure used internally by phone drivers.
642 */ 650 */
643 GSM_CalendarEntry*Cal; 651 GSM_CalendarEntry*Cal;
644 /** 652 /**
645 * Used internally by phone drivers. 653 * Used internally by phone drivers.
646 */ 654 */
647 unsigned char *SecurityCode; 655 unsigned char *SecurityCode;
648 /** 656 /**
649 * Pointer to structure used internally by phone drivers. 657 * Pointer to structure used internally by phone drivers.
650 */ 658 */
651 GSM_WAPBookmark *WAPBookmark; 659 GSM_WAPBookmark *WAPBookmark;
652 /** 660 /**
653 * Pointer to structure used internally by phone drivers. 661 * Pointer to structure used internally by phone drivers.
654 */ 662 */
655 GSM_MultiWAPSettings*WAPSettings; 663 GSM_MultiWAPSettings*WAPSettings;
656 /** 664 /**
657 * Pointer to structure used internally by phone drivers. 665 * Pointer to structure used internally by phone drivers.
658 */ 666 */
659 GSM_Bitmap *Bitmap; 667 GSM_Bitmap *Bitmap;
660 /** 668 /**
661 * Used internally by phone drivers. 669 * Used internally by phone drivers.
662 */ 670 */
663 unsigned char *Netmonitor; 671 unsigned char *Netmonitor;
664 /** 672 /**
665 * Pointer to structure used internally by phone drivers. 673 * Pointer to structure used internally by phone drivers.
666 */ 674 */
667 GSM_MultiCallDivert*Divert; 675 GSM_MultiCallDivert*Divert;
668 /** 676 /**
669 * Pointer to structure used internally by phone drivers. 677 * Pointer to structure used internally by phone drivers.
670 */ 678 */
671 GSM_ToDoEntry *ToDo; 679 GSM_ToDoEntry *ToDo;
680 GSM_NoteEntry *Note;
672 /** 681 /**
673 * Used internally by phone drivers. 682 * Used internally by phone drivers.
674 */ 683 */
675 bool PressKey; 684 bool PressKey;
676 /** 685 /**
677 * Pointer to structure used internally by phone drivers. 686 * Pointer to structure used internally by phone drivers.
678 */ 687 */
679 GSM_SecurityCodeType*SecurityStatus; 688 GSM_SecurityCodeType*SecurityStatus;
680 /** 689 /**
681 * Pointer to structure used internally by phone drivers. 690 * Pointer to structure used internally by phone drivers.
682 */ 691 */
683 GSM_Profile *Profile; 692 GSM_Profile *Profile;
684 /** 693 /**
685 * Pointer to structure used internally by phone drivers. 694 * Pointer to structure used internally by phone drivers.
686 */ 695 */
687 GSM_AllRingtonesInfo*RingtonesInfo; 696 GSM_AllRingtonesInfo*RingtonesInfo;
688 /** 697 /**
689 * Pointer to structure used internally by phone drivers. 698 * Pointer to structure used internally by phone drivers.
690 */ 699 */
691 GSM_DisplayFeatures*DisplayFeatures; 700 GSM_DisplayFeatures*DisplayFeatures;
692 /** 701 /**
693 * Pointer to structure used internally by phone drivers. 702 * Pointer to structure used internally by phone drivers.
694 */ 703 */
695 GSM_FMStation *FMStation; 704 GSM_FMStation *FMStation;
696 /** 705 /**
697 * Pointer to structure used internally by phone drivers. 706 * Pointer to structure used internally by phone drivers.
698 */ 707 */
699 GSM_Locale *Locale; 708 GSM_Locale *Locale;
700 /** 709 /**
701 * Pointer to structure used internally by phone drivers. 710 * Pointer to structure used internally by phone drivers.
702 */ 711 */
703 GSM_CalendarSettings*CalendarSettings; 712 GSM_CalendarSettings*CalendarSettings;
704 /** 713 /**
705 * Used internally by phone drivers. 714 * Used internally by phone drivers.
706 */ 715 */
707 unsigned char *PhoneString; 716 unsigned char *PhoneString;
708 /** 717 /**
709 * Used internally by phone drivers. 718 * Used internally by phone drivers.
710 */ 719 */
711 int StartPhoneString; 720 int StartPhoneString;
712 /** 721 /**
713 * Pointer to structure used internally by phone drivers. 722 * Pointer to structure used internally by phone drivers.
714 */ 723 */
715 GSM_File *FileInfo; 724 GSM_File *FileInfo;
716 /** 725 /**
717 * Pointer to structure used internally by phone drivers. 726 * Pointer to structure used internally by phone drivers.
718 */ 727 */
719 GSM_File *File; 728 GSM_File *File;
720 /** 729 /**
721 * Pointer to structure used internally by phone drivers. 730 * Pointer to structure used internally by phone drivers.
722 */ 731 */
723 GSM_FileSystemStatus*FileSystemStatus; 732 GSM_FileSystemStatus*FileSystemStatus;
724 GSM_ChatSettings*ChatSettings; 733 GSM_ChatSettings*ChatSettings;
725 GSM_SyncMLSettings*SyncMLSettings; 734 GSM_SyncMLSettings*SyncMLSettings;
726 735
727 /** 736 /**
728 * Should phone notify about incoming calls? 737 * Should phone notify about incoming calls?
729 */ 738 */
730 bool EnableIncomingCall; 739 bool EnableIncomingCall;
731 /** 740 /**
732 * Should phone notify about incoming SMSes? 741 * Should phone notify about incoming SMSes?
733 */ 742 */
734 bool EnableIncomingSMS; 743 bool EnableIncomingSMS;
735 /** 744 /**
736 * Should phone notify about incoming CBs? 745 * Should phone notify about incoming CBs?
737 */ 746 */
738 bool EnableIncomingCB; 747 bool EnableIncomingCB;
739 /** 748 /**
740 * Should phone notify about incoming USSDs? 749 * Should phone notify about incoming USSDs?
741 */ 750 */
742 bool EnableIncomingUSSD; 751 bool EnableIncomingUSSD;
743 752
744 /** 753 /**
745 * Last message received from phone. 754 * Last message received from phone.
746 */ 755 */
747 GSM_Protocol_Message*RequestMsg; 756 GSM_Protocol_Message*RequestMsg;
748 /** 757 /**
749 * Last message sent by Gammu. 758 * Last message sent by Gammu.
750 */ 759 */
751 GSM_Protocol_Message*SentMsg; 760 GSM_Protocol_Message*SentMsg;
752 /** 761 /**
753 * What operation is being performed now, see @ref GSM_Phone_RequestID 762 * What operation is being performed now, see @ref GSM_Phone_RequestID
754 * for possible values. 763 * for possible values.
755 */ 764 */
756 GSM_Phone_RequestIDRequestID; 765 GSM_Phone_RequestIDRequestID;
757 /** 766 /**
758 * Error returned by function in phone module. 767 * Error returned by function in phone module.
759 */ 768 */
760 GSM_Error DispatchError; 769 GSM_Error DispatchError;
761 770
762 /** 771 /**
763 * Structure with private phone modules data. 772 * Structure with private phone modules data.
764 */ 773 */
765 struct { 774 struct {
766 int fake; 775 int fake;
767#ifdef GSM_ENABLE_NOKIA3320 776#ifdef GSM_ENABLE_NOKIA3320
768 GSM_Phone_N3320Data N3320; 777 GSM_Phone_N3320Data N3320;
769#endif 778#endif
770#ifdef GSM_ENABLE_NOKIA3650 779#ifdef GSM_ENABLE_NOKIA3650
771 GSM_Phone_N3650Data N3650; 780 GSM_Phone_N3650Data N3650;
772#endif 781#endif
782#ifdef GSM_ENABLE_NOKIA650
783 GSM_Phone_N650Data N650;
784#endif
773#ifdef GSM_ENABLE_NOKIA6110 785#ifdef GSM_ENABLE_NOKIA6110
774 GSM_Phone_N6110Data N6110; 786 GSM_Phone_N6110Data N6110;
775#endif 787#endif
776#ifdef GSM_ENABLE_NOKIA6510 788#ifdef GSM_ENABLE_NOKIA6510
777 GSM_Phone_N6510Data N6510; 789 GSM_Phone_N6510Data N6510;
778#endif 790#endif
779#ifdef GSM_ENABLE_NOKIA7110 791#ifdef GSM_ENABLE_NOKIA7110
780 GSM_Phone_N7110Data N7110; 792 GSM_Phone_N7110Data N7110;
781#endif 793#endif
782#ifdef GSM_ENABLE_ATGEN 794#ifdef GSM_ENABLE_ATGEN
783 GSM_Phone_ATGENData ATGEN; 795 GSM_Phone_ATGENData ATGEN;
784#endif 796#endif
785#ifdef GSM_ENABLE_ALCATEL 797#ifdef GSM_ENABLE_ALCATEL
786 GSM_Phone_ALCATELData ALCATEL; 798 GSM_Phone_ALCATELData ALCATEL;
787#endif 799#endif
788#ifdef GSM_ENABLE_OBEXGEN 800#ifdef GSM_ENABLE_OBEXGEN
789 GSM_Phone_OBEXGENData OBEXGEN; 801 GSM_Phone_OBEXGENData OBEXGEN;
790#endif 802#endif
791#ifdef GSM_ENABLE_MROUTERGEN 803#ifdef GSM_ENABLE_MROUTERGEN
792 GSM_Phone_MROUTERGENData MROUTERGEN; 804 GSM_Phone_MROUTERGENData MROUTERGEN;
793#endif 805#endif
794 } Priv; 806 } Priv;
795} GSM_Phone_Data; 807} GSM_Phone_Data;
796 808
797/** 809/**
798 * Structure for defining reply functions. 810 * Structure for defining reply functions.
799 * 811 *
800 * Function is called when requestID matches current operation or is 812 * Function is called when requestID matches current operation or is
801 * ID_IncomingFrame and msgtype matches start message and (if msgtype is just 813 * ID_IncomingFrame and msgtype matches start message and (if msgtype is just
802 * one character) subtypechar is zero or subtypechar-th character of message 814 * one character) subtypechar is zero or subtypechar-th character of message
803 * matches subtype. 815 * matches subtype.
804 * 816 *
805 * Should be used in array with last element containing ID_None as requestID. 817 * Should be used in array with last element containing ID_None as requestID.
806 */ 818 */
807typedef struct { 819struct _GSM_Reply_Function {
808 /** 820 /**
809 * Pointer to function that should be executed. 821 * Pointer to function that should be executed.
810 */ 822 */
811 GSM_Error (*Function)(GSM_Protocol_Message msg, GSM_StateMachine *s); 823 GSM_Error (*Function)(GSM_Protocol_Message msg, GSM_StateMachine *s);
812 /** 824 /**
813 * Message type, if it is longer than 1 character, it disables subtype 825 * Message type, if it is longer than 1 character, it disables subtype
814 * checking. 826 * checking.
815 */ 827 */
816 unsigned char *msgtype; 828 unsigned char *msgtype;
817 /** 829 /**
818 * Which character of message should be checked as subtype. Zero to 830 * Which character of message should be checked as subtype. Zero to
819 * disable subtype checking. 831 * disable subtype checking.
820 */ 832 */
821 int subtypechar; 833 int subtypechar;
822 /** 834 /**
823 * Subtype to be checked. 835 * Subtype to be checked.
824 */ 836 */
825 unsigned char subtype; 837 unsigned char subtype;
826 /** 838 /**
827 * Phone request when this can be called, use ID_IncomingFrame when 839 * Phone request when this can be called, use ID_IncomingFrame when
828 * you want to use this in any state. 840 * you want to use this in any state.
829 */ 841 */
830 GSM_Phone_RequestIDrequestID; 842 GSM_Phone_RequestIDrequestID;
831} GSM_Reply_Function; 843};
832 844
833/** 845/**
834 * Structure defining phone functions. 846 * Structure defining phone functions.
835 */ 847 */
836typedef struct { 848typedef struct {
837 /** 849 /**
838 * Names of supported models separated by |. Must contain at least one 850 * Names of supported models separated by |. Must contain at least one
839 * name. 851 * name.
840 */ 852 */
841 char *models; 853 char *models;
842 /** 854 /**
843 * Array of reply functions for the phone, see 855 * Array of reply functions for the phone, see
844 * @ref GSM_Reply_Function for details about it. 856 * @ref GSM_Reply_Function for details about it.
845 */ 857 */
846 GSM_Reply_Function *ReplyFunctions; 858 GSM_Reply_Function *ReplyFunctions;
847 /** 859 /**
848 * Initializes phone. 860 * Initializes phone.
849 */ 861 */
850 GSM_Error (*Initialise) (GSM_StateMachine *s); 862 GSM_Error (*Initialise) (GSM_StateMachine *s);
851 /** 863 /**
852 * Terminates phone communication. 864 * Terminates phone communication.
853 */ 865 */
854 GSM_Error (*Terminate) (GSM_StateMachine *s); 866 GSM_Error (*Terminate) (GSM_StateMachine *s);
855 /** 867 /**
856 * Dispatches messages from phone, at the end it should call 868 * Dispatches messages from phone, at the end it should call
857 * @ref GSM_DispatchMessage. 869 * @ref GSM_DispatchMessage.
858 */ 870 */
859 GSM_Error (*DispatchMessage) (GSM_StateMachine *s); 871 GSM_Error (*DispatchMessage) (GSM_StateMachine *s);
860 /** 872 /**
861 * Enables showing information on phone display. 873 * Enables showing information on phone display.
862 */ 874 */
863 GSM_Error (*ShowStartInfo) (GSM_StateMachine *s, bool enable); 875 GSM_Error (*ShowStartInfo) (GSM_StateMachine *s, bool enable);
864 /** 876 /**
865 * Reads manufacturer from phone. 877 * Reads manufacturer from phone.
866 */ 878 */
867 GSM_Error (*GetManufacturer) (GSM_StateMachine *s); 879 GSM_Error (*GetManufacturer) (GSM_StateMachine *s);
868 /** 880 /**
869 * Reads model from phone. 881 * Reads model from phone.
870 */ 882 */
871 GSM_Error (*GetModel) (GSM_StateMachine *s); 883 GSM_Error (*GetModel) (GSM_StateMachine *s);
872 /** 884 /**
873 * Reads firmware information from phone. 885 * Reads firmware information from phone.
874 */ 886 */
875 GSM_Error (*GetFirmware)(GSM_StateMachine *s); 887 GSM_Error (*GetFirmware)(GSM_StateMachine *s);
876 /** 888 /**
877 * Reads IMEI/serial number from phone. 889 * Reads IMEI/serial number from phone.
878 */ 890 */
879 GSM_Error (*GetIMEI) (GSM_StateMachine *s); 891 GSM_Error (*GetIMEI) (GSM_StateMachine *s);
880 /** 892 /**
881 * Gets date and time from phone. 893 * Gets date and time from phone.
882 */ 894 */
883 GSM_Error (*GetOriginalIMEI) (GSM_StateMachine *s, char *value); 895 GSM_Error (*GetOriginalIMEI) (GSM_StateMachine *s, char *value);
884 /** 896 /**
885 * Gets month when device was manufactured. 897 * Gets month when device was manufactured.
886 */ 898 */
887 GSM_Error (*GetManufactureMonth)(GSM_StateMachine *s, char *value); 899 GSM_Error (*GetManufactureMonth)(GSM_StateMachine *s, char *value);
888 /** 900 /**
889 * Gets product code of device. 901 * Gets product code of device.
890 */ 902 */
891 GSM_Error (*GetProductCode) (GSM_StateMachine *s, char *value); 903 GSM_Error (*GetProductCode) (GSM_StateMachine *s, char *value);
892 /** 904 /**
893 * Gets hardware information about device. 905 * Gets hardware information about device.
894 */ 906 */
895 GSM_Error (*GetHardware)(GSM_StateMachine *s, char *value); 907 GSM_Error (*GetHardware)(GSM_StateMachine *s, char *value);
896 /** 908 /**
897 * Gets PPM (Post Programmable Memory) info from phone 909 * Gets PPM (Post Programmable Memory) info from phone
898 * (in other words for Nokia get, which language pack is in phone) 910 * (in other words for Nokia get, which language pack is in phone)
899 */ 911 */
900 GSM_Error (*GetPPM) (GSM_StateMachine *s, char *value); 912 GSM_Error (*GetPPM) (GSM_StateMachine *s, char *value);
901 /** 913 /**
902 * Gets SIM IMSI from phone. 914 * Gets SIM IMSI from phone.
903 */ 915 */
904 GSM_Error (*GetSIMIMSI) (GSM_StateMachine *s, char *IMSI); 916 GSM_Error (*GetSIMIMSI) (GSM_StateMachine *s, char *IMSI);
905 /** 917 /**
906 * Reads date and time from phone. 918 * Reads date and time from phone.
907 */ 919 */
908 GSM_Error (*GetDateTime)(GSM_StateMachine *s, GSM_DateTime *date_time); 920 GSM_Error (*GetDateTime)(GSM_StateMachine *s, GSM_DateTime *date_time);
909 /** 921 /**
910 * Sets date and time in phone. 922 * Sets date and time in phone.
911 */ 923 */
912 GSM_Error (*SetDateTime)(GSM_StateMachine *s, GSM_DateTime *date_time); 924 GSM_Error (*SetDateTime)(GSM_StateMachine *s, GSM_DateTime *date_time);
913 /** 925 /**
914 * Reads alarm set in phone. 926 * Reads alarm set in phone.
915 */ 927 */
916 GSM_Error (*GetAlarm) (GSM_StateMachine *s, GSM_Alarm*alarm); 928 GSM_Error (*GetAlarm) (GSM_StateMachine *s, GSM_Alarm*alarm);
917 /** 929 /**
918 * Sets alarm in phone. 930 * Sets alarm in phone.
919 */ 931 */
920 GSM_Error (*SetAlarm) (GSM_StateMachine *s, GSM_Alarm *alarm); 932 GSM_Error (*SetAlarm) (GSM_StateMachine *s, GSM_Alarm *alarm);
921 /** 933 /**
922 * Gets locale from phone. 934 * Gets locale from phone.
923 */ 935 */
924 GSM_Error (*GetLocale) (GSM_StateMachine *s, GSM_Locale *locale); 936 GSM_Error (*GetLocale) (GSM_StateMachine *s, GSM_Locale *locale);
925 /** 937 /**
926 * Sets locale of phone. 938 * Sets locale of phone.
927 */ 939 */
928 GSM_Error (*SetLocale) (GSM_StateMachine *s, GSM_Locale *locale); 940 GSM_Error (*SetLocale) (GSM_StateMachine *s, GSM_Locale *locale);
929 /** 941 /**
930 * Emulates key press or key release. 942 * Emulates key press or key release.
931 */ 943 */
932 GSM_Error (*PressKey) (GSM_StateMachine *s, GSM_KeyCode Key, bool Press); 944 GSM_Error (*PressKey) (GSM_StateMachine *s, GSM_KeyCode Key, bool Press);
933 /** 945 /**
934 * Performs phone reset. 946 * Performs phone reset.
935 */ 947 */
936 GSM_Error (*Reset) (GSM_StateMachine *s, bool hard); 948 GSM_Error (*Reset) (GSM_StateMachine *s, bool hard);
937 /** 949 /**
938 * Resets phone settings. 950 * Resets phone settings.
939 */ 951 */
940 GSM_Error (*ResetPhoneSettings) (GSM_StateMachine *s, GSM_ResetSettingsType Type); 952 GSM_Error (*ResetPhoneSettings) (GSM_StateMachine *s, GSM_ResetSettingsType Type);
941 /** 953 /**
942 * Enters security code (PIN, PUK,...) . 954 * Enters security code (PIN, PUK,...) .
943 */ 955 */
944 GSM_Error (*EnterSecurityCode) (GSM_StateMachine *s, GSM_SecurityCode Code); 956 GSM_Error (*EnterSecurityCode) (GSM_StateMachine *s, GSM_SecurityCode Code);
945 /** 957 /**
946 * Queries whether some security code needs to be entered./ 958 * Queries whether some security code needs to be entered./
947 */ 959 */
948 GSM_Error (*GetSecurityStatus) (GSM_StateMachine *s, GSM_SecurityCodeType *Status); 960 GSM_Error (*GetSecurityStatus) (GSM_StateMachine *s, GSM_SecurityCodeType *Status);
949 /** 961 /**
950 * Acquired display status. 962 * Acquired display status.
951 */ 963 */
952 GSM_Error (*GetDisplayStatus) (GSM_StateMachine *s, GSM_DisplayFeatures *features); 964 GSM_Error (*GetDisplayStatus) (GSM_StateMachine *s, GSM_DisplayFeatures *features);
953 /** 965 /**
954 * Enables network auto login. 966 * Enables network auto login.
955 */ 967 */
956 GSM_Error (*SetAutoNetworkLogin)(GSM_StateMachine *s); 968 GSM_Error (*SetAutoNetworkLogin)(GSM_StateMachine *s);
957 /** 969 /**
958 * Gets information about batery charge and phone charging state. 970 * Gets information about batery charge and phone charging state.
959 */ 971 */
960 GSM_Error (*GetBatteryCharge) (GSM_StateMachine *s, GSM_BatteryCharge *bat); 972 GSM_Error (*GetBatteryCharge) (GSM_StateMachine *s, GSM_BatteryCharge *bat);
961 /** 973 /**
962 * Reads signal quality (strength and error rate). 974 * Reads signal quality (strength and error rate).
963 */ 975 */
964 GSM_Error (*GetSignalQuality) (GSM_StateMachine *s, GSM_SignalQuality *sig); 976 GSM_Error (*GetSignalQuality) (GSM_StateMachine *s, GSM_SignalQuality *sig);
965 /** 977 /**
966 * Gets network information. 978 * Gets network information.
967 */ 979 */
968 GSM_Error (*GetNetworkInfo) (GSM_StateMachine *s, GSM_NetworkInfo *netinfo); 980 GSM_Error (*GetNetworkInfo) (GSM_StateMachine *s, GSM_NetworkInfo *netinfo);
969 /** 981 /**
970 * Reads category from phone. 982 * Reads category from phone.
971 */ 983 */
972 GSM_Error (*GetCategory)(GSM_StateMachine *s, GSM_Category *Category); 984 GSM_Error (*GetCategory)(GSM_StateMachine *s, GSM_Category *Category);
973 /** 985 /**
974 * Adds category to phone. 986 * Adds category to phone.
975 */ 987 */
976 GSM_Error (*AddCategory)(GSM_StateMachine *s, GSM_Category *Category); 988 GSM_Error (*AddCategory)(GSM_StateMachine *s, GSM_Category *Category);
977 /** 989 /**
978 * Reads category status (number of used entries) from phone. 990 * Reads category status (number of used entries) from phone.
979 */ 991 */
980 GSM_Error (*GetCategoryStatus) (GSM_StateMachine *s, GSM_CategoryStatus *Status); 992 GSM_Error (*GetCategoryStatus) (GSM_StateMachine *s, GSM_CategoryStatus *Status);
981 /** 993 /**
982 * Gets memory (phonebooks or calls) status (eg. number of used and 994 * Gets memory (phonebooks or calls) status (eg. number of used and
983 * free entries). 995 * free entries).
984 */ 996 */
985 GSM_Error (*GetMemoryStatus) (GSM_StateMachine *s, GSM_MemoryStatus *status); 997 GSM_Error (*GetMemoryStatus) (GSM_StateMachine *s, GSM_MemoryStatus *status);
986 /** 998 /**
987 * Reads entry from memory (phonebooks or calls). Which entry should 999 * Reads entry from memory (phonebooks or calls). Which entry should
988 * be read is defined in entry. 1000 * be read is defined in entry.
989 */ 1001 */
990 GSM_Error (*GetMemory) (GSM_StateMachine *s, GSM_MemoryEntry *entry); 1002 GSM_Error (*GetMemory) (GSM_StateMachine *s, GSM_MemoryEntry *entry);
991 /** 1003 /**
992 * Reads entry from memory (phonebooks or calls). Which entry should 1004 * Reads entry from memory (phonebooks or calls). Which entry should
993 * be read is defined in entry. This can be easily used for reading all entries. 1005 * be read is defined in entry. This can be easily used for reading all entries.
994 */ 1006 */
995 GSM_Error (*GetNextMemory) (GSM_StateMachine *s, GSM_MemoryEntry *entry, bool start); 1007 GSM_Error (*GetNextMemory) (GSM_StateMachine *s, GSM_MemoryEntry *entry, bool start);
996 /** 1008 /**
997 * Sets memory (phonebooks or calls) entry. 1009 * Sets memory (phonebooks or calls) entry.
998 */ 1010 */
999 GSM_Error (*SetMemory) (GSM_StateMachine *s, GSM_MemoryEntry *entry); 1011 GSM_Error (*SetMemory) (GSM_StateMachine *s, GSM_MemoryEntry *entry);
1000 /** 1012 /**
1001 * Deletes memory (phonebooks or calls) entry. 1013 * Deletes memory (phonebooks or calls) entry.
1002 */ 1014 */
1003 GSM_Error (*AddMemory) (GSM_StateMachine *s, GSM_MemoryEntry *entry); 1015 GSM_Error (*AddMemory) (GSM_StateMachine *s, GSM_MemoryEntry *entry);
1004 /** 1016 /**
1005 * Deletes memory (phonebooks or calls) entry. 1017 * Deletes memory (phonebooks or calls) entry.
1006 */ 1018 */
1007 GSM_Error (*DeleteMemory) (GSM_StateMachine *s, GSM_MemoryEntry *entry); 1019 GSM_Error (*DeleteMemory) (GSM_StateMachine *s, GSM_MemoryEntry *entry);
1008 /** 1020 /**
1009 * Deletes all memory (phonebooks or calls) entries of specified type. 1021 * Deletes all memory (phonebooks or calls) entries of specified type.
1010 */ 1022 */
1011 GSM_Error (*DeleteAllMemory) (GSM_StateMachine *s, GSM_MemoryType MemoryType); 1023 GSM_Error (*DeleteAllMemory) (GSM_StateMachine *s, GSM_MemoryType MemoryType);
1012 /** 1024 /**
1013 * Gets speed dial. 1025 * Gets speed dial.
1014 */ 1026 */
1015 GSM_Error (*GetSpeedDial) (GSM_StateMachine *s, GSM_SpeedDial *Speed); 1027 GSM_Error (*GetSpeedDial) (GSM_StateMachine *s, GSM_SpeedDial *Speed);
1016 /** 1028 /**
1017 * Sets speed dial. 1029 * Sets speed dial.
1018 */ 1030 */
1019 GSM_Error (*SetSpeedDial) (GSM_StateMachine *s, GSM_SpeedDial *Speed); 1031 GSM_Error (*SetSpeedDial) (GSM_StateMachine *s, GSM_SpeedDial *Speed);
1020 /** 1032 /**
1021 * Gets SMS Service Center number and SMS settings. 1033 * Gets SMS Service Center number and SMS settings.
1022 */ 1034 */
1023 GSM_Error (*GetSMSC) (GSM_StateMachine *s, GSM_SMSC *smsc); 1035 GSM_Error (*GetSMSC) (GSM_StateMachine *s, GSM_SMSC *smsc);
1024 /** 1036 /**
1025 * Sets SMS Service Center number and SMS settings. 1037 * Sets SMS Service Center number and SMS settings.
1026 */ 1038 */
1027 GSM_Error (*SetSMSC) (GSM_StateMachine *s, GSM_SMSC *smsc); 1039 GSM_Error (*SetSMSC) (GSM_StateMachine *s, GSM_SMSC *smsc);
1028 /** 1040 /**
1029 * Gets information about SMS memory (read/unread/size of memory for 1041 * Gets information about SMS memory (read/unread/size of memory for
1030 * both SIM and phone). 1042 * both SIM and phone).
1031 */ 1043 */
1032 GSM_Error (*GetSMSStatus) (GSM_StateMachine *s, GSM_SMSMemoryStatus *status); 1044 GSM_Error (*GetSMSStatus) (GSM_StateMachine *s, GSM_SMSMemoryStatus *status);
1033 /** 1045 /**
1034 * Reads SMS message. 1046 * Reads SMS message.
1035 */ 1047 */
1036 GSM_Error (*GetSMS) (GSM_StateMachine *s, GSM_MultiSMSMessage *sms); 1048 GSM_Error (*GetSMS) (GSM_StateMachine *s, GSM_MultiSMSMessage *sms);
1037 /** 1049 /**
1038 * Reads next (or first if start set) SMS message. This might be 1050 * Reads next (or first if start set) SMS message. This might be
1039 * faster for some phones than using @ref GetSMS for each message. 1051 * faster for some phones than using @ref GetSMS for each message.
1040 */ 1052 */
1041 GSM_Error (*GetNextSMS) (GSM_StateMachine *s, GSM_MultiSMSMessage *sms, bool start); 1053 GSM_Error (*GetNextSMS) (GSM_StateMachine *s, GSM_MultiSMSMessage *sms, bool start);
1042 /** 1054 /**
1043 * Sets SMS. 1055 * Sets SMS.
1044 */ 1056 */
1045 GSM_Error (*SetSMS) (GSM_StateMachine *s, GSM_SMSMessage *sms); 1057 GSM_Error (*SetSMS) (GSM_StateMachine *s, GSM_SMSMessage *sms);
1046 /** 1058 /**
1047 * Adds SMS to specified folder. 1059 * Adds SMS to specified folder.
1048 */ 1060 */
1049 GSM_Error (*AddSMS) (GSM_StateMachine *s, GSM_SMSMessage *sms); 1061 GSM_Error (*AddSMS) (GSM_StateMachine *s, GSM_SMSMessage *sms);
1050 /** 1062 /**
1051 * Deletes SMS. 1063 * Deletes SMS.
1052 */ 1064 */
1053 GSM_Error (*DeleteSMS) (GSM_StateMachine *s, GSM_SMSMessage *sms); 1065 GSM_Error (*DeleteSMS) (GSM_StateMachine *s, GSM_SMSMessage *sms);
1054 /** 1066 /**
1055 * Sends SMS. 1067 * Sends SMS.
1056 */ 1068 */
1057 GSM_Error (*SendSMS) (GSM_StateMachine *s, GSM_SMSMessage *sms); 1069 GSM_Error (*SendSMS) (GSM_StateMachine *s, GSM_SMSMessage *sms);
1058 /** 1070 /**
1059 * Sends SMS already saved in phone. 1071 * Sends SMS already saved in phone.
1060 */ 1072 */
1061 GSM_Error (*SendSavedSMS)(GSM_StateMachine *s, int Folder, int Location); 1073 GSM_Error (*SendSavedSMS)(GSM_StateMachine *s, int Folder, int Location);
1074 GSM_Error (*SetFastSMSSending) (GSM_StateMachine *s, bool enable);
1062 /** 1075 /**
1063 * Enable/disable notification on incoming SMS. 1076 * Enable/disable notification on incoming SMS.
1064 */ 1077 */
1065 GSM_Error (*SetIncomingSMS) (GSM_StateMachine *s, bool enable); 1078 GSM_Error (*SetIncomingSMS) (GSM_StateMachine *s, bool enable);
1066 /** 1079 /**
1067 * Gets network information from phone. 1080 * Gets network information from phone.
1068 */ 1081 */
1069 GSM_Error (*SetIncomingCB) (GSM_StateMachine *s, bool enable); 1082 GSM_Error (*SetIncomingCB) (GSM_StateMachine *s, bool enable);
1070 /** 1083 /**
1071 * Returns SMS folders information. 1084 * Returns SMS folders information.
1072 */ 1085 */
1073 GSM_Error (*GetSMSFolders) (GSM_StateMachine *s, GSM_SMSFolders *folders); 1086 GSM_Error (*GetSMSFolders) (GSM_StateMachine *s, GSM_SMSFolders *folders);
1074 /** 1087 /**
1075 * Creates SMS folder. 1088 * Creates SMS folder.
1076 */ 1089 */
1077 GSM_Error (*AddSMSFolder) (GSM_StateMachine *s, unsigned char *name); 1090 GSM_Error (*AddSMSFolder) (GSM_StateMachine *s, unsigned char *name);
1078 /** 1091 /**
1079 * Deletes SMS folder. 1092 * Deletes SMS folder.
1080 */ 1093 */
1081 GSM_Error (*DeleteSMSFolder) (GSM_StateMachine *s, int ID); 1094 GSM_Error (*DeleteSMSFolder) (GSM_StateMachine *s, int ID);
1082 /** 1095 /**
1083 * Dials number and starts voice call. 1096 * Dials number and starts voice call.
1084 */ 1097 */
1085 GSM_Error (*DialVoice) (GSM_StateMachine *s, char *Number, GSM_CallShowNumber ShowNumber); 1098 GSM_Error (*DialVoice) (GSM_StateMachine *s, char *Number, GSM_CallShowNumber ShowNumber);
1086 /** 1099 /**
1087 * Accept current incoming call. 1100 * Accept current incoming call.
1088 */ 1101 */
1089 GSM_Error (*AnswerCall) (GSM_StateMachine *s, int ID, bool all); 1102 GSM_Error (*AnswerCall) (GSM_StateMachine *s, int ID, bool all);
1090 /** 1103 /**
1091 * Deny current incoming call. 1104 * Deny current incoming call.
1092 */ 1105 */
1093 GSM_Error (*CancelCall) (GSM_StateMachine *s, int ID, bool all); 1106 GSM_Error (*CancelCall) (GSM_StateMachine *s, int ID, bool all);
1094 /** 1107 /**
1095 * Holds call. 1108 * Holds call.
1096 */ 1109 */
1097 GSM_Error (*HoldCall) (GSM_StateMachine *s, int ID); 1110 GSM_Error (*HoldCall) (GSM_StateMachine *s, int ID);
1098 /** 1111 /**
1099 * Unholds call. 1112 * Unholds call.
1100 */ 1113 */
1101 GSM_Error (*UnholdCall) (GSM_StateMachine *s, int ID); 1114 GSM_Error (*UnholdCall) (GSM_StateMachine *s, int ID);
1102 /** 1115 /**
1103 * Initiates conference call. 1116 * Initiates conference call.
1104 */ 1117 */
1105 GSM_Error (*ConferenceCall) (GSM_StateMachine *s, int ID); 1118 GSM_Error (*ConferenceCall) (GSM_StateMachine *s, int ID);
1106 /** 1119 /**
1107 * Splits call. 1120 * Splits call.
1108 */ 1121 */
1109 GSM_Error (*SplitCall) (GSM_StateMachine *s, int ID); 1122 GSM_Error (*SplitCall) (GSM_StateMachine *s, int ID);
1110 /** 1123 /**
1111 * Transfers call. 1124 * Transfers call.
1112 */ 1125 */
1113 GSM_Error (*TransferCall) (GSM_StateMachine *s, int ID, bool next); 1126 GSM_Error (*TransferCall) (GSM_StateMachine *s, int ID, bool next);
1114 /** 1127 /**
1115 * Switches call. 1128 * Switches call.
1116 */ 1129 */
1117 GSM_Error (*SwitchCall) (GSM_StateMachine *s, int ID, bool next); 1130 GSM_Error (*SwitchCall) (GSM_StateMachine *s, int ID, bool next);
1118 /** 1131 /**
1119 * Gets call diverts. 1132 * Gets call diverts.
1120 */ 1133 */
1121 GSM_Error (*GetCallDivert) (GSM_StateMachine *s, GSM_MultiCallDivert *divert); 1134 GSM_Error (*GetCallDivert) (GSM_StateMachine *s, GSM_MultiCallDivert *divert);
1122 /** 1135 /**
1123 * Sets call diverts. 1136 * Sets call diverts.
1124 */ 1137 */
1125 GSM_Error (*SetCallDivert) (GSM_StateMachine *s, GSM_MultiCallDivert *divert); 1138 GSM_Error (*SetCallDivert) (GSM_StateMachine *s, GSM_MultiCallDivert *divert);
1126 /** 1139 /**
1127 * Cancels all diverts. 1140 * Cancels all diverts.
1128 */ 1141 */
1129 GSM_Error (*CancelAllDiverts) (GSM_StateMachine *s); 1142 GSM_Error (*CancelAllDiverts) (GSM_StateMachine *s);
1130 /** 1143 /**
1131 * Activates/deactivates noticing about incoming calls. 1144 * Activates/deactivates noticing about incoming calls.
1132 */ 1145 */
1133 GSM_Error (*SetIncomingCall) (GSM_StateMachine *s, bool enable); 1146 GSM_Error (*SetIncomingCall) (GSM_StateMachine *s, bool enable);
1134 /** 1147 /**
1135 * Activates/deactivates noticing about incoming USSDs (UnStructured Supplementary Services). 1148 * Activates/deactivates noticing about incoming USSDs (UnStructured Supplementary Services).
1136 */ 1149 */
1137 GSM_Error (*SetIncomingUSSD) (GSM_StateMachine *s, bool enable); 1150 GSM_Error (*SetIncomingUSSD) (GSM_StateMachine *s, bool enable);
1138 /** 1151 /**
1139 * Sends DTMF (Dual Tone Multi Frequency) tone. 1152 * Sends DTMF (Dual Tone Multi Frequency) tone.
1140 */ 1153 */
1141 GSM_Error (*SendDTMF) (GSM_StateMachine *s, char *sequence); 1154 GSM_Error (*SendDTMF) (GSM_StateMachine *s, char *sequence);
1142 /** 1155 /**
1143 * Gets ringtone from phone. 1156 * Gets ringtone from phone.
1144 */ 1157 */
1145 GSM_Error (*GetRingtone)(GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone); 1158 GSM_Error (*GetRingtone)(GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone);
1146 /** 1159 /**
1147 * Sets ringtone in phone. 1160 * Sets ringtone in phone.
1148 */ 1161 */
1149 GSM_Error (*SetRingtone)(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength); 1162 GSM_Error (*SetRingtone)(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength);
1150 /** 1163 /**
1151 * Acquires ringtone informaiton. 1164 * Acquires ringtone informaiton.
1152 */ 1165 */
1153 GSM_Error (*GetRingtonesInfo) (GSM_StateMachine *s, GSM_AllRingtonesInfo *Info); 1166 GSM_Error (*GetRingtonesInfo) (GSM_StateMachine *s, GSM_AllRingtonesInfo *Info);
1154 /** 1167 /**
1155 * Deletes user defined ringtones from phone. 1168 * Deletes user defined ringtones from phone.
1156 */ 1169 */
1157 GSM_Error (*DeleteUserRingtones)(GSM_StateMachine *s); 1170 GSM_Error (*DeleteUserRingtones)(GSM_StateMachine *s);
1158 /** 1171 /**
1159 * Plays tone. 1172 * Plays tone.
1160 */ 1173 */
1161 GSM_Error (*PlayTone) (GSM_StateMachine *s, int Herz, unsigned char Volume, bool start); 1174 GSM_Error (*PlayTone) (GSM_StateMachine *s, int Herz, unsigned char Volume, bool start);
1162 /** 1175 /**
1163 * Reads WAP bookmark. 1176 * Reads WAP bookmark.
1164 */ 1177 */
1165 GSM_Error (*GetWAPBookmark) (GSM_StateMachine *s, GSM_WAPBookmark *bookmark); 1178 GSM_Error (*GetWAPBookmark) (GSM_StateMachine *s, GSM_WAPBookmark *bookmark);
1166 /** 1179 /**
1167 * Sets WAP bookmark. 1180 * Sets WAP bookmark.
1168 */ 1181 */
1169 GSM_Error (*SetWAPBookmark) (GSM_StateMachine *s, GSM_WAPBookmark *bookmark); 1182 GSM_Error (*SetWAPBookmark) (GSM_StateMachine *s, GSM_WAPBookmark *bookmark);
1170 /** 1183 /**
1171 * Deletes WAP bookmark. 1184 * Deletes WAP bookmark.
1172 */ 1185 */
1173 GSM_Error (*DeleteWAPBookmark) (GSM_StateMachine *s, GSM_WAPBookmark *bookmark); 1186 GSM_Error (*DeleteWAPBookmark) (GSM_StateMachine *s, GSM_WAPBookmark *bookmark);
1174 /** 1187 /**
1175 * Acquires WAP settings. 1188 * Acquires WAP settings.
1176 */ 1189 */
1177 GSM_Error (*GetWAPSettings) (GSM_StateMachine *s, GSM_MultiWAPSettings *settings); 1190 GSM_Error (*GetWAPSettings) (GSM_StateMachine *s, GSM_MultiWAPSettings *settings);
1178 /** 1191 /**
1179 * Changes WAP settings. 1192 * Changes WAP settings.
1180 */ 1193 */
1181 GSM_Error (*SetWAPSettings) (GSM_StateMachine *s, GSM_MultiWAPSettings *settings); 1194 GSM_Error (*SetWAPSettings) (GSM_StateMachine *s, GSM_MultiWAPSettings *settings);
1182 /** 1195 /**
1183 * Acquires MMS settings. 1196 * Acquires MMS settings.
1184 */ 1197 */
1185 GSM_Error (*GetMMSSettings) (GSM_StateMachine *s, GSM_MultiWAPSettings *settings); 1198 GSM_Error (*GetMMSSettings) (GSM_StateMachine *s, GSM_MultiWAPSettings *settings);
1186 /** 1199 /**
1187 * Changes MMS settings. 1200 * Changes MMS settings.
1188 */ 1201 */
1189 GSM_Error (*SetMMSSettings) (GSM_StateMachine *s, GSM_MultiWAPSettings *settings); 1202 GSM_Error (*SetMMSSettings) (GSM_StateMachine *s, GSM_MultiWAPSettings *settings);
1190 /** 1203 /**
1191 * Acquires SyncML settings. 1204 * Acquires SyncML settings.
1192 */ 1205 */
1193 GSM_Error (*GetSyncMLSettings) (GSM_StateMachine *s, GSM_SyncMLSettings *settings); 1206 GSM_Error (*GetSyncMLSettings) (GSM_StateMachine *s, GSM_SyncMLSettings *settings);
1194 /** 1207 /**
1195 * Changes SyncML settings. 1208 * Changes SyncML settings.
1196 */ 1209 */
1197 GSM_Error (*SetSyncMLSettings) (GSM_StateMachine *s, GSM_SyncMLSettings *settings); 1210 GSM_Error (*SetSyncMLSettings) (GSM_StateMachine *s, GSM_SyncMLSettings *settings);
1198 /** 1211 /**
1199 * Acquires chat/presence settings. 1212 * Acquires chat/presence settings.
1200 */ 1213 */
1201 GSM_Error (*GetChatSettings) (GSM_StateMachine *s, GSM_ChatSettings *settings); 1214 GSM_Error (*GetChatSettings) (GSM_StateMachine *s, GSM_ChatSettings *settings);
1202 /** 1215 /**
1203 * Changes chat/presence settings. 1216 * Changes chat/presence settings.
1204 */ 1217 */
1205 GSM_Error (*SetChatSettings) (GSM_StateMachine *s, GSM_ChatSettings *settings); 1218 GSM_Error (*SetChatSettings) (GSM_StateMachine *s, GSM_ChatSettings *settings);
1206 /** 1219 /**
1207 * Gets bitmap. 1220 * Gets bitmap.
1208 */ 1221 */
1209 GSM_Error (*GetBitmap) (GSM_StateMachine *s, GSM_Bitmap *Bitmap); 1222 GSM_Error (*GetBitmap) (GSM_StateMachine *s, GSM_Bitmap *Bitmap);
1210 /** 1223 /**
1211 * Sets bitmap. 1224 * Sets bitmap.
1212 */ 1225 */
1213 GSM_Error (*SetBitmap) (GSM_StateMachine *s, GSM_Bitmap *Bitmap); 1226 GSM_Error (*SetBitmap) (GSM_StateMachine *s, GSM_Bitmap *Bitmap);
1214 /** 1227 /**
1215 * Gets status of ToDos (count of used entries). 1228 * Gets status of ToDos (count of used entries).
1216 */ 1229 */
1217 GSM_Error (*GetToDoStatus) (GSM_StateMachine *s, GSM_ToDoStatus *status); 1230 GSM_Error (*GetToDoStatus) (GSM_StateMachine *s, GSM_ToDoStatus *status);
1218 /** 1231 /**
1219 * Reads ToDo from phone. 1232 * Reads ToDo from phone.
1220 */ 1233 */
1221 GSM_Error (*GetToDo) (GSM_StateMachine *s, GSM_ToDoEntry *ToDo); 1234 GSM_Error (*GetToDo) (GSM_StateMachine *s, GSM_ToDoEntry *ToDo);
1222 /** 1235 /**
1223 * Reads ToDo from phone. 1236 * Reads ToDo from phone.
1224 */ 1237 */
1225 GSM_Error (*GetNextToDo)(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool start); 1238 GSM_Error (*GetNextToDo)(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool start);
1226 /** 1239 /**
1227 * Sets ToDo in phone. 1240 * Sets ToDo in phone.
1228 */ 1241 */
1229 GSM_Error (*SetToDo) (GSM_StateMachine *s, GSM_ToDoEntry *ToDo); 1242 GSM_Error (*SetToDo) (GSM_StateMachine *s, GSM_ToDoEntry *ToDo);
1230 /** 1243 /**
1231 * Adds ToDo in phone. 1244 * Adds ToDo in phone.
1232 */ 1245 */
1233 GSM_Error (*AddToDo) (GSM_StateMachine *s, GSM_ToDoEntry *ToDo); 1246 GSM_Error (*AddToDo) (GSM_StateMachine *s, GSM_ToDoEntry *ToDo);
1234 /** 1247 /**
1235 * Deletes ToDo entry in phone. 1248 * Deletes ToDo entry in phone.
1236 */ 1249 */
1237 GSM_Error (*DeleteToDo) (GSM_StateMachine *s, GSM_ToDoEntry *ToDo); 1250 GSM_Error (*DeleteToDo) (GSM_StateMachine *s, GSM_ToDoEntry *ToDo);
1238 /** 1251 /**
1239 * Deletes all todo entries in phone. 1252 * Deletes all todo entries in phone.
1240 */ 1253 */
1241 GSM_Error (*DeleteAllToDo) (GSM_StateMachine *s); 1254 GSM_Error (*DeleteAllToDo) (GSM_StateMachine *s);
1242 /** 1255 /**
1243 * Retrieves calendar status (number of used entries). 1256 * Retrieves calendar status (number of used entries).
1244 */ 1257 */
1245 GSM_Error (*GetCalendarStatus) (GSM_StateMachine *s, GSM_CalendarStatus *Status); 1258 GSM_Error (*GetCalendarStatus) (GSM_StateMachine *s, GSM_CalendarStatus *Status);
1246 /** 1259 /**
1247 * Retrieves calendar entry. 1260 * Retrieves calendar entry.
1248 */ 1261 */
1249 GSM_Error (*GetCalendar)(GSM_StateMachine *s, GSM_CalendarEntry *Note); 1262 GSM_Error (*GetCalendar)(GSM_StateMachine *s, GSM_CalendarEntry *Note);
1250 /** 1263 /**
1251 * Retrieves calendar entry. This is useful for continuous reading of all 1264 * Retrieves calendar entry. This is useful for continuous reading of all
1252 * calendar entries. 1265 * calendar entries.
1253 */ 1266 */
1254 GSM_Error (*GetNextCalendar) (GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start); 1267 GSM_Error (*GetNextCalendar) (GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start);
1255 /** 1268 /**
1256 * Sets calendar entry 1269 * Sets calendar entry
1257 */ 1270 */
1258 GSM_Error (*SetCalendar)(GSM_StateMachine *s, GSM_CalendarEntry *Note); 1271 GSM_Error (*SetCalendar)(GSM_StateMachine *s, GSM_CalendarEntry *Note);
1259 /** 1272 /**
1260 * Adds calendar entry. 1273 * Adds calendar entry.
1261 */ 1274 */
1262 GSM_Error (*AddCalendar)(GSM_StateMachine *s, GSM_CalendarEntry *Note); 1275 GSM_Error (*AddCalendar)(GSM_StateMachine *s, GSM_CalendarEntry *Note);
1263 /** 1276 /**
1264 * Deletes calendar entry. 1277 * Deletes calendar entry.
1265 */ 1278 */
1266 GSM_Error (*DeleteCalendar) (GSM_StateMachine *s, GSM_CalendarEntry *Note); 1279 GSM_Error (*DeleteCalendar) (GSM_StateMachine *s, GSM_CalendarEntry *Note);
1267 /** 1280 /**
1268 * Deletes all calendar entries. 1281 * Deletes all calendar entries.
1269 */ 1282 */
1270 GSM_Error (*DeleteAllCalendar) (GSM_StateMachine *s); 1283 GSM_Error (*DeleteAllCalendar) (GSM_StateMachine *s);
1271 /** 1284 /**
1272 * Reads calendar settings. 1285 * Reads calendar settings.
1273 */ 1286 */
1274 GSM_Error (*GetCalendarSettings)(GSM_StateMachine *s, GSM_CalendarSettings *settings); 1287 GSM_Error (*GetCalendarSettings)(GSM_StateMachine *s, GSM_CalendarSettings *settings);
1275 /** 1288 /**
1276 * Sets calendar settings. 1289 * Sets calendar settings.
1277 */ 1290 */
1278 GSM_Error (*SetCalendarSettings)(GSM_StateMachine *s, GSM_CalendarSettings *settings); 1291 GSM_Error (*SetCalendarSettings)(GSM_StateMachine *s, GSM_CalendarSettings *settings);
1279 /** 1292 /**
1280 * Gets note. 1293 * Gets note.
1281 */ 1294 */
1282 GSM_Error (*GetNote) (GSM_StateMachine *s, GSM_NoteEntry *Note, bool refresh); 1295 GSM_Error (*GetNextNote)(GSM_StateMachine *s, GSM_NoteEntry *Note, bool refresh);
1283 /** 1296 /**
1284 * Reads profile. 1297 * Reads profile.
1285 */ 1298 */
1286 GSM_Error (*GetProfile) (GSM_StateMachine *s, GSM_Profile *Profile); 1299 GSM_Error (*GetProfile) (GSM_StateMachine *s, GSM_Profile *Profile);
1287 /** 1300 /**
1288 * Updates profile. 1301 * Updates profile.
1289 */ 1302 */
1290 GSM_Error (*SetProfile) (GSM_StateMachine *s, GSM_Profile *Profile); 1303 GSM_Error (*SetProfile) (GSM_StateMachine *s, GSM_Profile *Profile);
1291 /** 1304 /**
1292 * Reads FM station. 1305 * Reads FM station.
1293 */ 1306 */
1294 GSM_Error (*GetFMStation) (GSM_StateMachine *s, GSM_FMStation *FMStation); 1307 GSM_Error (*GetFMStation) (GSM_StateMachine *s, GSM_FMStation *FMStation);
1295 /** 1308 /**
1296 * Sets FM station. 1309 * Sets FM station.
1297 */ 1310 */
1298 GSM_Error (*SetFMStation) (GSM_StateMachine *s, GSM_FMStation *FMStation); 1311 GSM_Error (*SetFMStation) (GSM_StateMachine *s, GSM_FMStation *FMStation);
1299 /** 1312 /**
1300 * Clears defined FM stations. 1313 * Clears defined FM stations.
1301 */ 1314 */
1302 GSM_Error (*ClearFMStations) (GSM_StateMachine *s); 1315 GSM_Error (*ClearFMStations) (GSM_StateMachine *s);
1303 /** 1316 /**
1304 * Gets next filename from filesystem. 1317 * Gets next filename from filesystem.
1305 */ 1318 */
1306 GSM_Error (*GetNextFileFolder) (GSM_StateMachine *s, GSM_File *File, bool start); 1319 GSM_Error (*GetNextFileFolder) (GSM_StateMachine *s, GSM_File *File, bool start);
1307 /** 1320 /**
1308 * Gets file part from filesystem. 1321 * Gets file part from filesystem.
1309 */ 1322 */
1310 GSM_Error (*GetFilePart)(GSM_StateMachine *s, GSM_File *File); 1323 GSM_Error (*GetFilePart)(GSM_StateMachine *s, GSM_File *File);
1311 /** 1324 /**
1312 * Adds file part to filesystem. 1325 * Adds file part to filesystem.
1313 */ 1326 */
1314 GSM_Error (*AddFilePart)(GSM_StateMachine *s, GSM_File *File, int *Pos); 1327 GSM_Error (*AddFilePart)(GSM_StateMachine *s, GSM_File *File, int *Pos);
1315 /** 1328 /**
1316 * Acquires filesystem status. 1329 * Acquires filesystem status.
1317 */ 1330 */
1318 GSM_Error (*GetFileSystemStatus)(GSM_StateMachine *s, GSM_FileSystemStatus *Status); 1331 GSM_Error (*GetFileSystemStatus)(GSM_StateMachine *s, GSM_FileSystemStatus *Status);
1319 /** 1332 /**
1320 * Deletes file from filessytem. 1333 * Deletes file from filessytem.
1321 */ 1334 */
1322 GSM_Error (*DeleteFile) (GSM_StateMachine *s, unsigned char *ID); 1335 GSM_Error (*DeleteFile) (GSM_StateMachine *s, unsigned char *ID);
1323 /** 1336 /**
1324 * Adds folder to filesystem. 1337 * Adds folder to filesystem.
1325 */ 1338 */
1326 GSM_Error (*AddFolder) (GSM_StateMachine *s, GSM_File *File); 1339 GSM_Error (*AddFolder) (GSM_StateMachine *s, GSM_File *File);
1327 /** 1340 /**
1328 * Gets GPRS access point. 1341 * Gets GPRS access point.
1329 */ 1342 */
1330 GSM_Error (*GetGPRSAccessPoint) (GSM_StateMachine *s, GSM_GPRSAccessPoint *point); 1343 GSM_Error (*GetGPRSAccessPoint) (GSM_StateMachine *s, GSM_GPRSAccessPoint *point);
1331 /** 1344 /**
1332 * Sets GPRS access point. 1345 * Sets GPRS access point.
1333 */ 1346 */
1334 GSM_Error (*SetGPRSAccessPoint) (GSM_StateMachine *s, GSM_GPRSAccessPoint *point); 1347 GSM_Error (*SetGPRSAccessPoint) (GSM_StateMachine *s, GSM_GPRSAccessPoint *point);
1335} GSM_Phone_Functions; 1348} GSM_Phone_Functions;
1336 1349
1337 extern GSM_Phone_Functions NAUTOPhone; 1350 extern GSM_Phone_Functions NAUTOPhone;
1338#ifdef GSM_ENABLE_NOKIA3320 1351#ifdef GSM_ENABLE_NOKIA3320
1339 extern GSM_Phone_Functions N3320Phone; 1352 extern GSM_Phone_Functions N3320Phone;
1340#endif 1353#endif
1341#ifdef GSM_ENABLE_NOKIA3650 1354#ifdef GSM_ENABLE_NOKIA3650
1342 extern GSM_Phone_Functions N3650Phone; 1355 extern GSM_Phone_Functions N3650Phone;
1343#endif 1356#endif
1344#ifdef GSM_ENABLE_NOKIA6110 1357#ifdef GSM_ENABLE_NOKIA6110
1345 extern GSM_Phone_Functions N6110Phone; 1358 extern GSM_Phone_Functions N6110Phone;
1346#endif 1359#endif
1360#ifdef GSM_ENABLE_NOKIA650
1361 extern GSM_Phone_Functions N650Phone;
1362#endif
1347#ifdef GSM_ENABLE_NOKIA6510 1363#ifdef GSM_ENABLE_NOKIA6510
1348 extern GSM_Phone_Functions N6510Phone; 1364 extern GSM_Phone_Functions N6510Phone;
1349#endif 1365#endif
1350#ifdef GSM_ENABLE_NOKIA7110 1366#ifdef GSM_ENABLE_NOKIA7110
1351 extern GSM_Phone_Functions N7110Phone; 1367 extern GSM_Phone_Functions N7110Phone;
1352#endif 1368#endif
1353#ifdef GSM_ENABLE_NOKIA9210 1369#ifdef GSM_ENABLE_NOKIA9210
1354 extern GSM_Phone_Functions N9210Phone; 1370 extern GSM_Phone_Functions N9210Phone;
1355#endif 1371#endif
1356#ifdef GSM_ENABLE_ATGEN 1372#ifdef GSM_ENABLE_ATGEN
1357 extern GSM_Phone_Functions ATGENPhone; 1373 extern GSM_Phone_Functions ATGENPhone;
1358#endif 1374#endif
1359#ifdef GSM_ENABLE_ALCATEL 1375#ifdef GSM_ENABLE_ALCATEL
1360 extern GSM_Phone_Functions ALCATELPhone; 1376 extern GSM_Phone_Functions ALCATELPhone;
1361#endif 1377#endif
1362#ifdef GSM_ENABLE_OBEXGEN 1378#ifdef GSM_ENABLE_OBEXGEN
1363 extern GSM_Phone_Functions OBEXGENPhone; 1379 extern GSM_Phone_Functions OBEXGENPhone;
1364#endif 1380#endif
1365#ifdef GSM_ENABLE_MROUTERGEN 1381#ifdef GSM_ENABLE_MROUTERGEN
1366 extern GSM_Phone_Functions MROUTERGENPhone; 1382 extern GSM_Phone_Functions MROUTERGENPhone;
1367#endif 1383#endif
1368 1384
1369typedef struct { 1385typedef struct {
1370 GSM_Phone_Data Data; 1386 GSM_Phone_Data Data;
1371 GSM_Phone_Functions*Functions; 1387 GSM_Phone_Functions*Functions;
1372} GSM_Phone; 1388} GSM_Phone;
1373 1389
1374/* --------------------------- User layer ---------------------------------- */ 1390/* --------------------------- User layer ---------------------------------- */
1375 1391
1376struct _GSM_User { 1392struct _GSM_User {
1377 GSM_Reply_Function *UserReplyFunctions; 1393 GSM_Reply_Function *UserReplyFunctions;
1378 1394
1379 void (*IncomingCall) (char *Device, GSM_Call call); 1395 void (*IncomingCall) (char *Device, GSM_Call call);
1380 void (*IncomingSMS)(char *Device, GSM_SMSMessage sms); 1396 void (*IncomingSMS)(char *Device, GSM_SMSMessage sms);
1381 void (*IncomingCB) (char *Device, GSM_CBMessage cb); 1397 void (*IncomingCB) (char *Device, GSM_CBMessage cb);
1382 void (*IncomingUSSD) (char *Device, char *Text); 1398 void (*IncomingUSSD) (char *Device, char *Text);
1383 void (*SendSMSStatus) (char *Device, int status, int MessageReference); 1399 void (*SendSMSStatus) (char *Device, int status, int MessageReference);
1384}; 1400};
1385 1401
1386/* --------------------------- Statemachine layer -------------------------- */ 1402/* --------------------------- Statemachine layer -------------------------- */
1387 1403
1388typedef enum { 1404typedef enum {
1389 GCT_MBUS2=1, 1405 GCT_MBUS2=1,
1390 GCT_FBUS2, 1406 GCT_FBUS2,
1391 GCT_FBUS2DLR3, 1407 GCT_FBUS2DLR3,
1392 GCT_FBUS2DKU5, 1408 GCT_FBUS2DKU5,
1393 GCT_FBUS2PL2303, 1409 GCT_FBUS2PL2303,
1394 GCT_FBUS2BLUE, 1410 GCT_FBUS2BLUE,
1395 GCT_FBUS2IRDA, 1411 GCT_FBUS2IRDA,
1396 GCT_PHONETBLUE, 1412 GCT_PHONETBLUE,
1397 GCT_AT, 1413 GCT_AT,
1398 GCT_MROUTERBLUE, 1414 GCT_MROUTERBLUE,
1399 1415
1400 GCT_IRDAOBEX, 1416 GCT_IRDAOBEX,
1401 GCT_IRDAAT, 1417 GCT_IRDAAT,
1402 GCT_IRDAPHONET, 1418 GCT_IRDAPHONET,
1403 GCT_BLUEFBUS2, 1419 GCT_BLUEFBUS2,
1404 GCT_BLUEAT, 1420 GCT_BLUEAT,
1405 GCT_BLUEPHONET, 1421 GCT_BLUEPHONET,
1406 GCT_BLUEOBEX 1422 GCT_BLUEOBEX
1407} GSM_ConnectionType; 1423} GSM_ConnectionType;
1408 1424
1409typedef struct { 1425typedef struct {
1410 /* Config file (or Registry or...) variables */ 1426 /* Config file (or Registry or...) variables */
1411 char Model[50]; /* Model from config file */ 1427 char Model[50]; /* Model from config file */
1412 char DebugLevel[50]; /* Debug level */ 1428 char DebugLevel[50]; /* Debug level */
1413 char *Device; /* Device name from config file */ 1429 char *Device; /* Device name from config file */
1414 char *Connection; /* Connection type as string */ 1430 char *Connection; /* Connection type as string */
1415 char *SyncTime; /* Synchronize time on startup? */ 1431 char *SyncTime; /* Synchronize time on startup? */
1416 char *LockDevice; /* Lock device ? (Unix) */ 1432 char *LockDevice; /* Lock device ? (Unix) */
1417 char *DebugFile; /* Name of debug file */ 1433 char *DebugFile; /* Name of debug file */
1418 char *Localize; /* Name of localisation file */ 1434 char *Localize; /* Name of localisation file */
1419 char *StartInfo; /* Display something during start ? */ 1435 char *StartInfo; /* Display something during start ? */
1420 bool UseGlobalDebugFile;/* Should we use global debug file?*/ 1436 bool UseGlobalDebugFile;/* Should we use global debug file?*/
1421 bool DefaultModel; 1437 bool DefaultModel;
1422 bool DefaultDebugLevel; 1438 bool DefaultDebugLevel;
1423 bool DefaultDevice; 1439 bool DefaultDevice;
1424 bool DefaultConnection; 1440 bool DefaultConnection;
1425 bool DefaultSyncTime; 1441 bool DefaultSyncTime;
1426 bool DefaultLockDevice; 1442 bool DefaultLockDevice;
1427 bool DefaultDebugFile; 1443 bool DefaultDebugFile;
1428 bool DefaultLocalize; 1444 bool DefaultLocalize;
1429 bool DefaultStartInfo; 1445 bool DefaultStartInfo;
1430} GSM_Config; 1446} GSM_Config;
1431 1447
1432 #define MAX_CONFIG_NUM 5 1448 #define MAX_CONFIG_NUM 5
1433 1449
1434struct _GSM_StateMachine { 1450struct _GSM_StateMachine {
1435 GSM_ConnectionType ConnectionType; /* Type of connection as int */ 1451 GSM_ConnectionType ConnectionType; /* Type of connection as int */
1436 char *LockFile; /* Lock file name for Unix */ 1452 char *LockFile; /* Lock file name for Unix */
1437 Debug_Info di; /* Debug information */ 1453 Debug_Info di; /* Debug information */
1438 bool opened; /* Is connection opened ? */ 1454 bool opened; /* Is connection opened ? */
1439 GSM_Config Config[MAX_CONFIG_NUM + 1]; 1455 GSM_Config Config[MAX_CONFIG_NUM + 1];
1440 GSM_Config *CurrentConfig; /* Config file (or Registry or...) variables */ 1456 GSM_Config *CurrentConfig; /* Config file (or Registry or...) variables */
1441 int ConfigNum; 1457 int ConfigNum;
1442 INI_Section *msg; /* Localisation strings structure */ 1458 INI_Section *msg; /* Localisation strings structure */
1443 int ReplyNum; /* How many times make sth. */ 1459 int ReplyNum; /* How many times make sth. */
1444 int Speed; /* For some protocols used speed */ 1460 int Speed; /* For some protocols used speed */
1445 1461
1446 GSM_Device Device; 1462 GSM_Device Device;
1447 GSM_Protocol Protocol; 1463 GSM_Protocol Protocol;
1448 GSM_Phone Phone; 1464 GSM_Phone Phone;
1449 GSM_User User; 1465 GSM_User User;
1450}; 1466};
1451 1467
1452/* ------------------------ Other general definitions ---------------------- */ 1468/* ------------------------ Other general definitions ---------------------- */
1453 1469
1454 GSM_Error GSM_RegisterAllPhoneModules(GSM_StateMachine *s); 1470 GSM_Error GSM_RegisterAllPhoneModules(GSM_StateMachine *s);
1455 1471
1456 GSM_Error GSM_InitConnection (GSM_StateMachine *s, int ReplyNum); 1472 GSM_Error GSM_InitConnection (GSM_StateMachine *s, int ReplyNum);
1457 GSM_Error GSM_TerminateConnection(GSM_StateMachine *s); 1473 GSM_Error GSM_TerminateConnection(GSM_StateMachine *s);
1458 1474
1459 int GSM_ReadDevice (GSM_StateMachine *s, bool wait); 1475 int GSM_ReadDevice (GSM_StateMachine *s, bool wait);
1460 1476
1461 GSM_Error GSM_WaitForOnce (GSM_StateMachine *s, unsigned char *buffer, 1477 GSM_Error GSM_WaitForOnce (GSM_StateMachine *s, unsigned char *buffer,
1462 int length, unsigned char type, int time); 1478 int length, unsigned char type, int time);
1463 1479
1464 GSM_Error GSM_WaitFor (GSM_StateMachine *s, unsigned char *buffer, 1480 GSM_Error GSM_WaitFor (GSM_StateMachine *s, unsigned char *buffer,
1465 int length, unsigned char type, int time, 1481 int length, unsigned char type, int time,
1466 GSM_Phone_RequestID request); 1482 GSM_Phone_RequestID request);
1467 1483
1468 GSM_Error GSM_DispatchMessage (GSM_StateMachine *s); 1484 GSM_Error GSM_DispatchMessage (GSM_StateMachine *s);
1469 1485
1470 INI_Section *GSM_FindGammuRC(void); 1486 INI_Section *GSM_FindGammuRC(void);
1471 1487
1472 bool GSM_ReadConfig (INI_Section *cfg_info, GSM_Config *cfg, int num); 1488 bool GSM_ReadConfig (INI_Section *cfg_info, GSM_Config *cfg, int num);
1473 1489
1474 void GSM_DumpMessageLevel2 (GSM_StateMachine *s, unsigned char *message, int messagesize, int type); 1490 void GSM_DumpMessageLevel2 (GSM_StateMachine *s, unsigned char *message, int messagesize, int type);
1475 void GSM_DumpMessageLevel3 (GSM_StateMachine *s, unsigned char *message, int messagesize, int type); 1491 void GSM_DumpMessageLevel3 (GSM_StateMachine *s, unsigned char *message, int messagesize, int type);
1476 1492
1477/* ---------------------- Phone features ----------------------------------- */ 1493/* ---------------------- Phone features ----------------------------------- */
1478 1494
1479typedef enum { 1495typedef enum {
1480 /* n6110.c */ 1496 /* n6110.c */
1481 F_CAL33 = 1, /* Calendar,3310 style - 10 reminders, Unicode, 3 coding types*/ 1497 F_CAL33 = 1, /* Calendar,3310 style - 10 reminders, Unicode, 3 coding types*/
1482 F_CAL52, /* Calendar,5210 style - full Unicode, etc. */ 1498 F_CAL52, /* Calendar,5210 style - full Unicode, etc. */
1483 F_CAL82, /* Calendar,8250 style - "normal", but with Unicode */ 1499 F_CAL82, /* Calendar,8250 style - "normal", but with Unicode */
1484 F_RING_SM, /* Ringtones returned in SM format - 33xx */ 1500 F_RING_SM, /* Ringtones returned in SM format - 33xx */
1485 F_NORING, /* No ringtones */ 1501 F_NORING, /* No ringtones */
1486 F_NOPBKUNICODE, /* No phonebook in Unicode */ 1502 F_NOPBKUNICODE, /* No phonebook in Unicode */
1487 F_NOWAP, /* No WAP */ 1503 F_NOWAP, /* No WAP */
1488 F_NOCALLER, /* No caller groups */ 1504 F_NOCALLER, /* No caller groups */
1489 F_NOPICTURE, /* No Picture Images */ 1505 F_NOPICTURE, /* No Picture Images */
1490 F_NOPICTUREUNI, /* No Picture Images text in Unicode */ 1506 F_NOPICTUREUNI, /* No Picture Images text in Unicode */
1491 F_NOSTARTUP, /* No startup logo */ 1507 F_NOSTARTUP, /* No startup logo */
1492 F_NOCALENDAR, /* No calendar */ 1508 F_NOCALENDAR, /* No calendar */
1493 F_NOSTARTANI, /* Startup logo is not animated */ 1509 F_NOSTARTANI, /* Startup logo is not animated */
1494 F_POWER_BATT, /* Network and battery level get from netmonitor */ 1510 F_POWER_BATT, /* Network and battery level get from netmonitor */
1495 F_PROFILES33, /* Phone profiles in 3310 style */ 1511 F_PROFILES33, /* Phone profiles in 3310 style */
1496 F_PROFILES51, /* Phone profiles in 5110 style */ 1512 F_PROFILES51, /* Phone profiles in 5110 style */
1497 F_MAGICBYTES, /* Phone can make authentication with magic bytes */ 1513 F_MAGICBYTES, /* Phone can make authentication with magic bytes */
1498 F_NODTMF, /* Phone can't send DTMF */ 1514 F_NODTMF, /* Phone can't send DTMF */
1499 F_DISPSTATUS, /* Phone return display status */ 1515 F_DISPSTATUS, /* Phone return display status */
1500 F_NOCALLINFO, 1516 F_NOCALLINFO,
1501 1517
1502 /* n3320.c */ 1518 /* n3320.c */
1503 F_DAYMONTH, /* Day and month reversed in pbk, when compare to GSM models*/ 1519 F_DAYMONTH, /* Day and month reversed in pbk, when compare to GSM models*/
1504 1520
1505 /* n6510.c */ 1521 /* n6510.c */
1506 F_PBK35, /* Phonebook in 3510 style with ringtones ID */ 1522 F_PBK35, /* Phonebook in 3510 style with ringtones ID */
1507 F_PBKIMG, /* Phonebook in 7250 style with picture ID */ 1523 F_PBKIMG, /* Phonebook in 7250 style with picture ID */
1508 F_PBKTONEGAL,/* Phonebook with selecting ringtones from gallery */ 1524 F_PBKTONEGAL,/* Phonebook with selecting ringtones from gallery */
1509 F_PBKSMSLIST, /* Phonebook with SMS list */ 1525 F_PBKSMSLIST, /* Phonebook with SMS list */
1510 F_PBKUSER, /* Phonebook with user ID */ 1526 F_PBKUSER, /* Phonebook with user ID */
1511 F_RADIO, /* Phone with FM radio */ 1527 F_RADIO, /* Phone with FM radio */
1512 F_TODO63, /* ToDo in 6310 style - 0x55 msg type */ 1528 F_TODO63, /* ToDo in 6310 style - 0x55 msg type */
1513 F_TODO66, /* ToDo in 6610 style - like calendar, with date and other*/ 1529 F_TODO66, /* ToDo in 6610 style - like calendar, with date and other*/
1514 F_NOMIDI, /* No ringtones in MIDI */ 1530 F_NOMIDI, /* No ringtones in MIDI */
1515 F_BLUETOOTH, /* Bluetooth support */ 1531 F_BLUETOOTH, /* Bluetooth support */
1516 F_NOFILESYSTEM, /* No images, ringtones, java saved in special filesystem*/ 1532 F_NOFILESYSTEM, /* No images, ringtones, java saved in special filesystem*/
1517 F_NOMMS, /* No MMS sets in phone */ 1533 F_NOMMS, /* No MMS sets in phone */
1518 F_NOGPRSPOINT, /* GPRS point are not useable */ 1534 F_NOGPRSPOINT, /* GPRS point are not useable */
1519 F_CAL35, /* Calendar,3510 style - Reminder,Call,Birthday */ 1535 F_CAL35, /* Calendar,3510 style - Reminder,Call,Birthday */
1520 F_CAL65, /* Calendar,6510 style - CBMM, method 3 */ 1536 F_CAL65, /* Calendar,6510 style - CBMM, method 3 */
1521 F_WAPMMSPROXY, /* WAP & MMS settings contains first & second proxy */ 1537 F_WAPMMSPROXY, /* WAP & MMS settings contains first & second proxy */
1522 1538
1523 /* n6510.c && n7110.c */ 1539 /* n6510.c && n7110.c */
1524 F_VOICETAGS, /* Voice tags available */ 1540 F_VOICETAGS, /* Voice tags available */
1525 F_CAL62, /* Calendar,6210 style - Call,Birthday,Memo,Meeting */ 1541 F_CAL62, /* Calendar,6210 style - Call,Birthday,Memo,Meeting */
1542 F_NOTES,
1526 1543
1527 /* AT modules */ 1544 /* AT modules */
1528 F_SMSONLYSENT, /* Phone supports only sent/unsent messages */ 1545 F_SMSONLYSENT, /* Phone supports only sent/unsent messages */
1529 F_BROKENCPBS, /* CPBS on some memories can hang phone */ 1546 F_BROKENCPBS, /* CPBS on some memories can hang phone */
1530 F_M20SMS, /* Siemens M20 like SMS handling */ 1547 F_M20SMS, /* Siemens M20 like SMS handling */
1531 F_SLOWWRITE, /* Use slower writing which some phone need */ 1548 F_SLOWWRITE, /* Use slower writing which some phone need */
1532 F_SMSME900, /* SMS in ME start from location 900 - case of Sagem */ 1549 F_SMSME900, /* SMS in ME start from location 900 - case of Sagem */
1533 F_ALCATEL /* Phone supports Alcatel protocol */ 1550 F_ALCATEL /* Phone supports Alcatel protocol */
1534} Feature; 1551} Feature;
1535 1552
1536/* For models table */ 1553/* For models table */
1537struct _OnePhoneModel { 1554struct _OnePhoneModel {
1538 char *model; 1555 char *model;
1539 char *number; 1556 char *number;
1540 char *irdamodel; 1557 char *irdamodel;
1541 Feature features[12]; 1558 Feature features[12];
1542}; 1559};
1543 1560
1544 bool IsPhoneFeatureAvailable(OnePhoneModel *model, Feature feature); 1561 bool IsPhoneFeatureAvailable(OnePhoneModel *model, Feature feature);
1545 OnePhoneModel *GetModelData (char *model, char *number, char *irdamodel); 1562 OnePhoneModel *GetModelData (char *model, char *number, char *irdamodel);
1546 1563
1547#ifdef __GNUC__ 1564#ifdef __GNUC__
1548__attribute__((format(printf, 2, 3))) 1565__attribute__((format(printf, 2, 3)))
1549#endif 1566#endif
1550int smprintf(GSM_StateMachine *s, const char *format, ...); 1567int smprintf(GSM_StateMachine *s, const char *format, ...);
1551 1568
1552void GSM_OSErrorInfo(GSM_StateMachine *s, char *description); 1569void GSM_OSErrorInfo(GSM_StateMachine *s, char *description);
1553 1570
1554#ifdef GSM_ENABLE_BACKUP 1571#ifdef GSM_ENABLE_BACKUP
1555void GSM_GetPhoneFeaturesForBackup(GSM_StateMachine *s, GSM_Backup_Info *info); 1572void GSM_GetPhoneFeaturesForBackup(GSM_StateMachine *s, GSM_Backup_Info *info);
1556#endif 1573#endif
1557 1574
1558#endif 1575#endif
1559 1576
1560/* How should editor hadle tabs in this file? Add editor commands here. 1577/* How should editor hadle tabs in this file? Add editor commands here.
1561 * vim: noexpandtab sw=8 ts=8 sts=8: 1578 * vim: noexpandtab sw=8 ts=8 sts=8:
1562 */ 1579 */
diff --git a/gammu/emb/common/misc/coding/coding.c b/gammu/emb/common/misc/coding/coding.c
index 62543ac..b30b645 100644
--- a/gammu/emb/common/misc/coding/coding.c
+++ b/gammu/emb/common/misc/coding/coding.c
@@ -1,210 +1,363 @@
1/* (c) 2002-2004 by Marcin Wiacek, Michal Cihar and others */ 1/* (c) 2002-2004 by Marcin Wiacek, Michal Cihar and others */
2/* based on some work from MyGnokii and Gnokii */ 2/* based on some work from MyGnokii (www.mwiacek.com) */
3/* based on some work from Gnokii (www.gnokii.org)
4 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
5 * GNU GPL version 2 or later
6 */
3 7
4#include <stdio.h> 8#include <stdio.h>
5#include <stdlib.h> 9#include <stdlib.h>
6#include <string.h> 10#include <string.h>
7#include <ctype.h> 11#include <ctype.h>
8#include <locale.h> 12#include <locale.h>
9#ifndef __OpenBSD__ 13#ifndef __OpenBSD__
10# include <wctype.h> 14# include <wctype.h>
11#endif 15#endif
12#ifdef WIN32 16#ifdef WIN32
13# include "windows.h" 17# include "windows.h"
14#endif 18#endif
15 19
16#include "../misc.h" 20#include "../misc.h"
17#include "coding.h" 21#include "coding.h"
18 22
23/* function changes #10 #13 chars to \n \r */
24char *EncodeUnicodeSpecialChars(unsigned char *buffer)
25{
26 int Pos=0, Pos2=0;
27 static unsigned charBuf[20000];
28
29 while (buffer[Pos*2]!=0x00 || buffer[Pos*2+1]!=0x00) {
30 if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] == 10) {
31 Buf[Pos2*2] = 0x00;
32 Buf[Pos2*2+1] = '\\';
33 Pos2++;
34 Buf[Pos2*2] = 0x00;
35 Buf[Pos2*2+1] = 'n';
36 Pos2++;
37 } else if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] == 13) {
38 Buf[Pos2*2] = 0x00;
39 Buf[Pos2*2+1] = '\\';
40 Pos2++;
41 Buf[Pos2*2] = 0x00;
42 Buf[Pos2*2+1] = 'r';
43 Pos2++;
44 } else if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] == '\\') {
45 Buf[Pos2*2] = 0x00;
46 Buf[Pos2*2+1] = '\\';
47 Pos2++;
48 Buf[Pos2*2] = 0x00;
49 Buf[Pos2*2+1] = '\\';
50 Pos2++;
51 } else {
52 Buf[Pos2*2] = buffer[Pos*2];
53 Buf[Pos2*2+1] = buffer[Pos*2+1];
54 Pos2++;
55 }
56 Pos++;
57 }
58 Buf[Pos2*2] = 0;
59 Buf[Pos2*2+1] = 0;
60 return Buf;
61}
62
63/* function changes #10 #13 chars to \n \r */
64char *EncodeSpecialChars(unsigned char *buffer)
65{
66 int Pos=0, Pos2=0;
67 static unsigned charBuf[10000];
68
69 while (buffer[Pos]!=0x00) {
70 switch (buffer[Pos]) {
71 case 10:
72 Buf[Pos2++] = '\\';
73 Buf[Pos2++] = 'n';
74 break;
75 case 13:
76 Buf[Pos2++] = '\\';
77 Buf[Pos2++] = 'r';
78 break;
79 case '\\':
80 Buf[Pos2++] = '\\';
81 Buf[Pos2++] = '\\';
82 break;
83 default:
84 Buf[Pos2++] = buffer[Pos];
85 }
86 Pos++;
87 }
88 Buf[Pos2] = 0;
89 return Buf;
90}
91
92char *DecodeUnicodeSpecialChars(unsigned char *buffer)
93{
94 int Pos=0, Pos2=0, level=0;
95 static unsigned charBuf[10000];
96
97 while (buffer[Pos*2]!=0x00 || buffer[Pos*2+1]!=0x00) {
98 Buf[Pos2*2] = buffer[Pos*2];
99 Buf[Pos2*2+1] = buffer[Pos*2+1];
100 switch (level) {
101 case 0:
102 if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] == '\\') {
103 level = 1;
104 } else {
105 Pos2++;
106 }
107 break;
108 case 1:
109 if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] == 'n') {
110 Buf[Pos2*2] = 0;
111 Buf[Pos2*2+1] = 10;
112 }
113 if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] == 'r') {
114 Buf[Pos2*2] = 0;
115 Buf[Pos2*2+1] = 13;
116 }
117 if (buffer[Pos*2] == 0x00 && buffer[Pos*2+1] == '\\') {
118 Buf[Pos2*2] = 0;
119 Buf[Pos2*2+1] = '\\';
120 }
121 Pos2++;
122 level = 0;
123 }
124 Pos++;
125 }
126 Buf[Pos2*2] = 0;
127 Buf[Pos2*2+1] = 0;
128 return Buf;
129}
130
131char *DecodeSpecialChars(unsigned char *buffer)
132{
133 int Pos=0, Pos2=0, level=0;
134 static unsigned charBuf[10000];
135
136 while (buffer[Pos]!=0x00) {
137 Buf[Pos2] = buffer[Pos];
138 switch (level) {
139 case 0:
140 if (buffer[Pos] == '\\') {
141 level = 1;
142 } else {
143 Pos2++;
144 }
145 break;
146 case 1:
147 if (buffer[Pos] == 'n') Buf[Pos2] = 10;
148 if (buffer[Pos] == 'r') Buf[Pos2] = 13;
149 if (buffer[Pos] == '\\') Buf[Pos2] = '\\';
150 Pos2++;
151 level = 0;
152 }
153 Pos++;
154 }
155 Buf[Pos2] = 0;
156 return Buf;
157}
158
159char *mystrcasestr(unsigned const char *a, unsigned const char *b)
160{
161 unsigned char A[2000], B[200];
162 int i;
163
164 memset(A,0,sizeof(A));
165 memset(B,0,sizeof(B));
166 for (i=0;i<(int)strlen(a);i++) A[i] = tolower(a[i]);
167 for (i=0;i<(int)strlen(b);i++) B[i] = tolower(b[i]);
168
169 return strstr(A,B);
170}
171
19unsigned int UnicodeLength(const unsigned char *str) 172unsigned int UnicodeLength(const unsigned char *str)
20{ 173{
21 unsigned int len = 0; 174 unsigned int len = 0;
22 175
23 if (str == NULL) return 0; 176 if (str == NULL) return 0;
24 177
25 while(str[len*2] != 0 || str[len*2+1] != 0) len++; 178 while(str[len*2] != 0 || str[len*2+1] != 0) len++;
26 179
27 return len; 180 return len;
28} 181}
29 182
30/* Convert Unicode char saved in src to dest */ 183/* Convert Unicode char saved in src to dest */
31unsigned int EncodeWithUnicodeAlphabet(const unsigned char *src, wchar_t *dest) 184unsigned int EncodeWithUnicodeAlphabet(const unsigned char *src, wchar_t *dest)
32{ 185{
33 char retval; 186 char retval;
34 187
35 switch (retval = mbtowc(dest, src, MB_CUR_MAX)) { 188 switch (retval = mbtowc(dest, src, MB_CUR_MAX)) {
36 case -1 : 189 case -1 :
37 case 0 : return 1; 190 case 0 : return 1;
38 default : return retval; 191 default : return retval;
39 } 192 }
40} 193}
41 194
42/* Convert Unicode char saved in src to dest */ 195/* Convert Unicode char saved in src to dest */
43unsigned int DecodeWithUnicodeAlphabet(wchar_t src, unsigned char *dest) 196unsigned int DecodeWithUnicodeAlphabet(wchar_t src, unsigned char *dest)
44{ 197{
45 int retval; 198 int retval;
46 199
47 switch (retval = wctomb(dest, src)) { 200 switch (retval = wctomb(dest, src)) {
48 case -1: 201 case -1:
49 *dest = '?'; 202 *dest = '?';
50 return 1; 203 return 1;
51 default: 204 default:
52 return retval; 205 return retval;
53 } 206 }
54} 207}
55 208
56void DecodeUnicode (const unsigned char *src, unsigned char *dest) 209void DecodeUnicode (const unsigned char *src, unsigned char *dest)
57{ 210{
58 int i=0,o=0; 211 int i=0,o=0;
59 wchar_t wc; 212 wchar_t wc;
60 213
61 while (src[(2*i)+1]!=0x00 || src[2*i]!=0x00) { 214 while (src[(2*i)+1]!=0x00 || src[2*i]!=0x00) {
62 wc = src[(2*i)+1] | (src[2*i] << 8); 215 wc = src[(2*i)+1] | (src[2*i] << 8);
63 o += DecodeWithUnicodeAlphabet(wc, dest + o); 216 o += DecodeWithUnicodeAlphabet(wc, dest + o);
64 i++; 217 i++;
65 } 218 }
66 dest[o]=0; 219 dest[o]=0;
67} 220}
68 221
69/* Decode Unicode string and return as function result */ 222/* Decode Unicode string and return as function result */
70unsigned char *DecodeUnicodeString (const unsigned char *src) 223unsigned char *DecodeUnicodeString (const unsigned char *src)
71{ 224{
72 static char dest[500]; 225 static char dest[500];
73 226
74 DecodeUnicode(src,dest); 227 DecodeUnicode(src,dest);
75 return dest; 228 return dest;
76} 229}
77 230
78/* Decode Unicode string to UTF8 or other console charset 231/* Decode Unicode string to UTF8 or other console charset
79 * and return as function result 232 * and return as function result
80 */ 233 */
81unsigned char *DecodeUnicodeConsole(const unsigned char *src) 234unsigned char *DecodeUnicodeConsole(const unsigned char *src)
82{ 235{
83 static char dest[500]; 236 static char dest[500];
84 237
85 if (di.coding[0] != 0) { 238 if (di.coding[0] != 0) {
86 if (!strcmp(di.coding,"utf8")) { 239 if (!strcmp(di.coding,"utf8")) {
87 EncodeUTF8(dest, src); 240 EncodeUTF8(dest, src);
88 } else { 241 } else {
89#ifdef WIN32 242#ifdef WIN32
90 setlocale(LC_ALL, di.coding); 243 setlocale(LC_ALL, di.coding);
91#endif 244#endif
92 DecodeUnicode(src,dest); 245 DecodeUnicode(src,dest);
93 } 246 }
94 } else { 247 } else {
95#ifdef WIN32 248#ifdef WIN32
96 setlocale(LC_ALL, ".OCP"); 249 setlocale(LC_ALL, ".OCP");
97#endif 250#endif
98 DecodeUnicode(src,dest); 251 DecodeUnicode(src,dest);
99#ifdef WIN32 252#ifdef WIN32
100 setlocale(LC_ALL, ".ACP"); 253 setlocale(LC_ALL, ".ACP");
101#endif 254#endif
102 } 255 }
103 return dest; 256 return dest;
104} 257}
105 258
106/* Encode string to Unicode. Len is number of input chars */ 259/* Encode string to Unicode. Len is number of input chars */
107void EncodeUnicode (unsigned char *dest, const unsigned char *src, int len) 260void EncodeUnicode (unsigned char *dest, const unsigned char *src, int len)
108{ 261{
109 int i_len = 0, o_len; 262 int i_len = 0, o_len;
110 wchar_t wc; 263 wchar_t wc;
111 264
112 for (o_len = 0; i_len < len; o_len++) { 265 for (o_len = 0; i_len < len; o_len++) {
113 i_len += EncodeWithUnicodeAlphabet(&src[i_len], &wc); 266 i_len += EncodeWithUnicodeAlphabet(&src[i_len], &wc);
114 dest[o_len*2] = (wc >> 8) & 0xff; 267 dest[o_len*2] = (wc >> 8) & 0xff;
115 dest[(o_len*2)+1]= wc & 0xff; 268 dest[(o_len*2)+1]= wc & 0xff;
116 } 269 }
117 dest[o_len*2] = 0; 270 dest[o_len*2] = 0;
118 dest[(o_len*2)+1]= 0; 271 dest[(o_len*2)+1]= 0;
119} 272}
120 273
121unsigned char EncodeWithBCDAlphabet(int value) 274unsigned char EncodeWithBCDAlphabet(int value)
122{ 275{
123 div_t division; 276 div_t division;
124 277
125 division=div(value,10); 278 division=div(value,10);
126 return ( ( (value-division.quot*10) & 0x0f) << 4) | (division.quot & 0xf); 279 return ( ( (value-division.quot*10) & 0x0f) << 4) | (division.quot & 0xf);
127} 280}
128 281
129int DecodeWithBCDAlphabet(unsigned char value) 282int DecodeWithBCDAlphabet(unsigned char value)
130{ 283{
131 return 10*(value & 0x0f)+(value >> 4); 284 return 10*(value & 0x0f)+(value >> 4);
132} 285}
133 286
134void DecodeBCD (unsigned char *dest, const unsigned char *src, int len) 287void DecodeBCD (unsigned char *dest, const unsigned char *src, int len)
135{ 288{
136 int i,current=0,digit; 289 int i,current=0,digit;
137 290
138 for (i = 0; i < len; i++) { 291 for (i = 0; i < len; i++) {
139 digit=src[i] & 0x0f; 292 digit=src[i] & 0x0f;
140 if (digit<10) dest[current++]=digit + '0'; 293 if (digit<10) dest[current++]=digit + '0';
141 digit=src[i] >> 4; 294 digit=src[i] >> 4;
142 if (digit<10) dest[current++]=digit + '0'; 295 if (digit<10) dest[current++]=digit + '0';
143 } 296 }
144 dest[current++]=0; 297 dest[current++]=0;
145} 298}
146 299
147void EncodeBCD (unsigned char *dest, const unsigned char *src, int len, bool fill) 300void EncodeBCD (unsigned char *dest, const unsigned char *src, int len, bool fill)
148{ 301{
149 int i,current=0; 302 int i,current=0;
150 303
151 for (i = 0; i < len; i++) { 304 for (i = 0; i < len; i++) {
152 if (i & 0x01) { 305 if (i & 0x01) {
153 dest[current]=dest[current] | ((src[i]-'0') << 4); 306 dest[current]=dest[current] | ((src[i]-'0') << 4);
154 current++; 307 current++;
155 } else { 308 } else {
156 dest[current]=src[i]-'0'; 309 dest[current]=src[i]-'0';
157 } 310 }
158 } 311 }
159 312
160 /* When fill is set: if number consist of odd number of digits, 313 /* When fill is set: if number consist of odd number of digits,
161 we fill last bits in last byte with 0x0f 314 we fill last bits in last byte with 0x0f
162 */ 315 */
163 if (fill && (len & 0x01)) dest[current]=dest[current] | 0xf0; 316 if (fill && (len & 0x01)) dest[current]=dest[current] | 0xf0;
164} 317}
165 318
166int DecodeWithHexBinAlphabet (unsigned char mychar) 319int DecodeWithHexBinAlphabet (unsigned char mychar)
167{ 320{
168 if (mychar>='A' && mychar<='F') return mychar-'A'+10; 321 if (mychar>='A' && mychar<='F') return mychar-'A'+10;
169 if (mychar>='a' && mychar<='f') return mychar-'a'+10; 322 if (mychar>='a' && mychar<='f') return mychar-'a'+10;
170 if (mychar>='0' && mychar<='9') return mychar-'0'; 323 if (mychar>='0' && mychar<='9') return mychar-'0';
171 return -1; 324 return -1;
172} 325}
173 326
174unsigned char EncodeWithHexBinAlphabet (int digit) 327unsigned char EncodeWithHexBinAlphabet (int digit)
175{ 328{
176 if (digit >= 0 && digit <= 9) return '0'+(digit); 329 if (digit >= 0 && digit <= 9) return '0'+(digit);
177 if (digit >=10 && digit <=15) return 'A'+(digit-10); 330 if (digit >=10 && digit <=15) return 'A'+(digit-10);
178 return 0; 331 return 0;
179} 332}
180 333
181void DecodeHexUnicode (unsigned char *dest, const unsigned char *src, int len) 334void DecodeHexUnicode (unsigned char *dest, const unsigned char *src, int len)
182{ 335{
183 int i,current=0; 336 int i,current=0;
184 bool first = false; 337 bool first = false;
185 338
186 if (len != 0 && src[0] == '0' && src[1] == '0') { 339 if (len != 0 && src[0] == '0' && src[1] == '0') {
187 first = true; 340 first = true;
188 } else if (len != 0 && src[2] == '0' && src[3] == '0') { 341 } else if (len != 0 && src[2] == '0' && src[3] == '0') {
189 first = false; 342 first = false;
190 } else { 343 } else {
191 first = (10 * (src[0] - '0') + (src[1] - '0')) < (10 * (src[2] - '0')+ (src[3] - '0')); 344 first = (10 * (src[0] - '0') + (src[1] - '0')) < (10 * (src[2] - '0')+ (src[3] - '0'));
192 } 345 }
193 for (i = 0; i < len/4 ; i++) { 346 for (i = 0; i < len/4 ; i++) {
194 if (first) { 347 if (first) {
195 dest[current++] = DecodeWithHexBinAlphabet(src[i*4+0])*16+ 348 dest[current++] = DecodeWithHexBinAlphabet(src[i*4+0])*16+
196 DecodeWithHexBinAlphabet(src[i*4+1]); 349 DecodeWithHexBinAlphabet(src[i*4+1]);
197 dest[current++] = DecodeWithHexBinAlphabet(src[i*4+2])*16+ 350 dest[current++] = DecodeWithHexBinAlphabet(src[i*4+2])*16+
198 DecodeWithHexBinAlphabet(src[i*4+3]); 351 DecodeWithHexBinAlphabet(src[i*4+3]);
199 } else { 352 } else {
200 dest[current++] = DecodeWithHexBinAlphabet(src[i*4+2])*16+ 353 dest[current++] = DecodeWithHexBinAlphabet(src[i*4+2])*16+
201 DecodeWithHexBinAlphabet(src[i*4+3]); 354 DecodeWithHexBinAlphabet(src[i*4+3]);
202 dest[current++] = DecodeWithHexBinAlphabet(src[i*4+0])*16+ 355 dest[current++] = DecodeWithHexBinAlphabet(src[i*4+0])*16+
203 DecodeWithHexBinAlphabet(src[i*4+1]); 356 DecodeWithHexBinAlphabet(src[i*4+1]);
204 } 357 }
205 } 358 }
206 dest[current++] = 0; 359 dest[current++] = 0;
207 dest[current++] = 0; 360 dest[current++] = 0;
208} 361}
209 362
210void EncodeHexUnicode (unsigned char *dest, const unsigned char *src, int len) 363void EncodeHexUnicode (unsigned char *dest, const unsigned char *src, int len)
@@ -397,814 +550,814 @@ void EncodeDefault(unsigned char *dest, const unsigned char *src, int *len, bool
397 if (src[i*2]== GSM_DefaultAlphabetUnicode[j][0] && 550 if (src[i*2]== GSM_DefaultAlphabetUnicode[j][0] &&
398 src[i*2+1]== GSM_DefaultAlphabetUnicode[j][1]) { 551 src[i*2+1]== GSM_DefaultAlphabetUnicode[j][1]) {
399 ret = j; 552 ret = j;
400 FoundNormal = true; 553 FoundNormal = true;
401 break; 554 break;
402 } 555 }
403 j++; 556 j++;
404 } 557 }
405 if (ExtraAlphabet!=NULL && !FoundNormal) { 558 if (ExtraAlphabet!=NULL && !FoundNormal) {
406 j = 0; 559 j = 0;
407 while (ExtraAlphabet[j] != 0x00 || ExtraAlphabet[j+1] != 0x00 || ExtraAlphabet[j+2] != 0x00) { 560 while (ExtraAlphabet[j] != 0x00 || ExtraAlphabet[j+1] != 0x00 || ExtraAlphabet[j+2] != 0x00) {
408 if (ExtraAlphabet[j+1] == src[i*2] && 561 if (ExtraAlphabet[j+1] == src[i*2] &&
409 ExtraAlphabet[j+2] == src[i*2 + 1]) { 562 ExtraAlphabet[j+2] == src[i*2 + 1]) {
410 ret = ExtraAlphabet[j]; 563 ret = ExtraAlphabet[j];
411 FoundSpecial= true; 564 FoundSpecial= true;
412 break; 565 break;
413 } 566 }
414 j=j+3; 567 j=j+3;
415 } 568 }
416 } 569 }
417 if (!FoundNormal && !FoundSpecial) { 570 if (!FoundNormal && !FoundSpecial) {
418 j = 0; 571 j = 0;
419 FoundNormal = false; 572 FoundNormal = false;
420 while (ConvertTable[j*4] != 0x00 || 573 while (ConvertTable[j*4] != 0x00 ||
421 ConvertTable[j*4+1] != 0x00) { 574 ConvertTable[j*4+1] != 0x00) {
422 if (src[i*2] == ConvertTable[j*4] && 575 if (src[i*2] == ConvertTable[j*4] &&
423 src[i*2+1] == ConvertTable[j*4+1]) { 576 src[i*2+1] == ConvertTable[j*4+1]) {
424 z = 0; 577 z = 0;
425 while (GSM_DefaultAlphabetUnicode[z][1]!=0x00) { 578 while (GSM_DefaultAlphabetUnicode[z][1]!=0x00) {
426 if (ConvertTable[j*4+2]== GSM_DefaultAlphabetUnicode[z][0] && 579 if (ConvertTable[j*4+2]== GSM_DefaultAlphabetUnicode[z][0] &&
427 ConvertTable[j*4+3]== GSM_DefaultAlphabetUnicode[z][1]) { 580 ConvertTable[j*4+3]== GSM_DefaultAlphabetUnicode[z][1]) {
428 ret = z; 581 ret = z;
429 FoundNormal = true; 582 FoundNormal = true;
430 break; 583 break;
431 } 584 }
432 z++; 585 z++;
433 } 586 }
434 if (FoundNormal) break; 587 if (FoundNormal) break;
435 } 588 }
436 j++; 589 j++;
437 } 590 }
438 } 591 }
439 dest[current++]=ret; 592 dest[current++]=ret;
440 } 593 }
441 } 594 }
442 dest[current]=0; 595 dest[current]=0;
443#ifdef DEBUG 596#ifdef DEBUG
444 if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) DumpMessage(di.df, di.dl, dest, current); 597 if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) DumpMessage(di.df, di.dl, dest, current);
445#endif 598#endif
446 599
447 *len = current; 600 *len = current;
448} 601}
449 602
450/* You don't have to use ConvertTable here - 1 char is replaced there by 1 char */ 603/* You don't have to use ConvertTable here - 1 char is replaced there by 1 char */
451void FindDefaultAlphabetLen(const unsigned char *src, int *srclen, int *smslen, int maxlen) 604void FindDefaultAlphabetLen(const unsigned char *src, int *srclen, int *smslen, int maxlen)
452{ 605{
453 int current=0,j,i; 606 int current=0,j,i;
454 boolFoundSpecial; 607 boolFoundSpecial;
455 608
456 i = 0; 609 i = 0;
457 while (src[i*2] != 0x00 || src[i*2+1] != 0x00) { 610 while (src[i*2] != 0x00 || src[i*2+1] != 0x00) {
458 FoundSpecial = false; 611 FoundSpecial = false;
459 j = 0; 612 j = 0;
460 while (GSM_DefaultAlphabetCharsExtension[j][0]!=0x00) { 613 while (GSM_DefaultAlphabetCharsExtension[j][0]!=0x00) {
461 if (src[i*2] == GSM_DefaultAlphabetCharsExtension[j][2] && 614 if (src[i*2] == GSM_DefaultAlphabetCharsExtension[j][2] &&
462 src[i*2+1] == GSM_DefaultAlphabetCharsExtension[j][3]) { 615 src[i*2+1] == GSM_DefaultAlphabetCharsExtension[j][3]) {
463 FoundSpecial = true; 616 FoundSpecial = true;
464 if (current+2 > maxlen) { 617 if (current+2 > maxlen) {
465 *srclen = i; 618 *srclen = i;
466 *smslen = current; 619 *smslen = current;
467 return; 620 return;
468 } 621 }
469 current+=2; 622 current+=2;
470 break; 623 break;
471 } 624 }
472 j++; 625 j++;
473 } 626 }
474 if (!FoundSpecial) { 627 if (!FoundSpecial) {
475 if (current+1 > maxlen) { 628 if (current+1 > maxlen) {
476 *srclen = i; 629 *srclen = i;
477 *smslen = current; 630 *smslen = current;
478 return; 631 return;
479 } 632 }
480 current++; 633 current++;
481 } 634 }
482 i++; 635 i++;
483 } 636 }
484 *srclen = i; 637 *srclen = i;
485 *smslen = current; 638 *smslen = current;
486} 639}
487 640
488#ifndef ENABLE_LGPL 641#ifndef ENABLE_LGPL
489# define ByteMask ((1 << Bits) - 1) 642# define ByteMask ((1 << Bits) - 1)
490#endif 643#endif
491 644
492int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length, 645int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length,
493 unsigned char *input, unsigned char *output) 646 unsigned char *input, unsigned char *output)
494{ 647{
495#ifndef ENABLE_LGPL 648#ifndef ENABLE_LGPL
496 /* (c) by Pavel Janik and Pawel Kot */ 649 /* (c) by Pavel Janik and Pawel Kot */
497 650
498 unsigned char *OUTPUT = output; /* Current pointer to the output buffer */ 651 unsigned char *OUTPUT = output; /* Current pointer to the output buffer */
499 unsigned char *INPUT = input; /* Current pointer to the input buffer */ 652 unsigned char *INPUT = input; /* Current pointer to the input buffer */
500 unsigned char Rest = 0x00; 653 unsigned char Rest = 0x00;
501 int Bits; 654 int Bits;
502 655
503 Bits = offset ? offset : 7; 656 Bits = offset ? offset : 7;
504 657
505 while ((INPUT - input) < in_length) { 658 while ((INPUT - input) < in_length) {
506 659
507 *OUTPUT = ((*INPUT & ByteMask) << (7 - Bits)) | Rest; 660 *OUTPUT = ((*INPUT & ByteMask) << (7 - Bits)) | Rest;
508 Rest = *INPUT >> Bits; 661 Rest = *INPUT >> Bits;
509 662
510 /* If we don't start from 0th bit, we shouldn't go to the 663 /* If we don't start from 0th bit, we shouldn't go to the
511 next char. Under *OUTPUT we have now 0 and under Rest - 664 next char. Under *OUTPUT we have now 0 and under Rest -
512 _first_ part of the char. */ 665 _first_ part of the char. */
513 if ((INPUT != input) || (Bits == 7)) OUTPUT++; 666 if ((INPUT != input) || (Bits == 7)) OUTPUT++;
514 INPUT++; 667 INPUT++;
515 668
516 if ((OUTPUT - output) >= out_length) break; 669 if ((OUTPUT - output) >= out_length) break;
517 670
518 /* After reading 7 octets we have read 7 full characters but 671 /* After reading 7 octets we have read 7 full characters but
519 we have 7 bits as well. This is the next character */ 672 we have 7 bits as well. This is the next character */
520 if (Bits == 1) { 673 if (Bits == 1) {
521 *OUTPUT = Rest; 674 *OUTPUT = Rest;
522 OUTPUT++; 675 OUTPUT++;
523 Bits = 7; 676 Bits = 7;
524 Rest = 0x00; 677 Rest = 0x00;
525 } else { 678 } else {
526 Bits--; 679 Bits--;
527 } 680 }
528 } 681 }
529 682
530 return OUTPUT - output; 683 return OUTPUT - output;
531#else 684#else
532 return 0; 685 return 0;
533#endif 686#endif
534} 687}
535 688
536int GSM_PackSevenBitsToEight(int offset, unsigned char *input, unsigned char *output, int length) 689int GSM_PackSevenBitsToEight(int offset, unsigned char *input, unsigned char *output, int length)
537{ 690{
538#ifndef ENABLE_LGPL 691#ifndef ENABLE_LGPL
539 /* (c) by Pavel Janik and Pawel Kot */ 692 /* (c) by Pavel Janik and Pawel Kot */
540 693
541 unsigned char *OUTPUT = output; /* Current pointer to the output buffer */ 694 unsigned char *OUTPUT = output; /* Current pointer to the output buffer */
542 unsigned char *INPUT = input; /* Current pointer to the input buffer */ 695 unsigned char *INPUT = input; /* Current pointer to the input buffer */
543 int Bits; /* Number of bits directly copied to 696 int Bits; /* Number of bits directly copied to
544 * the output buffer */ 697 * the output buffer */
545 Bits = (7 + offset) % 8; 698 Bits = (7 + offset) % 8;
546 699
547 /* If we don't begin with 0th bit, we will write only a part of the 700 /* If we don't begin with 0th bit, we will write only a part of the
548 first octet */ 701 first octet */
549 if (offset) { 702 if (offset) {
550 *OUTPUT = 0x00; 703 *OUTPUT = 0x00;
551 OUTPUT++; 704 OUTPUT++;
552 } 705 }
553 706
554 while ((INPUT - input) < length) { 707 while ((INPUT - input) < length) {
555 unsigned char Byte = *INPUT; 708 unsigned char Byte = *INPUT;
556 709
557 *OUTPUT = Byte >> (7 - Bits); 710 *OUTPUT = Byte >> (7 - Bits);
558 /* If we don't write at 0th bit of the octet, we should write 711 /* If we don't write at 0th bit of the octet, we should write
559 a second part of the previous octet */ 712 a second part of the previous octet */
560 if (Bits != 7) 713 if (Bits != 7)
561 *(OUTPUT-1) |= (Byte & ((1 << (7-Bits)) - 1)) << (Bits+1); 714 *(OUTPUT-1) |= (Byte & ((1 << (7-Bits)) - 1)) << (Bits+1);
562 715
563 Bits--; 716 Bits--;
564 717
565 if (Bits == -1) Bits = 7; else OUTPUT++; 718 if (Bits == -1) Bits = 7; else OUTPUT++;
566 719
567 INPUT++; 720 INPUT++;
568 } 721 }
569 return (OUTPUT - output); 722 return (OUTPUT - output);
570#else 723#else
571 return 0; 724 return 0;
572#endif 725#endif
573} 726}
574 727
575void GSM_UnpackSemiOctetNumber(unsigned char *retval, unsigned char *Number, bool semioctet) 728void GSM_UnpackSemiOctetNumber(unsigned char *retval, unsigned char *Number, bool semioctet)
576{ 729{
577 unsigned char Buffer[50]= ""; 730 unsigned char Buffer[50]= "";
578 int length = Number[0]; 731 int length = Number[0];
579 732
580 if (semioctet) { 733 if (semioctet) {
581 /* Convert number of semioctets to number of chars */ 734 /* Convert number of semioctets to number of chars */
582 if (length % 2) length++; 735 if (length % 2) length++;
583 length=length / 2 + 1; 736 length=length / 2 + 1;
584 } 737 }
585 738
586 /*without leading byte with format of number*/ 739 /*without leading byte with format of number*/
587 length--; 740 length--;
588 741
589 switch (Number[1]) { 742 switch ((Number[1] & 112)) {
590 case NUMBER_ALPHANUMERIC: 743 case (NUMBER_ALPHANUMERIC_NUMBERING_PLAN_UNKNOWN & 112):
591 if (length > 6) length++; 744 if (length > 6) length++;
592 dbgprintf("Alphanumeric number, length %i\n",length); 745 dbgprintf("Alphanumeric number, length %i\n",length);
593 GSM_UnpackEightBitsToSeven(0, length, length, Number+2, Buffer); 746 GSM_UnpackEightBitsToSeven(0, length, length, Number+2, Buffer);
594 Buffer[length]=0; 747 Buffer[length]=0;
595 break; 748 break;
596 case NUMBER_INTERNATIONAL: 749 case (NUMBER_INTERNATIONAL_NUMBERING_PLAN_ISDN & 112):
597 dbgprintf("International number\n"); 750 dbgprintf("International number\n");
598 Buffer[0]='+'; 751 Buffer[0]='+';
599 DecodeBCD(Buffer+1,Number+2, length); 752 DecodeBCD(Buffer+1,Number+2, length);
600 break; 753 break;
601 default: 754 default:
602 dbgprintf("Default number %02x\n",Number[1]); 755 dbgprintf("Default number %02x\n",Number[1]);
603 DecodeBCD (Buffer, Number+2, length); 756 DecodeBCD (Buffer, Number+2, length);
604 break; 757 break;
605 } 758 }
606 759
607 EncodeUnicode(retval,Buffer,strlen(Buffer)); 760 EncodeUnicode(retval,Buffer,strlen(Buffer));
608} 761}
609 762
610/** 763/**
611 * Packing some phone numbers (SMSC, SMS destination and others) 764 * Packing some phone numbers (SMSC, SMS destination and others)
612 * 765 *
613 * See GSM 03.40 9.1.1: 766 * See GSM 03.40 9.1.1:
614 * 1 byte - length of number given in semioctets or bytes (when given in 767 * 1 byte - length of number given in semioctets or bytes (when given in
615 * bytes, includes one byte for byte with number format). 768 * bytes, includes one byte for byte with number format).
616 * Returned by function (set semioctet to true, if want result 769 * Returned by function (set semioctet to true, if want result
617 * in semioctets). 770 * in semioctets).
618 * 1 byte - format of number (see GSM_NumberType in coding.h). Returned 771 * 1 byte - format of number (see GSM_NumberType in coding.h). Returned
619 * in unsigned char *Output. 772 * in unsigned char *Output.
620 * n bytes - 2n or 2n-1 semioctets with number. Returned in unsigned char 773 * n bytes - 2n or 2n-1 semioctets with number. Returned in unsigned char
621 * *Output. 774 * *Output.
622 * 775 *
623 * 1 semioctet = 4 bits = half of byte 776 * 1 semioctet = 4 bits = half of byte
624 */ 777 */
625int GSM_PackSemiOctetNumber(unsigned char *Number, unsigned char *Output, bool semioctet) 778int GSM_PackSemiOctetNumber(unsigned char *Number, unsigned char *Output, bool semioctet)
626{ 779{
627 unsigned charformat, buffer[50]; 780 unsigned charformat, buffer[50];
628 int length, i; 781 int length, i;
629 782
630 length=UnicodeLength(Number); 783 length=UnicodeLength(Number);
631 memcpy(buffer,DecodeUnicodeString(Number),length+1); 784 memcpy(buffer,DecodeUnicodeString(Number),length+1);
632 785
633 /* Checking for format number */ 786 /* Checking for format number */
634 format = NUMBER_UNKNOWN; 787 format = NUMBER_UNKNOWN_NUMBERING_PLAN_ISDN;
635 for (i=0;i<length;i++) { 788 for (i=0;i<length;i++) {
636 /* first byte is '+'. Number can be international */ 789 /* first byte is '+'. Number can be international */
637 if (i==0 && buffer[i]=='+') { 790 if (i==0 && buffer[i]=='+') {
638 format=NUMBER_INTERNATIONAL; 791 format=NUMBER_INTERNATIONAL_NUMBERING_PLAN_ISDN;
639 } else { 792 } else {
640 /*char is not number. It must be alphanumeric*/ 793 /*char is not number. It must be alphanumeric*/
641 if (!isdigit(buffer[i])) format=NUMBER_ALPHANUMERIC; 794 if (!isdigit(buffer[i])) format=NUMBER_ALPHANUMERIC_NUMBERING_PLAN_UNKNOWN;
642 } 795 }
643 } 796 }
644 797
645 /** 798 /**
646 * First byte is used for saving type of number. See GSM 03.40 799 * First byte is used for saving type of number. See GSM 03.40
647 * section 9.1.2.5 800 * section 9.1.2.5
648 */ 801 */
649 Output[0]=format; 802 Output[0]=format;
650 803
651 /* After number type we will have number. GSM 03.40 section 9.1.2 */ 804 /* After number type we will have number. GSM 03.40 section 9.1.2 */
652 switch (format) { 805 switch (format) {
653 case NUMBER_ALPHANUMERIC: 806 case NUMBER_ALPHANUMERIC_NUMBERING_PLAN_UNKNOWN:
654 length=GSM_PackSevenBitsToEight(0, buffer, Output+1, strlen(buffer))*2; 807 length=GSM_PackSevenBitsToEight(0, buffer, Output+1, strlen(buffer))*2;
655 if (strlen(buffer)==7) length--; 808 if (strlen(buffer)==7) length--;
656 break; 809 break;
657 case NUMBER_INTERNATIONAL: 810 case NUMBER_INTERNATIONAL_NUMBERING_PLAN_ISDN:
658 length--; 811 length--;
659 EncodeBCD (Output+1, buffer+1, length, true); 812 EncodeBCD (Output+1, buffer+1, length, true);
660 break; 813 break;
661 default: 814 default:
662 EncodeBCD (Output+1, buffer, length, true); 815 EncodeBCD (Output+1, buffer, length, true);
663 break; 816 break;
664 } 817 }
665 818
666 if (semioctet) return length; 819 if (semioctet) return length;
667 820
668 /* Convert number of semioctets to number of chars */ 821 /* Convert number of semioctets to number of chars */
669 if (length % 2) length++; 822 if (length % 2) length++;
670 return length / 2 + 1; 823 return length / 2 + 1;
671} 824}
672 825
673void CopyUnicodeString(unsigned char *Dest, unsigned char *Source) 826void CopyUnicodeString(unsigned char *Dest, unsigned char *Source)
674{ 827{
675 int j = 0; 828 int j = 0;
676 829
677 while (Source[j]!=0x00 || Source[j+1]!=0x00) { 830 while (Source[j]!=0x00 || Source[j+1]!=0x00) {
678 Dest[j] = Source[j]; 831 Dest[j] = Source[j];
679 Dest[j+1]= Source[j+1]; 832 Dest[j+1]= Source[j+1];
680 j=j+2; 833 j=j+2;
681 } 834 }
682 Dest[j] = 0; 835 Dest[j] = 0;
683 Dest[j+1]= 0; 836 Dest[j+1]= 0;
684} 837}
685 838
686/* Changes minor/major order in Unicode string */ 839/* Changes minor/major order in Unicode string */
687void ReverseUnicodeString(unsigned char *String) 840void ReverseUnicodeString(unsigned char *String)
688{ 841{
689 int j = 0; 842 int j = 0;
690 unsigned charbyte1, byte2; 843 unsigned charbyte1, byte2;
691 844
692 while (String[j]!=0x00 || String[j+1]!=0x00) { 845 while (String[j]!=0x00 || String[j+1]!=0x00) {
693 byte1 = String[j]; 846 byte1 = String[j];
694 byte2 = String[j+1]; 847 byte2 = String[j+1];
695 String[j+1]= byte1; 848 String[j+1]= byte1;
696 String[j]= byte2; 849 String[j]= byte2;
697 j=j+2; 850 j=j+2;
698 } 851 }
699 String[j]= 0; 852 String[j]= 0;
700 String[j+1]= 0; 853 String[j+1]= 0;
701} 854}
702 855
703/* All input is in Unicode. First char can show Unicode minor/major order. 856/* All input is in Unicode. First char can show Unicode minor/major order.
704 Output is Unicode string in Gammu minor/major order */ 857 Output is Unicode string in Gammu minor/major order */
705void ReadUnicodeFile(unsigned char *Dest, unsigned char *Source) 858void ReadUnicodeFile(unsigned char *Dest, unsigned char *Source)
706{ 859{
707 int j = 0, current = 0; 860 int j = 0, current = 0;
708 861
709 if (Source[0] == 0xFF && Source[1] == 0xFE) j = 2; 862 if (Source[0] == 0xFF && Source[1] == 0xFE) j = 2;
710 if (Source[0] == 0xFE && Source[1] == 0xFF) j = 2; 863 if (Source[0] == 0xFE && Source[1] == 0xFF) j = 2;
711 864
712 while (Source[j]!=0x00 || Source[j+1]!=0x00) { 865 while (Source[j]!=0x00 || Source[j+1]!=0x00) {
713 if (Source[0] == 0xFF) { 866 if (Source[0] == 0xFF) {
714 Dest[current++] = Source[j+1]; 867 Dest[current++] = Source[j+1];
715 Dest[current++]= Source[j]; 868 Dest[current++]= Source[j];
716 } else { 869 } else {
717 Dest[current++] = Source[j]; 870 Dest[current++] = Source[j];
718 Dest[current++]= Source[j+1]; 871 Dest[current++]= Source[j+1];
719 } 872 }
720 j=j+2; 873 j=j+2;
721 } 874 }
722 Dest[current++] = 0; 875 Dest[current++] = 0;
723 Dest[current++]= 0; 876 Dest[current++]= 0;
724} 877}
725 878
726int GetBit(unsigned char *Buffer, int BitNum) 879int GetBit(unsigned char *Buffer, int BitNum)
727{ 880{
728 return Buffer[BitNum/8] & 1<<(7-(BitNum%8)); 881 return Buffer[BitNum/8] & 1<<(7-(BitNum%8));
729} 882}
730 883
731int SetBit(unsigned char *Buffer, int BitNum) 884int SetBit(unsigned char *Buffer, int BitNum)
732{ 885{
733 return Buffer[BitNum/8] |= 1<<(7-(BitNum%8)); 886 return Buffer[BitNum/8] |= 1<<(7-(BitNum%8));
734} 887}
735 888
736int ClearBit(unsigned char *Buffer, int BitNum) 889int ClearBit(unsigned char *Buffer, int BitNum)
737{ 890{
738 return Buffer[BitNum/8] &= 255 - (1 << (7-(BitNum%8))); 891 return Buffer[BitNum/8] &= 255 - (1 << (7-(BitNum%8)));
739} 892}
740 893
741void BufferAlign(unsigned char *Destination, int *CurrentBit) 894void BufferAlign(unsigned char *Destination, int *CurrentBit)
742{ 895{
743 int i=0; 896 int i=0;
744 897
745 while(((*CurrentBit) + i) % 8 != 0) { 898 while(((*CurrentBit) + i) % 8 != 0) {
746 ClearBit(Destination, (*CurrentBit)+i); 899 ClearBit(Destination, (*CurrentBit)+i);
747 i++; 900 i++;
748 } 901 }
749 902
750 (*CurrentBit) = (*CurrentBit) + i; 903 (*CurrentBit) = (*CurrentBit) + i;
751} 904}
752 905
753void BufferAlignNumber(int *CurrentBit) 906void BufferAlignNumber(int *CurrentBit)
754{ 907{
755 int i=0; 908 int i=0;
756 909
757 while(((*CurrentBit) + i) % 8 != 0) { 910 while(((*CurrentBit) + i) % 8 != 0) {
758 i++; 911 i++;
759 } 912 }
760 913
761 (*CurrentBit) = (*CurrentBit) + i; 914 (*CurrentBit) = (*CurrentBit) + i;
762} 915}
763 916
764 void AddBuffer(unsigned char *Destination, 917 void AddBuffer(unsigned char *Destination,
765 int *CurrentBit, 918 int *CurrentBit,
766 unsigned char *Source, 919 unsigned char *Source,
767 int BitsToProcess) 920 int BitsToProcess)
768{ 921{
769 int i=0; 922 int i=0;
770 923
771 while (i!=BitsToProcess) { 924 while (i!=BitsToProcess) {
772 if (GetBit(Source, i)) { 925 if (GetBit(Source, i)) {
773 SetBit(Destination, (*CurrentBit)+i); 926 SetBit(Destination, (*CurrentBit)+i);
774 } else { 927 } else {
775 ClearBit(Destination, (*CurrentBit)+i); 928 ClearBit(Destination, (*CurrentBit)+i);
776 } 929 }
777 i++; 930 i++;
778 } 931 }
779 (*CurrentBit) = (*CurrentBit) + BitsToProcess; 932 (*CurrentBit) = (*CurrentBit) + BitsToProcess;
780} 933}
781 934
782void AddBufferByte(unsigned char *Destination, 935void AddBufferByte(unsigned char *Destination,
783 int *CurrentBit, 936 int *CurrentBit,
784 unsigned char Source, 937 unsigned char Source,
785 int BitsToProcess) 938 int BitsToProcess)
786{ 939{
787 unsigned char Byte; 940 unsigned char Byte;
788 941
789 Byte = Source; 942 Byte = Source;
790 943
791 AddBuffer(Destination, CurrentBit, &Byte, BitsToProcess); 944 AddBuffer(Destination, CurrentBit, &Byte, BitsToProcess);
792} 945}
793 946
794void GetBuffer(unsigned char *Source, 947void GetBuffer(unsigned char *Source,
795 int *CurrentBit, 948 int *CurrentBit,
796 unsigned char *Destination, 949 unsigned char *Destination,
797 int BitsToProcess) 950 int BitsToProcess)
798{ 951{
799 int i=0; 952 int i=0;
800 953
801 while (i!=BitsToProcess) { 954 while (i!=BitsToProcess) {
802 if (GetBit(Source, (*CurrentBit)+i)) { 955 if (GetBit(Source, (*CurrentBit)+i)) {
803 SetBit(Destination, i); 956 SetBit(Destination, i);
804 } else { 957 } else {
805 ClearBit(Destination, i); 958 ClearBit(Destination, i);
806 } 959 }
807 i++; 960 i++;
808 } 961 }
809 (*CurrentBit) = (*CurrentBit) + BitsToProcess; 962 (*CurrentBit) = (*CurrentBit) + BitsToProcess;
810} 963}
811 964
812void GetBufferInt(unsigned char *Source, 965void GetBufferInt(unsigned char *Source,
813 int *CurrentBit, 966 int *CurrentBit,
814 int *integer, 967 int *integer,
815 int BitsToProcess) 968 int BitsToProcess)
816{ 969{
817 int l=0,z=128,i=0; 970 int l=0,z=128,i=0;
818 971
819 while (i!=BitsToProcess) { 972 while (i!=BitsToProcess) {
820 if (GetBit(Source, (*CurrentBit)+i)) l=l+z; 973 if (GetBit(Source, (*CurrentBit)+i)) l=l+z;
821 z=z/2; 974 z=z/2;
822 i++; 975 i++;
823 } 976 }
824 *integer=l; 977 *integer=l;
825 (*CurrentBit) = (*CurrentBit) + i; 978 (*CurrentBit) = (*CurrentBit) + i;
826} 979}
827 980
828 void GetBufferI(unsigned char *Source, 981 void GetBufferI(unsigned char *Source,
829 int *CurrentBit, 982 int *CurrentBit,
830 int *result, 983 int *result,
831 int BitsToProcess) 984 int BitsToProcess)
832{ 985{
833 int l=0,z,i=0; 986 int l=0,z,i=0;
834 987
835 z = 1<<(BitsToProcess-1); 988 z = 1<<(BitsToProcess-1);
836 989
837 while (i!=BitsToProcess) { 990 while (i!=BitsToProcess) {
838 if (GetBit(Source, (*CurrentBit)+i)) l=l+z; 991 if (GetBit(Source, (*CurrentBit)+i)) l=l+z;
839 z=z>>1; 992 z=z>>1;
840 i++; 993 i++;
841 } 994 }
842 *result=l; 995 *result=l;
843 (*CurrentBit) = (*CurrentBit) + i; 996 (*CurrentBit) = (*CurrentBit) + i;
844} 997}
845 998
846/* Unicode char 0x00 0x01 makes blinking in some Nokia phones. 999/* Unicode char 0x00 0x01 makes blinking in some Nokia phones.
847 * We replace single ~ chars into it. When user give double ~, it's replaced 1000 * We replace single ~ chars into it. When user give double ~, it's replaced
848 * to single ~ 1001 * to single ~
849 */ 1002 */
850void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len) 1003void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len)
851{ 1004{
852 int i,current = 0; 1005 int i,current = 0;
853 bool special=false; 1006 bool special=false;
854 1007
855 for (i = 0; i < len; i++) { 1008 for (i = 0; i < len; i++) {
856 if (special) { 1009 if (special) {
857 if (src[i*2] == 0x00 && src[i*2+1] == '~') { 1010 if (src[i*2] == 0x00 && src[i*2+1] == '~') {
858 dest[current++]= 0x00; 1011 dest[current++]= 0x00;
859 dest[current++]= '~'; 1012 dest[current++]= '~';
860 } else { 1013 } else {
861 dest[current++]= 0x00; 1014 dest[current++]= 0x00;
862 dest[current++] = 0x01; 1015 dest[current++] = 0x01;
863 dest[current++]= src[i*2]; 1016 dest[current++]= src[i*2];
864 dest[current++]= src[i*2+1]; 1017 dest[current++]= src[i*2+1];
865 } 1018 }
866 special = false; 1019 special = false;
867 } else { 1020 } else {
868 if (src[i*2] == 0x00 && src[i*2+1] == '~') { 1021 if (src[i*2] == 0x00 && src[i*2+1] == '~') {
869 special = true; 1022 special = true;
870 } else { 1023 } else {
871 dest[current++]= src[i*2]; 1024 dest[current++]= src[i*2];
872 dest[current++]= src[i*2+1]; 1025 dest[current++]= src[i*2+1];
873 } 1026 }
874 } 1027 }
875 } 1028 }
876 if (special) { 1029 if (special) {
877 dest[current++]= 0x00; 1030 dest[current++]= 0x00;
878 dest[current++]= 0x01; 1031 dest[current++]= 0x01;
879 } 1032 }
880 dest[current++] = 0x00; 1033 dest[current++] = 0x00;
881 dest[current++] = 0x00; 1034 dest[current++] = 0x00;
882} 1035}
883 1036
884void DecodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len) 1037void DecodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len)
885{ 1038{
886 int i=0,current=0; 1039 int i=0,current=0;
887 1040
888 for (i=0;i<len;i++) { 1041 for (i=0;i<len;i++) {
889 switch (src[2*i]) { 1042 switch (src[2*i]) {
890 case 0x00: 1043 case 0x00:
891 switch (src[2*i+1]) { 1044 switch (src[2*i+1]) {
892 case 0x01: 1045 case 0x01:
893 dest[current++] = 0x00; 1046 dest[current++] = 0x00;
894 dest[current++] = '~'; 1047 dest[current++] = '~';
895 break; 1048 break;
896 case '~': 1049 case '~':
897 dest[current++] = 0x00; 1050 dest[current++] = 0x00;
898 dest[current++] = '~'; 1051 dest[current++] = '~';
899 dest[current++] = 0x00; 1052 dest[current++] = 0x00;
900 dest[current++] = '~'; 1053 dest[current++] = '~';
901 break; 1054 break;
902 default: 1055 default:
903 dest[current++] = src[i*2]; 1056 dest[current++] = src[i*2];
904 dest[current++] = src[i*2+1]; 1057 dest[current++] = src[i*2+1];
905 } 1058 }
906 break; 1059 break;
907 default: 1060 default:
908 dest[current++] = src[i*2]; 1061 dest[current++] = src[i*2];
909 dest[current++] = src[i*2+1]; 1062 dest[current++] = src[i*2+1];
910 } 1063 }
911 } 1064 }
912 dest[current++] = 0x00; 1065 dest[current++] = 0x00;
913 dest[current++] = 0x00; 1066 dest[current++] = 0x00;
914} 1067}
915 1068
916bool mystrncasecmp(unsigned const char *a, unsigned const char *b, int num) 1069bool mystrncasecmp(unsigned const char *a, unsigned const char *b, int num)
917{ 1070{
918 int i; 1071 int i;
919 1072
920 if (a == NULL || b == NULL) return false; 1073 if (a == NULL || b == NULL) return false;
921 1074
922 num--; 1075 if (num == 0) num = -1;
923 1076
924 for (i = 0; i != num; i++) { 1077 for (i = 0; i != num; i++) {
925 if (a[i] == 0x00 && b[i] == 0x00) return true; 1078 if (a[i] == 0x00 && b[i] == 0x00) return true;
926 if (a[i] == 0x00 || b[i] == 0x00) return false; 1079 if (a[i] == 0x00 || b[i] == 0x00) return false;
927 if (tolower(a[i]) != tolower(b[i])) return false; 1080 if (tolower(a[i]) != tolower(b[i])) return false;
928 } 1081 }
929 return true; 1082 return true;
930} 1083}
931 1084
932/* Compares two Unicode strings without regarding to case. 1085/* Compares two Unicode strings without regarding to case.
933 * Return true, when they're equal 1086 * Return true, when they're equal
934 */ 1087 */
935bool mywstrncasecmp(unsigned const char *a, unsigned const char *b, int num) 1088bool mywstrncasecmp(unsigned const char *a, unsigned const char *b, int num)
936{ 1089{
937 int i; 1090 int i;
938 wchar_t wc,wc2; 1091 wchar_t wc,wc2;
939 1092
940 if (a == NULL || b == NULL) return false; 1093 if (a == NULL || b == NULL) return false;
941 1094
942 num--; 1095 if (num == 0) num = -1;
943 1096
944 for (i = 0; i != num; i++) { 1097 for (i = 0; i != num; i++) {
945 if ((a[i*2] == 0x00 && a[i*2+1] == 0x00) && (b[i*2] == 0x00 && b[i*2+1] == 0x00)) return true; 1098 if ((a[i*2] == 0x00 && a[i*2+1] == 0x00) && (b[i*2] == 0x00 && b[i*2+1] == 0x00)) return true;
946 if ((a[i*2] == 0x00 && a[i*2+1] == 0x00) || (b[i*2] == 0x00 && b[i*2+1] == 0x00)) return false; 1099 if ((a[i*2] == 0x00 && a[i*2+1] == 0x00) || (b[i*2] == 0x00 && b[i*2+1] == 0x00)) return false;
947 wc = a[i*2+1] | (a[i*2] << 8); 1100 wc = a[i*2+1] | (a[i*2] << 8);
948 wc2 = b[i*2+1] | (b[i*2] << 8); 1101 wc2 = b[i*2+1] | (b[i*2] << 8);
949 if (mytowlower(wc) != mytowlower(wc2)) return false; 1102 if (mytowlower(wc) != mytowlower(wc2)) return false;
950 } 1103 }
951 return true; 1104 return true;
952} 1105}
953 1106
954/* wcscmp in Mandrake 9.0 is wrong */ 1107/* wcscmp in Mandrake 9.0 is wrong */
955bool mywstrncmp(unsigned const char *a, unsigned const char *b, int num) 1108bool mywstrncmp(unsigned const char *a, unsigned const char *b, int num)
956{ 1109{
957 int i=0; 1110 int i=0;
958 1111
959 while (1) { 1112 while (1) {
960 if (a[i*2] != b[i*2] || a[i*2+1] != b[i*2+1]) return false; 1113 if (a[i*2] != b[i*2] || a[i*2+1] != b[i*2+1]) return false;
961 if (a[i*2] == 0x00 && a[i*2+1] == 0x00) return true; 1114 if (a[i*2] == 0x00 && a[i*2+1] == 0x00) return true;
962 i++; 1115 i++;
963 if (num == i) return true; 1116 if (num == i) return true;
964 } 1117 }
965} 1118}
966 1119
967/* FreeBSD boxes 4.7-STABLE does't have it, although it's ANSI standard */ 1120/* FreeBSD boxes 4.7-STABLE does't have it, although it's ANSI standard */
968bool myiswspace(unsigned const char *src) 1121bool myiswspace(unsigned const char *src)
969{ 1122{
970#ifndef HAVE_ISWSPACE 1123#ifndef HAVE_ISWSPACE
971 int o; 1124 int o;
972 unsigned chardest[10]; 1125 unsigned chardest[10];
973#endif 1126#endif
974 wchar_t wc; 1127 wchar_t wc;
975 1128
976 wc = src[1] | (src[0] << 8); 1129 wc = src[1] | (src[0] << 8);
977 1130
978#ifndef HAVE_ISWSPACE 1131#ifndef HAVE_ISWSPACE
979 o = DecodeWithUnicodeAlphabet(wc, dest); 1132 o = DecodeWithUnicodeAlphabet(wc, dest);
980 if (o == 1) { 1133 if (o == 1) {
981 if (isspace(((int)dest[0]))!=0) return true; 1134 if (isspace(((int)dest[0]))!=0) return true;
982 return false; 1135 return false;
983 } 1136 }
984 return false; 1137 return false;
985#else 1138#else
986 return iswspace(wc); 1139 return iswspace(wc);
987#endif 1140#endif
988} 1141}
989 1142
990/* FreeBSD boxes 4.7-STABLE does't have it, although it's ANSI standard */ 1143/* FreeBSD boxes 4.7-STABLE does't have it, although it's ANSI standard */
991int mytowlower(wchar_t c) 1144int mytowlower(wchar_t c)
992{ 1145{
993#ifndef HAVE_TOWLOWER 1146#ifndef HAVE_TOWLOWER
994 unsigned char dest[10]; 1147 unsigned char dest[10];
995 1148
996 DecodeWithUnicodeAlphabet(c, dest); 1149 DecodeWithUnicodeAlphabet(c, dest);
997 return tolower(dest[0]); 1150 return tolower(dest[0]);
998#else 1151#else
999 return towlower(c); 1152 return towlower(c);
1000#endif 1153#endif
1001} 1154}
1002 1155
1003/* 1156/*
1004 * Following code is based on wcsstr from the GNU C Library, original 1157 * Following code is based on wcsstr from the GNU C Library, original
1005 * comment follows: 1158 * comment follows:
1006 */ 1159 */
1007/* 1160/*
1008 * The original strstr() file contains the following comment: 1161 * The original strstr() file contains the following comment:
1009 * 1162 *
1010 * My personal strstr() implementation that beats most other algorithms. 1163 * My personal strstr() implementation that beats most other algorithms.
1011 * Until someone tells me otherwise, I assume that this is the 1164 * Until someone tells me otherwise, I assume that this is the
1012 * fastest implementation of strstr() in C. 1165 * fastest implementation of strstr() in C.
1013 * I deliberately chose not to comment it. You should have at least 1166 * I deliberately chose not to comment it. You should have at least
1014 * as much fun trying to understand it, as I had to write it :-). 1167 * as much fun trying to understand it, as I had to write it :-).
1015 * 1168 *
1016 * Stephen R. van den Berg, berg@pool.informatik.rwth-aachen.de */ 1169 * Stephen R. van den Berg, berg@pool.informatik.rwth-aachen.de */
1017 1170
1018unsigned char *mystrstr (const unsigned char *haystack, const unsigned char *needle) 1171unsigned char *mywstrstr (const unsigned char *haystack, const unsigned char *needle)
1019{ 1172{
1020/* One crazy define to convert unicode used in Gammu to standard wchar_t */ 1173/* One crazy define to convert unicode used in Gammu to standard wchar_t */
1021#define tolowerwchar(x) (mytowlower((wchar_t)( (((&(x))[0] & 0xff) << 8) | (((&(x))[1] & 0xff)) ))) 1174#define tolowerwchar(x) (mytowlower((wchar_t)( (((&(x))[0] & 0xff) << 8) | (((&(x))[1] & 0xff)) )))
1022 register wchar_t b, c; 1175 register wchar_t b, c;
1023 1176
1024 if ((b = tolowerwchar(*needle)) != L'\0') { 1177 if ((b = tolowerwchar(*needle)) != L'\0') {
1025 haystack -= 2; /* possible ANSI violation */ 1178 haystack -= 2; /* possible ANSI violation */
1026 do { 1179 do {
1027 haystack += 2; 1180 haystack += 2;
1028 if ((c = tolowerwchar(*haystack)) == L'\0') 1181 if ((c = tolowerwchar(*haystack)) == L'\0')
1029 goto ret0; 1182 goto ret0;
1030 } while (c != b); 1183 } while (c != b);
1031 1184
1032 needle += 2; 1185 needle += 2;
1033 if ((c = tolowerwchar(*needle)) == L'\0') 1186 if ((c = tolowerwchar(*needle)) == L'\0')
1034 goto foundneedle; 1187 goto foundneedle;
1035 needle += 2; 1188 needle += 2;
1036 goto jin; 1189 goto jin;
1037 1190
1038 for (;;) { 1191 for (;;) {
1039 register wchar_t a; 1192 register wchar_t a;
1040 register const unsigned char *rhaystack, *rneedle; 1193 register const unsigned char *rhaystack, *rneedle;
1041 1194
1042 do { 1195 do {
1043 haystack += 2; 1196 haystack += 2;
1044 if ((a = tolowerwchar(*haystack)) == L'\0') 1197 if ((a = tolowerwchar(*haystack)) == L'\0')
1045 goto ret0; 1198 goto ret0;
1046 if (a == b) 1199 if (a == b)
1047 break; 1200 break;
1048 haystack += 2; 1201 haystack += 2;
1049 if ((a = tolowerwchar(*haystack)) == L'\0') 1202 if ((a = tolowerwchar(*haystack)) == L'\0')
1050 goto ret0; 1203 goto ret0;
1051 shloop: ; 1204 shloop: ;
1052 } while (a != b); 1205 } while (a != b);
1053 1206
1054 jin: haystack += 2; 1207 jin: haystack += 2;
1055 if ((a = tolowerwchar(*haystack)) == L'\0') 1208 if ((a = tolowerwchar(*haystack)) == L'\0')
1056 goto ret0; 1209 goto ret0;
1057 1210
1058 if (a != c) 1211 if (a != c)
1059 goto shloop; 1212 goto shloop;
1060 1213
1061 rhaystack = haystack + 2; 1214 rhaystack = haystack + 2;
1062 haystack -= 2; 1215 haystack -= 2;
1063 rneedle = needle; 1216 rneedle = needle;
1064 if (tolowerwchar(*rhaystack) == (a = tolowerwchar(*rneedle))) 1217 if (tolowerwchar(*rhaystack) == (a = tolowerwchar(*rneedle)))
1065 do { 1218 do {
1066 if (a == L'\0') 1219 if (a == L'\0')
1067 goto foundneedle; 1220 goto foundneedle;
1068 rhaystack += 2; 1221 rhaystack += 2;
1069 needle += 2; 1222 needle += 2;
1070 if (tolowerwchar(*rhaystack) != (a = tolowerwchar(*needle))) 1223 if (tolowerwchar(*rhaystack) != (a = tolowerwchar(*needle)))
1071 break ; 1224 break ;
1072 if (a == L'\0') 1225 if (a == L'\0')
1073 goto foundneedle; 1226 goto foundneedle;
1074 rhaystack += 2; 1227 rhaystack += 2;
1075 needle += 2; 1228 needle += 2;
1076 } while (tolowerwchar(*rhaystack) == (a = tolowerwchar(*needle))); 1229 } while (tolowerwchar(*rhaystack) == (a = tolowerwchar(*needle)));
1077 1230
1078 needle = rneedle; /* took the register-poor approach */ 1231 needle = rneedle; /* took the register-poor approach */
1079 1232
1080 if (a == L'\0') 1233 if (a == L'\0')
1081 break; 1234 break;
1082 } 1235 }
1083 } 1236 }
1084foundneedle: 1237foundneedle:
1085 return (unsigned char *)haystack; 1238 return (unsigned char *)haystack;
1086ret0: 1239ret0:
1087 return NULL; 1240 return NULL;
1088#undef tolowerwchar 1241#undef tolowerwchar
1089} 1242}
1090 1243
1091void MyGetLine(unsigned char *Buffer, int *Pos, unsigned char *OutBuffer, int MaxLen) 1244void MyGetLine(unsigned char *Buffer, int *Pos, unsigned char *OutBuffer, int MaxLen)
1092{ 1245{
1093 OutBuffer[0] = 0; 1246 OutBuffer[0] = 0;
1094 if (Buffer == NULL) return; 1247 if (Buffer == NULL) return;
1095 while (1) { 1248 while (1) {
1096 if ((*Pos) >= MaxLen) return; 1249 if ((*Pos) >= MaxLen) return;
1097 switch (Buffer[*Pos]) { 1250 switch (Buffer[*Pos]) {
1098 case 0x00: 1251 case 0x00:
1099 return; 1252 return;
1100 case 0x0A: 1253 case 0x0A:
1101 if (strlen(OutBuffer) != 0) return; 1254 if (strlen(OutBuffer) != 0) return;
1102 break; 1255 break;
1103 case 0x0D: 1256 case 0x0D:
1104 if (strlen(OutBuffer) != 0) return; 1257 if (strlen(OutBuffer) != 0) return;
1105 break; 1258 break;
1106 default : 1259 default :
1107 OutBuffer[strlen(OutBuffer) + 1] = 0; 1260 OutBuffer[strlen(OutBuffer) + 1] = 0;
1108 OutBuffer[strlen(OutBuffer)] = Buffer[*Pos]; 1261 OutBuffer[strlen(OutBuffer)] = Buffer[*Pos];
1109 } 1262 }
1110 (*Pos)++; 1263 (*Pos)++;
1111 } 1264 }
1112} 1265}
1113 1266
1114void StringToDouble(char *text, double *d) 1267void StringToDouble(char *text, double *d)
1115{ 1268{
1116 bool before=true; 1269 bool before=true;
1117 double multiply = 1; 1270 double multiply = 1;
1118 unsigned int i; 1271 unsigned int i;
1119 1272
1120 *d = 0; 1273 *d = 0;
1121 for (i=0;i<strlen(text);i++) { 1274 for (i=0;i<strlen(text);i++) {
1122 if (isdigit(text[i])) { 1275 if (isdigit(text[i])) {
1123 if (before) { 1276 if (before) {
1124 (*d)=(*d)*10+(text[i]-'0'); 1277 (*d)=(*d)*10+(text[i]-'0');
1125 } else { 1278 } else {
1126 multiply=multiply*0.1; 1279 multiply=multiply*0.1;
1127 (*d)=(*d)+(text[i]-'0')*multiply; 1280 (*d)=(*d)+(text[i]-'0')*multiply;
1128 } 1281 }
1129 } 1282 }
1130 if (text[i]=='.' || text[i]==',') before=false; 1283 if (text[i]=='.' || text[i]==',') before=false;
1131 } 1284 }
1132} 1285}
1133 1286
1134/* When char can be converted, convert it from Unicode to UTF8 */ 1287/* When char can be converted, convert it from Unicode to UTF8 */
1135bool EncodeWithUTF8Alphabet(unsigned char mychar1, unsigned char mychar2, unsigned char *ret1, unsigned char *ret2) 1288bool EncodeWithUTF8Alphabet(unsigned char mychar1, unsigned char mychar2, unsigned char *ret1, unsigned char *ret2)
1136{ 1289{
1137 unsigned charmychar3,mychar4; 1290 unsigned charmychar3,mychar4;
1138 int j=0; 1291 int j=0;
1139 1292
1140 if (mychar1>0x00 || mychar2>128) { 1293 if (mychar1>0x00 || mychar2>128) {
1141 mychar3=0x00; 1294 mychar3=0x00;
1142 mychar4=128; 1295 mychar4=128;
1143 while (true) { 1296 while (true) {
1144 if (mychar3==mychar1) { 1297 if (mychar3==mychar1) {
1145 if (mychar4+64>=mychar2) { 1298 if (mychar4+64>=mychar2) {
1146 *ret1=j+0xc2; 1299 *ret1=j+0xc2;
1147 *ret2=0x80+(mychar2-mychar4); 1300 *ret2=0x80+(mychar2-mychar4);
1148 return true; 1301 return true;
1149 } 1302 }
1150 } 1303 }
1151 if (mychar4==192) { 1304 if (mychar4==192) {
1152 mychar3++; 1305 mychar3++;
1153 mychar4=0; 1306 mychar4=0;
1154 } else { 1307 } else {
1155 mychar4=mychar4+64; 1308 mychar4=mychar4+64;
1156 } 1309 }
1157 j++; 1310 j++;
1158 } 1311 }
1159 } 1312 }
1160 return false; 1313 return false;
1161} 1314}
1162 1315
1163/* Make UTF8 string from Unicode input string */ 1316/* Make UTF8 string from Unicode input string */
1164bool EncodeUTF8QuotedPrintable(unsigned char *dest, const unsigned char *src) 1317bool EncodeUTF8QuotedPrintable(unsigned char *dest, const unsigned char *src)
1165{ 1318{
1166 int i,j=0; 1319 int i,j=0;
1167 unsigned charmychar1, mychar2; 1320 unsigned charmychar1, mychar2;
1168 bool retval = false; 1321 bool retval = false;
1169 1322
1170 for (i = 0; i < (int)(UnicodeLength(src)); i++) { 1323 for (i = 0; i < (int)(UnicodeLength(src)); i++) {
1171 if (EncodeWithUTF8Alphabet(src[i*2],src[i*2+1],&mychar1,&mychar2)) { 1324 if (EncodeWithUTF8Alphabet(src[i*2],src[i*2+1],&mychar1,&mychar2)) {
1172 sprintf(dest+j, "=%02X=%02X",mychar1,mychar2); 1325 sprintf(dest+j, "=%02X=%02X",mychar1,mychar2);
1173 j= j+6; 1326 j= j+6;
1174 retval = true; 1327 retval = true;
1175 } else { 1328 } else {
1176 j += DecodeWithUnicodeAlphabet(((wchar_t)(src[i*2]*256+src[i*2+1])), dest + j); 1329 j += DecodeWithUnicodeAlphabet(((wchar_t)(src[i*2]*256+src[i*2+1])), dest + j);
1177 } 1330 }
1178 } 1331 }
1179 dest[j++]=0; 1332 dest[j++]=0;
1180 return retval; 1333 return retval;
1181} 1334}
1182 1335
1183bool EncodeUTF8(unsigned char *dest, const unsigned char *src) 1336bool EncodeUTF8(unsigned char *dest, const unsigned char *src)
1184{ 1337{
1185 int i,j=0; 1338 int i,j=0;
1186 unsigned charmychar1, mychar2; 1339 unsigned charmychar1, mychar2;
1187 bool retval = false; 1340 bool retval = false;
1188 1341
1189 for (i = 0; i < (int)(UnicodeLength(src)); i++) { 1342 for (i = 0; i < (int)(UnicodeLength(src)); i++) {
1190 if (EncodeWithUTF8Alphabet(src[i*2],src[i*2+1],&mychar1,&mychar2)) { 1343 if (EncodeWithUTF8Alphabet(src[i*2],src[i*2+1],&mychar1,&mychar2)) {
1191 sprintf(dest+j, "%c%c",mychar1,mychar2); 1344 sprintf(dest+j, "%c%c",mychar1,mychar2);
1192 j= j+2; 1345 j= j+2;
1193 retval = true; 1346 retval = true;
1194 } else { 1347 } else {
1195 j += DecodeWithUnicodeAlphabet(((wchar_t)(src[i*2]*256+src[i*2+1])), dest + j); 1348 j += DecodeWithUnicodeAlphabet(((wchar_t)(src[i*2]*256+src[i*2+1])), dest + j);
1196 } 1349 }
1197 } 1350 }
1198 dest[j++]=0; 1351 dest[j++]=0;
1199 return retval; 1352 return retval;
1200} 1353}
1201 1354
1202/* Decode UTF8 char to Unicode char */ 1355/* Decode UTF8 char to Unicode char */
1203wchar_t DecodeWithUTF8Alphabet(unsigned char mychar3, unsigned char mychar4) 1356wchar_t DecodeWithUTF8Alphabet(unsigned char mychar3, unsigned char mychar4)
1204{ 1357{
1205 unsigned charmychar1, mychar2; 1358 unsigned charmychar1, mychar2;
1206 int j; 1359 int j;
1207 1360
1208 mychar1=0x00; 1361 mychar1=0x00;
1209 mychar2=128; 1362 mychar2=128;
1210 for(j=0;j<mychar3-0xc2;j++) { 1363 for(j=0;j<mychar3-0xc2;j++) {
diff --git a/gammu/emb/common/misc/coding/coding.h b/gammu/emb/common/misc/coding/coding.h
index d0c334d..4cf0038 100644
--- a/gammu/emb/common/misc/coding/coding.h
+++ b/gammu/emb/common/misc/coding/coding.h
@@ -1,133 +1,148 @@
1/* (c) 2002-2004 by Marcin Wiacek and others */ 1/* (c) 2002-2004 by Marcin Wiacek and others */
2 2
3#ifndef __coding_h 3#ifndef __coding_h
4#define __coding_h 4#define __coding_h
5 5
6#if defined(_MSC_VER) && defined(__cplusplus)
7 extern "C" {
8#endif
9
6#include <stdlib.h> 10#include <stdlib.h>
7 11
8#include "../misc.h" 12#include "../misc.h"
9 13
10#ifdef __OpenBSD__ 14#ifdef __OpenBSD__
11 typedef int wint_t; 15 typedef int wint_t;
12#endif 16#endif
13 17
14/* ---------------------------- Unicode ------------------------------------ */ 18/* ---------------------------- Unicode ------------------------------------ */
15 bool mywstrncasecmp (unsigned const char *a, unsigned const char *b, int num); 19 bool mywstrncasecmp (unsigned const char *a, unsigned const char *b, int num);
16 unsigned char *mystrstr (unsigned const char *haystack, unsigned const char *needle); 20 unsigned char *mywstrstr (unsigned const char *haystack, unsigned const char *needle);
17 bool mywstrncmp (unsigned const char *a, unsigned const char *b, int num); 21 bool mywstrncmp (unsigned const char *a, unsigned const char *b, int num);
18 bool myiswspace (unsigned const char *src); 22 bool myiswspace (unsigned const char *src);
19 int mytowlower (wchar_t c); 23 int mytowlower (wchar_t c);
20 24
21 unsigned int EncodeWithUnicodeAlphabet(const unsigned char *value, wchar_t *dest); 25 unsigned int EncodeWithUnicodeAlphabet(const unsigned char *value, wchar_t *dest);
22 unsigned int DecodeWithUnicodeAlphabet(wchar_t value, unsigned char *dest); 26 unsigned int DecodeWithUnicodeAlphabet(wchar_t value, unsigned char *dest);
23 27
24 unsigned int UnicodeLength (const unsigned char *str); 28 unsigned int UnicodeLength (const unsigned char *str);
25 unsigned char *DecodeUnicodeString (const unsigned char *src); 29 unsigned char *DecodeUnicodeString (const unsigned char *src);
26 unsigned char *DecodeUnicodeConsole (const unsigned char *src); 30 unsigned char *DecodeUnicodeConsole (const unsigned char *src);
27 void DecodeUnicode (const unsigned char *src, unsigned char *dest); 31 void DecodeUnicode (const unsigned char *src, unsigned char *dest);
28 void EncodeUnicode (unsigned char *dest, const unsigned char *src, int len); 32 void EncodeUnicode (unsigned char *dest, const unsigned char *src, int len);
29 33
30 void CopyUnicodeString (unsigned char *Dest, unsigned char *Source); 34 void CopyUnicodeString (unsigned char *Dest, unsigned char *Source);
31 void ReverseUnicodeString (unsigned char *String); 35 void ReverseUnicodeString (unsigned char *String);
32 36
33 void ReadUnicodeFile (unsigned char *Dest, unsigned char *Source); 37 void ReadUnicodeFile (unsigned char *Dest, unsigned char *Source);
34 38
35 void DecodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len); 39 void DecodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len);
36 void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len); 40 void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len);
37 41
42 char *EncodeUnicodeSpecialChars(unsigned char *buffer);
43 char *DecodeUnicodeSpecialChars(unsigned char *buffer);
44
38/* ------------------------------- BCD ------------------------------------- */ 45/* ------------------------------- BCD ------------------------------------- */
39 unsigned char EncodeWithBCDAlphabet (int value); 46 unsigned char EncodeWithBCDAlphabet (int value);
40 int DecodeWithBCDAlphabet (unsigned char value); 47 int DecodeWithBCDAlphabet (unsigned char value);
41 48
42 void DecodeBCD (unsigned char *dest, const unsigned char *src, int len); 49 void DecodeBCD (unsigned char *dest, const unsigned char *src, int len);
43 void EncodeBCD (unsigned char *dest, const unsigned char *src, int len, bool fill); 50 void EncodeBCD (unsigned char *dest, const unsigned char *src, int len, bool fill);
44 51
45/* ------------------------------ UTF7 ------------------------------------- */ 52/* ------------------------------ UTF7 ------------------------------------- */
46 void DecodeUTF7 (unsigned char *dest, const unsigned char *src, int len); 53 void DecodeUTF7 (unsigned char *dest, const unsigned char *src, int len);
47 54
48/* ------------------------------ UTF8 ------------------------------------- */ 55/* ------------------------------ UTF8 ------------------------------------- */
49 wchar_t DecodeWithUTF8Alphabet (unsigned char mychar3, unsigned char mychar4); 56 wchar_t DecodeWithUTF8Alphabet (unsigned char mychar3, unsigned char mychar4);
50 bool EncodeWithUTF8Alphabet (unsigned char mychar1, unsigned char mychar2, unsigned char *ret1, unsigned char *ret2); 57 bool EncodeWithUTF8Alphabet (unsigned char mychar1, unsigned char mychar2, unsigned char *ret1, unsigned char *ret2);
51 58
52 bool EncodeUTF8QuotedPrintable(unsigned char *dest, const unsigned char *src); 59 bool EncodeUTF8QuotedPrintable(unsigned char *dest, const unsigned char *src);
53 void DecodeUTF8QuotedPrintable(unsigned char *dest, const unsigned char *src, int len); 60 void DecodeUTF8QuotedPrintable(unsigned char *dest, const unsigned char *src, int len);
54 61
55 bool EncodeUTF8 (unsigned char *dest, const unsigned char *src); 62 bool EncodeUTF8 (unsigned char *dest, const unsigned char *src);
56 void DecodeUTF8 (unsigned char *dest, const unsigned char *src, int len); 63 void DecodeUTF8 (unsigned char *dest, const unsigned char *src, int len);
57 64
58/* ------------------------------- BASE64 ---------------------------------- */ 65/* ------------------------------- BASE64 ---------------------------------- */
59 void EncodeBASE64 (const unsigned char *Input, unsigned char *Output, int Length); 66 void EncodeBASE64 (const unsigned char *Input, unsigned char *Output, int Length);
60 int DecodeBASE64 (const unsigned char *Input, unsigned char *Output, int Length); 67 int DecodeBASE64 (const unsigned char *Input, unsigned char *Output, int Length);
61 68
62/* ----------------------------- HexBin ------------------------------------ */ 69/* ----------------------------- HexBin ------------------------------------ */
63 void DecodeHexBin (unsigned char *dest, const unsigned char *src, int len); 70 void DecodeHexBin (unsigned char *dest, const unsigned char *src, int len);
64 void EncodeHexBin (unsigned char *dest, const unsigned char *src, int len); 71 void EncodeHexBin (unsigned char *dest, const unsigned char *src, int len);
65 72
66/* ----------------------------- HexUnicode -------------------------------- */ 73/* ----------------------------- HexUnicode -------------------------------- */
67 void DecodeHexUnicode (unsigned char *dest, const unsigned char *src, int len); 74 void DecodeHexUnicode (unsigned char *dest, const unsigned char *src, int len);
68 void EncodeHexUnicode (unsigned char *dest, const unsigned char *src, int len); 75 void EncodeHexUnicode (unsigned char *dest, const unsigned char *src, int len);
69 76
70/* ---------------------- DefaultAlphabet for SMS -------------------------- */ 77/* ---------------------- DefaultAlphabet for SMS -------------------------- */
71 void EncodeDefault (unsigned char *dest, const unsigned char *src, int *len, bool UseExtensions, unsigned char *ExtraAlphabet); 78 void EncodeDefault (unsigned char *dest, const unsigned char *src, int *len, bool UseExtensions, unsigned char *ExtraAlphabet);
72 void DecodeDefault (unsigned char *dest, const unsigned char *src, int len, bool UseExtensions, unsigned char *ExtraAlphabet); 79 void DecodeDefault (unsigned char *dest, const unsigned char *src, int len, bool UseExtensions, unsigned char *ExtraAlphabet);
73 void FindDefaultAlphabetLen (const unsigned char *src, int *srclen, int *smslen, int maxlen); 80 void FindDefaultAlphabetLen (const unsigned char *src, int *srclen, int *smslen, int maxlen);
74 81
75 int GSM_PackSevenBitsToEight(int offset, unsigned char *input, unsigned char *output, int length); 82 int GSM_PackSevenBitsToEight(int offset, unsigned char *input, unsigned char *output, int length);
76 int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length, 83 int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length,
77 unsigned char *input, unsigned char *output); 84 unsigned char *input, unsigned char *output);
78 85
79/* ----------------- Phone numbers according to GSM specs ------------------ */ 86/* ----------------- Phone numbers according to GSM specs ------------------ */
80 87
81/** 88/**
82 * Enum to handle types of phones numbers like 89 * Enum to handle types of phones numbers like
83 * specified in GSM 03.40 section 9.1.2.5 90 * specified in GSM 03.40 section 9.1.2.5
84 */ 91 */
85typedef enum { 92typedef enum {
86 /** 93 /**
87 * Unknown number type 94 * Unknown number type
88 */ 95 */
89 NUMBER_UNKNOWN = 0x81, 96 NUMBER_UNKNOWN_NUMBERING_PLAN_ISDN = 0x81,
90 /** 97 /**
91 * International number (full number with code of country) 98 * International number (full number with code of country)
92 */ 99 */
93 NUMBER_INTERNATIONAL= 0x91, 100 NUMBER_INTERNATIONAL_NUMBERING_PLAN_ISDN= 0x91,
94 /** 101 /**
95 * Alphanumeric number (with chars too) 102 * Alphanumeric number (with chars too)
96 */ 103 */
97 NUMBER_ALPHANUMERIC= 0xD0 104 NUMBER_ALPHANUMERIC_NUMBERING_PLAN_UNKNOWN= 0xD0
98 105
99 /* specification give also other values */ 106 /* specification give also other values */
100} GSM_NumberType; 107} GSM_NumberType;
101 108
102 void GSM_UnpackSemiOctetNumber(unsigned char *retval, unsigned char *Number, bool semioctet); 109 void GSM_UnpackSemiOctetNumber(unsigned char *retval, unsigned char *Number, bool semioctet);
103 int GSM_PackSemiOctetNumber (unsigned char *Number, unsigned char *Output, bool semioctet); 110 int GSM_PackSemiOctetNumber (unsigned char *Number, unsigned char *Output, bool semioctet);
104 111
105/* ---------------------------- Bits --------------------------------------- */ 112/* ---------------------------- Bits --------------------------------------- */
106 113
107void BufferAlign (unsigned char *Destination, int *CurrentBit); 114void BufferAlign (unsigned char *Destination, int *CurrentBit);
108void BufferAlignNumber(int *CurrentBit); 115void BufferAlignNumber(int *CurrentBit);
109 116
110 void AddBuffer (unsigned char *Destination, int *CurrentBit, unsigned char *Source, int BitsToProcess); 117 void AddBuffer (unsigned char *Destination, int *CurrentBit, unsigned char *Source, int BitsToProcess);
111void AddBufferByte(unsigned char *Destination, int *CurrentBit, unsigned char Source, int BitsToProcess); 118void AddBufferByte(unsigned char *Destination, int *CurrentBit, unsigned char Source, int BitsToProcess);
112 119
113void GetBuffer (unsigned char *Source, int *CurrentBit, unsigned char *Destination, int BitsToProcess); 120void GetBuffer (unsigned char *Source, int *CurrentBit, unsigned char *Destination, int BitsToProcess);
114void GetBufferInt (unsigned char *Source, int *CurrentBit, int *integer, int BitsToProcess); 121void GetBufferInt (unsigned char *Source, int *CurrentBit, int *integer, int BitsToProcess);
115void GetBufferI (unsigned char *Source, int *CurrentBit, int *result, int BitsToProcess); 122void GetBufferI (unsigned char *Source, int *CurrentBit, int *result, int BitsToProcess);
116 123
117int GetBit (unsigned char *Buffer, int BitNum); 124int GetBit (unsigned char *Buffer, int BitNum);
118int SetBit (unsigned char *Buffer, int BitNum); 125int SetBit (unsigned char *Buffer, int BitNum);
119int ClearBit (unsigned char *Buffer, int BitNum); 126int ClearBit (unsigned char *Buffer, int BitNum);
120 127
121/* ---------------------------- Other -------------------------------------- */ 128/* ---------------------------- Other -------------------------------------- */
122 129
123 void StringToDouble(char *text, double *d); 130 void StringToDouble(char *text, double *d);
124 131
125bool mystrncasecmp (unsigned const char *a, unsigned const char *b, int num); 132 bool mystrncasecmp (unsigned const char *a, unsigned const char *b, int num);
133 char *mystrcasestr (unsigned const char *a, unsigned const char *b);
126 134
127void MyGetLine(unsigned char *Buffer, int *Pos, unsigned char *OutBuffer, int MaxLen); 135 void MyGetLine (unsigned char *Buffer, int *Pos, unsigned char *OutBuffer, int MaxLen);
136
137char *EncodeSpecialChars(unsigned char *buffer);
138char *DecodeSpecialChars(unsigned char *buffer);
139
140#if defined(_MSC_VER) && defined(__cplusplus)
141 }
142#endif
128 143
129#endif 144#endif
130 145
131/* How should editor hadle tabs in this file? Add editor commands here. 146/* How should editor hadle tabs in this file? Add editor commands here.
132 * vim: noexpandtab sw=8 ts=8 sts=8: 147 * vim: noexpandtab sw=8 ts=8 sts=8:
133 */ 148 */
diff --git a/gammu/emb/common/misc/coding/md5.c b/gammu/emb/common/misc/coding/md5.c
index 30fe33f..abb61be 100644
--- a/gammu/emb/common/misc/coding/md5.c
+++ b/gammu/emb/common/misc/coding/md5.c
@@ -1,193 +1,193 @@
1/* Taken from ReHash (see http://www.reichlsoft.de.vu/) and released 1/* Taken from ReHash (www.reichlsoft.de.vu) and released
2 * under GPL/LGPL with permission from ReHash author 2 * under GPL/LGPL with permission from ReHash author
3 * Dominik Reichl <dominik.reichl@t-online.de>, Germany 3 * Dominik Reichl <dominik.reichl@t-online.de>, Germany
4 */ 4 */
5 5
6/* 6/*
7 ********************************************************************** 7 **********************************************************************
8 ** MD5.cpp ** 8 ** MD5.cpp **
9 ** ** 9 ** **
10 ** - Style modified by Tony Ray, January 2001 ** 10 ** - Style modified by Tony Ray, January 2001 **
11 ** Added support for randomizing initialization constants ** 11 ** Added support for randomizing initialization constants **
12 ** - Style modified by Dominik Reichl, April 2003 ** 12 ** - Style modified by Dominik Reichl, April 2003 **
13 ** Optimized code ** 13 ** Optimized code **
14 ** ** 14 ** **
15 ** MD5.c ** 15 ** MD5.c **
16 ** RSA Data Security, Inc. MD5 Message Digest Algorithm ** 16 ** RSA Data Security, Inc. MD5 Message Digest Algorithm **
17 ** Created: 2/17/90 RLR ** 17 ** Created: 2/17/90 RLR **
18 ** Revised: 1/91 SRD,AJ,BSK,JT Reference C Version ** 18 ** Revised: 1/91 SRD,AJ,BSK,JT Reference C Version **
19 ********************************************************************** 19 **********************************************************************
20 */ 20 */
21 21
22/* 22/*
23 ********************************************************************** 23 **********************************************************************
24 ** MD5.h -- Header file for implementation of MD5 ** 24 ** MD5.h -- Header file for implementation of MD5 **
25 ** RSA Data Security, Inc. MD5 Message Digest Algorithm ** 25 ** RSA Data Security, Inc. MD5 Message Digest Algorithm **
26 ** Created: 2/17/90 RLR ** 26 ** Created: 2/17/90 RLR **
27 ** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version ** 27 ** Revised: 12/27/90 SRD,AJ,BSK,JT Reference C version **
28 ** Revised (for MD5): RLR 4/27/91 ** 28 ** Revised (for MD5): RLR 4/27/91 **
29 ** -- G modified to have y&~z instead of y&z ** 29 ** -- G modified to have y&~z instead of y&z **
30 ** -- FF, GG, HH modified to add in last register done ** 30 ** -- FF, GG, HH modified to add in last register done **
31 ** -- Access pattern: round 2 works mod 5, round 3 works mod 3 ** 31 ** -- Access pattern: round 2 works mod 5, round 3 works mod 3 **
32 ** -- distinct additive constant for each step ** 32 ** -- distinct additive constant for each step **
33 ** -- round 4 added, working mod 7 ** 33 ** -- round 4 added, working mod 7 **
34 ********************************************************************** 34 **********************************************************************
35 */ 35 */
36 36
37/* 37/*
38 ********************************************************************** 38 **********************************************************************
39 ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. ** 39 ** Copyright (C) 1990, RSA Data Security, Inc. All rights reserved. **
40 ** ** 40 ** **
41 ** License to copy and use this software is granted provided that ** 41 ** License to copy and use this software is granted provided that **
42 ** it is identified as the "RSA Data Security, Inc. MD5 Message ** 42 ** it is identified as the "RSA Data Security, Inc. MD5 Message **
43 ** Digest Algorithm" in all material mentioning or referencing this ** 43 ** Digest Algorithm" in all material mentioning or referencing this **
44 ** software or this function. ** 44 ** software or this function. **
45 ** ** 45 ** **
46 ** License is also granted to make and use derivative works ** 46 ** License is also granted to make and use derivative works **
47 ** provided that such works are identified as "derived from the RSA ** 47 ** provided that such works are identified as "derived from the RSA **
48 ** Data Security, Inc. MD5 Message Digest Algorithm" in all ** 48 ** Data Security, Inc. MD5 Message Digest Algorithm" in all **
49 ** material mentioning or referencing the derived work. ** 49 ** material mentioning or referencing the derived work. **
50 ** ** 50 ** **
51 ** RSA Data Security, Inc. makes no representations concerning ** 51 ** RSA Data Security, Inc. makes no representations concerning **
52 ** either the merchantability of this software or the suitability ** 52 ** either the merchantability of this software or the suitability **
53 ** of this software for any particular purpose. It is provided "as ** 53 ** of this software for any particular purpose. It is provided "as **
54 ** is" without express or implied warranty of any kind. ** 54 ** is" without express or implied warranty of any kind. **
55 ** ** 55 ** **
56 ** These notices must be retained in any copies of any part of this ** 56 ** These notices must be retained in any copies of any part of this **
57 ** documentation and/or software. ** 57 ** documentation and/or software. **
58 ********************************************************************** 58 **********************************************************************
59 */ 59 */
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include <stdlib.h> 62#include <stdlib.h>
63 63
64#include "md5.h" 64#include "md5.h"
65 65
66/* Typedef a 32 bit type */ 66/* Typedef a 32 bit type */
67#ifndef UINT4 67#ifndef UINT4
68typedef unsigned long int UINT4; 68typedef unsigned long int UINT4;
69#endif 69#endif
70 70
71/* Data structure for MD5 (Message Digest) computation */ 71/* Data structure for MD5 (Message Digest) computation */
72typedef struct { 72typedef struct {
73 UINT4 i[2]; /* Number of _bits_ handled mod 2^64 */ 73 UINT4 i[2]; /* Number of _bits_ handled mod 2^64 */
74 UINT4 buf[4]; /* Scratch buffer */ 74 UINT4 buf[4]; /* Scratch buffer */
75 unsigned char in[64]; /* Input buffer */ 75 unsigned char in[64]; /* Input buffer */
76 unsigned char digest[16]; /* Actual digest after MD5Final call */ 76 unsigned char digest[16]; /* Actual digest after MD5Final call */
77} MD5_CTX; 77} MD5_CTX;
78 78
79/* Padding */ 79/* Padding */
80static unsigned char MD5_PADDING[64] = { 80static unsigned char MD5_PADDING[64] = {
81 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 81 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 82 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 83 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
84 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 84 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
85 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 85 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
86 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 86 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
88 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 88 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
89}; 89};
90 90
91/* MD5_F, MD5_G and MD5_H are basic MD5 functions: selection, majority, parity */ 91/* MD5_F, MD5_G and MD5_H are basic MD5 functions: selection, majority, parity */
92#define MD5_F(x, y, z) (((x) & (y)) | ((~x) & (z))) 92#define MD5_F(x, y, z) (((x) & (y)) | ((~x) & (z)))
93#define MD5_G(x, y, z) (((x) & (z)) | ((y) & (~z))) 93#define MD5_G(x, y, z) (((x) & (z)) | ((y) & (~z)))
94#define MD5_H(x, y, z) ((x) ^ (y) ^ (z)) 94#define MD5_H(x, y, z) ((x) ^ (y) ^ (z))
95#define MD5_I(x, y, z) ((y) ^ ((x) | (~z))) 95#define MD5_I(x, y, z) ((y) ^ ((x) | (~z)))
96 96
97/* ROTATE_LEFT rotates x left n bits */ 97/* ROTATE_LEFT rotates x left n bits */
98#ifndef ROTATE_LEFT 98#ifndef ROTATE_LEFT
99#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) 99#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
100#endif 100#endif
101 101
102/* MD5_FF, MD5_GG, MD5_HH, and MD5_II transformations for rounds 1, 2, 3, and 4 */ 102/* MD5_FF, MD5_GG, MD5_HH, and MD5_II transformations for rounds 1, 2, 3, and 4 */
103/* Rotation is separate from addition to prevent recomputation */ 103/* Rotation is separate from addition to prevent recomputation */
104#define MD5_FF(a, b, c, d, x, s, ac) {(a) += MD5_F ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); } 104#define MD5_FF(a, b, c, d, x, s, ac) {(a) += MD5_F ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
105#define MD5_GG(a, b, c, d, x, s, ac) {(a) += MD5_G ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); } 105#define MD5_GG(a, b, c, d, x, s, ac) {(a) += MD5_G ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
106#define MD5_HH(a, b, c, d, x, s, ac) {(a) += MD5_H ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); } 106#define MD5_HH(a, b, c, d, x, s, ac) {(a) += MD5_H ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
107#define MD5_II(a, b, c, d, x, s, ac) {(a) += MD5_I ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); } 107#define MD5_II(a, b, c, d, x, s, ac) {(a) += MD5_I ((b), (c), (d)) + (x) + (UINT4)(ac); (a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
108 108
109/* Constants for transformation */ 109/* Constants for transformation */
110#define MD5_S11 7 /* Round 1 */ 110#define MD5_S11 7 /* Round 1 */
111#define MD5_S12 12 111#define MD5_S12 12
112#define MD5_S13 17 112#define MD5_S13 17
113#define MD5_S14 22 113#define MD5_S14 22
114#define MD5_S21 5 /* Round 2 */ 114#define MD5_S21 5 /* Round 2 */
115#define MD5_S22 9 115#define MD5_S22 9
116#define MD5_S23 14 116#define MD5_S23 14
117#define MD5_S24 20 117#define MD5_S24 20
118#define MD5_S31 4 /* Round 3 */ 118#define MD5_S31 4 /* Round 3 */
119#define MD5_S32 11 119#define MD5_S32 11
120#define MD5_S33 16 120#define MD5_S33 16
121#define MD5_S34 23 121#define MD5_S34 23
122#define MD5_S41 6 /* Round 4 */ 122#define MD5_S41 6 /* Round 4 */
123#define MD5_S42 10 123#define MD5_S42 10
124#define MD5_S43 15 124#define MD5_S43 15
125#define MD5_S44 21 125#define MD5_S44 21
126 126
127/* Basic MD5 step. MD5_Transform buf based on in */ 127/* Basic MD5 step. MD5_Transform buf based on in */
128static void MD5_Transform (UINT4 *buf, UINT4 *in) 128static void MD5_Transform (UINT4 *buf, UINT4 *in)
129{ 129{
130 UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3]; 130 UINT4 a = buf[0], b = buf[1], c = buf[2], d = buf[3];
131 131
132 /* Round 1 */ 132 /* Round 1 */
133 MD5_FF ( a, b, c, d, in[ 0], MD5_S11, (UINT4) 3614090360u); /* 1 */ 133 MD5_FF ( a, b, c, d, in[ 0], MD5_S11, (UINT4) 3614090360u); /* 1 */
134 MD5_FF ( d, a, b, c, in[ 1], MD5_S12, (UINT4) 3905402710u); /* 2 */ 134 MD5_FF ( d, a, b, c, in[ 1], MD5_S12, (UINT4) 3905402710u); /* 2 */
135 MD5_FF ( c, d, a, b, in[ 2], MD5_S13, (UINT4) 606105819u); /* 3 */ 135 MD5_FF ( c, d, a, b, in[ 2], MD5_S13, (UINT4) 606105819u); /* 3 */
136 MD5_FF ( b, c, d, a, in[ 3], MD5_S14, (UINT4) 3250441966u); /* 4 */ 136 MD5_FF ( b, c, d, a, in[ 3], MD5_S14, (UINT4) 3250441966u); /* 4 */
137 MD5_FF ( a, b, c, d, in[ 4], MD5_S11, (UINT4) 4118548399u); /* 5 */ 137 MD5_FF ( a, b, c, d, in[ 4], MD5_S11, (UINT4) 4118548399u); /* 5 */
138 MD5_FF ( d, a, b, c, in[ 5], MD5_S12, (UINT4) 1200080426u); /* 6 */ 138 MD5_FF ( d, a, b, c, in[ 5], MD5_S12, (UINT4) 1200080426u); /* 6 */
139 MD5_FF ( c, d, a, b, in[ 6], MD5_S13, (UINT4) 2821735955u); /* 7 */ 139 MD5_FF ( c, d, a, b, in[ 6], MD5_S13, (UINT4) 2821735955u); /* 7 */
140 MD5_FF ( b, c, d, a, in[ 7], MD5_S14, (UINT4) 4249261313u); /* 8 */ 140 MD5_FF ( b, c, d, a, in[ 7], MD5_S14, (UINT4) 4249261313u); /* 8 */
141 MD5_FF ( a, b, c, d, in[ 8], MD5_S11, (UINT4) 1770035416u); /* 9 */ 141 MD5_FF ( a, b, c, d, in[ 8], MD5_S11, (UINT4) 1770035416u); /* 9 */
142 MD5_FF ( d, a, b, c, in[ 9], MD5_S12, (UINT4) 2336552879u); /* 10 */ 142 MD5_FF ( d, a, b, c, in[ 9], MD5_S12, (UINT4) 2336552879u); /* 10 */
143 MD5_FF ( c, d, a, b, in[10], MD5_S13, (UINT4) 4294925233u); /* 11 */ 143 MD5_FF ( c, d, a, b, in[10], MD5_S13, (UINT4) 4294925233u); /* 11 */
144 MD5_FF ( b, c, d, a, in[11], MD5_S14, (UINT4) 2304563134u); /* 12 */ 144 MD5_FF ( b, c, d, a, in[11], MD5_S14, (UINT4) 2304563134u); /* 12 */
145 MD5_FF ( a, b, c, d, in[12], MD5_S11, (UINT4) 1804603682u); /* 13 */ 145 MD5_FF ( a, b, c, d, in[12], MD5_S11, (UINT4) 1804603682u); /* 13 */
146 MD5_FF ( d, a, b, c, in[13], MD5_S12, (UINT4) 4254626195u); /* 14 */ 146 MD5_FF ( d, a, b, c, in[13], MD5_S12, (UINT4) 4254626195u); /* 14 */
147 MD5_FF ( c, d, a, b, in[14], MD5_S13, (UINT4) 2792965006u); /* 15 */ 147 MD5_FF ( c, d, a, b, in[14], MD5_S13, (UINT4) 2792965006u); /* 15 */
148 MD5_FF ( b, c, d, a, in[15], MD5_S14, (UINT4) 1236535329u); /* 16 */ 148 MD5_FF ( b, c, d, a, in[15], MD5_S14, (UINT4) 1236535329u); /* 16 */
149 149
150 /* Round 2 */ 150 /* Round 2 */
151 MD5_GG ( a, b, c, d, in[ 1], MD5_S21, (UINT4) 4129170786u); /* 17 */ 151 MD5_GG ( a, b, c, d, in[ 1], MD5_S21, (UINT4) 4129170786u); /* 17 */
152 MD5_GG ( d, a, b, c, in[ 6], MD5_S22, (UINT4) 3225465664u); /* 18 */ 152 MD5_GG ( d, a, b, c, in[ 6], MD5_S22, (UINT4) 3225465664u); /* 18 */
153 MD5_GG ( c, d, a, b, in[11], MD5_S23, (UINT4) 643717713u); /* 19 */ 153 MD5_GG ( c, d, a, b, in[11], MD5_S23, (UINT4) 643717713u); /* 19 */
154 MD5_GG ( b, c, d, a, in[ 0], MD5_S24, (UINT4) 3921069994u); /* 20 */ 154 MD5_GG ( b, c, d, a, in[ 0], MD5_S24, (UINT4) 3921069994u); /* 20 */
155 MD5_GG ( a, b, c, d, in[ 5], MD5_S21, (UINT4) 3593408605u); /* 21 */ 155 MD5_GG ( a, b, c, d, in[ 5], MD5_S21, (UINT4) 3593408605u); /* 21 */
156 MD5_GG ( d, a, b, c, in[10], MD5_S22, (UINT4) 38016083u); /* 22 */ 156 MD5_GG ( d, a, b, c, in[10], MD5_S22, (UINT4) 38016083u); /* 22 */
157 MD5_GG ( c, d, a, b, in[15], MD5_S23, (UINT4) 3634488961u); /* 23 */ 157 MD5_GG ( c, d, a, b, in[15], MD5_S23, (UINT4) 3634488961u); /* 23 */
158 MD5_GG ( b, c, d, a, in[ 4], MD5_S24, (UINT4) 3889429448u); /* 24 */ 158 MD5_GG ( b, c, d, a, in[ 4], MD5_S24, (UINT4) 3889429448u); /* 24 */
159 MD5_GG ( a, b, c, d, in[ 9], MD5_S21, (UINT4) 568446438u); /* 25 */ 159 MD5_GG ( a, b, c, d, in[ 9], MD5_S21, (UINT4) 568446438u); /* 25 */
160 MD5_GG ( d, a, b, c, in[14], MD5_S22, (UINT4) 3275163606u); /* 26 */ 160 MD5_GG ( d, a, b, c, in[14], MD5_S22, (UINT4) 3275163606u); /* 26 */
161 MD5_GG ( c, d, a, b, in[ 3], MD5_S23, (UINT4) 4107603335u); /* 27 */ 161 MD5_GG ( c, d, a, b, in[ 3], MD5_S23, (UINT4) 4107603335u); /* 27 */
162 MD5_GG ( b, c, d, a, in[ 8], MD5_S24, (UINT4) 1163531501u); /* 28 */ 162 MD5_GG ( b, c, d, a, in[ 8], MD5_S24, (UINT4) 1163531501u); /* 28 */
163 MD5_GG ( a, b, c, d, in[13], MD5_S21, (UINT4) 2850285829u); /* 29 */ 163 MD5_GG ( a, b, c, d, in[13], MD5_S21, (UINT4) 2850285829u); /* 29 */
164 MD5_GG ( d, a, b, c, in[ 2], MD5_S22, (UINT4) 4243563512u); /* 30 */ 164 MD5_GG ( d, a, b, c, in[ 2], MD5_S22, (UINT4) 4243563512u); /* 30 */
165 MD5_GG ( c, d, a, b, in[ 7], MD5_S23, (UINT4) 1735328473u); /* 31 */ 165 MD5_GG ( c, d, a, b, in[ 7], MD5_S23, (UINT4) 1735328473u); /* 31 */
166 MD5_GG ( b, c, d, a, in[12], MD5_S24, (UINT4) 2368359562u); /* 32 */ 166 MD5_GG ( b, c, d, a, in[12], MD5_S24, (UINT4) 2368359562u); /* 32 */
167 167
168 /* Round 3 */ 168 /* Round 3 */
169 MD5_HH ( a, b, c, d, in[ 5], MD5_S31, (UINT4) 4294588738u); /* 33 */ 169 MD5_HH ( a, b, c, d, in[ 5], MD5_S31, (UINT4) 4294588738u); /* 33 */
170 MD5_HH ( d, a, b, c, in[ 8], MD5_S32, (UINT4) 2272392833u); /* 34 */ 170 MD5_HH ( d, a, b, c, in[ 8], MD5_S32, (UINT4) 2272392833u); /* 34 */
171 MD5_HH ( c, d, a, b, in[11], MD5_S33, (UINT4) 1839030562u); /* 35 */ 171 MD5_HH ( c, d, a, b, in[11], MD5_S33, (UINT4) 1839030562u); /* 35 */
172 MD5_HH ( b, c, d, a, in[14], MD5_S34, (UINT4) 4259657740u); /* 36 */ 172 MD5_HH ( b, c, d, a, in[14], MD5_S34, (UINT4) 4259657740u); /* 36 */
173 MD5_HH ( a, b, c, d, in[ 1], MD5_S31, (UINT4) 2763975236u); /* 37 */ 173 MD5_HH ( a, b, c, d, in[ 1], MD5_S31, (UINT4) 2763975236u); /* 37 */
174 MD5_HH ( d, a, b, c, in[ 4], MD5_S32, (UINT4) 1272893353u); /* 38 */ 174 MD5_HH ( d, a, b, c, in[ 4], MD5_S32, (UINT4) 1272893353u); /* 38 */
175 MD5_HH ( c, d, a, b, in[ 7], MD5_S33, (UINT4) 4139469664u); /* 39 */ 175 MD5_HH ( c, d, a, b, in[ 7], MD5_S33, (UINT4) 4139469664u); /* 39 */
176 MD5_HH ( b, c, d, a, in[10], MD5_S34, (UINT4) 3200236656u); /* 40 */ 176 MD5_HH ( b, c, d, a, in[10], MD5_S34, (UINT4) 3200236656u); /* 40 */
177 MD5_HH ( a, b, c, d, in[13], MD5_S31, (UINT4) 681279174u); /* 41 */ 177 MD5_HH ( a, b, c, d, in[13], MD5_S31, (UINT4) 681279174u); /* 41 */
178 MD5_HH ( d, a, b, c, in[ 0], MD5_S32, (UINT4) 3936430074u); /* 42 */ 178 MD5_HH ( d, a, b, c, in[ 0], MD5_S32, (UINT4) 3936430074u); /* 42 */
179 MD5_HH ( c, d, a, b, in[ 3], MD5_S33, (UINT4) 3572445317u); /* 43 */ 179 MD5_HH ( c, d, a, b, in[ 3], MD5_S33, (UINT4) 3572445317u); /* 43 */
180 MD5_HH ( b, c, d, a, in[ 6], MD5_S34, (UINT4) 76029189u); /* 44 */ 180 MD5_HH ( b, c, d, a, in[ 6], MD5_S34, (UINT4) 76029189u); /* 44 */
181 MD5_HH ( a, b, c, d, in[ 9], MD5_S31, (UINT4) 3654602809u); /* 45 */ 181 MD5_HH ( a, b, c, d, in[ 9], MD5_S31, (UINT4) 3654602809u); /* 45 */
182 MD5_HH ( d, a, b, c, in[12], MD5_S32, (UINT4) 3873151461u); /* 46 */ 182 MD5_HH ( d, a, b, c, in[12], MD5_S32, (UINT4) 3873151461u); /* 46 */
183 MD5_HH ( c, d, a, b, in[15], MD5_S33, (UINT4) 530742520u); /* 47 */ 183 MD5_HH ( c, d, a, b, in[15], MD5_S33, (UINT4) 530742520u); /* 47 */
184 MD5_HH ( b, c, d, a, in[ 2], MD5_S34, (UINT4) 3299628645u); /* 48 */ 184 MD5_HH ( b, c, d, a, in[ 2], MD5_S34, (UINT4) 3299628645u); /* 48 */
185 185
186 /* Round 4 */ 186 /* Round 4 */
187 MD5_II ( a, b, c, d, in[ 0], MD5_S41, (UINT4) 4096336452u); /* 49 */ 187 MD5_II ( a, b, c, d, in[ 0], MD5_S41, (UINT4) 4096336452u); /* 49 */
188 MD5_II ( d, a, b, c, in[ 7], MD5_S42, (UINT4) 1126891415u); /* 50 */ 188 MD5_II ( d, a, b, c, in[ 7], MD5_S42, (UINT4) 1126891415u); /* 50 */
189 MD5_II ( c, d, a, b, in[14], MD5_S43, (UINT4) 2878612391u); /* 51 */ 189 MD5_II ( c, d, a, b, in[14], MD5_S43, (UINT4) 2878612391u); /* 51 */
190 MD5_II ( b, c, d, a, in[ 5], MD5_S44, (UINT4) 4237533241u); /* 52 */ 190 MD5_II ( b, c, d, a, in[ 5], MD5_S44, (UINT4) 4237533241u); /* 52 */
191 MD5_II ( a, b, c, d, in[12], MD5_S41, (UINT4) 1700485571u); /* 53 */ 191 MD5_II ( a, b, c, d, in[12], MD5_S41, (UINT4) 1700485571u); /* 53 */
192 MD5_II ( d, a, b, c, in[ 3], MD5_S42, (UINT4) 2399980690u); /* 54 */ 192 MD5_II ( d, a, b, c, in[ 3], MD5_S42, (UINT4) 2399980690u); /* 54 */
193 MD5_II ( c, d, a, b, in[10], MD5_S43, (UINT4) 4293915773u); /* 55 */ 193 MD5_II ( c, d, a, b, in[10], MD5_S43, (UINT4) 4293915773u); /* 55 */
diff --git a/gammu/emb/common/misc/misc.c b/gammu/emb/common/misc/misc.c
index c2f09e4..7227e7b 100644
--- a/gammu/emb/common/misc/misc.c
+++ b/gammu/emb/common/misc/misc.c
@@ -1,591 +1,600 @@
1/* (c) 2002-2004 by Marcin Wiacek and Michal Cihar */ 1/* (c) 2002-2004 by Marcin Wiacek and Michal Cihar */
2/* Checking used compiler (c) 2002 by Michal Cihar */ 2/* Checking used compiler (c) 2002 by Michal Cihar */
3 3
4#include <string.h> 4#include <string.h>
5#include <ctype.h> 5#include <ctype.h>
6#include <time.h> 6#include <time.h>
7#include <stdarg.h> 7#include <stdarg.h>
8#include <stdio.h> 8#include <stdio.h>
9#include <locale.h> 9#include <locale.h>
10#include <sys/timeb.h> 10#include <sys/timeb.h>
11#ifdef WIN32 11#ifdef WIN32
12# include "windows.h" 12# include "windows.h"
13#endif 13#endif
14#if defined(linux) || defined(__linux) || defined(__linux__)
15# include <sys/utsname.h>
16#endif
14 17
15#include "../gsmstate.h" 18#include "../gsmstate.h"
16#include "misc.h" 19#include "misc.h"
17 20
18/* Based on article in Polish PC-Kurier 8/1998 page 104 21/* Based on article in Polish PC-Kurier 8/1998 page 104
19 * Archive on http://www.pckurier.pl 22 * Archive on http://www.pckurier.pl
20 */ 23 */
21char *DayOfWeek (int year, int month, int day) 24char *DayOfWeek (int year, int month, int day)
22{ 25{
23 int p,q,r,w; 26 int p,q,r,w;
24 static char DayOfWeekChar[10]; 27 static char DayOfWeekChar[10];
25 28
26 p=(14-month) / 12; 29 p=(14-month) / 12;
27 q=month+12*p-2; 30 q=month+12*p-2;
28 r=year-p; 31 r=year-p;
29 w=(day+(31*q) / 12 + r + r / 4 - r / 100 + r / 400) % 7; 32 w=(day+(31*q) / 12 + r + r / 4 - r / 100 + r / 400) % 7;
30 strcpy(DayOfWeekChar,""); 33 strcpy(DayOfWeekChar,"");
31 switch (w) { 34 switch (w) {
32 case 0: strcpy(DayOfWeekChar,"Sun"); break; 35 case 0: strcpy(DayOfWeekChar,"Sun"); break;
33 case 1: strcpy(DayOfWeekChar,"Mon"); break; 36 case 1: strcpy(DayOfWeekChar,"Mon"); break;
34 case 2: strcpy(DayOfWeekChar,"Tue"); break; 37 case 2: strcpy(DayOfWeekChar,"Tue"); break;
35 case 3: strcpy(DayOfWeekChar,"Wed"); break; 38 case 3: strcpy(DayOfWeekChar,"Wed"); break;
36 case 4: strcpy(DayOfWeekChar,"Thu"); break; 39 case 4: strcpy(DayOfWeekChar,"Thu"); break;
37 case 5: strcpy(DayOfWeekChar,"Fri"); break; 40 case 5: strcpy(DayOfWeekChar,"Fri"); break;
38 case 6: strcpy(DayOfWeekChar,"Sat"); break; 41 case 6: strcpy(DayOfWeekChar,"Sat"); break;
39 } 42 }
40 return DayOfWeekChar; 43 return DayOfWeekChar;
41} 44}
42 45
43void Fill_GSM_DateTime(GSM_DateTime *Date, time_t timet) 46void Fill_GSM_DateTime(GSM_DateTime *Date, time_t timet)
44{ 47{
45 struct tm *now; 48 struct tm *now;
46 49
47 now = localtime(&timet); 50 now = localtime(&timet);
48 Date->Year= now->tm_year; 51 Date->Year= now->tm_year;
49 Date->Month= now->tm_mon+1; 52 Date->Month= now->tm_mon+1;
50 Date->Day= now->tm_mday; 53 Date->Day= now->tm_mday;
51 Date->Hour= now->tm_hour; 54 Date->Hour= now->tm_hour;
52 Date->Minute= now->tm_min; 55 Date->Minute= now->tm_min;
53 Date->Second = now->tm_sec; 56 Date->Second = now->tm_sec;
54} 57}
55 58
56void GSM_GetCurrentDateTime (GSM_DateTime *Date) 59void GSM_GetCurrentDateTime (GSM_DateTime *Date)
57{ 60{
58 Fill_GSM_DateTime(Date, time(NULL)); 61 Fill_GSM_DateTime(Date, time(NULL));
59 if (Date->Year<1900) { 62 if (Date->Year<1900) {
60 if (Date->Year>90) Date->Year = Date->Year+1900; 63 if (Date->Year>90) Date->Year = Date->Year+1900;
61 else Date->Year = Date->Year+2000; 64 else Date->Year = Date->Year+2000;
62 } 65 }
63} 66}
64 67
65time_t Fill_Time_T(GSM_DateTime DT, int TZ) 68time_t Fill_Time_T(GSM_DateTime DT, int TZ)
66{ 69{
67 struct tm tm_starttime; 70 struct tm tm_starttime;
68 unsigned char buffer[30]; 71 unsigned char buffer[30];
69 72
70 dbgprintf(" StartTime : %02i-%02i-%04i %02i:%02i:%02i\n", 73 dbgprintf(" StartTime : %02i-%02i-%04i %02i:%02i:%02i\n",
71 DT.Day,DT.Month,DT.Year,DT.Hour,DT.Minute,DT.Second); 74 DT.Day,DT.Month,DT.Year,DT.Hour,DT.Minute,DT.Second);
72 75
73 if (TZ != 0) { 76 if (TZ != 0) {
74#if defined(WIN32) || defined(__SVR4) 77#if defined(WIN32) || defined(__SVR4)
75 sprintf(buffer,"TZ=PST+%i",TZ); 78 sprintf(buffer,"TZ=PST+%i",TZ);
76 putenv(buffer); 79 putenv(buffer);
77#else 80#else
78 sprintf(buffer,"PST+%i",TZ); 81 sprintf(buffer,"PST+%i",TZ);
79 setenv("TZ",buffer,1); 82 setenv("TZ",buffer,1);
80#endif 83#endif
81 } 84 }
82 tzset(); 85 tzset();
83 86
84 memset(&tm_starttime, 0, sizeof(tm_starttime)); 87 memset(&tm_starttime, 0, sizeof(tm_starttime));
85 tm_starttime.tm_year = DT.Year - 1900; 88 tm_starttime.tm_year = DT.Year - 1900;
86 tm_starttime.tm_mon = DT.Month - 1; 89 tm_starttime.tm_mon = DT.Month - 1;
87 tm_starttime.tm_mday = DT.Day; 90 tm_starttime.tm_mday = DT.Day;
88 tm_starttime.tm_hour = DT.Hour; 91 tm_starttime.tm_hour = DT.Hour;
89 tm_starttime.tm_min = DT.Minute; 92 tm_starttime.tm_min = DT.Minute;
90 tm_starttime.tm_sec = DT.Second; 93 tm_starttime.tm_sec = DT.Second;
91 tm_starttime.tm_isdst= 0; 94 tm_starttime.tm_isdst= 0;
92 95
93 return mktime(&tm_starttime); 96 return mktime(&tm_starttime);
94} 97}
95 98
96void GetTimeDifference(unsigned long diff, GSM_DateTime *DT, bool Plus, int multi) 99void GetTimeDifference(unsigned long diff, GSM_DateTime *DT, bool Plus, int multi)
97{ 100{
98 time_t t_time; 101 time_t t_time;
99 102
100 t_time = Fill_Time_T(*DT,8); 103 t_time = Fill_Time_T(*DT,8);
101 104
102 if (Plus) { 105 if (Plus) {
103 t_time += diff*multi; 106 t_time += diff*multi;
104 } else { 107 } else {
105 t_time -= diff*multi; 108 t_time -= diff*multi;
106 } 109 }
107 110
108 Fill_GSM_DateTime(DT, t_time); 111 Fill_GSM_DateTime(DT, t_time);
109 DT->Year = DT->Year + 1900; 112 DT->Year = DT->Year + 1900;
110 dbgprintf(" EndTime : %02i-%02i-%04i %02i:%02i:%02i\n", 113 dbgprintf(" EndTime : %02i-%02i-%04i %02i:%02i:%02i\n",
111 DT->Day,DT->Month,DT->Year,DT->Hour,DT->Minute,DT->Second); 114 DT->Day,DT->Month,DT->Year,DT->Hour,DT->Minute,DT->Second);
112} 115}
113 116
114char *OSDateTime (GSM_DateTime dt, bool TimeZone) 117char *OSDateTime (GSM_DateTime dt, bool TimeZone)
115{ 118{
116 struct tm timeptr; 119 struct tm timeptr;
117 static char retval[200],retval2[200]; 120 static char retval[200],retval2[200];
118 int p,q,r,w; 121 int p,q,r,w;
119 122
120#ifdef WIN32 123#ifdef WIN32
121 setlocale(LC_ALL, ".OCP"); 124 setlocale(LC_ALL, ".OCP");
122#endif 125#endif
123 126
124 /* Based on article in Polish PC-Kurier 8/1998 page 104 127 /* Based on article in Polish PC-Kurier 8/1998 page 104
125 * Archive on http://www.pckurier.pl 128 * Archive on http://www.pckurier.pl
126 */ 129 */
127 p=(14-dt.Month) / 12; 130 p=(14-dt.Month) / 12;
128 q=dt.Month+12*p-2; 131 q=dt.Month+12*p-2;
129 r=dt.Year-p; 132 r=dt.Year-p;
130 w=(dt.Day+(31*q) / 12 + r + r / 4 - r / 100 + r / 400) % 7; 133 w=(dt.Day+(31*q) / 12 + r + r / 4 - r / 100 + r / 400) % 7;
131 134
132 timeptr.tm_yday = 0; /* FIXME */ 135 timeptr.tm_yday = 0; /* FIXME */
133 timeptr.tm_isdst = -1; /* FIXME */ 136 timeptr.tm_isdst = -1; /* FIXME */
134 timeptr.tm_year = dt.Year - 1900; 137 timeptr.tm_year = dt.Year - 1900;
135 timeptr.tm_mon = dt.Month - 1; 138 timeptr.tm_mon = dt.Month - 1;
136 timeptr.tm_mday = dt.Day; 139 timeptr.tm_mday = dt.Day;
137 timeptr.tm_hour = dt.Hour; 140 timeptr.tm_hour = dt.Hour;
138 timeptr.tm_min = dt.Minute; 141 timeptr.tm_min = dt.Minute;
139 timeptr.tm_sec = dt.Second; 142 timeptr.tm_sec = dt.Second;
140 timeptr.tm_wday = w; 143 timeptr.tm_wday = w;
141#ifdef _BSD_SOURCE 144#ifdef _BSD_SOURCE
142 timeptr.tm_zone = NULL; 145 timeptr.tm_zone = NULL;
143#endif 146#endif
144 147
145#ifdef WIN32 148#ifdef WIN32
146 strftime(retval2, 200, "%#c", &timeptr); 149 strftime(retval2, 200, "%#c", &timeptr);
147#else 150#else
148 strftime(retval2, 200, "%c", &timeptr); 151 strftime(retval2, 200, "%c", &timeptr);
149#endif 152#endif
150 if (TimeZone) { 153 if (TimeZone) {
151 if (dt.Timezone >= 0) { 154 if (dt.Timezone >= 0) {
152 sprintf(retval," +%02i00",dt.Timezone); 155 sprintf(retval," +%02i00",dt.Timezone);
153 } else { 156 } else {
154 sprintf(retval," -%02i00",dt.Timezone); 157 sprintf(retval," -%02i00",dt.Timezone);
155 } 158 }
156 strcat(retval2,retval); 159 strcat(retval2,retval);
157 } 160 }
158 /* If don't have weekday name, include it */ 161 /* If don't have weekday name, include it */
159 strftime(retval, 200, "%A", &timeptr); 162 strftime(retval, 200, "%A", &timeptr);
160 if (strstr(retval2,retval)==NULL) { 163 if (strstr(retval2,retval)==NULL) {
161 /* Check for abbreviated weekday */ 164 /* Check for abbreviated weekday */
162 strftime(retval, 200, "%a", &timeptr); 165 strftime(retval, 200, "%a", &timeptr);
163 if (strstr(retval2,retval)==NULL) { 166 if (strstr(retval2,retval)==NULL) {
164 strcat(retval2," ("); 167 strcat(retval2," (");
165 strcat(retval2,retval); 168 strcat(retval2,retval);
166 strcat(retval2,")"); 169 strcat(retval2,")");
167 } 170 }
168 } 171 }
169 172
170#ifdef WIN32 173#ifdef WIN32
171 setlocale(LC_ALL, ".ACP"); 174 setlocale(LC_ALL, ".ACP");
172#endif 175#endif
173 176
174 return retval2; 177 return retval2;
175} 178}
176 179
177char *OSDate (GSM_DateTime dt) 180char *OSDate (GSM_DateTime dt)
178{ 181{
179 struct tm timeptr; 182 struct tm timeptr;
180 static char retval[200],retval2[200]; 183 static char retval[200],retval2[200];
181 int p,q,r,w; 184 int p,q,r,w;
182 185
183#ifdef WIN32 186#ifdef WIN32
184 setlocale(LC_ALL, ".OCP"); 187 setlocale(LC_ALL, ".OCP");
185#endif 188#endif
186 189
187 /* Based on article in Polish PC-Kurier 8/1998 page 104 190 /* Based on article in Polish PC-Kurier 8/1998 page 104
188 * Archive on http://www.pckurier.pl 191 * Archive on http://www.pckurier.pl
189 */ 192 */
190 p=(14-dt.Month) / 12; 193 p=(14-dt.Month) / 12;
191 q=dt.Month+12*p-2; 194 q=dt.Month+12*p-2;
192 r=dt.Year-p; 195 r=dt.Year-p;
193 w=(dt.Day+(31*q) / 12 + r + r / 4 - r / 100 + r / 400) % 7; 196 w=(dt.Day+(31*q) / 12 + r + r / 4 - r / 100 + r / 400) % 7;
194 197
195 timeptr.tm_yday = 0; /* FIXME */ 198 timeptr.tm_yday = 0; /* FIXME */
196 timeptr.tm_isdst = -1; /* FIXME */ 199 timeptr.tm_isdst = -1; /* FIXME */
197 timeptr.tm_year = dt.Year - 1900; 200 timeptr.tm_year = dt.Year - 1900;
198 timeptr.tm_mon = dt.Month - 1; 201 timeptr.tm_mon = dt.Month - 1;
199 timeptr.tm_mday = dt.Day; 202 timeptr.tm_mday = dt.Day;
200 timeptr.tm_hour = dt.Hour; 203 timeptr.tm_hour = dt.Hour;
201 timeptr.tm_min = dt.Minute; 204 timeptr.tm_min = dt.Minute;
202 timeptr.tm_sec = dt.Second; 205 timeptr.tm_sec = dt.Second;
203 timeptr.tm_wday = w; 206 timeptr.tm_wday = w;
204#ifdef _BSD_SOURCE 207#ifdef _BSD_SOURCE
205 timeptr.tm_zone = NULL; 208 timeptr.tm_zone = NULL;
206#endif 209#endif
207 210
208#ifdef WIN32 211#ifdef WIN32
209 strftime(retval2, 200, "%#x", &timeptr); 212 strftime(retval2, 200, "%#x", &timeptr);
210#else 213#else
211 strftime(retval2, 200, "%x", &timeptr); 214 strftime(retval2, 200, "%x", &timeptr);
212#endif 215#endif
213 /* If don't have weekday name, include it */ 216 /* If don't have weekday name, include it */
214 strftime(retval, 200, "%A", &timeptr); 217 strftime(retval, 200, "%A", &timeptr);
215 if (strstr(retval2,retval)==NULL) { 218 if (strstr(retval2,retval)==NULL) {
216 /* Check also for short name */ 219 /* Check also for short name */
217 strftime(retval, 200, "%a", &timeptr); 220 strftime(retval, 200, "%a", &timeptr);
218 if (strstr(retval2,retval)==NULL) { 221 if (strstr(retval2,retval)==NULL) {
219 strcat(retval2," ("); 222 strcat(retval2," (");
220 strcat(retval2,retval); 223 strcat(retval2,retval);
221 strcat(retval2,")"); 224 strcat(retval2,")");
222 } 225 }
223 } 226 }
224 227
225#ifdef WIN32 228#ifdef WIN32
226 setlocale(LC_ALL, ".ACP"); 229 setlocale(LC_ALL, ".ACP");
227#endif 230#endif
228 231
229 return retval2; 232 return retval2;
230} 233}
231 234
232bool CheckDate(GSM_DateTime *date) 235bool CheckDate(GSM_DateTime *date)
233{ 236 {
234 /* FIXME: This could also check if day is correct for selected month */ 237 const unsigned int days[]={31,29,31,30,31,30,31,31,30,31,30,31};
238
239 /* FIXME: This could also check for leap years */
235 return date->Year != 0 && 240 return date->Year != 0 &&
236 date->Month >= 1 && date->Month <= 12 && 241 date->Month >= 1 && date->Month <= 12 &&
237 date->Day >= 1 && date->Day <= 31; 242 date->Day >= 1 && date->Day <= days[date->Month];
238} 243}
239 244
240bool CheckTime(GSM_DateTime *date) 245bool CheckTime(GSM_DateTime *date)
241{ 246{
242 return date->Hour <= 23 && date->Hour >= 0 && 247 return date->Hour <= 23 && date->Hour >= 0 &&
243 date->Minute <= 59 && date->Minute >= 0 && 248 date->Minute <= 59 && date->Minute >= 0 &&
244 date->Second <= 59 && date->Second >= 0; 249 date->Second <= 59 && date->Second >= 0;
245} 250}
246 251
247int GetLine(FILE *File, char *Line, int count) 252int GetLine(FILE *File, char *Line, int count)
248{ 253{
249 int num; 254 int num;
250 255
251 if (fgets(Line, count, File) != NULL) { 256 if (fgets(Line, count, File) != NULL) {
252 num = strlen(Line) - 1; 257 num = strlen(Line) - 1;
253 while(1) { 258 while(1) {
254 if (Line[num] != '\n' && Line[num] != '\r') break; 259 if (Line[num] != '\n' && Line[num] != '\r') break;
255 if (num == 0) break; 260 if (num == 0) break;
256 Line[num--] = 0; 261 Line[num--] = 0;
257 } 262 }
258 return strlen(Line); 263 return strlen(Line);
259 } 264 }
260 return -1; 265 return -1;
261} 266}
262 267
263void SplitLines(unsigned char *message, int messagesize, GSM_Lines *lines, unsigned char *whitespaces, int spaceslen, bool eot) 268void SplitLines(unsigned char *message, int messagesize, GSM_Lines *lines, unsigned char *whitespaces, int spaceslen, bool eot)
264{ 269{
265 int i,number=0,j; 270 int i,number=0,j;
266 bool whitespace=true, nowwhite; 271 bool whitespace=true, nowwhite;
267 272
268 for (i=0;i<MAX_LINES*2;i++) lines->numbers[i]=0; 273 for (i=0;i<MAX_LINES*2;i++) lines->numbers[i]=0;
269 274
270 for (i=0;i<messagesize;i++) { 275 for (i=0;i<messagesize;i++) {
271 nowwhite = false; 276 nowwhite = false;
272 for (j=0;j<spaceslen;j++) { 277 for (j=0;j<spaceslen;j++) {
273 if (whitespaces[j] == message[i]) { 278 if (whitespaces[j] == message[i]) {
274 nowwhite = true; 279 nowwhite = true;
275 break; 280 break;
276 } 281 }
277 } 282 }
278 if (whitespace) { 283 if (whitespace) {
279 if (!nowwhite) { 284 if (!nowwhite) {
280 lines->numbers[number]=i; 285 lines->numbers[number]=i;
281 number++; 286 number++;
282 whitespace=false; 287 whitespace=false;
283 } 288 }
284 } else { 289 } else {
285 if (nowwhite) { 290 if (nowwhite) {
286 lines->numbers[number]=i; 291 lines->numbers[number]=i;
287 number++; 292 number++;
288 whitespace=true; 293 whitespace=true;
289 } 294 }
290 295
291 } 296 }
292 } 297 }
293 if (eot && !whitespace) lines->numbers[number]=messagesize; 298 if (eot && !whitespace) lines->numbers[number]=messagesize;
294} 299}
295 300
296char *GetLineString(unsigned char *message, GSM_Lines lines, int start) 301char *GetLineString(unsigned char *message, GSM_Lines lines, int start)
297{ 302{
298 static char retval[800]; 303 static char retval[800];
299 304
300 memcpy(retval,message + lines.numbers[start*2-2],lines.numbers[start*2-2+1]-lines.numbers[start*2-2]); 305 memcpy(retval,message + lines.numbers[start*2-2],lines.numbers[start*2-2+1]-lines.numbers[start*2-2]);
301 retval[lines.numbers[start*2-2+1]-lines.numbers[start*2-2]]=0; 306 retval[lines.numbers[start*2-2+1]-lines.numbers[start*2-2]]=0;
302 307
303 return retval; 308 return retval;
304} 309}
305 310
306void CopyLineString(unsigned char *dest, unsigned char *src, GSM_Lines lines, int start) 311void CopyLineString(unsigned char *dest, unsigned char *src, GSM_Lines lines, int start)
307{ 312{
308 memcpy(dest,GetLineString(src, lines, start),strlen(GetLineString(src, lines, start))); 313 memcpy(dest,GetLineString(src, lines, start),strlen(GetLineString(src, lines, start)));
309 dest[strlen(GetLineString(src, lines, start))] = 0; 314 dest[strlen(GetLineString(src, lines, start))] = 0;
310} 315}
311 316
312Debug_Info di = {0,NULL,false,""}; 317Debug_Info di = {0,NULL,false,""};
313 318
314#ifdef DEBUG 319#ifdef DEBUG
315#ifdef __GNUC__ 320#ifdef __GNUC__
316__attribute__((format(printf, 1, 2))) 321__attribute__((format(printf, 1, 2)))
317#endif 322#endif
318int dbgprintf(const char *format, ...) 323int dbgprintf(const char *format, ...)
319{ 324{
320 va_list argp; 325 va_list argp;
321 int result; 326 int result;
322 static unsigned char nextline[2000]=""; 327 static unsigned char nextline[2000]="";
323 unsigned char buffer[2000]; 328 unsigned char buffer[2000];
324 GSM_DateTime date_time; 329 GSM_DateTime date_time;
325 330
326 if (di.df != NULL && (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE)) { 331 if (di.df != NULL && (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE)) {
327 va_start(argp, format); 332 va_start(argp, format);
328 result = vsprintf(buffer, format, argp); 333 result = vsprintf(buffer, format, argp);
329 strcat(nextline, buffer); 334 strcat(nextline, buffer);
330 if (strstr(buffer, "\n")) { 335 if (strstr(buffer, "\n")) {
331 if (di.dl == DL_TEXTALLDATE) { 336 if (di.dl == DL_TEXTALLDATE) {
332 GSM_GetCurrentDateTime(&date_time); 337 GSM_GetCurrentDateTime(&date_time);
333 fprintf(di.df,"%s %4d/%02d/%02d %02d:%02d:%02d: %s", 338 fprintf(di.df,"%s %4d/%02d/%02d %02d:%02d:%02d: %s",
334 DayOfWeek(date_time.Year, date_time.Month, date_time.Day), 339 DayOfWeek(date_time.Year, date_time.Month, date_time.Day),
335 date_time.Year, date_time.Month, date_time.Day, 340 date_time.Year, date_time.Month, date_time.Day,
336 date_time.Hour, date_time.Minute, date_time.Second,nextline); 341 date_time.Hour, date_time.Minute, date_time.Second,nextline);
337 } else { 342 } else {
338 fprintf(di.df,"%s",nextline); 343 fprintf(di.df,"%s",nextline);
339 } 344 }
340 strcpy(nextline, ""); 345 strcpy(nextline, "");
341 } 346 }
342 fflush(di.df); 347 fflush(di.df);
343 va_end(argp); 348 va_end(argp);
344 return result; 349 return result;
345 } 350 }
346 return 0; 351 return 0;
347} 352}
348#endif 353#endif
349 354
350/* assumption: if \n is present it is always the last char, 355/* assumption: if \n is present it is always the last char,
351 * string never of the form "......\n..." 356 * string never of the form "......\n..."
352 */ 357 */
353#ifdef __GNUC__ 358#ifdef __GNUC__
354__attribute__((format(printf, 3, 4))) 359__attribute__((format(printf, 3, 4)))
355#endif 360#endif
356int smfprintf(FILE *f, Debug_Level dl, const char *format, ...) 361int smfprintf(FILE *f, Debug_Level dl, const char *format, ...)
357{ 362{
358 va_list argp; 363 va_list argp;
359 int result=0; 364 int result=0;
360 static unsigned char prevline[2000] = "", nextline[2000]=""; 365 static unsigned char prevline[2000] = "", nextline[2000]="";
361 static unsigned int linecount=0; 366 static unsigned int linecount=0;
362 unsigned char buffer[2000]; 367 unsigned char buffer[2000];
363 GSM_DateTime date_time; 368 GSM_DateTime date_time;
364 369
365 if (f == NULL) return 0; 370 if (f == NULL) return 0;
366 va_start(argp, format); 371 va_start(argp, format);
367 result = vsprintf(buffer, format, argp); 372 result = vsprintf(buffer, format, argp);
368 strcat(nextline, buffer); 373 strcat(nextline, buffer);
369 if (strstr(buffer, "\n")) { 374 if (strstr(buffer, "\n")) {
370 if (ftell(f) < 5000000) { 375 if (ftell(f) < 5000000) {
371 GSM_GetCurrentDateTime(&date_time); 376 GSM_GetCurrentDateTime(&date_time);
372 if (linecount > 0) { 377 if (linecount > 0) {
373 if (dl == DL_TEXTALLDATE || dl == DL_TEXTERRORDATE || dl == DL_TEXTDATE) { 378 if (dl == DL_TEXTALLDATE || dl == DL_TEXTERRORDATE || dl == DL_TEXTDATE) {
374 fprintf(f,"%s %4d/%02d/%02d %02d:%02d:%02d: <%i> %s", 379 fprintf(f,"%s %4d/%02d/%02d %02d:%02d:%02d: <%i> %s",
375 DayOfWeek(date_time.Year, date_time.Month, date_time.Day), 380 DayOfWeek(date_time.Year, date_time.Month, date_time.Day),
376 date_time.Year, date_time.Month, date_time.Day, 381 date_time.Year, date_time.Month, date_time.Day,
377 date_time.Hour, date_time.Minute, date_time.Second,linecount,prevline); 382 date_time.Hour, date_time.Minute, date_time.Second,linecount,prevline);
378 } else { 383 } else {
379 fprintf(f,"%s",prevline); 384 fprintf(f,"%s",prevline);
380 } 385 }
381 } 386 }
382 linecount=0; 387 linecount=0;
383 if (dl == DL_TEXTALLDATE || dl == DL_TEXTERRORDATE || dl == DL_TEXTDATE) { 388 if (dl == DL_TEXTALLDATE || dl == DL_TEXTERRORDATE || dl == DL_TEXTDATE) {
384 fprintf(f,"%s %4d/%02d/%02d %02d:%02d:%02d: %s", 389 fprintf(f,"%s %4d/%02d/%02d %02d:%02d:%02d: %s",
385 DayOfWeek(date_time.Year, date_time.Month, date_time.Day), 390 DayOfWeek(date_time.Year, date_time.Month, date_time.Day),
386 date_time.Year, date_time.Month, date_time.Day, 391 date_time.Year, date_time.Month, date_time.Day,
387 date_time.Hour, date_time.Minute, date_time.Second,nextline); 392 date_time.Hour, date_time.Minute, date_time.Second,nextline);
388 } else { 393 } else {
389 fprintf(f,"%s",nextline); 394 fprintf(f,"%s",nextline);
390 } 395 }
391 strcpy(prevline, nextline); 396 strcpy(prevline, nextline);
392 } 397 }
393 strcpy(nextline, ""); 398 strcpy(nextline, "");
394 fflush(f); 399 fflush(f);
395 } 400 }
396 va_end(argp); 401 va_end(argp);
397 return result; 402 return result;
398} 403}
399 404
400bool GSM_SetDebugLevel(char *info, Debug_Info *di) 405bool GSM_SetDebugLevel(char *info, Debug_Info *di)
401{ 406{
402 if (!strcmp(info,"nothing")) {di->dl = 0; return true;} 407 if (!strcmp(info,"nothing")) {di->dl = 0; return true;}
403 if (!strcmp(info,"text")) {di->dl = DL_TEXT; return true;} 408 if (!strcmp(info,"text")) {di->dl = DL_TEXT; return true;}
404 if (!strcmp(info,"textall")) {di->dl = DL_TEXTALL; return true;} 409 if (!strcmp(info,"textall")) {di->dl = DL_TEXTALL; return true;}
405 if (!strcmp(info,"binary")) {di->dl = DL_BINARY; return true;} 410 if (!strcmp(info,"binary")) {di->dl = DL_BINARY; return true;}
406 if (!strcmp(info,"errors")) {di->dl = DL_TEXTERROR; return true;} 411 if (!strcmp(info,"errors")) {di->dl = DL_TEXTERROR; return true;}
407 if (!strcmp(info,"textdate")) {di->dl = DL_TEXTDATE; return true;} 412 if (!strcmp(info,"textdate")) {di->dl = DL_TEXTDATE; return true;}
408 if (!strcmp(info,"textalldate")) {di->dl = DL_TEXTALLDATE; return true;} 413 if (!strcmp(info,"textalldate")) {di->dl = DL_TEXTALLDATE; return true;}
409 if (!strcmp(info,"errorsdate")) {di->dl = DL_TEXTERRORDATE; return true;} 414 if (!strcmp(info,"errorsdate")) {di->dl = DL_TEXTERRORDATE; return true;}
410 return false; 415 return false;
411} 416}
412 417
413/* Dumps a message */ 418/* Dumps a message */
414void DumpMessage(FILE *df, Debug_Level dl, const unsigned char *message, int messagesize) 419void DumpMessage(FILE *df, Debug_Level dl, const unsigned char *message, int messagesize)
415{ 420{
416 int i,j=0,len=16; 421 int i,j=0,len=16;
417 unsigned charbuffer[200]; 422 unsigned charbuffer[200];
418 423
419 if (df==NULL || messagesize == 0) return; 424 if (df==NULL || messagesize == 0) return;
420 425
421 smfprintf(df, dl, "\n"); 426 smfprintf(df, dl, "\n");
422 427
423 memset(buffer,0x20,sizeof(buffer)); 428 memset(buffer,0x20,sizeof(buffer));
424 buffer[len*5-1]=0; 429 buffer[len*5-1]=0;
425 430
426 for (i = 0; i < messagesize; i++) { 431 for (i = 0; i < messagesize; i++) {
427 sprintf(buffer+j*4,"%02X",message[i]); 432 sprintf(buffer+j*4,"%02X",message[i]);
428 buffer[j*4+2] = 0x20; 433 buffer[j*4+2] = 0x20;
429 if (isprint(message[i]) && message[i]!=0x09) { 434 if (isprint(message[i]) && message[i]!=0x09) {
430 if (j != len-1) buffer[j*4+2] = message[i]; 435 if (j != len-1) buffer[j*4+2] = message[i];
431 buffer[(len-1)*4+j+3] = message[i]; 436 buffer[(len-1)*4+j+3] = message[i];
432 } else { 437 } else {
433 buffer[(len-1)*4+j+3] = '.'; 438 buffer[(len-1)*4+j+3] = '.';
434 } 439 }
435 if (j != len-1 && i != messagesize-1) buffer[j*4+3] = '|'; 440 if (j != len-1 && i != messagesize-1) buffer[j*4+3] = '|';
436 if (j == len-1) { 441 if (j == len-1) {
437 smfprintf(df, dl, "%s\n", buffer); 442 smfprintf(df, dl, "%s\n", buffer);
438 memset(buffer,0x20,sizeof(buffer)); 443 memset(buffer,0x20,sizeof(buffer));
439 buffer[len*5-1]=0; 444 buffer[len*5-1]=0;
440 j = 0; 445 j = 0;
441 } else { 446 } else {
442 j++; 447 j++;
443 } 448 }
444 } 449 }
445 if (j != 0) smfprintf(df, dl, "%s\n", buffer); 450 if (j != 0) smfprintf(df, dl, "%s\n", buffer);
446} 451}
447 452
448char *GetOS(void) 453char *GetOS(void)
449{ 454{
450#ifdef WIN32 455#ifdef WIN32
451 OSVERSIONINFOEX Ver; 456 OSVERSIONINFOEX Ver;
452 bool Extended = true; 457 bool Extended = true;
453#endif 458#endif
459#if defined(linux) || defined(__linux) || defined(__linux__)
460 struct utsnameVer;
461#endif
454 static char Buffer[100] = {0x00}; 462 static char Buffer[100] = {0x00};
455 463
456#ifdef WIN32 464#ifdef WIN32
457 memset(&Ver,sizeof(OSVERSIONINFOEX),0); 465 memset(&Ver,sizeof(OSVERSIONINFOEX),0);
458 Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); 466 Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
459 467
460 if (!GetVersionEx((OSVERSIONINFO *)&Ver)) { 468 if (!GetVersionEx((OSVERSIONINFO *)&Ver)) {
461 Extended = false; 469 Extended = false;
462 Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 470 Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
463 if (!GetVersionEx((OSVERSIONINFO *)&Ver)) { 471 if (!GetVersionEx((OSVERSIONINFO *)&Ver)) {
464//#ifdef _MSC_VER 472//#ifdef _MSC_VER
465 // Ver.dwMajorVersion = _winmajor; 473 // Ver.dwMajorVersion = _winmajor;
466 // Ver.dwMinorVersion = _winminor; 474 // Ver.dwMinorVersion = _winminor;
467 // Ver.dwBuildNumber = _osver; 475 // Ver.dwBuildNumber = _osver;
468//#else 476//#else
469 sprintf(Buffer, "Windows"); 477 sprintf(Buffer, "Windows");
470 return Buffer; 478 return Buffer;
471//#endif 479//#endif
472 } 480 }
473 } 481 }
474 482
475 /* ----------------- 9x family ------------------ */ 483 /* ----------------- 9x family ------------------ */
476 484
477 /* no info about Win95 SP1, Win95 OSR2.1, Win95 OSR2.5.... */ 485 /* no info about Win95 SP1, Win95 OSR2.1, Win95 OSR2.5.... */
478 if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 950) { 486 if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 950) {
479 sprintf(Buffer,"Win 95"); 487 sprintf(Buffer,"Win 95");
480 } else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 1111) { 488 } else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 1111) {
481 sprintf(Buffer,"Win 95 OSR2.x"); 489 sprintf(Buffer,"Win 95 OSR2.x");
482 490
483 /* no info about Win98 SP1.... */ 491 /* no info about Win98 SP1.... */
484 } else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 10 && Ver.dwBuildNumber == 1998) { 492 } else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 10 && Ver.dwBuildNumber == 1998) {
485 sprintf(Buffer,"Win 98"); 493 sprintf(Buffer,"Win 98");
486 } else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 10 && Ver.dwBuildNumber == 2222) { 494 } else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 10 && Ver.dwBuildNumber == 2222) {
487 sprintf(Buffer,"Win 98 SE"); 495 sprintf(Buffer,"Win 98 SE");
488 496
489 } else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 90 && Ver.dwBuildNumber == 3000) { 497 } else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 90 && Ver.dwBuildNumber == 3000) {
490 sprintf(Buffer,"Win ME"); 498 sprintf(Buffer,"Win ME");
491 499
492 /* ---------------- NT family ------------------- */ 500 /* ---------------- NT family ------------------- */
493 501
494 } else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 1381) { 502 } else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 1381) {
495 sprintf(Buffer,"Win NT 4.0"); 503 sprintf(Buffer,"Win NT 4.0");
496 504
497 } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 2195) { 505 } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 2195) {
498 sprintf(Buffer,"Win 2000"); 506 sprintf(Buffer,"Win 2000");
499 507
500 } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 1 && Ver.dwBuildNumber == 2600) { 508 } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 1 && Ver.dwBuildNumber == 2600) {
501 sprintf(Buffer,"Win XP"); 509 sprintf(Buffer,"Win XP");
502#if _MSC_VER > 1200 //6.0 has it undeclared 510#if _MSC_VER > 1200 //6.0 has it undeclared
503 if (Extended) { 511 if (Extended) {
504 if (Ver.wSuiteMask & VER_SUITE_PERSONAL) { 512 if (Ver.wSuiteMask & VER_SUITE_PERSONAL) {
505 sprintf(Buffer+strlen(Buffer)," Home"); 513 sprintf(Buffer+strlen(Buffer)," Home");
506 } else { 514 } else {
507 sprintf(Buffer+strlen(Buffer)," Pro"); 515 sprintf(Buffer+strlen(Buffer)," Pro");
508 } 516 }
509 } 517 }
510#endif 518#endif
511 519
512 } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 2) { 520 } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 2) {
513 sprintf(Buffer,"Win 2003"); 521 sprintf(Buffer,"Win 2003");
514 522
515 } else { 523 } else {
516 sprintf(Buffer, "Windows %i.%i.%i",Ver.dwMajorVersion,Ver.dwMinorVersion,Ver.dwBuildNumber); 524 sprintf(Buffer, "Windows %i.%i.%i",Ver.dwMajorVersion,Ver.dwMinorVersion,Ver.dwBuildNumber);
517 } 525 }
518 526
519 if (Extended && Ver.wServicePackMajor != 0) { 527 if (Extended && Ver.wServicePackMajor != 0) {
520 sprintf(Buffer+strlen(Buffer)," SP%i",Ver.wServicePackMajor); 528 sprintf(Buffer+strlen(Buffer)," SP%i",Ver.wServicePackMajor);
521 } 529 }
522#elif defined(linux) || defined(__linux) || defined(__linux__) 530#elif defined(linux) || defined(__linux) || defined(__linux__)
523 sprintf(Buffer, "Linux"); 531 uname(&Ver);
532 sprintf(Buffer, "Linux, kernel %s",Ver.release);
524#elif defined(__FreeBSD__) 533#elif defined(__FreeBSD__)
525 sprintf(Buffer, "FreeBSD"); 534 sprintf(Buffer, "FreeBSD");
526#elif defined(__NetBSD__) 535#elif defined(__NetBSD__)
527 sprintf(Buffer, "NetBSD"); 536 sprintf(Buffer, "NetBSD");
528#elif defined(__OpenBSD__) 537#elif defined(__OpenBSD__)
529 sprintf(Buffer, "OpenBSD"); 538 sprintf(Buffer, "OpenBSD");
530#elif defined(__GNU__) 539#elif defined(__GNU__)
531 sprintf(Buffer, "GNU/Hurd"); 540 sprintf(Buffer, "GNU/Hurd");
532#elif defined(sun) || defined(__sun) || defined(__sun__) 541#elif defined(sun) || defined(__sun) || defined(__sun__)
533# ifdef __SVR4 542# ifdef __SVR4
534 sprintf(Buffer, "Sun Solaris"); 543 sprintf(Buffer, "Sun Solaris");
535# else 544# else
536 sprintf(Buffer, "SunOS"); 545 sprintf(Buffer, "SunOS");
537# endif 546# endif
538#elif defined(hpux) || defined(__hpux) || defined(__hpux__) 547#elif defined(hpux) || defined(__hpux) || defined(__hpux__)
539 sprintf(Buffer, "HP-UX"); 548 sprintf(Buffer, "HP-UX");
540#elif defined(ultrix) || defined(__ultrix) || defined(__ultrix__) 549#elif defined(ultrix) || defined(__ultrix) || defined(__ultrix__)
541 sprintf(Buffer, "DEC Ultrix"); 550 sprintf(Buffer, "DEC Ultrix");
542#elif defined(sgi) || defined(__sgi) 551#elif defined(sgi) || defined(__sgi)
543 sprintf(Buffer, "SGI Irix"); 552 sprintf(Buffer, "SGI Irix");
544#elif defined(__osf__) 553#elif defined(__osf__)
545 sprintf(Buffer, "OSF Unix"); 554 sprintf(Buffer, "OSF Unix");
546#elif defined(bsdi) || defined(__bsdi__) 555#elif defined(bsdi) || defined(__bsdi__)
547 sprintf(Buffer, "BSDI Unix"); 556 sprintf(Buffer, "BSDI Unix");
548#elif defined(_AIX) 557#elif defined(_AIX)
549 sprintf(Buffer, "AIX Unix"); 558 sprintf(Buffer, "AIX Unix");
550#elif defined(_UNIXWARE) 559#elif defined(_UNIXWARE)
551 sprintf(Buffer, "SCO Unixware"); 560 sprintf(Buffer, "SCO Unixware");
552#elif defined(DGUX) 561#elif defined(DGUX)
553 sprintf(Buffer, "DG Unix"); 562 sprintf(Buffer, "DG Unix");
554#elif defined(__QNX__) 563#elif defined(__QNX__)
555 sprintf(Buffer, "QNX"); 564 sprintf(Buffer, "QNX");
556#endif 565#endif
557 return Buffer; 566 return Buffer;
558} 567}
559 568
560char *GetCompiler(void) 569char *GetCompiler(void)
561{ 570{
562 static char Buffer[100] = {0x00}; 571 static char Buffer[100] = {0x00};
563 572
564#ifdef WIN32 573#ifdef WIN32
565# ifdef _MSC_VER 574# ifdef _MSC_VER
566 if (_MSC_VER == 1200) { //? 575 if (_MSC_VER == 1200) { //?
567 sprintf(Buffer, "MS VC 6.0"); 576 sprintf(Buffer, "MS VC 6.0");
568 } else if (_MSC_VER == 1300) { 577 } else if (_MSC_VER == 1300) {
569 sprintf(Buffer, "MS VC .NET 2002"); 578 sprintf(Buffer, "MS VC .NET 2002");
570 } else if (_MSC_VER == 1310) { 579 } else if (_MSC_VER == 1310) {
571 sprintf(Buffer, "MS VC .NET 2003"); 580 sprintf(Buffer, "MS VC .NET 2003");
572 } else { 581 } else {
573 sprintf(Buffer, "MS VC %i",_MSC_VER); 582 sprintf(Buffer, "MS VC %i",_MSC_VER);
574 } 583 }
575# elif defined(__BORLANDC__) 584# elif defined(__BORLANDC__)
576 sprintf(Buffer, "Borland C++ %i",__BORLANDC__); 585 sprintf(Buffer, "Borland C++ %i",__BORLANDC__);
577# endif 586# endif
578#elif defined(DJGPP) 587#elif defined(DJGPP)
579 sprintf(Buffer, "djgpp"); 588 sprintf(Buffer, "djgpp");
580#elif defined(__GNUC__) 589#elif defined(__GNUC__)
581 sprintf(Buffer, "gcc %i.%i", __GNUC__, __GNUC_MINOR__); 590 sprintf(Buffer, "gcc %i.%i", __GNUC__, __GNUC_MINOR__);
582#elif defined(__SUNPRO_CC) 591#elif defined(__SUNPRO_CC)
583 sprintf(Buffer, "Sun C++ %x", __SUNPRO_CC); 592 sprintf(Buffer, "Sun C++ %x", __SUNPRO_CC);
584#endif 593#endif
585 594
586 return Buffer; 595 return Buffer;
587} 596}
588 597
589/* How should editor hadle tabs in this file? Add editor commands here. 598/* How should editor hadle tabs in this file? Add editor commands here.
590 * vim: noexpandtab sw=8 ts=8 sts=8: 599 * vim: noexpandtab sw=8 ts=8 sts=8:
591 */ 600 */
diff --git a/gammu/emb/common/misc/misc.h b/gammu/emb/common/misc/misc.h
index 8b46170..c461001 100644
--- a/gammu/emb/common/misc/misc.h
+++ b/gammu/emb/common/misc/misc.h
@@ -1,137 +1,145 @@
1/* (c) 2002-2004 by Marcin Wiacek */ 1/* (c) 2002-2004 by Marcin Wiacek */
2 2
3#ifndef __misc_h 3#ifndef __misc_h
4#define __misc_h 4#define __misc_h
5 5
6#if defined(_MSC_VER) && defined(__cplusplus)
7 extern "C" {
8#endif
9
6#include <stdio.h> 10#include <stdio.h>
7#include <time.h> 11#include <time.h>
8#ifdef WIN32 12#ifdef WIN32
9# include <windows.h> 13# include <windows.h>
10#endif 14#endif
11 15
12#include "../config.h" 16#include "../config.h"
13 17
14#ifndef __cplusplus 18#ifndef __cplusplus
15#ifndef false 19#ifndef false
16# define false 0 20# define false 0
17#endif 21#endif
18#ifndef true 22#ifndef true
19 # define true !0 23 # define true !0
20#endif 24#endif
21#ifndef bool 25#ifndef bool
22 # define boolchar 26 # define boolchar
23#endif 27#endif
24#endif /* __cplusplus */ 28#endif /* __cplusplus */
25 29
26#ifdef WIN32 30#ifdef WIN32
27# define my_sleep(x) ((x)<1000 ? Sleep(1) : Sleep((x)/1000)) 31# define my_sleep(x) ((x)<1000 ? Sleep(1) : Sleep((x)/1000))
28#else 32#else
29# define my_sleep(x) usleep(x) 33# define my_sleep(x) usleep(x)
30#endif 34#endif
31 35
32#undef MAX 36#undef MAX
33#define MAX(a,b) ((a)>(b) ? (a) : (b)) 37#define MAX(a,b) ((a)>(b) ? (a) : (b))
34#undef MIN 38#undef MIN
35#define MIN(a,b) ((a)<(b) ? (a) : (b)) 39#define MIN(a,b) ((a)<(b) ? (a) : (b))
36 40
37/* ------------------------------------------------------------------------- */ 41/* ------------------------------------------------------------------------- */
38 42
39#define MAX_LINES 50 43#define MAX_LINES 50
40 44
41int GetLine(FILE *File, char *Line, int count); 45int GetLine(FILE *File, char *Line, int count);
42 46
43typedef struct { 47typedef struct {
44 int numbers[MAX_LINES*2]; 48 int numbers[MAX_LINES*2];
45} GSM_Lines; 49} GSM_Lines;
46 50
47void SplitLines(unsigned char *message, int messagesize, GSM_Lines *lines, unsigned char *whitespaces, int spaceslen, bool eot); 51void SplitLines(unsigned char *message, int messagesize, GSM_Lines *lines, unsigned char *whitespaces, int spaceslen, bool eot);
48char *GetLineString(unsigned char *message, GSM_Lines lines, int start); 52char *GetLineString(unsigned char *message, GSM_Lines lines, int start);
49void CopyLineString(unsigned char *dest, unsigned char *src, GSM_Lines lines, int start); 53void CopyLineString(unsigned char *dest, unsigned char *src, GSM_Lines lines, int start);
50 54
51/* ------------------------------------------------------------------------- */ 55/* ------------------------------------------------------------------------- */
52 56
53typedef enum { 57typedef enum {
54 DL_BINARY = 1, /* Binary transmission dump */ 58 DL_BINARY = 1, /* Binary transmission dump */
55 DL_TEXT, /* Text transmission dump*/ 59 DL_TEXT, /* Text transmission dump*/
56 DL_TEXTALL, /* Everything */ 60 DL_TEXTALL, /* Everything */
57 DL_TEXTERROR, /* Only errors */ 61 DL_TEXTERROR, /* Only errors */
58 DL_TEXTDATE, /* Text transmission dump*/ 62 DL_TEXTDATE, /* Text transmission dump*/
59 DL_TEXTALLDATE, /* Everything */ 63 DL_TEXTALLDATE, /* Everything */
60 DL_TEXTERRORDATE /* Only errors */ 64 DL_TEXTERRORDATE /* Only errors */
61} Debug_Level; 65} Debug_Level;
62 66
63typedef struct { 67typedef struct {
64 Debug_Leveldl; 68 Debug_Leveldl;
65 FILE *df; 69 FILE *df;
66 bool use_global; 70 bool use_global;
67 char *coding; 71 char *coding;
68} Debug_Info; 72} Debug_Info;
69 73
70 extern Debug_Infodi; 74 extern Debug_Infodi;
71 75
72#ifdef DEBUG 76#ifdef DEBUG
73#ifdef __GNUC__ 77#ifdef __GNUC__
74__attribute__((format(printf, 1, 2))) 78__attribute__((format(printf, 1, 2)))
75#endif 79#endif
76int dbgprintf(const char *format, ...); 80int dbgprintf(const char *format, ...);
77#else 81#else
78# ifndef WIN32 82# ifndef WIN32
79# define dbgprintf(a...) do { } while (0) 83# define dbgprintf(a...) do { } while (0)
80# else 84# else
81# define dbgprintf 85# define dbgprintf
82# endif 86# endif
83#endif 87#endif
84 88
85#ifdef __GNUC__ 89#ifdef __GNUC__
86__attribute__((format(printf, 3, 4))) 90__attribute__((format(printf, 3, 4)))
87#endif 91#endif
88int smfprintf(FILE *f, Debug_Level dl, const char *format, ...); 92int smfprintf(FILE *f, Debug_Level dl, const char *format, ...);
89 93
90void DumpMessage(FILE *df, Debug_Level dl, const unsigned char *message, int messagesize); 94void DumpMessage(FILE *df, Debug_Level dl, const unsigned char *message, int messagesize);
91 95
92bool GSM_SetDebugLevel(char *info, Debug_Info *di); 96bool GSM_SetDebugLevel(char *info, Debug_Info *di);
93 97
94/* ------------------------------------------------------------------------- */ 98/* ------------------------------------------------------------------------- */
95 99
96/** 100/**
97 * Structure used for saving date and time 101 * Structure used for saving date and time
98 */ 102 */
99typedef struct { 103typedef struct {
100 /** 104 /**
101 * The difference between local time and GMT in hours 105 * The difference between local time and GMT in hours
102 */ 106 */
103 int Timezone; 107 int Timezone;
104 108
105 unsigned int Second; 109 unsigned int Second;
106 unsigned int Minute; 110 unsigned int Minute;
107 unsigned int Hour; 111 unsigned int Hour;
108 112
109 unsigned int Day; 113 unsigned int Day;
110 /** 114 /**
111 * January = 1, February = 2, etc. 115 * January = 1, February = 2, etc.
112 */ 116 */
113 unsigned int Month; 117 unsigned int Month;
114 /** 118 /**
115 * Complete year number. Not 03, but 2003 119 * Complete year number. Not 03, but 2003
116 */ 120 */
117 unsigned int Year; 121 unsigned int Year;
118} GSM_DateTime; 122} GSM_DateTime;
119 123
120 void GSM_GetCurrentDateTime (GSM_DateTime *Date); 124 void GSM_GetCurrentDateTime (GSM_DateTime *Date);
121 char *OSDateTime (GSM_DateTime dt, bool TimeZone); 125 char *OSDateTime (GSM_DateTime dt, bool TimeZone);
122 char *OSDate (GSM_DateTime dt); 126 char *OSDate (GSM_DateTime dt);
123 char *DayOfWeek (int year, int month, int day); 127 char *DayOfWeek (int year, int month, int day);
124 time_t Fill_Time_T (GSM_DateTime DT, int TZ); 128 time_t Fill_Time_T (GSM_DateTime DT, int TZ);
125 void GetTimeDifference (unsigned long diff, GSM_DateTime *DT, bool Plus, int multi); 129 void GetTimeDifference (unsigned long diff, GSM_DateTime *DT, bool Plus, int multi);
126 void Fill_GSM_DateTime (GSM_DateTime *Date, time_t timet); 130 void Fill_GSM_DateTime (GSM_DateTime *Date, time_t timet);
127 bool CheckDate (GSM_DateTime *date); 131 bool CheckDate (GSM_DateTime *date);
128 bool CheckTime (GSM_DateTime *date); 132 bool CheckTime (GSM_DateTime *date);
129 133
130 char *GetCompiler(void); 134 char *GetCompiler(void);
131 char *GetOS(void); 135 char *GetOS(void);
132 136
137#if defined(_MSC_VER) && defined(__cplusplus)
138 }
139#endif
140
133#endif 141#endif
134 142
135/* How should editor hadle tabs in this file? Add editor commands here. 143/* How should editor hadle tabs in this file? Add editor commands here.
136 * vim: noexpandtab sw=8 ts=8 sts=8: 144 * vim: noexpandtab sw=8 ts=8 sts=8:
137 */ 145 */
diff --git a/gammu/emb/common/phone/alcatel/alcatel.c b/gammu/emb/common/phone/alcatel/alcatel.c
index f004ad4..3821f13 100644
--- a/gammu/emb/common/phone/alcatel/alcatel.c
+++ b/gammu/emb/common/phone/alcatel/alcatel.c
@@ -1,2534 +1,2537 @@
1/* (c) 2002-2004 by Michal Cihar */ 1/* (c) 2002-2004 by Michal Cihar */
2 2
3/* 3/*
4 * High level functions for communication with Alcatel One Touch 501 and 4 * High level functions for communication with Alcatel One Touch 501 and
5 * compatible mobile phone. 5 * compatible mobile phone.
6 * 6 *
7 * This code implements functions to communicate with Alcatel phones, 7 * This code implements functions to communicate with Alcatel phones,
8 * currently seem to work: 8 * currently seem to work:
9 * - BE5 series (501/701) 9 * - BE5 series (501/701)
10 * - BF5 series (715) 10 * - BF5 series (715)
11 * - BH4 series (535/735) 11 * - BH4 series (535/735)
12 * For some functions it uses normal AT mode (not implemented here, look at 12 * For some functions it uses normal AT mode (not implemented here, look at
13 * ../at/atgen.[ch]) for others it switches into binary mode and initialises 13 * ../at/atgen.[ch]) for others it switches into binary mode and initialises
14 * underlaying protocol (see ../../protocol/alcatel/alcabus.[ch]) and 14 * underlaying protocol (see ../../protocol/alcatel/alcabus.[ch]) and
15 * communicates over it. Don't ask me why Alcatel uses such silly thing... 15 * communicates over it. Don't ask me why Alcatel uses such silly thing...
16 * 16 *
17 * Notes for future features: 17 * Notes for future features:
18 * - max phone number length is 61 (BE5) 18 * - max phone number length is 61 (BE5)
19 * - max name length is 50 (BE5) 19 * - max name length is 50 (BE5)
20 */ 20 */
21 21
22#include "../../gsmstate.h" 22#include "../../gsmstate.h"
23 23
24#ifdef GSM_ENABLE_ALCATEL 24#ifdef GSM_ENABLE_ALCATEL
25#ifdef GSM_ENABLE_ATGEN 25#ifdef GSM_ENABLE_ATGEN
26 26
27#include <string.h> 27#include <string.h>
28#include <time.h> 28#include <time.h>
29 29
30#include "../../gsmcomon.h" 30#include "../../gsmcomon.h"
31#include "../../misc/coding/coding.h" 31#include "../../misc/coding/coding.h"
32#include "../../misc/misc.h" 32#include "../../misc/misc.h"
33#include "../../service/sms/gsmsms.h" 33#include "../../service/sms/gsmsms.h"
34#include "../pfunc.h" 34#include "../pfunc.h"
35#include "alcatel.h" 35#include "alcatel.h"
36 36
37/* Timeout for GSM_WaitFor calls. */ 37/* Timeout for GSM_WaitFor calls. */
38 #define ALCATEL_TIMEOUT 64 38 #define ALCATEL_TIMEOUT 64
39 39
40/* Some magic numbers for protocol follow */ 40/* Some magic numbers for protocol follow */
41 41
42/* synchronisation types (for everything except begin transfer): */ 42/* synchronisation types (for everything except begin transfer): */
43 #define ALCATEL_SYNC_TYPE_CALENDAR0x64 43 #define ALCATEL_SYNC_TYPE_CALENDAR0x64
44 #define ALCATEL_SYNC_TYPE_TODO 0x68 44 #define ALCATEL_SYNC_TYPE_TODO 0x68
45 #define ALCATEL_SYNC_TYPE_CONTACTS0x6C 45 #define ALCATEL_SYNC_TYPE_CONTACTS0x6C
46 46
47/* synchronisation types (for begin transfer): */ 47/* synchronisation types (for begin transfer): */
48 #define ALCATEL_BEGIN_SYNC_CALENDAR0x00 48 #define ALCATEL_BEGIN_SYNC_CALENDAR0x00
49 #define ALCATEL_BEGIN_SYNC_TODO 0x02 49 #define ALCATEL_BEGIN_SYNC_TODO 0x02
50 #define ALCATEL_BEGIN_SYNC_CONTACTS0x01 50 #define ALCATEL_BEGIN_SYNC_CONTACTS0x01
51 51
52/* category types */ 52/* category types */
53 #define ALCATEL_LIST_TODO_CAT 0x9B 53 #define ALCATEL_LIST_TODO_CAT 0x9B
54 #define ALCATEL_LIST_CONTACTS_CAT0x96 54 #define ALCATEL_LIST_CONTACTS_CAT0x96
55 55
56 56
57/* We need lot of ATGEN functions, because Alcatel is an AT device. */ 57/* We need lot of ATGEN functions, because Alcatel is an AT device. */
58 58
59extern GSM_Reply_Function ALCATELReplyFunctions[]; 59extern GSM_Reply_Function ALCATELReplyFunctions[];
60extern GSM_Reply_Function ATGENReplyFunctions[]; 60extern GSM_Reply_Function ATGENReplyFunctions[];
61 61
62 extern GSM_Error ATGEN_Initialise (GSM_StateMachine *s); 62 extern GSM_Error ATGEN_Initialise (GSM_StateMachine *s);
63 extern GSM_Error ATGEN_Terminate (GSM_StateMachine *s); 63 extern GSM_Error ATGEN_Terminate (GSM_StateMachine *s);
64 extern GSM_Error ATGEN_GetIMEI (GSM_StateMachine *s); 64 extern GSM_Error ATGEN_GetIMEI (GSM_StateMachine *s);
65 extern GSM_Error ATGEN_GetFirmware (GSM_StateMachine *s); 65 extern GSM_Error ATGEN_GetFirmware (GSM_StateMachine *s);
66 extern GSM_Error ATGEN_GetModel (GSM_StateMachine *s); 66 extern GSM_Error ATGEN_GetModel (GSM_StateMachine *s);
67 extern GSM_Error ATGEN_GetDateTime (GSM_StateMachine *s, GSM_DateTime *date_time); 67 extern GSM_Error ATGEN_GetDateTime (GSM_StateMachine *s, GSM_DateTime *date_time);
68 extern GSM_Error ATGEN_GetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry); 68 extern GSM_Error ATGEN_GetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry);
69 extern GSM_Error ATGEN_GetNextMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry, bool start); 69 extern GSM_Error ATGEN_GetNextMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry, bool start);
70 extern GSM_Error ATGEN_SetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry); 70 extern GSM_Error ATGEN_SetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry);
71 extern GSM_Error ATGEN_AddMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry); 71 extern GSM_Error ATGEN_AddMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry);
72 extern GSM_Error ATGEN_DeleteMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry); 72 extern GSM_Error ATGEN_DeleteMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry);
73 extern GSM_Error ATGEN_GetMemoryStatus (GSM_StateMachine *s, GSM_MemoryStatus *Status); 73 extern GSM_Error ATGEN_GetMemoryStatus (GSM_StateMachine *s, GSM_MemoryStatus *Status);
74 extern GSM_Error ATGEN_GetSMSC (GSM_StateMachine *s, GSM_SMSC *smsc); 74 extern GSM_Error ATGEN_GetSMSC (GSM_StateMachine *s, GSM_SMSC *smsc);
75 extern GSM_Error ATGEN_SetSMSC (GSM_StateMachine *s, GSM_SMSC *smsc); 75 extern GSM_Error ATGEN_SetSMSC (GSM_StateMachine *s, GSM_SMSC *smsc);
76 extern GSM_Error ATGEN_GetSMSFolders (GSM_StateMachine *s, GSM_SMSFolders *folders); 76 extern GSM_Error ATGEN_GetSMSFolders (GSM_StateMachine *s, GSM_SMSFolders *folders);
77 extern GSM_Error ATGEN_GetSMSStatus (GSM_StateMachine *s, GSM_SMSMemoryStatus *status); 77 extern GSM_Error ATGEN_GetSMSStatus (GSM_StateMachine *s, GSM_SMSMemoryStatus *status);
78 extern GSM_Error ATGEN_GetSMS (GSM_StateMachine *s, GSM_MultiSMSMessage *sms); 78 extern GSM_Error ATGEN_GetSMS (GSM_StateMachine *s, GSM_MultiSMSMessage *sms);
79 extern GSM_Error ATGEN_GetNextSMS (GSM_StateMachine *s, GSM_MultiSMSMessage *sms, bool start); 79 extern GSM_Error ATGEN_GetNextSMS (GSM_StateMachine *s, GSM_MultiSMSMessage *sms, bool start);
80 extern GSM_Error ATGEN_SendSavedSMS (GSM_StateMachine *s, int Folder, int Location); 80 extern GSM_Error ATGEN_SendSavedSMS (GSM_StateMachine *s, int Folder, int Location);
81 extern GSM_Error ATGEN_SendSMS (GSM_StateMachine *s, GSM_SMSMessage *sms); 81 extern GSM_Error ATGEN_SendSMS (GSM_StateMachine *s, GSM_SMSMessage *sms);
82 extern GSM_Error ATGEN_DeleteSMS (GSM_StateMachine *s, GSM_SMSMessage *sms); 82 extern GSM_Error ATGEN_DeleteSMS (GSM_StateMachine *s, GSM_SMSMessage *sms);
83 extern GSM_Error ATGEN_AddSMS (GSM_StateMachine *s, GSM_SMSMessage *sms); 83 extern GSM_Error ATGEN_AddSMS (GSM_StateMachine *s, GSM_SMSMessage *sms);
84 extern GSM_Error ATGEN_GetBatteryCharge (GSM_StateMachine *s, GSM_BatteryCharge *bat); 84 extern GSM_Error ATGEN_GetBatteryCharge (GSM_StateMachine *s, GSM_BatteryCharge *bat);
85 extern GSM_Error ATGEN_GetSignalQuality (GSM_StateMachine *s, GSM_SignalQuality *sig); 85 extern GSM_Error ATGEN_GetSignalQuality (GSM_StateMachine *s, GSM_SignalQuality *sig);
86 extern GSM_Error ATGEN_DialVoice (GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber); 86 extern GSM_Error ATGEN_DialVoice (GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber);
87 extern GSM_Error ATGEN_AnswerCall (GSM_StateMachine *s, int ID, bool all); 87 extern GSM_Error ATGEN_AnswerCall (GSM_StateMachine *s, int ID, bool all);
88 extern GSM_Error ATGEN_CancelCall (GSM_StateMachine *s, int ID, bool all); 88 extern GSM_Error ATGEN_CancelCall (GSM_StateMachine *s, int ID, bool all);
89 extern GSM_Error ATGEN_SetDateTime (GSM_StateMachine *s, GSM_DateTime *date_time); 89 extern GSM_Error ATGEN_SetDateTime (GSM_StateMachine *s, GSM_DateTime *date_time);
90 extern GSM_Error ATGEN_EnterSecurityCode(GSM_StateMachine *s, GSM_SecurityCode Code); 90 extern GSM_Error ATGEN_EnterSecurityCode(GSM_StateMachine *s, GSM_SecurityCode Code);
91 extern GSM_Error ATGEN_GetSecurityStatus(GSM_StateMachine *s, GSM_SecurityCodeType *Status); 91 extern GSM_Error ATGEN_GetSecurityStatus(GSM_StateMachine *s, GSM_SecurityCodeType *Status);
92 extern GSM_Error ATGEN_ResetPhoneSettings(GSM_StateMachine *s, GSM_ResetSettingsType Type); 92 extern GSM_Error ATGEN_ResetPhoneSettings(GSM_StateMachine *s, GSM_ResetSettingsType Type);
93 extern GSM_Error ATGEN_SendDTMF (GSM_StateMachine *s, char *sequence); 93 extern GSM_Error ATGEN_SendDTMF (GSM_StateMachine *s, char *sequence);
94 extern GSM_Error ATGEN_GetSIMIMSI (GSM_StateMachine *s, char *IMSI); 94 extern GSM_Error ATGEN_GetSIMIMSI (GSM_StateMachine *s, char *IMSI);
95 extern GSM_Error ATGEN_HandleCMSError (GSM_StateMachine *s); 95 extern GSM_Error ATGEN_HandleCMSError (GSM_StateMachine *s);
96 extern GSM_Error ATGEN_GetNetworkInfo (GSM_StateMachine *s, GSM_NetworkInfo *netinfo); 96 extern GSM_Error ATGEN_GetNetworkInfo (GSM_StateMachine *s, GSM_NetworkInfo *netinfo);
97 extern GSM_Error ATGEN_Reset (GSM_StateMachine *s, bool hard); 97 extern GSM_Error ATGEN_Reset (GSM_StateMachine *s, bool hard);
98 extern GSM_Error ATGEN_PressKey (GSM_StateMachine *s, GSM_KeyCode Key, bool Press); 98 extern GSM_Error ATGEN_PressKey (GSM_StateMachine *s, GSM_KeyCode Key, bool Press);
99 extern GSM_Error ATGEN_GetDisplayStatus (GSM_StateMachine *s, GSM_DisplayFeatures *features); 99 extern GSM_Error ATGEN_GetDisplayStatus (GSM_StateMachine *s, GSM_DisplayFeatures *features);
100 extern GSM_Error ATGEN_SetAutoNetworkLogin(GSM_StateMachine *s); 100 extern GSM_Error ATGEN_SetAutoNetworkLogin(GSM_StateMachine *s);
101 extern GSM_Error ATGEN_DeleteAllMemory (GSM_StateMachine *s, GSM_MemoryType type); 101 extern GSM_Error ATGEN_DeleteAllMemory (GSM_StateMachine *s, GSM_MemoryType type);
102 102
103 extern GSM_Error ATGEN_DispatchMessage (GSM_StateMachine *s); 103 extern GSM_Error ATGEN_DispatchMessage (GSM_StateMachine *s);
104 extern GSM_Error ATGEN_SetFastSMSSending(GSM_StateMachine *s, bool enable);
104 extern GSM_Error ATGEN_SetIncomingCB (GSM_StateMachine *s, bool enable); 105 extern GSM_Error ATGEN_SetIncomingCB (GSM_StateMachine *s, bool enable);
105 extern GSM_Error ATGEN_SetIncomingSMS (GSM_StateMachine *s, bool enable); 106 extern GSM_Error ATGEN_SetIncomingSMS (GSM_StateMachine *s, bool enable);
106 107
107/** 108/**
108 * Alcatel uses some 8-bit characters in contacts, calendar etc.. This table 109 * Alcatel uses some 8-bit characters in contacts, calendar etc.. This table
109 * attempts to decode it, it is probably not complete, here are just chars 110 * attempts to decode it, it is probably not complete, here are just chars
110 * that I found... 111 * that I found...
111 */ 112 */
112unsigned char GSM_AlcatelAlphabet[] = 113unsigned char GSM_AlcatelAlphabet[] =
113{ 114{
114 /* in phone unicode description*/ 115 /* in phone unicode description*/
115 0x80, 0x00,0x20, /* empty */ 116 0x80, 0x00,0x20, /* empty */
116 0x81, 0x00,0x20, /* empty*/ 117 0x81, 0x00,0x20, /* empty*/
117 0x82, 0x00,0x20, /* empty*/ 118 0x82, 0x00,0x20, /* empty*/
118 0x83, 0x00,0x20, /* empty*/ 119 0x83, 0x00,0x20, /* empty*/
119 120
120 0x84, 0x00,0xe7, /* c cedilla*/ 121 0x84, 0x00,0xe7, /* c cedilla*/
121 0x85, 0x20,0x26, /* ... */ 122 0x85, 0x20,0x26, /* ... */
122 0x86, 0x03,0xc0, /* pi */ 123 0x86, 0x03,0xc0, /* pi */
123 0x87, 0x01,0x3e, /* l caron*/ 124 0x87, 0x01,0x3e, /* l caron*/
124 0x88, 0x00,0xc0, /* A grave*/ 125 0x88, 0x00,0xc0, /* A grave*/
125 0x89, 0x00,0xc1, /* A acute*/ 126 0x89, 0x00,0xc1, /* A acute*/
126 0x8a, 0x00,0xc2, /* A circumflex*/ 127 0x8a, 0x00,0xc2, /* A circumflex*/
127 0x8b, 0x00,0xc3, /* A tilde*/ 128 0x8b, 0x00,0xc3, /* A tilde*/
128 0x8c, 0x00,0xc8, /* E grave*/ 129 0x8c, 0x00,0xc8, /* E grave*/
129 0x8d, 0x00,0xca, /* E circumflex*/ 130 0x8d, 0x00,0xca, /* E circumflex*/
130 0x8e, 0x00,0xcb, /* E diaresis*/ 131 0x8e, 0x00,0xcb, /* E diaresis*/
131 0x8f, 0x00,0xcc, /* I grave*/ 132 0x8f, 0x00,0xcc, /* I grave*/
132 0x90, 0x00,0xcd, /* I acute*/ 133 0x90, 0x00,0xcd, /* I acute*/
133 0x91, 0x00,0xd0, /* ETH */ 134 0x91, 0x00,0xd0, /* ETH */
134 0x92, 0x00,0xd2, /* O grave*/ 135 0x92, 0x00,0xd2, /* O grave*/
135 0x93, 0x00,0xd3, /* O acute*/ 136 0x93, 0x00,0xd3, /* O acute*/
136 0x94, 0x00,0xd4, /* O circumflex*/ 137 0x94, 0x00,0xd4, /* O circumflex*/
137 0x95, 0x00,0xd5, /* O tilde*/ 138 0x95, 0x00,0xd5, /* O tilde*/
138 0x96, 0x00,0xd9, /* U grave*/ 139 0x96, 0x00,0xd9, /* U grave*/
139 0x97, 0x00,0xda, /* U acute*/ 140 0x97, 0x00,0xda, /* U acute*/
140 0x98, 0x00,0xe1, /* a acute*/ 141 0x98, 0x00,0xe1, /* a acute*/
141 0x99, 0x00,0xe2, /* a circumflex*/ 142 0x99, 0x00,0xe2, /* a circumflex*/
142 0x9a, 0x00,0xe3, /* a tilde*/ 143 0x9a, 0x00,0xe3, /* a tilde*/
143 0x9b, 0x00,0xea, /* e circumflex*/ 144 0x9b, 0x00,0xea, /* e circumflex*/
144 0x9c, 0x00,0xeb, /* e diaresis*/ 145 0x9c, 0x00,0xeb, /* e diaresis*/
145 0x9d, 0x00,0xed, /* i acute*/ 146 0x9d, 0x00,0xed, /* i acute*/
146 0x9e, 0x00,0xee, /* i circumflex*/ 147 0x9e, 0x00,0xee, /* i circumflex*/
147 0x9f, 0x00,0xef, /* i diaresis*/ 148 0x9f, 0x00,0xef, /* i diaresis*/
148 0xa0, 0x00,0xf3, /* o acute*/ 149 0xa0, 0x00,0xf3, /* o acute*/
149 0xa1, 0x00,0xf4, /* o circumflex*/ 150 0xa1, 0x00,0xf4, /* o circumflex*/
150 0xa2, 0x00,0xf5, /* o tilde*/ 151 0xa2, 0x00,0xf5, /* o tilde*/
151 0xa3, 0x00,0xfa, /* u acute*/ 152 0xa3, 0x00,0xfa, /* u acute*/
152 0xa4, 0x00,0xa2, /* cent */ 153 0xa4, 0x00,0xa2, /* cent */
153 0xa5, 0x00,0x5b, /* [ */ 154 0xa5, 0x00,0x5b, /* [ */
154 0xa6, 0x01,0x59, /* r caron*/ 155 0xa6, 0x01,0x59, /* r caron*/
155 0xa7, 0x01,0x0d, /* c caron*/ 156 0xa7, 0x01,0x0d, /* c caron*/
156 0xa8, 0x01,0x61, /* s caron*/ 157 0xa8, 0x01,0x61, /* s caron*/
157 0xa9, 0x01,0x1b, /* e caron*/ 158 0xa9, 0x01,0x1b, /* e caron*/
158 0xaa, 0x01,0x6f, /* u ring*/ 159 0xaa, 0x01,0x6f, /* u ring*/
159 0xab, 0x00,0xfd, /* y acute*/ 160 0xab, 0x00,0xfd, /* y acute*/
160 0xac, 0x00,0xf0, /* eth */ 161 0xac, 0x00,0xf0, /* eth */
161 0xad, 0x01,0x07, /* c acute*/ 162 0xad, 0x01,0x07, /* c acute*/
162 0xae, 0x01,0x19, /* e ogonek*/ 163 0xae, 0x01,0x19, /* e ogonek*/
163 0xaf, 0x01,0x05, /* a ogonek*/ 164 0xaf, 0x01,0x05, /* a ogonek*/
164 0xb0, 0x01,0x7c, /* z dot*/ 165 0xb0, 0x01,0x7c, /* z dot*/
165 0xb1, 0x01,0x7a, /* z acute*/ 166 0xb1, 0x01,0x7a, /* z acute*/
166 0xb2, 0x01,0x5b, /* s acute*/ 167 0xb2, 0x01,0x5b, /* s acute*/
167 0xb3, 0x01,0x44, /* n acute*/ 168 0xb3, 0x01,0x44, /* n acute*/
168 0xb4, 0x01,0x42, /* l stroke*/ 169 0xb4, 0x01,0x42, /* l stroke*/
169 170
170 0xb5, 0x00,0x20, /* empty*/ 171 0xb5, 0x00,0x20, /* empty*/
171 172
172 0xb6, 0x01,0x48, /* n caron*/ 173 0xb6, 0x01,0x48, /* n caron*/
173 0xb7, 0x01,0x65, /* t caron*/ 174 0xb7, 0x01,0x65, /* t caron*/
174 175
175 0xb8, 0x00,0x20, /* empty*/ 176 0xb8, 0x00,0x20, /* empty*/
176 177
177 0xb9, 0x01,0x7e, /* z caron*/ 178 0xb9, 0x01,0x7e, /* z caron*/
178 0xba, 0x01,0xe7, /* g caron*/ 179 0xba, 0x01,0xe7, /* g caron*/
179 180
180 0xbb, 0x00,0x20, /* empty*/ 181 0xbb, 0x00,0x20, /* empty*/
181 0xbc, 0x00,0x20, /* empty*/ 182 0xbc, 0x00,0x20, /* empty*/
182 183
183 0xbd, 0x1e,0x20, /* G macron*/ 184 0xbd, 0x1e,0x20, /* G macron*/
184 0xbe, 0x1e,0x21, /* g macron*/ 185 0xbe, 0x1e,0x21, /* g macron*/
185 0xbf, 0x01,0x5e, /* S cedilla*/ 186 0xbf, 0x01,0x5e, /* S cedilla*/
186 0xc0, 0x01,0x5f, /* s cedilla*/ 187 0xc0, 0x01,0x5f, /* s cedilla*/
187 0xc1, 0x01,0x2f, /* i ogonek*/ /* FIXME: not sure with this, it look like normal i */ 188 0xc1, 0x01,0x2f, /* i ogonek*/ /* FIXME: not sure with this, it look like normal i */
188 0xc2, 0x01,0x31, /* i dotless*/ 189 0xc2, 0x01,0x31, /* i dotless*/
189 0xc3, 0x01,0x68, /* U tilde*/ 190 0xc3, 0x01,0x68, /* U tilde*/
190 0xc4, 0x01,0x50, /* O dbl acute*/ 191 0xc4, 0x01,0x50, /* O dbl acute*/
191 0xc5, 0x01,0x69, /* u tilde*/ 192 0xc5, 0x01,0x69, /* u tilde*/
192 0xc6, 0x01,0x51, /* o dbl acute*/ 193 0xc6, 0x01,0x51, /* o dbl acute*/
193 0xc7, 0x27,0xa9, /* => */ 194 0xc7, 0x27,0xa9, /* => */
194 0xc8, 0x27,0xa8, /* filled =>*/ 195 0xc8, 0x27,0xa8, /* filled =>*/
195 0xc9, 0x00,0xd7, /* x */ 196 0xc9, 0x00,0xd7, /* x */
196 0xca, 0x00,0x5d, /* ] */ 197 0xca, 0x00,0x5d, /* ] */
197 0xcb, 0x26,0x0f, /* phone*/ 198 0xcb, 0x26,0x0f, /* phone*/
198 0xcc, 0x01,0x0f, /* d caron*/ 199 0xcc, 0x01,0x0f, /* d caron*/
199 200
200 0xcd, 0x00,0x20, /* empty*/ 201 0xcd, 0x00,0x20, /* empty*/
201 202
202 0xce, 0x00,0x7e, /* ~ */ 203 0xce, 0x00,0x7e, /* ~ */
203 0xcf, 0x00,0x5c, /* \ */ 204 0xcf, 0x00,0x5c, /* \ */
204 0xd0, 0x00,0x5e, /* ^ */ 205 0xd0, 0x00,0x5e, /* ^ */
205 206
206 0xd1, 0x00,0x20, /* empty*/ 207 0xd1, 0x00,0x20, /* empty*/
207 208
208 0xd2, 0x00,0x7b, /* { */ 209 0xd2, 0x00,0x7b, /* { */
209 0xd3, 0x00,0x7c, /* | */ 210 0xd3, 0x00,0x7c, /* | */
210 0xd4, 0x00,0x7d, /* } */ 211 0xd4, 0x00,0x7d, /* } */
211 212
212 0xd5, 0x00,0x20, /* empty*/ 213 0xd5, 0x00,0x20, /* empty*/
213 214
214 0xd6, 0x01,0x63, /* t cedilla*/ 215 0xd6, 0x01,0x63, /* t cedilla*/
215 216
216 0xd7, 0x00,0x20, /* empty*/ 217 0xd7, 0x00,0x20, /* empty*/
217 0xd8, 0x00,0x20, /* empty*/ 218 0xd8, 0x00,0x20, /* empty*/
218 0xd9, 0x00,0x20, /* empty*/ 219 0xd9, 0x00,0x20, /* empty*/
219 0xda, 0x00,0x20, /* empty*/ 220 0xda, 0x00,0x20, /* empty*/
220 0xdb, 0x00,0x20, /* empty*/ 221 0xdb, 0x00,0x20, /* empty*/
221 0xdc, 0x00,0x20, /* empty*/ 222 0xdc, 0x00,0x20, /* empty*/
222 0xdd, 0x00,0x20, /* empty*/ 223 0xdd, 0x00,0x20, /* empty*/
223 0xde, 0x00,0x20, /* empty*/ 224 0xde, 0x00,0x20, /* empty*/
224 0xdf, 0x00,0x20, /* empty*/ 225 0xdf, 0x00,0x20, /* empty*/
225 0xe0, 0x00,0x20, /* empty*/ 226 0xe0, 0x00,0x20, /* empty*/
226 227
227 0xe1, 0x00,0x20, /* two candles*/ /* FIXME */ 228 0xe1, 0x00,0x20, /* two candles*/ /* FIXME */
228 229
229 0xe2, 0x00,0x20, /* empty*/ 230 0xe2, 0x00,0x20, /* empty*/
230 0xe3, 0x00,0x20, /* empty*/ 231 0xe3, 0x00,0x20, /* empty*/
231 0xe4, 0x00,0x20, /* empty*/ 232 0xe4, 0x00,0x20, /* empty*/
232 233
233 0xe5, 0x01,0xce, /* a caron*/ 234 0xe5, 0x01,0xce, /* a caron*/
234 0xe6, 0x01,0x01, /* a macron*/ 235 0xe6, 0x01,0x01, /* a macron*/
235 0xe7, 0x01,0x13, /* e macron*/ 236 0xe7, 0x01,0x13, /* e macron*/
236 0xe8, 0x01,0x2b, /* i macron*/ 237 0xe8, 0x01,0x2b, /* i macron*/
237 0xe9, 0x01,0x4d, /* o macron*/ 238 0xe9, 0x01,0x4d, /* o macron*/
238 0xea, 0x01,0x6b, /* u macron*/ 239 0xea, 0x01,0x6b, /* u macron*/
239 0xeb, 0x00,0x41, /* A */ 240 0xeb, 0x00,0x41, /* A */
240 0xec, 0x00,0x40, /* @ */ 241 0xec, 0x00,0x40, /* @ */
241 0xed, 0x00,0x20,/* some strange char :-) */ /* FIXME */ 242 0xed, 0x00,0x20,/* some strange char :-) */ /* FIXME */
242 243
243 0xee, 0x00,0x20, /* big key stroken*/ /* FIXME */ 244 0xee, 0x00,0x20, /* big key stroken*/ /* FIXME */
244 0xef, 0x00,0x20, /* big key*/ /* FIXME */ 245 0xef, 0x00,0x20, /* big key*/ /* FIXME */
245 246
246 0xf0, 0x00,0x20, /* empty*/ 247 0xf0, 0x00,0x20, /* empty*/
247 248
248 0xf1, 0x00,0x31, /* 1 */ 249 0xf1, 0x00,0x31, /* 1 */
249 0xf2, 0x00,0x21, /* bold !*/ 250 0xf2, 0x00,0x21, /* bold !*/
250 0xf3, 0x26,0x0e, /* black phone*/ 251 0xf3, 0x26,0x0e, /* black phone*/
251 0xf4, 0x00,0x26, /* & */ 252 0xf4, 0x00,0x26, /* & */
252 0xf5, 0x23,0x7e, /* bell */ 253 0xf5, 0x23,0x7e, /* bell */
253 0xf6, 0x26,0x6a, /* note */ 254 0xf6, 0x26,0x6a, /* note */
254 255
255 0xf7, 0x27,0x13, /* okay inv*/ /* FIXME */ 256 0xf7, 0x27,0x13, /* okay inv*/ /* FIXME */
256 0xf8, 0x27,0x13, /* okay */ 257 0xf8, 0x27,0x13, /* okay */
257 258
258 0xf9, 0x00,0x20, /* empty*/ 259 0xf9, 0x00,0x20, /* empty*/
259 260
260 0xfa, 0x00,0x20, /* key */ /* FIXME */ 261 0xfa, 0x00,0x20, /* key */ /* FIXME */
261 262
262 0xfb, 0x00,0x20, /* empty*/ 263 0xfb, 0x00,0x20, /* empty*/
263 264
264 0xfc, 0x20,0xac, /* Euro */ 265 0xfc, 0x20,0xac, /* Euro */
265 0xfd, 0x21,0x97, /* NE arrow*/ 266 0xfd, 0x21,0x97, /* NE arrow*/
266 0xfe, 0x21,0x98, /* SE arrow*/ 267 0xfe, 0x21,0x98, /* SE arrow*/
267 268
268 0xff, 0x00,0x20, /* empty*/ 269 0xff, 0x00,0x20, /* empty*/
269 270
270 0x00, 0x00,0x00 271 0x00, 0x00,0x00
271}; 272};
272 273
273/* This is being called from atgen */ 274/* This is being called from atgen */
274 GSM_Error ALCATEL_ProtocolVersionReply(GSM_Protocol_Message msg, GSM_StateMachine *s) 275 GSM_Error ALCATEL_ProtocolVersionReply(GSM_Protocol_Message msg, GSM_StateMachine *s)
275{ 276{
276 char *str, *str2; 277 char *str, *str2;
277/* 278/*
278 * Reply received here looks like: 279 * Reply received here looks like:
279 * 1 "AT+CPROT=?" 280 * 1 "AT+CPROT=?"
280 * 2 "+CPROT: 0,"V1.0",1" 281 * 2 "+CPROT: 0,"V1.0",1"
281 * 3 "+CPROT: 16,"V1.1",16" 282 * 3 "+CPROT: 16,"V1.1",16"
282 * 4 "OK" 283 * 4 "OK"
283 */ 284 */
284 switch (s->Phone.Data.Priv.ATGEN.ReplyState) { 285 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
285 case AT_Reply_OK: 286 case AT_Reply_OK:
286 str = strstr(msg.Buffer, "\"V"); 287 str = strstr(msg.Buffer, "\"V");
287 if (str == NULL) return ERR_UNKNOWNRESPONSE; 288 if (str == NULL) return ERR_UNKNOWNRESPONSE;
288 str += 2; 289 str += 2;
289 while((str2 = strstr(str, "\"V")) != NULL) str = str2 + 2; 290 while((str2 = strstr(str, "\"V")) != NULL) str = str2 + 2;
290 if (strncmp(str, "1.0", 3) == 0) { 291 if (strncmp(str, "1.0", 3) == 0) {
291 s->Phone.Data.Priv.ALCATEL.ProtocolVersion = V_1_0; 292 s->Phone.Data.Priv.ALCATEL.ProtocolVersion = V_1_0;
292 } else if (strncmp(str, "1.1", 3) == 0) { 293 } else if (strncmp(str, "1.1", 3) == 0) {
293 s->Phone.Data.Priv.ALCATEL.ProtocolVersion = V_1_1; 294 s->Phone.Data.Priv.ALCATEL.ProtocolVersion = V_1_1;
294 } else { 295 } else {
295 smprintf(s, "Unknown protocol version. Please send debug log and phone info to author.\n"); 296 smprintf(s, "Unknown protocol version. Please send debug log and phone info to author.\n");
296 return ERR_NOTIMPLEMENTED; 297 return ERR_NOTIMPLEMENTED;
297 } 298 }
298 return ERR_NONE; 299 return ERR_NONE;
299 case AT_Reply_Error: 300 case AT_Reply_Error:
300 case AT_Reply_CMSError: 301 case AT_Reply_CMSError:
301 return ATGEN_HandleCMSError(s); 302 return ATGEN_HandleCMSError(s);
302 default: 303 default:
303 return ERR_UNKNOWNRESPONSE; 304 return ERR_UNKNOWNRESPONSE;
304 } 305 }
305} 306}
306 307
307static GSM_Error ALCATEL_SetBinaryMode(GSM_StateMachine *s) 308static GSM_Error ALCATEL_SetBinaryMode(GSM_StateMachine *s)
308{ 309{
309 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 310 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
310 GSM_Error error; 311 GSM_Error error;
311 312
312 if (Priv->Mode == ModeBinary) return ERR_NONE; 313 if (Priv->Mode == ModeBinary) return ERR_NONE;
313 314
314 dbgprintf ("Changing to binary mode\n"); 315 dbgprintf ("Changing to binary mode\n");
315 316
316 error=GSM_WaitFor (s, "AT+IFC=2,2\r", 11, 0x02, 4, ID_SetFlowControl); 317 error=GSM_WaitFor (s, "AT+IFC=2,2\r", 11, 0x02, 4, ID_SetFlowControl);
317 if (error != ERR_NONE) return error; 318 if (error != ERR_NONE) return error;
318 319
319 error=GSM_WaitFor (s, "AT+CPROT=?\r", 11, 0x02, 4, ID_AlcatelProtocol); 320 error=GSM_WaitFor (s, "AT+CPROT=?\r", 11, 0x02, 4, ID_AlcatelProtocol);
320 if (error != ERR_NONE) return error; 321 if (error != ERR_NONE) return error;
321 322
322 if (Priv->ProtocolVersion == V_1_0) { 323 if (Priv->ProtocolVersion == V_1_0) {
323 error=GSM_WaitFor (s, "AT+CPROT=16,\"V1.0\",16\r", 22, 0x00, 4, ID_AlcatelConnect); 324 error=GSM_WaitFor (s, "AT+CPROT=16,\"V1.0\",16\r", 22, 0x00, 4, ID_AlcatelConnect);
324 } else { 325 } else {
325 error=GSM_WaitFor (s, "AT+CPROT=16,\"V1.1\",16\r", 22, 0x00, 4, ID_AlcatelConnect); 326 error=GSM_WaitFor (s, "AT+CPROT=16,\"V1.1\",16\r", 22, 0x00, 4, ID_AlcatelConnect);
326 } 327 }
327 328
328 if (error == ERR_TIMEOUT && s->Speed != 19200) { 329 if (error == ERR_TIMEOUT && s->Speed != 19200) {
329 smprintf(s, "HINT: Try changing speed to 19200, it is sometimes needed for Alcatel binary mode.\n"); 330 smprintf(s, "HINT: Try changing speed to 19200, it is sometimes needed for Alcatel binary mode.\n");
330 } 331 }
331 332
332 if (error != ERR_NONE) return error; 333 if (error != ERR_NONE) return error;
333 334
334 dbgprintf ("Changing protocol to Alcabus\n"); 335 dbgprintf ("Changing protocol to Alcabus\n");
335 336
336 s->Protocol.Functions = &ALCABUSProtocol; 337 s->Protocol.Functions = &ALCABUSProtocol;
337 error = s->Protocol.Functions->Initialise(s); 338 error = s->Protocol.Functions->Initialise(s);
338 if (error != ERR_NONE) { 339 if (error != ERR_NONE) {
339 s->Protocol.Functions = &ATProtocol; 340 s->Protocol.Functions = &ATProtocol;
340 return error; 341 return error;
341 } 342 }
342 s->Phone.Functions->ReplyFunctions= ALCATELReplyFunctions; 343 s->Phone.Functions->ReplyFunctions= ALCATELReplyFunctions;
343 Priv->Mode = ModeBinary; 344 Priv->Mode = ModeBinary;
344 Priv->BinaryItem = 0; 345 Priv->BinaryItem = 0;
345 Priv->BinaryType = 0; 346 Priv->BinaryType = 0;
346 Priv->BinaryState = StateAttached; 347 Priv->BinaryState = StateAttached;
347 return ERR_NONE; 348 return ERR_NONE;
348} 349}
349 350
350static GSM_Error ALCATEL_GoToBinaryState(GSM_StateMachine *s, GSM_Alcatel_BinaryState state, GSM_Alcatel_BinaryType type, int item) { 351static GSM_Error ALCATEL_GoToBinaryState(GSM_StateMachine *s, GSM_Alcatel_BinaryState state, GSM_Alcatel_BinaryType type, int item) {
351 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 352 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
352 GSM_Error error; 353 GSM_Error error;
353 unsigned char attach_buffer[] = {0x00, 0x00, 0x7C ,0x20}; 354 unsigned char attach_buffer[] = {0x00, 0x00, 0x7C ,0x20};
354 unsigned char detach_buffer[] = {0x00, 0x01, 0x7C ,0x00}; 355 unsigned char detach_buffer[] = {0x00, 0x01, 0x7C ,0x00};
355 unsigned char start_buffer[] = 356 unsigned char start_buffer[] =
356 {0x00, 0x04, 0x7C, 0x80, /* 4 byte database id follows */ 357 {0x00, 0x04, 0x7C, 0x80, /* 4 byte database id follows */
357 0x12, 0x34, 0x56, 0x78}; 358 0x12, 0x34, 0x56, 0x78};
358 unsigned char end_buffer[] = 359 unsigned char end_buffer[] =
359 {0x00, 0x04, 0x7C, 0x82, 360 {0x00, 0x04, 0x7C, 0x82,
360 0x00, /* type */ 361 0x00, /* type */
361 0x00, 0x00, 0x00, 0x00}; /* TimeStamp */ 362 0x00, 0x00, 0x00, 0x00}; /* TimeStamp */
362 unsigned char close_buffer[] = 363 unsigned char close_buffer[] =
363 {0x00, 0x04, 364 {0x00, 0x04,
364 0x00, /*type */ 365 0x00, /*type */
365 0x23, 0x01}; 366 0x23, 0x01};
366 unsigned char select1_buffer[] = 367 unsigned char select1_buffer[] =
367 {0x00, 0x00, 368 {0x00, 0x00,
368 0x00, /*type */ 369 0x00, /*type */
369 0x20}; 370 0x20};
370 unsigned char select2_buffer[] = 371 unsigned char select2_buffer[] =
371 {0x00, 0x04, 372 {0x00, 0x04,
372 0x00, /*type */ 373 0x00, /*type */
373 0x22, 0x01, 0x00}; 374 0x22, 0x01, 0x00};
374 unsigned char begin_buffer[] = 375 unsigned char begin_buffer[] =
375 {0x00, 0x04, 0x7C, 0x81, 376 {0x00, 0x04, 0x7C, 0x81,
376 0x00, /*type */ 377 0x00, /*type */
377 0x00, 0x85, 0x00}; 378 0x00, 0x85, 0x00};
378 unsigned char commit_buffer[] = 379 unsigned char commit_buffer[] =
379 {0x00, 0x04, 380 {0x00, 0x04,
380 0x00, /*type */ 381 0x00, /*type */
381 0x20, 0x01}; 382 0x20, 0x01};
382 383
383 smprintf(s, "Alcatel state switcher: %d -> %d, %d -> %d, %d -> %d\n", Priv->BinaryState, state, Priv->BinaryType, type, Priv->BinaryItem, item); 384 smprintf(s, "Alcatel state switcher: %d -> %d, %d -> %d, %d -> %d\n", Priv->BinaryState, state, Priv->BinaryType, type, Priv->BinaryItem, item);
384 error = ALCATEL_SetBinaryMode(s); 385 error = ALCATEL_SetBinaryMode(s);
385 if (error != ERR_NONE) return error; 386 if (error != ERR_NONE) return error;
386 387
387 /* Do we need to do anything? */ 388 /* Do we need to do anything? */
388 if ((state == Priv->BinaryState) && (type == Priv->BinaryType) && (item == Priv->BinaryItem)) return ERR_NONE; 389 if ((state == Priv->BinaryState) && (type == Priv->BinaryType) && (item == Priv->BinaryItem)) return ERR_NONE;
389 390
390 /* We're editing, but the next state is not the same. so commit editing */ 391 /* We're editing, but the next state is not the same. so commit editing */
391 if (Priv->BinaryState == StateEdit) { 392 if (Priv->BinaryState == StateEdit) {
392 /* Something has changed, we will have to reread fields! */ 393 /* Something has changed, we will have to reread fields! */
393 Priv->CurrentFieldsItem = -1; 394 Priv->CurrentFieldsItem = -1;
394 switch (Priv->BinaryType) { 395 switch (Priv->BinaryType) {
395 case TypeCalendar: 396 case TypeCalendar:
396 commit_buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR; 397 commit_buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR;
397 break; 398 break;
398 case TypeContacts: 399 case TypeContacts:
399 commit_buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 400 commit_buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
400 break; 401 break;
401 case TypeToDo: 402 case TypeToDo:
402 commit_buffer[2] = ALCATEL_SYNC_TYPE_TODO; 403 commit_buffer[2] = ALCATEL_SYNC_TYPE_TODO;
403 break; 404 break;
404 } 405 }
405 dbgprintf ("Commiting edited record\n"); 406 dbgprintf ("Commiting edited record\n");
406 error=GSM_WaitFor (s, commit_buffer, 5, 0x02, ALCATEL_TIMEOUT, ID_AlcatelCommit); 407 error=GSM_WaitFor (s, commit_buffer, 5, 0x02, ALCATEL_TIMEOUT, ID_AlcatelCommit);
407 if (error != ERR_NONE) return error; 408 if (error != ERR_NONE) return error;
408 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelCommit2); 409 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelCommit2);
409 if (error != ERR_NONE) return error; 410 if (error != ERR_NONE) return error;
410 Priv->BinaryState = StateSession; 411 Priv->BinaryState = StateSession;
411 Priv->BinaryItem = 0; 412 Priv->BinaryItem = 0;
412 } 413 }
413 414
414 /* Do we want to edit something of same type? */ 415 /* Do we want to edit something of same type? */
415 if ((state == StateEdit) && (type == Priv->BinaryType)) { 416 if ((state == StateEdit) && (type == Priv->BinaryType)) {
416 /* Edit state doesn't need any switching, it is needed only for 417 /* Edit state doesn't need any switching, it is needed only for
417 * indication that e have to commit record before we switch to other 418 * indication that e have to commit record before we switch to other
418 * mode. 419 * mode.
419 */ 420 */
420 Priv->BinaryState = StateEdit; 421 Priv->BinaryState = StateEdit;
421 Priv->BinaryItem = item; 422 Priv->BinaryItem = item;
422 return ERR_NONE; 423 return ERR_NONE;
423 } 424 }
424 425
425 /* Now we can be only in Attached or Session state, so if states and types matches, just keep them as they are */ 426 /* Now we can be only in Attached or Session state, so if states and types matches, just keep them as they are */
426 if ((state == Priv->BinaryState) && (type == Priv->BinaryType)) { 427 if ((state == Priv->BinaryState) && (type == Priv->BinaryType)) {
427 return ERR_NONE; 428 return ERR_NONE;
428 } 429 }
429 430
430 /* Do we need to close session? */ 431 /* Do we need to close session? */
431 if (Priv->BinaryState == StateSession) { 432 if (Priv->BinaryState == StateSession) {
432 dbgprintf ("Ending session\n"); 433 dbgprintf ("Ending session\n");
433 switch (Priv->BinaryType) { 434 switch (Priv->BinaryType) {
434 case TypeCalendar: 435 case TypeCalendar:
435 end_buffer[4] = ALCATEL_BEGIN_SYNC_CALENDAR; 436 end_buffer[4] = ALCATEL_BEGIN_SYNC_CALENDAR;
436 break; 437 break;
437 case TypeContacts: 438 case TypeContacts:
438 end_buffer[4] = ALCATEL_BEGIN_SYNC_CONTACTS; 439 end_buffer[4] = ALCATEL_BEGIN_SYNC_CONTACTS;
439 break; 440 break;
440 case TypeToDo: 441 case TypeToDo:
441 end_buffer[4] = ALCATEL_BEGIN_SYNC_TODO; 442 end_buffer[4] = ALCATEL_BEGIN_SYNC_TODO;
442 break; 443 break;
443 } 444 }
444 error=GSM_WaitFor (s, end_buffer, 9, 0x02, ALCATEL_TIMEOUT, ID_AlcatelEnd); 445 error=GSM_WaitFor (s, end_buffer, 9, 0x02, ALCATEL_TIMEOUT, ID_AlcatelEnd);
445 if (error != ERR_NONE) return error; 446 if (error != ERR_NONE) return error;
446 447
447 switch (Priv->BinaryType) { 448 switch (Priv->BinaryType) {
448 case TypeCalendar: 449 case TypeCalendar:
449 close_buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR; 450 close_buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR;
450 break; 451 break;
451 case TypeContacts: 452 case TypeContacts:
452 close_buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 453 close_buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
453 break; 454 break;
454 case TypeToDo: 455 case TypeToDo:
455 close_buffer[2] = ALCATEL_SYNC_TYPE_TODO; 456 close_buffer[2] = ALCATEL_SYNC_TYPE_TODO;
456 break; 457 break;
457 } 458 }
458 dbgprintf ("Closing session\n"); 459 dbgprintf ("Closing session\n");
459 error=GSM_WaitFor (s, close_buffer, 5, 0x02, ALCATEL_TIMEOUT, ID_AlcatelClose); 460 error=GSM_WaitFor (s, close_buffer, 5, 0x02, ALCATEL_TIMEOUT, ID_AlcatelClose);
460 if (error != ERR_NONE) return error; 461 if (error != ERR_NONE) return error;
461 462
462 dbgprintf ("Detaching binary mode\n"); 463 dbgprintf ("Detaching binary mode\n");
463 GSM_WaitFor (s, detach_buffer, 4, 0x02, ALCATEL_TIMEOUT, ID_AlcatelDetach); 464 GSM_WaitFor (s, detach_buffer, 4, 0x02, ALCATEL_TIMEOUT, ID_AlcatelDetach);
464 465
465 Priv->BinaryState = StateAttached; 466 Priv->BinaryState = StateAttached;
466 Priv->BinaryType = 0; 467 Priv->BinaryType = 0;
467 } 468 }
468 469
469 /* Do we need to open session? */ 470 /* Do we need to open session? */
470 if (state == StateSession || state == StateEdit) { 471 if (state == StateSession || state == StateEdit) {
471 dbgprintf ("Starting session for %s\n", 472 dbgprintf ("Starting session for %s\n",
472 (type == TypeCalendar ? "Calendar" : 473 (type == TypeCalendar ? "Calendar" :
473 (type == TypeToDo ? "Todo" : 474 (type == TypeToDo ? "Todo" :
474 (type == TypeContacts ? "Contacts" : 475 (type == TypeContacts ? "Contacts" :
475 "Unknown!")))); 476 "Unknown!"))));
476 /* Fill up buffers */ 477 /* Fill up buffers */
477 switch (type) { 478 switch (type) {
478 case TypeCalendar: 479 case TypeCalendar:
479 select1_buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR; 480 select1_buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR;
480 select2_buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR; 481 select2_buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR;
481 begin_buffer[4] = ALCATEL_BEGIN_SYNC_CALENDAR; 482 begin_buffer[4] = ALCATEL_BEGIN_SYNC_CALENDAR;
482 break; 483 break;
483 case TypeContacts: 484 case TypeContacts:
484 select1_buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 485 select1_buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
485 select2_buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 486 select2_buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
486 begin_buffer[4] = ALCATEL_BEGIN_SYNC_CONTACTS; 487 begin_buffer[4] = ALCATEL_BEGIN_SYNC_CONTACTS;
487 break; 488 break;
488 case TypeToDo: 489 case TypeToDo:
489 select1_buffer[2] = ALCATEL_SYNC_TYPE_TODO; 490 select1_buffer[2] = ALCATEL_SYNC_TYPE_TODO;
490 select2_buffer[2] = ALCATEL_SYNC_TYPE_TODO; 491 select2_buffer[2] = ALCATEL_SYNC_TYPE_TODO;
491 begin_buffer[4] = ALCATEL_BEGIN_SYNC_TODO; 492 begin_buffer[4] = ALCATEL_BEGIN_SYNC_TODO;
492 break; 493 break;
493 } 494 }
494 dbgprintf ("Attaching in binary mode\n"); 495 dbgprintf ("Attaching in binary mode\n");
495 496
496 /* Communicate */ 497 /* Communicate */
497 error=GSM_WaitFor (s, attach_buffer, 4, 0x02, ALCATEL_TIMEOUT, ID_AlcatelAttach); 498 error=GSM_WaitFor (s, attach_buffer, 4, 0x02, ALCATEL_TIMEOUT, ID_AlcatelAttach);
498 if (error != ERR_NONE) return error; 499 if (error != ERR_NONE) return error;
499 500
500 smprintf(s,"Start session\n"); 501 smprintf(s,"Start session\n");
501 error=GSM_WaitFor (s, start_buffer, 8, 0x02, ALCATEL_TIMEOUT, ID_AlcatelStart); 502 error=GSM_WaitFor (s, start_buffer, 8, 0x02, ALCATEL_TIMEOUT, ID_AlcatelStart);
502 if (error != ERR_NONE) return error; 503 if (error != ERR_NONE) return error;
503 504
504 smprintf(s,"Select type\n"); 505 smprintf(s,"Select type\n");
505 error=GSM_WaitFor (s, select1_buffer, 4, 0x02, ALCATEL_TIMEOUT, ID_AlcatelSelect1); 506 error=GSM_WaitFor (s, select1_buffer, 4, 0x02, ALCATEL_TIMEOUT, ID_AlcatelSelect1);
506 if (error != ERR_NONE) return error; 507 if (error != ERR_NONE) return error;
507 error=GSM_WaitFor (s, select2_buffer, 6, 0x02, ALCATEL_TIMEOUT, ID_AlcatelSelect2); 508 error=GSM_WaitFor (s, select2_buffer, 6, 0x02, ALCATEL_TIMEOUT, ID_AlcatelSelect2);
508 if (error != ERR_NONE) return error; 509 if (error != ERR_NONE) return error;
509 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelSelect3); 510 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelSelect3);
510 if (error != ERR_NONE) return error; 511 if (error != ERR_NONE) return error;
511 512
512 smprintf(s,"Begin transfer\n"); 513 smprintf(s,"Begin transfer\n");
513 error=GSM_WaitFor (s, begin_buffer, 8, 0x02, ALCATEL_TIMEOUT, ID_AlcatelBegin1); 514 error=GSM_WaitFor (s, begin_buffer, 8, 0x02, ALCATEL_TIMEOUT, ID_AlcatelBegin1);
514 if (error != ERR_NONE) return error; 515 if (error != ERR_NONE) return error;
515 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelBegin2); 516 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelBegin2);
516 if (error != ERR_NONE) return error; 517 if (error != ERR_NONE) return error;
517 518
518 Priv->BinaryState = StateSession; 519 Priv->BinaryState = StateSession;
519 Priv->BinaryType = type; 520 Priv->BinaryType = type;
520 /* Do we want to edit something of same type? */ 521 /* Do we want to edit something of same type? */
521 if ((state == StateEdit) && (type == Priv->BinaryType)) { 522 if ((state == StateEdit) && (type == Priv->BinaryType)) {
522 Priv->BinaryState = StateEdit; 523 Priv->BinaryState = StateEdit;
523 Priv->BinaryItem = item; 524 Priv->BinaryItem = item;
524 return ERR_NONE; 525 return ERR_NONE;
525 } 526 }
526 } 527 }
527 return ERR_NONE; 528 return ERR_NONE;
528} 529}
529 530
530static GSM_Error ALCATEL_SetATMode(GSM_StateMachine *s) 531static GSM_Error ALCATEL_SetATMode(GSM_StateMachine *s)
531{ 532{
532 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 533 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
533 GSM_Error error; 534 GSM_Error error;
534 535
535 if (Priv->Mode == ModeAT) return ERR_NONE; 536 if (Priv->Mode == ModeAT) return ERR_NONE;
536 537
537 error = ALCATEL_GoToBinaryState(s, StateAttached, 0, 0); 538 error = ALCATEL_GoToBinaryState(s, StateAttached, 0, 0);
538 if (error != ERR_NONE) return error; 539 if (error != ERR_NONE) return error;
539 540
540 error = s->Protocol.Functions->Terminate(s); 541 error = s->Protocol.Functions->Terminate(s);
541 if (error != ERR_NONE) return error; 542 if (error != ERR_NONE) return error;
542 543
543 dbgprintf ("Changing protocol to AT\n"); 544 dbgprintf ("Changing protocol to AT\n");
544 s->Protocol.Functions = &ATProtocol; 545 s->Protocol.Functions = &ATProtocol;
545 s->Phone.Functions->ReplyFunctions= ATGENReplyFunctions; 546 s->Phone.Functions->ReplyFunctions= ATGENReplyFunctions;
546 Priv->Mode = ModeAT; 547 Priv->Mode = ModeAT;
548 s->Phone.Data.Priv.ATGEN.PBKCharset= 0;
549 s->Phone.Data.Priv.ATGEN.PBKMemory= 0;
547 550
548 my_sleep(100); 551 my_sleep(100);
549 552
550 /* In case we don't send AT command short after closing binary mode, 553 /* In case we don't send AT command short after closing binary mode,
551 * phone takes VERY long to react next time. The error code in 554 * phone takes VERY long to react next time. The error code in
552 * intetionally ignored. 555 * intetionally ignored.
553 */ 556 */
554 GSM_WaitFor (s, "AT\r", 3, 0x00, 0, ID_IncomingFrame); 557 GSM_WaitFor (s, "AT\r", 3, 0x00, 0, ID_IncomingFrame);
555 558
556 return ERR_NONE; 559 return ERR_NONE;
557} 560}
558 561
559static GSM_Error ALCATEL_Initialise(GSM_StateMachine *s) 562static GSM_Error ALCATEL_Initialise(GSM_StateMachine *s)
560{ 563{
561 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 564 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
562 GSM_Error error; 565 GSM_Error error;
563 566
564 Priv->Mode = ModeAT; 567 Priv->Mode = ModeAT;
565 568
566 Priv->CalendarItems = NULL; 569 Priv->CalendarItems = NULL;
567 Priv->ContactsItems = NULL; 570 Priv->ContactsItems = NULL;
568 Priv->ToDoItems = NULL; 571 Priv->ToDoItems = NULL;
569 Priv->CalendarItemsCount = 0; 572 Priv->CalendarItemsCount = 0;
570 Priv->ToDoItemsCount = 0; 573 Priv->ToDoItemsCount = 0;
571 Priv->ContactsItemsCount = 0; 574 Priv->ContactsItemsCount = 0;
572 Priv->CurrentFields[0] = 0; 575 Priv->CurrentFields[0] = 0;
573 Priv->CurrentFieldsCount = 0; 576 Priv->CurrentFieldsCount = 0;
574 Priv->CurrentFieldsItem = 0; 577 Priv->CurrentFieldsItem = 0;
575 Priv->CurrentFieldsType = 0; 578 Priv->CurrentFieldsType = 0;
576 Priv->ProtocolVersion = V_1_0; 579 Priv->ProtocolVersion = V_1_0;
577 Priv->CurrentFieldsItem = -1; 580 Priv->CurrentFieldsItem = -1;
578 581
579 Priv->CurrentCategoriesCount = 0; 582 Priv->CurrentCategoriesCount = 0;
580 Priv->CurrentCategoriesType = 0; 583 Priv->CurrentCategoriesType = 0;
581 584
582 s->Protocol.Functions = &ATProtocol; 585 s->Protocol.Functions = &ATProtocol;
583 s->Phone.Functions->ReplyFunctions= ATGENReplyFunctions; 586 s->Phone.Functions->ReplyFunctions= ATGENReplyFunctions;
584 587
585 if (ATGEN_Initialise(s) != ERR_NONE || GSM_WaitFor (s, "AT\r", 3, 0x00, 2, ID_IncomingFrame) != ERR_NONE) { 588 if (ATGEN_Initialise(s) != ERR_NONE || GSM_WaitFor (s, "AT\r", 3, 0x00, 2, ID_IncomingFrame) != ERR_NONE) {
586 smprintf(s,"AT initialisation failed, trying to stop binary mode...\n"); 589 smprintf(s,"AT initialisation failed, trying to stop binary mode...\n");
587 s->Protocol.Functions = &ALCABUSProtocol; 590 s->Protocol.Functions = &ALCABUSProtocol;
588 error = s->Protocol.Functions->Terminate(s); 591 error = s->Protocol.Functions->Terminate(s);
589 s->Protocol.Functions = &ATProtocol; 592 s->Protocol.Functions = &ATProtocol;
590 593
591 error = ATGEN_Initialise(s); 594 error = ATGEN_Initialise(s);
592 if (error != ERR_NONE) return error; 595 if (error != ERR_NONE) return error;
593 } 596 }
594 597
595 return ERR_NONE; 598 return ERR_NONE;
596} 599}
597 600
598static GSM_Error ALCATEL_Terminate(GSM_StateMachine *s) 601static GSM_Error ALCATEL_Terminate(GSM_StateMachine *s)
599{ 602{
600 GSM_Error error; 603 GSM_Error error;
601 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 604 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
602 605
603 free(Priv->CalendarItems); 606 free(Priv->CalendarItems);
604 free(Priv->ContactsItems); 607 free(Priv->ContactsItems);
605 free(Priv->ToDoItems); 608 free(Priv->ToDoItems);
606 error = ALCATEL_SetATMode(s); 609 error = ALCATEL_SetATMode(s);
607 return ATGEN_Terminate(s); 610 return ATGEN_Terminate(s);
608} 611}
609 612
610/* finds whether id is set in the phone */ 613/* finds whether id is set in the phone */
611static GSM_Error ALCATEL_IsIdAvailable(GSM_StateMachine *s, int id) { 614static GSM_Error ALCATEL_IsIdAvailable(GSM_StateMachine *s, int id) {
612 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 615 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
613 int i; 616 int i;
614 617
615 if (id > ALCATEL_MAX_LOCATION) return ERR_INVALIDLOCATION; 618 if (id > ALCATEL_MAX_LOCATION) return ERR_INVALIDLOCATION;
616 619
617 switch (Priv->BinaryType) { 620 switch (Priv->BinaryType) {
618 case TypeCalendar: 621 case TypeCalendar:
619 Priv->CurrentList = &(Priv->CalendarItems); 622 Priv->CurrentList = &(Priv->CalendarItems);
620 Priv->CurrentCount = &(Priv->CalendarItemsCount); 623 Priv->CurrentCount = &(Priv->CalendarItemsCount);
621 break; 624 break;
622 case TypeContacts: 625 case TypeContacts:
623 Priv->CurrentList = &(Priv->ContactsItems); 626 Priv->CurrentList = &(Priv->ContactsItems);
624 Priv->CurrentCount = &(Priv->ContactsItemsCount); 627 Priv->CurrentCount = &(Priv->ContactsItemsCount);
625 break; 628 break;
626 case TypeToDo: 629 case TypeToDo:
627 Priv->CurrentList = &(Priv->ToDoItems); 630 Priv->CurrentList = &(Priv->ToDoItems);
628 Priv->CurrentCount = &(Priv->ToDoItemsCount); 631 Priv->CurrentCount = &(Priv->ToDoItemsCount);
629 break; 632 break;
630 } 633 }
631 634
632 for (i=0; i<*Priv->CurrentCount; i++) { 635 for (i=0; i<*Priv->CurrentCount; i++) {
633 if ((*Priv->CurrentList)[i] == id) return ERR_NONE; 636 if ((*Priv->CurrentList)[i] == id) return ERR_NONE;
634 } 637 }
635 638
636 return ERR_EMPTY; 639 return ERR_EMPTY;
637} 640}
638 641
639/* finds next id that is available in the phone */ 642/* finds next id that is available in the phone */
640static GSM_Error ALCATEL_GetNextId(GSM_StateMachine *s, int *id) { 643static GSM_Error ALCATEL_GetNextId(GSM_StateMachine *s, int *id) {
641 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 644 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
642 int i = 0; 645 int i = 0;
643 int next = ALCATEL_MAX_LOCATION; 646 int next = ALCATEL_MAX_LOCATION;
644 647
645 switch (Priv->BinaryType) { 648 switch (Priv->BinaryType) {
646 case TypeCalendar: 649 case TypeCalendar:
647 Priv->CurrentList = &(Priv->CalendarItems); 650 Priv->CurrentList = &(Priv->CalendarItems);
648 Priv->CurrentCount = &(Priv->CalendarItemsCount); 651 Priv->CurrentCount = &(Priv->CalendarItemsCount);
649 break; 652 break;
650 case TypeContacts: 653 case TypeContacts:
651 Priv->CurrentList = &(Priv->ContactsItems); 654 Priv->CurrentList = &(Priv->ContactsItems);
652 Priv->CurrentCount = &(Priv->ContactsItemsCount); 655 Priv->CurrentCount = &(Priv->ContactsItemsCount);
653 break; 656 break;
654 case TypeToDo: 657 case TypeToDo:
655 Priv->CurrentList = &(Priv->ToDoItems); 658 Priv->CurrentList = &(Priv->ToDoItems);
656 Priv->CurrentCount = &(Priv->ToDoItemsCount); 659 Priv->CurrentCount = &(Priv->ToDoItemsCount);
657 break; 660 break;
658 } 661 }
659 662
660 for (i=0; i<*Priv->CurrentCount; i++) { 663 for (i=0; i<*Priv->CurrentCount; i++) {
661 if (((*Priv->CurrentList)[i] > *id) && ((*Priv->CurrentList)[i] < next )) { 664 if (((*Priv->CurrentList)[i] > *id) && ((*Priv->CurrentList)[i] < next )) {
662 next = (*Priv->CurrentList)[i]; 665 next = (*Priv->CurrentList)[i];
663 } 666 }
664 } 667 }
665 if (next == ALCATEL_MAX_LOCATION) { 668 if (next == ALCATEL_MAX_LOCATION) {
666 return ERR_EMPTY; 669 return ERR_EMPTY;
667 } else { 670 } else {
668 *id = next; 671 *id = next;
669 return ERR_NONE; 672 return ERR_NONE;
670 } 673 }
671} 674}
672 675
673static GSM_Error ALCATEL_ReplyGetIds(GSM_Protocol_Message msg, GSM_StateMachine *s) 676static GSM_Error ALCATEL_ReplyGetIds(GSM_Protocol_Message msg, GSM_StateMachine *s)
674{ 677{
675 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL; 678 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL;
676 int count,i,pos; 679 int count,i,pos;
677 680
678 count = msg.Buffer[10]; 681 count = msg.Buffer[10];
679 *Priv->CurrentCount += count; 682 *Priv->CurrentCount += count;
680 683
681 *Priv->CurrentList = (int *)realloc(*Priv->CurrentList, (*Priv->CurrentCount + 1)* sizeof(int)); 684 *Priv->CurrentList = (int *)realloc(*Priv->CurrentList, (*Priv->CurrentCount + 1)* sizeof(int));
682 if (*Priv->CurrentList == NULL) return ERR_MOREMEMORY; 685 if (*Priv->CurrentList == NULL) return ERR_MOREMEMORY;
683 686
684 for (i = 0; i < count; i++) { 687 for (i = 0; i < count; i++) {
685 pos = 11 + (4 * i); 688 pos = 11 + (4 * i);
686 (*Priv->CurrentList)[*Priv->CurrentCount - count + i] = msg.Buffer[pos + 3] + 689 (*Priv->CurrentList)[*Priv->CurrentCount - count + i] = msg.Buffer[pos + 3] +
687 (msg.Buffer[pos + 2] << 8) + 690 (msg.Buffer[pos + 2] << 8) +
688 (msg.Buffer[pos + 1] << 16) + 691 (msg.Buffer[pos + 1] << 16) +
689 (msg.Buffer[pos] << 24); 692 (msg.Buffer[pos] << 24);
690 } 693 }
691 (*Priv->CurrentList)[*Priv->CurrentCount] = 0; 694 (*Priv->CurrentList)[*Priv->CurrentCount] = 0;
692 695
693 /* If last byte is 0, then we transmitted all items */ 696 /* If last byte is 0, then we transmitted all items */
694 Priv->TransferCompleted = msg.Buffer[4 + msg.Buffer[4]] == 0; 697 Priv->TransferCompleted = msg.Buffer[4 + msg.Buffer[4]] == 0;
695 return ERR_NONE; 698 return ERR_NONE;
696} 699}
697 700
698static GSM_Error ALCATEL_GetAvailableIds(GSM_StateMachine *s, bool refresh) 701static GSM_Error ALCATEL_GetAvailableIds(GSM_StateMachine *s, bool refresh)
699{ 702{
700 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 703 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
701 GSM_Error error; 704 GSM_Error error;
702 int i; 705 int i;
703 unsigned char buffer[] = 706 unsigned char buffer[] =
704 {0x00, 0x04, 707 {0x00, 0x04,
705 0x00, /*type */ 708 0x00, /*type */
706 0x2F, 0x01}; 709 0x2F, 0x01};
707 710
708 if (Priv->BinaryState != StateSession) return ERR_UNKNOWN; 711 if (Priv->BinaryState != StateSession) return ERR_UNKNOWN;
709 712
710 switch (Priv->BinaryType) { 713 switch (Priv->BinaryType) {
711 case TypeCalendar: 714 case TypeCalendar:
712 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR; 715 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR;
713 Priv->CurrentList= &(Priv->CalendarItems); 716 Priv->CurrentList= &(Priv->CalendarItems);
714 Priv->CurrentCount= &(Priv->CalendarItemsCount); 717 Priv->CurrentCount= &(Priv->CalendarItemsCount);
715 break; 718 break;
716 case TypeContacts: 719 case TypeContacts:
717 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 720 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
718 Priv->CurrentList= &(Priv->ContactsItems); 721 Priv->CurrentList= &(Priv->ContactsItems);
719 Priv->CurrentCount= &(Priv->ContactsItemsCount); 722 Priv->CurrentCount= &(Priv->ContactsItemsCount);
720 break; 723 break;
721 case TypeToDo: 724 case TypeToDo:
722 buffer[2] = ALCATEL_SYNC_TYPE_TODO; 725 buffer[2] = ALCATEL_SYNC_TYPE_TODO;
723 Priv->CurrentList= &(Priv->ToDoItems); 726 Priv->CurrentList= &(Priv->ToDoItems);
724 Priv->CurrentCount= &(Priv->ToDoItemsCount); 727 Priv->CurrentCount= &(Priv->ToDoItemsCount);
725 break; 728 break;
726 } 729 }
727 730
728 if (*Priv->CurrentList != NULL) { 731 if (*Priv->CurrentList != NULL) {
729 if (!refresh) return ERR_NONE; 732 if (!refresh) return ERR_NONE;
730 free(*Priv->CurrentList); 733 free(*Priv->CurrentList);
731 *Priv->CurrentList = NULL; 734 *Priv->CurrentList = NULL;
732 } 735 }
733 smprintf(s,"Reading items list\n"); 736 smprintf(s,"Reading items list\n");
734 737
735 *Priv->CurrentCount = 0; 738 *Priv->CurrentCount = 0;
736 Priv->TransferCompleted = false; 739 Priv->TransferCompleted = false;
737 740
738 error=GSM_WaitFor (s, buffer, 5, 0x02, ALCATEL_TIMEOUT, ID_AlcatelGetIds1); 741 error=GSM_WaitFor (s, buffer, 5, 0x02, ALCATEL_TIMEOUT, ID_AlcatelGetIds1);
739 if (error != ERR_NONE) return error; 742 if (error != ERR_NONE) return error;
740 743
741 while (!Priv->TransferCompleted) { 744 while (!Priv->TransferCompleted) {
742 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelGetIds2); 745 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelGetIds2);
743 if (error != ERR_NONE) return error; 746 if (error != ERR_NONE) return error;
744 } 747 }
745 748
746 i = 0; 749 i = 0;
747 smprintf(s,"Received %d ids: ", *Priv->CurrentCount); 750 smprintf(s,"Received %d ids: ", *Priv->CurrentCount);
748 for (i=0; i < *Priv->CurrentCount; i++) { 751 for (i=0; i < *Priv->CurrentCount; i++) {
749 smprintf(s,"%x ", (*Priv->CurrentList)[i]); 752 smprintf(s,"%x ", (*Priv->CurrentList)[i]);
750 } 753 }
751 smprintf(s,"\n"); 754 smprintf(s,"\n");
752 755
753 return ERR_NONE; 756 return ERR_NONE;
754} 757}
755 758
756static GSM_Error ALCATEL_ReplyGetFields(GSM_Protocol_Message msg, GSM_StateMachine *s) 759static GSM_Error ALCATEL_ReplyGetFields(GSM_Protocol_Message msg, GSM_StateMachine *s)
757{ 760{
758 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL; 761 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL;
759 int i; 762 int i;
760 763
761 if (msg.Buffer[14] > GSM_PHONEBOOK_ENTRIES) { 764 if (msg.Buffer[14] > GSM_PHONEBOOK_ENTRIES) {
762 smprintf(s, "WARNING: Field list truncated, you should increase GSM_PHONEBOOK_ENTRIES to at least %d\n", msg.Buffer[14]); 765 smprintf(s, "WARNING: Field list truncated, you should increase GSM_PHONEBOOK_ENTRIES to at least %d\n", msg.Buffer[14]);
763 Priv->CurrentFieldsCount = GSM_PHONEBOOK_ENTRIES; 766 Priv->CurrentFieldsCount = GSM_PHONEBOOK_ENTRIES;
764 } else { 767 } else {
765 Priv->CurrentFieldsCount = msg.Buffer[14]; 768 Priv->CurrentFieldsCount = msg.Buffer[14];
766 } 769 }
767 770
768 Priv->CurrentFields[Priv->CurrentFieldsCount] = 0; 771 Priv->CurrentFields[Priv->CurrentFieldsCount] = 0;
769 772
770 for (i = 0; i < Priv->CurrentFieldsCount; i++) { 773 for (i = 0; i < Priv->CurrentFieldsCount; i++) {
771 Priv->CurrentFields[i] = msg.Buffer[15 + i]; 774 Priv->CurrentFields[i] = msg.Buffer[15 + i];
772 } 775 }
773 776
774 return ERR_NONE; 777 return ERR_NONE;
775} 778}
776 779
777static GSM_Error ALCATEL_GetFields(GSM_StateMachine *s, int id) { 780static GSM_Error ALCATEL_GetFields(GSM_StateMachine *s, int id) {
778 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 781 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
779 GSM_Error error; 782 GSM_Error error;
780 int i; 783 int i;
781 unsigned char buffer[] = 784 unsigned char buffer[] =
782 {0x00, 0x04, 785 {0x00, 0x04,
783 0x00, /* type */ 786 0x00, /* type */
784 0x30, 0x01, 787 0x30, 0x01,
785 0x00, 0x00, 0x00, 0x00}; /* item */ 788 0x00, 0x00, 0x00, 0x00}; /* item */
786 789
787 if (Priv->BinaryState != StateSession) return ERR_UNKNOWN; 790 if (Priv->BinaryState != StateSession) return ERR_UNKNOWN;
788 if ((Priv->CurrentFieldsItem == id) && (Priv->CurrentFieldsType == Priv->BinaryType)) return ERR_NONE; 791 if ((Priv->CurrentFieldsItem == id) && (Priv->CurrentFieldsType == Priv->BinaryType)) return ERR_NONE;
789 792
790 smprintf(s,"Reading item fields (%d)\n", id); 793 smprintf(s,"Reading item fields (%d)\n", id);
791 794
792 buffer[5] = (id >> 24); 795 buffer[5] = (id >> 24);
793 buffer[6] = ((id >> 16) & 0xff); 796 buffer[6] = ((id >> 16) & 0xff);
794 buffer[7] = ((id >> 8) & 0xff); 797 buffer[7] = ((id >> 8) & 0xff);
795 buffer[8] = (id & 0xff); 798 buffer[8] = (id & 0xff);
796 799
797 switch (Priv->BinaryType) { 800 switch (Priv->BinaryType) {
798 case TypeCalendar: 801 case TypeCalendar:
799 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR; 802 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR;
800 break; 803 break;
801 case TypeContacts: 804 case TypeContacts:
802 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 805 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
803 break; 806 break;
804 case TypeToDo: 807 case TypeToDo:
805 buffer[2] = ALCATEL_SYNC_TYPE_TODO; 808 buffer[2] = ALCATEL_SYNC_TYPE_TODO;
806 break; 809 break;
807 } 810 }
808 811
809 Priv->CurrentFieldsItem = id; 812 Priv->CurrentFieldsItem = id;
810 Priv->CurrentFieldsType = Priv->BinaryType; 813 Priv->CurrentFieldsType = Priv->BinaryType;
811 814
812 error=GSM_WaitFor (s, buffer, 9, 0x02, ALCATEL_TIMEOUT, ID_AlcatelGetFields1); 815 error=GSM_WaitFor (s, buffer, 9, 0x02, ALCATEL_TIMEOUT, ID_AlcatelGetFields1);
813 if (error != ERR_NONE) return error; 816 if (error != ERR_NONE) return error;
814 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelGetFields2); 817 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelGetFields2);
815 if (error != ERR_NONE) return error; 818 if (error != ERR_NONE) return error;
816 819
817 i = 0; 820 i = 0;
818 smprintf(s,"Received %d fields: ", Priv->CurrentFieldsCount); 821 smprintf(s,"Received %d fields: ", Priv->CurrentFieldsCount);
819 for (i=0; i < Priv->CurrentFieldsCount; i++) { 822 for (i=0; i < Priv->CurrentFieldsCount; i++) {
820 smprintf(s,"%x ", Priv->CurrentFields[i]); 823 smprintf(s,"%x ", Priv->CurrentFields[i]);
821 } 824 }
822 smprintf(s,"\n"); 825 smprintf(s,"\n");
823 826
824 return ERR_NONE; 827 return ERR_NONE;
825} 828}
826 829
827static GSM_Error ALCATEL_ReplyGetFieldValue(GSM_Protocol_Message msg, GSM_StateMachine *s) 830static GSM_Error ALCATEL_ReplyGetFieldValue(GSM_Protocol_Message msg, GSM_StateMachine *s)
828{ 831{
829 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL; 832 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL;
830 unsigned char *buffer = &(msg.Buffer[16]); 833 unsigned char *buffer = &(msg.Buffer[16]);
831 834
832 if (buffer[1] == 0x05 && buffer[2] == 0x67) { 835 if (buffer[1] == 0x05 && buffer[2] == 0x67) {
833 /* date */ 836 /* date */
834 Priv->ReturnType = Alcatel_date; 837 Priv->ReturnType = Alcatel_date;
835 Priv->ReturnDateTime.Day= buffer[4]; 838 Priv->ReturnDateTime.Day= buffer[4];
836 Priv->ReturnDateTime.Month= buffer[5]; 839 Priv->ReturnDateTime.Month= buffer[5];
837 Priv->ReturnDateTime.Year= buffer[7] + (buffer[6] << 8); 840 Priv->ReturnDateTime.Year= buffer[7] + (buffer[6] << 8);
838 Priv->ReturnDateTime.Timezone= 0; /* FIXME: how to acquire this? */ 841 Priv->ReturnDateTime.Timezone= 0; /* FIXME: how to acquire this? */
839 842
840 Priv->ReturnDateTime.Hour= 0; 843 Priv->ReturnDateTime.Hour= 0;
841 Priv->ReturnDateTime.Minute= 0; 844 Priv->ReturnDateTime.Minute= 0;
842 Priv->ReturnDateTime.Second= 0; 845 Priv->ReturnDateTime.Second= 0;
843 } else if (buffer[1] == 0x06 && buffer[2] == 0x68) { 846 } else if (buffer[1] == 0x06 && buffer[2] == 0x68) {
844 /* time */ 847 /* time */
845 Priv->ReturnType = Alcatel_time; 848 Priv->ReturnType = Alcatel_time;
846 Priv->ReturnDateTime.Hour= buffer[4]; 849 Priv->ReturnDateTime.Hour= buffer[4];
847 Priv->ReturnDateTime.Minute= buffer[5]; 850 Priv->ReturnDateTime.Minute= buffer[5];
848 Priv->ReturnDateTime.Second= buffer[6]; 851 Priv->ReturnDateTime.Second= buffer[6];
849 852
850 Priv->ReturnDateTime.Day= 0; 853 Priv->ReturnDateTime.Day= 0;
851 Priv->ReturnDateTime.Month= 0; 854 Priv->ReturnDateTime.Month= 0;
852 Priv->ReturnDateTime.Year= 0; 855 Priv->ReturnDateTime.Year= 0;
853 Priv->ReturnDateTime.Timezone= 0; 856 Priv->ReturnDateTime.Timezone= 0;
854 } else if (buffer[1] == 0x08 && buffer[2] == 0x3C) { 857 } else if (buffer[1] == 0x08 && buffer[2] == 0x3C) {
855 /* string */ 858 /* string */
856 Priv->ReturnType = Alcatel_string; 859 Priv->ReturnType = Alcatel_string;
857 if (GSM_PHONEBOOK_TEXT_LENGTH < buffer[3]) 860 if (GSM_PHONEBOOK_TEXT_LENGTH < buffer[3])
858 smprintf(s, "WARNING: Text truncated, you should increase GSM_PHONEBOOK_TEXT_LENGTH to at least %d\n", buffer[3] + 1); 861 smprintf(s, "WARNING: Text truncated, you should increase GSM_PHONEBOOK_TEXT_LENGTH to at least %d\n", buffer[3] + 1);
859 if (Priv->ProtocolVersion == V_1_0) { 862 if (Priv->ProtocolVersion == V_1_0) {
860 DecodeDefault( Priv->ReturnString, buffer + 4, MIN(GSM_PHONEBOOK_TEXT_LENGTH, buffer[3]), false, GSM_AlcatelAlphabet); 863 DecodeDefault( Priv->ReturnString, buffer + 4, MIN(GSM_PHONEBOOK_TEXT_LENGTH, buffer[3]), false, GSM_AlcatelAlphabet);
861 } else if(Priv->ProtocolVersion == V_1_1 && (buffer[4] & 0x80)) { 864 } else if(Priv->ProtocolVersion == V_1_1 && (buffer[4] & 0x80)) {
862 memcpy(Priv->ReturnString, buffer + 5, buffer[3]); 865 memcpy(Priv->ReturnString, buffer + 5, buffer[3]);
863 Priv->ReturnString[buffer[3] + 1] = 0; 866 Priv->ReturnString[buffer[3] + 1] = 0;
864 Priv->ReturnString[buffer[3] + 2] = 0; 867 Priv->ReturnString[buffer[3] + 2] = 0;
865 ReverseUnicodeString(Priv->ReturnString); 868 ReverseUnicodeString(Priv->ReturnString);
866 } else { 869 } else {
867 DecodeDefault( Priv->ReturnString, buffer + 4, MIN(GSM_PHONEBOOK_TEXT_LENGTH, buffer[3]), false, GSM_AlcatelAlphabet); 870 DecodeDefault( Priv->ReturnString, buffer + 4, MIN(GSM_PHONEBOOK_TEXT_LENGTH, buffer[3]), false, GSM_AlcatelAlphabet);
868 } 871 }
869 } else if (buffer[1] == 0x07 && buffer[2] == 0x3C) { 872 } else if (buffer[1] == 0x07 && buffer[2] == 0x3C) {
870 /* phone */ 873 /* phone */
871 Priv->ReturnType = Alcatel_phone; 874 Priv->ReturnType = Alcatel_phone;
872 if (GSM_PHONEBOOK_TEXT_LENGTH < buffer[3]) 875 if (GSM_PHONEBOOK_TEXT_LENGTH < buffer[3])
873 smprintf(s, "WARNING: Text truncated, you should increase GSM_PHONEBOOK_TEXT_LENGTH to at least %d\n", buffer[3] + 1); 876 smprintf(s, "WARNING: Text truncated, you should increase GSM_PHONEBOOK_TEXT_LENGTH to at least %d\n", buffer[3] + 1);
874 if (Priv->ProtocolVersion == V_1_0) { 877 if (Priv->ProtocolVersion == V_1_0) {
875 DecodeDefault( Priv->ReturnString, buffer + 4, MIN(GSM_PHONEBOOK_TEXT_LENGTH, buffer[3]), false, GSM_AlcatelAlphabet); 878 DecodeDefault( Priv->ReturnString, buffer + 4, MIN(GSM_PHONEBOOK_TEXT_LENGTH, buffer[3]), false, GSM_AlcatelAlphabet);
876 } else if(Priv->ProtocolVersion == V_1_1 && (buffer[4] & 0x80)) { 879 } else if(Priv->ProtocolVersion == V_1_1 && (buffer[4] & 0x80)) {
877 memcpy(Priv->ReturnString, buffer + 5, buffer[3]); 880 memcpy(Priv->ReturnString, buffer + 5, buffer[3]);
878 Priv->ReturnString[buffer[3] + 1] = 0; 881 Priv->ReturnString[buffer[3] + 1] = 0;
879 Priv->ReturnString[buffer[3] + 2] = 0; 882 Priv->ReturnString[buffer[3] + 2] = 0;
880 ReverseUnicodeString(Priv->ReturnString); 883 ReverseUnicodeString(Priv->ReturnString);
881 } else { 884 } else {
882 DecodeDefault( Priv->ReturnString, buffer + 4, MIN(GSM_PHONEBOOK_TEXT_LENGTH, buffer[3]), false, GSM_AlcatelAlphabet); 885 DecodeDefault( Priv->ReturnString, buffer + 4, MIN(GSM_PHONEBOOK_TEXT_LENGTH, buffer[3]), false, GSM_AlcatelAlphabet);
883 } 886 }
884 } else if (buffer[1] == 0x03 && buffer[2] == 0x3B) { 887 } else if (buffer[1] == 0x03 && buffer[2] == 0x3B) {
885 /* boolean */ 888 /* boolean */
886 Priv->ReturnType = Alcatel_bool; 889 Priv->ReturnType = Alcatel_bool;
887 Priv->ReturnInt = buffer[3]; 890 Priv->ReturnInt = buffer[3];
888 } else if (buffer[1] == 0x02 && buffer[2] == 0x3A) { 891 } else if (buffer[1] == 0x02 && buffer[2] == 0x3A) {
889 /* integer */ 892 /* integer */
890 Priv->ReturnType = Alcatel_int; 893 Priv->ReturnType = Alcatel_int;
891 Priv->ReturnInt = buffer[6] + (buffer[5] << 8) + (buffer[4] << 16) + (buffer[3] << 24); 894 Priv->ReturnInt = buffer[6] + (buffer[5] << 8) + (buffer[4] << 16) + (buffer[3] << 24);
892 } else if (buffer[1] == 0x04 && buffer[2] == 0x38) { 895 } else if (buffer[1] == 0x04 && buffer[2] == 0x38) {
893 /* enumeration */ 896 /* enumeration */
894 Priv->ReturnType = Alcatel_enum; 897 Priv->ReturnType = Alcatel_enum;
895 Priv->ReturnInt = buffer[3]; 898 Priv->ReturnInt = buffer[3];
896 } else if (buffer[1] == 0x00 && buffer[2] == 0x38) { 899 } else if (buffer[1] == 0x00 && buffer[2] == 0x38) {
897 /* byte */ 900 /* byte */
898 Priv->ReturnType = Alcatel_byte; 901 Priv->ReturnType = Alcatel_byte;
899 Priv->ReturnInt = buffer[3]; 902 Priv->ReturnInt = buffer[3];
900 } else { 903 } else {
901 smprintf(s, "WARNING: Uknown data type received (%02X,%02X)\n", buffer[1], buffer[2]); 904 smprintf(s, "WARNING: Uknown data type received (%02X,%02X)\n", buffer[1], buffer[2]);
902 return ERR_UNKNOWNRESPONSE; 905 return ERR_UNKNOWNRESPONSE;
903 } 906 }
904 return ERR_NONE; 907 return ERR_NONE;
905} 908}
906 909
907static GSM_Error ALCATEL_GetFieldValue(GSM_StateMachine *s, int id, int field) 910static GSM_Error ALCATEL_GetFieldValue(GSM_StateMachine *s, int id, int field)
908{ 911{
909 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 912 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
910 GSM_Error error; 913 GSM_Error error;
911 unsigned char buffer[] = 914 unsigned char buffer[] =
912 {0x00, 0x04, 915 {0x00, 0x04,
913 0x00, /* type */ 916 0x00, /* type */
914 0x1f, 0x01, 917 0x1f, 0x01,
915 0x00, 0x00, 0x00, 0x00,/* here follows 4byte id */ 918 0x00, 0x00, 0x00, 0x00,/* here follows 4byte id */
916 0x00}; /* field */ 919 0x00}; /* field */
917 920
918 smprintf(s,"Reading item value (%08x.%02x)\n", id, field); 921 smprintf(s,"Reading item value (%08x.%02x)\n", id, field);
919 922
920 switch (Priv->BinaryType) { 923 switch (Priv->BinaryType) {
921 case TypeCalendar: 924 case TypeCalendar:
922 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR; 925 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR;
923 break; 926 break;
924 case TypeContacts: 927 case TypeContacts:
925 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 928 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
926 break; 929 break;
927 case TypeToDo: 930 case TypeToDo:
928 buffer[2] = ALCATEL_SYNC_TYPE_TODO; 931 buffer[2] = ALCATEL_SYNC_TYPE_TODO;
929 break; 932 break;
930 } 933 }
931 934
932 buffer[5] = (id >> 24); 935 buffer[5] = (id >> 24);
933 buffer[6] = ((id >> 16) & 0xff); 936 buffer[6] = ((id >> 16) & 0xff);
934 buffer[7] = ((id >> 8) & 0xff); 937 buffer[7] = ((id >> 8) & 0xff);
935 buffer[8] = (id & 0xff); 938 buffer[8] = (id & 0xff);
936 buffer[9] = (field & 0xff); 939 buffer[9] = (field & 0xff);
937 940
938 error=GSM_WaitFor (s, buffer, 10, 0x02, ALCATEL_TIMEOUT, ID_AlcatelGetFieldValue1); 941 error=GSM_WaitFor (s, buffer, 10, 0x02, ALCATEL_TIMEOUT, ID_AlcatelGetFieldValue1);
939 if (error != ERR_NONE) return error; 942 if (error != ERR_NONE) return error;
940 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelGetFieldValue2); 943 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelGetFieldValue2);
941 if (error != ERR_NONE) return error; 944 if (error != ERR_NONE) return error;
942 945
943 return ERR_NONE; 946 return ERR_NONE;
944} 947}
945 948
946static GSM_Error ALCATEL_ReplyGetCategories(GSM_Protocol_Message msg, GSM_StateMachine *s) 949static GSM_Error ALCATEL_ReplyGetCategories(GSM_Protocol_Message msg, GSM_StateMachine *s)
947{ 950{
948 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL; 951 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL;
949 int i; 952 int i;
950 953
951 /* Did we get any category? */ 954 /* Did we get any category? */
952 if (msg.Buffer[4] == 6) { 955 if (msg.Buffer[4] == 6) {
953 Priv->CurrentCategoriesCount = 0; 956 Priv->CurrentCategoriesCount = 0;
954 return ERR_NONE; 957 return ERR_NONE;
955 } 958 }
956 if (msg.Buffer[12] > ALCATEL_MAX_CATEGORIES) { 959 if (msg.Buffer[12] > ALCATEL_MAX_CATEGORIES) {
957 smprintf(s, "WARNING: Field list truncated, you should increase ALCATEL_MAX_CATEGORIES to at least %d\n", msg.Buffer[12]); 960 smprintf(s, "WARNING: Field list truncated, you should increase ALCATEL_MAX_CATEGORIES to at least %d\n", msg.Buffer[12]);
958 Priv->CurrentCategoriesCount = ALCATEL_MAX_CATEGORIES; 961 Priv->CurrentCategoriesCount = ALCATEL_MAX_CATEGORIES;
959 } else { 962 } else {
960 Priv->CurrentCategoriesCount = msg.Buffer[12]; 963 Priv->CurrentCategoriesCount = msg.Buffer[12];
961 } 964 }
962 965
963 for (i = 0; i < Priv->CurrentCategoriesCount; i++) { 966 for (i = 0; i < Priv->CurrentCategoriesCount; i++) {
964 Priv->CurrentCategories[i] = msg.Buffer[13 + i]; 967 Priv->CurrentCategories[i] = msg.Buffer[13 + i];
965 Priv->CurrentCategoriesCache[i][0] = '\000'; 968 Priv->CurrentCategoriesCache[i][0] = '\000';
966 Priv->CurrentCategoriesCache[i][1] = '\000'; 969 Priv->CurrentCategoriesCache[i][1] = '\000';
967 } 970 }
968 971
969 return ERR_NONE; 972 return ERR_NONE;
970} 973}
971 974
972static GSM_Error ALCATEL_GetAvailableCategoryIds(GSM_StateMachine *s) { 975static GSM_Error ALCATEL_GetAvailableCategoryIds(GSM_StateMachine *s) {
973 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 976 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
974 GSM_Error error; 977 GSM_Error error;
975 int i; 978 int i;
976 unsigned char buffer[] = 979 unsigned char buffer[] =
977 {0x00, 0x04, 980 {0x00, 0x04,
978 0x00 /*type */, 981 0x00 /*type */,
979 0x0b, 982 0x0b,
980 0x00 /* list */}; 983 0x00 /* list */};
981 984
982 if (Priv->BinaryState != StateSession) return ERR_UNKNOWN; 985 if (Priv->BinaryState != StateSession) return ERR_UNKNOWN;
983 if (Priv->CurrentCategoriesType == Priv->BinaryType) return ERR_NONE; 986 if (Priv->CurrentCategoriesType == Priv->BinaryType) return ERR_NONE;
984 switch (Priv->BinaryType) { 987 switch (Priv->BinaryType) {
985 case TypeContacts: 988 case TypeContacts:
986 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 989 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
987 buffer[4] = ALCATEL_LIST_CONTACTS_CAT; 990 buffer[4] = ALCATEL_LIST_CONTACTS_CAT;
988 break; 991 break;
989 case TypeToDo: 992 case TypeToDo:
990 buffer[2] = ALCATEL_SYNC_TYPE_TODO; 993 buffer[2] = ALCATEL_SYNC_TYPE_TODO;
991 buffer[4] = ALCATEL_LIST_TODO_CAT; 994 buffer[4] = ALCATEL_LIST_TODO_CAT;
992 break; 995 break;
993 default: 996 default:
994 return ERR_NOTSUPPORTED; 997 return ERR_NOTSUPPORTED;
995 } 998 }
996 999
997 Priv->CurrentCategoriesType = Priv->BinaryType; 1000 Priv->CurrentCategoriesType = Priv->BinaryType;
998 1001
999 smprintf(s,"Reading category list\n"); 1002 smprintf(s,"Reading category list\n");
1000 1003
1001 error=GSM_WaitFor (s, buffer, 5, 0x02, ALCATEL_TIMEOUT, ID_AlcatelGetCategories1); 1004 error=GSM_WaitFor (s, buffer, 5, 0x02, ALCATEL_TIMEOUT, ID_AlcatelGetCategories1);
1002 if (error != ERR_NONE) return error; 1005 if (error != ERR_NONE) return error;
1003 1006
1004 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelGetCategories2); 1007 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelGetCategories2);
1005 if (error != ERR_NONE) return error; 1008 if (error != ERR_NONE) return error;
1006 1009
1007 i = 0; 1010 i = 0;
1008 smprintf(s,"Received %d ids: ", Priv->CurrentCategoriesCount); 1011 smprintf(s,"Received %d ids: ", Priv->CurrentCategoriesCount);
1009 for (i=0; i < Priv->CurrentCategoriesCount; i++) { 1012 for (i=0; i < Priv->CurrentCategoriesCount; i++) {
1010 smprintf(s,"%i ", Priv->CurrentCategories[i]); 1013 smprintf(s,"%i ", Priv->CurrentCategories[i]);
1011 } 1014 }
1012 smprintf(s,"\n"); 1015 smprintf(s,"\n");
1013 1016
1014 return ERR_NONE; 1017 return ERR_NONE;
1015} 1018}
1016 1019
1017static GSM_Error ALCATEL_IsCategoryIdAvailable(GSM_StateMachine *s, int id) { 1020static GSM_Error ALCATEL_IsCategoryIdAvailable(GSM_StateMachine *s, int id) {
1018 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 1021 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
1019 int i = 0; 1022 int i = 0;
1020 1023
1021 if (Priv->CurrentCategoriesType != Priv->BinaryType) return ERR_UNKNOWN; 1024 if (Priv->CurrentCategoriesType != Priv->BinaryType) return ERR_UNKNOWN;
1022 1025
1023 for (i = 0; i< Priv->CurrentCategoriesCount; i++) { 1026 for (i = 0; i< Priv->CurrentCategoriesCount; i++) {
1024 if (Priv->CurrentCategories[i] == id) return ERR_NONE; 1027 if (Priv->CurrentCategories[i] == id) return ERR_NONE;
1025 } 1028 }
1026 return ERR_EMPTY; 1029 return ERR_EMPTY;
1027} 1030}
1028 1031
1029static GSM_Error ALCATEL_ReplyAddCategoryText(GSM_Protocol_Message msg, GSM_StateMachine *s) 1032static GSM_Error ALCATEL_ReplyAddCategoryText(GSM_Protocol_Message msg, GSM_StateMachine *s)
1030{ 1033{
1031 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL; 1034 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL;
1032 1035
1033 Priv->ReturnInt = msg.Buffer[12]; 1036 Priv->ReturnInt = msg.Buffer[12];
1034 1037
1035 return ERR_NONE; 1038 return ERR_NONE;
1036} 1039}
1037 1040
1038static GSM_Error ALCATEL_AddCategoryText(GSM_StateMachine *s, const unsigned char *str) { 1041static GSM_Error ALCATEL_AddCategoryText(GSM_StateMachine *s, const unsigned char *str) {
1039 unsigned char buffer[200] = {0x00, 0x04, 0x00 /*type*/, 0x0d, 0x00 /*list*/, 0x0b }; 1042 unsigned char buffer[200] = {0x00, 0x04, 0x00 /*type*/, 0x0d, 0x00 /*list*/, 0x0b };
1040 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 1043 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
1041 GSM_Error error; 1044 GSM_Error error;
1042 int len; 1045 int len;
1043 1046
1044 smprintf(s,"Creating category\n"); 1047 smprintf(s,"Creating category\n");
1045 len = UnicodeLength(str); 1048 len = UnicodeLength(str);
1046 EncodeDefault(buffer + 8, str, &len, true, GSM_AlcatelAlphabet); 1049 EncodeDefault(buffer + 8, str, &len, true, GSM_AlcatelAlphabet);
1047 buffer[6] = len + 1; 1050 buffer[6] = len + 1;
1048 buffer[7] = len; 1051 buffer[7] = len;
1049 1052
1050 switch (Priv->BinaryType) { 1053 switch (Priv->BinaryType) {
1051 case TypeContacts: 1054 case TypeContacts:
1052 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 1055 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
1053 buffer[4] = ALCATEL_LIST_CONTACTS_CAT; 1056 buffer[4] = ALCATEL_LIST_CONTACTS_CAT;
1054 break; 1057 break;
1055 case TypeToDo: 1058 case TypeToDo:
1056 buffer[2] = ALCATEL_SYNC_TYPE_TODO; 1059 buffer[2] = ALCATEL_SYNC_TYPE_TODO;
1057 buffer[4] = ALCATEL_LIST_TODO_CAT; 1060 buffer[4] = ALCATEL_LIST_TODO_CAT;
1058 break; 1061 break;
1059 default: 1062 default:
1060 return ERR_NOTSUPPORTED; 1063 return ERR_NOTSUPPORTED;
1061 } 1064 }
1062 1065
1063 error=GSM_WaitFor (s, buffer, 8 + len, 0x02, ALCATEL_TIMEOUT, ID_AlcatelAddCategoryText1); 1066 error=GSM_WaitFor (s, buffer, 8 + len, 0x02, ALCATEL_TIMEOUT, ID_AlcatelAddCategoryText1);
1064 if (error != ERR_NONE) return error; 1067 if (error != ERR_NONE) return error;
1065 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelAddCategoryText2); 1068 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelAddCategoryText2);
1066 if (error != ERR_NONE) return error; 1069 if (error != ERR_NONE) return error;
1067 1070
1068 /* Refresh list */ 1071 /* Refresh list */
1069 Priv->CurrentCategoriesType = 0; 1072 Priv->CurrentCategoriesType = 0;
1070 return ALCATEL_GetAvailableCategoryIds(s); 1073 return ALCATEL_GetAvailableCategoryIds(s);
1071} 1074}
1072 1075
1073static GSM_Error ALCATEL_ReplyGetCategoryText(GSM_Protocol_Message msg, GSM_StateMachine *s) 1076static GSM_Error ALCATEL_ReplyGetCategoryText(GSM_Protocol_Message msg, GSM_StateMachine *s)
1074{ 1077{
1075 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL; 1078 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL;
1076 int len; 1079 int len;
1077 1080
1078 len = msg.Buffer[14]; 1081 len = msg.Buffer[14];
1079 if (len > GSM_MAX_CATEGORY_NAME_LENGTH) { 1082 if (len > GSM_MAX_CATEGORY_NAME_LENGTH) {
1080 smprintf(s, "WARNING: Category name truncated, you should increase GSM_MAX_CATEGORY_NAME_LENGTH to at least %d\n", len); 1083 smprintf(s, "WARNING: Category name truncated, you should increase GSM_MAX_CATEGORY_NAME_LENGTH to at least %d\n", len);
1081 } 1084 }
1082 if (Priv->ProtocolVersion == V_1_0) { 1085 if (Priv->ProtocolVersion == V_1_0) {
1083 DecodeDefault( Priv->ReturnString, msg.Buffer + 15, MIN(GSM_MAX_CATEGORY_NAME_LENGTH, len), false, GSM_AlcatelAlphabet); 1086 DecodeDefault( Priv->ReturnString, msg.Buffer + 15, MIN(GSM_MAX_CATEGORY_NAME_LENGTH, len), false, GSM_AlcatelAlphabet);
1084 } else if(Priv->ProtocolVersion == V_1_1 && (msg.Buffer[15] & 0x80)) { 1087 } else if(Priv->ProtocolVersion == V_1_1 && (msg.Buffer[15] & 0x80)) {
1085 memcpy(Priv->ReturnString, msg.Buffer + 16, len); 1088 memcpy(Priv->ReturnString, msg.Buffer + 16, len);
1086 Priv->ReturnString[len + 1] = 0; 1089 Priv->ReturnString[len + 1] = 0;
1087 Priv->ReturnString[len + 2] = 0; 1090 Priv->ReturnString[len + 2] = 0;
1088 ReverseUnicodeString(Priv->ReturnString); 1091 ReverseUnicodeString(Priv->ReturnString);
1089 } else { 1092 } else {
1090 DecodeDefault( Priv->ReturnString, msg.Buffer + 15, MIN(GSM_MAX_CATEGORY_NAME_LENGTH, len), false, GSM_AlcatelAlphabet); 1093 DecodeDefault( Priv->ReturnString, msg.Buffer + 15, MIN(GSM_MAX_CATEGORY_NAME_LENGTH, len), false, GSM_AlcatelAlphabet);
1091 } 1094 }
1092 return ERR_NONE; 1095 return ERR_NONE;
1093} 1096}
1094 1097
1095static GSM_Error ALCATEL_GetCategoryText(GSM_StateMachine *s, int id) { 1098static GSM_Error ALCATEL_GetCategoryText(GSM_StateMachine *s, int id) {
1096 unsigned char buffer[] = {0x00, 0x04, 0x00 /*type*/, 0x0c, 0x00 /*list*/, 0x0A, 0x01, 0x00 /*item*/ }; 1099 unsigned char buffer[] = {0x00, 0x04, 0x00 /*type*/, 0x0c, 0x00 /*list*/, 0x0A, 0x01, 0x00 /*item*/ };
1097 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 1100 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
1098 GSM_Error error; 1101 GSM_Error error;
1099 1102
1100 if (Priv->CurrentCategoriesCache[id][0] != '\000' || Priv->CurrentCategoriesCache[id][1] != '\000') { 1103 if (Priv->CurrentCategoriesCache[id][0] != '\000' || Priv->CurrentCategoriesCache[id][1] != '\000') {
1101 CopyUnicodeString(Priv->ReturnString, Priv->CurrentCategoriesCache[id]); 1104 CopyUnicodeString(Priv->ReturnString, Priv->CurrentCategoriesCache[id]);
1102 return ERR_NONE; 1105 return ERR_NONE;
1103 } 1106 }
1104 1107
1105 smprintf(s,"Reading category %d\n", id); 1108 smprintf(s,"Reading category %d\n", id);
1106 1109
1107 switch (Priv->BinaryType) { 1110 switch (Priv->BinaryType) {
1108 case TypeContacts: 1111 case TypeContacts:
1109 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 1112 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
1110 buffer[4] = ALCATEL_LIST_CONTACTS_CAT; 1113 buffer[4] = ALCATEL_LIST_CONTACTS_CAT;
1111 break; 1114 break;
1112 case TypeToDo: 1115 case TypeToDo:
1113 buffer[2] = ALCATEL_SYNC_TYPE_TODO; 1116 buffer[2] = ALCATEL_SYNC_TYPE_TODO;
1114 buffer[4] = ALCATEL_LIST_TODO_CAT; 1117 buffer[4] = ALCATEL_LIST_TODO_CAT;
1115 break; 1118 break;
1116 default: 1119 default:
1117 return ERR_NOTSUPPORTED; 1120 return ERR_NOTSUPPORTED;
1118 } 1121 }
1119 1122
1120 buffer[7] = (id & 0xff); 1123 buffer[7] = (id & 0xff);
1121 1124
1122 error=GSM_WaitFor (s, buffer, 8, 0x02, ALCATEL_TIMEOUT, ID_AlcatelGetCategoryText1); 1125 error=GSM_WaitFor (s, buffer, 8, 0x02, ALCATEL_TIMEOUT, ID_AlcatelGetCategoryText1);
1123 if (error != ERR_NONE) return error; 1126 if (error != ERR_NONE) return error;
1124 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelGetCategoryText2); 1127 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelGetCategoryText2);
1125 if (error != ERR_NONE) return error; 1128 if (error != ERR_NONE) return error;
1126 1129
1127 CopyUnicodeString(Priv->CurrentCategoriesCache[id], Priv->ReturnString); 1130 CopyUnicodeString(Priv->CurrentCategoriesCache[id], Priv->ReturnString);
1128 1131
1129 return ERR_NONE; 1132 return ERR_NONE;
1130} 1133}
1131 1134
1132static GSM_Error ALCATEL_DeleteField(GSM_StateMachine *s, int id, int field) { 1135static GSM_Error ALCATEL_DeleteField(GSM_StateMachine *s, int id, int field) {
1133 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 1136 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
1134 GSM_Error error; 1137 GSM_Error error;
1135 unsigned char buffer[] = 1138 unsigned char buffer[] =
1136 {0x00, 0x04, 1139 {0x00, 0x04,
1137 0x00, /* type */ 1140 0x00, /* type */
1138 0x26, 0x01, 1141 0x26, 0x01,
1139 0x00, 0x00, 0x00, 0x00,/* here follows 4byte id */ 1142 0x00, 0x00, 0x00, 0x00,/* here follows 4byte id */
1140 0x65, 0x01, 1143 0x65, 0x01,
1141 0x00, /* field */ 1144 0x00, /* field */
1142 0x01}; 1145 0x01};
1143 1146
1144 smprintf(s,"Deleting field (%08x.%02x)\n", id, field); 1147 smprintf(s,"Deleting field (%08x.%02x)\n", id, field);
1145 1148
1146 switch (Priv->BinaryType) { 1149 switch (Priv->BinaryType) {
1147 case TypeCalendar: 1150 case TypeCalendar:
1148 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR; 1151 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR;
1149 break; 1152 break;
1150 case TypeContacts: 1153 case TypeContacts:
1151 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 1154 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
1152 break; 1155 break;
1153 case TypeToDo: 1156 case TypeToDo:
1154 buffer[2] = ALCATEL_SYNC_TYPE_TODO; 1157 buffer[2] = ALCATEL_SYNC_TYPE_TODO;
1155 break; 1158 break;
1156 } 1159 }
1157 1160
1158 buffer[5] = (id >> 24); 1161 buffer[5] = (id >> 24);
1159 buffer[6] = ((id >> 16) & 0xff); 1162 buffer[6] = ((id >> 16) & 0xff);
1160 buffer[7] = ((id >> 8) & 0xff); 1163 buffer[7] = ((id >> 8) & 0xff);
1161 buffer[8] = (id & 0xff); 1164 buffer[8] = (id & 0xff);
1162 buffer[11] = (field & 0xff); 1165 buffer[11] = (field & 0xff);
1163 1166
1164 error=GSM_WaitFor (s, buffer, 13, 0x02, ALCATEL_TIMEOUT, ID_AlcatelDeleteField); 1167 error=GSM_WaitFor (s, buffer, 13, 0x02, ALCATEL_TIMEOUT, ID_AlcatelDeleteField);
1165 if (error != ERR_NONE) return error; 1168 if (error != ERR_NONE) return error;
1166 1169
1167 return ERR_NONE; 1170 return ERR_NONE;
1168} 1171}
1169 1172
1170static GSM_Error ALCATEL_DeleteItem(GSM_StateMachine *s, int id) { 1173static GSM_Error ALCATEL_DeleteItem(GSM_StateMachine *s, int id) {
1171 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 1174 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
1172 GSM_Error error; 1175 GSM_Error error;
1173 unsigned char buffer[] = 1176 unsigned char buffer[] =
1174 {0x00, 0x04, 1177 {0x00, 0x04,
1175 0x00, /* type */ 1178 0x00, /* type */
1176 0x27, 0x01, 1179 0x27, 0x01,
1177 0x00, 0x00, 0x00, 0x00,/* here follows 4byte id */ 1180 0x00, 0x00, 0x00, 0x00,/* here follows 4byte id */
1178 0x42}; 1181 0x42};
1179 1182
1180 smprintf(s,"Deleting item (%08x)\n", id); 1183 smprintf(s,"Deleting item (%08x)\n", id);
1181 1184
1182 switch (Priv->BinaryType) { 1185 switch (Priv->BinaryType) {
1183 case TypeCalendar: 1186 case TypeCalendar:
1184 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR; 1187 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR;
1185 break; 1188 break;
1186 case TypeContacts: 1189 case TypeContacts:
1187 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 1190 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
1188 break; 1191 break;
1189 case TypeToDo: 1192 case TypeToDo:
1190 buffer[2] = ALCATEL_SYNC_TYPE_TODO; 1193 buffer[2] = ALCATEL_SYNC_TYPE_TODO;
1191 break; 1194 break;
1192 } 1195 }
1193 1196
1194 buffer[5] = (id >> 24); 1197 buffer[5] = (id >> 24);
1195 buffer[6] = ((id >> 16) & 0xff); 1198 buffer[6] = ((id >> 16) & 0xff);
1196 buffer[7] = ((id >> 8) & 0xff); 1199 buffer[7] = ((id >> 8) & 0xff);
1197 buffer[8] = (id & 0xff); 1200 buffer[8] = (id & 0xff);
1198 1201
1199 error=GSM_WaitFor (s, buffer, 10, 0x02, ALCATEL_TIMEOUT, ID_AlcatelDeleteItem1); 1202 error=GSM_WaitFor (s, buffer, 10, 0x02, ALCATEL_TIMEOUT, ID_AlcatelDeleteItem1);
1200 if (error != ERR_NONE) return error; 1203 if (error != ERR_NONE) return error;
1201 1204
1202 error=GSM_WaitFor (s, 0, 0, 0x0, ALCATEL_TIMEOUT, ID_AlcatelDeleteItem2); 1205 error=GSM_WaitFor (s, 0, 0, 0x0, ALCATEL_TIMEOUT, ID_AlcatelDeleteItem2);
1203 if (error != ERR_NONE) return error; 1206 if (error != ERR_NONE) return error;
1204 1207
1205 return ERR_NONE; 1208 return ERR_NONE;
1206} 1209}
1207 1210
1208static GSM_Error ALCATEL_ReplyDeleteItem(GSM_Protocol_Message msg, GSM_StateMachine *s) 1211static GSM_Error ALCATEL_ReplyDeleteItem(GSM_Protocol_Message msg, GSM_StateMachine *s)
1209{ 1212{
1210 if (msg.Buffer[8] != 0x25) return ERR_UNKNOWNRESPONSE; 1213 if (msg.Buffer[8] != 0x25) return ERR_UNKNOWNRESPONSE;
1211 return ERR_NONE; 1214 return ERR_NONE;
1212} 1215}
1213 1216
1214static GSM_Error ALCATEL_BuildWriteBuffer(unsigned char * buffer, GSM_Alcatel_FieldType type, int field, void *data) { 1217static GSM_Error ALCATEL_BuildWriteBuffer(unsigned char * buffer, GSM_Alcatel_FieldType type, int field, void *data) {
1215 int len; 1218 int len;
1216 1219
1217 buffer[1] = field & 0xff; 1220 buffer[1] = field & 0xff;
1218 1221
1219 switch(type) { 1222 switch(type) {
1220 case Alcatel_date: 1223 case Alcatel_date:
1221 if (!CheckDate((GSM_DateTime *)data)) return ERR_INVALIDDATETIME; 1224 if (!CheckDate((GSM_DateTime *)data)) return ERR_INVALIDDATETIME;
1222 1225
1223 buffer[3] = 0x05; 1226 buffer[3] = 0x05;
1224 buffer[4] = 0x67; 1227 buffer[4] = 0x67;
1225 1228
1226 buffer[0] = 0x09; 1229 buffer[0] = 0x09;
1227 buffer[5] = 0x04; 1230 buffer[5] = 0x04;
1228 buffer[6] = ((GSM_DateTime *)data)->Day & 0xff; 1231 buffer[6] = ((GSM_DateTime *)data)->Day & 0xff;
1229 buffer[7] = ((GSM_DateTime *)data)->Month & 0xff; 1232 buffer[7] = ((GSM_DateTime *)data)->Month & 0xff;
1230 buffer[8] = ((GSM_DateTime *)data)->Year >> 8; 1233 buffer[8] = ((GSM_DateTime *)data)->Year >> 8;
1231 buffer[9] = ((GSM_DateTime *)data)->Year & 0xff; 1234 buffer[9] = ((GSM_DateTime *)data)->Year & 0xff;
1232 buffer[10] = 0x00; 1235 buffer[10] = 0x00;
1233 break; 1236 break;
1234 case Alcatel_time: 1237 case Alcatel_time:
1235 if (!CheckTime((GSM_DateTime *)data)) return ERR_INVALIDDATETIME; 1238 if (!CheckTime((GSM_DateTime *)data)) return ERR_INVALIDDATETIME;
1236 1239
1237 buffer[3] = 0x06; 1240 buffer[3] = 0x06;
1238 buffer[4] = 0x68; 1241 buffer[4] = 0x68;
1239 1242
1240 buffer[0] = 0x08; 1243 buffer[0] = 0x08;
1241 buffer[5] = 0x03; 1244 buffer[5] = 0x03;
1242 buffer[6] = ((GSM_DateTime *)data)->Hour & 0xff; 1245 buffer[6] = ((GSM_DateTime *)data)->Hour & 0xff;
1243 buffer[7] = ((GSM_DateTime *)data)->Minute & 0xff; 1246 buffer[7] = ((GSM_DateTime *)data)->Minute & 0xff;
1244 buffer[8] = ((GSM_DateTime *)data)->Second & 0xff; 1247 buffer[8] = ((GSM_DateTime *)data)->Second & 0xff;
1245 buffer[9] = 0x00; 1248 buffer[9] = 0x00;
1246 break; 1249 break;
1247 case Alcatel_string: 1250 case Alcatel_string:
1248 buffer[3] = 0x08; 1251 buffer[3] = 0x08;
1249 buffer[4] = 0x3c; 1252 buffer[4] = 0x3c;
1250 1253
1251 len = MIN(UnicodeLength((char *)data),62); 1254 len = MIN(UnicodeLength((char *)data),62);
1252 EncodeDefault(buffer + 6, (char *)data, &len, true, GSM_AlcatelAlphabet); 1255 EncodeDefault(buffer + 6, (char *)data, &len, true, GSM_AlcatelAlphabet);
1253 buffer[5] = len; 1256 buffer[5] = len;
1254 buffer[0] = 5 + len; 1257 buffer[0] = 5 + len;
1255 buffer[6 + len] = 0x00; 1258 buffer[6 + len] = 0x00;
1256 break; 1259 break;
1257 case Alcatel_phone: 1260 case Alcatel_phone:
1258 buffer[3] = 0x07; 1261 buffer[3] = 0x07;
1259 buffer[4] = 0x3c; 1262 buffer[4] = 0x3c;
1260 1263
1261 len = MIN(UnicodeLength((char *)data),50); 1264 len = MIN(UnicodeLength((char *)data),50);
1262 EncodeDefault(buffer + 6, (char *)data, &len, true, GSM_AlcatelAlphabet); 1265 EncodeDefault(buffer + 6, (char *)data, &len, true, GSM_AlcatelAlphabet);
1263 buffer[5] = len; 1266 buffer[5] = len;
1264 buffer[0] = 5 + len; 1267 buffer[0] = 5 + len;
1265 buffer[6 + len] = 0x00; 1268 buffer[6 + len] = 0x00;
1266 break; 1269 break;
1267 case Alcatel_enum: 1270 case Alcatel_enum:
1268 buffer[3] = 0x04; 1271 buffer[3] = 0x04;
1269 buffer[4] = 0x38; 1272 buffer[4] = 0x38;
1270 1273
1271 buffer[0] = 0x05; 1274 buffer[0] = 0x05;
1272 buffer[5] = *(int *)data & 0xff; 1275 buffer[5] = *(int *)data & 0xff;
1273 buffer[6] = 0x00; 1276 buffer[6] = 0x00;
1274 break; 1277 break;
1275 case Alcatel_bool: 1278 case Alcatel_bool:
1276 buffer[3] = 0x03; 1279 buffer[3] = 0x03;
1277 buffer[4] = 0x3b; 1280 buffer[4] = 0x3b;
1278 1281
1279 buffer[0] = 0x05; 1282 buffer[0] = 0x05;
1280 buffer[5] = *(int *)data & 0xff; 1283 buffer[5] = *(int *)data & 0xff;
1281 buffer[6] = 0x00; 1284 buffer[6] = 0x00;
1282 break; 1285 break;
1283 case Alcatel_int: 1286 case Alcatel_int:
1284 buffer[3] = 0x02; 1287 buffer[3] = 0x02;
1285 buffer[4] = 0x3a; 1288 buffer[4] = 0x3a;
1286 1289
1287 buffer[0] = 0x08; 1290 buffer[0] = 0x08;
1288 buffer[5] = *(unsigned int *)data >> 24; 1291 buffer[5] = *(unsigned int *)data >> 24;
1289 buffer[6] = (*(unsigned int *)data >> 16) & 0xff; 1292 buffer[6] = (*(unsigned int *)data >> 16) & 0xff;
1290 buffer[7] = (*(unsigned int *)data >> 8) & 0xff; 1293 buffer[7] = (*(unsigned int *)data >> 8) & 0xff;
1291 buffer[8] = *(unsigned int *)data & 0xff; 1294 buffer[8] = *(unsigned int *)data & 0xff;
1292 buffer[9] = 0x00; 1295 buffer[9] = 0x00;
1293 break; 1296 break;
1294 case Alcatel_byte: 1297 case Alcatel_byte:
1295 buffer[3] = 0x00; 1298 buffer[3] = 0x00;
1296 buffer[4] = 0x38; 1299 buffer[4] = 0x38;
1297 1300
1298 buffer[0] = 0x05; 1301 buffer[0] = 0x05;
1299 buffer[5] = *(int *)data & 0xff; 1302 buffer[5] = *(int *)data & 0xff;
1300 buffer[6] = 0x00; 1303 buffer[6] = 0x00;
1301 break; 1304 break;
1302 } 1305 }
1303 return ERR_NONE; 1306 return ERR_NONE;
1304} 1307}
1305 1308
1306static GSM_Error ALCATEL_CreateField(GSM_StateMachine *s, GSM_Alcatel_FieldType type, int field, void *data) { 1309static GSM_Error ALCATEL_CreateField(GSM_StateMachine *s, GSM_Alcatel_FieldType type, int field, void *data) {
1307 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 1310 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
1308 GSM_Error error; 1311 GSM_Error error;
1309 unsigned char buffer[200] = 1312 unsigned char buffer[200] =
1310 {0x00, 0x04, 1313 {0x00, 0x04,
1311 0x00, /* type */ 1314 0x00, /* type */
1312 0x25, 0x01, 0x65, 1315 0x25, 0x01, 0x65,
1313 0x00, /* length of remaining part */ 1316 0x00, /* length of remaining part */
1314 0x00, /* field */ 1317 0x00, /* field */
1315 0x37}; /* data follows here */ 1318 0x37}; /* data follows here */
1316 1319
1317 smprintf(s,"Creating field (%02x)\n", field); 1320 smprintf(s,"Creating field (%02x)\n", field);
1318 1321
1319 switch (Priv->BinaryType) { 1322 switch (Priv->BinaryType) {
1320 case TypeCalendar: 1323 case TypeCalendar:
1321 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR; 1324 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR;
1322 break; 1325 break;
1323 case TypeContacts: 1326 case TypeContacts:
1324 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 1327 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
1325 break; 1328 break;
1326 case TypeToDo: 1329 case TypeToDo:
1327 buffer[2] = ALCATEL_SYNC_TYPE_TODO; 1330 buffer[2] = ALCATEL_SYNC_TYPE_TODO;
1328 break; 1331 break;
1329 } 1332 }
1330 error = ALCATEL_BuildWriteBuffer(buffer + 6, type, field, data); 1333 error = ALCATEL_BuildWriteBuffer(buffer + 6, type, field, data);
1331 if (error != ERR_NONE) return error; 1334 if (error != ERR_NONE) return error;
1332 1335
1333 error = GSM_WaitFor (s, buffer, 8 + buffer[6], 0x02, ALCATEL_TIMEOUT, ID_AlcatelCreateField); 1336 error = GSM_WaitFor (s, buffer, 8 + buffer[6], 0x02, ALCATEL_TIMEOUT, ID_AlcatelCreateField);
1334 if (error != ERR_NONE) return error; 1337 if (error != ERR_NONE) return error;
1335 1338
1336 return ERR_NONE; 1339 return ERR_NONE;
1337} 1340}
1338 1341
1339static GSM_Error ALCATEL_UpdateField(GSM_StateMachine *s, GSM_Alcatel_FieldType type, int id, int field, void *data) { 1342static GSM_Error ALCATEL_UpdateField(GSM_StateMachine *s, GSM_Alcatel_FieldType type, int id, int field, void *data) {
1340 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 1343 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
1341 GSM_Error error; 1344 GSM_Error error;
1342 unsigned char buffer[200] = 1345 unsigned char buffer[200] =
1343 {0x00, 0x04, 1346 {0x00, 0x04,
1344 0x00, /* type */ 1347 0x00, /* type */
1345 0x26, 0x01, 1348 0x26, 0x01,
1346 0x00, 0x00, 0x00, 0x00,/* id */ 1349 0x00, 0x00, 0x00, 0x00,/* id */
1347 0x65, 1350 0x65,
1348 0x00, /* length of remaining part */ 1351 0x00, /* length of remaining part */
1349 0x00, /* field */ 1352 0x00, /* field */
1350 0x37}; /* data follows here */ 1353 0x37}; /* data follows here */
1351 1354
1352 smprintf(s,"Updating field (%08x.%02x)\n", id, field); 1355 smprintf(s,"Updating field (%08x.%02x)\n", id, field);
1353 1356
1354 buffer[5] = (id >> 24); 1357 buffer[5] = (id >> 24);
1355 buffer[6] = ((id >> 16) & 0xff); 1358 buffer[6] = ((id >> 16) & 0xff);
1356 buffer[7] = ((id >> 8) & 0xff); 1359 buffer[7] = ((id >> 8) & 0xff);
1357 buffer[8] = (id & 0xff); 1360 buffer[8] = (id & 0xff);
1358 1361
1359 switch (Priv->BinaryType) { 1362 switch (Priv->BinaryType) {
1360 case TypeCalendar: 1363 case TypeCalendar:
1361 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR; 1364 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR;
1362 break; 1365 break;
1363 case TypeContacts: 1366 case TypeContacts:
1364 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 1367 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
1365 break; 1368 break;
1366 case TypeToDo: 1369 case TypeToDo:
1367 buffer[2] = ALCATEL_SYNC_TYPE_TODO; 1370 buffer[2] = ALCATEL_SYNC_TYPE_TODO;
1368 break; 1371 break;
1369 } 1372 }
1370 error = ALCATEL_BuildWriteBuffer(buffer + 10, type, field, data); 1373 error = ALCATEL_BuildWriteBuffer(buffer + 10, type, field, data);
1371 if (error != ERR_NONE) return error; 1374 if (error != ERR_NONE) return error;
1372 1375
1373 error = GSM_WaitFor (s, buffer, 12 + buffer[10], 0x02, ALCATEL_TIMEOUT, ID_AlcatelUpdateField); 1376 error = GSM_WaitFor (s, buffer, 12 + buffer[10], 0x02, ALCATEL_TIMEOUT, ID_AlcatelUpdateField);
1374 if (error != ERR_NONE) return error; 1377 if (error != ERR_NONE) return error;
1375 1378
1376 return ERR_NONE; 1379 return ERR_NONE;
1377} 1380}
1378 1381
1379static GSM_Error ALCATEL_GetManufacturer(GSM_StateMachine *s) 1382static GSM_Error ALCATEL_GetManufacturer(GSM_StateMachine *s)
1380{ 1383{
1381 strcpy(s->Phone.Data.Manufacturer, "Alcatel"); 1384 strcpy(s->Phone.Data.Manufacturer, "Alcatel");
1382 return ERR_NONE; 1385 return ERR_NONE;
1383} 1386}
1384 1387
1385static GSM_Error ALCATEL_GetIMEI (GSM_StateMachine *s) 1388static GSM_Error ALCATEL_GetIMEI (GSM_StateMachine *s)
1386{ 1389{
1387 GSM_Error error; 1390 GSM_Error error;
1388 1391
1389 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 1392 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
1390 return ATGEN_GetIMEI(s); 1393 return ATGEN_GetIMEI(s);
1391} 1394}
1392 1395
1393static GSM_Error ALCATEL_GetFirmware(GSM_StateMachine *s) 1396static GSM_Error ALCATEL_GetFirmware(GSM_StateMachine *s)
1394{ 1397{
1395 GSM_Error error; 1398 GSM_Error error;
1396 1399
1397 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 1400 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
1398 return ATGEN_GetFirmware(s); 1401 return ATGEN_GetFirmware(s);
1399} 1402}
1400 1403
1401static GSM_Error ALCATEL_GetModel(GSM_StateMachine *s) 1404static GSM_Error ALCATEL_GetModel(GSM_StateMachine *s)
1402{ 1405{
1403 GSM_Error error; 1406 GSM_Error error;
1404 1407
1405 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 1408 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
1406 return ATGEN_GetModel(s); 1409 return ATGEN_GetModel(s);
1407} 1410}
1408 1411
1409static GSM_Error ALCATEL_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time) 1412static GSM_Error ALCATEL_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
1410{ 1413{
1411 GSM_Error error; 1414 GSM_Error error;
1412 1415
1413 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 1416 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
1414 return ATGEN_GetDateTime(s, date_time); 1417 return ATGEN_GetDateTime(s, date_time);
1415} 1418}
1416 1419
1417static GSM_Error ALCATEL_GetMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry) 1420static GSM_Error ALCATEL_GetMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
1418{ 1421{
1419 GSM_Error error; 1422 GSM_Error error;
1420 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 1423 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
1421 int i; 1424 int i;
1422 int j = 0; 1425 int j = 0;
1423 1426
1424 if (entry->MemoryType == MEM_ME) { 1427 if (entry->MemoryType == MEM_ME) {
1425 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error; 1428 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error;
1426 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error; 1429 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error;
1427 if ((error = ALCATEL_IsIdAvailable(s, entry->Location))!= ERR_NONE) { 1430 if ((error = ALCATEL_IsIdAvailable(s, entry->Location))!= ERR_NONE) {
1428 entry->EntriesNum = 0; 1431 entry->EntriesNum = 0;
1429 return error; 1432 return error;
1430 } 1433 }
1431 if ((error = ALCATEL_GetFields(s, entry->Location))!= ERR_NONE) return error; 1434 if ((error = ALCATEL_GetFields(s, entry->Location))!= ERR_NONE) return error;
1432 1435
1433 entry->EntriesNum = Priv->CurrentFieldsCount; 1436 entry->EntriesNum = Priv->CurrentFieldsCount;
1434 1437
1435 for (i=0; i<Priv->CurrentFieldsCount; i++) { 1438 for (i=0; i<Priv->CurrentFieldsCount; i++) {
1436 if ((error = ALCATEL_GetFieldValue(s, entry->Location, Priv->CurrentFields[i]))!= ERR_NONE) return error; 1439 if ((error = ALCATEL_GetFieldValue(s, entry->Location, Priv->CurrentFields[i]))!= ERR_NONE) return error;
1437 entry->Entries[i].VoiceTag = 0; 1440 entry->Entries[i].VoiceTag = 0;
1438 entry->Entries[i].SMSList[0] = 0; 1441 entry->Entries[i].SMSList[0] = 0;
1439 switch (Priv->CurrentFields[i]) { 1442 switch (Priv->CurrentFields[i]) {
1440 case 0: 1443 case 0:
1441 if (Priv->ReturnType != Alcatel_string) { 1444 if (Priv->ReturnType != Alcatel_string) {
1442 smprintf(s,"WARNING: Received unexpected type %02X for field 0, ignoring\n", Priv->ReturnType); 1445 smprintf(s,"WARNING: Received unexpected type %02X for field 0, ignoring\n", Priv->ReturnType);
1443 entry->EntriesNum--; 1446 entry->EntriesNum--;
1444 j++; 1447 j++;
1445 break; 1448 break;
1446 } 1449 }
1447 entry->Entries[i - j].EntryType = PBK_Text_LastName; 1450 entry->Entries[i - j].EntryType = PBK_Text_LastName;
1448 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1451 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1449 break; 1452 break;
1450 case 1: 1453 case 1:
1451 if (Priv->ReturnType != Alcatel_string) { 1454 if (Priv->ReturnType != Alcatel_string) {
1452 smprintf(s,"WARNING: Received unexpected type %02X for field 1, ignoring\n", Priv->ReturnType); 1455 smprintf(s,"WARNING: Received unexpected type %02X for field 1, ignoring\n", Priv->ReturnType);
1453 entry->EntriesNum--; 1456 entry->EntriesNum--;
1454 j++; 1457 j++;
1455 break; 1458 break;
1456 } 1459 }
1457 entry->Entries[i - j].EntryType = PBK_Text_FirstName; 1460 entry->Entries[i - j].EntryType = PBK_Text_FirstName;
1458 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1461 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1459 break; 1462 break;
1460 case 2: 1463 case 2:
1461 if (Priv->ReturnType != Alcatel_string) { 1464 if (Priv->ReturnType != Alcatel_string) {
1462 smprintf(s,"WARNING: Received unexpected type %02X for field 2, ignoring\n", Priv->ReturnType); 1465 smprintf(s,"WARNING: Received unexpected type %02X for field 2, ignoring\n", Priv->ReturnType);
1463 entry->EntriesNum--; 1466 entry->EntriesNum--;
1464 j++; 1467 j++;
1465 break; 1468 break;
1466 } 1469 }
1467 entry->Entries[i - j].EntryType = PBK_Text_Company; 1470 entry->Entries[i - j].EntryType = PBK_Text_Company;
1468 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1471 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1469 break; 1472 break;
1470 case 3: 1473 case 3:
1471 if (Priv->ReturnType != Alcatel_string) { 1474 if (Priv->ReturnType != Alcatel_string) {
1472 smprintf(s,"WARNING: Received unexpected type %02X for field 3, ignoring\n", Priv->ReturnType); 1475 smprintf(s,"WARNING: Received unexpected type %02X for field 3, ignoring\n", Priv->ReturnType);
1473 entry->EntriesNum--; 1476 entry->EntriesNum--;
1474 j++; 1477 j++;
1475 break; 1478 break;
1476 } 1479 }
1477 entry->Entries[i - j].EntryType = PBK_Text_JobTitle; 1480 entry->Entries[i - j].EntryType = PBK_Text_JobTitle;
1478 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1481 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1479 break; 1482 break;
1480 case 4: 1483 case 4:
1481 if (Priv->ReturnType != Alcatel_string) { 1484 if (Priv->ReturnType != Alcatel_string) {
1482 smprintf(s,"WARNING: Received unexpected type %02X for field 4, ignoring\n", Priv->ReturnType); 1485 smprintf(s,"WARNING: Received unexpected type %02X for field 4, ignoring\n", Priv->ReturnType);
1483 entry->EntriesNum--; 1486 entry->EntriesNum--;
1484 j++; 1487 j++;
1485 break; 1488 break;
1486 } 1489 }
1487 entry->Entries[i - j].EntryType = PBK_Text_Note; 1490 entry->Entries[i - j].EntryType = PBK_Text_Note;
1488 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1491 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1489 break; 1492 break;
1490 case 5: 1493 case 5:
1491 if (Priv->ReturnType != Alcatel_byte) { 1494 if (Priv->ReturnType != Alcatel_byte) {
1492 smprintf(s,"WARNING: Received unexpected type %02X for field 5, ignoring\n", Priv->ReturnType); 1495 smprintf(s,"WARNING: Received unexpected type %02X for field 5, ignoring\n", Priv->ReturnType);
1493 entry->EntriesNum--; 1496 entry->EntriesNum--;
1494 j++; 1497 j++;
1495 break; 1498 break;
1496 } 1499 }
1497 entry->Entries[i - j].EntryType = PBK_Category; 1500 entry->Entries[i - j].EntryType = PBK_Category;
1498 entry->Entries[i - j].Number = Priv->ReturnInt; 1501 entry->Entries[i - j].Number = Priv->ReturnInt;
1499 break; 1502 break;
1500 case 6: 1503 case 6:
1501 if (Priv->ReturnType != Alcatel_bool) { 1504 if (Priv->ReturnType != Alcatel_bool) {
1502 smprintf(s,"WARNING: Received unexpected type %02X for field 6, ignoring\n", Priv->ReturnType); 1505 smprintf(s,"WARNING: Received unexpected type %02X for field 6, ignoring\n", Priv->ReturnType);
1503 entry->EntriesNum--; 1506 entry->EntriesNum--;
1504 j++; 1507 j++;
1505 break; 1508 break;
1506 } 1509 }
1507 entry->Entries[i - j].EntryType = PBK_Private; 1510 entry->Entries[i - j].EntryType = PBK_Private;
1508 entry->Entries[i - j].Number = Priv->ReturnInt; 1511 entry->Entries[i - j].Number = Priv->ReturnInt;
1509 break; 1512 break;
1510 case 7: 1513 case 7:
1511 if (Priv->ReturnType != Alcatel_phone) { 1514 if (Priv->ReturnType != Alcatel_phone) {
1512 smprintf(s,"WARNING: Received unexpected type %02X for field 7, ignoring\n", Priv->ReturnType); 1515 smprintf(s,"WARNING: Received unexpected type %02X for field 7, ignoring\n", Priv->ReturnType);
1513 entry->EntriesNum--; 1516 entry->EntriesNum--;
1514 j++; 1517 j++;
1515 break; 1518 break;
1516 } 1519 }
1517 entry->Entries[i - j].EntryType = PBK_Number_Work; 1520 entry->Entries[i - j].EntryType = PBK_Number_Work;
1518 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1521 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1519 break; 1522 break;
1520 case 8: 1523 case 8:
1521 if (Priv->ReturnType != Alcatel_phone) { 1524 if (Priv->ReturnType != Alcatel_phone) {
1522 smprintf(s,"WARNING: Received unexpected type %02X for field 8, ignoring\n", Priv->ReturnType); 1525 smprintf(s,"WARNING: Received unexpected type %02X for field 8, ignoring\n", Priv->ReturnType);
1523 entry->EntriesNum--; 1526 entry->EntriesNum--;
1524 j++; 1527 j++;
1525 break; 1528 break;
1526 } 1529 }
1527 entry->Entries[i - j].EntryType = PBK_Number_General; 1530 entry->Entries[i - j].EntryType = PBK_Number_General;
1528 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1531 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1529 break; 1532 break;
1530 case 9: 1533 case 9:
1531 if (Priv->ReturnType != Alcatel_phone) { 1534 if (Priv->ReturnType != Alcatel_phone) {
1532 smprintf(s,"WARNING: Received unexpected type %02X for field 9, ignoring\n", Priv->ReturnType); 1535 smprintf(s,"WARNING: Received unexpected type %02X for field 9, ignoring\n", Priv->ReturnType);
1533 entry->EntriesNum--; 1536 entry->EntriesNum--;
1534 j++; 1537 j++;
1535 break; 1538 break;
1536 } 1539 }
1537 entry->Entries[i - j].EntryType = PBK_Number_Fax; 1540 entry->Entries[i - j].EntryType = PBK_Number_Fax;
1538 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1541 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1539 break; 1542 break;
1540 case 10: 1543 case 10:
1541 if (Priv->ReturnType != Alcatel_phone) { 1544 if (Priv->ReturnType != Alcatel_phone) {
1542 smprintf(s,"WARNING: Received unexpected type %02X for field 10, ignoring\n", Priv->ReturnType); 1545 smprintf(s,"WARNING: Received unexpected type %02X for field 10, ignoring\n", Priv->ReturnType);
1543 entry->EntriesNum--; 1546 entry->EntriesNum--;
1544 j++; 1547 j++;
1545 break; 1548 break;
1546 } 1549 }
1547 entry->Entries[i - j].EntryType = PBK_Number_Other; 1550 entry->Entries[i - j].EntryType = PBK_Number_Other;
1548 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1551 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1549 break; 1552 break;
1550 case 11: 1553 case 11:
1551 if (Priv->ReturnType != Alcatel_phone) { 1554 if (Priv->ReturnType != Alcatel_phone) {
1552 smprintf(s,"WARNING: Received unexpected type %02X for field 11, ignoring\n", Priv->ReturnType); 1555 smprintf(s,"WARNING: Received unexpected type %02X for field 11, ignoring\n", Priv->ReturnType);
1553 entry->EntriesNum--; 1556 entry->EntriesNum--;
1554 j++; 1557 j++;
1555 break; 1558 break;
1556 } 1559 }
1557 entry->Entries[i - j].EntryType = PBK_Number_Pager; 1560 entry->Entries[i - j].EntryType = PBK_Number_Pager;
1558 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1561 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1559 break; 1562 break;
1560 case 12: 1563 case 12:
1561 if (Priv->ReturnType != Alcatel_phone) { 1564 if (Priv->ReturnType != Alcatel_phone) {
1562 smprintf(s,"WARNING: Received unexpected type %02X for field 12, ignoring\n", Priv->ReturnType); 1565 smprintf(s,"WARNING: Received unexpected type %02X for field 12, ignoring\n", Priv->ReturnType);
1563 entry->EntriesNum--; 1566 entry->EntriesNum--;
1564 j++; 1567 j++;
1565 break; 1568 break;
1566 } 1569 }
1567 entry->Entries[i - j].EntryType = PBK_Number_Mobile; 1570 entry->Entries[i - j].EntryType = PBK_Number_Mobile;
1568 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1571 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1569 break; 1572 break;
1570 case 13: 1573 case 13:
1571 if (Priv->ReturnType != Alcatel_phone) { 1574 if (Priv->ReturnType != Alcatel_phone) {
1572 smprintf(s,"WARNING: Received unexpected type %02X for field 13, ignoring\n", Priv->ReturnType); 1575 smprintf(s,"WARNING: Received unexpected type %02X for field 13, ignoring\n", Priv->ReturnType);
1573 entry->EntriesNum--; 1576 entry->EntriesNum--;
1574 j++; 1577 j++;
1575 break; 1578 break;
1576 } 1579 }
1577 entry->Entries[i - j].EntryType = PBK_Number_Home; 1580 entry->Entries[i - j].EntryType = PBK_Number_Home;
1578 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1581 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1579 break; 1582 break;
1580 case 14: 1583 case 14:
1581 if (Priv->ReturnType != Alcatel_string) { 1584 if (Priv->ReturnType != Alcatel_string) {
1582 smprintf(s,"WARNING: Received unexpected type %02X for field 14, ignoring\n", Priv->ReturnType); 1585 smprintf(s,"WARNING: Received unexpected type %02X for field 14, ignoring\n", Priv->ReturnType);
1583 entry->EntriesNum--; 1586 entry->EntriesNum--;
1584 j++; 1587 j++;
1585 break; 1588 break;
1586 } 1589 }
1587 entry->Entries[i - j].EntryType = PBK_Text_Email; 1590 entry->Entries[i - j].EntryType = PBK_Text_Email;
1588 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1591 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1589 break; 1592 break;
1590 case 15: 1593 case 15:
1591 if (Priv->ReturnType != Alcatel_string) { 1594 if (Priv->ReturnType != Alcatel_string) {
1592 smprintf(s,"WARNING: Received unexpected type %02X for field 15, ignoring\n", Priv->ReturnType); 1595 smprintf(s,"WARNING: Received unexpected type %02X for field 15, ignoring\n", Priv->ReturnType);
1593 entry->EntriesNum--; 1596 entry->EntriesNum--;
1594 j++; 1597 j++;
1595 break; 1598 break;
1596 } 1599 }
1597 entry->Entries[i - j].EntryType = PBK_Text_Email2; 1600 entry->Entries[i - j].EntryType = PBK_Text_Email2;
1598 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1601 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1599 break; 1602 break;
1600 case 16: 1603 case 16:
1601 if (Priv->ReturnType != Alcatel_string) { 1604 if (Priv->ReturnType != Alcatel_string) {
1602 smprintf(s,"WARNING: Received unexpected type %02X for field 16, ignoring\n", Priv->ReturnType); 1605 smprintf(s,"WARNING: Received unexpected type %02X for field 16, ignoring\n", Priv->ReturnType);
1603 entry->EntriesNum--; 1606 entry->EntriesNum--;
1604 j++; 1607 j++;
1605 break; 1608 break;
1606 } 1609 }
1607 entry->Entries[i - j].EntryType = PBK_Text_StreetAddress; 1610 entry->Entries[i - j].EntryType = PBK_Text_StreetAddress;
1608 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1611 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1609 break; 1612 break;
1610 case 17: 1613 case 17:
1611 if (Priv->ReturnType != Alcatel_string) { 1614 if (Priv->ReturnType != Alcatel_string) {
1612 smprintf(s,"WARNING: Received unexpected type %02X for field 17, ignoring\n", Priv->ReturnType); 1615 smprintf(s,"WARNING: Received unexpected type %02X for field 17, ignoring\n", Priv->ReturnType);
1613 entry->EntriesNum--; 1616 entry->EntriesNum--;
1614 j++; 1617 j++;
1615 break; 1618 break;
1616 } 1619 }
1617 entry->Entries[i - j].EntryType = PBK_Text_City; 1620 entry->Entries[i - j].EntryType = PBK_Text_City;
1618 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1621 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1619 break; 1622 break;
1620 case 18: 1623 case 18:
1621 if (Priv->ReturnType != Alcatel_string) { 1624 if (Priv->ReturnType != Alcatel_string) {
1622 smprintf(s,"WARNING: Received unexpected type %02X for field 18, ignoring\n", Priv->ReturnType); 1625 smprintf(s,"WARNING: Received unexpected type %02X for field 18, ignoring\n", Priv->ReturnType);
1623 entry->EntriesNum--; 1626 entry->EntriesNum--;
1624 j++; 1627 j++;
1625 break; 1628 break;
1626 } 1629 }
1627 entry->Entries[i - j].EntryType = PBK_Text_State; 1630 entry->Entries[i - j].EntryType = PBK_Text_State;
1628 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1631 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1629 break; 1632 break;
1630 case 19: 1633 case 19:
1631 if (Priv->ReturnType != Alcatel_string) { 1634 if (Priv->ReturnType != Alcatel_string) {
1632 smprintf(s,"WARNING: Received unexpected type %02X for field 19, ignoring\n", Priv->ReturnType); 1635 smprintf(s,"WARNING: Received unexpected type %02X for field 19, ignoring\n", Priv->ReturnType);
1633 entry->EntriesNum--; 1636 entry->EntriesNum--;
1634 j++; 1637 j++;
1635 break; 1638 break;
1636 } 1639 }
1637 entry->Entries[i - j].EntryType = PBK_Text_Zip; 1640 entry->Entries[i - j].EntryType = PBK_Text_Zip;
1638 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1641 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1639 break; 1642 break;
1640 case 20: 1643 case 20:
1641 if (Priv->ReturnType != Alcatel_string) { 1644 if (Priv->ReturnType != Alcatel_string) {
1642 smprintf(s,"WARNING: Received unexpected type %02X for field 20, ignoring\n", Priv->ReturnType); 1645 smprintf(s,"WARNING: Received unexpected type %02X for field 20, ignoring\n", Priv->ReturnType);
1643 entry->EntriesNum--; 1646 entry->EntriesNum--;
1644 j++; 1647 j++;
1645 break; 1648 break;
1646 } 1649 }
1647 entry->Entries[i - j].EntryType = PBK_Text_Country; 1650 entry->Entries[i - j].EntryType = PBK_Text_Country;
1648 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1651 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1649 break; 1652 break;
1650 case 21: 1653 case 21:
1651 if (Priv->ReturnType != Alcatel_string) { 1654 if (Priv->ReturnType != Alcatel_string) {
1652 smprintf(s,"WARNING: Received unexpected type %02X for field 21, ignoring\n", Priv->ReturnType); 1655 smprintf(s,"WARNING: Received unexpected type %02X for field 21, ignoring\n", Priv->ReturnType);
1653 entry->EntriesNum--; 1656 entry->EntriesNum--;
1654 j++; 1657 j++;
1655 break; 1658 break;
1656 } 1659 }
1657 entry->Entries[i - j].EntryType = PBK_Text_Custom1; 1660 entry->Entries[i - j].EntryType = PBK_Text_Custom1;
1658 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1661 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1659 break; 1662 break;
1660 case 22: 1663 case 22:
1661 if (Priv->ReturnType != Alcatel_string) { 1664 if (Priv->ReturnType != Alcatel_string) {
1662 smprintf(s,"WARNING: Received unexpected type %02X for field 22, ignoring\n", Priv->ReturnType); 1665 smprintf(s,"WARNING: Received unexpected type %02X for field 22, ignoring\n", Priv->ReturnType);
1663 entry->EntriesNum--; 1666 entry->EntriesNum--;
1664 j++; 1667 j++;
1665 break; 1668 break;
1666 } 1669 }
1667 entry->Entries[i - j].EntryType = PBK_Text_Custom2; 1670 entry->Entries[i - j].EntryType = PBK_Text_Custom2;
1668 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1671 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1669 break; 1672 break;
1670 case 23: 1673 case 23:
1671 if (Priv->ReturnType != Alcatel_string) { 1674 if (Priv->ReturnType != Alcatel_string) {
1672 smprintf(s,"WARNING: Received unexpected type %02X for field 23, ignoring\n", Priv->ReturnType); 1675 smprintf(s,"WARNING: Received unexpected type %02X for field 23, ignoring\n", Priv->ReturnType);
1673 entry->EntriesNum--; 1676 entry->EntriesNum--;
1674 j++; 1677 j++;
1675 break; 1678 break;
1676 } 1679 }
1677 entry->Entries[i - j].EntryType = PBK_Text_Custom3; 1680 entry->Entries[i - j].EntryType = PBK_Text_Custom3;
1678 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1681 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1679 break; 1682 break;
1680 case 24: 1683 case 24:
1681 if (Priv->ReturnType != Alcatel_string) { 1684 if (Priv->ReturnType != Alcatel_string) {
1682 smprintf(s,"WARNING: Received unexpected type %02X for field 24, ignoring\n", Priv->ReturnType); 1685 smprintf(s,"WARNING: Received unexpected type %02X for field 24, ignoring\n", Priv->ReturnType);
1683 entry->EntriesNum--; 1686 entry->EntriesNum--;
1684 j++; 1687 j++;
1685 break; 1688 break;
1686 } 1689 }
1687 entry->Entries[i - j].EntryType = PBK_Text_Custom4; 1690 entry->Entries[i - j].EntryType = PBK_Text_Custom4;
1688 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString); 1691 CopyUnicodeString(entry->Entries[i - j].Text, Priv->ReturnString);
1689 break; 1692 break;
1690 case 25: 1693 case 25:
1691 if (Priv->ReturnType != Alcatel_int) { 1694 if (Priv->ReturnType != Alcatel_int) {
1692 smprintf(s,"WARNING: Received unexpected type %02X for field 25, ignoring\n", Priv->ReturnType); 1695 smprintf(s,"WARNING: Received unexpected type %02X for field 25, ignoring\n", Priv->ReturnType);
1693 entry->EntriesNum--; 1696 entry->EntriesNum--;
1694 j++; 1697 j++;
1695 break; 1698 break;
1696 } 1699 }
1697 if (Priv->ReturnInt != 0) { 1700 if (Priv->ReturnInt != 0) {
1698 entry->Entries[i - j].EntryType = PBK_PictureID; 1701 entry->Entries[i - j].EntryType = PBK_PictureID;
1699 entry->Entries[i - j].Number = Priv->ReturnInt; 1702 entry->Entries[i - j].Number = Priv->ReturnInt;
1700 } else { 1703 } else {
1701 entry->EntriesNum--; 1704 entry->EntriesNum--;
1702 j++; 1705 j++;
1703 } 1706 }
1704 break; 1707 break;
1705 default: 1708 default:
1706 entry->EntriesNum--; 1709 entry->EntriesNum--;
1707 j++; 1710 j++;
1708 smprintf(s,"WARNING: Received unknown field %02X, ignoring. Type = %02X. Value = ", Priv->CurrentFields[i], Priv->ReturnType); 1711 smprintf(s,"WARNING: Received unknown field %02X, ignoring. Type = %02X. Value = ", Priv->CurrentFields[i], Priv->ReturnType);
1709 switch (Priv->ReturnType) { 1712 switch (Priv->ReturnType) {
1710 case Alcatel_date: 1713 case Alcatel_date:
1711 smprintf(s, "%d.%d.%d", Priv->ReturnDateTime.Day, Priv->ReturnDateTime.Month, Priv->ReturnDateTime.Year); 1714 smprintf(s, "%d.%d.%d", Priv->ReturnDateTime.Day, Priv->ReturnDateTime.Month, Priv->ReturnDateTime.Year);
1712 break; 1715 break;
1713 case Alcatel_time: 1716 case Alcatel_time:
1714 smprintf(s, "%d:%d:%d", Priv->ReturnDateTime.Hour, Priv->ReturnDateTime.Minute, Priv->ReturnDateTime.Second); 1717 smprintf(s, "%d:%d:%d", Priv->ReturnDateTime.Hour, Priv->ReturnDateTime.Minute, Priv->ReturnDateTime.Second);
1715 break; 1718 break;
1716 case Alcatel_string: 1719 case Alcatel_string:
1717 case Alcatel_phone: 1720 case Alcatel_phone:
1718 smprintf(s, "\"%s\"",DecodeUnicodeString(Priv->ReturnString)); 1721 smprintf(s, "\"%s\"",DecodeUnicodeString(Priv->ReturnString));
1719 break; 1722 break;
1720 case Alcatel_enum: 1723 case Alcatel_enum:
1721 case Alcatel_bool: 1724 case Alcatel_bool:
1722 case Alcatel_int: 1725 case Alcatel_int:
1723 case Alcatel_byte: 1726 case Alcatel_byte:
1724 smprintf(s, "%d", Priv->ReturnInt); 1727 smprintf(s, "%d", Priv->ReturnInt);
1725 break; 1728 break;
1726 } 1729 }
1727 smprintf(s,"\n"); 1730 smprintf(s,"\n");
1728 } 1731 }
1729 } 1732 }
1730 return ERR_NONE; 1733 return ERR_NONE;
1731 } else { 1734 } else {
1732 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 1735 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
1733 return ATGEN_GetMemory(s, entry); 1736 return ATGEN_GetMemory(s, entry);
1734 } 1737 }
1735} 1738}
1736 1739
1737static GSM_Error ALCATEL_GetNextMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry, bool start) 1740static GSM_Error ALCATEL_GetNextMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry, bool start)
1738{ 1741{
1739 GSM_Error error; 1742 GSM_Error error;
1740 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 1743 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
1741 1744
1742 if (entry->MemoryType == MEM_ME) { 1745 if (entry->MemoryType == MEM_ME) {
1743 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error; 1746 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error;
1744 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error; 1747 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error;
1745 if (Priv->ContactsItemsCount == 0) return ERR_EMPTY; 1748 if (Priv->ContactsItemsCount == 0) return ERR_EMPTY;
1746 1749
1747 if (start) entry->Location = 0; 1750 if (start) entry->Location = 0;
1748 if ((error = ALCATEL_GetNextId(s, &(entry->Location))) != ERR_NONE) return error; 1751 if ((error = ALCATEL_GetNextId(s, &(entry->Location))) != ERR_NONE) return error;
1749 1752
1750 return ALCATEL_GetMemory(s, entry); 1753 return ALCATEL_GetMemory(s, entry);
1751 } else { 1754 } else {
1752 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 1755 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
1753 return ATGEN_GetNextMemory(s, entry, start); 1756 return ATGEN_GetNextMemory(s, entry, start);
1754 } 1757 }
1755} 1758}
1756 1759
1757static GSM_Error ALCATEL_AddMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry) 1760static GSM_Error ALCATEL_AddMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
1758{ 1761{
1759 GSM_Error error; 1762 GSM_Error error;
1760 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 1763 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
1761 int NamePosition = -1; 1764 int NamePosition = -1;
1762 bool NameSet = false; 1765 bool NameSet = false;
1763 int i; 1766 int i;
1764 1767
1765 1768
1766 if (entry->MemoryType == MEM_ME) { 1769 if (entry->MemoryType == MEM_ME) {
1767 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error; 1770 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error;
1768 if ((error = ALCATEL_GoToBinaryState(s, StateEdit, TypeContacts, 0))!= ERR_NONE) return error; 1771 if ((error = ALCATEL_GoToBinaryState(s, StateEdit, TypeContacts, 0))!= ERR_NONE) return error;
1769 for (i = 0; i < entry->EntriesNum; i++) { 1772 for (i = 0; i < entry->EntriesNum; i++) {
1770 switch (entry->Entries[i].EntryType) { 1773 switch (entry->Entries[i].EntryType) {
1771 case PBK_Number_General: 1774 case PBK_Number_General:
1772 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 8, entry->Entries[i].Text)) != ERR_NONE) return error; 1775 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 8, entry->Entries[i].Text)) != ERR_NONE) return error;
1773 break; 1776 break;
1774 case PBK_Number_Mobile: 1777 case PBK_Number_Mobile:
1775 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 12, entry->Entries[i].Text)) != ERR_NONE) return error; 1778 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 12, entry->Entries[i].Text)) != ERR_NONE) return error;
1776 break; 1779 break;
1777 case PBK_Number_Work: 1780 case PBK_Number_Work:
1778 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 7, entry->Entries[i].Text)) != ERR_NONE) return error; 1781 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 7, entry->Entries[i].Text)) != ERR_NONE) return error;
1779 break; 1782 break;
1780 case PBK_Number_Fax: 1783 case PBK_Number_Fax:
1781 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 9, entry->Entries[i].Text)) != ERR_NONE) return error; 1784 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 9, entry->Entries[i].Text)) != ERR_NONE) return error;
1782 break; 1785 break;
1783 case PBK_Number_Home: 1786 case PBK_Number_Home:
1784 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 13, entry->Entries[i].Text)) != ERR_NONE) return error; 1787 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 13, entry->Entries[i].Text)) != ERR_NONE) return error;
1785 break; 1788 break;
1786 case PBK_Number_Pager: 1789 case PBK_Number_Pager:
1787 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 11, entry->Entries[i].Text)) != ERR_NONE) return error; 1790 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 11, entry->Entries[i].Text)) != ERR_NONE) return error;
1788 break; 1791 break;
1789 case PBK_Number_Other: 1792 case PBK_Number_Other:
1790 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 10, entry->Entries[i].Text)) != ERR_NONE) return error; 1793 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 10, entry->Entries[i].Text)) != ERR_NONE) return error;
1791 break; 1794 break;
1792 case PBK_Text_Note: 1795 case PBK_Text_Note:
1793 if ((error = ALCATEL_CreateField(s, Alcatel_string, 4, entry->Entries[i].Text)) != ERR_NONE) return error; 1796 if ((error = ALCATEL_CreateField(s, Alcatel_string, 4, entry->Entries[i].Text)) != ERR_NONE) return error;
1794 break; 1797 break;
1795 case PBK_Text_Email: 1798 case PBK_Text_Email:
1796 if ((error = ALCATEL_CreateField(s, Alcatel_string, 14, entry->Entries[i].Text)) != ERR_NONE) return error; 1799 if ((error = ALCATEL_CreateField(s, Alcatel_string, 14, entry->Entries[i].Text)) != ERR_NONE) return error;
1797 break; 1800 break;
1798 case PBK_Text_Email2: 1801 case PBK_Text_Email2:
1799 if ((error = ALCATEL_CreateField(s, Alcatel_string, 15, entry->Entries[i].Text)) != ERR_NONE) return error; 1802 if ((error = ALCATEL_CreateField(s, Alcatel_string, 15, entry->Entries[i].Text)) != ERR_NONE) return error;
1800 break; 1803 break;
1801 case PBK_Text_LastName: 1804 case PBK_Text_LastName:
1802 if ((error = ALCATEL_CreateField(s, Alcatel_string, 0, entry->Entries[i].Text)) != ERR_NONE) return error; 1805 if ((error = ALCATEL_CreateField(s, Alcatel_string, 0, entry->Entries[i].Text)) != ERR_NONE) return error;
1803 NameSet = true; 1806 NameSet = true;
1804 break; 1807 break;
1805 case PBK_Text_FirstName: 1808 case PBK_Text_FirstName:
1806 if ((error = ALCATEL_CreateField(s, Alcatel_string, 1, entry->Entries[i].Text)) != ERR_NONE) return error; 1809 if ((error = ALCATEL_CreateField(s, Alcatel_string, 1, entry->Entries[i].Text)) != ERR_NONE) return error;
1807 NameSet = true; 1810 NameSet = true;
1808 break; 1811 break;
1809 case PBK_Text_Company: 1812 case PBK_Text_Company:
1810 if ((error = ALCATEL_CreateField(s, Alcatel_string, 2, entry->Entries[i].Text)) != ERR_NONE) return error; 1813 if ((error = ALCATEL_CreateField(s, Alcatel_string, 2, entry->Entries[i].Text)) != ERR_NONE) return error;
1811 break; 1814 break;
1812 case PBK_Text_JobTitle: 1815 case PBK_Text_JobTitle:
1813 if ((error = ALCATEL_CreateField(s, Alcatel_string, 3, entry->Entries[i].Text)) != ERR_NONE) return error; 1816 if ((error = ALCATEL_CreateField(s, Alcatel_string, 3, entry->Entries[i].Text)) != ERR_NONE) return error;
1814 break; 1817 break;
1815 case PBK_Category: 1818 case PBK_Category:
1816 if ((error = ALCATEL_CreateField(s, Alcatel_byte, 5, &(entry->Entries[i].Number))) != ERR_NONE) return error; 1819 if ((error = ALCATEL_CreateField(s, Alcatel_byte, 5, &(entry->Entries[i].Number))) != ERR_NONE) return error;
1817 break; 1820 break;
1818 case PBK_Private: 1821 case PBK_Private:
1819 if ((error = ALCATEL_CreateField(s, Alcatel_bool, 6, &(entry->Entries[i].Number))) != ERR_NONE) return error; 1822 if ((error = ALCATEL_CreateField(s, Alcatel_bool, 6, &(entry->Entries[i].Number))) != ERR_NONE) return error;
1820 break; 1823 break;
1821 case PBK_Text_StreetAddress: 1824 case PBK_Text_StreetAddress:
1822 if ((error = ALCATEL_CreateField(s, Alcatel_string, 16, entry->Entries[i].Text)) != ERR_NONE) return error; 1825 if ((error = ALCATEL_CreateField(s, Alcatel_string, 16, entry->Entries[i].Text)) != ERR_NONE) return error;
1823 break; 1826 break;
1824 case PBK_Text_City: 1827 case PBK_Text_City:
1825 if ((error = ALCATEL_CreateField(s, Alcatel_string, 17, entry->Entries[i].Text)) != ERR_NONE) return error; 1828 if ((error = ALCATEL_CreateField(s, Alcatel_string, 17, entry->Entries[i].Text)) != ERR_NONE) return error;
1826 break; 1829 break;
1827 case PBK_Text_State: 1830 case PBK_Text_State:
1828 if ((error = ALCATEL_CreateField(s, Alcatel_string, 18, entry->Entries[i].Text)) != ERR_NONE) return error; 1831 if ((error = ALCATEL_CreateField(s, Alcatel_string, 18, entry->Entries[i].Text)) != ERR_NONE) return error;
1829 break; 1832 break;
1830 case PBK_Text_Zip: 1833 case PBK_Text_Zip:
1831 if ((error = ALCATEL_CreateField(s, Alcatel_string, 19, entry->Entries[i].Text)) != ERR_NONE) return error; 1834 if ((error = ALCATEL_CreateField(s, Alcatel_string, 19, entry->Entries[i].Text)) != ERR_NONE) return error;
1832 break; 1835 break;
1833 case PBK_Text_Country: 1836 case PBK_Text_Country:
1834 if ((error = ALCATEL_CreateField(s, Alcatel_string, 20, entry->Entries[i].Text)) != ERR_NONE) return error; 1837 if ((error = ALCATEL_CreateField(s, Alcatel_string, 20, entry->Entries[i].Text)) != ERR_NONE) return error;
1835 break; 1838 break;
1836 case PBK_Text_Custom1: 1839 case PBK_Text_Custom1:
1837 if ((error = ALCATEL_CreateField(s, Alcatel_string, 21, entry->Entries[i].Text)) != ERR_NONE) return error; 1840 if ((error = ALCATEL_CreateField(s, Alcatel_string, 21, entry->Entries[i].Text)) != ERR_NONE) return error;
1838 break; 1841 break;
1839 case PBK_Text_Custom2: 1842 case PBK_Text_Custom2:
1840 if ((error = ALCATEL_CreateField(s, Alcatel_string, 22, entry->Entries[i].Text)) != ERR_NONE) return error; 1843 if ((error = ALCATEL_CreateField(s, Alcatel_string, 22, entry->Entries[i].Text)) != ERR_NONE) return error;
1841 break; 1844 break;
1842 case PBK_Text_Custom3: 1845 case PBK_Text_Custom3:
1843 if ((error = ALCATEL_CreateField(s, Alcatel_string, 23, entry->Entries[i].Text)) != ERR_NONE) return error; 1846 if ((error = ALCATEL_CreateField(s, Alcatel_string, 23, entry->Entries[i].Text)) != ERR_NONE) return error;
1844 break; 1847 break;
1845 case PBK_Text_Custom4: 1848 case PBK_Text_Custom4:
1846 if ((error = ALCATEL_CreateField(s, Alcatel_string, 24, entry->Entries[i].Text)) != ERR_NONE) return error; 1849 if ((error = ALCATEL_CreateField(s, Alcatel_string, 24, entry->Entries[i].Text)) != ERR_NONE) return error;
1847 break; 1850 break;
1848 case PBK_PictureID: 1851 case PBK_PictureID:
1849 if (s->Phone.Data.Priv.ALCATEL.ProtocolVersion == V_1_1) { 1852 if (s->Phone.Data.Priv.ALCATEL.ProtocolVersion == V_1_1) {
1850 if ((error = ALCATEL_CreateField(s, Alcatel_int, 25, &(entry->Entries[i].Number))) != ERR_NONE) return error; 1853 if ((error = ALCATEL_CreateField(s, Alcatel_int, 25, &(entry->Entries[i].Number))) != ERR_NONE) return error;
1851 } else { 1854 } else {
1852 smprintf(s,"WARNING: Ignoring entry %d, not supported by phone\n", entry->Entries[i].EntryType); 1855 smprintf(s,"WARNING: Ignoring entry %d, not supported by phone\n", entry->Entries[i].EntryType);
1853 } 1856 }
1854 break; 1857 break;
1855 1858
1856 case PBK_Text_Name: NamePosition = i; break; 1859 case PBK_Text_Name: NamePosition = i; break;
1857 /* Following fields are not supported: */ 1860 /* Following fields are not supported: */
1858 case PBK_Text_UserID: 1861 case PBK_Text_UserID:
1859 case PBK_SMSListID: 1862 case PBK_SMSListID:
1860 case PBK_RingtoneFileSystemID: 1863 case PBK_RingtoneFileSystemID:
1861 case PBK_Date: 1864 case PBK_Date:
1862 case PBK_Caller_Group: 1865 case PBK_Caller_Group:
1863 case PBK_RingtoneID: 1866 case PBK_RingtoneID:
1864 case PBK_Text_Postal: 1867 case PBK_Text_Postal:
1865 case PBK_Text_URL: 1868 case PBK_Text_URL:
1866 smprintf(s,"WARNING: Ignoring entry %d, not supported by phone\n", entry->Entries[i].EntryType); 1869 smprintf(s,"WARNING: Ignoring entry %d, not supported by phone\n", entry->Entries[i].EntryType);
1867 break; 1870 break;
1868 } 1871 }
1869 } 1872 }
1870 if (NamePosition != -1) { 1873 if (NamePosition != -1) {
1871 if (NameSet) { 1874 if (NameSet) {
1872 smprintf(s,"WARNING: Ignoring name, not supported by phone\n"); 1875 smprintf(s,"WARNING: Ignoring name, not supported by phone\n");
1873 } else { 1876 } else {
1874 if ((error = ALCATEL_CreateField(s, Alcatel_string, 1, entry->Entries[i].Text)) != ERR_NONE) return error; 1877 if ((error = ALCATEL_CreateField(s, Alcatel_string, 1, entry->Entries[i].Text)) != ERR_NONE) return error;
1875 } 1878 }
1876 } 1879 }
1877 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error; 1880 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error;
1878 entry->Location = Priv->CommitedRecord; 1881 entry->Location = Priv->CommitedRecord;
1879 /* Refresh list */ 1882 /* Refresh list */
1880 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error; 1883 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error;
1881 return ERR_NONE; 1884 return ERR_NONE;
1882 } else { 1885 } else {
1883 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 1886 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
1884 return ATGEN_AddMemory(s, entry); 1887 return ATGEN_AddMemory(s, entry);
1885 } 1888 }
1886} 1889}
1887 1890
1888static GSM_Error ALCATEL_SetMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry) 1891static GSM_Error ALCATEL_SetMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
1889{ 1892{
1890 GSM_Error error; 1893 GSM_Error error;
1891 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 1894 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
1892 int NamePosition = -1; 1895 int NamePosition = -1;
1893 bool NameSet = false; 1896 bool NameSet = false;
1894 int i; 1897 int i;
1895 bool UpdatedFields[26]; 1898 bool UpdatedFields[26];
1896 1899
1897 if (entry->Location == 0) return ERR_INVALIDLOCATION; 1900 if (entry->Location == 0) return ERR_INVALIDLOCATION;
1898 1901
1899 if (entry->MemoryType == MEM_ME) { 1902 if (entry->MemoryType == MEM_ME) {
1900 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error; 1903 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error;
1901 /* Save modified entry */ 1904 /* Save modified entry */
1902 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error; 1905 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error;
1903 if ((error = ALCATEL_IsIdAvailable(s, entry->Location))!= ERR_NONE) { 1906 if ((error = ALCATEL_IsIdAvailable(s, entry->Location))!= ERR_NONE) {
1904 /* Entry doesn't exist, we will create new one */ 1907 /* Entry doesn't exist, we will create new one */
1905 return ALCATEL_AddMemory(s, entry); 1908 return ALCATEL_AddMemory(s, entry);
1906 } 1909 }
1907 /* Get fields for current item */ 1910 /* Get fields for current item */
1908 if ((error = ALCATEL_GetFields(s, entry->Location))!= ERR_NONE) return error; 1911 if ((error = ALCATEL_GetFields(s, entry->Location))!= ERR_NONE) return error;
1909 1912
1910 for (i = 0; i < 26; i++) { UpdatedFields[i] = false; } 1913 for (i = 0; i < 26; i++) { UpdatedFields[i] = false; }
1911 1914
1912 if ((error = ALCATEL_GoToBinaryState(s, StateEdit, TypeContacts, entry->Location))!= ERR_NONE) return error; 1915 if ((error = ALCATEL_GoToBinaryState(s, StateEdit, TypeContacts, entry->Location))!= ERR_NONE) return error;
1913 for (i = 0; i < entry->EntriesNum; i++) { 1916 for (i = 0; i < entry->EntriesNum; i++) {
1914 switch (entry->Entries[i].EntryType) { 1917 switch (entry->Entries[i].EntryType) {
1915 case PBK_Number_General: 1918 case PBK_Number_General:
1916 UpdatedFields[8] = true; 1919 UpdatedFields[8] = true;
1917 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, entry->Location, 8, entry->Entries[i].Text)) != ERR_NONE) return error; 1920 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, entry->Location, 8, entry->Entries[i].Text)) != ERR_NONE) return error;
1918 break; 1921 break;
1919 case PBK_Number_Mobile: 1922 case PBK_Number_Mobile:
1920 UpdatedFields[12] = true; 1923 UpdatedFields[12] = true;
1921 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, entry->Location, 12, entry->Entries[i].Text)) != ERR_NONE) return error; 1924 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, entry->Location, 12, entry->Entries[i].Text)) != ERR_NONE) return error;
1922 break; 1925 break;
1923 case PBK_Number_Work: 1926 case PBK_Number_Work:
1924 UpdatedFields[7] = true; 1927 UpdatedFields[7] = true;
1925 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, entry->Location, 7, entry->Entries[i].Text)) != ERR_NONE) return error; 1928 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, entry->Location, 7, entry->Entries[i].Text)) != ERR_NONE) return error;
1926 break; 1929 break;
1927 case PBK_Number_Fax: 1930 case PBK_Number_Fax:
1928 UpdatedFields[9] = true; 1931 UpdatedFields[9] = true;
1929 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, entry->Location, 9, entry->Entries[i].Text)) != ERR_NONE) return error; 1932 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, entry->Location, 9, entry->Entries[i].Text)) != ERR_NONE) return error;
1930 break; 1933 break;
1931 case PBK_Number_Home: 1934 case PBK_Number_Home:
1932 UpdatedFields[13] = true; 1935 UpdatedFields[13] = true;
1933 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, entry->Location, 13, entry->Entries[i].Text)) != ERR_NONE) return error; 1936 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, entry->Location, 13, entry->Entries[i].Text)) != ERR_NONE) return error;
1934 break; 1937 break;
1935 case PBK_Number_Pager: 1938 case PBK_Number_Pager:
1936 UpdatedFields[11] = true; 1939 UpdatedFields[11] = true;
1937 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, entry->Location, 11, entry->Entries[i].Text)) != ERR_NONE) return error; 1940 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, entry->Location, 11, entry->Entries[i].Text)) != ERR_NONE) return error;
1938 break; 1941 break;
1939 case PBK_Number_Other: 1942 case PBK_Number_Other:
1940 UpdatedFields[10] = true; 1943 UpdatedFields[10] = true;
1941 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, entry->Location, 10, entry->Entries[i].Text)) != ERR_NONE) return error; 1944 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, entry->Location, 10, entry->Entries[i].Text)) != ERR_NONE) return error;
1942 break; 1945 break;
1943 case PBK_Text_Note: 1946 case PBK_Text_Note:
1944 UpdatedFields[4] = true; 1947 UpdatedFields[4] = true;
1945 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 4, entry->Entries[i].Text)) != ERR_NONE) return error; 1948 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 4, entry->Entries[i].Text)) != ERR_NONE) return error;
1946 break; 1949 break;
1947 case PBK_Text_Email: 1950 case PBK_Text_Email:
1948 UpdatedFields[14] = true; 1951 UpdatedFields[14] = true;
1949 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 14, entry->Entries[i].Text)) != ERR_NONE) return error; 1952 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 14, entry->Entries[i].Text)) != ERR_NONE) return error;
1950 break; 1953 break;
1951 case PBK_Text_Email2: 1954 case PBK_Text_Email2:
1952 UpdatedFields[15] = true; 1955 UpdatedFields[15] = true;
1953 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 15, entry->Entries[i].Text)) != ERR_NONE) return error; 1956 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 15, entry->Entries[i].Text)) != ERR_NONE) return error;
1954 break; 1957 break;
1955 case PBK_Text_LastName: 1958 case PBK_Text_LastName:
1956 UpdatedFields[0] = true; 1959 UpdatedFields[0] = true;
1957 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 0, entry->Entries[i].Text)) != ERR_NONE) return error; NameSet = true; 1960 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 0, entry->Entries[i].Text)) != ERR_NONE) return error; NameSet = true;
1958 break; 1961 break;
1959 case PBK_Text_FirstName: 1962 case PBK_Text_FirstName:
1960 UpdatedFields[1] = true; 1963 UpdatedFields[1] = true;
1961 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 1, entry->Entries[i].Text)) != ERR_NONE) return error; NameSet = true; 1964 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 1, entry->Entries[i].Text)) != ERR_NONE) return error; NameSet = true;
1962 break; 1965 break;
1963 case PBK_Text_Company: 1966 case PBK_Text_Company:
1964 UpdatedFields[2] = true; 1967 UpdatedFields[2] = true;
1965 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 2, entry->Entries[i].Text)) != ERR_NONE) return error; 1968 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 2, entry->Entries[i].Text)) != ERR_NONE) return error;
1966 break; 1969 break;
1967 case PBK_Text_JobTitle: 1970 case PBK_Text_JobTitle:
1968 UpdatedFields[3] = true; 1971 UpdatedFields[3] = true;
1969 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 3, entry->Entries[i].Text)) != ERR_NONE) return error; 1972 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 3, entry->Entries[i].Text)) != ERR_NONE) return error;
1970 break; 1973 break;
1971 case PBK_Category: 1974 case PBK_Category:
1972 UpdatedFields[5] = true; 1975 UpdatedFields[5] = true;
1973 if ((error = ALCATEL_UpdateField(s, Alcatel_byte, entry->Location, 5, &(entry->Entries[i].Number))) != ERR_NONE) return error; 1976 if ((error = ALCATEL_UpdateField(s, Alcatel_byte, entry->Location, 5, &(entry->Entries[i].Number))) != ERR_NONE) return error;
1974 break; 1977 break;
1975 case PBK_Private: 1978 case PBK_Private:
1976 UpdatedFields[6] = true; 1979 UpdatedFields[6] = true;
1977 if ((error = ALCATEL_UpdateField(s, Alcatel_bool, entry->Location, 6, &(entry->Entries[i].Number))) != ERR_NONE) return error; 1980 if ((error = ALCATEL_UpdateField(s, Alcatel_bool, entry->Location, 6, &(entry->Entries[i].Number))) != ERR_NONE) return error;
1978 break; 1981 break;
1979 case PBK_Text_StreetAddress: 1982 case PBK_Text_StreetAddress:
1980 UpdatedFields[16] = true; 1983 UpdatedFields[16] = true;
1981 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 16, entry->Entries[i].Text)) != ERR_NONE) return error; 1984 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 16, entry->Entries[i].Text)) != ERR_NONE) return error;
1982 break; 1985 break;
1983 case PBK_Text_City: 1986 case PBK_Text_City:
1984 UpdatedFields[17] = true; 1987 UpdatedFields[17] = true;
1985 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 17, entry->Entries[i].Text)) != ERR_NONE) return error; 1988 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 17, entry->Entries[i].Text)) != ERR_NONE) return error;
1986 break; 1989 break;
1987 case PBK_Text_State: 1990 case PBK_Text_State:
1988 UpdatedFields[18] = true; 1991 UpdatedFields[18] = true;
1989 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 18, entry->Entries[i].Text)) != ERR_NONE) return error; 1992 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 18, entry->Entries[i].Text)) != ERR_NONE) return error;
1990 break; 1993 break;
1991 case PBK_Text_Zip: 1994 case PBK_Text_Zip:
1992 UpdatedFields[19] = true; 1995 UpdatedFields[19] = true;
1993 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 19, entry->Entries[i].Text)) != ERR_NONE) return error; 1996 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 19, entry->Entries[i].Text)) != ERR_NONE) return error;
1994 break; 1997 break;
1995 case PBK_Text_Country: 1998 case PBK_Text_Country:
1996 UpdatedFields[20] = true; 1999 UpdatedFields[20] = true;
1997 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 20, entry->Entries[i].Text)) != ERR_NONE) return error; 2000 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 20, entry->Entries[i].Text)) != ERR_NONE) return error;
1998 break; 2001 break;
1999 case PBK_Text_Custom1: 2002 case PBK_Text_Custom1:
2000 UpdatedFields[21] = true; 2003 UpdatedFields[21] = true;
2001 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 21, entry->Entries[i].Text)) != ERR_NONE) return error; 2004 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 21, entry->Entries[i].Text)) != ERR_NONE) return error;
2002 break; 2005 break;
2003 case PBK_Text_Custom2: 2006 case PBK_Text_Custom2:
2004 UpdatedFields[22] = true; 2007 UpdatedFields[22] = true;
2005 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 22, entry->Entries[i].Text)) != ERR_NONE) return error; 2008 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 22, entry->Entries[i].Text)) != ERR_NONE) return error;
2006 break; 2009 break;
2007 case PBK_Text_Custom3: 2010 case PBK_Text_Custom3:
2008 UpdatedFields[23] = true; 2011 UpdatedFields[23] = true;
2009 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 23, entry->Entries[i].Text)) != ERR_NONE) return error; 2012 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 23, entry->Entries[i].Text)) != ERR_NONE) return error;
2010 break; 2013 break;
2011 case PBK_Text_Custom4: 2014 case PBK_Text_Custom4:
2012 UpdatedFields[24] = true; 2015 UpdatedFields[24] = true;
2013 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 24, entry->Entries[i].Text)) != ERR_NONE) return error 2016 if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 24, entry->Entries[i].Text)) != ERR_NONE) return error
2014 ; break; 2017 ; break;
2015 case PBK_PictureID: 2018 case PBK_PictureID:
2016 if (s->Phone.Data.Priv.ALCATEL.ProtocolVersion == V_1_1) { 2019 if (s->Phone.Data.Priv.ALCATEL.ProtocolVersion == V_1_1) {
2017 UpdatedFields[25] = true; 2020 UpdatedFields[25] = true;
2018 if ((error = ALCATEL_UpdateField(s, Alcatel_int, entry->Location, 25, &(entry->Entries[i].Number))) != ERR_NONE) return error; 2021 if ((error = ALCATEL_UpdateField(s, Alcatel_int, entry->Location, 25, &(entry->Entries[i].Number))) != ERR_NONE) return error;
2019 } else { 2022 } else {
2020 smprintf(s,"WARNING: Ignoring entry %d, not supported by phone\n", entry->Entries[i].EntryType); 2023 smprintf(s,"WARNING: Ignoring entry %d, not supported by phone\n", entry->Entries[i].EntryType);
2021 } 2024 }
2022 break; 2025 break;
2023 2026
2024 case PBK_Text_Name: NamePosition = i; break; 2027 case PBK_Text_Name: NamePosition = i; break;
2025 /* Following fields are not supported: */ 2028 /* Following fields are not supported: */
2026 case PBK_SMSListID: 2029 case PBK_SMSListID:
2027 case PBK_Text_UserID: 2030 case PBK_Text_UserID:
2028 case PBK_RingtoneFileSystemID: 2031 case PBK_RingtoneFileSystemID:
2029 case PBK_Date: 2032 case PBK_Date:
2030 case PBK_Caller_Group: 2033 case PBK_Caller_Group:
2031 case PBK_RingtoneID: 2034 case PBK_RingtoneID:
2032 case PBK_Text_Postal: 2035 case PBK_Text_Postal:
2033 case PBK_Text_URL: 2036 case PBK_Text_URL:
2034 smprintf(s,"WARNING: Ignoring entry %d, not supported by phone\n", entry->Entries[i].EntryType); 2037 smprintf(s,"WARNING: Ignoring entry %d, not supported by phone\n", entry->Entries[i].EntryType);
2035 break; 2038 break;
2036 } 2039 }
2037 } 2040 }
2038 if (NamePosition != -1) { 2041 if (NamePosition != -1) {
2039 if (NameSet) { 2042 if (NameSet) {
2040 smprintf(s,"WARNING: Ignoring name, not supported by phone\n"); 2043 smprintf(s,"WARNING: Ignoring name, not supported by phone\n");
2041 } else { 2044 } else {
2042 UpdatedFields[1] = true; if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 1, entry->Entries[i].Text)) != ERR_NONE) return error; 2045 UpdatedFields[1] = true; if ((error = ALCATEL_UpdateField(s, Alcatel_string, entry->Location, 1, entry->Entries[i].Text)) != ERR_NONE) return error;
2043 } 2046 }
2044 } 2047 }
2045 /* If we didn't update some field, we have to delete it... */ 2048 /* If we didn't update some field, we have to delete it... */
2046 for (i=0; i<Priv->CurrentFieldsCount; i++) { 2049 for (i=0; i<Priv->CurrentFieldsCount; i++) {
2047 if (!UpdatedFields[Priv->CurrentFields[i]]) if ((error = ALCATEL_DeleteField(s, entry->Location, Priv->CurrentFields[i])) != ERR_NONE) return error; 2050 if (!UpdatedFields[Priv->CurrentFields[i]]) if ((error = ALCATEL_DeleteField(s, entry->Location, Priv->CurrentFields[i])) != ERR_NONE) return error;
2048 } 2051 }
2049 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error; 2052 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error;
2050 entry->Location = Priv->CommitedRecord; 2053 entry->Location = Priv->CommitedRecord;
2051 return ERR_NONE; 2054 return ERR_NONE;
2052 } else { 2055 } else {
2053 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2056 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2054 return ATGEN_SetMemory(s, entry); 2057 return ATGEN_SetMemory(s, entry);
2055 } 2058 }
2056} 2059}
2057 2060
2058static GSM_Error ALCATEL_DeleteMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry) 2061static GSM_Error ALCATEL_DeleteMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
2059{ 2062{
2060 GSM_Error error; 2063 GSM_Error error;
2061 2064
2062 if (entry->MemoryType == MEM_ME) { 2065 if (entry->MemoryType == MEM_ME) {
2063 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error; 2066 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error;
2064 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error; 2067 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error;
2065 if ((error = ALCATEL_IsIdAvailable(s, entry->Location))!= ERR_NONE) { 2068 if ((error = ALCATEL_IsIdAvailable(s, entry->Location))!= ERR_NONE) {
2066 /* Entry was empty => no error */ 2069 /* Entry was empty => no error */
2067 return ERR_NONE; 2070 return ERR_NONE;
2068 } 2071 }
2069 /* Do real delete */ 2072 /* Do real delete */
2070 error = ALCATEL_DeleteItem(s, entry->Location); 2073 error = ALCATEL_DeleteItem(s, entry->Location);
2071 if (error != ERR_NONE) return error; 2074 if (error != ERR_NONE) return error;
2072 2075
2073 /* Refresh list */ 2076 /* Refresh list */
2074 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error; 2077 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error;
2075 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error; 2078 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error;
2076 2079
2077 return ERR_NONE; 2080 return ERR_NONE;
2078 } else { 2081 } else {
2079 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2082 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2080 return ATGEN_DeleteMemory(s, entry); 2083 return ATGEN_DeleteMemory(s, entry);
2081 } 2084 }
2082} 2085}
2083 2086
2084static GSM_Error ALCATEL_DeleteAllMemory(GSM_StateMachine *s, GSM_MemoryType type) 2087static GSM_Error ALCATEL_DeleteAllMemory(GSM_StateMachine *s, GSM_MemoryType type)
2085{ 2088{
2086 GSM_Error error; 2089 GSM_Error error;
2087 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 2090 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
2088 int i; 2091 int i;
2089 2092
2090 if (type == MEM_ME) { 2093 if (type == MEM_ME) {
2091 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error; 2094 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error;
2092 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error; 2095 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error;
2093 2096
2094 for (i=0; i<Priv->ContactsItemsCount; i++) { 2097 for (i=0; i<Priv->ContactsItemsCount; i++) {
2095 error = ALCATEL_DeleteItem(s, Priv->ContactsItems[i]); 2098 error = ALCATEL_DeleteItem(s, Priv->ContactsItems[i]);
2096 if (error != ERR_NONE) return error; 2099 if (error != ERR_NONE) return error;
2097 } 2100 }
2098 2101
2099 /* Refresh list */ 2102 /* Refresh list */
2100 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error; 2103 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error;
2101 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error; 2104 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error;
2102 2105
2103 return ERR_NONE; 2106 return ERR_NONE;
2104 } else { 2107 } else {
2105 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2108 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2106 return ATGEN_DeleteAllMemory(s, type); 2109 return ATGEN_DeleteAllMemory(s, type);
2107 } 2110 }
2108} 2111}
2109 2112
2110static GSM_Error ALCATEL_GetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc) 2113static GSM_Error ALCATEL_GetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc)
2111{ 2114{
2112 GSM_Error error; 2115 GSM_Error error;
2113 2116
2114 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2117 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2115 return ATGEN_GetSMSC(s, smsc); 2118 return ATGEN_GetSMSC(s, smsc);
2116} 2119}
2117 2120
2118 2121
2119static GSM_Error ALCATEL_GetMemoryStatus(GSM_StateMachine *s, GSM_MemoryStatus *Status) 2122static GSM_Error ALCATEL_GetMemoryStatus(GSM_StateMachine *s, GSM_MemoryStatus *Status)
2120{ 2123{
2121 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL; 2124 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL;
2122 GSM_Error error; 2125 GSM_Error error;
2123 2126
2124 if (Status->MemoryType == MEM_ME) { 2127 if (Status->MemoryType == MEM_ME) {
2125 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error; 2128 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeContacts, 0))!= ERR_NONE) return error;
2126 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error; 2129 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error;
2127 Status->MemoryUsed = Priv->ContactsItemsCount; 2130 Status->MemoryUsed = Priv->ContactsItemsCount;
2128 Status->MemoryFree = ALCATEL_FREE_MEMORY; 2131 Status->MemoryFree = ALCATEL_FREE_MEMORY;
2129 return ERR_NONE; 2132 return ERR_NONE;
2130 } else { 2133 } else {
2131 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2134 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2132 return ATGEN_GetMemoryStatus(s, Status); 2135 return ATGEN_GetMemoryStatus(s, Status);
2133 } 2136 }
2134} 2137}
2135 2138
2136static GSM_Error ALCATEL_GetSMS(GSM_StateMachine *s, GSM_MultiSMSMessage *sms) 2139static GSM_Error ALCATEL_GetSMS(GSM_StateMachine *s, GSM_MultiSMSMessage *sms)
2137{ 2140{
2138 GSM_Error error; 2141 GSM_Error error;
2139 2142
2140 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2143 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2141 return ATGEN_GetSMS(s, sms); 2144 return ATGEN_GetSMS(s, sms);
2142} 2145}
2143 2146
2144static GSM_Error ALCATEL_DeleteSMS(GSM_StateMachine *s, GSM_SMSMessage *sms) 2147static GSM_Error ALCATEL_DeleteSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
2145{ 2148{
2146 GSM_Error error; 2149 GSM_Error error;
2147 2150
2148 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2151 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2149 return ATGEN_DeleteSMS(s, sms); 2152 return ATGEN_DeleteSMS(s, sms);
2150} 2153}
2151 2154
2152static GSM_Error ALCATEL_AddSMS(GSM_StateMachine *s, GSM_SMSMessage *sms) 2155static GSM_Error ALCATEL_AddSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
2153{ 2156{
2154 GSM_Error error; 2157 GSM_Error error;
2155 2158
2156 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2159 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2157 return ATGEN_AddSMS(s, sms); 2160 return ATGEN_AddSMS(s, sms);
2158} 2161}
2159 2162
2160static GSM_Error ALCATEL_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat) 2163static GSM_Error ALCATEL_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat)
2161{ 2164{
2162 GSM_Error error; 2165 GSM_Error error;
2163 2166
2164 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2167 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2165 return ATGEN_GetBatteryCharge(s, bat); 2168 return ATGEN_GetBatteryCharge(s, bat);
2166} 2169}
2167 2170
2168static GSM_Error ALCATEL_GetSignalStrength(GSM_StateMachine *s, GSM_SignalQuality *sig) 2171static GSM_Error ALCATEL_GetSignalStrength(GSM_StateMachine *s, GSM_SignalQuality *sig)
2169{ 2172{
2170 GSM_Error error; 2173 GSM_Error error;
2171 2174
2172 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2175 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2173 return ATGEN_GetSignalQuality(s, sig); 2176 return ATGEN_GetSignalQuality(s, sig);
2174} 2177}
2175 2178
2176static GSM_Error ALCATEL_GetSMSFolders(GSM_StateMachine *s, GSM_SMSFolders *folders) 2179static GSM_Error ALCATEL_GetSMSFolders(GSM_StateMachine *s, GSM_SMSFolders *folders)
2177{ 2180{
2178 GSM_Error error; 2181 GSM_Error error;
2179 2182
2180 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2183 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2181 return ATGEN_GetSMSFolders(s, folders); 2184 return ATGEN_GetSMSFolders(s, folders);
2182} 2185}
2183 2186
2184static GSM_Error ALCATEL_GetNextSMS(GSM_StateMachine *s, GSM_MultiSMSMessage *sms, bool start) 2187static GSM_Error ALCATEL_GetNextSMS(GSM_StateMachine *s, GSM_MultiSMSMessage *sms, bool start)
2185{ 2188{
2186 GSM_Error error; 2189 GSM_Error error;
2187 2190
2188 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2191 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2189 return ATGEN_GetNextSMS(s, sms, start); 2192 return ATGEN_GetNextSMS(s, sms, start);
2190} 2193}
2191 2194
2192static GSM_Error ALCATEL_GetSMSStatus(GSM_StateMachine *s, GSM_SMSMemoryStatus *status) 2195static GSM_Error ALCATEL_GetSMSStatus(GSM_StateMachine *s, GSM_SMSMemoryStatus *status)
2193{ 2196{
2194 GSM_Error error; 2197 GSM_Error error;
2195 2198
2196 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2199 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2197 return ATGEN_GetSMSStatus(s, status); 2200 return ATGEN_GetSMSStatus(s, status);
2198} 2201}
2199 2202
2200static GSM_Error ALCATEL_DialVoice(GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber) 2203static GSM_Error ALCATEL_DialVoice(GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber)
2201{ 2204{
2202 GSM_Error error; 2205 GSM_Error error;
2203 2206
2204 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2207 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2205 return ATGEN_DialVoice(s, number, ShowNumber); 2208 return ATGEN_DialVoice(s, number, ShowNumber);
2206} 2209}
2207 2210
2208static GSM_Error ALCATEL_AnswerCall(GSM_StateMachine *s, int ID, bool all) 2211static GSM_Error ALCATEL_AnswerCall(GSM_StateMachine *s, int ID, bool all)
2209{ 2212{
2210 GSM_Error error; 2213 GSM_Error error;
2211 2214
2212 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2215 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2213 return ATGEN_AnswerCall(s,ID,all); 2216 return ATGEN_AnswerCall(s,ID,all);
2214} 2217}
2215 2218
2216static GSM_Error ALCATEL_GetNetworkInfo(GSM_StateMachine *s, GSM_NetworkInfo *netinfo) 2219static GSM_Error ALCATEL_GetNetworkInfo(GSM_StateMachine *s, GSM_NetworkInfo *netinfo)
2217{ 2220{
2218 GSM_Error error; 2221 GSM_Error error;
2219 2222
2220 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2223 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2221 return ATGEN_GetNetworkInfo(s, netinfo); 2224 return ATGEN_GetNetworkInfo(s, netinfo);
2222} 2225}
2223 2226
2224static GSM_Error ALCATEL_GetDisplayStatus(GSM_StateMachine *s, GSM_DisplayFeatures *features) 2227static GSM_Error ALCATEL_GetDisplayStatus(GSM_StateMachine *s, GSM_DisplayFeatures *features)
2225{ 2228{
2226 GSM_Error error; 2229 GSM_Error error;
2227 2230
2228 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2231 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2229 return ATGEN_GetDisplayStatus(s, features); 2232 return ATGEN_GetDisplayStatus(s, features);
2230} 2233}
2231 2234
2232static GSM_Error ALCATEL_SetAutoNetworkLogin(GSM_StateMachine *s) 2235static GSM_Error ALCATEL_SetAutoNetworkLogin(GSM_StateMachine *s)
2233{ 2236{
2234 GSM_Error error; 2237 GSM_Error error;
2235 2238
2236 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2239 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2237 return ATGEN_SetAutoNetworkLogin(s); 2240 return ATGEN_SetAutoNetworkLogin(s);
2238} 2241}
2239 2242
2240static GSM_Error ALCATEL_PressKey(GSM_StateMachine *s, GSM_KeyCode Key, bool Press) 2243static GSM_Error ALCATEL_PressKey(GSM_StateMachine *s, GSM_KeyCode Key, bool Press)
2241{ 2244{
2242 GSM_Error error; 2245 GSM_Error error;
2243 2246
2244 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2247 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2245 return ATGEN_PressKey(s, Key, Press); 2248 return ATGEN_PressKey(s, Key, Press);
2246} 2249}
2247 2250
2248static GSM_Error ALCATEL_Reset(GSM_StateMachine *s, bool hard) 2251static GSM_Error ALCATEL_Reset(GSM_StateMachine *s, bool hard)
2249{ 2252{
2250 GSM_Error error; 2253 GSM_Error error;
2251 2254
2252 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2255 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2253 return ATGEN_Reset(s, hard); 2256 return ATGEN_Reset(s, hard);
2254} 2257}
2255 2258
2256static GSM_Error ALCATEL_CancelCall(GSM_StateMachine *s, int ID, bool all) 2259static GSM_Error ALCATEL_CancelCall(GSM_StateMachine *s, int ID, bool all)
2257{ 2260{
2258 GSM_Error error; 2261 GSM_Error error;
2259 2262
2260 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2263 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2261 return ATGEN_CancelCall(s,ID,all); 2264 return ATGEN_CancelCall(s,ID,all);
2262} 2265}
2263 2266
2264static GSM_Error ALCATEL_SendSavedSMS(GSM_StateMachine *s, int Folder, int Location) 2267static GSM_Error ALCATEL_SendSavedSMS(GSM_StateMachine *s, int Folder, int Location)
2265{ 2268{
2266 GSM_Error error; 2269 GSM_Error error;
2267 2270
2268 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2271 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2269 return ATGEN_SendSavedSMS(s, Folder, Location); 2272 return ATGEN_SendSavedSMS(s, Folder, Location);
2270} 2273}
2271 2274
2272static GSM_Error ALCATEL_SendSMS(GSM_StateMachine *s, GSM_SMSMessage *sms) 2275static GSM_Error ALCATEL_SendSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
2273{ 2276{
2274 GSM_Error error; 2277 GSM_Error error;
2275 2278
2276 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2279 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2277 return ATGEN_SendSMS(s, sms); 2280 return ATGEN_SendSMS(s, sms);
2278} 2281}
2279 2282
2280static GSM_Error ALCATEL_SetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time) 2283static GSM_Error ALCATEL_SetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
2281{ 2284{
2282 GSM_Error error; 2285 GSM_Error error;
2283 2286
2284 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2287 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2285 return ATGEN_SetDateTime(s, date_time); 2288 return ATGEN_SetDateTime(s, date_time);
2286} 2289}
2287 2290
2288static GSM_Error ALCATEL_SetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc) 2291static GSM_Error ALCATEL_SetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc)
2289{ 2292{
2290 GSM_Error error; 2293 GSM_Error error;
2291 2294
2292 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2295 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2293 return ATGEN_SetSMSC(s, smsc); 2296 return ATGEN_SetSMSC(s, smsc);
2294} 2297}
2295 2298
2296static GSM_Error ALCATEL_EnterSecurityCode(GSM_StateMachine *s, GSM_SecurityCode Code) 2299static GSM_Error ALCATEL_EnterSecurityCode(GSM_StateMachine *s, GSM_SecurityCode Code)
2297{ 2300{
2298 GSM_Error error; 2301 GSM_Error error;
2299 2302
2300 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2303 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2301 return ATGEN_EnterSecurityCode(s, Code); 2304 return ATGEN_EnterSecurityCode(s, Code);
2302} 2305}
2303 2306
2304static GSM_Error ALCATEL_GetSecurityStatus(GSM_StateMachine *s, GSM_SecurityCodeType *Status) 2307static GSM_Error ALCATEL_GetSecurityStatus(GSM_StateMachine *s, GSM_SecurityCodeType *Status)
2305{ 2308{
2306 GSM_Error error; 2309 GSM_Error error;
2307 2310
2308 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2311 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2309 return ATGEN_GetSecurityStatus(s, Status); 2312 return ATGEN_GetSecurityStatus(s, Status);
2310} 2313}
2311 2314
2312static GSM_Error ALCATEL_ResetPhoneSettings(GSM_StateMachine *s, GSM_ResetSettingsType Type) 2315static GSM_Error ALCATEL_ResetPhoneSettings(GSM_StateMachine *s, GSM_ResetSettingsType Type)
2313{ 2316{
2314 GSM_Error error; 2317 GSM_Error error;
2315 2318
2316 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2319 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2317 return ATGEN_ResetPhoneSettings(s, Type); 2320 return ATGEN_ResetPhoneSettings(s, Type);
2318} 2321}
2319 2322
2320static GSM_Error ALCATEL_SendDTMF(GSM_StateMachine *s, char *sequence) 2323static GSM_Error ALCATEL_SendDTMF(GSM_StateMachine *s, char *sequence)
2321{ 2324{
2322 GSM_Error error; 2325 GSM_Error error;
2323 2326
2324 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2327 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2325 return ATGEN_SendDTMF(s, sequence); 2328 return ATGEN_SendDTMF(s, sequence);
2326} 2329}
2327 2330
2328static GSM_Error ALCATEL_GetSIMIMSI(GSM_StateMachine *s, char *IMSI) 2331static GSM_Error ALCATEL_GetSIMIMSI(GSM_StateMachine *s, char *IMSI)
2329{ 2332{
2330 GSM_Error error; 2333 GSM_Error error;
2331 2334
2332 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 2335 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
2333 return ATGEN_GetSIMIMSI(s, IMSI); 2336 return ATGEN_GetSIMIMSI(s, IMSI);
2334} 2337}
2335 2338
2336static GSM_Error ALCATEL_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *status) 2339static GSM_Error ALCATEL_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *status)
2337{ 2340{
2338 GSM_Error error; 2341 GSM_Error error;
2339 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 2342 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
2340 2343
2341 status->Used = 0; 2344 status->Used = 0;
2342 2345
2343 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error; 2346 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error;
2344 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error; 2347 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error;
2345 2348
2346 status->Used = Priv->CalendarItemsCount; 2349 status->Used = Priv->CalendarItemsCount;
2347 return ERR_NONE; 2350 return ERR_NONE;
2348} 2351}
2349 2352
2350static GSM_Error ALCATEL_GetCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note) 2353static GSM_Error ALCATEL_GetCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note)
2351{ 2354{
2352 GSM_Error error; 2355 GSM_Error error;
2353 GSM_DateTime *dt = NULL; 2356 GSM_DateTime *dt = NULL;
2354 GSM_DateTime evdate; 2357 GSM_DateTime evdate;
2355 bool evdateused = true; 2358 bool evdateused = true;
2356 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 2359 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
2357 int i; 2360 int i;
2358 int j=0; 2361 int j=0;
2359 2362
2360 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error; 2363 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error;
2361 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error; 2364 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error;
2362 if ((error = ALCATEL_IsIdAvailable(s, Note->Location))!= ERR_NONE) { 2365 if ((error = ALCATEL_IsIdAvailable(s, Note->Location))!= ERR_NONE) {
2363 Note->EntriesNum = 0; 2366 Note->EntriesNum = 0;
2364 return error; 2367 return error;
2365 } 2368 }
2366 if ((error = ALCATEL_GetFields(s, Note->Location))!= ERR_NONE) return error; 2369 if ((error = ALCATEL_GetFields(s, Note->Location))!= ERR_NONE) return error;
2367 2370
2368 Note->EntriesNum = Priv->CurrentFieldsCount; 2371 Note->EntriesNum = Priv->CurrentFieldsCount;
2369 2372
2370 for (i=0; i < Priv->CurrentFieldsCount; i++) { 2373 for (i=0; i < Priv->CurrentFieldsCount; i++) {
2371 if ((error = ALCATEL_GetFieldValue(s, Note->Location, Priv->CurrentFields[i]))!= ERR_NONE) return error; 2374 if ((error = ALCATEL_GetFieldValue(s, Note->Location, Priv->CurrentFields[i]))!= ERR_NONE) return error;
2372 switch (Priv->CurrentFields[i]) { 2375 switch (Priv->CurrentFields[i]) {
2373 case 0: 2376 case 0:
2374 if (Priv->ReturnType != Alcatel_date) { 2377 if (Priv->ReturnType != Alcatel_date) {
2375 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2378 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2376 Note->EntriesNum--; 2379 Note->EntriesNum--;
2377 j++; 2380 j++;
2378 break; 2381 break;
2379 } 2382 }
2380 if (!CheckDate(&(Priv->ReturnDateTime))) { 2383 if (!CheckDate(&(Priv->ReturnDateTime))) {
2381 smprintf(s,"WARNING: Invalid date in phone, ignoring\n"); 2384 smprintf(s,"WARNING: Invalid date in phone, ignoring\n");
2382 Note->EntriesNum--; 2385 Note->EntriesNum--;
2383 j++; 2386 j++;
2384 break; 2387 break;
2385 } 2388 }
2386 j++; 2389 j++;
2387 Note->EntriesNum--; 2390 Note->EntriesNum--;
2388 evdate = Priv->ReturnDateTime; 2391 evdate = Priv->ReturnDateTime;
2389 evdateused = false; 2392 evdateused = false;
2390 break; 2393 break;
2391 case 1: 2394 case 1:
2392 if (Priv->ReturnType != Alcatel_time) { 2395 if (Priv->ReturnType != Alcatel_time) {
2393 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2396 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2394 Note->EntriesNum--; 2397 Note->EntriesNum--;
2395 j++; 2398 j++;
2396 break; 2399 break;
2397 } 2400 }
2398 if (!CheckTime(&(Priv->ReturnDateTime))) { 2401 if (!CheckTime(&(Priv->ReturnDateTime))) {
2399 smprintf(s,"WARNING: Invalid time in phone, ignoring\n"); 2402 smprintf(s,"WARNING: Invalid time in phone, ignoring\n");
2400 Note->EntriesNum--; 2403 Note->EntriesNum--;
2401 j++; 2404 j++;
2402 break; 2405 break;
2403 } 2406 }
2404 Note->Entries[i-j].EntryType = CAL_START_DATETIME; 2407 Note->Entries[i-j].EntryType = CAL_START_DATETIME;
2405 Note->Entries[i-j].Date = Priv->ReturnDateTime; 2408 Note->Entries[i-j].Date = Priv->ReturnDateTime;
2406 Note->Entries[i-j].Date.Day = evdate.Day; 2409 Note->Entries[i-j].Date.Day = evdate.Day;
2407 Note->Entries[i-j].Date.Month = evdate.Month; 2410 Note->Entries[i-j].Date.Month = evdate.Month;
2408 Note->Entries[i-j].Date.Year = evdate.Year; 2411 Note->Entries[i-j].Date.Year = evdate.Year;
2409 Note->Entries[i-j].Date.Timezone = evdate.Timezone; 2412 Note->Entries[i-j].Date.Timezone = evdate.Timezone;
2410 evdateused = true; 2413 evdateused = true;
2411 break; 2414 break;
2412 case 2: 2415 case 2:
2413 if (Priv->ReturnType != Alcatel_time) { 2416 if (Priv->ReturnType != Alcatel_time) {
2414 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2417 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2415 Note->EntriesNum--; 2418 Note->EntriesNum--;
2416 j++; 2419 j++;
2417 break; 2420 break;
2418 } 2421 }
2419 if (!CheckTime(&(Priv->ReturnDateTime))) { 2422 if (!CheckTime(&(Priv->ReturnDateTime))) {
2420 smprintf(s,"WARNING: Invalid time in phone, ignoring\n"); 2423 smprintf(s,"WARNING: Invalid time in phone, ignoring\n");
2421 Note->EntriesNum--; 2424 Note->EntriesNum--;
2422 j++; 2425 j++;
2423 break; 2426 break;
2424 } 2427 }
2425 Note->Entries[i-j].EntryType = CAL_END_DATETIME; 2428 Note->Entries[i-j].EntryType = CAL_END_DATETIME;
2426 Note->Entries[i-j].Date = Priv->ReturnDateTime; 2429 Note->Entries[i-j].Date = Priv->ReturnDateTime;
2427 Note->Entries[i-j].Date.Day = evdate.Day; 2430 Note->Entries[i-j].Date.Day = evdate.Day;
2428 Note->Entries[i-j].Date.Month = evdate.Month; 2431 Note->Entries[i-j].Date.Month = evdate.Month;
2429 Note->Entries[i-j].Date.Year = evdate.Year; 2432 Note->Entries[i-j].Date.Year = evdate.Year;
2430 Note->Entries[i-j].Date.Timezone = evdate.Timezone; 2433 Note->Entries[i-j].Date.Timezone = evdate.Timezone;
2431 evdateused = true; 2434 evdateused = true;
2432 break; 2435 break;
2433 case 3: 2436 case 3:
2434 if (Priv->ReturnType != Alcatel_date) { 2437 if (Priv->ReturnType != Alcatel_date) {
2435 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2438 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2436 Note->EntriesNum--; 2439 Note->EntriesNum--;
2437 j++; 2440 j++;
2438 break; 2441 break;
2439 } 2442 }
2440 if (!CheckDate(&(Priv->ReturnDateTime))) { 2443 if (!CheckDate(&(Priv->ReturnDateTime))) {
2441 smprintf(s,"WARNING: Invalid date in phone, ignoring\n"); 2444 smprintf(s,"WARNING: Invalid date in phone, ignoring\n");
2442 Note->EntriesNum--; 2445 Note->EntriesNum--;
2443 j++; 2446 j++;
2444 break; 2447 break;
2445 } 2448 }
2446 if (dt == NULL) { 2449 if (dt == NULL) {
2447 Note->Entries[i-j].EntryType = CAL_ALARM_DATETIME; 2450 Note->Entries[i-j].EntryType = CAL_ALARM_DATETIME;
2448 Note->Entries[i-j].Date = Priv->ReturnDateTime; 2451 Note->Entries[i-j].Date = Priv->ReturnDateTime;
2449 dt = &(Note->Entries[i-j].Date); 2452 dt = &(Note->Entries[i-j].Date);
2450 } else { 2453 } else {
2451 j++; 2454 j++;
2452 Note->EntriesNum--; 2455 Note->EntriesNum--;
2453 dt->Day = Priv->ReturnDateTime.Day; 2456 dt->Day = Priv->ReturnDateTime.Day;
2454 dt->Month = Priv->ReturnDateTime.Month; 2457 dt->Month = Priv->ReturnDateTime.Month;
2455 dt->Year = Priv->ReturnDateTime.Year; 2458 dt->Year = Priv->ReturnDateTime.Year;
2456 dt->Timezone = Priv->ReturnDateTime.Timezone; 2459 dt->Timezone = Priv->ReturnDateTime.Timezone;
2457 dt = NULL; 2460 dt = NULL;
2458 } 2461 }
2459 break; 2462 break;
2460 case 4: 2463 case 4:
2461 if (Priv->ReturnType != Alcatel_time) { 2464 if (Priv->ReturnType != Alcatel_time) {
2462 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2465 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2463 Note->EntriesNum--; 2466 Note->EntriesNum--;
2464 j++; 2467 j++;
2465 break; 2468 break;
2466 } 2469 }
2467 if (!CheckTime(&(Priv->ReturnDateTime))) { 2470 if (!CheckTime(&(Priv->ReturnDateTime))) {
2468 smprintf(s,"WARNING: Invalid time in phone, ignoring\n"); 2471 smprintf(s,"WARNING: Invalid time in phone, ignoring\n");
2469 Note->EntriesNum--; 2472 Note->EntriesNum--;
2470 j++; 2473 j++;
2471 break; 2474 break;
2472 } 2475 }
2473 if (dt == NULL) { 2476 if (dt == NULL) {
2474 Note->Entries[i-j].EntryType = CAL_ALARM_DATETIME; 2477 Note->Entries[i-j].EntryType = CAL_ALARM_DATETIME;
2475 Note->Entries[i-j].Date = Priv->ReturnDateTime; 2478 Note->Entries[i-j].Date = Priv->ReturnDateTime;
2476 dt = &(Note->Entries[i-j].Date); 2479 dt = &(Note->Entries[i-j].Date);
2477 } else { 2480 } else {
2478 j++; 2481 j++;
2479 Note->EntriesNum--; 2482 Note->EntriesNum--;
2480 dt->Hour = Priv->ReturnDateTime.Hour; 2483 dt->Hour = Priv->ReturnDateTime.Hour;
2481 dt->Minute = Priv->ReturnDateTime.Minute; 2484 dt->Minute = Priv->ReturnDateTime.Minute;
2482 dt->Second = Priv->ReturnDateTime.Second; 2485 dt->Second = Priv->ReturnDateTime.Second;
2483 dt = NULL; 2486 dt = NULL;
2484 } 2487 }
2485 break; 2488 break;
2486 case 5: 2489 case 5:
2487 if (Priv->ReturnType != Alcatel_string) { 2490 if (Priv->ReturnType != Alcatel_string) {
2488 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2491 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2489 Note->EntriesNum--; 2492 Note->EntriesNum--;
2490 j++; 2493 j++;
2491 break; 2494 break;
2492 } 2495 }
2493 Note->Entries[i-j].EntryType = CAL_TEXT; 2496 Note->Entries[i-j].EntryType = CAL_TEXT;
2494 CopyUnicodeString(Note->Entries[i-j].Text, Priv->ReturnString); 2497 CopyUnicodeString(Note->Entries[i-j].Text, Priv->ReturnString);
2495 break; 2498 break;
2496 case 6: 2499 case 6:
2497 if (Priv->ReturnType != Alcatel_bool) { 2500 if (Priv->ReturnType != Alcatel_bool) {
2498 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2501 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2499 Note->EntriesNum--; 2502 Note->EntriesNum--;
2500 j++; 2503 j++;
2501 break; 2504 break;
2502 } 2505 }
2503 Note->Entries[i-j].EntryType = CAL_PRIVATE; 2506 Note->Entries[i-j].EntryType = CAL_PRIVATE;
2504 Note->Entries[i-j].Number = Priv->ReturnInt; 2507 Note->Entries[i-j].Number = Priv->ReturnInt;
2505 break; 2508 break;
2506 case 7: 2509 case 7:
2507 if (Priv->ReturnType != Alcatel_enum) { 2510 if (Priv->ReturnType != Alcatel_enum) {
2508 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2511 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2509 Note->EntriesNum--; 2512 Note->EntriesNum--;
2510 j++; 2513 j++;
2511 break; 2514 break;
2512 } 2515 }
2513 switch (Priv->ReturnInt) { 2516 switch (Priv->ReturnInt) {
2514 case 0: 2517 case 0:
2515 Note->Type = GSM_CAL_MEETING; 2518 Note->Type = GSM_CAL_MEETING;
2516 break; 2519 break;
2517 case 2: 2520 case 2:
2518 Note->Type = GSM_CAL_BIRTHDAY; 2521 Note->Type = GSM_CAL_BIRTHDAY;
2519 break; 2522 break;
2520 case 3: 2523 case 3:
2521 Note->Type = GSM_CAL_CALL; 2524 Note->Type = GSM_CAL_CALL;
2522 break; 2525 break;
2523 case 4: 2526 case 4:
2524 Note->Type = GSM_CAL_ALARM; 2527 Note->Type = GSM_CAL_ALARM;
2525 break; 2528 break;
2526 case 5: 2529 case 5:
2527 Note->Type = GSM_CAL_DAILY_ALARM; 2530 Note->Type = GSM_CAL_DAILY_ALARM;
2528 break; 2531 break;
2529 case 9: 2532 case 9:
2530 /* I'd call this repeating event, but it makes no sense creating one more type ... */ 2533 /* I'd call this repeating event, but it makes no sense creating one more type ... */
2531 Note->Type = GSM_CAL_MEETING; 2534 Note->Type = GSM_CAL_MEETING;
2532 break; 2535 break;
2533 default: 2536 default:
2534 smprintf(s,"WARNING: Received unknown event type %02X!\n", Priv->ReturnInt); 2537 smprintf(s,"WARNING: Received unknown event type %02X!\n", Priv->ReturnInt);
@@ -2538,1454 +2541,1463 @@ static GSM_Error ALCATEL_GetCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Not
2538 Note->EntriesNum--; 2541 Note->EntriesNum--;
2539 break; 2542 break;
2540 case 8: 2543 case 8:
2541 if (Priv->ReturnType != Alcatel_int) { 2544 if (Priv->ReturnType != Alcatel_int) {
2542 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2545 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2543 Note->EntriesNum--; 2546 Note->EntriesNum--;
2544 j++; 2547 j++;
2545 break; 2548 break;
2546 } 2549 }
2547 /* 0xffffffff indicates that there is phone (BF5), 0 means none (BF5, BE5)*/ 2550 /* 0xffffffff indicates that there is phone (BF5), 0 means none (BF5, BE5)*/
2548 if (Priv->ReturnInt == 0xffffffff || Priv->ReturnInt == 0) { 2551 if (Priv->ReturnInt == 0xffffffff || Priv->ReturnInt == 0) {
2549 j++; 2552 j++;
2550 Note->EntriesNum--; 2553 Note->EntriesNum--;
2551 } else { 2554 } else {
2552 Note->Entries[i-j].EntryType = CAL_CONTACTID; 2555 Note->Entries[i-j].EntryType = CAL_CONTACTID;
2553 Note->Entries[i-j].Number = Priv->ReturnInt; 2556 Note->Entries[i-j].Number = Priv->ReturnInt;
2554 } 2557 }
2555 break; 2558 break;
2556 case 9: 2559 case 9:
2557 if (Priv->ReturnType != Alcatel_phone) { 2560 if (Priv->ReturnType != Alcatel_phone) {
2558 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2561 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2559 Note->EntriesNum--; 2562 Note->EntriesNum--;
2560 j++; 2563 j++;
2561 break; 2564 break;
2562 } 2565 }
2563 Note->Entries[i-j].EntryType = CAL_PHONE; 2566 Note->Entries[i-j].EntryType = CAL_PHONE;
2564 CopyUnicodeString(Note->Entries[i-j].Text, Priv->ReturnString); 2567 CopyUnicodeString(Note->Entries[i-j].Text, Priv->ReturnString);
2565 break; 2568 break;
2566 case 10: 2569 case 10:
2567 if (Priv->ReturnType != Alcatel_byte) { 2570 if (Priv->ReturnType != Alcatel_byte) {
2568 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2571 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2569 Note->EntriesNum--; 2572 Note->EntriesNum--;
2570 j++; 2573 j++;
2571 break; 2574 break;
2572 } 2575 }
2573 Note->Entries[i-j].EntryType = CAL_REPEAT_DAYOFWEEK; 2576 Note->Entries[i-j].EntryType = CAL_REPEAT_DAYOFWEEK;
2574 Note->Entries[i-j].Number = Priv->ReturnInt; 2577 Note->Entries[i-j].Number = Priv->ReturnInt;
2575 break; 2578 break;
2576 case 11: 2579 case 11:
2577 if (Priv->ReturnType != Alcatel_byte) { 2580 if (Priv->ReturnType != Alcatel_byte) {
2578 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2581 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2579 Note->EntriesNum--; 2582 Note->EntriesNum--;
2580 j++; 2583 j++;
2581 break; 2584 break;
2582 } 2585 }
2583 Note->Entries[i-j].EntryType = CAL_REPEAT_DAY; 2586 Note->Entries[i-j].EntryType = CAL_REPEAT_DAY;
2584 Note->Entries[i-j].Number = Priv->ReturnInt; 2587 Note->Entries[i-j].Number = Priv->ReturnInt;
2585 break; 2588 break;
2586 case 12: 2589 case 12:
2587 if (Priv->ReturnType != Alcatel_byte) { 2590 if (Priv->ReturnType != Alcatel_byte) {
2588 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2591 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2589 Note->EntriesNum--; 2592 Note->EntriesNum--;
2590 j++; 2593 j++;
2591 break; 2594 break;
2592 } 2595 }
2593 Note->Entries[i-j].EntryType = CAL_REPEAT_WEEKOFMONTH; 2596 Note->Entries[i-j].EntryType = CAL_REPEAT_WEEKOFMONTH;
2594 Note->Entries[i-j].Number = Priv->ReturnInt; 2597 Note->Entries[i-j].Number = Priv->ReturnInt;
2595 break; 2598 break;
2596 case 13: 2599 case 13:
2597 if (Priv->ReturnType != Alcatel_byte) { 2600 if (Priv->ReturnType != Alcatel_byte) {
2598 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2601 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2599 Note->EntriesNum--; 2602 Note->EntriesNum--;
2600 j++; 2603 j++;
2601 break; 2604 break;
2602 } 2605 }
2603 Note->Entries[i-j].EntryType = CAL_REPEAT_MONTH; 2606 Note->Entries[i-j].EntryType = CAL_REPEAT_MONTH;
2604 Note->Entries[i-j].Number = Priv->ReturnInt; 2607 Note->Entries[i-j].Number = Priv->ReturnInt;
2605 break; 2608 break;
2606 case 17: 2609 case 17:
2607 if (Priv->ReturnType != Alcatel_byte) { 2610 if (Priv->ReturnType != Alcatel_byte) {
2608 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2611 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2609 Note->EntriesNum--; 2612 Note->EntriesNum--;
2610 j++; 2613 j++;
2611 break; 2614 break;
2612 } 2615 }
2613 /* In BF5 birthday has frequency = 1 */ 2616 /* In BF5 birthday has frequency = 1 */
2614 if (Note->Type == GSM_CAL_BIRTHDAY) { 2617 if (Note->Type == GSM_CAL_BIRTHDAY) {
2615 Note->EntriesNum--; 2618 Note->EntriesNum--;
2616 j++; 2619 j++;
2617 } else { 2620 } else {
2618 Note->Entries[i-j].EntryType = CAL_REPEAT_FREQUENCY; 2621 Note->Entries[i-j].EntryType = CAL_REPEAT_FREQUENCY;
2619 Note->Entries[i-j].Number = Priv->ReturnInt; 2622 Note->Entries[i-j].Number = Priv->ReturnInt;
2620 } 2623 }
2621 break; 2624 break;
2622 case 18: 2625 case 18:
2623 if (Priv->ReturnType != Alcatel_date) { 2626 if (Priv->ReturnType != Alcatel_date) {
2624 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2627 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2625 Note->EntriesNum--; 2628 Note->EntriesNum--;
2626 j++; 2629 j++;
2627 break; 2630 break;
2628 } 2631 }
2629 if (!CheckDate(&(Priv->ReturnDateTime))) { 2632 if (!CheckDate(&(Priv->ReturnDateTime))) {
2630 smprintf(s,"WARNING: Invalid date in phone, ignoring\n"); 2633 smprintf(s,"WARNING: Invalid date in phone, ignoring\n");
2631 Note->EntriesNum--; 2634 Note->EntriesNum--;
2632 j++; 2635 j++;
2633 break; 2636 break;
2634 } 2637 }
2635 Note->Entries[i-j].EntryType = CAL_REPEAT_STARTDATE; 2638 Note->Entries[i-j].EntryType = CAL_REPEAT_STARTDATE;
2636 Note->Entries[i-j].Date = Priv->ReturnDateTime; 2639 Note->Entries[i-j].Date = Priv->ReturnDateTime;
2637 break; 2640 break;
2638 case 19: 2641 case 19:
2639 if (Priv->ReturnType != Alcatel_date) { 2642 if (Priv->ReturnType != Alcatel_date) {
2640 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2643 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2641 Note->EntriesNum--; 2644 Note->EntriesNum--;
2642 j++; 2645 j++;
2643 break; 2646 break;
2644 } 2647 }
2645 if (!CheckDate(&(Priv->ReturnDateTime))) { 2648 if (!CheckDate(&(Priv->ReturnDateTime))) {
2646 smprintf(s,"WARNING: Invalid date in phone, ignoring\n"); 2649 smprintf(s,"WARNING: Invalid date in phone, ignoring\n");
2647 Note->EntriesNum--; 2650 Note->EntriesNum--;
2648 j++; 2651 j++;
2649 break; 2652 break;
2650 } 2653 }
2651 Note->Entries[i-j].EntryType = CAL_REPEAT_STOPDATE; 2654 Note->Entries[i-j].EntryType = CAL_REPEAT_STOPDATE;
2652 Note->Entries[i-j].Date = Priv->ReturnDateTime; 2655 Note->Entries[i-j].Date = Priv->ReturnDateTime;
2653 break; 2656 break;
2654 case 20: 2657 case 20:
2655 if (Priv->ReturnType != Alcatel_date) { 2658 if (Priv->ReturnType != Alcatel_date) {
2656 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2659 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2657 Note->EntriesNum--; 2660 Note->EntriesNum--;
2658 j++; 2661 j++;
2659 break; 2662 break;
2660 } 2663 }
2661 if (!CheckDate(&(Priv->ReturnDateTime))) { 2664 if (!CheckDate(&(Priv->ReturnDateTime))) {
2662 smprintf(s,"WARNING: Invalid date in phone, ignoring\n"); 2665 smprintf(s,"WARNING: Invalid date in phone, ignoring\n");
2663 Note->EntriesNum--; 2666 Note->EntriesNum--;
2664 j++; 2667 j++;
2665 break; 2668 break;
2666 } 2669 }
2667 /* This entry had always same value as the 3rd (alarm date) */ 2670 /* This entry had always same value as the 3rd (alarm date) */
2668 j++; 2671 j++;
2669 Note->EntriesNum--; 2672 Note->EntriesNum--;
2670 break; 2673 break;
2671 case 21: 2674 case 21:
2672 if (Priv->ReturnType != Alcatel_time) { 2675 if (Priv->ReturnType != Alcatel_time) {
2673 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 2676 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
2674 Note->EntriesNum--; 2677 Note->EntriesNum--;
2675 j++; 2678 j++;
2676 break; 2679 break;
2677 } 2680 }
2678 if (!CheckTime(&(Priv->ReturnDateTime))) { 2681 if (!CheckTime(&(Priv->ReturnDateTime))) {
2679 smprintf(s,"WARNING: Invalid time in phone, ignoring\n"); 2682 smprintf(s,"WARNING: Invalid time in phone, ignoring\n");
2680 Note->EntriesNum--; 2683 Note->EntriesNum--;
2681 j++; 2684 j++;
2682 break; 2685 break;
2683 } 2686 }
2684 /* This entry had always same value as the 4th (alarm time) */ 2687 /* This entry had always same value as the 4th (alarm time) */
2685 j++; 2688 j++;
2686 Note->EntriesNum--; 2689 Note->EntriesNum--;
2687 break; 2690 break;
2688 default: 2691 default:
2689 Note->EntriesNum--; 2692 Note->EntriesNum--;
2690 j++; 2693 j++;
2691 smprintf(s,"WARNING: Received unknown field %02X, ignoring. Type = %02X. Value = ", Priv->CurrentFields[i], Priv->ReturnType); 2694 smprintf(s,"WARNING: Received unknown field %02X, ignoring. Type = %02X. Value = ", Priv->CurrentFields[i], Priv->ReturnType);
2692 switch (Priv->ReturnType) { 2695 switch (Priv->ReturnType) {
2693 case Alcatel_date: 2696 case Alcatel_date:
2694 smprintf(s, "%d.%d.%d", Priv->ReturnDateTime.Day, Priv->ReturnDateTime.Month, Priv->ReturnDateTime.Year); 2697 smprintf(s, "%d.%d.%d", Priv->ReturnDateTime.Day, Priv->ReturnDateTime.Month, Priv->ReturnDateTime.Year);
2695 break; 2698 break;
2696 case Alcatel_time: 2699 case Alcatel_time:
2697 smprintf(s, "%d:%d:%d", Priv->ReturnDateTime.Hour, Priv->ReturnDateTime.Minute, Priv->ReturnDateTime.Second); 2700 smprintf(s, "%d:%d:%d", Priv->ReturnDateTime.Hour, Priv->ReturnDateTime.Minute, Priv->ReturnDateTime.Second);
2698 break; 2701 break;
2699 case Alcatel_string: 2702 case Alcatel_string:
2700 case Alcatel_phone: 2703 case Alcatel_phone:
2701 smprintf(s, "\"%s\"",DecodeUnicodeString(Priv->ReturnString)); 2704 smprintf(s, "\"%s\"",DecodeUnicodeString(Priv->ReturnString));
2702 break; 2705 break;
2703 case Alcatel_enum: 2706 case Alcatel_enum:
2704 case Alcatel_bool: 2707 case Alcatel_bool:
2705 case Alcatel_int: 2708 case Alcatel_int:
2706 case Alcatel_byte: 2709 case Alcatel_byte:
2707 smprintf(s, "%d", Priv->ReturnInt); 2710 smprintf(s, "%d", Priv->ReturnInt);
2708 break; 2711 break;
2709 } 2712 }
2710 smprintf(s,"\n"); 2713 smprintf(s,"\n");
2711 } 2714 }
2712 } 2715 }
2713 /* The event didn't have start/stop time -> we need only date */ 2716 /* The event didn't have start/stop time -> we need only date */
2714 if (!evdateused) { 2717 if (!evdateused) {
2715 Note->EntriesNum++; 2718 Note->EntriesNum++;
2716 Note->Entries[i-j].EntryType = CAL_START_DATETIME; 2719 Note->Entries[i-j].EntryType = CAL_START_DATETIME;
2717 Note->Entries[i-j].Date = evdate; 2720 Note->Entries[i-j].Date = evdate;
2718 } 2721 }
2719 return ERR_NONE; 2722 return ERR_NONE;
2720} 2723}
2721 2724
2722static GSM_Error ALCATEL_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start) 2725static GSM_Error ALCATEL_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start)
2723{ 2726{
2724 GSM_Error error; 2727 GSM_Error error;
2725 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 2728 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
2726 2729
2727 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error; 2730 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error;
2728 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error; 2731 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error;
2729 if (Priv->CalendarItemsCount == 0) return ERR_EMPTY; 2732 if (Priv->CalendarItemsCount == 0) return ERR_EMPTY;
2730 2733
2731 if (start) Note->Location = 0; 2734 if (start) Note->Location = 0;
2732 if ((error = ALCATEL_GetNextId(s, &(Note->Location))) != ERR_NONE) return error; 2735 if ((error = ALCATEL_GetNextId(s, &(Note->Location))) != ERR_NONE) return error;
2733 2736
2734 return ALCATEL_GetCalendar(s, Note); 2737 return ALCATEL_GetCalendar(s, Note);
2735} 2738}
2736 2739
2737 2740
2738static GSM_Error ALCATEL_DeleteCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note) 2741static GSM_Error ALCATEL_DeleteCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note)
2739{ 2742{
2740 GSM_Error error; 2743 GSM_Error error;
2741 2744
2742 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error; 2745 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error;
2743 /* Delete Calendar */ 2746 /* Delete Calendar */
2744 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error; 2747 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error;
2745 if ((error = ALCATEL_IsIdAvailable(s, Note->Location))!= ERR_NONE) { 2748 if ((error = ALCATEL_IsIdAvailable(s, Note->Location))!= ERR_NONE) {
2746 /* Entry was empty => no error */ 2749 /* Entry was empty => no error */
2747 return ERR_NONE; 2750 return ERR_NONE;
2748 } 2751 }
2749 error = ALCATEL_DeleteItem(s, Note->Location); 2752 error = ALCATEL_DeleteItem(s, Note->Location);
2750 if (error != ERR_NONE) return error; 2753 if (error != ERR_NONE) return error;
2751 /* Refresh list */ 2754 /* Refresh list */
2752 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error; 2755 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error;
2753 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error; 2756 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error;
2754 return ERR_NONE; 2757 return ERR_NONE;
2755} 2758}
2756 2759
2757 2760
2758static GSM_Error ALCATEL_AddCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note) 2761static GSM_Error ALCATEL_AddCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note)
2759{ 2762{
2760 GSM_Error error; 2763 GSM_Error error;
2761 unsigned int val; 2764 unsigned int val;
2762 bool contact_set = false; 2765 bool contact_set = false;
2763 bool phone_set = false; 2766 bool phone_set = false;
2764 bool date_set = false; 2767 bool date_set = false;
2765 bool repeating = false; 2768 bool repeating = false;
2766 int i; 2769 int i;
2767 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 2770 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
2768 2771
2769 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error; 2772 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error;
2770 if ((error = ALCATEL_GoToBinaryState(s, StateEdit, TypeCalendar, 0))!= ERR_NONE) return error; 2773 if ((error = ALCATEL_GoToBinaryState(s, StateEdit, TypeCalendar, 0))!= ERR_NONE) return error;
2771 2774
2772 for (i = 0; i < Note->EntriesNum; i++) { 2775 for (i = 0; i < Note->EntriesNum; i++) {
2773 switch (Note->Entries[i].EntryType) { 2776 switch (Note->Entries[i].EntryType) {
2774 case CAL_START_DATETIME: 2777 case CAL_START_DATETIME:
2775 if (!date_set) { 2778 if (!date_set) {
2776 if ((error = ALCATEL_CreateField(s, Alcatel_date, 0, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2779 if ((error = ALCATEL_CreateField(s, Alcatel_date, 0, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2777 date_set = true; 2780 date_set = true;
2778 } 2781 }
2779 if ((error = ALCATEL_CreateField(s, Alcatel_time, 1, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2782 if ((error = ALCATEL_CreateField(s, Alcatel_time, 1, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2780 break; 2783 break;
2781 case CAL_END_DATETIME: 2784 case CAL_END_DATETIME:
2782 if (!date_set) { 2785 if (!date_set) {
2783 if ((error = ALCATEL_CreateField(s, Alcatel_date, 0, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2786 if ((error = ALCATEL_CreateField(s, Alcatel_date, 0, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2784 date_set = true; 2787 date_set = true;
2785 } 2788 }
2786 if ((error = ALCATEL_CreateField(s, Alcatel_time, 2, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2789 if ((error = ALCATEL_CreateField(s, Alcatel_time, 2, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2787 break; 2790 break;
2788 case CAL_ALARM_DATETIME: 2791 case CAL_ALARM_DATETIME:
2789 if ((error = ALCATEL_CreateField(s, Alcatel_date, 3, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2792 if ((error = ALCATEL_CreateField(s, Alcatel_date, 3, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2790 if ((error = ALCATEL_CreateField(s, Alcatel_time, 4, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2793 if ((error = ALCATEL_CreateField(s, Alcatel_time, 4, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2791 if (Note->Type == GSM_CAL_ALARM || Note->Type == GSM_CAL_DAILY_ALARM) { 2794 if (Note->Type == GSM_CAL_ALARM || Note->Type == GSM_CAL_DAILY_ALARM) {
2792 if ((error = ALCATEL_CreateField(s, Alcatel_date, 20, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2795 if ((error = ALCATEL_CreateField(s, Alcatel_date, 20, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2793 if ((error = ALCATEL_CreateField(s, Alcatel_time, 21, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2796 if ((error = ALCATEL_CreateField(s, Alcatel_time, 21, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2794 } 2797 }
2795 break; 2798 break;
2796 case CAL_TEXT: 2799 case CAL_TEXT:
2797 if ((error = ALCATEL_CreateField(s, Alcatel_string, 5, Note->Entries[i].Text)) != ERR_NONE) return error; 2800 if ((error = ALCATEL_CreateField(s, Alcatel_string, 5, Note->Entries[i].Text)) != ERR_NONE) return error;
2798 break; 2801 break;
2799 case CAL_PRIVATE: 2802 case CAL_PRIVATE:
2800 if ((error = ALCATEL_CreateField(s, Alcatel_bool, 6, &(Note->Entries[i].Number))) != ERR_NONE) return error; 2803 if ((error = ALCATEL_CreateField(s, Alcatel_bool, 6, &(Note->Entries[i].Number))) != ERR_NONE) return error;
2801 break; 2804 break;
2802 case CAL_CONTACTID: 2805 case CAL_CONTACTID:
2803 if ((error = ALCATEL_CreateField(s, Alcatel_int, 8, &(Note->Entries[i].Number))) != ERR_NONE) return error; 2806 if ((error = ALCATEL_CreateField(s, Alcatel_int, 8, &(Note->Entries[i].Number))) != ERR_NONE) return error;
2804 contact_set = true; 2807 contact_set = true;
2805 break; 2808 break;
2806 case CAL_PHONE: 2809 case CAL_PHONE:
2807 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 9, Note->Entries[i].Text)) != ERR_NONE) return error; 2810 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 9, Note->Entries[i].Text)) != ERR_NONE) return error;
2808 phone_set = true; 2811 phone_set = true;
2809 break; 2812 break;
2810 case CAL_REPEAT_DAYOFWEEK: 2813 case CAL_REPEAT_DAYOFWEEK:
2811 if ((error = ALCATEL_CreateField(s, Alcatel_byte, 10, &(Note->Entries[i].Number))) != ERR_NONE) return error; 2814 if ((error = ALCATEL_CreateField(s, Alcatel_byte, 10, &(Note->Entries[i].Number))) != ERR_NONE) return error;
2812 repeating = true; 2815 repeating = true;
2813 break; 2816 break;
2814 case CAL_REPEAT_DAY: 2817 case CAL_REPEAT_DAY:
2815 if ((error = ALCATEL_CreateField(s, Alcatel_byte, 11, &(Note->Entries[i].Number))) != ERR_NONE) return error; 2818 if ((error = ALCATEL_CreateField(s, Alcatel_byte, 11, &(Note->Entries[i].Number))) != ERR_NONE) return error;
2816 repeating = true; 2819 repeating = true;
2817 break; 2820 break;
2818 case CAL_REPEAT_WEEKOFMONTH: 2821 case CAL_REPEAT_WEEKOFMONTH:
2819 if ((error = ALCATEL_CreateField(s, Alcatel_byte, 12, &(Note->Entries[i].Number))) != ERR_NONE) return error; 2822 if ((error = ALCATEL_CreateField(s, Alcatel_byte, 12, &(Note->Entries[i].Number))) != ERR_NONE) return error;
2820 repeating = true; 2823 repeating = true;
2821 break; 2824 break;
2822 case CAL_REPEAT_MONTH: 2825 case CAL_REPEAT_MONTH:
2823 if ((error = ALCATEL_CreateField(s, Alcatel_byte, 13, &(Note->Entries[i].Number))) != ERR_NONE) return error; 2826 if ((error = ALCATEL_CreateField(s, Alcatel_byte, 13, &(Note->Entries[i].Number))) != ERR_NONE) return error;
2824 repeating = true; 2827 repeating = true;
2825 break; 2828 break;
2826 case CAL_REPEAT_FREQUENCY: 2829 case CAL_REPEAT_FREQUENCY:
2827 if ((error = ALCATEL_CreateField(s, Alcatel_byte, 17, &(Note->Entries[i].Number))) != ERR_NONE) return error; 2830 if ((error = ALCATEL_CreateField(s, Alcatel_byte, 17, &(Note->Entries[i].Number))) != ERR_NONE) return error;
2828 repeating = true; 2831 repeating = true;
2829 break; 2832 break;
2830 case CAL_REPEAT_STARTDATE: 2833 case CAL_REPEAT_STARTDATE:
2831 if ((error = ALCATEL_CreateField(s, Alcatel_date, 18, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2834 if ((error = ALCATEL_CreateField(s, Alcatel_date, 18, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2832 repeating = true; 2835 repeating = true;
2833 break; 2836 break;
2834 case CAL_REPEAT_STOPDATE: 2837 case CAL_REPEAT_STOPDATE:
2835 if ((error = ALCATEL_CreateField(s, Alcatel_date, 19, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2838 if ((error = ALCATEL_CreateField(s, Alcatel_date, 19, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2836 repeating = true; 2839 repeating = true;
2837 break; 2840 break;
2838 case CAL_SILENT_ALARM_DATETIME: 2841 case CAL_SILENT_ALARM_DATETIME:
2839 case CAL_RECURRANCE: 2842 case CAL_RECURRANCE:
2840 case CAL_LOCATION: 2843 case CAL_LOCATION:
2841 smprintf(s,"WARNING: Ignoring entry %d, not supported by phone\n", Note->Entries[i].EntryType); 2844 smprintf(s,"WARNING: Ignoring entry %d, not supported by phone\n", Note->Entries[i].EntryType);
2842 break; 2845 break;
2843 } 2846 }
2844 } 2847 }
2845 2848
2846 switch (Note->Type) { 2849 switch (Note->Type) {
2847 case GSM_CAL_CALL: 2850 case GSM_CAL_CALL:
2848 val = 3; 2851 val = 3;
2849 break; 2852 break;
2850 case GSM_CAL_BIRTHDAY: 2853 case GSM_CAL_BIRTHDAY:
2851 val = 2; 2854 val = 2;
2852 break; 2855 break;
2853 case GSM_CAL_ALARM: 2856 case GSM_CAL_ALARM:
2854 val = 4; 2857 val = 4;
2855 break; 2858 break;
2856 case GSM_CAL_DAILY_ALARM: 2859 case GSM_CAL_DAILY_ALARM:
2857 val = 5; 2860 val = 5;
2858 break; 2861 break;
2859 default: 2862 default:
2860 if (repeating) { 2863 if (repeating) {
2861 val = 9; 2864 val = 9;
2862 } else { 2865 } else {
2863 val = 0; 2866 val = 0;
2864 } 2867 }
2865 } 2868 }
2866 if ((error = ALCATEL_CreateField(s, Alcatel_enum, 7, &val)) != ERR_NONE) return error; 2869 if ((error = ALCATEL_CreateField(s, Alcatel_enum, 7, &val)) != ERR_NONE) return error;
2867 2870
2868 if (!contact_set) { 2871 if (!contact_set) {
2869 if (phone_set) { 2872 if (phone_set) {
2870 val = 0xffffffff; 2873 val = 0xffffffff;
2871 } else { 2874 } else {
2872 val = 0; 2875 val = 0;
2873 } 2876 }
2874 if ((error = ALCATEL_CreateField(s, Alcatel_int, 8, &val)) != ERR_NONE) return error; 2877 if ((error = ALCATEL_CreateField(s, Alcatel_int, 8, &val)) != ERR_NONE) return error;
2875 } 2878 }
2876 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error; 2879 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error;
2877 Note->Location = Priv->CommitedRecord; 2880 Note->Location = Priv->CommitedRecord;
2878 /* Refresh list */ 2881 /* Refresh list */
2879 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error; 2882 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error;
2880 return ERR_NONE; 2883 return ERR_NONE;
2881} 2884}
2882 2885
2883static GSM_Error ALCATEL_SetCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note) 2886static GSM_Error ALCATEL_SetCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note)
2884{ 2887{
2885 GSM_Error error; 2888 GSM_Error error;
2886 unsigned int val; 2889 unsigned int val;
2887 bool contact_set = false; 2890 bool contact_set = false;
2888 bool phone_set = false; 2891 bool phone_set = false;
2889 bool date_set = false; 2892 bool date_set = false;
2890 bool repeating = false; 2893 bool repeating = false;
2891 int i; 2894 int i;
2892 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 2895 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
2893 bool UpdatedFields[22]; 2896 bool UpdatedFields[22];
2894 2897
2895 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error; 2898 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error;
2896 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error; 2899 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error;
2897 if ((error = ALCATEL_IsIdAvailable(s, Note->Location))!= ERR_NONE) { 2900 if ((error = ALCATEL_IsIdAvailable(s, Note->Location))!= ERR_NONE) {
2898 /* Entry doesn't exist, we will create new one */ 2901 /* Entry doesn't exist, we will create new one */
2899 return ALCATEL_AddCalendar(s, Note); 2902 return ALCATEL_AddCalendar(s, Note);
2900 } 2903 }
2901 /* Get fields for current item */ 2904 /* Get fields for current item */
2902 if ((error = ALCATEL_GetFields(s, Note->Location))!= ERR_NONE) return error; 2905 if ((error = ALCATEL_GetFields(s, Note->Location))!= ERR_NONE) return error;
2903 2906
2904 for (i = 0; i < 22; i++) { UpdatedFields[i] = false; } 2907 for (i = 0; i < 22; i++) { UpdatedFields[i] = false; }
2905 2908
2906 if ((error = ALCATEL_GoToBinaryState(s, StateEdit, TypeCalendar, Note->Location))!= ERR_NONE) return error; 2909 if ((error = ALCATEL_GoToBinaryState(s, StateEdit, TypeCalendar, Note->Location))!= ERR_NONE) return error;
2907 2910
2908 for (i = 0; i < Note->EntriesNum; i++) { 2911 for (i = 0; i < Note->EntriesNum; i++) {
2909 switch (Note->Entries[i].EntryType) { 2912 switch (Note->Entries[i].EntryType) {
2910 case CAL_START_DATETIME: 2913 case CAL_START_DATETIME:
2911 if (!date_set) { 2914 if (!date_set) {
2912 UpdatedFields[0] = true; 2915 UpdatedFields[0] = true;
2913 if ((error = ALCATEL_UpdateField(s, Alcatel_date, Note->Location, 0, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2916 if ((error = ALCATEL_UpdateField(s, Alcatel_date, Note->Location, 0, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2914 date_set = true; 2917 date_set = true;
2915 } 2918 }
2916 UpdatedFields[1] = true; 2919 UpdatedFields[1] = true;
2917 if ((error = ALCATEL_UpdateField(s, Alcatel_time, Note->Location, 1, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2920 if ((error = ALCATEL_UpdateField(s, Alcatel_time, Note->Location, 1, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2918 break; 2921 break;
2919 case CAL_END_DATETIME: 2922 case CAL_END_DATETIME:
2920 if (!date_set) { 2923 if (!date_set) {
2921 UpdatedFields[0] = true; 2924 UpdatedFields[0] = true;
2922 if ((error = ALCATEL_UpdateField(s, Alcatel_date, Note->Location, 0, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2925 if ((error = ALCATEL_UpdateField(s, Alcatel_date, Note->Location, 0, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2923 date_set = true; 2926 date_set = true;
2924 } 2927 }
2925 UpdatedFields[2] = true; if ((error = ALCATEL_UpdateField(s, Alcatel_time, Note->Location, 2, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2928 UpdatedFields[2] = true; if ((error = ALCATEL_UpdateField(s, Alcatel_time, Note->Location, 2, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2926 break; 2929 break;
2927 case CAL_ALARM_DATETIME: 2930 case CAL_ALARM_DATETIME:
2928 UpdatedFields[3] = true; 2931 UpdatedFields[3] = true;
2929 if ((error = ALCATEL_UpdateField(s, Alcatel_date, Note->Location, 3, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2932 if ((error = ALCATEL_UpdateField(s, Alcatel_date, Note->Location, 3, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2930 UpdatedFields[4] = true; 2933 UpdatedFields[4] = true;
2931 if ((error = ALCATEL_UpdateField(s, Alcatel_time, Note->Location, 4, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2934 if ((error = ALCATEL_UpdateField(s, Alcatel_time, Note->Location, 4, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2932 if (Note->Type == GSM_CAL_ALARM || Note->Type == GSM_CAL_DAILY_ALARM) { 2935 if (Note->Type == GSM_CAL_ALARM || Note->Type == GSM_CAL_DAILY_ALARM) {
2933 UpdatedFields[20] = true; 2936 UpdatedFields[20] = true;
2934 if ((error = ALCATEL_UpdateField(s, Alcatel_date, Note->Location, 20, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2937 if ((error = ALCATEL_UpdateField(s, Alcatel_date, Note->Location, 20, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2935 UpdatedFields[21] = true; 2938 UpdatedFields[21] = true;
2936 if ((error = ALCATEL_UpdateField(s, Alcatel_time, Note->Location, 21, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2939 if ((error = ALCATEL_UpdateField(s, Alcatel_time, Note->Location, 21, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2937 } 2940 }
2938 break; 2941 break;
2939 case CAL_TEXT: 2942 case CAL_TEXT:
2940 UpdatedFields[5] = true; 2943 UpdatedFields[5] = true;
2941 if ((error = ALCATEL_UpdateField(s, Alcatel_string, Note->Location, 5, Note->Entries[i].Text)) != ERR_NONE) return error; 2944 if ((error = ALCATEL_UpdateField(s, Alcatel_string, Note->Location, 5, Note->Entries[i].Text)) != ERR_NONE) return error;
2942 break; 2945 break;
2943 case CAL_PRIVATE: 2946 case CAL_PRIVATE:
2944 UpdatedFields[6] = true; 2947 UpdatedFields[6] = true;
2945 if ((error = ALCATEL_UpdateField(s, Alcatel_bool, Note->Location, 6, &(Note->Entries[i].Number))) != ERR_NONE) return error; 2948 if ((error = ALCATEL_UpdateField(s, Alcatel_bool, Note->Location, 6, &(Note->Entries[i].Number))) != ERR_NONE) return error;
2946 break; 2949 break;
2947 case CAL_CONTACTID: 2950 case CAL_CONTACTID:
2948 UpdatedFields[8] = true; 2951 UpdatedFields[8] = true;
2949 if ((error = ALCATEL_UpdateField(s, Alcatel_int, Note->Location, 8, &(Note->Entries[i].Number))) != ERR_NONE) return error; 2952 if ((error = ALCATEL_UpdateField(s, Alcatel_int, Note->Location, 8, &(Note->Entries[i].Number))) != ERR_NONE) return error;
2950 contact_set = true; 2953 contact_set = true;
2951 break; 2954 break;
2952 case CAL_PHONE: 2955 case CAL_PHONE:
2953 UpdatedFields[9] = true; 2956 UpdatedFields[9] = true;
2954 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, Note->Location, 9, Note->Entries[i].Text)) != ERR_NONE) return error; 2957 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, Note->Location, 9, Note->Entries[i].Text)) != ERR_NONE) return error;
2955 phone_set = true; 2958 phone_set = true;
2956 break; 2959 break;
2957 case CAL_REPEAT_DAYOFWEEK: 2960 case CAL_REPEAT_DAYOFWEEK:
2958 UpdatedFields[10] = true; 2961 UpdatedFields[10] = true;
2959 if ((error = ALCATEL_UpdateField(s, Alcatel_byte, Note->Location, 10, &(Note->Entries[i].Number))) != ERR_NONE) return error; 2962 if ((error = ALCATEL_UpdateField(s, Alcatel_byte, Note->Location, 10, &(Note->Entries[i].Number))) != ERR_NONE) return error;
2960 repeating = true; 2963 repeating = true;
2961 break; 2964 break;
2962 case CAL_REPEAT_DAY: 2965 case CAL_REPEAT_DAY:
2963 UpdatedFields[11] = true; 2966 UpdatedFields[11] = true;
2964 if ((error = ALCATEL_UpdateField(s, Alcatel_byte, Note->Location, 11, &(Note->Entries[i].Number))) != ERR_NONE) return error; 2967 if ((error = ALCATEL_UpdateField(s, Alcatel_byte, Note->Location, 11, &(Note->Entries[i].Number))) != ERR_NONE) return error;
2965 repeating = true; 2968 repeating = true;
2966 break; 2969 break;
2967 case CAL_REPEAT_WEEKOFMONTH: 2970 case CAL_REPEAT_WEEKOFMONTH:
2968 UpdatedFields[12] = true; 2971 UpdatedFields[12] = true;
2969 if ((error = ALCATEL_UpdateField(s, Alcatel_byte, Note->Location, 12, &(Note->Entries[i].Number))) != ERR_NONE) return error; 2972 if ((error = ALCATEL_UpdateField(s, Alcatel_byte, Note->Location, 12, &(Note->Entries[i].Number))) != ERR_NONE) return error;
2970 repeating = true; 2973 repeating = true;
2971 break; 2974 break;
2972 case CAL_REPEAT_MONTH: 2975 case CAL_REPEAT_MONTH:
2973 UpdatedFields[13] = true; 2976 UpdatedFields[13] = true;
2974 if ((error = ALCATEL_UpdateField(s, Alcatel_byte, Note->Location, 13, &(Note->Entries[i].Number))) != ERR_NONE) return error; 2977 if ((error = ALCATEL_UpdateField(s, Alcatel_byte, Note->Location, 13, &(Note->Entries[i].Number))) != ERR_NONE) return error;
2975 repeating = true; 2978 repeating = true;
2976 break; 2979 break;
2977 case CAL_REPEAT_FREQUENCY: 2980 case CAL_REPEAT_FREQUENCY:
2978 UpdatedFields[17] = true; 2981 UpdatedFields[17] = true;
2979 if ((error = ALCATEL_UpdateField(s, Alcatel_byte, Note->Location, 17, &(Note->Entries[i].Number))) != ERR_NONE) return error; 2982 if ((error = ALCATEL_UpdateField(s, Alcatel_byte, Note->Location, 17, &(Note->Entries[i].Number))) != ERR_NONE) return error;
2980 repeating = true; 2983 repeating = true;
2981 break; 2984 break;
2982 case CAL_REPEAT_STARTDATE: 2985 case CAL_REPEAT_STARTDATE:
2983 UpdatedFields[18] = true; 2986 UpdatedFields[18] = true;
2984 if ((error = ALCATEL_UpdateField(s, Alcatel_date, Note->Location, 18, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2987 if ((error = ALCATEL_UpdateField(s, Alcatel_date, Note->Location, 18, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2985 repeating = true; 2988 repeating = true;
2986 break; 2989 break;
2987 case CAL_REPEAT_STOPDATE: 2990 case CAL_REPEAT_STOPDATE:
2988 UpdatedFields[19] = true; 2991 UpdatedFields[19] = true;
2989 if ((error = ALCATEL_UpdateField(s, Alcatel_date, Note->Location, 19, &(Note->Entries[i].Date))) != ERR_NONE) return error; 2992 if ((error = ALCATEL_UpdateField(s, Alcatel_date, Note->Location, 19, &(Note->Entries[i].Date))) != ERR_NONE) return error;
2990 repeating = true; 2993 repeating = true;
2991 break; 2994 break;
2992 case CAL_SILENT_ALARM_DATETIME: 2995 case CAL_SILENT_ALARM_DATETIME:
2993 case CAL_RECURRANCE: 2996 case CAL_RECURRANCE:
2994 case CAL_LOCATION: 2997 case CAL_LOCATION:
2995 smprintf(s,"WARNING: Ignoring entry %d, not supported by phone\n", Note->Entries[i].EntryType); 2998 smprintf(s,"WARNING: Ignoring entry %d, not supported by phone\n", Note->Entries[i].EntryType);
2996 break; 2999 break;
2997 } 3000 }
2998 } 3001 }
2999 3002
3000 switch (Note->Type) { 3003 switch (Note->Type) {
3001 case GSM_CAL_CALL: 3004 case GSM_CAL_CALL:
3002 val = 3; 3005 val = 3;
3003 break; 3006 break;
3004 case GSM_CAL_BIRTHDAY: 3007 case GSM_CAL_BIRTHDAY:
3005 val = 2; 3008 val = 2;
3006 break; 3009 break;
3007 case GSM_CAL_ALARM: 3010 case GSM_CAL_ALARM:
3008 val = 4; 3011 val = 4;
3009 break; 3012 break;
3010 case GSM_CAL_DAILY_ALARM: 3013 case GSM_CAL_DAILY_ALARM:
3011 val = 5; 3014 val = 5;
3012 break; 3015 break;
3013 default: 3016 default:
3014 if (repeating) { 3017 if (repeating) {
3015 val = 9; 3018 val = 9;
3016 } else { 3019 } else {
3017 val = 0; 3020 val = 0;
3018 } 3021 }
3019 } 3022 }
3020 UpdatedFields[7] = true; 3023 UpdatedFields[7] = true;
3021 if ((error = ALCATEL_UpdateField(s, Alcatel_enum, Note->Location, 7, &val)) != ERR_NONE) return error; 3024 if ((error = ALCATEL_UpdateField(s, Alcatel_enum, Note->Location, 7, &val)) != ERR_NONE) return error;
3022 3025
3023 if (!contact_set) { 3026 if (!contact_set) {
3024 if (phone_set) { 3027 if (phone_set) {
3025 val = 0xffffffff; 3028 val = 0xffffffff;
3026 } else { 3029 } else {
3027 val = 0; 3030 val = 0;
3028 } 3031 }
3029 UpdatedFields[8] = true; 3032 UpdatedFields[8] = true;
3030 if ((error = ALCATEL_UpdateField(s, Alcatel_int, Note->Location, 8, &val)) != ERR_NONE) return error; 3033 if ((error = ALCATEL_UpdateField(s, Alcatel_int, Note->Location, 8, &val)) != ERR_NONE) return error;
3031 } 3034 }
3032 /* If we didn't update some field, we have to delete it... */ 3035 /* If we didn't update some field, we have to delete it... */
3033 for (i=0; i<Priv->CurrentFieldsCount; i++) { 3036 for (i=0; i<Priv->CurrentFieldsCount; i++) {
3034 if (!UpdatedFields[Priv->CurrentFields[i]]) if ((error = ALCATEL_DeleteField(s, Note->Location, Priv->CurrentFields[i])) != ERR_NONE) return error; 3037 if (!UpdatedFields[Priv->CurrentFields[i]]) if ((error = ALCATEL_DeleteField(s, Note->Location, Priv->CurrentFields[i])) != ERR_NONE) return error;
3035 } 3038 }
3036 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error; 3039 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error;
3037 return ERR_NONE; 3040 return ERR_NONE;
3038} 3041}
3039 3042
3040static GSM_Error ALCATEL_DeleteAllCalendar (GSM_StateMachine *s) 3043static GSM_Error ALCATEL_DeleteAllCalendar (GSM_StateMachine *s)
3041{ 3044{
3042 GSM_Error error; 3045 GSM_Error error;
3043 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 3046 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
3044 int i; 3047 int i;
3045 3048
3046 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error; 3049 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error;
3047 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error; 3050 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error;
3048 3051
3049 for (i=0; i<Priv->CalendarItemsCount; i++) { 3052 for (i=0; i<Priv->CalendarItemsCount; i++) {
3050 error = ALCATEL_DeleteItem(s, Priv->CalendarItems[i]); 3053 error = ALCATEL_DeleteItem(s, Priv->CalendarItems[i]);
3051 if (error != ERR_NONE) return error; 3054 if (error != ERR_NONE) return error;
3052 } 3055 }
3053 3056
3054 /* Refresh list */ 3057 /* Refresh list */
3055 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error; 3058 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error;
3056 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error; 3059 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error;
3057 3060
3058 return ERR_NONE; 3061 return ERR_NONE;
3059} 3062}
3060 3063
3061 3064
3062static GSM_Error ALCATEL_GetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm) 3065static GSM_Error ALCATEL_GetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm)
3063{ 3066{
3064 GSM_Error error; 3067 GSM_Error error;
3065 GSM_CalendarEntryNote; 3068 GSM_CalendarEntryNote;
3066 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 3069 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
3067 int i; 3070 int i;
3068 bool Found = false; 3071 bool Found = false;
3069 bool DateSet = false; 3072 bool DateSet = false;
3070 int alarm_number = alarm->Location; 3073 int alarm_number = alarm->Location;
3071 static GSM_DateTimenulldt = {0,0,0,0,0,0,0}; 3074 static GSM_DateTimenulldt = {0,0,0,0,0,0,0};
3072 3075
3073 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error; 3076 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error;
3074 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error; 3077 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error;
3075 3078
3076 for (i=0; i<Priv->CalendarItemsCount; i++) { 3079 for (i=0; i<Priv->CalendarItemsCount; i++) {
3077 if ((error = ALCATEL_GetFieldValue(s, Priv->CalendarItems[i], 7))!= ERR_NONE) return error; 3080 if ((error = ALCATEL_GetFieldValue(s, Priv->CalendarItems[i], 7))!= ERR_NONE) return error;
3078 if (Priv->ReturnType != Alcatel_enum) { 3081 if (Priv->ReturnType != Alcatel_enum) {
3079 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 3082 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
3080 continue; 3083 continue;
3081 } 3084 }
3082 if (Priv->ReturnInt == 4 || Priv->ReturnInt == 5) { 3085 if (Priv->ReturnInt == 4 || Priv->ReturnInt == 5) {
3083 alarm_number--; 3086 alarm_number--;
3084 if (alarm_number == 0) { 3087 if (alarm_number == 0) {
3085 Found = true; 3088 Found = true;
3086 break; 3089 break;
3087 } 3090 }
3088 } 3091 }
3089 } 3092 }
3090 3093
3091 if (!Found) return ERR_EMPTY; 3094 if (!Found) return ERR_EMPTY;
3092 3095
3093 Note.Location = Priv->CalendarItems[i]; 3096 Note.Location = Priv->CalendarItems[i];
3094 3097
3095 if ((error = ALCATEL_GetCalendar(s, &Note))!= ERR_NONE) return error; 3098 if ((error = ALCATEL_GetCalendar(s, &Note))!= ERR_NONE) return error;
3096 3099
3097 if (Note.Type == GSM_CAL_ALARM) { 3100 if (Note.Type == GSM_CAL_ALARM) {
3098 alarm->Repeating = false; 3101 alarm->Repeating = false;
3099 } else { 3102 } else {
3100 alarm->Repeating = true; 3103 alarm->Repeating = true;
3101 } 3104 }
3102 3105
3103 alarm->Text[0] = 0; alarm->Text[1] = 0; 3106 alarm->Text[0] = 0; alarm->Text[1] = 0;
3104 3107
3105 3108
3106 for (i = 0; i < Note.EntriesNum; i++) { 3109 for (i = 0; i < Note.EntriesNum; i++) {
3107 if (Note.Entries[i].EntryType == CAL_TEXT) { 3110 if (Note.Entries[i].EntryType == CAL_TEXT) {
3108 CopyUnicodeString(alarm->Text, Note.Entries[i].Text); 3111 CopyUnicodeString(alarm->Text, Note.Entries[i].Text);
3109 } else if (Note.Entries[i].EntryType == CAL_ALARM_DATETIME) { 3112 } else if (Note.Entries[i].EntryType == CAL_ALARM_DATETIME) {
3110 alarm->DateTime = Note.Entries[i].Date; 3113 alarm->DateTime = Note.Entries[i].Date;
3111 DateSet = false; 3114 DateSet = false;
3112 } 3115 }
3113 } 3116 }
3114 if (!DateSet) { 3117 if (!DateSet) {
3115 alarm->DateTime = nulldt; 3118 alarm->DateTime = nulldt;
3116 } 3119 }
3117 3120
3118 return ERR_NONE; 3121 return ERR_NONE;
3119} 3122}
3120 3123
3121 3124
3122static GSM_Error ALCATEL_SetAlarm (GSM_StateMachine *s, GSM_Alarm *alarm) 3125static GSM_Error ALCATEL_SetAlarm (GSM_StateMachine *s, GSM_Alarm *alarm)
3123{ 3126{
3124 GSM_Error error; 3127 GSM_Error error;
3125 GSM_CalendarEntryNote; 3128 GSM_CalendarEntryNote;
3126 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 3129 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
3127 GSM_DateTime dt; 3130 GSM_DateTime dt;
3128 int i; 3131 int i;
3129 bool Found = false; 3132 bool Found = false;
3130 int alarm_number = alarm->Location; 3133 int alarm_number = alarm->Location;
3131 3134
3132 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error; 3135 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeCalendar, 0))!= ERR_NONE) return error;
3133 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error; 3136 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error;
3134 3137
3135 for (i=0; i<Priv->CalendarItemsCount; i++) { 3138 for (i=0; i<Priv->CalendarItemsCount; i++) {
3136 if ((error = ALCATEL_GetFieldValue(s, Priv->CalendarItems[i], 7))!= ERR_NONE) return error; 3139 if ((error = ALCATEL_GetFieldValue(s, Priv->CalendarItems[i], 7))!= ERR_NONE) return error;
3137 if (Priv->ReturnType != Alcatel_enum) { 3140 if (Priv->ReturnType != Alcatel_enum) {
3138 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 3141 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
3139 continue; 3142 continue;
3140 } 3143 }
3141 if (Priv->ReturnInt == 4 || Priv->ReturnInt == 5) { 3144 if (Priv->ReturnInt == 4 || Priv->ReturnInt == 5) {
3142 alarm_number--; 3145 alarm_number--;
3143 if (alarm_number == 0) { 3146 if (alarm_number == 0) {
3144 Found = true; 3147 Found = true;
3145 break; 3148 break;
3146 } 3149 }
3147 } 3150 }
3148 } 3151 }
3149 3152
3150 if (Found) { 3153 if (Found) {
3151 Note.Location = Priv->CalendarItems[i]; 3154 Note.Location = Priv->CalendarItems[i];
3152 } 3155 }
3153 3156
3154 Note.EntriesNum = 1; 3157 Note.EntriesNum = 1;
3155 3158
3156 Note.Entries[0].EntryType = CAL_ALARM_DATETIME; 3159 Note.Entries[0].EntryType = CAL_ALARM_DATETIME;
3157 Note.Entries[0].Date = alarm->DateTime; 3160 Note.Entries[0].Date = alarm->DateTime;
3158 3161
3159 if (alarm->Repeating) { 3162 if (alarm->Repeating) {
3160 Note.Type = GSM_CAL_DAILY_ALARM; 3163 Note.Type = GSM_CAL_DAILY_ALARM;
3161 GSM_GetCurrentDateTime(&dt); 3164 GSM_GetCurrentDateTime(&dt);
3162 Note.Entries[0].Date.Day = dt.Day; 3165 Note.Entries[0].Date.Day = dt.Day;
3163 Note.Entries[0].Date.Month = dt.Month; 3166 Note.Entries[0].Date.Month = dt.Month;
3164 Note.Entries[0].Date.Year = dt.Year; 3167 Note.Entries[0].Date.Year = dt.Year;
3165 } else { 3168 } else {
3166 Note.Type = GSM_CAL_ALARM; 3169 Note.Type = GSM_CAL_ALARM;
3167 } 3170 }
3168 3171
3169 if (alarm->Text[0] != 0 || alarm->Text[1] != 0) { 3172 if (alarm->Text[0] != 0 || alarm->Text[1] != 0) {
3170 Note.EntriesNum++; 3173 Note.EntriesNum++;
3171 Note.Entries[1].EntryType = CAL_TEXT; 3174 Note.Entries[1].EntryType = CAL_TEXT;
3172 CopyUnicodeString(Note.Entries[1].Text, alarm->Text); 3175 CopyUnicodeString(Note.Entries[1].Text, alarm->Text);
3173 } 3176 }
3174 3177
3175 if (Found) { 3178 if (Found) {
3176 return ALCATEL_SetCalendar(s, &Note); 3179 return ALCATEL_SetCalendar(s, &Note);
3177 } else { 3180 } else {
3178 return ALCATEL_AddCalendar(s, &Note); 3181 return ALCATEL_AddCalendar(s, &Note);
3179 } 3182 }
3180} 3183}
3181 3184
3182 3185
3183static GSM_Error ALCATEL_GetToDoStatus(GSM_StateMachine *s, GSM_ToDoStatus *status) 3186static GSM_Error ALCATEL_GetToDoStatus(GSM_StateMachine *s, GSM_ToDoStatus *status)
3184{ 3187{
3185 GSM_Error error; 3188 GSM_Error error;
3186 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 3189 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
3187 3190
3188 status->Used = 0; 3191 status->Used = 0;
3189 3192
3190 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error; 3193 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error;
3191 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error; 3194 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error;
3192 3195
3193 status->Used = Priv->ToDoItemsCount; 3196 status->Used = Priv->ToDoItemsCount;
3194 return ERR_NONE; 3197 return ERR_NONE;
3195} 3198}
3196 3199
3197static GSM_Error ALCATEL_GetToDo (GSM_StateMachine *s, GSM_ToDoEntry *ToDo) 3200static GSM_Error ALCATEL_GetToDo (GSM_StateMachine *s, GSM_ToDoEntry *ToDo)
3198{ 3201{
3199 GSM_Error error; 3202 GSM_Error error;
3200 GSM_DateTime *dt = NULL; 3203 GSM_DateTime *dt = NULL;
3201 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 3204 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
3202 int i; 3205 int i;
3203 int j=0; 3206 int j=0;
3204 3207
3205 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error; 3208 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error;
3206 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error; 3209 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error;
3207 if ((error = ALCATEL_IsIdAvailable(s, ToDo->Location))!= ERR_NONE) { 3210 if ((error = ALCATEL_IsIdAvailable(s, ToDo->Location))!= ERR_NONE) {
3208 ToDo->EntriesNum = 0; 3211 ToDo->EntriesNum = 0;
3209 return error; 3212 return error;
3210 } 3213 }
3211 if ((error = ALCATEL_GetFields(s, ToDo->Location))!= ERR_NONE) return error; 3214 if ((error = ALCATEL_GetFields(s, ToDo->Location))!= ERR_NONE) return error;
3212 3215
3213 ToDo->EntriesNum = Priv->CurrentFieldsCount; 3216 ToDo->EntriesNum = Priv->CurrentFieldsCount;
3214 3217
3215 for (i=0; i < Priv->CurrentFieldsCount; i++) { 3218 for (i=0; i < Priv->CurrentFieldsCount; i++) {
3216 if ((error = ALCATEL_GetFieldValue(s, ToDo->Location, Priv->CurrentFields[i]))!= ERR_NONE) return error; 3219 if ((error = ALCATEL_GetFieldValue(s, ToDo->Location, Priv->CurrentFields[i]))!= ERR_NONE) return error;
3217 switch (Priv->CurrentFields[i]) { 3220 switch (Priv->CurrentFields[i]) {
3218 case 0: 3221 case 0:
3219 if (Priv->ReturnType != Alcatel_date) { 3222 if (Priv->ReturnType != Alcatel_date) {
3220 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 3223 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
3221 ToDo->EntriesNum--; 3224 ToDo->EntriesNum--;
3222 j++; 3225 j++;
3223 break; 3226 break;
3224 } 3227 }
3225 if (!CheckDate(&(Priv->ReturnDateTime))) { 3228 if (!CheckDate(&(Priv->ReturnDateTime))) {
3226 smprintf(s,"WARNING: Invalid date in phone, ignoring\n"); 3229 smprintf(s,"WARNING: Invalid date in phone, ignoring\n");
3227 ToDo->EntriesNum--; 3230 ToDo->EntriesNum--;
3228 j++; 3231 j++;
3229 break; 3232 break;
3230 } 3233 }
3231 ToDo->Entries[i-j].EntryType = TODO_END_DATETIME; 3234 ToDo->Entries[i-j].EntryType = TODO_END_DATETIME;
3232 ToDo->Entries[i-j].Date = Priv->ReturnDateTime; 3235 ToDo->Entries[i-j].Date = Priv->ReturnDateTime;
3233 break; 3236 break;
3234 case 1: 3237 case 1:
3235 if (Priv->ReturnType != Alcatel_bool) { 3238 if (Priv->ReturnType != Alcatel_bool) {
3236 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 3239 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
3237 ToDo->EntriesNum--; 3240 ToDo->EntriesNum--;
3238 j++; 3241 j++;
3239 break; 3242 break;
3240 } 3243 }
3241 ToDo->Entries[i-j].EntryType = TODO_COMPLETED; 3244 ToDo->Entries[i-j].EntryType = TODO_COMPLETED;
3242 ToDo->Entries[i-j].Number = Priv->ReturnInt; 3245 ToDo->Entries[i-j].Number = Priv->ReturnInt;
3243 break; 3246 break;
3244 case 2: 3247 case 2:
3245 if (Priv->ReturnType != Alcatel_date) { 3248 if (Priv->ReturnType != Alcatel_date) {
3246 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 3249 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
3247 ToDo->EntriesNum--; 3250 ToDo->EntriesNum--;
3248 j++; 3251 j++;
3249 break; 3252 break;
3250 } 3253 }
3251 if (!CheckDate(&(Priv->ReturnDateTime))) { 3254 if (!CheckDate(&(Priv->ReturnDateTime))) {
3252 smprintf(s,"WARNING: Invalid date in phone, ignoring\n"); 3255 smprintf(s,"WARNING: Invalid date in phone, ignoring\n");
3253 ToDo->EntriesNum--; 3256 ToDo->EntriesNum--;
3254 j++; 3257 j++;
3255 break; 3258 break;
3256 } 3259 }
3257 if (dt == NULL) { 3260 if (dt == NULL) {
3258 ToDo->Entries[i-j].EntryType = TODO_ALARM_DATETIME; 3261 ToDo->Entries[i-j].EntryType = TODO_ALARM_DATETIME;
3259 ToDo->Entries[i-j].Date = Priv->ReturnDateTime; 3262 ToDo->Entries[i-j].Date = Priv->ReturnDateTime;
3260 dt = &(ToDo->Entries[i-j].Date); 3263 dt = &(ToDo->Entries[i-j].Date);
3261 } else { 3264 } else {
3262 j++; 3265 j++;
3263 ToDo->EntriesNum--; 3266 ToDo->EntriesNum--;
3264 dt->Day = Priv->ReturnDateTime.Day; 3267 dt->Day = Priv->ReturnDateTime.Day;
3265 dt->Month = Priv->ReturnDateTime.Month; 3268 dt->Month = Priv->ReturnDateTime.Month;
3266 dt->Year = Priv->ReturnDateTime.Year; 3269 dt->Year = Priv->ReturnDateTime.Year;
3267 dt->Timezone = Priv->ReturnDateTime.Timezone; 3270 dt->Timezone = Priv->ReturnDateTime.Timezone;
3268 dt = NULL; 3271 dt = NULL;
3269 } 3272 }
3270 break; 3273 break;
3271 case 3: 3274 case 3:
3272 if (Priv->ReturnType != Alcatel_time) { 3275 if (Priv->ReturnType != Alcatel_time) {
3273 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 3276 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
3274 ToDo->EntriesNum--; 3277 ToDo->EntriesNum--;
3275 j++; 3278 j++;
3276 break; 3279 break;
3277 } 3280 }
3278 if (!CheckTime(&(Priv->ReturnDateTime))) { 3281 if (!CheckTime(&(Priv->ReturnDateTime))) {
3279 smprintf(s,"WARNING: Invalid time in phone, ignoring\n"); 3282 smprintf(s,"WARNING: Invalid time in phone, ignoring\n");
3280 ToDo->EntriesNum--; 3283 ToDo->EntriesNum--;
3281 j++; 3284 j++;
3282 break; 3285 break;
3283 } 3286 }
3284 if (dt == NULL) { 3287 if (dt == NULL) {
3285 ToDo->Entries[i-j].EntryType = TODO_ALARM_DATETIME; 3288 ToDo->Entries[i-j].EntryType = TODO_ALARM_DATETIME;
3286 ToDo->Entries[i-j].Date = Priv->ReturnDateTime; 3289 ToDo->Entries[i-j].Date = Priv->ReturnDateTime;
3287 dt = &(ToDo->Entries[i-j].Date); 3290 dt = &(ToDo->Entries[i-j].Date);
3288 } else { 3291 } else {
3289 j++; 3292 j++;
3290 ToDo->EntriesNum--; 3293 ToDo->EntriesNum--;
3291 dt->Hour = Priv->ReturnDateTime.Hour; 3294 dt->Hour = Priv->ReturnDateTime.Hour;
3292 dt->Minute = Priv->ReturnDateTime.Minute; 3295 dt->Minute = Priv->ReturnDateTime.Minute;
3293 dt->Second = Priv->ReturnDateTime.Second; 3296 dt->Second = Priv->ReturnDateTime.Second;
3294 dt = NULL; 3297 dt = NULL;
3295 } 3298 }
3296 break; 3299 break;
3297 case 4: 3300 case 4:
3298 if (Priv->ReturnType != Alcatel_string) { 3301 if (Priv->ReturnType != Alcatel_string) {
3299 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 3302 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
3300 ToDo->EntriesNum--; 3303 ToDo->EntriesNum--;
3301 j++; 3304 j++;
3302 break; 3305 break;
3303 } 3306 }
3304 ToDo->Entries[i-j].EntryType = TODO_TEXT; 3307 ToDo->Entries[i-j].EntryType = TODO_TEXT;
3305 CopyUnicodeString(ToDo->Entries[i-j].Text, Priv->ReturnString); 3308 CopyUnicodeString(ToDo->Entries[i-j].Text, Priv->ReturnString);
3306 break; 3309 break;
3307 case 5: 3310 case 5:
3308 if (Priv->ReturnType != Alcatel_bool) { 3311 if (Priv->ReturnType != Alcatel_bool) {
3309 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 3312 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
3310 ToDo->EntriesNum--; 3313 ToDo->EntriesNum--;
3311 j++; 3314 j++;
3312 break; 3315 break;
3313 } 3316 }
3314 ToDo->Entries[i-j].EntryType = TODO_PRIVATE; 3317 ToDo->Entries[i-j].EntryType = TODO_PRIVATE;
3315 ToDo->Entries[i-j].Number = Priv->ReturnInt; 3318 ToDo->Entries[i-j].Number = Priv->ReturnInt;
3316 break; 3319 break;
3317 case 6: 3320 case 6:
3318 if (Priv->ReturnType != Alcatel_byte) { 3321 if (Priv->ReturnType != Alcatel_byte) {
3319 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 3322 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
3320 ToDo->EntriesNum--; 3323 ToDo->EntriesNum--;
3321 j++; 3324 j++;
3322 break; 3325 break;
3323 } 3326 }
3324 if (Priv->ReturnInt == 255) { 3327 if (Priv->ReturnInt == 255) {
3325 /* 255 means no category */ 3328 /* 255 means no category */
3326 j++; 3329 j++;
3327 ToDo->EntriesNum--; 3330 ToDo->EntriesNum--;
3328 } else { 3331 } else {
3329 ToDo->Entries[i-j].EntryType = TODO_CATEGORY; 3332 ToDo->Entries[i-j].EntryType = TODO_CATEGORY;
3330 ToDo->Entries[i-j].Number = Priv->ReturnInt; 3333 ToDo->Entries[i-j].Number = Priv->ReturnInt;
3331 } 3334 }
3332 break; 3335 break;
3333 case 7: 3336 case 7:
3334 /* This one seems to be byte for BF5 and enum for BE5 */ 3337 /* This one seems to be byte for BF5 and enum for BE5 */
3335 if (Priv->ReturnType != Alcatel_enum && Priv->ReturnType != Alcatel_byte) { 3338 if (Priv->ReturnType != Alcatel_enum && Priv->ReturnType != Alcatel_byte) {
3336 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 3339 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
3337 ToDo->EntriesNum--; 3340 ToDo->EntriesNum--;
3338 j++; 3341 j++;
3339 break; 3342 break;
3340 } 3343 }
3341 switch (Priv->ReturnInt) { 3344 switch (Priv->ReturnInt) {
3342 case 0: 3345 case 0:
3343 ToDo->Priority = GSM_Priority_High; 3346 ToDo->Priority = GSM_Priority_High;
3344 break; 3347 break;
3345 case 1: 3348 case 1:
3346 ToDo->Priority = GSM_Priority_Medium; 3349 ToDo->Priority = GSM_Priority_Medium;
3347 break; 3350 break;
3348 case 2: 3351 case 2:
3349 ToDo->Priority = GSM_Priority_Low; 3352 ToDo->Priority = GSM_Priority_Low;
3350 break; 3353 break;
3351 default: 3354 default:
3352 ToDo->Priority = 0; 3355 ToDo->Priority = 0;
3353 smprintf(s,"WARNING: Received unexpected priority %02X, ignoring\n", Priv->ReturnInt); 3356 smprintf(s,"WARNING: Received unexpected priority %02X, ignoring\n", Priv->ReturnInt);
3354 } 3357 }
3355 j++; 3358 j++;
3356 ToDo->EntriesNum--; 3359 ToDo->EntriesNum--;
3357 break; 3360 break;
3358 case 8: 3361 case 8:
3359 if (Priv->ReturnType != Alcatel_int) { 3362 if (Priv->ReturnType != Alcatel_int) {
3360 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 3363 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
3361 ToDo->EntriesNum--; 3364 ToDo->EntriesNum--;
3362 j++; 3365 j++;
3363 break; 3366 break;
3364 } 3367 }
3365 /* 0xffffffff indicates that there is phone, 0 means none */ 3368 /* 0xffffffff indicates that there is phone, 0 means none */
3366 if (Priv->ReturnInt == 0xffffffff || Priv->ReturnInt == 0) { 3369 if (Priv->ReturnInt == 0xffffffff || Priv->ReturnInt == 0) {
3367 j++; 3370 j++;
3368 ToDo->EntriesNum--; 3371 ToDo->EntriesNum--;
3369 } else { 3372 } else {
3370 ToDo->Entries[i-j].EntryType = TODO_CONTACTID; 3373 ToDo->Entries[i-j].EntryType = TODO_CONTACTID;
3371 ToDo->Entries[i-j].Number = Priv->ReturnInt; 3374 ToDo->Entries[i-j].Number = Priv->ReturnInt;
3372 } 3375 }
3373 break; 3376 break;
3374 case 9: 3377 case 9:
3375 if (Priv->ReturnType != Alcatel_phone) { 3378 if (Priv->ReturnType != Alcatel_phone) {
3376 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 3379 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
3377 ToDo->EntriesNum--; 3380 ToDo->EntriesNum--;
3378 j++; 3381 j++;
3379 break; 3382 break;
3380 } 3383 }
3381 ToDo->Entries[i-j].EntryType = TODO_PHONE; 3384 ToDo->Entries[i-j].EntryType = TODO_PHONE;
3382 CopyUnicodeString(ToDo->Entries[i-j].Text, Priv->ReturnString); 3385 CopyUnicodeString(ToDo->Entries[i-j].Text, Priv->ReturnString);
3383 break; 3386 break;
3384 case 10: 3387 case 10:
3385 if (Priv->ReturnType != Alcatel_date) { 3388 if (Priv->ReturnType != Alcatel_date) {
3386 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 3389 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
3387 ToDo->EntriesNum--; 3390 ToDo->EntriesNum--;
3388 j++; 3391 j++;
3389 break; 3392 break;
3390 } 3393 }
3391 if (!CheckDate(&(Priv->ReturnDateTime))) { 3394 if (!CheckDate(&(Priv->ReturnDateTime))) {
3392 smprintf(s,"WARNING: Invalid date in phone, ignoring\n"); 3395 smprintf(s,"WARNING: Invalid date in phone, ignoring\n");
3393 ToDo->EntriesNum--; 3396 ToDo->EntriesNum--;
3394 j++; 3397 j++;
3395 break; 3398 break;
3396 } 3399 }
3397 /* This entry had always same value as the 2nd (alarm date) */ 3400 /* This entry had always same value as the 2nd (alarm date) */
3398 j++; 3401 j++;
3399 ToDo->EntriesNum--; 3402 ToDo->EntriesNum--;
3400 break; 3403 break;
3401 case 11: 3404 case 11:
3402 if (Priv->ReturnType != Alcatel_time) { 3405 if (Priv->ReturnType != Alcatel_time) {
3403 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType); 3406 smprintf(s,"WARNING: Received unexpected type %02X, ignoring\n", Priv->ReturnType);
3404 ToDo->EntriesNum--; 3407 ToDo->EntriesNum--;
3405 j++; 3408 j++;
3406 break; 3409 break;
3407 } 3410 }
3408 if (!CheckTime(&(Priv->ReturnDateTime))) { 3411 if (!CheckTime(&(Priv->ReturnDateTime))) {
3409 smprintf(s,"WARNING: Invalid time in phone, ignoring\n"); 3412 smprintf(s,"WARNING: Invalid time in phone, ignoring\n");
3410 ToDo->EntriesNum--; 3413 ToDo->EntriesNum--;
3411 j++; 3414 j++;
3412 break; 3415 break;
3413 } 3416 }
3414 /* This entry had always same value as the 3rd (alarm time) */ 3417 /* This entry had always same value as the 3rd (alarm time) */
3415 j++; 3418 j++;
3416 ToDo->EntriesNum--; 3419 ToDo->EntriesNum--;
3417 break; 3420 break;
3418 default: 3421 default:
3419 ToDo->EntriesNum--; 3422 ToDo->EntriesNum--;
3420 j++; 3423 j++;
3421 smprintf(s,"WARNING: Received unknown field %02X, ignoring. Type = %02X. Value = ", Priv->CurrentFields[i], Priv->ReturnType); 3424 smprintf(s,"WARNING: Received unknown field %02X, ignoring. Type = %02X. Value = ", Priv->CurrentFields[i], Priv->ReturnType);
3422 switch (Priv->ReturnType) { 3425 switch (Priv->ReturnType) {
3423 case Alcatel_date: 3426 case Alcatel_date:
3424 smprintf(s, "%d.%d.%d", Priv->ReturnDateTime.Day, Priv->ReturnDateTime.Month, Priv->ReturnDateTime.Year); 3427 smprintf(s, "%d.%d.%d", Priv->ReturnDateTime.Day, Priv->ReturnDateTime.Month, Priv->ReturnDateTime.Year);
3425 break; 3428 break;
3426 case Alcatel_time: 3429 case Alcatel_time:
3427 smprintf(s, "%d:%d:%d", Priv->ReturnDateTime.Hour, Priv->ReturnDateTime.Minute, Priv->ReturnDateTime.Second); 3430 smprintf(s, "%d:%d:%d", Priv->ReturnDateTime.Hour, Priv->ReturnDateTime.Minute, Priv->ReturnDateTime.Second);
3428 break; 3431 break;
3429 case Alcatel_string: 3432 case Alcatel_string:
3430 case Alcatel_phone: 3433 case Alcatel_phone:
3431 smprintf(s, "\"%s\"",DecodeUnicodeString(Priv->ReturnString)); 3434 smprintf(s, "\"%s\"",DecodeUnicodeString(Priv->ReturnString));
3432 break; 3435 break;
3433 case Alcatel_enum: 3436 case Alcatel_enum:
3434 case Alcatel_bool: 3437 case Alcatel_bool:
3435 case Alcatel_int: 3438 case Alcatel_int:
3436 case Alcatel_byte: 3439 case Alcatel_byte:
3437 smprintf(s, "%d", Priv->ReturnInt); 3440 smprintf(s, "%d", Priv->ReturnInt);
3438 break; 3441 break;
3439 } 3442 }
3440 smprintf(s,"\n"); 3443 smprintf(s,"\n");
3441 } 3444 }
3442 } 3445 }
3443 return ERR_NONE; 3446 return ERR_NONE;
3444} 3447}
3445 3448
3446static GSM_Error ALCATEL_GetNextToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool start) 3449static GSM_Error ALCATEL_GetNextToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool start)
3447{ 3450{
3448 GSM_Error error; 3451 GSM_Error error;
3449 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 3452 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
3450 3453
3451 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error; 3454 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error;
3452 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error; 3455 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error;
3453 if (Priv->ToDoItemsCount == 0) return ERR_EMPTY; 3456 if (Priv->ToDoItemsCount == 0) return ERR_EMPTY;
3454 3457
3455 if (start) ToDo->Location = 0; 3458 if (start) ToDo->Location = 0;
3456 if ((error = ALCATEL_GetNextId(s, &(ToDo->Location))) != ERR_NONE) return error; 3459 if ((error = ALCATEL_GetNextId(s, &(ToDo->Location))) != ERR_NONE) return error;
3457 3460
3458 return ALCATEL_GetToDo(s, ToDo); 3461 return ALCATEL_GetToDo(s, ToDo);
3459} 3462}
3460 3463
3461static GSM_Error ALCATEL_DeleteAllToDo (GSM_StateMachine *s) 3464static GSM_Error ALCATEL_DeleteAllToDo (GSM_StateMachine *s)
3462{ 3465{
3463 GSM_Error error; 3466 GSM_Error error;
3464 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 3467 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
3465 int i; 3468 int i;
3466 3469
3467 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error; 3470 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error;
3468 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error; 3471 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error;
3469 3472
3470 for (i=0; i<Priv->ToDoItemsCount; i++) { 3473 for (i=0; i<Priv->ToDoItemsCount; i++) {
3471 error = ALCATEL_DeleteItem(s, Priv->ToDoItems[i]); 3474 error = ALCATEL_DeleteItem(s, Priv->ToDoItems[i]);
3472 if (error != ERR_NONE) return error; 3475 if (error != ERR_NONE) return error;
3473 } 3476 }
3474 3477
3475 /* Refresh list */ 3478 /* Refresh list */
3476 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error; 3479 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error;
3477 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error; 3480 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error;
3478 3481
3479 return ERR_NONE; 3482 return ERR_NONE;
3480} 3483}
3481 3484
3482static GSM_Error ALCATEL_AddToDo (GSM_StateMachine *s, GSM_ToDoEntry *ToDo) 3485static GSM_Error ALCATEL_AddToDo (GSM_StateMachine *s, GSM_ToDoEntry *ToDo)
3483{ 3486{
3484 GSM_Error error; 3487 GSM_Error error;
3485 unsigned int val; 3488 unsigned int val;
3486 bool contact_set = false; 3489 bool contact_set = false;
3487 bool phone_set = false; 3490 bool phone_set = false;
3488 int i; 3491 int i;
3489 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 3492 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
3490 3493
3491 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error; 3494 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error;
3492 if ((error = ALCATEL_GoToBinaryState(s, StateEdit, TypeToDo, 0))!= ERR_NONE) return error; 3495 if ((error = ALCATEL_GoToBinaryState(s, StateEdit, TypeToDo, 0))!= ERR_NONE) return error;
3493 3496
3494 switch (ToDo->Priority) { 3497 switch (ToDo->Priority) {
3495 case GSM_Priority_High: 3498 case GSM_Priority_High:
3496 val = 0; 3499 val = 0;
3497 break; 3500 break;
3498 case GSM_Priority_Low: 3501 case GSM_Priority_Low:
3499 val = 2; 3502 val = 2;
3500 break; 3503 break;
3501 case GSM_Priority_Medium: 3504 case GSM_Priority_Medium:
3502 default: 3505 default:
3503 val = 1; 3506 val = 1;
3504 break; 3507 break;
3505 } 3508 }
3506 /* This one seems to be byte for BF5 and enum for BE5 */ 3509 /* This one seems to be byte for BF5 and enum for BE5 */
3507 if (s->Phone.Data.Priv.ALCATEL.ProtocolVersion == V_1_1) { 3510 if (s->Phone.Data.Priv.ALCATEL.ProtocolVersion == V_1_1) {
3508 if ((error = ALCATEL_CreateField(s, Alcatel_byte, 7, &val)) != ERR_NONE) return error; 3511 if ((error = ALCATEL_CreateField(s, Alcatel_byte, 7, &val)) != ERR_NONE) return error;
3509 } else { 3512 } else {
3510 if ((error = ALCATEL_CreateField(s, Alcatel_enum, 7, &val)) != ERR_NONE) return error; 3513 if ((error = ALCATEL_CreateField(s, Alcatel_enum, 7, &val)) != ERR_NONE) return error;
3511 } 3514 }
3512 3515
3513 for (i = 0; i < ToDo->EntriesNum; i++) { 3516 for (i = 0; i < ToDo->EntriesNum; i++) {
3514 switch (ToDo->Entries[i].EntryType) { 3517 switch (ToDo->Entries[i].EntryType) {
3515 case TODO_END_DATETIME: 3518 case TODO_END_DATETIME:
3516 if ((error = ALCATEL_CreateField(s, Alcatel_date, 0, &(ToDo->Entries[i].Date))) != ERR_NONE) return error; 3519 if ((error = ALCATEL_CreateField(s, Alcatel_date, 0, &(ToDo->Entries[i].Date))) != ERR_NONE) return error;
3517 break; 3520 break;
3518 case TODO_COMPLETED: 3521 case TODO_COMPLETED:
3519 if ((error = ALCATEL_CreateField(s, Alcatel_bool, 1, &(ToDo->Entries[i].Number))) != ERR_NONE) return error; 3522 if ((error = ALCATEL_CreateField(s, Alcatel_bool, 1, &(ToDo->Entries[i].Number))) != ERR_NONE) return error;
3520 break; 3523 break;
3521 case TODO_ALARM_DATETIME: 3524 case TODO_ALARM_DATETIME:
3522 if ((error = ALCATEL_CreateField(s, Alcatel_date, 2, &(ToDo->Entries[i].Date))) != ERR_NONE) return error; 3525 if ((error = ALCATEL_CreateField(s, Alcatel_date, 2, &(ToDo->Entries[i].Date))) != ERR_NONE) return error;
3523 if ((error = ALCATEL_CreateField(s, Alcatel_time, 3, &(ToDo->Entries[i].Date))) != ERR_NONE) return error; 3526 if ((error = ALCATEL_CreateField(s, Alcatel_time, 3, &(ToDo->Entries[i].Date))) != ERR_NONE) return error;
3524 if ((error = ALCATEL_CreateField(s, Alcatel_date, 10, &(ToDo->Entries[i].Date))) != ERR_NONE) return error; 3527 if ((error = ALCATEL_CreateField(s, Alcatel_date, 10, &(ToDo->Entries[i].Date))) != ERR_NONE) return error;
3525 if ((error = ALCATEL_CreateField(s, Alcatel_time, 11, &(ToDo->Entries[i].Date))) != ERR_NONE) return error; 3528 if ((error = ALCATEL_CreateField(s, Alcatel_time, 11, &(ToDo->Entries[i].Date))) != ERR_NONE) return error;
3526 break; 3529 break;
3527 case TODO_TEXT: 3530 case TODO_TEXT:
3528 if ((error = ALCATEL_CreateField(s, Alcatel_string, 4, ToDo->Entries[i].Text)) != ERR_NONE) return error; 3531 if ((error = ALCATEL_CreateField(s, Alcatel_string, 4, ToDo->Entries[i].Text)) != ERR_NONE) return error;
3529 break; 3532 break;
3530 case TODO_PRIVATE: 3533 case TODO_PRIVATE:
3531 if ((error = ALCATEL_CreateField(s, Alcatel_bool, 5, &(ToDo->Entries[i].Number))) != ERR_NONE) return error; 3534 if ((error = ALCATEL_CreateField(s, Alcatel_bool, 5, &(ToDo->Entries[i].Number))) != ERR_NONE) return error;
3532 break; 3535 break;
3533 case TODO_CATEGORY: 3536 case TODO_CATEGORY:
3534 if ((error = ALCATEL_CreateField(s, Alcatel_byte, 6, &(ToDo->Entries[i].Number))) != ERR_NONE) return error; 3537 if ((error = ALCATEL_CreateField(s, Alcatel_byte, 6, &(ToDo->Entries[i].Number))) != ERR_NONE) return error;
3535 break; 3538 break;
3536 case TODO_CONTACTID: 3539 case TODO_CONTACTID:
3537 if ((error = ALCATEL_CreateField(s, Alcatel_int, 8, &(ToDo->Entries[i].Number))) != ERR_NONE) return error; 3540 if ((error = ALCATEL_CreateField(s, Alcatel_int, 8, &(ToDo->Entries[i].Number))) != ERR_NONE) return error;
3538 contact_set = true; 3541 contact_set = true;
3539 break; 3542 break;
3540 case TODO_PHONE: 3543 case TODO_PHONE:
3541 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 9, ToDo->Entries[i].Text)) != ERR_NONE) return error; 3544 if ((error = ALCATEL_CreateField(s, Alcatel_phone, 9, ToDo->Entries[i].Text)) != ERR_NONE) return error;
3542 phone_set = true; 3545 phone_set = true;
3543 break; 3546 break;
3544 default: 3547 default:
3545 break; 3548 break;
3546 } 3549 }
3547 } 3550 }
3548 if (!contact_set) { 3551 if (!contact_set) {
3549 if (phone_set) { 3552 if (phone_set) {
3550 val = 0xffffffff; 3553 val = 0xffffffff;
3551 } else { 3554 } else {
3552 val = 0; 3555 val = 0;
3553 } 3556 }
3554 if ((error = ALCATEL_CreateField(s, Alcatel_int, 8, &val)) != ERR_NONE) return error; 3557 if ((error = ALCATEL_CreateField(s, Alcatel_int, 8, &val)) != ERR_NONE) return error;
3555 } 3558 }
3556 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error; 3559 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error;
3557 ToDo->Location = Priv->CommitedRecord; 3560 ToDo->Location = Priv->CommitedRecord;
3558 /* Refresh list */ 3561 /* Refresh list */
3559 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error; 3562 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error;
3560 return ERR_NONE; 3563 return ERR_NONE;
3561} 3564}
3562 3565
3563static GSM_Error ALCATEL_SetToDo (GSM_StateMachine *s, GSM_ToDoEntry *ToDo) 3566static GSM_Error ALCATEL_SetToDo (GSM_StateMachine *s, GSM_ToDoEntry *ToDo)
3564{ 3567{
3565 GSM_Error error; 3568 GSM_Error error;
3566 unsigned int val; 3569 unsigned int val;
3567 bool contact_set = false; 3570 bool contact_set = false;
3568 bool phone_set = false; 3571 bool phone_set = false;
3569 bool UpdatedFields[12]; 3572 bool UpdatedFields[12];
3570 int i; 3573 int i;
3571 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 3574 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
3572 3575
3573 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error; 3576 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error;
3574 /* Save modified ToDo */ 3577 /* Save modified ToDo */
3575 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error; 3578 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error;
3576 if ((error = ALCATEL_IsIdAvailable(s, ToDo->Location))!= ERR_NONE) { 3579 if ((error = ALCATEL_IsIdAvailable(s, ToDo->Location))!= ERR_NONE) {
3577 /* Entry doesn't exist, we will create new one */ 3580 /* Entry doesn't exist, we will create new one */
3578 return ALCATEL_AddToDo(s, ToDo); 3581 return ALCATEL_AddToDo(s, ToDo);
3579 } 3582 }
3580 /* Get fields for current item */ 3583 /* Get fields for current item */
3581 if ((error = ALCATEL_GetFields(s, ToDo->Location))!= ERR_NONE) return error; 3584 if ((error = ALCATEL_GetFields(s, ToDo->Location))!= ERR_NONE) return error;
3582 3585
3583 for (i = 0; i < 12; i++) { UpdatedFields[i] = false; } 3586 for (i = 0; i < 12; i++) { UpdatedFields[i] = false; }
3584 3587
3585 if ((error = ALCATEL_GoToBinaryState(s, StateEdit, TypeToDo, ToDo->Location))!= ERR_NONE) return error; 3588 if ((error = ALCATEL_GoToBinaryState(s, StateEdit, TypeToDo, ToDo->Location))!= ERR_NONE) return error;
3586 3589
3587 switch (ToDo->Priority) { 3590 switch (ToDo->Priority) {
3588 case GSM_Priority_High: 3591 case GSM_Priority_High:
3589 val = 0; 3592 val = 0;
3590 break; 3593 break;
3591 case GSM_Priority_Low: 3594 case GSM_Priority_Low:
3592 val = 2; 3595 val = 2;
3593 break; 3596 break;
3594 case GSM_Priority_Medium: 3597 case GSM_Priority_Medium:
3595 default: 3598 default:
3596 val = 1; 3599 val = 1;
3597 break; 3600 break;
3598 } 3601 }
3599 /* This one seems to be byte for BF5 and enum for BE5 */ 3602 /* This one seems to be byte for BF5 and enum for BE5 */
3600 if (s->Phone.Data.Priv.ALCATEL.ProtocolVersion == V_1_1) { 3603 if (s->Phone.Data.Priv.ALCATEL.ProtocolVersion == V_1_1) {
3601 if ((error = ALCATEL_UpdateField(s, Alcatel_byte, ToDo->Location, 7, &val)) != ERR_NONE) return error; 3604 if ((error = ALCATEL_UpdateField(s, Alcatel_byte, ToDo->Location, 7, &val)) != ERR_NONE) return error;
3602 } else { 3605 } else {
3603 if ((error = ALCATEL_UpdateField(s, Alcatel_enum, ToDo->Location, 7, &val)) != ERR_NONE) return error; 3606 if ((error = ALCATEL_UpdateField(s, Alcatel_enum, ToDo->Location, 7, &val)) != ERR_NONE) return error;
3604 } 3607 }
3605 UpdatedFields[7] = true; 3608 UpdatedFields[7] = true;
3606 3609
3607 for (i = 0; i < ToDo->EntriesNum; i++) { 3610 for (i = 0; i < ToDo->EntriesNum; i++) {
3608 switch (ToDo->Entries[i].EntryType) { 3611 switch (ToDo->Entries[i].EntryType) {
3609 case TODO_END_DATETIME: 3612 case TODO_END_DATETIME:
3610 if ((error = ALCATEL_UpdateField(s, Alcatel_date, ToDo->Location, 0, &(ToDo->Entries[i].Date))) != ERR_NONE) return error; 3613 if ((error = ALCATEL_UpdateField(s, Alcatel_date, ToDo->Location, 0, &(ToDo->Entries[i].Date))) != ERR_NONE) return error;
3611 UpdatedFields[0] = true; 3614 UpdatedFields[0] = true;
3612 break; 3615 break;
3613 case TODO_COMPLETED: 3616 case TODO_COMPLETED:
3614 if ((error = ALCATEL_UpdateField(s, Alcatel_bool, ToDo->Location, 1, &(ToDo->Entries[i].Number))) != ERR_NONE) return error; 3617 if ((error = ALCATEL_UpdateField(s, Alcatel_bool, ToDo->Location, 1, &(ToDo->Entries[i].Number))) != ERR_NONE) return error;
3615 UpdatedFields[1] = true; 3618 UpdatedFields[1] = true;
3616 break; 3619 break;
3617 case TODO_ALARM_DATETIME: 3620 case TODO_ALARM_DATETIME:
3618 if ((error = ALCATEL_UpdateField(s, Alcatel_date, ToDo->Location, 2, &(ToDo->Entries[i].Date))) != ERR_NONE) return error; 3621 if ((error = ALCATEL_UpdateField(s, Alcatel_date, ToDo->Location, 2, &(ToDo->Entries[i].Date))) != ERR_NONE) return error;
3619 UpdatedFields[2] = true; 3622 UpdatedFields[2] = true;
3620 if ((error = ALCATEL_UpdateField(s, Alcatel_time, ToDo->Location, 3, &(ToDo->Entries[i].Date))) != ERR_NONE) return error; 3623 if ((error = ALCATEL_UpdateField(s, Alcatel_time, ToDo->Location, 3, &(ToDo->Entries[i].Date))) != ERR_NONE) return error;
3621 UpdatedFields[3] = true; 3624 UpdatedFields[3] = true;
3622 if ((error = ALCATEL_UpdateField(s, Alcatel_date, ToDo->Location, 10, &(ToDo->Entries[i].Date))) != ERR_NONE) return error; 3625 if ((error = ALCATEL_UpdateField(s, Alcatel_date, ToDo->Location, 10, &(ToDo->Entries[i].Date))) != ERR_NONE) return error;
3623 UpdatedFields[10] = true; 3626 UpdatedFields[10] = true;
3624 if ((error = ALCATEL_UpdateField(s, Alcatel_time, ToDo->Location, 11, &(ToDo->Entries[i].Date))) != ERR_NONE) return error; 3627 if ((error = ALCATEL_UpdateField(s, Alcatel_time, ToDo->Location, 11, &(ToDo->Entries[i].Date))) != ERR_NONE) return error;
3625 UpdatedFields[11] = true; 3628 UpdatedFields[11] = true;
3626 break; 3629 break;
3627 case TODO_TEXT: 3630 case TODO_TEXT:
3628 if ((error = ALCATEL_UpdateField(s, Alcatel_string, ToDo->Location, 4, ToDo->Entries[i].Text)) != ERR_NONE) return error; 3631 if ((error = ALCATEL_UpdateField(s, Alcatel_string, ToDo->Location, 4, ToDo->Entries[i].Text)) != ERR_NONE) return error;
3629 UpdatedFields[4] = true; 3632 UpdatedFields[4] = true;
3630 break; 3633 break;
3631 case TODO_PRIVATE: 3634 case TODO_PRIVATE:
3632 if ((error = ALCATEL_UpdateField(s, Alcatel_bool, ToDo->Location, 5, &(ToDo->Entries[i].Number))) != ERR_NONE) return error; 3635 if ((error = ALCATEL_UpdateField(s, Alcatel_bool, ToDo->Location, 5, &(ToDo->Entries[i].Number))) != ERR_NONE) return error;
3633 UpdatedFields[5] = true; 3636 UpdatedFields[5] = true;
3634 break; 3637 break;
3635 case TODO_CATEGORY: 3638 case TODO_CATEGORY:
3636 if ((error = ALCATEL_UpdateField(s, Alcatel_byte, ToDo->Location, 6, &(ToDo->Entries[i].Number))) != ERR_NONE) return error; 3639 if ((error = ALCATEL_UpdateField(s, Alcatel_byte, ToDo->Location, 6, &(ToDo->Entries[i].Number))) != ERR_NONE) return error;
3637 UpdatedFields[6] = true; 3640 UpdatedFields[6] = true;
3638 break; 3641 break;
3639 case TODO_CONTACTID: 3642 case TODO_CONTACTID:
3640 if ((error = ALCATEL_UpdateField(s, Alcatel_int, ToDo->Location, 8, &(ToDo->Entries[i].Number))) != ERR_NONE) return error; 3643 if ((error = ALCATEL_UpdateField(s, Alcatel_int, ToDo->Location, 8, &(ToDo->Entries[i].Number))) != ERR_NONE) return error;
3641 UpdatedFields[8] = true; 3644 UpdatedFields[8] = true;
3642 contact_set = true; 3645 contact_set = true;
3643 break; 3646 break;
3644 case TODO_PHONE: 3647 case TODO_PHONE:
3645 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, ToDo->Location, 9, ToDo->Entries[i].Text)) != ERR_NONE) return error; 3648 if ((error = ALCATEL_UpdateField(s, Alcatel_phone, ToDo->Location, 9, ToDo->Entries[i].Text)) != ERR_NONE) return error;
3646 UpdatedFields[9] = true; 3649 UpdatedFields[9] = true;
3647 phone_set = true; 3650 phone_set = true;
3648 break; 3651 break;
3649 default: 3652 default:
3650 break; 3653 break;
3651 } 3654 }
3652 } 3655 }
3653 if (!contact_set) { 3656 if (!contact_set) {
3654 if (phone_set) { 3657 if (phone_set) {
3655 val = 0xffffffff; 3658 val = 0xffffffff;
3656 } else { 3659 } else {
3657 val = 0; 3660 val = 0;
3658 } 3661 }
3659 if ((error = ALCATEL_UpdateField(s, Alcatel_int, ToDo->Location, 8, &val)) != ERR_NONE) return error; 3662 if ((error = ALCATEL_UpdateField(s, Alcatel_int, ToDo->Location, 8, &val)) != ERR_NONE) return error;
3660 UpdatedFields[8] = true; 3663 UpdatedFields[8] = true;
3661 } 3664 }
3662 3665
3663 3666
3664 /* If we didn't update some field, we have to delete it... */ 3667 /* If we didn't update some field, we have to delete it... */
3665 for (i=0; i<Priv->CurrentFieldsCount; i++) { 3668 for (i=0; i<Priv->CurrentFieldsCount; i++) {
3666 if (!UpdatedFields[Priv->CurrentFields[i]]) if ((error = ALCATEL_DeleteField(s, ToDo->Location, Priv->CurrentFields[i])) != ERR_NONE) return error; 3669 if (!UpdatedFields[Priv->CurrentFields[i]]) if ((error = ALCATEL_DeleteField(s, ToDo->Location, Priv->CurrentFields[i])) != ERR_NONE) return error;
3667 } 3670 }
3668 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error; 3671 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error;
3669 return ERR_NONE; 3672 return ERR_NONE;
3670} 3673}
3671 3674
3672static GSM_Error ALCATEL_DeleteToDo (GSM_StateMachine *s, GSM_ToDoEntry *ToDo) 3675static GSM_Error ALCATEL_DeleteToDo (GSM_StateMachine *s, GSM_ToDoEntry *ToDo)
3673{ 3676{
3674 GSM_Error error; 3677 GSM_Error error;
3675 3678
3676 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error; 3679 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error;
3677 /* Delete ToDo */ 3680 /* Delete ToDo */
3678 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error; 3681 if ((error = ALCATEL_GetAvailableIds(s, false))!= ERR_NONE) return error;
3679 if ((error = ALCATEL_IsIdAvailable(s, ToDo->Location))!= ERR_NONE) { 3682 if ((error = ALCATEL_IsIdAvailable(s, ToDo->Location))!= ERR_NONE) {
3680 /* Entry was empty => no error */ 3683 /* Entry was empty => no error */
3681 return ERR_NONE; 3684 return ERR_NONE;
3682 } 3685 }
3683 error = ALCATEL_DeleteItem(s, ToDo->Location); 3686 error = ALCATEL_DeleteItem(s, ToDo->Location);
3684 if (error != ERR_NONE) return error; 3687 if (error != ERR_NONE) return error;
3685 /* Refresh list */ 3688 /* Refresh list */
3686 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error; 3689 if ((error = ALCATEL_GoToBinaryState(s, StateSession, TypeToDo, 0))!= ERR_NONE) return error;
3687 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error; 3690 if ((error = ALCATEL_GetAvailableIds(s, true))!= ERR_NONE) return error;
3688 return ERR_NONE; 3691 return ERR_NONE;
3689} 3692}
3690 3693
3691static GSM_Error ALCATEL_GetCategoryStatus(GSM_StateMachine *s, GSM_CategoryStatus *Status) 3694static GSM_Error ALCATEL_GetCategoryStatus(GSM_StateMachine *s, GSM_CategoryStatus *Status)
3692{ 3695{
3693 GSM_Alcatel_BinaryTypetype; 3696 GSM_Alcatel_BinaryTypetype;
3694 GSM_Error error; 3697 GSM_Error error;
3695 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 3698 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
3696 3699
3697 switch (Status->Type) { 3700 switch (Status->Type) {
3698 case Category_ToDo: type = TypeToDo; break; 3701 case Category_ToDo: type = TypeToDo; break;
3699 case Category_Phonebook: type = TypeContacts; break; 3702 case Category_Phonebook: type = TypeContacts; break;
3700 default: return ERR_NOTSUPPORTED; 3703 default: return ERR_NOTSUPPORTED;
3701 } 3704 }
3702 if ((error = ALCATEL_GoToBinaryState(s, StateSession, type, 0))!= ERR_NONE) return error; 3705 if ((error = ALCATEL_GoToBinaryState(s, StateSession, type, 0))!= ERR_NONE) return error;
3703 if ((error = ALCATEL_GetAvailableCategoryIds(s))!= ERR_NONE) return error; 3706 if ((error = ALCATEL_GetAvailableCategoryIds(s))!= ERR_NONE) return error;
3704 3707
3705 Status->Used = Priv->CurrentCategoriesCount; 3708 Status->Used = Priv->CurrentCategoriesCount;
3706 3709
3707 return ERR_NONE; 3710 return ERR_NONE;
3708} 3711}
3709 3712
3710static GSM_Error ALCATEL_GetCategory(GSM_StateMachine *s, GSM_Category *Category) 3713static GSM_Error ALCATEL_GetCategory(GSM_StateMachine *s, GSM_Category *Category)
3711{ 3714{
3712 GSM_Alcatel_BinaryTypetype; 3715 GSM_Alcatel_BinaryTypetype;
3713 GSM_Error error; 3716 GSM_Error error;
3714 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 3717 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
3715 3718
3716 switch (Category->Type) { 3719 switch (Category->Type) {
3717 case Category_ToDo: type = TypeToDo; break; 3720 case Category_ToDo: type = TypeToDo; break;
3718 case Category_Phonebook: type = TypeContacts; break; 3721 case Category_Phonebook: type = TypeContacts; break;
3719 default: return ERR_NOTSUPPORTED; 3722 default: return ERR_NOTSUPPORTED;
3720 } 3723 }
3721 if ((error = ALCATEL_GoToBinaryState(s, StateSession, type, 0))!= ERR_NONE) return error; 3724 if ((error = ALCATEL_GoToBinaryState(s, StateSession, type, 0))!= ERR_NONE) return error;
3722 if ((error = ALCATEL_GetAvailableCategoryIds(s))!= ERR_NONE) return error; 3725 if ((error = ALCATEL_GetAvailableCategoryIds(s))!= ERR_NONE) return error;
3723 if ((error = ALCATEL_IsCategoryIdAvailable(s, Category->Location))!= ERR_NONE) return error; 3726 if ((error = ALCATEL_IsCategoryIdAvailable(s, Category->Location))!= ERR_NONE) return error;
3724 if ((error = ALCATEL_GetCategoryText(s, Category->Location))!= ERR_NONE) return error; 3727 if ((error = ALCATEL_GetCategoryText(s, Category->Location))!= ERR_NONE) return error;
3725 3728
3726 CopyUnicodeString(Category->Name, Priv->ReturnString); 3729 CopyUnicodeString(Category->Name, Priv->ReturnString);
3727 3730
3728 return ERR_NONE; 3731 return ERR_NONE;
3729} 3732}
3730 3733
3731static GSM_Error ALCATEL_AddCategory(GSM_StateMachine *s, GSM_Category *Category) 3734static GSM_Error ALCATEL_AddCategory(GSM_StateMachine *s, GSM_Category *Category)
3732{ 3735{
3733 GSM_Alcatel_BinaryTypetype; 3736 GSM_Alcatel_BinaryTypetype;
3734 GSM_Error error; 3737 GSM_Error error;
3735 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 3738 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
3736 3739
3737 switch (Category->Type) { 3740 switch (Category->Type) {
3738 case Category_ToDo: type = TypeToDo; break; 3741 case Category_ToDo: type = TypeToDo; break;
3739 case Category_Phonebook: type = TypeContacts; break; 3742 case Category_Phonebook: type = TypeContacts; break;
3740 default: return ERR_NOTSUPPORTED; 3743 default: return ERR_NOTSUPPORTED;
3741 } 3744 }
3742 if ((error = ALCATEL_GoToBinaryState(s, StateSession, type, 0))!= ERR_NONE) return error; 3745 if ((error = ALCATEL_GoToBinaryState(s, StateSession, type, 0))!= ERR_NONE) return error;
3743 if ((error = ALCATEL_AddCategoryText(s, Category->Name))!= ERR_NONE) return error; 3746 if ((error = ALCATEL_AddCategoryText(s, Category->Name))!= ERR_NONE) return error;
3744 3747
3745 Category->Location = Priv->ReturnInt; 3748 Category->Location = Priv->ReturnInt;
3746 3749
3747 return ERR_NONE; 3750 return ERR_NONE;
3748} 3751}
3749 3752
3750static GSM_Error ALCATEL_GetProductCode(GSM_StateMachine *s, char *value) 3753static GSM_Error ALCATEL_GetProductCode(GSM_StateMachine *s, char *value)
3751{ 3754{
3752 strcpy(value, s->Phone.Data.ModelInfo->model); 3755 strcpy(value, s->Phone.Data.ModelInfo->model);
3753 return ERR_NONE; 3756 return ERR_NONE;
3754} 3757}
3755 3758
3756static GSM_Error ALCATEL_DispatchMessage(GSM_StateMachine *s) 3759static GSM_Error ALCATEL_DispatchMessage(GSM_StateMachine *s)
3757{ 3760{
3758 if (s->Phone.Data.Priv.ALCATEL.Mode == ModeBinary) { 3761 if (s->Phone.Data.Priv.ALCATEL.Mode == ModeBinary) {
3759 return GSM_DispatchMessage(s); 3762 return GSM_DispatchMessage(s);
3760 } else { 3763 } else {
3761 return ATGEN_DispatchMessage(s); 3764 return ATGEN_DispatchMessage(s);
3762 } 3765 }
3763} 3766}
3764 3767
3765static GSM_Error ALCATEL_ReplyGeneric(GSM_Protocol_Message msg, GSM_StateMachine *s) 3768static GSM_Error ALCATEL_ReplyGeneric(GSM_Protocol_Message msg, GSM_StateMachine *s)
3766{ 3769{
3767 /* All error values are just VERY wild guesses, but these seems to work 3770 /* All error values are just VERY wild guesses, but these seems to work
3768 * almost as expected ... 3771 * almost as expected ...
3769 */ 3772 */
3770 switch (msg.Buffer[8]) { 3773 switch (msg.Buffer[8]) {
3771 case 0x00: /* no error */ 3774 case 0x00: /* no error */
3772 return ERR_NONE; 3775 return ERR_NONE;
3773 case 0x10: /* same thing opened in phone menus */ 3776 case 0x10: /* same thing opened in phone menus */
3774 return ERR_INSIDEPHONEMENU; 3777 return ERR_INSIDEPHONEMENU;
3775 case 0x13: 3778 case 0x13:
3776 /* This appears in more cases: 3779 /* This appears in more cases:
3777 *- phone needs PIN code 3780 *- phone needs PIN code
3778 *- we want to close not opened session 3781 *- we want to close not opened session
3779 * For normal users the second case shouldn't occur... 3782 * For normal users the second case shouldn't occur...
3780 */ 3783 */
3781 return ERR_SECURITYERROR; 3784 return ERR_SECURITYERROR;
3782 case 0x14: /* Bad data */ 3785 case 0x14: /* Bad data */
3783 case 0x2f: /* Closing session when not opened */ 3786 case 0x2f: /* Closing session when not opened */
3784 case 0x1f: /* Bad in/out counter in packet/ack */ 3787 case 0x1f: /* Bad in/out counter in packet/ack */
3785 case 0x0e: /* Openning session when not closed */ 3788 case 0x0e: /* Openning session when not closed */
3786 case 0x0C: /* Bad id (item/database) */ 3789 case 0x0C: /* Bad id (item/database) */
3787 case 0x11: /* Bad list id */ 3790 case 0x11: /* Bad list id */
3788 case 0x2A: /* Nonexistant field/item id */ 3791 case 0x2A: /* Nonexistant field/item id */
3789 case 0x35: /* Too long text */ 3792 case 0x35: /* Too long text */
3790 return ERR_BUG; 3793 return ERR_BUG;
3791 case 0x23: /* Session opened */ 3794 case 0x23: /* Session opened */
3792 case 0x80: /* Transfer started */ 3795 case 0x80: /* Transfer started */
3793 return ERR_NONE; 3796 return ERR_NONE;
3794 case 0x82: /* Transfer canceled */ 3797 case 0x82: /* Transfer canceled */
3795 return ERR_CANCELED; 3798 return ERR_CANCELED;
3796 default: 3799 default:
3797 smprintf(s, "WARNING: Packet seems to indicate some status by %02X, ignoring!\n", msg.Buffer[8]); 3800 smprintf(s, "WARNING: Packet seems to indicate some status by %02X, ignoring!\n", msg.Buffer[8]);
3798 return ERR_NONE; 3801 return ERR_NONE;
3799 } 3802 }
3800} 3803}
3801 3804
3802static GSM_Error ALCATEL_ReplyCommit(GSM_Protocol_Message msg, GSM_StateMachine *s) 3805static GSM_Error ALCATEL_ReplyCommit(GSM_Protocol_Message msg, GSM_StateMachine *s)
3803{ 3806{
3804 s->Phone.Data.Priv.ALCATEL.CommitedRecord = msg.Buffer[12] + (msg.Buffer[11] << 8) + (msg.Buffer[10] << 16) + (msg.Buffer[9] << 24); 3807 s->Phone.Data.Priv.ALCATEL.CommitedRecord = msg.Buffer[12] + (msg.Buffer[11] << 8) + (msg.Buffer[10] << 16) + (msg.Buffer[9] << 24);
3805 smprintf(s, "Created record %08x\n", s->Phone.Data.Priv.ALCATEL.CommitedRecord); 3808 smprintf(s, "Created record %08x\n", s->Phone.Data.Priv.ALCATEL.CommitedRecord);
3806 return ERR_NONE; 3809 return ERR_NONE;
3807} 3810}
3808 3811
3809static GSM_Error ALCATEL_SetIncomingCB (GSM_StateMachine *s, bool enable) 3812static GSM_Error ALCATEL_SetIncomingCB (GSM_StateMachine *s, bool enable)
3810{ 3813{
3811 GSM_Error error; 3814 GSM_Error error;
3812 3815
3813 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 3816 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
3814 return ATGEN_SetIncomingCB(s, enable); 3817 return ATGEN_SetIncomingCB(s, enable);
3815} 3818}
3816 3819
3817static GSM_Error ALCATEL_SetIncomingSMS (GSM_StateMachine *s, bool enable) 3820static GSM_Error ALCATEL_SetIncomingSMS (GSM_StateMachine *s, bool enable)
3818{ 3821{
3819 GSM_Error error; 3822 GSM_Error error;
3820 3823
3821 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error; 3824 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
3822 return ATGEN_SetIncomingSMS(s, enable); 3825 return ATGEN_SetIncomingSMS(s, enable);
3823} 3826}
3824 3827
3828static GSM_Error ALCATEL_SetFastSMSSending(GSM_StateMachine *s, bool enable)
3829{
3830 GSM_Error error;
3831
3832 if ((error = ALCATEL_SetATMode(s))!= ERR_NONE) return error;
3833 return ATGEN_SetFastSMSSending(s, enable);
3834}
3835
3825static GSM_Reply_Function ALCATELReplyFunctions[] = { 3836static GSM_Reply_Function ALCATELReplyFunctions[] = {
3826 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelAttach }, 3837 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelAttach },
3827 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelDetach }, 3838 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelDetach },
3828 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelCommit }, 3839 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelCommit },
3829 {ALCATEL_ReplyCommit, "\x02",0x00,0x00, ID_AlcatelCommit2 }, 3840 {ALCATEL_ReplyCommit, "\x02",0x00,0x00, ID_AlcatelCommit2 },
3830 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelEnd }, 3841 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelEnd },
3831 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelClose }, 3842 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelClose },
3832 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelStart }, 3843 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelStart },
3833 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelSelect1 }, 3844 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelSelect1 },
3834 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelSelect2 }, 3845 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelSelect2 },
3835 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelSelect3 }, 3846 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelSelect3 },
3836 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelBegin1 }, 3847 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelBegin1 },
3837 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelBegin2 }, 3848 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelBegin2 },
3838 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelGetIds1 }, 3849 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelGetIds1 },
3839 {ALCATEL_ReplyGetIds, "\x02",0x00,0x00, ID_AlcatelGetIds2 }, 3850 {ALCATEL_ReplyGetIds, "\x02",0x00,0x00, ID_AlcatelGetIds2 },
3840 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelGetCategories1}, 3851 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelGetCategories1},
3841 {ALCATEL_ReplyGetCategories, "\x02",0x00,0x00, ID_AlcatelGetCategories2}, 3852 {ALCATEL_ReplyGetCategories, "\x02",0x00,0x00, ID_AlcatelGetCategories2},
3842 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelGetCategoryText1}, 3853 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelGetCategoryText1},
3843 {ALCATEL_ReplyGetCategoryText, "\x02",0x00,0x00, ID_AlcatelGetCategoryText2}, 3854 {ALCATEL_ReplyGetCategoryText, "\x02",0x00,0x00, ID_AlcatelGetCategoryText2},
3844 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelAddCategoryText1}, 3855 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelAddCategoryText1},
3845 {ALCATEL_ReplyAddCategoryText, "\x02",0x00,0x00, ID_AlcatelAddCategoryText2}, 3856 {ALCATEL_ReplyAddCategoryText, "\x02",0x00,0x00, ID_AlcatelAddCategoryText2},
3846 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelGetFields1 }, 3857 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelGetFields1 },
3847 {ALCATEL_ReplyGetFields, "\x02",0x00,0x00, ID_AlcatelGetFields2 }, 3858 {ALCATEL_ReplyGetFields, "\x02",0x00,0x00, ID_AlcatelGetFields2 },
3848 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelGetFieldValue1}, 3859 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelGetFieldValue1},
3849 {ALCATEL_ReplyGetFieldValue, "\x02",0x00,0x00, ID_AlcatelGetFieldValue2}, 3860 {ALCATEL_ReplyGetFieldValue, "\x02",0x00,0x00, ID_AlcatelGetFieldValue2},
3850 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelDeleteField }, 3861 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelDeleteField },
3851 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelDeleteItem1 }, 3862 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelDeleteItem1 },
3852 {ALCATEL_ReplyDeleteItem, "\x02",0x00,0x00, ID_AlcatelDeleteItem2 }, 3863 {ALCATEL_ReplyDeleteItem, "\x02",0x00,0x00, ID_AlcatelDeleteItem2 },
3853 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelCreateField }, 3864 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelCreateField },
3854 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelUpdateField }, 3865 {ALCATEL_ReplyGeneric, "\x02",0x00,0x00, ID_AlcatelUpdateField },
3855 {NULL, "\x00",0x00,0x00, ID_None } 3866 {NULL, "\x00",0x00,0x00, ID_None }
3856}; 3867};
3857 3868
3858GSM_Phone_Functions ALCATELPhone = { 3869GSM_Phone_Functions ALCATELPhone = {
3859 /* AFAIK, any 50[0123] phone should work, but I'm not sure whether all 3870 /* AFAIK, any 50[0123] phone should work, but I'm not sure whether all
3860 * they were ever really released, if yes add them here also. 3871 * they were ever really released, if yes add them here also.
3861 */ 3872 */
3862 "alcatel|OT501|OT701|OT715|OT535|OT735|BE5|BF5|BH4", 3873 "alcatel|OT501|OT701|OT715|OT535|OT735|BE5|BF5|BH4",
3863 ALCATELReplyFunctions, 3874 ALCATELReplyFunctions,
3864 ALCATEL_Initialise, 3875 ALCATEL_Initialise,
3865 ALCATEL_Terminate, 3876 ALCATEL_Terminate,
3866 ALCATEL_DispatchMessage, 3877 ALCATEL_DispatchMessage,
3867 NOTSUPPORTED, /* ShowStartInfo */ 3878 NOTSUPPORTED, /* ShowStartInfo */
3868 ALCATEL_GetManufacturer, 3879 ALCATEL_GetManufacturer,
3869 ALCATEL_GetModel, 3880 ALCATEL_GetModel,
3870 ALCATEL_GetFirmware, 3881 ALCATEL_GetFirmware,
3871 ALCATEL_GetIMEI, 3882 ALCATEL_GetIMEI,
3872 NOTSUPPORTED, /* GetOriginalIMEI */ 3883 NOTSUPPORTED, /* GetOriginalIMEI */
3873 NOTSUPPORTED, /* GetManufactureMonth*/ 3884 NOTSUPPORTED, /* GetManufactureMonth*/
3874 ALCATEL_GetProductCode, 3885 ALCATEL_GetProductCode,
3875 NOTSUPPORTED, /* GetHardware */ 3886 NOTSUPPORTED, /* GetHardware */
3876 NOTSUPPORTED, /* GetPPM */ 3887 NOTSUPPORTED, /* GetPPM */
3877 ALCATEL_GetSIMIMSI, 3888 ALCATEL_GetSIMIMSI,
3878 ALCATEL_GetDateTime, 3889 ALCATEL_GetDateTime,
3879 ALCATEL_SetDateTime, 3890 ALCATEL_SetDateTime,
3880 ALCATEL_GetAlarm, 3891 ALCATEL_GetAlarm,
3881 ALCATEL_SetAlarm, 3892 ALCATEL_SetAlarm,
3882 NOTSUPPORTED, /* GetLocale */ 3893 NOTSUPPORTED, /* GetLocale */
3883 NOTSUPPORTED, /* SetLocale */ 3894 NOTSUPPORTED, /* SetLocale */
3884 ALCATEL_PressKey, 3895 ALCATEL_PressKey,
3885 ALCATEL_Reset, 3896 ALCATEL_Reset,
3886 ALCATEL_ResetPhoneSettings, 3897 ALCATEL_ResetPhoneSettings,
3887 ALCATEL_EnterSecurityCode, 3898 ALCATEL_EnterSecurityCode,
3888 ALCATEL_GetSecurityStatus, 3899 ALCATEL_GetSecurityStatus,
3889 ALCATEL_GetDisplayStatus, 3900 ALCATEL_GetDisplayStatus,
3890 ALCATEL_SetAutoNetworkLogin, 3901 ALCATEL_SetAutoNetworkLogin,
3891 ALCATEL_GetBatteryCharge, 3902 ALCATEL_GetBatteryCharge,
3892 ALCATEL_GetSignalStrength, 3903 ALCATEL_GetSignalStrength,
3893 ALCATEL_GetNetworkInfo, 3904 ALCATEL_GetNetworkInfo,
3894 ALCATEL_GetCategory, 3905 ALCATEL_GetCategory,
3895 ALCATEL_AddCategory, 3906 ALCATEL_AddCategory,
3896 ALCATEL_GetCategoryStatus, 3907 ALCATEL_GetCategoryStatus,
3897 ALCATEL_GetMemoryStatus, 3908 ALCATEL_GetMemoryStatus,
3898 ALCATEL_GetMemory, 3909 ALCATEL_GetMemory,
3899 ALCATEL_GetNextMemory, 3910 ALCATEL_GetNextMemory,
3900 ALCATEL_SetMemory, 3911 ALCATEL_SetMemory,
3901 ALCATEL_AddMemory, 3912 ALCATEL_AddMemory,
3902 ALCATEL_DeleteMemory, 3913 ALCATEL_DeleteMemory,
3903 ALCATEL_DeleteAllMemory, 3914 ALCATEL_DeleteAllMemory,
3904 NOTSUPPORTED, /* GetSpeedDial */ 3915 NOTSUPPORTED, /* GetSpeedDial */
3905 NOTSUPPORTED, /* SetSpeedDial */ 3916 NOTSUPPORTED, /* SetSpeedDial */
3906 ALCATEL_GetSMSC, 3917 ALCATEL_GetSMSC,
3907 ALCATEL_SetSMSC, 3918 ALCATEL_SetSMSC,
3908 ALCATEL_GetSMSStatus, 3919 ALCATEL_GetSMSStatus,
3909 ALCATEL_GetSMS, 3920 ALCATEL_GetSMS,
3910 ALCATEL_GetNextSMS, 3921 ALCATEL_GetNextSMS,
3911 NOTSUPPORTED, /* SetSMS */ 3922 NOTSUPPORTED, /* SetSMS */
3912 ALCATEL_AddSMS, 3923 ALCATEL_AddSMS,
3913 ALCATEL_DeleteSMS, 3924 ALCATEL_DeleteSMS,
3914 ALCATEL_SendSMS, 3925 ALCATEL_SendSMS,
3915 ALCATEL_SendSavedSMS, 3926 ALCATEL_SendSavedSMS,
3927 ALCATEL_SetFastSMSSending,
3916 ALCATEL_SetIncomingSMS, 3928 ALCATEL_SetIncomingSMS,
3917 ALCATEL_SetIncomingCB, 3929 ALCATEL_SetIncomingCB,
3918 ALCATEL_GetSMSFolders, 3930 ALCATEL_GetSMSFolders,
3919 NOTSUPPORTED, /* AddSMSFolder */ 3931 NOTSUPPORTED, /* AddSMSFolder */
3920 NOTSUPPORTED, /* DeleteSMSFolder */ 3932 NOTSUPPORTED, /* DeleteSMSFolder */
3921 ALCATEL_DialVoice, 3933 ALCATEL_DialVoice,
3922 ALCATEL_AnswerCall, 3934 ALCATEL_AnswerCall,
3923 ALCATEL_CancelCall, 3935 ALCATEL_CancelCall,
3924 NOTSUPPORTED, /* HoldCall */ 3936 NOTSUPPORTED, /* HoldCall */
3925 NOTSUPPORTED, /* UnholdCall */ 3937 NOTSUPPORTED, /* UnholdCall */
3926 NOTSUPPORTED, /* ConferenceCall */ 3938 NOTSUPPORTED, /* ConferenceCall */
3927 NOTSUPPORTED, /* SplitCall */ 3939 NOTSUPPORTED, /* SplitCall */
3928 NOTSUPPORTED, /* TransferCall */ 3940 NOTSUPPORTED, /* TransferCall */
3929 NOTSUPPORTED, /* SwitchCall */ 3941 NOTSUPPORTED, /* SwitchCall */
3930 NOTSUPPORTED, /* GetCallDivert */ 3942 NOTSUPPORTED, /* GetCallDivert */
3931 NOTSUPPORTED, /* SetCallDivert */ 3943 NOTSUPPORTED, /* SetCallDivert */
3932 NOTSUPPORTED, /* CancelAllDiverts*/ 3944 NOTSUPPORTED, /* CancelAllDiverts*/
3933 NONEFUNCTION, /* SetIncomingCall */ 3945 NONEFUNCTION, /* SetIncomingCall */
3934 NOTSUPPORTED, /* SetIncomingUSSD */ 3946 NOTSUPPORTED, /* SetIncomingUSSD */
3935 ALCATEL_SendDTMF, 3947 ALCATEL_SendDTMF,
3936 NOTSUPPORTED, /* GetRingtone */ 3948 NOTSUPPORTED, /* GetRingtone */
3937 NOTSUPPORTED, /* SetRingtone */ 3949 NOTSUPPORTED, /* SetRingtone */
3938 NOTSUPPORTED, /* GetRingtonesInfo*/ 3950 NOTSUPPORTED, /* GetRingtonesInfo*/
3939 NOTSUPPORTED, /* DeleteUserRingtones*/ 3951 NOTSUPPORTED, /* DeleteUserRingtones*/
3940 NOTSUPPORTED, /* PlayTone */ 3952 NOTSUPPORTED, /* PlayTone */
3941 NOTSUPPORTED, /* GetWAPBookmark */ 3953 NOTSUPPORTED, /* GetWAPBookmark */
3942 NOTSUPPORTED, /* SetWAPBookmark */ 3954 NOTSUPPORTED, /* SetWAPBookmark */
3943 NOTSUPPORTED, /* DeleteWAPBookmark*/ 3955 NOTSUPPORTED, /* DeleteWAPBookmark*/
3944 NOTSUPPORTED, /* GetWAPSettings */ 3956 NOTSUPPORTED, /* GetWAPSettings */
3945 NOTSUPPORTED, /* SetWAPSettings */ 3957 NOTSUPPORTED, /* SetWAPSettings */
3946 NOTSUPPORTED, /* GetMMSSettings */ 3958 NOTSUPPORTED, /* GetMMSSettings */
3947 NOTSUPPORTED, /* SetMMSSettings */ 3959 NOTSUPPORTED, /* SetMMSSettings */
3948 NOTSUPPORTED, /* GetSyncMLSettings*/ 3960 NOTSUPPORTED, /* GetSyncMLSettings*/
3949 NOTSUPPORTED, /* SetSyncMLSettings*/ 3961 NOTSUPPORTED, /* SetSyncMLSettings*/
3950 NOTSUPPORTED, /* GetChatSettings */ 3962 NOTSUPPORTED, /* GetChatSettings */
3951 NOTSUPPORTED, /* SetChatSettings */ 3963 NOTSUPPORTED, /* SetChatSettings */
3952 NOTSUPPORTED, /* GetBitmap */ 3964 NOTSUPPORTED, /* GetBitmap */
3953 NOTSUPPORTED, /* SetBitmap */ 3965 NOTSUPPORTED, /* SetBitmap */
3954 ALCATEL_GetToDoStatus, 3966 ALCATEL_GetToDoStatus,
3955 ALCATEL_GetToDo, 3967 ALCATEL_GetToDo,
3956 ALCATEL_GetNextToDo, 3968 ALCATEL_GetNextToDo,
3957 ALCATEL_SetToDo, 3969 ALCATEL_SetToDo,
3958 ALCATEL_AddToDo, 3970 ALCATEL_AddToDo,
3959 ALCATEL_DeleteToDo, 3971 ALCATEL_DeleteToDo,
3960 ALCATEL_DeleteAllToDo, 3972 ALCATEL_DeleteAllToDo,
3961 ALCATEL_GetCalendarStatus, 3973 ALCATEL_GetCalendarStatus,
3962 ALCATEL_GetCalendar, 3974 ALCATEL_GetCalendar,
3963 ALCATEL_GetNextCalendar, 3975 ALCATEL_GetNextCalendar,
3964 ALCATEL_SetCalendar, 3976 ALCATEL_SetCalendar,
3965 ALCATEL_AddCalendar, 3977 ALCATEL_AddCalendar,
3966 ALCATEL_DeleteCalendar, 3978 ALCATEL_DeleteCalendar,
3967 ALCATEL_DeleteAllCalendar, 3979 ALCATEL_DeleteAllCalendar,
3968 NOTSUPPORTED, /* GetCalendarSettings*/ 3980 NOTSUPPORTED, /* GetCalendarSettings*/
3969 NOTSUPPORTED, /* SetCalendarSettings*/ 3981 NOTSUPPORTED, /* SetCalendarSettings*/
3970 NOTSUPPORTED, /* GetNote */ 3982 NOTSUPPORTED, /* GetNextNote */
3971 NOTSUPPORTED, /* GetProfile */ 3983 NOTSUPPORTED, /* GetProfile */
3972 NOTSUPPORTED, /* SetProfile */ 3984 NOTSUPPORTED, /* SetProfile */
3973 NOTSUPPORTED, /* GetFMStation */ 3985 NOTSUPPORTED, /* GetFMStation */
3974 NOTSUPPORTED, /* SetFMStation */ 3986 NOTSUPPORTED, /* SetFMStation */
3975 NOTSUPPORTED, /* ClearFMStations */ 3987 NOTSUPPORTED, /* ClearFMStations */
3976 NOTSUPPORTED, /* GetNextFileFolder*/ 3988 NOTSUPPORTED, /* GetNextFileFolder*/
3977 NOTSUPPORTED, /* GetFilePart */ 3989 NOTSUPPORTED, /* GetFilePart */
3978 NOTSUPPORTED, /* AddFilePart */ 3990 NOTSUPPORTED, /* AddFilePart */
3979 NOTSUPPORTED, /* GetFileSystemStatus*/ 3991 NOTSUPPORTED, /* GetFileSystemStatus*/
3980 NOTSUPPORTED, /* DeleteFile */ 3992 NOTSUPPORTED, /* DeleteFile */
3981 NOTSUPPORTED, /* AddFolder */ 3993 NOTSUPPORTED, /* AddFolder */
3982 NOTSUPPORTED, /* GetGPRSAccessPoint*/ 3994 NOTSUPPORTED, /* GetGPRSAccessPoint*/
3983 NOTSUPPORTED /* SetGPRSAccessPoint*/ 3995 NOTSUPPORTED /* SetGPRSAccessPoint*/
3984}; 3996};
3985 3997
3986#endif 3998#endif
3987#endif 3999#endif
3988 4000
3989/* How should editor hadle tabs in this file? Add editor commands here. 4001/* How should editor hadle tabs in this file? Add editor commands here.
3990 * vim: noexpandtab sw=8 ts=8 sts=8: 4002 * vim: noexpandtab sw=8 ts=8 sts=8:
3991 */ 4003 */
diff --git a/gammu/emb/common/phone/at/atgen.c b/gammu/emb/common/phone/at/atgen.c
index 1834f15..ba23eb2 100644
--- a/gammu/emb/common/phone/at/atgen.c
+++ b/gammu/emb/common/phone/at/atgen.c
@@ -1,1144 +1,1200 @@
1/* (c) 2002-2004 by Marcin Wiacek and Michal Cihar */ 1/* (c) 2002-2004 by Marcin Wiacek and Michal Cihar */
2 2
3#include "../../gsmstate.h" 3#include "../../gsmstate.h"
4 4
5#ifdef GSM_ENABLE_ATGEN 5#ifdef GSM_ENABLE_ATGEN
6 6
7#include <string.h> 7#include <string.h>
8#include <time.h> 8#include <time.h>
9#include <ctype.h> 9#include <ctype.h>
10 10
11#include "../../gsmcomon.h" 11#include "../../gsmcomon.h"
12#include "../../misc/coding/coding.h" 12#include "../../misc/coding/coding.h"
13#include "../../service/sms/gsmsms.h" 13#include "../../service/sms/gsmsms.h"
14#include "../pfunc.h" 14#include "../pfunc.h"
15
15#include "atgen.h" 16#include "atgen.h"
16 17
18#include "samsung.h"
19#include "siemens.h"
20#include "sonyeric.h"
21
17#ifdef GSM_ENABLE_ALCATEL 22#ifdef GSM_ENABLE_ALCATEL
18 extern GSM_Error ALCATEL_ProtocolVersionReply(GSM_Protocol_Message msg, GSM_StateMachine *s); 23GSM_Error ALCATEL_ProtocolVersionReply (GSM_Protocol_Message, GSM_StateMachine *);
19#endif 24#endif
20 25
21 extern GSM_Error ATGEN_CMS35ReplyGetBitmap(GSM_Protocol_Message msg, GSM_StateMachine *s);
22 extern GSM_Error ATGEN_CMS35ReplySetBitmap(GSM_Protocol_Message msg, GSM_StateMachine *s);
23 extern GSM_Error ATGEN_CMS35ReplyGetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s);
24 extern GSM_Error ATGEN_CMS35ReplySetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s);
25 extern GSM_Error ATGEN_CMS35ReplyGetNextCal(GSM_Protocol_Message msg, GSM_StateMachine *s);
26 extern GSM_Error ATGEN_CMS35ReplySetCalendar(GSM_Protocol_Message msg, GSM_StateMachine *s);
27 extern GSM_Error ATGEN_CMS35ReplyDeleteCalendar(GSM_Protocol_Message msg, GSM_StateMachine *s);
28 extern GSM_Error ATGEN_SL45ReplyGetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s);
29
30 extern GSM_Error ATGEN_GetRingtone (GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone);
31 extern GSM_Error ATGEN_SetRingtone (GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength);
32 extern GSM_Error ATGEN_GetBitmap (GSM_StateMachine *s, GSM_Bitmap *Bitmap);
33 extern GSM_Error ATGEN_SetBitmap (GSM_StateMachine *s, GSM_Bitmap *Bitmap);
34 extern GSM_Error SIEMENS_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start);
35 extern GSM_Error SIEMENS_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note);
36 extern GSM_Error SIEMENS_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note);
37
38 extern GSM_Error SONYERIC_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start);
39 extern GSM_Error SONYERIC_GetNextToDo (GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool start);
40 extern GSM_Error SONYERIC_GetToDoStatus (GSM_StateMachine *s, GSM_ToDoStatus *status);
41 extern GSM_Error SONYERIC_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note);
42 extern GSM_Error SONYERIC_AddToDo (GSM_StateMachine *s, GSM_ToDoEntry *ToDo);
43 extern GSM_Error SONYERIC_DeleteAllToDo (GSM_StateMachine *s);
44 extern GSM_Error SONYERIC_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note);
45 extern GSM_Error SONYERIC_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *Status);
46 26
47typedef struct { 27typedef struct {
48 int Number; 28 int Number;
49 char Text[60]; 29 char Text[60];
50} ATErrorCode; 30} ATErrorCode;
51 31
52static ATErrorCode CMSErrorCodes[] = { 32static ATErrorCode CMSErrorCodes[] = {
53 /* 33 /*
54 * Error codes not specified here were either undefined or reserved in my 34 * Error codes not specified here were either undefined or reserved in my
55 * copy of specifications, if you have newer one, please fill in the gaps. 35 * copy of specifications, if you have newer one, please fill in the gaps.
56 */ 36 */
57 /* 0...127 from GSM 04.11 Annex E-2 */ 37 /* 0...127 from GSM 04.11 Annex E-2 */
58 {1, "Unassigned (unallocated) number"}, 38 {1, "Unassigned (unallocated) number"},
59 {8, "Operator determined barring"}, 39 {8, "Operator determined barring"},
60 {10, "Call barred"}, 40 {10, "Call barred"},
61 {21, "Short message transfer rejected"}, 41 {21, "Short message transfer rejected"},
62 {27, "Destination out of service"}, 42 {27, "Destination out of service"},
63 {28, "Unidentified subscriber"}, 43 {28, "Unidentified subscriber"},
64 {29, "Facility rejected"}, 44 {29, "Facility rejected"},
65 {30, "Unknown subscriber"}, 45 {30, "Unknown subscriber"},
66 {38, "Network out of order"}, 46 {38, "Network out of order"},
67 {41, "Temporary failure"}, 47 {41, "Temporary failure"},
68 {42, "Congestion"}, 48 {42, "Congestion"},
69 {47, "Resources unavailable, unspecified"}, 49 {47, "Resources unavailable, unspecified"},
70 {50, "Requested facility not subscribed"}, 50 {50, "Requested facility not subscribed"},
71 {69, "Requested facility not implemented"}, 51 {69, "Requested facility not implemented"},
72 {81, "Invalid short message transfer reference value"}, 52 {81, "Invalid short message transfer reference value"},
73 {95, "Invalid message, unspecified"}, 53 {95, "Invalid message, unspecified"},
74 {96, "Invalid mandatory information"}, 54 {96, "Invalid mandatory information"},
75 {97, "Message type non-existent or not implemented"}, 55 {97, "Message type non-existent or not implemented"},
76 {98, "Message not compatible with short message protocol state"}, 56 {98, "Message not compatible with short message protocol state"},
77 {99, "Information element non-existent or not implemented"}, 57 {99, "Information element non-existent or not implemented"},
78 {111, "Protocol error, unspecified"}, 58 {111, "Protocol error, unspecified"},
79 {127, "Interworking, unspecified"}, 59 {127, "Interworking, unspecified"},
80 /* 128...255 from GSM 03.40 subclause 9.2.3.22 */ 60 /* 128...255 from GSM 03.40 subclause 9.2.3.22 */
81 {0x80, "Telematic interworking not supported"}, 61 {0x80, "Telematic interworking not supported"},
82 {0x81, "Short message Type 0 not supported"}, 62 {0x81, "Short message Type 0 not supported"},
83 {0x82, "Cannot replace short message"}, 63 {0x82, "Cannot replace short message"},
84 {0x8F, "Unspecified TP-PID error"}, 64 {0x8F, "Unspecified TP-PID error"},
85 {0x90, "Data coding scheme (alphabet) not supported"}, 65 {0x90, "Data coding scheme (alphabet) not supported"},
86 {0x91, "Message class not supported"}, 66 {0x91, "Message class not supported"},
87 {0x9F, "Unspecified TP-DCS error"}, 67 {0x9F, "Unspecified TP-DCS error"},
88 {0xA0, "Command cannot be actioned"}, 68 {0xA0, "Command cannot be actioned"},
89 {0xA1, "Command unsupported"}, 69 {0xA1, "Command unsupported"},
90 {0xAF, "Unspecified TP-Command error"}, 70 {0xAF, "Unspecified TP-Command error"},
91 {0xB0, "TPDU not supported"}, 71 {0xB0, "TPDU not supported"},
92 {0xC0, "SC busy"}, 72 {0xC0, "SC busy"},
93 {0xC1, "No SC subscription"}, 73 {0xC1, "No SC subscription"},
94 {0xC2, "SC system failure"}, 74 {0xC2, "SC system failure"},
95 {0xC3, "Invalid SME address"}, 75 {0xC3, "Invalid SME address"},
96 {0xC4, "Destination SME barred"}, 76 {0xC4, "Destination SME barred"},
97 {0xC5, "SM Rejected-Duplicate SM"}, 77 {0xC5, "SM Rejected-Duplicate SM"},
98 {0xC6, "TP-VPF not supported"}, 78 {0xC6, "TP-VPF not supported"},
99 {0xC7, "TP-VP not supported"}, 79 {0xC7, "TP-VP not supported"},
100 {0xD0, "SIM SMS storage full"}, 80 {0xD0, "SIM SMS storage full"},
101 {0xD1, "No SMS storage capability in SIM"}, 81 {0xD1, "No SMS storage capability in SIM"},
102 {0xD2, "Error in MS"}, 82 {0xD2, "Error in MS"},
103 {0xD3, "Memory Capacity Exceede"}, 83 {0xD3, "Memory Capacity Exceede"},
104 {0xD4, "SIM Application Toolkit Busy"}, 84 {0xD4, "SIM Application Toolkit Busy"},
105 {0xFF, "Unspecified error cause"}, 85 {0xFF, "Unspecified error cause"},
106 /* 300...511 from GSM 07.05 subclause 3.2.5 */ 86 /* 300...511 from GSM 07.05 subclause 3.2.5 */
107 {300, "ME failure"}, 87 {300, "ME failure"},
108 {301, "SMS service of ME reserved"}, 88 {301, "SMS service of ME reserved"},
109 {302, "operation not allowed"}, 89 {302, "operation not allowed"},
110 {303, "operation not supported"}, 90 {303, "operation not supported"},
111 {304, "invalid PDU mode parameter"}, 91 {304, "invalid PDU mode parameter"},
112 {305, "invalid text mode parameter"}, 92 {305, "invalid text mode parameter"},
113 {310, "SIM not inserted"}, 93 {310, "SIM not inserted"},
114 {311, "SIM PIN required"}, 94 {311, "SIM PIN required"},
115 {312, "PH-SIM PIN required"}, 95 {312, "PH-SIM PIN required"},
116 {313, "SIM failure"}, 96 {313, "SIM failure"},
117 {314, "SIM busy"}, 97 {314, "SIM busy"},
118 {315, "SIM wrong"}, 98 {315, "SIM wrong"},
119 {316, "SIM PUK required"}, 99 {316, "SIM PUK required"},
120 {317, "SIM PIN2 required"}, 100 {317, "SIM PIN2 required"},
121 {318, "SIM PUK2 required"}, 101 {318, "SIM PUK2 required"},
122 {320, "memory failure"}, 102 {320, "memory failure"},
123 {321, "invalid memory index"}, 103 {321, "invalid memory index"},
124 {322, "memory full"}, 104 {322, "memory full"},
125 {330, "SMSC address unknown"}, 105 {330, "SMSC address unknown"},
126 {331, "no network service"}, 106 {331, "no network service"},
127 {332, "network timeout"}, 107 {332, "network timeout"},
128 {340, "no CNMA acknowledgement expected"}, 108 {340, "no CNMA acknowledgement expected"},
129 {500, "unknown error"}, 109 {500, "unknown error"},
130 /* > 512 are manufacturer specific according to GSM 07.05 subclause 3.2.5 */ 110 /* > 512 are manufacturer specific according to GSM 07.05 subclause 3.2.5 */
131 {-1, ""} 111 {-1, ""}
132}; 112};
133 113
134static ATErrorCode CMEErrorCodes[] = { 114static ATErrorCode CMEErrorCodes[] = {
135 /* CME Error codes from GSM 07.07 section 9.2 */ 115 /* CME Error codes from GSM 07.07 section 9.2 */
136 {0, "phone failure"}, 116 {0, "phone failure"},
137 {1, "no connection to phone"}, 117 {1, "no connection to phone"},
138 {2, "phone-adaptor link reserved"}, 118 {2, "phone-adaptor link reserved"},
139 {3, "operation not allowed"}, 119 {3, "operation not allowed"},
140 {4, "operation not supported"}, 120 {4, "operation not supported"},
141 {5, "PH-SIM PIN required"}, 121 {5, "PH-SIM PIN required"},
142 {10, "SIM not inserted"}, 122 {10, "SIM not inserted"},
143 {11, "SIM PIN required"}, 123 {11, "SIM PIN required"},
144 {12, "SIM PUK required"}, 124 {12, "SIM PUK required"},
145 {13, "SIM failure"}, 125 {13, "SIM failure"},
146 {14, "SIM busy"}, 126 {14, "SIM busy"},
147 {15, "SIM wrong"}, 127 {15, "SIM wrong"},
148 {16, "incorrect password"}, 128 {16, "incorrect password"},
149 {17, "SIM PIN2 required"}, 129 {17, "SIM PIN2 required"},
150 {18, "SIM PUK2 required"}, 130 {18, "SIM PUK2 required"},
151 {20, "memory full"}, 131 {20, "memory full"},
152 {21, "invalid index"}, 132 {21, "invalid index"},
153 {22, "not found"}, 133 {22, "not found"},
154 {23, "memory failure"}, 134 {23, "memory failure"},
155 {24, "text string too long"}, 135 {24, "text string too long"},
156 {25, "invalid characters in text string"}, 136 {25, "invalid characters in text string"},
157 {26, "dial string too long"}, 137 {26, "dial string too long"},
158 {27, "invalid characters in dial string"}, 138 {27, "invalid characters in dial string"},
159 {30, "no network service"}, 139 {30, "no network service"},
160 {31, "network timeout"}, 140 {31, "network timeout"},
161 {100, "unknown"}, 141 {100, "unknown"},
162}; 142};
163 143
164 144
165GSM_Error ATGEN_HandleCMEError(GSM_StateMachine *s) 145GSM_Error ATGEN_HandleCMEError(GSM_StateMachine *s)
166{ 146{
167 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 147 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
168 148
169 if (Priv->ErrorCode == 0) { 149 if (Priv->ErrorCode == 0) {
170 smprintf(s, "CME Error occured, but it's type not detected\n"); 150 smprintf(s, "CME Error occured, but it's type not detected\n");
171 } else if (Priv->ErrorText == NULL) { 151 } else if (Priv->ErrorText == NULL) {
172 smprintf(s, "CME Error %i, no description available\n", Priv->ErrorCode); 152 smprintf(s, "CME Error %i, no description available\n", Priv->ErrorCode);
173 } else { 153 } else {
174 smprintf(s, "CME Error %i: \"%s\"\n", Priv->ErrorCode, Priv->ErrorText); 154 smprintf(s, "CME Error %i: \"%s\"\n", Priv->ErrorCode, Priv->ErrorText);
175 } 155 }
176 /* For error codes descriptions see table a bit above */ 156 /* For error codes descriptions see table a bit above */
177 switch (Priv->ErrorCode) { 157 switch (Priv->ErrorCode) {
158 case -1:
159 return ERR_EMPTY;
178 case 3: 160 case 3:
179 return ERR_PERMISSION; 161 return ERR_PERMISSION;
180 case 4: 162 case 4:
181 return ERR_NOTSUPPORTED; 163 return ERR_NOTSUPPORTED;
182 case 5: 164 case 5:
183 case 11: 165 case 11:
184 case 12: 166 case 12:
185 case 16: 167 case 16:
186 case 17: 168 case 17:
187 case 18: 169 case 18:
188 return ERR_SECURITYERROR; 170 return ERR_SECURITYERROR;
189 case 20: 171 case 20:
190 return ERR_FULL; 172 return ERR_FULL;
191 case 21: 173 case 21:
192 return ERR_INVALIDLOCATION; 174 return ERR_INVALIDLOCATION;
193 case 22: 175 case 22:
194 return ERR_EMPTY; 176 return ERR_EMPTY;
195 case 23: 177 case 23:
196 return ERR_MEMORY; 178 return ERR_MEMORY;
197 case 24: 179 case 24:
198 case 25: 180 case 25:
199 case 26: 181 case 26:
200 case 27: 182 case 27:
201 return ERR_INVALIDDATA; 183 return ERR_INVALIDDATA;
202 default: 184 default:
203 return ERR_UNKNOWN; 185 return ERR_UNKNOWN;
204 } 186 }
205} 187}
206 188
207GSM_Error ATGEN_HandleCMSError(GSM_StateMachine *s) 189GSM_Error ATGEN_HandleCMSError(GSM_StateMachine *s)
208{ 190{
209 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 191 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
210 192
211 if (Priv->ErrorCode == 0) { 193 if (Priv->ErrorCode == 0) {
212 smprintf(s, "CMS Error occured, but it's type not detected\n"); 194 smprintf(s, "CMS Error occured, but it's type not detected\n");
213 } else if (Priv->ErrorText == NULL) { 195 } else if (Priv->ErrorText == NULL) {
214 smprintf(s, "CMS Error %i, no description available\n", Priv->ErrorCode); 196 smprintf(s, "CMS Error %i, no description available\n", Priv->ErrorCode);
215 } else { 197 } else {
216 smprintf(s, "CMS Error %i: \"%s\"\n", Priv->ErrorCode, Priv->ErrorText); 198 smprintf(s, "CMS Error %i: \"%s\"\n", Priv->ErrorCode, Priv->ErrorText);
217 } 199 }
218 /* For error codes descriptions see table a bit above */ 200 /* For error codes descriptions see table a bit above */
219 switch (Priv->ErrorCode) { 201 switch (Priv->ErrorCode) {
220 case 304: 202 case 304:
221 return ERR_NOTSUPPORTED; 203 return ERR_NOTSUPPORTED;
222 case 305: 204 case 305:
223 return ERR_BUG; 205 return ERR_BUG;
224 case 311: 206 case 311:
225 case 312: 207 case 312:
226 case 316: 208 case 316:
227 case 317: 209 case 317:
228 case 318: 210 case 318:
229 return ERR_SECURITYERROR; 211 return ERR_SECURITYERROR;
230 case 322: 212 case 322:
231 return ERR_FULL; 213 return ERR_FULL;
232 case 321: 214 case 321:
233 return ERR_INVALIDLOCATION; 215 return ERR_INVALIDLOCATION;
234 default: 216 default:
235 return ERR_UNKNOWN; 217 return ERR_UNKNOWN;
236 } 218 }
237} 219}
238 220
239/* FIXME: Function doesn't respect quoting of parameters and thus +FOO: 221/* FIXME: Function doesn't respect quoting of parameters and thus +FOO:
240 * "ab","cd,ef" will consider as three arguments: "ab" >> "cd >> ef" 222 * "ab","cd,ef" will consider as three arguments: "ab" >> "cd >> ef"
241 */ 223 */
242int ATGEN_ExtractOneParameter(unsigned char *input, unsigned char *output) 224int ATGEN_ExtractOneParameter(unsigned char *input, unsigned char *output)
243{ 225{
244 int position=0; 226 int position=0;
245 227
246 while (*input!=',' && *input!=0x0d && *input!=0x00) { 228 while (*input!=',' && *input!=0x0d && *input!=0x00) {
247 *output=*input; 229 *output=*input;
248 input++; 230 input++;
249 output++; 231 output++;
250 position++; 232 position++;
251 } 233 }
252 *output=0; 234 *output=0;
253 position++; 235 position++;
254 return position; 236 return position;
255} 237}
256 238
257void ATGEN_DecodeDateTime(GSM_DateTime *dt, unsigned char *input) 239void ATGEN_DecodeDateTime(GSM_DateTime *dt, unsigned char *input)
258{ 240{
259 dt->Year=2000+(*input-'0')*10; input++; 241 /* Samsung phones report year as %d instead of %02d */
242 if (input[2] == '/') {
243 dt->Year=(*input-'0')*10;
244 input++;
245 } else {
246 dt->Year=0;
247 }
248
260 dt->Year=dt->Year+(*input-'0'); input++; 249 dt->Year=dt->Year+(*input-'0'); input++;
250 dt->Year+=2000;
261 251
262 input++; 252 input++;
263 dt->Month=(*input-'0')*10; input++; 253 dt->Month=(*input-'0')*10; input++;
264 dt->Month=dt->Month+(*input-'0'); input++; 254 dt->Month=dt->Month+(*input-'0'); input++;
265 255
266 input++; 256 input++;
267 dt->Day=(*input-'0')*10; input++; 257 dt->Day=(*input-'0')*10; input++;
268 dt->Day=dt->Day+(*input-'0'); input++; 258 dt->Day=dt->Day+(*input-'0'); input++;
269 259
270 input++; 260 input++;
271 dt->Hour=(*input-'0')*10; input++; 261 dt->Hour=(*input-'0')*10; input++;
272 dt->Hour=dt->Hour+(*input-'0'); input++; 262 dt->Hour=dt->Hour+(*input-'0'); input++;
273 263
274 input++; 264 input++;
275 dt->Minute=(*input-'0')*10; input++; 265 dt->Minute=(*input-'0')*10; input++;
276 dt->Minute=dt->Minute+(*input-'0');input++; 266 dt->Minute=dt->Minute+(*input-'0');input++;
277 267
278 input++; 268 input++;
279 dt->Second=(*input-'0')*10; input++; 269 dt->Second=(*input-'0')*10; input++;
280 dt->Second=dt->Second+(*input-'0');input++; 270 dt->Second=dt->Second+(*input-'0');input++;
281 271
282 if (input!=NULL) { 272 if (input!=NULL) {
283 input++; 273 input++;
284 dt->Timezone=(*input-'0')*10; input++; 274 dt->Timezone=(*input-'0')*10; input++;
285 dt->Timezone=dt->Timezone+(*input-'0');input++; 275 dt->Timezone=dt->Timezone+(*input-'0');input++;
286 input=input-2; 276 input=input-2;
287 if (*input=='-') dt->Timezone=-dt->Timezone; 277 if (*input=='-') dt->Timezone=-dt->Timezone;
288 } 278 }
289} 279}
290 280
291GSM_Error ATGEN_DispatchMessage(GSM_StateMachine *s) 281GSM_Error ATGEN_DispatchMessage(GSM_StateMachine *s)
292{ 282{
293 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 283 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
294 GSM_Protocol_Message *msg= s->Phone.Data.RequestMsg; 284 GSM_Protocol_Message *msg= s->Phone.Data.RequestMsg;
295 int i= 0, j, k; 285 int i= 0, j, k;
296 char *err, *line; 286 char *err, *line;
297 ATErrorCode *ErrorCodes = NULL; 287 ATErrorCode *ErrorCodes = NULL;
298 288
299 SplitLines(msg->Buffer, msg->Length, &Priv->Lines, "\x0D\x0A", 2, true); 289 SplitLines(msg->Buffer, msg->Length, &Priv->Lines, "\x0D\x0A", 2, true);
300 290
301 /* Find number of lines */ 291 /* Find number of lines */
302 while (Priv->Lines.numbers[i*2+1] != 0) { 292 while (Priv->Lines.numbers[i*2+1] != 0) {
303 /* FIXME: handle special chars correctly */ 293 /* FIXME: handle special chars correctly */
304 smprintf(s, "%i \"%s\"\n",i+1,GetLineString(msg->Buffer,Priv->Lines,i+1)); 294 smprintf(s, "%i \"%s\"\n",i+1,GetLineString(msg->Buffer,Priv->Lines,i+1));
305 i++; 295 i++;
306 } 296 }
307 297
308 Priv->ReplyState = AT_Reply_Unknown; 298 Priv->ReplyState = AT_Reply_Unknown;
309 Priv->ErrorText = NULL; 299 Priv->ErrorText = NULL;
310 Priv->ErrorCode = 0; 300 Priv->ErrorCode = 0;
311 301
312 line = GetLineString(msg->Buffer,Priv->Lines,i); 302 line = GetLineString(msg->Buffer,Priv->Lines,i);
313 if (!strcmp(line,"OK")) Priv->ReplyState = AT_Reply_OK; 303 if (!strcmp(line,"OK")) Priv->ReplyState = AT_Reply_OK;
314 if (!strcmp(line,"> ")) Priv->ReplyState = AT_Reply_SMSEdit; 304 if (!strcmp(line,"> ")) Priv->ReplyState = AT_Reply_SMSEdit;
315 if (!strcmp(line,"CONNECT"))Priv->ReplyState = AT_Reply_Connect; 305 if (!strcmp(line,"CONNECT"))Priv->ReplyState = AT_Reply_Connect;
316 if (!strcmp(line,"ERROR" ))Priv->ReplyState = AT_Reply_Error; 306 if (!strcmp(line,"ERROR" ))Priv->ReplyState = AT_Reply_Error;
317 if (!strncmp(line,"+CME ERROR:",11)) { 307 if (!strncmp(line,"+CME ERROR:",11)) {
318 Priv->ReplyState = AT_Reply_CMEError; 308 Priv->ReplyState = AT_Reply_CMEError;
319 ErrorCodes = CMEErrorCodes; 309 ErrorCodes = CMEErrorCodes;
320 } 310 }
321 if (!strncmp(line,"+CMS ERROR:",11)) { 311 if (!strncmp(line,"+CMS ERROR:",11)) {
322 Priv->ReplyState = AT_Reply_CMSError; 312 Priv->ReplyState = AT_Reply_CMSError;
323 ErrorCodes = CMSErrorCodes; 313 ErrorCodes = CMSErrorCodes;
324 } 314 }
315
316 /* FIXME: Samsung phones can answer +CME ERROR:-1 meaning empty location */
317 if (Priv->ReplyState == AT_Reply_CMEError && Priv->Manufacturer == AT_Samsung) {
318 err = line + 11;
319 Priv->ErrorCode = atoi(err);
320
321 if (Priv->ErrorCode == -1) {
322 Priv->ErrorText = "[Samsung] Empty location";
323 return GSM_DispatchMessage(s);
324 }
325 }
326
325 if (Priv->ReplyState == AT_Reply_CMEError || Priv->ReplyState == AT_Reply_CMSError) { 327 if (Priv->ReplyState == AT_Reply_CMEError || Priv->ReplyState == AT_Reply_CMSError) {
326 j = 0; 328 j = 0;
327 /* One char behind +CM[SE] ERROR */ 329 /* One char behind +CM[SE] ERROR */
328 err = line + 12; 330 err = line + 12;
329 while (err[j] && !isalnum(err[j])) j++; 331 while (err[j] && !isalnum(err[j])) j++;
330 if (isdigit(err[j])) { 332 if (isdigit(err[j])) {
331 Priv->ErrorCode = atoi(&(err[j])); 333 Priv->ErrorCode = atoi(&(err[j]));
332 k = 0; 334 k = 0;
333 while (ErrorCodes[k].Number != -1) { 335 while (ErrorCodes[k].Number != -1) {
334 if (ErrorCodes[k].Number == Priv->ErrorCode) { 336 if (ErrorCodes[k].Number == Priv->ErrorCode) {
335 Priv->ErrorText = (char *)&(ErrorCodes[k].Text); 337 Priv->ErrorText = (char *)&(ErrorCodes[k].Text);
336 break; 338 break;
337 } 339 }
338 k++; 340 k++;
339 } 341 }
340 } else if (isalpha(err[j])) { 342 } else if (isalpha(err[j])) {
341 k = 0; 343 k = 0;
342 while (ErrorCodes[k].Number != -1) { 344 while (ErrorCodes[k].Number != -1) {
343 if (!strncmp(err + j, ErrorCodes[k].Text, strlen(ErrorCodes[k].Text))) { 345 if (!strncmp(err + j, ErrorCodes[k].Text, strlen(ErrorCodes[k].Text))) {
344 Priv->ErrorCode = ErrorCodes[k].Number; 346 Priv->ErrorCode = ErrorCodes[k].Number;
345 Priv->ErrorText = (char *)&(ErrorCodes[k].Text); 347 Priv->ErrorText = (char *)&(ErrorCodes[k].Text);
346 break; 348 break;
347 } 349 }
348 k++; 350 k++;
349 } 351 }
350 } 352 }
351 } 353 }
352 return GSM_DispatchMessage(s); 354 return GSM_DispatchMessage(s);
353} 355}
354 356
355GSM_Error ATGEN_GenericReply(GSM_Protocol_Message msg, GSM_StateMachine *s) 357GSM_Error ATGEN_GenericReply(GSM_Protocol_Message msg, GSM_StateMachine *s)
356{ 358{
357 switch (s->Phone.Data.Priv.ATGEN.ReplyState) { 359 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
358 case AT_Reply_OK: 360 case AT_Reply_OK:
359 case AT_Reply_Connect: 361 case AT_Reply_Connect:
360 return ERR_NONE; 362 return ERR_NONE;
361 case AT_Reply_Error: 363 case AT_Reply_Error:
362 return ERR_UNKNOWN; 364 return ERR_UNKNOWN;
363 case AT_Reply_CMSError: 365 case AT_Reply_CMSError:
364 return ATGEN_HandleCMSError(s); 366 return ATGEN_HandleCMSError(s);
365 case AT_Reply_CMEError: 367 case AT_Reply_CMEError:
366 return ATGEN_HandleCMEError(s); 368 return ATGEN_HandleCMEError(s);
367 default: 369 default:
368 break; 370 break;
369 } 371 }
370 return ERR_UNKNOWNRESPONSE; 372 return ERR_UNKNOWNRESPONSE;
371} 373}
372 374
375GSM_Error ATGEN_ReplyGetUSSD(GSM_Protocol_Message msg, GSM_StateMachine *s)
376{
377 unsigned char buffer[2000],buffer2[4000];
378 int i = 10;
379
380 /* Ugly hack */
381 while (msg.Buffer[i]!=13) i++;
382 i = i - 6;
383 memcpy(buffer,msg.Buffer+10,i-11);
384 buffer[i-11] = 0x00;
385
386 smprintf(s, "USSD reply: \"%s\"\n",buffer);
387
388 if (s->Phone.Data.EnableIncomingUSSD && s->User.IncomingUSSD!=NULL) {
389 EncodeUnicode(buffer2,buffer,strlen(buffer));
390 s->User.IncomingUSSD(s->CurrentConfig->Device, buffer2);
391 }
392
393 return ERR_NONE;
394}
395
396GSM_Error ATGEN_SetIncomingUSSD(GSM_StateMachine *s, bool enable)
397{
398 GSM_Error error;
399
400 if (enable) {
401 smprintf(s, "Enabling incoming USSD\n");
402 error=GSM_WaitFor (s, "AT+CUSD=1\r", 10, 0x00, 3, ID_SetUSSD);
403 } else {
404 smprintf(s, "Disabling incoming USSD\n");
405 error=GSM_WaitFor (s, "AT+CUSD=0\r", 10, 0x00, 3, ID_SetUSSD);
406 }
407 if (error==ERR_NONE) s->Phone.Data.EnableIncomingUSSD = enable;
408 return error;
409}
410
373GSM_Error ATGEN_ReplyGetModel(GSM_Protocol_Message msg, GSM_StateMachine *s) 411GSM_Error ATGEN_ReplyGetModel(GSM_Protocol_Message msg, GSM_StateMachine *s)
374{ 412{
375 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 413 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
376 GSM_Phone_Data *Data = &s->Phone.Data; 414 GSM_Phone_Data *Data = &s->Phone.Data;
377 415
378 if (s->Phone.Data.Priv.ATGEN.ReplyState != AT_Reply_OK) return ERR_NOTSUPPORTED; 416 if (s->Phone.Data.Priv.ATGEN.ReplyState != AT_Reply_OK) return ERR_NOTSUPPORTED;
379 417
380 if (strlen(GetLineString(msg.Buffer, Priv->Lines, 2)) <= MAX_MODEL_LENGTH) { 418 if (strlen(GetLineString(msg.Buffer, Priv->Lines, 2)) <= MAX_MODEL_LENGTH) {
381 CopyLineString(Data->Model, msg.Buffer, Priv->Lines, 2); 419 CopyLineString(Data->Model, msg.Buffer, Priv->Lines, 2);
382 420
383 /* Sometimes phone adds this before manufacturer (Sagem) */ 421 /* Sometimes phone adds this before manufacturer (Sagem) */
384 if (strncmp("+CGMM: ", Data->Model, 7) == 0) { 422 if (strncmp("+CGMM: ", Data->Model, 7) == 0) {
385 memmove(Data->Model, Data->Model + 7, strlen(Data->Model + 7) + 1); 423 memmove(Data->Model, Data->Model + 7, strlen(Data->Model + 7) + 1);
386 } 424 }
387 425
388 Data->ModelInfo = GetModelData(NULL,Data->Model,NULL); 426 Data->ModelInfo = GetModelData(NULL,Data->Model,NULL);
389 if (Data->ModelInfo->number[0] == 0) Data->ModelInfo = GetModelData(NULL,NULL,Data->Model); 427 if (Data->ModelInfo->number[0] == 0) Data->ModelInfo = GetModelData(NULL,NULL,Data->Model);
390 if (Data->ModelInfo->number[0] == 0) Data->ModelInfo = GetModelData(Data->Model,NULL,NULL); 428 if (Data->ModelInfo->number[0] == 0) Data->ModelInfo = GetModelData(Data->Model,NULL,NULL);
391 429
392 if (Data->ModelInfo->number[0] != 0) strcpy(Data->Model,Data->ModelInfo->number); 430 if (Data->ModelInfo->number[0] != 0) strcpy(Data->Model,Data->ModelInfo->number);
393 431
394 if (strstr(msg.Buffer,"Nokia")) Priv->Manufacturer = AT_Nokia; 432 if (strstr(msg.Buffer,"Nokia")) Priv->Manufacturer = AT_Nokia;
395 else if (strstr(msg.Buffer,"M20")) Priv->Manufacturer = AT_Siemens; 433 else if (strstr(msg.Buffer,"M20")) Priv->Manufacturer = AT_Siemens;
396 else if (strstr(msg.Buffer,"MC35")) Priv->Manufacturer = AT_Siemens; 434 else if (strstr(msg.Buffer,"MC35")) Priv->Manufacturer = AT_Siemens;
435 else if (strstr(msg.Buffer,"TC35")) Priv->Manufacturer = AT_Siemens;
397 else if (strstr(msg.Buffer, "iPAQ")) Priv->Manufacturer = AT_HP; 436 else if (strstr(msg.Buffer, "iPAQ")) Priv->Manufacturer = AT_HP;
398 437
399 if (strstr(msg.Buffer,"M20")) strcpy(Data->Model,"M20"); 438 if (strstr(msg.Buffer,"M20")) strcpy(Data->Model,"M20");
400 else if (strstr(msg.Buffer,"MC35")) strcpy(Data->Model,"MC35"); 439 else if (strstr(msg.Buffer,"MC35")) strcpy(Data->Model,"MC35");
440 else if (strstr(msg.Buffer,"TC35")) strcpy(Data->Model,"TC35");
401 else if (strstr(msg.Buffer, "iPAQ")) strcpy(Data->Model,"iPAQ"); 441 else if (strstr(msg.Buffer, "iPAQ")) strcpy(Data->Model,"iPAQ");
402 } else { 442 } else {
403 smprintf(s, "WARNING: Model name too long, increase MAX_MODEL_LENGTH to at least %zd\n", strlen(GetLineString(msg.Buffer, Priv->Lines, 2))); 443 smprintf(s, "WARNING: Model name too long, increase MAX_MODEL_LENGTH to at least %zd\n", strlen(GetLineString(msg.Buffer, Priv->Lines, 2)));
404 } 444 }
405 445
406 return ERR_NONE; 446 return ERR_NONE;
407} 447}
408 448
409GSM_Error ATGEN_GetModel(GSM_StateMachine *s) 449GSM_Error ATGEN_GetModel(GSM_StateMachine *s)
410{ 450{
411 GSM_Error error; 451 GSM_Error error;
412 452
413 if (s->Phone.Data.Model[0] != 0) return ERR_NONE; 453 if (s->Phone.Data.Model[0] != 0) return ERR_NONE;
414 454
415 smprintf(s, "Getting model\n"); 455 smprintf(s, "Getting model\n");
416 error=GSM_WaitFor (s, "AT+CGMM\r", 8, 0x00, 3, ID_GetModel); 456 error=GSM_WaitFor (s, "AT+CGMM\r", 8, 0x00, 3, ID_GetModel);
417 if (error==ERR_NONE) { 457 if (error==ERR_NONE) {
418 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || 458 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL ||
419 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) { 459 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) {
420 smprintf(s, "[Connected model - \"%s\"]\n",s->Phone.Data.Model); 460 smprintf(s, "[Connected model - \"%s\"]\n",s->Phone.Data.Model);
421 } 461 }
422 } 462 }
423 return error; 463 return error;
424} 464}
425 465
426GSM_Error ATGEN_ReplyGetManufacturer(GSM_Protocol_Message msg, GSM_StateMachine *s) 466GSM_Error ATGEN_ReplyGetManufacturer(GSM_Protocol_Message msg, GSM_StateMachine *s)
427{ 467{
428 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 468 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
429 469
430 switch (Priv->ReplyState) { 470 switch (Priv->ReplyState) {
431 case AT_Reply_OK: 471 case AT_Reply_OK:
432 smprintf(s, "Manufacturer info received\n"); 472 smprintf(s, "Manufacturer info received\n");
433 Priv->Manufacturer = AT_Unknown; 473 Priv->Manufacturer = AT_Unknown;
434 if (strlen(GetLineString(msg.Buffer, Priv->Lines, 2)) <= MAX_MANUFACTURER_LENGTH) { 474 if (strlen(GetLineString(msg.Buffer, Priv->Lines, 2)) <= MAX_MANUFACTURER_LENGTH) {
435 CopyLineString(s->Phone.Data.Manufacturer, msg.Buffer, Priv->Lines, 2); 475 CopyLineString(s->Phone.Data.Manufacturer, msg.Buffer, Priv->Lines, 2);
436 } else { 476 } else {
437 smprintf(s, "WARNING: Manufacturer name too long, increase MAX_MANUFACTURER_LENGTH to at least %zd\n", strlen(GetLineString(msg.Buffer, Priv->Lines, 2))); 477 smprintf(s, "WARNING: Manufacturer name too long, increase MAX_MANUFACTURER_LENGTH to at least %zd\n", strlen(GetLineString(msg.Buffer, Priv->Lines, 2)));
438 s->Phone.Data.Manufacturer[0] = 0; 478 s->Phone.Data.Manufacturer[0] = 0;
439 } 479 }
440 /* Sometimes phone adds this before manufacturer (Sagem) */ 480 /* Sometimes phone adds this before manufacturer (Sagem) */
441 if (strncmp("+CGMI: ", s->Phone.Data.Manufacturer, 7) == 0) { 481 if (strncmp("+CGMI: ", s->Phone.Data.Manufacturer, 7) == 0) {
442 memmove(s->Phone.Data.Manufacturer, s->Phone.Data.Manufacturer + 7, strlen(s->Phone.Data.Manufacturer + 7) + 1); 482 memmove(s->Phone.Data.Manufacturer, s->Phone.Data.Manufacturer + 7, strlen(s->Phone.Data.Manufacturer + 7) + 1);
443 } 483 }
444 if (strstr(msg.Buffer,"Falcom")) { 484 if (strstr(msg.Buffer,"Falcom")) {
445 smprintf(s, "Falcom\n"); 485 smprintf(s, "Falcom\n");
446 strcpy(s->Phone.Data.Manufacturer,"Falcom"); 486 strcpy(s->Phone.Data.Manufacturer,"Falcom");
447 Priv->Manufacturer = AT_Falcom; 487 Priv->Manufacturer = AT_Falcom;
448 if (strstr(msg.Buffer,"A2D")) { 488 if (strstr(msg.Buffer,"A2D")) {
449 strcpy(s->Phone.Data.Model,"A2D"); 489 strcpy(s->Phone.Data.Model,"A2D");
450 s->Phone.Data.ModelInfo = GetModelData(NULL,s->Phone.Data.Model,NULL); 490 s->Phone.Data.ModelInfo = GetModelData(NULL,s->Phone.Data.Model,NULL);
451 smprintf(s, "Model A2D\n"); 491 smprintf(s, "Model A2D\n");
452 } 492 }
453 } 493 }
454 if (strstr(msg.Buffer,"Nokia")) { 494 if (strstr(msg.Buffer,"Nokia")) {
455 smprintf(s, "Nokia\n"); 495 smprintf(s, "Nokia\n");
456 strcpy(s->Phone.Data.Manufacturer,"Nokia"); 496 strcpy(s->Phone.Data.Manufacturer,"Nokia");
457 Priv->Manufacturer = AT_Nokia; 497 Priv->Manufacturer = AT_Nokia;
458 } 498 }
459 if (strstr(msg.Buffer,"SIEMENS")) { 499 if (strstr(msg.Buffer,"SIEMENS")) {
460 smprintf(s, "Siemens\n"); 500 smprintf(s, "Siemens\n");
461 strcpy(s->Phone.Data.Manufacturer,"Siemens"); 501 strcpy(s->Phone.Data.Manufacturer,"Siemens");
462 Priv->Manufacturer = AT_Siemens; 502 Priv->Manufacturer = AT_Siemens;
463 } 503 }
464 if (strstr(msg.Buffer,"ERICSSON")) { 504 if (strstr(msg.Buffer,"ERICSSON")) {
465 smprintf(s, "Ericsson\n"); 505 smprintf(s, "Ericsson\n");
466 strcpy(s->Phone.Data.Manufacturer,"Ericsson"); 506 strcpy(s->Phone.Data.Manufacturer,"Ericsson");
467 Priv->Manufacturer = AT_Ericsson; 507 Priv->Manufacturer = AT_Ericsson;
468 } 508 }
469 if (strstr(msg.Buffer,"iPAQ")) { 509 if (strstr(msg.Buffer,"iPAQ")) {
470 smprintf(s, "iPAQ\n"); 510 smprintf(s, "iPAQ\n");
471 strcpy(s->Phone.Data.Manufacturer,"HP"); 511 strcpy(s->Phone.Data.Manufacturer,"HP");
472 Priv->Manufacturer = AT_HP; 512 Priv->Manufacturer = AT_HP;
473 } 513 }
474 if (strstr(msg.Buffer,"ALCATEL")) { 514 if (strstr(msg.Buffer,"ALCATEL")) {
475 smprintf(s, "Alcatel\n"); 515 smprintf(s, "Alcatel\n");
476 strcpy(s->Phone.Data.Manufacturer,"Alcatel"); 516 strcpy(s->Phone.Data.Manufacturer,"Alcatel");
477 Priv->Manufacturer = AT_Alcatel; 517 Priv->Manufacturer = AT_Alcatel;
478 } 518 }
479 if (strstr(msg.Buffer,"SAGEM")) { 519 if (strstr(msg.Buffer,"SAGEM")) {
480 smprintf(s, "Sagem\n"); 520 smprintf(s, "Sagem\n");
481 strcpy(s->Phone.Data.Manufacturer,"Sagem"); 521 strcpy(s->Phone.Data.Manufacturer,"Sagem");
482 Priv->Manufacturer = AT_Sagem; 522 Priv->Manufacturer = AT_Sagem;
483 } 523 }
524 if (strstr(msg.Buffer,"Samsung")) {
525 smprintf(s, "Samsung\n");
526 strcpy(s->Phone.Data.Manufacturer,"Samsung");
527 Priv->Manufacturer = AT_Samsung;
528 }
484 return ERR_NONE; 529 return ERR_NONE;
485 case AT_Reply_CMSError: 530 case AT_Reply_CMSError:
486 return ATGEN_HandleCMSError(s); 531 return ATGEN_HandleCMSError(s);
487 default: 532 default:
488 break; 533 break;
489 } 534 }
490 return ERR_UNKNOWNRESPONSE; 535 return ERR_UNKNOWNRESPONSE;
491} 536}
492 537
493GSM_Error ATGEN_GetManufacturer(GSM_StateMachine *s) 538GSM_Error ATGEN_GetManufacturer(GSM_StateMachine *s)
494{ 539{
495 if (s->Phone.Data.Manufacturer[0] != 0) return ERR_NONE; 540 if (s->Phone.Data.Manufacturer[0] != 0) return ERR_NONE;
496 541
497 return GSM_WaitFor (s, "AT+CGMI\r", 8, 0x00, 4, ID_GetManufacturer); 542 return GSM_WaitFor (s, "AT+CGMI\r", 8, 0x00, 4, ID_GetManufacturer);
498} 543}
499 544
500GSM_Error ATGEN_ReplyGetFirmwareCGMR(GSM_Protocol_Message msg, GSM_StateMachine *s) 545GSM_Error ATGEN_ReplyGetFirmwareCGMR(GSM_Protocol_Message msg, GSM_StateMachine *s)
501{ 546{
502 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 547 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
503 unsigned int i = 0; 548 unsigned int i = 0;
504 549
505 strcpy(s->Phone.Data.Version,"unknown"); 550 strcpy(s->Phone.Data.Version,"unknown");
506 s->Phone.Data.VerNum = 0; 551 s->Phone.Data.VerNum = 0;
507 if (Priv->ReplyState == AT_Reply_OK) { 552 if (Priv->ReplyState == AT_Reply_OK) {
508 CopyLineString(s->Phone.Data.Version, msg.Buffer, Priv->Lines, 2); 553 CopyLineString(s->Phone.Data.Version, msg.Buffer, Priv->Lines, 2);
509 /* Sometimes phone adds this before manufacturer (Sagem) */ 554 /* Sometimes phone adds this before manufacturer (Sagem) */
510 if (strncmp("+CGMR: ", s->Phone.Data.Version, 7) == 0) { 555 if (strncmp("+CGMR: ", s->Phone.Data.Version, 7) == 0) {
511 memmove(s->Phone.Data.Version, s->Phone.Data.Version + 7, strlen(s->Phone.Data.Version + 7) + 1); 556 memmove(s->Phone.Data.Version, s->Phone.Data.Version + 7, strlen(s->Phone.Data.Version + 7) + 1);
512 } 557 }
513 } 558 }
514 if (Priv->Manufacturer == AT_Ericsson) { 559 if (Priv->Manufacturer == AT_Ericsson) {
515 while (1) { 560 while (1) {
516 if (s->Phone.Data.Version[i] == 0x20) { 561 if (s->Phone.Data.Version[i] == 0x20) {
517 s->Phone.Data.Version[i] = 0x00; 562 s->Phone.Data.Version[i] = 0x00;
518 break; 563 break;
519 } 564 }
520 if (i == strlen(s->Phone.Data.Version)) break; 565 if (i == strlen(s->Phone.Data.Version)) break;
521 i++; 566 i++;
522 } 567 }
523 } 568 }
524 smprintf(s, "Received firmware version: \"%s\"\n",s->Phone.Data.Version); 569 smprintf(s, "Received firmware version: \"%s\"\n",s->Phone.Data.Version);
525 GSM_CreateFirmwareNumber(s); 570 GSM_CreateFirmwareNumber(s);
526 return ERR_NONE; 571 return ERR_NONE;
527} 572}
528 573
529GSM_Error ATGEN_ReplyGetFirmwareATI(GSM_Protocol_Message msg, GSM_StateMachine *s) 574GSM_Error ATGEN_ReplyGetFirmwareATI(GSM_Protocol_Message msg, GSM_StateMachine *s)
530{ 575{
531 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 576 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
532 577
533 switch (Priv->ReplyState) { 578 switch (Priv->ReplyState) {
534 case AT_Reply_OK: 579 case AT_Reply_OK:
535 // strcpy(Data->Version,"0.00"); 580 // strcpy(Data->Version,"0.00");
536 // *Data->VersionNum=0; 581 // *Data->VersionNum=0;
537 // if (Data->Priv.ATGEN.ReplyState==AT_Reply_OK) { 582 // if (Data->Priv.ATGEN.ReplyState==AT_Reply_OK) {
538 // CopyLineString(Data->Version, msg.Buffer, Priv->Lines, 2); 583 // CopyLineString(Data->Version, msg.Buffer, Priv->Lines, 2);
539 // } 584 // }
540 // smprintf(s, "Received firmware version: \"%s\"\n",Data->Version); 585 // smprintf(s, "Received firmware version: \"%s\"\n",Data->Version);
541 // GSM_CreateFirmwareNumber(Data); 586 // GSM_CreateFirmwareNumber(Data);
542 // return ERR_NONE; 587 // return ERR_NONE;
543 case AT_Reply_Error: 588 case AT_Reply_Error:
544 return ERR_NOTSUPPORTED; 589 return ERR_NOTSUPPORTED;
545 case AT_Reply_CMSError: 590 case AT_Reply_CMSError:
546 return ATGEN_HandleCMSError(s); 591 return ATGEN_HandleCMSError(s);
547 default: 592 default:
548 break; 593 break;
549 } 594 }
550 return ERR_UNKNOWNRESPONSE; 595 return ERR_UNKNOWNRESPONSE;
551} 596}
552 597
553GSM_Error ATGEN_GetFirmware(GSM_StateMachine *s) 598GSM_Error ATGEN_GetFirmware(GSM_StateMachine *s)
554{ 599{
555 GSM_Error error; 600 GSM_Error error;
556 601
557 if (s->Phone.Data.Version[0] != 0) return ERR_NONE; 602 if (s->Phone.Data.Version[0] != 0) return ERR_NONE;
558 603
559 error=ATGEN_GetManufacturer(s); 604 error=ATGEN_GetManufacturer(s);
560 if (error != ERR_NONE) return error; 605 if (error != ERR_NONE) return error;
561 606
562 //smprintf(s, "Getting firmware - method 1\n"); 607 //smprintf(s, "Getting firmware - method 1\n");
563 //error=GSM_WaitFor (s, "ATI\r", 4, 0x00, 3, ID_GetFirmware); 608 //error=GSM_WaitFor (s, "ATI\r", 4, 0x00, 3, ID_GetFirmware);
564 //if (error != ERR_NONE) { 609 //if (error != ERR_NONE) {
565 smprintf(s, "Getting firmware - method 2\n"); 610 smprintf(s, "Getting firmware - method 2\n");
566 error=GSM_WaitFor (s, "AT+CGMR\r", 8, 0x00, 3, ID_GetFirmware); 611 error=GSM_WaitFor (s, "AT+CGMR\r", 8, 0x00, 3, ID_GetFirmware);
567 //} 612 //}
568 if (error==ERR_NONE) { 613 if (error==ERR_NONE) {
569 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || 614 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL ||
570 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) { 615 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) {
571 smprintf(s, "[Firmware version - \"%s\"]\n",s->Phone.Data.Version); 616 smprintf(s, "[Firmware version - \"%s\"]\n",s->Phone.Data.Version);
572 } 617 }
573 } 618 }
574 return error; 619 return error;
575} 620}
576 621
577GSM_Error ATGEN_Initialise(GSM_StateMachine *s) 622GSM_Error ATGEN_Initialise(GSM_StateMachine *s)
578{ 623{
579 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 624 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
580 GSM_Error error; 625 GSM_Error error;
581 char buff[2]; 626 char buff[2];
582 627
583 Priv->SMSMode = 0; 628 Priv->SMSMode = 0;
584 Priv->Manufacturer = 0; 629 Priv->Manufacturer = 0;
585 Priv->PhoneSMSMemory = 0; 630 Priv->PhoneSMSMemory = 0;
586 Priv->CanSaveSMS = false; 631 Priv->CanSaveSMS = false;
587 Priv->SIMSMSMemory = 0; 632 Priv->SIMSMSMemory = 0;
588 Priv->SMSMemory = 0; 633 Priv->SMSMemory = 0;
589 Priv->PBKMemory = 0; 634 Priv->PBKMemory = 0;
590 Priv->PBKSBNR = 0; 635 Priv->PBKSBNR = 0;
591 Priv->PBKCharset = 0; 636 Priv->PBKCharset = 0;
592 Priv->UCS2CharsetFailed = false; 637 Priv->UCS2CharsetFailed = false;
593 Priv->NonUCS2CharsetFailed= false; 638 Priv->NonUCS2CharsetFailed= false;
594 Priv->PBKMemories[0] = 0; 639 Priv->PBKMemories[0] = 0;
595 Priv->FirstCalendarPos = 0; 640 Priv->FirstCalendarPos = 0;
596 Priv->NextMemoryEntry = 0; 641 Priv->NextMemoryEntry = 0;
597 Priv->FirstMemoryEntry = 0; 642 Priv->FirstMemoryEntry = 0;
598 Priv->file.Used = 0; 643 Priv->file.Used = 0;
599 Priv->file.Buffer = NULL; 644 Priv->file.Buffer = NULL;
600 Priv->OBEX = false; 645 Priv->OBEX = false;
601 Priv->MemorySize = 0; 646 Priv->MemorySize = 0;
602 Priv->TextLength = 0; 647 Priv->TextLength = 0;
603 Priv->NumberLength = 0; 648 Priv->NumberLength = 0;
604 649
605 Priv->ErrorText = NULL; 650 Priv->ErrorText = NULL;
606 651
607 if (s->ConnectionType != GCT_IRDAAT && s->ConnectionType != GCT_BLUEAT) { 652 if (s->ConnectionType != GCT_IRDAAT && s->ConnectionType != GCT_BLUEAT) {
608 /* We try to escape AT+CMGS mode, at least Siemens M20 653 /* We try to escape AT+CMGS mode, at least Siemens M20
609 * then needs to get some rest 654 * then needs to get some rest
610 */ 655 */
611 smprintf(s, "Escaping SMS mode\n"); 656 smprintf(s, "Escaping SMS mode\n");
612 error = s->Protocol.Functions->WriteMessage(s, "\x1B\r", 2, 0x00); 657 error = s->Protocol.Functions->WriteMessage(s, "\x1B\r", 2, 0x00);
613 if (error!=ERR_NONE) return error; 658 if (error!=ERR_NONE) return error;
614 659
615 /* Grab any possible garbage */ 660 /* Grab any possible garbage */
616 while (s->Device.Functions->ReadDevice(s, buff, 2) > 0) my_sleep(10); 661 while (s->Device.Functions->ReadDevice(s, buff, 2) > 0) my_sleep(10);
617 } 662 }
618 663
619 /* When some phones (Alcatel BE5) is first time connected, it needs extra 664 /* When some phones (Alcatel BE5) is first time connected, it needs extra
620 * time to react, sending just AT wakes up the phone and it then can react 665 * time to react, sending just AT wakes up the phone and it then can react
621 * to ATE1. We don't need to check whether this fails as it is just to 666 * to ATE1. We don't need to check whether this fails as it is just to
622 * wake up the phone and does nothing. 667 * wake up the phone and does nothing.
623 */ 668 */
624 smprintf(s, "Sending simple AT command to wake up some devices\n"); 669 smprintf(s, "Sending simple AT command to wake up some devices\n");
625 GSM_WaitFor (s, "AT\r", 3, 0x00, 2, ID_IncomingFrame); 670 GSM_WaitFor (s, "AT\r", 3, 0x00, 2, ID_IncomingFrame);
626 671
627 smprintf(s, "Enabling echo\n"); 672 smprintf(s, "Enabling echo\n");
628 error = GSM_WaitFor (s, "ATE1\r", 5, 0x00, 3, ID_EnableEcho); 673 error = GSM_WaitFor (s, "ATE1\r", 5, 0x00, 3, ID_EnableEcho);
629 if (error != ERR_NONE) return error; 674 if (error != ERR_NONE) return error;
630 675
631 smprintf(s, "Enabling CME errors\n"); 676 smprintf(s, "Enabling CME errors\n");
632 /* Try numeric errors */ 677 /* Try numeric errors */
633 if (GSM_WaitFor (s, "AT+CMEE=1\r", 10, 0x00, 3, ID_EnableErrorInfo) != ERR_NONE) { 678 if (GSM_WaitFor (s, "AT+CMEE=1\r", 10, 0x00, 3, ID_EnableErrorInfo) != ERR_NONE) {
634 /* Try textual errors */ 679 /* Try textual errors */
635 if (GSM_WaitFor (s, "AT+CMEE=2\r", 10, 0x00, 3, ID_EnableErrorInfo) != ERR_NONE) { 680 if (GSM_WaitFor (s, "AT+CMEE=2\r", 10, 0x00, 3, ID_EnableErrorInfo) != ERR_NONE) {
636 smprintf(s, "CME errors could not be enabled, some error types won't be detected.\n"); 681 smprintf(s, "CME errors could not be enabled, some error types won't be detected.\n");
637 } 682 }
638 } 683 }
639 684
640 error = ATGEN_GetModel(s); 685 error = ATGEN_GetModel(s);
641 if (error != ERR_NONE) return error; 686 if (error != ERR_NONE) return error;
642 687
643 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SLOWWRITE)) { 688 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SLOWWRITE)) {
644 s->Protocol.Data.AT.FastWrite = true; 689 s->Protocol.Data.AT.FastWrite = true;
645 } 690 }
646 691
647 return error; 692 return error;
648} 693}
649 694
650GSM_Error ATGEN_SetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc) 695GSM_Error ATGEN_SetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc)
651{ 696{
652 unsigned char req[50]; 697 unsigned char req[50];
653 698
654 if (smsc->Location!=1) return ERR_NOTSUPPORTED; 699 if (smsc->Location!=1) return ERR_NOTSUPPORTED;
655 700
656 sprintf(req, "AT+CSCA=\"%s\"\r",DecodeUnicodeString(smsc->Number)); 701 sprintf(req, "AT+CSCA=\"%s\"\r",DecodeUnicodeString(smsc->Number));
657 702
658 smprintf(s, "Setting SMSC\n"); 703 smprintf(s, "Setting SMSC\n");
659 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_SetSMSC); 704 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_SetSMSC);
660} 705}
661 706
662GSM_Error ATGEN_ReplyGetSMSMemories(GSM_Protocol_Message msg, GSM_StateMachine *s) 707GSM_Error ATGEN_ReplyGetSMSMemories(GSM_Protocol_Message msg, GSM_StateMachine *s)
663{ 708{
664 switch (s->Phone.Data.Priv.ATGEN.ReplyState) { 709 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
665 case AT_Reply_OK: 710 case AT_Reply_OK:
666 /* Reply here is: 711 /* Reply here is:
667 * (memories for reading)[, (memories for writing)[, (memories for storing received messages)]] 712 * (memories for reading)[, (memories for writing)[, (memories for storing received messages)]]
668 * each memory is in quotes, 713 * each memory is in quotes,
669 * Example: ("SM"), ("SM"), ("SM") 714 * Example: ("SM"), ("SM"), ("SM")
670 * 715 *
671 * We need to get from this supported memories. For this case 716 * We need to get from this supported memories. For this case
672 * we assume, that just appearence of memory makes it 717 * we assume, that just appearence of memory makes it
673 * available for everything. Then we need to find out whether 718 * available for everything. Then we need to find out whether
674 * phone supports writing to memory. This is done by searching 719 * phone supports writing to memory. This is done by searching
675 * for "), (", which will appear between lists. 720 * for "), (", which will appear between lists.
676 */ 721 */
677 s->Phone.Data.Priv.ATGEN.CanSaveSMS = (strstr(msg.Buffer, "), (") != NULL); 722 s->Phone.Data.Priv.ATGEN.CanSaveSMS = false;
723 if (strstr(msg.Buffer, "), (") != NULL || strstr(msg.Buffer, "),(") != NULL) {
724 s->Phone.Data.Priv.ATGEN.CanSaveSMS = true;
725 }
726
678 if (strstr(msg.Buffer, "\"SM\"") != NULL) s->Phone.Data.Priv.ATGEN.SIMSMSMemory = AT_AVAILABLE; 727 if (strstr(msg.Buffer, "\"SM\"") != NULL) s->Phone.Data.Priv.ATGEN.SIMSMSMemory = AT_AVAILABLE;
679 else s->Phone.Data.Priv.ATGEN.SIMSMSMemory = AT_NOTAVAILABLE; 728 else s->Phone.Data.Priv.ATGEN.SIMSMSMemory = AT_NOTAVAILABLE;
729
680 if (strstr(msg.Buffer, "\"ME\"") != NULL) s->Phone.Data.Priv.ATGEN.PhoneSMSMemory = AT_AVAILABLE; 730 if (strstr(msg.Buffer, "\"ME\"") != NULL) s->Phone.Data.Priv.ATGEN.PhoneSMSMemory = AT_AVAILABLE;
681 else s->Phone.Data.Priv.ATGEN.PhoneSMSMemory = AT_NOTAVAILABLE; 731 else s->Phone.Data.Priv.ATGEN.PhoneSMSMemory = AT_NOTAVAILABLE;
682 smprintf(s, "Available SMS memories received, ME = %d, SM = %d\n", s->Phone.Data.Priv.ATGEN.PhoneSMSMemory, s->Phone.Data.Priv.ATGEN.SIMSMSMemory); 732
733 smprintf(s, "Available SMS memories received, ME = %d, SM = %d, cansavesms =", s->Phone.Data.Priv.ATGEN.PhoneSMSMemory, s->Phone.Data.Priv.ATGEN.SIMSMSMemory);
734 if (s->Phone.Data.Priv.ATGEN.CanSaveSMS) smprintf(s, "true");
735 smprintf(s, "\n");
683 return ERR_NONE; 736 return ERR_NONE;
684 case AT_Reply_Error: 737 case AT_Reply_Error:
685 case AT_Reply_CMSError: 738 case AT_Reply_CMSError:
686 return ATGEN_HandleCMSError(s); 739 return ATGEN_HandleCMSError(s);
740 case AT_Reply_CMEError:
741 return ATGEN_HandleCMEError(s);
687 default: 742 default:
688 return ERR_UNKNOWNRESPONSE; 743 return ERR_UNKNOWNRESPONSE;
689 } 744 }
690} 745}
691 746
692GSM_Error ATGEN_GetSMSMemories(GSM_StateMachine *s) 747GSM_Error ATGEN_GetSMSMemories(GSM_StateMachine *s)
693{ 748{
694 smprintf(s, "Getting available SMS memories\n"); 749 smprintf(s, "Getting available SMS memories\n");
695 return GSM_WaitFor (s, "AT+CPMS=?\r", 10, 0x00, 4, ID_GetSMSMemories); 750 return GSM_WaitFor (s, "AT+CPMS=?\r", 10, 0x00, 4, ID_GetSMSMemories);
696} 751}
697 752
698GSM_Error ATGEN_SetSMSMemory(GSM_StateMachine *s, bool SIM) 753GSM_Error ATGEN_SetSMSMemory(GSM_StateMachine *s, bool SIM)
699{ 754{
700 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 755 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
701 char req[] = "AT+CPMS=\"XX\",\"XX\"\r"; 756 char req[] = "AT+CPMS=\"XX\",\"XX\"\r";
702 int reqlen = 18; 757 int reqlen = 18;
703 GSM_Error error; 758 GSM_Error error;
704 759
705 if ((SIM && Priv->SIMSMSMemory == 0) || (!SIM && Priv->PhoneSMSMemory == 0)) { 760 if ((SIM && Priv->SIMSMSMemory == 0) || (!SIM && Priv->PhoneSMSMemory == 0)) {
706 /* We silently ignore error here, because when this fails, we can try to setmemory anyway */ 761 /* We silently ignore error here, because when this fails, we can try to setmemory anyway */
707 ATGEN_GetSMSMemories(s); 762 ATGEN_GetSMSMemories(s);
708 } 763 }
709 764
710 /* If phone can not save SMS, don't try to set memory for saving */ 765 /* If phone can not save SMS, don't try to set memory for saving */
711 if (!Priv->CanSaveSMS) { 766 if (!Priv->CanSaveSMS) {
712 req[12] = '\r'; 767 req[12] = '\r';
713 reqlen = 13; 768 reqlen = 13;
714 } 769 }
715 770
716 if (SIM) { 771 if (SIM) {
717 if (Priv->SMSMemory == MEM_SM) return ERR_NONE; 772 if (Priv->SMSMemory == MEM_SM) return ERR_NONE;
718 if (Priv->SIMSMSMemory == AT_NOTAVAILABLE) return ERR_NOTSUPPORTED; 773 if (Priv->SIMSMSMemory == AT_NOTAVAILABLE) return ERR_NOTSUPPORTED;
719 774
720 req[9] = 'S'; req[10] = 'M'; 775 req[9] = 'S'; req[10] = 'M';
721 req[14] = 'S'; req[15] = 'M'; 776 req[14] = 'S'; req[15] = 'M';
722 777
723 smprintf(s, "Setting SMS memory type to SM\n"); 778 smprintf(s, "Setting SMS memory type to SM\n");
724 error=GSM_WaitFor (s, req, reqlen, 0x00, 3, ID_SetMemoryType); 779 error=GSM_WaitFor (s, req, reqlen, 0x00, 3, ID_SetMemoryType);
725 if (Priv->SIMSMSMemory == 0 && error == ERR_NONE) { 780 if (Priv->SIMSMSMemory == 0 && error == ERR_NONE) {
726 Priv->SIMSMSMemory = AT_AVAILABLE; 781 Priv->SIMSMSMemory = AT_AVAILABLE;
727 } 782 }
728 if (error == ERR_NOTSUPPORTED) { 783 if (error == ERR_NOTSUPPORTED) {
729 smprintf(s, "Can't access SIM card?\n"); 784 smprintf(s, "Can't access SIM card?\n");
730 return ERR_SECURITYERROR; 785 return ERR_SECURITYERROR;
731 } 786 }
732 if (error != ERR_NONE) return error; 787 if (error != ERR_NONE) return error;
733 Priv->SMSMemory = MEM_SM; 788 Priv->SMSMemory = MEM_SM;
734 } else { 789 } else {
735 if (Priv->SMSMemory == MEM_ME) return ERR_NONE; 790 if (Priv->SMSMemory == MEM_ME) return ERR_NONE;
736 if (Priv->PhoneSMSMemory == AT_NOTAVAILABLE) return ERR_NOTSUPPORTED; 791 if (Priv->PhoneSMSMemory == AT_NOTAVAILABLE) return ERR_NOTSUPPORTED;
737 792
738 req[9] = 'M'; req[10] = 'E'; 793 req[9] = 'M'; req[10] = 'E';
739 req[14] = 'M'; req[15] = 'E'; 794 req[14] = 'M'; req[15] = 'E';
740 795
741 smprintf(s, "Setting SMS memory type to ME\n"); 796 smprintf(s, "Setting SMS memory type to ME\n");
742 error=GSM_WaitFor (s, req, reqlen, 0x00, 3, ID_SetMemoryType); 797 error=GSM_WaitFor (s, req, reqlen, 0x00, 3, ID_SetMemoryType);
743 if (Priv->PhoneSMSMemory == 0 && error == ERR_NONE) { 798 if (Priv->PhoneSMSMemory == 0 && error == ERR_NONE) {
744 Priv->PhoneSMSMemory = AT_AVAILABLE; 799 Priv->PhoneSMSMemory = AT_AVAILABLE;
745 } 800 }
746 if (error == ERR_NONE) Priv->SMSMemory = MEM_ME; 801 if (error == ERR_NONE) Priv->SMSMemory = MEM_ME;
747 } 802 }
748 return error; 803 return error;
749} 804}
750 805
751GSM_Error ATGEN_GetSMSMode(GSM_StateMachine *s) 806GSM_Error ATGEN_GetSMSMode(GSM_StateMachine *s)
752{ 807{
753 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 808 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
754 GSM_Error error; 809 GSM_Error error;
755 810
756 if (Priv->SMSMode != 0) return ERR_NONE; 811 if (Priv->SMSMode != 0) return ERR_NONE;
757 812
758 smprintf(s, "Trying SMS PDU mode\n"); 813 smprintf(s, "Trying SMS PDU mode\n");
759 error=GSM_WaitFor (s, "AT+CMGF=0\r", 10, 0x00, 3, ID_GetSMSMode); 814 error=GSM_WaitFor (s, "AT+CMGF=0\r", 10, 0x00, 3, ID_GetSMSMode);
760 if (error==ERR_NONE) { 815 if (error==ERR_NONE) {
761 Priv->SMSMode = SMS_AT_PDU; 816 Priv->SMSMode = SMS_AT_PDU;
762 return ERR_NONE; 817 return ERR_NONE;
763 } 818 }
764 819
765 smprintf(s, "Trying SMS text mode\n"); 820 smprintf(s, "Trying SMS text mode\n");
766 error=GSM_WaitFor (s, "AT+CMGF=1\r", 10, 0x00, 3, ID_GetSMSMode); 821 error=GSM_WaitFor (s, "AT+CMGF=1\r", 10, 0x00, 3, ID_GetSMSMode);
767 if (error==ERR_NONE) { 822 if (error==ERR_NONE) {
768 smprintf(s, "Enabling displaying all parameters in text mode\n"); 823 smprintf(s, "Enabling displaying all parameters in text mode\n");
769 error=GSM_WaitFor (s, "AT+CSDH=1\r", 10, 0x00, 3, ID_GetSMSMode); 824 error=GSM_WaitFor (s, "AT+CSDH=1\r", 10, 0x00, 3, ID_GetSMSMode);
770 if (error == ERR_NONE) Priv->SMSMode = SMS_AT_TXT; 825 if (error == ERR_NONE) Priv->SMSMode = SMS_AT_TXT;
771 } 826 }
772 827
773 return error; 828 return error;
774} 829}
775 830
776GSM_Error ATGEN_GetSMSLocation(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char *folderid, int *location) 831GSM_Error ATGEN_GetSMSLocation(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char *folderid, int *location)
777{ 832{
778 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 833 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
779 int ifolderid, maxfolder; 834 int ifolderid, maxfolder;
780 GSM_Error error; 835 GSM_Error error;
781 836
782 if (Priv->PhoneSMSMemory == 0) { 837 if (Priv->PhoneSMSMemory == 0) {
783 error = ATGEN_SetSMSMemory(s, false); 838 error = ATGEN_SetSMSMemory(s, false);
784 if (error != ERR_NONE && error != ERR_NOTSUPPORTED) return error; 839 if (error != ERR_NONE && error != ERR_NOTSUPPORTED) return error;
785 } 840 }
786 if (Priv->SIMSMSMemory == 0) { 841 if (Priv->SIMSMSMemory == 0) {
787 error = ATGEN_SetSMSMemory(s, true); 842 error = ATGEN_SetSMSMemory(s, true);
788 if (error != ERR_NONE && error != ERR_NOTSUPPORTED) return error; 843 if (error != ERR_NONE && error != ERR_NOTSUPPORTED) return error;
789 } 844 }
790 845
791 if (Priv->SIMSMSMemory != AT_AVAILABLE && Priv->PhoneSMSMemory != AT_AVAILABLE) { 846 if (Priv->SIMSMSMemory != AT_AVAILABLE && Priv->PhoneSMSMemory != AT_AVAILABLE) {
792 /* No SMS memory at all */ 847 /* No SMS memory at all */
793 return ERR_NOTSUPPORTED; 848 return ERR_NOTSUPPORTED;
794 } 849 }
795 if (Priv->SIMSMSMemory == AT_AVAILABLE && Priv->PhoneSMSMemory == AT_AVAILABLE) { 850 if (Priv->SIMSMSMemory == AT_AVAILABLE && Priv->PhoneSMSMemory == AT_AVAILABLE) {
796 /* Both available */ 851 /* Both available */
797 maxfolder = 2; 852 maxfolder = 2;
798 } else { 853 } else {
799 /* One available */ 854 /* One available */
800 maxfolder = 1; 855 maxfolder = 1;
801 } 856 }
802 857
803 /* simulate flat SMS memory */ 858 /* simulate flat SMS memory */
804 if (sms->Folder == 0x00) { 859 if (sms->Folder == 0x00) {
805 ifolderid = sms->Location / PHONE_MAXSMSINFOLDER; 860 ifolderid = sms->Location / PHONE_MAXSMSINFOLDER;
806 if (ifolderid + 1 > maxfolder) return ERR_NOTSUPPORTED; 861 if (ifolderid + 1 > maxfolder) return ERR_NOTSUPPORTED;
807 *folderid = ifolderid + 1; 862 *folderid = ifolderid + 1;
808 *location = sms->Location - ifolderid * PHONE_MAXSMSINFOLDER; 863 *location = sms->Location - ifolderid * PHONE_MAXSMSINFOLDER;
809 } else { 864 } else {
810 if (sms->Folder > 2 * maxfolder) return ERR_NOTSUPPORTED; 865 if (sms->Folder > 2 * maxfolder) return ERR_NOTSUPPORTED;
811 *folderid = sms->Folder <= 2 ? 1 : 2; 866 *folderid = sms->Folder <= 2 ? 1 : 2;
812 *location = sms->Location; 867 *location = sms->Location;
813 } 868 }
814 smprintf(s, "SMS folder %i & location %i -> ATGEN folder %i & location %i\n", 869 smprintf(s, "SMS folder %i & location %i -> ATGEN folder %i & location %i\n",
815 sms->Folder,sms->Location,*folderid,*location); 870 sms->Folder,sms->Location,*folderid,*location);
816 871
817 if (Priv->SIMSMSMemory == AT_AVAILABLE && *folderid == 1) { 872 if (Priv->SIMSMSMemory == AT_AVAILABLE && *folderid == 1) {
818 return ATGEN_SetSMSMemory(s, true); 873 return ATGEN_SetSMSMemory(s, true);
819 } else { 874 } else {
820 return ATGEN_SetSMSMemory(s, false); 875 return ATGEN_SetSMSMemory(s, false);
821 } 876 }
822} 877}
823 878
824void ATGEN_SetSMSLocation(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char folderid, int location) 879void ATGEN_SetSMSLocation(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char folderid, int location)
825{ 880{
826 sms->Folder= 0; 881 sms->Folder= 0;
827 sms->Location= (folderid - 1) * PHONE_MAXSMSINFOLDER + location; 882 sms->Location= (folderid - 1) * PHONE_MAXSMSINFOLDER + location;
828 smprintf(s, "ATGEN folder %i & location %i -> SMS folder %i & location %i\n", 883 smprintf(s, "ATGEN folder %i & location %i -> SMS folder %i & location %i\n",
829 folderid,location,sms->Folder,sms->Location); 884 folderid,location,sms->Folder,sms->Location);
830} 885}
831 886
832GSM_Error ATGEN_ReplyGetSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s) 887GSM_Error ATGEN_ReplyGetSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s)
833{ 888{
834 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 889 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
835 GSM_SMSMessage *sms= &s->Phone.Data.GetSMSMessage->SMS[0]; 890 GSM_SMSMessage *sms= &s->Phone.Data.GetSMSMessage->SMS[0];
836 int current = 0, current2, i; 891 int current = 0, current2, i;
837 unsigned char buffer[300],smsframe[800]; 892 unsigned char buffer[300],smsframe[800];
838 unsigned char firstbyte, TPDCS, TPUDL, TPStatus; 893 unsigned char firstbyte, TPDCS, TPUDL, TPStatus;
839 GSM_Error error; 894 GSM_Error error;
840 895
841 switch (Priv->ReplyState) { 896 switch (Priv->ReplyState) {
842 case AT_Reply_OK: 897 case AT_Reply_OK:
843 if (Priv->Lines.numbers[4] == 0x00) return ERR_EMPTY; 898 if (Priv->Lines.numbers[4] == 0x00) return ERR_EMPTY;
844 s->Phone.Data.GetSMSMessage->Number = 1; 899 s->Phone.Data.GetSMSMessage->Number = 1;
845 s->Phone.Data.GetSMSMessage->SMS[0].Name[0] = 0; 900 s->Phone.Data.GetSMSMessage->SMS[0].Name[0] = 0;
846 s->Phone.Data.GetSMSMessage->SMS[0].Name[1]= 0; 901 s->Phone.Data.GetSMSMessage->SMS[0].Name[1]= 0;
847 switch (Priv->SMSMode) { 902 switch (Priv->SMSMode) {
848 case SMS_AT_PDU: 903 case SMS_AT_PDU:
849 CopyLineString(buffer, msg.Buffer, Priv->Lines, 2); 904 CopyLineString(buffer, msg.Buffer, Priv->Lines, 2);
850 switch (buffer[7]) { 905 switch (buffer[7]) {
851 case '0': sms->State = SMS_UnRead; break; 906 case '0': sms->State = SMS_UnRead; break;
852 case '1': sms->State = SMS_Read;break; 907 case '1': sms->State = SMS_Read;break;
853 case '2': sms->State = SMS_UnSent;break; 908 case '2': sms->State = SMS_UnSent;break;
854 default : sms->State = SMS_Sent;break;//case '3' 909 default : sms->State = SMS_Sent;break;//case '3'
855 } 910 }
856 DecodeHexBin (buffer, GetLineString(msg.Buffer,Priv->Lines,3), strlen(GetLineString(msg.Buffer,Priv->Lines,3))); 911 DecodeHexBin (buffer, GetLineString(msg.Buffer,Priv->Lines,3), strlen(GetLineString(msg.Buffer,Priv->Lines,3)));
857 /* Siemens MC35 (only ?) */ 912 /* Siemens MC35 (only ?) */
858 if (strstr(msg.Buffer,"+CMGR: 0,,0")!=NULL) return ERR_EMPTY; 913 if (strstr(msg.Buffer,"+CMGR: 0,,0")!=NULL) return ERR_EMPTY;
859 /* Siemens M20 */ 914 /* Siemens M20 */
860 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_M20SMS)) { 915 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_M20SMS)) {
861 if (buffer[1]!=NUMBER_UNKNOWN && buffer[1]!=NUMBER_INTERNATIONAL && 916 /* we check for the most often visible */
862 buffer[1]!=NUMBER_ALPHANUMERIC) { 917 if (buffer[1]!=NUMBER_UNKNOWN_NUMBERING_PLAN_ISDN && buffer[1]!=NUMBER_INTERNATIONAL_NUMBERING_PLAN_ISDN &&
918 buffer[1]!=NUMBER_ALPHANUMERIC_NUMBERING_PLAN_UNKNOWN) {
863 /* Seems to be Delivery Report */ 919 /* Seems to be Delivery Report */
864 smprintf(s, "SMS type - status report (M20 style)\n"); 920 smprintf(s, "SMS type - status report (M20 style)\n");
865 sms->PDU = SMS_Status_Report; 921 sms->PDU = SMS_Status_Report;
866 sms->Folder = 1;/*INBOX SIM*/ 922 sms->Folder = 1;/*INBOX SIM*/
867 sms->InboxFolder = true; 923 sms->InboxFolder = true;
868 924
869 smsframe[12]=buffer[current++]; 925 smsframe[12]=buffer[current++];
870 smsframe[PHONE_SMSStatusReport.TPMR]=buffer[current++]; 926 smsframe[PHONE_SMSStatusReport.TPMR]=buffer[current++];
871 current2=((buffer[current])+1)/2+1; 927 current2=((buffer[current])+1)/2+1;
872 for(i=0;i<current2+1;i++) smsframe[PHONE_SMSStatusReport.Number+i]=buffer[current++]; 928 for(i=0;i<current2+1;i++) smsframe[PHONE_SMSStatusReport.Number+i]=buffer[current++];
873 for(i=0;i<7;i++) smsframe[PHONE_SMSStatusReport.DateTime+i]=buffer[current++]; 929 for(i=0;i<7;i++) smsframe[PHONE_SMSStatusReport.DateTime+i]=buffer[current++];
874 smsframe[0] = 0; 930 smsframe[0] = 0;
875 for(i=0;i<7;i++) smsframe[PHONE_SMSStatusReport.SMSCTime+i]=buffer[current++]; 931 for(i=0;i<7;i++) smsframe[PHONE_SMSStatusReport.SMSCTime+i]=buffer[current++];
876 smsframe[PHONE_SMSStatusReport.TPStatus]=buffer[current]; 932 smsframe[PHONE_SMSStatusReport.TPStatus]=buffer[current];
877 GSM_DecodeSMSFrame(sms,smsframe,PHONE_SMSStatusReport); 933 GSM_DecodeSMSFrame(sms,smsframe,PHONE_SMSStatusReport);
878 return ERR_NONE; 934 return ERR_NONE;
879 } 935 }
880 } 936 }
881 /* We use locations from SMS layouts like in ../phone2.c(h) */ 937 /* We use locations from SMS layouts like in ../phone2.c(h) */
882 for(i=0;i<buffer[0]+1;i++) smsframe[i]=buffer[current++]; 938 for(i=0;i<buffer[0]+1;i++) smsframe[i]=buffer[current++];
883 smsframe[12]=buffer[current++]; 939 smsframe[12]=buffer[current++];
884 /* See GSM 03.40 section 9.2.3.1 */ 940 /* See GSM 03.40 section 9.2.3.1 */
885 switch (smsframe[12] & 0x03) { 941 switch (smsframe[12] & 0x03) {
886 case 0x00: 942 case 0x00:
887 smprintf(s, "SMS type - deliver\n"); 943 smprintf(s, "SMS type - deliver\n");
888 sms->PDU = SMS_Deliver; 944 sms->PDU = SMS_Deliver;
889 if (Priv->SMSMemory == MEM_SM) { 945 if (Priv->SMSMemory == MEM_SM) {
890 sms->Folder = 1; /*INBOX SIM*/ 946 sms->Folder = 1; /*INBOX SIM*/
891 } else { 947 } else {
892 sms->Folder = 3; /*INBOX ME*/ 948 sms->Folder = 3; /*INBOX ME*/
893 } 949 }
894 sms->InboxFolder = true; 950 sms->InboxFolder = true;
895 current2=((buffer[current])+1)/2+1; 951 current2=((buffer[current])+1)/2+1;
896 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_M20SMS)) { 952 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_M20SMS)) {
897 if (buffer[current+1]==NUMBER_ALPHANUMERIC) { 953 if (buffer[current+1]==NUMBER_ALPHANUMERIC_NUMBERING_PLAN_UNKNOWN) {
898 smprintf(s, "Trying to read alphanumeric number\n"); 954 smprintf(s, "Trying to read alphanumeric number\n");
899 for(i=0;i<4;i++) smsframe[PHONE_SMSDeliver.Number+i]=buffer[current++]; 955 for(i=0;i<4;i++) smsframe[PHONE_SMSDeliver.Number+i]=buffer[current++];
900 current+=6; 956 current+=6;
901 for(i=0;i<current2-3;i++) smsframe[PHONE_SMSDeliver.Number+i+4]=buffer[current++]; 957 for(i=0;i<current2-3;i++) smsframe[PHONE_SMSDeliver.Number+i+4]=buffer[current++];
902 } else { 958 } else {
903 for(i=0;i<current2+1;i++) smsframe[PHONE_SMSDeliver.Number+i]=buffer[current++]; 959 for(i=0;i<current2+1;i++) smsframe[PHONE_SMSDeliver.Number+i]=buffer[current++];
904 } 960 }
905 } else { 961 } else {
906 for(i=0;i<current2+1;i++) smsframe[PHONE_SMSDeliver.Number+i]=buffer[current++]; 962 for(i=0;i<current2+1;i++) smsframe[PHONE_SMSDeliver.Number+i]=buffer[current++];
907 } 963 }
908 smsframe[PHONE_SMSDeliver.TPPID] = buffer[current++]; 964 smsframe[PHONE_SMSDeliver.TPPID] = buffer[current++];
909 smsframe[PHONE_SMSDeliver.TPDCS] = buffer[current++]; 965 smsframe[PHONE_SMSDeliver.TPDCS] = buffer[current++];
910 for(i=0;i<7;i++) smsframe[PHONE_SMSDeliver.DateTime+i]=buffer[current++]; 966 for(i=0;i<7;i++) smsframe[PHONE_SMSDeliver.DateTime+i]=buffer[current++];
911 smsframe[PHONE_SMSDeliver.TPUDL] = buffer[current++]; 967 smsframe[PHONE_SMSDeliver.TPUDL] = buffer[current++];
912 for(i=0;i<smsframe[PHONE_SMSDeliver.TPUDL];i++) smsframe[i+PHONE_SMSDeliver.Text]=buffer[current++]; 968 for(i=0;i<smsframe[PHONE_SMSDeliver.TPUDL];i++) smsframe[i+PHONE_SMSDeliver.Text]=buffer[current++];
913 GSM_DecodeSMSFrame(sms,smsframe,PHONE_SMSDeliver); 969 GSM_DecodeSMSFrame(sms,smsframe,PHONE_SMSDeliver);
914 return ERR_NONE; 970 return ERR_NONE;
915 case 0x01: 971 case 0x01:
916 smprintf(s, "SMS type - submit\n"); 972 smprintf(s, "SMS type - submit\n");
917 sms->PDU = SMS_Submit; 973 sms->PDU = SMS_Submit;
918 if (Priv->SMSMemory == MEM_SM) { 974 if (Priv->SMSMemory == MEM_SM) {
919 sms->Folder = 2; /*OUTBOX SIM*/ 975 sms->Folder = 2; /*OUTBOX SIM*/
920 smprintf(s, "Outbox SIM\n"); 976 smprintf(s, "Outbox SIM\n");
921 } else { 977 } else {
922 sms->Folder = 4; /*OUTBOX ME*/ 978 sms->Folder = 4; /*OUTBOX ME*/
923 } 979 }
924 sms->InboxFolder = false; 980 sms->InboxFolder = false;
925 smsframe[PHONE_SMSSubmit.TPMR] = buffer[current++]; 981 smsframe[PHONE_SMSSubmit.TPMR] = buffer[current++];
926 current2=((buffer[current])+1)/2+1; 982 current2=((buffer[current])+1)/2+1;
927 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_M20SMS)) { 983 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_M20SMS)) {
928 if (buffer[current+1]==NUMBER_ALPHANUMERIC) { 984 if (buffer[current+1]==NUMBER_ALPHANUMERIC_NUMBERING_PLAN_UNKNOWN) {
929 smprintf(s, "Trying to read alphanumeric number\n"); 985 smprintf(s, "Trying to read alphanumeric number\n");
930 for(i=0;i<4;i++) smsframe[PHONE_SMSSubmit.Number+i]=buffer[current++]; 986 for(i=0;i<4;i++) smsframe[PHONE_SMSSubmit.Number+i]=buffer[current++];
931 current+=6; 987 current+=6;
932 for(i=0;i<current2-3;i++) smsframe[PHONE_SMSSubmit.Number+i+4]=buffer[current++]; 988 for(i=0;i<current2-3;i++) smsframe[PHONE_SMSSubmit.Number+i+4]=buffer[current++];
933 } else { 989 } else {
934 for(i=0;i<current2+1;i++) smsframe[PHONE_SMSSubmit.Number+i]=buffer[current++]; 990 for(i=0;i<current2+1;i++) smsframe[PHONE_SMSSubmit.Number+i]=buffer[current++];
935 } 991 }
936 } else { 992 } else {
937 for(i=0;i<current2+1;i++) smsframe[PHONE_SMSSubmit.Number+i]=buffer[current++]; 993 for(i=0;i<current2+1;i++) smsframe[PHONE_SMSSubmit.Number+i]=buffer[current++];
938 } 994 }
939 smsframe[PHONE_SMSSubmit.TPPID] = buffer[current++]; 995 smsframe[PHONE_SMSSubmit.TPPID] = buffer[current++];
940 smsframe[PHONE_SMSSubmit.TPDCS] = buffer[current++]; 996 smsframe[PHONE_SMSSubmit.TPDCS] = buffer[current++];
941 /* See GSM 03.40 9.2.3.3 - TPVP can not exist in frame */ 997 /* See GSM 03.40 9.2.3.3 - TPVP can not exist in frame */
942 if ((smsframe[12] & 0x18)!=0) current++; //TPVP is ignored now 998 if ((smsframe[12] & 0x18)!=0) current++; //TPVP is ignored now
943 smsframe[PHONE_SMSSubmit.TPUDL] = buffer[current++]; 999 smsframe[PHONE_SMSSubmit.TPUDL] = buffer[current++];
944 for(i=0;i<smsframe[PHONE_SMSSubmit.TPUDL];i++) smsframe[i+PHONE_SMSSubmit.Text]=buffer[current++]; 1000 for(i=0;i<smsframe[PHONE_SMSSubmit.TPUDL];i++) smsframe[i+PHONE_SMSSubmit.Text]=buffer[current++];
945 GSM_DecodeSMSFrame(sms,smsframe,PHONE_SMSSubmit); 1001 GSM_DecodeSMSFrame(sms,smsframe,PHONE_SMSSubmit);
946 return ERR_NONE; 1002 return ERR_NONE;
947 case 0x02: 1003 case 0x02:
948 smprintf(s, "SMS type - status report\n"); 1004 smprintf(s, "SMS type - status report\n");
949 sms->PDU = SMS_Status_Report; 1005 sms->PDU = SMS_Status_Report;
950 sms->Folder = 1;/*INBOX SIM*/ 1006 sms->Folder = 1;/*INBOX SIM*/
951 sms->InboxFolder = true; 1007 sms->InboxFolder = true;
952 smprintf(s, "TPMR is %02x\n",buffer[current]); 1008 smprintf(s, "TPMR is %d\n",buffer[current]);
953 smsframe[PHONE_SMSStatusReport.TPMR] = buffer[current++]; 1009 smsframe[PHONE_SMSStatusReport.TPMR] = buffer[current++];
954 current2=((buffer[current])+1)/2+1; 1010 current2=((buffer[current])+1)/2+1;
955 for(i=0;i<current2+1;i++) smsframe[PHONE_SMSStatusReport.Number+i]=buffer[current++]; 1011 for(i=0;i<current2+1;i++) smsframe[PHONE_SMSStatusReport.Number+i]=buffer[current++];
956 for(i=0;i<7;i++) smsframe[PHONE_SMSStatusReport.DateTime+i]=buffer[current++]; 1012 for(i=0;i<7;i++) smsframe[PHONE_SMSStatusReport.DateTime+i]=buffer[current++];
957 for(i=0;i<7;i++) smsframe[PHONE_SMSStatusReport.SMSCTime+i]=buffer[current++]; 1013 for(i=0;i<7;i++) smsframe[PHONE_SMSStatusReport.SMSCTime+i]=buffer[current++];
958 smsframe[PHONE_SMSStatusReport.TPStatus]=buffer[current]; 1014 smsframe[PHONE_SMSStatusReport.TPStatus]=buffer[current];
959 GSM_DecodeSMSFrame(sms,smsframe,PHONE_SMSStatusReport); 1015 GSM_DecodeSMSFrame(sms,smsframe,PHONE_SMSStatusReport);
960 return ERR_NONE; 1016 return ERR_NONE;
961 } 1017 }
962 break; 1018 break;
963 case SMS_AT_TXT: 1019 case SMS_AT_TXT:
964 current = 0; 1020 current = 0;
965 while (msg.Buffer[current]!='"') current++; 1021 while (msg.Buffer[current]!='"') current++;
966 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1022 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
967 if (!strcmp(buffer,"\"0\"") || !strcmp(buffer,"\"REC UNREAD\"")) { 1023 if (!strcmp(buffer,"\"0\"") || !strcmp(buffer,"\"REC UNREAD\"")) {
968 smprintf(s, "SMS type - deliver\n"); 1024 smprintf(s, "SMS type - deliver\n");
969 sms->State = SMS_UnRead; 1025 sms->State = SMS_UnRead;
970 sms->PDU = SMS_Deliver; 1026 sms->PDU = SMS_Deliver;
971 if (Priv->SMSMemory == MEM_SM) { 1027 if (Priv->SMSMemory == MEM_SM) {
972 sms->Folder = 1; /*INBOX SIM*/ 1028 sms->Folder = 1; /*INBOX SIM*/
973 } else { 1029 } else {
974 sms->Folder = 3; /*INBOX ME*/ 1030 sms->Folder = 3; /*INBOX ME*/
975 } 1031 }
976 sms->InboxFolder = true; 1032 sms->InboxFolder = true;
977 } else if (!strcmp(buffer,"\"1\"") || !strcmp(buffer,"\"REC READ\"")) { 1033 } else if (!strcmp(buffer,"\"1\"") || !strcmp(buffer,"\"REC READ\"")) {
978 smprintf(s, "SMS type - deliver\n"); 1034 smprintf(s, "SMS type - deliver\n");
979 sms->State = SMS_Read; 1035 sms->State = SMS_Read;
980 sms->PDU = SMS_Deliver; 1036 sms->PDU = SMS_Deliver;
981 if (Priv->SMSMemory == MEM_SM) { 1037 if (Priv->SMSMemory == MEM_SM) {
982 sms->Folder = 1; /*INBOX SIM*/ 1038 sms->Folder = 1; /*INBOX SIM*/
983 } else { 1039 } else {
984 sms->Folder = 3; /*INBOX ME*/ 1040 sms->Folder = 3; /*INBOX ME*/
985 } 1041 }
986 sms->InboxFolder = true; 1042 sms->InboxFolder = true;
987 } else if (!strcmp(buffer,"\"2\"") || !strcmp(buffer,"\"STO UNSENT\"")) { 1043 } else if (!strcmp(buffer,"\"2\"") || !strcmp(buffer,"\"STO UNSENT\"")) {
988 smprintf(s, "SMS type - submit\n"); 1044 smprintf(s, "SMS type - submit\n");
989 sms->State = SMS_UnSent; 1045 sms->State = SMS_UnSent;
990 sms->PDU = SMS_Submit; 1046 sms->PDU = SMS_Submit;
991 if (Priv->SMSMemory == MEM_SM) { 1047 if (Priv->SMSMemory == MEM_SM) {
992 sms->Folder = 2; /*OUTBOX SIM*/ 1048 sms->Folder = 2; /*OUTBOX SIM*/
993 } else { 1049 } else {
994 sms->Folder = 4; /*OUTBOX ME*/ 1050 sms->Folder = 4; /*OUTBOX ME*/
995 } 1051 }
996 sms->InboxFolder = false; 1052 sms->InboxFolder = false;
997 } else if (!strcmp(buffer,"\"3\"") || !strcmp(buffer,"\"STO SENT\"")) { 1053 } else if (!strcmp(buffer,"\"3\"") || !strcmp(buffer,"\"STO SENT\"")) {
998 smprintf(s, "SMS type - submit\n"); 1054 smprintf(s, "SMS type - submit\n");
999 sms->State = SMS_Sent; 1055 sms->State = SMS_Sent;
1000 sms->PDU = SMS_Submit; 1056 sms->PDU = SMS_Submit;
1001 if (Priv->SMSMemory == MEM_SM) { 1057 if (Priv->SMSMemory == MEM_SM) {
1002 sms->Folder = 2; /*OUTBOX SIM*/ 1058 sms->Folder = 2; /*OUTBOX SIM*/
1003 } else { 1059 } else {
1004 sms->Folder = 4; /*OUTBOX ME*/ 1060 sms->Folder = 4; /*OUTBOX ME*/
1005 } 1061 }
1006 sms->InboxFolder = false; 1062 sms->InboxFolder = false;
1007 } 1063 }
1008 current += ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1064 current += ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1009 /* It's delivery report according to Nokia AT standards */ 1065 /* It's delivery report according to Nokia AT standards */
1010 if (sms->Folder==1 && buffer[0]!=0 && buffer[0]!='"') { 1066 if (sms->Folder==1 && buffer[0]!=0 && buffer[0]!='"') {
1011 /* ??? */ 1067 /* ??? */
1012 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1068 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1013 /* format of sender number */ 1069 /* format of sender number */
1014 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1070 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1015 /* Sender number */ 1071 /* Sender number */
1016 /* FIXME: support for all formats */ 1072 /* FIXME: support for all formats */
1017 EncodeUnicode(sms->Number,buffer+1,strlen(buffer)-2); 1073 EncodeUnicode(sms->Number,buffer+1,strlen(buffer)-2);
1018 smprintf(s, "Sender \"%s\"\n",DecodeUnicodeString(sms->Number)); 1074 smprintf(s, "Sender \"%s\"\n",DecodeUnicodeString(sms->Number));
1019 /* ??? */ 1075 /* ??? */
1020 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1076 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1021 /* Sending datetime */ 1077 /* Sending datetime */
1022 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1078 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1023 i = strlen(buffer); 1079 i = strlen(buffer);
1024 buffer[i] = ','; 1080 buffer[i] = ',';
1025 i++; 1081 i++;
1026 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer+i); 1082 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer+i);
1027 smprintf(s, "\"%s\"\n",buffer); 1083 smprintf(s, "\"%s\"\n",buffer);
1028 ATGEN_DecodeDateTime(&sms->DateTime, buffer+1); 1084 ATGEN_DecodeDateTime(&sms->DateTime, buffer+1);
1029 /* Date of SMSC response */ 1085 /* Date of SMSC response */
1030 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1086 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1031 i = strlen(buffer); 1087 i = strlen(buffer);
1032 buffer[i] = ','; 1088 buffer[i] = ',';
1033 i++; 1089 i++;
1034 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer+i); 1090 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer+i);
1035 smprintf(s, "\"%s\"\n",buffer); 1091 smprintf(s, "\"%s\"\n",buffer);
1036 ATGEN_DecodeDateTime(&sms->SMSCTime, buffer+1); 1092 ATGEN_DecodeDateTime(&sms->SMSCTime, buffer+1);
1037 /* TPStatus */ 1093 /* TPStatus */
1038 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1094 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1039 TPStatus=atoi(buffer); 1095 TPStatus=atoi(buffer);
1040 buffer[PHONE_SMSStatusReport.TPStatus] = TPStatus; 1096 buffer[PHONE_SMSStatusReport.TPStatus] = TPStatus;
1041 error=GSM_DecodeSMSFrameStatusReportData(sms, buffer, PHONE_SMSStatusReport); 1097 error=GSM_DecodeSMSFrameStatusReportData(sms, buffer, PHONE_SMSStatusReport);
1042 if (error!=ERR_NONE) return error; 1098 if (error!=ERR_NONE) return error;
1043 /* NO SMSC number */ 1099 /* NO SMSC number */
1044 sms->SMSC.Number[0]=0; 1100 sms->SMSC.Number[0]=0;
1045 sms->SMSC.Number[1]=0; 1101 sms->SMSC.Number[1]=0;
1046 sms->PDU = SMS_Status_Report; 1102 sms->PDU = SMS_Status_Report;
1047 sms->ReplyViaSameSMSC=false; 1103 sms->ReplyViaSameSMSC=false;
1048 } else { 1104 } else {
1049 /* Sender number */ 1105 /* Sender number */
1050 /* FIXME: support for all formats */ 1106 /* FIXME: support for all formats */
1051 EncodeUnicode(sms->Number,buffer+1,strlen(buffer)-2); 1107 EncodeUnicode(sms->Number,buffer+1,strlen(buffer)-2);
1052 /* Sender number in alphanumeric format ? */ 1108 /* Sender number in alphanumeric format ? */
1053 current += ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1109 current += ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1054 if (strlen(buffer)!=0) EncodeUnicode(sms->Number,buffer+1,strlen(buffer)-2); 1110 if (strlen(buffer)!=0) EncodeUnicode(sms->Number,buffer+1,strlen(buffer)-2);
1055 smprintf(s, "Sender \"%s\"\n",DecodeUnicodeString(sms->Number)); 1111 smprintf(s, "Sender \"%s\"\n",DecodeUnicodeString(sms->Number));
1056 /* Sending datetime */ 1112 /* Sending datetime */
1057 if (sms->Folder==1 || sms->Folder==3) { 1113 if (sms->Folder==1 || sms->Folder==3) {
1058 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1114 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1059 /* FIXME: ATGEN_ExtractOneParameter() is broken as it doesn't respect 1115 /* FIXME: ATGEN_ExtractOneParameter() is broken as it doesn't respect
1060 * quoting of parameters and thus +FOO: "ab","cd,ef" will consider 1116 * quoting of parameters and thus +FOO: "ab","cd,ef" will consider
1061 * as three arguments: "ab" >> "cd >> ef" 1117 * as three arguments: "ab" >> "cd >> ef"
1062 */ 1118 */
1063 if (*buffer=='"') { 1119 if (*buffer=='"') {
1064 i = strlen(buffer); 1120 i = strlen(buffer);
1065 buffer[i] = ','; 1121 buffer[i] = ',';
1066 i++; 1122 i++;
1067 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer+i); 1123 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer+i);
1068 } 1124 }
1069 smprintf(s, "\"%s\"\n",buffer); 1125 smprintf(s, "\"%s\"\n",buffer);
1070 if (*buffer) 1126 if (*buffer)
1071 ATGEN_DecodeDateTime(&sms->DateTime, buffer+1); 1127 ATGEN_DecodeDateTime(&sms->DateTime, buffer+1);
1072 else { 1128 else {
1073 /* FIXME: What is the proper undefined GSM_DateTime ? */ 1129 /* FIXME: What is the proper undefined GSM_DateTime ? */
1074 memset(&sms->DateTime, 0, sizeof(sms->DateTime)); 1130 memset(&sms->DateTime, 0, sizeof(sms->DateTime));
1075 } 1131 }
1076 ATGEN_DecodeDateTime(&sms->DateTime, buffer+1); 1132 ATGEN_DecodeDateTime(&sms->DateTime, buffer+1);
1077 } 1133 }
1078 /* Sender number format */ 1134 /* Sender number format */
1079 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1135 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1080 /* First byte */ 1136 /* First byte */
1081 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1137 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1082 firstbyte=atoi(buffer); 1138 firstbyte=atoi(buffer);
1083 sms->ReplyViaSameSMSC=false; 1139 sms->ReplyViaSameSMSC=false;
1084 /* GSM 03.40 section 9.2.3.17 (TP-Reply-Path) */ 1140 /* GSM 03.40 section 9.2.3.17 (TP-Reply-Path) */
1085 if ((firstbyte & 128)==128) sms->ReplyViaSameSMSC=true; 1141 if ((firstbyte & 128)==128) sms->ReplyViaSameSMSC=true;
1086 /* TP PID */ 1142 /* TP PID */
1087 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1143 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1088 sms->ReplaceMessage = 0; 1144 sms->ReplaceMessage = 0;
1089 if (atoi(buffer) > 0x40 && atoi(buffer) < 0x48) { 1145 if (atoi(buffer) > 0x40 && atoi(buffer) < 0x48) {
1090 sms->ReplaceMessage = atoi(buffer) - 0x40; 1146 sms->ReplaceMessage = atoi(buffer) - 0x40;
1091 } 1147 }
1092 smprintf(s, "TPPID: %02x %i\n",atoi(buffer),atoi(buffer)); 1148 smprintf(s, "TPPID: %02x %i\n",atoi(buffer),atoi(buffer));
1093 /* TP DCS */ 1149 /* TP DCS */
1094 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1150 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1095 TPDCS=atoi(buffer); 1151 TPDCS=atoi(buffer);
1096 if (sms->Folder==2 || sms->Folder==4) { 1152 if (sms->Folder==2 || sms->Folder==4) {
1097 /*TP VP */ 1153 /*TP VP */
1098 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1154 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1099 } 1155 }
1100 /* SMSC number */ 1156 /* SMSC number */
1101 /* FIXME: support for all formats */ 1157 /* FIXME: support for all formats */
1102 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1158 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1103 EncodeUnicode(sms->SMSC.Number,buffer+1,strlen(buffer)-2); 1159 EncodeUnicode(sms->SMSC.Number,buffer+1,strlen(buffer)-2);
1104 /* Format of SMSC number */ 1160 /* Format of SMSC number */
1105 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1161 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1106 /* TPUDL */ 1162 /* TPUDL */
1107 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1163 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1108 TPUDL=atoi(buffer); 1164 TPUDL=atoi(buffer);
1109 current++; 1165 current++;
1110 sms->Coding = SMS_Coding_Default; 1166 sms->Coding = SMS_Coding_Default;
1111 /* GSM 03.40 section 9.2.3.10 (TP-Data-Coding-Scheme) 1167 /* GSM 03.40 section 9.2.3.10 (TP-Data-Coding-Scheme)
1112 * and GSM 03.38 section 4 1168 * and GSM 03.38 section 4
1113 */ 1169 */
1114 if ((TPDCS & 0xf4) == 0xf4) sms->Coding=SMS_Coding_8bit; 1170 if ((TPDCS & 0xf4) == 0xf4) sms->Coding=SMS_Coding_8bit;
1115 if ((TPDCS & 0x08) == 0x08) sms->Coding=SMS_Coding_Unicode; 1171 if ((TPDCS & 0x08) == 0x08) sms->Coding=SMS_Coding_Unicode;
1116 sms->Class = -1; 1172 sms->Class = -1;
1117 if ((TPDCS & 0xF3)==0xF0) sms->Class = 0; 1173 if ((TPDCS & 0xF3)==0xF0) sms->Class = 0;
1118 if ((TPDCS & 0xF3)==0xF1) sms->Class = 1; 1174 if ((TPDCS & 0xF3)==0xF1) sms->Class = 1;
1119 if ((TPDCS & 0xF3)==0xF2) sms->Class = 2; 1175 if ((TPDCS & 0xF3)==0xF2) sms->Class = 2;
1120 if ((TPDCS & 0xF3)==0xF3) sms->Class = 3; 1176 if ((TPDCS & 0xF3)==0xF3) sms->Class = 3;
1121 smprintf(s, "SMS class: %i\n",sms->Class); 1177 smprintf(s, "SMS class: %i\n",sms->Class);
1122 switch (sms->Coding) { 1178 switch (sms->Coding) {
1123 case SMS_Coding_Default: 1179 case SMS_Coding_Default:
1124 /* GSM 03.40 section 9.2.3.23 (TP-User-Data-Header-Indicator) */ 1180 /* GSM 03.40 section 9.2.3.23 (TP-User-Data-Header-Indicator) */
1125 /* If not SMS with UDH, it's coded normal */ 1181 /* If not SMS with UDH, it's coded normal */
1126 /* If UDH available, treat it as Unicode or 8 bit */ 1182 /* If UDH available, treat it as Unicode or 8 bit */
1127 if ((firstbyte & 0x40)!=0x40) { 1183 if ((firstbyte & 0x40)!=0x40) {
1128 sms->UDH.Type= UDH_NoUDH; 1184 sms->UDH.Type= UDH_NoUDH;
1129 sms->Length= TPUDL; 1185 sms->Length= TPUDL;
1130 EncodeUnicode(sms->Text,msg.Buffer+Priv->Lines.numbers[2*2],TPUDL); 1186 EncodeUnicode(sms->Text,msg.Buffer+Priv->Lines.numbers[2*2],TPUDL);
1131 break; 1187 break;
1132 } 1188 }
1133 case SMS_Coding_Unicode: 1189 case SMS_Coding_Unicode:
1134 case SMS_Coding_8bit: 1190 case SMS_Coding_8bit:
1135 DecodeHexBin(buffer+PHONE_SMSDeliver.Text, msg.Buffer+current, TPUDL*2); 1191 DecodeHexBin(buffer+PHONE_SMSDeliver.Text, msg.Buffer+current, TPUDL*2);
1136 buffer[PHONE_SMSDeliver.firstbyte] = firstbyte; 1192 buffer[PHONE_SMSDeliver.firstbyte] = firstbyte;
1137 buffer[PHONE_SMSDeliver.TPDCS] = TPDCS; 1193 buffer[PHONE_SMSDeliver.TPDCS] = TPDCS;
1138 buffer[PHONE_SMSDeliver.TPUDL] = TPUDL; 1194 buffer[PHONE_SMSDeliver.TPUDL] = TPUDL;
1139 return GSM_DecodeSMSFrameText(sms, buffer, PHONE_SMSDeliver); 1195 return GSM_DecodeSMSFrameText(sms, buffer, PHONE_SMSDeliver);
1140 } 1196 }
1141 } 1197 }
1142 return ERR_NONE; 1198 return ERR_NONE;
1143 default: 1199 default:
1144 break; 1200 break;
@@ -1451,531 +1507,544 @@ GSM_Error ATGEN_MakeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *message, unsig
1451 for(i=0;i<length;i++) req[(*current)++]=buffer[PHONE_SMSSubmit.Text+i]; 1507 for(i=0;i<length;i++) req[(*current)++]=buffer[PHONE_SMSSubmit.Text+i];
1452 EncodeHexBin(hexreq, req, *current); 1508 EncodeHexBin(hexreq, req, *current);
1453 *length2 = *current * 2; 1509 *length2 = *current * 2;
1454 *current = *current - (req[PHONE_SMSSubmit.SMSCNumber]+1); 1510 *current = *current - (req[PHONE_SMSSubmit.SMSCNumber]+1);
1455 } 1511 }
1456 break; 1512 break;
1457 case SMS_AT_TXT: 1513 case SMS_AT_TXT:
1458 if (Priv->Manufacturer == 0) { 1514 if (Priv->Manufacturer == 0) {
1459 error=ATGEN_GetManufacturer(s); 1515 error=ATGEN_GetManufacturer(s);
1460 if (error != ERR_NONE) return error; 1516 if (error != ERR_NONE) return error;
1461 } 1517 }
1462 if (Priv->Manufacturer != AT_Nokia) { 1518 if (Priv->Manufacturer != AT_Nokia) {
1463 if (message->Coding != SMS_Coding_Default) return ERR_NOTSUPPORTED; 1519 if (message->Coding != SMS_Coding_Default) return ERR_NOTSUPPORTED;
1464 } 1520 }
1465 error=PHONE_EncodeSMSFrame(s,message,req,PHONE_SMSDeliver,&i,true); 1521 error=PHONE_EncodeSMSFrame(s,message,req,PHONE_SMSDeliver,&i,true);
1466 if (error != ERR_NONE) return error; 1522 if (error != ERR_NONE) return error;
1467 CopyUnicodeString(SMSC.Number,message->SMSC.Number); 1523 CopyUnicodeString(SMSC.Number,message->SMSC.Number);
1468 SMSC.Location=1; 1524 SMSC.Location=1;
1469 error=ATGEN_SetSMSC(s,&SMSC); 1525 error=ATGEN_SetSMSC(s,&SMSC);
1470 if (error!=ERR_NONE) return error; 1526 if (error!=ERR_NONE) return error;
1471 sprintf(buffer, "AT+CSMP=%i,%i,%i,%i\r", 1527 sprintf(buffer, "AT+CSMP=%i,%i,%i,%i\r",
1472 req[PHONE_SMSDeliver.firstbyte], 1528 req[PHONE_SMSDeliver.firstbyte],
1473 req[PHONE_SMSDeliver.TPVP], 1529 req[PHONE_SMSDeliver.TPVP],
1474 req[PHONE_SMSDeliver.TPPID], 1530 req[PHONE_SMSDeliver.TPPID],
1475 req[PHONE_SMSDeliver.TPDCS]); 1531 req[PHONE_SMSDeliver.TPDCS]);
1476 error=GSM_WaitFor (s, buffer, strlen(buffer), 0x00, 4, ID_SetSMSParameters); 1532 error=GSM_WaitFor (s, buffer, strlen(buffer), 0x00, 4, ID_SetSMSParameters);
1477 if (error==ERR_NOTSUPPORTED) { 1533 if (error==ERR_NOTSUPPORTED) {
1478 /* Nokia Communicator 9000i doesn't support <vp> parameter */ 1534 /* Nokia Communicator 9000i doesn't support <vp> parameter */
1479 sprintf(buffer, "AT+CSMP=%i,,%i,%i\r", 1535 sprintf(buffer, "AT+CSMP=%i,,%i,%i\r",
1480 req[PHONE_SMSDeliver.firstbyte], 1536 req[PHONE_SMSDeliver.firstbyte],
1481 req[PHONE_SMSDeliver.TPPID], 1537 req[PHONE_SMSDeliver.TPPID],
1482 req[PHONE_SMSDeliver.TPDCS]); 1538 req[PHONE_SMSDeliver.TPDCS]);
1483 error=GSM_WaitFor (s, buffer, strlen(buffer), 0x00, 4, ID_SetSMSParameters); 1539 error=GSM_WaitFor (s, buffer, strlen(buffer), 0x00, 4, ID_SetSMSParameters);
1484 } 1540 }
1485 if (error!=ERR_NONE) return error; 1541 if (error!=ERR_NONE) return error;
1486 switch (message->Coding) { 1542 switch (message->Coding) {
1487 case SMS_Coding_Default: 1543 case SMS_Coding_Default:
1488 /* If not SMS with UDH, it's as normal text */ 1544 /* If not SMS with UDH, it's as normal text */
1489 if (message->UDH.Type==UDH_NoUDH) { 1545 if (message->UDH.Type==UDH_NoUDH) {
1490 strcpy(hexreq,DecodeUnicodeString(message->Text)); 1546 strcpy(hexreq,DecodeUnicodeString(message->Text));
1491 *length2 = UnicodeLength(message->Text); 1547 *length2 = UnicodeLength(message->Text);
1492 break; 1548 break;
1493 } 1549 }
1494 case SMS_Coding_Unicode: 1550 case SMS_Coding_Unicode:
1495 case SMS_Coding_8bit: 1551 case SMS_Coding_8bit:
1496 error=PHONE_EncodeSMSFrame(s,message,buffer,PHONE_SMSDeliver,current,true); 1552 error=PHONE_EncodeSMSFrame(s,message,buffer,PHONE_SMSDeliver,current,true);
1497 if (error != ERR_NONE) return error; 1553 if (error != ERR_NONE) return error;
1498 EncodeHexBin (hexreq, buffer+PHONE_SMSDeliver.Text, buffer[PHONE_SMSDeliver.TPUDL]); 1554 EncodeHexBin (hexreq, buffer+PHONE_SMSDeliver.Text, buffer[PHONE_SMSDeliver.TPUDL]);
1499 *length2 = buffer[PHONE_SMSDeliver.TPUDL] * 2; 1555 *length2 = buffer[PHONE_SMSDeliver.TPUDL] * 2;
1500 break; 1556 break;
1501 } 1557 }
1502 break; 1558 break;
1503 } 1559 }
1504 return ERR_NONE; 1560 return ERR_NONE;
1505} 1561}
1506 1562
1507GSM_Error ATGEN_AddSMS(GSM_StateMachine *s, GSM_SMSMessage *sms) 1563GSM_Error ATGEN_AddSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
1508{ 1564{
1509 GSM_Error error, error2; 1565 GSM_Error error, error2;
1510 int state,Replies,reply, current, current2; 1566 int state,Replies,reply, current, current2;
1511 unsigned char buffer[1000], hexreq[1000]; 1567 unsigned char buffer[1000], hexreq[1000];
1512 GSM_Phone_Data *Phone = &s->Phone.Data; 1568 GSM_Phone_Data *Phone = &s->Phone.Data;
1513 unsigned char *statetxt; 1569 unsigned char *statetxt;
1514 1570
1515 /* This phone supports only sent/unsent messages on SIM */ 1571 /* This phone supports only sent/unsent messages on SIM */
1516 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SMSONLYSENT)) { 1572 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SMSONLYSENT)) {
1517 if (sms->Folder != 2) { 1573 if (sms->Folder != 2) {
1518 smprintf(s, "This phone supports only folder = 2!\n"); 1574 smprintf(s, "This phone supports only folder = 2!\n");
1519 return ERR_NOTSUPPORTED; 1575 return ERR_NOTSUPPORTED;
1520 } 1576 }
1521 } 1577 }
1522 1578
1523 sms->PDU = SMS_Submit; 1579 sms->PDU = SMS_Submit;
1524 switch (sms->Folder) { 1580 switch (sms->Folder) {
1525 case 1: sms->PDU = SMS_Deliver; /* Inbox SIM */ 1581 case 1: sms->PDU = SMS_Deliver; /* Inbox SIM */
1526 error=ATGEN_SetSMSMemory(s, true); 1582 error=ATGEN_SetSMSMemory(s, true);
1527 break; 1583 break;
1528 case 2: error=ATGEN_SetSMSMemory(s, true);/* Outbox SIM */ 1584 case 2: error=ATGEN_SetSMSMemory(s, true);/* Outbox SIM */
1529 break; 1585 break;
1530 case 3: sms->PDU = SMS_Deliver; 1586 case 3: sms->PDU = SMS_Deliver;
1531 error=ATGEN_SetSMSMemory(s, false);/* Inbox phone */ 1587 error=ATGEN_SetSMSMemory(s, false);/* Inbox phone */
1532 break; 1588 break;
1533 case 4: error=ATGEN_SetSMSMemory(s, false);/* Outbox phone */ 1589 case 4: error=ATGEN_SetSMSMemory(s, false);/* Outbox phone */
1534 break; 1590 break;
1535 default: return ERR_NOTSUPPORTED; 1591 default: return ERR_NOTSUPPORTED;
1536 } 1592 }
1537 if (error!=ERR_NONE) return error; 1593 if (error!=ERR_NONE) return error;
1538 1594
1539 error = ATGEN_MakeSMSFrame(s, sms, hexreq, &current, &current2); 1595 error = ATGEN_MakeSMSFrame(s, sms, hexreq, &current, &current2);
1540 if (error != ERR_NONE) return error; 1596 if (error != ERR_NONE) return error;
1541 1597
1542 switch (Phone->Priv.ATGEN.SMSMode) { 1598 switch (Phone->Priv.ATGEN.SMSMode) {
1543 case SMS_AT_PDU: 1599 case SMS_AT_PDU:
1544 if (sms->PDU == SMS_Deliver) { 1600 if (sms->PDU == SMS_Deliver) {
1545 state = 0; 1601 state = 0;
1546 if (sms->State == SMS_Read || sms->State == SMS_Sent) state = 1; 1602 if (sms->State == SMS_Read || sms->State == SMS_Sent) state = 1;
1547 } else { 1603 } else {
1548 state = 2; 1604 state = 2;
1549 if (sms->State == SMS_Read || sms->State == SMS_Sent) state = 3; 1605 if (sms->State == SMS_Read || sms->State == SMS_Sent) state = 3;
1550 } 1606 }
1551 /* Siemens M20 */ 1607 /* Siemens M20 */
1552 if (IsPhoneFeatureAvailable(Phone->ModelInfo, F_M20SMS)) { 1608 if (IsPhoneFeatureAvailable(Phone->ModelInfo, F_M20SMS)) {
1553 /* No (good and 100% working) support for alphanumeric numbers */ 1609 /* No (good and 100% working) support for alphanumeric numbers */
1554 if (sms->Number[1]!='+' && (sms->Number[1]<'0' || sms->Number[1]>'9')) { 1610 if (sms->Number[1]!='+' && (sms->Number[1]<'0' || sms->Number[1]>'9')) {
1555 EncodeUnicode(sms->Number,"123",3); 1611 EncodeUnicode(sms->Number,"123",3);
1556 error = ATGEN_MakeSMSFrame(s, sms, hexreq, &current, &current2); 1612 error = ATGEN_MakeSMSFrame(s, sms, hexreq, &current, &current2);
1557 if (error != ERR_NONE) return error; 1613 if (error != ERR_NONE) return error;
1558 } 1614 }
1559 } 1615 }
1560 sprintf(buffer, "AT+CMGW=%i,%i\r",current,state); 1616 sprintf(buffer, "AT+CMGW=%i,%i\r",current,state);
1561 break; 1617 break;
1562 case SMS_AT_TXT: 1618 case SMS_AT_TXT:
1563 if (sms->PDU == SMS_Deliver) { 1619 if (sms->PDU == SMS_Deliver) {
1564 statetxt = "REC UNREAD"; 1620 statetxt = "REC UNREAD";
1565 if (sms->State == SMS_Read || sms->State == SMS_Sent) statetxt = "REC READ"; 1621 if (sms->State == SMS_Read || sms->State == SMS_Sent) statetxt = "REC READ";
1566 } else { 1622 } else {
1567 statetxt = "STO UNSENT"; 1623 statetxt = "STO UNSENT";
1568 if (sms->State == SMS_Read || sms->State == SMS_Sent) statetxt = "STO SENT"; 1624 if (sms->State == SMS_Read || sms->State == SMS_Sent) statetxt = "STO SENT";
1569 } 1625 }
1570 /* Siemens M20 */ 1626 /* Siemens M20 */
1571 if (IsPhoneFeatureAvailable(Phone->ModelInfo, F_M20SMS)) { 1627 if (IsPhoneFeatureAvailable(Phone->ModelInfo, F_M20SMS)) {
1572 /* No (good and 100% working) support for alphanumeric numbers */ 1628 /* No (good and 100% working) support for alphanumeric numbers */
1573 /* FIXME: Try to autodetect support for <stat> (statetxt) parameter although: 1629 /* FIXME: Try to autodetect support for <stat> (statetxt) parameter although:
1574 * Siemens M20 supports +CMGW <stat> specification but on my model it just 1630 * Siemens M20 supports +CMGW <stat> specification but on my model it just
1575 * reports ERROR (and <stat> is not respected). 1631 * reports ERROR (and <stat> is not respected).
1576 * Fortunately it will write "+CMGW: <index>\n" before and the message gets written 1632 * Fortunately it will write "+CMGW: <index>\n" before and the message gets written
1577 */ 1633 */
1578 if (sms->Number[1]!='+' && (sms->Number[1]<'0' || sms->Number[1]>'9')) { 1634 if (sms->Number[1]!='+' && (sms->Number[1]<'0' || sms->Number[1]>'9')) {
1579 sprintf(buffer, "AT+CMGW=\"123\",,\"%s\"\r",statetxt); 1635 sprintf(buffer, "AT+CMGW=\"123\",,\"%s\"\r",statetxt);
1580 } else { 1636 } else {
1581 sprintf(buffer, "AT+CMGW=\"%s\",,\"%s\"\r",DecodeUnicodeString(sms->Number),statetxt); 1637 sprintf(buffer, "AT+CMGW=\"%s\",,\"%s\"\r",DecodeUnicodeString(sms->Number),statetxt);
1582 } 1638 }
1583 } else { 1639 } else {
1584 sprintf(buffer, "AT+CMGW=\"%s\",,\"%s\"\r",DecodeUnicodeString(sms->Number),statetxt); 1640 sprintf(buffer, "AT+CMGW=\"%s\",,\"%s\"\r",DecodeUnicodeString(sms->Number),statetxt);
1585 } 1641 }
1586 } 1642 }
1587 1643
1588 Phone->SaveSMSMessage = sms; 1644 Phone->SaveSMSMessage = sms;
1589 1645
1590 for (reply=0;reply<s->ReplyNum;reply++) { 1646 for (reply=0;reply<s->ReplyNum;reply++) {
1591 if (reply!=0) { 1647 if (reply!=0) {
1592 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || 1648 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
1593 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { 1649 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) {
1594 smprintf(s, "[Retrying %i]\n", reply+1); 1650 smprintf(s, "[Retrying %i]\n", reply+1);
1595 } 1651 }
1596 } 1652 }
1597 s->Protocol.Data.AT.EditMode = true; 1653 s->Protocol.Data.AT.EditMode = true;
1598 Replies = s->ReplyNum; 1654 Replies = s->ReplyNum;
1599 s->ReplyNum = 1; 1655 s->ReplyNum = 1;
1600 smprintf(s,"Waiting for modem prompt\n"); 1656 smprintf(s,"Waiting for modem prompt\n");
1601 error=GSM_WaitFor (s, buffer, strlen(buffer), 0x00, 3, ID_SaveSMSMessage); 1657 error=GSM_WaitFor (s, buffer, strlen(buffer), 0x00, 3, ID_SaveSMSMessage);
1602 s->ReplyNum = Replies; 1658 s->ReplyNum = Replies;
1603 if (error == ERR_NONE) { 1659 if (error == ERR_NONE) {
1604 Phone->DispatchError = ERR_TIMEOUT; 1660 Phone->DispatchError = ERR_TIMEOUT;
1605 Phone->RequestID = ID_SaveSMSMessage; 1661 Phone->RequestID = ID_SaveSMSMessage;
1606 smprintf(s, "Saving SMS\n"); 1662 smprintf(s, "Saving SMS\n");
1607 error = s->Protocol.Functions->WriteMessage(s, hexreq, current2, 0x00); 1663 error = s->Protocol.Functions->WriteMessage(s, hexreq, current2, 0x00);
1608 if (error!=ERR_NONE) return error; 1664 if (error!=ERR_NONE) return error;
1609 my_sleep(500); 1665 my_sleep(500);
1610 /* CTRL+Z ends entering */ 1666 /* CTRL+Z ends entering */
1611 error = s->Protocol.Functions->WriteMessage(s, "\x1A", 1, 0x00); 1667 error = s->Protocol.Functions->WriteMessage(s, "\x1A", 1, 0x00);
1612 if (error!=ERR_NONE) return error; 1668 if (error!=ERR_NONE) return error;
1613 error = GSM_WaitForOnce(s, NULL, 0x00, 0x00, 4); 1669 error = GSM_WaitForOnce(s, NULL, 0x00, 0x00, 4);
1614 if (error != ERR_TIMEOUT) return error; 1670 if (error != ERR_TIMEOUT) return error;
1615 } else { 1671 } else {
1616 smprintf(s, "Escaping SMS mode\n"); 1672 smprintf(s, "Escaping SMS mode\n");
1617 error2 = s->Protocol.Functions->WriteMessage(s, "\x1B\r", 2, 0x00); 1673 error2 = s->Protocol.Functions->WriteMessage(s, "\x1B\r", 2, 0x00);
1618 if (error2 != ERR_NONE) return error2; 1674 if (error2 != ERR_NONE) return error2;
1619 return error; 1675 return error;
1620 } 1676 }
1621 } 1677 }
1622 1678
1623 return Phone->DispatchError; 1679 return Phone->DispatchError;
1624} 1680}
1625 1681
1626GSM_Error ATGEN_ReplySendSMS(GSM_Protocol_Message msg, GSM_StateMachine *s) 1682GSM_Error ATGEN_ReplySendSMS(GSM_Protocol_Message msg, GSM_StateMachine *s)
1627{ 1683{
1628 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 1684 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
1629 char *start; 1685 char *start;
1630 1686
1631 if (s->Protocol.Data.AT.EditMode) { 1687 if (s->Protocol.Data.AT.EditMode) {
1632 if (s->Phone.Data.Priv.ATGEN.ReplyState != AT_Reply_SMSEdit) { 1688 if (s->Phone.Data.Priv.ATGEN.ReplyState != AT_Reply_SMSEdit) {
1633 return ERR_UNKNOWN; 1689 return ERR_UNKNOWN;
1634 } 1690 }
1635 s->Protocol.Data.AT.EditMode = false; 1691 s->Protocol.Data.AT.EditMode = false;
1636 return ERR_NONE; 1692 return ERR_NONE;
1637 } 1693 }
1638 1694
1639 switch (Priv->ReplyState) { 1695 switch (Priv->ReplyState) {
1640 case AT_Reply_OK: 1696 case AT_Reply_OK:
1641 smprintf(s, "SMS sent OK\n"); 1697 smprintf(s, "SMS sent OK\n");
1642 if (s->User.SendSMSStatus!=NULL) { 1698 if (s->User.SendSMSStatus!=NULL) {
1643 start = strstr(msg.Buffer, "+CMGW: "); 1699 start = strstr(msg.Buffer, "+CMGS: ");
1644 if (start != NULL) { 1700 if (start != NULL) {
1645 s->User.SendSMSStatus(s->CurrentConfig->Device,0,atoi(start+7)); 1701 s->User.SendSMSStatus(s->CurrentConfig->Device,0,atoi(start+7));
1646 } else { 1702 } else {
1647 s->User.SendSMSStatus(s->CurrentConfig->Device,0,0); 1703 s->User.SendSMSStatus(s->CurrentConfig->Device,0,-1);
1648 } 1704 }
1649 } 1705 }
1650 return ERR_NONE; 1706 return ERR_NONE;
1651 case AT_Reply_CMSError: 1707 case AT_Reply_CMSError:
1652 smprintf(s, "Error %i\n",Priv->ErrorCode); 1708 smprintf(s, "Error %i\n",Priv->ErrorCode);
1653 if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s->CurrentConfig->Device,Priv->ErrorCode,0); 1709 if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s->CurrentConfig->Device,Priv->ErrorCode,-1);
1654 return ATGEN_HandleCMSError(s); 1710 return ATGEN_HandleCMSError(s);
1655 case AT_Reply_Error: 1711 case AT_Reply_Error:
1656 return ERR_UNKNOWN; 1712 return ERR_UNKNOWN;
1657 default: 1713 default:
1658 return ERR_UNKNOWNRESPONSE; 1714 return ERR_UNKNOWNRESPONSE;
1659 } 1715 }
1660} 1716}
1661 1717
1662GSM_Error ATGEN_SendSMS(GSM_StateMachine *s, GSM_SMSMessage *sms) 1718GSM_Error ATGEN_SendSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
1663{ 1719{
1664 GSM_Error error,error2; 1720 GSM_Error error,error2;
1665 int current, current2, Replies; 1721 int current, current2, Replies;
1666 unsigned char buffer[1000], hexreq[1000]; 1722 unsigned char buffer[1000], hexreq[1000];
1667 GSM_Phone_Data *Phone = &s->Phone.Data; 1723 GSM_Phone_Data *Phone = &s->Phone.Data;
1668 1724
1669 if (sms->PDU == SMS_Deliver) sms->PDU = SMS_Submit; 1725 if (sms->PDU == SMS_Deliver) sms->PDU = SMS_Submit;
1670 1726
1671 error = ATGEN_MakeSMSFrame(s, sms, hexreq, &current, &current2); 1727 error = ATGEN_MakeSMSFrame(s, sms, hexreq, &current, &current2);
1672 if (error != ERR_NONE) return error; 1728 if (error != ERR_NONE) return error;
1673 1729
1674 switch (Phone->Priv.ATGEN.SMSMode) { 1730 switch (Phone->Priv.ATGEN.SMSMode) {
1675 case SMS_AT_PDU: 1731 case SMS_AT_PDU:
1676 sprintf(buffer, "AT+CMGS=%i\r",current); 1732 sprintf(buffer, "AT+CMGS=%i\r",current);
1677 break; 1733 break;
1678 case SMS_AT_TXT: 1734 case SMS_AT_TXT:
1679 sprintf(buffer, "AT+CMGS=\"%s\"\r",DecodeUnicodeString(sms->Number)); 1735 sprintf(buffer, "AT+CMGS=\"%s\"\r",DecodeUnicodeString(sms->Number));
1680 } 1736 }
1681 1737
1682 s->Protocol.Data.AT.EditMode = true; 1738 s->Protocol.Data.AT.EditMode = true;
1683 Replies = s->ReplyNum; 1739 Replies = s->ReplyNum;
1684 s->ReplyNum = 1; 1740 s->ReplyNum = 1;
1685 smprintf(s,"Waiting for modem prompt\n"); 1741 smprintf(s,"Waiting for modem prompt\n");
1686 error=GSM_WaitFor (s, buffer, strlen(buffer), 0x00, 3, ID_IncomingFrame); 1742 error=GSM_WaitFor (s, buffer, strlen(buffer), 0x00, 3, ID_IncomingFrame);
1687 s->ReplyNum = Replies; 1743 s->ReplyNum = Replies;
1688 if (error == ERR_NONE) { 1744 if (error == ERR_NONE) {
1689 smprintf(s, "Sending SMS\n"); 1745 smprintf(s, "Sending SMS\n");
1690 error = s->Protocol.Functions->WriteMessage(s, hexreq, current2, 0x00); 1746 error = s->Protocol.Functions->WriteMessage(s, hexreq, current2, 0x00);
1691 if (error!=ERR_NONE) return error; 1747 if (error!=ERR_NONE) return error;
1692 my_sleep(500); 1748 my_sleep(500);
1693 /* CTRL+Z ends entering */ 1749 /* CTRL+Z ends entering */
1694 error=s->Protocol.Functions->WriteMessage(s, "\x1A", 1, 0x00); 1750 error=s->Protocol.Functions->WriteMessage(s, "\x1A", 1, 0x00);
1695 my_sleep(100); 1751 my_sleep(100);
1696 return error; 1752 return error;
1697 } else { 1753 } else {
1698 smprintf(s, "Escaping SMS mode\n"); 1754 smprintf(s, "Escaping SMS mode\n");
1699 error2=s->Protocol.Functions->WriteMessage(s, "\x1B\r", 2, 0x00); 1755 error2=s->Protocol.Functions->WriteMessage(s, "\x1B\r", 2, 0x00);
1700 if (error2 != ERR_NONE) return error2; 1756 if (error2 != ERR_NONE) return error2;
1701 } 1757 }
1702 return error; 1758 return error;
1703} 1759}
1704 1760
1705GSM_Error ATGEN_SendSavedSMS(GSM_StateMachine *s, int Folder, int Location) 1761GSM_Error ATGEN_SendSavedSMS(GSM_StateMachine *s, int Folder, int Location)
1706{ 1762{
1707 GSM_Error error; 1763 GSM_Error error;
1708 int location; 1764 int location;
1709 unsigned charsmsfolder; 1765 unsigned charsmsfolder;
1710 unsigned charreq[100]; 1766 unsigned charreq[100];
1711 GSM_MultiSMSMessagemsms; 1767 GSM_MultiSMSMessagemsms;
1712 1768
1713 msms.Number = 0; 1769 msms.Number = 0;
1714 msms.SMS[0].Folder = Folder; 1770 msms.SMS[0].Folder = Folder;
1715 msms.SMS[0].Location = Location; 1771 msms.SMS[0].Location = Location;
1716 1772
1717 /* By reading SMS we check if it is really inbox/outbox */ 1773 /* By reading SMS we check if it is really inbox/outbox */
1718 error = ATGEN_GetSMS(s, &msms); 1774 error = ATGEN_GetSMS(s, &msms);
1719 if (error != ERR_NONE) return error; 1775 if (error != ERR_NONE) return error;
1720 1776
1721 /* Can not send from other folder that outbox */ 1777 /* Can not send from other folder that outbox */
1722 if (msms.SMS[0].Folder != 2 && msms.SMS[0].Folder != 4) return ERR_NOTSUPPORTED; 1778 if (msms.SMS[0].Folder != 2 && msms.SMS[0].Folder != 4) return ERR_NOTSUPPORTED;
1723 1779
1724 error=ATGEN_GetSMSLocation(s, &msms.SMS[0], &smsfolder, &location); 1780 error=ATGEN_GetSMSLocation(s, &msms.SMS[0], &smsfolder, &location);
1725 if (error != ERR_NONE) return error; 1781 if (error != ERR_NONE) return error;
1726 1782
1727 sprintf(req, "AT+CMSS=%i\r",location); 1783 sprintf(req, "AT+CMSS=%i\r",location);
1728 return s->Protocol.Functions->WriteMessage(s, req, strlen(req), 0x00); 1784 return s->Protocol.Functions->WriteMessage(s, req, strlen(req), 0x00);
1729} 1785}
1730 1786
1731GSM_Error ATGEN_ReplyGetDateTime_Alarm(GSM_Protocol_Message msg, GSM_StateMachine *s) 1787GSM_Error ATGEN_ReplyGetDateTime_Alarm(GSM_Protocol_Message msg, GSM_StateMachine *s)
1732{ 1788{
1733 int current= 19; 1789 int current= 19;
1734 GSM_Phone_Data *Data = &s->Phone.Data; 1790 GSM_Phone_Data *Data = &s->Phone.Data;
1735 1791
1736 switch (s->Phone.Data.Priv.ATGEN.ReplyState) { 1792 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
1737 case AT_Reply_OK: 1793 case AT_Reply_OK:
1738 if (msg.Buffer[current]==0x0d || msg.Buffer[current-1]==0x0d) { 1794 if (msg.Buffer[current]==0x0d || msg.Buffer[current-1]==0x0d) {
1739 smprintf(s, "Not set in phone\n"); 1795 smprintf(s, "Not set in phone\n");
1740 return ERR_EMPTY; 1796 return ERR_EMPTY;
1741 } else { 1797 } else {
1742 if (Data->RequestID == ID_GetDateTime) { 1798 if (Data->RequestID == ID_GetDateTime) {
1743 ATGEN_DecodeDateTime(Data->DateTime, msg.Buffer+current); 1799 ATGEN_DecodeDateTime(Data->DateTime, msg.Buffer+current);
1744 } else { 1800 } else {
1745 ATGEN_DecodeDateTime(&(Data->Alarm->DateTime), msg.Buffer+current); 1801 ATGEN_DecodeDateTime(&(Data->Alarm->DateTime), msg.Buffer+current);
1746 } 1802 }
1747 return ERR_NONE; 1803 return ERR_NONE;
1748 } 1804 }
1749 case AT_Reply_Error: 1805 case AT_Reply_Error:
1750 return ERR_NOTSUPPORTED; 1806 return ERR_NOTSUPPORTED;
1751 case AT_Reply_CMSError: 1807 case AT_Reply_CMSError:
1752 return ATGEN_HandleCMSError(s); 1808 return ATGEN_HandleCMSError(s);
1753 default: 1809 default:
1754 break; 1810 break;
1755 } 1811 }
1756 return ERR_UNKNOWNRESPONSE; 1812 return ERR_UNKNOWNRESPONSE;
1757} 1813}
1758 1814
1759GSM_Error ATGEN_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time) 1815GSM_Error ATGEN_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
1760{ 1816{
1761 s->Phone.Data.DateTime=date_time; 1817 s->Phone.Data.DateTime=date_time;
1762 smprintf(s, "Getting date & time\n"); 1818 smprintf(s, "Getting date & time\n");
1763 return GSM_WaitFor (s, "AT+CCLK?\r", 9, 0x00, 4, ID_GetDateTime); 1819 return GSM_WaitFor (s, "AT+CCLK?\r", 9, 0x00, 4, ID_GetDateTime);
1764} 1820}
1765 1821
1766GSM_Error ATGEN_SetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time) 1822GSM_Error ATGEN_SetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
1767{ 1823{
1768 char req[128]; 1824 char req[128];
1769 1825
1770 sprintf(req, "AT+CCLK=\"%02i/%02i/%02i,%02i:%02i:%02i+00\"\r", 1826 sprintf(req, "AT+CCLK=\"%02i/%02i/%02i,%02i:%02i:%02i+00\"\r",
1771 date_time->Year-2000,date_time->Month,date_time->Day, 1827 date_time->Year-2000,date_time->Month,date_time->Day,
1772 date_time->Hour,date_time->Minute,date_time->Second); 1828 date_time->Hour,date_time->Minute,date_time->Second);
1773 1829
1774 smprintf(s, "Setting date & time\n"); 1830 smprintf(s, "Setting date & time\n");
1775 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_SetDateTime); 1831 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_SetDateTime);
1776} 1832}
1777 1833
1778GSM_Error ATGEN_GetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm) 1834GSM_Error ATGEN_GetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm)
1779{ 1835{
1780 if (alarm->Location != 1) return ERR_NOTSUPPORTED; 1836 if (alarm->Location != 1) return ERR_NOTSUPPORTED;
1781 1837
1782 alarm->Repeating = true; 1838 alarm->Repeating = true;
1783 alarm->Text[0] = 0; alarm->Text[1] = 0; 1839 alarm->Text[0] = 0; alarm->Text[1] = 0;
1784 1840
1785 s->Phone.Data.Alarm = alarm; 1841 s->Phone.Data.Alarm = alarm;
1786 smprintf(s, "Getting alarm\n"); 1842 smprintf(s, "Getting alarm\n");
1787 return GSM_WaitFor (s, "AT+CALA?\r", 9, 0x00, 4, ID_GetAlarm); 1843 return GSM_WaitFor (s, "AT+CALA?\r", 9, 0x00, 4, ID_GetAlarm);
1788} 1844}
1789 1845
1846/* R320 only takes HH:MM. Do other phones understand full date? */
1847GSM_Error ATGEN_SetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm)
1848{
1849 char req[20];
1850
1851 if (alarm->Location != 1) return ERR_INVALIDLOCATION;
1852
1853 sprintf(req, "AT+CALA=\"%02i:%02i\"\r",alarm->DateTime.Hour,alarm->DateTime.Minute);
1854
1855 smprintf(s, "Setting Alarm\n");
1856 return GSM_WaitFor (s, req, strlen(req), 0x00, 3, ID_SetAlarm);
1857}
1858
1790GSM_Error ATGEN_ReplyGetSMSC(GSM_Protocol_Message msg, GSM_StateMachine *s) 1859GSM_Error ATGEN_ReplyGetSMSC(GSM_Protocol_Message msg, GSM_StateMachine *s)
1791{ 1860{
1792 GSM_SMSC *SMSC = s->Phone.Data.SMSC; 1861 GSM_SMSC *SMSC = s->Phone.Data.SMSC;
1793 int current; 1862 int current;
1794 int len; 1863 int len;
1795 unsigned char buffer[100]; 1864 unsigned char buffer[100];
1796 1865
1797 switch (s->Phone.Data.Priv.ATGEN.ReplyState) { 1866 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
1798 case AT_Reply_OK: 1867 case AT_Reply_OK:
1799 smprintf(s, "SMSC info received\n"); 1868 smprintf(s, "SMSC info received\n");
1800 1869
1801 current = 0; 1870 current = 0;
1802 while (msg.Buffer[current]!='"') current++; 1871 while (msg.Buffer[current]!='"') current++;
1803 1872
1804 /* SMSC number */ 1873 /* SMSC number */
1805 /* FIXME: support for all formats */ 1874 /* FIXME: support for all formats */
1806 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1875 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1807 /* 1876 /*
1808 * Some phones return this as unicode encoded when they are 1877 * Some phones return this as unicode encoded when they are
1809 * switched to UCS2 mode, so we try to solve this correctly. 1878 * switched to UCS2 mode, so we try to solve this correctly.
1810 */ 1879 */
1811 len = strlen(buffer + 1) - 1; 1880 len = strlen(buffer + 1) - 1;
1812 buffer[len + 1] = 0; 1881 buffer[len + 1] = 0;
1813 if ((len > 20) && (len % 4 == 0) && (strchr(buffer + 1, '+') == NULL)) { 1882 if ((len > 20) && (len % 4 == 0) && (strchr(buffer + 1, '+') == NULL)) {
1814 /* This is probably unicode encoded number */ 1883 /* This is probably unicode encoded number */
1815 DecodeHexUnicode(SMSC->Number,buffer + 1,len); 1884 DecodeHexUnicode(SMSC->Number,buffer + 1,len);
1816 } else { 1885 } else {
1817 EncodeUnicode(SMSC->Number,buffer + 1,len); 1886 EncodeUnicode(SMSC->Number,buffer + 1,len);
1818 } 1887 }
1819 smprintf(s, "Number: \"%s\"\n",DecodeUnicodeString(SMSC->Number)); 1888 smprintf(s, "Number: \"%s\"\n",DecodeUnicodeString(SMSC->Number));
1820 1889
1821 /* Format of SMSC number */ 1890 /* Format of SMSC number */
1822 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer); 1891 current+=ATGEN_ExtractOneParameter(msg.Buffer+current, buffer);
1823 smprintf(s, "Format %s\n",buffer); 1892 smprintf(s, "Format %s\n",buffer);
1824 /* International number */ 1893 /* International number */
1825 if (!strcmp(buffer,"145")) { 1894 if (!strcmp(buffer,"145")) {
1826 sprintf(buffer+1,"%s",DecodeUnicodeString(SMSC->Number)); 1895 sprintf(buffer+1,"%s",DecodeUnicodeString(SMSC->Number));
1827 if (strlen(buffer+1)!=0 && buffer[1] != '+') { 1896 if (strlen(buffer+1)!=0 && buffer[1] != '+') {
1828 /* Sony Ericsson issue */ 1897 /* Sony Ericsson issue */
1829 /* International number is without + */ 1898 /* International number is without + */
1830 buffer[0] = '+'; 1899 buffer[0] = '+';
1831 EncodeUnicode(SMSC->Number,buffer,strlen(buffer)); 1900 EncodeUnicode(SMSC->Number,buffer,strlen(buffer));
1832 } 1901 }
1833 } 1902 }
1834 1903
1835 SMSC->Format = SMS_FORMAT_Text; 1904 SMSC->Format = SMS_FORMAT_Text;
1836 SMSC->Validity.Format = SMS_Validity_RelativeFormat; 1905 SMSC->Validity.Format = SMS_Validity_RelativeFormat;
1837 SMSC->Validity.Relative= SMS_VALID_Max_Time; 1906 SMSC->Validity.Relative= SMS_VALID_Max_Time;
1838 SMSC->Name[0] = 0; 1907 SMSC->Name[0] = 0;
1839 SMSC->Name[1] = 0; 1908 SMSC->Name[1] = 0;
1840 SMSC->DefaultNumber[0]= 0; 1909 SMSC->DefaultNumber[0]= 0;
1841 SMSC->DefaultNumber[1]= 0; 1910 SMSC->DefaultNumber[1]= 0;
1842 return ERR_NONE; 1911 return ERR_NONE;
1843 case AT_Reply_CMSError: 1912 case AT_Reply_CMSError:
1844 return ATGEN_HandleCMSError(s); 1913 return ATGEN_HandleCMSError(s);
1845 default: 1914 default:
1846 break; 1915 break;
1847 } 1916 }
1848 return ERR_UNKNOWNRESPONSE; 1917 return ERR_UNKNOWNRESPONSE;
1849} 1918}
1850 1919
1851GSM_Error ATGEN_GetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc) 1920GSM_Error ATGEN_GetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc)
1852{ 1921{
1853 if (smsc->Location==0x00 || smsc->Location!=0x01) return ERR_INVALIDLOCATION; 1922 if (smsc->Location==0x00 || smsc->Location!=0x01) return ERR_INVALIDLOCATION;
1854 1923
1855 s->Phone.Data.SMSC=smsc; 1924 s->Phone.Data.SMSC=smsc;
1856 smprintf(s, "Getting SMSC\n"); 1925 smprintf(s, "Getting SMSC\n");
1857 return GSM_WaitFor (s, "AT+CSCA?\r", 9, 0x00, 4, ID_GetSMSC); 1926 return GSM_WaitFor (s, "AT+CSCA?\r", 9, 0x00, 4, ID_GetSMSC);
1858} 1927}
1859 1928
1860GSM_Error ATGEN_ReplyGetNetworkLAC_CID(GSM_Protocol_Message msg, GSM_StateMachine *s) 1929GSM_Error ATGEN_ReplyGetNetworkLAC_CID(GSM_Protocol_Message msg, GSM_StateMachine *s)
1861{ 1930{
1862 GSM_NetworkInfo *NetworkInfo = s->Phone.Data.NetworkInfo; 1931 GSM_NetworkInfo *NetworkInfo = s->Phone.Data.NetworkInfo;
1863 GSM_Lines Lines; 1932 GSM_Lines Lines;
1864 int i=0; 1933 int i=0;
1865 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 1934 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
1866 char *answer; 1935 char *answer;
1867 1936
1868 if (s->Phone.Data.RequestID == ID_IncomingFrame) { 1937 if (s->Phone.Data.RequestID == ID_IncomingFrame) {
1869 smprintf(s, "Incoming LAC & CID info\n"); 1938 smprintf(s, "Incoming LAC & CID info\n");
1870 return ERR_NONE; 1939 return ERR_NONE;
1871 } 1940 }
1872 1941
1873 switch (s->Phone.Data.Priv.ATGEN.ReplyState) { 1942 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
1874 case AT_Reply_OK: 1943 case AT_Reply_OK:
1875 break; 1944 break;
1876 case AT_Reply_CMSError: 1945 case AT_Reply_CMSError:
1877 return ATGEN_HandleCMSError(s); 1946 return ATGEN_HandleCMSError(s);
1878 default: 1947 default:
1879 return ERR_UNKNOWNRESPONSE; 1948 return ERR_UNKNOWNRESPONSE;
1880 } 1949 }
1881 1950
1882 SplitLines(GetLineString(msg.Buffer,Priv->Lines,2), 1951 SplitLines(GetLineString(msg.Buffer,Priv->Lines,2),
1883 strlen(GetLineString(msg.Buffer,Priv->Lines,2)), 1952 strlen(GetLineString(msg.Buffer,Priv->Lines,2)),
1884 &Lines, ",", 1, true); 1953 &Lines, ",", 1, true);
1885 1954
1886 /* Find number of lines */ 1955 /* Find number of lines */
1887 while (Lines.numbers[i*2+1] != 0) { 1956 while (Lines.numbers[i*2+1] != 0) {
1888 /* FIXME: handle special chars correctly */ 1957 /* FIXME: handle special chars correctly */
1889 smprintf(s, "%i \"%s\"\n",i+1,GetLineString(GetLineString(msg.Buffer,Priv->Lines,2),Lines,i+1)); 1958 smprintf(s, "%i \"%s\"\n",i+1,GetLineString(GetLineString(msg.Buffer,Priv->Lines,2),Lines,i+1));
1890 i++; 1959 i++;
1891 } 1960 }
1892 1961
1893 smprintf(s, "Network LAC & CID & state received\n"); 1962 smprintf(s, "Network LAC & CID & state received\n");
1894 answer = GetLineString(GetLineString(msg.Buffer,Priv->Lines,2),Lines,2); 1963 answer = GetLineString(GetLineString(msg.Buffer,Priv->Lines,2),Lines,2);
1895 while (*answer == 0x20) answer++; 1964 while (*answer == 0x20) answer++;
1896#ifdef DEBUG 1965#ifdef DEBUG
1897 switch (answer[0]) { 1966 switch (answer[0]) {
1898 case '0': smprintf(s, "Not registered into any network. Not searching for network\n"); break; 1967 case '0': smprintf(s, "Not registered into any network. Not searching for network\n"); break;
1899 case '1': smprintf(s, "Home network\n"); break; 1968 case '1': smprintf(s, "Home network\n"); break;
1900 case '2': smprintf(s, "Not registered into any network. Searching for network\n"); break; 1969 case '2': smprintf(s, "Not registered into any network. Searching for network\n"); break;
1901 case '3': smprintf(s, "Registration denied\n"); break; 1970 case '3': smprintf(s, "Registration denied\n"); break;
1902 case '4': smprintf(s, "Unknown\n"); break; 1971 case '4': smprintf(s, "Unknown\n"); break;
1903 case '5': smprintf(s, "Registered in roaming network\n"); break; 1972 case '5': smprintf(s, "Registered in roaming network\n"); break;
1904 default : smprintf(s, "Unknown\n"); 1973 default : smprintf(s, "Unknown\n");
1905 } 1974 }
1906#endif 1975#endif
1907 switch (answer[0]) { 1976 switch (answer[0]) {
1908 case '0': NetworkInfo->State = GSM_NoNetwork; break; 1977 case '0': NetworkInfo->State = GSM_NoNetwork; break;
1909 case '1': NetworkInfo->State = GSM_HomeNetwork; break; 1978 case '1': NetworkInfo->State = GSM_HomeNetwork; break;
1910 case '2': NetworkInfo->State = GSM_RequestingNetwork; break; 1979 case '2': NetworkInfo->State = GSM_RequestingNetwork; break;
1911 case '3': NetworkInfo->State = GSM_RegistrationDenied;break; 1980 case '3': NetworkInfo->State = GSM_RegistrationDenied;break;
1912 case '4': NetworkInfo->State = GSM_NetworkStatusUnknown;break; 1981 case '4': NetworkInfo->State = GSM_NetworkStatusUnknown;break;
1913 case '5': NetworkInfo->State = GSM_RoamingNetwork; break; 1982 case '5': NetworkInfo->State = GSM_RoamingNetwork; break;
1914 default : NetworkInfo->State = GSM_NetworkStatusUnknown;break; 1983 default : NetworkInfo->State = GSM_NetworkStatusUnknown;break;
1915 } 1984 }
1916 if (NetworkInfo->State == GSM_HomeNetwork || 1985 if (NetworkInfo->State == GSM_HomeNetwork ||
1917 NetworkInfo->State == GSM_RoamingNetwork) { 1986 NetworkInfo->State == GSM_RoamingNetwork) {
1918 memset(NetworkInfo->CID,0,4); 1987 memset(NetworkInfo->CID,0,4);
1919 memset(NetworkInfo->LAC,0,4); 1988 memset(NetworkInfo->LAC,0,4);
1920 1989
1921 if (Lines.numbers[3*2+1]==0) return ERR_NONE; 1990 if (Lines.numbers[3*2+1]==0) return ERR_NONE;
1922 1991
1923 answer = GetLineString(GetLineString(msg.Buffer,Priv->Lines,2),Lines,3); 1992 answer = GetLineString(GetLineString(msg.Buffer,Priv->Lines,2),Lines,3);
1924 while (*answer == 0x20) answer++; 1993 while (*answer == 0x20) answer++;
1925 sprintf(NetworkInfo->CID,"%c%c%c%c", answer[1], answer[2], answer[3], answer[4]); 1994 sprintf(NetworkInfo->CID,"%c%c%c%c", answer[1], answer[2], answer[3], answer[4]);
1926 1995
1927 answer = GetLineString(GetLineString(msg.Buffer,Priv->Lines,2),Lines,4); 1996 answer = GetLineString(GetLineString(msg.Buffer,Priv->Lines,2),Lines,4);
1928 while (*answer == 0x20) answer++; 1997 while (*answer == 0x20) answer++;
1929 sprintf(NetworkInfo->LAC,"%c%c%c%c", answer[1], answer[2], answer[3], answer[4]); 1998 sprintf(NetworkInfo->LAC,"%c%c%c%c", answer[1], answer[2], answer[3], answer[4]);
1930 1999
1931 smprintf(s, "CID : %s\n",NetworkInfo->CID); 2000 smprintf(s, "CID : %s\n",NetworkInfo->CID);
1932 smprintf(s, "LAC : %s\n",NetworkInfo->LAC); 2001 smprintf(s, "LAC : %s\n",NetworkInfo->LAC);
1933 } 2002 }
1934 return ERR_NONE; 2003 return ERR_NONE;
1935} 2004}
1936 2005
1937GSM_Error ATGEN_ReplyGetNetworkCode(GSM_Protocol_Message msg, GSM_StateMachine *s) 2006GSM_Error ATGEN_ReplyGetNetworkCode(GSM_Protocol_Message msg, GSM_StateMachine *s)
1938{ 2007{
1939 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 2008 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
1940 GSM_NetworkInfo *NetworkInfo = s->Phone.Data.NetworkInfo; 2009 GSM_NetworkInfo *NetworkInfo = s->Phone.Data.NetworkInfo;
1941 2010
1942 switch (Priv->ReplyState) { 2011 switch (Priv->ReplyState) {
1943 case AT_Reply_OK: 2012 case AT_Reply_OK:
1944 smprintf(s, "Network code received\n"); 2013 smprintf(s, "Network code received\n");
1945 if (Priv->Manufacturer == AT_Falcom) { 2014 if (Priv->Manufacturer == AT_Falcom) {
1946 NetworkInfo->NetworkCode[0] = msg.Buffer[22]; 2015 NetworkInfo->NetworkCode[0] = msg.Buffer[22];
1947 NetworkInfo->NetworkCode[1] = msg.Buffer[23]; 2016 NetworkInfo->NetworkCode[1] = msg.Buffer[23];
1948 NetworkInfo->NetworkCode[2] = msg.Buffer[24]; 2017 NetworkInfo->NetworkCode[2] = msg.Buffer[24];
1949 NetworkInfo->NetworkCode[3] = ' '; 2018 NetworkInfo->NetworkCode[3] = ' ';
1950 NetworkInfo->NetworkCode[4] = msg.Buffer[25]; 2019 NetworkInfo->NetworkCode[4] = msg.Buffer[25];
1951 NetworkInfo->NetworkCode[5] = msg.Buffer[26]; 2020 NetworkInfo->NetworkCode[5] = msg.Buffer[26];
1952 } else { 2021 } else {
1953 NetworkInfo->NetworkCode[0] = msg.Buffer[23]; 2022 NetworkInfo->NetworkCode[0] = msg.Buffer[23];
1954 NetworkInfo->NetworkCode[1] = msg.Buffer[24]; 2023 NetworkInfo->NetworkCode[1] = msg.Buffer[24];
1955 NetworkInfo->NetworkCode[2] = msg.Buffer[25]; 2024 NetworkInfo->NetworkCode[2] = msg.Buffer[25];
1956 NetworkInfo->NetworkCode[3] = ' '; 2025 NetworkInfo->NetworkCode[3] = ' ';
1957 NetworkInfo->NetworkCode[4] = msg.Buffer[26]; 2026 NetworkInfo->NetworkCode[4] = msg.Buffer[26];
1958 NetworkInfo->NetworkCode[5] = msg.Buffer[27]; 2027 NetworkInfo->NetworkCode[5] = msg.Buffer[27];
1959 } 2028 }
1960 NetworkInfo->NetworkCode[6] = 0; 2029 NetworkInfo->NetworkCode[6] = 0;
1961 smprintf(s, " Network code : %s\n", NetworkInfo->NetworkCode); 2030 smprintf(s, " Network code : %s\n", NetworkInfo->NetworkCode);
1962 smprintf(s, " Network name for Gammu : %s ", 2031 smprintf(s, " Network name for Gammu : %s ",
1963 DecodeUnicodeString(GSM_GetNetworkName(NetworkInfo->NetworkCode))); 2032 DecodeUnicodeString(GSM_GetNetworkName(NetworkInfo->NetworkCode)));
1964 smprintf(s, "(%s)\n",DecodeUnicodeString(GSM_GetCountryName(NetworkInfo->NetworkCode))); 2033 smprintf(s, "(%s)\n",DecodeUnicodeString(GSM_GetCountryName(NetworkInfo->NetworkCode)));
1965 return ERR_NONE; 2034 return ERR_NONE;
1966 case AT_Reply_CMSError: 2035 case AT_Reply_CMSError:
1967 return ATGEN_HandleCMSError(s); 2036 return ATGEN_HandleCMSError(s);
1968 default: 2037 default:
1969 break; 2038 break;
1970 } 2039 }
1971 return ERR_UNKNOWNRESPONSE; 2040 return ERR_UNKNOWNRESPONSE;
1972} 2041}
1973 2042
1974GSM_Error ATGEN_GetNetworkInfo(GSM_StateMachine *s, GSM_NetworkInfo *netinfo) 2043GSM_Error ATGEN_GetNetworkInfo(GSM_StateMachine *s, GSM_NetworkInfo *netinfo)
1975{ 2044{
1976 GSM_Error error; 2045 GSM_Error error;
1977 2046
1978 s->Phone.Data.NetworkInfo=netinfo; 2047 s->Phone.Data.NetworkInfo=netinfo;
1979 2048
1980 netinfo->NetworkName[0] = 0; 2049 netinfo->NetworkName[0] = 0;
1981 netinfo->NetworkName[1] = 0; 2050 netinfo->NetworkName[1] = 0;
@@ -2013,1657 +2082,1781 @@ GSM_Error ATGEN_ReplyGetPBKMemories(GSM_Protocol_Message msg, GSM_StateMachine *
2013 } 2082 }
2014 memcpy(s->Phone.Data.Priv.ATGEN.PBKMemories,msg.Buffer,strlen(msg.Buffer)); 2083 memcpy(s->Phone.Data.Priv.ATGEN.PBKMemories,msg.Buffer,strlen(msg.Buffer));
2015 return ERR_NONE; 2084 return ERR_NONE;
2016} 2085}
2017 2086
2018GSM_Error ATGEN_SetPBKMemory(GSM_StateMachine *s, GSM_MemoryType MemType) 2087GSM_Error ATGEN_SetPBKMemory(GSM_StateMachine *s, GSM_MemoryType MemType)
2019{ 2088{
2020 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 2089 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
2021 char req[] = "AT+CPBS=\"XX\"\r"; 2090 char req[] = "AT+CPBS=\"XX\"\r";
2022 GSM_Error error; 2091 GSM_Error error;
2023 2092
2024 if (Priv->PBKMemory == MemType) return ERR_NONE; 2093 if (Priv->PBKMemory == MemType) return ERR_NONE;
2025 2094
2026 /* Zero values that are for actual memory */ 2095 /* Zero values that are for actual memory */
2027 Priv->MemorySize = 0; 2096 Priv->MemorySize = 0;
2028 Priv->FirstMemoryEntry = 0; 2097 Priv->FirstMemoryEntry = 0;
2029 Priv->NextMemoryEntry = 0; 2098 Priv->NextMemoryEntry = 0;
2030 Priv->TextLength = 0; 2099 Priv->TextLength = 0;
2031 Priv->NumberLength = 0; 2100 Priv->NumberLength = 0;
2032 2101
2033 if (Priv->PBKMemories[0] == 0) { 2102 if (Priv->PBKMemories[0] == 0) {
2034 error=GSM_WaitFor (s, "AT+CPBS=?\r", 10, 0x00, 3, ID_SetMemoryType); 2103 error=GSM_WaitFor (s, "AT+CPBS=?\r", 10, 0x00, 3, ID_SetMemoryType);
2035 if (error != ERR_NONE) return error; 2104 if (error != ERR_NONE) return error;
2036 } 2105 }
2037 2106
2038 switch (MemType) { 2107 switch (MemType) {
2039 case MEM_SM: 2108 case MEM_SM:
2040 req[9] = 'S'; req[10] = 'M'; 2109 req[9] = 'S'; req[10] = 'M';
2041 break; 2110 break;
2042 case MEM_ME: 2111 case MEM_ME:
2043 if (strstr(Priv->PBKMemories,"ME")==NULL) return ERR_NOTSUPPORTED; 2112 if (strstr(Priv->PBKMemories,"ME")==NULL) return ERR_NOTSUPPORTED;
2044 req[9] = 'M'; req[10] = 'E'; 2113 req[9] = 'M'; req[10] = 'E';
2045 break; 2114 break;
2046 case MEM_RC: 2115 case MEM_RC:
2047 if (strstr(Priv->PBKMemories,"RC")==NULL) return ERR_NOTSUPPORTED; 2116 if (strstr(Priv->PBKMemories,"RC")==NULL) return ERR_NOTSUPPORTED;
2048 req[9] = 'R'; req[10] = 'C'; 2117 req[9] = 'R'; req[10] = 'C';
2049 break; 2118 break;
2050 case MEM_MC: 2119 case MEM_MC:
2051 if (strstr(Priv->PBKMemories,"MC")==NULL) return ERR_NOTSUPPORTED; 2120 if (strstr(Priv->PBKMemories,"MC")==NULL) return ERR_NOTSUPPORTED;
2052 req[9] = 'M'; req[10] = 'C'; 2121 req[9] = 'M'; req[10] = 'C';
2053 break; 2122 break;
2054 case MEM_ON: 2123 case MEM_ON:
2055 if (strstr(Priv->PBKMemories,"ON")==NULL) return ERR_NOTSUPPORTED; 2124 if (strstr(Priv->PBKMemories,"ON")==NULL) return ERR_NOTSUPPORTED;
2056 req[9] = 'O'; req[10] = 'N'; 2125 req[9] = 'O'; req[10] = 'N';
2057 break; 2126 break;
2058 case MEM_FD: 2127 case MEM_FD:
2059 if (strstr(Priv->PBKMemories,"FD")==NULL) return ERR_NOTSUPPORTED; 2128 if (strstr(Priv->PBKMemories,"FD")==NULL) return ERR_NOTSUPPORTED;
2060 req[9] = 'F'; req[10] = 'D'; 2129 req[9] = 'F'; req[10] = 'D';
2061 break; 2130 break;
2062 case MEM_DC: 2131 case MEM_DC:
2063 if (strstr(Priv->PBKMemories,"DC")!=NULL) { 2132 if (strstr(Priv->PBKMemories,"DC")!=NULL) {
2064 req[9] = 'D'; req[10] = 'C'; 2133 req[9] = 'D'; req[10] = 'C';
2065 break; 2134 break;
2066 } 2135 }
2067 if (strstr(Priv->PBKMemories,"LD")!=NULL) { 2136 if (strstr(Priv->PBKMemories,"LD")!=NULL) {
2068 req[9] = 'L'; req[10] = 'D'; 2137 req[9] = 'L'; req[10] = 'D';
2069 break; 2138 break;
2070 } 2139 }
2071 return ERR_NOTSUPPORTED; 2140 return ERR_NOTSUPPORTED;
2072 break; 2141 break;
2073 default: 2142 default:
2074 return ERR_NOTSUPPORTED; 2143 return ERR_NOTSUPPORTED;
2075 } 2144 }
2076 2145
2077 smprintf(s, "Setting memory type\n"); 2146 smprintf(s, "Setting memory type\n");
2078 error=GSM_WaitFor (s, req, 13, 0x00, 3, ID_SetMemoryType); 2147 error=GSM_WaitFor (s, req, 13, 0x00, 3, ID_SetMemoryType);
2079 if (error == ERR_NONE) Priv->PBKMemory = MemType; 2148 if (error == ERR_NONE) Priv->PBKMemory = MemType;
2080 return error; 2149 return error;
2081} 2150}
2082 2151
2083GSM_Error ATGEN_ReplyGetCPBSMemoryStatus(GSM_Protocol_Message msg, GSM_StateMachine *s) 2152GSM_Error ATGEN_ReplyGetCPBSMemoryStatus(GSM_Protocol_Message msg, GSM_StateMachine *s)
2084{ 2153{
2085 GSM_MemoryStatus*MemoryStatus = s->Phone.Data.MemoryStatus; 2154 GSM_MemoryStatus*MemoryStatus = s->Phone.Data.MemoryStatus;
2086 char *start; 2155 char *start;
2087 2156
2088 switch (s->Phone.Data.Priv.ATGEN.ReplyState) { 2157 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
2089 case AT_Reply_OK: 2158 case AT_Reply_OK:
2090 smprintf(s, "Memory status received\n"); 2159 smprintf(s, "Memory status received\n");
2091 MemoryStatus->MemoryUsed = 0; 2160 MemoryStatus->MemoryUsed = 0;
2092 MemoryStatus->MemoryFree = 0; 2161 MemoryStatus->MemoryFree = 0;
2093 start = strchr(msg.Buffer, ','); 2162 start = strchr(msg.Buffer, ',');
2094 if (start) { 2163 if (start) {
2095 start++; 2164 start++;
2096 MemoryStatus->MemoryUsed = atoi(start); 2165 MemoryStatus->MemoryUsed = atoi(start);
2097 start = strchr(start, ','); 2166 start = strchr(start, ',');
2098 if (start) { 2167 if (start) {
2099 start++; 2168 start++;
2100 MemoryStatus->MemoryFree = atoi(start) - MemoryStatus->MemoryUsed; 2169 MemoryStatus->MemoryFree = atoi(start) - MemoryStatus->MemoryUsed;
2101 return ERR_NONE; 2170 return ERR_NONE;
2102 } else return ERR_UNKNOWN; 2171 } else return ERR_UNKNOWN;
2103 } else return ERR_UNKNOWN; 2172 } else return ERR_UNKNOWN;
2104 case AT_Reply_CMSError: 2173 case AT_Reply_CMSError:
2105 return ATGEN_HandleCMSError(s); 2174 return ATGEN_HandleCMSError(s);
2106 default: 2175 default:
2107 break; 2176 break;
2108 } 2177 }
2109 return ERR_UNKNOWNRESPONSE; 2178 return ERR_UNKNOWNRESPONSE;
2110} 2179}
2111 2180
2112GSM_Error ATGEN_ReplyGetCPBRMemoryInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 2181GSM_Error ATGEN_ReplyGetCPBRMemoryInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
2113{ 2182{
2114 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 2183 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
2115 char *pos; 2184 char *pos;
2116 2185
2117 switch (Priv->ReplyState) { 2186 switch (Priv->ReplyState) {
2118 case AT_Reply_OK: 2187 case AT_Reply_OK:
2119 smprintf(s, "Memory info received\n"); 2188 smprintf(s, "Memory info received\n");
2120 /* Parse +CPBR: (first-last),max_number_len,max_name_len */ 2189 /* Parse +CPBR: (first-last),max_number_len,max_name_len */
2121 2190
2122 /* Parse first location */ 2191 /* Parse first location */
2123 pos = strchr(msg.Buffer, '('); 2192 pos = strchr(msg.Buffer, '(');
2124 if (!pos) return ERR_UNKNOWN; 2193 if (!pos) return ERR_UNKNOWN;
2125 pos++; 2194 pos++;
2126 Priv->FirstMemoryEntry = atoi(pos); 2195 Priv->FirstMemoryEntry = atoi(pos);
2127 2196
2128 /* Parse last location*/ 2197 /* Parse last location*/
2129 pos = strchr(pos, '-'); 2198 pos = strchr(pos, '-');
2130 if (!pos) return ERR_UNKNOWN; 2199 if (!pos) return ERR_UNKNOWN;
2131 pos++; 2200 pos++;
2132 Priv->MemorySize = atoi(pos) + 1 - Priv->FirstMemoryEntry; 2201 Priv->MemorySize = atoi(pos) + 1 - Priv->FirstMemoryEntry;
2133 2202
2134 /* Parse number length*/ 2203 /* Parse number length*/
2135 pos = strchr(pos, ','); 2204 pos = strchr(pos, ',');
2136 if (!pos) return ERR_UNKNOWN; 2205 if (!pos) return ERR_UNKNOWN;
2137 pos++; 2206 pos++;
2138 Priv->NumberLength = atoi(pos); 2207 Priv->NumberLength = atoi(pos);
2139 2208
2140 /* Parse text length*/ 2209 /* Parse text length*/
2141 pos = strchr(pos, ','); 2210 pos = strchr(pos, ',');
2142 if (!pos) return ERR_UNKNOWN; 2211 if (!pos) return ERR_UNKNOWN;
2143 pos++; 2212 pos++;
2144 Priv->TextLength = atoi(pos); 2213 Priv->TextLength = atoi(pos);
2145 2214
2146 return ERR_NONE; 2215 return ERR_NONE;
2147 case AT_Reply_Error: 2216 case AT_Reply_Error:
2148 return ERR_UNKNOWN; 2217 return ERR_UNKNOWN;
2149 case AT_Reply_CMSError: 2218 case AT_Reply_CMSError:
2150 return ATGEN_HandleCMSError(s); 2219 return ATGEN_HandleCMSError(s);
2151 default: 2220 default:
2152 return ERR_UNKNOWNRESPONSE; 2221 return ERR_UNKNOWNRESPONSE;
2153 } 2222 }
2154} 2223}
2155 2224
2156GSM_Error ATGEN_ReplyGetCPBRMemoryStatus(GSM_Protocol_Message msg, GSM_StateMachine *s) 2225GSM_Error ATGEN_ReplyGetCPBRMemoryStatus(GSM_Protocol_Message msg, GSM_StateMachine *s)
2157{ 2226{
2158 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 2227 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
2159 GSM_MemoryStatus*MemoryStatus = s->Phone.Data.MemoryStatus; 2228 GSM_MemoryStatus*MemoryStatus = s->Phone.Data.MemoryStatus;
2160 int line=0; 2229 int line=0;
2161 char *str; 2230 char *str;
2162 int cur; 2231 int cur;
2163 2232
2164 switch (Priv->ReplyState) { 2233 switch (Priv->ReplyState) {
2165 case AT_Reply_OK: 2234 case AT_Reply_OK:
2166 smprintf(s, "Memory entries received\n"); 2235 smprintf(s, "Memory entries received\n");
2167 /* Walk through lines with +CPBR: */ 2236 /* Walk through lines with +CPBR: */
2168 while (Priv->Lines.numbers[line*2+1]!=0) { 2237 while (Priv->Lines.numbers[line*2+1]!=0) {
2169 str = GetLineString(msg.Buffer,Priv->Lines,line+1); 2238 str = GetLineString(msg.Buffer,Priv->Lines,line+1);
2170 if (strncmp(str, "+CPBR: ", 7) == 0) { 2239 if (strncmp(str, "+CPBR: ", 7) == 0) {
2171 MemoryStatus->MemoryUsed++; 2240 MemoryStatus->MemoryUsed++;
2172 if (sscanf(str, "+CPBR: %d,", &cur) == 1) { 2241 if (sscanf(str, "+CPBR: %d,", &cur) == 1) {
2173 cur -= Priv->FirstMemoryEntry - 1; 2242 cur -= Priv->FirstMemoryEntry - 1;
2174 if (cur == Priv->NextMemoryEntry || Priv->NextMemoryEntry == 0) 2243 if (cur == Priv->NextMemoryEntry || Priv->NextMemoryEntry == 0)
2175 Priv->NextMemoryEntry = cur + 1; 2244 Priv->NextMemoryEntry = cur + 1;
2176 } 2245 }
2177 } 2246 }
2178 line++; 2247 line++;
2179 } 2248 }
2180 return ERR_NONE; 2249 return ERR_NONE;
2181 case AT_Reply_Error: 2250 case AT_Reply_Error:
2182 return ERR_UNKNOWN; 2251 return ERR_UNKNOWN;
2183 case AT_Reply_CMSError: 2252 case AT_Reply_CMSError:
2184 return ATGEN_HandleCMSError(s); 2253 return ATGEN_HandleCMSError(s);
2185 default: 2254 default:
2186 return ERR_UNKNOWNRESPONSE; 2255 return ERR_UNKNOWNRESPONSE;
2187 } 2256 }
2188} 2257}
2189 2258
2190GSM_Error ATGEN_GetMemoryInfo(GSM_StateMachine *s, GSM_MemoryStatus *Status, GSM_AT_NeededMemoryInfo NeededInfo) 2259GSM_Error ATGEN_GetMemoryInfo(GSM_StateMachine *s, GSM_MemoryStatus *Status, GSM_AT_NeededMemoryInfo NeededInfo)
2191{ 2260{
2192 GSM_Error error; 2261 GSM_Error error;
2193 char req[20]; 2262 char req[20];
2194 int start; 2263 int start;
2195 int end; 2264 int end;
2196 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 2265 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
2197 2266
2198 smprintf(s, "Getting memory information\n"); 2267 smprintf(s, "Getting memory information\n");
2199 2268
2200 Priv->MemorySize = 0; 2269 Priv->MemorySize = 0;
2201 Priv->TextLength = 0; 2270 Priv->TextLength = 0;
2202 Priv->NumberLength = 0; 2271 Priv->NumberLength = 0;
2203 2272
2204 error = GSM_WaitFor (s, "AT+CPBR=?\r", 10, 0x00, 4, ID_GetMemoryStatus); 2273 error = GSM_WaitFor (s, "AT+CPBR=?\r", 10, 0x00, 4, ID_GetMemoryStatus);
2274 if (Priv->Manufacturer == AT_Samsung)
2275 error = GSM_WaitFor (s, "", 0, 0x00, 4, ID_GetMemoryStatus);
2205 if (error != ERR_NONE) return error; 2276 if (error != ERR_NONE) return error;
2206 if (NeededInfo == AT_Total || NeededInfo == AT_Sizes || NeededInfo == AT_First) return ERR_NONE; 2277 if (NeededInfo == AT_Total || NeededInfo == AT_Sizes || NeededInfo == AT_First) return ERR_NONE;
2207 2278
2208 smprintf(s, "Getting memory status by reading values\n"); 2279 smprintf(s, "Getting memory status by reading values\n");
2209 2280
2210 s->Phone.Data.MemoryStatus= Status; 2281 s->Phone.Data.MemoryStatus= Status;
2211 Status->MemoryUsed = 0; 2282 Status->MemoryUsed = 0;
2212 Status->MemoryFree = 0; 2283 Status->MemoryFree = 0;
2213 start = Priv->FirstMemoryEntry; 2284 start = Priv->FirstMemoryEntry;
2214 Priv->NextMemoryEntry = 0; 2285 Priv->NextMemoryEntry = 0;
2215 while (1) { 2286 while (1) {
2216 end= start + 20; 2287 end= start + 20;
2217 if (end > Priv->MemorySize) end = Priv->MemorySize; 2288 if (end > Priv->MemorySize) end = Priv->MemorySize;
2218 sprintf(req, "AT+CPBR=%i,%i\r", start, end); 2289 sprintf(req, "AT+CPBR=%i,%i\r", start, end);
2219 error= GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetMemoryStatus); 2290 error= GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetMemoryStatus);
2220 if (error != ERR_NONE) return error; 2291 if (error != ERR_NONE) return error;
2221 if (NeededInfo == AT_NextEmpty && Priv->NextMemoryEntry != 0 && Priv->NextMemoryEntry != end + 1) return ERR_NONE; 2292 if (NeededInfo == AT_NextEmpty && Priv->NextMemoryEntry != 0 && Priv->NextMemoryEntry != end + 1) return ERR_NONE;
2222 if (end == Priv->MemorySize) { 2293 if (end == Priv->MemorySize) {
2223 Status->MemoryFree = Priv->MemorySize - Status->MemoryUsed; 2294 Status->MemoryFree = Priv->MemorySize - Status->MemoryUsed;
2224 return ERR_NONE; 2295 return ERR_NONE;
2225 } 2296 }
2226 start = end + 1; 2297 start = end + 1;
2227 } 2298 }
2228} 2299}
2229 2300
2230GSM_Error ATGEN_GetMemoryStatus(GSM_StateMachine *s, GSM_MemoryStatus *Status) 2301GSM_Error ATGEN_GetMemoryStatus(GSM_StateMachine *s, GSM_MemoryStatus *Status)
2231{ 2302{
2232 GSM_Error error; 2303 GSM_Error error;
2233 2304
2234 error = ATGEN_SetPBKMemory(s, Status->MemoryType); 2305 error = ATGEN_SetPBKMemory(s, Status->MemoryType);
2235 if (error != ERR_NONE) return error; 2306 if (error != ERR_NONE) return error;
2236 2307
2237 s->Phone.Data.MemoryStatus=Status; 2308 s->Phone.Data.MemoryStatus=Status;
2238 2309
2239 /* in some phones doesn't work or doesn't return memory status inside */ 2310 /* in some phones doesn't work or doesn't return memory status inside */
2240 /* Some workaround for buggy mobile, that hangs after "AT+CPBS?" for other 2311 /* Some workaround for buggy mobile, that hangs after "AT+CPBS?" for other
2241 * memory than SM. 2312 * memory than SM.
2242 */ 2313 */
2243 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_BROKENCPBS) || (Status->MemoryType == MEM_SM)) { 2314 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_BROKENCPBS) || (Status->MemoryType == MEM_SM)) {
2244 smprintf(s, "Getting memory status\n"); 2315 smprintf(s, "Getting memory status\n");
2245 error=GSM_WaitFor (s, "AT+CPBS?\r", 9, 0x00, 4, ID_GetMemoryStatus); 2316 error=GSM_WaitFor (s, "AT+CPBS?\r", 9, 0x00, 4, ID_GetMemoryStatus);
2246 if (error == ERR_NONE) return ERR_NONE; 2317 if (error == ERR_NONE) return ERR_NONE;
2247 } 2318 }
2248 2319
2249 return ATGEN_GetMemoryInfo(s, Status, AT_Status); 2320 return ATGEN_GetMemoryInfo(s, Status, AT_Status);
2250} 2321}
2251 2322
2252GSM_Error ATGEN_SetPBKCharset(GSM_StateMachine *s, bool PreferUnicode) 2323GSM_Error ATGEN_SetPBKCharset(GSM_StateMachine *s, bool PreferUnicode)
2253{ 2324{
2254 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 2325 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
2255 GSM_Error error; 2326 GSM_Error error;
2256 2327
2257 /* Have we already selected something? */ 2328 /* Have we already selected something? */
2258 if (Priv->PBKCharset!=0) { 2329 if (Priv->PBKCharset!=0) {
2259 /* If we want unicode charset and we have it already or setting of it 2330 /* If we want unicode charset and we have it already or setting of it
2260 * failed, we have nothing to do. */ 2331 * failed, we have nothing to do. */
2261 if (PreferUnicode && (Priv->PBKCharset==AT_PBK_UCS2 || Priv->UCS2CharsetFailed)) return ERR_NONE; 2332 if (PreferUnicode && (Priv->PBKCharset==AT_PBK_UCS2 || Priv->UCS2CharsetFailed)) return ERR_NONE;
2262 2333
2263 /* If we don't need unicode charset and we have some (or have unicode 2334 /* If we don't need unicode charset and we have some (or have unicode
2264 * charset when other failed), we have nothing to do. */ 2335 * charset when other failed), we have nothing to do. */
2265 if (!PreferUnicode && (Priv->PBKCharset!=AT_PBK_UCS2 || Priv->NonUCS2CharsetFailed)) return ERR_NONE; 2336 if (!PreferUnicode && (Priv->PBKCharset!=AT_PBK_UCS2 || Priv->NonUCS2CharsetFailed)) return ERR_NONE;
2266 } 2337 }
2267 2338
2268 error=ATGEN_GetManufacturer(s); 2339 error=ATGEN_GetManufacturer(s);
2269 if (error != ERR_NONE) return error; 2340 if (error != ERR_NONE) return error;
2270 2341
2342 /* Samsung (and Sagem?) phones use only PCCP437? */
2343 if (Priv->Manufacturer == AT_Samsung) {
2344 Priv->PBKCharset = AT_PBK_PCCP437;
2345 return ERR_NONE;
2346 }
2347
2271 if (PreferUnicode && !Priv->UCS2CharsetFailed) { 2348 if (PreferUnicode && !Priv->UCS2CharsetFailed) {
2272 smprintf(s, "Setting charset to UCS2\n"); 2349 smprintf(s, "Setting charset to UCS2\n");
2273 error=GSM_WaitFor (s, "AT+CSCS=\"UCS2\"\r", 15, 0x00, 3, ID_SetMemoryCharset); 2350 error=GSM_WaitFor (s, "AT+CSCS=\"UCS2\"\r", 15, 0x00, 3, ID_SetMemoryCharset);
2274 if (error == ERR_NONE) { 2351 if (error == ERR_NONE) {
2275 Priv->PBKCharset = AT_PBK_UCS2; 2352 Priv->PBKCharset = AT_PBK_UCS2;
2276 return ERR_NONE; 2353 return ERR_NONE;
2277 } else { 2354 } else {
2278 Priv->UCS2CharsetFailed = true; 2355 Priv->UCS2CharsetFailed = true;
2279 } 2356 }
2280 } 2357 }
2281 2358
2282 smprintf(s, "Setting charset to HEX\n"); 2359 smprintf(s, "Setting charset to HEX\n");
2283 error=GSM_WaitFor (s, "AT+CSCS=\"HEX\"\r", 14, 0x00, 3, ID_SetMemoryCharset); 2360 error=GSM_WaitFor (s, "AT+CSCS=\"HEX\"\r", 14, 0x00, 3, ID_SetMemoryCharset);
2284 /* Falcom replies OK for HEX mode and send everything 2361 /* Falcom replies OK for HEX mode and send everything
2285 * in normal format */ 2362 * in normal format */
2286 if (error == ERR_NONE && Priv->Manufacturer != AT_Falcom) { 2363 if (error == ERR_NONE && Priv->Manufacturer != AT_Falcom) {
2287 Priv->PBKCharset = AT_PBK_HEX; 2364 Priv->PBKCharset = AT_PBK_HEX;
2288 return ERR_NONE; 2365 return ERR_NONE;
2289 } 2366 }
2290 2367
2291 smprintf(s, "Setting charset to GSM\n"); 2368 smprintf(s, "Setting charset to GSM\n");
2292 error=GSM_WaitFor (s, "AT+CSCS=\"GSM\"\r", 14, 0x00, 3, ID_SetMemoryCharset); 2369 error=GSM_WaitFor (s, "AT+CSCS=\"GSM\"\r", 14, 0x00, 3, ID_SetMemoryCharset);
2293 if (error == ERR_NONE) { 2370 if (error == ERR_NONE) {
2294 Priv->PBKCharset = AT_PBK_GSM; 2371 Priv->PBKCharset = AT_PBK_GSM;
2295 return ERR_NONE; 2372 return ERR_NONE;
2296 } 2373 }
2297 2374
2298 if (!Priv->UCS2CharsetFailed) { 2375 if (!Priv->UCS2CharsetFailed) {
2299 Priv->NonUCS2CharsetFailed = true; 2376 Priv->NonUCS2CharsetFailed = true;
2300 smprintf(s, "Setting charset to UCS2\n"); 2377 smprintf(s, "Setting charset to UCS2\n");
2301 error=GSM_WaitFor (s, "AT+CSCS=\"UCS2\"\r", 15, 0x00, 3, ID_SetMemoryCharset); 2378 error=GSM_WaitFor (s, "AT+CSCS=\"UCS2\"\r", 15, 0x00, 3, ID_SetMemoryCharset);
2302 if (error == ERR_NONE) { 2379 if (error == ERR_NONE) {
2303 Priv->PBKCharset = AT_PBK_UCS2; 2380 Priv->PBKCharset = AT_PBK_UCS2;
2304 return ERR_NONE; 2381 return ERR_NONE;
2305 } else { 2382 } else {
2306 Priv->UCS2CharsetFailed = true; 2383 Priv->UCS2CharsetFailed = true;
2307 } 2384 }
2308 } 2385 }
2309 2386
2310 return error; 2387 return error;
2311} 2388}
2312 2389
2313GSM_Error ATGEN_ReplyGetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s) 2390GSM_Error ATGEN_ReplyGetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s)
2314{ 2391{
2315 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 2392 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
2316 GSM_MemoryEntry *Memory = s->Phone.Data.Memory; 2393 GSM_MemoryEntry *Memory = s->Phone.Data.Memory;
2317 char *pos; 2394 char *pos;
2318 unsigned char buffer[500],buffer2[500]; 2395 unsigned char buffer[500],buffer2[500];
2319 int len; 2396 int len;
2320 2397
2321 switch (Priv->ReplyState) { 2398 switch (Priv->ReplyState) {
2322 case AT_Reply_OK: 2399 case AT_Reply_OK:
2323 smprintf(s, "Phonebook entry received\n"); 2400 smprintf(s, "Phonebook entry received\n");
2324 Memory->EntriesNum = 0; 2401 Memory->EntriesNum = 0;
2325 if (Priv->Lines.numbers[4]==0) return ERR_EMPTY; 2402 if (Priv->Lines.numbers[4]==0) return ERR_EMPTY;
2326 pos = strstr(msg.Buffer, "+CPBR:"); 2403 pos = strstr(msg.Buffer, "+CPBR:");
2327 if (pos == NULL) return ERR_UNKNOWN; 2404 if (pos == NULL) return ERR_UNKNOWN;
2328 /* Go after +CPBR: */ 2405 /* Go after +CPBR: */
2329 pos += 6; 2406 pos += 6;
2330 2407
2331 /* Location */ 2408 /* Location */
2332 while (*pos && !isdigit(*pos)) pos++; 2409 while (*pos && !isdigit(*pos)) pos++;
2333 Memory->Location = atoi(pos) + 1 - Priv->FirstMemoryEntry; 2410 Memory->Location = atoi(pos) + 1 - Priv->FirstMemoryEntry;
2334 smprintf(s, "Location: %d\n", Memory->Location); 2411 smprintf(s, "Location: %d\n", Memory->Location);
2335 2412
2336 /* Number */ 2413 /* Number */
2337 while (*pos != '"') pos++; 2414 while (*pos != '"') pos++;
2338 pos += ATGEN_ExtractOneParameter(pos, buffer); 2415 pos += ATGEN_ExtractOneParameter(pos, buffer);
2339 smprintf(s, "Number: %s\n",buffer); 2416 smprintf(s, "Number: %s\n",buffer);
2340 Memory->EntriesNum++; 2417 Memory->EntriesNum++;
2341 Memory->Entries[0].EntryType = PBK_Number_General; 2418 Memory->Entries[0].EntryType = PBK_Number_General;
2342 Memory->Entries[0].VoiceTag = 0; 2419 Memory->Entries[0].VoiceTag = 0;
2343 Memory->Entries[0].SMSList[0] = 0; 2420 Memory->Entries[0].SMSList[0] = 0;
2344 2421
2345 len = strlen(buffer + 1) - 1; 2422 len = strlen(buffer + 1) - 1;
2346 if (Priv->PBKCharset == AT_PBK_HEX && (len > 10) && (len % 2 == 0) && (strchr(buffer + 1, '+') == NULL)) { 2423 if (Priv->PBKCharset == AT_PBK_HEX && (len > 10) && (len % 2 == 0) && (strchr(buffer + 1, '+') == NULL)) {
2347 /* This is probably hex encoded number */ 2424 /* This is probably hex encoded number */
2348 DecodeHexBin(buffer2, buffer+1, len); 2425 DecodeHexBin(buffer2, buffer+1, len);
2349 DecodeDefault(Memory->Entries[0].Text ,buffer2, strlen(buffer2), false, NULL); 2426 DecodeDefault(Memory->Entries[0].Text ,buffer2, strlen(buffer2), false, NULL);
2350 } else if (Priv->PBKCharset == AT_PBK_UCS2 && (len > 20) && (len % 4 == 0) && (strchr(buffer + 1, '+') == NULL)) { 2427 } else if (Priv->PBKCharset == AT_PBK_UCS2 && (len > 20) && (len % 4 == 0) && (strchr(buffer + 1, '+') == NULL)) {
2351 /* This is probably unicode encoded number */ 2428 /* This is probably unicode encoded number */
2352 DecodeHexUnicode(Memory->Entries[0].Text, buffer + 1,len); 2429 DecodeHexUnicode(Memory->Entries[0].Text, buffer + 1,len);
2353 } else { 2430 } else {
2354 EncodeUnicode(Memory->Entries[0].Text, buffer + 1, len); 2431 EncodeUnicode(Memory->Entries[0].Text, buffer + 1, len);
2355 } 2432 }
2356 2433
2357 /* Number format */ 2434 /* Number format */
2358 pos += ATGEN_ExtractOneParameter(pos, buffer); 2435 pos += ATGEN_ExtractOneParameter(pos, buffer);
2359 smprintf(s, "Number format: %s\n",buffer); 2436 smprintf(s, "Number format: %s\n",buffer);
2360 2437
2361 /* International number */ 2438 /* International number */
2362 if (!strcmp(buffer,"145")) { 2439 if (!strcmp(buffer,"145")) {
2363 sprintf(buffer+1,"%s",DecodeUnicodeString(Memory->Entries[0].Text)); 2440 sprintf(buffer+1,"%s",DecodeUnicodeString(Memory->Entries[0].Text));
2364 if (strlen(buffer+1)!=0 && buffer[1] != '+') { 2441 if (strlen(buffer+1)!=0 && buffer[1] != '+') {
2365 /* Sony Ericsson issue */ 2442 /* Sony Ericsson issue */
2366 /* International number is without + */ 2443 /* International number is without + */
2367 buffer[0] = '+'; 2444 buffer[0] = '+';
2368 EncodeUnicode(Memory->Entries[0].Text,buffer,strlen(buffer)); 2445 EncodeUnicode(Memory->Entries[0].Text,buffer,strlen(buffer));
2369 } 2446 }
2370 } 2447 }
2371 2448
2372 /* Name */ 2449 /* Name */
2373 pos += ATGEN_ExtractOneParameter(pos, buffer); 2450 pos += ATGEN_ExtractOneParameter(pos, buffer);
2374 smprintf(s, "Name text: %s\n",buffer); 2451 smprintf(s, "Name text: %s\n",buffer);
2375 Memory->EntriesNum++; 2452 Memory->EntriesNum++;
2376 Memory->Entries[1].EntryType=PBK_Text_Name; 2453 Memory->Entries[1].EntryType=PBK_Text_Name;
2377 switch (Priv->PBKCharset) { 2454 switch (Priv->PBKCharset) {
2378 case AT_PBK_HEX: 2455 case AT_PBK_HEX:
2379 DecodeHexBin(buffer2,buffer+1,strlen(buffer)-2); 2456 DecodeHexBin(buffer2,buffer+1,strlen(buffer)-2);
2380 DecodeDefault(Memory->Entries[1].Text,buffer2,strlen(buffer2),false,NULL); 2457 DecodeDefault(Memory->Entries[1].Text,buffer2,strlen(buffer2),false,NULL);
2381 break; 2458 break;
2382 case AT_PBK_GSM: 2459 case AT_PBK_GSM:
2383 DecodeDefault(Memory->Entries[1].Text,buffer+1,strlen(buffer)-2,false,NULL); 2460 DecodeDefault(Memory->Entries[1].Text,buffer+1,strlen(buffer)-2,false,NULL);
2384 break; 2461 break;
2385 case AT_PBK_UCS2: 2462 case AT_PBK_UCS2:
2386 DecodeHexUnicode(Memory->Entries[1].Text,buffer+1,strlen(buffer+1) - 1); 2463 DecodeHexUnicode(Memory->Entries[1].Text,buffer+1,strlen(buffer+1) - 1);
2387 break; 2464 break;
2465 case AT_PBK_PCCP437:
2466 /* FIXME: correctly decode PCCP437 */
2467 DecodeDefault(Memory->Entries[1].Text,buffer+1,strlen(buffer)-2,false,NULL);
2468 break;
2469 }
2470
2471 /* Samsung number type */
2472 if (Priv->Manufacturer == AT_Samsung) {
2473 int type;
2474
2475 pos += ATGEN_ExtractOneParameter(pos, buffer);
2476 smprintf(s, "Number type: %s\n",buffer);
2477 type = strtoul(buffer, NULL, 0);
2478 switch (type) {
2479 case 0:
2480 Memory->Entries[0].EntryType = PBK_Number_Mobile;
2481 break;
2482 case 1:
2483 Memory->Entries[0].EntryType = PBK_Number_Work;
2484 break;
2485 case 2:
2486 Memory->Entries[0].EntryType = PBK_Number_Home;
2487 break;
2488 case 3:
2489 Memory->Entries[0].EntryType = PBK_Text_Email;
2490 break;
2491 default:
2492 Memory->Entries[0].EntryType = PBK_Number_General;
2493 }
2388 } 2494 }
2495
2389 return ERR_NONE; 2496 return ERR_NONE;
2390 case AT_Reply_CMEError: 2497 case AT_Reply_CMEError:
2391 return ATGEN_HandleCMEError(s); 2498 return ATGEN_HandleCMEError(s);
2392 case AT_Reply_Error: 2499 case AT_Reply_Error:
2393 smprintf(s, "Error - too high location ?\n"); 2500 smprintf(s, "Error - too high location ?\n");
2394 return ERR_INVALIDLOCATION; 2501 return ERR_INVALIDLOCATION;
2395 case AT_Reply_CMSError: 2502 case AT_Reply_CMSError:
2396 return ATGEN_HandleCMSError(s); 2503 return ATGEN_HandleCMSError(s);
2397 default: 2504 default:
2398 break; 2505 break;
2399 } 2506 }
2400 return ERR_UNKNOWNRESPONSE; 2507 return ERR_UNKNOWNRESPONSE;
2401} 2508}
2402 2509
2403GSM_Error ATGEN_PrivGetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry, int endlocation) 2510GSM_Error ATGEN_PrivGetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry, int endlocation)
2404{ 2511{
2405 GSM_Error error; 2512 GSM_Error error;
2406 unsigned char req[20]; 2513 unsigned char req[20];
2407 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 2514 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
2408 2515
2409 if (entry->Location==0x00) return ERR_INVALIDLOCATION; 2516 if (entry->Location==0x00) return ERR_INVALIDLOCATION;
2410 2517
2411 if (entry->MemoryType == MEM_ME) { 2518 if (entry->MemoryType == MEM_ME) {
2412 if (Priv->PBKSBNR == 0) { 2519 if (Priv->PBKSBNR == 0) {
2413 sprintf(req, "AT^SBNR=?\r"); 2520 sprintf(req, "AT^SBNR=?\r");
2414 smprintf(s, "Checking availablity of SBNR\n"); 2521 smprintf(s, "Checking availablity of SBNR\n");
2415 error=GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetMemory); 2522 error=GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetMemory);
2416 switch (error) { 2523 switch (error) {
2417 case ERR_NONE: 2524 case ERR_NONE:
2418 Priv->PBKSBNR = AT_SBNR_AVAILABLE; 2525 Priv->PBKSBNR = AT_SBNR_AVAILABLE;
2419 break; 2526 break;
2420 case ERR_UNKNOWN: 2527 case ERR_UNKNOWN:
2421 case ERR_NOTSUPPORTED: 2528 case ERR_NOTSUPPORTED:
2422 Priv->PBKSBNR = AT_SBNR_NOTAVAILABLE; 2529 Priv->PBKSBNR = AT_SBNR_NOTAVAILABLE;
2423 break; 2530 break;
2424 default: 2531 default:
2425 return error; 2532 return error;
2426 } 2533 }
2427 } 2534 }
2428 if (Priv->PBKSBNR == AT_SBNR_AVAILABLE) { 2535 if (Priv->PBKSBNR == AT_SBNR_AVAILABLE) {
2429 sprintf(req, "AT^SBNR=vcf,%i\r",entry->Location-1); 2536 sprintf(req, "AT^SBNR=vcf,%i\r",entry->Location-1);
2430 s->Phone.Data.Memory=entry; 2537 s->Phone.Data.Memory=entry;
2431 smprintf(s, "Getting phonebook entry\n"); 2538 smprintf(s, "Getting phonebook entry\n");
2432 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetMemory); 2539 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetMemory);
2433 } 2540 }
2434 } 2541 }
2435 2542
2436 error=ATGEN_GetManufacturer(s); 2543 error=ATGEN_GetManufacturer(s);
2437 if (error != ERR_NONE) return error; 2544 if (error != ERR_NONE) return error;
2438 2545
2439 error=ATGEN_SetPBKMemory(s, entry->MemoryType); 2546 error=ATGEN_SetPBKMemory(s, entry->MemoryType);
2440 if (error != ERR_NONE) return error; 2547 if (error != ERR_NONE) return error;
2441 2548
2442 if (Priv->FirstMemoryEntry == 0) { 2549 if (Priv->FirstMemoryEntry == 0) {
2443 error = ATGEN_GetMemoryInfo(s, NULL, AT_First); 2550 error = ATGEN_GetMemoryInfo(s, NULL, AT_First);
2444 if (error != ERR_NONE) return error; 2551 if (error != ERR_NONE) return error;
2445 } 2552 }
2446 2553
2447 2554
2448 error=ATGEN_SetPBKCharset(s, true); /* For reading we prefer unicode */ 2555 error=ATGEN_SetPBKCharset(s, true); /* For reading we prefer unicode */
2449 if (error != ERR_NONE) return error; 2556 if (error != ERR_NONE) return error;
2450 2557
2451 if (endlocation == 0) { 2558 if (endlocation == 0) {
2452 sprintf(req, "AT+CPBR=%i\r", entry->Location + Priv->FirstMemoryEntry - 1); 2559 sprintf(req, "AT+CPBR=%i\r", entry->Location + Priv->FirstMemoryEntry - 1);
2453 } else { 2560 } else {
2454 sprintf(req, "AT+CPBR=%i,%i\r", entry->Location + Priv->FirstMemoryEntry - 1, endlocation + Priv->FirstMemoryEntry - 1); 2561 sprintf(req, "AT+CPBR=%i,%i\r", entry->Location + Priv->FirstMemoryEntry - 1, endlocation + Priv->FirstMemoryEntry - 1);
2455 } 2562 }
2456 2563
2457 s->Phone.Data.Memory=entry; 2564 s->Phone.Data.Memory=entry;
2458 smprintf(s, "Getting phonebook entry\n"); 2565 smprintf(s, "Getting phonebook entry\n");
2459 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetMemory); 2566 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetMemory);
2460} 2567}
2461 2568
2462GSM_Error ATGEN_GetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry) 2569GSM_Error ATGEN_GetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry)
2463{ 2570{
2464 return ATGEN_PrivGetMemory(s, entry, 0); 2571 return ATGEN_PrivGetMemory(s, entry, 0);
2465} 2572}
2466 2573
2467GSM_Error ATGEN_GetNextMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry, bool start) 2574GSM_Error ATGEN_GetNextMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry, bool start)
2468{ 2575{
2469 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 2576 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
2470 GSM_Error error; 2577 GSM_Error error;
2471 int step = 0; 2578 int step = 0;
2472 2579
2473 if (Priv->MemorySize == 0) { 2580 if (Priv->MemorySize == 0) {
2474 error = ATGEN_GetMemoryInfo(s, NULL, AT_Total); 2581 error = ATGEN_GetMemoryInfo(s, NULL, AT_Total);
2475 if (error != ERR_NONE) return error; 2582 if (error != ERR_NONE) return error;
2476 } 2583 }
2477 2584
2478 if (start) { 2585 if (start) {
2479 entry->Location = 1; 2586 entry->Location = 1;
2480 } else { 2587 } else {
2481 entry->Location++; 2588 entry->Location++;
2482 } 2589 }
2483 while ((error = ATGEN_PrivGetMemory(s, entry, step == 0 ? 0 : MIN(Priv->MemorySize, entry->Location + step))) == ERR_EMPTY) { 2590 while ((error = ATGEN_PrivGetMemory(s, entry, step == 0 ? 0 : MIN(Priv->MemorySize, entry->Location + step))) == ERR_EMPTY) {
2484 entry->Location += step + 1; 2591 entry->Location += step + 1;
2485 if (entry->Location > Priv->MemorySize) break; 2592 if (entry->Location > Priv->MemorySize) break;
2486 /* SNBR works only for one location */ 2593 /* SNBR works only for one location */
2487 if (entry->MemoryType != MEM_ME || Priv->PBKSBNR != AT_SBNR_AVAILABLE) step = MIN(step + 2, 20); 2594 if (entry->MemoryType != MEM_ME || Priv->PBKSBNR != AT_SBNR_AVAILABLE) step = MIN(step + 2, 20);
2488 } 2595 }
2489 if (error == ERR_INVALIDLOCATION) return ERR_EMPTY; 2596 if (error == ERR_INVALIDLOCATION) return ERR_EMPTY;
2490 return error; 2597 return error;
2491} 2598}
2492 2599
2493GSM_Error ATGEN_DeleteAllMemory(GSM_StateMachine *s, GSM_MemoryType type) 2600GSM_Error ATGEN_DeleteAllMemory(GSM_StateMachine *s, GSM_MemoryType type)
2494{ 2601{
2495 GSM_Error error; 2602 GSM_Error error;
2496 unsigned char req[100]; 2603 unsigned char req[100];
2497 int i; 2604 int i;
2498 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 2605 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
2499 2606
2500 error = ATGEN_SetPBKMemory(s, type); 2607 error = ATGEN_SetPBKMemory(s, type);
2501 if (error != ERR_NONE) return error; 2608 if (error != ERR_NONE) return error;
2502 2609
2503 if (Priv->MemorySize == 0) { 2610 if (Priv->MemorySize == 0) {
2504 error = ATGEN_GetMemoryInfo(s, NULL, AT_Total); 2611 error = ATGEN_GetMemoryInfo(s, NULL, AT_Total);
2505 if (error != ERR_NONE) return error; 2612 if (error != ERR_NONE) return error;
2506 } 2613 }
2507 2614
2508 if (Priv->FirstMemoryEntry == 0) { 2615 if (Priv->FirstMemoryEntry == 0) {
2509 error = ATGEN_GetMemoryInfo(s, NULL, AT_First); 2616 error = ATGEN_GetMemoryInfo(s, NULL, AT_First);
2510 if (error != ERR_NONE) return error; 2617 if (error != ERR_NONE) return error;
2511 } 2618 }
2512 2619
2513 2620
2514 smprintf(s, "Deleting all phonebook entries\n"); 2621 smprintf(s, "Deleting all phonebook entries\n");
2515 for (i = Priv->FirstMemoryEntry; i < Priv->FirstMemoryEntry + Priv->MemorySize; i++) { 2622 for (i = Priv->FirstMemoryEntry; i < Priv->FirstMemoryEntry + Priv->MemorySize; i++) {
2516 sprintf(req, "AT+CPBW=%d\r",i); 2623 sprintf(req, "AT+CPBW=%d\r",i);
2517 error = GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_SetMemory); 2624 error = GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_SetMemory);
2518 if (error != ERR_NONE) return error; 2625 if (error != ERR_NONE) return error;
2519 } 2626 }
2520 return ERR_NONE; 2627 return ERR_NONE;
2521} 2628}
2522 2629
2523GSM_Error ATGEN_ReplyDialVoice(GSM_Protocol_Message msg, GSM_StateMachine *s) 2630GSM_Error ATGEN_ReplyDialVoice(GSM_Protocol_Message msg, GSM_StateMachine *s)
2524{ 2631{
2525 switch (s->Phone.Data.Priv.ATGEN.ReplyState) { 2632 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
2526 case AT_Reply_OK: 2633 case AT_Reply_OK:
2527 smprintf(s, "Dial voice OK\n"); 2634 smprintf(s, "Dial voice OK\n");
2528 return ERR_NONE; 2635 return ERR_NONE;
2529 case AT_Reply_Error: 2636 case AT_Reply_Error:
2530 smprintf(s, "Dial voice error\n"); 2637 smprintf(s, "Dial voice error\n");
2531 return ERR_UNKNOWN; 2638 return ERR_UNKNOWN;
2532 case AT_Reply_CMSError: 2639 case AT_Reply_CMSError:
2533 return ATGEN_HandleCMSError(s); 2640 return ATGEN_HandleCMSError(s);
2534 default: 2641 default:
2535 break; 2642 break;
2536 } 2643 }
2537 return ERR_UNKNOWNRESPONSE; 2644 return ERR_UNKNOWNRESPONSE;
2538} 2645}
2539 2646
2540GSM_Error ATGEN_DialVoice(GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber) 2647GSM_Error ATGEN_DialVoice(GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber)
2541{ 2648{
2542 char req[39] = "ATDT"; 2649 char req[39] = "ATDT";
2543 2650
2544 if (ShowNumber != GSM_CALL_DefaultNumberPresence) return ERR_NOTSUPPORTED; 2651 if (ShowNumber != GSM_CALL_DefaultNumberPresence) return ERR_NOTSUPPORTED;
2545 if (strlen(number) > 32) return (ERR_UNKNOWN); 2652 if (strlen(number) > 32) return (ERR_UNKNOWN);
2546 2653
2547 strcat(req, number); 2654 strcat(req, number);
2548 strcat(req, ";\r"); 2655 strcat(req, ";\r");
2549 2656
2550 smprintf(s, "Making voice call\n"); 2657 smprintf(s, "Making voice call\n");
2551 return GSM_WaitFor (s, req, 4+2+strlen(number), 0x00, 5, ID_DialVoice); 2658 return GSM_WaitFor (s, req, 4+2+strlen(number), 0x00, 5, ID_DialVoice);
2552} 2659}
2553 2660
2554GSM_Error ATGEN_ReplyEnterSecurityCode(GSM_Protocol_Message msg, GSM_StateMachine *s) 2661GSM_Error ATGEN_ReplyEnterSecurityCode(GSM_Protocol_Message msg, GSM_StateMachine *s)
2555{ 2662{
2556 switch (s->Phone.Data.Priv.ATGEN.ReplyState) { 2663 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
2557 case AT_Reply_OK: 2664 case AT_Reply_OK:
2558 smprintf(s, "Security code was OK\n"); 2665 smprintf(s, "Security code was OK\n");
2559 return ERR_NONE; 2666 return ERR_NONE;
2560 case AT_Reply_Error: 2667 case AT_Reply_Error:
2561 smprintf(s, "Incorrect security code\n"); 2668 smprintf(s, "Incorrect security code\n");
2562 return ERR_SECURITYERROR; 2669 return ERR_SECURITYERROR;
2563 case AT_Reply_CMSError: 2670 case AT_Reply_CMSError:
2564 return ATGEN_HandleCMSError(s); 2671 return ATGEN_HandleCMSError(s);
2672 case AT_Reply_CMEError:
2673 return ATGEN_HandleCMEError(s);
2565 default: 2674 default:
2566 break; 2675 break;
2567 } 2676 }
2568 return ERR_UNKNOWNRESPONSE; 2677 return ERR_UNKNOWNRESPONSE;
2569} 2678}
2570 2679
2571GSM_Error ATGEN_EnterSecurityCode(GSM_StateMachine *s, GSM_SecurityCode Code) 2680GSM_Error ATGEN_EnterSecurityCode(GSM_StateMachine *s, GSM_SecurityCode Code)
2572{ 2681{
2573 unsigned char req[50]; 2682 unsigned char req[50];
2574 2683
2575 switch (Code.Type) { 2684 switch (Code.Type) {
2576 case SEC_Pin : 2685 case SEC_Pin :
2577 sprintf(req, "AT+CPIN=\"%s\"\r" , Code.Code); 2686 sprintf(req, "AT+CPIN=\"%s\"\r" , Code.Code);
2578 break; 2687 break;
2579 case SEC_Pin2 : 2688 case SEC_Pin2 :
2580 if (s->Phone.Data.Priv.ATGEN.Manufacturer == AT_Siemens) { 2689 if (s->Phone.Data.Priv.ATGEN.Manufacturer == AT_Siemens) {
2581 sprintf(req, "AT+CPIN2=\"%s\"\r", Code.Code); 2690 sprintf(req, "AT+CPIN2=\"%s\"\r", Code.Code);
2582 } else { 2691 } else {
2583 sprintf(req, "AT+CPIN=\"%s\"\r" , Code.Code); 2692 sprintf(req, "AT+CPIN=\"%s\"\r" , Code.Code);
2584 } 2693 }
2585 break; 2694 break;
2586 default : return ERR_NOTIMPLEMENTED; 2695 default : return ERR_NOTIMPLEMENTED;
2587 } 2696 }
2588 2697
2589 smprintf(s, "Entering security code\n"); 2698 smprintf(s, "Entering security code\n");
2590 return GSM_WaitFor (s, req, strlen(req), 0x00, 6, ID_EnterSecurityCode); 2699 return GSM_WaitFor (s, req, strlen(req), 0x00, 6, ID_EnterSecurityCode);
2591} 2700}
2592 2701
2593GSM_Error ATGEN_ReplyGetSecurityStatus(GSM_Protocol_Message msg, GSM_StateMachine *s) 2702GSM_Error ATGEN_ReplyGetSecurityStatus(GSM_Protocol_Message msg, GSM_StateMachine *s)
2594{ 2703{
2595 GSM_SecurityCodeType *Status = s->Phone.Data.SecurityStatus; 2704 GSM_SecurityCodeType *Status = s->Phone.Data.SecurityStatus;
2596 2705
2597 smprintf(s, "Security status received - "); 2706 smprintf(s, "Security status received - ");
2598 if (strstr(msg.Buffer,"READY")) { 2707 if (strstr(msg.Buffer,"READY")) {
2599 *Status = SEC_None; 2708 *Status = SEC_None;
2600 smprintf(s, "nothing to enter\n"); 2709 smprintf(s, "nothing to enter\n");
2601 return ERR_NONE; 2710 return ERR_NONE;
2602 } 2711 }
2603 if (strstr(msg.Buffer,"PH_SIM PIN")) { 2712 if (strstr(msg.Buffer,"PH_SIM PIN")) {
2604 smprintf(s, "no SIM inside or other error\n"); 2713 smprintf(s, "no SIM inside or other error\n");
2605 return ERR_UNKNOWN; 2714 return ERR_UNKNOWN;
2606 } 2715 }
2607 if (strstr(msg.Buffer,"SIM PIN2")) { 2716 if (strstr(msg.Buffer,"SIM PIN2")) {
2608 *Status = SEC_Pin2; 2717 *Status = SEC_Pin2;
2609 smprintf(s, "waiting for PIN2\n"); 2718 smprintf(s, "waiting for PIN2\n");
2610 return ERR_NONE; 2719 return ERR_NONE;
2611 } 2720 }
2612 if (strstr(msg.Buffer,"SIM PUK2")) { 2721 if (strstr(msg.Buffer,"SIM PUK2")) {
2613 *Status = SEC_Puk2; 2722 *Status = SEC_Puk2;
2614 smprintf(s, "waiting for PUK2\n"); 2723 smprintf(s, "waiting for PUK2\n");
2615 return ERR_NONE; 2724 return ERR_NONE;
2616 } 2725 }
2617 if (strstr(msg.Buffer,"SIM PIN")) { 2726 if (strstr(msg.Buffer,"SIM PIN")) {
2618 *Status = SEC_Pin; 2727 *Status = SEC_Pin;
2619 smprintf(s, "waiting for PIN\n"); 2728 smprintf(s, "waiting for PIN\n");
2620 return ERR_NONE; 2729 return ERR_NONE;
2621 } 2730 }
2622 if (strstr(msg.Buffer,"SIM PUK")) { 2731 if (strstr(msg.Buffer,"SIM PUK")) {
2623 *Status = SEC_Puk; 2732 *Status = SEC_Puk;
2624 smprintf(s, "waiting for PUK\n"); 2733 smprintf(s, "waiting for PUK\n");
2625 return ERR_NONE; 2734 return ERR_NONE;
2626 } 2735 }
2627 smprintf(s, "unknown\n"); 2736 smprintf(s, "unknown\n");
2628 return ERR_UNKNOWNRESPONSE; 2737 return ERR_UNKNOWNRESPONSE;
2629} 2738}
2630 2739
2631GSM_Error ATGEN_GetSecurityStatus(GSM_StateMachine *s, GSM_SecurityCodeType *Status) 2740GSM_Error ATGEN_GetSecurityStatus(GSM_StateMachine *s, GSM_SecurityCodeType *Status)
2632{ 2741{
2633 s->Phone.Data.SecurityStatus=Status; 2742 s->Phone.Data.SecurityStatus=Status;
2634 2743
2635 smprintf(s, "Getting security code status\n"); 2744 smprintf(s, "Getting security code status\n");
2636 /* Please note, that A2D doesn't return OK on the end. 2745 /* Please note, that A2D doesn't return OK on the end.
2637 * Because of it ReplyGetSecurityStatus is called after receiving line 2746 * Because of it ReplyGetSecurityStatus is called after receiving line
2638 * with +CPIN: 2747 * with +CPIN:
2639 */ 2748 */
2640 return GSM_WaitFor (s, "AT+CPIN?\r", 9, 0x00, 4, ID_GetSecurityStatus); 2749 return GSM_WaitFor (s, "AT+CPIN?\r", 9, 0x00, 4, ID_GetSecurityStatus);
2641} 2750}
2642 2751
2643GSM_Error ATGEN_AnswerCall(GSM_StateMachine *s, int ID, bool all) 2752GSM_Error ATGEN_AnswerCall(GSM_StateMachine *s, int ID, bool all)
2644{ 2753{
2645 if (all) { 2754 if (all) {
2646 smprintf(s, "Answering all calls\n"); 2755 smprintf(s, "Answering all calls\n");
2647 return GSM_WaitFor (s, "ATA\r", 4, 0x00, 4, ID_AnswerCall); 2756 return GSM_WaitFor (s, "ATA\r", 4, 0x00, 4, ID_AnswerCall);
2648 } 2757 }
2649 return ERR_NOTSUPPORTED; 2758 return ERR_NOTSUPPORTED;
2650} 2759}
2651 2760
2652GSM_Error ATGEN_ReplyCancelCall(GSM_Protocol_Message msg, GSM_StateMachine *s) 2761GSM_Error ATGEN_ReplyCancelCall(GSM_Protocol_Message msg, GSM_StateMachine *s)
2653{ 2762{
2654 GSM_Call call; 2763 GSM_Call call;
2655 2764
2656 switch(s->Phone.Data.Priv.ATGEN.ReplyState) { 2765 switch(s->Phone.Data.Priv.ATGEN.ReplyState) {
2657 case AT_Reply_OK: 2766 case AT_Reply_OK:
2658 smprintf(s, "Calls canceled\n"); 2767 smprintf(s, "Calls canceled\n");
2659 call.CallIDAvailable = false; 2768 call.CallIDAvailable = false;
2660 call.Status = GSM_CALL_CallLocalEnd; 2769 call.Status = GSM_CALL_CallLocalEnd;
2661 if (s->User.IncomingCall) s->User.IncomingCall(s->CurrentConfig->Device, call); 2770 if (s->User.IncomingCall) s->User.IncomingCall(s->CurrentConfig->Device, call);
2662 2771
2663 return ERR_NONE; 2772 return ERR_NONE;
2664 case AT_Reply_CMSError: 2773 case AT_Reply_CMSError:
2665 return ATGEN_HandleCMSError(s); 2774 return ATGEN_HandleCMSError(s);
2666 default: 2775 default:
2667 return ERR_UNKNOWN; 2776 return ERR_UNKNOWN;
2668 } 2777 }
2669} 2778}
2670 2779
2671GSM_Error ATGEN_CancelCall(GSM_StateMachine *s, int ID, bool all) 2780GSM_Error ATGEN_CancelCall(GSM_StateMachine *s, int ID, bool all)
2672{ 2781{
2673 GSM_Error error; 2782 GSM_Error error;
2674 2783
2675 if (all) { 2784 if (all) {
2676 smprintf(s, "Dropping all calls\n"); 2785 smprintf(s, "Dropping all calls\n");
2677 error = GSM_WaitFor (s, "ATH\r", 4, 0x00, 4, ID_CancelCall); 2786 error = GSM_WaitFor (s, "ATH\r", 4, 0x00, 4, ID_CancelCall);
2678 if (error == ERR_UNKNOWN) { 2787 if (error == ERR_UNKNOWN) {
2679 return GSM_WaitFor (s, "AT+CHUP\r", 8, 0x00, 4, ID_CancelCall); 2788 return GSM_WaitFor (s, "AT+CHUP\r", 8, 0x00, 4, ID_CancelCall);
2680 } 2789 }
2681 return error; 2790 return error;
2682 } 2791 }
2683 return ERR_NOTSUPPORTED; 2792 return ERR_NOTSUPPORTED;
2684} 2793}
2685 2794
2686GSM_Error ATGEN_ReplyReset(GSM_Protocol_Message msg, GSM_StateMachine *s) 2795GSM_Error ATGEN_ReplyReset(GSM_Protocol_Message msg, GSM_StateMachine *s)
2687{ 2796{
2688 smprintf(s, "Reset done\n"); 2797 smprintf(s, "Reset done\n");
2689 return ERR_NONE; 2798 return ERR_NONE;
2690} 2799}
2691 2800
2692GSM_Error ATGEN_Reset(GSM_StateMachine *s, bool hard) 2801GSM_Error ATGEN_Reset(GSM_StateMachine *s, bool hard)
2693{ 2802{
2694 GSM_Error error; 2803 GSM_Error error;
2695 2804
2696 if (!hard) return ERR_NOTSUPPORTED; 2805 if (!hard) return ERR_NOTSUPPORTED;
2697 2806
2698 smprintf(s, "Resetting device\n"); 2807 smprintf(s, "Resetting device\n");
2699 /* Siemens 35 */ 2808 /* Siemens 35 */
2700 error=GSM_WaitFor (s, "AT+CFUN=1,1\r", 12, 0x00, 8, ID_Reset); 2809 error=GSM_WaitFor (s, "AT+CFUN=1,1\r", 12, 0x00, 8, ID_Reset);
2701 if (error != ERR_NONE) { 2810 if (error != ERR_NONE) {
2702 /* Siemens M20 */ 2811 /* Siemens M20 */
2703 error=GSM_WaitFor (s, "AT^SRESET\r", 10, 0x00, 8, ID_Reset); 2812 error=GSM_WaitFor (s, "AT^SRESET\r", 10, 0x00, 8, ID_Reset);
2704 } 2813 }
2705 return error; 2814 return error;
2706} 2815}
2707 2816
2708GSM_Error ATGEN_ReplyResetPhoneSettings(GSM_Protocol_Message msg, GSM_StateMachine *s) 2817GSM_Error ATGEN_ReplyResetPhoneSettings(GSM_Protocol_Message msg, GSM_StateMachine *s)
2709{ 2818{
2710 smprintf(s, "Reset done\n"); 2819 smprintf(s, "Reset done\n");
2711 return ERR_NONE; 2820 return ERR_NONE;
2712} 2821}
2713 2822
2714GSM_Error ATGEN_ResetPhoneSettings(GSM_StateMachine *s, GSM_ResetSettingsType Type) 2823GSM_Error ATGEN_ResetPhoneSettings(GSM_StateMachine *s, GSM_ResetSettingsType Type)
2715{ 2824{
2716 smprintf(s, "Resetting settings to default\n"); 2825 smprintf(s, "Resetting settings to default\n");
2717 return GSM_WaitFor (s, "AT&F\r", 5, 0x00, 4, ID_ResetPhoneSettings); 2826 return GSM_WaitFor (s, "AT&F\r", 5, 0x00, 4, ID_ResetPhoneSettings);
2718} 2827}
2719 2828
2720GSM_Error ATGEN_SetAutoNetworkLogin(GSM_StateMachine *s) 2829GSM_Error ATGEN_SetAutoNetworkLogin(GSM_StateMachine *s)
2721{ 2830{
2722 smprintf(s, "Enabling automatic network login\n"); 2831 smprintf(s, "Enabling automatic network login\n");
2723 return GSM_WaitFor (s, "AT+COPS=0\r", 10, 0x00, 4, ID_SetAutoNetworkLogin); 2832 return GSM_WaitFor (s, "AT+COPS=0\r", 10, 0x00, 4, ID_SetAutoNetworkLogin);
2724} 2833}
2725 2834
2726GSM_Error ATGEN_SendDTMF(GSM_StateMachine *s, char *sequence) 2835GSM_Error ATGEN_SendDTMF(GSM_StateMachine *s, char *sequence)
2727{ 2836{
2728 unsigned char req[80] = "AT+VTS="; 2837 unsigned char req[80] = "AT+VTS=";
2729 int n; 2838 int n;
2730 2839
2731 for (n = 0; n < 32; n++) { 2840 for (n = 0; n < 32; n++) {
2732 if (sequence[n] == '\0') break; 2841 if (sequence[n] == '\0') break;
2733 if (n != 0) req[6 + 2 * n] = ','; 2842 if (n != 0) req[6 + 2 * n] = ',';
2734 req[7 + 2 * n] = sequence[n]; 2843 req[7 + 2 * n] = sequence[n];
2735 } 2844 }
2736 2845
2737 strcat(req, ";\r"); 2846 strcat(req, ";\r");
2738 2847
2739 smprintf(s, "Sending DTMF\n"); 2848 smprintf(s, "Sending DTMF\n");
2740 return GSM_WaitFor (s, req, 7+2+2*strlen(sequence), 0x00, 4, ID_SendDTMF); 2849 return GSM_WaitFor (s, req, 7+2+2*strlen(sequence), 0x00, 4, ID_SendDTMF);
2741} 2850}
2742 2851
2743GSM_Error ATGEN_ReplyDeleteSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s) 2852GSM_Error ATGEN_ReplyDeleteSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s)
2744{ 2853{
2745 switch (s->Phone.Data.Priv.ATGEN.ReplyState) { 2854 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
2746 case AT_Reply_OK: 2855 case AT_Reply_OK:
2747 smprintf(s, "SMS deleted OK\n"); 2856 smprintf(s, "SMS deleted OK\n");
2748 return ERR_NONE; 2857 return ERR_NONE;
2749 case AT_Reply_Error: 2858 case AT_Reply_Error:
2750 smprintf(s, "Invalid location\n"); 2859 smprintf(s, "Invalid location\n");
2751 return ERR_INVALIDLOCATION; 2860 return ERR_INVALIDLOCATION;
2752 case AT_Reply_CMSError: 2861 case AT_Reply_CMSError:
2753 return ATGEN_HandleCMSError(s); 2862 return ATGEN_HandleCMSError(s);
2754 default: 2863 default:
2755 break; 2864 break;
2756 } 2865 }
2757 return ERR_UNKNOWNRESPONSE; 2866 return ERR_UNKNOWNRESPONSE;
2758} 2867}
2759 2868
2760GSM_Error ATGEN_DeleteSMS(GSM_StateMachine *s, GSM_SMSMessage *sms) 2869GSM_Error ATGEN_DeleteSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
2761{ 2870{
2762 unsigned char req[20], folderid; 2871 unsigned char req[20], folderid;
2763 GSM_Error error; 2872 GSM_Error error;
2764 int location; 2873 int location;
2765 GSM_MultiSMSMessagemsms; 2874 GSM_MultiSMSMessagemsms;
2766 2875
2767 msms.Number = 0; 2876 msms.Number = 0;
2768 msms.SMS[0] = *sms; 2877 msms.SMS[0] = *sms;
2769 2878
2770 /* By reading SMS we check if it is really inbox/outbox */ 2879 /* By reading SMS we check if it is really inbox/outbox */
2771 error = ATGEN_GetSMS(s, &msms); 2880 error = ATGEN_GetSMS(s, &msms);
2772 if (error != ERR_NONE) return error; 2881 if (error != ERR_NONE) return error;
2773 2882
2774 error = ATGEN_GetSMSLocation(s, sms, &folderid, &location); 2883 error = ATGEN_GetSMSLocation(s, sms, &folderid, &location);
2775 if (error != ERR_NONE) return error; 2884 if (error != ERR_NONE) return error;
2776 2885
2777 sprintf(req, "AT+CMGD=%i\r",location); 2886 sprintf(req, "AT+CMGD=%i\r",location);
2778 2887
2779 smprintf(s, "Deleting SMS\n"); 2888 smprintf(s, "Deleting SMS\n");
2780 return GSM_WaitFor (s, req, strlen(req), 0x00, 5, ID_DeleteSMSMessage); 2889 return GSM_WaitFor (s, req, strlen(req), 0x00, 5, ID_DeleteSMSMessage);
2781} 2890}
2782 2891
2783GSM_Error ATGEN_GetSMSFolders(GSM_StateMachine *s, GSM_SMSFolders *folders) 2892GSM_Error ATGEN_GetSMSFolders(GSM_StateMachine *s, GSM_SMSFolders *folders)
2784{ 2893{
2785 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 2894 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
2786 GSM_Error error; 2895 GSM_Error error;
2787 int used = 0; 2896 int used = 0;
2788 2897
2789 if (Priv->PhoneSMSMemory == 0) { 2898 if (Priv->PhoneSMSMemory == 0) {
2790 error = ATGEN_SetSMSMemory(s, false); 2899 error = ATGEN_SetSMSMemory(s, false);
2791 if (error != ERR_NONE && error != ERR_NOTSUPPORTED) return error; 2900 if (error != ERR_NONE && error != ERR_NOTSUPPORTED) return error;
2792 } 2901 }
2793 if (Priv->SIMSMSMemory == 0) { 2902 if (Priv->SIMSMSMemory == 0) {
2794 error = ATGEN_SetSMSMemory(s, true); 2903 error = ATGEN_SetSMSMemory(s, true);
2795 if (error != ERR_NONE && error != ERR_NOTSUPPORTED) return error; 2904 if (error != ERR_NONE && error != ERR_NOTSUPPORTED) return error;
2796 } 2905 }
2797 2906
2798 folders->Number = 0; 2907 folders->Number = 0;
2799 if (Priv->PhoneSMSMemory == AT_NOTAVAILABLE && Priv->SIMSMSMemory == AT_NOTAVAILABLE) { 2908 if (Priv->PhoneSMSMemory == AT_NOTAVAILABLE && Priv->SIMSMSMemory == AT_NOTAVAILABLE) {
2800 return ERR_NONE; 2909 return ERR_NONE;
2801 } 2910 }
2802 2911
2803 PHONE_GetSMSFolders(s,folders); 2912 PHONE_GetSMSFolders(s,folders);
2804 2913
2805 if (Priv->SIMSMSMemory == AT_AVAILABLE) { 2914 if (Priv->SIMSMSMemory == AT_AVAILABLE) {
2806 used = 2; 2915 used = 2;
2807 } 2916 }
2808 2917
2809 if (Priv->PhoneSMSMemory == AT_AVAILABLE) { 2918 if (Priv->PhoneSMSMemory == AT_AVAILABLE) {
2810 if (used != 0) { 2919 if (used != 0) {
2811 CopyUnicodeString(folders->Folder[used ].Name,folders->Folder[0].Name); 2920 CopyUnicodeString(folders->Folder[used ].Name,folders->Folder[0].Name);
2812 CopyUnicodeString(folders->Folder[used + 1].Name,folders->Folder[1].Name); 2921 CopyUnicodeString(folders->Folder[used + 1].Name,folders->Folder[1].Name);
2813 folders->Folder[used ].InboxFolder = true; 2922 folders->Folder[used ].InboxFolder = true;
2814 folders->Folder[used + 1].InboxFolder = false; 2923 folders->Folder[used + 1].InboxFolder = false;
2815 } 2924 }
2816 folders->Folder[used ].Memory = MEM_ME; 2925 folders->Folder[used ].Memory = MEM_ME;
2817 folders->Folder[used + 1].Memory = MEM_ME; 2926 folders->Folder[used + 1].Memory = MEM_ME;
2818 folders->Number += 2; 2927 folders->Number += 2;
2819 used += 2; 2928 used += 2;
2820 } 2929 }
2821 2930
2822 return ERR_NONE; 2931 return ERR_NONE;
2823} 2932}
2824 2933
2825GSM_Error ATGEN_ReplySetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s) 2934GSM_Error ATGEN_ReplySetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s)
2826{ 2935{
2827 switch (s->Phone.Data.Priv.ATGEN.ReplyState) { 2936 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
2828 case AT_Reply_OK: 2937 case AT_Reply_OK:
2829 smprintf(s, "Phonebook entry written OK\n"); 2938 smprintf(s, "Phonebook entry written OK\n");
2830 return ERR_NONE; 2939 return ERR_NONE;
2831 case AT_Reply_CMSError: 2940 case AT_Reply_CMSError:
2832 return ATGEN_HandleCMSError(s); 2941 return ATGEN_HandleCMSError(s);
2833 case AT_Reply_CMEError: 2942 case AT_Reply_CMEError:
2834 return ATGEN_HandleCMEError(s); 2943 return ATGEN_HandleCMEError(s);
2835 case AT_Reply_Error: 2944 case AT_Reply_Error:
2836 return ERR_INVALIDDATA; 2945 return ERR_INVALIDDATA;
2837 default: 2946 default:
2838 return ERR_UNKNOWNRESPONSE; 2947 return ERR_UNKNOWNRESPONSE;
2839 } 2948 }
2840} 2949}
2841 2950
2842GSM_Error ATGEN_DeleteMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry) 2951GSM_Error ATGEN_DeleteMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
2843{ 2952{
2844 GSM_Error error; 2953 GSM_Error error;
2845 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 2954 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
2846 unsigned char req[100]; 2955 unsigned char req[100];
2847 2956
2848 if (entry->Location < 1) return ERR_INVALIDLOCATION; 2957 if (entry->Location < 1) return ERR_INVALIDLOCATION;
2849 2958
2850 error = ATGEN_SetPBKMemory(s, entry->MemoryType); 2959 error = ATGEN_SetPBKMemory(s, entry->MemoryType);
2851 if (error != ERR_NONE) return error; 2960 if (error != ERR_NONE) return error;
2852 2961
2853 if (Priv->FirstMemoryEntry == 0) { 2962 if (Priv->FirstMemoryEntry == 0) {
2854 error = ATGEN_GetMemoryInfo(s, NULL, AT_First); 2963 error = ATGEN_GetMemoryInfo(s, NULL, AT_First);
2855 if (error != ERR_NONE) return error; 2964 if (error != ERR_NONE) return error;
2856 } 2965 }
2857 2966
2858 sprintf(req, "AT+CPBW=%d\r",entry->Location + Priv->FirstMemoryEntry - 1); 2967 sprintf(req, "AT+CPBW=%d\r",entry->Location + Priv->FirstMemoryEntry - 1);
2859 2968
2860 smprintf(s, "Deleting phonebook entry\n"); 2969 smprintf(s, "Deleting phonebook entry\n");
2861 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_SetMemory); 2970 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_SetMemory);
2862} 2971}
2863 2972
2864GSM_Error ATGEN_PrivSetMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry) 2973GSM_Error ATGEN_PrivSetMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
2865{ 2974{
2866 /* REQUEST_SIZE should be big enough to handle all possibl cases 2975 /* REQUEST_SIZE should be big enough to handle all possibl cases
2867 * correctly, especially with unicode entries */ 2976 * correctly, especially with unicode entries */
2868 #define REQUEST_SIZE((4 * GSM_PHONEBOOK_TEXT_LENGTH) + 30) 2977 #define REQUEST_SIZE((4 * GSM_PHONEBOOK_TEXT_LENGTH) + 30)
2869 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 2978 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
2870 int Group, Name, Number,NumberType=0, len; 2979 int Group, Name, Number,NumberType=0, len;
2871 GSM_Error error; 2980 GSM_Error error;
2872 unsigned char req[REQUEST_SIZE + 1]; 2981 unsigned char req[REQUEST_SIZE + 1];
2873 unsigned char name[2*(GSM_PHONEBOOK_TEXT_LENGTH + 1)]; 2982 unsigned char name[2*(GSM_PHONEBOOK_TEXT_LENGTH + 1)];
2874 unsigned char uname[2*(GSM_PHONEBOOK_TEXT_LENGTH + 1)]; 2983 unsigned char uname[2*(GSM_PHONEBOOK_TEXT_LENGTH + 1)];
2875 unsigned char number[GSM_PHONEBOOK_TEXT_LENGTH + 1]; 2984 unsigned char number[GSM_PHONEBOOK_TEXT_LENGTH + 1];
2876 int reqlen; 2985 int reqlen;
2877 bool PreferUnicode = false; 2986 bool PreferUnicode = false;
2878 2987
2879 if (entry->Location == 0) return ERR_INVALIDLOCATION; 2988 if (entry->Location == 0) return ERR_INVALIDLOCATION;
2880 2989
2881 error = ATGEN_SetPBKMemory(s, entry->MemoryType); 2990 error = ATGEN_SetPBKMemory(s, entry->MemoryType);
2882 if (error != ERR_NONE) return error; 2991 if (error != ERR_NONE) return error;
2883 2992
2884 GSM_PhonebookFindDefaultNameNumberGroup(entry, &Name, &Number, &Group); 2993 GSM_PhonebookFindDefaultNameNumberGroup(entry, &Name, &Number, &Group);
2885 2994
2886 name[0] = 0; 2995 name[0] = 0;
2887 if (Name != -1) { 2996 if (Name != -1) {
2888 len = UnicodeLength(entry->Entries[Name].Text); 2997 len = UnicodeLength(entry->Entries[Name].Text);
2889 2998
2890 /* Compare if we would loose some information when not using 2999 /* Compare if we would loose some information when not using
2891 * unicode */ 3000 * unicode */
2892 EncodeDefault(name, entry->Entries[Name].Text, &len, true, NULL); 3001 EncodeDefault(name, entry->Entries[Name].Text, &len, true, NULL);
2893 DecodeDefault(uname, name, len, true, NULL); 3002 DecodeDefault(uname, name, len, true, NULL);
2894 if (!mywstrncmp(uname, entry->Entries[Name].Text, len)) { 3003 if (!mywstrncmp(uname, entry->Entries[Name].Text, len)) {
2895 /* Get maximal text length */ 3004 /* Get maximal text length */
2896 if (Priv->TextLength == 0) { 3005 if (Priv->TextLength == 0) {
2897 ATGEN_GetMemoryInfo(s, NULL, AT_Sizes); 3006 ATGEN_GetMemoryInfo(s, NULL, AT_Sizes);
2898 } 3007 }
2899 3008
2900 /* I char stored in GSM alphabet takes 7 bits, one 3009 /* I char stored in GSM alphabet takes 7 bits, one
2901 * unicode 16, if storing in unicode would truncate 3010 * unicode 16, if storing in unicode would truncate
2902 * text, do not use it, otherwise we will use it */ 3011 * text, do not use it, otherwise we will use it */
2903 if ((Priv->TextLength != 0) && ((Priv->TextLength * 7 / 16) <= len)) { 3012 if ((Priv->TextLength != 0) && ((Priv->TextLength * 7 / 16) <= len)) {
2904 PreferUnicode = false; 3013 PreferUnicode = false;
2905 } else { 3014 } else {
2906 PreferUnicode = true; 3015 PreferUnicode = true;
2907 } 3016 }
2908 } 3017 }
2909 3018
2910 error = ATGEN_SetPBKCharset(s, PreferUnicode); 3019 error = ATGEN_SetPBKCharset(s, PreferUnicode);
2911 if (error != ERR_NONE) return error; 3020 if (error != ERR_NONE) return error;
2912 3021
2913 switch (Priv->PBKCharset) { 3022 switch (Priv->PBKCharset) {
2914 case AT_PBK_HEX: 3023 case AT_PBK_HEX:
2915 EncodeHexBin(name, DecodeUnicodeString(entry->Entries[Name].Text), UnicodeLength(entry->Entries[Name].Text)); 3024 EncodeHexBin(name, DecodeUnicodeString(entry->Entries[Name].Text), UnicodeLength(entry->Entries[Name].Text));
2916 len = strlen(name); 3025 len = strlen(name);
2917 break; 3026 break;
2918 case AT_PBK_GSM: 3027 case AT_PBK_GSM:
2919 smprintf(s, "str: %s\n", DecodeUnicodeString(entry->Entries[Name].Text)); 3028 smprintf(s, "str: %s\n", DecodeUnicodeString(entry->Entries[Name].Text));
2920 len = UnicodeLength(entry->Entries[Name].Text); 3029 len = UnicodeLength(entry->Entries[Name].Text);
2921 EncodeDefault(name, entry->Entries[Name].Text, &len, true, NULL); 3030 EncodeDefault(name, entry->Entries[Name].Text, &len, true, NULL);
2922 break; 3031 break;
2923 case AT_PBK_UCS2: 3032 case AT_PBK_UCS2:
2924 EncodeHexUnicode(name, entry->Entries[Name].Text, UnicodeLength(entry->Entries[Name].Text)); 3033 EncodeHexUnicode(name, entry->Entries[Name].Text, UnicodeLength(entry->Entries[Name].Text));
2925 len = strlen(name); 3034 len = strlen(name);
2926 break; 3035 break;
3036 case AT_PBK_PCCP437:
3037 /* FIXME: correctly decode PCCP437 */
3038 smprintf(s, "str: %s\n", DecodeUnicodeString(entry->Entries[Name].Text));
3039 len = UnicodeLength(entry->Entries[Name].Text);
3040 EncodeDefault(name, entry->Entries[Name].Text, &len, true, NULL);
3041 break;
2927 } 3042 }
2928 } else { 3043 } else {
2929 smprintf(s, "WARNING: No usable name found!\n"); 3044 smprintf(s, "WARNING: No usable name found!\n");
2930 len = 0; 3045 len = 0;
2931 } 3046 }
2932 3047
2933 if (Number != -1) { 3048 if (Number != -1) {
2934 GSM_PackSemiOctetNumber(entry->Entries[Number].Text, number, false); 3049 GSM_PackSemiOctetNumber(entry->Entries[Number].Text, number, false);
2935 NumberType = number[0]; 3050 NumberType = number[0];
2936 sprintf(number,"%s",DecodeUnicodeString(entry->Entries[Number].Text)); 3051 sprintf(number,"%s",DecodeUnicodeString(entry->Entries[Number].Text));
2937 } else { 3052 } else {
2938 smprintf(s, "WARNING: No usable number found!\n"); 3053 smprintf(s, "WARNING: No usable number found!\n");
2939 number[0] = 0; 3054 number[0] = 0;
2940 } 3055 }
2941 3056
2942 if (Priv->FirstMemoryEntry == 0) { 3057 if (Priv->FirstMemoryEntry == 0) {
2943 error = ATGEN_GetMemoryInfo(s, NULL, AT_First); 3058 error = ATGEN_GetMemoryInfo(s, NULL, AT_First);
2944 if (error != ERR_NONE) return error; 3059 if (error != ERR_NONE) return error;
2945 } 3060 }
2946 3061
2947 /* We can't use here: 3062 /* We can't use here:
2948 * sprintf(req, "AT+CPBW=%d, \"%s\", %i, \"%s\"\r", 3063 * sprintf(req, "AT+CPBW=%d, \"%s\", %i, \"%s\"\r",
2949 * entry->Location, number, NumberType, name); 3064 * entry->Location, number, NumberType, name);
2950 * because name can contain 0 when using GSM alphabet. 3065 * because name can contain 0 when using GSM alphabet.
2951 */ 3066 */
2952 sprintf(req, "AT+CPBW=%d, \"%s\", %i, \"", entry->Location + Priv->FirstMemoryEntry - 1, number, NumberType); 3067 sprintf(req, "AT+CPBW=%d, \"%s\", %i, \"", entry->Location + Priv->FirstMemoryEntry - 1, number, NumberType);
2953 reqlen = strlen(req); 3068 reqlen = strlen(req);
2954 if (reqlen + len > REQUEST_SIZE - 2) { 3069 if (reqlen + len > REQUEST_SIZE - 2) {
2955 smprintf(s, "WARNING: Text truncated to fit in buffer!\n"); 3070 smprintf(s, "WARNING: Text truncated to fit in buffer!\n");
2956 len = REQUEST_SIZE - 2 - reqlen; 3071 len = REQUEST_SIZE - 2 - reqlen;
2957 } 3072 }
2958 memcpy(req + reqlen, name, len); 3073 memcpy(req + reqlen, name, len);
2959 reqlen += len; 3074 reqlen += len;
2960 memcpy(req + reqlen, "\"\r", 2); 3075 memcpy(req + reqlen, "\"\r", 2);
2961 reqlen += 2; 3076 reqlen += 2;
2962 3077
2963 smprintf(s, "Writing phonebook entry\n"); 3078 smprintf(s, "Writing phonebook entry\n");
2964 return GSM_WaitFor (s, req, reqlen, 0x00, 4, ID_SetMemory); 3079 return GSM_WaitFor (s, req, reqlen, 0x00, 4, ID_SetMemory);
2965#undef REQUEST_SIZE 3080#undef REQUEST_SIZE
2966} 3081}
2967 3082
2968GSM_Error ATGEN_SetMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry) 3083GSM_Error ATGEN_SetMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
2969{ 3084{
2970 if (entry->Location == 0) return ERR_INVALIDLOCATION; 3085 if (entry->Location == 0) return ERR_INVALIDLOCATION;
2971 return ATGEN_PrivSetMemory(s, entry); 3086 return ATGEN_PrivSetMemory(s, entry);
2972} 3087}
2973 3088
2974GSM_Error ATGEN_AddMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry) 3089GSM_Error ATGEN_AddMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
2975{ 3090{
2976 GSM_Error error; 3091 GSM_Error error;
2977 GSM_MemoryStatusStatus; 3092 GSM_MemoryStatusStatus;
2978 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 3093 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
2979 3094
2980 /* Find out empty location */ 3095 /* Find out empty location */
2981 error = ATGEN_GetMemoryInfo(s, &Status, AT_NextEmpty); 3096 error = ATGEN_GetMemoryInfo(s, &Status, AT_NextEmpty);
2982 if (error != ERR_NONE) return error; 3097 if (error != ERR_NONE) return error;
2983 if (Priv->NextMemoryEntry == 0) return ERR_FULL; 3098 if (Priv->NextMemoryEntry == 0) return ERR_FULL;
2984 entry->Location = Priv->NextMemoryEntry; 3099 entry->Location = Priv->NextMemoryEntry;
2985 3100
2986 return ATGEN_PrivSetMemory(s, entry); 3101 return ATGEN_PrivSetMemory(s, entry);
2987} 3102}
2988 3103
2989/* Use ATGEN_ExtractOneParameter ?? */ 3104/* Use ATGEN_ExtractOneParameter ?? */
2990void Extract_CLIP_number(char *dest, char *buf) 3105void Extract_CLIP_number(char *dest, char *buf)
2991{ 3106{
2992 char *start, *stop; 3107 char *start, *stop;
2993 int i = 0; 3108 int i = 0;
2994 3109
2995 stop = strstr(buf, ","); 3110 stop = strstr(buf, ",");
2996 if (stop != NULL) { 3111 if (stop != NULL) {
2997 start = strstr(buf, ":"); 3112 start = strstr(buf, ":");
2998 if (start != NULL) { 3113 if (start != NULL) {
2999 for (start = start + 2; start + i < stop; i++) 3114 for (start = start + 2; start + i < stop; i++)
3000 dest[i] = start[i]; 3115 dest[i] = start[i];
3001 } 3116 }
3002 } 3117 }
3003 dest[i] = 0; /* end the number */ 3118 dest[i] = 0; /* end the number */
3004 3119
3005 return; 3120 return;
3006} 3121}
3007 3122
3008GSM_Error ATGEN_ReplyIncomingCallInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 3123GSM_Error ATGEN_ReplyIncomingCallInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
3009{ 3124{
3010 char num[128]; 3125 char num[128];
3011 GSM_Call call; 3126 GSM_Call call;
3012 3127
3013 smprintf(s, "Incoming call info\n"); 3128 smprintf(s, "Incoming call info\n");
3014 if (s->Phone.Data.EnableIncomingCall && s->User.IncomingCall!=NULL) { 3129 if (s->Phone.Data.EnableIncomingCall && s->User.IncomingCall!=NULL) {
3015 call.CallIDAvailable = false; 3130 call.CallIDAvailable = false;
3016 num[0] = 0; 3131 num[0] = 0;
3017 if (strstr(msg.Buffer, "RING")) { 3132 if (strstr(msg.Buffer, "RING")) {
3018 call.Status = GSM_CALL_IncomingCall; 3133 call.Status = GSM_CALL_IncomingCall;
3019 Extract_CLIP_number(num, msg.Buffer); 3134 Extract_CLIP_number(num, msg.Buffer);
3020 } else if (strstr(msg.Buffer, "NO CARRIER")) { 3135 } else if (strstr(msg.Buffer, "NO CARRIER")) {
3021 call.Status = GSM_CALL_CallEnd; 3136 call.Status = GSM_CALL_CallEnd;
3022 } else if (strstr(msg.Buffer, "COLP:")) { 3137 } else if (strstr(msg.Buffer, "COLP:")) {
3023 call.Status = GSM_CALL_CallStart; 3138 call.Status = GSM_CALL_CallStart;
3024 Extract_CLIP_number(num, msg.Buffer); 3139 Extract_CLIP_number(num, msg.Buffer);
3025 } else { 3140 } else {
3026 smprintf(s, "CLIP: error\n"); 3141 smprintf(s, "CLIP: error\n");
3027 return ERR_NONE; 3142 return ERR_NONE;
3028 } 3143 }
3029 EncodeUnicode(call.PhoneNumber, num, strlen(num)); 3144 EncodeUnicode(call.PhoneNumber, num, strlen(num));
3030 3145
3031 s->User.IncomingCall(s->CurrentConfig->Device, call); 3146 s->User.IncomingCall(s->CurrentConfig->Device, call);
3032 } 3147 }
3033 3148
3034 return ERR_NONE; 3149 return ERR_NONE;
3035} 3150}
3036 3151
3037GSM_Error ATGEN_IncomingGPRS(GSM_Protocol_Message msg, GSM_StateMachine *s) 3152GSM_Error ATGEN_IncomingGPRS(GSM_Protocol_Message msg, GSM_StateMachine *s)
3038{ 3153{
3039 /* "+CGREG: 1,1" */ 3154 /* "+CGREG: 1,1" */
3040 smprintf(s, "GPRS change\n"); 3155 smprintf(s, "GPRS change\n");
3041 return ERR_NONE; 3156 return ERR_NONE;
3042} 3157}
3043 3158
3044GSM_Error ATGEN_IncomingBattery(GSM_Protocol_Message msg, GSM_StateMachine *s) 3159GSM_Error ATGEN_IncomingBattery(GSM_Protocol_Message msg, GSM_StateMachine *s)
3045{ 3160{
3046 int level = 0; 3161 int level = 0;
3047 char *p; 3162 char *p;
3048 3163
3049 /* "_OBS: 92,1" */ 3164 /* "_OBS: 92,1" */
3050 p = strstr(msg.Buffer, "_OBS:"); 3165 p = strstr(msg.Buffer, "_OBS:");
3051 if (p) level = atoi(p + 5); 3166 if (p) level = atoi(p + 5);
3052 smprintf(s, "Battery level changed to %d\n", level); 3167 smprintf(s, "Battery level changed to %d\n", level);
3053 return ERR_NONE; 3168 return ERR_NONE;
3054} 3169}
3055 3170
3056GSM_Error ATGEN_IncomingNetworkLevel(GSM_Protocol_Message msg, GSM_StateMachine *s) 3171GSM_Error ATGEN_IncomingNetworkLevel(GSM_Protocol_Message msg, GSM_StateMachine *s)
3057{ 3172{
3058 int level = 0; 3173 int level = 0;
3059 char *p; 3174 char *p;
3060 3175
3061 /* "_OSIGQ: 12,0" */ 3176 /* "_OSIGQ: 12,0" */
3062 p = strstr(msg.Buffer, "_OSIGQ: "); 3177 p = strstr(msg.Buffer, "_OSIGQ: ");
3063 if (p) level = atoi(p + 7); 3178 if (p) level = atoi(p + 7);
3064 smprintf(s, "Network level changed to %d\n", level); 3179 smprintf(s, "Network level changed to %d\n", level);
3065 return ERR_NONE; 3180 return ERR_NONE;
3066} 3181}
3067 3182
3068GSM_Error ATGEN_ReplyGetSIMIMSI(GSM_Protocol_Message msg, GSM_StateMachine *s) 3183GSM_Error ATGEN_ReplyGetSIMIMSI(GSM_Protocol_Message msg, GSM_StateMachine *s)
3069{ 3184{
3070 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 3185 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
3071 GSM_Phone_Data *Data = &s->Phone.Data; 3186 GSM_Phone_Data *Data = &s->Phone.Data;
3072 char *c; 3187 char *c;
3073 3188
3074 switch (Priv->ReplyState) { 3189 switch (Priv->ReplyState) {
3075 case AT_Reply_OK: 3190 case AT_Reply_OK:
3076 CopyLineString(Data->PhoneString, msg.Buffer, Priv->Lines, 2); 3191 CopyLineString(Data->PhoneString, msg.Buffer, Priv->Lines, 2);
3077 3192
3078 /* Read just IMSI also on phones that prepend it by "<IMSI>:" (Alcatel BE5) */ 3193 /* Read just IMSI also on phones that prepend it by "<IMSI>:" (Alcatel BE5) */
3079 c = strstr(Data->PhoneString, "<IMSI>:"); 3194 c = strstr(Data->PhoneString, "<IMSI>:");
3080 if (c != NULL) { 3195 if (c != NULL) {
3081 c += 7; 3196 c += 7;
3082 memmove(Data->PhoneString, c, strlen(c) + 1); 3197 memmove(Data->PhoneString, c, strlen(c) + 1);
3083 } 3198 }
3084 3199
3085 smprintf(s, "Received IMSI %s\n",Data->PhoneString); 3200 smprintf(s, "Received IMSI %s\n",Data->PhoneString);
3086 return ERR_NONE; 3201 return ERR_NONE;
3087 case AT_Reply_Error: 3202 case AT_Reply_Error:
3088 smprintf(s, "No access to SIM card or not supported by device\n"); 3203 smprintf(s, "No access to SIM card or not supported by device\n");
3089 return ERR_SECURITYERROR; 3204 return ERR_SECURITYERROR;
3090 case AT_Reply_CMEError: 3205 case AT_Reply_CMEError:
3091 return ATGEN_HandleCMEError(s); 3206 return ATGEN_HandleCMEError(s);
3092 case AT_Reply_CMSError: 3207 case AT_Reply_CMSError:
3093 return ATGEN_HandleCMSError(s); 3208 return ATGEN_HandleCMSError(s);
3094 default: 3209 default:
3095 break; 3210 break;
3096 } 3211 }
3097 return ERR_UNKNOWNRESPONSE; 3212 return ERR_UNKNOWNRESPONSE;
3098} 3213}
3099 3214
3100GSM_Error ATGEN_GetSIMIMSI(GSM_StateMachine *s, char *IMSI) 3215GSM_Error ATGEN_GetSIMIMSI(GSM_StateMachine *s, char *IMSI)
3101{ 3216{
3102 s->Phone.Data.PhoneString = IMSI; 3217 s->Phone.Data.PhoneString = IMSI;
3103 smprintf(s, "Getting SIM IMSI\n"); 3218 smprintf(s, "Getting SIM IMSI\n");
3104 return GSM_WaitFor (s, "AT+CIMI\r", 8, 0x00, 4, ID_GetSIMIMSI); 3219 return GSM_WaitFor (s, "AT+CIMI\r", 8, 0x00, 4, ID_GetSIMIMSI);
3105} 3220}
3106 3221
3107GSM_Error ATGEN_GetDisplayStatus(GSM_StateMachine *s, GSM_DisplayFeatures *features) 3222GSM_Error ATGEN_GetDisplayStatus(GSM_StateMachine *s, GSM_DisplayFeatures *features)
3108{ 3223{
3109 return ERR_NOTSUPPORTED; 3224 return ERR_NOTSUPPORTED;
3110 3225
3111 s->Phone.Data.DisplayFeatures = features; 3226 s->Phone.Data.DisplayFeatures = features;
3112 smprintf(s, "Getting display status\n"); 3227 smprintf(s, "Getting display status\n");
3113 return GSM_WaitFor (s, "AT+CIND?\r",9, 0x00, 4, ID_GetDisplayStatus); 3228 return GSM_WaitFor (s, "AT+CIND?\r",9, 0x00, 4, ID_GetDisplayStatus);
3114} 3229}
3115 3230
3116GSM_Error ATGEN_IncomingSMSCInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 3231GSM_Error ATGEN_IncomingSMSCInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
3117{ 3232{
3118 return ERR_NONE; 3233 return ERR_NONE;
3119} 3234}
3120 3235
3121GSM_Error ATGEN_ReplyGetBatteryCharge(GSM_Protocol_Message msg, GSM_StateMachine *s) 3236GSM_Error ATGEN_ReplyGetBatteryCharge(GSM_Protocol_Message msg, GSM_StateMachine *s)
3122{ 3237{
3123 GSM_Phone_Data *Data = &s->Phone.Data; 3238 GSM_Phone_Data *Data = &s->Phone.Data;
3124 int i; 3239 int i;
3125 3240
3126 Data->BatteryCharge->BatteryPercent = -1; 3241 Data->BatteryCharge->BatteryPercent = -1;
3127 Data->BatteryCharge->ChargeState = 0; 3242 Data->BatteryCharge->ChargeState = 0;
3128 3243
3129 switch (s->Phone.Data.Priv.ATGEN.ReplyState) { 3244 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
3130 case AT_Reply_OK: 3245 case AT_Reply_OK:
3131 smprintf(s, "Battery level received\n"); 3246 smprintf(s, "Battery level received\n");
3132 Data->BatteryCharge->BatteryPercent = atoi(msg.Buffer+17); 3247 Data->BatteryCharge->BatteryPercent = atoi(msg.Buffer+17);
3133 i = atoi(msg.Buffer+14); 3248 i = atoi(msg.Buffer+14);
3134 if (i >= 0 && i <= 3) { 3249 if (i >= 0 && i <= 3) {
3135 Data->BatteryCharge->ChargeState = i + 1; 3250 Data->BatteryCharge->ChargeState = i + 1;
3136 } 3251 }
3137 return ERR_NONE; 3252 return ERR_NONE;
3138 case AT_Reply_Error: 3253 case AT_Reply_Error:
3139 smprintf(s, "Can't get battery level\n"); 3254 smprintf(s, "Can't get battery level\n");
3140 return ERR_UNKNOWN; 3255 return ERR_UNKNOWN;
3141 case AT_Reply_CMSError: 3256 case AT_Reply_CMSError:
3142 smprintf(s, "Can't get battery level\n"); 3257 smprintf(s, "Can't get battery level\n");
3143 return ATGEN_HandleCMSError(s); 3258 return ATGEN_HandleCMSError(s);
3144 default: 3259 default:
3145 break; 3260 break;
3146 } 3261 }
3147 return ERR_UNKNOWNRESPONSE; 3262 return ERR_UNKNOWNRESPONSE;
3148} 3263}
3149 3264
3150GSM_Error ATGEN_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat) 3265GSM_Error ATGEN_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat)
3151{ 3266{
3152 s->Phone.Data.BatteryCharge = bat; 3267 s->Phone.Data.BatteryCharge = bat;
3153 smprintf(s, "Getting battery charge\n"); 3268 smprintf(s, "Getting battery charge\n");
3154 return GSM_WaitFor (s, "AT+CBC\r", 7, 0x00, 4, ID_GetBatteryCharge); 3269 return GSM_WaitFor (s, "AT+CBC\r", 7, 0x00, 4, ID_GetBatteryCharge);
3155} 3270}
3156 3271
3157GSM_Error ATGEN_ReplyGetSignalQuality(GSM_Protocol_Message msg, GSM_StateMachine *s) 3272GSM_Error ATGEN_ReplyGetSignalQuality(GSM_Protocol_Message msg, GSM_StateMachine *s)
3158{ 3273{
3159 GSM_SignalQuality*Signal = s->Phone.Data.SignalQuality; 3274 GSM_SignalQuality*Signal = s->Phone.Data.SignalQuality;
3160 int i; 3275 int i;
3161 char *pos; 3276 char *pos;
3162 3277
3163 Signal->SignalStrength = -1; 3278 Signal->SignalStrength = -1;
3164 Signal->SignalPercent = -1; 3279 Signal->SignalPercent = -1;
3165 Signal->BitErrorRate = -1; 3280 Signal->BitErrorRate = -1;
3166 3281
3167 switch (s->Phone.Data.Priv.ATGEN.ReplyState) { 3282 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
3168 case AT_Reply_OK: 3283 case AT_Reply_OK:
3169 smprintf(s, "Signal quality info received\n"); 3284 smprintf(s, "Signal quality info received\n");
3170 i = atoi(msg.Buffer+15); 3285 i = atoi(msg.Buffer+15);
3171 if (i != 99) { 3286 if (i != 99) {
3172 /* from GSM 07.07 section 8.5 */ 3287 /* from GSM 07.07 section 8.5 */
3173 Signal->SignalStrength = 2 * i - 113; 3288 Signal->SignalStrength = 2 * i - 113;
3174 3289
3175 /* FIXME: this is wild guess and probably will be phone dependant */ 3290 /* FIXME: this is wild guess and probably will be phone dependant */
3176 Signal->SignalPercent = 15 * i; 3291 Signal->SignalPercent = 15 * i;
3177 if (Signal->SignalPercent > 100) Signal->SignalPercent = 100; 3292 if (Signal->SignalPercent > 100) Signal->SignalPercent = 100;
3178 } 3293 }
3179 pos = strchr(msg.Buffer + 15, ','); 3294 pos = strchr(msg.Buffer + 15, ',');
3180 if (pos != NULL) { 3295 if (pos != NULL) {
3181 i = atoi(pos + 1); 3296 i = atoi(pos + 1);
3182 /* from GSM 05.08 section 8.2.4 */ 3297 /* from GSM 05.08 section 8.2.4 */
3183 switch (i) { 3298 switch (i) {
3184 case 0: Signal->BitErrorRate = 0; break; /* 0.14 */ 3299 case 0: Signal->BitErrorRate = 0; break; /* 0.14 */
3185 case 1: Signal->BitErrorRate = 0; break; /* 0.28 */ 3300 case 1: Signal->BitErrorRate = 0; break; /* 0.28 */
3186 case 2: Signal->BitErrorRate = 1; break; /* 0.57 */ 3301 case 2: Signal->BitErrorRate = 1; break; /* 0.57 */
3187 case 3: Signal->BitErrorRate = 1; break; /* 1.13 */ 3302 case 3: Signal->BitErrorRate = 1; break; /* 1.13 */
3188 case 4: Signal->BitErrorRate = 2; break; /* 2.26 */ 3303 case 4: Signal->BitErrorRate = 2; break; /* 2.26 */
3189 case 5: Signal->BitErrorRate = 5; break; /* 4.53 */ 3304 case 5: Signal->BitErrorRate = 5; break; /* 4.53 */
3190 case 6: Signal->BitErrorRate = 9; break; /* 9.05 */ 3305 case 6: Signal->BitErrorRate = 9; break; /* 9.05 */
3191 case 7: Signal->BitErrorRate = 18; break; /* 18.10 */ 3306 case 7: Signal->BitErrorRate = 18; break; /* 18.10 */
3192 } 3307 }
3193 } 3308 }
3194 return ERR_NONE; 3309 return ERR_NONE;
3195 case AT_Reply_CMSError: 3310 case AT_Reply_CMSError:
3196 return ATGEN_HandleCMSError(s); 3311 return ATGEN_HandleCMSError(s);
3197 default: 3312 default:
3198 break; 3313 break;
3199 } 3314 }
3200 return ERR_UNKNOWNRESPONSE; 3315 return ERR_UNKNOWNRESPONSE;
3201} 3316}
3202 3317
3203GSM_Error ATGEN_GetSignalQuality(GSM_StateMachine *s, GSM_SignalQuality *sig) 3318GSM_Error ATGEN_GetSignalQuality(GSM_StateMachine *s, GSM_SignalQuality *sig)
3204{ 3319{
3205 s->Phone.Data.SignalQuality = sig; 3320 s->Phone.Data.SignalQuality = sig;
3206 smprintf(s, "Getting signal quality info\n"); 3321 smprintf(s, "Getting signal quality info\n");
3207 return GSM_WaitFor (s, "AT+CSQ\r", 7, 0x00, 4, ID_GetSignalQuality); 3322 return GSM_WaitFor (s, "AT+CSQ\r", 7, 0x00, 4, ID_GetSignalQuality);
3208} 3323}
3209 3324
3210/* When use AT+CPIN?, A2D returns it without OK and because of it Gammu 3325/* When use AT+CPIN?, A2D returns it without OK and because of it Gammu
3211 parses answer without it. 3326 parses answer without it.
3212 MC35 and other return OK after answer for AT+CPIN?. Here we handle it. 3327 MC35 and other return OK after answer for AT+CPIN?. Here we handle it.
3213 Any better idea ? 3328 Any better idea ?
3214 */ 3329 */
3215GSM_Error ATGEN_ReplyOK(GSM_Protocol_Message msg, GSM_StateMachine *s) 3330GSM_Error ATGEN_ReplyOK(GSM_Protocol_Message msg, GSM_StateMachine *s)
3216{ 3331{
3217 return ERR_NONE; 3332 return ERR_NONE;
3218} 3333}
3219 3334
3220static GSM_Error ATGEN_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start) 3335static GSM_Error ATGEN_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start)
3221{ 3336{
3222 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 3337 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
3223 3338
3224 if (Priv->Manufacturer==AT_Siemens ) return SIEMENS_GetNextCalendar(s,Note,start); 3339 if (Priv->Manufacturer==AT_Siemens ) return SIEMENS_GetNextCalendar(s,Note,start);
3225 if (Priv->Manufacturer==AT_Ericsson) return SONYERIC_GetNextCalendar(s,Note,start); 3340 if (Priv->Manufacturer==AT_Ericsson) return SONYERIC_GetNextCalendar(s,Note,start);
3226 return ERR_NOTSUPPORTED; 3341 return ERR_NOTSUPPORTED;
3227} 3342}
3228 3343
3229GSM_Error ATGEN_Terminate(GSM_StateMachine *s) 3344GSM_Error ATGEN_Terminate(GSM_StateMachine *s)
3230{ 3345{
3231 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 3346 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
3232 3347
3233 free(Priv->file.Buffer); 3348 free(Priv->file.Buffer);
3234 return ERR_NONE; 3349 return ERR_NONE;
3235} 3350}
3236 3351
3237GSM_Error ATGEN_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note) 3352GSM_Error ATGEN_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note)
3238{ 3353{
3239 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 3354 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
3240 3355
3241 if (Priv->Manufacturer==AT_Siemens) return SIEMENS_AddCalendarNote(s, Note); 3356 if (Priv->Manufacturer==AT_Siemens) return SIEMENS_AddCalendarNote(s, Note);
3242 if (Priv->Manufacturer==AT_Ericsson) return SONYERIC_AddCalendarNote(s, Note); 3357 if (Priv->Manufacturer==AT_Ericsson) return SONYERIC_AddCalendarNote(s, Note);
3243 return ERR_NOTSUPPORTED; 3358 return ERR_NOTSUPPORTED;
3244} 3359}
3245 3360
3246GSM_Error ATGEN_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note) 3361GSM_Error ATGEN_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note)
3247{ 3362{
3248 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 3363 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
3249 3364
3250 if (Priv->Manufacturer==AT_Siemens) return SIEMENS_DelCalendarNote(s, Note); 3365 if (Priv->Manufacturer==AT_Siemens) return SIEMENS_DelCalendarNote(s, Note);
3251 if (Priv->Manufacturer==AT_Ericsson) return SONYERIC_DelCalendarNote(s, Note); 3366 if (Priv->Manufacturer==AT_Ericsson) return SONYERIC_DelCalendarNote(s, Note);
3252 return ERR_NOTSUPPORTED; 3367 return ERR_NOTSUPPORTED;
3253} 3368}
3254 3369
3370
3371GSM_Error ATGEN_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
3372{
3373 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
3374
3375 if (Priv->Manufacturer==AT_Siemens) return SIEMENS_GetBitmap(s, Bitmap);
3376 if (Priv->Manufacturer==AT_Samsung) return SAMSUNG_GetBitmap(s, Bitmap);
3377 return ERR_NOTSUPPORTED;
3378}
3379
3380GSM_Error ATGEN_SetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
3381{
3382 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
3383
3384 if (Priv->Manufacturer==AT_Siemens) return SIEMENS_SetBitmap(s, Bitmap);
3385 if (Priv->Manufacturer==AT_Samsung) return SAMSUNG_SetBitmap(s, Bitmap);
3386 return ERR_NOTSUPPORTED;
3387}
3388
3389GSM_Error ATGEN_GetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone)
3390{
3391 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
3392
3393 if (Priv->Manufacturer==AT_Siemens) return SIEMENS_GetRingtone(s, Ringtone, PhoneRingtone);
3394 if (Priv->Manufacturer==AT_Samsung) return SAMSUNG_GetRingtone(s, Ringtone, PhoneRingtone);
3395 return ERR_NOTSUPPORTED;
3396}
3397
3398GSM_Error ATGEN_SetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength)
3399{
3400 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
3401
3402 if (Priv->Manufacturer==AT_Siemens) return SIEMENS_SetRingtone(s, Ringtone, maxlength);
3403 if (Priv->Manufacturer==AT_Samsung) return SAMSUNG_SetRingtone(s, Ringtone, maxlength);
3404 return ERR_NOTSUPPORTED;
3405}
3406
3255GSM_Error ATGEN_PressKey(GSM_StateMachine *s, GSM_KeyCode Key, bool Press) 3407GSM_Error ATGEN_PressKey(GSM_StateMachine *s, GSM_KeyCode Key, bool Press)
3256{ 3408{
3257 GSM_Errorerror; 3409 GSM_Errorerror;
3258 unsigned char Frame[] = "AT+CKPD=\"?\"\r"; 3410 unsigned char Frame[] = "AT+CKPD=\"?\"\r";
3259 3411
3260 if (Press) { 3412 if (Press) {
3261 switch (Key) { 3413 switch (Key) {
3262 case GSM_KEY_1 : Frame[9] = '1'; break; 3414 case GSM_KEY_1 : Frame[9] = '1'; break;
3263 case GSM_KEY_2 : Frame[9] = '2'; break; 3415 case GSM_KEY_2 : Frame[9] = '2'; break;
3264 case GSM_KEY_3 : Frame[9] = '3'; break; 3416 case GSM_KEY_3 : Frame[9] = '3'; break;
3265 case GSM_KEY_4 : Frame[9] = '4'; break; 3417 case GSM_KEY_4 : Frame[9] = '4'; break;
3266 case GSM_KEY_5 : Frame[9] = '5'; break; 3418 case GSM_KEY_5 : Frame[9] = '5'; break;
3267 case GSM_KEY_6 : Frame[9] = '6'; break; 3419 case GSM_KEY_6 : Frame[9] = '6'; break;
3268 case GSM_KEY_7 : Frame[9] = '7'; break; 3420 case GSM_KEY_7 : Frame[9] = '7'; break;
3269 case GSM_KEY_8 : Frame[9] = '8'; break; 3421 case GSM_KEY_8 : Frame[9] = '8'; break;
3270 case GSM_KEY_9 : Frame[9] = '9'; break; 3422 case GSM_KEY_9 : Frame[9] = '9'; break;
3271 case GSM_KEY_0 : Frame[9] = '0'; break; 3423 case GSM_KEY_0 : Frame[9] = '0'; break;
3272 case GSM_KEY_HASH : Frame[9] = '#'; break; 3424 case GSM_KEY_HASH : Frame[9] = '#'; break;
3273 case GSM_KEY_ASTERISK : Frame[9] = '*'; break; 3425 case GSM_KEY_ASTERISK : Frame[9] = '*'; break;
3274 case GSM_KEY_POWER : return ERR_NOTSUPPORTED; 3426 case GSM_KEY_POWER : return ERR_NOTSUPPORTED;
3275 case GSM_KEY_GREEN : Frame[9] = 'S'; break; 3427 case GSM_KEY_GREEN : Frame[9] = 'S'; break;
3276 case GSM_KEY_RED : Frame[9] = 'E'; break; 3428 case GSM_KEY_RED : Frame[9] = 'E'; break;
3277 case GSM_KEY_INCREASEVOLUME: Frame[9] = 'U'; break; 3429 case GSM_KEY_INCREASEVOLUME: Frame[9] = 'U'; break;
3278 case GSM_KEY_DECREASEVOLUME: Frame[9] = 'D'; break; 3430 case GSM_KEY_DECREASEVOLUME: Frame[9] = 'D'; break;
3279 case GSM_KEY_UP : Frame[9] = '^'; break; 3431 case GSM_KEY_UP : Frame[9] = '^'; break;
3280 case GSM_KEY_DOWN : Frame[9] = 'V'; break; 3432 case GSM_KEY_DOWN : Frame[9] = 'V'; break;
3281 case GSM_KEY_MENU : Frame[9] = 'F'; break; 3433 case GSM_KEY_MENU : Frame[9] = 'F'; break;
3282 case GSM_KEY_NAMES : Frame[9] = 'C'; break; 3434 case GSM_KEY_NAMES : Frame[9] = 'C'; break;
3283 default : return ERR_NOTSUPPORTED; 3435 default : return ERR_NOTSUPPORTED;
3284 } 3436 }
3285 smprintf(s, "Pressing key\n"); 3437 smprintf(s, "Pressing key\n");
3286 error = GSM_WaitFor (s, Frame, 12, 0x00, 4, ID_PressKey); 3438 error = GSM_WaitFor (s, Frame, 12, 0x00, 4, ID_PressKey);
3287 if (error != ERR_NONE) return error; 3439 if (error != ERR_NONE) return error;
3288 3440
3289 /* Strange. My T310 needs it */ 3441 /* Strange. My T310 needs it */
3290 return GSM_WaitFor (s, "ATE1\r", 5, 0x00, 4, ID_EnableEcho); 3442 return GSM_WaitFor (s, "ATE1\r", 5, 0x00, 4, ID_EnableEcho);
3291 } else { 3443 } else {
3292 return ERR_NONE; 3444 return ERR_NONE;
3293 } 3445 }
3294} 3446}
3295 3447
3296#ifdef GSM_ENABLE_CELLBROADCAST 3448#ifdef GSM_ENABLE_CELLBROADCAST
3297 3449
3298GSM_Error ATGEN_ReplyIncomingCB(GSM_Protocol_Message msg, GSM_StateMachine *s) 3450GSM_Error ATGEN_ReplyIncomingCB(GSM_Protocol_Message msg, GSM_StateMachine *s)
3299{ 3451{
3300 GSM_CBMessage CB; 3452 GSM_CBMessage CB;
3301 int i,j; 3453 int i,j;
3302 char Buffer[300],Buffer2[300]; 3454 char Buffer[300],Buffer2[300];
3303 3455
3304 smprintf(s, "CB received\n"); 3456 smprintf(s, "CB received\n");
3305 return ERR_NONE; 3457 return ERR_NONE;
3306 3458
3307 DecodeHexBin (Buffer,msg.Buffer+6,msg.Length-6); 3459 DecodeHexBin (Buffer,msg.Buffer+6,msg.Length-6);
3308 DumpMessage(stdout, di.dl ,Buffer,msg.Length-6); 3460 DumpMessage(stdout, di.dl ,Buffer,msg.Length-6);
3309 3461
3310 CB.Channel = Buffer[4]; 3462 CB.Channel = Buffer[4];
3311 3463
3312 for (j=0;j<msg.Length;j++) { 3464 for (j=0;j<msg.Length;j++) {
3313 smprintf(s, "j=%i\n",j); 3465 smprintf(s, "j=%i\n",j);
3314 i=GSM_UnpackEightBitsToSeven(0, msg.Buffer[6], msg.Buffer[6], msg.Buffer+j, Buffer2); 3466 i=GSM_UnpackEightBitsToSeven(0, msg.Buffer[6], msg.Buffer[6], msg.Buffer+j, Buffer2);
3315 //i = msg.Buffer[6] - 1; 3467 //i = msg.Buffer[6] - 1;
3316 //while (i!=0) { 3468 //while (i!=0) {
3317 // if (Buffer[i] == 13) i = i - 1; else break; 3469 // if (Buffer[i] == 13) i = i - 1; else break;
3318 //} 3470 //}
3319 DecodeDefault(CB.Text, Buffer2, msg.Buffer[6], false, NULL); 3471 DecodeDefault(CB.Text, Buffer2, msg.Buffer[6], false, NULL);
3320 smprintf(s, "Channel %i, text \"%s\"\n",CB.Channel,DecodeUnicodeString(CB.Text)); 3472 smprintf(s, "Channel %i, text \"%s\"\n",CB.Channel,DecodeUnicodeString(CB.Text));
3321 } 3473 }
3322 if (s->Phone.Data.EnableIncomingCB && s->User.IncomingCB!=NULL) { 3474 if (s->Phone.Data.EnableIncomingCB && s->User.IncomingCB!=NULL) {
3323 s->User.IncomingCB(s->CurrentConfig->Device,CB); 3475 s->User.IncomingCB(s->CurrentConfig->Device,CB);
3324 } 3476 }
3325 return ERR_NONE; 3477 return ERR_NONE;
3326} 3478}
3327 3479
3328#endif 3480#endif
3329 3481
3330GSM_Error ATGEN_SetIncomingCB(GSM_StateMachine *s, bool enable) 3482GSM_Error ATGEN_SetIncomingCB(GSM_StateMachine *s, bool enable)
3331{ 3483{
3332#ifdef GSM_ENABLE_CELLBROADCAST 3484#ifdef GSM_ENABLE_CELLBROADCAST
3333 if (s->Phone.Data.EnableIncomingCB!=enable) { 3485 if (s->Phone.Data.EnableIncomingCB!=enable) {
3334 s->Phone.Data.EnableIncomingCB = enable; 3486 s->Phone.Data.EnableIncomingCB = enable;
3335 if (enable) { 3487 if (enable) {
3336 smprintf(s, "Enabling incoming CB\n"); 3488 smprintf(s, "Enabling incoming CB\n");
3337 return GSM_WaitFor(s, "AT+CNMI=3,,2\r", 13, 0x00, 4, ID_SetIncomingCB); 3489 return GSM_WaitFor(s, "AT+CNMI=3,,2\r", 13, 0x00, 4, ID_SetIncomingCB);
3338 } else { 3490 } else {
3339 smprintf(s, "Disabling incoming CB\n"); 3491 smprintf(s, "Disabling incoming CB\n");
3340 return GSM_WaitFor(s, "AT+CNMI=3,,0\r", 13, 0x00, 4, ID_SetIncomingCB); 3492 return GSM_WaitFor(s, "AT+CNMI=3,,0\r", 13, 0x00, 4, ID_SetIncomingCB);
3341 } 3493 }
3342 } 3494 }
3343 return ERR_NONE; 3495 return ERR_NONE;
3344#else 3496#else
3345 return ERR_SOURCENOTAVAILABLE; 3497 return ERR_SOURCENOTAVAILABLE;
3346#endif 3498#endif
3347} 3499}
3348 3500
3501GSM_Error ATGEN_SetFastSMSSending(GSM_StateMachine *s, bool enable)
3502{
3503 if (enable) {
3504 smprintf(s, "Enabling fast SMS sending\n");
3505 return GSM_WaitFor(s, "AT+CMMS=2\r", 10, 0x00, 4, ID_SetFastSMSSending);
3506 } else {
3507 smprintf(s, "Disabling fast SMS sending\n");
3508 return GSM_WaitFor(s, "AT+CMMS=0\r", 10, 0x00, 4, ID_SetFastSMSSending);
3509 }
3510}
3511
3349GSM_Error ATGEN_IncomingSMSInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 3512GSM_Error ATGEN_IncomingSMSInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
3350{ 3513{
3351 smprintf(s, "Incoming SMS\n"); 3514 smprintf(s, "Incoming SMS\n");
3352 return ERR_NONE; 3515 return ERR_NONE;
3353} 3516}
3354 3517
3355GSM_Error ATGEN_IncomingSMSDeliver(GSM_Protocol_Message msg, GSM_StateMachine *s) 3518GSM_Error ATGEN_IncomingSMSDeliver(GSM_Protocol_Message msg, GSM_StateMachine *s)
3356{ 3519{
3357 GSM_Phone_Data *Data = &s->Phone.Data; 3520 GSM_Phone_Data *Data = &s->Phone.Data;
3358 GSM_SMSMessage sms; 3521 GSM_SMSMessage sms;
3359 int current = 0, current2, i=0; 3522 int current = 0, current2, i=0;
3360 unsigned char buffer[300],smsframe[800]; 3523 unsigned char buffer[300],smsframe[800];
3361 3524
3362 smprintf(s, "Incoming SMS received (Deliver)\n"); 3525 smprintf(s, "Incoming SMS received (Deliver)\n");
3363 if (Data->EnableIncomingSMS && s->User.IncomingSMS!=NULL) { 3526 if (Data->EnableIncomingSMS && s->User.IncomingSMS!=NULL) {
3364 sms.State = SMS_UnRead; 3527 sms.State = SMS_UnRead;
3365 sms.InboxFolder = true; 3528 sms.InboxFolder = true;
3366 sms.PDU = SMS_Deliver; 3529 sms.PDU = SMS_Deliver;
3367 3530
3368 /* T310 with larger SMS goes crazy and mix this incoming 3531 /* T310 with larger SMS goes crazy and mix this incoming
3369 * frame with normal answers. PDU is always last frame 3532 * frame with normal answers. PDU is always last frame
3370 * We find its' number and parse it */ 3533 * We find its' number and parse it */
3371 while (Data->Priv.ATGEN.Lines.numbers[i*2+1] != 0) { 3534 while (Data->Priv.ATGEN.Lines.numbers[i*2+1] != 0) {
3372 /* FIXME: handle special chars correctly */ 3535 /* FIXME: handle special chars correctly */
3373 i++; 3536 i++;
3374 } 3537 }
3375 DecodeHexBin (buffer, 3538 DecodeHexBin (buffer,
3376 GetLineString(msg.Buffer,Data->Priv.ATGEN.Lines,i), 3539 GetLineString(msg.Buffer,Data->Priv.ATGEN.Lines,i),
3377 strlen(GetLineString(msg.Buffer,Data->Priv.ATGEN.Lines,i))); 3540 strlen(GetLineString(msg.Buffer,Data->Priv.ATGEN.Lines,i)));
3378 3541
3379 /* We use locations from SMS layouts like in ../phone2.c(h) */ 3542 /* We use locations from SMS layouts like in ../phone2.c(h) */
3380 for(i=0;i<buffer[0]+1;i++) smsframe[i]=buffer[current++]; 3543 for(i=0;i<buffer[0]+1;i++) smsframe[i]=buffer[current++];
3381 smsframe[12]=buffer[current++]; 3544 smsframe[12]=buffer[current++];
3382 3545
3383 current2=((buffer[current])+1)/2+1; 3546 current2=((buffer[current])+1)/2+1;
3384 for(i=0;i<current2+1;i++) smsframe[PHONE_SMSDeliver.Number+i]=buffer[current++]; 3547 for(i=0;i<current2+1;i++) smsframe[PHONE_SMSDeliver.Number+i]=buffer[current++];
3385 smsframe[PHONE_SMSDeliver.TPPID] = buffer[current++]; 3548 smsframe[PHONE_SMSDeliver.TPPID] = buffer[current++];
3386 smsframe[PHONE_SMSDeliver.TPDCS] = buffer[current++]; 3549 smsframe[PHONE_SMSDeliver.TPDCS] = buffer[current++];
3387 for(i=0;i<7;i++) smsframe[PHONE_SMSDeliver.DateTime+i]=buffer[current++]; 3550 for(i=0;i<7;i++) smsframe[PHONE_SMSDeliver.DateTime+i]=buffer[current++];
3388 smsframe[PHONE_SMSDeliver.TPUDL] = buffer[current++]; 3551 smsframe[PHONE_SMSDeliver.TPUDL] = buffer[current++];
3389 for(i=0;i<smsframe[PHONE_SMSDeliver.TPUDL];i++) smsframe[i+PHONE_SMSDeliver.Text]=buffer[current++]; 3552 for(i=0;i<smsframe[PHONE_SMSDeliver.TPUDL];i++) smsframe[i+PHONE_SMSDeliver.Text]=buffer[current++];
3390 GSM_DecodeSMSFrame(&sms,smsframe,PHONE_SMSDeliver); 3553 GSM_DecodeSMSFrame(&sms,smsframe,PHONE_SMSDeliver);
3391 3554
3392 s->User.IncomingSMS(s->CurrentConfig->Device,sms); 3555 s->User.IncomingSMS(s->CurrentConfig->Device,sms);
3393 } 3556 }
3394 return ERR_NONE; 3557 return ERR_NONE;
3395} 3558}
3396 3559
3397/* I don't have phone able to do it and can't fill it */ 3560/* I don't have phone able to do it and can't fill it */
3398GSM_Error ATGEN_IncomingSMSReport(GSM_Protocol_Message msg, GSM_StateMachine *s) 3561GSM_Error ATGEN_IncomingSMSReport(GSM_Protocol_Message msg, GSM_StateMachine *s)
3399{ 3562{
3400 smprintf(s, "Incoming SMS received (Report)\n"); 3563 smprintf(s, "Incoming SMS received (Report)\n");
3401 return ERR_NONE; 3564 return ERR_NONE;
3402} 3565}
3403 3566
3404GSM_Error ATGEN_SetIncomingSMS(GSM_StateMachine *s, bool enable) 3567GSM_Error ATGEN_SetIncomingSMS(GSM_StateMachine *s, bool enable)
3405{ 3568{
3406 /* Nokia returns OK, but doesn't return anything */ 3569 /* Nokia returns OK, but doesn't return anything */
3407 if (s->Phone.Data.Priv.ATGEN.Manufacturer == AT_Nokia) return ERR_NOTSUPPORTED; 3570 if (s->Phone.Data.Priv.ATGEN.Manufacturer == AT_Nokia) return ERR_NOTSUPPORTED;
3408 3571
3409 if (s->Phone.Data.EnableIncomingSMS!=enable) { 3572 if (s->Phone.Data.EnableIncomingSMS!=enable) {
3410 s->Phone.Data.EnableIncomingSMS = enable; 3573 s->Phone.Data.EnableIncomingSMS = enable;
3411 if (enable) { 3574 if (enable) {
3412 smprintf(s, "Enabling incoming SMS\n"); 3575 smprintf(s, "Enabling incoming SMS\n");
3413 3576
3414 /* Delivery reports */ 3577 /* Delivery reports */
3415 GSM_WaitFor(s, "AT+CNMI=3,,,1\r", 14, 0x00, 4, ID_SetIncomingSMS); 3578 GSM_WaitFor(s, "AT+CNMI=3,,,1\r", 14, 0x00, 4, ID_SetIncomingSMS);
3416 3579
3417 /* SMS deliver */ 3580 /* SMS deliver */
3418 return GSM_WaitFor(s, "AT+CNMI=3,3\r", 12, 0x00, 4, ID_SetIncomingSMS); 3581 return GSM_WaitFor(s, "AT+CNMI=3,3\r", 12, 0x00, 4, ID_SetIncomingSMS);
3419 } else { 3582 } else {
3420 smprintf(s, "Disabling incoming SMS\n"); 3583 smprintf(s, "Disabling incoming SMS\n");
3421 return GSM_WaitFor(s, "AT+CNMI=3,0\r", 12, 0x00, 4, ID_SetIncomingSMS); 3584 return GSM_WaitFor(s, "AT+CNMI=3,0\r", 12, 0x00, 4, ID_SetIncomingSMS);
3422 } 3585 }
3423 } 3586 }
3424 return ERR_NONE; 3587 return ERR_NONE;
3425} 3588}
3426 3589
3590GSM_Error ATGEN_GetLocale(GSM_StateMachine *s, GSM_Locale *locale)
3591{
3592 if (s->Phone.Data.Priv.ATGEN.Manufacturer==AT_Ericsson) return ERICSSON_GetLocale(s,locale);
3593 return ERR_NOTSUPPORTED;
3594}
3595
3596GSM_Error ATGEN_SetLocale(GSM_StateMachine *s, GSM_Locale *locale)
3597{
3598 if (s->Phone.Data.Priv.ATGEN.Manufacturer==AT_Ericsson) return ERICSSON_SetLocale(s,locale);
3599 return ERR_NOTSUPPORTED;
3600}
3601
3427GSM_Reply_Function ATGENReplyFunctions[] = { 3602GSM_Reply_Function ATGENReplyFunctions[] = {
3428 {ATGEN_GenericReply, "AT\r" ,0x00,0x00,ID_IncomingFrame }, 3603 {ATGEN_GenericReply, "AT\r" ,0x00,0x00,ID_IncomingFrame },
3429 {ATGEN_GenericReply, "ATE1" ,0x00,0x00,ID_EnableEcho }, 3604 {ATGEN_GenericReply, "ATE1" ,0x00,0x00,ID_EnableEcho },
3430 {ATGEN_GenericReply, "AT+CMEE=" ,0x00,0x00,ID_EnableErrorInfo }, 3605 {ATGEN_GenericReply, "AT+CMEE=" ,0x00,0x00,ID_EnableErrorInfo },
3431 {ATGEN_GenericReply, "AT+CKPD=" ,0x00,0x00,ID_PressKey }, 3606 {ATGEN_GenericReply, "AT+CKPD=" ,0x00,0x00,ID_PressKey },
3432 {ATGEN_ReplyGetSIMIMSI, "AT+CIMI" ,0x00,0x00,ID_GetSIMIMSI }, 3607 {ATGEN_ReplyGetSIMIMSI, "AT+CIMI" ,0x00,0x00,ID_GetSIMIMSI },
3433 {ATGEN_GenericReply, "AT*EOBEX" ,0x00,0x00,ID_SetOBEX }, 3608 {ATGEN_GenericReply, "AT*EOBEX" ,0x00,0x00,ID_SetOBEX },
3434 3609
3610 {ERICSSON_ReplyGetDateLocale, "*ESDF:" ,0x00,0x00,ID_GetLocale },
3611 {ERICSSON_ReplyGetTimeLocale, "*ESTF:" ,0x00,0x00,ID_GetLocale },
3612 {ATGEN_GenericReply, "AT*ESDF=" ,0x00,0x00,ID_SetLocale },
3613 {ATGEN_GenericReply, "AT*ESTF=" ,0x00,0x00,ID_SetLocale },
3614
3435#ifdef GSM_ENABLE_CELLBROADCAST 3615#ifdef GSM_ENABLE_CELLBROADCAST
3436 {ATGEN_ReplyIncomingCB, "+CBM:" ,0x00,0x00,ID_IncomingFrame }, 3616 {ATGEN_ReplyIncomingCB, "+CBM:" ,0x00,0x00,ID_IncomingFrame },
3437 {ATGEN_GenericReply, "AT+CNMI" ,0x00,0x00,ID_SetIncomingCB }, 3617 {ATGEN_GenericReply, "AT+CNMI" ,0x00,0x00,ID_SetIncomingCB },
3438#endif 3618#endif
3439 3619
3440 {ATGEN_IncomingBattery, "_OBS:" ,0x00,0x00,ID_IncomingFrame }, 3620 {ATGEN_IncomingBattery, "_OBS:" ,0x00,0x00,ID_IncomingFrame },
3441 {ATGEN_ReplyGetBatteryCharge, "AT+CBC" ,0x00,0x00,ID_GetBatteryCharge }, 3621 {ATGEN_ReplyGetBatteryCharge, "AT+CBC" ,0x00,0x00,ID_GetBatteryCharge },
3442 3622
3443 {ATGEN_ReplyGetModel, "AT+CGMM" ,0x00,0x00,ID_GetModel }, 3623 {ATGEN_ReplyGetModel, "AT+CGMM" ,0x00,0x00,ID_GetModel },
3444 {ATGEN_ReplyGetManufacturer, "AT+CGMI" ,0x00,0x00,ID_GetManufacturer }, 3624 {ATGEN_ReplyGetManufacturer, "AT+CGMI" ,0x00,0x00,ID_GetManufacturer },
3445 {ATGEN_ReplyGetFirmwareCGMR, "AT+CGMR" ,0x00,0x00,ID_GetFirmware }, 3625 {ATGEN_ReplyGetFirmwareCGMR, "AT+CGMR" ,0x00,0x00,ID_GetFirmware },
3446 {ATGEN_ReplyGetFirmwareATI, "ATI" ,0x00,0x00,ID_GetFirmware }, 3626 {ATGEN_ReplyGetFirmwareATI, "ATI" ,0x00,0x00,ID_GetFirmware },
3447 {ATGEN_ReplyGetIMEI, "AT+CGSN" ,0x00,0x00,ID_GetIMEI }, 3627 {ATGEN_ReplyGetIMEI, "AT+CGSN" ,0x00,0x00,ID_GetIMEI },
3448 3628
3449 {ATGEN_ReplySendSMS, "AT+CMGS" ,0x00,0x00,ID_IncomingFrame }, 3629 {ATGEN_ReplySendSMS, "AT+CMGS" ,0x00,0x00,ID_IncomingFrame },
3450 {ATGEN_ReplySendSMS, "AT+CMSS" ,0x00,0x00,ID_IncomingFrame }, 3630 {ATGEN_ReplySendSMS, "AT+CMSS" ,0x00,0x00,ID_IncomingFrame },
3451 {ATGEN_GenericReply, "AT+CNMI" ,0x00,0x00,ID_SetIncomingSMS }, 3631 {ATGEN_GenericReply, "AT+CNMI" ,0x00,0x00,ID_SetIncomingSMS },
3452 {ATGEN_GenericReply, "AT+CMGF" ,0x00,0x00,ID_GetSMSMode }, 3632 {ATGEN_GenericReply, "AT+CMGF" ,0x00,0x00,ID_GetSMSMode },
3453 {ATGEN_GenericReply, "AT+CSDH" ,0x00,0x00,ID_GetSMSMode }, 3633 {ATGEN_GenericReply, "AT+CSDH" ,0x00,0x00,ID_GetSMSMode },
3454 {ATGEN_ReplyGetSMSMessage, "AT+CMGR" ,0x00,0x00,ID_GetSMSMessage }, 3634 {ATGEN_ReplyGetSMSMessage, "AT+CMGR" ,0x00,0x00,ID_GetSMSMessage },
3455 {ATGEN_GenericReply, "AT+CPMS" ,0x00,0x00,ID_SetMemoryType }, 3635 {ATGEN_GenericReply, "AT+CPMS" ,0x00,0x00,ID_SetMemoryType },
3456 {ATGEN_ReplyGetSMSStatus, "AT+CPMS" ,0x00,0x00,ID_GetSMSStatus }, 3636 {ATGEN_ReplyGetSMSStatus, "AT+CPMS" ,0x00,0x00,ID_GetSMSStatus },
3457 {ATGEN_ReplyGetSMSMemories, "AT+CPMS=?" ,0x00,0x00,ID_GetSMSMemories }, 3637 {ATGEN_ReplyGetSMSMemories, "AT+CPMS=?" ,0x00,0x00,ID_GetSMSMemories },
3458 {ATGEN_ReplyAddSMSMessage, "AT+CMGW" ,0x00,0x00,ID_SaveSMSMessage }, 3638 {ATGEN_ReplyAddSMSMessage, "AT+CMGW" ,0x00,0x00,ID_SaveSMSMessage },
3459 {ATGEN_GenericReply, "AT+CSMP" ,0x00,0x00,ID_SetSMSParameters }, 3639 {ATGEN_GenericReply, "AT+CSMP" ,0x00,0x00,ID_SetSMSParameters },
3460 {ATGEN_GenericReply, "AT+CSCA" ,0x00,0x00,ID_SetSMSC }, 3640 {ATGEN_GenericReply, "AT+CSCA" ,0x00,0x00,ID_SetSMSC },
3461 {ATGEN_ReplyGetSMSC, "AT+CSCA?" ,0x00,0x00,ID_GetSMSC }, 3641 {ATGEN_ReplyGetSMSC, "AT+CSCA?" ,0x00,0x00,ID_GetSMSC },
3462 {ATGEN_ReplyDeleteSMSMessage, "AT+CMGD" ,0x00,0x00,ID_DeleteSMSMessage }, 3642 {ATGEN_ReplyDeleteSMSMessage, "AT+CMGD" ,0x00,0x00,ID_DeleteSMSMessage },
3463 {ATGEN_GenericReply, "ATE1" ,0x00,0x00,ID_SetSMSParameters }, 3643 {ATGEN_GenericReply, "ATE1" ,0x00,0x00,ID_SetSMSParameters },
3464 {ATGEN_GenericReply, "\x1b\x0D" ,0x00,0x00,ID_SetSMSParameters }, 3644 {ATGEN_GenericReply, "\x1b\x0D" ,0x00,0x00,ID_SetSMSParameters },
3645 {ATGEN_GenericReply, "AT+CMMS" ,0x00,0x00,ID_SetFastSMSSending },
3465 {ATGEN_IncomingSMSInfo, "+CMTI:" ,0x00,0x00,ID_IncomingFrame }, 3646 {ATGEN_IncomingSMSInfo, "+CMTI:" ,0x00,0x00,ID_IncomingFrame },
3466 {ATGEN_IncomingSMSDeliver, "+CMT:" ,0x00,0x00,ID_IncomingFrame }, 3647 {ATGEN_IncomingSMSDeliver, "+CMT:" ,0x00,0x00,ID_IncomingFrame },
3467 {ATGEN_IncomingSMSReport, "+CDS:" ,0x00,0x00,ID_IncomingFrame }, 3648 {ATGEN_IncomingSMSReport, "+CDS:" ,0x00,0x00,ID_IncomingFrame },
3468 {ATGEN_IncomingSMSCInfo, "^SCN:" ,0x00,0x00,ID_IncomingFrame }, 3649 {ATGEN_IncomingSMSCInfo, "^SCN:" ,0x00,0x00,ID_IncomingFrame },
3469 3650
3470 {ATGEN_ReplyGetDateTime_Alarm, "AT+CCLK?" ,0x00,0x00,ID_GetDateTime }, 3651 {ATGEN_ReplyGetDateTime_Alarm, "AT+CCLK?" ,0x00,0x00,ID_GetDateTime },
3471 {ATGEN_GenericReply, "AT+CCLK=" ,0x00,0x00,ID_SetDateTime }, 3652 {ATGEN_GenericReply, "AT+CCLK=" ,0x00,0x00,ID_SetDateTime },
3653 {ATGEN_GenericReply, "AT+CALA=" ,0x00,0x00,ID_SetAlarm },
3472 {ATGEN_ReplyGetDateTime_Alarm, "AT+CALA?" ,0x00,0x00,ID_GetAlarm }, 3654 {ATGEN_ReplyGetDateTime_Alarm, "AT+CALA?" ,0x00,0x00,ID_GetAlarm },
3473 3655
3474 {ATGEN_ReplyGetNetworkLAC_CID, "AT+CREG?" ,0x00,0x00,ID_GetNetworkInfo }, 3656 {ATGEN_ReplyGetNetworkLAC_CID, "AT+CREG?" ,0x00,0x00,ID_GetNetworkInfo },
3475 {ATGEN_GenericReply, "AT+CREG=2" ,0x00,0x00,ID_GetNetworkInfo }, 3657 {ATGEN_GenericReply, "AT+CREG=2" ,0x00,0x00,ID_GetNetworkInfo },
3476 {ATGEN_GenericReply, "AT+COPS=" ,0x00,0x00,ID_GetNetworkInfo }, 3658 {ATGEN_GenericReply, "AT+COPS=" ,0x00,0x00,ID_GetNetworkInfo },
3477 {ATGEN_GenericReply, "AT+COPS=" ,0x00,0x00,ID_SetAutoNetworkLogin}, 3659 {ATGEN_GenericReply, "AT+COPS=" ,0x00,0x00,ID_SetAutoNetworkLogin},
3478 {ATGEN_ReplyGetNetworkCode, "AT+COPS" ,0x00,0x00,ID_GetNetworkInfo }, 3660 {ATGEN_ReplyGetNetworkCode, "AT+COPS" ,0x00,0x00,ID_GetNetworkInfo },
3479 {ATGEN_ReplyGetSignalQuality, "AT+CSQ" ,0x00,0x00,ID_GetSignalQuality }, 3661 {ATGEN_ReplyGetSignalQuality, "AT+CSQ" ,0x00,0x00,ID_GetSignalQuality },
3480 {ATGEN_IncomingNetworkLevel, "_OSIGQ:" ,0x00,0x00,ID_IncomingFrame }, 3662 {ATGEN_IncomingNetworkLevel, "_OSIGQ:" ,0x00,0x00,ID_IncomingFrame },
3481 {ATGEN_IncomingGPRS, "+CGREG:" ,0x00,0x00,ID_IncomingFrame }, 3663 {ATGEN_IncomingGPRS, "+CGREG:" ,0x00,0x00,ID_IncomingFrame },
3482 {ATGEN_ReplyGetNetworkLAC_CID, "+CREG:" ,0x00,0x00,ID_IncomingFrame }, 3664 {ATGEN_ReplyGetNetworkLAC_CID, "+CREG:" ,0x00,0x00,ID_IncomingFrame },
3483 3665
3484 {ATGEN_ReplyGetPBKMemories, "AT+CPBS=?" ,0x00,0x00,ID_SetMemoryType }, 3666 {ATGEN_ReplyGetPBKMemories, "AT+CPBS=?" ,0x00,0x00,ID_SetMemoryType },
3485 {ATGEN_GenericReply, "AT+CPBS=" ,0x00,0x00,ID_SetMemoryType }, 3667 {ATGEN_GenericReply, "AT+CPBS=" ,0x00,0x00,ID_SetMemoryType },
3486 {ATGEN_ReplyGetCPBSMemoryStatus,"AT+CPBS?" ,0x00,0x00,ID_GetMemoryStatus }, 3668 {ATGEN_ReplyGetCPBSMemoryStatus,"AT+CPBS?" ,0x00,0x00,ID_GetMemoryStatus },
3669// /* Samsung phones reply +CPBR: after OK --claudio*/
3487 {ATGEN_ReplyGetCPBRMemoryInfo, "AT+CPBR=?" ,0x00,0x00,ID_GetMemoryStatus }, 3670 {ATGEN_ReplyGetCPBRMemoryInfo, "AT+CPBR=?" ,0x00,0x00,ID_GetMemoryStatus },
3671 {ATGEN_ReplyGetCPBRMemoryInfo, "+CPBR:" ,0x00,0x00,ID_GetMemoryStatus },
3488 {ATGEN_ReplyGetCPBRMemoryStatus,"AT+CPBR=" ,0x00,0x00,ID_GetMemoryStatus }, 3672 {ATGEN_ReplyGetCPBRMemoryStatus,"AT+CPBR=" ,0x00,0x00,ID_GetMemoryStatus },
3489 {ATGEN_GenericReply, "AT+CSCS=" ,0x00,0x00,ID_SetMemoryCharset }, 3673 {ATGEN_GenericReply, "AT+CSCS=" ,0x00,0x00,ID_SetMemoryCharset },
3490 {ATGEN_ReplyGetMemory, "AT+CPBR=" ,0x00,0x00,ID_GetMemory }, 3674 {ATGEN_ReplyGetMemory, "AT+CPBR=" ,0x00,0x00,ID_GetMemory },
3491 {ATGEN_GenericReply, "AT^SBNR=?" ,0x00,0x00,ID_GetMemory }, 3675 {ATGEN_GenericReply, "AT^SBNR=?" ,0x00,0x00,ID_GetMemory },
3492 {ATGEN_SL45ReplyGetMemory, "AT^SBNR" ,0x00,0x00,ID_GetMemory }, 3676 {SIEMENS_ReplyGetMemory, "AT^SBNR" ,0x00,0x00,ID_GetMemory },
3493 {ATGEN_ReplySetMemory, "AT+CPBW" ,0x00,0x00,ID_SetMemory }, 3677 {ATGEN_ReplySetMemory, "AT+CPBW" ,0x00,0x00,ID_SetMemory },
3494 3678
3495 {ATGEN_CMS35ReplyGetBitmap, "AT^SBNR=\"bmp\"" ,0x00,0x00,ID_GetBitmap }, 3679 {SIEMENS_ReplyGetBitmap, "AT^SBNR=\"bmp\"" ,0x00,0x00,ID_GetBitmap },
3496 {ATGEN_CMS35ReplySetBitmap, "AT^SBNW=\"bmp\"" ,0x00,0x00,ID_SetBitmap }, 3680 {SIEMENS_ReplySetBitmap, "AT^SBNW=\"bmp\"" ,0x00,0x00,ID_SetBitmap },
3497 3681
3498 {ATGEN_CMS35ReplyGetRingtone, "AT^SBNR=\"mid\"" ,0x00,0x00,ID_GetRingtone }, 3682 {SIEMENS_ReplyGetRingtone, "AT^SBNR=\"mid\"" ,0x00,0x00,ID_GetRingtone },
3499 {ATGEN_CMS35ReplySetRingtone, "AT^SBNW=\"mid\"" ,0x00,0x00,ID_SetRingtone }, 3683 {SIEMENS_ReplySetRingtone, "AT^SBNW=\"mid\"" ,0x00,0x00,ID_SetRingtone },
3500 3684
3501 {ATGEN_CMS35ReplyGetNextCal, "AT^SBNR=\"vcs\"" ,0x00,0x00,ID_GetCalendarNote }, 3685 {SIEMENS_ReplyGetNextCalendar, "AT^SBNR=\"vcs\"" ,0x00,0x00,ID_GetCalendarNote },
3502 {ATGEN_CMS35ReplySetCalendar, "AT^SBNW=\"vcs\"" ,0x00,0x00,ID_SetCalendarNote }, 3686 {SIEMENS_ReplyAddCalendarNote, "AT^SBNW=\"vcs\"" ,0x00,0x00,ID_SetCalendarNote },
3503 {ATGEN_CMS35ReplyDeleteCalendar,"AT^SBNW=\"vcs\"",0x00,0x00,ID_DeleteCalendarNote }, 3687 {SIEMENS_ReplyDelCalendarNote, "AT^SBNW=\"vcs\"",0x00,0x00,ID_DeleteCalendarNote },
3504 3688
3505 {ATGEN_ReplyEnterSecurityCode, "AT+CPIN=" ,0x00,0x00,ID_EnterSecurityCode }, 3689 {ATGEN_ReplyEnterSecurityCode, "AT+CPIN=" ,0x00,0x00,ID_EnterSecurityCode },
3506 {ATGEN_ReplyEnterSecurityCode, "AT+CPIN2=" ,0x00,0x00,ID_EnterSecurityCode }, 3690 {ATGEN_ReplyEnterSecurityCode, "AT+CPIN2=" ,0x00,0x00,ID_EnterSecurityCode },
3507 {ATGEN_ReplyGetSecurityStatus, "AT+CPIN?" ,0x00,0x00,ID_GetSecurityStatus }, 3691 {ATGEN_ReplyGetSecurityStatus, "AT+CPIN?" ,0x00,0x00,ID_GetSecurityStatus },
3508 {ATGEN_ReplyOK, "OK" ,0x00,0x00,ID_IncomingFrame }, 3692 {ATGEN_ReplyOK, "OK" ,0x00,0x00,ID_IncomingFrame },
3509 3693
3510 {ATGEN_GenericReply, "AT+VTS" ,0x00,0x00,ID_SendDTMF }, 3694 {ATGEN_GenericReply, "AT+VTS" ,0x00,0x00,ID_SendDTMF },
3511 {ATGEN_ReplyCancelCall, "AT+CHUP" ,0x00,0x00,ID_CancelCall }, 3695 {ATGEN_ReplyCancelCall, "AT+CHUP" ,0x00,0x00,ID_CancelCall },
3512 {ATGEN_ReplyDialVoice, "ATDT" ,0x00,0x00,ID_DialVoice }, 3696 {ATGEN_ReplyDialVoice, "ATDT" ,0x00,0x00,ID_DialVoice },
3513 {ATGEN_ReplyCancelCall, "ATH" ,0x00,0x00,ID_CancelCall }, 3697 {ATGEN_ReplyCancelCall, "ATH" ,0x00,0x00,ID_CancelCall },
3698 {ATGEN_GenericReply, "AT+CUSD" ,0x00,0x00,ID_SetUSSD },
3699 {ATGEN_ReplyGetUSSD, "+CUSD" ,0x00,0x00,ID_IncomingFrame },
3514 {ATGEN_GenericReply, "AT+CLIP=1" ,0x00,0x00,ID_IncomingFrame }, 3700 {ATGEN_GenericReply, "AT+CLIP=1" ,0x00,0x00,ID_IncomingFrame },
3515 {ATGEN_ReplyIncomingCallInfo, "+CLIP" ,0x00,0x00,ID_IncomingFrame }, 3701 {ATGEN_ReplyIncomingCallInfo, "+CLIP" ,0x00,0x00,ID_IncomingFrame },
3516 {ATGEN_ReplyIncomingCallInfo, "+COLP" ,0x00,0x00,ID_IncomingFrame }, 3702 {ATGEN_ReplyIncomingCallInfo, "+COLP" ,0x00,0x00,ID_IncomingFrame },
3517 {ATGEN_ReplyIncomingCallInfo, "RING" ,0x00,0x00,ID_IncomingFrame }, 3703 {ATGEN_ReplyIncomingCallInfo, "RING" ,0x00,0x00,ID_IncomingFrame },
3518 {ATGEN_ReplyIncomingCallInfo, "NO CARRIER" ,0x00,0x00,ID_IncomingFrame }, 3704 {ATGEN_ReplyIncomingCallInfo, "NO CARRIER" ,0x00,0x00,ID_IncomingFrame },
3519 3705
3520 {ATGEN_ReplyReset, "AT^SRESET" ,0x00,0x00,ID_Reset }, 3706 {ATGEN_ReplyReset, "AT^SRESET" ,0x00,0x00,ID_Reset },
3521 {ATGEN_ReplyReset, "AT+CFUN=1,1" ,0x00,0x00,ID_Reset }, 3707 {ATGEN_ReplyReset, "AT+CFUN=1,1" ,0x00,0x00,ID_Reset },
3522 {ATGEN_ReplyResetPhoneSettings, "AT&F" ,0x00,0x00,ID_ResetPhoneSettings }, 3708 {ATGEN_ReplyResetPhoneSettings, "AT&F" ,0x00,0x00,ID_ResetPhoneSettings },
3523 3709
3710 {SAMSUNG_ReplyGetBitmap, "AT+IMGR=" ,0x00,0x00,ID_GetBitmap },
3711 {SAMSUNG_ReplySetBitmap, "SDNDCRC =" ,0x00,0x00,ID_SetBitmap },
3712
3713 {SAMSUNG_ReplyGetRingtone, "AT+MELR=" ,0x00,0x00,ID_GetRingtone },
3714 {SAMSUNG_ReplySetRingtone, "SDNDCRC =" ,0x00,0x00,ID_SetRingtone },
3715
3524#ifdef GSM_ENABLE_ALCATEL 3716#ifdef GSM_ENABLE_ALCATEL
3525/* Why do I give Alcatel specific things here? It's simple, Alcatel needs 3717/* Why do I give Alcatel specific things here? It's simple, Alcatel needs
3526 * some AT commands to start it's binary mode, so this needs to be in AT 3718 * some AT commands to start it's binary mode, so this needs to be in AT
3527 * related stuff. 3719 * related stuff.
3528 * 3720 *
3529 * XXX: AT+IFC could later move outside this ifdef, because it is not Alcatel 3721 * XXX: AT+IFC could later move outside this ifdef, because it is not Alcatel
3530 * specific and it's part of ETSI specifications 3722 * specific and it's part of ETSI specifications
3531 */ 3723 */
3532 {ATGEN_GenericReply, "AT+IFC" ,0x00,0x00,ID_SetFlowControl }, 3724 {ATGEN_GenericReply, "AT+IFC" ,0x00,0x00,ID_SetFlowControl },
3533 {ALCATEL_ProtocolVersionReply, "AT+CPROT=?" ,0x00,0x00,ID_AlcatelProtocol }, 3725 {ALCATEL_ProtocolVersionReply, "AT+CPROT=?" ,0x00,0x00,ID_AlcatelProtocol },
3534 {ATGEN_GenericReply, "AT+CPROT" ,0x00,0x00,ID_AlcatelConnect }, 3726 {ATGEN_GenericReply, "AT+CPROT" ,0x00,0x00,ID_AlcatelConnect },
3535#endif 3727#endif
3536 3728
3537 {NULL, "\x00" ,0x00,0x00,ID_None } 3729 {NULL, "\x00" ,0x00,0x00,ID_None }
3538}; 3730};
3539 3731
3540GSM_Phone_Functions ATGENPhone = { 3732GSM_Phone_Functions ATGENPhone = {
3541 "A2D|iPAQ|at|M20|S25|MC35|C35i|5110|5130|5190|5210|6110|6130|6150|6190|6210|6250|6310|6310i|6510|7110|8210|8250|8290|8310|8390|8850|8855|8890|8910|9110|9210", 3733 "A2D|iPAQ|at|M20|S25|MC35|TC35|C35i|S300|5110|5130|5190|5210|6110|6130|6150|6190|6210|6250|6310|6310i|6510|7110|8210|8250|8290|8310|8390|8850|8855|8890|8910|9110|9210",
3542 ATGENReplyFunctions, 3734 ATGENReplyFunctions,
3543 ATGEN_Initialise, 3735 ATGEN_Initialise,
3544 ATGEN_Terminate, 3736 ATGEN_Terminate,
3545 ATGEN_DispatchMessage, 3737 ATGEN_DispatchMessage,
3546 NOTSUPPORTED, /* ShowStartInfo */ 3738 NOTSUPPORTED, /* ShowStartInfo */
3547 ATGEN_GetManufacturer, 3739 ATGEN_GetManufacturer,
3548 ATGEN_GetModel, 3740 ATGEN_GetModel,
3549 ATGEN_GetFirmware, 3741 ATGEN_GetFirmware,
3550 ATGEN_GetIMEI, 3742 ATGEN_GetIMEI,
3551 NOTSUPPORTED, /* GetOriginalIMEI */ 3743 NOTSUPPORTED, /* GetOriginalIMEI */
3552 NOTSUPPORTED, /* GetManufactureMonth*/ 3744 NOTSUPPORTED, /* GetManufactureMonth*/
3553 NOTSUPPORTED, /* GetProductCode */ 3745 NOTSUPPORTED, /* GetProductCode */
3554 NOTSUPPORTED, /* GetHardware */ 3746 NOTSUPPORTED, /* GetHardware */
3555 NOTSUPPORTED, /* GetPPM */ 3747 NOTSUPPORTED, /* GetPPM */
3556 ATGEN_GetSIMIMSI, 3748 ATGEN_GetSIMIMSI,
3557 ATGEN_GetDateTime, 3749 ATGEN_GetDateTime,
3558 ATGEN_SetDateTime, 3750 ATGEN_SetDateTime,
3559 ATGEN_GetAlarm, 3751 ATGEN_GetAlarm,
3560 NOTIMPLEMENTED, /* SetAlarm */ 3752 ATGEN_SetAlarm,
3561 NOTSUPPORTED, /* GetLocale */ 3753 ATGEN_GetLocale,
3562 NOTSUPPORTED, /* SetLocale */ 3754 ATGEN_SetLocale,
3563 ATGEN_PressKey, 3755 ATGEN_PressKey,
3564 ATGEN_Reset, 3756 ATGEN_Reset,
3565 ATGEN_ResetPhoneSettings, 3757 ATGEN_ResetPhoneSettings,
3566 ATGEN_EnterSecurityCode, 3758 ATGEN_EnterSecurityCode,
3567 ATGEN_GetSecurityStatus, 3759 ATGEN_GetSecurityStatus,
3568 ATGEN_GetDisplayStatus, 3760 ATGEN_GetDisplayStatus,
3569 ATGEN_SetAutoNetworkLogin, 3761 ATGEN_SetAutoNetworkLogin,
3570 ATGEN_GetBatteryCharge, 3762 ATGEN_GetBatteryCharge,
3571 ATGEN_GetSignalQuality, 3763 ATGEN_GetSignalQuality,
3572 ATGEN_GetNetworkInfo, 3764 ATGEN_GetNetworkInfo,
3573 NOTSUPPORTED, /* GetCategory */ 3765 NOTSUPPORTED, /* GetCategory */
3574 NOTSUPPORTED, /* AddCategory */ 3766 NOTSUPPORTED, /* AddCategory */
3575 NOTSUPPORTED, /* GetCategoryStatus */ 3767 NOTSUPPORTED, /* GetCategoryStatus */
3576 ATGEN_GetMemoryStatus, 3768 ATGEN_GetMemoryStatus,
3577 ATGEN_GetMemory, 3769 ATGEN_GetMemory,
3578 ATGEN_GetNextMemory, 3770 ATGEN_GetNextMemory,
3579 ATGEN_SetMemory, 3771 ATGEN_SetMemory,
3580 ATGEN_AddMemory, 3772 ATGEN_AddMemory,
3581 ATGEN_DeleteMemory, 3773 ATGEN_DeleteMemory,
3582 ATGEN_DeleteAllMemory, 3774 ATGEN_DeleteAllMemory,
3583 NOTSUPPORTED, /* GetSpeedDial */ 3775 NOTSUPPORTED, /* GetSpeedDial */
3584 NOTSUPPORTED, /* SetSpeedDial */ 3776 NOTSUPPORTED, /* SetSpeedDial */
3585 ATGEN_GetSMSC, 3777 ATGEN_GetSMSC,
3586 ATGEN_SetSMSC, 3778 ATGEN_SetSMSC,
3587 ATGEN_GetSMSStatus, 3779 ATGEN_GetSMSStatus,
3588 ATGEN_GetSMS, 3780 ATGEN_GetSMS,
3589 ATGEN_GetNextSMS, 3781 ATGEN_GetNextSMS,
3590 NOTSUPPORTED, /* SetSMS */ 3782 NOTSUPPORTED, /* SetSMS */
3591 ATGEN_AddSMS, 3783 ATGEN_AddSMS,
3592 ATGEN_DeleteSMS, 3784 ATGEN_DeleteSMS,
3593 ATGEN_SendSMS, 3785 ATGEN_SendSMS,
3594 ATGEN_SendSavedSMS, 3786 ATGEN_SendSavedSMS,
3787 ATGEN_SetFastSMSSending,
3595 ATGEN_SetIncomingSMS, 3788 ATGEN_SetIncomingSMS,
3596 ATGEN_SetIncomingCB, 3789 ATGEN_SetIncomingCB,
3597 ATGEN_GetSMSFolders, 3790 ATGEN_GetSMSFolders,
3598 NOTSUPPORTED, /* AddSMSFolder */ 3791 NOTSUPPORTED, /* AddSMSFolder */
3599 NOTSUPPORTED, /* DeleteSMSFolder */ 3792 NOTSUPPORTED, /* DeleteSMSFolder */
3600 ATGEN_DialVoice, 3793 ATGEN_DialVoice,
3601 ATGEN_AnswerCall, 3794 ATGEN_AnswerCall,
3602 ATGEN_CancelCall, 3795 ATGEN_CancelCall,
3603 NOTSUPPORTED, /* HoldCall */ 3796 NOTSUPPORTED, /* HoldCall */
3604 NOTSUPPORTED, /* UnholdCall */ 3797 NOTSUPPORTED, /* UnholdCall */
3605 NOTSUPPORTED, /* ConferenceCall */ 3798 NOTSUPPORTED, /* ConferenceCall */
3606 NOTSUPPORTED, /* SplitCall */ 3799 NOTSUPPORTED, /* SplitCall */
3607 NOTSUPPORTED, /* TransferCall */ 3800 NOTSUPPORTED, /* TransferCall */
3608 NOTSUPPORTED, /* SwitchCall */ 3801 NOTSUPPORTED, /* SwitchCall */
3609 NOTSUPPORTED, /* GetCallDivert */ 3802 NOTSUPPORTED, /* GetCallDivert */
3610 NOTSUPPORTED, /* SetCallDivert */ 3803 NOTSUPPORTED, /* SetCallDivert */
3611 NOTSUPPORTED, /* CancelAllDiverts*/ 3804 NOTSUPPORTED, /* CancelAllDiverts*/
3612 NONEFUNCTION, /* SetIncomingCall */ 3805 NONEFUNCTION, /* SetIncomingCall */
3613 NOTSUPPORTED, /* SetIncomingUSSD */ 3806 ATGEN_SetIncomingUSSD,
3614 ATGEN_SendDTMF, 3807 ATGEN_SendDTMF,
3615 ATGEN_GetRingtone, 3808 ATGEN_GetRingtone,
3616 ATGEN_SetRingtone, 3809 ATGEN_SetRingtone,
3617 NOTSUPPORTED, /* GetRingtonesInfo*/ 3810 NOTSUPPORTED, /* GetRingtonesInfo*/
3618 NOTSUPPORTED, /* DeleteUserRingtones*/ 3811 NOTSUPPORTED, /* DeleteUserRingtones*/
3619 NOTSUPPORTED, /* PlayTone */ 3812 NOTSUPPORTED, /* PlayTone */
3620 NOTSUPPORTED, /* GetWAPBookmark */ 3813 NOTSUPPORTED, /* GetWAPBookmark */
3621 NOTSUPPORTED, /* SetWAPBookmark */ 3814 NOTSUPPORTED, /* SetWAPBookmark */
3622 NOTSUPPORTED, /* DeleteWAPBookmark */ 3815 NOTSUPPORTED, /* DeleteWAPBookmark */
3623 NOTSUPPORTED, /* GetWAPSettings */ 3816 NOTSUPPORTED, /* GetWAPSettings */
3624 NOTSUPPORTED, /* SetWAPSettings */ 3817 NOTSUPPORTED, /* SetWAPSettings */
3625 NOTSUPPORTED, /* GetMMSSettings */ 3818 NOTSUPPORTED, /* GetMMSSettings */
3626 NOTSUPPORTED, /* SetMMSSettings */ 3819 NOTSUPPORTED, /* SetMMSSettings */
3627 NOTSUPPORTED, /* GetSyncMLSettings*/ 3820 NOTSUPPORTED, /* GetSyncMLSettings*/
3628 NOTSUPPORTED, /* SetSyncMLSettings*/ 3821 NOTSUPPORTED, /* SetSyncMLSettings*/
3629 NOTSUPPORTED, /* GetChatSettings */ 3822 NOTSUPPORTED, /* GetChatSettings */
3630 NOTSUPPORTED, /* SetChatSettings */ 3823 NOTSUPPORTED, /* SetChatSettings */
3631 ATGEN_GetBitmap, /* GetBitmap */ 3824 ATGEN_GetBitmap, /* GetBitmap */
3632 ATGEN_SetBitmap, /* SetBitmap */ 3825 ATGEN_SetBitmap, /* SetBitmap */
3633 SONYERIC_GetToDoStatus, 3826 SONYERIC_GetToDoStatus,
3634 NOTSUPPORTED, /* GetToDo */ 3827 NOTSUPPORTED, /* GetToDo */
3635 SONYERIC_GetNextToDo, 3828 SONYERIC_GetNextToDo,
3636 NOTSUPPORTED, /* SetToDo */ 3829 NOTSUPPORTED, /* SetToDo */
3637 SONYERIC_AddToDo, 3830 SONYERIC_AddToDo,
3638 NOTSUPPORTED, /* DeleteToDo */ 3831 NOTSUPPORTED, /* DeleteToDo */
3639 SONYERIC_DeleteAllToDo, 3832 SONYERIC_DeleteAllToDo,
3640 SONYERIC_GetCalendarStatus, 3833 SONYERIC_GetCalendarStatus,
3641 NOTIMPLEMENTED, /* GetCalendar */ 3834 NOTIMPLEMENTED, /* GetCalendar */
3642 ATGEN_GetNextCalendar, 3835 ATGEN_GetNextCalendar,
3643 NOTIMPLEMENTED, /* SetCalendar */ 3836 NOTIMPLEMENTED, /* SetCalendar */
3644 ATGEN_AddCalendarNote, 3837 ATGEN_AddCalendarNote,
3645 ATGEN_DelCalendarNote, 3838 ATGEN_DelCalendarNote,
3646 NOTIMPLEMENTED, /* DeleteAllCalendar*/ 3839 NOTIMPLEMENTED, /* DeleteAllCalendar*/
3647 NOTSUPPORTED, /* GetCalendarSettings*/ 3840 NOTSUPPORTED, /* GetCalendarSettings*/
3648 NOTSUPPORTED, /* SetCalendarSettings*/ 3841 NOTSUPPORTED, /* SetCalendarSettings*/
3649 NOTSUPPORTED, /* GetNote */ 3842 NOTSUPPORTED, /* GetNextNote */
3650 NOTSUPPORTED, /* GetProfile */ 3843 NOTSUPPORTED, /* GetProfile */
3651 NOTSUPPORTED, /* SetProfile */ 3844 NOTSUPPORTED, /* SetProfile */
3652 NOTSUPPORTED, /* GetFMStation */ 3845 NOTSUPPORTED, /* GetFMStation */
3653 NOTSUPPORTED, /* SetFMStation */ 3846 NOTSUPPORTED, /* SetFMStation */
3654 NOTSUPPORTED, /* ClearFMStations */ 3847 NOTSUPPORTED, /* ClearFMStations */
3655 NOTSUPPORTED, /* GetNextFileFolder*/ 3848 NOTSUPPORTED, /* GetNextFileFolder*/
3656 NOTSUPPORTED, /* GetFilePart */ 3849 NOTSUPPORTED, /* GetFilePart */
3657 NOTSUPPORTED, /* AddFile */ 3850 NOTSUPPORTED, /* AddFile */
3658 NOTSUPPORTED, /* GetFileSystemStatus*/ 3851 NOTSUPPORTED, /* GetFileSystemStatus*/
3659 NOTSUPPORTED, /* DeleteFile */ 3852 NOTSUPPORTED, /* DeleteFile */
3660 NOTSUPPORTED, /* AddFolder */ 3853 NOTSUPPORTED, /* AddFolder */
3661 NOTSUPPORTED, /* GetGPRSAccessPoint*/ 3854 NOTSUPPORTED, /* GetGPRSAccessPoint*/
3662 NOTSUPPORTED /* SetGPRSAccessPoint*/ 3855 NOTSUPPORTED /* SetGPRSAccessPoint*/
3663}; 3856};
3664 3857
3665#endif 3858#endif
3666 3859
3667/* How should editor hadle tabs in this file? Add editor commands here. 3860/* How should editor hadle tabs in this file? Add editor commands here.
3668 * vim: noexpandtab sw=8 ts=8 sts=8: 3861 * vim: noexpandtab sw=8 ts=8 sts=8:
3669 */ 3862 */
diff --git a/gammu/emb/common/phone/at/atgen.h b/gammu/emb/common/phone/at/atgen.h
index 0e08ee4..bb5c559 100644
--- a/gammu/emb/common/phone/at/atgen.h
+++ b/gammu/emb/common/phone/at/atgen.h
@@ -1,110 +1,116 @@
1/* (c) 2002-2004 by Marcin Wiacek and Michal Cihar */ 1/* (c) 2002-2004 by Marcin Wiacek and Michal Cihar */
2 2
3#ifndef atgen_h 3#ifndef atgen_h
4#define atgen_h 4#define atgen_h
5 5
6#include "../../gsmcomon.h" 6#include "../../gsmcomon.h"
7#include "../../gsmstate.h" 7#include "../../gsmstate.h"
8#include "../../service/sms/gsmsms.h" 8#include "../../service/sms/gsmsms.h"
9 9
10#ifndef GSM_USED_AT 10#ifndef GSM_USED_AT
11# define GSM_USED_AT 11# define GSM_USED_AT
12#endif 12#endif
13#ifndef GSM_USED_BLUEAT 13#ifndef GSM_USED_BLUEAT
14# define GSM_USED_BLUEAT 14# define GSM_USED_BLUEAT
15#endif 15#endif
16#ifndef GSM_USED_IRDAAT 16#ifndef GSM_USED_IRDAAT
17# define GSM_USED_IRDAAT 17# define GSM_USED_IRDAAT
18#endif 18#endif
19 19
20#define MAX_VCALENDAR_LOCATION 50 20#define MAX_VCALENDAR_LOCATION 50
21 21
22typedef enum { 22typedef enum {
23 SMS_AT_PDU = 1, 23 SMS_AT_PDU = 1,
24 SMS_AT_TXT 24 SMS_AT_TXT
25} GSM_AT_SMS_Modes; 25} GSM_AT_SMS_Modes;
26 26
27typedef enum { 27typedef enum {
28 AT_Reply_OK = 1, 28 AT_Reply_OK = 1,
29 AT_Reply_Connect, 29 AT_Reply_Connect,
30 AT_Reply_Error, 30 AT_Reply_Error,
31 AT_Reply_Unknown, 31 AT_Reply_Unknown,
32 AT_Reply_CMSError, 32 AT_Reply_CMSError,
33 AT_Reply_CMEError, 33 AT_Reply_CMEError,
34 AT_Reply_SMSEdit 34 AT_Reply_SMSEdit
35} GSM_AT_Reply_State; 35} GSM_AT_Reply_State;
36 36
37typedef enum { 37typedef enum {
38 AT_Nokia = 1, 38 AT_Nokia = 1,
39 AT_Alcatel, 39 AT_Alcatel,
40 AT_Siemens, 40 AT_Siemens,
41 AT_HP, 41 AT_HP,
42 AT_Falcom, 42 AT_Falcom,
43 AT_Ericsson, 43 AT_Ericsson,
44 AT_Sagem, 44 AT_Sagem,
45 AT_Samsung,
45 AT_Unknown 46 AT_Unknown
46} GSM_AT_Manufacturer; 47} GSM_AT_Manufacturer;
47 48
48typedef enum { 49typedef enum {
49 AT_PBK_HEX = 1, 50 AT_PBK_HEX = 1,
50 AT_PBK_GSM, 51 AT_PBK_GSM,
51 AT_PBK_UCS2 52 AT_PBK_UCS2,
53 AT_PBK_PCCP437
52} GSM_AT_PBK_Charset; 54} GSM_AT_PBK_Charset;
53 55
54typedef enum { 56typedef enum {
55 AT_AVAILABLE = 1, 57 AT_AVAILABLE = 1,
56 AT_NOTAVAILABLE 58 AT_NOTAVAILABLE
57} GSM_AT_SMSMemory; 59} GSM_AT_SMSMemory;
58 60
59typedef enum { 61typedef enum {
60 AT_SBNR_AVAILABLE = 1, 62 AT_SBNR_AVAILABLE = 1,
61 AT_SBNR_NOTAVAILABLE 63 AT_SBNR_NOTAVAILABLE
62} GSM_AT_SBNR; 64} GSM_AT_SBNR;
63 65
64typedef enum { 66typedef enum {
65 AT_Status, 67 AT_Status,
66 AT_NextEmpty, 68 AT_NextEmpty,
67 AT_Total, 69 AT_Total,
68 AT_First, 70 AT_First,
69 AT_Sizes 71 AT_Sizes
70} GSM_AT_NeededMemoryInfo; 72} GSM_AT_NeededMemoryInfo;
71 73
72 #define AT_PBK_MAX_MEMORIES200 74 #define AT_PBK_MAX_MEMORIES200
73 75
74typedef struct { 76typedef struct {
75 GSM_AT_Manufacturer Manufacturer; /* Who is manufacturer */ 77 GSM_AT_Manufacturer Manufacturer; /* Who is manufacturer */
76 GSM_Lines Lines; /* Allow to simply get each line in response */ 78 GSM_Lines Lines; /* Allow to simply get each line in response */
77 GSM_AT_Reply_State ReplyState; /* What response type - error, OK, etc. */ 79 GSM_AT_Reply_State ReplyState; /* What response type - error, OK, etc. */
78 int ErrorCode; /* Error codes from responses */ 80 int ErrorCode; /* Error codes from responses */
79 char *ErrorText; /* Error description */ 81 char *ErrorText; /* Error description */
80 82
81 GSM_MemoryType PBKMemory; /* Last read PBK memory */ 83 GSM_MemoryType PBKMemory; /* Last read PBK memory */
82 char PBKMemories[AT_PBK_MAX_MEMORIES + 1]; /* Supported by phone PBK memories */ 84 char PBKMemories[AT_PBK_MAX_MEMORIES + 1]; /* Supported by phone PBK memories */
83 int NextMemoryEntry; /* Next empty memory entry */ 85 int NextMemoryEntry; /* Next empty memory entry */
84 int FirstMemoryEntry; /* First memory entry to be read */ 86 int FirstMemoryEntry; /* First memory entry to be read */
85 GSM_AT_PBK_Charset PBKCharset; /* Last read PBK charset */ 87 GSM_AT_PBK_Charset PBKCharset; /* Last read PBK charset */
86 bool UCS2CharsetFailed; /* Whether setting of UCS2 charset has already failed */ 88 bool UCS2CharsetFailed; /* Whether setting of UCS2 charset has already failed */
87 bool NonUCS2CharsetFailed; /* Whether setting of non-UCS2 charset has already failed */ 89 bool NonUCS2CharsetFailed; /* Whether setting of non-UCS2 charset has already failed */
88 GSM_AT_SBNR PBKSBNR; 90 GSM_AT_SBNR PBKSBNR;
89 int NumberLength; 91 int NumberLength;
90 int TextLength; 92 int TextLength;
91 int MemorySize; 93 int MemorySize;
92 94
93 GSM_SMSMemoryStatusLastSMSStatus; 95 GSM_SMSMemoryStatusLastSMSStatus;
94 int LastSMSRead; 96 int LastSMSRead;
95 int FirstCalendarPos; 97 int FirstCalendarPos;
96 bool CanSaveSMS; 98 bool CanSaveSMS;
97 GSM_AT_SMSMemory PhoneSMSMemory; /* Is phone SMS memory available ? */ 99 GSM_AT_SMSMemory PhoneSMSMemory; /* Is phone SMS memory available ? */
98 GSM_AT_SMSMemory SIMSMSMemory; /* Is SIM SMS memory available ? */ 100 GSM_AT_SMSMemory SIMSMSMemory; /* Is SIM SMS memory available ? */
99 GSM_MemoryType SMSMemory; /* Last read SMS memory */ 101 GSM_MemoryType SMSMemory; /* Last read SMS memory */
100 GSM_AT_SMS_Modes SMSMode; /* PDU or TEXT mode for SMS ? */ 102 GSM_AT_SMS_Modes SMSMode; /* PDU or TEXT mode for SMS ? */
101 103
102 bool OBEX; 104 bool OBEX;
103 GSM_File file; 105 GSM_File file;
104} GSM_Phone_ATGENData; 106} GSM_Phone_ATGENData;
105 107
108 GSM_Error ATGEN_HandleCMSError(GSM_StateMachine *);
109 GSM_Error ATGEN_HandleCMEError(GSM_StateMachine *);
110 GSM_Error ATGEN_DispatchMessage(GSM_StateMachine *);
111
106#endif 112#endif
107 113
108/* How should editor hadle tabs in this file? Add editor commands here. 114/* How should editor hadle tabs in this file? Add editor commands here.
109 * vim: noexpandtab sw=8 ts=8 sts=8: 115 * vim: noexpandtab sw=8 ts=8 sts=8:
110 */ 116 */
diff --git a/gammu/emb/common/phone/at/samsung.c b/gammu/emb/common/phone/at/samsung.c
new file mode 100644
index 0000000..55a42e5
--- a/dev/null
+++ b/gammu/emb/common/phone/at/samsung.c
@@ -0,0 +1,447 @@
1/* Samsung-specific functions
2 * Copyright (C) 2004 Claudio Matsuoka <cmatsuoka@gmail.com>
3 * Tested with S300 only!
4 */
5
6#include "../../gsmstate.h"
7
8#ifdef GSM_ENABLE_ATGEN
9
10#include <string.h>
11#include <time.h>
12#include <ctype.h>
13
14#include "../../misc/coding/coding.h"
15#include "../../gsmcomon.h"
16#include "../../service/sms/gsmsms.h"
17#include "../pfunc.h"
18
19#include "atgen.h"
20#include "samsung.h"
21
22/* Binary frame size */
23#define BLKSZ 1024
24
25struct ModelRes {
26 char *model;
27 int width;
28 int height;
29};
30
31static struct ModelRes modres[] = {
32 { "S100", 128, 128 },
33 { "S200", 128, 113 },
34 { "S300", 128, 97 },
35 { "S500", 128, 128 },
36 { "T100", 128, 128 },
37 { "E700", 128, 128 },
38 { NULL, 0, 0 }
39};
40
41/*
42 * CRC functions from the Granch SBNI12 Linux driver by
43 * Denis I. Timofeev <timofeev@granch.ru>
44 */
45static unsigned int crc32tab[] = {
46 0xD202EF8D, 0xA505DF1B, 0x3C0C8EA1, 0x4B0BBE37,
47 0xD56F2B94, 0xA2681B02, 0x3B614AB8, 0x4C667A2E,
48 0xDCD967BF, 0xABDE5729, 0x32D70693, 0x45D03605,
49 0xDBB4A3A6, 0xACB39330, 0x35BAC28A, 0x42BDF21C,
50 0xCFB5FFE9, 0xB8B2CF7F, 0x21BB9EC5, 0x56BCAE53,
51 0xC8D83BF0, 0xBFDF0B66, 0x26D65ADC, 0x51D16A4A,
52 0xC16E77DB, 0xB669474D, 0x2F6016F7, 0x58672661,
53 0xC603B3C2, 0xB1048354, 0x280DD2EE, 0x5F0AE278,
54 0xE96CCF45, 0x9E6BFFD3, 0x0762AE69, 0x70659EFF,
55 0xEE010B5C, 0x99063BCA, 0x000F6A70, 0x77085AE6,
56 0xE7B74777, 0x90B077E1, 0x09B9265B, 0x7EBE16CD,
57 0xE0DA836E, 0x97DDB3F8, 0x0ED4E242, 0x79D3D2D4,
58 0xF4DBDF21, 0x83DCEFB7, 0x1AD5BE0D, 0x6DD28E9B,
59 0xF3B61B38, 0x84B12BAE, 0x1DB87A14, 0x6ABF4A82,
60 0xFA005713, 0x8D076785, 0x140E363F, 0x630906A9,
61 0xFD6D930A, 0x8A6AA39C, 0x1363F226, 0x6464C2B0,
62 0xA4DEAE1D, 0xD3D99E8B, 0x4AD0CF31, 0x3DD7FFA7,
63 0xA3B36A04, 0xD4B45A92, 0x4DBD0B28, 0x3ABA3BBE,
64 0xAA05262F, 0xDD0216B9, 0x440B4703, 0x330C7795,
65 0xAD68E236, 0xDA6FD2A0, 0x4366831A, 0x3461B38C,
66 0xB969BE79, 0xCE6E8EEF, 0x5767DF55, 0x2060EFC3,
67 0xBE047A60, 0xC9034AF6, 0x500A1B4C, 0x270D2BDA,
68 0xB7B2364B, 0xC0B506DD, 0x59BC5767, 0x2EBB67F1,
69 0xB0DFF252, 0xC7D8C2C4, 0x5ED1937E, 0x29D6A3E8,
70 0x9FB08ED5, 0xE8B7BE43, 0x71BEEFF9, 0x06B9DF6F,
71 0x98DD4ACC, 0xEFDA7A5A, 0x76D32BE0, 0x01D41B76,
72 0x916B06E7, 0xE66C3671, 0x7F6567CB, 0x0862575D,
73 0x9606C2FE, 0xE101F268, 0x7808A3D2, 0x0F0F9344,
74 0x82079EB1, 0xF500AE27, 0x6C09FF9D, 0x1B0ECF0B,
75 0x856A5AA8, 0xF26D6A3E, 0x6B643B84, 0x1C630B12,
76 0x8CDC1683, 0xFBDB2615, 0x62D277AF, 0x15D54739,
77 0x8BB1D29A, 0xFCB6E20C, 0x65BFB3B6, 0x12B88320,
78 0x3FBA6CAD, 0x48BD5C3B, 0xD1B40D81, 0xA6B33D17,
79 0x38D7A8B4, 0x4FD09822, 0xD6D9C998, 0xA1DEF90E,
80 0x3161E49F, 0x4666D409, 0xDF6F85B3, 0xA868B525,
81 0x360C2086, 0x410B1010, 0xD80241AA, 0xAF05713C,
82 0x220D7CC9, 0x550A4C5F, 0xCC031DE5, 0xBB042D73,
83 0x2560B8D0, 0x52678846, 0xCB6ED9FC, 0xBC69E96A,
84 0x2CD6F4FB, 0x5BD1C46D, 0xC2D895D7, 0xB5DFA541,
85 0x2BBB30E2, 0x5CBC0074, 0xC5B551CE, 0xB2B26158,
86 0x04D44C65, 0x73D37CF3, 0xEADA2D49, 0x9DDD1DDF,
87 0x03B9887C, 0x74BEB8EA, 0xEDB7E950, 0x9AB0D9C6,
88 0x0A0FC457, 0x7D08F4C1, 0xE401A57B, 0x930695ED,
89 0x0D62004E, 0x7A6530D8, 0xE36C6162, 0x946B51F4,
90 0x19635C01, 0x6E646C97, 0xF76D3D2D, 0x806A0DBB,
91 0x1E0E9818, 0x6909A88E, 0xF000F934, 0x8707C9A2,
92 0x17B8D433, 0x60BFE4A5, 0xF9B6B51F, 0x8EB18589,
93 0x10D5102A, 0x67D220BC, 0xFEDB7106, 0x89DC4190,
94 0x49662D3D, 0x3E611DAB, 0xA7684C11, 0xD06F7C87,
95 0x4E0BE924, 0x390CD9B2, 0xA0058808, 0xD702B89E,
96 0x47BDA50F, 0x30BA9599, 0xA9B3C423, 0xDEB4F4B5,
97 0x40D06116, 0x37D75180, 0xAEDE003A, 0xD9D930AC,
98 0x54D13D59, 0x23D60DCF, 0xBADF5C75, 0xCDD86CE3,
99 0x53BCF940, 0x24BBC9D6, 0xBDB2986C, 0xCAB5A8FA,
100 0x5A0AB56B, 0x2D0D85FD, 0xB404D447, 0xC303E4D1,
101 0x5D677172, 0x2A6041E4, 0xB369105E, 0xC46E20C8,
102 0x72080DF5, 0x050F3D63, 0x9C066CD9, 0xEB015C4F,
103 0x7565C9EC, 0x0262F97A, 0x9B6BA8C0, 0xEC6C9856,
104 0x7CD385C7, 0x0BD4B551, 0x92DDE4EB, 0xE5DAD47D,
105 0x7BBE41DE, 0x0CB97148, 0x95B020F2, 0xE2B71064,
106 0x6FBF1D91, 0x18B82D07, 0x81B17CBD, 0xF6B64C2B,
107 0x68D2D988, 0x1FD5E91E, 0x86DCB8A4, 0xF1DB8832,
108 0x616495A3, 0x1663A535, 0x8F6AF48F, 0xF86DC419,
109 0x660951BA, 0x110E612C, 0x88073096, 0xFF000000
110};
111
112static unsigned int GetCRC(char *data, int size)
113{
114 unsigned int crc = 0;
115
116 while (size--)
117 crc = crc32tab[(crc ^ *data++) & 0xff] ^ ((crc >> 8) & 0x00FFFFFF);
118
119 return crc;
120}
121
122/*
123 * Frame transfer
124 */
125
126static GSM_Error WaitFor(GSM_StateMachine *s, char *t, int ttl)
127{
128 char readbuf[100];
129 int n;
130 unsigned int sec;
131 GSM_DateTime Date;
132
133 GSM_GetCurrentDateTime (&Date);
134 sec = Date.Second;
135
136 n = s->Device.Functions->ReadDevice(s, readbuf, 80);
137 readbuf[n] = 0;
138 while (strstr(readbuf, t) == NULL && (sec + ttl) >= Date.Second) {
139 my_sleep(5000);
140 n = s->Device.Functions->ReadDevice(s, readbuf, 80);
141 readbuf[n] = 0;
142 GSM_GetCurrentDateTime (&Date);
143 }
144
145 return (sec + ttl) >= Date.Second ? ERR_NONE : ERR_TIMEOUT;
146}
147
148static GSM_Error SetSamsungFrame(GSM_StateMachine *s, unsigned char *buff, int size, GSM_Phone_RequestID id)
149{
150 GSM_Phone_Data *Phone = &s->Phone.Data;
151 GSM_Error error;
152 int i, count;
153
154 count = size / BLKSZ;
155
156 for (i = 0; i < count; i++) {
157 error = WaitFor(s, ">", 4);
158 if (error!=ERR_NONE) return error;
159
160 error = s->Protocol.Functions->WriteMessage(s,
161 buff + i * BLKSZ, BLKSZ, 0x00);
162 if (error!=ERR_NONE) return error;
163 }
164
165 error = WaitFor(s, ">", 4);
166 if (error!=ERR_NONE) return error;
167 error = s->Protocol.Functions->WriteMessage(s,
168 buff + i * BLKSZ, size%BLKSZ, 0x00);
169 if (error!=ERR_NONE) return error;
170
171 error = GSM_WaitFor(s, "", 0, 0x00, 4, id);
172 if (error!=ERR_NONE) return error;
173
174 return Phone->DispatchError;
175}
176
177/* Answer format for binary data transfer
178 *
179 * SDNDCRC = 0xa : RECEIVECRC = 0xcbf53a1c : BINSIZE = 5
180 * CRCERR
181 */
182static GSM_Error ReplySetSamsungFrame(GSM_Protocol_Message msg, GSM_StateMachine *s)
183{
184 unsigned long txcrc, rxcrc;
185 int binsize;
186 char *pos;
187
188 /* Parse SDNDCRC */
189 pos = strchr(msg.Buffer, '=');
190 if (!pos) return ERR_UNKNOWN;
191 pos++;
192 txcrc = strtoul(pos, NULL, 0);
193 smprintf(s, "Sent CRC : 0x%lx\n", txcrc);
194
195 /* Parse RECEIVECRC */
196 pos = strchr(pos, '=');
197 if (!pos) return ERR_UNKNOWN;
198 pos++;
199 rxcrc = strtoul(pos, NULL, 0);
200 smprintf(s, "Reveived CRC : 0x%lx\n", rxcrc);
201
202 /* Parse BINSIZE */
203 pos = strchr(pos, '=');
204 if (!pos) return ERR_UNKNOWN;
205 pos++;
206 binsize = strtoul(pos, NULL, 0);
207 smprintf(s, "Binary size : %d\n", binsize);
208
209 return txcrc == rxcrc ? ERR_NONE : ERR_WRONGCRC;
210}
211
212/*
213 * Bitmaps
214 */
215
216GSM_Error SAMSUNG_ReplyGetBitmap(GSM_Protocol_Message msg, GSM_StateMachine *s)
217{
218 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
219 unsigned char buffer[32];
220 char *pos;
221 int location, count;
222
223 switch (Priv->ReplyState) {
224 case AT_Reply_OK:
225 smprintf(s, "Bitmap info received\n");
226 /* Parse +IMGR:location,name,0,0,0,0 */
227
228 /* Parse location */
229 pos = strchr(msg.Buffer, ':');
230 if (!pos) return ERR_UNKNOWN;
231 pos++;
232 location = atoi(pos);
233 smprintf(s, "Location : %d\n", location);
234
235 /* Parse name */
236 pos = strchr(pos, '"');
237 if (!pos) return ERR_UNKNOWN;
238 pos++;
239 for (count = 0; count < 31; count++) {
240 if (pos[count] == '"')
241 break;
242 buffer[count] = pos[count];
243 }
244 buffer[count] = 0;
245 smprintf(s, "Name : %s\n", buffer);
246 s->Phone.Data.Bitmap->Name = malloc((strlen(buffer) + 1) * 2);
247 if (s->Phone.Data.Bitmap->Name == NULL)
248 return ERR_MOREMEMORY;
249 EncodeUnicode(s->Phone.Data.Bitmap->Name, buffer, strlen(buffer));
250
251 s->Phone.Data.Bitmap->Location = location;
252
253 return ERR_NONE;
254 case AT_Reply_Error:
255 return ERR_UNKNOWN;
256 case AT_Reply_CMSError:
257 return ATGEN_HandleCMSError(s);
258 case AT_Reply_CMEError:
259 return ATGEN_HandleCMEError(s);
260 default:
261 return ERR_UNKNOWNRESPONSE;
262 }
263}
264
265GSM_Error SAMSUNG_ReplySetBitmap(GSM_Protocol_Message msg, GSM_StateMachine *s)
266{
267 smprintf(s, "Bitmap sent\n");
268 return ReplySetSamsungFrame(msg, s);
269}
270
271GSM_Error SAMSUNG_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
272{
273 unsigned char req[100];
274
275 s->Phone.Data.Bitmap=Bitmap;
276 smprintf(s, "Getting bitmap\n");
277 sprintf(req, "AT+IMGR=%d\r", Bitmap->Location-1);
278 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetBitmap);
279}
280
281GSM_Error SAMSUNG_SetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
282{
283 unsigned charreq[100];
284 unsigned longcrc;
285 GSM_Errorerror;
286 char name[50], *dot, *model;
287 GSM_Phone_Data *Data = &s->Phone.Data;
288 int i;
289
290 s->Phone.Data.Bitmap = Bitmap;
291 smprintf(s, "Setting bitmap\n");
292
293 if (Bitmap->Type != GSM_PictureBinary) {
294 smprintf(s, "Invalid picture type\n");
295 return ERR_INVALIDDATA;
296 }
297
298 if (Bitmap->BinaryPic.Type != PICTURE_GIF) {
299 smprintf(s, "Invalid binary picture type\n");
300 return ERR_INVALIDDATA;
301 }
302
303 /* Check if picture size matches phone model */
304 model = GetModelData(NULL,Data->Model,NULL)->model;
305 smprintf(s, "Checking picture size for %s\n", model);
306 for (i = 0; modres[i].model; i++) {
307 if (!strcmp(model, modres[i].model)) {
308 if (Bitmap->BitmapWidth != modres[i].width ||
309 Bitmap->BitmapHeight != modres[i].height) {
310 smprintf(s, "Model %s must use %d x %d picture size\n",
311 modres[i].model, modres[i].width,
312 modres[i].height);
313 return ERR_INVALIDDATA;
314 }
315 break;
316 }
317 }
318 if (modres[i].model == NULL) {
319 smprintf(s, "Model \"%s\" is not supported.\n", Data->Model);
320 return ERR_NOTSUPPORTED;
321 }
322
323 crc = GetCRC(Bitmap->BinaryPic.Buffer, Bitmap->BinaryPic.Length);
324
325 /* Remove extension from file name */
326 strncpy(name, DecodeUnicodeString(Bitmap->Name), 50);
327 if ((dot = strrchr(name, '.')) != NULL)
328 *dot = 0;
329
330 sprintf(req, "AT+IMGW=0,\"%s\",2,0,0,0,0,100,%d,%u\r", name,
331 Bitmap->BinaryPic.Length, (unsigned int)crc);
332
333 error = s->Protocol.Functions->WriteMessage(s, req, strlen(req), 0x00);
334 if (error!=ERR_NONE) return error;
335
336 return SetSamsungFrame(s, Bitmap->BinaryPic.Buffer,
337 Bitmap->BinaryPic.Length, ID_SetBitmap);
338}
339
340/*
341 * Ringtones
342 */
343
344GSM_Error SAMSUNG_ReplyGetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s)
345{
346 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
347 unsigned char buffer[32];
348 char *pos;
349 int location, length, count;
350
351 switch (Priv->ReplyState) {
352 case AT_Reply_OK:
353 smprintf(s, "Ringtone info received\n");
354 /* Parse +MELR:location,name,size */
355
356 /* Parse location */
357 pos = strchr(msg.Buffer, ':');
358 if (!pos) return ERR_UNKNOWN;
359 pos++;
360 location = atoi(pos);
361 smprintf(s, "Location : %d\n", location);
362
363 /* Parse name */
364 pos = strchr(pos, '"');
365 if (!pos) return ERR_UNKNOWN;
366 pos++;
367 /* Ringtone.Name size is 20 chars */
368 for (count = 0; count < 19; count++) {
369 if (pos[count] == '"')
370 break;
371 buffer[count] = pos[count];
372 }
373 buffer[count] = 0;
374 smprintf(s, "Name : %s\n", buffer);
375 EncodeUnicode(s->Phone.Data.Ringtone->Name,buffer,strlen(buffer));
376
377 /* Parse ringtone length */
378 pos = strchr(pos, ',');
379 if (!pos) return ERR_UNKNOWN;
380 pos++;
381 length = atoi(pos);
382 smprintf(s, "Length : %d\n", length);
383
384 /* S300 ringtones are always MMF */
385 s->Phone.Data.Ringtone->Format = RING_MMF;
386 s->Phone.Data.Ringtone->Location = location;
387 s->Phone.Data.Ringtone->BinaryTone.Length = length;
388
389 return ERR_NONE;
390 case AT_Reply_Error:
391 return ERR_UNKNOWN;
392 case AT_Reply_CMSError:
393 return ATGEN_HandleCMSError(s);
394 case AT_Reply_CMEError:
395 return ATGEN_HandleCMEError(s);
396 default:
397 return ERR_UNKNOWNRESPONSE;
398 }
399}
400
401GSM_Error SAMSUNG_GetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone)
402{
403 unsigned char req[100];
404
405 s->Phone.Data.Ringtone = Ringtone;
406 smprintf(s, "Getting ringtone\n");
407 sprintf(req, "AT+MELR=%d\r", Ringtone->Location-1);
408 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetRingtone);
409}
410
411GSM_Error SAMSUNG_ReplySetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s)
412{
413 smprintf(s, "Ringtone sent\n");
414 return ReplySetSamsungFrame(msg, s);
415}
416
417GSM_Error SAMSUNG_SetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength)
418{
419 unsigned charreq[100];
420 unsigned longcrc;
421 GSM_Errorerror;
422 char name[50], *dot;
423
424 s->Phone.Data.Ringtone = Ringtone;
425 smprintf(s, "Setting ringtone\n");
426
427 if (Ringtone->Format != RING_MMF) {
428 smprintf(s, "Not MMF ringtone\n");
429 return ERR_INVALIDDATA;
430 }
431
432 /* Remove extension from file name */
433 strncpy(name, DecodeUnicodeString(Ringtone->Name), 50);
434 if ((dot = strrchr(name, '.')) != NULL) *dot = 0;
435
436 crc = GetCRC(Ringtone->BinaryTone.Buffer, Ringtone->BinaryTone.Length);
437 sprintf(req, "AT+MELW=0,\"%s\",4,%d,%u\r", name,
438 Ringtone->BinaryTone.Length, (unsigned int)crc);
439
440 error = s->Protocol.Functions->WriteMessage(s, req, strlen(req), 0x00);
441 if (error!=ERR_NONE) return error;
442
443 return SetSamsungFrame(s, Ringtone->BinaryTone.Buffer,
444 Ringtone->BinaryTone.Length, ID_SetRingtone);
445}
446
447#endif
diff --git a/gammu/emb/common/phone/at/samsung.h b/gammu/emb/common/phone/at/samsung.h
new file mode 100644
index 0000000..3b2947c
--- a/dev/null
+++ b/gammu/emb/common/phone/at/samsung.h
@@ -0,0 +1,16 @@
1#ifndef samsung_h
2#define samsung_h
3
4#include "../../gsmstate.h"
5
6 GSM_Error SAMSUNG_ReplyGetRingtone(GSM_Protocol_Message, GSM_StateMachine *);
7 GSM_Error SAMSUNG_ReplySetRingtone(GSM_Protocol_Message, GSM_StateMachine *);
8 GSM_Error SAMSUNG_ReplyGetBitmap(GSM_Protocol_Message, GSM_StateMachine *);
9 GSM_Error SAMSUNG_ReplySetBitmap(GSM_Protocol_Message, GSM_StateMachine *);
10 GSM_Error SAMSUNG_GetRingtone (GSM_StateMachine *, GSM_Ringtone *, bool);
11 GSM_Error SAMSUNG_SetRingtone (GSM_StateMachine *, GSM_Ringtone *, int *);
12 GSM_Error SAMSUNG_GetBitmap (GSM_StateMachine *, GSM_Bitmap *);
13 GSM_Error SAMSUNG_SetBitmap (GSM_StateMachine *, GSM_Bitmap *);
14 GSM_Error SAMSUNG_GetCallLogs (GSM_StateMachine *, GSM_MemoryEntry *, int);
15
16#endif
diff --git a/gammu/emb/common/phone/at/siemens.c b/gammu/emb/common/phone/at/siemens.c
index ab7dd2c..7f66cf8 100644
--- a/gammu/emb/common/phone/at/siemens.c
+++ b/gammu/emb/common/phone/at/siemens.c
@@ -1,320 +1,316 @@
1/* (c) 2002-2003 by Walek */ 1/* (c) 2002-2003 by Walek */
2 2
3#include "../../gsmstate.h" 3#include "../../gsmstate.h"
4 4
5#ifdef GSM_ENABLE_ATGEN 5#ifdef GSM_ENABLE_ATGEN
6 6
7#include <string.h> 7#include <string.h>
8#include <time.h> 8#include <time.h>
9#include <ctype.h> 9#include <ctype.h>
10 10
11#include "../../misc/coding/coding.h" 11#include "../../misc/coding/coding.h"
12#include "../../gsmcomon.h" 12#include "../../gsmcomon.h"
13#include "../../service/sms/gsmsms.h" 13#include "../../service/sms/gsmsms.h"
14#include "../pfunc.h" 14#include "../pfunc.h"
15 15
16extern GSM_Error ATGEN_HandleCMSError(GSM_StateMachine *s); 16#include "atgen.h"
17#include "siemens.h"
17 18
18GSM_Error ATGEN_CMS35ReplySetFunction (GSM_Protocol_Message msg, GSM_StateMachine *s,char *function)
19{
20 if (s->Protocol.Data.AT.EditMode) {
21 s->Protocol.Data.AT.EditMode = false;
22 return ERR_NONE;
23 }
24 dbgprintf ("Written %s",function);
25 if (s->Phone.Data.Priv.ATGEN.ReplyState == AT_Reply_OK){
26 dbgprintf (" - OK\n");
27 return ERR_NONE;
28 } else {
29 dbgprintf (" - error\n");
30 return ERR_UNKNOWN;
31 }
32}
33 19
34GSM_Error GetSiemensFrame(GSM_Protocol_Message msg, GSM_StateMachine *s, char *templ, 20static GSM_Error GetSiemensFrame(GSM_Protocol_Message msg, GSM_StateMachine *s, char *templ,
35 unsigned char *buffer, int *len) 21 unsigned char *buffer, int *len)
36{ 22{
37 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 23 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
38 int i=2, pos=0, length=0; 24 int i=2, pos=0, length=0;
39 unsigned char buf[512]; 25 unsigned char buf[512];
40 26
41 if (strstr(GetLineString(msg.Buffer,Priv->Lines,2),"OK")) return ERR_EMPTY; 27 if (strstr(GetLineString(msg.Buffer,Priv->Lines,2),"OK")) return ERR_EMPTY;
42 if (!strstr(GetLineString(msg.Buffer,Priv->Lines,2),templ)) return ERR_UNKNOWN; 28 if (!strstr(GetLineString(msg.Buffer,Priv->Lines,2),templ)) return ERR_UNKNOWN;
43 29
44 while (1) { 30 while (1) {
45 if (Priv->Lines.numbers[i*2+1]==0) break; 31 if (Priv->Lines.numbers[i*2+1]==0) break;
46 if ((!strstr(GetLineString(msg.Buffer,Priv->Lines,i+1),templ)) && 32 if ((!strstr(GetLineString(msg.Buffer,Priv->Lines,i+1),templ)) &&
47 (strstr(GetLineString(msg.Buffer,Priv->Lines,i),templ))){ 33 (strstr(GetLineString(msg.Buffer,Priv->Lines,i),templ))){
48 length = strlen(GetLineString(msg.Buffer,Priv->Lines,i+1)); 34 length = strlen(GetLineString(msg.Buffer,Priv->Lines,i+1));
49 DecodeHexBin(buf, GetLineString(msg.Buffer,Priv->Lines,i+1),length); 35 DecodeHexBin(buf, GetLineString(msg.Buffer,Priv->Lines,i+1),length);
50 length = length/2; 36 length = length/2;
51 memcpy (buffer+pos,buf,length); 37 memcpy (buffer+pos,buf,length);
52 pos+=length; 38 pos+=length;
53 } 39 }
54 i++; 40 i++;
55 } 41 }
56 *len = pos; 42 *len = pos;
57 return ERR_NONE; 43 return ERR_NONE;
58} 44}
59 45
60GSM_Error SetSiemensFrame (GSM_StateMachine *s, unsigned char *buff, char *templ, 46static GSM_Error SetSiemensFrame (GSM_StateMachine *s, unsigned char *buff, char *templ,
61 int Location, GSM_Phone_RequestID RequestID, int len) 47 int Location, GSM_Phone_RequestID RequestID, int len)
62{ 48{
63 GSM_Phone_Data *Phone = &s->Phone.Data; 49 GSM_Phone_Data *Phone = &s->Phone.Data;
64 GSM_Error error; 50 GSM_Error error;
65 unsigned char req[20],req1[512],hexreq[2096]; 51 unsigned char req[20],req1[512],hexreq[2096];
66 int MaxFrame,CurrentFrame,size,sz,pos=0; 52 int MaxFrame,CurrentFrame,size,sz,pos=0;
67 53
68 EncodeHexBin(hexreq,buff,len); 54 EncodeHexBin(hexreq,buff,len);
69 size = len * 2; 55 size = len * 2;
70 MaxFrame = size / 352; 56 MaxFrame = size / 352;
71 if (size % 352) MaxFrame++; 57 if (size % 352) MaxFrame++;
72 58
73 for (CurrentFrame=0;CurrentFrame<MaxFrame;CurrentFrame++) { 59 for (CurrentFrame=0;CurrentFrame<MaxFrame;CurrentFrame++) {
74 pos=CurrentFrame*352; 60 pos=CurrentFrame*352;
75 if (pos+352 < size) sz = 352; else sz = size - pos; 61 if (pos+352 < size) sz = 352; else sz = size - pos;
76 sprintf(req, "AT^SBNW=\"%s\",%i,%i,%i\r",templ,Location,CurrentFrame+1,MaxFrame); 62 sprintf(req, "AT^SBNW=\"%s\",%i,%i,%i\r",templ,Location,CurrentFrame+1,MaxFrame);
77 s->Protocol.Data.AT.EditMode = true; 63 s->Protocol.Data.AT.EditMode = true;
78 error = GSM_WaitFor (s, req, strlen(req), 0x00, 3, RequestID); 64 error = GSM_WaitFor (s, req, strlen(req), 0x00, 3, RequestID);
79 s->Phone.Data.DispatchError=ERR_TIMEOUT; 65 s->Phone.Data.DispatchError=ERR_TIMEOUT;
80 s->Phone.Data.RequestID=RequestID; 66 s->Phone.Data.RequestID=RequestID;
81 if (error!=ERR_NONE) return error; 67 if (error!=ERR_NONE) return error;
82 memcpy (req1,hexreq+pos,sz); 68 memcpy (req1,hexreq+pos,sz);
83 error = s->Protocol.Functions->WriteMessage(s, req1, sz, 0x00); 69 error = s->Protocol.Functions->WriteMessage(s, req1, sz, 0x00);
84 if (error!=ERR_NONE) return error; 70 if (error!=ERR_NONE) return error;
85 error = s->Protocol.Functions->WriteMessage(s,"\x1A", 1, 0x00); 71 error = s->Protocol.Functions->WriteMessage(s,"\x1A", 1, 0x00);
86 if (error!=ERR_NONE) return error; 72 if (error!=ERR_NONE) return error;
87 error = GSM_WaitForOnce(s, NULL, 0x00, 0x00, 4); 73 error = GSM_WaitForOnce(s, NULL, 0x00, 0x00, 4);
88 if (error == ERR_TIMEOUT) return error; 74 if (error == ERR_TIMEOUT) return error;
89 } 75 }
90 return Phone->DispatchError; 76 return Phone->DispatchError;
91} 77}
92 78
93GSM_Error ATGEN_CMS35ReplyGetBitmap(GSM_Protocol_Message msg, GSM_StateMachine *s) 79GSM_Error SIEMENS_ReplyGetBitmap(GSM_Protocol_Message msg, GSM_StateMachine *s)
94{ 80{
95 unsigned char buffer[4096]; 81 unsigned char buffer[4096];
96 int length; 82 int length;
97 GSM_Error error; 83 GSM_Error error;
98 84
99 error = GetSiemensFrame(msg,s,"bmp",buffer,&length); 85 error = GetSiemensFrame(msg,s,"bmp",buffer,&length);
100 if (error!=ERR_NONE) return error; 86 if (error!=ERR_NONE) return error;
101 dbgprintf ("Operator logo received lenght=%i\n",length); 87 dbgprintf ("Operator logo received lenght=%i\n",length);
102 error = BMP2Bitmap (buffer,NULL,s->Phone.Data.Bitmap); 88 error = BMP2Bitmap (buffer,NULL,s->Phone.Data.Bitmap);
103 if (error==ERR_NONE) return error; 89 if (error==ERR_NONE) return error;
104 else return ERR_UNKNOWN; 90 else return ERR_UNKNOWN;
105} 91}
106 92
107GSM_Error ATGEN_CMS35ReplySetBitmap(GSM_Protocol_Message msg, GSM_StateMachine *s) 93GSM_Error SIEMENS_ReplySetFunction (GSM_Protocol_Message msg, GSM_StateMachine *s,char *function)
108{ 94{
109 return ATGEN_CMS35ReplySetFunction (msg, s, "Operator Logo"); 95 if (s->Protocol.Data.AT.EditMode) {
96 s->Protocol.Data.AT.EditMode = false;
97 return ERR_NONE;
98 }
99 dbgprintf ("Written %s",function);
100 if (s->Phone.Data.Priv.ATGEN.ReplyState == AT_Reply_OK){
101 dbgprintf (" - OK\n");
102 return ERR_NONE;
103 } else {
104 dbgprintf (" - error\n");
105 return ERR_UNKNOWN;
106 }
110} 107}
111 108
112GSM_Error ATGEN_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap) 109GSM_Error SIEMENS_ReplySetBitmap(GSM_Protocol_Message msg, GSM_StateMachine *s)
110{
111 return SIEMENS_ReplySetFunction (msg, s, "Operator Logo");
112}
113
114GSM_Error SIEMENS_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
113{ 115{
114 unsigned char req[32]; 116 unsigned char req[32];
115 117
116 if (s->Phone.Data.Priv.ATGEN.Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED;
117 if (Bitmap->Type!=GSM_OperatorLogo) return ERR_NOTSUPPORTED; 118 if (Bitmap->Type!=GSM_OperatorLogo) return ERR_NOTSUPPORTED;
118 if (Bitmap->Location-1 < 0) Bitmap->Location++; 119 if (Bitmap->Location-1 < 0) Bitmap->Location++;
119 s->Phone.Data.Bitmap=Bitmap; 120 s->Phone.Data.Bitmap=Bitmap;
120 sprintf(req, "AT^SBNR=\"bmp\",%i\r", Bitmap->Location-1); 121 sprintf(req, "AT^SBNR=\"bmp\",%i\r", Bitmap->Location-1);
121 smprintf(s, "Getting Bitmap\n"); 122 smprintf(s, "Getting Bitmap\n");
122 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetBitmap); 123 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetBitmap);
123} 124}
124 125
125GSM_Error ATGEN_SetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap) 126GSM_Error SIEMENS_SetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
126{ 127{
127 unsigned char buffer[4096]; 128 unsigned char buffer[4096];
128 int length; 129 int length;
129 GSM_Errorerror; 130 GSM_Errorerror;
130 131
131 if (s->Phone.Data.Priv.ATGEN.Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED;
132 if (Bitmap->Type!=GSM_OperatorLogo) return ERR_NOTSUPPORTED; 132 if (Bitmap->Type!=GSM_OperatorLogo) return ERR_NOTSUPPORTED;
133 133
134 error = Bitmap2BMP (buffer,NULL,Bitmap); 134 error = Bitmap2BMP (buffer,NULL,Bitmap);
135 if (error!=ERR_NONE) return error; 135 if (error!=ERR_NONE) return error;
136 length = 0x100 * buffer[3] + buffer[2]; 136 length = 0x100 * buffer[3] + buffer[2];
137 buffer[58]=0xff; buffer[59]=0xff; buffer[60]=0xff; 137 buffer[58]=0xff; buffer[59]=0xff; buffer[60]=0xff;
138 if (Bitmap->Location-1 < 0) Bitmap->Location++; 138 if (Bitmap->Location-1 < 0) Bitmap->Location++;
139 s->Phone.Data.Bitmap=Bitmap; 139 s->Phone.Data.Bitmap=Bitmap;
140 return SetSiemensFrame(s, buffer,"bmp",Bitmap->Location-1, 140 return SetSiemensFrame(s, buffer,"bmp",Bitmap->Location-1,
141 ID_SetBitmap,length); 141 ID_SetBitmap,length);
142} 142}
143 143
144GSM_Error ATGEN_CMS35ReplyGetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s) 144GSM_Error SIEMENS_ReplyGetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s)
145{ 145{
146 unsigned char buffer[32]; 146 unsigned char buffer[32];
147 int length; 147 int length;
148 GSM_Error error; 148 GSM_Error error;
149 149
150 error = GetSiemensFrame(msg,s,"mid",s->Phone.Data.Ringtone->NokiaBinary.Frame,&length); 150 error = GetSiemensFrame(msg,s,"mid",s->Phone.Data.Ringtone->NokiaBinary.Frame,&length);
151 if (error!=ERR_NONE) return error; 151 if (error!=ERR_NONE) return error;
152 dbgprintf ("Midi ringtone received\n"); 152 dbgprintf ("Midi ringtone received\n");
153 153
154 s->Phone.Data.Ringtone->Format = RING_MIDI; 154 s->Phone.Data.Ringtone->Format = RING_MIDI;
155 s->Phone.Data.Ringtone->NokiaBinary.Length= length; 155 s->Phone.Data.Ringtone->NokiaBinary.Length= length;
156 sprintf(buffer,"Individual"); 156 sprintf(buffer,"Individual");
157 EncodeUnicode (s->Phone.Data.Ringtone->Name,buffer,strlen(buffer)); 157 EncodeUnicode (s->Phone.Data.Ringtone->Name,buffer,strlen(buffer));
158 return ERR_NONE; 158 return ERR_NONE;
159} 159}
160 160
161GSM_Error ATGEN_GetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone) 161GSM_Error SIEMENS_GetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone)
162{ 162{
163 unsigned char req[32]; 163 unsigned char req[32];
164 164
165 if (s->Phone.Data.Priv.ATGEN.Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED;
166
167 s->Phone.Data.Ringtone=Ringtone; 165 s->Phone.Data.Ringtone=Ringtone;
168 sprintf(req, "AT^SBNR=\"mid\",%i\r", Ringtone->Location-1); 166 sprintf(req, "AT^SBNR=\"mid\",%i\r", Ringtone->Location-1);
169 smprintf(s, "Getting RingTone\n"); 167 smprintf(s, "Getting RingTone\n");
170 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetRingtone); 168 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetRingtone);
171} 169}
172 170
173GSM_Error ATGEN_CMS35ReplySetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s) 171GSM_Error SIEMENS_ReplySetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s)
174{ 172{
175 return ATGEN_CMS35ReplySetFunction (msg, s, "Ringtone"); 173 return SIEMENS_ReplySetFunction (msg, s, "Ringtone");
176} 174}
177 175
178GSM_Error ATGEN_SetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength) 176GSM_Error SIEMENS_SetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength)
179{ 177{
180 GSM_Phone_Data *Phone = &s->Phone.Data; 178 GSM_Phone_Data *Phone = &s->Phone.Data;
181 179
182 if (s->Phone.Data.Priv.ATGEN.Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED;
183
184 if (Ringtone->Location==255) Ringtone->Location=1; 180 if (Ringtone->Location==255) Ringtone->Location=1;
185 if (Ringtone->Location-1 > 1) return ERR_INVALIDLOCATION; 181 if (Ringtone->Location-1 > 1) return ERR_INVALIDLOCATION;
186 182
187 s->Phone.Data.Ringtone= Ringtone; 183 s->Phone.Data.Ringtone= Ringtone;
188 Phone->Ringtone = Ringtone; 184 Phone->Ringtone = Ringtone;
189 return SetSiemensFrame(s, Ringtone->NokiaBinary.Frame,"mid",Ringtone->Location-1, 185 return SetSiemensFrame(s, Ringtone->NokiaBinary.Frame,"mid",Ringtone->Location-1,
190 ID_SetRingtone,Ringtone->NokiaBinary.Length); 186 ID_SetRingtone,Ringtone->NokiaBinary.Length);
191} 187}
192 188
193GSM_Error ATGEN_CMS35ReplyGetNextCal(GSM_Protocol_Message msg, GSM_StateMachine *s) 189GSM_Error SIEMENS_ReplyGetNextCalendar(GSM_Protocol_Message msg, GSM_StateMachine *s)
194{ 190{
195 GSM_Phone_Data *Data = &s->Phone.Data; 191 GSM_Phone_Data *Data = &s->Phone.Data;
196 GSM_CalendarEntry*Calendar = Data->Cal; 192 GSM_CalendarEntry*Calendar = Data->Cal;
197 GSM_ToDoEntry ToDo; 193 GSM_ToDoEntry ToDo;
198 GSM_Error error; 194 GSM_Error error;
199 unsigned char buffer[354]; 195 unsigned char buffer[354];
200 int len, pos=0; 196 int len, pos=0;
201 197
202 if (Data->Priv.ATGEN.ReplyState != AT_Reply_OK) return ERR_UNKNOWN; 198 if (Data->Priv.ATGEN.ReplyState != AT_Reply_OK) return ERR_UNKNOWN;
203 199
204 error = GetSiemensFrame(msg,s,"vcs",buffer,&len); 200 error = GetSiemensFrame(msg,s,"vcs",buffer,&len);
205 if (error!=ERR_NONE) return error; 201 if (error!=ERR_NONE) return error;
206 error=GSM_DecodeVCALENDAR_VTODO(buffer,&pos,Calendar,&ToDo,Siemens_VCalendar,0); 202 error=GSM_DecodeVCALENDAR_VTODO(buffer,&pos,Calendar,&ToDo,Siemens_VCalendar,0);
207 203
208 return error; 204 return error;
209} 205}
210 206
211GSM_Error SIEMENS_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start) 207GSM_Error SIEMENS_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start)
212{ 208{
213 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 209 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
214 GSM_Error error; 210 GSM_Error error;
215 unsigned char req[32]; 211 unsigned char req[32];
216 int Location; 212 int Location;
217 213
218 if (Priv->Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED; 214 if (Priv->Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED;
219 215
220 if (start) Note->Location=Priv->FirstCalendarPos; 216 if (start) Note->Location=Priv->FirstCalendarPos;
221 s->Phone.Data.Cal = Note; 217 s->Phone.Data.Cal = Note;
222 Note->EntriesNum = 0; 218 Note->EntriesNum = 0;
223 smprintf(s, "Getting VCALENDAR\n"); 219 smprintf(s, "Getting VCALENDAR\n");
224 Location = Note->Location; 220 Location = Note->Location;
225 while (1){ 221 while (1){
226 Location++; 222 Location++;
227 sprintf(req, "AT^SBNR=\"vcs\",%i\r",Location); 223 sprintf(req, "AT^SBNR=\"vcs\",%i\r",Location);
228 error = GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetCalendarNote); 224 error = GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_GetCalendarNote);
229 if ((error!=ERR_NONE) && (error!=ERR_EMPTY)) return ERR_INVALIDLOCATION; 225 if ((error!=ERR_NONE) && (error!=ERR_EMPTY)) return ERR_INVALIDLOCATION;
230 Note->Location = Location; 226 Note->Location = Location;
231 Priv->FirstCalendarPos = Location; 227 Priv->FirstCalendarPos = Location;
232 if (Location > MAX_VCALENDAR_LOCATION) return ERR_EMPTY; 228 if (Location > MAX_VCALENDAR_LOCATION) return ERR_EMPTY;
233 if (error==ERR_NONE) return error; 229 if (error==ERR_NONE) return error;
234 } 230 }
235 return error; 231 return error;
236} 232}
237 233
238GSM_Error ATGEN_CMS35ReplySetCalendar(GSM_Protocol_Message msg, GSM_StateMachine *s) 234GSM_Error SIEMENS_ReplyAddCalendarNote(GSM_Protocol_Message msg, GSM_StateMachine *s)
239{ 235{
240 return ATGEN_CMS35ReplySetFunction (msg, s, "Calendar Note"); 236 return SIEMENS_ReplySetFunction (msg, s, "Calendar Note");
241} 237}
242 238
243GSM_Error ATGEN_CMS35ReplyDeleteCalendar(GSM_Protocol_Message msg, GSM_StateMachine *s) 239GSM_Error SIEMENS_ReplyDelCalendarNote(GSM_Protocol_Message msg, GSM_StateMachine *s)
244{ 240{
245 GSM_Phone_Data *Data = &s->Phone.Data; 241 GSM_Phone_Data *Data = &s->Phone.Data;
246 242
247 if (Data->Cal->Location > MAX_VCALENDAR_LOCATION) return ERR_UNKNOWN; 243 if (Data->Cal->Location > MAX_VCALENDAR_LOCATION) return ERR_UNKNOWN;
248 244
249 if (Data->Priv.ATGEN.ReplyState== AT_Reply_OK) { 245 if (Data->Priv.ATGEN.ReplyState== AT_Reply_OK) {
250 smprintf(s, "Calendar note deleted\n"); 246 smprintf(s, "Calendar note deleted\n");
251 return ERR_NONE; 247 return ERR_NONE;
252 } else { 248 } else {
253 smprintf(s, "Can't delete calendar note\n"); 249 smprintf(s, "Can't delete calendar note\n");
254 return ERR_UNKNOWN; 250 return ERR_UNKNOWN;
255 } 251 }
256} 252}
257 253
258GSM_Error SIEMENS_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note) 254GSM_Error SIEMENS_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note)
259{ 255{
260 unsigned char req[32]; 256 unsigned char req[32];
261 257
262 if (s->Phone.Data.Priv.ATGEN.Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED; 258 if (s->Phone.Data.Priv.ATGEN.Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED;
263 s->Phone.Data.Cal = Note; 259 s->Phone.Data.Cal = Note;
264 sprintf(req, "AT^SBNW=\"vcs\",%i,0\r",Note->Location); 260 sprintf(req, "AT^SBNW=\"vcs\",%i,0\r",Note->Location);
265 smprintf(s, "Deleting calendar note\n"); 261 smprintf(s, "Deleting calendar note\n");
266 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_DeleteCalendarNote); 262 return GSM_WaitFor (s, req, strlen(req), 0x00, 4, ID_DeleteCalendarNote);
267} 263}
268 264
269GSM_Error SIEMENS_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note) 265GSM_Error SIEMENS_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note)
270{ 266{
271 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 267 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
272 GSM_Error error; 268 GSM_Error error;
273 unsigned char req[500]; 269 unsigned char req[500];
274 int size=0; 270 int size=0;
275 271
276 if (Priv->Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED; 272 if (Priv->Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED;
277 // if (Note->Location==0x00) return ERR_INVALIDLOCATION; 273 // if (Note->Location==0x00) return ERR_INVALIDLOCATION;
278 274
279 s->Phone.Data.Cal = Note; 275 s->Phone.Data.Cal = Note;
280 error=GSM_EncodeVCALENDAR(req,&size,Note,true,Siemens_VCalendar); 276 error=GSM_EncodeVCALENDAR(req,&size,Note,true,Siemens_VCalendar);
281 277
282 return SetSiemensFrame (s,req,"vcs",Note->Location,ID_SetCalendarNote,size); 278 return SetSiemensFrame (s,req,"vcs",Note->Location,ID_SetCalendarNote,size);
283} 279}
284 280
285/* (c) by Timo Teras */ 281/* (c) by Timo Teras */
286GSM_Error ATGEN_SL45ReplyGetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s) 282GSM_Error SIEMENS_ReplyGetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s)
287{ 283{
288#ifndef ENABLE_LGPL 284#ifndef ENABLE_LGPL
289 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 285 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
290 GSM_MemoryEntry *Memory = s->Phone.Data.Memory; 286 GSM_MemoryEntry *Memory = s->Phone.Data.Memory;
291 unsigned char buffer[500],buffer2[500]; 287 unsigned char buffer[500],buffer2[500];
292 288
293 switch (Priv->ReplyState) { 289 switch (Priv->ReplyState) {
294 case AT_Reply_OK: 290 case AT_Reply_OK:
295 smprintf(s, "Phonebook entry received\n"); 291 smprintf(s, "Phonebook entry received\n");
296 CopyLineString(buffer, msg.Buffer, Priv->Lines, 3); 292 CopyLineString(buffer, msg.Buffer, Priv->Lines, 3);
297 DecodeHexBin(buffer2,buffer,strlen(buffer)); 293 DecodeHexBin(buffer2,buffer,strlen(buffer));
298 Memory->EntriesNum = 0; 294 Memory->EntriesNum = 0;
299 DecodeVCARD21Text(buffer2, Memory); 295 DecodeVCARD21Text(buffer2, Memory);
300 if (Memory->EntriesNum == 0) return ERR_EMPTY; 296 if (Memory->EntriesNum == 0) return ERR_EMPTY;
301 return ERR_NONE; 297 return ERR_NONE;
302 case AT_Reply_Error: 298 case AT_Reply_Error:
303 smprintf(s, "Error - too high location ?\n"); 299 smprintf(s, "Error - too high location ?\n");
304 return ERR_INVALIDLOCATION; 300 return ERR_INVALIDLOCATION;
305 case AT_Reply_CMSError: 301 case AT_Reply_CMSError:
306 return ATGEN_HandleCMSError(s); 302 return ATGEN_HandleCMSError(s);
307 default: 303 default:
308 break; 304 break;
309 } 305 }
310 return ERR_UNKNOWNRESPONSE; 306 return ERR_UNKNOWNRESPONSE;
311#else 307#else
312 return ERR_NOTIMPLEMENTED; 308 return ERR_NOTIMPLEMENTED;
313#endif 309#endif
314} 310}
315 311
316#endif 312#endif
317 313
318/* How should editor hadle tabs in this file? Add editor commands here. 314/* How should editor hadle tabs in this file? Add editor commands here.
319 * vim: noexpandtab sw=8 ts=8 sts=8: 315 * vim: noexpandtab sw=8 ts=8 sts=8:
320 */ 316 */
diff --git a/gammu/emb/common/phone/at/sonyeric.c b/gammu/emb/common/phone/at/sonyeric.c
index 4b2670a..8eeb39b 100644
--- a/gammu/emb/common/phone/at/sonyeric.c
+++ b/gammu/emb/common/phone/at/sonyeric.c
@@ -1,411 +1,520 @@
1/* (c) 2003 by Marcin Wiacek */ 1/* (c) 2003 by Marcin Wiacek */
2 2
3#include "../../gsmstate.h" 3#include "../../gsmstate.h"
4 4
5#ifdef GSM_ENABLE_ATGEN 5#ifdef GSM_ENABLE_ATGEN
6 6
7#include <string.h> 7#include <string.h>
8#include <time.h> 8#include <time.h>
9#include <ctype.h> 9#include <ctype.h>
10 10
11#include "../../gsmcomon.h" 11#include "../../gsmcomon.h"
12#include "../../misc/coding/coding.h" 12#include "../../misc/coding/coding.h"
13 13
14 extern GSM_Reply_Function ATGENReplyFunctions[]; 14#include "atgen.h"
15 extern GSM_Error ATGEN_DispatchMessage(GSM_StateMachine *s); 15#include "sonyeric.h"
16 16
17#ifdef GSM_ENABLE_OBEXGEN 17#ifdef GSM_ENABLE_OBEXGEN
18 18
19 extern GSM_Reply_Function OBEXGENReplyFunctions[]; 19#include "../obex/obexgen.h"
20 extern GSM_Error OBEXGEN_GetFilePart(GSM_StateMachine *s, GSM_File *File);
21 extern GSM_Error OBEXGEN_AddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos);
22 extern GSM_Error OBEXGEN_Disconnect(GSM_StateMachine *s);
23 20
24#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 21 extern GSM_Reply_FunctionOBEXGENReplyFunctions[];
22 extern GSM_Reply_FunctionATGENReplyFunctions[];
25 23
26static GSM_Error SONYERIC_SetOBEXMode(GSM_StateMachine *s) 24static GSM_Error SONYERIC_SetOBEXMode(GSM_StateMachine *s)
27{ 25{
28 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 26 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
29 GSM_Error error; 27 GSM_Error error;
30 28
31 if (Priv->OBEX) return ERR_NONE; 29 if (Priv->OBEX) return ERR_NONE;
32 30
33 dbgprintf ("Changing to OBEX\n"); 31 dbgprintf ("Changing to OBEX\n");
34 32
35 error=GSM_WaitFor (s, "AT*EOBEX\r", 9, 0x00, 4, ID_SetOBEX); 33 error=GSM_WaitFor (s, "AT*EOBEX\r", 9, 0x00, 4, ID_SetOBEX);
36 if (error != ERR_NONE) return error; 34 if (error != ERR_NONE) return error;
37 35
38 error = s->Protocol.Functions->Terminate(s); 36 error = s->Protocol.Functions->Terminate(s);
39 if (error != ERR_NONE) return error; 37 if (error != ERR_NONE) return error;
40 38
41 s->Protocol.Functions = &OBEXProtocol; 39 s->Protocol.Functions = &OBEXProtocol;
42 error = s->Protocol.Functions->Initialise(s); 40 error = s->Protocol.Functions->Initialise(s);
43 if (error != ERR_NONE) { 41 if (error != ERR_NONE) {
44 s->Protocol.Functions = &ATProtocol; 42 s->Protocol.Functions = &ATProtocol;
45 return error; 43 return error;
46 } 44 }
47 strcpy(s->CurrentConfig->Model,"seobex"); 45 strcpy(s->CurrentConfig->Model,"seobex");
48 s->Phone.Data.Priv.OBEXGEN.Service = 0; 46 s->Phone.Data.Priv.OBEXGEN.Service = 0;
49 s->Phone.Functions->DispatchMessage= GSM_DispatchMessage; 47 s->Phone.Functions->DispatchMessage= GSM_DispatchMessage;
50 s->Phone.Functions->ReplyFunctions= OBEXGENReplyFunctions; 48 s->Phone.Functions->ReplyFunctions= OBEXGENReplyFunctions;
51 Priv->OBEX = true; 49 Priv->OBEX = true;
52 return ERR_NONE; 50 return ERR_NONE;
53} 51}
54 52
55static GSM_Error SONYERIC_SetATMode(GSM_StateMachine *s) 53static GSM_Error SONYERIC_SetATMode(GSM_StateMachine *s)
56{ 54{
57 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 55 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
58 GSM_Error error; 56 GSM_Error error;
59 57
60 if (!Priv->OBEX) return ERR_NONE; 58 if (!Priv->OBEX) return ERR_NONE;
61 59
62 dbgprintf ("Changing to AT\n"); 60 dbgprintf ("Changing to AT\n");
63 61
64 error = OBEXGEN_Disconnect(s); 62 error = OBEXGEN_Disconnect(s);
65 if (error != ERR_NONE) return error; 63 if (error != ERR_NONE) return error;
66 64
67 error = s->Protocol.Functions->Terminate(s); 65 error = s->Protocol.Functions->Terminate(s);
68 if (error != ERR_NONE) return error; 66 if (error != ERR_NONE) return error;
69 67
70 s->Protocol.Functions = &ATProtocol; 68 s->Protocol.Functions = &ATProtocol;
71 error = s->Protocol.Functions->Initialise(s); 69 error = s->Protocol.Functions->Initialise(s);
72 if (error != ERR_NONE) { 70 if (error != ERR_NONE) {
73 s->Protocol.Functions = &OBEXProtocol; 71 s->Protocol.Functions = &OBEXProtocol;
74 return error; 72 return error;
75 } 73 }
76 strcpy(s->CurrentConfig->Model,"at"); 74 strcpy(s->CurrentConfig->Model,"at");
77 s->Phone.Functions->DispatchMessage= ATGEN_DispatchMessage; 75 s->Phone.Functions->DispatchMessage= ATGEN_DispatchMessage;
78 s->Phone.Functions->ReplyFunctions= ATGENReplyFunctions; 76 s->Phone.Functions->ReplyFunctions= ATGENReplyFunctions;
79 Priv->OBEX = false; 77 Priv->OBEX = false;
80 return ERR_NONE; 78 return ERR_NONE;
81} 79}
82 80
83static GSM_Error SONYERIC_GetFile(GSM_StateMachine *s, GSM_File *File, unsigned char *FileName) 81static GSM_Error SONYERIC_GetFile(GSM_StateMachine *s, GSM_File *File, unsigned char *FileName)
84{ 82{
85 GSM_Error error; 83 GSM_Error error;
86 84
87 strcpy(File->ID_FullName,FileName); 85 strcpy(File->ID_FullName,FileName);
88 File->Used = 0; 86 File->Used = 0;
89 if (File->Buffer != NULL) free(File->Buffer); 87 if (File->Buffer != NULL) free(File->Buffer);
90 File->Buffer = NULL; 88 File->Buffer = NULL;
91 89
92 error = SONYERIC_SetOBEXMode(s); 90 error = SONYERIC_SetOBEXMode(s);
93 if (error != ERR_NONE) return error; 91 if (error != ERR_NONE) return error;
94 92
95 error = ERR_NONE; 93 error = ERR_NONE;
96 while (error == ERR_NONE) error = OBEXGEN_GetFilePart(s,File); 94 while (error == ERR_NONE) error = OBEXGEN_GetFilePart(s,File);
97 if (error != ERR_EMPTY) return error; 95 if (error != ERR_EMPTY) return error;
98 96
99 return SONYERIC_SetATMode(s); 97 return SONYERIC_SetATMode(s);
100} 98}
101 99
102static GSM_Error SONYERIC_SetFile(GSM_StateMachine *s, unsigned char *FileName, unsigned char *Buffer, int Length) 100static GSM_Error SONYERIC_SetFile(GSM_StateMachine *s, unsigned char *FileName, unsigned char *Buffer, int Length)
103{ 101{
104 GSM_Errorerror; 102 GSM_Errorerror;
105 GSM_File File; 103 GSM_File File;
106 int Pos = 0; 104 int Pos = 0;
107 105
108 error = SONYERIC_SetOBEXMode(s); 106 error = SONYERIC_SetOBEXMode(s);
109 if (error != ERR_NONE) return error; 107 if (error != ERR_NONE) return error;
110 108
111 strcpy(File.ID_FullName,FileName); 109 strcpy(File.ID_FullName,FileName);
112 EncodeUnicode(File.Name,FileName,strlen(FileName)); 110 EncodeUnicode(File.Name,FileName,strlen(FileName));
113 File.Used = Length; 111 File.Used = Length;
114 File.Buffer = malloc(Length); 112 File.Buffer = malloc(Length);
115 memcpy(File.Buffer,Buffer,Length); 113 memcpy(File.Buffer,Buffer,Length);
116 114
117 error = ERR_NONE; 115 error = ERR_NONE;
118 while (error == ERR_NONE) error = OBEXGEN_AddFilePart(s,&File,&Pos); 116 while (error == ERR_NONE) error = OBEXGEN_AddFilePart(s,&File,&Pos);
119 free(File.Buffer); 117 free(File.Buffer);
120 if (error != ERR_EMPTY) return error; 118 if (error != ERR_EMPTY) return error;
121 119
122 return SONYERIC_SetATMode(s); 120 return SONYERIC_SetATMode(s);
123} 121}
124 122
125#endif 123#endif
126 124
127GSM_Error SONYERIC_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start) 125GSM_Error SONYERIC_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start)
128{ 126{
129#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 127#ifdef GSM_ENABLE_OBEXGEN
130 GSM_Error error; 128 GSM_Error error;
131 GSM_ToDoEntry ToDo; 129 GSM_ToDoEntry ToDo;
132 int Pos, num, Loc; 130 int Pos, num, Loc;
133 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 131 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
134 132
135 if (start) { 133 if (start) {
136 error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); 134 error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs");
137 if (error != ERR_NONE) return error; 135 if (error != ERR_NONE) return error;
138 136
139 Note->Location = 1; 137 Note->Location = 1;
140 } else { 138 } else {
141 Note->Location++; 139 Note->Location++;
142 } 140 }
143 smprintf(s, "Getting calendar note %i\n",Note->Location); 141 smprintf(s, "Getting calendar note %i\n",Note->Location);
144 142
145 Loc = Note->Location; 143 Loc = Note->Location;
146 Pos = 0; 144 Pos = 0;
147 num = 0; 145 num = 0;
148 while (1) { 146 while (1) {
149 error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, Note, &ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo); 147 error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, Note, &ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo);
150 if (error == ERR_EMPTY) break; 148 if (error == ERR_EMPTY) break;
151 if (error != ERR_NONE) return error; 149 if (error != ERR_NONE) return error;
152 if (Note->EntriesNum != 0) { 150 if (Note->EntriesNum != 0) {
153 num++; 151 num++;
154 if (num == Loc) return ERR_NONE; 152 if (num == Loc) return ERR_NONE;
155 } 153 }
156 } 154 }
157 return ERR_EMPTY; 155 return ERR_EMPTY;
158#else 156#else
159 return ERR_SOURCENOTAVAILABLE; 157 return ERR_SOURCENOTAVAILABLE;
160#endif 158#endif
161} 159}
162 160
163GSM_Error SONYERIC_GetNextToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool start) 161GSM_Error SONYERIC_GetNextToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool start)
164{ 162{
165#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 163#ifdef GSM_ENABLE_OBEXGEN
166 GSM_Error error; 164 GSM_Error error;
167 GSM_CalendarEntryCalendar; 165 GSM_CalendarEntryCalendar;
168 int Pos, num, Loc; 166 int Pos, num, Loc;
169 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 167 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
170 168
171 if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; 169 if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED;
172 170
173 if (start) { 171 if (start) {
174 error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); 172 error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs");
175 if (error != ERR_NONE) return error; 173 if (error != ERR_NONE) return error;
176 174
177 ToDo->Location = 1; 175 ToDo->Location = 1;
178 } else { 176 } else {
179 ToDo->Location++; 177 ToDo->Location++;
180 } 178 }
181 smprintf(s,"Getting ToDo %i\n",ToDo->Location); 179 smprintf(s,"Getting ToDo %i\n",ToDo->Location);
182 180
183 Loc = ToDo->Location; 181 Loc = ToDo->Location;
184 Pos = 0; 182 Pos = 0;
185 num = 0; 183 num = 0;
186 while (1) { 184 while (1) {
187 error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, &Calendar, ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo); 185 error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, &Calendar, ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo);
188 if (error == ERR_EMPTY) break; 186 if (error == ERR_EMPTY) break;
189 if (error != ERR_NONE) return error; 187 if (error != ERR_NONE) return error;
190 if (ToDo->EntriesNum != 0) { 188 if (ToDo->EntriesNum != 0) {
191 num++; 189 num++;
192 if (num == Loc) return ERR_NONE; 190 if (num == Loc) return ERR_NONE;
193 } 191 }
194 } 192 }
195 193
196 return ERR_EMPTY; 194 return ERR_EMPTY;
197#else 195#else
198 return ERR_SOURCENOTAVAILABLE; 196 return ERR_SOURCENOTAVAILABLE;
199#endif 197#endif
200} 198}
201 199
202GSM_Error SONYERIC_GetToDoStatus(GSM_StateMachine *s, GSM_ToDoStatus *status) 200GSM_Error SONYERIC_GetToDoStatus(GSM_StateMachine *s, GSM_ToDoStatus *status)
203{ 201{
204#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 202#ifdef GSM_ENABLE_OBEXGEN
205 GSM_Error error; 203 GSM_Error error;
206 GSM_ToDoEntry ToDo; 204 GSM_ToDoEntry ToDo;
207 GSM_CalendarEntry Calendar; 205 GSM_CalendarEntry Calendar;
208 int Pos; 206 int Pos;
209 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 207 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
210 208
211 if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; 209 if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED;
212 210
213 smprintf(s,"Getting ToDo status\n"); 211 smprintf(s,"Getting ToDo status\n");
214 212
215 error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); 213 error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs");
216 if (error != ERR_NONE) return error; 214 if (error != ERR_NONE) return error;
217 215
218 status->Used = 0; 216 status->Used = 0;
219 Pos = 0; 217 Pos = 0;
220 while (1) { 218 while (1) {
221 error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, &Calendar, &ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo); 219 error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, &Calendar, &ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo);
222 if (error == ERR_EMPTY) break; 220 if (error == ERR_EMPTY) break;
223 if (error != ERR_NONE) return error; 221 if (error != ERR_NONE) return error;
224 if (ToDo.EntriesNum != 0) status->Used++; 222 if (ToDo.EntriesNum != 0) status->Used++;
225 } 223 }
226 224
227 return ERR_NONE; 225 return ERR_NONE;
228#else 226#else
229 return ERR_SOURCENOTAVAILABLE; 227 return ERR_SOURCENOTAVAILABLE;
230#endif 228#endif
231} 229}
232 230
233GSM_Error SONYERIC_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note) 231GSM_Error SONYERIC_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note)
234{ 232{
235#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 233#ifdef GSM_ENABLE_OBEXGEN
236 unsigned char req[5000]; 234 unsigned char req[5000];
237 int size=0; 235 int size=0;
238 236
239 smprintf(s,"Adding calendar note\n"); 237 smprintf(s,"Adding calendar note\n");
240 238
241 GSM_EncodeVCALENDAR(req,&size,Note,true,SonyEricsson_VCalendar); 239 GSM_EncodeVCALENDAR(req,&size,Note,true,SonyEricsson_VCalendar);
242 240
243 return SONYERIC_SetFile(s, "telecom/cal/luid/.vcs", req, size); 241 return SONYERIC_SetFile(s, "telecom/cal/luid/.vcs", req, size);
244#else 242#else
245 return ERR_SOURCENOTAVAILABLE; 243 return ERR_SOURCENOTAVAILABLE;
246#endif 244#endif
247} 245}
248 246
249GSM_Error SONYERIC_AddToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo) 247GSM_Error SONYERIC_AddToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo)
250{ 248{
251#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 249#ifdef GSM_ENABLE_OBEXGEN
252 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 250 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
253 unsigned char req[5000]; 251 unsigned char req[5000];
254 int size=0; 252 int size=0;
255 253
256 if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; 254 if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED;
257 255
258 smprintf(s,"Adding ToDo\n"); 256 smprintf(s,"Adding ToDo\n");
259 257
260 GSM_EncodeVTODO(req,&size,ToDo,true,SonyEricsson_VToDo); 258 GSM_EncodeVTODO(req,&size,ToDo,true,SonyEricsson_VToDo);
261 259
262 return SONYERIC_SetFile(s, "telecom/cal/luid/.vcs", req, size); 260 return SONYERIC_SetFile(s, "telecom/cal/luid/.vcs", req, size);
263#else 261#else
264 return ERR_SOURCENOTAVAILABLE; 262 return ERR_SOURCENOTAVAILABLE;
265#endif 263#endif
266} 264}
267 265
268GSM_Error SONYERIC_DeleteAllToDo(GSM_StateMachine *s) 266GSM_Error SONYERIC_DeleteAllToDo(GSM_StateMachine *s)
269{ 267{
270#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 268#ifdef GSM_ENABLE_OBEXGEN
271 GSM_Error error; 269 GSM_Error error;
272 int Pos,Level = 0,Used; 270 int Pos,Level = 0,Used;
273 unsigned char *Buf; 271 unsigned char *Buf;
274 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 272 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
275 unsigned char Line[2000]; 273 unsigned char Line[2000];
276 274
277 if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; 275 if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED;
278 276
279 smprintf(s,"Deleting all ToDo\n"); 277 smprintf(s,"Deleting all ToDo\n");
280 278
281 error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); 279 error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs");
282 if (error != ERR_NONE) return error; 280 if (error != ERR_NONE) return error;
283 281
284 Pos = 0; 282 Pos = 0;
285 Buf = NULL; 283 Buf = NULL;
286 Used = 0; 284 Used = 0;
287 while (1) { 285 while (1) {
288 MyGetLine(Priv->file.Buffer, &Pos, Line, Priv->file.Used); 286 MyGetLine(Priv->file.Buffer, &Pos, Line, Priv->file.Used);
289 if (strlen(Line) == 0) break; 287 if (strlen(Line) == 0) break;
290 dbgprintf("Line is %s,%i,%i\n",Line,Priv->file.Used,Pos); 288 dbgprintf("Line is %s,%i,%i\n",Line,Priv->file.Used,Pos);
291 switch (Level) { 289 switch (Level) {
292 case 0: 290 case 0:
293 if (strstr(Line,"BEGIN:VTODO")) { 291 if (strstr(Line,"BEGIN:VTODO")) {
294 Level = 2; 292 Level = 2;
295 break; 293 break;
296 } 294 }
297 Buf=(unsigned char *)realloc(Buf,Used+strlen(Line)+3); 295 Buf=(unsigned char *)realloc(Buf,Used+strlen(Line)+3);
298 strcpy(Buf+Used,Line); 296 strcpy(Buf+Used,Line);
299 Used=Used+strlen(Line)+3; 297 Used=Used+strlen(Line)+3;
300 Buf[Used-3] = 13; 298 Buf[Used-3] = 13;
301 Buf[Used-2] = 10; 299 Buf[Used-2] = 10;
302 Buf[Used-1] = 0x00; 300 Buf[Used-1] = 0x00;
303 break; 301 break;
304 case 2: /* ToDo note */ 302 case 2: /* ToDo note */
305 if (strstr(Line,"END:VTODO")) { 303 if (strstr(Line,"END:VTODO")) {
306 Level = 0; 304 Level = 0;
307 } 305 }
308 break; 306 break;
309 } 307 }
310 } 308 }
311 309
312 error = SONYERIC_SetFile(s, "telecom/cal.vcs", Buf, Used); 310 error = SONYERIC_SetFile(s, "telecom/cal.vcs", Buf, Used);
313 //if (Buf != NULL) free(Buf); 311 //if (Buf != NULL) free(Buf);
314 return error; 312 return error;
315#else 313#else
316 return ERR_SOURCENOTAVAILABLE; 314 return ERR_SOURCENOTAVAILABLE;
317#endif 315#endif
318} 316}
319 317
320GSM_Error SONYERIC_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note) 318GSM_Error SONYERIC_DelCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note)
321{ 319{
322#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 320#ifdef GSM_ENABLE_OBEXGEN
323 GSM_Error error; 321 GSM_Error error;
324 int Pos,Level = 0,Loc=0,Used; 322 int Pos,Level = 0,Loc=0,Used;
325 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 323 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
326 unsigned char Line[2000]; 324 unsigned char Line[2000];
327 unsigned char *Buf; 325 unsigned char *Buf;
328 326
329 smprintf(s, "Deleting calendar note %i\n",Note->Location); 327 smprintf(s, "Deleting calendar note %i\n",Note->Location);
330 328
331 error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); 329 error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs");
332 if (error != ERR_NONE) return error; 330 if (error != ERR_NONE) return error;
333 331
334 Pos = 0; 332 Pos = 0;
335 Buf = NULL; 333 Buf = NULL;
336 Used = 0; 334 Used = 0;
337 while (1) { 335 while (1) {
338 MyGetLine(Priv->file.Buffer, &Pos, Line, Priv->file.Used); 336 MyGetLine(Priv->file.Buffer, &Pos, Line, Priv->file.Used);
339 if (strlen(Line) == 0) break; 337 if (strlen(Line) == 0) break;
340 dbgprintf("Line is %s,%i,%i\n",Line,Priv->file.Used,Pos); 338 dbgprintf("Line is %s,%i,%i\n",Line,Priv->file.Used,Pos);
341 switch (Level) { 339 switch (Level) {
342 case 0: 340 case 0:
343 if (strstr(Line,"BEGIN:VEVENT")) { 341 if (strstr(Line,"BEGIN:VEVENT")) {
344 Loc++; 342 Loc++;
345 if (Loc == Note->Location) { 343 if (Loc == Note->Location) {
346 Level = 1; 344 Level = 1;
347 break; 345 break;
348 } 346 }
349 } 347 }
350 Buf=(unsigned char *)realloc(Buf,Used+strlen(Line)+3); 348 Buf=(unsigned char *)realloc(Buf,Used+strlen(Line)+3);
351 strcpy(Buf+Used,Line); 349 strcpy(Buf+Used,Line);
352 Used=Used+strlen(Line)+3; 350 Used=Used+strlen(Line)+3;
353 Buf[Used-3] = 13; 351 Buf[Used-3] = 13;
354 Buf[Used-2] = 10; 352 Buf[Used-2] = 10;
355 Buf[Used-1] = 0x00; 353 Buf[Used-1] = 0x00;
356 break; 354 break;
357 case 1: /* Calendar note */ 355 case 1: /* Calendar note */
358 if (strstr(Line,"END:VEVENT")) { 356 if (strstr(Line,"END:VEVENT")) {
359 Level = 0; 357 Level = 0;
360 } 358 }
361 break; 359 break;
362 } 360 }
363 } 361 }
364 362
365 DumpMessage(s->di.df, s->di.dl, Buf, Used); 363 DumpMessage(s->di.df, s->di.dl, Buf, Used);
366 364
367 error = SONYERIC_SetFile(s, "telecom/cal.vcs", Buf, Used); 365 error = SONYERIC_SetFile(s, "telecom/cal.vcs", Buf, Used);
368 if (Buf != NULL) free(Buf); 366 if (Buf != NULL) free(Buf);
369 return error; 367 return error;
370#else 368#else
371 return ERR_SOURCENOTAVAILABLE; 369 return ERR_SOURCENOTAVAILABLE;
372#endif 370#endif
373} 371}
374 372
375GSM_Error SONYERIC_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *Status) 373GSM_Error SONYERIC_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *Status)
376{ 374{
377#if defined(GSM_ENABLE_BLUEOBEX) || defined(GSM_ENABLE_IRDAOBEX) 375#ifdef GSM_ENABLE_OBEXGEN
378 GSM_Error error; 376 GSM_Error error;
379 GSM_ToDoEntry ToDo; 377 GSM_ToDoEntry ToDo;
380 GSM_CalendarEntry Calendar; 378 GSM_CalendarEntry Calendar;
381 int Pos; 379 int Pos;
382 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 380 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
383 381
384 if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED; 382 if (Priv->Manufacturer!=AT_Ericsson) return ERR_NOTSUPPORTED;
385 383
386 smprintf(s, "Getting calendar status\n"); 384 smprintf(s, "Getting calendar status\n");
387 385
388 error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs"); 386 error = SONYERIC_GetFile(s, &Priv->file, "telecom/cal.vcs");
389 if (error != ERR_NONE) return error; 387 if (error != ERR_NONE) return error;
390 388
391 Status->Used = 0; 389 Status->Used = 0;
392 Pos = 0; 390 Pos = 0;
393 while (1) { 391 while (1) {
394 error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, &Calendar, &ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo); 392 error = GSM_DecodeVCALENDAR_VTODO(Priv->file.Buffer, &Pos, &Calendar, &ToDo, SonyEricsson_VCalendar, SonyEricsson_VToDo);
395 if (error == ERR_EMPTY) break; 393 if (error == ERR_EMPTY) break;
396 if (error != ERR_NONE) return error; 394 if (error != ERR_NONE) return error;
397 if (Calendar.EntriesNum != 0) Status->Used++; 395 if (Calendar.EntriesNum != 0) Status->Used++;
398 } 396 }
399 397
400 return ERR_NONE; 398 return ERR_NONE;
401#else 399#else
402 return ERR_SOURCENOTAVAILABLE; 400 return ERR_SOURCENOTAVAILABLE;
403#endif 401#endif
404} 402}
405 403
406#endif 404GSM_Error ERICSSON_ReplyGetDateLocale(GSM_Protocol_Message msg, GSM_StateMachine *s)
405 { /*Author: Peter Ondraska, based on code by Marcin Wiacek and Michal Cihar
406 License: Whatever the current maintainer of gammulib chooses, as long as there
407 is an easy way to obtain the source under GPL, otherwise the author's parts
408 of this function are GPL 2.0.
409 */
410 GSM_Locale*locale = s->Phone.Data.Locale;
411 char format;
412
413 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
414 case AT_Reply_OK:
415 smprintf(s, "Date settings received\n");
416 format=atoi(msg.Buffer);
417 switch (format) {
418 case 0: locale->DateFormat = GSM_Date_OFF;
419 locale->DateSeparator = 0;
420 break;
421 case 1: locale->DateFormat = GSM_Date_DDMMMYY;
422 locale->DateSeparator = '-';
423 break;
424 case 2: locale->DateFormat = GSM_Date_DDMMYY;
425 locale->DateSeparator = '-';
426 break;
427 case 3: locale->DateFormat = GSM_Date_MMDDYY;
428 locale->DateSeparator = '/';
429 break;
430 case 4: locale->DateFormat = GSM_Date_DDMMYY;
431 locale->DateSeparator = '/';
432 break;
433 case 5: locale->DateFormat = GSM_Date_DDMMYY;
434 locale->DateSeparator = '.';
435 break;
436 case 6: locale->DateFormat = GSM_Date_YYMMDD;
437 locale->DateSeparator = 0;
438 break;
439 case 7: locale->DateFormat = GSM_Date_YYMMDD;
440 locale->DateSeparator = '-';
441 break;
442 default:return ERR_UNKNOWNRESPONSE;
443 }
444 default:
445 return ERR_NOTSUPPORTED;
446 }
447}
448
449GSM_Error ERICSSON_ReplyGetTimeLocale(GSM_Protocol_Message msg, GSM_StateMachine *s)
450 { /*Author: Peter Ondraska
451 License: Whatever the current maintainer of gammulib chooses, as long as there
452 is an easy way to obtain the source under GPL, otherwise the author's parts
453 of this function are GPL 2.0.
454 */
455 char format;
456
457 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
458 case AT_Reply_OK:
459 smprintf(s, "Time settings received\n");
460 format=atoi(msg.Buffer);
461 switch (format) {
462 case 1:
463 case 2: s->Phone.Data.Locale->AMPMTime=(format==2);
464 return ERR_NONE;
465 default:return ERR_UNKNOWNRESPONSE;
466 }
467 default: return ERR_NOTSUPPORTED;
468 }
469}
470
471GSM_Error ERICSSON_GetLocale(GSM_StateMachine *s, GSM_Locale *locale)
472{
473 GSM_Error error;
474
475 s->Phone.Data.Locale = locale;
476
477 smprintf(s, "Getting date format\n");
478 error=GSM_WaitFor (s, "AT+ESDF?\r", 9, 0x00, 3, ID_GetLocale);
479 if (error!=ERR_NONE) return error;
480
481 smprintf(s, "Getting time format\n");
482 return GSM_WaitFor (s, "AT+ESTF?\r", 9, 0x00, 3, ID_GetLocale);
483}
484
485
486GSM_Error ERICSSON_SetLocale(GSM_StateMachine *s, GSM_Locale *locale)
487 { /*Author: Peter Ondraska
488 License: Whatever the current maintainer of gammulib chooses, as long as there
489 is an easy way to obtain the source under GPL, otherwise the author's parts
490 of this function are GPL 2.0.
491 */
492 /* this is not yet supported by gammu.c */
493 intformat=0;
494 charreq[12];
495
496 if (locale->DateFormat==GSM_Date_OFF) { format=0; } else
497 if ((locale->DateFormat==GSM_Date_DDMMMYY)&&(locale->DateSeparator=='-')) { format=1; } else
498 if ((locale->DateFormat==GSM_Date_DDMMYY)&&(locale->DateSeparator=='-')) { format=2; } else
499 if ((locale->DateFormat==GSM_Date_MMDDYY)&&(locale->DateSeparator=='/')) { format=3; } else
500 if ((locale->DateFormat==GSM_Date_DDMMYY)&&(locale->DateSeparator=='/')) { format=4; } else
501 if ((locale->DateFormat==GSM_Date_DDMMYY)&&(locale->DateSeparator=='.')) { format=5; } else
502 if ((locale->DateFormat==GSM_Date_YYMMDD)&&(locale->DateSeparator==0)) { format=6; } else
503 if ((locale->DateFormat==GSM_Date_YYMMDD)&&(locale->DateSeparator=='-')) { format=7; }
504 else { return ERR_NOTSUPPORTED; } /* ERR_WRONGINPUT */
505
506 sprintf(req,"AT+ESDF=%i\r",format);
507 smprintf(s, "Setting date format\n");
508 return GSM_WaitFor (s, req, strlen(req), 0x00, 3, ID_SetLocale);
509
510 if (locale->AMPMTime) { format=2; } else { format=1; }
511 sprintf(req,"AT+ESTF=%i\r",format);
512 smprintf(s, "Setting time format\n");
513 return GSM_WaitFor (s, req, strlen(req), 0x00, 3, ID_SetLocale);
514}
515
407#endif 516#endif
408 517
409/* How should editor hadle tabs in this file? Add editor commands here. 518/* How should editor hadle tabs in this file? Add editor commands here.
410 * vim: noexpandtab sw=8 ts=8 sts=8: 519 * vim: noexpandtab sw=8 ts=8 sts=8:
411 */ 520 */
diff --git a/gammu/emb/common/phone/nokia/dct3/dct3func.c b/gammu/emb/common/phone/nokia/dct3/dct3func.c
index beef33c..17cd0a4 100644
--- a/gammu/emb/common/phone/nokia/dct3/dct3func.c
+++ b/gammu/emb/common/phone/nokia/dct3/dct3func.c
@@ -1,195 +1,198 @@
1/* (c) 2001-2004 by Marcin Wiacek */ 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 */ 2/* resetting DCT4 phones settings (c) by Walek */
3/* based on some Markus Plail, Pavel Janik & others work from Gnokii (www.gnokii.org)
4 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
5 * GNU GPL version 2 or later
6 */
4 7
5#include <string.h> /* memcpy only */ 8#include <string.h> /* memcpy only */
6#include <stdio.h> 9#include <stdio.h>
7#include <ctype.h> 10#include <ctype.h>
8 11
9#include "../../../gsmstate.h" 12#include "../../../gsmstate.h"
10#include "../../../misc/coding/coding.h" 13#include "../../../misc/coding/coding.h"
11#include "../../../service/sms/gsmsms.h" 14#include "../../../service/sms/gsmsms.h"
12#include "../../pfunc.h" 15#include "../../pfunc.h"
13#include "../nfunc.h" 16#include "../nfunc.h"
14#include "dct3func.h" 17#include "dct3func.h"
15 18
16#ifdef GSM_ENABLE_NOKIA_DCT3 19#ifdef GSM_ENABLE_NOKIA_DCT3
17 20
18GSM_Error DCT3_DeleteWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark) 21GSM_Error DCT3_DeleteWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
19{ 22{
20 GSM_Error error; 23 GSM_Error error;
21 24
22 /* We have to enable WAP frames in phone */ 25 /* We have to enable WAP frames in phone */
23 error=DCT3DCT4_EnableWAPFunctions(s); 26 error=DCT3DCT4_EnableWAPFunctions(s);
24 if (error!=ERR_NONE) return error; 27 if (error!=ERR_NONE) return error;
25 28
26 return DCT3DCT4_DeleteWAPBookmarkPart(s,bookmark); 29 return DCT3DCT4_DeleteWAPBookmarkPart(s,bookmark);
27} 30}
28 31
29GSM_Error DCT3_GetWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark) 32GSM_Error DCT3_GetWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
30{ 33{
31 GSM_Error error; 34 GSM_Error error;
32 35
33 /* We have to enable WAP frames in phone */ 36 /* We have to enable WAP frames in phone */
34 error=DCT3DCT4_EnableWAPFunctions(s); 37 error=DCT3DCT4_EnableWAPFunctions(s);
35 if (error!=ERR_NONE) return error; 38 if (error!=ERR_NONE) return error;
36 39
37 return DCT3DCT4_GetWAPBookmarkPart(s,bookmark); 40 return DCT3DCT4_GetWAPBookmarkPart(s,bookmark);
38} 41}
39 42
40GSM_Error DCT3_ReplyPressKey(GSM_Protocol_Message msg, GSM_StateMachine *s) 43GSM_Error DCT3_ReplyPressKey(GSM_Protocol_Message msg, GSM_StateMachine *s)
41{ 44{
42 GSM_Phone_Data *Data = &s->Phone.Data; 45 GSM_Phone_Data *Data = &s->Phone.Data;
43 46
44 switch (msg.Buffer[2]) { 47 switch (msg.Buffer[2]) {
45 case 0x46: 48 case 0x46:
46 smprintf(s, "Pressing key OK\n"); 49 smprintf(s, "Pressing key OK\n");
47 if (Data->PressKey) return ERR_NONE; 50 if (Data->PressKey) return ERR_NONE;
48 break; 51 break;
49 case 0x47: 52 case 0x47:
50 smprintf(s, "Releasing key OK\n"); 53 smprintf(s, "Releasing key OK\n");
51 if (!Data->PressKey) return ERR_NONE; 54 if (!Data->PressKey) return ERR_NONE;
52 break; 55 break;
53 } 56 }
54 return ERR_UNKNOWNRESPONSE; 57 return ERR_UNKNOWNRESPONSE;
55} 58}
56 59
57GSM_Error DCT3_PressKey(GSM_StateMachine *s, GSM_KeyCode Key, bool Press) 60GSM_Error DCT3_PressKey(GSM_StateMachine *s, GSM_KeyCode Key, bool Press)
58{ 61{
59 unsigned char PressReq[] = {0x00, 0x01, 0x46, 0x00, 0x01, 62 unsigned char PressReq[] = {0x00, 0x01, 0x46, 0x00, 0x01,
60 0x0a}; /* Key code */ 63 0x0a}; /* Key code */
61 unsigned char ReleaseReq[] = {0x00, 0x01, 0x47, 0x00, 0x01, 0x0c}; 64 unsigned char ReleaseReq[] = {0x00, 0x01, 0x47, 0x00, 0x01, 0x0c};
62 65
63 if (Press) { 66 if (Press) {
64 PressReq[5] = Key; 67 PressReq[5] = Key;
65 s->Phone.Data.PressKey = true; 68 s->Phone.Data.PressKey = true;
66 smprintf(s, "Pressing key\n"); 69 smprintf(s, "Pressing key\n");
67 return GSM_WaitFor (s, PressReq, 6, 0xd1, 4, ID_PressKey); 70 return GSM_WaitFor (s, PressReq, 6, 0xd1, 4, ID_PressKey);
68 } else { 71 } else {
69 s->Phone.Data.PressKey = false; 72 s->Phone.Data.PressKey = false;
70 smprintf(s, "Releasing key\n"); 73 smprintf(s, "Releasing key\n");
71 return GSM_WaitFor (s, ReleaseReq, 6, 0xd1, 4, ID_PressKey); 74 return GSM_WaitFor (s, ReleaseReq, 6, 0xd1, 4, ID_PressKey);
72 } 75 }
73} 76}
74 77
75GSM_Error DCT3_ReplyPlayTone(GSM_Protocol_Message msg, GSM_StateMachine *s) 78GSM_Error DCT3_ReplyPlayTone(GSM_Protocol_Message msg, GSM_StateMachine *s)
76{ 79{
77 smprintf(s, "Tone played\n"); 80 smprintf(s, "Tone played\n");
78 return ERR_NONE; 81 return ERR_NONE;
79} 82}
80 83
81GSM_Error DCT3_PlayTone(GSM_StateMachine *s, int Herz, unsigned char Volume, bool start) 84GSM_Error DCT3_PlayTone(GSM_StateMachine *s, int Herz, unsigned char Volume, bool start)
82{ 85{
83 GSM_Error error; 86 GSM_Error error;
84 unsigned char req[] = {0x00,0x01,0x8f, 87 unsigned char req[] = {0x00,0x01,0x8f,
85 0x00, /* Volume */ 88 0x00, /* Volume */
86 0x00, /* HerzLo */ 89 0x00, /* HerzLo */
87 0x00}; /* HerzHi */ 90 0x00}; /* HerzHi */
88 91
89 if (start) { 92 if (start) {
90 error=DCT3_EnableSecurity (s, 0x01); 93 error=DCT3_EnableSecurity (s, 0x01);
91 if (error!=ERR_NONE) return error; 94 if (error!=ERR_NONE) return error;
92 } 95 }
93 96
94 /* For Herz==255*255 we have silent */ 97 /* For Herz==255*255 we have silent */
95 if (Herz!=255*255) { 98 if (Herz!=255*255) {
96 req[3]=Volume; 99 req[3]=Volume;
97 req[5]=Herz%256; 100 req[5]=Herz%256;
98 req[4]=Herz/256; 101 req[4]=Herz/256;
99 } else { 102 } else {
100 req[3]=0; 103 req[3]=0;
101 req[5]=0; 104 req[5]=0;
102 req[4]=0; 105 req[4]=0;
103 } 106 }
104 107
105 return GSM_WaitFor (s, req, 6, 0x40, 4, ID_PlayTone); 108 return GSM_WaitFor (s, req, 6, 0x40, 4, ID_PlayTone);
106} 109}
107 110
108#ifdef GSM_ENABLE_CELLBROADCAST 111#ifdef GSM_ENABLE_CELLBROADCAST
109 112
110GSM_Error DCT3_ReplyIncomingCB(GSM_Protocol_Message msg, GSM_StateMachine *s) 113GSM_Error DCT3_ReplyIncomingCB(GSM_Protocol_Message msg, GSM_StateMachine *s)
111{ 114{
112 GSM_CBMessage CB; 115 GSM_CBMessage CB;
113 int i; 116 int i;
114 char Buffer[300]; 117 char Buffer[300];
115 118
116 smprintf(s, "CB received\n"); 119 smprintf(s, "CB received\n");
117 CB.Channel = msg.Buffer[7]; 120 CB.Channel = msg.Buffer[7];
118 i = GSM_UnpackEightBitsToSeven(0, msg.Buffer[9], msg.Buffer[9], msg.Buffer+10, Buffer); 121 i = GSM_UnpackEightBitsToSeven(0, msg.Buffer[9], msg.Buffer[9], msg.Buffer+10, Buffer);
119 i = msg.Buffer[9] - 1; 122 i = msg.Buffer[9] - 1;
120 while (i!=0) { 123 while (i!=0) {
121 if (Buffer[i] == 13) i = i - 1; else break; 124 if (Buffer[i] == 13) i = i - 1; else break;
122 } 125 }
123 DecodeDefault(CB.Text, Buffer, i + 1, false, NULL); 126 DecodeDefault(CB.Text, Buffer, i + 1, false, NULL);
124 smprintf(s, "Channel %i, text \"%s\"\n",CB.Channel,DecodeUnicodeString(CB.Text)); 127 smprintf(s, "Channel %i, text \"%s\"\n",CB.Channel,DecodeUnicodeString(CB.Text));
125 if (s->Phone.Data.EnableIncomingCB && s->User.IncomingCB!=NULL) { 128 if (s->Phone.Data.EnableIncomingCB && s->User.IncomingCB!=NULL) {
126 s->User.IncomingCB(s->CurrentConfig->Device,CB); 129 s->User.IncomingCB(s->CurrentConfig->Device,CB);
127 } 130 }
128 return ERR_NONE; 131 return ERR_NONE;
129} 132}
130 133
131GSM_Error DCT3_ReplySetIncomingCB(GSM_Protocol_Message msg, GSM_StateMachine *s) 134GSM_Error DCT3_ReplySetIncomingCB(GSM_Protocol_Message msg, GSM_StateMachine *s)
132{ 135{
133 switch (msg.Buffer[3]) { 136 switch (msg.Buffer[3]) {
134 case 0x21: 137 case 0x21:
135 smprintf(s, "CB set\n"); 138 smprintf(s, "CB set\n");
136 return ERR_NONE; 139 return ERR_NONE;
137 case 0x22: 140 case 0x22:
138 smprintf(s, "CB not set\n"); 141 smprintf(s, "CB not set\n");
139 return ERR_UNKNOWN; 142 return ERR_UNKNOWN;
140 case 0xCA: 143 case 0xCA:
141 smprintf(s, "No network and no CB\n"); 144 smprintf(s, "No network and no CB\n");
142 return ERR_SECURITYERROR; 145 return ERR_SECURITYERROR;
143 } 146 }
144 return ERR_UNKNOWNRESPONSE; 147 return ERR_UNKNOWNRESPONSE;
145} 148}
146 149
147#endif 150#endif
148 151
149GSM_Error DCT3_SetIncomingCB(GSM_StateMachine *s, bool enable) 152GSM_Error DCT3_SetIncomingCB(GSM_StateMachine *s, bool enable)
150{ 153{
151#ifdef GSM_ENABLE_CELLBROADCAST 154#ifdef GSM_ENABLE_CELLBROADCAST
152 unsigned char reqOn[] = {N6110_FRAME_HEADER, 0x20, 0x01, 155 unsigned char reqOn[] = {N6110_FRAME_HEADER, 0x20, 0x01,
153 0x01, 0x00, 0x00, 0x01, 0x01}; 156 0x01, 0x00, 0x00, 0x01, 0x01};
154 unsigned char reqOff[] = {N6110_FRAME_HEADER, 0x20, 0x00, 157 unsigned char reqOff[] = {N6110_FRAME_HEADER, 0x20, 0x00,
155 0x00, 0x00, 0x00, 0x00, 0x00}; 158 0x00, 0x00, 0x00, 0x00, 0x00};
156 159
157 if (s->Phone.Data.EnableIncomingCB!=enable) { 160 if (s->Phone.Data.EnableIncomingCB!=enable) {
158 s->Phone.Data.EnableIncomingCB = enable; 161 s->Phone.Data.EnableIncomingCB = enable;
159 if (enable) { 162 if (enable) {
160 smprintf(s, "Enabling incoming CB\n"); 163 smprintf(s, "Enabling incoming CB\n");
161 return GSM_WaitFor(s, reqOn, 10, 0x02, 4, ID_SetIncomingCB); 164 return GSM_WaitFor(s, reqOn, 10, 0x02, 4, ID_SetIncomingCB);
162 } else { 165 } else {
163 smprintf(s, "Disabling incoming CB\n"); 166 smprintf(s, "Disabling incoming CB\n");
164 return GSM_WaitFor(s, reqOff, 10, 0x02, 4, ID_SetIncomingCB); 167 return GSM_WaitFor(s, reqOff, 10, 0x02, 4, ID_SetIncomingCB);
165 } 168 }
166 } 169 }
167 return ERR_NONE; 170 return ERR_NONE;
168#else 171#else
169 return ERR_SOURCENOTAVAILABLE; 172 return ERR_SOURCENOTAVAILABLE;
170#endif 173#endif
171} 174}
172 175
173GSM_Error DCT3_ReplySetSMSC(GSM_Protocol_Message msg, GSM_StateMachine *s) 176GSM_Error DCT3_ReplySetSMSC(GSM_Protocol_Message msg, GSM_StateMachine *s)
174{ 177{
175 smprintf(s, "SMSC set\n"); 178 smprintf(s, "SMSC set\n");
176 return ERR_NONE; 179 return ERR_NONE;
177} 180}
178 181
179GSM_Error DCT3_SetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc) 182GSM_Error DCT3_SetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc)
180{ 183{
181 unsigned char req[100] = {N6110_FRAME_HEADER, 0x30, 0x64}; 184 unsigned char req[100] = {N6110_FRAME_HEADER, 0x30, 0x64};
182 185
183 memset(req+6,100-6,0); 186 memset(req+6,100-6,0);
184 187
185 /* SMSC location */ 188 /* SMSC location */
186 req[5] = smsc->Location; 189 req[5] = smsc->Location;
187 190
188 /* SMSC format */ 191 /* SMSC format */
189 switch (smsc->Format) { 192 switch (smsc->Format) {
190 case SMS_FORMAT_Text : req[7] = 0x00; break; 193 case SMS_FORMAT_Text : req[7] = 0x00; break;
191 case SMS_FORMAT_Fax : req[7] = 0x22; break; 194 case SMS_FORMAT_Fax : req[7] = 0x22; break;
192 case SMS_FORMAT_Pager : req[7] = 0x26; break; 195 case SMS_FORMAT_Pager : req[7] = 0x26; break;
193 case SMS_FORMAT_Email : req[7] = 0x32; break; 196 case SMS_FORMAT_Email : req[7] = 0x32; break;
194 } 197 }
195 198
@@ -205,451 +208,452 @@ GSM_Error DCT3_SetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc)
205 /* SMSC name */ 208 /* SMSC name */
206 memcpy(req + 34, DecodeUnicodeString(smsc->Name),UnicodeLength(smsc->Name)); 209 memcpy(req + 34, DecodeUnicodeString(smsc->Name),UnicodeLength(smsc->Name));
207 210
208 smprintf(s, "Setting SMSC\n"); 211 smprintf(s, "Setting SMSC\n");
209 return GSM_WaitFor (s, req, 35+UnicodeLength(smsc->Name), 0x02, 4, ID_SetSMSC); 212 return GSM_WaitFor (s, req, 35+UnicodeLength(smsc->Name), 0x02, 4, ID_SetSMSC);
210} 213}
211 214
212GSM_Error DCT3_ReplyEnableSecurity(GSM_Protocol_Message msg, GSM_StateMachine *s) 215GSM_Error DCT3_ReplyEnableSecurity(GSM_Protocol_Message msg, GSM_StateMachine *s)
213{ 216{
214 smprintf(s, "State of security commands set\n"); 217 smprintf(s, "State of security commands set\n");
215 return ERR_NONE; 218 return ERR_NONE;
216} 219}
217 220
218/* If you set make some things (for example, change Security Code from 221/* 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 222 * 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. 223 * and you won't be able to play tones, get netmonitor, etc.
221 * This function do thing called "Enabling extended security commands" 224 * This function do thing called "Enabling extended security commands"
222 * and it enables 0x40 frame functions. 225 * and it enables 0x40 frame functions.
223 * This frame can also some other things - see below 226 * This frame can also some other things - see below
224 */ 227 */
225GSM_Error DCT3_EnableSecurity (GSM_StateMachine *s, unsigned char status) 228GSM_Error DCT3_EnableSecurity (GSM_StateMachine *s, unsigned char status)
226{ 229{
227 unsigned char req[] = {0x00, 0x01, 0x64, 230 unsigned char req[] = {0x00, 0x01, 0x64,
228 0x01};/* 0x00/0x01 - off/on, 231 0x01};/* 0x00/0x01 - off/on,
229 * 0x03/0x04 - soft/hard reset, 232 * 0x03/0x04 - soft/hard reset,
230 * 0x06 - CONTACT SERVICE 233 * 0x06 - CONTACT SERVICE
231 */ 234 */
232 235
233 /* 0x06 MAKES CONTACT SERVICE! BE CAREFULL! */ 236 /* 0x06 MAKES CONTACT SERVICE! BE CAREFULL! */
234 /* When use 0x03 and had during session changed time & date 237 /* When use 0x03 and had during session changed time & date
235 * some phones (like 6150 or 6210) can ask for time & date after reset 238 * some phones (like 6150 or 6210) can ask for time & date after reset
236 * or disable clock on the screen 239 * or disable clock on the screen
237 */ 240 */
238 if (status!=0x06) req[3] = status; 241 if (status!=0x06) req[3] = status;
239 smprintf(s, "Setting state of security commands\n"); 242 smprintf(s, "Setting state of security commands\n");
240 return GSM_WaitFor (s, req, 4, 0x40, 4, ID_EnableSecurity); 243 return GSM_WaitFor (s, req, 4, 0x40, 4, ID_EnableSecurity);
241} 244}
242 245
243GSM_Error DCT3_ReplyGetIMEI(GSM_Protocol_Message msg, GSM_StateMachine *s) 246GSM_Error DCT3_ReplyGetIMEI(GSM_Protocol_Message msg, GSM_StateMachine *s)
244{ 247{
245 memcpy(s->Phone.Data.IMEI,msg.Buffer + 4, 16); 248 memcpy(s->Phone.Data.IMEI,msg.Buffer + 4, 16);
246 smprintf(s, "Received IMEI %s\n",s->Phone.Data.IMEI); 249 smprintf(s, "Received IMEI %s\n",s->Phone.Data.IMEI);
247 return ERR_NONE; 250 return ERR_NONE;
248} 251}
249 252
250GSM_Error DCT3_GetIMEI (GSM_StateMachine *s) 253GSM_Error DCT3_GetIMEI (GSM_StateMachine *s)
251{ 254{
252 unsigned char req[] = {0x00, 0x01, 0x66, 0x00}; 255 unsigned char req[] = {0x00, 0x01, 0x66, 0x00};
253 GSM_Error error; 256 GSM_Error error;
254 257
255 if (strlen(s->Phone.Data.IMEI)!=0) return ERR_NONE; 258 if (strlen(s->Phone.Data.IMEI)!=0) return ERR_NONE;
256 259
257 error=DCT3_EnableSecurity (s, 0x01); 260 error=DCT3_EnableSecurity (s, 0x01);
258 if (error!=ERR_NONE) return error; 261 if (error!=ERR_NONE) return error;
259 262
260 smprintf(s, "Getting IMEI\n"); 263 smprintf(s, "Getting IMEI\n");
261 return GSM_WaitFor (s, req, 4, 0x40, 2, ID_GetIMEI); 264 return GSM_WaitFor (s, req, 4, 0x40, 2, ID_GetIMEI);
262} 265}
263 266
264GSM_Error DCT3_ReplySIMLogin(GSM_Protocol_Message msg, GSM_StateMachine *s) 267GSM_Error DCT3_ReplySIMLogin(GSM_Protocol_Message msg, GSM_StateMachine *s)
265{ 268{
266 smprintf(s, "Login for SIM card\n"); 269 smprintf(s, "Login for SIM card\n");
267 return ERR_NONE; 270 return ERR_NONE;
268} 271}
269 272
270GSM_Error DCT3_ReplySIMLogout(GSM_Protocol_Message msg, GSM_StateMachine *s) 273GSM_Error DCT3_ReplySIMLogout(GSM_Protocol_Message msg, GSM_StateMachine *s)
271{ 274{
272 smprintf(s, "Logout for SIM card\n"); 275 smprintf(s, "Logout for SIM card\n");
273 return ERR_NONE; 276 return ERR_NONE;
274} 277}
275 278
276GSM_Error DCT3_ReplyGetDateTime(GSM_Protocol_Message msg, GSM_StateMachine *s) 279GSM_Error DCT3_ReplyGetDateTime(GSM_Protocol_Message msg, GSM_StateMachine *s)
277{ 280{
278 smprintf(s, "Date & time received\n"); 281 smprintf(s, "Date & time received\n");
279 if (msg.Buffer[4]==0x01) { 282 if (msg.Buffer[4]==0x01) {
280 NOKIA_DecodeDateTime(s, msg.Buffer+8, s->Phone.Data.DateTime); 283 NOKIA_DecodeDateTime(s, msg.Buffer+8, s->Phone.Data.DateTime);
281 return ERR_NONE; 284 return ERR_NONE;
282 } 285 }
283 smprintf(s, "Not set in phone\n"); 286 smprintf(s, "Not set in phone\n");
284 return ERR_EMPTY; 287 return ERR_EMPTY;
285} 288}
286 289
287GSM_Error DCT3_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time, unsigned char msgtype) 290GSM_Error DCT3_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time, unsigned char msgtype)
288{ 291{
289 unsigned char req[] = {N6110_FRAME_HEADER, 0x62}; 292 unsigned char req[] = {N6110_FRAME_HEADER, 0x62};
290 293
291 s->Phone.Data.DateTime=date_time; 294 s->Phone.Data.DateTime=date_time;
292 smprintf(s, "Getting date & time\n"); 295 smprintf(s, "Getting date & time\n");
293 return GSM_WaitFor (s, req, 4, msgtype, 4, ID_GetDateTime); 296 return GSM_WaitFor (s, req, 4, msgtype, 4, ID_GetDateTime);
294} 297}
295 298
296GSM_Error DCT3_ReplyGetAlarm(GSM_Protocol_Message msg, GSM_StateMachine *s) 299GSM_Error DCT3_ReplyGetAlarm(GSM_Protocol_Message msg, GSM_StateMachine *s)
297{ 300{
298 GSM_Phone_Data*Data = &s->Phone.Data; 301 GSM_Phone_Data*Data = &s->Phone.Data;
299 302
300 smprintf(s, "Alarm: "); 303 smprintf(s, "Alarm: ");
301 if (msg.Buffer[8]==0x02) { 304 if (msg.Buffer[8]==0x02) {
302 smprintf(s, "set to %02i:%02i\n", msg.Buffer[9], msg.Buffer[10]); 305 smprintf(s, "set to %02i:%02i\n", msg.Buffer[9], msg.Buffer[10]);
303 Data->Alarm->Repeating = true; 306 Data->Alarm->Repeating = true;
304 Data->Alarm->Text[0] = 0; 307 Data->Alarm->Text[0] = 0;
305 Data->Alarm->Text[1] = 0; 308 Data->Alarm->Text[1] = 0;
306 Data->Alarm->DateTime.Hour= msg.Buffer[9]; 309 Data->Alarm->DateTime.Hour= msg.Buffer[9];
307 Data->Alarm->DateTime.Minute= msg.Buffer[10]; 310 Data->Alarm->DateTime.Minute= msg.Buffer[10];
308 Data->Alarm->DateTime.Second= 0; 311 Data->Alarm->DateTime.Second= 0;
309 return ERR_NONE; 312 return ERR_NONE;
310 } 313 }
311 smprintf(s, "not set\n"); 314 smprintf(s, "not set\n");
312 return ERR_EMPTY; 315 return ERR_EMPTY;
313} 316}
314 317
315GSM_Error DCT3_GetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm, unsigned char msgtype) 318GSM_Error DCT3_GetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm, unsigned char msgtype)
316{ 319{
317 unsigned char req[] = {N6110_FRAME_HEADER, 0x6d}; 320 unsigned char req[] = {N6110_FRAME_HEADER, 0x6d};
318 321
319 if (alarm->Location!=1) return ERR_NOTSUPPORTED; 322 if (alarm->Location!=1) return ERR_NOTSUPPORTED;
320 323
321 s->Phone.Data.Alarm=alarm; 324 s->Phone.Data.Alarm=alarm;
322 smprintf(s, "Getting alarm\n"); 325 smprintf(s, "Getting alarm\n");
323 return GSM_WaitFor (s, req, 4, msgtype, 4, ID_GetAlarm); 326 return GSM_WaitFor (s, req, 4, msgtype, 4, ID_GetAlarm);
324} 327}
325 328
326GSM_Error DCT3_ReplySetDateTime(GSM_Protocol_Message msg, GSM_StateMachine *s) 329GSM_Error DCT3_ReplySetDateTime(GSM_Protocol_Message msg, GSM_StateMachine *s)
327{ 330{
328 smprintf(s, "Date & time: "); 331 smprintf(s, "Date & time: ");
329 if (msg.Buffer[4]==0x01) { 332 if (msg.Buffer[4]==0x01) {
330 smprintf(s, "set OK\n"); 333 smprintf(s, "set OK\n");
331 return ERR_NONE; 334 return ERR_NONE;
332 } 335 }
333 smprintf(s, "error setting\n"); 336 smprintf(s, "error setting\n");
334 return ERR_UNKNOWN; 337 return ERR_UNKNOWN;
335} 338}
336 339
337GSM_Error DCT3_SetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time, unsigned char msgtype) 340GSM_Error DCT3_SetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time, unsigned char msgtype)
338{ 341{
339 unsigned char req[] = {N6110_FRAME_HEADER, 0x60, 0x01, 0x01, 0x07, 342 unsigned char req[] = {N6110_FRAME_HEADER, 0x60, 0x01, 0x01, 0x07,
340 0x00, 0x00, /* Year */ 343 0x00, 0x00, /* Year */
341 0x00, /* Month */ 344 0x00, /* Month */
342 0x00, /* Day */ 345 0x00, /* Day */
343 0x00, /* Hour */ 346 0x00, /* Hour */
344 0x00, /* Minute */ 347 0x00, /* Minute */
345 0x00}; /* Unknown. Not seconds */ 348 0x00}; /* Unknown. Not seconds */
346 349
347 NOKIA_EncodeDateTime(s, req+7, date_time); 350 NOKIA_EncodeDateTime(s, req+7, date_time);
348 smprintf(s, "Setting date & time\n"); 351 smprintf(s, "Setting date & time\n");
349 return GSM_WaitFor (s, req, 14, msgtype, 4, ID_SetDateTime); 352 return GSM_WaitFor (s, req, 14, msgtype, 4, ID_SetDateTime);
350} 353}
351 354
352GSM_Error DCT3_ReplySetAlarm(GSM_Protocol_Message msg, GSM_StateMachine *s) 355GSM_Error DCT3_ReplySetAlarm(GSM_Protocol_Message msg, GSM_StateMachine *s)
353{ 356{
354 smprintf(s, "Alarm: "); 357 smprintf(s, "Alarm: ");
355 if (msg.Buffer[4]==0x01) { 358 if (msg.Buffer[4]==0x01) {
356 smprintf(s, "set OK\n"); 359 smprintf(s, "set OK\n");
357 return ERR_NONE; 360 return ERR_NONE;
358 } 361 }
359 smprintf(s, "error setting\n"); 362 smprintf(s, "error setting\n");
360 return ERR_UNKNOWN; 363 return ERR_UNKNOWN;
361} 364}
362 365
363GSM_Error DCT3_SetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm, unsigned char msgtype) 366GSM_Error DCT3_SetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm, unsigned char msgtype)
364{ 367{
365 unsigned char req[] = {N6110_FRAME_HEADER, 0x6b, 0x01, 0x20, 0x03, 368 unsigned char req[] = {N6110_FRAME_HEADER, 0x6b, 0x01, 0x20, 0x03,
366 0x02, /* Unknown. Not for enabling/disabling */ 369 0x02, /* Unknown. Not for enabling/disabling */
367 0x00, /* Hour */ 370 0x00, /* Hour */
368 0x00, /* Minute */ 371 0x00, /* Minute */
369 0x00}; /* Unknown. Not seconds */ 372 0x00}; /* Unknown. Not seconds */
370 373
371 if (alarm->Location != 1) return ERR_NOTSUPPORTED; 374 if (alarm->Location != 1) return ERR_NOTSUPPORTED;
372 375
373 req[8] = alarm->DateTime.Hour; 376 req[8] = alarm->DateTime.Hour;
374 req[9] = alarm->DateTime.Minute; 377 req[9] = alarm->DateTime.Minute;
375 378
376 smprintf(s, "Setting alarm\n"); 379 smprintf(s, "Setting alarm\n");
377 return GSM_WaitFor (s, req, 11, msgtype, 4, ID_SetAlarm); 380 return GSM_WaitFor (s, req, 11, msgtype, 4, ID_SetAlarm);
378} 381}
379 382
380GSM_Error DCT3_ReplyGetSMSC(GSM_Protocol_Message msg, GSM_StateMachine *s) 383GSM_Error DCT3_ReplyGetSMSC(GSM_Protocol_Message msg, GSM_StateMachine *s)
381{ 384{
382 int i; 385 int i;
383 GSM_Phone_Data*Data = &s->Phone.Data; 386 GSM_Phone_Data*Data = &s->Phone.Data;
384 387
385 switch (msg.Buffer[3]) { 388 switch (msg.Buffer[3]) {
386 case 0x34: 389 case 0x34:
387 smprintf(s, "SMSC received\n"); 390 smprintf(s, "SMSC received\n");
388 Data->SMSC->Format = SMS_FORMAT_Text; 391 Data->SMSC->Format = SMS_FORMAT_Text;
389 switch (msg.Buffer[6]) { 392 switch (msg.Buffer[6]) {
390 case 0x00: Data->SMSC->Format = SMS_FORMAT_Text; break; 393 case 0x00: Data->SMSC->Format = SMS_FORMAT_Text; break;
391 case 0x22: Data->SMSC->Format = SMS_FORMAT_Fax; break; 394 case 0x22: Data->SMSC->Format = SMS_FORMAT_Fax; break;
392 case 0x26: Data->SMSC->Format = SMS_FORMAT_Pager;break; 395 case 0x26: Data->SMSC->Format = SMS_FORMAT_Pager;break;
393 case 0x32: Data->SMSC->Format = SMS_FORMAT_Email;break; 396 case 0x32: Data->SMSC->Format = SMS_FORMAT_Email;break;
394 } 397 }
395 Data->SMSC->Validity.Format = SMS_Validity_RelativeFormat; 398 Data->SMSC->Validity.Format = SMS_Validity_RelativeFormat;
396 Data->SMSC->Validity.Relative= msg.Buffer[8]; 399 Data->SMSC->Validity.Relative= msg.Buffer[8];
400 if (msg.Buffer[8] == 0x00) Data->SMSC->Validity.Relative = SMS_VALID_Max_Time;
397 401
398 i=33; 402 i=33;
399 while (msg.Buffer[i]!=0) {i++;} 403 while (msg.Buffer[i]!=0) {i++;}
400 i=i-33; 404 i=i-33;
401 if (i>GSM_MAX_SMSC_NAME_LENGTH) { 405 if (i>GSM_MAX_SMSC_NAME_LENGTH) {
402 smprintf(s, "Too long name\n"); 406 smprintf(s, "Too long name\n");
403 return ERR_UNKNOWNRESPONSE; 407 return ERR_UNKNOWNRESPONSE;
404 } 408 }
405 EncodeUnicode(Data->SMSC->Name,msg.Buffer+33,i); 409 EncodeUnicode(Data->SMSC->Name,msg.Buffer+33,i);
406 smprintf(s, "Name \"%s\"\n", DecodeUnicodeString(Data->SMSC->Name)); 410 smprintf(s, "Name \"%s\"\n", DecodeUnicodeString(Data->SMSC->Name));
407 411
408 GSM_UnpackSemiOctetNumber(Data->SMSC->DefaultNumber,msg.Buffer+9,true); 412 GSM_UnpackSemiOctetNumber(Data->SMSC->DefaultNumber,msg.Buffer+9,true);
409 smprintf(s, "Default number \"%s\"\n", DecodeUnicodeString(Data->SMSC->DefaultNumber)); 413 smprintf(s, "Default number \"%s\"\n", DecodeUnicodeString(Data->SMSC->DefaultNumber));
410 414
411 GSM_UnpackSemiOctetNumber(Data->SMSC->Number,msg.Buffer+21,false); 415 GSM_UnpackSemiOctetNumber(Data->SMSC->Number,msg.Buffer+21,false);
412 smprintf(s, "Number \"%s\"\n", DecodeUnicodeString(Data->SMSC->Number)); 416 smprintf(s, "Number \"%s\"\n", DecodeUnicodeString(Data->SMSC->Number));
413 417
414 return ERR_NONE; 418 return ERR_NONE;
415 case 0x35: 419 case 0x35:
416 smprintf(s, "Getting SMSC failed\n"); 420 smprintf(s, "Getting SMSC failed\n");
417 return ERR_INVALIDLOCATION; 421 return ERR_INVALIDLOCATION;
418 } 422 }
419 return ERR_UNKNOWNRESPONSE; 423 return ERR_UNKNOWNRESPONSE;
420} 424}
421 425
422GSM_Error DCT3_GetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc) 426GSM_Error DCT3_GetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc)
423{ 427{
424 unsigned char req[] = {N6110_FRAME_HEADER, 0x33, 0x64, 428 unsigned char req[] = {N6110_FRAME_HEADER, 0x33, 0x64,
425 0x00}; /* Location */ 429 0x00}; /* Location */
426 430
427 if (smsc->Location==0x00) return ERR_INVALIDLOCATION; 431 if (smsc->Location==0x00) return ERR_INVALIDLOCATION;
428 432
429 req[5]=smsc->Location; 433 req[5]=smsc->Location;
430 434
431 s->Phone.Data.SMSC=smsc; 435 s->Phone.Data.SMSC=smsc;
432 smprintf(s, "Getting SMSC\n"); 436 smprintf(s, "Getting SMSC\n");
433 return GSM_WaitFor (s, req, 6, 0x02, 4, ID_GetSMSC); 437 return GSM_WaitFor (s, req, 6, 0x02, 4, ID_GetSMSC);
434} 438}
435 439
436GSM_Error DCT3_ReplyGetNetworkInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 440GSM_Error DCT3_ReplyGetNetworkInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
437{ 441{
438 int count; 442 int count;
439 GSM_Phone_Data*Data = &s->Phone.Data; 443 GSM_Phone_Data*Data = &s->Phone.Data;
440#ifdef DEBUG 444#ifdef DEBUG
441 GSM_NetworkInfo NetInfo; 445 GSM_NetworkInfo NetInfo;
442 char name[100]; 446 char name[100];
443 447
444 smprintf(s, "Network info received\n"); 448 smprintf(s, "Network info received\n");
445 smprintf(s, " Status : "); 449 smprintf(s, "Status : ");
446 switch (msg.Buffer[8]) { 450 switch (msg.Buffer[8]) {
447 case 0x01: smprintf(s, "home network"); break; 451 case 0x01: smprintf(s, "home network"); break;
448 case 0x02: smprintf(s, "roaming network"); break; 452 case 0x02: smprintf(s, "roaming network"); break;
449 case 0x03: smprintf(s, "requesting network"); break; 453 case 0x03: smprintf(s, "requesting network"); break;
450 case 0x04: smprintf(s, "not registered in the network");break; 454 case 0x04: smprintf(s, "not registered in the network");break;
451 default : smprintf(s, "unknown"); 455 default : smprintf(s, "unknown");
452 } 456 }
453 smprintf(s, "\n"); 457 smprintf(s, "\n");
454 smprintf(s, "Network selection : %s\n", msg.Buffer[9]==1?"manual":"automatic"); 458 smprintf(s, "Network selection : %s\n", msg.Buffer[9]==1?"manual":"automatic");
455 if (msg.Buffer[8]<0x03) { 459 if (msg.Buffer[8]<0x03) {
456 sprintf(NetInfo.CID, "%02x%02x", msg.Buffer[10], msg.Buffer[11]); 460 sprintf(NetInfo.CID, "%02x%02x", msg.Buffer[10], msg.Buffer[11]);
457 smprintf(s, "CID : %s\n", NetInfo.CID); 461 smprintf(s, "CID : %s\n", NetInfo.CID);
458 462
459 sprintf(NetInfo.LAC, "%02x%02x", msg.Buffer[12], msg.Buffer[13]); 463 sprintf(NetInfo.LAC, "%02x%02x", msg.Buffer[12], msg.Buffer[13]);
460 smprintf(s, "LAC : %s\n", NetInfo.LAC); 464 smprintf(s, "LAC : %s\n", NetInfo.LAC);
461 465
462 smprintf(s, "Network code : %s\n", NetInfo.NetworkCode);
463 NOKIA_DecodeNetworkCode(msg.Buffer+14,NetInfo.NetworkCode); 466 NOKIA_DecodeNetworkCode(msg.Buffer+14,NetInfo.NetworkCode);
467 smprintf(s, "Network code : %s\n", NetInfo.NetworkCode);
464 smprintf(s, "Network name for Gammu : %s ", 468 smprintf(s, "Network name for Gammu : %s ",
465 DecodeUnicodeString(GSM_GetNetworkName(NetInfo.NetworkCode))); 469 DecodeUnicodeString(GSM_GetNetworkName(NetInfo.NetworkCode)));
466 smprintf(s, "(%s)\n",DecodeUnicodeString(GSM_GetCountryName(NetInfo.NetworkCode))); 470 smprintf(s, "(%s)\n",DecodeUnicodeString(GSM_GetCountryName(NetInfo.NetworkCode)));
467 471
468 if (msg.Length>18) { 472 if (msg.Length>18) {
469 if (msg.Buffer[18]==0x00) { 473 if (msg.Buffer[18]==0x00) {
470 /* In 6210 name is in "normal" Unicode */ 474 /* In 6210 name is in "normal" Unicode */
471 memcpy(name,msg.Buffer+18,msg.Buffer[17]*2); 475 memcpy(name,msg.Buffer+18,msg.Buffer[17]*2);
472 name[msg.Buffer[17]*2]=0x00; 476 name[msg.Buffer[17]*2]=0x00;
473 name[msg.Buffer[17]*2+1]=0x00; 477 name[msg.Buffer[17]*2+1]=0x00;
474 smprintf(s, "Network name for phone : %s\n",DecodeUnicodeString(name)); 478 smprintf(s, "Network name for phone : %s\n",DecodeUnicodeString(name));
475 } else { 479 } else {
476 /* In 9210 first 0x00 is cut from Unicode string */ 480 /* In 9210 first 0x00 is cut from Unicode string */
477 name[0] = 0; 481 name[0] = 0;
478 memcpy(name+1,msg.Buffer+18,msg.Buffer[17]*2); 482 memcpy(name+1,msg.Buffer+18,msg.Buffer[17]*2);
479 name[msg.Buffer[17]*2+1]=0x00; 483 name[msg.Buffer[17]*2+1]=0x00;
480 name[msg.Buffer[17]*2+2]=0x00; 484 name[msg.Buffer[17]*2+2]=0x00;
481 smprintf(s, "Network name for phone : %s\n",DecodeUnicodeString(name)); 485 smprintf(s, "Network name for phone : %s\n",DecodeUnicodeString(name));
482 } 486 }
483 } 487 }
484 } 488 }
485#endif 489#endif
486 if (Data->RequestID==ID_GetNetworkInfo) { 490 if (Data->RequestID==ID_GetNetworkInfo) {
487 Data->NetworkInfo->NetworkName[0] = 0x00; 491 Data->NetworkInfo->NetworkName[0] = 0x00;
488 Data->NetworkInfo->NetworkName[1] = 0x00; 492 Data->NetworkInfo->NetworkName[1] = 0x00;
489 Data->NetworkInfo->State = 0; 493 Data->NetworkInfo->State = 0;
490 switch (msg.Buffer[8]) { 494 switch (msg.Buffer[8]) {
491 case 0x01: Data->NetworkInfo->State = GSM_HomeNetwork; break; 495 case 0x01: Data->NetworkInfo->State = GSM_HomeNetwork; break;
492 case 0x02: Data->NetworkInfo->State = GSM_RoamingNetwork;break; 496 case 0x02: Data->NetworkInfo->State = GSM_RoamingNetwork;break;
493 case 0x03: Data->NetworkInfo->State = GSM_RequestingNetwork;break; 497 case 0x03: Data->NetworkInfo->State = GSM_RequestingNetwork;break;
494 case 0x04: Data->NetworkInfo->State = GSM_NoNetwork; break; 498 case 0x04: Data->NetworkInfo->State = GSM_NoNetwork; break;
495 } 499 }
496 if (Data->NetworkInfo->State == GSM_HomeNetwork || Data->NetworkInfo->State == GSM_RoamingNetwork) { 500 if (Data->NetworkInfo->State == GSM_HomeNetwork || Data->NetworkInfo->State == GSM_RoamingNetwork) {
497 if (msg.Buffer[18]==0x00) { 501 if (msg.Buffer[18]==0x00) {
498 /* In 6210 name is in "normal" Unicode */ 502 /* In 6210 name is in "normal" Unicode */
499 memcpy(Data->NetworkInfo->NetworkName,msg.Buffer+18,msg.Buffer[17]*2); 503 memcpy(Data->NetworkInfo->NetworkName,msg.Buffer+18,msg.Buffer[17]*2);
500 Data->NetworkInfo->NetworkName[msg.Buffer[17]*2] = 0x00; 504 Data->NetworkInfo->NetworkName[msg.Buffer[17]*2] = 0x00;
501 Data->NetworkInfo->NetworkName[msg.Buffer[17]*2+1] = 0x00; 505 Data->NetworkInfo->NetworkName[msg.Buffer[17]*2+1] = 0x00;
502 } else { 506 } else {
503 /* In 9210 first 0x00 is cut from Unicode string */ 507 /* In 9210 first 0x00 is cut from Unicode string */
504 Data->NetworkInfo->NetworkName[0] = 0; 508 Data->NetworkInfo->NetworkName[0] = 0;
505 memcpy(Data->NetworkInfo->NetworkName+1,msg.Buffer+18,msg.Buffer[17]*2); 509 memcpy(Data->NetworkInfo->NetworkName+1,msg.Buffer+18,msg.Buffer[17]*2);
506 Data->NetworkInfo->NetworkName[msg.Buffer[17]*2+1]=0x00; 510 Data->NetworkInfo->NetworkName[msg.Buffer[17]*2+1]=0x00;
507 Data->NetworkInfo->NetworkName[msg.Buffer[17]*2+2]=0x00; 511 Data->NetworkInfo->NetworkName[msg.Buffer[17]*2+2]=0x00;
508 } 512 }
509 NOKIA_DecodeNetworkCode(msg.Buffer+14,Data->NetworkInfo->NetworkCode); 513 NOKIA_DecodeNetworkCode(msg.Buffer+14,Data->NetworkInfo->NetworkCode);
510 sprintf(Data->NetworkInfo->CID, "%02x%02x", msg.Buffer[10], msg.Buffer[11]); 514 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]); 515 sprintf(Data->NetworkInfo->LAC, "%02x%02x", msg.Buffer[12], msg.Buffer[13]);
512 } 516 }
513 } 517 }
514 /* 6210/6250/7110 */ 518 /* 6210/6250/7110 */
515 if (Data->RequestID==ID_GetBitmap) { 519 if (Data->RequestID==ID_GetBitmap) {
516 if (msg.Buffer[4]==0x02) { 520 if (msg.Buffer[4]==0x02) {
517 smprintf(s, "Operator logo available\n"); 521 smprintf(s, "Operator logo available\n");
518 count = 7; 522 count = 7;
519 /* skip network info */ 523 /* skip network info */
520 count += msg.Buffer[count]; 524 count += msg.Buffer[count];
521 count ++; 525 count ++;
522 Data->Bitmap->BitmapWidth= msg.Buffer[count++]; 526 Data->Bitmap->BitmapWidth= msg.Buffer[count++];
523 Data->Bitmap->BitmapHeight= msg.Buffer[count++]; 527 Data->Bitmap->BitmapHeight= msg.Buffer[count++];
524 count+=4; 528 count+=4;
525 PHONE_DecodeBitmap(GSM_Nokia7110OperatorLogo,msg.Buffer+count,Data->Bitmap); 529 PHONE_DecodeBitmap(GSM_Nokia7110OperatorLogo,msg.Buffer+count,Data->Bitmap);
526 NOKIA_DecodeNetworkCode(msg.Buffer+14,Data->Bitmap->NetworkCode); 530 NOKIA_DecodeNetworkCode(msg.Buffer+14,Data->Bitmap->NetworkCode);
527 } else { 531 } else {
528 Data->Bitmap->BitmapWidth= 78; 532 Data->Bitmap->BitmapWidth= 78;
529 Data->Bitmap->BitmapHeight= 21; 533 Data->Bitmap->BitmapHeight= 21;
530 GSM_ClearBitmap(Data->Bitmap); 534 GSM_ClearBitmap(Data->Bitmap);
531 strcpy(Data->Bitmap->NetworkCode,"000 00"); 535 strcpy(Data->Bitmap->NetworkCode,"000 00");
532 } 536 }
533 } 537 }
534 return ERR_NONE; 538 return ERR_NONE;
535} 539}
536 540
537GSM_Error DCT3_GetNetworkInfo(GSM_StateMachine *s, GSM_NetworkInfo *netinfo) 541GSM_Error DCT3_GetNetworkInfo(GSM_StateMachine *s, GSM_NetworkInfo *netinfo)
538{ 542{
539 unsigned char req[] = {N6110_FRAME_HEADER, 0x70}; 543 unsigned char req[] = {N6110_FRAME_HEADER, 0x70};
540 544
541 s->Phone.Data.NetworkInfo=netinfo; 545 s->Phone.Data.NetworkInfo=netinfo;
542 smprintf(s, "Getting network info\n"); 546 smprintf(s, "Getting network info\n");
543 return GSM_WaitFor (s, req, 4, 0x0a, 4, ID_GetNetworkInfo); 547 return GSM_WaitFor (s, req, 4, 0x0a, 4, ID_GetNetworkInfo);
544} 548}
545 549
546GSM_Error DCT3_ReplyDialCommand(GSM_Protocol_Message msg, GSM_StateMachine *s) 550GSM_Error DCT3_ReplyDialCommand(GSM_Protocol_Message msg, GSM_StateMachine *s)
547{ 551{
548 smprintf(s, "Answer for call commands\n"); 552 smprintf(s, "Answer for call commands\n");
549 return ERR_NONE; 553 return ERR_NONE;
550} 554}
551 555
552GSM_Error DCT3_DialVoice(GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber) 556GSM_Error DCT3_DialVoice(GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber)
553{ 557{
554 unsigned inti = 0; 558 unsigned inti = 0;
555 GSM_Errorerror; 559 GSM_Errorerror;
556 unsigned char req[100] = {0x00, 0x01, 0x7c, 560 unsigned char req[100] = {0x00, 0x01, 0x7c,
557 0x01}; /* call command */ 561 0x01}; /* call command */
558 562
559 if (ShowNumber != GSM_CALL_DefaultNumberPresence) return ERR_NOTSUPPORTED; 563 if (ShowNumber != GSM_CALL_DefaultNumberPresence) return ERR_NOTSUPPORTED;
560 564
561 error=DCT3_EnableSecurity (s, 0x01); 565 error=DCT3_EnableSecurity (s, 0x01);
562 if (error!=ERR_NONE) return error; 566 if (error!=ERR_NONE) return error;
563 567
564 for (i=0; i < strlen(number); i++) req[4+i]=number[i]; 568 for (i=0; i < strlen(number); i++) req[4+i]=number[i];
565 req[4+i+1]=0; 569 req[4+i+1]=0;
566 570
567 smprintf(s, "Making voice call\n"); 571 smprintf(s, "Making voice call\n");
568 return GSM_WaitFor (s, req, 4+strlen(number)+1, 0x40, 4, ID_DialVoice); 572 return GSM_WaitFor (s, req, 4+strlen(number)+1, 0x40, 4, ID_DialVoice);
569} 573}
570 574
571static GSM_Error DCT3_CancelAllCalls(GSM_StateMachine *s) 575static GSM_Error DCT3_CancelAllCalls(GSM_StateMachine *s)
572{ 576{
573 GSM_Errorerror; 577 GSM_Errorerror;
574 unsigned char req[] = {0x00, 0x01, 0x7c, 578 unsigned char req[] = {0x00, 0x01, 0x7c,
575 0x03}; /* call command */ 579 0x03}; /* call command */
576 580
577 error=DCT3_EnableSecurity (s, 0x01); 581 error=DCT3_EnableSecurity (s, 0x01);
578 if (error!=ERR_NONE) return error; 582 if (error!=ERR_NONE) return error;
579 583
580 smprintf(s, "Canceling calls\n"); 584 smprintf(s, "Canceling calls\n");
581 return GSM_WaitFor (s, req, 4, 0x40, 4, ID_CancelCall); 585 return GSM_WaitFor (s, req, 4, 0x40, 4, ID_CancelCall);
582} 586}
583 587
584GSM_Error DCT3_CancelCall(GSM_StateMachine *s, int ID, bool all) 588GSM_Error DCT3_CancelCall(GSM_StateMachine *s, int ID, bool all)
585{ 589{
586 if (!all) return DCT3DCT4_CancelCall(s,ID); 590 if (!all) return DCT3DCT4_CancelCall(s,ID);
587 return DCT3_CancelAllCalls(s); 591 return DCT3_CancelAllCalls(s);
588} 592}
589 593
590GSM_Error DCT3_AnswerAllCalls(GSM_StateMachine *s) 594GSM_Error DCT3_AnswerAllCalls(GSM_StateMachine *s)
591{ 595{
592 GSM_Errorerror; 596 GSM_Errorerror;
593 unsigned char req[] = {0x00, 0x01, 0x7c, 597 unsigned char req[] = {0x00, 0x01, 0x7c,
594 0x02}; /* call command */ 598 0x02}; /* call command */
595 599
596 error=DCT3_EnableSecurity (s, 0x01); 600 error=DCT3_EnableSecurity (s, 0x01);
597 if (error!=ERR_NONE) return error; 601 if (error!=ERR_NONE) return error;
598 602
599 smprintf(s, "Answering calls\n"); 603 smprintf(s, "Answering calls\n");
600 return GSM_WaitFor (s, req, 4, 0x40, 4, ID_AnswerCall); 604 return GSM_WaitFor (s, req, 4, 0x40, 4, ID_AnswerCall);
601} 605}
602 606
603GSM_Error DCT3_Reset(GSM_StateMachine *s, bool hard) 607GSM_Error DCT3_Reset(GSM_StateMachine *s, bool hard)
604{ 608{
605 GSM_Error error; 609 GSM_Error error;
606 610
607 if (hard) { 611 if (hard) {
608 error=DCT3_EnableSecurity(s, 0x04); 612 error=DCT3_EnableSecurity(s, 0x04);
609 } else { 613 } else {
610 error=DCT3_EnableSecurity(s, 0x03); 614 error=DCT3_EnableSecurity(s, 0x03);
611 } 615 }
612 if (error == ERR_NONE) { 616 if (error == ERR_NONE) {
613 s->Phone.Data.EnableIncomingSMS = false; 617 s->Phone.Data.EnableIncomingSMS = false;
614 s->Phone.Data.EnableIncomingCB = false; 618 s->Phone.Data.EnableIncomingCB = false;
615 } 619 }
616 return error; 620 return error;
617} 621}
618 622
619GSM_Error DCT3_ReplyGetWAPBookmark(GSM_Protocol_Message msg, GSM_StateMachine *s) 623GSM_Error DCT3_ReplyGetWAPBookmark(GSM_Protocol_Message msg, GSM_StateMachine *s)
620{ 624{
621 return DCT3DCT4_ReplyGetWAPBookmark (msg,s,false); 625 return DCT3DCT4_ReplyGetWAPBookmark (msg,s,false);
622} 626}
623 627
624GSM_Error DCT3_SetWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark) 628GSM_Error DCT3_SetWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
625{ 629{
626 GSM_Error error; 630 GSM_Error error;
627 int count = 4, location; 631 int count = 4, location;
628 unsigned char req[600] = {N6110_FRAME_HEADER, 0x09}; 632 unsigned char req[600] = {N6110_FRAME_HEADER, 0x09};
629 633
630 /* We have to enable WAP frames in phone */ 634 /* We have to enable WAP frames in phone */
631 error=DCT3DCT4_EnableWAPFunctions(s); 635 error=DCT3DCT4_EnableWAPFunctions(s);
632 if (error!=ERR_NONE) return error; 636 if (error!=ERR_NONE) return error;
633 637
634 location = bookmark->Location - 1; 638 location = bookmark->Location - 1;
635 if (bookmark->Location == 0) location = 0xffff; 639 if (bookmark->Location == 0) location = 0xffff;
636 req[count++] = (location & 0xff00) >> 8; 640 req[count++] = (location & 0xff00) >> 8;
637 req[count++] = location & 0x00ff; 641 req[count++] = location & 0x00ff;
638 642
639 count += NOKIA_SetUnicodeString(s, req+count, bookmark->Title, false); 643 count += NOKIA_SetUnicodeString(s, req+count, bookmark->Title, false);
640 count += NOKIA_SetUnicodeString(s, req+count, bookmark->Address, false); 644 count += NOKIA_SetUnicodeString(s, req+count, bookmark->Address, false);
641 645
642 /* unknown */ 646 /* unknown */
643 req[count++] = 0x01; req[count++] = 0x80; req[count++] = 0x00; 647 req[count++] = 0x01; req[count++] = 0x80; req[count++] = 0x00;
644 req[count++] = 0x00; req[count++] = 0x00; req[count++] = 0x00; 648 req[count++] = 0x00; req[count++] = 0x00; req[count++] = 0x00;
645 req[count++] = 0x00; req[count++] = 0x00; req[count++] = 0x00; 649 req[count++] = 0x00; req[count++] = 0x00; req[count++] = 0x00;
646 650
647 smprintf(s, "Setting WAP bookmark\n"); 651 smprintf(s, "Setting WAP bookmark\n");
648 error = GSM_WaitFor (s, req, count, 0x3f, 4, ID_SetWAPBookmark); 652 error = GSM_WaitFor (s, req, count, 0x3f, 4, ID_SetWAPBookmark);
649 if (error != ERR_NONE) { 653 if (error != ERR_NONE) {
650 if (error == ERR_INSIDEPHONEMENU || error == ERR_EMPTY || error == ERR_FULL) { 654 if (error == ERR_INSIDEPHONEMENU || error == ERR_EMPTY || error == ERR_FULL) {
651 DCT3DCT4_DisableConnectionFunctions(s); 655 DCT3DCT4_DisableConnectionFunctions(s);
652 } 656 }
653 return error; 657 return error;
654 } 658 }
655 659
@@ -1019,389 +1023,389 @@ GSM_Error DCT3_SetWAPSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *setting
1019 if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_USSD) { 1023 if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_USSD) {
1020 if (phone3 != -1) loc3=i; 1024 if (phone3 != -1) loc3=i;
1021 } 1025 }
1022 } 1026 }
1023 1027
1024 pos = 5; 1028 pos = 5;
1025 memset(SetReq + pos, 0, 200 - pos); 1029 memset(SetReq + pos, 0, 200 - pos);
1026 SetReq[4] = settings->Location - 1; 1030 SetReq[4] = settings->Location - 1;
1027 if (loc1 != -1) { 1031 if (loc1 != -1) {
1028 /* Name */ 1032 /* Name */
1029 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc1].Title, false); 1033 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc1].Title, false);
1030 /* HomePage */ 1034 /* HomePage */
1031 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc1].HomePage, false); 1035 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc1].HomePage, false);
1032 if (settings->Settings[loc1].IsContinuous) SetReq[pos] = 0x01; 1036 if (settings->Settings[loc1].IsContinuous) SetReq[pos] = 0x01;
1033 pos++; 1037 pos++;
1034 SetReq[pos++] = ID; 1038 SetReq[pos++] = ID;
1035 1039
1036 SetReq[pos] = phone1; /* bearer */ 1040 SetReq[pos] = phone1; /* bearer */
1037 switch (settings->ActiveBearer) { 1041 switch (settings->ActiveBearer) {
1038 case WAPSETTINGS_BEARER_DATA: 1042 case WAPSETTINGS_BEARER_DATA:
1039 if (loc1 != -1) SetReq[pos] = phone1; 1043 if (loc1 != -1) SetReq[pos] = phone1;
1040 break; 1044 break;
1041 case WAPSETTINGS_BEARER_SMS: 1045 case WAPSETTINGS_BEARER_SMS:
1042 if (loc2 != -1) SetReq[pos] = phone2; 1046 if (loc2 != -1) SetReq[pos] = phone2;
1043 break; 1047 break;
1044 case WAPSETTINGS_BEARER_USSD: 1048 case WAPSETTINGS_BEARER_USSD:
1045 if (loc3 != -1) SetReq[pos] = phone3; 1049 if (loc3 != -1) SetReq[pos] = phone3;
1046 break; 1050 break;
1047 default: break; 1051 default: break;
1048 } 1052 }
1049 pos++; 1053 pos++;
1050 1054
1051 if (settings->Settings[loc1].IsSecurity) SetReq[pos] = 0x01; 1055 if (settings->Settings[loc1].IsSecurity) SetReq[pos] = 0x01;
1052 pos++; 1056 pos++;
1053 } else if (loc2 != -1) { 1057 } else if (loc2 != -1) {
1054 /* Name */ 1058 /* Name */
1055 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc2].Title, false); 1059 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc2].Title, false);
1056 /* HomePage */ 1060 /* HomePage */
1057 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc2].HomePage, false); 1061 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc2].HomePage, false);
1058 if (settings->Settings[loc2].IsContinuous) SetReq[pos] = 0x01; 1062 if (settings->Settings[loc2].IsContinuous) SetReq[pos] = 0x01;
1059 pos++; 1063 pos++;
1060 SetReq[pos++] = ID; 1064 SetReq[pos++] = ID;
1061 1065
1062 SetReq[pos] = phone2; /* bearer */ 1066 SetReq[pos] = phone2; /* bearer */
1063 switch (settings->ActiveBearer) { 1067 switch (settings->ActiveBearer) {
1064 case WAPSETTINGS_BEARER_DATA: 1068 case WAPSETTINGS_BEARER_DATA:
1065 if (loc1 != -1) SetReq[pos] = phone1; 1069 if (loc1 != -1) SetReq[pos] = phone1;
1066 break; 1070 break;
1067 case WAPSETTINGS_BEARER_SMS: 1071 case WAPSETTINGS_BEARER_SMS:
1068 if (loc2 != -1) SetReq[pos] = phone2; 1072 if (loc2 != -1) SetReq[pos] = phone2;
1069 break; 1073 break;
1070 case WAPSETTINGS_BEARER_USSD: 1074 case WAPSETTINGS_BEARER_USSD:
1071 if (loc3 != -1) SetReq[pos] = phone3; 1075 if (loc3 != -1) SetReq[pos] = phone3;
1072 break; 1076 break;
1073 default: break; 1077 default: break;
1074 } 1078 }
1075 pos++; 1079 pos++;
1076 1080
1077 if (settings->Settings[loc2].IsSecurity) SetReq[pos] = 0x01; 1081 if (settings->Settings[loc2].IsSecurity) SetReq[pos] = 0x01;
1078 pos++; 1082 pos++;
1079 } else if (loc3 != -1) { 1083 } else if (loc3 != -1) {
1080 /* Name */ 1084 /* Name */
1081 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc3].Title, false); 1085 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc3].Title, false);
1082 /* HomePage */ 1086 /* HomePage */
1083 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc3].HomePage, false); 1087 pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc3].HomePage, false);
1084 if (settings->Settings[loc3].IsContinuous) SetReq[pos] = 0x01; 1088 if (settings->Settings[loc3].IsContinuous) SetReq[pos] = 0x01;
1085 pos++; 1089 pos++;
1086 SetReq[pos++] = ID; 1090 SetReq[pos++] = ID;
1087 1091
1088 SetReq[pos] = phone3; /* bearer */ 1092 SetReq[pos] = phone3; /* bearer */
1089 switch (settings->ActiveBearer) { 1093 switch (settings->ActiveBearer) {
1090 case WAPSETTINGS_BEARER_DATA: 1094 case WAPSETTINGS_BEARER_DATA:
1091 if (loc1 != -1) SetReq[pos] = phone1; 1095 if (loc1 != -1) SetReq[pos] = phone1;
1092 break; 1096 break;
1093 case WAPSETTINGS_BEARER_SMS: 1097 case WAPSETTINGS_BEARER_SMS:
1094 if (loc2 != -1) SetReq[pos] = phone2; 1098 if (loc2 != -1) SetReq[pos] = phone2;
1095 break; 1099 break;
1096 case WAPSETTINGS_BEARER_USSD: 1100 case WAPSETTINGS_BEARER_USSD:
1097 if (loc3 != -1) SetReq[pos] = phone3; 1101 if (loc3 != -1) SetReq[pos] = phone3;
1098 break; 1102 break;
1099 default: break; 1103 default: break;
1100 } 1104 }
1101 pos++; 1105 pos++;
1102 1106
1103 if (settings->Settings[loc3].IsSecurity) SetReq[pos] = 0x01; 1107 if (settings->Settings[loc3].IsSecurity) SetReq[pos] = 0x01;
1104 pos++; 1108 pos++;
1105 } else { 1109 } else {
1106 return ERR_UNKNOWN;/* We have to have write something known */ 1110 return ERR_UNKNOWN;/* We have to have write something known */
1107 } 1111 }
1108 memcpy(SetReq + pos, "\x01\x80\x00\x00\x00\x00\x00\x00\x00", 9); 1112 memcpy(SetReq + pos, "\x01\x80\x00\x00\x00\x00\x00\x00\x00", 9);
1109 pos += 9; 1113 pos += 9;
1110 1114
1111 smprintf(s, "Writing WAP settings part 1\n"); 1115 smprintf(s, "Writing WAP settings part 1\n");
1112 error=GSM_WaitFor (s, SetReq, pos, 0x3f, 4, ID_SetConnectSet); 1116 error=GSM_WaitFor (s, SetReq, pos, 0x3f, 4, ID_SetConnectSet);
1113 if (error != ERR_NONE) return error; 1117 if (error != ERR_NONE) return error;
1114 1118
1115 /* Data */ 1119 /* Data */
1116 if (phone1 != -1) { 1120 if (phone1 != -1) {
1117 pos = 4; 1121 pos = 4;
1118 memset(SetReq2 + pos, 0, 200 - pos); 1122 memset(SetReq2 + pos, 0, 200 - pos);
1119 SetReq2[pos++] = phone1; 1123 SetReq2[pos++] = phone1;
1120 SetReq2[pos++] = 0x02; 1124 SetReq2[pos++] = 0x02;
1121 SetReq2[pos++] = 0x01; /* GSMdata */ 1125 SetReq2[pos++] = 0x01; /* GSMdata */
1122 if (loc1 != -1) { 1126 if (loc1 != -1) {
1123 if (!settings->Settings[loc1].IsNormalAuthentication) SetReq2[pos] = 0x01; 1127 if (!settings->Settings[loc1].IsNormalAuthentication) SetReq2[pos] = 0x01;
1124 } 1128 }
1125 pos++; 1129 pos++;
1126 if (loc1 != -1) { 1130 if (loc1 != -1) {
1127 if (settings->Settings[loc1].IsISDNCall) SetReq2[pos] = 0x01; 1131 if (settings->Settings[loc1].IsISDNCall) SetReq2[pos] = 0x01;
1128 } 1132 }
1129 pos++; 1133 pos++;
1130 if (loc1 != -1) { 1134 if (loc1 != -1) {
1131 switch (settings->Settings[loc1].Speed) { 1135 switch (settings->Settings[loc1].Speed) {
1132 case WAPSETTINGS_SPEED_9600 : SetReq2[pos++] = 0x01; break; 1136 case WAPSETTINGS_SPEED_9600 : SetReq2[pos++] = 0x01; break;
1133 case WAPSETTINGS_SPEED_14400 : SetReq2[pos++] = 0x02; break; 1137 case WAPSETTINGS_SPEED_14400 : SetReq2[pos++] = 0x02; break;
1134 default : SetReq2[pos++] = 0x02; break; 1138 default : SetReq2[pos++] = 0x02; break;
1135 } 1139 }
1136 switch (settings->Settings[loc1].Speed) { 1140 switch (settings->Settings[loc1].Speed) {
1137 case WAPSETTINGS_SPEED_9600 : SetReq2[pos++] = 0x01; break; 1141 case WAPSETTINGS_SPEED_9600 : SetReq2[pos++] = 0x01; break;
1138 case WAPSETTINGS_SPEED_14400 : SetReq2[pos++] = 0x02; break; 1142 case WAPSETTINGS_SPEED_14400 : SetReq2[pos++] = 0x02; break;
1139 default : SetReq2[pos++] = 0x02; break; 1143 default : SetReq2[pos++] = 0x02; break;
1140 } 1144 }
1141 } else pos+=2; 1145 } else pos+=2;
1142 if (loc1 != -1) { 1146 if (loc1 != -1) {
1143 /* IP */ 1147 /* IP */
1144 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc1].IPAddress, false); 1148 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc1].IPAddress, false);
1145 /* Number */ 1149 /* Number */
1146 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc1].DialUp, false); 1150 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc1].DialUp, false);
1147 /* Username */ 1151 /* Username */
1148 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc1].User, false); 1152 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc1].User, false);
1149 /* Password */ 1153 /* Password */
1150 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc1].Password, false); 1154 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc1].Password, false);
1151 } else pos+=5; 1155 } else pos+=5;
1152 memcpy(SetReq2 + pos, "\x80\x00\x00\x00\x00\x00\x00\x00", 8); 1156 memcpy(SetReq2 + pos, "\x80\x00\x00\x00\x00\x00\x00\x00", 8);
1153 pos += 8; 1157 pos += 8;
1154 smprintf(s, "Writing WAP settings part 2 (Data bearer)\n"); 1158 smprintf(s, "Writing WAP settings part 2 (Data bearer)\n");
1155 error=GSM_WaitFor (s, SetReq2, pos, 0x3f, 4, ID_SetConnectSet); 1159 error=GSM_WaitFor (s, SetReq2, pos, 0x3f, 4, ID_SetConnectSet);
1156 if (error != ERR_NONE) return error; 1160 if (error != ERR_NONE) return error;
1157 } 1161 }
1158 /* SMS */ 1162 /* SMS */
1159 if (phone2 != -1) { 1163 if (phone2 != -1) {
1160 pos = 4; 1164 pos = 4;
1161 memset(SetReq2 + pos, 0, 200 - pos); 1165 memset(SetReq2 + pos, 0, 200 - pos);
1162 SetReq2[pos++] = phone2; 1166 SetReq2[pos++] = phone2;
1163 SetReq2[pos++] = 0x02; 1167 SetReq2[pos++] = 0x02;
1164 SetReq2[pos++] = 0x00; /* SMS */ 1168 SetReq2[pos++] = 0x00; /* SMS */
1165 if (loc2 != -1) { 1169 if (loc2 != -1) {
1166 /* Service number */ 1170 /* Service number */
1167 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc2].Service, false); 1171 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc2].Service, false);
1168 /* Server number */ 1172 /* Server number */
1169 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc2].Server, false); 1173 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc2].Server, false);
1170 } else pos += 2; 1174 } else pos += 2;
1171 memcpy(SetReq2 + pos, "\x80\x00\x00\x00\x00\x00\x00\x00", 8); 1175 memcpy(SetReq2 + pos, "\x80\x00\x00\x00\x00\x00\x00\x00", 8);
1172 pos += 8; 1176 pos += 8;
1173 smprintf(s, "Writing WAP settings part 2 (SMS bearer)\n"); 1177 smprintf(s, "Writing WAP settings part 2 (SMS bearer)\n");
1174 error=GSM_WaitFor (s, SetReq2, pos, 0x3f, 4, ID_SetConnectSet); 1178 error=GSM_WaitFor (s, SetReq2, pos, 0x3f, 4, ID_SetConnectSet);
1175 if (error != ERR_NONE) return error; 1179 if (error != ERR_NONE) return error;
1176 } 1180 }
1177 /* USSD */ 1181 /* USSD */
1178 if (phone3 != -1) { 1182 if (phone3 != -1) {
1179 pos = 4; 1183 pos = 4;
1180 memset(SetReq2 + pos, 0, 200 - pos); 1184 memset(SetReq2 + pos, 0, 200 - pos);
1181 SetReq2[pos++] = phone3; 1185 SetReq2[pos++] = phone3;
1182 SetReq2[pos++] = 0x02; 1186 SetReq2[pos++] = 0x02;
1183 SetReq2[pos++] = 0x02; /* USSD */ 1187 SetReq2[pos++] = 0x02; /* USSD */
1184 if (loc3 != -1) { 1188 if (loc3 != -1) {
1185 if (!settings->Settings[loc3].IsIP) SetReq2[pos] = 0x01; 1189 if (!settings->Settings[loc3].IsIP) SetReq2[pos] = 0x01;
1186 } 1190 }
1187 pos++; 1191 pos++;
1188 if (loc3 != -1) { 1192 if (loc3 != -1) {
1189 /* Service number or IP address */ 1193 /* Service number or IP address */
1190 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc3].Service, false); 1194 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc3].Service, false);
1191 /* Code number */ 1195 /* Code number */
1192 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc3].Code, false); 1196 pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc3].Code, false);
1193 } else pos+=2; 1197 } else pos+=2;
1194 memcpy(SetReq2 + pos, "\x80\x00\x00\x00\x00\x00\x00\x00", 8); 1198 memcpy(SetReq2 + pos, "\x80\x00\x00\x00\x00\x00\x00\x00", 8);
1195 pos += 8; 1199 pos += 8;
1196 smprintf(s, "Writing WAP settings part 2 (USSD bearer)\n"); 1200 smprintf(s, "Writing WAP settings part 2 (USSD bearer)\n");
1197 error=GSM_WaitFor (s, SetReq2, pos, 0x3f, 4, ID_SetConnectSet); 1201 error=GSM_WaitFor (s, SetReq2, pos, 0x3f, 4, ID_SetConnectSet);
1198 if (error != ERR_NONE) return error; 1202 if (error != ERR_NONE) return error;
1199 } 1203 }
1200 error = DCT3DCT4_SetActiveConnectSet(s, settings); 1204 error = DCT3DCT4_SetActiveConnectSet(s, settings);
1201 if (error != ERR_NONE) return error; 1205 if (error != ERR_NONE) return error;
1202 1206
1203 return DCT3DCT4_DisableConnectionFunctions(s); 1207 return DCT3DCT4_DisableConnectionFunctions(s);
1204} 1208}
1205 1209
1206GSM_Error DCT3_ReplySendSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s) 1210GSM_Error DCT3_ReplySendSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s)
1207{ 1211{
1208 switch (msg.Buffer[3]) { 1212 switch (msg.Buffer[3]) {
1209 case 0x02: 1213 case 0x02:
1210 smprintf(s, "SMS sent OK\n"); 1214 smprintf(s, "SMS sent OK\n");
1211 if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s->CurrentConfig->Device,0,0); 1215 if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s->CurrentConfig->Device,0,msg.Buffer[5]);
1212 return ERR_NONE; 1216 return ERR_NONE;
1213 case 0x03: 1217 case 0x03:
1214 smprintf(s, "Error %i\n",msg.Buffer[6]); 1218 smprintf(s, "Error %i\n",msg.Buffer[6]);
1215 if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s->CurrentConfig->Device,msg.Buffer[6],0); 1219 if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s->CurrentConfig->Device,msg.Buffer[6],-1);
1216 return ERR_NONE; 1220 return ERR_NONE;
1217 } 1221 }
1218 return ERR_UNKNOWNRESPONSE; 1222 return ERR_UNKNOWNRESPONSE;
1219} 1223}
1220 1224
1221GSM_Error DCT3_SendSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms) 1225GSM_Error DCT3_SendSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms)
1222{ 1226{
1223 int length; 1227 int length;
1224 GSM_Error error; 1228 GSM_Error error;
1225 unsigned char req[256] = {N6110_FRAME_HEADER, 0x01, 0x02, 0x00}; 1229 unsigned char req[256] = {N6110_FRAME_HEADER, 0x01, 0x02, 0x00};
1226 1230
1227 error=PHONE_EncodeSMSFrame(s,sms,req+6,PHONE_SMSSubmit,&length, true); 1231 error=PHONE_EncodeSMSFrame(s,sms,req+6,PHONE_SMSSubmit,&length, true);
1228 if (error != ERR_NONE) return error; 1232 if (error != ERR_NONE) return error;
1229 1233
1230 smprintf(s, "Sending sms\n"); 1234 smprintf(s, "Sending sms\n");
1231 return s->Protocol.Functions->WriteMessage(s, req, 6+length, 0x02); 1235 return s->Protocol.Functions->WriteMessage(s, req, 6+length, 0x02);
1232} 1236}
1233 1237
1234GSM_Error DCT3_ReplyNetmonitor(GSM_Protocol_Message msg, GSM_StateMachine *s) 1238GSM_Error DCT3_ReplyNetmonitor(GSM_Protocol_Message msg, GSM_StateMachine *s)
1235{ 1239{
1236 switch (msg.Buffer[3]) { 1240 switch (msg.Buffer[3]) {
1237 case 0x00: 1241 case 0x00:
1238 smprintf(s, "Netmonitor correctly set\n"); 1242 smprintf(s, "Netmonitor correctly set\n");
1239 break; 1243 break;
1240 default: 1244 default:
1241 smprintf(s, "Menu %i\n",msg.Buffer[3]); 1245 smprintf(s, "Menu %i\n",msg.Buffer[3]);
1242 smprintf(s, "%s\n",msg.Buffer+4); 1246 smprintf(s, "%s\n",msg.Buffer+4);
1243 strcpy(s->Phone.Data.Netmonitor,msg.Buffer+4); 1247 strcpy(s->Phone.Data.Netmonitor,msg.Buffer+4);
1244 break; 1248 break;
1245 } 1249 }
1246 return ERR_NONE; 1250 return ERR_NONE;
1247} 1251}
1248 1252
1249GSM_Error DCT3_Netmonitor(GSM_StateMachine *s, int testnumber, char *value) 1253GSM_Error DCT3_Netmonitor(GSM_StateMachine *s, int testnumber, char *value)
1250{ 1254{
1251 GSM_Error error; 1255 GSM_Error error;
1252 unsigned char req[] = {0x00, 0x01, 0x7e, 1256 unsigned char req[] = {0x00, 0x01, 0x7e,
1253 0x00}; /* Test number */ 1257 0x00}; /* Test number */
1254 1258
1255 value[0] = 0; 1259 value[0] = 0;
1256 1260
1257 error=DCT3_EnableSecurity (s, 0x01); 1261 error=DCT3_EnableSecurity (s, 0x01);
1258 if (error != ERR_NONE) return error; 1262 if (error != ERR_NONE) return error;
1259 1263
1260 req[3] = testnumber; 1264 req[3] = testnumber;
1261 1265
1262 smprintf(s, "Getting netmonitor test\n"); 1266 smprintf(s, "Getting netmonitor test\n");
1263 s->Phone.Data.Netmonitor = value; 1267 s->Phone.Data.Netmonitor = value;
1264 return GSM_WaitFor (s, req, 4, 0x40, 4, ID_Netmonitor); 1268 return GSM_WaitFor (s, req, 4, 0x40, 4, ID_Netmonitor);
1265} 1269}
1266 1270
1267GSM_Error DCT3_GetManufactureMonth(GSM_StateMachine *s, char *value) 1271GSM_Error DCT3_GetManufactureMonth(GSM_StateMachine *s, char *value)
1268{ 1272{
1269 GSM_Error error; 1273 GSM_Error error;
1270 1274
1271 error=DCT3_EnableSecurity (s, 0x01); 1275 error=DCT3_EnableSecurity (s, 0x01);
1272 if (error != ERR_NONE) return error; 1276 if (error != ERR_NONE) return error;
1273 return NOKIA_GetPhoneString(s,"\x00\x01\xCC\x02",4,0x40,value,ID_GetManufactureMonth,5); 1277 return NOKIA_GetPhoneString(s,"\x00\x01\xCC\x02",4,0x40,value,ID_GetManufactureMonth,5);
1274} 1278}
1275 1279
1276GSM_Error DCT3_GetProductCode(GSM_StateMachine *s, char *value) 1280GSM_Error DCT3_GetProductCode(GSM_StateMachine *s, char *value)
1277{ 1281{
1278 GSM_Error error; 1282 GSM_Error error;
1279 1283
1280 if (strlen(s->Phone.Data.ProductCodeCache)!=0) { 1284 if (strlen(s->Phone.Data.ProductCodeCache)!=0) {
1281 strcpy(value,s->Phone.Data.ProductCodeCache); 1285 strcpy(value,s->Phone.Data.ProductCodeCache);
1282 return ERR_NONE; 1286 return ERR_NONE;
1283 } 1287 }
1284 1288
1285 error=DCT3_EnableSecurity (s, 0x01); 1289 error=DCT3_EnableSecurity (s, 0x01);
1286 if (error != ERR_NONE) return error; 1290 if (error != ERR_NONE) return error;
1287 return NOKIA_GetPhoneString(s,"\x00\x01\xCA\x01",4,0x40,value,ID_GetProductCode,5); 1291 return NOKIA_GetPhoneString(s,"\x00\x01\xCA\x01",4,0x40,value,ID_GetProductCode,5);
1288} 1292}
1289 1293
1290GSM_Error DCT3_GetOriginalIMEI(GSM_StateMachine *s, char *value) 1294GSM_Error DCT3_GetOriginalIMEI(GSM_StateMachine *s, char *value)
1291{ 1295{
1292 GSM_Error error; 1296 GSM_Error error;
1293 1297
1294 error=DCT3_EnableSecurity (s, 0x01); 1298 error=DCT3_EnableSecurity (s, 0x01);
1295 if (error != ERR_NONE) return error; 1299 if (error != ERR_NONE) return error;
1296 return NOKIA_GetPhoneString(s,"\x00\x01\xCC\x01",4,0x40,value,ID_GetOriginalIMEI,5); 1300 return NOKIA_GetPhoneString(s,"\x00\x01\xCC\x01",4,0x40,value,ID_GetOriginalIMEI,5);
1297} 1301}
1298 1302
1299GSM_Error DCT3_GetHardware(GSM_StateMachine *s, char *value) 1303GSM_Error DCT3_GetHardware(GSM_StateMachine *s, char *value)
1300{ 1304{
1301 GSM_Error error; 1305 GSM_Error error;
1302 1306
1303 if (strlen(s->Phone.Data.HardwareCache)!=0) { 1307 if (strlen(s->Phone.Data.HardwareCache)!=0) {
1304 strcpy(value,s->Phone.Data.HardwareCache); 1308 strcpy(value,s->Phone.Data.HardwareCache);
1305 return ERR_NONE; 1309 return ERR_NONE;
1306 } 1310 }
1307 1311
1308 error=DCT3_EnableSecurity (s, 0x01); 1312 error=DCT3_EnableSecurity (s, 0x01);
1309 if (error != ERR_NONE) return error; 1313 if (error != ERR_NONE) return error;
1310 return NOKIA_GetPhoneString(s,"\x00\x01\xC8\x05",4,0x40,value,ID_GetHardware,5); 1314 return NOKIA_GetPhoneString(s,"\x00\x01\xC8\x05",4,0x40,value,ID_GetHardware,5);
1311} 1315}
1312 1316
1313GSM_Error DCT3_GetPPM(GSM_StateMachine *s, char *value) 1317GSM_Error DCT3_GetPPM(GSM_StateMachine *s, char *value)
1314{ 1318{
1315 GSM_Error error; 1319 GSM_Error error;
1316 1320
1317 error=DCT3_EnableSecurity (s, 0x01); 1321 error=DCT3_EnableSecurity (s, 0x01);
1318 if (error != ERR_NONE) return error; 1322 if (error != ERR_NONE) return error;
1319 return NOKIA_GetPhoneString(s,"\x00\x01\xC8\x12",4,0x40,value,ID_GetPPM,5); 1323 return NOKIA_GetPhoneString(s,"\x00\x01\xC8\x12",4,0x40,value,ID_GetPPM,5);
1320} 1324}
1321 1325
1322GSM_Error DCT3_GetSMSStatus(GSM_StateMachine *s, GSM_SMSMemoryStatus *status) 1326GSM_Error DCT3_GetSMSStatus(GSM_StateMachine *s, GSM_SMSMemoryStatus *status)
1323{ 1327{
1324 unsigned char req[] = {N6110_FRAME_HEADER, 0x36, 0x64}; 1328 unsigned char req[] = {N6110_FRAME_HEADER, 0x36, 0x64};
1325 1329
1326 s->Phone.Data.SMSStatus=status; 1330 s->Phone.Data.SMSStatus=status;
1327 smprintf(s, "Getting SMS status\n"); 1331 smprintf(s, "Getting SMS status\n");
1328 return GSM_WaitFor (s, req, 5, 0x14, 2, ID_GetSMSStatus); 1332 return GSM_WaitFor (s, req, 5, 0x14, 2, ID_GetSMSStatus);
1329 1333
1330 /* 6210 family doesn't show in frame with SMS status info 1334 /* 6210 family doesn't show in frame with SMS status info
1331 * about Templates. We get separately info about this SMS folder. 1335 * about Templates. We get separately info about this SMS folder.
1332 */ 1336 */
1333} 1337}
1334 1338
1335GSM_Error DCT3_ReplyDeleteSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s) 1339GSM_Error DCT3_ReplyDeleteSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s)
1336{ 1340{
1337 switch(msg.Buffer[3]) { 1341 switch(msg.Buffer[3]) {
1338 case 0x0b: 1342 case 0x0b:
1339 smprintf(s, "SMS deleted\n"); 1343 smprintf(s, "SMS deleted\n");
1340 return ERR_NONE; 1344 return ERR_NONE;
1341 case 0x0c: 1345 case 0x0c:
1342 smprintf(s, "Error deleting SMS\n"); 1346 smprintf(s, "Error deleting SMS\n");
1343 switch (msg.Buffer[4]) { 1347 switch (msg.Buffer[4]) {
1344 case 0x00: 1348 case 0x00:
1345 /* Not tested on 6210 */ 1349 /* Not tested on 6210 */
1346 smprintf(s, "Unknown meaning, SMS seems to be deleted\n"); 1350 smprintf(s, "Unknown meaning, SMS seems to be deleted\n");
1347 return ERR_NONE; 1351 return ERR_NONE;
1348 case 0x02: 1352 case 0x02:
1349 /* Not tested on 6210 */ 1353 /* Not tested on 6210 */
1350 smprintf(s, "Invalid location\n"); 1354 smprintf(s, "Invalid location\n");
1351 return ERR_INVALIDLOCATION; 1355 return ERR_INVALIDLOCATION;
1352 case 0x06: 1356 case 0x06:
1353 /* Not tested on 6210 */ 1357 /* Not tested on 6210 */
1354 smprintf(s, "Phone is OFF\n"); 1358 smprintf(s, "Phone is OFF\n");
1355 return ERR_PHONEOFF; 1359 return ERR_PHONEOFF;
1356 default: 1360 default:
1357 smprintf(s, "Unknown error: %02x\n",msg.Buffer[4]); 1361 smprintf(s, "Unknown error: %02x\n",msg.Buffer[4]);
1358 return ERR_UNKNOWNRESPONSE; 1362 return ERR_UNKNOWNRESPONSE;
1359 } 1363 }
1360 } 1364 }
1361 return ERR_UNKNOWNRESPONSE; 1365 return ERR_UNKNOWNRESPONSE;
1362} 1366}
1363 1367
1364GSM_Error N71_92_ReplyGetSignalQuality(GSM_Protocol_Message msg, GSM_StateMachine *s) 1368GSM_Error N71_92_ReplyGetSignalQuality(GSM_Protocol_Message msg, GSM_StateMachine *s)
1365{ 1369{
1366 GSM_Phone_Data *Data = &s->Phone.Data; 1370 GSM_Phone_Data *Data = &s->Phone.Data;
1367 1371
1368 smprintf(s, "Network level received: %i\n",msg.Buffer[4]); 1372 smprintf(s, "Network level received: %i\n",msg.Buffer[4]);
1369 Data->SignalQuality->SignalStrength = -1; 1373 Data->SignalQuality->SignalStrength = -1;
1370 Data->SignalQuality->SignalPercent = ((int)msg.Buffer[4]); 1374 Data->SignalQuality->SignalPercent = ((int)msg.Buffer[4]);
1371 Data->SignalQuality->BitErrorRate = -1; 1375 Data->SignalQuality->BitErrorRate = -1;
1372 return ERR_NONE; 1376 return ERR_NONE;
1373} 1377}
1374 1378
1375GSM_Error N71_92_GetSignalQuality(GSM_StateMachine *s, GSM_SignalQuality *sig) 1379GSM_Error N71_92_GetSignalQuality(GSM_StateMachine *s, GSM_SignalQuality *sig)
1376{ 1380{
1377 unsigned char req[] = {N6110_FRAME_HEADER, 0x81}; 1381 unsigned char req[] = {N6110_FRAME_HEADER, 0x81};
1378 1382
1379 s->Phone.Data.SignalQuality = sig; 1383 s->Phone.Data.SignalQuality = sig;
1380 smprintf(s, "Getting network level\n"); 1384 smprintf(s, "Getting network level\n");
1381 return GSM_WaitFor (s, req, 4, 0x0a, 4, ID_GetSignalQuality); 1385 return GSM_WaitFor (s, req, 4, 0x0a, 4, ID_GetSignalQuality);
1382} 1386}
1383 1387
1384GSM_Error N71_92_ReplyGetBatteryCharge(GSM_Protocol_Message msg, GSM_StateMachine *s) 1388GSM_Error N71_92_ReplyGetBatteryCharge(GSM_Protocol_Message msg, GSM_StateMachine *s)
1385{ 1389{
1386 GSM_Phone_Data *Data = &s->Phone.Data; 1390 GSM_Phone_Data *Data = &s->Phone.Data;
1387 1391
1388 smprintf(s, "Battery level received: %i\n",msg.Buffer[5]); 1392 smprintf(s, "Battery level received: %i\n",msg.Buffer[5]);
1389 Data->BatteryCharge->BatteryPercent = ((int)msg.Buffer[5]); 1393 Data->BatteryCharge->BatteryPercent = ((int)msg.Buffer[5]);
1390 Data->BatteryCharge->ChargeState = 0; 1394 Data->BatteryCharge->ChargeState = 0;
1391 return ERR_NONE; 1395 return ERR_NONE;
1392} 1396}
1393 1397
1394GSM_Error N71_92_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat) 1398GSM_Error N71_92_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat)
1395{ 1399{
1396 unsigned char req[] = {N6110_FRAME_HEADER, 0x02}; 1400 unsigned char req[] = {N6110_FRAME_HEADER, 0x02};
1397 1401
1398 s->Phone.Data.BatteryCharge = bat; 1402 s->Phone.Data.BatteryCharge = bat;
1399 smprintf(s, "Getting battery level\n"); 1403 smprintf(s, "Getting battery level\n");
1400 return GSM_WaitFor (s, req, 4, 0x17, 4, ID_GetBatteryCharge); 1404 return GSM_WaitFor (s, req, 4, 0x17, 4, ID_GetBatteryCharge);
1401} 1405}
1402 1406
1403GSM_Error N71_92_ReplyPhoneSetting(GSM_Protocol_Message msg, GSM_StateMachine *s) 1407GSM_Error N71_92_ReplyPhoneSetting(GSM_Protocol_Message msg, GSM_StateMachine *s)
1404{ 1408{
1405 GSM_Phone_Bitmap_TypesBmpType; 1409 GSM_Phone_Bitmap_TypesBmpType;
1406 GSM_Phone_Data *Data = &s->Phone.Data; 1410 GSM_Phone_Data *Data = &s->Phone.Data;
1407 1411
diff --git a/gammu/emb/common/phone/nokia/dct3/dct3func.h b/gammu/emb/common/phone/nokia/dct3/dct3func.h
index 66b67ec..18b2026 100644
--- a/gammu/emb/common/phone/nokia/dct3/dct3func.h
+++ b/gammu/emb/common/phone/nokia/dct3/dct3func.h
@@ -1,78 +1,80 @@
1/* (c) 2002-2003 by Marcin Wiacek */ 1/* (c) 2002-2003 by Marcin Wiacek */
2 2
3#ifndef phone_nokia_dct3_h 3#ifndef phone_nokia_dct3_h
4#define phone_nokia_dct3_h 4#define phone_nokia_dct3_h
5 5
6#include "../ncommon.h"
7
6 GSM_Error DCT3_ReplyPressKey (GSM_Protocol_Message msg, GSM_StateMachine *s); 8 GSM_Error DCT3_ReplyPressKey (GSM_Protocol_Message msg, GSM_StateMachine *s);
7 GSM_Error DCT3_ReplyPlayTone (GSM_Protocol_Message msg, GSM_StateMachine *s); 9 GSM_Error DCT3_ReplyPlayTone (GSM_Protocol_Message msg, GSM_StateMachine *s);
8 GSM_Error DCT3_ReplyEnableSecurity(GSM_Protocol_Message msg, GSM_StateMachine *s); 10 GSM_Error DCT3_ReplyEnableSecurity(GSM_Protocol_Message msg, GSM_StateMachine *s);
9 GSM_Error DCT3_ReplyGetIMEI (GSM_Protocol_Message msg, GSM_StateMachine *s); 11 GSM_Error DCT3_ReplyGetIMEI (GSM_Protocol_Message msg, GSM_StateMachine *s);
10 GSM_Error DCT3_ReplyGetSMSC (GSM_Protocol_Message msg, GSM_StateMachine *s); 12 GSM_Error DCT3_ReplyGetSMSC (GSM_Protocol_Message msg, GSM_StateMachine *s);
11 GSM_Error DCT3_ReplySIMLogin (GSM_Protocol_Message msg, GSM_StateMachine *s); 13 GSM_Error DCT3_ReplySIMLogin (GSM_Protocol_Message msg, GSM_StateMachine *s);
12 GSM_Error DCT3_ReplySIMLogout (GSM_Protocol_Message msg, GSM_StateMachine *s); 14 GSM_Error DCT3_ReplySIMLogout (GSM_Protocol_Message msg, GSM_StateMachine *s);
13 GSM_Error DCT3_ReplyGetDateTime (GSM_Protocol_Message msg, GSM_StateMachine *s); 15 GSM_Error DCT3_ReplyGetDateTime (GSM_Protocol_Message msg, GSM_StateMachine *s);
14 GSM_Error DCT3_ReplyGetAlarm (GSM_Protocol_Message msg, GSM_StateMachine *s); 16 GSM_Error DCT3_ReplyGetAlarm (GSM_Protocol_Message msg, GSM_StateMachine *s);
15 GSM_Error DCT3_ReplySetDateTime (GSM_Protocol_Message msg, GSM_StateMachine *s); 17 GSM_Error DCT3_ReplySetDateTime (GSM_Protocol_Message msg, GSM_StateMachine *s);
16 GSM_Error DCT3_ReplySetAlarm (GSM_Protocol_Message msg, GSM_StateMachine *s); 18 GSM_Error DCT3_ReplySetAlarm (GSM_Protocol_Message msg, GSM_StateMachine *s);
17 GSM_Error DCT3_ReplyDialCommand (GSM_Protocol_Message msg, GSM_StateMachine *s); 19 GSM_Error DCT3_ReplyDialCommand (GSM_Protocol_Message msg, GSM_StateMachine *s);
18 GSM_Error DCT3_ReplyGetWAPBookmark(GSM_Protocol_Message msg, GSM_StateMachine *s); 20 GSM_Error DCT3_ReplyGetWAPBookmark(GSM_Protocol_Message msg, GSM_StateMachine *s);
19 GSM_Error DCT3_ReplyGetNetworkInfo(GSM_Protocol_Message msg, GSM_StateMachine *s); 21 GSM_Error DCT3_ReplyGetNetworkInfo(GSM_Protocol_Message msg, GSM_StateMachine *s);
20 GSM_Error DCT3_ReplySendSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s); 22 GSM_Error DCT3_ReplySendSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s);
21 GSM_Error DCT3_ReplySetSMSC (GSM_Protocol_Message msg, GSM_StateMachine *s); 23 GSM_Error DCT3_ReplySetSMSC (GSM_Protocol_Message msg, GSM_StateMachine *s);
22 GSM_Error DCT3_ReplyGetWAPSettings(GSM_Protocol_Message msg, GSM_StateMachine *s); 24 GSM_Error DCT3_ReplyGetWAPSettings(GSM_Protocol_Message msg, GSM_StateMachine *s);
23 GSM_Error DCT3_ReplySetWAPSettings(GSM_Protocol_Message msg, GSM_StateMachine *s); 25 GSM_Error DCT3_ReplySetWAPSettings(GSM_Protocol_Message msg, GSM_StateMachine *s);
24 GSM_Error DCT3_ReplyNetmonitor (GSM_Protocol_Message msg, GSM_StateMachine *s); 26 GSM_Error DCT3_ReplyNetmonitor (GSM_Protocol_Message msg, GSM_StateMachine *s);
25 GSM_Error DCT3_ReplyDeleteSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s); 27 GSM_Error DCT3_ReplyDeleteSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s);
26 GSM_Error N71_92_ReplyGetSignalQuality(GSM_Protocol_Message msg, GSM_StateMachine *s); 28 GSM_Error N71_92_ReplyGetSignalQuality(GSM_Protocol_Message msg, GSM_StateMachine *s);
27 GSM_Error N71_92_ReplyGetBatteryCharge(GSM_Protocol_Message msg, GSM_StateMachine *s); 29 GSM_Error N71_92_ReplyGetBatteryCharge(GSM_Protocol_Message msg, GSM_StateMachine *s);
28 GSM_Error N71_92_ReplyPhoneSetting(GSM_Protocol_Message msg, GSM_StateMachine *s); 30 GSM_Error N71_92_ReplyPhoneSetting(GSM_Protocol_Message msg, GSM_StateMachine *s);
29GSM_Error N61_71_ReplyResetPhoneSettings(GSM_Protocol_Message msg, GSM_StateMachine *s); 31GSM_Error N61_71_ReplyResetPhoneSettings(GSM_Protocol_Message msg, GSM_StateMachine *s);
30 GSM_Error N61_91_ReplySetOpLogo (GSM_Protocol_Message msg, GSM_StateMachine *s); 32 GSM_Error N61_91_ReplySetOpLogo (GSM_Protocol_Message msg, GSM_StateMachine *s);
31#ifdef GSM_ENABLE_CELLBROADCAST 33#ifdef GSM_ENABLE_CELLBROADCAST
32 GSM_Error DCT3_ReplySetIncomingCB(GSM_Protocol_Message msg, GSM_StateMachine *s); 34 GSM_Error DCT3_ReplySetIncomingCB(GSM_Protocol_Message msg, GSM_StateMachine *s);
33 GSM_Error DCT3_ReplyIncomingCB (GSM_Protocol_Message msg, GSM_StateMachine *s); 35 GSM_Error DCT3_ReplyIncomingCB (GSM_Protocol_Message msg, GSM_StateMachine *s);
34#endif 36#endif
35 37
36 GSM_Error DCT3_DeleteWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark); 38 GSM_Error DCT3_DeleteWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark);
37 GSM_Error DCT3_GetWAPBookmark (GSM_StateMachine *s, GSM_WAPBookmark *bookmark); 39 GSM_Error DCT3_GetWAPBookmark (GSM_StateMachine *s, GSM_WAPBookmark *bookmark);
38 GSM_Error DCT3_PressKey (GSM_StateMachine *s, GSM_KeyCode Key, bool Press); 40 GSM_Error DCT3_PressKey (GSM_StateMachine *s, GSM_KeyCode Key, bool Press);
39 GSM_Error DCT3_PlayTone (GSM_StateMachine *s, int Herz, unsigned char Volume, bool start); 41 GSM_Error DCT3_PlayTone (GSM_StateMachine *s, int Herz, unsigned char Volume, bool start);
40 GSM_Error DCT3_EnableSecurity (GSM_StateMachine *s, unsigned char status); 42 GSM_Error DCT3_EnableSecurity (GSM_StateMachine *s, unsigned char status);
41 GSM_Error DCT3_GetIMEI (GSM_StateMachine *s); 43 GSM_Error DCT3_GetIMEI (GSM_StateMachine *s);
42 GSM_Error DCT3_GetSMSC (GSM_StateMachine *s, GSM_SMSC *smsc ); 44 GSM_Error DCT3_GetSMSC (GSM_StateMachine *s, GSM_SMSC *smsc );
43 GSM_Error DCT3_GetNetworkInfo (GSM_StateMachine *s, GSM_NetworkInfo *netinfo); 45 GSM_Error DCT3_GetNetworkInfo (GSM_StateMachine *s, GSM_NetworkInfo *netinfo);
44 GSM_Error DCT3_DialVoice (GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber); 46 GSM_Error DCT3_DialVoice (GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber);
45 GSM_Error DCT3_Reset (GSM_StateMachine *s, bool hard ); 47 GSM_Error DCT3_Reset (GSM_StateMachine *s, bool hard );
46 GSM_Error DCT3_CancelCall (GSM_StateMachine *s, int ID, bool all); 48 GSM_Error DCT3_CancelCall (GSM_StateMachine *s, int ID, bool all);
47 GSM_Error DCT3_AnswerAllCalls (GSM_StateMachine *s); 49 GSM_Error DCT3_AnswerAllCalls (GSM_StateMachine *s);
48 GSM_Error DCT3_SendSMSMessage (GSM_StateMachine *s, GSM_SMSMessage *sms ); 50 GSM_Error DCT3_SendSMSMessage (GSM_StateMachine *s, GSM_SMSMessage *sms );
49 GSM_Error DCT3_GetAlarm (GSM_StateMachine *s, GSM_Alarm *alarm,unsigned char msgtype); 51 GSM_Error DCT3_GetAlarm (GSM_StateMachine *s, GSM_Alarm *alarm,unsigned char msgtype);
50 GSM_Error DCT3_GetDateTime (GSM_StateMachine *s, GSM_DateTime *date_time, unsigned char msgtype); 52 GSM_Error DCT3_GetDateTime (GSM_StateMachine *s, GSM_DateTime *date_time, unsigned char msgtype);
51 GSM_Error DCT3_SetAlarm (GSM_StateMachine *s, GSM_Alarm *alarm, unsigned char msgtype); 53 GSM_Error DCT3_SetAlarm (GSM_StateMachine *s, GSM_Alarm *alarm, unsigned char msgtype);
52 GSM_Error DCT3_SetDateTime (GSM_StateMachine *s, GSM_DateTime *date_time, unsigned char msgtype); 54 GSM_Error DCT3_SetDateTime (GSM_StateMachine *s, GSM_DateTime *date_time, unsigned char msgtype);
53 GSM_Error DCT3_SetIncomingCB (GSM_StateMachine *s, bool enable); 55 GSM_Error DCT3_SetIncomingCB (GSM_StateMachine *s, bool enable);
54 GSM_Error DCT3_GetSMSStatus (GSM_StateMachine *s, GSM_SMSMemoryStatus *status); 56 GSM_Error DCT3_GetSMSStatus (GSM_StateMachine *s, GSM_SMSMemoryStatus *status);
55 GSM_Error DCT3_SetSMSC (GSM_StateMachine *s, GSM_SMSC *smsc ); 57 GSM_Error DCT3_SetSMSC (GSM_StateMachine *s, GSM_SMSC *smsc );
56 GSM_Error DCT3_GetWAPSettings (GSM_StateMachine *s, GSM_MultiWAPSettings *settings); 58 GSM_Error DCT3_GetWAPSettings (GSM_StateMachine *s, GSM_MultiWAPSettings *settings);
57 GSM_Error DCT3_SetWAPSettings (GSM_StateMachine *s, GSM_MultiWAPSettings *settings); 59 GSM_Error DCT3_SetWAPSettings (GSM_StateMachine *s, GSM_MultiWAPSettings *settings);
58 GSM_Error DCT3_SetWAPBookmark (GSM_StateMachine *s, GSM_WAPBookmark *bookmark); 60 GSM_Error DCT3_SetWAPBookmark (GSM_StateMachine *s, GSM_WAPBookmark *bookmark);
59 GSM_Error DCT3_Netmonitor (GSM_StateMachine *s, int testnumber, char *value); 61 GSM_Error DCT3_Netmonitor (GSM_StateMachine *s, int testnumber, char *value);
60 GSM_Error DCT3_GetManufactureMonth (GSM_StateMachine *s, char *value); 62 GSM_Error DCT3_GetManufactureMonth (GSM_StateMachine *s, char *value);
61 GSM_Error DCT3_GetProductCode (GSM_StateMachine *s, char *value); 63 GSM_Error DCT3_GetProductCode (GSM_StateMachine *s, char *value);
62 GSM_Error DCT3_GetOriginalIMEI (GSM_StateMachine *s, char *value); 64 GSM_Error DCT3_GetOriginalIMEI (GSM_StateMachine *s, char *value);
63 GSM_Error DCT3_GetHardware (GSM_StateMachine *s, char *value); 65 GSM_Error DCT3_GetHardware (GSM_StateMachine *s, char *value);
64 GSM_Error DCT3_GetPPM (GSM_StateMachine *s, char *value); 66 GSM_Error DCT3_GetPPM (GSM_StateMachine *s, char *value);
65 GSM_Error N61_71_ResetPhoneSettings(GSM_StateMachine *s, GSM_ResetSettingsType Type); 67 GSM_Error N61_71_ResetPhoneSettings(GSM_StateMachine *s, GSM_ResetSettingsType Type);
66 GSM_Error N71_92_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat); 68 GSM_Error N71_92_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat);
67 GSM_Error N71_92_GetSignalQuality(GSM_StateMachine *s, GSM_SignalQuality *sig); 69 GSM_Error N71_92_GetSignalQuality(GSM_StateMachine *s, GSM_SignalQuality *sig);
68 GSM_Error N71_92_GetPhoneSetting(GSM_StateMachine *s, int Request, int Setting); 70 GSM_Error N71_92_GetPhoneSetting(GSM_StateMachine *s, int Request, int Setting);
69 GSM_Error N71_92_GetDateTime (GSM_StateMachine *s, GSM_DateTime *date_time); 71 GSM_Error N71_92_GetDateTime (GSM_StateMachine *s, GSM_DateTime *date_time);
70 GSM_Error N71_92_SetDateTime (GSM_StateMachine *s, GSM_DateTime *date_time); 72 GSM_Error N71_92_SetDateTime (GSM_StateMachine *s, GSM_DateTime *date_time);
71 73
72 GSM_Error DCT3_DecodeSMSFrame (GSM_StateMachine *s, GSM_SMSMessage *SMS, unsigned char *buffer); 74 GSM_Error DCT3_DecodeSMSFrame (GSM_StateMachine *s, GSM_SMSMessage *SMS, unsigned char *buffer);
73 75
74#endif 76#endif
75 77
76/* How should editor hadle tabs in this file? Add editor commands here. 78/* How should editor hadle tabs in this file? Add editor commands here.
77 * vim: noexpandtab sw=8 ts=8 sts=8: 79 * vim: noexpandtab sw=8 ts=8 sts=8:
78 */ 80 */
diff --git a/gammu/emb/common/phone/nokia/dct3/n6110.c b/gammu/emb/common/phone/nokia/dct3/n6110.c
index 263d12b..dac6c12 100644
--- a/gammu/emb/common/phone/nokia/dct3/n6110.c
+++ b/gammu/emb/common/phone/nokia/dct3/n6110.c
@@ -1,321 +1,324 @@
1/* (c) 2001-2004 by Marcin Wiacek */ 1/* (c) 2001-2004 by Marcin Wiacek */
2/* based on some work from Markus Plail and Gnokii */
3/* Authentication function (c) 1999 or earlier by Pavel Janik */
4/* 5210 calendar IDs by Frederick Ros */ 2/* 5210 calendar IDs by Frederick Ros */
3/* based on some Markus Plail, Pavel Janik & others work from Gnokii (www.gnokii.org)
4 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
5 * GNU GPL version 2 or later
6 */
5 7
6#include "../../../gsmstate.h" 8#include "../../../gsmstate.h"
7 9
8#ifdef GSM_ENABLE_NOKIA6110 10#ifdef GSM_ENABLE_NOKIA6110
9 11
10#include <string.h> 12#include <string.h>
11 13
12#include "../../../../cfg/config.h" 14#include "../../../../cfg/config.h"
13#include "../../../misc/coding/coding.h" 15#include "../../../misc/coding/coding.h"
14#include "../../../service/sms/gsmsms.h" 16#include "../../../service/sms/gsmsms.h"
15#include "../../../gsmcomon.h" 17#include "../../../gsmcomon.h"
16#include "../../pfunc.h" 18#include "../../pfunc.h"
17#include "../nfunc.h" 19#include "../nfunc.h"
18#include "n6110.h" 20#include "n6110.h"
19#include "dct3func.h" 21#include "dct3func.h"
20 22
21static unsigned char N6110_MEMORY_TYPES[] = { 23static unsigned char N6110_MEMORY_TYPES[] = {
22 MEM_ME, 0x02, 24 MEM_ME, 0x02,
23 MEM_SM, 0x03, 25 MEM_SM, 0x03,
24 MEM_ON, 0x05, 26 MEM_ON, 0x05,
25 MEM_DC, 0x07, 27 MEM_DC, 0x07,
26 MEM_RC, 0x08, 28 MEM_RC, 0x08,
27 MEM_MC, 0x09, 29 MEM_MC, 0x09,
28 MEM_VM, 0x0b, 30 MEM_VM, 0x0b,
29 0x00, 0x00 31 0x00, 0x00
30}; 32};
31 33
32static GSM_Error N6110_ReplyGetPhoneLanguage(GSM_Protocol_Message msg, GSM_StateMachine *s) 34static GSM_Error N6110_ReplyGetPhoneLanguage(GSM_Protocol_Message msg, GSM_StateMachine *s)
33{ 35{
34 N6110_Language lang = N6110_Auto; 36 N6110_Language lang = N6110_Auto;
35 37
36 if (msg.Buffer[3] == 0x15) return ERR_NONE; 38 if (msg.Buffer[3] == 0x15) return ERR_NONE;
37 39
38 smprintf(s, "Phone language is %02x\n",msg.Buffer[6]); 40 smprintf(s, "Phone language is %02x\n",msg.Buffer[6]);
39 switch (msg.Buffer[6]) { 41 switch (msg.Buffer[6]) {
40 case 0x21: lang = N6110_Europe; break; //Polish 42 case 0x21: lang = N6110_Europe; break; //Polish
41 } 43 }
42 s->Phone.Data.Priv.N6110.PhoneLanguage = lang; 44 s->Phone.Data.Priv.N6110.PhoneLanguage = lang;
43 return ERR_NONE; 45 return ERR_NONE;
44} 46}
45 47
46static GSM_Error N6110_GetPhoneLanguage(GSM_StateMachine *s) 48static GSM_Error N6110_GetPhoneLanguage(GSM_StateMachine *s)
47{ 49{
48 unsigned char feat_req[] = {N6110_FRAME_HEADER, 0x13, 0x01, 50 unsigned char feat_req[] = {N6110_FRAME_HEADER, 0x13, 0x01,
49 0x00, /* Profile location */ 51 0x00, /* Profile location */
50 0x00}; /* Feature number */ 52 0x00}; /* Feature number */
51 53
52 s->Phone.Data.Priv.N6110.PhoneLanguage = N6110_Auto; 54 s->Phone.Data.Priv.N6110.PhoneLanguage = N6110_Auto;
53 55
54 feat_req[5] = 0; 56 feat_req[5] = 0;
55 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PROFILES33)) { 57 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PROFILES33)) {
56 feat_req[6] = 0x1E; 58 feat_req[6] = 0x1E;
57 } else { 59 } else {
58 feat_req[6] = 0x21; 60 feat_req[6] = 0x21;
59 } 61 }
60 smprintf(s, "Getting profile feature\n"); 62 smprintf(s, "Getting profile feature\n");
61 return GSM_WaitFor (s, feat_req, 7, 0x05, 4, ID_GetLanguage); 63 return GSM_WaitFor (s, feat_req, 7, 0x05, 4, ID_GetLanguage);
62} 64}
63 65
64struct N6110_Lang_Char { 66struct N6110_Lang_Char {
65 N6110_Language Lang; 67 N6110_Language Lang;
66 unsigned char Phone; 68 unsigned char Phone;
67 unsigned char Unicode1; 69 unsigned char Unicode1;
68 unsigned char Unicode2; 70 unsigned char Unicode2;
69}; 71};
70 72
71static struct N6110_Lang_Char N6110_Lang_Table[] = { 73static struct N6110_Lang_Char N6110_Lang_Table[] = {
72{N6110_Europe,0x13,0x01,0x04},//Latin capital letter a with ogonek 74{N6110_Europe,0x13,0x01,0x04},//Latin capital letter a with ogonek
73{N6110_Europe,0x14,0x01,0x05},//Latin small letter a with ogonek 75{N6110_Europe,0x14,0x01,0x05},//Latin small letter a with ogonek
74{N6110_Europe,0x15,0x01,0x06},//Latin capital letter c with acute 76{N6110_Europe,0x15,0x01,0x06},//Latin capital letter c with acute
75{N6110_Europe,0x17,0x01,0x07},//Latin small letter c with acute 77{N6110_Europe,0x17,0x01,0x07},//Latin small letter c with acute
76{N6110_Europe,0x1D,0x01,0x18},//Latin capital letter e with ogonek 78{N6110_Europe,0x1D,0x01,0x18},//Latin capital letter e with ogonek
77{N6110_Europe,0x1E,0x01,0x19},//Latin small letter e with ogonek 79{N6110_Europe,0x1E,0x01,0x19},//Latin small letter e with ogonek
78{N6110_Europe,0x83,0x00,0xD3},//Latin capital letter o with acute 80{N6110_Europe,0x83,0x00,0xD3},//Latin capital letter o with acute
79{N6110_Europe,0x8E,0x01,0x41},//Latin capital letter l with stroke 81{N6110_Europe,0x8E,0x01,0x41},//Latin capital letter l with stroke
80{N6110_Europe,0x90,0x01,0x42},//Latin small letter l with stroke 82{N6110_Europe,0x90,0x01,0x42},//Latin small letter l with stroke
81{N6110_Europe,0x92,0x01,0x43},//Latin capital letter n with acute 83{N6110_Europe,0x92,0x01,0x43},//Latin capital letter n with acute
82{N6110_Europe,0x93,0x01,0x44},//Latin small letter n with acute 84{N6110_Europe,0x93,0x01,0x44},//Latin small letter n with acute
83{N6110_Europe,0x9A,0x00,0xF3},//Latin small letter o with acute 85{N6110_Europe,0x9A,0x00,0xF3},//Latin small letter o with acute
84{N6110_Europe,0xB2,0x20,0xAC},//euro 86{N6110_Europe,0xB2,0x20,0xAC},//euro
85{N6110_Europe,0xB5,0x01,0x5A},//Latin capital letter s with acute 87{N6110_Europe,0xB5,0x01,0x5A},//Latin capital letter s with acute
86{N6110_Europe,0xB6,0x01,0x5B},//Latin small letter s with acute 88{N6110_Europe,0xB6,0x01,0x5B},//Latin small letter s with acute
87{N6110_Europe,0xE7,0x01,0x79},//Latin capital letter z with acute 89{N6110_Europe,0xE7,0x01,0x79},//Latin capital letter z with acute
88{N6110_Europe,0xEE,0x01,0x7A},//Latin small letter z with acute 90{N6110_Europe,0xEE,0x01,0x7A},//Latin small letter z with acute
89{N6110_Europe,0xF4,0x01,0x7C},//Latin small letter z with dot above 91{N6110_Europe,0xF4,0x01,0x7C},//Latin small letter z with dot above
90{N6110_Europe,0xF0,0x01,0x7B},//Latin capital letter z with dot above 92{N6110_Europe,0xF0,0x01,0x7B},//Latin capital letter z with dot above
91{0,0,0,0} 93{0,0,0,0}
92}; 94};
93 95
94static void N6110_EncodeUnicode(GSM_StateMachine *s, unsigned char *dest, const unsigned char *src, int len) 96static void N6110_EncodeUnicode(GSM_StateMachine *s, unsigned char *dest, const unsigned char *src, int len)
95{ 97{
96 int i_len = 0, o_len, i; 98 int i_len = 0, o_len, i;
97 wchar_t wc; 99 wchar_t wc;
98 GSM_Phone_N6110Data *Priv = &s->Phone.Data.Priv.N6110; 100 GSM_Phone_N6110Data *Priv = &s->Phone.Data.Priv.N6110;
99 bool found; 101 bool found;
100 102
101 for (o_len = 0; i_len < len; o_len++) { 103 for (o_len = 0; i_len < len; o_len++) {
102 found = false; 104 found = false;
103 if (Priv->PhoneLanguage != N6110_Auto) { 105 if (Priv->PhoneLanguage != N6110_Auto) {
104 i = 0; 106 i = 0;
105 while(1) { 107 while(1) {
106 if (N6110_Lang_Table[i].Lang == 0) break; 108 if (N6110_Lang_Table[i].Lang == 0) break;
107 if (N6110_Lang_Table[i].Lang == Priv->PhoneLanguage && 109 if (N6110_Lang_Table[i].Lang == Priv->PhoneLanguage &&
108 N6110_Lang_Table[i].Phone == src[i_len]) { 110 N6110_Lang_Table[i].Phone == src[i_len]) {
109 dest[o_len*2] = N6110_Lang_Table[i].Unicode1; 111 dest[o_len*2] = N6110_Lang_Table[i].Unicode1;
110 dest[(o_len*2)+1] = N6110_Lang_Table[i].Unicode2; 112 dest[(o_len*2)+1] = N6110_Lang_Table[i].Unicode2;
111 i_len++; 113 i_len++;
112 found = true; 114 found = true;
113 break; 115 break;
114 } 116 }
115 i++; 117 i++;
116 } 118 }
117 } 119 }
118 if (!found) { 120 if (!found) {
119 i_len += EncodeWithUnicodeAlphabet(&src[i_len], &wc); 121 i_len += EncodeWithUnicodeAlphabet(&src[i_len], &wc);
120 dest[o_len*2] = (wc >> 8) & 0xff; 122 dest[o_len*2] = (wc >> 8) & 0xff;
121 dest[(o_len*2)+1] = wc & 0xff; 123 dest[(o_len*2)+1] = wc & 0xff;
122 } 124 }
123 } 125 }
124 dest[o_len*2] = 0; 126 dest[o_len*2] = 0;
125 dest[(o_len*2)+1] = 0; 127 dest[(o_len*2)+1] = 0;
126} 128}
127 129
128#ifndef ENABLE_LGPL 130#ifndef ENABLE_LGPL
129 131
132/* Pavel Janik */
130/* This function provides Nokia authentication protocol. 133/* This function provides Nokia authentication protocol.
131 * Nokia authentication protocol is used in the communication between Nokia 134 * Nokia authentication protocol is used in the communication between Nokia
132 * mobile phones (e.g. Nokia 6110) and Nokia Cellular Data Suite software, 135 * mobile phones (e.g. Nokia 6110) and Nokia Cellular Data Suite software,
133 * commercially sold by Nokia Corp. 136 * commercially sold by Nokia Corp.
134 * The authentication scheme is based on the token send by the phone to the 137 * The authentication scheme is based on the token send by the phone to the
135 * software. The software does it's magic (see the function 138 * software. The software does it's magic (see the function
136 * N6110_GetNokiaAuthentication) and returns the result back to the phone. 139 * N6110_GetNokiaAuthentication) and returns the result back to the phone.
137 * If the result is correct the phone responds with the message "Accessory 140 * If the result is correct the phone responds with the message "Accessory
138 * connected!" displayed on the LCD. Otherwise it will display "Accessory not 141 * connected!" displayed on the LCD. Otherwise it will display "Accessory not
139 * supported" and some functions will not be available for use (?). 142 * supported" and some functions will not be available for use (?).
140 * The specification of the protocol is not publicly available, no comment. 143 * The specification of the protocol is not publicly available, no comment.
141 */ 144 */
142static void N6110_GetNokiaAuthentication(unsigned char *Imei, unsigned char *MagicBytes, unsigned char *MagicResponse) 145static void N6110_GetNokiaAuthentication(unsigned char *Imei, unsigned char *MagicBytes, unsigned char *MagicResponse)
143{ 146{
144 int i, j, CRC=0; 147 int i, j, CRC=0;
145 unsigned char Temp[16]; /* This is our temporary working area. */ 148 unsigned char Temp[16]; /* This is our temporary working area. */
146 149
147 /* Here we put FAC (Final Assembly Code) and serial number into our area. */ 150 /* Here we put FAC (Final Assembly Code) and serial number into our area. */
148 Temp[0] = Imei[6]; Temp[1] = Imei[7]; 151 Temp[0] = Imei[6]; Temp[1] = Imei[7];
149 Temp[2] = Imei[8]; Temp[3] = Imei[9]; 152 Temp[2] = Imei[8]; Temp[3] = Imei[9];
150 Temp[4] = Imei[10]; Temp[5] = Imei[11]; 153 Temp[4] = Imei[10]; Temp[5] = Imei[11];
151 Temp[6] = Imei[12]; Temp[7] = Imei[13]; 154 Temp[6] = Imei[12]; Temp[7] = Imei[13];
152 155
153 /* And now the TAC (Type Approval Code). */ 156 /* And now the TAC (Type Approval Code). */
154 Temp[8] = Imei[2]; Temp[9] = Imei[3]; 157 Temp[8] = Imei[2]; Temp[9] = Imei[3];
155 Temp[10] = Imei[4]; Temp[11] = Imei[5]; 158 Temp[10] = Imei[4]; Temp[11] = Imei[5];
156 159
157 /* And now we pack magic bytes from the phone. */ 160 /* And now we pack magic bytes from the phone. */
158 Temp[12] = MagicBytes[0]; Temp[13] = MagicBytes[1]; 161 Temp[12] = MagicBytes[0]; Temp[13] = MagicBytes[1];
159 Temp[14] = MagicBytes[2]; Temp[15] = MagicBytes[3]; 162 Temp[14] = MagicBytes[2]; Temp[15] = MagicBytes[3];
160 163
161 for (i=0; i<=11; i++) if (Temp[i + 1]& 1) Temp[i]<<=1; 164 for (i=0; i<=11; i++) if (Temp[i + 1]& 1) Temp[i]<<=1;
162 switch (Temp[15] & 0x03) { 165 switch (Temp[15] & 0x03) {
163 case 1: 166 case 1:
164 case 2: j = Temp[13] & 0x07; 167 case 2: j = Temp[13] & 0x07;
165 for (i=0; i<=3; i++) Temp[i+j] ^= Temp[i+12]; 168 for (i=0; i<=3; i++) Temp[i+j] ^= Temp[i+12];
166 break; 169 break;
167 default: j = Temp[14] & 0x07; 170 default: j = Temp[14] & 0x07;
168 for (i=0; i<=3; i++) Temp[i + j] |= Temp[i + 12]; 171 for (i=0; i<=3; i++) Temp[i + j] |= Temp[i + 12];
169 } 172 }
170 for (i=0; i<=15; i++) CRC ^= Temp[i]; 173 for (i=0; i<=15; i++) CRC ^= Temp[i];
171 for (i=0; i<=15; i++) { 174 for (i=0; i<=15; i++) {
172 switch (Temp[15 - i] & 0x06) { 175 switch (Temp[15 - i] & 0x06) {
173 case 0: j = Temp[i] | CRC; break; 176 case 0: j = Temp[i] | CRC; break;
174 case 2: 177 case 2:
175 case 4: j = Temp[i] ^ CRC; break; 178 case 4: j = Temp[i] ^ CRC; break;
176 case 6: j = Temp[i] & CRC; break; 179 case 6: j = Temp[i] & CRC; break;
177 } 180 }
178 if (j == CRC) j = 0x2c; 181 if (j == CRC) j = 0x2c;
179 if (Temp[i] == 0) j = 0; 182 if (Temp[i] == 0) j = 0;
180 MagicResponse[i] = j; 183 MagicResponse[i] = j;
181 } 184 }
182} 185}
183 186
184static GSM_Error N6110_ReplyGetMagicBytes(GSM_Protocol_Message msg, GSM_StateMachine *s) 187static GSM_Error N6110_ReplyGetMagicBytes(GSM_Protocol_Message msg, GSM_StateMachine *s)
185{ 188{
186 GSM_Phone_N6110Data *Priv = &s->Phone.Data.Priv.N6110; 189 GSM_Phone_N6110Data *Priv = &s->Phone.Data.Priv.N6110;
187 GSM_Phone_Data *Data = &s->Phone.Data; 190 GSM_Phone_Data *Data = &s->Phone.Data;
188 191
189 sprintf(Data->IMEI, "%s", msg.Buffer+9); 192 sprintf(Data->IMEI, "%s", msg.Buffer+9);
190 sprintf(Data->HardwareCache, "%s", msg.Buffer+39); 193 sprintf(Data->HardwareCache, "%s", msg.Buffer+39);
191 sprintf(Data->ProductCodeCache, "%s", msg.Buffer+31); 194 sprintf(Data->ProductCodeCache, "%s", msg.Buffer+31);
192 195
193 smprintf(s, "Message: Mobile phone identification received:\n"); 196 smprintf(s, "Message: Mobile phone identification received:\n");
194 smprintf(s, "IMEI : %s\n", msg.Buffer+9); 197 smprintf(s, "IMEI : %s\n", msg.Buffer+9);
195 smprintf(s, "Model : %s\n", msg.Buffer+25); 198 smprintf(s, "Model : %s\n", msg.Buffer+25);
196 smprintf(s, "Production Code : %s\n", msg.Buffer+31); 199 smprintf(s, "Production Code : %s\n", msg.Buffer+31);
197 smprintf(s, "HW : %s\n", msg.Buffer+39); 200 smprintf(s, "HW : %s\n", msg.Buffer+39);
198 smprintf(s, "Firmware : %s\n", msg.Buffer+44); 201 smprintf(s, "Firmware : %s\n", msg.Buffer+44);
199 202
200 /* These bytes are probably the source of the "Accessory not connected" 203 /* These bytes are probably the source of the "Accessory not connected"
201 * messages on the phone when trying to emulate NCDS... I hope.... 204 * messages on the phone when trying to emulate NCDS... I hope....
202 * UPDATE: of course, now we have the authentication algorithm. 205 * UPDATE: of course, now we have the authentication algorithm.
203 */ 206 */
204 smprintf(s, " Magic bytes : %02x %02x %02x %02x\n", msg.Buffer[50], msg.Buffer[51], msg.Buffer[52], msg.Buffer[53]); 207 smprintf(s, " Magic bytes : %02x %02x %02x %02x\n", msg.Buffer[50], msg.Buffer[51], msg.Buffer[52], msg.Buffer[53]);
205 208
206 Priv->MagicBytes[0]=msg.Buffer[50]; 209 Priv->MagicBytes[0]=msg.Buffer[50];
207 Priv->MagicBytes[1]=msg.Buffer[51]; 210 Priv->MagicBytes[1]=msg.Buffer[51];
208 Priv->MagicBytes[2]=msg.Buffer[52]; 211 Priv->MagicBytes[2]=msg.Buffer[52];
209 Priv->MagicBytes[3]=msg.Buffer[53]; 212 Priv->MagicBytes[3]=msg.Buffer[53];
210 213
211 return ERR_NONE; 214 return ERR_NONE;
212} 215}
213 216
214static GSM_Error N6110_MakeAuthentication(GSM_StateMachine *s) 217static GSM_Error N6110_MakeAuthentication(GSM_StateMachine *s)
215{ 218{
216 GSM_Phone_N6110Data *Priv = &s->Phone.Data.Priv.N6110; 219 GSM_Phone_N6110Data *Priv = &s->Phone.Data.Priv.N6110;
217 GSM_Error error; 220 GSM_Error error;
218 unsigned char connect4[] = {N6110_FRAME_HEADER, 0x10}; 221 unsigned char connect4[] = {N6110_FRAME_HEADER, 0x10};
219 unsigned char magic_connect[] = { 222 unsigned char magic_connect[] = {
220 N6110_FRAME_HEADER, 0x12, 223 N6110_FRAME_HEADER, 0x12,
221 /* The real magic goes here ... These bytes are filled in 224 /* The real magic goes here ... These bytes are filled in
222 * with the function N6110_GetNokiaAuthentication. */ 225 * with the function N6110_GetNokiaAuthentication. */
223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
225 /* NOKIA&GNOKII Accessory */ 228 /* NOKIA&GNOKII Accessory */
226 'N', 'O', 'K', 'I', 'A', '&', 'N', 'O', 'K', 'I', 'A', 229 'N', 'O', 'K', 'I', 'A', '&', 'N', 'O', 'K', 'I', 'A',
227 'a', 'c', 'c', 'e', 's', 's', 'o', 'r', 'y', 230 'a', 'c', 'c', 'e', 's', 's', 'o', 'r', 'y',
228 0x00, 0x00, 0x00, 0x00}; 231 0x00, 0x00, 0x00, 0x00};
229 232
230 smprintf(s, "Getting magic bytes for authentication\n"); 233 smprintf(s, "Getting magic bytes for authentication\n");
231 error=GSM_WaitFor (s, connect4, 4, 0x64, 4, ID_MakeAuthentication); 234 error=GSM_WaitFor (s, connect4, 4, 0x64, 4, ID_MakeAuthentication);
232 if (error!=ERR_NONE) return error; 235 if (error!=ERR_NONE) return error;
233 236
234 N6110_GetNokiaAuthentication(s->Phone.Data.IMEI, Priv->MagicBytes, magic_connect+4); 237 N6110_GetNokiaAuthentication(s->Phone.Data.IMEI, Priv->MagicBytes, magic_connect+4);
235 smprintf(s, "Sending authentication bytes\n"); 238 smprintf(s, "Sending authentication bytes\n");
236 return s->Protocol.Functions->WriteMessage(s, magic_connect, 45, 0x64); 239 return s->Protocol.Functions->WriteMessage(s, magic_connect, 45, 0x64);
237} 240}
238 241
239#endif 242#endif
240 243
241static GSM_Error N6110_ShowStartInfo(GSM_StateMachine *s, bool enable) 244static GSM_Error N6110_ShowStartInfo(GSM_StateMachine *s, bool enable)
242{ 245{
243#ifdef ENABLE_LGPL 246#ifdef ENABLE_LGPL
244 return ERR_NONE; 247 return ERR_NONE;
245#else 248#else
246 GSM_Error error=ERR_NONE; 249 GSM_Error error=ERR_NONE;
247 250
248 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_MAGICBYTES)) { 251 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_MAGICBYTES)) {
249 if (s->ConnectionType == GCT_FBUS2 || 252 if (s->ConnectionType == GCT_FBUS2 ||
250 s->ConnectionType == GCT_FBUS2IRDA) { 253 s->ConnectionType == GCT_FBUS2IRDA) {
251 error=N6110_MakeAuthentication(s); 254 error=N6110_MakeAuthentication(s);
252 } 255 }
253 } 256 }
254 return error; 257 return error;
255#endif 258#endif
256} 259}
257 260
258static GSM_Error N6110_Initialise (GSM_StateMachine *s) 261static GSM_Error N6110_Initialise (GSM_StateMachine *s)
259{ 262{
260#ifdef DEBUG 263#ifdef DEBUG
261 DCT3_SetIncomingCB(s,true); 264 DCT3_SetIncomingCB(s,true);
262#endif 265#endif
263 N6110_GetPhoneLanguage(s); 266 N6110_GetPhoneLanguage(s);
264 return ERR_NONE; 267 return ERR_NONE;
265} 268}
266 269
267static GSM_Error N6110_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time) 270static GSM_Error N6110_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
268{ 271{
269 return DCT3_GetDateTime(s, date_time, 0x11); 272 return DCT3_GetDateTime(s, date_time, 0x11);
270} 273}
271 274
272static GSM_Error N6110_GetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm) 275static GSM_Error N6110_GetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm)
273{ 276{
274 return DCT3_GetAlarm(s, alarm, 0x11); 277 return DCT3_GetAlarm(s, alarm, 0x11);
275} 278}
276 279
277static GSM_Error N6110_SetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time) 280static GSM_Error N6110_SetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
278{ 281{
279 return DCT3_SetDateTime(s, date_time, 0x11); 282 return DCT3_SetDateTime(s, date_time, 0x11);
280} 283}
281 284
282static GSM_Error N6110_SetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm) 285static GSM_Error N6110_SetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm)
283{ 286{
284 return DCT3_SetAlarm(s, alarm, 0x11); 287 return DCT3_SetAlarm(s, alarm, 0x11);
285} 288}
286 289
287static GSM_Error N6110_ReplyGetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s) 290static GSM_Error N6110_ReplyGetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s)
288{ 291{
289 int count; 292 int count;
290 GSM_Phone_Data *Data = &s->Phone.Data; 293 GSM_Phone_Data *Data = &s->Phone.Data;
291 294
292 smprintf(s, "Phonebook entry received\n"); 295 smprintf(s, "Phonebook entry received\n");
293 switch (msg.Buffer[3]) { 296 switch (msg.Buffer[3]) {
294 case 0x02: 297 case 0x02:
295 Data->Memory->EntriesNum = 0; 298 Data->Memory->EntriesNum = 0;
296 count=5; 299 count=5;
297 /* If name is not empty */ 300 /* If name is not empty */
298 if (msg.Buffer[count]!=0x00) { 301 if (msg.Buffer[count]!=0x00) {
299 if (msg.Buffer[count]>GSM_PHONEBOOK_TEXT_LENGTH) { 302 if (msg.Buffer[count]>GSM_PHONEBOOK_TEXT_LENGTH) {
300 smprintf(s, "Too long text\n"); 303 smprintf(s, "Too long text\n");
301 return ERR_UNKNOWNRESPONSE; 304 return ERR_UNKNOWNRESPONSE;
302 } 305 }
303 Data->Memory->Entries[Data->Memory->EntriesNum].EntryType=PBK_Text_Name; 306 Data->Memory->Entries[Data->Memory->EntriesNum].EntryType=PBK_Text_Name;
304 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOPBKUNICODE)) { 307 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOPBKUNICODE)) {
305 if (Data->Memory->MemoryType==MEM_DC || 308 if (Data->Memory->MemoryType==MEM_DC ||
306 Data->Memory->MemoryType==MEM_RC || 309 Data->Memory->MemoryType==MEM_RC ||
307 Data->Memory->MemoryType==MEM_MC || 310 Data->Memory->MemoryType==MEM_MC ||
308 Data->Memory->MemoryType==MEM_ME) { 311 Data->Memory->MemoryType==MEM_ME) {
309 N6110_EncodeUnicode(s,Data->Memory->Entries[Data->Memory->EntriesNum].Text, 312 N6110_EncodeUnicode(s,Data->Memory->Entries[Data->Memory->EntriesNum].Text,
310 msg.Buffer+count+1,msg.Buffer[count]); 313 msg.Buffer+count+1,msg.Buffer[count]);
311 } else { 314 } else {
312 EncodeUnicode(Data->Memory->Entries[Data->Memory->EntriesNum].Text, 315 EncodeUnicode(Data->Memory->Entries[Data->Memory->EntriesNum].Text,
313 msg.Buffer+count+1,msg.Buffer[count]); 316 msg.Buffer+count+1,msg.Buffer[count]);
314 } 317 }
315 } else { 318 } else {
316 memcpy(Data->Memory->Entries[Data->Memory->EntriesNum].Text, 319 memcpy(Data->Memory->Entries[Data->Memory->EntriesNum].Text,
317 msg.Buffer+count+1,msg.Buffer[count]); 320 msg.Buffer+count+1,msg.Buffer[count]);
318 Data->Memory->Entries[Data->Memory->EntriesNum].Text[msg.Buffer[count]]=0x00; 321 Data->Memory->Entries[Data->Memory->EntriesNum].Text[msg.Buffer[count]]=0x00;
319 Data->Memory->Entries[Data->Memory->EntriesNum].Text[msg.Buffer[count]+1]=0x00; 322 Data->Memory->Entries[Data->Memory->EntriesNum].Text[msg.Buffer[count]+1]=0x00;
320 } 323 }
321 smprintf(s, "Name \"%s\"\n", 324 smprintf(s, "Name \"%s\"\n",
@@ -635,384 +638,385 @@ static GSM_Error N6110_GetSignalQuality(GSM_StateMachine *s, GSM_SignalQuality *
635 if (error!=ERR_NONE) return error; 638 if (error!=ERR_NONE) return error;
636 sig->SignalPercent = 100; 639 sig->SignalPercent = 100;
637 if (value[4]!='-') { 640 if (value[4]!='-') {
638 if (value[5]=='9' && value[6]>'4') sig->SignalPercent = 25; 641 if (value[5]=='9' && value[6]>'4') sig->SignalPercent = 25;
639 if (value[5]=='9' && value[6]<'5') sig->SignalPercent = 50; 642 if (value[5]=='9' && value[6]<'5') sig->SignalPercent = 50;
640 if (value[5]=='8' && value[6]>'4') sig->SignalPercent = 75; 643 if (value[5]=='8' && value[6]>'4') sig->SignalPercent = 75;
641 } else sig->SignalPercent = 0; 644 } else sig->SignalPercent = 0;
642 return ERR_NONE; 645 return ERR_NONE;
643 } else { 646 } else {
644 s->Phone.Data.SignalQuality = sig; 647 s->Phone.Data.SignalQuality = sig;
645 return N6110_GetStatus(s, ID_GetSignalQuality); 648 return N6110_GetStatus(s, ID_GetSignalQuality);
646 } 649 }
647} 650}
648 651
649static GSM_Error N6110_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat) 652static GSM_Error N6110_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat)
650{ 653{
651 char value[100]; 654 char value[100];
652 GSM_Error error; 655 GSM_Error error;
653 656
654 smprintf(s, "Getting battery level\n"); 657 smprintf(s, "Getting battery level\n");
655 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_POWER_BATT)) { 658 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_POWER_BATT)) {
656 error = DCT3_Netmonitor(s, 23, value); 659 error = DCT3_Netmonitor(s, 23, value);
657 if (error!=ERR_NONE) return error; 660 if (error!=ERR_NONE) return error;
658 bat->BatteryPercent = 100; 661 bat->BatteryPercent = 100;
659 bat->ChargeState = 0; 662 bat->ChargeState = 0;
660 if (value[29]=='7') bat->BatteryPercent = 75; 663 if (value[29]=='7') bat->BatteryPercent = 75;
661 if (value[29]=='5') bat->BatteryPercent = 50; 664 if (value[29]=='5') bat->BatteryPercent = 50;
662 if (value[29]=='2') bat->BatteryPercent = 25; 665 if (value[29]=='2') bat->BatteryPercent = 25;
663 return ERR_NONE; 666 return ERR_NONE;
664 } else { 667 } else {
665 s->Phone.Data.BatteryCharge = bat; 668 s->Phone.Data.BatteryCharge = bat;
666 return N6110_GetStatus(s, ID_GetBatteryCharge); 669 return N6110_GetStatus(s, ID_GetBatteryCharge);
667 } 670 }
668} 671}
669 672
670static GSM_Error N6110_ReplySaveSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s) 673static GSM_Error N6110_ReplySaveSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s)
671{ 674{
672 GSM_Phone_Data *Data = &s->Phone.Data; 675 GSM_Phone_Data *Data = &s->Phone.Data;
673 676
674 smprintf(s, "SMS message saving status\n"); 677 smprintf(s, "SMS message saving status\n");
675 switch (msg.Buffer[3]) { 678 switch (msg.Buffer[3]) {
676 case 0x05: 679 case 0x05:
677 smprintf(s, "Saved at location %i\n",msg.Buffer[5]); 680 smprintf(s, "Saved at location %i\n",msg.Buffer[5]);
678 Data->SaveSMSMessage->Location=msg.Buffer[5]; 681 Data->SaveSMSMessage->Location=msg.Buffer[5];
679 return ERR_NONE; 682 return ERR_NONE;
680 case 0x06: 683 case 0x06:
681 switch (msg.Buffer[4]) { 684 switch (msg.Buffer[4]) {
682 case 0x02: 685 case 0x02:
683 smprintf(s, "All locations busy\n"); 686 smprintf(s, "All locations busy\n");
684 return ERR_FULL; 687 return ERR_FULL;
685 case 0x03: 688 case 0x03:
686 smprintf(s, "Too high ?\n"); 689 smprintf(s, "Too high ?\n");
687 return ERR_INVALIDLOCATION; 690 return ERR_INVALIDLOCATION;
688 default: 691 default:
689 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]); 692 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]);
690 } 693 }
691 } 694 }
692 return ERR_UNKNOWNRESPONSE; 695 return ERR_UNKNOWNRESPONSE;
693} 696}
694 697
695static GSM_Error N6110_PrivSetSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms) 698static GSM_Error N6110_PrivSetSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms)
696{ 699{
697 int length; 700 int length;
698 GSM_Error error; 701 GSM_Error error;
699 unsigned char req[256] = {N6110_FRAME_HEADER, 0x04, 702 unsigned char req[256] = {N6110_FRAME_HEADER, 0x04,
700 0x00, /* SMS status */ 703 0x00, /* SMS status */
701 0x02, 704 0x02,
702 0x00, /* SMS location */ 705 0x00, /* SMS location */
703 0x02}; /* SMS type */ 706 0x02}; /* SMS type */
704 707
705 req[6] = sms->Location; 708 req[6] = sms->Location;
706 if (sms->Folder==1) { /* Inbox */ 709 if (sms->Folder==1) { /* Inbox */
707 req[4] = 1; /* SMS status - GSM_Read */ 710 req[4] = 1; /* SMS status - GSM_Read */
708 req[7] = 0x00; /* SMS type */ 711 req[7] = 0x00; /* SMS type */
709 sms->PDU = SMS_Deliver; 712 sms->PDU = SMS_Deliver;
710 error=PHONE_EncodeSMSFrame(s,sms,req+8,PHONE_SMSDeliver,&length,true); 713 error=PHONE_EncodeSMSFrame(s,sms,req+8,PHONE_SMSDeliver,&length,true);
711 } else { /* Outbox */ 714 } else { /* Outbox */
712 req[4] = 5; /* SMS status - GSM_Sent */ 715 req[4] = 5; /* SMS status - GSM_Sent */
713 req[7] = 0x02; /* SMS type */ 716 req[7] = 0x02; /* SMS type */
714 sms->PDU = SMS_Submit; 717 sms->PDU = SMS_Submit;
715 error=PHONE_EncodeSMSFrame(s,sms,req+8,PHONE_SMSSubmit,&length,true); 718 error=PHONE_EncodeSMSFrame(s,sms,req+8,PHONE_SMSSubmit,&length,true);
716 } 719 }
717 if (error != ERR_NONE) return error; 720 if (error != ERR_NONE) return error;
718 721
719 /* SMS State - GSM_Read -> GSM_Unread and GSM_Sent -> GSM_UnSent */ 722 /* SMS State - GSM_Read -> GSM_Unread and GSM_Sent -> GSM_UnSent */
720 if (sms->State == SMS_UnSent || sms->State == SMS_UnRead) req[4] |= 0x02; 723 if (sms->State == SMS_UnSent || sms->State == SMS_UnRead) req[4] |= 0x02;
721 724
722 s->Phone.Data.SaveSMSMessage=sms; 725 s->Phone.Data.SaveSMSMessage=sms;
723 smprintf(s, "Saving sms\n"); 726 smprintf(s, "Saving sms\n");
724 return GSM_WaitFor (s, req, 8+length, 0x14, 4, ID_SaveSMSMessage); 727 return GSM_WaitFor (s, req, 8+length, 0x14, 4, ID_SaveSMSMessage);
725} 728}
726 729
727static GSM_Error N6110_SetSMS(GSM_StateMachine *s, GSM_SMSMessage *sms) 730static GSM_Error N6110_SetSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
728{ 731{
729 if (sms->Location == 0) return ERR_INVALIDLOCATION; 732 if (sms->Location == 0) return ERR_INVALIDLOCATION;
730 return N6110_PrivSetSMSMessage(s, sms); 733 return N6110_PrivSetSMSMessage(s, sms);
731} 734}
732 735
733static GSM_Error N6110_AddSMS(GSM_StateMachine *s, GSM_SMSMessage *sms) 736static GSM_Error N6110_AddSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
734{ 737{
735 sms->Location = 0; 738 sms->Location = 0;
736 return N6110_PrivSetSMSMessage(s, sms); 739 return N6110_PrivSetSMSMessage(s, sms);
737} 740}
738 741
739static GSM_Error N6110_ReplySetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s) 742static GSM_Error N6110_ReplySetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s)
740{ 743{
741 switch (msg.Buffer[3]) { 744 switch (msg.Buffer[3]) {
742 case 0x37: 745 case 0x37:
743 smprintf(s, "Ringtone set OK\n"); 746 smprintf(s, "Ringtone set OK\n");
744 return ERR_NONE; 747 return ERR_NONE;
745 break; 748 break;
746 case 0x38: 749 case 0x38:
747 smprintf(s, "Error setting ringtone\n"); 750 smprintf(s, "Error setting ringtone\n");
748 switch (msg.Buffer[4]) { 751 switch (msg.Buffer[4]) {
749 case 0x7d: 752 case 0x7d:
750 smprintf(s, "Too high location ?\n"); 753 smprintf(s, "Too high location ?\n");
751 return ERR_INVALIDLOCATION; 754 return ERR_INVALIDLOCATION;
752 default: 755 default:
753 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]); 756 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]);
754 } 757 }
755 } 758 }
756 return ERR_UNKNOWNRESPONSE; 759 return ERR_UNKNOWNRESPONSE;
757} 760}
758 761
759static GSM_Error N6110_ReplySetBinRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s) 762static GSM_Error N6110_ReplySetBinRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s)
760{ 763{
761 switch (msg.Buffer[4]) { 764 switch (msg.Buffer[4]) {
762 case 0x00: 765 case 0x00:
763 smprintf(s, "Set at location %i\n",msg.Buffer[3]+1); 766 smprintf(s, "Set at location %i\n",msg.Buffer[3]+1);
764 return ERR_NONE; 767 return ERR_NONE;
765 default: 768 default:
766 smprintf(s, "Invalid location. Too high ?\n"); 769 smprintf(s, "Invalid location. Too high ?\n");
767 return ERR_INVALIDLOCATION; 770 return ERR_INVALIDLOCATION;
768 } 771 }
769} 772}
770 773
771static GSM_Error N6110_SetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength) 774static GSM_Error N6110_SetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength)
772{ 775{
773 GSM_NetworkInfo NetInfo; 776 GSM_NetworkInfo NetInfo;
774 GSM_Error error; 777 GSM_Error error;
775 int size=200,current=8; 778 int size=200,current=8;
776 GSM_UDHHeader UDHHeader; 779 GSM_UDHHeader UDHHeader;
777 unsigned char req[1000] = {N6110_FRAME_HEADER, 0x36, 780 unsigned char req[1000] = {N6110_FRAME_HEADER, 0x36,
778 0x00, /* Location */ 781 0x00, /* Location */
779 0x00,0x78}; 782 0x00,0x78};
780 unsigned char reqBin[1000] = {0x00,0x01,0xa0,0x00,0x00,0x0c,0x01,0x2c}; 783 unsigned char reqBin[1000] = {0x00,0x01,0xa0,0x00,0x00,0x0c,0x01,0x2c};
781 784
782 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NORING)) return ERR_NOTSUPPORTED; 785 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NORING)) return ERR_NOTSUPPORTED;
783 if (Ringtone->Location == 0) return ERR_INVALIDLOCATION; 786 if (Ringtone->Location == 0) return ERR_INVALIDLOCATION;
784 787
785 switch (Ringtone->Format) { 788 switch (Ringtone->Format) {
786 case RING_NOTETONE: 789 case RING_NOTETONE:
787 if (Ringtone->Location==255) { 790 if (Ringtone->Location==255) {
788 /* Only 6110, 6130 and 6150 support it */ 791 /* Only 6110, 6130 and 6150 support it */
789 if (strcmp(s->Phone.Data.Model,"NSE-3") == 0 || strcmp(s->Phone.Data.Model,"NSK-3") == 0 || 792 if (strcmp(s->Phone.Data.Model,"NSE-3") == 0 || strcmp(s->Phone.Data.Model,"NSK-3") == 0 ||
790 strcmp(s->Phone.Data.Model,"NSM-1") == 0) { 793 strcmp(s->Phone.Data.Model,"NSM-1") == 0) {
791 req[0] = 0x0c; 794 req[0] = 0x0c;
792 req[1] = 0x01; 795 req[1] = 0x01;
793 UDHHeader.Type = UDH_NokiaRingtone; 796 UDHHeader.Type = UDH_NokiaRingtone;
794 GSM_EncodeUDHHeader(&UDHHeader); 797 GSM_EncodeUDHHeader(&UDHHeader);
795 /* We copy UDH now */ 798 /* We copy UDH now */
796 memcpy(req+2,UDHHeader.Text,UDHHeader.Length); 799 memcpy(req+2,UDHHeader.Text,UDHHeader.Length);
797 *maxlength=GSM_EncodeNokiaRTTLRingtone(*Ringtone, req+2+UDHHeader.Length, &size); 800 *maxlength=GSM_EncodeNokiaRTTLRingtone(*Ringtone, req+2+UDHHeader.Length, &size);
798 error = s->Protocol.Functions->WriteMessage(s, req, 2+UDHHeader.Length+size, 0x12); 801 error = s->Protocol.Functions->WriteMessage(s, req, 2+UDHHeader.Length+size, 0x12);
799 if (error!=ERR_NONE) return error; 802 if (error!=ERR_NONE) return error;
800 my_sleep(1000); 803 my_sleep(1000);
801 /* We have to make something (not important, what) now */ 804 /* We have to make something (not important, what) now */
802 /* no answer from phone*/ 805 /* no answer from phone*/
803 return DCT3_GetNetworkInfo(s,&NetInfo); 806 return DCT3_GetNetworkInfo(s,&NetInfo);
804 } else { 807 } else {
805 return ERR_NOTSUPPORTED; 808 return ERR_NOTSUPPORTED;
806 } 809 }
807 } 810 }
808 *maxlength=GSM_EncodeNokiaRTTLRingtone(*Ringtone, req+7, &size); 811 *maxlength=GSM_EncodeNokiaRTTLRingtone(*Ringtone, req+7, &size);
809 req[4] = Ringtone->Location - 1; 812 req[4] = Ringtone->Location - 1;
810 smprintf(s, "Setting ringtone\n"); 813 smprintf(s, "Setting ringtone\n");
811 return GSM_WaitFor (s, req, 7 + size, 0x05, 4, ID_SetRingtone); 814 return GSM_WaitFor (s, req, 7 + size, 0x05, 4, ID_SetRingtone);
812 case RING_NOKIABINARY: 815 case RING_NOKIABINARY:
813 error=DCT3_EnableSecurity (s, 0x01); 816 error=DCT3_EnableSecurity (s, 0x01);
814 if (error!=ERR_NONE) return error; 817 if (error!=ERR_NONE) return error;
815 memcpy(reqBin+current,DecodeUnicodeString(Ringtone->Name),UnicodeLength(Ringtone->Name)); 818 memcpy(reqBin+current,DecodeUnicodeString(Ringtone->Name),UnicodeLength(Ringtone->Name));
816 current += UnicodeLength(Ringtone->Name); 819 current += UnicodeLength(Ringtone->Name);
817 reqBin[current++] = 0x00; 820 reqBin[current++] = 0x00;
818 reqBin[current++] = 0x00; 821 reqBin[current++] = 0x00;
819 reqBin[current++] = 0x00;/*xxx*/ 822 reqBin[current++] = 0x00;/*xxx*/
820 memcpy(reqBin+current,Ringtone->NokiaBinary.Frame,Ringtone->NokiaBinary.Length); 823 memcpy(reqBin+current,Ringtone->NokiaBinary.Frame,Ringtone->NokiaBinary.Length);
821 current=current+Ringtone->NokiaBinary.Length; 824 current=current+Ringtone->NokiaBinary.Length;
822 reqBin[3]=Ringtone->Location-1; 825 reqBin[3]=Ringtone->Location-1;
823 if (!strcmp(s->Phone.Data.ModelInfo->model,"3210")) reqBin[5]=0x10; 826 if (!strcmp(s->Phone.Data.ModelInfo->model,"3210")) reqBin[5]=0x10;
824 smprintf(s, "Setting binary ringtone\n"); 827 smprintf(s, "Setting binary ringtone\n");
825 return GSM_WaitFor (s, reqBin, current, 0x40, 4, ID_SetRingtone); 828 return GSM_WaitFor (s, reqBin, current, 0x40, 4, ID_SetRingtone);
826 case RING_MIDI: 829 case RING_MIDI:
830 case RING_MMF:
827 return ERR_NOTSUPPORTED; 831 return ERR_NOTSUPPORTED;
828 } 832 }
829 return ERR_NOTSUPPORTED; 833 return ERR_NOTSUPPORTED;
830} 834}
831 835
832static GSM_Error N6110_ReplyGetOpLogo(GSM_Protocol_Message msg, GSM_StateMachine *s) 836static GSM_Error N6110_ReplyGetOpLogo(GSM_Protocol_Message msg, GSM_StateMachine *s)
833{ 837{
834 int count=5; 838 int count=5;
835 GSM_Phone_Data *Data = &s->Phone.Data; 839 GSM_Phone_Data *Data = &s->Phone.Data;
836 840
837 smprintf(s, "Operator logo received\n"); 841 smprintf(s, "Operator logo received\n");
838 NOKIA_DecodeNetworkCode(msg.Buffer+count,Data->Bitmap->NetworkCode); 842 NOKIA_DecodeNetworkCode(msg.Buffer+count,Data->Bitmap->NetworkCode);
839 count = count + 3; 843 count = count + 3;
840 smprintf(s, "Network code : %s\n", Data->Bitmap->NetworkCode); 844 smprintf(s, "Network code : %s\n", Data->Bitmap->NetworkCode);
841 smprintf(s, "Network name for Gammu : %s ", 845 smprintf(s, "Network name for Gammu : %s ",
842 DecodeUnicodeString(GSM_GetNetworkName(Data->Bitmap->NetworkCode))); 846 DecodeUnicodeString(GSM_GetNetworkName(Data->Bitmap->NetworkCode)));
843 smprintf(s, "(%s)\n",DecodeUnicodeString(GSM_GetCountryName(Data->Bitmap->NetworkCode))); 847 smprintf(s, "(%s)\n",DecodeUnicodeString(GSM_GetCountryName(Data->Bitmap->NetworkCode)));
844 848
845 count = count + 3; /* We ignore size */ 849 count = count + 3; /* We ignore size */
846 Data->Bitmap->BitmapWidth = msg.Buffer[count++]; 850 Data->Bitmap->BitmapWidth = msg.Buffer[count++];
847 Data->Bitmap->BitmapHeight = msg.Buffer[count++]; 851 Data->Bitmap->BitmapHeight = msg.Buffer[count++];
848 count++; 852 count++;
849 PHONE_DecodeBitmap(GSM_NokiaOperatorLogo,msg.Buffer+count,Data->Bitmap); 853 PHONE_DecodeBitmap(GSM_NokiaOperatorLogo,msg.Buffer+count,Data->Bitmap);
850 return ERR_NONE; 854 return ERR_NONE;
851} 855}
852 856
853static GSM_Error N6110_ReplyGetStartup(GSM_Protocol_Message msg, GSM_StateMachine *s) 857static GSM_Error N6110_ReplyGetStartup(GSM_Protocol_Message msg, GSM_StateMachine *s)
854{ 858{
855 int i, count = 5; 859 int i, count = 5;
856 GSM_Phone_Data *Data = &s->Phone.Data; 860 GSM_Phone_Data *Data = &s->Phone.Data;
857 861
858 smprintf(s, "Startup logo & notes received\n"); 862 smprintf(s, "Startup logo & notes received\n");
859 for (i=0;i<msg.Buffer[4];i++) { 863 for (i=0;i<msg.Buffer[4];i++) {
860 switch (msg.Buffer[count++]) { 864 switch (msg.Buffer[count++]) {
861 case 0x01: 865 case 0x01:
862 smprintf(s, "Startup logo\n"); 866 smprintf(s, "Startup logo\n");
863 if (Data->Bitmap->Type == GSM_StartupLogo) { 867 if (Data->Bitmap->Type == GSM_StartupLogo) {
864 Data->Bitmap->BitmapHeight = msg.Buffer[count++]; 868 Data->Bitmap->BitmapHeight = msg.Buffer[count++];
865 Data->Bitmap->BitmapWidth = msg.Buffer[count++]; 869 Data->Bitmap->BitmapWidth = msg.Buffer[count++];
866 PHONE_DecodeBitmap(GSM_NokiaStartupLogo, msg.Buffer + count, Data->Bitmap); 870 PHONE_DecodeBitmap(GSM_NokiaStartupLogo, msg.Buffer + count, Data->Bitmap);
867 } else { 871 } else {
868 count = count + 2; 872 count = count + 2;
869 } 873 }
870 count = count + PHONE_GetBitmapSize(GSM_NokiaStartupLogo,0,0); 874 count = count + PHONE_GetBitmapSize(GSM_NokiaStartupLogo,0,0);
871 break; 875 break;
872 case 0x02: 876 case 0x02:
873 smprintf(s, "Welcome note\n"); 877 smprintf(s, "Welcome note\n");
874 if (Data->Bitmap->Type == GSM_WelcomeNote_Text) { 878 if (Data->Bitmap->Type == GSM_WelcomeNote_Text) {
875 EncodeUnicode(Data->Bitmap->Text,msg.Buffer+count, msg.Buffer[count]); 879 EncodeUnicode(Data->Bitmap->Text,msg.Buffer+count, msg.Buffer[count]);
876 smprintf(s, "Text is \"%s\"\n",Data->Bitmap->Text); 880 smprintf(s, "Text is \"%s\"\n",Data->Bitmap->Text);
877 } 881 }
878 count = count + msg.Buffer[count] + 1; 882 count = count + msg.Buffer[count] + 1;
879 break; 883 break;
880 case 0x03: 884 case 0x03:
881 smprintf(s, "Dealer welcome note\n"); 885 smprintf(s, "Dealer welcome note\n");
882 if (Data->Bitmap->Type == GSM_DealerNote_Text) { 886 if (Data->Bitmap->Type == GSM_DealerNote_Text) {
883 EncodeUnicode(Data->Bitmap->Text,msg.Buffer+count, msg.Buffer[count]); 887 EncodeUnicode(Data->Bitmap->Text,msg.Buffer+count, msg.Buffer[count]);
884 smprintf(s, "Text is \"%s\"\n",Data->Bitmap->Text); 888 smprintf(s, "Text is \"%s\"\n",Data->Bitmap->Text);
885 } 889 }
886 count = count + msg.Buffer[count] + 1; 890 count = count + msg.Buffer[count] + 1;
887 break; 891 break;
888 default: 892 default:
889 smprintf(s, "Unknown block\n"); 893 smprintf(s, "Unknown block\n");
890 return ERR_UNKNOWNRESPONSE; 894 return ERR_UNKNOWNRESPONSE;
891 break; 895 break;
892 } 896 }
893 } 897 }
894 return ERR_NONE; 898 return ERR_NONE;
895} 899}
896 900
897static GSM_Error N6110_ReplyGetCallerLogo(GSM_Protocol_Message msg, GSM_StateMachine *s) 901static GSM_Error N6110_ReplyGetCallerLogo(GSM_Protocol_Message msg, GSM_StateMachine *s)
898{ 902{
899 int count; 903 int count;
900 GSM_Phone_Data *Data = &s->Phone.Data; 904 GSM_Phone_Data *Data = &s->Phone.Data;
901 905
902 switch (msg.Buffer[3]) { 906 switch (msg.Buffer[3]) {
903 case 0x11: 907 case 0x11:
904 smprintf(s, "Caller group info received\n"); 908 smprintf(s, "Caller group info received\n");
905 EncodeUnicode(Data->Bitmap->Text,msg.Buffer+6,msg.Buffer[5]); 909 EncodeUnicode(Data->Bitmap->Text,msg.Buffer+6,msg.Buffer[5]);
906 smprintf(s, "Name : \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Text)); 910 smprintf(s, "Name : \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Text));
907 Data->Bitmap->DefaultName = false; 911 Data->Bitmap->DefaultName = false;
908 if (msg.Buffer[5] == 0x00) Data->Bitmap->DefaultName = true; 912 if (msg.Buffer[5] == 0x00) Data->Bitmap->DefaultName = true;
909 count = msg.Buffer[5] + 6; 913 count = msg.Buffer[5] + 6;
910 Data->Bitmap->RingtoneID = msg.Buffer[count++]; 914 Data->Bitmap->RingtoneID = msg.Buffer[count++];
911 Data->Bitmap->DefaultRingtone = false; 915 Data->Bitmap->DefaultRingtone = false;
912 Data->Bitmap->FileSystemRingtone = false; 916 Data->Bitmap->FileSystemRingtone = false;
913 if (Data->Bitmap->RingtoneID == 16) Data->Bitmap->DefaultRingtone = true; 917 if (Data->Bitmap->RingtoneID == 16) Data->Bitmap->DefaultRingtone = true;
914 smprintf(s, "Ringtone ID: %02x\n",Data->Bitmap->RingtoneID); 918 smprintf(s, "Ringtone ID: %02x\n",Data->Bitmap->RingtoneID);
915 Data->Bitmap->BitmapEnabled=(msg.Buffer[count++]==1); 919 Data->Bitmap->BitmapEnabled=(msg.Buffer[count++]==1);
916#ifdef DEBUG 920#ifdef DEBUG
917 smprintf(s, "Caller group logo "); 921 smprintf(s, "Caller group logo ");
918 if (Data->Bitmap->BitmapEnabled) { 922 if (Data->Bitmap->BitmapEnabled) {
919 smprintf(s, "enabled\n"); 923 smprintf(s, "enabled\n");
920 } else { 924 } else {
921 smprintf(s, "disabled\n"); 925 smprintf(s, "disabled\n");
922 } 926 }
923#endif 927#endif
924 count = count + 3; /* We ignore size */ 928 count = count + 3; /* We ignore size */
925 Data->Bitmap->BitmapWidth = msg.Buffer[count++]; 929 Data->Bitmap->BitmapWidth = msg.Buffer[count++];
926 Data->Bitmap->BitmapHeight = msg.Buffer[count++]; 930 Data->Bitmap->BitmapHeight = msg.Buffer[count++];
927 count++; 931 count++;
928 PHONE_DecodeBitmap(GSM_NokiaCallerLogo,msg.Buffer+count,Data->Bitmap); 932 PHONE_DecodeBitmap(GSM_NokiaCallerLogo,msg.Buffer+count,Data->Bitmap);
929 Data->Bitmap->DefaultBitmap = false; 933 Data->Bitmap->DefaultBitmap = false;
930 return ERR_NONE; 934 return ERR_NONE;
931 case 0x12: 935 case 0x12:
932 smprintf(s, "Error getting caller group info\n"); 936 smprintf(s, "Error getting caller group info\n");
933 return ERR_INVALIDLOCATION; 937 return ERR_INVALIDLOCATION;
934 } 938 }
935 return ERR_UNKNOWNRESPONSE; 939 return ERR_UNKNOWNRESPONSE;
936} 940}
937 941
938static GSM_Error N6110_ReplyGetSetPicture(GSM_Protocol_Message msg, GSM_StateMachine *s) 942static GSM_Error N6110_ReplyGetSetPicture(GSM_Protocol_Message msg, GSM_StateMachine *s)
939{ 943{
940 int count = 5, i; 944 int count = 5, i;
941 GSM_Phone_Data *Data = &s->Phone.Data; 945 GSM_Phone_Data *Data = &s->Phone.Data;
942 946
943 switch (msg.Buffer[3]) { 947 switch (msg.Buffer[3]) {
944 case 0x02: 948 case 0x02:
945 smprintf(s, "Picture Image received\n"); 949 smprintf(s, "Picture Image received\n");
946 if (msg.Buffer[count]!=0) { 950 if (msg.Buffer[count]!=0) {
947 GSM_UnpackSemiOctetNumber(Data->Bitmap->Sender, msg.Buffer + 5, true); 951 GSM_UnpackSemiOctetNumber(Data->Bitmap->Sender, msg.Buffer + 5, true);
948 /* Convert number of semioctets to number of chars */ 952 /* Convert number of semioctets to number of chars */
949 i = msg.Buffer[5]; 953 i = msg.Buffer[5];
950 if (i % 2) i++; 954 if (i % 2) i++;
951 i=i / 2 + 1; 955 i=i / 2 + 1;
952 count = count + i + 1; 956 count = count + i + 1;
953 } else { 957 } else {
954 Data->Bitmap->Sender[0] = 0x00; 958 Data->Bitmap->Sender[0] = 0x00;
955 Data->Bitmap->Sender[1] = 0x00; 959 Data->Bitmap->Sender[1] = 0x00;
956 count+=2; 960 count+=2;
957 } 961 }
958 smprintf(s, "Sender : \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Sender)); 962 smprintf(s, "Sender : \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Sender));
959 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOPICTUREUNI) || 963 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOPICTUREUNI) ||
960 (!strcmp(Data->Model,"NHM-5") && Data->VerNum < 5.79)) { 964 (!strcmp(Data->Model,"NHM-5") && Data->VerNum < 5.79)) {
961 count++; 965 count++;
962 EncodeUnicode(Data->Bitmap->Text,msg.Buffer+count+1,msg.Buffer[count]); 966 EncodeUnicode(Data->Bitmap->Text,msg.Buffer+count+1,msg.Buffer[count]);
963 count += UnicodeLength(Data->Bitmap->Text) + 1; 967 count += UnicodeLength(Data->Bitmap->Text) + 1;
964 } else { 968 } else {
965 if (!strcmp(Data->Model,"NHM-5")) { 969 if (!strcmp(Data->Model,"NHM-5")) {
966 i = msg.Buffer[count] * 256 + msg.Buffer[count+1]; 970 i = msg.Buffer[count] * 256 + msg.Buffer[count+1];
967 } else { 971 } else {
968 /* 3410 4.26 */ 972 /* 3410 4.26 */
969 i = msg.Buffer[count] * 256 + msg.Buffer[count+1] - 2; 973 i = msg.Buffer[count] * 256 + msg.Buffer[count+1] - 2;
970 count += 2; 974 count += 2;
971 } 975 }
972 memcpy(Data->Bitmap->Text,msg.Buffer+count+2,i); 976 memcpy(Data->Bitmap->Text,msg.Buffer+count+2,i);
973 Data->Bitmap->Text[i] = 0; 977 Data->Bitmap->Text[i] = 0;
974 Data->Bitmap->Text[i+1] = 0; 978 Data->Bitmap->Text[i+1] = 0;
975 count += i + 2; 979 count += i + 2;
976 } 980 }
977 smprintf(s, "Text : \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Text)); 981 smprintf(s, "Text : \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Text));
978 Data->Bitmap->BitmapWidth = msg.Buffer[count++]; 982 Data->Bitmap->BitmapWidth = msg.Buffer[count++];
979 Data->Bitmap->BitmapHeight = msg.Buffer[count++]; 983 Data->Bitmap->BitmapHeight = msg.Buffer[count++];
980 PHONE_DecodeBitmap(GSM_NokiaPictureImage, msg.Buffer + count + 2, Data->Bitmap); 984 PHONE_DecodeBitmap(GSM_NokiaPictureImage, msg.Buffer + count + 2, Data->Bitmap);
981#ifdef DEBUG 985#ifdef DEBUG
982 if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) GSM_PrintBitmap(di.df,Data->Bitmap); 986 if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) GSM_PrintBitmap(di.df,Data->Bitmap);
983#endif 987#endif
984 return ERR_NONE; 988 return ERR_NONE;
985 break; 989 break;
986 case 0x04: 990 case 0x04:
987 smprintf(s, "Picture Image set OK\n"); 991 smprintf(s, "Picture Image set OK\n");
988 return ERR_NONE; 992 return ERR_NONE;
989 case 0x05: 993 case 0x05:
990 smprintf(s, "Can't set Picture Image - invalid location ?\n"); 994 smprintf(s, "Can't set Picture Image - invalid location ?\n");
991 return ERR_INVALIDLOCATION; 995 return ERR_INVALIDLOCATION;
992 break; 996 break;
993 case 0x06: 997 case 0x06:
994 smprintf(s, "Can't get Picture Image - invalid location ?\n"); 998 smprintf(s, "Can't get Picture Image - invalid location ?\n");
995 return ERR_INVALIDLOCATION; 999 return ERR_INVALIDLOCATION;
996 break; 1000 break;
997 } 1001 }
998 return ERR_UNKNOWNRESPONSE; 1002 return ERR_UNKNOWNRESPONSE;
999} 1003}
1000 1004
1001static GSM_Error N6110_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap) 1005static GSM_Error N6110_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
1002{ 1006{
1003 GSM_Error error; 1007 GSM_Error error;
1004 unsigned char req[10] = {N6110_FRAME_HEADER}; 1008 unsigned char req[10] = {N6110_FRAME_HEADER};
1005 1009
1006 s->Phone.Data.Bitmap=Bitmap; 1010 s->Phone.Data.Bitmap=Bitmap;
1007 switch (Bitmap->Type) { 1011 switch (Bitmap->Type) {
1008 case GSM_StartupLogo: 1012 case GSM_StartupLogo:
1009 case GSM_WelcomeNote_Text: 1013 case GSM_WelcomeNote_Text:
1010 case GSM_DealerNote_Text: 1014 case GSM_DealerNote_Text:
1011 if (Bitmap->Type == GSM_StartupLogo && IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NOSTARTUP)) return ERR_NOTSUPPORTED; 1015 if (Bitmap->Type == GSM_StartupLogo && IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NOSTARTUP)) return ERR_NOTSUPPORTED;
1012 req[3] = 0x16; 1016 req[3] = 0x16;
1013 return GSM_WaitFor (s, req, 4, 0x05, 4, ID_GetBitmap); 1017 return GSM_WaitFor (s, req, 4, 0x05, 4, ID_GetBitmap);
1014 case GSM_CallerGroupLogo: 1018 case GSM_CallerGroupLogo:
1015 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NOCALLER)) return ERR_NOTSUPPORTED; 1019 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NOCALLER)) return ERR_NOTSUPPORTED;
1016 req[3] = 0x10; 1020 req[3] = 0x10;
1017 req[4] = Bitmap->Location - 1; 1021 req[4] = Bitmap->Location - 1;
1018 error = GSM_WaitFor (s, req, 5, 0x03, 4, ID_GetBitmap); 1022 error = GSM_WaitFor (s, req, 5, 0x03, 4, ID_GetBitmap);
@@ -1335,421 +1339,423 @@ static GSM_Error N6110_ReplyCallInfo(GSM_Protocol_Message msg, GSM_StateMachine
1335 if (msg.Buffer[3] == 0x09) { 1339 if (msg.Buffer[3] == 0x09) {
1336 if (s->Phone.Data.CallID == msg.Buffer[4]) return ERR_NONE; 1340 if (s->Phone.Data.CallID == msg.Buffer[4]) return ERR_NONE;
1337 /* when we canceled call and see frame about other 1341 /* when we canceled call and see frame about other
1338 * call releasing, we don't give ERR_NONE for "our" 1342 * call releasing, we don't give ERR_NONE for "our"
1339 * call release command 1343 * call release command
1340 */ 1344 */
1341 return ERR_NEEDANOTHERANSWER; 1345 return ERR_NEEDANOTHERANSWER;
1342 } 1346 }
1343 } 1347 }
1344 if (s->Phone.Data.RequestID == ID_AnswerCall) { 1348 if (s->Phone.Data.RequestID == ID_AnswerCall) {
1345 if (msg.Buffer[3] == 0x07) { 1349 if (msg.Buffer[3] == 0x07) {
1346 if (s->Phone.Data.CallID == msg.Buffer[4]) return ERR_NONE; 1350 if (s->Phone.Data.CallID == msg.Buffer[4]) return ERR_NONE;
1347 return ERR_NEEDANOTHERANSWER; 1351 return ERR_NEEDANOTHERANSWER;
1348 } 1352 }
1349 } 1353 }
1350 if (s->Phone.Data.RequestID == ID_UnholdCall) { 1354 if (s->Phone.Data.RequestID == ID_UnholdCall) {
1351 if (msg.Buffer[3] == 0x25) { 1355 if (msg.Buffer[3] == 0x25) {
1352 if (s->Phone.Data.CallID == msg.Buffer[4]) return ERR_NONE; 1356 if (s->Phone.Data.CallID == msg.Buffer[4]) return ERR_NONE;
1353 return ERR_NEEDANOTHERANSWER; 1357 return ERR_NEEDANOTHERANSWER;
1354 } 1358 }
1355 } 1359 }
1356 if (s->Phone.Data.RequestID == ID_HoldCall) { 1360 if (s->Phone.Data.RequestID == ID_HoldCall) {
1357 if (msg.Buffer[3] == 0x23) { 1361 if (msg.Buffer[3] == 0x23) {
1358 if (s->Phone.Data.CallID == msg.Buffer[4]) return ERR_NONE; 1362 if (s->Phone.Data.CallID == msg.Buffer[4]) return ERR_NONE;
1359 return ERR_NEEDANOTHERANSWER; 1363 return ERR_NEEDANOTHERANSWER;
1360 } 1364 }
1361 } 1365 }
1362 if (s->Phone.Data.RequestID == ID_ConferenceCall) { 1366 if (s->Phone.Data.RequestID == ID_ConferenceCall) {
1363 if (msg.Buffer[3] == 0x29) { 1367 if (msg.Buffer[3] == 0x29) {
1364 if (s->Phone.Data.CallID == msg.Buffer[4]) return ERR_NONE; 1368 if (s->Phone.Data.CallID == msg.Buffer[4]) return ERR_NONE;
1365 return ERR_NEEDANOTHERANSWER; 1369 return ERR_NEEDANOTHERANSWER;
1366 } 1370 }
1367 } 1371 }
1368 if (s->Phone.Data.RequestID == ID_SplitCall) { 1372 if (s->Phone.Data.RequestID == ID_SplitCall) {
1369 if (msg.Buffer[3] == 0x2B) { 1373 if (msg.Buffer[3] == 0x2B) {
1370 if (s->Phone.Data.CallID == msg.Buffer[4]) return ERR_NONE; 1374 if (s->Phone.Data.CallID == msg.Buffer[4]) return ERR_NONE;
1371 return ERR_NEEDANOTHERANSWER; 1375 return ERR_NEEDANOTHERANSWER;
1372 } 1376 }
1373 } 1377 }
1374 return ERR_NONE; 1378 return ERR_NONE;
1375} 1379}
1376 1380
1377static GSM_Error N6110_DeleteSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms) 1381static GSM_Error N6110_DeleteSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms)
1378{ 1382{
1379 unsigned char req[] = {N6110_FRAME_HEADER, 0x0a, 0x02, 1383 unsigned char req[] = {N6110_FRAME_HEADER, 0x0a, 0x02,
1380 0x00}; /* Location */ 1384 0x00}; /* Location */
1381 1385
1382 if (sms->Folder!=0x00) return ERR_NOTSUPPORTED; 1386 if (sms->Folder!=0x00) return ERR_NOTSUPPORTED;
1383 1387
1384 req[5]=sms->Location; 1388 req[5]=sms->Location;
1385 1389
1386 smprintf(s, "Deleting sms\n"); 1390 smprintf(s, "Deleting sms\n");
1387 return GSM_WaitFor (s, req, 6, 0x14, 4, ID_DeleteSMSMessage); 1391 return GSM_WaitFor (s, req, 6, 0x14, 4, ID_DeleteSMSMessage);
1388} 1392}
1389 1393
1390static GSM_Error N6110_ReplySetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s) 1394static GSM_Error N6110_ReplySetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s)
1391{ 1395{
1392 smprintf(s, "Reply for writing memory\n"); 1396 smprintf(s, "Reply for writing memory\n");
1393 switch (msg.Buffer[3]) { 1397 switch (msg.Buffer[3]) {
1394 case 0x05: 1398 case 0x05:
1395 smprintf(s, "Done OK\n"); 1399 smprintf(s, "Done OK\n");
1396 return ERR_NONE; 1400 return ERR_NONE;
1397 case 0x06: 1401 case 0x06:
1398 smprintf(s, "Error\n"); 1402 smprintf(s, "Error\n");
1399 switch (msg.Buffer[4]) { 1403 switch (msg.Buffer[4]) {
1400 case 0x7d: 1404 case 0x7d:
1401 smprintf(s, "Too high location ?\n"); 1405 smprintf(s, "Too high location ?\n");
1402 return ERR_INVALIDLOCATION; 1406 return ERR_INVALIDLOCATION;
1403 case 0x90: 1407 case 0x90:
1404 smprintf(s, "Too long name...or other error\n"); 1408 smprintf(s, "Too long name...or other error\n");
1405 return ERR_NOTSUPPORTED; 1409 return ERR_NOTSUPPORTED;
1406 default: 1410 default:
1407 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]); 1411 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]);
1408 } 1412 }
1409 } 1413 }
1410 return ERR_UNKNOWNRESPONSE; 1414 return ERR_UNKNOWNRESPONSE;
1411} 1415}
1412 1416
1413static GSM_Error N6110_SetMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry) 1417static GSM_Error N6110_SetMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
1414{ 1418{
1415 int current, Group, Name, Number; 1419 int current, Group, Name, Number;
1416 unsigned char req[128] = {N6110_FRAME_HEADER, 0x04, 1420 unsigned char req[128] = {N6110_FRAME_HEADER, 0x04,
1417 0x00, /* memory type */ 1421 0x00, /* memory type */
1418 0x00}; /* location */ 1422 0x00}; /* location */
1419 1423
1420 if (entry->Location == 0) return ERR_NOTSUPPORTED; 1424 if (entry->Location == 0) return ERR_NOTSUPPORTED;
1421 1425
1422 GSM_PhonebookFindDefaultNameNumberGroup(entry, &Name, &Number, &Group); 1426 GSM_PhonebookFindDefaultNameNumberGroup(entry, &Name, &Number, &Group);
1423 1427
1424 req[4] = NOKIA_GetMemoryType(s, entry->MemoryType,N6110_MEMORY_TYPES); 1428 req[4] = NOKIA_GetMemoryType(s, entry->MemoryType,N6110_MEMORY_TYPES);
1425 req[5] = entry->Location; 1429 req[5] = entry->Location;
1426 1430
1427 current = 7; 1431 current = 7;
1428 1432
1429 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOPBKUNICODE)) { 1433 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOPBKUNICODE)) {
1430 if (Name != -1) { 1434 if (Name != -1) {
1431 req[6] = UnicodeLength(entry->Entries[Name].Text); 1435 req[6] = UnicodeLength(entry->Entries[Name].Text);
1432 memcpy(req+current,DecodeUnicodeString(entry->Entries[Name].Text),UnicodeLength(entry->Entries[Name].Text)); 1436 memcpy(req+current,DecodeUnicodeString(entry->Entries[Name].Text),UnicodeLength(entry->Entries[Name].Text));
1433 current += UnicodeLength(entry->Entries[Name].Text); 1437 current += UnicodeLength(entry->Entries[Name].Text);
1434 } else req[6] = 0; 1438 } else req[6] = 0;
1435 } else { 1439 } else {
1436 if (Name != -1) { 1440 if (Name != -1) {
1437 req[6] = UnicodeLength(entry->Entries[Name].Text)*2+2; 1441 req[6] = UnicodeLength(entry->Entries[Name].Text)*2+2;
1438 memcpy(req+current,entry->Entries[Name].Text,UnicodeLength(entry->Entries[Name].Text)*2); 1442 memcpy(req+current,entry->Entries[Name].Text,UnicodeLength(entry->Entries[Name].Text)*2);
1439 current += UnicodeLength(entry->Entries[Name].Text)*2; 1443 current += UnicodeLength(entry->Entries[Name].Text)*2;
1440 } else req[6] = 0; 1444 } else req[6] = 0;
1441 req[current++]=0x00; 1445 req[current++]=0x00;
1442 req[current++]=0x00; 1446 req[current++]=0x00;
1443 } 1447 }
1444 1448
1445 if (Number != -1) { 1449 if (Number != -1) {
1446 req[current++]=UnicodeLength(entry->Entries[Number].Text); 1450 req[current++]=UnicodeLength(entry->Entries[Number].Text);
1447 memcpy(req+current,DecodeUnicodeString(entry->Entries[Number].Text),UnicodeLength(entry->Entries[Number].Text)); 1451 memcpy(req+current,DecodeUnicodeString(entry->Entries[Number].Text),UnicodeLength(entry->Entries[Number].Text));
1448 current += UnicodeLength(entry->Entries[Number].Text); 1452 current += UnicodeLength(entry->Entries[Number].Text);
1449 } else req[current++] = 0; 1453 } else req[current++] = 0;
1450 1454
1451 /* This allow to save 14 characters name into SIM memory, when 1455 /* This allow to save 14 characters name into SIM memory, when
1452 * no caller group is selected. */ 1456 * no caller group is selected. */
1453 if (Group == -1) { 1457 if (Group == -1) {
1454 req[current++] = 0xff; 1458 req[current++] = 0xff;
1455 } else { 1459 } else {
1456 req[current++] = entry->Entries[Group].Number-1; 1460 req[current++] = entry->Entries[Group].Number-1;
1457 } 1461 }
1458 1462
1459 smprintf(s, "Writing phonebook entry\n"); 1463 smprintf(s, "Writing phonebook entry\n");
1460 return GSM_WaitFor (s, req, current, 0x03, 4, ID_SetMemory); 1464 return GSM_WaitFor (s, req, current, 0x03, 4, ID_SetMemory);
1461} 1465}
1462 1466
1463static GSM_Error N6110_DeleteMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry) 1467static GSM_Error N6110_DeleteMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
1464{ 1468{
1465 GSM_MemoryEntry dwa; 1469 GSM_MemoryEntry dwa;
1466 1470
1467 dwa.Location = entry->Location; 1471 dwa.Location = entry->Location;
1468 dwa.MemoryType = entry->MemoryType; 1472 dwa.MemoryType = entry->MemoryType;
1469 dwa.EntriesNum = 0; 1473 dwa.EntriesNum = 0;
1470 1474
1471 return N6110_SetMemory(s, &dwa); 1475 return N6110_SetMemory(s, &dwa);
1472} 1476}
1473 1477
1474static GSM_Error N6110_ReplyGetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s) 1478static GSM_Error N6110_ReplyGetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s)
1475{ 1479{
1476 GSM_Phone_Data *Data = &s->Phone.Data; 1480 GSM_Phone_Data *Data = &s->Phone.Data;
1477 char buffer[2000]; 1481 char buffer[2000];
1478 GSM_Error error; 1482 GSM_Error error;
1479 int i,end,start; 1483 int i,end,start;
1480 1484
1481 smprintf(s, "Ringtone received\n"); 1485 smprintf(s, "Ringtone received\n");
1482 switch (msg.Buffer[4]) { 1486 switch (msg.Buffer[4]) {
1483 case 0x00: 1487 case 0x00:
1484 switch (Data->Ringtone->Format) { 1488 switch (Data->Ringtone->Format) {
1485 case RING_NOTETONE: 1489 case RING_NOTETONE:
1486 memcpy(buffer,msg.Buffer,msg.Length); 1490 memcpy(buffer,msg.Buffer,msg.Length);
1487 i=7; 1491 i=7;
1488 if (buffer[9]==0x4a && buffer[10]==0x3a) i=8; 1492 if (buffer[9]==0x4a && buffer[10]==0x3a) i=8;
1489 buffer[i]=0x02; 1493 buffer[i]=0x02;
1490 error=GSM_DecodeNokiaRTTLRingtone(Data->Ringtone, buffer+i, msg.Length-i); 1494 error=GSM_DecodeNokiaRTTLRingtone(Data->Ringtone, buffer+i, msg.Length-i);
1491 if (error!=ERR_NONE) return ERR_EMPTY; 1495 if (error!=ERR_NONE) return ERR_EMPTY;
1492 return ERR_NONE; 1496 return ERR_NONE;
1493 case RING_NOKIABINARY: 1497 case RING_NOKIABINARY:
1494 i=8; 1498 i=8;
1495 while (msg.Buffer[i]!=0) { 1499 while (msg.Buffer[i]!=0) {
1496 i++; 1500 i++;
1497 if (i>msg.Length) return ERR_EMPTY; 1501 if (i>msg.Length) return ERR_EMPTY;
1498 } 1502 }
1499 EncodeUnicode(Data->Ringtone->Name,msg.Buffer+8,i-8); 1503 EncodeUnicode(Data->Ringtone->Name,msg.Buffer+8,i-8);
1500 smprintf(s, "Name \"%s\"\n",DecodeUnicodeString(Data->Ringtone->Name)); 1504 smprintf(s, "Name \"%s\"\n",DecodeUnicodeString(Data->Ringtone->Name));
1501 /* Looking for start && end */ 1505 /* Looking for start && end */
1502 end=0;start=0;i=0; 1506 end=0;start=0;i=0;
1503 while (true) { 1507 while (true) {
1504 if (start!=0) { 1508 if (start!=0) {
1505 if (msg.Buffer[i]==0x07 && msg.Buffer[i+1]==0x0b) { 1509 if (msg.Buffer[i]==0x07 && msg.Buffer[i+1]==0x0b) {
1506 end=i+2; break; 1510 end=i+2; break;
1507 } 1511 }
1508 if (msg.Buffer[i]==0x0e && msg.Buffer[i+1]==0x0b) { 1512 if (msg.Buffer[i]==0x0e && msg.Buffer[i+1]==0x0b) {
1509 end=i+2; break; 1513 end=i+2; break;
1510 } 1514 }
1511 } else { 1515 } else {
1512 if (msg.Buffer[i]==0x02 && msg.Buffer[i+1]==0xfc && msg.Buffer[i+2]==0x09) { 1516 if (msg.Buffer[i]==0x02 && msg.Buffer[i+1]==0xfc && msg.Buffer[i+2]==0x09) {
1513 start = i; 1517 start = i;
1514 } 1518 }
1515 } 1519 }
1516 i++; 1520 i++;
1517 if (i==msg.Length-3) return ERR_EMPTY; 1521 if (i==msg.Length-3) return ERR_EMPTY;
1518 } 1522 }
1519 /* Copying frame */ 1523 /* Copying frame */
1520 memcpy(Data->Ringtone->NokiaBinary.Frame,msg.Buffer+start,end-start); 1524 memcpy(Data->Ringtone->NokiaBinary.Frame,msg.Buffer+start,end-start);
1521 Data->Ringtone->NokiaBinary.Length=end-start; 1525 Data->Ringtone->NokiaBinary.Length=end-start;
1522#ifdef DEBUG 1526#ifdef DEBUG
1523 if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) DumpMessage(di.df, di.dl, Data->Ringtone->NokiaBinary.Frame, Data->Ringtone->NokiaBinary.Length); 1527 if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) DumpMessage(di.df, di.dl, Data->Ringtone->NokiaBinary.Frame, Data->Ringtone->NokiaBinary.Length);
1524#endif 1528#endif
1525 return ERR_NONE; 1529 return ERR_NONE;
1526 case RING_MIDI: 1530 case RING_MIDI:
1531 case RING_MMF:
1527 return ERR_NOTSUPPORTED; 1532 return ERR_NOTSUPPORTED;
1528 } 1533 }
1529 smprintf(s, "Ringtone format is %i\n",Data->Ringtone->Format); 1534 smprintf(s, "Ringtone format is %i\n",Data->Ringtone->Format);
1530 break; 1535 break;
1531 default: 1536 default:
1532 smprintf(s, "Invalid location. Too high ?\n"); 1537 smprintf(s, "Invalid location. Too high ?\n");
1533 return ERR_INVALIDLOCATION; 1538 return ERR_INVALIDLOCATION;
1534 } 1539 }
1535 return ERR_UNKNOWNRESPONSE; 1540 return ERR_UNKNOWNRESPONSE;
1536} 1541}
1537 1542
1538static GSM_Error N6110_GetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone) 1543static GSM_Error N6110_GetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone)
1539{ 1544{
1540 GSM_Error error; 1545 GSM_Error error;
1541 unsigned char req[] = {0x00, 0x01, 0x9e, 1546 unsigned char req[] = {0x00, 0x01, 0x9e,
1542 0x00}; /* location */ 1547 0x00}; /* location */
1543 1548
1544 if (PhoneRingtone) return ERR_NOTSUPPORTED; 1549 if (PhoneRingtone) return ERR_NOTSUPPORTED;
1545 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NORING)) return ERR_NOTSUPPORTED; 1550 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NORING)) return ERR_NOTSUPPORTED;
1546 if (Ringtone->Location == 0) return ERR_INVALIDLOCATION; 1551 if (Ringtone->Location == 0) return ERR_INVALIDLOCATION;
1547 1552
1548 if (Ringtone->Format == 0x00) { 1553 if (Ringtone->Format == 0x00) {
1549 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_RING_SM)) { 1554 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_RING_SM)) {
1550 Ringtone->Format = RING_NOTETONE; 1555 Ringtone->Format = RING_NOTETONE;
1551 } else { 1556 } else {
1552 Ringtone->Format = RING_NOKIABINARY; 1557 Ringtone->Format = RING_NOKIABINARY;
1553 } 1558 }
1554 } 1559 }
1555 1560
1556 switch (Ringtone->Format) { 1561 switch (Ringtone->Format) {
1557 case RING_NOTETONE: 1562 case RING_NOTETONE:
1558 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_RING_SM)) return ERR_NOTSUPPORTED; 1563 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_RING_SM)) return ERR_NOTSUPPORTED;
1559 break; 1564 break;
1560 case RING_NOKIABINARY: 1565 case RING_NOKIABINARY:
1561 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_RING_SM)) return ERR_NOTSUPPORTED; 1566 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_RING_SM)) return ERR_NOTSUPPORTED;
1562 break; 1567 break;
1563 case RING_MIDI: 1568 case RING_MIDI:
1569 case RING_MMF:
1564 return ERR_NOTSUPPORTED; 1570 return ERR_NOTSUPPORTED;
1565 } 1571 }
1566 1572
1567 error=DCT3_EnableSecurity (s, 0x01); 1573 error=DCT3_EnableSecurity (s, 0x01);
1568 if (error!=ERR_NONE) return error; 1574 if (error!=ERR_NONE) return error;
1569 1575
1570 req[3]=Ringtone->Location-1; 1576 req[3]=Ringtone->Location-1;
1571 s->Phone.Data.Ringtone=Ringtone; 1577 s->Phone.Data.Ringtone=Ringtone;
1572 smprintf(s, "Getting (binary) ringtone\n"); 1578 smprintf(s, "Getting (binary) ringtone\n");
1573 return GSM_WaitFor (s, req, 4, 0x40, 4, ID_GetRingtone); 1579 return GSM_WaitFor (s, req, 4, 0x40, 4, ID_GetRingtone);
1574} 1580}
1575 1581
1576static GSM_Error N6110_ReplyGetSecurityStatus(GSM_Protocol_Message msg, GSM_StateMachine *s) 1582static GSM_Error N6110_ReplyGetSecurityStatus(GSM_Protocol_Message msg, GSM_StateMachine *s)
1577{ 1583{
1578 *s->Phone.Data.SecurityStatus = msg.Buffer[4]; 1584 *s->Phone.Data.SecurityStatus = msg.Buffer[4];
1579 1585
1580#ifdef DEBUG 1586#ifdef DEBUG
1581 smprintf(s, "Security code status\n"); 1587 smprintf(s, "Security code status\n");
1582 switch(msg.Buffer[4]) { 1588 switch(msg.Buffer[4]) {
1583 case SEC_SecurityCode: smprintf(s, "waiting for Security Code.\n"); break; 1589 case SEC_SecurityCode: smprintf(s, "waiting for Security Code.\n"); break;
1584 case SEC_Pin : smprintf(s, "waiting for PIN.\n"); break; 1590 case SEC_Pin : smprintf(s, "waiting for PIN.\n"); break;
1585 case SEC_Pin2 : smprintf(s, "waiting for PIN2.\n"); break; 1591 case SEC_Pin2 : smprintf(s, "waiting for PIN2.\n"); break;
1586 case SEC_Puk : smprintf(s, "waiting for PUK.\n"); break; 1592 case SEC_Puk : smprintf(s, "waiting for PUK.\n"); break;
1587 case SEC_Puk2 : smprintf(s, "waiting for PUK2.\n"); break; 1593 case SEC_Puk2 : smprintf(s, "waiting for PUK2.\n"); break;
1588 case SEC_None : smprintf(s, "nothing to enter.\n"); break; 1594 case SEC_None : smprintf(s, "nothing to enter.\n"); break;
1589 default : smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]); 1595 default : smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]);
1590 return ERR_UNKNOWNRESPONSE; 1596 return ERR_UNKNOWNRESPONSE;
1591 } 1597 }
1592#endif 1598#endif
1593 return ERR_NONE; 1599 return ERR_NONE;
1594} 1600}
1595 1601
1596static GSM_Error N6110_GetSecurityStatus(GSM_StateMachine *s, GSM_SecurityCodeType *Status) 1602static GSM_Error N6110_GetSecurityStatus(GSM_StateMachine *s, GSM_SecurityCodeType *Status)
1597{ 1603{
1598 unsigned char req[4] = {N6110_FRAME_HEADER, 0x07}; 1604 unsigned char req[4] = {N6110_FRAME_HEADER, 0x07};
1599 1605
1600 s->Phone.Data.SecurityStatus=Status; 1606 s->Phone.Data.SecurityStatus=Status;
1601 smprintf(s, "Getting security code status\n"); 1607 smprintf(s, "Getting security code status\n");
1602 return GSM_WaitFor (s, req, 4, 0x08, 2, ID_GetSecurityStatus); 1608 return GSM_WaitFor (s, req, 4, 0x08, 2, ID_GetSecurityStatus);
1603} 1609}
1604 1610
1605static GSM_Error N6110_ReplyEnterSecurityCode(GSM_Protocol_Message msg, GSM_StateMachine *s) 1611static GSM_Error N6110_ReplyEnterSecurityCode(GSM_Protocol_Message msg, GSM_StateMachine *s)
1606{ 1612{
1607 switch (msg.Buffer[3]) { 1613 switch (msg.Buffer[3]) {
1608 case 0x0b: 1614 case 0x0b:
1609 smprintf(s, "Security code OK\n"); 1615 smprintf(s, "Security code OK\n");
1610 return ERR_NONE; 1616 return ERR_NONE;
1611 case 0x0c: 1617 case 0x0c:
1612 switch (msg.Buffer[4]) { 1618 switch (msg.Buffer[4]) {
1613 case 0x88: 1619 case 0x88:
1614 smprintf(s, "Wrong code\n"); 1620 smprintf(s, "Wrong code\n");
1615 return ERR_SECURITYERROR; 1621 return ERR_SECURITYERROR;
1616 case 0x8b: 1622 case 0x8b:
1617 smprintf(s, "Not required\n"); 1623 smprintf(s, "Not required\n");
1618 return ERR_NONE; 1624 return ERR_NONE;
1619 default: 1625 default:
1620 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]); 1626 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]);
1621 } 1627 }
1622 } 1628 }
1623 return ERR_UNKNOWNRESPONSE; 1629 return ERR_UNKNOWNRESPONSE;
1624} 1630}
1625 1631
1626static GSM_Error N6110_EnterSecurityCode(GSM_StateMachine *s, GSM_SecurityCode Code) 1632static GSM_Error N6110_EnterSecurityCode(GSM_StateMachine *s, GSM_SecurityCode Code)
1627{ 1633{
1628 int len = 0; 1634 int len = 0;
1629 unsigned char req[15] = {N6110_FRAME_HEADER, 0x0a, 1635 unsigned char req[15] = {N6110_FRAME_HEADER, 0x0a,
1630 0x00}; /* Type of code to enter */ 1636 0x00}; /* Type of code to enter */
1631 1637
1632 req[4]=Code.Type; 1638 req[4]=Code.Type;
1633 1639
1634 len = strlen(Code.Code); 1640 len = strlen(Code.Code);
1635 memcpy(req+5,Code.Code,len); 1641 memcpy(req+5,Code.Code,len);
1636 req[5+len]=0x00; 1642 req[5+len]=0x00;
1637 req[6+len]=0x00; 1643 req[6+len]=0x00;
1638 1644
1639 smprintf(s, "Entering security code\n"); 1645 smprintf(s, "Entering security code\n");
1640 return GSM_WaitFor (s, req, 7+len, 0x08, 4, ID_EnterSecurityCode); 1646 return GSM_WaitFor (s, req, 7+len, 0x08, 4, ID_EnterSecurityCode);
1641} 1647}
1642 1648
1643static GSM_Error N6110_ReplyGetSpeedDial(GSM_Protocol_Message msg, GSM_StateMachine *s) 1649static GSM_Error N6110_ReplyGetSpeedDial(GSM_Protocol_Message msg, GSM_StateMachine *s)
1644{ 1650{
1645 GSM_Phone_Data *Data = &s->Phone.Data; 1651 GSM_Phone_Data *Data = &s->Phone.Data;
1646 1652
1647 switch (msg.Buffer[3]) { 1653 switch (msg.Buffer[3]) {
1648 case 0x17: 1654 case 0x17:
1649 smprintf(s, "Speed dial received\n"); 1655 smprintf(s, "Speed dial received\n");
1650 switch (msg.Buffer[4]) { 1656 switch (msg.Buffer[4]) {
1651 case 0x02: 1657 case 0x02:
1652 Data->SpeedDial->MemoryType = MEM_ME; 1658 Data->SpeedDial->MemoryType = MEM_ME;
1653 smprintf(s, "ME "); 1659 smprintf(s, "ME ");
1654 break; 1660 break;
1655 case 0x03: 1661 case 0x03:
1656 Data->SpeedDial->MemoryType = MEM_SM; 1662 Data->SpeedDial->MemoryType = MEM_SM;
1657 smprintf(s, "SIM "); 1663 smprintf(s, "SIM ");
1658 break; 1664 break;
1659 default: 1665 default:
1660 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]); 1666 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]);
1661 return ERR_UNKNOWNRESPONSE; 1667 return ERR_UNKNOWNRESPONSE;
1662 } 1668 }
1663 Data->SpeedDial->MemoryLocation = msg.Buffer[5]; 1669 Data->SpeedDial->MemoryLocation = msg.Buffer[5];
1664 if (msg.Buffer[5] == 0x00) Data->SpeedDial->MemoryLocation = Data->SpeedDial->Location; 1670 if (msg.Buffer[5] == 0x00) Data->SpeedDial->MemoryLocation = Data->SpeedDial->Location;
1665 Data->SpeedDial->MemoryNumberID = 2; 1671 Data->SpeedDial->MemoryNumberID = 2;
1666 smprintf(s, "location %i\n",Data->SpeedDial->MemoryLocation); 1672 smprintf(s, "location %i\n",Data->SpeedDial->MemoryLocation);
1667 return ERR_NONE; 1673 return ERR_NONE;
1668 case 0x18: 1674 case 0x18:
1669 smprintf(s, "Error getting speed dial. Invalid location\n"); 1675 smprintf(s, "Error getting speed dial. Invalid location\n");
1670 return ERR_INVALIDLOCATION; 1676 return ERR_INVALIDLOCATION;
1671 } 1677 }
1672 return ERR_UNKNOWNRESPONSE; 1678 return ERR_UNKNOWNRESPONSE;
1673} 1679}
1674 1680
1675static GSM_Error N6110_GetSpeedDial(GSM_StateMachine *s, GSM_SpeedDial *SpeedDial) 1681static GSM_Error N6110_GetSpeedDial(GSM_StateMachine *s, GSM_SpeedDial *SpeedDial)
1676{ 1682{
1677 unsigned char req[] = {N6110_FRAME_HEADER, 0x16, 1683 unsigned char req[] = {N6110_FRAME_HEADER, 0x16,
1678 0x01}; /* location */ 1684 0x01}; /* location */
1679 1685
1680 req[4] = SpeedDial->Location; 1686 req[4] = SpeedDial->Location;
1681 1687
1682 s->Phone.Data.SpeedDial=SpeedDial; 1688 s->Phone.Data.SpeedDial=SpeedDial;
1683 smprintf(s, "Getting speed dial\n"); 1689 smprintf(s, "Getting speed dial\n");
1684 return GSM_WaitFor (s, req, 5, 0x03, 4, ID_GetSpeedDial); 1690 return GSM_WaitFor (s, req, 5, 0x03, 4, ID_GetSpeedDial);
1685} 1691}
1686 1692
1687static GSM_Error N6110_ReplySendDTMF(GSM_Protocol_Message msg, GSM_StateMachine *s) 1693static GSM_Error N6110_ReplySendDTMF(GSM_Protocol_Message msg, GSM_StateMachine *s)
1688{ 1694{
1689 switch (msg.Buffer[3]) { 1695 switch (msg.Buffer[3]) {
1690 case 0x40: 1696 case 0x40:
1691 smprintf(s, "During sending DTMF\n"); 1697 smprintf(s, "During sending DTMF\n");
1692 return ERR_NONE; 1698 return ERR_NONE;
1693 case 0x51: 1699 case 0x51:
1694 smprintf(s, "DTMF sent OK\n"); 1700 smprintf(s, "DTMF sent OK\n");
1695 return ERR_NONE; 1701 return ERR_NONE;
1696 } 1702 }
1697 return ERR_UNKNOWNRESPONSE; 1703 return ERR_UNKNOWNRESPONSE;
1698} 1704}
1699 1705
1700static GSM_Error N6110_ReplyGetDisplayStatus(GSM_Protocol_Message msg, GSM_StateMachine *s) 1706static GSM_Error N6110_ReplyGetDisplayStatus(GSM_Protocol_Message msg, GSM_StateMachine *s)
1701{ 1707{
1702 int i; 1708 int i;
1703 GSM_Phone_Data *Data = &s->Phone.Data; 1709 GSM_Phone_Data *Data = &s->Phone.Data;
1704 1710
1705 smprintf(s, "Display status received\n"); 1711 smprintf(s, "Display status received\n");
1706 if (Data->RequestID == ID_GetDisplayStatus) Data->DisplayFeatures->Number=0; 1712 if (Data->RequestID == ID_GetDisplayStatus) Data->DisplayFeatures->Number=0;
1707 for (i=0;i<msg.Buffer[4];i++) { 1713 for (i=0;i<msg.Buffer[4];i++) {
1708 if (msg.Buffer[2*i+6] == 0x02) { 1714 if (msg.Buffer[2*i+6] == 0x02) {
1709#ifdef DEBUG 1715#ifdef DEBUG
1710 switch (msg.Buffer[2*i+5]) { 1716 switch (msg.Buffer[2*i+5]) {
1711 case 0x01: smprintf(s, "Call in progress\n"); break; 1717 case 0x01: smprintf(s, "Call in progress\n"); break;
1712 case 0x02: smprintf(s, "Unknown\n"); break; 1718 case 0x02: smprintf(s, "Unknown\n"); break;
1713 case 0x03: smprintf(s, "Unread SMS\n"); break; 1719 case 0x03: smprintf(s, "Unread SMS\n"); break;
1714 case 0x04: smprintf(s, "Voice call\n"); break; 1720 case 0x04: smprintf(s, "Voice call\n"); break;
1715 case 0x05: smprintf(s, "Fax call active\n"); break; 1721 case 0x05: smprintf(s, "Fax call active\n"); break;
1716 case 0x06: smprintf(s, "Data call active\n"); break; 1722 case 0x06: smprintf(s, "Data call active\n"); break;
1717 case 0x07: smprintf(s, "Keyboard lock\n"); break; 1723 case 0x07: smprintf(s, "Keyboard lock\n"); break;
1718 case 0x08: smprintf(s, "SMS storage full\n"); break; 1724 case 0x08: smprintf(s, "SMS storage full\n"); break;
1719 } 1725 }
1720#endif 1726#endif
1721 if (Data->RequestID == ID_GetDisplayStatus) { 1727 if (Data->RequestID == ID_GetDisplayStatus) {
1722 switch (msg.Buffer[2*i+5]) { 1728 switch (msg.Buffer[2*i+5]) {
1723 case 0x01: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_CallActive; 1729 case 0x01: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_CallActive;
1724 break; 1730 break;
1725 case 0x03: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_UnreadSMS; 1731 case 0x03: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_UnreadSMS;
1726 break; 1732 break;
1727 case 0x04: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_VoiceCall; 1733 case 0x04: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_VoiceCall;
1728 break; 1734 break;
1729 case 0x05: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_FaxCall; 1735 case 0x05: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_FaxCall;
1730 break; 1736 break;
1731 case 0x06: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_DataCall; 1737 case 0x06: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_DataCall;
1732 break; 1738 break;
1733 case 0x07: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_KeypadLocked; 1739 case 0x07: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_KeypadLocked;
1734 break; 1740 break;
1735 case 0x08: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_SMSMemoryFull; 1741 case 0x08: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_SMSMemoryFull;
1736 break; 1742 break;
1737 } 1743 }
1738 if (msg.Buffer[2*i+5]!=0x02) Data->DisplayFeatures->Number++; 1744 if (msg.Buffer[2*i+5]!=0x02) Data->DisplayFeatures->Number++;
1739 } 1745 }
1740 } 1746 }
1741 } 1747 }
1742 return ERR_NONE; 1748 return ERR_NONE;
1743} 1749}
1744 1750
1745static GSM_Error N6110_GetDisplayStatus(GSM_StateMachine *s, GSM_DisplayFeatures *features) 1751static GSM_Error N6110_GetDisplayStatus(GSM_StateMachine *s, GSM_DisplayFeatures *features)
1746{ 1752{
1747 unsigned char req[] = {N6110_FRAME_HEADER, 0x51}; 1753 unsigned char req[] = {N6110_FRAME_HEADER, 0x51};
1748 1754
1749 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_DISPSTATUS)) return ERR_NOTSUPPORTED; 1755 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_DISPSTATUS)) return ERR_NOTSUPPORTED;
1750 1756
1751 s->Phone.Data.DisplayFeatures = features; 1757 s->Phone.Data.DisplayFeatures = features;
1752 smprintf(s, "Getting display status\n"); 1758 smprintf(s, "Getting display status\n");
1753 return GSM_WaitFor (s, req, 4, 0x0d, 4, ID_GetDisplayStatus); 1759 return GSM_WaitFor (s, req, 4, 0x0d, 4, ID_GetDisplayStatus);
1754} 1760}
1755 1761
@@ -2254,631 +2260,632 @@ static void Decode3310Subset3(int j, GSM_Protocol_Message msg, GSM_Phone_Data *D
2254 2260
2255 i = j; 2261 i = j;
2256 while (i!=msg.Buffer[23]) { 2262 while (i!=msg.Buffer[23]) {
2257 EncodeWithUnicodeAlphabet(msg.Buffer+24+i,&wc); 2263 EncodeWithUnicodeAlphabet(msg.Buffer+24+i,&wc);
2258 charfound = false; 2264 charfound = false;
2259 if (i!=msg.Buffer[23]-2) { 2265 if (i!=msg.Buffer[23]-2) {
2260 if (msg.Buffer[24+i] ==0xe2 && msg.Buffer[24+i+1]==0x82 && 2266 if (msg.Buffer[24+i] ==0xe2 && msg.Buffer[24+i+1]==0x82 &&
2261 msg.Buffer[24+i+2]==0xac) { 2267 msg.Buffer[24+i+2]==0xac) {
2262 wc = 0x20 * 256 + 0xac; 2268 wc = 0x20 * 256 + 0xac;
2263 i+=2; 2269 i+=2;
2264 charfound = true; 2270 charfound = true;
2265 } 2271 }
2266 } 2272 }
2267 if (i!=msg.Buffer[23]-1 && !charfound) { 2273 if (i!=msg.Buffer[23]-1 && !charfound) {
2268 if (msg.Buffer[24+i]>=0xc2) { 2274 if (msg.Buffer[24+i]>=0xc2) {
2269 wc = DecodeWithUTF8Alphabet(msg.Buffer[24+i],msg.Buffer[24+i+1]); 2275 wc = DecodeWithUTF8Alphabet(msg.Buffer[24+i],msg.Buffer[24+i+1]);
2270 i++; 2276 i++;
2271 } 2277 }
2272 } 2278 }
2273 Entry->Entries[Entry->EntriesNum].Text[len++] = (wc >> 8) & 0xff; 2279 Entry->Entries[Entry->EntriesNum].Text[len++] = (wc >> 8) & 0xff;
2274 Entry->Entries[Entry->EntriesNum].Text[len++] = wc & 0xff; 2280 Entry->Entries[Entry->EntriesNum].Text[len++] = wc & 0xff;
2275 i++; 2281 i++;
2276 } 2282 }
2277 Entry->Entries[Entry->EntriesNum].Text[len++] = 0; 2283 Entry->Entries[Entry->EntriesNum].Text[len++] = 0;
2278 Entry->Entries[Entry->EntriesNum].Text[len++] = 0; 2284 Entry->Entries[Entry->EntriesNum].Text[len++] = 0;
2279} 2285}
2280 2286
2281/* For example: "a with : above" char */ 2287/* For example: "a with : above" char */
2282static void Decode3310Subset2(int j, GSM_Protocol_Message msg, GSM_Phone_Data *Data) 2288static void Decode3310Subset2(int j, GSM_Protocol_Message msg, GSM_Phone_Data *Data)
2283{ 2289{
2284 int len = 0; 2290 int len = 0;
2285 int i; 2291 int i;
2286 GSM_CalendarEntry *Entry = Data->Cal; 2292 GSM_CalendarEntry *Entry = Data->Cal;
2287 2293
2288 i = j; 2294 i = j;
2289 while (i!=msg.Buffer[23]) { 2295 while (i!=msg.Buffer[23]) {
2290 Entry->Entries[Entry->EntriesNum].Text[len++] = 0x00; 2296 Entry->Entries[Entry->EntriesNum].Text[len++] = 0x00;
2291 Entry->Entries[Entry->EntriesNum].Text[len++] = msg.Buffer[24+i]; 2297 Entry->Entries[Entry->EntriesNum].Text[len++] = msg.Buffer[24+i];
2292 i++; 2298 i++;
2293 } 2299 }
2294 Entry->Entries[Entry->EntriesNum].Text[len++] = 0; 2300 Entry->Entries[Entry->EntriesNum].Text[len++] = 0;
2295 Entry->Entries[Entry->EntriesNum].Text[len++] = 0; 2301 Entry->Entries[Entry->EntriesNum].Text[len++] = 0;
2296} 2302}
2297 2303
2298static GSM_Error N6110_ReplyGetNextCalendar(GSM_Protocol_Message msg, GSM_StateMachine *s) 2304static GSM_Error N6110_ReplyGetNextCalendar(GSM_Protocol_Message msg, GSM_StateMachine *s)
2299{ 2305{
2300 int i = 0; 2306 int i = 0;
2301 bool SpecialSubSet = false; 2307 bool SpecialSubSet = false;
2302 GSM_CalendarEntry *Entry = s->Phone.Data.Cal; 2308 GSM_CalendarEntry *Entry = s->Phone.Data.Cal;
2303 2309
2304 switch (msg.Buffer[4]) { 2310 switch (msg.Buffer[4]) {
2305 case 0x01: 2311 case 0x01:
2306 smprintf(s, "Calendar note received\n"); 2312 smprintf(s, "Calendar note received\n");
2307 switch (msg.Buffer[8]) { 2313 switch (msg.Buffer[8]) {
2308 case 0x01: Entry->Type = GSM_CAL_REMINDER; break; 2314 case 0x01: Entry->Type = GSM_CAL_REMINDER; break;
2309 case 0x02: Entry->Type = GSM_CAL_CALL; break; 2315 case 0x02: Entry->Type = GSM_CAL_CALL; break;
2310 case 0x03: Entry->Type = GSM_CAL_MEETING; break; 2316 case 0x03: Entry->Type = GSM_CAL_MEETING; break;
2311 case 0x04: Entry->Type = GSM_CAL_BIRTHDAY; break; 2317 case 0x04: Entry->Type = GSM_CAL_BIRTHDAY; break;
2312 case 0x05: Entry->Type = GSM_CAL_T_ATHL; break; 2318 case 0x05: Entry->Type = GSM_CAL_T_ATHL; break;
2313 case 0x06: Entry->Type = GSM_CAL_T_BALL; break; 2319 case 0x06: Entry->Type = GSM_CAL_T_BALL; break;
2314 case 0x07: Entry->Type = GSM_CAL_T_CYCL; break; 2320 case 0x07: Entry->Type = GSM_CAL_T_CYCL; break;
2315 case 0x08: Entry->Type = GSM_CAL_T_BUDO; break; 2321 case 0x08: Entry->Type = GSM_CAL_T_BUDO; break;
2316 case 0x09: Entry->Type = GSM_CAL_T_DANC; break; 2322 case 0x09: Entry->Type = GSM_CAL_T_DANC; break;
2317 case 0x0a: Entry->Type = GSM_CAL_T_EXTR; break; 2323 case 0x0a: Entry->Type = GSM_CAL_T_EXTR; break;
2318 case 0x0b: Entry->Type = GSM_CAL_T_FOOT; break; 2324 case 0x0b: Entry->Type = GSM_CAL_T_FOOT; break;
2319 case 0x0c: Entry->Type = GSM_CAL_T_GOLF; break; 2325 case 0x0c: Entry->Type = GSM_CAL_T_GOLF; break;
2320 case 0x0d: Entry->Type = GSM_CAL_T_GYM; break; 2326 case 0x0d: Entry->Type = GSM_CAL_T_GYM; break;
2321 case 0x0e: Entry->Type = GSM_CAL_T_HORS; break; 2327 case 0x0e: Entry->Type = GSM_CAL_T_HORS; break;
2322 case 0x0f: Entry->Type = GSM_CAL_T_HOCK; break; 2328 case 0x0f: Entry->Type = GSM_CAL_T_HOCK; break;
2323 case 0x10: Entry->Type = GSM_CAL_T_RACE; break; 2329 case 0x10: Entry->Type = GSM_CAL_T_RACE; break;
2324 case 0x11: Entry->Type = GSM_CAL_T_RUGB; break; 2330 case 0x11: Entry->Type = GSM_CAL_T_RUGB; break;
2325 case 0x12: Entry->Type = GSM_CAL_T_SAIL; break; 2331 case 0x12: Entry->Type = GSM_CAL_T_SAIL; break;
2326 case 0x13: Entry->Type = GSM_CAL_T_STRE; break; 2332 case 0x13: Entry->Type = GSM_CAL_T_STRE; break;
2327 case 0x14: Entry->Type = GSM_CAL_T_SWIM; break; 2333 case 0x14: Entry->Type = GSM_CAL_T_SWIM; break;
2328 case 0x15: Entry->Type = GSM_CAL_T_TENN; break; 2334 case 0x15: Entry->Type = GSM_CAL_T_TENN; break;
2329 case 0x16: Entry->Type = GSM_CAL_T_TRAV; break; 2335 case 0x16: Entry->Type = GSM_CAL_T_TRAV; break;
2330 case 0x17: Entry->Type = GSM_CAL_T_WINT; break; 2336 case 0x17: Entry->Type = GSM_CAL_T_WINT; break;
2331 default : 2337 default :
2332 smprintf(s, "Unknown note type %i\n",msg.Buffer[8]); 2338 smprintf(s, "Unknown note type %i\n",msg.Buffer[8]);
2333 return ERR_UNKNOWNRESPONSE; 2339 return ERR_UNKNOWNRESPONSE;
2334 } 2340 }
2335#ifdef DEBUG 2341#ifdef DEBUG
2336 switch (msg.Buffer[8]) { 2342 switch (msg.Buffer[8]) {
2337 case 0x01: smprintf(s, "Reminder\n"); break; 2343 case 0x01: smprintf(s, "Reminder\n"); break;
2338 case 0x02: smprintf(s, "Call\n"); break; 2344 case 0x02: smprintf(s, "Call\n"); break;
2339 case 0x03: smprintf(s, "Meeting\n"); break; 2345 case 0x03: smprintf(s, "Meeting\n"); break;
2340 case 0x04: smprintf(s, "Birthday\n"); break; 2346 case 0x04: smprintf(s, "Birthday\n"); break;
2341 } 2347 }
2342#endif 2348#endif
2343 Entry->EntriesNum = 0; 2349 Entry->EntriesNum = 0;
2344 2350
2345 NOKIA_DecodeDateTime(s, msg.Buffer+9, &Entry->Entries[0].Date); 2351 NOKIA_DecodeDateTime(s, msg.Buffer+9, &Entry->Entries[0].Date);
2346 smprintf(s, "Time : %02i-%02i-%04i %02i:%02i:%02i\n", 2352 smprintf(s, "Time : %02i-%02i-%04i %02i:%02i:%02i\n",
2347 Entry->Entries[0].Date.Day,Entry->Entries[0].Date.Month,Entry->Entries[0].Date.Year, 2353 Entry->Entries[0].Date.Day,Entry->Entries[0].Date.Month,Entry->Entries[0].Date.Year,
2348 Entry->Entries[0].Date.Hour,Entry->Entries[0].Date.Minute,Entry->Entries[0].Date.Second); 2354 Entry->Entries[0].Date.Hour,Entry->Entries[0].Date.Minute,Entry->Entries[0].Date.Second);
2349 Entry->Entries[0].EntryType = CAL_START_DATETIME; 2355 Entry->Entries[0].EntryType = CAL_START_DATETIME;
2350 Entry->EntriesNum++; 2356 Entry->EntriesNum++;
2351 2357
2352 NOKIA_DecodeDateTime(s, msg.Buffer+16, &Entry->Entries[1].Date); 2358 NOKIA_DecodeDateTime(s, msg.Buffer+16, &Entry->Entries[1].Date);
2353 if (Entry->Entries[1].Date.Year!=0) { 2359 if (Entry->Entries[1].Date.Year!=0) {
2354 smprintf(s, "Alarm : %02i-%02i-%04i %02i:%02i:%02i\n", 2360 smprintf(s, "Alarm : %02i-%02i-%04i %02i:%02i:%02i\n",
2355 Entry->Entries[1].Date.Day,Entry->Entries[1].Date.Month,Entry->Entries[1].Date.Year, 2361 Entry->Entries[1].Date.Day,Entry->Entries[1].Date.Month,Entry->Entries[1].Date.Year,
2356 Entry->Entries[1].Date.Hour,Entry->Entries[1].Date.Minute,Entry->Entries[1].Date.Second); 2362 Entry->Entries[1].Date.Hour,Entry->Entries[1].Date.Minute,Entry->Entries[1].Date.Second);
2357 Entry->Entries[1].EntryType = CAL_ALARM_DATETIME; 2363 Entry->Entries[1].EntryType = CAL_ALARM_DATETIME;
2358 Entry->EntriesNum++; 2364 Entry->EntriesNum++;
2359 } else { 2365 } else {
2360 smprintf(s, "No alarm\n"); 2366 smprintf(s, "No alarm\n");
2361 } 2367 }
2362 2368
2363 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_CAL52) || 2369 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_CAL52) ||
2364 IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_CAL82)) { 2370 IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_CAL82)) {
2365 memcpy(Entry->Entries[Entry->EntriesNum].Text,msg.Buffer+24,msg.Buffer[23]); 2371 memcpy(Entry->Entries[Entry->EntriesNum].Text,msg.Buffer+24,msg.Buffer[23]);
2366 Entry->Entries[Entry->EntriesNum].Text[msg.Buffer[23] ]=0; 2372 Entry->Entries[Entry->EntriesNum].Text[msg.Buffer[23] ]=0;
2367 Entry->Entries[Entry->EntriesNum].Text[msg.Buffer[23]+1]=0; 2373 Entry->Entries[Entry->EntriesNum].Text[msg.Buffer[23]+1]=0;
2368 } else { 2374 } else {
2369 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_CAL33)) { 2375 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_CAL33)) {
2370 /* first char is subset for 33xx and reminders */ 2376 /* first char is subset for 33xx and reminders */
2371 if (Entry->Type == GSM_CAL_REMINDER) { 2377 if (Entry->Type == GSM_CAL_REMINDER) {
2372 i=1; 2378 i=1;
2373 smprintf(s, "Subset %i in reminder note !\n",msg.Buffer[24]); 2379 smprintf(s, "Subset %i in reminder note !\n",msg.Buffer[24]);
2374 } 2380 }
2375 SpecialSubSet = true; 2381 SpecialSubSet = true;
2376 switch (msg.Buffer[24]) { 2382 switch (msg.Buffer[24]) {
2377 case 2 : Decode3310Subset2(i,msg,&s->Phone.Data); break; 2383 case 2 : Decode3310Subset2(i,msg,&s->Phone.Data); break;
2378 case 3 : Decode3310Subset3(i,msg,&s->Phone.Data); break; 2384 case 3 : Decode3310Subset3(i,msg,&s->Phone.Data); break;
2379 default : SpecialSubSet = false; break; 2385 default : SpecialSubSet = false; break;
2380 } 2386 }
2381 } 2387 }
2382 if (!SpecialSubSet) { 2388 if (!SpecialSubSet) {
2383 N6110_EncodeUnicode(s,Entry->Entries[Entry->EntriesNum].Text,msg.Buffer+24+i,msg.Buffer[23]-i); 2389 N6110_EncodeUnicode(s,Entry->Entries[Entry->EntriesNum].Text,msg.Buffer+24+i,msg.Buffer[23]-i);
2384 } 2390 }
2385 } 2391 }
2386 smprintf(s, "Text \"%s\"\n",DecodeUnicodeString(Entry->Entries[Entry->EntriesNum].Text)); 2392 smprintf(s, "Text \"%s\"\n",DecodeUnicodeString(Entry->Entries[Entry->EntriesNum].Text));
2387 if (msg.Buffer[23] != 0x00) { 2393 if (msg.Buffer[23] != 0x00) {
2388 Entry->Entries[Entry->EntriesNum].EntryType = CAL_TEXT; 2394 Entry->Entries[Entry->EntriesNum].EntryType = CAL_TEXT;
2389 Entry->EntriesNum++; 2395 Entry->EntriesNum++;
2390 } 2396 }
2391 2397
2392 if (Entry->Type == GSM_CAL_CALL) { 2398 if (Entry->Type == GSM_CAL_CALL) {
2393 EncodeUnicode(Entry->Entries[Entry->EntriesNum].Text,msg.Buffer+24+msg.Buffer[23]+1,msg.Buffer[24+msg.Buffer[23]]); 2399 EncodeUnicode(Entry->Entries[Entry->EntriesNum].Text,msg.Buffer+24+msg.Buffer[23]+1,msg.Buffer[24+msg.Buffer[23]]);
2394 smprintf(s, "Phone : \"%s\"\n",DecodeUnicodeString(Entry->Entries[Entry->EntriesNum].Text)); 2400 smprintf(s, "Phone : \"%s\"\n",DecodeUnicodeString(Entry->Entries[Entry->EntriesNum].Text));
2395 if (msg.Buffer[24+msg.Buffer[23]] != 0x00) { 2401 if (msg.Buffer[24+msg.Buffer[23]] != 0x00) {
2396 Entry->Entries[Entry->EntriesNum].EntryType = CAL_PHONE; 2402 Entry->Entries[Entry->EntriesNum].EntryType = CAL_PHONE;
2397 Entry->EntriesNum++; 2403 Entry->EntriesNum++;
2398 } 2404 }
2399 } 2405 }
2400 return ERR_NONE; 2406 return ERR_NONE;
2401 case 0x93: 2407 case 0x93:
2402 smprintf(s, "Can't get calendar note - too high location?\n"); 2408 smprintf(s, "Can't get calendar note - too high location?\n");
2403 return ERR_INVALIDLOCATION; 2409 return ERR_INVALIDLOCATION;
2404 } 2410 }
2405 return ERR_UNKNOWNRESPONSE; 2411 return ERR_UNKNOWNRESPONSE;
2406} 2412}
2407 2413
2408static GSM_Error N6110_GetNextCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start) 2414static GSM_Error N6110_GetNextCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start)
2409{ 2415{
2410 int Text, Time, Alarm, Phone, Recurrance, EndTime, Location; 2416 int Text, Time, Alarm, Phone, Recurrance, EndTime, Location;
2411 GSM_Error error; 2417 GSM_Error error;
2412 GSM_DateTime date_time; 2418 GSM_DateTime date_time;
2413 GSM_Phone_N6110Data *Priv = &s->Phone.Data.Priv.N6110; 2419 GSM_Phone_N6110Data *Priv = &s->Phone.Data.Priv.N6110;
2414 unsigned char req[] = {N6110_FRAME_HEADER, 0x66, 2420 unsigned char req[] = {N6110_FRAME_HEADER, 0x66,
2415 0x00}; /* Location */ 2421 0x00}; /* Location */
2416 2422
2417 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOCALENDAR)) return ERR_NOTSUPPORTED; 2423 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOCALENDAR)) return ERR_NOTSUPPORTED;
2418 2424
2419 if (start) { 2425 if (start) {
2420 Priv->LastCalendarPos = 1; 2426 Priv->LastCalendarPos = 1;
2421 } else { 2427 } else {
2422 Priv->LastCalendarPos++; 2428 Priv->LastCalendarPos++;
2423 } 2429 }
2424 2430
2425 Note->Location = Priv->LastCalendarPos; 2431 Note->Location = Priv->LastCalendarPos;
2426 req[4] = Priv->LastCalendarPos; 2432 req[4] = Priv->LastCalendarPos;
2427 2433
2428 s->Phone.Data.Cal=Note; 2434 s->Phone.Data.Cal=Note;
2429 smprintf(s, "Getting calendar note\n"); 2435 smprintf(s, "Getting calendar note\n");
2430 error=GSM_WaitFor (s, req, 5, 0x13, 4, ID_GetCalendarNote); 2436 error=GSM_WaitFor (s, req, 5, 0x13, 4, ID_GetCalendarNote);
2431 2437
2432 GSM_CalendarFindDefaultTextTimeAlarmPhoneRecurrance(Note, &Text, &Time, &Alarm, &Phone, &Recurrance, &EndTime, &Location); 2438 GSM_CalendarFindDefaultTextTimeAlarmPhoneRecurrance(Note, &Text, &Time, &Alarm, &Phone, &Recurrance, &EndTime, &Location);
2433 /* 2090 year is set for example in 3310 */ 2439 /* 2090 year is set for example in 3310 */
2434 if (error == ERR_NONE && Note->Entries[Time].Date.Year == 2090) { 2440 if (error == ERR_NONE && Note->Entries[Time].Date.Year == 2090) {
2435 error=N6110_GetDateTime(s, &date_time); 2441 error=N6110_GetDateTime(s, &date_time);
2436 if (error == ERR_NONE) Note->Entries[Time].Date.Year = date_time.Year; 2442 if (error == ERR_NONE) Note->Entries[Time].Date.Year = date_time.Year;
2437 } 2443 }
2438 return error; 2444 return error;
2439} 2445}
2440 2446
2441GSM_Error N6110_ReplyUSSDInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 2447GSM_Error N6110_ReplyUSSDInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
2442{ 2448{
2443 unsigned char buffer[2000],buffer2[4000]; 2449 unsigned char buffer[2000],buffer2[4000];
2444 int tmp; 2450 int tmp;
2445 2451
2446 tmp=GSM_UnpackEightBitsToSeven(0, 82, 82, msg.Buffer+8, buffer); 2452 tmp=GSM_UnpackEightBitsToSeven(0, msg.Buffer[7], 82, msg.Buffer+8, buffer);
2447 msg.Buffer[tmp] = 0; 2453 buffer[tmp] = 0;
2448 2454
2449 smprintf(s, "USSD reply: \"%s\"\n",buffer); 2455 smprintf(s, "USSD reply: \"%s\"\n",buffer);
2450 2456
2451 if (s->Phone.Data.EnableIncomingUSSD && s->User.IncomingUSSD!=NULL) { 2457 if (s->Phone.Data.EnableIncomingUSSD && s->User.IncomingUSSD!=NULL) {
2452 EncodeUnicode(buffer2,buffer,strlen(buffer)); 2458 EncodeUnicode(buffer2,buffer,strlen(buffer));
2453 s->User.IncomingUSSD(s->CurrentConfig->Device, buffer2); 2459 s->User.IncomingUSSD(s->CurrentConfig->Device, buffer2);
2454 } 2460 }
2455 2461
2456 return ERR_NONE; 2462 return ERR_NONE;
2457} 2463}
2458 2464
2459GSM_Error N6110_AnswerCall(GSM_StateMachine *s, int ID, bool all) 2465GSM_Error N6110_AnswerCall(GSM_StateMachine *s, int ID, bool all)
2460{ 2466{
2461 GSM_Error error; 2467 GSM_Error error;
2462 unsigned char req1[] = {N6110_FRAME_HEADER, 0x42, 0x05, 0x01, 2468 unsigned char req1[] = {N6110_FRAME_HEADER, 0x42, 0x05, 0x01,
2463 0x07, 0xa2, 0x88, 0x81, 0x21, 0x15, 0x63, 0xa8, 2469 0x07, 0xa2, 0x88, 0x81, 0x21, 0x15, 0x63, 0xa8,
2464 0x00, 0x00, 0x07, 0xa3, 0xb8, 0x81, 0x20, 0x15, 2470 0x00, 0x00, 0x07, 0xa3, 0xb8, 0x81, 0x20, 0x15,
2465 0x63, 0x80}; 2471 0x63, 0x80};
2466 2472
2467 if (!all) { 2473 if (!all) {
2468 smprintf(s, "Answering call part 1\n"); 2474 smprintf(s, "Answering call part 1\n");
2469 error = GSM_WaitFor (s, req1, 24, 0x01, 5, ID_AnswerCall); 2475 error = GSM_WaitFor (s, req1, 24, 0x01, 5, ID_AnswerCall);
2470 if (error != ERR_NONE) return error; 2476 if (error != ERR_NONE) return error;
2471 return DCT3DCT4_AnswerCall(s,ID); 2477 return DCT3DCT4_AnswerCall(s,ID);
2472 } 2478 }
2473 2479
2474 return DCT3_AnswerAllCalls(s); 2480 return DCT3_AnswerAllCalls(s);
2475} 2481}
2476 2482
2477static GSM_Error N6110_DialVoice(GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber) 2483static GSM_Error N6110_DialVoice(GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber)
2478{ 2484{
2479 unsigned int pos = 4; 2485 unsigned int pos = 4;
2480 unsigned char req[100] = {N6110_FRAME_HEADER,0x01, 2486 unsigned char req[100] = {N6110_FRAME_HEADER,0x01,
2481 0x0c}; /* Length of number */ 2487 0x0c}; /* Length of number */
2482 2488
2483 if (ShowNumber == GSM_CALL_DefaultNumberPresence) return DCT3_DialVoice(s,number,ShowNumber); 2489 if (ShowNumber == GSM_CALL_DefaultNumberPresence) return DCT3_DialVoice(s,number,ShowNumber);
2484 2490
2485 req[pos++] = strlen(number); 2491 req[pos++] = strlen(number);
2486 memcpy(req+pos,number,strlen(number)); 2492 memcpy(req+pos,number,strlen(number));
2487 pos += strlen(number); 2493 pos += strlen(number);
2488 req[pos++] = 0x05; /* call type: voice - 0x05, data - 0x01 */ 2494 req[pos++] = 0x05; /* call type: voice - 0x05, data - 0x01 */
2489 req[pos++] = 0x01; 2495 req[pos++] = 0x01;
2490 req[pos++] = 0x01; 2496 req[pos++] = 0x01;
2491 req[pos++] = 0x05; 2497 req[pos++] = 0x05;
2492 req[pos++] = 0x81; 2498 req[pos++] = 0x81;
2493 switch (ShowNumber) { 2499 switch (ShowNumber) {
2494 case GSM_CALL_HideNumber: 2500 case GSM_CALL_HideNumber:
2495 req[pos++] = 0x02; 2501 req[pos++] = 0x02;
2496 break; 2502 break;
2497 case GSM_CALL_ShowNumber: 2503 case GSM_CALL_ShowNumber:
2498 req[pos++] = 0x03; 2504 req[pos++] = 0x03;
2499 break; 2505 break;
2500 case GSM_CALL_DefaultNumberPresence: 2506 case GSM_CALL_DefaultNumberPresence:
2501 req[pos++] = 0x01; 2507 req[pos++] = 0x01;
2502 break; 2508 break;
2503 } 2509 }
2504 req[pos++] = 0x00; 2510 req[pos++] = 0x00;
2505 req[pos++] = 0x00; 2511 req[pos++] = 0x00;
2506 2512
2507 smprintf(s, "Making voice call\n"); 2513 smprintf(s, "Making voice call\n");
2508 return GSM_WaitFor (s, req, pos, 0x01, 4, ID_DialVoice); 2514 return GSM_WaitFor (s, req, pos, 0x01, 4, ID_DialVoice);
2509} 2515}
2510 2516
2511GSM_Error N6110_UnholdCall(GSM_StateMachine *s, int ID) 2517GSM_Error N6110_UnholdCall(GSM_StateMachine *s, int ID)
2512{ 2518{
2513 unsigned char req[] = {N6110_FRAME_HEADER, 0x24, 0x00, 0x02}; 2519 unsigned char req[] = {N6110_FRAME_HEADER, 0x24, 0x00, 0x02};
2514 2520
2515 req[4] = (unsigned char)ID; 2521 req[4] = (unsigned char)ID;
2516 s->Phone.Data.CallID = ID; 2522 s->Phone.Data.CallID = ID;
2517 2523
2518 smprintf(s, "Unholding call\n"); 2524 smprintf(s, "Unholding call\n");
2519 return GSM_WaitFor (s, req, 6, 0x01, 4, ID_UnholdCall); 2525 return GSM_WaitFor (s, req, 6, 0x01, 4, ID_UnholdCall);
2520} 2526}
2521 2527
2522GSM_Error N6110_HoldCall(GSM_StateMachine *s, int ID) 2528GSM_Error N6110_HoldCall(GSM_StateMachine *s, int ID)
2523{ 2529{
2524 unsigned char req[] = {N6110_FRAME_HEADER, 0x22, 0x00, 0x00}; 2530 unsigned char req[] = {N6110_FRAME_HEADER, 0x22, 0x00, 0x00};
2525 2531
2526 req[4] = (unsigned char)ID; 2532 req[4] = (unsigned char)ID;
2527 s->Phone.Data.CallID = ID; 2533 s->Phone.Data.CallID = ID;
2528 2534
2529 smprintf(s, "Unholding call\n"); 2535 smprintf(s, "Unholding call\n");
2530 return GSM_WaitFor (s, req, 6, 0x01, 4, ID_HoldCall); 2536 return GSM_WaitFor (s, req, 6, 0x01, 4, ID_HoldCall);
2531} 2537}
2532 2538
2533/* Joining selected call to current (and making conference) */ 2539/* Joining selected call to current (and making conference) */
2534GSM_Error N6110_ConferenceCall(GSM_StateMachine *s, int ID) 2540GSM_Error N6110_ConferenceCall(GSM_StateMachine *s, int ID)
2535{ 2541{
2536 unsigned char req[] = {N6110_FRAME_HEADER, 0x28, 0x00, 0x01}; 2542 unsigned char req[] = {N6110_FRAME_HEADER, 0x28, 0x00, 0x01};
2537 2543
2538 req[4] = (unsigned char)ID; 2544 req[4] = (unsigned char)ID;
2539 s->Phone.Data.CallID = ID; 2545 s->Phone.Data.CallID = ID;
2540 2546
2541 smprintf(s, "Conference call\n"); 2547 smprintf(s, "Conference call\n");
2542 return GSM_WaitFor (s, req, 6, 0x01, 4, ID_ConferenceCall); 2548 return GSM_WaitFor (s, req, 6, 0x01, 4, ID_ConferenceCall);
2543} 2549}
2544 2550
2545/* Removing selected call from conference and making private call with it 2551/* Removing selected call from conference and making private call with it
2546 * (conference call is on hold) */ 2552 * (conference call is on hold) */
2547GSM_Error N6110_SplitCall(GSM_StateMachine *s, int ID) 2553GSM_Error N6110_SplitCall(GSM_StateMachine *s, int ID)
2548{ 2554{
2549 unsigned char req[] = {N6110_FRAME_HEADER, 0x2A, 0x00, 0x01}; 2555 unsigned char req[] = {N6110_FRAME_HEADER, 0x2A, 0x00, 0x01};
2550 2556
2551 req[4] = (unsigned char)ID; 2557 req[4] = (unsigned char)ID;
2552 s->Phone.Data.CallID = ID; 2558 s->Phone.Data.CallID = ID;
2553 2559
2554 smprintf(s, "Split call\n"); 2560 smprintf(s, "Split call\n");
2555 return GSM_WaitFor (s, req, 6, 0x01, 4, ID_SplitCall); 2561 return GSM_WaitFor (s, req, 6, 0x01, 4, ID_SplitCall);
2556} 2562}
2557 2563
2558/* This probably need more investigation */ 2564/* This probably need more investigation */
2559GSM_Error N6110_SwitchCall(GSM_StateMachine *s, int ID, bool next) 2565GSM_Error N6110_SwitchCall(GSM_StateMachine *s, int ID, bool next)
2560{ 2566{
2561// unsigned char req[] = {N6110_FRAME_HEADER, 0x20}; calls info 2567// unsigned char req[] = {N6110_FRAME_HEADER, 0x20}; calls info
2562 unsigned char req[] = {N6110_FRAME_HEADER, 0x26, 0x00}; 2568 unsigned char req[] = {N6110_FRAME_HEADER, 0x26, 0x00};
2563 2569
2564 s->Phone.Data.CallID = ID; 2570 s->Phone.Data.CallID = ID;
2565 2571
2566 if (next) { 2572 if (next) {
2567 smprintf(s, "Switch call\n"); 2573 smprintf(s, "Switch call\n");
2568 return GSM_WaitFor (s, req, 4, 0x01, 4, ID_SwitchCall); 2574 return GSM_WaitFor (s, req, 4, 0x01, 4, ID_SwitchCall);
2569 } else { 2575 } else {
2570 req[4] = (unsigned char)ID; 2576 req[4] = (unsigned char)ID;
2571 2577
2572 smprintf(s, "Switch call\n"); 2578 smprintf(s, "Switch call\n");
2573 return GSM_WaitFor (s, req, 5, 0x01, 4, ID_SwitchCall); 2579 return GSM_WaitFor (s, req, 5, 0x01, 4, ID_SwitchCall);
2574 } 2580 }
2575} 2581}
2576 2582
2577/* This probably need more investigation */ 2583/* This probably need more investigation */
2578GSM_Error N6110_TransferCall(GSM_StateMachine *s, int ID, bool next) 2584GSM_Error N6110_TransferCall(GSM_StateMachine *s, int ID, bool next)
2579{ 2585{
2580 unsigned char req[] = {N6110_FRAME_HEADER, 0x2C, 0x00}; 2586 unsigned char req[] = {N6110_FRAME_HEADER, 0x2C, 0x00};
2581 2587
2582 s->Phone.Data.CallID = ID; 2588 s->Phone.Data.CallID = ID;
2583 2589
2584 if (next) { 2590 if (next) {
2585 smprintf(s, "Transfer call\n"); 2591 smprintf(s, "Transfer call\n");
2586 return GSM_WaitFor (s, req, 4, 0x01, 4, ID_TransferCall); 2592 return GSM_WaitFor (s, req, 4, 0x01, 4, ID_TransferCall);
2587 } else { 2593 } else {
2588 req[4] = (unsigned char)ID; 2594 req[4] = (unsigned char)ID;
2589 2595
2590 smprintf(s, "Transfer call\n"); 2596 smprintf(s, "Transfer call\n");
2591 return GSM_WaitFor (s, req, 5, 0x01, 4, ID_TransferCall); 2597 return GSM_WaitFor (s, req, 5, 0x01, 4, ID_TransferCall);
2592 } 2598 }
2593} 2599}
2594 2600
2595static GSM_Reply_Function N6110ReplyFunctions[] = { 2601static GSM_Reply_Function N6110ReplyFunctions[] = {
2596 {N6110_ReplyCallInfo, "\x01",0x03,0x02,ID_IncomingFrame }, 2602 {N6110_ReplyCallInfo, "\x01",0x03,0x02,ID_IncomingFrame },
2597 {N6110_ReplyCallInfo, "\x01",0x03,0x03,ID_IncomingFrame }, 2603 {N6110_ReplyCallInfo, "\x01",0x03,0x03,ID_IncomingFrame },
2598 {N6110_ReplyCallInfo, "\x01",0x03,0x04,ID_IncomingFrame }, 2604 {N6110_ReplyCallInfo, "\x01",0x03,0x04,ID_IncomingFrame },
2599 {N6110_ReplyCallInfo, "\x01",0x03,0x05,ID_IncomingFrame }, 2605 {N6110_ReplyCallInfo, "\x01",0x03,0x05,ID_IncomingFrame },
2600 {N6110_ReplyCallInfo, "\x01",0x03,0x07,ID_AnswerCall }, 2606 {N6110_ReplyCallInfo, "\x01",0x03,0x07,ID_AnswerCall },
2601 {N6110_ReplyCallInfo, "\x01",0x03,0x07,ID_IncomingFrame }, 2607 {N6110_ReplyCallInfo, "\x01",0x03,0x07,ID_IncomingFrame },
2602 {N6110_ReplyCallInfo, "\x01",0x03,0x09,ID_CancelCall }, 2608 {N6110_ReplyCallInfo, "\x01",0x03,0x09,ID_CancelCall },
2603 {N6110_ReplyCallInfo, "\x01",0x03,0x09,ID_IncomingFrame }, 2609 {N6110_ReplyCallInfo, "\x01",0x03,0x09,ID_IncomingFrame },
2604 {N6110_ReplyCallInfo, "\x01",0x03,0x0A,ID_IncomingFrame }, 2610 {N6110_ReplyCallInfo, "\x01",0x03,0x0A,ID_IncomingFrame },
2605 {N6110_ReplyCallInfo, "\x01",0x03,0x23,ID_HoldCall }, 2611 {N6110_ReplyCallInfo, "\x01",0x03,0x23,ID_HoldCall },
2606 {N6110_ReplyCallInfo, "\x01",0x03,0x23,ID_IncomingFrame }, 2612 {N6110_ReplyCallInfo, "\x01",0x03,0x23,ID_IncomingFrame },
2607 {N6110_ReplyCallInfo, "\x01",0x03,0x25,ID_UnholdCall }, 2613 {N6110_ReplyCallInfo, "\x01",0x03,0x25,ID_UnholdCall },
2608 {N6110_ReplyCallInfo, "\x01",0x03,0x25,ID_IncomingFrame }, 2614 {N6110_ReplyCallInfo, "\x01",0x03,0x25,ID_IncomingFrame },
2609 {N6110_ReplyCallInfo, "\x01",0x03,0x27,ID_IncomingFrame }, 2615 {N6110_ReplyCallInfo, "\x01",0x03,0x27,ID_IncomingFrame },
2610 {N6110_ReplyCallInfo, "\x01",0x03,0x29,ID_ConferenceCall }, 2616 {N6110_ReplyCallInfo, "\x01",0x03,0x29,ID_ConferenceCall },
2611 {N6110_ReplyCallInfo, "\x01",0x03,0x29,ID_IncomingFrame }, 2617 {N6110_ReplyCallInfo, "\x01",0x03,0x29,ID_IncomingFrame },
2612 {N6110_ReplyCallInfo, "\x01",0x03,0x2B,ID_SplitCall }, 2618 {N6110_ReplyCallInfo, "\x01",0x03,0x2B,ID_SplitCall },
2613 {N6110_ReplyCallInfo, "\x01",0x03,0x2B,ID_IncomingFrame }, 2619 {N6110_ReplyCallInfo, "\x01",0x03,0x2B,ID_IncomingFrame },
2614 {N6110_ReplySendDTMF, "\x01",0x03,0x40,ID_SendDTMF }, 2620 {N6110_ReplySendDTMF, "\x01",0x03,0x40,ID_SendDTMF },
2615 {NoneReply, "\x01",0x03,0x40,ID_DialVoice }, 2621 {NoneReply, "\x01",0x03,0x40,ID_DialVoice },
2616 {NoneReply, "\x01",0x03,0x40,ID_IncomingFrame }, 2622 {NoneReply, "\x01",0x03,0x40,ID_IncomingFrame },
2617 {NoneReply, "\x01",0x03,0x43,ID_AnswerCall }, 2623 {NoneReply, "\x01",0x03,0x43,ID_AnswerCall },
2618 {N6110_ReplySendDTMF, "\x01",0x03,0x51,ID_SendDTMF }, 2624 {N6110_ReplySendDTMF, "\x01",0x03,0x51,ID_SendDTMF },
2619 2625
2620 {DCT3_ReplySendSMSMessage, "\x02",0x03,0x02,ID_IncomingFrame }, 2626 {DCT3_ReplySendSMSMessage, "\x02",0x03,0x02,ID_IncomingFrame },
2621 {DCT3_ReplySendSMSMessage, "\x02",0x03,0x03,ID_IncomingFrame }, 2627 {DCT3_ReplySendSMSMessage, "\x02",0x03,0x03,ID_IncomingFrame },
2622 {N6110_ReplyIncomingSMS, "\x02",0x03,0x10,ID_IncomingFrame }, 2628 {N6110_ReplyIncomingSMS, "\x02",0x03,0x10,ID_IncomingFrame },
2623#ifdef GSM_ENABLE_CELLBROADCAST 2629#ifdef GSM_ENABLE_CELLBROADCAST
2624 {DCT3_ReplySetIncomingCB, "\x02",0x03,0x21,ID_SetIncomingCB }, 2630 {DCT3_ReplySetIncomingCB, "\x02",0x03,0x21,ID_SetIncomingCB },
2625 {DCT3_ReplySetIncomingCB, "\x02",0x03,0x22,ID_SetIncomingCB }, 2631 {DCT3_ReplySetIncomingCB, "\x02",0x03,0x22,ID_SetIncomingCB },
2626 {DCT3_ReplyIncomingCB, "\x02",0x03,0x23,ID_IncomingFrame }, 2632 {DCT3_ReplyIncomingCB, "\x02",0x03,0x23,ID_IncomingFrame },
2627#endif 2633#endif
2628 {DCT3_ReplySetSMSC, "\x02",0x03,0x31,ID_SetSMSC }, 2634 {DCT3_ReplySetSMSC, "\x02",0x03,0x31,ID_SetSMSC },
2629 {DCT3_ReplyGetSMSC, "\x02",0x03,0x34,ID_GetSMSC }, 2635 {DCT3_ReplyGetSMSC, "\x02",0x03,0x34,ID_GetSMSC },
2630 {DCT3_ReplyGetSMSC, "\x02",0x03,0x35,ID_GetSMSC }, 2636 {DCT3_ReplyGetSMSC, "\x02",0x03,0x35,ID_GetSMSC },
2631 2637
2632 {N6110_ReplyGetMemory, "\x03",0x03,0x02,ID_GetMemory }, 2638 {N6110_ReplyGetMemory, "\x03",0x03,0x02,ID_GetMemory },
2633 {N6110_ReplyGetMemory, "\x03",0x03,0x03,ID_GetMemory }, 2639 {N6110_ReplyGetMemory, "\x03",0x03,0x03,ID_GetMemory },
2634 {N6110_ReplySetMemory, "\x03",0x03,0x05,ID_SetMemory }, 2640 {N6110_ReplySetMemory, "\x03",0x03,0x05,ID_SetMemory },
2635 {N6110_ReplySetMemory, "\x03",0x03,0x06,ID_SetMemory }, 2641 {N6110_ReplySetMemory, "\x03",0x03,0x06,ID_SetMemory },
2636 {N6110_ReplyGetMemoryStatus, "\x03",0x03,0x08,ID_GetMemoryStatus }, 2642 {N6110_ReplyGetMemoryStatus, "\x03",0x03,0x08,ID_GetMemoryStatus },
2637 {N6110_ReplyGetMemoryStatus, "\x03",0x03,0x09,ID_GetMemoryStatus }, 2643 {N6110_ReplyGetMemoryStatus, "\x03",0x03,0x09,ID_GetMemoryStatus },
2638 {N6110_ReplyGetCallerLogo, "\x03",0x03,0x11,ID_GetBitmap }, 2644 {N6110_ReplyGetCallerLogo, "\x03",0x03,0x11,ID_GetBitmap },
2639 {N6110_ReplyGetCallerLogo, "\x03",0x03,0x12,ID_GetBitmap }, 2645 {N6110_ReplyGetCallerLogo, "\x03",0x03,0x12,ID_GetBitmap },
2640 {N6110_ReplySetCallerLogo, "\x03",0x03,0x14,ID_SetBitmap }, 2646 {N6110_ReplySetCallerLogo, "\x03",0x03,0x14,ID_SetBitmap },
2641 {N6110_ReplySetCallerLogo, "\x03",0x03,0x15,ID_SetBitmap }, 2647 {N6110_ReplySetCallerLogo, "\x03",0x03,0x15,ID_SetBitmap },
2642 {N6110_ReplyGetSpeedDial, "\x03",0x03,0x17,ID_GetSpeedDial }, 2648 {N6110_ReplyGetSpeedDial, "\x03",0x03,0x17,ID_GetSpeedDial },
2643 {N6110_ReplyGetSpeedDial, "\x03",0x03,0x18,ID_GetSpeedDial }, 2649 {N6110_ReplyGetSpeedDial, "\x03",0x03,0x18,ID_GetSpeedDial },
2644 /* 0x1A, 0x1B - reply set speed dial */ 2650 /* 0x1A, 0x1B - reply set speed dial */
2645 2651
2646 {N6110_ReplyGetStatus, "\x04",0x03,0x02,ID_GetSignalQuality }, 2652 {N6110_ReplyGetStatus, "\x04",0x03,0x02,ID_GetSignalQuality },
2647 {N6110_ReplyGetStatus, "\x04",0x03,0x02,ID_GetBatteryCharge }, 2653 {N6110_ReplyGetStatus, "\x04",0x03,0x02,ID_GetBatteryCharge },
2648 2654
2649 {N6110_ReplySetProfileFeature, "\x05",0x03,0x11,ID_SetProfile }, 2655 {N6110_ReplySetProfileFeature, "\x05",0x03,0x11,ID_SetProfile },
2650 {N6110_ReplySetProfileFeature, "\x05",0x03,0x12,ID_SetProfile }, 2656 {N6110_ReplySetProfileFeature, "\x05",0x03,0x12,ID_SetProfile },
2651 {N6110_ReplyGetProfileFeature, "\x05",0x03,0x14,ID_GetProfile }, 2657 {N6110_ReplyGetProfileFeature, "\x05",0x03,0x14,ID_GetProfile },
2652 {N6110_ReplyGetPhoneLanguage, "\x05",0x03,0x14,ID_GetLanguage }, 2658 {N6110_ReplyGetPhoneLanguage, "\x05",0x03,0x14,ID_GetLanguage },
2653 {N6110_ReplyGetProfileFeature, "\x05",0x03,0x15,ID_GetProfile }, 2659 {N6110_ReplyGetProfileFeature, "\x05",0x03,0x15,ID_GetProfile },
2654 {N6110_ReplyGetPhoneLanguage, "\x05",0x03,0x15,ID_GetLanguage }, 2660 {N6110_ReplyGetPhoneLanguage, "\x05",0x03,0x15,ID_GetLanguage },
2655 {N6110_ReplyGetStartup, "\x05",0x03,0x17,ID_GetBitmap }, 2661 {N6110_ReplyGetStartup, "\x05",0x03,0x17,ID_GetBitmap },
2656 {N6110_ReplySetStartup, "\x05",0x03,0x19,ID_SetBitmap }, 2662 {N6110_ReplySetStartup, "\x05",0x03,0x19,ID_SetBitmap },
2657 {N6110_ReplyGetProfileFeature, "\x05",0x03,0x1b,ID_GetProfile }, 2663 {N6110_ReplyGetProfileFeature, "\x05",0x03,0x1b,ID_GetProfile },
2658 {N61_91_ReplySetOpLogo, "\x05",0x03,0x31,ID_SetBitmap }, 2664 {N61_91_ReplySetOpLogo, "\x05",0x03,0x31,ID_SetBitmap },
2659 {N61_91_ReplySetOpLogo, "\x05",0x03,0x32,ID_SetBitmap }, 2665 {N61_91_ReplySetOpLogo, "\x05",0x03,0x32,ID_SetBitmap },
2660 {N6110_ReplyGetOpLogo, "\x05",0x03,0x34,ID_GetBitmap }, 2666 {N6110_ReplyGetOpLogo, "\x05",0x03,0x34,ID_GetBitmap },
2661 {N6110_ReplySetRingtone, "\x05",0x03,0x37,ID_SetRingtone }, 2667 {N6110_ReplySetRingtone, "\x05",0x03,0x37,ID_SetRingtone },
2662 {N6110_ReplySetRingtone, "\x05",0x03,0x38,ID_SetRingtone }, 2668 {N6110_ReplySetRingtone, "\x05",0x03,0x38,ID_SetRingtone },
2663 2669
2664 {DCT3DCT4_ReplyCallDivert, "\x06",0x03,0x02,ID_Divert }, 2670 {DCT3DCT4_ReplyCallDivert, "\x06",0x03,0x02,ID_Divert },
2665 {DCT3DCT4_ReplyCallDivert, "\x06",0x03,0x03,ID_Divert }, 2671 {DCT3DCT4_ReplyCallDivert, "\x06",0x03,0x03,ID_Divert },
2666 {N6110_ReplyUSSDInfo, "\x06",0x03,0x05,ID_IncomingFrame }, 2672 {N6110_ReplyUSSDInfo, "\x06",0x03,0x05,ID_IncomingFrame },
2667 {NoneReply, "\x06",0x03,0x06,ID_IncomingFrame },//incoming call divert info 2673 {NoneReply, "\x06",0x03,0x06,ID_IncomingFrame },//incoming call divert info
2668 2674
2669 {N6110_ReplyGetSecurityStatus, "\x08",0x03,0x08,ID_GetSecurityStatus }, 2675 {N6110_ReplyGetSecurityStatus, "\x08",0x03,0x08,ID_GetSecurityStatus },
2670 {N6110_ReplyEnterSecurityCode, "\x08",0x03,0x0b,ID_EnterSecurityCode }, 2676 {N6110_ReplyEnterSecurityCode, "\x08",0x03,0x0b,ID_EnterSecurityCode },
2671 {N6110_ReplyEnterSecurityCode, "\x08",0x03,0x0c,ID_EnterSecurityCode }, 2677 {N6110_ReplyEnterSecurityCode, "\x08",0x03,0x0c,ID_EnterSecurityCode },
2672 2678
2673 {DCT3_ReplySIMLogin, "\x09",0x03,0x80,ID_IncomingFrame }, 2679 {DCT3_ReplySIMLogin, "\x09",0x03,0x80,ID_IncomingFrame },
2674 {DCT3_ReplySIMLogout, "\x09",0x03,0x81,ID_IncomingFrame }, 2680 {DCT3_ReplySIMLogout, "\x09",0x03,0x81,ID_IncomingFrame },
2675 2681
2676 {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_GetNetworkInfo }, 2682 {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_GetNetworkInfo },
2677 {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_IncomingFrame }, 2683 {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_IncomingFrame },
2678 2684
2679 {N6110_ReplyGetDisplayStatus, "\x0D",0x03,0x52,ID_GetDisplayStatus }, 2685 {N6110_ReplyGetDisplayStatus, "\x0D",0x03,0x52,ID_GetDisplayStatus },
2680 {N6110_ReplyGetDisplayStatus, "\x0D",0x03,0x52,ID_IncomingFrame }, 2686 {N6110_ReplyGetDisplayStatus, "\x0D",0x03,0x52,ID_IncomingFrame },
2681 2687
2682 {DCT3_ReplySetDateTime, "\x11",0x03,0x61,ID_SetDateTime }, 2688 {DCT3_ReplySetDateTime, "\x11",0x03,0x61,ID_SetDateTime },
2683 {DCT3_ReplyGetDateTime, "\x11",0x03,0x63,ID_GetDateTime }, 2689 {DCT3_ReplyGetDateTime, "\x11",0x03,0x63,ID_GetDateTime },
2684 {DCT3_ReplySetAlarm, "\x11",0x03,0x6C,ID_SetAlarm }, 2690 {DCT3_ReplySetAlarm, "\x11",0x03,0x6C,ID_SetAlarm },
2685 {DCT3_ReplyGetAlarm, "\x11",0x03,0x6E,ID_GetAlarm }, 2691 {DCT3_ReplyGetAlarm, "\x11",0x03,0x6E,ID_GetAlarm },
2686 2692
2687 {N6110_ReplyAddCalendar, "\x13",0x03,0x65,ID_SetCalendarNote }, 2693 {N6110_ReplyAddCalendar, "\x13",0x03,0x65,ID_SetCalendarNote },
2688 {N6110_ReplyAddCalendar, "\x13",0x03,0x65,ID_IncomingFrame }, 2694 {N6110_ReplyAddCalendar, "\x13",0x03,0x65,ID_IncomingFrame },
2689 {N6110_ReplyGetNextCalendar, "\x13",0x03,0x67,ID_GetCalendarNote }, 2695 {N6110_ReplyGetNextCalendar, "\x13",0x03,0x67,ID_GetCalendarNote },
2690 {N6110_ReplyDeleteCalendar, "\x13",0x03,0x69,ID_DeleteCalendarNote }, 2696 {N6110_ReplyDeleteCalendar, "\x13",0x03,0x69,ID_DeleteCalendarNote },
2691 {N6110_ReplyDeleteCalendar, "\x13",0x03,0x69,ID_IncomingFrame }, 2697 {N6110_ReplyDeleteCalendar, "\x13",0x03,0x69,ID_IncomingFrame },
2692 2698
2693 {N6110_ReplySaveSMSMessage, "\x14",0x03,0x05,ID_SaveSMSMessage }, 2699 {N6110_ReplySaveSMSMessage, "\x14",0x03,0x05,ID_SaveSMSMessage },
2694 {N6110_ReplySaveSMSMessage, "\x14",0x03,0x06,ID_SaveSMSMessage }, 2700 {N6110_ReplySaveSMSMessage, "\x14",0x03,0x06,ID_SaveSMSMessage },
2695 {N6110_ReplyGetSMSMessage, "\x14",0x03,0x08,ID_GetSMSMessage }, 2701 {N6110_ReplyGetSMSMessage, "\x14",0x03,0x08,ID_GetSMSMessage },
2696 {N6110_ReplyGetSMSMessage, "\x14",0x03,0x09,ID_GetSMSMessage }, 2702 {N6110_ReplyGetSMSMessage, "\x14",0x03,0x09,ID_GetSMSMessage },
2697 {DCT3_ReplyDeleteSMSMessage, "\x14",0x03,0x0B,ID_DeleteSMSMessage }, 2703 {DCT3_ReplyDeleteSMSMessage, "\x14",0x03,0x0B,ID_DeleteSMSMessage },
2698 {DCT3_ReplyDeleteSMSMessage, "\x14",0x03,0x0C,ID_DeleteSMSMessage }, 2704 {DCT3_ReplyDeleteSMSMessage, "\x14",0x03,0x0C,ID_DeleteSMSMessage },
2699 {N6110_ReplyGetSMSStatus, "\x14",0x03,0x37,ID_GetSMSStatus }, 2705 {N6110_ReplyGetSMSStatus, "\x14",0x03,0x37,ID_GetSMSStatus },
2700 {N6110_ReplyGetSMSStatus, "\x14",0x03,0x38,ID_GetSMSStatus }, 2706 {N6110_ReplyGetSMSStatus, "\x14",0x03,0x38,ID_GetSMSStatus },
2701 2707
2702 {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x01,ID_EnableConnectFunc }, 2708 {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x01,ID_EnableConnectFunc },
2703 {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x02,ID_EnableConnectFunc }, 2709 {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x02,ID_EnableConnectFunc },
2704 {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x04,ID_DisableConnectFunc }, 2710 {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x04,ID_DisableConnectFunc },
2705 {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x05,ID_DisableConnectFunc }, 2711 {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x05,ID_DisableConnectFunc },
2706 {DCT3_ReplyGetWAPBookmark, "\x3f",0x03,0x07,ID_GetWAPBookmark }, 2712 {DCT3_ReplyGetWAPBookmark, "\x3f",0x03,0x07,ID_GetWAPBookmark },
2707 {DCT3_ReplyGetWAPBookmark, "\x3f",0x03,0x08,ID_GetWAPBookmark }, 2713 {DCT3_ReplyGetWAPBookmark, "\x3f",0x03,0x08,ID_GetWAPBookmark },
2708 {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0A,ID_SetWAPBookmark }, 2714 {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0A,ID_SetWAPBookmark },
2709 {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0B,ID_SetWAPBookmark }, 2715 {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0B,ID_SetWAPBookmark },
2710 {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0D,ID_DeleteWAPBookmark }, 2716 {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0D,ID_DeleteWAPBookmark },
2711 {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0E,ID_DeleteWAPBookmark }, 2717 {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0E,ID_DeleteWAPBookmark },
2712 {DCT3DCT4_ReplyGetActiveConnectSet,"\x3f",0x03,0x10,ID_GetConnectSet }, 2718 {DCT3DCT4_ReplyGetActiveConnectSet,"\x3f",0x03,0x10,ID_GetConnectSet },
2713 {DCT3DCT4_ReplySetActiveConnectSet,"\x3f",0x03,0x13,ID_SetConnectSet }, 2719 {DCT3DCT4_ReplySetActiveConnectSet,"\x3f",0x03,0x13,ID_SetConnectSet },
2714 {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x16,ID_GetConnectSet }, 2720 {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x16,ID_GetConnectSet },
2715 {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x17,ID_GetConnectSet }, 2721 {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x17,ID_GetConnectSet },
2716 {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x19,ID_SetConnectSet }, 2722 {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x19,ID_SetConnectSet },
2717 {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x1A,ID_SetConnectSet }, 2723 {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x1A,ID_SetConnectSet },
2718 {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x1C,ID_GetConnectSet }, 2724 {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x1C,ID_GetConnectSet },
2719 {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x1D,ID_GetConnectSet }, 2725 {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x1D,ID_GetConnectSet },
2720 {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x1F,ID_SetConnectSet }, 2726 {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x1F,ID_SetConnectSet },
2721 2727
2722 {DCT3_ReplyEnableSecurity, "\x40",0x02,0x64,ID_EnableSecurity }, 2728 {DCT3_ReplyEnableSecurity, "\x40",0x02,0x64,ID_EnableSecurity },
2723 {N61_71_ReplyResetPhoneSettings, "\x40",0x02,0x65,ID_ResetPhoneSettings }, 2729 {N61_71_ReplyResetPhoneSettings, "\x40",0x02,0x65,ID_ResetPhoneSettings },
2724 {DCT3_ReplyGetIMEI, "\x40",0x02,0x66,ID_GetIMEI }, 2730 {DCT3_ReplyGetIMEI, "\x40",0x02,0x66,ID_GetIMEI },
2725 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_DialVoice }, 2731 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_DialVoice },
2726 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_CancelCall }, 2732 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_CancelCall },
2727 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_AnswerCall }, 2733 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_AnswerCall },
2728 {DCT3_ReplyNetmonitor, "\x40",0x02,0x7E,ID_Netmonitor }, 2734 {DCT3_ReplyNetmonitor, "\x40",0x02,0x7E,ID_Netmonitor },
2729 {DCT3_ReplyPlayTone, "\x40",0x02,0x8F,ID_PlayTone }, 2735 {DCT3_ReplyPlayTone, "\x40",0x02,0x8F,ID_PlayTone },
2730 {N6110_ReplyGetRingtone, "\x40",0x02,0x9E,ID_GetRingtone }, 2736 {N6110_ReplyGetRingtone, "\x40",0x02,0x9E,ID_GetRingtone },
2731 {N6110_ReplySetBinRingtone, "\x40",0x02,0xA0,ID_SetRingtone }, 2737 {N6110_ReplySetBinRingtone, "\x40",0x02,0xA0,ID_SetRingtone },
2732 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetHardware }, 2738 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetHardware },
2733 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetPPM }, 2739 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetPPM },
2734 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCA,ID_GetProductCode }, 2740 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCA,ID_GetProductCode },
2735 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetManufactureMonth}, 2741 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetManufactureMonth},
2736 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetOriginalIMEI }, 2742 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetOriginalIMEI },
2737 2743
2738 {N6110_ReplyGetSetPicture, "\x47",0x03,0x02,ID_GetBitmap }, 2744 {N6110_ReplyGetSetPicture, "\x47",0x03,0x02,ID_GetBitmap },
2739 {N6110_ReplyGetSetPicture, "\x47",0x03,0x04,ID_SetBitmap }, 2745 {N6110_ReplyGetSetPicture, "\x47",0x03,0x04,ID_SetBitmap },
2740 {N6110_ReplyGetSetPicture, "\x47",0x03,0x05,ID_SetBitmap }, 2746 {N6110_ReplyGetSetPicture, "\x47",0x03,0x05,ID_SetBitmap },
2741 {N6110_ReplyGetSetPicture, "\x47",0x03,0x06,ID_GetBitmap }, 2747 {N6110_ReplyGetSetPicture, "\x47",0x03,0x06,ID_GetBitmap },
2742 2748
2743#ifndef ENABLE_LGPL 2749#ifndef ENABLE_LGPL
2744 {N6110_ReplyGetMagicBytes, "\x64",0x00,0x00,ID_MakeAuthentication }, 2750 {N6110_ReplyGetMagicBytes, "\x64",0x00,0x00,ID_MakeAuthentication },
2745#endif 2751#endif
2746 2752
2747 {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetModel }, 2753 {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetModel },
2748 {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetFirmware }, 2754 {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetFirmware },
2749 {DCT3_ReplyPressKey, "\xD2",0x02,0x46,ID_PressKey }, 2755 {DCT3_ReplyPressKey, "\xD2",0x02,0x46,ID_PressKey },
2750 {DCT3_ReplyPressKey, "\xD2",0x02,0x47,ID_PressKey }, 2756 {DCT3_ReplyPressKey, "\xD2",0x02,0x47,ID_PressKey },
2751 2757
2752 {NULL, "\x00",0x00,0x00,ID_None } 2758 {NULL, "\x00",0x00,0x00,ID_None }
2753}; 2759};
2754 2760
2755GSM_Phone_Functions N6110Phone = { 2761GSM_Phone_Functions N6110Phone = {
2756 "2100|3210|3310|3330|3390|3410|3610|5110|5110i|5130|5190|5210|5510|6110|6130|6150|6190|8210|8250|8290|8850|8855|8890", 2762 "2100|3210|3310|3330|3390|3410|3610|5110|5110i|5130|5190|5210|5510|6110|6130|6150|6190|8210|8250|8290|8850|8855|8890",
2757 N6110ReplyFunctions, 2763 N6110ReplyFunctions,
2758 N6110_Initialise, 2764 N6110_Initialise,
2759 PHONE_Terminate, 2765 PHONE_Terminate,
2760 GSM_DispatchMessage, 2766 GSM_DispatchMessage,
2761 N6110_ShowStartInfo, 2767 N6110_ShowStartInfo,
2762 NOKIA_GetManufacturer, 2768 NOKIA_GetManufacturer,
2763 DCT3DCT4_GetModel, 2769 DCT3DCT4_GetModel,
2764 DCT3DCT4_GetFirmware, 2770 DCT3DCT4_GetFirmware,
2765 DCT3_GetIMEI, 2771 DCT3_GetIMEI,
2766 DCT3_GetOriginalIMEI, 2772 DCT3_GetOriginalIMEI,
2767 DCT3_GetManufactureMonth, 2773 DCT3_GetManufactureMonth,
2768 DCT3_GetProductCode, 2774 DCT3_GetProductCode,
2769 DCT3_GetHardware, 2775 DCT3_GetHardware,
2770 DCT3_GetPPM, 2776 DCT3_GetPPM,
2771 NOTSUPPORTED, /* GetSIMIMSI */ 2777 NOTSUPPORTED, /* GetSIMIMSI */
2772 N6110_GetDateTime, 2778 N6110_GetDateTime,
2773 N6110_SetDateTime, 2779 N6110_SetDateTime,
2774 N6110_GetAlarm, 2780 N6110_GetAlarm,
2775 N6110_SetAlarm, 2781 N6110_SetAlarm,
2776 NOTSUPPORTED, /* GetLocale */ 2782 NOTSUPPORTED, /* GetLocale */
2777 NOTSUPPORTED, /* SetLocale */ 2783 NOTSUPPORTED, /* SetLocale */
2778 DCT3_PressKey, 2784 DCT3_PressKey,
2779 DCT3_Reset, 2785 DCT3_Reset,
2780 N61_71_ResetPhoneSettings, 2786 N61_71_ResetPhoneSettings,
2781 N6110_EnterSecurityCode, 2787 N6110_EnterSecurityCode,
2782 N6110_GetSecurityStatus, 2788 N6110_GetSecurityStatus,
2783 N6110_GetDisplayStatus, 2789 N6110_GetDisplayStatus,
2784 NOTIMPLEMENTED, /* SetAutoNetworkLogin */ 2790 NOTIMPLEMENTED, /* SetAutoNetworkLogin */
2785 N6110_GetBatteryCharge, 2791 N6110_GetBatteryCharge,
2786 N6110_GetSignalQuality, 2792 N6110_GetSignalQuality,
2787 DCT3_GetNetworkInfo, 2793 DCT3_GetNetworkInfo,
2788 NOTSUPPORTED, /* GetCategory */ 2794 NOTSUPPORTED, /* GetCategory */
2789 NOTSUPPORTED, /* AddCategory */ 2795 NOTSUPPORTED, /* AddCategory */
2790 NOTSUPPORTED, /* GetCategoryStatus */ 2796 NOTSUPPORTED, /* GetCategoryStatus */
2791 N6110_GetMemoryStatus, 2797 N6110_GetMemoryStatus,
2792 N6110_GetMemory, 2798 N6110_GetMemory,
2793 NOTIMPLEMENTED, /* GetNextMemory */ 2799 NOTIMPLEMENTED, /* GetNextMemory */
2794 N6110_SetMemory, 2800 N6110_SetMemory,
2795 NOTIMPLEMENTED, /* AddMemory */ 2801 NOTIMPLEMENTED, /* AddMemory */
2796 N6110_DeleteMemory, 2802 N6110_DeleteMemory,
2797 NOTIMPLEMENTED, /* DeleteAllMemory */ 2803 NOTIMPLEMENTED, /* DeleteAllMemory */
2798 N6110_GetSpeedDial, 2804 N6110_GetSpeedDial,
2799 NOTIMPLEMENTED, /* SetSpeedDial */ 2805 NOTIMPLEMENTED, /* SetSpeedDial */
2800 DCT3_GetSMSC, 2806 DCT3_GetSMSC,
2801 DCT3_SetSMSC, 2807 DCT3_SetSMSC,
2802 DCT3_GetSMSStatus, 2808 DCT3_GetSMSStatus,
2803 N6110_GetSMSMessage, 2809 N6110_GetSMSMessage,
2804 N6110_GetNextSMSMessage, 2810 N6110_GetNextSMSMessage,
2805 N6110_SetSMS, 2811 N6110_SetSMS,
2806 N6110_AddSMS, 2812 N6110_AddSMS,
2807 N6110_DeleteSMSMessage, 2813 N6110_DeleteSMSMessage,
2808 DCT3_SendSMSMessage, 2814 DCT3_SendSMSMessage,
2809 NOTSUPPORTED, /* SendSavedSMS */ 2815 NOTSUPPORTED, /* SendSavedSMS */
2816 NOTSUPPORTED, /* SetFastSMSSending*/
2810 NOKIA_SetIncomingSMS, 2817 NOKIA_SetIncomingSMS,
2811 DCT3_SetIncomingCB, 2818 DCT3_SetIncomingCB,
2812 PHONE_GetSMSFolders, 2819 PHONE_GetSMSFolders,
2813 NOTSUPPORTED, /* AddSMSFolder */ 2820 NOTSUPPORTED, /* AddSMSFolder */
2814 NOTSUPPORTED, /* DeleteSMSFolder */ 2821 NOTSUPPORTED, /* DeleteSMSFolder */
2815 N6110_DialVoice, 2822 N6110_DialVoice,
2816 N6110_AnswerCall, 2823 N6110_AnswerCall,
2817 DCT3_CancelCall, 2824 DCT3_CancelCall,
2818 N6110_HoldCall, 2825 N6110_HoldCall,
2819 N6110_UnholdCall, 2826 N6110_UnholdCall,
2820 N6110_ConferenceCall, 2827 N6110_ConferenceCall,
2821 N6110_SplitCall, 2828 N6110_SplitCall,
2822 N6110_TransferCall, 2829 N6110_TransferCall,
2823 N6110_SwitchCall, 2830 N6110_SwitchCall,
2824 DCT3DCT4_GetCallDivert, 2831 DCT3DCT4_GetCallDivert,
2825 DCT3DCT4_SetCallDivert, 2832 DCT3DCT4_SetCallDivert,
2826 DCT3DCT4_CancelAllDiverts, 2833 DCT3DCT4_CancelAllDiverts,
2827 NOKIA_SetIncomingCall, 2834 NOKIA_SetIncomingCall,
2828 NOKIA_SetIncomingUSSD, 2835 NOKIA_SetIncomingUSSD,
2829 DCT3DCT4_SendDTMF, 2836 DCT3DCT4_SendDTMF,
2830 N6110_GetRingtone, 2837 N6110_GetRingtone,
2831 N6110_SetRingtone, 2838 N6110_SetRingtone,
2832 NOTSUPPORTED, /* GetRingtonesInfo */ 2839 NOTSUPPORTED, /* GetRingtonesInfo */
2833 NOTSUPPORTED, /* DeleteUserRingtones */ 2840 NOTSUPPORTED, /* DeleteUserRingtones */
2834 DCT3_PlayTone, 2841 DCT3_PlayTone,
2835 DCT3_GetWAPBookmark, 2842 DCT3_GetWAPBookmark,
2836 DCT3_SetWAPBookmark, 2843 DCT3_SetWAPBookmark,
2837 DCT3_DeleteWAPBookmark, 2844 DCT3_DeleteWAPBookmark,
2838 DCT3_GetWAPSettings, 2845 DCT3_GetWAPSettings,
2839 DCT3_SetWAPSettings, 2846 DCT3_SetWAPSettings,
2840 NOTSUPPORTED, /* GetMMSSettings */ 2847 NOTSUPPORTED, /* GetMMSSettings */
2841 NOTSUPPORTED, /* SetMMSSettings */ 2848 NOTSUPPORTED, /* SetMMSSettings */
2842 NOTSUPPORTED, /* GetSyncMLSettings*/ 2849 NOTSUPPORTED, /* GetSyncMLSettings*/
2843 NOTSUPPORTED, /* SetSyncMLSettings*/ 2850 NOTSUPPORTED, /* SetSyncMLSettings*/
2844 NOTSUPPORTED, /* GetChatSettings */ 2851 NOTSUPPORTED, /* GetChatSettings */
2845 NOTSUPPORTED, /* SetChatSettings */ 2852 NOTSUPPORTED, /* SetChatSettings */
2846 N6110_GetBitmap, 2853 N6110_GetBitmap,
2847 N6110_SetBitmap, 2854 N6110_SetBitmap,
2848 NOTSUPPORTED, /* GetToDoStatus */ 2855 NOTSUPPORTED, /* GetToDoStatus */
2849 NOTSUPPORTED, /* GetToDo */ 2856 NOTSUPPORTED, /* GetToDo */
2850 NOTSUPPORTED, /* GetNextToDo */ 2857 NOTSUPPORTED, /* GetNextToDo */
2851 NOTSUPPORTED, /* SetToDo */ 2858 NOTSUPPORTED, /* SetToDo */
2852 NOTSUPPORTED, /* AddToDo */ 2859 NOTSUPPORTED, /* AddToDo */
2853 NOTSUPPORTED, /* DeleteToDo */ 2860 NOTSUPPORTED, /* DeleteToDo */
2854 NOTSUPPORTED, /* DeleteAllToDo */ 2861 NOTSUPPORTED, /* DeleteAllToDo */
2855 NOTIMPLEMENTED, /* GetCalendarStatus */ 2862 NOTIMPLEMENTED, /* GetCalendarStatus */
2856 NOTIMPLEMENTED, /* GetCalendar */ 2863 NOTIMPLEMENTED, /* GetCalendar */
2857 N6110_GetNextCalendarNote, 2864 N6110_GetNextCalendarNote,
2858 NOTIMPLEMENTED, /* SetCalendar */ 2865 NOTIMPLEMENTED, /* SetCalendar */
2859 N6110_AddCalendarNote, 2866 N6110_AddCalendarNote,
2860 N6110_DeleteCalendarNote, 2867 N6110_DeleteCalendarNote,
2861 NOTIMPLEMENTED, /* DeleteAllCalendar */ 2868 NOTIMPLEMENTED, /* DeleteAllCalendar */
2862 NOTSUPPORTED, /* GetCalendarSettings */ 2869 NOTSUPPORTED, /* GetCalendarSettings */
2863 NOTSUPPORTED, /* SetCalendarSettings */ 2870 NOTSUPPORTED, /* SetCalendarSettings */
2864 NOTSUPPORTED, /* GetNote */ 2871 NOTSUPPORTED, /* GetNextNote */
2865 N6110_GetProfile, 2872 N6110_GetProfile,
2866 N6110_SetProfile, 2873 N6110_SetProfile,
2867 NOTSUPPORTED, /* GetFMStation */ 2874 NOTSUPPORTED, /* GetFMStation */
2868 NOTSUPPORTED, /* SetFMStation */ 2875 NOTSUPPORTED, /* SetFMStation */
2869 NOTSUPPORTED, /* ClearFMStations */ 2876 NOTSUPPORTED, /* ClearFMStations */
2870 NOTSUPPORTED, /* GetNextFileFolder */ 2877 NOTSUPPORTED, /* GetNextFileFolder */
2871 NOTSUPPORTED, /* GetFilePart */ 2878 NOTSUPPORTED, /* GetFilePart */
2872 NOTSUPPORTED, /* AddFile */ 2879 NOTSUPPORTED, /* AddFile */
2873 NOTSUPPORTED, /* GetFileSystemStatus */ 2880 NOTSUPPORTED, /* GetFileSystemStatus */
2874 NOTSUPPORTED, /* DeleteFile */ 2881 NOTSUPPORTED, /* DeleteFile */
2875 NOTSUPPORTED, /* AddFolder */ 2882 NOTSUPPORTED, /* AddFolder */
2876 NOTSUPPORTED, /* GetGPRSAccessPoint */ 2883 NOTSUPPORTED, /* GetGPRSAccessPoint */
2877 NOTSUPPORTED /* SetGPRSAccessPoint */ 2884 NOTSUPPORTED /* SetGPRSAccessPoint */
2878}; 2885};
2879 2886
2880#endif 2887#endif
2881 2888
2882/* How should editor hadle tabs in this file? Add editor commands here. 2889/* How should editor hadle tabs in this file? Add editor commands here.
2883 * vim: noexpandtab sw=8 ts=8 sts=8: 2890 * vim: noexpandtab sw=8 ts=8 sts=8:
2884 */ 2891 */
diff --git a/gammu/emb/common/phone/nokia/dct3/n7110.c b/gammu/emb/common/phone/nokia/dct3/n7110.c
index 5a02c9c..b597f9b 100644
--- a/gammu/emb/common/phone/nokia/dct3/n7110.c
+++ b/gammu/emb/common/phone/nokia/dct3/n7110.c
@@ -1,194 +1,197 @@
1/* (c) 2001-2004 by Marcin Wiacek */ 1/* (c) 2001-2004 by Marcin Wiacek */
2/* based on some work from Markus Plail and Gnokii */ 2/* based on some Markus Plail work from Gnokii (www.gnokii.org)
3 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
4 * GNU GPL version 2 or later
5 */
3 6
4#include "../../../gsmstate.h" 7#include "../../../gsmstate.h"
5 8
6#ifdef GSM_ENABLE_NOKIA7110 9#ifdef GSM_ENABLE_NOKIA7110
7 10
8#include <string.h> 11#include <string.h>
9#include <time.h> 12#include <time.h>
10 13
11#include "../../../misc/coding/coding.h" 14#include "../../../misc/coding/coding.h"
12#include "../../../gsmcomon.h" 15#include "../../../gsmcomon.h"
13#include "../../../service/gsmlogo.h" 16#include "../../../service/gsmlogo.h"
14#include "../../pfunc.h" 17#include "../../pfunc.h"
15#include "../nfunc.h" 18#include "../nfunc.h"
16#include "../nfuncold.h" 19#include "../nfuncold.h"
17#include "n7110.h" 20#include "n7110.h"
18#include "dct3func.h" 21#include "dct3func.h"
19 22
20static GSM_Error N7110_GetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm) 23static GSM_Error N7110_GetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm)
21{ 24{
22 return DCT3_GetAlarm(s, alarm, 0x19); 25 return DCT3_GetAlarm(s, alarm, 0x19);
23} 26}
24 27
25static GSM_Error N7110_SetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm) 28static GSM_Error N7110_SetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm)
26{ 29{
27 return DCT3_SetAlarm(s, alarm, 0x19); 30 return DCT3_SetAlarm(s, alarm, 0x19);
28} 31}
29 32
30static GSM_Error N7110_ReplyGetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s) 33static GSM_Error N7110_ReplyGetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s)
31{ 34{
32 GSM_Phone_Data *Data = &s->Phone.Data; 35 GSM_Phone_Data *Data = &s->Phone.Data;
33 36
34 smprintf(s, "Phonebook entry received\n"); 37 smprintf(s, "Phonebook entry received\n");
35 switch (msg.Buffer[6]) { 38 switch (msg.Buffer[6]) {
36 case 0x0f: 39 case 0x0f:
37 return N71_65_ReplyGetMemoryError(msg.Buffer[10], s); 40 return N71_65_ReplyGetMemoryError(msg.Buffer[10], s);
38 default: 41 default:
39 return N71_65_DecodePhonebook(s, Data->Memory,Data->Bitmap,Data->SpeedDial,msg.Buffer+18,msg.Length-18,false); 42 return N71_65_DecodePhonebook(s, Data->Memory,Data->Bitmap,Data->SpeedDial,msg.Buffer+18,msg.Length-18,false);
40 } 43 }
41 return ERR_UNKNOWN; 44 return ERR_UNKNOWN;
42} 45}
43 46
44static GSM_Error N7110_GetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry) 47static GSM_Error N7110_GetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry)
45{ 48{
46 unsigned char req[] = {N7110_FRAME_HEADER, 0x07, 0x01, 0x01, 0x00, 0x01, 49 unsigned char req[] = {N7110_FRAME_HEADER, 0x07, 0x01, 0x01, 0x00, 0x01,
47 0x02, /* memory type */ 50 0x02, /* memory type */
48 0x05, 51 0x05,
49 0x00, 0x00,/* location */ 52 0x00, 0x00,/* location */
50 0x00, 0x00}; 53 0x00, 0x00};
51 54
52 req[9] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES); 55 req[9] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES);
53 if (req[9]==0xff) return ERR_NOTSUPPORTED; 56 if (req[9]==0xff) return ERR_NOTSUPPORTED;
54 57
55 if (entry->Location==0x00) return ERR_INVALIDLOCATION; 58 if (entry->Location==0x00) return ERR_INVALIDLOCATION;
56 59
57 req[10] = entry->Location / 256; 60 req[10] = entry->Location / 256;
58 req[11] = entry->Location % 256; 61 req[11] = entry->Location % 256;
59 62
60 s->Phone.Data.Memory=entry; 63 s->Phone.Data.Memory=entry;
61 smprintf(s, "Getting phonebook entry\n"); 64 smprintf(s, "Getting phonebook entry\n");
62 return GSM_WaitFor (s, req, 14, 0x03, 4, ID_GetMemory); 65 return GSM_WaitFor (s, req, 14, 0x03, 4, ID_GetMemory);
63} 66}
64 67
65static GSM_Error N7110_ReplyGetMemoryStatus(GSM_Protocol_Message msg, GSM_StateMachine *s) 68static GSM_Error N7110_ReplyGetMemoryStatus(GSM_Protocol_Message msg, GSM_StateMachine *s)
66{ 69{
67 GSM_Phone_Data *Data = &s->Phone.Data; 70 GSM_Phone_Data *Data = &s->Phone.Data;
68 71
69 smprintf(s, "Memory status received\n"); 72 smprintf(s, "Memory status received\n");
70 /* Quess ;-)) */ 73 /* Quess ;-)) */
71 if (msg.Buffer[10]==0x10) { 74 if (msg.Buffer[10]==0x10) {
72 Data->MemoryStatus->MemoryFree = msg.Buffer[14]*256 + msg.Buffer[15]; 75 Data->MemoryStatus->MemoryFree = msg.Buffer[14]*256 + msg.Buffer[15];
73 } else { 76 } else {
74 Data->MemoryStatus->MemoryFree = msg.Buffer[18]; 77 Data->MemoryStatus->MemoryFree = msg.Buffer[18];
75 } 78 }
76 smprintf(s, " Size : %i\n",Data->MemoryStatus->MemoryFree); 79 smprintf(s, " Size : %i\n",Data->MemoryStatus->MemoryFree);
77 Data->MemoryStatus->MemoryUsed = msg.Buffer[16]*256 + msg.Buffer[17]; 80 Data->MemoryStatus->MemoryUsed = msg.Buffer[16]*256 + msg.Buffer[17];
78 smprintf(s, " Used : %i\n",Data->MemoryStatus->MemoryUsed); 81 smprintf(s, " Used : %i\n",Data->MemoryStatus->MemoryUsed);
79 Data->MemoryStatus->MemoryFree -= Data->MemoryStatus->MemoryUsed; 82 Data->MemoryStatus->MemoryFree -= Data->MemoryStatus->MemoryUsed;
80 smprintf(s, " Free : %i\n",Data->MemoryStatus->MemoryFree); 83 smprintf(s, " Free : %i\n",Data->MemoryStatus->MemoryFree);
81 return ERR_NONE; 84 return ERR_NONE;
82} 85}
83 86
84static GSM_Error N7110_GetMemoryStatus(GSM_StateMachine *s, GSM_MemoryStatus *Status) 87static GSM_Error N7110_GetMemoryStatus(GSM_StateMachine *s, GSM_MemoryStatus *Status)
85{ 88{
86 unsigned char req[] = {N6110_FRAME_HEADER, 0x03, 0x02, 89 unsigned char req[] = {N6110_FRAME_HEADER, 0x03, 0x02,
87 0x05}; /* Memory type */ 90 0x05}; /* Memory type */
88 91
89 req[5] = NOKIA_GetMemoryType(s, Status->MemoryType,N71_65_MEMORY_TYPES); 92 req[5] = NOKIA_GetMemoryType(s, Status->MemoryType,N71_65_MEMORY_TYPES);
90 if (req[5]==0xff) return ERR_NOTSUPPORTED; 93 if (req[5]==0xff) return ERR_NOTSUPPORTED;
91 94
92 s->Phone.Data.MemoryStatus=Status; 95 s->Phone.Data.MemoryStatus=Status;
93 smprintf(s, "Getting memory status\n"); 96 smprintf(s, "Getting memory status\n");
94 return GSM_WaitFor (s, req, 6, 0x03, 4, ID_GetMemoryStatus); 97 return GSM_WaitFor (s, req, 6, 0x03, 4, ID_GetMemoryStatus);
95} 98}
96 99
97static void N7110_GetSMSLocation(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char *folderid, int *location) 100static void N7110_GetSMSLocation(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char *folderid, int *location)
98{ 101{
99 int ifolderid; 102 int ifolderid;
100 103
101 /* simulate flat SMS memory */ 104 /* simulate flat SMS memory */
102 if (sms->Folder==0x00) { 105 if (sms->Folder==0x00) {
103 ifolderid = sms->Location / PHONE_MAXSMSINFOLDER; 106 ifolderid = sms->Location / PHONE_MAXSMSINFOLDER;
104 *folderid = (ifolderid + 1) * 0x08; 107 *folderid = (ifolderid + 1) * 0x08;
105 *location = sms->Location - ifolderid * PHONE_MAXSMSINFOLDER; 108 *location = sms->Location - ifolderid * PHONE_MAXSMSINFOLDER;
106 } else { 109 } else {
107 *folderid = sms->Folder * 0x08; 110 *folderid = sms->Folder * 0x08;
108 *location = sms->Location; 111 *location = sms->Location;
109 } 112 }
110 smprintf(s, "SMS folder %i & location %i -> 7110 folder %i & location %i\n", 113 smprintf(s, "SMS folder %i & location %i -> 7110 folder %i & location %i\n",
111 sms->Folder,sms->Location,*folderid,*location); 114 sms->Folder,sms->Location,*folderid,*location);
112} 115}
113 116
114static void N7110_SetSMSLocation(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char folderid, int location) 117static void N7110_SetSMSLocation(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char folderid, int location)
115{ 118{
116 sms->Folder= 0; 119 sms->Folder= 0;
117 sms->Location= (folderid / 0x08 - 1) * PHONE_MAXSMSINFOLDER + location; 120 sms->Location= (folderid / 0x08 - 1) * PHONE_MAXSMSINFOLDER + location;
118 smprintf(s, "7110 folder %i & location %i -> SMS folder %i & location %i\n", 121 smprintf(s, "7110 folder %i & location %i -> SMS folder %i & location %i\n",
119 folderid,location,sms->Folder,sms->Location); 122 folderid,location,sms->Folder,sms->Location);
120} 123}
121 124
122static GSM_Error N7110_ReplyGetSMSFolders(GSM_Protocol_Message msg, GSM_StateMachine *s) 125static GSM_Error N7110_ReplyGetSMSFolders(GSM_Protocol_Message msg, GSM_StateMachine *s)
123{ 126{
124 int j,current=5; 127 int j,current=5;
125 unsigned char buffer[200]; 128 unsigned char buffer[200];
126 GSM_Phone_Data*Data = &s->Phone.Data; 129 GSM_Phone_Data*Data = &s->Phone.Data;
127 130
128 switch (msg.Buffer[3]) { 131 switch (msg.Buffer[3]) {
129 case 0x7B: 132 case 0x7B:
130 smprintf(s, "Names for SMS folders received\n"); 133 smprintf(s, "Names for SMS folders received\n");
131 Data->SMSFolders->Number=msg.Buffer[4]; 134 Data->SMSFolders->Number=msg.Buffer[4];
132 for (j=0;j<msg.Buffer[4];j++) { 135 for (j=0;j<msg.Buffer[4];j++) {
133 smprintf(s, "Folder index: %02x",msg.Buffer[current]); 136 smprintf(s, "Folder index: %02x",msg.Buffer[current]);
134 current++; 137 current++;
135 smprintf(s, ", folder name: \""); 138 smprintf(s, ", folder name: \"");
136 CopyUnicodeString(buffer,msg.Buffer+current); 139 CopyUnicodeString(buffer,msg.Buffer+current);
137 if ((UnicodeLength(buffer))>GSM_MAX_SMS_FOLDER_NAME_LEN) { 140 if ((UnicodeLength(buffer))>GSM_MAX_SMS_FOLDER_NAME_LEN) {
138 smprintf(s, "Too long text\n"); 141 smprintf(s, "Too long text\n");
139 return ERR_UNKNOWNRESPONSE; 142 return ERR_UNKNOWNRESPONSE;
140 } 143 }
141 CopyUnicodeString(Data->SMSFolders->Folder[j].Name,buffer); 144 CopyUnicodeString(Data->SMSFolders->Folder[j].Name,buffer);
142 smprintf(s, "%s\"\n",DecodeUnicodeString(buffer)); 145 smprintf(s, "%s\"\n",DecodeUnicodeString(buffer));
143 current=current+2+UnicodeLength(buffer)*2; 146 current=current+2+UnicodeLength(buffer)*2;
144 Data->SMSFolders->Folder[j].InboxFolder = false; 147 Data->SMSFolders->Folder[j].InboxFolder = false;
145 if (j==0) Data->SMSFolders->Folder[j].InboxFolder = true; 148 if (j==0) Data->SMSFolders->Folder[j].InboxFolder = true;
146 Data->SMSFolders->Folder[j].Memory = MEM_ME; 149 Data->SMSFolders->Folder[j].Memory = MEM_ME;
147 if (j==0 || j==1) Data->SMSFolders->Folder[j].InboxFolder = MEM_MT; 150 if (j==0 || j==1) Data->SMSFolders->Folder[j].InboxFolder = MEM_MT;
148 } 151 }
149 return ERR_NONE; 152 return ERR_NONE;
150 case 0x7C: 153 case 0x7C:
151 smprintf(s, "Security error ? No PIN ?\n"); 154 smprintf(s, "Security error ? No PIN ?\n");
152 return ERR_SECURITYERROR; 155 return ERR_SECURITYERROR;
153 case 0xCA: 156 case 0xCA:
154 smprintf(s, "Wait a moment. Phone is during power on and busy now\n"); 157 smprintf(s, "Wait a moment. Phone is during power on and busy now\n");
155 return ERR_SECURITYERROR; 158 return ERR_SECURITYERROR;
156 } 159 }
157 return ERR_UNKNOWNRESPONSE; 160 return ERR_UNKNOWNRESPONSE;
158} 161}
159 162
160static GSM_Error N7110_GetSMSFolders(GSM_StateMachine *s, GSM_SMSFolders *folders) 163static GSM_Error N7110_GetSMSFolders(GSM_StateMachine *s, GSM_SMSFolders *folders)
161{ 164{
162 unsigned char req[] = {N6110_FRAME_HEADER, 0x7A, 0x00, 0x00}; 165 unsigned char req[] = {N6110_FRAME_HEADER, 0x7A, 0x00, 0x00};
163 166
164 s->Phone.Data.SMSFolders=folders; 167 s->Phone.Data.SMSFolders=folders;
165 smprintf(s, "Getting SMS folders\n"); 168 smprintf(s, "Getting SMS folders\n");
166 return GSM_WaitFor (s, req, 6, 0x14, 4, ID_GetSMSFolders); 169 return GSM_WaitFor (s, req, 6, 0x14, 4, ID_GetSMSFolders);
167} 170}
168 171
169static GSM_Error N7110_ReplyGetSMSFolderStatus(GSM_Protocol_Message msg, GSM_StateMachine *s) 172static GSM_Error N7110_ReplyGetSMSFolderStatus(GSM_Protocol_Message msg, GSM_StateMachine *s)
170{ 173{
171 int i; 174 int i;
172 GSM_Phone_N7110Data*Priv = &s->Phone.Data.Priv.N7110; 175 GSM_Phone_N7110Data*Priv = &s->Phone.Data.Priv.N7110;
173 176
174 smprintf(s, "SMS folder status received\n"); 177 smprintf(s, "SMS folder status received\n");
175 Priv->LastSMSFolder.Number=msg.Buffer[4]*256+msg.Buffer[5]; 178 Priv->LastSMSFolder.Number=msg.Buffer[4]*256+msg.Buffer[5];
176 smprintf(s, "Number of Entries: %i\n",Priv->LastSMSFolder.Number); 179 smprintf(s, "Number of Entries: %i\n",Priv->LastSMSFolder.Number);
177 smprintf(s, "Locations: "); 180 smprintf(s, "Locations: ");
178 for (i=0;i<Priv->LastSMSFolder.Number;i++) { 181 for (i=0;i<Priv->LastSMSFolder.Number;i++) {
179 Priv->LastSMSFolder.Location[i]=msg.Buffer[6+(i*2)]*256+msg.Buffer[(i*2)+7]; 182 Priv->LastSMSFolder.Location[i]=msg.Buffer[6+(i*2)]*256+msg.Buffer[(i*2)+7];
180 if (Priv->LastSMSFolder.Location[i] > PHONE_MAXSMSINFOLDER) { 183 if (Priv->LastSMSFolder.Location[i] > PHONE_MAXSMSINFOLDER) {
181 smprintf(s, "Increase PHONE_MAXSMSINFOLDER\n"); 184 smprintf(s, "Increase PHONE_MAXSMSINFOLDER\n");
182 return ERR_UNKNOWNRESPONSE; 185 return ERR_UNKNOWNRESPONSE;
183 } 186 }
184 smprintf(s, "%i ",Priv->LastSMSFolder.Location[i]); 187 smprintf(s, "%i ",Priv->LastSMSFolder.Location[i]);
185 } 188 }
186 smprintf(s, "\n"); 189 smprintf(s, "\n");
187 NOKIA_SortSMSFolderStatus(s, &Priv->LastSMSFolder); 190 NOKIA_SortSMSFolderStatus(s, &Priv->LastSMSFolder);
188 return ERR_NONE; 191 return ERR_NONE;
189} 192}
190 193
191static GSM_Error N7110_PrivGetSMSFolderStatus(GSM_StateMachine *s, int folderid) 194static GSM_Error N7110_PrivGetSMSFolderStatus(GSM_StateMachine *s, int folderid)
192{ 195{
193 unsigned char req[] = {N7110_FRAME_HEADER, 0x6b, 196 unsigned char req[] = {N7110_FRAME_HEADER, 0x6b,
194 0x08, /* folderID */ 197 0x08, /* folderID */
@@ -337,384 +340,385 @@ static GSM_Error N7110_ReplyGetSMSMessage(GSM_Protocol_Message msg, GSM_StateMac
337 return ERR_NONE; 340 return ERR_NONE;
338 } 341 }
339 return ERR_UNKNOWNRESPONSE; 342 return ERR_UNKNOWNRESPONSE;
340} 343}
341 344
342static GSM_Error N7110_PrivGetSMSMessage(GSM_StateMachine *s, GSM_MultiSMSMessage *sms) 345static GSM_Error N7110_PrivGetSMSMessage(GSM_StateMachine *s, GSM_MultiSMSMessage *sms)
343{ 346{
344 GSM_Error error; 347 GSM_Error error;
345 unsigned char folderid; 348 unsigned char folderid;
346 int location; 349 int location;
347 int i; 350 int i;
348 unsigned char req[] = {N6110_FRAME_HEADER, 0x07, 351 unsigned char req[] = {N6110_FRAME_HEADER, 0x07,
349 0x08, /* folder ID */ 352 0x08, /* folder ID */
350 0x00, 0x05, /* location */ 353 0x00, 0x05, /* location */
351 0x01, 0x65, 0x01}; 354 0x01, 0x65, 0x01};
352 unsigned char NameReq[] = {N6110_FRAME_HEADER, 0x6E, 355 unsigned char NameReq[] = {N6110_FRAME_HEADER, 0x6E,
353 0x08, /* folder ID */ 356 0x08, /* folder ID */
354 0x00, 0x05}; /* location */ 357 0x00, 0x05}; /* location */
355 358
356 N7110_GetSMSLocation(s, &sms->SMS[0], &folderid, &location); 359 N7110_GetSMSLocation(s, &sms->SMS[0], &folderid, &location);
357 360
358 req[4]=folderid; 361 req[4]=folderid;
359 req[5]=location / 256; 362 req[5]=location / 256;
360 req[6]=location; 363 req[6]=location;
361 364
362 s->Phone.Data.GetSMSMessage=sms; 365 s->Phone.Data.GetSMSMessage=sms;
363 smprintf(s, "Getting sms\n"); 366 smprintf(s, "Getting sms\n");
364 error=GSM_WaitFor (s, req, 10, 0x14, 4, ID_GetSMSMessage); 367 error=GSM_WaitFor (s, req, 10, 0x14, 4, ID_GetSMSMessage);
365 if (error==ERR_NONE) { 368 if (error==ERR_NONE) {
366 NameReq[4] = folderid; 369 NameReq[4] = folderid;
367 NameReq[5] = location / 256; 370 NameReq[5] = location / 256;
368 NameReq[6] = location; 371 NameReq[6] = location;
369 smprintf(s, "Getting sms info\n"); 372 smprintf(s, "Getting sms info\n");
370 error=GSM_WaitFor (s, NameReq, 7, 0x14, 4, ID_GetSMSMessage); 373 error=GSM_WaitFor (s, NameReq, 7, 0x14, 4, ID_GetSMSMessage);
371 if (error != ERR_NONE) return error; 374 if (error != ERR_NONE) return error;
372 for (i=0;i<sms->Number;i++) { 375 for (i=0;i<sms->Number;i++) {
373 N7110_SetSMSLocation(s, &sms->SMS[i], folderid, location); 376 N7110_SetSMSLocation(s, &sms->SMS[i], folderid, location);
374 sms->SMS[i].Folder = folderid/0x08; 377 sms->SMS[i].Folder = folderid/0x08;
375 sms->SMS[i].InboxFolder = true; 378 sms->SMS[i].InboxFolder = true;
376 if (folderid/0x08 != 0x01) sms->SMS[i].InboxFolder = false; 379 if (folderid/0x08 != 0x01) sms->SMS[i].InboxFolder = false;
377 CopyUnicodeString(sms->SMS[i].Name,sms->SMS[0].Name); 380 CopyUnicodeString(sms->SMS[i].Name,sms->SMS[0].Name);
378 sms->SMS[i].Memory = MEM_ME; 381 sms->SMS[i].Memory = MEM_ME;
379 if (folderid/0x08 == 0x01 || folderid/0x08 == 0x02) { 382 if (folderid/0x08 == 0x01 || folderid/0x08 == 0x02) {
380 sms->SMS[i].Memory = MEM_MT; 383 sms->SMS[i].Memory = MEM_MT;
381 if (folderid/0x08 == 0x01) { /* Inbox */ 384 if (folderid/0x08 == 0x01) { /* Inbox */
382 if (sms->SMS[i].State == SMS_Sent) sms->SMS[i].Memory = MEM_ME; 385 if (sms->SMS[i].State == SMS_Sent) sms->SMS[i].Memory = MEM_ME;
383 if (sms->SMS[i].State == SMS_UnSent) sms->SMS[i].Memory = MEM_ME; 386 if (sms->SMS[i].State == SMS_UnSent) sms->SMS[i].Memory = MEM_ME;
384 if (sms->SMS[i].State == SMS_Read) sms->SMS[i].Memory = MEM_SM; 387 if (sms->SMS[i].State == SMS_Read) sms->SMS[i].Memory = MEM_SM;
385 if (sms->SMS[i].State == SMS_UnRead) sms->SMS[i].Memory = MEM_SM; 388 if (sms->SMS[i].State == SMS_UnRead) sms->SMS[i].Memory = MEM_SM;
386 } 389 }
387 if (folderid/0x08 == 0x02) { /* Outbox */ 390 if (folderid/0x08 == 0x02) { /* Outbox */
388 if (sms->SMS[i].State == SMS_Sent) sms->SMS[i].Memory = MEM_SM; 391 if (sms->SMS[i].State == SMS_Sent) sms->SMS[i].Memory = MEM_SM;
389 if (sms->SMS[i].State == SMS_UnSent) sms->SMS[i].Memory = MEM_SM; 392 if (sms->SMS[i].State == SMS_UnSent) sms->SMS[i].Memory = MEM_SM;
390 if (sms->SMS[i].State == SMS_Read) sms->SMS[i].Memory = MEM_ME; 393 if (sms->SMS[i].State == SMS_Read) sms->SMS[i].Memory = MEM_ME;
391 if (sms->SMS[i].State == SMS_UnRead) sms->SMS[i].Memory = MEM_ME; 394 if (sms->SMS[i].State == SMS_UnRead) sms->SMS[i].Memory = MEM_ME;
392 } 395 }
393 } 396 }
394 } 397 }
395 } 398 }
396 return error; 399 return error;
397} 400}
398 401
399static GSM_Error N7110_GetSMSMessage(GSM_StateMachine *s, GSM_MultiSMSMessage *sms) 402static GSM_Error N7110_GetSMSMessage(GSM_StateMachine *s, GSM_MultiSMSMessage *sms)
400{ 403{
401 GSM_Error error; 404 GSM_Error error;
402 unsigned char folderid; 405 unsigned char folderid;
403 int location; 406 int location;
404 GSM_Phone_N7110Data*Priv = &s->Phone.Data.Priv.N7110; 407 GSM_Phone_N7110Data*Priv = &s->Phone.Data.Priv.N7110;
405 int i; 408 int i;
406 bool found = false; 409 bool found = false;
407 410
408 N7110_GetSMSLocation(s, &sms->SMS[0], &folderid, &location); 411 N7110_GetSMSLocation(s, &sms->SMS[0], &folderid, &location);
409 error=N7110_GetSMSFolderStatus(s, folderid); 412 error=N7110_GetSMSFolderStatus(s, folderid);
410 if (error!=ERR_NONE) return error; 413 if (error!=ERR_NONE) return error;
411 for (i=0;i<Priv->LastSMSFolder.Number;i++) { 414 for (i=0;i<Priv->LastSMSFolder.Number;i++) {
412 if (Priv->LastSMSFolder.Location[i]==location) { 415 if (Priv->LastSMSFolder.Location[i]==location) {
413 found = true; 416 found = true;
414 break; 417 break;
415 } 418 }
416 } 419 }
417 if (!found) return ERR_EMPTY; 420 if (!found) return ERR_EMPTY;
418 return N7110_PrivGetSMSMessage(s,sms); 421 return N7110_PrivGetSMSMessage(s,sms);
419} 422}
420 423
421static GSM_Error N7110_GetNextSMSMessage(GSM_StateMachine *s, GSM_MultiSMSMessage *sms, bool start) 424static GSM_Error N7110_GetNextSMSMessage(GSM_StateMachine *s, GSM_MultiSMSMessage *sms, bool start)
422{ 425{
423 GSM_Phone_N7110Data*Priv = &s->Phone.Data.Priv.N7110; 426 GSM_Phone_N7110Data*Priv = &s->Phone.Data.Priv.N7110;
424 unsigned char folderid; 427 unsigned char folderid;
425 int location; 428 int location;
426 GSM_Error error; 429 GSM_Error error;
427 int i; 430 int i;
428 bool findnextfolder = false; 431 bool findnextfolder = false;
429 432
430 if (start) { 433 if (start) {
431 folderid=0x00; 434 folderid=0x00;
432 findnextfolder=true; 435 findnextfolder=true;
433 error=N7110_GetSMSFolders(s,&Priv->LastSMSFolders); 436 error=N7110_GetSMSFolders(s,&Priv->LastSMSFolders);
434 if (error!=ERR_NONE) return error; 437 if (error!=ERR_NONE) return error;
435 } else { 438 } else {
436 N7110_GetSMSLocation(s, &sms->SMS[0], &folderid, &location); 439 N7110_GetSMSLocation(s, &sms->SMS[0], &folderid, &location);
437 for (i=0;i<Priv->LastSMSFolder.Number;i++) { 440 for (i=0;i<Priv->LastSMSFolder.Number;i++) {
438 if (Priv->LastSMSFolder.Location[i]==location) break; 441 if (Priv->LastSMSFolder.Location[i]==location) break;
439 } 442 }
440 /* Is this last location in this folder ? */ 443 /* Is this last location in this folder ? */
441 if (i==Priv->LastSMSFolder.Number-1) { 444 if (i==Priv->LastSMSFolder.Number-1) {
442 findnextfolder=true; 445 findnextfolder=true;
443 } else { 446 } else {
444 location=Priv->LastSMSFolder.Location[i+1]; 447 location=Priv->LastSMSFolder.Location[i+1];
445 } 448 }
446 } 449 }
447 if (findnextfolder) { 450 if (findnextfolder) {
448 Priv->LastSMSFolder.Number=0; 451 Priv->LastSMSFolder.Number=0;
449 while (Priv->LastSMSFolder.Number==0) { 452 while (Priv->LastSMSFolder.Number==0) {
450 folderid=folderid+0x08; 453 folderid=folderid+0x08;
451 /* Too high folder number */ 454 /* Too high folder number */
452 if ((folderid/0x08)>Priv->LastSMSFolders.Number) return ERR_EMPTY; 455 if ((folderid/0x08)>Priv->LastSMSFolders.Number) return ERR_EMPTY;
453 /* Get next folder status */ 456 /* Get next folder status */
454 error=N7110_GetSMSFolderStatus(s, folderid); 457 error=N7110_GetSMSFolderStatus(s, folderid);
455 if (error!=ERR_NONE) return error; 458 if (error!=ERR_NONE) return error;
456 /* First location from this folder */ 459 /* First location from this folder */
457 location=Priv->LastSMSFolder.Location[0]; 460 location=Priv->LastSMSFolder.Location[0];
458 } 461 }
459 } 462 }
460 N7110_SetSMSLocation(s, &sms->SMS[0], folderid, location); 463 N7110_SetSMSLocation(s, &sms->SMS[0], folderid, location);
461 464
462 return N7110_PrivGetSMSMessage(s, sms); 465 return N7110_PrivGetSMSMessage(s, sms);
463} 466}
464 467
465static int N7110_ReturnBinaryRingtoneLocation(char *model) 468static int N7110_ReturnBinaryRingtoneLocation(char *model)
466{ 469{
467 if (strcmp(model,"NSE-5") == 0) return 0x72; /* first 0x72 - 7110 */ 470 if (strcmp(model,"NSE-5") == 0) return 0x72; /* first 0x72 - 7110 */
468 if (strcmp(model,"NPE-3") == 0) return 0x89; /* first 0x89 - 6210 */ 471 if (strcmp(model,"NPE-3") == 0) return 0x89; /* first 0x89 - 6210 */
469 if (strcmp(model,"NHM-3") == 0) return 0x89; /* quess for 6250 */ 472 if (strcmp(model,"NHM-3") == 0) return 0x89; /* quess for 6250 */
470 return 0; 473 return 0;
471} 474}
472 475
473static GSM_Error N7110_ReplyGetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s) 476static GSM_Error N7110_ReplyGetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s)
474{ 477{
475 int tmp,i; 478 int tmp,i;
476 GSM_Phone_Data *Data = &s->Phone.Data; 479 GSM_Phone_Data *Data = &s->Phone.Data;
477 480
478 smprintf(s, "Ringtone received\n"); 481 smprintf(s, "Ringtone received\n");
479 switch (msg.Buffer[3]) { 482 switch (msg.Buffer[3]) {
480 case 0x23: 483 case 0x23:
481 tmp=0;i=4; 484 tmp=0;i=4;
482 while (msg.Buffer[i]!=0 || msg.Buffer[i+1]!=0) { 485 while (msg.Buffer[i]!=0 || msg.Buffer[i+1]!=0) {
483 tmp++; 486 tmp++;
484 i=i+2; 487 i=i+2;
485 if (i>msg.Length) return ERR_EMPTY; 488 if (i>msg.Length) return ERR_EMPTY;
486 } 489 }
487 memcpy(Data->Ringtone->Name,msg.Buffer+6,tmp*2); 490 memcpy(Data->Ringtone->Name,msg.Buffer+6,tmp*2);
488 smprintf(s, "Name \"%s\"\n",DecodeUnicodeString(Data->Ringtone->Name)); 491 smprintf(s, "Name \"%s\"\n",DecodeUnicodeString(Data->Ringtone->Name));
489 /* Looking for end */ 492 /* Looking for end */
490 i=37; 493 i=37;
491 while (true) { 494 while (true) {
492 if (msg.Buffer[i]==0x07 && msg.Buffer[i+1]==0x0b) { 495 if (msg.Buffer[i]==0x07 && msg.Buffer[i+1]==0x0b) {
493 i=i+2; break; 496 i=i+2; break;
494 } 497 }
495 if (msg.Buffer[i]==0x0e && msg.Buffer[i+1]==0x0b) { 498 if (msg.Buffer[i]==0x0e && msg.Buffer[i+1]==0x0b) {
496 i=i+2; break; 499 i=i+2; break;
497 } 500 }
498 i++; 501 i++;
499 if (i==msg.Length) return ERR_EMPTY; 502 if (i==msg.Length) return ERR_EMPTY;
500 } 503 }
501 /* Copying frame */ 504 /* Copying frame */
502 memcpy(Data->Ringtone->NokiaBinary.Frame,msg.Buffer+37,i-37); 505 memcpy(Data->Ringtone->NokiaBinary.Frame,msg.Buffer+37,i-37);
503 Data->Ringtone->NokiaBinary.Length=i-37; 506 Data->Ringtone->NokiaBinary.Length=i-37;
504 return ERR_NONE; 507 return ERR_NONE;
505 case 0x24: 508 case 0x24:
506 smprintf(s, "Invalid location. Too high ?\n"); 509 smprintf(s, "Invalid location. Too high ?\n");
507 return ERR_INVALIDLOCATION; 510 return ERR_INVALIDLOCATION;
508 } 511 }
509 return ERR_UNKNOWNRESPONSE; 512 return ERR_UNKNOWNRESPONSE;
510} 513}
511 514
512static GSM_Error N7110_GetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone) 515static GSM_Error N7110_GetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone)
513{ 516{
514 unsigned char req[] = {N7110_FRAME_HEADER, 0x22, 0x00, 0x00}; 517 unsigned char req[] = {N7110_FRAME_HEADER, 0x22, 0x00, 0x00};
515 518
516 if (PhoneRingtone) return ERR_NOTSUPPORTED; 519 if (PhoneRingtone) return ERR_NOTSUPPORTED;
517 if (Ringtone->Format == 0x00) Ringtone->Format = RING_NOKIABINARY; 520 if (Ringtone->Format == 0x00) Ringtone->Format = RING_NOKIABINARY;
518 521
519 switch (Ringtone->Format) { 522 switch (Ringtone->Format) {
520 case RING_NOTETONE: 523 case RING_NOTETONE:
521 /* In the future get binary and convert */ 524 /* In the future get binary and convert */
522 return ERR_NOTSUPPORTED; 525 return ERR_NOTSUPPORTED;
523 case RING_NOKIABINARY: 526 case RING_NOKIABINARY:
524 req[5]=N7110_ReturnBinaryRingtoneLocation(s->Phone.Data.Model)+Ringtone->Location; 527 req[5]=N7110_ReturnBinaryRingtoneLocation(s->Phone.Data.Model)+Ringtone->Location;
525 s->Phone.Data.Ringtone=Ringtone; 528 s->Phone.Data.Ringtone=Ringtone;
526 smprintf(s, "Getting binary ringtone\n"); 529 smprintf(s, "Getting binary ringtone\n");
527 return GSM_WaitFor (s, req, 6, 0x1f, 4, ID_GetRingtone); 530 return GSM_WaitFor (s, req, 6, 0x1f, 4, ID_GetRingtone);
528 case RING_MIDI: 531 case RING_MIDI:
532 case RING_MMF:
529 return ERR_NOTSUPPORTED; 533 return ERR_NOTSUPPORTED;
530 } 534 }
531 return ERR_NOTSUPPORTED; 535 return ERR_NOTSUPPORTED;
532} 536}
533 537
534static GSM_Error N7110_ReplyGetPictureImageInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 538static GSM_Error N7110_ReplyGetPictureImageInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
535{ 539{
536 int i; 540 int i;
537 GSM_Phone_N7110Data*Priv = &s->Phone.Data.Priv.N7110; 541 GSM_Phone_N7110Data*Priv = &s->Phone.Data.Priv.N7110;
538 542
539 smprintf(s, "Received info for Picture Images\n"); 543 smprintf(s, "Received info for Picture Images\n");
540 smprintf(s, "Number : %i\n",msg.Buffer[4]*256+msg.Buffer[5]); 544 smprintf(s, "Number : %i\n",msg.Buffer[4]*256+msg.Buffer[5]);
541 smprintf(s, "Locations :"); 545 smprintf(s, "Locations :");
542 Priv->LastPictureImageFolder.Number=msg.Buffer[4]*256+msg.Buffer[5]; 546 Priv->LastPictureImageFolder.Number=msg.Buffer[4]*256+msg.Buffer[5];
543 for (i=0;i<Priv->LastPictureImageFolder.Number;i++) { 547 for (i=0;i<Priv->LastPictureImageFolder.Number;i++) {
544 Priv->LastPictureImageFolder.Location[i]=msg.Buffer[6+i*2]*256+msg.Buffer[7+i*2]; 548 Priv->LastPictureImageFolder.Location[i]=msg.Buffer[6+i*2]*256+msg.Buffer[7+i*2];
545 smprintf(s, " %i",Priv->LastPictureImageFolder.Location[i]); 549 smprintf(s, " %i",Priv->LastPictureImageFolder.Location[i]);
546 } 550 }
547 smprintf(s, "\n"); 551 smprintf(s, "\n");
548 return ERR_NONE; 552 return ERR_NONE;
549} 553}
550 554
551static GSM_Error N7110_GetPictureImageLocation(GSM_StateMachine *s, GSM_Bitmap *Bitmap, unsigned char *folder, int *location) 555static GSM_Error N7110_GetPictureImageLocation(GSM_StateMachine *s, GSM_Bitmap *Bitmap, unsigned char *folder, int *location)
552{ 556{
553 GSM_Phone_N7110Data*Priv = &s->Phone.Data.Priv.N7110; 557 GSM_Phone_N7110Data*Priv = &s->Phone.Data.Priv.N7110;
554 GSM_SMSFolders folders; 558 GSM_SMSFolders folders;
555 GSM_Error error; 559 GSM_Error error;
556 int i, j = 0, count = 0; 560 int i, j = 0, count = 0;
557 unsigned char req[] = {N6110_FRAME_HEADER, 0x96, 561 unsigned char req[] = {N6110_FRAME_HEADER, 0x96,
558 0x00, /* Folder ID */ 562 0x00, /* Folder ID */
559 0x0f, 0x07}; 563 0x0f, 0x07};
560 564
561 error=N7110_GetSMSFolders (s, &folders); 565 error=N7110_GetSMSFolders (s, &folders);
562 if (error!=ERR_NONE) return error; 566 if (error!=ERR_NONE) return error;
563 567
564 for (i=0;i<folders.Number;i++) { 568 for (i=0;i<folders.Number;i++) {
565 req[4] = (i+1) * 0x08;/* SMS folder ID */ 569 req[4] = (i+1) * 0x08;/* SMS folder ID */
566 error = GSM_WaitFor (s, req, 7, 0x14, 4, ID_GetBitmap); 570 error = GSM_WaitFor (s, req, 7, 0x14, 4, ID_GetBitmap);
567 if (error!=ERR_NONE) return error; 571 if (error!=ERR_NONE) return error;
568 for (j=0;j<Priv->LastPictureImageFolder.Number;j++) { 572 for (j=0;j<Priv->LastPictureImageFolder.Number;j++) {
569 count++; 573 count++;
570 if (count==Bitmap->Location) break; 574 if (count==Bitmap->Location) break;
571 } 575 }
572 if (count==Bitmap->Location) break; 576 if (count==Bitmap->Location) break;
573 } 577 }
574 if (count!=Bitmap->Location) return ERR_INVALIDLOCATION; 578 if (count!=Bitmap->Location) return ERR_INVALIDLOCATION;
575 *folder = (i+1) * 0x08;/* SMS Folder ID */ 579 *folder = (i+1) * 0x08;/* SMS Folder ID */
576 *location= Priv->LastPictureImageFolder.Location[j]; 580 *location= Priv->LastPictureImageFolder.Location[j];
577 return ERR_NONE; 581 return ERR_NONE;
578} 582}
579 583
580static GSM_Error N7110_GetPictureImage(GSM_StateMachine *s, GSM_Bitmap *Bitmap) 584static GSM_Error N7110_GetPictureImage(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
581{ 585{
582 unsigned char folder; 586 unsigned char folder;
583 int location; 587 int location;
584 GSM_Error error; 588 GSM_Error error;
585 unsigned char req[] = {N6110_FRAME_HEADER, 0x07, 589 unsigned char req[] = {N6110_FRAME_HEADER, 0x07,
586 0x00, /* Folder ID */ 590 0x00, /* Folder ID */
587 0x00, 0x00, /* Location */ 591 0x00, 0x00, /* Location */
588 0x00, 0x64}; 592 0x00, 0x64};
589 593
590 error = N7110_GetPictureImageLocation(s, Bitmap, &folder, &location); 594 error = N7110_GetPictureImageLocation(s, Bitmap, &folder, &location);
591 switch (error) { 595 switch (error) {
592 case ERR_NONE: 596 case ERR_NONE:
593 req[4] = folder; 597 req[4] = folder;
594 req[5] = location / 256; 598 req[5] = location / 256;
595 req[6] = location % 256; 599 req[6] = location % 256;
596 return GSM_WaitFor (s, req, 9, 0x14, 4, ID_GetBitmap); 600 return GSM_WaitFor (s, req, 9, 0x14, 4, ID_GetBitmap);
597 default: 601 default:
598 return error; 602 return error;
599 } 603 }
600} 604}
601 605
602static GSM_Error N7110_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap) 606static GSM_Error N7110_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
603{ 607{
604 GSM_MemoryEntry pbk; 608 GSM_MemoryEntry pbk;
605 GSM_Error error; 609 GSM_Error error;
606 unsigned char OpReq[] = {N6110_FRAME_HEADER, 0x70}; 610 unsigned char OpReq[] = {N6110_FRAME_HEADER, 0x70};
607 611
608 s->Phone.Data.Bitmap=Bitmap; 612 s->Phone.Data.Bitmap=Bitmap;
609 switch (Bitmap->Type) { 613 switch (Bitmap->Type) {
610 case GSM_StartupLogo: 614 case GSM_StartupLogo:
611 smprintf(s, "Getting startup logo\n"); 615 smprintf(s, "Getting startup logo\n");
612 return N71_92_GetPhoneSetting(s, ID_GetBitmap, 0x15); 616 return N71_92_GetPhoneSetting(s, ID_GetBitmap, 0x15);
613 case GSM_WelcomeNote_Text: 617 case GSM_WelcomeNote_Text:
614 smprintf(s, "Getting welcome note\n"); 618 smprintf(s, "Getting welcome note\n");
615 return N71_92_GetPhoneSetting(s, ID_GetBitmap, 0x02); 619 return N71_92_GetPhoneSetting(s, ID_GetBitmap, 0x02);
616 case GSM_DealerNote_Text: 620 case GSM_DealerNote_Text:
617 smprintf(s, "Getting dealer note\n"); 621 smprintf(s, "Getting dealer note\n");
618 return N71_92_GetPhoneSetting(s, ID_GetBitmap, 0x17); 622 return N71_92_GetPhoneSetting(s, ID_GetBitmap, 0x17);
619 case GSM_CallerGroupLogo: 623 case GSM_CallerGroupLogo:
620 pbk.MemoryType = MEM7110_CG; 624 pbk.MemoryType = MEM7110_CG;
621 pbk.Location = Bitmap->Location; 625 pbk.Location = Bitmap->Location;
622 smprintf(s, "Getting caller group logo\n"); 626 smprintf(s, "Getting caller group logo\n");
623 error=N7110_GetMemory(s,&pbk); 627 error=N7110_GetMemory(s,&pbk);
624 if (error==ERR_NONE) NOKIA_GetDefaultCallerGroupName(s,Bitmap); 628 if (error==ERR_NONE) NOKIA_GetDefaultCallerGroupName(s,Bitmap);
625 return error; 629 return error;
626 case GSM_OperatorLogo: 630 case GSM_OperatorLogo:
627 smprintf(s, "Getting operator logo\n"); 631 smprintf(s, "Getting operator logo\n");
628 /* This is like DCT3_GetNetworkInfo */ 632 /* This is like DCT3_GetNetworkInfo */
629 return GSM_WaitFor (s, OpReq, 4, 0x0a, 4, ID_GetBitmap); 633 return GSM_WaitFor (s, OpReq, 4, 0x0a, 4, ID_GetBitmap);
630 case GSM_PictureImage: 634 case GSM_PictureImage:
631 /* 7110 doesn't support it */ 635 /* 7110 doesn't support it */
632 if (strcmp(s->Phone.Data.Model,"NSE-5") == 0) return ERR_NOTSUPPORTED; 636 if (strcmp(s->Phone.Data.Model,"NSE-5") == 0) return ERR_NOTSUPPORTED;
633 return N7110_GetPictureImage(s, Bitmap); 637 return N7110_GetPictureImage(s, Bitmap);
634 default: 638 default:
635 break; 639 break;
636 } 640 }
637 return ERR_NOTSUPPORTED; 641 return ERR_NOTSUPPORTED;
638} 642}
639 643
640static GSM_Error N7110_SetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength) 644static GSM_Error N7110_SetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength)
641{ 645{
642 GSM_Ringtonedest; 646 GSM_Ringtonedest;
643 GSM_Errorerror; 647 GSM_Errorerror;
644 GSM_NetworkInfoNetInfo; 648 GSM_NetworkInfoNetInfo;
645 int size=200; 649 int size=200;
646 unsigned charreq[1000] = {0x7C, 0x01, 0x00, 0x0D, 0x00, 650 unsigned charreq[1000] = {0x7C, 0x01, 0x00, 0x0D, 0x00,
647 0x00, 0x00, 0x00, 0x00, 0x00, 651 0x00, 0x00, 0x00, 0x00, 0x00,
648 0x00}; /*Length*/ 652 0x00}; /*Length*/
649 unsigned charreq2[4000] = {N7110_FRAME_HEADER, 0x1F, 0x00, 653 unsigned charreq2[4000] = {N7110_FRAME_HEADER, 0x1F, 0x00,
650 0x87, /* Location */ 654 0x87, /* Location */
651 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 655 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
652 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 656 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
653 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 657 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
654 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 658 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
655 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 659 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
656 660
657 switch (Ringtone->Format) { 661 switch (Ringtone->Format) {
658 case RING_NOTETONE: 662 case RING_NOTETONE:
659 if (Ringtone->Location==255) { 663 if (Ringtone->Location==255) {
660 /* 7110 doesn't support it */ 664 /* 7110 doesn't support it */
661 if (strcmp(s->Phone.Data.Model,"NSE-5") == 0) return ERR_NOTSUPPORTED; 665 if (strcmp(s->Phone.Data.Model,"NSE-5") == 0) return ERR_NOTSUPPORTED;
662 *maxlength=GSM_EncodeNokiaRTTLRingtone(*Ringtone, req+11, &size); 666 *maxlength=GSM_EncodeNokiaRTTLRingtone(*Ringtone, req+11, &size);
663 req[10] = size; 667 req[10] = size;
664 error = s->Protocol.Functions->WriteMessage(s, req, size+11, 0x00); 668 error = s->Protocol.Functions->WriteMessage(s, req, size+11, 0x00);
665 if (error!=ERR_NONE) return error; 669 if (error!=ERR_NONE) return error;
666 my_sleep(1000); 670 my_sleep(1000);
667 /* We have to make something (not important, what) now */ 671 /* We have to make something (not important, what) now */
668 /* no answer from phone*/ 672 /* no answer from phone*/
669 return DCT3_GetNetworkInfo(s,&NetInfo); 673 return DCT3_GetNetworkInfo(s,&NetInfo);
670 } 674 }
671 GSM_RingtoneConvert(&dest, Ringtone, RING_NOKIABINARY); 675 GSM_RingtoneConvert(&dest, Ringtone, RING_NOKIABINARY);
672 break; 676 break;
673 case RING_NOKIABINARY: 677 case RING_NOKIABINARY:
674 memcpy(&dest,Ringtone,sizeof(GSM_Ringtone)); 678 memcpy(&dest,Ringtone,sizeof(GSM_Ringtone));
675 break; 679 break;
676 default: 680 default:
677 return ERR_NOTSUPPORTED; 681 return ERR_NOTSUPPORTED;
678 } 682 }
679 req2[5]=N7110_ReturnBinaryRingtoneLocation(s->Phone.Data.Model)+Ringtone->Location; 683 req2[5]=N7110_ReturnBinaryRingtoneLocation(s->Phone.Data.Model)+Ringtone->Location;
680 CopyUnicodeString(req2+6,Ringtone->Name); 684 CopyUnicodeString(req2+6,Ringtone->Name);
681 memcpy(req2+37,dest.NokiaBinary.Frame,dest.NokiaBinary.Length); 685 memcpy(req2+37,dest.NokiaBinary.Frame,dest.NokiaBinary.Length);
682 error = s->Protocol.Functions->WriteMessage(s, req2, 37+dest.NokiaBinary.Length, 0x1F); 686 error = s->Protocol.Functions->WriteMessage(s, req2, 37+dest.NokiaBinary.Length, 0x1F);
683 if (error!=ERR_NONE) return error; 687 if (error!=ERR_NONE) return error;
684 my_sleep(1000); 688 my_sleep(1000);
685 /* We have to make something (not important, what) now */ 689 /* We have to make something (not important, what) now */
686 /* no answer from phone*/ 690 /* no answer from phone*/
687 return DCT3_GetNetworkInfo(s,&NetInfo); 691 return DCT3_GetNetworkInfo(s,&NetInfo);
688} 692}
689 693
690static GSM_Error N7110_ReplySaveSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s) 694static GSM_Error N7110_ReplySaveSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s)
691{ 695{
692 GSM_Phone_Data *Data = &s->Phone.Data; 696 GSM_Phone_Data *Data = &s->Phone.Data;
693 697
694 switch (msg.Buffer[3]) { 698 switch (msg.Buffer[3]) {
695 case 0x05: 699 case 0x05:
696 smprintf(s, "SMS message saving status\n"); 700 smprintf(s, "SMS message saving status\n");
697 smprintf(s, "Saved in folder %i at location %i\n",msg.Buffer[4], msg.Buffer[5]*256+msg.Buffer[6]); 701 smprintf(s, "Saved in folder %i at location %i\n",msg.Buffer[4], msg.Buffer[5]*256+msg.Buffer[6]);
698 if (msg.Buffer[4] == 0xf8) { 702 if (msg.Buffer[4] == 0xf8) {
699 N7110_SetSMSLocation(s, Data->SaveSMSMessage,0x08,msg.Buffer[5]*256+msg.Buffer[6]); 703 N7110_SetSMSLocation(s, Data->SaveSMSMessage,0x08,msg.Buffer[5]*256+msg.Buffer[6]);
700 Data->SaveSMSMessage->Folder = 0x01; 704 Data->SaveSMSMessage->Folder = 0x01;
701 } else { 705 } else {
702 N7110_SetSMSLocation(s, Data->SaveSMSMessage,msg.Buffer[4],msg.Buffer[5]*256+msg.Buffer[6]); 706 N7110_SetSMSLocation(s, Data->SaveSMSMessage,msg.Buffer[4],msg.Buffer[5]*256+msg.Buffer[6]);
703 Data->SaveSMSMessage->Folder = msg.Buffer[4] / 0x08; 707 Data->SaveSMSMessage->Folder = msg.Buffer[4] / 0x08;
704 } 708 }
705 return ERR_NONE; 709 return ERR_NONE;
706 case 0x06: 710 case 0x06:
707 smprintf(s, "SMS message saving status\n"); 711 smprintf(s, "SMS message saving status\n");
708 switch (msg.Buffer[4]) { 712 switch (msg.Buffer[4]) {
709 case 0x03: 713 case 0x03:
710 smprintf(s, "Too high location ?\n"); 714 smprintf(s, "Too high location ?\n");
711 return ERR_INVALIDLOCATION; 715 return ERR_INVALIDLOCATION;
712 default: 716 default:
713 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]); 717 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]);
714 } 718 }
715 break; 719 break;
716 case 0x84: 720 case 0x84:
717 smprintf(s, "Name for SMS changed OK to \"%s\"\n",DecodeUnicodeString(msg.Buffer+7)); 721 smprintf(s, "Name for SMS changed OK to \"%s\"\n",DecodeUnicodeString(msg.Buffer+7));
718 smprintf(s, "Saved in folder %i at location %i\n",msg.Buffer[4], msg.Buffer[5]*256+msg.Buffer[6]); 722 smprintf(s, "Saved in folder %i at location %i\n",msg.Buffer[4], msg.Buffer[5]*256+msg.Buffer[6]);
719 if (msg.Buffer[4] == 0xf8) { 723 if (msg.Buffer[4] == 0xf8) {
720 N7110_SetSMSLocation(s, Data->SaveSMSMessage,0x08,msg.Buffer[5]*256+msg.Buffer[6]); 724 N7110_SetSMSLocation(s, Data->SaveSMSMessage,0x08,msg.Buffer[5]*256+msg.Buffer[6]);
@@ -1458,267 +1462,268 @@ static GSM_Reply_Function N7110ReplyFunctions[] = {
1458 {N71_65_ReplySendDTMF, "\x01",0x03,0x5E,ID_SendDTMF }, 1462 {N71_65_ReplySendDTMF, "\x01",0x03,0x5E,ID_SendDTMF },
1459 1463
1460 {DCT3_ReplySendSMSMessage, "\x02",0x03,0x02,ID_IncomingFrame }, 1464 {DCT3_ReplySendSMSMessage, "\x02",0x03,0x02,ID_IncomingFrame },
1461 {DCT3_ReplySendSMSMessage, "\x02",0x03,0x03,ID_IncomingFrame }, 1465 {DCT3_ReplySendSMSMessage, "\x02",0x03,0x03,ID_IncomingFrame },
1462 {N7110_ReplyIncomingSMS, "\x02",0x03,0x10,ID_IncomingFrame }, 1466 {N7110_ReplyIncomingSMS, "\x02",0x03,0x10,ID_IncomingFrame },
1463#ifdef GSM_ENABLE_CELLBROADCAST 1467#ifdef GSM_ENABLE_CELLBROADCAST
1464 {DCT3_ReplySetIncomingCB, "\x02",0x03,0x21,ID_SetIncomingCB }, 1468 {DCT3_ReplySetIncomingCB, "\x02",0x03,0x21,ID_SetIncomingCB },
1465 {DCT3_ReplySetIncomingCB, "\x02",0x03,0x22,ID_SetIncomingCB }, 1469 {DCT3_ReplySetIncomingCB, "\x02",0x03,0x22,ID_SetIncomingCB },
1466 {DCT3_ReplyIncomingCB, "\x02",0x03,0x23,ID_IncomingFrame }, 1470 {DCT3_ReplyIncomingCB, "\x02",0x03,0x23,ID_IncomingFrame },
1467#endif 1471#endif
1468 {DCT3_ReplySetSMSC, "\x02",0x03,0x31,ID_SetSMSC }, 1472 {DCT3_ReplySetSMSC, "\x02",0x03,0x31,ID_SetSMSC },
1469 {DCT3_ReplyGetSMSC, "\x02",0x03,0x34,ID_GetSMSC }, 1473 {DCT3_ReplyGetSMSC, "\x02",0x03,0x34,ID_GetSMSC },
1470 {DCT3_ReplyGetSMSC, "\x02",0x03,0x35,ID_GetSMSC }, 1474 {DCT3_ReplyGetSMSC, "\x02",0x03,0x35,ID_GetSMSC },
1471#ifdef GSM_ENABLE_CELLBROADCAST 1475#ifdef GSM_ENABLE_CELLBROADCAST
1472 {DCT3_ReplySetIncomingCB, "\x02",0x03,0xCA,ID_SetIncomingCB }, 1476 {DCT3_ReplySetIncomingCB, "\x02",0x03,0xCA,ID_SetIncomingCB },
1473#endif 1477#endif
1474 1478
1475 {N7110_ReplyGetMemoryStatus, "\x03",0x03,0x04,ID_GetMemoryStatus }, 1479 {N7110_ReplyGetMemoryStatus, "\x03",0x03,0x04,ID_GetMemoryStatus },
1476 {N7110_ReplyGetMemory, "\x03",0x03,0x08,ID_GetMemory }, 1480 {N7110_ReplyGetMemory, "\x03",0x03,0x08,ID_GetMemory },
1477 {N7110_ReplyDeleteMemory, "\x03",0x03,0x10,ID_SetMemory }, 1481 {N7110_ReplyDeleteMemory, "\x03",0x03,0x10,ID_SetMemory },
1478 {N71_65_ReplyWritePhonebook, "\x03",0x03,0x0C,ID_SetBitmap }, 1482 {N71_65_ReplyWritePhonebook, "\x03",0x03,0x0C,ID_SetBitmap },
1479 {N71_65_ReplyWritePhonebook, "\x03",0x03,0x0C,ID_SetMemory }, 1483 {N71_65_ReplyWritePhonebook, "\x03",0x03,0x0C,ID_SetMemory },
1480 1484
1481 {N71_65_ReplyUSSDInfo, "\x06",0x03,0x03,ID_IncomingFrame }, 1485 {N71_65_ReplyUSSDInfo, "\x06",0x03,0x03,ID_IncomingFrame },
1482 {NoneReply, "\x06",0x03,0x06,ID_IncomingFrame }, 1486 {NoneReply, "\x06",0x03,0x06,ID_IncomingFrame },
1483 1487
1484 {DCT3_ReplySIMLogin, "\x09",0x03,0x80,ID_IncomingFrame }, 1488 {DCT3_ReplySIMLogin, "\x09",0x03,0x80,ID_IncomingFrame },
1485 {DCT3_ReplySIMLogout, "\x09",0x03,0x81,ID_IncomingFrame }, 1489 {DCT3_ReplySIMLogout, "\x09",0x03,0x81,ID_IncomingFrame },
1486 1490
1487 {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_GetNetworkInfo }, 1491 {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_GetNetworkInfo },
1488 {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_GetBitmap }, 1492 {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_GetBitmap },
1489 {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_IncomingFrame }, 1493 {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_IncomingFrame },
1490 {N7110_ReplyGetNetworkInfoError, "\x0A",0x03,0x72,ID_GetNetworkInfo }, 1494 {N7110_ReplyGetNetworkInfoError, "\x0A",0x03,0x72,ID_GetNetworkInfo },
1491 {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x73,ID_IncomingFrame }, 1495 {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x73,ID_IncomingFrame },
1492 {N71_92_ReplyGetSignalQuality, "\x0A",0x03,0x82,ID_GetSignalQuality }, 1496 {N71_92_ReplyGetSignalQuality, "\x0A",0x03,0x82,ID_GetSignalQuality },
1493 {N7110_ReplySetOperatorLogo, "\x0A",0x03,0xA4,ID_SetBitmap }, 1497 {N7110_ReplySetOperatorLogo, "\x0A",0x03,0xA4,ID_SetBitmap },
1494 {N7110_ReplyClearOperatorLogo, "\x0A",0x03,0xB0,ID_SetBitmap }, 1498 {N7110_ReplyClearOperatorLogo, "\x0A",0x03,0xB0,ID_SetBitmap },
1495 {NoneReply, "\x0A",0x03,0xB5,ID_IncomingFrame }, 1499 {NoneReply, "\x0A",0x03,0xB5,ID_IncomingFrame },
1496 1500
1497#ifdef DEBUG 1501#ifdef DEBUG
1498 {N71_65_ReplyAddCalendar1, "\x13",0x03,0x02,ID_SetCalendarNote },/*method 1*/ 1502 {N71_65_ReplyAddCalendar1, "\x13",0x03,0x02,ID_SetCalendarNote },/*method 1*/
1499 {N71_65_ReplyAddCalendar1, "\x13",0x03,0x04,ID_SetCalendarNote },/*method 1*/ 1503 {N71_65_ReplyAddCalendar1, "\x13",0x03,0x04,ID_SetCalendarNote },/*method 1*/
1500 {N71_65_ReplyAddCalendar1, "\x13",0x03,0x06,ID_SetCalendarNote },/*method 1*/ 1504 {N71_65_ReplyAddCalendar1, "\x13",0x03,0x06,ID_SetCalendarNote },/*method 1*/
1501 {N71_65_ReplyAddCalendar1, "\x13",0x03,0x08,ID_SetCalendarNote },/*method 1*/ 1505 {N71_65_ReplyAddCalendar1, "\x13",0x03,0x08,ID_SetCalendarNote },/*method 1*/
1502#endif 1506#endif
1503 {N71_65_ReplyDelCalendar, "\x13",0x03,0x0C,ID_DeleteCalendarNote }, 1507 {N71_65_ReplyDelCalendar, "\x13",0x03,0x0C,ID_DeleteCalendarNote },
1504 {N71_65_ReplyGetNextCalendar1, "\x13",0x03,0x1A,ID_GetCalendarNote },/*method 1*/ 1508 {N71_65_ReplyGetNextCalendar1, "\x13",0x03,0x1A,ID_GetCalendarNote },/*method 1*/
1505#ifdef DEBUG 1509#ifdef DEBUG
1506 {N7110_ReplyGetCalendarNotePos, "\x13",0x03,0x32,ID_GetCalendarNotePos },/*method 1*/ 1510 {N7110_ReplyGetCalendarNotePos, "\x13",0x03,0x32,ID_GetCalendarNotePos },/*method 1*/
1507#endif 1511#endif
1508 {N7110_ReplyGetCalendarInfo, "\x13",0x03,0x3B,ID_GetCalendarNotesInfo},/*method 1*/ 1512 {N7110_ReplyGetCalendarInfo, "\x13",0x03,0x3B,ID_GetCalendarNotesInfo},/*method 1*/
1509#ifdef DEBUG 1513#ifdef DEBUG
1510 {N71_65_ReplyGetNextCalendar2, "\x13",0x03,0x3F,ID_GetCalendarNote },/*method 2*/ 1514 {N71_65_ReplyGetNextCalendar2, "\x13",0x03,0x3F,ID_GetCalendarNote },/*method 2*/
1511#endif 1515#endif
1512 {N71_65_ReplyAddCalendar2, "\x13",0x03,0x41,ID_SetCalendarNote },/*method 2*/ 1516 {N71_65_ReplyAddCalendar2, "\x13",0x03,0x41,ID_SetCalendarNote },/*method 2*/
1513 1517
1514 {N7110_ReplySaveSMSMessage, "\x14",0x03,0x05,ID_SaveSMSMessage }, 1518 {N7110_ReplySaveSMSMessage, "\x14",0x03,0x05,ID_SaveSMSMessage },
1515 {N7110_ReplySaveSMSMessage, "\x14",0x03,0x06,ID_SaveSMSMessage }, 1519 {N7110_ReplySaveSMSMessage, "\x14",0x03,0x06,ID_SaveSMSMessage },
1516 {N7110_ReplyGetSMSMessage, "\x14",0x03,0x08,ID_GetSMSMessage }, 1520 {N7110_ReplyGetSMSMessage, "\x14",0x03,0x08,ID_GetSMSMessage },
1517 {N7110_ReplyGetSMSMessage, "\x14",0x03,0x08,ID_GetBitmap }, 1521 {N7110_ReplyGetSMSMessage, "\x14",0x03,0x08,ID_GetBitmap },
1518 {N7110_ReplyGetSMSMessage, "\x14",0x03,0x09,ID_GetSMSMessage }, 1522 {N7110_ReplyGetSMSMessage, "\x14",0x03,0x09,ID_GetSMSMessage },
1519 {DCT3_ReplyDeleteSMSMessage, "\x14",0x03,0x0B,ID_DeleteSMSMessage }, 1523 {DCT3_ReplyDeleteSMSMessage, "\x14",0x03,0x0B,ID_DeleteSMSMessage },
1520 {DCT3_ReplyDeleteSMSMessage, "\x14",0x03,0x0C,ID_DeleteSMSMessage }, 1524 {DCT3_ReplyDeleteSMSMessage, "\x14",0x03,0x0C,ID_DeleteSMSMessage },
1521 {N7110_ReplyGetSMSStatus, "\x14",0x03,0x37,ID_GetSMSStatus }, 1525 {N7110_ReplyGetSMSStatus, "\x14",0x03,0x37,ID_GetSMSStatus },
1522 {N7110_ReplyGetSMSStatus, "\x14",0x03,0x38,ID_GetSMSStatus }, 1526 {N7110_ReplyGetSMSStatus, "\x14",0x03,0x38,ID_GetSMSStatus },
1523 {N7110_ReplySetPicture, "\x14",0x03,0x51,ID_SetBitmap }, 1527 {N7110_ReplySetPicture, "\x14",0x03,0x51,ID_SetBitmap },
1524 {N7110_ReplyGetSMSFolderStatus, "\x14",0x03,0x6C,ID_GetSMSFolderStatus }, 1528 {N7110_ReplyGetSMSFolderStatus, "\x14",0x03,0x6C,ID_GetSMSFolderStatus },
1525 {N7110_ReplyGetSMSMessage, "\x14",0x03,0x6F,ID_GetSMSMessage }, 1529 {N7110_ReplyGetSMSMessage, "\x14",0x03,0x6F,ID_GetSMSMessage },
1526 {N7110_ReplyGetSMSFolders, "\x14",0x03,0x7B,ID_GetSMSFolders }, 1530 {N7110_ReplyGetSMSFolders, "\x14",0x03,0x7B,ID_GetSMSFolders },
1527 {N7110_ReplyGetSMSFolders, "\x14",0x03,0x7C,ID_GetSMSFolders }, 1531 {N7110_ReplyGetSMSFolders, "\x14",0x03,0x7C,ID_GetSMSFolders },
1528 {N7110_ReplySaveSMSMessage, "\x14",0x03,0x84,ID_SaveSMSMessage }, 1532 {N7110_ReplySaveSMSMessage, "\x14",0x03,0x84,ID_SaveSMSMessage },
1529 {N7110_ReplyGetPictureImageInfo, "\x14",0x03,0x97,ID_GetBitmap }, 1533 {N7110_ReplyGetPictureImageInfo, "\x14",0x03,0x97,ID_GetBitmap },
1530 {N7110_ReplyGetSMSFolders, "\x14",0x03,0xCA,ID_GetSMSFolders }, 1534 {N7110_ReplyGetSMSFolders, "\x14",0x03,0xCA,ID_GetSMSFolders },
1531 1535
1532 {N71_92_ReplyGetBatteryCharge, "\x17",0x03,0x03,ID_GetBatteryCharge }, 1536 {N71_92_ReplyGetBatteryCharge, "\x17",0x03,0x03,ID_GetBatteryCharge },
1533 1537
1534 {DCT3_ReplySetDateTime, "\x19",0x03,0x61,ID_SetDateTime }, 1538 {DCT3_ReplySetDateTime, "\x19",0x03,0x61,ID_SetDateTime },
1535 {DCT3_ReplyGetDateTime, "\x19",0x03,0x63,ID_GetDateTime }, 1539 {DCT3_ReplyGetDateTime, "\x19",0x03,0x63,ID_GetDateTime },
1536 {DCT3_ReplySetAlarm, "\x19",0x03,0x6C,ID_SetAlarm }, 1540 {DCT3_ReplySetAlarm, "\x19",0x03,0x6C,ID_SetAlarm },
1537 {DCT3_ReplyGetAlarm, "\x19",0x03,0x6E,ID_GetAlarm }, 1541 {DCT3_ReplyGetAlarm, "\x19",0x03,0x6E,ID_GetAlarm },
1538 1542
1539 {N7110_ReplyGetRingtone, "\x1f",0x03,0x23,ID_GetRingtone }, 1543 {N7110_ReplyGetRingtone, "\x1f",0x03,0x23,ID_GetRingtone },
1540 {N7110_ReplyGetRingtone, "\x1f",0x03,0x24,ID_GetRingtone }, 1544 {N7110_ReplyGetRingtone, "\x1f",0x03,0x24,ID_GetRingtone },
1541 1545
1542 {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x01,ID_EnableConnectFunc }, 1546 {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x01,ID_EnableConnectFunc },
1543 {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x02,ID_EnableConnectFunc }, 1547 {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x02,ID_EnableConnectFunc },
1544 {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x04,ID_DisableConnectFunc }, 1548 {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x04,ID_DisableConnectFunc },
1545 {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x05,ID_DisableConnectFunc }, 1549 {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x05,ID_DisableConnectFunc },
1546 {DCT3_ReplyGetWAPBookmark, "\x3f",0x03,0x07,ID_GetWAPBookmark }, 1550 {DCT3_ReplyGetWAPBookmark, "\x3f",0x03,0x07,ID_GetWAPBookmark },
1547 {DCT3_ReplyGetWAPBookmark, "\x3f",0x03,0x08,ID_GetWAPBookmark }, 1551 {DCT3_ReplyGetWAPBookmark, "\x3f",0x03,0x08,ID_GetWAPBookmark },
1548 {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0A,ID_SetWAPBookmark }, 1552 {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0A,ID_SetWAPBookmark },
1549 {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0B,ID_SetWAPBookmark }, 1553 {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0B,ID_SetWAPBookmark },
1550 {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0D,ID_DeleteWAPBookmark }, 1554 {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0D,ID_DeleteWAPBookmark },
1551 {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0E,ID_DeleteWAPBookmark }, 1555 {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0E,ID_DeleteWAPBookmark },
1552 {DCT3DCT4_ReplyGetActiveConnectSet,"\x3f",0x03,0x10,ID_GetConnectSet }, 1556 {DCT3DCT4_ReplyGetActiveConnectSet,"\x3f",0x03,0x10,ID_GetConnectSet },
1553 {DCT3DCT4_ReplySetActiveConnectSet,"\x3f",0x03,0x13,ID_SetConnectSet }, 1557 {DCT3DCT4_ReplySetActiveConnectSet,"\x3f",0x03,0x13,ID_SetConnectSet },
1554 {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x16,ID_GetConnectSet }, 1558 {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x16,ID_GetConnectSet },
1555 {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x17,ID_GetConnectSet }, 1559 {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x17,ID_GetConnectSet },
1556 {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x19,ID_SetConnectSet }, 1560 {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x19,ID_SetConnectSet },
1557 {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x1A,ID_SetConnectSet }, 1561 {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x1A,ID_SetConnectSet },
1558 {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x1C,ID_GetConnectSet }, 1562 {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x1C,ID_GetConnectSet },
1559 {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x1D,ID_GetConnectSet }, 1563 {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x1D,ID_GetConnectSet },
1560 {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x1F,ID_SetConnectSet }, 1564 {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x1F,ID_SetConnectSet },
1561 1565
1562 {N7110_ReplyGetProfileFeature, "\x39",0x03,0x02,ID_GetProfile }, 1566 {N7110_ReplyGetProfileFeature, "\x39",0x03,0x02,ID_GetProfile },
1563 {N7110_ReplySetProfileFeature, "\x39",0x03,0x04,ID_SetProfile }, 1567 {N7110_ReplySetProfileFeature, "\x39",0x03,0x04,ID_SetProfile },
1564 1568
1565 {DCT3_ReplyEnableSecurity, "\x40",0x02,0x64,ID_EnableSecurity }, 1569 {DCT3_ReplyEnableSecurity, "\x40",0x02,0x64,ID_EnableSecurity },
1566 {N61_71_ReplyResetPhoneSettings, "\x40",0x02,0x65,ID_ResetPhoneSettings }, 1570 {N61_71_ReplyResetPhoneSettings, "\x40",0x02,0x65,ID_ResetPhoneSettings },
1567 {DCT3_ReplyGetIMEI, "\x40",0x02,0x66,ID_GetIMEI }, 1571 {DCT3_ReplyGetIMEI, "\x40",0x02,0x66,ID_GetIMEI },
1568 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_DialVoice }, 1572 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_DialVoice },
1569 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_CancelCall }, 1573 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_CancelCall },
1570 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_AnswerCall }, 1574 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_AnswerCall },
1571 {DCT3_ReplyNetmonitor, "\x40",0x02,0x7E,ID_Netmonitor }, 1575 {DCT3_ReplyNetmonitor, "\x40",0x02,0x7E,ID_Netmonitor },
1572 {DCT3_ReplyPlayTone, "\x40",0x02,0x8F,ID_PlayTone }, 1576 {DCT3_ReplyPlayTone, "\x40",0x02,0x8F,ID_PlayTone },
1573 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetHardware }, 1577 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetHardware },
1574 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetPPM }, 1578 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetPPM },
1575 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCA,ID_GetProductCode }, 1579 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCA,ID_GetProductCode },
1576 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetManufactureMonth }, 1580 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetManufactureMonth },
1577 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetOriginalIMEI }, 1581 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetOriginalIMEI },
1578 {NoneReply, "\x40",0x02,0xFF,ID_IncomingFrame }, 1582 {NoneReply, "\x40",0x02,0xFF,ID_IncomingFrame },
1579 1583
1580 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x02,ID_GetBitmap }, 1584 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x02,ID_GetBitmap },
1581 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x02,ID_SetBitmap }, 1585 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x02,ID_SetBitmap },
1582 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x15,ID_GetBitmap }, 1586 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x15,ID_GetBitmap },
1583 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x15,ID_SetBitmap }, 1587 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x15,ID_SetBitmap },
1584 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x17,ID_GetBitmap }, 1588 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x17,ID_GetBitmap },
1585 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x17,ID_SetBitmap }, 1589 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x17,ID_SetBitmap },
1586 1590
1587 {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetModel }, 1591 {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetModel },
1588 {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetFirmware }, 1592 {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetFirmware },
1589 {DCT3_ReplyPressKey, "\xD2",0x02,0x46,ID_PressKey }, 1593 {DCT3_ReplyPressKey, "\xD2",0x02,0x46,ID_PressKey },
1590 {DCT3_ReplyPressKey, "\xD2",0x02,0x47,ID_PressKey }, 1594 {DCT3_ReplyPressKey, "\xD2",0x02,0x47,ID_PressKey },
1591 1595
1592 {NULL, "\x00",0x00,0x00,ID_None } 1596 {NULL, "\x00",0x00,0x00,ID_None }
1593}; 1597};
1594 1598
1595GSM_Phone_Functions N7110Phone = { 1599GSM_Phone_Functions N7110Phone = {
1596 "6210|6250|7110|7190", 1600 "6210|6250|7110|7190",
1597 N7110ReplyFunctions, 1601 N7110ReplyFunctions,
1598 N7110_Initialise, 1602 N7110_Initialise,
1599 PHONE_Terminate, 1603 PHONE_Terminate,
1600 GSM_DispatchMessage, 1604 GSM_DispatchMessage,
1601 NOTSUPPORTED, /* ShowStartInfo */ 1605 NOTSUPPORTED, /* ShowStartInfo */
1602 NOKIA_GetManufacturer, 1606 NOKIA_GetManufacturer,
1603 DCT3DCT4_GetModel, 1607 DCT3DCT4_GetModel,
1604 DCT3DCT4_GetFirmware, 1608 DCT3DCT4_GetFirmware,
1605 DCT3_GetIMEI, 1609 DCT3_GetIMEI,
1606 DCT3_GetOriginalIMEI, 1610 DCT3_GetOriginalIMEI,
1607 DCT3_GetManufactureMonth, 1611 DCT3_GetManufactureMonth,
1608 DCT3_GetProductCode, 1612 DCT3_GetProductCode,
1609 DCT3_GetHardware, 1613 DCT3_GetHardware,
1610 DCT3_GetPPM, 1614 DCT3_GetPPM,
1611 NOTSUPPORTED, /* GetSIMIMSI */ 1615 NOTSUPPORTED, /* GetSIMIMSI */
1612 N71_92_GetDateTime, 1616 N71_92_GetDateTime,
1613 N71_92_SetDateTime, 1617 N71_92_SetDateTime,
1614 N7110_GetAlarm, 1618 N7110_GetAlarm,
1615 N7110_SetAlarm, 1619 N7110_SetAlarm,
1616 NOTSUPPORTED, /* GetLocale */ 1620 NOTSUPPORTED, /* GetLocale */
1617 NOTSUPPORTED, /* SetLocale */ 1621 NOTSUPPORTED, /* SetLocale */
1618 DCT3_PressKey, 1622 DCT3_PressKey,
1619 DCT3_Reset, 1623 DCT3_Reset,
1620 N61_71_ResetPhoneSettings, 1624 N61_71_ResetPhoneSettings,
1621 NOTSUPPORTED, /* EnterSecurityCode*/ 1625 NOTSUPPORTED, /* EnterSecurityCode*/
1622 NOTSUPPORTED, /* GetSecurityStatus*/ 1626 NOTSUPPORTED, /* GetSecurityStatus*/
1623 NOTSUPPORTED, /* GetDisplayStatus*/ 1627 NOTSUPPORTED, /* GetDisplayStatus*/
1624 NOTIMPLEMENTED, /* SetAutoNetworkLogin*/ 1628 NOTIMPLEMENTED, /* SetAutoNetworkLogin*/
1625 N71_92_GetBatteryCharge, 1629 N71_92_GetBatteryCharge,
1626 N71_92_GetSignalQuality, 1630 N71_92_GetSignalQuality,
1627 DCT3_GetNetworkInfo, 1631 DCT3_GetNetworkInfo,
1628 NOTSUPPORTED, /* GetCategory */ 1632 NOTSUPPORTED, /* GetCategory */
1629 NOTSUPPORTED, /* AddCategory */ 1633 NOTSUPPORTED, /* AddCategory */
1630 NOTSUPPORTED, /* GetCategoryStatus */ 1634 NOTSUPPORTED, /* GetCategoryStatus */
1631 N7110_GetMemoryStatus, 1635 N7110_GetMemoryStatus,
1632 N7110_GetMemory, 1636 N7110_GetMemory,
1633 NOTIMPLEMENTED, /* GetNextMemory */ 1637 NOTIMPLEMENTED, /* GetNextMemory */
1634 N7110_SetMemory, 1638 N7110_SetMemory,
1635 NOTIMPLEMENTED, /* AddMemory */ 1639 NOTIMPLEMENTED, /* AddMemory */
1636 N7110_DeleteMemory, 1640 N7110_DeleteMemory,
1637 NOTIMPLEMENTED, /* DeleteAllMemory */ 1641 NOTIMPLEMENTED, /* DeleteAllMemory */
1638 N7110_GetSpeedDial, 1642 N7110_GetSpeedDial,
1639 NOTIMPLEMENTED, /* SetSpeedDial */ 1643 NOTIMPLEMENTED, /* SetSpeedDial */
1640 DCT3_GetSMSC, 1644 DCT3_GetSMSC,
1641 DCT3_SetSMSC, 1645 DCT3_SetSMSC,
1642 N7110_GetSMSStatus, 1646 N7110_GetSMSStatus,
1643 N7110_GetSMSMessage, 1647 N7110_GetSMSMessage,
1644 N7110_GetNextSMSMessage, 1648 N7110_GetNextSMSMessage,
1645 N7110_SetSMS, 1649 N7110_SetSMS,
1646 N7110_AddSMS, 1650 N7110_AddSMS,
1647 N7110_DeleteSMS, 1651 N7110_DeleteSMS,
1648 DCT3_SendSMSMessage, 1652 DCT3_SendSMSMessage,
1649 NOTSUPPORTED, /* SendSavedSMS */ 1653 NOTSUPPORTED, /* SendSavedSMS */
1654 NOTSUPPORTED, /* SetFastSMSSending*/
1650 N7110_SetIncomingSMS, 1655 N7110_SetIncomingSMS,
1651 DCT3_SetIncomingCB, 1656 DCT3_SetIncomingCB,
1652 N7110_GetSMSFolders, 1657 N7110_GetSMSFolders,
1653 NOTIMPLEMENTED, /* AddSMSFolder */ 1658 NOTIMPLEMENTED, /* AddSMSFolder */
1654 NOTIMPLEMENTED, /* DeleteSMSFolder */ 1659 NOTIMPLEMENTED, /* DeleteSMSFolder */
1655 DCT3_DialVoice, 1660 DCT3_DialVoice,
1656 N7110_AnswerCall, 1661 N7110_AnswerCall,
1657 DCT3_CancelCall, 1662 DCT3_CancelCall,
1658 NOTIMPLEMENTED, /* HoldCall */ 1663 NOTIMPLEMENTED, /* HoldCall */
1659 NOTIMPLEMENTED, /* UnholdCall */ 1664 NOTIMPLEMENTED, /* UnholdCall */
1660 NOTIMPLEMENTED, /* ConferenceCall */ 1665 NOTIMPLEMENTED, /* ConferenceCall */
1661 NOTIMPLEMENTED, /* SplitCall */ 1666 NOTIMPLEMENTED, /* SplitCall */
1662 NOTIMPLEMENTED, /* TransferCall */ 1667 NOTIMPLEMENTED, /* TransferCall */
1663 NOTIMPLEMENTED, /* SwitchCall */ 1668 NOTIMPLEMENTED, /* SwitchCall */
1664 NOTSUPPORTED, /* GetCallDivert */ 1669 NOTSUPPORTED, /* GetCallDivert */
1665 N7110_SetCallDivert, 1670 N7110_SetCallDivert,
1666 N7110_CancelAllDiverts, 1671 N7110_CancelAllDiverts,
1667 N7110_SetIncomingCall, 1672 N7110_SetIncomingCall,
1668 N7110_SetIncomingUSSD, 1673 N7110_SetIncomingUSSD,
1669 DCT3DCT4_SendDTMF, 1674 DCT3DCT4_SendDTMF,
1670 N7110_GetRingtone, 1675 N7110_GetRingtone,
1671 N7110_SetRingtone, 1676 N7110_SetRingtone,
1672 NOTSUPPORTED, /* GetRingtonesInfo*/ 1677 NOTSUPPORTED, /* GetRingtonesInfo*/
1673 NOTSUPPORTED, /* DeleteUserRingtones*/ 1678 NOTSUPPORTED, /* DeleteUserRingtones*/
1674 DCT3_PlayTone, 1679 DCT3_PlayTone,
1675 DCT3_GetWAPBookmark, 1680 DCT3_GetWAPBookmark,
1676 DCT3_SetWAPBookmark, 1681 DCT3_SetWAPBookmark,
1677 DCT3_DeleteWAPBookmark, 1682 DCT3_DeleteWAPBookmark,
1678 DCT3_GetWAPSettings, 1683 DCT3_GetWAPSettings,
1679 DCT3_SetWAPSettings, 1684 DCT3_SetWAPSettings,
1680 NOTSUPPORTED, /* GetMMSSettings */ 1685 NOTSUPPORTED, /* GetMMSSettings */
1681 NOTSUPPORTED, /* SetMMSSettings */ 1686 NOTSUPPORTED, /* SetMMSSettings */
1682 NOTSUPPORTED, /* GetSyncMLSettings*/ 1687 NOTSUPPORTED, /* GetSyncMLSettings*/
1683 NOTSUPPORTED, /* SetSyncMLSettings*/ 1688 NOTSUPPORTED, /* SetSyncMLSettings*/
1684 NOTSUPPORTED, /* GetChatSettings */ 1689 NOTSUPPORTED, /* GetChatSettings */
1685 NOTSUPPORTED, /* SetChatSettings */ 1690 NOTSUPPORTED, /* SetChatSettings */
1686 N7110_GetBitmap, 1691 N7110_GetBitmap,
1687 N7110_SetBitmap, 1692 N7110_SetBitmap,
1688 NOTSUPPORTED, /* GetToDoStatus */ 1693 NOTSUPPORTED, /* GetToDoStatus */
1689 NOTSUPPORTED, /* GetToDo */ 1694 NOTSUPPORTED, /* GetToDo */
1690 NOTSUPPORTED, /* GetNextToDo */ 1695 NOTSUPPORTED, /* GetNextToDo */
1691 NOTSUPPORTED, /* SetToDo */ 1696 NOTSUPPORTED, /* SetToDo */
1692 NOTSUPPORTED, /* AddToDo */ 1697 NOTSUPPORTED, /* AddToDo */
1693 NOTSUPPORTED, /* DeleteToDo */ 1698 NOTSUPPORTED, /* DeleteToDo */
1694 NOTSUPPORTED, /* DeleteAllToDo */ 1699 NOTSUPPORTED, /* DeleteAllToDo */
1695 N7110_GetCalendarStatus, 1700 N7110_GetCalendarStatus,
1696 NOTIMPLEMENTED, /* GetCalendar */ 1701 NOTIMPLEMENTED, /* GetCalendar */
1697 N7110_GetNextCalendar, 1702 N7110_GetNextCalendar,
1698 NOTIMPLEMENTED, /* SetCalendar */ 1703 NOTIMPLEMENTED, /* SetCalendar */
1699 N7110_AddCalendar, 1704 N7110_AddCalendar,
1700 N71_65_DelCalendar, 1705 N71_65_DelCalendar,
1701 NOTIMPLEMENTED, /* DeleteAllCalendar*/ 1706 NOTIMPLEMENTED, /* DeleteAllCalendar*/
1702 NOTSUPPORTED, /* GetCalendarSettings*/ 1707 NOTSUPPORTED, /* GetCalendarSettings*/
1703 NOTSUPPORTED, /* SetCalendarSettings*/ 1708 NOTSUPPORTED, /* SetCalendarSettings*/
1704 NOTSUPPORTED, /* GetNote */ 1709 NOTSUPPORTED, /* GetNextNote */
1705 N7110_GetProfile, 1710 N7110_GetProfile,
1706 N7110_SetProfile, 1711 N7110_SetProfile,
1707 NOTSUPPORTED, /* GetFMStation */ 1712 NOTSUPPORTED, /* GetFMStation */
1708 NOTSUPPORTED, /* SetFMStation */ 1713 NOTSUPPORTED, /* SetFMStation */
1709 NOTSUPPORTED, /* ClearFMStations */ 1714 NOTSUPPORTED, /* ClearFMStations */
1710 NOTSUPPORTED, /* GetNextFileFolder*/ 1715 NOTSUPPORTED, /* GetNextFileFolder*/
1711 NOTSUPPORTED, /* GetFilePart */ 1716 NOTSUPPORTED, /* GetFilePart */
1712 NOTSUPPORTED, /* AddFile */ 1717 NOTSUPPORTED, /* AddFile */
1713 NOTSUPPORTED, /* GetFileSystemStatus*/ 1718 NOTSUPPORTED, /* GetFileSystemStatus*/
1714 NOTSUPPORTED, /* DeleteFile */ 1719 NOTSUPPORTED, /* DeleteFile */
1715 NOTSUPPORTED, /* AddFolder */ 1720 NOTSUPPORTED, /* AddFolder */
1716 NOTSUPPORTED, /* GetGPRSAccessPoint*/ 1721 NOTSUPPORTED, /* GetGPRSAccessPoint*/
1717 NOTSUPPORTED /* SetGPRSAccessPoint*/ 1722 NOTSUPPORTED /* SetGPRSAccessPoint*/
1718}; 1723};
1719 1724
1720#endif 1725#endif
1721 1726
1722/* How should editor hadle tabs in this file? Add editor commands here. 1727/* How should editor hadle tabs in this file? Add editor commands here.
1723 * vim: noexpandtab sw=8 ts=8 sts=8: 1728 * vim: noexpandtab sw=8 ts=8 sts=8:
1724 */ 1729 */
diff --git a/gammu/emb/common/phone/nokia/dct3/n9210.c b/gammu/emb/common/phone/nokia/dct3/n9210.c
index e82d530..ff71ad3 100644
--- a/gammu/emb/common/phone/nokia/dct3/n9210.c
+++ b/gammu/emb/common/phone/nokia/dct3/n9210.c
@@ -130,267 +130,268 @@ static GSM_Error N9210_SetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
130 130
131static GSM_Error N9210_ReplyIncomingSMS(GSM_Protocol_Message msg, GSM_StateMachine *s) 131static GSM_Error N9210_ReplyIncomingSMS(GSM_Protocol_Message msg, GSM_StateMachine *s)
132{ 132{
133 GSM_SMSMessage sms; 133 GSM_SMSMessage sms;
134 GSM_Phone_Data *Data = &s->Phone.Data; 134 GSM_Phone_Data *Data = &s->Phone.Data;
135 135
136#ifdef DEBUG 136#ifdef DEBUG
137 smprintf(s, "SMS message received\n"); 137 smprintf(s, "SMS message received\n");
138 sms.State = SMS_UnRead; 138 sms.State = SMS_UnRead;
139 sms.InboxFolder = true; 139 sms.InboxFolder = true;
140 DCT3_DecodeSMSFrame(s, &sms,msg.Buffer+5); 140 DCT3_DecodeSMSFrame(s, &sms,msg.Buffer+5);
141#endif 141#endif
142 if (Data->EnableIncomingSMS && s->User.IncomingSMS!=NULL) { 142 if (Data->EnableIncomingSMS && s->User.IncomingSMS!=NULL) {
143 sms.State = SMS_UnRead; 143 sms.State = SMS_UnRead;
144 sms.InboxFolder = true; 144 sms.InboxFolder = true;
145 DCT3_DecodeSMSFrame(s, &sms,msg.Buffer+5); 145 DCT3_DecodeSMSFrame(s, &sms,msg.Buffer+5);
146 146
147 s->User.IncomingSMS(s->CurrentConfig->Device,sms); 147 s->User.IncomingSMS(s->CurrentConfig->Device,sms);
148 } 148 }
149 return ERR_NONE; 149 return ERR_NONE;
150} 150}
151 151
152#ifdef GSM_ENABLE_N71_92INCOMINGINFO 152#ifdef GSM_ENABLE_N71_92INCOMINGINFO
153static GSM_Error N9210_ReplySetIncomingSMS(GSM_Protocol_Message msg, GSM_StateMachine *s) 153static GSM_Error N9210_ReplySetIncomingSMS(GSM_Protocol_Message msg, GSM_StateMachine *s)
154{ 154{
155 switch (msg.Buffer[3]) { 155 switch (msg.Buffer[3]) {
156 case 0x0e: 156 case 0x0e:
157 s->Phone.Data.EnableIncomingSMS = true; 157 s->Phone.Data.EnableIncomingSMS = true;
158 smprintf(s, "Incoming SMS enabled\n"); 158 smprintf(s, "Incoming SMS enabled\n");
159 return ERR_NONE; 159 return ERR_NONE;
160 case 0x0f: 160 case 0x0f:
161 smprintf(s, "Error enabling incoming SMS\n"); 161 smprintf(s, "Error enabling incoming SMS\n");
162 switch (msg.Buffer[4]) { 162 switch (msg.Buffer[4]) {
163 case 0x0c: 163 case 0x0c:
164 smprintf(s, "No PIN ?\n"); 164 smprintf(s, "No PIN ?\n");
165 return ERR_SECURITYERROR; 165 return ERR_SECURITYERROR;
166 default: 166 default:
167 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]); 167 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]);
168 } 168 }
169 } 169 }
170 return ERR_UNKNOWNRESPONSE; 170 return ERR_UNKNOWNRESPONSE;
171} 171}
172#endif 172#endif
173 173
174static GSM_Error N9210_SetIncomingSMS(GSM_StateMachine *s, bool enable) 174static GSM_Error N9210_SetIncomingSMS(GSM_StateMachine *s, bool enable)
175{ 175{
176#ifdef GSM_ENABLE_N71_92INCOMINGINFO 176#ifdef GSM_ENABLE_N71_92INCOMINGINFO
177 unsigned char req[] = {N6110_FRAME_HEADER, 0x0d, 0x00, 0x00, 0x02}; 177 unsigned char req[] = {N6110_FRAME_HEADER, 0x0d, 0x00, 0x00, 0x02};
178 178
179 if (enable!=s->Phone.Data.EnableIncomingSMS) { 179 if (enable!=s->Phone.Data.EnableIncomingSMS) {
180 if (enable) { 180 if (enable) {
181 smprintf(s, "Enabling incoming SMS\n"); 181 smprintf(s, "Enabling incoming SMS\n");
182 return GSM_WaitFor (s, req, 7, 0x02, 4, ID_SetIncomingSMS); 182 return GSM_WaitFor (s, req, 7, 0x02, 4, ID_SetIncomingSMS);
183 } else { 183 } else {
184 s->Phone.Data.EnableIncomingSMS = false; 184 s->Phone.Data.EnableIncomingSMS = false;
185 smprintf(s, "Disabling incoming SMS\n"); 185 smprintf(s, "Disabling incoming SMS\n");
186 } 186 }
187 } 187 }
188 return ERR_NONE; 188 return ERR_NONE;
189#else 189#else
190 return ERR_SOURCENOTAVAILABLE; 190 return ERR_SOURCENOTAVAILABLE;
191#endif 191#endif
192} 192}
193 193
194static GSM_Error N9210_Initialise (GSM_StateMachine *s) 194static GSM_Error N9210_Initialise (GSM_StateMachine *s)
195{ 195{
196#ifdef DEBUG 196#ifdef DEBUG
197 DCT3_SetIncomingCB(s,true); 197 DCT3_SetIncomingCB(s,true);
198 198
199#ifdef GSM_ENABLE_N71_92INCOMINGINFO 199#ifdef GSM_ENABLE_N71_92INCOMINGINFO
200 N9210_SetIncomingSMS(s,true); 200 N9210_SetIncomingSMS(s,true);
201#endif 201#endif
202 202
203#endif 203#endif
204 return ERR_NONE; 204 return ERR_NONE;
205} 205}
206 206
207GSM_Error N9210_AnswerCall(GSM_StateMachine *s, int ID, bool all) 207GSM_Error N9210_AnswerCall(GSM_StateMachine *s, int ID, bool all)
208{ 208{
209 if (!all) return DCT3DCT4_AnswerCall(s,ID); 209 if (!all) return DCT3DCT4_AnswerCall(s,ID);
210 return DCT3_AnswerAllCalls(s); 210 return DCT3_AnswerAllCalls(s);
211} 211}
212 212
213static GSM_Reply_Function N9210ReplyFunctions[] = { 213static GSM_Reply_Function N9210ReplyFunctions[] = {
214 {DCT3_ReplySendSMSMessage, "\x02",0x03,0x02,ID_IncomingFrame}, 214 {DCT3_ReplySendSMSMessage, "\x02",0x03,0x02,ID_IncomingFrame},
215 {DCT3_ReplySendSMSMessage, "\x02",0x03,0x03,ID_IncomingFrame}, 215 {DCT3_ReplySendSMSMessage, "\x02",0x03,0x03,ID_IncomingFrame},
216#ifdef GSM_ENABLE_N71_92INCOMINGINFO 216#ifdef GSM_ENABLE_N71_92INCOMINGINFO
217 {N9210_ReplySetIncomingSMS, "\x02",0x03,0x0E,ID_SetIncomingSMS}, 217 {N9210_ReplySetIncomingSMS, "\x02",0x03,0x0E,ID_SetIncomingSMS},
218 {N9210_ReplySetIncomingSMS, "\x02",0x03,0x0F,ID_SetIncomingSMS}, 218 {N9210_ReplySetIncomingSMS, "\x02",0x03,0x0F,ID_SetIncomingSMS},
219#endif 219#endif
220 {N9210_ReplyIncomingSMS, "\x02",0x03,0x11,ID_IncomingFrame}, 220 {N9210_ReplyIncomingSMS, "\x02",0x03,0x11,ID_IncomingFrame},
221#ifdef GSM_ENABLE_CELLBROADCAST 221#ifdef GSM_ENABLE_CELLBROADCAST
222 {DCT3_ReplySetIncomingCB, "\x02",0x03,0x21,ID_SetIncomingCB}, 222 {DCT3_ReplySetIncomingCB, "\x02",0x03,0x21,ID_SetIncomingCB},
223 {DCT3_ReplySetIncomingCB, "\x02",0x03,0x22,ID_SetIncomingCB}, 223 {DCT3_ReplySetIncomingCB, "\x02",0x03,0x22,ID_SetIncomingCB},
224 {DCT3_ReplyIncomingCB, "\x02",0x03,0x23,ID_IncomingFrame}, 224 {DCT3_ReplyIncomingCB, "\x02",0x03,0x23,ID_IncomingFrame},
225#endif 225#endif
226 {DCT3_ReplySetSMSC, "\x02",0x03,0x31,ID_SetSMSC }, 226 {DCT3_ReplySetSMSC, "\x02",0x03,0x31,ID_SetSMSC },
227 {DCT3_ReplyGetSMSC, "\x02",0x03,0x34,ID_GetSMSC }, 227 {DCT3_ReplyGetSMSC, "\x02",0x03,0x34,ID_GetSMSC },
228 {DCT3_ReplyGetSMSC, "\x02",0x03,0x35,ID_GetSMSC }, 228 {DCT3_ReplyGetSMSC, "\x02",0x03,0x35,ID_GetSMSC },
229 229
230 {N61_91_ReplySetOpLogo, "\x05",0x03,0x31,ID_SetBitmap }, 230 {N61_91_ReplySetOpLogo, "\x05",0x03,0x31,ID_SetBitmap },
231 {N61_91_ReplySetOpLogo, "\x05",0x03,0x32,ID_SetBitmap }, 231 {N61_91_ReplySetOpLogo, "\x05",0x03,0x32,ID_SetBitmap },
232 232
233 {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_GetNetworkInfo}, 233 {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_GetNetworkInfo},
234 {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_IncomingFrame}, 234 {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_IncomingFrame},
235 {N71_92_ReplyGetSignalQuality, "\x0A",0x03,0x82,ID_GetSignalQuality}, 235 {N71_92_ReplyGetSignalQuality, "\x0A",0x03,0x82,ID_GetSignalQuality},
236 {N9210_ReplySetOpLogo, "\x0A",0x03,0xA4,ID_SetBitmap }, 236 {N9210_ReplySetOpLogo, "\x0A",0x03,0xA4,ID_SetBitmap },
237 {N9210_ReplySetOpLogo, "\x0A",0x03,0xB0,ID_SetBitmap }, 237 {N9210_ReplySetOpLogo, "\x0A",0x03,0xB0,ID_SetBitmap },
238 238
239 {N71_92_ReplyGetBatteryCharge, "\x17",0x03,0x03,ID_GetBatteryCharge}, 239 {N71_92_ReplyGetBatteryCharge, "\x17",0x03,0x03,ID_GetBatteryCharge},
240 240
241 {DCT3_ReplySetDateTime, "\x19",0x03,0x61,ID_SetDateTime }, 241 {DCT3_ReplySetDateTime, "\x19",0x03,0x61,ID_SetDateTime },
242 {DCT3_ReplyGetDateTime, "\x19",0x03,0x63,ID_GetDateTime }, 242 {DCT3_ReplyGetDateTime, "\x19",0x03,0x63,ID_GetDateTime },
243 243
244 {DCT3_ReplyEnableSecurity, "\x40",0x02,0x64,ID_EnableSecurity}, 244 {DCT3_ReplyEnableSecurity, "\x40",0x02,0x64,ID_EnableSecurity},
245 {DCT3_ReplyGetIMEI, "\x40",0x02,0x66,ID_GetIMEI }, 245 {DCT3_ReplyGetIMEI, "\x40",0x02,0x66,ID_GetIMEI },
246 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_DialVoice }, 246 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_DialVoice },
247 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_CancelCall }, 247 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_CancelCall },
248 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_AnswerCall }, 248 {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_AnswerCall },
249 {DCT3_ReplyNetmonitor, "\x40",0x02,0x7E,ID_Netmonitor }, 249 {DCT3_ReplyNetmonitor, "\x40",0x02,0x7E,ID_Netmonitor },
250 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetHardware }, 250 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetHardware },
251 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetPPM }, 251 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetPPM },
252 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCA,ID_GetProductCode}, 252 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCA,ID_GetProductCode},
253 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetManufactureMonth}, 253 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetManufactureMonth},
254 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetOriginalIMEI}, 254 {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetOriginalIMEI},
255 255
256 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x02,ID_GetBitmap }, 256 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x02,ID_GetBitmap },
257 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x02,ID_SetBitmap }, 257 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x02,ID_SetBitmap },
258 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x15,ID_GetBitmap }, 258 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x15,ID_GetBitmap },
259 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x15,ID_SetBitmap }, 259 {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x15,ID_SetBitmap },
260 260
261 {DCT3DCT4_ReplyGetModelFirmware,"\xD2",0x02,0x00,ID_GetModel }, 261 {DCT3DCT4_ReplyGetModelFirmware,"\xD2",0x02,0x00,ID_GetModel },
262 {DCT3DCT4_ReplyGetModelFirmware,"\xD2",0x02,0x00,ID_GetFirmware }, 262 {DCT3DCT4_ReplyGetModelFirmware,"\xD2",0x02,0x00,ID_GetFirmware },
263 263
264 {NULL, "\x00",0x00,0x00,ID_None } 264 {NULL, "\x00",0x00,0x00,ID_None }
265}; 265};
266 266
267GSM_Phone_Functions N9210Phone = { 267GSM_Phone_Functions N9210Phone = {
268 "9210|9210i", 268 "9210|9210i",
269 N9210ReplyFunctions, 269 N9210ReplyFunctions,
270 N9210_Initialise, 270 N9210_Initialise,
271 PHONE_Terminate, 271 PHONE_Terminate,
272 GSM_DispatchMessage, 272 GSM_DispatchMessage,
273 NOTSUPPORTED, /* ShowStartInfo */ 273 NOTSUPPORTED, /* ShowStartInfo */
274 NOKIA_GetManufacturer, 274 NOKIA_GetManufacturer,
275 DCT3DCT4_GetModel, 275 DCT3DCT4_GetModel,
276 DCT3DCT4_GetFirmware, 276 DCT3DCT4_GetFirmware,
277 DCT3_GetIMEI, 277 DCT3_GetIMEI,
278 DCT3_GetOriginalIMEI, 278 DCT3_GetOriginalIMEI,
279 DCT3_GetManufactureMonth, 279 DCT3_GetManufactureMonth,
280 DCT3_GetProductCode, 280 DCT3_GetProductCode,
281 DCT3_GetHardware, 281 DCT3_GetHardware,
282 DCT3_GetPPM, 282 DCT3_GetPPM,
283 NOTSUPPORTED, /* GetSIMIMSI */ 283 NOTSUPPORTED, /* GetSIMIMSI */
284 N71_92_GetDateTime, 284 N71_92_GetDateTime,
285 N71_92_SetDateTime, 285 N71_92_SetDateTime,
286 NOTIMPLEMENTED, /* GetAlarm */ 286 NOTIMPLEMENTED, /* GetAlarm */
287 NOTIMPLEMENTED, /* SetAlarm */ 287 NOTIMPLEMENTED, /* SetAlarm */
288 NOTSUPPORTED, /* GetLocale */ 288 NOTSUPPORTED, /* GetLocale */
289 NOTSUPPORTED, /* SetLocale */ 289 NOTSUPPORTED, /* SetLocale */
290 NOTIMPLEMENTED, /* PressKey */ 290 NOTIMPLEMENTED, /* PressKey */
291 NOTIMPLEMENTED, /* Reset */ 291 NOTIMPLEMENTED, /* Reset */
292 NOTIMPLEMENTED, /* ResetPhoneSettings*/ 292 NOTIMPLEMENTED, /* ResetPhoneSettings*/
293 NOTSUPPORTED, /* EnterSecurityCode*/ 293 NOTSUPPORTED, /* EnterSecurityCode*/
294 NOTSUPPORTED, /* GetSecurityStatus*/ 294 NOTSUPPORTED, /* GetSecurityStatus*/
295 NOTSUPPORTED, /* GetDisplayStatus*/ 295 NOTSUPPORTED, /* GetDisplayStatus*/
296 NOTIMPLEMENTED, /* SetAutoNetworkLogin*/ 296 NOTIMPLEMENTED, /* SetAutoNetworkLogin*/
297 N71_92_GetBatteryCharge, 297 N71_92_GetBatteryCharge,
298 N71_92_GetSignalQuality, 298 N71_92_GetSignalQuality,
299 DCT3_GetNetworkInfo, 299 DCT3_GetNetworkInfo,
300 NOTSUPPORTED, /* GetCategory */ 300 NOTSUPPORTED, /* GetCategory */
301 NOTSUPPORTED, /* AddCategory */ 301 NOTSUPPORTED, /* AddCategory */
302 NOTSUPPORTED, /* GetCategoryStatus */ 302 NOTSUPPORTED, /* GetCategoryStatus */
303 NOTIMPLEMENTED, /* GetMemoryStatus */ 303 NOTIMPLEMENTED, /* GetMemoryStatus */
304 NOTIMPLEMENTED, /* GetMemory */ 304 NOTIMPLEMENTED, /* GetMemory */
305 NOTIMPLEMENTED, /* GetNextMemory */ 305 NOTIMPLEMENTED, /* GetNextMemory */
306 NOTIMPLEMENTED, /* SetMemory */ 306 NOTIMPLEMENTED, /* SetMemory */
307 NOTIMPLEMENTED, /* AddMemory */ 307 NOTIMPLEMENTED, /* AddMemory */
308 NOTIMPLEMENTED, /* DeleteMemory */ 308 NOTIMPLEMENTED, /* DeleteMemory */
309 NOTIMPLEMENTED, /* DeleteAllMemory */ 309 NOTIMPLEMENTED, /* DeleteAllMemory */
310 NOTIMPLEMENTED, /* GetSpeedDial */ 310 NOTIMPLEMENTED, /* GetSpeedDial */
311 NOTIMPLEMENTED, /* SetSpeedDial */ 311 NOTIMPLEMENTED, /* SetSpeedDial */
312 DCT3_GetSMSC, 312 DCT3_GetSMSC,
313 DCT3_SetSMSC, /* FIXME: test it */ 313 DCT3_SetSMSC, /* FIXME: test it */
314 NOTIMPLEMENTED, /* GetSMSStatus */ 314 NOTIMPLEMENTED, /* GetSMSStatus */
315 NOTIMPLEMENTED, /* GetSMS */ 315 NOTIMPLEMENTED, /* GetSMS */
316 NOTIMPLEMENTED, /* GetNextSMS */ 316 NOTIMPLEMENTED, /* GetNextSMS */
317 NOTIMPLEMENTED, /* SetSMS */ 317 NOTIMPLEMENTED, /* SetSMS */
318 NOTIMPLEMENTED, /* AddSMS */ 318 NOTIMPLEMENTED, /* AddSMS */
319 NOTIMPLEMENTED, /* DeleteSMS */ 319 NOTIMPLEMENTED, /* DeleteSMS */
320 DCT3_SendSMSMessage, 320 DCT3_SendSMSMessage,
321 NOTSUPPORTED, /* SendSavedSMS */ 321 NOTSUPPORTED, /* SendSavedSMS */
322 NOTSUPPORTED, /* SetFastSMSSending*/
322 N9210_SetIncomingSMS, 323 N9210_SetIncomingSMS,
323 DCT3_SetIncomingCB, 324 DCT3_SetIncomingCB,
324 NOTIMPLEMENTED, /* GetSMSFolders */ 325 NOTIMPLEMENTED, /* GetSMSFolders */
325 NOTSUPPORTED, /* AddSMSFolder */ 326 NOTSUPPORTED, /* AddSMSFolder */
326 NOTSUPPORTED, /* DeleteSMSFolder */ 327 NOTSUPPORTED, /* DeleteSMSFolder */
327 DCT3_DialVoice, 328 DCT3_DialVoice,
328 N9210_AnswerCall, 329 N9210_AnswerCall,
329 DCT3_CancelCall, 330 DCT3_CancelCall,
330 NOTSUPPORTED, /* HoldCall */ 331 NOTSUPPORTED, /* HoldCall */
331 NOTSUPPORTED, /* UnholdCall */ 332 NOTSUPPORTED, /* UnholdCall */
332 NOTSUPPORTED, /* ConferenceCall */ 333 NOTSUPPORTED, /* ConferenceCall */
333 NOTSUPPORTED, /* SplitCall */ 334 NOTSUPPORTED, /* SplitCall */
334 NOTSUPPORTED, /* TransferCall */ 335 NOTSUPPORTED, /* TransferCall */
335 NOTSUPPORTED, /* SwitchCall */ 336 NOTSUPPORTED, /* SwitchCall */
336 NOTSUPPORTED, /* GetCallDivert */ 337 NOTSUPPORTED, /* GetCallDivert */
337 NOTSUPPORTED, /* SetCallDivert */ 338 NOTSUPPORTED, /* SetCallDivert */
338 NOTSUPPORTED, /* CancelAllDiverts*/ 339 NOTSUPPORTED, /* CancelAllDiverts*/
339 NOTSUPPORTED, /* SetIncomingCall */ 340 NOTSUPPORTED, /* SetIncomingCall */
340 NOTIMPLEMENTED, /* SetIncomingUSSD */ 341 NOTIMPLEMENTED, /* SetIncomingUSSD */
341 NOTSUPPORTED, /* SendDTMF */ 342 NOTSUPPORTED, /* SendDTMF */
342 NOTIMPLEMENTED, /* GetRingtone */ 343 NOTIMPLEMENTED, /* GetRingtone */
343 NOTIMPLEMENTED, /* SetRingtone */ 344 NOTIMPLEMENTED, /* SetRingtone */
344 NOTSUPPORTED, /* GetRingtonesInfo*/ 345 NOTSUPPORTED, /* GetRingtonesInfo*/
345 NOTSUPPORTED, /* DeleteUserRingtones*/ 346 NOTSUPPORTED, /* DeleteUserRingtones*/
346 NOTSUPPORTED, /* PlayTone */ 347 NOTSUPPORTED, /* PlayTone */
347 NOTIMPLEMENTED, /* GetWAPBookmark */ 348 NOTIMPLEMENTED, /* GetWAPBookmark */
348 NOTIMPLEMENTED, /* SetWAPBookmark */ 349 NOTIMPLEMENTED, /* SetWAPBookmark */
349 NOTIMPLEMENTED, /* DeleteWAPBookmark */ 350 NOTIMPLEMENTED, /* DeleteWAPBookmark */
350 NOTIMPLEMENTED, /* GetWAPSettings */ 351 NOTIMPLEMENTED, /* GetWAPSettings */
351 NOTSUPPORTED, /* SetWAPSettings */ 352 NOTSUPPORTED, /* SetWAPSettings */
352 NOTSUPPORTED, /* GetMMSSettings */ 353 NOTSUPPORTED, /* GetMMSSettings */
353 NOTSUPPORTED, /* SetMMSSettings */ 354 NOTSUPPORTED, /* SetMMSSettings */
354 NOTSUPPORTED, /* GetSyncMLSettings*/ 355 NOTSUPPORTED, /* GetSyncMLSettings*/
355 NOTSUPPORTED, /* SetSyncMLSettings*/ 356 NOTSUPPORTED, /* SetSyncMLSettings*/
356 NOTSUPPORTED, /* GetChatSettings */ 357 NOTSUPPORTED, /* GetChatSettings */
357 NOTSUPPORTED, /* SetChatSettings */ 358 NOTSUPPORTED, /* SetChatSettings */
358 N9210_GetBitmap, 359 N9210_GetBitmap,
359 N9210_SetBitmap, 360 N9210_SetBitmap,
360 NOTSUPPORTED, /* GetToDoStatus */ 361 NOTSUPPORTED, /* GetToDoStatus */
361 NOTSUPPORTED, /* GetToDo */ 362 NOTSUPPORTED, /* GetToDo */
362 NOTSUPPORTED, /* GetNextToDo */ 363 NOTSUPPORTED, /* GetNextToDo */
363 NOTSUPPORTED, /* SetToDo */ 364 NOTSUPPORTED, /* SetToDo */
364 NOTSUPPORTED, /* AddToDo */ 365 NOTSUPPORTED, /* AddToDo */
365 NOTSUPPORTED, /* DeleteToDo */ 366 NOTSUPPORTED, /* DeleteToDo */
366 NOTSUPPORTED, /* DeleteAllToDo */ 367 NOTSUPPORTED, /* DeleteAllToDo */
367 NOTSUPPORTED, /* GetCalendarStatus*/ 368 NOTSUPPORTED, /* GetCalendarStatus*/
368 NOTSUPPORTED, /* GetCalendar */ 369 NOTSUPPORTED, /* GetCalendar */
369 NOTSUPPORTED, /* GetNextCalendar */ 370 NOTSUPPORTED, /* GetNextCalendar */
370 NOTSUPPORTED, /* SetCalendar */ 371 NOTSUPPORTED, /* SetCalendar */
371 NOTSUPPORTED, /* AddCalendar */ 372 NOTSUPPORTED, /* AddCalendar */
372 NOTSUPPORTED, /* DeleteCalendar */ 373 NOTSUPPORTED, /* DeleteCalendar */
373 NOTSUPPORTED, /* DeleteAllCalendar*/ 374 NOTSUPPORTED, /* DeleteAllCalendar*/
374 NOTSUPPORTED, /* GetCalendarSettings*/ 375 NOTSUPPORTED, /* GetCalendarSettings*/
375 NOTSUPPORTED, /* SetCalendarSettings*/ 376 NOTSUPPORTED, /* SetCalendarSettings*/
376 NOTSUPPORTED, /* GetNote */ 377 NOTSUPPORTED, /* GetNextNote */
377 NOTIMPLEMENTED, /* GetProfile */ 378 NOTIMPLEMENTED, /* GetProfile */
378 NOTSUPPORTED, /* SetProfile */ 379 NOTSUPPORTED, /* SetProfile */
379 NOTSUPPORTED, /* GetFMStation */ 380 NOTSUPPORTED, /* GetFMStation */
380 NOTSUPPORTED, /* SetFMStation */ 381 NOTSUPPORTED, /* SetFMStation */
381 NOTSUPPORTED, /* ClearFMStations */ 382 NOTSUPPORTED, /* ClearFMStations */
382 NOTSUPPORTED, /* GetNextFileFolder*/ 383 NOTSUPPORTED, /* GetNextFileFolder*/
383 NOTSUPPORTED, /* GetFilePart */ 384 NOTSUPPORTED, /* GetFilePart */
384 NOTSUPPORTED, /* AddFile */ 385 NOTSUPPORTED, /* AddFile */
385 NOTSUPPORTED, /* GetFileSystemStatus*/ 386 NOTSUPPORTED, /* GetFileSystemStatus*/
386 NOTSUPPORTED, /* DeleteFile */ 387 NOTSUPPORTED, /* DeleteFile */
387 NOTSUPPORTED, /* AddFolder */ 388 NOTSUPPORTED, /* AddFolder */
388 NOTSUPPORTED, /* GetGPRSAccessPoint*/ 389 NOTSUPPORTED, /* GetGPRSAccessPoint*/
389 NOTSUPPORTED /* SetGPRSAccessPoint*/ 390 NOTSUPPORTED /* SetGPRSAccessPoint*/
390}; 391};
391 392
392#endif 393#endif
393 394
394/* How should editor hadle tabs in this file? Add editor commands here. 395/* How should editor hadle tabs in this file? Add editor commands here.
395 * vim: noexpandtab sw=8 ts=8 sts=8: 396 * vim: noexpandtab sw=8 ts=8 sts=8:
396 */ 397 */
diff --git a/gammu/emb/common/phone/nokia/dct4/n3320.c b/gammu/emb/common/phone/nokia/dct4/n3320.c
index 51e6f18..9b1d6cd 100644
--- a/gammu/emb/common/phone/nokia/dct4/n3320.c
+++ b/gammu/emb/common/phone/nokia/dct4/n3320.c
@@ -5,267 +5,268 @@
5#ifdef GSM_ENABLE_NOKIA3320 5#ifdef GSM_ENABLE_NOKIA3320
6 6
7#include <string.h> 7#include <string.h>
8#include <time.h> 8#include <time.h>
9 9
10#include "../../../gsmcomon.h" 10#include "../../../gsmcomon.h"
11#include "../../../misc/coding/coding.h" 11#include "../../../misc/coding/coding.h"
12#include "../../../service/gsmlogo.h" 12#include "../../../service/gsmlogo.h"
13#include "../nfunc.h" 13#include "../nfunc.h"
14#include "../nfuncold.h" 14#include "../nfuncold.h"
15#include "../../pfunc.h" 15#include "../../pfunc.h"
16#include "n3320.h" 16#include "n3320.h"
17 17
18static GSM_Error N3320_ReplyGetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s) 18static GSM_Error N3320_ReplyGetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s)
19{ 19{
20 smprintf(s, "Phonebook entry received\n"); 20 smprintf(s, "Phonebook entry received\n");
21 switch (msg.Buffer[6]) { 21 switch (msg.Buffer[6]) {
22 case 0x0f: 22 case 0x0f:
23 return N71_65_ReplyGetMemoryError(msg.Buffer[10], s); 23 return N71_65_ReplyGetMemoryError(msg.Buffer[10], s);
24 default: 24 default:
25 return N71_65_DecodePhonebook(s, s->Phone.Data.Memory, s->Phone.Data.Bitmap, s->Phone.Data.SpeedDial, msg.Buffer+22, msg.Length-22,true); 25 return N71_65_DecodePhonebook(s, s->Phone.Data.Memory, s->Phone.Data.Bitmap, s->Phone.Data.SpeedDial, msg.Buffer+22, msg.Length-22,true);
26 } 26 }
27 return ERR_UNKNOWN; 27 return ERR_UNKNOWN;
28} 28}
29 29
30static GSM_Error N3320_GetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry) 30static GSM_Error N3320_GetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry)
31{ 31{
32 unsigned char req[] = {N6110_FRAME_HEADER, 0x07, 0x01, 0x01, 0x00, 0x01, 32 unsigned char req[] = {N6110_FRAME_HEADER, 0x07, 0x01, 0x01, 0x00, 0x01,
33 0xfe, 0x10, /* memory type */ 33 0xfe, 0x10, /* memory type */
34 0x00, 0x00, 0x00, 0x00, 34 0x00, 0x00, 0x00, 0x00,
35 0x00, 0x01, /* location */ 35 0x00, 0x01, /* location */
36 0x00, 0x00, 0x01}; 36 0x00, 0x00, 0x01};
37 37
38 req[9] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES); 38 req[9] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES);
39 if (entry->MemoryType == MEM_SM) return ERR_NOTSUPPORTED; 39 if (entry->MemoryType == MEM_SM) return ERR_NOTSUPPORTED;
40 if (req[9]==0xff) return ERR_NOTSUPPORTED; 40 if (req[9]==0xff) return ERR_NOTSUPPORTED;
41 41
42 if (entry->Location==0x00) return ERR_INVALIDLOCATION; 42 if (entry->Location==0x00) return ERR_INVALIDLOCATION;
43 43
44 req[14] = entry->Location / 256; 44 req[14] = entry->Location / 256;
45 req[15] = entry->Location % 256; 45 req[15] = entry->Location % 256;
46 46
47 s->Phone.Data.Memory=entry; 47 s->Phone.Data.Memory=entry;
48 smprintf(s, "Getting phonebook entry\n"); 48 smprintf(s, "Getting phonebook entry\n");
49 return GSM_WaitFor (s, req, 19, 0x03, 4, ID_GetMemory); 49 return GSM_WaitFor (s, req, 19, 0x03, 4, ID_GetMemory);
50} 50}
51 51
52static GSM_Error N3320_ReplyGetMemoryStatus(GSM_Protocol_Message msg, GSM_StateMachine *s) 52static GSM_Error N3320_ReplyGetMemoryStatus(GSM_Protocol_Message msg, GSM_StateMachine *s)
53{ 53{
54 GSM_Phone_Data *Data = &s->Phone.Data; 54 GSM_Phone_Data *Data = &s->Phone.Data;
55 55
56 smprintf(s, "Memory status received\n"); 56 smprintf(s, "Memory status received\n");
57 /* Quess ;-)) */ 57 /* Quess ;-)) */
58 if (msg.Buffer[14]==0x10) { 58 if (msg.Buffer[14]==0x10) {
59 Data->MemoryStatus->MemoryFree = msg.Buffer[18]*256 + msg.Buffer[19]; 59 Data->MemoryStatus->MemoryFree = msg.Buffer[18]*256 + msg.Buffer[19];
60 } else { 60 } else {
61 Data->MemoryStatus->MemoryFree = msg.Buffer[17]; 61 Data->MemoryStatus->MemoryFree = msg.Buffer[17];
62 } 62 }
63 smprintf(s, "Size : %i\n",Data->MemoryStatus->MemoryFree); 63 smprintf(s, "Size : %i\n",Data->MemoryStatus->MemoryFree);
64 Data->MemoryStatus->MemoryUsed = msg.Buffer[20]*256 + msg.Buffer[21]; 64 Data->MemoryStatus->MemoryUsed = msg.Buffer[20]*256 + msg.Buffer[21];
65 smprintf(s, "Used : %i\n",Data->MemoryStatus->MemoryUsed); 65 smprintf(s, "Used : %i\n",Data->MemoryStatus->MemoryUsed);
66 Data->MemoryStatus->MemoryFree -= Data->MemoryStatus->MemoryUsed; 66 Data->MemoryStatus->MemoryFree -= Data->MemoryStatus->MemoryUsed;
67 smprintf(s, "Free : %i\n",Data->MemoryStatus->MemoryFree); 67 smprintf(s, "Free : %i\n",Data->MemoryStatus->MemoryFree);
68 return ERR_NONE; 68 return ERR_NONE;
69} 69}
70 70
71static GSM_Error N3320_GetMemoryStatus(GSM_StateMachine *s, GSM_MemoryStatus *Status) 71static GSM_Error N3320_GetMemoryStatus(GSM_StateMachine *s, GSM_MemoryStatus *Status)
72{ 72{
73 unsigned char req[] = {N6110_FRAME_HEADER, 0x03, 0x02, 73 unsigned char req[] = {N6110_FRAME_HEADER, 0x03, 0x02,
74 0x00, /* memory type */ 74 0x00, /* memory type */
75 0x55, 0x55, 0x55, 0x00}; 75 0x55, 0x55, 0x55, 0x00};
76 76
77 req[5] = NOKIA_GetMemoryType(s, Status->MemoryType,N71_65_MEMORY_TYPES); 77 req[5] = NOKIA_GetMemoryType(s, Status->MemoryType,N71_65_MEMORY_TYPES);
78 if (Status->MemoryType == MEM_SM) return ERR_NOTSUPPORTED; 78 if (Status->MemoryType == MEM_SM) return ERR_NOTSUPPORTED;
79 if (req[5]==0xff) return ERR_NOTSUPPORTED; 79 if (req[5]==0xff) return ERR_NOTSUPPORTED;
80 80
81 s->Phone.Data.MemoryStatus=Status; 81 s->Phone.Data.MemoryStatus=Status;
82 smprintf(s, "Getting memory status\n"); 82 smprintf(s, "Getting memory status\n");
83 return GSM_WaitFor (s, req, 10, 0x03, 4, ID_GetMemoryStatus); 83 return GSM_WaitFor (s, req, 10, 0x03, 4, ID_GetMemoryStatus);
84} 84}
85 85
86static GSM_Error N3320_ReplyGetDateTime(GSM_Protocol_Message msg, GSM_StateMachine *s) 86static GSM_Error N3320_ReplyGetDateTime(GSM_Protocol_Message msg, GSM_StateMachine *s)
87{ 87{
88 smprintf(s, "Date & time received\n"); 88 smprintf(s, "Date & time received\n");
89 if (msg.Buffer[4]==0x01) { 89 if (msg.Buffer[4]==0x01) {
90 NOKIA_DecodeDateTime(s, msg.Buffer+10, s->Phone.Data.DateTime); 90 NOKIA_DecodeDateTime(s, msg.Buffer+10, s->Phone.Data.DateTime);
91 return ERR_NONE; 91 return ERR_NONE;
92 } 92 }
93 smprintf(s, "Not set in phone\n"); 93 smprintf(s, "Not set in phone\n");
94 return ERR_EMPTY; 94 return ERR_EMPTY;
95} 95}
96 96
97static GSM_Error N3320_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time) 97static GSM_Error N3320_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
98{ 98{
99 unsigned char req[] = {N6110_FRAME_HEADER, 0x0A, 0x00, 0x00}; 99 unsigned char req[] = {N6110_FRAME_HEADER, 0x0A, 0x00, 0x00};
100 100
101 s->Phone.Data.DateTime=date_time; 101 s->Phone.Data.DateTime=date_time;
102 smprintf(s, "Getting date & time\n"); 102 smprintf(s, "Getting date & time\n");
103 return GSM_WaitFor (s, req, 6, 0x19, 4, ID_GetDateTime); 103 return GSM_WaitFor (s, req, 6, 0x19, 4, ID_GetDateTime);
104} 104}
105 105
106static GSM_Error N3320_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start) 106static GSM_Error N3320_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start)
107{ 107{
108 return N71_65_GetNextCalendar1(s,Note,start,&s->Phone.Data.Priv.N3320.LastCalendar,&s->Phone.Data.Priv.N3320.LastCalendarYear,&s->Phone.Data.Priv.N3320.LastCalendarPos); 108 return N71_65_GetNextCalendar1(s,Note,start,&s->Phone.Data.Priv.N3320.LastCalendar,&s->Phone.Data.Priv.N3320.LastCalendarYear,&s->Phone.Data.Priv.N3320.LastCalendarPos);
109} 109}
110 110
111static GSM_Error N3320_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *Status) 111static GSM_Error N3320_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *Status)
112{ 112{
113 GSM_Error error; 113 GSM_Error error;
114 114
115 /* Method 1 */ 115 /* Method 1 */
116 error=N71_65_GetCalendarInfo1(s, &s->Phone.Data.Priv.N3320.LastCalendar); 116 error=N71_65_GetCalendarInfo1(s, &s->Phone.Data.Priv.N3320.LastCalendar);
117 if (error!=ERR_NONE) return error; 117 if (error!=ERR_NONE) return error;
118 Status->Used = s->Phone.Data.Priv.N3320.LastCalendar.Number; 118 Status->Used = s->Phone.Data.Priv.N3320.LastCalendar.Number;
119 return ERR_NONE; 119 return ERR_NONE;
120} 120}
121 121
122static GSM_Error N3320_ReplyGetCalendarInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 122static GSM_Error N3320_ReplyGetCalendarInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
123{ 123{
124 return N71_65_ReplyGetCalendarInfo1(msg, s, &s->Phone.Data.Priv.N3320.LastCalendar); 124 return N71_65_ReplyGetCalendarInfo1(msg, s, &s->Phone.Data.Priv.N3320.LastCalendar);
125} 125}
126 126
127static GSM_Reply_Function N3320ReplyFunctions[] = { 127static GSM_Reply_Function N3320ReplyFunctions[] = {
128 {N3320_ReplyGetMemoryStatus, "\x03",0x03,0x04,ID_GetMemoryStatus }, 128 {N3320_ReplyGetMemoryStatus, "\x03",0x03,0x04,ID_GetMemoryStatus },
129 {N3320_ReplyGetMemory, "\x03",0x03,0x08,ID_GetMemory }, 129 {N3320_ReplyGetMemory, "\x03",0x03,0x08,ID_GetMemory },
130 130
131 {N71_65_ReplyGetNextCalendar1, "\x13",0x03,0x1A,ID_GetCalendarNote },/*method 1*/ 131 {N71_65_ReplyGetNextCalendar1, "\x13",0x03,0x1A,ID_GetCalendarNote },/*method 1*/
132 {N3320_ReplyGetCalendarInfo, "\x13",0x03,0x3B,ID_GetCalendarNotesInfo},/*method 1*/ 132 {N3320_ReplyGetCalendarInfo, "\x13",0x03,0x3B,ID_GetCalendarNotesInfo},/*method 1*/
133 133
134 {N3320_ReplyGetDateTime, "\x19",0x03,0x0B,ID_GetDateTime }, 134 {N3320_ReplyGetDateTime, "\x19",0x03,0x0B,ID_GetDateTime },
135 135
136 {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetModel }, 136 {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetModel },
137 {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetFirmware }, 137 {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetFirmware },
138 138
139 {NULL, "\x00",0x00,0x00,ID_None } 139 {NULL, "\x00",0x00,0x00,ID_None }
140}; 140};
141 141
142GSM_Phone_Functions N3320Phone = { 142GSM_Phone_Functions N3320Phone = {
143 "3320", 143 "3320",
144 N3320ReplyFunctions, 144 N3320ReplyFunctions,
145 NONEFUNCTION, /* Initialise */ 145 NONEFUNCTION, /* Initialise */
146 NONEFUNCTION, /* Terminate */ 146 NONEFUNCTION, /* Terminate */
147 GSM_DispatchMessage, 147 GSM_DispatchMessage,
148 NOTSUPPORTED, /* ShowStartInfo */ 148 NOTSUPPORTED, /* ShowStartInfo */
149 NOKIA_GetManufacturer, 149 NOKIA_GetManufacturer,
150 DCT3DCT4_GetModel, 150 DCT3DCT4_GetModel,
151 DCT3DCT4_GetFirmware, 151 DCT3DCT4_GetFirmware,
152 NOTSUPPORTED, /* GetIMEI */ 152 NOTSUPPORTED, /* GetIMEI */
153 NOTSUPPORTED, /* GetOriginalIMEI */ 153 NOTSUPPORTED, /* GetOriginalIMEI */
154 NOTSUPPORTED, /* GetManufactureMonth*/ 154 NOTSUPPORTED, /* GetManufactureMonth*/
155 NOTSUPPORTED, /* GetProductCode */ 155 NOTSUPPORTED, /* GetProductCode */
156 NOTSUPPORTED, /* GetHardware */ 156 NOTSUPPORTED, /* GetHardware */
157 NOTSUPPORTED, /* GetPPM */ 157 NOTSUPPORTED, /* GetPPM */
158 NOTSUPPORTED, /* GetSIMIMSI */ 158 NOTSUPPORTED, /* GetSIMIMSI */
159 N3320_GetDateTime, 159 N3320_GetDateTime,
160 NOTSUPPORTED, /* SetDateTime */ 160 NOTSUPPORTED, /* SetDateTime */
161 NOTSUPPORTED, /* GetAlarm */ 161 NOTSUPPORTED, /* GetAlarm */
162 NOTSUPPORTED, /* SetAlarm */ 162 NOTSUPPORTED, /* SetAlarm */
163 NOTSUPPORTED, /* GetLocale */ 163 NOTSUPPORTED, /* GetLocale */
164 NOTSUPPORTED, /* SetLocale */ 164 NOTSUPPORTED, /* SetLocale */
165 NOTSUPPORTED, /* PressKey */ 165 NOTSUPPORTED, /* PressKey */
166 NOTSUPPORTED, /* Reset */ 166 NOTSUPPORTED, /* Reset */
167 NOTSUPPORTED, /* ResetPhoneSettings*/ 167 NOTSUPPORTED, /* ResetPhoneSettings*/
168 NOTSUPPORTED, /* EnterSecurityCode*/ 168 NOTSUPPORTED, /* EnterSecurityCode*/
169 NOTSUPPORTED, /* GetSecurityStatus*/ 169 NOTSUPPORTED, /* GetSecurityStatus*/
170 NOTSUPPORTED, /* GetDisplayStatus*/ 170 NOTSUPPORTED, /* GetDisplayStatus*/
171 NOTSUPPORTED, /* SetAutoNetworkLogin*/ 171 NOTSUPPORTED, /* SetAutoNetworkLogin*/
172 NOTSUPPORTED, /* GetBatteryCharge*/ 172 NOTSUPPORTED, /* GetBatteryCharge*/
173 NOTSUPPORTED, /* GetSignalQuality*/ 173 NOTSUPPORTED, /* GetSignalQuality*/
174 NOTSUPPORTED, /* GetNetworkInfo */ 174 NOTSUPPORTED, /* GetNetworkInfo */
175 NOTSUPPORTED, /* GetCategory */ 175 NOTSUPPORTED, /* GetCategory */
176 NOTSUPPORTED, /* AddCategory */ 176 NOTSUPPORTED, /* AddCategory */
177 NOTSUPPORTED, /* GetCategoryStatus */ 177 NOTSUPPORTED, /* GetCategoryStatus */
178 N3320_GetMemoryStatus, 178 N3320_GetMemoryStatus,
179 N3320_GetMemory, 179 N3320_GetMemory,
180 NOTSUPPORTED, /* GetNextMemory */ 180 NOTSUPPORTED, /* GetNextMemory */
181 NOTSUPPORTED, /* SetMemory */ 181 NOTSUPPORTED, /* SetMemory */
182 NOTSUPPORTED, /* AddMemory */ 182 NOTSUPPORTED, /* AddMemory */
183 NOTSUPPORTED, /* DeleteMemory */ 183 NOTSUPPORTED, /* DeleteMemory */
184 NOTIMPLEMENTED, /* DeleteAllMemory */ 184 NOTIMPLEMENTED, /* DeleteAllMemory */
185 NOTSUPPORTED, /* GetSpeedDial */ 185 NOTSUPPORTED, /* GetSpeedDial */
186 NOTSUPPORTED, /* SetSpeedDial */ 186 NOTSUPPORTED, /* SetSpeedDial */
187 NOTSUPPORTED, /* GetSMSC */ 187 NOTSUPPORTED, /* GetSMSC */
188 NOTSUPPORTED, /* SetSMSC */ 188 NOTSUPPORTED, /* SetSMSC */
189 NOTSUPPORTED, /* GetSMSStatus */ 189 NOTSUPPORTED, /* GetSMSStatus */
190 NOTSUPPORTED, /* GetSMS */ 190 NOTSUPPORTED, /* GetSMS */
191 NOTSUPPORTED, /* GetNextSMS */ 191 NOTSUPPORTED, /* GetNextSMS */
192 NOTSUPPORTED, /* SetSMS */ 192 NOTSUPPORTED, /* SetSMS */
193 NOTSUPPORTED, /* AddSMS */ 193 NOTSUPPORTED, /* AddSMS */
194 NOTSUPPORTED, /* DeleteSMS */ 194 NOTSUPPORTED, /* DeleteSMS */
195 NOTSUPPORTED, /* SendSMS */ 195 NOTSUPPORTED, /* SendSMS */
196 NOTSUPPORTED, /* SendSavedSMS */ 196 NOTSUPPORTED, /* SendSavedSMS */
197 NOTSUPPORTED, /* SetFastSMSSending*/
197 NOTSUPPORTED, /* SetIncomingSMS */ 198 NOTSUPPORTED, /* SetIncomingSMS */
198 NOTSUPPORTED, /* SetIncomingCB */ 199 NOTSUPPORTED, /* SetIncomingCB */
199 NOTSUPPORTED, /* GetSMSFolders */ 200 NOTSUPPORTED, /* GetSMSFolders */
200 NOTSUPPORTED, /* AddSMSFolder */ 201 NOTSUPPORTED, /* AddSMSFolder */
201 NOTSUPPORTED, /* DeleteSMSFolder */ 202 NOTSUPPORTED, /* DeleteSMSFolder */
202 NOTIMPLEMENTED, /* DialVoice */ 203 NOTIMPLEMENTED, /* DialVoice */
203 NOTIMPLEMENTED, /* AnswerCall */ 204 NOTIMPLEMENTED, /* AnswerCall */
204 NOTIMPLEMENTED, /* CancelCall */ 205 NOTIMPLEMENTED, /* CancelCall */
205 NOTIMPLEMENTED, /* HoldCall */ 206 NOTIMPLEMENTED, /* HoldCall */
206 NOTIMPLEMENTED, /* UnholdCall */ 207 NOTIMPLEMENTED, /* UnholdCall */
207 NOTIMPLEMENTED, /* ConferenceCall */ 208 NOTIMPLEMENTED, /* ConferenceCall */
208 NOTIMPLEMENTED, /* SplitCall */ 209 NOTIMPLEMENTED, /* SplitCall */
209 NOTIMPLEMENTED, /* TransferCall */ 210 NOTIMPLEMENTED, /* TransferCall */
210 NOTIMPLEMENTED, /* SwitchCall */ 211 NOTIMPLEMENTED, /* SwitchCall */
211 NOTSUPPORTED, /* GetCallDivert */ 212 NOTSUPPORTED, /* GetCallDivert */
212 NOTSUPPORTED, /* SetCallDivert */ 213 NOTSUPPORTED, /* SetCallDivert */
213 NOTSUPPORTED, /* CancelAllDiverts*/ 214 NOTSUPPORTED, /* CancelAllDiverts*/
214 NOTIMPLEMENTED, /* SetIncomingCall */ 215 NOTIMPLEMENTED, /* SetIncomingCall */
215 NOTIMPLEMENTED, /* SetIncomingUSSD */ 216 NOTIMPLEMENTED, /* SetIncomingUSSD */
216 NOTSUPPORTED, /* SendDTMF */ 217 NOTSUPPORTED, /* SendDTMF */
217 NOTSUPPORTED, /* GetRingtone */ 218 NOTSUPPORTED, /* GetRingtone */
218 NOTSUPPORTED, /* SetRingtone */ 219 NOTSUPPORTED, /* SetRingtone */
219 NOTSUPPORTED, /* GetRingtonesInfo*/ 220 NOTSUPPORTED, /* GetRingtonesInfo*/
220 NOTIMPLEMENTED, /* DeleteUserRingtones*/ 221 NOTIMPLEMENTED, /* DeleteUserRingtones*/
221 NOTSUPPORTED, /* PlayTone */ 222 NOTSUPPORTED, /* PlayTone */
222 NOTSUPPORTED, /* GetWAPBookmark */ 223 NOTSUPPORTED, /* GetWAPBookmark */
223 NOTSUPPORTED, /* SetWAPBookmark */ 224 NOTSUPPORTED, /* SetWAPBookmark */
224 NOTSUPPORTED, /* DeleteWAPBookmark */ 225 NOTSUPPORTED, /* DeleteWAPBookmark */
225 NOTSUPPORTED, /* GetWAPSettings */ 226 NOTSUPPORTED, /* GetWAPSettings */
226 NOTSUPPORTED, /* SetWAPSettings */ 227 NOTSUPPORTED, /* SetWAPSettings */
227 NOTSUPPORTED, /* GetMMSSettings */ 228 NOTSUPPORTED, /* GetMMSSettings */
228 NOTSUPPORTED, /* SetMMSSettings */ 229 NOTSUPPORTED, /* SetMMSSettings */
229 NOTSUPPORTED, /* GetSyncMLSettings*/ 230 NOTSUPPORTED, /* GetSyncMLSettings*/
230 NOTSUPPORTED, /* SetSyncMLSettings*/ 231 NOTSUPPORTED, /* SetSyncMLSettings*/
231 NOTSUPPORTED, /* GetChatSettings */ 232 NOTSUPPORTED, /* GetChatSettings */
232 NOTSUPPORTED, /* SetChatSettings */ 233 NOTSUPPORTED, /* SetChatSettings */
233 NOTSUPPORTED, /* GetBitmap */ 234 NOTSUPPORTED, /* GetBitmap */
234 NOTSUPPORTED, /* SetBitmap */ 235 NOTSUPPORTED, /* SetBitmap */
235 NOTSUPPORTED, /* GetToDoStatus */ 236 NOTSUPPORTED, /* GetToDoStatus */
236 NOTSUPPORTED, /* GetToDo */ 237 NOTSUPPORTED, /* GetToDo */
237 NOTSUPPORTED, /* GetNextToDo */ 238 NOTSUPPORTED, /* GetNextToDo */
238 NOTSUPPORTED, /* SetToDo */ 239 NOTSUPPORTED, /* SetToDo */
239 NOTSUPPORTED, /* AddToDo */ 240 NOTSUPPORTED, /* AddToDo */
240 NOTSUPPORTED, /* DeleteToDo */ 241 NOTSUPPORTED, /* DeleteToDo */
241 NOTSUPPORTED, /* DeleteAllToDo */ 242 NOTSUPPORTED, /* DeleteAllToDo */
242 N3320_GetCalendarStatus, 243 N3320_GetCalendarStatus,
243 NOTIMPLEMENTED, /* GetCalendar */ 244 NOTIMPLEMENTED, /* GetCalendar */
244 N3320_GetNextCalendar, 245 N3320_GetNextCalendar,
245 NOTIMPLEMENTED, /* SetCalendar */ 246 NOTIMPLEMENTED, /* SetCalendar */
246 NOTSUPPORTED, /* AddCalendar */ 247 NOTSUPPORTED, /* AddCalendar */
247 NOTSUPPORTED, /* DeleteCalendar */ 248 NOTSUPPORTED, /* DeleteCalendar */
248 NOTIMPLEMENTED, /* DeleteAllCalendar*/ 249 NOTIMPLEMENTED, /* DeleteAllCalendar*/
249 NOTSUPPORTED, /* GetCalendarSettings*/ 250 NOTSUPPORTED, /* GetCalendarSettings*/
250 NOTSUPPORTED, /* SetCalendarSettings*/ 251 NOTSUPPORTED, /* SetCalendarSettings*/
251 NOTSUPPORTED, /* GetNote */ 252 NOTSUPPORTED, /* GetNextNote */
252 NOTSUPPORTED, /* GetProfile */ 253 NOTSUPPORTED, /* GetProfile */
253 NOTSUPPORTED, /* SetProfile */ 254 NOTSUPPORTED, /* SetProfile */
254 NOTSUPPORTED, /* GetFMStation */ 255 NOTSUPPORTED, /* GetFMStation */
255 NOTSUPPORTED, /* SetFMStation */ 256 NOTSUPPORTED, /* SetFMStation */
256 NOTSUPPORTED, /* ClearFMStations */ 257 NOTSUPPORTED, /* ClearFMStations */
257 NOTSUPPORTED, /* GetNextFileFolder*/ 258 NOTSUPPORTED, /* GetNextFileFolder*/
258 NOTSUPPORTED, /* GetFilePart */ 259 NOTSUPPORTED, /* GetFilePart */
259 NOTIMPLEMENTED, /* AddFilePart */ 260 NOTIMPLEMENTED, /* AddFilePart */
260 NOTSUPPORTED, /* GetFileSystemStatus*/ 261 NOTSUPPORTED, /* GetFileSystemStatus*/
261 NOTIMPLEMENTED, /* DeleteFile */ 262 NOTIMPLEMENTED, /* DeleteFile */
262 NOTIMPLEMENTED, /* AddFolder */ 263 NOTIMPLEMENTED, /* AddFolder */
263 NOTSUPPORTED, /* GetGPRSAccessPoint*/ 264 NOTSUPPORTED, /* GetGPRSAccessPoint*/
264 NOTSUPPORTED /* SetGPRSAccessPoint*/ 265 NOTSUPPORTED /* SetGPRSAccessPoint*/
265}; 266};
266 267
267#endif 268#endif
268 269
269/* How should editor hadle tabs in this file? Add editor commands here. 270/* How should editor hadle tabs in this file? Add editor commands here.
270 * vim: noexpandtab sw=8 ts=8 sts=8: 271 * vim: noexpandtab sw=8 ts=8 sts=8:
271 */ 272 */
diff --git a/gammu/emb/common/phone/nokia/dct4/n3650.c b/gammu/emb/common/phone/nokia/dct4/n3650.c
index 2da55bf..d4746a7 100644
--- a/gammu/emb/common/phone/nokia/dct4/n3650.c
+++ b/gammu/emb/common/phone/nokia/dct4/n3650.c
@@ -126,267 +126,268 @@ static GSM_Error N3650_ReplyGetFolderInfo(GSM_Protocol_Message msg, GSM_StateMac
126 } 126 }
127 dbgprintf("\n"); 127 dbgprintf("\n");
128 return ERR_NONE; 128 return ERR_NONE;
129} 129}
130 130
131static GSM_Error N3650_GetFolderInfo(GSM_StateMachine *s, GSM_File *File) 131static GSM_Error N3650_GetFolderInfo(GSM_StateMachine *s, GSM_File *File)
132{ 132{
133 int len=10; 133 int len=10;
134 unsigned char req[500] = { 134 unsigned char req[500] = {
135 N7110_FRAME_HEADER, 0x0B, 0x00, 0x01, 0x07, 135 N7110_FRAME_HEADER, 0x0B, 0x00, 0x01, 0x07,
136 0x18, /* folder name length + 6 */ 136 0x18, /* folder name length + 6 */
137 0x12, /* folder name length */ 137 0x12, /* folder name length */
138 0x00, 138 0x00,
139 0x00}; /* folder name */ 139 0x00}; /* folder name */
140 140
141 sprintf(req+10,File->ID_FullName); 141 sprintf(req+10,File->ID_FullName);
142 len +=strlen(File->ID_FullName); 142 len +=strlen(File->ID_FullName);
143 req[7] = strlen(File->ID_FullName) + 6; 143 req[7] = strlen(File->ID_FullName) + 6;
144 req[8] = strlen(File->ID_FullName); 144 req[8] = strlen(File->ID_FullName);
145 req[len++] = 0x00; 145 req[len++] = 0x00;
146 req[len++] = 0x00; 146 req[len++] = 0x00;
147 147
148 s->Phone.Data.FileInfo = File; 148 s->Phone.Data.FileInfo = File;
149 return GSM_WaitFor (s, req, len, 0x58, 4, ID_GetFile); 149 return GSM_WaitFor (s, req, len, 0x58, 4, ID_GetFile);
150} 150}
151 151
152static GSM_Error N3650_GetNextFileFolder(GSM_StateMachine *s, GSM_File *File, bool start) 152static GSM_Error N3650_GetNextFileFolder(GSM_StateMachine *s, GSM_File *File, bool start)
153{ 153{
154 GSM_Error error; 154 GSM_Error error;
155 GSM_Phone_N3650Data*Priv = &s->Phone.Data.Priv.N3650; 155 GSM_Phone_N3650Data*Priv = &s->Phone.Data.Priv.N3650;
156 156
157 if (start) { 157 if (start) {
158 error = DCT4_SetPhoneMode(s, DCT4_MODE_LOCAL); 158 error = DCT4_SetPhoneMode(s, DCT4_MODE_LOCAL);
159 if (error != ERR_NONE) return error; 159 if (error != ERR_NONE) return error;
160 160
161 Priv->Files[0]->Folder = true; 161 Priv->Files[0]->Folder = true;
162 Priv->Files[0]->Level = 1; 162 Priv->Files[0]->Level = 1;
163 Priv->Files[0]->Name[0] = 0; 163 Priv->Files[0]->Name[0] = 0;
164 Priv->Files[0]->Name[1] = 0; 164 Priv->Files[0]->Name[1] = 0;
165 Priv->Files[0]->ID_FullName[0]= 'Z'; 165 Priv->Files[0]->ID_FullName[0]= 'Z';
166 Priv->Files[0]->ID_FullName[1]= ':'; 166 Priv->Files[0]->ID_FullName[1]= ':';
167 Priv->Files[0]->ID_FullName[2]= 0; 167 Priv->Files[0]->ID_FullName[2]= 0;
168 168
169 Priv->Files[1]->Folder = true; 169 Priv->Files[1]->Folder = true;
170 Priv->Files[1]->Level = 1; 170 Priv->Files[1]->Level = 1;
171 Priv->Files[1]->Name[0] = 0; 171 Priv->Files[1]->Name[0] = 0;
172 Priv->Files[1]->Name[1] = 0; 172 Priv->Files[1]->Name[1] = 0;
173 Priv->Files[1]->ID_FullName[0]= 'E'; 173 Priv->Files[1]->ID_FullName[0]= 'E';
174 Priv->Files[1]->ID_FullName[1]= ':'; 174 Priv->Files[1]->ID_FullName[1]= ':';
175 Priv->Files[1]->ID_FullName[2]= 0; 175 Priv->Files[1]->ID_FullName[2]= 0;
176 176
177 Priv->Files[2]->Folder = true; 177 Priv->Files[2]->Folder = true;
178 Priv->Files[2]->Level = 1; 178 Priv->Files[2]->Level = 1;
179 Priv->Files[2]->Name[0] = 0; 179 Priv->Files[2]->Name[0] = 0;
180 Priv->Files[2]->Name[1] = 0; 180 Priv->Files[2]->Name[1] = 0;
181 Priv->Files[2]->ID_FullName[0]= 'C'; 181 Priv->Files[2]->ID_FullName[0]= 'C';
182 Priv->Files[2]->ID_FullName[1]= ':'; 182 Priv->Files[2]->ID_FullName[1]= ':';
183 Priv->Files[2]->ID_FullName[2]= 0; 183 Priv->Files[2]->ID_FullName[2]= 0;
184 184
185 Priv->FilesLocationsUsed = 3; 185 Priv->FilesLocationsUsed = 3;
186 Priv->FilesLocationsCurrent = 0; 186 Priv->FilesLocationsCurrent = 0;
187 Priv->FileLev = 1; 187 Priv->FileLev = 1;
188 } 188 }
189 189
190 if (Priv->FilesLocationsCurrent == Priv->FilesLocationsUsed) { 190 if (Priv->FilesLocationsCurrent == Priv->FilesLocationsUsed) {
191 // error = DCT4_SetPhoneMode(s, DCT4_MODE_NORMAL); 191 // error = DCT4_SetPhoneMode(s, DCT4_MODE_NORMAL);
192 // if (error != ERR_NONE) return error; 192 // if (error != ERR_NONE) return error;
193 193
194 return ERR_EMPTY; 194 return ERR_EMPTY;
195 } 195 }
196 196
197 strcpy(File->ID_FullName,Priv->Files[Priv->FilesLocationsCurrent]->ID_FullName); 197 strcpy(File->ID_FullName,Priv->Files[Priv->FilesLocationsCurrent]->ID_FullName);
198 File->Level= Priv->Files[Priv->FilesLocationsCurrent]->Level; 198 File->Level= Priv->Files[Priv->FilesLocationsCurrent]->Level;
199 File->Folder= Priv->Files[Priv->FilesLocationsCurrent]->Folder; 199 File->Folder= Priv->Files[Priv->FilesLocationsCurrent]->Folder;
200 CopyUnicodeString(File->Name,Priv->Files[Priv->FilesLocationsCurrent]->Name); 200 CopyUnicodeString(File->Name,Priv->Files[Priv->FilesLocationsCurrent]->Name);
201 Priv->FilesLocationsCurrent++; 201 Priv->FilesLocationsCurrent++;
202 202
203 if (!File->Folder) return ERR_NONE; 203 if (!File->Folder) return ERR_NONE;
204 204
205 if (Priv->FilesLocationsCurrent > 1) { 205 if (Priv->FilesLocationsCurrent > 1) {
206 if (File->ID_FullName[0]!=Priv->Files[Priv->FilesLocationsCurrent-2]->ID_FullName[0]) { 206 if (File->ID_FullName[0]!=Priv->Files[Priv->FilesLocationsCurrent-2]->ID_FullName[0]) {
207 if (File->ID_FullName[0] == 'E') { 207 if (File->ID_FullName[0] == 'E') {
208 error = DCT4_SetPhoneMode(s, DCT4_MODE_TEST); 208 error = DCT4_SetPhoneMode(s, DCT4_MODE_TEST);
209 error = DCT4_SetPhoneMode(s, DCT4_MODE_TEST); 209 error = DCT4_SetPhoneMode(s, DCT4_MODE_TEST);
210 } 210 }
211 if (File->ID_FullName[0] == 'C') { 211 if (File->ID_FullName[0] == 'C') {
212 error = DCT4_SetPhoneMode(s, DCT4_MODE_LOCAL); 212 error = DCT4_SetPhoneMode(s, DCT4_MODE_LOCAL);
213 error = DCT4_SetPhoneMode(s, DCT4_MODE_LOCAL); 213 error = DCT4_SetPhoneMode(s, DCT4_MODE_LOCAL);
214 } 214 }
215 // if (error != ERR_NONE) return error; 215 // if (error != ERR_NONE) return error;
216 } 216 }
217 } 217 }
218 218
219 File->ReadOnly = false; 219 File->ReadOnly = false;
220 File->System = false; 220 File->System = false;
221 File->Protected = false; 221 File->Protected = false;
222 File->Hidden = false; 222 File->Hidden = false;
223 223
224 return N3650_GetFolderInfo(s, File); 224 return N3650_GetFolderInfo(s, File);
225} 225}
226 226
227static GSM_Error N3650_Initialise (GSM_StateMachine *s) 227static GSM_Error N3650_Initialise (GSM_StateMachine *s)
228{ 228{
229 GSM_Phone_N3650Data *Priv = &s->Phone.Data.Priv.N3650; 229 GSM_Phone_N3650Data *Priv = &s->Phone.Data.Priv.N3650;
230 int i; 230 int i;
231 231
232 for (i=0;i<10000;i++) { 232 for (i=0;i<10000;i++) {
233 Priv->Files[i] = malloc(sizeof(GSM_File)); 233 Priv->Files[i] = malloc(sizeof(GSM_File));
234 if (Priv->Files[i] == NULL) return ERR_MOREMEMORY; 234 if (Priv->Files[i] == NULL) return ERR_MOREMEMORY;
235 } 235 }
236 return ERR_NONE; 236 return ERR_NONE;
237} 237}
238 238
239static GSM_Error N3650_Terminate(GSM_StateMachine *s) 239static GSM_Error N3650_Terminate(GSM_StateMachine *s)
240{ 240{
241 GSM_Phone_N3650Data *Priv = &s->Phone.Data.Priv.N3650; 241 GSM_Phone_N3650Data *Priv = &s->Phone.Data.Priv.N3650;
242 int i; 242 int i;
243 243
244 for (i=0;i<10000;i++) free(Priv->Files[i]); 244 for (i=0;i<10000;i++) free(Priv->Files[i]);
245 return ERR_NONE; 245 return ERR_NONE;
246} 246}
247 247
248static GSM_Reply_Function N3650ReplyFunctions[] = { 248static GSM_Reply_Function N3650ReplyFunctions[] = {
249 {DCT4_ReplySetPhoneMode, "\x15",0x03,0x64,ID_Reset }, 249 {DCT4_ReplySetPhoneMode, "\x15",0x03,0x64,ID_Reset },
250 {DCT4_ReplyGetPhoneMode, "\x15",0x03,0x65,ID_Reset }, 250 {DCT4_ReplyGetPhoneMode, "\x15",0x03,0x65,ID_Reset },
251 {NoneReply, "\x15",0x03,0x68,ID_Reset }, 251 {NoneReply, "\x15",0x03,0x68,ID_Reset },
252 252
253 {DCT4_ReplyGetIMEI, "\x1B",0x03,0x01,ID_GetIMEI }, 253 {DCT4_ReplyGetIMEI, "\x1B",0x03,0x01,ID_GetIMEI },
254 {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x08,ID_GetHardware }, 254 {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x08,ID_GetHardware },
255 {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x0C,ID_GetProductCode }, 255 {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x0C,ID_GetProductCode },
256 256
257 {N3650_ReplyGetFolderInfo, "\x58",0x03,0x0C,ID_GetFile }, 257 {N3650_ReplyGetFolderInfo, "\x58",0x03,0x0C,ID_GetFile },
258 {N3650_ReplyGetFilePart, "\x58",0x03,0x0E,ID_GetFile }, 258 {N3650_ReplyGetFilePart, "\x58",0x03,0x0E,ID_GetFile },
259 259
260 {NULL, "\x00",0x00,0x00,ID_None } 260 {NULL, "\x00",0x00,0x00,ID_None }
261}; 261};
262 262
263GSM_Phone_Functions N3650Phone = { 263GSM_Phone_Functions N3650Phone = {
264 "3650|NGAGE", 264 "3650|NGAGE",
265 N3650ReplyFunctions, 265 N3650ReplyFunctions,
266 N3650_Initialise, 266 N3650_Initialise,
267 N3650_Terminate, 267 N3650_Terminate,
268 GSM_DispatchMessage, 268 GSM_DispatchMessage,
269 NOTSUPPORTED, /* ShowStartInfo */ 269 NOTSUPPORTED, /* ShowStartInfo */
270 NOKIA_GetManufacturer, 270 NOKIA_GetManufacturer,
271 DCT3DCT4_GetModel, 271 DCT3DCT4_GetModel,
272 DCT3DCT4_GetFirmware, 272 DCT3DCT4_GetFirmware,
273 DCT4_GetIMEI, 273 DCT4_GetIMEI,
274 NOTSUPPORTED, /* GetOriginalIMEI */ 274 NOTSUPPORTED, /* GetOriginalIMEI */
275 NOTSUPPORTED, /* GetManufactureMonth*/ 275 NOTSUPPORTED, /* GetManufactureMonth*/
276 DCT4_GetProductCode, 276 DCT4_GetProductCode,
277 DCT4_GetHardware, 277 DCT4_GetHardware,
278 NOTSUPPORTED, /* GetPPM */ 278 NOTSUPPORTED, /* GetPPM */
279 NOTSUPPORTED, /* GetSIMIMSI */ 279 NOTSUPPORTED, /* GetSIMIMSI */
280 NOTSUPPORTED, /* GetDateTime */ 280 NOTSUPPORTED, /* GetDateTime */
281 NOTSUPPORTED, /* SetDateTime */ 281 NOTSUPPORTED, /* SetDateTime */
282 NOTSUPPORTED, /* GetAlarm */ 282 NOTSUPPORTED, /* GetAlarm */
283 NOTSUPPORTED, /* SetAlarm */ 283 NOTSUPPORTED, /* SetAlarm */
284 NOTSUPPORTED, /* GetLocale */ 284 NOTSUPPORTED, /* GetLocale */
285 NOTSUPPORTED, /* SetLocale */ 285 NOTSUPPORTED, /* SetLocale */
286 NOTSUPPORTED, /* PressKey */ 286 NOTSUPPORTED, /* PressKey */
287 DCT4_Reset, 287 DCT4_Reset,
288 NOTSUPPORTED, /* ResetPhoneSettings*/ 288 NOTSUPPORTED, /* ResetPhoneSettings*/
289 NOTSUPPORTED, /* EnterSecurityCode*/ 289 NOTSUPPORTED, /* EnterSecurityCode*/
290 NOTSUPPORTED, /* GetSecurityStatus*/ 290 NOTSUPPORTED, /* GetSecurityStatus*/
291 NOTSUPPORTED, /* GetDisplayStatus*/ 291 NOTSUPPORTED, /* GetDisplayStatus*/
292 NOTSUPPORTED, /* SetAutoNetworkLogin*/ 292 NOTSUPPORTED, /* SetAutoNetworkLogin*/
293 NOTSUPPORTED, /* GetBatteryCharge*/ 293 NOTSUPPORTED, /* GetBatteryCharge*/
294 NOTSUPPORTED, /* GetSignalQuality*/ 294 NOTSUPPORTED, /* GetSignalQuality*/
295 NOTSUPPORTED, /* GetNetworkInfo */ 295 NOTSUPPORTED, /* GetNetworkInfo */
296 NOTSUPPORTED, /* GetCategory */ 296 NOTSUPPORTED, /* GetCategory */
297 NOTSUPPORTED, /* AddCategory */ 297 NOTSUPPORTED, /* AddCategory */
298 NOTSUPPORTED, /* GetCategoryStatus */ 298 NOTSUPPORTED, /* GetCategoryStatus */
299 NOTSUPPORTED, /* GetMemoryStatus */ 299 NOTSUPPORTED, /* GetMemoryStatus */
300 NOTSUPPORTED, /* GetMemory */ 300 NOTSUPPORTED, /* GetMemory */
301 NOTSUPPORTED, /* GetNextMemory */ 301 NOTSUPPORTED, /* GetNextMemory */
302 NOTSUPPORTED, /* SetMemory */ 302 NOTSUPPORTED, /* SetMemory */
303 NOTSUPPORTED, /* AddMemory */ 303 NOTSUPPORTED, /* AddMemory */
304 NOTSUPPORTED, /* DeleteMemory */ 304 NOTSUPPORTED, /* DeleteMemory */
305 NOTIMPLEMENTED, /* DeleteAllMemory */ 305 NOTIMPLEMENTED, /* DeleteAllMemory */
306 NOTSUPPORTED, /* GetSpeedDial */ 306 NOTSUPPORTED, /* GetSpeedDial */
307 NOTSUPPORTED, /* SetSpeedDial */ 307 NOTSUPPORTED, /* SetSpeedDial */
308 NOTSUPPORTED, /* GetSMSC */ 308 NOTSUPPORTED, /* GetSMSC */
309 NOTSUPPORTED, /* SetSMSC */ 309 NOTSUPPORTED, /* SetSMSC */
310 NOTSUPPORTED, /* GetSMSStatus */ 310 NOTSUPPORTED, /* GetSMSStatus */
311 NOTSUPPORTED, /* GetSMS */ 311 NOTSUPPORTED, /* GetSMS */
312 NOTSUPPORTED, /* GetNextSMS */ 312 NOTSUPPORTED, /* GetNextSMS */
313 NOTSUPPORTED, /* SetSMS */ 313 NOTSUPPORTED, /* SetSMS */
314 NOTSUPPORTED, /* AddSMS */ 314 NOTSUPPORTED, /* AddSMS */
315 NOTSUPPORTED, /* DeleteSMS */ 315 NOTSUPPORTED, /* DeleteSMS */
316 NOTSUPPORTED, /* SendSMS */ 316 NOTSUPPORTED, /* SendSMS */
317 NOTSUPPORTED, /* SendSavedSMS */ 317 NOTSUPPORTED, /* SendSavedSMS */
318 NOTSUPPORTED, /* SetFastSMSSending*/
318 NOTSUPPORTED, /* SetIncomingSMS */ 319 NOTSUPPORTED, /* SetIncomingSMS */
319 NOTSUPPORTED, /* SetIncomingCB */ 320 NOTSUPPORTED, /* SetIncomingCB */
320 NOTSUPPORTED, /* GetSMSFolders */ 321 NOTSUPPORTED, /* GetSMSFolders */
321 NOTSUPPORTED, /* AddSMSFolder */ 322 NOTSUPPORTED, /* AddSMSFolder */
322 NOTSUPPORTED, /* DeleteSMSFolder */ 323 NOTSUPPORTED, /* DeleteSMSFolder */
323 NOTIMPLEMENTED, /* DialVoice */ 324 NOTIMPLEMENTED, /* DialVoice */
324 NOTIMPLEMENTED, /* AnswerCall */ 325 NOTIMPLEMENTED, /* AnswerCall */
325 NOTIMPLEMENTED, /* CancelCall */ 326 NOTIMPLEMENTED, /* CancelCall */
326 NOTIMPLEMENTED, /* HoldCall */ 327 NOTIMPLEMENTED, /* HoldCall */
327 NOTIMPLEMENTED, /* UnholdCall */ 328 NOTIMPLEMENTED, /* UnholdCall */
328 NOTIMPLEMENTED, /* ConferenceCall */ 329 NOTIMPLEMENTED, /* ConferenceCall */
329 NOTIMPLEMENTED, /* SplitCall */ 330 NOTIMPLEMENTED, /* SplitCall */
330 NOTIMPLEMENTED, /* TransferCall */ 331 NOTIMPLEMENTED, /* TransferCall */
331 NOTIMPLEMENTED, /* SwitchCall */ 332 NOTIMPLEMENTED, /* SwitchCall */
332 NOTSUPPORTED, /* GetCallDivert */ 333 NOTSUPPORTED, /* GetCallDivert */
333 NOTSUPPORTED, /* SetCallDivert */ 334 NOTSUPPORTED, /* SetCallDivert */
334 NOTSUPPORTED, /* CancelAllDiverts*/ 335 NOTSUPPORTED, /* CancelAllDiverts*/
335 NOTIMPLEMENTED, /* SetIncomingCall */ 336 NOTIMPLEMENTED, /* SetIncomingCall */
336 NOTIMPLEMENTED, /* SetIncomingUSSD */ 337 NOTIMPLEMENTED, /* SetIncomingUSSD */
337 NOTSUPPORTED, /* SendDTMF */ 338 NOTSUPPORTED, /* SendDTMF */
338 NOTSUPPORTED, /* GetRingtone */ 339 NOTSUPPORTED, /* GetRingtone */
339 NOTSUPPORTED, /* SetRingtone */ 340 NOTSUPPORTED, /* SetRingtone */
340 NOTSUPPORTED, /* GetRingtonesInfo*/ 341 NOTSUPPORTED, /* GetRingtonesInfo*/
341 NOTIMPLEMENTED, /* DeleteUserRingtones*/ 342 NOTIMPLEMENTED, /* DeleteUserRingtones*/
342 NOTSUPPORTED, /* PlayTone */ 343 NOTSUPPORTED, /* PlayTone */
343 NOTSUPPORTED, /* GetWAPBookmark */ 344 NOTSUPPORTED, /* GetWAPBookmark */
344 NOTSUPPORTED, /* SetWAPBookmark */ 345 NOTSUPPORTED, /* SetWAPBookmark */
345 NOTSUPPORTED, /* DeleteWAPBookmark */ 346 NOTSUPPORTED, /* DeleteWAPBookmark */
346 NOTSUPPORTED, /* GetWAPSettings */ 347 NOTSUPPORTED, /* GetWAPSettings */
347 NOTSUPPORTED, /* SetWAPSettings */ 348 NOTSUPPORTED, /* SetWAPSettings */
348 NOTSUPPORTED, /* GetMMSSettings */ 349 NOTSUPPORTED, /* GetMMSSettings */
349 NOTSUPPORTED, /* SetMMSSettings */ 350 NOTSUPPORTED, /* SetMMSSettings */
350 NOTSUPPORTED, /* GetSyncMLSettings*/ 351 NOTSUPPORTED, /* GetSyncMLSettings*/
351 NOTSUPPORTED, /* SetSyncMLSettings*/ 352 NOTSUPPORTED, /* SetSyncMLSettings*/
352 NOTSUPPORTED, /* GetChatSettings */ 353 NOTSUPPORTED, /* GetChatSettings */
353 NOTSUPPORTED, /* SetChatSettings */ 354 NOTSUPPORTED, /* SetChatSettings */
354 NOTSUPPORTED, /* GetBitmap */ 355 NOTSUPPORTED, /* GetBitmap */
355 NOTSUPPORTED, /* SetBitmap */ 356 NOTSUPPORTED, /* SetBitmap */
356 NOTSUPPORTED, /* GetToDoStatus */ 357 NOTSUPPORTED, /* GetToDoStatus */
357 NOTSUPPORTED, /* GetToDo */ 358 NOTSUPPORTED, /* GetToDo */
358 NOTSUPPORTED, /* GetNextToDo */ 359 NOTSUPPORTED, /* GetNextToDo */
359 NOTSUPPORTED, /* SetToDo */ 360 NOTSUPPORTED, /* SetToDo */
360 NOTSUPPORTED, /* AddToDo */ 361 NOTSUPPORTED, /* AddToDo */
361 NOTSUPPORTED, /* DeleteToDo */ 362 NOTSUPPORTED, /* DeleteToDo */
362 NOTSUPPORTED, /* DeleteAllToDo */ 363 NOTSUPPORTED, /* DeleteAllToDo */
363 NOTIMPLEMENTED, /* GetCalendarStatus*/ 364 NOTIMPLEMENTED, /* GetCalendarStatus*/
364 NOTIMPLEMENTED, /* GetCalendar */ 365 NOTIMPLEMENTED, /* GetCalendar */
365 NOTSUPPORTED, /* GetNextCalendar */ 366 NOTSUPPORTED, /* GetNextCalendar */
366 NOTIMPLEMENTED, /* SetCalendar */ 367 NOTIMPLEMENTED, /* SetCalendar */
367 NOTSUPPORTED, /* AddCalendar */ 368 NOTSUPPORTED, /* AddCalendar */
368 NOTSUPPORTED, /* DeleteCalendar */ 369 NOTSUPPORTED, /* DeleteCalendar */
369 NOTIMPLEMENTED, /* DeleteAllCalendar*/ 370 NOTIMPLEMENTED, /* DeleteAllCalendar*/
370 NOTSUPPORTED, /* GetCalendarSettings*/ 371 NOTSUPPORTED, /* GetCalendarSettings*/
371 NOTSUPPORTED, /* SetCalendarSettings*/ 372 NOTSUPPORTED, /* SetCalendarSettings*/
372 NOTSUPPORTED, /* GetNote */ 373 NOTSUPPORTED, /* GetNextNote */
373 NOTSUPPORTED, /* GetProfile */ 374 NOTSUPPORTED, /* GetProfile */
374 NOTSUPPORTED, /* SetProfile */ 375 NOTSUPPORTED, /* SetProfile */
375 NOTSUPPORTED, /* GetFMStation */ 376 NOTSUPPORTED, /* GetFMStation */
376 NOTSUPPORTED, /* SetFMStation */ 377 NOTSUPPORTED, /* SetFMStation */
377 NOTSUPPORTED, /* ClearFMStations */ 378 NOTSUPPORTED, /* ClearFMStations */
378 N3650_GetNextFileFolder, 379 N3650_GetNextFileFolder,
379 N3650_GetFilePart, 380 N3650_GetFilePart,
380 NOTIMPLEMENTED, /* AddFilePart */ 381 NOTIMPLEMENTED, /* AddFilePart */
381 NOTSUPPORTED, /* GetFileSystemStatus*/ 382 NOTSUPPORTED, /* GetFileSystemStatus*/
382 NOTIMPLEMENTED, /* DeleteFile */ 383 NOTIMPLEMENTED, /* DeleteFile */
383 NOTIMPLEMENTED, /* AddFolder */ 384 NOTIMPLEMENTED, /* AddFolder */
384 NOTSUPPORTED, /* GetGPRSAccessPoint*/ 385 NOTSUPPORTED, /* GetGPRSAccessPoint*/
385 NOTSUPPORTED /* SetGPRSAccessPoint*/ 386 NOTSUPPORTED /* SetGPRSAccessPoint*/
386}; 387};
387 388
388#endif 389#endif
389 390
390/* How should editor hadle tabs in this file? Add editor commands here. 391/* How should editor hadle tabs in this file? Add editor commands here.
391 * vim: noexpandtab sw=8 ts=8 sts=8: 392 * vim: noexpandtab sw=8 ts=8 sts=8:
392 */ 393 */
diff --git a/gammu/emb/common/phone/nokia/dct4/n6510.c b/gammu/emb/common/phone/nokia/dct4/n6510.c
index 67fe492..2208def 100644
--- a/gammu/emb/common/phone/nokia/dct4/n6510.c
+++ b/gammu/emb/common/phone/nokia/dct4/n6510.c
@@ -1,460 +1,465 @@
1/* (c) 2002-2004 by Marcin Wiacek */ 1/* (c) 2002-2004 by Marcin Wiacek */
2/* based on some work from Markus Plail, Pawel Kot and Gnokii */ 2/* based on some Markus Plail, Pawel Kot work from Gnokii (www.gnokii.org)
3 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
4 * GNU GPL version 2 or later
5 */
3/* function for making CRC for filesystem (c) 2003 by Michael Schroeder */ 6/* function for making CRC for filesystem (c) 2003 by Michael Schroeder */
4 7
5#include "../../../gsmstate.h" 8#include "../../../gsmstate.h"
6 9
7#ifdef GSM_ENABLE_NOKIA6510 10#ifdef GSM_ENABLE_NOKIA6510
8 11
9#include <string.h> 12#include <string.h>
10#include <time.h> 13#include <time.h>
11 14
12#include "../../../misc/coding/coding.h" 15#include "../../../misc/coding/coding.h"
13#include "../../../gsmcomon.h" 16#include "../../../gsmcomon.h"
14#include "../../../service/gsmlogo.h" 17#include "../../../service/gsmlogo.h"
15#include "../nfunc.h" 18#include "../nfunc.h"
16#include "../nfuncold.h" 19#include "../nfuncold.h"
17#include "../../pfunc.h" 20#include "../../pfunc.h"
18#include "dct4func.h" 21#include "dct4func.h"
19#include "n6510.h" 22#include "n6510.h"
20 23
21static GSM_Error N6510_Initialise (GSM_StateMachine *s) 24static GSM_Error N6510_Initialise (GSM_StateMachine *s)
22{ 25{
23 s->Phone.Data.Priv.N6510.CalendarIconsNum = 0; 26 s->Phone.Data.Priv.N6510.CalendarIconsNum = 0;
24 27
25 /* Enables various things like incoming SMS, call info, etc. */ 28 /* Enables various things like incoming SMS, call info, etc. */
26 return N71_65_EnableFunctions (s, "\x01\x02\x06\x0A\x14\x17\x39", 7); 29 return N71_65_EnableFunctions (s, "\x01\x02\x06\x0A\x14\x17\x39", 7);
27} 30}
28 31
29static GSM_Error N6510_ReplyGetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s) 32static GSM_Error N6510_ReplyGetMemory(GSM_Protocol_Message msg, GSM_StateMachine *s)
30{ 33{
31 smprintf(s, "Phonebook entry received\n"); 34 smprintf(s, "Phonebook entry received\n");
32 switch (msg.Buffer[6]) { 35 switch (msg.Buffer[6]) {
33 case 0x0f: 36 case 0x0f:
34 return N71_65_ReplyGetMemoryError(msg.Buffer[10], s); 37 return N71_65_ReplyGetMemoryError(msg.Buffer[10], s);
35 default: 38 default:
36 return N71_65_DecodePhonebook(s, s->Phone.Data.Memory, s->Phone.Data.Bitmap, s->Phone.Data.SpeedDial, msg.Buffer+22, msg.Length-22,false); 39 return N71_65_DecodePhonebook(s, s->Phone.Data.Memory, s->Phone.Data.Bitmap, s->Phone.Data.SpeedDial, msg.Buffer+22, msg.Length-22,false);
37 } 40 }
38 return ERR_UNKNOWN; 41 return ERR_UNKNOWN;
39} 42}
40 43
41static GSM_Error N6510_GetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry) 44static GSM_Error N6510_GetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry)
42{ 45{
43 unsigned char req[] = {N6110_FRAME_HEADER, 0x07, 0x01, 0x01, 0x00, 0x01, 46 unsigned char req[] = {N6110_FRAME_HEADER, 0x07, 0x01, 0x01, 0x00, 0x01,
44 0xfe, 0x10, /* memory type */ 47 0xfe, 0x10, /* memory type */
45 0x00, 0x00, 0x00, 0x00, 48 0x00, 0x00, 0x00, 0x00,
46 0x00, 0x01, /* location */ 49 0x00, 0x01, /* location */
47 0x00, 0x00, 0x01}; 50 0x00, 0x00, 0x01};
48 51
49 req[9] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES); 52 req[9] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES);
50 if (req[9]==0xff) return ERR_NOTSUPPORTED; 53 if (req[9]==0xff) return ERR_NOTSUPPORTED;
51 54
52 if (entry->Location==0x00) return ERR_INVALIDLOCATION; 55 if (entry->Location==0x00) return ERR_INVALIDLOCATION;
53 56
54 req[14] = entry->Location / 256; 57 req[14] = entry->Location / 256;
55 req[15] = entry->Location % 256; 58 req[15] = entry->Location % 256;
56 59
57 s->Phone.Data.Memory=entry; 60 s->Phone.Data.Memory=entry;
58 smprintf(s, "Getting phonebook entry\n"); 61 smprintf(s, "Getting phonebook entry\n");
59 return GSM_WaitFor (s, req, 19, 0x03, 4, ID_GetMemory); 62 return GSM_WaitFor (s, req, 19, 0x03, 4, ID_GetMemory);
60} 63}
61 64
62static GSM_Error N6510_ReplyGetMemoryStatus(GSM_Protocol_Message msg, GSM_StateMachine *s) 65static GSM_Error N6510_ReplyGetMemoryStatus(GSM_Protocol_Message msg, GSM_StateMachine *s)
63{ 66{
64 GSM_Phone_Data *Data = &s->Phone.Data; 67 GSM_Phone_Data *Data = &s->Phone.Data;
65 68
66 smprintf(s, "Memory status received\n"); 69 smprintf(s, "Memory status received\n");
67 /* Quess ;-)) */ 70 /* Quess ;-)) */
68 if (msg.Buffer[14]==0x10) { 71 if (msg.Buffer[14]==0x10) {
69 Data->MemoryStatus->MemoryFree = msg.Buffer[18]*256 + msg.Buffer[19]; 72 Data->MemoryStatus->MemoryFree = msg.Buffer[18]*256 + msg.Buffer[19];
70 } else { 73 } else {
71 Data->MemoryStatus->MemoryFree = msg.Buffer[17]; 74 Data->MemoryStatus->MemoryFree = msg.Buffer[17];
72 } 75 }
73 smprintf(s, "Size : %i\n",Data->MemoryStatus->MemoryFree); 76 smprintf(s, "Size : %i\n",Data->MemoryStatus->MemoryFree);
74 Data->MemoryStatus->MemoryUsed = msg.Buffer[20]*256 + msg.Buffer[21]; 77 Data->MemoryStatus->MemoryUsed = msg.Buffer[20]*256 + msg.Buffer[21];
75 smprintf(s, "Used : %i\n",Data->MemoryStatus->MemoryUsed); 78 smprintf(s, "Used : %i\n",Data->MemoryStatus->MemoryUsed);
76 Data->MemoryStatus->MemoryFree -= Data->MemoryStatus->MemoryUsed; 79 Data->MemoryStatus->MemoryFree -= Data->MemoryStatus->MemoryUsed;
77 smprintf(s, "Free : %i\n",Data->MemoryStatus->MemoryFree); 80 smprintf(s, "Free : %i\n",Data->MemoryStatus->MemoryFree);
78 return ERR_NONE; 81 return ERR_NONE;
79} 82}
80 83
81static GSM_Error N6510_GetMemoryStatus(GSM_StateMachine *s, GSM_MemoryStatus *Status) 84static GSM_Error N6510_GetMemoryStatus(GSM_StateMachine *s, GSM_MemoryStatus *Status)
82{ 85{
83 unsigned char req[] = {N6110_FRAME_HEADER, 0x03, 0x02, 86 unsigned char req[] = {N6110_FRAME_HEADER, 0x03, 0x02,
84 0x00, /* memory type */ 87 0x00, /* memory type */
85 0x55, 0x55, 0x55, 0x00}; 88 0x55, 0x55, 0x55, 0x00};
86 89
87 req[5] = NOKIA_GetMemoryType(s, Status->MemoryType,N71_65_MEMORY_TYPES); 90 req[5] = NOKIA_GetMemoryType(s, Status->MemoryType,N71_65_MEMORY_TYPES);
88 if (req[5]==0xff) return ERR_NOTSUPPORTED; 91 if (req[5]==0xff) return ERR_NOTSUPPORTED;
89 92
90 s->Phone.Data.MemoryStatus=Status; 93 s->Phone.Data.MemoryStatus=Status;
91 smprintf(s, "Getting memory status\n"); 94 smprintf(s, "Getting memory status\n");
92 return GSM_WaitFor (s, req, 10, 0x03, 4, ID_GetMemoryStatus); 95 return GSM_WaitFor (s, req, 10, 0x03, 4, ID_GetMemoryStatus);
93} 96}
94 97
95static GSM_Error N6510_ReplyGetSMSC(GSM_Protocol_Message msg, GSM_StateMachine *s) 98static GSM_Error N6510_ReplyGetSMSC(GSM_Protocol_Message msg, GSM_StateMachine *s)
96{ 99{
97 int i, current, j; 100 int i, current, j;
98 GSM_Phone_Data *Data = &s->Phone.Data; 101 GSM_Phone_Data *Data = &s->Phone.Data;
99 102
100 switch (msg.Buffer[4]) { 103 switch (msg.Buffer[4]) {
101 case 0x00: 104 case 0x00:
102 smprintf(s, "SMSC received\n"); 105 smprintf(s, "SMSC received\n");
103 break; 106 break;
104 case 0x02: 107 case 0x02:
105 smprintf(s, "SMSC empty\n"); 108 smprintf(s, "SMSC empty\n");
106 return ERR_INVALIDLOCATION; 109 return ERR_INVALIDLOCATION;
107 default: 110 default:
108 smprintf(s, "Unknown SMSC state: %02x\n",msg.Buffer[4]); 111 smprintf(s, "Unknown SMSC state: %02x\n",msg.Buffer[4]);
109 return ERR_UNKNOWNRESPONSE; 112 return ERR_UNKNOWNRESPONSE;
110 } 113 }
111 memset(Data->SMSC,0,sizeof(GSM_SMSC)); 114 memset(Data->SMSC,0,sizeof(GSM_SMSC));
112 Data->SMSC->Location = msg.Buffer[8]; 115 Data->SMSC->Location = msg.Buffer[8];
113 Data->SMSC->Format = SMS_FORMAT_Text; 116 Data->SMSC->Format = SMS_FORMAT_Text;
114 switch (msg.Buffer[10]) { 117 switch (msg.Buffer[10]) {
115 case 0x00: Data->SMSC->Format = SMS_FORMAT_Text; break; 118 case 0x00: Data->SMSC->Format = SMS_FORMAT_Text; break;
116 case 0x22: Data->SMSC->Format = SMS_FORMAT_Fax; break; 119 case 0x22: Data->SMSC->Format = SMS_FORMAT_Fax; break;
117 case 0x26: Data->SMSC->Format = SMS_FORMAT_Pager;break; 120 case 0x26: Data->SMSC->Format = SMS_FORMAT_Pager;break;
118 case 0x32: Data->SMSC->Format = SMS_FORMAT_Email;break; 121 case 0x32: Data->SMSC->Format = SMS_FORMAT_Email;break;
119 } 122 }
120 Data->SMSC->Validity.Format= SMS_Validity_RelativeFormat; 123 Data->SMSC->Validity.Format= SMS_Validity_RelativeFormat;
121 Data->SMSC->Validity.Relative= msg.Buffer[12]; 124 Data->SMSC->Validity.Relative= msg.Buffer[12];
125 if (msg.Buffer[12] == 0x00) Data->SMSC->Validity.Relative = SMS_VALID_Max_Time;
126
122 current = 14; 127 current = 14;
123 for (i=0;i<msg.Buffer[13];i++) { 128 for (i=0;i<msg.Buffer[13];i++) {
124 switch (msg.Buffer[current]) { 129 switch (msg.Buffer[current]) {
125 case 0x81: 130 case 0x81:
126 j=current+4; 131 j=current+4;
127 while (msg.Buffer[j]!=0) {j++;} 132 while (msg.Buffer[j]!=0) {j++;}
128 j=j-33; 133 j=j-33;
129 if (j>GSM_MAX_SMSC_NAME_LENGTH) { 134 if (j>GSM_MAX_SMSC_NAME_LENGTH) {
130 smprintf(s, "Too long name\n"); 135 smprintf(s, "Too long name\n");
131 return ERR_UNKNOWNRESPONSE; 136 return ERR_UNKNOWNRESPONSE;
132 } 137 }
133 CopyUnicodeString(Data->SMSC->Name,msg.Buffer+current+4); 138 CopyUnicodeString(Data->SMSC->Name,msg.Buffer+current+4);
134 smprintf(s, " Name \"%s\"\n", DecodeUnicodeString(Data->SMSC->Name)); 139 smprintf(s, " Name \"%s\"\n", DecodeUnicodeString(Data->SMSC->Name));
135 break; 140 break;
136 case 0x82: 141 case 0x82:
137 switch (msg.Buffer[current+2]) { 142 switch (msg.Buffer[current+2]) {
138 case 0x01: 143 case 0x01:
139 GSM_UnpackSemiOctetNumber(Data->SMSC->DefaultNumber,msg.Buffer+current+4,true); 144 GSM_UnpackSemiOctetNumber(Data->SMSC->DefaultNumber,msg.Buffer+current+4,true);
140 smprintf(s, " Default number \"%s\"\n", DecodeUnicodeString(Data->SMSC->DefaultNumber)); 145 smprintf(s, " Default number \"%s\"\n", DecodeUnicodeString(Data->SMSC->DefaultNumber));
141 break; 146 break;
142 case 0x02: 147 case 0x02:
143 GSM_UnpackSemiOctetNumber(Data->SMSC->Number,msg.Buffer+current+4,false); 148 GSM_UnpackSemiOctetNumber(Data->SMSC->Number,msg.Buffer+current+4,false);
144 smprintf(s, " Number \"%s\"\n", DecodeUnicodeString(Data->SMSC->Number)); 149 smprintf(s, " Number \"%s\"\n", DecodeUnicodeString(Data->SMSC->Number));
145 break; 150 break;
146 default: 151 default:
147 smprintf(s, "Unknown SMSC number: %02x\n",msg.Buffer[current+2]); 152 smprintf(s, "Unknown SMSC number: %02x\n",msg.Buffer[current+2]);
148 return ERR_UNKNOWNRESPONSE; 153 return ERR_UNKNOWNRESPONSE;
149 } 154 }
150 break; 155 break;
151 default: 156 default:
152 smprintf(s, "Unknown SMSC block: %02x\n",msg.Buffer[current]); 157 smprintf(s, "Unknown SMSC block: %02x\n",msg.Buffer[current]);
153 return ERR_UNKNOWNRESPONSE; 158 return ERR_UNKNOWNRESPONSE;
154 } 159 }
155 current = current + msg.Buffer[current+1]; 160 current = current + msg.Buffer[current+1];
156 } 161 }
157 return ERR_NONE; 162 return ERR_NONE;
158} 163}
159 164
160static GSM_Error N6510_GetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc) 165static GSM_Error N6510_GetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc)
161{ 166{
162 unsigned char req[] = {N6110_FRAME_HEADER, 0x14, 167 unsigned char req[] = {N6110_FRAME_HEADER, 0x14,
163 0x01, /* location */ 168 0x01, /* location */
164 0x00}; 169 0x00};
165 170
166 if (smsc->Location==0x00) return ERR_INVALIDLOCATION; 171 if (smsc->Location==0x00) return ERR_INVALIDLOCATION;
167 172
168 req[4]=smsc->Location; 173 req[4]=smsc->Location;
169 174
170 s->Phone.Data.SMSC=smsc; 175 s->Phone.Data.SMSC=smsc;
171 smprintf(s, "Getting SMSC\n"); 176 smprintf(s, "Getting SMSC\n");
172 return GSM_WaitFor (s, req, 6, 0x02, 4, ID_GetSMSC); 177 return GSM_WaitFor (s, req, 6, 0x02, 4, ID_GetSMSC);
173} 178}
174 179
175static GSM_Error N6510_ReplySetSMSC(GSM_Protocol_Message msg, GSM_StateMachine *s) 180static GSM_Error N6510_ReplySetSMSC(GSM_Protocol_Message msg, GSM_StateMachine *s)
176{ 181{
177 switch (msg.Buffer[4]) { 182 switch (msg.Buffer[4]) {
178 case 0x00: 183 case 0x00:
179 smprintf(s, "SMSC set OK\n"); 184 smprintf(s, "SMSC set OK\n");
180 return ERR_NONE; 185 return ERR_NONE;
181 case 0x02: 186 case 0x02:
182 smprintf(s, "Invalid SMSC location\n"); 187 smprintf(s, "Invalid SMSC location\n");
183 return ERR_INVALIDLOCATION; 188 return ERR_INVALIDLOCATION;
184 default: 189 default:
185 smprintf(s, "Unknown SMSC state: %02x\n",msg.Buffer[4]); 190 smprintf(s, "Unknown SMSC state: %02x\n",msg.Buffer[4]);
186 return ERR_UNKNOWNRESPONSE; 191 return ERR_UNKNOWNRESPONSE;
187 } 192 }
188 return ERR_UNKNOWNRESPONSE; 193 return ERR_UNKNOWNRESPONSE;
189} 194}
190 195
191static GSM_Error N6510_SetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc) 196static GSM_Error N6510_SetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc)
192{ 197{
193 int count = 13,i; 198 int count = 13,i;
194 unsigned char req[256] = {N6110_FRAME_HEADER, 199 unsigned char req[256] = {N6110_FRAME_HEADER,
195 0x12, 0x55, 0x01, 0x0B, 0x34, 200 0x12, 0x55, 0x01, 0x0B, 0x34,
196 0x05, /* Location */ 201 0x05, /* Location */
197 0x00, 202 0x00,
198 0x00, /* Format */ 203 0x00, /* Format */
199 0x00, 204 0x00,
200 0xFF}; /* Validity*/ 205 0xFF}; /* Validity*/
201 206
202 req[8] = smsc->Location; 207 req[8] = smsc->Location;
203 switch (smsc->Format) { 208 switch (smsc->Format) {
204 case SMS_FORMAT_Text: req[10] = 0x00;break; 209 case SMS_FORMAT_Text: req[10] = 0x00;break;
205 case SMS_FORMAT_Fax: req[10] = 0x22;break; 210 case SMS_FORMAT_Fax: req[10] = 0x22;break;
206 case SMS_FORMAT_Pager: req[10] = 0x26;break; 211 case SMS_FORMAT_Pager: req[10] = 0x26;break;
207 case SMS_FORMAT_Email: req[10] = 0x32;break; 212 case SMS_FORMAT_Email: req[10] = 0x32;break;
208 } 213 }
209 req[12] = smsc->Validity.Relative; 214 req[12] = smsc->Validity.Relative;
210 215
211 /* We have now blocks. Number of blocks = 3 */ 216 /* We have now blocks. Number of blocks = 3 */
212 req[count++] = 0x03; 217 req[count++] = 0x03;
213 218
214 /* -------------- SMSC number ----------------- */ 219 /* -------------- SMSC number ----------------- */
215 /* Block type: number */ 220 /* Block type: number */
216 req[count++] = 0x82; 221 req[count++] = 0x82;
217 /* Offset to next block */ 222 /* Offset to next block */
218 req[count++] = 0x1A; 223 req[count++] = 0x1A;
219 /* Type of number: SMSC number */ 224 /* Type of number: SMSC number */
220 req[count++] = 0x02; 225 req[count++] = 0x02;
221 req[count] = GSM_PackSemiOctetNumber(smsc->Number, req+count+2, false) + 1; 226 req[count] = GSM_PackSemiOctetNumber(smsc->Number, req+count+2, false) + 1;
222 if (req[count]>18) { 227 if (req[count]>18) {
223 smprintf(s, "Too long SMSC number in frame\n"); 228 smprintf(s, "Too long SMSC number in frame\n");
224 return ERR_UNKNOWN; 229 return ERR_UNKNOWN;
225 } 230 }
226 req[count+1] = req[count] - 1; 231 req[count+1] = req[count] - 1;
227 count += 23; 232 count += 23;
228 233
229 /* --------------- Default number ------------- */ 234 /* --------------- Default number ------------- */
230 /* Block type: number */ 235 /* Block type: number */
231 req[count++] = 0x82; 236 req[count++] = 0x82;
232 /* Offset to next block */ 237 /* Offset to next block */
233 req[count++] = 0x14; 238 req[count++] = 0x14;
234 /* Type of number: default number */ 239 /* Type of number: default number */
235 req[count++] = 0x01; 240 req[count++] = 0x01;
236 req[count] = GSM_PackSemiOctetNumber(smsc->DefaultNumber, req+count+2, true) + 1; 241 req[count] = GSM_PackSemiOctetNumber(smsc->DefaultNumber, req+count+2, true) + 1;
237 if (req[count]*2>12) { 242 if (req[count]*2>12) {
238 smprintf(s, "Too long SMSC number in frame\n"); 243 smprintf(s, "Too long SMSC number in frame\n");
239 return ERR_UNKNOWN; 244 return ERR_UNKNOWN;
240 } 245 }
241 req[count+1] = req[count] - 1; 246 req[count+1] = req[count] - 1;
242 count += 17; 247 count += 17;
243 248
244 /* -------------- SMSC name ------------------- */ 249 /* -------------- SMSC name ------------------- */
245 req[count++] = 0x81; 250 req[count++] = 0x81;
246 req[count++] = UnicodeLength(smsc->Name)*2 + 2 + 4; 251 req[count++] = UnicodeLength(smsc->Name)*2 + 2 + 4;
247 req[count++] = UnicodeLength(smsc->Name)*2 + 2; 252 req[count++] = UnicodeLength(smsc->Name)*2 + 2;
248 req[count++] = 0x00; 253 req[count++] = 0x00;
249 /* Can't make CopyUnicodeString(req+count,sms->Name) !!!! 254 /* Can't make CopyUnicodeString(req+count,sms->Name) !!!!
250 * with MSVC6 count is changed then 255 * with MSVC6 count is changed then
251 */ 256 */
252 i = count; 257 i = count;
253 CopyUnicodeString(req+i,smsc->Name); 258 CopyUnicodeString(req+i,smsc->Name);
254 count += UnicodeLength(smsc->Name)*2 + 2; 259 count += UnicodeLength(smsc->Name)*2 + 2;
255 260
256 smprintf(s, "Setting SMSC\n"); 261 smprintf(s, "Setting SMSC\n");
257 return GSM_WaitFor (s, req, count, 0x02, 4, ID_SetSMSC); 262 return GSM_WaitFor (s, req, count, 0x02, 4, ID_SetSMSC);
258} 263}
259 264
260static GSM_Error N6510_ReplyGetNetworkInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 265static GSM_Error N6510_ReplyGetNetworkInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
261{ 266{
262 int current = msg.Buffer[7]+7, tmp; 267 int current = msg.Buffer[7]+7, tmp;
263 GSM_Phone_Data*Data = &s->Phone.Data; 268 GSM_Phone_Data*Data = &s->Phone.Data;
264#ifdef DEBUG 269#ifdef DEBUG
265 char name[100]; 270 char name[100];
266 GSM_NetworkInfo NetInfo; 271 GSM_NetworkInfo NetInfo;
267 272
268 smprintf(s, "Network status: "); 273 smprintf(s, "Network status : ");
269 switch (msg.Buffer[8]) { 274 switch (msg.Buffer[8]) {
270 case 0x00 : smprintf(s, "home network\n"); break; 275 case 0x00 : smprintf(s, "home network\n"); break;
271 case 0x01 : smprintf(s, "roaming network\n"); break; 276 case 0x01 : smprintf(s, "roaming network\n"); break;
272 case 0x04 : smprintf(s, "not logged"); break; 277 case 0x04 : smprintf(s, "not logged"); break;
273 case 0x06 : smprintf(s, "SIM card rejected\n"); break; 278 case 0x06 : smprintf(s, "SIM card rejected\n"); break;
274 case 0x09 : smprintf(s, "not logged"); break; 279 case 0x09 : smprintf(s, "not logged"); break;
275 default : smprintf(s, "unknown %i!\n",msg.Buffer[8]); break; 280 default : smprintf(s, "unknown %i!\n",msg.Buffer[8]); break;
276 } 281 }
277 if (msg.Buffer[8]==0x00 || msg.Buffer[8] == 0x01) { 282 if (msg.Buffer[8]==0x00 || msg.Buffer[8] == 0x01) {
278 NOKIA_DecodeNetworkCode(msg.Buffer + (current + 7),NetInfo.NetworkCode); 283 NOKIA_DecodeNetworkCode(msg.Buffer + (current + 7),NetInfo.NetworkCode);
279 smprintf(s, "Network code : %s\n", NetInfo.NetworkCode); 284 smprintf(s, "Network code : %s\n", NetInfo.NetworkCode);
280 smprintf(s, "Network name for Gammu : %s ", 285 smprintf(s, "Network name for Gammu : %s ",
281 DecodeUnicodeString(GSM_GetNetworkName(NetInfo.NetworkCode))); 286 DecodeUnicodeString(GSM_GetNetworkName(NetInfo.NetworkCode)));
282 smprintf(s, "(%s)\n",DecodeUnicodeString(GSM_GetCountryName(NetInfo.NetworkCode))); 287 smprintf(s, "(%s)\n",DecodeUnicodeString(GSM_GetCountryName(NetInfo.NetworkCode)));
283 288
284 sprintf(NetInfo.LAC,"%02x%02x", msg.Buffer[current+1], msg.Buffer[current+2]); 289 sprintf(NetInfo.LAC,"%02x%02x", msg.Buffer[current+1], msg.Buffer[current+2]);
285 smprintf(s, "LAC : %s\n", NetInfo.LAC); 290 smprintf(s, "LAC : %s\n", NetInfo.LAC);
286 291
287 sprintf(NetInfo.CID, "%02x%02x", msg.Buffer[current+5], msg.Buffer[current+6]); 292 sprintf(NetInfo.CID, "%02x%02x", msg.Buffer[current+5], msg.Buffer[current+6]);
288 smprintf(s, "CID : %s\n", NetInfo.CID); 293 smprintf(s, "CID : %s\n", NetInfo.CID);
289 294
290 tmp = 10; 295 tmp = 10;
291 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer,name,true); 296 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer,name,true);
292 smprintf(s, "Network name for phone : %s\n",DecodeUnicodeString(name)); 297 smprintf(s, "Network name for phone : %s\n",DecodeUnicodeString(name));
293 } 298 }
294#endif 299#endif
295 if (Data->RequestID==ID_GetNetworkInfo) { 300 if (Data->RequestID==ID_GetNetworkInfo) {
296 Data->NetworkInfo->NetworkName[0] = 0x00; 301 Data->NetworkInfo->NetworkName[0] = 0x00;
297 Data->NetworkInfo->NetworkName[1] = 0x00; 302 Data->NetworkInfo->NetworkName[1] = 0x00;
298 Data->NetworkInfo->State = 0; 303 Data->NetworkInfo->State = 0;
299 switch (msg.Buffer[8]) { 304 switch (msg.Buffer[8]) {
300 case 0x00: Data->NetworkInfo->State = GSM_HomeNetwork; break; 305 case 0x00: Data->NetworkInfo->State = GSM_HomeNetwork; break;
301 case 0x01: Data->NetworkInfo->State = GSM_RoamingNetwork;break; 306 case 0x01: Data->NetworkInfo->State = GSM_RoamingNetwork;break;
302 case 0x04: 307 case 0x04:
303 case 0x06: 308 case 0x06:
304 case 0x09: Data->NetworkInfo->State = GSM_NoNetwork; break; 309 case 0x09: Data->NetworkInfo->State = GSM_NoNetwork; break;
305 } 310 }
306 if (Data->NetworkInfo->State == GSM_HomeNetwork || Data->NetworkInfo->State == GSM_RoamingNetwork) { 311 if (Data->NetworkInfo->State == GSM_HomeNetwork || Data->NetworkInfo->State == GSM_RoamingNetwork) {
307 tmp = 10; 312 tmp = 10;
308 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer,Data->NetworkInfo->NetworkName,true); 313 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer,Data->NetworkInfo->NetworkName,true);
309 sprintf(Data->NetworkInfo->LAC, "%02x%02x", msg.Buffer[current+1], msg.Buffer[current+2]); 314 sprintf(Data->NetworkInfo->LAC, "%02x%02x", msg.Buffer[current+1], msg.Buffer[current+2]);
310 sprintf(Data->NetworkInfo->CID, "%02x%02x", msg.Buffer[current+5], msg.Buffer[current+6]); 315 sprintf(Data->NetworkInfo->CID, "%02x%02x", msg.Buffer[current+5], msg.Buffer[current+6]);
311 NOKIA_DecodeNetworkCode(msg.Buffer + (current+7),Data->NetworkInfo->NetworkCode); 316 NOKIA_DecodeNetworkCode(msg.Buffer + (current+7),Data->NetworkInfo->NetworkCode);
312 } 317 }
313 } 318 }
314 return ERR_NONE; 319 return ERR_NONE;
315} 320}
316 321
317static GSM_Error N6510_GetNetworkInfo(GSM_StateMachine *s, GSM_NetworkInfo *netinfo) 322static GSM_Error N6510_GetNetworkInfo(GSM_StateMachine *s, GSM_NetworkInfo *netinfo)
318{ 323{
319 unsigned char req[] = {N6110_FRAME_HEADER, 0x00, 0x00}; 324 unsigned char req[] = {N6110_FRAME_HEADER, 0x00, 0x00};
320 325
321 s->Phone.Data.NetworkInfo=netinfo; 326 s->Phone.Data.NetworkInfo=netinfo;
322 smprintf(s, "Getting network info\n"); 327 smprintf(s, "Getting network info\n");
323 return GSM_WaitFor (s, req, 5, 0x0a, 4, ID_GetNetworkInfo); 328 return GSM_WaitFor (s, req, 5, 0x0a, 4, ID_GetNetworkInfo);
324} 329}
325 330
326static GSM_Error N6510_EncodeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char *req, GSM_SMSMessageLayout *Layout, int *length) 331static GSM_Error N6510_EncodeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char *req, GSM_SMSMessageLayout *Layout, int *length)
327{ 332{
328 int start, count = 0, pos1, pos2, pos3, pos4, pos5; 333 int start, count = 0, pos1, pos2, pos3, pos4, pos5;
329 GSM_Error error; 334 GSM_Error error;
330 335
331 memset(Layout,255,sizeof(GSM_SMSMessageLayout)); 336 memset(Layout,255,sizeof(GSM_SMSMessageLayout));
332 337
333 start = *length; 338 start = *length;
334 339
335 req[count++] = 0x01; 340 req[count++] = 0x01;
336 if (sms->PDU != SMS_Deliver) { 341 if (sms->PDU != SMS_Deliver) {
337 req[count++] = 0x02; 342 req[count++] = 0x02;
338 } else { 343 } else {
339 req[count++] = 0x00; 344 req[count++] = 0x00;
340 } 345 }
341 346
342 pos1 = count; count++; 347 pos1 = count; count++;
343 /* firstbyte set in SMS Layout */ 348 /* firstbyte set in SMS Layout */
344 Layout->firstbyte = count; count++; 349 Layout->firstbyte = count; count++;
345 if (sms->PDU != SMS_Deliver) { 350 if (sms->PDU != SMS_Deliver) {
346 Layout->TPMR = count; count++; 351 Layout->TPMR = count; count++;
347 352
348 Layout->TPPID = count; count++; 353 Layout->TPPID = count; count++;
349 354
350 /* TP.DCS set in SMS layout */ 355 /* TP.DCS set in SMS layout */
351 Layout->TPDCS = count; count++; 356 Layout->TPDCS = count; count++;
352 req[count++] = 0x00; 357 req[count++] = 0x00;
353 } else { 358 } else {
354 Layout->TPPID = count; count++; 359 Layout->TPPID = count; count++;
355 /* TP.DCS set in SMS layout */ 360 /* TP.DCS set in SMS layout */
356 Layout->TPDCS = count; count++; 361 Layout->TPDCS = count; count++;
357 Layout->DateTime = count; count += 7; 362 Layout->DateTime = count; count += 7;
358 req[count++] = 0x55; 363 req[count++] = 0x55;
359 req[count++] = 0x55; 364 req[count++] = 0x55;
360 req[count++] = 0x55; 365 req[count++] = 0x55;
361 } 366 }
362 367
363 /* We have now blocks. Number of blocks = 3 or 4 */ 368 /* We have now blocks. Number of blocks = 3 or 4 */
364 if (sms->PDU != SMS_Deliver) { 369 if (sms->PDU != SMS_Deliver) {
365 req[count++] = 0x04; 370 req[count++] = 0x04;
366 } else { 371 } else {
367 req[count++] = 0x03; 372 req[count++] = 0x03;
368 } 373 }
369 374
370 /* -------------- Phone number ------------- */ 375 /* -------------- Phone number ------------- */
371 /* Block type: number */ 376 /* Block type: number */
372 req[count++] = 0x82; 377 req[count++] = 0x82;
373 /* Offset to next block */ 378 /* Offset to next block */
374 req[count++] = 0x10; 379 req[count++] = 0x10;
375 /* Type of number: default number */ 380 /* Type of number: default number */
376 req[count++] = 0x01; 381 req[count++] = 0x01;
377 pos4 = count; count++; 382 pos4 = count; count++;
378 /* now coded Number in SMS Layout */ 383 /* now coded Number in SMS Layout */
379 Layout->Number = count; count+= 12; 384 Layout->Number = count; count+= 12;
380 385
381 /* -------------- SMSC number -------------- */ 386 /* -------------- SMSC number -------------- */
382 /* Block type: number */ 387 /* Block type: number */
383 req[count++] = 0x82; 388 req[count++] = 0x82;
384 /* Offset to next block */ 389 /* Offset to next block */
385 req[count++] = 0x10; 390 req[count++] = 0x10;
386 /* Type of number: SMSC number */ 391 /* Type of number: SMSC number */
387 req[count++] = 0x02; 392 req[count++] = 0x02;
388 pos5 = count; count++; 393 pos5 = count; count++;
389 /* now coded SMSC number in SMS Layout */ 394 /* now coded SMSC number in SMS Layout */
390 Layout->SMSCNumber = count; count += 12; 395 Layout->SMSCNumber = count; count += 12;
391 396
392 /* -------------- SMS validity ------------- */ 397 /* -------------- SMS validity ------------- */
393 if (sms->PDU != SMS_Deliver) { 398 if (sms->PDU != SMS_Deliver) {
394 /* Block type: validity */ 399 /* Block type: validity */
395 req[count++] = 0x08; 400 req[count++] = 0x08;
396 req[count++] = 0x04; 401 req[count++] = 0x04;
397 /* data length */ 402 /* data length */
398 req[count++] = 0x01; 403 req[count++] = 0x01;
399 Layout->TPVP = count; count++; 404 Layout->TPVP = count; count++;
400 } 405 }
401 406
402 /* --------------- SMS text ---------------- */ 407 /* --------------- SMS text ---------------- */
403 /* Block type: SMS text */ 408 /* Block type: SMS text */
404 req[count++] = 0x80; 409 req[count++] = 0x80;
405 /* this the same as req[11] but starting from req[42] */ 410 /* this the same as req[11] but starting from req[42] */
406 pos2 = count; count++; 411 pos2 = count; count++;
407 pos3 = count; count++; 412 pos3 = count; count++;
408 /* FIXME*/ 413 /* FIXME*/
409 Layout->TPUDL = count; count++; 414 Layout->TPUDL = count; count++;
410 /* SMS text and UDH coded in SMS Layout */ 415 /* SMS text and UDH coded in SMS Layout */
411 Layout->Text = count; 416 Layout->Text = count;
412 417
413 error = PHONE_EncodeSMSFrame(s,sms,req,*Layout,length,false); 418 error = PHONE_EncodeSMSFrame(s,sms,req,*Layout,length,false);
414 if (error != ERR_NONE) return error; 419 if (error != ERR_NONE) return error;
415 420
416 req[pos1] = *length - 1; 421 req[pos1] = *length - 1;
417 req[pos2] = *length - Layout->Text + 6; 422 req[pos2] = *length - Layout->Text + 6;
418 req[pos3] = *length - Layout->Text; 423 req[pos3] = *length - Layout->Text;
419 424
420 /* Convert number of semioctets to number of chars */ 425 /* Convert number of semioctets to number of chars */
421 req[pos4] = req[Layout->Number] + 4; 426 req[pos4] = req[Layout->Number] + 4;
422 if (req[pos4] % 2) req[pos4]++; 427 if (req[pos4] % 2) req[pos4]++;
423 req[pos4] /= 2; 428 req[pos4] /= 2;
424 429
425 req[pos5] = req[Layout->SMSCNumber] + 1; 430 req[pos5] = req[Layout->SMSCNumber] + 1;
426 431
427 if (req[pos4]>12 || req[pos5]>12) { 432 if (req[pos4]>12 || req[pos5]>12) {
428 smprintf(s, "Too long phone number in frame\n"); 433 smprintf(s, "Too long phone number in frame\n");
429 return ERR_UNKNOWN; 434 return ERR_UNKNOWN;
430 } 435 }
431 436
432 return ERR_NONE; 437 return ERR_NONE;
433} 438}
434 439
435static GSM_Error N6510_ReplyGetSMSFolders(GSM_Protocol_Message msg, GSM_StateMachine *s) 440static GSM_Error N6510_ReplyGetSMSFolders(GSM_Protocol_Message msg, GSM_StateMachine *s)
436{ 441{
437 int j, num = 0, pos; 442 int j, num = 0, pos;
438 GSM_Phone_Data *Data = &s->Phone.Data; 443 GSM_Phone_Data *Data = &s->Phone.Data;
439 444
440 switch (msg.Buffer[3]) { 445 switch (msg.Buffer[3]) {
441 case 0x13: 446 case 0x13:
442 smprintf(s, "SMS folders names received\n"); 447 smprintf(s, "SMS folders names received\n");
443 Data->SMSFolders->Number = msg.Buffer[5]+2; 448 Data->SMSFolders->Number = msg.Buffer[5]+2;
444 pos = 6; 449 pos = 6;
445 for (j=0;j<msg.Buffer[5];j++) { 450 for (j=0;j<msg.Buffer[5];j++) {
446 while (true) { 451 while (true) {
447 if (msg.Buffer[pos] == msg.Buffer[6] && 452 if (msg.Buffer[pos] == msg.Buffer[6] &&
448 msg.Buffer[pos+1] == msg.Buffer[7]) break; 453 msg.Buffer[pos+1] == msg.Buffer[7]) break;
449 if (pos+4 > msg.Length) return ERR_UNKNOWNRESPONSE; 454 if (pos+4 > msg.Length) return ERR_UNKNOWNRESPONSE;
450 pos++; 455 pos++;
451 } 456 }
452 pos+=4; 457 pos+=4;
453 smprintf(s, "Folder index: %02x",msg.Buffer[pos - 2]); 458 smprintf(s, "Folder index: %02x",msg.Buffer[pos - 2]);
454 if (msg.Buffer[pos - 1]>GSM_MAX_SMS_FOLDER_NAME_LEN) { 459 if (msg.Buffer[pos - 1]>GSM_MAX_SMS_FOLDER_NAME_LEN) {
455 smprintf(s, "Too long text\n"); 460 smprintf(s, "Too long text\n");
456 return ERR_UNKNOWNRESPONSE; 461 return ERR_UNKNOWNRESPONSE;
457 } 462 }
458 CopyUnicodeString(Data->SMSFolders->Folder[num].Name,msg.Buffer + pos); 463 CopyUnicodeString(Data->SMSFolders->Folder[num].Name,msg.Buffer + pos);
459 smprintf(s, ", folder name: \"%s\"\n",DecodeUnicodeString(Data->SMSFolders->Folder[num].Name)); 464 smprintf(s, ", folder name: \"%s\"\n",DecodeUnicodeString(Data->SMSFolders->Folder[num].Name));
460 Data->SMSFolders->Folder[num].InboxFolder = false; 465 Data->SMSFolders->Folder[num].InboxFolder = false;
@@ -796,389 +801,389 @@ static GSM_Error N6510_GetNextSMSMessageBitmap(GSM_StateMachine *s, GSM_MultiSMS
796 if (i==Priv->LastSMSFolder.Number-1) { 801 if (i==Priv->LastSMSFolder.Number-1) {
797 findnextfolder=true; 802 findnextfolder=true;
798 } else { 803 } else {
799 location=Priv->LastSMSFolder.Location[i+1]; 804 location=Priv->LastSMSFolder.Location[i+1];
800 } 805 }
801 } 806 }
802 if (findnextfolder) { 807 if (findnextfolder) {
803 Priv->LastSMSFolder.Number=0; 808 Priv->LastSMSFolder.Number=0;
804 while (Priv->LastSMSFolder.Number==0) { 809 while (Priv->LastSMSFolder.Number==0) {
805 folderid++; 810 folderid++;
806 /* Too high folder number */ 811 /* Too high folder number */
807 if ((folderid-1)>Priv->LastSMSFolders.Number) return ERR_EMPTY; 812 if ((folderid-1)>Priv->LastSMSFolders.Number) return ERR_EMPTY;
808 /* Get next folder status */ 813 /* Get next folder status */
809 error=N6510_GetSMSFolderStatus(s, folderid); 814 error=N6510_GetSMSFolderStatus(s, folderid);
810 if (error!=ERR_NONE) return error; 815 if (error!=ERR_NONE) return error;
811 /* First location from this folder */ 816 /* First location from this folder */
812 location=Priv->LastSMSFolder.Location[0]; 817 location=Priv->LastSMSFolder.Location[0];
813 } 818 }
814 } 819 }
815 N6510_SetSMSLocation(s, &sms->SMS[0], folderid, location); 820 N6510_SetSMSLocation(s, &sms->SMS[0], folderid, location);
816 821
817 return N6510_PrivGetSMSMessageBitmap(s, sms, bitmap); 822 return N6510_PrivGetSMSMessageBitmap(s, sms, bitmap);
818} 823}
819 824
820static GSM_Error N6510_GetNextSMSMessage(GSM_StateMachine *s, GSM_MultiSMSMessage *sms, bool start) 825static GSM_Error N6510_GetNextSMSMessage(GSM_StateMachine *s, GSM_MultiSMSMessage *sms, bool start)
821{ 826{
822 return N6510_GetNextSMSMessageBitmap(s, sms, start, NULL); 827 return N6510_GetNextSMSMessageBitmap(s, sms, start, NULL);
823} 828}
824 829
825static GSM_Error N6510_ReplyStartupNoteLogo(GSM_Protocol_Message msg, GSM_StateMachine *s) 830static GSM_Error N6510_ReplyStartupNoteLogo(GSM_Protocol_Message msg, GSM_StateMachine *s)
826{ 831{
827 GSM_Phone_Data *Data = &s->Phone.Data; 832 GSM_Phone_Data *Data = &s->Phone.Data;
828 833
829 if (Data->RequestID == ID_GetBitmap) { 834 if (Data->RequestID == ID_GetBitmap) {
830 switch (msg.Buffer[4]) { 835 switch (msg.Buffer[4]) {
831 case 0x01: 836 case 0x01:
832 smprintf(s, "Welcome note text received\n"); 837 smprintf(s, "Welcome note text received\n");
833 CopyUnicodeString(Data->Bitmap->Text,msg.Buffer+6); 838 CopyUnicodeString(Data->Bitmap->Text,msg.Buffer+6);
834 smprintf(s, "Text is \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Text)); 839 smprintf(s, "Text is \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Text));
835 return ERR_NONE; 840 return ERR_NONE;
836 case 0x10: 841 case 0x10:
837 smprintf(s, "Dealer note text received\n"); 842 smprintf(s, "Dealer note text received\n");
838 CopyUnicodeString(Data->Bitmap->Text,msg.Buffer+6); 843 CopyUnicodeString(Data->Bitmap->Text,msg.Buffer+6);
839 smprintf(s, "Text is \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Text)); 844 smprintf(s, "Text is \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Text));
840 return ERR_NONE; 845 return ERR_NONE;
841 case 0x0f: 846 case 0x0f:
842 smprintf(s, "Startup logo received\n"); 847 smprintf(s, "Startup logo received\n");
843 PHONE_DecodeBitmap(GSM_Nokia7110StartupLogo, msg.Buffer + 22, Data->Bitmap); 848 PHONE_DecodeBitmap(GSM_Nokia7110StartupLogo, msg.Buffer + 22, Data->Bitmap);
844 return ERR_NONE; 849 return ERR_NONE;
845 } 850 }
846 } 851 }
847 if (Data->RequestID == ID_SetBitmap) { 852 if (Data->RequestID == ID_SetBitmap) {
848 switch (msg.Buffer[4]) { 853 switch (msg.Buffer[4]) {
849 case 0x01: 854 case 0x01:
850 case 0x10: 855 case 0x10:
851 case 0x0f: 856 case 0x0f:
852 case 0x25: 857 case 0x25:
853 return ERR_NONE; 858 return ERR_NONE;
854 } 859 }
855 } 860 }
856 return ERR_UNKNOWN; 861 return ERR_UNKNOWN;
857} 862}
858 863
859static GSM_Error N6510_GetPictureImage(GSM_StateMachine *s, GSM_Bitmap *Bitmap, int *location) 864static GSM_Error N6510_GetPictureImage(GSM_StateMachine *s, GSM_Bitmap *Bitmap, int *location)
860{ 865{
861 GSM_MultiSMSMessage sms; 866 GSM_MultiSMSMessage sms;
862 int Number; 867 int Number;
863 GSM_Bitmap bitmap; 868 GSM_Bitmap bitmap;
864 GSM_Error error; 869 GSM_Error error;
865 870
866 sms.SMS[0].Folder= 0; 871 sms.SMS[0].Folder= 0;
867 Number = 0; 872 Number = 0;
868 bitmap.Location = 255; 873 bitmap.Location = 255;
869 error=N6510_GetNextSMSMessageBitmap(s, &sms, true, &bitmap); 874 error=N6510_GetNextSMSMessageBitmap(s, &sms, true, &bitmap);
870 while (error == ERR_NONE) { 875 while (error == ERR_NONE) {
871 if (bitmap.Location != 255) { 876 if (bitmap.Location != 255) {
872 Number++; 877 Number++;
873 if (Number == Bitmap->Location) { 878 if (Number == Bitmap->Location) {
874 bitmap.Location = Bitmap->Location; 879 bitmap.Location = Bitmap->Location;
875 memcpy(Bitmap,&bitmap,sizeof(GSM_Bitmap)); 880 memcpy(Bitmap,&bitmap,sizeof(GSM_Bitmap));
876 *location = sms.SMS[0].Location; 881 *location = sms.SMS[0].Location;
877 return ERR_NONE; 882 return ERR_NONE;
878 } 883 }
879 } 884 }
880 bitmap.Location = 255; 885 bitmap.Location = 255;
881 sms.SMS[0].Folder = 0; 886 sms.SMS[0].Folder = 0;
882 error=N6510_GetNextSMSMessageBitmap(s, &sms, false, &bitmap); 887 error=N6510_GetNextSMSMessageBitmap(s, &sms, false, &bitmap);
883 } 888 }
884 return ERR_INVALIDLOCATION; 889 return ERR_INVALIDLOCATION;
885} 890}
886 891
887static GSM_Error N6510_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap) 892static GSM_Error N6510_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
888{ 893{
889 unsigned char reqOp[] = {N6110_FRAME_HEADER, 0x23, 0x00, 0x00, 0x55, 0x55, 0x55}; 894 unsigned char reqOp[] = {N6110_FRAME_HEADER, 0x23, 0x00, 0x00, 0x55, 0x55, 0x55};
890 unsigned char reqStartup[] = {N6110_FRAME_HEADER, 0x02, 0x0f}; 895 unsigned char reqStartup[] = {N6110_FRAME_HEADER, 0x02, 0x0f};
891 unsigned char reqNote[] = {N6110_FRAME_HEADER, 0x02, 0x01, 0x00}; 896 unsigned char reqNote[] = {N6110_FRAME_HEADER, 0x02, 0x01, 0x00};
892 GSM_MemoryEntrypbk; 897 GSM_MemoryEntrypbk;
893 GSM_Error error; 898 GSM_Error error;
894 int Location; 899 int Location;
895 900
896 s->Phone.Data.Bitmap=Bitmap; 901 s->Phone.Data.Bitmap=Bitmap;
897 switch (Bitmap->Type) { 902 switch (Bitmap->Type) {
898 case GSM_StartupLogo: 903 case GSM_StartupLogo:
899 Bitmap->BitmapWidth = 96; 904 Bitmap->BitmapWidth = 96;
900 Bitmap->BitmapHeight = 65; 905 Bitmap->BitmapHeight = 65;
901 GSM_ClearBitmap(Bitmap); 906 GSM_ClearBitmap(Bitmap);
902 smprintf(s, "Getting startup logo\n"); 907 smprintf(s, "Getting startup logo\n");
903 return GSM_WaitFor (s, reqStartup, 5, 0x7A, 4, ID_GetBitmap); 908 return GSM_WaitFor (s, reqStartup, 5, 0x7A, 4, ID_GetBitmap);
904 case GSM_DealerNote_Text: 909 case GSM_DealerNote_Text:
905 reqNote[4] = 0x10; 910 reqNote[4] = 0x10;
906 smprintf(s, "Getting dealer note\n"); 911 smprintf(s, "Getting dealer note\n");
907 return GSM_WaitFor (s, reqNote, 6, 0x7A, 4, ID_GetBitmap); 912 return GSM_WaitFor (s, reqNote, 6, 0x7A, 4, ID_GetBitmap);
908 case GSM_WelcomeNote_Text: 913 case GSM_WelcomeNote_Text:
909 smprintf(s, "Getting welcome note\n"); 914 smprintf(s, "Getting welcome note\n");
910 return GSM_WaitFor (s, reqNote, 6, 0x7A, 4, ID_GetBitmap); 915 return GSM_WaitFor (s, reqNote, 6, 0x7A, 4, ID_GetBitmap);
911 case GSM_CallerGroupLogo: 916 case GSM_CallerGroupLogo:
912 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PBK35)) return ERR_NOTSUPPORTED; 917 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PBK35)) return ERR_NOTSUPPORTED;
913 Bitmap->BitmapWidth = 72; 918 Bitmap->BitmapWidth = 72;
914 Bitmap->BitmapHeight = 14; 919 Bitmap->BitmapHeight = 14;
915 GSM_ClearBitmap(Bitmap); 920 GSM_ClearBitmap(Bitmap);
916 pbk.MemoryType= MEM7110_CG; 921 pbk.MemoryType= MEM7110_CG;
917 pbk.Location= Bitmap->Location; 922 pbk.Location= Bitmap->Location;
918 smprintf(s, "Getting caller group logo\n"); 923 smprintf(s, "Getting caller group logo\n");
919 error=N6510_GetMemory(s,&pbk); 924 error=N6510_GetMemory(s,&pbk);
920 if (error==ERR_NONE) NOKIA_GetDefaultCallerGroupName(s, Bitmap); 925 if (error==ERR_NONE) NOKIA_GetDefaultCallerGroupName(s, Bitmap);
921 return error; 926 return error;
922 case GSM_OperatorLogo: 927 case GSM_OperatorLogo:
923 smprintf(s, "Getting operator logo\n"); 928 smprintf(s, "Getting operator logo\n");
924 return GSM_WaitFor (s, reqOp, 9, 0x0A, 4, ID_GetBitmap); 929 return GSM_WaitFor (s, reqOp, 9, 0x0A, 4, ID_GetBitmap);
925 case GSM_PictureImage: 930 case GSM_PictureImage:
926 return N6510_GetPictureImage(s, Bitmap, &Location); 931 return N6510_GetPictureImage(s, Bitmap, &Location);
927 default: 932 default:
928 break; 933 break;
929 } 934 }
930 return ERR_NOTSUPPORTED; 935 return ERR_NOTSUPPORTED;
931} 936}
932 937
933static GSM_Error N6510_ReplyGetIncSignalQuality(GSM_Protocol_Message msg, GSM_StateMachine *s) 938static GSM_Error N6510_ReplyGetIncSignalQuality(GSM_Protocol_Message msg, GSM_StateMachine *s)
934{ 939{
935 smprintf(s, "Network level changed to: %i\n",msg.Buffer[4]); 940 smprintf(s, "Network level changed to: %i\n",msg.Buffer[4]);
936 return ERR_NONE; 941 return ERR_NONE;
937} 942}
938 943
939static GSM_Error N6510_ReplyGetSignalQuality(GSM_Protocol_Message msg, GSM_StateMachine *s) 944static GSM_Error N6510_ReplyGetSignalQuality(GSM_Protocol_Message msg, GSM_StateMachine *s)
940{ 945{
941 GSM_Phone_Data *Data = &s->Phone.Data; 946 GSM_Phone_Data *Data = &s->Phone.Data;
942 947
943 smprintf(s, "Network level received: %i\n",msg.Buffer[8]); 948 smprintf(s, "Network level received: %i\n",msg.Buffer[8]);
944 Data->SignalQuality->SignalStrength = -1; 949 Data->SignalQuality->SignalStrength = -1;
945 Data->SignalQuality->SignalPercent = ((int)msg.Buffer[8]); 950 Data->SignalQuality->SignalPercent = ((int)msg.Buffer[8]);
946 Data->SignalQuality->BitErrorRate = -1; 951 Data->SignalQuality->BitErrorRate = -1;
947 return ERR_NONE; 952 return ERR_NONE;
948} 953}
949 954
950static GSM_Error N6510_GetSignalQuality(GSM_StateMachine *s, GSM_SignalQuality *sig) 955static GSM_Error N6510_GetSignalQuality(GSM_StateMachine *s, GSM_SignalQuality *sig)
951{ 956{
952 unsigned char req[] = {N6110_FRAME_HEADER, 0x0B, 0x00, 0x02, 0x00, 0x00, 0x00}; 957 unsigned char req[] = {N6110_FRAME_HEADER, 0x0B, 0x00, 0x02, 0x00, 0x00, 0x00};
953 958
954 s->Phone.Data.SignalQuality = sig; 959 s->Phone.Data.SignalQuality = sig;
955 smprintf(s, "Getting network level\n"); 960 smprintf(s, "Getting network level\n");
956 return GSM_WaitFor (s, req, 9, 0x0a, 4, ID_GetSignalQuality); 961 return GSM_WaitFor (s, req, 9, 0x0a, 4, ID_GetSignalQuality);
957} 962}
958 963
959static GSM_Error N6510_ReplyGetBatteryCharge(GSM_Protocol_Message msg, GSM_StateMachine *s) 964static GSM_Error N6510_ReplyGetBatteryCharge(GSM_Protocol_Message msg, GSM_StateMachine *s)
960{ 965{
961 GSM_Phone_Data *Data = &s->Phone.Data; 966 GSM_Phone_Data *Data = &s->Phone.Data;
962 967
963 smprintf(s, "Battery level received: %i\n",msg.Buffer[9]*100/7); 968 smprintf(s, "Battery level received: %i\n",msg.Buffer[9]*100/7);
964 Data->BatteryCharge->BatteryPercent = ((int)(msg.Buffer[9]*100/7)); 969 Data->BatteryCharge->BatteryPercent = ((int)(msg.Buffer[9]*100/7));
965 Data->BatteryCharge->ChargeState = 0; 970 Data->BatteryCharge->ChargeState = 0;
966 return ERR_NONE; 971 return ERR_NONE;
967} 972}
968 973
969static GSM_Error N6510_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat) 974static GSM_Error N6510_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat)
970{ 975{
971 unsigned char req[] = {N6110_FRAME_HEADER, 0x0A, 0x02, 0x00}; 976 unsigned char req[] = {N6110_FRAME_HEADER, 0x0A, 0x02, 0x00};
972 977
973 s->Phone.Data.BatteryCharge = bat; 978 s->Phone.Data.BatteryCharge = bat;
974 smprintf(s, "Getting battery level\n"); 979 smprintf(s, "Getting battery level\n");
975 return GSM_WaitFor (s, req, 6, 0x17, 4, ID_GetBatteryCharge); 980 return GSM_WaitFor (s, req, 6, 0x17, 4, ID_GetBatteryCharge);
976} 981}
977 982
978static GSM_Error N6510_ReplyGetWAPBookmark(GSM_Protocol_Message msg, GSM_StateMachine *s) 983static GSM_Error N6510_ReplyGetWAPBookmark(GSM_Protocol_Message msg, GSM_StateMachine *s)
979{ 984{
980 return DCT3DCT4_ReplyGetWAPBookmark (msg, s, true); 985 return DCT3DCT4_ReplyGetWAPBookmark (msg, s, true);
981} 986}
982 987
983static GSM_Error N6510_ReplyGetOperatorLogo(GSM_Protocol_Message msg, GSM_StateMachine *s) 988static GSM_Error N6510_ReplyGetOperatorLogo(GSM_Protocol_Message msg, GSM_StateMachine *s)
984{ 989{
985 GSM_Phone_Data *Data = &s->Phone.Data; 990 GSM_Phone_Data *Data = &s->Phone.Data;
986 991
987 smprintf(s, "Operator logo received\n"); 992 smprintf(s, "Operator logo received\n");
993 if (msg.Length == 18) return ERR_EMPTY;
988 NOKIA_DecodeNetworkCode(msg.Buffer+12,Data->Bitmap->NetworkCode); 994 NOKIA_DecodeNetworkCode(msg.Buffer+12,Data->Bitmap->NetworkCode);
989 smprintf(s, "Network code %s\n",Data->Bitmap->NetworkCode); 995 smprintf(s, "Network code %s\n",Data->Bitmap->NetworkCode);
990 Data->Bitmap->BitmapWidth= msg.Buffer[20]; 996 Data->Bitmap->BitmapWidth= msg.Buffer[20];
991 Data->Bitmap->BitmapHeight= msg.Buffer[21]; 997 Data->Bitmap->BitmapHeight= msg.Buffer[21];
992 if (msg.Length == 18) return ERR_EMPTY;
993 PHONE_DecodeBitmap(GSM_Nokia6510OperatorLogo,msg.Buffer+26,Data->Bitmap); 998 PHONE_DecodeBitmap(GSM_Nokia6510OperatorLogo,msg.Buffer+26,Data->Bitmap);
994 return ERR_NONE; 999 return ERR_NONE;
995} 1000}
996 1001
997GSM_Error N6510_ReplyDeleteMemory(GSM_Protocol_Message msg, GSM_StateMachine *s) 1002GSM_Error N6510_ReplyDeleteMemory(GSM_Protocol_Message msg, GSM_StateMachine *s)
998{ 1003{
999 smprintf(s, "Phonebook entry deleted\n"); 1004 smprintf(s, "Phonebook entry deleted\n");
1000 return ERR_NONE; 1005 return ERR_NONE;
1001} 1006}
1002 1007
1003GSM_Error N6510_DeleteMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry) 1008GSM_Error N6510_DeleteMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
1004{ 1009{
1005 unsigned char req[] = {N7110_FRAME_HEADER, 0x0f, 0x55, 0x01, 1010 unsigned char req[] = {N7110_FRAME_HEADER, 0x0f, 0x55, 0x01,
1006 0x04, 0x55, 0x00, 0x10, 0xFF, 0x02, 1011 0x04, 0x55, 0x00, 0x10, 0xFF, 0x02,
1007 0x00, 0x01, /* location*/ 1012 0x00, 0x01, /* location*/
1008 0x00, 0x00, 0x00, 0x00, 1013 0x00, 0x00, 0x00, 0x00,
1009 0x05, /* memory type*/ 1014 0x05, /* memory type*/
1010 0x55, 0x55, 0x55}; 1015 0x55, 0x55, 0x55};
1011 1016
1012 req[12] = entry->Location / 256; 1017 req[12] = entry->Location / 256;
1013 req[13] = entry->Location % 256; 1018 req[13] = entry->Location % 256;
1014 1019
1015 req[18] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES); 1020 req[18] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES);
1016 if (req[18]==0xff) return ERR_NOTSUPPORTED; 1021 if (req[18]==0xff) return ERR_NOTSUPPORTED;
1017 1022
1018 smprintf(s, "Deleting phonebook entry\n"); 1023 smprintf(s, "Deleting phonebook entry\n");
1019 return GSM_WaitFor (s, req, 22, 0x03, 4, ID_SetMemory); 1024 return GSM_WaitFor (s, req, 22, 0x03, 4, ID_SetMemory);
1020} 1025}
1021 1026
1022static GSM_Error N6510_SetMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry) 1027static GSM_Error N6510_SetMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
1023{ 1028{
1024 int count = 22, blocks; 1029 int count = 22, blocks;
1025 unsigned char req[500] = { 1030 unsigned char req[500] = {
1026 N7110_FRAME_HEADER, 0x0b, 0x00, 0x01, 0x01, 0x00, 0x00, 0x10, 1031 N7110_FRAME_HEADER, 0x0b, 0x00, 0x01, 0x01, 0x00, 0x00, 0x10,
1027 0x02, 0x00, /* memory type */ 1032 0x02, 0x00, /* memory type */
1028 0x00, 0x00, /* location */ 1033 0x00, 0x00, /* location */
1029 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 1034 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1030 1035
1031 if (entry->Location == 0) return ERR_NOTSUPPORTED; 1036 if (entry->Location == 0) return ERR_NOTSUPPORTED;
1032 1037
1033 req[11] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES); 1038 req[11] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES);
1034 if (req[11]==0xff) return ERR_NOTSUPPORTED; 1039 if (req[11]==0xff) return ERR_NOTSUPPORTED;
1035 1040
1036 req[12] = entry->Location / 256; 1041 req[12] = entry->Location / 256;
1037 req[13] = entry->Location % 256; 1042 req[13] = entry->Location % 256;
1038 1043
1039 count = count + N71_65_EncodePhonebookFrame(s, req+22, *entry, &blocks, true, IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_VOICETAGS)); 1044 count = count + N71_65_EncodePhonebookFrame(s, req+22, *entry, &blocks, true, IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_VOICETAGS));
1040 req[21] = blocks; 1045 req[21] = blocks;
1041 1046
1042 smprintf(s, "Writing phonebook entry\n"); 1047 smprintf(s, "Writing phonebook entry\n");
1043 return GSM_WaitFor (s, req, count, 0x03, 4, ID_SetMemory); 1048 return GSM_WaitFor (s, req, count, 0x03, 4, ID_SetMemory);
1044} 1049}
1045 1050
1046static GSM_Error N6510_ReplySetOperatorLogo(GSM_Protocol_Message msg, GSM_StateMachine *s) 1051static GSM_Error N6510_ReplySetOperatorLogo(GSM_Protocol_Message msg, GSM_StateMachine *s)
1047{ 1052{
1048 smprintf(s, "Operator logo set OK\n"); 1053 smprintf(s, "Operator logo set OK\n");
1049 return ERR_NONE; 1054 return ERR_NONE;
1050} 1055}
1051 1056
1052static GSM_Error N6510_SetCallerLogo(GSM_StateMachine *s, GSM_Bitmap *bitmap) 1057static GSM_Error N6510_SetCallerLogo(GSM_StateMachine *s, GSM_Bitmap *bitmap)
1053{ 1058{
1054 char string[500]; 1059 char string[500];
1055 int block=0, i, Width, Height; 1060 int block=0, i, Width, Height;
1056 unsigned int count = 22; 1061 unsigned int count = 22;
1057 unsigned char req[500] = { 1062 unsigned char req[500] = {
1058 N6110_FRAME_HEADER, 0x0b, 0x00, 0x01, 0x01, 0x00, 0x00, 0x10, 1063 N6110_FRAME_HEADER, 0x0b, 0x00, 0x01, 0x01, 0x00, 0x00, 0x10,
1059 0xfe, 0x10, /* memory type */ 1064 0xfe, 0x10, /* memory type */
1060 0x00, 0x00, /* location */ 1065 0x00, 0x00, /* location */
1061 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 1066 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1062 1067
1063 req[13] = bitmap->Location; 1068 req[13] = bitmap->Location;
1064 1069
1065 /* Enabling/disabling logo */ 1070 /* Enabling/disabling logo */
1066 string[0] = bitmap->BitmapEnabled?1:0; 1071 string[0] = bitmap->BitmapEnabled?1:0;
1067 string[1] = 0; 1072 string[1] = 0;
1068 count += N71_65_PackPBKBlock(s, N7110_PBK_LOGOON, 2, block++, string, req + count); 1073 count += N71_65_PackPBKBlock(s, N7110_PBK_LOGOON, 2, block++, string, req + count);
1069 1074
1070 /* Ringtone */ 1075 /* Ringtone */
1071 if (!bitmap->DefaultRingtone) { 1076 if (!bitmap->DefaultRingtone) {
1072 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PBKTONEGAL)) { 1077 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PBKTONEGAL)) {
1073 } else { 1078 } else {
1074 string[0] = 0x00; 1079 string[0] = 0x00;
1075 string[1] = 0x00; 1080 string[1] = 0x00;
1076 string[2] = bitmap->RingtoneID; 1081 string[2] = bitmap->RingtoneID;
1077 count += N71_65_PackPBKBlock(s, N7110_PBK_RINGTONE_ID, 3, block++, string, req + count); 1082 count += N71_65_PackPBKBlock(s, N7110_PBK_RINGTONE_ID, 3, block++, string, req + count);
1078 count --; 1083 count --;
1079 req[count-5] = 8; 1084 req[count-5] = 8;
1080 } 1085 }
1081 } 1086 }
1082 1087
1083 /* Number of group */ 1088 /* Number of group */
1084 string[0] = bitmap->Location; 1089 string[0] = bitmap->Location;
1085 string[1] = 0; 1090 string[1] = 0;
1086 count += N71_65_PackPBKBlock(s, N7110_PBK_GROUP, 2, block++, string, req + count); 1091 count += N71_65_PackPBKBlock(s, N7110_PBK_GROUP, 2, block++, string, req + count);
1087 1092
1088 /* Name */ 1093 /* Name */
1089 if (!bitmap->DefaultName) { 1094 if (!bitmap->DefaultName) {
1090 i = UnicodeLength(bitmap->Text) * 2; 1095 i = UnicodeLength(bitmap->Text) * 2;
1091 string[0] = i + 2; 1096 string[0] = i + 2;
1092 memcpy(string + 1, bitmap->Text, i); 1097 memcpy(string + 1, bitmap->Text, i);
1093 string[i + 1] = 0; 1098 string[i + 1] = 0;
1094 count += N71_65_PackPBKBlock(s, N7110_PBK_NAME, i + 2, block++, string, req + count); 1099 count += N71_65_PackPBKBlock(s, N7110_PBK_NAME, i + 2, block++, string, req + count);
1095 } 1100 }
1096 1101
1097 /* Logo */ 1102 /* Logo */
1098 if (!bitmap->DefaultBitmap) { 1103 if (!bitmap->DefaultBitmap) {
1099 PHONE_GetBitmapWidthHeight(GSM_NokiaCallerLogo, &Width, &Height); 1104 PHONE_GetBitmapWidthHeight(GSM_NokiaCallerLogo, &Width, &Height);
1100 string[0] = Width; 1105 string[0] = Width;
1101 string[1] = Height; 1106 string[1] = Height;
1102 string[2] = 0; 1107 string[2] = 0;
1103 string[3] = 0; 1108 string[3] = 0;
1104 string[4] = PHONE_GetBitmapSize(GSM_NokiaCallerLogo,0,0); 1109 string[4] = PHONE_GetBitmapSize(GSM_NokiaCallerLogo,0,0);
1105 PHONE_EncodeBitmap(GSM_NokiaCallerLogo, string + 5, bitmap); 1110 PHONE_EncodeBitmap(GSM_NokiaCallerLogo, string + 5, bitmap);
1106 count += N71_65_PackPBKBlock(s, N7110_PBK_GROUPLOGO, PHONE_GetBitmapSize(GSM_NokiaCallerLogo,0,0) + 5, block++, string, req + count); 1111 count += N71_65_PackPBKBlock(s, N7110_PBK_GROUPLOGO, PHONE_GetBitmapSize(GSM_NokiaCallerLogo,0,0) + 5, block++, string, req + count);
1107 } 1112 }
1108 1113
1109 req[21] = block; 1114 req[21] = block;
1110 1115
1111 return GSM_WaitFor (s, req, count, 0x03, 4, ID_SetBitmap); 1116 return GSM_WaitFor (s, req, count, 0x03, 4, ID_SetBitmap);
1112} 1117}
1113 1118
1114static GSM_Error N6510_ReplySetPicture(GSM_Protocol_Message msg, GSM_StateMachine *s) 1119static GSM_Error N6510_ReplySetPicture(GSM_Protocol_Message msg, GSM_StateMachine *s)
1115{ 1120{
1116 //smprintf(s, "Picture Image written OK, folder %i, location %i\n",msg.Buffer[4],msg.Buffer[5]*256+msg.Buffer[6]); 1121 //smprintf(s, "Picture Image written OK, folder %i, location %i\n",msg.Buffer[4],msg.Buffer[5]*256+msg.Buffer[6]);
1117 return ERR_NONE; 1122 return ERR_NONE;
1118} 1123}
1119 1124
1120static GSM_Error N6510_SetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap) 1125static GSM_Error N6510_SetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
1121{ 1126{
1122 GSM_SMSMessage sms; 1127 GSM_SMSMessage sms;
1123 GSM_Phone_Bitmap_TypesType; 1128 GSM_Phone_Bitmap_TypesType;
1124 int Width, Height, i, count; 1129 int Width, Height, i, count;
1125#ifdef DEVELOP 1130#ifdef DEVELOP
1126 unsigned char folderid; 1131 unsigned char folderid;
1127 int location; 1132 int location;
1128#endif 1133#endif
1129 GSM_NetworkInfo NetInfo; 1134 GSM_NetworkInfo NetInfo;
1130 GSM_Error error; 1135 GSM_Error error;
1131 unsigned char reqStartup[1000] = { 1136 unsigned char reqStartup[1000] = {
1132 N7110_FRAME_HEADER, 0x04, 0x0F, 1137 N7110_FRAME_HEADER, 0x04, 0x0F,
1133 0x00, 0x00, 0x00, 1138 0x00, 0x00, 0x00,
1134 0x04, 0xC0, 0x02, 0x00, 1139 0x04, 0xC0, 0x02, 0x00,
1135 0x41, 0xC0, 0x03, 0x00, 1140 0x41, 0xC0, 0x03, 0x00,
1136 0x60, 0xC0, 0x04}; 1141 0x60, 0xC0, 0x04};
1137 unsigned char reqColourWallPaper[200] = { 1142 unsigned char reqColourWallPaper[200] = {
1138 N6110_FRAME_HEADER, 0x07, 0x00, 0x00, 0x00, 0xD5, 1143 N6110_FRAME_HEADER, 0x07, 0x00, 0x00, 0x00, 0xD5,
1139 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 1144 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
1140 0x00, 0x00, 0x00, 0x01, 0x00, 1145 0x00, 0x00, 0x00, 0x01, 0x00,
1141 0x18}; /* Bitmap ID */ 1146 0x18}; /* Bitmap ID */
1142 unsigned char reqColourStartup[200] = { 1147 unsigned char reqColourStartup[200] = {
1143 N6110_FRAME_HEADER, 0x04, 0x25, 0x00, 0x01, 0x00, 0x18}; 1148 N6110_FRAME_HEADER, 0x04, 0x25, 0x00, 0x01, 0x00, 0x18};
1144 unsigned char reqOp[1000] = { 1149 unsigned char reqOp[1000] = {
1145 N7110_FRAME_HEADER, 0x25, 0x01, 1150 N7110_FRAME_HEADER, 0x25, 0x01,
1146 0x55, 0x00, 0x00, 0x55, 1151 0x55, 0x00, 0x00, 0x55,
1147 0x01, /* 0x01 - not set, 0x02 - set */ 1152 0x01, /* 0x01 - not set, 0x02 - set */
1148 0x0C, 0x08, 1153 0x0C, 0x08,
1149 0x62, 0xF0, 0x10,/* Network code */ 1154 0x62, 0xF0, 0x10,/* Network code */
1150 0x03, 0x55, 0x55}; 1155 0x03, 0x55, 0x55};
1151 unsigned char reqColourOp[200] = { 1156 unsigned char reqColourOp[200] = {
1152 N6110_FRAME_HEADER, 1157 N6110_FRAME_HEADER,
1153 0x07, 0x00, 0x00, 0x00, 0xE7, 0x00, 0x00, 0x00, 0xF9, 0x00, 1158 0x07, 0x00, 0x00, 0x00, 0xE7, 0x00, 0x00, 0x00, 0xF9, 0x00,
1154 0x08, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 1159 0x08, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00,
1155 0x18, /* File ID */ 1160 0x18, /* File ID */
1156 0x00, 1161 0x00,
1157 0x00, 0x00, 0x00};/* Network code */ 1162 0x00, 0x00, 0x00};/* Network code */
1158 unsigned char reqNote[200] = {N6110_FRAME_HEADER, 0x04, 0x01}; 1163 unsigned char reqNote[200] = {N6110_FRAME_HEADER, 0x04, 0x01};
1159 unsigned char reqPicture[2000] = { 1164 unsigned char reqPicture[2000] = {
1160 N6110_FRAME_HEADER, 0x00, 1165 N6110_FRAME_HEADER, 0x00,
1161 0x02, 0x05, /* SMS folder */ 1166 0x02, 0x05, /* SMS folder */
1162 0x00, 0x00, /* location */ 1167 0x00, 0x00, /* location */
1163 0x01, 0x01, 0xa0, 0x02, 0x01, 0x40, 0x00, 0x34, 1168 0x01, 0x01, 0xa0, 0x02, 0x01, 0x40, 0x00, 0x34,
1164 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 1169 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1165 0x00, 0x00, 0x55, 0x55, 0x55, 0x03, 0x82, 0x10, 1170 0x00, 0x00, 0x55, 0x55, 0x55, 0x03, 0x82, 0x10,
1166 0x01, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 1171 0x01, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1167 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x10, 1172 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x10,
1168 0x02, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 1173 0x02, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1169 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x04, 1174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x04,
1170 0x00, 0x00, 0xa1, 0x55, 0x01, 0x08, 0x00, 0x00, 1175 0x00, 0x00, 0xa1, 0x55, 0x01, 0x08, 0x00, 0x00,
1171 0x00, 0x01, 0x48, 0x1c, 0x00, 0xfc, 0x00}; 1176 0x00, 0x01, 0x48, 0x1c, 0x00, 0xfc, 0x00};
1172 1177
1173 switch (Bitmap->Type) { 1178 switch (Bitmap->Type) {
1174 case GSM_ColourWallPaper_ID: 1179 case GSM_ColourWallPaper_ID:
1175 reqColourWallPaper[21] = Bitmap->ID; 1180 reqColourWallPaper[21] = Bitmap->ID;
1176 smprintf(s, "Setting colour wall paper\n"); 1181 smprintf(s, "Setting colour wall paper\n");
1177 return GSM_WaitFor (s, reqColourWallPaper, 22, 0x43, 4, ID_SetBitmap); 1182 return GSM_WaitFor (s, reqColourWallPaper, 22, 0x43, 4, ID_SetBitmap);
1178 case GSM_StartupLogo: 1183 case GSM_StartupLogo:
1179 Type = GSM_Nokia7110StartupLogo; 1184 Type = GSM_Nokia7110StartupLogo;
1180 switch (Bitmap->Location) { 1185 switch (Bitmap->Location) {
1181 case 1: PHONE_EncodeBitmap(Type, reqStartup + 22, Bitmap); 1186 case 1: PHONE_EncodeBitmap(Type, reqStartup + 22, Bitmap);
1182 break; 1187 break;
1183 case 2: memset(reqStartup+5,0x00,15); 1188 case 2: memset(reqStartup+5,0x00,15);
1184 PHONE_ClearBitmap(Type, reqStartup + 22,0,0); 1189 PHONE_ClearBitmap(Type, reqStartup + 22,0,0);
@@ -1576,385 +1581,386 @@ static GSM_Error N6510_ReplyGetConnectionSettings(GSM_Protocol_Message msg, GSM_
1576 switch (msg.Buffer[tmp+2]) { 1581 switch (msg.Buffer[tmp+2]) {
1577 case 0x00: smprintf(s, "manual\n");break; 1582 case 0x00: smprintf(s, "manual\n");break;
1578 case 0x01: smprintf(s, "automatic\n");break; 1583 case 0x01: smprintf(s, "automatic\n");break;
1579 default: smprintf(s, "unknown\n");break; 1584 default: smprintf(s, "unknown\n");break;
1580 } 1585 }
1581#endif 1586#endif
1582 Data->WAPSettings->Settings[num].IsNormalAuthentication=true; 1587 Data->WAPSettings->Settings[num].IsNormalAuthentication=true;
1583 if (msg.Buffer[tmp]==0x01) Data->WAPSettings->Settings[num].IsNormalAuthentication=false; 1588 if (msg.Buffer[tmp]==0x01) Data->WAPSettings->Settings[num].IsNormalAuthentication=false;
1584 1589
1585 Data->WAPSettings->Settings[num].IsContinuous = true; 1590 Data->WAPSettings->Settings[num].IsContinuous = true;
1586 if (msg.Buffer[tmp+1] == 0x01) Data->WAPSettings->Settings[num].IsContinuous = false; 1591 if (msg.Buffer[tmp+1] == 0x01) Data->WAPSettings->Settings[num].IsContinuous = false;
1587 1592
1588 Data->WAPSettings->Settings[num].ManualLogin=false; 1593 Data->WAPSettings->Settings[num].ManualLogin=false;
1589 if (msg.Buffer[tmp+2]==0x00) Data->WAPSettings->Settings[num].ManualLogin = true; 1594 if (msg.Buffer[tmp+2]==0x00) Data->WAPSettings->Settings[num].ManualLogin = true;
1590 1595
1591 tmp+=3; 1596 tmp+=3;
1592 1597
1593 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[num].DialUp,false); 1598 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[num].DialUp,false);
1594 smprintf(s, "Access point: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[num].DialUp)); 1599 smprintf(s, "Access point: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[num].DialUp));
1595 1600
1596 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[num].IPAddress,true); 1601 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[num].IPAddress,true);
1597 smprintf(s, "IP address: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[num].IPAddress)); 1602 smprintf(s, "IP address: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[num].IPAddress));
1598 1603
1599 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[num].User,true); 1604 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[num].User,true);
1600 smprintf(s, "User name: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[num].User)); 1605 smprintf(s, "User name: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[num].User));
1601 1606
1602 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[num].Password,true); 1607 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer, Data->WAPSettings->Settings[num].Password,true);
1603 smprintf(s, "Password: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[num].Password)); 1608 smprintf(s, "Password: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[num].Password));
1604 1609
1605 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_WAPMMSPROXY)) { 1610 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_WAPMMSPROXY)) {
1606 if (msg.Buffer[tmp] == 0x00 && msg.Buffer[tmp+1] == 0x00) tmp = tmp+2; 1611 if (msg.Buffer[tmp] == 0x00 && msg.Buffer[tmp+1] == 0x00) tmp = tmp+2;
1607 1612
1608 memcpy(buff,msg.Buffer+tmp+10,msg.Buffer[tmp+4]); 1613 memcpy(buff,msg.Buffer+tmp+10,msg.Buffer[tmp+4]);
1609 buff[msg.Buffer[tmp+4]] = 0x00; 1614 buff[msg.Buffer[tmp+4]] = 0x00;
1610 smprintf(s, "Proxy 1: \"%s\", port %i\n",buff,msg.Buffer[tmp+6]*256+msg.Buffer[tmp+7]); 1615 smprintf(s, "Proxy 1: \"%s\", port %i\n",buff,msg.Buffer[tmp+6]*256+msg.Buffer[tmp+7]);
1611 EncodeUnicode(Data->WAPSettings->Proxy,buff,strlen(buff)); 1616 EncodeUnicode(Data->WAPSettings->Proxy,buff,strlen(buff));
1612 Data->WAPSettings->ProxyPort = msg.Buffer[tmp+6]*256+msg.Buffer[tmp+7]; 1617 Data->WAPSettings->ProxyPort = msg.Buffer[tmp+6]*256+msg.Buffer[tmp+7];
1613 1618
1614 memcpy(buff,msg.Buffer+tmp+10+msg.Buffer[tmp+4],msg.Buffer[tmp+5]); 1619 memcpy(buff,msg.Buffer+tmp+10+msg.Buffer[tmp+4],msg.Buffer[tmp+5]);
1615 buff[msg.Buffer[tmp+5]] = 0x00; 1620 buff[msg.Buffer[tmp+5]] = 0x00;
1616 smprintf(s, "Proxy 2: \"%s\", port %i\n",buff,msg.Buffer[tmp+8]*256+msg.Buffer[tmp+9]); 1621 smprintf(s, "Proxy 2: \"%s\", port %i\n",buff,msg.Buffer[tmp+8]*256+msg.Buffer[tmp+9]);
1617 EncodeUnicode(Data->WAPSettings->Proxy2,buff,strlen(buff)); 1622 EncodeUnicode(Data->WAPSettings->Proxy2,buff,strlen(buff));
1618 Data->WAPSettings->Proxy2Port = msg.Buffer[tmp+8]*256+msg.Buffer[tmp+9]; 1623 Data->WAPSettings->Proxy2Port = msg.Buffer[tmp+8]*256+msg.Buffer[tmp+9];
1619 1624
1620 tmp = tmp + msg.Buffer[tmp+3] + 19; 1625 tmp = tmp + msg.Buffer[tmp+3] + 19;
1621 1626
1622 for (i=0;i<4;i++) { 1627 for (i=0;i<4;i++) {
1623#ifdef DEBUG 1628#ifdef DEBUG
1624 smprintf(s, "Proxy data %i\n",i+1); 1629 smprintf(s, "Proxy data %i\n",i+1);
1625 if (msg.Buffer[tmp+2]!=0) memcpy(buff,msg.Buffer+tmp+9,msg.Buffer[tmp+2]*2); 1630 if (msg.Buffer[tmp+2]!=0) memcpy(buff,msg.Buffer+tmp+9,msg.Buffer[tmp+2]*2);
1626 buff[msg.Buffer[tmp+2]*2] =0; 1631 buff[msg.Buffer[tmp+2]*2] =0;
1627 buff[msg.Buffer[tmp+2]*2+1]=0; 1632 buff[msg.Buffer[tmp+2]*2+1]=0;
1628 smprintf(s, "IP: \"%s\"",DecodeUnicodeString(buff)); 1633 smprintf(s, "IP: \"%s\"",DecodeUnicodeString(buff));
1629 smprintf(s, ", port %i\n",msg.Buffer[tmp+3]*256+msg.Buffer[tmp+4]); 1634 smprintf(s, ", port %i\n",msg.Buffer[tmp+3]*256+msg.Buffer[tmp+4]);
1630#endif 1635#endif
1631 tmp = tmp + msg.Buffer[tmp]; 1636 tmp = tmp + msg.Buffer[tmp];
1632 } 1637 }
1633 1638
1634#ifdef DEBUG 1639#ifdef DEBUG
1635 smprintf(s, "%02x %02x\n",msg.Buffer[tmp],msg.Buffer[tmp+1]); 1640 smprintf(s, "%02x %02x\n",msg.Buffer[tmp],msg.Buffer[tmp+1]);
1636 smprintf(s, "Port %i\n",msg.Buffer[tmp+3]*256+msg.Buffer[tmp+4]); 1641 smprintf(s, "Port %i\n",msg.Buffer[tmp+3]*256+msg.Buffer[tmp+4]);
1637 tmp = tmp + msg.Buffer[tmp]; 1642 tmp = tmp + msg.Buffer[tmp];
1638#endif 1643#endif
1639 } 1644 }
1640 1645
1641 return ERR_NONE; 1646 return ERR_NONE;
1642 case 0x17: 1647 case 0x17:
1643 smprintf(s, "Connection settings receiving error\n"); 1648 smprintf(s, "Connection settings receiving error\n");
1644 switch (msg.Buffer[4]) { 1649 switch (msg.Buffer[4]) {
1645 case 0x01: 1650 case 0x01:
1646 smprintf(s, "Security error. Inside phone settings menu\n"); 1651 smprintf(s, "Security error. Inside phone settings menu\n");
1647 return ERR_INSIDEPHONEMENU; 1652 return ERR_INSIDEPHONEMENU;
1648 case 0x02: 1653 case 0x02:
1649 smprintf(s, "Invalid or empty\n"); 1654 smprintf(s, "Invalid or empty\n");
1650 return ERR_INVALIDLOCATION; 1655 return ERR_INVALIDLOCATION;
1651 default: 1656 default:
1652 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]); 1657 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]);
1653 return ERR_UNKNOWNRESPONSE; 1658 return ERR_UNKNOWNRESPONSE;
1654 } 1659 }
1655 break; 1660 break;
1656 } 1661 }
1657 return ERR_UNKNOWNRESPONSE; 1662 return ERR_UNKNOWNRESPONSE;
1658} 1663}
1659 1664
1660static GSM_Error N6510_GetConnectionSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings, N6510_Connection_Settings Type) 1665static GSM_Error N6510_GetConnectionSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings, N6510_Connection_Settings Type)
1661{ 1666{
1662 GSM_Phone_N6510Data*Priv = &s->Phone.Data.Priv.N6510; 1667 GSM_Phone_N6510Data*Priv = &s->Phone.Data.Priv.N6510;
1663 GSM_Error error; 1668 GSM_Error error;
1664 unsigned char req[] = {N6110_FRAME_HEADER, 0x15, 1669 unsigned char req[] = {N6110_FRAME_HEADER, 0x15,
1665 0x00}; /* Location */ 1670 0x00}; /* Location */
1666 1671
1667 error = N6510_EnableConnectionFunctions(s, Type); 1672 error = N6510_EnableConnectionFunctions(s, Type);
1668 if (error!=ERR_NONE) return error; 1673 if (error!=ERR_NONE) return error;
1669 1674
1670 req[4] = settings->Location-1; 1675 req[4] = settings->Location-1;
1671 s->Phone.Data.WAPSettings = settings; 1676 s->Phone.Data.WAPSettings = settings;
1672 1677
1673 switch (Type) { 1678 switch (Type) {
1674 case N6510_MMS_SETTINGS: 1679 case N6510_MMS_SETTINGS:
1675 smprintf(s, "Getting MMS settings\n"); 1680 smprintf(s, "Getting MMS settings\n");
1676 Priv->BearerNumber = 1; 1681 Priv->BearerNumber = 1;
1677 break; 1682 break;
1678 case N6510_WAP_SETTINGS: 1683 case N6510_WAP_SETTINGS:
1679 smprintf(s, "Getting WAP settings\n"); 1684 smprintf(s, "Getting WAP settings\n");
1680 Priv->BearerNumber = 2; 1685 Priv->BearerNumber = 2;
1681 break; 1686 break;
1682 case N6510_SYNCML_SETTINGS: 1687 case N6510_SYNCML_SETTINGS:
1683 smprintf(s, "Getting SyncML settings\n"); 1688 smprintf(s, "Getting SyncML settings\n");
1684 Priv->BearerNumber = 2; 1689 Priv->BearerNumber = 2;
1685 break; 1690 break;
1686 case N6510_CHAT_SETTINGS: 1691 case N6510_CHAT_SETTINGS:
1687 smprintf(s, "Getting Chat settings\n"); 1692 smprintf(s, "Getting Chat settings\n");
1688 Priv->BearerNumber = 1; 1693 Priv->BearerNumber = 1;
1689 break; 1694 break;
1690 } 1695 }
1691 1696
1692 error=GSM_WaitFor (s, req, 5, 0x3f, 4, ID_GetConnectSet); 1697 error=GSM_WaitFor (s, req, 5, 0x3f, 4, ID_GetConnectSet);
1693 if (error != ERR_NONE) { 1698 if (error != ERR_NONE) {
1694 if (error == ERR_INVALIDLOCATION || error == ERR_INSIDEPHONEMENU) { 1699 if (error == ERR_INVALIDLOCATION || error == ERR_INSIDEPHONEMENU) {
1695 DCT3DCT4_DisableConnectionFunctions(s); 1700 DCT3DCT4_DisableConnectionFunctions(s);
1696 } 1701 }
1697 return error; 1702 return error;
1698 } 1703 }
1699 1704
1700 error=DCT3DCT4_GetActiveConnectSet(s); 1705 error=DCT3DCT4_GetActiveConnectSet(s);
1701 if (error != ERR_NONE) return error; 1706 if (error != ERR_NONE) return error;
1702 1707
1703 return DCT3DCT4_DisableConnectionFunctions(s); 1708 return DCT3DCT4_DisableConnectionFunctions(s);
1704} 1709}
1705 1710
1706static GSM_Error N6510_GetWAPSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings) 1711static GSM_Error N6510_GetWAPSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings)
1707{ 1712{
1708 return N6510_GetConnectionSettings(s, settings, N6510_WAP_SETTINGS); 1713 return N6510_GetConnectionSettings(s, settings, N6510_WAP_SETTINGS);
1709} 1714}
1710 1715
1711static GSM_Error N6510_GetMMSSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings) 1716static GSM_Error N6510_GetMMSSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings)
1712{ 1717{
1713 return N6510_GetConnectionSettings(s, settings, N6510_MMS_SETTINGS); 1718 return N6510_GetConnectionSettings(s, settings, N6510_MMS_SETTINGS);
1714} 1719}
1715 1720
1716static GSM_Error N6510_ReplyGetSyncMLSettings(GSM_Protocol_Message msg, GSM_StateMachine *s) 1721static GSM_Error N6510_ReplyGetSyncMLSettings(GSM_Protocol_Message msg, GSM_StateMachine *s)
1717{ 1722{
1718 GSM_SyncMLSettings *Sett = s->Phone.Data.SyncMLSettings; 1723 GSM_SyncMLSettings *Sett = s->Phone.Data.SyncMLSettings;
1719 1724
1720 smprintf(s, "SyncML settings received OK\n"); 1725 smprintf(s, "SyncML settings received OK\n");
1721 CopyUnicodeString(Sett->User,msg.Buffer+18); 1726 CopyUnicodeString(Sett->User,msg.Buffer+18);
1722 CopyUnicodeString(Sett->Password,msg.Buffer+86); 1727 CopyUnicodeString(Sett->Password,msg.Buffer+86);
1723 CopyUnicodeString(Sett->PhonebookDataBase,msg.Buffer+130); 1728 CopyUnicodeString(Sett->PhonebookDataBase,msg.Buffer+130);
1724 CopyUnicodeString(Sett->CalendarDataBase,msg.Buffer+234); 1729 CopyUnicodeString(Sett->CalendarDataBase,msg.Buffer+234);
1725 CopyUnicodeString(Sett->Server,msg.Buffer+338); 1730 CopyUnicodeString(Sett->Server,msg.Buffer+338);
1726 1731
1727 Sett->SyncPhonebook = false; 1732 Sett->SyncPhonebook = false;
1728 Sett->SyncCalendar = false; 1733 Sett->SyncCalendar = false;
1729 if ((msg.Buffer[598] & 0x02)==0x02) Sett->SyncCalendar = true; 1734 if ((msg.Buffer[598] & 0x02)==0x02) Sett->SyncCalendar = true;
1730 if ((msg.Buffer[598] & 0x01)==0x01) Sett->SyncPhonebook = true; 1735 if ((msg.Buffer[598] & 0x01)==0x01) Sett->SyncPhonebook = true;
1731 1736
1732 return ERR_NONE; 1737 return ERR_NONE;
1733} 1738}
1734 1739
1735static GSM_Error N6510_ReplyGetSyncMLName(GSM_Protocol_Message msg, GSM_StateMachine *s) 1740static GSM_Error N6510_ReplyGetSyncMLName(GSM_Protocol_Message msg, GSM_StateMachine *s)
1736{ 1741{
1737 GSM_SyncMLSettings *Sett = s->Phone.Data.SyncMLSettings; 1742 GSM_SyncMLSettings *Sett = s->Phone.Data.SyncMLSettings;
1738 1743
1739 smprintf(s, "SyncML names received OK\n"); 1744 smprintf(s, "SyncML names received OK\n");
1740 1745
1741 CopyUnicodeString(Sett->Name,msg.Buffer+18); 1746 CopyUnicodeString(Sett->Name,msg.Buffer+18);
1742 1747
1743 return ERR_NONE; 1748 return ERR_NONE;
1744} 1749}
1745 1750
1746static GSM_Error N6510_GetSyncMLSettings(GSM_StateMachine *s, GSM_SyncMLSettings *settings) 1751static GSM_Error N6510_GetSyncMLSettings(GSM_StateMachine *s, GSM_SyncMLSettings *settings)
1747{ 1752{
1748 GSM_Error error; 1753 GSM_Error error;
1749 // unsigned char NameReq[] = {N6110_FRAME_HEADER, 0x05, 1754 // unsigned char NameReq[] = {N6110_FRAME_HEADER, 0x05,
1750 // 0x00, 0x00, 0x00, 0x31, 0x00, 1755 // 0x00, 0x00, 0x00, 0x31, 0x00,
1751 // 0x06, 0x00, 0x00, 0x00, 0xDE, 0x00, 0x00}; 1756 // 0x06, 0x00, 0x00, 0x00, 0xDE, 0x00, 0x00};
1752 // unsigned char GetActive[] = {N6110_FRAME_HEADER, 0x05, 1757 // unsigned char GetActive[] = {N6110_FRAME_HEADER, 0x05,
1753 // 0x00, 0x00, 0x00, 0x31, 0x00, 1758 // 0x00, 0x00, 0x00, 0x31, 0x00,
1754 // 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}; 1759 // 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00};
1755 unsigned char req[] = {N6110_FRAME_HEADER, 0x05, 1760 unsigned char req[] = {N6110_FRAME_HEADER, 0x05,
1756 0x00, 0x00, 0x00, 0x31, 0x00, 1761 0x00, 0x00, 0x00, 0x31, 0x00,
1757 0x01, //location 1762 0x01, //location
1758 0x00, 0x00, 0x02, 0x46, 0x00, 0x00}; 1763 0x00, 0x00, 0x02, 0x46, 0x00, 0x00};
1759 1764
1760 settings->Connection.Location = settings->Location; 1765 settings->Connection.Location = settings->Location;
1761 error = N6510_GetConnectionSettings(s, &settings->Connection, N6510_SYNCML_SETTINGS); 1766 error = N6510_GetConnectionSettings(s, &settings->Connection, N6510_SYNCML_SETTINGS);
1762 if (error != ERR_NONE) return error; 1767 if (error != ERR_NONE) return error;
1763 1768
1764 settings->Active = settings->Connection.Active; 1769 settings->Active = settings->Connection.Active;
1765 1770
1766 settings->Name[0] = 0; 1771 settings->Name[0] = 0;
1767 settings->Name[1] = 0; 1772 settings->Name[1] = 0;
1768 //s->Phone.Data.SyncMLSettings = settings; 1773 s->Phone.Data.SyncMLSettings = settings;
1774
1769 //smprintf(s, "Getting SyncML settings name\n"); 1775 //smprintf(s, "Getting SyncML settings name\n");
1770 //error = GSM_WaitFor (s, NameReq, 16, 0x43, 4, ID_GetSyncMLName); 1776 //error = GSM_WaitFor (s, NameReq, 16, 0x43, 4, ID_GetSyncMLName);
1771 //if (error != ERR_NONE) return error; 1777 //if (error != ERR_NONE) return error;
1772 1778
1773 req[9] = settings->Location - 1; 1779 req[9] = settings->Location - 1;
1774 smprintf(s, "Getting additional SyncML settings\n"); 1780 smprintf(s, "Getting additional SyncML settings\n");
1775 return GSM_WaitFor (s, req, 16, 0x43, 4, ID_GetSyncMLSettings); 1781 return GSM_WaitFor (s, req, 16, 0x43, 4, ID_GetSyncMLSettings);
1776} 1782}
1777 1783
1778static GSM_Error N6510_ReplyGetChatSettings(GSM_Protocol_Message msg, GSM_StateMachine *s) 1784static GSM_Error N6510_ReplyGetChatSettings(GSM_Protocol_Message msg, GSM_StateMachine *s)
1779{ 1785{
1780 GSM_ChatSettings *Sett = s->Phone.Data.ChatSettings; 1786 GSM_ChatSettings *Sett = s->Phone.Data.ChatSettings;
1781 int i; 1787 int i;
1782 1788
1783 Sett->Name[0] = 0; 1789 Sett->Name[0] = 0;
1784 Sett->Name[1] = 0; 1790 Sett->Name[1] = 0;
1785 Sett->HomePage[0] = 0; 1791 Sett->HomePage[0] = 0;
1786 Sett->HomePage[1] = 0; 1792 Sett->HomePage[1] = 0;
1787 Sett->User[0] = 0; 1793 Sett->User[0] = 0;
1788 Sett->User[1] = 0; 1794 Sett->User[1] = 0;
1789 Sett->Password[0] = 0; 1795 Sett->Password[0] = 0;
1790 Sett->Password[1] = 0; 1796 Sett->Password[1] = 0;
1791 1797
1792 switch(msg.Buffer[3]) { 1798 switch(msg.Buffer[3]) {
1793 case 0x3B: 1799 case 0x3B:
1794 smprintf(s, "Chat settings received OK\n"); 1800 smprintf(s, "Chat settings received OK\n");
1795 memcpy(Sett->Name,msg.Buffer+20,msg.Buffer[12]*2); 1801 memcpy(Sett->Name,msg.Buffer+20,msg.Buffer[12]*2);
1796 Sett->Name[msg.Buffer[12]*2] = 0; 1802 Sett->Name[msg.Buffer[12]*2] = 0;
1797 Sett->Name[msg.Buffer[12]*2+1] = 0; 1803 Sett->Name[msg.Buffer[12]*2+1] = 0;
1798 memcpy(Sett->HomePage,msg.Buffer+20+msg.Buffer[12]*2,msg.Buffer[15]*2); 1804 memcpy(Sett->HomePage,msg.Buffer+20+msg.Buffer[12]*2,msg.Buffer[15]*2);
1799 Sett->HomePage[msg.Buffer[15]*2] = 0; 1805 Sett->HomePage[msg.Buffer[15]*2] = 0;
1800 Sett->HomePage[msg.Buffer[15]*2+1] = 0; 1806 Sett->HomePage[msg.Buffer[15]*2+1] = 0;
1801 i = msg.Buffer[12]*2 + msg.Buffer[15]*2 + 29; 1807 i = msg.Buffer[12]*2 + msg.Buffer[15]*2 + 29;
1802 memcpy(Sett->User,msg.Buffer+i+3,msg.Buffer[i]*2); 1808 memcpy(Sett->User,msg.Buffer+i+3,msg.Buffer[i]*2);
1803 Sett->User[msg.Buffer[i]*2] = 0; 1809 Sett->User[msg.Buffer[i]*2] = 0;
1804 Sett->User[msg.Buffer[i]*2+1] = 0; 1810 Sett->User[msg.Buffer[i]*2+1] = 0;
1805 memcpy(Sett->Password,msg.Buffer+i+3+msg.Buffer[i]*2,msg.Buffer[i+1]*2); 1811 memcpy(Sett->Password,msg.Buffer+i+3+msg.Buffer[i]*2,msg.Buffer[i+1]*2);
1806 Sett->Password[msg.Buffer[i+1]*2] = 0; 1812 Sett->Password[msg.Buffer[i+1]*2] = 0;
1807 Sett->Password[msg.Buffer[i+1]*2+1] = 0; 1813 Sett->Password[msg.Buffer[i+1]*2+1] = 0;
1808 return ERR_NONE; 1814 return ERR_NONE;
1809 case 0x3C: 1815 case 0x3C:
1810 smprintf(s, "Empty chat settings received\n"); 1816 smprintf(s, "Empty chat settings received\n");
1811 return ERR_NONE; 1817 return ERR_NONE;
1812 } 1818 }
1813 return ERR_UNKNOWNRESPONSE; 1819 return ERR_UNKNOWNRESPONSE;
1814} 1820}
1815 1821
1816static GSM_Error N6510_GetChatSettings(GSM_StateMachine *s, GSM_ChatSettings *settings) 1822static GSM_Error N6510_GetChatSettings(GSM_StateMachine *s, GSM_ChatSettings *settings)
1817{ 1823{
1818 GSM_Error error; 1824 GSM_Error error;
1819 unsigned char req[] = {N6110_FRAME_HEADER, 0x3a, 1825 unsigned char req[] = {N6110_FRAME_HEADER, 0x3a,
1820 0x09, // location 1826 0x09, // location
1821 0x01, 0x0e}; 1827 0x01, 0x0e};
1822 1828
1823 settings->Connection.Location = settings->Location; 1829 settings->Connection.Location = settings->Location;
1824 error = N6510_GetConnectionSettings(s, &settings->Connection, N6510_CHAT_SETTINGS); 1830 error = N6510_GetConnectionSettings(s, &settings->Connection, N6510_CHAT_SETTINGS);
1825 if (error != ERR_NONE) return error; 1831 if (error != ERR_NONE) return error;
1826 1832
1827 settings->Active = settings->Connection.Active; 1833 settings->Active = settings->Connection.Active;
1828 1834
1829 s->Phone.Data.ChatSettings = settings; 1835 s->Phone.Data.ChatSettings = settings;
1830 req[4] = settings->Location - 1; 1836 req[4] = settings->Location - 1;
1831 smprintf(s, "Getting additional Chat settings\n"); 1837 smprintf(s, "Getting additional Chat settings\n");
1832 return GSM_WaitFor (s, req, 7, 0x3f, 4, ID_GetChatSettings); 1838 return GSM_WaitFor (s, req, 7, 0x3f, 4, ID_GetChatSettings);
1833} 1839}
1834 1840
1835static GSM_Error N6510_ReplySetConnectionSettings(GSM_Protocol_Message msg, GSM_StateMachine *s) 1841static GSM_Error N6510_ReplySetConnectionSettings(GSM_Protocol_Message msg, GSM_StateMachine *s)
1836{ 1842{
1837 switch (msg.Buffer[3]) { 1843 switch (msg.Buffer[3]) {
1838 case 0x19: 1844 case 0x19:
1839 smprintf(s, "Connection settings cleaned\n"); 1845 smprintf(s, "Connection settings cleaned\n");
1840 return ERR_NONE; 1846 return ERR_NONE;
1841 case 0x1a: 1847 case 0x1a:
1842 smprintf(s, "Connection settings setting status\n"); 1848 smprintf(s, "Connection settings setting status\n");
1843 switch (msg.Buffer[4]) { 1849 switch (msg.Buffer[4]) {
1844 case 0x01: 1850 case 0x01:
1845 smprintf(s, "Security error. Inside phone settings menu\n"); 1851 smprintf(s, "Security error. Inside phone settings menu\n");
1846 return ERR_INSIDEPHONEMENU; 1852 return ERR_INSIDEPHONEMENU;
1847 case 0x03: 1853 case 0x03:
1848 smprintf(s, "Invalid location\n"); 1854 smprintf(s, "Invalid location\n");
1849 return ERR_INVALIDLOCATION; 1855 return ERR_INVALIDLOCATION;
1850 case 0x05: 1856 case 0x05:
1851 smprintf(s, "Written OK\n"); 1857 smprintf(s, "Written OK\n");
1852 return ERR_NONE; 1858 return ERR_NONE;
1853 default: 1859 default:
1854 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]); 1860 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]);
1855 return ERR_UNKNOWNRESPONSE; 1861 return ERR_UNKNOWNRESPONSE;
1856 } 1862 }
1857 case 0x28: 1863 case 0x28:
1858 case 0x2B: 1864 case 0x2B:
1859 smprintf(s, "Set OK\n"); 1865 smprintf(s, "Set OK\n");
1860 return ERR_NONE; 1866 return ERR_NONE;
1861 } 1867 }
1862 return ERR_UNKNOWNRESPONSE; 1868 return ERR_UNKNOWNRESPONSE;
1863} 1869}
1864 1870
1865static GSM_Error N6510_SetConnectionSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings, N6510_Connection_Settings Type) 1871static GSM_Error N6510_SetConnectionSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings, N6510_Connection_Settings Type)
1866{ 1872{
1867 GSM_Error error; 1873 GSM_Error error;
1868 int i, pad = 0, length, pos = 5, loc1=-1,loc2=-1,port; 1874 int i, pad = 0, length, pos = 5, loc1=-1,loc2=-1,port;
1869 unsigned char*Proxy; 1875 unsigned char*Proxy;
1870 unsigned char req[2000] = {N6110_FRAME_HEADER, 0x18, 1876 unsigned char req[2000] = {N6110_FRAME_HEADER, 0x18,
1871 0x00}; /* Location */ 1877 0x00}; /* Location */
1872 unsigned char Lock[5] = {N6110_FRAME_HEADER, 0x27, 1878 unsigned char Lock[5] = {N6110_FRAME_HEADER, 0x27,
1873 0x00}; /* Location */ 1879 0x00}; /* Location */
1874 unsigned char UnLock[5] = {N6110_FRAME_HEADER, 0x2A, 1880 unsigned char UnLock[5] = {N6110_FRAME_HEADER, 0x2A,
1875 0x00}; /* Location */ 1881 0x00}; /* Location */
1876 1882
1877 error = N6510_EnableConnectionFunctions(s, Type); 1883 error = N6510_EnableConnectionFunctions(s, Type);
1878 if (error!=ERR_NONE) return error; 1884 if (error!=ERR_NONE) return error;
1879 1885
1880 memset(req + pos, 0, 1000 - pos); 1886 memset(req + pos, 0, 1000 - pos);
1881 1887
1882 req[4] = settings->Location-1; 1888 req[4] = settings->Location-1;
1883 1889
1884 for (i=0;i<settings->Number;i++) { 1890 for (i=0;i<settings->Number;i++) {
1885 if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_DATA) loc1=i; 1891 if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_DATA) loc1=i;
1886 if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_GPRS) loc2=i; 1892 if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_GPRS) loc2=i;
1887 } 1893 }
1888 1894
1889 if (loc1 != -1) { 1895 if (loc1 != -1) {
1890 /* Name */ 1896 /* Name */
1891 length = UnicodeLength(settings->Settings[loc1].Title); 1897 length = UnicodeLength(settings->Settings[loc1].Title);
1892 if (!(length % 2)) pad = 1; 1898 if (!(length % 2)) pad = 1;
1893 pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc1].Title, false); 1899 pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc1].Title, false);
1894 1900
1895 /* Home */ 1901 /* Home */
1896 length = UnicodeLength(settings->Settings[loc1].HomePage); 1902 length = UnicodeLength(settings->Settings[loc1].HomePage);
1897 if (((length + pad) % 2)) pad = 2; else pad = 0; 1903 if (((length + pad) % 2)) pad = 2; else pad = 0;
1898 pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc1].HomePage, true); 1904 pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc1].HomePage, true);
1899 1905
1900 if (settings->Settings[loc1].IsContinuous) req[pos] = 0x01; pos++; 1906 if (settings->Settings[loc1].IsContinuous) req[pos] = 0x01; pos++;
1901 if (settings->Settings[loc1].IsSecurity) req[pos] = 0x01; pos++; 1907 if (settings->Settings[loc1].IsSecurity) req[pos] = 0x01; pos++;
1902 } else if (loc2 != -1) { 1908 } else if (loc2 != -1) {
1903 /* Name */ 1909 /* Name */
1904 length = UnicodeLength(settings->Settings[loc2].Title); 1910 length = UnicodeLength(settings->Settings[loc2].Title);
1905 if (!(length % 2)) pad = 1; 1911 if (!(length % 2)) pad = 1;
1906 pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc2].Title, false); 1912 pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc2].Title, false);
1907 1913
1908 /* Home */ 1914 /* Home */
1909 length = UnicodeLength(settings->Settings[loc2].HomePage); 1915 length = UnicodeLength(settings->Settings[loc2].HomePage);
1910 if (((length + pad) % 2)) pad = 2; else pad = 0; 1916 if (((length + pad) % 2)) pad = 2; else pad = 0;
1911 pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc2].HomePage, true); 1917 pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc2].HomePage, true);
1912 1918
1913 if (settings->Settings[loc2].IsContinuous) req[pos] = 0x01; pos++; 1919 if (settings->Settings[loc2].IsContinuous) req[pos] = 0x01; pos++;
1914 if (settings->Settings[loc2].IsSecurity) req[pos] = 0x01; pos++; 1920 if (settings->Settings[loc2].IsSecurity) req[pos] = 0x01; pos++;
1915 } else { 1921 } else {
1916 /* Name */ 1922 /* Name */
1917 length = 0; 1923 length = 0;
1918 if (!(length % 2)) pad = 1; 1924 if (!(length % 2)) pad = 1;
1919 pos ++; 1925 pos ++;
1920 1926
1921 /* Home */ 1927 /* Home */
1922 length = 0; 1928 length = 0;
1923 if (((length + pad) % 2)) pad = 2; else pad = 0; 1929 if (((length + pad) % 2)) pad = 2; else pad = 0;
1924 pos += 2; 1930 pos += 2;
1925 1931
1926 pos += 2; 1932 pos += 2;
1927 } 1933 }
1928 1934
1929 if (Type == N6510_MMS_SETTINGS || Type == N6510_CHAT_SETTINGS) { 1935 if (Type == N6510_MMS_SETTINGS || Type == N6510_CHAT_SETTINGS) {
1930 req[pos++] = 0x03; //active bearer: GPRS 1936 req[pos++] = 0x03; //active bearer: GPRS
1931 } else { 1937 } else {
1932 if (settings->ActiveBearer == WAPSETTINGS_BEARER_GPRS && loc2 != -1) { 1938 if (settings->ActiveBearer == WAPSETTINGS_BEARER_GPRS && loc2 != -1) {
1933 req[pos++] = 0x03; //active bearer: GPRS 1939 req[pos++] = 0x03; //active bearer: GPRS
1934 } else { 1940 } else {
1935 req[pos++] = 0x01; //active bearer: data set 1941 req[pos++] = 0x01; //active bearer: data set
1936 } 1942 }
1937 } 1943 }
1938 1944
1939 /* Number of sent bearers */ 1945 /* Number of sent bearers */
1940 if (Type == N6510_MMS_SETTINGS || Type == N6510_CHAT_SETTINGS) { 1946 if (Type == N6510_MMS_SETTINGS || Type == N6510_CHAT_SETTINGS) {
1941 req[pos] = 0x01; 1947 req[pos] = 0x01;
1942 } else { 1948 } else {
1943 req[pos] = 0x02; 1949 req[pos] = 0x02;
1944 } 1950 }
1945 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_WAPMMSPROXY)) req[pos] += 2; 1951 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_WAPMMSPROXY)) req[pos] += 2;
1946 pos++; 1952 pos++;
1947 pos += pad; 1953 pos += pad;
1948 1954
1949 if (Type != N6510_MMS_SETTINGS && Type != N6510_CHAT_SETTINGS) { 1955 if (Type != N6510_MMS_SETTINGS && Type != N6510_CHAT_SETTINGS) {
1950 /* GSM data block */ 1956 /* GSM data block */
1951 memcpy(req + pos, "\x01\x00", 2);pos += 2; 1957 memcpy(req + pos, "\x01\x00", 2);pos += 2;
1952 1958
1953 if (loc1 != -1) { 1959 if (loc1 != -1) {
1954 length = UnicodeLength(settings->Settings[loc1].IPAddress)*2+1; 1960 length = UnicodeLength(settings->Settings[loc1].IPAddress)*2+1;
1955 length += UnicodeLength(settings->Settings[loc1].DialUp) *2+2; 1961 length += UnicodeLength(settings->Settings[loc1].DialUp) *2+2;
1956 length += UnicodeLength(settings->Settings[loc1].User) *2+2; 1962 length += UnicodeLength(settings->Settings[loc1].User) *2+2;
1957 length += UnicodeLength(settings->Settings[loc1].Password) *2+2; 1963 length += UnicodeLength(settings->Settings[loc1].Password) *2+2;
1958 } else { 1964 } else {
1959 length = 1 + 2 + 2 + 2; 1965 length = 1 + 2 + 2 + 2;
1960 } 1966 }
@@ -2094,385 +2100,385 @@ static GSM_Error N6510_SetConnectionSettings(GSM_StateMachine *s, GSM_MultiWAPSe
2094 2100
2095 req[pos++] = 0x00; 2101 req[pos++] = 0x00;
2096 req[pos++] = 0x01; 2102 req[pos++] = 0x01;
2097 2103
2098 req[pos++] = 0x00; 2104 req[pos++] = 0x00;
2099 if (Proxy != NULL && UnicodeLength(Proxy)!=0) { 2105 if (Proxy != NULL && UnicodeLength(Proxy)!=0) {
2100 CopyUnicodeString(req+pos,Proxy); 2106 CopyUnicodeString(req+pos,Proxy);
2101 pos+=UnicodeLength(Proxy)*2; 2107 pos+=UnicodeLength(Proxy)*2;
2102 if (UnicodeLength(Proxy)%2 != 0) { 2108 if (UnicodeLength(Proxy)%2 != 0) {
2103 req[pos++] = 0x00; 2109 req[pos++] = 0x00;
2104 req[pos++] = 0x00; 2110 req[pos++] = 0x00;
2105 } 2111 }
2106 } 2112 }
2107 } 2113 }
2108 2114
2109 req[pos++] = 0x09; req[pos++] = 0x00; req[pos++] = 0x00; 2115 req[pos++] = 0x09; req[pos++] = 0x00; req[pos++] = 0x00;
2110 req[pos++] = 0x0C; req[pos++] = 0x02; req[pos++] = 0x00; 2116 req[pos++] = 0x0C; req[pos++] = 0x02; req[pos++] = 0x00;
2111 req[pos++] = 0x00; req[pos++] = 0x02; req[pos++] = 0x00; 2117 req[pos++] = 0x00; req[pos++] = 0x02; req[pos++] = 0x00;
2112 req[pos++] = 0x00; req[pos++] = 0x00; req[pos++] = 0x00; 2118 req[pos++] = 0x00; req[pos++] = 0x00; req[pos++] = 0x00;
2113 } else { 2119 } else {
2114 /* end of blocks ? */ 2120 /* end of blocks ? */
2115 memcpy(req + pos, "\x80\x00\x00\x0c", 4);pos += 4; 2121 memcpy(req + pos, "\x80\x00\x00\x0c", 4);pos += 4;
2116 } 2122 }
2117 2123
2118 UnLock[4] = settings->Location-1; 2124 UnLock[4] = settings->Location-1;
2119 smprintf(s, "Making Connection settings read-write\n"); 2125 smprintf(s, "Making Connection settings read-write\n");
2120 error = GSM_WaitFor (s, UnLock, 5, 0x3f, 4, ID_SetConnectSet); 2126 error = GSM_WaitFor (s, UnLock, 5, 0x3f, 4, ID_SetConnectSet);
2121 if (error != ERR_NONE) return error; 2127 if (error != ERR_NONE) return error;
2122 2128
2123 switch (Type) { 2129 switch (Type) {
2124 case N6510_MMS_SETTINGS: 2130 case N6510_MMS_SETTINGS:
2125 smprintf(s, "Setting MMS settings\n"); 2131 smprintf(s, "Setting MMS settings\n");
2126 break; 2132 break;
2127 case N6510_CHAT_SETTINGS: 2133 case N6510_CHAT_SETTINGS:
2128 smprintf(s, "Setting Chat settings\n"); 2134 smprintf(s, "Setting Chat settings\n");
2129 break; 2135 break;
2130 case N6510_WAP_SETTINGS: 2136 case N6510_WAP_SETTINGS:
2131 smprintf(s, "Setting WAP settings\n"); 2137 smprintf(s, "Setting WAP settings\n");
2132 break; 2138 break;
2133 case N6510_SYNCML_SETTINGS: 2139 case N6510_SYNCML_SETTINGS:
2134 smprintf(s, "Setting SyncML settings\n"); 2140 smprintf(s, "Setting SyncML settings\n");
2135 break; 2141 break;
2136 } 2142 }
2137 error = GSM_WaitFor (s, req, pos, 0x3f, 4, ID_SetConnectSet); 2143 error = GSM_WaitFor (s, req, pos, 0x3f, 4, ID_SetConnectSet);
2138 if (error != ERR_NONE) { 2144 if (error != ERR_NONE) {
2139 if (error == ERR_INSIDEPHONEMENU || error == ERR_INVALIDLOCATION) { 2145 if (error == ERR_INSIDEPHONEMENU || error == ERR_INVALIDLOCATION) {
2140 DCT3DCT4_DisableConnectionFunctions(s); 2146 DCT3DCT4_DisableConnectionFunctions(s);
2141 } 2147 }
2142 return error; 2148 return error;
2143 } 2149 }
2144 2150
2145 if (settings->ReadOnly) { 2151 if (settings->ReadOnly) {
2146 Lock[4] = settings->Location-1; 2152 Lock[4] = settings->Location-1;
2147 smprintf(s, "Making Connection settings readonly\n"); 2153 smprintf(s, "Making Connection settings readonly\n");
2148 error = GSM_WaitFor (s, Lock, 5, 0x3f, 4, ID_SetConnectSet); 2154 error = GSM_WaitFor (s, Lock, 5, 0x3f, 4, ID_SetConnectSet);
2149 if (error != ERR_NONE) return error; 2155 if (error != ERR_NONE) return error;
2150 } 2156 }
2151 2157
2152 error = DCT3DCT4_SetActiveConnectSet(s, settings); 2158 error = DCT3DCT4_SetActiveConnectSet(s, settings);
2153 if (error != ERR_NONE) return error; 2159 if (error != ERR_NONE) return error;
2154 2160
2155 return DCT3DCT4_DisableConnectionFunctions(s); 2161 return DCT3DCT4_DisableConnectionFunctions(s);
2156} 2162}
2157 2163
2158static GSM_Error N6510_SetWAPSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings) 2164static GSM_Error N6510_SetWAPSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings)
2159{ 2165{
2160 return N6510_SetConnectionSettings(s, settings, N6510_WAP_SETTINGS); 2166 return N6510_SetConnectionSettings(s, settings, N6510_WAP_SETTINGS);
2161} 2167}
2162 2168
2163static GSM_Error N6510_SetMMSSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings) 2169static GSM_Error N6510_SetMMSSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings)
2164{ 2170{
2165 return N6510_SetConnectionSettings(s, settings, N6510_MMS_SETTINGS); 2171 return N6510_SetConnectionSettings(s, settings, N6510_MMS_SETTINGS);
2166} 2172}
2167 2173
2168static GSM_Error N6510_ReplyGetOriginalIMEI(GSM_Protocol_Message msg, GSM_StateMachine *s) 2174static GSM_Error N6510_ReplyGetOriginalIMEI(GSM_Protocol_Message msg, GSM_StateMachine *s)
2169{ 2175{
2170 if (msg.Buffer[7] == 0x00) { 2176 if (msg.Buffer[7] == 0x00) {
2171 smprintf(s, "No SIM card\n"); 2177 smprintf(s, "No SIM card\n");
2172 return ERR_SECURITYERROR; 2178 return ERR_SECURITYERROR;
2173 } else { 2179 } else {
2174 return NOKIA_ReplyGetPhoneString(msg, s); 2180 return NOKIA_ReplyGetPhoneString(msg, s);
2175 } 2181 }
2176} 2182}
2177 2183
2178static GSM_Error N6510_GetOriginalIMEI(GSM_StateMachine *s, char *value) 2184static GSM_Error N6510_GetOriginalIMEI(GSM_StateMachine *s, char *value)
2179{ 2185{
2180 return NOKIA_GetPhoneString(s,"\x00\x07\x02\x01\x00\x01",6,0x42,value,ID_GetOriginalIMEI,14); 2186 return NOKIA_GetPhoneString(s,"\x00\x07\x02\x01\x00\x01",6,0x42,value,ID_GetOriginalIMEI,14);
2181} 2187}
2182 2188
2183static GSM_Error N6510_ReplyGetSMSStatus(GSM_Protocol_Message msg, GSM_StateMachine *s) 2189static GSM_Error N6510_ReplyGetSMSStatus(GSM_Protocol_Message msg, GSM_StateMachine *s)
2184{ 2190{
2185 GSM_Phone_Data *Data = &s->Phone.Data; 2191 GSM_Phone_Data *Data = &s->Phone.Data;
2186 2192
2187 switch (msg.Buffer[3]) { 2193 switch (msg.Buffer[3]) {
2188 case 0x09: 2194 case 0x09:
2189 switch (msg.Buffer[4]) { 2195 switch (msg.Buffer[4]) {
2190 case 0x00: 2196 case 0x00:
2191 smprintf(s, "Max. in phone memory : %i\n",msg.Buffer[10]*256+msg.Buffer[11]); 2197 smprintf(s, "Max. in phone memory : %i\n",msg.Buffer[10]*256+msg.Buffer[11]);
2192 smprintf(s, "Used in phone memory : %i\n",msg.Buffer[12]*256+msg.Buffer[13]); 2198 smprintf(s, "Used in phone memory : %i\n",msg.Buffer[12]*256+msg.Buffer[13]);
2193 smprintf(s, "Unread in phone memory : %i\n",msg.Buffer[14]*256+msg.Buffer[15]); 2199 smprintf(s, "Unread in phone memory : %i\n",msg.Buffer[14]*256+msg.Buffer[15]);
2194 smprintf(s, "Max. in SIM : %i\n",msg.Buffer[22]*256+msg.Buffer[23]); 2200 smprintf(s, "Max. in SIM : %i\n",msg.Buffer[22]*256+msg.Buffer[23]);
2195 smprintf(s, "Used in SIM : %i\n",msg.Buffer[24]*256+msg.Buffer[25]); 2201 smprintf(s, "Used in SIM : %i\n",msg.Buffer[24]*256+msg.Buffer[25]);
2196 smprintf(s, "Unread in SIM : %i\n",msg.Buffer[26]*256+msg.Buffer[27]); 2202 smprintf(s, "Unread in SIM : %i\n",msg.Buffer[26]*256+msg.Buffer[27]);
2197 Data->SMSStatus->PhoneSize= msg.Buffer[10]*256+msg.Buffer[11]; 2203 Data->SMSStatus->PhoneSize= msg.Buffer[10]*256+msg.Buffer[11];
2198 Data->SMSStatus->PhoneUsed= msg.Buffer[12]*256+msg.Buffer[13]; 2204 Data->SMSStatus->PhoneUsed= msg.Buffer[12]*256+msg.Buffer[13];
2199 Data->SMSStatus->PhoneUnRead = msg.Buffer[14]*256+msg.Buffer[15]; 2205 Data->SMSStatus->PhoneUnRead = msg.Buffer[14]*256+msg.Buffer[15];
2200 Data->SMSStatus->SIMSize= msg.Buffer[22]*256+msg.Buffer[23]; 2206 Data->SMSStatus->SIMSize= msg.Buffer[22]*256+msg.Buffer[23];
2201 Data->SMSStatus->SIMUsed = msg.Buffer[24]*256+msg.Buffer[25]; 2207 Data->SMSStatus->SIMUsed = msg.Buffer[24]*256+msg.Buffer[25];
2202 Data->SMSStatus->SIMUnRead = msg.Buffer[26]*256+msg.Buffer[27]; 2208 Data->SMSStatus->SIMUnRead = msg.Buffer[26]*256+msg.Buffer[27];
2203 return ERR_NONE; 2209 return ERR_NONE;
2204 case 0x0f: 2210 case 0x0f:
2205 smprintf(s, "No PIN\n"); 2211 smprintf(s, "No PIN\n");
2206 return ERR_SECURITYERROR; 2212 return ERR_SECURITYERROR;
2207 default: 2213 default:
2208 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]); 2214 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]);
2209 return ERR_UNKNOWNRESPONSE; 2215 return ERR_UNKNOWNRESPONSE;
2210 } 2216 }
2211 case 0x1a: 2217 case 0x1a:
2212 smprintf(s, "Wait a moment. Phone is during power on and busy now\n"); 2218 smprintf(s, "Wait a moment. Phone is during power on and busy now\n");
2213 return ERR_SECURITYERROR; 2219 return ERR_SECURITYERROR;
2214 } 2220 }
2215 return ERR_UNKNOWNRESPONSE; 2221 return ERR_UNKNOWNRESPONSE;
2216} 2222}
2217 2223
2218static GSM_Error N6510_GetSMSStatus(GSM_StateMachine *s, GSM_SMSMemoryStatus *status) 2224static GSM_Error N6510_GetSMSStatus(GSM_StateMachine *s, GSM_SMSMemoryStatus *status)
2219{ 2225{
2220 GSM_Error error; 2226 GSM_Error error;
2221 GSM_Phone_N6510Data*Priv = &s->Phone.Data.Priv.N6510; 2227 GSM_Phone_N6510Data*Priv = &s->Phone.Data.Priv.N6510;
2222 unsigned char req[] = {N6110_FRAME_HEADER, 0x08, 0x00, 0x00}; 2228 unsigned char req[] = {N6110_FRAME_HEADER, 0x08, 0x00, 0x00};
2223 2229
2224 s->Phone.Data.SMSStatus=status; 2230 s->Phone.Data.SMSStatus=status;
2225 smprintf(s, "Getting SMS status\n"); 2231 smprintf(s, "Getting SMS status\n");
2226 error = GSM_WaitFor (s, req, 6, 0x14, 2, ID_GetSMSStatus); 2232 error = GSM_WaitFor (s, req, 6, 0x14, 2, ID_GetSMSStatus);
2227 if (error != ERR_NONE) return error; 2233 if (error != ERR_NONE) return error;
2228 2234
2229 /* DCT4 family doesn't show in frame with SMS status info 2235 /* DCT4 family doesn't show in frame with SMS status info
2230 * about Templates. We get separately info about this SMS folder. 2236 * about Templates. We get separately info about this SMS folder.
2231 */ 2237 */
2232 error = N6510_GetSMSFolderStatus(s, 0x06); 2238 error = N6510_GetSMSFolderStatus(s, 0x06);
2233 if (error != ERR_NONE) return error; 2239 if (error != ERR_NONE) return error;
2234 status->TemplatesUsed = Priv->LastSMSFolder.Number; 2240 status->TemplatesUsed = Priv->LastSMSFolder.Number;
2235 2241
2236 return error; 2242 return error;
2237} 2243}
2238 2244
2239static GSM_Error N6510_ReplyDeleteSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s) 2245static GSM_Error N6510_ReplyDeleteSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s)
2240{ 2246{
2241 switch (msg.Buffer[3]) { 2247 switch (msg.Buffer[3]) {
2242 case 0x05: 2248 case 0x05:
2243 smprintf(s, "SMS deleted OK\n"); 2249 smprintf(s, "SMS deleted OK\n");
2244 return ERR_NONE; 2250 return ERR_NONE;
2245 case 0x06: 2251 case 0x06:
2246 switch (msg.Buffer[4]) { 2252 switch (msg.Buffer[4]) {
2247 case 0x02: 2253 case 0x02:
2248 smprintf(s, "Invalid location\n"); 2254 smprintf(s, "Invalid location\n");
2249 return ERR_INVALIDLOCATION; 2255 return ERR_INVALIDLOCATION;
2250 default: 2256 default:
2251 smprintf(s, "Unknown error: %02x\n",msg.Buffer[4]); 2257 smprintf(s, "Unknown error: %02x\n",msg.Buffer[4]);
2252 return ERR_UNKNOWNRESPONSE; 2258 return ERR_UNKNOWNRESPONSE;
2253 } 2259 }
2254 } 2260 }
2255 return ERR_UNKNOWNRESPONSE; 2261 return ERR_UNKNOWNRESPONSE;
2256} 2262}
2257 2263
2258static GSM_Error N6510_DeleteSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms) 2264static GSM_Error N6510_DeleteSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms)
2259{ 2265{
2260 unsigned char folderid; 2266 unsigned char folderid;
2261 int location; 2267 int location;
2262 unsigned char req[] = {N6110_FRAME_HEADER, 0x04, 2268 unsigned char req[] = {N6110_FRAME_HEADER, 0x04,
2263 0x01, /* 0x01=SM, 0x02=ME */ 2269 0x01, /* 0x01=SM, 0x02=ME */
2264 0x00, /* FolderID */ 2270 0x00, /* FolderID */
2265 0x00, 0x02, /* Location */ 2271 0x00, 0x02, /* Location */
2266 0x0F, 0x55}; 2272 0x0F, 0x55};
2267 2273
2268 N6510_GetSMSLocation(s, sms, &folderid, &location); 2274 N6510_GetSMSLocation(s, sms, &folderid, &location);
2269 2275
2270 switch (folderid) { 2276 switch (folderid) {
2271 case 0x01: req[5] = 0x02; break; /* INBOX SIM */ 2277 case 0x01: req[5] = 0x02; break; /* INBOX SIM */
2272 case 0x02: req[5] = 0x03; break; /* OUTBOX SIM */ 2278 case 0x02: req[5] = 0x03; break; /* OUTBOX SIM */
2273 default : req[5] = folderid - 1; req[4] = 0x02; break; /* ME folders*/ 2279 default : req[5] = folderid - 1; req[4] = 0x02; break; /* ME folders*/
2274 } 2280 }
2275 req[6]=location / 256; 2281 req[6]=location / 256;
2276 req[7]=location; 2282 req[7]=location;
2277 2283
2278 smprintf(s, "Deleting sms\n"); 2284 smprintf(s, "Deleting sms\n");
2279 return GSM_WaitFor (s, req, 10, 0x14, 4, ID_DeleteSMSMessage); 2285 return GSM_WaitFor (s, req, 10, 0x14, 4, ID_DeleteSMSMessage);
2280} 2286}
2281 2287
2282static GSM_Error N6510_ReplySendSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s) 2288static GSM_Error N6510_ReplySendSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s)
2283{ 2289{
2284 switch (msg.Buffer[8]) { 2290 switch (msg.Buffer[8]) {
2285 case 0x00: 2291 case 0x00:
2286 smprintf(s, "SMS sent OK, TPMR for sent sms is %02x\n",msg.Buffer[10]); 2292 smprintf(s, "SMS sent OK, TPMR for sent sms is %d\n",msg.Buffer[10]);
2287 if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s->CurrentConfig->Device,0,msg.Buffer[10]); 2293 if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s->CurrentConfig->Device,0,msg.Buffer[10]);
2288 return ERR_NONE; 2294 return ERR_NONE;
2289 default: 2295 default:
2290 smprintf(s, "SMS not sent OK, error code probably %i\n",msg.Buffer[8]); 2296 smprintf(s, "SMS not sent OK, error code probably %i\n",msg.Buffer[8]);
2291 if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s->CurrentConfig->Device,msg.Buffer[8],msg.Buffer[10]); 2297 if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s->CurrentConfig->Device,msg.Buffer[8],msg.Buffer[10]);
2292 return ERR_NONE; 2298 return ERR_NONE;
2293 } 2299 }
2294} 2300}
2295 2301
2296static GSM_Error N6510_SendSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms) 2302static GSM_Error N6510_SendSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms)
2297{ 2303{
2298 int length = 11; 2304 int length = 11;
2299 GSM_Error error; 2305 GSM_Error error;
2300 GSM_SMSMessageLayout Layout; 2306 GSM_SMSMessageLayout Layout;
2301 unsigned char req [300] = { 2307 unsigned char req [300] = {
2302 N6110_FRAME_HEADER, 0x02, 0x00, 0x00, 0x00, 0x55, 0x55}; 2308 N6110_FRAME_HEADER, 0x02, 0x00, 0x00, 0x00, 0x55, 0x55};
2303 2309
2304 if (sms->PDU == SMS_Deliver) sms->PDU = SMS_Submit; 2310 if (sms->PDU == SMS_Deliver) sms->PDU = SMS_Submit;
2305 memset(req+9,0x00,sizeof(req) - 9); 2311 memset(req+9,0x00,sizeof(req) - 9);
2306 error=N6510_EncodeSMSFrame(s, sms, req + 9, &Layout, &length); 2312 error=N6510_EncodeSMSFrame(s, sms, req + 9, &Layout, &length);
2307 if (error != ERR_NONE) return error; 2313 if (error != ERR_NONE) return error;
2308 2314
2309 smprintf(s, "Sending sms\n"); 2315 smprintf(s, "Sending sms\n");
2310 return s->Protocol.Functions->WriteMessage(s, req, length + 9, 0x02); 2316 return s->Protocol.Functions->WriteMessage(s, req, length + 9, 0x02);
2311} 2317}
2312 2318
2313static GSM_Error N6510_ReplyGetSecurityStatus(GSM_Protocol_Message msg, GSM_StateMachine *s) 2319static GSM_Error N6510_ReplyGetSecurityStatus(GSM_Protocol_Message msg, GSM_StateMachine *s)
2314{ 2320{
2315 GSM_Phone_Data *Data = &s->Phone.Data; 2321 GSM_Phone_Data *Data = &s->Phone.Data;
2316 2322
2317 smprintf(s, "Security Code status received: "); 2323 smprintf(s, "Security Code status received: ");
2318 switch (msg.Buffer[4]) { 2324 switch (msg.Buffer[4]) {
2319 case 0x01 : smprintf(s, "waiting for Security Code.\n"); *Data->SecurityStatus = SEC_SecurityCode;break; 2325 case 0x01 : smprintf(s, "waiting for Security Code.\n"); *Data->SecurityStatus = SEC_SecurityCode;break;
2320 case 0x07 : 2326 case 0x07 :
2321 case 0x02 : smprintf(s, "waiting for PIN.\n"); *Data->SecurityStatus = SEC_Pin; break; 2327 case 0x02 : smprintf(s, "waiting for PIN.\n"); *Data->SecurityStatus = SEC_Pin; break;
2322 case 0x03 : smprintf(s, "waiting for PUK.\n"); *Data->SecurityStatus = SEC_Puk; break; 2328 case 0x03 : smprintf(s, "waiting for PUK.\n"); *Data->SecurityStatus = SEC_Puk; break;
2323 case 0x05 : smprintf(s, "PIN ok, SIM ok\n"); *Data->SecurityStatus = SEC_None; break; 2329 case 0x05 : smprintf(s, "PIN ok, SIM ok\n"); *Data->SecurityStatus = SEC_None; break;
2324 case 0x06 : smprintf(s, "No input status\n"); *Data->SecurityStatus = SEC_None; break; 2330 case 0x06 : smprintf(s, "No input status\n"); *Data->SecurityStatus = SEC_None; break;
2325 case 0x16 : smprintf(s, "No SIM card\n"); *Data->SecurityStatus = SEC_None; break; 2331 case 0x16 : smprintf(s, "No SIM card\n"); *Data->SecurityStatus = SEC_None; break;
2326 case 0x1A : smprintf(s, "SIM card rejected!\n"); *Data->SecurityStatus = SEC_None; break; 2332 case 0x1A : smprintf(s, "SIM card rejected!\n"); *Data->SecurityStatus = SEC_None; break;
2327 default : smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]); 2333 default : smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]);
2328 return ERR_UNKNOWNRESPONSE; 2334 return ERR_UNKNOWNRESPONSE;
2329 } 2335 }
2330 return ERR_NONE; 2336 return ERR_NONE;
2331} 2337}
2332 2338
2333static GSM_Error N6510_GetSecurityStatus(GSM_StateMachine *s, GSM_SecurityCodeType *Status) 2339static GSM_Error N6510_GetSecurityStatus(GSM_StateMachine *s, GSM_SecurityCodeType *Status)
2334{ 2340{
2335 unsigned char req[5] = {N6110_FRAME_HEADER, 0x11, 0x00}; 2341 unsigned char req[5] = {N6110_FRAME_HEADER, 0x11, 0x00};
2336 2342
2337 s->Phone.Data.SecurityStatus=Status; 2343 s->Phone.Data.SecurityStatus=Status;
2338 smprintf(s, "Getting security code status\n"); 2344 smprintf(s, "Getting security code status\n");
2339 return GSM_WaitFor (s, req, 5, 0x08, 2, ID_GetSecurityStatus); 2345 return GSM_WaitFor (s, req, 5, 0x08, 2, ID_GetSecurityStatus);
2340} 2346}
2341 2347
2342static GSM_Error N6510_ReplyEnterSecurityCode(GSM_Protocol_Message msg, GSM_StateMachine *s) 2348static GSM_Error N6510_ReplyEnterSecurityCode(GSM_Protocol_Message msg, GSM_StateMachine *s)
2343{ 2349{
2344 switch (msg.Buffer[3]) { 2350 switch (msg.Buffer[3]) {
2345 case 0x08: 2351 case 0x08:
2346 smprintf(s, "Security code OK\n"); 2352 smprintf(s, "Security code OK\n");
2347 return ERR_NONE; 2353 return ERR_NONE;
2348 case 0x09: 2354 case 0x09:
2349 switch (msg.Buffer[4]) { 2355 switch (msg.Buffer[4]) {
2350 case 0x06: 2356 case 0x06:
2351 smprintf(s, "Wrong PIN\n"); 2357 smprintf(s, "Wrong PIN\n");
2352 return ERR_SECURITYERROR; 2358 return ERR_SECURITYERROR;
2353 case 0x09: 2359 case 0x09:
2354 smprintf(s, "Wrong PUK\n"); 2360 smprintf(s, "Wrong PUK\n");
2355 return ERR_SECURITYERROR; 2361 return ERR_SECURITYERROR;
2356 default: 2362 default:
2357 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]); 2363 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]);
2358 } 2364 }
2359 } 2365 }
2360 return ERR_UNKNOWNRESPONSE; 2366 return ERR_UNKNOWNRESPONSE;
2361} 2367}
2362 2368
2363static GSM_Error N6510_EnterSecurityCode(GSM_StateMachine *s, GSM_SecurityCode Code) 2369static GSM_Error N6510_EnterSecurityCode(GSM_StateMachine *s, GSM_SecurityCode Code)
2364{ 2370{
2365 int len = 0; 2371 int len = 0;
2366 unsigned char req[15] = {N6110_FRAME_HEADER, 0x07, 2372 unsigned char req[15] = {N6110_FRAME_HEADER, 0x07,
2367 0x00};/* Code type */ 2373 0x00};/* Code type */
2368 2374
2369 switch (Code.Type) { 2375 switch (Code.Type) {
2370 case SEC_Pin: req[4] = 0x02; break; 2376 case SEC_Pin: req[4] = 0x02; break;
2371 case SEC_Puk: req[4] = 0x03; break;/* FIXME */ 2377 case SEC_Puk: req[4] = 0x03; break;/* FIXME */
2372 default : return ERR_NOTSUPPORTED; 2378 default : return ERR_NOTSUPPORTED;
2373 } 2379 }
2374 2380
2375 len = strlen(Code.Code); 2381 len = strlen(Code.Code);
2376 memcpy(req+5,Code.Code,len); 2382 memcpy(req+5,Code.Code,len);
2377 req[5+len]=0x00; 2383 req[5+len]=0x00;
2378 2384
2379 smprintf(s, "Entering security code\n"); 2385 smprintf(s, "Entering security code\n");
2380 return GSM_WaitFor (s, req, 6+len, 0x08, 4, ID_EnterSecurityCode); 2386 return GSM_WaitFor (s, req, 6+len, 0x08, 4, ID_EnterSecurityCode);
2381} 2387}
2382 2388
2383static GSM_Error N6510_ReplySaveSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s) 2389static GSM_Error N6510_ReplySaveSMSMessage(GSM_Protocol_Message msg, GSM_StateMachine *s)
2384{ 2390{
2385 unsigned char folder; 2391 unsigned char folder;
2386 GSM_Phone_Data *Data = &s->Phone.Data; 2392 GSM_Phone_Data *Data = &s->Phone.Data;
2387 2393
2388 switch (msg.Buffer[3]) { 2394 switch (msg.Buffer[3]) {
2389 case 0x01: 2395 case 0x01:
2390 switch (msg.Buffer[4]) { 2396 switch (msg.Buffer[4]) {
2391 case 0x00: 2397 case 0x00:
2392 smprintf(s, "Done OK\n"); 2398 smprintf(s, "Done OK\n");
2393 smprintf(s, "Folder info: %i %i\n",msg.Buffer[5],msg.Buffer[8]); 2399 smprintf(s, "Folder info: %i %i\n",msg.Buffer[5],msg.Buffer[8]);
2394 switch (msg.Buffer[8]) { 2400 switch (msg.Buffer[8]) {
2395 case 0x02 : if (msg.Buffer[5] == 0x02) { 2401 case 0x02 : if (msg.Buffer[5] == 0x02) {
2396 folder = 0x03; /* INBOX ME */ 2402 folder = 0x03; /* INBOX ME */
2397 } else { 2403 } else {
2398 folder = 0x01; /* INBOX SIM */ 2404 folder = 0x01; /* INBOX SIM */
2399 } 2405 }
2400 break; 2406 break;
2401 case 0x03 : if (msg.Buffer[5] == 0x02) { 2407 case 0x03 : if (msg.Buffer[5] == 0x02) {
2402 folder = 0x04; /* OUTBOX ME */ 2408 folder = 0x04; /* OUTBOX ME */
2403 } else { 2409 } else {
2404 folder = 0x02; /* OUTBOX SIM */ 2410 folder = 0x02; /* OUTBOX SIM */
2405 } 2411 }
2406 break; 2412 break;
2407 default : folder = msg.Buffer[8] + 1; 2413 default : folder = msg.Buffer[8] + 1;
2408 } 2414 }
2409 N6510_SetSMSLocation(s, Data->SaveSMSMessage,folder,msg.Buffer[6]*256+msg.Buffer[7]); 2415 N6510_SetSMSLocation(s, Data->SaveSMSMessage,folder,msg.Buffer[6]*256+msg.Buffer[7]);
2410 smprintf(s, "Saved in folder %i at location %i\n",folder, msg.Buffer[6]*256+msg.Buffer[7]); 2416 smprintf(s, "Saved in folder %i at location %i\n",folder, msg.Buffer[6]*256+msg.Buffer[7]);
2411 Data->SaveSMSMessage->Folder = folder; 2417 Data->SaveSMSMessage->Folder = folder;
2412 return ERR_NONE; 2418 return ERR_NONE;
2413 case 0x02: 2419 case 0x02:
2414 printf("Incorrect location\n"); 2420 printf("Incorrect location\n");
2415 return ERR_INVALIDLOCATION; 2421 return ERR_INVALIDLOCATION;
2416 case 0x05: 2422 case 0x05:
2417 printf("Incorrect folder\n"); 2423 printf("Incorrect folder\n");
2418 return ERR_INVALIDLOCATION; 2424 return ERR_INVALIDLOCATION;
2419 default: 2425 default:
2420 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]); 2426 smprintf(s, "ERROR: unknown %i\n",msg.Buffer[4]);
2421 return ERR_UNKNOWNRESPONSE; 2427 return ERR_UNKNOWNRESPONSE;
2422 } 2428 }
2423 case 0x17: 2429 case 0x17:
2424 smprintf(s, "SMS name changed\n"); 2430 smprintf(s, "SMS name changed\n");
2425 return ERR_NONE; 2431 return ERR_NONE;
2426 } 2432 }
2427 return ERR_UNKNOWNRESPONSE; 2433 return ERR_UNKNOWNRESPONSE;
2428} 2434}
2429 2435
2430static GSM_Error N6510_PrivSetSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms) 2436static GSM_Error N6510_PrivSetSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms)
2431{ 2437{
2432 int location, length = 11; 2438 int location, length = 11;
2433 unsigned char folderid, folder; 2439 unsigned char folderid, folder;
2434 GSM_SMSMessageLayout Layout; 2440 GSM_SMSMessageLayout Layout;
2435 GSM_Error error; 2441 GSM_Error error;
2436 unsigned char req [300] = { 2442 unsigned char req [300] = {
2437 N6110_FRAME_HEADER, 0x00, 2443 N6110_FRAME_HEADER, 0x00,
2438 0x01, /* 1 = SIM, 2 = ME */ 2444 0x01, /* 1 = SIM, 2 = ME */
2439 0x02, /* Folder */ 2445 0x02, /* Folder */
2440 0x00, 0x01, /* Location */ 2446 0x00, 0x01, /* Location */
2441 0x01}; /* SMS state */ 2447 0x01}; /* SMS state */
2442 unsigned char NameReq[200] = { 2448 unsigned char NameReq[200] = {
2443 N6110_FRAME_HEADER, 0x16, 2449 N6110_FRAME_HEADER, 0x16,
2444 0x01, /* 1 = SIM, 2 = ME */ 2450 0x01, /* 1 = SIM, 2 = ME */
2445 0x02, /* Folder */ 2451 0x02, /* Folder */
2446 0x00, 0x01}; /* Location */ 2452 0x00, 0x01}; /* Location */
2447 2453
2448 N6510_GetSMSLocation(s, sms, &folderid, &location); 2454 N6510_GetSMSLocation(s, sms, &folderid, &location);
2449 switch (folderid) { 2455 switch (folderid) {
2450 case 0x01: req[5] = 0x02; break; /* INBOX SIM */ 2456 case 0x01: req[5] = 0x02; break; /* INBOX SIM */
2451 case 0x02: req[5] = 0x03; break; /* OUTBOX SIM */ 2457 case 0x02: req[5] = 0x03; break; /* OUTBOX SIM */
2452 default : req[5] = folderid - 1; req[4] = 0x02; break; /* ME folders*/ 2458 default : req[5] = folderid - 1; req[4] = 0x02; break; /* ME folders*/
2453 } 2459 }
2454 req[6]=location / 256; 2460 req[6]=location / 256;
2455 req[7]=location; 2461 req[7]=location;
2456 2462
2457 switch (sms->PDU) { 2463 switch (sms->PDU) {
2458 case SMS_Submit: 2464 case SMS_Submit:
2459 /* Inbox */ 2465 /* Inbox */
2460 if (folderid == 0x01 || folderid == 0x03) sms->PDU = SMS_Deliver; 2466 if (folderid == 0x01 || folderid == 0x03) sms->PDU = SMS_Deliver;
2461 break; 2467 break;
2462 case SMS_Deliver: 2468 case SMS_Deliver:
2463 /* SIM Outbox */ 2469 /* SIM Outbox */
2464 if (folderid == 0x02) sms->PDU = SMS_Submit; 2470 if (folderid == 0x02) sms->PDU = SMS_Submit;
2465 break; 2471 break;
2466 default: 2472 default:
2467 return ERR_UNKNOWN; 2473 return ERR_UNKNOWN;
2468 } 2474 }
2469 if (sms->PDU == SMS_Deliver) { 2475 if (sms->PDU == SMS_Deliver) {
2470 switch (sms->State) { 2476 switch (sms->State) {
2471 case SMS_Sent: /* We use GSM_Read, because phone return error */ 2477 case SMS_Sent: /* We use GSM_Read, because phone return error */
2472 case SMS_Read: req[8] = 0x01; break; 2478 case SMS_Read: req[8] = 0x01; break;
2473 case SMS_UnSent: /* We use GSM_UnRead, because phone return error */ 2479 case SMS_UnSent: /* We use GSM_UnRead, because phone return error */
2474 case SMS_UnRead: req[8] = 0x03; break; 2480 case SMS_UnRead: req[8] = 0x03; break;
2475 } 2481 }
2476 } else { 2482 } else {
2477 switch (sms->State) { 2483 switch (sms->State) {
2478 case SMS_Sent: /* We use GSM_Sent, because phone change folder */ 2484 case SMS_Sent: /* We use GSM_Sent, because phone change folder */
@@ -2581,2013 +2587,2089 @@ static GSM_Error N6510_ReplyGetManufactureMonth(GSM_Protocol_Message msg, GSM_St
2581 } else { 2587 } else {
2582 sprintf(s->Phone.Data.PhoneString,"%02i/%04i",msg.Buffer[13],msg.Buffer[14]*256+msg.Buffer[15]); 2588 sprintf(s->Phone.Data.PhoneString,"%02i/%04i",msg.Buffer[13],msg.Buffer[14]*256+msg.Buffer[15]);
2583 return ERR_NONE; 2589 return ERR_NONE;
2584 } 2590 }
2585} 2591}
2586 2592
2587static GSM_Error N6510_GetManufactureMonth(GSM_StateMachine *s, char *value) 2593static GSM_Error N6510_GetManufactureMonth(GSM_StateMachine *s, char *value)
2588{ 2594{
2589 unsigned char req[6] = {0x00, 0x05, 0x02, 0x01, 0x00, 0x02}; 2595 unsigned char req[6] = {0x00, 0x05, 0x02, 0x01, 0x00, 0x02};
2590 //unsigned char req[6] = {0x00, 0x03, 0x04, 0x0B, 0x01, 0x00}; 2596 //unsigned char req[6] = {0x00, 0x03, 0x04, 0x0B, 0x01, 0x00};
2591 2597
2592 s->Phone.Data.PhoneString=value; 2598 s->Phone.Data.PhoneString=value;
2593 smprintf(s, "Getting manufacture month\n"); 2599 smprintf(s, "Getting manufacture month\n");
2594 return GSM_WaitFor (s, req, 6, 0x42, 2, ID_GetManufactureMonth); 2600 return GSM_WaitFor (s, req, 6, 0x42, 2, ID_GetManufactureMonth);
2595 //return GSM_WaitFor (s, req, 6, 0x1B, 2, ID_GetManufactureMonth); 2601 //return GSM_WaitFor (s, req, 6, 0x1B, 2, ID_GetManufactureMonth);
2596} 2602}
2597 2603
2598static GSM_Error N6510_ReplyGetAlarm(GSM_Protocol_Message msg, GSM_StateMachine *s) 2604static GSM_Error N6510_ReplyGetAlarm(GSM_Protocol_Message msg, GSM_StateMachine *s)
2599{ 2605{
2600 GSM_Phone_Data *Data = &s->Phone.Data; 2606 GSM_Phone_Data *Data = &s->Phone.Data;
2601 2607
2602 switch(msg.Buffer[3]) { 2608 switch(msg.Buffer[3]) {
2603 case 0x1A: 2609 case 0x1A:
2604 smprintf(s, " Alarm: %02d:%02d\n", msg.Buffer[14], msg.Buffer[15]); 2610 smprintf(s, " Alarm: %02d:%02d\n", msg.Buffer[14], msg.Buffer[15]);
2605 Data->Alarm->Repeating = true; 2611 Data->Alarm->Repeating = true;
2606 Data->Alarm->Text[0] = 0; 2612 Data->Alarm->Text[0] = 0;
2607 Data->Alarm->Text[1] = 0; 2613 Data->Alarm->Text[1] = 0;
2608 Data->Alarm->DateTime.Hour= msg.Buffer[14]; 2614 Data->Alarm->DateTime.Hour= msg.Buffer[14];
2609 Data->Alarm->DateTime.Minute= msg.Buffer[15]; 2615 Data->Alarm->DateTime.Minute= msg.Buffer[15];
2610 Data->Alarm->DateTime.Second= 0; 2616 Data->Alarm->DateTime.Second= 0;
2611 return ERR_NONE; 2617 return ERR_NONE;
2612 case 0x20: 2618 case 0x20:
2613 smprintf(s, "Alarm state received\n"); 2619 smprintf(s, "Alarm state received\n");
2614 if (msg.Buffer[37] == 0x01) { 2620 if (msg.Buffer[37] == 0x01) {
2615 smprintf(s, " Not set in phone\n"); 2621 smprintf(s, " Not set in phone\n");
2616 return ERR_EMPTY; 2622 return ERR_EMPTY;
2617 } 2623 }
2618 smprintf(s, "Enabled\n"); 2624 smprintf(s, "Enabled\n");
2619 return ERR_NONE; 2625 return ERR_NONE;
2620 } 2626 }
2621 return ERR_UNKNOWNRESPONSE; 2627 return ERR_UNKNOWNRESPONSE;
2622} 2628}
2623 2629
2624static GSM_Error N6510_GetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm) 2630static GSM_Error N6510_GetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm)
2625{ 2631{
2626 unsigned char StateReq[] = {N6110_FRAME_HEADER, 0x1f, 0x01, 0x00}; 2632 unsigned char StateReq[] = {N6110_FRAME_HEADER, 0x1f, 0x01, 0x00};
2627 unsigned char GetReq [] = {N6110_FRAME_HEADER, 0x19, 0x00, 0x02}; 2633 unsigned char GetReq [] = {N6110_FRAME_HEADER, 0x19, 0x00, 0x02};
2628 GSM_Errorerror; 2634 GSM_Errorerror;
2629 2635
2630 if (alarm->Location != 1) return ERR_NOTSUPPORTED; 2636 if (alarm->Location != 1) return ERR_NOTSUPPORTED;
2631 2637
2632 s->Phone.Data.Alarm=alarm; 2638 s->Phone.Data.Alarm=alarm;
2633 smprintf(s, "Getting alarm state\n"); 2639 smprintf(s, "Getting alarm state\n");
2634 error = GSM_WaitFor (s, StateReq, 6, 0x19, 4, ID_GetAlarm); 2640 error = GSM_WaitFor (s, StateReq, 6, 0x19, 4, ID_GetAlarm);
2635 if (error != ERR_NONE) return error; 2641 if (error != ERR_NONE) return error;
2636 2642
2637 smprintf(s, "Getting alarm\n"); 2643 smprintf(s, "Getting alarm\n");
2638 return GSM_WaitFor (s, GetReq, 6, 0x19, 4, ID_GetAlarm); 2644 return GSM_WaitFor (s, GetReq, 6, 0x19, 4, ID_GetAlarm);
2639} 2645}
2640 2646
2641static GSM_Error N6510_ReplySetAlarm(GSM_Protocol_Message msg, GSM_StateMachine *s) 2647static GSM_Error N6510_ReplySetAlarm(GSM_Protocol_Message msg, GSM_StateMachine *s)
2642{ 2648{
2643 smprintf(s, "Alarm set\n"); 2649 smprintf(s, "Alarm set\n");
2644 return ERR_NONE; 2650 return ERR_NONE;
2645} 2651}
2646 2652
2647static GSM_Error N6510_SetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm) 2653static GSM_Error N6510_SetAlarm(GSM_StateMachine *s, GSM_Alarm *alarm)
2648{ 2654{
2649 unsigned char req[] = {N6110_FRAME_HEADER, 2655 unsigned char req[] = {N6110_FRAME_HEADER,
2650 0x11, 0x00, 0x01, 0x01, 0x0c, 0x02, 2656 0x11, 0x00, 0x01, 0x01, 0x0c, 0x02,
2651 0x01, 0x00, 0x00, 0x00, 0x00, 2657 0x01, 0x00, 0x00, 0x00, 0x00,
2652 0x00, 0x00, /* Hours, Minutes */ 2658 0x00, 0x00, /* Hours, Minutes */
2653 0x00, 0x00, 0x00 }; 2659 0x00, 0x00, 0x00 };
2654 2660
2655 if (alarm->Location != 1) return ERR_NOTSUPPORTED; 2661 if (alarm->Location != 1) return ERR_NOTSUPPORTED;
2656 2662
2657 req[14] = alarm->DateTime.Hour; 2663 req[14] = alarm->DateTime.Hour;
2658 req[15] = alarm->DateTime.Minute; 2664 req[15] = alarm->DateTime.Minute;
2659 2665
2660 smprintf(s, "Setting alarm\n"); 2666 smprintf(s, "Setting alarm\n");
2661 return GSM_WaitFor (s, req, 19, 0x19, 4, ID_SetAlarm); 2667 return GSM_WaitFor (s, req, 19, 0x19, 4, ID_SetAlarm);
2662} 2668}
2663 2669
2664static GSM_Error N6510_ReplyGetRingtonesInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 2670static GSM_Error N6510_ReplyGetRingtonesInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
2665{ 2671{
2666 int tmp,i; 2672 int tmp,i;
2667 GSM_Phone_Data *Data = &s->Phone.Data; 2673 GSM_Phone_Data *Data = &s->Phone.Data;
2668 2674
2669 smprintf(s, "Ringtones info received\n"); 2675 smprintf(s, "Ringtones info received\n");
2670 memset(Data->RingtonesInfo,0,sizeof(GSM_AllRingtonesInfo)); 2676 memset(Data->RingtonesInfo,0,sizeof(GSM_AllRingtonesInfo));
2671 if (msg.Buffer[4] * 256 + msg.Buffer[5] == 0x00) return ERR_EMPTY; 2677 if (msg.Buffer[4] * 256 + msg.Buffer[5] == 0x00) return ERR_EMPTY;
2672 Data->RingtonesInfo->Number = msg.Buffer[4] * 256 + msg.Buffer[5]; 2678 Data->RingtonesInfo->Number = msg.Buffer[4] * 256 + msg.Buffer[5];
2673 tmp = 6; 2679 tmp = 6;
2674 for (i=0;i<Data->RingtonesInfo->Number;i++) { 2680 for (i=0;i<Data->RingtonesInfo->Number;i++) {
2675 Data->RingtonesInfo->Ringtone[i].Group = msg.Buffer[tmp+4]; 2681 Data->RingtonesInfo->Ringtone[i].Group = msg.Buffer[tmp+4];
2676 Data->RingtonesInfo->Ringtone[i].ID = msg.Buffer[tmp+2] * 256 + msg.Buffer[tmp+3]; 2682 Data->RingtonesInfo->Ringtone[i].ID = msg.Buffer[tmp+2] * 256 + msg.Buffer[tmp+3];
2677 memcpy(Data->RingtonesInfo->Ringtone[i].Name,msg.Buffer+tmp+8,(msg.Buffer[tmp+6]*256+msg.Buffer[tmp+7])*2); 2683 memcpy(Data->RingtonesInfo->Ringtone[i].Name,msg.Buffer+tmp+8,(msg.Buffer[tmp+6]*256+msg.Buffer[tmp+7])*2);
2678 smprintf(s, "%5i (%5i). \"%s\"\n", 2684 smprintf(s, "%5i (%5i). \"%s\"\n",
2679 Data->RingtonesInfo->Ringtone[i].ID, 2685 Data->RingtonesInfo->Ringtone[i].ID,
2680 Data->RingtonesInfo->Ringtone[i].Group, 2686 Data->RingtonesInfo->Ringtone[i].Group,
2681 DecodeUnicodeString(Data->RingtonesInfo->Ringtone[i].Name)); 2687 DecodeUnicodeString(Data->RingtonesInfo->Ringtone[i].Name));
2682 tmp = tmp + (msg.Buffer[tmp]*256+msg.Buffer[tmp+1]); 2688 tmp = tmp + (msg.Buffer[tmp]*256+msg.Buffer[tmp+1]);
2683 } 2689 }
2684 return ERR_NONE; 2690 return ERR_NONE;
2685} 2691}
2686 2692
2687static GSM_Error N6510_PrivGetRingtonesInfo(GSM_StateMachine *s, GSM_AllRingtonesInfo *Info, bool AllRingtones) 2693static GSM_Error N6510_PrivGetRingtonesInfo(GSM_StateMachine *s, GSM_AllRingtonesInfo *Info, bool AllRingtones)
2688{ 2694{
2689 GSM_Errorerror; 2695 GSM_Errorerror;
2690 unsigned char UserReq[8] = {N7110_FRAME_HEADER, 0x07, 0x00, 0x00, 0x00, 0x02}; 2696 unsigned char UserReq[8] = {N7110_FRAME_HEADER, 0x07, 0x00, 0x00, 0x00, 0x02};
2691 // unsigned char All_Req[9] = {N7110_FRAME_HEADER, 0x07, 0x00, 0x00, 0xFE, 0x00, 0x7D}; 2697 // unsigned char All_Req[9] = {N7110_FRAME_HEADER, 0x07, 0x00, 0x00, 0xFE, 0x00, 0x7D};
2692 unsigned char All_Req[8] = {N7110_FRAME_HEADER, 0x07, 0x00, 0x00, 0x00, 0x00}; 2698 unsigned char All_Req[8] = {N7110_FRAME_HEADER, 0x07, 0x00, 0x00, 0x00, 0x00};
2693 2699
2694 s->Phone.Data.RingtonesInfo=Info; 2700 s->Phone.Data.RingtonesInfo=Info;
2695 smprintf(s, "Getting binary ringtones ID\n"); 2701 smprintf(s, "Getting binary ringtones ID\n");
2696 if (AllRingtones) { 2702 if (AllRingtones) {
2697 // error = GSM_WaitFor (s, All_Req, 9, 0x1f, 4, ID_GetRingtonesInfo); 2703 // error = GSM_WaitFor (s, All_Req, 9, 0x1f, 4, ID_GetRingtonesInfo);
2698 error = GSM_WaitFor (s, All_Req, 8, 0x1f, 4, ID_GetRingtonesInfo); 2704 error = GSM_WaitFor (s, All_Req, 8, 0x1f, 4, ID_GetRingtonesInfo);
2699 if (error == ERR_EMPTY && Info->Number == 0) return ERR_NOTSUPPORTED; 2705 if (error == ERR_EMPTY && Info->Number == 0) return ERR_NOTSUPPORTED;
2700 return error; 2706 return error;
2701 } else { 2707 } else {
2702 error = GSM_WaitFor (s, UserReq, 8, 0x1f, 4, ID_GetRingtonesInfo); 2708 error = GSM_WaitFor (s, UserReq, 8, 0x1f, 4, ID_GetRingtonesInfo);
2703 if (error == ERR_EMPTY && Info->Number == 0) return ERR_NOTSUPPORTED; 2709 if (error == ERR_EMPTY && Info->Number == 0) return ERR_NOTSUPPORTED;
2704 return error; 2710 return error;
2705 } 2711 }
2706} 2712}
2707 2713
2708static GSM_Error N6510_GetRingtonesInfo(GSM_StateMachine *s, GSM_AllRingtonesInfo *Info) 2714static GSM_Error N6510_GetRingtonesInfo(GSM_StateMachine *s, GSM_AllRingtonesInfo *Info)
2709{ 2715{
2710 return N6510_PrivGetRingtonesInfo(s, Info, true); 2716 return N6510_PrivGetRingtonesInfo(s, Info, true);
2711} 2717}
2712 2718
2713static GSM_Error N6510_ReplyGetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s) 2719static GSM_Error N6510_ReplyGetRingtone(GSM_Protocol_Message msg, GSM_StateMachine *s)
2714{ 2720{
2715 int tmp,i; 2721 int tmp,i;
2716 GSM_Phone_Data *Data = &s->Phone.Data; 2722 GSM_Phone_Data *Data = &s->Phone.Data;
2717 2723
2718 smprintf(s, "Ringtone received\n"); 2724 smprintf(s, "Ringtone received\n");
2719 memcpy(Data->Ringtone->Name,msg.Buffer+8,msg.Buffer[7]*2); 2725 memcpy(Data->Ringtone->Name,msg.Buffer+8,msg.Buffer[7]*2);
2720 Data->Ringtone->Name[msg.Buffer[7]*2]=0; 2726 Data->Ringtone->Name[msg.Buffer[7]*2]=0;
2721 Data->Ringtone->Name[msg.Buffer[7]*2+1]=0; 2727 Data->Ringtone->Name[msg.Buffer[7]*2+1]=0;
2722 smprintf(s, "Name \"%s\"\n",DecodeUnicodeString(Data->Ringtone->Name)); 2728 smprintf(s, "Name \"%s\"\n",DecodeUnicodeString(Data->Ringtone->Name));
2723 if (msg.Buffer[msg.Buffer[7]*2+10] == 'M' && 2729 if (msg.Buffer[msg.Buffer[7]*2+10] == 'M' &&
2724 msg.Buffer[msg.Buffer[7]*2+11] == 'T' && 2730 msg.Buffer[msg.Buffer[7]*2+11] == 'T' &&
2725 msg.Buffer[msg.Buffer[7]*2+12] == 'h' && 2731 msg.Buffer[msg.Buffer[7]*2+12] == 'h' &&
2726 msg.Buffer[msg.Buffer[7]*2+13] == 'd') { 2732 msg.Buffer[msg.Buffer[7]*2+13] == 'd') {
2727 smprintf(s,"MIDI\n"); 2733 smprintf(s,"MIDI\n");
2728 tmp = msg.Buffer[7]*2+10; 2734 tmp = msg.Buffer[7]*2+10;
2729 i = msg.Length - 2; /* ?????? */ 2735 i = msg.Length - 2; /* ?????? */
2730 Data->Ringtone->Format = RING_MIDI; 2736 Data->Ringtone->Format = RING_MIDI;
2731 } else { 2737 } else {
2732 /* Looking for end */ 2738 /* Looking for end */
2733 i=8+msg.Buffer[7]*2+3; 2739 i=8+msg.Buffer[7]*2+3;
2734 tmp = i; 2740 tmp = i;
2735 while (true) { 2741 while (true) {
2736 if (msg.Buffer[i]==0x07 && msg.Buffer[i+1]==0x0b) { 2742 if (msg.Buffer[i]==0x07 && msg.Buffer[i+1]==0x0b) {
2737 i=i+2; break; 2743 i=i+2; break;
2738 } 2744 }
2739 i++; 2745 i++;
2740 if (i==msg.Length) return ERR_EMPTY; 2746 if (i==msg.Length) return ERR_EMPTY;
2741 } 2747 }
2742 } 2748 }
2743 /* Copying frame */ 2749 /* Copying frame */
2744 memcpy(Data->Ringtone->NokiaBinary.Frame,msg.Buffer+tmp,i-tmp); 2750 memcpy(Data->Ringtone->NokiaBinary.Frame,msg.Buffer+tmp,i-tmp);
2745 Data->Ringtone->NokiaBinary.Length=i-tmp; 2751 Data->Ringtone->NokiaBinary.Length=i-tmp;
2746 return ERR_NONE; 2752 return ERR_NONE;
2747} 2753}
2748 2754
2749static GSM_Error N6510_GetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone) 2755static GSM_Error N6510_GetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, bool PhoneRingtone)
2750{ 2756{
2751 GSM_AllRingtonesInfo Info; 2757 GSM_AllRingtonesInfo Info;
2752 GSM_Error error; 2758 GSM_Error error;
2753 unsigned char req2[6] = {N7110_FRAME_HEADER, 0x12, 2759 unsigned char req2[6] = {N7110_FRAME_HEADER, 0x12,
2754 0x00, 0xe7}; /* Location */ 2760 0x00, 0xe7}; /* Location */
2755 2761
2756 if (Ringtone->Format == 0x00) Ringtone->Format = RING_NOKIABINARY; 2762 if (Ringtone->Format == 0x00) Ringtone->Format = RING_NOKIABINARY;
2757 2763
2758 switch (Ringtone->Format) { 2764 switch (Ringtone->Format) {
2759 case RING_NOTETONE: 2765 case RING_NOTETONE:
2760 /* In the future get binary and convert */ 2766 /* In the future get binary and convert */
2761 return ERR_NOTSUPPORTED; 2767 return ERR_NOTSUPPORTED;
2762 case RING_NOKIABINARY: 2768 case RING_NOKIABINARY:
2763 s->Phone.Data.Ringtone= Ringtone; 2769 s->Phone.Data.Ringtone= Ringtone;
2764 Info.Number = 0; 2770 Info.Number = 0;
2765 error=N6510_PrivGetRingtonesInfo(s, &Info, PhoneRingtone); 2771 error=N6510_PrivGetRingtonesInfo(s, &Info, PhoneRingtone);
2766 if (error != ERR_NONE) return error; 2772 if (error != ERR_NONE) return error;
2767 if (Ringtone->Location > Info.Number) return ERR_INVALIDLOCATION; 2773 if (Ringtone->Location > Info.Number) return ERR_INVALIDLOCATION;
2768 req2[4] = Info.Ringtone[Ringtone->Location-1].ID / 256; 2774 req2[4] = Info.Ringtone[Ringtone->Location-1].ID / 256;
2769 req2[5] = Info.Ringtone[Ringtone->Location-1].ID % 256; 2775 req2[5] = Info.Ringtone[Ringtone->Location-1].ID % 256;
2770 smprintf(s, "Getting binary ringtone\n"); 2776 smprintf(s, "Getting binary ringtone\n");
2771 return GSM_WaitFor (s, req2, 6, 0x1f, 4, ID_GetRingtone); 2777 return GSM_WaitFor (s, req2, 6, 0x1f, 4, ID_GetRingtone);
2772 case RING_MIDI: 2778 case RING_MIDI:
2779 case RING_MMF:
2773 return ERR_NOTSUPPORTED; 2780 return ERR_NOTSUPPORTED;
2774 } 2781 }
2775 return ERR_NOTSUPPORTED; 2782 return ERR_NOTSUPPORTED;
2776} 2783}
2777 2784
2778static GSM_Error N6510_PlayTone(GSM_StateMachine *s, int Herz, unsigned char Volume, bool start) 2785static GSM_Error N6510_PlayTone(GSM_StateMachine *s, int Herz, unsigned char Volume, bool start)
2779{ 2786{
2780 GSM_Error error; 2787 GSM_Error error;
2781 unsigned char reqStart[] = { 2788 unsigned char reqStart[] = {
2782 0x00,0x06,0x01,0x00,0x07,0x00 }; 2789 0x00,0x06,0x01,0x00,0x07,0x00 };
2783 unsigned char reqPlay[] = { 2790 unsigned char reqPlay[] = {
2784 0x00,0x06,0x01,0x14,0x05,0x04, 2791 0x00,0x06,0x01,0x14,0x05,0x04,
2785 0x00,0x00,0x00,0x03,0x03,0x08, 2792 0x00,0x00,0x00,0x03,0x03,0x08,
2786 0x00,0x00,0x00,0x01,0x00,0x00, 2793 0x00,0x00,0x00,0x01,0x00,0x00,
2787 0x03,0x08,0x01,0x00, 2794 0x03,0x08,0x01,0x00,
2788 0x07,0xd0,/*Frequency */ 2795 0x07,0xd0,/*Frequency */
2789 0x00,0x00,0x03,0x08,0x02,0x00,0x00, 2796 0x00,0x00,0x03,0x08,0x02,0x00,0x00,
2790 0x05, /*Volume */ 2797 0x05, /*Volume */
2791 0x00,0x00}; 2798 0x00,0x00};
2792 unsigned char reqOff[] = { 2799 unsigned char reqOff[] = {
2793 0x00,0x06,0x01,0x14,0x05,0x05, 2800 0x00,0x06,0x01,0x14,0x05,0x05,
2794 0x00,0x00,0x00,0x01,0x03,0x08, 2801 0x00,0x00,0x00,0x01,0x03,0x08,
2795 0x05,0x00,0x00,0x08,0x00,0x00}; 2802 0x05,0x00,0x00,0x08,0x00,0x00};
2796 // unsigned char reqOff2[] = { 2803 // unsigned char reqOff2[] = {
2797 // 0x00,0x06,0x01,0x14,0x05,0x04, 2804 // 0x00,0x06,0x01,0x14,0x05,0x04,
2798 // 0x00,0x00,0x00,0x01,0x03,0x08, 2805 // 0x00,0x00,0x00,0x01,0x03,0x08,
2799 // 0x00,0x00,0x00,0x00,0x00,0x00}; 2806 // 0x00,0x00,0x00,0x00,0x00,0x00};
2800 2807
2801 if (start) { 2808 if (start) {
2802 smprintf(s, "Enabling sound - part 1\n"); 2809 smprintf(s, "Enabling sound - part 1\n");
2803 error=GSM_WaitFor (s, reqStart, 6, 0x0b, 4, ID_PlayTone); 2810 error=GSM_WaitFor (s, reqStart, 6, 0x0b, 4, ID_PlayTone);
2804 if (error!=ERR_NONE) return error; 2811 if (error!=ERR_NONE) return error;
2805 smprintf(s, "Enabling sound - part 2 (disabling sound command)\n"); 2812 smprintf(s, "Enabling sound - part 2 (disabling sound command)\n");
2806 error=GSM_WaitFor (s, reqOff, 18, 0x0b, 4, ID_PlayTone); 2813 error=GSM_WaitFor (s, reqOff, 18, 0x0b, 4, ID_PlayTone);
2807 if (error!=ERR_NONE) return error; 2814 if (error!=ERR_NONE) return error;
2808 } 2815 }
2809 2816
2810 /* For Herz==255*255 we have silent */ 2817 /* For Herz==255*255 we have silent */
2811 if (Herz!=255*255) { 2818 if (Herz!=255*255) {
2812 reqPlay[23] = Herz%256; 2819 reqPlay[23] = Herz%256;
2813 reqPlay[22] = Herz/256; 2820 reqPlay[22] = Herz/256;
2814 reqPlay[31] = Volume; 2821 reqPlay[31] = Volume;
2815 smprintf(s, "Playing sound\n"); 2822 smprintf(s, "Playing sound\n");
2816 return GSM_WaitFor (s, reqPlay, 34, 0x0b, 4, ID_PlayTone); 2823 return GSM_WaitFor (s, reqPlay, 34, 0x0b, 4, ID_PlayTone);
2817 } else { 2824 } else {
2818 reqPlay[23] = 0; 2825 reqPlay[23] = 0;
2819 reqPlay[22] = 0; 2826 reqPlay[22] = 0;
2820 reqPlay[31] = 0; 2827 reqPlay[31] = 0;
2821 smprintf(s, "Playing silent sound\n"); 2828 smprintf(s, "Playing silent sound\n");
2822 return GSM_WaitFor (s, reqPlay, 34, 0x0b, 4, ID_PlayTone); 2829 return GSM_WaitFor (s, reqPlay, 34, 0x0b, 4, ID_PlayTone);
2823 2830
2824 // smprintf(s, "Disabling sound - part 1\n"); 2831 // smprintf(s, "Disabling sound - part 1\n");
2825 // error=GSM_WaitFor (s, reqOff, 18, 0x0b, 4, ID_PlayTone); 2832 // error=GSM_WaitFor (s, reqOff, 18, 0x0b, 4, ID_PlayTone);
2826 // if (error!=ERR_NONE) return error; 2833 // if (error!=ERR_NONE) return error;
2827 // smprintf(s, "Disabling sound - part 2\n"); 2834 // smprintf(s, "Disabling sound - part 2\n");
2828 // return GSM_WaitFor (s, reqOff2, 18, 0x0b, 4, ID_PlayTone); 2835 // return GSM_WaitFor (s, reqOff2, 18, 0x0b, 4, ID_PlayTone);
2829 } 2836 }
2830} 2837}
2831 2838
2832static GSM_Error N6510_ReplyGetPPM(GSM_Protocol_Message msg, GSM_StateMachine *s) 2839static GSM_Error N6510_ReplyGetPPM(GSM_Protocol_Message msg, GSM_StateMachine *s)
2833{ 2840{
2834 GSM_Phone_Data *Data = &s->Phone.Data; 2841 GSM_Phone_Data *Data = &s->Phone.Data;
2835 int pos = 6,len; 2842 int pos = 6,len;
2836 2843
2837 smprintf(s, "Received phone info\n"); 2844 smprintf(s, "Received phone info\n");
2838 2845
2839 while(pos < msg.Length) { 2846 while(pos < msg.Length) {
2840 if (msg.Buffer[pos] == 0x55 && msg.Buffer[pos+1] == 0x55) { 2847 if (msg.Buffer[pos] == 0x55 && msg.Buffer[pos+1] == 0x55) {
2841 while(1) { 2848 while(1) {
2842 if (msg.Buffer[pos] != 0x55) break; 2849 if (msg.Buffer[pos] != 0x55) break;
2843 pos++; 2850 pos++;
2844 } 2851 }
2845 } 2852 }
2846 len = pos; 2853 len = pos;
2847 while(1) { 2854 while(1) {
2848 if (msg.Buffer[len] == 0x00 && msg.Buffer[len+1] == 0x00) break; 2855 if (msg.Buffer[len] == 0x00 && msg.Buffer[len+1] == 0x00) break;
2849 len++; 2856 len++;
2850 } 2857 }
2851 while(1) { 2858 while(1) {
2852 if (msg.Buffer[len] != 0x00) break; 2859 if (msg.Buffer[len] != 0x00) break;
2853 len++; 2860 len++;
2854 } 2861 }
2855 len = len-pos; 2862 len = len-pos;
2856 smprintf(s, "Block with ID %02x",msg.Buffer[pos]); 2863 smprintf(s, "Block with ID %02x",msg.Buffer[pos]);
2857#ifdef DEBUG 2864#ifdef DEBUG
2858 if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) DumpMessage(di.df, di.dl, msg.Buffer+pos, len); 2865 if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) DumpMessage(di.df, di.dl, msg.Buffer+pos, len);
2859#endif 2866#endif
2860 switch (msg.Buffer[pos]) { 2867 switch (msg.Buffer[pos]) {
2861 case 0x49: 2868 case 0x49:
2862 smprintf(s, "hardware version\n"); 2869 smprintf(s, "hardware version\n");
2863 break; 2870 break;
2864 case 0x58: 2871 case 0x58:
2865 pos += 3; 2872 pos += 3;
2866 while (msg.Buffer[pos] != 0x00) pos++; 2873 while (msg.Buffer[pos] != 0x00) pos++;
2867 Data->PhoneString[0] = msg.Buffer[pos - 1]; 2874 Data->PhoneString[0] = msg.Buffer[pos - 1];
2868 Data->PhoneString[1] = 0x00; 2875 Data->PhoneString[1] = 0x00;
2869 smprintf(s, "PPM %s\n",Data->PhoneString); 2876 smprintf(s, "PPM %s\n",Data->PhoneString);
2870 return ERR_NONE; 2877 return ERR_NONE;
2871 default: 2878 default:
2872 break; 2879 break;
2873 } 2880 }
2874 pos += len; 2881 pos += len;
2875 } 2882 }
2876 return ERR_NOTSUPPORTED; 2883 return ERR_NOTSUPPORTED;
2877} 2884}
2878 2885
2879static GSM_Error N6510_GetPPM(GSM_StateMachine *s,char *value) 2886static GSM_Error N6510_GetPPM(GSM_StateMachine *s,char *value)
2880{ 2887{
2881 //unsigned char req[6] = {N6110_FRAME_HEADER, 0x07, 0x01, 0xff}; 2888 //unsigned char req[6] = {N6110_FRAME_HEADER, 0x07, 0x01, 0xff};
2882 unsigned char req[6] = {N6110_FRAME_HEADER, 0x07, 0x01, 0x00}; 2889 unsigned char req[6] = {N6110_FRAME_HEADER, 0x07, 0x01, 0x00};
2883 2890
2884 s->Phone.Data.PhoneString=value; 2891 s->Phone.Data.PhoneString=value;
2885 smprintf(s, "Getting PPM\n"); 2892 smprintf(s, "Getting PPM\n");
2886 return GSM_WaitFor (s, req, 6, 0x1b, 3, ID_GetPPM); 2893 return GSM_WaitFor (s, req, 6, 0x1b, 3, ID_GetPPM);
2887} 2894}
2888 2895
2889static GSM_Error N6510_GetSpeedDial(GSM_StateMachine *s, GSM_SpeedDial *SpeedDial) 2896static GSM_Error N6510_GetSpeedDial(GSM_StateMachine *s, GSM_SpeedDial *SpeedDial)
2890{ 2897{
2891 GSM_MemoryEntry pbk; 2898 GSM_MemoryEntry pbk;
2892 GSM_Error error; 2899 GSM_Error error;
2893 2900
2894 pbk.MemoryType = MEM7110_SP; 2901 pbk.MemoryType = MEM7110_SP;
2895 pbk.Location = SpeedDial->Location; 2902 pbk.Location = SpeedDial->Location;
2896 SpeedDial->MemoryLocation = 0; 2903 SpeedDial->MemoryLocation = 0;
2897 s->Phone.Data.SpeedDial = SpeedDial; 2904 s->Phone.Data.SpeedDial = SpeedDial;
2898 2905
2899 smprintf(s, "Getting speed dial\n"); 2906 smprintf(s, "Getting speed dial\n");
2900 error=N6510_GetMemory(s,&pbk); 2907 error=N6510_GetMemory(s,&pbk);
2901 switch (error) { 2908 switch (error) {
2902 case ERR_NOTSUPPORTED: 2909 case ERR_NOTSUPPORTED:
2903 smprintf(s, "No speed dials set in phone\n"); 2910 smprintf(s, "No speed dials set in phone\n");
2904 return ERR_EMPTY; 2911 return ERR_EMPTY;
2905 case ERR_NONE: 2912 case ERR_NONE:
2906 if (SpeedDial->MemoryLocation == 0) { 2913 if (SpeedDial->MemoryLocation == 0) {
2907 smprintf(s, "Speed dial not assigned or error in firmware\n"); 2914 smprintf(s, "Speed dial not assigned or error in firmware\n");
2908 return ERR_EMPTY; 2915 return ERR_EMPTY;
2909 } 2916 }
2910 return ERR_NONE; 2917 return ERR_NONE;
2911 default: 2918 default:
2912 return error; 2919 return error;
2913 } 2920 }
2914} 2921}
2915 2922
2916static GSM_Error N6510_ReplyGetProfile(GSM_Protocol_Message msg, GSM_StateMachine *s) 2923static GSM_Error N6510_ReplyGetProfile(GSM_Protocol_Message msg, GSM_StateMachine *s)
2917{ 2924{
2918 unsigned char *blockstart; 2925 unsigned char *blockstart;
2919 int i,j; 2926 int i,j;
2920 GSM_Phone_Data*Data = &s->Phone.Data; 2927 GSM_Phone_Data*Data = &s->Phone.Data;
2921 2928
2922 switch (msg.Buffer[3]) { 2929 switch (msg.Buffer[3]) {
2923 case 0x02: 2930 case 0x02:
2924 blockstart = msg.Buffer + 7; 2931 blockstart = msg.Buffer + 7;
2925 for (i = 0; i < 11; i++) { 2932 for (i = 0; i < 11; i++) {
2926 smprintf(s, "Profile feature %02x ",blockstart[1]); 2933 smprintf(s, "Profile feature %02x ",blockstart[1]);
2927#ifdef DEBUG 2934#ifdef DEBUG
2928 if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) DumpMessage(di.df, di.dl, blockstart, blockstart[0]); 2935 if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) DumpMessage(di.df, di.dl, blockstart, blockstart[0]);
2929#endif 2936#endif
2930 2937
2931 switch (blockstart[1]) { 2938 switch (blockstart[1]) {
2932 case 0x03: 2939 case 0x03:
2933 smprintf(s, "Ringtone ID\n"); 2940 smprintf(s, "Ringtone ID\n");
2934 Data->Profile->FeatureID[Data->Profile->FeaturesNumber] = Profile_RingtoneID; 2941 Data->Profile->FeatureID[Data->Profile->FeaturesNumber] = Profile_RingtoneID;
2935 Data->Profile->FeatureValue[Data->Profile->FeaturesNumber] = blockstart[7]; 2942 Data->Profile->FeatureValue[Data->Profile->FeaturesNumber] = blockstart[7];
2936 if (blockstart[7] == 0x00) { 2943 if (blockstart[7] == 0x00) {
2937 Data->Profile->FeatureValue[Data->Profile->FeaturesNumber] = blockstart[10]; 2944 Data->Profile->FeatureValue[Data->Profile->FeaturesNumber] = blockstart[10];
2938 } 2945 }
2939 Data->Profile->FeaturesNumber++; 2946 Data->Profile->FeaturesNumber++;
2940 break; 2947 break;
2941 case 0x05:/* SMS tone */ 2948 case 0x05:/* SMS tone */
2942 j = Data->Profile->FeaturesNumber; 2949 j = Data->Profile->FeaturesNumber;
2943 NOKIA_FindFeatureValue(s, Profile71_65,blockstart[1],blockstart[7],Data,false); 2950 NOKIA_FindFeatureValue(s, Profile71_65,blockstart[1],blockstart[7],Data,false);
2944 if (j == Data->Profile->FeaturesNumber) { 2951 if (j == Data->Profile->FeaturesNumber) {
2945 Data->Profile->FeatureID[Data->Profile->FeaturesNumber] = Profile_MessageTone; 2952 Data->Profile->FeatureID[Data->Profile->FeaturesNumber] = Profile_MessageTone;
2946 Data->Profile->FeatureValue[Data->Profile->FeaturesNumber] = PROFILE_MESSAGE_PERSONAL; 2953 Data->Profile->FeatureValue[Data->Profile->FeaturesNumber] = PROFILE_MESSAGE_PERSONAL;
2947 Data->Profile->FeaturesNumber++; 2954 Data->Profile->FeaturesNumber++;
2948 Data->Profile->FeatureID[Data->Profile->FeaturesNumber] = Profile_MessageToneID; 2955 Data->Profile->FeatureID[Data->Profile->FeaturesNumber] = Profile_MessageToneID;
2949 Data->Profile->FeatureValue[Data->Profile->FeaturesNumber] = blockstart[7]; 2956 Data->Profile->FeatureValue[Data->Profile->FeaturesNumber] = blockstart[7];
2950 Data->Profile->FeaturesNumber++; 2957 Data->Profile->FeaturesNumber++;
2951 } 2958 }
2952 break; 2959 break;
2953 case 0x08:/* Caller groups */ 2960 case 0x08:/* Caller groups */
2954 NOKIA_FindFeatureValue(s, Profile71_65,blockstart[1],blockstart[7],Data,true); 2961 NOKIA_FindFeatureValue(s, Profile71_65,blockstart[1],blockstart[7],Data,true);
2955 break; 2962 break;
2956 case 0x0c : 2963 case 0x0c :
2957 CopyUnicodeString(Data->Profile->Name,blockstart + 7); 2964 CopyUnicodeString(Data->Profile->Name,blockstart + 7);
2958 smprintf(s, "profile Name: \"%s\"\n", DecodeUnicodeString(Data->Profile->Name)); 2965 smprintf(s, "profile Name: \"%s\"\n", DecodeUnicodeString(Data->Profile->Name));
2959 Data->Profile->DefaultName = false; 2966 Data->Profile->DefaultName = false;
2960 break; 2967 break;
2961 default: 2968 default:
2962 NOKIA_FindFeatureValue(s, Profile71_65,blockstart[1],blockstart[7],Data,false); 2969 NOKIA_FindFeatureValue(s, Profile71_65,blockstart[1],blockstart[7],Data,false);
2963 } 2970 }
2964 blockstart = blockstart + blockstart[0]; 2971 blockstart = blockstart + blockstart[0];
2965 } 2972 }
2966 return ERR_NONE; 2973 return ERR_NONE;
2967 case 0x06: 2974 case 0x06:
2968 Data->Profile->Active = false; 2975 Data->Profile->Active = false;
2969 if (Data->Profile->Location == msg.Buffer[5]) Data->Profile->Active = true; 2976 if (Data->Profile->Location == msg.Buffer[5]) Data->Profile->Active = true;
2970 return ERR_NONE; 2977 return ERR_NONE;
2971 } 2978 }
2972 return ERR_UNKNOWNRESPONSE; 2979 return ERR_UNKNOWNRESPONSE;
2973} 2980}
2974 2981
2975static GSM_Error N6510_GetProfile(GSM_StateMachine *s, GSM_Profile *Profile) 2982static GSM_Error N6510_GetProfile(GSM_StateMachine *s, GSM_Profile *Profile)
2976{ 2983{
2977 unsigned char req[150] = {N6110_FRAME_HEADER, 0x01, 0x01, 0x0C, 0x01}; 2984 unsigned char req[150] = {N6110_FRAME_HEADER, 0x01, 0x01, 0x0C, 0x01};
2978 unsigned charreqActive[] = {N6110_FRAME_HEADER, 0x05}; 2985 unsigned charreqActive[] = {N6110_FRAME_HEADER, 0x05};
2979 int i, length = 7; 2986 int i, length = 7;
2980 GSM_Errorerror; 2987 GSM_Errorerror;
2981 2988
2982 /* For now !!! */ 2989 /* For now !!! */
2983 if (!strcmp(s->Phone.Data.ModelInfo->model,"3510")) { 2990 if (!strcmp(s->Phone.Data.ModelInfo->model,"3510")) {
2984 if (s->Phone.Data.VerNum>3.37) return ERR_NOTSUPPORTED; 2991 if (s->Phone.Data.VerNum>3.37) return ERR_NOTSUPPORTED;
2985 } 2992 }
2986 if (!strcmp(s->Phone.Data.ModelInfo->model,"6230")) { 2993 if (!strcmp(s->Phone.Data.ModelInfo->model,"6230")) {
2987 return ERR_NOTSUPPORTED; 2994 return ERR_NOTSUPPORTED;
2988 } 2995 }
2996 if (!strcmp(s->Phone.Data.ModelInfo->model,"5140")) {
2997 return ERR_NOTSUPPORTED;
2998 }
2989 2999
2990 if (Profile->Location>5) return ERR_INVALIDLOCATION; 3000 if (Profile->Location>5) return ERR_INVALIDLOCATION;
2991 3001
2992 for (i = 0; i < 0x0a; i++) { 3002 for (i = 0; i < 0x0a; i++) {
2993 req[length++] = 0x04; 3003 req[length++] = 0x04;
2994 req[length++] = Profile->Location; 3004 req[length++] = Profile->Location;
2995 req[length++] = i; 3005 req[length++] = i;
2996 req[length++] = 0x01; 3006 req[length++] = 0x01;
2997 } 3007 }
2998 3008
2999 req[length++] = 0x04; 3009 req[length++] = 0x04;
3000 req[length++] = Profile->Location; 3010 req[length++] = Profile->Location;
3001 req[length++] = 0x0c; 3011 req[length++] = 0x0c;
3002 req[length++] = 0x01; 3012 req[length++] = 0x01;
3003 3013
3004 req[length++] = 0x04; 3014 req[length++] = 0x04;
3005 3015
3006 Profile->CarKitProfile= false; 3016 Profile->CarKitProfile= false;
3007 Profile->HeadSetProfile= false; 3017 Profile->HeadSetProfile= false;
3008 3018
3009 Profile->FeaturesNumber = 0; 3019 Profile->FeaturesNumber = 0;
3010 3020
3011 s->Phone.Data.Profile=Profile; 3021 s->Phone.Data.Profile=Profile;
3012 smprintf(s, "Getting profile\n"); 3022 smprintf(s, "Getting profile\n");
3013 error = GSM_WaitFor (s, req, length, 0x39, 4, ID_GetProfile); 3023 error = GSM_WaitFor (s, req, length, 0x39, 4, ID_GetProfile);
3014 if (error != ERR_NONE) return error; 3024 if (error != ERR_NONE) return error;
3015 3025
3016 smprintf(s, "Checking, which profile is active\n"); 3026 smprintf(s, "Checking, which profile is active\n");
3017 return GSM_WaitFor (s, reqActive, 4, 0x39, 4, ID_GetProfile); 3027 return GSM_WaitFor (s, reqActive, 4, 0x39, 4, ID_GetProfile);
3018} 3028}
3019 3029
3020static GSM_Error N6510_ReplySetProfile(GSM_Protocol_Message msg, GSM_StateMachine *s) 3030static GSM_Error N6510_ReplySetProfile(GSM_Protocol_Message msg, GSM_StateMachine *s)
3021{ 3031{
3022 unsigned char *blockstart; 3032 unsigned char *blockstart;
3023 int i; 3033 int i;
3024 3034
3025 smprintf(s, "Response to profile writing received!\n"); 3035 smprintf(s, "Response to profile writing received!\n");
3026 3036
3027 blockstart = msg.Buffer + 6; 3037 blockstart = msg.Buffer + 6;
3028 for (i = 0; i < msg.Buffer[5]; i++) { 3038 for (i = 0; i < msg.Buffer[5]; i++) {
3029 switch (blockstart[2]) { 3039 switch (blockstart[2]) {
3030 case 0x00: smprintf(s, "keypad tone level"); break; 3040 case 0x00: smprintf(s, "keypad tone level"); break;
3031 case 0x02: smprintf(s, "call alert"); break; 3041 case 0x02: smprintf(s, "call alert"); break;
3032 case 0x03: smprintf(s, "ringtone"); break; 3042 case 0x03: smprintf(s, "ringtone"); break;
3033 case 0x04: smprintf(s, "ringtone volume"); break; 3043 case 0x04: smprintf(s, "ringtone volume"); break;
3034 case 0x05: smprintf(s, "SMS tone"); break; 3044 case 0x05: smprintf(s, "SMS tone"); break;
3035 case 0x06: smprintf(s, "vibration"); break; 3045 case 0x06: smprintf(s, "vibration"); break;
3036 case 0x07: smprintf(s, "warning tone level"); break; 3046 case 0x07: smprintf(s, "warning tone level"); break;
3037 case 0x08: smprintf(s, "caller groups"); break; 3047 case 0x08: smprintf(s, "caller groups"); break;
3038 case 0x09: smprintf(s, "automatic answer"); break; 3048 case 0x09: smprintf(s, "automatic answer"); break;
3039 case 0x0c: smprintf(s, "name"); break; 3049 case 0x0c: smprintf(s, "name"); break;
3040 default: 3050 default:
3041 smprintf(s, "Unknown block type %02x", blockstart[2]); 3051 smprintf(s, "Unknown block type %02x", blockstart[2]);
3042 break; 3052 break;
3043 } 3053 }
3044 if (msg.Buffer[4] == 0x00) { 3054 if (msg.Buffer[4] == 0x00) {
3045 smprintf(s, ": set OK\n"); 3055 smprintf(s, ": set OK\n");
3046 } else { 3056 } else {
3047 smprintf(s, ": setting error %i\n", msg.Buffer[4]); 3057 smprintf(s, ": setting error %i\n", msg.Buffer[4]);
3048 } 3058 }
3049 blockstart = blockstart + blockstart[1]; 3059 blockstart = blockstart + blockstart[1];
3050 } 3060 }
3051 return ERR_NONE; 3061 return ERR_NONE;
3052} 3062}
3053 3063
3054static GSM_Error N6510_SetProfile(GSM_StateMachine *s, GSM_Profile *Profile) 3064static GSM_Error N6510_SetProfile(GSM_StateMachine *s, GSM_Profile *Profile)
3055{ 3065{
3056 int i, length = 7, blocks = 0; 3066 int i, length = 7, blocks = 0;
3057 bool found; 3067 bool found;
3058 unsigned charID,Value; 3068 unsigned charID,Value;
3059 unsigned char req[150] = {N6110_FRAME_HEADER, 0x03, 0x01, 3069 unsigned char req[150] = {N6110_FRAME_HEADER, 0x03, 0x01,
3060 0x06, /* Number of blocks */ 3070 0x06, /* Number of blocks */
3061 0x03}; 3071 0x03};
3062 3072
3063 if (Profile->Location>5) return ERR_INVALIDLOCATION; 3073 if (Profile->Location>5) return ERR_INVALIDLOCATION;
3064 3074
3065 for (i=0;i<Profile->FeaturesNumber;i++) { 3075 for (i=0;i<Profile->FeaturesNumber;i++) {
3066 found = false; 3076 found = false;
3067 switch (Profile->FeatureID[i]) { 3077 switch (Profile->FeatureID[i]) {
3068 case Profile_RingtoneID: 3078 case Profile_RingtoneID:
3069 ID = 0x03; 3079 ID = 0x03;
3070 Value = Profile->FeatureValue[i]; 3080 Value = Profile->FeatureValue[i];
3071 found = true; 3081 found = true;
3072 break; 3082 break;
3073 default: 3083 default:
3074 found=NOKIA_FindPhoneFeatureValue( 3084 found=NOKIA_FindPhoneFeatureValue(
3075 s, 3085 s,
3076 Profile71_65, 3086 Profile71_65,
3077 Profile->FeatureID[i],Profile->FeatureValue[i], 3087 Profile->FeatureID[i],Profile->FeatureValue[i],
3078 &ID,&Value); 3088 &ID,&Value);
3079 } 3089 }
3080 if (found) { 3090 if (found) {
3081 req[length] = 0x09; 3091 req[length] = 0x09;
3082 req[length + 1] = ID; 3092 req[length + 1] = ID;
3083 req[length + 2] = Profile->Location; 3093 req[length + 2] = Profile->Location;
3084 memcpy(req + length + 4, "\x00\x00\x01", 3); 3094 memcpy(req + length + 4, "\x00\x00\x01", 3);
3085 req[length + 8] = 0x03; 3095 req[length + 8] = 0x03;
3086 req[length + 3] = req[length + 7] = Value; 3096 req[length + 3] = req[length + 7] = Value;
3087 blocks++; 3097 blocks++;
3088 length += 9; 3098 length += 9;
3089 } 3099 }
3090 } 3100 }
3091 3101
3092 smprintf(s, "Setting profile\n"); 3102 smprintf(s, "Setting profile\n");
3093 return GSM_WaitFor (s, req, length, 0x39, 4, ID_SetProfile); 3103 return GSM_WaitFor (s, req, length, 0x39, 4, ID_SetProfile);
3094} 3104}
3095 3105
3096static GSM_Error N6510_ReplyIncomingSMS(GSM_Protocol_Message msg, GSM_StateMachine *s) 3106static GSM_Error N6510_ReplyIncomingSMS(GSM_Protocol_Message msg, GSM_StateMachine *s)
3097{ 3107{
3098 GSM_SMSMessage sms; 3108 GSM_SMSMessage sms;
3099 3109
3100#ifdef DEBUG 3110#ifdef DEBUG
3101 smprintf(s, "SMS message received\n"); 3111 smprintf(s, "SMS message received\n");
3102 N6510_DecodeSMSFrame(s, &sms, msg.Buffer+10); 3112 N6510_DecodeSMSFrame(s, &sms, msg.Buffer+10);
3103#endif 3113#endif
3104 3114
3105 if (s->Phone.Data.EnableIncomingSMS && s->User.IncomingSMS!=NULL) { 3115 if (s->Phone.Data.EnableIncomingSMS && s->User.IncomingSMS!=NULL) {
3106 sms.State = SMS_UnRead; 3116 sms.State = SMS_UnRead;
3107 sms.InboxFolder = true; 3117 sms.InboxFolder = true;
3108 3118
3109 N6510_DecodeSMSFrame(s, &sms, msg.Buffer+10); 3119 N6510_DecodeSMSFrame(s, &sms, msg.Buffer+10);
3110 3120
3111 s->User.IncomingSMS(s->CurrentConfig->Device,sms); 3121 s->User.IncomingSMS(s->CurrentConfig->Device,sms);
3112 } 3122 }
3113 return ERR_NONE; 3123 return ERR_NONE;
3114} 3124}
3115 3125
3116static GSM_Error N6510_DialVoice(GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber) 3126static GSM_Error N6510_DialVoice(GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber)
3117{ 3127{
3128 unsigned int pos2 = 15;
3118 unsigned intpos = 4; 3129 unsigned intpos = 4;
3130 unsigned char req2[100] = {N6110_FRAME_HEADER,0x01,
3131 0x00,0x02,0x07,0x04,
3132 0x01, // 1 - voice, 2 - data
3133 0x00,0x03,
3134 0x18, // length of rest + 1
3135 0x00,0x00,0x00};
3119 unsigned char req[100] = {N6110_FRAME_HEADER,0x01, 3136 unsigned char req[100] = {N6110_FRAME_HEADER,0x01,
3120 0x0c};/* Number length */ 3137 0x0c};/* Number length */
3138 GSM_Errorerror;
3139
3140 /* USSD not supported */
3141 if (number[0] == '*') return ERR_NOTSUPPORTED;
3142 if (number[0] == '#') return ERR_NOTSUPPORTED;
3121 3143
3122 req[pos++] = strlen(number); 3144 req[pos++] = strlen(number);
3123 EncodeUnicode(req+pos,number,strlen(number)); 3145 EncodeUnicode(req+pos,number,strlen(number));
3124 pos += strlen(number)*2; 3146 pos += strlen(number)*2;
3125 req[pos++] = 0x05; /* call type: voice - 0x05, data - 0x01 */ 3147 req[pos++] = 0x05; /* call type: voice - 0x05, data - 0x01 */
3126 req[pos++] = 0x01; 3148 req[pos++] = 0x01;
3127 req[pos++] = 0x05; 3149 req[pos++] = 0x05;
3128 req[pos++] = 0x00; 3150 req[pos++] = 0x00;
3129 req[pos++] = 0x02; 3151 req[pos++] = 0x02;
3130 req[pos++] = 0x00; 3152 req[pos++] = 0x00;
3131 req[pos++] = 0x00; 3153 req[pos++] = 0x00;
3132 switch (ShowNumber) { 3154 switch (ShowNumber) {
3133 case GSM_CALL_HideNumber: 3155 case GSM_CALL_HideNumber:
3134 req[pos++] = 0x02; 3156 req[pos++] = 0x02;
3135 break; 3157 break;
3136 case GSM_CALL_ShowNumber: 3158 case GSM_CALL_ShowNumber:
3137 req[pos++] = 0x03; 3159 req[pos++] = 0x03;
3138 break; 3160 break;
3139 case GSM_CALL_DefaultNumberPresence: 3161 case GSM_CALL_DefaultNumberPresence:
3140 req[pos++] = 0x01; 3162 req[pos++] = 0x01;
3141 break; 3163 break;
3142 } 3164 }
3165 smprintf(s, "Making voice call\n");
3166 error = GSM_WaitFor (s, req, pos, 0x01, 4, ID_DialVoice);
3167 if (error != ERR_NOTSUPPORTED) return error;
3168
3169 if (ShowNumber != GSM_CALL_DefaultNumberPresence) return ERR_NOTSUPPORTED;
3170
3171 req2[11] = strlen(number)*2+6;
3172 req2[pos2++] = strlen(number);
3173 EncodeUnicode(req2+pos2,number,strlen(number));
3174 pos2 += strlen(number)*2;
3143 3175
3144 smprintf(s, "Making voice call\n"); 3176 smprintf(s, "Making voice call\n");
3145 return GSM_WaitFor (s, req, pos, 0x01, 4, ID_DialVoice); 3177 error = GSM_WaitFor (s, req2, pos2, 0x01, 4, ID_DialVoice);
3178 if (error == ERR_NOTSUPPORTED) return ERR_NONE;
3179 return error;
3146} 3180}
3147 3181
3148/* method 3 */ 3182/* method 3 */
3149static GSM_Error N6510_ReplyGetCalendarInfo3(GSM_Protocol_Message msg, GSM_StateMachine *s, GSM_NOKIACalToDoLocations *Last) 3183static GSM_Error N6510_ReplyGetCalendarInfo3(GSM_Protocol_Message msg, GSM_StateMachine *s, GSM_NOKIACalToDoLocations *Last)
3150{ 3184{
3151 int i=0,j=0; 3185 int i=0,j=0;
3152 3186
3153 while (Last->Location[j] != 0x00) j++; 3187 while (Last->Location[j] != 0x00) j++;
3154 if (j >= GSM_MAXCALENDARTODONOTES) { 3188 if (j >= GSM_MAXCALENDARTODONOTES) {
3155 smprintf(s, "Increase GSM_MAXCALENDARTODONOTES\n"); 3189 smprintf(s, "Increase GSM_MAXCALENDARTODONOTES\n");
3156 return ERR_UNKNOWN; 3190 return ERR_UNKNOWN;
3157 } 3191 }
3158 if (j == 0) { 3192 if (j == 0) {
3159 Last->Number=msg.Buffer[8]*256+msg.Buffer[9]; 3193 Last->Number=msg.Buffer[8]*256+msg.Buffer[9];
3160 smprintf(s, "Number of Entries: %i\n",Last->Number); 3194 smprintf(s, "Number of Entries: %i\n",Last->Number);
3161 } 3195 }
3162 smprintf(s, "Locations: "); 3196 smprintf(s, "Locations: ");
3163 while (14+(i*4) <= msg.Length) { 3197 while (14+(i*4) <= msg.Length) {
3164 Last->Location[j++]=msg.Buffer[12+i*4]*256+msg.Buffer[13+i*4]; 3198 Last->Location[j++]=msg.Buffer[12+i*4]*256+msg.Buffer[13+i*4];
3165 smprintf(s, "%i ",Last->Location[j-1]); 3199 smprintf(s, "%i ",Last->Location[j-1]);
3166 i++; 3200 i++;
3167 } 3201 }
3168 smprintf(s, "\nNumber of Entries in frame: %i\n",i); 3202 smprintf(s, "\nNumber of Entries in frame: %i\n",i);
3169 Last->Location[j] = 0; 3203 Last->Location[j] = 0;
3170 smprintf(s, "\n"); 3204 smprintf(s, "\n");
3171 if (i == 1 && msg.Buffer[12+0*4]*256+msg.Buffer[13+0*4] == 0) return ERR_EMPTY; 3205 if (i == 1 && msg.Buffer[12+0*4]*256+msg.Buffer[13+0*4] == 0) return ERR_EMPTY;
3172 if (i == 0) return ERR_EMPTY; 3206 if (i == 0) return ERR_EMPTY;
3173 return ERR_NONE; 3207 return ERR_NONE;
3174} 3208}
3175 3209
3176/* method 3 */ 3210/* method 3 */
3177static GSM_Error N6510_GetCalendarInfo3(GSM_StateMachine *s, GSM_NOKIACalToDoLocations *Last, bool Calendar) 3211static GSM_Error N6510_GetCalendarInfo3(GSM_StateMachine *s, GSM_NOKIACalToDoLocations *Last, char Type)
3178{ 3212{
3179 GSM_Error error; 3213 GSM_Error error = ERR_UNKNOWN;
3180 int i; 3214 int i;
3181 unsigned char req[] = {N6110_FRAME_HEADER, 0x9E, 0xFF, 0xFF, 0x00, 0x00, 3215 unsigned char req[] = {N6110_FRAME_HEADER, 0x9E, 0xFF, 0xFF, 0x00, 0x00,
3182 0x00, 0x00,/* First location */ 3216 0x00, 0x00,/* First location */
3183 0x00}; /* 0 = calendar, 1 = ToDo in 6610 style */ 3217 0x00}; /* 0 = calendar, 1 = ToDo in 6610 style, 2 = Notes */
3184 3218
3185 Last->Location[0] = 0x00; 3219 Last->Location[0] = 0x00;
3186 Last->Number = 0; 3220 Last->Number = 0;
3187 3221
3188 if (Calendar) { 3222 req[10] = Type;
3223 if (Type == 0) {
3189 smprintf(s, "Getting locations for calendar method 3\n"); 3224 smprintf(s, "Getting locations for calendar method 3\n");
3190 error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetCalendarNotesInfo); 3225 error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetCalendarNotesInfo);
3191 } else { 3226 } else if (Type == 1) {
3192 req[10] = 0x01;
3193 smprintf(s, "Getting locations for ToDo method 2\n"); 3227 smprintf(s, "Getting locations for ToDo method 2\n");
3194 error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetToDo); 3228 error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetToDo);
3229 } else if (Type == 2) {
3230 smprintf(s, "Getting locations for Notes\n");
3231 error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetNote);
3195 } 3232 }
3196 if (error != ERR_NONE && error != ERR_EMPTY) return error; 3233 if (error != ERR_NONE && error != ERR_EMPTY) return error;
3197 3234
3198 while (1) { 3235 while (1) {
3199 i=0; 3236 i=0;
3200 while (Last->Location[i] != 0x00) i++; 3237 while (Last->Location[i] != 0x00) i++;
3201 smprintf(s, "i = %i %i\n",i,Last->Number); 3238 smprintf(s, "i = %i %i\n",i,Last->Number);
3202 if (i == Last->Number) break; 3239 if (i == Last->Number) break;
3203 if (i != Last->Number && error == ERR_EMPTY) { 3240 if (i != Last->Number && error == ERR_EMPTY) {
3204 smprintf(s, "Phone doesn't support some notes with this method. Workaround\n"); 3241 smprintf(s, "Phone doesn't support some notes with this method. Workaround\n");
3205 Last->Number = i; 3242 Last->Number = i;
3206 break; 3243 break;
3207 } 3244 }
3208 req[8] = Last->Location[i-1] / 256; 3245 req[8] = Last->Location[i-1] / 256;
3209 req[9] = Last->Location[i-1] % 256; 3246 req[9] = Last->Location[i-1] % 256;
3210 if (Calendar) { 3247 if (Type == 0) {
3211 smprintf(s, "Getting locations for calendar method 3\n"); 3248 smprintf(s, "Getting locations for calendar method 3\n");
3212 error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetCalendarNotesInfo); 3249 error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetCalendarNotesInfo);
3213 } else { 3250 } else if (Type == 1) {
3214 smprintf(s, "Getting locations for todo method 2\n"); 3251 smprintf(s, "Getting locations for todo method 2\n");
3215 error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetToDo); 3252 error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetToDo);
3253 } else if (Type == 2) {
3254 smprintf(s, "Getting locations for Notes\n");
3255 error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetNote);
3216 } 3256 }
3217 if (error != ERR_NONE && error != ERR_EMPTY) return error; 3257 if (error != ERR_NONE && error != ERR_EMPTY) return error;
3218 } 3258 }
3219 return ERR_NONE; 3259 return ERR_NONE;
3220} 3260}
3221 3261
3222/* method 3 */ 3262/* method 3 */
3223GSM_Error N6510_ReplyGetCalendar3(GSM_Protocol_Message msg, GSM_StateMachine *s) 3263GSM_Error N6510_ReplyGetCalendar3(GSM_Protocol_Message msg, GSM_StateMachine *s)
3224{ 3264{
3225 GSM_CalendarEntry *entry = s->Phone.Data.Cal; 3265 GSM_CalendarEntry *entry = s->Phone.Data.Cal;
3226 GSM_DateTime Date; 3266 GSM_DateTime Date;
3227 unsigned long diff; 3267 unsigned long diff;
3228 int i; 3268 int i;
3229 bool found = false; 3269 bool found = false;
3230 GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510; 3270 GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
3231 3271
3232 smprintf(s, "Calendar note received method 3\n"); 3272 smprintf(s, "Calendar note received method 3\n");
3233 3273
3234 smprintf(s,"Note type %02i: ",msg.Buffer[27]); 3274 smprintf(s,"Note type %02i: ",msg.Buffer[27]);
3235 switch(msg.Buffer[27]) { 3275 switch(msg.Buffer[27]) {
3236 case 0x00: smprintf(s,"Reminder\n"); entry->Type = GSM_CAL_REMINDER; break; 3276 case 0x00: smprintf(s,"Reminder\n"); entry->Type = GSM_CAL_REMINDER; break;
3237 case 0x01: smprintf(s,"Meeting\n"); entry->Type = GSM_CAL_MEETING; break; 3277 case 0x01: smprintf(s,"Meeting\n"); entry->Type = GSM_CAL_MEETING; break;
3238 case 0x02: smprintf(s,"Call\n"); entry->Type = GSM_CAL_CALL; break; 3278 case 0x02: smprintf(s,"Call\n"); entry->Type = GSM_CAL_CALL; break;
3239 case 0x04: smprintf(s,"Birthday\n"); entry->Type = GSM_CAL_BIRTHDAY; break; 3279 case 0x04: smprintf(s,"Birthday\n"); entry->Type = GSM_CAL_BIRTHDAY; break;
3240 case 0x08: smprintf(s,"Memo\n"); entry->Type = GSM_CAL_MEMO; break; 3280 case 0x08: smprintf(s,"Memo\n"); entry->Type = GSM_CAL_MEMO; break;
3241 default : smprintf(s,"unknown\n"); 3281 default : smprintf(s,"unknown\n");
3242 } 3282 }
3243 3283
3244 smprintf(s,"StartTime: %04i-%02i-%02i %02i:%02i\n", 3284 smprintf(s,"StartTime: %04i-%02i-%02i %02i:%02i\n",
3245 msg.Buffer[28]*256+msg.Buffer[29], 3285 msg.Buffer[28]*256+msg.Buffer[29],
3246 msg.Buffer[30],msg.Buffer[31],msg.Buffer[32], 3286 msg.Buffer[30],msg.Buffer[31],msg.Buffer[32],
3247 msg.Buffer[33]); 3287 msg.Buffer[33]);
3248 Date.Year = msg.Buffer[28]*256+msg.Buffer[29]; 3288 Date.Year = msg.Buffer[28]*256+msg.Buffer[29];
3249 if (entry->Type == GSM_CAL_BIRTHDAY) { 3289 if (entry->Type == GSM_CAL_BIRTHDAY) {
3250 Date.Year = entry->Entries[0].Date.Year; 3290 Date.Year = entry->Entries[0].Date.Year;
3251 smprintf(s,"%i\n",Date.Year); 3291 smprintf(s,"%i\n",Date.Year);
3252 } 3292 }
3253 Date.Month = msg.Buffer[30]; 3293 Date.Month = msg.Buffer[30];
3254 Date.Day = msg.Buffer[31]; 3294 Date.Day = msg.Buffer[31];
3255 Date.Hour = msg.Buffer[32]; 3295 Date.Hour = msg.Buffer[32];
3256 Date.Minute = msg.Buffer[33]; 3296 Date.Minute = msg.Buffer[33];
3257 /* Garbage seen with 3510i 3.51 */ 3297 /* Garbage seen with 3510i 3.51 */
3258 if (Date.Month == 0 && Date.Day == 0 && Date.Hour == 0 && Date.Minute == 0) return ERR_EMPTY; 3298 if (Date.Month == 0 && Date.Day == 0 && Date.Hour == 0 && Date.Minute == 0) return ERR_EMPTY;
3259 Date.Second= 0; 3299 Date.Second= 0;
3260 entry->Entries[0].EntryType = CAL_START_DATETIME; 3300 entry->Entries[0].EntryType = CAL_START_DATETIME;
3261 memcpy(&entry->Entries[0].Date,&Date,sizeof(GSM_DateTime)); 3301 memcpy(&entry->Entries[0].Date,&Date,sizeof(GSM_DateTime));
3262 entry->EntriesNum++; 3302 entry->EntriesNum++;
3263 3303
3264 if (entry->Type != GSM_CAL_BIRTHDAY) { 3304 if (entry->Type != GSM_CAL_BIRTHDAY) {
3265 smprintf(s,"EndTime: %04i-%02i-%02i %02i:%02i\n", 3305 smprintf(s,"EndTime: %04i-%02i-%02i %02i:%02i\n",
3266 msg.Buffer[34]*256+msg.Buffer[35], 3306 msg.Buffer[34]*256+msg.Buffer[35],
3267 msg.Buffer[36],msg.Buffer[37],msg.Buffer[38], 3307 msg.Buffer[36],msg.Buffer[37],msg.Buffer[38],
3268 msg.Buffer[39]); 3308 msg.Buffer[39]);
3269 Date.Year = msg.Buffer[34]*256+msg.Buffer[35]; 3309 Date.Year = msg.Buffer[34]*256+msg.Buffer[35];
3270 Date.Month = msg.Buffer[36]; 3310 Date.Month = msg.Buffer[36];
3271 Date.Day = msg.Buffer[37]; 3311 Date.Day = msg.Buffer[37];
3272 Date.Hour = msg.Buffer[38]; 3312 Date.Hour = msg.Buffer[38];
3273 Date.Minute = msg.Buffer[39]; 3313 Date.Minute = msg.Buffer[39];
3274 Date.Second= 0; 3314 Date.Second= 0;
3275 entry->Entries[1].EntryType = CAL_END_DATETIME; 3315 entry->Entries[1].EntryType = CAL_END_DATETIME;
3276 memcpy(&entry->Entries[1].Date,&Date,sizeof(GSM_DateTime)); 3316 memcpy(&entry->Entries[1].Date,&Date,sizeof(GSM_DateTime));
3277 entry->EntriesNum++; 3317 entry->EntriesNum++;
3278 } 3318 }
3279 3319
3280 smprintf(s, "Note icon: %02x\n",msg.Buffer[21]); 3320 smprintf(s, "Note icon: %02x\n",msg.Buffer[21]);
3281 for(i=0;i<Priv->CalendarIconsNum;i++) { 3321 for(i=0;i<Priv->CalendarIconsNum;i++) {
3282 if (Priv->CalendarIconsTypes[i] == entry->Type) { 3322 if (Priv->CalendarIconsTypes[i] == entry->Type) {
3283 found = true; 3323 found = true;
3284 } 3324 }
3285 } 3325 }
3286 if (!found) { 3326 if (!found) {
3287 Priv->CalendarIconsTypes[Priv->CalendarIconsNum] = entry->Type; 3327 Priv->CalendarIconsTypes[Priv->CalendarIconsNum] = entry->Type;
3288 Priv->CalendarIcons[Priv->CalendarIconsNum] = msg.Buffer[21]; 3328 Priv->CalendarIcons[Priv->CalendarIconsNum] = msg.Buffer[21];
3289 Priv->CalendarIconsNum++; 3329 Priv->CalendarIconsNum++;
3290 } 3330 }
3291 3331
3292 if (msg.Buffer[14] == 0xFF && msg.Buffer[15] == 0xFF && msg.Buffer[16] == 0xff && msg.Buffer[17] == 0xff) 3332 if (msg.Buffer[14] == 0xFF && msg.Buffer[15] == 0xFF && msg.Buffer[16] == 0xff && msg.Buffer[17] == 0xff)
3293 { 3333 {
3294 smprintf(s, "No alarm\n"); 3334 smprintf(s, "No alarm\n");
3295 } else { 3335 } else {
3296 diff = ((unsigned int)msg.Buffer[14]) << 24; 3336 diff = ((unsigned int)msg.Buffer[14]) << 24;
3297 diff += ((unsigned int)msg.Buffer[15]) << 16; 3337 diff += ((unsigned int)msg.Buffer[15]) << 16;
3298 diff += ((unsigned int)msg.Buffer[16]) << 8; 3338 diff += ((unsigned int)msg.Buffer[16]) << 8;
3299 diff += msg.Buffer[17]; 3339 diff += msg.Buffer[17];
3300 3340
3301 memcpy(&entry->Entries[entry->EntriesNum].Date,&entry->Entries[0].Date,sizeof(GSM_DateTime)); 3341 memcpy(&entry->Entries[entry->EntriesNum].Date,&entry->Entries[0].Date,sizeof(GSM_DateTime));
3302 GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, false, 60); 3342 GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, false, 60);
3303 smprintf(s, "Alarm date : %02i-%02i-%04i %02i:%02i:%02i\n", 3343 smprintf(s, "Alarm date : %02i-%02i-%04i %02i:%02i:%02i\n",
3304 entry->Entries[entry->EntriesNum].Date.Day, entry->Entries[entry->EntriesNum].Date.Month, 3344 entry->Entries[entry->EntriesNum].Date.Day, entry->Entries[entry->EntriesNum].Date.Month,
3305 entry->Entries[entry->EntriesNum].Date.Year, entry->Entries[entry->EntriesNum].Date.Hour, 3345 entry->Entries[entry->EntriesNum].Date.Year, entry->Entries[entry->EntriesNum].Date.Hour,
3306 entry->Entries[entry->EntriesNum].Date.Minute,entry->Entries[entry->EntriesNum].Date.Second); 3346 entry->Entries[entry->EntriesNum].Date.Minute,entry->Entries[entry->EntriesNum].Date.Second);
3307 3347
3308 entry->Entries[entry->EntriesNum].EntryType = CAL_ALARM_DATETIME; 3348 entry->Entries[entry->EntriesNum].EntryType = CAL_ALARM_DATETIME;
3309 if (msg.Buffer[22]==0x00 && msg.Buffer[23]==0x00 && 3349 if (msg.Buffer[22]==0x00 && msg.Buffer[23]==0x00 &&
3310 msg.Buffer[24]==0x00 && msg.Buffer[25]==0x00) 3350 msg.Buffer[24]==0x00 && msg.Buffer[25]==0x00)
3311 { 3351 {
3312 entry->Entries[entry->EntriesNum].EntryType = CAL_SILENT_ALARM_DATETIME; 3352 entry->Entries[entry->EntriesNum].EntryType = CAL_SILENT_ALARM_DATETIME;
3313 smprintf(s, "Alarm type : Silent\n"); 3353 smprintf(s, "Alarm type : Silent\n");
3314 } 3354 }
3315 entry->EntriesNum++; 3355 entry->EntriesNum++;
3316 } 3356 }
3317 3357
3318 N71_65_GetCalendarRecurrance(s, msg.Buffer+40, entry); 3358 N71_65_GetCalendarRecurrance(s, msg.Buffer+40, entry);
3319 3359
3320 if (entry->Type == GSM_CAL_BIRTHDAY) { 3360 if (entry->Type == GSM_CAL_BIRTHDAY) {
3321 if (msg.Buffer[42] == 0xff && msg.Buffer[43] == 0xff) { 3361 if (msg.Buffer[42] == 0xff && msg.Buffer[43] == 0xff) {
3322 entry->Entries[0].Date.Year = 0; 3362 entry->Entries[0].Date.Year = 0;
3323 } else { 3363 } else {
3324 entry->Entries[0].Date.Year = msg.Buffer[42]*256+msg.Buffer[43]; 3364 entry->Entries[0].Date.Year = msg.Buffer[42]*256+msg.Buffer[43];
3325 } 3365 }
3326 } 3366 }
3327 3367
3328 memcpy(entry->Entries[entry->EntriesNum].Text, msg.Buffer+54, msg.Buffer[51]*2); 3368 memcpy(entry->Entries[entry->EntriesNum].Text, msg.Buffer+54, msg.Buffer[51]*2);
3329 entry->Entries[entry->EntriesNum].Text[msg.Buffer[51]*2] = 0; 3369 entry->Entries[entry->EntriesNum].Text[msg.Buffer[51]*2] = 0;
3330 entry->Entries[entry->EntriesNum].Text[msg.Buffer[51]*2+1] = 0; 3370 entry->Entries[entry->EntriesNum].Text[msg.Buffer[51]*2+1] = 0;
3331 entry->Entries[entry->EntriesNum].EntryType = CAL_TEXT; 3371 entry->Entries[entry->EntriesNum].EntryType = CAL_TEXT;
3332 entry->EntriesNum++; 3372 entry->EntriesNum++;
3333 smprintf(s, "Note text: \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum-1].Text)); 3373 smprintf(s, "Note text: \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum-1].Text));
3334 3374
3335 if (entry->Type == GSM_CAL_CALL) { 3375 if (entry->Type == GSM_CAL_CALL) {
3336 memcpy(entry->Entries[entry->EntriesNum].Text, msg.Buffer+(54+msg.Buffer[51]*2), msg.Buffer[52]*2); 3376 memcpy(entry->Entries[entry->EntriesNum].Text, msg.Buffer+(54+msg.Buffer[51]*2), msg.Buffer[52]*2);
3337 entry->Entries[entry->EntriesNum].Text[msg.Buffer[52]*2] = 0; 3377 entry->Entries[entry->EntriesNum].Text[msg.Buffer[52]*2] = 0;
3338 entry->Entries[entry->EntriesNum].Text[msg.Buffer[52]*2+1] = 0; 3378 entry->Entries[entry->EntriesNum].Text[msg.Buffer[52]*2+1] = 0;
3339 entry->Entries[entry->EntriesNum].EntryType = CAL_PHONE; 3379 entry->Entries[entry->EntriesNum].EntryType = CAL_PHONE;
3340 entry->EntriesNum++; 3380 entry->EntriesNum++;
3341 } 3381 }
3342 if (entry->Type == GSM_CAL_MEETING) { 3382 if (entry->Type == GSM_CAL_MEETING) {
3343 memcpy(entry->Entries[entry->EntriesNum].Text, msg.Buffer+(54+msg.Buffer[51]*2), msg.Buffer[52]*2); 3383 memcpy(entry->Entries[entry->EntriesNum].Text, msg.Buffer+(54+msg.Buffer[51]*2), msg.Buffer[52]*2);
3344 entry->Entries[entry->EntriesNum].Text[msg.Buffer[52]*2] = 0; 3384 entry->Entries[entry->EntriesNum].Text[msg.Buffer[52]*2] = 0;
3345 entry->Entries[entry->EntriesNum].Text[msg.Buffer[52]*2+1] = 0; 3385 entry->Entries[entry->EntriesNum].Text[msg.Buffer[52]*2+1] = 0;
3346 entry->Entries[entry->EntriesNum].EntryType = CAL_LOCATION; 3386 entry->Entries[entry->EntriesNum].EntryType = CAL_LOCATION;
3347 entry->EntriesNum++; 3387 entry->EntriesNum++;
3348 } 3388 }
3349 3389
3350 return ERR_NONE; 3390 return ERR_NONE;
3351} 3391}
3352 3392
3393static GSM_Error N6510_PrivGetGenericCalendar3(GSM_StateMachine *s, int Location, GSM_Phone_RequestID ID)
3394{
3395 unsigned char req[] = {N6110_FRAME_HEADER,0x7D,0x00,0x00,0x00,0x00,
3396 0x00,0x99,/* Location */
3397 0xff,0xff,0xff,0xff};
3398
3399 req[8] = Location / 256;
3400 req[9] = Location % 256;
3401
3402 return GSM_WaitFor (s, req, 14, 0x13, 4, ID);
3403}
3404
3353static GSM_Error N6510_PrivGetCalendar3(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start, int *LastCalendarYear) 3405static GSM_Error N6510_PrivGetCalendar3(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start, int *LastCalendarYear)
3354{ 3406{
3355 GSM_Error error; 3407 GSM_Error error;
3356 GSM_DateTime date_time; 3408 GSM_DateTime date_time;
3357 unsigned char req[] = {N6110_FRAME_HEADER,0x7D,0x00,0x00,0x00,0x00,
3358 0x00,0x99,/* Location */
3359 0xff,0xff,0xff,0xff,0x01};
3360 3409
3361 if (start) { 3410 if (start) {
3362 /* We have to get current year. It's NOT written in frame for 3411 /* We have to get current year. It's NOT written in frame for
3363 * Birthday 3412 * Birthday
3364 */ 3413 */
3365 error=s->Phone.Functions->GetDateTime(s,&date_time); 3414 error=s->Phone.Functions->GetDateTime(s,&date_time);
3366 switch (error) { 3415 switch (error) {
3367 case ERR_EMPTY: 3416 case ERR_EMPTY:
3368 case ERR_NOTIMPLEMENTED: 3417 case ERR_NOTIMPLEMENTED:
3369 GSM_GetCurrentDateTime(&date_time); 3418 GSM_GetCurrentDateTime(&date_time);
3370 break; 3419 break;
3371 case ERR_NONE: 3420 case ERR_NONE:
3372 break; 3421 break;
3373 default: 3422 default:
3374 return error; 3423 return error;
3375 } 3424 }
3376 *LastCalendarYear = date_time.Year; 3425 *LastCalendarYear = date_time.Year;
3377 } 3426 }
3378 3427
3379 Note->EntriesNum = 0; 3428 Note->EntriesNum = 0;
3380 Note->Entries[0].Date.Year = *LastCalendarYear; 3429 Note->Entries[0].Date.Year = *LastCalendarYear;
3381 3430
3382 req[8] = Note->Location / 256;
3383 req[9] = Note->Location % 256;
3384
3385 s->Phone.Data.Cal=Note; 3431 s->Phone.Data.Cal=Note;
3386 smprintf(s, "Getting calendar note method 3\n"); 3432 smprintf(s, "Getting calendar note method 3\n");
3387 return GSM_WaitFor (s, req, 15, 0x13, 4, ID_GetCalendarNote); 3433 return N6510_PrivGetGenericCalendar3(s, Note->Location, ID_GetCalendarNote);
3388} 3434}
3389 3435
3390/* method 3 */ 3436/* method 3 */
3391GSM_Error N6510_GetNextCalendar3(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start, GSM_NOKIACalToDoLocations *LastCalendar, int *LastCalendarYear, int *LastCalendarPos) 3437GSM_Error N6510_GetNextCalendar3(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start, GSM_NOKIACalToDoLocations *LastCalendar, int *LastCalendarYear, int *LastCalendarPos)
3392{ 3438{
3393 GSM_Error error; 3439 GSM_Error error;
3394 bool start2; 3440 bool start2;
3395 3441
3396 if (start) { 3442 if (start) {
3397 error=N6510_GetCalendarInfo3(s,LastCalendar,true); 3443 error=N6510_GetCalendarInfo3(s,LastCalendar,0);
3398 if (error!=ERR_NONE) return error; 3444 if (error!=ERR_NONE) return error;
3399 if (LastCalendar->Number == 0) return ERR_EMPTY; 3445 if (LastCalendar->Number == 0) return ERR_EMPTY;
3400 3446
3401 *LastCalendarPos = 0; 3447 *LastCalendarPos = 0;
3402 } else { 3448 } else {
3403 (*LastCalendarPos)++; 3449 (*LastCalendarPos)++;
3404 } 3450 }
3405 3451
3406 error = ERR_EMPTY; 3452 error = ERR_EMPTY;
3407 start2 = start; 3453 start2 = start;
3408 while (error == ERR_EMPTY) { 3454 while (error == ERR_EMPTY) {
3409 if (*LastCalendarPos >= LastCalendar->Number) return ERR_EMPTY; 3455 if (*LastCalendarPos >= LastCalendar->Number) return ERR_EMPTY;
3410 3456
3411 Note->Location = LastCalendar->Location[*LastCalendarPos]; 3457 Note->Location = LastCalendar->Location[*LastCalendarPos];
3412 error=N6510_PrivGetCalendar3(s, Note, start2, LastCalendarYear); 3458 error=N6510_PrivGetCalendar3(s, Note, start2, LastCalendarYear);
3413 if (error == ERR_EMPTY) (*LastCalendarPos)++; 3459 if (error == ERR_EMPTY) (*LastCalendarPos)++;
3414 3460
3415 start2 = false; 3461 start2 = false;
3416 } 3462 }
3417 return error; 3463 return error;
3418} 3464}
3419 3465
3420static GSM_Error N6510_ReplyGetCalendarInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 3466static GSM_Error N6510_ReplyGetCalendarInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
3421{ 3467{
3422 switch (msg.Buffer[3]) { 3468 switch (msg.Buffer[3]) {
3423 case 0x3B: 3469 case 0x3B:
3424 /* Old method 1 for accessing calendar */ 3470 /* Old method 1 for accessing calendar */
3425 return N71_65_ReplyGetCalendarInfo1(msg, s, &s->Phone.Data.Priv.N6510.LastCalendar); 3471 return N71_65_ReplyGetCalendarInfo1(msg, s, &s->Phone.Data.Priv.N6510.LastCalendar);
3426 case 0x9F: 3472 case 0x9F:
3427 smprintf(s, "Info with calendar notes locations received method 3\n"); 3473 smprintf(s, "Info with calendar notes locations received method 3\n");
3428 return N6510_ReplyGetCalendarInfo3(msg, s, &s->Phone.Data.Priv.N6510.LastCalendar); 3474 return N6510_ReplyGetCalendarInfo3(msg, s, &s->Phone.Data.Priv.N6510.LastCalendar);
3429 } 3475 }
3430 return ERR_UNKNOWNRESPONSE; 3476 return ERR_UNKNOWNRESPONSE;
3431} 3477}
3432 3478
3433/* method 3 */ 3479/* method 3 */
3434GSM_Error N6510_ReplyGetCalendarNotePos3(GSM_Protocol_Message msg, GSM_StateMachine *s,int *FirstCalendarPos) 3480GSM_Error N6510_ReplyGetCalendarNotePos3(GSM_Protocol_Message msg, GSM_StateMachine *s,int *FirstCalendarPos)
3435{ 3481{
3436 smprintf(s, "First calendar location: %i\n",msg.Buffer[8]*256+msg.Buffer[9]); 3482 smprintf(s, "First calendar location: %i\n",msg.Buffer[8]*256+msg.Buffer[9]);
3437 *FirstCalendarPos = msg.Buffer[8]*256+msg.Buffer[9]; 3483 *FirstCalendarPos = msg.Buffer[8]*256+msg.Buffer[9];
3438 return ERR_NONE; 3484 return ERR_NONE;
3439} 3485}
3440 3486
3441/* method 3 */ 3487/* method 3 */
3442static GSM_Error N6510_GetCalendarNotePos3(GSM_StateMachine *s) 3488static GSM_Error N6510_GetCalendarNotePos3(GSM_StateMachine *s)
3443{ 3489{
3444 unsigned char req[] = {N6110_FRAME_HEADER, 0x95, 0x00}; 3490 unsigned char req[] = {N6110_FRAME_HEADER, 0x95, 0x00};
3445 3491
3446 smprintf(s, "Getting first free calendar note location\n"); 3492 smprintf(s, "Getting first free calendar note location\n");
3447 return GSM_WaitFor (s, req, 5, 0x13, 4, ID_GetCalendarNotePos); 3493 return GSM_WaitFor (s, req, 5, 0x13, 4, ID_GetCalendarNotePos);
3448} 3494}
3449 3495
3450static GSM_Error N6510_ReplyGetCalendarNotePos(GSM_Protocol_Message msg, GSM_StateMachine *s) 3496static GSM_Error N6510_ReplyGetCalendarNotePos(GSM_Protocol_Message msg, GSM_StateMachine *s)
3451{ 3497{
3452 switch (msg.Buffer[3]) { 3498 switch (msg.Buffer[3]) {
3453 case 0x32: 3499 case 0x32:
3454 /* Old method 1 for accessing calendar */ 3500 /* Old method 1 for accessing calendar */
3455 return N71_65_ReplyGetCalendarNotePos1(msg, s,&s->Phone.Data.Priv.N6510.FirstCalendarPos); 3501 return N71_65_ReplyGetCalendarNotePos1(msg, s,&s->Phone.Data.Priv.N6510.FirstCalendarPos);
3456 case 0x96: 3502 case 0x96:
3457 return N6510_ReplyGetCalendarNotePos3(msg, s,&s->Phone.Data.Priv.N6510.FirstCalendarPos); 3503 return N6510_ReplyGetCalendarNotePos3(msg, s,&s->Phone.Data.Priv.N6510.FirstCalendarPos);
3458 } 3504 }
3459 return ERR_UNKNOWNRESPONSE; 3505 return ERR_UNKNOWNRESPONSE;
3460} 3506}
3461 3507
3462static GSM_Error N6510_FindCalendarIconID3(GSM_StateMachine *s, GSM_CalendarEntry *Entry, unsigned char *ID) 3508static GSM_Error N6510_FindCalendarIconID3(GSM_StateMachine *s, GSM_CalendarEntry *Entry, unsigned char *ID)
3463{ 3509{
3464 int i,j,LastCalendarYear; 3510 int i,j,LastCalendarYear;
3465 GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510; 3511 GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
3466 GSM_CalendarEntry Note; 3512 GSM_CalendarEntry Note;
3467 GSM_NOKIACalToDoLocationsLastCalendar1,LastCalendar2; 3513 GSM_NOKIACalToDoLocationsLastCalendar1,LastCalendar2;
3468 GSM_Error error; 3514 GSM_Error error;
3469 bool found; 3515 bool found;
3470 3516
3471 for(i=0;i<Priv->CalendarIconsNum;i++) { 3517 for(i=0;i<Priv->CalendarIconsNum;i++) {
3472 if (Priv->CalendarIconsTypes[i] == Entry->Type) { 3518 if (Priv->CalendarIconsTypes[i] == Entry->Type) {
3473 *ID = Priv->CalendarIcons[i]; 3519 *ID = Priv->CalendarIcons[i];
3474 return ERR_NONE; 3520 return ERR_NONE;
3475 } 3521 }
3476 } 3522 }
3477 3523
3478 smprintf(s, "Starting finding note ID\n"); 3524 smprintf(s, "Starting finding note ID\n");
3479 3525
3480 error=N6510_GetCalendarInfo3(s, &Priv->LastCalendar,true); 3526 error=N6510_GetCalendarInfo3(s, &Priv->LastCalendar,0);
3481 memcpy(&LastCalendar1,&Priv->LastCalendar,sizeof(GSM_NOKIACalToDoLocations)); 3527 memcpy(&LastCalendar1,&Priv->LastCalendar,sizeof(GSM_NOKIACalToDoLocations));
3482 if (error != ERR_NONE) return error; 3528 if (error != ERR_NONE) return error;
3483 3529
3484 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL35) || 3530 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL35) ||
3485 IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL65) || 3531 IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL65) ||
3486 IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62)) { 3532 IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62)) {
3487 error=N71_65_AddCalendar2(s,Entry); 3533 error=N71_65_AddCalendar2(s,Entry);
3488 } else { 3534 } else {
3489 if (Entry->Type == GSM_CAL_MEETING) { 3535 if (Entry->Type == GSM_CAL_MEETING) {
3490 error=N71_65_AddCalendar1(s, Entry, &s->Phone.Data.Priv.N6510.FirstCalendarPos); 3536 error=N71_65_AddCalendar1(s, Entry, &s->Phone.Data.Priv.N6510.FirstCalendarPos);
3491 } else { 3537 } else {
3492 error=N71_65_AddCalendar2(s,Entry); 3538 error=N71_65_AddCalendar2(s,Entry);
3493 } 3539 }
3494 } 3540 }
3495 if (error != ERR_NONE) return error; 3541 if (error != ERR_NONE) return error;
3496 3542
3497 error=N6510_GetCalendarInfo3(s, &Priv->LastCalendar,true); 3543 error=N6510_GetCalendarInfo3(s, &Priv->LastCalendar,0);
3498 memcpy(&LastCalendar2,&Priv->LastCalendar,sizeof(GSM_NOKIACalToDoLocations)); 3544 memcpy(&LastCalendar2,&Priv->LastCalendar,sizeof(GSM_NOKIACalToDoLocations));
3499 if (error != ERR_NONE) return error; 3545 if (error != ERR_NONE) return error;
3500 3546
3501 smprintf(s,"Number of entries: %i %i\n",LastCalendar1.Number,LastCalendar2.Number); 3547 smprintf(s,"Number of entries: %i %i\n",LastCalendar1.Number,LastCalendar2.Number);
3502 3548
3503 for(i=0;i<LastCalendar2.Number;i++) { 3549 for(i=0;i<LastCalendar2.Number;i++) {
3504 found = true; 3550 found = true;
3505 for(j=0;j<LastCalendar1.Number;j++) { 3551 for(j=0;j<LastCalendar1.Number;j++) {
3506 if (LastCalendar1.Location[j] == LastCalendar2.Location[i]) { 3552 if (LastCalendar1.Location[j] == LastCalendar2.Location[i]) {
3507 found = false; 3553 found = false;
3508 break; 3554 break;
3509 } 3555 }
3510 } 3556 }
3511 if (found) { 3557 if (found) {
3512 Note.Location = LastCalendar2.Location[i]; 3558 Note.Location = LastCalendar2.Location[i];
3513 error=N6510_PrivGetCalendar3(s, &Note, true, &LastCalendarYear); 3559 error=N6510_PrivGetCalendar3(s, &Note, true, &LastCalendarYear);
3514 if (error != ERR_NONE) return error; 3560 if (error != ERR_NONE) return error;
3515 3561
3516 error=N71_65_DelCalendar(s, &Note); 3562 error=N71_65_DelCalendar(s, &Note);
3517 if (error != ERR_NONE) return error; 3563 if (error != ERR_NONE) return error;
3518 3564
3519 smprintf(s, "Ending finding note ID\n"); 3565 smprintf(s, "Ending finding note ID\n");
3520 3566
3521 for(j=0;j<Priv->CalendarIconsNum;j++) { 3567 for(j=0;j<Priv->CalendarIconsNum;j++) {
3522 if (Priv->CalendarIconsTypes[j] == Entry->Type) { 3568 if (Priv->CalendarIconsTypes[j] == Entry->Type) {
3523 *ID = Priv->CalendarIcons[j]; 3569 *ID = Priv->CalendarIcons[j];
3524 return ERR_NONE; 3570 return ERR_NONE;
3525 } 3571 }
3526 } 3572 }
3527 return ERR_UNKNOWN; 3573 return ERR_UNKNOWN;
3528 } 3574 }
3529 } 3575 }
3530 3576
3531 return ERR_UNKNOWN; 3577 return ERR_UNKNOWN;
3532} 3578}
3533 3579
3534/* method 3 */ 3580/* method 3 */
3535static GSM_Error N6510_ReplyAddCalendar3(GSM_Protocol_Message msg, GSM_StateMachine *s) 3581static GSM_Error N6510_ReplyAddCalendar3(GSM_Protocol_Message msg, GSM_StateMachine *s)
3536{ 3582{
3537 smprintf(s, "Calendar note added\n"); 3583 smprintf(s, "Calendar note added\n");
3538 return ERR_NONE; 3584 return ERR_NONE;
3539} 3585}
3540 3586
3541/* method 3 */ 3587/* method 3 */
3542GSM_Error N6510_AddCalendar3(GSM_StateMachine *s, GSM_CalendarEntry *Note, int *FirstCalendarPos) 3588GSM_Error N6510_AddCalendar3(GSM_StateMachine *s, GSM_CalendarEntry *Note, int *FirstCalendarPos)
3543{ 3589{
3544 GSM_CalendarNoteTypeNoteType, OldNoteType; 3590 GSM_CalendarNoteTypeNoteType, OldNoteType;
3545 time_t t_time1,t_time2; 3591 time_t t_time1,t_time2;
3546 long diff; 3592 long diff;
3547 GSM_Error error; 3593 GSM_Error error;
3548 GSM_DateTime DT,date_time; 3594 GSM_DateTime DT,date_time;
3549 int Text, Time, Alarm, Phone, Recurrance, EndTime, Location, count=54; 3595 int Text, Time, Alarm, Phone, Recurrance, EndTime, Location, count=54;
3550 unsigned char req[5000] = { 3596 unsigned char req[5000] = {
3551 N6110_FRAME_HEADER, 0x65, 3597 N6110_FRAME_HEADER, 0x65,
3552 0x00, /* 0 = calendar, 1 = todo */ 3598 0x00, /* 0 = calendar, 1 = todo */
3553 0x00, 0x00, 0x00, 3599 0x00, 0x00, 0x00,
3554 0x00, 0x00, /* location */ 3600 0x00, 0x00, /* location */
3555 0x00, 0x00, 0x00, 0x00, 3601 0x00, 0x00, 0x00, 0x00,
3556 0xFF, 0xFF, 0xFF, 0xFF, /* alarm */ 3602 0xFF, 0xFF, 0xFF, 0xFF, /* alarm */
3557 0x80, 0x00, 0x00, 3603 0x80, 0x00, 0x00,
3558 0x01, /* note icon */ 3604 0x01, /* note icon */
3559 0xFF, 0xFF, 0xFF, 0xFF, /* alarm type */ 3605 0xFF, 0xFF, 0xFF, 0xFF, /* alarm type */
3560 0x00, /* 0x02 or 0x00 */ 3606 0x00, /* 0x02 or 0x00 */
3561 0x01, /* note type */ 3607 0x01, /* note type */
3562 0x07, 0xD0, 0x01, 0x12, 0x0C, 0x00, /* start date/time */ 3608 0x07, 0xD0, 0x01, 0x12, 0x0C, 0x00, /* start date/time */
3563 0x07, 0xD0, 0x01, 0x12, 0x0C, 0x00, /* end date/time */ 3609 0x07, 0xD0, 0x01, 0x12, 0x0C, 0x00, /* end date/time */
3564 0x00, 0x00, /* recurrance */ 3610 0x00, 0x00, /* recurrance */
3565 0x00, 0x00, /* birth year */ 3611 0x00, 0x00, /* birth year */
3566 0x20, /* ToDo priority */ 3612 0x20, /* ToDo priority */
3567 0x00, /* ToDo completed ? */ 3613 0x00, /* ToDo completed ? */
3568 0x00, 0x00, 0x00, 3614 0x00, 0x00, 0x00,
3569 0x00, /* note text length */ 3615 0x00, /* note text length */
3570 0x00, /* phone length/meeting place*/ 3616 0x00, /* phone length/meeting place*/
3571 0x00, 0x00, 0x00}; 3617 0x00, 0x00, 0x00};
3572 3618
3573 error=N6510_GetCalendarNotePos3(s); 3619 error=N6510_GetCalendarNotePos3(s);
3574 if (error!=ERR_NONE) return error; 3620 if (error!=ERR_NONE) return error;
3575 req[8] = *FirstCalendarPos/256; 3621 req[8] = *FirstCalendarPos/256;
3576 req[9] = *FirstCalendarPos%256; 3622 req[9] = *FirstCalendarPos%256;
3577 3623
3578 NoteType = N71_65_FindCalendarType(Note->Type, s->Phone.Data.ModelInfo); 3624 NoteType = N71_65_FindCalendarType(Note->Type, s->Phone.Data.ModelInfo);
3579 3625
3580 switch(NoteType) { 3626 switch(NoteType) {
3581 case GSM_CAL_REMINDER : req[27]=0x00; req[26]=0x02; break; 3627 case GSM_CAL_REMINDER : req[27]=0x00; req[26]=0x02; break;
3582 case GSM_CAL_MEETING : req[27]=0x01; break; 3628 case GSM_CAL_MEETING : req[27]=0x01; break;
3583 case GSM_CAL_CALL : req[27]=0x02; break; 3629 case GSM_CAL_CALL : req[27]=0x02; break;
3584 case GSM_CAL_BIRTHDAY : req[27]=0x04; break; 3630 case GSM_CAL_BIRTHDAY : req[27]=0x04; break;
3585 case GSM_CAL_MEMO : req[27]=0x08; break; 3631 case GSM_CAL_MEMO : req[27]=0x08; break;
3586 default : return ERR_UNKNOWN; 3632 default : return ERR_UNKNOWN;
3587 } 3633 }
3588 3634
3589 OldNoteType = Note->Type; 3635 OldNoteType = Note->Type;
3590 Note->Type = NoteType; 3636 Note->Type = NoteType;
3591 error=N6510_FindCalendarIconID3(s, Note, &req[21]); 3637 error=N6510_FindCalendarIconID3(s, Note, &req[21]);
3592 Note->Type = OldNoteType; 3638 Note->Type = OldNoteType;
3593 if (error!=ERR_NONE) return error; 3639 if (error!=ERR_NONE) return error;
3594 3640
3595 GSM_CalendarFindDefaultTextTimeAlarmPhoneRecurrance(Note, &Text, &Time, &Alarm, &Phone, &Recurrance, &EndTime, &Location); 3641 GSM_CalendarFindDefaultTextTimeAlarmPhoneRecurrance(Note, &Text, &Time, &Alarm, &Phone, &Recurrance, &EndTime, &Location);
3596 3642
3597 if (Time == -1) return ERR_UNKNOWN; 3643 if (Time == -1) return ERR_UNKNOWN;
3598 memcpy(&DT,&Note->Entries[Time].Date,sizeof(GSM_DateTime)); 3644 memcpy(&DT,&Note->Entries[Time].Date,sizeof(GSM_DateTime));
3599 req[28]= DT.Year / 256; 3645 req[28]= DT.Year / 256;
3600 req[29]= DT.Year % 256; 3646 req[29]= DT.Year % 256;
3601 req[30]= DT.Month; 3647 req[30]= DT.Month;
3602 req[31]= DT.Day; 3648 req[31]= DT.Day;
3603 req[32]= DT.Hour; 3649 req[32]= DT.Hour;
3604 req[33]= DT.Minute; 3650 req[33]= DT.Minute;
3605 3651
3606 if (NoteType == GSM_CAL_BIRTHDAY) { 3652 if (NoteType == GSM_CAL_BIRTHDAY) {
3607 error=s->Phone.Functions->GetDateTime(s,&date_time); 3653 error=s->Phone.Functions->GetDateTime(s,&date_time);
3608 switch (error) { 3654 switch (error) {
3609 case ERR_EMPTY: 3655 case ERR_EMPTY:
3610 case ERR_NOTIMPLEMENTED: 3656 case ERR_NOTIMPLEMENTED:
3611 GSM_GetCurrentDateTime(&date_time); 3657 GSM_GetCurrentDateTime(&date_time);
3612 break; 3658 break;
3613 case ERR_NONE: 3659 case ERR_NONE:
3614 break; 3660 break;
3615 default: 3661 default:
3616 return error; 3662 return error;
3617 } 3663 }
3618 req[28]= date_time.Year / 256; 3664 req[28]= date_time.Year / 256;
3619 req[29] = date_time.Year % 256; 3665 req[29] = date_time.Year % 256;
3620 if (DT.Year == 0) { 3666 if (DT.Year == 0) {
3621 req[42]= 0xff; 3667 req[42]= 0xff;
3622 req[43]= 0xff; 3668 req[43]= 0xff;
3623 } else { 3669 } else {
3624 req[42]= DT.Year / 256; 3670 req[42]= DT.Year / 256;
3625 req[43]= DT.Year % 256; 3671 req[43]= DT.Year % 256;
3626 } 3672 }
3627 } 3673 }
3628 3674
3629 if (EndTime != -1) memcpy(&DT,&Note->Entries[EndTime].Date,sizeof(GSM_DateTime)); 3675 if (EndTime != -1) memcpy(&DT,&Note->Entries[EndTime].Date,sizeof(GSM_DateTime));
3630 req[34]= DT.Year / 256; 3676 req[34]= DT.Year / 256;
3631 req[35]= DT.Year % 256; 3677 req[35]= DT.Year % 256;
3632 req[36]= DT.Month; 3678 req[36]= DT.Month;
3633 req[37]= DT.Day; 3679 req[37]= DT.Day;
3634 req[38]= DT.Hour; 3680 req[38]= DT.Hour;
3635 req[39]= DT.Minute; 3681 req[39]= DT.Minute;
3636 if (NoteType == GSM_CAL_BIRTHDAY) { 3682 if (NoteType == GSM_CAL_BIRTHDAY) {
3637 req[34]= date_time.Year / 256; 3683 req[34]= date_time.Year / 256;
3638 req[35] = date_time.Year % 256; 3684 req[35] = date_time.Year % 256;
3639 } 3685 }
3640 3686
3641 if (Recurrance != -1) { 3687 if (Recurrance != -1) {
3642 /* max. 1 Year = 8760 hours */ 3688 /* max. 1 Year = 8760 hours */
3643 if (Note->Entries[Recurrance].Number >= 8760) { 3689 if (Note->Entries[Recurrance].Number >= 8760) {
3644 req[40] = 0xff; 3690 req[40] = 0xff;
3645 req[41] = 0xff; 3691 req[41] = 0xff;
3646 } else { 3692 } else {
3647 req[40] = Note->Entries[Recurrance].Number / 256; 3693 req[40] = Note->Entries[Recurrance].Number / 256;
3648 req[41] = Note->Entries[Recurrance].Number % 256; 3694 req[41] = Note->Entries[Recurrance].Number % 256;
3649 } 3695 }
3650 } 3696 }
3651 3697
3652 if (Alarm != -1) { 3698 if (Alarm != -1) {
3653 memcpy(&DT,&Note->Entries[Time].Date,sizeof(GSM_DateTime)); 3699 memcpy(&DT,&Note->Entries[Time].Date,sizeof(GSM_DateTime));
3654 if (Note->Entries[Alarm].EntryType == CAL_SILENT_ALARM_DATETIME) { 3700 if (Note->Entries[Alarm].EntryType == CAL_SILENT_ALARM_DATETIME) {
3655 req[22] = 0x00; req[23] = 0x00; req[24] = 0x00; req[25] = 0x00; 3701 req[22] = 0x00; req[23] = 0x00; req[24] = 0x00; req[25] = 0x00;
3656 } 3702 }
3657 if (NoteType == GSM_CAL_BIRTHDAY) DT.Year = date_time.Year; 3703 if (NoteType == GSM_CAL_BIRTHDAY) DT.Year = date_time.Year;
3658 t_time2 = Fill_Time_T(DT,8); 3704 t_time2 = Fill_Time_T(DT,8);
3659 t_time1 = Fill_Time_T(Note->Entries[Alarm].Date,8); 3705 t_time1 = Fill_Time_T(Note->Entries[Alarm].Date,8);
3660 diff = (t_time1-t_time2)/60; 3706 diff = (t_time1-t_time2)/60;
3661 3707
3662 smprintf(s, " Difference : %li seconds or minutes\n", -diff); 3708 smprintf(s, " Difference : %li seconds or minutes\n", -diff);
3663 req[14] = (unsigned char)(-diff >> 24); 3709 req[14] = (unsigned char)(-diff >> 24);
3664 req[15] = (unsigned char)(-diff >> 16); 3710 req[15] = (unsigned char)(-diff >> 16);
3665 req[16] = (unsigned char)(-diff >> 8); 3711 req[16] = (unsigned char)(-diff >> 8);
3666 req[17] = (unsigned char)(-diff); 3712 req[17] = (unsigned char)(-diff);
3667 } 3713 }
3668 3714
3669 if (Text != -1) { 3715 if (Text != -1) {
3670 req[49] = UnicodeLength(Note->Entries[Text].Text); 3716 req[49] = UnicodeLength(Note->Entries[Text].Text);
3671 CopyUnicodeString(req+54,Note->Entries[Text].Text); 3717 CopyUnicodeString(req+54,Note->Entries[Text].Text);
3672 count+= req[49]*2; 3718 count+= req[49]*2;
3673 } 3719 }
3674 3720
3675 if (Phone != -1 && NoteType == GSM_CAL_CALL) { 3721 if (Phone != -1 && NoteType == GSM_CAL_CALL) {
3676 req[50] = UnicodeLength(Note->Entries[Phone].Text); 3722 req[50] = UnicodeLength(Note->Entries[Phone].Text);
3677 CopyUnicodeString(req+54+req[49]*2,Note->Entries[Phone].Text); 3723 CopyUnicodeString(req+54+req[49]*2,Note->Entries[Phone].Text);
3678 count+= req[50]*2; 3724 count+= req[50]*2;
3679 } 3725 }
3680 3726
3681 if (Location != -1 && NoteType == GSM_CAL_MEETING) { 3727 if (Location != -1 && NoteType == GSM_CAL_MEETING) {
3682 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62) || 3728 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62) ||
3683 IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL65) || 3729 IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL65) ||
3684 IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL35)) { 3730 IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL35)) {
3685 } else { 3731 } else {
3686 req[50] = UnicodeLength(Note->Entries[Location].Text); 3732 req[50] = UnicodeLength(Note->Entries[Location].Text);
3687 CopyUnicodeString(req+54+req[49]*2,Note->Entries[Location].Text); 3733 CopyUnicodeString(req+54+req[49]*2,Note->Entries[Location].Text);
3688 count+= req[50]*2; 3734 count+= req[50]*2;
3689 } 3735 }
3690 } 3736 }
3691 3737
3692 req[count++] = 0x00; 3738 req[count++] = 0x00;
3693 3739
3694 smprintf(s, "Writing calendar note method 3\n"); 3740 smprintf(s, "Writing calendar note method 3\n");
3695 return GSM_WaitFor (s, req, count, 0x13, 4, ID_SetCalendarNote); 3741 return GSM_WaitFor (s, req, count, 0x13, 4, ID_SetCalendarNote);
3696} 3742}
3697 3743
3698static GSM_Error N6510_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start) 3744static GSM_Error N6510_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, bool start)
3699{ 3745{
3700#ifdef GSM_FORCE_DCT4_CALENDAR_6210 3746#ifdef GSM_FORCE_DCT4_CALENDAR_6210
3701 /* Method 1. Some features missed. Not working with some notes in 3510 */ 3747 /* Method 1. Some features missed. Not working with some notes in 3510 */
3702 return N71_65_GetNextCalendar1(s,Note,start,&s->Phone.Data.Priv.N6510.LastCalendar,&s->Phone.Data.Priv.N6510.LastCalendarYear,&s->Phone.Data.Priv.N6510.LastCalendarPos); 3748 return N71_65_GetNextCalendar1(s,Note,start,&s->Phone.Data.Priv.N6510.LastCalendar,&s->Phone.Data.Priv.N6510.LastCalendarYear,&s->Phone.Data.Priv.N6510.LastCalendarPos);
3703#endif 3749#endif
3704 3750
3705 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62)) { 3751 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62)) {
3706 /* Method 1. Some features missed. Not working with some notes in 3510 */ 3752 /* Method 1. Some features missed. Not working with some notes in 3510 */
3707 return N71_65_GetNextCalendar1(s,Note,start,&s->Phone.Data.Priv.N6510.LastCalendar,&s->Phone.Data.Priv.N6510.LastCalendarYear,&s->Phone.Data.Priv.N6510.LastCalendarPos); 3753 return N71_65_GetNextCalendar1(s,Note,start,&s->Phone.Data.Priv.N6510.LastCalendar,&s->Phone.Data.Priv.N6510.LastCalendarYear,&s->Phone.Data.Priv.N6510.LastCalendarPos);
3708 3754
3709 /* Method 2. In known phones texts of notes cut to 50 chars. Some features missed */ 3755 /* Method 2. In known phones texts of notes cut to 50 chars. Some features missed */
3710 // return N71_65_GetNextCalendar2(s,Note,start,&s->Phone.Data.Priv.N6510.LastCalendarYear,&s->Phone.Data.Priv.N6510.LastCalendarPos); 3756 // return N71_65_GetNextCalendar2(s,Note,start,&s->Phone.Data.Priv.N6510.LastCalendarYear,&s->Phone.Data.Priv.N6510.LastCalendarPos);
3711 } else { 3757 } else {
3712 /* Method 3. All DCT4 features supported. Not supported by 8910 */ 3758 /* Method 3. All DCT4 features supported. Not supported by 8910 */
3713 return N6510_GetNextCalendar3(s,Note,start,&s->Phone.Data.Priv.N6510.LastCalendar,&s->Phone.Data.Priv.N6510.LastCalendarYear,&s->Phone.Data.Priv.N6510.LastCalendarPos); 3759 return N6510_GetNextCalendar3(s,Note,start,&s->Phone.Data.Priv.N6510.LastCalendar,&s->Phone.Data.Priv.N6510.LastCalendarYear,&s->Phone.Data.Priv.N6510.LastCalendarPos);
3714 } 3760 }
3715} 3761}
3716 3762
3717static GSM_Error N6510_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *Status) 3763static GSM_Error N6510_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *Status)
3718{ 3764{
3719 GSM_Error error; 3765 GSM_Error error;
3720 3766
3721#ifdef GSM_FORCE_DCT4_CALENDAR_6210 3767#ifdef GSM_FORCE_DCT4_CALENDAR_6210
3722 /* Method 1 */ 3768 /* Method 1 */
3723 error=N71_65_GetCalendarInfo1(s, &s->Phone.Data.Priv.N6510.LastCalendar); 3769 error=N71_65_GetCalendarInfo1(s, &s->Phone.Data.Priv.N6510.LastCalendar);
3724 if (error!=ERR_NONE) return error; 3770 if (error!=ERR_NONE) return error;
3725 Status->Used = s->Phone.Data.Priv.N6510.LastCalendar.Number; 3771 Status->Used = s->Phone.Data.Priv.N6510.LastCalendar.Number;
3726 return ERR_NONE; 3772 return ERR_NONE;
3727#endif 3773#endif
3728 3774
3729 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62)) { 3775 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62)) {
3730 /* Method 1 */ 3776 /* Method 1 */
3731 error=N71_65_GetCalendarInfo1(s, &s->Phone.Data.Priv.N6510.LastCalendar); 3777 error=N71_65_GetCalendarInfo1(s, &s->Phone.Data.Priv.N6510.LastCalendar);
3732 if (error!=ERR_NONE) return error; 3778 if (error!=ERR_NONE) return error;
3733 Status->Used = s->Phone.Data.Priv.N6510.LastCalendar.Number; 3779 Status->Used = s->Phone.Data.Priv.N6510.LastCalendar.Number;
3734 return ERR_NONE; 3780 return ERR_NONE;
3735 3781
3736 /* Method 2 */ 3782 /* Method 2 */
3737 // return ERR_NOTSUPPORTED; 3783 // return ERR_NOTSUPPORTED;
3738 } else { 3784 } else {
3739 /* Method 3 */ 3785 /* Method 3 */
3740 error=N6510_GetCalendarInfo3(s,&s->Phone.Data.Priv.N6510.LastCalendar,true); 3786 error=N6510_GetCalendarInfo3(s,&s->Phone.Data.Priv.N6510.LastCalendar,0);
3741 if (error!=ERR_NONE) return error; 3787 if (error!=ERR_NONE) return error;
3742 Status->Used = s->Phone.Data.Priv.N6510.LastCalendar.Number; 3788 Status->Used = s->Phone.Data.Priv.N6510.LastCalendar.Number;
3743 return ERR_NONE; 3789 return ERR_NONE;
3744 } 3790 }
3745} 3791}
3746 3792
3747static GSM_Error N6510_AddCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note) 3793static GSM_Error N6510_AddCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note)
3748{ 3794{
3749#ifdef GSM_FORCE_DCT4_CALENDAR_6210 3795#ifdef GSM_FORCE_DCT4_CALENDAR_6210
3750 return N71_65_AddCalendar2(s,Note); 3796 return N71_65_AddCalendar2(s,Note);
3751#endif 3797#endif
3752 3798
3753 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62)) { 3799 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62)) {
3754 return N71_65_AddCalendar2(s,Note); 3800 return N71_65_AddCalendar2(s,Note);
3755 // return N71_65_AddCalendar1(s, Note, &s->Phone.Data.Priv.N6510.FirstCalendarPos); 3801 // return N71_65_AddCalendar1(s, Note, &s->Phone.Data.Priv.N6510.FirstCalendarPos);
3756 } else { 3802 } else {
3757 /* Method 3. All DCT4 features supported. Not supported by 8910 */ 3803 /* Method 3. All DCT4 features supported. Not supported by 8910 */
3758 return N6510_AddCalendar3(s, Note, &s->Phone.Data.Priv.N6510.FirstCalendarPos); 3804 return N6510_AddCalendar3(s, Note, &s->Phone.Data.Priv.N6510.FirstCalendarPos);
3759 } 3805 }
3760} 3806}
3761 3807
3762static GSM_Error N6510_ReplyLogIntoNetwork(GSM_Protocol_Message msg, GSM_StateMachine *s) 3808static GSM_Error N6510_ReplyLogIntoNetwork(GSM_Protocol_Message msg, GSM_StateMachine *s)
3763{ 3809{
3764 smprintf(s, "Probably phone says: I log into network\n"); 3810 smprintf(s, "Probably phone says: I log into network\n");
3765 return ERR_NONE; 3811 return ERR_NONE;
3766} 3812}
3767 3813
3768void N6510_EncodeFMFrequency(double freq, unsigned char *buff) 3814void N6510_EncodeFMFrequency(double freq, unsigned char *buff)
3769{ 3815{
3770 double freq0; 3816 double freq0;
3771 unsigned char buffer[20]; 3817 unsigned char buffer[20];
3772 unsigned int i,freq2; 3818 unsigned int i,freq2;
3773 3819
3774 sprintf(buffer,"%.3f",freq); 3820 sprintf(buffer,"%.3f",freq);
3775 for (i=0;i<strlen(buffer);i++) { 3821 for (i=0;i<strlen(buffer);i++) {
3776 if (buffer[i] == ',' || buffer[i] == '.') buffer[i] = ' '; 3822 if (buffer[i] == ',' || buffer[i] == '.') buffer[i] = ' ';
3777 } 3823 }
3778 StringToDouble(buffer, &freq0); 3824 StringToDouble(buffer, &freq0);
3779 freq2 = (unsigned int)freq0; 3825 freq2 = (unsigned int)freq0;
3780 dbgprintf("Frequency: %s %i\n",buffer,freq2); 3826 dbgprintf("Frequency: %s %i\n",buffer,freq2);
3781 freq2= freq2 - 0xffff; 3827 freq2= freq2 - 0xffff;
3782 buff[0] = freq2 / 0x100; 3828 buff[0] = freq2 / 0x100;
3783 buff[1] = freq2 % 0x100; 3829 buff[1] = freq2 % 0x100;
3784} 3830}
3785 3831
3786void N6510_DecodeFMFrequency(double *freq, unsigned char *buff) 3832void N6510_DecodeFMFrequency(double *freq, unsigned char *buff)
3787{ 3833{
3788 unsigned char buffer[20]; 3834 unsigned char buffer[20];
3789 3835
3790 sprintf(buffer,"%i.%i",(0xffff + buff[0] * 0x100 + buff[1])/1000, 3836 sprintf(buffer,"%i.%i",(0xffff + buff[0] * 0x100 + buff[1])/1000,
3791 (0xffff + buff[0] * 0x100 + buff[1])%1000); 3837 (0xffff + buff[0] * 0x100 + buff[1])%1000);
3792 dbgprintf("Frequency: %s\n",buffer); 3838 dbgprintf("Frequency: %s\n",buffer);
3793 StringToDouble(buffer, freq); 3839 StringToDouble(buffer, freq);
3794} 3840}
3795 3841
3796static GSM_Error N6510_ReplyGetFMStatus(GSM_Protocol_Message msg, GSM_StateMachine *s) 3842static GSM_Error N6510_ReplyGetFMStatus(GSM_Protocol_Message msg, GSM_StateMachine *s)
3797{ 3843{
3798 smprintf(s, "getting FM status OK\n"); 3844 smprintf(s, "getting FM status OK\n");
3799 memcpy(s->Phone.Data.Priv.N6510.FMStatus,msg.Buffer,msg.Length); 3845 memcpy(s->Phone.Data.Priv.N6510.FMStatus,msg.Buffer,msg.Length);
3800 s->Phone.Data.Priv.N6510.FMStatusLength = msg.Length; 3846 s->Phone.Data.Priv.N6510.FMStatusLength = msg.Length;
3801 return ERR_NONE; 3847 return ERR_NONE;
3802} 3848}
3803 3849
3804static GSM_Error N6510_GetFMStatus(GSM_StateMachine *s) 3850static GSM_Error N6510_GetFMStatus(GSM_StateMachine *s)
3805{ 3851{
3806 unsigned char req[7] = {N6110_FRAME_HEADER, 0x0d, 0x00, 0x00, 0x01}; 3852 unsigned char req[7] = {N6110_FRAME_HEADER, 0x0d, 0x00, 0x00, 0x01};
3807 3853
3808 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_RADIO)) return ERR_NOTSUPPORTED; 3854 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_RADIO)) return ERR_NOTSUPPORTED;
3809 return GSM_WaitFor (s, req, 7, 0x3E, 2, ID_GetFMStation); 3855 return GSM_WaitFor (s, req, 7, 0x3E, 2, ID_GetFMStation);
3810} 3856}
3811 3857
3812static GSM_Error N6510_ReplyGetFMStation(GSM_Protocol_Message msg, GSM_StateMachine *s) 3858static GSM_Error N6510_ReplyGetFMStation(GSM_Protocol_Message msg, GSM_StateMachine *s)
3813{ 3859{
3814 unsigned char name[GSM_MAX_FMSTATION_LENGTH*2+2]; 3860 unsigned char name[GSM_MAX_FMSTATION_LENGTH*2+2];
3815 int length; 3861 int length;
3816 GSM_Phone_Data*Data = &s->Phone.Data; 3862 GSM_Phone_Data*Data = &s->Phone.Data;
3817 3863
3818 switch (msg.Buffer[3]) { 3864 switch (msg.Buffer[3]) {
3819 case 0x06: 3865 case 0x06:
3820 smprintf(s, "Received FM station\n"); 3866 smprintf(s, "Received FM station\n");
3821 length = msg.Buffer[8]; 3867 length = msg.Buffer[8];
3822 memcpy(name,msg.Buffer+18,length*2); 3868 memcpy(name,msg.Buffer+18,length*2);
3823 name[length*2] = 0x00; 3869 name[length*2] = 0x00;
3824 name[length*2+1] = 0x00; 3870 name[length*2+1] = 0x00;
3825 CopyUnicodeString(Data->FMStation->StationName,name); 3871 CopyUnicodeString(Data->FMStation->StationName,name);
3826 smprintf(s,"Station name: \"%s\"\n",DecodeUnicodeString(Data->FMStation->StationName)); 3872 smprintf(s,"Station name: \"%s\"\n",DecodeUnicodeString(Data->FMStation->StationName));
3827 N6510_DecodeFMFrequency(&Data->FMStation->Frequency, msg.Buffer+16); 3873 N6510_DecodeFMFrequency(&Data->FMStation->Frequency, msg.Buffer+16);
3828 return ERR_NONE; 3874 return ERR_NONE;
3829 case 0x16: 3875 case 0x16:
3830 smprintf(s, "Received FM station. Empty ?\n"); 3876 smprintf(s, "Received FM station. Empty ?\n");
3831 return ERR_EMPTY; 3877 return ERR_EMPTY;
3832 } 3878 }
3833 return ERR_UNKNOWNRESPONSE; 3879 return ERR_UNKNOWNRESPONSE;
3834} 3880}
3835 3881
3836static GSM_Error N6510_GetFMStation (GSM_StateMachine *s, GSM_FMStation *FMStation) 3882static GSM_Error N6510_GetFMStation (GSM_StateMachine *s, GSM_FMStation *FMStation)
3837{ 3883{
3838 GSM_Error error; 3884 GSM_Error error;
3839 int location; 3885 int location;
3840 unsigned char req[7] = {N6110_FRAME_HEADER, 0x05, 3886 unsigned char req[7] = {N6110_FRAME_HEADER, 0x05,
3841 0x00, // location 3887 0x00, // location
3842 0x00,0x01}; 3888 0x00,0x01};
3843 3889
3844 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_RADIO)) return ERR_NOTSUPPORTED; 3890 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_RADIO)) return ERR_NOTSUPPORTED;
3845 if (FMStation->Location > GSM_MAX_FM_STATION) return ERR_INVALIDLOCATION; 3891 if (FMStation->Location > GSM_MAX_FM_STATION) return ERR_INVALIDLOCATION;
3846 3892
3847 s->Phone.Data.FMStation = FMStation; 3893 s->Phone.Data.FMStation = FMStation;
3848 3894
3849 error = N6510_GetFMStatus(s); 3895 error = N6510_GetFMStatus(s);
3850 if (error != ERR_NONE) return error; 3896 if (error != ERR_NONE) return error;
3851 3897
3852 location = FMStation->Location-1; 3898 location = FMStation->Location-1;
3853 if (s->Phone.Data.Priv.N6510.FMStatus[14+location] == 0xFF) return ERR_EMPTY; 3899 if (s->Phone.Data.Priv.N6510.FMStatus[14+location] == 0xFF) return ERR_EMPTY;
3854 req[4] = s->Phone.Data.Priv.N6510.FMStatus[14+location]; 3900 req[4] = s->Phone.Data.Priv.N6510.FMStatus[14+location];
3855 3901
3856 smprintf(s, "Getting FM Station %i\n",FMStation->Location); 3902 smprintf(s, "Getting FM Station %i\n",FMStation->Location);
3857 return GSM_WaitFor (s, req, 7, 0x3E, 2, ID_GetFMStation); 3903 return GSM_WaitFor (s, req, 7, 0x3E, 2, ID_GetFMStation);
3858} 3904}
3859 3905
3860static GSM_Error N6510_ReplySetFMStation(GSM_Protocol_Message msg, GSM_StateMachine *s) 3906static GSM_Error N6510_ReplySetFMStation(GSM_Protocol_Message msg, GSM_StateMachine *s)
3861{ 3907{
3862#ifdef DEBUG 3908#ifdef DEBUG
3863 switch (msg.Buffer[4]){ 3909 switch (msg.Buffer[4]){
3864 case 0x03: smprintf(s, "FM stations cleaned\n"); break; 3910 case 0x03: smprintf(s, "FM stations cleaned\n"); break;
3865 case 0x11: smprintf(s, "Setting FM station status OK\n"); break; 3911 case 0x11: smprintf(s, "Setting FM station status OK\n"); break;
3866 case 0x12: smprintf(s, "Setting FM station OK\n"); break; 3912 case 0x12: smprintf(s, "Setting FM station OK\n"); break;
3867 } 3913 }
3868#endif 3914#endif
3869 return ERR_NONE; 3915 return ERR_NONE;
3870} 3916}
3871 3917
3872static GSM_Error N6510_ClearFMStations (GSM_StateMachine *s) 3918static GSM_Error N6510_ClearFMStations (GSM_StateMachine *s)
3873{ 3919{
3874 unsigned char req[7] = {N6110_FRAME_HEADER, 0x03,0x0f,0x00,0x01}; 3920 unsigned char req[7] = {N6110_FRAME_HEADER, 0x03,0x0f,0x00,0x01};
3875 3921
3876 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_RADIO)) return ERR_NOTSUPPORTED; 3922 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_RADIO)) return ERR_NOTSUPPORTED;
3877 3923
3878 smprintf(s, "Cleaning FM Stations\n"); 3924 smprintf(s, "Cleaning FM Stations\n");
3879 return GSM_WaitFor (s, req, 7, 0x3E, 2, ID_SetFMStation); 3925 return GSM_WaitFor (s, req, 7, 0x3E, 2, ID_SetFMStation);
3880} 3926}
3881 3927
3882static GSM_Error N6510_SetFMStation (GSM_StateMachine *s, GSM_FMStation *FMStation) 3928static GSM_Error N6510_SetFMStation (GSM_StateMachine *s, GSM_FMStation *FMStation)
3883{ 3929{
3884 unsigned int len, location; 3930 unsigned int len, location;
3885 GSM_Error error; 3931 GSM_Error error;
3886 unsigned char setstatus[36] = {N6110_FRAME_HEADER,0x11,0x00,0x01,0x01, 3932 unsigned char setstatus[36] = {N6110_FRAME_HEADER,0x11,0x00,0x01,0x01,
3887 0x00,0x00,0x1c,0x00,0x14,0x00,0x00, 3933 0x00,0x00,0x1c,0x00,0x14,0x00,0x00,
3888 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 3934 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
3889 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 3935 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
3890 0xff,0xff,0xff,0xff,0xff,0x01}; 3936 0xff,0xff,0xff,0xff,0xff,0x01};
3891 unsigned char req[64] = {N6110_FRAME_HEADER, 0x12,0x00,0x01,0x00, 3937 unsigned char req[64] = {N6110_FRAME_HEADER, 0x12,0x00,0x01,0x00,
3892 0x00, // 0x0e + (strlen(name) * 2) 3938 0x00, // 0x0e + (strlen(name) * 2)
3893 0x00, // strlen(name) 3939 0x00, // strlen(name)
3894 0x14,0x09,0x00, 3940 0x14,0x09,0x00,
3895 0x00, // location 3941 0x00, // location
3896 0x00,0x00,0x01, 3942 0x00,0x00,0x01,
3897 0x00, // freqHi 3943 0x00, // freqHi
3898 0x00, // freqLo 3944 0x00, // freqLo
3899 0x01}; 3945 0x01};
3900 3946
3901 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_RADIO)) return ERR_NOTSUPPORTED; 3947 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_RADIO)) return ERR_NOTSUPPORTED;
3902 3948
3903 s->Phone.Data.FMStation = FMStation; 3949 s->Phone.Data.FMStation = FMStation;
3904 location = FMStation->Location-1; 3950 location = FMStation->Location-1;
3905 3951
3906 error = N6510_GetFMStatus(s); 3952 error = N6510_GetFMStatus(s);
3907 if (error != ERR_NONE) return error; 3953 if (error != ERR_NONE) return error;
3908 3954
3909 memcpy(setstatus+14,s->Phone.Data.Priv.N6510.FMStatus+14,20); 3955 memcpy(setstatus+14,s->Phone.Data.Priv.N6510.FMStatus+14,20);
3910 setstatus [14+location] = location; 3956 setstatus [14+location] = location;
3911 3957
3912 smprintf(s, "Setting FM status %i\n",FMStation->Location); 3958 smprintf(s, "Setting FM status %i\n",FMStation->Location);
3913 error = GSM_WaitFor (s, setstatus, 36 , 0x3E, 2, ID_SetFMStation); 3959 error = GSM_WaitFor (s, setstatus, 36 , 0x3E, 2, ID_SetFMStation);
3914 if (error != ERR_NONE) return error; 3960 if (error != ERR_NONE) return error;
3915 3961
3916 req[12] = location; 3962 req[12] = location;
3917 3963
3918 /* Name */ 3964 /* Name */
3919 len = UnicodeLength(FMStation->StationName); 3965 len = UnicodeLength(FMStation->StationName);
3920 req[8] = len; 3966 req[8] = len;
3921 req[7] = 0x0e + len * 2; 3967 req[7] = 0x0e + len * 2;
3922 memcpy (req+18,FMStation->StationName,len*2); 3968 memcpy (req+18,FMStation->StationName,len*2);
3923 3969
3924 /* Frequency */ 3970 /* Frequency */
3925 N6510_EncodeFMFrequency(FMStation->Frequency, req+16); 3971 N6510_EncodeFMFrequency(FMStation->Frequency, req+16);
3926 3972
3927 smprintf(s, "Setting FM Station %i\n",FMStation->Location); 3973 smprintf(s, "Setting FM Station %i\n",FMStation->Location);
3928 return GSM_WaitFor (s, req, 0x13+len*2, 0x3E, 2, ID_SetFMStation); 3974 return GSM_WaitFor (s, req, 0x13+len*2, 0x3E, 2, ID_SetFMStation);
3929} 3975}
3930 3976
3931static GSM_Error N6510_ReplySetLight(GSM_Protocol_Message msg, GSM_StateMachine *s) 3977static GSM_Error N6510_ReplySetLight(GSM_Protocol_Message msg, GSM_StateMachine *s)
3932{ 3978{
3933 smprintf(s, "Light set\n"); 3979 smprintf(s, "Light set\n");
3934 return ERR_NONE; 3980 return ERR_NONE;
3935} 3981}
3936 3982
3937GSM_Error N6510_SetLight(GSM_StateMachine *s, N6510_PHONE_LIGHTS light, bool enable) 3983GSM_Error N6510_SetLight(GSM_StateMachine *s, N6510_PHONE_LIGHTS light, bool enable)
3938{ 3984{
3939 unsigned char req[14] = { 3985 unsigned char req[14] = {
3940 N6110_FRAME_HEADER, 0x05, 3986 N6110_FRAME_HEADER, 0x05,
3941 0x01, /* 0x01 = Display, 0x03 = keypad */ 3987 0x01, /* 0x01 = Display, 0x03 = keypad */
3942 0x01, /* 0x01 = Enable, 0x02 = disable */ 3988 0x01, /* 0x01 = Enable, 0x02 = disable */
3943 0x00, 0x00, 0x00, 0x01, 3989 0x00, 0x00, 0x00, 0x01,
3944 0x05, 0x04, 0x02, 0x00}; 3990 0x05, 0x04, 0x02, 0x00};
3945 3991
3946 req[4] = light; 3992 req[4] = light;
3947 if (!enable) req[5] = 0x02; 3993 if (!enable) req[5] = 0x02;
3948 smprintf(s, "Setting light\n"); 3994 smprintf(s, "Setting light\n");
3949 return GSM_WaitFor (s, req, 14, 0x3A, 4, ID_SetLight); 3995 return GSM_WaitFor (s, req, 14, 0x3A, 4, ID_SetLight);
3950} 3996}
3951 3997
3952static GSM_Error N6510_ShowStartInfo(GSM_StateMachine *s, bool enable) 3998static GSM_Error N6510_ShowStartInfo(GSM_StateMachine *s, bool enable)
3953{ 3999{
3954 GSM_Error error; 4000 GSM_Error error;
3955 4001
3956 if (enable) { 4002 if (enable) {
3957 error=N6510_SetLight(s,N6510_LIGHT_DISPLAY,true); 4003 error=N6510_SetLight(s,N6510_LIGHT_DISPLAY,true);
3958 if (error != ERR_NONE) return error; 4004 if (error != ERR_NONE) return error;
3959 4005
3960 error=N6510_SetLight(s,N6510_LIGHT_TORCH,true); 4006 error=N6510_SetLight(s,N6510_LIGHT_TORCH,true);
3961 if (error != ERR_NONE) return error; 4007 if (error != ERR_NONE) return error;
3962 4008
3963 return N6510_SetLight(s,N6510_LIGHT_KEYPAD,true); 4009 return N6510_SetLight(s,N6510_LIGHT_KEYPAD,true);
3964 } else { 4010 } else {
3965 error=N6510_SetLight(s,N6510_LIGHT_DISPLAY,false); 4011 error=N6510_SetLight(s,N6510_LIGHT_DISPLAY,false);
3966 if (error != ERR_NONE) return error; 4012 if (error != ERR_NONE) return error;
3967 4013
3968 error=N6510_SetLight(s,N6510_LIGHT_TORCH,false); 4014 error=N6510_SetLight(s,N6510_LIGHT_TORCH,false);
3969 if (error != ERR_NONE) return error; 4015 if (error != ERR_NONE) return error;
3970 4016
3971 return N6510_SetLight(s,N6510_LIGHT_KEYPAD,false); 4017 return N6510_SetLight(s,N6510_LIGHT_KEYPAD,false);
3972 } 4018 }
3973} 4019}
3974 4020
4021static GSM_Error N6510_ReplyGetNoteInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
4022{
4023 return N6510_ReplyGetCalendarInfo3(msg, s, &s->Phone.Data.Priv.N6510.LastNote);
4024}
4025
4026static GSM_Error N6510_ReplyGetNote(GSM_Protocol_Message msg, GSM_StateMachine *s)
4027{
4028 smprintf(s, "Note received\n");
4029 memcpy(s->Phone.Data.Note->Text,msg.Buffer+54,(msg.Buffer[50]*256+msg.Buffer[51])*2);
4030 s->Phone.Data.Note->Text[(msg.Buffer[50]*256+msg.Buffer[51])*2] = 0;
4031 s->Phone.Data.Note->Text[(msg.Buffer[50]*256+msg.Buffer[51])*2+1] = 0;
4032 return ERR_NONE;
4033}
4034
4035GSM_Error N6510_GetNextNote(GSM_StateMachine *s, GSM_NoteEntry *Note, bool start)
4036{
4037 GSM_Error error;
4038 GSM_NOKIACalToDoLocations *LastNote = &s->Phone.Data.Priv.N6510.LastNote;
4039
4040 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOTES)) return ERR_NOTSUPPORTED;
4041
4042 if (start) {
4043 error=N6510_GetCalendarInfo3(s,LastNote,2);
4044 if (error!=ERR_NONE) return error;
4045 Note->Location = 1;
4046 } else {
4047 Note->Location++;
4048 }
4049
4050 if (Note->Location > LastNote->Number) return ERR_EMPTY;
4051
4052 s->Phone.Data.Note = Note;
4053 smprintf(s, "Getting note\n");
4054 return N6510_PrivGetGenericCalendar3(s, LastNote->Location[Note->Location-1], ID_GetNote);
4055}
4056
3975static int N6510_FindFileCheckSum(unsigned char *ptr, int len) 4057static int N6510_FindFileCheckSum(unsigned char *ptr, int len)
3976{ 4058{
3977 int acc, i, accx; 4059 int acc, i, accx;
3978 4060
3979 accx = 0; 4061 accx = 0;
3980 acc = 0xffff; 4062 acc = 0xffff;
3981 while (len--) { 4063 while (len--) {
3982 accx = (accx & 0xffff00ff) | (acc & 0xff00); 4064 accx = (accx & 0xffff00ff) | (acc & 0xff00);
3983 acc = (acc & 0xffff00ff) | *ptr++ << 8; 4065 acc = (acc & 0xffff00ff) | *ptr++ << 8;
3984 for (i = 0; i < 8; i++) { 4066 for (i = 0; i < 8; i++) {
3985 acc <<= 1; 4067 acc <<= 1;
3986 if (acc & 0x10000) acc ^= 0x1021; 4068 if (acc & 0x10000) acc ^= 0x1021;
3987 if (accx & 0x80000000) acc ^= 0x1021; 4069 if (accx & 0x80000000) acc ^= 0x1021;
3988 accx <<= 1; 4070 accx <<= 1;
3989 } 4071 }
3990 } 4072 }
3991 dbgprintf("Checksum from Gammu is %04X\n",(acc & 0xffff)); 4073 dbgprintf("Checksum from Gammu is %04X\n",(acc & 0xffff));
3992 return (acc & 0xffff); 4074 return (acc & 0xffff);
3993} 4075}
3994 4076
3995static GSM_Error N6510_ReplyGetFileFolderInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 4077static GSM_Error N6510_ReplyGetFileFolderInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
3996{ 4078{
3997 GSM_File *File = s->Phone.Data.FileInfo; 4079 GSM_File *File = s->Phone.Data.FileInfo;
3998 GSM_Phone_N6510Data*Priv = &s->Phone.Data.Priv.N6510; 4080 GSM_Phone_N6510Data*Priv = &s->Phone.Data.Priv.N6510;
3999 int i; 4081 int i;
4000 4082
4001 switch (msg.Buffer[3]) { 4083 switch (msg.Buffer[3]) {
4002 case 0x15: 4084 case 0x15:
4003 smprintf(s,"File or folder details received\n"); 4085 smprintf(s,"File or folder details received\n");
4004 CopyUnicodeString(File->Name,msg.Buffer+10); 4086 CopyUnicodeString(File->Name,msg.Buffer+10);
4005 if (!strncmp(DecodeUnicodeString(File->Name),"GMSTemp",7)) return ERR_EMPTY; 4087 if (!strncmp(DecodeUnicodeString(File->Name),"GMSTemp",7)) return ERR_EMPTY;
4006 if (File->Name[0] == 0x00 && File->Name[1] == 0x00) return ERR_UNKNOWN; 4088 if (File->Name[0] == 0x00 && File->Name[1] == 0x00) return ERR_UNKNOWN;
4007 4089
4008 i = msg.Buffer[8]*256+msg.Buffer[9]; 4090 i = msg.Buffer[8]*256+msg.Buffer[9];
4009 dbgprintf("%02x %02x %02x %02x %02x %02x %02x %02x %02x\n", 4091 dbgprintf("%02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
4010 msg.Buffer[i-5],msg.Buffer[i-4],msg.Buffer[i-3], 4092 msg.Buffer[i-5],msg.Buffer[i-4],msg.Buffer[i-3],
4011 msg.Buffer[i-2],msg.Buffer[i-1],msg.Buffer[i], 4093 msg.Buffer[i-2],msg.Buffer[i-1],msg.Buffer[i],
4012 msg.Buffer[i+1],msg.Buffer[i+2],msg.Buffer[i+3]); 4094 msg.Buffer[i+1],msg.Buffer[i+2],msg.Buffer[i+3]);
4013 4095
4014 File->Folder = false; 4096 File->Folder = false;
4015 if (msg.Buffer[i-5] == 0x00) File->Folder = true; 4097 if (msg.Buffer[i-5] == 0x00) File->Folder = true;
4016 4098
4017 File->ReadOnly = false; 4099 File->ReadOnly = false;
4018 File->Protected = false; 4100 File->Protected = false;
4019 File->System= false; 4101 File->System= false;
4020 File->Hidden= false; 4102 File->Hidden= false;
4021 if (msg.Buffer[i+2] == 0x01) File->Protected = true; 4103 if (msg.Buffer[i+2] == 0x01) File->Protected = true;
4022 if (msg.Buffer[i+4] == 0x01) File->ReadOnly = true; 4104 if (msg.Buffer[i+4] == 0x01) File->ReadOnly = true;
4023 if (msg.Buffer[i+5] == 0x01) File->Hidden= true; 4105 if (msg.Buffer[i+5] == 0x01) File->Hidden= true;
4024 if (msg.Buffer[i+6] == 0x01) File->System= true;//fixme 4106 if (msg.Buffer[i+6] == 0x01) File->System= true;//fixme
4025 4107
4026 File->ModifiedEmpty = false; 4108 File->ModifiedEmpty = false;
4027 NOKIA_DecodeDateTime(s, msg.Buffer+i-22, &File->Modified); 4109 NOKIA_DecodeDateTime(s, msg.Buffer+i-22, &File->Modified);
4028 if (File->Modified.Year == 0x00) File->ModifiedEmpty = true; 4110 if (File->Modified.Year == 0x00) File->ModifiedEmpty = true;
4029 dbgprintf("%02x %02x %02x %02x\n",msg.Buffer[i-22],msg.Buffer[i-21],msg.Buffer[i-20],msg.Buffer[i-19]); 4111 dbgprintf("%02x %02x %02x %02x\n",msg.Buffer[i-22],msg.Buffer[i-21],msg.Buffer[i-20],msg.Buffer[i-19]);
4030 4112
4031 Priv->FileToken = msg.Buffer[i-10]*256+msg.Buffer[i-9]; 4113 Priv->FileToken = msg.Buffer[i-10]*256+msg.Buffer[i-9];
4032 Priv->ParentID = msg.Buffer[i]*256+msg.Buffer[i+1]; 4114 Priv->ParentID = msg.Buffer[i]*256+msg.Buffer[i+1];
4033 smprintf(s,"ParentID is %i\n",Priv->ParentID); 4115 smprintf(s,"ParentID is %i\n",Priv->ParentID);
4034 4116
4035 File->Type = GSM_File_Other; 4117 File->Type = GSM_File_Other;
4036 if (msg.Length > 240){ 4118 if (msg.Length > 240){
4037 i = 227; 4119 i = 227;
4038 if (msg.Buffer[i]==0x02 && msg.Buffer[i+2]==0x01) 4120 if (msg.Buffer[i]==0x02 && msg.Buffer[i+2]==0x01)
4039 File->Type = GSM_File_Image_JPG; 4121 File->Type = GSM_File_Image_JPG;
4040 else if (msg.Buffer[i]==0x02 && msg.Buffer[i+2]==0x02) 4122 else if (msg.Buffer[i]==0x02 && msg.Buffer[i+2]==0x02)
4041 File->Type = GSM_File_Image_BMP; 4123 File->Type = GSM_File_Image_BMP;
4042 else if (msg.Buffer[i]==0x02 && msg.Buffer[i+2]==0x07) 4124 else if (msg.Buffer[i]==0x02 && msg.Buffer[i+2]==0x07)
4043 File->Type = GSM_File_Image_BMP; 4125 File->Type = GSM_File_Image_BMP;
4044 else if (msg.Buffer[i]==0x02 && msg.Buffer[i+2]==0x03) 4126 else if (msg.Buffer[i]==0x02 && msg.Buffer[i+2]==0x03)
4045 File->Type = GSM_File_Image_PNG; 4127 File->Type = GSM_File_Image_PNG;
4046 else if (msg.Buffer[i]==0x02 && msg.Buffer[i+2]==0x05) 4128 else if (msg.Buffer[i]==0x02 && msg.Buffer[i+2]==0x05)
4047 File->Type = GSM_File_Image_GIF; 4129 File->Type = GSM_File_Image_GIF;
4048 else if (msg.Buffer[i]==0x02 && msg.Buffer[i+2]==0x09) 4130 else if (msg.Buffer[i]==0x02 && msg.Buffer[i+2]==0x09)
4049 File->Type = GSM_File_Image_WBMP; 4131 File->Type = GSM_File_Image_WBMP;
4050 else if (msg.Buffer[i]==0x04 && msg.Buffer[i+2]==0x01) 4132 else if (msg.Buffer[i]==0x04 && msg.Buffer[i+2]==0x01)
4051 File->Type = GSM_File_Sound_AMR; 4133 File->Type = GSM_File_Sound_AMR;
4052 else if (msg.Buffer[i]==0x04 && msg.Buffer[i+2]==0x02) 4134 else if (msg.Buffer[i]==0x04 && msg.Buffer[i+2]==0x02)
4053 File->Type = GSM_File_Sound_MIDI; 4135 File->Type = GSM_File_Sound_MIDI;
4054 else if (msg.Buffer[i]==0x08 && msg.Buffer[i+2]==0x05) 4136 else if (msg.Buffer[i]==0x08 && msg.Buffer[i+2]==0x05)
4055 File->Type = GSM_File_Video_3GP; 4137 File->Type = GSM_File_Video_3GP;
4056 else if (msg.Buffer[i]==0x10 && msg.Buffer[i+2]==0x01) 4138 else if (msg.Buffer[i]==0x10 && msg.Buffer[i+2]==0x01)
4057 File->Type = GSM_File_Java_JAR; 4139 File->Type = GSM_File_Java_JAR;
4058#if DEVELOP 4140#ifdef DEVELOP
4059 else if (msg.Buffer[i]==0x00 && msg.Buffer[i+2]==0x01) 4141 else if (msg.Buffer[i]==0x00 && msg.Buffer[i+2]==0x01)
4060 File->Type = GSM_File_MMS; 4142 File->Type = GSM_File_MMS;
4061#endif 4143#endif
4062 } 4144 }
4063 return ERR_NONE; 4145 return ERR_NONE;
4064 case 0x2F: 4146 case 0x2F:
4065 smprintf(s,"File or folder used bytes received\n"); 4147 smprintf(s,"File or folder used bytes received\n");
4066 File->Used = msg.Buffer[6]*256*256*256+ 4148 File->Used = msg.Buffer[6]*256*256*256+
4067 msg.Buffer[7]*256*256+ 4149 msg.Buffer[7]*256*256+
4068 msg.Buffer[8]*256+ 4150 msg.Buffer[8]*256+
4069 msg.Buffer[9]; 4151 msg.Buffer[9];
4070 return ERR_NONE; 4152 return ERR_NONE;
4071 case 0x33: 4153 case 0x33:
4072 if (s->Phone.Data.RequestID == ID_GetFileInfo) { 4154 if (s->Phone.Data.RequestID == ID_GetFileInfo) {
4073 i = Priv->FilesLocationsUsed-1; 4155 i = Priv->FilesLocationsUsed-1;
4074 while (1) { 4156 while (1) {
4075 if (i==Priv->FilesLocationsCurrent-1) break; 4157 if (i==Priv->FilesLocationsCurrent-1) break;
4076 dbgprintf("Copying %i to %i, max %i, current %i\n", 4158 dbgprintf("Copying %i to %i, max %i, current %i\n",
4077 i,i+msg.Buffer[9], 4159 i,i+msg.Buffer[9],
4078 Priv->FilesLocationsUsed,Priv->FilesLocationsCurrent); 4160 Priv->FilesLocationsUsed,Priv->FilesLocationsCurrent);
4079 Priv->FilesLocations[i+msg.Buffer[9]] = Priv->FilesLocations[i]; 4161 Priv->FilesLocations[i+msg.Buffer[9]] = Priv->FilesLocations[i];
4080 Priv->FilesLevels[i+msg.Buffer[9]]= Priv->FilesLevels[i]; 4162 Priv->FilesLevels[i+msg.Buffer[9]]= Priv->FilesLevels[i];
4081 i--; 4163 i--;
4082 } 4164 }
4083 Priv->FilesLocationsUsed += msg.Buffer[9]; 4165 Priv->FilesLocationsUsed += msg.Buffer[9];
4084 for (i=0;i<msg.Buffer[9];i++) { 4166 for (i=0;i<msg.Buffer[9];i++) {
4085 Priv->FilesLocations[Priv->FilesLocationsCurrent+i] = msg.Buffer[13+i*4-1]*256 + msg.Buffer[13+i*4]; 4167 Priv->FilesLocations[Priv->FilesLocationsCurrent+i] = msg.Buffer[13+i*4-1]*256 + msg.Buffer[13+i*4];
4086 Priv->FilesLevels[Priv->FilesLocationsCurrent+i] = File->Level+1; 4168 Priv->FilesLevels[Priv->FilesLocationsCurrent+i] = File->Level+1;
4087 dbgprintf("%i ",Priv->FilesLocations[Priv->FilesLocationsCurrent+i]); 4169 dbgprintf("%i ",Priv->FilesLocations[Priv->FilesLocationsCurrent+i]);
4088 } 4170 }
4089 dbgprintf("\n"); 4171 dbgprintf("\n");
4090 } 4172 }
4091 if (msg.Buffer[9] != 0x00) File->Folder = true; 4173 if (msg.Buffer[9] != 0x00) File->Folder = true;
4092 return ERR_NONE; 4174 return ERR_NONE;
4093 case 0x43: 4175 case 0x43:
4094 Priv->FileCheckSum = msg.Buffer[6] * 256 + msg.Buffer[7]; 4176 Priv->FileCheckSum = msg.Buffer[6] * 256 + msg.Buffer[7];
4095 smprintf(s,"File checksum from phone is %04X\n",Priv->FileCheckSum); 4177 smprintf(s,"File checksum from phone is %04X\n",Priv->FileCheckSum);
4096 return ERR_NONE; 4178 return ERR_NONE;
4097 } 4179 }
4098 return ERR_UNKNOWNRESPONSE; 4180 return ERR_UNKNOWNRESPONSE;
4099} 4181}
4100 4182
4101static GSM_Error N6510_GetFileFolderInfo(GSM_StateMachine *s, GSM_File *File, GSM_Phone_RequestID Request) 4183static GSM_Error N6510_GetFileFolderInfo(GSM_StateMachine *s, GSM_File *File, GSM_Phone_RequestID Request)
4102{ 4184{
4103 GSM_Error error; 4185 GSM_Error error;
4104 unsigned char req[10] = { 4186 unsigned char req[10] = {
4105 N7110_FRAME_HEADER, 4187 N7110_FRAME_HEADER,
4106 0x14, /* 0x14 - info, 0x22 - free/total, 0x2E - used, 0x32 - sublocations */ 4188 0x14, /* 0x14 - info, 0x22 - free/total, 0x2E - used, 0x32 - sublocations */
4107 0x01, /* 0x00 for sublocations reverse sorting, 0x01 for free */ 4189 0x01, /* 0x00 for sublocations reverse sorting, 0x01 for free */
4108 0x00, 0x00, 0x01, 4190 0x00, 0x00, 0x01,
4109 0x00, 0x01};/* Folder or file number */ 4191 0x00, 0x01};/* Folder or file number */
4110 unsigned char GetCRC[] = { 4192 unsigned char GetCRC[] = {
4111 N7110_FRAME_HEADER, 0x42, 0x00, 0x00, 0x00, 0x01, 4193 N7110_FRAME_HEADER, 0x42, 0x00, 0x00, 0x00, 0x01,
4112 0x00, 0x1E}; /* file ID */ 4194 0x00, 0x1E}; /* file ID */
4113 4195
4114 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED; 4196 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
4115 4197
4116 s->Phone.Data.FileInfo = File; 4198 s->Phone.Data.FileInfo = File;
4117 req[8] = atoi(File->ID_FullName) / 256; 4199 req[8] = atoi(File->ID_FullName) / 256;
4118 req[9] = atoi(File->ID_FullName) % 256; 4200 req[9] = atoi(File->ID_FullName) % 256;
4119 4201
4120 req[3] = 0x14; 4202 req[3] = 0x14;
4121 req[4] = 0x01; 4203 req[4] = 0x01;
4122 smprintf(s,"Getting info for file in filesystem\n"); 4204 smprintf(s,"Getting info for file in filesystem\n");
4123 error=GSM_WaitFor (s, req, 10, 0x6D, 4, Request); 4205 error=GSM_WaitFor (s, req, 10, 0x6D, 4, Request);
4124 if (error != ERR_NONE) return error; 4206 if (error != ERR_NONE) return error;
4125 4207
4126 if (Request != ID_AddFile) { 4208 if (Request != ID_AddFile) {
4127 req[3] = 0x32; 4209 req[3] = 0x32;
4128 req[4] = 0x00; 4210 req[4] = 0x00;
4129 smprintf(s,"Getting subfolders for filesystem\n"); 4211 smprintf(s,"Getting subfolders for filesystem\n");
4130 error=GSM_WaitFor (s, req, 10, 0x6D, 4, Request); 4212 error=GSM_WaitFor (s, req, 10, 0x6D, 4, Request);
4131 if (error != ERR_NONE) return error; 4213 if (error != ERR_NONE) return error;
4132 4214
4133 if (!File->Folder) { 4215 if (!File->Folder) {
4134 req[3] = 0x2E; 4216 req[3] = 0x2E;
4135 req[4] = 0x01; 4217 req[4] = 0x01;
4136 smprintf(s,"Getting used memory for file in filesystem\n"); 4218 smprintf(s,"Getting used memory for file in filesystem\n");
4137 error=GSM_WaitFor (s, req, 10, 0x6D, 4, Request); 4219 error=GSM_WaitFor (s, req, 10, 0x6D, 4, Request);
4138 if (error != ERR_NONE) return error; 4220 if (error != ERR_NONE) return error;
4139 4221
4140 GetCRC[8] = atoi(File->ID_FullName) / 256; 4222 GetCRC[8] = atoi(File->ID_FullName) / 256;
4141 GetCRC[9] = atoi(File->ID_FullName) % 256; 4223 GetCRC[9] = atoi(File->ID_FullName) % 256;
4142 smprintf(s,"Getting CRC for file in filesystem\n"); 4224 smprintf(s,"Getting CRC for file in filesystem\n");
4143 error=GSM_WaitFor (s, GetCRC, 10, 0x6D, 4, Request); 4225 error=GSM_WaitFor (s, GetCRC, 10, 0x6D, 4, Request);
4144 } 4226 }
4145 } 4227 }
4146 return error; 4228 return error;
4147} 4229}
4148 4230
4149static GSM_Error N6510_GetNextFileFolder(GSM_StateMachine *s, GSM_File *File, bool start) 4231static GSM_Error N6510_GetNextFileFolder(GSM_StateMachine *s, GSM_File *File, bool start)
4150{ 4232{
4151 GSM_Phone_N6510Data*Priv = &s->Phone.Data.Priv.N6510; 4233 GSM_Phone_N6510Data*Priv = &s->Phone.Data.Priv.N6510;
4152 GSM_Error error; 4234 GSM_Error error;
4153 4235
4154 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED; 4236 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
4155 4237
4156 if (start) { 4238 if (start) {
4157 Priv->FilesLocationsUsed = 1; 4239 Priv->FilesLocationsUsed = 1;
4158 Priv->FilesLocationsCurrent = 0; 4240 Priv->FilesLocationsCurrent = 0;
4159 Priv->FilesLocations[0] = 0x01; 4241 Priv->FilesLocations[0] = 0x01;
4160 Priv->FilesLevels[0] = 1; 4242 Priv->FilesLevels[0] = 1;
4161 } 4243 }
4162 4244
4163 while (1) { 4245 while (1) {
4164 if (Priv->FilesLocationsCurrent == Priv->FilesLocationsUsed) return ERR_EMPTY; 4246 if (Priv->FilesLocationsCurrent == Priv->FilesLocationsUsed) return ERR_EMPTY;
4165 4247
4166 sprintf(File->ID_FullName,"%i",Priv->FilesLocations[Priv->FilesLocationsCurrent]); 4248 sprintf(File->ID_FullName,"%i",Priv->FilesLocations[Priv->FilesLocationsCurrent]);
4167 File->Level= Priv->FilesLevels[Priv->FilesLocationsCurrent]; 4249 File->Level= Priv->FilesLevels[Priv->FilesLocationsCurrent];
4168 Priv->FilesLocationsCurrent++; 4250 Priv->FilesLocationsCurrent++;
4169 4251
4170 error = N6510_GetFileFolderInfo(s, File, ID_GetFileInfo); 4252 error = N6510_GetFileFolderInfo(s, File, ID_GetFileInfo);
4171 if (error == ERR_EMPTY) continue; 4253 if (error == ERR_EMPTY) continue;
4172 return error; 4254 return error;
4173 } 4255 }
4174} 4256}
4175 4257
4176static GSM_Error N6510_ReplyGetFileSystemStatus(GSM_Protocol_Message msg, GSM_StateMachine *s) 4258static GSM_Error N6510_ReplyGetFileSystemStatus(GSM_Protocol_Message msg, GSM_StateMachine *s)
4177{ 4259{
4178 switch (msg.Buffer[3]) { 4260 switch (msg.Buffer[3]) {
4179 case 0x23: 4261 case 0x23:
4180 if (!strcmp(s->Phone.Data.ModelInfo->model,"6310i")) { 4262 if (!strcmp(s->Phone.Data.ModelInfo->model,"6310i")) {
4181 smprintf(s,"File or folder total bytes received\n"); 4263 smprintf(s,"File or folder total bytes received\n");
4182 s->Phone.Data.FileSystemStatus->Free = 4264 s->Phone.Data.FileSystemStatus->Free =
4183 3*256*256 + msg.Buffer[8]*256 + msg.Buffer[9] - 4265 3*256*256 + msg.Buffer[8]*256 + msg.Buffer[9] -
4184 s->Phone.Data.FileSystemStatus->Used; 4266 s->Phone.Data.FileSystemStatus->Used;
4185 } else { 4267 } else {
4186 smprintf(s,"File or folder free bytes received\n"); 4268 smprintf(s,"File or folder free bytes received\n");
4187 s->Phone.Data.FileSystemStatus->Free = 4269 s->Phone.Data.FileSystemStatus->Free =
4188 msg.Buffer[6]*256*256*256+ 4270 msg.Buffer[6]*256*256*256+
4189 msg.Buffer[7]*256*256+ 4271 msg.Buffer[7]*256*256+
4190 msg.Buffer[8]*256+ 4272 msg.Buffer[8]*256+
4191 msg.Buffer[9]; 4273 msg.Buffer[9];
4192 } 4274 }
4193 return ERR_NONE; 4275 return ERR_NONE;
4194 case 0x2F: 4276 case 0x2F:
4195 smprintf(s,"File or folder used bytes received\n"); 4277 smprintf(s,"File or folder used bytes received\n");
4196 s->Phone.Data.FileSystemStatus->Used = 4278 s->Phone.Data.FileSystemStatus->Used =
4197 msg.Buffer[6]*256*256*256+ 4279 msg.Buffer[6]*256*256*256+
4198 msg.Buffer[7]*256*256+ 4280 msg.Buffer[7]*256*256+
4199 msg.Buffer[8]*256+ 4281 msg.Buffer[8]*256+
4200 msg.Buffer[9]; 4282 msg.Buffer[9];
4201 return ERR_NONE; 4283 return ERR_NONE;
4202 } 4284 }
4203 return ERR_UNKNOWNRESPONSE; 4285 return ERR_UNKNOWNRESPONSE;
4204} 4286}
4205 4287
4206static GSM_Error N6510_GetFileSystemStatus(GSM_StateMachine *s, GSM_FileSystemStatus *status) 4288static GSM_Error N6510_GetFileSystemStatus(GSM_StateMachine *s, GSM_FileSystemStatus *status)
4207{ 4289{
4208 GSM_Error error; 4290 GSM_Error error;
4209 unsigned char req[10] = { 4291 unsigned char req[10] = {
4210 N7110_FRAME_HEADER, 4292 N7110_FRAME_HEADER,
4211 0x22, /* 0x14 - info, 0x22 - free/total, 0x2E - used, 0x32 - sublocations */ 4293 0x22, /* 0x14 - info, 0x22 - free/total, 0x2E - used, 0x32 - sublocations */
4212 0x01, /* 0x00 for sublocations reverse sorting, 0x01 for free */ 4294 0x01, /* 0x00 for sublocations reverse sorting, 0x01 for free */
4213 0x00, 0x00, 0x01, 4295 0x00, 0x00, 0x01,
4214 0x00, 0x01};/* Folder or file number */ 4296 0x00, 0x01};/* Folder or file number */
4215 4297
4216 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED; 4298 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
4217 4299
4218 s->Phone.Data.FileSystemStatus = status; 4300 s->Phone.Data.FileSystemStatus = status;
4219 4301
4220 status->Free = 0; 4302 status->Free = 0;
4221 4303
4222 req[3] = 0x2E; 4304 req[3] = 0x2E;
4223 req[4] = 0x01; 4305 req[4] = 0x01;
4224 smprintf(s, "Getting used/total memory in filesystem\n"); 4306 smprintf(s, "Getting used/total memory in filesystem\n");
4225 error = GSM_WaitFor (s, req, 10, 0x6D, 4, ID_FileSystemStatus); 4307 error = GSM_WaitFor (s, req, 10, 0x6D, 4, ID_FileSystemStatus);
4226 4308
4227 req[3] = 0x22; 4309 req[3] = 0x22;
4228 req[4] = 0x01; 4310 req[4] = 0x01;
4229 smprintf(s, "Getting free memory in filesystem\n"); 4311 smprintf(s, "Getting free memory in filesystem\n");
4230 return GSM_WaitFor (s, req, 10, 0x6D, 4, ID_FileSystemStatus); 4312 return GSM_WaitFor (s, req, 10, 0x6D, 4, ID_FileSystemStatus);
4231} 4313}
4232 4314
4233static GSM_Error N6510_SearchForFileName(GSM_StateMachine *s, GSM_File *File) 4315static GSM_Error N6510_SearchForFileName(GSM_StateMachine *s, GSM_File *File)
4234{ 4316{
4235 GSM_File File2; 4317 GSM_File File2;
4236 GSM_Error error; 4318 GSM_Error error;
4237 int FilesLocations[1000],FilesLocations2[1000]; 4319 int FilesLocations[1000],FilesLocations2[1000];
4238 int FilesLevels[1000]; 4320 int FilesLevels[1000];
4239 int FilesLocationsUsed, FilesLocationsCurrent; 4321 int FilesLocationsUsed, FilesLocationsCurrent;
4240 int FilesLocationsUsed2, FilesLocationsCurrent2; 4322 int FilesLocationsUsed2, FilesLocationsCurrent2;
4241 GSM_Phone_N6510Data*Priv = &s->Phone.Data.Priv.N6510; 4323 GSM_Phone_N6510Data*Priv = &s->Phone.Data.Priv.N6510;
4242 4324
4243 memcpy(FilesLocations, Priv->FilesLocations,sizeof(FilesLocations)); 4325 memcpy(FilesLocations, Priv->FilesLocations,sizeof(FilesLocations));
4244 memcpy(FilesLevels, Priv->FilesLevels,sizeof(FilesLevels)); 4326 memcpy(FilesLevels, Priv->FilesLevels,sizeof(FilesLevels));
4245 FilesLocationsUsed = Priv->FilesLocationsUsed; 4327 FilesLocationsUsed = Priv->FilesLocationsUsed;
4246 FilesLocationsCurrent = Priv->FilesLocationsCurrent; 4328 FilesLocationsCurrent = Priv->FilesLocationsCurrent;
4247 4329
4248 Priv->FilesLocationsUsed = 1; 4330 Priv->FilesLocationsUsed = 1;
4249 Priv->FilesLocationsCurrent = 1; 4331 Priv->FilesLocationsCurrent = 1;
4250 Priv->FilesLocations[0] = atoi(File->ID_FullName); 4332 Priv->FilesLocations[0] = atoi(File->ID_FullName);
4251 Priv->FilesLevels[0] = 1; 4333 Priv->FilesLevels[0] = 1;
4252 4334
4253 strcpy(File2.ID_FullName,File->ID_FullName); 4335 strcpy(File2.ID_FullName,File->ID_FullName);
4254 error = N6510_GetFileFolderInfo(s, &File2, ID_GetFileInfo); 4336 error = N6510_GetFileFolderInfo(s, &File2, ID_GetFileInfo);
4255 memcpy(FilesLocations2, Priv->FilesLocations,sizeof(FilesLocations2)); 4337 memcpy(FilesLocations2, Priv->FilesLocations,sizeof(FilesLocations2));
4256 FilesLocationsUsed2 = Priv->FilesLocationsUsed; 4338 FilesLocationsUsed2 = Priv->FilesLocationsUsed;
4257 FilesLocationsCurrent2 = Priv->FilesLocationsCurrent; 4339 FilesLocationsCurrent2 = Priv->FilesLocationsCurrent;
4258 4340
4259 memcpy(Priv->FilesLocations, FilesLocations, sizeof(FilesLocations)); 4341 memcpy(Priv->FilesLocations, FilesLocations, sizeof(FilesLocations));
4260 memcpy(Priv->FilesLevels, FilesLevels, sizeof(FilesLevels)); 4342 memcpy(Priv->FilesLevels, FilesLevels, sizeof(FilesLevels));
4261 Priv->FilesLocationsUsed = FilesLocationsUsed; 4343 Priv->FilesLocationsUsed = FilesLocationsUsed;
4262 Priv->FilesLocationsCurrent = FilesLocationsCurrent; 4344 Priv->FilesLocationsCurrent = FilesLocationsCurrent;
4263 if (error != ERR_NONE) return error; 4345 if (error != ERR_NONE) return error;
4264 4346
4265 while (1) { 4347 while (1) {
4266 if (FilesLocationsCurrent2 == FilesLocationsUsed2) return ERR_EMPTY; 4348 if (FilesLocationsCurrent2 == FilesLocationsUsed2) return ERR_EMPTY;
4267 4349
4268 sprintf(File2.ID_FullName,"%i",FilesLocations2[FilesLocationsCurrent2]); 4350 sprintf(File2.ID_FullName,"%i",FilesLocations2[FilesLocationsCurrent2]);
4269 dbgprintf("Current is %i\n",FilesLocations2[FilesLocationsCurrent2]); 4351 dbgprintf("Current is %i\n",FilesLocations2[FilesLocationsCurrent2]);
4270 FilesLocationsCurrent2++; 4352 FilesLocationsCurrent2++;
4271 4353
4272 error = N6510_GetFileFolderInfo(s, &File2, ID_AddFile); 4354 error = N6510_GetFileFolderInfo(s, &File2, ID_AddFile);
4273 if (error == ERR_EMPTY) continue; 4355 if (error == ERR_EMPTY) continue;
4274 if (error != ERR_NONE) return error; 4356 if (error != ERR_NONE) return error;
4275 dbgprintf("%s %s\n",DecodeUnicodeString(File->Name),DecodeUnicodeString(File2.Name)); 4357 dbgprintf("%s %s\n",DecodeUnicodeString(File->Name),DecodeUnicodeString(File2.Name));
4276 if (mywstrncasecmp(File2.Name,File->Name,0)) return ERR_NONE; 4358 if (mywstrncasecmp(File2.Name,File->Name,0)) return ERR_NONE;
4277 } 4359 }
4278 return ERR_EMPTY; 4360 return ERR_EMPTY;
4279} 4361}
4280 4362
4281static GSM_Error N6510_ReplyGetFilePart(GSM_Protocol_Message msg, GSM_StateMachine *s) 4363static GSM_Error N6510_ReplyGetFilePart(GSM_Protocol_Message msg, GSM_StateMachine *s)
4282{ 4364{
4283 int old; 4365 int old;
4284 4366
4285 smprintf(s,"File part received\n"); 4367 smprintf(s,"File part received\n");
4286 old = s->Phone.Data.File->Used; 4368 old = s->Phone.Data.File->Used;
4287 s->Phone.Data.File->Used += msg.Buffer[6]*256*256*256+ 4369 s->Phone.Data.File->Used += msg.Buffer[6]*256*256*256+
4288 msg.Buffer[7]*256*256+ 4370 msg.Buffer[7]*256*256+
4289 msg.Buffer[8]*256+ 4371 msg.Buffer[8]*256+
4290 msg.Buffer[9]; 4372 msg.Buffer[9];
4291 smprintf(s,"Length of file part: %i\n", 4373 smprintf(s,"Length of file part: %i\n",
4292 msg.Buffer[6]*256*256*256+ 4374 msg.Buffer[6]*256*256*256+
4293 msg.Buffer[7]*256*256+ 4375 msg.Buffer[7]*256*256+
4294 msg.Buffer[8]*256+ 4376 msg.Buffer[8]*256+
4295 msg.Buffer[9]); 4377 msg.Buffer[9]);
4296 s->Phone.Data.File->Buffer = (unsigned char *)realloc(s->Phone.Data.File->Buffer,s->Phone.Data.File->Used); 4378 s->Phone.Data.File->Buffer = (unsigned char *)realloc(s->Phone.Data.File->Buffer,s->Phone.Data.File->Used);
4297 memcpy(s->Phone.Data.File->Buffer+old,msg.Buffer+10,s->Phone.Data.File->Used-old); 4379 memcpy(s->Phone.Data.File->Buffer+old,msg.Buffer+10,s->Phone.Data.File->Used-old);
4298 return ERR_NONE; 4380 return ERR_NONE;
4299} 4381}
4300 4382
4301static GSM_Error N6510_GetFilePart(GSM_StateMachine *s, GSM_File *File) 4383static GSM_Error N6510_GetFilePart(GSM_StateMachine *s, GSM_File *File)
4302{ 4384{
4303 GSM_Phone_N6510Data*Priv = &s->Phone.Data.Priv.N6510; 4385 GSM_Phone_N6510Data*Priv = &s->Phone.Data.Priv.N6510;
4304 int old; 4386 int old;
4305 GSM_Error error; 4387 GSM_Error error;
4306 unsigned char req[] = { 4388 unsigned char req[] = {
4307 N7110_FRAME_HEADER, 0x0E, 0x00, 0x00, 0x00, 0x01, 4389 N7110_FRAME_HEADER, 0x0E, 0x00, 0x00, 0x00, 0x01,
4308 0x00, 0x01, /* Folder or file number */ 4390 0x00, 0x01, /* Folder or file number */
4309 0x00, 0x00, 0x00, 0x00,/* Start from xxx byte */ 4391 0x00, 0x00, 0x00, 0x00,/* Start from xxx byte */
4310 0x00, 0x00, 4392 0x00, 0x00,
4311 0x03, 0xE8}; /* Read xxx bytes */ 4393 0x03, 0xE8}; /* Read xxx bytes */
4312 4394
4313 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED; 4395 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
4314 4396
4315 if (File->Used == 0x00) { 4397 if (File->Used == 0x00) {
4316 error = N6510_GetFileFolderInfo(s, File, ID_GetFile); 4398 error = N6510_GetFileFolderInfo(s, File, ID_GetFile);
4317 if (error != ERR_NONE) return error; 4399 if (error != ERR_NONE) return error;
4318 File->Used = 0; 4400 File->Used = 0;
4319 } 4401 }
4320 4402
4321 old = File->Used; 4403 old = File->Used;
4322 req[8] = atoi(File->ID_FullName) / 256; 4404 req[8] = atoi(File->ID_FullName) / 256;
4323 req[9] = atoi(File->ID_FullName) % 256; 4405 req[9] = atoi(File->ID_FullName) % 256;
4324 req[10] = old / (256*256*256); 4406 req[10] = old / (256*256*256);
4325 req[11] = old / (256*256); 4407 req[11] = old / (256*256);
4326 req[12] = old / 256; 4408 req[12] = old / 256;
4327 req[13] = old % 256; 4409 req[13] = old % 256;
4328 4410
4329 s->Phone.Data.File = File; 4411 s->Phone.Data.File = File;
4330 smprintf(s, "Getting file part from filesystem\n"); 4412 smprintf(s, "Getting file part from filesystem\n");
4331 error=GSM_WaitFor (s, req, 18, 0x6D, 4, ID_GetFile); 4413 error=GSM_WaitFor (s, req, 18, 0x6D, 4, ID_GetFile);
4332 if (error != ERR_NONE) return error; 4414 if (error != ERR_NONE) return error;
4333 if (File->Used - old != (0x03 * 256 + 0xE8)) { 4415 if (File->Used - old != (0x03 * 256 + 0xE8)) {
4334 if (N6510_FindFileCheckSum(File->Buffer, File->Used) != Priv->FileCheckSum) { 4416 if (N6510_FindFileCheckSum(File->Buffer, File->Used) != Priv->FileCheckSum) {
4335 smprintf(s,"File2 checksum is %i, File checksum is %i\n",N6510_FindFileCheckSum(File->Buffer, File->Used),Priv->FileCheckSum); 4417 smprintf(s,"File2 checksum is %i, File checksum is %i\n",N6510_FindFileCheckSum(File->Buffer, File->Used),Priv->FileCheckSum);
4336 return ERR_WRONGCRC; 4418 return ERR_WRONGCRC;
4337 } 4419 }
4338 return ERR_EMPTY; 4420 return ERR_EMPTY;
4339 } 4421 }
4340 return ERR_NONE; 4422 return ERR_NONE;
4341} 4423}
4342 4424
4343static GSM_Error N6510_SetReadOnly(GSM_StateMachine *s, unsigned char *ID, bool enable) 4425static GSM_Error N6510_SetReadOnly(GSM_StateMachine *s, unsigned char *ID, bool enable)
4344{ 4426{
4345 unsigned char SetAttr[] = { 4427 unsigned char SetAttr[] = {
4346 N7110_FRAME_HEADER, 0x18, 0x00, 0x00, 0x00, 0x01, 4428 N7110_FRAME_HEADER, 0x18, 0x00, 0x00, 0x00, 0x01,
4347 0x00, 0x20}; /* File ID */ 4429 0x00, 0x20}; /* File ID */
4348 4430
4349 if (!enable) SetAttr[4] = 0x06; 4431 if (!enable) SetAttr[4] = 0x06;
4350 4432
4351 SetAttr[8] = atoi(ID) / 256; 4433 SetAttr[8] = atoi(ID) / 256;
4352 SetAttr[9] = atoi(ID) % 256; 4434 SetAttr[9] = atoi(ID) % 256;
4353 smprintf(s, "Setting readonly attribute\n"); 4435 smprintf(s, "Setting readonly attribute\n");
4354 return GSM_WaitFor (s, SetAttr, 10, 0x6D, 4, ID_DeleteFile); 4436 return GSM_WaitFor (s, SetAttr, 10, 0x6D, 4, ID_DeleteFile);
4355} 4437}
4356 4438
4357static GSM_Error N6510_ReplyAddFileHeader(GSM_Protocol_Message msg, GSM_StateMachine *s) 4439static GSM_Error N6510_ReplyAddFileHeader(GSM_Protocol_Message msg, GSM_StateMachine *s)
4358{ 4440{
4359 switch (msg.Buffer[3]) { 4441 switch (msg.Buffer[3]) {
4360 case 0x03: 4442 case 0x03:
4361 smprintf(s,"File header added\n"); 4443 smprintf(s,"File header added\n");
4362 sprintf(s->Phone.Data.File->ID_FullName,"%i",msg.Buffer[9]); 4444 sprintf(s->Phone.Data.File->ID_FullName,"%i",msg.Buffer[9]);
4363 return ERR_NONE; 4445 return ERR_NONE;
4364 case 0x13: 4446 case 0x13:
4365 return ERR_NONE; 4447 return ERR_NONE;
4366 } 4448 }
4367 return ERR_UNKNOWNRESPONSE; 4449 return ERR_UNKNOWNRESPONSE;
4368} 4450}
4369 4451
4370static GSM_Error N6510_ReplyAddFilePart(GSM_Protocol_Message msg, GSM_StateMachine *s) 4452static GSM_Error N6510_ReplyAddFilePart(GSM_Protocol_Message msg, GSM_StateMachine *s)
4371{ 4453{
4372 return ERR_NONE; 4454 return ERR_NONE;
4373} 4455}
4374 4456
4375static GSM_Error N6510_AddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos) 4457static GSM_Error N6510_AddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos)
4376{ 4458{
4377 GSM_Phone_N6510Data*Priv = &s->Phone.Data.Priv.N6510; 4459 GSM_Phone_N6510Data*Priv = &s->Phone.Data.Priv.N6510;
4378 GSM_File File2; 4460 GSM_File File2;
4379 GSM_Error error; 4461 GSM_Error error;
4380 int j; 4462 int j;
4381 unsigned char Header[400] = { 4463 unsigned char Header[400] = {
4382 N7110_FRAME_HEADER, 0x02, 0x00, 0x00, 0x00, 0x01, 4464 N7110_FRAME_HEADER, 0x02, 0x00, 0x00, 0x00, 0x01,
4383 0x00, 0x0C, /* parent folder ID */ 4465 0x00, 0x0C, /* parent folder ID */
4384 0x00, 0x00, 0x00, 0xE8}; 4466 0x00, 0x00, 0x00, 0xE8};
4385 unsigned char Add[15000] = { 4467 unsigned char Add[15000] = {
4386 N7110_FRAME_HEADER, 0x40, 0x00, 0x00, 0x00, 0x01, 4468 N7110_FRAME_HEADER, 0x40, 0x00, 0x00, 0x00, 0x01,
4387 0x00, 0x04, /* file ID */ 4469 0x00, 0x04, /* file ID */
4388 0x00, 0x00, 4470 0x00, 0x00,
4389 0x01, 0x28}; /* length */ 4471 0x01, 0x28}; /* length */
4390 unsigned char end[30] = { 4472 unsigned char end[30] = {
4391 N7110_FRAME_HEADER, 0x40, 0x00, 0x00, 0x00, 0x01, 4473 N7110_FRAME_HEADER, 0x40, 0x00, 0x00, 0x00, 0x01,
4392 0x00, 0x04, /* file ID */ 4474 0x00, 0x04, /* file ID */
4393 0x00, 0x00, 0x00, 0x00}; 4475 0x00, 0x00, 0x00, 0x00};
4394 4476
4395 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED; 4477 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
4396 4478
4397 s->Phone.Data.File = File; 4479 s->Phone.Data.File = File;
4398 4480
4399 if (*Pos == 0) { 4481 if (*Pos == 0) {
4400 error = N6510_SearchForFileName(s,File); 4482 error = N6510_SearchForFileName(s,File);
4401 if (error == ERR_NONE) return ERR_INVALIDLOCATION; 4483 if (error == ERR_NONE) return ERR_FILEALREADYEXIST;
4402 if (error != ERR_EMPTY) return error; 4484 if (error != ERR_EMPTY) return error;
4403 4485
4404 Header[8] = atoi(File->ID_FullName) / 256; 4486 Header[8] = atoi(File->ID_FullName) / 256;
4405 Header[9] = atoi(File->ID_FullName) % 256; 4487 Header[9] = atoi(File->ID_FullName) % 256;
4406 memset(Header+14, 0x00, 300); 4488 memset(Header+14, 0x00, 300);
4407 CopyUnicodeString(Header+14,File->Name); 4489 CopyUnicodeString(Header+14,File->Name);
4408 Header[222] = File->Used / (256*256*256); 4490 Header[222] = File->Used / (256*256*256);
4409 Header[223] = File->Used / (256*256); 4491 Header[223] = File->Used / (256*256);
4410 Header[224] = File->Used / 256; 4492 Header[224] = File->Used / 256;
4411 Header[225] = File->Used % 256; 4493 Header[225] = File->Used % 256;
4412 switch(File->Type) { 4494 switch(File->Type) {
4413 case GSM_File_Image_JPG : Header[231]=0x02; Header[233]=0x01; break; 4495 case GSM_File_Image_JPG : Header[231]=0x02; Header[233]=0x01; break;
4414 case GSM_File_Image_BMP : Header[231]=0x02; Header[233]=0x02; break; 4496 case GSM_File_Image_BMP : Header[231]=0x02; Header[233]=0x02; break;
4415 case GSM_File_Image_PNG : Header[231]=0x02; Header[233]=0x03; break; 4497 case GSM_File_Image_PNG : Header[231]=0x02; Header[233]=0x03; break;
4416 case GSM_File_Image_GIF : Header[231]=0x02; Header[233]=0x05; break; 4498 case GSM_File_Image_GIF : Header[231]=0x02; Header[233]=0x05; break;
4417 case GSM_File_Image_WBMP : Header[231]=0x02; Header[233]=0x09; break; 4499 case GSM_File_Image_WBMP : Header[231]=0x02; Header[233]=0x09; break;
4418 case GSM_File_Sound_AMR : Header[231]=0x04; Header[233]=0x01; break; 4500 case GSM_File_Sound_AMR : Header[231]=0x04; Header[233]=0x01; break;
4419 case GSM_File_Sound_MIDI : Header[231]=0x04; Header[233]=0x05; break; //Header[238]=0x01; 4501 case GSM_File_Sound_MIDI : Header[231]=0x04; Header[233]=0x05; break; //Header[238]=0x01;
4420 case GSM_File_Sound_NRT : Header[231]=0x04; Header[233]=0x06; break; 4502 case GSM_File_Sound_NRT : Header[231]=0x04; Header[233]=0x06; break;
4421 case GSM_File_Video_3GP : Header[231]=0x08; Header[233]=0x05; break; 4503 case GSM_File_Video_3GP : Header[231]=0x08; Header[233]=0x05; break;
4422 case GSM_File_Java_JAR : Header[231]=0x10; Header[233]=0x01; break; 4504 case GSM_File_Java_JAR : Header[231]=0x10; Header[233]=0x01; break;
4423#ifdef DEVELOP 4505#ifdef DEVELOP
4424 case GSM_File_MMS: 4506 case GSM_File_MMS:
4425 Header[214]=0x07; 4507 Header[214]=0x07;
4426 Header[215]=0xd3; 4508 Header[215]=0xd3;
4427 Header[216]=0x06; 4509 Header[216]=0x06;
4428 Header[217]=0x01; 4510 Header[217]=0x01;
4429 Header[218]=0x12; 4511 Header[218]=0x12;
4430 Header[219]=0x13; 4512 Header[219]=0x13;
4431 Header[220]=0x29; 4513 Header[220]=0x29;
4432 Header[233]=0x01; 4514 Header[233]=0x01;
4433 break; 4515 break;
4434#endif 4516#endif
4435 default : Header[231]=0x01; Header[233]=0x05; 4517 default : Header[231]=0x01; Header[233]=0x05;
4436 } 4518 }
4437 Header[235] = 0x01; 4519 Header[235] = 0x01;
4438 Header[236] = atoi(File->ID_FullName) / 256; 4520 Header[236] = atoi(File->ID_FullName) / 256;
4439 Header[237] = atoi(File->ID_FullName) % 256; 4521 Header[237] = atoi(File->ID_FullName) % 256;
4440 if (File->Protected) Header[238] = 0x01; //Nokia forward lock 4522 if (File->Protected) Header[238] = 0x01; //Nokia forward lock
4441 if (File->Hidden) Header[241] = 0x01; 4523 if (File->Hidden) Header[241] = 0x01;
4442 if (File->System) Header[242] = 0x01; //fixme 4524 if (File->System) Header[242] = 0x01; //fixme
4443 smprintf(s, "Adding file header\n"); 4525 smprintf(s, "Adding file header\n");
4444 error=GSM_WaitFor (s, Header, 246, 0x6D, 4, ID_AddFile); 4526 error=GSM_WaitFor (s, Header, 246, 0x6D, 4, ID_AddFile);
4445 if (error != ERR_NONE) return error; 4527 if (error != ERR_NONE) return error;
4446 } 4528 }
4447 4529
4448 j = 1000; 4530 j = 1000;
4449 if (File->Used - *Pos < 1000) j = File->Used - *Pos; 4531 if (File->Used - *Pos < 1000) j = File->Used - *Pos;
4450 Add[ 8] = atoi(File->ID_FullName) / 256; 4532 Add[ 8] = atoi(File->ID_FullName) / 256;
4451 Add[ 9] = atoi(File->ID_FullName) % 256; 4533 Add[ 9] = atoi(File->ID_FullName) % 256;
4452 Add[12] = j / 256; 4534 Add[12] = j / 256;
4453 Add[13] = j % 256; 4535 Add[13] = j % 256;
4454 memcpy(Add+14,File->Buffer+(*Pos),j); 4536 memcpy(Add+14,File->Buffer+(*Pos),j);
4455 smprintf(s, "Adding file part %i %i\n",*Pos,j); 4537 smprintf(s, "Adding file part %i %i\n",*Pos,j);
4456 error=GSM_WaitFor (s, Add, 14+j, 0x6D, 4, ID_AddFile); 4538 error=GSM_WaitFor (s, Add, 14+j, 0x6D, 4, ID_AddFile);
4457 if (error != ERR_NONE) return error; 4539 if (error != ERR_NONE) return error;
4458 *Pos = *Pos + j; 4540 *Pos = *Pos + j;
4459 4541
4460 if (j < 1000) { 4542 if (j < 1000) {
4461 end[8] = atoi(File->ID_FullName) / 256; 4543 end[8] = atoi(File->ID_FullName) / 256;
4462 end[9] = atoi(File->ID_FullName) % 256; 4544 end[9] = atoi(File->ID_FullName) % 256;
4463 smprintf(s, "Frame for ending adding file\n"); 4545 smprintf(s, "Frame for ending adding file\n");
4464 error = GSM_WaitFor (s, end, 14, 0x6D, 4, ID_AddFile); 4546 error = GSM_WaitFor (s, end, 14, 0x6D, 4, ID_AddFile);
4465 if (error != ERR_NONE) return error; 4547 if (error != ERR_NONE) return error;
4466 4548
4467 strcpy(File2.ID_FullName,File->ID_FullName); 4549 strcpy(File2.ID_FullName,File->ID_FullName);
4468 error = N6510_GetFileFolderInfo(s, &File2, ID_GetFileInfo); 4550 error = N6510_GetFileFolderInfo(s, &File2, ID_GetFileInfo);
4469 if (error != ERR_NONE) return error; 4551 if (error != ERR_NONE) return error;
4470 4552
4471 if (!File->ModifiedEmpty) { 4553 if (!File->ModifiedEmpty) {
4472 Header[3] = 0x12; 4554 Header[3] = 0x12;
4473 Header[4] = 0x01; 4555 Header[4] = 0x01;
4474 Header[12] = 0x00; 4556 Header[12] = 0x00;
4475 Header[13] = 0xE8; 4557 Header[13] = 0xE8;
4476 Header[8] = atoi(File->ID_FullName) / 256; 4558 Header[8] = atoi(File->ID_FullName) / 256;
4477 Header[9] = atoi(File->ID_FullName) % 256; 4559 Header[9] = atoi(File->ID_FullName) % 256;
4478 memset(Header+14, 0x00, 300); 4560 memset(Header+14, 0x00, 300);
4479 CopyUnicodeString(Header+14,File->Name); 4561 CopyUnicodeString(Header+14,File->Name);
4480 NOKIA_EncodeDateTime(s,Header+214,&File->Modified); 4562 NOKIA_EncodeDateTime(s,Header+214,&File->Modified);
4481 /* When you save too big file for phone and it changes 4563 /* When you save too big file for phone and it changes
4482 * size (some part is cut by firmware), you HAVE to write 4564 * size (some part is cut by firmware), you HAVE to write
4483 * here correct file size. In other case filesystem 4565 * here correct file size. In other case filesystem
4484 * will be damaged 4566 * will be damaged
4485 */ 4567 */
4486 Header[224] = File2.Used / 256; 4568 Header[224] = File2.Used / 256;
4487 Header[225] = File2.Used % 256; 4569 Header[225] = File2.Used % 256;
4488 Header[226] = Priv->FileToken / 256; 4570 Header[226] = Priv->FileToken / 256;
4489 Header[227] = Priv->FileToken % 256; 4571 Header[227] = Priv->FileToken % 256;
4490 switch(File->Type) { 4572 switch(File->Type) {
4491 case GSM_File_Image_JPG : Header[231]=0x02; Header[233]=0x01; break; 4573 case GSM_File_Image_JPG : Header[231]=0x02; Header[233]=0x01; break;
4492 case GSM_File_Image_BMP : Header[231]=0x02; Header[233]=0x02; break; 4574 case GSM_File_Image_BMP : Header[231]=0x02; Header[233]=0x02; break;
4493 case GSM_File_Image_PNG : Header[231]=0x02; Header[233]=0x03; break; 4575 case GSM_File_Image_PNG : Header[231]=0x02; Header[233]=0x03; break;
4494 case GSM_File_Image_GIF : Header[231]=0x02; Header[233]=0x05; break; 4576 case GSM_File_Image_GIF : Header[231]=0x02; Header[233]=0x05; break;
4495 case GSM_File_Image_WBMP : Header[231]=0x02; Header[233]=0x09; break; 4577 case GSM_File_Image_WBMP : Header[231]=0x02; Header[233]=0x09; break;
4496 case GSM_File_Sound_AMR : Header[231]=0x04; Header[233]=0x01; break; 4578 case GSM_File_Sound_AMR : Header[231]=0x04; Header[233]=0x01; break;
4497 case GSM_File_Sound_MIDI : Header[231]=0x04; Header[233]=0x05; break; //Header[238]=0x01; 4579 case GSM_File_Sound_MIDI : Header[231]=0x04; Header[233]=0x05; break; //Header[238]=0x01;
4498 case GSM_File_Sound_NRT : Header[231]=0x04; Header[233]=0x06; break; 4580 case GSM_File_Sound_NRT : Header[231]=0x04; Header[233]=0x06; break;
4499 case GSM_File_Video_3GP : Header[231]=0x08; Header[233]=0x05; break; 4581 case GSM_File_Video_3GP : Header[231]=0x08; Header[233]=0x05; break;
4500 case GSM_File_Java_JAR : Header[231]=0x10; Header[233]=0x01; break; 4582 case GSM_File_Java_JAR : Header[231]=0x10; Header[233]=0x01; break;
4501#ifdef DEVELOP 4583#ifdef DEVELOP
4502 case GSM_File_MMS: 4584 case GSM_File_MMS:
4503 Header[214]=0x07; 4585 Header[214]=0x07;
4504 Header[215]=0xd3; 4586 Header[215]=0xd3;
4505 Header[216]=0x06; 4587 Header[216]=0x06;
4506 Header[217]=0x01; 4588 Header[217]=0x01;
4507 Header[218]=0x12; 4589 Header[218]=0x12;
4508 Header[219]=0x13; 4590 Header[219]=0x13;
4509 Header[220]=0x29; 4591 Header[220]=0x29;
4510 Header[233]=0x01; 4592 Header[233]=0x01;
4511 break; 4593 break;
4512#endif 4594#endif
4513 default : Header[231]=0x01; Header[233]=0x05; 4595 default : Header[231]=0x01; Header[233]=0x05;
4514 } 4596 }
4515 Header[235] = 0x01; 4597 Header[235] = 0x01;
4516 Header[236] = Priv->ParentID / 256; 4598 Header[236] = Priv->ParentID / 256;
4517 Header[237] = Priv->ParentID % 256; 4599 Header[237] = Priv->ParentID % 256;
4518 smprintf(s, "Adding file header\n"); 4600 smprintf(s, "Adding file header\n");
4519 error=GSM_WaitFor (s, Header, 246, 0x6D, 4, ID_AddFile); 4601 error=GSM_WaitFor (s, Header, 246, 0x6D, 4, ID_AddFile);
4520 if (error != ERR_NONE) return error; 4602 if (error != ERR_NONE) return error;
4521 } 4603 }
4522 4604
4523 /* Can't delete from phone menu */ 4605 /* Can't delete from phone menu */
4524 if (File->ReadOnly) { 4606 if (File->ReadOnly) {
4525 error = N6510_SetReadOnly(s, File->ID_FullName, true); 4607 error = N6510_SetReadOnly(s, File->ID_FullName, true);
4526 if (error != ERR_NONE) return error; 4608 if (error != ERR_NONE) return error;
4527 } 4609 }
4528 4610
4529 if (N6510_FindFileCheckSum(File->Buffer, File->Used) != Priv->FileCheckSum) { 4611 if (N6510_FindFileCheckSum(File->Buffer, File->Used) != Priv->FileCheckSum) {
4530 smprintf(s,"File2 checksum is %i, File checksum is %i\n",N6510_FindFileCheckSum(File->Buffer, File->Used),Priv->FileCheckSum); 4612 smprintf(s,"File2 checksum is %i, File checksum is %i\n",N6510_FindFileCheckSum(File->Buffer, File->Used),Priv->FileCheckSum);
4531 return ERR_WRONGCRC; 4613 return ERR_WRONGCRC;
4532 } 4614 }
4533 4615
4534 return ERR_EMPTY; 4616 return ERR_EMPTY;
4535 } 4617 }
4536 4618
4537 return ERR_NONE; 4619 return ERR_NONE;
4538} 4620}
4539 4621
4540static GSM_Error N6510_ReplyDeleteFile(GSM_Protocol_Message msg, GSM_StateMachine *s) 4622static GSM_Error N6510_ReplyDeleteFile(GSM_Protocol_Message msg, GSM_StateMachine *s)
4541{ 4623{
4542 return ERR_NONE; 4624 return ERR_NONE;
4543} 4625}
4544 4626
4545static GSM_Error N6510_DeleteFile(GSM_StateMachine *s, unsigned char *ID) 4627static GSM_Error N6510_DeleteFile(GSM_StateMachine *s, unsigned char *ID)
4546{ 4628{
4547 GSM_Errorerror; 4629 GSM_Errorerror;
4548 unsigned char Delete[40] = { 4630 unsigned char Delete[40] = {
4549 N7110_FRAME_HEADER, 0x1E, 0x00, 0x00, 0x00, 0x01, 4631 N7110_FRAME_HEADER, 0x1E, 0x00, 0x00, 0x00, 0x01,
4550 0x00, 0x35}; /* File ID */ 4632 0x00, 0x35}; /* File ID */
4551 4633
4552 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED; 4634 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
4553 4635
4554 error = N6510_SetReadOnly(s, ID, false); 4636 error = N6510_SetReadOnly(s, ID, false);
4555 if (error != ERR_NONE) return error; 4637 if (error != ERR_NONE) return error;
4556 4638
4557 Delete[8] = atoi(ID) / 256; 4639 Delete[8] = atoi(ID) / 256;
4558 Delete[9] = atoi(ID) % 256; 4640 Delete[9] = atoi(ID) % 256;
4559 return GSM_WaitFor (s, Delete, 10, 0x6D, 4, ID_DeleteFile); 4641 return GSM_WaitFor (s, Delete, 10, 0x6D, 4, ID_DeleteFile);
4560} 4642}
4561 4643
4562static GSM_Error N6510_ReplyAddFolder(GSM_Protocol_Message msg, GSM_StateMachine *s) 4644static GSM_Error N6510_ReplyAddFolder(GSM_Protocol_Message msg, GSM_StateMachine *s)
4563{ 4645{
4564 sprintf(s->Phone.Data.File->ID_FullName,"%i",msg.Buffer[9]); 4646 sprintf(s->Phone.Data.File->ID_FullName,"%i",msg.Buffer[9]);
4565 return ERR_NONE; 4647 return ERR_NONE;
4566} 4648}
4567 4649
4568static GSM_Error N6510_AddFolder(GSM_StateMachine *s, GSM_File *File) 4650static GSM_Error N6510_AddFolder(GSM_StateMachine *s, GSM_File *File)
4569{ 4651{
4570 GSM_Errorerror; 4652 GSM_Errorerror;
4571 unsigned char Header[400] = { 4653 unsigned char Header[400] = {
4572 N7110_FRAME_HEADER, 0x04, 0x00, 0x00, 0x00, 0x01, 4654 N7110_FRAME_HEADER, 0x04, 0x00, 0x00, 0x00, 0x01,
4573 0x00, 0x0C, /* parent folder ID */ 4655 0x00, 0x0C, /* parent folder ID */
4574 0x00, 0x00, 0x00, 0xE8}; 4656 0x00, 0x00, 0x00, 0xE8};
4575 4657
4576 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED; 4658 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
4577 4659
4578 error = N6510_SearchForFileName(s,File); 4660 error = N6510_SearchForFileName(s,File);
4579 if (error == ERR_NONE) return ERR_INVALIDLOCATION; 4661 if (error == ERR_NONE) return ERR_INVALIDLOCATION;
4580 if (error != ERR_EMPTY) return error; 4662 if (error != ERR_EMPTY) return error;
4581 4663
4582 Header[8] = atoi(File->ID_FullName) / 256; 4664 Header[8] = atoi(File->ID_FullName) / 256;
4583 Header[9] = atoi(File->ID_FullName) % 256; 4665 Header[9] = atoi(File->ID_FullName) % 256;
4584 memset(Header+14, 0x00, 300); 4666 memset(Header+14, 0x00, 300);
4585 CopyUnicodeString(Header+14,File->Name); 4667 CopyUnicodeString(Header+14,File->Name);
4586 Header[233] = 0x02; 4668 Header[233] = 0x02;
4587 Header[235] = 0x01; 4669 Header[235] = 0x01;
4588 Header[236] = atoi(File->ID_FullName) / 256; 4670 Header[236] = atoi(File->ID_FullName) / 256;
4589 Header[237] = atoi(File->ID_FullName) % 256; 4671 Header[237] = atoi(File->ID_FullName) % 256;
4590 4672
4591 s->Phone.Data.File = File; 4673 s->Phone.Data.File = File;
4592 smprintf(s, "Adding folder\n"); 4674 smprintf(s, "Adding folder\n");
4593 error = GSM_WaitFor (s, Header, 246, 0x6D, 4, ID_AddFolder); 4675 error = GSM_WaitFor (s, Header, 246, 0x6D, 4, ID_AddFolder);
@@ -4625,614 +4707,605 @@ static GSM_Error N6510_EnableGPRSAccessPoint(GSM_StateMachine *s)
4625 error = GSM_WaitFor (s, req, 16, 0x43, 4, ID_EnableGPRSPoint); 4707 error = GSM_WaitFor (s, req, 16, 0x43, 4, ID_EnableGPRSPoint);
4626 if (error != ERR_NONE) return error; 4708 if (error != ERR_NONE) return error;
4627 } 4709 }
4628 return error; 4710 return error;
4629} 4711}
4630 4712
4631#endif 4713#endif
4632 4714
4633static GSM_Error N6510_ReplyGetGPRSAccessPoint(GSM_Protocol_Message msg, GSM_StateMachine *s) 4715static GSM_Error N6510_ReplyGetGPRSAccessPoint(GSM_Protocol_Message msg, GSM_StateMachine *s)
4634{ 4716{
4635 GSM_GPRSAccessPoint *point = s->Phone.Data.GPRSPoint; 4717 GSM_GPRSAccessPoint *point = s->Phone.Data.GPRSPoint;
4636 4718
4637 switch (msg.Buffer[13]) { 4719 switch (msg.Buffer[13]) {
4638 case 0x01: 4720 case 0x01:
4639 smprintf(s,"Active GPRS point received\n"); 4721 smprintf(s,"Active GPRS point received\n");
4640 point->Active = false; 4722 point->Active = false;
4641 if (point->Location == msg.Buffer[18]) point->Active = true; 4723 if (point->Location == msg.Buffer[18]) point->Active = true;
4642 return ERR_NONE; 4724 return ERR_NONE;
4643 case 0xD2: 4725 case 0xD2:
4644 smprintf(s,"Names for GPRS points received\n"); 4726 smprintf(s,"Names for GPRS points received\n");
4645 CopyUnicodeString(point->Name,msg.Buffer+18+(point->Location-1)*42); 4727 CopyUnicodeString(point->Name,msg.Buffer+18+(point->Location-1)*42);
4646 smprintf(s,"\"%s\"\n",DecodeUnicodeString(point->Name)); 4728 smprintf(s,"\"%s\"\n",DecodeUnicodeString(point->Name));
4647 return ERR_NONE; 4729 return ERR_NONE;
4648 case 0xF2: 4730 case 0xF2:
4649 smprintf(s,"URL for GPRS points received\n"); 4731 smprintf(s,"URL for GPRS points received\n");
4650 CopyUnicodeString(point->URL,msg.Buffer+18+(point->Location-1)*202); 4732 CopyUnicodeString(point->URL,msg.Buffer+18+(point->Location-1)*202);
4651 smprintf(s,"\"%s\"\n",DecodeUnicodeString(point->URL)); 4733 smprintf(s,"\"%s\"\n",DecodeUnicodeString(point->URL));
4652 return ERR_NONE; 4734 return ERR_NONE;
4653 } 4735 }
4654 return ERR_UNKNOWNRESPONSE; 4736 return ERR_UNKNOWNRESPONSE;
4655} 4737}
4656 4738
4657static GSM_Error N6510_GetGPRSAccessPoint(GSM_StateMachine *s, GSM_GPRSAccessPoint *point) 4739static GSM_Error N6510_GetGPRSAccessPoint(GSM_StateMachine *s, GSM_GPRSAccessPoint *point)
4658{ 4740{
4659 GSM_Errorerror; 4741 GSM_Errorerror;
4660 unsigned char URL[] = { 4742 unsigned char URL[] = {
4661 N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00, 4743 N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00,
4662 0x00, 0x00, 0x00, 0x03, 0xF2, 0x00, 0x00}; 4744 0x00, 0x00, 0x00, 0x03, 0xF2, 0x00, 0x00};
4663 unsigned char Name[] = { 4745 unsigned char Name[] = {
4664 N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00, 4746 N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00,
4665 0x01, 0x00, 0x00, 0x00, 0xD2, 0x00, 0x00}; 4747 0x01, 0x00, 0x00, 0x00, 0xD2, 0x00, 0x00};
4666 unsigned char Active[] = { 4748 unsigned char Active[] = {
4667 N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00, 4749 N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00,
4668 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}; 4750 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00};
4669 4751
4670 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOGPRSPOINT)) return ERR_NOTSUPPORTED; 4752 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOGPRSPOINT)) return ERR_NOTSUPPORTED;
4671 if (point->Location < 1) return ERR_UNKNOWN; 4753 if (point->Location < 1) return ERR_UNKNOWN;
4672 if (point->Location > 5) return ERR_INVALIDLOCATION; 4754 if (point->Location > 5) return ERR_INVALIDLOCATION;
4673 4755
4674 s->Phone.Data.GPRSPoint = point; 4756 s->Phone.Data.GPRSPoint = point;
4675 4757
4676#ifdef DEVELOP 4758#ifdef DEVELOP
4677 error = N6510_EnableGPRSAccessPoint(s); 4759 error = N6510_EnableGPRSAccessPoint(s);
4678 if (error != ERR_NONE) return error; 4760 if (error != ERR_NONE) return error;
4679#endif 4761#endif
4680 4762
4681 smprintf(s, "Getting GPRS access point name\n"); 4763 smprintf(s, "Getting GPRS access point name\n");
4682 error=GSM_WaitFor (s, Name, 16, 0x43, 4, ID_GetGPRSPoint); 4764 error=GSM_WaitFor (s, Name, 16, 0x43, 4, ID_GetGPRSPoint);
4683 if (error != ERR_NONE) return error; 4765 if (error != ERR_NONE) return error;
4684 4766
4685 smprintf(s, "Getting GPRS access point URL\n"); 4767 smprintf(s, "Getting GPRS access point URL\n");
4686 error=GSM_WaitFor (s, URL, 16, 0x43, 4, ID_GetGPRSPoint); 4768 error=GSM_WaitFor (s, URL, 16, 0x43, 4, ID_GetGPRSPoint);
4687 if (error != ERR_NONE) return error; 4769 if (error != ERR_NONE) return error;
4688 4770
4689 smprintf(s, "Getting number of active GPRS access point\n"); 4771 smprintf(s, "Getting number of active GPRS access point\n");
4690 error=GSM_WaitFor (s, Active, 16, 0x43, 4, ID_GetGPRSPoint); 4772 error=GSM_WaitFor (s, Active, 16, 0x43, 4, ID_GetGPRSPoint);
4691 if (error != ERR_NONE) return error; 4773 if (error != ERR_NONE) return error;
4692 4774
4693 if (UnicodeLength(point->URL)==0 && UnicodeLength(point->Name)==0) return ERR_EMPTY; 4775 if (UnicodeLength(point->URL)==0 && UnicodeLength(point->Name)==0) return ERR_EMPTY;
4694 return error; 4776 return error;
4695} 4777}
4696 4778
4697static GSM_Error N6510_ReplySetGPRSAccessPoint1(GSM_Protocol_Message msg, GSM_StateMachine *s) 4779static GSM_Error N6510_ReplySetGPRSAccessPoint1(GSM_Protocol_Message msg, GSM_StateMachine *s)
4698{ 4780{
4699 switch (msg.Buffer[13]) { 4781 switch (msg.Buffer[13]) {
4700 case 0x01: 4782 case 0x01:
4701 case 0xD2: 4783 case 0xD2:
4702 case 0xF2: 4784 case 0xF2:
4703 memcpy(s->Phone.Data.Priv.N6510.GPRSPoints,msg.Buffer,msg.Length); 4785 memcpy(s->Phone.Data.Priv.N6510.GPRSPoints,msg.Buffer,msg.Length);
4704 s->Phone.Data.Priv.N6510.GPRSPointsLength = msg.Length; 4786 s->Phone.Data.Priv.N6510.GPRSPointsLength = msg.Length;
4705 return ERR_NONE; 4787 return ERR_NONE;
4706 } 4788 }
4707 return ERR_UNKNOWNRESPONSE; 4789 return ERR_UNKNOWNRESPONSE;
4708} 4790}
4709 4791
4710static GSM_Error N6510_SetGPRSAccessPoint(GSM_StateMachine *s, GSM_GPRSAccessPoint *point) 4792static GSM_Error N6510_SetGPRSAccessPoint(GSM_StateMachine *s, GSM_GPRSAccessPoint *point)
4711{ 4793{
4712 unsigned char*buff = s->Phone.Data.Priv.N6510.GPRSPoints; 4794 unsigned char*buff = s->Phone.Data.Priv.N6510.GPRSPoints;
4713 GSM_Errorerror; 4795 GSM_Errorerror;
4714 unsigned char URL[] = { 4796 unsigned char URL[] = {
4715 N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00, 4797 N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00,
4716 0x00, 0x00, 0x00, 0x03, 0xF2, 0x00, 0x00}; 4798 0x00, 0x00, 0x00, 0x03, 0xF2, 0x00, 0x00};
4717 unsigned char Name[] = { 4799 unsigned char Name[] = {
4718 N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00, 4800 N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00,
4719 0x01, 0x00, 0x00, 0x00, 0xD2, 0x00, 0x00}; 4801 0x01, 0x00, 0x00, 0x00, 0xD2, 0x00, 0x00};
4720 unsigned char Active[] = { 4802 unsigned char Active[] = {
4721 N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00, 4803 N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00,
4722 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}; 4804 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00};
4723 4805
4724 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOGPRSPOINT)) return ERR_NOTSUPPORTED; 4806 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOGPRSPOINT)) return ERR_NOTSUPPORTED;
4725 if (point->Location < 1) return ERR_UNKNOWN; 4807 if (point->Location < 1) return ERR_UNKNOWN;
4726 if (point->Location > 5) return ERR_INVALIDLOCATION; 4808 if (point->Location > 5) return ERR_INVALIDLOCATION;
4727 4809
4728 s->Phone.Data.GPRSPoint = point; 4810 s->Phone.Data.GPRSPoint = point;
4729 4811
4730#ifdef DEVELOP 4812#ifdef DEVELOP
4731 error = N6510_EnableGPRSAccessPoint(s); 4813 error = N6510_EnableGPRSAccessPoint(s);
4732 if (error != ERR_NONE) return error; 4814 if (error != ERR_NONE) return error;
4733#endif 4815#endif
4734 4816
4735 smprintf(s, "Getting GPRS access point name\n"); 4817 smprintf(s, "Getting GPRS access point name\n");
4736 error=GSM_WaitFor (s, Name, 16, 0x43, 4, ID_SetGPRSPoint); 4818 error=GSM_WaitFor (s, Name, 16, 0x43, 4, ID_SetGPRSPoint);
4737 if (error != ERR_NONE) return error; 4819 if (error != ERR_NONE) return error;
4738 CopyUnicodeString(buff+18+(point->Location-1)*42,point->Name); 4820 CopyUnicodeString(buff+18+(point->Location-1)*42,point->Name);
4739 buff[0] = 0x00; 4821 buff[0] = 0x00;
4740 buff[1] = 0x01; 4822 buff[1] = 0x01;
4741 buff[2] = 0x01; 4823 buff[2] = 0x01;
4742 buff[3] = 0x07; 4824 buff[3] = 0x07;
4743 smprintf(s, "Setting GPRS access point name\n"); 4825 smprintf(s, "Setting GPRS access point name\n");
4744 error=GSM_WaitFor (s, buff, s->Phone.Data.Priv.N6510.GPRSPointsLength, 0x43, 4, ID_SetGPRSPoint); 4826 error=GSM_WaitFor (s, buff, s->Phone.Data.Priv.N6510.GPRSPointsLength, 0x43, 4, ID_SetGPRSPoint);
4745 if (error != ERR_NONE) return error; 4827 if (error != ERR_NONE) return error;
4746 4828
4747 smprintf(s, "Getting GPRS access point URL\n"); 4829 smprintf(s, "Getting GPRS access point URL\n");
4748 error=GSM_WaitFor (s, URL, 16, 0x43, 4, ID_SetGPRSPoint); 4830 error=GSM_WaitFor (s, URL, 16, 0x43, 4, ID_SetGPRSPoint);
4749 if (error != ERR_NONE) return error; 4831 if (error != ERR_NONE) return error;
4750 CopyUnicodeString(buff+18+(point->Location-1)*42,point->URL); 4832 CopyUnicodeString(buff+18+(point->Location-1)*42,point->URL);
4751 buff[0] = 0x00; 4833 buff[0] = 0x00;
4752 buff[1] = 0x01; 4834 buff[1] = 0x01;
4753 buff[2] = 0x01; 4835 buff[2] = 0x01;
4754 buff[3] = 0x07; 4836 buff[3] = 0x07;
4755 smprintf(s, "Setting GPRS access point URL\n"); 4837 smprintf(s, "Setting GPRS access point URL\n");
4756 error=GSM_WaitFor (s, buff, s->Phone.Data.Priv.N6510.GPRSPointsLength, 0x43, 4, ID_SetGPRSPoint); 4838 error=GSM_WaitFor (s, buff, s->Phone.Data.Priv.N6510.GPRSPointsLength, 0x43, 4, ID_SetGPRSPoint);
4757 if (error != ERR_NONE) return error; 4839 if (error != ERR_NONE) return error;
4758 4840
4759 if (point->Active) { 4841 if (point->Active) {
4760 smprintf(s, "Getting number of active GPRS access point\n"); 4842 smprintf(s, "Getting number of active GPRS access point\n");
4761 error=GSM_WaitFor (s, Active, 16, 0x43, 4, ID_SetGPRSPoint); 4843 error=GSM_WaitFor (s, Active, 16, 0x43, 4, ID_SetGPRSPoint);
4762 if (error != ERR_NONE) return error; 4844 if (error != ERR_NONE) return error;
4763 buff[0] = 0x00; 4845 buff[0] = 0x00;
4764 buff[1] = 0x01; 4846 buff[1] = 0x01;
4765 buff[2] = 0x01; 4847 buff[2] = 0x01;
4766 buff[3] = 0x07; 4848 buff[3] = 0x07;
4767 buff[18]= point->Location; 4849 buff[18]= point->Location;
4768 smprintf(s, "Setting number of active GPRS access point\n"); 4850 smprintf(s, "Setting number of active GPRS access point\n");
4769 error=GSM_WaitFor (s, buff, s->Phone.Data.Priv.N6510.GPRSPointsLength, 0x43, 4, ID_SetGPRSPoint); 4851 error=GSM_WaitFor (s, buff, s->Phone.Data.Priv.N6510.GPRSPointsLength, 0x43, 4, ID_SetGPRSPoint);
4770 if (error != ERR_NONE) return error; 4852 if (error != ERR_NONE) return error;
4771 } 4853 }
4772 4854
4773 return error; 4855 return error;
4774} 4856}
4775 4857
4776/* ToDo support - 6310 style */ 4858/* ToDo support - 6310 style */
4777static GSM_Error N6510_ReplyGetToDoStatus1(GSM_Protocol_Message msg, GSM_StateMachine *s) 4859static GSM_Error N6510_ReplyGetToDoStatus1(GSM_Protocol_Message msg, GSM_StateMachine *s)
4778{ 4860{
4779 int i; 4861 int i;
4780 GSM_NOKIACalToDoLocations*Last = &s->Phone.Data.Priv.N6510.LastToDo; 4862 GSM_NOKIACalToDoLocations*Last = &s->Phone.Data.Priv.N6510.LastToDo;
4781 4863
4782 smprintf(s, "TODO locations received\n"); 4864 smprintf(s, "TODO locations received\n");
4783 Last->Number=msg.Buffer[6]*256+msg.Buffer[7]; 4865 Last->Number=msg.Buffer[6]*256+msg.Buffer[7];
4784 smprintf(s, "Number of Entries: %i\n",Last->Number); 4866 smprintf(s, "Number of Entries: %i\n",Last->Number);
4785 smprintf(s, "Locations: "); 4867 smprintf(s, "Locations: ");
4786 for (i=0;i<Last->Number;i++) { 4868 for (i=0;i<Last->Number;i++) {
4787 Last->Location[i]=msg.Buffer[12+(i*4)]*256+msg.Buffer[(i*4)+13]; 4869 Last->Location[i]=msg.Buffer[12+(i*4)]*256+msg.Buffer[(i*4)+13];
4788 smprintf(s, "%i ",Last->Location[i]); 4870 smprintf(s, "%i ",Last->Location[i]);
4789 } 4871 }
4790 smprintf(s, "\n"); 4872 smprintf(s, "\n");
4791 return ERR_NONE; 4873 return ERR_NONE;
4792} 4874}
4793 4875
4794/* ToDo support - 6310 style */ 4876/* ToDo support - 6310 style */
4795static GSM_Error N6510_GetToDoStatus1(GSM_StateMachine *s, GSM_ToDoStatus *status) 4877static GSM_Error N6510_GetToDoStatus1(GSM_StateMachine *s, GSM_ToDoStatus *status)
4796{ 4878{
4797 GSM_Error error; 4879 GSM_Error error;
4798 GSM_NOKIACalToDoLocations*LastToDo = &s->Phone.Data.Priv.N6510.LastToDo; 4880 GSM_NOKIACalToDoLocations*LastToDo = &s->Phone.Data.Priv.N6510.LastToDo;
4799 unsigned char reqLoc[] = { 4881 unsigned char reqLoc[] = {
4800 N6110_FRAME_HEADER, 4882 N6110_FRAME_HEADER,
4801 0x15, 0x01, 0x00, 0x00, 4883 0x15, 0x01, 0x00, 0x00,
4802 0x00, 0x00, 0x00}; 4884 0x00, 0x00, 0x00};
4803 4885
4804 smprintf(s, "Getting ToDo locations\n"); 4886 smprintf(s, "Getting ToDo locations\n");
4805 error = GSM_WaitFor (s, reqLoc, 10, 0x55, 4, ID_GetToDo); 4887 error = GSM_WaitFor (s, reqLoc, 10, 0x55, 4, ID_GetToDo);
4806 if (error != ERR_NONE) return error; 4888 if (error != ERR_NONE) return error;
4807 4889
4808 status->Used = LastToDo->Number; 4890 status->Used = LastToDo->Number;
4809 return ERR_NONE; 4891 return ERR_NONE;
4810} 4892}
4811 4893
4812static GSM_Error N6510_GetToDoStatus2(GSM_StateMachine *s, GSM_ToDoStatus *status) 4894static GSM_Error N6510_GetToDoStatus2(GSM_StateMachine *s, GSM_ToDoStatus *status)
4813{ 4895{
4814 GSM_NOKIACalToDoLocations*LastToDo = &s->Phone.Data.Priv.N6510.LastToDo; 4896 GSM_NOKIACalToDoLocations*LastToDo = &s->Phone.Data.Priv.N6510.LastToDo;
4815 GSM_Error error; 4897 GSM_Error error;
4816 4898
4817 error = N6510_GetCalendarInfo3(s,LastToDo,false); 4899 error = N6510_GetCalendarInfo3(s,LastToDo,1);
4818 if (error!=ERR_NONE) return error; 4900 if (error!=ERR_NONE) return error;
4819 4901
4820 status->Used = LastToDo->Number; 4902 status->Used = LastToDo->Number;
4821 return ERR_NONE; 4903 return ERR_NONE;
4822} 4904}
4823 4905
4824static GSM_Error N6510_GetToDoStatus(GSM_StateMachine *s, GSM_ToDoStatus *status) 4906static GSM_Error N6510_GetToDoStatus(GSM_StateMachine *s, GSM_ToDoStatus *status)
4825{ 4907{
4826 status->Used = 0; 4908 status->Used = 0;
4827 4909
4828 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO63)) { 4910 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO63)) {
4829 return N6510_GetToDoStatus1(s, status); 4911 return N6510_GetToDoStatus1(s, status);
4830 } else if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO66)) { 4912 } else if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO66)) {
4831 return N6510_GetToDoStatus2(s, status); 4913 return N6510_GetToDoStatus2(s, status);
4832 } else { 4914 } else {
4833 return ERR_NOTSUPPORTED; 4915 return ERR_NOTSUPPORTED;
4834 } 4916 }
4835} 4917}
4836 4918
4837/* ToDo support - 6310 style */ 4919/* ToDo support - 6310 style */
4838static GSM_Error N6510_ReplyGetToDo1(GSM_Protocol_Message msg, GSM_StateMachine *s) 4920static GSM_Error N6510_ReplyGetToDo1(GSM_Protocol_Message msg, GSM_StateMachine *s)
4839{ 4921{
4840 GSM_ToDoEntry *Last = s->Phone.Data.ToDo; 4922 GSM_ToDoEntry *Last = s->Phone.Data.ToDo;
4841 4923
4842 smprintf(s, "TODO received method 1\n"); 4924 smprintf(s, "TODO received method 1\n");
4843 4925
4844 switch (msg.Buffer[4]) { 4926 switch (msg.Buffer[4]) {
4845 case 1 : Last->Priority = GSM_Priority_High; break; 4927 case 1 : Last->Priority = GSM_Priority_High; break;
4846 case 2 : Last->Priority = GSM_Priority_Medium; break; 4928 case 2 : Last->Priority = GSM_Priority_Medium; break;
4847 case 3 : Last->Priority = GSM_Priority_Low; break; 4929 case 3 : Last->Priority = GSM_Priority_Low; break;
4848 default: return ERR_UNKNOWN; 4930 default: return ERR_UNKNOWN;
4849 } 4931 }
4850 smprintf(s, "Priority: %i\n",msg.Buffer[4]); 4932 smprintf(s, "Priority: %i\n",msg.Buffer[4]);
4851 4933
4852 CopyUnicodeString(Last->Entries[0].Text,msg.Buffer+14); 4934 CopyUnicodeString(Last->Entries[0].Text,msg.Buffer+14);
4853 Last->Entries[0].EntryType = TODO_TEXT; 4935 Last->Entries[0].EntryType = TODO_TEXT;
4854 Last->EntriesNum = 1; 4936 Last->EntriesNum = 1;
4855 smprintf(s, "Text: \"%s\"\n",DecodeUnicodeString(Last->Entries[0].Text)); 4937 smprintf(s, "Text: \"%s\"\n",DecodeUnicodeString(Last->Entries[0].Text));
4856 4938
4857 return ERR_NONE; 4939 return ERR_NONE;
4858} 4940}
4859 4941
4860/* ToDo support - 6310 style */ 4942/* ToDo support - 6310 style */
4861static GSM_Error N6510_GetNextToDo1(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool refresh) 4943static GSM_Error N6510_GetNextToDo1(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool refresh)
4862{ 4944{
4863 GSM_Error error; 4945 GSM_Error error;
4864 GSM_ToDoStatus status; 4946 GSM_ToDoStatus status;
4865 GSM_NOKIACalToDoLocations*LastToDo = &s->Phone.Data.Priv.N6510.LastToDo; 4947 GSM_NOKIACalToDoLocations*LastToDo = &s->Phone.Data.Priv.N6510.LastToDo;
4866 unsigned char reqGet[] = { 4948 unsigned char reqGet[] = {
4867 N6110_FRAME_HEADER, 4949 N6110_FRAME_HEADER,
4868 0x03, 0x00, 0x00, 0x80, 0x00, 4950 0x03, 0x00, 0x00, 0x80, 0x00,
4869 0x00, 0x17}; /* Location */ 4951 0x00, 0x17}; /* Location */
4870 4952
4871 if (refresh) { 4953 if (refresh) {
4872 error = N6510_GetToDoStatus(s, &status); 4954 error = N6510_GetToDoStatus(s, &status);
4873 if (error != ERR_NONE) return error; 4955 if (error != ERR_NONE) return error;
4874 ToDo->Location = 1; 4956 ToDo->Location = 1;
4875 } else { 4957 } else {
4876 ToDo->Location++; 4958 ToDo->Location++;
4877 } 4959 }
4878 if (ToDo->Location > LastToDo->Number) return ERR_EMPTY; 4960 if (ToDo->Location > LastToDo->Number) return ERR_EMPTY;
4879 4961
4880 reqGet[8] = LastToDo->Location[ToDo->Location-1] / 256; 4962 reqGet[8] = LastToDo->Location[ToDo->Location-1] / 256;
4881 reqGet[9] = LastToDo->Location[ToDo->Location-1] % 256; 4963 reqGet[9] = LastToDo->Location[ToDo->Location-1] % 256;
4882 s->Phone.Data.ToDo = ToDo; 4964 s->Phone.Data.ToDo = ToDo;
4883 smprintf(s, "Getting ToDo\n"); 4965 smprintf(s, "Getting ToDo\n");
4884 return GSM_WaitFor (s, reqGet, 10, 0x55, 4, ID_GetToDo); 4966 return GSM_WaitFor (s, reqGet, 10, 0x55, 4, ID_GetToDo);
4885} 4967}
4886 4968
4887static GSM_Error N6510_ReplyGetToDoStatus2(GSM_Protocol_Message msg, GSM_StateMachine *s) 4969static GSM_Error N6510_ReplyGetToDoStatus2(GSM_Protocol_Message msg, GSM_StateMachine *s)
4888{ 4970{
4889 return N6510_ReplyGetCalendarInfo3(msg, s, &s->Phone.Data.Priv.N6510.LastToDo); 4971 return N6510_ReplyGetCalendarInfo3(msg, s, &s->Phone.Data.Priv.N6510.LastToDo);
4890} 4972}
4891 4973
4892/* Similiar to getting calendar method 3 */ 4974/* Similiar to getting calendar method 3 */
4893static GSM_Error N6510_ReplyGetToDo2(GSM_Protocol_Message msg, GSM_StateMachine *s) 4975static GSM_Error N6510_ReplyGetToDo2(GSM_Protocol_Message msg, GSM_StateMachine *s)
4894{ 4976{
4895 GSM_ToDoEntry *Last = s->Phone.Data.ToDo; 4977 GSM_ToDoEntry *Last = s->Phone.Data.ToDo;
4896 GSM_DateTime Date; 4978 GSM_DateTime Date;
4897 unsigned long diff; 4979 unsigned long diff;
4898 4980
4899 smprintf(s, "ToDo received method 2\n"); 4981 smprintf(s, "ToDo received method 2\n");
4900 4982
4901 switch (msg.Buffer[44]) { 4983 switch (msg.Buffer[44]) {
4902 case 0x10: Last->Priority = GSM_Priority_Low; break; 4984 case 0x10: Last->Priority = GSM_Priority_Low; break;
4903 case 0x20: Last->Priority = GSM_Priority_Medium; break; 4985 case 0x20: Last->Priority = GSM_Priority_Medium; break;
4904 case 0x30: Last->Priority = GSM_Priority_High; break; 4986 case 0x30: Last->Priority = GSM_Priority_High; break;
4905 default : return ERR_UNKNOWN; 4987 default : return ERR_UNKNOWN;
4906 } 4988 }
4907 4989
4908 memcpy(Last->Entries[0].Text,msg.Buffer+54,msg.Buffer[51]*2); 4990 memcpy(Last->Entries[0].Text,msg.Buffer+54,msg.Buffer[51]*2);
4909 Last->Entries[0].Text[msg.Buffer[51]*2] = 0; 4991 Last->Entries[0].Text[msg.Buffer[51]*2] = 0;
4910 Last->Entries[0].Text[msg.Buffer[51]*2+1] = 0; 4992 Last->Entries[0].Text[msg.Buffer[51]*2+1] = 0;
4911 Last->Entries[0].EntryType = TODO_TEXT; 4993 Last->Entries[0].EntryType = TODO_TEXT;
4912 smprintf(s, "Text: \"%s\"\n",DecodeUnicodeString(Last->Entries[0].Text)); 4994 smprintf(s, "Text: \"%s\"\n",DecodeUnicodeString(Last->Entries[0].Text));
4913 4995
4914 smprintf(s,"EndTime: %04i-%02i-%02i %02i:%02i\n", 4996 smprintf(s,"EndTime: %04i-%02i-%02i %02i:%02i\n",
4915 msg.Buffer[34]*256+msg.Buffer[35], 4997 msg.Buffer[34]*256+msg.Buffer[35],
4916 msg.Buffer[36],msg.Buffer[37],msg.Buffer[38], 4998 msg.Buffer[36],msg.Buffer[37],msg.Buffer[38],
4917 msg.Buffer[39]); 4999 msg.Buffer[39]);
4918 Date.Year = msg.Buffer[34]*256+msg.Buffer[35]; 5000 Date.Year = msg.Buffer[34]*256+msg.Buffer[35];
4919 Date.Month = msg.Buffer[36]; 5001 Date.Month = msg.Buffer[36];
4920 Date.Day = msg.Buffer[37]; 5002 Date.Day = msg.Buffer[37];
4921 Date.Hour = msg.Buffer[38]; 5003 Date.Hour = msg.Buffer[38];
4922 Date.Minute = msg.Buffer[39]; 5004 Date.Minute = msg.Buffer[39];
4923 Date.Second= 0; 5005 Date.Second= 0;
4924 Last->Entries[1].EntryType = TODO_END_DATETIME; 5006 Last->Entries[1].EntryType = TODO_END_DATETIME;
4925 memcpy(&Last->Entries[1].Date,&Date,sizeof(GSM_DateTime)); 5007 memcpy(&Last->Entries[1].Date,&Date,sizeof(GSM_DateTime));
4926 5008
4927 smprintf(s,"StartTime: %04i-%02i-%02i %02i:%02i\n", 5009 smprintf(s,"StartTime: %04i-%02i-%02i %02i:%02i\n",
4928 msg.Buffer[28]*256+msg.Buffer[29], 5010 msg.Buffer[28]*256+msg.Buffer[29],
4929 msg.Buffer[30],msg.Buffer[31],msg.Buffer[32], 5011 msg.Buffer[30],msg.Buffer[31],msg.Buffer[32],
4930 msg.Buffer[33]); 5012 msg.Buffer[33]);
4931 Date.Year = msg.Buffer[28]*256+msg.Buffer[29]; 5013 Date.Year = msg.Buffer[28]*256+msg.Buffer[29];
4932 Date.Month = msg.Buffer[30]; 5014 Date.Month = msg.Buffer[30];
4933 Date.Day = msg.Buffer[31]; 5015 Date.Day = msg.Buffer[31];
4934 Date.Hour = msg.Buffer[32]; 5016 Date.Hour = msg.Buffer[32];
4935 Date.Minute = msg.Buffer[33]; 5017 Date.Minute = msg.Buffer[33];
4936 Date.Second= 0; 5018 Date.Second= 0;
4937 5019
4938 Last->EntriesNum = 2; 5020 Last->EntriesNum = 2;
4939 5021
4940 if (msg.Buffer[45] == 0x01) { 5022 if (msg.Buffer[45] == 0x01) {
4941 Last->Entries[2].Number = msg.Buffer[45]; 5023 Last->Entries[2].Number = msg.Buffer[45];
4942 Last->Entries[2].EntryType = TODO_COMPLETED; 5024 Last->Entries[2].EntryType = TODO_COMPLETED;
4943 Last->EntriesNum++; 5025 Last->EntriesNum++;
4944 smprintf(s,"Completed\n"); 5026 smprintf(s,"Completed\n");
4945 } 5027 }
4946 5028
4947 if (msg.Buffer[14] == 0xFF && msg.Buffer[15] == 0xFF && msg.Buffer[16] == 0xff && msg.Buffer[17] == 0xff) 5029 if (msg.Buffer[14] == 0xFF && msg.Buffer[15] == 0xFF && msg.Buffer[16] == 0xff && msg.Buffer[17] == 0xff) {
4948 {
4949 smprintf(s, "No alarm\n"); 5030 smprintf(s, "No alarm\n");
4950 } else { 5031 } else {
4951 diff = ((unsigned int)msg.Buffer[14]) << 24; 5032 diff = ((unsigned int)msg.Buffer[14]) << 24;
4952 diff += ((unsigned int)msg.Buffer[15]) << 16; 5033 diff += ((unsigned int)msg.Buffer[15]) << 16;
4953 diff += ((unsigned int)msg.Buffer[16]) << 8; 5034 diff += ((unsigned int)msg.Buffer[16]) << 8;
4954 diff += msg.Buffer[17]; 5035 diff += msg.Buffer[17];
4955 5036
4956 memcpy(&Last->Entries[Last->EntriesNum].Date,&Date,sizeof(GSM_DateTime)); 5037 memcpy(&Last->Entries[Last->EntriesNum].Date,&Date,sizeof(GSM_DateTime));
4957 GetTimeDifference(diff, &Last->Entries[Last->EntriesNum].Date, false, 60); 5038 GetTimeDifference(diff, &Last->Entries[Last->EntriesNum].Date, false, 60);
4958 smprintf(s, "Alarm date : %02i-%02i-%04i %02i:%02i:%02i\n", 5039 smprintf(s, "Alarm date : %02i-%02i-%04i %02i:%02i:%02i\n",
4959 Last->Entries[Last->EntriesNum].Date.Day, Last->Entries[Last->EntriesNum].Date.Month, 5040 Last->Entries[Last->EntriesNum].Date.Day, Last->Entries[Last->EntriesNum].Date.Month,
4960 Last->Entries[Last->EntriesNum].Date.Year, Last->Entries[Last->EntriesNum].Date.Hour, 5041 Last->Entries[Last->EntriesNum].Date.Year, Last->Entries[Last->EntriesNum].Date.Hour,
4961 Last->Entries[Last->EntriesNum].Date.Minute,Last->Entries[Last->EntriesNum].Date.Second); 5042 Last->Entries[Last->EntriesNum].Date.Minute,Last->Entries[Last->EntriesNum].Date.Second);
4962 5043
4963 Last->Entries[Last->EntriesNum].EntryType = TODO_ALARM_DATETIME; 5044 Last->Entries[Last->EntriesNum].EntryType = TODO_ALARM_DATETIME;
4964 if (msg.Buffer[22]==0x00 && msg.Buffer[23]==0x00 && 5045 if (msg.Buffer[22]==0x00 && msg.Buffer[23]==0x00 &&
4965 msg.Buffer[24]==0x00 && msg.Buffer[25]==0x00) 5046 msg.Buffer[24]==0x00 && msg.Buffer[25]==0x00)
4966 { 5047 {
4967 Last->Entries[Last->EntriesNum].EntryType = TODO_SILENT_ALARM_DATETIME; 5048 Last->Entries[Last->EntriesNum].EntryType = TODO_SILENT_ALARM_DATETIME;
4968 smprintf(s, "Alarm type : Silent\n"); 5049 smprintf(s, "Alarm type : Silent\n");
4969 } 5050 }
4970 Last->EntriesNum++; 5051 Last->EntriesNum++;
4971 } 5052 }
4972 5053
4973 return ERR_NONE; 5054 return ERR_NONE;
4974} 5055}
4975 5056
4976/* ToDo support - 6610 style */ 5057/* ToDo support - 6610 style */
4977static GSM_Error N6510_GetNextToDo2(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool refresh) 5058static GSM_Error N6510_GetNextToDo2(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool refresh)
4978{ 5059{
4979 GSM_Error error; 5060 GSM_Error error;
4980 GSM_NOKIACalToDoLocations *LastToDo = &s->Phone.Data.Priv.N6510.LastToDo; 5061 GSM_NOKIACalToDoLocations *LastToDo = &s->Phone.Data.Priv.N6510.LastToDo;
4981 /* The same to getting calendar method 3 */
4982 unsigned char req[] = {
4983 N6110_FRAME_HEADER,0x7D,0x00,0x00,0x00,0x00,
4984 0x00,0x99, /* Location */
4985 0xff,0xff,0xff,0xff,0x01};
4986 5062
4987 if (refresh) { 5063 if (refresh) {
4988 error=N6510_GetCalendarInfo3(s,LastToDo,false); 5064 error=N6510_GetCalendarInfo3(s,LastToDo,1);
4989 if (error!=ERR_NONE) return error; 5065 if (error!=ERR_NONE) return error;
4990 ToDo->Location = 1; 5066 ToDo->Location = 1;
4991 } else { 5067 } else {
4992 ToDo->Location++; 5068 ToDo->Location++;
4993 } 5069 }
4994 5070
4995 if (ToDo->Location > LastToDo->Number) return ERR_EMPTY; 5071 if (ToDo->Location > LastToDo->Number) return ERR_EMPTY;
4996 5072
4997 req[8] = LastToDo->Location[ToDo->Location-1] / 256;
4998 req[9] = LastToDo->Location[ToDo->Location-1] % 256;
4999
5000 s->Phone.Data.ToDo = ToDo; 5073 s->Phone.Data.ToDo = ToDo;
5001 smprintf(s, "Getting todo method 2\n"); 5074 smprintf(s, "Getting todo method 2\n");
5002 return GSM_WaitFor (s, req, 15, 0x13, 4, ID_GetToDo); 5075 return N6510_PrivGetGenericCalendar3(s, LastToDo->Location[ToDo->Location-1], ID_GetToDo);
5003} 5076}
5004 5077
5005static GSM_Error N6510_GetNextToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool refresh) 5078static GSM_Error N6510_GetNextToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, bool refresh)
5006{ 5079{
5007 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO63)) { 5080 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO63)) {
5008 return N6510_GetNextToDo1(s, ToDo, refresh); 5081 return N6510_GetNextToDo1(s, ToDo, refresh);
5009 } else if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO66)) { 5082 } else if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO66)) {
5010 return N6510_GetNextToDo2(s, ToDo, refresh); 5083 return N6510_GetNextToDo2(s, ToDo, refresh);
5011 } else { 5084 } else {
5012 return ERR_NOTSUPPORTED; 5085 return ERR_NOTSUPPORTED;
5013 } 5086 }
5014} 5087}
5015 5088
5016/* ToDo support - 6310 style */ 5089/* ToDo support - 6310 style */
5017static GSM_Error N6510_ReplyDeleteAllToDo1(GSM_Protocol_Message msg, GSM_StateMachine *s) 5090static GSM_Error N6510_ReplyDeleteAllToDo1(GSM_Protocol_Message msg, GSM_StateMachine *s)
5018{ 5091{
5019 smprintf(s, "All TODO deleted\n"); 5092 smprintf(s, "All TODO deleted\n");
5020 return ERR_NONE; 5093 return ERR_NONE;
5021} 5094}
5022 5095
5023/* ToDo support - 6310 style */ 5096/* ToDo support - 6310 style */
5024static GSM_Error N6510_DeleteAllToDo1(GSM_StateMachine *s) 5097static GSM_Error N6510_DeleteAllToDo1(GSM_StateMachine *s)
5025{ 5098{
5026 unsigned char req[] = {N6110_FRAME_HEADER, 0x11}; 5099 unsigned char req[] = {N6110_FRAME_HEADER, 0x11};
5027 5100
5028 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO63)) { 5101 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO63)) {
5029 return ERR_NOTSUPPORTED; 5102 return ERR_NOTSUPPORTED;
5030 } 5103 }
5031 5104
5032 smprintf(s, "Deleting all ToDo method 1\n"); 5105 smprintf(s, "Deleting all ToDo method 1\n");
5033 return GSM_WaitFor (s, req, 4, 0x55, 4, ID_DeleteAllToDo); 5106 return GSM_WaitFor (s, req, 4, 0x55, 4, ID_DeleteAllToDo);
5034} 5107}
5035 5108
5036static GSM_Error N6510_DeleteToDo2(GSM_StateMachine *s, GSM_ToDoEntry *ToDo) 5109static GSM_Error N6510_DeleteToDo2(GSM_StateMachine *s, GSM_ToDoEntry *ToDo)
5037{ 5110{
5038 GSM_Error error; 5111 GSM_Error error;
5039 GSM_NOKIACalToDoLocations *LastToDo = &s->Phone.Data.Priv.N6510.LastToDo; 5112 GSM_NOKIACalToDoLocations *LastToDo = &s->Phone.Data.Priv.N6510.LastToDo;
5040 GSM_CalendarEntry Note; 5113 GSM_CalendarEntry Note;
5041 5114
5042 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO66)) { 5115 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO66)) {
5043 return ERR_NOTSUPPORTED; 5116 return ERR_NOTSUPPORTED;
5044 } 5117 }
5045 5118
5046 error=N6510_GetCalendarInfo3(s,LastToDo,false); 5119 error=N6510_GetCalendarInfo3(s,LastToDo,1);
5047 if (error!=ERR_NONE) return error; 5120 if (error!=ERR_NONE) return error;
5048 5121
5049 smprintf(s, "Deleting ToDo method 2\n"); 5122 smprintf(s, "Deleting ToDo method 2\n");
5050 5123
5051 if (ToDo->Location > LastToDo->Number || ToDo->Location == 0) return ERR_INVALIDLOCATION; 5124 if (ToDo->Location > LastToDo->Number || ToDo->Location == 0) return ERR_INVALIDLOCATION;
5052 5125
5053 Note.Location = LastToDo->Location[ToDo->Location-1]; 5126 Note.Location = LastToDo->Location[ToDo->Location-1];
5054 return N71_65_DelCalendar(s,&Note); 5127 return N71_65_DelCalendar(s,&Note);
5055} 5128}
5056 5129
5057/* ToDo support - 6310 style */ 5130/* ToDo support - 6310 style */
5058static GSM_Error N6510_ReplyGetToDoFirstLoc1(GSM_Protocol_Message msg, GSM_StateMachine *s) 5131static GSM_Error N6510_ReplyGetToDoFirstLoc1(GSM_Protocol_Message msg, GSM_StateMachine *s)
5059{ 5132{
5060 smprintf(s, "TODO first location received method 1: %02x\n",msg.Buffer[9]); 5133 smprintf(s, "TODO first location received method 1: %02x\n",msg.Buffer[9]);
5061 s->Phone.Data.ToDo->Location = msg.Buffer[9]; 5134 s->Phone.Data.ToDo->Location = msg.Buffer[9];
5062 return ERR_NONE; 5135 return ERR_NONE;
5063} 5136}
5064 5137
5065/* ToDo support - 6310 style */ 5138/* ToDo support - 6310 style */
5066static GSM_Error N6510_ReplyAddToDo1(GSM_Protocol_Message msg, GSM_StateMachine *s) 5139static GSM_Error N6510_ReplyAddToDo1(GSM_Protocol_Message msg, GSM_StateMachine *s)
5067{ 5140{
5068 smprintf(s, "TODO set OK\n"); 5141 smprintf(s, "TODO set OK\n");
5069 return ERR_NONE; 5142 return ERR_NONE;
5070} 5143}
5071 5144
5072/* ToDo support - 6310 style */ 5145/* ToDo support - 6310 style */
5073static GSM_Error N6510_AddToDo1(GSM_StateMachine *s, GSM_ToDoEntry *ToDo) 5146static GSM_Error N6510_AddToDo1(GSM_StateMachine *s, GSM_ToDoEntry *ToDo)
5074{ 5147{
5075 int Text, Alarm, EndTime, Completed, ulen, Phone; 5148 int Text, Alarm, EndTime, Completed, ulen, Phone;
5076 GSM_Error error; 5149 GSM_Error error;
5077 unsigned char reqLoc[] = {N6110_FRAME_HEADER, 0x0F}; 5150 unsigned char reqLoc[] = {N6110_FRAME_HEADER, 0x0F};
5078 unsigned char reqSet[500] = { 5151 unsigned char reqSet[500] = {
5079 N6110_FRAME_HEADER, 0x01, 5152 N6110_FRAME_HEADER, 0x01,
5080 0x03, /* Priority */ 5153 0x03, /* Priority */
5081 0x00, /* Length of text */ 5154 0x00, /* Length of text */
5082 0x80,0x00,0x00, 5155 0x80,0x00,0x00,
5083 0x18}; /* Location */ 5156 0x18}; /* Location */
5084 5157
5085 s->Phone.Data.ToDo = ToDo; 5158 s->Phone.Data.ToDo = ToDo;
5086 5159
5087 smprintf(s, "Getting first ToDo location\n"); 5160 smprintf(s, "Getting first ToDo location\n");
5088 error = GSM_WaitFor (s, reqLoc, 4, 0x55, 4, ID_SetToDo); 5161 error = GSM_WaitFor (s, reqLoc, 4, 0x55, 4, ID_SetToDo);
5089 if (error != ERR_NONE) return error; 5162 if (error != ERR_NONE) return error;
5090 reqSet[9] = ToDo->Location; 5163 reqSet[9] = ToDo->Location;
5091 5164
5092 switch (ToDo->Priority) { 5165 switch (ToDo->Priority) {
5093 case GSM_Priority_Low: reqSet[4] = 3; break; 5166 case GSM_Priority_Low: reqSet[4] = 3; break;
5094 case GSM_Priority_Medium: reqSet[4] = 2; break; 5167 case GSM_Priority_Medium: reqSet[4] = 2; break;
5095 case GSM_Priority_High: reqSet[4] = 1; break; 5168 case GSM_Priority_High: reqSet[4] = 1; break;
5096 } 5169 }
5097 5170
5098 GSM_ToDoFindDefaultTextTimeAlarmCompleted(ToDo, &Text, &Alarm, &Completed, &EndTime, &Phone); 5171 GSM_ToDoFindDefaultTextTimeAlarmCompleted(ToDo, &Text, &Alarm, &Completed, &EndTime, &Phone);
5099 5172
5100 if (Text == -1) return ERR_NOTSUPPORTED; /* XXX: shouldn't this be handled different way? */ 5173 if (Text == -1) return ERR_NOTSUPPORTED; /* XXX: shouldn't this be handled different way? */
5101 ulen = UnicodeLength(ToDo->Entries[Text].Text); 5174 ulen = UnicodeLength(ToDo->Entries[Text].Text);
5102 reqSet[5] = ulen+1; 5175 reqSet[5] = ulen+1;
5103 CopyUnicodeString(reqSet+10,ToDo->Entries[Text].Text); 5176 CopyUnicodeString(reqSet+10,ToDo->Entries[Text].Text);
5104 reqSet[10+ulen*2] = 0x00; 5177 reqSet[10+ulen*2] = 0x00;
5105 reqSet[10+ulen*2+1] = 0x00; 5178 reqSet[10+ulen*2+1] = 0x00;
5106 smprintf(s, "Adding ToDo method 1\n"); 5179 smprintf(s, "Adding ToDo method 1\n");
5107 return GSM_WaitFor (s, reqSet, 12+ulen*2, 0x55, 4, ID_SetToDo); 5180 return GSM_WaitFor (s, reqSet, 12+ulen*2, 0x55, 4, ID_SetToDo);
5108} 5181}
5109 5182
5110static GSM_Error N6510_ReplyAddToDo2(GSM_Protocol_Message msg, GSM_StateMachine *s) 5183static GSM_Error N6510_ReplyAddToDo2(GSM_Protocol_Message msg, GSM_StateMachine *s)
5111{ 5184{
5112 smprintf(s, "ToDo added method 2\n"); 5185 smprintf(s, "ToDo added method 2\n");
5113 return ERR_NONE; 5186 return ERR_NONE;
5114} 5187}
5115 5188
5116static GSM_Error N6510_ReplyGetToDoFirstLoc2(GSM_Protocol_Message msg, GSM_StateMachine *s) 5189static GSM_Error N6510_ReplyGetToDoFirstLoc2(GSM_Protocol_Message msg, GSM_StateMachine *s)
5117{ 5190{
5118 smprintf(s, "First ToDo location method 2: %i\n",msg.Buffer[8]*256+msg.Buffer[9]); 5191 smprintf(s, "First ToDo location method 2: %i\n",msg.Buffer[8]*256+msg.Buffer[9]);
5119 s->Phone.Data.ToDo->Location = msg.Buffer[9]; 5192 s->Phone.Data.ToDo->Location = msg.Buffer[9];
5120 return ERR_NONE; 5193 return ERR_NONE;
5121} 5194}
5122 5195
5123static GSM_Error N6510_AddToDo2(GSM_StateMachine *s, GSM_ToDoEntry *ToDo) 5196static GSM_Error N6510_AddToDo2(GSM_StateMachine *s, GSM_ToDoEntry *ToDo)
5124{ 5197{
5125 GSM_CalendarEntryNote; 5198 GSM_CalendarEntryNote;
5126 time_t t_time1,t_time2; 5199 time_t t_time1,t_time2;
5127 long diff; 5200 long diff;
5128 GSM_Error error; 5201 GSM_Error error;
5129 GSM_DateTime DT; 5202 GSM_DateTime DT;
5130 int Text, Alarm, EndTime, Completed, count=54, Phone; 5203 int Text, Alarm, EndTime, Completed, count=54, Phone;
5131 unsigned char reqLoc[] = {N6110_FRAME_HEADER, 0x95, 0x01}; 5204 unsigned char reqLoc[] = {N6110_FRAME_HEADER, 0x95, 0x01};
5132 unsigned char req[5000] = { 5205 unsigned char req[5000] = {
5133 N6110_FRAME_HEADER, 0x65, 5206 N6110_FRAME_HEADER, 0x65,
5134 0x01, /* 0 = calendar, 1 = todo */ 5207 0x01, /* 0 = calendar, 1 = todo */
5135 0x00, 0x00, 0x00, 5208 0x00, 0x00, 0x00,
5136 0x00, 0x00, /* location */ 5209 0x00, 0x00, /* location */
5137 0x00, 0x00, 0x00, 0x00, 5210 0x00, 0x00, 0x00, 0x00,
5138 0xFF, 0xFF, 0xFF, 0xFF, /* alarm */ 5211 0xFF, 0xFF, 0xFF, 0xFF, /* alarm */
5139 0x80, 0x00, 0x00, 5212 0x80, 0x00, 0x00,
5140 0x01, /* note icon */ 5213 0x01, /* note icon */
5141 0xFF, 0xFF, 0xFF, 0xFF, /* alarm type */ 5214 0xFF, 0xFF, 0xFF, 0xFF, /* alarm type */
5142 0x00, /* 0x02 or 0x00 */ 5215 0x00, /* 0x02 or 0x00 */
5143 0x01, /* note type */ 5216 0x01, /* note type */
5144 0x07, 0xD0, 0x01, 0x12, 0x0C, 0x00, /* start date/time */ 5217 0x07, 0xD0, 0x01, 0x12, 0x0C, 0x00, /* start date/time */
5145 0x07, 0xD0, 0x01, 0x12, 0x0C, 0x00, /* end date/time */ 5218 0x07, 0xD0, 0x01, 0x12, 0x0C, 0x00, /* end date/time */
5146 0x00, 0x00, /* recurrance */ 5219 0x00, 0x00, /* recurrance */
5147 0x00, 0x00, /* birth year */ 5220 0x00, 0x00, /* birth year */
5148 0x20, /* ToDo priority */ 5221 0x20, /* ToDo priority */
5149 0x00, /* ToDo completed ? */ 5222 0x00, /* ToDo completed ? */
5150 0x00, 0x00, 0x00, 5223 0x00, 0x00, 0x00,
5151 0x00, /* note text length */ 5224 0x00, /* note text length */
5152 0x00, /* phone length/meeting place*/ 5225 0x00, /* phone length/meeting place*/
5153 0x00, 0x00, 0x00}; 5226 0x00, 0x00, 0x00};
5154 5227
5155 s->Phone.Data.ToDo = ToDo; 5228 s->Phone.Data.ToDo = ToDo;
5156 5229
5157 smprintf(s, "Getting first free ToDo location method 2\n"); 5230 smprintf(s, "Getting first free ToDo location method 2\n");
5158 error = GSM_WaitFor (s, reqLoc, 5, 0x13, 4, ID_SetToDo); 5231 error = GSM_WaitFor (s, reqLoc, 5, 0x13, 4, ID_SetToDo);
5159 if (error!=ERR_NONE) return error; 5232 if (error!=ERR_NONE) return error;
5160 req[8] = ToDo->Location/256; 5233 req[8] = ToDo->Location/256;
5161 req[9] = ToDo->Location%256; 5234 req[9] = ToDo->Location%256;
5162 5235
5163 Note.Type = GSM_CAL_MEETING; 5236 Note.Type = GSM_CAL_MEETING;
5164 DT.Year = 2004; DT.Month = 1; DT.Day = 1; 5237 DT.Year = 2004; DT.Month = 1; DT.Day = 1;
5165 DT.Hour = 12; DT.Minute = 12; DT.Second = 0; 5238 DT.Hour = 12; DT.Minute = 12; DT.Second = 0;
5166 memcpy(&Note.Entries[0].Date,&DT,sizeof(GSM_DateTime)); 5239 memcpy(&Note.Entries[0].Date,&DT,sizeof(GSM_DateTime));
5167 Note.Entries[0].EntryType = CAL_START_DATETIME; 5240 Note.Entries[0].EntryType = CAL_START_DATETIME;
5168 memcpy(&Note.Entries[1].Date,&DT,sizeof(GSM_DateTime)); 5241 memcpy(&Note.Entries[1].Date,&DT,sizeof(GSM_DateTime));
5169 Note.Entries[1].EntryType = CAL_END_DATETIME; 5242 Note.Entries[1].EntryType = CAL_END_DATETIME;
5170 EncodeUnicode(Note.Entries[2].Text,"ala",3); 5243 EncodeUnicode(Note.Entries[2].Text,"ala",3);
5171 Note.Entries[2].EntryType = CAL_TEXT; 5244 Note.Entries[2].EntryType = CAL_TEXT;
5172 Note.EntriesNum = 3; 5245 Note.EntriesNum = 3;
5173 error=N6510_FindCalendarIconID3(s, &Note, &req[21]); 5246 error=N6510_FindCalendarIconID3(s, &Note, &req[21]);
5174 if (error!=ERR_NONE) return error; 5247 if (error!=ERR_NONE) return error;
5175 5248
5176 switch (ToDo->Priority) { 5249 switch (ToDo->Priority) {
5177 case GSM_Priority_Low: req[44] = 0x10; break; 5250 case GSM_Priority_Low: req[44] = 0x10; break;
5178 case GSM_Priority_Medium: req[44] = 0x20; break; 5251 case GSM_Priority_Medium: req[44] = 0x20; break;
5179 case GSM_Priority_High: req[44] = 0x30; break; 5252 case GSM_Priority_High: req[44] = 0x30; break;
5180 } 5253 }
5181 5254
5182 GSM_ToDoFindDefaultTextTimeAlarmCompleted(ToDo, &Text, &Alarm, &Completed, &EndTime, &Phone); 5255 GSM_ToDoFindDefaultTextTimeAlarmCompleted(ToDo, &Text, &Alarm, &Completed, &EndTime, &Phone);
5183 5256
5184 if (Completed != -1) req[45] = 0x01; 5257 if (Completed != -1) req[45] = 0x01;
5185 5258
5186 if (EndTime == -1) { 5259 if (EndTime == -1) {
5187 GSM_GetCurrentDateTime(&DT); 5260 GSM_GetCurrentDateTime(&DT);
5188 } else { 5261 } else {
5189 memcpy(&DT,&ToDo->Entries[EndTime].Date,sizeof(GSM_DateTime)); 5262 memcpy(&DT,&ToDo->Entries[EndTime].Date,sizeof(GSM_DateTime));
5190 } 5263 }
5191 /*Start time*/ 5264 /*Start time*/
5192 req[28]= DT.Year / 256; 5265 req[28]= DT.Year / 256;
5193 req[29]= DT.Year % 256; 5266 req[29]= DT.Year % 256;
5194 req[30]= DT.Month; 5267 req[30]= DT.Month;
5195 req[31]= DT.Day; 5268 req[31]= DT.Day;
5196 req[32]= DT.Hour; 5269 req[32]= DT.Hour;
5197 req[33]= DT.Minute; 5270 req[33]= DT.Minute;
5198 /*End time*/ 5271 /*End time*/
5199 req[34]= DT.Year / 256; 5272 req[34]= DT.Year / 256;
5200 req[35]= DT.Year % 256; 5273 req[35]= DT.Year % 256;
5201 req[36]= DT.Month; 5274 req[36]= DT.Month;
5202 req[37]= DT.Day; 5275 req[37]= DT.Day;
5203 req[38]= DT.Hour; 5276 req[38]= DT.Hour;
5204 req[39]= DT.Minute; 5277 req[39]= DT.Minute;
5205 5278
5206 if (Alarm != -1) { 5279 if (Alarm != -1) {
5207 if (ToDo->Entries[Alarm].EntryType == CAL_SILENT_ALARM_DATETIME) 5280 if (ToDo->Entries[Alarm].EntryType == CAL_SILENT_ALARM_DATETIME)
5208 { 5281 {
5209 req[22] = 0x00; req[23] = 0x00; req[24] = 0x00; req[25] = 0x00; 5282 req[22] = 0x00; req[23] = 0x00; req[24] = 0x00; req[25] = 0x00;
5210 } 5283 }
5211 t_time2 = Fill_Time_T(DT,8); 5284 t_time2 = Fill_Time_T(DT,8);
5212 t_time1 = Fill_Time_T(ToDo->Entries[Alarm].Date,8); 5285 t_time1 = Fill_Time_T(ToDo->Entries[Alarm].Date,8);
5213 diff = (t_time1-t_time2)/60; 5286 diff = (t_time1-t_time2)/60;
5214 5287
5215 smprintf(s, " Difference : %li seconds or minutes\n", -diff); 5288 smprintf(s, " Difference : %li seconds or minutes\n", -diff);
5216 req[14] = (unsigned char)(-diff >> 24); 5289 req[14] = (unsigned char)(-diff >> 24);
5217 req[15] = (unsigned char)(-diff >> 16); 5290 req[15] = (unsigned char)(-diff >> 16);
5218 req[16] = (unsigned char)(-diff >> 8); 5291 req[16] = (unsigned char)(-diff >> 8);
5219 req[17] = (unsigned char)(-diff); 5292 req[17] = (unsigned char)(-diff);
5220 } 5293 }
5221 5294
5222 if (Text != -1) { 5295 if (Text != -1) {
5223 req[49] = UnicodeLength(ToDo->Entries[Text].Text); 5296 req[49] = UnicodeLength(ToDo->Entries[Text].Text);
5224 CopyUnicodeString(req+54,ToDo->Entries[Text].Text); 5297 CopyUnicodeString(req+54,ToDo->Entries[Text].Text);
5225 count+= req[49]*2; 5298 count+= req[49]*2;
5226 } 5299 }
5227 5300
5228 req[count++] = 0x00; 5301 req[count++] = 0x00;
5229 5302
5230 smprintf(s, "Adding ToDo method 2\n"); 5303 smprintf(s, "Adding ToDo method 2\n");
5231 return GSM_WaitFor (s, req, count, 0x13, 4, ID_SetToDo); 5304 return GSM_WaitFor (s, req, count, 0x13, 4, ID_SetToDo);
5232} 5305}
5233 5306
5234static GSM_Error N6510_AddToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo) 5307static GSM_Error N6510_AddToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo)
5235{ 5308{
5236 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO63)) { 5309 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO63)) {
5237 return N6510_AddToDo1(s, ToDo); 5310 return N6510_AddToDo1(s, ToDo);
5238 } else if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO66)) { 5311 } else if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO66)) {
@@ -5262,521 +5335,530 @@ static GSM_Error N6510_ReplyGetLocale(GSM_Protocol_Message msg, GSM_StateMachine
5262 locale->DateFormat = GSM_Date_YYYYMMDD; 5335 locale->DateFormat = GSM_Date_YYYYMMDD;
5263 locale->DateSeparator = '.'; 5336 locale->DateSeparator = '.';
5264 break; 5337 break;
5265 case 0x04: 5338 case 0x04:
5266 locale->DateFormat = GSM_Date_DDMMYYYY; 5339 locale->DateFormat = GSM_Date_DDMMYYYY;
5267 locale->DateSeparator = '/'; 5340 locale->DateSeparator = '/';
5268 break; 5341 break;
5269 case 0x05: 5342 case 0x05:
5270 locale->DateFormat = GSM_Date_MMDDYYYY; 5343 locale->DateFormat = GSM_Date_MMDDYYYY;
5271 locale->DateSeparator = '/'; 5344 locale->DateSeparator = '/';
5272 break; 5345 break;
5273 case 0x06: 5346 case 0x06:
5274 locale->DateFormat = GSM_Date_YYYYMMDD; 5347 locale->DateFormat = GSM_Date_YYYYMMDD;
5275 locale->DateSeparator = '/'; 5348 locale->DateSeparator = '/';
5276 break; 5349 break;
5277 case 0x08: 5350 case 0x08:
5278 locale->DateFormat = GSM_Date_DDMMYYYY; 5351 locale->DateFormat = GSM_Date_DDMMYYYY;
5279 locale->DateSeparator = '-'; 5352 locale->DateSeparator = '-';
5280 break; 5353 break;
5281 case 0x09: 5354 case 0x09:
5282 locale->DateFormat = GSM_Date_MMDDYYYY; 5355 locale->DateFormat = GSM_Date_MMDDYYYY;
5283 locale->DateSeparator = '-'; 5356 locale->DateSeparator = '-';
5284 break; 5357 break;
5285 case 0x0A: 5358 case 0x0A:
5286 locale->DateFormat = GSM_Date_YYYYMMDD; 5359 locale->DateFormat = GSM_Date_YYYYMMDD;
5287 locale->DateSeparator = '-'; 5360 locale->DateSeparator = '-';
5288 break; 5361 break;
5289 default:/* FIXME */ 5362 default:/* FIXME */
5290 locale->DateFormat = GSM_Date_DDMMYYYY; 5363 locale->DateFormat = GSM_Date_DDMMYYYY;
5291 locale->DateSeparator = '/'; 5364 locale->DateSeparator = '/';
5292 break; 5365 break;
5293 } 5366 }
5294 return ERR_NONE; 5367 return ERR_NONE;
5295 } 5368 }
5296 return ERR_UNKNOWNRESPONSE; 5369 return ERR_UNKNOWNRESPONSE;
5297} 5370}
5298 5371
5299static GSM_Error N6510_GetLocale(GSM_StateMachine *s, GSM_Locale *locale) 5372static GSM_Error N6510_GetLocale(GSM_StateMachine *s, GSM_Locale *locale)
5300{ 5373{
5301 unsigned char req[] = {N6110_FRAME_HEADER, 0x89}; 5374 unsigned char req[] = {N6110_FRAME_HEADER, 0x89};
5302 5375
5303 s->Phone.Data.Locale = locale; 5376 s->Phone.Data.Locale = locale;
5304 5377
5305 smprintf(s, "Getting date format\n"); 5378 smprintf(s, "Getting date format\n");
5306 return GSM_WaitFor (s, req, 4, 0x13, 4, ID_GetLocale); 5379 return GSM_WaitFor (s, req, 4, 0x13, 4, ID_GetLocale);
5307} 5380}
5308 5381
5309static GSM_Error N6510_ReplyGetCalendarSettings(GSM_Protocol_Message msg, GSM_StateMachine *s) 5382static GSM_Error N6510_ReplyGetCalendarSettings(GSM_Protocol_Message msg, GSM_StateMachine *s)
5310{ 5383{
5311 GSM_CalendarSettings *sett = s->Phone.Data.CalendarSettings; 5384 GSM_CalendarSettings *sett = s->Phone.Data.CalendarSettings;
5312 5385
5313 switch (msg.Buffer[3]) { 5386 switch (msg.Buffer[3]) {
5314 case 0x86: 5387 case 0x86:
5315 smprintf(s, "Auto deleting setting received\n"); 5388 smprintf(s, "Auto deleting setting received\n");
5316 sett->AutoDelete = msg.Buffer[4]; 5389 sett->AutoDelete = msg.Buffer[4];
5317 return ERR_NONE; 5390 return ERR_NONE;
5318 case 0x8E: 5391 case 0x8E:
5319 smprintf(s, "Start day for calendar received\n"); 5392 smprintf(s, "Start day for calendar received\n");
5320 switch(msg.Buffer[4]) { 5393 switch(msg.Buffer[4]) {
5321 case 0x03: 5394 case 0x03:
5322 sett->StartDay = 6; 5395 sett->StartDay = 6;
5323 return ERR_NONE; 5396 return ERR_NONE;
5324 case 0x02: 5397 case 0x02:
5325 sett->StartDay = 7; 5398 sett->StartDay = 7;
5326 return ERR_NONE; 5399 return ERR_NONE;
5327 case 0x01: 5400 case 0x01:
5328 sett->StartDay = 1; 5401 sett->StartDay = 1;
5329 return ERR_NONE; 5402 return ERR_NONE;
5330 } 5403 }
5331 break; 5404 break;
5332 } 5405 }
5333 return ERR_UNKNOWNRESPONSE; 5406 return ERR_UNKNOWNRESPONSE;
5334} 5407}
5335 5408
5336static GSM_Error N6510_GetCalendarSettings(GSM_StateMachine *s, GSM_CalendarSettings *settings) 5409static GSM_Error N6510_GetCalendarSettings(GSM_StateMachine *s, GSM_CalendarSettings *settings)
5337{ 5410{
5338 GSM_Errorerror; 5411 GSM_Errorerror;
5339 unsigned char req1[] = {N6110_FRAME_HEADER, 0x85}; 5412 unsigned char req1[] = {N6110_FRAME_HEADER, 0x85};
5340 unsigned char req2[] = {N6110_FRAME_HEADER, 0x8D}; 5413 unsigned char req2[] = {N6110_FRAME_HEADER, 0x8D};
5341 5414
5342 s->Phone.Data.CalendarSettings = settings; 5415 s->Phone.Data.CalendarSettings = settings;
5343 5416
5344 smprintf(s, "Getting auto delete\n"); 5417 smprintf(s, "Getting auto delete\n");
5345 error = GSM_WaitFor (s, req1, 4, 0x13, 4, ID_GetCalendarSettings); 5418 error = GSM_WaitFor (s, req1, 4, 0x13, 4, ID_GetCalendarSettings);
5346 if (error != ERR_NONE) return error; 5419 if (error != ERR_NONE) return error;
5347 5420
5348 smprintf(s, "Getting start day for week\n"); 5421 smprintf(s, "Getting start day for week\n");
5349 return GSM_WaitFor (s, req2, 4, 0x13, 4, ID_GetCalendarSettings); 5422 return GSM_WaitFor (s, req2, 4, 0x13, 4, ID_GetCalendarSettings);
5350} 5423}
5351 5424
5352GSM_Error N6510_CancelCall(GSM_StateMachine *s, int ID, bool all) 5425GSM_Error N6510_CancelCall(GSM_StateMachine *s, int ID, bool all)
5353{ 5426{
5354 if (all) return ERR_NOTSUPPORTED; 5427 if (all) return ERR_NOTSUPPORTED;
5355 return DCT3DCT4_CancelCall(s,ID); 5428 return DCT3DCT4_CancelCall(s,ID);
5356} 5429}
5357 5430
5358GSM_Error N6510_AnswerCall(GSM_StateMachine *s, int ID, bool all) 5431GSM_Error N6510_AnswerCall(GSM_StateMachine *s, int ID, bool all)
5359{ 5432{
5360 if (all) return ERR_NOTSUPPORTED; 5433 if (all) return ERR_NOTSUPPORTED;
5361 return DCT3DCT4_AnswerCall(s,ID); 5434 return DCT3DCT4_AnswerCall(s,ID);
5362} 5435}
5363 5436
5364static GSM_Error N6510_ReplyAddSMSFolder(GSM_Protocol_Message msg, GSM_StateMachine *s) 5437static GSM_Error N6510_ReplyAddSMSFolder(GSM_Protocol_Message msg, GSM_StateMachine *s)
5365{ 5438{
5366 smprintf(s,"SMS folder \"%s\" has been added\n",DecodeUnicodeString(msg.Buffer+10)); 5439 smprintf(s,"SMS folder \"%s\" has been added\n",DecodeUnicodeString(msg.Buffer+10));
5367 return ERR_NONE; 5440 return ERR_NONE;
5368} 5441}
5369 5442
5370GSM_Error N6510_AddSMSFolder(GSM_StateMachine *s, unsigned char *name) 5443GSM_Error N6510_AddSMSFolder(GSM_StateMachine *s, unsigned char *name)
5371{ 5444{
5372 unsigned char req[200] = {N6110_FRAME_HEADER, 0x10, 0x01, 0x00, 0x01, 5445 unsigned char req[200] = {N6110_FRAME_HEADER, 0x10, 0x01, 0x00, 0x01,
5373 0x00, /* Length */ 5446 0x00, /* Length */
5374 0x00, 0x00}; 5447 0x00, 0x00};
5375 5448
5376 5449
5377 CopyUnicodeString(req+10,name); 5450 CopyUnicodeString(req+10,name);
5378 req[7] = UnicodeLength(name)*2 + 6; 5451 req[7] = UnicodeLength(name)*2 + 6;
5379 5452
5380 smprintf(s, "Adding SMS folder\n"); 5453 smprintf(s, "Adding SMS folder\n");
5381 return GSM_WaitFor (s, req, req[7] + 6, 0x14, 4, ID_AddSMSFolder); 5454 return GSM_WaitFor (s, req, req[7] + 6, 0x14, 4, ID_AddSMSFolder);
5382} 5455}
5383 5456
5384static GSM_Error N6510_SetWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark) 5457static GSM_Error N6510_SetWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
5385{ 5458{
5386 GSM_Error error; 5459 GSM_Error error;
5387 int count=4, location; 5460 int count=4, location;
5388 unsigned char req[600] = {N6110_FRAME_HEADER, 0x09}; 5461 unsigned char req[600] = {N6110_FRAME_HEADER, 0x09};
5389 5462
5390 /* We have to enable WAP frames in phone */ 5463 /* We have to enable WAP frames in phone */
5391 error=N6510_EnableConnectionFunctions(s,N6510_WAP_SETTINGS); 5464 error=N6510_EnableConnectionFunctions(s,N6510_WAP_SETTINGS);
5392 if (error!=ERR_NONE) return error; 5465 if (error!=ERR_NONE) return error;
5393 5466
5394 location = bookmark->Location - 1; 5467 location = bookmark->Location - 1;
5395 if (bookmark->Location == 0) location = 0xffff; 5468 if (bookmark->Location == 0) location = 0xffff;
5396 req[count++] = (location & 0xff00) >> 8; 5469 req[count++] = (location & 0xff00) >> 8;
5397 req[count++] = location & 0x00ff; 5470 req[count++] = location & 0x00ff;
5398 5471
5399 count += NOKIA_SetUnicodeString(s, req+count, bookmark->Title, true); 5472 count += NOKIA_SetUnicodeString(s, req+count, bookmark->Title, true);
5400 count += NOKIA_SetUnicodeString(s, req+count, bookmark->Address, true); 5473 count += NOKIA_SetUnicodeString(s, req+count, bookmark->Address, true);
5401 5474
5402 req[count++] = 0x00; 5475 req[count++] = 0x00;
5403 req[count++] = 0x00; 5476 req[count++] = 0x00;
5404 req[count++] = 0x00; 5477 req[count++] = 0x00;
5405 req[count++] = 0x00; 5478 req[count++] = 0x00;
5406 5479
5407 smprintf(s, "Setting WAP bookmark\n"); 5480 smprintf(s, "Setting WAP bookmark\n");
5408 error = GSM_WaitFor (s, req, count, 0x3f, 4, ID_SetWAPBookmark); 5481 error = GSM_WaitFor (s, req, count, 0x3f, 4, ID_SetWAPBookmark);
5409 if (error != ERR_NONE) { 5482 if (error != ERR_NONE) {
5410 if (error == ERR_INSIDEPHONEMENU || error == ERR_EMPTY || error == ERR_FULL) { 5483 if (error == ERR_INSIDEPHONEMENU || error == ERR_EMPTY || error == ERR_FULL) {
5411 DCT3DCT4_DisableConnectionFunctions(s); 5484 DCT3DCT4_DisableConnectionFunctions(s);
5412 } 5485 }
5413 return error; 5486 return error;
5414 } 5487 }
5415 5488
5416 return DCT3DCT4_DisableConnectionFunctions(s); 5489 return DCT3DCT4_DisableConnectionFunctions(s);
5417} 5490}
5418 5491
5419GSM_Error N6510_DeleteWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark) 5492GSM_Error N6510_DeleteWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
5420{ 5493{
5421 GSM_Error error; 5494 GSM_Error error;
5422 5495
5423 /* We have to enable WAP frames in phone */ 5496 /* We have to enable WAP frames in phone */
5424 error=N6510_EnableConnectionFunctions(s,N6510_WAP_SETTINGS); 5497 error=N6510_EnableConnectionFunctions(s,N6510_WAP_SETTINGS);
5425 if (error!=ERR_NONE) return error; 5498 if (error!=ERR_NONE) return error;
5426 5499
5427 return DCT3DCT4_DeleteWAPBookmarkPart(s,bookmark); 5500 return DCT3DCT4_DeleteWAPBookmarkPart(s,bookmark);
5428} 5501}
5429 5502
5430GSM_Error N6510_GetWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark) 5503GSM_Error N6510_GetWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
5431{ 5504{
5432 GSM_Error error; 5505 GSM_Error error;
5433 5506
5434 /* We have to enable WAP frames in phone */ 5507 /* We have to enable WAP frames in phone */
5435 error=N6510_EnableConnectionFunctions(s,N6510_WAP_SETTINGS); 5508 error=N6510_EnableConnectionFunctions(s,N6510_WAP_SETTINGS);
5436 if (error!=ERR_NONE) return error; 5509 if (error!=ERR_NONE) return error;
5437 5510
5438 return DCT3DCT4_GetWAPBookmarkPart(s,bookmark); 5511 return DCT3DCT4_GetWAPBookmarkPart(s,bookmark);
5439} 5512}
5440 5513
5441static GSM_Reply_Function N6510ReplyFunctions[] = { 5514static GSM_Reply_Function N6510ReplyFunctions[] = {
5442 {N71_65_ReplyCallInfo, "\x01",0x03,0x02,ID_IncomingFrame }, 5515 {N71_65_ReplyCallInfo, "\x01",0x03,0x02,ID_IncomingFrame },
5443 {N71_65_ReplyCallInfo, "\x01",0x03,0x03,ID_IncomingFrame }, 5516 {N71_65_ReplyCallInfo, "\x01",0x03,0x03,ID_IncomingFrame },
5444 {N71_65_ReplyCallInfo, "\x01",0x03,0x04,ID_IncomingFrame }, 5517 {N71_65_ReplyCallInfo, "\x01",0x03,0x04,ID_IncomingFrame },
5445 {N71_65_ReplyCallInfo, "\x01",0x03,0x05,ID_IncomingFrame }, 5518 {N71_65_ReplyCallInfo, "\x01",0x03,0x05,ID_IncomingFrame },
5446 {N71_65_ReplyCallInfo, "\x01",0x03,0x07,ID_AnswerCall }, 5519 {N71_65_ReplyCallInfo, "\x01",0x03,0x07,ID_AnswerCall },
5447 {N71_65_ReplyCallInfo, "\x01",0x03,0x07,ID_IncomingFrame }, 5520 {N71_65_ReplyCallInfo, "\x01",0x03,0x07,ID_IncomingFrame },
5448 {N71_65_ReplyCallInfo, "\x01",0x03,0x09,ID_CancelCall }, 5521 {N71_65_ReplyCallInfo, "\x01",0x03,0x09,ID_CancelCall },
5449 {N71_65_ReplyCallInfo, "\x01",0x03,0x09,ID_IncomingFrame }, 5522 {N71_65_ReplyCallInfo, "\x01",0x03,0x09,ID_IncomingFrame },
5450 {N71_65_ReplyCallInfo, "\x01",0x03,0x0A,ID_IncomingFrame }, 5523 {N71_65_ReplyCallInfo, "\x01",0x03,0x0A,ID_IncomingFrame },
5451 {N71_65_ReplyCallInfo, "\x01",0x03,0x0B,ID_IncomingFrame }, 5524 {N71_65_ReplyCallInfo, "\x01",0x03,0x0B,ID_IncomingFrame },
5452 {N71_65_ReplyCallInfo, "\x01",0x03,0x0C,ID_DialVoice }, 5525 {N71_65_ReplyCallInfo, "\x01",0x03,0x0C,ID_DialVoice },
5453 {N71_65_ReplyCallInfo, "\x01",0x03,0x0C,ID_IncomingFrame }, 5526 {N71_65_ReplyCallInfo, "\x01",0x03,0x0C,ID_IncomingFrame },
5527 {N71_65_ReplyCallInfo, "\x01",0x03,0x0F,ID_IncomingFrame },
5528 {N71_65_ReplyCallInfo, "\x01",0x03,0x10,ID_DialVoice },
5529 {N71_65_ReplyCallInfo, "\x01",0x03,0x10,ID_IncomingFrame },
5454 {N71_65_ReplyCallInfo, "\x01",0x03,0x23,ID_IncomingFrame }, 5530 {N71_65_ReplyCallInfo, "\x01",0x03,0x23,ID_IncomingFrame },
5455 {N71_65_ReplyCallInfo, "\x01",0x03,0x25,ID_IncomingFrame }, 5531 {N71_65_ReplyCallInfo, "\x01",0x03,0x25,ID_IncomingFrame },
5456 {N71_65_ReplyCallInfo, "\x01",0x03,0x27,ID_IncomingFrame }, 5532 {N71_65_ReplyCallInfo, "\x01",0x03,0x27,ID_IncomingFrame },
5457 {N71_65_ReplySendDTMF, "\x01",0x03,0x51,ID_SendDTMF }, 5533 {N71_65_ReplySendDTMF, "\x01",0x03,0x51,ID_SendDTMF },
5458 {N71_65_ReplyCallInfo, "\x01",0x03,0x53,ID_IncomingFrame }, 5534 {N71_65_ReplyCallInfo, "\x01",0x03,0x53,ID_IncomingFrame },
5459 {N71_65_ReplySendDTMF, "\x01",0x03,0x59,ID_SendDTMF }, 5535 {N71_65_ReplySendDTMF, "\x01",0x03,0x59,ID_SendDTMF },
5460 {N71_65_ReplySendDTMF, "\x01",0x03,0x5E,ID_SendDTMF }, 5536 {N71_65_ReplySendDTMF, "\x01",0x03,0x5E,ID_SendDTMF },
5537 {N71_65_ReplyCallInfo, "\x01",0x03,0xA6,ID_IncomingFrame },
5538 {N71_65_ReplyCallInfo, "\x01",0x03,0xD2,ID_IncomingFrame },
5539 {N71_65_ReplyCallInfo, "\x01",0x03,0xD3,ID_IncomingFrame },
5461 5540
5462 {N6510_ReplySendSMSMessage, "\x02",0x03,0x03,ID_IncomingFrame }, 5541 {N6510_ReplySendSMSMessage, "\x02",0x03,0x03,ID_IncomingFrame },
5463 {N6510_ReplyIncomingSMS, "\x02",0x03,0x04,ID_IncomingFrame }, 5542 {N6510_ReplyIncomingSMS, "\x02",0x03,0x04,ID_IncomingFrame },
5464 {N6510_ReplySetSMSC, "\x02",0x03,0x13,ID_SetSMSC }, 5543 {N6510_ReplySetSMSC, "\x02",0x03,0x13,ID_SetSMSC },
5465 {N6510_ReplyGetSMSC, "\x02",0x03,0x15,ID_GetSMSC }, 5544 {N6510_ReplyGetSMSC, "\x02",0x03,0x15,ID_GetSMSC },
5466 5545
5467 {N6510_ReplyGetMemoryStatus, "\x03",0x03,0x04,ID_GetMemoryStatus }, 5546 {N6510_ReplyGetMemoryStatus, "\x03",0x03,0x04,ID_GetMemoryStatus },
5468 {N6510_ReplyGetMemory, "\x03",0x03,0x08,ID_GetMemory }, 5547 {N6510_ReplyGetMemory, "\x03",0x03,0x08,ID_GetMemory },
5469 {N6510_ReplyDeleteMemory, "\x03",0x03,0x10,ID_SetMemory }, 5548 {N6510_ReplyDeleteMemory, "\x03",0x03,0x10,ID_SetMemory },
5470 {N71_65_ReplyWritePhonebook, "\x03",0x03,0x0C,ID_SetBitmap }, 5549 {N71_65_ReplyWritePhonebook, "\x03",0x03,0x0C,ID_SetBitmap },
5471 {N71_65_ReplyWritePhonebook, "\x03",0x03,0x0C,ID_SetMemory }, 5550 {N71_65_ReplyWritePhonebook, "\x03",0x03,0x0C,ID_SetMemory },
5472 5551
5473 {DCT3DCT4_ReplyCallDivert, "\x06",0x03,0x02,ID_Divert }, 5552 {DCT3DCT4_ReplyCallDivert, "\x06",0x03,0x02,ID_Divert },
5474 {N71_65_ReplyUSSDInfo, "\x06",0x03,0x03,ID_IncomingFrame }, 5553 {N71_65_ReplyUSSDInfo, "\x06",0x03,0x03,ID_IncomingFrame },
5475 {NoneReply, "\x06",0x03,0x06,ID_IncomingFrame }, 5554 {NoneReply, "\x06",0x03,0x06,ID_IncomingFrame },
5476 {NoneReply, "\x06",0x03,0x09,ID_IncomingFrame }, 5555 {NoneReply, "\x06",0x03,0x09,ID_IncomingFrame },
5477 5556
5478 {N6510_ReplyEnterSecurityCode, "\x08",0x03,0x08,ID_EnterSecurityCode }, 5557 {N6510_ReplyEnterSecurityCode, "\x08",0x03,0x08,ID_EnterSecurityCode },
5479 {N6510_ReplyEnterSecurityCode, "\x08",0x03,0x09,ID_EnterSecurityCode }, 5558 {N6510_ReplyEnterSecurityCode, "\x08",0x03,0x09,ID_EnterSecurityCode },
5480 {N6510_ReplyGetSecurityStatus, "\x08",0x03,0x12,ID_GetSecurityStatus }, 5559 {N6510_ReplyGetSecurityStatus, "\x08",0x03,0x12,ID_GetSecurityStatus },
5481 5560
5482 {N6510_ReplyGetNetworkInfo, "\x0A",0x03,0x01,ID_GetNetworkInfo }, 5561 {N6510_ReplyGetNetworkInfo, "\x0A",0x03,0x01,ID_GetNetworkInfo },
5483 {N6510_ReplyGetNetworkInfo, "\x0A",0x03,0x01,ID_IncomingFrame }, 5562 {N6510_ReplyGetNetworkInfo, "\x0A",0x03,0x01,ID_IncomingFrame },
5484 {N6510_ReplyLogIntoNetwork, "\x0A",0x03,0x02,ID_IncomingFrame }, 5563 {N6510_ReplyLogIntoNetwork, "\x0A",0x03,0x02,ID_IncomingFrame },
5485 {N6510_ReplyGetSignalQuality, "\x0A",0x03,0x0C,ID_GetSignalQuality }, 5564 {N6510_ReplyGetSignalQuality, "\x0A",0x03,0x0C,ID_GetSignalQuality },
5486 {N6510_ReplyGetIncSignalQuality, "\x0A",0x03,0x1E,ID_IncomingFrame }, 5565 {N6510_ReplyGetIncSignalQuality, "\x0A",0x03,0x1E,ID_IncomingFrame },
5487 {NoneReply, "\x0A",0x03,0x20,ID_IncomingFrame }, 5566 {NoneReply, "\x0A",0x03,0x20,ID_IncomingFrame },
5488 {N6510_ReplyGetOperatorLogo, "\x0A",0x03,0x24,ID_GetBitmap }, 5567 {N6510_ReplyGetOperatorLogo, "\x0A",0x03,0x24,ID_GetBitmap },
5489 {N6510_ReplySetOperatorLogo, "\x0A",0x03,0x26,ID_SetBitmap }, 5568 {N6510_ReplySetOperatorLogo, "\x0A",0x03,0x26,ID_SetBitmap },
5490 5569
5491 {NoneReply, "\x0B",0x03,0x01,ID_PlayTone }, 5570 {NoneReply, "\x0B",0x03,0x01,ID_PlayTone },
5492 {NoneReply, "\x0B",0x03,0x15,ID_PlayTone }, 5571 {NoneReply, "\x0B",0x03,0x15,ID_PlayTone },
5493 {NoneReply, "\x0B",0x03,0x16,ID_PlayTone }, 5572 {NoneReply, "\x0B",0x03,0x16,ID_PlayTone },
5494 5573
5495 {N71_65_ReplyAddCalendar1, "\x13",0x03,0x02,ID_SetCalendarNote }, 5574 {N71_65_ReplyAddCalendar1, "\x13",0x03,0x02,ID_SetCalendarNote },
5496 {N71_65_ReplyAddCalendar1, "\x13",0x03,0x04,ID_SetCalendarNote }, 5575 {N71_65_ReplyAddCalendar1, "\x13",0x03,0x04,ID_SetCalendarNote },
5497 {N71_65_ReplyAddCalendar1, "\x13",0x03,0x06,ID_SetCalendarNote }, 5576 {N71_65_ReplyAddCalendar1, "\x13",0x03,0x06,ID_SetCalendarNote },
5498 {N71_65_ReplyAddCalendar1, "\x13",0x03,0x08,ID_SetCalendarNote }, 5577 {N71_65_ReplyAddCalendar1, "\x13",0x03,0x08,ID_SetCalendarNote },
5499 {N71_65_ReplyDelCalendar, "\x13",0x03,0x0C,ID_DeleteCalendarNote }, 5578 {N71_65_ReplyDelCalendar, "\x13",0x03,0x0C,ID_DeleteCalendarNote },
5500 {N71_65_ReplyGetNextCalendar1, "\x13",0x03,0x1A,ID_GetCalendarNote },/*method 1*/ 5579 {N71_65_ReplyGetNextCalendar1, "\x13",0x03,0x1A,ID_GetCalendarNote },/*method 1*/
5501 {N6510_ReplyGetCalendarNotePos, "\x13",0x03,0x32,ID_GetCalendarNotePos },/*method 1*/ 5580 {N6510_ReplyGetCalendarNotePos, "\x13",0x03,0x32,ID_GetCalendarNotePos },/*method 1*/
5502 {N6510_ReplyGetCalendarInfo, "\x13",0x03,0x3B,ID_GetCalendarNotesInfo},/*method 1*/ 5581 {N6510_ReplyGetCalendarInfo, "\x13",0x03,0x3B,ID_GetCalendarNotesInfo},/*method 1*/
5503#ifdef DEBUG 5582#ifdef DEBUG
5504 {N71_65_ReplyGetNextCalendar2, "\x13",0x03,0x3F,ID_GetCalendarNote }, 5583 {N71_65_ReplyGetNextCalendar2, "\x13",0x03,0x3F,ID_GetCalendarNote },
5505#endif 5584#endif
5506 {N71_65_ReplyAddCalendar2, "\x13",0x03,0x41,ID_SetCalendarNote },/*method 2*/ 5585 {N71_65_ReplyAddCalendar2, "\x13",0x03,0x41,ID_SetCalendarNote },/*method 2*/
5507 {N6510_ReplyAddCalendar3, "\x13",0x03,0x66,ID_SetCalendarNote },/*method 3*/ 5586 {N6510_ReplyAddCalendar3, "\x13",0x03,0x66,ID_SetCalendarNote },/*method 3*/
5508 {N6510_ReplyAddToDo2, "\x13",0x03,0x66,ID_SetToDo }, 5587 {N6510_ReplyAddToDo2, "\x13",0x03,0x66,ID_SetToDo },
5509 {N6510_ReplyGetCalendar3, "\x13",0x03,0x7E,ID_GetCalendarNote },/*method 3*/ 5588 {N6510_ReplyGetCalendar3, "\x13",0x03,0x7E,ID_GetCalendarNote },/*method 3*/
5510 {N6510_ReplyGetToDo2, "\x13",0x03,0x7E,ID_GetToDo }, 5589 {N6510_ReplyGetToDo2, "\x13",0x03,0x7E,ID_GetToDo },
5590 {N6510_ReplyGetNote, "\x13",0x03,0x7E,ID_GetNote },
5511 {N6510_ReplyGetCalendarSettings, "\x13",0x03,0x86,ID_GetCalendarSettings }, 5591 {N6510_ReplyGetCalendarSettings, "\x13",0x03,0x86,ID_GetCalendarSettings },
5512 {N6510_ReplyGetLocale, "\x13",0x03,0x8A,ID_GetLocale }, 5592 {N6510_ReplyGetLocale, "\x13",0x03,0x8A,ID_GetLocale },
5513 {N6510_ReplyGetCalendarSettings, "\x13",0x03,0x8E,ID_GetCalendarSettings }, 5593 {N6510_ReplyGetCalendarSettings, "\x13",0x03,0x8E,ID_GetCalendarSettings },
5514 {N6510_ReplyGetCalendarNotePos, "\x13",0x03,0x96,ID_GetCalendarNotePos },/*method 3*/ 5594 {N6510_ReplyGetCalendarNotePos, "\x13",0x03,0x96,ID_GetCalendarNotePos },/*method 3*/
5515 {N6510_ReplyGetToDoFirstLoc2, "\x13",0x03,0x96,ID_SetToDo }, 5595 {N6510_ReplyGetToDoFirstLoc2, "\x13",0x03,0x96,ID_SetToDo },
5516 {N6510_ReplyGetCalendarInfo, "\x13",0x03,0x9F,ID_GetCalendarNotesInfo},/*method 3*/ 5596 {N6510_ReplyGetCalendarInfo, "\x13",0x03,0x9F,ID_GetCalendarNotesInfo},/*method 3*/
5517 {N6510_ReplyGetToDoStatus2, "\x13",0x03,0x9F,ID_GetToDo }, 5597 {N6510_ReplyGetToDoStatus2, "\x13",0x03,0x9F,ID_GetToDo },
5598 {N6510_ReplyGetNoteInfo, "\x13",0x03,0x9F,ID_GetNote },
5518 5599
5519 {N6510_ReplySaveSMSMessage, "\x14",0x03,0x01,ID_SaveSMSMessage }, 5600 {N6510_ReplySaveSMSMessage, "\x14",0x03,0x01,ID_SaveSMSMessage },
5520 {N6510_ReplySetPicture, "\x14",0x03,0x01,ID_SetBitmap }, 5601 {N6510_ReplySetPicture, "\x14",0x03,0x01,ID_SetBitmap },
5521 {N6510_ReplyGetSMSMessage, "\x14",0x03,0x03,ID_GetSMSMessage }, 5602 {N6510_ReplyGetSMSMessage, "\x14",0x03,0x03,ID_GetSMSMessage },
5522 {N6510_ReplyDeleteSMSMessage, "\x14",0x03,0x05,ID_DeleteSMSMessage }, 5603 {N6510_ReplyDeleteSMSMessage, "\x14",0x03,0x05,ID_DeleteSMSMessage },
5523 {N6510_ReplyDeleteSMSMessage, "\x14",0x03,0x06,ID_DeleteSMSMessage }, 5604 {N6510_ReplyDeleteSMSMessage, "\x14",0x03,0x06,ID_DeleteSMSMessage },
5524 {N6510_ReplyGetSMSStatus, "\x14",0x03,0x09,ID_GetSMSStatus }, 5605 {N6510_ReplyGetSMSStatus, "\x14",0x03,0x09,ID_GetSMSStatus },
5525 {N6510_ReplyGetSMSFolderStatus, "\x14",0x03,0x0d,ID_GetSMSFolderStatus }, 5606 {N6510_ReplyGetSMSFolderStatus, "\x14",0x03,0x0d,ID_GetSMSFolderStatus },
5526 {N6510_ReplyGetSMSMessage, "\x14",0x03,0x0f,ID_GetSMSMessage }, 5607 {N6510_ReplyGetSMSMessage, "\x14",0x03,0x0f,ID_GetSMSMessage },
5527 {N6510_ReplyAddSMSFolder, "\x14",0x03,0x11,ID_AddSMSFolder }, 5608 {N6510_ReplyAddSMSFolder, "\x14",0x03,0x11,ID_AddSMSFolder },
5528 {N6510_ReplyGetSMSFolders, "\x14",0x03,0x13,ID_GetSMSFolders }, 5609 {N6510_ReplyGetSMSFolders, "\x14",0x03,0x13,ID_GetSMSFolders },
5529 {N6510_ReplySaveSMSMessage, "\x14",0x03,0x17,ID_SaveSMSMessage }, 5610 {N6510_ReplySaveSMSMessage, "\x14",0x03,0x17,ID_SaveSMSMessage },
5530 {N6510_ReplyGetSMSStatus, "\x14",0x03,0x1a,ID_GetSMSStatus }, 5611 {N6510_ReplyGetSMSStatus, "\x14",0x03,0x1a,ID_GetSMSStatus },
5531 5612
5532 {DCT4_ReplySetPhoneMode, "\x15",0x03,0x64,ID_Reset }, 5613 {DCT4_ReplySetPhoneMode, "\x15",0x03,0x64,ID_Reset },
5533 {DCT4_ReplyGetPhoneMode, "\x15",0x03,0x65,ID_Reset }, 5614 {DCT4_ReplyGetPhoneMode, "\x15",0x03,0x65,ID_Reset },
5534 {NoneReply, "\x15",0x03,0x68,ID_Reset }, 5615 {NoneReply, "\x15",0x03,0x68,ID_Reset },
5535 5616
5536 {N6510_ReplyGetBatteryCharge, "\x17",0x03,0x0B,ID_GetBatteryCharge }, 5617 {N6510_ReplyGetBatteryCharge, "\x17",0x03,0x0B,ID_GetBatteryCharge },
5537 5618
5538 {N6510_ReplySetDateTime, "\x19",0x03,0x02,ID_SetDateTime }, 5619 {N6510_ReplySetDateTime, "\x19",0x03,0x02,ID_SetDateTime },
5539 {N6510_ReplyGetDateTime, "\x19",0x03,0x0B,ID_GetDateTime }, 5620 {N6510_ReplyGetDateTime, "\x19",0x03,0x0B,ID_GetDateTime },
5540 {N6510_ReplySetAlarm, "\x19",0x03,0x12,ID_SetAlarm }, 5621 {N6510_ReplySetAlarm, "\x19",0x03,0x12,ID_SetAlarm },
5541 {N6510_ReplyGetAlarm, "\x19",0x03,0x1A,ID_GetAlarm }, 5622 {N6510_ReplyGetAlarm, "\x19",0x03,0x1A,ID_GetAlarm },
5542 {N6510_ReplyGetAlarm, "\x19",0x03,0x20,ID_GetAlarm }, 5623 {N6510_ReplyGetAlarm, "\x19",0x03,0x20,ID_GetAlarm },
5543 5624
5544 {DCT4_ReplyGetIMEI, "\x1B",0x03,0x01,ID_GetIMEI }, 5625 {DCT4_ReplyGetIMEI, "\x1B",0x03,0x01,ID_GetIMEI },
5545 {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x08,ID_GetHardware }, 5626 {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x08,ID_GetHardware },
5546 {N6510_ReplyGetPPM, "\x1B",0x03,0x08,ID_GetPPM }, 5627 {N6510_ReplyGetPPM, "\x1B",0x03,0x08,ID_GetPPM },
5547 {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x0C,ID_GetProductCode }, 5628 {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x0C,ID_GetProductCode },
5548 5629
5549 /* 0x1C - vibra */ 5630 /* 0x1C - vibra */
5550 5631
5551 {N6510_ReplyGetRingtonesInfo, "\x1f",0x03,0x08,ID_GetRingtonesInfo }, 5632 {N6510_ReplyGetRingtonesInfo, "\x1f",0x03,0x08,ID_GetRingtonesInfo },
5552 {N6510_ReplyDeleteRingtones, "\x1f",0x03,0x11,ID_SetRingtone }, 5633 {N6510_ReplyDeleteRingtones, "\x1f",0x03,0x11,ID_SetRingtone },
5553 {N6510_ReplyGetRingtone, "\x1f",0x03,0x13,ID_GetRingtone }, 5634 {N6510_ReplyGetRingtone, "\x1f",0x03,0x13,ID_GetRingtone },
5554 {N6510_ReplySetBinRingtone, "\x1f",0x03,0x0F,ID_SetRingtone }, 5635 {N6510_ReplySetBinRingtone, "\x1f",0x03,0x0F,ID_SetRingtone },
5555 5636
5556 /* 0x23 - voice records */ 5637 /* 0x23 - voice records */
5557 5638
5558 {N6510_ReplyGetProfile, "\x39",0x03,0x02,ID_GetProfile }, 5639 {N6510_ReplyGetProfile, "\x39",0x03,0x02,ID_GetProfile },
5559 {N6510_ReplySetProfile, "\x39",0x03,0x04,ID_SetProfile }, 5640 {N6510_ReplySetProfile, "\x39",0x03,0x04,ID_SetProfile },
5560 {N6510_ReplyGetProfile, "\x39",0x03,0x06,ID_GetProfile }, 5641 {N6510_ReplyGetProfile, "\x39",0x03,0x06,ID_GetProfile },
5561 5642
5562 {N6510_ReplySetLight, "\x3A",0x03,0x06,ID_SetLight }, 5643 {N6510_ReplySetLight, "\x3A",0x03,0x06,ID_SetLight },
5563 5644
5564 {N6510_ReplyGetFMStation, "\x3E",0x03,0x06,ID_GetFMStation }, 5645 {N6510_ReplyGetFMStation, "\x3E",0x03,0x06,ID_GetFMStation },
5565 {N6510_ReplyGetFMStatus, "\x3E",0x03,0x0E,ID_GetFMStation }, 5646 {N6510_ReplyGetFMStatus, "\x3E",0x03,0x0E,ID_GetFMStation },
5566 {N6510_ReplySetFMStation, "\x3E",0x03,0x15,ID_SetFMStation }, 5647 {N6510_ReplySetFMStation, "\x3E",0x03,0x15,ID_SetFMStation },
5567 {N6510_ReplyGetFMStation, "\x3E",0x03,0x16,ID_GetFMStation }, 5648 {N6510_ReplyGetFMStation, "\x3E",0x03,0x16,ID_GetFMStation },
5568 5649
5569 {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x01,ID_EnableConnectFunc }, 5650 {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x01,ID_EnableConnectFunc },
5570 {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x02,ID_EnableConnectFunc }, 5651 {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x02,ID_EnableConnectFunc },
5571 {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x04,ID_DisableConnectFunc }, 5652 {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x04,ID_DisableConnectFunc },
5572 {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x05,ID_DisableConnectFunc }, 5653 {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x05,ID_DisableConnectFunc },
5573 {N6510_ReplyGetWAPBookmark, "\x3f",0x03,0x07,ID_GetWAPBookmark }, 5654 {N6510_ReplyGetWAPBookmark, "\x3f",0x03,0x07,ID_GetWAPBookmark },
5574 {N6510_ReplyGetWAPBookmark, "\x3f",0x03,0x08,ID_GetWAPBookmark }, 5655 {N6510_ReplyGetWAPBookmark, "\x3f",0x03,0x08,ID_GetWAPBookmark },
5575 {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0A,ID_SetWAPBookmark }, 5656 {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0A,ID_SetWAPBookmark },
5576 {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0B,ID_SetWAPBookmark }, 5657 {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0B,ID_SetWAPBookmark },
5577 {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0D,ID_DeleteWAPBookmark }, 5658 {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0D,ID_DeleteWAPBookmark },
5578 {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0E,ID_DeleteWAPBookmark }, 5659 {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0E,ID_DeleteWAPBookmark },
5579 {DCT3DCT4_ReplyGetActiveConnectSet,"\x3f",0x03,0x10,ID_GetConnectSet }, 5660 {DCT3DCT4_ReplyGetActiveConnectSet,"\x3f",0x03,0x10,ID_GetConnectSet },
5580 {DCT3DCT4_ReplySetActiveConnectSet,"\x3f",0x03,0x13,ID_SetConnectSet }, 5661 {DCT3DCT4_ReplySetActiveConnectSet,"\x3f",0x03,0x13,ID_SetConnectSet },
5581 {N6510_ReplyGetConnectionSettings,"\x3f",0x03,0x16,ID_GetConnectSet }, 5662 {N6510_ReplyGetConnectionSettings,"\x3f",0x03,0x16,ID_GetConnectSet },
5582 {N6510_ReplyGetConnectionSettings,"\x3f",0x03,0x17,ID_GetConnectSet }, 5663 {N6510_ReplyGetConnectionSettings,"\x3f",0x03,0x17,ID_GetConnectSet },
5583 {N6510_ReplySetConnectionSettings,"\x3f",0x03,0x19,ID_SetConnectSet }, 5664 {N6510_ReplySetConnectionSettings,"\x3f",0x03,0x19,ID_SetConnectSet },
5584 {N6510_ReplySetConnectionSettings,"\x3f",0x03,0x1A,ID_SetConnectSet }, 5665 {N6510_ReplySetConnectionSettings,"\x3f",0x03,0x1A,ID_SetConnectSet },
5585 {N6510_ReplySetConnectionSettings,"\x3f",0x03,0x28,ID_SetConnectSet }, 5666 {N6510_ReplySetConnectionSettings,"\x3f",0x03,0x28,ID_SetConnectSet },
5586 {N6510_ReplySetConnectionSettings,"\x3f",0x03,0x2B,ID_SetConnectSet }, 5667 {N6510_ReplySetConnectionSettings,"\x3f",0x03,0x2B,ID_SetConnectSet },
5587 {N6510_ReplyGetChatSettings, "\x3f",0x03,0x3B,ID_GetChatSettings }, 5668 {N6510_ReplyGetChatSettings, "\x3f",0x03,0x3B,ID_GetChatSettings },
5588 {N6510_ReplyGetChatSettings, "\x3f",0x03,0x3C,ID_GetChatSettings }, 5669 {N6510_ReplyGetChatSettings, "\x3f",0x03,0x3C,ID_GetChatSettings },
5589 5670
5590 {N6510_ReplyGetOriginalIMEI, "\x42",0x07,0x00,ID_GetOriginalIMEI }, 5671 {N6510_ReplyGetOriginalIMEI, "\x42",0x07,0x00,ID_GetOriginalIMEI },
5591 {N6510_ReplyGetManufactureMonth, "\x42",0x07,0x00,ID_GetManufactureMonth }, 5672 {N6510_ReplyGetManufactureMonth, "\x42",0x07,0x00,ID_GetManufactureMonth },
5592 {N6510_ReplyGetOriginalIMEI, "\x42",0x07,0x01,ID_GetOriginalIMEI }, 5673 {N6510_ReplyGetOriginalIMEI, "\x42",0x07,0x01,ID_GetOriginalIMEI },
5593 {N6510_ReplyGetManufactureMonth, "\x42",0x07,0x02,ID_GetManufactureMonth }, 5674 {N6510_ReplyGetManufactureMonth, "\x42",0x07,0x02,ID_GetManufactureMonth },
5594 5675
5595 {N6510_ReplySetOperatorLogo, "\x43",0x03,0x08,ID_SetBitmap }, 5676 {N6510_ReplySetOperatorLogo, "\x43",0x03,0x08,ID_SetBitmap },
5596 {N6510_ReplyGetGPRSAccessPoint, "\x43",0x03,0x06,ID_GetGPRSPoint }, 5677 {N6510_ReplyGetGPRSAccessPoint, "\x43",0x03,0x06,ID_GetGPRSPoint },
5597 {N6510_ReplySetGPRSAccessPoint1, "\x43",0x03,0x06,ID_SetGPRSPoint }, 5678 {N6510_ReplySetGPRSAccessPoint1, "\x43",0x03,0x06,ID_SetGPRSPoint },
5598#ifdef DEVELOP 5679#ifdef DEVELOP
5599 {N6510_ReplyEnableGPRSAccessPoint,"\x43",0x03,0x06,ID_EnableGPRSPoint }, 5680 {N6510_ReplyEnableGPRSAccessPoint,"\x43",0x03,0x06,ID_EnableGPRSPoint },
5600#endif 5681#endif
5601 {N6510_ReplyGetSyncMLSettings, "\x43",0x03,0x06,ID_GetSyncMLSettings }, 5682 {N6510_ReplyGetSyncMLSettings, "\x43",0x03,0x06,ID_GetSyncMLSettings },
5602 {N6510_ReplyGetSyncMLName, "\x43",0x03,0x06,ID_GetSyncMLName }, 5683 {N6510_ReplyGetSyncMLName, "\x43",0x03,0x06,ID_GetSyncMLName },
5603 {NoneReply, "\x43",0x03,0x08,ID_SetGPRSPoint }, 5684 {NoneReply, "\x43",0x03,0x08,ID_SetGPRSPoint },
5604 5685
5605 /* 0x4A - voice records */ 5686 /* 0x4A - voice records */
5606 5687
5607 /* 0x53 - simlock */ 5688 /* 0x53 - simlock */
5608 5689
5609 {N6510_ReplyAddToDo1, "\x55",0x03,0x02,ID_SetToDo }, 5690 {N6510_ReplyAddToDo1, "\x55",0x03,0x02,ID_SetToDo },
5610 {N6510_ReplyGetToDo1, "\x55",0x03,0x04,ID_GetToDo }, 5691 {N6510_ReplyGetToDo1, "\x55",0x03,0x04,ID_GetToDo },
5611 {N6510_ReplyGetToDoFirstLoc1, "\x55",0x03,0x10,ID_SetToDo }, 5692 {N6510_ReplyGetToDoFirstLoc1, "\x55",0x03,0x10,ID_SetToDo },
5612 {N6510_ReplyDeleteAllToDo1, "\x55",0x03,0x12,ID_DeleteAllToDo }, 5693 {N6510_ReplyDeleteAllToDo1, "\x55",0x03,0x12,ID_DeleteAllToDo },
5613 {N6510_ReplyGetToDoStatus1, "\x55",0x03,0x16,ID_GetToDo }, 5694 {N6510_ReplyGetToDoStatus1, "\x55",0x03,0x16,ID_GetToDo },
5614 5695
5615 {N6510_ReplyAddFileHeader, "\x6D",0x03,0x03,ID_AddFile }, 5696 {N6510_ReplyAddFileHeader, "\x6D",0x03,0x03,ID_AddFile },
5616 {N6510_ReplyAddFolder, "\x6D",0x03,0x05,ID_AddFolder }, 5697 {N6510_ReplyAddFolder, "\x6D",0x03,0x05,ID_AddFolder },
5617 {N6510_ReplyGetFilePart, "\x6D",0x03,0x0F,ID_GetFile }, 5698 {N6510_ReplyGetFilePart, "\x6D",0x03,0x0F,ID_GetFile },
5618 {N6510_ReplyAddFileHeader, "\x6D",0x03,0x13,ID_AddFile }, 5699 {N6510_ReplyAddFileHeader, "\x6D",0x03,0x13,ID_AddFile },
5619 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x15,ID_GetFileInfo }, 5700 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x15,ID_GetFileInfo },
5620 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x15,ID_GetFile }, 5701 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x15,ID_GetFile },
5621 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x15,ID_AddFile }, 5702 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x15,ID_AddFile },
5622 {N6510_ReplyDeleteFile, "\x6D",0x03,0x19,ID_DeleteFile }, 5703 {N6510_ReplyDeleteFile, "\x6D",0x03,0x19,ID_DeleteFile },
5623 {N6510_ReplyDeleteFile, "\x6D",0x03,0x1F,ID_DeleteFile }, 5704 {N6510_ReplyDeleteFile, "\x6D",0x03,0x1F,ID_DeleteFile },
5624 {N6510_ReplyGetFileSystemStatus, "\x6D",0x03,0x23,ID_FileSystemStatus }, 5705 {N6510_ReplyGetFileSystemStatus, "\x6D",0x03,0x23,ID_FileSystemStatus },
5625 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x2F,ID_GetFileInfo }, 5706 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x2F,ID_GetFileInfo },
5626 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x2F,ID_GetFile }, 5707 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x2F,ID_GetFile },
5627 {N6510_ReplyGetFileSystemStatus, "\x6D",0x03,0x2F,ID_FileSystemStatus }, 5708 {N6510_ReplyGetFileSystemStatus, "\x6D",0x03,0x2F,ID_FileSystemStatus },
5628 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x33,ID_GetFileInfo }, 5709 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x33,ID_GetFileInfo },
5629 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x33,ID_GetFile }, 5710 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x33,ID_GetFile },
5630 {N6510_ReplyAddFilePart, "\x6D",0x03,0x41,ID_AddFile }, 5711 {N6510_ReplyAddFilePart, "\x6D",0x03,0x41,ID_AddFile },
5631 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x43,ID_AddFile }, 5712 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x43,ID_AddFile },
5632 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x43,ID_GetFile }, 5713 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x43,ID_GetFile },
5633 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x43,ID_GetFileInfo }, 5714 {N6510_ReplyGetFileFolderInfo, "\x6D",0x03,0x43,ID_GetFileInfo },
5634 5715
5635 {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x01,ID_GetBitmap }, 5716 {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x01,ID_GetBitmap },
5636 {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x01,ID_SetBitmap }, 5717 {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x01,ID_SetBitmap },
5637 {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x0F,ID_GetBitmap }, 5718 {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x0F,ID_GetBitmap },
5638 {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x0F,ID_SetBitmap }, 5719 {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x0F,ID_SetBitmap },
5639 {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x10,ID_GetBitmap }, 5720 {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x10,ID_GetBitmap },
5640 {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x10,ID_SetBitmap }, 5721 {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x10,ID_SetBitmap },
5641 {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x25,ID_SetBitmap }, 5722 {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x25,ID_SetBitmap },
5642 5723
5643 {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetModel }, 5724 {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetModel },
5644 {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetFirmware }, 5725 {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetFirmware },
5645 5726
5646 /* 0xD7 - Bluetooth */ 5727 /* 0xD7 - Bluetooth */
5647 5728
5648 {N6510_ReplyGetRingtoneID, "\xDB",0x03,0x02,ID_SetRingtone }, 5729 {N6510_ReplyGetRingtoneID, "\xDB",0x03,0x02,ID_SetRingtone },
5649 5730
5650 {NULL, "\x00",0x00,0x00,ID_None } 5731 {NULL, "\x00",0x00,0x00,ID_None }
5651}; 5732};
5652 5733
5653GSM_Phone_Functions N6510Phone = { 5734GSM_Phone_Functions N6510Phone = {
5654 "1100|1100a|1100b|3100|3100b|3108|3200|3200a|3300|3510|3510i|3530|3589i|3590|3595|5100|6100|6200|6220|6230|6310|6310i|6385|6510|6610|6800|7210|7250|7250i|7600|8310|8390|8910|8910i", 5735 "1100|1100a|1100b|3100|3100b|3108|3200|3200a|3300|3510|3510i|3530|3589i|3590|3595|5100|5140|6100|6200|6220|6230|6310|6310i|6385|6510|6610|6610i|6800|6810|6820|7210|7250|7250i|7600|8310|8390|8910|8910i",
5655 N6510ReplyFunctions, 5736 N6510ReplyFunctions,
5656 N6510_Initialise, 5737 N6510_Initialise,
5657 NONEFUNCTION, /* Terminate */ 5738 NONEFUNCTION, /* Terminate */
5658 GSM_DispatchMessage, 5739 GSM_DispatchMessage,
5659 N6510_ShowStartInfo, 5740 N6510_ShowStartInfo,
5660 NOKIA_GetManufacturer, 5741 NOKIA_GetManufacturer,
5661 DCT3DCT4_GetModel, 5742 DCT3DCT4_GetModel,
5662 DCT3DCT4_GetFirmware, 5743 DCT3DCT4_GetFirmware,
5663 DCT4_GetIMEI, 5744 DCT4_GetIMEI,
5664 N6510_GetOriginalIMEI, 5745 N6510_GetOriginalIMEI,
5665 N6510_GetManufactureMonth, 5746 N6510_GetManufactureMonth,
5666 DCT4_GetProductCode, 5747 DCT4_GetProductCode,
5667 DCT4_GetHardware, 5748 DCT4_GetHardware,
5668 N6510_GetPPM, 5749 N6510_GetPPM,
5669 NOTSUPPORTED, /* GetSIMIMSI */ 5750 NOTSUPPORTED, /* GetSIMIMSI */
5670 N6510_GetDateTime, 5751 N6510_GetDateTime,
5671 N6510_SetDateTime, 5752 N6510_SetDateTime,
5672 N6510_GetAlarm, 5753 N6510_GetAlarm,
5673 N6510_SetAlarm, 5754 N6510_SetAlarm,
5674 N6510_GetLocale, 5755 N6510_GetLocale,
5675 NOTSUPPORTED, /* SetLocale */ 5756 NOTSUPPORTED, /* SetLocale */
5676 N6510_PressKey, 5757 N6510_PressKey,
5677 DCT4_Reset, 5758 DCT4_Reset,
5678 NOTIMPLEMENTED, /* ResetPhoneSettings*/ 5759 NOTIMPLEMENTED, /* ResetPhoneSettings*/
5679 N6510_EnterSecurityCode, 5760 N6510_EnterSecurityCode,
5680 N6510_GetSecurityStatus, 5761 N6510_GetSecurityStatus,
5681 NOTSUPPORTED, /* GetDisplayStatus*/ 5762 NOTSUPPORTED, /* GetDisplayStatus*/
5682 NOTIMPLEMENTED, /* SetAutoNetworkLogin*/ 5763 NOTIMPLEMENTED, /* SetAutoNetworkLogin*/
5683 N6510_GetBatteryCharge, 5764 N6510_GetBatteryCharge,
5684 N6510_GetSignalQuality, 5765 N6510_GetSignalQuality,
5685 N6510_GetNetworkInfo, 5766 N6510_GetNetworkInfo,
5686 NOTSUPPORTED, /* GetCategory */ 5767 NOTSUPPORTED, /* GetCategory */
5687 NOTSUPPORTED, /* AddCategory */ 5768 NOTSUPPORTED, /* AddCategory */
5688 NOTSUPPORTED, /* GetCategoryStatus */ 5769 NOTSUPPORTED, /* GetCategoryStatus */
5689 N6510_GetMemoryStatus, 5770 N6510_GetMemoryStatus,
5690 N6510_GetMemory, 5771 N6510_GetMemory,
5691 NOTIMPLEMENTED, /* GetNextMemory */ 5772 NOTIMPLEMENTED, /* GetNextMemory */
5692 N6510_SetMemory, 5773 N6510_SetMemory,
5693 NOTIMPLEMENTED, /* AddMemory */ 5774 NOTIMPLEMENTED, /* AddMemory */
5694 N6510_DeleteMemory, 5775 N6510_DeleteMemory,
5695 NOTIMPLEMENTED, /* DeleteAllMemory */ 5776 NOTIMPLEMENTED, /* DeleteAllMemory */
5696 N6510_GetSpeedDial, 5777 N6510_GetSpeedDial,
5697 NOTIMPLEMENTED, /* SetSpeedDial */ 5778 NOTIMPLEMENTED, /* SetSpeedDial */
5698 N6510_GetSMSC, 5779 N6510_GetSMSC,
5699 N6510_SetSMSC, 5780 N6510_SetSMSC,
5700 N6510_GetSMSStatus, 5781 N6510_GetSMSStatus,
5701 N6510_GetSMSMessage, 5782 N6510_GetSMSMessage,
5702 N6510_GetNextSMSMessage, 5783 N6510_GetNextSMSMessage,
5703 N6510_SetSMS, 5784 N6510_SetSMS,
5704 N6510_AddSMS, 5785 N6510_AddSMS,
5705 N6510_DeleteSMSMessage, 5786 N6510_DeleteSMSMessage,
5706 N6510_SendSMSMessage, 5787 N6510_SendSMSMessage,
5707 NOTSUPPORTED, /* SendSavedSMS */ 5788 NOTSUPPORTED, /* SendSavedSMS */
5789 NOTSUPPORTED, /* SetFastSMSSending*/
5708 NOKIA_SetIncomingSMS, 5790 NOKIA_SetIncomingSMS,
5709 NOTIMPLEMENTED, /* SetIncomingCB */ 5791 NOTIMPLEMENTED, /* SetIncomingCB */
5710 N6510_GetSMSFolders, 5792 N6510_GetSMSFolders,
5711 N6510_AddSMSFolder, 5793 N6510_AddSMSFolder,
5712 NOTIMPLEMENTED, /* DeleteSMSFolder */ 5794 NOTIMPLEMENTED, /* DeleteSMSFolder */
5713 N6510_DialVoice, 5795 N6510_DialVoice,
5714 N6510_AnswerCall, 5796 N6510_AnswerCall,
5715 N6510_CancelCall, 5797 N6510_CancelCall,
5716 NOTIMPLEMENTED, /* HoldCall */ 5798 NOTIMPLEMENTED, /* HoldCall */
5717 NOTIMPLEMENTED, /* UnholdCall */ 5799 NOTIMPLEMENTED, /* UnholdCall */
5718 NOTIMPLEMENTED, /* ConferenceCall */ 5800 NOTIMPLEMENTED, /* ConferenceCall */
5719 NOTIMPLEMENTED, /* SplitCall */ 5801 NOTIMPLEMENTED, /* SplitCall */
5720 NOTIMPLEMENTED, /* TransferCall */ 5802 NOTIMPLEMENTED, /* TransferCall */
5721 NOTIMPLEMENTED, /* SwitchCall */ 5803 NOTIMPLEMENTED, /* SwitchCall */
5722 DCT3DCT4_GetCallDivert, 5804 DCT3DCT4_GetCallDivert,
5723 DCT3DCT4_SetCallDivert, 5805 DCT3DCT4_SetCallDivert,
5724 DCT3DCT4_CancelAllDiverts, 5806 DCT3DCT4_CancelAllDiverts,
5725 NOKIA_SetIncomingCall, 5807 NOKIA_SetIncomingCall,
5726 NOKIA_SetIncomingUSSD, 5808 NOKIA_SetIncomingUSSD,
5727 DCT3DCT4_SendDTMF, 5809 DCT3DCT4_SendDTMF,
5728 N6510_GetRingtone, 5810 N6510_GetRingtone,
5729 N6510_SetRingtone, 5811 N6510_SetRingtone,
5730 N6510_GetRingtonesInfo, 5812 N6510_GetRingtonesInfo,
5731 N6510_DeleteUserRingtones, 5813 N6510_DeleteUserRingtones,
5732 N6510_PlayTone, 5814 N6510_PlayTone,
5733 N6510_GetWAPBookmark, 5815 N6510_GetWAPBookmark,
5734 N6510_SetWAPBookmark, 5816 N6510_SetWAPBookmark,
5735 N6510_DeleteWAPBookmark, 5817 N6510_DeleteWAPBookmark,
5736 N6510_GetWAPSettings, 5818 N6510_GetWAPSettings,
5737 N6510_SetWAPSettings, 5819 N6510_SetWAPSettings,
5738 N6510_GetMMSSettings, 5820 N6510_GetMMSSettings,
5739 N6510_SetMMSSettings, 5821 N6510_SetMMSSettings,
5740 N6510_GetSyncMLSettings, 5822 N6510_GetSyncMLSettings,
5741 NOTSUPPORTED, /* SetSyncMLSettings*/ 5823 NOTSUPPORTED, /* SetSyncMLSettings*/
5742 N6510_GetChatSettings, 5824 N6510_GetChatSettings,
5743 NOTSUPPORTED, /* SetChatSettings */ 5825 NOTSUPPORTED, /* SetChatSettings */
5744 N6510_GetBitmap, 5826 N6510_GetBitmap,
5745 N6510_SetBitmap, 5827 N6510_SetBitmap,
5746 N6510_GetToDoStatus, 5828 N6510_GetToDoStatus,
5747 NOTIMPLEMENTED, /* GetToDo */ 5829 NOTIMPLEMENTED, /* GetToDo */
5748 N6510_GetNextToDo, 5830 N6510_GetNextToDo,
5749 NOTIMPLEMENTED, /* SetToDo */ 5831 NOTIMPLEMENTED, /* SetToDo */
5750 N6510_AddToDo, 5832 N6510_AddToDo,
5751 N6510_DeleteToDo2, 5833 N6510_DeleteToDo2,
5752 N6510_DeleteAllToDo1, 5834 N6510_DeleteAllToDo1,
5753 N6510_GetCalendarStatus, 5835 N6510_GetCalendarStatus,
5754 NOTIMPLEMENTED, /* GetCalendar */ 5836 NOTIMPLEMENTED, /* GetCalendar */
5755 N6510_GetNextCalendar, 5837 N6510_GetNextCalendar,
5756 NOTIMPLEMENTED, /* SetCalendar */ 5838 NOTIMPLEMENTED, /* SetCalendar */
5757 N6510_AddCalendar, 5839 N6510_AddCalendar,
5758 N71_65_DelCalendar, 5840 N71_65_DelCalendar,
5759 NOTIMPLEMENTED, /* DeleteAllCalendar*/ 5841 NOTIMPLEMENTED, /* DeleteAllCalendar*/
5760 N6510_GetCalendarSettings, 5842 N6510_GetCalendarSettings,
5761 NOTSUPPORTED, /* SetCalendarSettings*/ 5843 NOTSUPPORTED, /* SetCalendarSettings*/
5762 NOTIMPLEMENTED, /* GetNote */ 5844 N6510_GetNextNote,
5763 N6510_GetProfile, 5845 N6510_GetProfile,
5764 N6510_SetProfile, 5846 N6510_SetProfile,
5765 N6510_GetFMStation, 5847 N6510_GetFMStation,
5766 N6510_SetFMStation, 5848 N6510_SetFMStation,
5767 N6510_ClearFMStations, 5849 N6510_ClearFMStations,
5768 N6510_GetNextFileFolder, 5850 N6510_GetNextFileFolder,
5769 N6510_GetFilePart, 5851 N6510_GetFilePart,
5770 N6510_AddFilePart, 5852 N6510_AddFilePart,
5771 N6510_GetFileSystemStatus, 5853 N6510_GetFileSystemStatus,
5772 N6510_DeleteFile, 5854 N6510_DeleteFile,
5773 N6510_AddFolder, 5855 N6510_AddFolder,
5774 N6510_GetGPRSAccessPoint, 5856 N6510_GetGPRSAccessPoint,
5775 N6510_SetGPRSAccessPoint 5857 N6510_SetGPRSAccessPoint
5776}; 5858};
5777 5859
5778#endif 5860#endif
5779 5861
5780/* How should editor hadle tabs in this file? Add editor commands here. 5862/* How should editor hadle tabs in this file? Add editor commands here.
5781 * vim: noexpandtab sw=8 ts=8 sts=8: 5863 * vim: noexpandtab sw=8 ts=8 sts=8:
5782 */ 5864 */
diff --git a/gammu/emb/common/phone/nokia/dct4/n6510.h b/gammu/emb/common/phone/nokia/dct4/n6510.h
index 4717aeb..26623d6 100644
--- a/gammu/emb/common/phone/nokia/dct4/n6510.h
+++ b/gammu/emb/common/phone/nokia/dct4/n6510.h
@@ -1,90 +1,92 @@
1/* (c) 2002-2004 by Marcin Wiacek */ 1/* (c) 2002-2004 by Marcin Wiacek */
2 2
3#ifndef n6510_h 3#ifndef n6510_h
4#define n6510_h 4#define n6510_h
5 5
6#include "../ncommon.h" 6#include "../ncommon.h"
7#include "../../../service/sms/gsmsms.h" 7#include "../../../service/sms/gsmsms.h"
8 8
9typedef enum { 9typedef enum {
10 N6510_MMS_SETTINGS = 0x01, 10 N6510_MMS_SETTINGS = 0x01,
11 N6510_CHAT_SETTINGS, 11 N6510_CHAT_SETTINGS,
12 12
13 N6510_WAP_SETTINGS, 13 N6510_WAP_SETTINGS,
14 N6510_SYNCML_SETTINGS 14 N6510_SYNCML_SETTINGS
15} N6510_Connection_Settings; 15} N6510_Connection_Settings;
16 16
17typedef enum { 17typedef enum {
18 N6510_LIGHT_DISPLAY = 0x01, 18 N6510_LIGHT_DISPLAY = 0x01,
19 N6510_LIGHT_KEYPAD = 0x03, 19 N6510_LIGHT_KEYPAD = 0x03,
20 N6510_LIGHT_TORCH = 0x10 20 N6510_LIGHT_TORCH = 0x10
21} N6510_PHONE_LIGHTS; 21} N6510_PHONE_LIGHTS;
22 22
23typedef struct { 23typedef struct {
24 int LastCalendarYear; 24 int LastCalendarYear;
25 int LastCalendarPos; 25 int LastCalendarPos;
26 GSM_NOKIACalToDoLocationsLastCalendar; 26 GSM_NOKIACalToDoLocationsLastCalendar;
27 int FirstCalendarPos; 27 int FirstCalendarPos;
28 unsigned char CalendarIcons[10]; 28 unsigned char CalendarIcons[10];
29 GSM_CalendarNoteType CalendarIconsTypes[10]; 29 GSM_CalendarNoteType CalendarIconsTypes[10];
30 int CalendarIconsNum; 30 int CalendarIconsNum;
31 31
32 GSM_NOKIASMSFolder LastSMSFolder; 32 GSM_NOKIASMSFolder LastSMSFolder;
33 GSM_SMSFolders LastSMSFolders; 33 GSM_SMSFolders LastSMSFolders;
34 34
35 GSM_NOKIACalToDoLocationsLastToDo; 35 GSM_NOKIACalToDoLocationsLastToDo;
36 36
37 GSM_NOKIACalToDoLocationsLastNote;
38
37 unsigned char RingtoneID;/* When set with preview */ 39 unsigned char RingtoneID;/* When set with preview */
38 40
39 int FilesLocations[1000]; 41 int FilesLocations[1000];
40 int FilesLevels[1000]; 42 int FilesLevels[1000];
41 int FilesLocationsUsed; 43 int FilesLocationsUsed;
42 int FilesLocationsCurrent; 44 int FilesLocationsCurrent;
43 int FileToken; 45 int FileToken;
44 int ParentID; 46 int ParentID;
45 int FileCheckSum; 47 int FileCheckSum;
46 48
47 unsigned char FMStatus[4000]; 49 unsigned char FMStatus[4000];
48 int FMStatusLength; 50 int FMStatusLength;
49 51
50 unsigned char GPRSPoints[4000]; 52 unsigned char GPRSPoints[4000];
51 int GPRSPointsLength; 53 int GPRSPointsLength;
52 54
53 int BearerNumber; 55 int BearerNumber;
54 56
55 unsigned char PhoneMode; 57 unsigned char PhoneMode;
56} GSM_Phone_N6510Data; 58} GSM_Phone_N6510Data;
57 59
58void N6510_EncodeFMFrequency(double freq, unsigned char *buff); 60void N6510_EncodeFMFrequency(double freq, unsigned char *buff);
59void N6510_DecodeFMFrequency(double *freq, unsigned char *buff); 61void N6510_DecodeFMFrequency(double *freq, unsigned char *buff);
60 62
61#ifndef GSM_USED_MBUS2 63#ifndef GSM_USED_MBUS2
62# define GSM_USED_MBUS2 64# define GSM_USED_MBUS2
63#endif 65#endif
64#ifndef GSM_USED_FBUS2 66#ifndef GSM_USED_FBUS2
65# define GSM_USED_FBUS2 67# define GSM_USED_FBUS2
66#endif 68#endif
67#ifndef GSM_USED_FBUS2DLR3 69#ifndef GSM_USED_FBUS2DLR3
68# define GSM_USED_FBUS2DLR3 70# define GSM_USED_FBUS2DLR3
69#endif 71#endif
70#ifndef GSM_USED_FBUS2DKU5 72#ifndef GSM_USED_FBUS2DKU5
71# define GSM_USED_FBUS2DKU5 73# define GSM_USED_FBUS2DKU5
72#endif 74#endif
73#ifndef GSM_USED_PHONETBLUE 75#ifndef GSM_USED_PHONETBLUE
74# define GSM_USED_PHONETBLUE 76# define GSM_USED_PHONETBLUE
75#endif 77#endif
76#ifndef GSM_USED_IRDAPHONET 78#ifndef GSM_USED_IRDAPHONET
77# define GSM_USED_IRDAPHONET 79# define GSM_USED_IRDAPHONET
78#endif 80#endif
79#ifndef GSM_USED_BLUEPHONET 81#ifndef GSM_USED_BLUEPHONET
80# define GSM_USED_BLUEPHONET 82# define GSM_USED_BLUEPHONET
81#endif 83#endif
82#ifndef GSM_USED_FBUS2PL2303 84#ifndef GSM_USED_FBUS2PL2303
83# define GSM_USED_FBUS2PL2303 85# define GSM_USED_FBUS2PL2303
84#endif 86#endif
85 87
86#endif 88#endif
87 89
88/* How should editor hadle tabs in this file? Add editor commands here. 90/* How should editor hadle tabs in this file? Add editor commands here.
89 * vim: noexpandtab sw=8 ts=8 sts=8: 91 * vim: noexpandtab sw=8 ts=8 sts=8:
90 */ 92 */
diff --git a/gammu/emb/common/phone/nokia/nauto.c b/gammu/emb/common/phone/nokia/nauto.c
index bf74bc9..3bb53ec 100644
--- a/gammu/emb/common/phone/nokia/nauto.c
+++ b/gammu/emb/common/phone/nokia/nauto.c
@@ -1,144 +1,144 @@
1/* (c) 2002-2003 by Marcin Wiacek */ 1/* (c) 2002-2003 by Marcin Wiacek */
2 2
3#include <string.h> 3#include <string.h>
4#include <time.h> 4#include <time.h>
5 5
6#include "../../gsmcomon.h" 6#include "../../gsmcomon.h"
7#include "../../gsmstate.h" 7#include "../../gsmstate.h"
8#include "nfunc.h" 8#include "nfunc.h"
9 9
10#if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4) 10#if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4)
11 11
12static GSM_Reply_Function NAUTOReplyFunctions[] = { 12static GSM_Reply_Function NAUTOReplyFunctions[] = {
13 {DCT3DCT4_ReplyGetModelFirmware,"\xD2",0x02,0x00,ID_GetModel }, 13 {DCT3DCT4_ReplyGetModelFirmware,"\xD2",0x02,0x00,ID_GetModel },
14 {DCT3DCT4_ReplyGetModelFirmware,"\xD2",0x02,0x00,ID_GetFirmware }, 14 {DCT3DCT4_ReplyGetModelFirmware,"\xD2",0x02,0x00,ID_GetFirmware },
15 15
16 {NULL, "\x00",0x00,0x00,ID_None } 16 {NULL, "\x00",0x00,0x00,ID_None }
17}; 17};
18 18
19GSM_Phone_Functions NAUTOPhone = { 19GSM_Phone_Functions NAUTOPhone = {
20 "NAUTO", 20 "NAUTO",
21 NAUTOReplyFunctions, 21 NAUTOReplyFunctions,
22 NONEFUNCTION, /* Initialise */ 22 NONEFUNCTION, /* Initialise */
23 NONEFUNCTION, /* Terminate */ 23 NONEFUNCTION, /* Terminate */
24 GSM_DispatchMessage, 24 GSM_DispatchMessage,
25 NOTSUPPORTED, /* ShowStartInfo */ 25 NOTSUPPORTED, /* ShowStartInfo */
26 NOKIA_GetManufacturer, 26 NOKIA_GetManufacturer,
27 DCT3DCT4_GetModel, 27 DCT3DCT4_GetModel,
28 DCT3DCT4_GetFirmware, 28 DCT3DCT4_GetFirmware,
29 NOTSUPPORTED, /* GetIMEI */ 29 NOTSUPPORTED, /* GetIMEI */
30 NOTSUPPORTED, /* GetOriginalIMEI */ 30 NOTSUPPORTED, /* GetOriginalIMEI */
31 NOTSUPPORTED, /* GetManufactureMonth*/ 31 NOTSUPPORTED, /* GetManufactureMonth*/
32 NOTSUPPORTED, /* GetProductCode */ 32 NOTSUPPORTED, /* GetProductCode */
33 NOTSUPPORTED, /* GetHardware */ 33 NOTSUPPORTED, /* GetHardware */
34 NOTSUPPORTED, /* GetPPM */ 34 NOTSUPPORTED, /* GetPPM */
35 NOTSUPPORTED, /* GetSIMIMSI */ 35 NOTSUPPORTED, /* GetSIMIMSI */
36 NOTSUPPORTED, /* GetDateTime */ 36 NOTSUPPORTED, /* GetDateTime */
37 NOTSUPPORTED, /* SetDateTime */ 37 NOTSUPPORTED, /* SetDateTime */
38 NOTSUPPORTED, /* GetAlarm */ 38 NOTSUPPORTED, /* GetAlarm */
39 NOTSUPPORTED, /* SetAlarm */ 39 NOTSUPPORTED, /* SetAlarm */
40 NOTSUPPORTED, /* GetLocale */ 40 NOTSUPPORTED, /* GetLocale */
41 NOTSUPPORTED, /* SetLocale */ 41 NOTSUPPORTED, /* SetLocale */
42 NOTSUPPORTED, /* PressKey */ 42 NOTSUPPORTED, /* PressKey */
43 NOTSUPPORTED, /* Reset */ 43 NOTSUPPORTED, /* Reset */
44 NOTSUPPORTED, /* ResetPhoneSettings*/ 44 NOTSUPPORTED, /* ResetPhoneSettings*/
45 NOTSUPPORTED, /* EnterSecurityCode*/ 45 NOTSUPPORTED, /* EnterSecurityCode*/
46 NOTSUPPORTED, /* GetSecurityStatus*/ 46 NOTSUPPORTED, /* GetSecurityStatus*/
47 NOTSUPPORTED, /* GetDisplayStatus*/ 47 NOTSUPPORTED, /* GetDisplayStatus*/
48 NOTSUPPORTED, /* SetAutoNetworkLogin*/ 48 NOTSUPPORTED, /* SetAutoNetworkLogin*/
49 NOTSUPPORTED, /* GetBatteryCharge*/ 49 NOTSUPPORTED, /* GetBatteryCharge*/
50 NOTSUPPORTED, /* GetSignalQuality*/ 50 NOTSUPPORTED, /* GetSignalQuality*/
51 NOTSUPPORTED, /* GetNetworkInfo */ 51 NOTSUPPORTED, /* GetNetworkInfo */
52 NOTSUPPORTED, /* GetCategory */ 52 NOTSUPPORTED, /* GetCategory */
53 NOTSUPPORTED, /* AddCategory */ 53 NOTSUPPORTED, /* AddCategory */
54 NOTSUPPORTED, /* GetCategoryStatus */ 54 NOTSUPPORTED, /* GetCategoryStatus */
55 NOTSUPPORTED, /* GetMemoryStatus */ 55 NOTSUPPORTED, /* GetMemoryStatus */
56 NOTSUPPORTED, /* GetMemory */ 56 NOTSUPPORTED, /* GetMemory */
57 NOTSUPPORTED, /* GetNextMemory */ 57 NOTSUPPORTED, /* GetNextMemory */
58 NOTSUPPORTED, /* SetMemory */ 58 NOTSUPPORTED, /* SetMemory */
59 NOTSUPPORTED, /* AddMemory */ 59 NOTSUPPORTED, /* AddMemory */
60 NOTSUPPORTED, /* DeleteMemory */ 60 NOTSUPPORTED, /* DeleteMemory */
61 NOTIMPLEMENTED, /* DeleteAllMemory */ 61 NOTIMPLEMENTED, /* DeleteAllMemory */
62 NOTSUPPORTED, /* GetSpeedDial */ 62 NOTSUPPORTED, /* GetSpeedDial */
63 NOTSUPPORTED, /* SetSpeedDial */ 63 NOTSUPPORTED, /* SetSpeedDial */
64 NOTSUPPORTED, /* GetSMSC */ 64 NOTSUPPORTED, /* GetSMSC */
65 NOTSUPPORTED, /* SetSMSC */ 65 NOTSUPPORTED, /* SetSMSC */
66 NOTSUPPORTED, /* GetSMSStatus */ 66 NOTSUPPORTED, /* GetSMSStatus */
67 NOTSUPPORTED, /* GetSMS */ 67 NOTSUPPORTED, /* GetSMS */
68 NOTSUPPORTED, /* GetNextSMS */ 68 NOTSUPPORTED, /* GetNextSMS */
69 NOTSUPPORTED, /* SetSMS */ 69 NOTSUPPORTED, /* SetSMS */
70 NOTSUPPORTED, /* AddSMS */ 70 NOTSUPPORTED, /* AddSMS */
71 NOTSUPPORTED, /* DeleteSMS */ 71 NOTSUPPORTED, /* DeleteSMS */
72 NOTSUPPORTED, /* SendSMSMessage */ 72 NOTSUPPORTED, /* SendSMSMessage */
73 NOTSUPPORTED, /* SendSavedSMS */ 73 NOTSUPPORTED, /* SendSavedSMS */
74 NOTSUPPORTED, /* SetIncomingSMS */ 74 NOTSUPPORTED, /* SetIncomingSMS */
75 NOTSUPPORTED, /* SetIncomingCB */ 75 NOTSUPPORTED, /* SetIncomingCB */
76 NOTSUPPORTED, /* GetSMSFolders */ 76 NOTSUPPORTED, /* GetSMSFolders */
77 NOTSUPPORTED, /* AddSMSFolder */ 77 NOTSUPPORTED, /* AddSMSFolder */
78 NOTSUPPORTED, /* DeleteSMSFolder */ 78 NOTSUPPORTED, /* DeleteSMSFolder */
79 NOTSUPPORTED, /* DialVoice */ 79 NOTSUPPORTED, /* DialVoice */
80 NOTSUPPORTED, /* AnswerCall */ 80 NOTSUPPORTED, /* AnswerCall */
81 NOTSUPPORTED, /* CancelCall */ 81 NOTSUPPORTED, /* CancelCall */
82 NOTSUPPORTED, /* HoldCall */ 82 NOTSUPPORTED, /* HoldCall */
83 NOTSUPPORTED, /* UnholdCall */ 83 NOTSUPPORTED, /* UnholdCall */
84 NOTSUPPORTED, /* ConferenceCall */ 84 NOTSUPPORTED, /* ConferenceCall */
85 NOTSUPPORTED, /* SplitCall */ 85 NOTSUPPORTED, /* SplitCall */
86 NOTSUPPORTED, /* TransferCall */ 86 NOTSUPPORTED, /* TransferCall */
87 NOTSUPPORTED, /* SwitchCall */ 87 NOTSUPPORTED, /* SwitchCall */
88 NOTSUPPORTED, /* GetCallDivert */ 88 NOTSUPPORTED, /* GetCallDivert */
89 NOTSUPPORTED, /* SetCallDivert */ 89 NOTSUPPORTED, /* SetCallDivert */
90 NOTSUPPORTED, /* CancelAllDiverts*/ 90 NOTSUPPORTED, /* CancelAllDiverts*/
91 NOTSUPPORTED, /* SetIncomingCall */ 91 NOTSUPPORTED, /* SetIncomingCall */
92 NOTSUPPORTED, /* SetIncomingUSSD */ 92 NOTSUPPORTED, /* SetIncomingUSSD */
93 NOTSUPPORTED, /* SendDTMF */ 93 NOTSUPPORTED, /* SendDTMF */
94 NOTSUPPORTED, /* GetRingtone */ 94 NOTSUPPORTED, /* GetRingtone */
95 NOTSUPPORTED, /* SetRingtone */ 95 NOTSUPPORTED, /* SetRingtone */
96 NOTSUPPORTED, /* GetRingtonesInfo*/ 96 NOTSUPPORTED, /* GetRingtonesInfo*/
97 NOTSUPPORTED, /* DeleteUserRingtones*/ 97 NOTSUPPORTED, /* DeleteUserRingtones*/
98 NOTSUPPORTED, /* PlayTone */ 98 NOTSUPPORTED, /* PlayTone */
99 NOTSUPPORTED, /* GetWAPBookmark */ 99 NOTSUPPORTED, /* GetWAPBookmark */
100 NOTSUPPORTED, /* SetWAPBookmark */ 100 NOTSUPPORTED, /* SetWAPBookmark */
101 NOTSUPPORTED, /* DeleteWAPBookmark */ 101 NOTSUPPORTED, /* DeleteWAPBookmark */
102 NOTSUPPORTED, /* GetWAPSettings */ 102 NOTSUPPORTED, /* GetWAPSettings */
103 NOTSUPPORTED, /* SetWAPSettings */ 103 NOTSUPPORTED, /* SetWAPSettings */
104 NOTSUPPORTED, /* GetMMSSettings */ 104 NOTSUPPORTED, /* GetMMSSettings */
105 NOTSUPPORTED, /* SetMMSSettings */ 105 NOTSUPPORTED, /* SetMMSSettings */
106 NOTSUPPORTED, /* GetBitmap */ 106 NOTSUPPORTED, /* GetBitmap */
107 NOTSUPPORTED, /* SetBitmap */ 107 NOTSUPPORTED, /* SetBitmap */
108 NOTSUPPORTED, /* GetToDoStatus */ 108 NOTSUPPORTED, /* GetToDoStatus */
109 NOTSUPPORTED, /* GetToDo */ 109 NOTSUPPORTED, /* GetToDo */
110 NOTSUPPORTED, /* GetNextToDo */ 110 NOTSUPPORTED, /* GetNextToDo */
111 NOTSUPPORTED, /* SetToDo */ 111 NOTSUPPORTED, /* SetToDo */
112 NOTSUPPORTED, /* AddToDo */ 112 NOTSUPPORTED, /* AddToDo */
113 NOTSUPPORTED, /* DeleteToDo */ 113 NOTSUPPORTED, /* DeleteToDo */
114 NOTSUPPORTED, /* DeleteAllToDo */ 114 NOTSUPPORTED, /* DeleteAllToDo */
115 NOTSUPPORTED, /* GetCalendarStatus*/ 115 NOTSUPPORTED, /* GetCalendarStatus*/
116 NOTSUPPORTED, /* GetCalendar */ 116 NOTSUPPORTED, /* GetCalendar */
117 NOTSUPPORTED, /* GetNextCalendar */ 117 NOTSUPPORTED, /* GetNextCalendar */
118 NOTSUPPORTED, /* SetCalendar */ 118 NOTSUPPORTED, /* SetCalendar */
119 NOTSUPPORTED, /* AddCalendar */ 119 NOTSUPPORTED, /* AddCalendar */
120 NOTSUPPORTED, /* DeleteCalendar */ 120 NOTSUPPORTED, /* DeleteCalendar */
121 NOTSUPPORTED, /* DeleteAllCalendar*/ 121 NOTSUPPORTED, /* DeleteAllCalendar*/
122 NOTSUPPORTED, /* GetCalendarSettings*/ 122 NOTSUPPORTED, /* GetCalendarSettings*/
123 NOTSUPPORTED, /* SetCalendarSettings*/ 123 NOTSUPPORTED, /* SetCalendarSettings*/
124 NOTSUPPORTED, /* GetNote */ 124 NOTSUPPORTED, /* GetNextNote */
125 NOTSUPPORTED, /* GetProfile */ 125 NOTSUPPORTED, /* GetProfile */
126 NOTSUPPORTED, /* SetProfile */ 126 NOTSUPPORTED, /* SetProfile */
127 NOTSUPPORTED, /* GetFMStation */ 127 NOTSUPPORTED, /* GetFMStation */
128 NOTSUPPORTED, /* SetFMStation */ 128 NOTSUPPORTED, /* SetFMStation */
129 NOTSUPPORTED, /* ClearFMStations */ 129 NOTSUPPORTED, /* ClearFMStations */
130 NOTSUPPORTED, /* GetNextFileFolder*/ 130 NOTSUPPORTED, /* GetNextFileFolder*/
131 NOTSUPPORTED, /* GetFilePart */ 131 NOTSUPPORTED, /* GetFilePart */
132 NOTSUPPORTED, /* AddFilePart */ 132 NOTSUPPORTED, /* AddFilePart */
133 NOTSUPPORTED, /* GetFileSystemStatus*/ 133 NOTSUPPORTED, /* GetFileSystemStatus*/
134 NOTSUPPORTED, /* DeleteFile */ 134 NOTSUPPORTED, /* DeleteFile */
135 NOTSUPPORTED, /* AddFolder */ 135 NOTSUPPORTED, /* AddFolder */
136 NOTSUPPORTED, /* GetGPRSAccessPoint*/ 136 NOTSUPPORTED, /* GetGPRSAccessPoint*/
137 NOTSUPPORTED /* SetGPRSAccessPoint*/ 137 NOTSUPPORTED /* SetGPRSAccessPoint*/
138}; 138};
139 139
140#endif 140#endif
141 141
142/* How should editor hadle tabs in this file? Add editor commands here. 142/* How should editor hadle tabs in this file? Add editor commands here.
143 * vim: noexpandtab sw=8 ts=8 sts=8: 143 * vim: noexpandtab sw=8 ts=8 sts=8:
144 */ 144 */
diff --git a/gammu/emb/common/phone/nokia/nfunc.c b/gammu/emb/common/phone/nokia/nfunc.c
index 3acfb10..d4d8b03 100644
--- a/gammu/emb/common/phone/nokia/nfunc.c
+++ b/gammu/emb/common/phone/nokia/nfunc.c
@@ -1204,413 +1204,427 @@ void NOKIA_FindFeatureValue(GSM_StateMachine *s,
1204 if ((Value & PROFILE_CALLERGROUPS_GROUP2)==PROFILE_CALLERGROUPS_GROUP2) Data->Profile->CallerGroups[1] = true; 1204 if ((Value & PROFILE_CALLERGROUPS_GROUP2)==PROFILE_CALLERGROUPS_GROUP2) Data->Profile->CallerGroups[1] = true;
1205 if ((Value & PROFILE_CALLERGROUPS_GROUP3)==PROFILE_CALLERGROUPS_GROUP3) Data->Profile->CallerGroups[2] = true; 1205 if ((Value & PROFILE_CALLERGROUPS_GROUP3)==PROFILE_CALLERGROUPS_GROUP3) Data->Profile->CallerGroups[2] = true;
1206 if ((Value & PROFILE_CALLERGROUPS_GROUP4)==PROFILE_CALLERGROUPS_GROUP4) Data->Profile->CallerGroups[3] = true; 1206 if ((Value & PROFILE_CALLERGROUPS_GROUP4)==PROFILE_CALLERGROUPS_GROUP4) Data->Profile->CallerGroups[3] = true;
1207 if ((Value & PROFILE_CALLERGROUPS_GROUP5)==PROFILE_CALLERGROUPS_GROUP5) Data->Profile->CallerGroups[4] = true; 1207 if ((Value & PROFILE_CALLERGROUPS_GROUP5)==PROFILE_CALLERGROUPS_GROUP5) Data->Profile->CallerGroups[4] = true;
1208 return; 1208 return;
1209 } 1209 }
1210 1210
1211 i = 0; 1211 i = 0;
1212 while (ProfileTable[i].ID != 0x00) { 1212 while (ProfileTable[i].ID != 0x00) {
1213 if (ProfileTable[i].PhoneID == ID && 1213 if (ProfileTable[i].PhoneID == ID &&
1214 ProfileTable[i].PhoneValue == Value) { 1214 ProfileTable[i].PhoneValue == Value) {
1215#ifdef DEBUG 1215#ifdef DEBUG
1216 switch (ProfileTable[i].ID) { 1216 switch (ProfileTable[i].ID) {
1217 case Profile_KeypadTone : smprintf(s, "Keypad tones\n"); break; 1217 case Profile_KeypadTone : smprintf(s, "Keypad tones\n"); break;
1218 case Profile_CallAlert : smprintf(s, "Call alert\n"); break; 1218 case Profile_CallAlert : smprintf(s, "Call alert\n"); break;
1219 case Profile_RingtoneVolume : smprintf(s, "Ringtone volume\n"); break; 1219 case Profile_RingtoneVolume : smprintf(s, "Ringtone volume\n"); break;
1220 case Profile_MessageTone : smprintf(s, "SMS message tones\n"); break; 1220 case Profile_MessageTone : smprintf(s, "SMS message tones\n"); break;
1221 case Profile_Vibration : smprintf(s, "Vibration\n"); break; 1221 case Profile_Vibration : smprintf(s, "Vibration\n"); break;
1222 case Profile_WarningTone: smprintf(s, "Warning (ang games) tones\n"); break; 1222 case Profile_WarningTone: smprintf(s, "Warning (ang games) tones\n"); break;
1223 case Profile_AutoAnswer : smprintf(s, "Automatic answer\n"); break; 1223 case Profile_AutoAnswer : smprintf(s, "Automatic answer\n"); break;
1224 case Profile_Lights : smprintf(s, "Lights\n"); break; 1224 case Profile_Lights : smprintf(s, "Lights\n"); break;
1225 case Profile_ScreenSaver : smprintf(s, "Screen Saver\n"); break; 1225 case Profile_ScreenSaver : smprintf(s, "Screen Saver\n"); break;
1226 case Profile_ScreenSaverTime : smprintf(s, "Screen Saver timeout\n"); break; 1226 case Profile_ScreenSaverTime : smprintf(s, "Screen Saver timeout\n"); break;
1227 default : break; 1227 default : break;
1228 } 1228 }
1229#endif 1229#endif
1230 Data->Profile->FeatureID[Data->Profile->FeaturesNumber] = ProfileTable[i].ID; 1230 Data->Profile->FeatureID[Data->Profile->FeaturesNumber] = ProfileTable[i].ID;
1231 Data->Profile->FeatureValue[Data->Profile->FeaturesNumber] = ProfileTable[i].Value; 1231 Data->Profile->FeatureValue[Data->Profile->FeaturesNumber] = ProfileTable[i].Value;
1232 Data->Profile->FeaturesNumber++; 1232 Data->Profile->FeaturesNumber++;
1233 break; 1233 break;
1234 } 1234 }
1235 i++; 1235 i++;
1236 } 1236 }
1237} 1237}
1238 1238
1239GSM_Profile_PhoneTableValue Profile71_65[] = { 1239GSM_Profile_PhoneTableValue Profile71_65[] = {
1240 {Profile_KeypadTone, PROFILE_KEYPAD_OFF, 0x00,0x00}, 1240 {Profile_KeypadTone, PROFILE_KEYPAD_OFF, 0x00,0x00},
1241 {Profile_KeypadTone, PROFILE_KEYPAD_LEVEL1, 0x00,0x01}, 1241 {Profile_KeypadTone, PROFILE_KEYPAD_LEVEL1, 0x00,0x01},
1242 {Profile_KeypadTone, PROFILE_KEYPAD_LEVEL2, 0x00,0x02}, 1242 {Profile_KeypadTone, PROFILE_KEYPAD_LEVEL2, 0x00,0x02},
1243 {Profile_KeypadTone, PROFILE_KEYPAD_LEVEL3, 0x00,0x03}, 1243 {Profile_KeypadTone, PROFILE_KEYPAD_LEVEL3, 0x00,0x03},
1244 /* Lights ? */ 1244 /* Lights ? */
1245 {Profile_CallAlert, PROFILE_CALLALERT_RINGING,0x02,0x00}, 1245 {Profile_CallAlert, PROFILE_CALLALERT_RINGING,0x02,0x00},
1246 {Profile_CallAlert, PROFILE_CALLALERT_ASCENDING,0x02,0x01}, 1246 {Profile_CallAlert, PROFILE_CALLALERT_ASCENDING,0x02,0x01},
1247 {Profile_CallAlert, PROFILE_CALLALERT_RINGONCE,0x02,0x02}, 1247 {Profile_CallAlert, PROFILE_CALLALERT_RINGONCE,0x02,0x02},
1248 {Profile_CallAlert, PROFILE_CALLALERT_BEEPONCE,0x02,0x03}, 1248 {Profile_CallAlert, PROFILE_CALLALERT_BEEPONCE,0x02,0x03},
1249 {Profile_CallAlert, PROFILE_CALLALERT_OFF, 0x02,0x05}, 1249 {Profile_CallAlert, PROFILE_CALLALERT_OFF, 0x02,0x05},
1250 /* {Profile_CallAlert, PROFILE_CALLALERT_CALLERGROUPS,0x02,0x07},*/ 1250 /* {Profile_CallAlert, PROFILE_CALLALERT_CALLERGROUPS,0x02,0x07},*/
1251 /* Ringtone ID */ 1251 /* Ringtone ID */
1252 {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL1, 0x04,0x00}, 1252 {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL1, 0x04,0x00},
1253 {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL2, 0x04,0x01}, 1253 {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL2, 0x04,0x01},
1254 {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL3, 0x04,0x02}, 1254 {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL3, 0x04,0x02},
1255 {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL4, 0x04,0x03}, 1255 {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL4, 0x04,0x03},
1256 {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL5, 0x04,0x04}, 1256 {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL5, 0x04,0x04},
1257 {Profile_MessageTone, PROFILE_MESSAGE_NOTONE,0x05,0x00}, 1257 {Profile_MessageTone, PROFILE_MESSAGE_NOTONE,0x05,0x00},
1258 {Profile_MessageTone, PROFILE_MESSAGE_STANDARD,0x05,0x01}, 1258 {Profile_MessageTone, PROFILE_MESSAGE_STANDARD,0x05,0x01},
1259 {Profile_MessageTone, PROFILE_MESSAGE_SPECIAL,0x05,0x02}, 1259 {Profile_MessageTone, PROFILE_MESSAGE_SPECIAL,0x05,0x02},
1260 {Profile_MessageTone, PROFILE_MESSAGE_BEEPONCE,0x05,0x03}, 1260 {Profile_MessageTone, PROFILE_MESSAGE_BEEPONCE,0x05,0x03},
1261 {Profile_MessageTone, PROFILE_MESSAGE_ASCENDING,0x05,0x04}, 1261 {Profile_MessageTone, PROFILE_MESSAGE_ASCENDING,0x05,0x04},
1262 {Profile_Vibration, PROFILE_VIBRATION_OFF, 0x06,0x00}, 1262 {Profile_Vibration, PROFILE_VIBRATION_OFF, 0x06,0x00},
1263 {Profile_Vibration, PROFILE_VIBRATION_ON, 0x06,0x01}, 1263 {Profile_Vibration, PROFILE_VIBRATION_ON, 0x06,0x01},
1264 {Profile_WarningTone, PROFILE_WARNING_OFF, 0x07,0x00}, 1264 {Profile_WarningTone, PROFILE_WARNING_OFF, 0x07,0x00},
1265 {Profile_WarningTone, PROFILE_WARNING_ON, 0x07,0x01}, 1265 {Profile_WarningTone, PROFILE_WARNING_ON, 0x07,0x01},
1266 /* Caller groups */ 1266 /* Caller groups */
1267 {Profile_AutoAnswer, PROFILE_AUTOANSWER_OFF,0x09,0x00}, 1267 {Profile_AutoAnswer, PROFILE_AUTOANSWER_OFF,0x09,0x00},
1268 {Profile_AutoAnswer, PROFILE_AUTOANSWER_ON, 0x09,0x01}, 1268 {Profile_AutoAnswer, PROFILE_AUTOANSWER_ON, 0x09,0x01},
1269 {0x00, 0x00, 0x00,0x00} 1269 {0x00, 0x00, 0x00,0x00}
1270}; 1270};
1271 1271
1272GSM_Error NOKIA_SetIncomingSMS(GSM_StateMachine *s, bool enable) 1272GSM_Error NOKIA_SetIncomingSMS(GSM_StateMachine *s, bool enable)
1273{ 1273{
1274 s->Phone.Data.EnableIncomingSMS = enable; 1274 s->Phone.Data.EnableIncomingSMS = enable;
1275#ifdef DEBUG 1275#ifdef DEBUG
1276 if (enable) { 1276 if (enable) {
1277 smprintf(s, "Enabling incoming SMS\n"); 1277 smprintf(s, "Enabling incoming SMS\n");
1278 } else { 1278 } else {
1279 smprintf(s, "Disabling incoming SMS\n"); 1279 smprintf(s, "Disabling incoming SMS\n");
1280 } 1280 }
1281#endif 1281#endif
1282 return ERR_NONE; 1282 return ERR_NONE;
1283} 1283}
1284 1284
1285GSM_Error N71_65_ReplyUSSDInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 1285GSM_Error N71_65_ReplyUSSDInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
1286{ 1286{
1287 unsigned char buffer[2000],buffer2[4000]; 1287 unsigned char buffer[2000],buffer2[4000];
1288 1288
1289 if (s->Phone.Data.RequestID == ID_Divert) return ERR_NONE; 1289 if (s->Phone.Data.RequestID == ID_Divert) return ERR_NONE;
1290 1290
1291 memcpy(buffer,msg.Buffer+8,msg.Buffer[7]); 1291 memcpy(buffer,msg.Buffer+8,msg.Buffer[7]);
1292 buffer[msg.Buffer[7]] = 0x00; 1292 buffer[msg.Buffer[7]] = 0x00;
1293 1293
1294 smprintf(s, "USSD reply: \"%s\"\n",buffer); 1294 smprintf(s, "USSD reply: \"%s\"\n",buffer);
1295 1295
1296 if (s->Phone.Data.EnableIncomingUSSD && s->User.IncomingUSSD!=NULL) { 1296 if (s->Phone.Data.EnableIncomingUSSD && s->User.IncomingUSSD!=NULL) {
1297 EncodeUnicode(buffer2,buffer,strlen(buffer)); 1297 EncodeUnicode(buffer2,buffer,strlen(buffer));
1298 s->User.IncomingUSSD(s->CurrentConfig->Device, buffer2); 1298 s->User.IncomingUSSD(s->CurrentConfig->Device, buffer2);
1299 } 1299 }
1300 1300
1301 return ERR_NONE; 1301 return ERR_NONE;
1302} 1302}
1303 1303
1304GSM_Error NOKIA_SetIncomingUSSD(GSM_StateMachine *s, bool enable) 1304GSM_Error NOKIA_SetIncomingUSSD(GSM_StateMachine *s, bool enable)
1305{ 1305{
1306 s->Phone.Data.EnableIncomingUSSD = enable; 1306 s->Phone.Data.EnableIncomingUSSD = enable;
1307#ifdef DEBUG 1307#ifdef DEBUG
1308 if (enable) { 1308 if (enable) {
1309 smprintf(s, "Enabling incoming USSD\n"); 1309 smprintf(s, "Enabling incoming USSD\n");
1310 } else { 1310 } else {
1311 smprintf(s, "Disabling incoming USSD\n"); 1311 smprintf(s, "Disabling incoming USSD\n");
1312 } 1312 }
1313#endif 1313#endif
1314 return ERR_NONE; 1314 return ERR_NONE;
1315} 1315}
1316 1316
1317GSM_Error NOKIA_SetIncomingCall(GSM_StateMachine *s, bool enable) 1317GSM_Error NOKIA_SetIncomingCall(GSM_StateMachine *s, bool enable)
1318{ 1318{
1319 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NOCALLINFO)) return ERR_NOTSUPPORTED; 1319 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NOCALLINFO)) return ERR_NOTSUPPORTED;
1320 1320
1321 s->Phone.Data.EnableIncomingCall = enable; 1321 s->Phone.Data.EnableIncomingCall = enable;
1322#ifdef DEBUG 1322#ifdef DEBUG
1323 if (enable) { 1323 if (enable) {
1324 smprintf(s, "Enabling incoming Call\n"); 1324 smprintf(s, "Enabling incoming Call\n");
1325 } else { 1325 } else {
1326 smprintf(s, "Disabling incoming Call\n"); 1326 smprintf(s, "Disabling incoming Call\n");
1327 } 1327 }
1328#endif 1328#endif
1329 return ERR_NONE; 1329 return ERR_NONE;
1330} 1330}
1331 1331
1332GSM_Error N71_65_ReplyCallInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 1332GSM_Error N71_65_ReplyCallInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
1333{ 1333{
1334 GSM_Call call; 1334 GSM_Call call;
1335 int tmp; 1335 int tmp;
1336 unsigned char buffer[200]; 1336 unsigned char buffer[200];
1337 1337
1338 call.Status = 0; 1338 call.Status = 0;
1339 call.CallIDAvailable = true; 1339 call.CallIDAvailable = true;
1340 smprintf(s, "Call info, "); 1340 smprintf(s, "Call info, ");
1341 switch (msg.Buffer[3]) { 1341 switch (msg.Buffer[3]) {
1342 case 0x02: 1342 case 0x02:
1343 smprintf(s, "Call established, waiting for answer\n"); 1343 smprintf(s, "Call established, waiting for answer\n");
1344 call.Status = GSM_CALL_CallEstablished; 1344 call.Status = GSM_CALL_CallEstablished;
1345 break; 1345 break;
1346 case 0x03: 1346 case 0x03:
1347 smprintf(s, "Call started\n"); 1347 smprintf(s, "Call started\n");
1348 smprintf(s, "Call mode : %i\n",msg.Buffer[5]);//such interpretation is in gnokii 1348 smprintf(s, "Call mode : %i\n",msg.Buffer[5]);//such interpretation is in gnokii
1349 tmp = 6; 1349 tmp = 6;
1350 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer,buffer,false); 1350 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer,buffer,false);
1351 smprintf(s, "Number : \"%s\"\n",DecodeUnicodeString(buffer)); 1351 smprintf(s, "Number : \"%s\"\n",DecodeUnicodeString(buffer));
1352 /* FIXME: read name from frame */ 1352 /* FIXME: read name from frame */
1353 1353
1354 call.Status = GSM_CALL_CallStart; 1354 call.Status = GSM_CALL_CallStart;
1355 break; 1355 break;
1356 case 0x04: 1356 case 0x04:
1357 smprintf(s, "Remote end hang up\n"); 1357 smprintf(s, "Remote end hang up\n");
1358 smprintf(s, "Cause Type : %i\n",msg.Buffer[5]);//such interpretation is in gnokii 1358 smprintf(s, "Cause Type : %i\n",msg.Buffer[5]);//such interpretation is in gnokii
1359 smprintf(s, "CC : %i\n",msg.Buffer[6]); 1359 smprintf(s, "CC : %i\n",msg.Buffer[6]);
1360 smprintf(s, "MM(?) : %i\n",msg.Buffer[7]); 1360 smprintf(s, "MM(?) : %i\n",msg.Buffer[7]);
1361 smprintf(s, "RR(?) : %i\n",msg.Buffer[8]); 1361 smprintf(s, "RR(?) : %i\n",msg.Buffer[8]);
1362 call.Status = GSM_CALL_CallRemoteEnd; 1362 call.Status = GSM_CALL_CallRemoteEnd;
1363 call.StatusCode = msg.Buffer[6]; 1363 call.StatusCode = msg.Buffer[6];
1364 break; 1364 break;
1365 case 0x05: 1365 case 0x05:
1366 smprintf(s, "Incoming call\n"); 1366 smprintf(s, "Incoming call\n");
1367 smprintf(s, "Call mode : %i\n",msg.Buffer[5]);//such interpretation is in gnokii 1367 smprintf(s, "Call mode : %i\n",msg.Buffer[5]);//such interpretation is in gnokii
1368 tmp = 6; 1368 tmp = 6;
1369 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer,buffer,false); 1369 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer,buffer,false);
1370 smprintf(s, "Number : \"%s\"\n",DecodeUnicodeString(buffer)); 1370 smprintf(s, "Number : \"%s\"\n",DecodeUnicodeString(buffer));
1371 /* FIXME: read name from frame */ 1371 /* FIXME: read name from frame */
1372 call.Status = GSM_CALL_IncomingCall; 1372 call.Status = GSM_CALL_IncomingCall;
1373 tmp = 6; 1373 tmp = 6;
1374 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer,call.PhoneNumber,false); 1374 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer,call.PhoneNumber,false);
1375 break; 1375 break;
1376 case 0x07: 1376 case 0x07:
1377 smprintf(s, "Call answer initiated\n"); 1377 smprintf(s, "Call answer initiated\n");
1378 break; 1378 break;
1379 case 0x09: 1379 case 0x09:
1380 smprintf(s, "Call released\n"); 1380 smprintf(s, "Call released\n");
1381 call.Status = GSM_CALL_CallLocalEnd; 1381 call.Status = GSM_CALL_CallLocalEnd;
1382 break; 1382 break;
1383 case 0x0a: 1383 case 0x0a:
1384 smprintf(s, "Call is being released\n"); 1384 smprintf(s, "Call is being released\n");
1385 break; 1385 break;
1386 case 0x0b: 1386 case 0x0b:
1387 smprintf(s, "Meaning not known\n"); 1387 smprintf(s, "Meaning not known\n");
1388 call.CallIDAvailable = false; 1388 call.CallIDAvailable = false;
1389 break; 1389 break;
1390 case 0x0c: 1390 case 0x0c:
1391 smprintf(s, "Audio status\n"); 1391 smprintf(s, "Audio status\n");
1392 if (msg.Buffer[4] == 0x01) smprintf(s, "Audio enabled\n"); 1392 if (msg.Buffer[4] == 0x01) smprintf(s, "Audio enabled\n");
1393 else smprintf(s, "Audio disabled\n"); 1393 else smprintf(s, "Audio disabled\n");
1394 call.CallIDAvailable = false; 1394 call.CallIDAvailable = false;
1395 break; 1395 break;
1396 case 0x0f:
1397 case 0x10:
1398 smprintf(s, "Meaning not known\n");
1399 call.CallIDAvailable = false;
1400 break;
1396 case 0x23: 1401 case 0x23:
1397 smprintf(s, "Call held\n"); 1402 smprintf(s, "Call held\n");
1398 call.Status = GSM_CALL_CallHeld; 1403 call.Status = GSM_CALL_CallHeld;
1399 break; 1404 break;
1400 case 0x25: 1405 case 0x25:
1401 smprintf(s, "Call resumed\n"); 1406 smprintf(s, "Call resumed\n");
1402 call.Status = GSM_CALL_CallResumed; 1407 call.Status = GSM_CALL_CallResumed;
1403 break; 1408 break;
1404 case 0x27: 1409 case 0x27:
1405 smprintf(s, "Call switched\n"); 1410 smprintf(s, "Call switched\n");
1406 call.Status = GSM_CALL_CallSwitched; 1411 call.Status = GSM_CALL_CallSwitched;
1407 break; 1412 break;
1408 case 0x53: 1413 case 0x53:
1409 smprintf(s, "Outgoing call\n"); 1414 smprintf(s, "Outgoing call\n");
1410 smprintf(s, "Call mode : %i\n",msg.Buffer[5]);//such interpretation is in gnokii 1415 smprintf(s, "Call mode : %i\n",msg.Buffer[5]);//such interpretation is in gnokii
1411 tmp = 6; 1416 tmp = 6;
1412 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer,buffer,false); 1417 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer,buffer,false);
1413 smprintf(s, "Number : \"%s\"\n",DecodeUnicodeString(buffer)); 1418 smprintf(s, "Number : \"%s\"\n",DecodeUnicodeString(buffer));
1414 /* FIXME: read name from frame */ 1419 /* FIXME: read name from frame */
1415 call.Status = GSM_CALL_OutgoingCall; 1420 call.Status = GSM_CALL_OutgoingCall;
1416 tmp = 6; 1421 tmp = 6;
1417 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer,call.PhoneNumber,false); 1422 NOKIA_GetUnicodeString(s, &tmp, msg.Buffer,call.PhoneNumber,false);
1418 break; 1423 break;
1424 case 0xA6:
1425 case 0xD2:
1426 case 0xD3:
1427 smprintf(s, "Meaning not known\n");
1428 call.CallIDAvailable = false;
1429 break;
1419 } 1430 }
1420 if (call.CallIDAvailable) smprintf(s, "Call ID : %d\n",msg.Buffer[4]); 1431 if (call.CallIDAvailable) smprintf(s, "Call ID : %d\n",msg.Buffer[4]);
1421 if (s->Phone.Data.EnableIncomingCall && s->User.IncomingCall!=NULL && call.Status != 0) { 1432 if (s->Phone.Data.EnableIncomingCall && s->User.IncomingCall!=NULL && call.Status != 0) {
1422 if (call.CallIDAvailable) call.CallID = msg.Buffer[4]; 1433 if (call.CallIDAvailable) call.CallID = msg.Buffer[4];
1423 s->User.IncomingCall(s->CurrentConfig->Device, call); 1434 s->User.IncomingCall(s->CurrentConfig->Device, call);
1424 } 1435 }
1436 if (s->Phone.Data.RequestID == ID_DialVoice) {
1437 if (msg.Buffer[3] == 0x10) return ERR_NOTSUPPORTED;
1438 }
1425 if (s->Phone.Data.RequestID == ID_CancelCall) { 1439 if (s->Phone.Data.RequestID == ID_CancelCall) {
1426 if (msg.Buffer[3] == 0x09) { 1440 if (msg.Buffer[3] == 0x09) {
1427 if (s->Phone.Data.CallID == msg.Buffer[4]) return ERR_NONE; 1441 if (s->Phone.Data.CallID == msg.Buffer[4]) return ERR_NONE;
1428 /* when we canceled call and see frame about other 1442 /* when we canceled call and see frame about other
1429 * call releasing, we don't give ERR_NONE for "our" 1443 * call releasing, we don't give ERR_NONE for "our"
1430 * call release command 1444 * call release command
1431 */ 1445 */
1432 return ERR_NEEDANOTHERANSWER; 1446 return ERR_NEEDANOTHERANSWER;
1433 } 1447 }
1434 } 1448 }
1435 if (s->Phone.Data.RequestID == ID_AnswerCall) { 1449 if (s->Phone.Data.RequestID == ID_AnswerCall) {
1436 if (msg.Buffer[3] == 0x07) { 1450 if (msg.Buffer[3] == 0x07) {
1437 if (s->Phone.Data.CallID == msg.Buffer[4]) return ERR_NONE; 1451 if (s->Phone.Data.CallID == msg.Buffer[4]) return ERR_NONE;
1438 return ERR_NEEDANOTHERANSWER; 1452 return ERR_NEEDANOTHERANSWER;
1439 } 1453 }
1440 } 1454 }
1441 return ERR_NONE; 1455 return ERR_NONE;
1442} 1456}
1443 1457
1444void N71_65_GetCalendarRecurrance(GSM_StateMachine *s, unsigned char *buffer, GSM_CalendarEntry *entry) 1458void N71_65_GetCalendarRecurrance(GSM_StateMachine *s, unsigned char *buffer, GSM_CalendarEntry *entry)
1445{ 1459{
1446 int Recurrance; 1460 int Recurrance;
1447 1461
1448 Recurrance = buffer[0]*256 + buffer[1]; 1462 Recurrance = buffer[0]*256 + buffer[1];
1449 /* 8760 hours = 1 year */ 1463 /* 8760 hours = 1 year */
1450 if (Recurrance == 0xffff) Recurrance=8760; 1464 if (Recurrance == 0xffff) Recurrance=8760;
1451 if (Recurrance != 0) { 1465 if (Recurrance != 0) {
1452 smprintf(s, "Recurrance : %i hours\n",Recurrance); 1466 smprintf(s, "Recurrance : %i hours\n",Recurrance);
1453 entry->Entries[entry->EntriesNum].EntryType= CAL_RECURRANCE; 1467 entry->Entries[entry->EntriesNum].EntryType= CAL_RECURRANCE;
1454 entry->Entries[entry->EntriesNum].Number= Recurrance; 1468 entry->Entries[entry->EntriesNum].Number= Recurrance;
1455 entry->EntriesNum++; 1469 entry->EntriesNum++;
1456 } 1470 }
1457} 1471}
1458 1472
1459/* method 2 */ 1473/* method 2 */
1460GSM_Error N71_65_ReplyAddCalendar2(GSM_Protocol_Message msg, GSM_StateMachine *s) 1474GSM_Error N71_65_ReplyAddCalendar2(GSM_Protocol_Message msg, GSM_StateMachine *s)
1461{ 1475{
1462 smprintf(s, "Calendar note added\n"); 1476 smprintf(s, "Calendar note added\n");
1463 return ERR_NONE; 1477 return ERR_NONE;
1464} 1478}
1465 1479
1466/* method 2 */ 1480/* method 2 */
1467GSM_Error N71_65_AddCalendar2(GSM_StateMachine *s, GSM_CalendarEntry *Note) 1481GSM_Error N71_65_AddCalendar2(GSM_StateMachine *s, GSM_CalendarEntry *Note)
1468{ 1482{
1469 GSM_CalendarNoteTypeNoteType; 1483 GSM_CalendarNoteTypeNoteType;
1470 time_t t_time1,t_time2; 1484 time_t t_time1,t_time2;
1471 GSM_DateTime Date,date_time; 1485 GSM_DateTime Date,date_time;
1472 GSM_Error error; 1486 GSM_Error error;
1473 long diff; 1487 long diff;
1474 int Text, Time, Alarm, Phone, Recurrance, EndTime, Location, length=25; 1488 int Text, Time, Alarm, Phone, Recurrance, EndTime, Location, length=25;
1475 unsigned char req[5000] = { 1489 unsigned char req[5000] = {
1476 N6110_FRAME_HEADER, 1490 N6110_FRAME_HEADER,
1477 0x40, 1491 0x40,
1478 0x00, /* frame length - 7 */ 1492 0x00, /* frame length - 7 */
1479 0x00,0x00,0x00,0x00, 1493 0x00,0x00,0x00,0x00,
1480 0x00,0x00,0x00,0x00, /* start time saved as difference */ 1494 0x00,0x00,0x00,0x00, /* start time saved as difference */
1481 0x00,0x00,0xff,0xff, /* alarm saved as difference */ 1495 0x00,0x00,0xff,0xff, /* alarm saved as difference */
1482 0x00, /* frame length - 7 */ 1496 0x00, /* frame length - 7 */
1483 0x00, /* note type */ 1497 0x00, /* note type */
1484 0x00,0x00, /* recurrance */ 1498 0x00,0x00, /* recurrance */
1485 0x00,0x00,0x00,0x00, 1499 0x00,0x00,0x00,0x00,
1486 0x00,0x00,0x00,0x00}; /* rest depends on note type */ 1500 0x00,0x00,0x00,0x00}; /* rest depends on note type */
1487 1501
1488 NoteType = N71_65_FindCalendarType(Note->Type, s->Phone.Data.ModelInfo); 1502 NoteType = N71_65_FindCalendarType(Note->Type, s->Phone.Data.ModelInfo);
1489 1503
1490 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62) || 1504 if (IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62) ||
1491 IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL65)) { 1505 IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL65)) {
1492 switch(NoteType) { 1506 switch(NoteType) {
1493 case GSM_CAL_MEETING : req[18] = 0x01; length = 25; break; 1507 case GSM_CAL_MEETING : req[18] = 0x01; length = 25; break;
1494 case GSM_CAL_CALL : req[18] = 0x02; length = 27; break; 1508 case GSM_CAL_CALL : req[18] = 0x02; length = 27; break;
1495 case GSM_CAL_BIRTHDAY: req[18] = 0x04; length = 28; break; 1509 case GSM_CAL_BIRTHDAY: req[18] = 0x04; length = 28; break;
1496 case GSM_CAL_MEMO : req[18] = 0x08; length = 25; break; 1510 case GSM_CAL_MEMO : req[18] = 0x08; length = 25; break;
1497 default : return ERR_UNKNOWN; 1511 default : return ERR_UNKNOWN;
1498 } 1512 }
1499 } else { 1513 } else {
1500 switch(NoteType) { 1514 switch(NoteType) {
1501 case GSM_CAL_REMINDER: req[18] = 0x01; length = 25; break; 1515 case GSM_CAL_REMINDER: req[18] = 0x01; length = 25; break;
1502 case GSM_CAL_CALL : req[18] = 0x02; length = 27; break; 1516 case GSM_CAL_CALL : req[18] = 0x02; length = 27; break;
1503 case GSM_CAL_BIRTHDAY: req[18] = 0x04; length = 28; break; 1517 case GSM_CAL_BIRTHDAY: req[18] = 0x04; length = 28; break;
1504 case GSM_CAL_MEMO : req[18] = 0x08; length = 25; break; 1518 case GSM_CAL_MEMO : req[18] = 0x08; length = 25; break;
1505 default : return ERR_UNKNOWN; 1519 default : return ERR_UNKNOWN;
1506 } 1520 }
1507 } 1521 }
1508 1522
1509 GSM_CalendarFindDefaultTextTimeAlarmPhoneRecurrance(Note, &Text, &Time, &Alarm, &Phone, &Recurrance, &EndTime, &Location); 1523 GSM_CalendarFindDefaultTextTimeAlarmPhoneRecurrance(Note, &Text, &Time, &Alarm, &Phone, &Recurrance, &EndTime, &Location);
1510 1524
1511 if (Time == -1) return ERR_UNKNOWN; 1525 if (Time == -1) return ERR_UNKNOWN;
1512 if (NoteType != GSM_CAL_BIRTHDAY) { 1526 if (NoteType != GSM_CAL_BIRTHDAY) {
1513 Date.Year = 2030; Date.Month = 01; Date.Day = 01; 1527 Date.Year = 2030; Date.Month = 01; Date.Day = 01;
1514 Date.Hour = 00; Date.Minute = 00; Date.Second = 00; 1528 Date.Hour = 00; Date.Minute = 00; Date.Second = 00;
1515 } else { 1529 } else {
1516 Date.Year = 2029; Date.Month = 12; Date.Day = 31; 1530 Date.Year = 2029; Date.Month = 12; Date.Day = 31;
1517 Date.Hour = 22; Date.Minute = 59; Date.Second = 58; 1531 Date.Hour = 22; Date.Minute = 59; Date.Second = 58;
1518 } 1532 }
1519 t_time1 = Fill_Time_T(Date,8); 1533 t_time1 = Fill_Time_T(Date,8);
1520 memcpy(&Date,&Note->Entries[Time].Date,sizeof(GSM_DateTime)); 1534 memcpy(&Date,&Note->Entries[Time].Date,sizeof(GSM_DateTime));
1521 if (NoteType != GSM_CAL_BIRTHDAY) { 1535 if (NoteType != GSM_CAL_BIRTHDAY) {
1522 Date.Year -= 20; 1536 Date.Year -= 20;
1523 } else { 1537 } else {
1524 Date.Year = 1980; 1538 Date.Year = 1980;
1525 Date.Hour = 22; Date.Minute = 58; Date.Second = 58; 1539 Date.Hour = 22; Date.Minute = 58; Date.Second = 58;
1526 } 1540 }
1527 t_time2 = Fill_Time_T(Date,8); 1541 t_time2 = Fill_Time_T(Date,8);
1528 diff= t_time1-t_time2; 1542 diff= t_time1-t_time2;
1529 smprintf(s, " Difference : %li seconds\n", -diff); 1543 smprintf(s, " Difference : %li seconds\n", -diff);
1530 req[9] = (unsigned char)(-diff >> 24); 1544 req[9] = (unsigned char)(-diff >> 24);
1531 req[10] = (unsigned char)(-diff >> 16); 1545 req[10] = (unsigned char)(-diff >> 16);
1532 req[11] = (unsigned char)(-diff >> 8); 1546 req[11] = (unsigned char)(-diff >> 8);
1533 req[12] = (unsigned char)(-diff); 1547 req[12] = (unsigned char)(-diff);
1534 if (NoteType == GSM_CAL_BIRTHDAY) { 1548 if (NoteType == GSM_CAL_BIRTHDAY) {
1535 req[25] = Note->Entries[Time].Date.Year / 256; 1549 req[25] = Note->Entries[Time].Date.Year / 256;
1536 req[26] = Note->Entries[Time].Date.Year % 256; 1550 req[26] = Note->Entries[Time].Date.Year % 256;
1537 /* Recurrance = 1 year */ 1551 /* Recurrance = 1 year */
1538 req[19] = 0xff; 1552 req[19] = 0xff;
1539 req[20] = 0xff; 1553 req[20] = 0xff;
1540 } 1554 }
1541 1555
1542 if (NoteType == GSM_CAL_CALL && Phone != -1) { 1556 if (NoteType == GSM_CAL_CALL && Phone != -1) {
1543 req[25] = UnicodeLength(Note->Entries[Phone].Text); 1557 req[25] = UnicodeLength(Note->Entries[Phone].Text);
1544 CopyUnicodeString(req+length,Note->Entries[Phone].Text); 1558 CopyUnicodeString(req+length,Note->Entries[Phone].Text);
1545 length += UnicodeLength(Note->Entries[Phone].Text)*2; 1559 length += UnicodeLength(Note->Entries[Phone].Text)*2;
1546 } 1560 }
1547 1561
1548 if (Alarm != -1) { 1562 if (Alarm != -1) {
1549 if (NoteType == GSM_CAL_BIRTHDAY) { 1563 if (NoteType == GSM_CAL_BIRTHDAY) {
1550 if (Note->Entries[Alarm].EntryType == CAL_SILENT_ALARM_DATETIME) req[27] = 0x01; 1564 if (Note->Entries[Alarm].EntryType == CAL_SILENT_ALARM_DATETIME) req[27] = 0x01;
1551 error=s->Phone.Functions->GetDateTime(s,&date_time); 1565 error=s->Phone.Functions->GetDateTime(s,&date_time);
1552 switch (error) { 1566 switch (error) {
1553 case ERR_EMPTY: 1567 case ERR_EMPTY:
1554 case ERR_NOTIMPLEMENTED: 1568 case ERR_NOTIMPLEMENTED:
1555 GSM_GetCurrentDateTime(&date_time); 1569 GSM_GetCurrentDateTime(&date_time);
1556 break; 1570 break;
1557 case ERR_NONE: 1571 case ERR_NONE:
1558 break; 1572 break;
1559 default: 1573 default:
1560 return error; 1574 return error;
1561 } 1575 }
1562 Date.Year= date_time.Year; 1576 Date.Year= date_time.Year;
1563 Date.Hour = 23; 1577 Date.Hour = 23;
1564 Date.Minute = 59; 1578 Date.Minute = 59;
1565 } else { 1579 } else {
1566 Date.Year += 20; 1580 Date.Year += 20;
1567 } 1581 }
1568 t_time2 = Fill_Time_T(Date,8); 1582 t_time2 = Fill_Time_T(Date,8);
1569 t_time1 = Fill_Time_T(Note->Entries[Alarm].Date,8); 1583 t_time1 = Fill_Time_T(Note->Entries[Alarm].Date,8);
1570 diff = t_time1-t_time2; 1584 diff = t_time1-t_time2;
1571 1585
1572 /* Sometimes we have difference in minutes */ 1586 /* Sometimes we have difference in minutes */
1573 if (NoteType == GSM_CAL_MEETING) diff = diff / 60; 1587 if (NoteType == GSM_CAL_MEETING) diff = diff / 60;
1574 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL35)) { 1588 if (!IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL35)) {
1575 if (NoteType == GSM_CAL_MEMO || NoteType == GSM_CAL_CALL) { 1589 if (NoteType == GSM_CAL_MEMO || NoteType == GSM_CAL_CALL) {
1576 diff = diff / 60; 1590 diff = diff / 60;
1577 } 1591 }
1578 } 1592 }
1579 1593
1580 smprintf(s, " Difference : %li seconds or minutes\n", -diff); 1594 smprintf(s, " Difference : %li seconds or minutes\n", -diff);
1581 req[13] = (unsigned char)(-diff >> 24); 1595 req[13] = (unsigned char)(-diff >> 24);
1582 req[14] = (unsigned char)(-diff >> 16); 1596 req[14] = (unsigned char)(-diff >> 16);
1583 req[15] = (unsigned char)(-diff >> 8); 1597 req[15] = (unsigned char)(-diff >> 8);
1584 req[16] = (unsigned char)(-diff); 1598 req[16] = (unsigned char)(-diff);
1585 } 1599 }
1586 1600
1587 if (Recurrance != -1) { 1601 if (Recurrance != -1) {
1588 /* 8760 hours = 1 year */ 1602 /* 8760 hours = 1 year */
1589 if (Note->Entries[Recurrance].Number >= 8760) { 1603 if (Note->Entries[Recurrance].Number >= 8760) {
1590 req[19] = 0xff; 1604 req[19] = 0xff;
1591 req[20] = 0xff; 1605 req[20] = 0xff;
1592 } else { 1606 } else {
1593 req[19] = Note->Entries[Recurrance].Number / 256; 1607 req[19] = Note->Entries[Recurrance].Number / 256;
1594 req[20] = Note->Entries[Recurrance].Number % 256; 1608 req[20] = Note->Entries[Recurrance].Number % 256;
1595 } 1609 }
1596 } 1610 }
1597 1611
1598 if (Text != -1) { 1612 if (Text != -1) {
1599 switch (NoteType) { 1613 switch (NoteType) {
1600 case GSM_CAL_CALL: 1614 case GSM_CAL_CALL:
1601 req[26] = UnicodeLength(Note->Entries[Text].Text); 1615 req[26] = UnicodeLength(Note->Entries[Text].Text);
1602 break; 1616 break;
1603 default: 1617 default:
1604 req[length++] = UnicodeLength(Note->Entries[Text].Text); 1618 req[length++] = UnicodeLength(Note->Entries[Text].Text);
1605 if (NoteType == GSM_CAL_MEMO || NoteType == GSM_CAL_MEETING) req[length++] = 0x00; 1619 if (NoteType == GSM_CAL_MEMO || NoteType == GSM_CAL_MEETING) req[length++] = 0x00;
1606 } 1620 }
1607 CopyUnicodeString(req+length,Note->Entries[Text].Text); 1621 CopyUnicodeString(req+length,Note->Entries[Text].Text);
1608 length += UnicodeLength(Note->Entries[Text].Text)*2; 1622 length += UnicodeLength(Note->Entries[Text].Text)*2;
1609 } 1623 }
1610 1624
1611 req[length++] = 0x00; 1625 req[length++] = 0x00;
1612 req[length++] = 0x00; 1626 req[length++] = 0x00;
1613 1627
1614 req[4] = req[17] = length-7; 1628 req[4] = req[17] = length-7;
1615 1629
1616 smprintf(s, "Writing calendar note method 2\n"); 1630 smprintf(s, "Writing calendar note method 2\n");
diff --git a/gammu/emb/common/phone/obex/obexgen.c b/gammu/emb/common/phone/obex/obexgen.c
index dd14f8e..3106369 100644
--- a/gammu/emb/common/phone/obex/obexgen.c
+++ b/gammu/emb/common/phone/obex/obexgen.c
@@ -585,267 +585,268 @@ static GSM_Error OBEXGEN_GetNextFileFolder(GSM_StateMachine *s, GSM_File *File,
585 if (size != NULL) { 585 if (size != NULL) {
586 Priv->Files[Priv->FilesLocationsCurrent+pos2].ModifiedEmpty = false; 586 Priv->Files[Priv->FilesLocationsCurrent+pos2].ModifiedEmpty = false;
587 ReadVCALDateTime(size+10, &Priv->Files[Priv->FilesLocationsCurrent+pos2].Modified); 587 ReadVCALDateTime(size+10, &Priv->Files[Priv->FilesLocationsCurrent+pos2].Modified);
588 } 588 }
589 Priv->FilesLocationsUsed++; 589 Priv->FilesLocationsUsed++;
590 pos2++; 590 pos2++;
591 } 591 }
592 } 592 }
593 593
594 z = Priv->FilesLocationsCurrent; 594 z = Priv->FilesLocationsCurrent;
595 if (z != 1) { 595 if (z != 1) {
596 while (1) { 596 while (1) {
597 if (z == Priv->FilesLocationsUsed) break; 597 if (z == Priv->FilesLocationsUsed) break;
598 if (Priv->Files[z].Folder) { 598 if (Priv->Files[z].Folder) {
599 if (Priv->Files[z].Level > File->Level) { 599 if (Priv->Files[z].Level > File->Level) {
600 smprintf(s,"Changing path down\n"); 600 smprintf(s,"Changing path down\n");
601 error=OBEXGEN_ChangePath(s, File->Name, 2); 601 error=OBEXGEN_ChangePath(s, File->Name, 2);
602 if (error != ERR_NONE) return error; 602 if (error != ERR_NONE) return error;
603 } 603 }
604 break; 604 break;
605 } 605 }
606 z++; 606 z++;
607 } 607 }
608 } 608 }
609 609
610 Priv->FileLev = File->Level; 610 Priv->FileLev = File->Level;
611 free(File->Buffer); 611 free(File->Buffer);
612 } else { 612 } else {
613 File->Used = Priv->Files[Priv->FilesLocationsCurrent-1].Used; 613 File->Used = Priv->Files[Priv->FilesLocationsCurrent-1].Used;
614 File->ModifiedEmpty = Priv->Files[Priv->FilesLocationsCurrent-1].ModifiedEmpty; 614 File->ModifiedEmpty = Priv->Files[Priv->FilesLocationsCurrent-1].ModifiedEmpty;
615 if (!File->ModifiedEmpty) { 615 if (!File->ModifiedEmpty) {
616 memcpy(&File->Modified,&Priv->Files[Priv->FilesLocationsCurrent-1].Modified,sizeof(GSM_DateTime)); 616 memcpy(&File->Modified,&Priv->Files[Priv->FilesLocationsCurrent-1].Modified,sizeof(GSM_DateTime));
617 } 617 }
618 File->ReadOnly = false; 618 File->ReadOnly = false;
619 File->Protected = false; 619 File->Protected = false;
620 File->Hidden = false; 620 File->Hidden = false;
621 File->System = false; 621 File->System = false;
622 622
623 } 623 }
624 return ERR_NONE; 624 return ERR_NONE;
625 } 625 }
626} 626}
627 627
628static GSM_Error OBEXGEN_DeleteFile(GSM_StateMachine *s, unsigned char *ID) 628static GSM_Error OBEXGEN_DeleteFile(GSM_StateMachine *s, unsigned char *ID)
629{ 629{
630 GSM_Error error; 630 GSM_Error error;
631 unsigned int Current = 0, Pos; 631 unsigned int Current = 0, Pos;
632 unsigned char req[200],req2[200]; 632 unsigned char req[200],req2[200];
633 633
634 if (!strcmp(s->CurrentConfig->Model,"seobex")) return ERR_NOTSUPPORTED; 634 if (!strcmp(s->CurrentConfig->Model,"seobex")) return ERR_NOTSUPPORTED;
635 635
636 error = OBEXGEN_Connect(s,OBEX_BrowsingFolders); 636 error = OBEXGEN_Connect(s,OBEX_BrowsingFolders);
637 if (error != ERR_NONE) return error; 637 if (error != ERR_NONE) return error;
638 638
639 smprintf(s,"Changing to root\n"); 639 smprintf(s,"Changing to root\n");
640 error = OBEXGEN_ChangePath(s, NULL, 2); 640 error = OBEXGEN_ChangePath(s, NULL, 2);
641 if (error != ERR_NONE) return error; 641 if (error != ERR_NONE) return error;
642 642
643 Pos = 0; 643 Pos = 0;
644 do { 644 do {
645 OBEXGEN_FindNextDir(ID, &Pos, req2); 645 OBEXGEN_FindNextDir(ID, &Pos, req2);
646 smprintf(s,"%s %i %i\n",DecodeUnicodeString(req2),Pos,strlen(ID)); 646 smprintf(s,"%s %i %i\n",DecodeUnicodeString(req2),Pos,strlen(ID));
647 if (Pos == strlen(ID)) break; 647 if (Pos == strlen(ID)) break;
648 smprintf(s,"Changing path down\n"); 648 smprintf(s,"Changing path down\n");
649 error=OBEXGEN_ChangePath(s, req2, 2); 649 error=OBEXGEN_ChangePath(s, req2, 2);
650 if (error != ERR_NONE) return error; 650 if (error != ERR_NONE) return error;
651 } while (1); 651 } while (1);
652 652
653 /* Name block */ 653 /* Name block */
654 OBEXAddBlock(req, &Current, 0x01, req2, UnicodeLength(req2)*2+2); 654 OBEXAddBlock(req, &Current, 0x01, req2, UnicodeLength(req2)*2+2);
655 655
656 /* connection ID block */ 656 /* connection ID block */
657 req[Current++] = 0xCB; // ID 657 req[Current++] = 0xCB; // ID
658 req[Current++] = 0x00; req[Current++] = 0x00; 658 req[Current++] = 0x00; req[Current++] = 0x00;
659 req[Current++] = 0x00; req[Current++] = 0x01; 659 req[Current++] = 0x00; req[Current++] = 0x01;
660 660
661 return GSM_WaitFor (s, req, Current, 0x82, 4, ID_AddFile); 661 return GSM_WaitFor (s, req, Current, 0x82, 4, ID_AddFile);
662} 662}
663 663
664static GSM_Error OBEXGEN_AddFolder(GSM_StateMachine *s, GSM_File *File) 664static GSM_Error OBEXGEN_AddFolder(GSM_StateMachine *s, GSM_File *File)
665{ 665{
666 GSM_Error error; 666 GSM_Error error;
667 unsigned char req2[200]; 667 unsigned char req2[200];
668 unsigned int Pos; 668 unsigned int Pos;
669 669
670 if (!strcmp(s->CurrentConfig->Model,"seobex")) return ERR_NOTSUPPORTED; 670 if (!strcmp(s->CurrentConfig->Model,"seobex")) return ERR_NOTSUPPORTED;
671 671
672 error = OBEXGEN_Connect(s,OBEX_BrowsingFolders); 672 error = OBEXGEN_Connect(s,OBEX_BrowsingFolders);
673 if (error != ERR_NONE) return error; 673 if (error != ERR_NONE) return error;
674 674
675 smprintf(s,"Changing to root\n"); 675 smprintf(s,"Changing to root\n");
676 error = OBEXGEN_ChangePath(s, NULL, 2); 676 error = OBEXGEN_ChangePath(s, NULL, 2);
677 if (error != ERR_NONE) return error; 677 if (error != ERR_NONE) return error;
678 678
679 Pos = 0; 679 Pos = 0;
680 do { 680 do {
681 OBEXGEN_FindNextDir(File->ID_FullName, &Pos, req2); 681 OBEXGEN_FindNextDir(File->ID_FullName, &Pos, req2);
682 smprintf(s,"%s %i %i\n",DecodeUnicodeString(req2),Pos,strlen(File->ID_FullName)); 682 smprintf(s,"%s %i %i\n",DecodeUnicodeString(req2),Pos,strlen(File->ID_FullName));
683 smprintf(s,"Changing path down\n"); 683 smprintf(s,"Changing path down\n");
684 error=OBEXGEN_ChangePath(s, req2, 2); 684 error=OBEXGEN_ChangePath(s, req2, 2);
685 if (error != ERR_NONE) return error; 685 if (error != ERR_NONE) return error;
686 if (Pos == strlen(File->ID_FullName)) break; 686 if (Pos == strlen(File->ID_FullName)) break;
687 } while (1); 687 } while (1);
688 688
689 smprintf(s,"Adding directory\n"); 689 smprintf(s,"Adding directory\n");
690 return OBEXGEN_ChangePath(s, File->Name, 0); 690 return OBEXGEN_ChangePath(s, File->Name, 0);
691} 691}
692 692
693GSM_Reply_Function OBEXGENReplyFunctions[] = { 693GSM_Reply_Function OBEXGENReplyFunctions[] = {
694 /* CONTINUE block */ 694 /* CONTINUE block */
695 {OBEXGEN_ReplyAddFilePart, "\x90",0x00,0x00,ID_AddFile }, 695 {OBEXGEN_ReplyAddFilePart, "\x90",0x00,0x00,ID_AddFile },
696 {OBEXGEN_ReplyGetFilePart, "\x90",0x00,0x00,ID_GetFile }, 696 {OBEXGEN_ReplyGetFilePart, "\x90",0x00,0x00,ID_GetFile },
697 {OBEXGEN_ReplyGetFileInfo, "\x90",0x00,0x00,ID_GetFileInfo }, 697 {OBEXGEN_ReplyGetFileInfo, "\x90",0x00,0x00,ID_GetFileInfo },
698 698
699 /* OK block */ 699 /* OK block */
700 {OBEXGEN_ReplyChangePath, "\xA0",0x00,0x00,ID_SetPath }, 700 {OBEXGEN_ReplyChangePath, "\xA0",0x00,0x00,ID_SetPath },
701 {OBEXGEN_ReplyConnect, "\xA0",0x00,0x00,ID_Initialise }, 701 {OBEXGEN_ReplyConnect, "\xA0",0x00,0x00,ID_Initialise },
702 {OBEXGEN_ReplyAddFilePart, "\xA0",0x00,0x00,ID_AddFile }, 702 {OBEXGEN_ReplyAddFilePart, "\xA0",0x00,0x00,ID_AddFile },
703 {OBEXGEN_ReplyGetFilePart, "\xA0",0x00,0x00,ID_GetFile }, 703 {OBEXGEN_ReplyGetFilePart, "\xA0",0x00,0x00,ID_GetFile },
704 {OBEXGEN_ReplyGetFileInfo, "\xA0",0x00,0x00,ID_GetFileInfo }, 704 {OBEXGEN_ReplyGetFileInfo, "\xA0",0x00,0x00,ID_GetFileInfo },
705 705
706 /* FOLDER CREATED block */ 706 /* FOLDER CREATED block */
707 {OBEXGEN_ReplyChangePath, "\xA1",0x00,0x00,ID_SetPath }, 707 {OBEXGEN_ReplyChangePath, "\xA1",0x00,0x00,ID_SetPath },
708 708
709 /* NOT UNDERSTAND block */ 709 /* NOT UNDERSTAND block */
710 {OBEXGEN_ReplyAddFilePart, "\xC0",0x00,0x00,ID_AddFile }, 710 {OBEXGEN_ReplyAddFilePart, "\xC0",0x00,0x00,ID_AddFile },
711 711
712 /* FORBIDDEN block */ 712 /* FORBIDDEN block */
713 {OBEXGEN_ReplyChangePath, "\xC3",0x00,0x00,ID_SetPath }, 713 {OBEXGEN_ReplyChangePath, "\xC3",0x00,0x00,ID_SetPath },
714 {OBEXGEN_ReplyGetFilePart, "\xC3",0x00,0x00,ID_GetFile }, 714 {OBEXGEN_ReplyGetFilePart, "\xC3",0x00,0x00,ID_GetFile },
715 715
716 /* NOT FOUND block */ 716 /* NOT FOUND block */
717 {OBEXGEN_ReplyGetFilePart, "\xC4",0x00,0x00,ID_GetFile }, 717 {OBEXGEN_ReplyGetFilePart, "\xC4",0x00,0x00,ID_GetFile },
718 718
719 {NULL, "\x00",0x00,0x00,ID_None } 719 {NULL, "\x00",0x00,0x00,ID_None }
720}; 720};
721 721
722GSM_Phone_Functions OBEXGENPhone = { 722GSM_Phone_Functions OBEXGENPhone = {
723 "obex|seobex", 723 "obex|seobex",
724 OBEXGENReplyFunctions, 724 OBEXGENReplyFunctions,
725 OBEXGEN_Initialise, 725 OBEXGEN_Initialise,
726 NONEFUNCTION, /* Terminate */ 726 NONEFUNCTION, /* Terminate */
727 GSM_DispatchMessage, 727 GSM_DispatchMessage,
728 NOTIMPLEMENTED, /* ShowStartInfo */ 728 NOTIMPLEMENTED, /* ShowStartInfo */
729 NONEFUNCTION, /* GetManufacturer */ 729 NONEFUNCTION, /* GetManufacturer */
730 NONEFUNCTION, /* GetModel */ 730 NONEFUNCTION, /* GetModel */
731 NONEFUNCTION, /* GetFirmware */ 731 NONEFUNCTION, /* GetFirmware */
732 NOTIMPLEMENTED, /* GetIMEI */ 732 NOTIMPLEMENTED, /* GetIMEI */
733 NOTIMPLEMENTED, /* GetOriginalIMEI */ 733 NOTIMPLEMENTED, /* GetOriginalIMEI */
734 NOTIMPLEMENTED, /* GetManufactureMonth*/ 734 NOTIMPLEMENTED, /* GetManufactureMonth*/
735 NOTIMPLEMENTED, /* GetProductCode */ 735 NOTIMPLEMENTED, /* GetProductCode */
736 NOTIMPLEMENTED, /* GetHardware */ 736 NOTIMPLEMENTED, /* GetHardware */
737 NOTIMPLEMENTED, /* GetPPM */ 737 NOTIMPLEMENTED, /* GetPPM */
738 NOTIMPLEMENTED, /* GetSIMIMSI */ 738 NOTIMPLEMENTED, /* GetSIMIMSI */
739 NOTIMPLEMENTED, /* GetDateTime */ 739 NOTIMPLEMENTED, /* GetDateTime */
740 NOTIMPLEMENTED, /* SetDateTime */ 740 NOTIMPLEMENTED, /* SetDateTime */
741 NOTIMPLEMENTED, /* GetAlarm */ 741 NOTIMPLEMENTED, /* GetAlarm */
742 NOTIMPLEMENTED, /* SetAlarm */ 742 NOTIMPLEMENTED, /* SetAlarm */
743 NOTSUPPORTED, /* GetLocale */ 743 NOTSUPPORTED, /* GetLocale */
744 NOTSUPPORTED, /* SetLocale */ 744 NOTSUPPORTED, /* SetLocale */
745 NOTIMPLEMENTED, /* PressKey */ 745 NOTIMPLEMENTED, /* PressKey */
746 NOTIMPLEMENTED, /* Reset */ 746 NOTIMPLEMENTED, /* Reset */
747 NOTIMPLEMENTED, /* ResetPhoneSettings*/ 747 NOTIMPLEMENTED, /* ResetPhoneSettings*/
748 NOTIMPLEMENTED, /* EnterSecurityCode*/ 748 NOTIMPLEMENTED, /* EnterSecurityCode*/
749 NOTIMPLEMENTED, /* GetSecurityStatus*/ 749 NOTIMPLEMENTED, /* GetSecurityStatus*/
750 NOTIMPLEMENTED, /* GetDisplayStatus*/ 750 NOTIMPLEMENTED, /* GetDisplayStatus*/
751 NOTIMPLEMENTED, /* SetAutoNetworkLogin*/ 751 NOTIMPLEMENTED, /* SetAutoNetworkLogin*/
752 NOTIMPLEMENTED, /* GetBatteryCharge*/ 752 NOTIMPLEMENTED, /* GetBatteryCharge*/
753 NOTIMPLEMENTED, /* GetSignalQuality*/ 753 NOTIMPLEMENTED, /* GetSignalQuality*/
754 NOTIMPLEMENTED, /* GetNetworkInfo */ 754 NOTIMPLEMENTED, /* GetNetworkInfo */
755 NOTIMPLEMENTED, /* GetCategory */ 755 NOTIMPLEMENTED, /* GetCategory */
756 NOTSUPPORTED, /* AddCategory */ 756 NOTSUPPORTED, /* AddCategory */
757 NOTIMPLEMENTED, /* GetCategoryStatus */ 757 NOTIMPLEMENTED, /* GetCategoryStatus */
758 NOTIMPLEMENTED, /* GetMemoryStatus */ 758 NOTIMPLEMENTED, /* GetMemoryStatus */
759 NOTIMPLEMENTED, /* GetMemory */ 759 NOTIMPLEMENTED, /* GetMemory */
760 NOTIMPLEMENTED, /* GetNextMemory */ 760 NOTIMPLEMENTED, /* GetNextMemory */
761 NOTIMPLEMENTED, /* SetMemory */ 761 NOTIMPLEMENTED, /* SetMemory */
762 NOTIMPLEMENTED, /* AddMemory */ 762 NOTIMPLEMENTED, /* AddMemory */
763 NOTIMPLEMENTED, /* DeleteMemory */ 763 NOTIMPLEMENTED, /* DeleteMemory */
764 NOTIMPLEMENTED, /* DeleteAllMemory */ 764 NOTIMPLEMENTED, /* DeleteAllMemory */
765 NOTIMPLEMENTED, /* GetSpeedDial */ 765 NOTIMPLEMENTED, /* GetSpeedDial */
766 NOTIMPLEMENTED, /* SetSpeedDial */ 766 NOTIMPLEMENTED, /* SetSpeedDial */
767 NOTIMPLEMENTED, /* GetSMSC */ 767 NOTIMPLEMENTED, /* GetSMSC */
768 NOTIMPLEMENTED, /* SetSMSC */ 768 NOTIMPLEMENTED, /* SetSMSC */
769 NOTIMPLEMENTED, /* GetSMSStatus */ 769 NOTIMPLEMENTED, /* GetSMSStatus */
770 NOTIMPLEMENTED, /* GetSMS */ 770 NOTIMPLEMENTED, /* GetSMS */
771 NOTIMPLEMENTED, /* GetNextSMS */ 771 NOTIMPLEMENTED, /* GetNextSMS */
772 NOTIMPLEMENTED, /* SetSMS */ 772 NOTIMPLEMENTED, /* SetSMS */
773 NOTIMPLEMENTED, /* AddSMS */ 773 NOTIMPLEMENTED, /* AddSMS */
774 NOTIMPLEMENTED, /* DeleteSMS */ 774 NOTIMPLEMENTED, /* DeleteSMS */
775 NOTIMPLEMENTED, /* SendSMSMessage */ 775 NOTIMPLEMENTED, /* SendSMSMessage */
776 NOTSUPPORTED, /* SendSavedSMS */ 776 NOTSUPPORTED, /* SendSavedSMS */
777 NOTSUPPORTED, /* SetFastSMSSending*/
777 NOTIMPLEMENTED, /* SetIncomingSMS */ 778 NOTIMPLEMENTED, /* SetIncomingSMS */
778 NOTIMPLEMENTED, /* SetIncomingCB */ 779 NOTIMPLEMENTED, /* SetIncomingCB */
779 NOTIMPLEMENTED, /* GetSMSFolders */ 780 NOTIMPLEMENTED, /* GetSMSFolders */
780 NOTIMPLEMENTED, /* AddSMSFolder */ 781 NOTIMPLEMENTED, /* AddSMSFolder */
781 NOTIMPLEMENTED, /* DeleteSMSFolder */ 782 NOTIMPLEMENTED, /* DeleteSMSFolder */
782 NOTIMPLEMENTED, /* DialVoice */ 783 NOTIMPLEMENTED, /* DialVoice */
783 NOTIMPLEMENTED, /* AnswerCall */ 784 NOTIMPLEMENTED, /* AnswerCall */
784 NOTIMPLEMENTED, /* CancelCall */ 785 NOTIMPLEMENTED, /* CancelCall */
785 NOTIMPLEMENTED, /* HoldCall */ 786 NOTIMPLEMENTED, /* HoldCall */
786 NOTIMPLEMENTED, /* UnholdCall */ 787 NOTIMPLEMENTED, /* UnholdCall */
787 NOTIMPLEMENTED, /* ConferenceCall */ 788 NOTIMPLEMENTED, /* ConferenceCall */
788 NOTIMPLEMENTED, /* SplitCall */ 789 NOTIMPLEMENTED, /* SplitCall */
789 NOTIMPLEMENTED, /* TransferCall */ 790 NOTIMPLEMENTED, /* TransferCall */
790 NOTIMPLEMENTED, /* SwitchCall */ 791 NOTIMPLEMENTED, /* SwitchCall */
791 NOTIMPLEMENTED, /* GetCallDivert */ 792 NOTIMPLEMENTED, /* GetCallDivert */
792 NOTIMPLEMENTED, /* SetCallDivert */ 793 NOTIMPLEMENTED, /* SetCallDivert */
793 NOTIMPLEMENTED, /* CancelAllDiverts*/ 794 NOTIMPLEMENTED, /* CancelAllDiverts*/
794 NOTIMPLEMENTED, /* SetIncomingCall */ 795 NOTIMPLEMENTED, /* SetIncomingCall */
795 NOTIMPLEMENTED, /* SetIncomingUSSD */ 796 NOTIMPLEMENTED, /* SetIncomingUSSD */
796 NOTIMPLEMENTED, /* SendDTMF */ 797 NOTIMPLEMENTED, /* SendDTMF */
797 NOTIMPLEMENTED, /* GetRingtone */ 798 NOTIMPLEMENTED, /* GetRingtone */
798 NOTIMPLEMENTED, /* SetRingtone */ 799 NOTIMPLEMENTED, /* SetRingtone */
799 NOTIMPLEMENTED, /* GetRingtonesInfo*/ 800 NOTIMPLEMENTED, /* GetRingtonesInfo*/
800 NOTIMPLEMENTED, /* DeleteUserRingtones*/ 801 NOTIMPLEMENTED, /* DeleteUserRingtones*/
801 NOTIMPLEMENTED, /* PlayTone */ 802 NOTIMPLEMENTED, /* PlayTone */
802 NOTIMPLEMENTED, /* GetWAPBookmark */ 803 NOTIMPLEMENTED, /* GetWAPBookmark */
803 NOTIMPLEMENTED, /* SetWAPBookmark */ 804 NOTIMPLEMENTED, /* SetWAPBookmark */
804 NOTIMPLEMENTED, /* DeleteWAPBookmark */ 805 NOTIMPLEMENTED, /* DeleteWAPBookmark */
805 NOTIMPLEMENTED, /* GetWAPSettings */ 806 NOTIMPLEMENTED, /* GetWAPSettings */
806 NOTIMPLEMENTED, /* SetWAPSettings */ 807 NOTIMPLEMENTED, /* SetWAPSettings */
807 NOTIMPLEMENTED, /* GetMMSSettings */ 808 NOTIMPLEMENTED, /* GetMMSSettings */
808 NOTIMPLEMENTED, /* SetMMSSettings */ 809 NOTIMPLEMENTED, /* SetMMSSettings */
809 NOTSUPPORTED, /* GetSyncMLSettings*/ 810 NOTSUPPORTED, /* GetSyncMLSettings*/
810 NOTSUPPORTED, /* SetSyncMLSettings*/ 811 NOTSUPPORTED, /* SetSyncMLSettings*/
811 NOTSUPPORTED, /* GetChatSettings */ 812 NOTSUPPORTED, /* GetChatSettings */
812 NOTSUPPORTED, /* SetChatSettings */ 813 NOTSUPPORTED, /* SetChatSettings */
813 NOTIMPLEMENTED, /* GetBitmap */ 814 NOTIMPLEMENTED, /* GetBitmap */
814 NOTIMPLEMENTED, /* SetBitmap */ 815 NOTIMPLEMENTED, /* SetBitmap */
815 NOTIMPLEMENTED, /* GetToDoStatus */ 816 NOTIMPLEMENTED, /* GetToDoStatus */
816 NOTIMPLEMENTED, /* GetToDo */ 817 NOTIMPLEMENTED, /* GetToDo */
817 NOTIMPLEMENTED, /* GetNextToDo */ 818 NOTIMPLEMENTED, /* GetNextToDo */
818 NOTIMPLEMENTED, /* SetToDo */ 819 NOTIMPLEMENTED, /* SetToDo */
819 NOTIMPLEMENTED, /* AddToDo */ 820 NOTIMPLEMENTED, /* AddToDo */
820 NOTIMPLEMENTED, /* DeleteToDo */ 821 NOTIMPLEMENTED, /* DeleteToDo */
821 NOTIMPLEMENTED, /* DeleteAllToDo */ 822 NOTIMPLEMENTED, /* DeleteAllToDo */
822 NOTIMPLEMENTED, /* GetCalendarStatus*/ 823 NOTIMPLEMENTED, /* GetCalendarStatus*/
823 NOTIMPLEMENTED, /* GetCalendar */ 824 NOTIMPLEMENTED, /* GetCalendar */
824 NOTIMPLEMENTED, /* GetNextCalendar */ 825 NOTIMPLEMENTED, /* GetNextCalendar */
825 NOTIMPLEMENTED, /* SetCalendar */ 826 NOTIMPLEMENTED, /* SetCalendar */
826 NOTIMPLEMENTED, /* AddCalendar */ 827 NOTIMPLEMENTED, /* AddCalendar */
827 NOTIMPLEMENTED, /* DeleteCalendar */ 828 NOTIMPLEMENTED, /* DeleteCalendar */
828 NOTIMPLEMENTED, /* DeleteAllCalendar*/ 829 NOTIMPLEMENTED, /* DeleteAllCalendar*/
829 NOTSUPPORTED, /* GetCalendarSettings*/ 830 NOTSUPPORTED, /* GetCalendarSettings*/
830 NOTSUPPORTED, /* SetCalendarSettings*/ 831 NOTSUPPORTED, /* SetCalendarSettings*/
831 NOTSUPPORTED, /* GetNote */ 832 NOTSUPPORTED, /* GetNextNote */
832 NOTIMPLEMENTED, /* GetProfile */ 833 NOTIMPLEMENTED, /* GetProfile */
833 NOTIMPLEMENTED, /* SetProfile */ 834 NOTIMPLEMENTED, /* SetProfile */
834 NOTIMPLEMENTED, /* GetFMStation */ 835 NOTIMPLEMENTED, /* GetFMStation */
835 NOTIMPLEMENTED, /* SetFMStation */ 836 NOTIMPLEMENTED, /* SetFMStation */
836 NOTIMPLEMENTED, /* ClearFMStations */ 837 NOTIMPLEMENTED, /* ClearFMStations */
837 OBEXGEN_GetNextFileFolder, 838 OBEXGEN_GetNextFileFolder,
838 OBEXGEN_GetFilePart, 839 OBEXGEN_GetFilePart,
839 OBEXGEN_AddFilePart, 840 OBEXGEN_AddFilePart,
840 NOTIMPLEMENTED, /* GetFileSystemStatus*/ 841 NOTIMPLEMENTED, /* GetFileSystemStatus*/
841 OBEXGEN_DeleteFile, 842 OBEXGEN_DeleteFile,
842 OBEXGEN_AddFolder, 843 OBEXGEN_AddFolder,
843 NOTIMPLEMENTED, /* GetGPRSAccessPoint*/ 844 NOTIMPLEMENTED, /* GetGPRSAccessPoint*/
844 NOTIMPLEMENTED /* SetGPRSAccessPoint*/ 845 NOTIMPLEMENTED /* SetGPRSAccessPoint*/
845}; 846};
846 847
847#endif 848#endif
848 849
849/* How should editor hadle tabs in this file? Add editor commands here. 850/* How should editor hadle tabs in this file? Add editor commands here.
850 * vim: noexpandtab sw=8 ts=8 sts=8: 851 * vim: noexpandtab sw=8 ts=8 sts=8:
851 */ 852 */
diff --git a/gammu/emb/common/phone/obex/obexgen.h b/gammu/emb/common/phone/obex/obexgen.h
index 466fef5..b7033de 100644
--- a/gammu/emb/common/phone/obex/obexgen.h
+++ b/gammu/emb/common/phone/obex/obexgen.h
@@ -1,38 +1,42 @@
1/* (c) 2003 by Marcin Wiacek */ 1/* (c) 2003 by Marcin Wiacek */
2 2
3#ifndef obexgen_h 3#ifndef obexgen_h
4#define obexgen_h 4#define obexgen_h
5 5
6#include "../../gsmcomon.h" 6#include "../../gsmcomon.h"
7#include "../../gsmstate.h" 7#include "../../gsmstate.h"
8#include "../../service/gsmmisc.h" 8#include "../../service/gsmmisc.h"
9#include "../../service/sms/gsmsms.h" 9#include "../../service/sms/gsmsms.h"
10 10
11#ifndef GSM_USED_IRDAOBEX 11#ifndef GSM_USED_IRDAOBEX
12# define GSM_USED_IRDAOBEX 12# define GSM_USED_IRDAOBEX
13#endif 13#endif
14#ifndef GSM_USED_BLUEOBEX 14#ifndef GSM_USED_BLUEOBEX
15# define GSM_USED_BLUEOBEX 15# define GSM_USED_BLUEOBEX
16#endif 16#endif
17 17
18typedef enum { 18typedef enum {
19 OBEX_None = 1, 19 OBEX_None = 1,
20 OBEX_BrowsingFolders 20 OBEX_BrowsingFolders
21} OBEX_Service; 21} OBEX_Service;
22 22
23typedef struct { 23typedef struct {
24 int FileLev; 24 int FileLev;
25 int FilesLocationsUsed; 25 int FilesLocationsUsed;
26 int FilesLocationsCurrent; 26 int FilesLocationsCurrent;
27 GSM_File Files[500]; 27 GSM_File Files[500];
28 bool FileLastPart; 28 bool FileLastPart;
29 29
30 int FrameSize; 30 int FrameSize;
31 OBEX_Service Service; 31 OBEX_Service Service;
32} GSM_Phone_OBEXGENData; 32} GSM_Phone_OBEXGENData;
33 33
34 GSM_Error OBEXGEN_GetFilePart(GSM_StateMachine *s, GSM_File *File);
35 GSM_Error OBEXGEN_AddFilePart(GSM_StateMachine *s, GSM_File *File, int *Pos);
36 GSM_Error OBEXGEN_Disconnect(GSM_StateMachine *s);
37
34#endif 38#endif
35 39
36/* How should editor hadle tabs in this file? Add editor commands here. 40/* How should editor hadle tabs in this file? Add editor commands here.
37 * vim: noexpandtab sw=8 ts=8 sts=8: 41 * vim: noexpandtab sw=8 ts=8 sts=8:
38 */ 42 */
diff --git a/gammu/emb/common/phone/symbian/mroutgen.c b/gammu/emb/common/phone/symbian/mroutgen.c
index 2c339be..a7382cf 100644
--- a/gammu/emb/common/phone/symbian/mroutgen.c
+++ b/gammu/emb/common/phone/symbian/mroutgen.c
@@ -1,220 +1,221 @@
1/* (c) 2003 by Marcin Wiacek */ 1/* (c) 2003 by Marcin Wiacek */
2/* EXPERIMENTAL. NOT FUNCTIONAL */ 2/* EXPERIMENTAL. NOT FUNCTIONAL */
3 3
4#include <string.h> 4#include <string.h>
5#include <time.h> 5#include <time.h>
6 6
7#include "../../gsmcomon.h" 7#include "../../gsmcomon.h"
8#include "../../gsmstate.h" 8#include "../../gsmstate.h"
9#include "../../misc/coding/coding.h" 9#include "../../misc/coding/coding.h"
10#include "../../service/gsmmisc.h" 10#include "../../service/gsmmisc.h"
11 11
12#ifdef GSM_ENABLE_MROUTERGEN 12#ifdef GSM_ENABLE_MROUTERGEN
13 13
14GSM_Error MROUTERGEN_StartModem(GSM_StateMachine *s) 14GSM_Error MROUTERGEN_StartModem(GSM_StateMachine *s)
15{ 15{
16 return ERR_NONE; 16 return ERR_NONE;
17} 17}
18 18
19GSM_Error MROUTERGEN_Initialise(GSM_StateMachine *s) 19GSM_Error MROUTERGEN_Initialise(GSM_StateMachine *s)
20{ 20{
21 21
22unsigned char req2[]={0xFF,0x03,0x80,0xFD,0x04,0x01,0x00,0x09,0x11, 22unsigned char req2[]={0xFF,0x03,0x80,0xFD,0x04,0x01,0x00,0x09,0x11,
230x05,0x00,0x01,0x03,0x77,0xBC}; 230x05,0x00,0x01,0x03,0x77,0xBC};
24 24
25unsigned char req0[]={ 25unsigned char req0[]={
260xFF,0x7D,0x23,0xC0,0x21,0x7D,0x21,0x7D,0x24,0x7D, 260xFF,0x7D,0x23,0xC0,0x21,0x7D,0x21,0x7D,0x24,0x7D,
270x20,0x7D,0x2E,0x7D,0x22,0x7D,0x26,0x7D,0x20,0x7D, 270x20,0x7D,0x2E,0x7D,0x22,0x7D,0x26,0x7D,0x20,0x7D,
280x20,0x7D,0x20,0x7D,0x20,0x7D,0x27,0x7D,0x22,0x7D, 280x20,0x7D,0x20,0x7D,0x20,0x7D,0x27,0x7D,0x22,0x7D,
290x28,0x7D,0x22,0x69,0x27, 290x28,0x7D,0x22,0x69,0x27,
300x7E, 300x7E,
31 31
320x7E, 320x7E,
330xFF,0x7D,0x23,0xC0,0x21,0x7D,0x22,0x7D,0x21,0x7D, 330xFF,0x7D,0x23,0xC0,0x21,0x7D,0x22,0x7D,0x21,0x7D,
340x20,0x7D,0x34,0x7D,0x25,0x7D,0x26,0x87,0xB9,0x7D, 340x20,0x7D,0x34,0x7D,0x25,0x7D,0x26,0x87,0xB9,0x7D,
350x28,0xCF,0x7D,0x22,0x7D,0x26,0x7D,0x20,0x7D,0x20, 350x28,0xCF,0x7D,0x22,0x7D,0x26,0x7D,0x20,0x7D,0x20,
360x7D,0x20,0x7D,0x20,0x7D,0x27,0x7D,0x22,0x7D,0x28, 360x7D,0x20,0x7D,0x20,0x7D,0x27,0x7D,0x22,0x7D,0x28,
370x7D,0x22,0x82,0xB0, 370x7D,0x22,0x82,0xB0,
380x7E, 380x7E,
39 39
400x7E, 400x7E,
410xFF,0x7D,0x23,0xC0,0x21,0x7D,0x21,0x7D,0x24,0x7D, 410xFF,0x7D,0x23,0xC0,0x21,0x7D,0x21,0x7D,0x24,0x7D,
420x20,0x7D,0x2E,0x7D,0x22,0x7D,0x26,0x7D,0x20,0x7D, 420x20,0x7D,0x2E,0x7D,0x22,0x7D,0x26,0x7D,0x20,0x7D,
430x20,0x7D,0x20,0x7D,0x20,0x7D,0x27,0x7D,0x22,0x7D, 430x20,0x7D,0x20,0x7D,0x20,0x7D,0x27,0x7D,0x22,0x7D,
440x28,0x7D,0x22,0x69,0x27, 440x28,0x7D,0x22,0x69,0x27,
450x7E, 450x7E,
46 46
470x7E, 470x7E,
480xFF,0x7D,0x23,0xC0,0x21,0x7D,0x22,0x7D,0x21,0x7D, 480xFF,0x7D,0x23,0xC0,0x21,0x7D,0x22,0x7D,0x21,0x7D,
490x20,0x7D,0x34,0x7D,0x25,0x7D,0x26,0x87,0xB9,0x7D, 490x20,0x7D,0x34,0x7D,0x25,0x7D,0x26,0x87,0xB9,0x7D,
500x28,0xCF,0x7D,0x22,0x7D,0x26,0x7D,0x20,0x7D,0x20, 500x28,0xCF,0x7D,0x22,0x7D,0x26,0x7D,0x20,0x7D,0x20,
510x7D,0x20,0x7D,0x20,0x7D,0x27,0x7D,0x22,0x7D,0x28, 510x7D,0x20,0x7D,0x20,0x7D,0x27,0x7D,0x22,0x7D,0x28,
520x7D,0x22,0x82,0xB0}; 520x7D,0x22,0x82,0xB0};
53 53
54unsigned char req[]={0x2F,0x45,0x00,0x00,0x34,0x00,0xC6, 54unsigned char req[]={0x2F,0x45,0x00,0x00,0x34,0x00,0xC6,
55 0x00,0x00,0x0A,0x0D,0x59,0xB4,0xA9,0xFE,0x01, 55 0x00,0x00,0x0A,0x0D,0x59,0xB4,0xA9,0xFE,0x01,
56 0x44,0xA9,0xFE,0x01,0x0A,0x04,0x09,0x0B,0xB8, 56 0x44,0xA9,0xFE,0x01,0x0A,0x04,0x09,0x0B,0xB8,
57 0x10,0x00,0x02,0x79,0x69,0x81,0x74,0x99,0x50, 57 0x10,0x00,0x02,0x79,0x69,0x81,0x74,0x99,0x50,
58 0x18,0x60,0x00,0x9D,0x0C,0x00,0x00,0x08,0x00, 58 0x18,0x60,0x00,0x9D,0x0C,0x00,0x00,0x08,0x00,
59 0x00,0x00,0x12,0x00,0x41,0x00,0x01,0x14,0x00, 59 0x00,0x00,0x12,0x00,0x41,0x00,0x01,0x14,0x00,
60 0x00,0xBA,0x4A}; 60 0x00,0xBA,0x4A};
61 61
62unsigned char req3[]={0x2D,0x5C,0x0D,0xEC,0x4C,0x10,0x26,0x08,0x00, 62unsigned char req3[]={0x2D,0x5C,0x0D,0xEC,0x4C,0x10,0x26,0x08,0x00,
630x00,0x00,0x12,0x00,0x15,0x00,0x01,0x08,0x00,0x00, 630x00,0x00,0x12,0x00,0x15,0x00,0x01,0x08,0x00,0x00,
640xAD,0xDE}; 640xAD,0xDE};
65smprintf(s,"writing\n"); 65smprintf(s,"writing\n");
66 GSM_WaitFor (s, req0, 164, 0x00, 200, ID_Initialise); 66 GSM_WaitFor (s, req0, 164, 0x00, 200, ID_Initialise);
67smprintf(s,"writing\n"); 67smprintf(s,"writing\n");
68 GSM_WaitFor (s, req3, 21, 0x00, 200, ID_Initialise); 68 GSM_WaitFor (s, req3, 21, 0x00, 200, ID_Initialise);
69 GSM_WaitFor (s, req, 55, 0x00, 200, ID_Initialise); 69 GSM_WaitFor (s, req, 55, 0x00, 200, ID_Initialise);
70 70
71 GSM_WaitFor (s, req2, 15, 0x00, 200, ID_Initialise); 71 GSM_WaitFor (s, req2, 15, 0x00, 200, ID_Initialise);
72 72
73 73
74 while (1) { 74 while (1) {
75 GSM_ReadDevice(s,false); 75 GSM_ReadDevice(s,false);
76 } 76 }
77 77
78 78
79 79
80 while (1) { 80 while (1) {
81 GSM_ReadDevice(s,false); 81 GSM_ReadDevice(s,false);
82 } 82 }
83 83
84 84
85return ERR_UNKNOWN; 85return ERR_UNKNOWN;
86} 86}
87 87
88static GSM_Reply_Function MROUTERGENReplyFunctions[] = { 88static GSM_Reply_Function MROUTERGENReplyFunctions[] = {
89 {NULL, "\x00",0x00,0x00,ID_None } 89 {NULL, "\x00",0x00,0x00,ID_None }
90}; 90};
91 91
92GSM_Phone_Functions MROUTERGENPhone = { 92GSM_Phone_Functions MROUTERGENPhone = {
93 "mrouter", 93 "mrouter",
94 MROUTERGENReplyFunctions, 94 MROUTERGENReplyFunctions,
95 MROUTERGEN_Initialise, 95 MROUTERGEN_Initialise,
96 NONEFUNCTION, /* Terminate */ 96 NONEFUNCTION, /* Terminate */
97 GSM_DispatchMessage, 97 GSM_DispatchMessage,
98 NOTSUPPORTED, /* ShowStartInfo */ 98 NOTSUPPORTED, /* ShowStartInfo */
99 NONEFUNCTION, /* GetManufacturer */ 99 NONEFUNCTION, /* GetManufacturer */
100 NONEFUNCTION, /* GetModel */ 100 NONEFUNCTION, /* GetModel */
101 NONEFUNCTION, /* GetFirmware */ 101 NONEFUNCTION, /* GetFirmware */
102 NOTIMPLEMENTED, /* GetIMEI */ 102 NOTIMPLEMENTED, /* GetIMEI */
103 NOTSUPPORTED, /* GetOriginalIMEI */ 103 NOTSUPPORTED, /* GetOriginalIMEI */
104 NOTSUPPORTED, /* GetManufactureMonth*/ 104 NOTSUPPORTED, /* GetManufactureMonth*/
105 NOTSUPPORTED, /* GetProductCode */ 105 NOTSUPPORTED, /* GetProductCode */
106 NOTSUPPORTED, /* GetHardware */ 106 NOTSUPPORTED, /* GetHardware */
107 NOTSUPPORTED, /* GetPPM */ 107 NOTSUPPORTED, /* GetPPM */
108 NOTSUPPORTED, /* GetSIMIMSI */ 108 NOTSUPPORTED, /* GetSIMIMSI */
109 NOTSUPPORTED, /* GetDateTime */ 109 NOTSUPPORTED, /* GetDateTime */
110 NOTSUPPORTED, /* SetDateTime */ 110 NOTSUPPORTED, /* SetDateTime */
111 NOTSUPPORTED, /* GetAlarm */ 111 NOTSUPPORTED, /* GetAlarm */
112 NOTSUPPORTED, /* SetAlarm */ 112 NOTSUPPORTED, /* SetAlarm */
113 NOTSUPPORTED, /* GetLocale */ 113 NOTSUPPORTED, /* GetLocale */
114 NOTSUPPORTED, /* SetLocale */ 114 NOTSUPPORTED, /* SetLocale */
115 NOTSUPPORTED, /* PressKey */ 115 NOTSUPPORTED, /* PressKey */
116 NOTSUPPORTED, /* Reset */ 116 NOTSUPPORTED, /* Reset */
117 NOTSUPPORTED, /* ResetPhoneSettings*/ 117 NOTSUPPORTED, /* ResetPhoneSettings*/
118 NOTSUPPORTED, /* EnterSecurityCode*/ 118 NOTSUPPORTED, /* EnterSecurityCode*/
119 NOTSUPPORTED, /* GetSecurityStatus*/ 119 NOTSUPPORTED, /* GetSecurityStatus*/
120 NOTSUPPORTED, /* GetDisplayStatus*/ 120 NOTSUPPORTED, /* GetDisplayStatus*/
121 NOTSUPPORTED, /* SetAutoNetworkLogin*/ 121 NOTSUPPORTED, /* SetAutoNetworkLogin*/
122 NOTSUPPORTED, /* GetBatteryCharge*/ 122 NOTSUPPORTED, /* GetBatteryCharge*/
123 NOTSUPPORTED, /* GetSignalQuality*/ 123 NOTSUPPORTED, /* GetSignalQuality*/
124 NOTSUPPORTED, /* GetNetworkInfo */ 124 NOTSUPPORTED, /* GetNetworkInfo */
125 NOTSUPPORTED, /* GetCategory */ 125 NOTSUPPORTED, /* GetCategory */
126 NOTSUPPORTED, /* GetCategoryStatus */ 126 NOTSUPPORTED, /* GetCategoryStatus */
127 NOTSUPPORTED, /* GetMemoryStatus */ 127 NOTSUPPORTED, /* GetMemoryStatus */
128 NOTSUPPORTED, /* GetMemory */ 128 NOTSUPPORTED, /* GetMemory */
129 NOTSUPPORTED, /* GetNextMemory */ 129 NOTSUPPORTED, /* GetNextMemory */
130 NOTSUPPORTED, /* SetMemory */ 130 NOTSUPPORTED, /* SetMemory */
131 NOTSUPPORTED, /* AddMemory */ 131 NOTSUPPORTED, /* AddMemory */
132 NOTSUPPORTED, /* DeleteMemory */ 132 NOTSUPPORTED, /* DeleteMemory */
133 NOTIMPLEMENTED, /* DeleteAllMemory */ 133 NOTIMPLEMENTED, /* DeleteAllMemory */
134 NOTSUPPORTED, /* GetSpeedDial */ 134 NOTSUPPORTED, /* GetSpeedDial */
135 NOTSUPPORTED, /* SetSpeedDial */ 135 NOTSUPPORTED, /* SetSpeedDial */
136 NOTSUPPORTED, /* GetSMSC */ 136 NOTSUPPORTED, /* GetSMSC */
137 NOTSUPPORTED, /* SetSMSC */ 137 NOTSUPPORTED, /* SetSMSC */
138 NOTSUPPORTED, /* GetSMSStatus */ 138 NOTSUPPORTED, /* GetSMSStatus */
139 NOTSUPPORTED, /* GetSMS */ 139 NOTSUPPORTED, /* GetSMS */
140 NOTSUPPORTED, /* GetNextSMS */ 140 NOTSUPPORTED, /* GetNextSMS */
141 NOTSUPPORTED, /* SetSMS */ 141 NOTSUPPORTED, /* SetSMS */
142 NOTSUPPORTED, /* AddSMS */ 142 NOTSUPPORTED, /* AddSMS */
143 NOTSUPPORTED, /* DeleteSMS */ 143 NOTSUPPORTED, /* DeleteSMS */
144 NOTSUPPORTED, /* SendSMSMessage */ 144 NOTSUPPORTED, /* SendSMSMessage */
145 NOTSUPPORTED, /* SendSavedSMS */ 145 NOTSUPPORTED, /* SendSavedSMS */
146 NOTSUPPORTED, /* SetFastSMSSending*/
146 NOTSUPPORTED, /* SetIncomingSMS */ 147 NOTSUPPORTED, /* SetIncomingSMS */
147 NOTSUPPORTED, /* SetIncomingCB */ 148 NOTSUPPORTED, /* SetIncomingCB */
148 NOTSUPPORTED, /* GetSMSFolders */ 149 NOTSUPPORTED, /* GetSMSFolders */
149 NOTSUPPORTED, /* AddSMSFolder */ 150 NOTSUPPORTED, /* AddSMSFolder */
150 NOTSUPPORTED, /* DeleteSMSFolder */ 151 NOTSUPPORTED, /* DeleteSMSFolder */
151 NOTSUPPORTED, /* DialVoice */ 152 NOTSUPPORTED, /* DialVoice */
152 NOTSUPPORTED, /* AnswerCall */ 153 NOTSUPPORTED, /* AnswerCall */
153 NOTSUPPORTED, /* CancelCall */ 154 NOTSUPPORTED, /* CancelCall */
154 NOTSUPPORTED, /* HoldCall */ 155 NOTSUPPORTED, /* HoldCall */
155 NOTSUPPORTED, /* UnholdCall */ 156 NOTSUPPORTED, /* UnholdCall */
156 NOTSUPPORTED, /* ConferenceCall */ 157 NOTSUPPORTED, /* ConferenceCall */
157 NOTSUPPORTED, /* SplitCall */ 158 NOTSUPPORTED, /* SplitCall */
158 NOTSUPPORTED, /* TransferCall */ 159 NOTSUPPORTED, /* TransferCall */
159 NOTSUPPORTED, /* SwitchCall */ 160 NOTSUPPORTED, /* SwitchCall */
160 NOTSUPPORTED, /* GetCallDivert */ 161 NOTSUPPORTED, /* GetCallDivert */
161 NOTSUPPORTED, /* SetCallDivert */ 162 NOTSUPPORTED, /* SetCallDivert */
162 NOTSUPPORTED, /* CancelAllDiverts*/ 163 NOTSUPPORTED, /* CancelAllDiverts*/
163 NOTSUPPORTED, /* SetIncomingCall */ 164 NOTSUPPORTED, /* SetIncomingCall */
164 NOTSUPPORTED, /* SetIncomingUSSD */ 165 NOTSUPPORTED, /* SetIncomingUSSD */
165 NOTSUPPORTED, /* SendDTMF */ 166 NOTSUPPORTED, /* SendDTMF */
166 NOTSUPPORTED, /* GetRingtone */ 167 NOTSUPPORTED, /* GetRingtone */
167 NOTSUPPORTED, /* SetRingtone */ 168 NOTSUPPORTED, /* SetRingtone */
168 NOTSUPPORTED, /* GetRingtonesInfo*/ 169 NOTSUPPORTED, /* GetRingtonesInfo*/
169 NOTSUPPORTED, /* DeleteUserRingtones*/ 170 NOTSUPPORTED, /* DeleteUserRingtones*/
170 NOTSUPPORTED, /* PlayTone */ 171 NOTSUPPORTED, /* PlayTone */
171 NOTSUPPORTED, /* GetWAPBookmark */ 172 NOTSUPPORTED, /* GetWAPBookmark */
172 NOTSUPPORTED, /* SetWAPBookmark */ 173 NOTSUPPORTED, /* SetWAPBookmark */
173 NOTSUPPORTED, /* DeleteWAPBookmark */ 174 NOTSUPPORTED, /* DeleteWAPBookmark */
174 NOTSUPPORTED, /* GetWAPSettings */ 175 NOTSUPPORTED, /* GetWAPSettings */
175 NOTSUPPORTED, /* SetWAPSettings */ 176 NOTSUPPORTED, /* SetWAPSettings */
176 NOTSUPPORTED, /* GetMMSSettings */ 177 NOTSUPPORTED, /* GetMMSSettings */
177 NOTSUPPORTED, /* SetMMSSettings */ 178 NOTSUPPORTED, /* SetMMSSettings */
178 NOTSUPPORTED, /* GetSyncMLSettings*/ 179 NOTSUPPORTED, /* GetSyncMLSettings*/
179 NOTSUPPORTED, /* SetSyncMLSettings*/ 180 NOTSUPPORTED, /* SetSyncMLSettings*/
180 NOTSUPPORTED, /* GetChatSettings */ 181 NOTSUPPORTED, /* GetChatSettings */
181 NOTSUPPORTED, /* SetChatSettings */ 182 NOTSUPPORTED, /* SetChatSettings */
182 NOTSUPPORTED, /* GetBitmap */ 183 NOTSUPPORTED, /* GetBitmap */
183 NOTSUPPORTED, /* SetBitmap */ 184 NOTSUPPORTED, /* SetBitmap */
184 NOTSUPPORTED, /* GetToDoStatus */ 185 NOTSUPPORTED, /* GetToDoStatus */
185 NOTSUPPORTED, /* GetToDo */ 186 NOTSUPPORTED, /* GetToDo */
186 NOTSUPPORTED, /* GetNextToDo */ 187 NOTSUPPORTED, /* GetNextToDo */
187 NOTSUPPORTED, /* SetToDo */ 188 NOTSUPPORTED, /* SetToDo */
188 NOTSUPPORTED, /* AddToDo */ 189 NOTSUPPORTED, /* AddToDo */
189 NOTSUPPORTED, /* DeleteToDo */ 190 NOTSUPPORTED, /* DeleteToDo */
190 NOTSUPPORTED, /* DeleteAllToDo */ 191 NOTSUPPORTED, /* DeleteAllToDo */
191 NOTSUPPORTED, /* GetCalendarStatus*/ 192 NOTSUPPORTED, /* GetCalendarStatus*/
192 NOTSUPPORTED, /* GetCalendar */ 193 NOTSUPPORTED, /* GetCalendar */
193 NOTSUPPORTED, /* GetNextCalendar */ 194 NOTSUPPORTED, /* GetNextCalendar */
194 NOTSUPPORTED, /* SetCalendar */ 195 NOTSUPPORTED, /* SetCalendar */
195 NOTSUPPORTED, /* AddCalendar */ 196 NOTSUPPORTED, /* AddCalendar */
196 NOTSUPPORTED, /* DeleteCalendar */ 197 NOTSUPPORTED, /* DeleteCalendar */
197 NOTSUPPORTED, /* DeleteAllCalendar*/ 198 NOTSUPPORTED, /* DeleteAllCalendar*/
198 NOTSUPPORTED, /* GetCalendarSettings*/ 199 NOTSUPPORTED, /* GetCalendarSettings*/
199 NOTSUPPORTED, /* SetCalendarSettings*/ 200 NOTSUPPORTED, /* SetCalendarSettings*/
200 NOTSUPPORTED, /* GetNote */ 201 NOTSUPPORTED, /* GetNextNote */
201 NOTSUPPORTED, /* GetProfile */ 202 NOTSUPPORTED, /* GetProfile */
202 NOTSUPPORTED, /* SetProfile */ 203 NOTSUPPORTED, /* SetProfile */
203 NOTSUPPORTED, /* GetFMStation */ 204 NOTSUPPORTED, /* GetFMStation */
204 NOTSUPPORTED, /* SetFMStation */ 205 NOTSUPPORTED, /* SetFMStation */
205 NOTSUPPORTED, /* ClearFMStations */ 206 NOTSUPPORTED, /* ClearFMStations */
206 NOTSUPPORTED, /* GetNextFileFolder*/ 207 NOTSUPPORTED, /* GetNextFileFolder*/
207 NOTSUPPORTED, /* GetFilePart */ 208 NOTSUPPORTED, /* GetFilePart */
208 NOTSUPPORTED, /* AddFilePart */ 209 NOTSUPPORTED, /* AddFilePart */
209 NOTSUPPORTED, /* GetFileSystemStatus*/ 210 NOTSUPPORTED, /* GetFileSystemStatus*/
210 NOTSUPPORTED, /* DeleteFile */ 211 NOTSUPPORTED, /* DeleteFile */
211 NOTSUPPORTED, /* AddFolder */ 212 NOTSUPPORTED, /* AddFolder */
212 NOTSUPPORTED, /* GetGPRSAccessPoint*/ 213 NOTSUPPORTED, /* GetGPRSAccessPoint*/
213 NOTSUPPORTED /* SetGPRSAccessPoint*/ 214 NOTSUPPORTED /* SetGPRSAccessPoint*/
214}; 215};
215 216
216#endif 217#endif
217 218
218/* How should editor hadle tabs in this file? Add editor commands here. 219/* How should editor hadle tabs in this file? Add editor commands here.
219 * vim: noexpandtab sw=8 ts=8 sts=8: 220 * vim: noexpandtab sw=8 ts=8 sts=8:
220 */ 221 */
diff --git a/gammu/emb/common/protocol/at/at.c b/gammu/emb/common/protocol/at/at.c
index f4a75b7..f8ddc06 100644
--- a/gammu/emb/common/protocol/at/at.c
+++ b/gammu/emb/common/protocol/at/at.c
@@ -1,229 +1,233 @@
1/* (c) 2002-2004 by Marcin Wiacek and Michal Cihar */ 1/* (c) 2002-2004 by Marcin Wiacek and Michal Cihar */
2 2
3#include "../../gsmstate.h" 3#include "../../gsmstate.h"
4 4
5#if defined(GSM_ENABLE_AT) || defined(GSM_ENABLE_BLUEAT) || defined(GSM_ENABLE_IRDAAT) 5#if defined(GSM_ENABLE_AT) || defined(GSM_ENABLE_BLUEAT) || defined(GSM_ENABLE_IRDAAT)
6 6
7#include <stdio.h> 7#include <stdio.h>
8#include <string.h> 8#include <string.h>
9 9
10#include "../../gsmcomon.h" 10#include "../../gsmcomon.h"
11#include "at.h" 11#include "at.h"
12 12
13static GSM_Error AT_WriteMessage (GSM_StateMachine *s, unsigned char *buffer, 13static GSM_Error AT_WriteMessage (GSM_StateMachine *s, unsigned char *buffer,
14 int length, unsigned char type) 14 int length, unsigned char type)
15{ 15{
16 int i,sent = 0; 16 int i,sent = 0;
17 17
18 GSM_DumpMessageLevel2(s, buffer, length, type); 18 GSM_DumpMessageLevel2(s, buffer, length, type);
19 GSM_DumpMessageLevel3(s, buffer, length, type); 19 GSM_DumpMessageLevel3(s, buffer, length, type);
20 if (s->Protocol.Data.AT.FastWrite) { 20 if (s->Protocol.Data.AT.FastWrite) {
21 while (sent != length) { 21 while (sent != length) {
22 if ((i = s->Device.Functions->WriteDevice(s,buffer + sent, length - sent)) == 0) { 22 if ((i = s->Device.Functions->WriteDevice(s,buffer + sent, length - sent)) == 0) {
23 return ERR_DEVICEWRITEERROR; 23 return ERR_DEVICEWRITEERROR;
24 } 24 }
25 sent += i; 25 sent += i;
26 } 26 }
27 } else { 27 } else {
28 for (i=0;i<length;i++) { 28 for (i=0;i<length;i++) {
29 if (s->Device.Functions->WriteDevice(s,buffer+i,1)!=1) return ERR_DEVICEWRITEERROR; 29 if (s->Device.Functions->WriteDevice(s,buffer+i,1)!=1) return ERR_DEVICEWRITEERROR;
30 /* For some phones like Siemens M20 we need to wait a little 30 /* For some phones like Siemens M20 we need to wait a little
31 * after writing each char. Possible reason: these phones 31 * after writing each char. Possible reason: these phones
32 * can't receive so fast chars or there is bug here in Gammu */ 32 * can't receive so fast chars or there is bug here in Gammu */
33 my_sleep(1); 33 my_sleep(1);
34 } 34 }
35 my_sleep(400); 35 my_sleep(400);
36 } 36 }
37 37
38 return ERR_NONE; 38 return ERR_NONE;
39} 39}
40 40
41typedef struct { 41typedef struct {
42 char*text; 42 char*text;
43 intlines; 43 intlines;
44} SpecialAnswersStruct; 44} SpecialAnswersStruct;
45 45
46static GSM_Error AT_StateMachine(GSM_StateMachine *s, unsigned char rx_char) 46static GSM_Error AT_StateMachine(GSM_StateMachine *s, unsigned char rx_char)
47{ 47{
48 GSM_Protocol_Message Msg2; 48 GSM_Protocol_Message Msg2;
49 GSM_Protocol_ATData *d = &s->Protocol.Data.AT; 49 GSM_Protocol_ATData *d = &s->Protocol.Data.AT;
50 int i; 50 int i;
51 51
52 /* These are lines with end of "normal" answers */ 52 /* These are lines with end of "normal" answers */
53 static char *StartStrings[] = { 53 static char *StartStrings[] = {
54 "OK" , "ERROR" , 54 "OK" , "ERROR" ,
55 "+CME ERROR:" , "+CMS ERROR:", 55 "+CME ERROR:" , "+CMS ERROR:",
56 56
57 "+CPIN: " ,/*A2D issue*/ 57 "+CPIN: " ,/*A2D issue*/
58 58
59 NULL}; 59 NULL};
60 60
61 /* Some info from phone can be inside "normal" answers 61 /* Some info from phone can be inside "normal" answers
62 * It starts with strings written here 62 * It starts with strings written here
63 */ 63 */
64 static SpecialAnswersStructSpecialAnswers[] = { 64 static SpecialAnswersStructSpecialAnswers[] = {
65 {"_OSIGQ:" ,1}, {"_OBS:",1}, 65 {"_OSIGQ:" ,1}, {"_OBS:",1},
66 {"^SCN:" ,1}, {"+CGREG:",1}, 66 {"^SCN:" ,1}, {"+CGREG:",1},
67 {"+CBM:" ,1}, {"+CMT:",2}, 67 {"+CBM:" ,1}, {"+CMT:",2},
68 {"+CMTI:" ,1}, {"+CDS:",2}, 68 {"+CMTI:" ,1}, {"+CDS:",2},
69 {"+CREG:",1}, 69 {"+CREG:" ,1}, {"+CUSD",1},
70 70
71 {"RING" ,1}, {"NO CARRIER",1}, 71 {"RING" ,1}, {"NO CARRIER",1},
72 {"NO ANSWER" ,1}, {"+COLP",1}, 72 {"NO ANSWER" ,1}, {"+COLP",1},
73 {"+CLIP",1}, 73 {"+CLIP",1},
74 74
75 {"SDNDCRC =" ,1},/* Samsung binary transfer end */
76
75 {NULL ,1}}; 77 {NULL ,1}};
76 78
79//printf("%c",rx_char);
80
77 /* Ignore leading CR, LF and ESC */ 81 /* Ignore leading CR, LF and ESC */
78 if (d->Msg.Length == 0) { 82 if (d->Msg.Length == 0) {
79 if (rx_char == 10 || rx_char == 13 || rx_char == 27) return ERR_NONE; 83 if (rx_char == 10 || rx_char == 13 || rx_char == 27) return ERR_NONE;
80 d->LineStart = d->Msg.Length; 84 d->LineStart = d->Msg.Length;
81 } 85 }
82 86
83 if (d->Msg.BufferUsed < d->Msg.Length + 2) { 87 if (d->Msg.BufferUsed < d->Msg.Length + 2) {
84 d->Msg.BufferUsed= d->Msg.Length + 2; 88 d->Msg.BufferUsed= d->Msg.Length + 2;
85 d->Msg.Buffer = (unsigned char *)realloc(d->Msg.Buffer,d->Msg.BufferUsed); 89 d->Msg.Buffer = (unsigned char *)realloc(d->Msg.Buffer,d->Msg.BufferUsed);
86 } 90 }
87 d->Msg.Buffer[d->Msg.Length++] = rx_char; 91 d->Msg.Buffer[d->Msg.Length++] = rx_char;
88 d->Msg.Buffer[d->Msg.Length ] = 0; 92 d->Msg.Buffer[d->Msg.Length ] = 0;
89 93
90 switch (rx_char) { 94 switch (rx_char) {
91 case 0: 95 case 0:
92 break; 96 break;
93 case 10: 97 case 10:
94 case 13: 98 case 13:
95 if (!d->wascrlf) d->LineEnd = d->Msg.Length-1; 99 if (!d->wascrlf) d->LineEnd = d->Msg.Length-1;
96 d->wascrlf = true; 100 d->wascrlf = true;
97 if (d->Msg.Length > 0 && rx_char == 10 && d->Msg.Buffer[d->Msg.Length-2]==13) { 101 if (d->Msg.Length > 0 && rx_char == 10 && d->Msg.Buffer[d->Msg.Length-2]==13) {
98 i = 0; 102 i = 0;
99 while (StartStrings[i] != NULL) { 103 while (StartStrings[i] != NULL) {
100 if (strncmp(StartStrings[i],d->Msg.Buffer+d->LineStart,strlen(StartStrings[i])) == 0) { 104 if (strncmp(StartStrings[i],d->Msg.Buffer+d->LineStart,strlen(StartStrings[i])) == 0) {
101 s->Phone.Data.RequestMsg= &d->Msg; 105 s->Phone.Data.RequestMsg= &d->Msg;
102 s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s); 106 s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s);
103 d->Msg.Length = 0; 107 d->Msg.Length = 0;
104 break; 108 break;
105 } 109 }
106 i++; 110 i++;
107 } 111 }
108 if (d->Msg.Length == 0) break; 112 if (d->Msg.Length == 0) break;
109 113
110 i = 0; 114 i = 0;
111 while (SpecialAnswers[i].text != NULL) { 115 while (SpecialAnswers[i].text != NULL) {
112 if (strncmp(SpecialAnswers[i].text,d->Msg.Buffer+d->LineStart,strlen(SpecialAnswers[i].text)) == 0) { 116 if (strncmp(SpecialAnswers[i].text,d->Msg.Buffer+d->LineStart,strlen(SpecialAnswers[i].text)) == 0) {
113 /* We need something better here */ 117 /* We need something better here */
114 if (s->Phone.Data.RequestID == ID_GetNetworkInfo && strncmp(SpecialAnswers[i].text,"+CREG:",6) == 0) { 118 if (s->Phone.Data.RequestID == ID_GetNetworkInfo && strncmp(SpecialAnswers[i].text,"+CREG:",6) == 0) {
115 i++; 119 i++;
116 continue; 120 continue;
117 } 121 }
118 d->SpecialAnswerStart = d->LineStart; 122 d->SpecialAnswerStart = d->LineStart;
119 d->SpecialAnswerLines= SpecialAnswers[i].lines; 123 d->SpecialAnswerLines= SpecialAnswers[i].lines;
120 } 124 }
121 i++; 125 i++;
122 } 126 }
123 127
124 128
125 if (d->SpecialAnswerLines == 1) { 129 if (d->SpecialAnswerLines == 1) {
126 /* This is end of special answer. We copy it and send to phone module */ 130 /* This is end of special answer. We copy it and send to phone module */
127 Msg2.Buffer = malloc(d->LineEnd - d->SpecialAnswerStart + 3); 131 Msg2.Buffer = malloc(d->LineEnd - d->SpecialAnswerStart + 3);
128 memcpy(Msg2.Buffer,d->Msg.Buffer+d->SpecialAnswerStart,d->LineEnd - d->SpecialAnswerStart + 2); 132 memcpy(Msg2.Buffer,d->Msg.Buffer+d->SpecialAnswerStart,d->LineEnd - d->SpecialAnswerStart + 2);
129 Msg2.Length = d->LineEnd - d->SpecialAnswerStart + 2; 133 Msg2.Length = d->LineEnd - d->SpecialAnswerStart + 2;
130 Msg2.Buffer[Msg2.Length] = 0; 134 Msg2.Buffer[Msg2.Length] = 0;
131 135
132 s->Phone.Data.RequestMsg= &Msg2; 136 s->Phone.Data.RequestMsg= &Msg2;
133 s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s); 137 s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s);
134 free(Msg2.Buffer); 138 free(Msg2.Buffer);
135 139
136 /* We cut special answer from main buffer */ 140 /* We cut special answer from main buffer */
137 d->Msg.Length = d->SpecialAnswerStart; 141 d->Msg.Length = d->SpecialAnswerStart;
138 if (d->Msg.Length != 0) d->Msg.Length = d->Msg.Length - 2; 142 if (d->Msg.Length != 0) d->Msg.Length = d->Msg.Length - 2;
139 143
140 /* We need to find earlier values of all variables */ 144 /* We need to find earlier values of all variables */
141 d->wascrlf = false; 145 d->wascrlf = false;
142 d->LineStart = 0; 146 d->LineStart = 0;
143 for (i=0;i<d->Msg.Length;i++) { 147 for (i=0;i<d->Msg.Length;i++) {
144 switch(d->Msg.Buffer[i]) { 148 switch(d->Msg.Buffer[i]) {
145 case 0: 149 case 0:
146 break; 150 break;
147 case 10: 151 case 10:
148 case 13: 152 case 13:
149 if (!d->wascrlf) d->LineEnd = d->Msg.Length-1; 153 if (!d->wascrlf) d->LineEnd = d->Msg.Length-1;
150 d->wascrlf = true; 154 d->wascrlf = true;
151 break; 155 break;
152 default: 156 default:
153 if (d->wascrlf) { 157 if (d->wascrlf) {
154 d->LineStart= d->Msg.Length-1; 158 d->LineStart= d->Msg.Length-1;
155 d->wascrlf = false; 159 d->wascrlf = false;
156 } 160 }
157 } 161 }
158 } 162 }
159 d->Msg.Buffer[d->Msg.Length] = 0; 163 d->Msg.Buffer[d->Msg.Length] = 0;
160 } 164 }
161 if (d->SpecialAnswerLines > 0) d->SpecialAnswerLines--; 165 if (d->SpecialAnswerLines > 0) d->SpecialAnswerLines--;
162 } 166 }
163 break; 167 break;
164 case 'T': 168 case 'T':
165 /* When CONNECT string received, we know there will not follow 169 /* When CONNECT string received, we know there will not follow
166 * anything AT related, after CONNECT can follow ppp data, alcabus 170 * anything AT related, after CONNECT can follow ppp data, alcabus
167 * data and also other things. 171 * data and also other things.
168 */ 172 */
169 if (strncmp(d->Msg.Buffer+d->LineStart, "CONNECT", 7) == 0) { 173 if (strncmp(d->Msg.Buffer+d->LineStart, "CONNECT", 7) == 0) {
170 s->Phone.Data.RequestMsg = &d->Msg; 174 s->Phone.Data.RequestMsg = &d->Msg;
171 s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s); 175 s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s);
172 d->LineStart = -1; 176 d->LineStart = -1;
173 d->Msg.Length = 0; 177 d->Msg.Length = 0;
174 break; 178 break;
175 } 179 }
176 default: 180 default:
177 if (d->wascrlf) { 181 if (d->wascrlf) {
178 d->LineStart= d->Msg.Length-1; 182 d->LineStart= d->Msg.Length-1;
179 d->wascrlf = false; 183 d->wascrlf = false;
180 } 184 }
181 if (d->EditMode) { 185 if (d->EditMode) {
182 if (strlen(d->Msg.Buffer+d->LineStart) == 2 && strncmp(d->Msg.Buffer+d->LineStart,"> ",2)==0) { 186 if (strlen(d->Msg.Buffer+d->LineStart) == 2 && strncmp(d->Msg.Buffer+d->LineStart,"> ",2)==0) {
183 s->Phone.Data.RequestMsg= &d->Msg; 187 s->Phone.Data.RequestMsg= &d->Msg;
184 s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s); 188 s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s);
185 } 189 }
186 } 190 }
187 } 191 }
188 return ERR_NONE; 192 return ERR_NONE;
189} 193}
190 194
191static GSM_Error AT_Initialise(GSM_StateMachine *s) 195static GSM_Error AT_Initialise(GSM_StateMachine *s)
192{ 196{
193 GSM_Protocol_ATData *d = &s->Protocol.Data.AT; 197 GSM_Protocol_ATData *d = &s->Protocol.Data.AT;
194 198
195 d->Msg.Buffer = NULL; 199 d->Msg.Buffer = NULL;
196 d->Msg.BufferUsed= 0; 200 d->Msg.BufferUsed= 0;
197 d->Msg.Length = 0; 201 d->Msg.Length = 0;
198 d->Msg.Type = 0; 202 d->Msg.Type = 0;
199 203
200 d->SpecialAnswerLines= 0; 204 d->SpecialAnswerLines= 0;
201 d->LineStart = -1; 205 d->LineStart = -1;
202 d->LineEnd = -1; 206 d->LineEnd = -1;
203 d->wascrlf = false; 207 d->wascrlf = false;
204 d->EditMode = false; 208 d->EditMode = false;
205 d->FastWrite = false; 209 d->FastWrite = false;
206 210
207 s->Device.Functions->DeviceSetDtrRts(s,true,true); 211 s->Device.Functions->DeviceSetDtrRts(s,true,true);
208 212
209 return s->Device.Functions->DeviceSetSpeed(s,s->Speed); 213 return s->Device.Functions->DeviceSetSpeed(s,s->Speed);
210} 214}
211 215
212static GSM_Error AT_Terminate(GSM_StateMachine *s) 216static GSM_Error AT_Terminate(GSM_StateMachine *s)
213{ 217{
214 free(s->Protocol.Data.AT.Msg.Buffer); 218 free(s->Protocol.Data.AT.Msg.Buffer);
215 return ERR_NONE; 219 return ERR_NONE;
216} 220}
217 221
218GSM_Protocol_Functions ATProtocol = { 222GSM_Protocol_Functions ATProtocol = {
219 AT_WriteMessage, 223 AT_WriteMessage,
220 AT_StateMachine, 224 AT_StateMachine,
221 AT_Initialise, 225 AT_Initialise,
222 AT_Terminate 226 AT_Terminate
223}; 227};
224 228
225#endif 229#endif
226 230
227/* How should editor hadle tabs in this file? Add editor commands here. 231/* How should editor hadle tabs in this file? Add editor commands here.
228 * vim: noexpandtab sw=8 ts=8 sts=8: 232 * vim: noexpandtab sw=8 ts=8 sts=8:
229 */ 233 */
diff --git a/gammu/emb/common/protocol/nokia/fbus2.c b/gammu/emb/common/protocol/nokia/fbus2.c
index 8b3e024..2b41f8b 100644
--- a/gammu/emb/common/protocol/nokia/fbus2.c
+++ b/gammu/emb/common/protocol/nokia/fbus2.c
@@ -1,194 +1,198 @@
1/* (c) 2002-2003 by Marcin Wiacek */ 1/* (c) 2002-2003 by Marcin Wiacek */
2/* based on some work from Gnokii and MyGnokii */ 2/* based on some work from MyGnokii (www.mwiacek.com) */
3/* Based on some work from Gnokii (www.gnokii.org)
4 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
5 * GNU GPL version 2 or later
6 */
3 7
4#include "../../gsmstate.h" 8#include "../../gsmstate.h"
5 9
6#if defined(GSM_ENABLE_FBUS2) || defined(GSM_ENABLE_FBUS2IRDA) || defined(GSM_ENABLE_FBUS2DLR3) || defined(GSM_ENABLE_FBUS2BLUE) || defined(GSM_ENABLE_BLUEFBUS2) || defined(GSM_ENABLE_FBUS2DKU5) || defined(GSM_ENABLE_FBUS2PL2303) 10#if defined(GSM_ENABLE_FBUS2) || defined(GSM_ENABLE_FBUS2IRDA) || defined(GSM_ENABLE_FBUS2DLR3) || defined(GSM_ENABLE_FBUS2BLUE) || defined(GSM_ENABLE_BLUEFBUS2) || defined(GSM_ENABLE_FBUS2DKU5) || defined(GSM_ENABLE_FBUS2PL2303)
7 11
8#include <stdio.h> 12#include <stdio.h>
9#include <string.h> 13#include <string.h>
10 14
11#include "../../gsmcomon.h" 15#include "../../gsmcomon.h"
12#include "fbus2.h" 16#include "fbus2.h"
13 17
14 static GSM_Error FBUS2_WriteFrame(GSM_StateMachine *s, 18 static GSM_Error FBUS2_WriteFrame(GSM_StateMachine *s,
15 unsigned char *MsgBuffer, 19 unsigned char *MsgBuffer,
16 int MsgLength, 20 int MsgLength,
17 unsigned char MsgType) 21 unsigned char MsgType)
18{ 22{
19 unsigned char buffer2[FBUS2_MAX_TRANSMIT_LENGTH + 10]; 23 unsigned char buffer2[FBUS2_MAX_TRANSMIT_LENGTH + 10];
20 unsigned char checksum=0; 24 unsigned char checksum=0;
21 int i, len, sent; 25 int i, len, sent;
22 26
23 buffer2[0] = FBUS2_FRAME_ID; 27 buffer2[0] = FBUS2_FRAME_ID;
24 if (s->ConnectionType==GCT_FBUS2IRDA) buffer2[0] = FBUS2_IRDA_FRAME_ID; 28 if (s->ConnectionType==GCT_FBUS2IRDA) buffer2[0] = FBUS2_IRDA_FRAME_ID;
25 29
26 buffer2[1] = FBUS2_DEVICE_PHONE; //destination 30 buffer2[1] = FBUS2_DEVICE_PHONE; //destination
27 buffer2[2] = FBUS2_DEVICE_PC; //source 31 buffer2[2] = FBUS2_DEVICE_PC; //source
28 buffer2[3]= MsgType; 32 buffer2[3]= MsgType;
29 buffer2[4]= MsgLength / 256; 33 buffer2[4]= MsgLength / 256;
30 buffer2[5]= MsgLength % 256; 34 buffer2[5]= MsgLength % 256;
31 35
32 memcpy(buffer2 + 6, MsgBuffer, MsgLength); 36 memcpy(buffer2 + 6, MsgBuffer, MsgLength);
33 len = MsgLength + 6; 37 len = MsgLength + 6;
34 38
35 /* Odd messages require additional 0x00 byte */ 39 /* Odd messages require additional 0x00 byte */
36 if (MsgLength % 2) buffer2[len++] = 0x00; 40 if (MsgLength % 2) buffer2[len++] = 0x00;
37 41
38 checksum = 0; 42 checksum = 0;
39 for (i = 0; i < len; i+=2) checksum ^= buffer2[i]; 43 for (i = 0; i < len; i+=2) checksum ^= buffer2[i];
40 buffer2[len++] = checksum; 44 buffer2[len++] = checksum;
41 45
42 checksum = 0; 46 checksum = 0;
43 for (i = 1; i < len; i+=2) checksum ^= buffer2[i]; 47 for (i = 1; i < len; i+=2) checksum ^= buffer2[i];
44 buffer2[len++] = checksum; 48 buffer2[len++] = checksum;
45 49
46 /* Sending to phone */ 50 /* Sending to phone */
47 sent=s->Device.Functions->WriteDevice(s,buffer2,len); 51 sent=s->Device.Functions->WriteDevice(s,buffer2,len);
48 if (sent!=len) return ERR_DEVICEWRITEERROR; 52 if (sent!=len) return ERR_DEVICEWRITEERROR;
49 53
50 return ERR_NONE; 54 return ERR_NONE;
51} 55}
52 56
53 static GSM_Error FBUS2_WriteMessage (GSM_StateMachine *s, 57 static GSM_Error FBUS2_WriteMessage (GSM_StateMachine *s,
54 unsigned char *MsgBuffer, 58 unsigned char *MsgBuffer,
55 int MsgLength, 59 int MsgLength,
56 unsigned char MsgType) 60 unsigned char MsgType)
57{ 61{
58 int i, nom, togo, thislength; /* number of messages, ... */ 62 int i, nom, togo, thislength; /* number of messages, ... */
59 unsigned char buffer2[FBUS2_MAX_TRANSMIT_LENGTH + 2], seqnum; 63 unsigned char buffer2[FBUS2_MAX_TRANSMIT_LENGTH + 2], seqnum;
60 GSM_Protocol_FBUS2Data*d = &s->Protocol.Data.FBUS2; 64 GSM_Protocol_FBUS2Data*d = &s->Protocol.Data.FBUS2;
61 GSM_Error error; 65 GSM_Error error;
62 66
63 GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType); 67 GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType);
64 68
65 nom = (MsgLength + FBUS2_MAX_TRANSMIT_LENGTH - 1) / FBUS2_MAX_TRANSMIT_LENGTH; 69 nom = (MsgLength + FBUS2_MAX_TRANSMIT_LENGTH - 1) / FBUS2_MAX_TRANSMIT_LENGTH;
66 togo = MsgLength; 70 togo = MsgLength;
67 71
68 for (i = 0; i < nom; i++) { 72 for (i = 0; i < nom; i++) {
69 seqnum = d->MsgSequenceNumber; 73 seqnum = d->MsgSequenceNumber;
70 if (i==0) seqnum = seqnum + 0x40; 74 if (i==0) seqnum = seqnum + 0x40;
71 d->MsgSequenceNumber = (d->MsgSequenceNumber + 1) & 0x07; 75 d->MsgSequenceNumber = (d->MsgSequenceNumber + 1) & 0x07;
72 76
73 thislength = togo; 77 thislength = togo;
74 if (togo > FBUS2_MAX_TRANSMIT_LENGTH) thislength = FBUS2_MAX_TRANSMIT_LENGTH; 78 if (togo > FBUS2_MAX_TRANSMIT_LENGTH) thislength = FBUS2_MAX_TRANSMIT_LENGTH;
75 memcpy(buffer2, MsgBuffer + (MsgLength - togo), thislength); 79 memcpy(buffer2, MsgBuffer + (MsgLength - togo), thislength);
76 buffer2[thislength]= nom - i; 80 buffer2[thislength]= nom - i;
77 buffer2[thislength + 1]= seqnum; 81 buffer2[thislength + 1]= seqnum;
78 togo = togo - thislength; 82 togo = togo - thislength;
79 83
80 GSM_DumpMessageLevel2(s, buffer2, thislength, MsgType); 84 GSM_DumpMessageLevel2(s, buffer2, thislength, MsgType);
81 85
82 error=FBUS2_WriteFrame(s, buffer2, thislength + 2, MsgType); 86 error=FBUS2_WriteFrame(s, buffer2, thislength + 2, MsgType);
83 if (error!=ERR_NONE) return error; 87 if (error!=ERR_NONE) return error;
84 } 88 }
85 89
86 return ERR_NONE; 90 return ERR_NONE;
87} 91}
88 92
89 static GSM_Error FBUS2_SendAck(GSM_StateMachine *s, 93 static GSM_Error FBUS2_SendAck(GSM_StateMachine *s,
90 unsigned char MsgType, 94 unsigned char MsgType,
91 unsigned char MsgSequence) 95 unsigned char MsgSequence)
92{ 96{
93 unsigned char buffer2[2]; 97 unsigned char buffer2[2];
94 98
95 buffer2[0] = MsgType; 99 buffer2[0] = MsgType;
96 buffer2[1] = MsgSequence; 100 buffer2[1] = MsgSequence;
97 101
98 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || 102 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL ||
99 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) { 103 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) {
100 smprintf(s,"[Sending Ack of type %02x, seq %x]\n",buffer2[0],buffer2[1]); 104 smprintf(s,"[Sending Ack of type %02x, seq %x]\n",buffer2[0],buffer2[1]);
101 } 105 }
102 106
103 /* Sending to phone */ 107 /* Sending to phone */
104 return FBUS2_WriteFrame(s, buffer2, 2, FBUS2_ACK_BYTE); 108 return FBUS2_WriteFrame(s, buffer2, 2, FBUS2_ACK_BYTE);
105} 109}
106 110
107static GSM_Error FBUS2_StateMachine(GSM_StateMachine *s, unsigned char rx_char) 111static GSM_Error FBUS2_StateMachine(GSM_StateMachine *s, unsigned char rx_char)
108{ 112{
109 GSM_Protocol_FBUS2Data *d = &s->Protocol.Data.FBUS2; 113 GSM_Protocol_FBUS2Data *d = &s->Protocol.Data.FBUS2;
110 unsigned char frm_num, seq_num; 114 unsigned char frm_num, seq_num;
111 bool correct = false; 115 bool correct = false;
112 116
113 /* XOR the byte with the earlier checksum */ 117 /* XOR the byte with the earlier checksum */
114 d->Msg.CheckSum[d->Msg.Count & 1] ^= rx_char; 118 d->Msg.CheckSum[d->Msg.Count & 1] ^= rx_char;
115 119
116 if (d->MsgRXState == RX_GetMessage) { 120 if (d->MsgRXState == RX_GetMessage) {
117 d->Msg.Buffer[d->Msg.Count] = rx_char; 121 d->Msg.Buffer[d->Msg.Count] = rx_char;
118 d->Msg.Count++; 122 d->Msg.Count++;
119 123
120 /* This is not last byte in frame */ 124 /* This is not last byte in frame */
121 if (d->Msg.Count != d->Msg.Length+(d->Msg.Length%2)+2) return ERR_NONE; 125 if (d->Msg.Count != d->Msg.Length+(d->Msg.Length%2)+2) return ERR_NONE;
122 126
123 /* Checksum is incorrect */ 127 /* Checksum is incorrect */
124 if (d->Msg.CheckSum[0] != d->Msg.CheckSum[1]) { 128 if (d->Msg.CheckSum[0] != d->Msg.CheckSum[1]) {
125 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || 129 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
126 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { 130 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) {
127 smprintf(s,"[ERROR: checksum]\n"); 131 smprintf(s,"[ERROR: checksum]\n");
128 } 132 }
129 free(d->Msg.Buffer); 133 free(d->Msg.Buffer);
130 d->Msg.Length = 0; 134 d->Msg.Length = 0;
131 d->Msg.Buffer = NULL; 135 d->Msg.Buffer = NULL;
132 136
133 d->MsgRXState = RX_Sync; 137 d->MsgRXState = RX_Sync;
134 return ERR_NONE; 138 return ERR_NONE;
135 } 139 }
136 140
137 seq_num = d->Msg.Buffer[d->Msg.Length-1]; 141 seq_num = d->Msg.Buffer[d->Msg.Length-1];
138 142
139 if (d->Msg.Type == FBUS2_ACK_BYTE) { 143 if (d->Msg.Type == FBUS2_ACK_BYTE) {
140 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || 144 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL ||
141 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) { 145 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) {
142 smprintf(s, "[Received Ack of type %02x, seq %02x]\n",d->Msg.Buffer[0],seq_num); 146 smprintf(s, "[Received Ack of type %02x, seq %02x]\n",d->Msg.Buffer[0],seq_num);
143 } 147 }
144 148
145 d->MsgRXState = RX_Sync; 149 d->MsgRXState = RX_Sync;
146 return ERR_NONE; 150 return ERR_NONE;
147 } 151 }
148 152
149 frm_num = d->Msg.Buffer[d->Msg.Length-2]; 153 frm_num = d->Msg.Buffer[d->Msg.Length-2];
150 154
151 if ((seq_num & 0x40) == 0x40) { 155 if ((seq_num & 0x40) == 0x40) {
152 d->FramesToGo = frm_num; 156 d->FramesToGo = frm_num;
153 d->MultiMsg.Length= 0; 157 d->MultiMsg.Length= 0;
154 d->MultiMsg.Type= d->Msg.Type; 158 d->MultiMsg.Type= d->Msg.Type;
155 d->MultiMsg.Destination= d->Msg.Destination; 159 d->MultiMsg.Destination= d->Msg.Destination;
156 d->MultiMsg.Source= d->Msg.Source; 160 d->MultiMsg.Source= d->Msg.Source;
157 } 161 }
158 162
159 if ((seq_num & 0x40) != 0x40 && d->FramesToGo != frm_num) { 163 if ((seq_num & 0x40) != 0x40 && d->FramesToGo != frm_num) {
160 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || 164 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
161 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { 165 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) {
162 smprintf(s, "[ERROR: Missed part of multiframe msg]\n"); 166 smprintf(s, "[ERROR: Missed part of multiframe msg]\n");
163 } 167 }
164 168
165 free(d->Msg.Buffer); 169 free(d->Msg.Buffer);
166 d->Msg.Length = 0; 170 d->Msg.Length = 0;
167 d->Msg.Buffer = NULL; 171 d->Msg.Buffer = NULL;
168 172
169 d->MsgRXState = RX_Sync; 173 d->MsgRXState = RX_Sync;
170 return ERR_NONE; 174 return ERR_NONE;
171 } 175 }
172 176
173 if ((seq_num & 0x40) != 0x40 && d->Msg.Type != d->MultiMsg.Type) { 177 if ((seq_num & 0x40) != 0x40 && d->Msg.Type != d->MultiMsg.Type) {
174 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || 178 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
175 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { 179 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) {
176 smprintf(s, "[ERROR: Multiframe msg in multiframe msg]\n"); 180 smprintf(s, "[ERROR: Multiframe msg in multiframe msg]\n");
177 } 181 }
178 182
179 free(d->Msg.Buffer); 183 free(d->Msg.Buffer);
180 d->Msg.Length = 0; 184 d->Msg.Length = 0;
181 d->Msg.Buffer = NULL; 185 d->Msg.Buffer = NULL;
182 186
183 d->MsgRXState = RX_Sync; 187 d->MsgRXState = RX_Sync;
184 return ERR_NONE; 188 return ERR_NONE;
185 } 189 }
186 190
187 if (d->MultiMsg.BufferUsed < d->MultiMsg.Length+d->Msg.Length-2) { 191 if (d->MultiMsg.BufferUsed < d->MultiMsg.Length+d->Msg.Length-2) {
188 d->MultiMsg.BufferUsed = d->MultiMsg.Length+d->Msg.Length-2; 192 d->MultiMsg.BufferUsed = d->MultiMsg.Length+d->Msg.Length-2;
189 d->MultiMsg.Buffer = (unsigned char *)realloc(d->MultiMsg.Buffer,d->MultiMsg.BufferUsed); 193 d->MultiMsg.Buffer = (unsigned char *)realloc(d->MultiMsg.Buffer,d->MultiMsg.BufferUsed);
190 } 194 }
191 memcpy(d->MultiMsg.Buffer+d->MultiMsg.Length,d->Msg.Buffer,d->Msg.Length-2); 195 memcpy(d->MultiMsg.Buffer+d->MultiMsg.Length,d->Msg.Buffer,d->Msg.Length-2);
192 d->MultiMsg.Length = d->MultiMsg.Length+d->Msg.Length-2; 196 d->MultiMsg.Length = d->MultiMsg.Length+d->Msg.Length-2;
193 197
194 free(d->Msg.Buffer); 198 free(d->Msg.Buffer);
diff --git a/gammu/emb/common/protocol/nokia/fbus2.h b/gammu/emb/common/protocol/nokia/fbus2.h
index 5dd45d7..8dbcb07 100644
--- a/gammu/emb/common/protocol/nokia/fbus2.h
+++ b/gammu/emb/common/protocol/nokia/fbus2.h
@@ -1,38 +1,42 @@
1/* (c) 2002-2003 by Marcin Wiacek */ 1/* (c) 2002-2003 by Marcin Wiacek */
2/* based on some work from Gnokii and MyGnokii */ 2/* based on some work from MyGnokii (www.mwiacek.com) */
3/* Based on some work from Gnokii (www.gnokii.org)
4 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
5 * GNU GPL version 2 or later
6 */
3 7
4#ifndef fbus2_h 8#ifndef fbus2_h
5#define fbus2_h 9#define fbus2_h
6 10
7#include "../protocol.h" 11#include "../protocol.h"
8 12
9 #define FBUS2_FRAME_ID 0x1e 13 #define FBUS2_FRAME_ID 0x1e
10 #define FBUS2_IRDA_FRAME_ID 0x1c 14 #define FBUS2_IRDA_FRAME_ID 0x1c
11 #define FBUS2_DEVICE_PHONE 0x00 /* Nokia mobile phone */ 15 #define FBUS2_DEVICE_PHONE 0x00 /* Nokia mobile phone */
12 #define FBUS2_DEVICE_PC 0x0c /* Our PC */ 16 #define FBUS2_DEVICE_PC 0x0c /* Our PC */
13 #define FBUS2_ACK_BYTE 0x7f /* Acknowledge of the received frame */ 17 #define FBUS2_ACK_BYTE 0x7f /* Acknowledge of the received frame */
14 18
15#define FBUS2_MAX_TRANSMIT_LENGTH 120 19#define FBUS2_MAX_TRANSMIT_LENGTH 120
16 20
17typedef struct { 21typedef struct {
18 int MsgSequenceNumber; 22 int MsgSequenceNumber;
19 int MsgRXState; 23 int MsgRXState;
20 int FramesToGo; 24 int FramesToGo;
21 GSM_Protocol_MessageMultiMsg; 25 GSM_Protocol_MessageMultiMsg;
22 GSM_Protocol_MessageMsg; 26 GSM_Protocol_MessageMsg;
23} GSM_Protocol_FBUS2Data; 27} GSM_Protocol_FBUS2Data;
24 28
25#ifndef GSM_USED_SERIALDEVICE 29#ifndef GSM_USED_SERIALDEVICE
26# define GSM_USED_SERIALDEVICE 30# define GSM_USED_SERIALDEVICE
27#endif 31#endif
28#if defined(GSM_ENABLE_BLUEFBUS2) 32#if defined(GSM_ENABLE_BLUEFBUS2)
29# ifndef GSM_USED_BLUETOOTHDEVICE 33# ifndef GSM_USED_BLUETOOTHDEVICE
30# define GSM_USED_BLUETOOTHDEVICE 34# define GSM_USED_BLUETOOTHDEVICE
31# endif 35# endif
32#endif 36#endif
33 37
34#endif 38#endif
35 39
36/* How should editor hadle tabs in this file? Add editor commands here. 40/* How should editor hadle tabs in this file? Add editor commands here.
37 * vim: noexpandtab sw=8 ts=8 sts=8: 41 * vim: noexpandtab sw=8 ts=8 sts=8:
38 */ 42 */
diff --git a/gammu/emb/common/protocol/nokia/mbus2.c b/gammu/emb/common/protocol/nokia/mbus2.c
index f07d6c5..8353b46 100644
--- a/gammu/emb/common/protocol/nokia/mbus2.c
+++ b/gammu/emb/common/protocol/nokia/mbus2.c
@@ -1,194 +1,194 @@
1/* (c) 2001-2003 by Marcin Wiacek */ 1/* (c) 2001-2003 by Marcin Wiacek */
2/* based on some work from MyGnokii */ 2/* based on some work from MyGnokii (www.mwiacek.com) */
3 3
4#include "../../gsmstate.h" 4#include "../../gsmstate.h"
5 5
6#ifdef GSM_ENABLE_MBUS2 6#ifdef GSM_ENABLE_MBUS2
7 7
8#include <stdio.h> 8#include <stdio.h>
9#include <string.h> 9#include <string.h>
10 10
11#include "../../gsmcomon.h" 11#include "../../gsmcomon.h"
12#include "mbus2.h" 12#include "mbus2.h"
13 13
14 static GSM_Error MBUS2_WriteMessage (GSM_StateMachine *s, 14 static GSM_Error MBUS2_WriteMessage (GSM_StateMachine *s,
15 unsigned char *MsgBuffer, 15 unsigned char *MsgBuffer,
16 int MsgLength, 16 int MsgLength,
17 unsigned char MsgType) 17 unsigned char MsgType)
18{ 18{
19 unsigned char *buffer2, checksum = 0; 19 unsigned char *buffer2, checksum = 0;
20 GSM_Protocol_MBUS2Data *d = &s->Protocol.Data.MBUS2; 20 GSM_Protocol_MBUS2Data *d = &s->Protocol.Data.MBUS2;
21 int i, sent, len; 21 int i, sent, len;
22 22
23 GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType); 23 GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType);
24 24
25 buffer2 = (unsigned char *)malloc(MsgLength + 8); 25 buffer2 = (unsigned char *)malloc(MsgLength + 8);
26 26
27 buffer2[0] = MBUS2_FRAME_ID; 27 buffer2[0] = MBUS2_FRAME_ID;
28 buffer2[1] = MBUS2_DEVICE_PHONE; // destination 28 buffer2[1] = MBUS2_DEVICE_PHONE; // destination
29 buffer2[2] = MBUS2_DEVICE_PC; // source 29 buffer2[2] = MBUS2_DEVICE_PC; // source
30 buffer2[3] = MsgType; 30 buffer2[3] = MsgType;
31 buffer2[4] = MsgLength / 256; 31 buffer2[4] = MsgLength / 256;
32 buffer2[5] = MsgLength % 256; 32 buffer2[5] = MsgLength % 256;
33 33
34 memcpy(buffer2 + 6, MsgBuffer, MsgLength); 34 memcpy(buffer2 + 6, MsgBuffer, MsgLength);
35 len = 6 + MsgLength; 35 len = 6 + MsgLength;
36 36
37 /* According to http://www.flosys.com/tdma/n5160.html some phones 37 /* According to http://www.flosys.com/tdma/n5160.html some phones
38 * can have problems with checksum equal 0x1F. Phones can recognize 38 * can have problems with checksum equal 0x1F. Phones can recognize
39 * received frame, but won't send ACK for it. When checksum is 0x1F, 39 * received frame, but won't send ACK for it. When checksum is 0x1F,
40 * we increment the sequence number 40 * we increment the sequence number
41 */ 41 */
42 do { 42 do {
43 d->MsgSequenceNumber++; 43 d->MsgSequenceNumber++;
44 44
45 buffer2[len] = d->MsgSequenceNumber; 45 buffer2[len] = d->MsgSequenceNumber;
46 46
47 /* Calculating checksum */ 47 /* Calculating checksum */
48 checksum = 0; 48 checksum = 0;
49 for (i = 0; i < len + 1; i++) checksum ^= buffer2[i]; 49 for (i = 0; i < len + 1; i++) checksum ^= buffer2[i];
50 } while (checksum == 0x1f); 50 } while (checksum == 0x1f);
51 51
52 buffer2[len++] = d->MsgSequenceNumber; 52 buffer2[len++] = d->MsgSequenceNumber;
53 buffer2[len++] = checksum; 53 buffer2[len++] = checksum;
54 54
55 GSM_DumpMessageLevel2(s, buffer2+6, MsgLength, MsgType); 55 GSM_DumpMessageLevel2(s, buffer2+6, MsgLength, MsgType);
56 56
57 /* Sending to phone */ 57 /* Sending to phone */
58 my_sleep(10); 58 my_sleep(10);
59 sent=s->Device.Functions->WriteDevice(s,buffer2,len); 59 sent=s->Device.Functions->WriteDevice(s,buffer2,len);
60 60
61 free(buffer2); 61 free(buffer2);
62 62
63 if (sent!=len) return ERR_DEVICEWRITEERROR; 63 if (sent!=len) return ERR_DEVICEWRITEERROR;
64 return ERR_NONE; 64 return ERR_NONE;
65} 65}
66 66
67 static GSM_Error MBUS2_SendAck(GSM_StateMachine *s, 67 static GSM_Error MBUS2_SendAck(GSM_StateMachine *s,
68 unsigned char type, 68 unsigned char type,
69 unsigned char sequence) 69 unsigned char sequence)
70{ 70{
71 GSM_Device_Functions *Device = s->Device.Functions; 71 GSM_Device_Functions *Device = s->Device.Functions;
72 unsigned char buffer2[6]; 72 unsigned char buffer2[6];
73 int i; 73 int i;
74 74
75 buffer2[0] = MBUS2_FRAME_ID; 75 buffer2[0] = MBUS2_FRAME_ID;
76 buffer2[1] = MBUS2_DEVICE_PHONE;//destination 76 buffer2[1] = MBUS2_DEVICE_PHONE;//destination
77 buffer2[2] = MBUS2_DEVICE_PC; //source 77 buffer2[2] = MBUS2_DEVICE_PC; //source
78 buffer2[3] = MBUS2_ACK_BYTE; 78 buffer2[3] = MBUS2_ACK_BYTE;
79 buffer2[4] = sequence; 79 buffer2[4] = sequence;
80 buffer2[5] = 0; 80 buffer2[5] = 0;
81 81
82 /* Calculating checksum */ 82 /* Calculating checksum */
83 for (i = 0; i < 5; i++) buffer2[5] ^= buffer2[i]; 83 for (i = 0; i < 5; i++) buffer2[5] ^= buffer2[i];
84 84
85 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || 85 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL ||
86 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) { 86 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) {
87 smprintf(s,"[Sending Ack of type %02x, seq: %x]\n",type,sequence); 87 smprintf(s,"[Sending Ack of type %02x, seq: %x]\n",type,sequence);
88 } 88 }
89 89
90 /* Sending to phone */ 90 /* Sending to phone */
91 my_sleep(10); 91 my_sleep(10);
92 if (Device->WriteDevice(s,buffer2,6)!=6) return ERR_DEVICEWRITEERROR; 92 if (Device->WriteDevice(s,buffer2,6)!=6) return ERR_DEVICEWRITEERROR;
93 93
94 return ERR_NONE; 94 return ERR_NONE;
95} 95}
96 96
97static GSM_Error MBUS2_StateMachine(GSM_StateMachine *s, unsigned char rx_char) 97static GSM_Error MBUS2_StateMachine(GSM_StateMachine *s, unsigned char rx_char)
98{ 98{
99 GSM_Phone_Functions *Phone= s->Phone.Functions; 99 GSM_Phone_Functions *Phone= s->Phone.Functions;
100 GSM_Protocol_MBUS2Data *d= &s->Protocol.Data.MBUS2; 100 GSM_Protocol_MBUS2Data *d= &s->Protocol.Data.MBUS2;
101 101
102 d->Msg.CheckSum[0] = d->Msg.CheckSum[1]; 102 d->Msg.CheckSum[0] = d->Msg.CheckSum[1];
103 d->Msg.CheckSum[1] ^= rx_char; 103 d->Msg.CheckSum[1] ^= rx_char;
104 104
105 if (d->MsgRXState == RX_GetMessage) { 105 if (d->MsgRXState == RX_GetMessage) {
106 d->Msg.Buffer[d->Msg.Count] = rx_char; 106 d->Msg.Buffer[d->Msg.Count] = rx_char;
107 d->Msg.Count++; 107 d->Msg.Count++;
108 108
109 /* This is not last byte in frame */ 109 /* This is not last byte in frame */
110 if (d->Msg.Count != d->Msg.Length+2) return ERR_NONE; 110 if (d->Msg.Count != d->Msg.Length+2) return ERR_NONE;
111 111
112 /* Checksum is incorrect */ 112 /* Checksum is incorrect */
113 if (d->Msg.CheckSum[0] != rx_char) { 113 if (d->Msg.CheckSum[0] != rx_char) {
114 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || 114 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
115 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { 115 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) {
116 smprintf(s,"[ERROR: checksum]\n"); 116 smprintf(s,"[ERROR: checksum]\n");
117 } 117 }
118 118
119 d->MsgRXState = RX_Sync; 119 d->MsgRXState = RX_Sync;
120 return ERR_NONE; 120 return ERR_NONE;
121 } 121 }
122 122
123 if (d->Msg.Destination != MBUS2_DEVICE_PHONE) { 123 if (d->Msg.Destination != MBUS2_DEVICE_PHONE) {
124 MBUS2_SendAck(s, d->Msg.Type, d->Msg.Buffer[d->Msg.Count-2]); 124 MBUS2_SendAck(s, d->Msg.Type, d->Msg.Buffer[d->Msg.Count-2]);
125 s->Phone.Data.RequestMsg= &d->Msg; 125 s->Phone.Data.RequestMsg= &d->Msg;
126 s->Phone.Data.DispatchError= Phone->DispatchMessage(s); 126 s->Phone.Data.DispatchError= Phone->DispatchMessage(s);
127 } 127 }
128 128
129 d->MsgRXState = RX_Sync; 129 d->MsgRXState = RX_Sync;
130 return ERR_NONE; 130 return ERR_NONE;
131 } 131 }
132 if (d->MsgRXState == RX_GetLength2) { 132 if (d->MsgRXState == RX_GetLength2) {
133 if (d->Msg.Type == MBUS2_ACK_BYTE) { 133 if (d->Msg.Type == MBUS2_ACK_BYTE) {
134 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || 134 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL ||
135 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) { 135 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE) {
136 smprintf(s,"[Received Ack]\n"); 136 smprintf(s,"[Received Ack]\n");
137 } 137 }
138 138
139 d->MsgRXState = RX_Sync; 139 d->MsgRXState = RX_Sync;
140 return ERR_NONE; 140 return ERR_NONE;
141 } 141 }
142 142
143 d->Msg.Length = d->Msg.Length + rx_char; 143 d->Msg.Length = d->Msg.Length + rx_char;
144 if (d->Msg.BufferUsed < d->Msg.Length+2) { 144 if (d->Msg.BufferUsed < d->Msg.Length+2) {
145 d->Msg.BufferUsed = d->Msg.Length+2; 145 d->Msg.BufferUsed = d->Msg.Length+2;
146 d->Msg.Buffer = (unsigned char *)realloc(d->Msg.Buffer,d->Msg.BufferUsed); 146 d->Msg.Buffer = (unsigned char *)realloc(d->Msg.Buffer,d->Msg.BufferUsed);
147 } 147 }
148 148
149 d->MsgRXState = RX_GetMessage; 149 d->MsgRXState = RX_GetMessage;
150 return ERR_NONE; 150 return ERR_NONE;
151 } 151 }
152 if (d->MsgRXState == RX_GetLength1) { 152 if (d->MsgRXState == RX_GetLength1) {
153 d->Msg.Length = rx_char * 256; 153 d->Msg.Length = rx_char * 256;
154 154
155 d->MsgRXState = RX_GetLength2; 155 d->MsgRXState = RX_GetLength2;
156 return ERR_NONE; 156 return ERR_NONE;
157 } 157 }
158 if (d->MsgRXState == RX_GetType) { 158 if (d->MsgRXState == RX_GetType) {
159 d->Msg.Type = rx_char; 159 d->Msg.Type = rx_char;
160 160
161 d->MsgRXState = RX_GetLength1; 161 d->MsgRXState = RX_GetLength1;
162 return ERR_NONE; 162 return ERR_NONE;
163 } 163 }
164 if (d->MsgRXState == RX_GetSource) { 164 if (d->MsgRXState == RX_GetSource) {
165 if (rx_char != MBUS2_DEVICE_PHONE && rx_char != MBUS2_DEVICE_PC) { 165 if (rx_char != MBUS2_DEVICE_PHONE && rx_char != MBUS2_DEVICE_PC) {
166 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || 166 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
167 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { 167 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) {
168 smprintf(s,"[ERROR: incorrect char - %02x, not %02x and %02x]\n", rx_char, MBUS2_DEVICE_PHONE, MBUS2_DEVICE_PC); 168 smprintf(s,"[ERROR: incorrect char - %02x, not %02x and %02x]\n", rx_char, MBUS2_DEVICE_PHONE, MBUS2_DEVICE_PC);
169 } 169 }
170 d->MsgRXState = RX_Sync; 170 d->MsgRXState = RX_Sync;
171 return ERR_NONE; 171 return ERR_NONE;
172 } 172 }
173 d->Msg.Source = rx_char; 173 d->Msg.Source = rx_char;
174 174
175 d->MsgRXState = RX_GetType; 175 d->MsgRXState = RX_GetType;
176 return ERR_NONE; 176 return ERR_NONE;
177 } 177 }
178 if (d->MsgRXState == RX_GetDestination) { 178 if (d->MsgRXState == RX_GetDestination) {
179 if (rx_char != MBUS2_DEVICE_PC && rx_char != MBUS2_DEVICE_PHONE) { 179 if (rx_char != MBUS2_DEVICE_PC && rx_char != MBUS2_DEVICE_PHONE) {
180 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || 180 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
181 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { 181 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) {
182 smprintf(s,"[ERROR: incorrect char - %02x, not %02x and %02x]\n", rx_char, MBUS2_DEVICE_PHONE, MBUS2_DEVICE_PC); 182 smprintf(s,"[ERROR: incorrect char - %02x, not %02x and %02x]\n", rx_char, MBUS2_DEVICE_PHONE, MBUS2_DEVICE_PC);
183 } 183 }
184 d->MsgRXState = RX_Sync; 184 d->MsgRXState = RX_Sync;
185 return ERR_NONE; 185 return ERR_NONE;
186 } 186 }
187 d->Msg.Destination = rx_char; 187 d->Msg.Destination = rx_char;
188 188
189 d->MsgRXState = RX_GetSource; 189 d->MsgRXState = RX_GetSource;
190 return ERR_NONE; 190 return ERR_NONE;
191 } 191 }
192 if (d->MsgRXState == RX_Sync) { 192 if (d->MsgRXState == RX_Sync) {
193 if (rx_char != MBUS2_FRAME_ID) { 193 if (rx_char != MBUS2_FRAME_ID) {
194 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || 194 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
diff --git a/gammu/emb/common/protocol/nokia/mbus2.h b/gammu/emb/common/protocol/nokia/mbus2.h
index 86fcab6..5dbd8cb 100644
--- a/gammu/emb/common/protocol/nokia/mbus2.h
+++ b/gammu/emb/common/protocol/nokia/mbus2.h
@@ -1,28 +1,28 @@
1/* (c) 2001-2003 by Marcin Wiacek */ 1/* (c) 2001-2003 by Marcin Wiacek */
2/* based on some work from MyGnokii */ 2/* based on some work from MyGnokii (www.mwiacek.com) */
3 3
4#ifndef mbus2_h 4#ifndef mbus2_h
5#define mbus2_h 5#define mbus2_h
6 6
7#include "../protocol.h" 7#include "../protocol.h"
8 8
9#define MBUS2_FRAME_ID 0x1f 9#define MBUS2_FRAME_ID 0x1f
10#define MBUS2_DEVICE_PHONE 0x00 /* Nokia mobile phone */ 10#define MBUS2_DEVICE_PHONE 0x00 /* Nokia mobile phone */
11#define MBUS2_DEVICE_PC 0x10 /* Our PC (MBUS) */ 11#define MBUS2_DEVICE_PC 0x10 /* Our PC (MBUS) */
12 #define MBUS2_ACK_BYTE 0x7f /* Acknowledge of the received frame */ 12 #define MBUS2_ACK_BYTE 0x7f /* Acknowledge of the received frame */
13 13
14typedef struct { 14typedef struct {
15 int MsgSequenceNumber; 15 int MsgSequenceNumber;
16 int MsgRXState; 16 int MsgRXState;
17 GSM_Protocol_MessageMsg; 17 GSM_Protocol_MessageMsg;
18} GSM_Protocol_MBUS2Data; 18} GSM_Protocol_MBUS2Data;
19 19
20#ifndef GSM_USED_SERIALDEVICE 20#ifndef GSM_USED_SERIALDEVICE
21# define GSM_USED_SERIALDEVICE 21# define GSM_USED_SERIALDEVICE
22#endif 22#endif
23 23
24#endif 24#endif
25 25
26/* How should editor hadle tabs in this file? Add editor commands here. 26/* How should editor hadle tabs in this file? Add editor commands here.
27 * vim: noexpandtab sw=8 ts=8 sts=8: 27 * vim: noexpandtab sw=8 ts=8 sts=8:
28 */ 28 */
diff --git a/gammu/emb/common/protocol/nokia/phonet.c b/gammu/emb/common/protocol/nokia/phonet.c
index bc5717d..db5bd72 100644
--- a/gammu/emb/common/protocol/nokia/phonet.c
+++ b/gammu/emb/common/protocol/nokia/phonet.c
@@ -1,194 +1,197 @@
1/* (c) 2002-2003 by Marcin Wiacek */ 1/* (c) 2002-2003 by Marcin Wiacek */
2/* based on some work from Gnokii */ 2/* Based on some work from Gnokii (www.gnokii.org)
3 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
4 * GNU GPL version 2 or later
5 */
3 6
4#include "../../gsmstate.h" 7#include "../../gsmstate.h"
5 8
6#if defined(GSM_ENABLE_IRDA) || defined(GSM_ENABLE_PHONETBLUE) || defined(GSM_ENABLE_BLUEPHONET) 9#if defined(GSM_ENABLE_IRDA) || defined(GSM_ENABLE_PHONETBLUE) || defined(GSM_ENABLE_BLUEPHONET)
7 10
8#include <stdio.h> 11#include <stdio.h>
9#include <string.h> 12#include <string.h>
10 13
11#include "../../gsmcomon.h" 14#include "../../gsmcomon.h"
12#include "phonet.h" 15#include "phonet.h"
13 16
14 static GSM_Error PHONET_WriteMessage (GSM_StateMachine *s, 17 static GSM_Error PHONET_WriteMessage (GSM_StateMachine *s,
15 unsigned char *MsgBuffer, 18 unsigned char *MsgBuffer,
16 int MsgLength, 19 int MsgLength,
17 unsigned char MsgType) 20 unsigned char MsgType)
18{ 21{
19 unsigned char *buffer2; 22 unsigned char *buffer2;
20 int sent; 23 int sent;
21 24
22 GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType); 25 GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType);
23 26
24 buffer2 = (unsigned char *)malloc(MsgLength + 6); 27 buffer2 = (unsigned char *)malloc(MsgLength + 6);
25 28
26 buffer2[0] = PHONET_FRAME_ID, 29 buffer2[0] = PHONET_FRAME_ID,
27 buffer2[1] = PHONET_DEVICE_PHONE; //destination 30 buffer2[1] = PHONET_DEVICE_PHONE; //destination
28 buffer2[2] = PHONET_DEVICE_PC; //source 31 buffer2[2] = PHONET_DEVICE_PC; //source
29 32
30 if (s->ConnectionType==GCT_PHONETBLUE || s->ConnectionType==GCT_BLUEPHONET) { 33 if (s->ConnectionType==GCT_PHONETBLUE || s->ConnectionType==GCT_BLUEPHONET) {
31 buffer2[0] = PHONET_BLUE_FRAME_ID; 34 buffer2[0] = PHONET_BLUE_FRAME_ID;
32 buffer2[1] = PHONET_DEVICE_PHONE;//destination 35 buffer2[1] = PHONET_DEVICE_PHONE;//destination
33 buffer2[2] = PHONET_BLUE_DEVICE_PC;//source 36 buffer2[2] = PHONET_BLUE_DEVICE_PC;//source
34 } 37 }
35 38
36 buffer2[3] = MsgType; 39 buffer2[3] = MsgType;
37 buffer2[4] = MsgLength / 256; 40 buffer2[4] = MsgLength / 256;
38 buffer2[5] = MsgLength % 256; 41 buffer2[5] = MsgLength % 256;
39 42
40 memcpy(buffer2 + 6, MsgBuffer, MsgLength); 43 memcpy(buffer2 + 6, MsgBuffer, MsgLength);
41 44
42 GSM_DumpMessageLevel2(s, buffer2+6, MsgLength, MsgType); 45 GSM_DumpMessageLevel2(s, buffer2+6, MsgLength, MsgType);
43 46
44 /* Sending to phone */ 47 /* Sending to phone */
45 sent = s->Device.Functions->WriteDevice(s,buffer2,MsgLength+6); 48 sent = s->Device.Functions->WriteDevice(s,buffer2,MsgLength+6);
46 49
47 free(buffer2); 50 free(buffer2);
48 51
49 if (sent!=MsgLength+6) return ERR_DEVICEWRITEERROR; 52 if (sent!=MsgLength+6) return ERR_DEVICEWRITEERROR;
50 return ERR_NONE; 53 return ERR_NONE;
51} 54}
52 55
53static GSM_Error PHONET_StateMachine(GSM_StateMachine *s, unsigned char rx_char) 56static GSM_Error PHONET_StateMachine(GSM_StateMachine *s, unsigned char rx_char)
54{ 57{
55 GSM_Protocol_PHONETData *d = &s->Protocol.Data.PHONET; 58 GSM_Protocol_PHONETData *d = &s->Protocol.Data.PHONET;
56 bool correct = false; 59 bool correct = false;
57 60
58 if (d->MsgRXState==RX_GetMessage) { 61 if (d->MsgRXState==RX_GetMessage) {
59 d->Msg.Buffer[d->Msg.Count] = rx_char; 62 d->Msg.Buffer[d->Msg.Count] = rx_char;
60 d->Msg.Count++; 63 d->Msg.Count++;
61 64
62 /* This is not last byte in frame */ 65 /* This is not last byte in frame */
63 if (d->Msg.Count != d->Msg.Length) return ERR_NONE; 66 if (d->Msg.Count != d->Msg.Length) return ERR_NONE;
64 67
65 s->Phone.Data.RequestMsg= &d->Msg; 68 s->Phone.Data.RequestMsg= &d->Msg;
66 s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s); 69 s->Phone.Data.DispatchError= s->Phone.Functions->DispatchMessage(s);
67 70
68 free(d->Msg.Buffer); 71 free(d->Msg.Buffer);
69 d->Msg.Length = 0; 72 d->Msg.Length = 0;
70 d->Msg.Buffer = NULL; 73 d->Msg.Buffer = NULL;
71 74
72 d->MsgRXState = RX_Sync; 75 d->MsgRXState = RX_Sync;
73 return ERR_NONE; 76 return ERR_NONE;
74 } 77 }
75 if (d->MsgRXState==RX_GetLength2) { 78 if (d->MsgRXState==RX_GetLength2) {
76 d->Msg.Length = d->Msg.Length + rx_char; 79 d->Msg.Length = d->Msg.Length + rx_char;
77 d->Msg.Buffer = (unsigned char *)malloc(d->Msg.Length); 80 d->Msg.Buffer = (unsigned char *)malloc(d->Msg.Length);
78 81
79 d->MsgRXState = RX_GetMessage; 82 d->MsgRXState = RX_GetMessage;
80 return ERR_NONE; 83 return ERR_NONE;
81 } 84 }
82 if (d->MsgRXState==RX_GetLength1) { 85 if (d->MsgRXState==RX_GetLength1) {
83 d->Msg.Length = rx_char * 256; 86 d->Msg.Length = rx_char * 256;
84 87
85 d->MsgRXState = RX_GetLength2; 88 d->MsgRXState = RX_GetLength2;
86 return ERR_NONE; 89 return ERR_NONE;
87 } 90 }
88 if (d->MsgRXState==RX_GetType) { 91 if (d->MsgRXState==RX_GetType) {
89 d->Msg.Type = rx_char; 92 d->Msg.Type = rx_char;
90 93
91 d->MsgRXState = RX_GetLength1; 94 d->MsgRXState = RX_GetLength1;
92 return ERR_NONE; 95 return ERR_NONE;
93 } 96 }
94 if (d->MsgRXState==RX_GetSource) { 97 if (d->MsgRXState==RX_GetSource) {
95 if (rx_char != PHONET_DEVICE_PHONE) { 98 if (rx_char != PHONET_DEVICE_PHONE) {
96 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || 99 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
97 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { 100 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) {
98 smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, PHONET_DEVICE_PHONE); 101 smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, PHONET_DEVICE_PHONE);
99 } 102 }
100 d->MsgRXState = RX_Sync; 103 d->MsgRXState = RX_Sync;
101 return ERR_NONE; 104 return ERR_NONE;
102 } 105 }
103 d->Msg.Source = rx_char; 106 d->Msg.Source = rx_char;
104 107
105 d->MsgRXState = RX_GetType; 108 d->MsgRXState = RX_GetType;
106 return ERR_NONE; 109 return ERR_NONE;
107 } 110 }
108 if (d->MsgRXState==RX_GetDestination) { 111 if (d->MsgRXState==RX_GetDestination) {
109 switch (s->ConnectionType) { 112 switch (s->ConnectionType) {
110 case GCT_IRDAPHONET: 113 case GCT_IRDAPHONET:
111 if (rx_char == PHONET_DEVICE_PC) correct = true; 114 if (rx_char == PHONET_DEVICE_PC) correct = true;
112 break; 115 break;
113 case GCT_PHONETBLUE: 116 case GCT_PHONETBLUE:
114 case GCT_BLUEPHONET: 117 case GCT_BLUEPHONET:
115 if (rx_char == PHONET_BLUE_DEVICE_PC) correct = true; 118 if (rx_char == PHONET_BLUE_DEVICE_PC) correct = true;
116 break; 119 break;
117 default: 120 default:
118 break; 121 break;
119 } 122 }
120 if (!correct) { 123 if (!correct) {
121 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || 124 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
122 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { 125 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) {
123 smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, PHONET_DEVICE_PC); 126 smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, PHONET_DEVICE_PC);
124 } 127 }
125 d->MsgRXState = RX_Sync; 128 d->MsgRXState = RX_Sync;
126 return ERR_NONE; 129 return ERR_NONE;
127 } 130 }
128 d->Msg.Destination = rx_char; 131 d->Msg.Destination = rx_char;
129 132
130 d->MsgRXState = RX_GetSource; 133 d->MsgRXState = RX_GetSource;
131 return ERR_NONE; 134 return ERR_NONE;
132 } 135 }
133 if (d->MsgRXState==RX_Sync) { 136 if (d->MsgRXState==RX_Sync) {
134 switch (s->ConnectionType) { 137 switch (s->ConnectionType) {
135 case GCT_IRDAPHONET: 138 case GCT_IRDAPHONET:
136 if (rx_char == PHONET_FRAME_ID) correct = true; 139 if (rx_char == PHONET_FRAME_ID) correct = true;
137 break; 140 break;
138 case GCT_PHONETBLUE: 141 case GCT_PHONETBLUE:
139 case GCT_BLUEPHONET: 142 case GCT_BLUEPHONET:
140 if (rx_char == PHONET_BLUE_FRAME_ID) correct = true; 143 if (rx_char == PHONET_BLUE_FRAME_ID) correct = true;
141 break; 144 break;
142 default: 145 default:
143 break; 146 break;
144 } 147 }
145 if (!correct) { 148 if (!correct) {
146 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR || 149 if (s->di.dl==DL_TEXT || s->di.dl==DL_TEXTALL || s->di.dl==DL_TEXTERROR ||
147 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) { 150 s->di.dl==DL_TEXTDATE || s->di.dl==DL_TEXTALLDATE || s->di.dl==DL_TEXTERRORDATE) {
148 smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, PHONET_FRAME_ID); 151 smprintf(s,"[ERROR: incorrect char - %02x, not %02x]\n", rx_char, PHONET_FRAME_ID);
149 } 152 }
150 return ERR_NONE; 153 return ERR_NONE;
151 } 154 }
152 d->Msg.Count = 0; 155 d->Msg.Count = 0;
153 156
154 d->MsgRXState = RX_GetDestination; 157 d->MsgRXState = RX_GetDestination;
155 return ERR_NONE; 158 return ERR_NONE;
156 } 159 }
157 return ERR_NONE; 160 return ERR_NONE;
158} 161}
159 162
160static GSM_Error PHONET_Initialise(GSM_StateMachine *s) 163static GSM_Error PHONET_Initialise(GSM_StateMachine *s)
161{ 164{
162 int total = 0, i, n; 165 int total = 0, i, n;
163 GSM_Protocol_PHONETData *d = &s->Protocol.Data.PHONET; 166 GSM_Protocol_PHONETData *d = &s->Protocol.Data.PHONET;
164 unsigned char req[50]; 167 unsigned char req[50];
165 168
166 d->Msg.Length= 0; 169 d->Msg.Length= 0;
167 d->Msg.Buffer= NULL; 170 d->Msg.Buffer= NULL;
168 d->MsgRXState= RX_Sync; 171 d->MsgRXState= RX_Sync;
169 172
170 if (s->ConnectionType == GCT_PHONETBLUE || s->ConnectionType == GCT_BLUEPHONET) { 173 if (s->ConnectionType == GCT_PHONETBLUE || s->ConnectionType == GCT_BLUEPHONET) {
171 /* Send frame in PHONET style */ 174 /* Send frame in PHONET style */
172 req[0] = PHONET_BLUE_FRAME_ID; req[1] = PHONET_DEVICE_PHONE; 175 req[0] = PHONET_BLUE_FRAME_ID; req[1] = PHONET_DEVICE_PHONE;
173 req[2] = PHONET_BLUE_DEVICE_PC; req[3] = 0xD0; 176 req[2] = PHONET_BLUE_DEVICE_PC; req[3] = 0xD0;
174 req[4] = 0x00; req[5] = 0x01; 177 req[4] = 0x00; req[5] = 0x01;
175 req[6] = 0x04; 178 req[6] = 0x04;
176 if (s->Device.Functions->WriteDevice(s,req,7) != 7) return ERR_DEVICEWRITEERROR; 179 if (s->Device.Functions->WriteDevice(s,req,7) != 7) return ERR_DEVICEWRITEERROR;
177 180
178 while (total < 7) { 181 while (total < 7) {
179 n = s->Device.Functions->ReadDevice(s, req + total, 50 - total); 182 n = s->Device.Functions->ReadDevice(s, req + total, 50 - total);
180 total += n; 183 total += n;
181 } 184 }
182 185
183 /* Answer frame in PHONET style */ 186 /* Answer frame in PHONET style */
184 req[10] = PHONET_BLUE_FRAME_ID; req[11] = PHONET_BLUE_DEVICE_PC; 187 req[10] = PHONET_BLUE_FRAME_ID; req[11] = PHONET_BLUE_DEVICE_PC;
185 req[12] = PHONET_DEVICE_PHONE;req[13] = 0xD0; 188 req[12] = PHONET_DEVICE_PHONE;req[13] = 0xD0;
186 req[14] = 0x00; req[15] = 0x01; 189 req[14] = 0x00; req[15] = 0x01;
187 req[16] = 0x05; 190 req[16] = 0x05;
188 191
189 for (i = 0; i < 7; i++) { 192 for (i = 0; i < 7; i++) {
190 if (req[i] != req[10+i]) { 193 if (req[i] != req[10+i]) {
191 smprintf(s,"Incorrect byte in the answer\n"); 194 smprintf(s,"Incorrect byte in the answer\n");
192 return ERR_UNKNOWN; 195 return ERR_UNKNOWN;
193 } 196 }
194 } 197 }
diff --git a/gammu/emb/common/protocol/nokia/phonet.h b/gammu/emb/common/protocol/nokia/phonet.h
index 2f6e836..e750bbd 100644
--- a/gammu/emb/common/protocol/nokia/phonet.h
+++ b/gammu/emb/common/protocol/nokia/phonet.h
@@ -1,35 +1,38 @@
1/* (c) 2002-2003 by Marcin Wiacek */ 1/* (c) 2002-2003 by Marcin Wiacek */
2/* based on some work from Gnokii */ 2/* Based on some work from Gnokii (www.gnokii.org)
3 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
4 * GNU GPL version 2 or later
5 */
3 6
4#ifndef PHONET_h 7#ifndef PHONET_h
5#define PHONET_h 8#define PHONET_h
6 9
7#include "../protocol.h" 10#include "../protocol.h"
8 11
9 #define PHONET_FRAME_ID 0x14 12 #define PHONET_FRAME_ID 0x14
10 #define PHONET_BLUE_FRAME_ID0x19 13 #define PHONET_BLUE_FRAME_ID0x19
11 #define PHONET_DEVICE_PHONE 0x00 /* Nokia mobile phone */ 14 #define PHONET_DEVICE_PHONE 0x00 /* Nokia mobile phone */
12 #define PHONET_DEVICE_PC 0x0c /* Our PC */ 15 #define PHONET_DEVICE_PC 0x0c /* Our PC */
13#define PHONET_BLUE_DEVICE_PC 0x10 /* Our PC */ 16#define PHONET_BLUE_DEVICE_PC 0x10 /* Our PC */
14 17
15typedef struct { 18typedef struct {
16 int MsgRXState; 19 int MsgRXState;
17 GSM_Protocol_MessageMsg; 20 GSM_Protocol_MessageMsg;
18} GSM_Protocol_PHONETData; 21} GSM_Protocol_PHONETData;
19 22
20#if defined(GSM_ENABLE_IRDAPHONET) 23#if defined(GSM_ENABLE_IRDAPHONET)
21# ifndef GSM_USED_IRDADEVICE 24# ifndef GSM_USED_IRDADEVICE
22# define GSM_USED_IRDADEVICE 25# define GSM_USED_IRDADEVICE
23# endif 26# endif
24#endif 27#endif
25#if defined(GSM_ENABLE_BLUEPHONET) 28#if defined(GSM_ENABLE_BLUEPHONET)
26# ifndef GSM_USED_BLUETOOTHDEVICE 29# ifndef GSM_USED_BLUETOOTHDEVICE
27# define GSM_USED_BLUETOOTHDEVICE 30# define GSM_USED_BLUETOOTHDEVICE
28# endif 31# endif
29#endif 32#endif
30 33
31#endif 34#endif
32 35
33/* How should editor hadle tabs in this file? Add editor commands here. 36/* How should editor hadle tabs in this file? Add editor commands here.
34 * vim: noexpandtab sw=8 ts=8 sts=8: 37 * vim: noexpandtab sw=8 ts=8 sts=8:
35 */ 38 */
diff --git a/gammu/emb/common/service/backup/backgen.h b/gammu/emb/common/service/backup/backgen.h
index 9d7d973..9a930fc 100644
--- a/gammu/emb/common/service/backup/backgen.h
+++ b/gammu/emb/common/service/backup/backgen.h
@@ -1,69 +1,73 @@
1/* (c) 2002-2004 by Marcin Wiacek */ 1/* (c) 2002-2004 by Marcin Wiacek */
2 2
3#ifndef __gsm_backgen_h 3#ifndef __gsm_backgen_h
4#define __gsm_backgen_h 4#define __gsm_backgen_h
5 5
6#include "../../config.h" 6#include "../../config.h"
7#include "../../misc/misc.h" 7#include "../../misc/misc.h"
8#include "../gsmpbk.h" 8#include "../gsmpbk.h"
9#include "../gsmcal.h" 9#include "../gsmcal.h"
10#include "../gsmlogo.h" 10#include "../gsmlogo.h"
11#include "../gsmring.h" 11#include "../gsmring.h"
12#include "../gsmdata.h" 12#include "../gsmdata.h"
13#include "../gsmprof.h" 13#include "../gsmprof.h"
14#include "../gsmmisc.h" 14#include "../gsmmisc.h"
15#include "../sms/gsmsms.h" 15#include "../sms/gsmsms.h"
16 16
17 #define GSM_BACKUP_MAX_PHONEPHONEBOOK 501 17 #define GSM_BACKUP_MAX_PHONEPHONEBOOK 501
18 #define GSM_BACKUP_MAX_SIMPHONEBOOK 251 18 #define GSM_BACKUP_MAX_SIMPHONEBOOK 251
19 #define GSM_BACKUP_MAX_CALLER 6 19 #define GSM_BACKUP_MAX_CALLER 6
20 #define GSM_BACKUP_MAX_SMSC 10 20 #define GSM_BACKUP_MAX_SMSC 10
21 #define GSM_BACKUP_MAX_WAPBOOKMARK40 21 #define GSM_BACKUP_MAX_WAPBOOKMARK40
22 #define GSM_BACKUP_MAX_WAPSETTINGS30 22 #define GSM_BACKUP_MAX_WAPSETTINGS30
23 #define GSM_BACKUP_MAX_MMSSETTINGS30 23 #define GSM_BACKUP_MAX_MMSSETTINGS30
24 #define GSM_BACKUP_MAX_SYNCMLSETTINGS10
25 #define GSM_BACKUP_MAX_CHATSETTINGS10
24 #define GSM_BACKUP_MAX_RINGTONES30 26 #define GSM_BACKUP_MAX_RINGTONES30
25 #define GSM_BACKUP_MAX_PROFILES 10 27 #define GSM_BACKUP_MAX_PROFILES 10
26 #define GSM_BACKUP_MAX_FMSTATIONS20 28 #define GSM_BACKUP_MAX_FMSTATIONS20
27 #define GSM_BACKUP_MAX_GPRSPOINT10 29 #define GSM_BACKUP_MAX_GPRSPOINT10
28 #define GSM_BACKUP_MAX_NOTE 10/* FIXME */ 30 #define GSM_BACKUP_MAX_NOTE 10/* FIXME */
29 31
30typedef struct { 32typedef struct {
31 char IMEI [MAX_IMEI_LENGTH]; 33 char IMEI [MAX_IMEI_LENGTH];
32 char Model [MAX_MODEL_LENGTH+MAX_VERSION_LENGTH]; 34 char Model [MAX_MODEL_LENGTH+MAX_VERSION_LENGTH];
33 char Creator [80]; 35 char Creator [80];
34 GSM_DateTime DateTime; 36 GSM_DateTime DateTime;
35 bool DateTimeAvailable; 37 bool DateTimeAvailable;
36 char MD5Original[100]; 38 char MD5Original[100];
37 char MD5Calculated[100]; 39 char MD5Calculated[100];
38 GSM_MemoryEntry *PhonePhonebook[GSM_BACKUP_MAX_PHONEPHONEBOOK + 1]; 40 GSM_MemoryEntry *PhonePhonebook[GSM_BACKUP_MAX_PHONEPHONEBOOK + 1];
39 GSM_MemoryEntry *SIMPhonebook[GSM_BACKUP_MAX_SIMPHONEBOOK + 1]; 41 GSM_MemoryEntry *SIMPhonebook[GSM_BACKUP_MAX_SIMPHONEBOOK + 1];
40 GSM_CalendarEntry *Calendar[GSM_MAXCALENDARTODONOTES + 1]; 42 GSM_CalendarEntry *Calendar[GSM_MAXCALENDARTODONOTES + 1];
41 GSM_Bitmap *CallerLogos[GSM_BACKUP_MAX_CALLER + 1]; 43 GSM_Bitmap *CallerLogos[GSM_BACKUP_MAX_CALLER + 1];
42 GSM_SMSC *SMSC [GSM_BACKUP_MAX_SMSC + 1]; 44 GSM_SMSC *SMSC [GSM_BACKUP_MAX_SMSC + 1];
43 GSM_WAPBookmark *WAPBookmark[GSM_BACKUP_MAX_WAPBOOKMARK + 1]; 45 GSM_WAPBookmark *WAPBookmark[GSM_BACKUP_MAX_WAPBOOKMARK + 1];
44 GSM_MultiWAPSettings *WAPSettings[GSM_BACKUP_MAX_WAPSETTINGS + 1]; 46 GSM_MultiWAPSettings *WAPSettings[GSM_BACKUP_MAX_WAPSETTINGS + 1];
45 GSM_MultiWAPSettings *MMSSettings[GSM_BACKUP_MAX_MMSSETTINGS + 1]; 47 GSM_MultiWAPSettings *MMSSettings[GSM_BACKUP_MAX_MMSSETTINGS + 1];
48 GSM_SyncMLSettings*SyncMLSettings [GSM_BACKUP_MAX_SYNCMLSETTINGS + 1];
49 GSM_ChatSettings *ChatSettings [GSM_BACKUP_MAX_CHATSETTINGS + 1];
46 GSM_Ringtone *Ringtone[GSM_BACKUP_MAX_RINGTONES + 1]; 50 GSM_Ringtone *Ringtone[GSM_BACKUP_MAX_RINGTONES + 1];
47 GSM_ToDoEntry *ToDo [GSM_MAXCALENDARTODONOTES + 1]; 51 GSM_ToDoEntry *ToDo [GSM_MAXCALENDARTODONOTES + 1];
48 GSM_Profile *Profiles[GSM_BACKUP_MAX_PROFILES + 1]; 52 GSM_Profile *Profiles[GSM_BACKUP_MAX_PROFILES + 1];
49 GSM_FMStation *FMStation[GSM_BACKUP_MAX_FMSTATIONS +1]; 53 GSM_FMStation *FMStation[GSM_BACKUP_MAX_FMSTATIONS +1];
50 GSM_GPRSAccessPoint *GPRSPoint[GSM_BACKUP_MAX_GPRSPOINT + 1]; 54 GSM_GPRSAccessPoint *GPRSPoint[GSM_BACKUP_MAX_GPRSPOINT + 1];
51 GSM_NoteEntry *Note [GSM_BACKUP_MAX_NOTE + 1]; 55 GSM_NoteEntry *Note [GSM_BACKUP_MAX_NOTE + 1];
52 GSM_Bitmap *StartupLogo; 56 GSM_Bitmap *StartupLogo;
53 GSM_Bitmap *OperatorLogo; 57 GSM_Bitmap *OperatorLogo;
54} GSM_Backup; 58} GSM_Backup;
55 59
56 #define GSM_BACKUP_MAX_SMS500 60 #define GSM_BACKUP_MAX_SMS500
57 61
58typedef struct { 62typedef struct {
59 GSM_SMSMessage *SMS[GSM_BACKUP_MAX_SMS]; 63 GSM_SMSMessage *SMS[GSM_BACKUP_MAX_SMS];
60} GSM_SMS_Backup; 64} GSM_SMS_Backup;
61 65
62extern GSM_Error GSM_ReadSMSBackupFile(char *FileName, GSM_SMS_Backup *backup); 66extern GSM_Error GSM_ReadSMSBackupFile(char *FileName, GSM_SMS_Backup *backup);
63extern GSM_Error GSM_SaveSMSBackupFile(char *FileName, GSM_SMS_Backup *backup); 67extern GSM_Error GSM_SaveSMSBackupFile(char *FileName, GSM_SMS_Backup *backup);
64 68
65#endif 69#endif
66 70
67/* How should editor hadle tabs in this file? Add editor commands here. 71/* How should editor hadle tabs in this file? Add editor commands here.
68 * vim: noexpandtab sw=8 ts=8 sts=8: 72 * vim: noexpandtab sw=8 ts=8 sts=8:
69 */ 73 */
diff --git a/gammu/emb/common/service/backup/backtext.c b/gammu/emb/common/service/backup/backtext.c
index fee0f73..4cb1bb7 100644
--- a/gammu/emb/common/service/backup/backtext.c
+++ b/gammu/emb/common/service/backup/backtext.c
@@ -1,1304 +1,1380 @@
1/* (c) 2002-2004 by Marcin Wiacek, Walek and Michal Cihar */ 1/* (c) 2002-2004 by Marcin Wiacek, Walek and Michal Cihar */
2 2
3#include <string.h> 3#include <string.h>
4#include <ctype.h> 4#include <ctype.h>
5 5
6#include "../../phone/nokia/nfunc.h" 6#include "../../phone/nokia/nfunc.h"
7#include "../../phone/nokia/dct3/n7110.h" 7#include "../../phone/nokia/dct3/n7110.h"
8#include "../../misc/cfg.h" 8#include "../../misc/cfg.h"
9#include "../../misc/coding/coding.h" 9#include "../../misc/coding/coding.h"
10#include "../../misc/coding/md5.h" 10#include "../../misc/coding/md5.h"
11#include "../gsmlogo.h" 11#include "../gsmlogo.h"
12#include "../gsmmisc.h" 12#include "../gsmmisc.h"
13#include "backtext.h" 13#include "backtext.h"
14 14
15#ifdef GSM_ENABLE_BACKUP 15#ifdef GSM_ENABLE_BACKUP
16 16
17GSM_Error FindBackupChecksum(char *FileName, bool UseUnicode, char *checksum) 17GSM_Error FindBackupChecksum(char *FileName, bool UseUnicode, char *checksum)
18{ 18{
19 INI_Section *file_info, *h; 19 INI_Section *file_info, *h;
20 INI_Entry *e; 20 INI_Entry *e;
21 char *buffer = NULL,buff[100]; 21 char *buffer = NULL,buff[100];
22 int len=0; 22 int len=0;
23 23
24 //int i; 24 //int i;
25 25
26 file_info = INI_ReadFile(FileName, UseUnicode); 26 file_info = INI_ReadFile(FileName, UseUnicode);
27 27
28 if (UseUnicode) { 28 if (UseUnicode) {
29 for (h = file_info; h != NULL; h = h->Next) { 29 for (h = file_info; h != NULL; h = h->Next) {
30 EncodeUnicode(buff,"Checksum",8); 30 EncodeUnicode(buff,"Checksum",8);
31 if (mywstrncasecmp(buff, h->SectionName, 8)) continue; 31 if (mywstrncasecmp(buff, h->SectionName, 8)) continue;
32 32
33 buffer = (unsigned char *)realloc(buffer,len+UnicodeLength(h->SectionName)*2+2); 33 buffer = (unsigned char *)realloc(buffer,len+UnicodeLength(h->SectionName)*2+2);
34 CopyUnicodeString(buffer+len,h->SectionName); 34 CopyUnicodeString(buffer+len,h->SectionName);
35 len+=UnicodeLength(h->SectionName)*2; 35 len+=UnicodeLength(h->SectionName)*2;
36 // dbgprintf("[%s]\n",DecodeUnicodeConsole(h->SectionName)); 36 // dbgprintf("[%s]\n",DecodeUnicodeConsole(h->SectionName));
37 37
38 for (e = h->SubEntries; e != NULL; e = e->Next) { 38 for (e = h->SubEntries; e != NULL; e = e->Next) {
39 buffer = (unsigned char *)realloc(buffer,len+UnicodeLength(e->EntryName)*2+2); 39 buffer = (unsigned char *)realloc(buffer,len+UnicodeLength(e->EntryName)*2+2);
40 CopyUnicodeString(buffer+len,e->EntryName); 40 CopyUnicodeString(buffer+len,e->EntryName);
41 len+=UnicodeLength(e->EntryName)*2; 41 len+=UnicodeLength(e->EntryName)*2;
42 buffer = (unsigned char *)realloc(buffer,len+UnicodeLength(e->EntryValue)*2+2); 42 buffer = (unsigned char *)realloc(buffer,len+UnicodeLength(e->EntryValue)*2+2);
43 CopyUnicodeString(buffer+len,e->EntryValue); 43 CopyUnicodeString(buffer+len,e->EntryValue);
44 len+=UnicodeLength(e->EntryValue)*2; 44 len+=UnicodeLength(e->EntryValue)*2;
45 // dbgprintf("\"%s\"",DecodeUnicodeConsole(e->EntryName)); 45 // dbgprintf("\"%s\"",DecodeUnicodeConsole(e->EntryName));
46 // dbgprintf("=\"%s\"\n",DecodeUnicodeConsole(e->EntryValue)); 46 // dbgprintf("=\"%s\"\n",DecodeUnicodeConsole(e->EntryValue));
47 } 47 }
48 } 48 }
49 } else { 49 } else {
50 for (h = file_info; h != NULL; h = h->Next) { 50 for (h = file_info; h != NULL; h = h->Next) {
51 if (mystrncasecmp("Checksum", h->SectionName, 8)) continue; 51 if (mystrncasecmp("Checksum", h->SectionName, 8)) continue;
52 52
53 buffer = (unsigned char *)realloc(buffer,len+strlen(h->SectionName)+1); 53 buffer = (unsigned char *)realloc(buffer,len+strlen(h->SectionName)+1);
54 strcpy(buffer+len,h->SectionName); 54 strcpy(buffer+len,h->SectionName);
55 len+=strlen(h->SectionName); 55 len+=strlen(h->SectionName);
56 56
57 for (e = h->SubEntries; e != NULL; e = e->Next) { 57 for (e = h->SubEntries; e != NULL; e = e->Next) {
58 // dbgprintf("%s=%s\n",e->EntryName,e->EntryValue); 58 // dbgprintf("%s=%s\n",e->EntryName,e->EntryValue);
59 buffer = (unsigned char *)realloc(buffer,len+strlen(e->EntryName)+1); 59 buffer = (unsigned char *)realloc(buffer,len+strlen(e->EntryName)+1);
60 strcpy(buffer+len,e->EntryName); 60 strcpy(buffer+len,e->EntryName);
61 len+=strlen(e->EntryName); 61 len+=strlen(e->EntryName);
62 buffer = (unsigned char *)realloc(buffer,len+strlen(e->EntryValue)+1); 62 buffer = (unsigned char *)realloc(buffer,len+strlen(e->EntryValue)+1);
63 strcpy(buffer+len,e->EntryValue); 63 strcpy(buffer+len,e->EntryValue);
64 len+=strlen(e->EntryValue); 64 len+=strlen(e->EntryValue);
65 } 65 }
66 } 66 }
67 } 67 }
68 68
69 //for (i=0;i<len;i++) printf("%02x",buffer[i]); 69 //for (i=0;i<len;i++) printf("%02x",buffer[i]);
70 CalculateMD5(buffer, len, checksum); 70 CalculateMD5(buffer, len, checksum);
71 free(buffer); 71 free(buffer);
72 72
73 return ERR_NONE; 73 return ERR_NONE;
74} 74}
75 75
76static unsigned char *ReadCFGText(INI_Section *cfg, unsigned char *section, unsigned char *key, bool Unicode) 76static unsigned char *ReadCFGText(INI_Section *cfg, unsigned char *section, unsigned char *key, bool Unicode)
77{ 77{
78 unsigned char Buffer[500],Buffer2[500],*retval; 78 unsigned char Buffer[500],Buffer2[500],*retval;
79 79
80 if (Unicode) { 80 if (Unicode) {
81 EncodeUnicode(Buffer2,key,strlen(key)); 81 EncodeUnicode(Buffer2,key,strlen(key));
82 retval = INI_GetValue(cfg,section,Buffer2,Unicode); 82 retval = INI_GetValue(cfg,section,Buffer2,Unicode);
83 if (retval != NULL) return DecodeUnicodeString(retval); 83 if (retval != NULL) return DecodeUnicodeString(retval);
84 return NULL; 84 return NULL;
85 } else { 85 } else {
86 strcpy(Buffer,section); 86 strcpy(Buffer,section);
87 strcpy(Buffer2,key); 87 strcpy(Buffer2,key);
88 return INI_GetValue(cfg,section,key,Unicode); 88 return INI_GetValue(cfg,section,key,Unicode);
89 } 89 }
90} 90}
91 91
92static void SaveLinkedBackupText(FILE *file, char *myname, char *myvalue, bool UseUnicode) 92static void SaveLinkedBackupText(FILE *file, char *myname, char *myvalue, bool UseUnicode)
93{ 93{
94 int w,current; 94 int w,current;
95 unsigned char buffer2[1000],buffer3[1000]; 95 unsigned char buffer2[1000],buffer3[1000];
96 96
97 current = strlen(myvalue); w = 0; 97 current = strlen(myvalue); w = 0;
98 while (true) { 98 while (true) {
99 if (current > 200) { 99 if (current > 200) {
100 memcpy(buffer2,myvalue+(strlen(myvalue)-current),200); 100 memcpy(buffer2,myvalue+(strlen(myvalue)-current),200);
101 buffer2[200] = 0; 101 buffer2[200] = 0;
102 current = current - 200; 102 current = current - 200;
103 } else { 103 } else {
104 memcpy(buffer2,myvalue+(strlen(myvalue)-current),current); 104 memcpy(buffer2,myvalue+(strlen(myvalue)-current),current);
105 buffer2[current] = 0; 105 buffer2[current] = 0;
106 current = 0; 106 current = 0;
107 } 107 }
108 if (UseUnicode) { 108 if (UseUnicode) {
109 sprintf(buffer3,"%s%02i = %s%c%c",myname,w,buffer2,13,10); 109 sprintf(buffer3,"%s%02i = %s%c%c",myname,w,buffer2,13,10);
110 EncodeUnicode(buffer2,buffer3,strlen(buffer3)); 110 EncodeUnicode(buffer2,buffer3,strlen(buffer3));
111 fwrite(buffer2,1,strlen(buffer3)*2,file); 111 fwrite(buffer2,1,strlen(buffer3)*2,file);
112 } else { 112 } else {
113 fprintf(file,"%s%02i = %s%c%c",myname,w,buffer2,13,10); 113 fprintf(file,"%s%02i = %s%c%c",myname,w,buffer2,13,10);
114 } 114 }
115 if (current == 0) break; 115 if (current == 0) break;
116 w++; 116 w++;
117 } 117 }
118} 118}
119 119
120static void ReadLinkedBackupText(INI_Section *file_info, char *section, char *myname, char *myvalue, bool UseUnicode) 120static void ReadLinkedBackupText(INI_Section *file_info, char *section, char *myname, char *myvalue, bool UseUnicode)
121{ 121{
122 unsigned char buffer2[300]; 122 unsigned char buffer2[300];
123 char *readvalue; 123 char *readvalue;
124 int i; 124 int i;
125 125
126 i=0; 126 i=0;
127 myvalue[0] = 0; 127 myvalue[0] = 0;
128 while (true) { 128 while (true) {
129 sprintf(buffer2,"%s%02i",myname,i); 129 sprintf(buffer2,"%s%02i",myname,i);
130 readvalue = ReadCFGText(file_info, section, buffer2, UseUnicode); 130 readvalue = ReadCFGText(file_info, section, buffer2, UseUnicode);
131 if (readvalue!=NULL) { 131 if (readvalue!=NULL) {
132 myvalue[strlen(myvalue)+strlen(readvalue)]=0; 132 myvalue[strlen(myvalue)+strlen(readvalue)]=0;
133 memcpy(myvalue+strlen(myvalue),readvalue,strlen(readvalue)); 133 memcpy(myvalue+strlen(myvalue),readvalue,strlen(readvalue));
134 } else break; 134 } else break;
135 i++; 135 i++;
136 } 136 }
137} 137}
138 138
139static void SaveBackupText(FILE *file, char *myname, char *myvalue, bool UseUnicode) 139static void SaveBackupText(FILE *file, char *myname, char *myvalue, bool UseUnicode)
140{ 140{
141 unsigned char buffer[10000], buffer2[10000]; 141 unsigned char buffer[10000], buffer2[10000];
142 142
143 if (myname[0] == 0x00) { 143 if (myname[0] == 0x00) {
144 if (UseUnicode) { 144 if (UseUnicode) {
145 EncodeUnicode(buffer,myvalue,strlen(myvalue)); 145 EncodeUnicode(buffer,myvalue,strlen(myvalue));
146 fwrite(buffer,1,strlen(myvalue)*2,file); 146 fwrite(buffer,1,strlen(myvalue)*2,file);
147 } else fprintf(file,"%s",myvalue); 147 } else fprintf(file,"%s",myvalue);
148 } else { 148 } else {
149 if (UseUnicode) { 149 if (UseUnicode) {
150 sprintf(buffer,"%s = \"",myname); 150 sprintf(buffer,"%s = \"",myname);
151 EncodeUnicode(buffer2,buffer,strlen(buffer)); 151 EncodeUnicode(buffer2,buffer,strlen(buffer));
152 fwrite(buffer2,1,strlen(buffer)*2,file); 152 fwrite(buffer2,1,strlen(buffer)*2,file);
153 153
154 fwrite(myvalue,1,UnicodeLength(myvalue)*2,file); 154 fwrite(EncodeUnicodeSpecialChars(myvalue),1,UnicodeLength(EncodeUnicodeSpecialChars(myvalue))*2,file);
155 155
156 sprintf(buffer,"\"%c%c",13,10); 156 sprintf(buffer,"\"%c%c",13,10);
157 EncodeUnicode(buffer2,buffer,strlen(buffer)); 157 EncodeUnicode(buffer2,buffer,strlen(buffer));
158 fwrite(buffer2,1,strlen(buffer)*2,file); 158 fwrite(buffer2,1,strlen(buffer)*2,file);
159 } else { 159 } else {
160 sprintf(buffer,"%s = \"%s\"%c%c",myname,DecodeUnicodeString(myvalue),13,10); 160 sprintf(buffer,"%s = \"%s\"%c%c",myname,EncodeSpecialChars(DecodeUnicodeString(myvalue)),13,10);
161 fprintf(file,"%s",buffer); 161 fprintf(file,"%s",buffer);
162 162
163 EncodeHexBin(buffer,myvalue,UnicodeLength(myvalue)*2); 163 EncodeHexBin(buffer,myvalue,UnicodeLength(myvalue)*2);
164 fprintf(file,"%sUnicode = %s%c%c",myname,buffer,13,10); 164 fprintf(file,"%sUnicode = %s%c%c",myname,buffer,13,10);
165 } 165 }
166 } 166 }
167} 167}
168 168
169static bool ReadBackupText(INI_Section *file_info, char *section, char *myname, char *myvalue, bool UseUnicode) 169static bool ReadBackupText(INI_Section *file_info, char *section, char *myname, char *myvalue, bool UseUnicode)
170{ 170{
171 unsigned char paramname[10000],*readvalue; 171 unsigned char paramname[10000],*readvalue;
172 172
173 if (UseUnicode) { 173 if (UseUnicode) {
174 EncodeUnicode(paramname,myname,strlen(myname)); 174 EncodeUnicode(paramname,myname,strlen(myname));
175 readvalue = INI_GetValue(file_info, section, paramname, UseUnicode); 175 readvalue = INI_GetValue(file_info, section, paramname, UseUnicode);
176 if (readvalue!=NULL) { 176 if (readvalue!=NULL) {
177 CopyUnicodeString(myvalue,readvalue+2); 177 CopyUnicodeString(myvalue,DecodeUnicodeSpecialChars(readvalue+2));
178 myvalue[UnicodeLength(readvalue)*2-4]=0; 178 myvalue[UnicodeLength(myvalue)*2-2]=0;
179 myvalue[UnicodeLength(readvalue)*2-3]=0; 179 myvalue[UnicodeLength(myvalue)*2-1]=0;
180
180 dbgprintf("%s\n",DecodeUnicodeString(readvalue)); 181 dbgprintf("%s\n",DecodeUnicodeString(readvalue));
181 } else { 182 } else {
182 myvalue[0]=0; 183 myvalue[0]=0;
183 myvalue[1]=0; 184 myvalue[1]=0;
184 return false; 185 return false;
185 } 186 }
186 } else { 187 } else {
187 strcpy(paramname,myname); 188 strcpy(paramname,myname);
188 strcat(paramname,"Unicode"); 189 strcat(paramname,"Unicode");
189 readvalue = ReadCFGText(file_info, section, paramname, UseUnicode); 190 readvalue = ReadCFGText(file_info, section, paramname, UseUnicode);
190 if (readvalue!=NULL) { 191 if (readvalue!=NULL) {
191 dbgprintf("%s %i\n",readvalue,strlen(readvalue)); 192 dbgprintf("%s %i\n",readvalue,strlen(readvalue));
192 DecodeHexBin (myvalue, readvalue, strlen(readvalue)); 193 DecodeHexBin (myvalue, readvalue, strlen(readvalue));
193 myvalue[strlen(readvalue)/2]=0; 194 myvalue[strlen(readvalue)/2]=0;
194 myvalue[strlen(readvalue)/2+1]=0; 195 myvalue[strlen(readvalue)/2+1]=0;
195 dbgprintf("%s\n",DecodeUnicodeString(myvalue)); 196 dbgprintf("%s\n",DecodeUnicodeString(myvalue));
196 } else { 197 } else {
197 strcpy(paramname,myname); 198 strcpy(paramname,myname);
198 readvalue = ReadCFGText(file_info, section, paramname, UseUnicode); 199 readvalue = ReadCFGText(file_info, section, paramname, UseUnicode);
199 if (readvalue!=NULL) { 200 if (readvalue!=NULL) {
200 EncodeUnicode(myvalue,readvalue+1,strlen(readvalue)-2); 201 EncodeUnicode(myvalue,DecodeSpecialChars(readvalue+1),strlen(DecodeSpecialChars(readvalue+1))-1);
201 } else { 202 } else {
202 myvalue[0]=0; 203 myvalue[0]=0;
203 myvalue[1]=0; 204 myvalue[1]=0;
204 return false; 205 return false;
205 } 206 }
206 } 207 }
207 } 208 }
208 return true; 209 return true;
209} 210}
210 211
211static void SaveVCalDateTime(FILE *file, GSM_DateTime *dt, bool UseUnicode) 212static void SaveVCalDateTime(FILE *file, GSM_DateTime *dt, bool UseUnicode)
212{ 213{
213 unsigned char buffer[100]; 214 unsigned char buffer[100];
214 int Length = 3; 215 int Length = 3;
215 216
216 sprintf(buffer, " = "); 217 sprintf(buffer, " = ");
217 SaveVCALDateTime(buffer, &Length, dt, NULL); 218 SaveVCALDateTime(buffer, &Length, dt, NULL);
218 SaveBackupText(file, "", buffer, UseUnicode); 219 SaveBackupText(file, "", buffer, UseUnicode);
219} 220}
220 221
221static void SaveVCalDate(FILE *file, GSM_DateTime *dt, bool UseUnicode) 222static void SaveVCalDate(FILE *file, GSM_DateTime *dt, bool UseUnicode)
222{ 223{
223 unsigned char buffer[100]; 224 unsigned char buffer[100];
224 225
225 sprintf(buffer, " = %04d%02d%02d%c%c", dt->Year, dt->Month, dt->Day,13,10); 226 sprintf(buffer, " = %04d%02d%02d%c%c", dt->Year, dt->Month, dt->Day,13,10);
226 SaveBackupText(file, "", buffer, UseUnicode); 227 SaveBackupText(file, "", buffer, UseUnicode);
227} 228}
228 229
229/* ---------------------- backup files ------------------------------------- */ 230/* ---------------------- backup files ------------------------------------- */
230 231
231static void SavePbkEntry(FILE *file, GSM_MemoryEntry *Pbk, bool UseUnicode) 232static void SavePbkEntry(FILE *file, GSM_MemoryEntry *Pbk, bool UseUnicode)
232{ 233{
233 booltext; 234 booltext;
234 charbuffer[1000]; 235 charbuffer[1000];
235 intj, i; 236 intj, i;
236 237
237 sprintf(buffer,"Location = %03i%c%c",Pbk->Location,13,10); 238 sprintf(buffer,"Location = %03i%c%c",Pbk->Location,13,10);
238 SaveBackupText(file, "", buffer, UseUnicode); 239 SaveBackupText(file, "", buffer, UseUnicode);
239 for (j=0;j<Pbk->EntriesNum;j++) { 240 for (j=0;j<Pbk->EntriesNum;j++) {
240 text = true; 241 text = true;
241 switch (Pbk->Entries[j].EntryType) { 242 switch (Pbk->Entries[j].EntryType) {
242 case PBK_Number_General: 243 case PBK_Number_General:
243 sprintf(buffer,"Entry%02iType = NumberGeneral%c%c",j,13,10); 244 sprintf(buffer,"Entry%02iType = NumberGeneral%c%c",j,13,10);
244 SaveBackupText(file, "", buffer, UseUnicode); 245 SaveBackupText(file, "", buffer, UseUnicode);
245 break; 246 break;
246 case PBK_Number_Mobile: 247 case PBK_Number_Mobile:
247 sprintf(buffer,"Entry%02iType = NumberMobile%c%c",j,13,10); 248 sprintf(buffer,"Entry%02iType = NumberMobile%c%c",j,13,10);
248 SaveBackupText(file, "", buffer, UseUnicode); 249 SaveBackupText(file, "", buffer, UseUnicode);
249 break; 250 break;
250 case PBK_Number_Work: 251 case PBK_Number_Work:
251 sprintf(buffer,"Entry%02iType = NumberWork%c%c",j,13,10); 252 sprintf(buffer,"Entry%02iType = NumberWork%c%c",j,13,10);
252 SaveBackupText(file, "", buffer, UseUnicode); 253 SaveBackupText(file, "", buffer, UseUnicode);
253 break; 254 break;
254 case PBK_Number_Fax: 255 case PBK_Number_Fax:
255 sprintf(buffer,"Entry%02iType = NumberFax%c%c",j,13,10); 256 sprintf(buffer,"Entry%02iType = NumberFax%c%c",j,13,10);
256 SaveBackupText(file, "", buffer, UseUnicode); 257 SaveBackupText(file, "", buffer, UseUnicode);
257 break; 258 break;
258 case PBK_Number_Home: 259 case PBK_Number_Home:
259 sprintf(buffer,"Entry%02iType = NumberHome%c%c",j,13,10); 260 sprintf(buffer,"Entry%02iType = NumberHome%c%c",j,13,10);
260 SaveBackupText(file, "", buffer, UseUnicode); 261 SaveBackupText(file, "", buffer, UseUnicode);
261 break; 262 break;
262 case PBK_Number_Pager: 263 case PBK_Number_Pager:
263 sprintf(buffer,"Entry%02iType = NumberPager%c%c",j,13,10); 264 sprintf(buffer,"Entry%02iType = NumberPager%c%c",j,13,10);
264 SaveBackupText(file, "", buffer, UseUnicode); 265 SaveBackupText(file, "", buffer, UseUnicode);
265 break; 266 break;
266 case PBK_Number_Other: 267 case PBK_Number_Other:
267 sprintf(buffer,"Entry%02iType = NumberOther%c%c",j,13,10); 268 sprintf(buffer,"Entry%02iType = NumberOther%c%c",j,13,10);
268 SaveBackupText(file, "", buffer, UseUnicode); 269 SaveBackupText(file, "", buffer, UseUnicode);
269 break; 270 break;
270 case PBK_Text_Note: 271 case PBK_Text_Note:
271 sprintf(buffer,"Entry%02iType = Note%c%c",j,13,10); 272 sprintf(buffer,"Entry%02iType = Note%c%c",j,13,10);
272 SaveBackupText(file, "", buffer, UseUnicode); 273 SaveBackupText(file, "", buffer, UseUnicode);
273 break; 274 break;
274 case PBK_Text_Postal: 275 case PBK_Text_Postal:
275 sprintf(buffer,"Entry%02iType = Postal%c%c",j,13,10); 276 sprintf(buffer,"Entry%02iType = Postal%c%c",j,13,10);
276 SaveBackupText(file, "", buffer, UseUnicode); 277 SaveBackupText(file, "", buffer, UseUnicode);
277 break; 278 break;
278 case PBK_Text_Email: 279 case PBK_Text_Email:
279 sprintf(buffer,"Entry%02iType = Email%c%c",j,13,10); 280 sprintf(buffer,"Entry%02iType = Email%c%c",j,13,10);
280 SaveBackupText(file, "", buffer, UseUnicode); 281 SaveBackupText(file, "", buffer, UseUnicode);
281 break; 282 break;
282 case PBK_Text_Email2: 283 case PBK_Text_Email2:
283 sprintf(buffer,"Entry%02iType = Email2%c%c",j,13,10); 284 sprintf(buffer,"Entry%02iType = Email2%c%c",j,13,10);
284 SaveBackupText(file, "", buffer, UseUnicode); 285 SaveBackupText(file, "", buffer, UseUnicode);
285 break; 286 break;
286 case PBK_Text_URL: 287 case PBK_Text_URL:
287 sprintf(buffer,"Entry%02iType = URL%c%c",j,13,10); 288 sprintf(buffer,"Entry%02iType = URL%c%c",j,13,10);
288 SaveBackupText(file, "", buffer, UseUnicode); 289 SaveBackupText(file, "", buffer, UseUnicode);
289 break; 290 break;
290 case PBK_Text_Name: 291 case PBK_Text_Name:
291 sprintf(buffer,"Entry%02iType = Name%c%c",j,13,10); 292 sprintf(buffer,"Entry%02iType = Name%c%c",j,13,10);
292 SaveBackupText(file, "", buffer, UseUnicode); 293 SaveBackupText(file, "", buffer, UseUnicode);
293 break; 294 break;
294 case PBK_Caller_Group: 295 case PBK_Caller_Group:
295 sprintf(buffer,"Entry%02iType = CallerGroup%c%c",j,13,10); 296 sprintf(buffer,"Entry%02iType = CallerGroup%c%c",j,13,10);
296 SaveBackupText(file, "", buffer, UseUnicode); 297 SaveBackupText(file, "", buffer, UseUnicode);
297 sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10); 298 sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10);
298 SaveBackupText(file, "", buffer, UseUnicode); 299 SaveBackupText(file, "", buffer, UseUnicode);
299 text = false; 300 text = false;
300 break; 301 break;
301 case PBK_RingtoneID: 302 case PBK_RingtoneID:
302 sprintf(buffer,"Entry%02iType = RingtoneID%c%c",j,13,10); 303 sprintf(buffer,"Entry%02iType = RingtoneID%c%c",j,13,10);
303 SaveBackupText(file, "", buffer, UseUnicode); 304 SaveBackupText(file, "", buffer, UseUnicode);
304 sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10); 305 sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10);
305 SaveBackupText(file, "", buffer, UseUnicode); 306 SaveBackupText(file, "", buffer, UseUnicode);
306 text = false; 307 text = false;
307 break; 308 break;
308 case PBK_PictureID: 309 case PBK_PictureID:
309 sprintf(buffer,"Entry%02iType = PictureID%c%c",j,13,10); 310 sprintf(buffer,"Entry%02iType = PictureID%c%c",j,13,10);
310 SaveBackupText(file, "", buffer, UseUnicode); 311 SaveBackupText(file, "", buffer, UseUnicode);
311 sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10); 312 sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10);
312 SaveBackupText(file, "", buffer, UseUnicode); 313 SaveBackupText(file, "", buffer, UseUnicode);
313 text = false; 314 text = false;
314 break; 315 break;
315 case PBK_Text_UserID: 316 case PBK_Text_UserID:
316 sprintf(buffer,"Entry%02iType = UserID%c%c",j,13,10); 317 sprintf(buffer,"Entry%02iType = UserID%c%c",j,13,10);
317 SaveBackupText(file, "", buffer, UseUnicode); 318 SaveBackupText(file, "", buffer, UseUnicode);
318 break; 319 break;
319 case PBK_Category: 320 case PBK_Category:
320 sprintf(buffer,"Entry%02iType = Category%c%c",j,13,10); 321 sprintf(buffer,"Entry%02iType = Category%c%c",j,13,10);
321 SaveBackupText(file, "", buffer, UseUnicode); 322 SaveBackupText(file, "", buffer, UseUnicode);
322 sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10); 323 sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10);
323 SaveBackupText(file, "", buffer, UseUnicode); 324 SaveBackupText(file, "", buffer, UseUnicode);
324 text = false; 325 text = false;
325 break; 326 break;
326 case PBK_Private: 327 case PBK_Private:
327 sprintf(buffer,"Entry%02iType = Private%c%c",j,13,10); 328 sprintf(buffer,"Entry%02iType = Private%c%c",j,13,10);
328 SaveBackupText(file, "", buffer, UseUnicode); 329 SaveBackupText(file, "", buffer, UseUnicode);
329 sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10); 330 sprintf(buffer,"Entry%02iNumber = %i%c%c",j,Pbk->Entries[j].Number,13,10);
330 SaveBackupText(file, "", buffer, UseUnicode); 331 SaveBackupText(file, "", buffer, UseUnicode);
331 text = false; 332 text = false;
332 break; 333 break;
333 case PBK_Text_LastName: 334 case PBK_Text_LastName:
334 sprintf(buffer,"Entry%02iType = LastName%c%c",j,13,10); 335 sprintf(buffer,"Entry%02iType = LastName%c%c",j,13,10);
335 SaveBackupText(file, "", buffer, UseUnicode); 336 SaveBackupText(file, "", buffer, UseUnicode);
336 break; 337 break;
337 case PBK_Text_FirstName: 338 case PBK_Text_FirstName:
338 sprintf(buffer,"Entry%02iType = FirstName%c%c",j,13,10); 339 sprintf(buffer,"Entry%02iType = FirstName%c%c",j,13,10);
339 SaveBackupText(file, "", buffer, UseUnicode); 340 SaveBackupText(file, "", buffer, UseUnicode);
340 break; 341 break;
341 case PBK_Text_Company: 342 case PBK_Text_Company:
342 sprintf(buffer,"Entry%02iType = Company%c%c",j,13,10); 343 sprintf(buffer,"Entry%02iType = Company%c%c",j,13,10);
343 SaveBackupText(file, "", buffer, UseUnicode); 344 SaveBackupText(file, "", buffer, UseUnicode);
344 break; 345 break;
345 case PBK_Text_JobTitle: 346 case PBK_Text_JobTitle:
346 sprintf(buffer,"Entry%02iType = JobTitle%c%c",j,13,10); 347 sprintf(buffer,"Entry%02iType = JobTitle%c%c",j,13,10);
347 SaveBackupText(file, "", buffer, UseUnicode); 348 SaveBackupText(file, "", buffer, UseUnicode);
348 break; 349 break;
349 case PBK_Text_StreetAddress: 350 case PBK_Text_StreetAddress:
350 sprintf(buffer,"Entry%02iType = Address%c%c",j,13,10); 351 sprintf(buffer,"Entry%02iType = Address%c%c",j,13,10);
351 SaveBackupText(file, "", buffer, UseUnicode); 352 SaveBackupText(file, "", buffer, UseUnicode);
352 break; 353 break;
353 case PBK_Text_City: 354 case PBK_Text_City:
354 sprintf(buffer,"Entry%02iType = City%c%c",j,13,10); 355 sprintf(buffer,"Entry%02iType = City%c%c",j,13,10);
355 SaveBackupText(file, "", buffer, UseUnicode); 356 SaveBackupText(file, "", buffer, UseUnicode);
356 break; 357 break;
357 case PBK_Text_State: 358 case PBK_Text_State:
358 sprintf(buffer,"Entry%02iType = State%c%c",j,13,10); 359 sprintf(buffer,"Entry%02iType = State%c%c",j,13,10);
359 SaveBackupText(file, "", buffer, UseUnicode); 360 SaveBackupText(file, "", buffer, UseUnicode);
360 break; 361 break;
361 case PBK_Text_Zip: 362 case PBK_Text_Zip:
362 sprintf(buffer,"Entry%02iType = Zip%c%c",j,13,10); 363 sprintf(buffer,"Entry%02iType = Zip%c%c",j,13,10);
363 SaveBackupText(file, "", buffer, UseUnicode); 364 SaveBackupText(file, "", buffer, UseUnicode);
364 break; 365 break;
365 case PBK_Text_Country: 366 case PBK_Text_Country:
366 sprintf(buffer,"Entry%02iType = Country%c%c",j,13,10); 367 sprintf(buffer,"Entry%02iType = Country%c%c",j,13,10);
367 SaveBackupText(file, "", buffer, UseUnicode); 368 SaveBackupText(file, "", buffer, UseUnicode);
368 break; 369 break;
369 case PBK_Text_Custom1: 370 case PBK_Text_Custom1:
370 sprintf(buffer,"Entry%02iType = Custom1%c%c",j,13,10); 371 sprintf(buffer,"Entry%02iType = Custom1%c%c",j,13,10);
371 SaveBackupText(file, "", buffer, UseUnicode); 372 SaveBackupText(file, "", buffer, UseUnicode);
372 break; 373 break;
373 case PBK_Text_Custom2: 374 case PBK_Text_Custom2:
374 sprintf(buffer,"Entry%02iType = Custom2%c%c",j,13,10); 375 sprintf(buffer,"Entry%02iType = Custom2%c%c",j,13,10);
375 SaveBackupText(file, "", buffer, UseUnicode); 376 SaveBackupText(file, "", buffer, UseUnicode);
376 break; 377 break;
377 case PBK_Text_Custom3: 378 case PBK_Text_Custom3:
378 sprintf(buffer,"Entry%02iType = Custom3%c%c",j,13,10); 379 sprintf(buffer,"Entry%02iType = Custom3%c%c",j,13,10);
379 SaveBackupText(file, "", buffer, UseUnicode); 380 SaveBackupText(file, "", buffer, UseUnicode);
380 break; 381 break;
381 case PBK_Text_Custom4: 382 case PBK_Text_Custom4:
382 sprintf(buffer,"Entry%02iType = Custom4%c%c",j,13,10); 383 sprintf(buffer,"Entry%02iType = Custom4%c%c",j,13,10);
383 SaveBackupText(file, "", buffer, UseUnicode); 384 SaveBackupText(file, "", buffer, UseUnicode);
384 break; 385 break;
385 case PBK_SMSListID: 386 case PBK_SMSListID:
386 case PBK_RingtoneFileSystemID: 387 case PBK_RingtoneFileSystemID:
387 case PBK_Date: 388 case PBK_Date:
388 break; 389 break;
389 } 390 }
390 if (text) { 391 if (text) {
391 sprintf(buffer,"Entry%02iText",j); 392 sprintf(buffer,"Entry%02iText",j);
392 SaveBackupText(file,buffer,Pbk->Entries[j].Text, UseUnicode); 393 SaveBackupText(file,buffer,Pbk->Entries[j].Text, UseUnicode);
393 } 394 }
394 switch (Pbk->Entries[j].EntryType) { 395 switch (Pbk->Entries[j].EntryType) {
395 case PBK_Number_General: 396 case PBK_Number_General:
396 case PBK_Number_Mobile: 397 case PBK_Number_Mobile:
397 case PBK_Number_Work: 398 case PBK_Number_Work:
398 case PBK_Number_Fax: 399 case PBK_Number_Fax:
399 case PBK_Number_Home: 400 case PBK_Number_Home:
400 case PBK_Number_Other: 401 case PBK_Number_Other:
401 case PBK_Number_Pager: 402 case PBK_Number_Pager:
402 if (Pbk->Entries[j].VoiceTag!=0) { 403 if (Pbk->Entries[j].VoiceTag!=0) {
403 sprintf(buffer,"Entry%02iVoiceTag = %i%c%c",j,Pbk->Entries[j].VoiceTag,13,10); 404 sprintf(buffer,"Entry%02iVoiceTag = %i%c%c",j,Pbk->Entries[j].VoiceTag,13,10);
404 SaveBackupText(file, "", buffer, UseUnicode); 405 SaveBackupText(file, "", buffer, UseUnicode);
405 } 406 }
406 i = 0; 407 i = 0;
407 while (Pbk->Entries[j].SMSList[i]!=0) { 408 while (Pbk->Entries[j].SMSList[i]!=0) {
408 sprintf(buffer,"Entry%02iSMSList%02i = %i%c%c",j,i,Pbk->Entries[j].SMSList[i],13,10); 409 sprintf(buffer,"Entry%02iSMSList%02i = %i%c%c",j,i,Pbk->Entries[j].SMSList[i],13,10);
409 SaveBackupText(file, "", buffer, UseUnicode); 410 SaveBackupText(file, "", buffer, UseUnicode);
410 i++; 411 i++;
411 } 412 }
412 break; 413 break;
413 default: 414 default:
414 break; 415 break;
415 } 416 }
416 } 417 }
417 sprintf(buffer,"%c%c",13,10); 418 sprintf(buffer,"%c%c",13,10);
418 SaveBackupText(file, "", buffer, UseUnicode); 419 SaveBackupText(file, "", buffer, UseUnicode);
419} 420}
420 421
422static void SaveNoteEntry(FILE *file, GSM_NoteEntry *Note, bool UseUnicode)
423{
424 char buffer[1000];
425
426 sprintf(buffer,"Location = %d%c%c", Note->Location,13,10);
427 SaveBackupText(file, "", buffer, UseUnicode);
428 SaveBackupText(file, "Text", Note->Text, UseUnicode);
429 sprintf(buffer, "%c%c",13,10);
430 SaveBackupText(file, "", buffer, UseUnicode);
431}
432
421static void SaveCalendarEntry(FILE *file, GSM_CalendarEntry *Note, bool UseUnicode) 433static void SaveCalendarEntry(FILE *file, GSM_CalendarEntry *Note, bool UseUnicode)
422{ 434{
423 int i; 435 int i;
424 charbuffer[1000]; 436 charbuffer[1000];
425 437
426 sprintf(buffer,"Location = %d%c%c", Note->Location,13,10); 438 sprintf(buffer,"Location = %d%c%c", Note->Location,13,10);
427 SaveBackupText(file, "", buffer, UseUnicode); 439 SaveBackupText(file, "", buffer, UseUnicode);
428 SaveBackupText(file, "", "Type = ", UseUnicode); 440 SaveBackupText(file, "", "Type = ", UseUnicode);
429 switch (Note->Type) { 441 switch (Note->Type) {
430 case GSM_CAL_REMINDER : sprintf(buffer,"Reminder%c%c", 13,10); break; 442 case GSM_CAL_REMINDER : sprintf(buffer,"Reminder%c%c", 13,10); break;
431 case GSM_CAL_CALL : sprintf(buffer,"Call%c%c", 13,10); break; 443 case GSM_CAL_CALL : sprintf(buffer,"Call%c%c", 13,10); break;
432 case GSM_CAL_MEETING : sprintf(buffer,"Meeting%c%c", 13,10); break; 444 case GSM_CAL_MEETING : sprintf(buffer,"Meeting%c%c", 13,10); break;
433 case GSM_CAL_BIRTHDAY : sprintf(buffer,"Birthday%c%c", 13,10); break; 445 case GSM_CAL_BIRTHDAY : sprintf(buffer,"Birthday%c%c", 13,10); break;
434 case GSM_CAL_TRAVEL : sprintf(buffer,"Travel%c%c", 13,10); break; 446 case GSM_CAL_TRAVEL : sprintf(buffer,"Travel%c%c", 13,10); break;
435 case GSM_CAL_VACATION : sprintf(buffer,"Vacation%c%c", 13,10); break; 447 case GSM_CAL_VACATION : sprintf(buffer,"Vacation%c%c", 13,10); break;
436 case GSM_CAL_MEMO : sprintf(buffer,"Memo%c%c", 13,10); break; 448 case GSM_CAL_MEMO : sprintf(buffer,"Memo%c%c", 13,10); break;
437 case GSM_CAL_ALARM : sprintf(buffer,"Alarm%c%c", 13,10); break; 449 case GSM_CAL_ALARM : sprintf(buffer,"Alarm%c%c", 13,10); break;
438 case GSM_CAL_DAILY_ALARM : sprintf(buffer,"DailyAlarm%c%c", 13,10); break; 450 case GSM_CAL_DAILY_ALARM: sprintf(buffer,"DailyAlarm%c%c", 13,10); break;
439 case GSM_CAL_T_ATHL : sprintf(buffer,"Training/Athletism%c%c", 13,10); break; 451 case GSM_CAL_T_ATHL : sprintf(buffer,"Training/Athletism%c%c", 13,10); break;
440 case GSM_CAL_T_BALL : sprintf(buffer,"Training/BallGames%c%c", 13,10); break; 452 case GSM_CAL_T_BALL : sprintf(buffer,"Training/BallGames%c%c", 13,10); break;
441 case GSM_CAL_T_CYCL : sprintf(buffer,"Training/Cycling%c%c", 13,10); break; 453 case GSM_CAL_T_CYCL : sprintf(buffer,"Training/Cycling%c%c", 13,10); break;
442 case GSM_CAL_T_BUDO : sprintf(buffer,"Training/Budo%c%c", 13,10); break; 454 case GSM_CAL_T_BUDO : sprintf(buffer,"Training/Budo%c%c", 13,10); break;
443 case GSM_CAL_T_DANC : sprintf(buffer,"Training/Dance%c%c", 13,10); break; 455 case GSM_CAL_T_DANC : sprintf(buffer,"Training/Dance%c%c", 13,10); break;
444 case GSM_CAL_T_EXTR : sprintf(buffer,"Training/ExtremeSports%c%c", 13,10); break; 456 case GSM_CAL_T_EXTR : sprintf(buffer,"Training/ExtremeSports%c%c", 13,10); break;
445 case GSM_CAL_T_FOOT : sprintf(buffer,"Training/Football%c%c", 13,10); break; 457 case GSM_CAL_T_FOOT : sprintf(buffer,"Training/Football%c%c", 13,10); break;
446 case GSM_CAL_T_GOLF : sprintf(buffer,"Training/Golf%c%c", 13,10); break; 458 case GSM_CAL_T_GOLF : sprintf(buffer,"Training/Golf%c%c", 13,10); break;
447 case GSM_CAL_T_GYM : sprintf(buffer,"Training/Gym%c%c", 13,10); break; 459 case GSM_CAL_T_GYM : sprintf(buffer,"Training/Gym%c%c", 13,10); break;
448 case GSM_CAL_T_HORS : sprintf(buffer,"Training/HorseRaces%c%c", 13,10); break; 460 case GSM_CAL_T_HORS : sprintf(buffer,"Training/HorseRaces%c%c", 13,10); break;
449 case GSM_CAL_T_HOCK : sprintf(buffer,"Training/Hockey%c%c", 13,10); break; 461 case GSM_CAL_T_HOCK : sprintf(buffer,"Training/Hockey%c%c", 13,10); break;
450 case GSM_CAL_T_RACE : sprintf(buffer,"Training/Races%c%c", 13,10); break; 462 case GSM_CAL_T_RACE : sprintf(buffer,"Training/Races%c%c", 13,10); break;
451 case GSM_CAL_T_RUGB : sprintf(buffer,"Training/Rugby%c%c", 13,10); break; 463 case GSM_CAL_T_RUGB : sprintf(buffer,"Training/Rugby%c%c", 13,10); break;
452 case GSM_CAL_T_SAIL : sprintf(buffer,"Training/Sailing%c%c", 13,10); break; 464 case GSM_CAL_T_SAIL : sprintf(buffer,"Training/Sailing%c%c", 13,10); break;
453 case GSM_CAL_T_STRE : sprintf(buffer,"Training/StreetGames%c%c",13,10); break; 465 case GSM_CAL_T_STRE : sprintf(buffer,"Training/StreetGames%c%c",13,10); break;
454 case GSM_CAL_T_SWIM : sprintf(buffer,"Training/Swimming%c%c", 13,10); break; 466 case GSM_CAL_T_SWIM : sprintf(buffer,"Training/Swimming%c%c", 13,10); break;
455 case GSM_CAL_T_TENN : sprintf(buffer,"Training/Tennis%c%c", 13,10); break; 467 case GSM_CAL_T_TENN : sprintf(buffer,"Training/Tennis%c%c", 13,10); break;
456 case GSM_CAL_T_TRAV : sprintf(buffer,"Training/Travels%c%c", 13,10); break; 468 case GSM_CAL_T_TRAV : sprintf(buffer,"Training/Travels%c%c", 13,10); break;
457 case GSM_CAL_T_WINT : sprintf(buffer,"Training/WinterGames%c%c", 13,10); break; 469 case GSM_CAL_T_WINT : sprintf(buffer,"Training/WinterGames%c%c", 13,10); break;
458 } 470 }
459 SaveBackupText(file, "", buffer, UseUnicode); 471 SaveBackupText(file, "", buffer, UseUnicode);
460 for (i=0;i<Note->EntriesNum;i++) { 472 for (i=0;i<Note->EntriesNum;i++) {
461 switch (Note->Entries[i].EntryType) { 473 switch (Note->Entries[i].EntryType) {
462 case CAL_START_DATETIME: 474 case CAL_START_DATETIME:
463 SaveBackupText(file, "", "StartTime", UseUnicode); 475 SaveBackupText(file, "", "StartTime", UseUnicode);
464 SaveVCalDateTime(file, &Note->Entries[i].Date, UseUnicode); 476 SaveVCalDateTime(file, &Note->Entries[i].Date, UseUnicode);
465 break; 477 break;
466 case CAL_END_DATETIME: 478 case CAL_END_DATETIME:
467 SaveBackupText(file, "", "StopTime", UseUnicode); 479 SaveBackupText(file, "", "StopTime", UseUnicode);
468 SaveVCalDateTime(file, &Note->Entries[i].Date, UseUnicode); 480 SaveVCalDateTime(file, &Note->Entries[i].Date, UseUnicode);
469 break; 481 break;
470 case CAL_ALARM_DATETIME: 482 case CAL_ALARM_DATETIME:
471 SaveBackupText(file, "", "Alarm", UseUnicode); 483 SaveBackupText(file, "", "Alarm", UseUnicode);
472 SaveVCalDateTime(file, &Note->Entries[i].Date, UseUnicode); 484 SaveVCalDateTime(file, &Note->Entries[i].Date, UseUnicode);
473 sprintf(buffer,"AlarmType = Tone%c%c",13,10); 485 sprintf(buffer,"AlarmType = Tone%c%c",13,10);
474 SaveBackupText(file, "", buffer, UseUnicode); 486 SaveBackupText(file, "", buffer, UseUnicode);
475 break; 487 break;
476 case CAL_SILENT_ALARM_DATETIME: 488 case CAL_SILENT_ALARM_DATETIME:
477 SaveBackupText(file, "", "Alarm", UseUnicode); 489 SaveBackupText(file, "", "Alarm", UseUnicode);
478 SaveVCalDateTime(file, &Note->Entries[i].Date, UseUnicode); 490 SaveVCalDateTime(file, &Note->Entries[i].Date, UseUnicode);
479 sprintf(buffer,"AlarmType = Silent%c%c",13,10); 491 sprintf(buffer,"AlarmType = Silent%c%c",13,10);
480 SaveBackupText(file, "", buffer, UseUnicode); 492 SaveBackupText(file, "", buffer, UseUnicode);
481 break; 493 break;
482 case CAL_PRIVATE: 494 case CAL_PRIVATE:
483 sprintf(buffer, "Private = %d%c%c",Note->Entries[i].Number,13,10); 495 sprintf(buffer, "Private = %d%c%c",Note->Entries[i].Number,13,10);
484 SaveBackupText(file, "", buffer, UseUnicode); 496 SaveBackupText(file, "", buffer, UseUnicode);
485 break; 497 break;
486 case CAL_LOCATION: 498 case CAL_LOCATION:
487 SaveBackupText(file, "EventLocation", Note->Entries[i].Text, UseUnicode); 499 SaveBackupText(file, "EventLocation", Note->Entries[i].Text, UseUnicode);
488 break; 500 break;
489 case CAL_CONTACTID: 501 case CAL_CONTACTID:
490 sprintf(buffer, "ContactID = %d%c%c",Note->Entries[i].Number,13,10); 502 sprintf(buffer, "ContactID = %d%c%c",Note->Entries[i].Number,13,10);
491 SaveBackupText(file, "", buffer, UseUnicode); 503 SaveBackupText(file, "", buffer, UseUnicode);
492 break; 504 break;
493 case CAL_RECURRANCE: 505 case CAL_RECURRANCE:
494 sprintf(buffer, "Recurrance = %d%c%c",Note->Entries[i].Number/24,13,10); 506 sprintf(buffer, "Recurrance = %d%c%c",Note->Entries[i].Number/24,13,10);
495 SaveBackupText(file, "", buffer, UseUnicode); 507 SaveBackupText(file, "", buffer, UseUnicode);
496 break; 508 break;
497 case CAL_TEXT: 509 case CAL_TEXT:
498 SaveBackupText(file, "Text", Note->Entries[i].Text, UseUnicode); 510 SaveBackupText(file, "Text", Note->Entries[i].Text, UseUnicode);
499 break; 511 break;
500 case CAL_PHONE: 512 case CAL_PHONE:
501 SaveBackupText(file, "Phone", Note->Entries[i].Text, UseUnicode); 513 SaveBackupText(file, "Phone", Note->Entries[i].Text, UseUnicode);
502 break; 514 break;
503 case CAL_REPEAT_STOPDATE: 515 case CAL_REPEAT_STOPDATE:
504 SaveBackupText(file, "", "RepeatStopDate", UseUnicode); 516 SaveBackupText(file, "", "RepeatStopDate", UseUnicode);
505 SaveVCalDate(file, &Note->Entries[i].Date, UseUnicode); 517 SaveVCalDate(file, &Note->Entries[i].Date, UseUnicode);
506 break; 518 break;
507 case CAL_REPEAT_STARTDATE: 519 case CAL_REPEAT_STARTDATE:
508 SaveBackupText(file, "", "RepeatStartDate", UseUnicode); 520 SaveBackupText(file, "", "RepeatStartDate", UseUnicode);
509 SaveVCalDate(file, &Note->Entries[i].Date, UseUnicode); 521 SaveVCalDate(file, &Note->Entries[i].Date, UseUnicode);
510 break; 522 break;
511 case CAL_REPEAT_DAYOFWEEK: 523 case CAL_REPEAT_DAYOFWEEK:
512 sprintf(buffer, "RepeatDayOfWeek = %d%c%c",Note->Entries[i].Number,13,10); 524 sprintf(buffer, "RepeatDayOfWeek = %d%c%c",Note->Entries[i].Number,13,10);
513 SaveBackupText(file, "", buffer, UseUnicode); 525 SaveBackupText(file, "", buffer, UseUnicode);
514 break; 526 break;
515 case CAL_REPEAT_DAY: 527 case CAL_REPEAT_DAY:
516 sprintf(buffer, "RepeatDay = %d%c%c",Note->Entries[i].Number,13,10); 528 sprintf(buffer, "RepeatDay = %d%c%c",Note->Entries[i].Number,13,10);
517 SaveBackupText(file, "", buffer, UseUnicode); 529 SaveBackupText(file, "", buffer, UseUnicode);
518 break; 530 break;
519 case CAL_REPEAT_WEEKOFMONTH: 531 case CAL_REPEAT_WEEKOFMONTH:
520 sprintf(buffer, "RepeatWeekOfMonth = %d%c%c",Note->Entries[i].Number,13,10); 532 sprintf(buffer, "RepeatWeekOfMonth = %d%c%c",Note->Entries[i].Number,13,10);
521 SaveBackupText(file, "", buffer, UseUnicode); 533 SaveBackupText(file, "", buffer, UseUnicode);
522 break; 534 break;
523 case CAL_REPEAT_MONTH: 535 case CAL_REPEAT_MONTH:
524 sprintf(buffer, "RepeatMonth = %d%c%c",Note->Entries[i].Number,13,10); 536 sprintf(buffer, "RepeatMonth = %d%c%c",Note->Entries[i].Number,13,10);
525 SaveBackupText(file, "", buffer, UseUnicode); 537 SaveBackupText(file, "", buffer, UseUnicode);
526 break; 538 break;
527 case CAL_REPEAT_FREQUENCY: 539 case CAL_REPEAT_FREQUENCY:
528 sprintf(buffer, "RepeatFrequency = %d%c%c",Note->Entries[i].Number,13,10); 540 sprintf(buffer, "RepeatFrequency = %d%c%c",Note->Entries[i].Number,13,10);
529 SaveBackupText(file, "", buffer, UseUnicode); 541 SaveBackupText(file, "", buffer, UseUnicode);
530 break; 542 break;
531 } 543 }
532 } 544 }
533 sprintf(buffer, "%c%c",13,10); 545 sprintf(buffer, "%c%c",13,10);
534 SaveBackupText(file, "", buffer, UseUnicode); 546 SaveBackupText(file, "", buffer, UseUnicode);
535} 547}
536 548
537static void SaveWAPSettingsEntry(FILE *file, GSM_MultiWAPSettings *settings, bool UseUnicode) 549static void SaveWAPSettingsEntry(FILE *file, GSM_MultiWAPSettings *settings, bool UseUnicode)
538{ 550{
539 int i; 551 int i;
540 char buffer[10000]; 552 char buffer[10000];
541 553
542 if (settings->Active) { 554 if (settings->Active) {
543 sprintf(buffer,"Active = Yes%c%c",13,10); 555 sprintf(buffer,"Active = Yes%c%c",13,10);
544 SaveBackupText(file, "", buffer, UseUnicode); 556 SaveBackupText(file, "", buffer, UseUnicode);
545 } 557 }
546 switch (settings->ActiveBearer) { 558 switch (settings->ActiveBearer) {
547 case WAPSETTINGS_BEARER_SMS : sprintf(buffer,"Bearer = SMS%c%c",13,10); break; 559 case WAPSETTINGS_BEARER_SMS : sprintf(buffer,"Bearer = SMS%c%c",13,10); break;
548 case WAPSETTINGS_BEARER_GPRS: sprintf(buffer,"Bearer = GPRS%c%c",13,10); break; 560 case WAPSETTINGS_BEARER_GPRS: sprintf(buffer,"Bearer = GPRS%c%c",13,10); break;
549 case WAPSETTINGS_BEARER_DATA: sprintf(buffer,"Bearer = Data%c%c",13,10); break; 561 case WAPSETTINGS_BEARER_DATA: sprintf(buffer,"Bearer = Data%c%c",13,10); break;
550 case WAPSETTINGS_BEARER_USSD: sprintf(buffer,"Bearer = USSD%c%c",13,10); 562 case WAPSETTINGS_BEARER_USSD: sprintf(buffer,"Bearer = USSD%c%c",13,10);
551 } 563 }
552 SaveBackupText(file, "", buffer, UseUnicode); 564 SaveBackupText(file, "", buffer, UseUnicode);
553 if (settings->ReadOnly) { 565 if (settings->ReadOnly) {
554 sprintf(buffer,"ReadOnly = Yes%c%c",13,10); 566 sprintf(buffer,"ReadOnly = Yes%c%c",13,10);
555 SaveBackupText(file, "", buffer, UseUnicode); 567 SaveBackupText(file, "", buffer, UseUnicode);
556 } 568 }
557 sprintf(buffer,"Proxy"); 569 sprintf(buffer,"Proxy");
558 SaveBackupText(file, buffer, settings->Proxy, UseUnicode); 570 SaveBackupText(file, buffer, settings->Proxy, UseUnicode);
559 sprintf(buffer,"ProxyPort = %i%c%c",settings->ProxyPort,13,10); 571 sprintf(buffer,"ProxyPort = %i%c%c",settings->ProxyPort,13,10);
560 SaveBackupText(file, "", buffer, UseUnicode); 572 SaveBackupText(file, "", buffer, UseUnicode);
561 sprintf(buffer,"Proxy2"); 573 sprintf(buffer,"Proxy2");
562 SaveBackupText(file, buffer, settings->Proxy2, UseUnicode); 574 SaveBackupText(file, buffer, settings->Proxy2, UseUnicode);
563 sprintf(buffer,"Proxy2Port = %i%c%c",settings->Proxy2Port,13,10); 575 sprintf(buffer,"Proxy2Port = %i%c%c",settings->Proxy2Port,13,10);
564 SaveBackupText(file, "", buffer, UseUnicode); 576 SaveBackupText(file, "", buffer, UseUnicode);
565 sprintf(buffer,"%c%c",13,10); 577 sprintf(buffer,"%c%c",13,10);
566 SaveBackupText(file, "", buffer, UseUnicode); 578 SaveBackupText(file, "", buffer, UseUnicode);
567 for (i=0;i<settings->Number;i++) { 579 for (i=0;i<settings->Number;i++) {
568 sprintf(buffer,"Title%02i",i); 580 sprintf(buffer,"Title%02i",i);
569 SaveBackupText(file, buffer, settings->Settings[i].Title, UseUnicode); 581 SaveBackupText(file, buffer, settings->Settings[i].Title, UseUnicode);
570 sprintf(buffer,"HomePage%02i",i); 582 sprintf(buffer,"HomePage%02i",i);
571 SaveBackupText(file, buffer, settings->Settings[i].HomePage, UseUnicode); 583 SaveBackupText(file, buffer, settings->Settings[i].HomePage, UseUnicode);
572 if (settings->Settings[i].IsContinuous) { 584 if (settings->Settings[i].IsContinuous) {
573 sprintf(buffer,"Type%02i = Continuous%c%c",i,13,10); 585 sprintf(buffer,"Type%02i = Continuous%c%c",i,13,10);
574 } else { 586 } else {
575 sprintf(buffer,"Type%02i = Temporary%c%c",i,13,10); 587 sprintf(buffer,"Type%02i = Temporary%c%c",i,13,10);
576 } 588 }
577 SaveBackupText(file, "", buffer, UseUnicode); 589 SaveBackupText(file, "", buffer, UseUnicode);
578 if (settings->Settings[i].IsSecurity) { 590 if (settings->Settings[i].IsSecurity) {
579 sprintf(buffer,"Security%02i = On%c%c",i,13,10); 591 sprintf(buffer,"Security%02i = On%c%c",i,13,10);
580 } else { 592 } else {
581 sprintf(buffer,"Security%02i = Off%c%c",i,13,10); 593 sprintf(buffer,"Security%02i = Off%c%c",i,13,10);
582 } 594 }
583 SaveBackupText(file, "", buffer, UseUnicode); 595 SaveBackupText(file, "", buffer, UseUnicode);
584 switch (settings->Settings[i].Bearer) { 596 switch (settings->Settings[i].Bearer) {
585 case WAPSETTINGS_BEARER_SMS: 597 case WAPSETTINGS_BEARER_SMS:
586 sprintf(buffer,"Bearer%02i = SMS%c%c",i,13,10); 598 sprintf(buffer,"Bearer%02i = SMS%c%c",i,13,10);
587 SaveBackupText(file, "", buffer, UseUnicode); 599 SaveBackupText(file, "", buffer, UseUnicode);
588 sprintf(buffer,"Server%02i",i); 600 sprintf(buffer,"Server%02i",i);
589 SaveBackupText(file, buffer, settings->Settings[i].Server, UseUnicode); 601 SaveBackupText(file, buffer, settings->Settings[i].Server, UseUnicode);
590 sprintf(buffer,"Service%02i",i); 602 sprintf(buffer,"Service%02i",i);
591 SaveBackupText(file, buffer, settings->Settings[i].Service, UseUnicode); 603 SaveBackupText(file, buffer, settings->Settings[i].Service, UseUnicode);
592 break; 604 break;
593 case WAPSETTINGS_BEARER_GPRS: 605 case WAPSETTINGS_BEARER_GPRS:
594 sprintf(buffer,"Bearer%02i = GPRS%c%c",i,13,10); 606 sprintf(buffer,"Bearer%02i = GPRS%c%c",i,13,10);
595 SaveBackupText(file, "", buffer, UseUnicode); 607 SaveBackupText(file, "", buffer, UseUnicode);
596 sprintf(buffer,"IP%02i",i); 608 sprintf(buffer,"IP%02i",i);
597 SaveBackupText(file, buffer, settings->Settings[i].IPAddress, UseUnicode); 609 SaveBackupText(file, buffer, settings->Settings[i].IPAddress, UseUnicode);
598 case WAPSETTINGS_BEARER_DATA: 610 case WAPSETTINGS_BEARER_DATA:
599 if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_DATA) { 611 if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_DATA) {
600 sprintf(buffer,"Bearer%02i = Data%c%c",i,13,10); 612 sprintf(buffer,"Bearer%02i = Data%c%c",i,13,10);
601 SaveBackupText(file, "", buffer, UseUnicode); 613 SaveBackupText(file, "", buffer, UseUnicode);
602 if (settings->Settings[i].IsISDNCall) { 614 if (settings->Settings[i].IsISDNCall) {
603 sprintf(buffer,"CallType%02i = ISDN%c%c",i,13,10); 615 sprintf(buffer,"CallType%02i = ISDN%c%c",i,13,10);
604 } else { 616 } else {
605 sprintf(buffer,"CallType%02i = Analogue%c%c",i,13,10); 617 sprintf(buffer,"CallType%02i = Analogue%c%c",i,13,10);
606 } 618 }
607 SaveBackupText(file, "", buffer, UseUnicode); 619 SaveBackupText(file, "", buffer, UseUnicode);
608 sprintf(buffer,"IP%02i",i); 620 sprintf(buffer,"IP%02i",i);
609 SaveBackupText(file, buffer, settings->Settings[i].IPAddress, UseUnicode); 621 SaveBackupText(file, buffer, settings->Settings[i].IPAddress, UseUnicode);
610 } 622 }
611 sprintf(buffer,"Number%02i",i); 623 sprintf(buffer,"Number%02i",i);
612 SaveBackupText(file, buffer, settings->Settings[i].DialUp, UseUnicode); 624 SaveBackupText(file, buffer, settings->Settings[i].DialUp, UseUnicode);
613 if (settings->Settings[i].ManualLogin) { 625 if (settings->Settings[i].ManualLogin) {
614 sprintf(buffer,"Login%02i = Manual%c%c",i,13,10); 626 sprintf(buffer,"Login%02i = Manual%c%c",i,13,10);
615 } else { 627 } else {
616 sprintf(buffer,"Login%02i = Automatic%c%c",i,13,10); 628 sprintf(buffer,"Login%02i = Automatic%c%c",i,13,10);
617 } 629 }
618 SaveBackupText(file, "", buffer, UseUnicode); 630 SaveBackupText(file, "", buffer, UseUnicode);
619 if (settings->Settings[i].IsNormalAuthentication) { 631 if (settings->Settings[i].IsNormalAuthentication) {
620 sprintf(buffer,"Authentication%02i = Normal%c%c",i,13,10); 632 sprintf(buffer,"Authentication%02i = Normal%c%c",i,13,10);
621 } else { 633 } else {
622 sprintf(buffer,"Authentication%02i = Secure%c%c",i,13,10); 634 sprintf(buffer,"Authentication%02i = Secure%c%c",i,13,10);
623 } 635 }
624 SaveBackupText(file, "", buffer, UseUnicode); 636 SaveBackupText(file, "", buffer, UseUnicode);
625 switch (settings->Settings[i].Speed) { 637 switch (settings->Settings[i].Speed) {
626 case WAPSETTINGS_SPEED_9600 : sprintf(buffer,"CallSpeed%02i = 9600%c%c" ,i,13,10); break; 638 case WAPSETTINGS_SPEED_9600 : sprintf(buffer,"CallSpeed%02i = 9600%c%c" ,i,13,10); break;
627 case WAPSETTINGS_SPEED_14400: sprintf(buffer,"CallSpeed%02i = 14400%c%c",i,13,10); break; 639 case WAPSETTINGS_SPEED_14400: sprintf(buffer,"CallSpeed%02i = 14400%c%c",i,13,10); break;
628 case WAPSETTINGS_SPEED_AUTO : sprintf(buffer,"CallSpeed%02i = auto%c%c" ,i,13,10); break; 640 case WAPSETTINGS_SPEED_AUTO : sprintf(buffer,"CallSpeed%02i = auto%c%c" ,i,13,10); break;
629 } 641 }
630 switch (settings->Settings[i].Speed) { 642 switch (settings->Settings[i].Speed) {
631 case WAPSETTINGS_SPEED_9600 : 643 case WAPSETTINGS_SPEED_9600 :
632 case WAPSETTINGS_SPEED_14400: 644 case WAPSETTINGS_SPEED_14400:
633 case WAPSETTINGS_SPEED_AUTO : 645 case WAPSETTINGS_SPEED_AUTO :
634 SaveBackupText(file, "", buffer, UseUnicode); 646 SaveBackupText(file, "", buffer, UseUnicode);
635 default: 647 default:
636 break; 648 break;
637 } 649 }
638 sprintf(buffer,"User%02i",i); 650 sprintf(buffer,"User%02i",i);
639 SaveBackupText(file, buffer, settings->Settings[i].User, UseUnicode); 651 SaveBackupText(file, buffer, settings->Settings[i].User, UseUnicode);
640 sprintf(buffer,"Password%02i",i); 652 sprintf(buffer,"Password%02i",i);
641 SaveBackupText(file, buffer, settings->Settings[i].Password, UseUnicode); 653 SaveBackupText(file, buffer, settings->Settings[i].Password, UseUnicode);
642 break; 654 break;
643 case WAPSETTINGS_BEARER_USSD: 655 case WAPSETTINGS_BEARER_USSD:
644 sprintf(buffer,"Bearer%02i = USSD%c%c",i,13,10); 656 sprintf(buffer,"Bearer%02i = USSD%c%c",i,13,10);
645 SaveBackupText(file, "", buffer, UseUnicode); 657 SaveBackupText(file, "", buffer, UseUnicode);
646 sprintf(buffer,"ServiceCode%02i",i); 658 sprintf(buffer,"ServiceCode%02i",i);
647 SaveBackupText(file, buffer, settings->Settings[i].Code, UseUnicode); 659 SaveBackupText(file, buffer, settings->Settings[i].Code, UseUnicode);
648 if (settings->Settings[i].IsIP) { 660 if (settings->Settings[i].IsIP) {
649 sprintf(buffer,"IP%02i",i); 661 sprintf(buffer,"IP%02i",i);
650 } else { 662 } else {
651 sprintf(buffer,"Number%02i",i); 663 sprintf(buffer,"Number%02i",i);
652 } 664 }
653 SaveBackupText(file, buffer, settings->Settings[i].Service, UseUnicode); 665 SaveBackupText(file, buffer, settings->Settings[i].Service, UseUnicode);
654 } 666 }
655 sprintf(buffer,"%c%c",13,10); 667 sprintf(buffer,"%c%c",13,10);
656 SaveBackupText(file, "", buffer, UseUnicode); 668 SaveBackupText(file, "", buffer, UseUnicode);
657 } 669 }
658} 670}
659 671
672static void SaveChatSettingsEntry(FILE *file, GSM_ChatSettings *settings, bool UseUnicode)
673{
674 char buffer[10000];
675
676 sprintf(buffer,"HomePage");
677 SaveBackupText(file, buffer, settings->HomePage, UseUnicode);
678 sprintf(buffer,"User");
679 SaveBackupText(file, buffer, settings->User, UseUnicode);
680 sprintf(buffer,"Password");
681 SaveBackupText(file, buffer, settings->Password, UseUnicode);
682 SaveWAPSettingsEntry(file, &settings->Connection, UseUnicode);
683}
684
685static void SaveSyncMLSettingsEntry(FILE *file, GSM_SyncMLSettings *settings, bool UseUnicode)
686{
687 char buffer[10000];
688
689 sprintf(buffer,"User");
690 SaveBackupText(file, buffer, settings->User, UseUnicode);
691 sprintf(buffer,"Password");
692 SaveBackupText(file, buffer, settings->Password, UseUnicode);
693 sprintf(buffer,"PhonebookDB");
694 SaveBackupText(file, buffer, settings->PhonebookDataBase, UseUnicode);
695 sprintf(buffer,"CalendarDB");
696 SaveBackupText(file, buffer, settings->CalendarDataBase, UseUnicode);
697 sprintf(buffer,"Server");
698 SaveBackupText(file, buffer, settings->Server, UseUnicode);
699 if (settings->SyncPhonebook) {
700 sprintf(buffer,"SyncPhonebook = True%c%c",13,10);
701 } else {
702 sprintf(buffer,"SyncPhonebook = False%c%c",13,10);
703 }
704 SaveBackupText(file, "", buffer, UseUnicode);
705 if (settings->SyncCalendar) {
706 sprintf(buffer,"SyncCalendar = True%c%c",13,10);
707 } else {
708 sprintf(buffer,"SyncCalendar = False%c%c",13,10);
709 }
710 SaveBackupText(file, "", buffer, UseUnicode);
711 SaveWAPSettingsEntry(file, &settings->Connection, UseUnicode);
712}
713
660static void SaveBitmapEntry(FILE *file, GSM_Bitmap *bitmap, bool UseUnicode) 714static void SaveBitmapEntry(FILE *file, GSM_Bitmap *bitmap, bool UseUnicode)
661{ 715{
662 unsigned char buffer[10000],buffer2[10000]; 716 unsigned char buffer[10000],buffer2[10000];
663 int x,y; 717 int x,y;
664 718
665 sprintf(buffer,"Width = %i%c%c",bitmap->BitmapWidth,13,10); 719 sprintf(buffer,"Width = %i%c%c",bitmap->BitmapWidth,13,10);
666 SaveBackupText(file, "", buffer, UseUnicode); 720 SaveBackupText(file, "", buffer, UseUnicode);
667 sprintf(buffer,"Height = %i%c%c",bitmap->BitmapHeight,13,10); 721 sprintf(buffer,"Height = %i%c%c",bitmap->BitmapHeight,13,10);
668 SaveBackupText(file, "", buffer, UseUnicode); 722 SaveBackupText(file, "", buffer, UseUnicode);
669 for (y=0;y<bitmap->BitmapHeight;y++) { 723 for (y=0;y<bitmap->BitmapHeight;y++) {
670 for (x=0;x<bitmap->BitmapWidth;x++) { 724 for (x=0;x<bitmap->BitmapWidth;x++) {
671 buffer[x] = ' '; 725 buffer[x] = ' ';
672 if (GSM_IsPointBitmap(bitmap,x,y)) buffer[x]='#'; 726 if (GSM_IsPointBitmap(bitmap,x,y)) buffer[x]='#';
673 } 727 }
674 buffer[bitmap->BitmapWidth] = 0; 728 buffer[bitmap->BitmapWidth] = 0;
675 sprintf(buffer2,"Bitmap%02i = \"%s\"%c%c",y,buffer,13,10); 729 sprintf(buffer2,"Bitmap%02i = \"%s\"%c%c",y,buffer,13,10);
676 SaveBackupText(file, "", buffer2, UseUnicode); 730 SaveBackupText(file, "", buffer2, UseUnicode);
677 } 731 }
678} 732}
679 733
680static void SaveCallerEntry(FILE *file, GSM_Bitmap *bitmap, bool UseUnicode) 734static void SaveCallerEntry(FILE *file, GSM_Bitmap *bitmap, bool UseUnicode)
681{ 735{
682 unsigned char buffer[1000]; 736 unsigned char buffer[1000];
683 737
684 sprintf(buffer,"Location = %03i%c%c",bitmap->Location,13,10); 738 sprintf(buffer,"Location = %03i%c%c",bitmap->Location,13,10);
685 SaveBackupText(file, "", buffer, UseUnicode); 739 SaveBackupText(file, "", buffer, UseUnicode);
686 if (!bitmap->DefaultName) SaveBackupText(file, "Name", bitmap->Text, UseUnicode); 740 if (!bitmap->DefaultName) SaveBackupText(file, "Name", bitmap->Text, UseUnicode);
687 if (!bitmap->DefaultRingtone) { 741 if (!bitmap->DefaultRingtone) {
688 if (bitmap->FileSystemRingtone) { 742 if (bitmap->FileSystemRingtone) {
689 sprintf(buffer,"FileRingtone = %02x%c%c",bitmap->RingtoneID,13,10); 743 sprintf(buffer,"FileRingtone = %02x%c%c",bitmap->RingtoneID,13,10);
690 } else { 744 } else {
691 sprintf(buffer,"Ringtone = %02x%c%c",bitmap->RingtoneID,13,10); 745 sprintf(buffer,"Ringtone = %02x%c%c",bitmap->RingtoneID,13,10);
692 } 746 }
693 SaveBackupText(file, "", buffer, UseUnicode); 747 SaveBackupText(file, "", buffer, UseUnicode);
694 } 748 }
695 if (bitmap->BitmapEnabled) { 749 if (bitmap->BitmapEnabled) {
696 sprintf(buffer,"Enabled = True%c%c",13,10); 750 sprintf(buffer,"Enabled = True%c%c",13,10);
697 } else { 751 } else {
698 sprintf(buffer,"Enabled = False%c%c",13,10); 752 sprintf(buffer,"Enabled = False%c%c",13,10);
699 } 753 }
700 SaveBackupText(file, "", buffer, UseUnicode); 754 SaveBackupText(file, "", buffer, UseUnicode);
701 if (!bitmap->DefaultBitmap) SaveBitmapEntry(file, bitmap, UseUnicode); 755 if (!bitmap->DefaultBitmap) SaveBitmapEntry(file, bitmap, UseUnicode);
702 sprintf(buffer,"%c%c",13,10); 756 sprintf(buffer,"%c%c",13,10);
703 SaveBackupText(file, "", buffer, UseUnicode); 757 SaveBackupText(file, "", buffer, UseUnicode);
704} 758}
705 759
706static void SaveWAPBookmarkEntry(FILE *file, GSM_WAPBookmark *bookmark, bool UseUnicode) 760static void SaveWAPBookmarkEntry(FILE *file, GSM_WAPBookmark *bookmark, bool UseUnicode)
707{ 761{
708 unsigned char buffer[1000]; 762 unsigned char buffer[1000];
709 763
710 SaveBackupText(file, "URL", bookmark->Address, UseUnicode); 764 SaveBackupText(file, "URL", bookmark->Address, UseUnicode);
711 SaveBackupText(file, "Title", bookmark->Title, UseUnicode); 765 SaveBackupText(file, "Title", bookmark->Title, UseUnicode);
712 sprintf(buffer,"%c%c",13,10); 766 sprintf(buffer,"%c%c",13,10);
713 SaveBackupText(file, "", buffer, UseUnicode); 767 SaveBackupText(file, "", buffer, UseUnicode);
714} 768}
715 769
716static void SaveStartupEntry(FILE *file, GSM_Bitmap *bitmap, bool UseUnicode) 770static void SaveStartupEntry(FILE *file, GSM_Bitmap *bitmap, bool UseUnicode)
717{ 771{
718 unsigned char buffer[1000]; 772 unsigned char buffer[1000];
719 773
720 sprintf(buffer,"[Startup]%c%c",13,10); 774 sprintf(buffer,"[Startup]%c%c",13,10);
721 SaveBackupText(file, "", buffer, UseUnicode); 775 SaveBackupText(file, "", buffer, UseUnicode);
722 if (bitmap->Type == GSM_WelcomeNote_Text) { 776 if (bitmap->Type == GSM_WelcomeNote_Text) {
723 SaveBackupText(file, "Text", bitmap->Text, UseUnicode); 777 SaveBackupText(file, "Text", bitmap->Text, UseUnicode);
724 } 778 }
725 if (bitmap->Type == GSM_StartupLogo) { 779 if (bitmap->Type == GSM_StartupLogo) {
726 SaveBitmapEntry(file, bitmap, UseUnicode); 780 SaveBitmapEntry(file, bitmap, UseUnicode);
727 } 781 }
728 sprintf(buffer,"%c%c",13,10); 782 sprintf(buffer,"%c%c",13,10);
729 SaveBackupText(file, "", buffer, UseUnicode); 783 SaveBackupText(file, "", buffer, UseUnicode);
730} 784}
731 785
732static void SaveSMSCEntry(FILE *file, GSM_SMSC *SMSC, bool UseUnicode) 786static void SaveSMSCEntry(FILE *file, GSM_SMSC *SMSC, bool UseUnicode)
733{ 787{
734 unsigned char buffer[1000]; 788 unsigned char buffer[1000];
735 789
736 sprintf(buffer,"Location = %03i%c%c",SMSC->Location,13,10); 790 sprintf(buffer,"Location = %03i%c%c",SMSC->Location,13,10);
737 SaveBackupText(file, "", buffer, UseUnicode); 791 SaveBackupText(file, "", buffer, UseUnicode);
738 SaveBackupText(file, "Name", SMSC->Name, UseUnicode); 792 SaveBackupText(file, "Name", SMSC->Name, UseUnicode);
739 SaveBackupText(file, "Number", SMSC->Number, UseUnicode); 793 SaveBackupText(file, "Number", SMSC->Number, UseUnicode);
740 SaveBackupText(file, "DefaultNumber", SMSC->DefaultNumber, UseUnicode); 794 SaveBackupText(file, "DefaultNumber", SMSC->DefaultNumber, UseUnicode);
741 SaveBackupText(file, "", "Format = ", UseUnicode); 795 SaveBackupText(file, "", "Format = ", UseUnicode);
742 switch (SMSC->Format) { 796 switch (SMSC->Format) {
743 case SMS_FORMAT_Text: sprintf(buffer,"Text"); break; 797 case SMS_FORMAT_Text: sprintf(buffer,"Text"); break;
744 case SMS_FORMAT_Fax: sprintf(buffer,"Fax"); break; 798 case SMS_FORMAT_Fax: sprintf(buffer,"Fax"); break;
745 case SMS_FORMAT_Email: sprintf(buffer,"Email"); break; 799 case SMS_FORMAT_Email: sprintf(buffer,"Email"); break;
746 case SMS_FORMAT_Pager: sprintf(buffer,"Pager"); break; 800 case SMS_FORMAT_Pager: sprintf(buffer,"Pager"); break;
747 } 801 }
748 SaveBackupText(file, "", buffer, UseUnicode); 802 SaveBackupText(file, "", buffer, UseUnicode);
749 sprintf(buffer,"%c%cValidity = ",13,10); 803 sprintf(buffer,"%c%cValidity = ",13,10);
750 SaveBackupText(file, "", buffer, UseUnicode); 804 SaveBackupText(file, "", buffer, UseUnicode);
751 switch (SMSC->Validity.Relative) { 805 switch (SMSC->Validity.Relative) {
752 case SMS_VALID_1_Hour : sprintf(buffer, "1hour"); break; 806 case SMS_VALID_1_Hour : sprintf(buffer, "1hour"); break;
753 case SMS_VALID_6_Hours : sprintf(buffer, "6hours"); break; 807 case SMS_VALID_6_Hours : sprintf(buffer, "6hours"); break;
754 case SMS_VALID_1_Day : sprintf(buffer, "24hours"); break; 808 case SMS_VALID_1_Day : sprintf(buffer, "24hours"); break;
755 case SMS_VALID_3_Days : sprintf(buffer, "72hours"); break; 809 case SMS_VALID_3_Days : sprintf(buffer, "72hours"); break;
756 case SMS_VALID_1_Week : sprintf(buffer, "1week"); break; 810 case SMS_VALID_1_Week : sprintf(buffer, "1week"); break;
757 case SMS_VALID_Max_Time: 811 case SMS_VALID_Max_Time:
758 default : sprintf(buffer,"MaximumTime"); break; 812 default : sprintf(buffer,"MaximumTime"); break;
759 } 813 }
760 SaveBackupText(file, "", buffer, UseUnicode); 814 SaveBackupText(file, "", buffer, UseUnicode);
761 sprintf(buffer,"%c%c%c%c",13,10,13,10); 815 sprintf(buffer,"%c%c%c%c",13,10,13,10);
762 SaveBackupText(file, "", buffer, UseUnicode); 816 SaveBackupText(file, "", buffer, UseUnicode);
763} 817}
764 818
765static void SaveRingtoneEntry(FILE *file, GSM_Ringtone *ringtone, bool UseUnicode) 819static void SaveRingtoneEntry(FILE *file, GSM_Ringtone *ringtone, bool UseUnicode)
766{ 820{
767 unsigned char buffer[45000]; 821 unsigned char buffer[45000];
768 int i,j;
769 822
770 sprintf(buffer,"Location = %i%c%c",ringtone->Location,13,10); 823 sprintf(buffer,"Location = %i%c%c",ringtone->Location,13,10);
771 SaveBackupText(file, "", buffer, UseUnicode); 824 SaveBackupText(file, "", buffer, UseUnicode);
772 SaveBackupText(file, "Name", ringtone->Name, UseUnicode); 825 SaveBackupText(file, "Name", ringtone->Name, UseUnicode);
773 switch (ringtone->Format) { 826 switch (ringtone->Format) {
774 case RING_NOKIABINARY: 827 case RING_NOKIABINARY:
775 j = 0; i = 0;
776 EncodeHexBin(buffer,ringtone->NokiaBinary.Frame,ringtone->NokiaBinary.Length); 828 EncodeHexBin(buffer,ringtone->NokiaBinary.Frame,ringtone->NokiaBinary.Length);
777 SaveLinkedBackupText(file, "NokiaBinary", buffer, UseUnicode); 829 SaveLinkedBackupText(file, "NokiaBinary", buffer, UseUnicode);
778 break; 830 break;
779 case RING_MIDI: 831 case RING_MIDI:
780 j = 0; i = 0;
781 EncodeHexBin(buffer,ringtone->NokiaBinary.Frame,ringtone->NokiaBinary.Length); 832 EncodeHexBin(buffer,ringtone->NokiaBinary.Frame,ringtone->NokiaBinary.Length);
782 SaveLinkedBackupText(file, "Pure Midi", buffer, UseUnicode); 833 SaveLinkedBackupText(file, "Pure Midi", buffer, UseUnicode);
783 break; 834 break;
835 case RING_MMF:
836 EncodeHexBin(buffer,ringtone->NokiaBinary.Frame,ringtone->NokiaBinary.Length);
837 SaveLinkedBackupText(file, "SMAF", buffer, UseUnicode);
838 break;
784 case RING_NOTETONE: 839 case RING_NOTETONE:
785 break; 840 break;
786 } 841 }
787 sprintf(buffer,"%c%c",13,10); 842 sprintf(buffer,"%c%c",13,10);
788 SaveBackupText(file, "", buffer, UseUnicode); 843 SaveBackupText(file, "", buffer, UseUnicode);
789} 844}
790 845
791static void SaveOperatorEntry(FILE *file, GSM_Bitmap *bitmap, bool UseUnicode) 846static void SaveOperatorEntry(FILE *file, GSM_Bitmap *bitmap, bool UseUnicode)
792{ 847{
793 unsigned char buffer[1000]; 848 unsigned char buffer[1000];
794 849
795 sprintf(buffer,"[Operator]%c%c",13,10); 850 sprintf(buffer,"[Operator]%c%c",13,10);
796 SaveBackupText(file, "", buffer, UseUnicode); 851 SaveBackupText(file, "", buffer, UseUnicode);
797 sprintf(buffer,"Network = \"%s\"%c%c", bitmap->NetworkCode,13,10); 852 sprintf(buffer,"Network = \"%s\"%c%c", bitmap->NetworkCode,13,10);
798 SaveBackupText(file, "", buffer, UseUnicode); 853 SaveBackupText(file, "", buffer, UseUnicode);
799 SaveBitmapEntry(file, bitmap, UseUnicode); 854 SaveBitmapEntry(file, bitmap, UseUnicode);
800 sprintf(buffer,"%c%c",13,10); 855 sprintf(buffer,"%c%c",13,10);
801 SaveBackupText(file, "", buffer, UseUnicode); 856 SaveBackupText(file, "", buffer, UseUnicode);
802} 857}
803 858
804static void SaveToDoEntry(FILE *file, GSM_ToDoEntry *ToDo, bool UseUnicode) 859static void SaveToDoEntry(FILE *file, GSM_ToDoEntry *ToDo, bool UseUnicode)
805{ 860{
806 unsigned char buffer[1000]; 861 unsigned char buffer[1000];
807 int j; 862 int j;
808 863
809 sprintf(buffer,"Location = %i%c%c",ToDo->Location,13,10); 864 sprintf(buffer,"Location = %i%c%c",ToDo->Location,13,10);
810 SaveBackupText(file, "", buffer, UseUnicode); 865 SaveBackupText(file, "", buffer, UseUnicode);
811 switch (ToDo->Priority) { 866 switch (ToDo->Priority) {
812 case GSM_Priority_High: 867 case GSM_Priority_High:
813 sprintf(buffer,"Priority = High%c%c",13,10); 868 sprintf(buffer,"Priority = High%c%c",13,10);
814 break; 869 break;
815 case GSM_Priority_Medium: 870 case GSM_Priority_Medium:
816 sprintf(buffer,"Priority = Medium%c%c",13,10); 871 sprintf(buffer,"Priority = Medium%c%c",13,10);
817 break; 872 break;
818 case GSM_Priority_Low: 873 case GSM_Priority_Low:
819 sprintf(buffer,"Priority = Low%c%c",13,10); 874 sprintf(buffer,"Priority = Low%c%c",13,10);
820 break; 875 break;
821 } 876 }
822 SaveBackupText(file, "", buffer, UseUnicode); 877 SaveBackupText(file, "", buffer, UseUnicode);
823 878
824 for (j=0;j<ToDo->EntriesNum;j++) { 879 for (j=0;j<ToDo->EntriesNum;j++) {
825 switch (ToDo->Entries[j].EntryType) { 880 switch (ToDo->Entries[j].EntryType) {
826 case TODO_END_DATETIME: 881 case TODO_END_DATETIME:
827 SaveBackupText(file, "", "DueTime", UseUnicode); 882 SaveBackupText(file, "", "DueTime", UseUnicode);
828 SaveVCalDateTime(file, &ToDo->Entries[j].Date, UseUnicode); 883 SaveVCalDateTime(file, &ToDo->Entries[j].Date, UseUnicode);
829 break; 884 break;
830 case TODO_COMPLETED: 885 case TODO_COMPLETED:
831 sprintf(buffer,"Completed = %s%c%c",ToDo->Entries[j].Number == 1 ? "yes" : "no" ,13,10); 886 sprintf(buffer,"Completed = %s%c%c",ToDo->Entries[j].Number == 1 ? "yes" : "no" ,13,10);
832 SaveBackupText(file, "", buffer, UseUnicode); 887 SaveBackupText(file, "", buffer, UseUnicode);
833 break; 888 break;
834 case TODO_ALARM_DATETIME: 889 case TODO_ALARM_DATETIME:
835 SaveBackupText(file, "", "Alarm", UseUnicode); 890 SaveBackupText(file, "", "Alarm", UseUnicode);
836 SaveVCalDateTime(file, &ToDo->Entries[j].Date, UseUnicode); 891 SaveVCalDateTime(file, &ToDo->Entries[j].Date, UseUnicode);
837 break; 892 break;
838 case TODO_SILENT_ALARM_DATETIME: 893 case TODO_SILENT_ALARM_DATETIME:
839 SaveBackupText(file, "", "SilentAlarm", UseUnicode); 894 SaveBackupText(file, "", "SilentAlarm", UseUnicode);
840 SaveVCalDateTime(file, &ToDo->Entries[j].Date, UseUnicode); 895 SaveVCalDateTime(file, &ToDo->Entries[j].Date, UseUnicode);
841 break; 896 break;
842 case TODO_TEXT: 897 case TODO_TEXT:
843 SaveBackupText(file, "Text", ToDo->Entries[j].Text, UseUnicode); 898 SaveBackupText(file, "Text", ToDo->Entries[j].Text, UseUnicode);
844 break; 899 break;
845 case TODO_PRIVATE: 900 case TODO_PRIVATE:
846 sprintf(buffer,"Private = %i%c%c",ToDo->Entries[j].Number,13,10); 901 sprintf(buffer,"Private = %i%c%c",ToDo->Entries[j].Number,13,10);
847 SaveBackupText(file, "", buffer, UseUnicode); 902 SaveBackupText(file, "", buffer, UseUnicode);
848 break; 903 break;
849 case TODO_CATEGORY: 904 case TODO_CATEGORY:
850 sprintf(buffer,"Category = %i%c%c",ToDo->Entries[j].Number,13,10); 905 sprintf(buffer,"Category = %i%c%c",ToDo->Entries[j].Number,13,10);
851 SaveBackupText(file, "", buffer, UseUnicode); 906 SaveBackupText(file, "", buffer, UseUnicode);
852 break; 907 break;
853 case TODO_CONTACTID: 908 case TODO_CONTACTID:
854 sprintf(buffer,"ContactID = %i%c%c",ToDo->Entries[j].Number,13,10); 909 sprintf(buffer,"ContactID = %i%c%c",ToDo->Entries[j].Number,13,10);
855 SaveBackupText(file, "", buffer, UseUnicode); 910 SaveBackupText(file, "", buffer, UseUnicode);
856 break; 911 break;
857 case TODO_PHONE: 912 case TODO_PHONE:
858 SaveBackupText(file, "Phone", ToDo->Entries[j].Text, UseUnicode); 913 SaveBackupText(file, "Phone", ToDo->Entries[j].Text, UseUnicode);
859 break; 914 break;
860 } 915 }
861 } 916 }
862 sprintf(buffer,"%c%c",13,10); 917 sprintf(buffer,"%c%c",13,10);
863 SaveBackupText(file, "", buffer, UseUnicode); 918 SaveBackupText(file, "", buffer, UseUnicode);
864} 919}
865 920
866static void SaveProfileEntry(FILE *file, GSM_Profile *Profile, bool UseUnicode) 921static void SaveProfileEntry(FILE *file, GSM_Profile *Profile, bool UseUnicode)
867{ 922{
868 int j,k; 923 int j,k;
869 bool special; 924 bool special;
870 unsigned char buffer[1000]; 925 unsigned char buffer[1000];
871 926
872 sprintf(buffer,"Location = %i%c%c",Profile->Location,13,10); 927 sprintf(buffer,"Location = %i%c%c",Profile->Location,13,10);
873 SaveBackupText(file, "", buffer, UseUnicode); 928 SaveBackupText(file, "", buffer, UseUnicode);
874 SaveBackupText(file, "Name",Profile->Name, UseUnicode); 929 SaveBackupText(file, "Name",Profile->Name, UseUnicode);
875 930
876 if (Profile->DefaultName) { 931 if (Profile->DefaultName) {
877 sprintf(buffer,"DefaultName = true%c%c",13,10); 932 sprintf(buffer,"DefaultName = true%c%c",13,10);
878 SaveBackupText(file, "", buffer, UseUnicode); 933 SaveBackupText(file, "", buffer, UseUnicode);
879 } 934 }
880 if (Profile->HeadSetProfile) { 935 if (Profile->HeadSetProfile) {
881 sprintf(buffer,"HeadSetProfile = true%c%c",13,10); 936 sprintf(buffer,"HeadSetProfile = true%c%c",13,10);
882 SaveBackupText(file, "", buffer, UseUnicode); 937 SaveBackupText(file, "", buffer, UseUnicode);
883 } 938 }
884 if (Profile->CarKitProfile) { 939 if (Profile->CarKitProfile) {
885 sprintf(buffer,"CarKitProfile = true%c%c",13,10); 940 sprintf(buffer,"CarKitProfile = true%c%c",13,10);
886 SaveBackupText(file, "", buffer, UseUnicode); 941 SaveBackupText(file, "", buffer, UseUnicode);
887 } 942 }
888 943
889 for (j=0;j<Profile->FeaturesNumber;j++) { 944 for (j=0;j<Profile->FeaturesNumber;j++) {
890 sprintf(buffer,"Feature%02i = ",j); 945 sprintf(buffer,"Feature%02i = ",j);
891 SaveBackupText(file, "", buffer, UseUnicode); 946 SaveBackupText(file, "", buffer, UseUnicode);
892 special = false; 947 special = false;
893 switch (Profile->FeatureID[j]) { 948 switch (Profile->FeatureID[j]) {
894 case Profile_MessageToneID: 949 case Profile_MessageToneID:
895 case Profile_RingtoneID: 950 case Profile_RingtoneID:
896 special = true; 951 special = true;
897 if (Profile->FeatureID[j] == Profile_RingtoneID) { 952 if (Profile->FeatureID[j] == Profile_RingtoneID) {
898 sprintf(buffer,"RingtoneID%c%c",13,10); 953 sprintf(buffer,"RingtoneID%c%c",13,10);
899 } else { 954 } else {
900 sprintf(buffer,"MessageToneID%c%c",13,10); 955 sprintf(buffer,"MessageToneID%c%c",13,10);
901 } 956 }
902 SaveBackupText(file, "", buffer, UseUnicode); 957 SaveBackupText(file, "", buffer, UseUnicode);
903 sprintf(buffer,"Value%02i = %i%c%c",j,Profile->FeatureValue[j],13,10); 958 sprintf(buffer,"Value%02i = %i%c%c",j,Profile->FeatureValue[j],13,10);
904 SaveBackupText(file, "", buffer, UseUnicode); 959 SaveBackupText(file, "", buffer, UseUnicode);
905 break; 960 break;
906 case Profile_CallerGroups: 961 case Profile_CallerGroups:
907 special = true; 962 special = true;
908 sprintf(buffer,"CallerGroups%c%c",13,10); 963 sprintf(buffer,"CallerGroups%c%c",13,10);
909 SaveBackupText(file, "", buffer, UseUnicode); 964 SaveBackupText(file, "", buffer, UseUnicode);
910 sprintf(buffer,"Value%02i = ",j); 965 sprintf(buffer,"Value%02i = ",j);
911 SaveBackupText(file, "", buffer, UseUnicode); 966 SaveBackupText(file, "", buffer, UseUnicode);
912 for (k=0;k<5;k++) { 967 for (k=0;k<5;k++) {
913 if (Profile->CallerGroups[k]) { 968 if (Profile->CallerGroups[k]) {
914 sprintf(buffer,"%i",k); 969 sprintf(buffer,"%i",k);
915 SaveBackupText(file, "", buffer, UseUnicode); 970 SaveBackupText(file, "", buffer, UseUnicode);
916 } 971 }
917 } 972 }
918 sprintf(buffer,"%c%c",13,10); 973 sprintf(buffer,"%c%c",13,10);
919 SaveBackupText(file, "", buffer, UseUnicode); 974 SaveBackupText(file, "", buffer, UseUnicode);
920 break; 975 break;
921 case Profile_ScreenSaverNumber: 976 case Profile_ScreenSaverNumber:
922 special = true; 977 special = true;
923 sprintf(buffer,"ScreenSaverNumber%c%c",13,10); 978 sprintf(buffer,"ScreenSaverNumber%c%c",13,10);
924 SaveBackupText(file, "", buffer, UseUnicode); 979 SaveBackupText(file, "", buffer, UseUnicode);
925 sprintf(buffer,"Value%02i = %i%c%c",j,Profile->FeatureValue[j],13,10); 980 sprintf(buffer,"Value%02i = %i%c%c",j,Profile->FeatureValue[j],13,10);
926 SaveBackupText(file, "", buffer, UseUnicode); 981 SaveBackupText(file, "", buffer, UseUnicode);
927 break; 982 break;
928 case Profile_CallAlert : sprintf(buffer,"IncomingCallAlert%c%c",13,10); break; 983 case Profile_CallAlert : sprintf(buffer,"IncomingCallAlert%c%c",13,10); break;
929 case Profile_RingtoneVolume : sprintf(buffer,"RingtoneVolume%c%c",13,10); break; 984 case Profile_RingtoneVolume : sprintf(buffer,"RingtoneVolume%c%c",13,10); break;
930 case Profile_Vibration : sprintf(buffer,"Vibrating%c%c",13,10); break; 985 case Profile_Vibration : sprintf(buffer,"Vibrating%c%c",13,10); break;
931 case Profile_MessageTone : sprintf(buffer,"MessageTone%c%c",13,10); break; 986 case Profile_MessageTone : sprintf(buffer,"MessageTone%c%c",13,10); break;
932 case Profile_KeypadTone : sprintf(buffer,"KeypadTones%c%c",13,10); break; 987 case Profile_KeypadTone : sprintf(buffer,"KeypadTones%c%c",13,10); break;
933 case Profile_WarningTone : sprintf(buffer,"WarningTones%c%c",13,10); break; 988 case Profile_WarningTone : sprintf(buffer,"WarningTones%c%c",13,10); break;
934 case Profile_ScreenSaver : sprintf(buffer,"ScreenSaver%c%c",13,10); break; 989 case Profile_ScreenSaver : sprintf(buffer,"ScreenSaver%c%c",13,10); break;
935 case Profile_ScreenSaverTime : sprintf(buffer,"ScreenSaverTimeout%c%c",13,10); break; 990 case Profile_ScreenSaverTime : sprintf(buffer,"ScreenSaverTimeout%c%c",13,10); break;
936 case Profile_AutoAnswer : sprintf(buffer,"AutomaticAnswer%c%c",13,10); break; 991 case Profile_AutoAnswer : sprintf(buffer,"AutomaticAnswer%c%c",13,10); break;
937 case Profile_Lights : sprintf(buffer,"Lights%c%c",13,10); break; 992 case Profile_Lights : sprintf(buffer,"Lights%c%c",13,10); break;
938 default : special = true; 993 default : special = true;
939 } 994 }
940 if (!special) { 995 if (!special) {
941 SaveBackupText(file, "", buffer, UseUnicode); 996 SaveBackupText(file, "", buffer, UseUnicode);
942 sprintf(buffer,"Value%02i = ",j); 997 sprintf(buffer,"Value%02i = ",j);
943 SaveBackupText(file, "", buffer, UseUnicode); 998 SaveBackupText(file, "", buffer, UseUnicode);
944 switch (Profile->FeatureValue[j]) { 999 switch (Profile->FeatureValue[j]) {
945 case PROFILE_VOLUME_LEVEL1 : 1000 case PROFILE_VOLUME_LEVEL1 :
946 case PROFILE_KEYPAD_LEVEL1 : sprintf(buffer,"Level1%c%c",13,10); break; 1001 case PROFILE_KEYPAD_LEVEL1 : sprintf(buffer,"Level1%c%c",13,10); break;
947 case PROFILE_VOLUME_LEVEL2 : 1002 case PROFILE_VOLUME_LEVEL2 :
948 case PROFILE_KEYPAD_LEVEL2 : sprintf(buffer,"Level2%c%c",13,10); break; 1003 case PROFILE_KEYPAD_LEVEL2 : sprintf(buffer,"Level2%c%c",13,10); break;
949 case PROFILE_VOLUME_LEVEL3 : 1004 case PROFILE_VOLUME_LEVEL3 :
950 case PROFILE_KEYPAD_LEVEL3 : sprintf(buffer,"Level3%c%c",13,10); break; 1005 case PROFILE_KEYPAD_LEVEL3 : sprintf(buffer,"Level3%c%c",13,10); break;
951 case PROFILE_VOLUME_LEVEL4 : sprintf(buffer,"Level4%c%c",13,10); break; 1006 case PROFILE_VOLUME_LEVEL4 : sprintf(buffer,"Level4%c%c",13,10); break;
952 case PROFILE_VOLUME_LEVEL5 : sprintf(buffer,"Level5%c%c",13,10); break; 1007 case PROFILE_VOLUME_LEVEL5 : sprintf(buffer,"Level5%c%c",13,10); break;
953 case PROFILE_MESSAGE_NOTONE : 1008 case PROFILE_MESSAGE_NOTONE :
954 case PROFILE_AUTOANSWER_OFF : 1009 case PROFILE_AUTOANSWER_OFF :
955 case PROFILE_LIGHTS_OFF : 1010 case PROFILE_LIGHTS_OFF :
956 case PROFILE_SAVER_OFF : 1011 case PROFILE_SAVER_OFF :
957 case PROFILE_WARNING_OFF : 1012 case PROFILE_WARNING_OFF :
958 case PROFILE_CALLALERT_OFF : 1013 case PROFILE_CALLALERT_OFF :
959 case PROFILE_VIBRATION_OFF : 1014 case PROFILE_VIBRATION_OFF :
960 case PROFILE_KEYPAD_OFF : sprintf(buffer,"Off%c%c",13,10); break; 1015 case PROFILE_KEYPAD_OFF : sprintf(buffer,"Off%c%c",13,10); break;
961 case PROFILE_CALLALERT_RINGING : sprintf(buffer,"Ringing%c%c",13,10); break; 1016 case PROFILE_CALLALERT_RINGING : sprintf(buffer,"Ringing%c%c",13,10); break;
962 case PROFILE_CALLALERT_RINGONCE : sprintf(buffer,"RingOnce%c%c",13,10); break; 1017 case PROFILE_CALLALERT_RINGONCE : sprintf(buffer,"RingOnce%c%c",13,10); break;
963 case PROFILE_CALLALERT_ASCENDING : sprintf(buffer,"Ascending%c%c",13,10); break; 1018 case PROFILE_CALLALERT_ASCENDING : sprintf(buffer,"Ascending%c%c",13,10); break;
964 case PROFILE_CALLALERT_CALLERGROUPS : sprintf(buffer,"CallerGroups%c%c",13,10);break; 1019 case PROFILE_CALLALERT_CALLERGROUPS : sprintf(buffer,"CallerGroups%c%c",13,10);break;
965 case PROFILE_MESSAGE_STANDARD : sprintf(buffer,"Standard%c%c",13,10); break; 1020 case PROFILE_MESSAGE_STANDARD : sprintf(buffer,"Standard%c%c",13,10); break;
966 case PROFILE_MESSAGE_SPECIAL : sprintf(buffer,"Special%c%c",13,10); break; 1021 case PROFILE_MESSAGE_SPECIAL : sprintf(buffer,"Special%c%c",13,10); break;
967 case PROFILE_MESSAGE_BEEPONCE : 1022 case PROFILE_MESSAGE_BEEPONCE :
968 case PROFILE_CALLALERT_BEEPONCE : sprintf(buffer,"BeepOnce%c%c",13,10); break; 1023 case PROFILE_CALLALERT_BEEPONCE : sprintf(buffer,"BeepOnce%c%c",13,10); break;
969 case PROFILE_MESSAGE_ASCENDING : sprintf(buffer,"Ascending%c%c",13,10); break; 1024 case PROFILE_MESSAGE_ASCENDING : sprintf(buffer,"Ascending%c%c",13,10); break;
970 case PROFILE_MESSAGE_PERSONAL : sprintf(buffer,"Personal%c%c",13,10); break; 1025 case PROFILE_MESSAGE_PERSONAL : sprintf(buffer,"Personal%c%c",13,10); break;
971 case PROFILE_AUTOANSWER_ON : 1026 case PROFILE_AUTOANSWER_ON :
972 case PROFILE_WARNING_ON : 1027 case PROFILE_WARNING_ON :
973 case PROFILE_SAVER_ON : 1028 case PROFILE_SAVER_ON :
974 case PROFILE_VIBRATION_ON : sprintf(buffer,"On%c%c",13,10); break; 1029 case PROFILE_VIBRATION_ON : sprintf(buffer,"On%c%c",13,10); break;
975 case PROFILE_VIBRATION_FIRST : sprintf(buffer,"VibrateFirst%c%c",13,10);break; 1030 case PROFILE_VIBRATION_FIRST : sprintf(buffer,"VibrateFirst%c%c",13,10);break;
976 case PROFILE_LIGHTS_AUTO : sprintf(buffer,"Auto%c%c",13,10); break; 1031 case PROFILE_LIGHTS_AUTO : sprintf(buffer,"Auto%c%c",13,10); break;
977 case PROFILE_SAVER_TIMEOUT_5SEC : sprintf(buffer,"5Seconds%c%c",13,10); break; 1032 case PROFILE_SAVER_TIMEOUT_5SEC : sprintf(buffer,"5Seconds%c%c",13,10); break;
978 case PROFILE_SAVER_TIMEOUT_20SEC : sprintf(buffer,"20Seconds%c%c",13,10); break; 1033 case PROFILE_SAVER_TIMEOUT_20SEC : sprintf(buffer,"20Seconds%c%c",13,10); break;
979 case PROFILE_SAVER_TIMEOUT_1MIN : sprintf(buffer,"1Minute%c%c",13,10); break; 1034 case PROFILE_SAVER_TIMEOUT_1MIN : sprintf(buffer,"1Minute%c%c",13,10); break;
980 case PROFILE_SAVER_TIMEOUT_2MIN : sprintf(buffer,"2Minutes%c%c",13,10); break; 1035 case PROFILE_SAVER_TIMEOUT_2MIN : sprintf(buffer,"2Minutes%c%c",13,10); break;
981 case PROFILE_SAVER_TIMEOUT_5MIN : sprintf(buffer,"5Minutes%c%c",13,10); break; 1036 case PROFILE_SAVER_TIMEOUT_5MIN : sprintf(buffer,"5Minutes%c%c",13,10); break;
982 case PROFILE_SAVER_TIMEOUT_10MIN : sprintf(buffer,"10Minutes%c%c",13,10);break; 1037 case PROFILE_SAVER_TIMEOUT_10MIN : sprintf(buffer,"10Minutes%c%c",13,10);break;
983 default : sprintf(buffer,"UNKNOWN%c%c",13,10); 1038 default : sprintf(buffer,"UNKNOWN%c%c",13,10);
984 } 1039 }
985 SaveBackupText(file, "", buffer, UseUnicode); 1040 SaveBackupText(file, "", buffer, UseUnicode);
986 } 1041 }
987 } 1042 }
988 sprintf(buffer,"%c%c",13,10); 1043 sprintf(buffer,"%c%c",13,10);
989 SaveBackupText(file, "", buffer, UseUnicode); 1044 SaveBackupText(file, "", buffer, UseUnicode);
990} 1045}
991 1046
992static void SaveFMStationEntry(FILE *file, GSM_FMStation *FMStation, bool UseUnicode) 1047static void SaveFMStationEntry(FILE *file, GSM_FMStation *FMStation, bool UseUnicode)
993{ 1048{
994 unsigned char buffer[1000]; 1049 unsigned char buffer[1000];
995 1050
996 sprintf(buffer,"Location = %i%c%c",FMStation->Location,13,10); 1051 sprintf(buffer,"Location = %i%c%c",FMStation->Location,13,10);
997 SaveBackupText(file, "", buffer, UseUnicode); 1052 SaveBackupText(file, "", buffer, UseUnicode);
998 SaveBackupText(file, "StationName", FMStation->StationName, UseUnicode); 1053 SaveBackupText(file, "StationName", FMStation->StationName, UseUnicode);
999 sprintf(buffer,"Frequency = %f%c%c",FMStation->Frequency,13,10); 1054 sprintf(buffer,"Frequency = %f%c%c",FMStation->Frequency,13,10);
1000 SaveBackupText(file, "", buffer, UseUnicode); 1055 SaveBackupText(file, "", buffer, UseUnicode);
1001 sprintf(buffer,"%c%c",13,10); 1056 sprintf(buffer,"%c%c",13,10);
1002 SaveBackupText(file, "", buffer, UseUnicode); 1057 SaveBackupText(file, "", buffer, UseUnicode);
1003} 1058}
1004 1059
1005static void SaveGPRSPointEntry(FILE *file, GSM_GPRSAccessPoint *GPRSPoint, bool UseUnicode) 1060static void SaveGPRSPointEntry(FILE *file, GSM_GPRSAccessPoint *GPRSPoint, bool UseUnicode)
1006{ 1061{
1007 unsigned char buffer[1000]; 1062 unsigned char buffer[1000];
1008 1063
1009 sprintf(buffer,"Location = %i%c%c",GPRSPoint->Location,13,10); 1064 sprintf(buffer,"Location = %i%c%c",GPRSPoint->Location,13,10);
1010 SaveBackupText(file, "", buffer, UseUnicode); 1065 SaveBackupText(file, "", buffer, UseUnicode);
1011 SaveBackupText(file, "Name", GPRSPoint->Name, UseUnicode); 1066 SaveBackupText(file, "Name", GPRSPoint->Name, UseUnicode);
1012 SaveBackupText(file, "URL", GPRSPoint->URL, UseUnicode); 1067 SaveBackupText(file, "URL", GPRSPoint->URL, UseUnicode);
1013 if (GPRSPoint->Active) { 1068 if (GPRSPoint->Active) {
1014 sprintf(buffer,"Active = Yes%c%c",13,10); 1069 sprintf(buffer,"Active = Yes%c%c",13,10);
1015 SaveBackupText(file, "", buffer, UseUnicode); 1070 SaveBackupText(file, "", buffer, UseUnicode);
1016 } 1071 }
1017 sprintf(buffer,"%c%c",13,10); 1072 sprintf(buffer,"%c%c",13,10);
1018 SaveBackupText(file, "", buffer, UseUnicode); 1073 SaveBackupText(file, "", buffer, UseUnicode);
1019} 1074}
1020 1075
1021GSM_Error SaveBackup(char *FileName, GSM_Backup *backup, bool UseUnicode) 1076GSM_Error SaveBackup(char *FileName, GSM_Backup *backup, bool UseUnicode)
1022{ 1077{
1023 int i; 1078 int i;
1024 unsigned char buffer[1000],checksum[200]; 1079 unsigned char buffer[1000],checksum[200];
1025 FILE *file; 1080 FILE *file;
1026 1081
1027 file = fopen(FileName, "wb"); 1082 file = fopen(FileName, "wb");
1028 if (file == NULL) return ERR_CANTOPENFILE; 1083 if (file == NULL) return ERR_CANTOPENFILE;
1029 1084
1030 if (UseUnicode) { 1085 if (UseUnicode) {
1031 sprintf(buffer,"%c%c", 0xFE, 0xFF); 1086 sprintf(buffer,"%c%c", 0xFE, 0xFF);
1032 SaveBackupText(file, "", buffer, false); 1087 SaveBackupText(file, "", buffer, false);
1033 } 1088 }
1034 1089
1035 sprintf(buffer,"# Format of this file was designed for Gammu (see www.mwiacek.com)%c%c%c%c",13,10,13,10); 1090 sprintf(buffer,"# Format of this file was designed for Gammu (see www.mwiacek.com)%c%c%c%c",13,10,13,10);
1036 SaveBackupText(file, "", buffer, UseUnicode); 1091 SaveBackupText(file, "", buffer, UseUnicode);
1037 sprintf(buffer,"[Backup]%c%c",13,10); 1092 sprintf(buffer,"[Backup]%c%c",13,10);
1038 SaveBackupText(file, "", buffer, UseUnicode); 1093 SaveBackupText(file, "", buffer, UseUnicode);
1039 sprintf(buffer,"IMEI = \"%s\"%c%c",backup->IMEI,13,10); 1094 sprintf(buffer,"IMEI = \"%s\"%c%c",backup->IMEI,13,10);
1040 SaveBackupText(file, "", buffer, UseUnicode); 1095 SaveBackupText(file, "", buffer, UseUnicode);
1041 sprintf(buffer,"Phone = \"%s\"%c%c",backup->Model,13,10); 1096 sprintf(buffer,"Phone = \"%s\"%c%c",backup->Model,13,10);
1042 SaveBackupText(file, "", buffer, UseUnicode); 1097 SaveBackupText(file, "", buffer, UseUnicode);
1043 if (backup->Creator[0] != 0) { 1098 if (backup->Creator[0] != 0) {
1044 sprintf(buffer,"Creator = \"%s\"%c%c",backup->Creator,13,10); 1099 sprintf(buffer,"Creator = \"%s\"%c%c",backup->Creator,13,10);
1045 SaveBackupText(file, "", buffer, UseUnicode); 1100 SaveBackupText(file, "", buffer, UseUnicode);
1046 } 1101 }
1047 if (backup->DateTimeAvailable) { 1102 if (backup->DateTimeAvailable) {
1048 SaveBackupText(file, "", "DateTime", UseUnicode); 1103 SaveBackupText(file, "", "DateTime", UseUnicode);
1049 SaveVCalDateTime(file, &backup->DateTime, UseUnicode); 1104 SaveVCalDateTime(file, &backup->DateTime, UseUnicode);
1050 } 1105 }
1051 sprintf(buffer,"Format = 1.03%c%c",13,10); 1106 sprintf(buffer,"Format = 1.03%c%c",13,10);
1052 SaveBackupText(file, "", buffer, UseUnicode); 1107 SaveBackupText(file, "", buffer, UseUnicode);
1053 sprintf(buffer,"%c%c",13,10); 1108 sprintf(buffer,"%c%c",13,10);
1054 SaveBackupText(file, "", buffer, UseUnicode); 1109 SaveBackupText(file, "", buffer, UseUnicode);
1055 1110
1056 i=0; 1111 i=0;
1057 while (backup->PhonePhonebook[i]!=NULL) { 1112 while (backup->PhonePhonebook[i]!=NULL) {
1058 sprintf(buffer,"[PhonePBK%03i]%c%c",i+1,13,10); 1113 sprintf(buffer,"[PhonePBK%03i]%c%c",i+1,13,10);
1059 SaveBackupText(file, "", buffer, UseUnicode); 1114 SaveBackupText(file, "", buffer, UseUnicode);
1060 SavePbkEntry(file, backup->PhonePhonebook[i], UseUnicode); 1115 SavePbkEntry(file, backup->PhonePhonebook[i], UseUnicode);
1061 i++; 1116 i++;
1062 } 1117 }
1063 i=0; 1118 i=0;
1064 while (backup->SIMPhonebook[i]!=NULL) { 1119 while (backup->SIMPhonebook[i]!=NULL) {
1065 sprintf(buffer,"[SIMPBK%03i]%c%c",i+1,13,10); 1120 sprintf(buffer,"[SIMPBK%03i]%c%c",i+1,13,10);
1066 SaveBackupText(file, "", buffer, UseUnicode); 1121 SaveBackupText(file, "", buffer, UseUnicode);
1067 SavePbkEntry(file, backup->SIMPhonebook[i], UseUnicode); 1122 SavePbkEntry(file, backup->SIMPhonebook[i], UseUnicode);
1068 i++; 1123 i++;
1069 } 1124 }
1070 i=0; 1125 i=0;
1071 while (backup->Calendar[i]!=NULL) { 1126 while (backup->Calendar[i]!=NULL) {
1072 sprintf(buffer,"[Calendar%03i]%c%c",i+1,13,10); 1127 sprintf(buffer,"[Calendar%03i]%c%c",i+1,13,10);
1073 SaveBackupText(file, "", buffer, UseUnicode); 1128 SaveBackupText(file, "", buffer, UseUnicode);
1074 SaveCalendarEntry(file, backup->Calendar[i], UseUnicode); 1129 SaveCalendarEntry(file, backup->Calendar[i], UseUnicode);
1075 i++; 1130 i++;
1076 } 1131 }
1077 i=0; 1132 i=0;
1133 while (backup->Note[i]!=NULL) {
1134 sprintf(buffer,"[Note%03i]%c%c",i+1,13,10);
1135 SaveBackupText(file, "", buffer, UseUnicode);
1136 SaveNoteEntry(file, backup->Note[i], UseUnicode);
1137 i++;
1138 }
1139 i=0;
1078 while (backup->CallerLogos[i]!=NULL) { 1140 while (backup->CallerLogos[i]!=NULL) {
1079 sprintf(buffer,"[Caller%03i]%c%c",i+1,13,10); 1141 sprintf(buffer,"[Caller%03i]%c%c",i+1,13,10);
1080 SaveBackupText(file, "", buffer, UseUnicode); 1142 SaveBackupText(file, "", buffer, UseUnicode);
1081 SaveCallerEntry(file, backup->CallerLogos[i], UseUnicode); 1143 SaveCallerEntry(file, backup->CallerLogos[i], UseUnicode);
1082 i++; 1144 i++;
1083 } 1145 }
1084 i=0; 1146 i=0;
1085 while (backup->SMSC[i]!=NULL) { 1147 while (backup->SMSC[i]!=NULL) {
1086 sprintf(buffer,"[SMSC%03i]%c%c",i+1,13,10); 1148 sprintf(buffer,"[SMSC%03i]%c%c",i+1,13,10);
1087 SaveBackupText(file, "", buffer, UseUnicode); 1149 SaveBackupText(file, "", buffer, UseUnicode);
1088 SaveSMSCEntry(file, backup->SMSC[i], UseUnicode); 1150 SaveSMSCEntry(file, backup->SMSC[i], UseUnicode);
1089 i++; 1151 i++;
1090 } 1152 }
1091 i=0; 1153 i=0;
1092 while (backup->WAPBookmark[i]!=NULL) { 1154 while (backup->WAPBookmark[i]!=NULL) {
1093 sprintf(buffer,"[WAPBookmark%03i]%c%c",i+1,13,10); 1155 sprintf(buffer,"[WAPBookmark%03i]%c%c",i+1,13,10);
1094 SaveBackupText(file, "", buffer, UseUnicode); 1156 SaveBackupText(file, "", buffer, UseUnicode);
1095 SaveWAPBookmarkEntry(file, backup->WAPBookmark[i], UseUnicode); 1157 SaveWAPBookmarkEntry(file, backup->WAPBookmark[i], UseUnicode);
1096 i++; 1158 i++;
1097 } 1159 }
1098 i=0; 1160 i=0;
1099 while (backup->WAPSettings[i]!=NULL) { 1161 while (backup->WAPSettings[i]!=NULL) {
1100 sprintf(buffer,"[WAPSettings%03i]%c%c",i+1,13,10); 1162 sprintf(buffer,"[WAPSettings%03i]%c%c",i+1,13,10);
1101 SaveBackupText(file, "", buffer, UseUnicode); 1163 SaveBackupText(file, "", buffer, UseUnicode);
1102 SaveWAPSettingsEntry(file, backup->WAPSettings[i], UseUnicode); 1164 SaveWAPSettingsEntry(file, backup->WAPSettings[i], UseUnicode);
1103 i++; 1165 i++;
1104 } 1166 }
1105 i=0; 1167 i=0;
1106 while (backup->MMSSettings[i]!=NULL) { 1168 while (backup->MMSSettings[i]!=NULL) {
1107 sprintf(buffer,"[MMSSettings%03i]%c%c",i+1,13,10); 1169 sprintf(buffer,"[MMSSettings%03i]%c%c",i+1,13,10);
1108 SaveBackupText(file, "", buffer, UseUnicode); 1170 SaveBackupText(file, "", buffer, UseUnicode);
1109 SaveWAPSettingsEntry(file, backup->MMSSettings[i], UseUnicode); 1171 SaveWAPSettingsEntry(file, backup->MMSSettings[i], UseUnicode);
1110 i++; 1172 i++;
1111 } 1173 }
1112 i=0; 1174 i=0;
1175 while (backup->SyncMLSettings[i]!=NULL) {
1176 sprintf(buffer,"[SyncMLSettings%03i]%c%c",i+1,13,10);
1177 SaveBackupText(file, "", buffer, UseUnicode);
1178 SaveSyncMLSettingsEntry(file, backup->SyncMLSettings[i], UseUnicode);
1179 i++;
1180 }
1181 i=0;
1182 while (backup->ChatSettings[i]!=NULL) {
1183 sprintf(buffer,"[ChatSettings%03i]%c%c",i+1,13,10);
1184 SaveBackupText(file, "", buffer, UseUnicode);
1185 SaveChatSettingsEntry(file, backup->ChatSettings[i], UseUnicode);
1186 i++;
1187 }
1188 i=0;
1113 while (backup->Ringtone[i]!=NULL) { 1189 while (backup->Ringtone[i]!=NULL) {
1114 sprintf(buffer,"[Ringtone%03i]%c%c",i+1,13,10); 1190 sprintf(buffer,"[Ringtone%03i]%c%c",i+1,13,10);
1115 SaveBackupText(file, "", buffer, UseUnicode); 1191 SaveBackupText(file, "", buffer, UseUnicode);
1116 SaveRingtoneEntry(file, backup->Ringtone[i], UseUnicode); 1192 SaveRingtoneEntry(file, backup->Ringtone[i], UseUnicode);
1117 i++; 1193 i++;
1118 } 1194 }
1119 i=0; 1195 i=0;
1120 while (backup->ToDo[i]!=NULL) { 1196 while (backup->ToDo[i]!=NULL) {
1121 sprintf(buffer,"[TODO%03i]%c%c",i+1,13,10); 1197 sprintf(buffer,"[TODO%03i]%c%c",i+1,13,10);
1122 SaveBackupText(file, "", buffer, UseUnicode); 1198 SaveBackupText(file, "", buffer, UseUnicode);
1123 SaveToDoEntry(file, backup->ToDo[i], UseUnicode); 1199 SaveToDoEntry(file, backup->ToDo[i], UseUnicode);
1124 i++; 1200 i++;
1125 } 1201 }
1126 i=0; 1202 i=0;
1127 while (backup->Profiles[i]!=NULL) { 1203 while (backup->Profiles[i]!=NULL) {
1128 sprintf(buffer,"[Profile%03i]%c%c",i+1,13,10); 1204 sprintf(buffer,"[Profile%03i]%c%c",i+1,13,10);
1129 SaveBackupText(file, "", buffer, UseUnicode); 1205 SaveBackupText(file, "", buffer, UseUnicode);
1130 SaveProfileEntry(file, backup->Profiles[i], UseUnicode); 1206 SaveProfileEntry(file, backup->Profiles[i], UseUnicode);
1131 i++; 1207 i++;
1132 } 1208 }
1133 i=0; 1209 i=0;
1134 while (backup->FMStation[i]!=NULL) { 1210 while (backup->FMStation[i]!=NULL) {
1135 sprintf(buffer,"[FMStation%03i]%c%c",i+1,13,10); 1211 sprintf(buffer,"[FMStation%03i]%c%c",i+1,13,10);
1136 SaveBackupText(file, "", buffer, UseUnicode); 1212 SaveBackupText(file, "", buffer, UseUnicode);
1137 SaveFMStationEntry(file, backup->FMStation[i], UseUnicode); 1213 SaveFMStationEntry(file, backup->FMStation[i], UseUnicode);
1138 i++; 1214 i++;
1139 } 1215 }
1140 i=0; 1216 i=0;
1141 while (backup->GPRSPoint[i]!=NULL) { 1217 while (backup->GPRSPoint[i]!=NULL) {
1142 sprintf(buffer,"[GPRSPoint%03i]%c%c",i+1,13,10); 1218 sprintf(buffer,"[GPRSPoint%03i]%c%c",i+1,13,10);
1143 SaveBackupText(file, "", buffer, UseUnicode); 1219 SaveBackupText(file, "", buffer, UseUnicode);
1144 SaveGPRSPointEntry(file, backup->GPRSPoint[i], UseUnicode); 1220 SaveGPRSPointEntry(file, backup->GPRSPoint[i], UseUnicode);
1145 i++; 1221 i++;
1146 } 1222 }
1147 1223
1148 if (backup->StartupLogo!=NULL) { 1224 if (backup->StartupLogo!=NULL) {
1149 SaveStartupEntry(file, backup->StartupLogo, UseUnicode); 1225 SaveStartupEntry(file, backup->StartupLogo, UseUnicode);
1150 } 1226 }
1151 if (backup->OperatorLogo!=NULL) { 1227 if (backup->OperatorLogo!=NULL) {
1152 SaveOperatorEntry(file, backup->OperatorLogo, UseUnicode); 1228 SaveOperatorEntry(file, backup->OperatorLogo, UseUnicode);
1153 } 1229 }
1154 1230
1155 fclose(file); 1231 fclose(file);
1156 1232
1157 FindBackupChecksum(FileName, UseUnicode, checksum); 1233 FindBackupChecksum(FileName, UseUnicode, checksum);
1158 1234
1159 file = fopen(FileName, "ab"); 1235 file = fopen(FileName, "ab");
1160 if (file == NULL) return ERR_CANTOPENFILE; 1236 if (file == NULL) return ERR_CANTOPENFILE;
1161 sprintf(buffer,"[Checksum]%c%c",13,10); 1237 sprintf(buffer,"[Checksum]%c%c",13,10);
1162 SaveBackupText(file, "", buffer, UseUnicode); 1238 SaveBackupText(file, "", buffer, UseUnicode);
1163 sprintf(buffer,"MD5=%s%c%c",checksum,13,10); 1239 sprintf(buffer,"MD5=%s%c%c",checksum,13,10);
1164 SaveBackupText(file, "", buffer, UseUnicode); 1240 SaveBackupText(file, "", buffer, UseUnicode);
1165 fclose(file); 1241 fclose(file);
1166 1242
1167 return ERR_NONE; 1243 return ERR_NONE;
1168} 1244}
1169 1245
1170static void ReadPbkEntry(INI_Section *file_info, char *section, GSM_MemoryEntry *Pbk, bool UseUnicode) 1246static void ReadPbkEntry(INI_Section *file_info, char *section, GSM_MemoryEntry *Pbk, bool UseUnicode)
1171{ 1247{
1172 unsigned char buffer[10000]; 1248 unsigned char buffer[10000];
1173 char *readvalue; 1249 char *readvalue;
1174 int num,i; 1250 int num,i;
1175 INI_Entry *e; 1251 INI_Entry *e;
1176 1252
1177 Pbk->EntriesNum = 0; 1253 Pbk->EntriesNum = 0;
1178 e = INI_FindLastSectionEntry(file_info, section, UseUnicode); 1254 e = INI_FindLastSectionEntry(file_info, section, UseUnicode);
1179 1255
1180 while (e != NULL) { 1256 while (e != NULL) {
1181 num = -1; 1257 num = -1;
1182 if (UseUnicode) { 1258 if (UseUnicode) {
1183 sprintf(buffer,"%s",DecodeUnicodeString(e->EntryName)); 1259 sprintf(buffer,"%s",DecodeUnicodeString(e->EntryName));
1184 } else { 1260 } else {
1185 sprintf(buffer,"%s",e->EntryName); 1261 sprintf(buffer,"%s",e->EntryName);
1186 } 1262 }
1187 if (strlen(buffer) == 11) { 1263 if (strlen(buffer) == 11) {
1188 if (mystrncasecmp("Entry", buffer, 5) && 1264 if (mystrncasecmp("Entry", buffer, 5) &&
1189 mystrncasecmp("Type", buffer+7, 4)) { 1265 mystrncasecmp("Type", buffer+7, 4)) {
1190 num = atoi(buffer+5); 1266 num = atoi(buffer+5);
1191 } 1267 }
1192 } 1268 }
1193 e = e->Prev; 1269 e = e->Prev;
1194 if (num != -1) { 1270 if (num != -1) {
1195 sprintf(buffer,"Entry%02iType",num); 1271 sprintf(buffer,"Entry%02iType",num);
1196 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode); 1272 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1197 if (mystrncasecmp(readvalue,"NumberGeneral",0)) { 1273 if (mystrncasecmp(readvalue,"NumberGeneral",0)) {
1198 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_General; 1274 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_General;
1199 } else if (mystrncasecmp(readvalue,"NumberMobile",0)) { 1275 } else if (mystrncasecmp(readvalue,"NumberMobile",0)) {
1200 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Mobile; 1276 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Mobile;
1201 } else if (mystrncasecmp(readvalue,"NumberWork",0)) { 1277 } else if (mystrncasecmp(readvalue,"NumberWork",0)) {
1202 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Work; 1278 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Work;
1203 } else if (mystrncasecmp(readvalue,"NumberFax",0)) { 1279 } else if (mystrncasecmp(readvalue,"NumberFax",0)) {
1204 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Fax; 1280 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Fax;
1205 } else if (mystrncasecmp(readvalue,"NumberHome",0)) { 1281 } else if (mystrncasecmp(readvalue,"NumberHome",0)) {
1206 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Home; 1282 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Home;
1207 } else if (mystrncasecmp(readvalue,"NumberOther",0)) { 1283 } else if (mystrncasecmp(readvalue,"NumberOther",0)) {
1208 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Other; 1284 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Other;
1209 } else if (mystrncasecmp(readvalue,"NumberPager",0)) { 1285 } else if (mystrncasecmp(readvalue,"NumberPager",0)) {
1210 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Pager; 1286 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Number_Pager;
1211 } else if (mystrncasecmp(readvalue,"Note",0)) { 1287 } else if (mystrncasecmp(readvalue,"Note",0)) {
1212 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Note; 1288 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Note;
1213 } else if (mystrncasecmp(readvalue,"Postal",0)) { 1289 } else if (mystrncasecmp(readvalue,"Postal",0)) {
1214 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Postal; 1290 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Postal;
1215 } else if (mystrncasecmp(readvalue,"Email",0)) { 1291 } else if (mystrncasecmp(readvalue,"Email",0)) {
1216 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Email; 1292 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Email;
1217 } else if (mystrncasecmp(readvalue,"Email2",0)) { 1293 } else if (mystrncasecmp(readvalue,"Email2",0)) {
1218 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Email2; 1294 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Email2;
1219 } else if (mystrncasecmp(readvalue,"URL",0)) { 1295 } else if (mystrncasecmp(readvalue,"URL",0)) {
1220 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_URL; 1296 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_URL;
1221 } else if (mystrncasecmp(readvalue,"FirstName",0)) { 1297 } else if (mystrncasecmp(readvalue,"FirstName",0)) {
1222 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_FirstName; 1298 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_FirstName;
1223 } else if (mystrncasecmp(readvalue,"LastName",0)) { 1299 } else if (mystrncasecmp(readvalue,"LastName",0)) {
1224 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_LastName; 1300 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_LastName;
1225 } else if (mystrncasecmp(readvalue,"Company",0)) { 1301 } else if (mystrncasecmp(readvalue,"Company",0)) {
1226 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Company; 1302 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Company;
1227 } else if (mystrncasecmp(readvalue,"JobTitle",0)) { 1303 } else if (mystrncasecmp(readvalue,"JobTitle",0)) {
1228 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_JobTitle; 1304 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_JobTitle;
1229 } else if (mystrncasecmp(readvalue,"Address",0)) { 1305 } else if (mystrncasecmp(readvalue,"Address",0)) {
1230 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_StreetAddress; 1306 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_StreetAddress;
1231 } else if (mystrncasecmp(readvalue,"City",0)) { 1307 } else if (mystrncasecmp(readvalue,"City",0)) {
1232 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_City; 1308 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_City;
1233 } else if (mystrncasecmp(readvalue,"State",0)) { 1309 } else if (mystrncasecmp(readvalue,"State",0)) {
1234 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_State; 1310 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_State;
1235 } else if (mystrncasecmp(readvalue,"Zip",0)) { 1311 } else if (mystrncasecmp(readvalue,"Zip",0)) {
1236 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Zip; 1312 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Zip;
1237 } else if (mystrncasecmp(readvalue,"Country",0)) { 1313 } else if (mystrncasecmp(readvalue,"Country",0)) {
1238 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Country; 1314 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Country;
1239 } else if (mystrncasecmp(readvalue,"Custom1",0)) { 1315 } else if (mystrncasecmp(readvalue,"Custom1",0)) {
1240 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Custom1; 1316 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Custom1;
1241 } else if (mystrncasecmp(readvalue,"Custom2",0)) { 1317 } else if (mystrncasecmp(readvalue,"Custom2",0)) {
1242 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Custom2; 1318 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Custom2;
1243 } else if (mystrncasecmp(readvalue,"Custom3",0)) { 1319 } else if (mystrncasecmp(readvalue,"Custom3",0)) {
1244 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Custom3; 1320 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Custom3;
1245 } else if (mystrncasecmp(readvalue,"Custom4",0)) { 1321 } else if (mystrncasecmp(readvalue,"Custom4",0)) {
1246 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Custom4; 1322 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Custom4;
1247 } else if (mystrncasecmp(readvalue,"Name",0)) { 1323 } else if (mystrncasecmp(readvalue,"Name",0)) {
1248 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Name; 1324 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_Name;
1249 } else if (mystrncasecmp(readvalue,"Category",0)) { 1325 } else if (mystrncasecmp(readvalue,"Category",0)) {
1250 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Category; 1326 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Category;
1251 Pbk->Entries[Pbk->EntriesNum].Number = 0; 1327 Pbk->Entries[Pbk->EntriesNum].Number = 0;
1252 sprintf(buffer,"Entry%02iNumber",num); 1328 sprintf(buffer,"Entry%02iNumber",num);
1253 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode); 1329 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1254 if (readvalue!=NULL) { 1330 if (readvalue!=NULL) {
1255 Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue); 1331 Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue);
1256 } 1332 }
1257 Pbk->EntriesNum ++; 1333 Pbk->EntriesNum ++;
1258 continue; 1334 continue;
1259 } else if (mystrncasecmp(readvalue,"Private",0)) { 1335 } else if (mystrncasecmp(readvalue,"Private",0)) {
1260 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Private; 1336 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Private;
1261 Pbk->Entries[Pbk->EntriesNum].Number = 0; 1337 Pbk->Entries[Pbk->EntriesNum].Number = 0;
1262 sprintf(buffer,"Entry%02iNumber",num); 1338 sprintf(buffer,"Entry%02iNumber",num);
1263 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode); 1339 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1264 if (readvalue!=NULL) { 1340 if (readvalue!=NULL) {
1265 Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue); 1341 Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue);
1266 } 1342 }
1267 Pbk->EntriesNum ++; 1343 Pbk->EntriesNum ++;
1268 continue; 1344 continue;
1269 } else if (mystrncasecmp(readvalue,"CallerGroup",0)) { 1345 } else if (mystrncasecmp(readvalue,"CallerGroup",0)) {
1270 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Caller_Group; 1346 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Caller_Group;
1271 Pbk->Entries[Pbk->EntriesNum].Number = 0; 1347 Pbk->Entries[Pbk->EntriesNum].Number = 0;
1272 sprintf(buffer,"Entry%02iNumber",num); 1348 sprintf(buffer,"Entry%02iNumber",num);
1273 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode); 1349 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1274 if (readvalue!=NULL) { 1350 if (readvalue!=NULL) {
1275 Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue); 1351 Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue);
1276 } 1352 }
1277 Pbk->EntriesNum ++; 1353 Pbk->EntriesNum ++;
1278 continue; 1354 continue;
1279 } else if (mystrncasecmp(readvalue,"RingtoneID",0)) { 1355 } else if (mystrncasecmp(readvalue,"RingtoneID",0)) {
1280 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_RingtoneID; 1356 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_RingtoneID;
1281 Pbk->Entries[Pbk->EntriesNum].Number = 0; 1357 Pbk->Entries[Pbk->EntriesNum].Number = 0;
1282 sprintf(buffer,"Entry%02iNumber",num); 1358 sprintf(buffer,"Entry%02iNumber",num);
1283 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode); 1359 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1284 if (readvalue!=NULL) { 1360 if (readvalue!=NULL) {
1285 Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue); 1361 Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue);
1286 } 1362 }
1287 Pbk->EntriesNum ++; 1363 Pbk->EntriesNum ++;
1288 continue; 1364 continue;
1289 } else if (mystrncasecmp(readvalue,"PictureID",0)) { 1365 } else if (mystrncasecmp(readvalue,"PictureID",0)) {
1290 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_PictureID; 1366 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_PictureID;
1291 Pbk->Entries[Pbk->EntriesNum].Number = 0; 1367 Pbk->Entries[Pbk->EntriesNum].Number = 0;
1292 sprintf(buffer,"Entry%02iNumber",num); 1368 sprintf(buffer,"Entry%02iNumber",num);
1293 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode); 1369 readvalue = ReadCFGText(file_info, section, buffer, UseUnicode);
1294 if (readvalue!=NULL) { 1370 if (readvalue!=NULL) {
1295 Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue); 1371 Pbk->Entries[Pbk->EntriesNum].Number = atoi(readvalue);
1296 } 1372 }
1297 Pbk->EntriesNum ++; 1373 Pbk->EntriesNum ++;
1298 continue; 1374 continue;
1299 } else if (mystrncasecmp(readvalue,"UserID",0)) { 1375 } else if (mystrncasecmp(readvalue,"UserID",0)) {
1300 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_UserID; 1376 Pbk->Entries[Pbk->EntriesNum].EntryType = PBK_Text_UserID;
1301 } 1377 }
1302 sprintf(buffer,"Entry%02iText",num); 1378 sprintf(buffer,"Entry%02iText",num);
1303 ReadBackupText(file_info, section, buffer, Pbk->Entries[Pbk->EntriesNum].Text,UseUnicode); 1379 ReadBackupText(file_info, section, buffer, Pbk->Entries[Pbk->EntriesNum].Text,UseUnicode);
1304 dbgprintf("text \"%s\", type %i\n",DecodeUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text),Pbk->Entries[Pbk->EntriesNum].EntryType); 1380 dbgprintf("text \"%s\", type %i\n",DecodeUnicodeString(Pbk->Entries[Pbk->EntriesNum].Text),Pbk->Entries[Pbk->EntriesNum].EntryType);
@@ -2467,385 +2543,510 @@ GSM_Error LoadBackup(char *FileName, GSM_Backup *backup, bool UseUnicode)
2467 } else { 2543 } else {
2468 if (mystrncasecmp("WAPSettings", h->SectionName, 11)) found = true; 2544 if (mystrncasecmp("WAPSettings", h->SectionName, 11)) found = true;
2469 if (!found) { 2545 if (!found) {
2470 if (mystrncasecmp("Settings", h->SectionName, 8)) found = true; 2546 if (mystrncasecmp("Settings", h->SectionName, 8)) found = true;
2471 } 2547 }
2472 } 2548 }
2473 if (found) { 2549 if (found) {
2474 readvalue = ReadCFGText(file_info, h->SectionName, "Title00", UseUnicode); 2550 readvalue = ReadCFGText(file_info, h->SectionName, "Title00", UseUnicode);
2475 if (readvalue==NULL) break; 2551 if (readvalue==NULL) break;
2476 if (num < GSM_BACKUP_MAX_WAPSETTINGS) { 2552 if (num < GSM_BACKUP_MAX_WAPSETTINGS) {
2477 backup->WAPSettings[num] = malloc(sizeof(GSM_MultiWAPSettings)); 2553 backup->WAPSettings[num] = malloc(sizeof(GSM_MultiWAPSettings));
2478 if (backup->WAPSettings[num] == NULL) return ERR_MOREMEMORY; 2554 if (backup->WAPSettings[num] == NULL) return ERR_MOREMEMORY;
2479 backup->WAPSettings[num + 1] = NULL; 2555 backup->WAPSettings[num + 1] = NULL;
2480 } else { 2556 } else {
2481 dbgprintf("Increase GSM_BACKUP_MAX_WAPSETTINGS\n"); 2557 dbgprintf("Increase GSM_BACKUP_MAX_WAPSETTINGS\n");
2482 return ERR_MOREMEMORY; 2558 return ERR_MOREMEMORY;
2483 } 2559 }
2484 backup->WAPSettings[num]->Location = num + 1; 2560 backup->WAPSettings[num]->Location = num + 1;
2485 dbgprintf("reading wap settings\n"); 2561 dbgprintf("reading wap settings\n");
2486 ReadWAPSettingsEntry(file_info, h->SectionName, backup->WAPSettings[num],UseUnicode); 2562 ReadWAPSettingsEntry(file_info, h->SectionName, backup->WAPSettings[num],UseUnicode);
2487 num++; 2563 num++;
2488 } 2564 }
2489 } 2565 }
2490 num = 0; 2566 num = 0;
2491 for (h = file_info; h != NULL; h = h->Next) { 2567 for (h = file_info; h != NULL; h = h->Next) {
2492 found = false; 2568 found = false;
2493 if (UseUnicode) { 2569 if (UseUnicode) {
2494 EncodeUnicode(buffer,"MMSSettings",8); 2570 EncodeUnicode(buffer,"MMSSettings",8);
2495 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true; 2571 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true;
2496 } else { 2572 } else {
2497 if (mystrncasecmp("MMSSettings", h->SectionName, 8)) found = true; 2573 if (mystrncasecmp("MMSSettings", h->SectionName, 8)) found = true;
2498 } 2574 }
2499 if (found) { 2575 if (found) {
2500 readvalue = ReadCFGText(file_info, h->SectionName, "Title00", UseUnicode); 2576 readvalue = ReadCFGText(file_info, h->SectionName, "Title00", UseUnicode);
2501 if (readvalue==NULL) break; 2577 if (readvalue==NULL) break;
2502 if (num < GSM_BACKUP_MAX_MMSSETTINGS) { 2578 if (num < GSM_BACKUP_MAX_MMSSETTINGS) {
2503 backup->MMSSettings[num] = malloc(sizeof(GSM_MultiWAPSettings)); 2579 backup->MMSSettings[num] = malloc(sizeof(GSM_MultiWAPSettings));
2504 if (backup->MMSSettings[num] == NULL) return ERR_MOREMEMORY; 2580 if (backup->MMSSettings[num] == NULL) return ERR_MOREMEMORY;
2505 backup->MMSSettings[num + 1] = NULL; 2581 backup->MMSSettings[num + 1] = NULL;
2506 } else { 2582 } else {
2507 dbgprintf("Increase GSM_BACKUP_MAX_MMSSETTINGS\n"); 2583 dbgprintf("Increase GSM_BACKUP_MAX_MMSSETTINGS\n");
2508 return ERR_MOREMEMORY; 2584 return ERR_MOREMEMORY;
2509 } 2585 }
2510 backup->MMSSettings[num]->Location = num + 1; 2586 backup->MMSSettings[num]->Location = num + 1;
2511 dbgprintf("reading mms settings\n"); 2587 dbgprintf("reading mms settings\n");
2512 ReadWAPSettingsEntry(file_info, h->SectionName, backup->MMSSettings[num],UseUnicode); 2588 ReadWAPSettingsEntry(file_info, h->SectionName, backup->MMSSettings[num],UseUnicode);
2513 num++; 2589 num++;
2514 } 2590 }
2515 } 2591 }
2516 num = 0; 2592 num = 0;
2517 for (h = file_info; h != NULL; h = h->Next) { 2593 for (h = file_info; h != NULL; h = h->Next) {
2518 found = false; 2594 found = false;
2519 if (UseUnicode) { 2595 if (UseUnicode) {
2520 EncodeUnicode(buffer,"Ringtone",8); 2596 EncodeUnicode(buffer,"Ringtone",8);
2521 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true; 2597 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true;
2522 } else { 2598 } else {
2523 if (mystrncasecmp("Ringtone", h->SectionName, 8)) found = true; 2599 if (mystrncasecmp("Ringtone", h->SectionName, 8)) found = true;
2524 } 2600 }
2525 if (found) { 2601 if (found) {
2526 readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode); 2602 readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
2527 if (readvalue==NULL) break; 2603 if (readvalue==NULL) break;
2528 if (num < GSM_BACKUP_MAX_RINGTONES) { 2604 if (num < GSM_BACKUP_MAX_RINGTONES) {
2529 backup->Ringtone[num] = malloc(sizeof(GSM_Ringtone)); 2605 backup->Ringtone[num] = malloc(sizeof(GSM_Ringtone));
2530 if (backup->Ringtone[num] == NULL) return ERR_MOREMEMORY; 2606 if (backup->Ringtone[num] == NULL) return ERR_MOREMEMORY;
2531 backup->Ringtone[num + 1] = NULL; 2607 backup->Ringtone[num + 1] = NULL;
2532 } else { 2608 } else {
2533 dbgprintf("Increase GSM_BACKUP_MAX_RINGTONES\n"); 2609 dbgprintf("Increase GSM_BACKUP_MAX_RINGTONES\n");
2534 return ERR_MOREMEMORY; 2610 return ERR_MOREMEMORY;
2535 } 2611 }
2536 ReadRingtoneEntry(file_info, h->SectionName, backup->Ringtone[num],UseUnicode); 2612 ReadRingtoneEntry(file_info, h->SectionName, backup->Ringtone[num],UseUnicode);
2537 num++; 2613 num++;
2538 } 2614 }
2539 } 2615 }
2540 num = 0; 2616 num = 0;
2541 for (h = file_info; h != NULL; h = h->Next) { 2617 for (h = file_info; h != NULL; h = h->Next) {
2542 found = false; 2618 found = false;
2543 if (UseUnicode) { 2619 if (UseUnicode) {
2544 EncodeUnicode(buffer,"TODO",4); 2620 EncodeUnicode(buffer,"TODO",4);
2545 if (mywstrncasecmp(buffer, h->SectionName, 4)) found = true; 2621 if (mywstrncasecmp(buffer, h->SectionName, 4)) found = true;
2546 } else { 2622 } else {
2547 if (mystrncasecmp("TODO", h->SectionName, 4)) found = true; 2623 if (mystrncasecmp("TODO", h->SectionName, 4)) found = true;
2548 } 2624 }
2549 if (found) { 2625 if (found) {
2550 readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode); 2626 readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
2551 if (readvalue==NULL) break; 2627 if (readvalue==NULL) break;
2552 if (num < GSM_MAXCALENDARTODONOTES) { 2628 if (num < GSM_MAXCALENDARTODONOTES) {
2553 backup->ToDo[num] = malloc(sizeof(GSM_ToDoEntry)); 2629 backup->ToDo[num] = malloc(sizeof(GSM_ToDoEntry));
2554 if (backup->ToDo[num] == NULL) return ERR_MOREMEMORY; 2630 if (backup->ToDo[num] == NULL) return ERR_MOREMEMORY;
2555 backup->ToDo[num + 1] = NULL; 2631 backup->ToDo[num + 1] = NULL;
2556 } else { 2632 } else {
2557 dbgprintf("Increase GSM_MAXCALENDARTODONOTES\n"); 2633 dbgprintf("Increase GSM_MAXCALENDARTODONOTES\n");
2558 return ERR_MOREMEMORY; 2634 return ERR_MOREMEMORY;
2559 } 2635 }
2560 backup->ToDo[num]->Location = num + 1; 2636 backup->ToDo[num]->Location = num + 1;
2561 ReadToDoEntry(file_info, h->SectionName, backup->ToDo[num],UseUnicode); 2637 ReadToDoEntry(file_info, h->SectionName, backup->ToDo[num],UseUnicode);
2562 num++; 2638 num++;
2563 } 2639 }
2564 } 2640 }
2565 sprintf(buffer,"Startup"); 2641 sprintf(buffer,"Startup");
2566 readvalue = ReadCFGText(file_info, buffer, "Text", UseUnicode); 2642 readvalue = ReadCFGText(file_info, buffer, "Text", UseUnicode);
2567 if (readvalue==NULL) { 2643 if (readvalue==NULL) {
2568 readvalue = ReadCFGText(file_info, buffer, "Width", UseUnicode); 2644 readvalue = ReadCFGText(file_info, buffer, "Width", UseUnicode);
2569 } 2645 }
2570 if (readvalue!=NULL) { 2646 if (readvalue!=NULL) {
2571 backup->StartupLogo = malloc(sizeof(GSM_Bitmap)); 2647 backup->StartupLogo = malloc(sizeof(GSM_Bitmap));
2572 if (backup->StartupLogo == NULL) return ERR_MOREMEMORY; 2648 if (backup->StartupLogo == NULL) return ERR_MOREMEMORY;
2573 ReadStartupEntry(file_info, buffer, backup->StartupLogo,UseUnicode); 2649 ReadStartupEntry(file_info, buffer, backup->StartupLogo,UseUnicode);
2574 } 2650 }
2575 sprintf(buffer,"Operator"); 2651 sprintf(buffer,"Operator");
2576 readvalue = ReadCFGText(file_info, buffer, "Network", UseUnicode); 2652 readvalue = ReadCFGText(file_info, buffer, "Network", UseUnicode);
2577 if (readvalue!=NULL) { 2653 if (readvalue!=NULL) {
2578 backup->OperatorLogo = malloc(sizeof(GSM_Bitmap)); 2654 backup->OperatorLogo = malloc(sizeof(GSM_Bitmap));
2579 if (backup->OperatorLogo == NULL) return ERR_MOREMEMORY; 2655 if (backup->OperatorLogo == NULL) return ERR_MOREMEMORY;
2580 ReadOperatorEntry(file_info, buffer, backup->OperatorLogo,UseUnicode); 2656 ReadOperatorEntry(file_info, buffer, backup->OperatorLogo,UseUnicode);
2581 } 2657 }
2582 num = 0; 2658 num = 0;
2583 for (h = file_info; h != NULL; h = h->Next) { 2659 for (h = file_info; h != NULL; h = h->Next) {
2584 found = false; 2660 found = false;
2585 if (UseUnicode) { 2661 if (UseUnicode) {
2586 EncodeUnicode(buffer,"FMStation",9); 2662 EncodeUnicode(buffer,"FMStation",9);
2587 if (mywstrncasecmp(buffer, h->SectionName, 9)) found = true; 2663 if (mywstrncasecmp(buffer, h->SectionName, 9)) found = true;
2588 } else { 2664 } else {
2589 if (mystrncasecmp("FMStation", h->SectionName, 9)) found = true; 2665 if (mystrncasecmp("FMStation", h->SectionName, 9)) found = true;
2590 } 2666 }
2591 if (found) { 2667 if (found) {
2592 readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode); 2668 readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
2593 if (readvalue==NULL) break; 2669 if (readvalue==NULL) break;
2594 if (num < GSM_BACKUP_MAX_FMSTATIONS) { 2670 if (num < GSM_BACKUP_MAX_FMSTATIONS) {
2595 backup->FMStation[num] = malloc(sizeof(GSM_FMStation)); 2671 backup->FMStation[num] = malloc(sizeof(GSM_FMStation));
2596 if (backup->FMStation[num] == NULL) return ERR_MOREMEMORY; 2672 if (backup->FMStation[num] == NULL) return ERR_MOREMEMORY;
2597 backup->FMStation[num + 1] = NULL; 2673 backup->FMStation[num + 1] = NULL;
2598 } else { 2674 } else {
2599 dbgprintf("Increase GSM_BACKUP_MAX_FMSTATIONS\n"); 2675 dbgprintf("Increase GSM_BACKUP_MAX_FMSTATIONS\n");
2600 return ERR_MOREMEMORY; 2676 return ERR_MOREMEMORY;
2601 } 2677 }
2602 backup->FMStation[num]->Location = num + 1; 2678 backup->FMStation[num]->Location = num + 1;
2603 ReadFMStationEntry(file_info, h->SectionName, backup->FMStation[num],UseUnicode); 2679 ReadFMStationEntry(file_info, h->SectionName, backup->FMStation[num],UseUnicode);
2604 num++; 2680 num++;
2605 } 2681 }
2606 } 2682 }
2607 num = 0; 2683 num = 0;
2608 for (h = file_info; h != NULL; h = h->Next) { 2684 for (h = file_info; h != NULL; h = h->Next) {
2609 found = false; 2685 found = false;
2610 if (UseUnicode) { 2686 if (UseUnicode) {
2611 EncodeUnicode(buffer,"GPRSPoint",9); 2687 EncodeUnicode(buffer,"GPRSPoint",9);
2612 if (mywstrncasecmp(buffer, h->SectionName, 9)) found = true; 2688 if (mywstrncasecmp(buffer, h->SectionName, 9)) found = true;
2613 } else { 2689 } else {
2614 if (mystrncasecmp("GPRSPoint", h->SectionName, 9)) found = true; 2690 if (mystrncasecmp("GPRSPoint", h->SectionName, 9)) found = true;
2615 } 2691 }
2616 if (found) { 2692 if (found) {
2617 readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode); 2693 readvalue = ReadCFGText(file_info, h->SectionName, "Location", UseUnicode);
2618 if (readvalue==NULL) break; 2694 if (readvalue==NULL) break;
2619 if (num < GSM_BACKUP_MAX_GPRSPOINT) { 2695 if (num < GSM_BACKUP_MAX_GPRSPOINT) {
2620 backup->GPRSPoint[num] = malloc(sizeof(GSM_GPRSAccessPoint)); 2696 backup->GPRSPoint[num] = malloc(sizeof(GSM_GPRSAccessPoint));
2621 if (backup->GPRSPoint[num] == NULL) return ERR_MOREMEMORY; 2697 if (backup->GPRSPoint[num] == NULL) return ERR_MOREMEMORY;
2622 backup->GPRSPoint[num + 1] = NULL; 2698 backup->GPRSPoint[num + 1] = NULL;
2623 } else { 2699 } else {
2624 dbgprintf("Increase GSM_BACKUP_MAX_GPRSPOINT\n"); 2700 dbgprintf("Increase GSM_BACKUP_MAX_GPRSPOINT\n");
2625 return ERR_MOREMEMORY; 2701 return ERR_MOREMEMORY;
2626 } 2702 }
2627 backup->GPRSPoint[num]->Location = num + 1; 2703 backup->GPRSPoint[num]->Location = num + 1;
2628 ReadGPRSPointEntry(file_info, h->SectionName, backup->GPRSPoint[num],UseUnicode); 2704 ReadGPRSPointEntry(file_info, h->SectionName, backup->GPRSPoint[num],UseUnicode);
2629 num++; 2705 num++;
2630 } 2706 }
2631 } 2707 }
2632 num = 0; 2708 num = 0;
2633 for (h = file_info; h != NULL; h = h->Next) { 2709 for (h = file_info; h != NULL; h = h->Next) {
2634 found = false; 2710 found = false;
2635 if (UseUnicode) { 2711 if (UseUnicode) {
2636 EncodeUnicode(buffer,"Note",4); 2712 EncodeUnicode(buffer,"Note",4);
2637 if (mywstrncasecmp(buffer, h->SectionName, 4)) found = true; 2713 if (mywstrncasecmp(buffer, h->SectionName, 4)) found = true;
2638 } else { 2714 } else {
2639 if (mystrncasecmp("Note", h->SectionName, 4)) found = true; 2715 if (mystrncasecmp("Note", h->SectionName, 4)) found = true;
2640 } 2716 }
2641 if (found) { 2717 if (found) {
2642 readvalue = ReadCFGText(file_info, h->SectionName, "Text", UseUnicode); 2718 readvalue = ReadCFGText(file_info, h->SectionName, "Text", UseUnicode);
2643 if (readvalue==NULL) break; 2719 if (readvalue==NULL) break;
2644 if (num < GSM_BACKUP_MAX_NOTE) { 2720 if (num < GSM_BACKUP_MAX_NOTE) {
2645 backup->Note[num] = malloc(sizeof(GSM_NoteEntry)); 2721 backup->Note[num] = malloc(sizeof(GSM_NoteEntry));
2646 if (backup->Note[num] == NULL) return ERR_MOREMEMORY; 2722 if (backup->Note[num] == NULL) return ERR_MOREMEMORY;
2647 backup->Note[num + 1] = NULL; 2723 backup->Note[num + 1] = NULL;
2648 } else { 2724 } else {
2649 dbgprintf("Increase GSM_BACKUP_MAX_NOTE\n"); 2725 dbgprintf("Increase GSM_BACKUP_MAX_NOTE\n");
2650 return ERR_MOREMEMORY; 2726 return ERR_MOREMEMORY;
2651 } 2727 }
2652 ReadNoteEntry(file_info, h->SectionName, backup->Note[num],UseUnicode); 2728 ReadNoteEntry(file_info, h->SectionName, backup->Note[num],UseUnicode);
2653 num++; 2729 num++;
2654 } 2730 }
2655 } 2731 }
2656 if (backup->MD5Original[0]!=0) { 2732 if (backup->MD5Original[0]!=0) {
2657 FindBackupChecksum(FileName, UseUnicode, backup->MD5Calculated); 2733 FindBackupChecksum(FileName, UseUnicode, backup->MD5Calculated);
2658 } 2734 }
2659 2735 for (h = file_info; h != NULL; h = h->Next) {
2736 found = false;
2737 if (UseUnicode) {
2738 EncodeUnicode(buffer,"Backup",4);
2739 if (mywstrncasecmp(buffer, h->SectionName, 6)) found = true;
2740 } else {
2741 if (mystrncasecmp("Backup", h->SectionName, 6)) found = true;
2742 }
2743 if (UseUnicode) {
2744 EncodeUnicode(buffer,"Checksum",4);
2745 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true;
2746 } else {
2747 if (mystrncasecmp("Checksum", h->SectionName, 8)) found = true;
2748 }
2749 if (UseUnicode) {
2750 EncodeUnicode(buffer,"Profile",7);
2751 if (mywstrncasecmp(buffer, h->SectionName, 7)) found = true;
2752 } else {
2753 if (mystrncasecmp("Profile", h->SectionName, 7)) found = true;
2754 }
2755 if (UseUnicode) {
2756 EncodeUnicode(buffer,"PhonePBK",8);
2757 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true;
2758 } else {
2759 if (mystrncasecmp("PhonePBK", h->SectionName, 8)) found = true;
2760 }
2761 if (UseUnicode) {
2762 EncodeUnicode(buffer,"SIMPBK",6);
2763 if (mywstrncasecmp(buffer, h->SectionName, 6)) found = true;
2764 } else {
2765 if (mystrncasecmp("SIMPBK", h->SectionName, 6)) found = true;
2766 }
2767 if (UseUnicode) {
2768 EncodeUnicode(buffer,"Calendar",8);
2769 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true;
2770 } else {
2771 if (mystrncasecmp("Calendar", h->SectionName, 8)) found = true;
2772 }
2773 if (UseUnicode) {
2774 EncodeUnicode(buffer,"Caller",6);
2775 if (mywstrncasecmp(buffer, h->SectionName, 6)) found = true;
2776 } else {
2777 if (mystrncasecmp("Caller", h->SectionName, 6)) found = true;
2778 }
2779 if (UseUnicode) {
2780 EncodeUnicode(buffer,"SMSC",4);
2781 if (mywstrncasecmp(buffer, h->SectionName, 4)) found = true;
2782 } else {
2783 if (mystrncasecmp("SMSC", h->SectionName, 4)) found = true;
2784 }
2785 if (UseUnicode) {
2786 EncodeUnicode(buffer,"WAPBookmark",11);
2787 if (mywstrncasecmp(buffer, h->SectionName, 11)) found = true;
2788 if (!found) {
2789 EncodeUnicode(buffer,"Bookmark",8);
2790 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true;
2791 }
2792 } else {
2793 if (mystrncasecmp("WAPBookmark", h->SectionName, 11)) found = true;
2794 if (!found) {
2795 if (mystrncasecmp("Bookmark", h->SectionName, 8)) found = true;
2796 }
2797 }
2798 if (UseUnicode) {
2799 EncodeUnicode(buffer,"WAPSettings",11);
2800 if (mywstrncasecmp(buffer, h->SectionName, 11)) found = true;
2801 if (!found) {
2802 EncodeUnicode(buffer,"Settings",8);
2803 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true;
2804 }
2805 } else {
2806 if (mystrncasecmp("WAPSettings", h->SectionName, 11)) found = true;
2807 if (!found) {
2808 if (mystrncasecmp("Settings", h->SectionName, 8)) found = true;
2809 }
2810 }
2811 if (UseUnicode) {
2812 EncodeUnicode(buffer,"MMSSettings",8);
2813 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true;
2814 } else {
2815 if (mystrncasecmp("MMSSettings", h->SectionName, 8)) found = true;
2816 }
2817 if (UseUnicode) {
2818 EncodeUnicode(buffer,"Ringtone",8);
2819 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true;
2820 } else {
2821 if (mystrncasecmp("Ringtone", h->SectionName, 8)) found = true;
2822 }
2823 if (UseUnicode) {
2824 EncodeUnicode(buffer,"TODO",4);
2825 if (mywstrncasecmp(buffer, h->SectionName, 4)) found = true;
2826 } else {
2827 if (mystrncasecmp("TODO", h->SectionName, 4)) found = true;
2828 }
2829 if (UseUnicode) {
2830 EncodeUnicode(buffer,"Startup",7);
2831 if (mywstrncasecmp(buffer, h->SectionName, 7)) found = true;
2832 } else {
2833 if (mystrncasecmp("Startup", h->SectionName, 7)) found = true;
2834 }
2835 if (UseUnicode) {
2836 EncodeUnicode(buffer,"Operator",7);
2837 if (mywstrncasecmp(buffer, h->SectionName, 8)) found = true;
2838 } else {
2839 if (mystrncasecmp("Operator", h->SectionName, 8)) found = true;
2840 }
2841 if (UseUnicode) {
2842 EncodeUnicode(buffer,"FMStation",9);
2843 if (mywstrncasecmp(buffer, h->SectionName, 9)) found = true;
2844 } else {
2845 if (mystrncasecmp("FMStation", h->SectionName, 9)) found = true;
2846 }
2847 if (UseUnicode) {
2848 EncodeUnicode(buffer,"GPRSPoint",9);
2849 if (mywstrncasecmp(buffer, h->SectionName, 9)) found = true;
2850 } else {
2851 if (mystrncasecmp("GPRSPoint", h->SectionName, 9)) found = true;
2852 }
2853 if (UseUnicode) {
2854 EncodeUnicode(buffer,"Note",4);
2855 if (mywstrncasecmp(buffer, h->SectionName, 4)) found = true;
2856 } else {
2857 if (mystrncasecmp("Note", h->SectionName, 4)) found = true;
2858 }
2859 if (!found) return ERR_NOTIMPLEMENTED;
2860 }
2660 return ERR_NONE; 2861 return ERR_NONE;
2661} 2862}
2662 2863
2663/* ---------------------- backup files for SMS ----------------------------- */ 2864/* ---------------------- backup files for SMS ----------------------------- */
2664 2865
2665static void ReadSMSBackupEntry(INI_Section *file_info, char *section, GSM_SMSMessage *SMS) 2866static void ReadSMSBackupEntry(INI_Section *file_info, char *section, GSM_SMSMessage *SMS)
2666{ 2867{
2667 unsigned char buffer[10000], *readvalue; 2868 unsigned char buffer[10000], *readvalue;
2668 2869
2669 GSM_SetDefaultSMSData(SMS); 2870 GSM_SetDefaultSMSData(SMS);
2670 2871
2671 SMS->PDU = SMS_Submit; 2872 SMS->PDU = SMS_Submit;
2672 SMS->SMSC.Location = 0; 2873 SMS->SMSC.Location = 0;
2673 sprintf(buffer,"SMSC"); 2874 sprintf(buffer,"SMSC");
2674 ReadBackupText(file_info, section, buffer, SMS->SMSC.Number, false); 2875 ReadBackupText(file_info, section, buffer, SMS->SMSC.Number, false);
2675 sprintf(buffer,"ReplySMSC"); 2876 sprintf(buffer,"ReplySMSC");
2676 SMS->ReplyViaSameSMSC = false; 2877 SMS->ReplyViaSameSMSC = false;
2677 readvalue = ReadCFGText(file_info, section, buffer, false); 2878 readvalue = ReadCFGText(file_info, section, buffer, false);
2678 if (readvalue!=NULL) { 2879 if (readvalue!=NULL) {
2679 if (mystrncasecmp(readvalue,"True",0)) SMS->ReplyViaSameSMSC = true; 2880 if (mystrncasecmp(readvalue,"True",0)) SMS->ReplyViaSameSMSC = true;
2680 } 2881 }
2681 sprintf(buffer,"Class"); 2882 sprintf(buffer,"Class");
2682 SMS->Class = -1; 2883 SMS->Class = -1;
2683 readvalue = ReadCFGText(file_info, section, buffer, false); 2884 readvalue = ReadCFGText(file_info, section, buffer, false);
2684 if (readvalue!=NULL) SMS->Class = atoi(readvalue); 2885 if (readvalue!=NULL) SMS->Class = atoi(readvalue);
2685 sprintf(buffer,"Sent"); 2886 sprintf(buffer,"Sent");
2686 readvalue = ReadCFGText(file_info, section, buffer, false); 2887 readvalue = ReadCFGText(file_info, section, buffer, false);
2687 if (readvalue!=NULL) { 2888 if (readvalue!=NULL) {
2688 ReadVCALDateTime(readvalue, &SMS->DateTime); 2889 ReadVCALDateTime(readvalue, &SMS->DateTime);
2689 SMS->PDU = SMS_Deliver; 2890 SMS->PDU = SMS_Deliver;
2690 } 2891 }
2691 sprintf(buffer,"RejectDuplicates"); 2892 sprintf(buffer,"RejectDuplicates");
2692 SMS->RejectDuplicates = false; 2893 SMS->RejectDuplicates = false;
2693 readvalue = ReadCFGText(file_info, section, buffer, false); 2894 readvalue = ReadCFGText(file_info, section, buffer, false);
2694 if (readvalue!=NULL) { 2895 if (readvalue!=NULL) {
2695 if (mystrncasecmp(readvalue,"True",0)) SMS->RejectDuplicates = true; 2896 if (mystrncasecmp(readvalue,"True",0)) SMS->RejectDuplicates = true;
2696 } 2897 }
2697 sprintf(buffer,"ReplaceMessage"); 2898 sprintf(buffer,"ReplaceMessage");
2698 SMS->ReplaceMessage = 0; 2899 SMS->ReplaceMessage = 0;
2699 readvalue = ReadCFGText(file_info, section, buffer, false); 2900 readvalue = ReadCFGText(file_info, section, buffer, false);
2700 if (readvalue!=NULL) SMS->ReplaceMessage = atoi(readvalue); 2901 if (readvalue!=NULL) SMS->ReplaceMessage = atoi(readvalue);
2701 sprintf(buffer,"MessageReference"); 2902 sprintf(buffer,"MessageReference");
2702 SMS->MessageReference = 0; 2903 SMS->MessageReference = 0;
2703 readvalue = ReadCFGText(file_info, section, buffer, false); 2904 readvalue = ReadCFGText(file_info, section, buffer, false);
2704 if (readvalue!=NULL) SMS->MessageReference = atoi(readvalue); 2905 if (readvalue!=NULL) SMS->MessageReference = atoi(readvalue);
2705 sprintf(buffer,"State"); 2906 sprintf(buffer,"State");
2706 SMS->State = SMS_UnRead; 2907 SMS->State = SMS_UnRead;
2707 readvalue = ReadCFGText(file_info, section, buffer, false); 2908 readvalue = ReadCFGText(file_info, section, buffer, false);
2708 if (readvalue!=NULL) { 2909 if (readvalue!=NULL) {
2709 if (mystrncasecmp(readvalue,"Read",0)) SMS->State = SMS_Read; 2910 if (mystrncasecmp(readvalue,"Read",0)) SMS->State = SMS_Read;
2710 else if (mystrncasecmp(readvalue,"Sent",0))SMS->State = SMS_Sent; 2911 else if (mystrncasecmp(readvalue,"Sent",0))SMS->State = SMS_Sent;
2711 else if (mystrncasecmp(readvalue,"UnSent",0))SMS->State = SMS_UnSent; 2912 else if (mystrncasecmp(readvalue,"UnSent",0))SMS->State = SMS_UnSent;
2712 } 2913 }
2713 sprintf(buffer,"Number"); 2914 sprintf(buffer,"Number");
2714 ReadBackupText(file_info, section, buffer, SMS->Number, false); 2915 ReadBackupText(file_info, section, buffer, SMS->Number, false);
2715 sprintf(buffer,"Name"); 2916 sprintf(buffer,"Name");
2716 ReadBackupText(file_info, section, buffer, SMS->Name, false); 2917 ReadBackupText(file_info, section, buffer, SMS->Name, false);
2717 sprintf(buffer,"Length"); 2918 sprintf(buffer,"Length");
2718 SMS->Length = 0; 2919 SMS->Length = 0;
2719 readvalue = ReadCFGText(file_info, section, buffer, false); 2920 readvalue = ReadCFGText(file_info, section, buffer, false);
2720 if (readvalue!=NULL) SMS->Length = atoi(readvalue); 2921 if (readvalue!=NULL) SMS->Length = atoi(readvalue);
2721 sprintf(buffer,"Coding"); 2922 sprintf(buffer,"Coding");
2722 SMS->Coding = SMS_Coding_Default; 2923 SMS->Coding = SMS_Coding_Default;
2723 readvalue = ReadCFGText(file_info, section, buffer, false); 2924 readvalue = ReadCFGText(file_info, section, buffer, false);
2724 if (readvalue!=NULL) { 2925 if (readvalue!=NULL) {
2725 if (mystrncasecmp(readvalue,"Unicode",0)) { 2926 if (mystrncasecmp(readvalue,"Unicode",0)) {
2726 SMS->Coding = SMS_Coding_Unicode; 2927 SMS->Coding = SMS_Coding_Unicode;
2727 } else if (mystrncasecmp(readvalue,"8bit",0)) { 2928 } else if (mystrncasecmp(readvalue,"8bit",0)) {
2728 SMS->Coding = SMS_Coding_8bit; 2929 SMS->Coding = SMS_Coding_8bit;
2729 } 2930 }
2730 } 2931 }
2731 ReadLinkedBackupText(file_info, section, "Text", buffer, false); 2932 ReadLinkedBackupText(file_info, section, "Text", buffer, false);
2732 DecodeHexBin (SMS->Text, buffer, strlen(buffer)); 2933 DecodeHexBin (SMS->Text, buffer, strlen(buffer));
2733 SMS->Text[strlen(buffer)/2]= 0; 2934 SMS->Text[strlen(buffer)/2]= 0;
2734 SMS->Text[strlen(buffer)/2+1] = 0; 2935 SMS->Text[strlen(buffer)/2+1] = 0;
2735 sprintf(buffer,"Folder"); 2936 sprintf(buffer,"Folder");
2736 readvalue = ReadCFGText(file_info, section, buffer, false); 2937 readvalue = ReadCFGText(file_info, section, buffer, false);
2737 if (readvalue!=NULL) SMS->Folder = atoi(readvalue); 2938 if (readvalue!=NULL) SMS->Folder = atoi(readvalue);
2738 SMS->UDH.Type = UDH_NoUDH; 2939 SMS->UDH.Type = UDH_NoUDH;
2739 SMS->UDH.Length = 0; 2940 SMS->UDH.Length = 0;
2740 SMS->UDH.ID8bit = -1; 2941 SMS->UDH.ID8bit = -1;
2741 SMS->UDH.ID16bit= -1; 2942 SMS->UDH.ID16bit= -1;
2742 SMS->UDH.PartNumber= -1; 2943 SMS->UDH.PartNumber= -1;
2743 SMS->UDH.AllParts= -1; 2944 SMS->UDH.AllParts= -1;
2744 sprintf(buffer,"UDH"); 2945 sprintf(buffer,"UDH");
2745 readvalue = ReadCFGText(file_info, section, buffer, false); 2946 readvalue = ReadCFGText(file_info, section, buffer, false);
2746 if (readvalue!=NULL) { 2947 if (readvalue!=NULL) {
2747 DecodeHexBin (SMS->UDH.Text, readvalue, strlen(readvalue)); 2948 DecodeHexBin (SMS->UDH.Text, readvalue, strlen(readvalue));
2748 SMS->UDH.Length = strlen(readvalue)/2; 2949 SMS->UDH.Length = strlen(readvalue)/2;
2749 GSM_DecodeUDHHeader(&SMS->UDH); 2950 GSM_DecodeUDHHeader(&SMS->UDH);
2750 } 2951 }
2751} 2952}
2752 2953
2753static GSM_Error GSM_ReadSMSBackupTextFile(char *FileName, GSM_SMS_Backup *backup) 2954static GSM_Error GSM_ReadSMSBackupTextFile(char *FileName, GSM_SMS_Backup *backup)
2754{ 2955{
2755 INI_Section*file_info, *h; 2956 INI_Section*file_info, *h;
2756 char *readvalue; 2957 char *readvalue;
2757 int num; 2958 int num;
2758 2959
2759 backup->SMS[0] = NULL; 2960 backup->SMS[0] = NULL;
2760 2961
2761 file_info = INI_ReadFile(FileName, false); 2962 file_info = INI_ReadFile(FileName, false);
2762 2963
2763 num = 0; 2964 num = 0;
2764 for (h = file_info; h != NULL; h = h->Next) { 2965 for (h = file_info; h != NULL; h = h->Next) {
2765 if (mystrncasecmp("SMSBackup", h->SectionName, 9)) { 2966 if (mystrncasecmp("SMSBackup", h->SectionName, 9)) {
2766 readvalue = ReadCFGText(file_info, h->SectionName, "Number", false); 2967 readvalue = ReadCFGText(file_info, h->SectionName, "Number", false);
2767 if (readvalue==NULL) break; 2968 if (readvalue==NULL) break;
2768 if (num < GSM_BACKUP_MAX_SMS) { 2969 if (num < GSM_BACKUP_MAX_SMS) {
2769 backup->SMS[num] = malloc(sizeof(GSM_SMSMessage)); 2970 backup->SMS[num] = malloc(sizeof(GSM_SMSMessage));
2770 if (backup->SMS[num] == NULL) return ERR_MOREMEMORY; 2971 if (backup->SMS[num] == NULL) return ERR_MOREMEMORY;
2771 backup->SMS[num + 1] = NULL; 2972 backup->SMS[num + 1] = NULL;
2772 } else { 2973 } else {
2773 dbgprintf("Increase GSM_BACKUP_MAX_SMS\n"); 2974 dbgprintf("Increase GSM_BACKUP_MAX_SMS\n");
2774 return ERR_MOREMEMORY; 2975 return ERR_MOREMEMORY;
2775 } 2976 }
2776 backup->SMS[num]->Location = num + 1; 2977 backup->SMS[num]->Location = num + 1;
2777 ReadSMSBackupEntry(file_info, h->SectionName, backup->SMS[num]); 2978 ReadSMSBackupEntry(file_info, h->SectionName, backup->SMS[num]);
2778 num++; 2979 num++;
2779 } 2980 }
2780 } 2981 }
2781 return ERR_NONE; 2982 return ERR_NONE;
2782} 2983}
2783 2984
2784GSM_Error GSM_ReadSMSBackupFile(char *FileName, GSM_SMS_Backup *backup) 2985GSM_Error GSM_ReadSMSBackupFile(char *FileName, GSM_SMS_Backup *backup)
2785{ 2986{
2786 FILE *file; 2987 FILE *file;
2787 2988
2788 backup->SMS[0] = NULL; 2989 backup->SMS[0] = NULL;
2789 2990
2790 file = fopen(FileName, "rb"); 2991 file = fopen(FileName, "rb");
2791 if (file == NULL) return(ERR_CANTOPENFILE); 2992 if (file == NULL) return(ERR_CANTOPENFILE);
2792 2993
2793 fclose(file); 2994 fclose(file);
2794 2995
2795 return GSM_ReadSMSBackupTextFile(FileName, backup); 2996 return GSM_ReadSMSBackupTextFile(FileName, backup);
2796} 2997}
2797 2998
2798GSM_Error SaveSMSBackupTextFile(FILE *file, GSM_SMS_Backup *backup) 2999GSM_Error SaveSMSBackupTextFile(FILE *file, GSM_SMS_Backup *backup)
2799{ 3000{
2800 int i,w,current; 3001 int i,w,current;
2801 unsigned char buffer[10000]; 3002 unsigned char buffer[10000];
2802 GSM_DateTimeDT; 3003 GSM_DateTimeDT;
2803 3004
2804 fprintf(file,"\n# File created by Gammu (www.mwiacek.com) version %s\n",VERSION); 3005 fprintf(file,"\n# File created by Gammu (www.mwiacek.com) version %s\n",VERSION);
2805 GSM_GetCurrentDateTime (&DT); 3006 GSM_GetCurrentDateTime (&DT);
2806 fprintf(file,"# Saved %s\n\n",OSDateTime(DT,false)); 3007 fprintf(file,"# Saved %s\n\n",OSDateTime(DT,false));
2807 3008
2808 i=0; 3009 i=0;
2809 while (backup->SMS[i]!=NULL) { 3010 while (backup->SMS[i]!=NULL) {
2810 fprintf(file,"[SMSBackup%03i]\n",i); 3011 fprintf(file,"[SMSBackup%03i]\n",i);
2811 switch (backup->SMS[i]->Coding) { 3012 switch (backup->SMS[i]->Coding) {
2812 case SMS_Coding_Unicode: 3013 case SMS_Coding_Unicode:
2813 case SMS_Coding_Default: 3014 case SMS_Coding_Default:
2814 sprintf(buffer,"%s",DecodeUnicodeString(backup->SMS[i]->Text)); 3015 sprintf(buffer,"%s",DecodeUnicodeString(backup->SMS[i]->Text));
2815 fprintf(file,"#"); 3016 fprintf(file,"#");
2816 current = 0; 3017 current = 0;
2817 for (w=0;w<(int)(strlen(buffer));w++) { 3018 for (w=0;w<(int)(strlen(buffer));w++) {
2818 switch (buffer[w]) { 3019 switch (buffer[w]) {
2819 case 10: 3020 case 10:
2820 fprintf(file,"\n#"); 3021 fprintf(file,"\n#");
2821 current = 0; 3022 current = 0;
2822 break; 3023 break;
2823 case 13: 3024 case 13:
2824 break; 3025 break;
2825 default: 3026 default:
2826 if (isprint(buffer[w])) { 3027 if (isprint(buffer[w])) {
2827 fprintf(file,"%c",buffer[w]); 3028 fprintf(file,"%c",buffer[w]);
2828 current ++; 3029 current ++;
2829 } 3030 }
2830 if (current == 75) { 3031 if (current == 75) {
2831 fprintf(file,"\n#"); 3032 fprintf(file,"\n#");
2832 current = 0; 3033 current = 0;
2833 } 3034 }
2834 } 3035 }
2835 } 3036 }
2836 fprintf(file,"\n"); 3037 fprintf(file,"\n");
2837 break; 3038 break;
2838 default: 3039 default:
2839 break; 3040 break;
2840 } 3041 }
2841 if (backup->SMS[i]->PDU == SMS_Deliver) { 3042 if (backup->SMS[i]->PDU == SMS_Deliver) {
2842 SaveBackupText(file, "SMSC", backup->SMS[i]->SMSC.Number, false); 3043 SaveBackupText(file, "SMSC", backup->SMS[i]->SMSC.Number, false);
2843 if (backup->SMS[i]->ReplyViaSameSMSC) fprintf(file,"SMSCReply = true\n"); 3044 if (backup->SMS[i]->ReplyViaSameSMSC) fprintf(file,"SMSCReply = true\n");
2844 fprintf(file,"Sent"); 3045 fprintf(file,"Sent");
2845 SaveVCalDateTime(file,&backup->SMS[i]->DateTime, false); 3046 SaveVCalDateTime(file,&backup->SMS[i]->DateTime, false);
2846 } 3047 }
2847 fprintf(file,"State = "); 3048 fprintf(file,"State = ");
2848 switch (backup->SMS[i]->State) { 3049 switch (backup->SMS[i]->State) {
2849 case SMS_UnRead : fprintf(file,"UnRead\n");break; 3050 case SMS_UnRead : fprintf(file,"UnRead\n");break;
2850 case SMS_Read : fprintf(file,"Read\n");break; 3051 case SMS_Read : fprintf(file,"Read\n");break;
2851 case SMS_Sent : fprintf(file,"Sent\n");break; 3052 case SMS_Sent : fprintf(file,"Sent\n");break;
diff --git a/gammu/emb/common/service/backup/gsmback.c b/gammu/emb/common/service/backup/gsmback.c
index 91ac745..c94a4d2 100644
--- a/gammu/emb/common/service/backup/gsmback.c
+++ b/gammu/emb/common/service/backup/gsmback.c
@@ -1,280 +1,298 @@
1/* (c) 2002-2004 by Marcin Wiacek & Michal Cihar */ 1/* (c) 2002-2004 by Marcin Wiacek & Michal Cihar */
2 2
3#include <string.h> 3#include <string.h>
4#include <ctype.h> 4#include <ctype.h>
5 5
6#include "../../phone/nokia/nfunc.h" 6#include "../../phone/nokia/nfunc.h"
7#include "../../phone/nokia/dct3/n7110.h" 7#include "../../phone/nokia/dct3/n7110.h"
8#include "../../misc/coding/coding.h" 8#include "../../misc/coding/coding.h"
9#include "../../misc/cfg.h" 9#include "../../misc/cfg.h"
10#include "../gsmlogo.h" 10#include "../gsmlogo.h"
11#include "../gsmmisc.h" 11#include "../gsmmisc.h"
12#include "../gsmcal.h" 12#include "../gsmcal.h"
13#include "gsmback.h" 13#include "gsmback.h"
14#include "backtext.h" 14#include "backtext.h"
15#include "backldif.h" 15#include "backldif.h"
16#include "backlmb.h" 16#include "backlmb.h"
17#include "backvcs.h" 17#include "backvcs.h"
18#include "backvcf.h" 18#include "backvcf.h"
19#include "backics.h" 19#include "backics.h"
20 20
21#ifdef GSM_ENABLE_BACKUP 21#ifdef GSM_ENABLE_BACKUP
22 22
23void GSM_FreeBackup(GSM_Backup *backup) 23void GSM_FreeBackup(GSM_Backup *backup)
24{ 24{
25 int i; 25 int i;
26 26
27 i=0; 27 i=0;
28 while (backup->PhonePhonebook[i]!=NULL) { 28 while (backup->PhonePhonebook[i]!=NULL) {
29 free(backup->PhonePhonebook[i]); 29 free(backup->PhonePhonebook[i]);
30 backup->PhonePhonebook[i] = NULL; 30 backup->PhonePhonebook[i] = NULL;
31 i++; 31 i++;
32 } 32 }
33 i=0; 33 i=0;
34 while (backup->SIMPhonebook[i]!=NULL) { 34 while (backup->SIMPhonebook[i]!=NULL) {
35 free(backup->SIMPhonebook[i]); 35 free(backup->SIMPhonebook[i]);
36 backup->SIMPhonebook[i] = NULL; 36 backup->SIMPhonebook[i] = NULL;
37 i++; 37 i++;
38 } 38 }
39 i=0; 39 i=0;
40 while (backup->Calendar[i]!=NULL) { 40 while (backup->Calendar[i]!=NULL) {
41 free(backup->Calendar[i]); 41 free(backup->Calendar[i]);
42 backup->Calendar[i] = NULL; 42 backup->Calendar[i] = NULL;
43 i++; 43 i++;
44 } 44 }
45 i=0; 45 i=0;
46 while (backup->CallerLogos[i]!=NULL) { 46 while (backup->CallerLogos[i]!=NULL) {
47 free(backup->CallerLogos[i]); 47 free(backup->CallerLogos[i]);
48 backup->CallerLogos[i] = NULL; 48 backup->CallerLogos[i] = NULL;
49 i++; 49 i++;
50 } 50 }
51 i=0; 51 i=0;
52 while (backup->SMSC[i]!=NULL) { 52 while (backup->SMSC[i]!=NULL) {
53 free(backup->SMSC[i]); 53 free(backup->SMSC[i]);
54 backup->SMSC[i] = NULL; 54 backup->SMSC[i] = NULL;
55 i++; 55 i++;
56 } 56 }
57 i=0; 57 i=0;
58 while (backup->WAPBookmark[i]!=NULL) { 58 while (backup->WAPBookmark[i]!=NULL) {
59 free(backup->WAPBookmark[i]); 59 free(backup->WAPBookmark[i]);
60 backup->WAPBookmark[i] = NULL; 60 backup->WAPBookmark[i] = NULL;
61 i++; 61 i++;
62 } 62 }
63 i=0; 63 i=0;
64 while (backup->WAPSettings[i]!=NULL) { 64 while (backup->WAPSettings[i]!=NULL) {
65 free(backup->WAPSettings[i]); 65 free(backup->WAPSettings[i]);
66 backup->WAPSettings[i] = NULL; 66 backup->WAPSettings[i] = NULL;
67 i++; 67 i++;
68 } 68 }
69 i=0; 69 i=0;
70 while (backup->MMSSettings[i]!=NULL) { 70 while (backup->MMSSettings[i]!=NULL) {
71 free(backup->MMSSettings[i]); 71 free(backup->MMSSettings[i]);
72 backup->MMSSettings[i] = NULL; 72 backup->MMSSettings[i] = NULL;
73 i++; 73 i++;
74 } 74 }
75 i=0; 75 i=0;
76 while (backup->SyncMLSettings[i]!=NULL) {
77 free(backup->SyncMLSettings[i]);
78 backup->SyncMLSettings[i] = NULL;
79 i++;
80 }
81 i=0;
82 while (backup->ChatSettings[i]!=NULL) {
83 free(backup->ChatSettings[i]);
84 backup->ChatSettings[i] = NULL;
85 i++;
86 }
87 i=0;
76 while (backup->Ringtone[i]!=NULL) { 88 while (backup->Ringtone[i]!=NULL) {
77 free(backup->Ringtone[i]); 89 free(backup->Ringtone[i]);
78 backup->Ringtone[i] = NULL; 90 backup->Ringtone[i] = NULL;
79 i++; 91 i++;
80 } 92 }
81 i=0; 93 i=0;
82 while (backup->ToDo[i]!=NULL) { 94 while (backup->ToDo[i]!=NULL) {
83 free(backup->ToDo[i]); 95 free(backup->ToDo[i]);
84 backup->ToDo[i] = NULL; 96 backup->ToDo[i] = NULL;
85 i++; 97 i++;
86 } 98 }
87 i=0; 99 i=0;
88 while (backup->Profiles[i]!=NULL) { 100 while (backup->Profiles[i]!=NULL) {
89 free(backup->Profiles[i]); 101 free(backup->Profiles[i]);
90 backup->Profiles[i] = NULL; 102 backup->Profiles[i] = NULL;
91 i++; 103 i++;
92 } 104 }
93 i=0; 105 i=0;
94 while (backup->FMStation[i]!=NULL) { 106 while (backup->FMStation[i]!=NULL) {
95 free(backup->FMStation[i]); 107 free(backup->FMStation[i]);
96 backup->FMStation[i] = NULL; 108 backup->FMStation[i] = NULL;
97 i++; 109 i++;
98 } 110 }
99 if (backup->StartupLogo!=NULL) { 111 if (backup->StartupLogo!=NULL) {
100 free(backup->StartupLogo); 112 free(backup->StartupLogo);
101 backup->StartupLogo = NULL; 113 backup->StartupLogo = NULL;
102 } 114 }
103 if (backup->OperatorLogo!=NULL) { 115 if (backup->OperatorLogo!=NULL) {
104 free(backup->OperatorLogo); 116 free(backup->OperatorLogo);
105 backup->OperatorLogo = NULL; 117 backup->OperatorLogo = NULL;
106 } 118 }
107 i=0; 119 i=0;
108 while (backup->GPRSPoint[i]!=NULL) { 120 while (backup->GPRSPoint[i]!=NULL) {
109 free(backup->GPRSPoint[i]); 121 free(backup->GPRSPoint[i]);
110 backup->GPRSPoint[i] = NULL; 122 backup->GPRSPoint[i] = NULL;
111 i++; 123 i++;
112 } 124 }
113 i=0; 125 i=0;
114 while (backup->Note[i]!=NULL) { 126 while (backup->Note[i]!=NULL) {
115 free(backup->Note[i]); 127 free(backup->Note[i]);
116 backup->Note[i] = NULL; 128 backup->Note[i] = NULL;
117 i++; 129 i++;
118 } 130 }
119} 131}
120 132
121GSM_Error GSM_SaveBackupFile(char *FileName, GSM_Backup *backup, bool UseUnicode) 133GSM_Error GSM_SaveBackupFile(char *FileName, GSM_Backup *backup, bool UseUnicode)
122{ 134{
123 if (strstr(FileName,".lmb")) { 135 if (mystrcasestr(FileName,".lmb")) {
124 return SaveLMB(FileName,backup); 136 return SaveLMB(FileName,backup);
125 } else if (strstr(FileName,".vcs")) { 137 } else if (mystrcasestr(FileName,".vcs")) {
126 return SaveVCalendar(FileName,backup); 138 return SaveVCalendar(FileName,backup);
127 } else if (strstr(FileName,".vcf")) { 139 } else if (mystrcasestr(FileName,".vcf")) {
128 return SaveVCard(FileName,backup); 140 return SaveVCard(FileName,backup);
129 } else if (strstr(FileName,".ldif")) { 141 } else if (mystrcasestr(FileName,".ldif")) {
130 return SaveLDIF(FileName,backup); 142 return SaveLDIF(FileName,backup);
131 } else if (strstr(FileName,".ics")) { 143 } else if (mystrcasestr(FileName,".ics")) {
132 return SaveICS(FileName,backup); 144 return SaveICS(FileName,backup);
133 } else { 145 } else {
134 return SaveBackup(FileName,backup, UseUnicode); 146 return SaveBackup(FileName,backup, UseUnicode);
135 } 147 }
136} 148}
137 149
138GSM_Error GSM_ReadBackupFile(char *FileName, GSM_Backup *backup) 150GSM_Error GSM_ReadBackupFile(char *FileName, GSM_Backup *backup)
139{ 151{
140 FILE *file; 152 FILE *file;
141 unsigned charbuffer[300]; 153 unsigned charbuffer[300];
142 154
143 file = fopen(FileName, "rb"); 155 file = fopen(FileName, "rb");
144 if (file == NULL) return ERR_CANTOPENFILE; 156 if (file == NULL) return ERR_CANTOPENFILE;
145 fread(buffer, 1, 9, file); /* Read the header of the file. */ 157 fread(buffer, 1, 9, file); /* Read the header of the file. */
146 fclose(file); 158 fclose(file);
147 159
148 GSM_ClearBackup(backup); 160 GSM_ClearBackup(backup);
149 161
150 /* Attempt to identify filetype */ 162 /* Attempt to identify filetype */
151 if (strstr(FileName,".vcs")) { 163 if (mystrcasestr(FileName,".vcs")) {
152 return LoadVCalendar(FileName,backup); 164 return LoadVCalendar(FileName,backup);
153 } else if (strstr(FileName,".vcf")) { 165 } else if (mystrcasestr(FileName,".vcf")) {
154 return LoadVCard(FileName,backup); 166 return LoadVCard(FileName,backup);
155 } else if (strstr(FileName,".ldif")) { 167 } else if (mystrcasestr(FileName,".ldif")) {
156 return LoadLDIF(FileName,backup); 168 return LoadLDIF(FileName,backup);
157 } else if (strstr(FileName,".ics")) { 169 } else if (mystrcasestr(FileName,".ics")) {
158 return LoadICS(FileName,backup); 170 return LoadICS(FileName,backup);
159 } else if (memcmp(buffer, "LMB ",4)==0) { 171 } else if (memcmp(buffer, "LMB ",4)==0) {
160 return LoadLMB(FileName,backup); 172 return LoadLMB(FileName,backup);
161 } else if (buffer[0] == 0xFE && buffer[1] == 0xFF) { 173 } else if (buffer[0] == 0xFE && buffer[1] == 0xFF) {
162 return LoadBackup(FileName,backup,true); 174 return LoadBackup(FileName,backup,true);
163 } else if (buffer[0] == 0xFF && buffer[1] == 0xFE) { 175 } else if (buffer[0] == 0xFF && buffer[1] == 0xFE) {
164 return LoadBackup(FileName,backup,true); 176 return LoadBackup(FileName,backup,true);
165 } else { 177 } else {
166 return LoadBackup(FileName,backup,false); 178 return LoadBackup(FileName,backup,false);
167 } 179 }
168} 180}
169 181
170void GSM_ClearBackup(GSM_Backup *backup) 182void GSM_ClearBackup(GSM_Backup *backup)
171{ 183{
172 backup->PhonePhonebook[0] = NULL; 184 backup->PhonePhonebook[0] = NULL;
173 backup->SIMPhonebook[0] = NULL; 185 backup->SIMPhonebook[0] = NULL;
174 backup->Calendar[0] = NULL; 186 backup->Calendar[0] = NULL;
175 backup->CallerLogos[0] = NULL; 187 backup->CallerLogos[0] = NULL;
176 backup->SMSC [0] = NULL; 188 backup->SMSC [0] = NULL;
177 backup->WAPBookmark[0] = NULL; 189 backup->WAPBookmark[0] = NULL;
178 backup->WAPSettings[0] = NULL; 190 backup->WAPSettings[0] = NULL;
179 backup->MMSSettings[0] = NULL; 191 backup->MMSSettings[0] = NULL;
192 backup->SyncMLSettings[0] = NULL;
193 backup->ChatSettings[0] = NULL;
180 backup->Ringtone[0] = NULL; 194 backup->Ringtone[0] = NULL;
181 backup->Profiles[0] = NULL; 195 backup->Profiles[0] = NULL;
182 backup->ToDo [0] = NULL; 196 backup->ToDo [0] = NULL;
183 backup->GPRSPoint[0] = NULL; 197 backup->GPRSPoint[0] = NULL;
184 backup->FMStation[0] = NULL; 198 backup->FMStation[0] = NULL;
185 backup->Note [0] = NULL; 199 backup->Note [0] = NULL;
186 backup->StartupLogo = NULL; 200 backup->StartupLogo = NULL;
187 backup->OperatorLogo = NULL; 201 backup->OperatorLogo = NULL;
188 202
189 backup->Creator [0] = 0; 203 backup->Creator [0] = 0;
190 backup->IMEI [0] = 0; 204 backup->IMEI [0] = 0;
191 backup->Model [0] = 0; 205 backup->Model [0] = 0;
192 backup->DateTimeAvailable = false; 206 backup->DateTimeAvailable = false;
193 backup->MD5Original[0] = 0; 207 backup->MD5Original[0] = 0;
194 backup->MD5Calculated[0] = 0; 208 backup->MD5Calculated[0] = 0;
195} 209}
196 210
197void GSM_GetBackupFormatFeatures(char *FileName, GSM_Backup_Info *info) 211void GSM_GetBackupFormatFeatures(char *FileName, GSM_Backup_Info *info)
198{ 212{
199 info->UseUnicode= false; 213 info->UseUnicode= false;
200 info->IMEI = false; 214 info->IMEI = false;
201 info->Model = false; 215 info->Model = false;
202 info->DateTime = false; 216 info->DateTime = false;
203 info->PhonePhonebook = false; 217 info->PhonePhonebook = false;
204 info->SIMPhonebook = false; 218 info->SIMPhonebook = false;
205 info->ToDo = false; 219 info->ToDo = false;
206 info->Calendar = false; 220 info->Calendar = false;
207 info->CallerLogos = false; 221 info->CallerLogos = false;
208 info->SMSC = false; 222 info->SMSC = false;
209 info->WAPBookmark = false; 223 info->WAPBookmark = false;
210 info->WAPSettings = false; 224 info->WAPSettings = false;
211 info->MMSSettings = false; 225 info->MMSSettings = false;
226 info->SyncMLSettings = false;
227 info->ChatSettings = false;
212 info->Ringtone = false; 228 info->Ringtone = false;
213 info->StartupLogo = false; 229 info->StartupLogo = false;
214 info->OperatorLogo = false; 230 info->OperatorLogo = false;
215 info->Profiles = false; 231 info->Profiles = false;
216 info->FMStation = false; 232 info->FMStation = false;
217 info->GPRSPoint = false; 233 info->GPRSPoint = false;
218 info->Note = false; 234 info->Note = false;
219 235
220 if (strstr(FileName,".lmb")) { 236 if (strstr(FileName,".lmb")) {
221 info->PhonePhonebook = true; 237 info->PhonePhonebook = true;
222 info->SIMPhonebook = true; 238 info->SIMPhonebook = true;
223 info->CallerLogos = true; 239 info->CallerLogos = true;
224 info->StartupLogo = true; 240 info->StartupLogo = true;
225 } else if (strstr(FileName,".vcs")) { 241 } else if (strstr(FileName,".vcs")) {
226 info->ToDo = true; 242 info->ToDo = true;
227 info->Calendar = true; 243 info->Calendar = true;
228 } else if (strstr(FileName,".vcf")) { 244 } else if (strstr(FileName,".vcf")) {
229 info->PhonePhonebook= true; 245 info->PhonePhonebook= true;
230 } else if (strstr(FileName,".ics")) { 246 } else if (strstr(FileName,".ics")) {
231 info->ToDo = true; 247 info->ToDo = true;
232 info->Calendar = true; 248 info->Calendar = true;
233 } else if (strstr(FileName,".ldif")) { 249 } else if (strstr(FileName,".ldif")) {
234 info->PhonePhonebook= true; 250 info->PhonePhonebook= true;
235 } else { 251 } else {
236 info->UseUnicode= true; 252 info->UseUnicode= true;
237 info->IMEI = true; 253 info->IMEI = true;
238 info->Model = true; 254 info->Model = true;
239 info->DateTime = true; 255 info->DateTime = true;
240 info->PhonePhonebook = true; 256 info->PhonePhonebook = true;
241 info->SIMPhonebook = true; 257 info->SIMPhonebook = true;
242 info->ToDo = true; 258 info->ToDo = true;
243 info->Calendar = true; 259 info->Calendar = true;
244 info->CallerLogos = true; 260 info->CallerLogos = true;
245 info->SMSC = true; 261 info->SMSC = true;
246 info->WAPBookmark = true; 262 info->WAPBookmark = true;
247 info->WAPSettings = true; 263 info->WAPSettings = true;
248 info->MMSSettings = true; 264 info->MMSSettings = true;
265 info->SyncMLSettings = true;
266 info->ChatSettings = true;
249 info->Ringtone = true; 267 info->Ringtone = true;
250 info->StartupLogo = true; 268 info->StartupLogo = true;
251 info->OperatorLogo = true; 269 info->OperatorLogo = true;
252 info->Profiles = true; 270 info->Profiles = true;
253 info->FMStation = true; 271 info->FMStation = true;
254 info->GPRSPoint = true; 272 info->GPRSPoint = true;
255 info->Note = true; 273 info->Note = true;
256 } 274 }
257} 275}
258 276
259void GSM_GetBackupFileFeatures(char *FileName, GSM_Backup_Info *info, GSM_Backup *backup) 277void GSM_GetBackupFileFeatures(char *FileName, GSM_Backup_Info *info, GSM_Backup *backup)
260{ 278{
261 GSM_GetBackupFormatFeatures(FileName, info); 279 GSM_GetBackupFormatFeatures(FileName, info);
262 280
263 if (info->PhonePhonebook && backup->PhonePhonebook[0] == NULL) info->PhonePhonebook = false; 281 if (info->PhonePhonebook && backup->PhonePhonebook[0] == NULL) info->PhonePhonebook = false;
264 if (info->SIMPhonebook && backup->SIMPhonebook[0] == NULL) info->SIMPhonebook = false; 282 if (info->SIMPhonebook && backup->SIMPhonebook[0] == NULL) info->SIMPhonebook = false;
265 if (info->Calendar && backup->Calendar[0] == NULL) info->Calendar = false; 283 if (info->Calendar && backup->Calendar[0] == NULL) info->Calendar = false;
266 if (info->ToDo && backup->ToDo[0] == NULL) info->ToDo = false; 284 if (info->ToDo && backup->ToDo[0] == NULL) info->ToDo = false;
267 if (info->WAPBookmark && backup->WAPBookmark[0] == NULL) info->WAPBookmark = false; 285 if (info->WAPBookmark && backup->WAPBookmark[0] == NULL) info->WAPBookmark = false;
268 if (info->WAPSettings && backup->WAPSettings[0] == NULL) info->WAPSettings = false; 286 if (info->WAPSettings && backup->WAPSettings[0] == NULL) info->WAPSettings = false;
269 if (info->MMSSettings && backup->MMSSettings[0] == NULL) info->MMSSettings = false; 287 if (info->MMSSettings && backup->MMSSettings[0] == NULL) info->MMSSettings = false;
270 if (info->FMStation && backup->FMStation[0] == NULL) info->FMStation = false; 288 if (info->FMStation && backup->FMStation[0] == NULL) info->FMStation = false;
271 if (info->GPRSPoint && backup->GPRSPoint[0] == NULL) info->GPRSPoint = false; 289 if (info->GPRSPoint && backup->GPRSPoint[0] == NULL) info->GPRSPoint = false;
272 if (info->Profiles && backup->Profiles[0] == NULL) info->Profiles = false; 290 if (info->Profiles && backup->Profiles[0] == NULL) info->Profiles = false;
273 /* .... */ 291 /* .... */
274} 292}
275 293
276#endif 294#endif
277 295
278/* How should editor hadle tabs in this file? Add editor commands here. 296/* How should editor hadle tabs in this file? Add editor commands here.
279 * vim: noexpandtab sw=8 ts=8 sts=8: 297 * vim: noexpandtab sw=8 ts=8 sts=8:
280 */ 298 */
diff --git a/gammu/emb/common/service/backup/gsmback.h b/gammu/emb/common/service/backup/gsmback.h
index 1fd99b0..791e81d 100644
--- a/gammu/emb/common/service/backup/gsmback.h
+++ b/gammu/emb/common/service/backup/gsmback.h
@@ -1,48 +1,50 @@
1/* (c) 2003-2004 by Marcin Wiacek */ 1/* (c) 2003-2004 by Marcin Wiacek */
2 2
3#ifndef __gsm_back_h 3#ifndef __gsm_back_h
4#define __gsm_back_h 4#define __gsm_back_h
5 5
6#include "backgen.h" 6#include "backgen.h"
7 7
8#ifdef GSM_ENABLE_BACKUP 8#ifdef GSM_ENABLE_BACKUP
9 9
10GSM_Error GSM_SaveBackupFile(char *FileName, GSM_Backup *backup, bool UseUnicode); 10GSM_Error GSM_SaveBackupFile(char *FileName, GSM_Backup *backup, bool UseUnicode);
11GSM_Error GSM_ReadBackupFile(char *FileName, GSM_Backup *backup); 11GSM_Error GSM_ReadBackupFile(char *FileName, GSM_Backup *backup);
12 12
13void GSM_ClearBackup (GSM_Backup *backup); 13void GSM_ClearBackup (GSM_Backup *backup);
14void GSM_FreeBackup (GSM_Backup *backup); 14void GSM_FreeBackup (GSM_Backup *backup);
15 15
16typedef struct { 16typedef struct {
17 bool UseUnicode; 17 bool UseUnicode;
18 18
19 bool IMEI; 19 bool IMEI;
20 bool Model; 20 bool Model;
21 bool DateTime; 21 bool DateTime;
22 bool ToDo; 22 bool ToDo;
23 bool PhonePhonebook; 23 bool PhonePhonebook;
24 bool SIMPhonebook; 24 bool SIMPhonebook;
25 bool Calendar; 25 bool Calendar;
26 bool CallerLogos; 26 bool CallerLogos;
27 bool SMSC; 27 bool SMSC;
28 bool WAPBookmark; 28 bool WAPBookmark;
29 bool Profiles; 29 bool Profiles;
30 bool WAPSettings; 30 bool WAPSettings;
31 bool MMSSettings; 31 bool MMSSettings;
32 bool SyncMLSettings;
33 bool ChatSettings;
32 bool Ringtone; 34 bool Ringtone;
33 bool StartupLogo; 35 bool StartupLogo;
34 bool OperatorLogo; 36 bool OperatorLogo;
35 bool FMStation; 37 bool FMStation;
36 bool GPRSPoint; 38 bool GPRSPoint;
37 bool Note; 39 bool Note;
38} GSM_Backup_Info; 40} GSM_Backup_Info;
39 41
40void GSM_GetBackupFormatFeatures(char *FileName, GSM_Backup_Info *info); 42void GSM_GetBackupFormatFeatures(char *FileName, GSM_Backup_Info *info);
41void GSM_GetBackupFileFeatures (char *FileName, GSM_Backup_Info *info, GSM_Backup *backup); 43void GSM_GetBackupFileFeatures (char *FileName, GSM_Backup_Info *info, GSM_Backup *backup);
42 44
43#endif 45#endif
44#endif 46#endif
45 47
46/* How should editor hadle tabs in this file? Add editor commands here. 48/* How should editor hadle tabs in this file? Add editor commands here.
47 * vim: noexpandtab sw=8 ts=8 sts=8: 49 * vim: noexpandtab sw=8 ts=8 sts=8:
48 */ 50 */
diff --git a/gammu/emb/common/service/gsmcal.h b/gammu/emb/common/service/gsmcal.h
index 067a4a4..0a41b7b 100644
--- a/gammu/emb/common/service/gsmcal.h
+++ b/gammu/emb/common/service/gsmcal.h
@@ -216,230 +216,230 @@ typedef struct {
216 */ 216 */
217 unsigned char Text[(MAX_CALENDAR_TEXT_LENGTH + 1)*2]; 217 unsigned char Text[(MAX_CALENDAR_TEXT_LENGTH + 1)*2];
218 /** 218 /**
219 * Date and time of value, if applicable. 219 * Date and time of value, if applicable.
220 */ 220 */
221 GSM_DateTime Date; 221 GSM_DateTime Date;
222 /** 222 /**
223 * Number of value, if applicable. 223 * Number of value, if applicable.
224 */ 224 */
225 unsigned int Number; 225 unsigned int Number;
226} GSM_SubCalendarEntry; 226} GSM_SubCalendarEntry;
227 227
228/** 228/**
229 * Calendar note values. 229 * Calendar note values.
230 */ 230 */
231typedef struct { 231typedef struct {
232 /** 232 /**
233 * Type of calendar note. 233 * Type of calendar note.
234 */ 234 */
235 GSM_CalendarNoteType Type; 235 GSM_CalendarNoteType Type;
236 /** 236 /**
237 * Location in memory. 237 * Location in memory.
238 */ 238 */
239 int Location; 239 int Location;
240 /** 240 /**
241 * Number of entries. 241 * Number of entries.
242 */ 242 */
243 int EntriesNum; 243 int EntriesNum;
244 /** 244 /**
245 * Values of entries. 245 * Values of entries.
246 */ 246 */
247 GSM_SubCalendarEntry Entries[GSM_CALENDAR_ENTRIES]; 247 GSM_SubCalendarEntry Entries[GSM_CALENDAR_ENTRIES];
248} GSM_CalendarEntry; 248} GSM_CalendarEntry;
249 249
250void GSM_CalendarFindDefaultTextTimeAlarmPhoneRecurrance(GSM_CalendarEntry *entry, int *Text, int *Time, int *Alarm, int *Phone, int *Recurrance, int *EndTime, int *Location); 250void GSM_CalendarFindDefaultTextTimeAlarmPhoneRecurrance(GSM_CalendarEntry *entry, int *Text, int *Time, int *Alarm, int *Phone, int *Recurrance, int *EndTime, int *Location);
251 251
252typedef enum { 252typedef enum {
253 Nokia_VCalendar = 1, 253 Nokia_VCalendar = 1,
254 Siemens_VCalendar, 254 Siemens_VCalendar,
255 SonyEricsson_VCalendar 255 SonyEricsson_VCalendar
256} GSM_VCalendarVersion; 256} GSM_VCalendarVersion;
257 257
258GSM_Error GSM_EncodeVCALENDAR(char *Buffer, int *Length, GSM_CalendarEntry *note, bool header, GSM_VCalendarVersion Version); 258GSM_Error GSM_EncodeVCALENDAR(char *Buffer, int *Length, GSM_CalendarEntry *note, bool header, GSM_VCalendarVersion Version);
259 259
260bool IsCalendarNoteFromThePast(GSM_CalendarEntry *note); 260bool IsCalendarNoteFromThePast(GSM_CalendarEntry *note);
261 261
262typedef struct { 262typedef struct {
263 /** 263 /**
264 * Monday = 1, Tuesday = 2,... 264 * Monday = 1, Tuesday = 2,...
265 */ 265 */
266 int StartDay; 266 int StartDay;
267 /** 267 /**
268 * 0 = no delete, 1 = after day,... 268 * 0 = no delete, 1 = after day,...
269 */ 269 */
270 int AutoDelete; 270 int AutoDelete;
271} GSM_CalendarSettings; 271} GSM_CalendarSettings;
272 272
273/** 273/**
274 * Structure used for returning calendar status. 274 * Structure used for returning calendar status.
275 */ 275 */
276typedef struct { 276typedef struct {
277 /** 277 /**
278 * Number of used positions. 278 * Number of used positions.
279 */ 279 */
280 int Used; 280 int Used;
281} GSM_CalendarStatus; 281} GSM_CalendarStatus;
282 282
283 283
284/* ------------------------------ to-do ------------------------------------ */ 284/* ------------------------------ to-do ------------------------------------ */
285 285
286 #define GSM_TODO_ENTRIES 7 286 #define GSM_TODO_ENTRIES 7
287 #define MAX_TODO_TEXT_LENGTH 50 /* Alcatel BE5 50 chars */ 287 #define MAX_TODO_TEXT_LENGTH 50 /* Alcatel BE5 50 chars */
288 288
289/** 289/**
290 * Types of to do values. In parenthesis is member of @ref GSM_SubToDoEntry, 290 * Types of to do values. In parenthesis is member of @ref GSM_SubToDoEntry,
291 * where value is stored. 291 * where value is stored.
292 */ 292 */
293typedef enum { 293typedef enum {
294 /** 294 /**
295 * Due date. (Date) 295 * Due date. (Date)
296 */ 296 */
297 TODO_END_DATETIME = 1, 297 TODO_END_DATETIME = 1,
298 /** 298 /**
299 * Whether is completed. (Number) 299 * Whether is completed. (Number)
300 */ 300 */
301 TODO_COMPLETED, 301 TODO_COMPLETED,
302 /** 302 /**
303 * When should alarm be fired (Date). 303 * When should alarm be fired (Date).
304 */ 304 */
305 TODO_ALARM_DATETIME, 305 TODO_ALARM_DATETIME,
306 /** 306 /**
307 * When should silent alarm be fired (Date). 307 * When should silent alarm be fired (Date).
308 */ 308 */
309 TODO_SILENT_ALARM_DATETIME, 309 TODO_SILENT_ALARM_DATETIME,
310 /** 310 /**
311 * Text of to do (Text). 311 * Text of to do (Text).
312 */ 312 */
313 TODO_TEXT, 313 TODO_TEXT,
314 /** 314 /**
315 * Whether entry is private (Number). 315 * Whether entry is private (Number).
316 */ 316 */
317 TODO_PRIVATE, 317 TODO_PRIVATE,
318 /** 318 /**
319 * Category of entry (Number). 319 * Category of entry (Number).
320 */ 320 */
321 TODO_CATEGORY, 321 TODO_CATEGORY,
322 /** 322 /**
323 * Related contact ID (Number). 323 * Related contact ID (Number).
324 */ 324 */
325 TODO_CONTACTID, 325 TODO_CONTACTID,
326 /** 326 /**
327 * Number to call (Text). 327 * Number to call (Text).
328 */ 328 */
329 TODO_PHONE 329 TODO_PHONE
330} GSM_ToDoType; 330} GSM_ToDoType;
331 331
332/** 332/**
333 * Priority of to do. 333 * Priority of to do.
334 */ 334 */
335typedef enum { 335typedef enum {
336 GSM_Priority_High = 1, 336 GSM_Priority_High = 1,
337 GSM_Priority_Medium, 337 GSM_Priority_Medium,
338 GSM_Priority_Low 338 GSM_Priority_Low
339} GSM_ToDo_Priority; 339} GSM_ToDo_Priority;
340 340
341/** 341/**
342 * Value of to do entry. 342 * Value of to do entry.
343 */ 343 */
344typedef struct { 344typedef struct {
345 /** 345 /**
346 * Type of entry. 346 * Type of entry.
347 */ 347 */
348 GSM_ToDoType EntryType; 348 GSM_ToDoType EntryType;
349 /** 349 /**
350 * Text of value, if appropriate, see @ref GSM_ToDoType. 350 * Text of value, if appropriate, see @ref GSM_ToDoType.
351 */ 351 */
352 unsigned char Text[(MAX_TODO_TEXT_LENGTH + 1)*2]; 352 unsigned char Text[(MAX_TODO_TEXT_LENGTH + 1)*2];
353 /** 353 /**
354 * Date of value, if appropriate, see @ref GSM_ToDoType. 354 * Date of value, if appropriate, see @ref GSM_ToDoType.
355 */ 355 */
356 GSM_DateTime Date; 356 GSM_DateTime Date;
357 /** 357 /**
358 * Number of value, if appropriate, see @ref GSM_ToDoType. 358 * Number of value, if appropriate, see @ref GSM_ToDoType.
359 */ 359 */
360 unsigned int Number; 360 unsigned int Number;
361} GSM_SubToDoEntry; 361} GSM_SubToDoEntry;
362 362
363/** 363/**
364 * To do entry. 364 * To do entry.
365 */ 365 */
366typedef struct { 366typedef struct {
367 /** 367 /**
368 * Priority of entry. 368 * Priority of entry.
369 */ 369 */
370 GSM_ToDo_Priority Priority; 370 GSM_ToDo_Priority Priority;
371 /** 371 /**
372 * Location in memory. 372 * Location in memory.
373 */ 373 */
374 int Location; 374 int Location;
375 /** 375 /**
376 * Number of entries. 376 * Number of entries.
377 */ 377 */
378 int EntriesNum; 378 int EntriesNum;
379 /** 379 /**
380 * Values of current entry. 380 * Values of current entry.
381 */ 381 */
382 GSM_SubToDoEntryEntries[GSM_TODO_ENTRIES]; 382 GSM_SubToDoEntryEntries[GSM_TODO_ENTRIES];
383} GSM_ToDoEntry; 383} GSM_ToDoEntry;
384 384
385void GSM_ToDoFindDefaultTextTimeAlarmCompleted(GSM_ToDoEntry *entry, int *Text, int *Alarm, int *Completed, int *EndTime, int *Phone); 385void GSM_ToDoFindDefaultTextTimeAlarmCompleted(GSM_ToDoEntry *entry, int *Text, int *Alarm, int *Completed, int *EndTime, int *Phone);
386 386
387typedef enum { 387typedef enum {
388 Nokia_VToDo = 1, 388 Nokia_VToDo = 1,
389 SonyEricsson_VToDo 389 SonyEricsson_VToDo
390} GSM_VToDoVersion; 390} GSM_VToDoVersion;
391 391
392GSM_Error GSM_EncodeVTODO(char *Buffer, int *Length, GSM_ToDoEntry *note, bool header, GSM_VToDoVersion Version); 392GSM_Error GSM_EncodeVTODO(char *Buffer, int *Length, GSM_ToDoEntry *note, bool header, GSM_VToDoVersion Version);
393 393
394/** 394/**
395 * Status of to do entries. 395 * Status of to do entries.
396 */ 396 */
397typedef struct { 397typedef struct {
398 /** 398 /**
399 * Number of used positions. 399 * Number of used positions.
400 */ 400 */
401 int Used; 401 int Used;
402} GSM_ToDoStatus; 402} GSM_ToDoStatus;
403 403
404/* --------------------------- note ---------------------------------------- */ 404/* --------------------------- note ---------------------------------------- */
405 405
406typedef struct { 406typedef struct {
407 int Location; 407 int Location;
408 char Text[100]; 408 char Text[3000*2];
409} GSM_NoteEntry; 409} GSM_NoteEntry;
410 410
411GSM_Error GSM_EncodeVNTFile(unsigned char *Buffer, int *Length, GSM_NoteEntry *Note); 411GSM_Error GSM_EncodeVNTFile(unsigned char *Buffer, int *Length, GSM_NoteEntry *Note);
412 412
413/* --------------------------- alarm --------------------------------------- */ 413/* --------------------------- alarm --------------------------------------- */
414 414
415/** 415/**
416 * Alarm values. 416 * Alarm values.
417 */ 417 */
418typedef struct { 418typedef struct {
419 /** 419 /**
420 * Location where it is stored. 420 * Location where it is stored.
421 */ 421 */
422 int Location; 422 int Location;
423 /** 423 /**
424 * Date and time of alarm. 424 * Date and time of alarm.
425 */ 425 */
426 GSM_DateTime DateTime; 426 GSM_DateTime DateTime;
427 /** 427 /**
428 * Whether it repeats each day. 428 * Whether it repeats each day.
429 */ 429 */
430 bool Repeating; 430 bool Repeating;
431 /** 431 /**
432 * Text that is shown on display. 432 * Text that is shown on display.
433 */ 433 */
434 char Text[(MAX_CALENDAR_TEXT_LENGTH + 1) * 2]; 434 char Text[(MAX_CALENDAR_TEXT_LENGTH + 1) * 2];
435} GSM_Alarm; 435} GSM_Alarm;
436 436
437/* --------------------------- calendar & todo ----------------------------- */ 437/* --------------------------- calendar & todo ----------------------------- */
438 438
439GSM_Error GSM_DecodeVCALENDAR_VTODO(unsigned char *Buffer, int *Pos, GSM_CalendarEntry *Calendar, GSM_ToDoEntry *ToDo, GSM_VCalendarVersion CalVer, GSM_VToDoVersion ToDoVer); 439GSM_Error GSM_DecodeVCALENDAR_VTODO(unsigned char *Buffer, int *Pos, GSM_CalendarEntry *Calendar, GSM_ToDoEntry *ToDo, GSM_VCalendarVersion CalVer, GSM_VToDoVersion ToDoVer);
440 440
441#endif 441#endif
442 442
443/* How should editor hadle tabs in this file? Add editor commands here. 443/* How should editor hadle tabs in this file? Add editor commands here.
444 * vim: noexpandtab sw=8 ts=8 sts=8: 444 * vim: noexpandtab sw=8 ts=8 sts=8:
445 */ 445 */
diff --git a/gammu/emb/common/service/gsmdata.c b/gammu/emb/common/service/gsmdata.c
index 94e9b7b..9303b57 100644
--- a/gammu/emb/common/service/gsmdata.c
+++ b/gammu/emb/common/service/gsmdata.c
@@ -57,310 +57,388 @@ static void AddWAPSMSParameterText(unsigned char *Buffer, int *Length, unsigned
57 int i; 57 int i;
58 58
59 Buffer[(*Length)++] = 0x87; //PARM with attributes 59 Buffer[(*Length)++] = 0x87; //PARM with attributes
60 Buffer[(*Length)++] = ID; 60 Buffer[(*Length)++] = ID;
61 Buffer[(*Length)++] = 0x11; //VALUE 61 Buffer[(*Length)++] = 0x11; //VALUE
62 Buffer[(*Length)++] = 0x03; //Inline string 62 Buffer[(*Length)++] = 0x03; //Inline string
63 for (i=0;i<Len;i++) { 63 for (i=0;i<Len;i++) {
64 Buffer[(*Length)++] = Text[i]; //Text 64 Buffer[(*Length)++] = Text[i]; //Text
65 } 65 }
66 Buffer[(*Length)++] = 0x00; //END Inline string 66 Buffer[(*Length)++] = 0x00; //END Inline string
67 Buffer[(*Length)++] = 0x01; //END PARMeter 67 Buffer[(*Length)++] = 0x01; //END PARMeter
68} 68}
69 69
70/* http://forum.nokia.com: OTA MMS Settings 1.0, OTA Settings 7.0 */ 70/* http://forum.nokia.com: OTA MMS Settings 1.0, OTA Settings 7.0 */
71static void AddWAPSMSParameterInt(unsigned char *Buffer, int *Length, unsigned char ID, unsigned char Value) 71static void AddWAPSMSParameterInt(unsigned char *Buffer, int *Length, unsigned char ID, unsigned char Value)
72{ 72{
73 Buffer[(*Length)++] = 0x87; //PARM with attributes 73 Buffer[(*Length)++] = 0x87; //PARM with attributes
74 Buffer[(*Length)++] = ID; 74 Buffer[(*Length)++] = ID;
75 Buffer[(*Length)++] = Value; 75 Buffer[(*Length)++] = Value;
76 Buffer[(*Length)++] = 0x01; //END PARMeter 76 Buffer[(*Length)++] = 0x01; //END PARMeter
77} 77}
78 78
79/* http://forum.nokia.com : OTA MMS Settings 1.0, OTA Settings 7.0 79/* http://forum.nokia.com : OTA MMS Settings 1.0, OTA Settings 7.0
80 * http://www.wapforum.org : Wireless Datagram Protocol 80 * http://www.wapforum.org : Wireless Datagram Protocol
81 */ 81 */
82void NOKIA_EncodeWAPMMSSettingsSMSText(unsigned char *Buffer, int *Length, GSM_WAPSettings *settings, bool MMS) 82void NOKIA_EncodeWAPMMSSettingsSMSText(unsigned char *Buffer, int *Length, GSM_WAPSettings *settings, bool MMS)
83{ 83{
84 int i; 84 int i;
85 unsigned char buffer[400]; 85 unsigned char buffer[400];
86 86
87 Buffer[(*Length)++] = 0x01; //Push ID 87 Buffer[(*Length)++] = 0x01; //Push ID
88 Buffer[(*Length)++] = 0x06; //PDU Type (push) 88 Buffer[(*Length)++] = 0x06; //PDU Type (push)
89 Buffer[(*Length)++] = 0x2C; //Headers length (content type + headers) 89 Buffer[(*Length)++] = 0x2C; //Headers length (content type + headers)
90 strcpy(Buffer+(*Length),"\x1F\x2A"); 90 strcpy(Buffer+(*Length),"\x1F\x2A");
91 (*Length)=(*Length)+2; //Value length 91 (*Length)=(*Length)+2; //Value length
92 strcpy(Buffer+(*Length),"application/x-wap-prov.browser-settings"); 92 strcpy(Buffer+(*Length),"application/x-wap-prov.browser-settings");
93 (*Length)=(*Length)+39; //MIME-Type 93 (*Length)=(*Length)+39; //MIME-Type
94 Buffer[(*Length)++] = 0x00; //end inline string 94 Buffer[(*Length)++] = 0x00; //end inline string
95 strcpy(Buffer+(*Length),"\x81\xEA"); 95 strcpy(Buffer+(*Length),"\x81\xEA");
96 (*Length)=(*Length)+2; //charset UTF-8 short int. 96 (*Length)=(*Length)+2; //charset UTF-8 short int.
97 strcpy(Buffer+(*Length),"\x01\x01"); 97 strcpy(Buffer+(*Length),"\x01\x01");
98 (*Length)=(*Length)+2; //version WBXML 1.1 98 (*Length)=(*Length)+2; //version WBXML 1.1
99 Buffer[(*Length)++] = 0x6A; //charset UTF-8 99 Buffer[(*Length)++] = 0x6A; //charset UTF-8
100 Buffer[(*Length)++] = 0x00; //string table length 100 Buffer[(*Length)++] = 0x00; //string table length
101 101
102 Buffer[(*Length)++] = 0x45; //CHARACTERISTIC-LIST with content 102 Buffer[(*Length)++] = 0x45; //CHARACTERISTIC-LIST with content
103 Buffer[(*Length)++] = 0xC6; //CHARACTERISTIC with content and attributes 103 Buffer[(*Length)++] = 0xC6; //CHARACTERISTIC with content and attributes
104 Buffer[(*Length)++] = 0x06; //TYPE=ADDRESS 104 Buffer[(*Length)++] = 0x06; //TYPE=ADDRESS
105 Buffer[(*Length)++] = 0x01; //END PARMeter 105 Buffer[(*Length)++] = 0x01; //END PARMeter
106 switch (settings->Bearer) { 106 switch (settings->Bearer) {
107 case WAPSETTINGS_BEARER_GPRS: 107 case WAPSETTINGS_BEARER_GPRS:
108 /* Bearer */ 108 /* Bearer */
109 AddWAPSMSParameterInt(Buffer, Length, 0x12, 0x49); 109 AddWAPSMSParameterInt(Buffer, Length, 0x12, 0x49);
110 /* PPP_LOGINTYPE (manual login or not) */ 110 /* PPP_LOGINTYPE (manual login or not) */
111 if (settings->ManualLogin) { 111 if (settings->ManualLogin) {
112 AddWAPSMSParameterInt(Buffer, Length, 0x1D, 0x65); 112 AddWAPSMSParameterInt(Buffer, Length, 0x1D, 0x65);
113 } else { 113 } else {
114 AddWAPSMSParameterInt(Buffer, Length, 0x1D, 0x64); 114 AddWAPSMSParameterInt(Buffer, Length, 0x1D, 0x64);
115 } 115 }
116 /* PPP_AUTHTYPE*/ 116 /* PPP_AUTHTYPE*/
117 if (settings->IsNormalAuthentication) { 117 if (settings->IsNormalAuthentication) {
118 /* OTA_CSD_AUTHTYPE_PAP */ 118 /* OTA_CSD_AUTHTYPE_PAP */
119 AddWAPSMSParameterInt(Buffer, Length, 0x22, 0x70); 119 AddWAPSMSParameterInt(Buffer, Length, 0x22, 0x70);
120 } else { 120 } else {
121 /* OTA_CSD_AUTHTYPE_CHAP */ 121 /* OTA_CSD_AUTHTYPE_CHAP */
122 AddWAPSMSParameterInt(Buffer, Length, 0x22, 0x71); 122 AddWAPSMSParameterInt(Buffer, Length, 0x22, 0x71);
123 } 123 }
124 /* GPRS_ACCESSPOINTNAME */ 124 /* GPRS_ACCESSPOINTNAME */
125 AddWAPSMSParameterText(Buffer, Length, 0x1C, DecodeUnicodeString(settings->DialUp), UnicodeLength(settings->DialUp)); 125 AddWAPSMSParameterText(Buffer, Length, 0x1C, DecodeUnicodeString(settings->DialUp), UnicodeLength(settings->DialUp));
126 /* PROXY */ 126 /* PROXY */
127 AddWAPSMSParameterText(Buffer, Length, 0x13, DecodeUnicodeString(settings->IPAddress), UnicodeLength(settings->IPAddress)); 127 AddWAPSMSParameterText(Buffer, Length, 0x13, DecodeUnicodeString(settings->IPAddress), UnicodeLength(settings->IPAddress));
128 /* PPP_AUTHNAME (user) */ 128 /* PPP_AUTHNAME (user) */
129 AddWAPSMSParameterText(Buffer, Length, 0x23, DecodeUnicodeString(settings->User), UnicodeLength(settings->User)); 129 AddWAPSMSParameterText(Buffer, Length, 0x23, DecodeUnicodeString(settings->User), UnicodeLength(settings->User));
130 /* PPP_AUTHSECRET (password) */ 130 /* PPP_AUTHSECRET (password) */
131 AddWAPSMSParameterText(Buffer, Length, 0x24, DecodeUnicodeString(settings->Password), UnicodeLength(settings->Password)); 131 AddWAPSMSParameterText(Buffer, Length, 0x24, DecodeUnicodeString(settings->Password), UnicodeLength(settings->Password));
132 break; 132 break;
133 case WAPSETTINGS_BEARER_DATA: 133 case WAPSETTINGS_BEARER_DATA:
134 /* Bearer */ 134 /* Bearer */
135 AddWAPSMSParameterInt(Buffer, Length, 0x12, 0x45); 135 AddWAPSMSParameterInt(Buffer, Length, 0x12, 0x45);
136 /* CSD_DIALSTRING */ 136 /* CSD_DIALSTRING */
137 AddWAPSMSParameterText(Buffer, Length, 0x21, DecodeUnicodeString(settings->DialUp), UnicodeLength(settings->DialUp)); 137 AddWAPSMSParameterText(Buffer, Length, 0x21, DecodeUnicodeString(settings->DialUp), UnicodeLength(settings->DialUp));
138 /* PROXY */ 138 /* PROXY */
139 AddWAPSMSParameterText(Buffer, Length, 0x13, DecodeUnicodeString(settings->IPAddress), UnicodeLength(settings->IPAddress)); 139 AddWAPSMSParameterText(Buffer, Length, 0x13, DecodeUnicodeString(settings->IPAddress), UnicodeLength(settings->IPAddress));
140 /* PPP_LOGINTYPE (manual login or not) */ 140 /* PPP_LOGINTYPE (manual login or not) */
141 if (settings->ManualLogin) { 141 if (settings->ManualLogin) {
142 AddWAPSMSParameterInt(Buffer, Length, 0x1D, 0x65); 142 AddWAPSMSParameterInt(Buffer, Length, 0x1D, 0x65);
143 } else { 143 } else {
144 AddWAPSMSParameterInt(Buffer, Length, 0x1D, 0x64); 144 AddWAPSMSParameterInt(Buffer, Length, 0x1D, 0x64);
145 } 145 }
146 /* PPP_AUTHTYPE*/ 146 /* PPP_AUTHTYPE*/
147 if (settings->IsNormalAuthentication) { 147 if (settings->IsNormalAuthentication) {
148 /* OTA_CSD_AUTHTYPE_PAP */ 148 /* OTA_CSD_AUTHTYPE_PAP */
149 AddWAPSMSParameterInt(Buffer, Length, 0x22, 0x70); 149 AddWAPSMSParameterInt(Buffer, Length, 0x22, 0x70);
150 } else { 150 } else {
151 /* OTA_CSD_AUTHTYPE_CHAP */ 151 /* OTA_CSD_AUTHTYPE_CHAP */
152 AddWAPSMSParameterInt(Buffer, Length, 0x22, 0x71); 152 AddWAPSMSParameterInt(Buffer, Length, 0x22, 0x71);
153 } 153 }
154 /* CSD_CALLTYPE (type of call) */ 154 /* CSD_CALLTYPE (type of call) */
155 if (settings->IsISDNCall) { 155 if (settings->IsISDNCall) {
156 /* ISDN */ 156 /* ISDN */
157 AddWAPSMSParameterInt(Buffer, Length, 0x28, 0x73); 157 AddWAPSMSParameterInt(Buffer, Length, 0x28, 0x73);
158 } else { 158 } else {
159 /* analogue */ 159 /* analogue */
160 AddWAPSMSParameterInt(Buffer, Length, 0x28, 0x72); 160 AddWAPSMSParameterInt(Buffer, Length, 0x28, 0x72);
161 } 161 }
162 /* CSD_CALLSPEED (speed of call) */ 162 /* CSD_CALLSPEED (speed of call) */
163 switch (settings->Speed) { 163 switch (settings->Speed) {
164 case WAPSETTINGS_SPEED_AUTO: 164 case WAPSETTINGS_SPEED_AUTO:
165 AddWAPSMSParameterInt(Buffer, Length, 0x29, 0x6A); 165 AddWAPSMSParameterInt(Buffer, Length, 0x29, 0x6A);
166 break; 166 break;
167 case WAPSETTINGS_SPEED_9600: 167 case WAPSETTINGS_SPEED_9600:
168 AddWAPSMSParameterInt(Buffer, Length, 0x29, 0x6B); 168 AddWAPSMSParameterInt(Buffer, Length, 0x29, 0x6B);
169 break; 169 break;
170 case WAPSETTINGS_SPEED_14400: 170 case WAPSETTINGS_SPEED_14400:
171 AddWAPSMSParameterInt(Buffer, Length, 0x29, 0x6C); 171 AddWAPSMSParameterInt(Buffer, Length, 0x29, 0x6C);
172 } 172 }
173 /* PPP_AUTHNAME (user) */ 173 /* PPP_AUTHNAME (user) */
174 AddWAPSMSParameterText(Buffer, Length, 0x23, DecodeUnicodeString(settings->User), UnicodeLength(settings->User)); 174 AddWAPSMSParameterText(Buffer, Length, 0x23, DecodeUnicodeString(settings->User), UnicodeLength(settings->User));
175 /* PPP_AUTHSECRET (password) */ 175 /* PPP_AUTHSECRET (password) */
176 AddWAPSMSParameterText(Buffer, Length, 0x24, DecodeUnicodeString(settings->Password), UnicodeLength(settings->Password)); 176 AddWAPSMSParameterText(Buffer, Length, 0x24, DecodeUnicodeString(settings->Password), UnicodeLength(settings->Password));
177 break; 177 break;
178#ifdef DEVELOP 178#ifdef DEVELOP
179 case WAPSETTINGS_BEARER_SMS: 179 case WAPSETTINGS_BEARER_SMS:
180 /* Bearer */ 180 /* Bearer */
181 AddWAPSMSParameterInt(Buffer, Length, 0x12, 0x41); 181 AddWAPSMSParameterInt(Buffer, Length, 0x12, 0x41);
182 /* PROXY */ 182 /* PROXY */
183 AddWAPSMSParameterText(Buffer, Length, 0x13, DecodeUnicodeString(settings->Server), UnicodeLength(settings->Server)); 183 AddWAPSMSParameterText(Buffer, Length, 0x13, DecodeUnicodeString(settings->Server), UnicodeLength(settings->Server));
184 /* SMS_SMSC_ADDRESS */ 184 /* SMS_SMSC_ADDRESS */
185 // ..... 185 // .....
186 break; 186 break;
187 case WAPSETTINGS_BEARER_USSD: 187 case WAPSETTINGS_BEARER_USSD:
188 /* FIXME */ 188 /* FIXME */
189 /* Bearer */ 189 /* Bearer */
190 AddWAPSMSParameterInt(Buffer, Length, 0x12, 0x41); 190 AddWAPSMSParameterInt(Buffer, Length, 0x12, 0x41);
191 /* PROXY */ 191 /* PROXY */
192 AddWAPSMSParameterText(Buffer, Length, 0x13, DecodeUnicodeString(settings->Service), UnicodeLength(settings->Service)); 192 AddWAPSMSParameterText(Buffer, Length, 0x13, DecodeUnicodeString(settings->Service), UnicodeLength(settings->Service));
193 /* USSD_SERVICE_CODE */ 193 /* USSD_SERVICE_CODE */
194 /* FIXME */ 194 /* FIXME */
195 AddWAPSMSParameterText(Buffer, Length, 0x13, DecodeUnicodeString(settings->Code), UnicodeLength(settings->Code)); 195 AddWAPSMSParameterText(Buffer, Length, 0x13, DecodeUnicodeString(settings->Code), UnicodeLength(settings->Code));
196#else 196#else
197 case WAPSETTINGS_BEARER_SMS: 197 case WAPSETTINGS_BEARER_SMS:
198 case WAPSETTINGS_BEARER_USSD: 198 case WAPSETTINGS_BEARER_USSD:
199 break; 199 break;
200#endif 200#endif
201 } 201 }
202 /* PORT */ 202 /* PORT */
203 if (settings->IsSecurity) { 203 if (settings->IsSecurity) {
204 if (settings->IsContinuous) { 204 if (settings->IsContinuous) {
205 /* Port = 9203. Continuous */ 205 /* Port = 9203. Continuous */
206 AddWAPSMSParameterInt(Buffer, Length, 0x14, 0x63); 206 AddWAPSMSParameterInt(Buffer, Length, 0x14, 0x63);
207 } else { 207 } else {
208 /* Port = 9202. Temporary */ 208 /* Port = 9202. Temporary */
209 AddWAPSMSParameterInt(Buffer, Length, 0x14, 0x62); 209 AddWAPSMSParameterInt(Buffer, Length, 0x14, 0x62);
210 } 210 }
211 } else { 211 } else {
212 if (settings->IsContinuous) { 212 if (settings->IsContinuous) {
213 /* Port = 9201. Continuous */ 213 /* Port = 9201. Continuous */
214 AddWAPSMSParameterInt(Buffer, Length, 0x14, 0x61); 214 AddWAPSMSParameterInt(Buffer, Length, 0x14, 0x61);
215 } else { 215 } else {
216 /* Port = 9200. Temporary */ 216 /* Port = 9200. Temporary */
217 AddWAPSMSParameterInt(Buffer, Length, 0x14, 0x60); 217 AddWAPSMSParameterInt(Buffer, Length, 0x14, 0x60);
218 } 218 }
219 } 219 }
220 Buffer[(*Length)++] = 0x01; //END PARMeter 220 Buffer[(*Length)++] = 0x01; //END PARMeter
221 221
222 /* URL */ 222 /* URL */
223 Buffer[(*Length)++] = 0x86; //CHARACTERISTIC-LIST with attributes 223 Buffer[(*Length)++] = 0x86; //CHARACTERISTIC-LIST with attributes
224 if (MMS) { 224 if (MMS) {
225 Buffer[(*Length)++] = 0x7C; //TYPE = MMSURL 225 Buffer[(*Length)++] = 0x7C; //TYPE = MMSURL
226 } else { 226 } else {
227 Buffer[(*Length)++] = 0x07; //TYPE = URL 227 Buffer[(*Length)++] = 0x07; //TYPE = URL
228 } 228 }
229 Buffer[(*Length)++] = 0x11; //VALUE 229 Buffer[(*Length)++] = 0x11; //VALUE
230 Buffer[(*Length)++] = 0x03; //Inline string 230 Buffer[(*Length)++] = 0x03; //Inline string
231 sprintf(buffer,"%s",DecodeUnicodeString(settings->HomePage)); 231 sprintf(buffer,"%s",DecodeUnicodeString(settings->HomePage));
232 for (i=0;i<(int)strlen(buffer);i++) { 232 for (i=0;i<(int)strlen(buffer);i++) {
233 Buffer[(*Length)++] = buffer[i];//Text 233 Buffer[(*Length)++] = buffer[i];//Text
234 } 234 }
235 Buffer[(*Length)++] = 0x00; //END Inline string 235 Buffer[(*Length)++] = 0x00; //END Inline string
236 Buffer[(*Length)++] = 0x01; //END PARMeter 236 Buffer[(*Length)++] = 0x01; //END PARMeter
237 237
238 /* ISP_NAME (name) */ 238 /* ISP_NAME (name) */
239 Buffer[(*Length)++] = 0xC6; //CHARACTERISTIC with content and attributes 239 Buffer[(*Length)++] = 0xC6; //CHARACTERISTIC with content and attributes
240 Buffer[(*Length)++] = 0x08; //TYPE=NAME 240 Buffer[(*Length)++] = 0x08; //TYPE=NAME
241 Buffer[(*Length)++] = 0x01; //END PARMeter 241 Buffer[(*Length)++] = 0x01; //END PARMeter
242 /* Settings name */ 242 /* Settings name */
243 AddWAPSMSParameterText(Buffer, Length, 0x15, DecodeUnicodeString(settings->Title), UnicodeLength(settings->Title)); 243 AddWAPSMSParameterText(Buffer, Length, 0x15, DecodeUnicodeString(settings->Title), UnicodeLength(settings->Title));
244 Buffer[(*Length)++] = 0x01; //END PARMeter 244 Buffer[(*Length)++] = 0x01; //END PARMeter
245 Buffer[(*Length)++] = 0x01; //END PARMeter 245 Buffer[(*Length)++] = 0x01; //END PARMeter
246} 246}
247 247
248/* http://forum.nokia.com: OTA Settings 7.0 */ 248/* http://forum.nokia.com: OTA Settings 7.0 */
249/* first it used default/ISO coding */
250/* Joergen Thomsen changed to UTF8 */
249void NOKIA_EncodeWAPBookmarkSMSText(unsigned char *Buffer, int *Length, GSM_WAPBookmark *bookmark) 251void NOKIA_EncodeWAPBookmarkSMSText(unsigned char *Buffer, int *Length, GSM_WAPBookmark *bookmark)
250{ 252{
251 unsigned charbuffer[100]; 253 unsigned charbuffer[100];
252 bool UnicodeCoding = false;
253 254
254 EncodeUTF8QuotedPrintable(buffer,bookmark->Title); 255 // bool UnicodeCoding = false;
255 if (UnicodeLength(bookmark->Title)!=strlen(buffer)) UnicodeCoding = true; 256 //EncodeUTF8QuotedPrintable(buffer,bookmark->Title);
257 //if (UnicodeLength(bookmark->Title)!=strlen(buffer)) UnicodeCoding = true;
256 258
257 Buffer[(*Length)++] = 0x01; //Push ID 259 Buffer[(*Length)++] = 0x01; //Push ID
258 Buffer[(*Length)++] = 0x06; //PDU Type (push) 260 Buffer[(*Length)++] = 0x06; //PDU Type (push)
259 Buffer[(*Length)++] = 0x2D; //Headers length (content type + headers) 261 Buffer[(*Length)++] = 0x2D; //Headers length (content type + headers)
260 strcpy(Buffer+(*Length),"\x1F\x2B"); 262 strcpy(Buffer+(*Length),"\x1F\x2B");
261 (*Length)=(*Length)+2; //Value length 263 (*Length)=(*Length)+2; //Value length
262 strcpy(Buffer+(*Length),"application/x-wap-prov.browser-bookmarks"); 264 strcpy(Buffer+(*Length),"application/x-wap-prov.browser-bookmarks");
263 (*Length)=(*Length)+40; //MIME-Type 265 (*Length)=(*Length)+40; //MIME-Type
264 Buffer[(*Length)++] = 0x00; //end inline string 266 Buffer[(*Length)++] = 0x00; //end inline string
265 strcpy(Buffer+(*Length),"\x81\xEA"); 267 strcpy(Buffer+(*Length),"\x81\xEA");
266 (*Length)=(*Length)+2; //charset UTF-8 short int. 268 (*Length)=(*Length)+2; //charset UTF-8 short int.
267 269
270 /* removed by Joergen Thomsen */
268 /* Block from sniffs. UNKNOWN */ 271 /* Block from sniffs. UNKNOWN */
269 if (!UnicodeCoding) { 272 //if (!UnicodeCoding) {
270 Buffer[(*Length)++] = 0x00; 273 // Buffer[(*Length)++] = 0x00;
271 Buffer[(*Length)++] = 0x01; 274 // Buffer[(*Length)++] = 0x01;
272 } else { 275 //} else {
273 strcpy(Buffer+(*Length),"\x01\x01\x87\x68"); 276 // strcpy(Buffer+(*Length),"\x01\x01\x87\x68");
274 (*Length)=(*Length)+4; 277 // (*Length)=(*Length)+4;
275 } 278 //}
276 Buffer[(*Length)++] = 0x00; 279 //Buffer[(*Length)++] = 0x00;
280
281 /* added by Joergen Thomsen */
282 Buffer[(*Length)++] = 0x01; // Version WBXML 1.1
283 Buffer[(*Length)++] = 0x01; // Unknown public identifier
284 Buffer[(*Length)++] = 0x6A; // charset UTF-8
285 Buffer[(*Length)++] = 0x00; // string table length
277 286
278 Buffer[(*Length)++] = 0x45; //CHARACTERISTIC-LIST with content 287 Buffer[(*Length)++] = 0x45; //CHARACTERISTIC-LIST with content
279 /* URL */ 288 /* URL */
280 Buffer[(*Length)++] = 0xC6; //CHARACTERISTIC with content and attributes 289 Buffer[(*Length)++] = 0xC6; //CHARACTERISTIC with content and attributes
281 Buffer[(*Length)++] = 0x7F; //TYPE = BOOKMARK 290 Buffer[(*Length)++] = 0x7F; //TYPE = BOOKMARK
282 Buffer[(*Length)++] = 0x01; //END PARMeter 291 Buffer[(*Length)++] = 0x01; //END PARMeter
283 if (!UnicodeCoding) { 292
284 /* TITLE */ 293 /* removed by Joergen Thomsen */
285 AddWAPSMSParameterText(Buffer, Length, 0x15, DecodeUnicodeString(bookmark->Title), UnicodeLength(bookmark->Title)); 294 // if (!UnicodeCoding) {
286 /* URL */ 295 // /* TITLE */
287 AddWAPSMSParameterText(Buffer, Length, 0x17, DecodeUnicodeString(bookmark->Address), UnicodeLength(bookmark->Address)); 296 // AddWAPSMSParameterText(Buffer, Length, 0x15, DecodeUnicodeString(bookmark->Title), UnicodeLength(bookmark->Title));
288 } else { 297 // /* URL */
289 /* TITLE */ 298 // AddWAPSMSParameterText(Buffer, Length, 0x17, DecodeUnicodeString(bookmark->Address), UnicodeLength(bookmark->Address));
290 AddWAPSMSParameterText(Buffer, Length, 0x15, bookmark->Title, UnicodeLength(bookmark->Title)*2+1); 299 // } else {
291 /* URL */ 300 // /* TITLE */
292 AddWAPSMSParameterText(Buffer, Length, 0x17, bookmark->Address, UnicodeLength(bookmark->Address)*2+1); 301 // AddWAPSMSParameterText(Buffer, Length, 0x15, bookmark->Title, UnicodeLength(bookmark->Title)*2+1);
302 // /* URL */
303 // AddWAPSMSParameterText(Buffer, Length, 0x17, bookmark->Address, UnicodeLength(bookmark->Address)*2+1);
304 // }
305
306 /* added by Joergen Thomsen */
307 /* TITLE */
308 EncodeUTF8(buffer, bookmark->Title);
309 AddWAPSMSParameterText(Buffer, Length, 0x15, buffer, strlen(buffer));
310 /* URL */
311 EncodeUTF8(buffer, bookmark->Address);
312 AddWAPSMSParameterText(Buffer, Length, 0x17, buffer, strlen(buffer));
313
314 Buffer[(*Length)++] = 0x01; //END (CHARACTERISTIC)
315 Buffer[(*Length)++] = 0x01; //END (CHARACTERISTIC-LIST)
316}
317
318void GSM_EncodeWAPIndicatorSMSText(unsigned char *Buffer, int *Length, char *Text, char *URL)
319{
320 int i;
321
322 Buffer[(*Length)++] = 0x01; //Push ID
323 Buffer[(*Length)++] = 0x06; //PDU Type (push)
324 Buffer[(*Length)++] = 28; //Headers length (content type + headers)
325 strcpy(Buffer+(*Length),"\x1F\x23");
326 (*Length)=(*Length)+2; //Value length
327 strcpy(Buffer+(*Length),"application/vnd.wap.sic");
328 (*Length)=(*Length)+23; //MIME-Type
329 Buffer[(*Length)++] = 0x00; //end inline string
330 strcpy(Buffer+(*Length),"\x81\xEA");
331 (*Length)=(*Length)+2; //charset UTF-8 short int.
332
333 Buffer[(*Length)++] = 0x02; // WBXML 1.2
334 Buffer[(*Length)++] = 0x05; // SI 1.0 Public Identifier
335 Buffer[(*Length)++] = 0x6A; // charset UTF-8
336 Buffer[(*Length)++] = 0x00; // string table length
337 Buffer[(*Length)++] = 0x45; // SI with content
338 Buffer[(*Length)++] = 0xC6; // indication with content and attributes
339 Buffer[(*Length)++] = 0x0B;// address
340 Buffer[(*Length)++] = 0x03; // Inline string
341 for (i=0;i<(int)strlen(URL);i++) {
342 Buffer[(*Length)++] = URL[i];//Text
293 } 343 }
294 Buffer[(*Length)++] = 0x01; //END PARMeter 344 Buffer[(*Length)++] = 0x00; // END Inline string
295 Buffer[(*Length)++] = 0x01; //END PARMeter 345
346#ifdef XXX
347 Buffer[(*Length)++] = 0x0A;// created...
348 Buffer[(*Length)++] = 0xC3;// OPAQUE
349 Buffer[(*Length)++] = 0x07;// length
350 Buffer[(*Length)++] = 0x19;// year
351 Buffer[(*Length)++] = 0x80;// year
352 Buffer[(*Length)++] = 0x21;// month
353 Buffer[(*Length)++] = 0x12;// ..
354 Buffer[(*Length)++] = 0x00;// ..
355 Buffer[(*Length)++] = 0x00;// ..
356 Buffer[(*Length)++] = 0x00;// ..
357 Buffer[(*Length)++] = 0x10;// expires
358 Buffer[(*Length)++] = 0xC3;// OPAQUE
359 Buffer[(*Length)++] = 0x04;// length
360 Buffer[(*Length)++] = 0x20;// year
361 Buffer[(*Length)++] = 0x10;// year
362 Buffer[(*Length)++] = 0x06;// month
363 Buffer[(*Length)++] = 0x25;// day
364#endif
365
366 Buffer[(*Length)++] = 0x01; // END (indication)
367 Buffer[(*Length)++] = 0x03; // Inline string
368 for (i=0;i<(int)strlen(Text);i++) {
369 Buffer[(*Length)++] = Text[i];//Text
370 }
371 Buffer[(*Length)++] = 0x00; // END Inline string
372 Buffer[(*Length)++] = 0x01; // END (indication)
373 Buffer[(*Length)++] = 0x01; // END (SI)
296} 374}
297 375
298void GSM_EncodeMMSFile(GSM_EncodeMultiPartMMSInfo *Info, unsigned char *Buffer, int *Length) 376void GSM_EncodeMMSFile(GSM_EncodeMultiPartMMSInfo *Info, unsigned char *Buffer, int *Length)
299{ 377{
300 int i; 378 int i;
301 379
302 strcpy(Buffer+(*Length),"\x8C\x80\x98\x4F"); 380 strcpy(Buffer+(*Length),"\x8C\x80\x98\x4F");
303 (*Length)=(*Length)+4; 381 (*Length)=(*Length)+4;
304 382
305 /* Unique MMS ID ? */ 383 /* Unique MMS ID ? */
306 strcpy(Buffer+(*Length),"123456789"); 384 strcpy(Buffer+(*Length),"123456789");
307 (*Length)=(*Length)+9; 385 (*Length)=(*Length)+9;
308 Buffer[(*Length)++] = 0x00; 386 Buffer[(*Length)++] = 0x00;
309 387
310 strcpy(Buffer+(*Length),"\x8D\x90\x89"); 388 strcpy(Buffer+(*Length),"\x8D\x90\x89");
311 (*Length)=(*Length)+3; 389 (*Length)=(*Length)+3;
312 390
313 strcpy(Buffer+(*Length),"\x01\x81\x86\x81\x96"); 391 strcpy(Buffer+(*Length),"\x01\x81\x86\x81\x96");
314 (*Length)=(*Length)+5; 392 (*Length)=(*Length)+5;
315 393
316 if (UnicodeLength(Info->Subject) != 0) { 394 if (UnicodeLength(Info->Subject) != 0) {
317 sprintf(Buffer+(*Length),"%s",DecodeUnicodeString(Info->Subject)); 395 sprintf(Buffer+(*Length),"%s",DecodeUnicodeString(Info->Subject));
318 (*Length)=(*Length)+UnicodeLength(Info->Subject); 396 (*Length)=(*Length)+UnicodeLength(Info->Subject);
319 Buffer[(*Length)++] = 0x00; 397 Buffer[(*Length)++] = 0x00;
320 } 398 }
321 399
322 for (i=0;i<Info->EntriesNum;i++) { 400 for (i=0;i<Info->EntriesNum;i++) {
323 switch(Info->Entries[i].ID) { 401 switch(Info->Entries[i].ID) {
324 case MMS_Text: 402 case MMS_Text:
325 strcpy(Buffer+(*Length),"\x84\xA3\x01\x04\x04\x03\x83\x81\xEA"); 403 strcpy(Buffer+(*Length),"\x84\xA3\x01\x04\x04\x03\x83\x81\xEA");
326 (*Length)=(*Length)+9; 404 (*Length)=(*Length)+9;
327 405
328 sprintf(Buffer+(*Length),"%s",DecodeUnicodeString(Info->Entries[i].Buffer)); 406 sprintf(Buffer+(*Length),"%s",DecodeUnicodeString(Info->Entries[i].Buffer));
329 (*Length)=(*Length)+UnicodeLength(Info->Entries[i].Buffer); 407 (*Length)=(*Length)+UnicodeLength(Info->Entries[i].Buffer);
330 break; 408 break;
331 default: 409 default:
332 break; 410 break;
333 } 411 }
334 } 412 }
335} 413}
336 414
337void GSM_ClearMultiPartMMSInfo(GSM_EncodeMultiPartMMSInfo *Info) 415void GSM_ClearMultiPartMMSInfo(GSM_EncodeMultiPartMMSInfo *Info)
338{ 416{
339 Info->EntriesNum= 0; 417 Info->EntriesNum= 0;
340 Info->Subject[0]= 0x00; 418 Info->Subject[0]= 0x00;
341 Info->Subject[1]= 0x00; 419 Info->Subject[1]= 0x00;
342 Info->Source[0] = 0x00; 420 Info->Source[0] = 0x00;
343 Info->Source[1] = 0x00; 421 Info->Source[1] = 0x00;
344 Info->Destination[0] = 0x00; 422 Info->Destination[0] = 0x00;
345 Info->Destination[1] = 0x00; 423 Info->Destination[1] = 0x00;
346} 424}
347 425
348GSM_Error GSM_EncodeURLFile(unsigned char *Buffer, int *Length, GSM_WAPBookmark *bookmark) 426GSM_Error GSM_EncodeURLFile(unsigned char *Buffer, int *Length, GSM_WAPBookmark *bookmark)
349{ 427{
350 *Length+=sprintf(Buffer+(*Length), "BEGIN:VBKM%c%c",13,10); 428 *Length+=sprintf(Buffer+(*Length), "BEGIN:VBKM%c%c",13,10);
351 *Length+=sprintf(Buffer+(*Length), "VERSION:1.0%c%c",13,10); 429 *Length+=sprintf(Buffer+(*Length), "VERSION:1.0%c%c",13,10);
352 *Length+=sprintf(Buffer+(*Length), "TITLE:%s%c%c",DecodeUnicodeString(bookmark->Title),13,10); 430 *Length+=sprintf(Buffer+(*Length), "TITLE:%s%c%c",DecodeUnicodeString(bookmark->Title),13,10);
353 *Length+=sprintf(Buffer+(*Length), "URL:%s%c%c",DecodeUnicodeString(bookmark->Address),13,10); 431 *Length+=sprintf(Buffer+(*Length), "URL:%s%c%c",DecodeUnicodeString(bookmark->Address),13,10);
354 *Length+=sprintf(Buffer+(*Length), "BEGIN:ENV%c%c",13,10); 432 *Length+=sprintf(Buffer+(*Length), "BEGIN:ENV%c%c",13,10);
355 *Length+=sprintf(Buffer+(*Length), "X-IRMC-URL;QUOTED-PRINTABLE:=%c%c",13,10); 433 *Length+=sprintf(Buffer+(*Length), "X-IRMC-URL;QUOTED-PRINTABLE:=%c%c",13,10);
356 *Length+=sprintf(Buffer+(*Length), "[InternetShortcut] =%c%c",13,10); 434 *Length+=sprintf(Buffer+(*Length), "[InternetShortcut] =%c%c",13,10);
357 *Length+=sprintf(Buffer+(*Length), "URL=%s%c%c",DecodeUnicodeString(bookmark->Address),13,10); 435 *Length+=sprintf(Buffer+(*Length), "URL=%s%c%c",DecodeUnicodeString(bookmark->Address),13,10);
358 *Length+=sprintf(Buffer+(*Length), "END:ENV%c%c",13,10); 436 *Length+=sprintf(Buffer+(*Length), "END:ENV%c%c",13,10);
359 *Length+=sprintf(Buffer+(*Length), "END:VBKM%c%c",13,10); 437 *Length+=sprintf(Buffer+(*Length), "END:VBKM%c%c",13,10);
360 438
361 return ERR_NONE; 439 return ERR_NONE;
362} 440}
363 441
364/* How should editor hadle tabs in this file? Add editor commands here. 442/* How should editor hadle tabs in this file? Add editor commands here.
365 * vim: noexpandtab sw=8 ts=8 sts=8: 443 * vim: noexpandtab sw=8 ts=8 sts=8:
366 */ 444 */
diff --git a/gammu/emb/common/service/gsmdata.h b/gammu/emb/common/service/gsmdata.h
index f5f8e07..e81589f 100644
--- a/gammu/emb/common/service/gsmdata.h
+++ b/gammu/emb/common/service/gsmdata.h
@@ -1,152 +1,154 @@
1/* (c) 2001-2004 by Marcin Wiacek */ 1/* (c) 2001-2004 by Marcin Wiacek */
2 2
3#ifndef __gsm_wap_h 3#ifndef __gsm_wap_h
4#define __gsm_wap_h 4#define __gsm_wap_h
5 5
6#include "gsmmisc.h" 6#include "gsmmisc.h"
7#include "../misc/misc.h" 7#include "../misc/misc.h"
8 8
9/* --------------------------- WAP or MMS settings ------------------------- */ 9/* --------------------------- WAP or MMS settings ------------------------- */
10 10
11typedef enum { 11typedef enum {
12 WAPSETTINGS_SPEED_9600, 12 WAPSETTINGS_SPEED_9600,
13 WAPSETTINGS_SPEED_14400, 13 WAPSETTINGS_SPEED_14400,
14 WAPSETTINGS_SPEED_AUTO 14 WAPSETTINGS_SPEED_AUTO
15} WAPSettings_Speed; 15} WAPSettings_Speed;
16 16
17typedef enum { 17typedef enum {
18 WAPSETTINGS_BEARER_SMS = 1, 18 WAPSETTINGS_BEARER_SMS = 1,
19 WAPSETTINGS_BEARER_DATA, 19 WAPSETTINGS_BEARER_DATA,
20 WAPSETTINGS_BEARER_USSD, 20 WAPSETTINGS_BEARER_USSD,
21 WAPSETTINGS_BEARER_GPRS 21 WAPSETTINGS_BEARER_GPRS
22} WAPSettings_Bearer; 22} WAPSettings_Bearer;
23 23
24typedef struct { 24typedef struct {
25 char Title [(20+1)*2]; 25 char Title [(20+1)*2];
26 char HomePage[(100+1)*2]; 26 char HomePage[(100+1)*2];
27 WAPSettings_BearerBearer; 27 WAPSettings_BearerBearer;
28 bool IsSecurity; 28 bool IsSecurity;
29 bool IsContinuous; 29 bool IsContinuous;
30 30
31 /* for data bearer */ 31 /* for data bearer */
32 bool IsISDNCall; 32 bool IsISDNCall;
33 bool IsNormalAuthentication; 33 bool IsNormalAuthentication;
34 34
35 /* for sms bearer */ 35 /* for sms bearer */
36 char Server [(21+1)*2]; 36 char Server [(21+1)*2];
37 37
38 /* for sms or ussd bearer */ 38 /* for sms or ussd bearer */
39 char Service [(20+1)*2]; 39 char Service [(20+1)*2];
40 bool IsIP; 40 bool IsIP;
41 41
42 /* for ussd bearer */ 42 /* for ussd bearer */
43 char Code [(10+1)*2]; 43 char Code [(10+1)*2];
44 44
45 /* for data or gprs */ 45 /* for data or gprs */
46 char IPAddress[(20+1)*2]; 46 char IPAddress[(20+1)*2];
47 bool ManualLogin; 47 bool ManualLogin;
48 char DialUp [(20+1)*2]; 48 char DialUp [(20+1)*2];
49 char User [(50+1)*2]; /*is length OK ?*/ 49 char User [(50+1)*2]; /*is length OK ?*/
50 char Password[(50+1)*2]; /*is length OK ?*/ 50 char Password[(50+1)*2]; /*is length OK ?*/
51 WAPSettings_SpeedSpeed; 51 WAPSettings_SpeedSpeed;
52} GSM_WAPSettings; 52} GSM_WAPSettings;
53 53
54typedef struct { 54typedef struct {
55 int Location; 55 int Location;
56 unsigned char Number; 56 unsigned char Number;
57 GSM_WAPSettings Settings[4]; 57 GSM_WAPSettings Settings[4];
58 bool Active; 58 bool Active;
59 bool ReadOnly; 59 bool ReadOnly;
60 char Proxy [(100+1)*2]; 60 char Proxy [(100+1)*2];
61 int ProxyPort; 61 int ProxyPort;
62 char Proxy2 [(100+1)*2]; 62 char Proxy2 [(100+1)*2];
63 int Proxy2Port; 63 int Proxy2Port;
64 64
65 WAPSettings_BearerActiveBearer; 65 WAPSettings_BearerActiveBearer;
66} GSM_MultiWAPSettings; 66} GSM_MultiWAPSettings;
67 67
68void NOKIA_EncodeWAPMMSSettingsSMSText(unsigned char *Buffer, int *Length, GSM_WAPSettings *settings, bool MMS); 68void NOKIA_EncodeWAPMMSSettingsSMSText(unsigned char *Buffer, int *Length, GSM_WAPSettings *settings, bool MMS);
69 69
70/* -------------------------------- WAP Bookmark --------------------------- */ 70/* -------------------------------- WAP Bookmark --------------------------- */
71 71
72typedef struct { 72typedef struct {
73 char Address [(255+1)*2]; 73 char Address [(255+1)*2];
74 char Title [(50+1)*2]; 74 char Title [(50+1)*2];
75 int Location; 75 int Location;
76} GSM_WAPBookmark; 76} GSM_WAPBookmark;
77 77
78 void NOKIA_EncodeWAPBookmarkSMSText(unsigned char *Buffer, int *Length, GSM_WAPBookmark *bookmark); 78 void NOKIA_EncodeWAPBookmarkSMSText(unsigned char *Buffer, int *Length, GSM_WAPBookmark *bookmark);
79 GSM_Error GSM_EncodeURLFile (unsigned char *Buffer, int *Length, GSM_WAPBookmark *bookmark); 79 GSM_Error GSM_EncodeURLFile (unsigned char *Buffer, int *Length, GSM_WAPBookmark *bookmark);
80 80
81/* ------------------------------ MMS Indicator ---------------------------- */ 81/* ------------------------------ MMS Indicator ---------------------------- */
82 82
83typedef struct { 83typedef struct {
84 unsigned char Address[500]; 84 unsigned char Address[500];
85 unsigned char Title[200]; 85 unsigned char Title[200];
86 unsigned char Sender[200]; 86 unsigned char Sender[200];
87} GSM_MMSIndicator; 87} GSM_MMSIndicator;
88 88
89void GSM_EncodeMMSIndicatorSMSText(unsigned char *Buffer, int *Length, GSM_MMSIndicator Indicator); 89void GSM_EncodeMMSIndicatorSMSText(unsigned char *Buffer, int *Length, GSM_MMSIndicator Indicator);
90 90
91void GSM_EncodeWAPIndicatorSMSText(unsigned char *Buffer, int *Length, char *Text, char *URL);
92
91/* ------------------------------ MMS file --------------------------------- */ 93/* ------------------------------ MMS file --------------------------------- */
92 94
93#define MAX_MULTI_MMS 20 95#define MAX_MULTI_MMS 20
94 96
95typedef enum { 97typedef enum {
96 MMS_Text = 1, 98 MMS_Text = 1,
97 MMS_Bitmap_JPG 99 MMS_Bitmap_JPG
98} EncodeMultiPartMMSID; 100} EncodeMultiPartMMSID;
99 101
100typedef struct { 102typedef struct {
101 EncodeMultiPartMMSID ID; 103 EncodeMultiPartMMSID ID;
102 104
103 GSM_File File; 105 GSM_File File;
104 unsigned char *Buffer; 106 unsigned char *Buffer;
105} EncodeMultiPartMMSEntry; 107} EncodeMultiPartMMSEntry;
106 108
107typedef struct { 109typedef struct {
108 /* Input values */ 110 /* Input values */
109 EncodeMultiPartMMSEntry Entries[MAX_MULTI_MMS]; 111 EncodeMultiPartMMSEntry Entries[MAX_MULTI_MMS];
110 int EntriesNum; 112 int EntriesNum;
111 113
112 unsigned char Source[200]; 114 unsigned char Source[200];
113 unsigned char Destination[200]; 115 unsigned char Destination[200];
114 unsigned char Subject[200]; 116 unsigned char Subject[200];
115} GSM_EncodeMultiPartMMSInfo; 117} GSM_EncodeMultiPartMMSInfo;
116 118
117 void GSM_EncodeMMSFile (GSM_EncodeMultiPartMMSInfo *Info, unsigned char *Buffer, int *Length); 119 void GSM_EncodeMMSFile (GSM_EncodeMultiPartMMSInfo *Info, unsigned char *Buffer, int *Length);
118 void GSM_ClearMultiPartMMSInfo(GSM_EncodeMultiPartMMSInfo *Info); 120 void GSM_ClearMultiPartMMSInfo(GSM_EncodeMultiPartMMSInfo *Info);
119 121
120/* ------------------------------------------------------------------------ */ 122/* ------------------------------------------------------------------------ */
121 123
122typedef struct { 124typedef struct {
123 int Location; 125 int Location;
124 bool Active; 126 bool Active;
125 bool SyncPhonebook; 127 bool SyncPhonebook;
126 bool SyncCalendar; 128 bool SyncCalendar;
127 char Name[(20+1)*2]; 129 char Name[(20+1)*2];
128 char PhonebookDataBase[(50+1)*2]; 130 char PhonebookDataBase[(50+1)*2];
129 char CalendarDataBase[(50+1)*2]; 131 char CalendarDataBase[(50+1)*2];
130 char User[(30+1)*2]; 132 char User[(30+1)*2];
131 char Password[(20+1)*2]; 133 char Password[(20+1)*2];
132 char Server[(128+1)*2]; 134 char Server[(128+1)*2];
133 GSM_MultiWAPSettingsConnection; 135 GSM_MultiWAPSettingsConnection;
134} GSM_SyncMLSettings; 136} GSM_SyncMLSettings;
135 137
136/* ------------------------------------------------------------------------ */ 138/* ------------------------------------------------------------------------ */
137 139
138typedef struct { 140typedef struct {
139 char Name[(50+1)*2]; 141 char Name[(50+1)*2];
140 char HomePage[(200+1)*2]; 142 char HomePage[(200+1)*2];
141 char User[(50+1)*2]; 143 char User[(50+1)*2];
142 char Password[(50+1)*2]; 144 char Password[(50+1)*2];
143 int Location; 145 int Location;
144 bool Active; 146 bool Active;
145 GSM_MultiWAPSettingsConnection; 147 GSM_MultiWAPSettingsConnection;
146} GSM_ChatSettings; 148} GSM_ChatSettings;
147 149
148#endif 150#endif
149 151
150/* How should editor hadle tabs in this file? Add editor commands here. 152/* How should editor hadle tabs in this file? Add editor commands here.
151 * vim: noexpandtab sw=8 ts=8 sts=8: 153 * vim: noexpandtab sw=8 ts=8 sts=8:
152 */ 154 */
diff --git a/gammu/emb/common/service/gsmlogo.c b/gammu/emb/common/service/gsmlogo.c
index c992915..7c19967 100644
--- a/gammu/emb/common/service/gsmlogo.c
+++ b/gammu/emb/common/service/gsmlogo.c
@@ -1,355 +1,357 @@
1/* (c) 2001-2004 by Marcin Wiacek */ 1/* (c) 2001-2004 by Marcin Wiacek */
2 2
3#include <string.h> 3#include <string.h>
4#include <stdlib.h> 4#include <stdlib.h>
5#include <sys/stat.h>
5 6
6#include "../misc/misc.h" 7#include "../misc/misc.h"
7#include "../misc/coding/coding.h" 8#include "../misc/coding/coding.h"
8#include "gsmlogo.h" 9#include "gsmlogo.h"
9#include "gsmnet.h" 10#include "gsmnet.h"
10 11
11void PHONE_GetBitmapWidthHeight(GSM_Phone_Bitmap_Types Type, int *width, int *height) 12void PHONE_GetBitmapWidthHeight(GSM_Phone_Bitmap_Types Type, int *width, int *height)
12{ 13{
13 *width = 0; 14 *width = 0;
14 *height= 0; 15 *height= 0;
15 switch (Type) { 16 switch (Type) {
16 case GSM_EMSSmallPicture: *width=8; *height=8; break; 17 case GSM_EMSSmallPicture: *width=8; *height=8; break;
17 case GSM_EMSMediumPicture: *width=16; *height=16; break; 18 case GSM_EMSMediumPicture: *width=16; *height=16; break;
18 case GSM_EMSBigPicture : *width=32; *height=32; break; 19 case GSM_EMSBigPicture : *width=32; *height=32; break;
19 case GSM_NokiaOperatorLogo: 20 case GSM_NokiaOperatorLogo:
20 case GSM_NokiaCallerLogo: *width=72; *height=14; break; 21 case GSM_NokiaCallerLogo: *width=72; *height=14; break;
21 case GSM_NokiaPictureImage: *width=72; *height=28; break; 22 case GSM_NokiaPictureImage: *width=72; *height=28; break;
22 case GSM_Nokia7110OperatorLogo: 23 case GSM_Nokia7110OperatorLogo:
23 case GSM_Nokia6510OperatorLogo: *width=78; *height=21; break; 24 case GSM_Nokia6510OperatorLogo: *width=78; *height=21; break;
24 case GSM_NokiaStartupLogo: *width=84; *height=48; break; 25 case GSM_NokiaStartupLogo: *width=84; *height=48; break;
25 case GSM_Nokia6210StartupLogo: *width=96; *height=60; break; 26 case GSM_Nokia6210StartupLogo: *width=96; *height=60; break;
26 case GSM_Nokia7110StartupLogo: *width=96; *height=65; break; 27 case GSM_Nokia7110StartupLogo: *width=96; *height=65; break;
27 case GSM_EMSVariablePicture : break; 28 case GSM_EMSVariablePicture : break;
28 case GSM_AlcatelBMMIPicture : break; 29 case GSM_AlcatelBMMIPicture : break;
29 } 30 }
30} 31}
31 32
32int PHONE_GetBitmapSize(GSM_Phone_Bitmap_Types Type, int Width, int Height) 33int PHONE_GetBitmapSize(GSM_Phone_Bitmap_Types Type, int Width, int Height)
33{ 34{
34 int width, height, x; 35 int width, height, x;
35 36
36 PHONE_GetBitmapWidthHeight(Type, &width, &height); 37 PHONE_GetBitmapWidthHeight(Type, &width, &height);
37 if (width == 0 && height == 0) { 38 if (width == 0 && height == 0) {
38 width = Width; 39 width = Width;
39 height = Height; 40 height = Height;
40 } 41 }
41 switch (Type) { 42 switch (Type) {
42 case GSM_Nokia6510OperatorLogo: 43 case GSM_Nokia6510OperatorLogo:
43 x = width * height; 44 x = width * height;
44 return x/8 + (x%8 > 0); 45 return x/8 + (x%8 > 0);
45 case GSM_Nokia7110OperatorLogo: 46 case GSM_Nokia7110OperatorLogo:
46 return (width*height + 7)/8; 47 return (width*height + 7)/8;
47 case GSM_NokiaStartupLogo: 48 case GSM_NokiaStartupLogo:
48 case GSM_NokiaOperatorLogo: 49 case GSM_NokiaOperatorLogo:
49 case GSM_NokiaCallerLogo: 50 case GSM_NokiaCallerLogo:
50 case GSM_NokiaPictureImage: 51 case GSM_NokiaPictureImage:
51 case GSM_EMSSmallPicture: 52 case GSM_EMSSmallPicture:
52 case GSM_EMSMediumPicture: 53 case GSM_EMSMediumPicture:
53 case GSM_EMSBigPicture: 54 case GSM_EMSBigPicture:
54 case GSM_EMSVariablePicture: 55 case GSM_EMSVariablePicture:
55 return height*width/8; 56 return height*width/8;
56 case GSM_Nokia7110StartupLogo: 57 case GSM_Nokia7110StartupLogo:
57 case GSM_Nokia6210StartupLogo: 58 case GSM_Nokia6210StartupLogo:
58 return (height+7)/8*width; 59 return (height+7)/8*width;
59 case GSM_AlcatelBMMIPicture: 60 case GSM_AlcatelBMMIPicture:
60 return width*((height+7)/8); 61 return width*((height+7)/8);
61 } 62 }
62 return 0; 63 return 0;
63} 64}
64 65
65static bool PHONE_IsPointBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, int x, int y, int width, int height) 66static bool PHONE_IsPointBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, int x, int y, int width, int height)
66{ 67{
67 int i=0, pixel; 68 int i=0, pixel;
68 69
69 switch (Type) { 70 switch (Type) {
70 case GSM_NokiaStartupLogo: 71 case GSM_NokiaStartupLogo:
71 case GSM_Nokia6210StartupLogo: 72 case GSM_Nokia6210StartupLogo:
72 case GSM_Nokia7110StartupLogo: 73 case GSM_Nokia7110StartupLogo:
73 case GSM_Nokia6510OperatorLogo: 74 case GSM_Nokia6510OperatorLogo:
74 i=(buffer[(y/8*width) + x] & 1<<(y%8)); 75 i=(buffer[(y/8*width) + x] & 1<<(y%8));
75 break; 76 break;
76 case GSM_NokiaOperatorLogo: 77 case GSM_NokiaOperatorLogo:
77 case GSM_Nokia7110OperatorLogo: 78 case GSM_Nokia7110OperatorLogo:
78 case GSM_NokiaCallerLogo: 79 case GSM_NokiaCallerLogo:
79 case GSM_EMSVariablePicture: 80 case GSM_EMSVariablePicture:
80 case GSM_EMSSmallPicture: 81 case GSM_EMSSmallPicture:
81 case GSM_EMSMediumPicture: 82 case GSM_EMSMediumPicture:
82 case GSM_EMSBigPicture: 83 case GSM_EMSBigPicture:
83 pixel=width*y + x; 84 pixel=width*y + x;
84 i=(buffer[pixel/8] & 1<<(7-(pixel%8))); 85 i=(buffer[pixel/8] & 1<<(7-(pixel%8)));
85 break; 86 break;
86 case GSM_NokiaPictureImage: 87 case GSM_NokiaPictureImage:
87 i=(buffer[9*y + x/8] & 1<<(7-(x%8))); 88 i=(buffer[9*y + x/8] & 1<<(7-(x%8)));
88 break; 89 break;
89 case GSM_AlcatelBMMIPicture: 90 case GSM_AlcatelBMMIPicture:
90 break; 91 break;
91 } 92 }
92 if (i) return true; else return false; 93 if (i) return true; else return false;
93} 94}
94 95
95static void PHONE_SetPointBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, int x, int y, int width, int height) 96static void PHONE_SetPointBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, int x, int y, int width, int height)
96{ 97{
97 int pixel; 98 int pixel;
98 99
99 switch (Type) { 100 switch (Type) {
100 case GSM_NokiaStartupLogo: 101 case GSM_NokiaStartupLogo:
101 case GSM_Nokia6210StartupLogo: 102 case GSM_Nokia6210StartupLogo:
102 case GSM_Nokia7110StartupLogo: 103 case GSM_Nokia7110StartupLogo:
103 case GSM_Nokia6510OperatorLogo: 104 case GSM_Nokia6510OperatorLogo:
104 buffer[(y/8*width)+x] |= 1 << (y%8); 105 buffer[(y/8*width)+x] |= 1 << (y%8);
105 break; 106 break;
106 case GSM_NokiaOperatorLogo: 107 case GSM_NokiaOperatorLogo:
107 case GSM_Nokia7110OperatorLogo: 108 case GSM_Nokia7110OperatorLogo:
108 case GSM_NokiaCallerLogo: 109 case GSM_NokiaCallerLogo:
109 case GSM_EMSSmallPicture: 110 case GSM_EMSSmallPicture:
110 case GSM_EMSMediumPicture: 111 case GSM_EMSMediumPicture:
111 case GSM_EMSBigPicture: 112 case GSM_EMSBigPicture:
112 case GSM_EMSVariablePicture: 113 case GSM_EMSVariablePicture:
113 pixel = width*y + x; 114 pixel = width*y + x;
114 buffer[pixel/8] |= 1 << (7-(pixel%8)); 115 buffer[pixel/8] |= 1 << (7-(pixel%8));
115 break; 116 break;
116 case GSM_NokiaPictureImage: 117 case GSM_NokiaPictureImage:
117 buffer[9*y + x/8] |= 1 << (7-(x%8)); 118 buffer[9*y + x/8] |= 1 << (7-(x%8));
118 break; 119 break;
119 case GSM_AlcatelBMMIPicture: 120 case GSM_AlcatelBMMIPicture:
120 pixel = height / 8; 121 pixel = height / 8;
121 if ((height % 8) != 0) pixel++; 122 if ((height % 8) != 0) pixel++;
122 buffer[pixel*x + y/8] |= 1 << (7 - (y%8)); 123 buffer[pixel*x + y/8] |= 1 << (7 - (y%8));
123 break; 124 break;
124 } 125 }
125} 126}
126 127
127void PHONE_DecodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap) 128void PHONE_DecodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap)
128{ 129{
129 int width, height, x,y; 130 int width, height, x,y;
130 131
131 PHONE_GetBitmapWidthHeight(Type, &width, &height); 132 PHONE_GetBitmapWidthHeight(Type, &width, &height);
132 if (Type != GSM_Nokia6510OperatorLogo && Type != GSM_Nokia7110OperatorLogo && Type != GSM_EMSVariablePicture) { 133 if (Type != GSM_Nokia6510OperatorLogo && Type != GSM_Nokia7110OperatorLogo && Type != GSM_EMSVariablePicture) {
133 Bitmap->BitmapHeight= height; 134 Bitmap->BitmapHeight= height;
134 Bitmap->BitmapWidth= width; 135 Bitmap->BitmapWidth= width;
135 } 136 }
136 switch (Type) { 137 switch (Type) {
137 case GSM_NokiaOperatorLogo: 138 case GSM_NokiaOperatorLogo:
138 case GSM_Nokia7110OperatorLogo: 139 case GSM_Nokia7110OperatorLogo:
139 case GSM_Nokia6510OperatorLogo : Bitmap->Type=GSM_OperatorLogo;break; 140 case GSM_Nokia6510OperatorLogo : Bitmap->Type=GSM_OperatorLogo;break;
140 case GSM_NokiaCallerLogo : Bitmap->Type=GSM_CallerGroupLogo;break; 141 case GSM_NokiaCallerLogo : Bitmap->Type=GSM_CallerGroupLogo;break;
141 case GSM_AlcatelBMMIPicture : 142 case GSM_AlcatelBMMIPicture :
142 case GSM_NokiaStartupLogo: 143 case GSM_NokiaStartupLogo:
143 case GSM_Nokia7110StartupLogo: 144 case GSM_Nokia7110StartupLogo:
144 case GSM_Nokia6210StartupLogo : Bitmap->Type=GSM_StartupLogo; break; 145 case GSM_Nokia6210StartupLogo : Bitmap->Type=GSM_StartupLogo; break;
145 case GSM_NokiaPictureImage: 146 case GSM_NokiaPictureImage:
146 case GSM_EMSVariablePicture: 147 case GSM_EMSVariablePicture:
147 case GSM_EMSSmallPicture: 148 case GSM_EMSSmallPicture:
148 case GSM_EMSMediumPicture: 149 case GSM_EMSMediumPicture:
149 case GSM_EMSBigPicture : Bitmap->Type=GSM_PictureImage;break; 150 case GSM_EMSBigPicture : Bitmap->Type=GSM_PictureImage;break;
150 } 151 }
151 152
152 Bitmap->Location = 0; 153 Bitmap->Location = 0;
153 Bitmap->Text[0] = 0; 154 Bitmap->Text[0] = 0;
154 Bitmap->Text[1] = 0; 155 Bitmap->Text[1] = 0;
155 Bitmap->BitmapEnabled = false; 156 Bitmap->BitmapEnabled = false;
156 Bitmap->DefaultName = false; 157 Bitmap->DefaultName = false;
157 Bitmap->DefaultBitmap = false; 158 Bitmap->DefaultBitmap = false;
158 Bitmap->DefaultRingtone = false; 159 Bitmap->DefaultRingtone = false;
159 Bitmap->RingtoneID = 0; 160 Bitmap->RingtoneID = 0;
160 Bitmap->NetworkCode[0] = 0; 161 Bitmap->NetworkCode[0] = 0;
161 Bitmap->Sender[0] = 0; 162 Bitmap->Sender[0] = 0;
162 Bitmap->Sender[1] = 0; 163 Bitmap->Sender[1] = 0;
163 Bitmap->ID = 0; 164 Bitmap->ID = 0;
165 Bitmap->Name = NULL;
164 166
165 GSM_ClearBitmap(Bitmap); 167 GSM_ClearBitmap(Bitmap);
166 for (x=0;x<Bitmap->BitmapWidth;x++) { 168 for (x=0;x<Bitmap->BitmapWidth;x++) {
167 for (y=0;y<Bitmap->BitmapHeight;y++) { 169 for (y=0;y<Bitmap->BitmapHeight;y++) {
168 if (PHONE_IsPointBitmap(Type, buffer, x, y, Bitmap->BitmapWidth, Bitmap->BitmapHeight)) { 170 if (PHONE_IsPointBitmap(Type, buffer, x, y, Bitmap->BitmapWidth, Bitmap->BitmapHeight)) {
169 GSM_SetPointBitmap(Bitmap,x,y); 171 GSM_SetPointBitmap(Bitmap,x,y);
170 } 172 }
171 } 173 }
172 } 174 }
173} 175}
174 176
175void PHONE_ClearBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, int width, int height) 177void PHONE_ClearBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, int width, int height)
176{ 178{
177 memset(buffer,0,PHONE_GetBitmapSize(Type,width,height)); 179 memset(buffer,0,PHONE_GetBitmapSize(Type,width,height));
178} 180}
179 181
180void PHONE_EncodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap) 182void PHONE_EncodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap)
181{ 183{
182 int width, height, x, y; 184 int width, height, x, y;
183 GSM_Bitmapdest; 185 GSM_Bitmapdest;
184 186
185 PHONE_GetBitmapWidthHeight(Type, &width, &height); 187 PHONE_GetBitmapWidthHeight(Type, &width, &height);
186 if (width == 0 && height == 0) { 188 if (width == 0 && height == 0) {
187 width = Bitmap->BitmapWidth; 189 width = Bitmap->BitmapWidth;
188 height = Bitmap->BitmapHeight; 190 height = Bitmap->BitmapHeight;
189 } 191 }
190 GSM_ResizeBitmap(&dest, Bitmap, width, height); 192 GSM_ResizeBitmap(&dest, Bitmap, width, height);
191 PHONE_ClearBitmap(Type, buffer, width, height); 193 PHONE_ClearBitmap(Type, buffer, width, height);
192 194
193 for (x=0;x<width;x++) { 195 for (x=0;x<width;x++) {
194 for (y=0;y<height;y++) { 196 for (y=0;y<height;y++) {
195 if (GSM_IsPointBitmap(&dest,x,y)) PHONE_SetPointBitmap(Type, buffer, x, y, width, height); 197 if (GSM_IsPointBitmap(&dest,x,y)) PHONE_SetPointBitmap(Type, buffer, x, y, width, height);
196 } 198 }
197 } 199 }
198} 200}
199 201
200void GSM_GetMaxBitmapWidthHeight(GSM_Bitmap_Types Type, unsigned char *width, unsigned char *height) 202void GSM_GetMaxBitmapWidthHeight(GSM_Bitmap_Types Type, unsigned char *width, unsigned char *height)
201{ 203{
202 switch (Type) { 204 switch (Type) {
203 case GSM_CallerGroupLogo: *width=72; *height=14; break; 205 case GSM_CallerGroupLogo: *width=72; *height=14; break;
204 case GSM_OperatorLogo: *width=101;*height=21; break; 206 case GSM_OperatorLogo: *width=101;*height=21; break;
205 case GSM_StartupLogo: *width=96; *height=65; break; 207 case GSM_StartupLogo: *width=96; *height=65; break;
206 case GSM_PictureImage: *width=72; *height=28; break; 208 case GSM_PictureImage: *width=72; *height=28; break;
207 default : break; 209 default : break;
208 } 210 }
209} 211}
210 212
211void GSM_SetPointBitmap(GSM_Bitmap *bmp, int x, int y) 213void GSM_SetPointBitmap(GSM_Bitmap *bmp, int x, int y)
212{ 214{
213 SetBit(bmp->BitmapPoints,y*bmp->BitmapWidth+x); 215 SetBit(bmp->BitmapPoints,y*bmp->BitmapWidth+x);
214} 216}
215 217
216void GSM_ClearPointBitmap(GSM_Bitmap *bmp, int x, int y) 218void GSM_ClearPointBitmap(GSM_Bitmap *bmp, int x, int y)
217{ 219{
218 ClearBit(bmp->BitmapPoints,y*bmp->BitmapWidth+x); 220 ClearBit(bmp->BitmapPoints,y*bmp->BitmapWidth+x);
219} 221}
220 222
221bool GSM_IsPointBitmap(GSM_Bitmap *bmp, int x, int y) 223bool GSM_IsPointBitmap(GSM_Bitmap *bmp, int x, int y)
222{ 224{
223 if (GetBit(bmp->BitmapPoints,y*bmp->BitmapWidth+x)) return true; else return false; 225 if (GetBit(bmp->BitmapPoints,y*bmp->BitmapWidth+x)) return true; else return false;
224} 226}
225 227
226void GSM_ClearBitmap(GSM_Bitmap *bmp) 228void GSM_ClearBitmap(GSM_Bitmap *bmp)
227{ 229{
228 memset(bmp->BitmapPoints,0,GSM_GetBitmapSize(bmp)); 230 memset(bmp->BitmapPoints,0,GSM_GetBitmapSize(bmp));
229} 231}
230 232
231int GSM_GetBitmapSize(GSM_Bitmap *bmp) 233int GSM_GetBitmapSize(GSM_Bitmap *bmp)
232{ 234{
233 return bmp->BitmapWidth*bmp->BitmapHeight/8+1; 235 return bmp->BitmapWidth*bmp->BitmapHeight/8+1;
234} 236}
235 237
236void GSM_PrintBitmap(FILE *file, GSM_Bitmap *bitmap) 238void GSM_PrintBitmap(FILE *file, GSM_Bitmap *bitmap)
237{ 239{
238 int x,y; 240 int x,y;
239 241
240 for (y=0;y<bitmap->BitmapHeight;y++) { 242 for (y=0;y<bitmap->BitmapHeight;y++) {
241 for (x=0;x<bitmap->BitmapWidth;x++) { 243 for (x=0;x<bitmap->BitmapWidth;x++) {
242 if (GSM_IsPointBitmap(bitmap,x,y)) { 244 if (GSM_IsPointBitmap(bitmap,x,y)) {
243 fprintf(file,"#"); 245 fprintf(file,"#");
244 } else { 246 } else {
245 fprintf(file," "); 247 fprintf(file," ");
246 } 248 }
247 } 249 }
248 fprintf(file,"\n"); 250 fprintf(file,"\n");
249 } 251 }
250} 252}
251 253
252void GSM_ReverseBitmap(GSM_Bitmap *Bitmap) 254void GSM_ReverseBitmap(GSM_Bitmap *Bitmap)
253{ 255{
254 int x, y; 256 int x, y;
255 257
256 for (x=0;x<Bitmap->BitmapWidth;x++) { 258 for (x=0;x<Bitmap->BitmapWidth;x++) {
257 for (y=0;y<Bitmap->BitmapHeight;y++) { 259 for (y=0;y<Bitmap->BitmapHeight;y++) {
258 if (GSM_IsPointBitmap(Bitmap,x,y)) { 260 if (GSM_IsPointBitmap(Bitmap,x,y)) {
259 GSM_ClearPointBitmap(Bitmap, x, y); 261 GSM_ClearPointBitmap(Bitmap, x, y);
260 } else { 262 } else {
261 GSM_SetPointBitmap(Bitmap, x, y); 263 GSM_SetPointBitmap(Bitmap, x, y);
262 } 264 }
263 } 265 }
264 } 266 }
265} 267}
266 268
267void GSM_ResizeBitmap(GSM_Bitmap *dest, GSM_Bitmap *src, int width, int height) 269void GSM_ResizeBitmap(GSM_Bitmap *dest, GSM_Bitmap *src, int width, int height)
268{ 270{
269 int startx=0,endx=0,setx=0, starty=0,endy=0,sety=0, x, y; 271 int startx=0,endx=0,setx=0, starty=0,endy=0,sety=0, x, y;
270 272
271 if (src->BitmapWidth<=width) { 273 if (src->BitmapWidth<=width) {
272 startx= 0; 274 startx= 0;
273 endx= src->BitmapWidth; 275 endx= src->BitmapWidth;
274 setx= (width-src->BitmapWidth)/2; 276 setx= (width-src->BitmapWidth)/2;
275 } else { 277 } else {
276 startx= (src->BitmapWidth-width)/2; 278 startx= (src->BitmapWidth-width)/2;
277 endx= startx + width; 279 endx= startx + width;
278 setx= 0; 280 setx= 0;
279 } 281 }
280 if (src->BitmapHeight<=height) { 282 if (src->BitmapHeight<=height) {
281 starty= 0; 283 starty= 0;
282 endy= src->BitmapHeight; 284 endy= src->BitmapHeight;
283 sety= (height-src->BitmapHeight)/2; 285 sety= (height-src->BitmapHeight)/2;
284 } else { 286 } else {
285 starty= (src->BitmapHeight-height)/2; 287 starty= (src->BitmapHeight-height)/2;
286 endy= starty + height; 288 endy= starty + height;
287 sety= 0; 289 sety= 0;
288 } 290 }
289 dest->BitmapHeight= height; 291 dest->BitmapHeight= height;
290 dest->BitmapWidth= width; 292 dest->BitmapWidth= width;
291 GSM_ClearBitmap(dest); 293 GSM_ClearBitmap(dest);
292 for (x=startx;x<endx;x++) { 294 for (x=startx;x<endx;x++) {
293 for (y=starty;y<endy;y++) { 295 for (y=starty;y<endy;y++) {
294 if (GSM_IsPointBitmap(src,x,y)) 296 if (GSM_IsPointBitmap(src,x,y))
295 GSM_SetPointBitmap(dest,setx+x-startx,sety+y-starty); 297 GSM_SetPointBitmap(dest,setx+x-startx,sety+y-starty);
296 } 298 }
297 } 299 }
298} 300}
299 301
300GSM_Error Bitmap2BMP(unsigned char *buffer, FILE *file,GSM_Bitmap *bitmap) 302GSM_Error Bitmap2BMP(unsigned char *buffer, FILE *file,GSM_Bitmap *bitmap)
301{ 303{
302 int x,y,pos,i,sizeimage,buffpos=0; 304 int x,y,pos,i,sizeimage,buffpos=0;
303 unsigned charbuff[1]; 305 unsigned charbuff[1];
304 div_t division; 306 div_t division;
305 bool isfile=false; 307 bool isfile=false;
306 308
307 unsigned char header[]={ 309 unsigned char header[]={
308/*1'st header*/ 'B','M', /* BMP file ID */ 310/*1'st header*/ 'B','M', /* BMP file ID */
309 0x00,0x00,0x00,0x00, /* Size of file */ 311 0x00,0x00,0x00,0x00, /* Size of file */
310 0x00,0x00, /* Reserved for future use */ 312 0x00,0x00, /* Reserved for future use */
311 0x00,0x00, /* Reserved for future use */ 313 0x00,0x00, /* Reserved for future use */
312 62,0x00,0x00,0x00, /* Offset for image data */ 314 62,0x00,0x00,0x00, /* Offset for image data */
313 315
314/*2'nd header*/ 40,0x00,0x00,0x00, /* Length of this part of header */ 316/*2'nd header*/ 40,0x00,0x00,0x00, /* Length of this part of header */
315 0x00,0x00,0x00,0x00, /* Width of image */ 317 0x00,0x00,0x00,0x00, /* Width of image */
316 0x00,0x00,0x00,0x00, /* Height of image */ 318 0x00,0x00,0x00,0x00, /* Height of image */
317 1,0x00, /* How many planes in target device */ 319 1,0x00, /* How many planes in target device */
318 1,0x00, /* How many colors in image. 1 means 2^1=2 colors */ 320 1,0x00, /* How many colors in image. 1 means 2^1=2 colors */
319 0x00,0x00,0x00,0x00, /* Type of compression. 0 means no compression */ 321 0x00,0x00,0x00,0x00, /* Type of compression. 0 means no compression */
320/*Sometimes */ 0x00,0x00,0x00,0x00, /* Size of part with image data */ 322/*Sometimes */ 0x00,0x00,0x00,0x00, /* Size of part with image data */
321/*ttttttt...*/ 0xE8,0x03,0x00,0x00, /* XPelsPerMeter */ 323/*ttttttt...*/ 0xE8,0x03,0x00,0x00, /* XPelsPerMeter */
322 /*hhiiiiissss*/ 0xE8,0x03,0x00,0x00, /* YPelsPerMeter */ 324 /*hhiiiiissss*/ 0xE8,0x03,0x00,0x00, /* YPelsPerMeter */
323/*part of header*/0x02,0x00,0x00,0x00, /* How many colors from palette is used */ 325/*part of header*/0x02,0x00,0x00,0x00, /* How many colors from palette is used */
324/*doesn't exist*/ 0x00,0x00,0x00,0x00, /* How many colors from palette is required to display image. 0 means all */ 326/*doesn't exist*/ 0x00,0x00,0x00,0x00, /* How many colors from palette is required to display image. 0 means all */
325 327
326/*Color palette*/ 0x00,0x00,0x00, /* First color in palette in Blue, Green, Red. Here white */ 328/*Color palette*/ 0x00,0x00,0x00, /* First color in palette in Blue, Green, Red. Here white */
327 0x00, /* Each color in palette is end by 4'th byte */ 329 0x00, /* Each color in palette is end by 4'th byte */
328 102, 204, 102, /* Second color in palette in Blue, Green, Red. Here green */ 330 102, 204, 102, /* Second color in palette in Blue, Green, Red. Here green */
329 0x00}; /* Each color in palette is end by 4'th byte */ 331 0x00}; /* Each color in palette is end by 4'th byte */
330 332
331 if (file!=NULL) isfile=true; 333 if (file!=NULL) isfile=true;
332 334
333 header[22]=bitmap->BitmapHeight; 335 header[22]=bitmap->BitmapHeight;
334 header[18]=bitmap->BitmapWidth; 336 header[18]=bitmap->BitmapWidth;
335 337
336 pos = 7; 338 pos = 7;
337 sizeimage = 0; 339 sizeimage = 0;
338 /*lines are written from the last to the first*/ 340 /*lines are written from the last to the first*/
339 for (y=bitmap->BitmapHeight-1;y>=0;y--) { 341 for (y=bitmap->BitmapHeight-1;y>=0;y--) {
340 i=1; 342 i=1;
341 for (x=0;x<bitmap->BitmapWidth;x++) { 343 for (x=0;x<bitmap->BitmapWidth;x++) {
342 /*new byte !*/ 344 /*new byte !*/
343 if (pos==7) { 345 if (pos==7) {
344 if (x!=0) sizeimage++; 346 if (x!=0) sizeimage++;
345 i++; 347 i++;
346 /*each line is written in multiply of 4 bytes*/ 348 /*each line is written in multiply of 4 bytes*/
347 if(i==5) i=1; 349 if(i==5) i=1;
348 } 350 }
349 pos--; 351 pos--;
350 /*going to new byte*/ 352 /*going to new byte*/
351 if (pos<0) pos=7; 353 if (pos<0) pos=7;
352 } 354 }
353 /*going to new byte*/ 355 /*going to new byte*/
354 pos=7; 356 pos=7;
355 sizeimage++; 357 sizeimage++;
@@ -437,567 +439,600 @@ static GSM_Error savebmp(FILE *file, GSM_MultiBitmap *bitmap)
437} 439}
438 440
439static void PrivSaveNLMWBMP(FILE *file, GSM_Bitmap *Bitmap) 441static void PrivSaveNLMWBMP(FILE *file, GSM_Bitmap *Bitmap)
440{ 442{
441 unsigned charbuffer[1000]; 443 unsigned charbuffer[1000];
442 int x,y,pos,pos2; 444 int x,y,pos,pos2;
443 div_t division; 445 div_t division;
444 446
445 pos=0;pos2=7; 447 pos=0;pos2=7;
446 for (y=0;y<Bitmap->BitmapHeight;y++) { 448 for (y=0;y<Bitmap->BitmapHeight;y++) {
447 for (x=0;x<Bitmap->BitmapWidth;x++) { 449 for (x=0;x<Bitmap->BitmapWidth;x++) {
448 if (pos2==7) buffer[pos]=0; 450 if (pos2==7) buffer[pos]=0;
449 if (GSM_IsPointBitmap(Bitmap,x,y)) buffer[pos]|=(1<<pos2); 451 if (GSM_IsPointBitmap(Bitmap,x,y)) buffer[pos]|=(1<<pos2);
450 pos2--; 452 pos2--;
451 /* going to new line */ 453 /* going to new line */
452 if (pos2<0) {pos2=7;pos++;} 454 if (pos2<0) {pos2=7;pos++;}
453 } 455 }
454 /* for startup logos - new line with new byte */ 456 /* for startup logos - new line with new byte */
455 if (pos2!=7) {pos2=7;pos++;} 457 if (pos2!=7) {pos2=7;pos++;}
456 } 458 }
457 459
458 division=div(Bitmap->BitmapWidth,8); 460 division=div(Bitmap->BitmapWidth,8);
459 /* For startup logos */ 461 /* For startup logos */
460 if (division.rem!=0) division.quot++; 462 if (division.rem!=0) division.quot++;
461 463
462 fwrite(buffer,1,(division.quot*Bitmap->BitmapHeight),file); 464 fwrite(buffer,1,(division.quot*Bitmap->BitmapHeight),file);
463} 465}
464 466
465static GSM_Error savenlm(FILE *file, GSM_MultiBitmap *bitmap) 467static GSM_Error savenlm(FILE *file, GSM_MultiBitmap *bitmap)
466{ 468{
467 int i; 469 int i;
468 char header[]={ 470 char header[]={
469 'N','L','M',' ', /* Nokia Logo Manager file ID. */ 471 'N','L','M',' ', /* Nokia Logo Manager file ID. */
470 0x01, 472 0x01,
471 0x00, /* 0x00 (OP), 0x01 (CLI), 0x02 (Startup), 0x03 (Picture)*/ 473 0x00, /* 0x00 (OP), 0x01 (CLI), 0x02 (Startup), 0x03 (Picture)*/
472 0x00, /* Number of images inside file - 1. 0x01==2 images, 0x03==4 images, etc. */ 474 0x00, /* Number of images inside file - 1. 0x01==2 images, 0x03==4 images, etc. */
473 0x00, /* Width. */ 475 0x00, /* Width. */
474 0x00, /* Height. */ 476 0x00, /* Height. */
475 0x01}; 477 0x01};
476 478
477 switch (bitmap->Bitmap[0].Type) { 479 switch (bitmap->Bitmap[0].Type) {
478 case GSM_OperatorLogo : header[5]=0x00; break; 480 case GSM_OperatorLogo : header[5]=0x00; break;
479 case GSM_CallerGroupLogo : header[5]=0x01; break; 481 case GSM_CallerGroupLogo : header[5]=0x01; break;
480 case GSM_StartupLogo : header[5]=0x02; break; 482 case GSM_StartupLogo : header[5]=0x02; break;
481 case GSM_PictureImage : header[5]=0x03; break; 483 case GSM_PictureImage : header[5]=0x03; break;
482 default : return ERR_UNKNOWN; 484 default : return ERR_UNKNOWN;
483 } 485 }
484 header[6] = bitmap->Number - 1; 486 header[6] = bitmap->Number - 1;
485 header[7] = bitmap->Bitmap[0].BitmapWidth; 487 header[7] = bitmap->Bitmap[0].BitmapWidth;
486 header[8] = bitmap->Bitmap[0].BitmapHeight; 488 header[8] = bitmap->Bitmap[0].BitmapHeight;
487 fwrite(header,1,sizeof(header),file); 489 fwrite(header,1,sizeof(header),file);
488 490
489 for (i=0;i<bitmap->Number;i++) { 491 for (i=0;i<bitmap->Number;i++) {
490 PrivSaveNLMWBMP(file, &bitmap->Bitmap[i]); 492 PrivSaveNLMWBMP(file, &bitmap->Bitmap[i]);
491 } 493 }
492 494
493 return ERR_NONE; 495 return ERR_NONE;
494} 496}
495 497
496static void PrivSaveNGGNOL(FILE *file, GSM_MultiBitmap *bitmap) 498static void PrivSaveNGGNOL(FILE *file, GSM_MultiBitmap *bitmap)
497{ 499{
498 char buffer[GSM_BITMAP_SIZE]; 500 char buffer[GSM_BITMAP_SIZE];
499 intx,y,current=0; 501 intx,y,current=0;
500 502
501 for (y=0;y<bitmap->Bitmap[0].BitmapHeight;y++) { 503 for (y=0;y<bitmap->Bitmap[0].BitmapHeight;y++) {
502 for (x=0;x<bitmap->Bitmap[0].BitmapWidth;x++) { 504 for (x=0;x<bitmap->Bitmap[0].BitmapWidth;x++) {
503 if (GSM_IsPointBitmap(&bitmap->Bitmap[0],x,y)) { 505 if (GSM_IsPointBitmap(&bitmap->Bitmap[0],x,y)) {
504 buffer[current++] = '1'; 506 buffer[current++] = '1';
505 } else { 507 } else {
506 buffer[current++] = '0'; 508 buffer[current++] = '0';
507 } 509 }
508 } 510 }
509 } 511 }
510 fwrite(buffer,1,current,file); 512 fwrite(buffer,1,current,file);
511} 513}
512 514
513static GSM_Error savengg(FILE *file, GSM_MultiBitmap *bitmap) 515static GSM_Error savengg(FILE *file, GSM_MultiBitmap *bitmap)
514{ 516{
515 char header[]={ 517 char header[]={
516 'N','G','G',0x00,0x01,0x00, 518 'N','G','G',0x00,0x01,0x00,
517 0x00,0x00,/* Width */ 519 0x00,0x00,/* Width */
518 0x00,0x00,/* Height */ 520 0x00,0x00,/* Height */
519 0x01,0x00,0x01,0x00, 521 0x01,0x00,0x01,0x00,
520 0x00, /* Unknown.Can't be checksum - for */ 522 0x00, /* Unknown.Can't be checksum - for */
521 /* the same logo files can be different */ 523 /* the same logo files can be different */
522 0x00}; 524 0x00};
523 525
524 header[6] = bitmap->Bitmap[0].BitmapWidth; 526 header[6] = bitmap->Bitmap[0].BitmapWidth;
525 header[8] = bitmap->Bitmap[0].BitmapHeight; 527 header[8] = bitmap->Bitmap[0].BitmapHeight;
526 fwrite(header,1,sizeof(header),file); 528 fwrite(header,1,sizeof(header),file);
527 529
528 PrivSaveNGGNOL(file,bitmap); 530 PrivSaveNGGNOL(file,bitmap);
529 531
530 return ERR_NONE; 532 return ERR_NONE;
531} 533}
532 534
533static GSM_Error savenol(FILE *file, GSM_MultiBitmap *bitmap) 535static GSM_Error savenol(FILE *file, GSM_MultiBitmap *bitmap)
534{ 536{
535 int country,net; 537 int country,net;
536 char header[]={ 538 char header[]={
537 'N','O','L',0x00,0x01,0x00, 539 'N','O','L',0x00,0x01,0x00,
538 0x00,0x00, /* MCC */ 540 0x00,0x00, /* MCC */
539 0x00,0x00, /* MNC */ 541 0x00,0x00, /* MNC */
540 0x00,0x00, /* Width */ 542 0x00,0x00, /* Width */
541 0x00,0x00, /* Height */ 543 0x00,0x00, /* Height */
542 0x01,0x00,0x01,0x00, 544 0x01,0x00,0x01,0x00,
543 0x00, /* Unknown.Can't be checksum - for */ 545 0x00, /* Unknown.Can't be checksum - for */
544 /* the same logo files can be different */ 546 /* the same logo files can be different */
545 0x00}; 547 0x00};
546 548
547 if (bitmap->Bitmap[0].Type == GSM_OperatorLogo) sscanf(bitmap->Bitmap[0].NetworkCode, "%d %d", &country, &net); 549 if (bitmap->Bitmap[0].Type == GSM_OperatorLogo) sscanf(bitmap->Bitmap[0].NetworkCode, "%d %d", &country, &net);
548 550
549 header[6]= country%256; 551 header[6]= country%256;
550 header[7]= country/256; 552 header[7]= country/256;
551 header[8]= net%256; 553 header[8]= net%256;
552 header[9]= net/256; 554 header[9]= net/256;
553 header[10]= bitmap->Bitmap[0].BitmapWidth; 555 header[10]= bitmap->Bitmap[0].BitmapWidth;
554 header[12]= bitmap->Bitmap[0].BitmapHeight; 556 header[12]= bitmap->Bitmap[0].BitmapHeight;
555 fwrite(header,1,sizeof(header),file); 557 fwrite(header,1,sizeof(header),file);
556 558
557 PrivSaveNGGNOL(file,bitmap); 559 PrivSaveNGGNOL(file,bitmap);
558 560
559 return ERR_NONE; 561 return ERR_NONE;
560} 562}
561 563
562static GSM_Error savexpm(FILE *file, GSM_MultiBitmap *bitmap) 564static GSM_Error savexpm(FILE *file, GSM_MultiBitmap *bitmap)
563{ 565{
564 int x,y; 566 int x,y;
565 567
566 fprintf(file,"/* XPM */\n"); 568 fprintf(file,"/* XPM */\n");
567 fprintf(file,"static char * ala_xpm[] = {\n"); 569 fprintf(file,"static char * ala_xpm[] = {\n");
568 fprintf(file,"\"%i %i 2 1\",\n",bitmap->Bitmap[0].BitmapWidth,bitmap->Bitmap[0].BitmapHeight); 570 fprintf(file,"\"%i %i 2 1\",\n",bitmap->Bitmap[0].BitmapWidth,bitmap->Bitmap[0].BitmapHeight);
569 fprintf(file,"\". s c m #000000 g4 #000000 g #000000c #000000\",\n"); 571 fprintf(file,"\". s c m #000000 g4 #000000 g #000000c #000000\",\n");
570 fprintf(file,"\"# s c m #ffffff g4 #ffffff g #ffffffc #ffffff\",\n"); 572 fprintf(file,"\"# s c m #ffffff g4 #ffffff g #ffffffc #ffffff\",\n");
571 573
572 for (y=0;y<bitmap->Bitmap[0].BitmapHeight;y++) { 574 for (y=0;y<bitmap->Bitmap[0].BitmapHeight;y++) {
573 fprintf(file,"\""); 575 fprintf(file,"\"");
574 for (x=0;x<bitmap->Bitmap[0].BitmapWidth;x++) 576 for (x=0;x<bitmap->Bitmap[0].BitmapWidth;x++)
575 if (GSM_IsPointBitmap(&bitmap->Bitmap[0],x,y)) { 577 if (GSM_IsPointBitmap(&bitmap->Bitmap[0],x,y)) {
576 fprintf(file,"."); 578 fprintf(file,".");
577 } else { 579 } else {
578 fprintf(file,"#"); 580 fprintf(file,"#");
579 } 581 }
580 fprintf(file,"\""); 582 fprintf(file,"\"");
581 if (y==bitmap->Bitmap[0].BitmapHeight-1) { 583 if (y==bitmap->Bitmap[0].BitmapHeight-1) {
582 fprintf(file,"};\n"); 584 fprintf(file,"};\n");
583 } else { 585 } else {
584 fprintf(file,",\n"); 586 fprintf(file,",\n");
585 } 587 }
586 } 588 }
587 589
588 return ERR_NONE; 590 return ERR_NONE;
589} 591}
590 592
591static GSM_Error savensl(FILE *file, GSM_MultiBitmap *bitmap) 593static GSM_Error savensl(FILE *file, GSM_MultiBitmap *bitmap)
592{ 594{
593 char buffer[GSM_BITMAP_SIZE]; 595 char buffer[GSM_BITMAP_SIZE];
594 unsigned char header[]={ 596 unsigned char header[]={
595 'F','O','R','M', 0x01,0xFE,/* File ID block, size 1*256+0xFE=510*/ 597 'F','O','R','M', 0x01,0xFE,/* File ID block, size 1*256+0xFE=510*/
596 'N','S','L','D', 0x01,0xF8};/* Startup Logo block, size 1*256+0xF8=504*/ 598 'N','S','L','D', 0x01,0xF8};/* Startup Logo block, size 1*256+0xF8=504*/
597 599
598 fwrite(header,1,sizeof(header),file); 600 fwrite(header,1,sizeof(header),file);
599 PHONE_EncodeBitmap(GSM_NokiaStartupLogo, buffer, &bitmap->Bitmap[0]); 601 PHONE_EncodeBitmap(GSM_NokiaStartupLogo, buffer, &bitmap->Bitmap[0]);
600 fwrite(buffer,1,PHONE_GetBitmapSize(GSM_NokiaStartupLogo,0,0),file); 602 fwrite(buffer,1,PHONE_GetBitmapSize(GSM_NokiaStartupLogo,0,0),file);
601 603
602 return ERR_NONE; 604 return ERR_NONE;
603} 605}
604 606
605static GSM_Error savewbmp(FILE *file, GSM_MultiBitmap *bitmap) 607static GSM_Error savewbmp(FILE *file, GSM_MultiBitmap *bitmap)
606{ 608{
607 unsigned char buffer[4]; 609 unsigned char buffer[4];
608 610
609 buffer[0] = 0x00; 611 buffer[0] = 0x00;
610 buffer[1] = 0x00; 612 buffer[1] = 0x00;
611 buffer[2] = bitmap->Bitmap[0].BitmapWidth; 613 buffer[2] = bitmap->Bitmap[0].BitmapWidth;
612 buffer[3] = bitmap->Bitmap[0].BitmapHeight; 614 buffer[3] = bitmap->Bitmap[0].BitmapHeight;
613 fwrite(buffer,1,4,file); 615 fwrite(buffer,1,4,file);
614 616
615 PrivSaveNLMWBMP(file, &bitmap->Bitmap[0]); 617 PrivSaveNLMWBMP(file, &bitmap->Bitmap[0]);
616 618
617 return ERR_NONE; 619 return ERR_NONE;
618} 620}
619 621
620GSM_Error GSM_SaveBitmapFile(char *FileName, GSM_MultiBitmap *bitmap) 622GSM_Error GSM_SaveBitmapFile(char *FileName, GSM_MultiBitmap *bitmap)
621{ 623{
622 FILE *file; 624 FILE *file;
623 GSM_Error error=ERR_NONE; 625 GSM_Error error=ERR_NONE;
624 626
625 file = fopen(FileName, "wb"); 627 file = fopen(FileName, "wb");
626 if (file == NULL) return ERR_CANTOPENFILE; 628 if (file == NULL) return ERR_CANTOPENFILE;
627 629
628 /* Attempt to identify filetype */ 630 /* Attempt to identify filetype */
629 if (strstr(FileName,".nlm")) { 631 if (mystrcasestr(FileName,".nlm")) {
630 error=savenlm(file,bitmap); 632 error=savenlm(file,bitmap);
631 } else if (strstr(FileName,".ngg")) { 633 } else if (mystrcasestr(FileName,".ngg")) {
632 error=savengg(file,bitmap); 634 error=savengg(file,bitmap);
633 } else if (strstr(FileName,".nol")) { 635 } else if (mystrcasestr(FileName,".nol")) {
634 error=savenol(file,bitmap); 636 error=savenol(file,bitmap);
635 } else if (strstr(FileName,".xpm")) { 637 } else if (mystrcasestr(FileName,".xpm")) {
636 error=savexpm(file,bitmap); 638 error=savexpm(file,bitmap);
637 } else if (strstr(FileName,".nsl")) { 639 } else if (mystrcasestr(FileName,".nsl")) {
638 error=savensl(file,bitmap); 640 error=savensl(file,bitmap);
639 } else if (strstr(FileName,".wbmp")) { 641 } else if (mystrcasestr(FileName,".wbmp")) {
640 error=savewbmp(file,bitmap); 642 error=savewbmp(file,bitmap);
641 } else { 643 } else {
642 error=savebmp(file,bitmap); 644 error=savebmp(file,bitmap);
643 } 645 }
644 fclose(file); 646 fclose(file);
645 647
646 return error; 648 return error;
647} 649}
648 650
649GSM_Error BMP2Bitmap(unsigned char *buffer, FILE *file,GSM_Bitmap *bitmap) 651GSM_Error BMP2Bitmap(unsigned char *buffer, FILE *file,GSM_Bitmap *bitmap)
650{ 652{
651 bool first_white,isfile=false; 653 bool first_white,isfile=false;
652 unsigned char buff[34]; 654 unsigned char buff[34];
653 int w,h,pos,y,x,i,buffpos=0; 655 int w,h,pos,y,x,i,buffpos=0;
654#ifdef DEBUG 656#ifdef DEBUG
655 int sizeimage=0; 657 int sizeimage=0;
656#endif 658#endif
657 659
658 if (bitmap->Type == GSM_None) bitmap->Type = GSM_StartupLogo; 660 if (bitmap->Type == GSM_None) bitmap->Type = GSM_StartupLogo;
659 if (file!=NULL) isfile=true; 661 if (file!=NULL) isfile=true;
660 if (isfile) { 662 if (isfile) {
661 fread(buff, 1, 34, file); 663 fread(buff, 1, 34, file);
662 } else { 664 } else {
663 memcpy(buff,buffer,34); 665 memcpy(buff,buffer,34);
664 } 666 }
665 667
666 /* height and width of image in the file */ 668 /* height and width of image in the file */
667 h=buff[22]+256*buff[21]; 669 h=buff[22]+256*buff[21];
668 w=buff[18]+256*buff[17]; 670 w=buff[18]+256*buff[17];
669 dbgprintf("Image Size in BMP file: %dx%d\n",w,h); 671 dbgprintf("Image Size in BMP file: %dx%d\n",w,h);
670 672
671 GSM_GetMaxBitmapWidthHeight(bitmap->Type, &bitmap->BitmapWidth, &bitmap->BitmapHeight); 673 GSM_GetMaxBitmapWidthHeight(bitmap->Type, &bitmap->BitmapWidth, &bitmap->BitmapHeight);
672 if (h<bitmap->BitmapHeight)bitmap->BitmapHeight=h; 674 if (h<bitmap->BitmapHeight)bitmap->BitmapHeight=h;
673 if (w<bitmap->BitmapWidth)bitmap->BitmapWidth=w; 675 if (w<bitmap->BitmapWidth)bitmap->BitmapWidth=w;
674 dbgprintf("Height %i %i, width %i %i\n",h,bitmap->BitmapHeight,w,bitmap->BitmapWidth); 676 dbgprintf("Height %i %i, width %i %i\n",h,bitmap->BitmapHeight,w,bitmap->BitmapWidth);
675 677
676 GSM_ClearBitmap(bitmap); 678 GSM_ClearBitmap(bitmap);
677 679
678#ifdef DEBUG 680#ifdef DEBUG
679 dbgprintf("Number of colors in BMP file: "); 681 dbgprintf("Number of colors in BMP file: ");
680 switch (buff[28]) { 682 switch (buff[28]) {
681 case 1 : dbgprintf("2 (supported)\n"); break; 683 case 1 : dbgprintf("2 (supported)\n"); break;
682 case 4 : dbgprintf("16 (NOT SUPPORTED)\n"); break; 684 case 4 : dbgprintf("16 (NOT SUPPORTED)\n"); break;
683 case 8 : dbgprintf("256 (NOT SUPPORTED)\n"); break; 685 case 8 : dbgprintf("256 (NOT SUPPORTED)\n"); break;
684 case 24 : dbgprintf("True Color (NOT SUPPORTED)\n"); break; 686 case 24 : dbgprintf("True Color (NOT SUPPORTED)\n"); break;
685 default : dbgprintf("unknown\n"); break; 687 default : dbgprintf("unknown\n"); break;
686 } 688 }
687#endif 689#endif
688 if (buff[28]!=1) { 690 if (buff[28]!=1) {
689 dbgprintf("Wrong number of colors\n"); 691 dbgprintf("Wrong number of colors\n");
690 return ERR_FILENOTSUPPORTED; 692 return ERR_FILENOTSUPPORTED;
691 } 693 }
692 694
693#ifdef DEBUG 695#ifdef DEBUG
694 dbgprintf("Compression in BMP file: "); 696 dbgprintf("Compression in BMP file: ");
695 switch (buff[30]) { 697 switch (buff[30]) {
696 case 0 :dbgprintf("no compression (supported)\n"); break; 698 case 0 :dbgprintf("no compression (supported)\n"); break;
697 case 1 :dbgprintf("RLE8 (NOT SUPPORTED)\n"); break; 699 case 1 :dbgprintf("RLE8 (NOT SUPPORTED)\n"); break;
698 case 2 :dbgprintf("RLE4 (NOT SUPPORTED)\n"); break; 700 case 2 :dbgprintf("RLE4 (NOT SUPPORTED)\n"); break;
699 default :dbgprintf("unknown\n"); break; 701 default :dbgprintf("unknown\n"); break;
700 } 702 }
701#endif 703#endif
702 if (buff[30]!=0) { 704 if (buff[30]!=0) {
703 dbgprintf("Compression type not supported\n"); 705 dbgprintf("Compression type not supported\n");
704 return ERR_FILENOTSUPPORTED; 706 return ERR_FILENOTSUPPORTED;
705 } 707 }
706 708
707 /* read rest of header (if exists) and color palette */ 709 /* read rest of header (if exists) and color palette */
708 if (isfile) { 710 if (isfile) {
709 pos=buff[10]-34; 711 pos=buff[10]-34;
710 fread(buff, 1, pos, file); 712 fread(buff, 1, pos, file);
711 } else { 713 } else {
712 pos=buff[10]-34; 714 pos=buff[10]-34;
713 buffpos=buff[10]; 715 buffpos=buff[10];
714 memcpy (buff,buffer+34,pos); 716 memcpy (buff,buffer+34,pos);
715 } 717 }
716 718
717#ifdef DEBUG 719#ifdef DEBUG
718 dbgprintf("First color in BMP file: %i %i %i ",buff[pos-8], buff[pos-7], buff[pos-6]); 720 dbgprintf("First color in BMP file: %i %i %i ",buff[pos-8], buff[pos-7], buff[pos-6]);
719 if (buff[pos-8]==0 && buff[pos-7]==0 && buff[pos-6]==0) dbgprintf("(white)"); 721 if (buff[pos-8]==0 && buff[pos-7]==0 && buff[pos-6]==0) dbgprintf("(white)");
720 if (buff[pos-8]==0xFF && buff[pos-7]==0xFF && buff[pos-6]==0xFF) dbgprintf("(black)"); 722 if (buff[pos-8]==0xFF && buff[pos-7]==0xFF && buff[pos-6]==0xFF) dbgprintf("(black)");
721 if (buff[pos-8]==102 && buff[pos-7]==204 && buff[pos-6]==102) dbgprintf("(green)"); 723 if (buff[pos-8]==102 && buff[pos-7]==204 && buff[pos-6]==102) dbgprintf("(green)");
722 dbgprintf("\n"); 724 dbgprintf("\n");
723 dbgprintf("Second color in BMP file: %i %i %i ",buff[pos-38], buff[pos-37], buff[pos-36]); 725 dbgprintf("Second color in BMP file: %i %i %i ",buff[pos-38], buff[pos-37], buff[pos-36]);
724 if (buff[pos-4]==0 && buff[pos-3]==0 && buff[pos-2]==0) dbgprintf("(white)"); 726 if (buff[pos-4]==0 && buff[pos-3]==0 && buff[pos-2]==0) dbgprintf("(white)");
725 if (buff[pos-4]==0xFF && buff[pos-3]==0xFF && buff[pos-2]==0xFF) dbgprintf("(black)"); 727 if (buff[pos-4]==0xFF && buff[pos-3]==0xFF && buff[pos-2]==0xFF) dbgprintf("(black)");
726 dbgprintf("\n"); 728 dbgprintf("\n");
727#endif 729#endif
728 first_white=true; 730 first_white=true;
729 if (buff[pos-8]!=0 || buff[pos-7]!=0 || buff[pos-6]!=0) first_white=false; 731 if (buff[pos-8]!=0 || buff[pos-7]!=0 || buff[pos-6]!=0) first_white=false;
730 732
731 pos=7; 733 pos=7;
732 /* lines are written from the last to the first */ 734 /* lines are written from the last to the first */
733 for (y=h-1;y>=0;y--) { i=1; 735 for (y=h-1;y>=0;y--) { i=1;
734 for (x=0;x<w;x++) { /* new byte ! */ 736 for (x=0;x<w;x++) { /* new byte ! */
735 if (pos==7) { if (isfile) { 737 if (pos==7) { if (isfile) {
736 fread(buff, 1, 1, file); 738 fread(buff, 1, 1, file);
737 } else { 739 } else {
738 memcpy (buff,buffer+buffpos,1); 740 memcpy (buff,buffer+buffpos,1);
739 buffpos++; 741 buffpos++;
740 } 742 }
741#ifdef DEBUG 743#ifdef DEBUG
742 sizeimage++; 744 sizeimage++;
743#endif 745#endif
744 i++; 746 i++;
745 /* each line is written in multiply of 4 bytes */ 747 /* each line is written in multiply of 4 bytes */
746 if(i==5) i=1; 748 if(i==5) i=1;
747 } 749 }
748 /* we have top left corner ! */ 750 /* we have top left corner ! */
749 if (x<=bitmap->BitmapWidth && y<=bitmap->BitmapHeight) { if (first_white) { 751 if (x<=bitmap->BitmapWidth && y<=bitmap->BitmapHeight) { if (first_white) {
750 if ((buff[0]&(1<<pos))<=0) GSM_SetPointBitmap(bitmap,x,y); 752 if ((buff[0]&(1<<pos))<=0) GSM_SetPointBitmap(bitmap,x,y);
751 } else { 753 } else {
752 if ((buff[0]&(1<<pos))>0) GSM_SetPointBitmap(bitmap,x,y); 754 if ((buff[0]&(1<<pos))>0) GSM_SetPointBitmap(bitmap,x,y);
753 } 755 }
754 } 756 }
755 pos--; 757 pos--;
756 /* going to new byte */ 758 /* going to new byte */
757 if (pos<0) pos=7; 759 if (pos<0) pos=7;
758 } 760 }
759 /* going to new byte */ 761 /* going to new byte */
760 pos=7; 762 pos=7;
761 if (i!=1) { 763 if (i!=1) {
762 /* each line is written in multiply of 4 bytes */ 764 /* each line is written in multiply of 4 bytes */
763 while (i!=5) { 765 while (i!=5) {
764 if (isfile) { 766 if (isfile) {
765 fread(buff, 1, 1, file); 767 fread(buff, 1, 1, file);
766 } else { 768 } else {
767 memcpy (buff,buffer+buffpos,1); 769 memcpy (buff,buffer+buffpos,1);
768 buffpos++; 770 buffpos++;
769 } 771 }
770#ifdef DEBUG 772#ifdef DEBUG
771 sizeimage++; 773 sizeimage++;
772#endif 774#endif
773 i++; 775 i++;
774 } 776 }
775 } 777 }
776 } 778 }
777#ifdef DEBUG 779#ifdef DEBUG
778 dbgprintf("Data size in BMP file: %i\n",sizeimage); 780 dbgprintf("Data size in BMP file: %i\n",sizeimage);
779#endif 781#endif
780 return(ERR_NONE); 782 return(ERR_NONE);
781} 783}
782 784
783static GSM_Error loadbmp(FILE *file, GSM_MultiBitmap *bitmap) 785static GSM_Error loadbmp(FILE *file, GSM_MultiBitmap *bitmap)
784{ 786{
785 GSM_Error error; 787 GSM_Error error;
786 788
787 error=BMP2Bitmap(NULL,file,&bitmap->Bitmap[0]); 789 error=BMP2Bitmap(NULL,file,&bitmap->Bitmap[0]);
788 bitmap->Number = 1; 790 bitmap->Number = 1;
789 return error; 791 return error;
790} 792}
791 793
792static GSM_Error loadnlm (FILE *file, GSM_MultiBitmap *bitmap) 794static GSM_Error loadnlm (FILE *file, GSM_MultiBitmap *bitmap)
793{ 795{
794 unsigned char buffer[1000]; 796 unsigned char buffer[1000];
795 int pos,pos2,x,y,h,w,i,number; 797 int pos,pos2,x,y,h,w,i,number;
796 div_t division; 798 div_t division;
797 799
798 fread(buffer,1,5,file); 800 fread(buffer,1,5,file);
799 801
800 fread(buffer,1,1,file); 802 fread(buffer,1,1,file);
801 switch (buffer[0]) { 803 switch (buffer[0]) {
802 case 0x00: 804 case 0x00:
803 dbgprintf("Operator logo\n"); 805 dbgprintf("Operator logo\n");
804 if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_OperatorLogo; 806 if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_OperatorLogo;
805 break; 807 break;
806 case 0x01: 808 case 0x01:
807 dbgprintf("Caller logo\n"); 809 dbgprintf("Caller logo\n");
808 if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_CallerGroupLogo; 810 if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_CallerGroupLogo;
809 break; 811 break;
810 case 0x02: 812 case 0x02:
811 dbgprintf("Startup logo\n"); 813 dbgprintf("Startup logo\n");
812 if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_StartupLogo; 814 if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_StartupLogo;
813 break; 815 break;
814 case 0x03: 816 case 0x03:
815 dbgprintf("Picture Image logo\n"); 817 dbgprintf("Picture Image logo\n");
816 if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_PictureImage; 818 if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_PictureImage;
817 break; 819 break;
818 } 820 }
819 821
820 bitmap->Number = 0; 822 bitmap->Number = 0;
821 fread(buffer,1,4,file); 823 fread(buffer,1,4,file);
822 number = buffer[0] + 1; 824 number = buffer[0] + 1;
823 w = buffer[1]; 825 w = buffer[1];
824 h = buffer[2]; 826 h = buffer[2];
825 for (i=0;i<number;i++) { 827 for (i=0;i<number;i++) {
826 bitmap->Bitmap[i].Type = bitmap->Bitmap[0].Type; 828 bitmap->Bitmap[i].Type = bitmap->Bitmap[0].Type;
827 GSM_GetMaxBitmapWidthHeight(bitmap->Bitmap[i].Type, &bitmap->Bitmap[i].BitmapWidth, &bitmap->Bitmap[i].BitmapHeight); 829 GSM_GetMaxBitmapWidthHeight(bitmap->Bitmap[i].Type, &bitmap->Bitmap[i].BitmapWidth, &bitmap->Bitmap[i].BitmapHeight);
828 if (h < bitmap->Bitmap[i].BitmapHeight) bitmap->Bitmap[i].BitmapHeight= h; 830 if (h < bitmap->Bitmap[i].BitmapHeight) bitmap->Bitmap[i].BitmapHeight= h;
829 if (w < bitmap->Bitmap[i].BitmapWidth) bitmap->Bitmap[i].BitmapWidth = w; 831 if (w < bitmap->Bitmap[i].BitmapWidth) bitmap->Bitmap[i].BitmapWidth = w;
830 832
831 division=div(w,8); 833 division=div(w,8);
832 /* For startup logos */ 834 /* For startup logos */
833 if (division.rem!=0) division.quot++; 835 if (division.rem!=0) division.quot++;
834 if (fread(buffer,1,(division.quot*h),file)!=(unsigned int)(division.quot*h)) return ERR_UNKNOWN; 836 if (fread(buffer,1,(division.quot*h),file)!=(unsigned int)(division.quot*h)) return ERR_UNKNOWN;
835 837
836 GSM_ClearBitmap(&bitmap->Bitmap[i]); 838 GSM_ClearBitmap(&bitmap->Bitmap[i]);
837 839
838 pos=0;pos2=7; 840 pos=0;pos2=7;
839 for (y=0;y<h;y++) { 841 for (y=0;y<h;y++) {
840 for (x=0;x<w;x++) { 842 for (x=0;x<w;x++) {
841 if ((buffer[pos]&(1<<pos2))>0) { 843 if ((buffer[pos]&(1<<pos2))>0) {
842 if (y<bitmap->Bitmap[i].BitmapHeight && x<bitmap->Bitmap[i].BitmapWidth) GSM_SetPointBitmap(&bitmap->Bitmap[i],x,y); 844 if (y<bitmap->Bitmap[i].BitmapHeight && x<bitmap->Bitmap[i].BitmapWidth) GSM_SetPointBitmap(&bitmap->Bitmap[i],x,y);
843 } 845 }
844 pos2--; 846 pos2--;
845 /* going to new byte */ 847 /* going to new byte */
846 if (pos2<0) {pos2=7;pos++;} 848 if (pos2<0) {pos2=7;pos++;}
847 } 849 }
848 /* for startup logos-new line means new byte */ 850 /* for startup logos-new line means new byte */
849 if (pos2!=7) {pos2=7;pos++;} 851 if (pos2!=7) {pos2=7;pos++;}
850 } 852 }
851 bitmap->Number++; 853 bitmap->Number++;
852 if (bitmap->Number == MAX_MULTI_BITMAP) break; 854 if (bitmap->Number == MAX_MULTI_BITMAP) break;
853 } 855 }
854 return (ERR_NONE); 856 return (ERR_NONE);
855} 857}
856 858
857static GSM_Error loadnolngg(FILE *file, GSM_MultiBitmap *bitmap, bool nolformat) 859static GSM_Error loadnolngg(FILE *file, GSM_MultiBitmap *bitmap, bool nolformat)
858{ 860{
859 unsigned char buffer[2000]; 861 unsigned char buffer[2000];
860 int i,h,w,x,y; 862 int i,h,w,x,y;
861 863
862 fread(buffer, 1, 6, file); 864 fread(buffer, 1, 6, file);
863 865
864 if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_CallerGroupLogo; 866 if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_CallerGroupLogo;
865 if (nolformat) { 867 if (nolformat) {
866 fread(buffer, 1, 4, file); 868 fread(buffer, 1, 4, file);
867 sprintf(bitmap->Bitmap[0].NetworkCode, "%d %02d", buffer[0]+256*buffer[1], buffer[2]); 869 sprintf(bitmap->Bitmap[0].NetworkCode, "%d %02d", buffer[0]+256*buffer[1], buffer[2]);
868 if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_OperatorLogo; 870 if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_OperatorLogo;
869 } 871 }
870 872
871 fread(buffer, 1, 4, file); 873 fread(buffer, 1, 4, file);
872 w = buffer[0]; 874 w = buffer[0];
873 h = buffer[2]; 875 h = buffer[2];
874 GSM_GetMaxBitmapWidthHeight(bitmap->Bitmap[0].Type, &bitmap->Bitmap[0].BitmapWidth, &bitmap->Bitmap[0].BitmapHeight); 876 GSM_GetMaxBitmapWidthHeight(bitmap->Bitmap[0].Type, &bitmap->Bitmap[0].BitmapWidth, &bitmap->Bitmap[0].BitmapHeight);
875 if (h < bitmap->Bitmap[0].BitmapHeight) bitmap->Bitmap[0].BitmapHeight= h; 877 if (h < bitmap->Bitmap[0].BitmapHeight) bitmap->Bitmap[0].BitmapHeight= h;
876 if (w < bitmap->Bitmap[0].BitmapWidth) bitmap->Bitmap[0].BitmapWidth= w; 878 if (w < bitmap->Bitmap[0].BitmapWidth) bitmap->Bitmap[0].BitmapWidth= w;
877 879
878 /* Unknown bytes. */ 880 /* Unknown bytes. */
879 fread(buffer, 1, 6, file); 881 fread(buffer, 1, 6, file);
880 882
881 GSM_ClearBitmap(&bitmap->Bitmap[0]); 883 GSM_ClearBitmap(&bitmap->Bitmap[0]);
882 884
883 x=0; y=0; 885 x=0; y=0;
884 for (i=0; i<w*h; i++) { 886 for (i=0; i<w*h; i++) {
885 if (fread(buffer, 1, 1, file)!=1) return ERR_UNKNOWN; 887 if (fread(buffer, 1, 1, file)!=1) return ERR_UNKNOWN;
886 if (buffer[0]=='1') GSM_SetPointBitmap(&bitmap->Bitmap[0],x,y); 888 if (buffer[0]=='1') GSM_SetPointBitmap(&bitmap->Bitmap[0],x,y);
887 x++; 889 x++;
888 if (x==w) {x=0; y++;} 890 if (x==w) {x=0; y++;}
889 } 891 }
890 892
891#ifdef DEBUG 893#ifdef DEBUG
892 /* Some programs writes here fileinfo */ 894 /* Some programs writes here fileinfo */
893 if (fread(buffer, 1, 1, file)==1) { 895 if (fread(buffer, 1, 1, file)==1) {
894 dbgprintf("Fileinfo: %c",buffer[0]); 896 dbgprintf("Fileinfo: %c",buffer[0]);
895 while (fread(buffer, 1, 1, file)==1) { 897 while (fread(buffer, 1, 1, file)==1) {
896 if (buffer[0]!=0x0A) dbgprintf("%c",buffer[0]); 898 if (buffer[0]!=0x0A) dbgprintf("%c",buffer[0]);
897 } 899 }
898 dbgprintf("\n"); 900 dbgprintf("\n");
899 } 901 }
900#endif 902#endif
901 bitmap->Number = 1; 903 bitmap->Number = 1;
902 return(ERR_NONE); 904 return(ERR_NONE);
903} 905}
904 906
905static GSM_Error loadnsl(FILE *file, GSM_MultiBitmap *bitmap) 907static GSM_Error loadnsl(FILE *file, GSM_MultiBitmap *bitmap)
906{ 908{
907 unsigned char block[6],buffer[505]; 909 unsigned char block[6],buffer[505];
908 int block_size; 910 int block_size;
909 GSM_Bitmap_TypesOldType; 911 GSM_Bitmap_TypesOldType;
910 912
911 while (fread(block,1,6,file)==6) { 913 while (fread(block,1,6,file)==6) {
912 block_size = block[4]*256 + block[5]; 914 block_size = block[4]*256 + block[5];
913 dbgprintf("Block %c%c%c%c, size %i\n",block[0],block[1],block[2],block[3],block_size); 915 dbgprintf("Block %c%c%c%c, size %i\n",block[0],block[1],block[2],block[3],block_size);
914 if (!strncmp(block, "FORM", 4)) { 916 if (!strncmp(block, "FORM", 4)) {
915 dbgprintf("File ID\n"); 917 dbgprintf("File ID\n");
916 } else { 918 } else {
917 if (block_size>504) return ERR_UNKNOWN; 919 if (block_size>504) return ERR_UNKNOWN;
918 if (block_size!=0) { 920 if (block_size!=0) {
919 fread(buffer,1,block_size,file); 921 fread(buffer,1,block_size,file);
920 /* if it's string, we end it with 0 */ 922 /* if it's string, we end it with 0 */
921 buffer[block_size]=0; 923 buffer[block_size]=0;
922#ifdef DEBUG 924#ifdef DEBUG
923 if (!strncmp(block, "VERS", 4)) dbgprintf("File saved by: %s\n",buffer); 925 if (!strncmp(block, "VERS", 4)) dbgprintf("File saved by: %s\n",buffer);
924 if (!strncmp(block, "MODL", 4)) dbgprintf("Logo saved from: %s\n",buffer); 926 if (!strncmp(block, "MODL", 4)) dbgprintf("Logo saved from: %s\n",buffer);
925 if (!strncmp(block, "COMM", 4)) dbgprintf("Phone was connected to COM port: %s\n",buffer); 927 if (!strncmp(block, "COMM", 4)) dbgprintf("Phone was connected to COM port: %s\n",buffer);
926#endif 928#endif
927 if (!strncmp(block, "NSLD", 4)) { 929 if (!strncmp(block, "NSLD", 4)) {
928 bitmap->Bitmap[0].BitmapHeight = 48; 930 bitmap->Bitmap[0].BitmapHeight = 48;
929 bitmap->Bitmap[0].BitmapWidth = 84; 931 bitmap->Bitmap[0].BitmapWidth = 84;
930 OldType = bitmap->Bitmap[0].Type; 932 OldType = bitmap->Bitmap[0].Type;
931 PHONE_DecodeBitmap(GSM_NokiaStartupLogo, buffer, &bitmap->Bitmap[0]); 933 PHONE_DecodeBitmap(GSM_NokiaStartupLogo, buffer, &bitmap->Bitmap[0]);
932 if (OldType != GSM_None) bitmap->Bitmap[0].Type = OldType; 934 if (OldType != GSM_None) bitmap->Bitmap[0].Type = OldType;
933 dbgprintf("Startup logo (size %i)\n",block_size); 935 dbgprintf("Startup logo (size %i)\n",block_size);
934 } 936 }
935 } 937 }
936 } 938 }
937 } 939 }
938 bitmap->Number = 1; 940 bitmap->Number = 1;
939 return(ERR_NONE); 941 return(ERR_NONE);
940} 942}
941 943
942static GSM_Error loadwbmp(FILE *file, GSM_MultiBitmap *bitmap) 944static GSM_Error loadwbmp(FILE *file, GSM_MultiBitmap *bitmap)
943{ 945{
944 unsigned char buffer[10000]; 946 unsigned char buffer[10000];
945 947
946 fread(buffer,1,4,file); 948 fread(buffer,1,4,file);
947 bitmap->Bitmap[0].BitmapWidth = buffer[2]; 949 bitmap->Bitmap[0].BitmapWidth = buffer[2];
948 bitmap->Bitmap[0].BitmapHeight = buffer[3]; 950 bitmap->Bitmap[0].BitmapHeight = buffer[3];
949 bitmap->Number = 1; 951 bitmap->Number = 1;
950 952
951 fread(buffer,1,10000,file); 953 fread(buffer,1,10000,file);
952 PHONE_DecodeBitmap(GSM_Nokia7110OperatorLogo, buffer, &bitmap->Bitmap[0]); 954 PHONE_DecodeBitmap(GSM_Nokia7110OperatorLogo, buffer, &bitmap->Bitmap[0]);
953 GSM_ReverseBitmap(&bitmap->Bitmap[0]); 955 GSM_ReverseBitmap(&bitmap->Bitmap[0]);
954 956
955 return ERR_NONE; 957 return ERR_NONE;
956} 958}
957 959
960static GSM_Error loadgif(FILE *file, GSM_MultiBitmap *bitmap)
961{
962 GSM_Bitmap *bmap = &bitmap->Bitmap[0];
963 char *buffer;
964 struct stat st;
965 int length;
966
967 dbgprintf("loading gif file\n");
968 fstat(fileno(file), &st);
969 bmap->BinaryPic.Length = length = st.st_size;
970 bmap->BinaryPic.Buffer = buffer = malloc(length);
971 if (bmap->BinaryPic.Buffer == NULL)
972 return ERR_MOREMEMORY;
973
974 fread(buffer, 1, length, file);
975 dbgprintf("Length %i name \"%s\"\n", length,
976 DecodeUnicodeString(bmap->Name));
977
978 bmap->Type = GSM_PictureBinary;
979 bmap->BinaryPic.Type = PICTURE_GIF;
980 bmap->BitmapWidth = 256 * buffer[7] + buffer[6];
981 bmap->BitmapHeight = 256 * buffer[9] + buffer[8];
982 bitmap->Number = 1;
983
984 return ERR_NONE;
985}
986
958GSM_Error GSM_ReadBitmapFile(char *FileName, GSM_MultiBitmap *bitmap) 987GSM_Error GSM_ReadBitmapFile(char *FileName, GSM_MultiBitmap *bitmap)
959{ 988{
960 FILE *file; 989 FILE *file;
961 unsigned charbuffer[300]; 990 unsigned charbuffer[300];
962 991
963 file = fopen(FileName, "rb"); 992 file = fopen(FileName, "rb");
964 if (file == NULL) return ERR_CANTOPENFILE; 993 if (file == NULL) return ERR_CANTOPENFILE;
965 994
995 bitmap->Bitmap[0].Name = malloc((strlen(FileName) + 1) * 2);
996 if (bitmap->Bitmap[0].Name == NULL) return ERR_MOREMEMORY;
997 EncodeUnicode(bitmap->Bitmap[0].Name, FileName, strlen(FileName));
998
966 fread(buffer, 1, 9, file); /* Read the header of the file. */ 999 fread(buffer, 1, 9, file); /* Read the header of the file. */
967 rewind(file); 1000 rewind(file);
968 1001
969 bitmap->Bitmap[0].DefaultBitmap = false; 1002 bitmap->Bitmap[0].DefaultBitmap = false;
970 1003
971 /* Attempt to identify filetype */ 1004 /* Attempt to identify filetype */
972 if (memcmp(buffer, "BM",2)==0) { 1005 if (memcmp(buffer, "BM",2)==0) {
973 return loadbmp(file,bitmap); 1006 return loadbmp(file,bitmap);
974 } else if (buffer[0] == 0x00 && buffer[1] == 0x00) { 1007 } else if (buffer[0] == 0x00 && buffer[1] == 0x00) {
975 return loadwbmp(file,bitmap); 1008 return loadwbmp(file,bitmap);
976 } else if (memcmp(buffer, "NLM",3)==0) { 1009 } else if (memcmp(buffer, "NLM",3)==0) {
977 return loadnlm(file,bitmap); 1010 return loadnlm(file,bitmap);
978 } else if (memcmp(buffer, "NOL",3)==0) { 1011 } else if (memcmp(buffer, "NOL",3)==0) {
979 return loadnolngg(file,bitmap,true); 1012 return loadnolngg(file,bitmap,true);
980 } else if (memcmp(buffer, "NGG",3)==0) { 1013 } else if (memcmp(buffer, "NGG",3)==0) {
981 return loadnolngg(file,bitmap,false); 1014 return loadnolngg(file,bitmap,false);
982 } else if (memcmp(buffer, "FORM",4)==0) { 1015 } else if (memcmp(buffer, "FORM",4)==0) {
983 return loadnsl(file,bitmap); 1016 return loadnsl(file,bitmap);
1017 } else if (memcmp(buffer, "GIF",3)==0) {
1018 return loadgif(file,bitmap);
984 } 1019 }
985 return ERR_UNKNOWN; 1020 return ERR_UNKNOWN;
986} 1021}
987 1022
988void NOKIA_CopyBitmap(GSM_Phone_Bitmap_Types Type, GSM_Bitmap *Bitmap, char *Buffer, int *Length) 1023void NOKIA_CopyBitmap(GSM_Phone_Bitmap_Types Type, GSM_Bitmap *Bitmap, char *Buffer, int *Length)
989{ 1024{
990 int Width, Height; 1025 int Width, Height;
991 1026
992 Buffer[(*Length)++] = 0x00; 1027 Buffer[(*Length)++] = 0x00;
993 PHONE_GetBitmapWidthHeight(Type, &Width, &Height); 1028 PHONE_GetBitmapWidthHeight(Type, &Width, &Height);
994 Buffer[(*Length)++] = Width; 1029 Buffer[(*Length)++] = Width;
995 Buffer[(*Length)++] = Height; 1030 Buffer[(*Length)++] = Height;
996 Buffer[(*Length)++] = 0x01; 1031 Buffer[(*Length)++] = 0x01;
997 PHONE_EncodeBitmap(Type, Buffer + (*Length), Bitmap); 1032 PHONE_EncodeBitmap(Type, Buffer + (*Length), Bitmap);
998 (*Length) = (*Length) + PHONE_GetBitmapSize(Type,0,0); 1033 (*Length) = (*Length) + PHONE_GetBitmapSize(Type,0,0);
999} 1034}
1000 1035
1001/* How should editor hadle tabs in this file? Add editor commands here. 1036/* How should editor hadle tabs in this file? Add editor commands here.
1002 * vim: noexpandtab sw=8 ts=8 sts=8: 1037 * vim: noexpandtab sw=8 ts=8 sts=8:
1003 */ 1038 */
diff --git a/gammu/emb/common/service/gsmlogo.h b/gammu/emb/common/service/gsmlogo.h
index b1b579d..6c6e2d8 100644
--- a/gammu/emb/common/service/gsmlogo.h
+++ b/gammu/emb/common/service/gsmlogo.h
@@ -1,180 +1,206 @@
1/* (c) 2002-2004 by Marcin Wiacek */ 1/* (c) 2002-2004 by Marcin Wiacek */
2 2
3#ifndef __gsm_bitmaps_h 3#ifndef __gsm_bitmaps_h
4#define __gsm_bitmaps_h 4#define __gsm_bitmaps_h
5 5
6#include "../gsmcomon.h" 6#include "../gsmcomon.h"
7 7
8typedef enum {
9 PICTURE_BMP = 1,
10 PICTURE_GIF,
11 PICTURE_JPG,
12 PICTURE_ICN,
13 PICTURE_PNG
14} GSM_BinaryPicture_Types;
15
16typedef struct {
17 GSM_BinaryPicture_Types Type;
18 unsigned char *Buffer;
19 int Length;
20} GSM_BinaryPicture;
21
8/** 22/**
9 * Enum to handle all possible bitmaps, which are not saved in various filesystems. 23 * Enum to handle all possible bitmaps, which are not saved in various filesystems.
10 */ 24 */
11typedef enum { 25typedef enum {
12 GSM_None = 1, 26 GSM_None = 1,
13 /** 27 /**
14 * ID of static file in filesystem displayed during startup 28 * ID of static file in filesystem displayed during startup
15 */ 29 */
16 GSM_ColourStartupLogo_ID, 30 GSM_ColourStartupLogo_ID,
17 /** 31 /**
18 * Static mono bitmap/ID of animated mono bitmap displayed during startup 32 * Static mono bitmap/ID of animated mono bitmap displayed during startup
19 */ 33 */
20 GSM_StartupLogo, 34 GSM_StartupLogo,
21 /** 35 /**
22 * ID of static file in filesystem displayed instead of operator name 36 * ID of static file in filesystem displayed instead of operator name
23 */ 37 */
24 GSM_ColourOperatorLogo_ID, 38 GSM_ColourOperatorLogo_ID,
25 /** 39 /**
26 * Mono bitmap displayed instead of operator name 40 * Mono bitmap displayed instead of operator name
27 */ 41 */
28 GSM_OperatorLogo, 42 GSM_OperatorLogo,
29 /** 43 /**
30 * ID of static file in filesystem displayed as wallpaper 44 * ID of static file in filesystem displayed as wallpaper
31 */ 45 */
32 GSM_ColourWallPaper_ID, 46 GSM_ColourWallPaper_ID,
33 /** 47 /**
34 * Mono bitmap assigned to caller group 48 * Mono bitmap assigned to caller group
35 */ 49 */
36 GSM_CallerGroupLogo, 50 GSM_CallerGroupLogo,
37 /** 51 /**
38 * Text displayed during startup, which can't be removed from phone menu 52 * Text displayed during startup, which can't be removed from phone menu
39 */ 53 */
40 GSM_DealerNote_Text, 54 GSM_DealerNote_Text,
41 /** 55 /**
42 * Text displayed during startup 56 * Text displayed during startup
43 */ 57 */
44 GSM_WelcomeNote_Text, 58 GSM_WelcomeNote_Text,
45 /** 59 /**
46 * Image defined in Smart Messaging specification 60 * Image defined in Smart Messaging specification
47 */ 61 */
48 GSM_PictureImage 62 GSM_PictureImage,
63 /**
64 * Binary picture (BMP, GIF, etc.)
65 */
66 GSM_PictureBinary
49} GSM_Bitmap_Types; 67} GSM_Bitmap_Types;
50 68
51 #define GSM_BITMAP_SIZE(65+7)/8*96 69 #define GSM_BITMAP_SIZE(65+7)/8*96
52#define GSM_BITMAP_TEXT_LENGTH 128 70#define GSM_BITMAP_TEXT_LENGTH 128
53 71
54/** 72/**
55 * Structure for all possible bitmaps, which are not saved in various filesystems 73 * Structure for all possible bitmaps, which are not saved in various filesystems
56 */ 74 */
57typedef struct { 75typedef struct {
58 /** 76 /**
59 * For all: bitmap type 77 * For all: bitmap type
60 */ 78 */
61 GSM_Bitmap_Types Type; 79 GSM_Bitmap_Types Type;
62 /** 80 /**
63 * For caller group logos: number of group 81 * For caller group logos: number of group
64 * For startup logos: number of animated bitmap 82 * For startup logos: number of animated bitmap
65 */ 83 */
66 unsigned char Location; 84 unsigned char Location;
67 /** 85 /**
68 * For dealer/welcome note text: text 86 * For dealer/welcome note text: text
69 * For caller group logo: name of group 87 * For caller group logo: name of group
70 * For picture images: text assigned to it 88 * For picture images: text assigned to it
71 */ 89 */
72 unsigned char Text[2 * (GSM_BITMAP_TEXT_LENGTH + 1)]; 90 unsigned char Text[2 * (GSM_BITMAP_TEXT_LENGTH + 1)];
73 /** 91 /**
74 * For caller group logo: true, when logo is enabled in group 92 * For caller group logo: true, when logo is enabled in group
75 */ 93 */
76 bool BitmapEnabled; 94 bool BitmapEnabled;
77 /** 95 /**
78 * For caller group logo: true, when group has default name 96 * For caller group logo: true, when group has default name
79 */ 97 */
80 bool DefaultName; 98 bool DefaultName;
81 /** 99 /**
82 * For caller group logo: true, when group has default bitmap 100 * For caller group logo: true, when group has default bitmap
83 */ 101 */
84 bool DefaultBitmap; 102 bool DefaultBitmap;
85 /** 103 /**
86 * For caller group logo: true, when group has default ringtone 104 * For caller group logo: true, when group has default ringtone
87 */ 105 */
88 bool DefaultRingtone; 106 bool DefaultRingtone;
89 /** 107 /**
90 * For caller group logo: ringtone ID. Phone model specific 108 * For caller group logo: ringtone ID. Phone model specific
91 */ 109 */
92 unsigned char RingtoneID; 110 unsigned char RingtoneID;
93 bool FileSystemRingtone; 111 bool FileSystemRingtone;
94 /** 112 /**
95 * For mono bitmaps: body of bitmap 113 * For mono bitmaps: body of bitmap
96 */ 114 */
97 unsigned char BitmapPoints[GSM_BITMAP_SIZE]; 115 unsigned char BitmapPoints[GSM_BITMAP_SIZE];
98 /** 116 /**
99 * For mono bitmaps: height specified in pixels 117 * For mono bitmaps: height specified in pixels
100 */ 118 */
101 unsigned char BitmapHeight; 119 unsigned char BitmapHeight;
102 /** 120 /**
103 * For mono bitmaps: width specified in pixels 121 * For mono bitmaps: width specified in pixels
104 */ 122 */
105 unsigned char BitmapWidth; 123 unsigned char BitmapWidth;
106 /** 124 /**
107 * For operator logos: Network operator code 125 * For operator logos: Network operator code
108 */ 126 */
109 char NetworkCode[7]; 127 char NetworkCode[7];
110 /** 128 /**
111 * For picture images: number of sender 129 * For picture images: number of sender
112 */ 130 */
113 unsigned char Sender[2 * (GSM_MAX_NUMBER_LENGTH + 1)]; 131 unsigned char Sender[2 * (GSM_MAX_NUMBER_LENGTH + 1)];
114 /** 132 /**
115 * For colour bitmaps: ID 133 * For colour bitmaps: ID
116 */ 134 */
117 unsigned char ID; 135 unsigned char ID;
136 /**
137 * For binary pictures (GIF, BMP, etc.): frame and length
138 */
139 GSM_BinaryPicture BinaryPic;
140 /**
141 * Bitmap name
142 */
143 char *Name;
118} GSM_Bitmap; 144} GSM_Bitmap;
119 145
120#define MAX_MULTI_BITMAP 6 146#define MAX_MULTI_BITMAP 6
121 147
122/** 148/**
123 * Structure to handle more than one bitmap 149 * Structure to handle more than one bitmap
124 */ 150 */
125typedef struct { 151typedef struct {
126 /** 152 /**
127 * Number of bitmaps 153 * Number of bitmaps
128 */ 154 */
129 unsigned char Number; 155 unsigned char Number;
130 /** 156 /**
131 * All bitmaps 157 * All bitmaps
132 */ 158 */
133 GSM_Bitmap Bitmap[MAX_MULTI_BITMAP]; 159 GSM_Bitmap Bitmap[MAX_MULTI_BITMAP];
134} GSM_MultiBitmap; 160} GSM_MultiBitmap;
135 161
136typedef enum { 162typedef enum {
137 GSM_NokiaStartupLogo = 1,/*size 84*48*/ 163 GSM_NokiaStartupLogo = 1,/*size 84*48*/
138 GSM_NokiaOperatorLogo, /*size 72*14*/ 164 GSM_NokiaOperatorLogo, /*size 72*14*/
139 GSM_Nokia7110OperatorLogo,/*size 78*21*/ 165 GSM_Nokia7110OperatorLogo,/*size 78*21*/
140 GSM_Nokia6510OperatorLogo,/*size 78*21*/ 166 GSM_Nokia6510OperatorLogo,/*size 78*21*/
141 GSM_NokiaCallerLogo, /*size 72*14*/ 167 GSM_NokiaCallerLogo, /*size 72*14*/
142 GSM_NokiaPictureImage, /*size 72*28*/ 168 GSM_NokiaPictureImage, /*size 72*28*/
143 GSM_Nokia7110StartupLogo,/*size 96*65*/ 169 GSM_Nokia7110StartupLogo,/*size 96*65*/
144 GSM_Nokia6210StartupLogo,/*size 96*60*/ 170 GSM_Nokia6210StartupLogo,/*size 96*60*/
145 GSM_AlcatelBMMIPicture, 171 GSM_AlcatelBMMIPicture,
146 GSM_EMSSmallPicture, /*size 8* 8*/ 172 GSM_EMSSmallPicture, /*size 8* 8*/
147 GSM_EMSMediumPicture, /*size 16*16*/ 173 GSM_EMSMediumPicture, /*size 16*16*/
148 GSM_EMSBigPicture, /*size 32*32*/ 174 GSM_EMSBigPicture, /*size 32*32*/
149 GSM_EMSVariablePicture 175 GSM_EMSVariablePicture
150} GSM_Phone_Bitmap_Types; 176} GSM_Phone_Bitmap_Types;
151 177
152 bool GSM_IsPointBitmap (GSM_Bitmap *bmp, int x, int y); 178 bool GSM_IsPointBitmap (GSM_Bitmap *bmp, int x, int y);
153 void GSM_SetPointBitmap (GSM_Bitmap *bmp, int x, int y); 179 void GSM_SetPointBitmap (GSM_Bitmap *bmp, int x, int y);
154 void GSM_ClearPointBitmap (GSM_Bitmap *bmp, int x, int y); 180 void GSM_ClearPointBitmap (GSM_Bitmap *bmp, int x, int y);
155 void GSM_ClearBitmap (GSM_Bitmap *bmp); 181 void GSM_ClearBitmap (GSM_Bitmap *bmp);
156 void GSM_ResizeBitmap (GSM_Bitmap *dest, GSM_Bitmap *src, int width, int height); 182 void GSM_ResizeBitmap (GSM_Bitmap *dest, GSM_Bitmap *src, int width, int height);
157 void GSM_ReverseBitmap (GSM_Bitmap *Bitmap); 183 void GSM_ReverseBitmap (GSM_Bitmap *Bitmap);
158 void GSM_GetMaxBitmapWidthHeight(GSM_Bitmap_Types Type, unsigned char *width, unsigned char *height); 184 void GSM_GetMaxBitmapWidthHeight(GSM_Bitmap_Types Type, unsigned char *width, unsigned char *height);
159 int GSM_GetBitmapSize (GSM_Bitmap *bmp); 185 int GSM_GetBitmapSize (GSM_Bitmap *bmp);
160 void GSM_PrintBitmap (FILE *file, GSM_Bitmap *bitmap); 186 void GSM_PrintBitmap (FILE *file, GSM_Bitmap *bitmap);
161 187
162 GSM_Error GSM_SaveBitmapFile(char *FileName, GSM_MultiBitmap *bitmap); 188 GSM_Error GSM_SaveBitmapFile(char *FileName, GSM_MultiBitmap *bitmap);
163 GSM_Error GSM_ReadBitmapFile(char *FileName, GSM_MultiBitmap *bitmap); 189 GSM_Error GSM_ReadBitmapFile(char *FileName, GSM_MultiBitmap *bitmap);
164 190
165GSM_Error BMP2Bitmap (unsigned char *buffer, FILE *file,GSM_Bitmap *bitmap); 191GSM_Error BMP2Bitmap (unsigned char *buffer, FILE *file,GSM_Bitmap *bitmap);
166GSM_Error Bitmap2BMP (unsigned char *buffer, FILE *file,GSM_Bitmap *bitmap); 192GSM_Error Bitmap2BMP (unsigned char *buffer, FILE *file,GSM_Bitmap *bitmap);
167 193
168 void PHONE_GetBitmapWidthHeight(GSM_Phone_Bitmap_Types Type, int *width, int *height); 194 void PHONE_GetBitmapWidthHeight(GSM_Phone_Bitmap_Types Type, int *width, int *height);
169 int PHONE_GetBitmapSize(GSM_Phone_Bitmap_Types Type, int width, int height); 195 int PHONE_GetBitmapSize(GSM_Phone_Bitmap_Types Type, int width, int height);
170 void PHONE_ClearBitmap (GSM_Phone_Bitmap_Types Type, char *buffer, int width, int height); 196 void PHONE_ClearBitmap (GSM_Phone_Bitmap_Types Type, char *buffer, int width, int height);
171 void PHONE_DecodeBitmap (GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap); 197 void PHONE_DecodeBitmap (GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap);
172 void PHONE_EncodeBitmap (GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap); 198 void PHONE_EncodeBitmap (GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap);
173 199
174 void NOKIA_CopyBitmap (GSM_Phone_Bitmap_Types Type, GSM_Bitmap *Bitmap, char *Buffer, int *Length); 200 void NOKIA_CopyBitmap (GSM_Phone_Bitmap_Types Type, GSM_Bitmap *Bitmap, char *Buffer, int *Length);
175 201
176#endif 202#endif
177 203
178/* How should editor hadle tabs in this file? Add editor commands here. 204/* How should editor hadle tabs in this file? Add editor commands here.
179 * vim: noexpandtab sw=8 ts=8 sts=8: 205 * vim: noexpandtab sw=8 ts=8 sts=8:
180 */ 206 */
diff --git a/gammu/emb/common/service/gsmmisc.h b/gammu/emb/common/service/gsmmisc.h
index 37501ad..793d3d1 100644
--- a/gammu/emb/common/service/gsmmisc.h
+++ b/gammu/emb/common/service/gsmmisc.h
@@ -103,214 +103,219 @@ typedef struct {
103 */ 103 */
104 char Code[GSM_SECURITY_CODE_LEN+1]; 104 char Code[GSM_SECURITY_CODE_LEN+1];
105 /** 105 /**
106 * Type of the code. 106 * Type of the code.
107 */ 107 */
108 GSM_SecurityCodeType Type; 108 GSM_SecurityCodeType Type;
109} GSM_SecurityCode; 109} GSM_SecurityCode;
110 110
111/* ---------------------------- keyboard ----------------------------------- */ 111/* ---------------------------- keyboard ----------------------------------- */
112 112
113typedef enum { 113typedef enum {
114 GSM_KEY_NONE = 0x00, 114 GSM_KEY_NONE = 0x00,
115 GSM_KEY_1 = 0x01, 115 GSM_KEY_1 = 0x01,
116 GSM_KEY_2, 116 GSM_KEY_2,
117 GSM_KEY_3, 117 GSM_KEY_3,
118 GSM_KEY_4, 118 GSM_KEY_4,
119 GSM_KEY_5, 119 GSM_KEY_5,
120 GSM_KEY_6, 120 GSM_KEY_6,
121 GSM_KEY_7, 121 GSM_KEY_7,
122 GSM_KEY_8, 122 GSM_KEY_8,
123 GSM_KEY_9, 123 GSM_KEY_9,
124 GSM_KEY_0, 124 GSM_KEY_0,
125 /** 125 /**
126 * # 126 * #
127 */ 127 */
128 GSM_KEY_HASH, 128 GSM_KEY_HASH,
129 /** 129 /**
130 * * 130 * *
131 */ 131 */
132 GSM_KEY_ASTERISK, 132 GSM_KEY_ASTERISK,
133 GSM_KEY_POWER, 133 GSM_KEY_POWER,
134 /** 134 /**
135 * in some phone ie. N5110 sometimes works identical to POWER 135 * in some phone ie. N5110 sometimes works identical to POWER
136 */ 136 */
137 GSM_KEY_GREEN, 137 GSM_KEY_GREEN,
138 /** 138 /**
139 * (c) key in some phone: ie. N5110 139 * (c) key in some phone: ie. N5110
140 */ 140 */
141 GSM_KEY_RED, 141 GSM_KEY_RED,
142 /** 142 /**
143 * doesn't available in some phones as separate button: ie. N5110 143 * doesn't available in some phones as separate button: ie. N5110
144 */ 144 */
145 GSM_KEY_INCREASEVOLUME, 145 GSM_KEY_INCREASEVOLUME,
146 /** 146 /**
147 * doesn't available in some phones as separate button: ie. N5110 147 * doesn't available in some phones as separate button: ie. N5110
148 */ 148 */
149 GSM_KEY_DECREASEVOLUME, 149 GSM_KEY_DECREASEVOLUME,
150 GSM_KEY_UP = 0x17, 150 GSM_KEY_UP = 0x17,
151 GSM_KEY_DOWN, 151 GSM_KEY_DOWN,
152 GSM_KEY_MENU, 152 GSM_KEY_MENU,
153 /** 153 /**
154 * doesn't available in some phone: ie. N5110 154 * doesn't available in some phone: ie. N5110
155 */ 155 */
156 GSM_KEY_NAMES 156 GSM_KEY_NAMES
157} GSM_KeyCode; 157} GSM_KeyCode;
158 158
159GSM_Error MakeKeySequence(char *text, GSM_KeyCode *KeyCode, int *Length); 159GSM_Error MakeKeySequence(char *text, GSM_KeyCode *KeyCode, int *Length);
160 160
161/* ------------------------------- display features ------------------------ */ 161/* ------------------------------- display features ------------------------ */
162 162
163typedef enum { 163typedef enum {
164 GSM_CallActive = 1, 164 GSM_CallActive = 1,
165 /** 165 /**
166 * blinking envelope 166 * blinking envelope
167 */ 167 */
168 GSM_SMSMemoryFull, 168 GSM_SMSMemoryFull,
169 GSM_FaxCall, 169 GSM_FaxCall,
170 GSM_UnreadSMS, 170 GSM_UnreadSMS,
171 GSM_DataCall, 171 GSM_DataCall,
172 GSM_VoiceCall, 172 GSM_VoiceCall,
173 GSM_KeypadLocked 173 GSM_KeypadLocked
174} GSM_DisplayFeature; 174} GSM_DisplayFeature;
175 175
176typedef struct { 176typedef struct {
177 int Number; 177 int Number;
178 GSM_DisplayFeature Feature[7]; 178 GSM_DisplayFeature Feature[7];
179} GSM_DisplayFeatures; 179} GSM_DisplayFeatures;
180 180
181/* ----------------------------- power source ------------------------------ */ 181/* ----------------------------- power source ------------------------------ */
182 182
183typedef enum { 183typedef enum {
184 GSM_BatteryPowered = 1, 184 GSM_BatteryPowered = 1,
185 GSM_BatteryConnected, 185 GSM_BatteryConnected,
186 GSM_BatteryNotConnected, 186 GSM_BatteryNotConnected,
187 GSM_PowerFault 187 GSM_PowerFault
188} GSM_ChargeState; 188} GSM_ChargeState;
189 189
190typedef struct { 190typedef struct {
191 /** 191 /**
192 * Signal strength in percent, -1 = unknown 192 * Signal strength in percent, -1 = unknown
193 */ 193 */
194 int BatteryPercent; 194 int BatteryPercent;
195 /** 195 /**
196 * Charge state 196 * Charge state
197 */ 197 */
198 GSM_ChargeState ChargeState; 198 GSM_ChargeState ChargeState;
199} GSM_BatteryCharge; 199} GSM_BatteryCharge;
200 200
201/* ------------------------------ categories ------------------------------- */ 201/* ------------------------------ categories ------------------------------- */
202 202
203#define GSM_MAX_CATEGORY_NAME_LENGTH 50 203#define GSM_MAX_CATEGORY_NAME_LENGTH 50
204 204
205typedef enum { 205typedef enum {
206 Category_ToDo = 1, 206 Category_ToDo = 1,
207 Category_Phonebook 207 Category_Phonebook
208} GSM_CategoryType; 208} GSM_CategoryType;
209 209
210typedef struct { 210typedef struct {
211 GSM_CategoryType Type; 211 GSM_CategoryType Type;
212 int Location; 212 int Location;
213 unsigned char Name[(GSM_MAX_CATEGORY_NAME_LENGTH + 1)*2]; 213 unsigned char Name[(GSM_MAX_CATEGORY_NAME_LENGTH + 1)*2];
214} GSM_Category; 214} GSM_Category;
215 215
216typedef struct { 216typedef struct {
217 GSM_CategoryType Type; 217 GSM_CategoryType Type;
218 int Used; 218 int Used;
219} GSM_CategoryStatus; 219} GSM_CategoryStatus;
220 220
221/* ------------------- radio FM stations ---------------------------------- */ 221/* ------------------- radio FM stations ---------------------------------- */
222 222
223 #defineGSM_MAX_FMSTATION_LENGTH 12 223 #defineGSM_MAX_FMSTATION_LENGTH 12
224 #define GSM_MAX_FM_STATION 20 224 #define GSM_MAX_FM_STATION 20
225 225
226typedef struct { 226typedef struct {
227 int Location; 227 int Location;
228 char StationName [(GSM_MAX_FMSTATION_LENGTH+1)*2]; 228 char StationName [(GSM_MAX_FMSTATION_LENGTH+1)*2];
229 double Frequency; 229 double Frequency;
230} GSM_FMStation; 230} GSM_FMStation;
231 231
232/* ----------------------- filesystem ------------------------------------- */ 232/* ----------------------- filesystem ------------------------------------- */
233 233
234typedef enum { 234typedef enum {
235 GSM_File_Java_JAR = 1, 235 GSM_File_Java_JAR = 1,
236 GSM_File_Image_JPG, 236 GSM_File_Image_JPG,
237 GSM_File_Image_BMP, 237 GSM_File_Image_BMP,
238 GSM_File_Image_GIF, 238 GSM_File_Image_GIF,
239 GSM_File_Image_PNG, 239 GSM_File_Image_PNG,
240 GSM_File_Image_WBMP, 240 GSM_File_Image_WBMP,
241 GSM_File_Video_3GP, 241 GSM_File_Video_3GP,
242 GSM_File_Sound_AMR, 242 GSM_File_Sound_AMR,
243 GSM_File_Sound_NRT, /* DCT4 binary format */ 243 GSM_File_Sound_NRT, /* DCT4 binary format */
244 GSM_File_Sound_MIDI, 244 GSM_File_Sound_MIDI,
245#ifdef DEVELOP 245#ifdef DEVELOP
246 GSM_File_MMS, 246 GSM_File_MMS,
247#endif 247#endif
248 GSM_File_Other 248 GSM_File_Other
249} GSM_FileType; 249} GSM_FileType;
250 250
251typedef struct { 251typedef struct {
252 int Used; /* how many bytes used */ 252 int Used; /* how many bytes used */
253 unsigned char Name[300]; /* Name */ 253 unsigned char Name[300]; /* Name */
254 bool Folder; /* true, when folder */ 254 bool Folder; /* true, when folder */
255 int Level; 255 int Level;
256 GSM_FileTypeType; 256 GSM_FileTypeType;
257 unsigned charID_FullName[400]; 257 unsigned charID_FullName[400];
258 unsigned char*Buffer; 258 unsigned char*Buffer;
259 259
260 GSM_DateTimeModified; 260 GSM_DateTimeModified;
261 bool ModifiedEmpty; 261 bool ModifiedEmpty;
262 262
263 /* File attributes */ 263 /* File attributes */
264 bool Protected; 264 bool Protected;
265 bool ReadOnly; 265 bool ReadOnly;
266 bool Hidden; 266 bool Hidden;
267 bool System; 267 bool System;
268} GSM_File; 268} GSM_File;
269 269
270GSM_Error GSM_ReadFile(char *FileName, GSM_File *File); 270GSM_Error GSM_ReadFile(char *FileName, GSM_File *File);
271 271
272GSM_Error GSM_JADFindData(GSM_File File, char *Vendor, char *Name, char *JAR, char *Version, int *Size); 272GSM_Error GSM_JADFindData(GSM_File File, char *Vendor, char *Name, char *JAR, char *Version, int *Size);
273 273
274void GSM_IdentifyFileFormat(GSM_File *File); 274void GSM_IdentifyFileFormat(GSM_File *File);
275 275
276typedef struct { 276typedef struct {
277 int Free; 277 int Free;
278 int Used; 278 int Used;
279} GSM_FileSystemStatus; 279} GSM_FileSystemStatus;
280 280
281/* ----------------------------- GPRS access points ----------------------- */ 281/* ----------------------------- GPRS access points ----------------------- */
282 282
283typedef struct { 283typedef struct {
284 int Location; 284 int Location;
285 unsigned char Name[300]; 285 unsigned char Name[300];
286 unsigned char URL[500]; 286 unsigned char URL[500];
287 bool Active; 287 bool Active;
288} GSM_GPRSAccessPoint; 288} GSM_GPRSAccessPoint;
289 289
290/* ------------------------------------------------------------------------ */ 290/* ------------------------------------------------------------------------ */
291 291
292typedef enum { 292typedef enum {
293 GSM_Date_DDMMYYYY = 1, 293 GSM_Date_DDMMYYYY = 1,
294 GSM_Date_MMDDYYYY, 294 GSM_Date_MMDDYYYY,
295 GSM_Date_YYYYMMDD 295 GSM_Date_YYYYMMDD,
296 GSM_Date_DDMMMYY,
297 GSM_Date_MMDDYY,
298 GSM_Date_DDMMYY,
299 GSM_Date_YYMMDD,
300 GSM_Date_OFF
296} GSM_DateFormat; 301} GSM_DateFormat;
297 302
298typedef struct { 303typedef struct {
299 unsigned char DateSeparator; 304 unsigned char DateSeparator;
300 GSM_DateFormatDateFormat; 305 GSM_DateFormatDateFormat;
301 bool AMPMTime; 306 bool AMPMTime;
302} GSM_Locale; 307} GSM_Locale;
303 308
304/* ------------------------------------------------------------------------ */ 309/* ------------------------------------------------------------------------ */
305 310
306void ReadVCALDateTime(char *Buffer, GSM_DateTime *dt); 311void ReadVCALDateTime(char *Buffer, GSM_DateTime *dt);
307void SaveVCALDateTime(char *Buffer, int *Length, GSM_DateTime *Date, char *Start); 312void SaveVCALDateTime(char *Buffer, int *Length, GSM_DateTime *Date, char *Start);
308 313
309void SaveVCALText(char *Buffer, int *Length, char *Text, char *Start); 314void SaveVCALText(char *Buffer, int *Length, char *Text, char *Start);
310bool ReadVCALText(char *Buffer, char *Start, char *Value); 315bool ReadVCALText(char *Buffer, char *Start, char *Value);
311 316
312#endif 317#endif
313 318
314/* How should editor hadle tabs in this file? Add editor commands here. 319/* How should editor hadle tabs in this file? Add editor commands here.
315 * vim: noexpandtab sw=8 ts=8 sts=8: 320 * vim: noexpandtab sw=8 ts=8 sts=8:
316 */ 321 */
diff --git a/gammu/emb/common/service/gsmring.c b/gammu/emb/common/service/gsmring.c
index 7df46f1..dab028c 100644
--- a/gammu/emb/common/service/gsmring.c
+++ b/gammu/emb/common/service/gsmring.c
@@ -1,1036 +1,1077 @@
1/* (c) 2001-2004 by Marcin Wiacek */ 1/* (c) 2001-2004 by Marcin Wiacek */
2/* Based on some work from Ralf Thelen (7110 ringtones), 2/* Based on some work from Ralf Thelen (7110 ringtones) and others */
3 * Gnokii (RTTL and SM) and others 3/* Based on some work (RTTL and SM) from Gnokii (www.gnokii.org)
4 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
5 * GNU GPL version 2 or later
4 */ 6 */
5 7
6#include <stdlib.h> 8#include <stdlib.h>
7#include <string.h> 9#include <string.h>
8#include <ctype.h> 10#include <ctype.h>
9#include <math.h> 11#include <math.h>
12#include <sys/stat.h>
10#ifdef WIN32 13#ifdef WIN32
11# include <windows.h> 14# include <windows.h>
12#endif 15#endif
13 16
14#include "../gsmcomon.h" 17#include "../gsmcomon.h"
15#include "../misc/coding/coding.h" 18#include "../misc/coding/coding.h"
16#include "../gsmstate.h" 19#include "../gsmstate.h"
17#include "gsmring.h" 20#include "gsmring.h"
18#include "sms/gsmsms.h" 21#include "sms/gsmsms.h"
19 22
20int GSM_RingNoteGetFrequency(GSM_RingNote Note) 23int GSM_RingNoteGetFrequency(GSM_RingNote Note)
21{ 24{
22 double freq=0; 25 double freq=0;
23 26
24 /* Values according to the software from http://iki.fi/too/sw/xring/ 27 /* Values according to the software from http://iki.fi/too/sw/xring/
25 * generated with: 28 * generated with:
26 * perl -e 'print int(4400 * (2 **($_/12)) + .5)/10, "\n" for(3..14)' 29 * perl -e 'print int(4400 * (2 **($_/12)) + .5)/10, "\n" for(3..14)'
27 */ 30 */
28 switch (Note.Note) { 31 switch (Note.Note) {
29 case Note_C : freq = 523.3; break; 32 case Note_C : freq = 523.3; break;
30 case Note_Cis: freq = 554.4; break; 33 case Note_Cis: freq = 554.4; break;
31 case Note_D : freq = 587.3; break; 34 case Note_D : freq = 587.3; break;
32 case Note_Dis: freq = 622.3; break; 35 case Note_Dis: freq = 622.3; break;
33 case Note_E : freq = 659.3; break; 36 case Note_E : freq = 659.3; break;
34 case Note_F : freq = 698.5; break; 37 case Note_F : freq = 698.5; break;
35 case Note_Fis: freq = 740; break; 38 case Note_Fis: freq = 740; break;
36 case Note_G : freq = 784; break; 39 case Note_G : freq = 784; break;
37 case Note_Gis: freq = 830.6; break; 40 case Note_Gis: freq = 830.6; break;
38 case Note_A : freq = 880; break; 41 case Note_A : freq = 880; break;
39 case Note_Ais: freq = 932.3; break; 42 case Note_Ais: freq = 932.3; break;
40 case Note_H : freq = 987.8; break; 43 case Note_H : freq = 987.8; break;
41 case Note_Pause: break; 44 case Note_Pause: break;
42 } 45 }
43 switch (Note.Scale) { 46 switch (Note.Scale) {
44 case Scale_440 : freq = freq / 2; break; 47 case Scale_440 : freq = freq / 2; break;
45 case Scale_880 : break; 48 case Scale_880 : break;
46 case Scale_1760: freq = freq * 2; break; 49 case Scale_1760: freq = freq * 2; break;
47 case Scale_3520: freq = freq * 4; break; 50 case Scale_3520: freq = freq * 4; break;
48 default : break; 51 default : break;
49 } 52 }
50 return (int)freq; 53 return (int)freq;
51} 54}
52 55
53int GSM_RingNoteGetFullDuration(GSM_RingNote Note) 56int GSM_RingNoteGetFullDuration(GSM_RingNote Note)
54{ 57{
55 int duration = 1; 58 int duration = 1;
56 59
57 switch (Note.Duration) { 60 switch (Note.Duration) {
58 case Duration_Full : duration = 128; break; 61 case Duration_Full : duration = 128; break;
59 case Duration_1_2 : duration = 64; break; 62 case Duration_1_2 : duration = 64; break;
60 case Duration_1_4 : duration = 32; break; 63 case Duration_1_4 : duration = 32; break;
61 case Duration_1_8 : duration = 16; break; 64 case Duration_1_8 : duration = 16; break;
62 case Duration_1_16 : duration = 8; break; 65 case Duration_1_16 : duration = 8; break;
63 case Duration_1_32 : duration = 4; break; 66 case Duration_1_32 : duration = 4; break;
64 } 67 }
65 switch (Note.DurationSpec) { 68 switch (Note.DurationSpec) {
66 case NoSpecialDuration : break; 69 case NoSpecialDuration : break;
67 case DottedNote : duration = duration * 3/2;break; 70 case DottedNote : duration = duration * 3/2;break;
68 case DoubleDottedNote : duration = duration * 9/4;break; 71 case DoubleDottedNote : duration = duration * 9/4;break;
69 case Length_2_3 : duration = duration * 2/3;break; 72 case Length_2_3 : duration = duration * 2/3;break;
70 } 73 }
71 return duration; 74 return duration;
72} 75}
73 76
74#ifndef PI 77#ifndef PI
75# define PI 3.141592654 78# define PI 3.141592654
76#endif 79#endif
77 80
78#define WAV_SAMPLE_RATE 44100 81#define WAV_SAMPLE_RATE 44100
79 82
80GSM_Error savewav(FILE *file, GSM_Ringtone *ringtone) 83GSM_Error savewav(FILE *file, GSM_Ringtone *ringtone)
81{ 84{
82 unsigned char WAV_Header[] = { 85 unsigned char WAV_Header[] = {
83 'R','I','F','F', 86 'R','I','F','F',
84 0x00,0x00,0x00,0x00,/* Length */ 87 0x00,0x00,0x00,0x00,/* Length */
85 'W','A','V','E'}; 88 'W','A','V','E'};
86 unsigned char FMT_Header[] = {'f','m','t',' ', 89 unsigned char FMT_Header[] = {'f','m','t',' ',
87 0x10,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x44,0xac, 90 0x10,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x44,0xac,
88 0x00,0x00,0x88,0x58,0x01,0x00,0x02,0x00,0x10,0x00}; 91 0x00,0x00,0x88,0x58,0x01,0x00,0x02,0x00,0x10,0x00};
89 unsigned char DATA_Header[] = { 92 unsigned char DATA_Header[] = {
90 'd','a','t','a', 93 'd','a','t','a',
91 0x00,0x00,0x00,0x00};/* Length */ 94 0x00,0x00,0x00,0x00};/* Length */
92 short DATA_Buffer[60000]; 95 short DATA_Buffer[60000];
93 long wavfilesize; 96 long wavfilesize;
94 GSM_RingNote *Note; 97 GSM_RingNote *Note;
95 long i,j,length=0; 98 long i,j,length=0;
96 double phase=0,phase_step; 99 double phase=0,phase_step;
97 100
98 fwrite(&WAV_Header, 1, sizeof(WAV_Header),file); 101 fwrite(&WAV_Header, 1, sizeof(WAV_Header),file);
99 fwrite(&FMT_Header, 1, sizeof(FMT_Header),file); 102 fwrite(&FMT_Header, 1, sizeof(FMT_Header),file);
100 fwrite(&DATA_Header, 1, sizeof(DATA_Header),file); 103 fwrite(&DATA_Header, 1, sizeof(DATA_Header),file);
101 104
102 for (i=0;i<ringtone->NoteTone.NrCommands;i++) { 105 for (i=0;i<ringtone->NoteTone.NrCommands;i++) {
103 if (ringtone->NoteTone.Commands[i].Type == RING_Note) { 106 if (ringtone->NoteTone.Commands[i].Type == RING_Note) {
104 Note = &ringtone->NoteTone.Commands[i].Note; 107 Note = &ringtone->NoteTone.Commands[i].Note;
105 phase_step = GSM_RingNoteGetFrequency(*Note)*WAV_SAMPLE_RATE*1.5; 108 phase_step = GSM_RingNoteGetFrequency(*Note)*WAV_SAMPLE_RATE*1.5;
106 for (j=0;j<((long)(GSM_RingNoteGetFullDuration(*Note)*WAV_SAMPLE_RATE/70));j++) { 109 for (j=0;j<((long)(GSM_RingNoteGetFullDuration(*Note)*WAV_SAMPLE_RATE/70));j++) {
107#ifdef DESKTOP_VERSION 110#ifdef DESKTOP_VERSION
108 DATA_Buffer[j] = ((int)(sin(phase*PI)*50000)); 111 DATA_Buffer[j] = ((int)(sin(phase*PI)*50000));
109#else 112#else
110 // we have no sin on Zaurus 113 // we have no sin on Zaurus
111 DATA_Buffer[j] = ((int)(0.5*50000)); 114 DATA_Buffer[j] = ((int)(0.5*50000));
112#endif 115#endif
113 phase = phase + phase_step; 116 phase = phase + phase_step;
114 length++; 117 length++;
115 } 118 }
116 fwrite(&DATA_Buffer,sizeof(short),j,file); 119 fwrite(&DATA_Buffer,sizeof(short),j,file);
117 } 120 }
118 } 121 }
119 122
120 wavfilesize = sizeof(WAV_Header) + sizeof(FMT_Header) + sizeof(DATA_Header) + length*2; 123 wavfilesize = sizeof(WAV_Header) + sizeof(FMT_Header) + sizeof(DATA_Header) + length*2;
121 WAV_Header[4] = ((unsigned char)wavfilesize % 256); 124 WAV_Header[4] = ((unsigned char)wavfilesize % 256);
122 WAV_Header[5] = ((unsigned char)wavfilesize / 256); 125 WAV_Header[5] = ((unsigned char)wavfilesize / 256);
123 WAV_Header[6] = ((unsigned char)wavfilesize / (256*256)); 126 WAV_Header[6] = ((unsigned char)wavfilesize / (256*256));
124 WAV_Header[7] = ((unsigned char)wavfilesize / (256*256*256)); 127 WAV_Header[7] = ((unsigned char)wavfilesize / (256*256*256));
125 wavfilesize = wavfilesize - 54; 128 wavfilesize = wavfilesize - 54;
126 DATA_Header[4] = ((unsigned char)wavfilesize % 256); 129 DATA_Header[4] = ((unsigned char)wavfilesize % 256);
127 DATA_Header[5] = ((unsigned char)wavfilesize / 256); 130 DATA_Header[5] = ((unsigned char)wavfilesize / 256);
128 DATA_Header[6] = ((unsigned char)wavfilesize / (256*256)); 131 DATA_Header[6] = ((unsigned char)wavfilesize / (256*256));
129 DATA_Header[7] = ((unsigned char)wavfilesize / (256*256*256)); 132 DATA_Header[7] = ((unsigned char)wavfilesize / (256*256*256));
130 133
131 fseek( file, 0, SEEK_SET); 134 fseek( file, 0, SEEK_SET);
132 fwrite(&WAV_Header, 1, sizeof(WAV_Header),file); 135 fwrite(&WAV_Header, 1, sizeof(WAV_Header),file);
133 fwrite(&FMT_Header, 1, sizeof(FMT_Header),file); 136 fwrite(&FMT_Header, 1, sizeof(FMT_Header),file);
134 fwrite(&DATA_Header, 1, sizeof(DATA_Header),file); 137 fwrite(&DATA_Header, 1, sizeof(DATA_Header),file);
135 138
136 return ERR_NONE; 139 return ERR_NONE;
137} 140}
138 141
139static GSM_Error savebin(FILE *file, GSM_Ringtone *ringtone) 142static GSM_Error savebin(FILE *file, GSM_Ringtone *ringtone)
140{ 143{
141 char nullchar=0x00; 144 char nullchar=0x00;
142 145
143 fwrite(&nullchar,1,1,file); 146 fwrite(&nullchar,1,1,file);
144 fwrite(&nullchar,1,1,file); 147 fwrite(&nullchar,1,1,file);
145 fprintf(file,"\x0C\x01\x2C"); 148 fprintf(file,"\x0C\x01\x2C");
146 fprintf(file,"%s",DecodeUnicodeString(ringtone->Name)); 149 fprintf(file,"%s",DecodeUnicodeString(ringtone->Name));
147 fwrite(&nullchar,1,1,file); 150 fwrite(&nullchar,1,1,file);
148 fwrite(&nullchar,1,1,file); 151 fwrite(&nullchar,1,1,file);
149 fwrite(ringtone->NokiaBinary.Frame,1,ringtone->NokiaBinary.Length,file); 152 fwrite(ringtone->NokiaBinary.Frame,1,ringtone->NokiaBinary.Length,file);
150 return ERR_NONE; 153 return ERR_NONE;
151} 154}
152 155
153static GSM_Error savepuremidi(FILE *file, GSM_Ringtone *ringtone) 156static GSM_Error savepuremidi(FILE *file, GSM_Ringtone *ringtone)
154{ 157{
155 fwrite(ringtone->NokiaBinary.Frame,1,ringtone->NokiaBinary.Length,file); 158 fwrite(ringtone->NokiaBinary.Frame,1,ringtone->NokiaBinary.Length,file);
156 return ERR_NONE; 159 return ERR_NONE;
157} 160}
158 161
162static GSM_Error savemmf(FILE *file, GSM_Ringtone *ringtone)
163{
164 fwrite(ringtone->NokiaBinary.Frame,1,ringtone->NokiaBinary.Length,file);
165 return ERR_NONE;
166}
167
159GSM_Error saverttl(FILE *file, GSM_Ringtone *ringtone) 168GSM_Error saverttl(FILE *file, GSM_Ringtone *ringtone)
160{ 169{
161 GSM_RingNoteScaleDefNoteScale; 170 GSM_RingNoteScaleDefNoteScale;
162 GSM_RingNoteDurationDefNoteDuration; 171 GSM_RingNoteDurationDefNoteDuration;
163 172
164 GSM_RingNoteStyleDefNoteStyle=0; 173 GSM_RingNoteStyleDefNoteStyle=0;
165 int DefNoteTempo=0; 174 int DefNoteTempo=0;
166 175
167 bool started = false, firstcomma = true; 176 bool started = false, firstcomma = true;
168 GSM_RingNote *Note; 177 GSM_RingNote *Note;
169 178
170 unsigned char buffer[15]; 179 unsigned char buffer[15];
171 int i,j,k=0; 180 int i,j,k=0;
172 181
173 /* Saves ringtone name */ 182 /* Saves ringtone name */
174 fprintf(file,"%s:",DecodeUnicodeString(ringtone->Name)); 183 fprintf(file,"%s:",DecodeUnicodeString(ringtone->Name));
175 184
176 /* Find the most frequently used duration */ 185 /* Find the most frequently used duration */
177 for (i=0;i<6;i++) buffer[i]=0; 186 for (i=0;i<6;i++) buffer[i]=0;
178 for (i=0;i<ringtone->NoteTone.NrCommands;i++) { 187 for (i=0;i<ringtone->NoteTone.NrCommands;i++) {
179 if (ringtone->NoteTone.Commands[i].Type == RING_Note) { 188 if (ringtone->NoteTone.Commands[i].Type == RING_Note) {
180 Note = &ringtone->NoteTone.Commands[i].Note; 189 Note = &ringtone->NoteTone.Commands[i].Note;
181 /* some durations need 2 bytes in file, some 1 */ 190 /* some durations need 2 bytes in file, some 1 */
182 if (Note->Duration >= Duration_Full && Note->Duration <= Duration_1_8) { 191 if (Note->Duration >= Duration_Full && Note->Duration <= Duration_1_8) {
183 buffer[Note->Duration/32]++; 192 buffer[Note->Duration/32]++;
184 } 193 }
185 if (Note->Duration >= Duration_1_16 && Note->Duration <= Duration_1_32) { 194 if (Note->Duration >= Duration_1_16 && Note->Duration <= Duration_1_32) {
186 buffer[Note->Duration/32]+=2; 195 buffer[Note->Duration/32]+=2;
187 } 196 }
188 } 197 }
189 } 198 }
190 /* Now find the most frequently used */ 199 /* Now find the most frequently used */
191 j=0; 200 j=0;
192 for (i=0;i<6;i++) { 201 for (i=0;i<6;i++) {
193 if (buffer[i]>j) { 202 if (buffer[i]>j) {
194 k=i; 203 k=i;
195 j=buffer[i]; 204 j=buffer[i];
196 } 205 }
197 } 206 }
198 /* Finally convert the default duration */ 207 /* Finally convert the default duration */
199 DefNoteDuration = k * 32; 208 DefNoteDuration = k * 32;
200 dbgprintf("DefNoteDuration=%d\n", DefNoteDuration); 209 dbgprintf("DefNoteDuration=%d\n", DefNoteDuration);
201 switch (DefNoteDuration) { 210 switch (DefNoteDuration) {
202 case Duration_Full:fprintf(file,"d=1"); break; 211 case Duration_Full:fprintf(file,"d=1"); break;
203 case Duration_1_2 :fprintf(file,"d=2"); break; 212 case Duration_1_2 :fprintf(file,"d=2"); break;
204 case Duration_1_4 :fprintf(file,"d=4"); break; 213 case Duration_1_4 :fprintf(file,"d=4"); break;
205 case Duration_1_8 :fprintf(file,"d=8"); break; 214 case Duration_1_8 :fprintf(file,"d=8"); break;
206 case Duration_1_16:fprintf(file,"d=16");break; 215 case Duration_1_16:fprintf(file,"d=16");break;
207 case Duration_1_32:fprintf(file,"d=32");break; 216 case Duration_1_32:fprintf(file,"d=32");break;
208 } 217 }
209 218
210 /* Find the most frequently used scale */ 219 /* Find the most frequently used scale */
211 for (i=0;i<9;i++) buffer[i]=0; 220 for (i=0;i<9;i++) buffer[i]=0;
212 for (i=0;i<ringtone->NoteTone.NrCommands;i++) { 221 for (i=0;i<ringtone->NoteTone.NrCommands;i++) {
213 if (ringtone->NoteTone.Commands[i].Type == RING_Note) { 222 if (ringtone->NoteTone.Commands[i].Type == RING_Note) {
214 Note = &ringtone->NoteTone.Commands[i].Note; 223 Note = &ringtone->NoteTone.Commands[i].Note;
215 if (Note->Note!=Note_Pause && 224 if (Note->Note!=Note_Pause &&
216 Note->Scale >= Scale_55 && Note->Scale <= Scale_14080) { 225 Note->Scale >= Scale_55 && Note->Scale <= Scale_14080) {
217 buffer[Note->Scale - 1]++; 226 buffer[Note->Scale - 1]++;
218 } 227 }
219 } 228 }
220 } 229 }
221 j=0; 230 j=0;
222 for (i=0;i<9;i++) { 231 for (i=0;i<9;i++) {
223 if (buffer[i]>j) { 232 if (buffer[i]>j) {
224 k = i; 233 k = i;
225 j=buffer[i]; 234 j=buffer[i];
226 } 235 }
227 } 236 }
228 DefNoteScale = k + 1; 237 DefNoteScale = k + 1;
229 /* Save the default scale */ 238 /* Save the default scale */
230 fprintf(file,",o=%i,",DefNoteScale); 239 fprintf(file,",o=%i,",DefNoteScale);
231 dbgprintf("DefNoteScale=%d\n", DefNoteScale); 240 dbgprintf("DefNoteScale=%d\n", DefNoteScale);
232 241
233 for (i=0;i<ringtone->NoteTone.NrCommands;i++) { 242 for (i=0;i<ringtone->NoteTone.NrCommands;i++) {
234 if (ringtone->NoteTone.Commands[i].Type != RING_Note) continue; 243 if (ringtone->NoteTone.Commands[i].Type != RING_Note) continue;
235 244
236 Note = &ringtone->NoteTone.Commands[i].Note; 245 Note = &ringtone->NoteTone.Commands[i].Note;
237 246
238 /* Trick from PPM Edit */ 247 /* Trick from PPM Edit */
239 if (Note->DurationSpec == DoubleDottedNote) { 248 if (Note->DurationSpec == DoubleDottedNote) {
240 switch (Note->Duration) { 249 switch (Note->Duration) {
241 case Duration_Full:Note->Duration = Duration_Full;break; 250 case Duration_Full:Note->Duration = Duration_Full;break;
242 case Duration_1_2 :Note->Duration = Duration_Full;break; 251 case Duration_1_2 :Note->Duration = Duration_Full;break;
243 case Duration_1_4 :Note->Duration = Duration_1_2; break; 252 case Duration_1_4 :Note->Duration = Duration_1_2; break;
244 case Duration_1_8 :Note->Duration = Duration_1_4; break; 253 case Duration_1_8 :Note->Duration = Duration_1_4; break;
245 case Duration_1_16:Note->Duration = Duration_1_8; break; 254 case Duration_1_16:Note->Duration = Duration_1_8; break;
246 case Duration_1_32:Note->Duration = Duration_1_16;break; 255 case Duration_1_32:Note->Duration = Duration_1_16;break;
247 } 256 }
248 Note->DurationSpec = NoSpecialDuration; 257 Note->DurationSpec = NoSpecialDuration;
249 } 258 }
250 259
251 if (!started) { 260 if (!started) {
252 DefNoteTempo=Note->Tempo; 261 DefNoteTempo=Note->Tempo;
253 DefNoteStyle=Note->Style; 262 DefNoteStyle=Note->Style;
254 switch (Note->Style) { 263 switch (Note->Style) {
255 case StaccatoStyle: fprintf(file,"s=S,"); break; 264 case StaccatoStyle: fprintf(file,"s=S,"); break;
256 case NaturalStyle : fprintf(file,"s=N,"); break; 265 case NaturalStyle : fprintf(file,"s=N,"); break;
257 case ContinuousStyle : break; 266 case ContinuousStyle : break;
258 } 267 }
259 /* Save the default tempo */ 268 /* Save the default tempo */
260 fprintf(file,"b=%i:",DefNoteTempo); 269 fprintf(file,"b=%i:",DefNoteTempo);
261 dbgprintf("DefNoteTempo=%d\n", DefNoteTempo); 270 dbgprintf("DefNoteTempo=%d\n", DefNoteTempo);
262 started = true; 271 started = true;
263 firstcomma = true; 272 firstcomma = true;
264 } 273 }
265 274
266 if (!started) continue; 275 if (!started) continue;
267 276
268 if (Note->Style!=DefNoteStyle) { 277 if (Note->Style!=DefNoteStyle) {
269 /* And a separator */ 278 /* And a separator */
270 if (!firstcomma) fprintf(file,","); 279 if (!firstcomma) fprintf(file,",");
271 firstcomma = false; 280 firstcomma = false;
272 DefNoteStyle=Note->Style; 281 DefNoteStyle=Note->Style;
273 switch (Note->Style) { 282 switch (Note->Style) {
274 case StaccatoStyle : fprintf(file,"s=S"); break; 283 case StaccatoStyle : fprintf(file,"s=S"); break;
275 case NaturalStyle : fprintf(file,"s=N"); break; 284 case NaturalStyle : fprintf(file,"s=N"); break;
276 case ContinuousStyle: fprintf(file,"s=C"); break; 285 case ContinuousStyle: fprintf(file,"s=C"); break;
277 } 286 }
278 } 287 }
279 if (Note->Tempo!=DefNoteTempo) { 288 if (Note->Tempo!=DefNoteTempo) {
280 /* And a separator */ 289 /* And a separator */
281 if (!firstcomma) fprintf(file,","); 290 if (!firstcomma) fprintf(file,",");
282 firstcomma = false; 291 firstcomma = false;
283 DefNoteTempo=Note->Tempo; 292 DefNoteTempo=Note->Tempo;
284 fprintf(file,"b=%i",DefNoteTempo); 293 fprintf(file,"b=%i",DefNoteTempo);
285 } 294 }
286 /* This note has a duration different than the default. We must save it */ 295 /* This note has a duration different than the default. We must save it */
287 if (Note->Duration!=DefNoteDuration) { 296 if (Note->Duration!=DefNoteDuration) {
288 /* And a separator */ 297 /* And a separator */
289 if (!firstcomma) fprintf(file,","); 298 if (!firstcomma) fprintf(file,",");
290 firstcomma = false; 299 firstcomma = false;
291 switch (Note->Duration) { 300 switch (Note->Duration) {
292 case Duration_Full:fprintf(file,"1"); break; 301 case Duration_Full:fprintf(file,"1"); break;
293 case Duration_1_2 :fprintf(file,"2"); break; 302 case Duration_1_2 :fprintf(file,"2"); break;
294 case Duration_1_4 :fprintf(file,"4"); break; 303 case Duration_1_4 :fprintf(file,"4"); break;
295 case Duration_1_8 :fprintf(file,"8"); break; 304 case Duration_1_8 :fprintf(file,"8"); break;
296 case Duration_1_16:fprintf(file,"16");break; 305 case Duration_1_16:fprintf(file,"16");break;
297 case Duration_1_32:fprintf(file,"32");break; 306 case Duration_1_32:fprintf(file,"32");break;
298 } 307 }
299 } else { 308 } else {
300 /* And a separator */ 309 /* And a separator */
301 if (!firstcomma) fprintf(file,","); 310 if (!firstcomma) fprintf(file,",");
302 firstcomma = false; 311 firstcomma = false;
303 } 312 }
304 /* Now save the actual note */ 313 /* Now save the actual note */
305 switch (Note->Note) { 314 switch (Note->Note) {
306 case Note_C :fprintf(file,"c");break; 315 case Note_C :fprintf(file,"c");break;
307 case Note_Cis:fprintf(file,"c#");break; 316 case Note_Cis:fprintf(file,"c#");break;
308 case Note_D :fprintf(file,"d");break; 317 case Note_D :fprintf(file,"d");break;
309 case Note_Dis:fprintf(file,"d#");break; 318 case Note_Dis:fprintf(file,"d#");break;
310 case Note_E :fprintf(file,"e");break; 319 case Note_E :fprintf(file,"e");break;
311 case Note_F :fprintf(file,"f");break; 320 case Note_F :fprintf(file,"f");break;
312 case Note_Fis:fprintf(file,"f#");break; 321 case Note_Fis:fprintf(file,"f#");break;
313 case Note_G :fprintf(file,"g");break; 322 case Note_G :fprintf(file,"g");break;
314 case Note_Gis:fprintf(file,"g#");break; 323 case Note_Gis:fprintf(file,"g#");break;
315 case Note_A :fprintf(file,"a");break; 324 case Note_A :fprintf(file,"a");break;
316 case Note_Ais:fprintf(file,"a#");break; 325 case Note_Ais:fprintf(file,"a#");break;
317 case Note_H :fprintf(file,"h");break; 326 case Note_H :fprintf(file,"h");break;
318 default :fprintf(file,"p");break; /*Pause ?*/ 327 default :fprintf(file,"p");break; /*Pause ?*/
319 } 328 }
320 switch (Note->DurationSpec) { 329 switch (Note->DurationSpec) {
321 case DottedNote : fprintf(file,".");break; 330 case DottedNote : fprintf(file,".");break;
322 default : break; 331 default : break;
323 } 332 }
324 if (Note->Note!=Note_Pause && Note->Scale != DefNoteScale) { 333 if (Note->Note!=Note_Pause && Note->Scale != DefNoteScale) {
325 fprintf(file,"%i",Note->Scale); 334 fprintf(file,"%i",Note->Scale);
326 } 335 }
327 } 336 }
328 return ERR_NONE; 337 return ERR_NONE;
329} 338}
330 339
331void saveimelody(FILE *file, GSM_Ringtone *ringtone) 340void saveimelody(FILE *file, GSM_Ringtone *ringtone)
332{ 341{
333 char Buffer[2000]; 342 char Buffer[2000];
334 int i=2000; 343 int i=2000;
335 344
336 GSM_EncodeEMSSound(*ringtone, Buffer, &i, (float)1.2, true); 345 GSM_EncodeEMSSound(*ringtone, Buffer, &i, (float)1.2, true);
337 346
338 fwrite(Buffer, 1, i, file); 347 fwrite(Buffer, 1, i, file);
339} 348}
340 349
341#ifndef ENABLE_LGPL 350#ifndef ENABLE_LGPL
342 351
343static void WriteVarLen(unsigned char* midifile, int* current, long value) 352static void WriteVarLen(unsigned char* midifile, int* current, long value)
344{ 353{
345 long buffer; 354 long buffer;
346 355
347 buffer = value & 0x7f; 356 buffer = value & 0x7f;
348 357
349 while (value >>= 7) { 358 while (value >>= 7) {
350 buffer <<= 8; 359 buffer <<= 8;
351 buffer |= 0x80; 360 buffer |= 0x80;
352 buffer += (value & 0x7f); 361 buffer += (value & 0x7f);
353 } 362 }
354 363
355 while (1) { 364 while (1) {
356 midifile[(*current)++] = (unsigned char)buffer; 365 midifile[(*current)++] = (unsigned char)buffer;
357 if (buffer & 0x80) { 366 if (buffer & 0x80) {
358 buffer >>= 8; 367 buffer >>= 8;
359 } else { 368 } else {
360 break; 369 break;
361 } 370 }
362 } 371 }
363} 372}
364 373
365#define singlepauses 374#define singlepauses
366 375
367/* FIXME: need adding tempo before each note and scale too ? */ 376/* FIXME: need adding tempo before each note and scale too ? */
368void savemid(FILE* file, GSM_Ringtone *ringtone) 377void savemid(FILE* file, GSM_Ringtone *ringtone)
369{ 378{
370 int pause = 0, current = 26, duration, i, note=0, length = 20; 379 int pause = 0, current = 26, duration, i, note=0, length = 20;
371 bool started = false; 380 bool started = false;
372 GSM_RingNote *Note; 381 GSM_RingNote *Note;
373 unsigned char midifile[3000] = { 382 unsigned char midifile[3000] = {
374 0x4D, 0x54, 0x68, 0x64, // MThd 383 0x4D, 0x54, 0x68, 0x64, // MThd
375 0x00, 0x00, 0x00, 0x06, // chunk length 384 0x00, 0x00, 0x00, 0x06, // chunk length
376 0x00, 0x00, // format 0 385 0x00, 0x00, // format 0
377 0x00, 0x01, // one track 386 0x00, 0x01, // one track
378 0x00, 0x20, // 32 per quarter note 387 0x00, 0x20, // 32 per quarter note
379 0x4D, 0x54, 0x72, 0x6B, // MTrk 388 0x4D, 0x54, 0x72, 0x6B, // MTrk
380 0x00, 0x00, 0x00, 0x00, // chunk length 389 0x00, 0x00, 0x00, 0x00, // chunk length
381 0x00, 0xFF, 0x51, 0x03, // tempo meta event 390 0x00, 0xFF, 0x51, 0x03, // tempo meta event
382 0x00, 0x00, 0x00}; // 3 bytes for us for a quarter note 391 0x00, 0x00, 0x00}; // 3 bytes for us for a quarter note
383 392
384 for (i = 0; i < ringtone->NoteTone.NrCommands; i++) { 393 for (i = 0; i < ringtone->NoteTone.NrCommands; i++) {
385 if (ringtone->NoteTone.Commands[i].Type == RING_Note) { 394 if (ringtone->NoteTone.Commands[i].Type == RING_Note) {
386 Note = &ringtone->NoteTone.Commands[i].Note; 395 Note = &ringtone->NoteTone.Commands[i].Note;
387 if (!started) { 396 if (!started) {
388 /* readmid does not read pauses at the beginning */ 397 /* readmid does not read pauses at the beginning */
389 if (Note->Note != Note_Pause) { 398 if (Note->Note != Note_Pause) {
390 /* FIXME: we need add tempo before each note or so... */ 399 /* FIXME: we need add tempo before each note or so... */
391 long duration=60000000/Note->Tempo; 400 long duration=60000000/Note->Tempo;
392 401
393 midifile[current++] = (unsigned char)(duration >> 16); 402 midifile[current++] = (unsigned char)(duration >> 16);
394 midifile[current++] = (unsigned char)(duration >> 8); 403 midifile[current++] = (unsigned char)(duration >> 8);
395 midifile[current++] = (unsigned char)duration; 404 midifile[current++] = (unsigned char)duration;
396 405
397 started = true; 406 started = true;
398 } 407 }
399 } 408 }
400 if (!started) continue; 409 if (!started) continue;
401 duration = GSM_RingNoteGetFullDuration(*Note); 410 duration = GSM_RingNoteGetFullDuration(*Note);
402 if (Note->Note == Note_Pause) { 411 if (Note->Note == Note_Pause) {
403 pause += duration; 412 pause += duration;
404#ifdef singlepauses 413#ifdef singlepauses
405 WriteVarLen(midifile,&current,pause); 414 WriteVarLen(midifile,&current,pause);
406 pause=0; 415 pause=0;
407 midifile[current++]=0x00; // pause 416 midifile[current++]=0x00; // pause
408 midifile[current++]=0x00; 417 midifile[current++]=0x00;
409#endif 418#endif
410 } else { 419 } else {
411 if (Note->Note >= Note_C && Note->Note <= Note_H) { 420 if (Note->Note >= Note_C && Note->Note <= Note_H) {
412 note = Note->Note/16 + 12 * Note->Scale - 1; 421 note = Note->Note/16 + 12 * Note->Scale - 1;
413 } 422 }
414 423
415 WriteVarLen(midifile,&current,pause); 424 WriteVarLen(midifile,&current,pause);
416 pause=0; 425 pause=0;
417 midifile[current++]=0x90; // note on 426 midifile[current++]=0x90; // note on
418 midifile[current++]=note; 427 midifile[current++]=note;
419 midifile[current++]=0x64; // forte 428 midifile[current++]=0x64; // forte
420 429
421 WriteVarLen(midifile,&current,duration); 430 WriteVarLen(midifile,&current,duration);
422 midifile[current++]=0x80; // note off 431 midifile[current++]=0x80; // note off
423 midifile[current++]=note; 432 midifile[current++]=note;
424 midifile[current++]=0x64; 433 midifile[current++]=0x64;
425 } 434 }
426 } 435 }
427 } 436 }
428 if (pause) { 437 if (pause) {
429 WriteVarLen(midifile,&current,pause); 438 WriteVarLen(midifile,&current,pause);
430 midifile[current++]=0x00; // pause 439 midifile[current++]=0x00; // pause
431 midifile[current++]=0x00; // 440 midifile[current++]=0x00; //
432 } 441 }
433 midifile[current++] = 0x00; 442 midifile[current++] = 0x00;
434 midifile[current++] = 0xFF; // track end 443 midifile[current++] = 0xFF; // track end
435 midifile[current++] = 0x2F; 444 midifile[current++] = 0x2F;
436 midifile[current++] = 0x00; 445 midifile[current++] = 0x00;
437 midifile[length++] = (current-22) >> 8; 446 midifile[length++] = (current-22) >> 8;
438 midifile[length++] = current-22; 447 midifile[length++] = current-22;
439 448
440 fwrite(midifile,1,current,file); 449 fwrite(midifile,1,current,file);
441} 450}
442 451
443#endif 452#endif
444 453
445void saveott(FILE *file, GSM_Ringtone *ringtone) 454void saveott(FILE *file, GSM_Ringtone *ringtone)
446{ 455{
447 char Buffer[2000]; 456 char Buffer[2000];
448 int i=2000; 457 int i=2000;
449 458
450 GSM_EncodeNokiaRTTLRingtone(*ringtone, Buffer, &i); 459 GSM_EncodeNokiaRTTLRingtone(*ringtone, Buffer, &i);
451 460
452 fwrite(Buffer, 1, i, file); 461 fwrite(Buffer, 1, i, file);
453} 462}
454 463
455GSM_Error GSM_SaveRingtoneFile(char *FileName, GSM_Ringtone *ringtone) 464GSM_Error GSM_SaveRingtoneFile(char *FileName, GSM_Ringtone *ringtone)
456{ 465{
457 FILE *file; 466 FILE *file;
458 467
459 file = fopen(FileName, "wb"); 468 file = fopen(FileName, "wb");
460 if (file == NULL) return ERR_CANTOPENFILE; 469 if (file == NULL) return ERR_CANTOPENFILE;
461 470
462 switch (ringtone->Format) { 471 switch (ringtone->Format) {
463 case RING_NOTETONE: 472 case RING_NOTETONE:
464 if (strstr(FileName,".ott")) { 473 if (strstr(FileName,".ott")) {
465 saveott(file,ringtone); 474 saveott(file,ringtone);
466#ifndef ENABLE_LGPL 475#ifndef ENABLE_LGPL
467 } else if (strstr(FileName,".mid")) { 476 } else if (strstr(FileName,".mid")) {
468 savemid(file,ringtone); 477 savemid(file,ringtone);
469#endif 478#endif
470 } else if (strstr(FileName,".rng")) { 479 } else if (strstr(FileName,".rng")) {
471 saveott(file,ringtone); 480 saveott(file,ringtone);
472 } else if (strstr(FileName,".imy")) { 481 } else if (strstr(FileName,".imy")) {
473 saveimelody(file,ringtone); 482 saveimelody(file,ringtone);
474 } else if (strstr(FileName,".ime")) { 483 } else if (strstr(FileName,".ime")) {
475 saveimelody(file,ringtone); 484 saveimelody(file,ringtone);
476 } else if (strstr(FileName,".wav")) { 485 } else if (strstr(FileName,".wav")) {
477 savewav(file,ringtone); 486 savewav(file,ringtone);
478 } else { 487 } else {
479 saverttl(file, ringtone); 488 saverttl(file, ringtone);
480 } 489 }
481 break; 490 break;
482 case RING_NOKIABINARY: 491 case RING_NOKIABINARY:
483 savebin(file, ringtone); 492 savebin(file, ringtone);
484 break; 493 break;
485 case RING_MIDI: 494 case RING_MIDI:
486 savepuremidi(file, ringtone); 495 savepuremidi(file, ringtone);
487 break; 496 break;
497 case RING_MMF:
498 savemmf(file, ringtone);
499 break;
488 } 500 }
489 501
490 fclose(file); 502 fclose(file);
491 503
492 return ERR_NONE; 504 return ERR_NONE;
493} 505}
494 506
495static GSM_Error loadrttl(FILE *file, GSM_Ringtone *ringtone) 507static GSM_Error loadrttl(FILE *file, GSM_Ringtone *ringtone)
496{ 508{
497 GSM_RingNoteScale DefNoteScale= Scale_880; 509 GSM_RingNoteScale DefNoteScale= Scale_880;
498 GSM_RingNoteDuration DefNoteDuration= Duration_1_4; 510 GSM_RingNoteDuration DefNoteDuration= Duration_1_4;
499 GSM_RingNoteStyle DefNoteStyle= NaturalStyle; 511 GSM_RingNoteStyle DefNoteStyle= NaturalStyle;
500 int DefNoteTempo= 63, i=0; 512 int DefNoteTempo= 63, i=0;
501 513
502 unsigned char buffer[2000],Name[100]; 514 unsigned char buffer[2000],Name[100];
503 GSM_RingNote *Note; 515 GSM_RingNote *Note;
504 516
505 fread(buffer, 2000, 1, file); 517 fread(buffer, 2000, 1, file);
506 518
507 ringtone->NoteTone.NrCommands = 0; 519 ringtone->NoteTone.NrCommands = 0;
508 520
509 /* -------------- name ---------------- */ 521 /* -------------- name ---------------- */
510 while (buffer[i] != ':') { 522 while (buffer[i] != ':') {
511 if (buffer[i] == 0x00) return ERR_NONE; 523 if (buffer[i] == 0x00) return ERR_NONE;
512 i++; 524 i++;
513 } 525 }
514 if (i == 0) { 526 if (i == 0) {
515 /* This is for RTTL ringtones without name. */ 527 /* This is for RTTL ringtones without name. */
516 EncodeUnicode(ringtone->Name,"Gammu",5); 528 EncodeUnicode(ringtone->Name,"Gammu",5);
517 } else { 529 } else {
518 memcpy(Name,buffer,i); 530 memcpy(Name,buffer,i);
519 Name[i] = 0x00; 531 Name[i] = 0x00;
520 EncodeUnicode(ringtone->Name,Name,strlen(Name)); 532 EncodeUnicode(ringtone->Name,Name,strlen(Name));
521 } 533 }
522 i++; 534 i++;
523 535
524 /* --------- section with default ringtone settings ----------- */ 536 /* --------- section with default ringtone settings ----------- */
525 while(1) { 537 while(1) {
526 switch (buffer[i]) { 538 switch (buffer[i]) {
527 case ':': 539 case ':':
528 break; 540 break;
529 case 0x00: 541 case 0x00:
530 return ERR_NONE; 542 return ERR_NONE;
531 case 'd': case 'D': 543 case 'd': case 'D':
532 switch (atoi(buffer+i+2)) { 544 switch (atoi(buffer+i+2)) {
533 case 1: DefNoteDuration = Duration_Full; break; 545 case 1: DefNoteDuration = Duration_Full; break;
534 case 2: DefNoteDuration = Duration_1_2 ; break; 546 case 2: DefNoteDuration = Duration_1_2 ; break;
535 case 4: DefNoteDuration = Duration_1_4 ; break; 547 case 4: DefNoteDuration = Duration_1_4 ; break;
536 case 8: DefNoteDuration = Duration_1_8 ; break; 548 case 8: DefNoteDuration = Duration_1_8 ; break;
537 case 16: DefNoteDuration = Duration_1_16; break; 549 case 16: DefNoteDuration = Duration_1_16; break;
538 case 32: DefNoteDuration = Duration_1_32; break; 550 case 32: DefNoteDuration = Duration_1_32; break;
539 } 551 }
540 break; 552 break;
541 case 'o': case 'O': 553 case 'o': case 'O':
542 switch (atoi(buffer+i+2)) { 554 switch (atoi(buffer+i+2)) {
543 case 4: DefNoteScale = Scale_440 ; break; 555 case 4: DefNoteScale = Scale_440 ; break;
544 case 5: DefNoteScale = Scale_880 ; break; 556 case 5: DefNoteScale = Scale_880 ; break;
545 case 6: DefNoteScale = Scale_1760; break; 557 case 6: DefNoteScale = Scale_1760; break;
546 case 7: DefNoteScale = Scale_3520; break; 558 case 7: DefNoteScale = Scale_3520; break;
547 } 559 }
548 break; 560 break;
549 case 'b': case 'B': 561 case 'b': case 'B':
550 DefNoteTempo=atoi(buffer+i+2); 562 DefNoteTempo=atoi(buffer+i+2);
551 dbgprintf("Tempo = %i\n",DefNoteTempo); 563 dbgprintf("Tempo = %i\n",DefNoteTempo);
552 break; 564 break;
553 case 's': case 'S': 565 case 's': case 'S':
554 switch (buffer[i+1]) { 566 switch (buffer[i+1]) {
555 case 'C': case 'c': DefNoteStyle=ContinuousStyle;break; 567 case 'C': case 'c': DefNoteStyle=ContinuousStyle;break;
556 case 'N': case 'n': DefNoteStyle=NaturalStyle; break; 568 case 'N': case 'n': DefNoteStyle=NaturalStyle; break;
557 case 'S': case 's': DefNoteStyle=StaccatoStyle; break; 569 case 'S': case 's': DefNoteStyle=StaccatoStyle; break;
558 } 570 }
559 switch (buffer[i+2]) { 571 switch (buffer[i+2]) {
560 case 'C': case 'c': DefNoteStyle=ContinuousStyle;break; 572 case 'C': case 'c': DefNoteStyle=ContinuousStyle;break;
561 case 'N': case 'n': DefNoteStyle=NaturalStyle; break; 573 case 'N': case 'n': DefNoteStyle=NaturalStyle; break;
562 case 'S': case 's': DefNoteStyle=StaccatoStyle; break; 574 case 'S': case 's': DefNoteStyle=StaccatoStyle; break;
563 } 575 }
564 break; 576 break;
565 } 577 }
566 while (buffer[i] != ':' && buffer[i] != ',') { 578 while (buffer[i] != ':' && buffer[i] != ',') {
567 if (buffer[i] == 0x00) return ERR_NONE; 579 if (buffer[i] == 0x00) return ERR_NONE;
568 i++; 580 i++;
569 } 581 }
570 if (buffer[i] == ',') i++; 582 if (buffer[i] == ',') i++;
571 if (buffer[i] == ':') break; 583 if (buffer[i] == ':') break;
572 } 584 }
573 dbgprintf("DefNoteDuration=%d\n", DefNoteDuration); 585 dbgprintf("DefNoteDuration=%d\n", DefNoteDuration);
574 dbgprintf("DefNoteScale=%d\n", DefNoteScale); 586 dbgprintf("DefNoteScale=%d\n", DefNoteScale);
575 i++; 587 i++;
576 588
577 /* ------------------------- notes ------------------------------ */ 589 /* ------------------------- notes ------------------------------ */
578 while (buffer[i] != 0x00 && ringtone->NoteTone.NrCommands != MAX_RINGTONE_NOTES) { 590 while (buffer[i] != 0x00 && ringtone->NoteTone.NrCommands != MAX_RINGTONE_NOTES) {
579 switch(buffer[i]) { 591 switch(buffer[i]) {
580 case 'z': case 'Z': 592 case 'z': case 'Z':
581 switch (buffer[i+1]) { 593 switch (buffer[i+1]) {
582 case 'd': 594 case 'd':
583 ringtone->NoteTone.Commands[ringtone->NoteTone.NrCommands].Type = RING_DisableLED; 595 ringtone->NoteTone.Commands[ringtone->NoteTone.NrCommands].Type = RING_DisableLED;
584 ringtone->NoteTone.NrCommands++; 596 ringtone->NoteTone.NrCommands++;
585 break; 597 break;
586 case 'D': 598 case 'D':
587 ringtone->NoteTone.Commands[ringtone->NoteTone.NrCommands].Type = RING_EnableLED; 599 ringtone->NoteTone.Commands[ringtone->NoteTone.NrCommands].Type = RING_EnableLED;
588 ringtone->NoteTone.NrCommands++; 600 ringtone->NoteTone.NrCommands++;
589 break; 601 break;
590 case 'v': 602 case 'v':
591 ringtone->NoteTone.Commands[ringtone->NoteTone.NrCommands].Type = RING_DisableVibra; 603 ringtone->NoteTone.Commands[ringtone->NoteTone.NrCommands].Type = RING_DisableVibra;
592 ringtone->NoteTone.NrCommands++; 604 ringtone->NoteTone.NrCommands++;
593 break; 605 break;
594 case 'V': 606 case 'V':
595 ringtone->NoteTone.Commands[ringtone->NoteTone.NrCommands].Type = RING_EnableVibra; 607 ringtone->NoteTone.Commands[ringtone->NoteTone.NrCommands].Type = RING_EnableVibra;
596 ringtone->NoteTone.NrCommands++; 608 ringtone->NoteTone.NrCommands++;
597 break; 609 break;
598 case 'l': 610 case 'l':
599 ringtone->NoteTone.Commands[ringtone->NoteTone.NrCommands].Type = RING_DisableLight; 611 ringtone->NoteTone.Commands[ringtone->NoteTone.NrCommands].Type = RING_DisableLight;
600 ringtone->NoteTone.NrCommands++; 612 ringtone->NoteTone.NrCommands++;
601 break; 613 break;
602 case 'L': 614 case 'L':
603 ringtone->NoteTone.Commands[ringtone->NoteTone.NrCommands].Type = RING_EnableLight; 615 ringtone->NoteTone.Commands[ringtone->NoteTone.NrCommands].Type = RING_EnableLight;
604 ringtone->NoteTone.NrCommands++; 616 ringtone->NoteTone.NrCommands++;
605 } 617 }
606 break; 618 break;
607 case 'o': case 'O': 619 case 'o': case 'O':
608 switch (buffer[i+2]) { 620 switch (buffer[i+2]) {
609 case 4: DefNoteScale = Scale_440 ; break; 621 case 4: DefNoteScale = Scale_440 ; break;
610 case 5: DefNoteScale = Scale_880 ; break; 622 case 5: DefNoteScale = Scale_880 ; break;
611 case 6: DefNoteScale = Scale_1760; break; 623 case 6: DefNoteScale = Scale_1760; break;
612 case 7: DefNoteScale = Scale_3520; break; 624 case 7: DefNoteScale = Scale_3520; break;
613 } 625 }
614 break; 626 break;
615 case 's': case 'S': 627 case 's': case 'S':
616 switch (buffer[i+1]) { 628 switch (buffer[i+1]) {
617 case 'C': case 'c': DefNoteStyle=ContinuousStyle;break; 629 case 'C': case 'c': DefNoteStyle=ContinuousStyle;break;
618 case 'N': case 'n': DefNoteStyle=NaturalStyle; break; 630 case 'N': case 'n': DefNoteStyle=NaturalStyle; break;
619 case 'S': case 's': DefNoteStyle=StaccatoStyle; break; 631 case 'S': case 's': DefNoteStyle=StaccatoStyle; break;
620 } 632 }
621 switch (buffer[i+2]) { 633 switch (buffer[i+2]) {
622 case 'C': case 'c': DefNoteStyle=ContinuousStyle;break; 634 case 'C': case 'c': DefNoteStyle=ContinuousStyle;break;
623 case 'N': case 'n': DefNoteStyle=NaturalStyle; break; 635 case 'N': case 'n': DefNoteStyle=NaturalStyle; break;
624 case 'S': case 's': DefNoteStyle=StaccatoStyle; break; 636 case 'S': case 's': DefNoteStyle=StaccatoStyle; break;
625 } 637 }
626 break; 638 break;
627 default: 639 default:
628 ringtone->NoteTone.Commands[ringtone->NoteTone.NrCommands].Type = RING_Note; 640 ringtone->NoteTone.Commands[ringtone->NoteTone.NrCommands].Type = RING_Note;
629 Note = &ringtone->NoteTone.Commands[ringtone->NoteTone.NrCommands].Note; 641 Note = &ringtone->NoteTone.Commands[ringtone->NoteTone.NrCommands].Note;
630 Note->Style = DefNoteStyle; 642 Note->Style = DefNoteStyle;
631 Note->Tempo = DefNoteTempo; 643 Note->Tempo = DefNoteTempo;
632 Note->Scale = DefNoteScale; 644 Note->Scale = DefNoteScale;
633 Note->Duration = DefNoteDuration; 645 Note->Duration = DefNoteDuration;
634 Note->DurationSpec = NoSpecialDuration; 646 Note->DurationSpec = NoSpecialDuration;
635 Note->Note = Note_Pause; 647 Note->Note = Note_Pause;
636 648
637 /* Duration */ 649 /* Duration */
638 switch (atoi(buffer+i)) { 650 switch (atoi(buffer+i)) {
639 case 1: Note->Duration = Duration_Full ; break; 651 case 1: Note->Duration = Duration_Full ; break;
640 case 2: Note->Duration = Duration_1_2 ; break; 652 case 2: Note->Duration = Duration_1_2 ; break;
641 case 4: Note->Duration = Duration_1_4 ; break; 653 case 4: Note->Duration = Duration_1_4 ; break;
642 case 8: Note->Duration = Duration_1_8 ; break; 654 case 8: Note->Duration = Duration_1_8 ; break;
643 case 16: Note->Duration = Duration_1_16 ; break; 655 case 16: Note->Duration = Duration_1_16 ; break;
644 case 32: Note->Duration = Duration_1_32 ; break; 656 case 32: Note->Duration = Duration_1_32 ; break;
645 } 657 }
646 /* We skip all numbers from duration specification */ 658 /* We skip all numbers from duration specification */
647 while(isdigit(buffer[i])) i++; 659 while(isdigit(buffer[i])) i++;
648 660
649 /* Some files can have special duration here */ 661 /* Some files can have special duration here */
650 if (buffer[i]=='.') { 662 if (buffer[i]=='.') {
651 Note->DurationSpec = DottedNote; 663 Note->DurationSpec = DottedNote;
652 i++; 664 i++;
653 } 665 }
654 666
655 /* Note */ 667 /* Note */
656 /* B or b is not in specs, but I decided to put it, because 668 /* B or b is not in specs, but I decided to put it, because
657 * it's in some RTTL files. It's the same to H note */ 669 * it's in some RTTL files. It's the same to H note */
658 switch (buffer[i]) { 670 switch (buffer[i]) {
659 case 'A': case 'a': Note->Note = Note_A; break; 671 case 'A': case 'a': Note->Note = Note_A; break;
660 case 'B': case 'b': Note->Note = Note_H; break; 672 case 'B': case 'b': Note->Note = Note_H; break;
661 case 'C': case 'c': Note->Note = Note_C; break; 673 case 'C': case 'c': Note->Note = Note_C; break;
662 case 'D': case 'd': Note->Note = Note_D; break; 674 case 'D': case 'd': Note->Note = Note_D; break;
663 case 'E': case 'e': Note->Note = Note_E; break; 675 case 'E': case 'e': Note->Note = Note_E; break;
664 case 'F': case 'f': Note->Note = Note_F; break; 676 case 'F': case 'f': Note->Note = Note_F; break;
665 case 'G': case 'g': Note->Note = Note_G; break; 677 case 'G': case 'g': Note->Note = Note_G; break;
666 case 'H': case 'h': Note->Note = Note_H; break; 678 case 'H': case 'h': Note->Note = Note_H; break;
667 } 679 }
668 i++; 680 i++;
669 681
670 if (buffer[i]=='#') { 682 if (buffer[i]=='#') {
671 switch (Note->Note) { 683 switch (Note->Note) {
672 case Note_A : Note->Note = Note_Ais; break; 684 case Note_A : Note->Note = Note_Ais; break;
673 case Note_C : Note->Note = Note_Cis; break; 685 case Note_C : Note->Note = Note_Cis; break;
674 case Note_D : Note->Note = Note_Dis; break; 686 case Note_D : Note->Note = Note_Dis; break;
675 case Note_F : Note->Note = Note_Fis; break; 687 case Note_F : Note->Note = Note_Fis; break;
676 case Note_G : Note->Note = Note_Gis; break; 688 case Note_G : Note->Note = Note_Gis; break;
677 default : break; 689 default : break;
678 } 690 }
679 i++; 691 i++;
680 } 692 }
681 693
682 /* Some files can have special duration here */ 694 /* Some files can have special duration here */
683 if (buffer[i]=='.') { 695 if (buffer[i]=='.') {
684 Note->DurationSpec = DottedNote; 696 Note->DurationSpec = DottedNote;
685 i++; 697 i++;
686 } 698 }
687 699
688 /* Scale */ 700 /* Scale */
689 if (Note->Note!=Note_Pause && isdigit(buffer[i])) { 701 if (Note->Note!=Note_Pause && isdigit(buffer[i])) {
690 switch (atoi(buffer+i)) { 702 switch (atoi(buffer+i)) {
691 case 4: Note->Scale = Scale_440 ; break; 703 case 4: Note->Scale = Scale_440 ; break;
692 case 5: Note->Scale = Scale_880 ; break; 704 case 5: Note->Scale = Scale_880 ; break;
693 case 6: Note->Scale = Scale_1760; break; 705 case 6: Note->Scale = Scale_1760; break;
694 case 7: Note->Scale = Scale_3520; break; 706 case 7: Note->Scale = Scale_3520; break;
695 } 707 }
696 i++; 708 i++;
697 } 709 }
698 710
699 ringtone->NoteTone.NrCommands++; 711 ringtone->NoteTone.NrCommands++;
700 break; 712 break;
701 } 713 }
702 while (buffer[i] != ',') { 714 while (buffer[i] != ',') {
703 if (buffer[i] == 0x00) return ERR_NONE; 715 if (buffer[i] == 0x00) return ERR_NONE;
704 i++; 716 i++;
705 } 717 }
706 if (buffer[i] == ',') i++; 718 if (buffer[i] == ',') i++;
707 } 719 }
708 720
709 return ERR_NONE; 721 return ERR_NONE;
710} 722}
711 723
712static GSM_Error loadott(FILE *file, GSM_Ringtone *ringtone) 724static GSM_Error loadott(FILE *file, GSM_Ringtone *ringtone)
713{ 725{
714 char Buffer[2000]; 726 char Buffer[2000];
715 int i; 727 int i;
716 728
717 i=fread(Buffer, 1, 2000, file); 729 i=fread(Buffer, 1, 2000, file);
718 730
719 return GSM_DecodeNokiaRTTLRingtone(ringtone, Buffer, i); 731 return GSM_DecodeNokiaRTTLRingtone(ringtone, Buffer, i);
720} 732}
721 733
722static GSM_Error loadcommunicator(FILE *file, GSM_Ringtone *ringtone) 734static GSM_Error loadcommunicator(FILE *file, GSM_Ringtone *ringtone)
723{ 735{
724 char Buffer[4000]; 736 char Buffer[4000];
725 int i,j; 737 int i,j;
726 738
727 i=fread(Buffer, 1, 4000, file); 739 i=fread(Buffer, 1, 4000, file);
728 740
729 i=0;j=0; 741 i=0;j=0;
730 while (true) { 742 while (true) {
731 if (Buffer[j] ==0x00 && Buffer[j+1]==0x02 && 743 if (Buffer[j] ==0x00 && Buffer[j+1]==0x02 &&
732 Buffer[j+2]==0x4a && Buffer[j+3]==0x3a) break; 744 Buffer[j+2]==0x4a && Buffer[j+3]==0x3a) break;
733 if (j==i-4) return ERR_UNKNOWN; 745 if (j==i-4) return ERR_UNKNOWN;
734 j++; 746 j++;
735 } 747 }
736 j++; 748 j++;
737 749
738 return GSM_DecodeNokiaRTTLRingtone(ringtone, Buffer+j, i-j); 750 return GSM_DecodeNokiaRTTLRingtone(ringtone, Buffer+j, i-j);
739} 751}
740 752
741static GSM_Error loadbin(FILE *file, GSM_Ringtone *ringtone) 753static GSM_Error loadbin(FILE *file, GSM_Ringtone *ringtone)
742{ 754{
743 int i; 755 int i;
744 unsigned charbuffer[2000]; 756 unsigned charbuffer[2000];
745 757
746 dbgprintf("loading binary\n"); 758 dbgprintf("loading binary\n");
747 ringtone->NokiaBinary.Length=fread(buffer, 1, 500, file); 759 ringtone->NokiaBinary.Length=fread(buffer, 1, 500, file);
748 i=5; 760 i=5;
749 while (buffer[i]!=0x00) i++; 761 while (buffer[i]!=0x00) i++;
750 EncodeUnicode(ringtone->Name,buffer+5,i-5); 762 EncodeUnicode(ringtone->Name,buffer+5,i-5);
751 while (buffer[i]!=0x02 && buffer[i+1]!=0xFC && buffer[i+2]!=0x09) { 763 while (buffer[i]!=0x02 && buffer[i+1]!=0xFC && buffer[i+2]!=0x09) {
752 i++; 764 i++;
753 } 765 }
754 ringtone->NokiaBinary.Length=ringtone->NokiaBinary.Length-i; 766 ringtone->NokiaBinary.Length=ringtone->NokiaBinary.Length-i;
755 memcpy(ringtone->NokiaBinary.Frame,buffer+i,ringtone->NokiaBinary.Length); 767 memcpy(ringtone->NokiaBinary.Frame,buffer+i,ringtone->NokiaBinary.Length);
756 dbgprintf("Length %i name \"%s\"\n",ringtone->NokiaBinary.Length,DecodeUnicodeString(ringtone->Name)); 768 dbgprintf("Length %i name \"%s\"\n",ringtone->NokiaBinary.Length,DecodeUnicodeString(ringtone->Name));
757 return ERR_NONE; 769 return ERR_NONE;
758} 770}
759 771
760static GSM_Error loadpuremidi(FILE *file, GSM_Ringtone *ringtone) 772static GSM_Error loadpuremidi(FILE *file, GSM_Ringtone *ringtone)
761{ 773{
762 unsigned char buffer[30000]; 774 unsigned char buffer[30000];
763 775
764 dbgprintf("loading midi\n"); 776 dbgprintf("loading midi\n");
765 EncodeUnicode(ringtone->Name,"MIDI",4); 777 EncodeUnicode(ringtone->Name,"MIDI",4);
766 ringtone->NokiaBinary.Length=fread(buffer, 1, 30000, file); 778 ringtone->NokiaBinary.Length=fread(buffer, 1, 30000, file);
767 memcpy(ringtone->NokiaBinary.Frame,buffer,ringtone->NokiaBinary.Length); 779 memcpy(ringtone->NokiaBinary.Frame,buffer,ringtone->NokiaBinary.Length);
768 dbgprintf("Length %i name \"%s\"\n",ringtone->NokiaBinary.Length,DecodeUnicodeString(ringtone->Name)); 780 dbgprintf("Length %i name \"%s\"\n",ringtone->NokiaBinary.Length,DecodeUnicodeString(ringtone->Name));
769 return ERR_NONE; 781 return ERR_NONE;
770} 782}
771 783
784static GSM_Error loadmmf(FILE *file, GSM_Ringtone *ringtone)
785{
786 struct stat st;
787 char *buffer;
788 int length;
789
790 dbgprintf("loading smaf file\n");
791 fstat(fileno(file), &st);
792 ringtone->BinaryTone.Length = length = st.st_size;
793 ringtone->BinaryTone.Buffer = buffer = malloc(length);
794 if (buffer == NULL)
795 return ERR_MOREMEMORY;
796 fread(buffer, 1, length, file);
797
798 dbgprintf("Length %i name \"%s\"\n", length,
799 DecodeUnicodeString(ringtone->Name));
800
801 return ERR_NONE;
802}
803
772static GSM_Error loadre(FILE *file, GSM_Ringtone *ringtone) 804static GSM_Error loadre(FILE *file, GSM_Ringtone *ringtone)
773{ 805{
774 unsigned char buffer[2000]; 806 unsigned char buffer[2000];
775 807
776 ringtone->NokiaBinary.Length=fread(buffer, 1, 500, file); 808 ringtone->NokiaBinary.Length=fread(buffer, 1, 500, file);
777 809
778 if (buffer[18]==0x00 && buffer[21]!=0x02) { 810 if (buffer[18]==0x00 && buffer[21]!=0x02) {
779 /* DCT3, Unicode subformat, 62xx & 7110 */ 811 /* DCT3, Unicode subformat, 62xx & 7110 */
780 CopyUnicodeString(ringtone->Name,buffer+18); 812 CopyUnicodeString(ringtone->Name,buffer+18);
781 ringtone->NokiaBinary.Length = ringtone->NokiaBinary.Length - (21+UnicodeLength(ringtone->Name)*2); 813 ringtone->NokiaBinary.Length = ringtone->NokiaBinary.Length - (21+UnicodeLength(ringtone->Name)*2);
782 memcpy(ringtone->NokiaBinary.Frame,buffer+21+UnicodeLength(ringtone->Name)*2,ringtone->NokiaBinary.Length); 814 memcpy(ringtone->NokiaBinary.Frame,buffer+21+UnicodeLength(ringtone->Name)*2,ringtone->NokiaBinary.Length);
783 } else { 815 } else {
784 /* DCT3, normal subformat, 32xx/33xx/51xx/5210/5510/61xx/8xxx */ 816 /* DCT3, normal subformat, 32xx/33xx/51xx/5210/5510/61xx/8xxx */
785 EncodeUnicode(ringtone->Name,buffer+17,buffer[16]); 817 EncodeUnicode(ringtone->Name,buffer+17,buffer[16]);
786 ringtone->NokiaBinary.Length = ringtone->NokiaBinary.Length - (19+UnicodeLength(ringtone->Name)); 818 ringtone->NokiaBinary.Length = ringtone->NokiaBinary.Length - (19+UnicodeLength(ringtone->Name));
787 memcpy(ringtone->NokiaBinary.Frame,buffer+19+UnicodeLength(ringtone->Name),ringtone->NokiaBinary.Length); 819 memcpy(ringtone->NokiaBinary.Frame,buffer+19+UnicodeLength(ringtone->Name),ringtone->NokiaBinary.Length);
788 } 820 }
789 dbgprintf("Name \"%s\"\n",DecodeUnicodeString(ringtone->Name)); 821 dbgprintf("Name \"%s\"\n",DecodeUnicodeString(ringtone->Name));
790 return ERR_NONE; 822 return ERR_NONE;
791} 823}
792 824
793GSM_Error GSM_ReadRingtoneFile(char *FileName, GSM_Ringtone *ringtone) 825GSM_Error GSM_ReadRingtoneFile(char *FileName, GSM_Ringtone *ringtone)
794{ 826{
795 FILE *file; 827 FILE *file;
796 unsigned charbuffer[300]; 828 unsigned charbuffer[300];
797 GSM_Errorerror = ERR_UNKNOWN; 829 GSM_Errorerror = ERR_UNKNOWN;
798 830
799 dbgprintf("Loading ringtone %s\n",FileName); 831 dbgprintf("Loading ringtone %s\n",FileName);
800 file = fopen(FileName, "rb"); 832 file = fopen(FileName, "rb");
801 if (file == NULL) return ERR_CANTOPENFILE; 833 if (file == NULL) return ERR_CANTOPENFILE;
802 834
803 /* Read the header of the file. */ 835 /* Read the header of the file. */
804 fread(buffer, 1, 4, file); 836 fread(buffer, 1, 4, file);
805 if (ringtone->Format == 0x00) { 837 if (ringtone->Format == 0x00) {
806 ringtone->Format = RING_NOTETONE; 838 ringtone->Format = RING_NOTETONE;
807 if (buffer[0]==0x00 && buffer[1]==0x00 && 839 if (buffer[0]==0x00 && buffer[1]==0x00 &&
808 buffer[2]==0x0C && buffer[3]==0x01) { 840 buffer[2]==0x0C && buffer[3]==0x01) {
809 ringtone->Format = RING_NOKIABINARY; 841 ringtone->Format = RING_NOKIABINARY;
810 } 842 }
811 if (buffer[0]==0x00 && buffer[1]==0x00 && 843 if (buffer[0]==0x00 && buffer[1]==0x00 &&
812 buffer[2]==0x00) { 844 buffer[2]==0x00) {
813 ringtone->Format = RING_NOKIABINARY; 845 ringtone->Format = RING_NOKIABINARY;
814 } 846 }
815 if (buffer[0]==0x4D && buffer[1]==0x54 && 847 if (buffer[0]==0x4D && buffer[1]==0x54 &&
816 buffer[2]==0x68 && buffer[3]==0x64) { 848 buffer[2]==0x68 && buffer[3]==0x64) {
817 ringtone->Format = RING_MIDI; 849 ringtone->Format = RING_MIDI;
818 } 850 }
851 if (buffer[0]==0x4D && buffer[1]==0x4D &&
852 buffer[2]==0x4D && buffer[3]==0x44) {
853 ringtone->Format = RING_MMF;
854 }
819 } 855 }
820 rewind(file); 856 rewind(file);
821 switch (ringtone->Format) { 857 switch (ringtone->Format) {
822 case RING_NOTETONE: 858 case RING_NOTETONE:
823 if (buffer[0]==0x02 && buffer[1]==0x4A) { 859 if (buffer[0]==0x02 && buffer[1]==0x4A) {
824 error=loadott(file,ringtone); 860 error=loadott(file,ringtone);
825 } else if (buffer[0]==0xC7 && buffer[1]==0x45) { 861 } else if (buffer[0]==0xC7 && buffer[1]==0x45) {
826 error=loadcommunicator(file,ringtone); 862 error=loadcommunicator(file,ringtone);
827 } else { 863 } else {
828 error=loadrttl(file,ringtone); 864 error=loadrttl(file,ringtone);
829 } 865 }
830 ringtone->NoteTone.AllNotesScale=false; 866 ringtone->NoteTone.AllNotesScale=false;
831 break; 867 break;
832 case RING_NOKIABINARY: 868 case RING_NOKIABINARY:
833 if (buffer[0]==0x00 && buffer[1]==0x00 && 869 if (buffer[0]==0x00 && buffer[1]==0x00 &&
834 buffer[2]==0x0C && buffer[3]==0x01) { 870 buffer[2]==0x0C && buffer[3]==0x01) {
835 error=loadbin(file,ringtone); 871 error=loadbin(file,ringtone);
836 } 872 }
837 if (buffer[0]==0x00 && buffer[1]==0x00 && 873 if (buffer[0]==0x00 && buffer[1]==0x00 &&
838 buffer[2]==0x00) { 874 buffer[2]==0x00) {
839 error=loadre(file,ringtone); 875 error=loadre(file,ringtone);
840 } 876 }
841 break; 877 break;
842 case RING_MIDI: 878 case RING_MIDI:
843 EncodeUnicode(ringtone->Name,FileName,strlen(FileName)); 879 EncodeUnicode(ringtone->Name,FileName,strlen(FileName));
844 error = loadpuremidi(file,ringtone); 880 error = loadpuremidi(file,ringtone);
881 break;
882 case RING_MMF:
883 EncodeUnicode(ringtone->Name,FileName,strlen(FileName));
884 error = loadmmf(file,ringtone);
885 break;
845 } 886 }
846 fclose(file); 887 fclose(file);
847 return(error); 888 return(error);
848} 889}
849 890
850/* -------------------------- required with Nokia & RTTL ------------------- */ 891/* -------------------------- required with Nokia & RTTL ------------------- */
851 892
852/* Beats per Minute like written in Smart Messaging */ 893/* Beats per Minute like written in Smart Messaging */
853static int SM_BeatsPerMinute[] = { 894static int SM_BeatsPerMinute[] = {
854 25, 28, 31, 35, 40, 45, 50, 56, 63,70, 895 25, 28, 31, 35, 40, 45, 50, 56, 63,70,
855 80, 90, 100, 112, 125, 140, 160, 180, 200,225, 896 80, 90, 100, 112, 125, 140, 160, 180, 200,225,
856 250, 285, 320, 355, 400, 450, 500, 565, 635,715, 897 250, 285, 320, 355, 400, 450, 500, 565, 635,715,
857 800,900 898 800,900
858}; 899};
859 900
860int GSM_RTTLGetTempo(int Beats) 901int GSM_RTTLGetTempo(int Beats)
861{ 902{
862 int i=0; 903 int i=0;
863 904
864 while (Beats > SM_BeatsPerMinute[i] && SM_BeatsPerMinute[i] != 900) i++; 905 while (Beats > SM_BeatsPerMinute[i] && SM_BeatsPerMinute[i] != 900) i++;
865 906
866 return i<<3; 907 return i<<3;
867} 908}
868 909
869/* This function packs the ringtone from the structure "ringtone" to 910/* This function packs the ringtone from the structure "ringtone" to
870 "package", where maxlength means length of package. 911 "package", where maxlength means length of package.
871 Function returns number of packed notes and change maxlength to 912 Function returns number of packed notes and change maxlength to
872 number of used chars in "package" */ 913 number of used chars in "package" */
873unsigned char GSM_EncodeNokiaRTTLRingtone(GSM_Ringtone ringtone, unsigned char *package, int *maxlength) 914unsigned char GSM_EncodeNokiaRTTLRingtone(GSM_Ringtone ringtone, unsigned char *package, int *maxlength)
874{ 915{
875 unsigned char CommandLength = 0x02; 916 unsigned char CommandLength = 0x02;
876 unsigned char Loop = 0x15;/* Infinite */ 917 unsigned char Loop = 0x15;/* Infinite */
877 918
878 unsigned char Buffer[200]; 919 unsigned char Buffer[200];
879 int StartBit=0, OldStartBit; 920 int StartBit=0, OldStartBit;
880 int StartBitHowManyCommands; 921 int StartBitHowManyCommands;
881 int HowManyCommands = 0;/* How many instructions packed */ 922 int HowManyCommands = 0;/* How many instructions packed */
882 int HowManyNotes= 0; 923 int HowManyNotes= 0;
883 int i,j; 924 int i,j;
884 bool started; 925 bool started;
885 GSM_RingNote *Note; 926 GSM_RingNote *Note;
886 927
887 GSM_RingNoteScale DefScale = 255; 928 GSM_RingNoteScale DefScale = 255;
888 GSM_RingNoteStyle DefStyle = 255; 929 GSM_RingNoteStyle DefStyle = 255;
889 int DefTempo = 255; 930 int DefTempo = 255;
890 931
891 AddBufferByte(package, &StartBit, CommandLength, 8); 932 AddBufferByte(package, &StartBit, CommandLength, 8);
892 AddBufferByte(package, &StartBit, SM_Command_RingingToneProgramming, 7); 933 AddBufferByte(package, &StartBit, SM_Command_RingingToneProgramming, 7);
893 934
894 /* According to specification we need have next part octet-aligned */ 935 /* According to specification we need have next part octet-aligned */
895 BufferAlign(package, &StartBit); 936 BufferAlign(package, &StartBit);
896 937
897 AddBufferByte(package, &StartBit, SM_Command_Sound, 7); 938 AddBufferByte(package, &StartBit, SM_Command_Sound, 7);
898 AddBufferByte(package, &StartBit, SM_Song_BasicSongType, 3); 939 AddBufferByte(package, &StartBit, SM_Song_BasicSongType, 3);
899 940
900 /* Packing the name of the tune. */ 941 /* Packing the name of the tune. */
901 EncodeUnicodeSpecialNOKIAChars(Buffer, ringtone.Name, UnicodeLength(ringtone.Name)); 942 EncodeUnicodeSpecialNOKIAChars(Buffer, ringtone.Name, UnicodeLength(ringtone.Name));
902 AddBufferByte(package, &StartBit, ((unsigned char)(UnicodeLength(Buffer)<<4)), 4); 943 AddBufferByte(package, &StartBit, ((unsigned char)(UnicodeLength(Buffer)<<4)), 4);
903 AddBuffer(package, &StartBit, DecodeUnicodeString(Buffer), 8*UnicodeLength(Buffer)); 944 AddBuffer(package, &StartBit, DecodeUnicodeString(Buffer), 8*UnicodeLength(Buffer));
904 945
905 /* Packing info about song pattern */ 946 /* Packing info about song pattern */
906 AddBufferByte(package, &StartBit, 0x01, 8); //one pattern 947 AddBufferByte(package, &StartBit, 0x01, 8); //one pattern
907 AddBufferByte(package, &StartBit, SM_InstructionID_PatternHeaderId, 3); 948 AddBufferByte(package, &StartBit, SM_InstructionID_PatternHeaderId, 3);
908 AddBufferByte(package, &StartBit, SM_PatternID_A_part, 2); 949 AddBufferByte(package, &StartBit, SM_PatternID_A_part, 2);
909 AddBufferByte(package, &StartBit, ((unsigned char)(Loop<<4)), 4); 950 AddBufferByte(package, &StartBit, ((unsigned char)(Loop<<4)), 4);
910 951
911 /* Later here will be HowManyCommands */ 952 /* Later here will be HowManyCommands */
912 StartBitHowManyCommands=StartBit; 953 StartBitHowManyCommands=StartBit;
913 StartBit = StartBit + 8; 954 StartBit = StartBit + 8;
914 955
915 started = false; 956 started = false;
916 for (i=0; i<ringtone.NoteTone.NrCommands; i++) { 957 for (i=0; i<ringtone.NoteTone.NrCommands; i++) {
917 if (ringtone.NoteTone.Commands[i].Type != RING_Note) { 958 if (ringtone.NoteTone.Commands[i].Type != RING_Note) {
918 HowManyNotes++; 959 HowManyNotes++;
919 continue; 960 continue;
920 } 961 }
921 Note = &ringtone.NoteTone.Commands[i].Note; 962 Note = &ringtone.NoteTone.Commands[i].Note;
922 if (!started) { 963 if (!started) {
923 /* First note can't be Pause - it makes problems 964 /* First note can't be Pause - it makes problems
924 * for example with PC Composer 965 * for example with PC Composer
925 */ 966 */
926 if (Note->Note != Note_Pause) started = true; 967 if (Note->Note != Note_Pause) started = true;
927 } 968 }
928 if (!started) { 969 if (!started) {
929 HowManyNotes++; 970 HowManyNotes++;
930 continue; 971 continue;
931 } 972 }
932 OldStartBit = StartBit; 973 OldStartBit = StartBit;
933 /* we don't write Scale & Style info before "Pause" note - it saves place */ 974 /* we don't write Scale & Style info before "Pause" note - it saves place */
934 if (Note->Note!=Note_Pause) { 975 if (Note->Note!=Note_Pause) {
935 if (DefScale != Note->Scale || ringtone.NoteTone.AllNotesScale) { 976 if (DefScale != Note->Scale || ringtone.NoteTone.AllNotesScale) {
936 j = StartBit+5+8; 977 j = StartBit+5+8;
937 BufferAlignNumber(&j); 978 BufferAlignNumber(&j);
938 if ((j/8)>(*maxlength)) { 979 if ((j/8)>(*maxlength)) {
939 StartBit = OldStartBit; 980 StartBit = OldStartBit;
940 break; 981 break;
941 } 982 }
942 DefScale = Note->Scale; 983 DefScale = Note->Scale;
943 AddBufferByte(package, &StartBit, SM_InstructionID_ScaleInstructionId, 3); 984 AddBufferByte(package, &StartBit, SM_InstructionID_ScaleInstructionId, 3);
944 AddBufferByte(package, &StartBit, ((unsigned char)((DefScale-4)<<6)), 2); 985 AddBufferByte(package, &StartBit, ((unsigned char)((DefScale-4)<<6)), 2);
945 HowManyCommands++; 986 HowManyCommands++;
946 } 987 }
947 if (DefStyle != Note->Style) { 988 if (DefStyle != Note->Style) {
948 j = StartBit+5+8; 989 j = StartBit+5+8;
949 BufferAlignNumber(&j); 990 BufferAlignNumber(&j);
950 if ((j/8)>(*maxlength)) { 991 if ((j/8)>(*maxlength)) {
951 StartBit = OldStartBit; 992 StartBit = OldStartBit;
952 break; 993 break;
953 } 994 }
954 DefStyle = Note->Style; 995 DefStyle = Note->Style;
955 AddBufferByte(package, &StartBit, SM_InstructionID_StyleInstructionId, 3); 996 AddBufferByte(package, &StartBit, SM_InstructionID_StyleInstructionId, 3);
956 AddBufferByte(package, &StartBit, ((unsigned char)DefStyle), 2); 997 AddBufferByte(package, &StartBit, ((unsigned char)DefStyle), 2);
957 HowManyCommands++; 998 HowManyCommands++;
958 } 999 }
959 } 1000 }
960 /* Beats per minute/tempo of the tune */ 1001 /* Beats per minute/tempo of the tune */
961 if (DefTempo != GSM_RTTLGetTempo(Note->Tempo)) { 1002 if (DefTempo != GSM_RTTLGetTempo(Note->Tempo)) {
962 j = StartBit+8+8; 1003 j = StartBit+8+8;
963 BufferAlignNumber(&j); 1004 BufferAlignNumber(&j);
964 if ((j/8)>(*maxlength)) { 1005 if ((j/8)>(*maxlength)) {
965 StartBit = OldStartBit; 1006 StartBit = OldStartBit;
966 break; 1007 break;
967 } 1008 }
968 DefTempo=GSM_RTTLGetTempo(Note->Tempo); 1009 DefTempo=GSM_RTTLGetTempo(Note->Tempo);
969 /* Adding beats per minute (tempo) of the tune */ 1010 /* Adding beats per minute (tempo) of the tune */
970 AddBufferByte(package, &StartBit, SM_InstructionID_TempoInstructionId, 3); 1011 AddBufferByte(package, &StartBit, SM_InstructionID_TempoInstructionId, 3);
971 AddBufferByte(package, &StartBit, ((unsigned char)DefTempo), 5); 1012 AddBufferByte(package, &StartBit, ((unsigned char)DefTempo), 5);
972 HowManyCommands++; 1013 HowManyCommands++;
973 } 1014 }
974 j = StartBit+12+8; 1015 j = StartBit+12+8;
975 BufferAlignNumber(&j); 1016 BufferAlignNumber(&j);
976 if ((j/8)>(*maxlength)) { 1017 if ((j/8)>(*maxlength)) {
977 StartBit = OldStartBit; 1018 StartBit = OldStartBit;
978 break; 1019 break;
979 } 1020 }
980 /* Note */ 1021 /* Note */
981 AddBufferByte(package, &StartBit, SM_InstructionID_NoteInstructionId, 3); 1022 AddBufferByte(package, &StartBit, SM_InstructionID_NoteInstructionId, 3);
982 AddBufferByte(package, &StartBit, ((unsigned char)Note->Note), 4); 1023 AddBufferByte(package, &StartBit, ((unsigned char)Note->Note), 4);
983 AddBufferByte(package, &StartBit, ((unsigned char)Note->Duration), 3); 1024 AddBufferByte(package, &StartBit, ((unsigned char)Note->Duration), 3);
984 AddBufferByte(package, &StartBit, ((unsigned char)Note->DurationSpec), 2); 1025 AddBufferByte(package, &StartBit, ((unsigned char)Note->DurationSpec), 2);
985 HowManyCommands++; 1026 HowManyCommands++;
986 /* We are sure, we pack it for SMS or setting to phone, not for OTT file */ 1027 /* We are sure, we pack it for SMS or setting to phone, not for OTT file */
987 if (*maxlength<1000) { 1028 if (*maxlength<1000) {
988 /* Like Pc Composer say - before of phone limitations...*/ 1029 /* Like Pc Composer say - before of phone limitations...*/
989 if (HowManyNotes==130-1) break; 1030 if (HowManyNotes==130-1) break;
990 } 1031 }
991 HowManyNotes++; 1032 HowManyNotes++;
992 } 1033 }
993 1034
994 BufferAlign(package, &StartBit); 1035 BufferAlign(package, &StartBit);
995 AddBufferByte(package, &StartBit, SM_CommandEnd_CommandEnd, 8); 1036 AddBufferByte(package, &StartBit, SM_CommandEnd_CommandEnd, 8);
996 1037
997 OldStartBit = StartBit; 1038 OldStartBit = StartBit;
998 StartBit = StartBitHowManyCommands; 1039 StartBit = StartBitHowManyCommands;
999 /* HowManyCommands */ 1040 /* HowManyCommands */
1000 AddBufferByte(package, &StartBit, ((unsigned char)HowManyCommands), 8); 1041 AddBufferByte(package, &StartBit, ((unsigned char)HowManyCommands), 8);
1001 StartBit = OldStartBit; 1042 StartBit = OldStartBit;
1002 1043
1003 *maxlength=StartBit/8; 1044 *maxlength=StartBit/8;
1004 1045
1005 return(i); 1046 return(i);
1006} 1047}
1007 1048
1008GSM_Error GSM_DecodeNokiaRTTLRingtone(GSM_Ringtone *ringtone, unsigned char *package, int maxlength) 1049GSM_Error GSM_DecodeNokiaRTTLRingtone(GSM_Ringtone *ringtone, unsigned char *package, int maxlength)
1009{ 1050{
1010 int StartBit=0, HowMany, l, q, i, spec; 1051 int StartBit=0, HowMany, l, q, i, spec;
1011 char Buffer[100]; 1052 char Buffer[100];
1012 GSM_RingNote *Note; 1053 GSM_RingNote *Note;
1013 1054
1014 /* Default ringtone parameters */ 1055 /* Default ringtone parameters */
1015 GSM_RingNoteScale DefScale= Scale_880; 1056 GSM_RingNoteScale DefScale= Scale_880;
1016 GSM_RingNoteStyle DefStyle = NaturalStyle; 1057 GSM_RingNoteStyle DefStyle = NaturalStyle;
1017 int DefTempo= 63; 1058 int DefTempo= 63;
1018 1059
1019 ringtone->Format = RING_NOTETONE; 1060 ringtone->Format = RING_NOTETONE;
1020 ringtone->NoteTone.NrCommands = 0; 1061 ringtone->NoteTone.NrCommands = 0;
1021 1062
1022 GetBufferInt(package,&StartBit,&l,8); 1063 GetBufferInt(package,&StartBit,&l,8);
1023 if (l!=0x02) { 1064 if (l!=0x02) {
1024 dbgprintf("Not header\n"); 1065 dbgprintf("Not header\n");
1025 return ERR_NOTSUPPORTED; 1066 return ERR_NOTSUPPORTED;
1026 } 1067 }
1027 1068
1028 GetBufferInt(package,&StartBit,&l,7); 1069 GetBufferInt(package,&StartBit,&l,7);
1029 if (l!=SM_Command_RingingToneProgramming) { 1070 if (l!=SM_Command_RingingToneProgramming) {
1030 dbgprintf("Not RingingToneProgramming\n"); 1071 dbgprintf("Not RingingToneProgramming\n");
1031 return ERR_NOTSUPPORTED; 1072 return ERR_NOTSUPPORTED;
1032 } 1073 }
1033 1074
1034 /* According to specification we need have next part octet-aligned */ 1075 /* According to specification we need have next part octet-aligned */
1035 BufferAlignNumber(&StartBit); 1076 BufferAlignNumber(&StartBit);
1036 1077
diff --git a/gammu/emb/common/service/gsmring.h b/gammu/emb/common/service/gsmring.h
index 207cf31..2d2dd7a 100644
--- a/gammu/emb/common/service/gsmring.h
+++ b/gammu/emb/common/service/gsmring.h
@@ -1,202 +1,204 @@
1/* (c) 2002-2004 by Marcin Wiacek */ 1/* (c) 2002-2004 by Marcin Wiacek */
2 2
3#ifndef __gsm_ring_h 3#ifndef __gsm_ring_h
4#define __gsm_ring_h 4#define __gsm_ring_h
5 5
6/* --------------- Smart Messaging Specification 2.0 & 3.0 ----------------- */ 6/* --------------- Smart Messaging Specification 2.0 & 3.0 ----------------- */
7 7
8 #define SM_CommandEnd_CommandEnd 0x00 8 #define SM_CommandEnd_CommandEnd 0x00
9 9
10/* specification gives also other */ 10/* specification gives also other */
11 #define SM_Command_RingingToneProgramming 0x25<<1 11 #define SM_Command_RingingToneProgramming 0x25<<1
12 #define SM_Command_Sound 0x1d<<1 12 #define SM_Command_Sound 0x1d<<1
13/* specification gives also other */ 13/* specification gives also other */
14 14
15 #define SM_Song_BasicSongType 0x01<<5 15 #define SM_Song_BasicSongType 0x01<<5
16/* specification gives also other */ 16/* specification gives also other */
17 17
18 #define SM_PatternID_A_part 0x00<<6 18 #define SM_PatternID_A_part 0x00<<6
19/* specification gives also other */ 19/* specification gives also other */
20 20
21 #define SM_InstructionID_PatternHeaderId 0x00<<5 21 #define SM_InstructionID_PatternHeaderId 0x00<<5
22 #define SM_InstructionID_NoteInstructionId 0x01<<5 22 #define SM_InstructionID_NoteInstructionId 0x01<<5
23 #define SM_InstructionID_ScaleInstructionId 0x02<<5 23 #define SM_InstructionID_ScaleInstructionId 0x02<<5
24 #define SM_InstructionID_StyleInstructionId 0x03<<5 24 #define SM_InstructionID_StyleInstructionId 0x03<<5
25 #define SM_InstructionID_TempoInstructionId 0x04<<5 25 #define SM_InstructionID_TempoInstructionId 0x04<<5
26 #define SM_InstructionID_VolumeInstructionId 0x05<<5 26 #define SM_InstructionID_VolumeInstructionId 0x05<<5
27 27
28/* ------ end of Smart Messaging Specification 2.0 & 3.0 definitions ------- */ 28/* ------ end of Smart Messaging Specification 2.0 & 3.0 definitions ------- */
29 29
30#define MAX_RINGTONE_NOTES 255 30#define MAX_RINGTONE_NOTES 255
31 31
32typedef enum { 32typedef enum {
33 /** 33 /**
34 * Natural style (rest between notes) 34 * Natural style (rest between notes)
35 */ 35 */
36 NaturalStyle = 0x00<<6, 36 NaturalStyle = 0x00<<6,
37 /** 37 /**
38 * Continuous style (no rest between notes) 38 * Continuous style (no rest between notes)
39 */ 39 */
40 ContinuousStyle = 0x01<<6, 40 ContinuousStyle = 0x01<<6,
41 /** 41 /**
42 * Staccato style (shorter notes and longer rest period) 42 * Staccato style (shorter notes and longer rest period)
43 */ 43 */
44 StaccatoStyle = 0x02<<6 44 StaccatoStyle = 0x02<<6
45} GSM_RingNoteStyle; 45} GSM_RingNoteStyle;
46 46
47typedef enum { 47typedef enum {
48 Note_Pause = 0x00<<4, 48 Note_Pause = 0x00<<4,
49 Note_C = 0x01<<4, 49 Note_C = 0x01<<4,
50 Note_Cis = 0x02<<4, 50 Note_Cis = 0x02<<4,
51 Note_D = 0x03<<4, 51 Note_D = 0x03<<4,
52 Note_Dis = 0x04<<4, 52 Note_Dis = 0x04<<4,
53 Note_E = 0x05<<4, 53 Note_E = 0x05<<4,
54 Note_F = 0x06<<4, 54 Note_F = 0x06<<4,
55 Note_Fis = 0x07<<4, 55 Note_Fis = 0x07<<4,
56 Note_G = 0x08<<4, 56 Note_G = 0x08<<4,
57 Note_Gis = 0x09<<4, 57 Note_Gis = 0x09<<4,
58 Note_A = 0x0a<<4, 58 Note_A = 0x0a<<4,
59 Note_Ais = 0x0b<<4, 59 Note_Ais = 0x0b<<4,
60 Note_H = 0x0c<<4 60 Note_H = 0x0c<<4
61} GSM_RingNoteNote; 61} GSM_RingNoteNote;
62 62
63typedef enum { 63typedef enum {
64 Duration_Full = 0x00<<5, 64 Duration_Full = 0x00<<5,
65 Duration_1_2 = 0x01<<5, 65 Duration_1_2 = 0x01<<5,
66 Duration_1_4 = 0x02<<5, 66 Duration_1_4 = 0x02<<5,
67 Duration_1_8 = 0x03<<5, 67 Duration_1_8 = 0x03<<5,
68 Duration_1_16 = 0x04<<5, 68 Duration_1_16 = 0x04<<5,
69 Duration_1_32 = 0x05<<5 69 Duration_1_32 = 0x05<<5
70} GSM_RingNoteDuration; 70} GSM_RingNoteDuration;
71 71
72typedef enum { 72typedef enum {
73 NoSpecialDuration = 0x00<<6, 73 NoSpecialDuration = 0x00<<6,
74 DottedNote = 0x01<<6, 74 DottedNote = 0x01<<6,
75 DoubleDottedNote = 0x02<<6, 75 DoubleDottedNote = 0x02<<6,
76 Length_2_3 = 0x03<<6 76 Length_2_3 = 0x03<<6
77} GSM_RingNoteDurationSpec; 77} GSM_RingNoteDurationSpec;
78 78
79typedef enum { 79typedef enum {
80 Scale_55 = 1, /* 55 Hz for note A */ 80 Scale_55 = 1, /* 55 Hz for note A */
81 Scale_110, /* 110 Hz for note A */ 81 Scale_110, /* 110 Hz for note A */
82 Scale_220, 82 Scale_220,
83 Scale_440, /* first scale for Nokia */ 83 Scale_440, /* first scale for Nokia */
84 Scale_880, 84 Scale_880,
85 Scale_1760, 85 Scale_1760,
86 Scale_3520, /* last scale for Nokia */ 86 Scale_3520, /* last scale for Nokia */
87 Scale_7040, 87 Scale_7040,
88 Scale_14080 88 Scale_14080
89} GSM_RingNoteScale; 89} GSM_RingNoteScale;
90 90
91typedef struct { 91typedef struct {
92 GSM_RingNoteDuration Duration; 92 GSM_RingNoteDuration Duration;
93 GSM_RingNoteDurationSpec DurationSpec; 93 GSM_RingNoteDurationSpec DurationSpec;
94 GSM_RingNoteNote Note; 94 GSM_RingNoteNote Note;
95 GSM_RingNoteStyle Style; 95 GSM_RingNoteStyle Style;
96 GSM_RingNoteScale Scale; 96 GSM_RingNoteScale Scale;
97 int Tempo; 97 int Tempo;
98} GSM_RingNote; 98} GSM_RingNote;
99 99
100typedef enum { 100typedef enum {
101 RING_Note = 1, 101 RING_Note = 1,
102 RING_EnableVibra, 102 RING_EnableVibra,
103 RING_DisableVibra, 103 RING_DisableVibra,
104 RING_EnableLight, 104 RING_EnableLight,
105 RING_DisableLight, 105 RING_DisableLight,
106 RING_EnableLED, 106 RING_EnableLED,
107 RING_DisableLED, 107 RING_DisableLED,
108 RING_Repeat 108 RING_Repeat
109} GSM_RingCommandType; 109} GSM_RingCommandType;
110 110
111typedef struct { 111typedef struct {
112 GSM_RingCommandType Type; 112 GSM_RingCommandType Type;
113 GSM_RingNote Note; 113 GSM_RingNote Note;
114 unsigned char Value; 114 unsigned char Value;
115} GSM_RingCommand; 115} GSM_RingCommand;
116 116
117typedef struct { 117typedef struct {
118 int NrCommands; 118 int NrCommands;
119 GSM_RingCommand Commands[MAX_RINGTONE_NOTES]; 119 GSM_RingCommand Commands[MAX_RINGTONE_NOTES];
120 bool AllNotesScale; 120 bool AllNotesScale;
121} GSM_NoteRingtone; 121} GSM_NoteRingtone;
122 122
123/* FIXME: should use BinaryTone instead? */
123/* Structure to hold Nokia binary ringtones. */ 124/* Structure to hold Nokia binary ringtones. */
124typedef struct { 125typedef struct {
125 unsigned char Frame[30000]; 126 unsigned char Frame[50000];
126 int Length; 127 int Length;
127} GSM_NokiaBinaryRingtone; 128} GSM_NokiaBinaryRingtone;
128 129
129typedef struct { 130typedef struct {
130 unsigned char *Frame; 131 unsigned char *Buffer;
131 int Length; 132 int Length;
132} GSM_BinaryTone; 133} GSM_BinaryTone;
133 134
134typedef enum { 135typedef enum {
135 RING_NOTETONE = 1, 136 RING_NOTETONE = 1,
136 RING_NOKIABINARY, 137 RING_NOKIABINARY,
137 RING_MIDI 138 RING_MIDI,
139 RING_MMF
138} GSM_RingtoneFormat; 140} GSM_RingtoneFormat;
139 141
140/** 142/**
141 * Structure for saving various ringtones formats 143 * Structure for saving various ringtones formats
142 */ 144 */
143typedef struct { 145typedef struct {
144 /** 146 /**
145 * Ringtone saved in one of three formats 147 * Ringtone saved in one of three formats
146 */ 148 */
147 GSM_NokiaBinaryRingtone NokiaBinary; 149 GSM_NokiaBinaryRingtone NokiaBinary;
148 GSM_BinaryTone BinaryTone; 150 GSM_BinaryTone BinaryTone;
149 GSM_NoteRingtone NoteTone; 151 GSM_NoteRingtone NoteTone;
150 /** 152 /**
151 * Ringtone format 153 * Ringtone format
152 */ 154 */
153 GSM_RingtoneFormat Format; 155 GSM_RingtoneFormat Format;
154 /** 156 /**
155 * Ringtone name 157 * Ringtone name
156 */ 158 */
157 char Name[20*2]; 159 char Name[20*2];
158 /** 160 /**
159 * Ringtone location 161 * Ringtone location
160 */ 162 */
161 int Location; 163 int Location;
162} GSM_Ringtone; 164} GSM_Ringtone;
163 165
164typedef struct { 166typedef struct {
165 int Group;//Nokia specific 167 int Group;//Nokia specific
166 int ID; 168 int ID;
167 char Name[30*2]; 169 char Name[30*2];
168} GSM_RingtoneInfo; 170} GSM_RingtoneInfo;
169 171
170typedef struct { 172typedef struct {
171 int Number; 173 int Number;
172 GSM_RingtoneInfo Ringtone[100]; 174 GSM_RingtoneInfo Ringtone[100];
173} GSM_AllRingtonesInfo; 175} GSM_AllRingtonesInfo;
174 176
175GSM_Error GSM_SaveRingtoneFile(char *FileName, GSM_Ringtone *ringtone); 177GSM_Error GSM_SaveRingtoneFile(char *FileName, GSM_Ringtone *ringtone);
176GSM_Error GSM_ReadRingtoneFile(char *FileName, GSM_Ringtone *ringtone); 178GSM_Error GSM_ReadRingtoneFile(char *FileName, GSM_Ringtone *ringtone);
177 179
178void saveott(FILE *file, GSM_Ringtone *ringtone); 180void saveott(FILE *file, GSM_Ringtone *ringtone);
179void savemid(FILE *file, GSM_Ringtone *ringtone); 181void savemid(FILE *file, GSM_Ringtone *ringtone);
180void saverng(FILE *file, GSM_Ringtone *ringtone); 182void saverng(FILE *file, GSM_Ringtone *ringtone);
181void saveimelody(FILE *file, GSM_Ringtone *ringtone); 183void saveimelody(FILE *file, GSM_Ringtone *ringtone);
182GSM_Error savewav(FILE *file, GSM_Ringtone *ringtone); 184GSM_Error savewav(FILE *file, GSM_Ringtone *ringtone);
183GSM_Error saverttl(FILE *file, GSM_Ringtone *ringtone); 185GSM_Error saverttl(FILE *file, GSM_Ringtone *ringtone);
184 186
185 unsigned char GSM_EncodeNokiaRTTLRingtone(GSM_Ringtone ringtone, unsigned char *package, int *maxlength); 187 unsigned char GSM_EncodeNokiaRTTLRingtone(GSM_Ringtone ringtone, unsigned char *package, int *maxlength);
186 unsigned char GSM_EncodeEMSSound (GSM_Ringtone ringtone, unsigned char *package, int *maxlength, double version, bool start); 188 unsigned char GSM_EncodeEMSSound (GSM_Ringtone ringtone, unsigned char *package, int *maxlength, double version, bool start);
187 189
188 GSM_Error GSM_DecodeNokiaRTTLRingtone(GSM_Ringtone *ringtone, unsigned char *package, int maxlength); 190 GSM_Error GSM_DecodeNokiaRTTLRingtone(GSM_Ringtone *ringtone, unsigned char *package, int maxlength);
189 191
190 GSM_Error GSM_RingtoneConvert(GSM_Ringtone *dest, GSM_Ringtone *src, GSM_RingtoneFormatFormat); 192 GSM_Error GSM_RingtoneConvert(GSM_Ringtone *dest, GSM_Ringtone *src, GSM_RingtoneFormatFormat);
191 193
192 int GSM_RTTLGetTempo (int Beats); 194 int GSM_RTTLGetTempo (int Beats);
193 int GSM_RingNoteGetFrequency(GSM_RingNote Note); 195 int GSM_RingNoteGetFrequency(GSM_RingNote Note);
194 int GSM_RingNoteGetFullDuration(GSM_RingNote Note); 196 int GSM_RingNoteGetFullDuration(GSM_RingNote Note);
195 197
196char *GSM_GetRingtoneName(GSM_AllRingtonesInfo *Info, int ID); 198char *GSM_GetRingtoneName(GSM_AllRingtonesInfo *Info, int ID);
197 199
198#endif 200#endif
199 201
200/* How should editor hadle tabs in this file? Add editor commands here. 202/* How should editor hadle tabs in this file? Add editor commands here.
201 * vim: noexpandtab sw=8 ts=8 sts=8: 203 * vim: noexpandtab sw=8 ts=8 sts=8:
202 */ 204 */
diff --git a/gammu/emb/common/service/sms/gsmmulti.c b/gammu/emb/common/service/sms/gsmmulti.c
index 6c1cdcd..bdb5ee9 100644
--- a/gammu/emb/common/service/sms/gsmmulti.c
+++ b/gammu/emb/common/service/sms/gsmmulti.c
@@ -298,384 +298,389 @@ GSM_Error GSM_EncodeAlcatelMultiPartSMS(GSM_MultiSMSMessage *SMS,
298 SMS->SMS[i].UDH.Text[0] += MyUDH.Length-1; 298 SMS->SMS[i].UDH.Text[0] += MyUDH.Length-1;
299 SMS->SMS[i].UDH.Length += MyUDH.Length-1; 299 SMS->SMS[i].UDH.Length += MyUDH.Length-1;
300 } 300 }
301 301
302 SMS->SMS[i].Coding = SMS_Coding_8bit; 302 SMS->SMS[i].Coding = SMS_Coding_8bit;
303 SMS->SMS[i].Class = 1; 303 SMS->SMS[i].Class = 1;
304 } 304 }
305 305
306 p = 0; 306 p = 0;
307 while (p != Len) { 307 while (p != Len) {
308 i = 140-SMS->SMS[SMS->Number].UDH.Length; 308 i = 140-SMS->SMS[SMS->Number].UDH.Length;
309 if (Len - p < i) i = Len - p; 309 if (Len - p < i) i = Len - p;
310 memcpy(SMS->SMS[SMS->Number].Text,Data+p,i); 310 memcpy(SMS->SMS[SMS->Number].Text,Data+p,i);
311 p += i; 311 p += i;
312 SMS->SMS[SMS->Number].Length = i; 312 SMS->SMS[SMS->Number].Length = i;
313 SMS->Number++; 313 SMS->Number++;
314 314
315 } 315 }
316 316
317 /* Linked sms UDH */ 317 /* Linked sms UDH */
318 if (SMS->Number != 1) { 318 if (SMS->Number != 1) {
319 UDHID = GSM_MakeSMSIDFromTime(); 319 UDHID = GSM_MakeSMSIDFromTime();
320 for (i=0;i<SMS->Number;i++) { 320 for (i=0;i<SMS->Number;i++) {
321 SMS->SMS[i].UDH.Text[SMS->SMS[i].UDH.Length-3] = UDHID; 321 SMS->SMS[i].UDH.Text[SMS->SMS[i].UDH.Length-3] = UDHID;
322 SMS->SMS[i].UDH.Text[SMS->SMS[i].UDH.Length-2] = SMS->Number; 322 SMS->SMS[i].UDH.Text[SMS->SMS[i].UDH.Length-2] = SMS->Number;
323 SMS->SMS[i].UDH.Text[SMS->SMS[i].UDH.Length-1] = i+1; 323 SMS->SMS[i].UDH.Text[SMS->SMS[i].UDH.Length-1] = i+1;
324 } 324 }
325 } 325 }
326 326
327 return ERR_NONE; 327 return ERR_NONE;
328} 328}
329 329
330/* Alcatel docs from www.alcatel.com/wap/ahead and other */ 330/* Alcatel docs from www.alcatel.com/wap/ahead and other */
331 GSM_Error GSM_EncodeMultiPartSMS(GSM_MultiPartSMSInfo *Info, 331 GSM_Error GSM_EncodeMultiPartSMS(GSM_MultiPartSMSInfo *Info,
332 GSM_MultiSMSMessage *SMS) 332 GSM_MultiSMSMessage *SMS)
333{ 333{
334 unsigned charBuffer[GSM_MAX_SMS_LENGTH*2*MAX_MULTI_SMS]; 334 unsigned charBuffer[GSM_MAX_SMS_LENGTH*2*MAX_MULTI_SMS];
335 unsigned charBuffer2[GSM_MAX_SMS_LENGTH*2*MAX_MULTI_SMS]; 335 unsigned charBuffer2[GSM_MAX_SMS_LENGTH*2*MAX_MULTI_SMS];
336 int Length = 0,smslen,i, Class = -1, j,p; 336 int Length = 0,smslen,i, Class = -1, j,p;
337 GSM_Errorerror; 337 GSM_Errorerror;
338 GSM_Coding_Type Coding = SMS_Coding_8bit; 338 GSM_Coding_Type Coding = SMS_Coding_8bit;
339 GSM_UDH UDH= UDH_NoUDH; 339 GSM_UDH UDH= UDH_NoUDH;
340 GSM_UDHHeader UDHHeader; 340 GSM_UDHHeader UDHHeader;
341 bool EMS= false; 341 bool EMS= false;
342 int textnum = 0; 342 int textnum = 0;
343 343
344 SMS->Number = 0; 344 SMS->Number = 0;
345 345
346 if (Info->Entries[0].ID == SMS_AlcatelSMSTemplateName) { 346 if (Info->Entries[0].ID == SMS_AlcatelSMSTemplateName) {
347 Buffer[Length++] = 0x00; //number of elements 347 Buffer[Length++] = 0x00; //number of elements
348 for (i=1;i<Info->EntriesNum;i++) { 348 for (i=1;i<Info->EntriesNum;i++) {
349 switch (Info->Entries[i].ID) { 349 switch (Info->Entries[i].ID) {
350 case SMS_EMSSound10: 350 case SMS_EMSSound10:
351 case SMS_EMSSound12: 351 case SMS_EMSSound12:
352 case SMS_EMSSonyEricssonSound: 352 case SMS_EMSSonyEricssonSound:
353 case SMS_EMSSound10Long: 353 case SMS_EMSSound10Long:
354 case SMS_EMSSound12Long: 354 case SMS_EMSSound12Long:
355 case SMS_EMSSonyEricssonSoundLong: 355 case SMS_EMSSonyEricssonSoundLong:
356 case SMS_EMSVariableBitmap: 356 case SMS_EMSVariableBitmap:
357 case SMS_EMSAnimation: 357 case SMS_EMSAnimation:
358 case SMS_EMSVariableBitmapLong: 358 case SMS_EMSVariableBitmapLong:
359 break; 359 break;
360 case SMS_EMSPredefinedSound: 360 case SMS_EMSPredefinedSound:
361 Buffer[0]++; 361 Buffer[0]++;
362 Buffer[Length++] = 0x01; //type of data 362 Buffer[Length++] = 0x01; //type of data
363 Buffer[Length++] = 1 % 256;//len 363 Buffer[Length++] = 1 % 256;//len
364 Buffer[Length++] = 1 / 256; //len 364 Buffer[Length++] = 1 / 256; //len
365 Buffer[Length++] = Info->Entries[i].Number; 365 Buffer[Length++] = Info->Entries[i].Number;
366 break; 366 break;
367 case SMS_EMSPredefinedAnimation: 367 case SMS_EMSPredefinedAnimation:
368 Buffer[0]++; 368 Buffer[0]++;
369 Buffer[Length++] = 0x02; //type of data 369 Buffer[Length++] = 0x02; //type of data
370 Buffer[Length++] = 1 % 256;//len 370 Buffer[Length++] = 1 % 256;//len
371 Buffer[Length++] = 1 / 256; //len 371 Buffer[Length++] = 1 / 256; //len
372 Buffer[Length++] = Info->Entries[i].Number; 372 Buffer[Length++] = Info->Entries[i].Number;
373 break; 373 break;
374 case SMS_ConcatenatedTextLong: 374 case SMS_ConcatenatedTextLong:
375 Buffer[0]++; 375 Buffer[0]++;
376 p = UnicodeLength(Info->Entries[i].Buffer); 376 p = UnicodeLength(Info->Entries[i].Buffer);
377 EncodeDefault(Buffer2, Info->Entries[i].Buffer, &p, true, NULL); 377 EncodeDefault(Buffer2, Info->Entries[i].Buffer, &p, true, NULL);
378 Buffer[Length++] = 0x00; //type of data 378 Buffer[Length++] = 0x00; //type of data
379 Length = Length + 2; 379 Length = Length + 2;
380 smslen = GSM_PackSevenBitsToEight(0, Buffer2, Buffer+Length, p); 380 smslen = GSM_PackSevenBitsToEight(0, Buffer2, Buffer+Length, p);
381 Buffer[Length-2] = smslen % 256; //len 381 Buffer[Length-2] = smslen % 256; //len
382 Buffer[Length-1] = smslen / 256; //len 382 Buffer[Length-1] = smslen / 256; //len
383 Length = Length + smslen; 383 Length = Length + smslen;
384 break; 384 break;
385 default: 385 default:
386 return ERR_UNKNOWN; 386 return ERR_UNKNOWN;
387 } 387 }
388 } 388 }
389 Buffer[0] = Buffer[0] * 2; 389 Buffer[0] = Buffer[0] * 2;
390 return GSM_EncodeAlcatelMultiPartSMS(SMS,Buffer,Length,Info->Entries[0].Buffer,ALCATELTDD_SMSTEMPLATE); 390 return GSM_EncodeAlcatelMultiPartSMS(SMS,Buffer,Length,Info->Entries[0].Buffer,ALCATELTDD_SMSTEMPLATE);
391 } 391 }
392 392
393 for (i=0;i<Info->EntriesNum;i++) { 393 for (i=0;i<Info->EntriesNum;i++) {
394 switch (Info->Entries[i].ID) { 394 switch (Info->Entries[i].ID) {
395 case SMS_EMSPredefinedAnimation: 395 case SMS_EMSPredefinedAnimation:
396 case SMS_EMSPredefinedSound: 396 case SMS_EMSPredefinedSound:
397 case SMS_EMSSound10: 397 case SMS_EMSSound10:
398 case SMS_EMSSound12: 398 case SMS_EMSSound12:
399 case SMS_EMSSonyEricssonSound: 399 case SMS_EMSSonyEricssonSound:
400 case SMS_EMSSound10Long: 400 case SMS_EMSSound10Long:
401 case SMS_EMSSound12Long: 401 case SMS_EMSSound12Long:
402 case SMS_EMSSonyEricssonSoundLong: 402 case SMS_EMSSonyEricssonSoundLong:
403 case SMS_EMSFixedBitmap: 403 case SMS_EMSFixedBitmap:
404 case SMS_EMSVariableBitmap: 404 case SMS_EMSVariableBitmap:
405 case SMS_EMSAnimation: 405 case SMS_EMSAnimation:
406 case SMS_EMSVariableBitmapLong: 406 case SMS_EMSVariableBitmapLong:
407 EMS = true; 407 EMS = true;
408 break; 408 break;
409 case SMS_ConcatenatedTextLong: 409 case SMS_ConcatenatedTextLong:
410 case SMS_ConcatenatedTextLong16bit: 410 case SMS_ConcatenatedTextLong16bit:
411 411
412 /* This covers situation, when somebody will call function 412 /* This covers situation, when somebody will call function
413 * with two or more SMS_Concatenated.... entries only. 413 * with two or more SMS_Concatenated.... entries only.
414 * It will be still only linked sms, but functions below 414 * It will be still only linked sms, but functions below
415 * will pack only first entry according to own limits. 415 * will pack only first entry according to own limits.
416 * We redirect to EMS functions, because they are more generic 416 * We redirect to EMS functions, because they are more generic
417 * here and will handle it correctly and produce linked sms 417 * here and will handle it correctly and produce linked sms
418 * from all entries 418 * from all entries
419 */ 419 */
420 textnum ++; 420 textnum ++;
421 if (textnum > 1) EMS = true; 421 if (textnum > 1) EMS = true;
422 422
423 if (Info->Entries[i].Left || Info->Entries[i].Right || 423 if (Info->Entries[i].Left || Info->Entries[i].Right ||
424 Info->Entries[i].Center || Info->Entries[i].Large || 424 Info->Entries[i].Center || Info->Entries[i].Large ||
425 Info->Entries[i].Small || Info->Entries[i].Bold || 425 Info->Entries[i].Small || Info->Entries[i].Bold ||
426 Info->Entries[i].Italic || Info->Entries[i].Underlined || 426 Info->Entries[i].Italic || Info->Entries[i].Underlined ||
427 Info->Entries[i].Strikethrough) { 427 Info->Entries[i].Strikethrough) {
428 EMS = true; 428 EMS = true;
429 } 429 }
430 default: 430 default:
431 break; 431 break;
432 } 432 }
433 if (EMS) break; 433 if (EMS) break;
434 } 434 }
435 if (EMS) { 435 if (EMS) {
436 error=GSM_EncodeEMSMultiPartSMS(Info,SMS,UDH_NoUDH); 436 error=GSM_EncodeEMSMultiPartSMS(Info,SMS,UDH_NoUDH);
437 if (error != ERR_NONE) return error; 437 if (error != ERR_NONE) return error;
438 if (SMS->Number != 1) { 438 if (SMS->Number != 1) {
439 SMS->Number = 0; 439 SMS->Number = 0;
440 for (i=0;i<Info->EntriesNum;i++) { 440 for (i=0;i<Info->EntriesNum;i++) {
441 if (Info->Entries[i].ID == SMS_ConcatenatedTextLong16bit) { 441 if (Info->Entries[i].ID == SMS_ConcatenatedTextLong16bit) {
442 return GSM_EncodeEMSMultiPartSMS(Info,SMS,UDH_ConcatenatedMessages); 442 return GSM_EncodeEMSMultiPartSMS(Info,SMS,UDH_ConcatenatedMessages);
443 } 443 }
444 } 444 }
445 return GSM_EncodeEMSMultiPartSMS(Info,SMS,UDH_ConcatenatedMessages16bit); 445 return GSM_EncodeEMSMultiPartSMS(Info,SMS,UDH_ConcatenatedMessages16bit);
446 } 446 }
447 return error; 447 return error;
448 } 448 }
449 449
450 if (Info->EntriesNum != 1) return ERR_UNKNOWN; 450 if (Info->EntriesNum != 1) return ERR_UNKNOWN;
451 451
452 switch (Info->Entries[0].ID) { 452 switch (Info->Entries[0].ID) {
453 case SMS_AlcatelMonoBitmapLong: 453 case SMS_AlcatelMonoBitmapLong:
454 Buffer[0] = Info->Entries[0].Bitmap->Bitmap[0].BitmapWidth; 454 Buffer[0] = Info->Entries[0].Bitmap->Bitmap[0].BitmapWidth;
455 Buffer[1] = Info->Entries[0].Bitmap->Bitmap[0].BitmapHeight; 455 Buffer[1] = Info->Entries[0].Bitmap->Bitmap[0].BitmapHeight;
456 PHONE_EncodeBitmap(GSM_AlcatelBMMIPicture, Buffer+2, &Info->Entries[0].Bitmap->Bitmap[0]); 456 PHONE_EncodeBitmap(GSM_AlcatelBMMIPicture, Buffer+2, &Info->Entries[0].Bitmap->Bitmap[0]);
457 Length = PHONE_GetBitmapSize(GSM_AlcatelBMMIPicture,Info->Entries[0].Bitmap->Bitmap[0].BitmapWidth,Info->Entries[0].Bitmap->Bitmap[0].BitmapHeight)+2; 457 Length = PHONE_GetBitmapSize(GSM_AlcatelBMMIPicture,Info->Entries[0].Bitmap->Bitmap[0].BitmapWidth,Info->Entries[0].Bitmap->Bitmap[0].BitmapHeight)+2;
458 return GSM_EncodeAlcatelMultiPartSMS(SMS,Buffer,Length,Info->Entries[0].Bitmap->Bitmap[0].Text,ALCATELTDD_PICTURE); 458 return GSM_EncodeAlcatelMultiPartSMS(SMS,Buffer,Length,Info->Entries[0].Bitmap->Bitmap[0].Text,ALCATELTDD_PICTURE);
459 case SMS_AlcatelMonoAnimationLong: 459 case SMS_AlcatelMonoAnimationLong:
460 /* Number of sequence words */ 460 /* Number of sequence words */
461 Buffer[0] = (Info->Entries[0].Bitmap->Number+1) % 256; 461 Buffer[0] = (Info->Entries[0].Bitmap->Number+1) % 256;
462 Buffer[1] = (Info->Entries[0].Bitmap->Number+1) / 256; 462 Buffer[1] = (Info->Entries[0].Bitmap->Number+1) / 256;
463 /* Picture display time 1 second (1 = 100ms) */ 463 /* Picture display time 1 second (1 = 100ms) */
464 Buffer[2] = 10 % 256; 464 Buffer[2] = 10 % 256;
465 Buffer[3] = 10 / 256 + 0xF0; 465 Buffer[3] = 10 / 256 + 0xF0;
466 466
467 Length = 4; 467 Length = 4;
468 j = 0; 468 j = 0;
469 469
470 /* Offsets to bitmaps */ 470 /* Offsets to bitmaps */
471 for (i=0;i<Info->Entries[0].Bitmap->Number;i++) { 471 for (i=0;i<Info->Entries[0].Bitmap->Number;i++) {
472 Buffer[Length++] = (4+j+Info->Entries[0].Bitmap->Number*2) % 256; 472 Buffer[Length++] = (4+j+Info->Entries[0].Bitmap->Number*2) % 256;
473 Buffer[Length++] = (4+j+Info->Entries[0].Bitmap->Number*2) / 256; 473 Buffer[Length++] = (4+j+Info->Entries[0].Bitmap->Number*2) / 256;
474 j += PHONE_GetBitmapSize(GSM_AlcatelBMMIPicture,Info->Entries[0].Bitmap->Bitmap[i].BitmapWidth,Info->Entries[0].Bitmap->Bitmap[i].BitmapHeight)+2; 474 j += PHONE_GetBitmapSize(GSM_AlcatelBMMIPicture,Info->Entries[0].Bitmap->Bitmap[i].BitmapWidth,Info->Entries[0].Bitmap->Bitmap[i].BitmapHeight)+2;
475 } 475 }
476 476
477 /* Bitmaps */ 477 /* Bitmaps */
478 for (i=0;i<Info->Entries[0].Bitmap->Number;i++) { 478 for (i=0;i<Info->Entries[0].Bitmap->Number;i++) {
479 Buffer[Length++] = Info->Entries[0].Bitmap->Bitmap[i].BitmapWidth; 479 Buffer[Length++] = Info->Entries[0].Bitmap->Bitmap[i].BitmapWidth;
480 Buffer[Length++] = Info->Entries[0].Bitmap->Bitmap[i].BitmapHeight; 480 Buffer[Length++] = Info->Entries[0].Bitmap->Bitmap[i].BitmapHeight;
481 PHONE_EncodeBitmap(GSM_AlcatelBMMIPicture, Buffer+Length, &Info->Entries[0].Bitmap->Bitmap[i]); 481 PHONE_EncodeBitmap(GSM_AlcatelBMMIPicture, Buffer+Length, &Info->Entries[0].Bitmap->Bitmap[i]);
482 Length += PHONE_GetBitmapSize(GSM_AlcatelBMMIPicture,Info->Entries[0].Bitmap->Bitmap[i].BitmapWidth,Info->Entries[0].Bitmap->Bitmap[i].BitmapHeight); 482 Length += PHONE_GetBitmapSize(GSM_AlcatelBMMIPicture,Info->Entries[0].Bitmap->Bitmap[i].BitmapWidth,Info->Entries[0].Bitmap->Bitmap[i].BitmapHeight);
483 } 483 }
484 return GSM_EncodeAlcatelMultiPartSMS(SMS,Buffer,Length,Info->Entries[0].Bitmap->Bitmap[0].Text,ALCATELTDD_ANIMATION); 484 return GSM_EncodeAlcatelMultiPartSMS(SMS,Buffer,Length,Info->Entries[0].Bitmap->Bitmap[0].Text,ALCATELTDD_ANIMATION);
485 case SMS_MMSIndicatorLong: 485 case SMS_MMSIndicatorLong:
486 Class= 1; 486 Class= 1;
487 UDH= UDH_MMSIndicatorLong; 487 UDH= UDH_MMSIndicatorLong;
488 GSM_EncodeMMSIndicatorSMSText(Buffer,&Length,*Info->Entries[0].MMSIndicator); 488 GSM_EncodeMMSIndicatorSMSText(Buffer,&Length,*Info->Entries[0].MMSIndicator);
489 break; 489 break;
490 case SMS_WAPIndicatorLong:
491 Class= 1;
492 UDH= UDH_MMSIndicatorLong;
493 GSM_EncodeWAPIndicatorSMSText(Buffer,&Length,Info->Entries[0].MMSIndicator->Title,Info->Entries[0].MMSIndicator->Address);
494 break;
490 case SMS_NokiaRingtoneLong: 495 case SMS_NokiaRingtoneLong:
491 case SMS_NokiaRingtone: 496 case SMS_NokiaRingtone:
492 UDH= UDH_NokiaRingtone; 497 UDH= UDH_NokiaRingtone;
493 Class= 1; 498 Class= 1;
494 /* 7 = length of UDH_NokiaRingtone UDH header */ 499 /* 7 = length of UDH_NokiaRingtone UDH header */
495 Length = GSM_MAX_8BIT_SMS_LENGTH-7; 500 Length = GSM_MAX_8BIT_SMS_LENGTH-7;
496 Info->Entries[0].RingtoneNotes = GSM_EncodeNokiaRTTLRingtone(*Info->Entries[0].Ringtone,Buffer,&Length); 501 Info->Entries[0].RingtoneNotes = GSM_EncodeNokiaRTTLRingtone(*Info->Entries[0].Ringtone,Buffer,&Length);
497 if (Info->Entries[0].ID == SMS_NokiaRingtone) break; 502 if (Info->Entries[0].ID == SMS_NokiaRingtone) break;
498 if (Info->Entries[0].RingtoneNotes != Info->Entries[0].Ringtone->NoteTone.NrCommands) { 503 if (Info->Entries[0].RingtoneNotes != Info->Entries[0].Ringtone->NoteTone.NrCommands) {
499 UDH = UDH_NokiaRingtoneLong; 504 UDH = UDH_NokiaRingtoneLong;
500 Length = (GSM_MAX_8BIT_SMS_LENGTH-12)*3; 505 Length = (GSM_MAX_8BIT_SMS_LENGTH-12)*3;
501 Info->Entries[0].RingtoneNotes = GSM_EncodeNokiaRTTLRingtone(*Info->Entries[0].Ringtone,Buffer,&Length); 506 Info->Entries[0].RingtoneNotes = GSM_EncodeNokiaRTTLRingtone(*Info->Entries[0].Ringtone,Buffer,&Length);
502 } 507 }
503 break; 508 break;
504 case SMS_NokiaOperatorLogoLong: 509 case SMS_NokiaOperatorLogoLong:
505 if (Info->Entries[0].Bitmap->Bitmap[0].BitmapWidth > 72 || Info->Entries[0].Bitmap->Bitmap[0].BitmapHeight > 14) { 510 if (Info->Entries[0].Bitmap->Bitmap[0].BitmapWidth > 72 || Info->Entries[0].Bitmap->Bitmap[0].BitmapHeight > 14) {
506 UDH= UDH_NokiaOperatorLogoLong; 511 UDH= UDH_NokiaOperatorLogoLong;
507 Class = 1; 512 Class = 1;
508 NOKIA_EncodeNetworkCode(Buffer, Info->Entries[0].Bitmap->Bitmap[0].NetworkCode); 513 NOKIA_EncodeNetworkCode(Buffer, Info->Entries[0].Bitmap->Bitmap[0].NetworkCode);
509 Length = Length + 3; 514 Length = Length + 3;
510 NOKIA_CopyBitmap(GSM_Nokia7110OperatorLogo, &Info->Entries[0].Bitmap->Bitmap[0], Buffer, &Length); 515 NOKIA_CopyBitmap(GSM_Nokia7110OperatorLogo, &Info->Entries[0].Bitmap->Bitmap[0], Buffer, &Length);
511 break; 516 break;
512 } 517 }
513 case SMS_NokiaOperatorLogo: 518 case SMS_NokiaOperatorLogo:
514 UDH= UDH_NokiaOperatorLogo; 519 UDH= UDH_NokiaOperatorLogo;
515 Class = 1; 520 Class = 1;
516 NOKIA_EncodeNetworkCode(Buffer, Info->Entries[0].Bitmap->Bitmap[0].NetworkCode); 521 NOKIA_EncodeNetworkCode(Buffer, Info->Entries[0].Bitmap->Bitmap[0].NetworkCode);
517 Length = Length + 3; 522 Length = Length + 3;
518 NOKIA_CopyBitmap(GSM_NokiaOperatorLogo, &Info->Entries[0].Bitmap->Bitmap[0], Buffer, &Length); 523 NOKIA_CopyBitmap(GSM_NokiaOperatorLogo, &Info->Entries[0].Bitmap->Bitmap[0], Buffer, &Length);
519 break; 524 break;
520 case SMS_NokiaCallerLogo: 525 case SMS_NokiaCallerLogo:
521 UDH= UDH_NokiaCallerLogo; 526 UDH= UDH_NokiaCallerLogo;
522 Class = 1; 527 Class = 1;
523 NOKIA_CopyBitmap(GSM_NokiaCallerLogo, &Info->Entries[0].Bitmap->Bitmap[0], Buffer, &Length); 528 NOKIA_CopyBitmap(GSM_NokiaCallerLogo, &Info->Entries[0].Bitmap->Bitmap[0], Buffer, &Length);
524 break; 529 break;
525 case SMS_NokiaProfileLong: 530 case SMS_NokiaProfileLong:
526 case SMS_NokiaPictureImageLong: 531 case SMS_NokiaPictureImageLong:
527 case SMS_NokiaScreenSaverLong: 532 case SMS_NokiaScreenSaverLong:
528 Class = 1; 533 Class = 1;
529 UDH= UDH_NokiaProfileLong; 534 UDH= UDH_NokiaProfileLong;
530 GSM_EncodeSMS30MultiPartSMS(Info,Buffer,&Length); 535 GSM_EncodeSMS30MultiPartSMS(Info,Buffer,&Length);
531 break; 536 break;
532 case SMS_NokiaWAPBookmarkLong: 537 case SMS_NokiaWAPBookmarkLong:
533 Class= 1; 538 Class= 1;
534 NOKIA_EncodeWAPBookmarkSMSText(Buffer,&Length,Info->Entries[0].Bookmark); 539 NOKIA_EncodeWAPBookmarkSMSText(Buffer,&Length,Info->Entries[0].Bookmark);
535 /* 7 = length of UDH_NokiaWAP UDH header */ 540 /* 7 = length of UDH_NokiaWAP UDH header */
536 if (Length>(GSM_MAX_8BIT_SMS_LENGTH-7)) { 541 if (Length>(GSM_MAX_8BIT_SMS_LENGTH-7)) {
537 UDH=UDH_NokiaWAPLong; 542 UDH=UDH_NokiaWAPLong;
538 } else { 543 } else {
539 UDH=UDH_NokiaWAP; 544 UDH=UDH_NokiaWAP;
540 } 545 }
541 break; 546 break;
542 case SMS_NokiaWAPSettingsLong: 547 case SMS_NokiaWAPSettingsLong:
543 Class= 1; 548 Class= 1;
544 UDH= UDH_NokiaWAPLong; 549 UDH= UDH_NokiaWAPLong;
545 NOKIA_EncodeWAPMMSSettingsSMSText(Buffer,&Length,Info->Entries[0].Settings,false); 550 NOKIA_EncodeWAPMMSSettingsSMSText(Buffer,&Length,Info->Entries[0].Settings,false);
546 break; 551 break;
547 case SMS_NokiaMMSSettingsLong: 552 case SMS_NokiaMMSSettingsLong:
548 Class= 1; 553 Class= 1;
549 UDH= UDH_NokiaWAPLong; 554 UDH= UDH_NokiaWAPLong;
550 NOKIA_EncodeWAPMMSSettingsSMSText(Buffer,&Length,Info->Entries[0].Settings,true); 555 NOKIA_EncodeWAPMMSSettingsSMSText(Buffer,&Length,Info->Entries[0].Settings,true);
551 break; 556 break;
552 case SMS_NokiaVCARD10Long: 557 case SMS_NokiaVCARD10Long:
553 GSM_EncodeVCARD(Buffer,&Length,Info->Entries[0].Phonebook,true,Nokia_VCard10); 558 GSM_EncodeVCARD(Buffer,&Length,Info->Entries[0].Phonebook,true,Nokia_VCard10);
554 /* is 1 SMS ? 8 = length of ..SCKE2 */ 559 /* is 1 SMS ? 8 = length of ..SCKE2 */
555 if (Length<=GSM_MAX_SMS_LENGTH-8) { 560 if (Length<=GSM_MAX_SMS_LENGTH-8) {
556 sprintf(Buffer,"//SCKE2 "); 561 sprintf(Buffer,"//SCKE2 ");
557 Length = 8; 562 Length = 8;
558 GSM_EncodeVCARD(Buffer,&Length,Info->Entries[0].Phonebook,true,Nokia_VCard10); 563 GSM_EncodeVCARD(Buffer,&Length,Info->Entries[0].Phonebook,true,Nokia_VCard10);
559 } else { 564 } else {
560 /* FIXME: It wasn't checked */ 565 /* FIXME: It wasn't checked */
561 UDH = UDH_NokiaPhonebookLong; 566 UDH = UDH_NokiaPhonebookLong;
562 } 567 }
563 Coding = SMS_Coding_Default; 568 Coding = SMS_Coding_Default;
564 memcpy(Buffer2,Buffer,Length); 569 memcpy(Buffer2,Buffer,Length);
565 EncodeUnicode(Buffer,Buffer2,Length); 570 EncodeUnicode(Buffer,Buffer2,Length);
566 break; 571 break;
567 case SMS_NokiaVCARD21Long: 572 case SMS_NokiaVCARD21Long:
568 GSM_EncodeVCARD(Buffer,&Length,Info->Entries[0].Phonebook,true,Nokia_VCard21); 573 GSM_EncodeVCARD(Buffer,&Length,Info->Entries[0].Phonebook,true,Nokia_VCard21);
569 /* Is 1 SMS ? 12 = length of ..SCKL23F4 */ 574 /* Is 1 SMS ? 12 = length of ..SCKL23F4 */
570 if (Length<=GSM_MAX_SMS_LENGTH-12) { 575 if (Length<=GSM_MAX_SMS_LENGTH-12) {
571 sprintf(Buffer,"//SCKL23F4%c%c",13,10); 576 sprintf(Buffer,"//SCKL23F4%c%c",13,10);
572 Length = 12; 577 Length = 12;
573 GSM_EncodeVCARD(Buffer,&Length,Info->Entries[0].Phonebook,true,Nokia_VCard21); 578 GSM_EncodeVCARD(Buffer,&Length,Info->Entries[0].Phonebook,true,Nokia_VCard21);
574 } else { 579 } else {
575 UDH = UDH_NokiaPhonebookLong; 580 UDH = UDH_NokiaPhonebookLong;
576 /* Here can be also 8 bit coding */ 581 /* Here can be also 8 bit coding */
577 } 582 }
578 Coding = SMS_Coding_Default; 583 Coding = SMS_Coding_Default;
579 memcpy(Buffer2,Buffer,Length); 584 memcpy(Buffer2,Buffer,Length);
580 EncodeUnicode(Buffer,Buffer2,Length); 585 EncodeUnicode(Buffer,Buffer2,Length);
581 break; 586 break;
582 case SMS_VCARD10Long: 587 case SMS_VCARD10Long:
583 GSM_EncodeVCARD(Buffer,&Length,Info->Entries[0].Phonebook,true,Nokia_VCard10); 588 GSM_EncodeVCARD(Buffer,&Length,Info->Entries[0].Phonebook,true,Nokia_VCard10);
584 if (Length>GSM_MAX_SMS_LENGTH) UDH = UDH_ConcatenatedMessages; 589 if (Length>GSM_MAX_SMS_LENGTH) UDH = UDH_ConcatenatedMessages;
585 Coding = SMS_Coding_Default; 590 Coding = SMS_Coding_Default;
586 memcpy(Buffer2,Buffer,Length); 591 memcpy(Buffer2,Buffer,Length);
587 EncodeUnicode(Buffer,Buffer2,Length); 592 EncodeUnicode(Buffer,Buffer2,Length);
588 break; 593 break;
589 case SMS_VCARD21Long: 594 case SMS_VCARD21Long:
590 GSM_EncodeVCARD(Buffer,&Length,Info->Entries[0].Phonebook,true,Nokia_VCard21); 595 GSM_EncodeVCARD(Buffer,&Length,Info->Entries[0].Phonebook,true,Nokia_VCard21);
591 if (Length>GSM_MAX_SMS_LENGTH) UDH = UDH_ConcatenatedMessages; 596 if (Length>GSM_MAX_SMS_LENGTH) UDH = UDH_ConcatenatedMessages;
592 Coding = SMS_Coding_Default; 597 Coding = SMS_Coding_Default;
593 memcpy(Buffer2,Buffer,Length); 598 memcpy(Buffer2,Buffer,Length);
594 EncodeUnicode(Buffer,Buffer2,Length); 599 EncodeUnicode(Buffer,Buffer2,Length);
595 break; 600 break;
596 case SMS_NokiaVCALENDAR10Long: 601 case SMS_NokiaVCALENDAR10Long:
597 error=GSM_EncodeVCALENDAR(Buffer,&Length,Info->Entries[0].Calendar,true,Nokia_VCalendar); 602 error=GSM_EncodeVCALENDAR(Buffer,&Length,Info->Entries[0].Calendar,true,Nokia_VCalendar);
598 if (error != ERR_NONE) return error; 603 if (error != ERR_NONE) return error;
599 /* Is 1 SMS ? 8 = length of ..SCKE4 */ 604 /* Is 1 SMS ? 8 = length of ..SCKE4 */
600 if (Length<=GSM_MAX_SMS_LENGTH-8) { 605 if (Length<=GSM_MAX_SMS_LENGTH-8) {
601 sprintf(Buffer,"//SCKE4 "); 606 sprintf(Buffer,"//SCKE4 ");
602 Length = 8; 607 Length = 8;
603 GSM_EncodeVCALENDAR(Buffer,&Length,Info->Entries[0].Calendar,true,Nokia_VCalendar); 608 GSM_EncodeVCALENDAR(Buffer,&Length,Info->Entries[0].Calendar,true,Nokia_VCalendar);
604 } else { 609 } else {
605 UDH = UDH_NokiaCalendarLong; 610 UDH = UDH_NokiaCalendarLong;
606 /* can be here 8 bit coding ? */ 611 /* can be here 8 bit coding ? */
607 } 612 }
608 Coding = SMS_Coding_Default; 613 Coding = SMS_Coding_Default;
609 memcpy(Buffer2,Buffer,Length); 614 memcpy(Buffer2,Buffer,Length);
610 EncodeUnicode(Buffer,Buffer2,Length); 615 EncodeUnicode(Buffer,Buffer2,Length);
611 break; 616 break;
612 case SMS_NokiaVTODOLong: 617 case SMS_NokiaVTODOLong:
613 error=GSM_EncodeVTODO(Buffer,&Length,Info->Entries[0].ToDo,true,Nokia_VToDo); 618 error=GSM_EncodeVTODO(Buffer,&Length,Info->Entries[0].ToDo,true,Nokia_VToDo);
614 if (error != ERR_NONE) return error; 619 if (error != ERR_NONE) return error;
615 UDH = UDH_NokiaCalendarLong; 620 UDH = UDH_NokiaCalendarLong;
616 Coding = SMS_Coding_Default; 621 Coding = SMS_Coding_Default;
617 memcpy(Buffer2,Buffer,Length); 622 memcpy(Buffer2,Buffer,Length);
618 EncodeUnicode(Buffer,Buffer2,Length); 623 EncodeUnicode(Buffer,Buffer2,Length);
619 break; 624 break;
620 case SMS_DisableVoice: 625 case SMS_DisableVoice:
621 case SMS_DisableFax: 626 case SMS_DisableFax:
622 case SMS_DisableEmail: 627 case SMS_DisableEmail:
623 case SMS_EnableVoice: 628 case SMS_EnableVoice:
624 case SMS_EnableFax: 629 case SMS_EnableFax:
625 case SMS_EnableEmail: 630 case SMS_EnableEmail:
626 case SMS_VoidSMS: 631 case SMS_VoidSMS:
627 case SMS_Text: 632 case SMS_Text:
628 Class = Info->Class; 633 Class = Info->Class;
629 switch (Info->Entries[0].ID) { 634 switch (Info->Entries[0].ID) {
630 case SMS_DisableVoice: UDH = UDH_DisableVoice; break; 635 case SMS_DisableVoice: UDH = UDH_DisableVoice; break;
631 case SMS_DisableFax : UDH = UDH_DisableFax; break; 636 case SMS_DisableFax : UDH = UDH_DisableFax; break;
632 case SMS_DisableEmail: UDH = UDH_DisableEmail; break; 637 case SMS_DisableEmail: UDH = UDH_DisableEmail; break;
633 case SMS_EnableVoice: UDH = UDH_EnableVoice; break; 638 case SMS_EnableVoice: UDH = UDH_EnableVoice; break;
634 case SMS_EnableFax : UDH = UDH_EnableFax; break; 639 case SMS_EnableFax : UDH = UDH_EnableFax; break;
635 case SMS_EnableEmail: UDH = UDH_EnableEmail; break; 640 case SMS_EnableEmail: UDH = UDH_EnableEmail; break;
636 case SMS_VoidSMS : UDH = UDH_VoidSMS; break; 641 case SMS_VoidSMS : UDH = UDH_VoidSMS; break;
637 case SMS_Text : UDH = UDH_NoUDH; break; 642 case SMS_Text : UDH = UDH_NoUDH; break;
638 default : break; 643 default : break;
639 } 644 }
640 UDHHeader.Type = UDH; 645 UDHHeader.Type = UDH;
641 GSM_EncodeUDHHeader(&UDHHeader); 646 GSM_EncodeUDHHeader(&UDHHeader);
642 memcpy(Buffer,Info->Entries[0].Buffer,UnicodeLength(Info->Entries[0].Buffer)*2+2); 647 memcpy(Buffer,Info->Entries[0].Buffer,UnicodeLength(Info->Entries[0].Buffer)*2+2);
643 if (Info->UnicodeCoding) { 648 if (Info->UnicodeCoding) {
644 Coding = SMS_Coding_Unicode; 649 Coding = SMS_Coding_Unicode;
645 Length = UnicodeLength(Info->Entries[0].Buffer); 650 Length = UnicodeLength(Info->Entries[0].Buffer);
646 if (Length>(140-UDHHeader.Length)/2) Length = (140-UDHHeader.Length)/2; 651 if (Length>(140-UDHHeader.Length)/2) Length = (140-UDHHeader.Length)/2;
647 } else { 652 } else {
648 Coding = SMS_Coding_Default; 653 Coding = SMS_Coding_Default;
649 FindDefaultAlphabetLen(Info->Entries[0].Buffer,&Length,&smslen,(GSM_MAX_8BIT_SMS_LENGTH-UDHHeader.Length)*8/7); 654 FindDefaultAlphabetLen(Info->Entries[0].Buffer,&Length,&smslen,(GSM_MAX_8BIT_SMS_LENGTH-UDHHeader.Length)*8/7);
650 } 655 }
651 break; 656 break;
652 case SMS_ConcatenatedAutoTextLong: 657 case SMS_ConcatenatedAutoTextLong:
653 case SMS_ConcatenatedAutoTextLong16bit: 658 case SMS_ConcatenatedAutoTextLong16bit:
654 smslen = UnicodeLength(Info->Entries[0].Buffer); 659 smslen = UnicodeLength(Info->Entries[0].Buffer);
655 memcpy(Buffer,Info->Entries[0].Buffer,smslen*2); 660 memcpy(Buffer,Info->Entries[0].Buffer,smslen*2);
656 EncodeDefault(Buffer2, Buffer, &smslen, true, NULL); 661 EncodeDefault(Buffer2, Buffer, &smslen, true, NULL);
657 DecodeDefault(Buffer, Buffer2, smslen, true, NULL); 662 DecodeDefault(Buffer, Buffer2, smslen, true, NULL);
658#ifdef DEBUG 663#ifdef DEBUG
659 if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) { 664 if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) {
660 dbgprintf("Info->Entries[0].Buffer:\n"); 665 dbgprintf("Info->Entries[0].Buffer:\n");
661 DumpMessage(di.df, di.dl, Info->Entries[0].Buffer, UnicodeLength(Info->Entries[0].Buffer)*2); 666 DumpMessage(di.df, di.dl, Info->Entries[0].Buffer, UnicodeLength(Info->Entries[0].Buffer)*2);
662 dbgprintf("Buffer:\n"); 667 dbgprintf("Buffer:\n");
663 DumpMessage(di.df, di.dl, Buffer, UnicodeLength(Buffer)*2); 668 DumpMessage(di.df, di.dl, Buffer, UnicodeLength(Buffer)*2);
664 } 669 }
665#endif 670#endif
666 Info->UnicodeCoding = false; 671 Info->UnicodeCoding = false;
667 for (smslen=0;smslen<(int)(UnicodeLength(Info->Entries[0].Buffer)*2);smslen++) { 672 for (smslen=0;smslen<(int)(UnicodeLength(Info->Entries[0].Buffer)*2);smslen++) {
668 if (Info->Entries[0].Buffer[smslen] != Buffer[smslen]) { 673 if (Info->Entries[0].Buffer[smslen] != Buffer[smslen]) {
669 Info->UnicodeCoding = true; 674 Info->UnicodeCoding = true;
670 dbgprintf("Setting to Unicode %i\n",smslen); 675 dbgprintf("Setting to Unicode %i\n",smslen);
671 break; 676 break;
672 } 677 }
673 } 678 }
674 /* No break here - we go to the SMS_ConcatenatedTextLong */ 679 /* No break here - we go to the SMS_ConcatenatedTextLong */
675 case SMS_ConcatenatedTextLong: 680 case SMS_ConcatenatedTextLong:
676 case SMS_ConcatenatedTextLong16bit: 681 case SMS_ConcatenatedTextLong16bit:
677 Class = Info->Class; 682 Class = Info->Class;
678 memcpy(Buffer,Info->Entries[0].Buffer,UnicodeLength(Info->Entries[0].Buffer)*2+2); 683 memcpy(Buffer,Info->Entries[0].Buffer,UnicodeLength(Info->Entries[0].Buffer)*2+2);
679 UDH = UDH_NoUDH; 684 UDH = UDH_NoUDH;
680 if (Info->UnicodeCoding) { 685 if (Info->UnicodeCoding) {
681 Coding = SMS_Coding_Unicode; 686 Coding = SMS_Coding_Unicode;
diff --git a/gammu/emb/common/service/sms/gsmmulti.h b/gammu/emb/common/service/sms/gsmmulti.h
index c672261..3f70d81 100644
--- a/gammu/emb/common/service/sms/gsmmulti.h
+++ b/gammu/emb/common/service/sms/gsmmulti.h
@@ -1,271 +1,280 @@
1/* (c) 2002-2004 by Marcin Wiacek */ 1/* (c) 2002-2004 by Marcin Wiacek */
2 2
3#ifndef __gsm_multi_h 3#ifndef __gsm_multi_h
4#define __gsm_multi_h 4#define __gsm_multi_h
5 5
6#if defined(_MSC_VER) && defined(__cplusplus)
7 extern "C" {
8#endif
9
6#include "../../gsmcomon.h" 10#include "../../gsmcomon.h"
7#include "../gsmlogo.h" 11#include "../gsmlogo.h"
8#include "../gsmcal.h" 12#include "../gsmcal.h"
9#include "../gsmpbk.h" 13#include "../gsmpbk.h"
10#include "../gsmdata.h" 14#include "../gsmdata.h"
11#include "../gsmring.h" 15#include "../gsmring.h"
12#include "gsmsms.h" 16#include "gsmsms.h"
13 17
14/* ---------------------- multi SMS --------------------------------------- */ 18/* ---------------------- multi SMS --------------------------------------- */
15 19
16/* Identifiers for Smart Messaging 3.0 multipart SMS */ 20/* Identifiers for Smart Messaging 3.0 multipart SMS */
17 21
18#define SM30_ISOTEXT 0 /* ISO 8859-1 text */ 22#define SM30_ISOTEXT 0 /* ISO 8859-1 text */
19#define SM30_UNICODETEXT 1 23#define SM30_UNICODETEXT 1
20 #define SM30_OTA 2 24 #define SM30_OTA 2
21#define SM30_RINGTONE 3 25#define SM30_RINGTONE 3
22#define SM30_PROFILENAME 4 26#define SM30_PROFILENAME 4
23/* ... */ 27/* ... */
24#define SM30_SCREENSAVER 6 28#define SM30_SCREENSAVER 6
25 29
26/* Identifiers for Alcatel Terminal Data Download */ 30/* Identifiers for Alcatel Terminal Data Download */
27#define ALCATELTDD_PICTURE 4 31#define ALCATELTDD_PICTURE 4
28#define ALCATELTDD_ANIMATION 5 32#define ALCATELTDD_ANIMATION 5
29#define ALCATELTDD_SMSTEMPLATE 6 33#define ALCATELTDD_SMSTEMPLATE 6
30 34
31 void GSM_SMSCounter(int MessageLength, 35 void GSM_SMSCounter(int MessageLength,
32 unsigned char *MessageBuffer, 36 unsigned char *MessageBuffer,
33 GSM_UDH UDHType, 37 GSM_UDH UDHType,
34 GSM_Coding_Type Coding, 38 GSM_Coding_Type Coding,
35 int *SMSNum, 39 int *SMSNum,
36 int *CharsLeft); 40 int *CharsLeft);
37 41
38#define MAX_MULTI_SMS 10 42#define MAX_MULTI_SMS 10
39 43
40/** 44/**
41 * Multiple SMS messages, used for Smart Messaging 3.0/EMS. 45 * Multiple SMS messages, used for Smart Messaging 3.0/EMS.
42 */ 46 */
43typedef struct { 47typedef struct {
44 /** 48 /**
45 * Sender or recipient number. 49 * Sender or recipient number.
46 */ 50 */
47 unsigned char Number; 51 unsigned char Number;
48 /** 52 /**
49 * Array of SMSes. 53 * Array of SMSes.
50 */ 54 */
51 GSM_SMSMessage SMS[MAX_MULTI_SMS]; 55 GSM_SMSMessage SMS[MAX_MULTI_SMS];
52} GSM_MultiSMSMessage; 56} GSM_MultiSMSMessage;
53 57
54GSM_Error GSM_AddSMS_Text_UDH(GSM_MultiSMSMessage *SMS, 58GSM_Error GSM_AddSMS_Text_UDH(GSM_MultiSMSMessage *SMS,
55 GSM_Coding_Type Coding, 59 GSM_Coding_Type Coding,
56 char *Buffer, 60 char *Buffer,
57 int BufferLen, 61 int BufferLen,
58 bool UDH, 62 bool UDH,
59 int *UsedText, 63 int *UsedText,
60 int *CopiedText, 64 int *CopiedText,
61 int *CopiedSMSText); 65 int *CopiedSMSText);
62 66
63void GSM_MakeMultiPartSMS(GSM_MultiSMSMessage *SMS, 67void GSM_MakeMultiPartSMS(GSM_MultiSMSMessage *SMS,
64 unsigned char *MessageBuffer, 68 unsigned char *MessageBuffer,
65 int MessageLength, 69 int MessageLength,
66 GSM_UDH UDHType, 70 GSM_UDH UDHType,
67 GSM_Coding_Type Coding, 71 GSM_Coding_Type Coding,
68 int Class, 72 int Class,
69 unsigned char RejectDuplicates); 73 unsigned char RejectDuplicates);
70 74
71void GSM_Find_Free_Used_SMS2(GSM_Coding_Type Coding,GSM_SMSMessage SMS, int *UsedText, int *FreeText, int *FreeBytes); 75void GSM_Find_Free_Used_SMS2(GSM_Coding_Type Coding,GSM_SMSMessage SMS, int *UsedText, int *FreeText, int *FreeBytes);
72 76
73unsigned char GSM_MakeSMSIDFromTime(void); 77unsigned char GSM_MakeSMSIDFromTime(void);
74 78
75/** 79/**
76 * ID during packing SMS for Smart Messaging 3.0, EMS and other 80 * ID during packing SMS for Smart Messaging 3.0, EMS and other
77 */ 81 */
78typedef enum { 82typedef enum {
79 /** 83 /**
80 * 1 text SMS. 84 * 1 text SMS.
81 */ 85 */
82 SMS_Text = 1, 86 SMS_Text = 1,
83 /** 87 /**
84 * Contacenated SMS, when longer than 1 SMS. 88 * Contacenated SMS, when longer than 1 SMS.
85 */ 89 */
86 SMS_ConcatenatedTextLong, 90 SMS_ConcatenatedTextLong,
87 /** 91 /**
88 * Contacenated SMS, auto Default/Unicode coding. 92 * Contacenated SMS, auto Default/Unicode coding.
89 */ 93 */
90 SMS_ConcatenatedAutoTextLong, 94 SMS_ConcatenatedAutoTextLong,
91 SMS_ConcatenatedTextLong16bit, 95 SMS_ConcatenatedTextLong16bit,
92 SMS_ConcatenatedAutoTextLong16bit, 96 SMS_ConcatenatedAutoTextLong16bit,
93 /** 97 /**
94 * Nokia profile = Name, Ringtone, ScreenSaver 98 * Nokia profile = Name, Ringtone, ScreenSaver
95 */ 99 */
96 SMS_NokiaProfileLong, 100 SMS_NokiaProfileLong,
97 /** 101 /**
98 * Nokia Picture Image + (text) 102 * Nokia Picture Image + (text)
99 */ 103 */
100 SMS_NokiaPictureImageLong, 104 SMS_NokiaPictureImageLong,
101 /** 105 /**
102 * Nokia screen saver + (text) 106 * Nokia screen saver + (text)
103 */ 107 */
104 SMS_NokiaScreenSaverLong, 108 SMS_NokiaScreenSaverLong,
105 /** 109 /**
106 * Nokia ringtone - old SM2.0 format, 1 SMS 110 * Nokia ringtone - old SM2.0 format, 1 SMS
107 */ 111 */
108 SMS_NokiaRingtone, 112 SMS_NokiaRingtone,
109 /** 113 /**
110 * Nokia ringtone contacenated, when very long 114 * Nokia ringtone contacenated, when very long
111 */ 115 */
112 SMS_NokiaRingtoneLong, 116 SMS_NokiaRingtoneLong,
113 /** 117 /**
114 * Nokia 72x14 operator logo, 1 SMS 118 * Nokia 72x14 operator logo, 1 SMS
115 */ 119 */
116 SMS_NokiaOperatorLogo, 120 SMS_NokiaOperatorLogo,
117 /** 121 /**
118 * Nokia 72x14 op logo or 78x21 in 2 SMS 122 * Nokia 72x14 op logo or 78x21 in 2 SMS
119 */ 123 */
120 SMS_NokiaOperatorLogoLong, 124 SMS_NokiaOperatorLogoLong,
121 /** 125 /**
122 * Nokia 72x14 caller logo, 1 SMS 126 * Nokia 72x14 caller logo, 1 SMS
123 */ 127 */
124 SMS_NokiaCallerLogo, 128 SMS_NokiaCallerLogo,
125 /** 129 /**
126 * Nokia WAP bookmark in 1 or 2 SMS 130 * Nokia WAP bookmark in 1 or 2 SMS
127 */ 131 */
128 SMS_NokiaWAPBookmarkLong, 132 SMS_NokiaWAPBookmarkLong,
129 /** 133 /**
130 * Nokia WAP settings in 2 SMS 134 * Nokia WAP settings in 2 SMS
131 */ 135 */
132 SMS_NokiaWAPSettingsLong, 136 SMS_NokiaWAPSettingsLong,
133 /** 137 /**
134 * Nokia MMS settings in 2 SMS 138 * Nokia MMS settings in 2 SMS
135 */ 139 */
136 SMS_NokiaMMSSettingsLong, 140 SMS_NokiaMMSSettingsLong,
137 /** 141 /**
138 * Nokia VCARD 1.0 - only name and default number 142 * Nokia VCARD 1.0 - only name and default number
139 */ 143 */
140 SMS_NokiaVCARD10Long, 144 SMS_NokiaVCARD10Long,
141 /** 145 /**
142 * Nokia VCARD 2.1 - all numbers + text 146 * Nokia VCARD 2.1 - all numbers + text
143 */ 147 */
144 SMS_NokiaVCARD21Long, 148 SMS_NokiaVCARD21Long,
145 /** 149 /**
146 * Nokia VCALENDAR 1.0 - can be in few sms 150 * Nokia VCALENDAR 1.0 - can be in few sms
147 */ 151 */
148 SMS_NokiaVCALENDAR10Long, 152 SMS_NokiaVCALENDAR10Long,
149 SMS_NokiaVTODOLong, 153 SMS_NokiaVTODOLong,
150 SMS_VCARD10Long, 154 SMS_VCARD10Long,
151 SMS_VCARD21Long, 155 SMS_VCARD21Long,
152 SMS_DisableVoice, 156 SMS_DisableVoice,
153 SMS_DisableFax, 157 SMS_DisableFax,
154 SMS_DisableEmail, 158 SMS_DisableEmail,
155 SMS_EnableVoice, 159 SMS_EnableVoice,
156 SMS_EnableFax, 160 SMS_EnableFax,
157 SMS_EnableEmail, 161 SMS_EnableEmail,
158 SMS_VoidSMS, 162 SMS_VoidSMS,
159 /** 163 /**
160 * IMelody 1.0 164 * IMelody 1.0
161 */ 165 */
162 SMS_EMSSound10, 166 SMS_EMSSound10,
163 /** 167 /**
164 * IMelody 1.2 168 * IMelody 1.2
165 */ 169 */
166 SMS_EMSSound12, 170 SMS_EMSSound12,
167 /** 171 /**
168 * IMelody without header - SonyEricsson extension 172 * IMelody without header - SonyEricsson extension
169 */ 173 */
170 SMS_EMSSonyEricssonSound, 174 SMS_EMSSonyEricssonSound,
171 /** 175 /**
172 * IMelody 1.0 with UPI. 176 * IMelody 1.0 with UPI.
173 */ 177 */
174 SMS_EMSSound10Long, 178 SMS_EMSSound10Long,
175 /*** 179 /**
176 * IMelody 1.2 with UPI. 180 * IMelody 1.2 with UPI.
177 */ 181 */
178 SMS_EMSSound12Long, 182 SMS_EMSSound12Long,
179 /** 183 /**
180 * IMelody without header with UPI. 184 * IMelody without header with UPI.
181 */ 185 */
182 SMS_EMSSonyEricssonSoundLong, 186 SMS_EMSSonyEricssonSoundLong,
183 SMS_EMSPredefinedSound, 187 SMS_EMSPredefinedSound,
184 SMS_EMSPredefinedAnimation, 188 SMS_EMSPredefinedAnimation,
185 SMS_EMSAnimation, 189 SMS_EMSAnimation,
186 /** 190 /**
187 * Fixed bitmap of size 16x16 or 32x32. 191 * Fixed bitmap of size 16x16 or 32x32.
188 */ 192 */
189 SMS_EMSFixedBitmap, 193 SMS_EMSFixedBitmap,
190 SMS_EMSVariableBitmap, 194 SMS_EMSVariableBitmap,
191 SMS_EMSVariableBitmapLong, 195 SMS_EMSVariableBitmapLong,
192 SMS_MMSIndicatorLong, 196 SMS_MMSIndicatorLong,
197 SMS_WAPIndicatorLong,
193 /** 198 /**
194 * Variable bitmap with black and white colors 199 * Variable bitmap with black and white colors
195 */ 200 */
196 SMS_AlcatelMonoBitmapLong, 201 SMS_AlcatelMonoBitmapLong,
197 /** 202 /**
198 * Variable animation with black and white colors 203 * Variable animation with black and white colors
199 */ 204 */
200 SMS_AlcatelMonoAnimationLong, 205 SMS_AlcatelMonoAnimationLong,
201 SMS_AlcatelSMSTemplateName 206 SMS_AlcatelSMSTemplateName
202} EncodeMultiPartSMSID; 207} EncodeMultiPartSMSID;
203 208
204typedef struct { 209typedef struct {
205 EncodeMultiPartSMSID ID; 210 EncodeMultiPartSMSID ID;
206 211
207 int Number; 212 int Number;
208 GSM_Ringtone *Ringtone; 213 GSM_Ringtone *Ringtone;
209 GSM_MultiBitmap *Bitmap; 214 GSM_MultiBitmap *Bitmap;
210 GSM_WAPBookmark *Bookmark; 215 GSM_WAPBookmark *Bookmark;
211 GSM_WAPSettings *Settings; 216 GSM_WAPSettings *Settings;
212 GSM_MMSIndicator*MMSIndicator; 217 GSM_MMSIndicator*MMSIndicator;
213 GSM_MemoryEntry *Phonebook; 218 GSM_MemoryEntry *Phonebook;
214 GSM_CalendarEntry *Calendar; 219 GSM_CalendarEntry *Calendar;
215 GSM_ToDoEntry *ToDo; 220 GSM_ToDoEntry *ToDo;
216 bool Protected; 221 bool Protected;
217 222
218 unsigned char *Buffer; 223 unsigned char *Buffer;
219 bool Left; 224 bool Left;
220 bool Right; 225 bool Right;
221 bool Center; 226 bool Center;
222 bool Large; 227 bool Large;
223 bool Small; 228 bool Small;
224 bool Bold; 229 bool Bold;
225 bool Italic; 230 bool Italic;
226 bool Underlined; 231 bool Underlined;
227 bool Strikethrough; 232 bool Strikethrough;
228 233
229 /* Return values */ 234 /* Return values */
230 int RingtoneNotes; 235 int RingtoneNotes;
231} MultiPartSMSEntry; 236} MultiPartSMSEntry;
232 237
233typedef struct { 238typedef struct {
234 MultiPartSMSEntryEntries[MAX_MULTI_SMS]; 239 MultiPartSMSEntryEntries[MAX_MULTI_SMS];
235 int EntriesNum; 240 int EntriesNum;
236 bool UnicodeCoding; 241 bool UnicodeCoding;
237 int Class; 242 int Class;
238 unsigned char ReplaceMessage; 243 unsigned char ReplaceMessage;
239 bool Unknown; 244 bool Unknown;
240} GSM_MultiPartSMSInfo; 245} GSM_MultiPartSMSInfo;
241 246
242/** 247/**
243 * Encodes multi part SMS from "readable" format. 248 * Encodes multi part SMS from "readable" format.
244 */ 249 */
245GSM_Error GSM_EncodeMultiPartSMS (GSM_MultiPartSMSInfo *Info, GSM_MultiSMSMessage *SMS); 250GSM_Error GSM_EncodeMultiPartSMS (GSM_MultiPartSMSInfo *Info, GSM_MultiSMSMessage *SMS);
246 251
247/** 252/**
248 * Decodes multi part SMS to "readable" format. 253 * Decodes multi part SMS to "readable" format.
249 */ 254 */
250bool GSM_DecodeMultiPartSMS (GSM_MultiPartSMSInfo *Info, GSM_MultiSMSMessage *SMS, bool ems); 255bool GSM_DecodeMultiPartSMS (GSM_MultiPartSMSInfo *Info, GSM_MultiSMSMessage *SMS, bool ems);
251 256
252/** 257/**
253 * Clears @ref GSM_MultiPartSMSInfo to default values. 258 * Clears @ref GSM_MultiPartSMSInfo to default values.
254 */ 259 */
255void GSM_ClearMultiPartSMSInfo (GSM_MultiPartSMSInfo *Info); 260void GSM_ClearMultiPartSMSInfo (GSM_MultiPartSMSInfo *Info);
256 261
257/** 262/**
258 * Frees any allocated structures inside @ref GSM_MultiPartSMSInfo. 263 * Frees any allocated structures inside @ref GSM_MultiPartSMSInfo.
259 */ 264 */
260void GSM_FreeMultiPartSMSInfo (GSM_MultiPartSMSInfo *Info); 265void GSM_FreeMultiPartSMSInfo (GSM_MultiPartSMSInfo *Info);
261 266
262/** 267/**
263 * Links SMS messages according to IDs. 268 * Links SMS messages according to IDs.
264 */ 269 */
265GSM_Error GSM_LinkSMS(GSM_MultiSMSMessage **INPUT, GSM_MultiSMSMessage **OUTPUT, bool ems); 270GSM_Error GSM_LinkSMS(GSM_MultiSMSMessage **INPUT, GSM_MultiSMSMessage **OUTPUT, bool ems);
266 271
272#if defined(_MSC_VER) && defined(__cplusplus)
273 }
274#endif
275
267#endif 276#endif
268 277
269/* How should editor hadle tabs in this file? Add editor commands here. 278/* How should editor hadle tabs in this file? Add editor commands here.
270 * vim: noexpandtab sw=8 ts=8 sts=8: 279 * vim: noexpandtab sw=8 ts=8 sts=8:
271 */ 280 */
diff --git a/gammu/emb/common/service/sms/gsmsms.c b/gammu/emb/common/service/sms/gsmsms.c
index 9920835..feceba4 100644
--- a/gammu/emb/common/service/sms/gsmsms.c
+++ b/gammu/emb/common/service/sms/gsmsms.c
@@ -1,194 +1,197 @@
1/* (c) 2001-2004 by Marcin Wiacek */ 1/* (c) 2001-2004 by Marcin Wiacek */
2/* based on some work from Pawel Kot, others and Gnokii */ 2/* Based on some Pawel Kot and others work from Gnokii (www.gnokii.org)
3 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
4 * GNU GPL version 2 or later
5 */
3 6
4#include <ctype.h> 7#include <ctype.h>
5#include <string.h> 8#include <string.h>
6#include <time.h> 9#include <time.h>
7 10
8#include "../../gsmcomon.h" 11#include "../../gsmcomon.h"
9#include "../../misc/coding/coding.h" 12#include "../../misc/coding/coding.h"
10#include "../gsmcal.h" 13#include "../gsmcal.h"
11#include "../gsmpbk.h" 14#include "../gsmpbk.h"
12#include "../gsmlogo.h" 15#include "../gsmlogo.h"
13#include "../gsmring.h" 16#include "../gsmring.h"
14#include "../gsmdata.h" 17#include "../gsmdata.h"
15#include "../gsmnet.h" 18#include "../gsmnet.h"
16#include "gsmsms.h" 19#include "gsmsms.h"
17 20
18/* User data headers */ 21/* User data headers */
19static GSM_UDHHeader UDHHeaders[] = { 22static GSM_UDHHeader UDHHeaders[] = {
20 /* See GSM 03.40 section 9.2.3.24.1 23 /* See GSM 03.40 section 9.2.3.24.1
21 * 1 byte 0x00 24 * 1 byte 0x00
22 * 1 byte 0x03 25 * 1 byte 0x03
23 * 1 byte 0x01: unique ID for message series 26 * 1 byte 0x01: unique ID for message series
24 * 1 byte 0x00: how many SMS in sequence 27 * 1 byte 0x00: how many SMS in sequence
25 * 1 byte 0x00: number of current SMS in sequence */ 28 * 1 byte 0x00: number of current SMS in sequence */
26 { UDH_ConcatenatedMessages, 0x05, "\x00\x03\x01\x00\x00",2,-1,4,3}, 29 { UDH_ConcatenatedMessages, 0x05, "\x00\x03\x01\x00\x00",2,-1,4,3},
27 30
28 /* See GSM 03.40 section 9.2.3.24.2 for voice, fax and email messages */ 31 /* See GSM 03.40 section 9.2.3.24.2 for voice, fax and email messages */
29 { UDH_DisableVoice, 0x04, "\x01\x02\x00\x00",-1,-1,-1,-1}, 32 { UDH_DisableVoice, 0x04, "\x01\x02\x00\x00",-1,-1,-1,-1},
30 { UDH_DisableFax, 0x04, "\x01\x02\x01\x00",-1,-1,-1,-1}, 33 { UDH_DisableFax, 0x04, "\x01\x02\x01\x00",-1,-1,-1,-1},
31 { UDH_DisableEmail, 0x04, "\x01\x02\x02\x00",-1,-1,-1,-1}, 34 { UDH_DisableEmail, 0x04, "\x01\x02\x02\x00",-1,-1,-1,-1},
32 { UDH_EnableVoice, 0x04, "\x01\x02\x00\x01",-1,-1,-1,-1}, 35 { UDH_EnableVoice, 0x04, "\x01\x02\x00\x01",-1,-1,-1,-1},
33 { UDH_EnableFax, 0x04, "\x01\x02\x01\x01",-1,-1,-1,-1}, 36 { UDH_EnableFax, 0x04, "\x01\x02\x01\x01",-1,-1,-1,-1},
34 { UDH_EnableEmail, 0x04, "\x01\x02\x02\x01",-1,-1,-1,-1}, 37 { UDH_EnableEmail, 0x04, "\x01\x02\x02\x01",-1,-1,-1,-1},
35 38
36 /* When send such SMS to some phones, they don't display anything, 39 /* When send such SMS to some phones, they don't display anything,
37 * only beep and enable vibra/light 40 * only beep and enable vibra/light
38 */ 41 */
39 { UDH_VoidSMS, 0x08, "\x01\x02\x02\x01\x01\x02\x02\x00",-1,-1,-1,-1}, 42 { UDH_VoidSMS, 0x08, "\x01\x02\x02\x01\x01\x02\x02\x00",-1,-1,-1,-1},
40 43
41 /* Nokia Smart Messaging (short version) UDH 44 /* Nokia Smart Messaging (short version) UDH
42 * General format : 45 * General format :
43 * 1 byte 0x05 : IEI application port addressing scheme, 16 bit address 46 * 1 byte 0x05 : IEI application port addressing scheme, 16 bit address
44 * 1 byte 0x04 : IEI length 47 * 1 byte 0x04 : IEI length
45 * 2 bytes : destination address : high & low byte 48 * 2 bytes : destination address : high & low byte
46 * 2 bytes 0x00 0x00 : originator address : high & low byte */ 49 * 2 bytes 0x00 0x00 : originator address : high & low byte */
47 { UDH_NokiaRingtone, 0x06, "\x05\x04\x15\x81\x00\x00",-1,-1,-1,-1}, 50 { UDH_NokiaRingtone, 0x06, "\x05\x04\x15\x81\x00\x00",-1,-1,-1,-1},
48 { UDH_NokiaOperatorLogo, 0x06, "\x05\x04\x15\x82\x00\x00",-1,-1,-1,-1}, 51 { UDH_NokiaOperatorLogo, 0x06, "\x05\x04\x15\x82\x00\x00",-1,-1,-1,-1},
49 { UDH_NokiaCallerLogo, 0x06, "\x05\x04\x15\x83\x00\x00",-1,-1,-1,-1}, 52 { UDH_NokiaCallerLogo, 0x06, "\x05\x04\x15\x83\x00\x00",-1,-1,-1,-1},
50 { UDH_NokiaWAP, 0x06, "\x05\x04\xc3\x4f\x00\x00",-1,-1,-1,-1}, 53 { UDH_NokiaWAP, 0x06, "\x05\x04\xc3\x4f\x00\x00",-1,-1,-1,-1},
51 54
52 /* Nokia Smart Messaging (long version) UDH and other 55 /* Nokia Smart Messaging (long version) UDH and other
53 * General format: 56 * General format:
54 * 1 byte 0x05 : IEI application port addressing scheme, 16 bit address 57 * 1 byte 0x05 : IEI application port addressing scheme, 16 bit address
55 * 1 byte 0x04 : IEI length 58 * 1 byte 0x04 : IEI length
56 * 2 bytes 0x00 0x00 : destination address : high & low byte 59 * 2 bytes 0x00 0x00 : destination address : high & low byte
57 * 2 bytes 0x00 0x00 : originator address : high & low byte 60 * 2 bytes 0x00 0x00 : originator address : high & low byte
58 * 1 byte 0x00 : SAR 61 * 1 byte 0x00 : SAR
59 * 1 byte 0x03 : SAR length 62 * 1 byte 0x03 : SAR length
60 * 1 byte : diagram reference number (unique ID for message series) 63 * 1 byte : diagram reference number (unique ID for message series)
61 * 1 byte : number of all SMS 64 * 1 byte : number of all SMS
62 * 1 byte : number of current SMS */ 65 * 1 byte : number of current SMS */
63 { UDH_NokiaCalendarLong, 0x0b, "\x05\x04\x00\xe4\x00\x00\x00\x03\xc7\x00\x00",8,-1,10,9}, 66 { UDH_NokiaCalendarLong, 0x0b, "\x05\x04\x00\xe4\x00\x00\x00\x03\xc7\x00\x00",8,-1,10,9},
64 { UDH_MMSIndicatorLong, 0x0b, "\x05\x04\x0b\x84\x23\xf0\x00\x03\xe5\x00\x00",8,-1,10,9}, 67 { UDH_MMSIndicatorLong, 0x0b, "\x05\x04\x0b\x84\x23\xf0\x00\x03\xe5\x00\x00",8,-1,10,9},
65 { UDH_NokiaRingtoneLong, 0x0b, "\x05\x04\x15\x81\x00\x00\x00\x03\x01\x00\x00",8,-1,10,9}, 68 { UDH_NokiaRingtoneLong, 0x0b, "\x05\x04\x15\x81\x00\x00\x00\x03\x01\x00\x00",8,-1,10,9},
66 { UDH_NokiaOperatorLogoLong, 0x0b, "\x05\x04\x15\x82\x00\x00\x00\x03\x02\x00\x00",8,-1,10,9}, 69 { UDH_NokiaOperatorLogoLong, 0x0b, "\x05\x04\x15\x82\x00\x00\x00\x03\x02\x00\x00",8,-1,10,9},
67 { UDH_NokiaProfileLong, 0x0b, "\x05\x04\x15\x8a\x00\x00\x00\x03\xce\x00\x00",8,-1,10,9}, 70 { UDH_NokiaProfileLong, 0x0b, "\x05\x04\x15\x8a\x00\x00\x00\x03\xce\x00\x00",8,-1,10,9},
68 { UDH_NokiaPhonebookLong, 0x0b, "\x05\x04\x23\xf4\x00\x00\x00\x03\x01\x00\x00",8,-1,10,9}, 71 { UDH_NokiaPhonebookLong, 0x0b, "\x05\x04\x23\xf4\x00\x00\x00\x03\x01\x00\x00",8,-1,10,9},
69 { UDH_NokiaWAPLong, 0x0b, "\x05\x04\xc3\x4f\x00\x00\x00\x03\x7f\x00\x00",8,-1,10,9}, 72 { UDH_NokiaWAPLong, 0x0b, "\x05\x04\xc3\x4f\x00\x00\x00\x03\x7f\x00\x00",8,-1,10,9},
70 73
71 { UDH_ConcatenatedMessages16bit,0x06, "\x08\x04\x00\x00\x00\x00",-1,2,5,4}, 74 { UDH_ConcatenatedMessages16bit,0x06, "\x08\x04\x00\x00\x00\x00",-1,2,5,4},
72 75
73 { UDH_NoUDH, 0x00, "",-1,-1,-1,-1} 76 { UDH_NoUDH, 0x00, "",-1,-1,-1,-1}
74}; 77};
75 78
76/* --------------------------- Unpacking SMS ------------------------------- */ 79/* --------------------------- Unpacking SMS ------------------------------- */
77 80
78/* See GSM 03.40 section 9.2.3.11 */ 81/* See GSM 03.40 section 9.2.3.11 */
79static GSM_Error GSM_DecodeSMSDateTime(GSM_DateTime *DT, unsigned char *req) 82static GSM_Error GSM_DecodeSMSDateTime(GSM_DateTime *DT, unsigned char *req)
80{ 83{
81 DT->Year = DecodeWithBCDAlphabet(req[0]); 84 DT->Year = DecodeWithBCDAlphabet(req[0]);
82 if (DT->Year<90) DT->Year=DT->Year+2000; else DT->Year=DT->Year+1990; 85 if (DT->Year<90) DT->Year=DT->Year+2000; else DT->Year=DT->Year+1990;
83 DT->Month = DecodeWithBCDAlphabet(req[1]); 86 DT->Month = DecodeWithBCDAlphabet(req[1]);
84 DT->Day = DecodeWithBCDAlphabet(req[2]); 87 DT->Day = DecodeWithBCDAlphabet(req[2]);
85 DT->Hour = DecodeWithBCDAlphabet(req[3]); 88 DT->Hour = DecodeWithBCDAlphabet(req[3]);
86 DT->Minute = DecodeWithBCDAlphabet(req[4]); 89 DT->Minute = DecodeWithBCDAlphabet(req[4]);
87 DT->Second = DecodeWithBCDAlphabet(req[5]); 90 DT->Second = DecodeWithBCDAlphabet(req[5]);
88 91
89 /* Base for timezone is GMT. It's in quarters */ 92 /* Base for timezone is GMT. It's in quarters */
90 DT->Timezone=(10*(req[6]&0x07)+(req[6]>>4))/4; 93 DT->Timezone=(10*(req[6]&0x07)+(req[6]>>4))/4;
91 94
92 if (req[6]&0x08) DT->Timezone = -DT->Timezone; 95 if (req[6]&0x08) DT->Timezone = -DT->Timezone;
93 96
94 dbgprintf("Decoding date & time: "); 97 dbgprintf("Decoding date & time: ");
95 dbgprintf("%s %4d/%02d/%02d ", DayOfWeek(DT->Year, DT->Month, DT->Day), 98 dbgprintf("%s %4d/%02d/%02d ", DayOfWeek(DT->Year, DT->Month, DT->Day),
96 DT->Year, DT->Month, DT->Day); 99 DT->Year, DT->Month, DT->Day);
97 dbgprintf("%02d:%02d:%02d %02d00\n", DT->Hour, DT->Minute, DT->Second, DT->Timezone); 100 dbgprintf("%02d:%02d:%02d %02d00\n", DT->Hour, DT->Minute, DT->Second, DT->Timezone);
98 101
99 return ERR_NONE; 102 return ERR_NONE;
100} 103}
101 104
102void GSM_DecodeUDHHeader(GSM_UDHHeader *UDH) 105void GSM_DecodeUDHHeader(GSM_UDHHeader *UDH)
103{ 106{
104 inti, tmp, w; 107 inti, tmp, w;
105 boolUDHOK; 108 boolUDHOK;
106 109
107 UDH->Type = UDH_UserUDH; 110 UDH->Type = UDH_UserUDH;
108 UDH->ID8bit= -1; 111 UDH->ID8bit= -1;
109 UDH->ID16bit= -1; 112 UDH->ID16bit= -1;
110 UDH->PartNumber= -1; 113 UDH->PartNumber= -1;
111 UDH->AllParts= -1; 114 UDH->AllParts= -1;
112 115
113 i=-1; 116 i=-1;
114 while (true) { 117 while (true) {
115 i++; 118 i++;
116 if (UDHHeaders[i].Type==UDH_NoUDH) break; 119 if (UDHHeaders[i].Type==UDH_NoUDH) break;
117 120
118 tmp=UDHHeaders[i].Length; 121 tmp=UDHHeaders[i].Length;
119 /* if length is the same */ 122 /* if length is the same */
120 if (tmp==UDH->Text[0]) { 123 if (tmp==UDH->Text[0]) {
121 124
122 if (tmp==0x05) tmp=tmp-3;/*three last bytes can be different for such UDH*/ 125 if (tmp==0x05) tmp=tmp-3;/*three last bytes can be different for such UDH*/
123 if (tmp==0x0b) tmp=tmp-3;/*three last bytes can be different for such UDH*/ 126 if (tmp==0x0b) tmp=tmp-3;/*three last bytes can be different for such UDH*/
124 if (tmp==0x06 && UDH->Text[1] == 0x08) tmp=tmp-4; 127 if (tmp==0x06 && UDH->Text[1] == 0x08) tmp=tmp-4;
125 128
126 UDHOK=true; 129 UDHOK=true;
127 for (w=0;w<tmp;w++) { 130 for (w=0;w<tmp;w++) {
128 if (UDHHeaders[i].Text[w]!=UDH->Text[w+1]) { 131 if (UDHHeaders[i].Text[w]!=UDH->Text[w+1]) {
129 UDHOK=false; 132 UDHOK=false;
130 break; 133 break;
131 } 134 }
132 } 135 }
133 if (UDHOK) { 136 if (UDHOK) {
134 UDH->Type=UDHHeaders[i].Type; 137 UDH->Type=UDHHeaders[i].Type;
135 138
136 if (UDHHeaders[i].ID8bit !=-1) UDH->ID8bit = UDH->Text[UDHHeaders[i].ID8bit+1]; 139 if (UDHHeaders[i].ID8bit !=-1) UDH->ID8bit = UDH->Text[UDHHeaders[i].ID8bit+1];
137 if (UDHHeaders[i].ID16bit !=-1) UDH->ID16bit = UDH->Text[UDHHeaders[i].ID16bit+1]*256+UDH->Text[UDHHeaders[i].ID16bit+2]; 140 if (UDHHeaders[i].ID16bit !=-1) UDH->ID16bit = UDH->Text[UDHHeaders[i].ID16bit+1]*256+UDH->Text[UDHHeaders[i].ID16bit+2];
138 if (UDHHeaders[i].PartNumber !=-1) UDH->PartNumber = UDH->Text[UDHHeaders[i].PartNumber+1]; 141 if (UDHHeaders[i].PartNumber !=-1) UDH->PartNumber = UDH->Text[UDHHeaders[i].PartNumber+1];
139 if (UDHHeaders[i].AllParts !=-1) UDH->AllParts = UDH->Text[UDHHeaders[i].AllParts+1]; 142 if (UDHHeaders[i].AllParts !=-1) UDH->AllParts = UDH->Text[UDHHeaders[i].AllParts+1];
140 break; 143 break;
141 } 144 }
142 } 145 }
143 } 146 }
144 147
145#ifdef DEBUG 148#ifdef DEBUG
146 dbgprintf("Type of UDH: "); 149 dbgprintf("Type of UDH: ");
147 switch (UDH->Type) { 150 switch (UDH->Type) {
148 case UDH_ConcatenatedMessages : dbgprintf("Concatenated (linked) message"); break; 151 case UDH_ConcatenatedMessages : dbgprintf("Concatenated (linked) message"); break;
149 case UDH_ConcatenatedMessages16bit : dbgprintf("Concatenated (linked) message"); break; 152 case UDH_ConcatenatedMessages16bit : dbgprintf("Concatenated (linked) message"); break;
150 case UDH_DisableVoice : dbgprintf("Disables voice indicator"); break; 153 case UDH_DisableVoice : dbgprintf("Disables voice indicator"); break;
151 case UDH_EnableVoice : dbgprintf("Enables voice indicator"); break; 154 case UDH_EnableVoice : dbgprintf("Enables voice indicator"); break;
152 case UDH_DisableFax : dbgprintf("Disables fax indicator"); break; 155 case UDH_DisableFax : dbgprintf("Disables fax indicator"); break;
153 case UDH_EnableFax : dbgprintf("Enables fax indicator"); break; 156 case UDH_EnableFax : dbgprintf("Enables fax indicator"); break;
154 case UDH_DisableEmail : dbgprintf("Disables email indicator"); break; 157 case UDH_DisableEmail : dbgprintf("Disables email indicator"); break;
155 case UDH_EnableEmail : dbgprintf("Enables email indicator"); break; 158 case UDH_EnableEmail : dbgprintf("Enables email indicator"); break;
156 case UDH_VoidSMS : dbgprintf("Void SMS"); break; 159 case UDH_VoidSMS : dbgprintf("Void SMS"); break;
157 case UDH_NokiaWAP : dbgprintf("Nokia WAP Bookmark"); break; 160 case UDH_NokiaWAP : dbgprintf("Nokia WAP Bookmark"); break;
158 case UDH_NokiaOperatorLogoLong : dbgprintf("Nokia operator logo"); break; 161 case UDH_NokiaOperatorLogoLong : dbgprintf("Nokia operator logo"); break;
159 case UDH_NokiaWAPLong : dbgprintf("Nokia WAP Bookmark or WAP/MMS Settings");break; 162 case UDH_NokiaWAPLong : dbgprintf("Nokia WAP Bookmark or WAP/MMS Settings");break;
160 case UDH_NokiaRingtone : dbgprintf("Nokia ringtone"); break; 163 case UDH_NokiaRingtone : dbgprintf("Nokia ringtone"); break;
161 case UDH_NokiaRingtoneLong : dbgprintf("Nokia ringtone"); break; 164 case UDH_NokiaRingtoneLong : dbgprintf("Nokia ringtone"); break;
162 case UDH_NokiaOperatorLogo : dbgprintf("Nokia GSM operator logo"); break; 165 case UDH_NokiaOperatorLogo : dbgprintf("Nokia GSM operator logo"); break;
163 case UDH_NokiaCallerLogo : dbgprintf("Nokia caller logo"); break; 166 case UDH_NokiaCallerLogo : dbgprintf("Nokia caller logo"); break;
164 case UDH_NokiaProfileLong : dbgprintf("Nokia profile"); break; 167 case UDH_NokiaProfileLong : dbgprintf("Nokia profile"); break;
165 case UDH_NokiaCalendarLong : dbgprintf("Nokia calendar note"); break; 168 case UDH_NokiaCalendarLong : dbgprintf("Nokia calendar note"); break;
166 case UDH_NokiaPhonebookLong : dbgprintf("Nokia phonebook entry"); break; 169 case UDH_NokiaPhonebookLong : dbgprintf("Nokia phonebook entry"); break;
167 case UDH_UserUDH : dbgprintf("User UDH"); break; 170 case UDH_UserUDH : dbgprintf("User UDH"); break;
168 case UDH_MMSIndicatorLong : dbgprintf("MMS indicator"); break; 171 case UDH_MMSIndicatorLong : dbgprintf("MMS indicator"); break;
169 case UDH_NoUDH: break; 172 case UDH_NoUDH: break;
170 } 173 }
171 if (UDH->ID8bit != -1) dbgprintf(", ID 8 bit %i",UDH->ID8bit); 174 if (UDH->ID8bit != -1) dbgprintf(", ID 8 bit %i",UDH->ID8bit);
172 if (UDH->ID16bit != -1) dbgprintf(", ID 16 bit %i",UDH->ID16bit); 175 if (UDH->ID16bit != -1) dbgprintf(", ID 16 bit %i",UDH->ID16bit);
173 if (UDH->PartNumber != -1 && UDH->AllParts != -1) { 176 if (UDH->PartNumber != -1 && UDH->AllParts != -1) {
174 dbgprintf(", part %i of %i",UDH->PartNumber,UDH->AllParts); 177 dbgprintf(", part %i of %i",UDH->PartNumber,UDH->AllParts);
175 } 178 }
176 dbgprintf("\n"); 179 dbgprintf("\n");
177 if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) DumpMessage(di.df, di.dl, UDH->Text, UDH->Length); 180 if (di.dl == DL_TEXTALL || di.dl == DL_TEXTALLDATE) DumpMessage(di.df, di.dl, UDH->Text, UDH->Length);
178#endif 181#endif
179} 182}
180 183
181GSM_Error GSM_DecodeSMSFrameText(GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout) 184GSM_Error GSM_DecodeSMSFrameText(GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout)
182{ 185{
183 int off=0; // length of the User Data Header 186 int off=0; // length of the User Data Header
184 int w,i,tmp=0; 187 int w,i,tmp=0;
185 unsigned charoutput[161]; 188 unsigned charoutput[161];
186 189
187 SMS->UDH.Length = 0; 190 SMS->UDH.Length = 0;
188 /* UDH header available */ 191 /* UDH header available */
189 if (buffer[Layout.firstbyte] & 64) { 192 if (buffer[Layout.firstbyte] & 64) {
190 /* Length of UDH header */ 193 /* Length of UDH header */
191 off = (buffer[Layout.Text] + 1); 194 off = (buffer[Layout.Text] + 1);
192 SMS->UDH.Length = off; 195 SMS->UDH.Length = off;
193 dbgprintf("UDH header available (length %i)\n",off); 196 dbgprintf("UDH header available (length %i)\n",off);
194 197
diff --git a/gammu/emb/common/service/sms/gsmsms.h b/gammu/emb/common/service/sms/gsmsms.h
index d87ff60..0b950d3 100644
--- a/gammu/emb/common/service/sms/gsmsms.h
+++ b/gammu/emb/common/service/sms/gsmsms.h
@@ -1,194 +1,197 @@
1/* (c) 2001-2004 by Marcin Wiacek */ 1/* (c) 2001-2004 by Marcin Wiacek */
2/* based on some work from Pawel Kot, others and Gnokii */ 2/* Based on some Pawel Kot and others work from Gnokii (www.gnokii.org)
3 * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
4 * GNU GPL version 2 or later
5 */
3 6
4#ifndef __gsm_sms_h 7#ifndef __gsm_sms_h
5#define __gsm_sms_h 8#define __gsm_sms_h
6 9
7#include "../../gsmcomon.h" 10#include "../../gsmcomon.h"
8#include "../gsmlogo.h" 11#include "../gsmlogo.h"
9#include "../gsmcal.h" 12#include "../gsmcal.h"
10#include "../gsmpbk.h" 13#include "../gsmpbk.h"
11#include "../gsmdata.h" 14#include "../gsmdata.h"
12#include "../gsmring.h" 15#include "../gsmring.h"
13 16
14/* --------------------- Some general definitions ------------------------- */ 17/* --------------------- Some general definitions ------------------------- */
15 18
16 #define GSM_MAX_UDH_LENGTH 140 19 #define GSM_MAX_UDH_LENGTH 140
17 #define GSM_MAX_SMS_LENGTH 160 20 #define GSM_MAX_SMS_LENGTH 160
18 #define GSM_MAX_8BIT_SMS_LENGTH 140 21 #define GSM_MAX_8BIT_SMS_LENGTH 140
19 22
20/* -------------------- Cell Broadcast ------------------------------------ */ 23/* -------------------- Cell Broadcast ------------------------------------ */
21 24
22/** 25/**
23 * Structure for Cell Broadcast messages. 26 * Structure for Cell Broadcast messages.
24 */ 27 */
25typedef struct { 28typedef struct {
26 /** 29 /**
27 * Message text. 30 * Message text.
28 */ 31 */
29 char Text[300]; 32 char Text[300];
30 /** 33 /**
31 * Channel number. 34 * Channel number.
32 */ 35 */
33 int Channel; 36 int Channel;
34} GSM_CBMessage; 37} GSM_CBMessage;
35 38
36/* ------------------------ SMS status ------------------------------------ */ 39/* ------------------------ SMS status ------------------------------------ */
37 40
38/** 41/**
39 * Status of SMS memory. 42 * Status of SMS memory.
40 */ 43 */
41typedef struct { 44typedef struct {
42 /** 45 /**
43 * Number of unread messages on SIM. 46 * Number of unread messages on SIM.
44 */ 47 */
45 int SIMUnRead; 48 int SIMUnRead;
46 /** 49 /**
47 * Number of all saved messages (including unread) on SIM. 50 * Number of all saved messages (including unread) on SIM.
48 */ 51 */
49 int SIMUsed; 52 int SIMUsed;
50 /** 53 /**
51 * Number of all possible messages on SIM. 54 * Number of all possible messages on SIM.
52 */ 55 */
53 int SIMSize; 56 int SIMSize;
54 /** 57 /**
55 * Number of used templates (62xx/63xx/7110/etc.). 58 * Number of used templates (62xx/63xx/7110/etc.).
56 */ 59 */
57 int TemplatesUsed; 60 int TemplatesUsed;
58 /** 61 /**
59 * Number of unread messages in phone. 62 * Number of unread messages in phone.
60 */ 63 */
61 int PhoneUnRead; 64 int PhoneUnRead;
62 /** 65 /**
63 * Number of all saved messages in phone. 66 * Number of all saved messages in phone.
64 */ 67 */
65 int PhoneUsed; 68 int PhoneUsed;
66 /** 69 /**
67 * Number of all possible messages on phone. 70 * Number of all possible messages on phone.
68 */ 71 */
69 int PhoneSize; 72 int PhoneSize;
70} GSM_SMSMemoryStatus; 73} GSM_SMSMemoryStatus;
71 74
72/* --------------------- SMS Center --------------------------------------- */ 75/* --------------------- SMS Center --------------------------------------- */
73 76
74/** 77/**
75 * Enum defines format of SMS messages. See GSM 03.40 section 9.2.3.9 78 * Enum defines format of SMS messages. See GSM 03.40 section 9.2.3.9
76 */ 79 */
77typedef enum { 80typedef enum {
78 SMS_FORMAT_Pager = 1, 81 SMS_FORMAT_Pager = 1,
79 SMS_FORMAT_Fax, 82 SMS_FORMAT_Fax,
80 SMS_FORMAT_Email, 83 SMS_FORMAT_Email,
81 SMS_FORMAT_Text 84 SMS_FORMAT_Text
82 /* Some values not handled here */ 85 /* Some values not handled here */
83} GSM_SMSFormat; 86} GSM_SMSFormat;
84 87
85/** 88/**
86 * Enum defines some the most often used validity lengths for SMS messages 89 * Enum defines some the most often used validity lengths for SMS messages
87 * for relative validity format. See GSM 03.40 section 9.2.3.12.1 - it gives 90 * for relative validity format. See GSM 03.40 section 9.2.3.12.1 - it gives
88 * more values 91 * more values
89 */ 92 */
90typedef enum { 93typedef enum {
91 SMS_VALID_1_Hour = 0x0b, 94 SMS_VALID_1_Hour = 0x0b,
92 SMS_VALID_6_Hours = 0x47, 95 SMS_VALID_6_Hours = 0x47,
93 SMS_VALID_1_Day = 0xa7, 96 SMS_VALID_1_Day = 0xa7,
94 SMS_VALID_3_Days = 0xa9, 97 SMS_VALID_3_Days = 0xa9,
95 SMS_VALID_1_Week = 0xad, 98 SMS_VALID_1_Week = 0xad,
96 SMS_VALID_Max_Time = 0xff 99 SMS_VALID_Max_Time = 0xff
97} GSM_ValidityPeriod; 100} GSM_ValidityPeriod;
98 101
99/** 102/**
100 * Enum defines format of validity period for SMS messages. 103 * Enum defines format of validity period for SMS messages.
101 * See GSM 03.40 section 9.2.3.12 104 * See GSM 03.40 section 9.2.3.12
102 */ 105 */
103typedef enum { 106typedef enum {
104 SMS_Validity_NotAvailable = 1, 107 SMS_Validity_NotAvailable = 1,
105 SMS_Validity_RelativeFormat 108 SMS_Validity_RelativeFormat
106 /* Specification gives also other possibilities */ 109 /* Specification gives also other possibilities */
107} GSM_ValidityPeriodFormat; 110} GSM_ValidityPeriodFormat;
108 111
109/** 112/**
110 * Structure for validity of SMS messages 113 * Structure for validity of SMS messages
111 */ 114 */
112typedef struct { 115typedef struct {
113 GSM_ValidityPeriodFormatFormat; 116 GSM_ValidityPeriodFormatFormat;
114 /** 117 /**
115 * Value defines period for relative format 118 * Value defines period for relative format
116 */ 119 */
117 GSM_ValidityPeriod Relative; 120 GSM_ValidityPeriod Relative;
118} GSM_SMSValidity; 121} GSM_SMSValidity;
119 122
120 #define GSM_MAX_SMSC_NAME_LENGTH30 123 #define GSM_MAX_SMSC_NAME_LENGTH30
121 124
122/** 125/**
123 * Structure for SMSC (SMS Center) information. 126 * Structure for SMSC (SMS Center) information.
124 */ 127 */
125typedef struct { 128typedef struct {
126 /** 129 /**
127 * Number of the SMSC on SIM 130 * Number of the SMSC on SIM
128 */ 131 */
129 int Location; 132 int Location;
130 /** 133 /**
131 * Name of the SMSC 134 * Name of the SMSC
132 */ 135 */
133 unsigned char Name[(GSM_MAX_SMSC_NAME_LENGTH+1)*2]; 136 unsigned char Name[(GSM_MAX_SMSC_NAME_LENGTH+1)*2];
134 /** 137 /**
135 * SMSC phone number. 138 * SMSC phone number.
136 */ 139 */
137 unsigned char Number[(GSM_MAX_NUMBER_LENGTH+1)*2]; 140 unsigned char Number[(GSM_MAX_NUMBER_LENGTH+1)*2];
138 /** 141 /**
139 * Validity of SMS messages. 142 * Validity of SMS messages.
140 */ 143 */
141 GSM_SMSValidity Validity; 144 GSM_SMSValidity Validity;
142 /** 145 /**
143 * Format of sent SMS messages. 146 * Format of sent SMS messages.
144 */ 147 */
145 GSM_SMSFormat Format; 148 GSM_SMSFormat Format;
146 /** 149 /**
147 * Default recipient number. In old DCT3 ignored 150 * Default recipient number. In old DCT3 ignored
148 */ 151 */
149 unsigned char DefaultNumber[(GSM_MAX_NUMBER_LENGTH+1)*2]; 152 unsigned char DefaultNumber[(GSM_MAX_NUMBER_LENGTH+1)*2];
150} GSM_SMSC; 153} GSM_SMSC;
151 154
152/* --------------------- single SMS --------------------------------------- */ 155/* --------------------- single SMS --------------------------------------- */
153 156
154/** 157/**
155 * Status of SMS message. 158 * Status of SMS message.
156 */ 159 */
157typedef enum { 160typedef enum {
158 SMS_Sent = 1, 161 SMS_Sent = 1,
159 SMS_UnSent, 162 SMS_UnSent,
160 SMS_Read, 163 SMS_Read,
161 SMS_UnRead 164 SMS_UnRead
162} GSM_SMS_State; 165} GSM_SMS_State;
163 166
164/** 167/**
165 * Coding type of SMS. 168 * Coding type of SMS.
166 */ 169 */
167typedef enum { 170typedef enum {
168 /** 171 /**
169 * Unicode 172 * Unicode
170 */ 173 */
171 SMS_Coding_Unicode = 1, 174 SMS_Coding_Unicode = 1,
172 /** 175 /**
173 * Default GSM aplhabet. 176 * Default GSM aplhabet.
174 */ 177 */
175 SMS_Coding_Default, 178 SMS_Coding_Default,
176 /** 179 /**
177 * 8-bit. 180 * 8-bit.
178 */ 181 */
179 SMS_Coding_8bit 182 SMS_Coding_8bit
180} GSM_Coding_Type; 183} GSM_Coding_Type;
181 184
182/** 185/**
183 * Types of UDH (User Data Header). 186 * Types of UDH (User Data Header).
184 */ 187 */
185typedef enum { 188typedef enum {
186 UDH_NoUDH = 1, 189 UDH_NoUDH = 1,
187 /** 190 /**
188 * Linked SMS. 191 * Linked SMS.
189 */ 192 */
190 UDH_ConcatenatedMessages, 193 UDH_ConcatenatedMessages,
191 /** 194 /**
192 * Linked SMS with 16 bit reference. 195 * Linked SMS with 16 bit reference.
193 */ 196 */
194 UDH_ConcatenatedMessages16bit, 197 UDH_ConcatenatedMessages16bit,
diff --git a/gammu/emb/gammu/depend/nokia/dct3.c b/gammu/emb/gammu/depend/nokia/dct3.c
index d4a55da..b9e47ea 100644
--- a/gammu/emb/gammu/depend/nokia/dct3.c
+++ b/gammu/emb/gammu/depend/nokia/dct3.c
@@ -421,381 +421,387 @@ static GSM_Error DCT3_ReplyGetMCUchkSum(GSM_Protocol_Message msg, GSM_StateMachi
421 printf("\n"); 421 printf("\n");
422 } 422 }
423 return ERR_NONE; 423 return ERR_NONE;
424} 424}
425 425
426static unsigned char MSID1; 426static unsigned char MSID1;
427 427
428GSM_Error DCT3_ReplyEnableSecurity2(GSM_Protocol_Message msg, GSM_StateMachine *s) 428GSM_Error DCT3_ReplyEnableSecurity2(GSM_Protocol_Message msg, GSM_StateMachine *s)
429{ 429{
430 smprintf(s, "State of security commands set\n"); 430 smprintf(s, "State of security commands set\n");
431 MSID1 = msg.Buffer[5]; 431 MSID1 = msg.Buffer[5];
432 return ERR_NONE; 432 return ERR_NONE;
433} 433}
434 434
435void DCT3Info(int argc, char *argv[]) 435void DCT3Info(int argc, char *argv[])
436{ 436{
437 unsigned char req[] = {0x00, 0x01, 0x8A, 0x00}; /* Get simlock info */ 437 unsigned char req[] = {0x00, 0x01, 0x8A, 0x00}; /* Get simlock info */
438 unsigned char req2[] = {0x00, 0x01, 0xb4, 0x00, 0x00}; /* Get MSID */ 438 unsigned char req2[] = {0x00, 0x01, 0xb4, 0x00, 0x00}; /* Get MSID */
439 unsigned char req3[] = {0x00, 0x01, 0xc8, 0x02}; /* Get MCU chksum */ 439 unsigned char req3[] = {0x00, 0x01, 0xc8, 0x02}; /* Get MCU chksum */
440 unsigned char req4[] = {0x00, 0x01, 0xc8, 0x09}; /* Get DSP ROM */ 440 unsigned char req4[] = {0x00, 0x01, 0xc8, 0x09}; /* Get DSP ROM */
441 441
442 if (CheckDCT3Only()!=ERR_NONE) return; 442 if (CheckDCT3Only()!=ERR_NONE) return;
443 443
444 s.User.UserReplyFunctions=UserReplyFunctions3; 444 s.User.UserReplyFunctions=UserReplyFunctions3;
445 445
446 error=DCT3_EnableSecurity (&s, 0x01); 446 error=DCT3_EnableSecurity (&s, 0x01);
447 Print_Error(error); 447 Print_Error(error);
448 448
449 error=GSM_WaitFor (&s, req, 4, 0x40, 4, ID_User3); 449 error=GSM_WaitFor (&s, req, 4, 0x40, 4, ID_User3);
450 Print_Error(error); 450 Print_Error(error);
451 451
452 req2[3] = MSID1; 452 req2[3] = MSID1;
453 req2[4] = req2[2] + req2[3]; 453 req2[4] = req2[2] + req2[3];
454 error=GSM_WaitFor (&s, req2, 5, 0x40, 4, ID_User8); 454 error=GSM_WaitFor (&s, req2, 5, 0x40, 4, ID_User8);
455 Print_Error(error); 455 Print_Error(error);
456 456
457 error=GSM_WaitFor (&s, req3, 4, 0x40, 4, ID_User9); 457 error=GSM_WaitFor (&s, req3, 4, 0x40, 4, ID_User9);
458 Print_Error(error); 458 Print_Error(error);
459 459
460 error=GSM_WaitFor (&s, req4, 4, 0x40, 4, ID_User10); 460 error=GSM_WaitFor (&s, req4, 4, 0x40, 4, ID_User10);
461 Print_Error(error); 461 Print_Error(error);
462} 462}
463 463
464static GSM_Error DCT3_ReplyResetTest36(GSM_Protocol_Message msg, GSM_StateMachine *s) 464static GSM_Error DCT3_ReplyResetTest36(GSM_Protocol_Message msg, GSM_StateMachine *s)
465{ 465{
466 printf("Netmonitor test 36 cleaned OK\n"); 466 printf("Netmonitor test 36 cleaned OK\n");
467 return ERR_NONE; 467 return ERR_NONE;
468} 468}
469 469
470void DCT3ResetTest36(int argc, char *argv[]) 470void DCT3ResetTest36(int argc, char *argv[])
471{ 471{
472 unsigned char req[] = {0x00, 0x01, 0x65, 0x40, 0x00}; /* Reset test 36 in netmon */ 472 unsigned char req[] = {0x00, 0x01, 0x65, 0x40, 0x00}; /* Reset test 36 in netmon */
473 473
474 GSM_Init(true); 474 GSM_Init(true);
475 475
476 CheckDCT3(); 476 CheckDCT3();
477 477
478 error=DCT3_EnableSecurity (&s, 0x01); 478 error=DCT3_EnableSecurity (&s, 0x01);
479 Print_Error(error); 479 Print_Error(error);
480 480
481 s.User.UserReplyFunctions=UserReplyFunctions3; 481 s.User.UserReplyFunctions=UserReplyFunctions3;
482 482
483 error=GSM_WaitFor (&s, req, 5, 0x40, 4, ID_User2); 483 error=GSM_WaitFor (&s, req, 5, 0x40, 4, ID_User2);
484 Print_Error(error); 484 Print_Error(error);
485 485
486#ifdef GSM_ENABLE_BEEP 486#ifdef GSM_ENABLE_BEEP
487 GSM_PhoneBeep(); 487 GSM_PhoneBeep();
488#endif 488#endif
489 GSM_Terminate(); 489 GSM_Terminate();
490} 490}
491 491
492static unsigned char PPS[32]; /* Product Profile Settings */ 492static unsigned char PPS[32]; /* Product Profile Settings */
493 493
494static GSM_Error DCT3_ReplyGetPPS(GSM_Protocol_Message msg, GSM_StateMachine *s) 494static GSM_Error DCT3_ReplyGetPPS(GSM_Protocol_Message msg, GSM_StateMachine *s)
495{ 495{
496 int i,j,z; 496 int i,j,z;
497 497
498#ifdef DEBUG 498#ifdef DEBUG
499 dbgprintf("Product Profile Settings received -"); 499 dbgprintf("Product Profile Settings received -");
500 for (i=0;i<4;i++) dbgprintf(" %02x",msg.Buffer[3+i]); 500 for (i=0;i<4;i++) dbgprintf(" %02x",msg.Buffer[3+i]);
501 dbgprintf("\n"); 501 dbgprintf("\n");
502#endif 502#endif
503 j=128;z=0; 503 j=128;z=0;
504 for (i=0;i<32;i++) { 504 for (i=0;i<32;i++) {
505 PPS[i]='0'; 505 PPS[i]='0';
506 if (msg.Buffer[z+3]&j) PPS[i]='1'; 506 if (msg.Buffer[z+3]&j) PPS[i]='1';
507 if (j==1) { 507 if (j==1) {
508 j=128; 508 j=128;
509 z++; 509 z++;
510 } else j=j/2; 510 } else j=j/2;
511 } 511 }
512#ifdef DEBUG 512#ifdef DEBUG
513 dbgprintf("After decoding: "); 513 dbgprintf("After decoding: ");
514 for (i=0;i<32;i++) dbgprintf("%c",PPS[i]); 514 for (i=0;i<32;i++) dbgprintf("%c",PPS[i]);
515 dbgprintf("\n"); 515 dbgprintf("\n");
516#endif 516#endif
517 return ERR_NONE; 517 return ERR_NONE;
518} 518}
519 519
520static GSM_Error DCT3_ReplySetPPS(GSM_Protocol_Message msg, GSM_StateMachine *s) 520static GSM_Error DCT3_ReplySetPPS(GSM_Protocol_Message msg, GSM_StateMachine *s)
521{ 521{
522 printf("Setting done OK\n"); 522 printf("Setting done OK\n");
523 return ERR_NONE; 523 return ERR_NONE;
524} 524}
525 525
526void DCT3SetPhoneMenus(int argc, char *argv[]) 526void DCT3SetPhoneMenus(int argc, char *argv[])
527{ 527{
528 char value[100]; 528 char value[100];
529 int i,j,z; 529 int i,j,z;
530 unsigned char reqGet[] = {0x00, 0x01, 0x6a}; 530 unsigned char reqGet[] = {0x00, 0x01, 0x6a};
531 unsigned char reqSet[] = { 531 unsigned char reqSet[] = {
532 0x00, 0x01, 0x6b, 532 0x00, 0x01, 0x6b,
533 0x00, 0x00, 0x00, 0x00 }; /* bytes with Product Profile Setings */ 533 0x00, 0x00, 0x00, 0x00 }; /* bytes with Product Profile Setings */
534 534
535 if (CheckDCT3Only()!=ERR_NONE) return; 535 if (CheckDCT3Only()!=ERR_NONE) return;
536 536
537 error=DCT3_EnableSecurity (&s, 0x01); 537 error=DCT3_EnableSecurity (&s, 0x01);
538 Print_Error(error); 538 Print_Error(error);
539 539
540 s.User.UserReplyFunctions=UserReplyFunctions3; 540 s.User.UserReplyFunctions=UserReplyFunctions3;
541 541
542 error=GSM_WaitFor (&s, reqGet, 3, 0x40, 4, ID_User4); 542 error=GSM_WaitFor (&s, reqGet, 3, 0x40, 4, ID_User4);
543 Print_Error(error); 543 Print_Error(error);
544 544
545 printf("ALS : enabling menu\n"); 545 printf("ALS : enabling menu\n");
546 PPS[10] = '1'; 546 PPS[10] = '1';
547 547
548 if (!strcmp(s.Phone.Data.ModelInfo->model,"3310") && s.Phone.Data.VerNum>5.87) { 548 if (!strcmp(s.Phone.Data.ModelInfo->model,"3310") && s.Phone.Data.VerNum>5.87) {
549 printf("3310: enabling control of SMS charsets\n"); 549 printf("3310: enabling control of SMS charsets\n");
550 PPS[11] = '0';//0 = ON, 1 = OFF 550 PPS[11] = '0';//0 = ON, 1 = OFF
551 } 551 }
552 if (!strcmp(s.Phone.Data.ModelInfo->model,"6150")) { 552 if (!strcmp(s.Phone.Data.ModelInfo->model,"6150")) {
553 printf("6150: enabling WellMate menu\n"); 553 printf("6150: enabling WellMate menu\n");
554 PPS[18] = '1'; 554 PPS[18] = '1';
555 } 555 }
556 /* FIXME */ 556 /* FIXME */
557 if (!strcmp(s.Phone.Data.ModelInfo->model,"3210")) { 557 if (!strcmp(s.Phone.Data.ModelInfo->model,"3210")) {
558 printf("3210: enabling vibra menu\n"); 558 printf("3210: enabling vibra menu\n");
559 PPS[24] = '1'; 559 PPS[24] = '1';
560 } 560 }
561 if (!strcmp(s.Phone.Data.ModelInfo->model,"3310") && s.Phone.Data.VerNum>5.13) { 561 if (!strcmp(s.Phone.Data.ModelInfo->model,"3310") && s.Phone.Data.VerNum>5.13) {
562 printf("3310: enabling 3315 features\n"); 562 printf("3310: enabling 3315 features\n");
563 PPS[25] = '1'; 563 PPS[25] = '1';
564 } 564 }
565 /* FIXME */ 565 /* FIXME */
566 if (!strcmp(s.Phone.Data.ModelInfo->model,"3210") && s.Phone.Data.VerNum>=5.31) { 566 if (!strcmp(s.Phone.Data.ModelInfo->model,"3210") && s.Phone.Data.VerNum>=5.31) {
567 printf("3210: enabling React and Logic game\n"); 567 printf("3210: enabling React and Logic game\n");
568 PPS[26] = '1'; 568 PPS[26] = '1';
569 } 569 }
570 570
571#ifdef DEBUG 571#ifdef DEBUG
572 dbgprintf("After settings: "); 572 dbgprintf("After settings: ");
573 for (i=0;i<32;i++) dbgprintf("%c",PPS[i]); 573 for (i=0;i<32;i++) dbgprintf("%c",PPS[i]);
574 dbgprintf("\n"); 574 dbgprintf("\n");
575#endif 575#endif
576 576
577 j=128;z=0; 577 j=128;z=0;
578 for (i=0;i<32;i++) { 578 for (i=0;i<32;i++) {
579 if (PPS[i]=='1') reqSet[z+3]=reqSet[z+3]+j; 579 if (PPS[i]=='1') reqSet[z+3]=reqSet[z+3]+j;
580 if (j==1) { 580 if (j==1) {
581 j=128; 581 j=128;
582 z++; 582 z++;
583 } else j=j/2; 583 } else j=j/2;
584 } 584 }
585 585
586 //reqSet[3]=0xe7; 586 //reqSet[3]=0xe7;
587 //reqSet[4]=0x25; 587 //reqSet[4]=0x25;
588 //reqSet[5]=0x00; 588 //reqSet[5]=0x00;
589 //reqSet[6]=0xe0; 589 //reqSet[6]=0xe0;
590 590
591 error=GSM_WaitFor (&s, reqSet, 7, 0x40, 4, ID_User4); 591 error=GSM_WaitFor (&s, reqSet, 7, 0x40, 4, ID_User4);
592 Print_Error(error); 592 Print_Error(error);
593 593
594 printf("Enabling netmonitor\n"); 594 printf("Enabling netmonitor\n");
595 error=DCT3_Netmonitor(&s, 243, value); 595 error=DCT3_Netmonitor(&s, 243, value);
596 Print_Error(error); 596 Print_Error(error);
597} 597}
598 598
599static GSM_Error DCT3_Reply61GetSecurityCode(GSM_Protocol_Message msg, GSM_StateMachine *s) 599static GSM_Error DCT3_Reply61GetSecurityCode(GSM_Protocol_Message msg, GSM_StateMachine *s)
600{ 600{
601 printf("Security Code is \"%s\"\n",msg.Buffer+5); 601 printf("Security Code is \"%s\"\n",msg.Buffer+5);
602 return ERR_NONE; 602 return ERR_NONE;
603} 603}
604 604
605static GSM_Error DCT3_Reply7191GetSecurityCode(GSM_Protocol_Message msg, GSM_StateMachine *s) 605static GSM_Error DCT3_Reply7191GetSecurityCode(GSM_Protocol_Message msg, GSM_StateMachine *s)
606{ 606{
607 printf("Security Code is \"%s\"\n",msg.Buffer+6); 607 printf("Security Code is \"%s\"\n",msg.Buffer+6);
608 return ERR_NONE; 608 return ERR_NONE;
609} 609}
610 610
611void DCT3GetSecurityCode(int argc, char *argv[]) 611void DCT3GetSecurityCode(int argc, char *argv[])
612{ 612{
613#ifdef GSM_ENABLE_NOKIA6110
613 unsigned char req6110[] = {0x00, 0x01, 0x6e, 614 unsigned char req6110[] = {0x00, 0x01, 0x6e,
614 0x01};/* Code type */ 615 0x01};/* Code type */
616#endif
617#if defined(GSM_ENABLE_NOKIA7110) || defined(GSM_ENABLE_NOKIA9210)
615 unsigned char req71_91[] = {N7110_FRAME_HEADER, 0xee, 618 unsigned char req71_91[] = {N7110_FRAME_HEADER, 0xee,
616 0x1c};/* Setting */ 619 0x1c};/* Setting */
620#endif
617 621
618 if (CheckDCT3Only()!=ERR_NONE) return; 622 if (CheckDCT3Only()!=ERR_NONE) return;
619 623
620 error=DCT3_EnableSecurity (&s, 0x01); 624 error=DCT3_EnableSecurity (&s, 0x01);
621 Print_Error(error); 625 Print_Error(error);
622 626
623 s.User.UserReplyFunctions=UserReplyFunctions3; 627 s.User.UserReplyFunctions=UserReplyFunctions3;
624 628
625#ifdef GSM_ENABLE_NOKIA6110 629#ifdef GSM_ENABLE_NOKIA6110
626 if (strstr(N6110Phone.models, s.Phone.Data.ModelInfo->model) != NULL) { 630 if (strstr(N6110Phone.models, s.Phone.Data.ModelInfo->model) != NULL) {
627 error=GSM_WaitFor (&s, req6110, 4, 0x40, 4, ID_User6); 631 error=GSM_WaitFor (&s, req6110, 4, 0x40, 4, ID_User6);
628 } 632 }
629#endif 633#endif
630#ifdef GSM_ENABLE_NOKIA7110 634#ifdef GSM_ENABLE_NOKIA7110
631 if (strstr(N7110Phone.models, s.Phone.Data.ModelInfo->model) != NULL) { 635 if (strstr(N7110Phone.models, s.Phone.Data.ModelInfo->model) != NULL) {
632 error=GSM_WaitFor (&s, req71_91, 5, 0x7a, 4, ID_User6); 636 error=GSM_WaitFor (&s, req71_91, 5, 0x7a, 4, ID_User6);
633 } 637 }
634#endif 638#endif
635#ifdef GSM_ENABLE_NOKIA9210 639#ifdef GSM_ENABLE_NOKIA9210
636 if (strstr(N9210Phone.models, s.Phone.Data.ModelInfo->model) != NULL) { 640 if (strstr(N9210Phone.models, s.Phone.Data.ModelInfo->model) != NULL) {
637 error=GSM_WaitFor (&s, req71_91, 5, 0x7a, 4, ID_User6); 641 error=GSM_WaitFor (&s, req71_91, 5, 0x7a, 4, ID_User6);
638 } 642 }
639#endif 643#endif
640 Print_Error(error); 644 Print_Error(error);
641} 645}
642 646
643#ifdef GSM_ENABLE_NOKIA6110 647#ifdef GSM_ENABLE_NOKIA6110
644 648
645static GSM_Error DCT3_ReplyGetOperatorName(GSM_Protocol_Message msg, GSM_StateMachine *s) 649static GSM_Error DCT3_ReplyGetOperatorName(GSM_Protocol_Message msg, GSM_StateMachine *s)
646{ 650{
647 unsigned char buffer[10]; 651 unsigned char buffer[10];
648 652
649 NOKIA_DecodeNetworkCode(msg.Buffer+5, buffer); 653 NOKIA_DecodeNetworkCode(msg.Buffer+5, buffer);
650 buffer[6] = 0; 654 buffer[6] = 0;
651 printf("Network : %s (%s ",buffer,DecodeUnicodeString(GSM_GetNetworkName(buffer))); 655 printf("Network : %s (%s ",buffer,DecodeUnicodeString(GSM_GetNetworkName(buffer)));
652 printf(", %s)\n", DecodeUnicodeString(GSM_GetCountryName(buffer))); 656 printf(", %s)\n", DecodeUnicodeString(GSM_GetCountryName(buffer)));
653 printf("Name : \"%s\"\n",msg.Buffer+8); 657 printf("Name : \"%s\"\n",msg.Buffer+8);
654 658
655 return ERR_NONE; 659 return ERR_NONE;
656} 660}
657 661
658void DCT3GetOperatorName(int argc, char *argv[]) 662void DCT3GetOperatorName(int argc, char *argv[])
659{ 663{
660 unsigned char req[] = {0x00,0x01,0x8c,0x00}; 664 unsigned char req[] = {0x00,0x01,0x8c,0x00};
661 665
662 GSM_Init(true); 666 GSM_Init(true);
663 667
664 if (strstr(N6110Phone.models, s.Phone.Data.ModelInfo->model) == NULL) Print_Error(ERR_NOTSUPPORTED); 668 if (strstr(N6110Phone.models, s.Phone.Data.ModelInfo->model) == NULL) Print_Error(ERR_NOTSUPPORTED);
665 CheckDCT3(); 669 CheckDCT3();
666 670
667 error=DCT3_EnableSecurity (&s, 0x01); 671 error=DCT3_EnableSecurity (&s, 0x01);
668 Print_Error(error); 672 Print_Error(error);
669 673
670 s.User.UserReplyFunctions=UserReplyFunctions3; 674 s.User.UserReplyFunctions=UserReplyFunctions3;
671 675
672 error=GSM_WaitFor (&s, req, 4, 0x40, 4, ID_User5); 676 error=GSM_WaitFor (&s, req, 4, 0x40, 4, ID_User5);
673 Print_Error(error); 677 Print_Error(error);
674 678
675 GSM_Terminate(); 679 GSM_Terminate();
676} 680}
677 681
678static GSM_Error DCT3_ReplySetOperatorName(GSM_Protocol_Message msg, GSM_StateMachine *s) 682static GSM_Error DCT3_ReplySetOperatorName(GSM_Protocol_Message msg, GSM_StateMachine *s)
679{ 683{
680 printf("Operator name set OK\n"); 684 printf("Operator name set OK\n");
681 return ERR_NONE; 685 return ERR_NONE;
682} 686}
683 687
684void DCT3SetOperatorName(int argc, char *argv[]) 688void DCT3SetOperatorName(int argc, char *argv[])
685{ 689{
686 int i = 0; 690 int i = 0;
687 unsigned char req[256] = {0x00,0x01,0x8b,0x00, 691 unsigned char req[256] = {0x00,0x01,0x8b,0x00,
688 0x00,0x00, /* MCC */ 692 0x00,0x00, /* MCC */
689 0x00}; /* MNC */ 693 0x00}; /* MNC */
690 694
691 GSM_Init(true); 695 GSM_Init(true);
692 696
693 if (strstr(N6110Phone.models, s.Phone.Data.ModelInfo->model) == NULL) Print_Error(ERR_NOTSUPPORTED); 697 if (strstr(N6110Phone.models, s.Phone.Data.ModelInfo->model) == NULL) Print_Error(ERR_NOTSUPPORTED);
694 CheckDCT3(); 698 CheckDCT3();
695 699
696 error=DCT3_EnableSecurity (&s, 0x01); 700 error=DCT3_EnableSecurity (&s, 0x01);
697 Print_Error(error); 701 Print_Error(error);
698 702
699 s.User.UserReplyFunctions=UserReplyFunctions3; 703 s.User.UserReplyFunctions=UserReplyFunctions3;
700 704
701 switch (argc) { 705 switch (argc) {
702 case 2: 706 case 2:
703 case 3:NOKIA_EncodeNetworkCode(req+4,"000 00"); 707 case 3:NOKIA_EncodeNetworkCode(req+4,"000 00");
704 req[7] = 0x00; 708 req[7] = 0x00;
705 i = 1; 709 i = 1;
706 break; 710 break;
707 case 4: NOKIA_EncodeNetworkCode(req+4,argv[2]); 711 case 4: NOKIA_EncodeNetworkCode(req+4,argv[2]);
708 strncpy(req+7,argv[3],200); 712 strncpy(req+7,argv[3],200);
709 i = strlen(argv[3]); 713 i = strlen(argv[3]);
710 } 714 }
711 715
712 error=GSM_WaitFor (&s, req, 8+i, 0x40, 4, ID_User7); 716 error=GSM_WaitFor (&s, req, 8+i, 0x40, 4, ID_User7);
713 Print_Error(error); 717 Print_Error(error);
714 718
715 GSM_Terminate(); 719 GSM_Terminate();
716} 720}
717 721
718static GSM_Error DCT3_ReplyDisplayOutput(GSM_Protocol_Message msg, GSM_StateMachine *s) 722static GSM_Error DCT3_ReplyDisplayOutput(GSM_Protocol_Message msg, GSM_StateMachine *s)
719{ 723{
720 unsigned char buf[100]; 724 unsigned char buf[100];
721 725
722 switch (msg.Buffer[3]) { 726 switch (msg.Buffer[3]) {
723 case 0x50: 727 case 0x50:
724 dbgprintf("Display string received\n"); 728 dbgprintf("Display string received\n");
725 memcpy(buf,msg.Buffer+8,msg.Buffer[7]*2); 729 memcpy(buf,msg.Buffer+8,msg.Buffer[7]*2);
726 buf[msg.Buffer[7]*2] = 0; 730 buf[msg.Buffer[7]*2] = 0;
727 buf[msg.Buffer[7]*2+1] = 0; 731 buf[msg.Buffer[7]*2+1] = 0;
728 printf("X=%i, Y=%i, Text=\"%s\"\n",msg.Buffer[6],msg.Buffer[5],DecodeUnicodeString(buf)); 732 printf("X=%i, Y=%i, Text=\"%s\"\n",msg.Buffer[6],msg.Buffer[5],DecodeUnicodeString(buf));
729 return ERR_NONE; 733 return ERR_NONE;
730 case 0x54: 734 case 0x54:
731 dbgprintf("Display output set\n"); 735 dbgprintf("Display output set\n");
732 return ERR_NONE; 736 return ERR_NONE;
733 } 737 }
734 return ERR_UNKNOWNRESPONSE; 738 return ERR_UNKNOWNRESPONSE;
735} 739}
736 740
737void DCT3DisplayOutput(int argc, char *argv[]) 741void DCT3DisplayOutput(int argc, char *argv[])
738{ 742{
739 unsigned char req[] = {N6110_FRAME_HEADER, 0x53, 743 unsigned char req[] = {N6110_FRAME_HEADER, 0x53,
740 0x01}; //1 = enable, 2 = disable 744 0x01}; //1 = enable, 2 = disable
741 745
742 GSM_Init(true); 746 GSM_Init(true);
743 747
744 if (strstr(N6110Phone.models, s.Phone.Data.ModelInfo->model) == NULL) Print_Error(ERR_NOTSUPPORTED); 748 if (strstr(N6110Phone.models, s.Phone.Data.ModelInfo->model) == NULL) Print_Error(ERR_NOTSUPPORTED);
745 CheckDCT3(); 749 CheckDCT3();
746 750
747 s.User.UserReplyFunctions=UserReplyFunctions3; 751 s.User.UserReplyFunctions=UserReplyFunctions3;
748 752
749 error=GSM_WaitFor (&s, req, 5, 0x0d, 4, ID_User7); 753 error=GSM_WaitFor (&s, req, 5, 0x0d, 4, ID_User7);
750 Print_Error(error); 754 Print_Error(error);
751 755
752 signal(SIGINT, interrupt); 756 signal(SIGINT, interrupt);
753 printf("Press Ctrl+C to break...\n"); 757 printf("Press Ctrl+C to break...\n");
754 printf("Entering monitor mode...\n\n"); 758 printf("Entering monitor mode...\n\n");
755 759
756 while (!gshutdown) { 760 while (!gshutdown) {
757 GSM_ReadDevice(&s,true); 761 GSM_ReadDevice(&s,true);
758 my_sleep(10); 762 my_sleep(10);
759 } 763 }
760 764
761 req[4] = 0x02; 765 req[4] = 0x02;
762 error=GSM_WaitFor (&s, req, 5, 0x0d, 4, ID_User7); 766 error=GSM_WaitFor (&s, req, 5, 0x0d, 4, ID_User7);
763 Print_Error(error); 767 Print_Error(error);
764 768
765 GSM_Terminate(); 769 GSM_Terminate();
766} 770}
767#endif 771#endif
768 772
769static GSM_Reply_Function UserReplyFunctions3[] = { 773static GSM_Reply_Function UserReplyFunctions3[] = {
774#ifdef GSM_ENABLE_NOKIA6110
770 {DCT3_ReplyDisplayOutput, "\x0D",0x03,0x50,ID_IncomingFrame}, 775 {DCT3_ReplyDisplayOutput, "\x0D",0x03,0x50,ID_IncomingFrame},
771 {DCT3_ReplyDisplayOutput, "\x0D",0x03,0x54,ID_User7 }, 776 {DCT3_ReplyDisplayOutput, "\x0D",0x03,0x54,ID_User7 },
777#endif
772 778
773 {DCT3_ReplyEnableSecurity2, "\x40",0x02,0x64,ID_EnableSecurity}, 779 {DCT3_ReplyEnableSecurity2, "\x40",0x02,0x64,ID_EnableSecurity},
774 {DCT3_ReplyResetTest36, "\x40",0x02,0x65,ID_User2 }, 780 {DCT3_ReplyResetTest36, "\x40",0x02,0x65,ID_User2 },
775 {DCT3_ReplyGetADC, "\x40",0x02,0x68,ID_User3 }, 781 {DCT3_ReplyGetADC, "\x40",0x02,0x68,ID_User3 },
776 {DCT3_ReplyGetPPS, "\x40",0x02,0x6A,ID_User4 }, 782 {DCT3_ReplyGetPPS, "\x40",0x02,0x6A,ID_User4 },
777 {DCT3_ReplySetPPS, "\x40",0x02,0x6B,ID_User4 }, 783 {DCT3_ReplySetPPS, "\x40",0x02,0x6B,ID_User4 },
778 {DCT3_Reply61GetSecurityCode, "\x40",0x02,0x6E,ID_User6 }, 784 {DCT3_Reply61GetSecurityCode, "\x40",0x02,0x6E,ID_User6 },
779 {DCT3_ReplySimlockInfo, "\x40",0x02,0x8A,ID_User3 }, 785 {DCT3_ReplySimlockInfo, "\x40",0x02,0x8A,ID_User3 },
780#ifdef GSM_ENABLE_NOKIA6110 786#ifdef GSM_ENABLE_NOKIA6110
781 {DCT3_ReplySetOperatorName, "\x40",0x02,0x8B,ID_User7 }, 787 {DCT3_ReplySetOperatorName, "\x40",0x02,0x8B,ID_User7 },
782 {DCT3_ReplyGetOperatorName, "\x40",0x02,0x8C,ID_User5 }, 788 {DCT3_ReplyGetOperatorName, "\x40",0x02,0x8C,ID_User5 },
783#endif 789#endif
784 {DCT3_ReplyGetADC, "\x40",0x02,0x91,ID_User3 }, 790 {DCT3_ReplyGetADC, "\x40",0x02,0x91,ID_User3 },
785 {NoneReply, "\x40",0x02,0xA3,ID_User3 }, 791 {NoneReply, "\x40",0x02,0xA3,ID_User3 },
786 {DCT3_ReplyGetT9, "\x40",0x02,0xAE,ID_User3 }, 792 {DCT3_ReplyGetT9, "\x40",0x02,0xAE,ID_User3 },
787 {DCT3_ReplyGetMSID, "\x40",0x02,0xb5,ID_User8 }, 793 {DCT3_ReplyGetMSID, "\x40",0x02,0xb5,ID_User8 },
788 {DCT3_ReplyGetDSPROM, "\x40",0x02,0xC8,ID_User10 }, 794 {DCT3_ReplyGetDSPROM, "\x40",0x02,0xC8,ID_User10 },
789 {DCT3_ReplyGetMCUchkSum, "\x40",0x02,0xC8,ID_User9 }, 795 {DCT3_ReplyGetMCUchkSum, "\x40",0x02,0xC8,ID_User9 },
790 {DCT3_ReplyPhoneTests, "\x40",0x02,0xCF,ID_User1 }, 796 {DCT3_ReplyPhoneTests, "\x40",0x02,0xCF,ID_User1 },
791 797
792 {DCT3_Reply7191GetSecurityCode, "\x7a",0x04,0x1C,ID_User6 }, 798 {DCT3_Reply7191GetSecurityCode, "\x7a",0x04,0x1C,ID_User6 },
793 799
794 {NULL, "\x00",0x00,0x00,ID_None } 800 {NULL, "\x00",0x00,0x00,ID_None }
795 }; 801 };
796 802
797#endif 803#endif
798 804
799/* How should editor hadle tabs in this file? Add editor commands here. 805/* How should editor hadle tabs in this file? Add editor commands here.
800 * vim: noexpandtab sw=8 ts=8 sts=8: 806 * vim: noexpandtab sw=8 ts=8 sts=8:
801 */ 807 */
diff --git a/gammu/emb/gammu/depend/nokia/dct4.c b/gammu/emb/gammu/depend/nokia/dct4.c
index f4ed305..4bf958d 100644
--- a/gammu/emb/gammu/depend/nokia/dct4.c
+++ b/gammu/emb/gammu/depend/nokia/dct4.c
@@ -1,230 +1,231 @@
1/* (c) 2002-2004 by Marcin Wiacek */ 1/* (c) 2002-2004 by Marcin Wiacek */
2 2
3#include "../../../common/gsmstate.h" 3#include "../../../common/gsmstate.h"
4 4
5#ifdef GSM_ENABLE_NOKIA_DCT4 5#ifdef GSM_ENABLE_NOKIA_DCT4
6 6
7#include <string.h> 7#include <string.h>
8 8
9#include "dct4.h" 9#include "dct4.h"
10#include "../../gammu.h" 10#include "../../gammu.h"
11#include "../../../common/phone/pfunc.h" 11#include "../../../common/phone/pfunc.h"
12#include "../../../common/phone/nokia/nfunc.h" 12#include "../../../common/phone/nokia/nfunc.h"
13#include "../../../common/phone/nokia/dct4/dct4func.h" 13#include "../../../common/phone/nokia/dct4/dct4func.h"
14#include "../../../common/misc/coding/coding.h" 14#include "../../../common/misc/coding/coding.h"
15 15
16extern GSM_Reply_Function UserReplyFunctions4[]; 16extern GSM_Reply_Function UserReplyFunctions4[];
17 17
18/* ------- some usefull functions ----------------------------------------- */ 18/* ------- some usefull functions ----------------------------------------- */
19 19
20GSM_Error CheckDCT4Only() 20GSM_Error CheckDCT4Only()
21{ 21{
22 bool found = false; 22 bool found = false;
23 23
24 /* Checking if phone is DCT4 */ 24 /* Checking if phone is DCT4 */
25#ifdef GSM_ENABLE_NOKIA3650 25#ifdef GSM_ENABLE_NOKIA3650
26 if (strstr(N3650Phone.models, s.Phone.Data.ModelInfo->model) != NULL) found = true; 26 if (strstr(N3650Phone.models, s.Phone.Data.ModelInfo->model) != NULL) found = true;
27#endif 27#endif
28#ifdef GSM_ENABLE_NOKIA6510 28#ifdef GSM_ENABLE_NOKIA6510
29 if (strstr(N6510Phone.models, s.Phone.Data.ModelInfo->model) != NULL) found = true; 29 if (strstr(N6510Phone.models, s.Phone.Data.ModelInfo->model) != NULL) found = true;
30#endif 30#endif
31#ifdef GSM_ENABLE_NOKIA3320 31#ifdef GSM_ENABLE_NOKIA3320
32 if (strstr(N3320Phone.models, s.Phone.Data.ModelInfo->model) != NULL) found = true; 32 if (strstr(N3320Phone.models, s.Phone.Data.ModelInfo->model) != NULL) found = true;
33#endif 33#endif
34 if (!found) return ERR_NOTSUPPORTED; 34 if (!found) return ERR_NOTSUPPORTED;
35 35
36 if (s.ConnectionType!=GCT_MBUS2 && s.ConnectionType!=GCT_FBUS2 && 36 if (s.ConnectionType!=GCT_MBUS2 && s.ConnectionType!=GCT_FBUS2 &&
37 s.ConnectionType!=GCT_FBUS2DLR3 && s.ConnectionType!=GCT_PHONETBLUE && 37 s.ConnectionType!=GCT_FBUS2DLR3 && s.ConnectionType!=GCT_PHONETBLUE &&
38 s.ConnectionType!=GCT_IRDAPHONET && s.ConnectionType!=GCT_BLUEPHONET) { 38 s.ConnectionType!=GCT_IRDAPHONET && s.ConnectionType!=GCT_BLUEPHONET &&
39 s.ConnectionType!=GCT_FBUS2DKU5) {
39 return ERR_OTHERCONNECTIONREQUIRED; 40 return ERR_OTHERCONNECTIONREQUIRED;
40 } 41 }
41 return ERR_NONE; 42 return ERR_NONE;
42} 43}
43 44
44static void CheckDCT4() 45static void CheckDCT4()
45{ 46{
46 GSM_Error error; 47 GSM_Error error;
47 48
48 error = CheckDCT4Only(); 49 error = CheckDCT4Only();
49 switch (error) { 50 switch (error) {
50 case ERR_NOTSUPPORTED: 51 case ERR_NOTSUPPORTED:
51 Print_Error(ERR_NOTSUPPORTED); 52 Print_Error(ERR_NOTSUPPORTED);
52 break; 53 break;
53 case ERR_OTHERCONNECTIONREQUIRED: 54 case ERR_OTHERCONNECTIONREQUIRED:
54 printf("Can't do it with current phone protocol\n"); 55 printf("Can't do it with current phone protocol\n");
55 GSM_TerminateConnection(&s); 56 GSM_TerminateConnection(&s);
56 exit(-1); 57 exit(-1);
57 default: 58 default:
58 break; 59 break;
59 } 60 }
60} 61}
61 62
62static bool answer_yes2(char *text) 63static bool answer_yes2(char *text)
63{ 64{
64 int len; 65 int len;
65 char ans[99]; 66 char ans[99];
66 67
67 while (1) { 68 while (1) {
68 printf("%s (yes/no) ? ",text); 69 printf("%s (yes/no) ? ",text);
69 len=GetLine(stdin, ans, 99); 70 len=GetLine(stdin, ans, 99);
70 if (len==-1) exit(-1); 71 if (len==-1) exit(-1);
71 if (mystrncasecmp(ans, "yes",0)) return true; 72 if (mystrncasecmp(ans, "yes",0)) return true;
72 if (mystrncasecmp(ans, "no" ,0)) return false; 73 if (mystrncasecmp(ans, "no" ,0)) return false;
73 } 74 }
74} 75}
75 76
76/* ------------------- functions ------------------------------------------- */ 77/* ------------------- functions ------------------------------------------- */
77 78
78static DCT4_Feature DCT4Features[] = { 79static DCT4_Feature DCT4Features[] = {
79 {DCT4_ALWAYS_ONLINE, "GPRS Always Online", {{0,"on (Context)"},{1,"off (Attach)"},{0,""}}},///?? 80 {DCT4_ALWAYS_ONLINE, "GPRS Always Online", {{0,"on (Context)"},{1,"off (Attach)"},{0,""}}},///??
80 {DCT4_GPRS_PCCH, "PCCH support for GPRS", {{1,"on"},{0,"off"},{0,""}}}, 81 {DCT4_GPRS_PCCH, "PCCH support for GPRS", {{1,"on"},{0,"off"},{0,""}}},
81 {DCT4_GEA1, "GEA1 support indication", {{1,"on"},{0,"off"},{0,""}}}, 82 {DCT4_GEA1, "GEA1 support indication", {{1,"on"},{0,"off"},{0,""}}},
82 {DCT4_EOTD, "EOTD support", {{1,"on"},{0,"off"},{0,""}}}, 83 {DCT4_EOTD, "EOTD support", {{1,"on"},{0,"off"},{0,""}}},
83 {DCT4_WAP_PUSH, "WAP push", {{1,"on"},{0,"off"},{0,""}}}, 84 {DCT4_WAP_PUSH, "WAP push", {{1,"on"},{0,"off"},{0,""}}},
84 {DCT4_USE_PREF_SIM_NET, "Use SIM preffered network list",{{1,"on"},{0,"off"},{0,""}}}, 85 {DCT4_USE_PREF_SIM_NET, "Use SIM preffered network list",{{1,"on"},{0,"off"},{0,""}}},
85 {DCT4_JAVA_TCK, "Java TCK support", {{1,"on"},{0,"off"},{0,""}}}, 86 {DCT4_JAVA_TCK, "Java TCK support", {{1,"on"},{0,"off"},{0,""}}},
86 87
87 {DCT4_ALS, "Alternate Line Service (ALS)", {{1,"on"},{0,"off"},{0,""}}}, 88 {DCT4_ALS, "Alternate Line Service (ALS)", {{1,"on"},{0,"off"},{0,""}}},
88 {DCT4_A52, "Ciphering alghoritm A52", {{1,"on"},{0,"off"},{0,""}}}, 89 {DCT4_A52, "Ciphering alghoritm A52", {{1,"on"},{0,"off"},{0,""}}},
89 {DCT4_CSP, "Customer Service Profile", {{0,"off"},{1,"on"},{0,""}}}, 90 {DCT4_CSP, "Customer Service Profile", {{0,"off"},{1,"on"},{0,""}}},
90 {DCT4_EONS, "EONS support", {{1,"on"},{0,"off"},{0,""}}}, 91 {DCT4_EONS, "EONS support", {{1,"on"},{0,"off"},{0,""}}},
91 {DCT4_3GINDICATOR, "3G indicator", {{1,"on"},{0,"off"},{0,""}}}, 92 {DCT4_3GINDICATOR, "3G indicator", {{1,"on"},{0,"off"},{0,""}}},
92 {DCT4_DISPLAY_PHONE_NAME, "Display both number and name for incoming calls",{{1,"on"},{0,"off"},{0,""}}}, 93 {DCT4_DISPLAY_PHONE_NAME, "Display both number and name for incoming calls",{{1,"on"},{0,"off"},{0,""}}},
93 {DCT4_DISPLAY_WAP_PROFILE, "Display selected WAP profile name instead of Home option menu in Services",{{1,"on"},{0,"off"},{0,""}}}, 94 {DCT4_DISPLAY_WAP_PROFILE, "Display selected WAP profile name instead of Home option menu in Services",{{1,"on"},{0,"off"},{0,""}}},
94 95
95 {DCT4_GAMES_WAP_DOWNLOAD, "Games WAP download", {{1,"on"},{0,"off"},{0,""}}}, 96 {DCT4_GAMES_WAP_DOWNLOAD, "Games WAP download", {{1,"on"},{0,"off"},{0,""}}},
96 {DCT4_GAMES_SCORE_SEND, "Games WAP score send", {{1,"on"},{0,"off"},{0,""}}}, 97 {DCT4_GAMES_SCORE_SEND, "Games WAP score send", {{1,"on"},{0,"off"},{0,""}}},
97 {DCT4_GAMES_URL_CHECK, "Games URL check", {{1,"on"},{0,"off"},{0,""}}}, 98 {DCT4_GAMES_URL_CHECK, "Games URL check", {{1,"on"},{0,"off"},{0,""}}},
98 99
99 {DCT4_BLUETOOTH_MENU, "Bluetooth menu", {{1,"on"},{0,"off"},{0,""}}}, 100 {DCT4_BLUETOOTH_MENU, "Bluetooth menu", {{1,"on"},{0,"off"},{0,""}}},
100 {DCT4_WAP_BOOKMARKS_MENU, "Bookmarks menu in Services", {{1,"on"},{0,"off"},{0,""}}}, 101 {DCT4_WAP_BOOKMARKS_MENU, "Bookmarks menu in Services", {{1,"on"},{0,"off"},{0,""}}},
101 {DCT4_WAP_BOOKMARKS_MENU2, "Bookmarks menu in Services", {{3,"bookmarks & download"},{0,"off"},{0,""}}}, 102 {DCT4_WAP_BOOKMARKS_MENU2, "Bookmarks menu in Services", {{3,"bookmarks & download"},{0,"off"},{0,""}}},
102 {DCT4_WAP_GOTO_MENU, "GoTo menu in Services", {{0,"on"},{1,"off"},{0,""}}}, 103 {DCT4_WAP_GOTO_MENU, "GoTo menu in Services", {{0,"on"},{1,"off"},{0,""}}},
103 {DCT4_WAP_SETTINGS_MENU, "Profiles menu in Services", {{0,"on"},{1,"off"},{0,""}}}, 104 {DCT4_WAP_SETTINGS_MENU, "Profiles menu in Services", {{0,"on"},{1,"off"},{0,""}}},
104 {DCT4_SERVICES_GAMES_APP_GALLERY,"Services menu in Games/Apps/Gallery",{{1,"on"},{0,"off"},{0,""}}}, 105 {DCT4_SERVICES_GAMES_APP_GALLERY,"Services menu in Games/Apps/Gallery",{{1,"on"},{0,"off"},{0,""}}},
105 {DCT4_JAVA_GAMES_MENU, "Java games menu in Games", {{1,"on"},{0,"off"},{0,""}}}, 106 {DCT4_JAVA_GAMES_MENU, "Java games menu in Games", {{1,"on"},{0,"off"},{0,""}}},
106 {DCT4_SAT_CONFIRM_MENU, "Can use confirming SIM service actions", {{1,"on"},{0,"off"},{0,""}}}, 107 {DCT4_SAT_CONFIRM_MENU, "Can use confirming SIM service actions", {{1,"on"},{0,"off"},{0,""}}},
107 {DCT4_INSTANT_MESS_MENU, "Instant Messaging in Messages",{{1,"on"},{0,"off"},{0,""}}}, 108 {DCT4_INSTANT_MESS_MENU, "Instant Messaging in Messages",{{1,"on"},{0,"off"},{0,""}}},
108 {DCT4_CONFIRM_ALS, "Confirm using ALS", {{1,"on"},{0,"off"},{0,""}}}, 109 {DCT4_CONFIRM_ALS, "Confirm using ALS", {{1,"on"},{0,"off"},{0,""}}},
109 {DCT4_BOOKMARK_GOTO_MENU, "Bookmarks in GoTo menu", {{1,"on"},{0,"off"},{0,""}}}, 110 {DCT4_BOOKMARK_GOTO_MENU, "Bookmarks in GoTo menu", {{1,"on"},{0,"off"},{0,""}}},
110 111
111 {DCT4_5100_IDENTIFY, "Phone identification", {{1,"NPM-6U"},{0,"NPM-6"},{0,""}}}, 112 {DCT4_5100_IDENTIFY, "Phone identification", {{1,"NPM-6U"},{0,"NPM-6"},{0,""}}},
112 113
113#ifdef DEBUG 114#ifdef DEBUG
114 {DCT4_TEST,"",{{1,"1"},{0,"0"}}}, 115 {DCT4_TEST,"",{{1,"1"},{0,"0"}}},
115#endif 116#endif
116 117
117 {0, "", {{0,""}}} 118 {0, "", {{0,""}}}
118}; 119};
119 120
120static DCT4_Phone_Features DCT4PhoneFeatures[] = { 121static DCT4_Phone_Features DCT4PhoneFeatures[] = {
121 /*3100*/ {"RH-19",{{DCT4_ALS,1},{DCT4_A52,3},{DCT4_CSP,4},{DCT4_GPRS_PCCH,8}, 122 /*3100*/ {"RH-19",{{DCT4_ALS,1},{DCT4_A52,3},{DCT4_CSP,4},{DCT4_GPRS_PCCH,8},
122 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 123 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
123 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 124 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
124 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 125 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
125 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 126 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
126 {DCT4_EONS,28},{DCT4_3GINDICATOR,30},{DCT4_INSTANT_MESS_MENU,33}, 127 {DCT4_EONS,28},{DCT4_3GINDICATOR,30},{DCT4_INSTANT_MESS_MENU,33},
127 {DCT4_CONFIRM_ALS,35}, 128 {DCT4_CONFIRM_ALS,35},
128 {0,0}}}, 129 {0,0}}},
129 /*3200*/ {"RH-30",{{DCT4_ALS,2},{DCT4_A52,4},{DCT4_CSP,5},{DCT4_GPRS_PCCH,14}, 130 /*3200*/ {"RH-30",{{DCT4_ALS,2},{DCT4_A52,4},{DCT4_CSP,5},{DCT4_GPRS_PCCH,14},
130 {DCT4_GEA1,15},{DCT4_EOTD,18},{DCT4_WAP_SETTINGS_MENU,20}, 131 {DCT4_GEA1,15},{DCT4_EOTD,18},{DCT4_WAP_SETTINGS_MENU,20},
131 {DCT4_DISPLAY_PHONE_NAME,21},{DCT4_WAP_GOTO_MENU,23}, 132 {DCT4_DISPLAY_PHONE_NAME,21},{DCT4_WAP_GOTO_MENU,23},
132 {DCT4_SERVICES_GAMES_APP_GALLERY,26},{DCT4_3GINDICATOR,28}, 133 {DCT4_SERVICES_GAMES_APP_GALLERY,26},{DCT4_3GINDICATOR,28},
133 {DCT4_DISPLAY_WAP_PROFILE,31},{DCT4_SAT_CONFIRM_MENU,33}, 134 {DCT4_DISPLAY_WAP_PROFILE,31},{DCT4_SAT_CONFIRM_MENU,33},
134 {DCT4_CONFIRM_ALS,34},{DCT4_EONS,40},{DCT4_ALWAYS_ONLINE,45}, 135 {DCT4_CONFIRM_ALS,34},{DCT4_EONS,40},{DCT4_ALWAYS_ONLINE,45},
135 {0,0}}}, 136 {0,0}}},
136 /*3200*/ {"RH-31",{{DCT4_ALS,2},{DCT4_A52,4},{DCT4_CSP,5},{DCT4_GPRS_PCCH,14}, 137 /*3200*/ {"RH-31",{{DCT4_ALS,2},{DCT4_A52,4},{DCT4_CSP,5},{DCT4_GPRS_PCCH,14},
137 {DCT4_GEA1,15},{DCT4_EOTD,18},{DCT4_WAP_SETTINGS_MENU,20}, 138 {DCT4_GEA1,15},{DCT4_EOTD,18},{DCT4_WAP_SETTINGS_MENU,20},
138 {DCT4_DISPLAY_PHONE_NAME,21},{DCT4_WAP_GOTO_MENU,23}, 139 {DCT4_DISPLAY_PHONE_NAME,21},{DCT4_WAP_GOTO_MENU,23},
139 {DCT4_SERVICES_GAMES_APP_GALLERY,26},{DCT4_3GINDICATOR,28}, 140 {DCT4_SERVICES_GAMES_APP_GALLERY,26},{DCT4_3GINDICATOR,28},
140 {DCT4_DISPLAY_WAP_PROFILE,31},{DCT4_SAT_CONFIRM_MENU,33}, 141 {DCT4_DISPLAY_WAP_PROFILE,31},{DCT4_SAT_CONFIRM_MENU,33},
141 {DCT4_CONFIRM_ALS,34},{DCT4_EONS,40},{DCT4_ALWAYS_ONLINE,45}, 142 {DCT4_CONFIRM_ALS,34},{DCT4_EONS,40},{DCT4_ALWAYS_ONLINE,45},
142 {0,0}}}, 143 {0,0}}},
143 /*3300*/ {"NEM-1",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8}, 144 /*3300*/ {"NEM-1",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8},
144 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 145 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
145 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 146 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
146 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 147 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
147 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 148 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
148 /*MORE*/ {0,0}}}, 149 /*MORE*/ {0,0}}},
149 /*3510*/ {"NHM-8",{{DCT4_ALS,1},{DCT4_A52,3},{DCT4_CSP,6}, 150 /*3510*/ {"NHM-8",{{DCT4_ALS,1},{DCT4_A52,3},{DCT4_CSP,6},
150 {DCT4_GAMES_WAP_DOWNLOAD,7},{DCT4_GAMES_SCORE_SEND,8}, 151 {DCT4_GAMES_WAP_DOWNLOAD,7},{DCT4_GAMES_SCORE_SEND,8},
151 {DCT4_GAMES_URL_CHECK,9},{DCT4_GPRS_PCCH,13}, 152 {DCT4_GAMES_URL_CHECK,9},{DCT4_GPRS_PCCH,13},
152 {DCT4_GEA1,15},{DCT4_ALWAYS_ONLINE,18},{0,0}}}, 153 {DCT4_GEA1,15},{DCT4_ALWAYS_ONLINE,18},{0,0}}},
153 /*3510i*/{"RH-9",{{DCT4_ALS,1},{DCT4_A52,3},{DCT4_CSP,4},{DCT4_GPRS_PCCH,9}, 154 /*3510i*/{"RH-9",{{DCT4_ALS,1},{DCT4_A52,3},{DCT4_CSP,4},{DCT4_GPRS_PCCH,9},
154 {DCT4_DISPLAY_PHONE_NAME,14},{DCT4_WAP_GOTO_MENU,15}, 155 {DCT4_DISPLAY_PHONE_NAME,14},{DCT4_WAP_GOTO_MENU,15},
155 {DCT4_WAP_SETTINGS_MENU,16},{DCT4_SERVICES_GAMES_APP_GALLERY,19}, 156 {DCT4_WAP_SETTINGS_MENU,16},{DCT4_SERVICES_GAMES_APP_GALLERY,19},
156 {DCT4_DISPLAY_WAP_PROFILE,25},{0,0}}}, 157 {DCT4_DISPLAY_WAP_PROFILE,25},{0,0}}},
157 /*3650*/ {"NHL-8",{{DCT4_ALS,1},{0,0}}}, 158 /*3650*/ {"NHL-8",{{DCT4_ALS,1},{0,0}}},
158 /*5100*/ {"NPM-6",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8}, 159 /*5100*/ {"NPM-6",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8},
159 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 160 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
160 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 161 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
161 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 162 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
162 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 163 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
163 {DCT4_EONS,28}, 164 {DCT4_EONS,28},
164 // {DCT4_5100_IDENTIFY,10}, 165 // {DCT4_5100_IDENTIFY,10},
165 {0,0}}}, 166 {0,0}}},
166 /*5100*/ {"NPM-6U",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8}, 167 /*5100*/ {"NPM-6U",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8},
167 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 168 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
168 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 169 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
169 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 170 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
170 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 171 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
171 {DCT4_EONS,28}, 172 {DCT4_EONS,28},
172 // {DCT4_5100_IDENTIFY,10}, 173 // {DCT4_5100_IDENTIFY,10},
173 {0,0}}}, 174 {0,0}}},
174 /*6100*/ {"NPL-2",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8}, 175 /*6100*/ {"NPL-2",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8},
175 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 176 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
176 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 177 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
177 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 178 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
178 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 179 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
179 {0,0}}}, 180 {0,0}}},
180 /*6220*/ {"RH-20",{{DCT4_ALS,1},{DCT4_A52,3},{DCT4_CSP,4}, 181 /*6220*/ {"RH-20",{{DCT4_ALS,1},{DCT4_A52,3},{DCT4_CSP,4},
181 {DCT4_GEA1,14},{DCT4_EOTD,17},{DCT4_WAP_SETTINGS_MENU,19}, 182 {DCT4_GEA1,14},{DCT4_EOTD,17},{DCT4_WAP_SETTINGS_MENU,19},
182 {DCT4_DISPLAY_PHONE_NAME,20},{DCT4_WAP_GOTO_MENU,22}, 183 {DCT4_DISPLAY_PHONE_NAME,20},{DCT4_WAP_GOTO_MENU,22},
183 {DCT4_WAP_BOOKMARKS_MENU2,24},{DCT4_SERVICES_GAMES_APP_GALLERY,25}, 184 {DCT4_WAP_BOOKMARKS_MENU2,24},{DCT4_SERVICES_GAMES_APP_GALLERY,25},
184 {DCT4_3GINDICATOR,27},{DCT4_DISPLAY_WAP_PROFILE,30},{DCT4_SAT_CONFIRM_MENU,32}, 185 {DCT4_3GINDICATOR,27},{DCT4_DISPLAY_WAP_PROFILE,30},{DCT4_SAT_CONFIRM_MENU,32},
185 {DCT4_CONFIRM_ALS,33},{DCT4_JAVA_TCK,36},{DCT4_BOOKMARK_GOTO_MENU,37}, 186 {DCT4_CONFIRM_ALS,33},{DCT4_JAVA_TCK,36},{DCT4_BOOKMARK_GOTO_MENU,37},
186 {0,0}}}, 187 {0,0}}},
187 /*6310*/ {"NPE-4",{{DCT4_ALS,1},{DCT4_A52,3},{DCT4_CSP,6},{DCT4_GAMES_WAP_DOWNLOAD,7}, 188 /*6310*/ {"NPE-4",{{DCT4_ALS,1},{DCT4_A52,3},{DCT4_CSP,6},{DCT4_GAMES_WAP_DOWNLOAD,7},
188 {DCT4_GAMES_SCORE_SEND,8},{DCT4_GAMES_URL_CHECK,9},{DCT4_BLUETOOTH_MENU,10}, 189 {DCT4_GAMES_SCORE_SEND,8},{DCT4_GAMES_URL_CHECK,9},{DCT4_BLUETOOTH_MENU,10},
189 {DCT4_GPRS_PCCH,13},{DCT4_GEA1,15},{DCT4_ALWAYS_ONLINE,18},{0,0}}}, 190 {DCT4_GPRS_PCCH,13},{DCT4_GEA1,15},{DCT4_ALWAYS_ONLINE,18},{0,0}}},
190 /*6310i*/{"NPL-1",{{DCT4_ALS,1},{DCT4_A52,3},{DCT4_CSP,6},{DCT4_GAMES_WAP_DOWNLOAD,7}, 191 /*6310i*/{"NPL-1",{{DCT4_ALS,1},{DCT4_A52,3},{DCT4_CSP,6},{DCT4_GAMES_WAP_DOWNLOAD,7},
191 {DCT4_GAMES_SCORE_SEND,8},{DCT4_GAMES_URL_CHECK,9}, 192 {DCT4_GAMES_SCORE_SEND,8},{DCT4_GAMES_URL_CHECK,9},
192 {DCT4_BLUETOOTH_MENU,10},{DCT4_USE_PREF_SIM_NET,11}, 193 {DCT4_BLUETOOTH_MENU,10},{DCT4_USE_PREF_SIM_NET,11},
193 {DCT4_GPRS_PCCH,13},{DCT4_GEA1,15},{DCT4_EOTD,16}, 194 {DCT4_GPRS_PCCH,13},{DCT4_GEA1,15},{DCT4_EOTD,16},
194 {DCT4_ALWAYS_ONLINE,17},{DCT4_JAVA_GAMES_MENU,18}, 195 {DCT4_ALWAYS_ONLINE,17},{DCT4_JAVA_GAMES_MENU,18},
195 {DCT4_WAP_BOOKMARKS_MENU,20},{DCT4_WAP_SETTINGS_MENU,21}, 196 {DCT4_WAP_BOOKMARKS_MENU,20},{DCT4_WAP_SETTINGS_MENU,21},
196 {DCT4_WAP_PUSH,28},{DCT4_WAP_GOTO_MENU,29},{0,0}}}, 197 {DCT4_WAP_PUSH,28},{DCT4_WAP_GOTO_MENU,29},{0,0}}},
197 /*6510*/ {"NPM-9",{{DCT4_ALS,1},{DCT4_A52,3},{DCT4_CSP,6},{DCT4_GAMES_WAP_DOWNLOAD,7}, 198 /*6510*/ {"NPM-9",{{DCT4_ALS,1},{DCT4_A52,3},{DCT4_CSP,6},{DCT4_GAMES_WAP_DOWNLOAD,7},
198 {DCT4_GAMES_SCORE_SEND,8},{DCT4_GAMES_URL_CHECK,9}, 199 {DCT4_GAMES_SCORE_SEND,8},{DCT4_GAMES_URL_CHECK,9},
199 {DCT4_GPRS_PCCH,13},{DCT4_GEA1,15},{DCT4_ALWAYS_ONLINE,18},{0,0}}}, 200 {DCT4_GPRS_PCCH,13},{DCT4_GEA1,15},{DCT4_ALWAYS_ONLINE,18},{0,0}}},
200 /*6610*/ {"NHL-4U",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8}, 201 /*6610*/ {"NHL-4U",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8},
201 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 202 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
202 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 203 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
203 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 204 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
204 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 205 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
205 {0,0}}}, 206 {0,0}}},
206 /*6800*/ {"NHL-6",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8}, 207 /*6800*/ {"NHL-6",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8},
207 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 208 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
208 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 209 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
209 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 210 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
210 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 211 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
211 /*MORE*/ {0,0}}}, 212 /*MORE*/ {0,0}}},
212 /*7210*/ {"NHL-4",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8}, 213 /*7210*/ {"NHL-4",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8},
213 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 214 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
214 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 215 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
215 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 216 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
216 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 217 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
217 {0,0}}}, 218 {0,0}}},
218 /*7250*/ {"NHL-4J",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8}, 219 /*7250*/ {"NHL-4J",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8},
219 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 220 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
220 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 221 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
221 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 222 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
222 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 223 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
223 {0,0}}}, 224 {0,0}}},
224 /*7250i*/{"NHL-4JX",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8}, 225 /*7250i*/{"NHL-4JX",{{DCT4_ALS,1},{DCT4_CSP,4},{DCT4_GAMES_URL_CHECK,5},{DCT4_GPRS_PCCH,8},
225 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 226 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
226 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 227 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
227 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 228 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
228 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 229 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
229 /*MORE*/ {0,0}}}, 230 /*MORE*/ {0,0}}},
230 /*8310*/{"NHM-7",{{DCT4_ALS,1},{DCT4_CSP,6},{DCT4_GAMES_WAP_DOWNLOAD,7}, 231 /*8310*/{"NHM-7",{{DCT4_ALS,1},{DCT4_CSP,6},{DCT4_GAMES_WAP_DOWNLOAD,7},
@@ -696,646 +697,654 @@ void DCT4GetVoiceRecord(int argc, char *argv[])
696 fwrite(Buffer,1,size,WAVFile); 697 fwrite(Buffer,1,size,WAVFile);
697 } 698 }
698 if (error == ERR_EMPTY) break; 699 if (error == ERR_EMPTY) break;
699 Print_Error(error); 700 Print_Error(error);
700 CurrentLocation += 4; 701 CurrentLocation += 4;
701 ReqGet[11] = CurrentLocation / 256; 702 ReqGet[11] = CurrentLocation / 256;
702 ReqGet[12] = CurrentLocation % 256; 703 ReqGet[12] = CurrentLocation % 256;
703 if (CurrentLocation+4 > TokenLocation) break; 704 if (CurrentLocation+4 > TokenLocation) break;
704 } 705 }
705 dbgprintf("Getting first part in last sequence of voice record\n"); 706 dbgprintf("Getting first part in last sequence of voice record\n");
706 for (i=255;i>=0;i--) { 707 for (i=255;i>=0;i--) {
707 ReqGet[16] = i; 708 ReqGet[16] = i;
708 ReqGet[17] = Token; 709 ReqGet[17] = Token;
709 fprintf(stderr,"."); 710 fprintf(stderr,".");
710 error=GSM_WaitFor (&s, ReqGet, 18, 0x23, 4, ID_User4); 711 error=GSM_WaitFor (&s, ReqGet, 18, 0x23, 4, ID_User4);
711 if (error == ERR_NONE) { 712 if (error == ERR_NONE) {
712 wavfilesize += size; 713 wavfilesize += size;
713 fwrite(Buffer,1,size,WAVFile); 714 fwrite(Buffer,1,size,WAVFile);
714 break; 715 break;
715 } 716 }
716 if (error != ERR_EMPTY) Print_Error(error); 717 if (error != ERR_EMPTY) Print_Error(error);
717 } 718 }
718 while (1) { 719 while (1) {
719 dbgprintf("Getting next part of last sequence in voice record\n"); 720 dbgprintf("Getting next part of last sequence in voice record\n");
720 CurrentLocation += 4; 721 CurrentLocation += 4;
721 ReqGet[11] = CurrentLocation / 256; 722 ReqGet[11] = CurrentLocation / 256;
722 ReqGet[12] = CurrentLocation % 256; 723 ReqGet[12] = CurrentLocation % 256;
723 fprintf(stderr,"."); 724 fprintf(stderr,".");
724 error=GSM_WaitFor (&s, ReqGet, 18, 0x23, 4, ID_User4); 725 error=GSM_WaitFor (&s, ReqGet, 18, 0x23, 4, ID_User4);
725 if (error == ERR_NONE) { 726 if (error == ERR_NONE) {
726 wavfilesize += size; 727 wavfilesize += size;
727 fwrite(Buffer,1,size,WAVFile); 728 fwrite(Buffer,1,size,WAVFile);
728 } 729 }
729 if (error == ERR_EMPTY) break; 730 if (error == ERR_EMPTY) break;
730 Print_Error(error); 731 Print_Error(error);
731 } 732 }
732 fprintf(stderr,"\n"); 733 fprintf(stderr,"\n");
733 734
734 wavfilesize += sizeof(WAV_Header) + sizeof(FMT_Header) + sizeof(DATA_Header); 735 wavfilesize += sizeof(WAV_Header) + sizeof(FMT_Header) + sizeof(DATA_Header);
735 WAV_Header[4] = (unsigned char)(wavfilesize % 256); 736 WAV_Header[4] = (unsigned char)(wavfilesize % 256);
736 WAV_Header[5] = (unsigned char)(wavfilesize / 256); 737 WAV_Header[5] = (unsigned char)(wavfilesize / 256);
737 WAV_Header[6] = (unsigned char)(wavfilesize / (256*256)); 738 WAV_Header[6] = (unsigned char)(wavfilesize / (256*256));
738 WAV_Header[7] = (unsigned char)(wavfilesize / (256*256*256)); 739 WAV_Header[7] = (unsigned char)(wavfilesize / (256*256*256));
739 740
740 /* FIXME */ 741 /* FIXME */
741 FMT_Header[36]= (unsigned char)(((wavfilesize - 238) * 5 ) % 256); 742 FMT_Header[36]= (unsigned char)(((wavfilesize - 238) * 5 ) % 256);
742 FMT_Header[37]= (unsigned char)(((wavfilesize - 238) * 5 ) / 256); 743 FMT_Header[37]= (unsigned char)(((wavfilesize - 238) * 5 ) / 256);
743 FMT_Header[38]= (unsigned char)(((wavfilesize - 238) * 5 ) / (256*256)); 744 FMT_Header[38]= (unsigned char)(((wavfilesize - 238) * 5 ) / (256*256));
744 FMT_Header[39]= (unsigned char)(((wavfilesize - 238) * 5 ) / (256*256*256)); 745 FMT_Header[39]= (unsigned char)(((wavfilesize - 238) * 5 ) / (256*256*256));
745 746
746 wavfilesize = wavfilesize - 54 - 6; 747 wavfilesize = wavfilesize - 54 - 6;
747 DATA_Header[4] = (unsigned char)(wavfilesize % 256); 748 DATA_Header[4] = (unsigned char)(wavfilesize % 256);
748 DATA_Header[5] = (unsigned char)(wavfilesize / 256); 749 DATA_Header[5] = (unsigned char)(wavfilesize / 256);
749 DATA_Header[6] = (unsigned char)(wavfilesize / (256*256)); 750 DATA_Header[6] = (unsigned char)(wavfilesize / (256*256));
750 DATA_Header[7] = (unsigned char)(wavfilesize / (256*256*256)); 751 DATA_Header[7] = (unsigned char)(wavfilesize / (256*256*256));
751 752
752 fseek( WAVFile, 0, SEEK_SET); 753 fseek( WAVFile, 0, SEEK_SET);
753 fwrite(&WAV_Header, 1, sizeof(WAV_Header),WAVFile); 754 fwrite(&WAV_Header, 1, sizeof(WAV_Header),WAVFile);
754 fwrite(&FMT_Header, 1, sizeof(FMT_Header),WAVFile); 755 fwrite(&FMT_Header, 1, sizeof(FMT_Header),WAVFile);
755 fwrite(&DATA_Header, 1, sizeof(DATA_Header),WAVFile); 756 fwrite(&DATA_Header, 1, sizeof(DATA_Header),WAVFile);
756 757
757 fclose(WAVFile); 758 fclose(WAVFile);
758 759
759 GSM_Terminate(); 760 GSM_Terminate();
760} 761}
761 762
762static GSM_Error DCT4_ReplyGetBTInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 763static GSM_Error DCT4_ReplyGetBTInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
763{ 764{
764 printf("device address %02x%02x%02x%02x%02x%02x\n", 765 printf("device address %02x%02x%02x%02x%02x%02x\n",
765 msg.Buffer[9],msg.Buffer[10],msg.Buffer[11], 766 msg.Buffer[9],msg.Buffer[10],msg.Buffer[11],
766 msg.Buffer[12],msg.Buffer[13],msg.Buffer[14]); 767 msg.Buffer[12],msg.Buffer[13],msg.Buffer[14]);
767 return ERR_NONE; 768 return ERR_NONE;
768} 769}
769 770
770static GSM_Error DCT4_ReplyGetSimlock(GSM_Protocol_Message msg, GSM_StateMachine *s) 771static GSM_Error DCT4_ReplyGetSimlock(GSM_Protocol_Message msg, GSM_StateMachine *s)
771{ 772{
772 int i; 773 int i;
773 774
774 switch (msg.Buffer[3]) { 775 switch (msg.Buffer[3]) {
775 case 0x0D: 776 case 0x0D:
776 dbgprintf("Simlock info received\n"); 777 dbgprintf("Simlock info received\n");
777 dbgprintf("Config_Data: "); 778 dbgprintf("Config_Data: ");
778 for (i=14;i<22;i++) { 779 for (i=14;i<22;i++) {
779 dbgprintf("%02x",msg.Buffer[i]); 780 dbgprintf("%02x",msg.Buffer[i]);
780 } 781 }
781 dbgprintf("\n"); 782 dbgprintf("\n");
782 dbgprintf("Profile_Bits: "); 783 dbgprintf("Profile_Bits: ");
783 for (i=22;i<30;i++) { 784 for (i=22;i<30;i++) {
784 dbgprintf("%02x",msg.Buffer[i]); 785 dbgprintf("%02x",msg.Buffer[i]);
785 } 786 }
786 dbgprintf("\n"); 787 dbgprintf("\n");
787 return ERR_NONE; 788 return ERR_NONE;
788 case 0x13: 789 case 0x13:
789 dbgprintf("Simlock info received\n"); 790 dbgprintf("Simlock info received\n");
790 if (msg.Buffer[58] == 0x05 && msg.Buffer[59] == 0x02) { 791 if (msg.Buffer[58] == 0x05 && msg.Buffer[59] == 0x02) {
791 dbgprintf("SIM_PATH: "); 792 dbgprintf("SIM_PATH: ");
792 for (i=44;i<52;i++) { 793 for (i=44;i<52;i++) {
793 dbgprintf("%02x",msg.Buffer[i]); 794 dbgprintf("%02x",msg.Buffer[i]);
794 } 795 }
795 dbgprintf("\n"); 796 dbgprintf("\n");
796 printf("Simlock data : "); 797 printf("Simlock data : ");
797 for (i=60;i<63;i++) { 798 for (i=60;i<63;i++) {
798 printf("%02x",msg.Buffer[i]); 799 printf("%02x",msg.Buffer[i]);
799 } 800 }
800 printf("\n"); 801 printf("\n");
801 } 802 }
802 return ERR_NONE; 803 return ERR_NONE;
803 } 804 }
804 return ERR_UNKNOWNRESPONSE; 805 return ERR_UNKNOWNRESPONSE;
805} 806}
806 807
807void DCT4Info(int argc, char *argv[]) 808void DCT4Info(int argc, char *argv[])
808{ 809{
809 unsigned char GetBTAddress[8] = {N6110_FRAME_HEADER, 0x09, 0x19, 0x01, 0x03, 0x06}; 810 unsigned char GetBTAddress[8] = {N6110_FRAME_HEADER, 0x09, 0x19, 0x01, 0x03, 0x06};
810 unsigned char GetSimlock[5] = {N6110_FRAME_HEADER, 0x12, 0x0D}; 811 unsigned char GetSimlock[5] = {N6110_FRAME_HEADER, 0x12, 0x0D};
811 unsigned char value[10]; 812 unsigned char value[10];
812 813
813 if (CheckDCT4Only()!=ERR_NONE) return; 814 if (CheckDCT4Only()!=ERR_NONE) return;
814 815
815 s.User.UserReplyFunctions=UserReplyFunctions4; 816 s.User.UserReplyFunctions=UserReplyFunctions4;
816 817
817 if (IsPhoneFeatureAvailable(s.Phone.Data.ModelInfo, F_BLUETOOTH)) { 818 if (IsPhoneFeatureAvailable(s.Phone.Data.ModelInfo, F_BLUETOOTH)) {
818 printf("Bluetooth : "); 819 printf("Bluetooth : ");
819 820
820 error=GSM_WaitFor (&s, GetBTAddress, 8, 0xD7, 4, ID_User6); 821 error=GSM_WaitFor (&s, GetBTAddress, 8, 0xD7, 4, ID_User6);
821 Print_Error(error); 822 Print_Error(error);
822 } 823 }
823 824
824 error=GSM_WaitFor (&s, GetSimlock, 5, 0x53, 4, ID_User6); 825 error=GSM_WaitFor (&s, GetSimlock, 5, 0x53, 4, ID_User6);
825 Print_Error(error); 826 Print_Error(error);
826 GetSimlock[4] = 0x0E; 827 GetSimlock[4] = 0x0E;
827 error=GSM_WaitFor (&s, GetSimlock, 5, 0x53, 4, ID_User6); 828 error=GSM_WaitFor (&s, GetSimlock, 5, 0x53, 4, ID_User6);
828 Print_Error(error); 829 Print_Error(error);
829 GetSimlock[3] = 0x0C; 830 GetSimlock[3] = 0x0C;
830 error=GSM_WaitFor (&s, GetSimlock, 4, 0x53, 4, ID_User6); 831 error=GSM_WaitFor (&s, GetSimlock, 4, 0x53, 4, ID_User6);
831 Print_Error(error); 832 Print_Error(error);
832 error=NOKIA_GetPhoneString(&s,"\x00\x03\x02\x07\x00\x08",6,0x1b,value,ID_User6,10); 833 error=NOKIA_GetPhoneString(&s,"\x00\x03\x02\x07\x00\x08",6,0x1b,value,ID_User6,10);
833 Print_Error(error); 834 Print_Error(error);
834 printf("UEM : %s\n",value); 835 printf("UEM : %s\n",value);
835} 836}
836 837
837 static FILE *T9File; 838 static FILE *T9File;
838 int T9Size; 839 int T9Size;
839 int T9FullSize; 840 int T9FullSize;
840 841
841static GSM_Error DCT4_ReplyGetT9(GSM_Protocol_Message msg, GSM_StateMachine *s) 842static GSM_Error DCT4_ReplyGetT9(GSM_Protocol_Message msg, GSM_StateMachine *s)
842{ 843{
843 T9FullSize = msg.Buffer[18] * 256 + msg.Buffer[19]; 844 T9FullSize = msg.Buffer[18] * 256 + msg.Buffer[19];
844 T9Size = msg.Length - 18; 845 T9Size = msg.Length - 18;
845 fwrite(msg.Buffer+18,1,T9Size,T9File); 846 fwrite(msg.Buffer+18,1,T9Size,T9File);
846 return ERR_NONE; 847 return ERR_NONE;
847} 848}
848 849
849void DCT4GetT9(int argc, char *argv[]) 850void DCT4GetT9(int argc, char *argv[])
850{ 851{
851 int i,T9Dictionary=0; 852 int i,T9Dictionary=0;
852 unsigned char req[] = {N7110_FRAME_HEADER, 0x04, 0x00, 0x5B, 853 unsigned char req[] = {N7110_FRAME_HEADER, 0x04, 0x00, 0x5B,
853 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 854 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
854 0x00, 0x00,/* Start position */ 855 0x00, 0x00,/* Start position */
855 0x00, 0x00, 856 0x00, 0x00,
856 0x02, 0xBC};/* How many bytes to read */ 857 0x02, 0xBC};/* How many bytes to read */
857 858
858 if (CheckDCT4Only()!=ERR_NONE) return; 859 if (CheckDCT4Only()!=ERR_NONE) return;
859 860
860 T9File = fopen("T9", "w"); 861 T9File = fopen("T9", "w");
861 if (T9File == NULL) return; 862 if (T9File == NULL) return;
862 863
863 s.User.UserReplyFunctions=UserReplyFunctions4; 864 s.User.UserReplyFunctions=UserReplyFunctions4;
864 865
865 i = 0; 866 i = 0;
866 while (1) { 867 while (1) {
867 req[12] = i / 256; 868 req[12] = i / 256;
868 req[13] = i % 256; 869 req[13] = i % 256;
869 if (i != 0) { 870 if (i != 0) {
870 if (T9Dictionary - i < req[16]*256+req[17]) { 871 if (T9Dictionary - i < req[16]*256+req[17]) {
871 req[16] = (T9Dictionary - i) / 256; 872 req[16] = (T9Dictionary - i) / 256;
872 req[17] = (T9Dictionary - i) % 256; 873 req[17] = (T9Dictionary - i) % 256;
873 } 874 }
874 if (T9Dictionary - i == 0) break; 875 if (T9Dictionary - i == 0) break;
875 } 876 }
876 error=GSM_WaitFor (&s, req, 18, 0x23, 4, ID_User3); 877 error=GSM_WaitFor (&s, req, 18, 0x23, 4, ID_User3);
877 Print_Error(error); 878 Print_Error(error);
878 if (i==0) { 879 if (i==0) {
879 T9Dictionary = T9FullSize; 880 T9Dictionary = T9FullSize;
880 dbgprintf("T9 dictionary size is %i\n",T9Dictionary); 881 dbgprintf("T9 dictionary size is %i\n",T9Dictionary);
881 } 882 }
882 i+=T9Size; 883 i+=T9Size;
883 } 884 }
884 885
885 fclose(T9File); 886 fclose(T9File);
886} 887}
887 888
889#ifdef GSM_ENABLE_NOKIA6510
890
888extern GSM_Error N6510_SetLight(GSM_StateMachine *s, N6510_PHONE_LIGHTS light, bool enable); 891extern GSM_Error N6510_SetLight(GSM_StateMachine *s, N6510_PHONE_LIGHTS light, bool enable);
889 892
890void DCT4SetLight(int argc, char *argv[]) 893void DCT4SetLight(int argc, char *argv[])
891{ 894{
892 int i; 895 int i;
893 N6510_PHONE_LIGHTS type; 896 N6510_PHONE_LIGHTS type;
894 bool enable; 897 bool enable;
895 898
896 if (mystrncasecmp(argv[2],"display",0)) { type = N6510_LIGHT_DISPLAY; 899 if (mystrncasecmp(argv[2],"display",0)) { type = N6510_LIGHT_DISPLAY;
897 } else if (mystrncasecmp(argv[2],"keypad",0)) {type = N6510_LIGHT_KEYPAD; 900 } else if (mystrncasecmp(argv[2],"keypad",0)) {type = N6510_LIGHT_KEYPAD;
898 } else if (mystrncasecmp(argv[2],"torch",0)) {type = N6510_LIGHT_TORCH; 901 } else if (mystrncasecmp(argv[2],"torch",0)) {type = N6510_LIGHT_TORCH;
899 } else { 902 } else {
900 printf("What lights should I enable (\"%s\") ?\n",argv[2]); 903 printf("What lights should I enable (\"%s\") ?\n",argv[2]);
901 exit(-1); 904 exit(-1);
902 } 905 }
903 906
904 if (mystrncasecmp(argv[3],"on",0)) { enable = true; 907 if (mystrncasecmp(argv[3],"on",0)) { enable = true;
905 } else if (mystrncasecmp(argv[3],"off",0)) {enable = false; 908 } else if (mystrncasecmp(argv[3],"off",0)) {enable = false;
906 } else { 909 } else {
907 printf("What should I do (\"%s\") ?\n",argv[3]); 910 printf("What should I do (\"%s\") ?\n",argv[3]);
908 exit(-1); 911 exit(-1);
909 } 912 }
910 913
911 for (i=0;i<s.ConfigNum;i++) { 914 for (i=0;i<s.ConfigNum;i++) {
912 s.Config[i].StartInfo = "false"; 915 s.Config[i].StartInfo = "false";
913 } 916 }
914 917
915 GSM_Init(true); 918 GSM_Init(true);
916 919
917 CheckDCT4(); 920 CheckDCT4();
918 921
919 error=N6510_SetLight(&s, type, enable); 922 error=N6510_SetLight(&s, type, enable);
920 Print_Error(error); 923 Print_Error(error);
921 924
922 GSM_Terminate(); 925 GSM_Terminate();
923} 926}
927#endif
924 928
925void DCT4DisplayTest(int argc, char *argv[]) 929void DCT4DisplayTest(int argc, char *argv[])
926{ 930{
927 unsigned char ans[200]; 931 unsigned char ans[200];
928 unsigned char req0[] = {0x00, 0x08, 0x0D, 0x00, 0x0F, 0x00}; 932 unsigned char req0[] = {0x00, 0x08, 0x0D, 0x00, 0x0F, 0x00};
929 unsigned char req[] = {0x00, 0x08, 0x0E, 0x00, 0x12, 0x01, 0x00, 0x04, 933 unsigned char req[] = {0x00, 0x08, 0x0E, 0x00, 0x12, 0x01, 0x00, 0x04,
930 0x09, /* test number */ 934 0x09, /* test number */
931 0x00}; 935 0x00};
932 936
933 if (CheckDCT4Only()!=ERR_NONE) return; 937 if (CheckDCT4Only()!=ERR_NONE) return;
934 938
935 s.User.UserReplyFunctions=UserReplyFunctions4; 939 s.User.UserReplyFunctions=UserReplyFunctions4;
936 940
937 DCT4_SetPhoneMode(&s, DCT4_MODE_TEST); 941 DCT4_SetPhoneMode(&s, DCT4_MODE_TEST);
938 942
939 s.Protocol.Functions->WriteMessage(&s, req0, 6, 0x40); 943 s.Protocol.Functions->WriteMessage(&s, req0, 6, 0x40);
940 944
941 req[8] = atoi(argv[2]); 945 req[8] = atoi(argv[2]);
942 s.Protocol.Functions->WriteMessage(&s, req, 10, 0x40); 946 s.Protocol.Functions->WriteMessage(&s, req, 10, 0x40);
943 947
944 printf("Press any key to continue...\n"); 948 printf("Press any key to continue...\n");
945 GetLine(stdin, ans, 99); 949 GetLine(stdin, ans, 99);
946 950
947 DCT4_SetPhoneMode(&s, DCT4_MODE_NORMAL); 951 DCT4_SetPhoneMode(&s, DCT4_MODE_NORMAL);
948} 952}
949 953
950int ADC; 954int ADC;
951 955
952static GSM_Error DCT4_ReplyGetADC(GSM_Protocol_Message msg, GSM_StateMachine *s) 956static GSM_Error DCT4_ReplyGetADC(GSM_Protocol_Message msg, GSM_StateMachine *s)
953{ 957{
954 if (msg.Buffer[6] == 0xff && msg.Buffer[7] == 0xff) return ERR_NONE; 958 if (msg.Buffer[6] == 0xff && msg.Buffer[7] == 0xff) return ERR_NONE;
955 switch (msg.Buffer[3]) { 959 switch (msg.Buffer[3]) {
956 case 0x10: 960 case 0x10:
957 printf("raw "); 961 printf("raw ");
958 printf("%10i ",msg.Buffer[8]*256+msg.Buffer[9]); 962 printf("%10i ",msg.Buffer[8]*256+msg.Buffer[9]);
959 break; 963 break;
960 case 0x12: 964 case 0x12:
961 printf("unit result "); 965 printf("unit result ");
962 printf("%10i ",(msg.Buffer[8]*256+msg.Buffer[9])*ADC); 966 printf("%10i ",(msg.Buffer[8]*256+msg.Buffer[9])*ADC);
963 break; 967 break;
964 } 968 }
965 return ERR_NONE; 969 return ERR_NONE;
966} 970}
967 971
968struct DCT4ADCInfo { 972struct DCT4ADCInfo {
969 char *name; 973 char *name;
970 char *unit; 974 char *unit;
971 int x; 975 int x;
972}; 976};
973 977
974static struct DCT4ADCInfo DCT4ADC[] = { 978static struct DCT4ADCInfo DCT4ADC[] = {
975 {"Battery voltage, divided:", "mV", 1}, 979 {"Battery voltage, divided:", "mV", 1},
976 {"Battery voltage, scaled:", "mV", 1}, 980 {"Battery voltage, scaled:", "mV", 1},
977 {"Charger voltage:", "mV", 1}, 981 {"Charger voltage:", "mV", 1},
978 {"Charger current:", "mA", 1}, 982 {"Charger current:", "mA", 1},
979 {"Battery size indicator:", "Ohms",100}, 983 {"Battery size indicator:", "Ohms",100},
980 {"Battery temperature:", "K", 1}, 984 {"Battery temperature:", "K", 1},
981 {"Headset interconnection:", "mV", 1}, 985 {"Headset interconnection:", "mV", 1},
982 {"Hook interconnection:", "mV", 1}, 986 {"Hook interconnection:", "mV", 1},
983 {"Light sensor:", "mV", 1}, 987 {"Light sensor:", "mV", 1},
984 {"Power amplifier temperature:","K", 1}, 988 {"Power amplifier temperature:","K", 1},
985 {"VCXO temperature:", "K", 1}, 989 {"VCXO temperature:", "K", 1},
986 {"Resistive keyboard 1/headint2:","mV", 1}, 990 {"Resistive keyboard 1/headint2:","mV", 1},
987 {"Resistive keyboard 1/auxdet:","mV", 1}, 991 {"Resistive keyboard 1/auxdet:","mV", 1},
988 {"Initial battery voltage:", "mV", 1}, 992 {"Initial battery voltage:", "mV", 1},
989 {"Battery Current:", "mA", 1}, 993 {"Battery Current:", "mA", 1},
990 {"Battery Current Fast:", "mA", 1}, 994 {"Battery Current Fast:", "mA", 1},
991 995
992 {"", "", 1} 996 {"", "", 1}
993}; 997};
994 998
995void DCT4GetADC(int argc, char *argv[]) 999void DCT4GetADC(int argc, char *argv[])
996{ 1000{
997 int i = 0; 1001 int i = 0;
998 unsigned char GetRaw[] = {N6110_FRAME_HEADER, 0x0F, 1002 unsigned char GetRaw[] = {N6110_FRAME_HEADER, 0x0F,
999 0x00, /* Test number */ 1003 0x00, /* Test number */
1000 0x01}; 1004 0x01};
1001 unsigned char GetUnit[] = {N6110_FRAME_HEADER, 0x11, 1005 unsigned char GetUnit[] = {N6110_FRAME_HEADER, 0x11,
1002 0x00, /* Test number */ 1006 0x00, /* Test number */
1003 0x01}; 1007 0x01};
1004 1008
1005 if (CheckDCT4Only()!=ERR_NONE) return; 1009 if (CheckDCT4Only()!=ERR_NONE) return;
1006 1010
1007 s.User.UserReplyFunctions=UserReplyFunctions4; 1011 s.User.UserReplyFunctions=UserReplyFunctions4;
1008 1012
1009 while (1) { 1013 while (1) {
1010 printf(" %30s ",DCT4ADC[i].name); 1014 printf(" %30s ",DCT4ADC[i].name);
1011 GetRaw[4] = i; 1015 GetRaw[4] = i;
1012 error=GSM_WaitFor (&s, GetRaw, 6, 0x17, 4, ID_User3); 1016 error=GSM_WaitFor (&s, GetRaw, 6, 0x17, 4, ID_User3);
1013 Print_Error(error); 1017 Print_Error(error);
1014 GetUnit[4] = i; 1018 GetUnit[4] = i;
1015 ADC = DCT4ADC[i].x; 1019 ADC = DCT4ADC[i].x;
1016 error=GSM_WaitFor (&s, GetUnit, 6, 0x17, 4, ID_User3); 1020 error=GSM_WaitFor (&s, GetUnit, 6, 0x17, 4, ID_User3);
1017 Print_Error(error); 1021 Print_Error(error);
1018 printf("%s\n",DCT4ADC[i].unit); 1022 printf("%s\n",DCT4ADC[i].unit);
1019 i++; 1023 i++;
1020 if (DCT4ADC[i].name[0] == 0x00) break; 1024 if (DCT4ADC[i].name[0] == 0x00) break;
1021 } 1025 }
1022} 1026}
1023 1027
1028#ifdef GSM_ENABLE_NOKIA6510
1029
1024 static double RadioFreq; 1030 static double RadioFreq;
1025 static unsigned char RadioName[100]; 1031 static unsigned char RadioName[100];
1026 1032
1027static GSM_Error DCT4_ReplyTuneRadio(GSM_Protocol_Message msg, GSM_StateMachine *s) 1033static GSM_Error DCT4_ReplyTuneRadio(GSM_Protocol_Message msg, GSM_StateMachine *s)
1028{ 1034{
1029 int length; 1035 int length;
1030 unsigned char name[100]; 1036 unsigned char name[100];
1031 1037
1032 switch (msg.Buffer[3]) { 1038 switch (msg.Buffer[3]) {
1033 case 0x09: 1039 case 0x09:
1034 N6510_DecodeFMFrequency(&RadioFreq, msg.Buffer+16); 1040 N6510_DecodeFMFrequency(&RadioFreq, msg.Buffer+16);
1035 1041
1036 length = msg.Buffer[8]; 1042 length = msg.Buffer[8];
1037 memcpy(name,msg.Buffer+18,length*2); 1043 memcpy(name,msg.Buffer+18,length*2);
1038 name[length*2] = 0x00; 1044 name[length*2] = 0x00;
1039 name[length*2+1] = 0x00; 1045 name[length*2+1] = 0x00;
1040 CopyUnicodeString(RadioName,name); 1046 CopyUnicodeString(RadioName,name);
1041 smprintf(s,"Station name: \"%s\"\n",DecodeUnicodeString(RadioName)); 1047 smprintf(s,"Station name: \"%s\"\n",DecodeUnicodeString(RadioName));
1042 return ERR_NONE; 1048 return ERR_NONE;
1043 case 0x15: 1049 case 0x15:
1044 case 0x16: 1050 case 0x16:
1045 smprintf(s,"Response for enabling radio/headset status received\n"); 1051 smprintf(s,"Response for enabling radio/headset status received\n");
1046 if (msg.Buffer[5] == 0) { 1052 if (msg.Buffer[5] == 0) {
1047 smprintf(s,"Connected\n"); 1053 smprintf(s,"Connected\n");
1048 return ERR_NONE; 1054 return ERR_NONE;
1049 } 1055 }
1050 smprintf(s,"Probably not connected\n"); 1056 smprintf(s,"Probably not connected\n");
1051 return ERR_PERMISSION; 1057 return ERR_PERMISSION;
1052 } 1058 }
1053 return ERR_UNKNOWNRESPONSE; 1059 return ERR_UNKNOWNRESPONSE;
1054} 1060}
1055 1061
1056void DCT4TuneRadio(int argc, char *argv[]) 1062void DCT4TuneRadio(int argc, char *argv[])
1057{ 1063{
1058 double Freq, diff; 1064 double Freq, diff;
1059 GSM_FMStation FMStation[50],FMStat; 1065 GSM_FMStation FMStation[50],FMStat;
1060 int i, j, num; 1066 int i, j, num;
1061 bool found; 1067 bool found;
1062 1068
1063 unsigned char Enable[] = {N6110_FRAME_HEADER, 0x00, 0x00, 0x00}; 1069 unsigned char Enable[] = {N6110_FRAME_HEADER, 0x00, 0x00, 0x00};
1064 unsigned char Disable[] = {N6110_FRAME_HEADER, 0x01, 0x0E, 0x00}; 1070 unsigned char Disable[] = {N6110_FRAME_HEADER, 0x01, 0x0E, 0x00};
1065 //unsigned char SetVolume[] = {N6110_FRAME_HEADER, 0x14, 1071 //unsigned char SetVolume[] = {N6110_FRAME_HEADER, 0x14,
1066 // 0x00,/* Volume level */ 1072 // 0x00,/* Volume level */
1067 // 0x00}; 1073 // 0x00};
1068 //unsigned char MuteUnMute[] = {N6110_FRAME_HEADER, 0x0F, 1074 //unsigned char MuteUnMute[] = {N6110_FRAME_HEADER, 0x0F,
1069 // 0x0C,/* 0x0B = mute, 0x0C = unmute */ 1075 // 0x0C,/* 0x0B = mute, 0x0C = unmute */
1070 // 0x00}; 1076 // 0x00};
1071 unsigned char SetFreq[] = {N6110_FRAME_HEADER, 0x08, 1077 unsigned char SetFreq[] = {N6110_FRAME_HEADER, 0x08,
1072 0x08, 0x14, 0x00, 0x01, 1078 0x08, 0x14, 0x00, 0x01,
1073 0x9A, 0x28}; /* Frequency */ 1079 0x9A, 0x28}; /* Frequency */
1074 // unsigned char Find1[] = {N6110_FRAME_HEADER, 0x08, 1080 // unsigned char Find1[] = {N6110_FRAME_HEADER, 0x08,
1075 // 0x04, 0x14, 0x00, 0x00, 0x00, 0x00}; 1081 // 0x04, 0x14, 0x00, 0x00, 0x00, 0x00};
1076 unsigned char Find2[] = {N6110_FRAME_HEADER, 0x08, 1082 unsigned char Find2[] = {N6110_FRAME_HEADER, 0x08,
1077 0x05, 0x14, 0x00, 0x00, 0x00, 0x00}; 1083 0x05, 0x14, 0x00, 0x00, 0x00, 0x00};
1078 //unsigned char SetStereo[] = {N6110_FRAME_HEADER, 0x19, 1084 //unsigned char SetStereo[] = {N6110_FRAME_HEADER, 0x19,
1079 // 0x0A, 0x00, 0x15}; 1085 // 0x0A, 0x00, 0x15};
1080 //unsigned char SetMono[] = {N6110_FRAME_HEADER, 0x19, 1086 //unsigned char SetMono[] = {N6110_FRAME_HEADER, 0x19,
1081 // 0x09, 0x00, 0x96}; 1087 // 0x09, 0x00, 0x96};
1082 1088
1083 GSM_Init(true); 1089 GSM_Init(true);
1084 1090
1085 CheckDCT4(); 1091 CheckDCT4();
1086 1092
1087 s.User.UserReplyFunctions=UserReplyFunctions4; 1093 s.User.UserReplyFunctions=UserReplyFunctions4;
1088 1094
1089 FMStat.Location = 1; 1095 FMStat.Location = 1;
1090 error = Phone->GetFMStation(&s,&FMStat); 1096 error = Phone->GetFMStation(&s,&FMStat);
1091 if (error != ERR_NONE && error != ERR_EMPTY) { 1097 if (error != ERR_NONE && error != ERR_EMPTY) {
1092 printf("Phone seems not to support radio\n"); 1098 printf("Phone seems not to support radio\n");
1093 GSM_Terminate(); 1099 GSM_Terminate();
1094 exit(-1); 1100 exit(-1);
1095 } 1101 }
1096 1102
1097 error=GSM_WaitFor (&s, Enable, 6, 0x3E, 4, ID_User3); 1103 error=GSM_WaitFor (&s, Enable, 6, 0x3E, 4, ID_User3);
1098 if (error == ERR_PERMISSION) { 1104 if (error == ERR_PERMISSION) {
1099 printf("Please connect headset. Required as antenna\n"); 1105 printf("Please connect headset. Required as antenna\n");
1100 GSM_Terminate(); 1106 GSM_Terminate();
1101 exit(-1); 1107 exit(-1);
1102 } 1108 }
1103 Print_Error(error); 1109 Print_Error(error);
1104 1110
1105 num=0; 1111 num=0;
1106 for (i=88;i<108;i++) { 1112 for (i=88;i<108;i++) {
1107 fprintf(stderr,"%cSearching: %i percent",13,(i-88)*100/(108-88)); 1113 fprintf(stderr,"%cSearching: %i percent",13,(i-88)*100/(108-88));
1108 Freq = i; 1114 Freq = i;
1109 N6510_EncodeFMFrequency(Freq, SetFreq+8); 1115 N6510_EncodeFMFrequency(Freq, SetFreq+8);
1110 error=GSM_WaitFor (&s, SetFreq, 10, 0x3E, 4, ID_User3); 1116 error=GSM_WaitFor (&s, SetFreq, 10, 0x3E, 4, ID_User3);
1111 Print_Error(error); 1117 Print_Error(error);
1112 1118
1113 error=GSM_WaitFor (&s, Find2, 10, 0x3E, 4, ID_User3); 1119 error=GSM_WaitFor (&s, Find2, 10, 0x3E, 4, ID_User3);
1114 Print_Error(error); 1120 Print_Error(error);
1115 found = false; 1121 found = false;
1116 for (j=0;j<num;j++) { 1122 for (j=0;j<num;j++) {
1117 if (FMStation[j].Frequency > RadioFreq) { 1123 if (FMStation[j].Frequency > RadioFreq) {
1118 diff = FMStation[j].Frequency - RadioFreq; 1124 diff = FMStation[j].Frequency - RadioFreq;
1119 } else { 1125 } else {
1120 diff = RadioFreq - FMStation[j].Frequency; 1126 diff = RadioFreq - FMStation[j].Frequency;
1121 } 1127 }
1122 if (diff <= 0.2) { 1128 if (diff <= 0.2) {
1123 dbgprintf("diff is %f\n",diff); 1129 dbgprintf("diff is %f\n",diff);
1124 found = true; 1130 found = true;
1125 break; 1131 break;
1126 } 1132 }
1127 } 1133 }
1128 if (!found) { 1134 if (!found) {
1129 dbgprintf("Adding %f, num %i\n",RadioFreq,num); 1135 dbgprintf("Adding %f, num %i\n",RadioFreq,num);
1130 FMStation[num].Frequency = RadioFreq; 1136 FMStation[num].Frequency = RadioFreq;
1131 CopyUnicodeString(FMStation[num].StationName,RadioName); 1137 CopyUnicodeString(FMStation[num].StationName,RadioName);
1132 num++; 1138 num++;
1133 } 1139 }
1134 } 1140 }
1135 fprintf(stderr,"%cSearching: %i percent",13,100); 1141 fprintf(stderr,"%cSearching: %i percent",13,100);
1136 fprintf(stderr,"\n\n"); 1142 fprintf(stderr,"\n\n");
1137 1143
1138 i=0; 1144 i=0;
1139 while(1) { 1145 while(1) {
1140 if (i==num || i==num-1) break; 1146 if (i==num || i==num-1) break;
1141 if (FMStation[i].Frequency > FMStation[i+1].Frequency) { 1147 if (FMStation[i].Frequency > FMStation[i+1].Frequency) {
1142 memcpy(&FMStat,&FMStation[i],sizeof(GSM_FMStation)); 1148 memcpy(&FMStat,&FMStation[i],sizeof(GSM_FMStation));
1143 memcpy(&FMStation[i],&FMStation[i+1],sizeof(GSM_FMStation)); 1149 memcpy(&FMStation[i],&FMStation[i+1],sizeof(GSM_FMStation));
1144 memcpy(&FMStation[i+1],&FMStat,sizeof(GSM_FMStation)); 1150 memcpy(&FMStation[i+1],&FMStat,sizeof(GSM_FMStation));
1145 i = 0; 1151 i = 0;
1146 continue; 1152 continue;
1147 } 1153 }
1148 i++; 1154 i++;
1149 } 1155 }
1150 for (i=0;i<num;i++) { 1156 for (i=0;i<num;i++) {
1151 fprintf(stderr,"%02i.",i+1); 1157 fprintf(stderr,"%02i.",i+1);
1152 if (FMStation[i].Frequency < 100) fprintf(stderr," "); 1158 if (FMStation[i].Frequency < 100) fprintf(stderr," ");
1153 fprintf(stderr,"%.1f MHz - \"%s\" \n", 1159 fprintf(stderr,"%.1f MHz - \"%s\" \n",
1154 FMStation[i].Frequency, 1160 FMStation[i].Frequency,
1155 DecodeUnicodeString(FMStation[i].StationName)); 1161 DecodeUnicodeString(FMStation[i].StationName));
1156 } 1162 }
1157 1163
1158 if (answer_yes2("Do you want to save found stations")) { 1164 if (answer_yes2("Do you want to save found stations")) {
1159 fprintf(stderr,"Deleting old FM stations: "); 1165 fprintf(stderr,"Deleting old FM stations: ");
1160 error=Phone->ClearFMStations(&s); 1166 error=Phone->ClearFMStations(&s);
1161 Print_Error(error); 1167 Print_Error(error);
1162 fprintf(stderr,"Done\n"); 1168 fprintf(stderr,"Done\n");
1163 for (i=0;i<num;i++) { 1169 for (i=0;i<num;i++) {
1164 FMStation[i].Location = i+1; 1170 FMStation[i].Location = i+1;
1165 error=Phone->SetFMStation(&s,&FMStation[i]); 1171 error=Phone->SetFMStation(&s,&FMStation[i]);
1166 Print_Error(error); 1172 Print_Error(error);
1167 fprintf(stderr,"%cWriting: %i percent",13,(i+1)*100/num); 1173 fprintf(stderr,"%cWriting: %i percent",13,(i+1)*100/num);
1168 } 1174 }
1169 fprintf(stderr,"\n"); 1175 fprintf(stderr,"\n");
1170 } 1176 }
1171 1177
1172 error=GSM_WaitFor (&s, Disable, 6, 0x3E, 4, ID_User3); 1178 error=GSM_WaitFor (&s, Disable, 6, 0x3E, 4, ID_User3);
1173 Print_Error(error); 1179 Print_Error(error);
1174 1180
1175 GSM_Terminate(); 1181 GSM_Terminate();
1176} 1182}
1183#endif
1177 1184
1178void DCT4PlaySavedRingtone(int argc, char *argv[]) 1185void DCT4PlaySavedRingtone(int argc, char *argv[])
1179{ 1186{
1180 unsigned char req[] = {N6110_FRAME_HEADER, 1187 unsigned char req[] = {N6110_FRAME_HEADER,
1181 0x01, 1188 0x01,
1182 0x00,0x64,//id 1189 0x00,0x64,//id
1183 0x01, //group 1190 0x01, //group
1184 0x01,0x00,0x00, 1191 0x01,0x00,0x00,
1185 0x0A, //volume 1192 0x0A, //volume
1186 0x00,0x00,0x00,0x00,0x00,0x00,0x00}; 1193 0x00,0x00,0x00,0x00,0x00,0x00,0x00};
1187 GSM_AllRingtonesInfo Info; 1194 GSM_AllRingtonesInfo Info;
1188 1195
1189 GSM_Init(true); 1196 GSM_Init(true);
1190 1197
1191 CheckDCT4(); 1198 CheckDCT4();
1192 1199
1193 s.User.UserReplyFunctions=UserReplyFunctions4; 1200 s.User.UserReplyFunctions=UserReplyFunctions4;
1194 1201
1195 error=Phone->GetRingtonesInfo(&s,&Info); 1202 error=Phone->GetRingtonesInfo(&s,&Info);
1196 Print_Error(error); 1203 Print_Error(error);
1197 1204
1198 if (atoi(argv[2]) > Info.Number-1) { 1205 if (atoi(argv[2]) > Info.Number-1) {
1199 GSM_Terminate(); 1206 GSM_Terminate();
1200 return; 1207 return;
1201 } 1208 }
1202 req[4] = Info.Ringtone[atoi(argv[2])].ID / 256; 1209 req[4] = Info.Ringtone[atoi(argv[2])].ID / 256;
1203 req[5] = Info.Ringtone[atoi(argv[2])].ID % 256; 1210 req[5] = Info.Ringtone[atoi(argv[2])].ID % 256;
1204 req[6] = Info.Ringtone[atoi(argv[2])].Group; 1211 req[6] = Info.Ringtone[atoi(argv[2])].Group;
1205 1212
1206 error=GSM_WaitFor (&s, req, 18, 0x1F, 4, ID_User3); 1213 error=GSM_WaitFor (&s, req, 18, 0x1F, 4, ID_User3);
1207 Print_Error(error); 1214 Print_Error(error);
1208 1215
1209 //for (i=0;i<Info.Number;i++) printmsg("%i. \"%s\"\n",i,DecodeUnicodeConsole(Info.Ringtone[i].Name)); 1216 //for (i=0;i<Info.Number;i++) printmsg("%i. \"%s\"\n",i,DecodeUnicodeConsole(Info.Ringtone[i].Name));
1210 1217
1211 GSM_Terminate(); 1218 GSM_Terminate();
1212} 1219}
1213 1220
1214static GSM_Error DCT4_ReplyMakeCameraShoot(GSM_Protocol_Message msg, GSM_StateMachine *s) 1221static GSM_Error DCT4_ReplyMakeCameraShoot(GSM_Protocol_Message msg, GSM_StateMachine *s)
1215{ 1222{
1216 return ERR_NONE; 1223 return ERR_NONE;
1217} 1224}
1218 1225
1219void DCT4MakeCameraShoot(int argc, char *argv[]) 1226void DCT4MakeCameraShoot(int argc, char *argv[])
1220{ 1227{
1221 unsigned char SetCamera[] = {N6110_FRAME_HEADER, 0x09, 0x01, 0x02}; 1228 unsigned char SetCamera[] = {N6110_FRAME_HEADER, 0x09, 0x01, 0x02};
1222 unsigned char CameraON[] = {N6110_FRAME_HEADER, 0x02, 0x01, 0x00, 0x00, 0x00 , 0x00, 0x00}; 1229 unsigned char CameraON[] = {N6110_FRAME_HEADER, 0x02, 0x01, 0x00, 0x00, 0x00 , 0x00, 0x00};
1223 unsigned char CameraON2[] = {N6110_FRAME_HEADER, 0xF0, 0x02, 0x00}; 1230 unsigned char CameraON2[] = {N6110_FRAME_HEADER, 0xF0, 0x02, 0x00};
1224 unsigned char MakeShot[200] = {N6110_FRAME_HEADER, 0x06, 0x01, 0x06, 1231 unsigned char MakeShot[200] = {N6110_FRAME_HEADER, 0x06, 0x01, 0x06,
1225 0x01, 0x00, 0x00, 0x02, 0x00, 0x04, 0x32, 0x00, 0x01, 1232 0x01, 0x00, 0x00, 0x02, 0x00, 0x04, 0x32, 0x00, 0x01,
1226 0x1D, //length of rest 1233 0x1D, //length of rest
1227 0x00, 0x00, 0x00, 0x01, 1234 0x00, 0x00, 0x00, 0x01,
1228 0x00, 0x02,//master folder id 1235 0x00, 0x02,//master folder id
1229 0x00, 0x14}; //length 1236 0x00, 0x14}; //length
1230 unsigned char CameraOFF[] = {N6110_FRAME_HEADER, 0x04, 0x01, 0x00}; 1237 unsigned char CameraOFF[] = {N6110_FRAME_HEADER, 0x04, 0x01, 0x00};
1231 1238
1232 GSM_Init(true); 1239 GSM_Init(true);
1233 1240
1234 CheckDCT4(); 1241 CheckDCT4();
1235 1242
1236 s.User.UserReplyFunctions=UserReplyFunctions4; 1243 s.User.UserReplyFunctions=UserReplyFunctions4;
1237 1244
1238 error=GSM_WaitFor (&s, SetCamera, 6, 0x61, 4, ID_User3); 1245 error=GSM_WaitFor (&s, SetCamera, 6, 0x61, 4, ID_User3);
1239 Print_Error(error); 1246 Print_Error(error);
1240 error=GSM_WaitFor (&s, CameraON, 10, 0x61, 4, ID_User3); 1247 error=GSM_WaitFor (&s, CameraON, 10, 0x61, 4, ID_User3);
1241 Print_Error(error); 1248 Print_Error(error);
1242 error=GSM_WaitFor (&s, CameraON2, 6, 0x61, 4, ID_User3); 1249 error=GSM_WaitFor (&s, CameraON2, 6, 0x61, 4, ID_User3);
1243 Print_Error(error); 1250 Print_Error(error);
1244 EncodeUnicode(MakeShot+24,"GammuShot",9); 1251 EncodeUnicode(MakeShot+24,"GammuShot",9);
1245 MakeShot[15] = 9+9*2; 1252 MakeShot[15] = 9+9*2;
1246 MakeShot[23] = 9*2; 1253 MakeShot[23] = 9*2;
1247 error=GSM_WaitFor (&s, MakeShot, 24+MakeShot[23], 0x61, 4, ID_User3); 1254 error=GSM_WaitFor (&s, MakeShot, 24+MakeShot[23], 0x61, 4, ID_User3);
1248 Print_Error(error); 1255 Print_Error(error);
1249 error=GSM_WaitFor (&s, SetCamera, 6, 0x61, 4, ID_User3); 1256 error=GSM_WaitFor (&s, SetCamera, 6, 0x61, 4, ID_User3);
1250 Print_Error(error); 1257 Print_Error(error);
1251 error=GSM_WaitFor (&s, CameraOFF, 6, 0x61, 4, ID_User3); 1258 error=GSM_WaitFor (&s, CameraOFF, 6, 0x61, 4, ID_User3);
1252 Print_Error(error); 1259 Print_Error(error);
1253 1260
1254 GSM_Terminate(); 1261 GSM_Terminate();
1255} 1262}
1256 1263
1257int len; 1264int len;
1258 1265
1259static GSM_Error DCT4_ReplyGetScreenDump(GSM_Protocol_Message msg, GSM_StateMachine *s) 1266static GSM_Error DCT4_ReplyGetScreenDump(GSM_Protocol_Message msg, GSM_StateMachine *s)
1260{ 1267{
1261 if (msg.Buffer[7] == 0x0C) len = 1; 1268 if (msg.Buffer[7] == 0x0C) len = 1;
1262 return ERR_NONE; 1269 return ERR_NONE;
1263} 1270}
1264 1271
1265void DCT4GetScreenDump(int argc, char *argv[]) 1272void DCT4GetScreenDump(int argc, char *argv[])
1266{ 1273{
1267 unsigned char req[] = {N6110_FRAME_HEADER, 0x07, 0x01, 0x00}; 1274 unsigned char req[] = {N6110_FRAME_HEADER, 0x07, 0x01, 0x00};
1268 //n6110_frameheader 06//screen info 1275 //n6110_frameheader 06//screen info
1269 1276
1270 GSM_Init(true); 1277 GSM_Init(true);
1271 1278
1272 CheckDCT4(); 1279 CheckDCT4();
1273 1280
1274 s.User.UserReplyFunctions=UserReplyFunctions4; 1281 s.User.UserReplyFunctions=UserReplyFunctions4;
1275 1282
1276 error=GSM_WaitFor (&s, req, 6, 0x0E, 4, ID_User3); 1283 error=GSM_WaitFor (&s, req, 6, 0x0E, 4, ID_User3);
1277 Print_Error(error); 1284 Print_Error(error);
1278 len = 2000; 1285 len = 2000;
1279 while (len >= 200) GSM_ReadDevice(&s,true); 1286 while (len >= 200) GSM_ReadDevice(&s,true);
1280 1287
1281 GSM_Terminate(); 1288 GSM_Terminate();
1282} 1289}
1283 1290
1284static GSM_Reply_Function UserReplyFunctions4[] = { 1291static GSM_Reply_Function UserReplyFunctions4[] = {
1285 1292
1286#ifdef DEBUG 1293#ifdef DEBUG
1287 {DCT4_ReplyResetSecurityCode, "\x08",0x03,0x05,ID_User2}, 1294 {DCT4_ReplyResetSecurityCode, "\x08",0x03,0x05,ID_User2},
1288 {DCT4_ReplyResetSecurityCode, "\x08",0x03,0x06,ID_User2}, 1295 {DCT4_ReplyResetSecurityCode, "\x08",0x03,0x06,ID_User2},
1289#endif 1296#endif
1290 1297
1291 {DCT4_ReplyGetScreenDump, "\x0E",0x00,0x00,ID_User3}, 1298 {DCT4_ReplyGetScreenDump, "\x0E",0x00,0x00,ID_User3},
1292 {DCT4_ReplyGetScreenDump,"\x0E",0x00,0x00,ID_IncomingFrame}, 1299 {DCT4_ReplyGetScreenDump,"\x0E",0x00,0x00,ID_IncomingFrame},
1293 1300
1294 {DCT4_ReplyGetADC, "\x17",0x03,0x10,ID_User3}, 1301 {DCT4_ReplyGetADC, "\x17",0x03,0x10,ID_User3},
1295 {DCT4_ReplyGetADC, "\x17",0x03,0x12,ID_User3}, 1302 {DCT4_ReplyGetADC, "\x17",0x03,0x12,ID_User3},
1296 1303
1297 {DCT4_ReplySetPPS, "\x1b",0x03,0x05,ID_User1}, 1304 {DCT4_ReplySetPPS, "\x1b",0x03,0x05,ID_User1},
1298 {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x08,ID_User6}, 1305 {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x08,ID_User6},
1299 1306
1300 {DCT4_ReplyVibra, "\x1C",0x03,0x0D,ID_User3}, 1307 {DCT4_ReplyVibra, "\x1C",0x03,0x0D,ID_User3},
1301 {DCT4_ReplyVibra, "\x1C",0x03,0x0F,ID_User3}, 1308 {DCT4_ReplyVibra, "\x1C",0x03,0x0F,ID_User3},
1302 1309
1303 {NoneReply, "\x1F",0x03,0x02,ID_User3}, 1310 {NoneReply, "\x1F",0x03,0x02,ID_User3},
1304 1311
1305 {DCT4_ReplyGetSecurityCode, "\x23",0x03,0x05,ID_User1}, 1312 {DCT4_ReplyGetSecurityCode, "\x23",0x03,0x05,ID_User1},
1306 {DCT4_ReplyGetT9, "\x23",0x03,0x05,ID_User3}, 1313 {DCT4_ReplyGetT9, "\x23",0x03,0x05,ID_User3},
1307 {DCT4_ReplyGetVoiceRecord, "\x23",0x03,0x05,ID_User4}, 1314 {DCT4_ReplyGetVoiceRecord, "\x23",0x03,0x05,ID_User4},
1308 {DCT4_ReplyGetVoiceRecord, "\x23",0x03,0x0D,ID_User4}, 1315 {DCT4_ReplyGetVoiceRecord, "\x23",0x03,0x0D,ID_User4},
1309 {DCT4_ReplyGetSecurityCode, "\x23",0x03,0x0D,ID_User1}, 1316 {DCT4_ReplyGetSecurityCode, "\x23",0x03,0x0D,ID_User1},
1310 1317
1311 {DCT4_ReplyTestsStartup, "\x35",0x02,0x01,ID_User3}, 1318 {DCT4_ReplyTestsStartup, "\x35",0x02,0x01,ID_User3},
1312 {DCT4_ReplyTestsStartup, "\x35",0x02,0x02,ID_User3}, 1319 {DCT4_ReplyTestsStartup, "\x35",0x02,0x02,ID_User3},
1313 {DCT4_ReplyTestsNames, "\x35",0x02,0x03,ID_User1}, 1320 {DCT4_ReplyTestsNames, "\x35",0x02,0x03,ID_User1},
1314 {DCT4_ReplyTestsStatus, "\x35",0x02,0x04,ID_User2}, 1321 {DCT4_ReplyTestsStatus, "\x35",0x02,0x04,ID_User2},
1315 1322
1323#ifdef GSM_ENABLE_NOKIA6510
1316 {DCT4_ReplyTuneRadio, "\x3E",0x03,0x09,ID_User3}, 1324 {DCT4_ReplyTuneRadio, "\x3E",0x03,0x09,ID_User3},
1317 {DCT4_ReplyTuneRadio, "\x3E",0x03,0x15,ID_User3}, 1325 {DCT4_ReplyTuneRadio, "\x3E",0x03,0x15,ID_User3},
1318 {DCT4_ReplyTuneRadio, "\x3E",0x03,0x15,ID_SetFMStation}, 1326 {DCT4_ReplyTuneRadio, "\x3E",0x03,0x15,ID_SetFMStation},
1319 {DCT4_ReplyTuneRadio, "\x3E",0x03,0x16,ID_User3}, 1327 {DCT4_ReplyTuneRadio, "\x3E",0x03,0x16,ID_User3},
1328#endif
1320 1329
1321 {DCT4_ReplyGetVoiceRecord, "\x4A",0x03,0x31,ID_User4}, 1330 {DCT4_ReplyGetVoiceRecord, "\x4A",0x03,0x31,ID_User4},
1322 1331
1323 {DCT4_ReplyGetSimlock, "\x53",0x03,0x0D,ID_User6}, 1332 {DCT4_ReplyGetSimlock, "\x53",0x03,0x0D,ID_User6},
1324 {DCT4_ReplyGetSimlock, "\x53",0x03,0x13,ID_User6}, 1333 {DCT4_ReplyGetSimlock, "\x53",0x03,0x13,ID_User6},
1325 1334
1326 {DCT4_ReplyMakeCameraShoot, "\x61",0x03,0x03,ID_User3}, 1335 {DCT4_ReplyMakeCameraShoot, "\x61",0x03,0x03,ID_User3},
1327 {DCT4_ReplyMakeCameraShoot, "\x61",0x03,0x07,ID_User3}, 1336 {DCT4_ReplyMakeCameraShoot, "\x61",0x03,0x07,ID_User3},
1328 {DCT4_ReplyMakeCameraShoot, "\x61",0x03,0x08,ID_User3}, 1337 {DCT4_ReplyMakeCameraShoot, "\x61",0x03,0x08,ID_User3},
1329 {DCT4_ReplyMakeCameraShoot, "\x61",0x03,0x0A,ID_User3}, 1338 {DCT4_ReplyMakeCameraShoot, "\x61",0x03,0x0A,ID_User3},
1330 {DCT4_ReplyMakeCameraShoot, "\x61",0x03,0xF0,ID_User3}, 1339 {DCT4_ReplyMakeCameraShoot, "\x61",0x03,0xF0,ID_User3},
1331 1340
1332 {DCT4_ReplyGetBTInfo, "\xD7",0x03,0x0A,ID_User6}, 1341 {DCT4_ReplyGetBTInfo, "\xD7",0x03,0x0A,ID_User6},
1333 1342
1334 {NULL, "\x00",0x00,0x00,ID_None} 1343 {NULL, "\x00",0x00,0x00,ID_None}
1335}; 1344};
1336 1345
1337#endif 1346#endif
1338 1347
1339/* How should editor hadle tabs in this file? Add editor commands here. 1348/* How should editor hadle tabs in this file? Add editor commands here.
1340 * vim: noexpandtab sw=8 ts=8 sts=8: 1349 * vim: noexpandtab sw=8 ts=8 sts=8:
1341 */ 1350 */
diff --git a/gammu/emb/gammu/depend/nokia/dct4.h b/gammu/emb/gammu/depend/nokia/dct4.h
index fde5b08..fae809f 100644
--- a/gammu/emb/gammu/depend/nokia/dct4.h
+++ b/gammu/emb/gammu/depend/nokia/dct4.h
@@ -1,95 +1,98 @@
1/* (c) 2002-2004 by Marcin Wiacek */ 1/* (c) 2002-2004 by Marcin Wiacek */
2 2
3#include "../../../common/gsmstate.h" 3#include "../../../common/gsmstate.h"
4 4
5 void DCT4SetPhoneMenus (int argc, char *argv[]); 5 void DCT4SetPhoneMenus (int argc, char *argv[]);
6 void DCT4SelfTests (int argc, char *argv[]); 6 void DCT4SelfTests (int argc, char *argv[]);
7 void DCT4SetVibraLevel (int argc, char *argv[]); 7 void DCT4SetVibraLevel (int argc, char *argv[]);
8void DCT4GetSecurityCode (int argc, char *argv[]); 8void DCT4GetSecurityCode (int argc, char *argv[]);
9#ifdef DEBUG
10void DCT4ResetSecurityCode (int argc, char *argv[]);
11#endif
12 void DCT4GetVoiceRecord (int argc, char *argv[]); 9 void DCT4GetVoiceRecord (int argc, char *argv[]);
13 void DCT4Info (int argc, char *argv[]); 10 void DCT4Info (int argc, char *argv[]);
14 void DCT4GetT9 (int argc, char *argv[]); 11 void DCT4GetT9 (int argc, char *argv[]);
15 void DCT4SetLight (int argc, char *argv[]);
16 void DCT4DisplayTest (int argc, char *argv[]); 12 void DCT4DisplayTest (int argc, char *argv[]);
17 void DCT4GetADC (int argc, char *argv[]); 13 void DCT4GetADC (int argc, char *argv[]);
18 void DCT4VibraTest (int argc, char *argv[]); 14 void DCT4VibraTest (int argc, char *argv[]);
19 void DCT4TuneRadio (int argc, char *argv[]);
20void DCT4PlaySavedRingtone (int argc, char *argv[]); 15void DCT4PlaySavedRingtone (int argc, char *argv[]);
21void DCT4MakeCameraShoot (int argc, char *argv[]); 16void DCT4MakeCameraShoot (int argc, char *argv[]);
22 void DCT4GetScreenDump (int argc, char *argv[]); 17 void DCT4GetScreenDump (int argc, char *argv[]);
23 18
19#ifdef DEBUG
20 void DCT4ResetSecurityCode (int argc, char *argv[]);
21#endif
22#ifdef GSM_ENABLE_NOKIA6510
23 void DCT4SetLight (int argc, char *argv[]);
24 void DCT4TuneRadio (int argc, char *argv[]);
25#endif
26
24/* ------------------- features matrix ------------------------------------- */ 27/* ------------------- features matrix ------------------------------------- */
25 28
26typedef enum { 29typedef enum {
27 DCT4_ALWAYS_ONLINE = 1, 30 DCT4_ALWAYS_ONLINE = 1,
28 DCT4_GPRS_PCCH, 31 DCT4_GPRS_PCCH,
29 DCT4_GEA1, 32 DCT4_GEA1,
30 DCT4_EOTD, 33 DCT4_EOTD,
31 DCT4_WAP_PUSH, 34 DCT4_WAP_PUSH,
32 DCT4_USE_PREF_SIM_NET, 35 DCT4_USE_PREF_SIM_NET,
33 DCT4_JAVA_TCK, 36 DCT4_JAVA_TCK,
34 37
35 DCT4_ALS, 38 DCT4_ALS,
36 DCT4_A52, 39 DCT4_A52,
37 DCT4_CSP, 40 DCT4_CSP,
38 DCT4_EONS, 41 DCT4_EONS,
39 DCT4_3GINDICATOR, 42 DCT4_3GINDICATOR,
40 DCT4_DISPLAY_PHONE_NAME, 43 DCT4_DISPLAY_PHONE_NAME,
41 DCT4_DISPLAY_WAP_PROFILE, 44 DCT4_DISPLAY_WAP_PROFILE,
42 45
43 DCT4_GAMES_WAP_DOWNLOAD, 46 DCT4_GAMES_WAP_DOWNLOAD,
44 DCT4_GAMES_SCORE_SEND, 47 DCT4_GAMES_SCORE_SEND,
45 DCT4_GAMES_URL_CHECK, 48 DCT4_GAMES_URL_CHECK,
46 49
47 DCT4_BLUETOOTH_MENU, 50 DCT4_BLUETOOTH_MENU,
48 DCT4_WAP_BOOKMARKS_MENU, 51 DCT4_WAP_BOOKMARKS_MENU,
49 DCT4_WAP_BOOKMARKS_MENU2, 52 DCT4_WAP_BOOKMARKS_MENU2,
50 DCT4_WAP_GOTO_MENU, 53 DCT4_WAP_GOTO_MENU,
51 DCT4_WAP_SETTINGS_MENU, 54 DCT4_WAP_SETTINGS_MENU,
52 DCT4_SERVICES_GAMES_APP_GALLERY, 55 DCT4_SERVICES_GAMES_APP_GALLERY,
53 DCT4_JAVA_GAMES_MENU, 56 DCT4_JAVA_GAMES_MENU,
54 DCT4_SAT_CONFIRM_MENU, 57 DCT4_SAT_CONFIRM_MENU,
55 DCT4_INSTANT_MESS_MENU, 58 DCT4_INSTANT_MESS_MENU,
56 DCT4_CONFIRM_ALS, 59 DCT4_CONFIRM_ALS,
57 DCT4_BOOKMARK_GOTO_MENU, 60 DCT4_BOOKMARK_GOTO_MENU,
58 61
59 DCT4_5100_IDENTIFY, 62 DCT4_5100_IDENTIFY,
60 63
61 DCT4_TEST 64 DCT4_TEST
62} DCT4_Feature_Name; 65} DCT4_Feature_Name;
63 66
64typedef struct { 67typedef struct {
65 DCT4_Feature_Name Name; 68 DCT4_Feature_Name Name;
66 unsigned char *Text; 69 unsigned char *Text;
67 struct { 70 struct {
68 unsigned char Value; 71 unsigned char Value;
69 unsigned char *Text; 72 unsigned char *Text;
70 } Values[10]; 73 } Values[10];
71} DCT4_Feature; 74} DCT4_Feature;
72 75
73typedef struct { 76typedef struct {
74 char *Model; 77 char *Model;
75 struct { 78 struct {
76 DCT4_Feature_NameName; 79 DCT4_Feature_NameName;
77 int Number; 80 int Number;
78 } Features[25]; 81 } Features[25];
79} DCT4_Phone_Features; 82} DCT4_Phone_Features;
80 83
81typedef struct { 84typedef struct {
82 struct { 85 struct {
83 char Name[100]; 86 char Name[100];
84 unsigned char ID; 87 unsigned char ID;
85 unsigned char Value; 88 unsigned char Value;
86 bool Startup; 89 bool Startup;
87 } Tests[50]; 90 } Tests[50];
88 int Num; 91 int Num;
89} DCT4_Phone_Tests; 92} DCT4_Phone_Tests;
90 93
91/* ------------------------------------------------------------------------- */ 94/* ------------------------------------------------------------------------- */
92 95
93/* How should editor hadle tabs in this file? Add editor commands here. 96/* How should editor hadle tabs in this file? Add editor commands here.
94 * vim: noexpandtab sw=8 ts=8 sts=8: 97 * vim: noexpandtab sw=8 ts=8 sts=8:
95 */ 98 */
diff --git a/gammu/emb/gammu/gammu.c b/gammu/emb/gammu/gammu.c
index 997485a..f49ae36 100644
--- a/gammu/emb/gammu/gammu.c
+++ b/gammu/emb/gammu/gammu.c
@@ -1,1774 +1,1804 @@
1/* (c) 2002-2004 by Marcin Wiacek and Michal Cihar */ 1/* (c) 2002-2004 by Marcin Wiacek and Michal Cihar */
2/* FM stuff by Walek */ 2/* FM stuff by Walek */
3 3
4#include <string.h> 4#include <string.h>
5#include <stdio.h> 5#include <stdio.h>
6#include <stdlib.h> 6#include <stdlib.h>
7#include <stdarg.h> 7#include <stdarg.h>
8#include <locale.h> 8#include <locale.h>
9#include <signal.h> 9#include <signal.h>
10#include <ctype.h> 10#include <ctype.h>
11#include <wchar.h> 11#include <wchar.h>
12#undef HAVE_MYSQL_MYSQL_H
13#ifdef WIN32 12#ifdef WIN32
14# include <windows.h> 13# include <windows.h>
15# include <process.h> 14# include <process.h>
16# ifdef _MSC_VER 15# ifdef _MSC_VER
17# include <sys/utime.h> 16# include <sys/utime.h>
18# else 17# else
19# include <utime.h> 18# include <utime.h>
20# endif 19# endif
21#else 20#else
22# include <utime.h> 21# include <utime.h>
23#endif 22#endif
24 23
25#include "../common/gammu.h" 24#include "../common/gammu.h"
26#include "gammu.h" 25#include "gammu.h"
27#include "smsd/smsdcore.h" 26#include "smsd/smsdcore.h"
28#ifdef DEBUG 27#ifdef DEBUG
29# include "sniff.h" 28# include "sniff.h"
30#endif 29#endif
31#ifdef GSM_ENABLE_NOKIA_DCT3 30#ifdef GSM_ENABLE_NOKIA_DCT3
32# include "depend/nokia/dct3.h" 31# include "depend/nokia/dct3.h"
33# include "depend/nokia/dct3trac/wmx.h" 32# include "depend/nokia/dct3trac/wmx.h"
34#endif 33#endif
35#ifdef GSM_ENABLE_NOKIA_DCT4 34#ifdef GSM_ENABLE_NOKIA_DCT4
36# include "depend/nokia/dct4.h" 35# include "depend/nokia/dct4.h"
37#endif 36#endif
38#ifdef GSM_ENABLE_ATGEN 37#ifdef GSM_ENABLE_ATGEN
39# include "depend/siemens/dsiemens.h" 38# include "depend/siemens/dsiemens.h"
40#endif 39#endif
41 40
42#ifdef HAVE_PTHREAD 41#ifdef HAVE_PTHREAD
43# include <pthread.h> 42# include <pthread.h>
44#endif 43#endif
45 44
46#ifdef HAVE_SYS_IOCTL_H 45#ifdef HAVE_SYS_IOCTL_H
47# include <sys/ioctl.h> 46# include <sys/ioctl.h>
48#endif 47#endif
49 48
50 49
51 //static GSM_StateMachine s; 50 GSM_StateMachine s;
52 //static GSM_Phone_Functions *Phone; 51 GSM_Phone_Functions *Phone;
53 static INI_Section *cfg = NULL; 52 static INI_Section *cfg = NULL;
54 53
55 //static GSM_Error error = ERR_NONE; 54 GSM_Error error = ERR_NONE;
56 static int i; 55 static int i;
57 56
58 //static bool gshutdown = false; 57 volatile bool gshutdown = false;
59typedef struct {
60 unsigned char Connection[50];
61} OneConnectionInfo;
62 58
63typedef struct {
64 unsigned char Device[50];
65 OneConnectionInfo Connections[6];
66 //GSM_StateMachines;
67} OneDeviceInfo;
68
69 static int num;
70 static OneDeviceInfo SearchDevices[100];
71 static bool SearchOutput;
72void interrupt(int sign) 59void interrupt(int sign)
73{ 60{
74 signal(sign, SIG_IGN); 61 signal(sign, SIG_IGN);
75 gshutdown = true; 62 gshutdown = true;
76} 63}
77 64
78#ifdef __GNUC__ 65#ifdef __GNUC__
79__attribute__((format(printf, 1, 2))) 66__attribute__((format(printf, 1, 2)))
80#endif 67#endif
81int printmsg(char *format, ...) 68int printmsg(char *format, ...)
82{ 69{
83 va_list argp; 70 va_list argp;
84 int result; 71 int result;
85 72
86 va_start(argp, format); 73 va_start(argp, format);
87 result = vfprintf(stdout,GetMsg(s.msg,format),argp); 74 result = vfprintf(stdout,GetMsg(s.msg,format),argp);
88 va_end(argp); 75 va_end(argp);
89 return result; 76 return result;
90} 77}
91 78
92#ifdef __GNUC__ 79#ifdef __GNUC__
93__attribute__((format(printf, 1, 2))) 80__attribute__((format(printf, 1, 2)))
94#endif 81#endif
95int printmsgerr(char *format, ...) 82int printmsgerr(char *format, ...)
96{ 83{
97 va_list argp; 84 va_list argp;
98 int result; 85 int result;
99 86
100 va_start(argp, format); 87 va_start(argp, format);
101 result = vfprintf(stderr,GetMsg(s.msg,format), argp); 88 result = vfprintf(stderr,GetMsg(s.msg,format), argp);
102 va_end(argp); 89 va_end(argp);
103 return result; 90 return result;
104} 91}
105 92
106static void PrintSecurityStatus() 93static void PrintSecurityStatus()
107{ 94{
108 GSM_SecurityCodeType Status; 95 GSM_SecurityCodeType Status;
109 96
110 error=Phone->GetSecurityStatus(&s,&Status); 97 error=Phone->GetSecurityStatus(&s,&Status);
111 Print_Error(error); 98 Print_Error(error);
112 switch(Status) { 99 switch(Status) {
113 case SEC_SecurityCode: 100 case SEC_SecurityCode:
114 printmsg("Waiting for Security Code.\n"); 101 printmsg("Waiting for Security Code.\n");
115 break; 102 break;
116 case SEC_Pin: 103 case SEC_Pin:
117 printmsg("Waiting for PIN.\n"); 104 printmsg("Waiting for PIN.\n");
118 break; 105 break;
119 case SEC_Pin2: 106 case SEC_Pin2:
120 printmsg("Waiting for PIN2.\n"); 107 printmsg("Waiting for PIN2.\n");
121 break; 108 break;
122 case SEC_Puk: 109 case SEC_Puk:
123 printmsg("Waiting for PUK.\n"); 110 printmsg("Waiting for PUK.\n");
124 break; 111 break;
125 case SEC_Puk2: 112 case SEC_Puk2:
126 printmsg("Waiting for PUK2.\n"); 113 printmsg("Waiting for PUK2.\n");
127 break; 114 break;
128 case SEC_None: 115 case SEC_None:
129 printmsg("Nothing to enter.\n"); 116 printmsg("Nothing to enter.\n");
130 break; 117 break;
131 default: 118 default:
132 printmsg("Unknown\n"); 119 printmsg("Unknown\n");
133 } 120 }
134} 121}
135 122
136void Print_Error(GSM_Error error) 123void Print_Error(GSM_Error error)
137{ 124{
138 if (error != ERR_NONE) { 125 if (error != ERR_NONE) {
139 printf("%s\n",print_error(error,s.di.df,s.msg)); 126 printf("%s\n",print_error(error,s.di.df,s.msg));
140 if (error == ERR_SECURITYERROR) { 127 if (error == ERR_SECURITYERROR) {
141 printmsg("Security status: "); 128 printmsg("Security status: ");
142 PrintSecurityStatus(); 129 PrintSecurityStatus();
143 } 130 }
144 if (s.opened) GSM_TerminateConnection(&s); 131 if (s.opened) GSM_TerminateConnection(&s);
145 exit (-1); 132 exit (-1);
146 } 133 }
147} 134}
148 135
149void GSM_Init(bool checkerror) 136void GSM_Init(bool checkerror)
150{ 137{
151 error=GSM_InitConnection(&s,3); 138 error=GSM_InitConnection(&s,3);
152 if (checkerror) Print_Error(error); 139 if (checkerror) Print_Error(error);
153 140
154 Phone=s.Phone.Functions; 141 Phone=s.Phone.Functions;
155} 142}
156 143
157void GSM_Terminate(void) 144void GSM_Terminate(void)
158{ 145{
159 error=GSM_TerminateConnection(&s); 146 error=GSM_TerminateConnection(&s);
160 Print_Error(error); 147 Print_Error(error);
161} 148}
162 149
163static void GetStartStop(int *start, int *stop, int num, int argc, char *argv[]) 150static void GetStartStop(int *start, int *stop, int num, int argc, char *argv[])
164{ 151{
165 *start=atoi(argv[num]); 152 *start=atoi(argv[num]);
166 if (*start==0) { 153 if (*start==0) {
167 printmsg("ERROR: enumerate locations from 1\n"); 154 printmsg("ERROR: enumerate locations from 1\n");
168 exit (-1); 155 exit (-1);
169 } 156 }
170 157
171 if (stop!=NULL) { 158 if (stop!=NULL) {
172 *stop=*start; 159 *stop=*start;
173 if (argc>=num+2) *stop=atoi(argv[num+1]); 160 if (argc>=num+2) *stop=atoi(argv[num+1]);
174 if (*stop==0) { 161 if (*stop==0) {
175 printmsg("ERROR: enumerate locations from 1\n"); 162 printmsg("ERROR: enumerate locations from 1\n");
176 exit (-1); 163 exit (-1);
177 } 164 }
178 } 165 }
179} 166}
180 167
181bool always_answer_yes = false; 168bool always_answer_yes = false;
182bool always_answer_no = false; 169bool always_answer_no = false;
183 170
184static bool answer_yes(char *text) 171static bool answer_yes(char *text)
185{ 172{
186 int len; 173 int len;
187 char ans[99]; 174 char ans[99];
188 175
189 while (1) { 176 while (1) {
190 printmsgerr("%s (yes/no/ALL/ONLY/NONE) ? ",text); 177 printmsgerr("%s (yes/no/ALL/ONLY/NONE) ? ",text);
191 if (always_answer_yes) { 178 if (always_answer_yes) {
192 printmsgerr("YES (always)\n"); 179 printmsgerr("YES (always)\n");
193 return true; 180 return true;
194 } 181 }
195 if (always_answer_no) { 182 if (always_answer_no) {
196 printmsgerr("NO (always)\n"); 183 printmsgerr("NO (always)\n");
197 return false; 184 return false;
198 } 185 }
199 len=GetLine(stdin, ans, 99); 186 len=GetLine(stdin, ans, 99);
200 if (len==-1) exit(-1); 187 if (len==-1) exit(-1);
201 if (!strcmp(ans, "NONE")) { 188 if (!strcmp(ans, "NONE")) {
202 always_answer_no = true; 189 always_answer_no = true;
203 return false; 190 return false;
204 } 191 }
205 if (!strcmp(ans, "ONLY")) { 192 if (!strcmp(ans, "ONLY")) {
206 always_answer_no = true; 193 always_answer_no = true;
207 return true; 194 return true;
208 } 195 }
209 if (!strcmp(ans, "ALL")) { 196 if (!strcmp(ans, "ALL")) {
210 always_answer_yes = true; 197 always_answer_yes = true;
211 return true; 198 return true;
212 } 199 }
213 if (mystrncasecmp(ans, "yes",0)) return true; 200 if (mystrncasecmp(ans, "yes",0)) return true;
214 if (mystrncasecmp(ans, "no" ,0)) return false; 201 if (mystrncasecmp(ans, "no" ,0)) return false;
215 } 202 }
216} 203}
217 204
218#ifdef GSM_ENABLE_BEEP 205#ifdef GSM_ENABLE_BEEP
219void GSM_PhoneBeep(void) 206void GSM_PhoneBeep(void)
220{ 207{
221 error = PHONE_Beep(&s); 208 error = PHONE_Beep(&s);
222 if (error != ERR_NOTSUPPORTED && error != ERR_NOTIMPLEMENTED) Print_Error(error); 209 if (error != ERR_NOTSUPPORTED && error != ERR_NOTIMPLEMENTED) Print_Error(error);
223} 210}
224#endif 211#endif
225 212
226static GSM_Error GSM_PlayRingtone(GSM_Ringtone ringtone) 213static GSM_Error GSM_PlayRingtone(GSM_Ringtone ringtone)
227{ 214{
228 int i; 215 int i;
229 bool first=true; 216 bool first=true;
230 GSM_Error error; 217 GSM_Error error;
231 218
232 signal(SIGINT, interrupt); 219 signal(SIGINT, interrupt);
233 printmsg("Press Ctrl+C to break...\n"); 220 printmsg("Press Ctrl+C to break...\n");
234 221
235 for (i=0;i<ringtone.NoteTone.NrCommands;i++) { 222 for (i=0;i<ringtone.NoteTone.NrCommands;i++) {
236 if (gshutdown) break; 223 if (gshutdown) break;
237 if (ringtone.NoteTone.Commands[i].Type != RING_NOTETONE) continue; 224 if (ringtone.NoteTone.Commands[i].Type != RING_NOTETONE) continue;
238 error=PHONE_RTTLPlayOneNote(&s,ringtone.NoteTone.Commands[i].Note,first); 225 error=PHONE_RTTLPlayOneNote(&s,ringtone.NoteTone.Commands[i].Note,first);
239 if (error!=ERR_NONE) return error; 226 if (error!=ERR_NONE) return error;
240 first = false; 227 first = false;
241 } 228 }
242 229
243 /* Disables buzzer */ 230 /* Disables buzzer */
244 return s.Phone.Functions->PlayTone(&s,255*255,0,false); 231 return s.Phone.Functions->PlayTone(&s,255*255,0,false);
245} 232}
233
246static void PlayRingtone(int argc, char *argv[]) 234static void PlayRingtone(int argc, char *argv[])
247{ 235{
248 GSM_Ringtone ringtone,ringtone2; 236 GSM_Ringtone ringtone,ringtone2;
249 237
250 ringtone.Format= 0; 238 ringtone.Format= 0;
251 error=GSM_ReadRingtoneFile(argv[2],&ringtone); 239 error=GSM_ReadRingtoneFile(argv[2],&ringtone);
252 Print_Error(error); 240 Print_Error(error);
253 241
254 error=GSM_RingtoneConvert(&ringtone2,&ringtone,RING_NOTETONE); 242 error=GSM_RingtoneConvert(&ringtone2,&ringtone,RING_NOTETONE);
255 Print_Error(error); 243 Print_Error(error);
256 244
257 GSM_Init(true); 245 GSM_Init(true);
258 246
259 error=GSM_PlayRingtone(ringtone2); 247 error=GSM_PlayRingtone(ringtone2);
260 Print_Error(error); 248 Print_Error(error);
261 249
262 GSM_Terminate(); 250 GSM_Terminate();
263} 251}
264 252
265static void Identify(int argc, char *argv[]) 253static void Identify(int argc, char *argv[])
266{ 254{
267 unsigned char buffer[100]; 255 unsigned char buffer[100];
268 256
269 GSM_Init(true); 257 GSM_Init(true);
270 258
271 error=Phone->GetManufacturer(&s); 259 error=Phone->GetManufacturer(&s);
272 Print_Error(error); 260 Print_Error(error);
273 printmsg("Manufacturer : %s\n", s.Phone.Data.Manufacturer); 261 printmsg("Manufacturer : %s\n", s.Phone.Data.Manufacturer);
274 error=Phone->GetModel(&s); 262 error=Phone->GetModel(&s);
275 Print_Error(error); 263 Print_Error(error);
276 printmsg("Model : %s (%s)\n", 264 printmsg("Model : %s (%s)\n",
277 s.Phone.Data.ModelInfo->model, 265 s.Phone.Data.ModelInfo->model,
278 s.Phone.Data.Model); 266 s.Phone.Data.Model);
279 267
280 error=Phone->GetFirmware(&s); 268 error=Phone->GetFirmware(&s);
281 Print_Error(error); 269 Print_Error(error);
282 printmsg("Firmware : %s",s.Phone.Data.Version); 270 printmsg("Firmware : %s",s.Phone.Data.Version);
283 error=Phone->GetPPM(&s, buffer); 271 error=Phone->GetPPM(&s, buffer);
284 if (error != ERR_NOTSUPPORTED) { 272 if (error != ERR_NOTSUPPORTED) {
285 if (error != ERR_NOTIMPLEMENTED) Print_Error(error); 273 if (error != ERR_NOTIMPLEMENTED) Print_Error(error);
286 if (error == ERR_NONE) printmsg(" %s",buffer); 274 if (error == ERR_NONE) printmsg(" %s",buffer);
287 } 275 }
288 if (s.Phone.Data.VerDate[0]!=0) printmsg(" (%s)",s.Phone.Data.VerDate); 276 if (s.Phone.Data.VerDate[0]!=0) printmsg(" (%s)",s.Phone.Data.VerDate);
289 printf("\n"); 277 printf("\n");
290 278
291 error=Phone->GetHardware(&s, buffer); 279 error=Phone->GetHardware(&s, buffer);
292 if (error != ERR_NOTSUPPORTED) { 280 if (error != ERR_NOTSUPPORTED) {
293 if (error != ERR_NOTIMPLEMENTED) Print_Error(error); 281 if (error != ERR_NOTIMPLEMENTED) Print_Error(error);
294 if (error == ERR_NONE) printmsg("Hardware : %s\n",buffer); 282 if (error == ERR_NONE) printmsg("Hardware : %s\n",buffer);
295 } 283 }
296 284
297 error=Phone->GetIMEI(&s); 285 error=Phone->GetIMEI(&s);
298 if (error != ERR_NOTSUPPORTED) { 286 if (error != ERR_NOTSUPPORTED) {
299 if (error != ERR_NOTIMPLEMENTED) Print_Error(error); 287 if (error != ERR_NOTIMPLEMENTED) Print_Error(error);
300 if (error == ERR_NONE) printmsg("IMEI : %s\n",s.Phone.Data.IMEI); 288 if (error == ERR_NONE) printmsg("IMEI : %s\n",s.Phone.Data.IMEI);
301 289
302 error=Phone->GetOriginalIMEI(&s, buffer); 290 error=Phone->GetOriginalIMEI(&s, buffer);
303 if (error != ERR_NOTSUPPORTED && error != ERR_SECURITYERROR) { 291 if (error != ERR_NOTSUPPORTED && error != ERR_SECURITYERROR) {
304 if (error != ERR_NOTIMPLEMENTED) Print_Error(error); 292 if (error != ERR_NOTIMPLEMENTED) Print_Error(error);
305 if (error == ERR_NONE) printmsg("Original IMEI : %s\n",buffer); 293 if (error == ERR_NONE) printmsg("Original IMEI : %s\n",buffer);
306 } 294 }
307 } 295 }
308 296
309 error=Phone->GetManufactureMonth(&s, buffer); 297 error=Phone->GetManufactureMonth(&s, buffer);
310 if (error != ERR_NOTSUPPORTED && error != ERR_SECURITYERROR) { 298 if (error != ERR_NOTSUPPORTED && error != ERR_SECURITYERROR) {
311 if (error != ERR_NOTIMPLEMENTED) Print_Error(error); 299 if (error != ERR_NOTIMPLEMENTED) Print_Error(error);
312 if (error == ERR_NONE) printmsg("Manufactured : %s\n",buffer); 300 if (error == ERR_NONE) printmsg("Manufactured : %s\n",buffer);
313 } 301 }
314 302
315 error=Phone->GetProductCode(&s, buffer); 303 error=Phone->GetProductCode(&s, buffer);
316 if (error != ERR_NOTSUPPORTED) { 304 if (error != ERR_NOTSUPPORTED) {
317 if (error != ERR_NOTIMPLEMENTED) Print_Error(error); 305 if (error != ERR_NOTIMPLEMENTED) Print_Error(error);
318 if (error == ERR_NONE) printmsg("Product code : %s\n",buffer); 306 if (error == ERR_NONE) printmsg("Product code : %s\n",buffer);
319 } 307 }
320 308
321 error=Phone->GetSIMIMSI(&s, buffer); 309 error=Phone->GetSIMIMSI(&s, buffer);
322 switch (error) { 310 switch (error) {
323 case ERR_SECURITYERROR: 311 case ERR_SECURITYERROR:
324 case ERR_NOTSUPPORTED: 312 case ERR_NOTSUPPORTED:
325 case ERR_NOTIMPLEMENTED: 313 case ERR_NOTIMPLEMENTED:
326 break; 314 break;
327 case ERR_NONE: 315 case ERR_NONE:
328 printmsg("SIM IMSI : %s\n",buffer); 316 printmsg("SIM IMSI : %s\n",buffer);
329 break; 317 break;
330 default: 318 default:
331 Print_Error(error); 319 Print_Error(error);
332 } 320 }
333 321
334#ifdef GSM_ENABLE_NOKIA_DCT3 322#ifdef GSM_ENABLE_NOKIA_DCT3
335 DCT3Info(argc, argv); 323 DCT3Info(argc, argv);
336#endif 324#endif
337#ifdef GSM_ENABLE_NOKIA_DCT4 325#ifdef GSM_ENABLE_NOKIA_DCT4
338 DCT4Info(argc, argv); 326 DCT4Info(argc, argv);
339#endif 327#endif
340 328
341 GSM_Terminate(); 329 GSM_Terminate();
342} 330}
343 331
344//#if 0
345static void GetDateTime(int argc, char *argv[]) 332static void GetDateTime(int argc, char *argv[])
346{ 333{
347 GSM_DateTime date_time; 334 GSM_DateTime date_time;
348 GSM_Localelocale; 335 GSM_Localelocale;
349 336
350 GSM_Init(true); 337 GSM_Init(true);
351 338
352 error=Phone->GetDateTime(&s, &date_time); 339 error=Phone->GetDateTime(&s, &date_time);
353 switch (error) { 340 switch (error) {
354 case ERR_EMPTY: 341 case ERR_EMPTY:
355 printmsg("Date and time not set in phone\n"); 342 printmsg("Date and time not set in phone\n");
356 break; 343 break;
357 case ERR_NONE: 344 case ERR_NONE:
358 printmsg("Phone time is %s\n",OSDateTime(date_time,false)); 345 printmsg("Phone time is %s\n",OSDateTime(date_time,false));
359 break; 346 break;
360 default: 347 default:
361 Print_Error(error); 348 Print_Error(error);
362 } 349 }
363 350
364 error=Phone->GetLocale(&s, &locale); 351 error=Phone->GetLocale(&s, &locale);
365 switch (error) { 352 switch (error) {
366 case ERR_NOTSUPPORTED: 353 case ERR_NOTSUPPORTED:
367 case ERR_NOTIMPLEMENTED: 354 case ERR_NOTIMPLEMENTED:
368 break; 355 break;
369 default: 356 default:
370 Print_Error(error); 357 Print_Error(error);
371 printmsg("Time format is "); 358 printmsg("Time format is ");
372 if (locale.AMPMTime) printmsg("12 hours\n"); else printmsg("24 hours\n"); 359 if (locale.AMPMTime) printmsg("12 hours\n"); else printmsg("24 hours\n");
373 printmsg("Date format is "); 360 printmsg("Date format is ");
374 switch (locale.DateFormat) { 361 switch (locale.DateFormat) {
375 case GSM_Date_DDMMYYYY:printmsg("DD MM YYYY");break; 362 case GSM_Date_DDMMYYYY:printmsg("DD MM YYYY");break;
376 case GSM_Date_MMDDYYYY:printmsg("MM DD YYYY");break; 363 case GSM_Date_MMDDYYYY:printmsg("MM DD YYYY");break;
377 case GSM_Date_YYYYMMDD:printmsg("YYYY MM DD"); 364 case GSM_Date_YYYYMMDD:printmsg("YYYY MM DD");
365 default :break;
378 } 366 }
379 printmsg(", date separator is %c\n",locale.DateSeparator); 367 printmsg(", date separator is %c\n",locale.DateSeparator);
380 } 368 }
381 369
382 GSM_Terminate(); 370 GSM_Terminate();
383} 371}
384 372
385static void SetDateTime(int argc, char *argv[]) 373static void SetDateTime(int argc, char *argv[])
386{ 374{
387 GSM_DateTime date_time; 375 GSM_DateTime date_time;
388 376
389 GSM_GetCurrentDateTime(&date_time); 377 GSM_GetCurrentDateTime(&date_time);
390 378
391 GSM_Init(true); 379 GSM_Init(true);
392 380
393 error=Phone->SetDateTime(&s, &date_time); 381 error=Phone->SetDateTime(&s, &date_time);
394 Print_Error(error); 382 Print_Error(error);
395 383
396 GSM_Terminate(); 384 GSM_Terminate();
397} 385}
398 386
399static void GetAlarm(int argc, char *argv[]) 387static void GetAlarm(int argc, char *argv[])
400{ 388{
401 GSM_Alarm alarm; 389 GSM_Alarm alarm;
402 390
403 GSM_Init(true); 391 GSM_Init(true);
404 392
405 alarm.Location = 1; 393 alarm.Location = 1;
406 error=Phone->GetAlarm(&s, &alarm); 394 error=Phone->GetAlarm(&s, &alarm);
407 switch (error) { 395 switch (error) {
408 case ERR_EMPTY: 396 case ERR_EMPTY:
409 printmsg("Alarm not set in phone\n"); 397 printmsg("Alarm not set in phone\n");
410 break; 398 break;
411 case ERR_NONE: 399 case ERR_NONE:
412 if (alarm.Repeating) { 400 if (alarm.Repeating) {
413 printmsg("Date: %s\n","Every day"); 401 printmsg("Date: %s\n","Every day");
414 } else { 402 } else {
415 printmsg("Date: %s\n",OSDate(alarm.DateTime)); 403 printmsg("Date: %s\n",OSDate(alarm.DateTime));
416 } 404 }
417 printmsg("Time: %02d:%02d\n",alarm.DateTime.Hour, alarm.DateTime.Minute); 405 printmsg("Time: %02d:%02d\n",alarm.DateTime.Hour, alarm.DateTime.Minute);
418 if (alarm.Text[0] != 0 || alarm.Text[1] != 0) { 406 if (alarm.Text[0] != 0 || alarm.Text[1] != 0) {
419 printmsg("Text: \"%s\"\n", DecodeUnicodeConsole(alarm.Text)); 407 printmsg("Text: \"%s\"\n", DecodeUnicodeConsole(alarm.Text));
420 } 408 }
421 break; 409 break;
422 default: 410 default:
423 Print_Error(error); 411 Print_Error(error);
424 } 412 }
425 413
426 GSM_Terminate(); 414 GSM_Terminate();
427} 415}
428 416
429static void SetAlarm(int argc, char *argv[]) 417static void SetAlarm(int argc, char *argv[])
430{ 418{
431 GSM_Alarm alarm; 419 GSM_Alarm alarm;
432 420
433 alarm.DateTime.Hour = atoi(argv[2]); 421 alarm.DateTime.Hour = atoi(argv[2]);
434 alarm.DateTime.Minute = atoi(argv[3]); 422 alarm.DateTime.Minute = atoi(argv[3]);
435 alarm.DateTime.Second = 0; 423 alarm.DateTime.Second = 0;
436 alarm.Location = 1; 424 alarm.Location = 1;
437 alarm.Repeating = true; 425 alarm.Repeating = true;
438 alarm.Text[0] = 0; 426 alarm.Text[0] = 0;
439 alarm.Text[1] = 0; 427 alarm.Text[1] = 0;
440 428
441 GSM_Init(true); 429 GSM_Init(true);
442 430
443 error=Phone->SetAlarm(&s, &alarm); 431 error=Phone->SetAlarm(&s, &alarm);
444 Print_Error(error); 432 Print_Error(error);
445 433
446 GSM_Terminate(); 434 GSM_Terminate();
447} 435}
448 436
449 GSM_Bitmap caller[5]; 437 GSM_Bitmap caller[5];
450 GSM_AllRingtonesInfo Info; 438 GSM_AllRingtonesInfo Info;
451 bool callerinit[5] = {false, false, false, false, false}; 439 bool callerinit[5] = {false, false, false, false, false};
452 bool ringinit = false; 440 bool ringinit = false;
453 441
454static void PrintMemoryEntry(GSM_MemoryEntry *entry) 442static void PrintMemoryEntry(GSM_MemoryEntry *entry)
455{ 443{
456 GSM_Category Category; 444 GSM_Category Category;
457 bool unknown; 445 bool unknown;
458 int z; 446 int z;
459 447
460 for (i=0;i<entry->EntriesNum;i++) { 448 for (i=0;i<entry->EntriesNum;i++) {
461 unknown = false; 449 unknown = false;
462 switch (entry->Entries[i].EntryType) { 450 switch (entry->Entries[i].EntryType) {
463 case PBK_Date: 451 case PBK_Date:
464 printmsg("Date and time : %s\n",OSDateTime(entry->Entries[i].Date,false)); 452 printmsg("Date and time : %s\n",OSDateTime(entry->Entries[i].Date,false));
465 continue; 453 continue;
466 case PBK_Category: 454 case PBK_Category:
467 Category.Location = entry->Entries[i].Number; 455 Category.Location = entry->Entries[i].Number;
468 Category.Type = Category_Phonebook; 456 Category.Type = Category_Phonebook;
469 error=Phone->GetCategory(&s, &Category); 457 error=Phone->GetCategory(&s, &Category);
470 if (error == ERR_NONE) { 458 if (error == ERR_NONE) {
471 printmsg("Category : \"%s\" (%i)\n", DecodeUnicodeConsole(Category.Name), entry->Entries[i].Number); 459 printmsg("Category : \"%s\" (%i)\n", DecodeUnicodeConsole(Category.Name), entry->Entries[i].Number);
472 } else { 460 } else {
473 printmsg("Category : %i\n", entry->Entries[i].Number); 461 printmsg("Category : %i\n", entry->Entries[i].Number);
474 } 462 }
475 continue; 463 continue;
476 case PBK_Private: 464 case PBK_Private:
477 printmsg("Private : %s\n", entry->Entries[i].Number == 1 ? "Yes" : "No"); 465 printmsg("Private : %s\n", entry->Entries[i].Number == 1 ? "Yes" : "No");
478 continue; 466 continue;
479 case PBK_Number_General : printmsg("General number "); break; 467 case PBK_Number_General : printmsg("General number "); break;
480 case PBK_Number_Mobile : printmsg("Mobile number "); break; 468 case PBK_Number_Mobile : printmsg("Mobile number "); break;
481 case PBK_Number_Work : printmsg("Work number "); break; 469 case PBK_Number_Work : printmsg("Work number "); break;
482 case PBK_Number_Fax : printmsg("Fax number "); break; 470 case PBK_Number_Fax : printmsg("Fax number "); break;
483 case PBK_Number_Home : printmsg("Home number "); break; 471 case PBK_Number_Home : printmsg("Home number "); break;
484 case PBK_Number_Pager : printmsg("Pager number "); break; 472 case PBK_Number_Pager : printmsg("Pager number "); break;
485 case PBK_Number_Other : printmsg("Other number "); break; 473 case PBK_Number_Other : printmsg("Other number "); break;
486 case PBK_Text_Note : printmsg("Text "); break; 474 case PBK_Text_Note : printmsg("Text "); break;
487 case PBK_Text_Postal : printmsg("Snail address "); break; 475 case PBK_Text_Postal : printmsg("Snail address "); break;
488 case PBK_Text_Email : printmsg("Email address 1 "); break; 476 case PBK_Text_Email : printmsg("Email address 1 "); break;
489 case PBK_Text_Email2 : printmsg("Email address 2 "); break; 477 case PBK_Text_Email2 : printmsg("Email address 2 "); break;
490 case PBK_Text_URL : printmsg("URL address "); break; 478 case PBK_Text_URL : printmsg("URL address "); break;
491 case PBK_Text_Name : printmsg("Name "); break; 479 case PBK_Text_Name : printmsg("Name "); break;
492 case PBK_Text_LastName : printmsg("Last name "); break; 480 case PBK_Text_LastName : printmsg("Last name "); break;
493 case PBK_Text_FirstName : printmsg("First name "); break; 481 case PBK_Text_FirstName : printmsg("First name "); break;
494 case PBK_Text_Company : printmsg("Company "); break; 482 case PBK_Text_Company : printmsg("Company "); break;
495 case PBK_Text_JobTitle : printmsg("Job title "); break; 483 case PBK_Text_JobTitle : printmsg("Job title "); break;
496 case PBK_Text_StreetAddress : printmsg("Street address "); break; 484 case PBK_Text_StreetAddress : printmsg("Street address "); break;
497 case PBK_Text_City : printmsg("City "); break; 485 case PBK_Text_City : printmsg("City "); break;
498 case PBK_Text_State : printmsg("State "); break; 486 case PBK_Text_State : printmsg("State "); break;
499 case PBK_Text_Zip : printmsg("Zip code "); break; 487 case PBK_Text_Zip : printmsg("Zip code "); break;
500 case PBK_Text_Country : printmsg("Country "); break; 488 case PBK_Text_Country : printmsg("Country "); break;
501 case PBK_Text_Custom1 : printmsg("Custom text 1 "); break; 489 case PBK_Text_Custom1 : printmsg("Custom text 1 "); break;
502 case PBK_Text_Custom2 : printmsg("Custom text 2 "); break; 490 case PBK_Text_Custom2 : printmsg("Custom text 2 "); break;
503 case PBK_Text_Custom3 : printmsg("Custom text 3 "); break; 491 case PBK_Text_Custom3 : printmsg("Custom text 3 "); break;
504 case PBK_Text_Custom4 : printmsg("Custom text 4 "); break; 492 case PBK_Text_Custom4 : printmsg("Custom text 4 "); break;
505 case PBK_Caller_Group : 493 case PBK_Caller_Group :
506 unknown = true; 494 unknown = true;
507 if (!callerinit[entry->Entries[i].Number]) { 495 if (!callerinit[entry->Entries[i].Number]) {
508 caller[entry->Entries[i].Number].Type = GSM_CallerGroupLogo; 496 caller[entry->Entries[i].Number].Type = GSM_CallerGroupLogo;
509 caller[entry->Entries[i].Number].Location = entry->Entries[i].Number; 497 caller[entry->Entries[i].Number].Location = entry->Entries[i].Number;
510 error=Phone->GetBitmap(&s,&caller[entry->Entries[i].Number]); 498 error=Phone->GetBitmap(&s,&caller[entry->Entries[i].Number]);
511 Print_Error(error); 499 Print_Error(error);
512 if (caller[entry->Entries[i].Number].DefaultName) { 500 if (caller[entry->Entries[i].Number].DefaultName) {
513 NOKIA_GetDefaultCallerGroupName(&s,&caller[entry->Entries[i].Number]); 501 NOKIA_GetDefaultCallerGroupName(&s,&caller[entry->Entries[i].Number]);
514 } 502 }
515 callerinit[entry->Entries[i].Number]=true; 503 callerinit[entry->Entries[i].Number]=true;
516 } 504 }
517 printmsg("Caller group : \"%s\"\n",DecodeUnicodeConsole(caller[entry->Entries[i].Number].Text)); 505 printmsg("Caller group : \"%s\"\n",DecodeUnicodeConsole(caller[entry->Entries[i].Number].Text));
518 break; 506 break;
519 case PBK_RingtoneID : 507 case PBK_RingtoneID :
520 unknown = true; 508 unknown = true;
521 if (!ringinit) { 509 if (!ringinit) {
522 error=Phone->GetRingtonesInfo(&s,&Info); 510 error=Phone->GetRingtonesInfo(&s,&Info);
523 if (error != ERR_NOTSUPPORTED) Print_Error(error); 511 if (error != ERR_NOTSUPPORTED) Print_Error(error);
524 if (error == ERR_NONE) ringinit = true; 512 if (error == ERR_NONE) ringinit = true;
525 } 513 }
526 if (ringinit) { 514 if (ringinit) {
527 for (z=0;z<Info.Number;z++) { 515 for (z=0;z<Info.Number;z++) {
528 if (Info.Ringtone[z].ID == entry->Entries[i].Number) { 516 if (Info.Ringtone[z].ID == entry->Entries[i].Number) {
529 printmsg("Ringtone : \"%s\"\n",DecodeUnicodeConsole(Info.Ringtone[z].Name)); 517 printmsg("Ringtone : \"%s\"\n",DecodeUnicodeConsole(Info.Ringtone[z].Name));
530 break; 518 break;
531 } 519 }
532 } 520 }
533 } else { 521 } else {
534 printmsg("Ringtone ID : %i\n",entry->Entries[i].Number); 522 printmsg("Ringtone ID : %i\n",entry->Entries[i].Number);
535 } 523 }
536 break; 524 break;
537 case PBK_PictureID : 525 case PBK_PictureID :
538 unknown = true; 526 unknown = true;
539 printmsg("Picture ID : 0x%x\n",entry->Entries[i].Number); 527 printmsg("Picture ID : 0x%x\n",entry->Entries[i].Number);
540 break; 528 break;
541 default : 529 default :
542 printmsg("UNKNOWN\n"); 530 printmsg("UNKNOWN\n");
543 unknown = true; 531 unknown = true;
544 break; 532 break;
545 } 533 }
546 if (!unknown) printmsg(" : \"%s\"\n", DecodeUnicodeConsole(entry->Entries[i].Text)); 534 if (!unknown) printmsg(" : \"%s\"\n", DecodeUnicodeConsole(entry->Entries[i].Text));
547 } 535 }
548 printf("\n"); 536 printf("\n");
549} 537}
550 538
551static void GetAllMemory(int argc, char *argv[]) 539static void GetAllMemory(int argc, char *argv[])
552{ 540{
553 GSM_MemoryEntry Entry; 541 GSM_MemoryEntry Entry;
554 bool start = true; 542 bool start = true;
555 543
556 signal(SIGINT, interrupt); 544 signal(SIGINT, interrupt);
557 printmsgerr("Press Ctrl+C to break...\n"); 545 printmsgerr("Press Ctrl+C to break...\n");
558 546
559 Entry.MemoryType = 0; 547 Entry.MemoryType = 0;
560 548
561 if (mystrncasecmp(argv[2],"DC",0)) Entry.MemoryType=MEM_DC; 549 if (mystrncasecmp(argv[2],"DC",0)) Entry.MemoryType=MEM_DC;
562 if (mystrncasecmp(argv[2],"ON",0)) Entry.MemoryType=MEM_ON; 550 if (mystrncasecmp(argv[2],"ON",0)) Entry.MemoryType=MEM_ON;
563 if (mystrncasecmp(argv[2],"RC",0)) Entry.MemoryType=MEM_RC; 551 if (mystrncasecmp(argv[2],"RC",0)) Entry.MemoryType=MEM_RC;
564 if (mystrncasecmp(argv[2],"MC",0)) Entry.MemoryType=MEM_MC; 552 if (mystrncasecmp(argv[2],"MC",0)) Entry.MemoryType=MEM_MC;
565 if (mystrncasecmp(argv[2],"ME",0)) Entry.MemoryType=MEM_ME; 553 if (mystrncasecmp(argv[2],"ME",0)) Entry.MemoryType=MEM_ME;
566 if (mystrncasecmp(argv[2],"SM",0)) Entry.MemoryType=MEM_SM; 554 if (mystrncasecmp(argv[2],"SM",0)) Entry.MemoryType=MEM_SM;
567 if (mystrncasecmp(argv[2],"VM",0)) Entry.MemoryType=MEM_VM; 555 if (mystrncasecmp(argv[2],"VM",0)) Entry.MemoryType=MEM_VM;
568 if (mystrncasecmp(argv[2],"FD",0)) Entry.MemoryType=MEM_FD; 556 if (mystrncasecmp(argv[2],"FD",0)) Entry.MemoryType=MEM_FD;
569 if (Entry.MemoryType==0) { 557 if (Entry.MemoryType==0) {
570 printmsg("ERROR: unknown memory type (\"%s\")\n",argv[2]); 558 printmsg("ERROR: unknown memory type (\"%s\")\n",argv[2]);
571 exit (-1); 559 exit (-1);
572 } 560 }
573 561
574 GSM_Init(true); 562 GSM_Init(true);
575 563
576 while (!gshutdown) { 564 while (!gshutdown) {
577 error = Phone->GetNextMemory(&s, &Entry, start); 565 error = Phone->GetNextMemory(&s, &Entry, start);
578 if (error == ERR_EMPTY) break; 566 if (error == ERR_EMPTY) break;
579 Print_Error(error); 567 Print_Error(error);
580 printmsg("Memory %s, Location %i\n",argv[2],Entry.Location); 568 printmsg("Memory %s, Location %i\n",argv[2],Entry.Location);
581 PrintMemoryEntry(&Entry); 569 PrintMemoryEntry(&Entry);
582 start = false; 570 start = false;
583 } 571 }
584 572
585 GSM_Terminate(); 573 GSM_Terminate();
586} 574}
587 575
588static void GetMemory(int argc, char *argv[]) 576static void GetMemory(int argc, char *argv[])
589{ 577{
590 int j, start, stop; 578 int j, start, stop, emptynum = 0, fillednum = 0;
591 GSM_MemoryEntry entry; 579 GSM_MemoryEntry entry;
580 bool empty = true;
592 581
593 entry.MemoryType=0; 582 entry.MemoryType=0;
594 583
595 if (mystrncasecmp(argv[2],"DC",0)) entry.MemoryType=MEM_DC; 584 if (mystrncasecmp(argv[2],"DC",0)) entry.MemoryType=MEM_DC;
596 if (mystrncasecmp(argv[2],"ON",0)) entry.MemoryType=MEM_ON; 585 if (mystrncasecmp(argv[2],"ON",0)) entry.MemoryType=MEM_ON;
597 if (mystrncasecmp(argv[2],"RC",0)) entry.MemoryType=MEM_RC; 586 if (mystrncasecmp(argv[2],"RC",0)) entry.MemoryType=MEM_RC;
598 if (mystrncasecmp(argv[2],"MC",0)) entry.MemoryType=MEM_MC; 587 if (mystrncasecmp(argv[2],"MC",0)) entry.MemoryType=MEM_MC;
599 if (mystrncasecmp(argv[2],"ME",0)) entry.MemoryType=MEM_ME; 588 if (mystrncasecmp(argv[2],"ME",0)) entry.MemoryType=MEM_ME;
600 if (mystrncasecmp(argv[2],"SM",0)) entry.MemoryType=MEM_SM; 589 if (mystrncasecmp(argv[2],"SM",0)) entry.MemoryType=MEM_SM;
601 if (mystrncasecmp(argv[2],"VM",0)) entry.MemoryType=MEM_VM; 590 if (mystrncasecmp(argv[2],"VM",0)) entry.MemoryType=MEM_VM;
602 if (mystrncasecmp(argv[2],"FD",0)) entry.MemoryType=MEM_FD; 591 if (mystrncasecmp(argv[2],"FD",0)) entry.MemoryType=MEM_FD;
603 if (entry.MemoryType==0) { 592 if (entry.MemoryType==0) {
604 printmsg("ERROR: unknown memory type (\"%s\")\n",argv[2]); 593 printmsg("ERROR: unknown memory type (\"%s\")\n",argv[2]);
605 exit (-1); 594 exit (-1);
606 } 595 }
607 596
608 GetStartStop(&start, &stop, 3, argc, argv); 597 GetStartStop(&start, &stop, 3, argc, argv);
609 598
599 if (argc > 5 && strcmp(argv[5],"")) {
600 if (mystrncasecmp(argv[5],"-nonempty",0)) {
601 empty = false;
602 } else {
603 printmsg("ERROR: unknown parameter \"%s\"\n",argv[5]);
604 exit (-1);
605 }
606 }
607
610 GSM_Init(true); 608 GSM_Init(true);
611 609
612 if (!strcmp(s.Phone.Data.ModelInfo->model,"3310")) { 610 if (!strcmp(s.Phone.Data.ModelInfo->model,"3310")) {
613 if (s.Phone.Data.VerNum<=4.06) printmsg("WARNING: you will have null names in entries. Upgrade firmware in phone to higher than 4.06\n"); 611 if (s.Phone.Data.VerNum<=4.06) printmsg("WARNING: you will have null names in entries. Upgrade firmware in phone to higher than 4.06\n");
614 } 612 }
615 613
616 for (j=start;j<=stop;j++) { 614 for (j=start;j<=stop;j++) {
617 printmsg("Memory %s, Location %i\n",argv[2],j); 615 if (empty) printmsg("Memory %s, Location %i\n",argv[2],j);
618 616
619 entry.Location=j; 617 entry.Location=j;
620 618
621 error=Phone->GetMemory(&s, &entry); 619 error=Phone->GetMemory(&s, &entry);
622 if (error != ERR_EMPTY) Print_Error(error); 620 if (error != ERR_EMPTY) Print_Error(error);
623 621
624 if (error == ERR_EMPTY) { 622 if (error == ERR_EMPTY) {
625 printmsg("Entry is empty\n"); 623 emptynum++;
626 printf("\n"); 624 if (empty) {
625 printmsg("Entry is empty\n");
626 printf("\n");
627 }
627 } else { 628 } else {
629 fillednum++;
630 if (!empty) printmsg("Memory %s, Location %i\n",argv[2],j);
628 PrintMemoryEntry(&entry); 631 PrintMemoryEntry(&entry);
629 } 632 }
630 } 633 }
634
635 printmsg("%i entries empty, %i entries filled\n",emptynum,fillednum);
631 636
632 GSM_Terminate(); 637 GSM_Terminate();
633} 638}
634 639
635#define MemoryLocationToString(x) ( \ 640#define MemoryLocationToString(x) ( \
636 x == MEM_ON ? "ON" : \ 641 x == MEM_ON ? "ON" : \
637 x == MEM_RC ? "RC" : \ 642 x == MEM_RC ? "RC" : \
638 x == MEM_MC ? "MC" : \ 643 x == MEM_MC ? "MC" : \
639 x == MEM_ME ? "ME" : \ 644 x == MEM_ME ? "ME" : \
640 x == MEM_SM ? "SM" : \ 645 x == MEM_SM ? "SM" : \
641 x == MEM_VM ? "VM" : \ 646 x == MEM_VM ? "VM" : \
642 x == MEM_FD ? "FD" : "XX") 647 x == MEM_FD ? "FD" : "XX")
643 648
644static void SearchOneEntry(GSM_MemoryEntry *Entry, unsigned char *Text) 649static void SearchOneEntry(GSM_MemoryEntry *Entry, unsigned char *Text)
645{ 650{
646 int i; 651 int i;
647 652
648 for (i=0;i<Entry->EntriesNum;i++) { 653 for (i=0;i<Entry->EntriesNum;i++) {
649 switch (Entry->Entries[i].EntryType) { 654 switch (Entry->Entries[i].EntryType) {
650 case PBK_Number_General : 655 case PBK_Number_General :
651 case PBK_Number_Mobile : 656 case PBK_Number_Mobile :
652 case PBK_Number_Work : 657 case PBK_Number_Work :
653 case PBK_Number_Fax : 658 case PBK_Number_Fax :
654 case PBK_Number_Home : 659 case PBK_Number_Home :
655 case PBK_Number_Pager : 660 case PBK_Number_Pager :
656 case PBK_Number_Other : 661 case PBK_Number_Other :
657 case PBK_Text_Note : 662 case PBK_Text_Note :
658 case PBK_Text_Postal : 663 case PBK_Text_Postal :
659 case PBK_Text_Email : 664 case PBK_Text_Email :
660 case PBK_Text_Email2 : 665 case PBK_Text_Email2 :
661 case PBK_Text_URL : 666 case PBK_Text_URL :
662 case PBK_Text_Name : 667 case PBK_Text_Name :
663 case PBK_Text_LastName : 668 case PBK_Text_LastName :
664 case PBK_Text_FirstName : 669 case PBK_Text_FirstName :
665 case PBK_Text_Company : 670 case PBK_Text_Company :
666 case PBK_Text_JobTitle : 671 case PBK_Text_JobTitle :
667 case PBK_Text_StreetAddress : 672 case PBK_Text_StreetAddress :
668 case PBK_Text_City : 673 case PBK_Text_City :
669 case PBK_Text_State : 674 case PBK_Text_State :
670 case PBK_Text_Zip : 675 case PBK_Text_Zip :
671 case PBK_Text_Country : 676 case PBK_Text_Country :
672 case PBK_Text_Custom1 : 677 case PBK_Text_Custom1 :
673 case PBK_Text_Custom2 : 678 case PBK_Text_Custom2 :
674 case PBK_Text_Custom3 : 679 case PBK_Text_Custom3 :
675 case PBK_Text_Custom4 : 680 case PBK_Text_Custom4 :
676 case PBK_Caller_Group : 681 case PBK_Caller_Group :
677 if (mystrstr(Entry->Entries[i].Text, Text) != NULL) { 682 if (mywstrstr(Entry->Entries[i].Text, Text) != NULL) {
678 fprintf(stderr,"\n"); 683 fprintf(stderr,"\n");
679 printmsg("Memory %s, Location %i\n",MemoryLocationToString(Entry->MemoryType),Entry->Location); 684 printmsg("Memory %s, Location %i\n",MemoryLocationToString(Entry->MemoryType),Entry->Location);
680 PrintMemoryEntry(Entry); 685 PrintMemoryEntry(Entry);
681 return; 686 return;
682 } 687 }
683 break; 688 break;
684 default: 689 default:
685 break; 690 break;
686 } 691 }
687 } 692 }
688 } 693 }
689 694
690static void SearchOneMemory(GSM_MemoryType MemoryType, char *Title, unsigned char *Text) 695static void SearchOneMemory(GSM_MemoryType MemoryType, char *Title, unsigned char *Text)
691{ 696{
692 GSM_MemoryEntry Entry; 697 GSM_MemoryEntry Entry;
693 GSM_MemoryStatusStatus; 698 GSM_MemoryStatusStatus;
694 int i = 0, l = 1; 699 int i = 0, l = 1;
695 bool start = true; 700 bool start = true;
696 701
697 Status.MemoryType = MemoryType; 702 Status.MemoryType = MemoryType;
698 Entry.MemoryType = MemoryType; 703 Entry.MemoryType = MemoryType;
699 704
700 if (Phone->GetMemoryStatus(&s, &Status) == ERR_NONE) { 705 if (Phone->GetMemoryStatus(&s, &Status) == ERR_NONE) {
701 fprintf(stderr,"%c%s: %i%%", 13, Title, (i+1)*100/(Status.MemoryUsed+1)); 706 fprintf(stderr,"%c%s: %i%%", 13, Title, (i+1)*100/(Status.MemoryUsed+1));
702 if (Phone->GetNextMemory != NOTSUPPORTED && Phone->GetNextMemory != NOTIMPLEMENTED) { 707 if (Phone->GetNextMemory != NOTSUPPORTED && Phone->GetNextMemory != NOTIMPLEMENTED) {
703 while (i < Status.MemoryUsed) { 708 while (i < Status.MemoryUsed) {
704 if (gshutdown) return; 709 if (gshutdown) return;
705 i++; 710 i++;
706 fprintf(stderr,"\r%s: %i%%", Title, (i+1)*100/(Status.MemoryUsed+1)); 711 fprintf(stderr,"\r%s: %i%%", Title, (i+1)*100/(Status.MemoryUsed+1));
707 error = Phone->GetNextMemory(&s, &Entry, start); 712 error = Phone->GetNextMemory(&s, &Entry, start);
708 if (error == ERR_EMPTY) break; 713 if (error == ERR_EMPTY) break;
709 Print_Error(error); 714 Print_Error(error);
710 SearchOneEntry(&Entry, Text); 715 SearchOneEntry(&Entry, Text);
711 start = false; 716 start = false;
712 } 717 }
713 } else { 718 } else {
714 while (i < Status.MemoryUsed) { 719 while (i < Status.MemoryUsed) {
715 Entry.Location = l; 720 Entry.Location = l;
716 error = Phone->GetMemory(&s, &Entry); 721 error = Phone->GetMemory(&s, &Entry);
717 if (error != ERR_EMPTY) { 722 if (error != ERR_EMPTY) {
718 Print_Error(error); 723 Print_Error(error);
719 i++; 724 i++;
720 SearchOneEntry(&Entry, Text); 725 SearchOneEntry(&Entry, Text);
721 } 726 }
722 fprintf(stderr,"%c%s: %i%%", 13, Title, (i+1)*100/(Status.MemoryUsed+1)); 727 fprintf(stderr,"%c%s: %i%%", 13, Title, (i+1)*100/(Status.MemoryUsed+1));
723 l++; 728 l++;
724 } 729 }
725 } 730 }
726 fprintf(stderr,"\n"); 731 fprintf(stderr,"\n");
727 } 732 }
728} 733}
729 734
730static void SearchMemory(int argc, char *argv[]) 735static void SearchMemory(int argc, char *argv[])
731{ 736{
732 unsigned char Text[(GSM_PHONEBOOK_TEXT_LENGTH+1)*2]; 737 unsigned char Text[(GSM_PHONEBOOK_TEXT_LENGTH+1)*2];
733 int Length; 738 int Length;
734 739
735 signal(SIGINT, interrupt); 740 signal(SIGINT, interrupt);
736 printmsgerr("Press Ctrl+C to break...\n"); 741 printmsgerr("Press Ctrl+C to break...\n");
737 742
738 Length = strlen(argv[2]); 743 Length = strlen(argv[2]);
739 if (Length > GSM_PHONEBOOK_TEXT_LENGTH) { 744 if (Length > GSM_PHONEBOOK_TEXT_LENGTH) {
740 printmsg("Search text too long, truncating to %d chars!\n", GSM_PHONEBOOK_TEXT_LENGTH); 745 printmsg("Search text too long, truncating to %d chars!\n", GSM_PHONEBOOK_TEXT_LENGTH);
741 Length = GSM_PHONEBOOK_TEXT_LENGTH; 746 Length = GSM_PHONEBOOK_TEXT_LENGTH;
742 } 747 }
743 EncodeUnicode(Text, argv[2], Length); 748 EncodeUnicode(Text, argv[2], Length);
744 749
745 GSM_Init(true); 750 GSM_Init(true);
746 751
747 if (!gshutdown) SearchOneMemory(MEM_ME, "Phone phonebook", Text); 752 if (!gshutdown) SearchOneMemory(MEM_ME, "Phone phonebook", Text);
748 if (!gshutdown) SearchOneMemory(MEM_SM, "SIM phonebook", Text); 753 if (!gshutdown) SearchOneMemory(MEM_SM, "SIM phonebook", Text);
749 if (!gshutdown) SearchOneMemory(MEM_ON, "Own numbers", Text); 754 if (!gshutdown) SearchOneMemory(MEM_ON, "Own numbers", Text);
750 if (!gshutdown) SearchOneMemory(MEM_DC, "Dialled numbers", Text); 755 if (!gshutdown) SearchOneMemory(MEM_DC, "Dialled numbers", Text);
751 if (!gshutdown) SearchOneMemory(MEM_RC, "Received numbers", Text); 756 if (!gshutdown) SearchOneMemory(MEM_RC, "Received numbers", Text);
752 if (!gshutdown) SearchOneMemory(MEM_MC, "Missed numbers", Text); 757 if (!gshutdown) SearchOneMemory(MEM_MC, "Missed numbers", Text);
753 if (!gshutdown) SearchOneMemory(MEM_FD, "Fix dialling", Text); 758 if (!gshutdown) SearchOneMemory(MEM_FD, "Fix dialling", Text);
754 if (!gshutdown) SearchOneMemory(MEM_VM, "Voice mailbox", Text); 759 if (!gshutdown) SearchOneMemory(MEM_VM, "Voice mailbox", Text);
755 760
756 GSM_Terminate(); 761 GSM_Terminate();
757} 762}
758 763
759static void ListMemoryCategoryEntries(int Category) 764static void ListMemoryCategoryEntries(int Category)
760{ 765{
761 GSM_MemoryEntry Entry; 766 GSM_MemoryEntry Entry;
762 bool start = true; 767 bool start = true;
763 int j; 768 int j;
764 769
765 /* Category can be only for ME stored entries */ 770 /* Category can be only for ME stored entries */
766 Entry.MemoryType = MEM_ME; 771 Entry.MemoryType = MEM_ME;
767 772
768 while (!gshutdown) { 773 while (!gshutdown) {
769 error = Phone->GetNextMemory(&s, &Entry, start); 774 error = Phone->GetNextMemory(&s, &Entry, start);
770 if (error == ERR_EMPTY) break; 775 if (error == ERR_EMPTY) break;
771 Print_Error(error); 776 Print_Error(error);
772 for (j=0;j<Entry.EntriesNum;j++) { 777 for (j=0;j<Entry.EntriesNum;j++) {
773 if (Entry.Entries[j].EntryType == PBK_Category && Entry.Entries[j].Number == Category) { 778 if (Entry.Entries[j].EntryType == PBK_Category && Entry.Entries[j].Number == Category) {
774 printmsg("Memory %s, Location %i\n",MemoryLocationToString(Entry.MemoryType),Entry.Location); 779 printmsg("Memory %s, Location %i\n",MemoryLocationToString(Entry.MemoryType),Entry.Location);
775 PrintMemoryEntry(&Entry); 780 PrintMemoryEntry(&Entry);
776 } 781 }
777 } 782 }
778 start = false; 783 start = false;
779 } 784 }
780} 785}
781 786
782static void ListMemoryCategory(int argc, char *argv[]) 787static void ListMemoryCategory(int argc, char *argv[])
783{ 788{
784 GSM_Category Category; 789 GSM_Category Category;
785 GSM_CategoryStatusStatus; 790 GSM_CategoryStatusStatus;
786 int j, count; 791 int j, count;
787 792
788 unsigned char Text[(GSM_MAX_CATEGORY_NAME_LENGTH+1)*2]; 793 unsigned char Text[(GSM_MAX_CATEGORY_NAME_LENGTH+1)*2];
789 int Length; 794 int Length;
790 bool Number = true;; 795 bool Number = true;;
791 796
792 GSM_Init(true); 797 GSM_Init(true);
793 798
794 signal(SIGINT, interrupt); 799 signal(SIGINT, interrupt);
795 printmsgerr("Press Ctrl+C to break...\n"); 800 printmsgerr("Press Ctrl+C to break...\n");
796 801
797 Length = strlen(argv[2]); 802 Length = strlen(argv[2]);
798 for (j = 0; j < Length; j++) { 803 for (j = 0; j < Length; j++) {
799 if (!isdigit(argv[2][j])) { 804 if (!isdigit(argv[2][j])) {
800 Number = false; 805 Number = false;
801 break; 806 break;
802 } 807 }
803 } 808 }
804 809
805 if (Number) { 810 if (Number) {
806 j = atoi(argv[2]); 811 j = atoi(argv[2]);
807 if (j > 0) { 812 if (j > 0) {
808 ListMemoryCategoryEntries(j); 813 ListMemoryCategoryEntries(j);
809 } 814 }
810 } else { 815 } else {
811 if (Length > GSM_MAX_CATEGORY_NAME_LENGTH) { 816 if (Length > GSM_MAX_CATEGORY_NAME_LENGTH) {
812 printmsg("Search text too long, truncating to %d chars!\n", GSM_MAX_CATEGORY_NAME_LENGTH); 817 printmsg("Search text too long, truncating to %d chars!\n", GSM_MAX_CATEGORY_NAME_LENGTH);
813 Length = GSM_MAX_CATEGORY_NAME_LENGTH; 818 Length = GSM_MAX_CATEGORY_NAME_LENGTH;
814 } 819 }
815 EncodeUnicode(Text, argv[2], Length); 820 EncodeUnicode(Text, argv[2], Length);
816 821
817 Category.Type = Category_Phonebook; 822 Category.Type = Category_Phonebook;
818 Status.Type = Category_Phonebook; 823 Status.Type = Category_Phonebook;
819 824
820 if (Phone->GetCategoryStatus(&s, &Status) == ERR_NONE) { 825 if (Phone->GetCategoryStatus(&s, &Status) == ERR_NONE) {
821 for (count=0,j=1;count<Status.Used;j++) { 826 for (count=0,j=1;count<Status.Used;j++) {
822 Category.Location=j; 827 Category.Location=j;
823 error=Phone->GetCategory(&s, &Category); 828 error=Phone->GetCategory(&s, &Category);
824 829
825 if (error != ERR_EMPTY) { 830 if (error != ERR_EMPTY) {
826 count++; 831 count++;
827 if (mystrstr(Category.Name, Text) != NULL) { 832 if (mywstrstr(Category.Name, Text) != NULL) {
828 ListMemoryCategoryEntries(j); 833 ListMemoryCategoryEntries(j);
829 } 834 }
830 } 835 }
831 } 836 }
832 } 837 }
833 } 838 }
834 GSM_Terminate(); 839 GSM_Terminate();
835} 840}
836 841
837static void displaysinglesmsinfo(GSM_SMSMessage sms, bool displaytext, bool displayudh) 842static void displaysinglesmsinfo(GSM_SMSMessage sms, bool displaytext, bool displayudh)
838{ 843{
839 switch (sms.PDU) { 844 switch (sms.PDU) {
840 case SMS_Status_Report: 845 case SMS_Status_Report:
841 printmsg("SMS status report\n"); 846 printmsg("SMS status report\n");
842 printmsg("Status : "); 847 printmsg("Status : ");
843 switch (sms.State) { 848 switch (sms.State) {
844 case SMS_Sent : printmsg("Sent");break; 849 case SMS_Sent : printmsg("Sent");break;
845 case SMS_Read : printmsg("Read");break; 850 case SMS_Read : printmsg("Read");break;
846 case SMS_UnRead : printmsg("UnRead");break; 851 case SMS_UnRead : printmsg("UnRead");break;
847 case SMS_UnSent : printmsg("UnSent");break; 852 case SMS_UnSent : printmsg("UnSent");break;
848 } 853 }
849 printmsg("\nRemote number : \"%s\"\n",DecodeUnicodeConsole(sms.Number)); 854 printmsg("\nRemote number : \"%s\"\n",DecodeUnicodeConsole(sms.Number));
850 printmsg("Reference number: 0x%02X\n",sms.MessageReference); 855 printmsg("Reference number: %d\n",sms.MessageReference);
851 printmsg("Sent : %s\n",OSDateTime(sms.DateTime,true)); 856 printmsg("Sent : %s\n",OSDateTime(sms.DateTime,true));
852 printmsg("SMSC number : \"%s\"\n",DecodeUnicodeConsole(sms.SMSC.Number)); 857 printmsg("SMSC number : \"%s\"\n",DecodeUnicodeConsole(sms.SMSC.Number));
853 printmsg("SMSC response : %s\n",OSDateTime(sms.SMSCTime,true)); 858 printmsg("SMSC response : %s\n",OSDateTime(sms.SMSCTime,true));
854 printmsg("Delivery status : %s\n",DecodeUnicodeConsole(sms.Text)); 859 printmsg("Delivery status : %s\n",DecodeUnicodeConsole(sms.Text));
855 printmsg("Details : "); 860 printmsg("Details : ");
856 if (sms.DeliveryStatus & 0x40) { 861 if (sms.DeliveryStatus & 0x40) {
857 if (sms.DeliveryStatus & 0x20) { 862 if (sms.DeliveryStatus & 0x20) {
858 printmsg("Temporary error, "); 863 printmsg("Temporary error, ");
859 } else { 864 } else {
860 printmsg("Permanent error, "); 865 printmsg("Permanent error, ");
861 } 866 }
862 } else if (sms.DeliveryStatus & 0x20) { 867 } else if (sms.DeliveryStatus & 0x20) {
863 printmsg("Temporary error, "); 868 printmsg("Temporary error, ");
864 } 869 }
865 switch (sms.DeliveryStatus) { 870 switch (sms.DeliveryStatus) {
866 case 0x00: printmsg("SM received by the SME"); break; 871 case 0x00: printmsg("SM received by the SME"); break;
867 case 0x01: printmsg("SM forwarded by the SC to the SME but the SC is unable to confirm delivery");break; 872 case 0x01: printmsg("SM forwarded by the SC to the SME but the SC is unable to confirm delivery");break;
868 case 0x02: printmsg("SM replaced by the SC"); break; 873 case 0x02: printmsg("SM replaced by the SC"); break;
869 case 0x20: printmsg("Congestion"); break; 874 case 0x20: printmsg("Congestion"); break;
870 case 0x21: printmsg("SME busy"); break; 875 case 0x21: printmsg("SME busy"); break;
871 case 0x22: printmsg("No response from SME"); break; 876 case 0x22: printmsg("No response from SME"); break;
872 case 0x23: printmsg("Service rejected"); break; 877 case 0x23: printmsg("Service rejected"); break;
873 case 0x24: printmsg("Quality of service not aviable"); break; 878 case 0x24: printmsg("Quality of service not aviable"); break;
874 case 0x25: printmsg("Error in SME"); break; 879 case 0x25: printmsg("Error in SME"); break;
875 case 0x40: printmsg("Remote procedure error"); break; 880 case 0x40: printmsg("Remote procedure error"); break;
876 case 0x41: printmsg("Incompatibile destination"); break; 881 case 0x41: printmsg("Incompatibile destination"); break;
877 case 0x42: printmsg("Connection rejected by SME"); break; 882 case 0x42: printmsg("Connection rejected by SME"); break;
878 case 0x43: printmsg("Not obtainable"); break; 883 case 0x43: printmsg("Not obtainable"); break;
879 case 0x44: printmsg("Quality of service not available"); break; 884 case 0x44: printmsg("Quality of service not available"); break;
880 case 0x45: printmsg("No internetworking available"); break; 885 case 0x45: printmsg("No internetworking available"); break;
881 case 0x46: printmsg("SM Validity Period Expired"); break; 886 case 0x46: printmsg("SM Validity Period Expired"); break;
882 case 0x47: printmsg("SM deleted by originating SME"); break; 887 case 0x47: printmsg("SM deleted by originating SME"); break;
883 case 0x48: printmsg("SM Deleted by SC Administration"); break; 888 case 0x48: printmsg("SM Deleted by SC Administration"); break;
884 case 0x49: printmsg("SM does not exist"); break; 889 case 0x49: printmsg("SM does not exist"); break;
885 case 0x60: printmsg("Congestion"); break; 890 case 0x60: printmsg("Congestion"); break;
886 case 0x61: printmsg("SME busy"); break; 891 case 0x61: printmsg("SME busy"); break;
887 case 0x62: printmsg("No response from SME"); break; 892 case 0x62: printmsg("No response from SME"); break;
888 case 0x63: printmsg("Service rejected"); break; 893 case 0x63: printmsg("Service rejected"); break;
889 case 0x64: printmsg("Quality of service not available"); break; 894 case 0x64: printmsg("Quality of service not available"); break;
890 case 0x65: printmsg("Error in SME"); break; 895 case 0x65: printmsg("Error in SME"); break;
891 default : printmsg("Reserved/Specific to SC: %x",sms.DeliveryStatus);break; 896 default : printmsg("Reserved/Specific to SC: %x",sms.DeliveryStatus);break;
892 } 897 }
893 printf("\n"); 898 printf("\n");
894 break; 899 break;
895 case SMS_Deliver: 900 case SMS_Deliver:
896 printmsg("SMS message\n"); 901 printmsg("SMS message\n");
897 printmsg("SMSC number : \"%s\"",DecodeUnicodeConsole(sms.SMSC.Number)); 902 if (sms.State==SMS_UnSent && sms.Memory==MEM_ME) {
898 if (sms.ReplyViaSameSMSC) printmsg(" (set for reply)"); 903 printmsg("Saved : %s\n",OSDateTime(sms.DateTime,true));
899 printmsg("\nSent : %s\n",OSDateTime(sms.DateTime,true)); 904 } else {
905 printmsg("SMSC number : \"%s\"",DecodeUnicodeConsole(sms.SMSC.Number));
906 if (sms.ReplyViaSameSMSC) printmsg(" (set for reply)");
907 printmsg("\nSent : %s\n",OSDateTime(sms.DateTime,true));
908 }
900 /* No break. The only difference for SMS_Deliver and SMS_Submit is, 909 /* No break. The only difference for SMS_Deliver and SMS_Submit is,
901 * that SMS_Deliver contains additional data. We wrote them and then go 910 * that SMS_Deliver contains additional data. We wrote them and then go
902 * for data shared with SMS_Submit 911 * for data shared with SMS_Submit
903 */ 912 */
904 case SMS_Submit: 913 case SMS_Submit:
905 if (sms.ReplaceMessage != 0) printmsg("SMS replacing ID : %i\n",sms.ReplaceMessage); 914 if (sms.ReplaceMessage != 0) printmsg("SMS replacing ID : %i\n",sms.ReplaceMessage);
906 /* If we went here from "case SMS_Deliver", we don't write "SMS Message" */ 915 /* If we went here from "case SMS_Deliver", we don't write "SMS Message" */
907 if (sms.PDU==SMS_Submit) { 916 if (sms.PDU==SMS_Submit) {
908 printmsg("SMS message\n"); 917 printmsg("SMS message\n");
909 printmsg("Reference number : 0x%02X\n",sms.MessageReference); 918 if (sms.State==SMS_UnSent && sms.Memory==MEM_ME) {
919 } else {
920 printmsg("Reference number : %d\n",sms.MessageReference);
921 }
910 } 922 }
911 if (sms.Name[0] != 0x00 || sms.Name[1] != 0x00) { 923 if (sms.Name[0] != 0x00 || sms.Name[1] != 0x00) {
912 printmsg("Name : \"%s\"\n",DecodeUnicodeConsole(sms.Name)); 924 printmsg("Name : \"%s\"\n",DecodeUnicodeConsole(sms.Name));
913 } 925 }
914 if (sms.Class != -1) { 926 if (sms.Class != -1) {
915 printmsg("Class : %i\n",sms.Class); 927 printmsg("Class : %i\n",sms.Class);
916 } 928 }
917 printmsg("Coding : "); 929 printmsg("Coding : ");
918 switch (sms.Coding) { 930 switch (sms.Coding) {
919 case SMS_Coding_Unicode : printmsg("Unicode\n"); break; 931 case SMS_Coding_Unicode : printmsg("Unicode\n"); break;
920 case SMS_Coding_Default : printmsg("Default GSM alphabet\n");break; 932 case SMS_Coding_Default : printmsg("Default GSM alphabet\n");break;
921 case SMS_Coding_8bit : printmsg("8 bit\n"); break; 933 case SMS_Coding_8bit : printmsg("8 bit\n"); break;
922 } 934 }
935 if (sms.State==SMS_UnSent && sms.Memory==MEM_ME) {
936 } else {
937 printmsg("Remote number : \"%s\"\n",DecodeUnicodeConsole(sms.Number));
938 }
923 printmsg("Status : "); 939 printmsg("Status : ");
924 switch (sms.State) { 940 switch (sms.State) {
925 case SMS_Sent : printmsg("Sent");break; 941 case SMS_Sent : printmsg("Sent\n");break;
926 case SMS_Read : printmsg("Read");break; 942 case SMS_Read : printmsg("Read\n");break;
927 case SMS_UnRead : printmsg("UnRead");break; 943 case SMS_UnRead : printmsg("UnRead\n");break;
928 case SMS_UnSent : printmsg("UnSent");break; 944 case SMS_UnSent : printmsg("UnSent\n");break;
929 } 945 }
930 printmsg("\nRemote number : \"%s\"\n",DecodeUnicodeConsole(sms.Number));
931 if (sms.UDH.Type != UDH_NoUDH) { 946 if (sms.UDH.Type != UDH_NoUDH) {
932 printmsg("User Data Header : "); 947 printmsg("User Data Header : ");
933 switch (sms.UDH.Type) { 948 switch (sms.UDH.Type) {
934 case UDH_ConcatenatedMessages : printmsg("Concatenated (linked) message"); break; 949 case UDH_ConcatenatedMessages : printmsg("Concatenated (linked) message"); break;
935 case UDH_ConcatenatedMessages16bit : printmsg("Concatenated (linked) message"); break; 950 case UDH_ConcatenatedMessages16bit : printmsg("Concatenated (linked) message"); break;
936 case UDH_DisableVoice : printmsg("Disables voice indicator"); break; 951 case UDH_DisableVoice : printmsg("Disables voice indicator"); break;
937 case UDH_EnableVoice : printmsg("Enables voice indicator"); break; 952 case UDH_EnableVoice : printmsg("Enables voice indicator"); break;
938 case UDH_DisableFax : printmsg("Disables fax indicator"); break; 953 case UDH_DisableFax : printmsg("Disables fax indicator"); break;
939 case UDH_EnableFax : printmsg("Enables fax indicator"); break; 954 case UDH_EnableFax : printmsg("Enables fax indicator"); break;
940 case UDH_DisableEmail : printmsg("Disables email indicator"); break; 955 case UDH_DisableEmail : printmsg("Disables email indicator"); break;
941 case UDH_EnableEmail : printmsg("Enables email indicator"); break; 956 case UDH_EnableEmail : printmsg("Enables email indicator"); break;
942 case UDH_VoidSMS : printmsg("Void SMS"); break; 957 case UDH_VoidSMS : printmsg("Void SMS"); break;
943 case UDH_NokiaWAP : printmsg("Nokia WAP bookmark"); break; 958 case UDH_NokiaWAP : printmsg("Nokia WAP bookmark"); break;
944 case UDH_NokiaOperatorLogoLong : printmsg("Nokia operator logo"); break; 959 case UDH_NokiaOperatorLogoLong : printmsg("Nokia operator logo"); break;
945 case UDH_NokiaWAPLong : printmsg("Nokia WAP bookmark or WAP/MMS settings"); break; 960 case UDH_NokiaWAPLong : printmsg("Nokia WAP bookmark or WAP/MMS settings"); break;
946 case UDH_NokiaRingtone : printmsg("Nokia ringtone"); break; 961 case UDH_NokiaRingtone : printmsg("Nokia ringtone"); break;
947 case UDH_NokiaRingtoneLong : printmsg("Nokia ringtone"); break; 962 case UDH_NokiaRingtoneLong : printmsg("Nokia ringtone"); break;
948 case UDH_NokiaOperatorLogo : printmsg("Nokia GSM operator logo"); break; 963 case UDH_NokiaOperatorLogo : printmsg("Nokia GSM operator logo"); break;
949 case UDH_NokiaCallerLogo : printmsg("Nokia caller logo"); break; 964 case UDH_NokiaCallerLogo : printmsg("Nokia caller logo"); break;
950 case UDH_NokiaProfileLong : printmsg("Nokia profile"); break; 965 case UDH_NokiaProfileLong : printmsg("Nokia profile"); break;
951 case UDH_NokiaCalendarLong : printmsg("Nokia calendar note"); break; 966 case UDH_NokiaCalendarLong : printmsg("Nokia calendar note"); break;
952 case UDH_NokiaPhonebookLong : printmsg("Nokia phonebook entry"); break; 967 case UDH_NokiaPhonebookLong : printmsg("Nokia phonebook entry"); break;
953 case UDH_UserUDH : printmsg("User UDH"); break; 968 case UDH_UserUDH : printmsg("User UDH"); break;
954 case UDH_MMSIndicatorLong : printmsg("MMS indicator"); break; 969 case UDH_MMSIndicatorLong : printmsg("MMS indicator"); break;
955 case UDH_NoUDH: break; 970 case UDH_NoUDH: break;
956 } 971 }
957 if (sms.UDH.Type != UDH_NoUDH) { 972 if (sms.UDH.Type != UDH_NoUDH) {
958 if (sms.UDH.ID8bit != -1) printmsg(", ID (8 bit) %i",sms.UDH.ID8bit); 973 if (sms.UDH.ID8bit != -1) printmsg(", ID (8 bit) %i",sms.UDH.ID8bit);
959 if (sms.UDH.ID16bit != -1) printmsg(", ID (16 bit) %i",sms.UDH.ID16bit); 974 if (sms.UDH.ID16bit != -1) printmsg(", ID (16 bit) %i",sms.UDH.ID16bit);
960 if (sms.UDH.PartNumber != -1 && sms.UDH.AllParts != -1) { 975 if (sms.UDH.PartNumber != -1 && sms.UDH.AllParts != -1) {
961 if (displayudh) { 976 if (displayudh) {
962 printmsg(", part %i of %i",sms.UDH.PartNumber,sms.UDH.AllParts); 977 printmsg(", part %i of %i",sms.UDH.PartNumber,sms.UDH.AllParts);
963 } else { 978 } else {
964 printmsg(", %i parts",sms.UDH.AllParts); 979 printmsg(", %i parts",sms.UDH.AllParts);
965 } 980 }
966 } 981 }
967 } 982 }
968 printf("\n"); 983 printf("\n");
969 } 984 }
970 if (displaytext) { 985 if (displaytext) {
971 printf("\n"); 986 printf("\n");
972 if (sms.Coding!=SMS_Coding_8bit) { 987 if (sms.Coding!=SMS_Coding_8bit) {
973 printmsg("%s\n",DecodeUnicodeConsole(sms.Text)); 988 printmsg("%s\n",DecodeUnicodeConsole(sms.Text));
974 } else { 989 } else {
975 printmsg("8 bit SMS, cannot be displayed here\n"); 990 printmsg("8 bit SMS, cannot be displayed here\n");
976 } 991 }
977 } 992 }
978 break; 993 break;
979 } 994 }
980} 995}
981//#if 0 996
982static void displaymultismsinfo (GSM_MultiSMSMessage sms, bool eachsms, bool ems) 997static void displaymultismsinfo (GSM_MultiSMSMessage sms, bool eachsms, bool ems)
983{ 998{
984 GSM_MultiPartSMSInfoSMSInfo; 999 GSM_MultiPartSMSInfoSMSInfo;
985 bool RetVal,udhinfo=true; 1000 bool RetVal,udhinfo=true;
986 int j; 1001 int j;
987 1002
988 /* GSM_DecodeMultiPartSMS returns if decoded SMS contenst correctly */ 1003 /* GSM_DecodeMultiPartSMS returns if decoded SMS contenst correctly */
989 RetVal = GSM_DecodeMultiPartSMS(&SMSInfo,&sms,ems); 1004 RetVal = GSM_DecodeMultiPartSMS(&SMSInfo,&sms,ems);
990 1005
991 if (eachsms) { 1006 if (eachsms) {
992 if (sms.SMS[0].UDH.Type != UDH_NoUDH && sms.SMS[0].UDH.AllParts == sms.Number) udhinfo = false; 1007 if (sms.SMS[0].UDH.Type != UDH_NoUDH && sms.SMS[0].UDH.AllParts == sms.Number) udhinfo = false;
993 if (RetVal && !udhinfo) { 1008 if (RetVal && !udhinfo) {
994 displaysinglesmsinfo(sms.SMS[0],false,false); 1009 displaysinglesmsinfo(sms.SMS[0],false,false);
995 printf("\n"); 1010 printf("\n");
996 } else { 1011 } else {
997 for (j=0;j<sms.Number;j++) { 1012 for (j=0;j<sms.Number;j++) {
998 displaysinglesmsinfo(sms.SMS[j],!RetVal,udhinfo); 1013 displaysinglesmsinfo(sms.SMS[j],!RetVal,udhinfo);
999 printf("\n"); 1014 printf("\n");
1000 } 1015 }
1001 } 1016 }
1002 } else { 1017 } else {
1003 for (j=0;j<sms.Number;j++) { 1018 for (j=0;j<sms.Number;j++) {
1004 displaysinglesmsinfo(sms.SMS[j],!RetVal,true); 1019 displaysinglesmsinfo(sms.SMS[j],!RetVal,true);
1005 printf("\n"); 1020 printf("\n");
1006 } 1021 }
1007 } 1022 }
1008 if (!RetVal) { 1023 if (!RetVal) {
1009 GSM_FreeMultiPartSMSInfo(&SMSInfo); 1024 GSM_FreeMultiPartSMSInfo(&SMSInfo);
1010 return; 1025 return;
1011 } 1026 }
1012 1027
1013 if (SMSInfo.Unknown) printmsg("Some details were ignored (unknown or not implemented in decoding functions)\n\n"); 1028 if (SMSInfo.Unknown) printmsg("Some details were ignored (unknown or not implemented in decoding functions)\n\n");
1014 1029
1015 for (i=0;i<SMSInfo.EntriesNum;i++) { 1030 for (i=0;i<SMSInfo.EntriesNum;i++) {
1016 switch (SMSInfo.Entries[i].ID) { 1031 switch (SMSInfo.Entries[i].ID) {
1017 case SMS_NokiaRingtone: 1032 case SMS_NokiaRingtone:
1018 printmsg("Ringtone \"%s\"\n",DecodeUnicodeConsole(SMSInfo.Entries[i].Ringtone->Name)); 1033 printmsg("Ringtone \"%s\"\n",DecodeUnicodeConsole(SMSInfo.Entries[i].Ringtone->Name));
1019 saverttl(stdout,SMSInfo.Entries[i].Ringtone); 1034 saverttl(stdout,SMSInfo.Entries[i].Ringtone);
1020 printf("\n"); 1035 printf("\n");
1021 if (s.Phone.Functions->PlayTone!=NOTSUPPORTED && 1036 if (s.Phone.Functions->PlayTone!=NOTSUPPORTED &&
1022 s.Phone.Functions->PlayTone!=NOTIMPLEMENTED) { 1037 s.Phone.Functions->PlayTone!=NOTIMPLEMENTED) {
1023 if (answer_yes("Do you want to play it")) GSM_PlayRingtone(*SMSInfo.Entries[i].Ringtone); 1038 if (answer_yes("Do you want to play it")) GSM_PlayRingtone(*SMSInfo.Entries[i].Ringtone);
1024 } 1039 }
1025 break; 1040 break;
1026 case SMS_NokiaCallerLogo: 1041 case SMS_NokiaCallerLogo:
1027 printmsg("Caller logo\n\n"); 1042 printmsg("Caller logo\n\n");
1028 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]); 1043 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]);
1029 break; 1044 break;
1030 case SMS_NokiaOperatorLogo: 1045 case SMS_NokiaOperatorLogo:
1031 printmsg("Operator logo for %s network (%s, %s)\n\n", 1046 printmsg("Operator logo for %s network (%s, %s)\n\n",
1032 SMSInfo.Entries[i].Bitmap->Bitmap[0].NetworkCode, 1047 SMSInfo.Entries[i].Bitmap->Bitmap[0].NetworkCode,
1033 DecodeUnicodeConsole(GSM_GetNetworkName(SMSInfo.Entries[i].Bitmap->Bitmap[0].NetworkCode)), 1048 DecodeUnicodeConsole(GSM_GetNetworkName(SMSInfo.Entries[i].Bitmap->Bitmap[0].NetworkCode)),
1034 DecodeUnicodeConsole(GSM_GetCountryName(SMSInfo.Entries[i].Bitmap->Bitmap[0].NetworkCode))); 1049 DecodeUnicodeConsole(GSM_GetCountryName(SMSInfo.Entries[i].Bitmap->Bitmap[0].NetworkCode)));
1035 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]); 1050 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]);
1036 break; 1051 break;
1037 case SMS_NokiaScreenSaverLong: 1052 case SMS_NokiaScreenSaverLong:
1038 printmsg("Screen saver\n"); 1053 printmsg("Screen saver\n");
1039 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]); 1054 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]);
1040 break; 1055 break;
1041 case SMS_NokiaPictureImageLong: 1056 case SMS_NokiaPictureImageLong:
1042 printmsg("Picture Image\n"); 1057 printmsg("Picture Image\n");
1043 if (UnicodeLength(SMSInfo.Entries[i].Bitmap->Bitmap[0].Text)!=0) printmsg("Text: \"%s\"\n\n",DecodeUnicodeConsole(SMSInfo.Entries[i].Bitmap->Bitmap[0].Text)); 1058 if (UnicodeLength(SMSInfo.Entries[i].Bitmap->Bitmap[0].Text)!=0) printmsg("Text: \"%s\"\n\n",DecodeUnicodeConsole(SMSInfo.Entries[i].Bitmap->Bitmap[0].Text));
1044 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]); 1059 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]);
1045 break; 1060 break;
1046 case SMS_NokiaProfileLong: 1061 case SMS_NokiaProfileLong:
1047 printmsg("Profile\n"); 1062 printmsg("Profile\n");
1048 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]); 1063 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]);
1049 break; 1064 break;
1050 case SMS_ConcatenatedTextLong: 1065 case SMS_ConcatenatedTextLong:
1051 case SMS_ConcatenatedAutoTextLong: 1066 case SMS_ConcatenatedAutoTextLong:
1052 case SMS_ConcatenatedTextLong16bit: 1067 case SMS_ConcatenatedTextLong16bit:
1053 case SMS_ConcatenatedAutoTextLong16bit: 1068 case SMS_ConcatenatedAutoTextLong16bit:
1054 printmsg("%s\n",DecodeUnicodeConsole(SMSInfo.Entries[i].Buffer)); 1069 printmsg("%s\n",DecodeUnicodeConsole(SMSInfo.Entries[i].Buffer));
1055 break; 1070 break;
1056 case SMS_EMSFixedBitmap: 1071 case SMS_EMSFixedBitmap:
1057 case SMS_EMSVariableBitmap: 1072 case SMS_EMSVariableBitmap:
1058 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]); 1073 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]);
1059 break; 1074 break;
1060 case SMS_EMSAnimation: 1075 case SMS_EMSAnimation:
1061 /* Can't show animation, we show first frame */ 1076 /* Can't show animation, we show first frame */
1062 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]); 1077 GSM_PrintBitmap(stdout,&SMSInfo.Entries[i].Bitmap->Bitmap[0]);
1063 break; 1078 break;
1064 case SMS_EMSPredefinedSound: 1079 case SMS_EMSPredefinedSound:
1065 printmsg("\nEMS sound ID: %i\n",SMSInfo.Entries[i].Number); 1080 printmsg("\nEMS sound ID: %i\n",SMSInfo.Entries[i].Number);
1066 break; 1081 break;
1067 case SMS_EMSPredefinedAnimation: 1082 case SMS_EMSPredefinedAnimation:
1068 printmsg("\nEMS animation ID: %i\n",SMSInfo.Entries[i].Number); 1083 printmsg("\nEMS animation ID: %i\n",SMSInfo.Entries[i].Number);
1069 break; 1084 break;
1070 default: 1085 default:
1071 printf("Error\n"); 1086 printf("Error\n");
1072 break; 1087 break;
1073 } 1088 }
1074 } 1089 }
1075 printf("\n"); 1090 printf("\n");
1076 GSM_FreeMultiPartSMSInfo(&SMSInfo); 1091 GSM_FreeMultiPartSMSInfo(&SMSInfo);
1077} 1092}
1078 1093
1079static void NetworkInfo(int argc, char *argv[]) 1094static void NetworkInfo(int argc, char *argv[])
1080{ 1095{
1081 GSM_NetworkInfo NetInfo; 1096 GSM_NetworkInfo NetInfo;
1082 1097
1083 GSM_Init(true); 1098 GSM_Init(true);
1084 1099
1085 if (Phone->GetNetworkInfo(&s,&NetInfo)==ERR_NONE) { 1100 if (Phone->GetNetworkInfo(&s,&NetInfo)==ERR_NONE) {
1086 printmsg("Network state : "); 1101 printmsg("Network state : ");
1087 switch (NetInfo.State) { 1102 switch (NetInfo.State) {
1088 case GSM_HomeNetwork : printmsg("home network\n"); break; 1103 case GSM_HomeNetwork : printmsg("home network\n"); break;
1089 case GSM_RoamingNetwork : printmsg("roaming network\n"); break; 1104 case GSM_RoamingNetwork : printmsg("roaming network\n"); break;
1090 case GSM_RequestingNetwork : printmsg("requesting network\n"); break; 1105 case GSM_RequestingNetwork : printmsg("requesting network\n"); break;
1091 case GSM_NoNetwork : printmsg("not logged into network\n");break; 1106 case GSM_NoNetwork : printmsg("not logged into network\n");break;
1092 case GSM_RegistrationDenied : printmsg("registration to network denied\n");break; 1107 case GSM_RegistrationDenied : printmsg("registration to network denied\n");break;
1093 case GSM_NetworkStatusUnknown : printmsg("unknown\n"); break; 1108 case GSM_NetworkStatusUnknown : printmsg("unknown\n"); break;
1094 default : printmsg("unknown\n"); 1109 default : printmsg("unknown\n");
1095 } 1110 }
1096 if (NetInfo.State == GSM_HomeNetwork || NetInfo.State == GSM_RoamingNetwork) { 1111 if (NetInfo.State == GSM_HomeNetwork || NetInfo.State == GSM_RoamingNetwork) {
1097 printmsg("Network : %s (%s",NetInfo.NetworkCode,DecodeUnicodeConsole(GSM_GetNetworkName(NetInfo.NetworkCode))); 1112 printmsg("Network : %s (%s",NetInfo.NetworkCode,DecodeUnicodeConsole(GSM_GetNetworkName(NetInfo.NetworkCode)));
1098 printmsg(", %s)", DecodeUnicodeConsole(GSM_GetCountryName(NetInfo.NetworkCode))); 1113 printmsg(", %s)", DecodeUnicodeConsole(GSM_GetCountryName(NetInfo.NetworkCode)));
1099 printmsg(", LAC %s, CellID %s\n", NetInfo.LAC,NetInfo.CID); 1114 printmsg(", LAC %s, CellID %s\n", NetInfo.LAC,NetInfo.CID);
1100 if (NetInfo.NetworkName[0] != 0x00 || NetInfo.NetworkName[1] != 0x00) { 1115 if (NetInfo.NetworkName[0] != 0x00 || NetInfo.NetworkName[1] != 0x00) {
1101 printmsg("Name in phone : \"%s\"\n",DecodeUnicodeConsole(NetInfo.NetworkName)); 1116 printmsg("Name in phone : \"%s\"\n",DecodeUnicodeConsole(NetInfo.NetworkName));
1102 } 1117 }
1103 } 1118 }
1104 } 1119 }
1105 GSM_Terminate(); 1120 GSM_Terminate();
1106} 1121}
1107 1122
1108static void IncomingSMS(char *Device, GSM_SMSMessage sms) 1123static void IncomingSMS(char *Device, GSM_SMSMessage sms)
1109{ 1124{
1110 GSM_MultiSMSMessage SMS; 1125 GSM_MultiSMSMessage SMS;
1111 1126
1112 printmsg("SMS message received\n"); 1127 printmsg("SMS message received\n");
1113 SMS.Number = 1; 1128 SMS.Number = 1;
1114 memcpy(&SMS.SMS[0],&sms,sizeof(GSM_SMSMessage)); 1129 memcpy(&SMS.SMS[0],&sms,sizeof(GSM_SMSMessage));
1115 displaymultismsinfo(SMS,false,false); 1130 displaymultismsinfo(SMS,false,false);
1116} 1131}
1117 1132
1118static void IncomingCB(char *Device, GSM_CBMessage CB) 1133static void IncomingCB(char *Device, GSM_CBMessage CB)
1119{ 1134{
1120 printmsg("CB message received\n"); 1135 printmsg("CB message received\n");
1121 printmsg("Channel %i, text \"%s\"\n",CB.Channel,DecodeUnicodeConsole(CB.Text)); 1136 printmsg("Channel %i, text \"%s\"\n",CB.Channel,DecodeUnicodeConsole(CB.Text));
1122} 1137}
1123 1138
1124static void IncomingCall(char *Device, GSM_Call call) 1139static void IncomingCall(char *Device, GSM_Call call)
1125{ 1140{
1126 printmsg("Call info : "); 1141 printmsg("Call info : ");
1127 if (call.CallIDAvailable) printmsg("ID %i, ",call.CallID); 1142 if (call.CallIDAvailable) printmsg("ID %i, ",call.CallID);
1128 switch(call.Status) { 1143 switch(call.Status) {
1129 case GSM_CALL_IncomingCall : printmsg("incoming call from \"%s\"\n",DecodeUnicodeConsole(call.PhoneNumber)); break; 1144 case GSM_CALL_IncomingCall : printmsg("incoming call from \"%s\"\n",DecodeUnicodeConsole(call.PhoneNumber)); break;
1130 case GSM_CALL_OutgoingCall : printmsg("outgoing call to \"%s\"\n",DecodeUnicodeConsole(call.PhoneNumber)); break; 1145 case GSM_CALL_OutgoingCall : printmsg("outgoing call to \"%s\"\n",DecodeUnicodeConsole(call.PhoneNumber)); break;
1131 case GSM_CALL_CallStart : printmsg("call started\n"); break; 1146 case GSM_CALL_CallStart : printmsg("call started\n"); break;
1132 case GSM_CALL_CallEnd : printmsg("end of call (unknown side)\n"); break; 1147 case GSM_CALL_CallEnd : printmsg("end of call (unknown side)\n"); break;
1133 case GSM_CALL_CallLocalEnd : printmsg("call end from our side\n"); break; 1148 case GSM_CALL_CallLocalEnd : printmsg("call end from our side\n"); break;
1134 case GSM_CALL_CallRemoteEnd : printmsg("call end from remote side (code %i)\n",call.StatusCode); break; 1149 case GSM_CALL_CallRemoteEnd : printmsg("call end from remote side (code %i)\n",call.StatusCode); break;
1135 case GSM_CALL_CallEstablished : printmsg("call established. Waiting for answer\n"); break; 1150 case GSM_CALL_CallEstablished : printmsg("call established. Waiting for answer\n"); break;
1136 case GSM_CALL_CallHeld : printmsg("call held\n"); break; 1151 case GSM_CALL_CallHeld : printmsg("call held\n"); break;
1137 case GSM_CALL_CallResumed : printmsg("call resumed\n"); break; 1152 case GSM_CALL_CallResumed : printmsg("call resumed\n"); break;
1138 case GSM_CALL_CallSwitched : printmsg("call switched\n"); break; 1153 case GSM_CALL_CallSwitched : printmsg("call switched\n"); break;
1139 } 1154 }
1140} 1155}
1141 1156
1142static void IncomingUSSD(char *Device, char *Buffer) 1157static void IncomingUSSD(char *Device, char *Buffer)
1143{ 1158{
1144 printmsg("Service reply: \"%s\"\n",DecodeUnicodeConsole(Buffer)); 1159 printmsg("Service reply: \"%s\"\n",DecodeUnicodeConsole(Buffer));
1145} 1160}
1146 1161
1147 #define CHECKMEMORYSTATUS(x, m, a1, b1) { \ 1162 #define CHECKMEMORYSTATUS(x, m, a1, b1) { \
1148 x.MemoryType=m; \ 1163 x.MemoryType=m; \
1149 if (Phone->GetMemoryStatus(&s, &x) == ERR_NONE) \ 1164 if (Phone->GetMemoryStatus(&s, &x) == ERR_NONE) \
1150 printmsg("%s %03d, %s %03d\n", a1, x.MemoryUsed, b1, x.MemoryFree);\ 1165 printmsg("%s %03d, %s %03d\n", a1, x.MemoryUsed, b1, x.MemoryFree);\
1151} 1166}
1152 1167
1153static void Monitor(int argc, char *argv[]) 1168static void Monitor(int argc, char *argv[])
1154{ 1169{
1155 GSM_MemoryStatusMemStatus; 1170 GSM_MemoryStatusMemStatus;
1156 GSM_SMSMemoryStatusSMSStatus; 1171 GSM_SMSMemoryStatusSMSStatus;
1157 GSM_ToDoStatus ToDoStatus; 1172 GSM_ToDoStatus ToDoStatus;
1158 GSM_CalendarStatusCalendarStatus; 1173 GSM_CalendarStatusCalendarStatus;
1159 GSM_NetworkInfo NetInfo; 1174 GSM_NetworkInfo NetInfo;
1160 GSM_BatteryCharge BatteryCharge; 1175 GSM_BatteryCharge BatteryCharge;
1161 GSM_SignalQuality SignalQuality; 1176 GSM_SignalQuality SignalQuality;
1162 int count = -1; 1177 int count = -1;
1163 1178
1164 if (argc >= 3) { 1179 if (argc >= 3) {
1165 count = atoi(argv[2]); 1180 count = atoi(argv[2]);
1166 if (count <= 0) count = -1; 1181 if (count <= 0) count = -1;
1167 } 1182 }
1168 1183
1169 signal(SIGINT, interrupt); 1184 signal(SIGINT, interrupt);
1170 printmsgerr("Press Ctrl+C to break...\n"); 1185 printmsgerr("Press Ctrl+C to break...\n");
1171 printmsg("Entering monitor mode...\n\n"); 1186 printmsg("Entering monitor mode...\n\n");
1172 1187
1173 GSM_Init(true); 1188 GSM_Init(true);
1174 1189
1175 s.User.IncomingSMS = IncomingSMS; 1190 s.User.IncomingSMS = IncomingSMS;
1176 s.User.IncomingCB = IncomingCB; 1191 s.User.IncomingCB = IncomingCB;
1177 s.User.IncomingCall = IncomingCall; 1192 s.User.IncomingCall = IncomingCall;
1178 s.User.IncomingUSSD = IncomingUSSD; 1193 s.User.IncomingUSSD = IncomingUSSD;
1179 1194
1180 error=Phone->SetIncomingSMS (&s,true); 1195 error=Phone->SetIncomingSMS (&s,true);
1181 printmsg("Enabling info about incoming SMS : %s\n",print_error(error,NULL,s.msg)); 1196 printmsg("Enabling info about incoming SMS : %s\n",print_error(error,NULL,s.msg));
1182 error=Phone->SetIncomingCB (&s,true); 1197 error=Phone->SetIncomingCB (&s,true);
1183 printmsg("Enabling info about incoming CB : %s\n",print_error(error,NULL,s.msg)); 1198 printmsg("Enabling info about incoming CB : %s\n",print_error(error,NULL,s.msg));
1184 error=Phone->SetIncomingCall (&s,true); 1199 error=Phone->SetIncomingCall (&s,true);
1185 printmsg("Enabling info about calls : %s\n",print_error(error,NULL,s.msg)); 1200 printmsg("Enabling info about calls : %s\n",print_error(error,NULL,s.msg));
1186 error=Phone->SetIncomingUSSD (&s,true); 1201 error=Phone->SetIncomingUSSD (&s,true);
1187 printmsg("Enabling info about USSD : %s\n\n",print_error(error,NULL,s.msg)); 1202 printmsg("Enabling info about USSD : %s\n\n",print_error(error,NULL,s.msg));
1188 1203
1189 while (!gshutdown && count != 0) { 1204 while (!gshutdown && count != 0) {
1190 if (count > 0) count--; 1205 if (count > 0) count--;
1191 CHECKMEMORYSTATUS(MemStatus,MEM_SM,"SIM phonebook : Used","Free"); 1206 CHECKMEMORYSTATUS(MemStatus,MEM_SM,"SIM phonebook : Used","Free");
1192 if (gshutdown) break; 1207 if (gshutdown) break;
1193 CHECKMEMORYSTATUS(MemStatus,MEM_DC,"Dialled numbers : Used","Free"); 1208 CHECKMEMORYSTATUS(MemStatus,MEM_DC,"Dialled numbers : Used","Free");
1194 if (gshutdown) break; 1209 if (gshutdown) break;
1195 CHECKMEMORYSTATUS(MemStatus,MEM_RC,"Received numbers : Used","Free"); 1210 CHECKMEMORYSTATUS(MemStatus,MEM_RC,"Received numbers : Used","Free");
1196 if (gshutdown) break; 1211 if (gshutdown) break;
1197 CHECKMEMORYSTATUS(MemStatus,MEM_MC,"Missed numbers : Used","Free"); 1212 CHECKMEMORYSTATUS(MemStatus,MEM_MC,"Missed numbers : Used","Free");
1198 if (gshutdown) break; 1213 if (gshutdown) break;
1199 CHECKMEMORYSTATUS(MemStatus,MEM_ON,"Own numbers : Used","Free"); 1214 CHECKMEMORYSTATUS(MemStatus,MEM_ON,"Own numbers : Used","Free");
1200 if (gshutdown) break; 1215 if (gshutdown) break;
1201 CHECKMEMORYSTATUS(MemStatus,MEM_ME,"Phone phonebook : Used","Free"); 1216 CHECKMEMORYSTATUS(MemStatus,MEM_ME,"Phone phonebook : Used","Free");
1202 if (gshutdown) break; 1217 if (gshutdown) break;
1203 if (Phone->GetToDoStatus(&s, &ToDoStatus) == ERR_NONE) { 1218 if (Phone->GetToDoStatus(&s, &ToDoStatus) == ERR_NONE) {
1204 printmsg("ToDos : Used %d\n", ToDoStatus.Used); 1219 printmsg("ToDos : Used %d\n", ToDoStatus.Used);
1205 } 1220 }
1206 if (gshutdown) break; 1221 if (gshutdown) break;
1207 if (Phone->GetCalendarStatus(&s, &CalendarStatus) == ERR_NONE) { 1222 if (Phone->GetCalendarStatus(&s, &CalendarStatus) == ERR_NONE) {
1208 printmsg("Calendar : Used %d\n", CalendarStatus.Used); 1223 printmsg("Calendar : Used %d\n", CalendarStatus.Used);
1209 } 1224 }
1210 if (gshutdown) break; 1225 if (gshutdown) break;
1211 if (Phone->GetBatteryCharge(&s,&BatteryCharge)==ERR_NONE) { 1226 if (Phone->GetBatteryCharge(&s,&BatteryCharge)==ERR_NONE) {
1212 if (BatteryCharge.BatteryPercent != -1) printmsg("Battery level : %i percent\n", BatteryCharge.BatteryPercent); 1227 if (BatteryCharge.BatteryPercent != -1) printmsg("Battery level : %i percent\n", BatteryCharge.BatteryPercent);
1213 if (BatteryCharge.ChargeState != 0) { 1228 if (BatteryCharge.ChargeState != 0) {
1214 printmsg("Charge state : "); 1229 printmsg("Charge state : ");
1215 switch (BatteryCharge.ChargeState) { 1230 switch (BatteryCharge.ChargeState) {
1216 case GSM_BatteryPowered: 1231 case GSM_BatteryPowered:
1217 printmsg("powered from battery"); 1232 printmsg("powered from battery");
1218 break; 1233 break;
1219 case GSM_BatteryConnected: 1234 case GSM_BatteryConnected:
1220 printmsg("battery connected, but not powered from battery"); 1235 printmsg("battery connected, but not powered from battery");
1221 break; 1236 break;
1222 case GSM_BatteryNotConnected: 1237 case GSM_BatteryNotConnected:
1223 printmsg("battery not connected"); 1238 printmsg("battery not connected");
1224 break; 1239 break;
1225 case GSM_PowerFault: 1240 case GSM_PowerFault:
1226 printmsg("detected power failure"); 1241 printmsg("detected power failure");
1227 break; 1242 break;
1228 default: 1243 default:
1229 printmsg("unknown"); 1244 printmsg("unknown");
1230 break; 1245 break;
1231 } 1246 }
1232 printf("\n"); 1247 printf("\n");
1233 } 1248 }
1234 } 1249 }
1235 if (gshutdown) break; 1250 if (gshutdown) break;
1236 if (Phone->GetSignalQuality(&s,&SignalQuality)==ERR_NONE) { 1251 if (Phone->GetSignalQuality(&s,&SignalQuality)==ERR_NONE) {
1237 if (SignalQuality.SignalStrength != -1) printmsg("Signal strength : %i dBm\n", SignalQuality.SignalStrength); 1252 if (SignalQuality.SignalStrength != -1) printmsg("Signal strength : %i dBm\n", SignalQuality.SignalStrength);
1238 if (SignalQuality.SignalPercent != -1) printmsg("Network level : %i percent\n", SignalQuality.SignalPercent); 1253 if (SignalQuality.SignalPercent != -1) printmsg("Network level : %i percent\n", SignalQuality.SignalPercent);
1239 if (SignalQuality.BitErrorRate != -1) printmsg("Bit error rate : %i percent\n", SignalQuality.BitErrorRate); 1254 if (SignalQuality.BitErrorRate != -1) printmsg("Bit error rate : %i percent\n", SignalQuality.BitErrorRate);
1240 } 1255 }
1241 if (gshutdown) break; 1256 if (gshutdown) break;
1242 if (Phone->GetSMSStatus(&s,&SMSStatus)==ERR_NONE) { 1257 if (Phone->GetSMSStatus(&s,&SMSStatus)==ERR_NONE) {
1243 if (SMSStatus.SIMSize > 0) { 1258 if (SMSStatus.SIMSize > 0) {
1244 printmsg("SIM SMS status : %i used, %i unread, %i locations\n", 1259 printmsg("SIM SMS status : %i used, %i unread, %i locations\n",
1245 SMSStatus.SIMUsed, 1260 SMSStatus.SIMUsed,
1246 SMSStatus.SIMUnRead, 1261 SMSStatus.SIMUnRead,
1247 SMSStatus.SIMSize); 1262 SMSStatus.SIMSize);
1248 } 1263 }
1249 1264
1250 if (SMSStatus.PhoneSize > 0) { 1265 if (SMSStatus.PhoneSize > 0) {
1251 printmsg("Phone SMS status : %i used, %i unread, %i locations", 1266 printmsg("Phone SMS status : %i used, %i unread, %i locations",
1252 SMSStatus.PhoneUsed, 1267 SMSStatus.PhoneUsed,
1253 SMSStatus.PhoneUnRead, 1268 SMSStatus.PhoneUnRead,
1254 SMSStatus.PhoneSize); 1269 SMSStatus.PhoneSize);
1255 if (SMSStatus.TemplatesUsed!=0) printmsg(", %i templates", SMSStatus.TemplatesUsed); 1270 if (SMSStatus.TemplatesUsed!=0) printmsg(", %i templates", SMSStatus.TemplatesUsed);
1256 printf("\n"); 1271 printf("\n");
1257 } 1272 }
1258 } 1273 }
1259 if (gshutdown) break; 1274 if (gshutdown) break;
1260 if (Phone->GetNetworkInfo(&s,&NetInfo)==ERR_NONE) { 1275 if (Phone->GetNetworkInfo(&s,&NetInfo)==ERR_NONE) {
1261 printmsg("Network state : "); 1276 printmsg("Network state : ");
1262 switch (NetInfo.State) { 1277 switch (NetInfo.State) {
1263 case GSM_HomeNetwork : printmsg("home network\n"); break; 1278 case GSM_HomeNetwork : printmsg("home network\n"); break;
1264 case GSM_RoamingNetwork : printmsg("roaming network\n"); break; 1279 case GSM_RoamingNetwork : printmsg("roaming network\n"); break;
1265 case GSM_RequestingNetwork : printmsg("requesting network\n"); break; 1280 case GSM_RequestingNetwork : printmsg("requesting network\n"); break;
1266 case GSM_NoNetwork : printmsg("not logged into network\n"); break; 1281 case GSM_NoNetwork : printmsg("not logged into network\n"); break;
1267 case GSM_RegistrationDenied : printmsg("registration to network denied\n");break; 1282 case GSM_RegistrationDenied : printmsg("registration to network denied\n");break;
1268 case GSM_NetworkStatusUnknown : printmsg("unknown\n"); break; 1283 case GSM_NetworkStatusUnknown : printmsg("unknown\n"); break;
1269 default : printmsg("unknown\n"); 1284 default : printmsg("unknown\n");
1270 } 1285 }
1271 if (NetInfo.State == GSM_HomeNetwork || NetInfo.State == GSM_RoamingNetwork) { 1286 if (NetInfo.State == GSM_HomeNetwork || NetInfo.State == GSM_RoamingNetwork) {
1272 printmsg("Network : %s (%s",NetInfo.NetworkCode,DecodeUnicodeConsole(GSM_GetNetworkName(NetInfo.NetworkCode))); 1287 printmsg("Network : %s (%s",NetInfo.NetworkCode,DecodeUnicodeConsole(GSM_GetNetworkName(NetInfo.NetworkCode)));
1273 printmsg(", %s)", DecodeUnicodeConsole(GSM_GetCountryName(NetInfo.NetworkCode))); 1288 printmsg(", %s)", DecodeUnicodeConsole(GSM_GetCountryName(NetInfo.NetworkCode)));
1274 printmsg(", LAC %s, CID %s\n", NetInfo.LAC,NetInfo.CID); 1289 printmsg(", LAC %s, CID %s\n", NetInfo.LAC,NetInfo.CID);
1275 if (NetInfo.NetworkName[0] != 0x00 || NetInfo.NetworkName[1] != 0x00) { 1290 if (NetInfo.NetworkName[0] != 0x00 || NetInfo.NetworkName[1] != 0x00) {
1276 printmsg("Name in phone : \"%s\"\n",DecodeUnicodeConsole(NetInfo.NetworkName)); 1291 printmsg("Name in phone : \"%s\"\n",DecodeUnicodeConsole(NetInfo.NetworkName));
1277 } 1292 }
1278 } 1293 }
1279 } 1294 }
1280 printf("\n"); 1295 printf("\n");
1281 } 1296 }
1282 1297
1283 printmsg("Leaving monitor mode...\n"); 1298 printmsg("Leaving monitor mode...\n");
1284 1299
1285 GSM_Terminate(); 1300 GSM_Terminate();
1286} 1301}
1287 1302
1303static void IncomingUSSD2(char *Device, char *Buffer)
1304{
1305 printmsg("Service reply: \"%s\"\n",DecodeUnicodeConsole(Buffer));
1306
1307 gshutdown = true;
1308}
1309
1288static void GetUSSD(int argc, char *argv[]) 1310static void GetUSSD(int argc, char *argv[])
1289{ 1311{
1290 GSM_Init(true); 1312 GSM_Init(true);
1291 1313
1292 signal(SIGINT, interrupt); 1314 signal(SIGINT, interrupt);
1293 printmsgerr("Press Ctrl+C to break...\n"); 1315 printmsgerr("Press Ctrl+C to break...\n");
1294 1316
1295 s.User.IncomingUSSD = IncomingUSSD; 1317 s.User.IncomingUSSD = IncomingUSSD2;
1296 1318
1297 error=Phone->SetIncomingUSSD(&s,true); 1319 error=Phone->SetIncomingUSSD(&s,true);
1298 Print_Error(error); 1320 Print_Error(error);
1299 1321
1300 error=Phone->DialVoice(&s, argv[2], GSM_CALL_DefaultNumberPresence); 1322 error=Phone->DialVoice(&s, argv[2], GSM_CALL_DefaultNumberPresence);
1301 Print_Error(error); 1323 Print_Error(error);
1302 1324
1303 while (!gshutdown) GSM_ReadDevice(&s,true); 1325 while (!gshutdown) GSM_ReadDevice(&s,true);
1304 1326
1305 GSM_Terminate(); 1327 GSM_Terminate();
1306} 1328}
1307 1329
1308static void GetSMSC(int argc, char *argv[]) 1330static void GetSMSC(int argc, char *argv[])
1309{ 1331{
1310 GSM_SMSC smsc; 1332 GSM_SMSC smsc;
1311 int start, stop; 1333 int start, stop;
1312 1334
1313 GetStartStop(&start, &stop, 2, argc, argv); 1335 GetStartStop(&start, &stop, 2, argc, argv);
1314 1336
1315 GSM_Init(true); 1337 GSM_Init(true);
1316 1338
1317 for (i=start;i<=stop;i++) { 1339 for (i=start;i<=stop;i++) {
1318 smsc.Location=i; 1340 smsc.Location=i;
1319 1341
1320 error=Phone->GetSMSC(&s, &smsc); 1342 error=Phone->GetSMSC(&s, &smsc);
1321 Print_Error(error); 1343 Print_Error(error);
1322 1344
1323 if (!strcmp(DecodeUnicodeConsole(smsc.Name),"")) { 1345 if (!strcmp(DecodeUnicodeConsole(smsc.Name),"")) {
1324 printmsg("%i. Set %i\n",smsc.Location, smsc.Location); 1346 printmsg("%i. Set %i\n",smsc.Location, smsc.Location);
1325 } else { 1347 } else {
1326 printmsg("%i. \"%s\"\n",smsc.Location, DecodeUnicodeConsole(smsc.Name)); 1348 printmsg("%i. \"%s\"\n",smsc.Location, DecodeUnicodeConsole(smsc.Name));
1327 } 1349 }
1328 printmsg("Number : \"%s\"\n",DecodeUnicodeConsole(smsc.Number)); 1350 printmsg("Number : \"%s\"\n",DecodeUnicodeConsole(smsc.Number));
1329 printmsg("Default number : \"%s\"\n",DecodeUnicodeConsole(smsc.DefaultNumber)); 1351 printmsg("Default number : \"%s\"\n",DecodeUnicodeConsole(smsc.DefaultNumber));
1330 1352
1331 printmsg("Format : "); 1353 printmsg("Format : ");
1332 switch (smsc.Format) { 1354 switch (smsc.Format) {
1333 case SMS_FORMAT_Text : printmsg("Text");break; 1355 case SMS_FORMAT_Text : printmsg("Text");break;
1334 case SMS_FORMAT_Fax : printmsg("Fax");break; 1356 case SMS_FORMAT_Fax : printmsg("Fax");break;
1335 case SMS_FORMAT_Email : printmsg("Email");break; 1357 case SMS_FORMAT_Email : printmsg("Email");break;
1336 case SMS_FORMAT_Pager : printmsg("Pager");break; 1358 case SMS_FORMAT_Pager : printmsg("Pager");break;
1337 } 1359 }
1338 printf("\n"); 1360 printf("\n");
1339 1361
1340 printmsg("Validity : "); 1362 printmsg("Validity : ");
1341 switch (smsc.Validity.Relative) { 1363 switch (smsc.Validity.Relative) {
1342 case SMS_VALID_1_Hour : printmsg("1 hour"); break; 1364 case SMS_VALID_1_Hour : printmsg("1 hour"); break;
1343 case SMS_VALID_6_Hours : printmsg("6 hours"); break; 1365 case SMS_VALID_6_Hours : printmsg("6 hours"); break;
1344 case SMS_VALID_1_Day : printmsg("24 hours"); break; 1366 case SMS_VALID_1_Day : printmsg("24 hours"); break;
1345 case SMS_VALID_3_Days : printmsg("72 hours"); break; 1367 case SMS_VALID_3_Days : printmsg("72 hours"); break;
1346 case SMS_VALID_1_Week : printmsg("1 week"); break; 1368 case SMS_VALID_1_Week : printmsg("1 week"); break;
1347 case SMS_VALID_Max_Time: printmsg("Maximum time"); break; 1369 case SMS_VALID_Max_Time: printmsg("Maximum time"); break;
1348 default : printmsg("Unknown"); 1370 default :
1371 if (smsc.Validity.Relative >= 0 && smsc.Validity.Relative <= 143) {
1372 printmsg("%i minutes",(smsc.Validity.Relative+1)*5);
1373 } else if (smsc.Validity.Relative >= 144 && smsc.Validity.Relative <= 167) {
1374 printmsg("%i minutes",12*60 + (smsc.Validity.Relative-143)*30);
1375 } else if (smsc.Validity.Relative >= 168 && smsc.Validity.Relative <= 196) {
1376 printmsg("%i days",smsc.Validity.Relative-166);
1377 } else if (smsc.Validity.Relative >= 197 && smsc.Validity.Relative <= 255) {
1378 printmsg("%i weeks",smsc.Validity.Relative-192);
1379 }
1349 } 1380 }
1350 printf("\n"); 1381 printf("\n");
1351 } 1382 }
1352 1383
1353 GSM_Terminate(); 1384 GSM_Terminate();
1354} 1385}
1355 1386
1356static void GetSMS(int argc, char *argv[]) 1387static void GetSMS(int argc, char *argv[])
1357{ 1388{
1358 GSM_MultiSMSMessagesms; 1389 GSM_MultiSMSMessagesms;
1359 GSM_SMSFolders folders; 1390 GSM_SMSFolders folders;
1360 int start, stop; 1391 int start, stop;
1361 int j; 1392 int j;
1362 1393
1363 GetStartStop(&start, &stop, 3, argc, argv); 1394 GetStartStop(&start, &stop, 3, argc, argv);
1364 1395
1365 GSM_Init(true); 1396 GSM_Init(true);
1366 1397
1367 error=Phone->GetSMSFolders(&s, &folders); 1398 error=Phone->GetSMSFolders(&s, &folders);
1368 Print_Error(error); 1399 Print_Error(error);
1369 1400
1370 for (j = start; j <= stop; j++) { 1401 for (j = start; j <= stop; j++) {
1371 sms.SMS[0].Folder= atoi(argv[2]); 1402 sms.SMS[0].Folder= atoi(argv[2]);
1372 sms.SMS[0].Location= j; 1403 sms.SMS[0].Location= j;
1373 error=Phone->GetSMS(&s, &sms); 1404 error=Phone->GetSMS(&s, &sms);
1374 switch (error) { 1405 switch (error) {
1375 case ERR_EMPTY: 1406 case ERR_EMPTY:
1376 printmsg("Location %i\n",sms.SMS[0].Location); 1407 printmsg("Location %i\n",sms.SMS[0].Location);
1377 printmsg("Empty\n"); 1408 printmsg("Empty\n");
1378 break; 1409 break;
1379 default: 1410 default:
1380 Print_Error(error); 1411 Print_Error(error);
1381 printmsg("Location %i, folder \"%s\"",sms.SMS[0].Location,DecodeUnicodeConsole(folders.Folder[sms.SMS[0].Folder-1].Name)); 1412 printmsg("Location %i, folder \"%s\"",sms.SMS[0].Location,DecodeUnicodeConsole(folders.Folder[sms.SMS[0].Folder-1].Name));
1382 switch(sms.SMS[0].Memory) { 1413 switch(sms.SMS[0].Memory) {
1383 case MEM_SM: printmsg(", SIM memory"); break; 1414 case MEM_SM: printmsg(", SIM memory"); break;
1384 case MEM_ME: printmsg(", phone memory"); break; 1415 case MEM_ME: printmsg(", phone memory"); break;
1385 case MEM_MT: printmsg(", phone or SIM memory"); break; 1416 case MEM_MT: printmsg(", phone or SIM memory"); break;
1386 default : break; 1417 default : break;
1387 } 1418 }
1388 if (sms.SMS[0].InboxFolder) printmsg(", Inbox folder"); 1419 if (sms.SMS[0].InboxFolder) printmsg(", Inbox folder");
1389 printf("\n"); 1420 printf("\n");
1390 displaymultismsinfo(sms,false,false); 1421 displaymultismsinfo(sms,false,false);
1391 } 1422 }
1392 } 1423 }
1393 1424
1394 GSM_Terminate(); 1425 GSM_Terminate();
1395} 1426}
1396 1427
1397static void DeleteSMS(int argc, char *argv[]) 1428static void DeleteSMS(int argc, char *argv[])
1398{ 1429{
1399 GSM_SMSMessagesms; 1430 GSM_SMSMessagesms;
1400 int start, stop; 1431 int start, stop;
1401 1432
1402 sms.Folder=atoi(argv[2]); 1433 sms.Folder=atoi(argv[2]);
1403 1434
1404 GetStartStop(&start, &stop, 3, argc, argv); 1435 GetStartStop(&start, &stop, 3, argc, argv);
1405 1436
1406 GSM_Init(true); 1437 GSM_Init(true);
1407 1438
1408 for (i=start;i<=stop;i++) { 1439 for (i=start;i<=stop;i++) {
1409 sms.Folder= 0; 1440 sms.Folder= 0;
1410 sms.Location= i; 1441 sms.Location= i;
1411 error=Phone->DeleteSMS(&s, &sms); 1442 error=Phone->DeleteSMS(&s, &sms);
1412 Print_Error(error); 1443 Print_Error(error);
1413 } 1444 }
1414#ifdef GSM_ENABLE_BEEP 1445#ifdef GSM_ENABLE_BEEP
1415 GSM_PhoneBeep(); 1446 GSM_PhoneBeep();
1416#endif 1447#endif
1417 GSM_Terminate(); 1448 GSM_Terminate();
1418} 1449}
1419 1450
1420static void GetAllSMS(int argc, char *argv[]) 1451static void GetAllSMS(int argc, char *argv[])
1421{ 1452{
1422 GSM_MultiSMSMessage sms; 1453 GSM_MultiSMSMessage sms;
1423 GSM_SMSFolders folders; 1454 GSM_SMSFolders folders;
1424 bool start = true; 1455 bool start = true;
1425 1456
1426 GSM_Init(true); 1457 GSM_Init(true);
1427 1458
1428 error=Phone->GetSMSFolders(&s, &folders); 1459 error=Phone->GetSMSFolders(&s, &folders);
1429 Print_Error(error); 1460 Print_Error(error);
1430 1461
1431 fprintf(stderr,"Reading: ");
1432 while (error == ERR_NONE) { 1462 while (error == ERR_NONE) {
1433 sms.SMS[0].Folder=0x00; 1463 sms.SMS[0].Folder=0x00;
1434 error=Phone->GetNextSMS(&s, &sms, start); 1464 error=Phone->GetNextSMS(&s, &sms, start);
1435 switch (error) { 1465 switch (error) {
1436 case ERR_EMPTY: 1466 case ERR_EMPTY:
1437 break; 1467 break;
1438 default: 1468 default:
1439 Print_Error(error); 1469 Print_Error(error);
1440 printmsg("Location %i, folder \"%s\"",sms.SMS[0].Location,DecodeUnicodeConsole(folders.Folder[sms.SMS[0].Folder-1].Name)); 1470 printmsg("Location %i, folder \"%s\"",sms.SMS[0].Location,DecodeUnicodeConsole(folders.Folder[sms.SMS[0].Folder-1].Name));
1441 switch(sms.SMS[0].Memory) { 1471 switch(sms.SMS[0].Memory) {
1442 case MEM_SM: printmsg(", SIM memory"); break; 1472 case MEM_SM: printmsg(", SIM memory"); break;
1443 case MEM_ME: printmsg(", phone memory"); break; 1473 case MEM_ME: printmsg(", phone memory"); break;
1444 case MEM_MT: printmsg(", phone or SIM memory"); break; 1474 case MEM_MT: printmsg(", phone or SIM memory"); break;
1445 default : break; 1475 default : break;
1446 } 1476 }
1447 if (sms.SMS[0].InboxFolder) printmsg(", Inbox folder"); 1477 if (sms.SMS[0].InboxFolder) printmsg(", Inbox folder");
1448 printf("\n"); 1478 printf("\n");
1449 displaymultismsinfo(sms,false,false); 1479 displaymultismsinfo(sms,false,false);
1450 } 1480 }
1451 fprintf(stderr,"*");
1452 start=false; 1481 start=false;
1453 } 1482 }
1454 fprintf(stderr,"\n"); 1483 fprintf(stderr,"\n");
1455 1484
1456#ifdef GSM_ENABLE_BEEP 1485#ifdef GSM_ENABLE_BEEP
1457 GSM_PhoneBeep(); 1486 GSM_PhoneBeep();
1458#endif 1487#endif
1459 GSM_Terminate(); 1488 GSM_Terminate();
1460} 1489}
1461 1490
1462static void GetEachSMS(int argc, char *argv[]) 1491static void GetEachSMS(int argc, char *argv[])
1463{ 1492{
1464 GSM_MultiSMSMessage*GetSMS[PHONE_MAXSMSINFOLDER],*SortedSMS[PHONE_MAXSMSINFOLDER],sms; 1493 GSM_MultiSMSMessage*GetSMS[PHONE_MAXSMSINFOLDER],*SortedSMS[PHONE_MAXSMSINFOLDER],sms;
1465 int GetSMSNumber = 0,i,j; 1494 int GetSMSNumber = 0,i,j;
1466 GSM_SMSFolders folders; 1495 GSM_SMSFolders folders;
1467 bool start = true, ems = true; 1496 bool start = true, ems = true;
1468 1497
1469 GetSMS[0] = NULL; 1498 GetSMS[0] = NULL;
1470 1499
1471 GSM_Init(true); 1500 GSM_Init(true);
1472 1501
1473 error=Phone->GetSMSFolders(&s, &folders); 1502 error=Phone->GetSMSFolders(&s, &folders);
1474 Print_Error(error); 1503 Print_Error(error);
1475 1504
1476 fprintf(stderr,"Reading: "); 1505 fprintf(stderr,"Reading: ");
1477 while (error == ERR_NONE) { 1506 while (error == ERR_NONE) {
1478 sms.SMS[0].Folder=0x00; 1507 sms.SMS[0].Folder=0x00;
1479 error=Phone->GetNextSMS(&s, &sms, start); 1508 error=Phone->GetNextSMS(&s, &sms, start);
1480 switch (error) { 1509 switch (error) {
1481 case ERR_EMPTY: 1510 case ERR_EMPTY:
1482 break; 1511 break;
1483 default: 1512 default:
1484 Print_Error(error); 1513 Print_Error(error);
1485 GetSMS[GetSMSNumber] = malloc(sizeof(GSM_MultiSMSMessage)); 1514 GetSMS[GetSMSNumber] = malloc(sizeof(GSM_MultiSMSMessage));
1486 if (GetSMS[GetSMSNumber] == NULL) Print_Error(ERR_MOREMEMORY); 1515 if (GetSMS[GetSMSNumber] == NULL) Print_Error(ERR_MOREMEMORY);
1487 GetSMS[GetSMSNumber+1] = NULL; 1516 GetSMS[GetSMSNumber+1] = NULL;
1488 memcpy(GetSMS[GetSMSNumber],&sms,sizeof(GSM_MultiSMSMessage)); 1517 memcpy(GetSMS[GetSMSNumber],&sms,sizeof(GSM_MultiSMSMessage));
1489 GetSMSNumber++; 1518 GetSMSNumber++;
1490 if (GetSMSNumber==PHONE_MAXSMSINFOLDER) { 1519 if (GetSMSNumber==PHONE_MAXSMSINFOLDER) {
1491 fprintf(stderr,"SMS counter overflow\n"); 1520 fprintf(stderr,"SMS counter overflow\n");
1492 return; 1521 return;
1493 } 1522 }
1494 } 1523 }
1495 fprintf(stderr,"*"); 1524 fprintf(stderr,"*");
1496 start=false; 1525 start=false;
1497 } 1526 }
1498 fprintf(stderr,"\n"); 1527 fprintf(stderr,"\n");
1499 1528
1500#ifdef GSM_ENABLE_BEEP 1529#ifdef GSM_ENABLE_BEEP
1501 GSM_PhoneBeep(); 1530 GSM_PhoneBeep();
1502#endif 1531#endif
1503 1532
1504 error = GSM_LinkSMS(GetSMS, SortedSMS, ems); 1533 error = GSM_LinkSMS(GetSMS, SortedSMS, ems);
1505 Print_Error(error); 1534 Print_Error(error);
1506 1535
1507 i=0; 1536 i=0;
1508 while(GetSMS[i] != NULL) { 1537 while(GetSMS[i] != NULL) {
1509 free(GetSMS[i]); 1538 free(GetSMS[i]);
1510 GetSMS[i] = NULL; 1539 GetSMS[i] = NULL;
1511 i++; 1540 i++;
1512 } 1541 }
1513 1542
1514 i=0; 1543 i=0;
1515 while(SortedSMS[i] != NULL) { 1544 while(SortedSMS[i] != NULL) {
1516 for (j=0;j<SortedSMS[i]->Number;j++) { 1545 for (j=0;j<SortedSMS[i]->Number;j++) {
1517 if ((j==0) || (j!=0 && SortedSMS[i]->SMS[j].Location != SortedSMS[i]->SMS[j-1].Location)) { 1546 if ((j==0) || (j!=0 && SortedSMS[i]->SMS[j].Location != SortedSMS[i]->SMS[j-1].Location)) {
1518 printmsg("Location %i, folder \"%s\"",SortedSMS[i]->SMS[j].Location,DecodeUnicodeConsole(folders.Folder[SortedSMS[i]->SMS[j].Folder-1].Name)); 1547 printmsg("Location %i, folder \"%s\"",SortedSMS[i]->SMS[j].Location,DecodeUnicodeConsole(folders.Folder[SortedSMS[i]->SMS[j].Folder-1].Name));
1519 switch(SortedSMS[i]->SMS[j].Memory) { 1548 switch(SortedSMS[i]->SMS[j].Memory) {
1520 case MEM_SM: printmsg(", SIM memory"); break; 1549 case MEM_SM: printmsg(", SIM memory"); break;
1521 case MEM_ME: printmsg(", phone memory"); break; 1550 case MEM_ME: printmsg(", phone memory"); break;
1522 case MEM_MT: printmsg(", phone or SIM memory"); break; 1551 case MEM_MT: printmsg(", phone or SIM memory"); break;
1523 default : break; 1552 default : break;
1524 } 1553 }
1525 if (SortedSMS[i]->SMS[j].InboxFolder) printmsg(", Inbox folder"); 1554 if (SortedSMS[i]->SMS[j].InboxFolder) printmsg(", Inbox folder");
1526 printf("\n"); 1555 printf("\n");
1527 } 1556 }
1528 } 1557 }
1529 displaymultismsinfo(*SortedSMS[i],true,ems); 1558 displaymultismsinfo(*SortedSMS[i],true,ems);
1530 1559
1531 free(SortedSMS[i]); 1560 free(SortedSMS[i]);
1532 SortedSMS[i] = NULL; 1561 SortedSMS[i] = NULL;
1533 i++; 1562 i++;
1534 } 1563 }
1535 1564
1536 GSM_Terminate(); 1565 GSM_Terminate();
1537} 1566}
1538 1567
1539static void GetSMSFolders(int argc, char *argv[]) 1568static void GetSMSFolders(int argc, char *argv[])
1540{ 1569{
1541 GSM_SMSFolders folders; 1570 GSM_SMSFolders folders;
1542 1571
1543 GSM_Init(true); 1572 GSM_Init(true);
1544 1573
1545 error=Phone->GetSMSFolders(&s,&folders); 1574 error=Phone->GetSMSFolders(&s,&folders);
1546 Print_Error(error); 1575 Print_Error(error);
1547 1576
1548 for (i=0;i<folders.Number;i++) { 1577 for (i=0;i<folders.Number;i++) {
1549 printmsg("%i. \"%30s\"",i+1,DecodeUnicodeConsole(folders.Folder[i].Name)); 1578 printmsg("%i. \"%30s\"",i+1,DecodeUnicodeConsole(folders.Folder[i].Name));
1550 switch(folders.Folder[i].Memory) { 1579 switch(folders.Folder[i].Memory) {
1551 case MEM_SM: printmsg(", SIM memory"); break; 1580 case MEM_SM: printmsg(", SIM memory"); break;
1552 case MEM_ME: printmsg(", phone memory"); break; 1581 case MEM_ME: printmsg(", phone memory"); break;
1553 case MEM_MT: printmsg(", phone or SIM memory"); break; 1582 case MEM_MT: printmsg(", phone or SIM memory"); break;
1554 default : break; 1583 default : break;
1555 } 1584 }
1556 if (folders.Folder[i].InboxFolder) printmsg(", Inbox folder"); 1585 if (folders.Folder[i].InboxFolder) printmsg(", Inbox folder");
1557 printf("\n"); 1586 printf("\n");
1558 } 1587 }
1559 1588
1560 GSM_Terminate(); 1589 GSM_Terminate();
1561} 1590}
1562 1591
1563static void GetRingtone(int argc, char *argv[]) 1592static void GetRingtone(int argc, char *argv[])
1564{ 1593{
1565 GSM_Ringtone ringtone; 1594 GSM_Ringtone ringtone;
1566 bool PhoneRingtone = false; 1595 bool PhoneRingtone = false;
1567 1596
1568 if (mystrncasecmp(argv[1],"--getphoneringtone",0)) PhoneRingtone = true; 1597 if (mystrncasecmp(argv[1],"--getphoneringtone",0)) PhoneRingtone = true;
1569 1598
1570 GetStartStop(&ringtone.Location, NULL, 2, argc, argv); 1599 GetStartStop(&ringtone.Location, NULL, 2, argc, argv);
1571 1600
1572 GSM_Init(true); 1601 GSM_Init(true);
1573 1602
1574 ringtone.Format=0; 1603 ringtone.Format=0;
1575 1604
1576 error=Phone->GetRingtone(&s,&ringtone,PhoneRingtone); 1605 error=Phone->GetRingtone(&s,&ringtone,PhoneRingtone);
1577 Print_Error(error); 1606 Print_Error(error);
1578 1607
1579 switch (ringtone.Format) { 1608 switch (ringtone.Format) {
1580 case RING_NOTETONE : printmsg("Smart Messaging");break; 1609 case RING_NOTETONE : printmsg("Smart Messaging");break;
1581 case RING_NOKIABINARY : printmsg("Nokia binary");break; 1610 case RING_NOKIABINARY : printmsg("Nokia binary");break;
1582 case RING_MIDI : printmsg("Midi format");break; 1611 case RING_MIDI : printmsg("MIDI"); break;
1612 case RING_MMF : printmsg("SMAF (MMF)");break;
1583 } 1613 }
1584 printmsg(" format, ringtone \"%s\"\n",DecodeUnicodeConsole(ringtone.Name)); 1614 printmsg(" format, ringtone \"%s\"\n",DecodeUnicodeConsole(ringtone.Name));
1585 1615
1586 if (argc==4) { 1616 if (argc==4) {
1587 error=GSM_SaveRingtoneFile(argv[3], &ringtone); 1617 error=GSM_SaveRingtoneFile(argv[3], &ringtone);
1588 Print_Error(error); 1618 Print_Error(error);
1589 } 1619 }
1590 1620
1591 GSM_Terminate(); 1621 GSM_Terminate();
1592} 1622}
1593 1623
1594static void GetRingtonesList(int argc, char *argv[]) 1624static void GetRingtonesList(int argc, char *argv[])
1595{ 1625{
1596 GSM_AllRingtonesInfo Info; 1626 GSM_AllRingtonesInfo Info;
1597 int i; 1627 int i;
1598 1628
1599 GSM_Init(true); 1629 GSM_Init(true);
1600 1630
1601 error=Phone->GetRingtonesInfo(&s,&Info); 1631 error=Phone->GetRingtonesInfo(&s,&Info);
1602 Print_Error(error); 1632 Print_Error(error);
1603 1633
1604 GSM_Terminate(); 1634 GSM_Terminate();
1605 1635
1606 for (i=0;i<Info.Number;i++) printmsg("%i. \"%s\"\n",i,DecodeUnicodeConsole(Info.Ringtone[i].Name)); 1636 for (i=0;i<Info.Number;i++) printmsg("%i. \"%s\"\n",i,DecodeUnicodeConsole(Info.Ringtone[i].Name));
1607} 1637}
1608 1638
1609static void DialVoice(int argc, char *argv[]) 1639static void DialVoice(int argc, char *argv[])
1610{ 1640{
1611 GSM_CallShowNumber ShowNumber = GSM_CALL_DefaultNumberPresence; 1641 GSM_CallShowNumber ShowNumber = GSM_CALL_DefaultNumberPresence;
1612 1642
1613 if (argc > 3) { 1643 if (argc > 3) {
1614 if (mystrncasecmp(argv[3],"show",0)) { ShowNumber = GSM_CALL_ShowNumber; 1644 if (mystrncasecmp(argv[3],"show",0)) { ShowNumber = GSM_CALL_ShowNumber;
1615 } else if (mystrncasecmp(argv[3],"hide",0)) {ShowNumber = GSM_CALL_HideNumber; 1645 } else if (mystrncasecmp(argv[3],"hide",0)) {ShowNumber = GSM_CALL_HideNumber;
1616 } else { 1646 } else {
1617 printmsg("Unknown parameter (\"%s\")\n",argv[3]); 1647 printmsg("Unknown parameter (\"%s\")\n",argv[3]);
1618 exit(-1); 1648 exit(-1);
1619 } 1649 }
1620 } 1650 }
1621 1651
1622 GSM_Init(true); 1652 GSM_Init(true);
1623 1653
1624 error=Phone->DialVoice(&s, argv[2], ShowNumber); 1654 error=Phone->DialVoice(&s, argv[2], ShowNumber);
1625 Print_Error(error); 1655 Print_Error(error);
1626 1656
1627 GSM_Terminate(); 1657 GSM_Terminate();
1628} 1658}
1629 1659
1630static void CancelCall(int argc, char *argv[]) 1660static void CancelCall(int argc, char *argv[])
1631{ 1661{
1632 GSM_Init(true); 1662 GSM_Init(true);
1633 1663
1634 if (argc>2) { 1664 if (argc>2) {
1635 error=Phone->CancelCall(&s,atoi(argv[2]),false); 1665 error=Phone->CancelCall(&s,atoi(argv[2]),false);
1636 } else { 1666 } else {
1637 error=Phone->CancelCall(&s,0,true); 1667 error=Phone->CancelCall(&s,0,true);
1638 } 1668 }
1639 Print_Error(error); 1669 Print_Error(error);
1640 1670
1641 GSM_Terminate(); 1671 GSM_Terminate();
1642} 1672}
1643 1673
1644static void AnswerCall(int argc, char *argv[]) 1674static void AnswerCall(int argc, char *argv[])
1645{ 1675{
1646 GSM_Init(true); 1676 GSM_Init(true);
1647 1677
1648 if (argc>2) { 1678 if (argc>2) {
1649 error=Phone->AnswerCall(&s,atoi(argv[2]),false); 1679 error=Phone->AnswerCall(&s,atoi(argv[2]),false);
1650 } else { 1680 } else {
1651 error=Phone->AnswerCall(&s,0,true); 1681 error=Phone->AnswerCall(&s,0,true);
1652 } 1682 }
1653 Print_Error(error); 1683 Print_Error(error);
1654 1684
1655 GSM_Terminate(); 1685 GSM_Terminate();
1656} 1686}
1657 1687
1658static void UnholdCall(int argc, char *argv[]) 1688static void UnholdCall(int argc, char *argv[])
1659{ 1689{
1660 GSM_Init(true); 1690 GSM_Init(true);
1661 1691
1662 error=Phone->UnholdCall(&s,atoi(argv[2])); 1692 error=Phone->UnholdCall(&s,atoi(argv[2]));
1663 Print_Error(error); 1693 Print_Error(error);
1664 1694
1665 GSM_Terminate(); 1695 GSM_Terminate();
1666} 1696}
1667 1697
1668static void HoldCall(int argc, char *argv[]) 1698static void HoldCall(int argc, char *argv[])
1669{ 1699{
1670 GSM_Init(true); 1700 GSM_Init(true);
1671 1701
1672 error=Phone->HoldCall(&s,atoi(argv[2])); 1702 error=Phone->HoldCall(&s,atoi(argv[2]));
1673 Print_Error(error); 1703 Print_Error(error);
1674 1704
1675 GSM_Terminate(); 1705 GSM_Terminate();
1676} 1706}
1677 1707
1678static void ConferenceCall(int argc, char *argv[]) 1708static void ConferenceCall(int argc, char *argv[])
1679{ 1709{
1680 GSM_Init(true); 1710 GSM_Init(true);
1681 1711
1682 error=Phone->ConferenceCall(&s,atoi(argv[2])); 1712 error=Phone->ConferenceCall(&s,atoi(argv[2]));
1683 Print_Error(error); 1713 Print_Error(error);
1684 1714
1685 GSM_Terminate(); 1715 GSM_Terminate();
1686} 1716}
1687 1717
1688static void SplitCall(int argc, char *argv[]) 1718static void SplitCall(int argc, char *argv[])
1689{ 1719{
1690 GSM_Init(true); 1720 GSM_Init(true);
1691 1721
1692 error=Phone->SplitCall(&s,atoi(argv[2])); 1722 error=Phone->SplitCall(&s,atoi(argv[2]));
1693 Print_Error(error); 1723 Print_Error(error);
1694 1724
1695 GSM_Terminate(); 1725 GSM_Terminate();
1696} 1726}
1697 1727
1698static void SwitchCall(int argc, char *argv[]) 1728static void SwitchCall(int argc, char *argv[])
1699{ 1729{
1700 GSM_Init(true); 1730 GSM_Init(true);
1701 1731
1702 if (argc > 2) { 1732 if (argc > 2) {
1703 error=Phone->SwitchCall(&s,atoi(argv[2]),false); 1733 error=Phone->SwitchCall(&s,atoi(argv[2]),false);
1704 } else { 1734 } else {
1705 error=Phone->SwitchCall(&s,0,true); 1735 error=Phone->SwitchCall(&s,0,true);
1706 } 1736 }
1707 Print_Error(error); 1737 Print_Error(error);
1708 1738
1709 GSM_Terminate(); 1739 GSM_Terminate();
1710} 1740}
1711 1741
1712static void TransferCall(int argc, char *argv[]) 1742static void TransferCall(int argc, char *argv[])
1713{ 1743{
1714 GSM_Init(true); 1744 GSM_Init(true);
1715 1745
1716 if (argc > 2) { 1746 if (argc > 2) {
1717 error=Phone->TransferCall(&s,atoi(argv[2]),false); 1747 error=Phone->TransferCall(&s,atoi(argv[2]),false);
1718 } else { 1748 } else {
1719 error=Phone->TransferCall(&s,0,true); 1749 error=Phone->TransferCall(&s,0,true);
1720 } 1750 }
1721 Print_Error(error); 1751 Print_Error(error);
1722 1752
1723 GSM_Terminate(); 1753 GSM_Terminate();
1724} 1754}
1725 1755
1726static void AddSMSFolder(int argc, char *argv[]) 1756static void AddSMSFolder(int argc, char *argv[])
1727{ 1757{
1728 unsigned char buffer[200]; 1758 unsigned char buffer[200];
1729 1759
1730 GSM_Init(true); 1760 GSM_Init(true);
1731 1761
1732 EncodeUnicode(buffer,argv[2],strlen(argv[2])); 1762 EncodeUnicode(buffer,argv[2],strlen(argv[2]));
1733 error=Phone->AddSMSFolder(&s,buffer); 1763 error=Phone->AddSMSFolder(&s,buffer);
1734 Print_Error(error); 1764 Print_Error(error);
1735 1765
1736 GSM_Terminate(); 1766 GSM_Terminate();
1737} 1767}
1738 1768
1739static void Reset(int argc, char *argv[]) 1769static void Reset(int argc, char *argv[])
1740{ 1770{
1741 bool hard; 1771 bool hard;
1742 1772
1743 if (mystrncasecmp(argv[2],"SOFT",0)) { hard=false; 1773 if (mystrncasecmp(argv[2],"SOFT",0)) { hard=false;
1744 } else if (mystrncasecmp(argv[2],"HARD",0)) {hard=true; 1774 } else if (mystrncasecmp(argv[2],"HARD",0)) {hard=true;
1745 } else { 1775 } else {
1746 printmsg("What type of reset do you want (\"%s\") ?\n",argv[2]); 1776 printmsg("What type of reset do you want (\"%s\") ?\n",argv[2]);
1747 exit(-1); 1777 exit(-1);
1748 } 1778 }
1749 1779
1750 GSM_Init(true); 1780 GSM_Init(true);
1751 1781
1752 error=Phone->Reset(&s, hard); 1782 error=Phone->Reset(&s, hard);
1753 Print_Error(error); 1783 Print_Error(error);
1754 1784
1755 GSM_Terminate(); 1785 GSM_Terminate();
1756} 1786}
1757 1787
1758static void PrintCalendar(GSM_CalendarEntry *Note) 1788static void PrintCalendar(GSM_CalendarEntry *Note)
1759{ 1789{
1760 int i_age = 0,i; 1790 int i_age = 0,i;
1761 GSM_DateTime Alarm,DateTime; 1791 GSM_DateTime Alarm,DateTime;
1762 GSM_MemoryEntry entry; 1792 GSM_MemoryEntry entry;
1763 unsigned char *name; 1793 unsigned char *name;
1764 1794
1765 bool repeating = false; 1795 bool repeating = false;
1766 int repeat_dayofweek = -1; 1796 int repeat_dayofweek = -1;
1767 int repeat_day = -1; 1797 int repeat_day = -1;
1768 int repeat_weekofmonth = -1; 1798 int repeat_weekofmonth = -1;
1769 int repeat_month = -1; 1799 int repeat_month = -1;
1770 int repeat_frequency = -1; 1800 int repeat_frequency = -1;
1771 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0}; 1801 GSM_DateTime repeat_startdate = {0,0,0,0,0,0,0};
1772 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0}; 1802 GSM_DateTime repeat_stopdate = {0,0,0,0,0,0,0};
1773 1803
1774 printmsg("Location : %d\n", Note->Location); 1804 printmsg("Location : %d\n", Note->Location);
@@ -1853,1199 +1883,1218 @@ static void PrintCalendar(GSM_CalendarEntry *Note)
1853 entry.Location = Note->Entries[i].Number; 1883 entry.Location = Note->Entries[i].Number;
1854 entry.MemoryType = MEM_ME; 1884 entry.MemoryType = MEM_ME;
1855 error=Phone->GetMemory(&s, &entry); 1885 error=Phone->GetMemory(&s, &entry);
1856 if (error == ERR_NONE) { 1886 if (error == ERR_NONE) {
1857 name = GSM_PhonebookGetEntryName(&entry); 1887 name = GSM_PhonebookGetEntryName(&entry);
1858 if (name != NULL) { 1888 if (name != NULL) {
1859 printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number); 1889 printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), Note->Entries[i].Number);
1860 } else { 1890 } else {
1861 printmsg("Contact ID : %d\n",Note->Entries[i].Number); 1891 printmsg("Contact ID : %d\n",Note->Entries[i].Number);
1862 } 1892 }
1863 } else { 1893 } else {
1864 printmsg("Contact ID : %d\n",Note->Entries[i].Number); 1894 printmsg("Contact ID : %d\n",Note->Entries[i].Number);
1865 } 1895 }
1866 break; 1896 break;
1867 case CAL_REPEAT_DAYOFWEEK: 1897 case CAL_REPEAT_DAYOFWEEK:
1868 repeat_dayofweek = Note->Entries[i].Number; 1898 repeat_dayofweek = Note->Entries[i].Number;
1869 repeating = true; 1899 repeating = true;
1870 break; 1900 break;
1871 case CAL_REPEAT_DAY: 1901 case CAL_REPEAT_DAY:
1872 repeat_day = Note->Entries[i].Number; 1902 repeat_day = Note->Entries[i].Number;
1873 repeating = true; 1903 repeating = true;
1874 break; 1904 break;
1875 case CAL_REPEAT_WEEKOFMONTH: 1905 case CAL_REPEAT_WEEKOFMONTH:
1876 repeat_weekofmonth = Note->Entries[i].Number; 1906 repeat_weekofmonth = Note->Entries[i].Number;
1877 repeating = true; 1907 repeating = true;
1878 break; 1908 break;
1879 case CAL_REPEAT_MONTH: 1909 case CAL_REPEAT_MONTH:
1880 repeat_month = Note->Entries[i].Number; 1910 repeat_month = Note->Entries[i].Number;
1881 repeating = true; 1911 repeating = true;
1882 break; 1912 break;
1883 case CAL_REPEAT_FREQUENCY: 1913 case CAL_REPEAT_FREQUENCY:
1884 repeat_frequency = Note->Entries[i].Number; 1914 repeat_frequency = Note->Entries[i].Number;
1885 repeating = true; 1915 repeating = true;
1886 break; 1916 break;
1887 case CAL_REPEAT_STARTDATE: 1917 case CAL_REPEAT_STARTDATE:
1888 repeat_startdate = Note->Entries[i].Date; 1918 repeat_startdate = Note->Entries[i].Date;
1889 repeating = true; 1919 repeating = true;
1890 break; 1920 break;
1891 case CAL_REPEAT_STOPDATE: 1921 case CAL_REPEAT_STOPDATE:
1892 repeat_stopdate = Note->Entries[i].Date; 1922 repeat_stopdate = Note->Entries[i].Date;
1893 repeating = true; 1923 repeating = true;
1894 break; 1924 break;
1895 } 1925 }
1896 } 1926 }
1897 if (repeating) { 1927 if (repeating) {
1898 printmsg("Repeating : "); 1928 printmsg("Repeating : ");
1899 if ((repeat_startdate.Day == 0) && (repeat_stopdate.Day == 0)) { 1929 if ((repeat_startdate.Day == 0) && (repeat_stopdate.Day == 0)) {
1900 printmsg("Forever"); 1930 printmsg("Forever");
1901 } else if (repeat_startdate.Day == 0) { 1931 } else if (repeat_startdate.Day == 0) {
1902 printmsg("Till %s", OSDate(repeat_stopdate)); 1932 printmsg("Till %s", OSDate(repeat_stopdate));
1903 } else if (repeat_stopdate.Day == 0) { 1933 } else if (repeat_stopdate.Day == 0) {
1904 printmsg("Since %s", OSDate(repeat_startdate)); 1934 printmsg("Since %s", OSDate(repeat_startdate));
1905 } else { 1935 } else {
1906 printmsg("Since %s till %s", OSDate(repeat_startdate), OSDate(repeat_stopdate)); 1936 printmsg("Since %s till %s", OSDate(repeat_startdate), OSDate(repeat_stopdate));
1907 } 1937 }
1908 if (repeat_frequency != -1) { 1938 if (repeat_frequency != -1) {
1909 if (repeat_frequency == 1) { 1939 if (repeat_frequency == 1) {
1910 printmsg (" on each "); 1940 printmsg (" on each ");
1911 } else { 1941 } else {
1912 printmsg(" on each %d. ", repeat_frequency); 1942 printmsg(" on each %d. ", repeat_frequency);
1913 } 1943 }
1914 if (repeat_dayofweek > 0) { 1944 if (repeat_dayofweek > 0) {
1915 switch (repeat_dayofweek) { 1945 switch (repeat_dayofweek) {
1916 case 1 : printmsg("Monday"); break; 1946 case 1 : printmsg("Monday"); break;
1917 case 2 : printmsg("Tuesday"); break; 1947 case 2 : printmsg("Tuesday"); break;
1918 case 3 : printmsg("Wednesday"); break; 1948 case 3 : printmsg("Wednesday"); break;
1919 case 4 : printmsg("Thursday"); break; 1949 case 4 : printmsg("Thursday"); break;
1920 case 5 : printmsg("Friday"); break; 1950 case 5 : printmsg("Friday"); break;
1921 case 6 : printmsg("Saturday"); break; 1951 case 6 : printmsg("Saturday"); break;
1922 case 7 : printmsg("Sunday"); break; 1952 case 7 : printmsg("Sunday"); break;
1923 default: printmsg("Bad day!"); break; 1953 default: printmsg("Bad day!"); break;
1924 } 1954 }
1925 if (repeat_weekofmonth > 0) { 1955 if (repeat_weekofmonth > 0) {
1926 printmsg(" in %d. week of ", repeat_weekofmonth); 1956 printmsg(" in %d. week of ", repeat_weekofmonth);
1927 } else { 1957 } else {
1928 printmsg(" in "); 1958 printmsg(" in ");
1929 } 1959 }
1930 if (repeat_month > 0) { 1960 if (repeat_month > 0) {
1931 switch(repeat_month) { 1961 switch(repeat_month) {
1932 case 1 : printmsg("January"); break; 1962 case 1 : printmsg("January"); break;
1933 case 2 : printmsg("February"); break; 1963 case 2 : printmsg("February"); break;
1934 case 3 : printmsg("March"); break; 1964 case 3 : printmsg("March"); break;
1935 case 4 : printmsg("April"); break; 1965 case 4 : printmsg("April"); break;
1936 case 5 : printmsg("May"); break; 1966 case 5 : printmsg("May"); break;
1937 case 6 : printmsg("June"); break; 1967 case 6 : printmsg("June"); break;
1938 case 7 : printmsg("July"); break; 1968 case 7 : printmsg("July"); break;
1939 case 8 : printmsg("August"); break; 1969 case 8 : printmsg("August"); break;
1940 case 9 : printmsg("September"); break; 1970 case 9 : printmsg("September"); break;
1941 case 10: printmsg("October"); break; 1971 case 10: printmsg("October"); break;
1942 case 11: printmsg("November"); break; 1972 case 11: printmsg("November"); break;
1943 case 12: printmsg("December"); break; 1973 case 12: printmsg("December"); break;
1944 default: printmsg("Bad month!"); break; 1974 default: printmsg("Bad month!"); break;
1945 } 1975 }
1946 } else { 1976 } else {
1947 printmsg("each month"); 1977 printmsg("each month");
1948 } 1978 }
1949 } else if (repeat_day > 0) { 1979 } else if (repeat_day > 0) {
1950 printmsg("%d. day of ", repeat_day); 1980 printmsg("%d. day of ", repeat_day);
1951 if (repeat_month > 0) { 1981 if (repeat_month > 0) {
1952 switch(repeat_month) { 1982 switch(repeat_month) {
1953 case 1 : printmsg("January"); break; 1983 case 1 : printmsg("January"); break;
1954 case 2 : printmsg("February"); break; 1984 case 2 : printmsg("February"); break;
1955 case 3 : printmsg("March");break; 1985 case 3 : printmsg("March");break;
1956 case 4 : printmsg("April"); break; 1986 case 4 : printmsg("April"); break;
1957 case 5 : printmsg("May"); break; 1987 case 5 : printmsg("May"); break;
1958 case 6 : printmsg("June"); break; 1988 case 6 : printmsg("June"); break;
1959 case 7 : printmsg("July"); break; 1989 case 7 : printmsg("July"); break;
1960 case 8 : printmsg("August"); break; 1990 case 8 : printmsg("August"); break;
1961 case 9 : printmsg("September"); break; 1991 case 9 : printmsg("September"); break;
1962 case 10: printmsg("October"); break; 1992 case 10: printmsg("October"); break;
1963 case 11: printmsg("November"); break; 1993 case 11: printmsg("November"); break;
1964 case 12: printmsg("December"); break; 1994 case 12: printmsg("December"); break;
1965 default: printmsg("Bad month!");break; 1995 default: printmsg("Bad month!");break;
1966 } 1996 }
1967 } else { 1997 } else {
1968 printmsg("each month"); 1998 printmsg("each month");
1969 } 1999 }
1970 } else { 2000 } else {
1971 printmsg("day"); 2001 printmsg("day");
1972 } 2002 }
1973 } 2003 }
1974 printf("\n"); 2004 printf("\n");
1975 } 2005 }
1976 if (Note->Type == GSM_CAL_BIRTHDAY) { 2006 if (Note->Type == GSM_CAL_BIRTHDAY) {
1977 if (Alarm.Year == 0x00) GSM_GetCurrentDateTime (&Alarm); 2007 if (Alarm.Year == 0x00) GSM_GetCurrentDateTime (&Alarm);
1978 if (DateTime.Year != 0) { 2008 if (DateTime.Year != 0) {
1979 i_age = Alarm.Year - DateTime.Year; 2009 i_age = Alarm.Year - DateTime.Year;
1980 if (DateTime.Month < Alarm.Month) i_age++; 2010 if (DateTime.Month < Alarm.Month) i_age++;
1981 if (DateTime.Month == Alarm.Month && 2011 if (DateTime.Month == Alarm.Month &&
1982 DateTime.Day < Alarm.Day) { 2012 DateTime.Day < Alarm.Day) {
1983 i_age++; 2013 i_age++;
1984 } 2014 }
1985 printmsg("Age : %d %s\n",i_age, (i_age==1)?"year":"years"); 2015 printmsg("Age : %d %s\n",i_age, (i_age==1)?"year":"years");
1986 } 2016 }
1987 } 2017 }
1988 printf("\n"); 2018 printf("\n");
1989} 2019}
1990 2020
1991static void GetCalendar(int argc, char *argv[]) 2021static void GetCalendar(int argc, char *argv[])
1992{ 2022{
1993 GSM_CalendarEntryNote; 2023 GSM_CalendarEntryNote;
1994 int start,stop; 2024 int start,stop;
1995 2025
1996 GetStartStop(&start, &stop, 2, argc, argv); 2026 GetStartStop(&start, &stop, 2, argc, argv);
1997 2027
1998 GSM_Init(true); 2028 GSM_Init(true);
1999 2029
2000 for (i=start;i<=stop;i++) { 2030 for (i=start;i<=stop;i++) {
2001 Note.Location=i; 2031 Note.Location=i;
2002 error = Phone->GetCalendar(&s, &Note); 2032 error = Phone->GetCalendar(&s, &Note);
2003 if (error == ERR_EMPTY) continue; 2033 if (error == ERR_EMPTY) continue;
2004 Print_Error(error); 2034 Print_Error(error);
2005 PrintCalendar(&Note); 2035 PrintCalendar(&Note);
2006 } 2036 }
2007 2037
2008 GSM_Terminate(); 2038 GSM_Terminate();
2009} 2039}
2010 2040
2011static void DeleteCalendar(int argc, char *argv[]) 2041static void DeleteCalendar(int argc, char *argv[])
2012{ 2042{
2013 GSM_CalendarEntryNote; 2043 GSM_CalendarEntryNote;
2014 int start,stop; 2044 int start,stop;
2015 2045
2016 GetStartStop(&start, &stop, 2, argc, argv); 2046 GetStartStop(&start, &stop, 2, argc, argv);
2017 2047
2018 GSM_Init(true); 2048 GSM_Init(true);
2019 2049
2020 for (i=start;i<=stop;i++) { 2050 for (i=start;i<=stop;i++) {
2021 Note.Location=i; 2051 Note.Location=i;
2022 error = Phone->DeleteCalendar(&s, &Note); 2052 error = Phone->DeleteCalendar(&s, &Note);
2023 if (error == ERR_EMPTY) continue; 2053 if (error == ERR_EMPTY) continue;
2024 Print_Error(error); 2054 Print_Error(error);
2025 PrintCalendar(&Note); 2055 PrintCalendar(&Note);
2026 } 2056 }
2027 2057
2028 GSM_Terminate(); 2058 GSM_Terminate();
2029} 2059}
2030 2060
2031 2061
2032static void GetAllCalendar(int argc, char *argv[]) 2062static void GetAllCalendar(int argc, char *argv[])
2033{ 2063{
2034 GSM_CalendarEntryNote; 2064 GSM_CalendarEntryNote;
2035 bool refresh= true; 2065 bool refresh= true;
2036 2066
2037 signal(SIGINT, interrupt); 2067 signal(SIGINT, interrupt);
2038 printmsgerr("Press Ctrl+C to break...\n"); 2068 printmsgerr("Press Ctrl+C to break...\n");
2039 2069
2040 GSM_Init(true); 2070 GSM_Init(true);
2041 2071
2042 while (!gshutdown) { 2072 while (!gshutdown) {
2043 error=Phone->GetNextCalendar(&s,&Note,refresh); 2073 error=Phone->GetNextCalendar(&s,&Note,refresh);
2044 if (error == ERR_EMPTY) break; 2074 if (error == ERR_EMPTY) break;
2045 PrintCalendar(&Note);
2046 Print_Error(error); 2075 Print_Error(error);
2076 PrintCalendar(&Note);
2047 refresh=false; 2077 refresh=false;
2048 } 2078 }
2049 2079
2050 GSM_Terminate(); 2080 GSM_Terminate();
2051} 2081}
2052 2082
2053static void GetCalendarSettings(int argc, char *argv[]) 2083static void GetCalendarSettings(int argc, char *argv[])
2054{ 2084{
2055 GSM_CalendarSettings settings; 2085 GSM_CalendarSettings settings;
2056 2086
2057 GSM_Init(true); 2087 GSM_Init(true);
2058 2088
2059 error=Phone->GetCalendarSettings(&s,&settings); 2089 error=Phone->GetCalendarSettings(&s,&settings);
2060 Print_Error(error); 2090 Print_Error(error);
2061 2091
2062 if (settings.AutoDelete == 0) { 2092 if (settings.AutoDelete == 0) {
2063 printmsg("Auto deleting disabled"); 2093 printmsg("Auto deleting disabled");
2064 } else { 2094 } else {
2065 printmsg("Auto deleting notes after %i day(s)",settings.AutoDelete); 2095 printmsg("Auto deleting notes after %i day(s)",settings.AutoDelete);
2066 } 2096 }
2067 printmsg("\nWeek start on "); 2097 printmsg("\nWeek start on ");
2068 switch(settings.StartDay) { 2098 switch(settings.StartDay) {
2069 case 1: printmsg("Monday"); break; 2099 case 1: printmsg("Monday"); break;
2070 case 6: printmsg("Saturday"); break; 2100 case 6: printmsg("Saturday"); break;
2071 case 7: printmsg("Sunday"); break; 2101 case 7: printmsg("Sunday"); break;
2072 } 2102 }
2073 printf("\n"); 2103 printf("\n");
2074 2104
2075 GSM_Terminate(); 2105 GSM_Terminate();
2076} 2106}
2077 2107
2078static void GetWAPBookmark(int argc, char *argv[]) 2108static void GetWAPBookmark(int argc, char *argv[])
2079{ 2109{
2080 GSM_WAPBookmark bookmark; 2110 GSM_WAPBookmark bookmark;
2081 int start,stop; 2111 int start,stop;
2082 2112
2083 GetStartStop(&start, &stop, 2, argc, argv); 2113 GetStartStop(&start, &stop, 2, argc, argv);
2084 2114
2085 GSM_Init(true); 2115 GSM_Init(true);
2086 2116
2087 for (i=start;i<=stop;i++) { 2117 for (i=start;i<=stop;i++) {
2088 bookmark.Location=i; 2118 bookmark.Location=i;
2089 error=Phone->GetWAPBookmark(&s,&bookmark); 2119 error=Phone->GetWAPBookmark(&s,&bookmark);
2090 Print_Error(error); 2120 Print_Error(error);
2091 printmsg("Name : \"%s\"\n",DecodeUnicodeConsole(bookmark.Title)); 2121 printmsg("Name : \"%s\"\n",DecodeUnicodeConsole(bookmark.Title));
2092 printmsg("Address : \"%s\"\n",DecodeUnicodeConsole(bookmark.Address)); 2122 printmsg("Address : \"%s\"\n",DecodeUnicodeConsole(bookmark.Address));
2093 } 2123 }
2094 2124
2095 GSM_Terminate(); 2125 GSM_Terminate();
2096} 2126}
2097 2127
2098static void DeleteWAPBookmark(int argc, char *argv[]) 2128static void DeleteWAPBookmark(int argc, char *argv[])
2099{ 2129{
2100 GSM_WAPBookmarkbookmark; 2130 GSM_WAPBookmarkbookmark;
2101 int start, stop; 2131 int start, stop;
2102 2132
2103 GetStartStop(&start, &stop, 2, argc, argv); 2133 GetStartStop(&start, &stop, 2, argc, argv);
2104 2134
2105 GSM_Init(true); 2135 GSM_Init(true);
2106 2136
2107 for (i=start;i<=stop;i++) { 2137 for (i=start;i<=stop;i++) {
2108 bookmark.Location=i; 2138 bookmark.Location=i;
2109 error=Phone->DeleteWAPBookmark(&s, &bookmark); 2139 error=Phone->DeleteWAPBookmark(&s, &bookmark);
2110 Print_Error(error); 2140 Print_Error(error);
2111 } 2141 }
2112 2142
2113 GSM_Terminate(); 2143 GSM_Terminate();
2114} 2144}
2115 2145
2116static void GetGPRSPoint(int argc, char *argv[]) 2146static void GetGPRSPoint(int argc, char *argv[])
2117{ 2147{
2118 GSM_GPRSAccessPointpoint; 2148 GSM_GPRSAccessPointpoint;
2119 int start,stop; 2149 int start,stop;
2120 2150
2121 GetStartStop(&start, &stop, 2, argc, argv); 2151 GetStartStop(&start, &stop, 2, argc, argv);
2122 2152
2123 GSM_Init(true); 2153 GSM_Init(true);
2124 2154
2125 for (i=start;i<=stop;i++) { 2155 for (i=start;i<=stop;i++) {
2126 point.Location=i; 2156 point.Location=i;
2127 error=Phone->GetGPRSAccessPoint(&s,&point); 2157 error=Phone->GetGPRSAccessPoint(&s,&point);
2128 if (error != ERR_EMPTY) { 2158 if (error != ERR_EMPTY) {
2129 Print_Error(error); 2159 Print_Error(error);
2130 printmsg("%i. \"%s\"",point.Location,DecodeUnicodeConsole(point.Name)); 2160 printmsg("%i. \"%s\"",point.Location,DecodeUnicodeConsole(point.Name));
2131 } else { 2161 } else {
2132 printmsg("%i. Access point %i",point.Location,point.Location); 2162 printmsg("%i. Access point %i",point.Location,point.Location);
2133 } 2163 }
2134 if (point.Active) printmsg(" (active)"); 2164 if (point.Active) printmsg(" (active)");
2135 if (error != ERR_EMPTY) { 2165 if (error != ERR_EMPTY) {
2136 printmsg("\nAddress : \"%s\"\n\n",DecodeUnicodeConsole(point.URL)); 2166 printmsg("\nAddress : \"%s\"\n\n",DecodeUnicodeConsole(point.URL));
2137 } else { 2167 } else {
2138 printmsg("\n\n"); 2168 printmsg("\n\n");
2139 } 2169 }
2140 } 2170 }
2141 2171
2142 GSM_Terminate(); 2172 GSM_Terminate();
2143} 2173}
2144 2174
2145static void GetBitmap(int argc, char *argv[]) 2175static void GetBitmap(int argc, char *argv[])
2146{ 2176{
2147 GSM_File File; 2177 GSM_File File;
2148 GSM_MultiBitmap MultiBitmap; 2178 GSM_MultiBitmap MultiBitmap;
2149 int location=0; 2179 int location=0;
2150 GSM_AllRingtonesInfo Info; 2180 GSM_AllRingtonesInfo Info;
2151 2181
2152 if (mystrncasecmp(argv[2],"STARTUP",0)) { 2182 if (mystrncasecmp(argv[2],"STARTUP",0)) {
2153 MultiBitmap.Bitmap[0].Type=GSM_StartupLogo; 2183 MultiBitmap.Bitmap[0].Type=GSM_StartupLogo;
2154 } else if (mystrncasecmp(argv[2],"CALLER",0)) { 2184 } else if (mystrncasecmp(argv[2],"CALLER",0)) {
2155 MultiBitmap.Bitmap[0].Type=GSM_CallerGroupLogo; 2185 MultiBitmap.Bitmap[0].Type=GSM_CallerGroupLogo;
2156 GetStartStop(&location, NULL, 3, argc, argv); 2186 GetStartStop(&location, NULL, 3, argc, argv);
2157 if (location>5) { 2187 if (location>5) {
2158 printmsg("Maximal location for caller logo can be 5\n"); 2188 printmsg("Maximal location for caller logo can be 5\n");
2159 exit (-1); 2189 exit (-1);
2160 } 2190 }
2161 } else if (mystrncasecmp(argv[2],"PICTURE",0)) { 2191 } else if (mystrncasecmp(argv[2],"PICTURE",0)) {
2162 MultiBitmap.Bitmap[0].Type=GSM_PictureImage; 2192 MultiBitmap.Bitmap[0].Type=GSM_PictureImage;
2163 GetStartStop(&location, NULL, 3, argc, argv); 2193 GetStartStop(&location, NULL, 3, argc, argv);
2164 } else if (mystrncasecmp(argv[2],"TEXT",0)) { 2194 } else if (mystrncasecmp(argv[2],"TEXT",0)) {
2165 MultiBitmap.Bitmap[0].Type=GSM_WelcomeNote_Text; 2195 MultiBitmap.Bitmap[0].Type=GSM_WelcomeNote_Text;
2166 } else if (mystrncasecmp(argv[2],"DEALER",0)) { 2196 } else if (mystrncasecmp(argv[2],"DEALER",0)) {
2167 MultiBitmap.Bitmap[0].Type=GSM_DealerNote_Text; 2197 MultiBitmap.Bitmap[0].Type=GSM_DealerNote_Text;
2168 } else if (mystrncasecmp(argv[2],"OPERATOR",0)) { 2198 } else if (mystrncasecmp(argv[2],"OPERATOR",0)) {
2169 MultiBitmap.Bitmap[0].Type=GSM_OperatorLogo; 2199 MultiBitmap.Bitmap[0].Type=GSM_OperatorLogo;
2170 } else { 2200 } else {
2171 printmsg("What type of logo do you want to get (\"%s\") ?\n",argv[2]); 2201 printmsg("What type of logo do you want to get (\"%s\") ?\n",argv[2]);
2172 exit(-1); 2202 exit(-1);
2173 } 2203 }
2174 MultiBitmap.Bitmap[0].Location=location; 2204 MultiBitmap.Bitmap[0].Location=location;
2175 2205
2176 GSM_Init(true); 2206 GSM_Init(true);
2177 2207
2178 error=Phone->GetBitmap(&s,&MultiBitmap.Bitmap[0]); 2208 error=Phone->GetBitmap(&s,&MultiBitmap.Bitmap[0]);
2179 Print_Error(error); 2209 Print_Error(error);
2180 2210
2181 MultiBitmap.Number = 1; 2211 MultiBitmap.Number = 1;
2182 2212
2183 error=ERR_NONE; 2213 error=ERR_NONE;
2184 switch (MultiBitmap.Bitmap[0].Type) { 2214 switch (MultiBitmap.Bitmap[0].Type) {
2185 case GSM_CallerGroupLogo: 2215 case GSM_CallerGroupLogo:
2186 if (!MultiBitmap.Bitmap[0].DefaultBitmap) GSM_PrintBitmap(stdout,&MultiBitmap.Bitmap[0]); 2216 if (!MultiBitmap.Bitmap[0].DefaultBitmap) GSM_PrintBitmap(stdout,&MultiBitmap.Bitmap[0]);
2187 printmsg("Group name : \"%s\"",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Text)); 2217 printmsg("Group name : \"%s\"",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Text));
2188 if (MultiBitmap.Bitmap[0].DefaultName) printmsg(" (default)"); 2218 if (MultiBitmap.Bitmap[0].DefaultName) printmsg(" (default)");
2189 printf("\n"); 2219 printf("\n");
2190 if (MultiBitmap.Bitmap[0].DefaultRingtone) { 2220 if (MultiBitmap.Bitmap[0].DefaultRingtone) {
2191 printmsg("Ringtone : default\n"); 2221 printmsg("Ringtone : default\n");
2192 } else if (MultiBitmap.Bitmap[0].FileSystemRingtone) { 2222 } else if (MultiBitmap.Bitmap[0].FileSystemRingtone) {
2193 sprintf(File.ID_FullName,"%i",MultiBitmap.Bitmap[0].RingtoneID); 2223 sprintf(File.ID_FullName,"%i",MultiBitmap.Bitmap[0].RingtoneID);
2194 2224
2195 File.Buffer = NULL; 2225 File.Buffer = NULL;
2196 File.Used = 0; 2226 File.Used = 0;
2197 2227
2198 error = ERR_NONE; 2228 error = ERR_NONE;
2199 // while (error == ERR_NONE) { 2229 // while (error == ERR_NONE) {
2200 error = Phone->GetFilePart(&s,&File); 2230 error = Phone->GetFilePart(&s,&File);
2201 // } 2231 // }
2202 if (error != ERR_EMPTY && error != ERR_WRONGCRC) Print_Error(error); 2232 if (error != ERR_EMPTY && error != ERR_WRONGCRC) Print_Error(error);
2203 error = ERR_NONE; 2233 error = ERR_NONE;
2204 2234
2205 printmsg("Ringtone : \"%s\" (file with ID %i)\n", 2235 printmsg("Ringtone : \"%s\" (file with ID %i)\n",
2206 DecodeUnicodeString(File.Name), 2236 DecodeUnicodeString(File.Name),
2207 MultiBitmap.Bitmap[0].RingtoneID); 2237 MultiBitmap.Bitmap[0].RingtoneID);
2208 } else { 2238 } else {
2209 error = Phone->GetRingtonesInfo(&s,&Info); 2239 error = Phone->GetRingtonesInfo(&s,&Info);
2210 if (error != ERR_NONE) Info.Number = 0; 2240 if (error != ERR_NONE) Info.Number = 0;
2211 error = ERR_NONE; 2241 error = ERR_NONE;
2212 2242
2213 printmsg("Ringtone : "); 2243 printmsg("Ringtone : ");
2214 if (UnicodeLength(GSM_GetRingtoneName(&Info,MultiBitmap.Bitmap[0].RingtoneID))!=0) { 2244 if (UnicodeLength(GSM_GetRingtoneName(&Info,MultiBitmap.Bitmap[0].RingtoneID))!=0) {
2215 printmsg("\"%s\" (ID %i)\n", 2245 printmsg("\"%s\" (ID %i)\n",
2216 DecodeUnicodeConsole(GSM_GetRingtoneName(&Info,MultiBitmap.Bitmap[0].RingtoneID)), 2246 DecodeUnicodeConsole(GSM_GetRingtoneName(&Info,MultiBitmap.Bitmap[0].RingtoneID)),
2217 MultiBitmap.Bitmap[0].RingtoneID); 2247 MultiBitmap.Bitmap[0].RingtoneID);
2218 } else { 2248 } else {
2219 printmsg("ID %i\n",MultiBitmap.Bitmap[0].RingtoneID); 2249 printmsg("ID %i\n",MultiBitmap.Bitmap[0].RingtoneID);
2220 } 2250 }
2221 } 2251 }
2222 if (MultiBitmap.Bitmap[0].BitmapEnabled) { 2252 if (MultiBitmap.Bitmap[0].BitmapEnabled) {
2223 printmsg("Bitmap : enabled\n"); 2253 printmsg("Bitmap : enabled\n");
2224 } else { 2254 } else {
2225 printmsg("Bitmap : disabled\n"); 2255 printmsg("Bitmap : disabled\n");
2226 } 2256 }
2227 if (argc>4 && !MultiBitmap.Bitmap[0].DefaultBitmap) error=GSM_SaveBitmapFile(argv[4],&MultiBitmap); 2257 if (argc>4 && !MultiBitmap.Bitmap[0].DefaultBitmap) error=GSM_SaveBitmapFile(argv[4],&MultiBitmap);
2228 break; 2258 break;
2229 case GSM_StartupLogo: 2259 case GSM_StartupLogo:
2230 GSM_PrintBitmap(stdout,&MultiBitmap.Bitmap[0]); 2260 GSM_PrintBitmap(stdout,&MultiBitmap.Bitmap[0]);
2231 if (argc>3) error=GSM_SaveBitmapFile(argv[3],&MultiBitmap); 2261 if (argc>3) error=GSM_SaveBitmapFile(argv[3],&MultiBitmap);
2232 break; 2262 break;
2233 case GSM_OperatorLogo: 2263 case GSM_OperatorLogo:
2234 if (strcmp(MultiBitmap.Bitmap[0].NetworkCode,"000 00")!=0) { 2264 if (strcmp(MultiBitmap.Bitmap[0].NetworkCode,"000 00")!=0) {
2235 GSM_PrintBitmap(stdout,&MultiBitmap.Bitmap[0]); 2265 GSM_PrintBitmap(stdout,&MultiBitmap.Bitmap[0]);
2236 if (argc>3) error=GSM_SaveBitmapFile(argv[3],&MultiBitmap); 2266 if (argc>3) error=GSM_SaveBitmapFile(argv[3],&MultiBitmap);
2237 } else { 2267 } else {
2238 printmsg("No operator logo in phone\n"); 2268 printmsg("No operator logo in phone\n");
2239 } 2269 }
2240 break; 2270 break;
2241 case GSM_PictureImage: 2271 case GSM_PictureImage:
2242 GSM_PrintBitmap(stdout,&MultiBitmap.Bitmap[0]); 2272 GSM_PrintBitmap(stdout,&MultiBitmap.Bitmap[0]);
2243 printmsg("Text : \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Text)); 2273 printmsg("Text : \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Text));
2244 printmsg("Sender : \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Sender)); 2274 printmsg("Sender : \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Sender));
2275 if (MultiBitmap.Bitmap[0].Name)
2276 printmsg("Name : \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Name));
2245 if (argc>4) error=GSM_SaveBitmapFile(argv[4],&MultiBitmap); 2277 if (argc>4) error=GSM_SaveBitmapFile(argv[4],&MultiBitmap);
2246 break; 2278 break;
2247 case GSM_WelcomeNote_Text: 2279 case GSM_WelcomeNote_Text:
2248 printmsg("Welcome note text is \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Text)); 2280 printmsg("Welcome note text is \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Text));
2249 break; 2281 break;
2250 case GSM_DealerNote_Text: 2282 case GSM_DealerNote_Text:
2251 printmsg("Dealer note text is \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Text)); 2283 printmsg("Dealer note text is \"%s\"\n",DecodeUnicodeConsole(MultiBitmap.Bitmap[0].Text));
2252 break; 2284 break;
2253 default: 2285 default:
2254 break; 2286 break;
2255 } 2287 }
2256 Print_Error(error); 2288 Print_Error(error);
2257 2289
2258 GSM_Terminate(); 2290 GSM_Terminate();
2259} 2291}
2260 2292
2261static void SetBitmap(int argc, char *argv[]) 2293static void SetBitmap(int argc, char *argv[])
2262{ 2294{
2263 GSM_Bitmap Bitmap, NewBitmap; 2295 GSM_Bitmap Bitmap, NewBitmap;
2264 GSM_MultiBitmap MultiBitmap; 2296 GSM_MultiBitmap MultiBitmap;
2265 GSM_NetworkInfo NetInfo; 2297 GSM_NetworkInfo NetInfo;
2266 bool init = true; 2298 bool init = true;
2267 2299
2268 if (mystrncasecmp(argv[2],"STARTUP",0)) { 2300 if (mystrncasecmp(argv[2],"STARTUP",0)) {
2269 if (argc<4) { 2301 if (argc<4) {
2270 printmsg("More arguments required\n"); 2302 printmsg("More arguments required\n");
2271 exit(-1); 2303 exit(-1);
2272 } 2304 }
2273 MultiBitmap.Bitmap[0].Type=GSM_StartupLogo; 2305 MultiBitmap.Bitmap[0].Type=GSM_StartupLogo;
2274 MultiBitmap.Bitmap[0].Location=1; 2306 MultiBitmap.Bitmap[0].Location=1;
2275 if (!strcmp(argv[3],"1")) MultiBitmap.Bitmap[0].Location = 2; 2307 if (!strcmp(argv[3],"1")) MultiBitmap.Bitmap[0].Location = 2;
2276 if (!strcmp(argv[3],"2")) MultiBitmap.Bitmap[0].Location = 3; 2308 if (!strcmp(argv[3],"2")) MultiBitmap.Bitmap[0].Location = 3;
2277 if (!strcmp(argv[3],"3")) MultiBitmap.Bitmap[0].Location = 4; 2309 if (!strcmp(argv[3],"3")) MultiBitmap.Bitmap[0].Location = 4;
2278 if (MultiBitmap.Bitmap[0].Location == 1) { 2310 if (MultiBitmap.Bitmap[0].Location == 1) {
2279 error=GSM_ReadBitmapFile(argv[3],&MultiBitmap); 2311 error=GSM_ReadBitmapFile(argv[3],&MultiBitmap);
2280 Print_Error(error); 2312 Print_Error(error);
2281 } 2313 }
2282 memcpy(&Bitmap,&MultiBitmap.Bitmap[0],sizeof(GSM_Bitmap)); 2314 memcpy(&Bitmap,&MultiBitmap.Bitmap[0],sizeof(GSM_Bitmap));
2283 } else if (mystrncasecmp(argv[2],"TEXT",0)) { 2315 } else if (mystrncasecmp(argv[2],"TEXT",0)) {
2284 if (argc<4) { 2316 if (argc<4) {
2285 printmsg("More arguments required\n"); 2317 printmsg("More arguments required\n");
2286 exit(-1); 2318 exit(-1);
2287 } 2319 }
2288 Bitmap.Type=GSM_WelcomeNote_Text; 2320 Bitmap.Type=GSM_WelcomeNote_Text;
2289 EncodeUnicode(Bitmap.Text,argv[3],strlen(argv[3])); 2321 EncodeUnicode(Bitmap.Text,argv[3],strlen(argv[3]));
2290 } else if (mystrncasecmp(argv[2],"DEALER",0)) { 2322 } else if (mystrncasecmp(argv[2],"DEALER",0)) {
2291 if (argc<4) { 2323 if (argc<4) {
2292 printmsg("More arguments required\n"); 2324 printmsg("More arguments required\n");
2293 exit(-1); 2325 exit(-1);
2294 } 2326 }
2295 Bitmap.Type=GSM_DealerNote_Text; 2327 Bitmap.Type=GSM_DealerNote_Text;
2296 EncodeUnicode(Bitmap.Text,argv[3],strlen(argv[3])); 2328 EncodeUnicode(Bitmap.Text,argv[3],strlen(argv[3]));
2297 } else if (mystrncasecmp(argv[2],"CALLER",0)) { 2329 } else if (mystrncasecmp(argv[2],"CALLER",0)) {
2298 if (argc<4) { 2330 if (argc<4) {
2299 printmsg("More arguments required\n"); 2331 printmsg("More arguments required\n");
2300 exit(-1); 2332 exit(-1);
2301 } 2333 }
2302 GetStartStop(&i, NULL, 3, argc, argv); 2334 GetStartStop(&i, NULL, 3, argc, argv);
2303 if (i>5 && i!=255) { 2335 if (i>5 && i!=255) {
2304 printmsg("Maximal location for caller logo can be 5\n"); 2336 printmsg("Maximal location for caller logo can be 5\n");
2305 exit (-1); 2337 exit (-1);
2306 } 2338 }
2307 MultiBitmap.Bitmap[0].Type = GSM_CallerGroupLogo; 2339 MultiBitmap.Bitmap[0].Type = GSM_CallerGroupLogo;
2308 MultiBitmap.Bitmap[0].Location= i; 2340 MultiBitmap.Bitmap[0].Location= i;
2309 if (argc>4) { 2341 if (argc>4) {
2310 error=GSM_ReadBitmapFile(argv[4],&MultiBitmap); 2342 error=GSM_ReadBitmapFile(argv[4],&MultiBitmap);
2311 Print_Error(error); 2343 Print_Error(error);
2312 } 2344 }
2313 memcpy(&Bitmap,&MultiBitmap.Bitmap[0],sizeof(GSM_Bitmap)); 2345 memcpy(&Bitmap,&MultiBitmap.Bitmap[0],sizeof(GSM_Bitmap));
2314 if (i!=255) { 2346 if (i!=255) {
2315 GSM_Init(true); 2347 GSM_Init(true);
2316 init = false; 2348 init = false;
2317 NewBitmap.Type = GSM_CallerGroupLogo; 2349 NewBitmap.Type = GSM_CallerGroupLogo;
2318 NewBitmap.Location = i; 2350 NewBitmap.Location = i;
2319 error=Phone->GetBitmap(&s,&NewBitmap); 2351 error=Phone->GetBitmap(&s,&NewBitmap);
2320 Print_Error(error); 2352 Print_Error(error);
2321 Bitmap.RingtoneID = NewBitmap.RingtoneID; 2353 Bitmap.RingtoneID = NewBitmap.RingtoneID;
2322 Bitmap.DefaultRingtone = NewBitmap.DefaultRingtone; 2354 Bitmap.DefaultRingtone = NewBitmap.DefaultRingtone;
2323 Bitmap.FileSystemRingtone = false; 2355 Bitmap.FileSystemRingtone = false;
2324 CopyUnicodeString(Bitmap.Text, NewBitmap.Text); 2356 CopyUnicodeString(Bitmap.Text, NewBitmap.Text);
2325 Bitmap.DefaultName = NewBitmap.DefaultName; 2357 Bitmap.DefaultName = NewBitmap.DefaultName;
2326 } 2358 }
2327 } else if (mystrncasecmp(argv[2],"PICTURE",0)) { 2359 } else if (mystrncasecmp(argv[2],"PICTURE",0)) {
2328 if (argc<5) { 2360 if (argc<5) {
2329 printmsg("More arguments required\n"); 2361 printmsg("More arguments required\n");
2330 exit(-1); 2362 exit(-1);
2331 } 2363 }
2332 MultiBitmap.Bitmap[0].Type = GSM_PictureImage; 2364 MultiBitmap.Bitmap[0].Type = GSM_PictureImage;
2333 MultiBitmap.Bitmap[0].Location = atoi(argv[4]); 2365 MultiBitmap.Bitmap[0].Location = atoi(argv[4]);
2334 error=GSM_ReadBitmapFile(argv[3],&MultiBitmap); 2366 error=GSM_ReadBitmapFile(argv[3],&MultiBitmap);
2335 Print_Error(error); 2367 Print_Error(error);
2336 memcpy(&Bitmap,&MultiBitmap.Bitmap[0],sizeof(GSM_Bitmap)); 2368 memcpy(&Bitmap,&MultiBitmap.Bitmap[0],sizeof(GSM_Bitmap));
2337 Bitmap.Text[0]=0; 2369 Bitmap.Text[0]=0;
2338 Bitmap.Text[1]=0; 2370 Bitmap.Text[1]=0;
2339 if (argc == 6) EncodeUnicode(Bitmap.Text,argv[5],strlen(argv[5])); 2371 if (argc == 6) EncodeUnicode(Bitmap.Text,argv[5],strlen(argv[5]));
2340 Bitmap.Sender[0]=0; 2372 Bitmap.Sender[0]=0;
2341 Bitmap.Sender[1]=0; 2373 Bitmap.Sender[1]=0;
2342 } else if (mystrncasecmp(argv[2],"COLOUROPERATOR",0)) { 2374 } else if (mystrncasecmp(argv[2],"COLOUROPERATOR",0)) {
2343 Bitmap.Type = GSM_ColourOperatorLogo_ID; 2375 Bitmap.Type = GSM_ColourOperatorLogo_ID;
2344 strcpy(Bitmap.NetworkCode,"000 00"); 2376 strcpy(Bitmap.NetworkCode,"000 00");
2345 if (argc > 3) { 2377 if (argc > 3) {
2346 Bitmap.ID = atoi(argv[3]); 2378 Bitmap.ID = atoi(argv[3]);
2347 if (argc>4) { 2379 if (argc>4) {
2348 strncpy(Bitmap.NetworkCode,argv[4],6); 2380 strncpy(Bitmap.NetworkCode,argv[4],6);
2349 } else { 2381 } else {
2350 GSM_Init(true); 2382 GSM_Init(true);
2351 init = false; 2383 init = false;
2352 error=Phone->GetNetworkInfo(&s,&NetInfo); 2384 error=Phone->GetNetworkInfo(&s,&NetInfo);
2353 Print_Error(error); 2385 Print_Error(error);
2354 strcpy(Bitmap.NetworkCode,NetInfo.NetworkCode); 2386 strcpy(Bitmap.NetworkCode,NetInfo.NetworkCode);
2355 } 2387 }
2356 } 2388 }
2357 } else if (mystrncasecmp(argv[2],"COLOURSTARTUP",0)) { 2389 } else if (mystrncasecmp(argv[2],"COLOURSTARTUP",0)) {
2358 Bitmap.Type = GSM_ColourStartupLogo_ID; 2390 Bitmap.Type = GSM_ColourStartupLogo_ID;
2359 Bitmap.Location = 0; 2391 Bitmap.Location = 0;
2360 if (argc > 3) { 2392 if (argc > 3) {
2361 Bitmap.Location = 1; 2393 Bitmap.Location = 1;
2362 Bitmap.ID = atoi(argv[3]); 2394 Bitmap.ID = atoi(argv[3]);
2363 } 2395 }
2364 } else if (mystrncasecmp(argv[2],"WALLPAPER",0)) { 2396 } else if (mystrncasecmp(argv[2],"WALLPAPER",0)) {
2365 Bitmap.Type = GSM_ColourWallPaper_ID; 2397 Bitmap.Type = GSM_ColourWallPaper_ID;
2366 Bitmap.ID = 0; 2398 Bitmap.ID = 0;
2367 if (argc > 3) Bitmap.ID = atoi(argv[3]); 2399 if (argc > 3) Bitmap.ID = atoi(argv[3]);
2368 } else if (mystrncasecmp(argv[2],"OPERATOR",0)) { 2400 } else if (mystrncasecmp(argv[2],"OPERATOR",0)) {
2369 MultiBitmap.Bitmap[0].Type= GSM_OperatorLogo; 2401 MultiBitmap.Bitmap[0].Type= GSM_OperatorLogo;
2370 MultiBitmap.Bitmap[0].Location = 1; 2402 MultiBitmap.Bitmap[0].Location = 1;
2371 strcpy(MultiBitmap.Bitmap[0].NetworkCode,"000 00"); 2403 strcpy(MultiBitmap.Bitmap[0].NetworkCode,"000 00");
2372 if (argc>3) { 2404 if (argc>3) {
2373 error=GSM_ReadBitmapFile(argv[3],&MultiBitmap); 2405 error=GSM_ReadBitmapFile(argv[3],&MultiBitmap);
2374 Print_Error(error); 2406 Print_Error(error);
2375 if (argc>4) { 2407 if (argc>4) {
2376 strncpy(MultiBitmap.Bitmap[0].NetworkCode,argv[4],6); 2408 strncpy(MultiBitmap.Bitmap[0].NetworkCode,argv[4],6);
2377 } else { 2409 } else {
2378 GSM_Init(true); 2410 GSM_Init(true);
2379 init = false; 2411 init = false;
2380 error=Phone->GetNetworkInfo(&s,&NetInfo); 2412 error=Phone->GetNetworkInfo(&s,&NetInfo);
2381 Print_Error(error); 2413 Print_Error(error);
2382 strcpy(MultiBitmap.Bitmap[0].NetworkCode,NetInfo.NetworkCode); 2414 strcpy(MultiBitmap.Bitmap[0].NetworkCode,NetInfo.NetworkCode);
2383 } 2415 }
2384 } 2416 }
2385 memcpy(&Bitmap,&MultiBitmap.Bitmap[0],sizeof(GSM_Bitmap)); 2417 memcpy(&Bitmap,&MultiBitmap.Bitmap[0],sizeof(GSM_Bitmap));
2386 } else { 2418 } else {
2387 printmsg("What type of logo do you want to set (\"%s\") ?\n",argv[2]); 2419 printmsg("What type of logo do you want to set (\"%s\") ?\n",argv[2]);
2388 exit(-1); 2420 exit(-1);
2389 } 2421 }
2390 2422
2391 if (init) GSM_Init(true); 2423 if (init) GSM_Init(true);
2392 2424
2393 error=Phone->SetBitmap(&s,&Bitmap); 2425 error=Phone->SetBitmap(&s,&Bitmap);
2394 Print_Error(error); 2426 Print_Error(error);
2395 2427
2396#ifdef GSM_ENABLE_BEEP 2428#ifdef GSM_ENABLE_BEEP
2397 GSM_PhoneBeep(); 2429 GSM_PhoneBeep();
2398#endif 2430#endif
2399 2431
2400 GSM_Terminate(); 2432 GSM_Terminate();
2401} 2433}
2402 2434
2403static void SetRingtone(int argc, char *argv[]) 2435static void SetRingtone(int argc, char *argv[])
2404{ 2436{
2405 GSM_Ringtone ringtone; 2437 GSM_Ringtone ringtone;
2406 int i,nextlong=0; 2438 int i,nextlong=0;
2407 2439
2408 ringtone.Format= 0; 2440 ringtone.Format= 0;
2409 error=GSM_ReadRingtoneFile(argv[2],&ringtone); 2441 error=GSM_ReadRingtoneFile(argv[2],&ringtone);
2410 Print_Error(error); 2442 Print_Error(error);
2411 ringtone.Location = 255; 2443 ringtone.Location = 255;
2412 for (i=3;i<argc;i++) { 2444 for (i=3;i<argc;i++) {
2413 switch (nextlong) { 2445 switch (nextlong) {
2414 case 0: 2446 case 0:
2415 if (mystrncasecmp(argv[i],"-scale",0)) { 2447 if (mystrncasecmp(argv[i],"-scale",0)) {
2416 ringtone.NoteTone.AllNotesScale = true; 2448 ringtone.NoteTone.AllNotesScale = true;
2417 break; 2449 break;
2418 } 2450 }
2419 if (mystrncasecmp(argv[i],"-location",0)) { 2451 if (mystrncasecmp(argv[i],"-location",0)) {
2420 nextlong = 1; 2452 nextlong = 1;
2421 break; 2453 break;
2422 } 2454 }
2423 if (mystrncasecmp(argv[i],"-name",0)) { 2455 if (mystrncasecmp(argv[i],"-name",0)) {
2424 nextlong = 2; 2456 nextlong = 2;
2425 break; 2457 break;
2426 } 2458 }
2427 printmsg("Unknown parameter \"%s\"",argv[i]); 2459 printmsg("Unknown parameter \"%s\"",argv[i]);
2428 exit(-1); 2460 exit(-1);
2429 case 1: 2461 case 1:
2430 ringtone.Location=atoi(argv[i]); 2462 ringtone.Location=atoi(argv[i]);
2431 nextlong = 0; 2463 nextlong = 0;
2432 break; 2464 break;
2433 case 2: 2465 case 2:
2434 EncodeUnicode(ringtone.Name,argv[i],strlen(argv[i])); 2466 EncodeUnicode(ringtone.Name,argv[i],strlen(argv[i]));
2435 nextlong = 0; 2467 nextlong = 0;
2436 break; 2468 break;
2437 } 2469 }
2438 } 2470 }
2439 if (nextlong!=0) { 2471 if (nextlong!=0) {
2440 printmsg("Parameter missed...\n"); 2472 printmsg("Parameter missed...\n");
2441 exit(-1); 2473 exit(-1);
2442 } 2474 }
2443 if (ringtone.Location==0) { 2475 if (ringtone.Location==0) {
2444 printmsg("ERROR: enumerate locations from 1\n"); 2476 printmsg("ERROR: enumerate locations from 1\n");
2445 exit (-1); 2477 exit (-1);
2446 } 2478 }
2447 2479
2448 GSM_Init(true); 2480 GSM_Init(true);
2449 error=Phone->SetRingtone(&s, &ringtone, &i); 2481 error=Phone->SetRingtone(&s, &ringtone, &i);
2450 Print_Error(error); 2482 Print_Error(error);
2451#ifdef GSM_ENABLE_BEEP 2483#ifdef GSM_ENABLE_BEEP
2452 GSM_PhoneBeep(); 2484 GSM_PhoneBeep();
2453#endif 2485#endif
2454 GSM_Terminate(); 2486 GSM_Terminate();
2455} 2487}
2456 2488
2457static void DisplaySMSFrame(GSM_SMSMessage *SMS) 2489static void DisplaySMSFrame(GSM_SMSMessage *SMS)
2458{ 2490{
2459 GSM_Error error; 2491 GSM_Error error;
2460 int i, length, current = 0; 2492 int i, length, current = 0;
2461 unsigned char req[1000], buffer[1000], hexreq[1000]; 2493 unsigned char req[1000], buffer[1000], hexreq[1000];
2462#ifdef OSCAR 2494#ifdef OSCAR
2463 unsigned char hexmsg[1000], hexudh[1000]; 2495 unsigned char hexmsg[1000], hexudh[1000];
2464#endif 2496#endif
2465 error=PHONE_EncodeSMSFrame(&s,SMS,buffer,PHONE_SMSSubmit,&length,true); 2497 error=PHONE_EncodeSMSFrame(&s,SMS,buffer,PHONE_SMSSubmit,&length,true);
2466 if (error != ERR_NONE) { 2498 if (error != ERR_NONE) {
2467 printmsg("Error\n"); 2499 printmsg("Error\n");
2468 exit(-1); 2500 exit(-1);
2469 } 2501 }
2470 length = length - PHONE_SMSSubmit.Text; 2502 length = length - PHONE_SMSSubmit.Text;
2471#ifdef OSCAR 2503#ifdef OSCAR
2472 for(i=SMS->UDH.Length;i<length;i++) { 2504 for(i=SMS->UDH.Length;i<length;i++) {
2473 req[i-SMS->UDH.Length]=buffer[PHONE_SMSSubmit.Text+i]; 2505 req[i-SMS->UDH.Length]=buffer[PHONE_SMSSubmit.Text+i];
2474 } 2506 }
2475 EncodeHexBin(hexmsg, req, length-SMS->UDH.Length); 2507 EncodeHexBin(hexmsg, req, length-SMS->UDH.Length);
2476 2508
2477 for(i=0;i<SMS->UDH.Length;i++) { 2509 for(i=0;i<SMS->UDH.Length;i++) {
2478 req[i]=buffer[PHONE_SMSSubmit.Text+i]; 2510 req[i]=buffer[PHONE_SMSSubmit.Text+i];
2479 } 2511 }
2480 EncodeHexBin(hexudh, req, SMS->UDH.Length); 2512 EncodeHexBin(hexudh, req, SMS->UDH.Length);
2481 2513
2482 printf("msg:%s nb:%i udh:%s\n", 2514 printf("msg:%s nb:%i udh:%s\n",
2483 hexmsg, 2515 hexmsg,
2484 (buffer[PHONE_SMSSubmit.TPUDL]-SMS->UDH.Length)*8, 2516 (buffer[PHONE_SMSSubmit.TPUDL]-SMS->UDH.Length)*8,
2485 hexudh); 2517 hexudh);
2486#else 2518#else
2487 for (i=0;i<buffer[PHONE_SMSSubmit.SMSCNumber]+1;i++) { 2519 for (i=0;i<buffer[PHONE_SMSSubmit.SMSCNumber]+1;i++) {
2488 req[current++]=buffer[PHONE_SMSSubmit.SMSCNumber+i]; 2520 req[current++]=buffer[PHONE_SMSSubmit.SMSCNumber+i];
2489 } 2521 }
2490 req[current++]=buffer[PHONE_SMSSubmit.firstbyte]; 2522 req[current++]=buffer[PHONE_SMSSubmit.firstbyte];
2491 req[current++]=buffer[PHONE_SMSSubmit.TPMR]; 2523 req[current++]=buffer[PHONE_SMSSubmit.TPMR];
2492 for (i=0;i<((buffer[PHONE_SMSSubmit.Number]+1)/2+1)+1;i++) { 2524 for (i=0;i<((buffer[PHONE_SMSSubmit.Number]+1)/2+1)+1;i++) {
2493 req[current++]=buffer[PHONE_SMSSubmit.Number+i]; 2525 req[current++]=buffer[PHONE_SMSSubmit.Number+i];
2494 } 2526 }
2495 req[current++]=buffer[PHONE_SMSSubmit.TPPID]; 2527 req[current++]=buffer[PHONE_SMSSubmit.TPPID];
2496 req[current++]=buffer[PHONE_SMSSubmit.TPDCS]; 2528 req[current++]=buffer[PHONE_SMSSubmit.TPDCS];
2497 req[current++]=buffer[PHONE_SMSSubmit.TPVP]; 2529 req[current++]=buffer[PHONE_SMSSubmit.TPVP];
2498 req[current++]=buffer[PHONE_SMSSubmit.TPUDL]; 2530 req[current++]=buffer[PHONE_SMSSubmit.TPUDL];
2499 for(i=0;i<length;i++) req[current++]=buffer[PHONE_SMSSubmit.Text+i]; 2531 for(i=0;i<length;i++) req[current++]=buffer[PHONE_SMSSubmit.Text+i];
2500 EncodeHexBin(hexreq, req, current); 2532 EncodeHexBin(hexreq, req, current);
2501 printmsg("%s\n\n",hexreq); 2533 printmsg("%s\n\n",hexreq);
2502#endif 2534#endif
2503} 2535}
2504 2536
2505#define SEND_SAVE_SMS_BUFFER_SIZE 10000 2537#define SEND_SAVE_SMS_BUFFER_SIZE 10000
2506 2538
2507static GSM_Error SMSStatus; 2539static GSM_Error SMSStatus;
2508//#if 0 2540
2509static void SendSMSStatus (char *Device, int status, int MessageReference) 2541static void SendSMSStatus (char *Device, int status, int MessageReference)
2510{ 2542{
2511 dbgprintf("Sent SMS on device: \"%s\"\n",Device); 2543 dbgprintf("Sent SMS on device: \"%s\"\n",Device);
2512 if (status==0) { 2544 if (status==0) {
2513 printmsg("..OK"); 2545 printmsg("..OK");
2514 SMSStatus = ERR_NONE; 2546 SMSStatus = ERR_NONE;
2515 } else { 2547 } else {
2516 printmsg("..error %i",status); 2548 printmsg("..error %i",status);
2517 SMSStatus = ERR_UNKNOWN; 2549 SMSStatus = ERR_UNKNOWN;
2518 } 2550 }
2519 printmsg(", message reference=%02x\n",MessageReference); 2551 printmsg(", message reference=%d\n",MessageReference);
2520} 2552}
2521 2553
2522static void SendSaveDisplaySMS(int argc, char *argv[]) 2554static void SendSaveDisplaySMS(int argc, char *argv[])
2523{ 2555{
2524#ifdef GSM_ENABLE_BACKUP 2556#ifdef GSM_ENABLE_BACKUP
2525 GSM_Backup Backup; 2557 GSM_Backup Backup;
2526#endif 2558#endif
2527 int i,j,z,FramesNum = 0; 2559 int i,j,z,FramesNum = 0;
2528 int Protected = 0; 2560 int Protected = 0;
2529 GSM_SMSFolders folders; 2561 GSM_SMSFolders folders;
2530 GSM_MultiSMSMessage sms; 2562 GSM_MultiSMSMessage sms;
2531 GSM_Ringtone ringtone[MAX_MULTI_SMS]; 2563 GSM_Ringtone ringtone[MAX_MULTI_SMS];
2532 GSM_MultiBitmap bitmap[MAX_MULTI_SMS],bitmap2; 2564 GSM_MultiBitmap bitmap[MAX_MULTI_SMS],bitmap2;
2533 GSM_MultiPartSMSInfoSMSInfo; 2565 GSM_MultiPartSMSInfo SMSInfo;
2534 GSM_NetworkInfo NetInfo; 2566 GSM_NetworkInfo NetInfo;
2535 GSM_MMSIndicator MMSInfo; 2567 GSM_MMSIndicator MMSInfo;
2536 FILE *ReplaceFile,*f; 2568 FILE *ReplaceFile,*f;
2537 char ReplaceBuffer2[200],ReplaceBuffer[200]; 2569 char ReplaceBuffer2[200],ReplaceBuffer[200];
2538 char InputBuffer[SEND_SAVE_SMS_BUFFER_SIZE/2+1]; 2570 char InputBuffer[SEND_SAVE_SMS_BUFFER_SIZE/2+1];
2539 char Buffer [MAX_MULTI_SMS][SEND_SAVE_SMS_BUFFER_SIZE]; 2571 char Buffer [MAX_MULTI_SMS][SEND_SAVE_SMS_BUFFER_SIZE];
2540 char Sender [(GSM_MAX_NUMBER_LENGTH+1)*2]; 2572 char Sender [(GSM_MAX_NUMBER_LENGTH+1)*2];
2541 char Name [(GSM_MAX_NUMBER_LENGTH+1)*2]; 2573 char Name [(GSM_MAX_NUMBER_LENGTH+1)*2];
2542 char SMSC [(GSM_MAX_NUMBER_LENGTH+1)*2]; 2574 char SMSC [(GSM_MAX_NUMBER_LENGTH+1)*2];
2543 int startarg = 0; 2575 int startarg = 0;
2544 int chars_read = 0; 2576 int chars_read = 0;
2545 int nextlong = 0; 2577 int nextlong = 0;
2546 bool ReplyViaSameSMSC = false; 2578 bool ReplyViaSameSMSC = false;
2547 int SMSCSet = 1; 2579 int SMSCSet = 1;
2548 int MaxSMS = -1; 2580 int MaxSMS = -1;
2549 bool EMS16Bit = false; 2581 bool EMS16Bit = false;
2550 bool SendSaved = false; 2582 bool SendSaved = false;
2551 2583
2552 /* Parameters required only during saving */ 2584 /* Parameters required only during saving */
2553 int Folder = 1; /*Inbox by default */ 2585 int Folder = 1; /*Inbox by default */
2554 GSM_SMS_State State = SMS_Sent; 2586 GSM_SMS_State State = SMS_Sent;
2555 2587
2556 /* Required only during sending */ 2588 /* Required only during sending */
2557 GSM_SMSValidity Validity; 2589 GSM_SMSValidity Validity;
2558 GSM_SMSC PhoneSMSC; 2590 GSM_SMSC PhoneSMSC;
2559 bool DeliveryReport = false; 2591 bool DeliveryReport = false;
2560 2592
2561 ReplaceBuffer[0] = 0; 2593 ReplaceBuffer[0] = 0;
2562 ReplaceBuffer[1] = 0; 2594 ReplaceBuffer[1] = 0;
2563 GSM_ClearMultiPartSMSInfo(&SMSInfo); 2595 GSM_ClearMultiPartSMSInfo(&SMSInfo);
2564 SMSInfo.ReplaceMessage = 0; 2596 SMSInfo.ReplaceMessage = 0;
2565 SMSInfo.EntriesNum = 1; 2597 SMSInfo.EntriesNum = 1;
2566 2598
2567 if (mystrncasecmp(argv[1],"--savesms",0)) { 2599 if (mystrncasecmp(argv[1],"--savesms",0)) {
2568 EncodeUnicode(Sender,"Gammu",5); 2600 EncodeUnicode(Sender,"Gammu",5);
2569 Name[0] = 0; 2601 Name[0] = 0;
2570 Name[1] = 0; 2602 Name[1] = 0;
2571 startarg = 0; 2603 startarg = 0;
2572 } else { 2604 } else {
2573 EncodeUnicode(Sender,argv[3],strlen(argv[3])); 2605 EncodeUnicode(Sender,argv[3],strlen(argv[3]));
2574 startarg = 1; 2606 startarg = 1;
2575 Validity.Format = 0; 2607 Validity.Format = 0;
2576 } 2608 }
2577 if (mystrncasecmp(argv[1],"--sendsmsdsms",0)) startarg=startarg+2; 2609 if (mystrncasecmp(argv[1],"--sendsmsdsms",0)) {
2610 startarg=startarg+2;
2611 EncodeUnicode(SMSC,"1234",4);
2612 SMSCSet= 0;
2613 }
2578 2614
2579 if (mystrncasecmp(argv[2],"TEXT",0)) { 2615 if (mystrncasecmp(argv[2],"TEXT",0)) {
2580 chars_read = fread(InputBuffer, 1, SEND_SAVE_SMS_BUFFER_SIZE/2, stdin); 2616 chars_read = fread(InputBuffer, 1, SEND_SAVE_SMS_BUFFER_SIZE/2, stdin);
2581 if (chars_read == 0) printmsg("Warning: 0 chars read !\n"); 2617 if (chars_read == 0) printmsg("Warning: 0 chars read !\n");
2582 InputBuffer[chars_read] = 0x00; 2618 InputBuffer[chars_read] = 0x00;
2583 InputBuffer[chars_read+1] = 0x00; 2619 InputBuffer[chars_read+1] = 0x00;
2584 EncodeUnicode(Buffer[0],InputBuffer,strlen(InputBuffer)); 2620 EncodeUnicode(Buffer[0],InputBuffer,strlen(InputBuffer));
2585 SMSInfo.Entries[0].Buffer = Buffer[0]; 2621 SMSInfo.Entries[0].Buffer = Buffer[0];
2586 SMSInfo.Entries[0].ID = SMS_Text; 2622 SMSInfo.Entries[0].ID = SMS_Text;
2587 SMSInfo.UnicodeCoding = false; 2623 SMSInfo.UnicodeCoding = false;
2588 startarg += 3; 2624 startarg += 3;
2589 } else if (mystrncasecmp(argv[2],"SMSTEMPLATE",0)) { 2625 } else if (mystrncasecmp(argv[2],"SMSTEMPLATE",0)) {
2590 SMSInfo.UnicodeCoding = false; 2626 SMSInfo.UnicodeCoding = false;
2591 SMSInfo.EntriesNum = 1; 2627 SMSInfo.EntriesNum = 1;
2592 Buffer[0][0] = 0x00; 2628 Buffer[0][0] = 0x00;
2593 Buffer[0][1] = 0x00; 2629 Buffer[0][1] = 0x00;
2594 SMSInfo.Entries[0].Buffer = Buffer[0]; 2630 SMSInfo.Entries[0].Buffer = Buffer[0];
2595 SMSInfo.Entries[0].ID = SMS_AlcatelSMSTemplateName; 2631 SMSInfo.Entries[0].ID = SMS_AlcatelSMSTemplateName;
2596 startarg += 3; 2632 startarg += 3;
2597 } else if (mystrncasecmp(argv[2],"EMS",0)) { 2633 } else if (mystrncasecmp(argv[2],"EMS",0)) {
2598 SMSInfo.UnicodeCoding = false; 2634 SMSInfo.UnicodeCoding = false;
2599 SMSInfo.EntriesNum = 0; 2635 SMSInfo.EntriesNum = 0;
2600 startarg += 3; 2636 startarg += 3;
2601 } else if (mystrncasecmp(argv[2],"MMSINDICATOR",0)) { 2637 } else if (mystrncasecmp(argv[2],"MMSINDICATOR",0)) {
2602 if (argc<6+startarg) { 2638 if (argc<6+startarg) {
2603 printmsg("Where is ringtone filename ?\n"); 2639 printmsg("Where are parameters ?\n");
2604 exit(-1); 2640 exit(-1);
2605 } 2641 }
2606 SMSInfo.Entries[0].ID = SMS_MMSIndicatorLong; 2642 SMSInfo.Entries[0].ID = SMS_MMSIndicatorLong;
2607 SMSInfo.Entries[0].MMSIndicator = &MMSInfo; 2643 SMSInfo.Entries[0].MMSIndicator = &MMSInfo;
2608 if (mystrncasecmp(argv[1],"--savesms",0)) { 2644 if (mystrncasecmp(argv[1],"--savesms",0)) {
2609 EncodeUnicode(Sender,"MMS Info",8); 2645 EncodeUnicode(Sender,"MMS Info",8);
2610 } 2646 }
2611 strcpy(MMSInfo.Address,argv[3+startarg]); 2647 strcpy(MMSInfo.Address,argv[3+startarg]);
2612 strcpy(MMSInfo.Title,argv[4+startarg]); 2648 strcpy(MMSInfo.Title,argv[4+startarg]);
2613 strcpy(MMSInfo.Sender,argv[5+startarg]); 2649 strcpy(MMSInfo.Sender,argv[5+startarg]);
2614 startarg += 6; 2650 startarg += 6;
2651 } else if (mystrncasecmp(argv[2],"WAPINDICATOR",0)) {
2652 if (argc<5+startarg) {
2653 printmsg("Where are parameters ?\n");
2654 exit(-1);
2655 }
2656 SMSInfo.Entries[0].ID = SMS_WAPIndicatorLong;
2657 SMSInfo.Entries[0].MMSIndicator = &MMSInfo;
2658 if (mystrncasecmp(argv[1],"--savesms",0)) {
2659 EncodeUnicode(Sender,"WAP Info",8);
2660 }
2661 strcpy(MMSInfo.Address,argv[3+startarg]);
2662 strcpy(MMSInfo.Title,argv[4+startarg]);
2663 startarg += 5;
2615 } else if (mystrncasecmp(argv[2],"RINGTONE",0)) { 2664 } else if (mystrncasecmp(argv[2],"RINGTONE",0)) {
2616 if (argc<4+startarg) { 2665 if (argc<4+startarg) {
2617 printmsg("Where is ringtone filename ?\n"); 2666 printmsg("Where is ringtone filename ?\n");
2618 exit(-1); 2667 exit(-1);
2619 } 2668 }
2620 ringtone[0].Format=RING_NOTETONE; 2669 ringtone[0].Format=RING_NOTETONE;
2621 error=GSM_ReadRingtoneFile(argv[3+startarg],&ringtone[0]); 2670 error=GSM_ReadRingtoneFile(argv[3+startarg],&ringtone[0]);
2622 Print_Error(error); 2671 Print_Error(error);
2623 SMSInfo.Entries[0].ID = SMS_NokiaRingtone; 2672 SMSInfo.Entries[0].ID = SMS_NokiaRingtone;
2624 SMSInfo.Entries[0].Ringtone = &ringtone[0]; 2673 SMSInfo.Entries[0].Ringtone = &ringtone[0];
2625 if (mystrncasecmp(argv[1],"--savesms",0)) { 2674 if (mystrncasecmp(argv[1],"--savesms",0)) {
2626 CopyUnicodeString(Sender, ringtone[0].Name); 2675 CopyUnicodeString(Sender, ringtone[0].Name);
2627 EncodeUnicode(Name,"Ringtone ",9); 2676 EncodeUnicode(Name,"Ringtone ",9);
2628 CopyUnicodeString(Name+9*2, ringtone[0].Name); 2677 CopyUnicodeString(Name+9*2, ringtone[0].Name);
2629 } 2678 }
2630 startarg += 4; 2679 startarg += 4;
2631 } else if (mystrncasecmp(argv[2],"OPERATOR",0)) { 2680 } else if (mystrncasecmp(argv[2],"OPERATOR",0)) {
2632 if (argc<4+startarg) { 2681 if (argc<4+startarg) {
2633 printmsg("Where is logo filename ?\n"); 2682 printmsg("Where is logo filename ?\n");
2634 exit(-1); 2683 exit(-1);
2635 } 2684 }
2636 bitmap[0].Bitmap[0].Type=GSM_OperatorLogo; 2685 bitmap[0].Bitmap[0].Type=GSM_OperatorLogo;
2637 error=GSM_ReadBitmapFile(argv[3+startarg],&bitmap[0]); 2686 error=GSM_ReadBitmapFile(argv[3+startarg],&bitmap[0]);
2638 Print_Error(error); 2687 Print_Error(error);
2639 strcpy(bitmap[0].Bitmap[0].NetworkCode,"000 00"); 2688 strcpy(bitmap[0].Bitmap[0].NetworkCode,"000 00");
2640 SMSInfo.Entries[0].ID = SMS_NokiaOperatorLogo; 2689 SMSInfo.Entries[0].ID = SMS_NokiaOperatorLogo;
2641 SMSInfo.Entries[0].Bitmap = &bitmap[0]; 2690 SMSInfo.Entries[0].Bitmap = &bitmap[0];
2642 if (mystrncasecmp(argv[1],"--savesms",0)) { 2691 if (mystrncasecmp(argv[1],"--savesms",0)) {
2643 EncodeUnicode(Sender, "OpLogo",6); 2692 EncodeUnicode(Sender, "OpLogo",6);
2644 EncodeUnicode(Name,"OpLogo ",7); 2693 EncodeUnicode(Name,"OpLogo ",7);
2645 } 2694 }
2646 startarg += 4; 2695 startarg += 4;
2647 } else if (mystrncasecmp(argv[2],"CALLER",0)) { 2696 } else if (mystrncasecmp(argv[2],"CALLER",0)) {
2648 if (argc<4+startarg) { 2697 if (argc<4+startarg) {
2649 printmsg("Where is logo filename ?\n"); 2698 printmsg("Where is logo filename ?\n");
2650 exit(-1); 2699 exit(-1);
2651 } 2700 }
2652 bitmap[0].Bitmap[0].Type=GSM_CallerGroupLogo; 2701 bitmap[0].Bitmap[0].Type=GSM_CallerGroupLogo;
2653 error=GSM_ReadBitmapFile(argv[3+startarg],&bitmap[0]); 2702 error=GSM_ReadBitmapFile(argv[3+startarg],&bitmap[0]);
2654 Print_Error(error); 2703 Print_Error(error);
2655 SMSInfo.Entries[0].ID = SMS_NokiaCallerLogo; 2704 SMSInfo.Entries[0].ID = SMS_NokiaCallerLogo;
2656 SMSInfo.Entries[0].Bitmap = &bitmap[0]; 2705 SMSInfo.Entries[0].Bitmap = &bitmap[0];
2657 if (mystrncasecmp(argv[1],"--savesms",0)) { 2706 if (mystrncasecmp(argv[1],"--savesms",0)) {
2658 EncodeUnicode(Sender, "Caller",6); 2707 EncodeUnicode(Sender, "Caller",6);
2659 } 2708 }
2660 startarg += 4; 2709 startarg += 4;
2661 } else if (mystrncasecmp(argv[2],"ANIMATION",0)) { 2710 } else if (mystrncasecmp(argv[2],"ANIMATION",0)) {
2662 SMSInfo.UnicodeCoding = false; 2711 SMSInfo.UnicodeCoding = false;
2663 SMSInfo.EntriesNum = 1; 2712 SMSInfo.EntriesNum = 1;
2664 if (argc<4+startarg) { 2713 if (argc<4+startarg) {
2665 printmsg("Where is number of frames ?\n"); 2714 printmsg("Where is number of frames ?\n");
2666 exit(-1); 2715 exit(-1);
2667 } 2716 }
2668 bitmap[0].Number = 0; 2717 bitmap[0].Number = 0;
2669 i = 1; 2718 i = 1;
2670 while (1) { 2719 while (1) {
2671 bitmap2.Bitmap[0].Type=GSM_StartupLogo; 2720 bitmap2.Bitmap[0].Type=GSM_StartupLogo;
2672 error=GSM_ReadBitmapFile(argv[3+startarg+i],&bitmap2); 2721 error=GSM_ReadBitmapFile(argv[3+startarg+i],&bitmap2);
2673 Print_Error(error); 2722 Print_Error(error);
2674 for (j=0;j<bitmap2.Number;j++) { 2723 for (j=0;j<bitmap2.Number;j++) {
2675 if (bitmap[0].Number == atoi(argv[3+startarg])) break; 2724 if (bitmap[0].Number == atoi(argv[3+startarg])) break;
2676 memcpy(&bitmap[0].Bitmap[bitmap[0].Number],&bitmap2.Bitmap[j],sizeof(GSM_Bitmap)); 2725 memcpy(&bitmap[0].Bitmap[bitmap[0].Number],&bitmap2.Bitmap[j],sizeof(GSM_Bitmap));
2677 bitmap[0].Number++; 2726 bitmap[0].Number++;
2678 } 2727 }
2679 if (bitmap[0].Number == atoi(argv[3+startarg])) break; 2728 if (bitmap[0].Number == atoi(argv[3+startarg])) break;
2680 i++; 2729 i++;
2681 } 2730 }
2682 SMSInfo.Entries[0].ID = SMS_AlcatelMonoAnimationLong; 2731 SMSInfo.Entries[0].ID = SMS_AlcatelMonoAnimationLong;
2683 SMSInfo.Entries[0].Bitmap = &bitmap[0]; 2732 SMSInfo.Entries[0].Bitmap = &bitmap[0];
2684 bitmap[0].Bitmap[0].Text[0]= 0; 2733 bitmap[0].Bitmap[0].Text[0]= 0;
2685 bitmap[0].Bitmap[0].Text[1]= 0; 2734 bitmap[0].Bitmap[0].Text[1]= 0;
2686 startarg += 4 + atoi(argv[3+startarg]); 2735 startarg += 4 + atoi(argv[3+startarg]);
2687 } else if (mystrncasecmp(argv[2],"PICTURE",0)) { 2736 } else if (mystrncasecmp(argv[2],"PICTURE",0)) {
2688 if (argc<4+startarg) { 2737 if (argc<4+startarg) {
2689 printmsg("Where is logo filename ?\n"); 2738 printmsg("Where is logo filename ?\n");
2690 exit(-1); 2739 exit(-1);
2691 } 2740 }
2692 bitmap[0].Bitmap[0].Type=GSM_PictureImage; 2741 bitmap[0].Bitmap[0].Type=GSM_PictureImage;
2693 error=GSM_ReadBitmapFile(argv[3+startarg],&bitmap[0]); 2742 error=GSM_ReadBitmapFile(argv[3+startarg],&bitmap[0]);
2694 printmsg("File \"%s\"\n",argv[3+startarg]); 2743 printmsg("File \"%s\"\n",argv[3+startarg]);
2695 Print_Error(error); 2744 Print_Error(error);
2696 SMSInfo.Entries[0].ID = SMS_NokiaPictureImageLong; 2745 SMSInfo.Entries[0].ID = SMS_NokiaPictureImageLong;
2697 SMSInfo.Entries[0].Bitmap = &bitmap[0]; 2746 SMSInfo.Entries[0].Bitmap = &bitmap[0];
2698 SMSInfo.UnicodeCoding = false; 2747 SMSInfo.UnicodeCoding = false;
2699 bitmap[0].Bitmap[0].Text[0]= 0; 2748 bitmap[0].Bitmap[0].Text[0]= 0;
2700 bitmap[0].Bitmap[0].Text[1]= 0; 2749 bitmap[0].Bitmap[0].Text[1]= 0;
2701 if (mystrncasecmp(argv[1],"--savesms",0)) { 2750 if (mystrncasecmp(argv[1],"--savesms",0)) {
2702 EncodeUnicode(Sender, "Picture",7); 2751 EncodeUnicode(Sender, "Picture",7);
2703 EncodeUnicode(Name,"Picture Image",13); 2752 EncodeUnicode(Name,"Picture Image",13);
2704 } 2753 }
2705 startarg += 4; 2754 startarg += 4;
2706#ifdef GSM_ENABLE_BACKUP 2755#ifdef GSM_ENABLE_BACKUP
2707 } else if (mystrncasecmp(argv[2],"BOOKMARK",0)) { 2756 } else if (mystrncasecmp(argv[2],"BOOKMARK",0)) {
2708 if (argc<5+startarg) { 2757 if (argc<5+startarg) {
2709 printmsg("Where is backup filename and location ?\n"); 2758 printmsg("Where is backup filename and location ?\n");
2710 exit(-1); 2759 exit(-1);
2711 } 2760 }
2712 error=GSM_ReadBackupFile(argv[3+startarg],&Backup); 2761 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2713 Print_Error(error); 2762 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
2714 i = 0; 2763 i = 0;
2715 while (Backup.WAPBookmark[i]!=NULL) { 2764 while (Backup.WAPBookmark[i]!=NULL) {
2716 if (i == atoi(argv[4+startarg])-1) break; 2765 if (i == atoi(argv[4+startarg])-1) break;
2717 i++; 2766 i++;
2718 } 2767 }
2719 if (i != atoi(argv[4+startarg])-1) { 2768 if (i != atoi(argv[4+startarg])-1) {
2720 printmsg("Bookmark not found in file\n"); 2769 printmsg("Bookmark not found in file\n");
2721 exit(-1); 2770 exit(-1);
2722 } 2771 }
2723 SMSInfo.Entries[0].ID = SMS_NokiaWAPBookmarkLong; 2772 SMSInfo.Entries[0].ID = SMS_NokiaWAPBookmarkLong;
2724 SMSInfo.Entries[0].Bookmark = Backup.WAPBookmark[i]; 2773 SMSInfo.Entries[0].Bookmark = Backup.WAPBookmark[i];
2725 if (mystrncasecmp(argv[1],"--savesms",0)) { 2774 if (mystrncasecmp(argv[1],"--savesms",0)) {
2726 EncodeUnicode(Sender, "Bookmark",8); 2775 EncodeUnicode(Sender, "Bookmark",8);
2727 EncodeUnicode(Name,"WAP Bookmark",12); 2776 EncodeUnicode(Name,"WAP Bookmark",12);
2728 } 2777 }
2729 startarg += 5; 2778 startarg += 5;
2730 } else if (mystrncasecmp(argv[2],"WAPSETTINGS",0)) { 2779 } else if (mystrncasecmp(argv[2],"WAPSETTINGS",0)) {
2731 if (argc<6+startarg) { 2780 if (argc<6+startarg) {
2732 printmsg("Where is backup filename and location ?\n"); 2781 printmsg("Where is backup filename and location ?\n");
2733 exit(-1); 2782 exit(-1);
2734 } 2783 }
2735 error=GSM_ReadBackupFile(argv[3+startarg],&Backup); 2784 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2736 Print_Error(error); 2785 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
2737 i = 0; 2786 i = 0;
2738 while (Backup.WAPSettings[i]!=NULL) { 2787 while (Backup.WAPSettings[i]!=NULL) {
2739 if (i == atoi(argv[4+startarg])-1) break; 2788 if (i == atoi(argv[4+startarg])-1) break;
2740 i++; 2789 i++;
2741 } 2790 }
2742 if (i != atoi(argv[4+startarg])-1) { 2791 if (i != atoi(argv[4+startarg])-1) {
2743 printmsg("WAP settings not found in file\n"); 2792 printmsg("WAP settings not found in file\n");
2744 exit(-1); 2793 exit(-1);
2745 } 2794 }
2746 SMSInfo.Entries[0].Settings = NULL; 2795 SMSInfo.Entries[0].Settings = NULL;
2747 for (j=0;j<Backup.WAPSettings[i]->Number;j++) { 2796 for (j=0;j<Backup.WAPSettings[i]->Number;j++) {
2748 switch (Backup.WAPSettings[i]->Settings[j].Bearer) { 2797 switch (Backup.WAPSettings[i]->Settings[j].Bearer) {
2749 case WAPSETTINGS_BEARER_GPRS: 2798 case WAPSETTINGS_BEARER_GPRS:
2750 if (mystrncasecmp(argv[5+startarg],"GPRS",0)) { 2799 if (mystrncasecmp(argv[5+startarg],"GPRS",0)) {
2751 SMSInfo.Entries[0].Settings = &Backup.WAPSettings[i]->Settings[j]; 2800 SMSInfo.Entries[0].Settings = &Backup.WAPSettings[i]->Settings[j];
2752 break; 2801 break;
2753 } 2802 }
2754 case WAPSETTINGS_BEARER_DATA: 2803 case WAPSETTINGS_BEARER_DATA:
2755 if (mystrncasecmp(argv[5+startarg],"DATA",0)) { 2804 if (mystrncasecmp(argv[5+startarg],"DATA",0)) {
2756 SMSInfo.Entries[0].Settings = &Backup.WAPSettings[i]->Settings[j]; 2805 SMSInfo.Entries[0].Settings = &Backup.WAPSettings[i]->Settings[j];
2757 break; 2806 break;
2758 } 2807 }
2759 default: 2808 default:
2760 break; 2809 break;
2761 } 2810 }
2762 } 2811 }
2763 if (SMSInfo.Entries[0].Settings == NULL) { 2812 if (SMSInfo.Entries[0].Settings == NULL) {
2764 printmsg("Sorry. For now there is only support for GPRS or DATA bearers end\n"); 2813 printmsg("Sorry. For now there is only support for GPRS or DATA bearers end\n");
2765 exit(-1); 2814 exit(-1);
2766 } 2815 }
2767 SMSInfo.Entries[0].ID = SMS_NokiaWAPSettingsLong; 2816 SMSInfo.Entries[0].ID = SMS_NokiaWAPSettingsLong;
2768 if (mystrncasecmp(argv[1],"--savesms",0)) { 2817 if (mystrncasecmp(argv[1],"--savesms",0)) {
2769 EncodeUnicode(Sender, "Settings",8); 2818 EncodeUnicode(Sender, "Settings",8);
2770 EncodeUnicode(Name,"WAP Settings",12); 2819 EncodeUnicode(Name,"WAP Settings",12);
2771 } 2820 }
2772 startarg += 6; 2821 startarg += 6;
2773 } else if (mystrncasecmp(argv[2],"MMSSETTINGS",0)) { 2822 } else if (mystrncasecmp(argv[2],"MMSSETTINGS",0)) {
2774 if (argc<5+startarg) { 2823 if (argc<5+startarg) {
2775 printmsg("Where is backup filename and location ?\n"); 2824 printmsg("Where is backup filename and location ?\n");
2776 exit(-1); 2825 exit(-1);
2777 } 2826 }
2778 error=GSM_ReadBackupFile(argv[3+startarg],&Backup); 2827 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2779 Print_Error(error); 2828 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
2780 i = 0; 2829 i = 0;
2781 while (Backup.MMSSettings[i]!=NULL) { 2830 while (Backup.MMSSettings[i]!=NULL) {
2782 if (i == atoi(argv[4+startarg])-1) break; 2831 if (i == atoi(argv[4+startarg])-1) break;
2783 i++; 2832 i++;
2784 } 2833 }
2785 if (i != atoi(argv[4+startarg])-1) { 2834 if (i != atoi(argv[4+startarg])-1) {
2786 printmsg("MMS settings not found in file\n"); 2835 printmsg("MMS settings not found in file\n");
2787 exit(-1); 2836 exit(-1);
2788 } 2837 }
2789 SMSInfo.Entries[0].Settings = NULL; 2838 SMSInfo.Entries[0].Settings = NULL;
2790 for (j=0;j<Backup.MMSSettings[i]->Number;j++) { 2839 for (j=0;j<Backup.MMSSettings[i]->Number;j++) {
2791 switch (Backup.MMSSettings[i]->Settings[j].Bearer) { 2840 switch (Backup.MMSSettings[i]->Settings[j].Bearer) {
2792 case WAPSETTINGS_BEARER_GPRS: 2841 case WAPSETTINGS_BEARER_GPRS:
2793 SMSInfo.Entries[0].Settings = &Backup.MMSSettings[i]->Settings[j]; 2842 SMSInfo.Entries[0].Settings = &Backup.MMSSettings[i]->Settings[j];
2794 break; 2843 break;
2795 default: 2844 default:
2796 break; 2845 break;
2797 } 2846 }
2798 } 2847 }
2799 if (SMSInfo.Entries[0].Settings == NULL) { 2848 if (SMSInfo.Entries[0].Settings == NULL) {
2800 printmsg("Sorry. No GPRS bearer found in MMS settings\n"); 2849 printmsg("Sorry. No GPRS bearer found in MMS settings\n");
2801 exit(-1); 2850 exit(-1);
2802 } 2851 }
2803 SMSInfo.Entries[0].ID = SMS_NokiaMMSSettingsLong; 2852 SMSInfo.Entries[0].ID = SMS_NokiaMMSSettingsLong;
2804 if (mystrncasecmp(argv[1],"--savesms",0)) { 2853 if (mystrncasecmp(argv[1],"--savesms",0)) {
2805 EncodeUnicode(Sender, "Settings",8); 2854 EncodeUnicode(Sender, "Settings",8);
2806 EncodeUnicode(Name,"MMS Settings",12); 2855 EncodeUnicode(Name,"MMS Settings",12);
2807 } 2856 }
2808 startarg += 5; 2857 startarg += 5;
2809 } else if (mystrncasecmp(argv[2],"CALENDAR",0)) { 2858 } else if (mystrncasecmp(argv[2],"CALENDAR",0)) {
2810 if (argc<5+startarg) { 2859 if (argc<5+startarg) {
2811 printmsg("Where is backup filename and location ?\n"); 2860 printmsg("Where is backup filename and location ?\n");
2812 exit(-1); 2861 exit(-1);
2813 } 2862 }
2814 error=GSM_ReadBackupFile(argv[3+startarg],&Backup); 2863 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2815 Print_Error(error); 2864 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
2816 i = 0; 2865 i = 0;
2817 while (Backup.Calendar[i]!=NULL) { 2866 while (Backup.Calendar[i]!=NULL) {
2818 if (i == atoi(argv[4+startarg])-1) break; 2867 if (i == atoi(argv[4+startarg])-1) break;
2819 i++; 2868 i++;
2820 } 2869 }
2821 if (i != atoi(argv[4+startarg])-1) { 2870 if (i != atoi(argv[4+startarg])-1) {
2822 printmsg("Calendar note not found in file\n"); 2871 printmsg("Calendar note not found in file\n");
2823 exit(-1); 2872 exit(-1);
2824 } 2873 }
2825 SMSInfo.Entries[0].ID = SMS_NokiaVCALENDAR10Long; 2874 SMSInfo.Entries[0].ID = SMS_NokiaVCALENDAR10Long;
2826 SMSInfo.Entries[0].Calendar = Backup.Calendar[i]; 2875 SMSInfo.Entries[0].Calendar = Backup.Calendar[i];
2827 if (mystrncasecmp(argv[1],"--savesms",0)) { 2876 if (mystrncasecmp(argv[1],"--savesms",0)) {
2828 EncodeUnicode(Sender, "Calendar",8); 2877 EncodeUnicode(Sender, "Calendar",8);
2829 } 2878 }
2830 startarg += 5; 2879 startarg += 5;
2831 } else if (mystrncasecmp(argv[2],"TODO",0)) { 2880 } else if (mystrncasecmp(argv[2],"TODO",0)) {
2832 if (argc<5+startarg) { 2881 if (argc<5+startarg) {
2833 printmsg("Where is backup filename and location ?\n"); 2882 printmsg("Where is backup filename and location ?\n");
2834 exit(-1); 2883 exit(-1);
2835 } 2884 }
2836 error=GSM_ReadBackupFile(argv[3+startarg],&Backup); 2885 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2837 Print_Error(error); 2886 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
2838 i = 0; 2887 i = 0;
2839 while (Backup.ToDo[i]!=NULL) { 2888 while (Backup.ToDo[i]!=NULL) {
2840 if (i == atoi(argv[4+startarg])-1) break; 2889 if (i == atoi(argv[4+startarg])-1) break;
2841 i++; 2890 i++;
2842 } 2891 }
2843 if (i != atoi(argv[4+startarg])-1) { 2892 if (i != atoi(argv[4+startarg])-1) {
2844 printmsg("ToDo note not found in file\n"); 2893 printmsg("ToDo note not found in file\n");
2845 exit(-1); 2894 exit(-1);
2846 } 2895 }
2847 SMSInfo.Entries[0].ID = SMS_NokiaVTODOLong; 2896 SMSInfo.Entries[0].ID = SMS_NokiaVTODOLong;
2848 SMSInfo.Entries[0].ToDo = Backup.ToDo[i]; 2897 SMSInfo.Entries[0].ToDo = Backup.ToDo[i];
2849 if (mystrncasecmp(argv[1],"--savesms",0)) { 2898 if (mystrncasecmp(argv[1],"--savesms",0)) {
2850 EncodeUnicode(Sender, "ToDo",8); 2899 EncodeUnicode(Sender, "ToDo",8);
2851 } 2900 }
2852 startarg += 5; 2901 startarg += 5;
2853 } else if (mystrncasecmp(argv[2],"VCARD10",0) || mystrncasecmp(argv[2],"VCARD21",0)) { 2902 } else if (mystrncasecmp(argv[2],"VCARD10",0) || mystrncasecmp(argv[2],"VCARD21",0)) {
2854 if (argc<6+startarg) { 2903 if (argc<6+startarg) {
2855 printmsg("Where is backup filename and location and memory type ?\n"); 2904 printmsg("Where is backup filename and location and memory type ?\n");
2856 exit(-1); 2905 exit(-1);
2857 } 2906 }
2858 error=GSM_ReadBackupFile(argv[3+startarg],&Backup); 2907 error=GSM_ReadBackupFile(argv[3+startarg],&Backup);
2859 Print_Error(error); 2908 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
2860 i = 0; 2909 i = 0;
2861 if (mystrncasecmp(argv[4+startarg],"SM",0)) { 2910 if (mystrncasecmp(argv[4+startarg],"SM",0)) {
2862 while (Backup.SIMPhonebook[i]!=NULL) { 2911 while (Backup.SIMPhonebook[i]!=NULL) {
2863 if (i == atoi(argv[5+startarg])-1) break; 2912 if (i == atoi(argv[5+startarg])-1) break;
2864 i++; 2913 i++;
2865 } 2914 }
2866 if (i != atoi(argv[5+startarg])-1) { 2915 if (i != atoi(argv[5+startarg])-1) {
2867 printmsg("Phonebook entry not found in file\n"); 2916 printmsg("Phonebook entry not found in file\n");
2868 exit(-1); 2917 exit(-1);
2869 } 2918 }
2870 SMSInfo.Entries[0].Phonebook = Backup.SIMPhonebook[i]; 2919 SMSInfo.Entries[0].Phonebook = Backup.SIMPhonebook[i];
2871 } else if (mystrncasecmp(argv[4+startarg],"ME",0)) { 2920 } else if (mystrncasecmp(argv[4+startarg],"ME",0)) {
2872 while (Backup.PhonePhonebook[i]!=NULL) { 2921 while (Backup.PhonePhonebook[i]!=NULL) {
2873 if (i == atoi(argv[5+startarg])-1) break; 2922 if (i == atoi(argv[5+startarg])-1) break;
2874 i++; 2923 i++;
2875 } 2924 }
2876 if (i != atoi(argv[5+startarg])-1) { 2925 if (i != atoi(argv[5+startarg])-1) {
2877 printmsg("Phonebook entry not found in file\n"); 2926 printmsg("Phonebook entry not found in file\n");
2878 exit(-1); 2927 exit(-1);
2879 } 2928 }
2880 SMSInfo.Entries[0].Phonebook = Backup.PhonePhonebook[i]; 2929 SMSInfo.Entries[0].Phonebook = Backup.PhonePhonebook[i];
2881 } else { 2930 } else {
2882 printmsg("Unknown memory type: \"%s\"\n",argv[4+startarg]); 2931 printmsg("Unknown memory type: \"%s\"\n",argv[4+startarg]);
2883 exit(-1); 2932 exit(-1);
2884 } 2933 }
2885 if (mystrncasecmp(argv[2],"VCARD10",0)) { 2934 if (mystrncasecmp(argv[2],"VCARD10",0)) {
2886 SMSInfo.Entries[0].ID = SMS_VCARD10Long; 2935 SMSInfo.Entries[0].ID = SMS_VCARD10Long;
2887 } else { 2936 } else {
2888 SMSInfo.Entries[0].ID = SMS_VCARD21Long; 2937 SMSInfo.Entries[0].ID = SMS_VCARD21Long;
2889 } 2938 }
2890 if (mystrncasecmp(argv[1],"--savesms",0)) { 2939 if (mystrncasecmp(argv[1],"--savesms",0)) {
2891 EncodeUnicode(Sender, "VCARD",5); 2940 EncodeUnicode(Sender, "VCARD",5);
2892 EncodeUnicode(Name, "Phonebook entry",15); 2941 EncodeUnicode(Name, "Phonebook entry",15);
2893 } 2942 }
2894 startarg += 6; 2943 startarg += 6;
2895#endif 2944#endif
2896 } else if (mystrncasecmp(argv[2],"PROFILE",0)) { 2945 } else if (mystrncasecmp(argv[2],"PROFILE",0)) {
2897 SMSInfo.Entries[0].ID = SMS_NokiaProfileLong; 2946 SMSInfo.Entries[0].ID = SMS_NokiaProfileLong;
2898 if (mystrncasecmp(argv[1],"--savesms",0)) { 2947 if (mystrncasecmp(argv[1],"--savesms",0)) {
2899 EncodeUnicode(Sender, "Profile",7); 2948 EncodeUnicode(Sender, "Profile",7);
2900 } 2949 }
2901 startarg += 3; 2950 startarg += 3;
2902 } else { 2951 } else {
2903 printmsg("What format of sms (\"%s\") ?\n",argv[2]); 2952 printmsg("What format of sms (\"%s\") ?\n",argv[2]);
2904 exit(-1); 2953 exit(-1);
2905 } 2954 }
2906 2955
2907 for (i=startarg;i<argc;i++) { 2956 for (i=startarg;i<argc;i++) {
2908 switch (nextlong) { 2957 switch (nextlong) {
2909 case 0: 2958 case 0:
2910 if (mystrncasecmp(argv[1],"--savesms",0) || SendSaved) { 2959 if (mystrncasecmp(argv[1],"--savesms",0) || SendSaved) {
2911 if (mystrncasecmp(argv[i],"-folder",0)) { 2960 if (mystrncasecmp(argv[i],"-folder",0)) {
2912 nextlong=1; 2961 nextlong=1;
2913 continue; 2962 continue;
2914 } 2963 }
2915 } 2964 }
2916 if (mystrncasecmp(argv[1],"--savesms",0)) { 2965 if (mystrncasecmp(argv[1],"--savesms",0)) {
2917 if (mystrncasecmp(argv[i],"-unread",0)) { 2966 if (mystrncasecmp(argv[i],"-unread",0)) {
2918 State = SMS_UnRead; 2967 State = SMS_UnRead;
2919 continue; 2968 continue;
2920 } 2969 }
2921 if (mystrncasecmp(argv[i],"-read",0)) { 2970 if (mystrncasecmp(argv[i],"-read",0)) {
2922 State = SMS_Read; 2971 State = SMS_Read;
2923 continue; 2972 continue;
2924 } 2973 }
2925 if (mystrncasecmp(argv[i],"-unsent",0)) { 2974 if (mystrncasecmp(argv[i],"-unsent",0)) {
2926 State = SMS_UnSent; 2975 State = SMS_UnSent;
2927 continue; 2976 continue;
2928 } 2977 }
2929 if (mystrncasecmp(argv[i],"-sent",0)) { 2978 if (mystrncasecmp(argv[i],"-sent",0)) {
2930 State = SMS_Sent; 2979 State = SMS_Sent;
2931 continue; 2980 continue;
2932 } 2981 }
2933 if (mystrncasecmp(argv[i],"-sender",0)) { 2982 if (mystrncasecmp(argv[i],"-sender",0)) {
2934 nextlong=2; 2983 nextlong=2;
2935 continue; 2984 continue;
2936 } 2985 }
2937 } else { 2986 } else {
2938 if (mystrncasecmp(argv[i],"-save",0)) { 2987 if (mystrncasecmp(argv[i],"-save",0)) {
2939 SendSaved=true; 2988 SendSaved=true;
2940 continue; 2989 continue;
2941 } 2990 }
2942 if (mystrncasecmp(argv[i],"-report",0)) { 2991 if (mystrncasecmp(argv[i],"-report",0)) {
2943 DeliveryReport=true; 2992 DeliveryReport=true;
2944 continue; 2993 continue;
2945 } 2994 }
2946 if (mystrncasecmp(argv[i],"-validity",0)) { 2995 if (mystrncasecmp(argv[i],"-validity",0)) {
2947 nextlong=10; 2996 nextlong=10;
2948 continue; 2997 continue;
2949 } 2998 }
2950 } 2999 }
2951 if (mystrncasecmp(argv[i],"-smscset",0)) { 3000 if (mystrncasecmp(argv[i],"-smscset",0)) {
2952 nextlong=3; 3001 nextlong=3;
2953 continue; 3002 continue;
2954 } 3003 }
2955 if (mystrncasecmp(argv[i],"-smscnumber",0)) { 3004 if (mystrncasecmp(argv[i],"-smscnumber",0)) {
2956 nextlong=4; 3005 nextlong=4;
2957 continue; 3006 continue;
2958 } 3007 }
2959 if (mystrncasecmp(argv[i],"-protected",0)) { 3008 if (mystrncasecmp(argv[i],"-protected",0)) {
2960 nextlong=19; 3009 nextlong=19;
2961 continue; 3010 continue;
2962 } 3011 }
2963 if (mystrncasecmp(argv[i],"-reply",0)) { 3012 if (mystrncasecmp(argv[i],"-reply",0)) {
2964 ReplyViaSameSMSC=true; 3013 ReplyViaSameSMSC=true;
2965 continue; 3014 continue;
2966 } 3015 }
2967 if (mystrncasecmp(argv[i],"-maxsms",0)) { 3016 if (mystrncasecmp(argv[i],"-maxsms",0)) {
2968 nextlong=21; 3017 nextlong=21;
2969 continue; 3018 continue;
2970 } 3019 }
2971 if (mystrncasecmp(argv[2],"RINGTONE",0)) { 3020 if (mystrncasecmp(argv[2],"RINGTONE",0)) {
2972 if (mystrncasecmp(argv[i],"-long",0)) { 3021 if (mystrncasecmp(argv[i],"-long",0)) {
2973 SMSInfo.Entries[0].ID = SMS_NokiaRingtoneLong; 3022 SMSInfo.Entries[0].ID = SMS_NokiaRingtoneLong;
2974 break; 3023 break;
2975 } 3024 }
2976 if (mystrncasecmp(argv[i],"-scale",0)) { 3025 if (mystrncasecmp(argv[i],"-scale",0)) {
2977 ringtone[0].NoteTone.AllNotesScale=true; 3026 ringtone[0].NoteTone.AllNotesScale=true;
2978 break; 3027 break;
2979 } 3028 }
2980 } 3029 }
2981 if (mystrncasecmp(argv[2],"TEXT",0)) { 3030 if (mystrncasecmp(argv[2],"TEXT",0)) {
2982 if (mystrncasecmp(argv[i],"-inputunicode",0)) { 3031 if (mystrncasecmp(argv[i],"-inputunicode",0)) {
2983 ReadUnicodeFile(Buffer[0],InputBuffer); 3032 ReadUnicodeFile(Buffer[0],InputBuffer);
2984 break; 3033 break;
2985 } 3034 }
2986 if (mystrncasecmp(argv[i],"-16bit",0)) { 3035 if (mystrncasecmp(argv[i],"-16bit",0)) {
2987 if (SMSInfo.Entries[0].ID == SMS_ConcatenatedTextLong) SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong16bit; 3036 if (SMSInfo.Entries[0].ID == SMS_ConcatenatedTextLong) SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong16bit;
2988 if (SMSInfo.Entries[0].ID == SMS_ConcatenatedAutoTextLong) SMSInfo.Entries[0].ID = SMS_ConcatenatedAutoTextLong16bit; 3037 if (SMSInfo.Entries[0].ID == SMS_ConcatenatedAutoTextLong) SMSInfo.Entries[0].ID = SMS_ConcatenatedAutoTextLong16bit;
2989 break; 3038 break;
2990 } 3039 }
2991 if (mystrncasecmp(argv[i],"-flash",0)) { 3040 if (mystrncasecmp(argv[i],"-flash",0)) {
2992 SMSInfo.Class = 0; 3041 SMSInfo.Class = 0;
2993 break; 3042 break;
2994 } 3043 }
2995 if (mystrncasecmp(argv[i],"-len",0)) { 3044 if (mystrncasecmp(argv[i],"-len",0)) {
2996 nextlong = 5; 3045 nextlong = 5;
2997 break; 3046 break;
2998 } 3047 }
2999 if (mystrncasecmp(argv[i],"-autolen",0)) { 3048 if (mystrncasecmp(argv[i],"-autolen",0)) {
3000 nextlong = 5; 3049 nextlong = 5;
3001 break; 3050 break;
3002 } 3051 }
3003 if (mystrncasecmp(argv[i],"-unicode",0)) { 3052 if (mystrncasecmp(argv[i],"-unicode",0)) {
3004 SMSInfo.UnicodeCoding = true; 3053 SMSInfo.UnicodeCoding = true;
3005 break; 3054 break;
3006 } 3055 }
3007 if (mystrncasecmp(argv[i],"-enablevoice",0)) { 3056 if (mystrncasecmp(argv[i],"-enablevoice",0)) {
3008 SMSInfo.Entries[0].ID = SMS_EnableVoice; 3057 SMSInfo.Entries[0].ID = SMS_EnableVoice;
3009 break; 3058 break;
3010 } 3059 }
3011 if (mystrncasecmp(argv[i],"-disablevoice",0)) { 3060 if (mystrncasecmp(argv[i],"-disablevoice",0)) {
3012 SMSInfo.Entries[0].ID = SMS_DisableVoice; 3061 SMSInfo.Entries[0].ID = SMS_DisableVoice;
3013 break; 3062 break;
3014 } 3063 }
3015 if (mystrncasecmp(argv[i],"-enablefax",0)) { 3064 if (mystrncasecmp(argv[i],"-enablefax",0)) {
3016 SMSInfo.Entries[0].ID = SMS_EnableFax; 3065 SMSInfo.Entries[0].ID = SMS_EnableFax;
3017 break; 3066 break;
3018 } 3067 }
3019 if (mystrncasecmp(argv[i],"-disablefax",0)) { 3068 if (mystrncasecmp(argv[i],"-disablefax",0)) {
3020 SMSInfo.Entries[0].ID = SMS_DisableFax; 3069 SMSInfo.Entries[0].ID = SMS_DisableFax;
3021 break; 3070 break;
3022 } 3071 }
3023 if (mystrncasecmp(argv[i],"-enableemail",0)) { 3072 if (mystrncasecmp(argv[i],"-enableemail",0)) {
3024 SMSInfo.Entries[0].ID = SMS_EnableEmail; 3073 SMSInfo.Entries[0].ID = SMS_EnableEmail;
3025 break; 3074 break;
3026 } 3075 }
3027 if (mystrncasecmp(argv[i],"-disableemail",0)) { 3076 if (mystrncasecmp(argv[i],"-disableemail",0)) {
3028 SMSInfo.Entries[0].ID = SMS_DisableEmail; 3077 SMSInfo.Entries[0].ID = SMS_DisableEmail;
3029 break; 3078 break;
3030 } 3079 }
3031 if (mystrncasecmp(argv[i],"-voidsms",0)) { 3080 if (mystrncasecmp(argv[i],"-voidsms",0)) {
3032 SMSInfo.Entries[0].ID = SMS_VoidSMS; 3081 SMSInfo.Entries[0].ID = SMS_VoidSMS;
3033 break; 3082 break;
3034 } 3083 }
3035 if (mystrncasecmp(argv[i],"-replacemessages",0) && 3084 if (mystrncasecmp(argv[i],"-replacemessages",0) &&
3036 SMSInfo.Entries[0].ID != SMS_ConcatenatedTextLong) { 3085 SMSInfo.Entries[0].ID != SMS_ConcatenatedTextLong) {
3037 nextlong = 8; 3086 nextlong = 8;
3038 break; 3087 break;
3039 } 3088 }
3040 if (mystrncasecmp(argv[i],"-replacefile",0)) { 3089 if (mystrncasecmp(argv[i],"-replacefile",0)) {
3041 nextlong = 9; 3090 nextlong = 9;
3042 continue; 3091 continue;
3043 } 3092 }
3044 } 3093 }
3045 if (mystrncasecmp(argv[2],"PICTURE",0)) { 3094 if (mystrncasecmp(argv[2],"PICTURE",0)) {
3046 if (mystrncasecmp(argv[i],"-text",0)) { 3095 if (mystrncasecmp(argv[i],"-text",0)) {
3047 nextlong = 6; 3096 nextlong = 6;
3048 break; 3097 break;
3049 } 3098 }
3050 if (mystrncasecmp(argv[i],"-unicode",0)) { 3099 if (mystrncasecmp(argv[i],"-unicode",0)) {
3051 SMSInfo.UnicodeCoding = true; 3100 SMSInfo.UnicodeCoding = true;
@@ -3620,1567 +3669,1669 @@ static void SendSaveDisplaySMS(int argc, char *argv[])
3620 } 3669 }
3621 } 3670 }
3622 } 3671 }
3623 } 3672 }
3624 } 3673 }
3625 3674
3626 error=GSM_EncodeMultiPartSMS(&SMSInfo,&sms); 3675 error=GSM_EncodeMultiPartSMS(&SMSInfo,&sms);
3627 Print_Error(error); 3676 Print_Error(error);
3628 3677
3629 for (i=0;i<SMSInfo.EntriesNum;i++) { 3678 for (i=0;i<SMSInfo.EntriesNum;i++) {
3630 switch (SMSInfo.Entries[i].ID) { 3679 switch (SMSInfo.Entries[i].ID) {
3631 case SMS_NokiaRingtone: 3680 case SMS_NokiaRingtone:
3632 case SMS_NokiaRingtoneLong: 3681 case SMS_NokiaRingtoneLong:
3633 case SMS_NokiaProfileLong: 3682 case SMS_NokiaProfileLong:
3634 case SMS_EMSSound10: 3683 case SMS_EMSSound10:
3635 case SMS_EMSSound12: 3684 case SMS_EMSSound12:
3636 case SMS_EMSSonyEricssonSound: 3685 case SMS_EMSSonyEricssonSound:
3637 case SMS_EMSSound10Long: 3686 case SMS_EMSSound10Long:
3638 case SMS_EMSSound12Long: 3687 case SMS_EMSSound12Long:
3639 case SMS_EMSSonyEricssonSoundLong: 3688 case SMS_EMSSonyEricssonSoundLong:
3640 if (SMSInfo.Entries[i].RingtoneNotes!=SMSInfo.Entries[i].Ringtone->NoteTone.NrCommands) { 3689 if (SMSInfo.Entries[i].RingtoneNotes!=SMSInfo.Entries[i].Ringtone->NoteTone.NrCommands) {
3641 printmsg("Warning: ringtone too long. %i percent part cut\n", 3690 printmsg("Warning: ringtone too long. %i percent part cut\n",
3642 (SMSInfo.Entries[i].Ringtone->NoteTone.NrCommands-SMSInfo.Entries[i].RingtoneNotes)*100/SMSInfo.Entries[i].Ringtone->NoteTone.NrCommands); 3691 (SMSInfo.Entries[i].Ringtone->NoteTone.NrCommands-SMSInfo.Entries[i].RingtoneNotes)*100/SMSInfo.Entries[i].Ringtone->NoteTone.NrCommands);
3643 } 3692 }
3644 default: 3693 default:
3645 break; 3694 break;
3646 3695
3647 } 3696 }
3648 } 3697 }
3649 if (MaxSMS != -1 && sms.Number > MaxSMS) { 3698 if (MaxSMS != -1 && sms.Number > MaxSMS) {
3650 printmsg("There is %i SMS packed and %i limit. Exiting\n",sms.Number,MaxSMS); 3699 printmsg("There is %i SMS packed and %i limit. Exiting\n",sms.Number,MaxSMS);
3651 if (!mystrncasecmp(argv[1],"--displaysms",0) && !mystrncasecmp(argv[1],"--sendsmsdsms",0)) GSM_Terminate(); 3700 if (!mystrncasecmp(argv[1],"--displaysms",0) && !mystrncasecmp(argv[1],"--sendsmsdsms",0)) GSM_Terminate();
3652 exit(-1); 3701 exit(-1);
3653 } 3702 }
3654 3703
3655 if (mystrncasecmp(argv[1],"--displaysms",0)) { 3704 if (mystrncasecmp(argv[1],"--displaysms",0)) {
3656 if (SMSCSet != 0) { 3705 if (SMSCSet != 0) {
3657 printmsg("Use -smscnumber option to give SMSC number\n"); 3706 printmsg("Use -smscnumber option to give SMSC number\n");
3658 exit(-1); 3707 exit(-1);
3659 } 3708 }
3660 3709
3661 for (i=0;i<sms.Number;i++) { 3710 for (i=0;i<sms.Number;i++) {
3662 sms.SMS[i].Location = 0; 3711 sms.SMS[i].Location = 0;
3663 sms.SMS[i].ReplyViaSameSMSC = ReplyViaSameSMSC; 3712 sms.SMS[i].ReplyViaSameSMSC = ReplyViaSameSMSC;
3664 sms.SMS[i].SMSC.Location = 0; 3713 sms.SMS[i].SMSC.Location = 0;
3665 sms.SMS[i].PDU = SMS_Submit; 3714 sms.SMS[i].PDU = SMS_Submit;
3666 if (DeliveryReport) sms.SMS[i].PDU= SMS_Status_Report; 3715 if (DeliveryReport) sms.SMS[i].PDU= SMS_Status_Report;
3667 CopyUnicodeString(sms.SMS[i].Number, Sender); 3716 CopyUnicodeString(sms.SMS[i].Number, Sender);
3668 CopyUnicodeString(sms.SMS[i].SMSC.Number, SMSC); 3717 CopyUnicodeString(sms.SMS[i].SMSC.Number, SMSC);
3669 if (Validity.Format != 0) memcpy(&sms.SMS[i].SMSC.Validity,&Validity,sizeof(GSM_SMSValidity)); 3718 if (Validity.Format != 0) memcpy(&sms.SMS[i].SMSC.Validity,&Validity,sizeof(GSM_SMSValidity));
3670 DisplaySMSFrame(&sms.SMS[i]); 3719 DisplaySMSFrame(&sms.SMS[i]);
3671 } 3720 }
3672 3721
3673 printmsg("\nNumber of SMS: %i\n",sms.Number); 3722 printmsg("\nNumber of SMS: %i\n",sms.Number);
3674 exit(sms.Number); 3723 exit(sms.Number);
3675 } 3724 }
3676 if (mystrncasecmp(argv[1],"--sendsmsdsms",0)) { 3725 if (mystrncasecmp(argv[1],"--sendsmsdsms",0)) {
3677 if (SMSCSet != 0) { 3726 if (SMSCSet != 0) {
3678 printmsg("Use -smscnumber option to give SMSC number\n"); 3727 printmsg("Use -smscnumber option to give SMSC number\n");
3679 exit(-1); 3728 exit(-1);
3680 } 3729 }
3681 3730
3682 for (i=0;i<sms.Number;i++) { 3731 for (i=0;i<sms.Number;i++) {
3683 sms.SMS[i].Location = 0; 3732 sms.SMS[i].Location = 0;
3684 sms.SMS[i].ReplyViaSameSMSC = ReplyViaSameSMSC; 3733 sms.SMS[i].ReplyViaSameSMSC = ReplyViaSameSMSC;
3685 sms.SMS[i].SMSC.Location = 0; 3734 sms.SMS[i].SMSC.Location = 0;
3686 sms.SMS[i].PDU = SMS_Submit; 3735 sms.SMS[i].PDU = SMS_Submit;
3687 if (DeliveryReport) sms.SMS[i].PDU= SMS_Status_Report; 3736 if (DeliveryReport) sms.SMS[i].PDU= SMS_Status_Report;
3688 CopyUnicodeString(sms.SMS[i].Number, Sender); 3737 CopyUnicodeString(sms.SMS[i].Number, Sender);
3689 CopyUnicodeString(sms.SMS[i].SMSC.Number, SMSC); 3738 CopyUnicodeString(sms.SMS[i].SMSC.Number, SMSC);
3690 if (Validity.Format != 0) memcpy(&sms.SMS[i].SMSC.Validity,&Validity,sizeof(GSM_SMSValidity)); 3739 if (Validity.Format != 0) memcpy(&sms.SMS[i].SMSC.Validity,&Validity,sizeof(GSM_SMSValidity));
3691 } 3740 }
3692 SMSDaemonSendSMS(argv[4],argv[5],&sms); 3741 SMSDaemonSendSMS(argv[4],argv[5],&sms);
3693 exit(0); 3742 exit(0);
3694 } 3743 }
3695 if (mystrncasecmp(argv[1],"--savesms",0) || SendSaved) { 3744 if (mystrncasecmp(argv[1],"--savesms",0) || SendSaved) {
3696 error=Phone->GetSMSFolders(&s, &folders); 3745 error=Phone->GetSMSFolders(&s, &folders);
3697 Print_Error(error); 3746 Print_Error(error);
3698 3747
3699 if (SendSaved){ 3748 if (SendSaved){
3700 if (Validity.Format != 0 && SMSCSet != 0) { 3749 if (Validity.Format != 0 && SMSCSet != 0) {
3701 PhoneSMSC.Location = SMSCSet; 3750 PhoneSMSC.Location = SMSCSet;
3702 error=Phone->GetSMSC(&s,&PhoneSMSC); 3751 error=Phone->GetSMSC(&s,&PhoneSMSC);
3703 Print_Error(error); 3752 Print_Error(error);
3704 CopyUnicodeString(SMSC,PhoneSMSC.Number); 3753 CopyUnicodeString(SMSC,PhoneSMSC.Number);
3705 SMSCSet = 0; 3754 SMSCSet = 0;
3706 } 3755 }
3707 3756
3708 s.User.SendSMSStatus = SendSMSStatus; 3757 s.User.SendSMSStatus = SendSMSStatus;
3709 3758
3710 signal(SIGINT, interrupt); 3759 signal(SIGINT, interrupt);
3711 printmsgerr("If you want break, press Ctrl+C...\n"); 3760 printmsgerr("If you want break, press Ctrl+C...\n");
3712 } 3761 }
3713 3762
3714 for (i=0;i<sms.Number;i++) { 3763 for (i=0;i<sms.Number;i++) {
3715 printmsg("Saving SMS %i/%i\n",i+1,sms.Number); 3764 printmsg("Saving SMS %i/%i\n",i+1,sms.Number);
3716 // sms.SMS[i].Location = 0; 3765 // sms.SMS[i].Location = 0;
3717 sms.SMS[i].Folder = Folder; 3766 sms.SMS[i].Folder = Folder;
3718 sms.SMS[i].State = State; 3767 sms.SMS[i].State = State;
3719 sms.SMS[i].ReplyViaSameSMSC= ReplyViaSameSMSC; 3768 sms.SMS[i].ReplyViaSameSMSC= ReplyViaSameSMSC;
3720 sms.SMS[i].SMSC.Location= SMSCSet; 3769 sms.SMS[i].SMSC.Location= SMSCSet;
3721 3770
3722 if (SendSaved){ 3771 if (SendSaved){
3723 sms.SMS[i].PDU= SMS_Submit; 3772 sms.SMS[i].PDU= SMS_Submit;
3724 if (DeliveryReport) sms.SMS[i].PDU = SMS_Status_Report; 3773 if (DeliveryReport) sms.SMS[i].PDU = SMS_Status_Report;
3725 if (Validity.Format != 0) sms.SMS[i].SMSC.Validity = Validity; 3774 if (Validity.Format != 0) sms.SMS[i].SMSC.Validity = Validity;
3726 } else { 3775 } else {
3727 sms.SMS[i].PDU= SMS_Deliver; 3776 sms.SMS[i].PDU= SMS_Deliver;
3728 } 3777 }
3729 3778
3730 CopyUnicodeString(sms.SMS[i].Number, Sender); 3779 CopyUnicodeString(sms.SMS[i].Number, Sender);
3731 CopyUnicodeString(sms.SMS[i].Name, Name); 3780 CopyUnicodeString(sms.SMS[i].Name, Name);
3732 if (SMSCSet==0) CopyUnicodeString(sms.SMS[i].SMSC.Number, SMSC); 3781 if (SMSCSet==0) CopyUnicodeString(sms.SMS[i].SMSC.Number, SMSC);
3733 error=Phone->AddSMS(&s, &sms.SMS[i]); 3782 error=Phone->AddSMS(&s, &sms.SMS[i]);
3734 Print_Error(error); 3783 Print_Error(error);
3735 printmsg("Saved in folder \"%s\", location %i\n", 3784 printmsg("Saved in folder \"%s\", location %i\n",
3736 DecodeUnicodeConsole(folders.Folder[sms.SMS[i].Folder-1].Name),sms.SMS[i].Location); 3785 DecodeUnicodeConsole(folders.Folder[sms.SMS[i].Folder-1].Name),sms.SMS[i].Location);
3737 3786
3738 if (SendSaved) { 3787 if (SendSaved) {
3739 printmsg("Sending sms from folder \"%s\", location %i\n", 3788 printmsg("Sending sms from folder \"%s\", location %i\n",
3740 DecodeUnicodeString(folders.Folder[sms.SMS[i].Folder-1].Name),sms.SMS[i].Location); 3789 DecodeUnicodeString(folders.Folder[sms.SMS[i].Folder-1].Name),sms.SMS[i].Location);
3741 SMSStatus = ERR_TIMEOUT; 3790 SMSStatus = ERR_TIMEOUT;
3742 error=Phone->SendSavedSMS(&s, 0, sms.SMS[i].Location); 3791 error=Phone->SendSavedSMS(&s, 0, sms.SMS[i].Location);
3743 Print_Error(error); 3792 Print_Error(error);
3744 printmsg("....waiting for network answer"); 3793 printmsg("....waiting for network answer");
3745 while (!gshutdown) { 3794 while (!gshutdown) {
3746 GSM_ReadDevice(&s,true); 3795 GSM_ReadDevice(&s,true);
3747 if (SMSStatus == ERR_UNKNOWN) { 3796 if (SMSStatus == ERR_UNKNOWN) {
3748 GSM_Terminate(); 3797 GSM_Terminate();
3749 exit(-1); 3798 exit(-1);
3750 } 3799 }
3751 if (SMSStatus == ERR_NONE) break; 3800 if (SMSStatus == ERR_NONE) break;
3752 } 3801 }
3753 } 3802 }
3754 } 3803 }
3755 } else { 3804 } else {
3756 if (Validity.Format != 0 && SMSCSet != 0) { 3805 if (Validity.Format != 0 && SMSCSet != 0) {
3757 PhoneSMSC.Location = SMSCSet; 3806 PhoneSMSC.Location = SMSCSet;
3758 error=Phone->GetSMSC(&s,&PhoneSMSC); 3807 error=Phone->GetSMSC(&s,&PhoneSMSC);
3759 Print_Error(error); 3808 Print_Error(error);
3760 CopyUnicodeString(SMSC,PhoneSMSC.Number); 3809 CopyUnicodeString(SMSC,PhoneSMSC.Number);
3761 SMSCSet = 0; 3810 SMSCSet = 0;
3762 } 3811 }
3763 3812
3764 signal(SIGINT, interrupt); 3813 signal(SIGINT, interrupt);
3765 printmsgerr("If you want break, press Ctrl+C...\n"); 3814 printmsgerr("If you want break, press Ctrl+C...\n");
3766 3815
3767 s.User.SendSMSStatus = SendSMSStatus; 3816 s.User.SendSMSStatus = SendSMSStatus;
3768 3817
3769 for (i=0;i<sms.Number;i++) { 3818 for (i=0;i<sms.Number;i++) {
3770 printmsg("Sending SMS %i/%i",i+1,sms.Number); 3819 printmsg("Sending SMS %i/%i",i+1,sms.Number);
3771 sms.SMS[i].Location = 0; 3820 sms.SMS[i].Location = 0;
3772 sms.SMS[i].ReplyViaSameSMSC = ReplyViaSameSMSC; 3821 sms.SMS[i].ReplyViaSameSMSC = ReplyViaSameSMSC;
3773 sms.SMS[i].SMSC.Location = SMSCSet; 3822 sms.SMS[i].SMSC.Location = SMSCSet;
3774 sms.SMS[i].PDU = SMS_Submit; 3823 sms.SMS[i].PDU = SMS_Submit;
3775 if (DeliveryReport) sms.SMS[i].PDU= SMS_Status_Report; 3824 if (DeliveryReport) sms.SMS[i].PDU= SMS_Status_Report;
3776 CopyUnicodeString(sms.SMS[i].Number, Sender); 3825 CopyUnicodeString(sms.SMS[i].Number, Sender);
3777 if (SMSCSet==0) CopyUnicodeString(sms.SMS[i].SMSC.Number, SMSC); 3826 if (SMSCSet==0) CopyUnicodeString(sms.SMS[i].SMSC.Number, SMSC);
3778 if (Validity.Format != 0) memcpy(&sms.SMS[i].SMSC.Validity,&Validity,sizeof(GSM_SMSValidity)); 3827 if (Validity.Format != 0) memcpy(&sms.SMS[i].SMSC.Validity,&Validity,sizeof(GSM_SMSValidity));
3779 SMSStatus = ERR_TIMEOUT; 3828 SMSStatus = ERR_TIMEOUT;
3780 error=Phone->SendSMS(&s, &sms.SMS[i]); 3829 error=Phone->SendSMS(&s, &sms.SMS[i]);
3781 Print_Error(error); 3830 Print_Error(error);
3782 printmsg("....waiting for network answer"); 3831 printmsg("....waiting for network answer");
3783 while (!gshutdown) { 3832 while (!gshutdown) {
3784 GSM_ReadDevice(&s,true); 3833 GSM_ReadDevice(&s,true);
3785 if (SMSStatus == ERR_UNKNOWN) { 3834 if (SMSStatus == ERR_UNKNOWN) {
3786 GSM_Terminate(); 3835 GSM_Terminate();
3787 exit(-1); 3836 exit(-1);
3788 } 3837 }
3789 if (SMSStatus == ERR_NONE) break; 3838 if (SMSStatus == ERR_NONE) break;
3790 } 3839 }
3791 } 3840 }
3792 } 3841 }
3793 3842
3794 GSM_Terminate(); 3843 GSM_Terminate();
3795} 3844}
3796 3845
3797#ifdef GSM_ENABLE_BACKUP 3846#ifdef GSM_ENABLE_BACKUP
3798static void SaveFile(int argc, char *argv[]) 3847static void SaveFile(int argc, char *argv[])
3799{ 3848{
3800 GSM_Backup Backup; 3849 GSM_Backup Backup;
3801 int i,j; 3850 int i,j;
3802 FILE *file; 3851 FILE *file;
3803 unsigned char Buffer[10000]; 3852 unsigned char Buffer[10000];
3804 GSM_MemoryEntry *pbk; 3853 GSM_MemoryEntry *pbk;
3805 3854
3806 if (mystrncasecmp(argv[2],"CALENDAR",0)) { 3855 if (mystrncasecmp(argv[2],"CALENDAR",0)) {
3807 if (argc<5) { 3856 if (argc<5) {
3808 printmsg("Where is backup filename and location ?\n"); 3857 printmsg("Where is backup filename and location ?\n");
3809 exit(-1); 3858 exit(-1);
3810 } 3859 }
3811 error=GSM_ReadBackupFile(argv[4],&Backup); 3860 error=GSM_ReadBackupFile(argv[4],&Backup);
3812 Print_Error(error); 3861 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
3813 i = 0; 3862 i = 0;
3814 while (Backup.Calendar[i]!=NULL) { 3863 while (Backup.Calendar[i]!=NULL) {
3815 if (i == atoi(argv[5])-1) break; 3864 if (i == atoi(argv[5])-1) break;
3816 i++; 3865 i++;
3817 } 3866 }
3818 if (i != atoi(argv[5])-1) { 3867 if (i != atoi(argv[5])-1) {
3819 printmsg("Calendar note not found in file\n"); 3868 printmsg("Calendar note not found in file\n");
3820 exit(-1); 3869 exit(-1);
3821 } 3870 }
3822 j = 0; 3871 j = 0;
3823 GSM_EncodeVCALENDAR(Buffer, &j, Backup.Calendar[i],true,Nokia_VCalendar); 3872 GSM_EncodeVCALENDAR(Buffer, &j, Backup.Calendar[i],true,Nokia_VCalendar);
3824 } else if (mystrncasecmp(argv[2],"BOOKMARK",0)) { 3873 } else if (mystrncasecmp(argv[2],"BOOKMARK",0)) {
3825 if (argc<5) { 3874 if (argc<5) {
3826 printmsg("Where is backup filename and location ?\n"); 3875 printmsg("Where is backup filename and location ?\n");
3827 exit(-1); 3876 exit(-1);
3828 } 3877 }
3829 error=GSM_ReadBackupFile(argv[4],&Backup); 3878 error=GSM_ReadBackupFile(argv[4],&Backup);
3830 Print_Error(error); 3879 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
3831 i = 0; 3880 i = 0;
3832 while (Backup.WAPBookmark[i]!=NULL) { 3881 while (Backup.WAPBookmark[i]!=NULL) {
3833 if (i == atoi(argv[5])-1) break; 3882 if (i == atoi(argv[5])-1) break;
3834 i++; 3883 i++;
3835 } 3884 }
3836 if (i != atoi(argv[5])-1) { 3885 if (i != atoi(argv[5])-1) {
3837 printmsg("WAP bookmark not found in file\n"); 3886 printmsg("WAP bookmark not found in file\n");
3838 exit(-1); 3887 exit(-1);
3839 } 3888 }
3840 j = 0; 3889 j = 0;
3841 GSM_EncodeURLFile(Buffer, &j, Backup.WAPBookmark[i]); 3890 GSM_EncodeURLFile(Buffer, &j, Backup.WAPBookmark[i]);
3842 } else if (mystrncasecmp(argv[2],"NOTE",0)) { 3891 } else if (mystrncasecmp(argv[2],"NOTE",0)) {
3843 if (argc<5) { 3892 if (argc<5) {
3844 printmsg("Where is backup filename and location ?\n"); 3893 printmsg("Where is backup filename and location ?\n");
3845 exit(-1); 3894 exit(-1);
3846 } 3895 }
3847 error=GSM_ReadBackupFile(argv[4],&Backup); 3896 error=GSM_ReadBackupFile(argv[4],&Backup);
3848 Print_Error(error); 3897 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
3849 i = 0; 3898 i = 0;
3850 while (Backup.Note[i]!=NULL) { 3899 while (Backup.Note[i]!=NULL) {
3851 if (i == atoi(argv[5])-1) break; 3900 if (i == atoi(argv[5])-1) break;
3852 i++; 3901 i++;
3853 } 3902 }
3854 if (i != atoi(argv[5])-1) { 3903 if (i != atoi(argv[5])-1) {
3855 printmsg("Note not found in file\n"); 3904 printmsg("Note not found in file\n");
3856 exit(-1); 3905 exit(-1);
3857 } 3906 }
3858 j = 0; 3907 j = 0;
3859 GSM_EncodeVNTFile(Buffer, &j, Backup.Note[i]); 3908 GSM_EncodeVNTFile(Buffer, &j, Backup.Note[i]);
3860 } else if (mystrncasecmp(argv[2],"TODO",0)) { 3909 } else if (mystrncasecmp(argv[2],"TODO",0)) {
3861 if (argc<5) { 3910 if (argc<5) {
3862 printmsg("Where is backup filename and location ?\n"); 3911 printmsg("Where is backup filename and location ?\n");
3863 exit(-1); 3912 exit(-1);
3864 } 3913 }
3865 error=GSM_ReadBackupFile(argv[4],&Backup); 3914 error=GSM_ReadBackupFile(argv[4],&Backup);
3866 Print_Error(error); 3915 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
3867 i = 0; 3916 i = 0;
3868 while (Backup.ToDo[i]!=NULL) { 3917 while (Backup.ToDo[i]!=NULL) {
3869 if (i == atoi(argv[5])-1) break; 3918 if (i == atoi(argv[5])-1) break;
3870 i++; 3919 i++;
3871 } 3920 }
3872 if (i != atoi(argv[5])-1) { 3921 if (i != atoi(argv[5])-1) {
3873 printmsg("ToDo note not found in file\n"); 3922 printmsg("ToDo note not found in file\n");
3874 exit(-1); 3923 exit(-1);
3875 } 3924 }
3876 j = 0; 3925 j = 0;
3877 GSM_EncodeVTODO(Buffer, &j, Backup.ToDo[i], true, Nokia_VToDo); 3926 GSM_EncodeVTODO(Buffer, &j, Backup.ToDo[i], true, Nokia_VToDo);
3878 } else if (mystrncasecmp(argv[2],"VCARD10",0) || mystrncasecmp(argv[2],"VCARD21",0)) { 3927 } else if (mystrncasecmp(argv[2],"VCARD10",0) || mystrncasecmp(argv[2],"VCARD21",0)) {
3879 if (argc<6) { 3928 if (argc<6) {
3880 printmsg("Where is backup filename and location and memory type ?\n"); 3929 printmsg("Where is backup filename and location and memory type ?\n");
3881 exit(-1); 3930 exit(-1);
3882 } 3931 }
3883 error=GSM_ReadBackupFile(argv[4],&Backup); 3932 error=GSM_ReadBackupFile(argv[4],&Backup);
3884 Print_Error(error); 3933 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
3885 i = 0; 3934 i = 0;
3886 if (mystrncasecmp(argv[5],"SM",0)) { 3935 if (mystrncasecmp(argv[5],"SM",0)) {
3887 while (Backup.SIMPhonebook[i]!=NULL) { 3936 while (Backup.SIMPhonebook[i]!=NULL) {
3888 if (i == atoi(argv[6])-1) break; 3937 if (i == atoi(argv[6])-1) break;
3889 i++; 3938 i++;
3890 } 3939 }
3891 if (i != atoi(argv[6])-1) { 3940 if (i != atoi(argv[6])-1) {
3892 printmsg("Phonebook entry not found in file\n"); 3941 printmsg("Phonebook entry not found in file\n");
3893 exit(-1); 3942 exit(-1);
3894 } 3943 }
3895 pbk = Backup.SIMPhonebook[i]; 3944 pbk = Backup.SIMPhonebook[i];
3896 } else if (mystrncasecmp(argv[5],"ME",0)) { 3945 } else if (mystrncasecmp(argv[5],"ME",0)) {
3897 while (Backup.PhonePhonebook[i]!=NULL) { 3946 while (Backup.PhonePhonebook[i]!=NULL) {
3898 if (i == atoi(argv[6])-1) break; 3947 if (i == atoi(argv[6])-1) break;
3899 i++; 3948 i++;
3900 } 3949 }
3901 if (i != atoi(argv[6])-1) { 3950 if (i != atoi(argv[6])-1) {
3902 printmsg("Phonebook entry not found in file\n"); 3951 printmsg("Phonebook entry not found in file\n");
3903 exit(-1); 3952 exit(-1);
3904 } 3953 }
3905 pbk = Backup.PhonePhonebook[i]; 3954 pbk = Backup.PhonePhonebook[i];
3906 } else { 3955 } else {
3907 printmsg("Unknown memory type: \"%s\"\n",argv[5]); 3956 printmsg("Unknown memory type: \"%s\"\n",argv[5]);
3908 exit(-1); 3957 exit(-1);
3909 } 3958 }
3910 j = 0; 3959 j = 0;
3911 if (mystrncasecmp(argv[2],"VCARD10",0)) { 3960 if (mystrncasecmp(argv[2],"VCARD10",0)) {
3912 GSM_EncodeVCARD(Buffer,&j,pbk,true,Nokia_VCard10); 3961 GSM_EncodeVCARD(Buffer,&j,pbk,true,Nokia_VCard10);
3913 } else { 3962 } else {
3914 GSM_EncodeVCARD(Buffer,&j,pbk,true,Nokia_VCard21); 3963 GSM_EncodeVCARD(Buffer,&j,pbk,true,Nokia_VCard21);
3915 } 3964 }
3916 } else { 3965 } else {
3917 printmsg("What format of file (\"%s\") ?\n",argv[2]); 3966 printmsg("What format of file (\"%s\") ?\n",argv[2]);
3918 exit(-1); 3967 exit(-1);
3919 } 3968 }
3920 3969
3921 file = fopen(argv[3],"wb"); 3970 file = fopen(argv[3],"wb");
3922 fwrite(Buffer,1,j,file); 3971 fwrite(Buffer,1,j,file);
3923 fclose(file); 3972 fclose(file);
3924} 3973}
3925 3974
3926static void Backup(int argc, char *argv[]) 3975static void Backup(int argc, char *argv[])
3927{ 3976{
3928 int i, used; 3977 int i, used;
3929 GSM_MemoryStatusMemStatus; 3978 GSM_MemoryStatusMemStatus;
3930 GSM_ToDoEntry ToDo; 3979 GSM_ToDoEntry ToDo;
3931 GSM_ToDoStatus ToDoStatus; 3980 GSM_ToDoStatus ToDoStatus;
3932 GSM_MemoryEntry Pbk; 3981 GSM_MemoryEntry Pbk;
3933 GSM_CalendarEntryNote; 3982 GSM_CalendarEntryCalendar;
3934 GSM_Bitmap Bitmap; 3983 GSM_Bitmap Bitmap;
3935 GSM_WAPBookmark Bookmark; 3984 GSM_WAPBookmark Bookmark;
3936 GSM_Profile Profile; 3985 GSM_Profile Profile;
3937 GSM_MultiWAPSettingsSettings; 3986 GSM_MultiWAPSettingsSettings;
3987 GSM_SyncMLSettingsSyncML;
3988 GSM_ChatSettingsChat;
3938 GSM_Ringtone Ringtone; 3989 GSM_Ringtone Ringtone;
3939 GSM_SMSC SMSC; 3990 GSM_SMSC SMSC;
3940 GSM_Backup Backup; 3991 GSM_Backup Backup;
3992 GSM_NoteEntry Note;
3941 GSM_Backup_Info Info; 3993 GSM_Backup_Info Info;
3942 GSM_FMStation FMStation; 3994 GSM_FMStation FMStation;
3943 GSM_GPRSAccessPointGPRSPoint; 3995 GSM_GPRSAccessPointGPRSPoint;
3944 bool DoBackup; 3996 bool DoBackup;
3945 3997
3946 if (argc == 4 && mystrncasecmp(argv[3],"-yes",0)) always_answer_yes = true; 3998 if (argc == 4 && mystrncasecmp(argv[3],"-yes",0)) always_answer_yes = true;
3947 3999
3948 GSM_ClearBackup(&Backup); 4000 GSM_ClearBackup(&Backup);
3949 GSM_GetBackupFormatFeatures(argv[2],&Info); 4001 GSM_GetBackupFormatFeatures(argv[2],&Info);
3950 4002
3951 sprintf(Backup.Creator,"Gammu %s",VERSION); 4003 sprintf(Backup.Creator,"Gammu %s",VERSION);
3952 if (strlen(GetOS()) != 0) { 4004 if (strlen(GetOS()) != 0) {
3953 strcat(Backup.Creator+strlen(Backup.Creator),", "); 4005 strcat(Backup.Creator+strlen(Backup.Creator),", ");
3954 strcat(Backup.Creator+strlen(Backup.Creator),GetOS()); 4006 strcat(Backup.Creator+strlen(Backup.Creator),GetOS());
3955 } 4007 }
3956 if (strlen(GetCompiler()) != 0) { 4008 if (strlen(GetCompiler()) != 0) {
3957 strcat(Backup.Creator+strlen(Backup.Creator),", "); 4009 strcat(Backup.Creator+strlen(Backup.Creator),", ");
3958 strcat(Backup.Creator+strlen(Backup.Creator),GetCompiler()); 4010 strcat(Backup.Creator+strlen(Backup.Creator),GetCompiler());
3959 } 4011 }
3960 4012
3961 signal(SIGINT, interrupt); 4013 signal(SIGINT, interrupt);
3962 printmsgerr("Press Ctrl+C to break...\n"); 4014 printmsgerr("Press Ctrl+C to break...\n");
3963 4015
3964 GSM_Init(true); 4016 GSM_Init(true);
3965 4017
3966 if (Info.UseUnicode) { 4018 if (Info.UseUnicode) {
3967 Info.UseUnicode=answer_yes("Use Unicode subformat of backup file"); 4019 Info.UseUnicode=answer_yes("Use Unicode subformat of backup file");
3968 } 4020 }
3969 if (Info.DateTime) { 4021 if (Info.DateTime) {
3970 GSM_GetCurrentDateTime (&Backup.DateTime); 4022 GSM_GetCurrentDateTime (&Backup.DateTime);
3971 Backup.DateTimeAvailable=true; 4023 Backup.DateTimeAvailable=true;
3972 } 4024 }
3973 if (Info.Model) { 4025 if (Info.Model) {
3974 error=Phone->GetManufacturer(&s); 4026 error=Phone->GetManufacturer(&s);
3975 Print_Error(error); 4027 Print_Error(error);
3976 sprintf(Backup.Model,"%s ",s.Phone.Data.Manufacturer); 4028 sprintf(Backup.Model,"%s ",s.Phone.Data.Manufacturer);
3977 if (s.Phone.Data.ModelInfo->model[0]!=0) { 4029 if (s.Phone.Data.ModelInfo->model[0]!=0) {
3978 strcat(Backup.Model,s.Phone.Data.ModelInfo->model); 4030 strcat(Backup.Model,s.Phone.Data.ModelInfo->model);
3979 } else { 4031 } else {
3980 strcat(Backup.Model,s.Phone.Data.Model); 4032 strcat(Backup.Model,s.Phone.Data.Model);
3981 } 4033 }
3982 strcat(Backup.Model," "); 4034 strcat(Backup.Model," ");
3983 strcat(Backup.Model,s.Phone.Data.Version); 4035 strcat(Backup.Model,s.Phone.Data.Version);
3984 } 4036 }
3985 if (Info.IMEI) { 4037 if (Info.IMEI) {
3986 error=Phone->GetIMEI(&s); 4038 error=Phone->GetIMEI(&s);
3987 if (error != ERR_NOTSUPPORTED) { 4039 if (error != ERR_NOTSUPPORTED) {
3988 strcpy(Backup.IMEI, s.Phone.Data.IMEI); 4040 strcpy(Backup.IMEI, s.Phone.Data.IMEI);
3989 Print_Error(error); 4041 Print_Error(error);
3990 } else { 4042 } else {
3991 Backup.IMEI[0] = 0; 4043 Backup.IMEI[0] = 0;
3992 } 4044 }
3993 } 4045 }
3994 printf("\n"); 4046 printf("\n");
3995 4047
3996 DoBackup = false; 4048 DoBackup = false;
3997 if (Info.PhonePhonebook) { 4049 if (Info.PhonePhonebook) {
3998 printmsg("Checking phone phonebook\n"); 4050 printmsg("Checking phone phonebook\n");
3999 MemStatus.MemoryType = MEM_ME; 4051 MemStatus.MemoryType = MEM_ME;
4000 error=Phone->GetMemoryStatus(&s, &MemStatus); 4052 error=Phone->GetMemoryStatus(&s, &MemStatus);
4001 if (error==ERR_NONE && MemStatus.MemoryUsed != 0) { 4053 if (error==ERR_NONE && MemStatus.MemoryUsed != 0) {
4002 if (answer_yes(" Backup phone phonebook")) DoBackup = true; 4054 if (answer_yes(" Backup phone phonebook")) DoBackup = true;
4003 } 4055 }
4004 } 4056 }
4005 if (DoBackup) { 4057 if (DoBackup) {
4006 Pbk.MemoryType = MEM_ME; 4058 Pbk.MemoryType = MEM_ME;
4007 i = 1; 4059 i = 1;
4008 used = 0; 4060 used = 0;
4009 while (used != MemStatus.MemoryUsed) { 4061 while (used != MemStatus.MemoryUsed) {
4010 Pbk.Location = i; 4062 Pbk.Location = i;
4011 error=Phone->GetMemory(&s, &Pbk); 4063 error=Phone->GetMemory(&s, &Pbk);
4012 if (error != ERR_EMPTY) { 4064 if (error != ERR_EMPTY) {
4013 Print_Error(error); 4065 Print_Error(error);
4014 if (used < GSM_BACKUP_MAX_PHONEPHONEBOOK) { 4066 if (used < GSM_BACKUP_MAX_PHONEPHONEBOOK) {
4015 Backup.PhonePhonebook[used] = malloc(sizeof(GSM_MemoryEntry)); 4067 Backup.PhonePhonebook[used] = malloc(sizeof(GSM_MemoryEntry));
4016 if (Backup.PhonePhonebook[used] == NULL) Print_Error(ERR_MOREMEMORY); 4068 if (Backup.PhonePhonebook[used] == NULL) Print_Error(ERR_MOREMEMORY);
4017 Backup.PhonePhonebook[used+1] = NULL; 4069 Backup.PhonePhonebook[used+1] = NULL;
4018 } else { 4070 } else {
4019 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_PHONEPHONEBOOK"); 4071 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_PHONEPHONEBOOK");
4020 GSM_Terminate(); 4072 GSM_Terminate();
4021 exit(-1); 4073 exit(-1);
4022 } 4074 }
4023 *Backup.PhonePhonebook[used]=Pbk; 4075 *Backup.PhonePhonebook[used]=Pbk;
4024 used++; 4076 used++;
4025 } 4077 }
4026 printmsgerr("%c Reading: %i percent",13,used*100/MemStatus.MemoryUsed); 4078 printmsgerr("%c Reading: %i percent",13,used*100/MemStatus.MemoryUsed);
4027 i++; 4079 i++;
4028 if (gshutdown) { 4080 if (gshutdown) {
4029 GSM_Terminate(); 4081 GSM_Terminate();
4030 exit(0); 4082 exit(0);
4031 } 4083 }
4032 } 4084 }
4033 printmsgerr("\n"); 4085 printmsgerr("\n");
4034 } 4086 }
4035 DoBackup = false; 4087 DoBackup = false;
4036 if (Info.SIMPhonebook) { 4088 if (Info.SIMPhonebook) {
4037 printmsg("Checking SIM phonebook\n"); 4089 printmsg("Checking SIM phonebook\n");
4038 MemStatus.MemoryType = MEM_SM; 4090 MemStatus.MemoryType = MEM_SM;
4039 error=Phone->GetMemoryStatus(&s, &MemStatus); 4091 error=Phone->GetMemoryStatus(&s, &MemStatus);
4040 if (error==ERR_NONE && MemStatus.MemoryUsed != 0) { 4092 if (error==ERR_NONE && MemStatus.MemoryUsed != 0) {
4041 if (answer_yes(" Backup SIM phonebook")) DoBackup=true; 4093 if (answer_yes(" Backup SIM phonebook")) DoBackup=true;
4042 } 4094 }
4043 } 4095 }
4044 if (DoBackup) { 4096 if (DoBackup) {
4045 Pbk.MemoryType = MEM_SM; 4097 Pbk.MemoryType = MEM_SM;
4046 i = 1; 4098 i = 1;
4047 used = 0; 4099 used = 0;
4048 while (used != MemStatus.MemoryUsed) { 4100 while (used != MemStatus.MemoryUsed) {
4049 Pbk.Location = i; 4101 Pbk.Location = i;
4050 error=Phone->GetMemory(&s, &Pbk); 4102 error=Phone->GetMemory(&s, &Pbk);
4051 if (error != ERR_EMPTY) { 4103 if (error != ERR_EMPTY) {
4052 Print_Error(error); 4104 Print_Error(error);
4053 if (used < GSM_BACKUP_MAX_SIMPHONEBOOK) { 4105 if (used < GSM_BACKUP_MAX_SIMPHONEBOOK) {
4054 Backup.SIMPhonebook[used] = malloc(sizeof(GSM_MemoryEntry)); 4106 Backup.SIMPhonebook[used] = malloc(sizeof(GSM_MemoryEntry));
4055 if (Backup.SIMPhonebook[used] == NULL) Print_Error(ERR_MOREMEMORY); 4107 if (Backup.SIMPhonebook[used] == NULL) Print_Error(ERR_MOREMEMORY);
4056 Backup.SIMPhonebook[used + 1] = NULL; 4108 Backup.SIMPhonebook[used + 1] = NULL;
4057 } else { 4109 } else {
4058 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_SIMPHONEBOOK"); 4110 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_SIMPHONEBOOK");
4059 GSM_Terminate(); 4111 GSM_Terminate();
4060 exit(-1); 4112 exit(-1);
4061 } 4113 }
4062 *Backup.SIMPhonebook[used]=Pbk; 4114 *Backup.SIMPhonebook[used]=Pbk;
4063 used++; 4115 used++;
4064 } 4116 }
4065 printmsgerr("%c Reading: %i percent",13,used*100/MemStatus.MemoryUsed); 4117 printmsgerr("%c Reading: %i percent",13,used*100/MemStatus.MemoryUsed);
4066 i++; 4118 i++;
4067 if (gshutdown) { 4119 if (gshutdown) {
4068 GSM_Terminate(); 4120 GSM_Terminate();
4069 exit(0); 4121 exit(0);
4070 } 4122 }
4071 } 4123 }
4072 printmsgerr("\n"); 4124 printmsgerr("\n");
4073 } 4125 }
4074 DoBackup = false; 4126 DoBackup = false;
4075 if (Info.Calendar) { 4127 if (Info.Calendar) {
4076 printmsg("Checking calendar\n"); 4128 printmsg("Checking calendar\n");
4077 error=Phone->GetNextCalendar(&s,&Note,true); 4129 error=Phone->GetNextCalendar(&s,&Calendar,true);
4078 if (error==ERR_NONE) { 4130 if (error==ERR_NONE) {
4079 if (answer_yes(" Backup calendar notes")) DoBackup = true; 4131 if (answer_yes(" Backup calendar notes")) DoBackup = true;
4080 } 4132 }
4081 } 4133 }
4082 if (DoBackup) { 4134 if (DoBackup) {
4083 used = 0; 4135 used = 0;
4084 printmsgerr(" Reading : "); 4136 printmsgerr(" Reading : ");
4085 while (error == ERR_NONE) { 4137 while (error == ERR_NONE) {
4086 if (used < GSM_MAXCALENDARTODONOTES) { 4138 if (used < GSM_MAXCALENDARTODONOTES) {
4087 Backup.Calendar[used] = malloc(sizeof(GSM_CalendarEntry)); 4139 Backup.Calendar[used] = malloc(sizeof(GSM_CalendarEntry));
4088 if (Backup.Calendar[used] == NULL) Print_Error(ERR_MOREMEMORY); 4140 if (Backup.Calendar[used] == NULL) Print_Error(ERR_MOREMEMORY);
4089 Backup.Calendar[used+1] = NULL; 4141 Backup.Calendar[used+1] = NULL;
4090 } else { 4142 } else {
4091 printmsg(" Increase %s\n" , "GSM_MAXCALENDARTODONOTES"); 4143 printmsg(" Increase %s\n" , "GSM_MAXCALENDARTODONOTES");
4092 GSM_Terminate(); 4144 GSM_Terminate();
4093 exit(-1); 4145 exit(-1);
4094 } 4146 }
4095 *Backup.Calendar[used]=Note; 4147 *Backup.Calendar[used]=Calendar;
4096 used ++; 4148 used ++;
4097 error=Phone->GetNextCalendar(&s,&Note,false); 4149 error=Phone->GetNextCalendar(&s,&Calendar,false);
4098 printmsgerr("*"); 4150 printmsgerr("*");
4099 if (gshutdown) { 4151 if (gshutdown) {
4100 GSM_Terminate(); 4152 GSM_Terminate();
4101 exit(0); 4153 exit(0);
4102 } 4154 }
4103 } 4155 }
4104 printmsgerr("\n"); 4156 printmsgerr("\n");
4105 } 4157 }
4106 DoBackup = false; 4158 DoBackup = false;
4107 if (Info.ToDo) { 4159 if (Info.ToDo) {
4108 printmsg("Checking ToDo\n"); 4160 printmsg("Checking ToDo\n");
4109 error=Phone->GetToDoStatus(&s,&ToDoStatus); 4161 error=Phone->GetToDoStatus(&s,&ToDoStatus);
4110 if (error == ERR_NONE && ToDoStatus.Used != 0) { 4162 if (error == ERR_NONE && ToDoStatus.Used != 0) {
4111 if (answer_yes(" Backup ToDo")) DoBackup = true; 4163 if (answer_yes(" Backup ToDo")) DoBackup = true;
4112 } 4164 }
4113 } 4165 }
4114 if (DoBackup) { 4166 if (DoBackup) {
4115 used = 0; 4167 used = 0;
4116 error=Phone->GetNextToDo(&s,&ToDo,true); 4168 error=Phone->GetNextToDo(&s,&ToDo,true);
4117 while (error == ERR_NONE) { 4169 while (error == ERR_NONE) {
4118 if (used < GSM_MAXCALENDARTODONOTES) { 4170 if (used < GSM_MAXCALENDARTODONOTES) {
4119 Backup.ToDo[used] = malloc(sizeof(GSM_ToDoEntry)); 4171 Backup.ToDo[used] = malloc(sizeof(GSM_ToDoEntry));
4120 if (Backup.ToDo[used] == NULL) Print_Error(ERR_MOREMEMORY); 4172 if (Backup.ToDo[used] == NULL) Print_Error(ERR_MOREMEMORY);
4121 Backup.ToDo[used+1] = NULL; 4173 Backup.ToDo[used+1] = NULL;
4122 } else { 4174 } else {
4123 printmsg(" Increase %s\n" , "GSM_MAXCALENDARTODONOTES"); 4175 printmsg(" Increase %s\n" , "GSM_MAXCALENDARTODONOTES");
4124 GSM_Terminate(); 4176 GSM_Terminate();
4125 exit(-1); 4177 exit(-1);
4126 } 4178 }
4127 *Backup.ToDo[used]=ToDo; 4179 *Backup.ToDo[used]=ToDo;
4128 used ++; 4180 used ++;
4129 error=Phone->GetNextToDo(&s,&ToDo,false); 4181 error=Phone->GetNextToDo(&s,&ToDo,false);
4130 printmsgerr("%c Reading: %i percent",13,used*100/ToDoStatus.Used); 4182 printmsgerr("%c Reading: %i percent",13,used*100/ToDoStatus.Used);
4131 if (gshutdown) { 4183 if (gshutdown) {
4132 GSM_Terminate(); 4184 GSM_Terminate();
4133 exit(0); 4185 exit(0);
4134 } 4186 }
4135 } 4187 }
4136 printmsgerr("\n"); 4188 printmsgerr("\n");
4137 } 4189 }
4138 DoBackup = false; 4190 DoBackup = false;
4191 if (Info.Note) {
4192 printmsg("Checking notes\n");
4193 error=Phone->GetNextNote(&s,&Note,true);
4194 if (error==ERR_NONE) {
4195 if (answer_yes(" Backup notes")) DoBackup = true;
4196 }
4197 }
4198 if (DoBackup) {
4199 used = 0;
4200 printmsgerr(" Reading : ");
4201 while (error == ERR_NONE) {
4202 if (used < GSM_BACKUP_MAX_NOTE) {
4203 Backup.Note[used] = malloc(sizeof(GSM_NoteEntry));
4204 if (Backup.Note[used] == NULL) Print_Error(ERR_MOREMEMORY);
4205 Backup.Note[used+1] = NULL;
4206 } else {
4207 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_NOTE");
4208 GSM_Terminate();
4209 exit(-1);
4210 }
4211 *Backup.Note[used]=Note;
4212 used ++;
4213 error=Phone->GetNextNote(&s,&Note,false);
4214 printmsgerr("*");
4215 if (gshutdown) {
4216 GSM_Terminate();
4217 exit(0);
4218 }
4219 }
4220 printmsgerr("\n");
4221 }
4222 DoBackup = false;
4139 if (Info.CallerLogos) { 4223 if (Info.CallerLogos) {
4140 printmsg("Checking caller logos\n"); 4224 printmsg("Checking caller logos\n");
4141 Bitmap.Type = GSM_CallerGroupLogo; 4225 Bitmap.Type = GSM_CallerGroupLogo;
4142 Bitmap.Location = 1; 4226 Bitmap.Location = 1;
4143 error=Phone->GetBitmap(&s,&Bitmap); 4227 error=Phone->GetBitmap(&s,&Bitmap);
4144 if (error == ERR_NONE) { 4228 if (error == ERR_NONE) {
4145 if (answer_yes(" Backup caller groups and logos")) DoBackup = true; 4229 if (answer_yes(" Backup caller groups and logos")) DoBackup = true;
4146 } 4230 }
4147 } 4231 }
4148 if (DoBackup) { 4232 if (DoBackup) {
4149 printmsgerr(" Reading : "); 4233 printmsgerr(" Reading : ");
4150 error = ERR_NONE; 4234 error = ERR_NONE;
4151 used = 0; 4235 used = 0;
4152 while (error == ERR_NONE) { 4236 while (error == ERR_NONE) {
4153 if (used < GSM_BACKUP_MAX_CALLER) { 4237 if (used < GSM_BACKUP_MAX_CALLER) {
4154 Backup.CallerLogos[used] = malloc(sizeof(GSM_Bitmap)); 4238 Backup.CallerLogos[used] = malloc(sizeof(GSM_Bitmap));
4155 if (Backup.CallerLogos[used] == NULL) Print_Error(ERR_MOREMEMORY); 4239 if (Backup.CallerLogos[used] == NULL) Print_Error(ERR_MOREMEMORY);
4156 Backup.CallerLogos[used+1] = NULL; 4240 Backup.CallerLogos[used+1] = NULL;
4157 } else { 4241 } else {
4158 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_CALLER"); 4242 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_CALLER");
4159 GSM_Terminate(); 4243 GSM_Terminate();
4160 exit(-1); 4244 exit(-1);
4161 } 4245 }
4162 *Backup.CallerLogos[used] = Bitmap; 4246 *Backup.CallerLogos[used] = Bitmap;
4163 used ++; 4247 used ++;
4164 Bitmap.Location = used + 1; 4248 Bitmap.Location = used + 1;
4165 error=Phone->GetBitmap(&s,&Bitmap); 4249 error=Phone->GetBitmap(&s,&Bitmap);
4166 printmsgerr("*"); 4250 printmsgerr("*");
4167 if (gshutdown) { 4251 if (gshutdown) {
4168 GSM_Terminate(); 4252 GSM_Terminate();
4169 exit(0); 4253 exit(0);
4170 } 4254 }
4171 } 4255 }
4172 printmsgerr("\n"); 4256 printmsgerr("\n");
4173 } 4257 }
4174 DoBackup = false; 4258 DoBackup = false;
4175 if (Info.SMSC) { 4259 if (Info.SMSC) {
4176 printmsg("Checking SMS profiles\n"); 4260 printmsg("Checking SMS profiles\n");
4177 if (answer_yes(" Backup SMS profiles")) DoBackup = true; 4261 if (answer_yes(" Backup SMS profiles")) DoBackup = true;
4178 } 4262 }
4179 if (DoBackup) { 4263 if (DoBackup) {
4180 used = 0; 4264 used = 0;
4181 printmsgerr(" Reading: "); 4265 printmsgerr(" Reading: ");
4182 while (true) { 4266 while (true) {
4183 SMSC.Location = used + 1; 4267 SMSC.Location = used + 1;
4184 error = Phone->GetSMSC(&s,&SMSC); 4268 error = Phone->GetSMSC(&s,&SMSC);
4185 if (error != ERR_NONE) break; 4269 if (error != ERR_NONE) break;
4186 if (used < GSM_BACKUP_MAX_SMSC) { 4270 if (used < GSM_BACKUP_MAX_SMSC) {
4187 Backup.SMSC[used] = malloc(sizeof(GSM_SMSC)); 4271 Backup.SMSC[used] = malloc(sizeof(GSM_SMSC));
4188 if (Backup.SMSC[used] == NULL) Print_Error(ERR_MOREMEMORY); 4272 if (Backup.SMSC[used] == NULL) Print_Error(ERR_MOREMEMORY);
4189 Backup.SMSC[used + 1] = NULL; 4273 Backup.SMSC[used + 1] = NULL;
4190 } else { 4274 } else {
4191 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_SMSC"); 4275 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_SMSC");
4192 GSM_Terminate(); 4276 GSM_Terminate();
4193 exit(-1); 4277 exit(-1);
4194 } 4278 }
4195 *Backup.SMSC[used]=SMSC; 4279 *Backup.SMSC[used]=SMSC;
4196 used++; 4280 used++;
4197 printmsgerr("*"); 4281 printmsgerr("*");
4198 } 4282 }
4199 printmsgerr("\n"); 4283 printmsgerr("\n");
4200 } 4284 }
4201 DoBackup = false; 4285 DoBackup = false;
4202 if (Info.StartupLogo) { 4286 if (Info.StartupLogo) {
4203 printmsg("Checking startup text\n"); 4287 printmsg("Checking startup text\n");
4204 Bitmap.Type = GSM_WelcomeNote_Text; 4288 Bitmap.Type = GSM_WelcomeNote_Text;
4205 error = Phone->GetBitmap(&s,&Bitmap); 4289 error = Phone->GetBitmap(&s,&Bitmap);
4206 if (error == ERR_NONE) { 4290 if (error == ERR_NONE) {
4207 if (answer_yes(" Backup startup logo/text")) DoBackup = true; 4291 if (answer_yes(" Backup startup logo/text")) DoBackup = true;
4208 } 4292 }
4209 } 4293 }
4210 if (DoBackup) { 4294 if (DoBackup) {
4211 Backup.StartupLogo = malloc(sizeof(GSM_Bitmap)); 4295 Backup.StartupLogo = malloc(sizeof(GSM_Bitmap));
4212 if (Backup.StartupLogo == NULL) Print_Error(ERR_MOREMEMORY); 4296 if (Backup.StartupLogo == NULL) Print_Error(ERR_MOREMEMORY);
4213 *Backup.StartupLogo = Bitmap; 4297 *Backup.StartupLogo = Bitmap;
4214 if (Bitmap.Text[0]==0 && Bitmap.Text[1]==0) { 4298 if (Bitmap.Text[0]==0 && Bitmap.Text[1]==0) {
4215 Bitmap.Type = GSM_StartupLogo; 4299 Bitmap.Type = GSM_StartupLogo;
4216 error = Phone->GetBitmap(&s,&Bitmap); 4300 error = Phone->GetBitmap(&s,&Bitmap);
4217 if (error == ERR_NONE) *Backup.StartupLogo = Bitmap; 4301 if (error == ERR_NONE) *Backup.StartupLogo = Bitmap;
4218 } 4302 }
4219 } 4303 }
4220 DoBackup = false; 4304 DoBackup = false;
4221 if (Info.OperatorLogo) { 4305 if (Info.OperatorLogo) {
4222 printmsg("Checking operator logo\n"); 4306 printmsg("Checking operator logo\n");
4223 Bitmap.Type = GSM_OperatorLogo; 4307 Bitmap.Type = GSM_OperatorLogo;
4224 error=Phone->GetBitmap(&s,&Bitmap); 4308 error=Phone->GetBitmap(&s,&Bitmap);
4225 if (error == ERR_NONE) { 4309 if (error == ERR_NONE) {
4226 if (strcmp(Bitmap.NetworkCode,"000 00")!=0) { 4310 if (strcmp(Bitmap.NetworkCode,"000 00")!=0) {
4227 if (answer_yes(" Backup operator logo")) DoBackup = true; 4311 if (answer_yes(" Backup operator logo")) DoBackup = true;
4228 } 4312 }
4229 } 4313 }
4230 } 4314 }
4231 if (DoBackup) { 4315 if (DoBackup) {
4232 Backup.OperatorLogo = malloc(sizeof(GSM_Bitmap)); 4316 Backup.OperatorLogo = malloc(sizeof(GSM_Bitmap));
4233 if (Backup.OperatorLogo == NULL) Print_Error(ERR_MOREMEMORY); 4317 if (Backup.OperatorLogo == NULL) Print_Error(ERR_MOREMEMORY);
4234 *Backup.OperatorLogo = Bitmap; 4318 *Backup.OperatorLogo = Bitmap;
4235 } 4319 }
4236 DoBackup = false; 4320 DoBackup = false;
4321 if (Info.WAPBookmark) {
4322 printmsg("Checking WAP bookmarks\n");
4323 Bookmark.Location = 1;
4324 error=Phone->GetWAPBookmark(&s,&Bookmark);
4325 if (error==ERR_NONE) {
4326 if (answer_yes(" Backup WAP bookmarks")) DoBackup = true;
4327 }
4328 }
4329 if (DoBackup) {
4330 used = 0;
4331 printmsgerr(" Reading : ");
4332 while (error == ERR_NONE) {
4333 if (used < GSM_BACKUP_MAX_WAPBOOKMARK) {
4334 Backup.WAPBookmark[used] = malloc(sizeof(GSM_WAPBookmark));
4335 if (Backup.WAPBookmark[used] == NULL) Print_Error(ERR_MOREMEMORY);
4336 Backup.WAPBookmark[used+1] = NULL;
4337 } else {
4338 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPBOOKMARK");
4339 GSM_Terminate();
4340 exit(-1);
4341 }
4342 *Backup.WAPBookmark[used]=Bookmark;
4343 used ++;
4344 Bookmark.Location = used+1;
4345 error=Phone->GetWAPBookmark(&s,&Bookmark);
4346 printmsgerr("*");
4347 if (gshutdown) {
4348 GSM_Terminate();
4349 exit(0);
4350 }
4351 }
4352 printmsgerr("\n");
4353 }
4354 DoBackup = false;
4355 if (Info.WAPSettings) {
4356 printmsg("Checking WAP settings\n");
4357 Settings.Location = 1;
4358 error=Phone->GetWAPSettings(&s,&Settings);
4359 if (error==ERR_NONE) {
4360 if (answer_yes(" Backup WAP settings")) DoBackup = true;
4361 }
4362 }
4363 if (DoBackup) {
4364 used = 0;
4365 printmsgerr(" Reading : ");
4366 while (error == ERR_NONE) {
4367 if (used < GSM_BACKUP_MAX_WAPSETTINGS) {
4368 Backup.WAPSettings[used] = malloc(sizeof(GSM_MultiWAPSettings));
4369 if (Backup.WAPSettings[used] == NULL) Print_Error(ERR_MOREMEMORY);
4370 Backup.WAPSettings[used+1] = NULL;
4371 } else {
4372 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPSETTINGS");
4373 GSM_Terminate();
4374 exit(-1);
4375 }
4376 *Backup.WAPSettings[used]=Settings;
4377 used ++;
4378 Settings.Location = used+1;
4379 error=Phone->GetWAPSettings(&s,&Settings);
4380 printmsgerr("*");
4381 if (gshutdown) {
4382 GSM_Terminate();
4383 exit(0);
4384 }
4385 }
4386 printmsgerr("\n");
4387 }
4388 DoBackup = false;
4237 if (Info.MMSSettings) { 4389 if (Info.MMSSettings) {
4238 printmsg("Checking MMS settings\n"); 4390 printmsg("Checking MMS settings\n");
4239 Settings.Location = 1; 4391 Settings.Location = 1;
4240 error=Phone->GetMMSSettings(&s,&Settings); 4392 error=Phone->GetMMSSettings(&s,&Settings);
4241 if (error==ERR_NONE) { 4393 if (error==ERR_NONE) {
4242 if (answer_yes(" Backup MMS settings")) DoBackup = true; 4394 if (answer_yes(" Backup MMS settings")) DoBackup = true;
4243 } 4395 }
4244 } 4396 }
4245 if (DoBackup) { 4397 if (DoBackup) {
4246 used = 0; 4398 used = 0;
4247 printmsgerr(" Reading : "); 4399 printmsgerr(" Reading : ");
4248 while (error == ERR_NONE) { 4400 while (error == ERR_NONE) {
4249 if (used < GSM_BACKUP_MAX_MMSSETTINGS) { 4401 if (used < GSM_BACKUP_MAX_MMSSETTINGS) {
4250 Backup.MMSSettings[used] = malloc(sizeof(GSM_MultiWAPSettings)); 4402 Backup.MMSSettings[used] = malloc(sizeof(GSM_MultiWAPSettings));
4251 if (Backup.MMSSettings[used] == NULL) Print_Error(ERR_MOREMEMORY); 4403 if (Backup.MMSSettings[used] == NULL) Print_Error(ERR_MOREMEMORY);
4252 Backup.MMSSettings[used+1] = NULL; 4404 Backup.MMSSettings[used+1] = NULL;
4253 } else { 4405 } else {
4254 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_MMSSETTINGS"); 4406 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_MMSSETTINGS");
4255 GSM_Terminate(); 4407 GSM_Terminate();
4256 exit(-1); 4408 exit(-1);
4257 } 4409 }
4258 *Backup.MMSSettings[used]=Settings; 4410 *Backup.MMSSettings[used]=Settings;
4259 used ++; 4411 used ++;
4260 Settings.Location = used+1; 4412 Settings.Location = used+1;
4261 error=Phone->GetMMSSettings(&s,&Settings); 4413 error=Phone->GetMMSSettings(&s,&Settings);
4262 printmsgerr("*"); 4414 printmsgerr("*");
4263 if (gshutdown) { 4415 if (gshutdown) {
4264 GSM_Terminate(); 4416 GSM_Terminate();
4265 exit(0); 4417 exit(0);
4266 } 4418 }
4267 } 4419 }
4268 printmsgerr("\n"); 4420 printmsgerr("\n");
4269 } 4421 }
4270 DoBackup = false; 4422 DoBackup = false;
4271 if (Info.WAPBookmark) { 4423 if (Info.ChatSettings) {
4272 printmsg("Checking WAP bookmarks\n"); 4424 printmsg("Checking Chat settings\n");
4273 Bookmark.Location = 1; 4425 Chat.Location = 1;
4274 error=Phone->GetWAPBookmark(&s,&Bookmark); 4426 error=Phone->GetChatSettings(&s,&Chat);
4275 if (error==ERR_NONE) { 4427 if (error==ERR_NONE) {
4276 if (answer_yes(" Backup WAP bookmarks")) DoBackup = true; 4428 if (answer_yes(" Backup Chat settings")) DoBackup = true;
4277 } 4429 }
4278 } 4430 }
4279 if (DoBackup) { 4431 if (DoBackup) {
4280 used = 0; 4432 used = 0;
4281 printmsgerr(" Reading : "); 4433 printmsgerr(" Reading : ");
4282 while (error == ERR_NONE) { 4434 while (error == ERR_NONE) {
4283 if (used < GSM_BACKUP_MAX_WAPBOOKMARK) { 4435 if (used < GSM_BACKUP_MAX_CHATSETTINGS) {
4284 Backup.WAPBookmark[used] = malloc(sizeof(GSM_WAPBookmark)); 4436 Backup.ChatSettings[used] = malloc(sizeof(GSM_ChatSettings));
4285 if (Backup.WAPBookmark[used] == NULL) Print_Error(ERR_MOREMEMORY); 4437 if (Backup.ChatSettings[used] == NULL) Print_Error(ERR_MOREMEMORY);
4286 Backup.WAPBookmark[used+1] = NULL; 4438 Backup.ChatSettings[used+1] = NULL;
4287 } else { 4439 } else {
4288 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPBOOKMARK"); 4440 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_CHATSETTINGS");
4289 GSM_Terminate(); 4441 GSM_Terminate();
4290 exit(-1); 4442 exit(-1);
4291 } 4443 }
4292 *Backup.WAPBookmark[used]=Bookmark; 4444 *Backup.ChatSettings[used]=Chat;
4293 used ++; 4445 used ++;
4294 Bookmark.Location = used+1; 4446 Chat.Location = used+1;
4295 error=Phone->GetWAPBookmark(&s,&Bookmark); 4447 error=Phone->GetChatSettings(&s,&Chat);
4296 printmsgerr("*"); 4448 printmsgerr("*");
4297 if (gshutdown) { 4449 if (gshutdown) {
4298 GSM_Terminate(); 4450 GSM_Terminate();
4299 exit(0); 4451 exit(0);
4300 } 4452 }
4301 } 4453 }
4302 printmsgerr("\n"); 4454 printmsgerr("\n");
4303 } 4455 }
4304 DoBackup = false; 4456 DoBackup = false;
4305 if (Info.WAPSettings) { 4457 if (Info.SyncMLSettings) {
4306 printmsg("Checking WAP settings\n"); 4458 printmsg("Checking SyncML settings\n");
4307 Settings.Location = 1; 4459 SyncML.Location = 1;
4308 error=Phone->GetWAPSettings(&s,&Settings); 4460 error=Phone->GetSyncMLSettings(&s,&SyncML);
4309 if (error==ERR_NONE) { 4461 if (error==ERR_NONE) {
4310 if (answer_yes(" Backup WAP settings")) DoBackup = true; 4462 if (answer_yes(" Backup SyncML settings")) DoBackup = true;
4311 } 4463 }
4312 } 4464 }
4313 if (DoBackup) { 4465 if (DoBackup) {
4314 used = 0; 4466 used = 0;
4315 printmsgerr(" Reading : "); 4467 printmsgerr(" Reading : ");
4316 while (error == ERR_NONE) { 4468 while (error == ERR_NONE) {
4317 if (used < GSM_BACKUP_MAX_WAPSETTINGS) { 4469 if (used < GSM_BACKUP_MAX_SYNCMLSETTINGS) {
4318 Backup.WAPSettings[used] = malloc(sizeof(GSM_MultiWAPSettings)); 4470 Backup.SyncMLSettings[used] = malloc(sizeof(GSM_SyncMLSettings));
4319 if (Backup.WAPSettings[used] == NULL) Print_Error(ERR_MOREMEMORY); 4471 if (Backup.SyncMLSettings[used] == NULL) Print_Error(ERR_MOREMEMORY);
4320 Backup.WAPSettings[used+1] = NULL; 4472 Backup.SyncMLSettings[used+1] = NULL;
4321 } else { 4473 } else {
4322 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_WAPSETTINGS"); 4474 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_SYNCMLSETTINGS");
4323 GSM_Terminate(); 4475 GSM_Terminate();
4324 exit(-1); 4476 exit(-1);
4325 } 4477 }
4326 *Backup.WAPSettings[used]=Settings; 4478 *Backup.SyncMLSettings[used]=SyncML;
4327 used ++; 4479 used ++;
4328 Settings.Location = used+1; 4480 SyncML.Location = used+1;
4329 error=Phone->GetWAPSettings(&s,&Settings); 4481 error=Phone->GetSyncMLSettings(&s,&SyncML);
4330 printmsgerr("*"); 4482 printmsgerr("*");
4331 if (gshutdown) { 4483 if (gshutdown) {
4332 GSM_Terminate(); 4484 GSM_Terminate();
4333 exit(0); 4485 exit(0);
4334 } 4486 }
4335 } 4487 }
4336 printmsgerr("\n"); 4488 printmsgerr("\n");
4337 } 4489 }
4338 DoBackup = false; 4490 DoBackup = false;
4339 if (Info.Ringtone) { 4491 if (Info.Ringtone) {
4340 printmsg("Checking user ringtones\n"); 4492 printmsg("Checking user ringtones\n");
4341 Ringtone.Location = 1; 4493 Ringtone.Location = 1;
4342 Ringtone.Format = 0; 4494 Ringtone.Format = 0;
4343 error=Phone->GetRingtone(&s,&Ringtone,false); 4495 error=Phone->GetRingtone(&s,&Ringtone,false);
4344 if (error==ERR_EMPTY || error == ERR_NONE) { 4496 if (error==ERR_EMPTY || error == ERR_NONE) {
4345 if (answer_yes(" Backup user ringtones")) DoBackup = true; 4497 if (answer_yes(" Backup user ringtones")) DoBackup = true;
4346 } 4498 }
4347 } 4499 }
4348 if (DoBackup) { 4500 if (DoBackup) {
4349 used = 0; 4501 used = 0;
4350 i= 1; 4502 i= 1;
4351 printmsgerr(" Reading : "); 4503 printmsgerr(" Reading : ");
4352 while (error == ERR_NONE || error == ERR_EMPTY) { 4504 while (error == ERR_NONE || error == ERR_EMPTY) {
4353 if (error == ERR_NONE) { 4505 if (error == ERR_NONE) {
4354 if (used < GSM_BACKUP_MAX_RINGTONES) { 4506 if (used < GSM_BACKUP_MAX_RINGTONES) {
4355 Backup.Ringtone[used] = malloc(sizeof(GSM_Ringtone)); 4507 Backup.Ringtone[used] = malloc(sizeof(GSM_Ringtone));
4356 if (Backup.Ringtone[used] == NULL) Print_Error(ERR_MOREMEMORY); 4508 if (Backup.Ringtone[used] == NULL) Print_Error(ERR_MOREMEMORY);
4357 Backup.Ringtone[used+1] = NULL; 4509 Backup.Ringtone[used+1] = NULL;
4358 } else { 4510 } else {
4359 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_RINGTONES"); 4511 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_RINGTONES");
4360 GSM_Terminate(); 4512 GSM_Terminate();
4361 exit(-1); 4513 exit(-1);
4362 } 4514 }
4363 *Backup.Ringtone[used]=Ringtone; 4515 *Backup.Ringtone[used]=Ringtone;
4364 used ++; 4516 used ++;
4365 } 4517 }
4366 i++; 4518 i++;
4367 Ringtone.Location = i; 4519 Ringtone.Location = i;
4368 Ringtone.Format = 0; 4520 Ringtone.Format = 0;
4369 error=Phone->GetRingtone(&s,&Ringtone,false); 4521 error=Phone->GetRingtone(&s,&Ringtone,false);
4370 printmsgerr("*"); 4522 printmsgerr("*");
4371 if (gshutdown) { 4523 if (gshutdown) {
4372 GSM_Terminate(); 4524 GSM_Terminate();
4373 exit(0); 4525 exit(0);
4374 } 4526 }
4375 } 4527 }
4376 printmsgerr("\n"); 4528 printmsgerr("\n");
4377 } 4529 }
4378 DoBackup = false; 4530 DoBackup = false;
4379 if (Info.Profiles) { 4531 if (Info.Profiles) {
4380 printmsg("Checking phone profiles\n"); 4532 printmsg("Checking phone profiles\n");
4381 Profile.Location = 1; 4533 Profile.Location = 1;
4382 error = Phone->GetProfile(&s,&Profile); 4534 error = Phone->GetProfile(&s,&Profile);
4383 if (error == ERR_NONE) { 4535 if (error == ERR_NONE) {
4384 if (answer_yes(" Backup phone profiles")) DoBackup = true; 4536 if (answer_yes(" Backup phone profiles")) DoBackup = true;
4385 } 4537 }
4386 } 4538 }
4387 if (DoBackup) { 4539 if (DoBackup) {
4388 used = 0; 4540 used = 0;
4389 printmsgerr(" Reading: "); 4541 printmsgerr(" Reading: ");
4390 while (true) { 4542 while (true) {
4391 Profile.Location = used + 1; 4543 Profile.Location = used + 1;
4392 error = Phone->GetProfile(&s,&Profile); 4544 error = Phone->GetProfile(&s,&Profile);
4393 if (error != ERR_NONE) break; 4545 if (error != ERR_NONE) break;
4394 if (used < GSM_BACKUP_MAX_PROFILES) { 4546 if (used < GSM_BACKUP_MAX_PROFILES) {
4395 Backup.Profiles[used] = malloc(sizeof(GSM_Profile)); 4547 Backup.Profiles[used] = malloc(sizeof(GSM_Profile));
4396 if (Backup.Profiles[used] == NULL) Print_Error(ERR_MOREMEMORY); 4548 if (Backup.Profiles[used] == NULL) Print_Error(ERR_MOREMEMORY);
4397 Backup.Profiles[used + 1] = NULL; 4549 Backup.Profiles[used + 1] = NULL;
4398 } else { 4550 } else {
4399 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_PROFILES"); 4551 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_PROFILES");
4400 GSM_Terminate(); 4552 GSM_Terminate();
4401 exit(-1); 4553 exit(-1);
4402 } 4554 }
4403 *Backup.Profiles[used]=Profile; 4555 *Backup.Profiles[used]=Profile;
4404 used++; 4556 used++;
4405 printmsgerr("*"); 4557 printmsgerr("*");
4406 } 4558 }
4407 printmsgerr("\n"); 4559 printmsgerr("\n");
4408 } 4560 }
4409 DoBackup = false; 4561 DoBackup = false;
4410 if (Info.FMStation) { 4562 if (Info.FMStation) {
4411 printmsg("Checking FM stations\n"); 4563 printmsg("Checking FM stations\n");
4412 FMStation.Location = 1; 4564 FMStation.Location = 1;
4413 error = Phone->GetFMStation(&s,&FMStation); 4565 error = Phone->GetFMStation(&s,&FMStation);
4414 if (error == ERR_NONE || error == ERR_EMPTY) { 4566 if (error == ERR_NONE || error == ERR_EMPTY) {
4415 if (answer_yes(" Backup phone FM stations")) DoBackup=true; 4567 if (answer_yes(" Backup phone FM stations")) DoBackup=true;
4416 } 4568 }
4417 } 4569 }
4418 if (DoBackup) { 4570 if (DoBackup) {
4419 used= 0; 4571 used= 0;
4420 i = 1; 4572 i = 1;
4421 printmsgerr(" Reading: "); 4573 printmsgerr(" Reading: ");
4422 while (error == ERR_NONE || error == ERR_EMPTY) { 4574 while (error == ERR_NONE || error == ERR_EMPTY) {
4423 error = Phone->GetFMStation(&s,&FMStation); 4575 error = Phone->GetFMStation(&s,&FMStation);
4424 if (error == ERR_NONE) { 4576 if (error == ERR_NONE) {
4425 if (used < GSM_BACKUP_MAX_FMSTATIONS) { 4577 if (used < GSM_BACKUP_MAX_FMSTATIONS) {
4426 Backup.FMStation[used] = malloc(sizeof(GSM_FMStation)); 4578 Backup.FMStation[used] = malloc(sizeof(GSM_FMStation));
4427 if (Backup.FMStation[used] == NULL) Print_Error(ERR_MOREMEMORY); 4579 if (Backup.FMStation[used] == NULL) Print_Error(ERR_MOREMEMORY);
4428 Backup.FMStation[used + 1] = NULL; 4580 Backup.FMStation[used + 1] = NULL;
4429 } else { 4581 } else {
4430 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_FMSTATIONS"); 4582 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_FMSTATIONS");
4431 GSM_Terminate(); 4583 GSM_Terminate();
4432 exit(-1); 4584 exit(-1);
4433 } 4585 }
4434 *Backup.FMStation[used]=FMStation; 4586 *Backup.FMStation[used]=FMStation;
4435 used++; 4587 used++;
4436 } 4588 }
4437 i++; 4589 i++;
4438 FMStation.Location = i; 4590 FMStation.Location = i;
4439 printmsgerr("*"); 4591 printmsgerr("*");
4440 } 4592 }
4441 printmsgerr("\n"); 4593 printmsgerr("\n");
4442 } 4594 }
4443 DoBackup = false; 4595 DoBackup = false;
4444 if (Info.GPRSPoint) { 4596 if (Info.GPRSPoint) {
4445 printmsg("Checking GPRS access points\n"); 4597 printmsg("Checking GPRS access points\n");
4446 GPRSPoint.Location = 1; 4598 GPRSPoint.Location = 1;
4447 error = Phone->GetGPRSAccessPoint(&s,&GPRSPoint); 4599 error = Phone->GetGPRSAccessPoint(&s,&GPRSPoint);
4448 if (error == ERR_NONE || error == ERR_EMPTY) { 4600 if (error == ERR_NONE || error == ERR_EMPTY) {
4449 if (answer_yes(" Backup GPRS access points")) DoBackup = true; 4601 if (answer_yes(" Backup GPRS access points")) DoBackup = true;
4450 } 4602 }
4451 } 4603 }
4452 if (DoBackup) { 4604 if (DoBackup) {
4453 used= 0; 4605 used= 0;
4454 i = 1; 4606 i = 1;
4455 printmsgerr(" Reading: "); 4607 printmsgerr(" Reading: ");
4456 while (error == ERR_NONE || error == ERR_EMPTY) { 4608 while (error == ERR_NONE || error == ERR_EMPTY) {
4457 error = Phone->GetGPRSAccessPoint(&s,&GPRSPoint); 4609 error = Phone->GetGPRSAccessPoint(&s,&GPRSPoint);
4458 if (error == ERR_NONE) { 4610 if (error == ERR_NONE) {
4459 if (used < GSM_BACKUP_MAX_GPRSPOINT) { 4611 if (used < GSM_BACKUP_MAX_GPRSPOINT) {
4460 Backup.GPRSPoint[used] = malloc(sizeof(GSM_GPRSAccessPoint)); 4612 Backup.GPRSPoint[used] = malloc(sizeof(GSM_GPRSAccessPoint));
4461 if (Backup.GPRSPoint[used] == NULL) Print_Error(ERR_MOREMEMORY); 4613 if (Backup.GPRSPoint[used] == NULL) Print_Error(ERR_MOREMEMORY);
4462 Backup.GPRSPoint[used + 1] = NULL; 4614 Backup.GPRSPoint[used + 1] = NULL;
4463 } else { 4615 } else {
4464 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_GPRSPOINT"); 4616 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_GPRSPOINT");
4465 GSM_Terminate(); 4617 GSM_Terminate();
4466 exit(-1); 4618 exit(-1);
4467 } 4619 }
4468 *Backup.GPRSPoint[used]=GPRSPoint; 4620 *Backup.GPRSPoint[used]=GPRSPoint;
4469 used++; 4621 used++;
4470 } 4622 }
4471 i++; 4623 i++;
4472 GPRSPoint.Location = i; 4624 GPRSPoint.Location = i;
4473 printmsgerr("*"); 4625 printmsgerr("*");
4474 } 4626 }
4475 printmsgerr("\n"); 4627 printmsgerr("\n");
4476 } 4628 }
4477 4629
4478 GSM_Terminate(); 4630 GSM_Terminate();
4479 4631
4480 GSM_SaveBackupFile(argv[2],&Backup, Info.UseUnicode); 4632 GSM_SaveBackupFile(argv[2],&Backup, Info.UseUnicode);
4481 GSM_FreeBackup(&Backup); 4633 GSM_FreeBackup(&Backup);
4482} 4634}
4483 4635
4484static void Restore(int argc, char *argv[]) 4636static void Restore(int argc, char *argv[])
4485{ 4637{
4486 GSM_Backup Backup; 4638 GSM_Backup Backup;
4487 GSM_FMStation FMStation; 4639 GSM_FMStation FMStation;
4488 GSM_DateTime date_time; 4640 GSM_DateTime date_time;
4489 GSM_CalendarEntryCalendar; 4641 GSM_CalendarEntryCalendar;
4490 GSM_Bitmap Bitmap; 4642 GSM_Bitmap Bitmap;
4491 GSM_Ringtone Ringtone; 4643 GSM_Ringtone Ringtone;
4492 GSM_MemoryEntry Pbk; 4644 GSM_MemoryEntry Pbk;
4493 GSM_MemoryStatusMemStatus; 4645 GSM_MemoryStatusMemStatus;
4494 GSM_ToDoEntry ToDo; 4646 GSM_ToDoEntry ToDo;
4495 GSM_ToDoStatus ToDoStatus; 4647 GSM_ToDoStatus ToDoStatus;
4496 GSM_Profile Profile; 4648 GSM_Profile Profile;
4497 GSM_MultiWAPSettingsSettings; 4649 GSM_MultiWAPSettingsSettings;
4498 GSM_GPRSAccessPointGPRSPoint; 4650 GSM_GPRSAccessPointGPRSPoint;
4499 GSM_WAPBookmark Bookmark; 4651 GSM_WAPBookmark Bookmark;
4500 int i, used, max = 0; 4652 int i, used, max = 0;
4501 bool Past = true; 4653 bool Past = true;
4502 bool Found, DoRestore; 4654 bool Found, DoRestore;
4503 4655
4504 error=GSM_ReadBackupFile(argv[2],&Backup); 4656 error=GSM_ReadBackupFile(argv[2],&Backup);
4505 Print_Error(error); 4657 if (error!=ERR_NOTIMPLEMENTED) {
4658 Print_Error(error);
4659 } else {
4660 printmsgerr("WARNING: Some data not read from file. It can be damaged or restoring some settings from this file format not implemented (maybe higher Gammu required ?)\n");
4661 }
4506 4662
4507 signal(SIGINT, interrupt); 4663 signal(SIGINT, interrupt);
4508 printmsgerr("Press Ctrl+C to break...\n"); 4664 printmsgerr("Press Ctrl+C to break...\n");
4509 4665
4510 if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false)); 4666 if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false));
4511 if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model); 4667 if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model);
4512 if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI); 4668 if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI);
4669 if (Backup.Creator[0]!=0) printmsgerr("File created by : %s\n",Backup.Creator);
4513 4670
4514 if (Backup.MD5Calculated[0]!=0) { 4671 if (Backup.MD5Calculated[0]!=0) {
4515 dbgprintf("\"%s\"\n",Backup.MD5Original); 4672 dbgprintf("\"%s\"\n",Backup.MD5Original);
4516 dbgprintf("\"%s\"\n",Backup.MD5Calculated); 4673 dbgprintf("\"%s\"\n",Backup.MD5Calculated);
4517 if (strcmp(Backup.MD5Original,Backup.MD5Calculated)) { 4674 if (strcmp(Backup.MD5Original,Backup.MD5Calculated)) {
4518 if (!answer_yes("Checksum in backup file do not match. Continue")) return; 4675 if (!answer_yes("Checksum in backup file do not match. Continue")) return;
4519 } 4676 }
4520 } 4677 }
4521 4678
4522 GSM_Init(true); 4679 GSM_Init(true);
4523 4680
4524 DoRestore = false; 4681 DoRestore = false;
4525 if (Backup.PhonePhonebook[0] != NULL) { 4682 if (Backup.PhonePhonebook[0] != NULL) {
4526 MemStatus.MemoryType = MEM_ME; 4683 MemStatus.MemoryType = MEM_ME;
4527 error=Phone->GetMemoryStatus(&s, &MemStatus); 4684 error=Phone->GetMemoryStatus(&s, &MemStatus);
4528 if (error==ERR_NONE) { 4685 if (error==ERR_NONE) {
4529 max = 0; 4686 max = 0;
4530 while (Backup.PhonePhonebook[max]!=NULL) max++; 4687 while (Backup.PhonePhonebook[max]!=NULL) max++;
4531 printmsgerr("%i entries in backup file\n",max); 4688 printmsgerr("%i entries in backup file\n",max);
4532 if (answer_yes("Restore phone phonebook")) DoRestore = true; 4689 if (answer_yes("Restore phone phonebook")) DoRestore = true;
4533 } 4690 }
4534 } 4691 }
4535 if (DoRestore) { 4692 if (DoRestore) {
4536 used = 0; 4693 used = 0;
4537 for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) { 4694 for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) {
4538 Pbk.MemoryType = MEM_ME; 4695 Pbk.MemoryType = MEM_ME;
4539 Pbk.Location= i + 1; 4696 Pbk.Location= i + 1;
4540 Pbk.EntriesNum= 0; 4697 Pbk.EntriesNum= 0;
4541 if (used<max) { 4698 if (used<max) {
4542 if (Backup.PhonePhonebook[used]->Location == Pbk.Location) { 4699 if (Backup.PhonePhonebook[used]->Location == Pbk.Location) {
4543 Pbk = *Backup.PhonePhonebook[used]; 4700 Pbk = *Backup.PhonePhonebook[used];
4544 used++; 4701 used++;
4545 dbgprintf("Location %i\n",Pbk.Location); 4702 dbgprintf("Location %i\n",Pbk.Location);
4546 if (Pbk.EntriesNum != 0) error=Phone->SetMemory(&s, &Pbk); 4703 if (Pbk.EntriesNum != 0) error=Phone->SetMemory(&s, &Pbk);
4547 } 4704 }
4548 } 4705 }
4549 if (Pbk.EntriesNum == 0) error=Phone->DeleteMemory(&s, &Pbk); 4706 if (Pbk.EntriesNum == 0) error=Phone->DeleteMemory(&s, &Pbk);
4550 Print_Error(error); 4707 Print_Error(error);
4551 printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.MemoryUsed+MemStatus.MemoryFree)); 4708 printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.MemoryUsed+MemStatus.MemoryFree));
4552 if (gshutdown) { 4709 if (gshutdown) {
4553 GSM_Terminate(); 4710 GSM_Terminate();
4554 exit(0); 4711 exit(0);
4555 } 4712 }
4556 } 4713 }
4557 printmsgerr("\n"); 4714 printmsgerr("\n");
4558 } 4715 }
4559 4716
4560 DoRestore = false; 4717 DoRestore = false;
4561 if (Backup.SIMPhonebook[0] != NULL) { 4718 if (Backup.SIMPhonebook[0] != NULL) {
4562 MemStatus.MemoryType = MEM_SM; 4719 MemStatus.MemoryType = MEM_SM;
4563 error=Phone->GetMemoryStatus(&s, &MemStatus); 4720 error=Phone->GetMemoryStatus(&s, &MemStatus);
4564 if (error==ERR_NONE) { 4721 if (error==ERR_NONE) {
4565 max = 0; 4722 max = 0;
4566 while (Backup.SIMPhonebook[max]!=NULL) max++; 4723 while (Backup.SIMPhonebook[max]!=NULL) max++;
4567 printmsgerr("%i entries in backup file\n",max); 4724 printmsgerr("%i entries in backup file\n",max);
4568 if (answer_yes("Restore SIM phonebook")) DoRestore = true; 4725 if (answer_yes("Restore SIM phonebook")) DoRestore = true;
4569 } 4726 }
4570 } 4727 }
4571 if (DoRestore) { 4728 if (DoRestore) {
4572 used = 0; 4729 used = 0;
4573 for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) { 4730 for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) {
4574 Pbk.MemoryType = MEM_SM; 4731 Pbk.MemoryType = MEM_SM;
4575 Pbk.Location= i + 1; 4732 Pbk.Location= i + 1;
4576 Pbk.EntriesNum= 0; 4733 Pbk.EntriesNum= 0;
4577 if (used<max) { 4734 if (used<max) {
4578 if (Backup.SIMPhonebook[used]->Location == Pbk.Location) { 4735 if (Backup.SIMPhonebook[used]->Location == Pbk.Location) {
4579 Pbk = *Backup.SIMPhonebook[used]; 4736 Pbk = *Backup.SIMPhonebook[used];
4580 used++; 4737 used++;
4581 dbgprintf("Location %i\n",Pbk.Location); 4738 dbgprintf("Location %i\n",Pbk.Location);
4582 if (Pbk.EntriesNum != 0) error=Phone->SetMemory(&s, &Pbk); 4739 if (Pbk.EntriesNum != 0) error=Phone->SetMemory(&s, &Pbk);
4583 } 4740 }
4584 } 4741 }
4585 if (Pbk.EntriesNum == 0) error=Phone->DeleteMemory(&s, &Pbk); 4742 if (Pbk.EntriesNum == 0) error=Phone->DeleteMemory(&s, &Pbk);
4586 Print_Error(error); 4743 Print_Error(error);
4587 printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.MemoryUsed+MemStatus.MemoryFree)); 4744 printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.MemoryUsed+MemStatus.MemoryFree));
4588 if (gshutdown) { 4745 if (gshutdown) {
4589 GSM_Terminate(); 4746 GSM_Terminate();
4590 exit(0); 4747 exit(0);
4591 } 4748 }
4592 } 4749 }
4593 printmsgerr("\n"); 4750 printmsgerr("\n");
4594 } 4751 }
4595 4752
4596 DoRestore = false; 4753 DoRestore = false;
4597 if (Backup.CallerLogos[0] != NULL) { 4754 if (Backup.CallerLogos[0] != NULL) {
4598 Bitmap.Type = GSM_CallerGroupLogo; 4755 Bitmap.Type = GSM_CallerGroupLogo;
4599 Bitmap.Location = 1; 4756 Bitmap.Location = 1;
4600 error=Phone->GetBitmap(&s,&Bitmap); 4757 error=Phone->GetBitmap(&s,&Bitmap);
4601 if (error == ERR_NONE) { 4758 if (error == ERR_NONE) {
4602 if (answer_yes("Restore caller groups and logos")) DoRestore = true; 4759 if (answer_yes("Restore caller groups and logos")) DoRestore = true;
4603 } 4760 }
4604 } 4761 }
4605 if (DoRestore) { 4762 if (DoRestore) {
4606 max = 0; 4763 max = 0;
4607 while (Backup.CallerLogos[max]!=NULL) max++; 4764 while (Backup.CallerLogos[max]!=NULL) max++;
4608 for (i=0;i<max;i++) { 4765 for (i=0;i<max;i++) {
4609 error=Phone->SetBitmap(&s,Backup.CallerLogos[i]); 4766 error=Phone->SetBitmap(&s,Backup.CallerLogos[i]);
4610 Print_Error(error); 4767 Print_Error(error);
4611 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 4768 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4612 if (gshutdown) { 4769 if (gshutdown) {
4613 GSM_Terminate(); 4770 GSM_Terminate();
4614 exit(0); 4771 exit(0);
4615 } 4772 }
4616 } 4773 }
4617 printmsgerr("\n"); 4774 printmsgerr("\n");
4618 } 4775 }
4619 4776
4620 if (!mystrncasecmp(s.CurrentConfig->SyncTime,"yes",0)) { 4777 if (!mystrncasecmp(s.CurrentConfig->SyncTime,"yes",0)) {
4621 if (/*answer_yes("Do you want to set date/time in phone (NOTE: in some phones it's required to correctly restore calendar notes and other items)")*/ true ) { 4778 if (answer_yes("Do you want to set date/time in phone (NOTE: in some phones it's required to correctly restore calendar notes and other items)")) {
4622 GSM_GetCurrentDateTime(&date_time); 4779 GSM_GetCurrentDateTime(&date_time);
4623 4780
4624 error=Phone->SetDateTime(&s, &date_time); 4781 error=Phone->SetDateTime(&s, &date_time);
4625 Print_Error(error); 4782 Print_Error(error);
4626 } 4783 }
4627 } 4784 }
4628 DoRestore = false; 4785 DoRestore = false;
4629 if (Backup.Calendar[0] != NULL) { 4786 if (Backup.Calendar[0] != NULL) {
4630 DoRestore = true;
4631 /* N6110 doesn't support getting calendar status */ 4787 /* N6110 doesn't support getting calendar status */
4632 error = Phone->GetNextCalendar(&s,&Calendar,true); 4788 error = Phone->GetNextCalendar(&s,&Calendar,true);
4633 if (error == ERR_NONE || error == ERR_INVALIDLOCATION || error == ERR_EMPTY) { 4789 if (error == ERR_NONE || error == ERR_INVALIDLOCATION || error == ERR_EMPTY) {
4634 max = 0; 4790 max = 0;
4635 while (Backup.Calendar[max] != NULL) max++; 4791 while (Backup.Calendar[max] != NULL) max++;
4636 printmsgerr("%i entries in backup file\n",max); 4792 printmsgerr("%i entries in backup file\n",max);
4793 // LR
4794 //if (answer_yes("Restore calendar notes")) {
4795 //Past = answer_yes("Restore notes from the past");
4637 DoRestore = true; 4796 DoRestore = true;
4638 /* 4797 //}
4639 if (answer_yes("Restore calendar notes")) {
4640 Past = answer_yes("Restore notes from the past");
4641 DoRestore = true;
4642 }
4643 */
4644 } 4798 }
4645 } 4799 }
4646 if (DoRestore) { 4800 if (DoRestore) {
4647 printmsgerr("Deleting old notes: "); 4801 printmsgerr("Deleting old notes: ");
4648 error = Phone->DeleteAllCalendar(&s); 4802 error = Phone->DeleteAllCalendar(&s);
4649 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 4803 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
4650 while (1) { 4804 while (1) {
4651 error = Phone->GetNextCalendar(&s,&Calendar,true); 4805 error = Phone->GetNextCalendar(&s,&Calendar,true);
4652 if (error != ERR_NONE) break; 4806 if (error != ERR_NONE) break;
4653 error = Phone->DeleteCalendar(&s,&Calendar); 4807 error = Phone->DeleteCalendar(&s,&Calendar);
4654 Print_Error(error); 4808 Print_Error(error);
4655 printmsgerr("*"); 4809 printmsgerr("*");
4656 } 4810 }
4657 printmsgerr("\n"); 4811 printmsgerr("\n");
4658 } else { 4812 } else {
4659 printmsgerr("Done\n"); 4813 printmsgerr("Done\n");
4660 Print_Error(error); 4814 Print_Error(error);
4661 } 4815 }
4662 4816
4663 for (i=0;i<max;i++) { 4817 for (i=0;i<max;i++) {
4664 if (!Past && IsCalendarNoteFromThePast(Backup.Calendar[i])) continue; 4818 if (!Past && IsCalendarNoteFromThePast(Backup.Calendar[i])) continue;
4665 4819
4666 Calendar = *Backup.Calendar[i]; 4820 Calendar = *Backup.Calendar[i];
4667 error=Phone->AddCalendar(&s,&Calendar); 4821 error=Phone->AddCalendar(&s,&Calendar);
4668 Print_Error(error); 4822 Print_Error(error);
4669 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 4823 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4670 if (gshutdown) { 4824 if (gshutdown) {
4671 GSM_Terminate(); 4825 GSM_Terminate();
4672 exit(0); 4826 exit(0);
4673 } 4827 }
4674 } 4828 }
4675 printmsgerr("\n"); 4829 printmsgerr("\n");
4676 } 4830 }
4677 4831
4678 DoRestore = false; 4832 DoRestore = false;
4679 if (Backup.ToDo[0] != NULL) { 4833 if (Backup.ToDo[0] != NULL) {
4680 error = Phone->GetToDoStatus(&s,&ToDoStatus); 4834 error = Phone->GetToDoStatus(&s,&ToDoStatus);
4681 if (error == ERR_NONE) { 4835 if (error == ERR_NONE) {
4682 error == ERR_NOTSUPPORTED;
4683 DoRestore = true;
4684 max = 0; 4836 max = 0;
4685 while (Backup.ToDo[max]!=NULL) max++; 4837 while (Backup.ToDo[max]!=NULL) max++;
4686 printmsgerr("%i entries in backup file\n",max); 4838 printmsgerr("%i entries in backup file\n",max);
4687 4839
4688 /*if (answer_yes("Restore ToDo")) */DoRestore = true; 4840 //LR if (answer_yes("Restore ToDo"))
4841 DoRestore = true;
4689 } 4842 }
4690 } 4843 }
4691 if (DoRestore) { 4844 if (DoRestore) {
4692 if ( max > 0 ) {
4693 ToDo = *Backup.ToDo[0]; 4845 ToDo = *Backup.ToDo[0];
4694 error = Phone->SetToDo(&s,&ToDo); 4846 error = Phone->SetToDo(&s,&ToDo);
4695 }
4696 } 4847 }
4697 if (DoRestore && (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED)) { 4848 if (DoRestore && (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED)) {
4698 printmsgerr("Deleting old ToDo: "); 4849 printmsgerr("Deleting old ToDo: ");
4699 error=Phone->DeleteAllToDo(&s); 4850 error=Phone->DeleteAllToDo(&s);
4700 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 4851 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
4701 while (1) { 4852 while (1) {
4702 error = Phone->GetNextToDo(&s,&ToDo,true); 4853 error = Phone->GetNextToDo(&s,&ToDo,true);
4703 if (error != ERR_NONE) break; 4854 if (error != ERR_NONE) break;
4704 error = Phone->DeleteToDo(&s,&ToDo); 4855 error = Phone->DeleteToDo(&s,&ToDo);
4705 Print_Error(error); 4856 Print_Error(error);
4706 printmsgerr("*"); 4857 printmsgerr("*");
4707 } 4858 }
4708 printmsgerr("\n"); 4859 printmsgerr("\n");
4709 } else { 4860 } else {
4710 printmsgerr("Done\n"); 4861 printmsgerr("Done\n");
4711 Print_Error(error); 4862 Print_Error(error);
4712 } 4863 }
4713 4864
4714 for (i=0;i<max;i++) { 4865 for (i=0;i<max;i++) {
4715 ToDo = *Backup.ToDo[i]; 4866 ToDo = *Backup.ToDo[i];
4716 ToDo.Location = 0; 4867 ToDo.Location = 0;
4717 error=Phone->AddToDo(&s,&ToDo); 4868 error=Phone->AddToDo(&s,&ToDo);
4718 Print_Error(error); 4869 Print_Error(error);
4719 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 4870 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4720 if (gshutdown) { 4871 if (gshutdown) {
4721 GSM_Terminate(); 4872 GSM_Terminate();
4722 exit(0); 4873 exit(0);
4723 } 4874 }
4724 } 4875 }
4725 printmsgerr("\n"); 4876 printmsgerr("\n");
4726 } else if (DoRestore) { 4877 } else if (DoRestore) {
4727 /* At first delete entries, that were deleted */ 4878 /* At first delete entries, that were deleted */
4728 used = 0; 4879 used = 0;
4729 error = Phone->GetNextToDo(&s,&ToDo,true); 4880 error = Phone->GetNextToDo(&s,&ToDo,true);
4730 while (error == ERR_NONE) { 4881 while (error == ERR_NONE) {
4731 used++; 4882 used++;
4732 Found = false; 4883 Found = false;
4733 for (i=0;i<max;i++) { 4884 for (i=0;i<max;i++) {
4734 if (Backup.ToDo[i]->Location == ToDo.Location) { 4885 if (Backup.ToDo[i]->Location == ToDo.Location) {
4735 Found = true; 4886 Found = true;
4736 break; 4887 break;
4737 } 4888 }
4738 } 4889 }
4739 if (!Found) { 4890 if (!Found) {
4740 error=Phone->DeleteToDo(&s,&ToDo); 4891 error=Phone->DeleteToDo(&s,&ToDo);
4741 Print_Error(error); 4892 Print_Error(error);
4742 } 4893 }
4743 error = Phone->GetNextToDo(&s,&ToDo,false); 4894 error = Phone->GetNextToDo(&s,&ToDo,false);
4744 printmsgerr("%cCleaning: %i percent",13,used*100/ToDoStatus.Used); 4895 printmsgerr("%cCleaning: %i percent",13,used*100/ToDoStatus.Used);
4745 if (gshutdown) { 4896 if (gshutdown) {
4746 GSM_Terminate(); 4897 GSM_Terminate();
4747 exit(0); 4898 exit(0);
4748 } 4899 }
4749 } 4900 }
4750 printmsgerr("\n"); 4901 printmsgerr("\n");
4751 4902
4752 /* Now write modified/new entries */ 4903 /* Now write modified/new entries */
4753 for (i=0;i<max;i++) { 4904 for (i=0;i<max;i++) {
4754 ToDo = *Backup.ToDo[i]; 4905 ToDo = *Backup.ToDo[i];
4755 error = Phone->SetToDo(&s,&ToDo); 4906 error = Phone->SetToDo(&s,&ToDo);
4756 Print_Error(error); 4907 Print_Error(error);
4757 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 4908 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4758 if (gshutdown) { 4909 if (gshutdown) {
4759 GSM_Terminate(); 4910 GSM_Terminate();
4760 exit(0); 4911 exit(0);
4761 } 4912 }
4762 } 4913 }
4763 printmsgerr("\n"); 4914 printmsgerr("\n");
4764 } 4915 }
4765 4916
4766 if (Backup.SMSC[0] != NULL && answer_yes("Restore SMSC profiles")) { 4917 if (Backup.SMSC[0] != NULL && answer_yes("Restore SMSC profiles")) {
4767 max = 0; 4918 max = 0;
4768 while (Backup.SMSC[max]!=NULL) max++; 4919 while (Backup.SMSC[max]!=NULL) max++;
4769 for (i=0;i<max;i++) { 4920 for (i=0;i<max;i++) {
4770 error=Phone->SetSMSC(&s,Backup.SMSC[i]); 4921 error=Phone->SetSMSC(&s,Backup.SMSC[i]);
4771 Print_Error(error); 4922 Print_Error(error);
4772 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 4923 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4773 if (gshutdown) { 4924 if (gshutdown) {
4774 GSM_Terminate(); 4925 GSM_Terminate();
4775 exit(0); 4926 exit(0);
4776 } 4927 }
4777 } 4928 }
4778 printmsgerr("\n"); 4929 printmsgerr("\n");
4779 } 4930 }
4780 if (Backup.StartupLogo != NULL && answer_yes("Restore startup logo/text")) { 4931 if (Backup.StartupLogo != NULL && answer_yes("Restore startup logo/text")) {
4781 error=Phone->SetBitmap(&s,Backup.StartupLogo); 4932 error=Phone->SetBitmap(&s,Backup.StartupLogo);
4782 Print_Error(error); 4933 Print_Error(error);
4783 } 4934 }
4784 if (Backup.OperatorLogo != NULL && answer_yes("Restore operator logo")) { 4935 if (Backup.OperatorLogo != NULL && answer_yes("Restore operator logo")) {
4785 error=Phone->SetBitmap(&s,Backup.OperatorLogo); 4936 error=Phone->SetBitmap(&s,Backup.OperatorLogo);
4786 Print_Error(error); 4937 Print_Error(error);
4787 } 4938 }
4788 DoRestore = false; 4939 DoRestore = false;
4789 if (Backup.WAPBookmark[0] != NULL) { 4940 if (Backup.WAPBookmark[0] != NULL) {
4790 Bookmark.Location = 1; 4941 Bookmark.Location = 1;
4791 error = Phone->GetWAPBookmark(&s,&Bookmark); 4942 error = Phone->GetWAPBookmark(&s,&Bookmark);
4792 if (error == ERR_NONE || error == ERR_INVALIDLOCATION) { 4943 if (error == ERR_NONE || error == ERR_INVALIDLOCATION) {
4793 if (answer_yes("Restore WAP bookmarks")) DoRestore = true; 4944 if (answer_yes("Restore WAP bookmarks")) DoRestore = true;
4794 } 4945 }
4795 } 4946 }
4796 if (DoRestore) { 4947 if (DoRestore) {
4797 printmsgerr("Deleting old bookmarks: "); 4948 printmsgerr("Deleting old bookmarks: ");
4798 /* One thing to explain: DCT4 phones seems to have bug here. 4949 /* One thing to explain: DCT4 phones seems to have bug here.
4799 * When delete for example first bookmark, phone change 4950 * When delete for example first bookmark, phone change
4800 * numeration for getting frame, not for deleting. So, we try to 4951 * numeration for getting frame, not for deleting. So, we try to
4801 * get 1'st bookmark. Inside frame is "correct" location. We use 4952 * get 1'st bookmark. Inside frame is "correct" location. We use
4802 * it later 4953 * it later
4803 */ 4954 */
4804 while (error==ERR_NONE) { 4955 while (error==ERR_NONE) {
4805 error = Phone->DeleteWAPBookmark(&s,&Bookmark); 4956 error = Phone->DeleteWAPBookmark(&s,&Bookmark);
4806 Bookmark.Location = 1; 4957 Bookmark.Location = 1;
4807 error = Phone->GetWAPBookmark(&s,&Bookmark); 4958 error = Phone->GetWAPBookmark(&s,&Bookmark);
4808 printmsgerr("*"); 4959 printmsgerr("*");
4809 } 4960 }
4810 printmsgerr("\n"); 4961 printmsgerr("\n");
4811 max = 0; 4962 max = 0;
4812 while (Backup.WAPBookmark[max]!=NULL) max++; 4963 while (Backup.WAPBookmark[max]!=NULL) max++;
4813 for (i=0;i<max;i++) { 4964 for (i=0;i<max;i++) {
4814 Bookmark = *Backup.WAPBookmark[i]; 4965 Bookmark = *Backup.WAPBookmark[i];
4815 Bookmark.Location = 0; 4966 Bookmark.Location = 0;
4816 error=Phone->SetWAPBookmark(&s,&Bookmark); 4967 error=Phone->SetWAPBookmark(&s,&Bookmark);
4817 Print_Error(error); 4968 Print_Error(error);
4818 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 4969 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4819 if (gshutdown) { 4970 if (gshutdown) {
4820 GSM_Terminate(); 4971 GSM_Terminate();
4821 exit(0); 4972 exit(0);
4822 } 4973 }
4823 } 4974 }
4824 printmsgerr("\n"); 4975 printmsgerr("\n");
4825 } 4976 }
4826 DoRestore = false; 4977 DoRestore = false;
4827 if (Backup.WAPSettings[0] != NULL) { 4978 if (Backup.WAPSettings[0] != NULL) {
4828 Settings.Location = 1; 4979 Settings.Location = 1;
4829 error = Phone->GetWAPSettings(&s,&Settings); 4980 error = Phone->GetWAPSettings(&s,&Settings);
4830 if (error == ERR_NONE) { 4981 if (error == ERR_NONE) {
4831 if (answer_yes("Restore WAP settings")) DoRestore = true; 4982 if (answer_yes("Restore WAP settings")) DoRestore = true;
4832 } 4983 }
4833 } 4984 }
4834 if (DoRestore) { 4985 if (DoRestore) {
4835 max = 0; 4986 max = 0;
4836 while (Backup.WAPSettings[max]!=NULL) max++; 4987 while (Backup.WAPSettings[max]!=NULL) max++;
4837 for (i=0;i<max;i++) { 4988 for (i=0;i<max;i++) {
4838 error=Phone->SetWAPSettings(&s,Backup.WAPSettings[i]); 4989 error=Phone->SetWAPSettings(&s,Backup.WAPSettings[i]);
4839 Print_Error(error); 4990 Print_Error(error);
4840 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 4991 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4841 if (gshutdown) { 4992 if (gshutdown) {
4842 GSM_Terminate(); 4993 GSM_Terminate();
4843 exit(0); 4994 exit(0);
4844 } 4995 }
4845 } 4996 }
4846 printmsgerr("\n"); 4997 printmsgerr("\n");
4847 } 4998 }
4848 DoRestore = false; 4999 DoRestore = false;
4849 if (Backup.MMSSettings[0] != NULL) { 5000 if (Backup.MMSSettings[0] != NULL) {
4850 Settings.Location = 1; 5001 Settings.Location = 1;
4851 error = Phone->GetMMSSettings(&s,&Settings); 5002 error = Phone->GetMMSSettings(&s,&Settings);
4852 if (error == ERR_NONE) { 5003 if (error == ERR_NONE) {
4853 if (answer_yes("Restore MMS settings")) DoRestore = true; 5004 if (answer_yes("Restore MMS settings")) DoRestore = true;
4854 } 5005 }
4855 } 5006 }
4856 if (DoRestore) { 5007 if (DoRestore) {
4857 max = 0; 5008 max = 0;
4858 while (Backup.MMSSettings[max]!=NULL) max++; 5009 while (Backup.MMSSettings[max]!=NULL) max++;
4859 for (i=0;i<max;i++) { 5010 for (i=0;i<max;i++) {
4860 error=Phone->SetMMSSettings(&s,Backup.MMSSettings[i]); 5011 error=Phone->SetMMSSettings(&s,Backup.MMSSettings[i]);
4861 Print_Error(error); 5012 Print_Error(error);
4862 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 5013 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4863 if (gshutdown) { 5014 if (gshutdown) {
4864 GSM_Terminate(); 5015 GSM_Terminate();
4865 exit(0); 5016 exit(0);
4866 } 5017 }
4867 } 5018 }
4868 printmsgerr("\n"); 5019 printmsgerr("\n");
4869 } 5020 }
4870 DoRestore = false; 5021 DoRestore = false;
4871 if (Backup.Ringtone[0] != NULL) { 5022 if (Backup.Ringtone[0] != NULL) {
4872 Ringtone.Location = 1; 5023 Ringtone.Location = 1;
4873 Ringtone.Format = 0; 5024 Ringtone.Format = 0;
4874 error = Phone->GetRingtone(&s,&Ringtone,false); 5025 error = Phone->GetRingtone(&s,&Ringtone,false);
4875 if (error == ERR_NONE || error ==ERR_EMPTY) { 5026 if (error == ERR_NONE || error ==ERR_EMPTY) {
4876 if (Phone->DeleteUserRingtones != NOTSUPPORTED) { 5027 if (Phone->DeleteUserRingtones != NOTSUPPORTED) {
4877 if (answer_yes("Delete all user ringtones")) DoRestore = true; 5028 if (answer_yes("Delete all user ringtones")) DoRestore = true;
4878 } 5029 }
4879 } 5030 }
4880 } 5031 }
4881 if (DoRestore) { 5032 if (DoRestore) {
4882 printmsgerr("Deleting: "); 5033 printmsgerr("Deleting: ");
4883 error=Phone->DeleteUserRingtones(&s); 5034 error=Phone->DeleteUserRingtones(&s);
4884 Print_Error(error); 5035 Print_Error(error);
4885 printmsgerr("Done\n"); 5036 printmsgerr("Done\n");
4886 DoRestore = false; 5037 DoRestore = false;
4887 if (answer_yes("Restore user ringtones")) DoRestore = true; 5038 if (answer_yes("Restore user ringtones")) DoRestore = true;
4888 } 5039 }
4889 if (DoRestore) { 5040 if (DoRestore) {
4890 max = 0; 5041 max = 0;
4891 while (Backup.Ringtone[max]!=NULL) max++; 5042 while (Backup.Ringtone[max]!=NULL) max++;
4892 for (i=0;i<max;i++) { 5043 for (i=0;i<max;i++) {
4893 error=GSM_RingtoneConvert(&Ringtone, Backup.Ringtone[i], Ringtone.Format); 5044 error=GSM_RingtoneConvert(&Ringtone, Backup.Ringtone[i], Ringtone.Format);
4894 Print_Error(error); 5045 Print_Error(error);
4895 error=Phone->SetRingtone(&s,&Ringtone,&i); 5046 error=Phone->SetRingtone(&s,&Ringtone,&i);
4896 Print_Error(error); 5047 Print_Error(error);
4897 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 5048 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4898 if (gshutdown) { 5049 if (gshutdown) {
4899 GSM_Terminate(); 5050 GSM_Terminate();
4900 exit(0); 5051 exit(0);
4901 } 5052 }
4902 } 5053 }
4903 printmsgerr("\n"); 5054 printmsgerr("\n");
4904 } 5055 }
4905 DoRestore = false; 5056 DoRestore = false;
4906 if (Backup.Profiles[0] != NULL) { 5057 if (Backup.Profiles[0] != NULL) {
4907 Profile.Location = 1; 5058 Profile.Location = 1;
4908 error = Phone->GetProfile(&s,&Profile); 5059 error = Phone->GetProfile(&s,&Profile);
4909 if (error == ERR_NONE) { 5060 if (error == ERR_NONE) {
4910 if (answer_yes("Restore profiles")) DoRestore = true; 5061 if (answer_yes("Restore profiles")) DoRestore = true;
4911 } 5062 }
4912 } 5063 }
4913 if (DoRestore) { 5064 if (DoRestore) {
4914 Profile.Location= 0; 5065 Profile.Location= 0;
4915 max = 0; 5066 max = 0;
4916 while (Backup.Profiles[max]!=NULL) max++; 5067 while (Backup.Profiles[max]!=NULL) max++;
4917 for (i=0;i<max;i++) { 5068 for (i=0;i<max;i++) {
4918 Profile= *Backup.Profiles[i]; 5069 Profile= *Backup.Profiles[i];
4919 error=Phone->SetProfile(&s,&Profile); 5070 error=Phone->SetProfile(&s,&Profile);
4920 Print_Error(error); 5071 Print_Error(error);
4921 if (gshutdown) { 5072 if (gshutdown) {
4922 GSM_Terminate(); 5073 GSM_Terminate();
4923 exit(0); 5074 exit(0);
4924 } 5075 }
4925 } 5076 }
4926 printmsgerr("\n"); 5077 printmsgerr("\n");
4927 } 5078 }
4928 DoRestore = false; 5079 DoRestore = false;
4929 if (Backup.FMStation[0] != NULL) { 5080 if (Backup.FMStation[0] != NULL) {
4930 FMStation.Location = 1; 5081 FMStation.Location = 1;
4931 error = Phone->GetFMStation(&s,&FMStation); 5082 error = Phone->GetFMStation(&s,&FMStation);
4932 if (error == ERR_NONE || error == ERR_EMPTY) { 5083 if (error == ERR_NONE || error == ERR_EMPTY) {
4933 if (answer_yes("Restore FM stations")) DoRestore = true; 5084 if (answer_yes("Restore FM stations")) DoRestore = true;
4934 } 5085 }
4935 } 5086 }
4936 if (DoRestore) { 5087 if (DoRestore) {
4937 printmsgerr("Deleting old FM stations: "); 5088 printmsgerr("Deleting old FM stations: ");
4938 error=Phone->ClearFMStations(&s); 5089 error=Phone->ClearFMStations(&s);
4939 Print_Error(error); 5090 Print_Error(error);
4940 printmsgerr("Done\n"); 5091 printmsgerr("Done\n");
4941 max = 0; 5092 max = 0;
4942 while (Backup.FMStation[max]!=NULL) max++; 5093 while (Backup.FMStation[max]!=NULL) max++;
4943 for (i=0;i<max;i++) { 5094 for (i=0;i<max;i++) {
4944 FMStation = *Backup.FMStation[i]; 5095 FMStation = *Backup.FMStation[i];
4945 error=Phone->SetFMStation(&s,&FMStation); 5096 error=Phone->SetFMStation(&s,&FMStation);
4946 Print_Error(error); 5097 Print_Error(error);
4947 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 5098 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4948 if (gshutdown) { 5099 if (gshutdown) {
4949 GSM_Terminate(); 5100 GSM_Terminate();
4950 exit(0); 5101 exit(0);
4951 } 5102 }
4952 } 5103 }
4953 printmsgerr("\n"); 5104 printmsgerr("\n");
4954 } 5105 }
4955 DoRestore = false; 5106 DoRestore = false;
4956 if (Backup.GPRSPoint[0] != NULL) { 5107 if (Backup.GPRSPoint[0] != NULL) {
4957 GPRSPoint.Location = 1; 5108 GPRSPoint.Location = 1;
4958 error = Phone->GetGPRSAccessPoint(&s,&GPRSPoint); 5109 error = Phone->GetGPRSAccessPoint(&s,&GPRSPoint);
4959 if (error == ERR_NONE || error == ERR_EMPTY) { 5110 if (error == ERR_NONE || error == ERR_EMPTY) {
4960 if (answer_yes("Restore GPRS Points")) DoRestore = true; 5111 if (answer_yes("Restore GPRS Points")) DoRestore = true;
4961 } 5112 }
4962 } 5113 }
4963 if (DoRestore) { 5114 if (DoRestore) {
4964 max = 0; 5115 max = 0;
4965 while (Backup.GPRSPoint[max]!=NULL) max++; 5116 while (Backup.GPRSPoint[max]!=NULL) max++;
4966 for (i=0;i<max;i++) { 5117 for (i=0;i<max;i++) {
4967 error=Phone->SetGPRSAccessPoint(&s,Backup.GPRSPoint[i]); 5118 error=Phone->SetGPRSAccessPoint(&s,Backup.GPRSPoint[i]);
4968 Print_Error(error); 5119 Print_Error(error);
4969 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 5120 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
4970 if (gshutdown) { 5121 if (gshutdown) {
4971 GSM_Terminate(); 5122 GSM_Terminate();
4972 exit(0); 5123 exit(0);
4973 } 5124 }
4974 } 5125 }
4975 printmsgerr("\n"); 5126 printmsgerr("\n");
4976 } 5127 }
4977 5128
4978 GSM_Terminate(); 5129 GSM_Terminate();
4979} 5130}
4980 5131
4981static void AddNew(int argc, char *argv[]) 5132static void AddNew(int argc, char *argv[])
4982{ 5133{
4983 GSM_Backup Backup; 5134 GSM_Backup Backup;
4984 GSM_DateTime date_time; 5135 GSM_DateTime date_time;
4985 GSM_MemoryEntry Pbk; 5136 GSM_MemoryEntry Pbk;
4986 GSM_MemoryStatusMemStatus; 5137 GSM_MemoryStatusMemStatus;
4987 GSM_ToDoEntry ToDo; 5138 GSM_ToDoEntry ToDo;
4988 GSM_ToDoStatus ToDoStatus; 5139 GSM_ToDoStatus ToDoStatus;
4989 GSM_CalendarEntryCalendar; 5140 GSM_CalendarEntryCalendar;
4990 GSM_WAPBookmark Bookmark; 5141 GSM_WAPBookmark Bookmark;
4991 int i, max, j; 5142 int i, max, j;
4992 5143
4993 error=GSM_ReadBackupFile(argv[2],&Backup); 5144 error=GSM_ReadBackupFile(argv[2],&Backup);
4994 Print_Error(error); 5145 if (error!=ERR_NOTIMPLEMENTED) Print_Error(error);
4995 5146
4996 signal(SIGINT, interrupt); 5147 signal(SIGINT, interrupt);
4997 printmsgerr("Press Ctrl+C to break...\n"); 5148 printmsgerr("Press Ctrl+C to break...\n");
4998 5149
4999 if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false)); 5150 if (Backup.DateTimeAvailable) printmsgerr("Time of backup : %s\n",OSDateTime(Backup.DateTime,false));
5000 if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model); 5151 if (Backup.Model[0]!=0) printmsgerr("Phone : %s\n",Backup.Model);
5001 if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI); 5152 if (Backup.IMEI[0]!=0) printmsgerr("IMEI : %s\n",Backup.IMEI);
5002 5153
5003 GSM_Init(true); 5154 GSM_Init(true);
5004 5155
5005 if (Backup.PhonePhonebook[0] != NULL) { 5156 if (Backup.PhonePhonebook[0] != NULL) {
5006 MemStatus.MemoryType = MEM_ME; 5157 MemStatus.MemoryType = MEM_ME;
5007 error=Phone->GetMemoryStatus(&s, &MemStatus); 5158 error=Phone->GetMemoryStatus(&s, &MemStatus);
5008 if (error==ERR_NONE) { 5159 if (error==ERR_NONE) {
5009 max = 0; 5160 max = 0;
5010 while (Backup.PhonePhonebook[max]!=NULL) max++; 5161 while (Backup.PhonePhonebook[max]!=NULL) max++;
5011 printmsgerr("%i entries in backup file\n",max); 5162 printmsgerr("%i entries in backup file\n",max);
5012 if (MemStatus.MemoryFree < max) { 5163 if (MemStatus.MemoryFree < max) {
5013 printmsgerr("Memory has only %i free locations.Exiting\n",MemStatus.MemoryFree); 5164 printmsgerr("Memory has only %i free locations.Exiting\n",MemStatus.MemoryFree);
5014 } else if (answer_yes("Add phone phonebook entries")) { 5165 } else if (answer_yes("Add phone phonebook entries")) {
5015 for (i=0;i<max;i++) { 5166 for (i=0;i<max;i++) {
5016 Pbk = *Backup.PhonePhonebook[i]; 5167 Pbk = *Backup.PhonePhonebook[i];
5017 Pbk.MemoryType = MEM_ME; 5168 Pbk.MemoryType = MEM_ME;
5018 error=Phone->AddMemory(&s, &Pbk); 5169 error=Phone->AddMemory(&s, &Pbk);
5019 Print_Error(error); 5170 Print_Error(error);
5020 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 5171 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
5021 if (gshutdown) { 5172 if (gshutdown) {
5022 GSM_Terminate(); 5173 GSM_Terminate();
5023 exit(0); 5174 exit(0);
5024 } 5175 }
5025 } 5176 }
5026 printmsgerr("\n"); 5177 printmsgerr("\n");
5027 } 5178 }
5028 } 5179 }
5029 } 5180 }
5030 if (Backup.SIMPhonebook[0] != NULL) { 5181 if (Backup.SIMPhonebook[0] != NULL) {
5031 MemStatus.MemoryType = MEM_SM; 5182 MemStatus.MemoryType = MEM_SM;
5032 error=Phone->GetMemoryStatus(&s, &MemStatus); 5183 error=Phone->GetMemoryStatus(&s, &MemStatus);
5033 if (error==ERR_NONE) { 5184 if (error==ERR_NONE) {
5034 max = 0; 5185 max = 0;
5035 while (Backup.SIMPhonebook[max]!=NULL) max++; 5186 while (Backup.SIMPhonebook[max]!=NULL) max++;
5036 printmsgerr("%i entries in backup file\n",max); 5187 printmsgerr("%i entries in backup file\n",max);
5037 if (MemStatus.MemoryFree < max) { 5188 if (MemStatus.MemoryFree < max) {
5038 printmsgerr("Memory has only %i free locations.Exiting\n",MemStatus.MemoryFree); 5189 printmsgerr("Memory has only %i free locations.Exiting\n",MemStatus.MemoryFree);
5039 } else if (answer_yes("Add SIM phonebook entries")) { 5190 } else if (answer_yes("Add SIM phonebook entries")) {
5040 j = 1; 5191 j = 1;
5041 for (i=0;i<max;i++) { 5192 for (i=0;i<max;i++) {
5042 Pbk = *Backup.SIMPhonebook[i]; 5193 Pbk = *Backup.SIMPhonebook[i];
5043 Pbk.MemoryType = MEM_SM; 5194 Pbk.MemoryType = MEM_SM;
5044 error=Phone->AddMemory(&s, &Pbk); 5195 error=Phone->AddMemory(&s, &Pbk);
5045 Print_Error(error); 5196 Print_Error(error);
5046 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 5197 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
5047 if (gshutdown) { 5198 if (gshutdown) {
5048 GSM_Terminate(); 5199 GSM_Terminate();
5049 exit(0); 5200 exit(0);
5050 } 5201 }
5051 } 5202 }
5052 printmsgerr("\n"); 5203 printmsgerr("\n");
5053 } 5204 }
5054 } 5205 }
5055 } 5206 }
5056 5207
5057 if (!mystrncasecmp(s.CurrentConfig->SyncTime,"yes",0)) { 5208 if (!mystrncasecmp(s.CurrentConfig->SyncTime,"yes",0)) {
5058 if (answer_yes("Do you want to set date/time in phone (NOTE: in some phones it's required to correctly restore calendar notes and other items)")) { 5209 if (answer_yes("Do you want to set date/time in phone (NOTE: in some phones it's required to correctly restore calendar notes and other items)")) {
5059 GSM_GetCurrentDateTime(&date_time); 5210 GSM_GetCurrentDateTime(&date_time);
5060 5211
5061 error=Phone->SetDateTime(&s, &date_time); 5212 error=Phone->SetDateTime(&s, &date_time);
5062 Print_Error(error); 5213 Print_Error(error);
5063 } 5214 }
5064 } 5215 }
5065 if (Backup.Calendar[0] != NULL) { 5216 if (Backup.Calendar[0] != NULL) {
5066 error = Phone->GetNextCalendar(&s,&Calendar,true); 5217 error = Phone->GetNextCalendar(&s,&Calendar,true);
5067 if (error == ERR_NONE || error == ERR_INVALIDLOCATION || error == ERR_EMPTY) { 5218 if (error == ERR_NONE || error == ERR_INVALIDLOCATION || error == ERR_EMPTY) {
5068 if (answer_yes("Add calendar notes")) { 5219 if (answer_yes("Add calendar notes")) {
5069 max = 0; 5220 max = 0;
5070 while (Backup.Calendar[max]!=NULL) max++; 5221 while (Backup.Calendar[max]!=NULL) max++;
5071 for (i=0;i<max;i++) { 5222 for (i=0;i<max;i++) {
5072 Calendar = *Backup.Calendar[i]; 5223 Calendar = *Backup.Calendar[i];
5073 error=Phone->AddCalendar(&s,&Calendar); 5224 error=Phone->AddCalendar(&s,&Calendar);
5074 Print_Error(error); 5225 Print_Error(error);
5075 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 5226 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
5076 if (gshutdown) { 5227 if (gshutdown) {
5077 GSM_Terminate(); 5228 GSM_Terminate();
5078 exit(0); 5229 exit(0);
5079 } 5230 }
5080 } 5231 }
5081 printmsgerr("\n"); 5232 printmsgerr("\n");
5082 } 5233 }
5083 } 5234 }
5084 } 5235 }
5085 if (Backup.ToDo[0] != NULL) { 5236 if (Backup.ToDo[0] != NULL) {
5086 ToDo.Location = 1; 5237 ToDo.Location = 1;
5087 error=Phone->GetToDoStatus(&s,&ToDoStatus); 5238 error=Phone->GetToDoStatus(&s,&ToDoStatus);
5088 if (error == ERR_NONE) { 5239 if (error == ERR_NONE) {
5089 if (answer_yes("Add ToDo")) { 5240 if (answer_yes("Add ToDo")) {
5090 max = 0; 5241 max = 0;
5091 while (Backup.ToDo[max]!=NULL) max++; 5242 while (Backup.ToDo[max]!=NULL) max++;
5092 for (i=0;i<max;i++) { 5243 for (i=0;i<max;i++) {
5093 ToDo = *Backup.ToDo[i]; 5244 ToDo = *Backup.ToDo[i];
5094 error = Phone->AddToDo(&s,&ToDo); 5245 error = Phone->AddToDo(&s,&ToDo);
5095 Print_Error(error); 5246 Print_Error(error);
5096 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 5247 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
5097 if (gshutdown) { 5248 if (gshutdown) {
5098 GSM_Terminate(); 5249 GSM_Terminate();
5099 exit(0); 5250 exit(0);
5100 } 5251 }
5101 } 5252 }
5102 printmsgerr("\n"); 5253 printmsgerr("\n");
5103 } 5254 }
5104 } 5255 }
5105 } 5256 }
5106 if (Backup.WAPBookmark[0] != NULL) { 5257 if (Backup.WAPBookmark[0] != NULL) {
5107 Bookmark.Location = 1; 5258 Bookmark.Location = 1;
5108 error = Phone->GetWAPBookmark(&s,&Bookmark); 5259 error = Phone->GetWAPBookmark(&s,&Bookmark);
5109 if (error == ERR_NONE || error == ERR_INVALIDLOCATION) { 5260 if (error == ERR_NONE || error == ERR_INVALIDLOCATION) {
5110 if (answer_yes("Add WAP bookmarks")) { 5261 if (answer_yes("Add WAP bookmarks")) {
5111 max = 0; 5262 max = 0;
5112 while (Backup.WAPBookmark[max]!=NULL) max++; 5263 while (Backup.WAPBookmark[max]!=NULL) max++;
5113 for (i=0;i<max;i++) { 5264 for (i=0;i<max;i++) {
5114 Bookmark = *Backup.WAPBookmark[i]; 5265 Bookmark = *Backup.WAPBookmark[i];
5115 Bookmark.Location = 0; 5266 Bookmark.Location = 0;
5116 error=Phone->SetWAPBookmark(&s,&Bookmark); 5267 error=Phone->SetWAPBookmark(&s,&Bookmark);
5117 Print_Error(error); 5268 Print_Error(error);
5118 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max); 5269 printmsgerr("%cWriting: %i percent",13,(i+1)*100/max);
5119 if (gshutdown) { 5270 if (gshutdown) {
5120 GSM_Terminate(); 5271 GSM_Terminate();
5121 exit(0); 5272 exit(0);
5122 } 5273 }
5123 } 5274 }
5124 printmsgerr("\n"); 5275 printmsgerr("\n");
5125 } 5276 }
5126 } 5277 }
5127 } 5278 }
5128 5279
5129 GSM_Terminate(); 5280 GSM_Terminate();
5130} 5281}
5131#endif 5282#endif
5132 5283
5133static void ClearAll(int argc, char *argv[]) 5284static void ClearAll(int argc, char *argv[])
5134{ 5285{
5135 GSM_MemoryStatusMemStatus; 5286 GSM_MemoryStatusMemStatus;
5136 GSM_ToDoStatus ToDoStatus; 5287 GSM_ToDoStatus ToDoStatus;
5137 GSM_CalendarEntryCalendar; 5288 GSM_CalendarEntryCalendar;
5138 GSM_ToDoEntry ToDo; 5289 GSM_ToDoEntry ToDo;
5139 GSM_WAPBookmark Bookmark; 5290 GSM_WAPBookmark Bookmark;
5140 GSM_FMStation Station; 5291 GSM_FMStation Station;
5141 GSM_MemoryEntry Pbk; 5292 GSM_MemoryEntry Pbk;
5142 bool DoClear; 5293 bool DoClear;
5143 5294
5144 GSM_Init(true); 5295 GSM_Init(true);
5145 5296
5146 DoClear = false; 5297 DoClear = false;
5147 MemStatus.MemoryType = MEM_ME; 5298 MemStatus.MemoryType = MEM_ME;
5148 error=Phone->GetMemoryStatus(&s, &MemStatus); 5299 error=Phone->GetMemoryStatus(&s, &MemStatus);
5149 if (error==ERR_NONE && MemStatus.MemoryUsed !=0) { 5300 if (error==ERR_NONE && MemStatus.MemoryUsed !=0) {
5150 if (answer_yes("Delete phone phonebook")) DoClear = true; 5301 if (answer_yes("Delete phone phonebook")) DoClear = true;
5151 } 5302 }
5152 if (DoClear) { 5303 if (DoClear) {
5153 error = Phone->DeleteAllMemory(&s,MEM_ME); 5304 error = Phone->DeleteAllMemory(&s,MEM_ME);
5154 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 5305 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
5155 for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) { 5306 for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) {
5156 Pbk.MemoryType = MEM_ME; 5307 Pbk.MemoryType = MEM_ME;
5157 Pbk.Location= i + 1; 5308 Pbk.Location= i + 1;
5158 Pbk.EntriesNum= 0; 5309 Pbk.EntriesNum= 0;
5159 error=Phone->DeleteMemory(&s, &Pbk); 5310 error=Phone->DeleteMemory(&s, &Pbk);
5160 Print_Error(error); 5311 Print_Error(error);
5161 printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.MemoryUsed+MemStatus.MemoryFree)); 5312 printmsgerr("%cWriting: %i percent",13,(i+1)*100/(MemStatus.MemoryUsed+MemStatus.MemoryFree));
5162 if (gshutdown) { 5313 if (gshutdown) {
5163 GSM_Terminate(); 5314 GSM_Terminate();
5164 exit(0); 5315 exit(0);
5165 } 5316 }
5166 } 5317 }
5167 printmsgerr("\n"); 5318 printmsgerr("\n");
5168 } else { 5319 } else {
5169 printmsgerr("Done\n"); 5320 printmsgerr("Done\n");
5170 Print_Error(error); 5321 Print_Error(error);
5171 } 5322 }
5172 } 5323 }
5173 5324
5174 DoClear = false; 5325 DoClear = false;
5175 MemStatus.MemoryType = MEM_SM; 5326 MemStatus.MemoryType = MEM_SM;
5176 error=Phone->GetMemoryStatus(&s, &MemStatus); 5327 error=Phone->GetMemoryStatus(&s, &MemStatus);
5177 if (error==ERR_NONE && MemStatus.MemoryUsed !=0) { 5328 if (error==ERR_NONE && MemStatus.MemoryUsed !=0) {
5178 if (answer_yes("Delete SIM phonebook")) DoClear = true; 5329 if (answer_yes("Delete SIM phonebook")) DoClear = true;
5179 } 5330 }
5180 if (DoClear) { 5331 if (DoClear) {
5181 error = Phone->DeleteAllMemory(&s,MEM_SM); 5332 error = Phone->DeleteAllMemory(&s,MEM_SM);
5182 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) { 5333 if (error == ERR_NOTSUPPORTED || error == ERR_NOTIMPLEMENTED) {
5183 for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) { 5334 for (i=0;i<MemStatus.MemoryUsed+MemStatus.MemoryFree;i++) {
5184 Pbk.MemoryType = MEM_SM; 5335 Pbk.MemoryType = MEM_SM;
5185 Pbk.Location= i + 1; 5336 Pbk.Location= i + 1;
5186 Pbk.EntriesNum= 0; 5337 Pbk.EntriesNum= 0;
@@ -5429,942 +5580,934 @@ static void GetChatSettings(int argc, char *argv[])
5429 printmsg("Set %i",i); 5580 printmsg("Set %i",i);
5430 } else { 5581 } else {
5431 printmsg("%s",DecodeUnicodeConsole(settings.Name)); 5582 printmsg("%s",DecodeUnicodeConsole(settings.Name));
5432 } 5583 }
5433 if (settings.Active) printmsg(" (active)"); 5584 if (settings.Active) printmsg(" (active)");
5434 // if (settings.ReadOnly) printmsg("\nRead only : yes"); 5585 // if (settings.ReadOnly) printmsg("\nRead only : yes");
5435 printmsg("\n"); 5586 printmsg("\n");
5436 printmsg("Homepage : \"%s\"\n",DecodeUnicodeConsole(settings.HomePage)); 5587 printmsg("Homepage : \"%s\"\n",DecodeUnicodeConsole(settings.HomePage));
5437 printmsg("User : \"%s\"\n",DecodeUnicodeConsole(settings.User)); 5588 printmsg("User : \"%s\"\n",DecodeUnicodeConsole(settings.User));
5438 printmsg("Password : \"%s\"\n",DecodeUnicodeConsole(settings.Password)); 5589 printmsg("Password : \"%s\"\n",DecodeUnicodeConsole(settings.Password));
5439 printmsg("\n"); 5590 printmsg("\n");
5440 for (j=0;j<settings.Connection.Number;j++) { 5591 for (j=0;j<settings.Connection.Number;j++) {
5441 if (settings.Connection.Settings[j].Title[0]==0 && settings.Connection.Settings[j].Title[1]==0) { 5592 if (settings.Connection.Settings[j].Title[0]==0 && settings.Connection.Settings[j].Title[1]==0) {
5442 printmsg("Connection set name : Set %i\n",i); 5593 printmsg("Connection set name : Set %i\n",i);
5443 } else { 5594 } else {
5444 printmsg("Connection set name : %s\n",DecodeUnicodeConsole(settings.Connection.Settings[j].Title)); 5595 printmsg("Connection set name : %s\n",DecodeUnicodeConsole(settings.Connection.Settings[j].Title));
5445 } 5596 }
5446 DisplayConnectionSettings(&settings.Connection,j); 5597 DisplayConnectionSettings(&settings.Connection,j);
5447 printf("\n"); 5598 printf("\n");
5448 } 5599 }
5449 } 5600 }
5450 GSM_Terminate(); 5601 GSM_Terminate();
5451} 5602}
5452 5603
5453static void GetWAPMMSSettings(int argc, char *argv[]) 5604static void GetWAPMMSSettings(int argc, char *argv[])
5454{ 5605{
5455 GSM_MultiWAPSettingssettings; 5606 GSM_MultiWAPSettingssettings;
5456 int start,stop,j; 5607 int start,stop,j;
5457 5608
5458 GetStartStop(&start, &stop, 2, argc, argv); 5609 GetStartStop(&start, &stop, 2, argc, argv);
5459 5610
5460 GSM_Init(true); 5611 GSM_Init(true);
5461 5612
5462 for (i=start;i<=stop;i++) { 5613 for (i=start;i<=stop;i++) {
5463 settings.Location=i; 5614 settings.Location=i;
5464 if (mystrncasecmp(argv[1],"--getwapsettings",0)) { 5615 if (mystrncasecmp(argv[1],"--getwapsettings",0)) {
5465 error=Phone->GetWAPSettings(&s,&settings); 5616 error=Phone->GetWAPSettings(&s,&settings);
5466 } else { 5617 } else {
5467 error=Phone->GetMMSSettings(&s,&settings); 5618 error=Phone->GetMMSSettings(&s,&settings);
5468 } 5619 }
5469 Print_Error(error); 5620 Print_Error(error);
5470 for (j=0;j<settings.Number;j++) { 5621 for (j=0;j<settings.Number;j++) {
5471 printmsg("%i. ",i); 5622 printmsg("%i. ",i);
5472 if (settings.Settings[j].Title[0]==0 && settings.Settings[j].Title[1]==0) { 5623 if (settings.Settings[j].Title[0]==0 && settings.Settings[j].Title[1]==0) {
5473 printmsg("Set %i",i); 5624 printmsg("Set %i",i);
5474 } else { 5625 } else {
5475 printmsg("%s",DecodeUnicodeConsole(settings.Settings[j].Title)); 5626 printmsg("%s",DecodeUnicodeConsole(settings.Settings[j].Title));
5476 } 5627 }
5477 if (settings.Active) printmsg(" (active)"); 5628 if (settings.Active) printmsg(" (active)");
5478 if (settings.ReadOnly) printmsg("\nRead only : yes"); 5629 if (settings.ReadOnly) printmsg("\nRead only : yes");
5479 printmsg("\nHomepage : \"%s\"\n",DecodeUnicodeConsole(settings.Settings[j].HomePage)); 5630 printmsg("\nHomepage : \"%s\"\n",DecodeUnicodeConsole(settings.Settings[j].HomePage));
5480 DisplayConnectionSettings(&settings,j); 5631 DisplayConnectionSettings(&settings,j);
5481 printf("\n"); 5632 printf("\n");
5482 } 5633 }
5483 } 5634 }
5484 GSM_Terminate(); 5635 GSM_Terminate();
5485} 5636}
5486 5637
5487#ifdef GSM_ENABLE_BACKUP 5638#ifdef GSM_ENABLE_BACKUP
5488static void BackupSMS(int argc, char *argv[]) 5639static void BackupSMS(int argc, char *argv[])
5489{ 5640{
5490 GSM_SMS_Backup Backup; 5641 GSM_SMS_Backup Backup;
5491 GSM_MultiSMSMessage sms; 5642 GSM_MultiSMSMessage sms;
5492 GSM_SMSFolders folders; 5643 GSM_SMSFolders folders;
5493 bool BackupFromFolder[GSM_MAX_SMS_FOLDERS]; 5644 bool BackupFromFolder[GSM_MAX_SMS_FOLDERS];
5494 bool start = true; 5645 bool start = true;
5495 bool DeleteAfter; 5646 bool DeleteAfter;
5496 int j, smsnum; 5647 int j, smsnum;
5497 char buffer[200]; 5648 char buffer[200];
5498 5649
5499 /* We ignore return code, because (when file doesn't exist) we 5650 /* We ignore return code, because (when file doesn't exist) we
5500 * will create new later 5651 * will create new later
5501 */ 5652 */
5502 GSM_ReadSMSBackupFile(argv[2], &Backup); 5653 GSM_ReadSMSBackupFile(argv[2], &Backup);
5503 smsnum = 0; 5654 smsnum = 0;
5504 while (Backup.SMS[smsnum]!=NULL) smsnum++; 5655 while (Backup.SMS[smsnum]!=NULL) smsnum++;
5505 5656
5506 GSM_Init(true); 5657 GSM_Init(true);
5507 5658
5508 error=Phone->GetSMSFolders(&s, &folders); 5659 error=Phone->GetSMSFolders(&s, &folders);
5509 Print_Error(error); 5660 Print_Error(error);
5510 5661
5511 DeleteAfter=answer_yes("Delete each sms after backup"); 5662 DeleteAfter=answer_yes("Delete each sms after backup");
5512 5663
5513 for (j=0;j<folders.Number;j++) { 5664 for (j=0;j<folders.Number;j++) {
5514 BackupFromFolder[j] = false; 5665 BackupFromFolder[j] = false;
5515 sprintf(buffer,"Backup sms from folder \"%s\"",DecodeUnicodeConsole(folders.Folder[j].Name)); 5666 sprintf(buffer,"Backup sms from folder \"%s\"",DecodeUnicodeConsole(folders.Folder[j].Name));
5516 if (answer_yes(buffer)) BackupFromFolder[j] = true; 5667 if (answer_yes(buffer)) BackupFromFolder[j] = true;
5517 } 5668 }
5518 5669
5519 while (error == ERR_NONE) { 5670 while (error == ERR_NONE) {
5520 sms.SMS[0].Folder=0x00; 5671 sms.SMS[0].Folder=0x00;
5521 error=Phone->GetNextSMS(&s, &sms, start); 5672 error=Phone->GetNextSMS(&s, &sms, start);
5522 switch (error) { 5673 switch (error) {
5523 case ERR_EMPTY: 5674 case ERR_EMPTY:
5524 break; 5675 break;
5525 default: 5676 default:
5526 Print_Error(error); 5677 Print_Error(error);
5527 for (j=0;j<sms.Number;j++) { 5678 for (j=0;j<sms.Number;j++) {
5528 if (BackupFromFolder[sms.SMS[j].Folder-1]) { 5679 if (BackupFromFolder[sms.SMS[j].Folder-1]) {
5529 switch (sms.SMS[j].PDU) { 5680 switch (sms.SMS[j].PDU) {
5530 case SMS_Status_Report: 5681 case SMS_Status_Report:
5531 break; 5682 break;
5532 case SMS_Submit: 5683 case SMS_Submit:
5533 case SMS_Deliver: 5684 case SMS_Deliver:
5534 if (sms.SMS[j].Length == 0) break; 5685 if (sms.SMS[j].Length == 0) break;
5535 if (smsnum < GSM_BACKUP_MAX_SMS) { 5686 if (smsnum < GSM_BACKUP_MAX_SMS) {
5536 Backup.SMS[smsnum] = malloc(sizeof(GSM_SMSMessage)); 5687 Backup.SMS[smsnum] = malloc(sizeof(GSM_SMSMessage));
5537 if (Backup.SMS[smsnum] == NULL) Print_Error(ERR_MOREMEMORY); 5688 if (Backup.SMS[smsnum] == NULL) Print_Error(ERR_MOREMEMORY);
5538 Backup.SMS[smsnum+1] = NULL; 5689 Backup.SMS[smsnum+1] = NULL;
5539 } else { 5690 } else {
5540 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_SMS"); 5691 printmsg(" Increase %s\n" , "GSM_BACKUP_MAX_SMS");
5541 GSM_Terminate(); 5692 GSM_Terminate();
5542 exit(-1); 5693 exit(-1);
5543 } 5694 }
5544 *Backup.SMS[smsnum] = sms.SMS[j]; 5695 *Backup.SMS[smsnum] = sms.SMS[j];
5545 smsnum++; 5696 smsnum++;
5546 break; 5697 break;
5547 } 5698 }
5548 } 5699 }
5549 } 5700 }
5550 } 5701 }
5551 start=false; 5702 start=false;
5552 } 5703 }
5553 5704
5554 error = GSM_SaveSMSBackupFile(argv[2],&Backup); 5705 error = GSM_SaveSMSBackupFile(argv[2],&Backup);
5555 Print_Error(error); 5706 Print_Error(error);
5556 5707
5557 if (DeleteAfter) { 5708 if (DeleteAfter) {
5558 for (j=0;j<smsnum;j++) { 5709 for (j=0;j<smsnum;j++) {
5559 Backup.SMS[j]->Folder = 0; 5710 Backup.SMS[j]->Folder = 0;
5560 error=Phone->DeleteSMS(&s, Backup.SMS[j]); 5711 error=Phone->DeleteSMS(&s, Backup.SMS[j]);
5561 Print_Error(error); 5712 Print_Error(error);
5562 printmsgerr("%cDeleting: %i percent",13,(j+1)*100/smsnum); 5713 printmsgerr("%cDeleting: %i percent",13,(j+1)*100/smsnum);
5563 } 5714 }
5564 } 5715 }
5565 5716
5566 GSM_Terminate(); 5717 GSM_Terminate();
5567} 5718}
5568 5719
5569static void AddSMS(int argc, char *argv[]) 5720static void AddSMS(int argc, char *argv[])
5570{ 5721{
5571 GSM_MultiSMSMessage SMS; 5722 GSM_MultiSMSMessage SMS;
5572 GSM_SMS_Backup Backup; 5723 GSM_SMS_Backup Backup;
5573 int smsnum = 0; 5724 int smsnum = 0;
5574 int folder; 5725 int folder;
5575 5726
5576 folder = atoi(argv[2]); 5727 folder = atoi(argv[2]);
5577 5728
5578 error = GSM_ReadSMSBackupFile(argv[3], &Backup); 5729 error = GSM_ReadSMSBackupFile(argv[3], &Backup);
5579 Print_Error(error); 5730 Print_Error(error);
5580 5731
5581 GSM_Init(true); 5732 GSM_Init(true);
5582 5733
5583 while (Backup.SMS[smsnum] != NULL) { 5734 while (Backup.SMS[smsnum] != NULL) {
5584 Backup.SMS[smsnum]->Folder = folder; 5735 Backup.SMS[smsnum]->Folder = folder;
5585 Backup.SMS[smsnum]->SMSC.Location = 1; 5736 Backup.SMS[smsnum]->SMSC.Location = 1;
5586 SMS.Number = 1; 5737 SMS.Number = 1;
5587 SMS.SMS[0] = *Backup.SMS[smsnum]; 5738 SMS.SMS[0] = *Backup.SMS[smsnum];
5588 displaymultismsinfo(SMS,false,false); 5739 displaymultismsinfo(SMS,false,false);
5589 if (answer_yes("Restore sms")) { 5740 if (answer_yes("Restore sms")) {
5590 error=Phone->AddSMS(&s, Backup.SMS[smsnum]); 5741 error=Phone->AddSMS(&s, Backup.SMS[smsnum]);
5591 Print_Error(error); 5742 Print_Error(error);
5592 } 5743 }
5593 smsnum++; 5744 smsnum++;
5594 } 5745 }
5595 5746
5596 GSM_Terminate(); 5747 GSM_Terminate();
5597} 5748}
5598 5749
5599static void RestoreSMS(int argc, char *argv[]) 5750static void RestoreSMS(int argc, char *argv[])
5600{ 5751{
5601 GSM_MultiSMSMessage SMS; 5752 GSM_MultiSMSMessage SMS;
5602 GSM_SMS_Backup Backup; 5753 GSM_SMS_Backup Backup;
5603 GSM_SMSFolders folders; 5754 GSM_SMSFolders folders;
5604 int smsnum = 0; 5755 int smsnum = 0;
5605 char buffer[200]; 5756 char buffer[200];
5606 5757
5607 error=GSM_ReadSMSBackupFile(argv[2], &Backup); 5758 error=GSM_ReadSMSBackupFile(argv[2], &Backup);
5608 Print_Error(error); 5759 Print_Error(error);
5609 5760
5610 GSM_Init(true); 5761 GSM_Init(true);
5611 5762
5612 error=Phone->GetSMSFolders(&s, &folders); 5763 error=Phone->GetSMSFolders(&s, &folders);
5613 Print_Error(error); 5764 Print_Error(error);
5614 5765
5615 while (Backup.SMS[smsnum] != NULL) { 5766 while (Backup.SMS[smsnum] != NULL) {
5616 SMS.Number = 1; 5767 SMS.Number = 1;
5617 memcpy(&SMS.SMS[0],Backup.SMS[smsnum],sizeof(GSM_SMSMessage)); 5768 memcpy(&SMS.SMS[0],Backup.SMS[smsnum],sizeof(GSM_SMSMessage));
5618 displaymultismsinfo(SMS,false,false); 5769 displaymultismsinfo(SMS,false,false);
5619 sprintf(buffer,"Restore sms to folder \"%s\"",DecodeUnicodeConsole(folders.Folder[Backup.SMS[smsnum]->Folder-1].Name)); 5770 sprintf(buffer,"Restore sms to folder \"%s\"",DecodeUnicodeConsole(folders.Folder[Backup.SMS[smsnum]->Folder-1].Name));
5620 if (answer_yes(buffer)) { 5771 if (answer_yes(buffer)) {
5621 Backup.SMS[smsnum]->Location = 0; 5772 error=Phone->AddSMS(&s, Backup.SMS[smsnum]);
5622 error=Phone->SetSMS(&s, Backup.SMS[smsnum]);
5623 Print_Error(error); 5773 Print_Error(error);
5624 } 5774 }
5625 smsnum++; 5775 smsnum++;
5626 } 5776 }
5627 5777
5628 GSM_Terminate(); 5778 GSM_Terminate();
5629} 5779}
5630#endif 5780#endif
5631 5781
5632static void CopyBitmap(int argc, char *argv[]) 5782static void CopyBitmap(int argc, char *argv[])
5633{ 5783{
5634 GSM_MultiBitmap Bitmap; 5784 GSM_MultiBitmap Bitmap;
5635 int i; 5785 int i;
5636 5786
5637 Bitmap.Bitmap[0].Type = GSM_None; 5787 Bitmap.Bitmap[0].Type = GSM_None;
5638 5788
5639 error=GSM_ReadBitmapFile(argv[2],&Bitmap); 5789 error=GSM_ReadBitmapFile(argv[2],&Bitmap);
5640 Print_Error(error); 5790 Print_Error(error);
5641 5791
5642 if (argc==3) { 5792 if (argc==3) {
5643 for (i=0;i<Bitmap.Number;i++) { 5793 for (i=0;i<Bitmap.Number;i++) {
5644 switch (Bitmap.Bitmap[i].Type) { 5794 switch (Bitmap.Bitmap[i].Type) {
5645 case GSM_StartupLogo : printmsg("Startup logo"); break; 5795 case GSM_StartupLogo : printmsg("Startup logo"); break;
5646 case GSM_OperatorLogo: printmsg("Operator logo"); break; 5796 case GSM_OperatorLogo: printmsg("Operator logo"); break;
5647 case GSM_PictureImage: printmsg("Picture Image"); break; 5797 case GSM_PictureImage: printmsg("Picture Image"); break;
5648 case GSM_CallerGroupLogo : printmsg("Caller group logo"); break; 5798 case GSM_CallerGroupLogo : printmsg("Caller group logo"); break;
5649 default : break; 5799 default : break;
5650 } 5800 }
5651 printmsg(", width %i, height %i\n",Bitmap.Bitmap[i].BitmapWidth,Bitmap.Bitmap[i].BitmapHeight); 5801 printmsg(", width %i, height %i\n",Bitmap.Bitmap[i].BitmapWidth,Bitmap.Bitmap[i].BitmapHeight);
5652 GSM_PrintBitmap(stdout,&Bitmap.Bitmap[i]); 5802 GSM_PrintBitmap(stdout,&Bitmap.Bitmap[i]);
5653 } 5803 }
5654 } else { 5804 } else {
5655 if (argc == 5) { 5805 if (argc == 5) {
5656 for (i=0;i<Bitmap.Number;i++) { 5806 for (i=0;i<Bitmap.Number;i++) {
5657 if (mystrncasecmp(argv[4],"PICTURE",0)) { 5807 if (mystrncasecmp(argv[4],"PICTURE",0)) {
5658 Bitmap.Bitmap[i].Type = GSM_PictureImage; 5808 Bitmap.Bitmap[i].Type = GSM_PictureImage;
5659 } else if (mystrncasecmp(argv[4],"STARTUP",0)) { 5809 } else if (mystrncasecmp(argv[4],"STARTUP",0)) {
5660 Bitmap.Bitmap[i].Type = GSM_StartupLogo; 5810 Bitmap.Bitmap[i].Type = GSM_StartupLogo;
5661 } else if (mystrncasecmp(argv[4],"CALLER",0)) { 5811 } else if (mystrncasecmp(argv[4],"CALLER",0)) {
5662 Bitmap.Bitmap[i].Type = GSM_CallerGroupLogo; 5812 Bitmap.Bitmap[i].Type = GSM_CallerGroupLogo;
5663 } else if (mystrncasecmp(argv[4],"OPERATOR",0)) { 5813 } else if (mystrncasecmp(argv[4],"OPERATOR",0)) {
5664 Bitmap.Bitmap[i].Type = GSM_OperatorLogo; 5814 Bitmap.Bitmap[i].Type = GSM_OperatorLogo;
5665 } else { 5815 } else {
5666 printmsg("What format of output file logo (\"%s\") ?\n",argv[4]); 5816 printmsg("What format of output file logo (\"%s\") ?\n",argv[4]);
5667 exit(-1); 5817 exit(-1);
5668 } 5818 }
5669 } 5819 }
5670 } 5820 }
5671 error=GSM_SaveBitmapFile(argv[3],&Bitmap); 5821 error=GSM_SaveBitmapFile(argv[3],&Bitmap);
5672 Print_Error(error); 5822 Print_Error(error);
5673 } 5823 }
5674} 5824}
5675 5825
5676static void NokiaComposer(int argc, char *argv[]) 5826static void NokiaComposer(int argc, char *argv[])
5677{ 5827{
5678 GSM_Ringtone ringtone; 5828 GSM_Ringtone ringtone;
5679 bool started; 5829 bool started;
5680 int i,j; 5830 int i,j;
5681 GSM_RingNote *Note; 5831 GSM_RingNote *Note;
5682 GSM_RingNoteDuration Duration; 5832 GSM_RingNoteDuration Duration;
5683 GSM_RingNoteDuration DefNoteDuration = 32; /* 32 = Duration_1_4 */ 5833 GSM_RingNoteDuration DefNoteDuration = 32; /* 32 = Duration_1_4 */
5684 unsigned int DefNoteScale = Scale_880; 5834 unsigned int DefNoteScale = Scale_880;
5685 5835
5686 ringtone.Format= 0; 5836 ringtone.Format= 0;
5687 error=GSM_ReadRingtoneFile(argv[2],&ringtone); 5837 error=GSM_ReadRingtoneFile(argv[2],&ringtone);
5688 5838
5689 if (ringtone.Format != RING_NOTETONE) { 5839 if (ringtone.Format != RING_NOTETONE) {
5690 printmsg("It can be RTTL ringtone only used with this option\n"); 5840 printmsg("It can be RTTL ringtone only used with this option\n");
5691 exit(-1); 5841 exit(-1);
5692 } 5842 }
5693 5843
5694 started = false; 5844 started = false;
5695 j= 0; 5845 j= 0;
5696 for (i=0;i<ringtone.NoteTone.NrCommands;i++) { 5846 for (i=0;i<ringtone.NoteTone.NrCommands;i++) {
5697 if (ringtone.NoteTone.Commands[i].Type == RING_Note) { 5847 if (ringtone.NoteTone.Commands[i].Type == RING_Note) {
5698 Note = &ringtone.NoteTone.Commands[i].Note; 5848 Note = &ringtone.NoteTone.Commands[i].Note;
5699 if (!started) { 5849 if (!started) {
5700 if (Note->Note != Note_Pause) { 5850 if (Note->Note != Note_Pause) {
5701 printmsg("Ringtone \"%s\" (tempo = %i Beats Per Minute)\n\n",DecodeUnicodeConsole(ringtone.Name),GSM_RTTLGetTempo(Note->Tempo)); 5851 printmsg("Ringtone \"%s\" (tempo = %i Beats Per Minute)\n\n",DecodeUnicodeConsole(ringtone.Name),GSM_RTTLGetTempo(Note->Tempo));
5702 started = true; 5852 started = true;
5703 } 5853 }
5704 } 5854 }
5705 if (started) j++; 5855 if (started) j++;
5706 } 5856 }
5707 } 5857 }
5708 if (j>50) printmsg("WARNING: LENGTH=%i NOTES, BUT YOU WILL ENTER ONLY FIRST 50 TONES.",j); 5858 if (j>50) printmsg("WARNING: LENGTH=%i NOTES, BUT YOU WILL ENTER ONLY FIRST 50 TONES.",j);
5709 5859
5710 printmsg("\n\nThis ringtone in Nokia Composer in phone should look: "); 5860 printmsg("\n\nThis ringtone in Nokia Composer in phone should look: ");
5711 started = false; 5861 started = false;
5712 for (i=0;i<ringtone.NoteTone.NrCommands;i++) { 5862 for (i=0;i<ringtone.NoteTone.NrCommands;i++) {
5713 if (ringtone.NoteTone.Commands[i].Type == RING_Note) { 5863 if (ringtone.NoteTone.Commands[i].Type == RING_Note) {
5714 Note = &ringtone.NoteTone.Commands[i].Note; 5864 Note = &ringtone.NoteTone.Commands[i].Note;
5715 if (!started) { 5865 if (!started) {
5716 if (Note->Note != Note_Pause) started = true; 5866 if (Note->Note != Note_Pause) started = true;
5717 } 5867 }
5718 if (started) { 5868 if (started) {
5719 switch (Note->Duration) { 5869 switch (Note->Duration) {
5720 case Duration_Full: printmsg("1"); break; 5870 case Duration_Full: printmsg("1"); break;
5721 case Duration_1_2 : printmsg("2"); break; 5871 case Duration_1_2 : printmsg("2"); break;
5722 case Duration_1_4 : printmsg("4"); break; 5872 case Duration_1_4 : printmsg("4"); break;
5723 case Duration_1_8 : printmsg("8"); break; 5873 case Duration_1_8 : printmsg("8"); break;
5724 case Duration_1_16: printmsg("16");break; 5874 case Duration_1_16: printmsg("16");break;
5725 case Duration_1_32: printmsg("32");break; 5875 case Duration_1_32: printmsg("32");break;
5726 } 5876 }
5727 if (Note->DurationSpec == DottedNote) printmsg("."); 5877 if (Note->DurationSpec == DottedNote) printmsg(".");
5728 switch (Note->Note) { 5878 switch (Note->Note) {
5729 case Note_C : printmsg("c");break; 5879 case Note_C : printmsg("c");break;
5730 case Note_Cis : printmsg("#c");break; 5880 case Note_Cis : printmsg("#c");break;
5731 case Note_D :printmsg("d");break; 5881 case Note_D :printmsg("d");break;
5732 case Note_Dis : printmsg("#d");break; 5882 case Note_Dis : printmsg("#d");break;
5733 case Note_E : printmsg("e");break; 5883 case Note_E : printmsg("e");break;
5734 case Note_F : printmsg("f");break; 5884 case Note_F : printmsg("f");break;
5735 case Note_Fis : printmsg("#f");break; 5885 case Note_Fis : printmsg("#f");break;
5736 case Note_G : printmsg("g");break; 5886 case Note_G : printmsg("g");break;
5737 case Note_Gis : printmsg("#g");break; 5887 case Note_Gis : printmsg("#g");break;
5738 case Note_A : printmsg("a");break; 5888 case Note_A : printmsg("a");break;
5739 case Note_Ais : printmsg("#a");break; 5889 case Note_Ais : printmsg("#a");break;
5740 case Note_H : printmsg("h");break; 5890 case Note_H : printmsg("h");break;
5741 case Note_Pause : printmsg("-");break; 5891 case Note_Pause : printmsg("-");break;
5742 } 5892 }
5743 if (Note->Note != Note_Pause) printmsg("%i",Note->Scale - 4); 5893 if (Note->Note != Note_Pause) printmsg("%i",Note->Scale - 4);
5744 printmsg(" "); 5894 printmsg(" ");
5745 } 5895 }
5746 } 5896 }
5747 } 5897 }
5748 5898
5749 printmsg("\n\nTo enter it please press: "); 5899 printmsg("\n\nTo enter it please press: ");
5750 started = false; 5900 started = false;
5751 for (i=0;i<ringtone.NoteTone.NrCommands;i++) { 5901 for (i=0;i<ringtone.NoteTone.NrCommands;i++) {
5752 if (ringtone.NoteTone.Commands[i].Type == RING_Note) { 5902 if (ringtone.NoteTone.Commands[i].Type == RING_Note) {
5753 Note = &ringtone.NoteTone.Commands[i].Note; 5903 Note = &ringtone.NoteTone.Commands[i].Note;
5754 if (!started) { 5904 if (!started) {
5755 if (Note->Note != Note_Pause) started = true; 5905 if (Note->Note != Note_Pause) started = true;
5756 } 5906 }
5757 if (started) { 5907 if (started) {
5758 switch (Note->Note) { 5908 switch (Note->Note) {
5759 case Note_C : case Note_Cis:printmsg("1");break; 5909 case Note_C : case Note_Cis:printmsg("1");break;
5760 case Note_D : case Note_Dis:printmsg("2");break; 5910 case Note_D : case Note_Dis:printmsg("2");break;
5761 case Note_E : printmsg("3");break; 5911 case Note_E : printmsg("3");break;
5762 case Note_F : case Note_Fis:printmsg("4");break; 5912 case Note_F : case Note_Fis:printmsg("4");break;
5763 case Note_G : case Note_Gis:printmsg("5");break; 5913 case Note_G : case Note_Gis:printmsg("5");break;
5764 case Note_A : case Note_Ais:printmsg("6");break; 5914 case Note_A : case Note_Ais:printmsg("6");break;
5765 case Note_H : printmsg("7");break; 5915 case Note_H : printmsg("7");break;
5766 default : printmsg("0");break; 5916 default : printmsg("0");break;
5767 } 5917 }
5768 if (Note->DurationSpec == DottedNote) printmsg("(longer)"); 5918 if (Note->DurationSpec == DottedNote) printmsg("(longer)");
5769 switch (Note->Note) { 5919 switch (Note->Note) {
5770 case Note_Cis: case Note_Dis: 5920 case Note_Cis: case Note_Dis:
5771 case Note_Fis: case Note_Gis: 5921 case Note_Fis: case Note_Gis:
5772 case Note_Ais: 5922 case Note_Ais:
5773 printmsg("#"); 5923 printmsg("#");
5774 break; 5924 break;
5775 default : 5925 default :
5776 break; 5926 break;
5777 } 5927 }
5778 if (Note->Note != Note_Pause) { 5928 if (Note->Note != Note_Pause) {
5779 if ((unsigned int)Note->Scale != DefNoteScale) { 5929 if ((unsigned int)Note->Scale != DefNoteScale) {
5780 while (DefNoteScale != (unsigned int)Note->Scale) { 5930 while (DefNoteScale != (unsigned int)Note->Scale) {
5781 printmsg("*"); 5931 printmsg("*");
5782 DefNoteScale++; 5932 DefNoteScale++;
5783 if (DefNoteScale==Scale_7040) DefNoteScale = Scale_880; 5933 if (DefNoteScale==Scale_7040) DefNoteScale = Scale_880;
5784 } 5934 }
5785 } 5935 }
5786 } 5936 }
5787 Duration = 0; 5937 Duration = 0;
5788 switch (Note->Duration) { 5938 switch (Note->Duration) {
5789 case Duration_Full : Duration = 128;break; 5939 case Duration_Full : Duration = 128;break;
5790 case Duration_1_2 : Duration = 64;break; 5940 case Duration_1_2 : Duration = 64;break;
5791 case Duration_1_4 : Duration = 32;break; 5941 case Duration_1_4 : Duration = 32;break;
5792 case Duration_1_8 : Duration = 16;break; 5942 case Duration_1_8 : Duration = 16;break;
5793 case Duration_1_16 : Duration = 8;break; 5943 case Duration_1_16 : Duration = 8;break;
5794 case Duration_1_32 : Duration = 4;break; 5944 case Duration_1_32 : Duration = 4;break;
5795 default : dbgprintf("error\n");break; 5945 default : dbgprintf("error\n");break;
5796 } 5946 }
5797 if (Duration > DefNoteDuration) { 5947 if (Duration > DefNoteDuration) {
5798 while (DefNoteDuration != Duration) { 5948 while (DefNoteDuration != Duration) {
5799 printmsg("9"); 5949 printmsg("9");
5800 DefNoteDuration = DefNoteDuration * 2; 5950 DefNoteDuration = DefNoteDuration * 2;
5801 } 5951 }
5802 } 5952 }
5803 if (Duration < DefNoteDuration) { 5953 if (Duration < DefNoteDuration) {
5804 while (DefNoteDuration != Duration) { 5954 while (DefNoteDuration != Duration) {
5805 printmsg("8"); 5955 printmsg("8");
5806 DefNoteDuration = DefNoteDuration / 2; 5956 DefNoteDuration = DefNoteDuration / 2;
5807 } 5957 }
5808 } 5958 }
5809 printmsg(" "); 5959 printmsg(" ");
5810 } 5960 }
5811 } 5961 }
5812 } 5962 }
5813 5963
5814 printf("\n"); 5964 printf("\n");
5815} 5965}
5816//#if 0 5966
5817static void CopyRingtone(int argc, char *argv[]) 5967static void CopyRingtone(int argc, char *argv[])
5818{ 5968{
5819 GSM_Ringtone ringtone, ringtone2; 5969 GSM_Ringtone ringtone, ringtone2;
5820 GSM_RingtoneFormatFormat; 5970 GSM_RingtoneFormatFormat;
5821 5971
5822 ringtone.Format= 0; 5972 ringtone.Format= 0;
5823 error=GSM_ReadRingtoneFile(argv[2],&ringtone); 5973 error=GSM_ReadRingtoneFile(argv[2],&ringtone);
5824 Print_Error(error); 5974 Print_Error(error);
5825 5975
5826 Format = ringtone.Format; 5976 Format = ringtone.Format;
5827 if (argc == 5) { 5977 if (argc == 5) {
5828 if (mystrncasecmp(argv[4],"RTTL",0)) { Format = RING_NOTETONE; 5978 if (mystrncasecmp(argv[4],"RTTL",0)) { Format = RING_NOTETONE;
5829 } else if (mystrncasecmp(argv[4],"BINARY",0)) {Format = RING_NOKIABINARY; 5979 } else if (mystrncasecmp(argv[4],"BINARY",0)) {Format = RING_NOKIABINARY;
5830 } else { 5980 } else {
5831 printmsg("What format of output ringtone file (\"%s\") ?\n",argv[4]); 5981 printmsg("What format of output ringtone file (\"%s\") ?\n",argv[4]);
5832 exit(-1); 5982 exit(-1);
5833 } 5983 }
5834 } 5984 }
5835 5985
5836 error=GSM_RingtoneConvert(&ringtone2,&ringtone,Format); 5986 error=GSM_RingtoneConvert(&ringtone2,&ringtone,Format);
5837 Print_Error(error); 5987 Print_Error(error);
5838 5988
5839 error=GSM_SaveRingtoneFile(argv[3],&ringtone2); 5989 error=GSM_SaveRingtoneFile(argv[3],&ringtone2);
5840 Print_Error(error); 5990 Print_Error(error);
5841} 5991}
5842 5992
5843static void PressKeySequence(int argc, char *argv[]) 5993static void PressKeySequence(int argc, char *argv[])
5844{ 5994{
5845 int i,Length; 5995 int i,Length;
5846 GSM_KeyCodeKeyCode[500]; 5996 GSM_KeyCodeKeyCode[500];
5847 5997
5848 error = MakeKeySequence(argv[2], KeyCode, &Length); 5998 error = MakeKeySequence(argv[2], KeyCode, &Length);
5849 if (error == ERR_NOTSUPPORTED) { 5999 if (error == ERR_NOTSUPPORTED) {
5850 printmsg("Unknown key/function name: \"%c\"\n",argv[2][Length]); 6000 printmsg("Unknown key/function name: \"%c\"\n",argv[2][Length]);
5851 exit(-1); 6001 exit(-1);
5852 } 6002 }
5853 6003
5854 GSM_Init(true); 6004 GSM_Init(true);
5855 6005
5856 for (i=0;i<Length;i++) { 6006 for (i=0;i<Length;i++) {
5857 error=Phone->PressKey(&s, KeyCode[i], true); 6007 error=Phone->PressKey(&s, KeyCode[i], true);
5858 Print_Error(error); 6008 Print_Error(error);
5859 error=Phone->PressKey(&s, KeyCode[i], false); 6009 error=Phone->PressKey(&s, KeyCode[i], false);
5860 Print_Error(error); 6010 Print_Error(error);
5861 } 6011 }
5862 6012
5863 GSM_Terminate(); 6013 GSM_Terminate();
5864} 6014}
5865 6015
5866static void GetAllCategories(int argc, char *argv[]) 6016static void GetAllCategories(int argc, char *argv[])
5867{ 6017{
5868 GSM_Category Category; 6018 GSM_Category Category;
5869 GSM_CategoryStatusStatus; 6019 GSM_CategoryStatusStatus;
5870 int j, count; 6020 int j, count;
5871 6021
5872 if (mystrncasecmp(argv[2],"TODO",0)) { 6022 if (mystrncasecmp(argv[2],"TODO",0)) {
5873 Category.Type = Category_ToDo; 6023 Category.Type = Category_ToDo;
5874 Status.Type = Category_ToDo; 6024 Status.Type = Category_ToDo;
5875 } else if (mystrncasecmp(argv[2],"PHONEBOOK",0)) { 6025 } else if (mystrncasecmp(argv[2],"PHONEBOOK",0)) {
5876 Category.Type = Category_Phonebook; 6026 Category.Type = Category_Phonebook;
5877 Status.Type = Category_Phonebook; 6027 Status.Type = Category_Phonebook;
5878 } else { 6028 } else {
5879 printmsg("What type of categories do you want to get (\"%s\") ?\n",argv[2]); 6029 printmsg("What type of categories do you want to get (\"%s\") ?\n",argv[2]);
5880 exit(-1); 6030 exit(-1);
5881 } 6031 }
5882 6032
5883 GSM_Init(true); 6033 GSM_Init(true);
5884 6034
5885 error=Phone->GetCategoryStatus(&s, &Status); 6035 error=Phone->GetCategoryStatus(&s, &Status);
5886 Print_Error(error); 6036 Print_Error(error);
5887 6037
5888 for (count=0,j=1;count<Status.Used;j++) 6038 for (count=0,j=1;count<Status.Used;j++)
5889 { 6039 {
5890 Category.Location=j; 6040 Category.Location=j;
5891 error=Phone->GetCategory(&s, &Category); 6041 error=Phone->GetCategory(&s, &Category);
5892 6042
5893 if (error != ERR_EMPTY) { 6043 if (error != ERR_EMPTY) {
5894 printmsg("Location: %i\n",j); 6044 printmsg("Location: %i\n",j);
5895 6045
5896 Print_Error(error); 6046 Print_Error(error);
5897 6047
5898 printmsg("Name : \"%s\"\n\n",DecodeUnicodeConsole(Category.Name)); 6048 printmsg("Name : \"%s\"\n\n",DecodeUnicodeConsole(Category.Name));
5899 count++; 6049 count++;
5900 } 6050 }
5901 } 6051 }
5902 6052
5903 GSM_Terminate(); 6053 GSM_Terminate();
5904} 6054}
5905 6055
5906static void GetCategory(int argc, char *argv[]) 6056static void GetCategory(int argc, char *argv[])
5907{ 6057{
5908 GSM_CategoryCategory; 6058 GSM_CategoryCategory;
5909 int start,stop,j; 6059 int start,stop,j;
5910 6060
5911 if (mystrncasecmp(argv[2],"TODO",0)) { 6061 if (mystrncasecmp(argv[2],"TODO",0)) {
5912 Category.Type = Category_ToDo; 6062 Category.Type = Category_ToDo;
5913 } else if (mystrncasecmp(argv[2],"PHONEBOOK",0)) { 6063 } else if (mystrncasecmp(argv[2],"PHONEBOOK",0)) {
5914 Category.Type = Category_Phonebook; 6064 Category.Type = Category_Phonebook;
5915 } else { 6065 } else {
5916 printmsg("What type of categories do you want to get (\"%s\") ?\n",argv[2]); 6066 printmsg("What type of categories do you want to get (\"%s\") ?\n",argv[2]);
5917 exit(-1); 6067 exit(-1);
5918 } 6068 }
5919 6069
5920 GetStartStop(&start, &stop, 2, argc - 1, argv + 1); 6070 GetStartStop(&start, &stop, 2, argc - 1, argv + 1);
5921 6071
5922 GSM_Init(true); 6072 GSM_Init(true);
5923 6073
5924 for (j=start;j<=stop;j++) 6074 for (j=start;j<=stop;j++)
5925 { 6075 {
5926 printmsg("Location: %i\n",j); 6076 printmsg("Location: %i\n",j);
5927 6077
5928 Category.Location=j; 6078 Category.Location=j;
5929 6079
5930 error=Phone->GetCategory(&s, &Category); 6080 error=Phone->GetCategory(&s, &Category);
5931 if (error != ERR_EMPTY) Print_Error(error); 6081 if (error != ERR_EMPTY) Print_Error(error);
5932 6082
5933 if (error == ERR_EMPTY) { 6083 if (error == ERR_EMPTY) {
5934 printmsg("Entry is empty\n\n"); 6084 printmsg("Entry is empty\n\n");
5935 } else { 6085 } else {
5936 printmsg("Name : \"%s\"\n\n",DecodeUnicodeConsole(Category.Name)); 6086 printmsg("Name : \"%s\"\n\n",DecodeUnicodeConsole(Category.Name));
5937 } 6087 }
5938 } 6088 }
5939 6089
5940 GSM_Terminate(); 6090 GSM_Terminate();
5941} 6091}
5942 6092
5943static void DeleteToDo(int argc, char *argv[]) 6093static void DeleteToDo(int argc, char *argv[])
5944{ 6094{
5945 GSM_ToDoEntryToDo; 6095 GSM_ToDoEntryToDo;
5946 int i; 6096 int i;
5947 int start,stop; 6097 int start,stop;
5948 6098
5949 GetStartStop(&start, &stop, 2, argc, argv); 6099 GetStartStop(&start, &stop, 2, argc, argv);
5950 6100
5951 GSM_Init(true); 6101 GSM_Init(true);
5952 6102
5953 for (i=start;i<=stop;i++) { 6103 for (i=start;i<=stop;i++) {
5954 ToDo.Location=i; 6104 ToDo.Location=i;
5955 printmsg("Location : %i\n",i); 6105 printmsg("Location : %i\n",i);
5956 error=Phone->DeleteToDo(&s,&ToDo); 6106 error=Phone->DeleteToDo(&s,&ToDo);
5957 if (error != ERR_EMPTY) Print_Error(error); 6107 if (error != ERR_EMPTY) Print_Error(error);
5958 6108
5959 if (error == ERR_EMPTY) { 6109 if (error == ERR_EMPTY) {
5960 printmsg("Entry was empty\n"); 6110 printmsg("Entry was empty\n");
5961 } else { 6111 } else {
5962 printmsg("Entry was deleted\n"); 6112 printmsg("Entry was deleted\n");
5963 } 6113 }
5964 printf("\n"); 6114 printf("\n");
5965 } 6115 }
5966 6116
5967 GSM_Terminate(); 6117 GSM_Terminate();
5968} 6118}
5969 6119
5970static void PrintToDo(GSM_ToDoEntry *ToDo) 6120static void PrintToDo(GSM_ToDoEntry *ToDo)
5971{ 6121{
5972 int j; 6122 int j;
5973 GSM_MemoryEntry entry; 6123 GSM_MemoryEntry entry;
5974 unsigned char *name; 6124 unsigned char *name;
5975 GSM_Category Category; 6125 GSM_Category Category;
5976 6126
5977 printmsg("Location : %i\n",ToDo->Location); 6127 printmsg("Location : %i\n",ToDo->Location);
5978 printmsg("Priority : "); 6128 printmsg("Priority : ");
5979 switch (ToDo->Priority) { 6129 switch (ToDo->Priority) {
5980 case GSM_Priority_Low : printmsg("Low\n"); break; 6130 case GSM_Priority_Low : printmsg("Low\n"); break;
5981 case GSM_Priority_Medium : printmsg("Medium\n"); break; 6131 case GSM_Priority_Medium : printmsg("Medium\n"); break;
5982 case GSM_Priority_High : printmsg("High\n"); break; 6132 case GSM_Priority_High : printmsg("High\n"); break;
5983 default : printmsg("Unknown\n");break; 6133 default : printmsg("Unknown\n");break;
5984 } 6134 }
5985 for (j=0;j<ToDo->EntriesNum;j++) { 6135 for (j=0;j<ToDo->EntriesNum;j++) {
5986 switch (ToDo->Entries[j].EntryType) { 6136 switch (ToDo->Entries[j].EntryType) {
5987 case TODO_END_DATETIME: 6137 case TODO_END_DATETIME:
5988 printmsg("DueTime : %s\n",OSDateTime(ToDo->Entries[j].Date,false)); 6138 printmsg("DueTime : %s\n",OSDateTime(ToDo->Entries[j].Date,false));
5989 break; 6139 break;
5990 case TODO_COMPLETED: 6140 case TODO_COMPLETED:
5991 printmsg("Completed : %s\n",ToDo->Entries[j].Number == 1 ? "Yes" : "No"); 6141 printmsg("Completed : %s\n",ToDo->Entries[j].Number == 1 ? "Yes" : "No");
5992 break; 6142 break;
5993 case TODO_ALARM_DATETIME: 6143 case TODO_ALARM_DATETIME:
5994 printmsg("Alarm : %s\n",OSDateTime(ToDo->Entries[j].Date,false)); 6144 printmsg("Alarm : %s\n",OSDateTime(ToDo->Entries[j].Date,false));
5995 break; 6145 break;
5996 case TODO_SILENT_ALARM_DATETIME: 6146 case TODO_SILENT_ALARM_DATETIME:
5997 printmsg("Silent alarm : %s\n",OSDateTime(ToDo->Entries[j].Date,false)); 6147 printmsg("Silent alarm : %s\n",OSDateTime(ToDo->Entries[j].Date,false));
5998 break; 6148 break;
5999 case TODO_TEXT: 6149 case TODO_TEXT:
6000 printmsg("Text : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text)); 6150 printmsg("Text : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text));
6001 break; 6151 break;
6002 case TODO_PRIVATE: 6152 case TODO_PRIVATE:
6003 printmsg("Private : %s\n",ToDo->Entries[j].Number == 1 ? "Yes" : "No"); 6153 printmsg("Private : %s\n",ToDo->Entries[j].Number == 1 ? "Yes" : "No");
6004 break; 6154 break;
6005 case TODO_CATEGORY: 6155 case TODO_CATEGORY:
6006 Category.Location = ToDo->Entries[j].Number; 6156 Category.Location = ToDo->Entries[j].Number;
6007 Category.Type = Category_ToDo; 6157 Category.Type = Category_ToDo;
6008 error=Phone->GetCategory(&s, &Category); 6158 error=Phone->GetCategory(&s, &Category);
6009 if (error == ERR_NONE) { 6159 if (error == ERR_NONE) {
6010 printmsg("Category : \"%s\" (%i)\n", DecodeUnicodeConsole(Category.Name), ToDo->Entries[j].Number); 6160 printmsg("Category : \"%s\" (%i)\n", DecodeUnicodeConsole(Category.Name), ToDo->Entries[j].Number);
6011 } else { 6161 } else {
6012 printmsg("Category : %i\n", ToDo->Entries[j].Number); 6162 printmsg("Category : %i\n", ToDo->Entries[j].Number);
6013 } 6163 }
6014 break; 6164 break;
6015 case TODO_CONTACTID: 6165 case TODO_CONTACTID:
6016 entry.Location = ToDo->Entries[j].Number; 6166 entry.Location = ToDo->Entries[j].Number;
6017 entry.MemoryType = MEM_ME; 6167 entry.MemoryType = MEM_ME;
6018 error=Phone->GetMemory(&s, &entry); 6168 error=Phone->GetMemory(&s, &entry);
6019 if (error == ERR_NONE) { 6169 if (error == ERR_NONE) {
6020 name = GSM_PhonebookGetEntryName(&entry); 6170 name = GSM_PhonebookGetEntryName(&entry);
6021 if (name != NULL) { 6171 if (name != NULL) {
6022 printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number); 6172 printmsg("Contact ID : \"%s\" (%d)\n", DecodeUnicodeConsole(name), ToDo->Entries[j].Number);
6023 } else { 6173 } else {
6024 printmsg("Contact ID : %d\n",ToDo->Entries[j].Number); 6174 printmsg("Contact ID : %d\n",ToDo->Entries[j].Number);
6025 } 6175 }
6026 } else { 6176 } else {
6027 printmsg("Contact : %d\n",ToDo->Entries[j].Number); 6177 printmsg("Contact : %d\n",ToDo->Entries[j].Number);
6028 } 6178 }
6029 break; 6179 break;
6030 case TODO_PHONE: 6180 case TODO_PHONE:
6031 printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text)); 6181 printmsg("Phone : \"%s\"\n",DecodeUnicodeConsole(ToDo->Entries[j].Text));
6032 break; 6182 break;
6033 } 6183 }
6034 } 6184 }
6035 printf("\n"); 6185 printf("\n");
6036} 6186}
6037 6187
6038static void ListToDoCategoryEntries(int Category) 6188static void ListToDoCategoryEntries(int Category)
6039{ 6189{
6040 GSM_ToDoEntry Entry; 6190 GSM_ToDoEntry Entry;
6041 bool start = true; 6191 bool start = true;
6042 int j; 6192 int j;
6043 6193
6044 while (!gshutdown) { 6194 while (!gshutdown) {
6045 error = Phone->GetNextToDo(&s, &Entry, start); 6195 error = Phone->GetNextToDo(&s, &Entry, start);
6046 if (error == ERR_EMPTY) break; 6196 if (error == ERR_EMPTY) break;
6047 Print_Error(error); 6197 Print_Error(error);
6048 for (j=0;j<Entry.EntriesNum;j++) { 6198 for (j=0;j<Entry.EntriesNum;j++) {
6049 if (Entry.Entries[j].EntryType == TODO_CATEGORY && Entry.Entries[j].Number == (unsigned int)Category) 6199 if (Entry.Entries[j].EntryType == TODO_CATEGORY && Entry.Entries[j].Number == (unsigned int)Category)
6050 PrintToDo(&Entry); 6200 PrintToDo(&Entry);
6051 } 6201 }
6052 start = false; 6202 start = false;
6053 } 6203 }
6054} 6204}
6055 6205
6056static void ListToDoCategory(int argc, char *argv[]) 6206static void ListToDoCategory(int argc, char *argv[])
6057{ 6207{
6058 GSM_Category Category; 6208 GSM_Category Category;
6059 GSM_CategoryStatusStatus; 6209 GSM_CategoryStatusStatus;
6060 int j, count; 6210 int j, count;
6061 6211
6062 unsigned char Text[(GSM_MAX_CATEGORY_NAME_LENGTH+1)*2]; 6212 unsigned char Text[(GSM_MAX_CATEGORY_NAME_LENGTH+1)*2];
6063 int Length; 6213 int Length;
6064 bool Number = true;; 6214 bool Number = true;;
6065 6215
6066 GSM_Init(true); 6216 GSM_Init(true);
6067 6217
6068 signal(SIGINT, interrupt); 6218 signal(SIGINT, interrupt);
6069 printmsgerr("Press Ctrl+C to break...\n"); 6219 printmsgerr("Press Ctrl+C to break...\n");
6070 6220
6071 Length = strlen(argv[2]); 6221 Length = strlen(argv[2]);
6072 for (j = 0; j < Length; j++) { 6222 for (j = 0; j < Length; j++) {
6073 if (!isdigit(argv[2][j])) { 6223 if (!isdigit(argv[2][j])) {
6074 Number = false; 6224 Number = false;
6075 break; 6225 break;
6076 } 6226 }
6077 } 6227 }
6078 6228
6079 if (Number) { 6229 if (Number) {
6080 j = atoi(argv[2]); 6230 j = atoi(argv[2]);
6081 if (j > 0) { 6231 if (j > 0) {
6082 ListToDoCategoryEntries(j); 6232 ListToDoCategoryEntries(j);
6083 } 6233 }
6084 } else { 6234 } else {
6085 if (Length > GSM_MAX_CATEGORY_NAME_LENGTH) { 6235 if (Length > GSM_MAX_CATEGORY_NAME_LENGTH) {
6086 printmsg("Search text too long, truncating to %d chars!\n", GSM_MAX_CATEGORY_NAME_LENGTH); 6236 printmsg("Search text too long, truncating to %d chars!\n", GSM_MAX_CATEGORY_NAME_LENGTH);
6087 Length = GSM_MAX_CATEGORY_NAME_LENGTH; 6237 Length = GSM_MAX_CATEGORY_NAME_LENGTH;
6088 } 6238 }
6089 EncodeUnicode(Text, argv[2], Length); 6239 EncodeUnicode(Text, argv[2], Length);
6090 6240
6091 Category.Type = Category_ToDo; 6241 Category.Type = Category_ToDo;
6092 Status.Type = Category_ToDo; 6242 Status.Type = Category_ToDo;
6093 6243
6094 if (Phone->GetCategoryStatus(&s, &Status) == ERR_NONE) { 6244 if (Phone->GetCategoryStatus(&s, &Status) == ERR_NONE) {
6095 for (count=0,j=1;count<Status.Used;j++) { 6245 for (count=0,j=1;count<Status.Used;j++) {
6096 Category.Location=j; 6246 Category.Location=j;
6097 error=Phone->GetCategory(&s, &Category); 6247 error=Phone->GetCategory(&s, &Category);
6098 6248
6099 if (error != ERR_EMPTY) { 6249 if (error != ERR_EMPTY) {
6100 count++; 6250 count++;
6101 if (mystrstr(Category.Name, Text) != NULL) { 6251 if (mywstrstr(Category.Name, Text) != NULL) {
6102 ListToDoCategoryEntries(j); 6252 ListToDoCategoryEntries(j);
6103 } 6253 }
6104 } 6254 }
6105 } 6255 }
6106 } 6256 }
6107 } 6257 }
6108 GSM_Terminate(); 6258 GSM_Terminate();
6109} 6259}
6110 6260
6111 6261
6112static void GetToDo(int argc, char *argv[]) 6262static void GetToDo(int argc, char *argv[])
6113{ 6263{
6114 GSM_ToDoEntryToDo; 6264 GSM_ToDoEntryToDo;
6115 int i; 6265 int i;
6116 int start,stop; 6266 int start,stop;
6117 6267
6118 GetStartStop(&start, &stop, 2, argc, argv); 6268 GetStartStop(&start, &stop, 2, argc, argv);
6119 6269
6120 GSM_Init(true); 6270 GSM_Init(true);
6121 6271
6122 for (i=start;i<=stop;i++) { 6272 for (i=start;i<=stop;i++) {
6123 ToDo.Location=i; 6273 ToDo.Location=i;
6124 error = Phone->GetToDo(&s,&ToDo); 6274 error = Phone->GetToDo(&s,&ToDo);
6125 if (error == ERR_EMPTY) continue; 6275 if (error == ERR_EMPTY) continue;
6126 Print_Error(error); 6276 Print_Error(error);
6127 PrintToDo(&ToDo); 6277 PrintToDo(&ToDo);
6128 } 6278 }
6129 6279
6130 GSM_Terminate(); 6280 GSM_Terminate();
6131} 6281}
6132 6282
6133static void GetAllToDo(int argc, char *argv[]) 6283static void GetAllToDo(int argc, char *argv[])
6134{ 6284{
6135 GSM_ToDoEntry ToDo; 6285 GSM_ToDoEntry ToDo;
6136 bool start = true; 6286 bool start = true;
6137 6287
6138 signal(SIGINT, interrupt); 6288 signal(SIGINT, interrupt);
6139 printmsgerr("Press Ctrl+C to break...\n"); 6289 printmsgerr("Press Ctrl+C to break...\n");
6140 6290
6141 GSM_Init(true); 6291 GSM_Init(true);
6142 6292
6143 while (!gshutdown) { 6293 while (!gshutdown) {
6144 error = Phone->GetNextToDo(&s, &ToDo, start); 6294 error = Phone->GetNextToDo(&s, &ToDo, start);
6145 if (error == ERR_EMPTY) break; 6295 if (error == ERR_EMPTY) break;
6146 Print_Error(error); 6296 Print_Error(error);
6147 PrintToDo(&ToDo); 6297 PrintToDo(&ToDo);
6148 start = false; 6298 start = false;
6149 } 6299 }
6150 6300
6151 GSM_Terminate(); 6301 GSM_Terminate();
6152} 6302}
6153 6303
6154static void GetNote(int argc, char *argv[]) 6304static void GetAllNotes(int argc, char *argv[])
6155{ 6305{
6156 GSM_NoteEntry Note; 6306 GSM_NoteEntry Note;
6157 int start,stop; 6307 bool start = true;
6158 bool refresh=true;
6159 6308
6160 GetStartStop(&start, &stop, 2, argc, argv); 6309 signal(SIGINT, interrupt);
6310 printmsgerr("Press Ctrl+C to break...\n");
6161 6311
6162 GSM_Init(true); 6312 GSM_Init(true);
6163 6313
6164 for (i=start;i<=stop;i++) { 6314 while (!gshutdown) {
6165 Note.Location=i; 6315 error = Phone->GetNextNote(&s, &Note, start);
6166 printmsg("Location : %i\n",i); 6316 if (error == ERR_EMPTY) break;
6167 error=Phone->GetNote(&s,&Note,refresh); 6317 Print_Error(error);
6168 if (error != ERR_EMPTY) Print_Error(error); 6318 printmsg("Text : \"%s\"\n",DecodeUnicodeConsole(Note.Text));
6169 6319 printf("\n");
6170 if (error == ERR_EMPTY) { 6320 start = false;
6171 printmsg("Entry is empty\n\n");
6172 } else {
6173 printmsg("Text : \"%s\"\n",DecodeUnicodeConsole(Note.Text));
6174 printf("\n");
6175 refresh=false;
6176 }
6177 } 6321 }
6178
6179 GSM_Terminate(); 6322 GSM_Terminate();
6180} 6323}
6181 6324
6182static void GetSecurityStatus(int argc, char *argv[]) 6325static void GetSecurityStatus(int argc, char *argv[])
6183{ 6326{
6184 GSM_Init(true); 6327 GSM_Init(true);
6185 6328
6186 PrintSecurityStatus(); 6329 PrintSecurityStatus();
6187 6330
6188 GSM_Terminate(); 6331 GSM_Terminate();
6189} 6332}
6190 6333
6191static void EnterSecurityCode(int argc, char *argv[]) 6334static void EnterSecurityCode(int argc, char *argv[])
6192{ 6335{
6193 GSM_SecurityCode Code; 6336 GSM_SecurityCode Code;
6194 6337
6195 if (mystrncasecmp(argv[2],"PIN",0)) { Code.Type = SEC_Pin; 6338 if (mystrncasecmp(argv[2],"PIN",0)) { Code.Type = SEC_Pin;
6196 } else if (mystrncasecmp(argv[2],"PUK",0)) {Code.Type = SEC_Puk; 6339 } else if (mystrncasecmp(argv[2],"PUK",0)) {Code.Type = SEC_Puk;
6197 } else if (mystrncasecmp(argv[2],"PIN2",0)) {Code.Type = SEC_Pin2; 6340 } else if (mystrncasecmp(argv[2],"PIN2",0)) {Code.Type = SEC_Pin2;
6198 } else if (mystrncasecmp(argv[2],"PUK2",0)) {Code.Type = SEC_Puk2; 6341 } else if (mystrncasecmp(argv[2],"PUK2",0)) {Code.Type = SEC_Puk2;
6199 } else { 6342 } else {
6200 printmsg("What security code (\"%s\") ?\n",argv[2]); 6343 printmsg("What security code (\"%s\") ?\n",argv[2]);
6201 exit(-1); 6344 exit(-1);
6202 } 6345 }
6203 6346
6204 strcpy(Code.Code,argv[3]); 6347 strcpy(Code.Code,argv[3]);
6205 6348
6206 GSM_Init(true); 6349 GSM_Init(true);
6207 6350
6208 error=Phone->EnterSecurityCode(&s,Code); 6351 error=Phone->EnterSecurityCode(&s,Code);
6209 Print_Error(error); 6352 Print_Error(error);
6210 6353
6211 GSM_Terminate(); 6354 GSM_Terminate();
6212} 6355}
6213 6356
6214static void GetProfile(int argc, char *argv[]) 6357static void GetProfile(int argc, char *argv[])
6215{ 6358{
6216 GSM_Profile Profile; 6359 GSM_Profile Profile;
6217 int start,stop,j,k; 6360 int start,stop,j,k;
6218 GSM_Bitmap caller[5]; 6361 GSM_Bitmap caller[5];
6219 bool callerinit[5],special; 6362 bool callerinit[5],special;
6220 GSM_AllRingtonesInfo Info; 6363 GSM_AllRingtonesInfo Info;
6221 6364
6222 GetStartStop(&start, &stop, 2, argc, argv); 6365 GetStartStop(&start, &stop, 2, argc, argv);
6223 6366
6224 for (i=0;i<5;i++) callerinit[i] = false; 6367 for (i=0;i<5;i++) callerinit[i] = false;
6225 6368
6226 GSM_Init(true); 6369 GSM_Init(true);
6227 6370
6228 error=Phone->GetRingtonesInfo(&s,&Info); 6371 error=Phone->GetRingtonesInfo(&s,&Info);
6229 if (error != ERR_NONE) Info.Number = 0; 6372 if (error != ERR_NONE) Info.Number = 0;
6230 6373
6231 for (i=start;i<=stop;i++) { 6374 for (i=start;i<=stop;i++) {
6232 Profile.Location=i; 6375 Profile.Location=i;
6233 error=Phone->GetProfile(&s,&Profile); 6376 error=Phone->GetProfile(&s,&Profile);
6234 Print_Error(error); 6377 Print_Error(error);
6235 6378
6236 printmsg("%i. \"%s\"",i,DecodeUnicodeConsole(Profile.Name)); 6379 printmsg("%i. \"%s\"",i,DecodeUnicodeConsole(Profile.Name));
6237 if (Profile.Active) printmsg(" (active)"); 6380 if (Profile.Active) printmsg(" (active)");
6238 if (Profile.DefaultName) printmsg(" (default name)"); 6381 if (Profile.DefaultName) printmsg(" (default name)");
6239 if (Profile.HeadSetProfile) printmsg(" (HeadSet profile)"); 6382 if (Profile.HeadSetProfile) printmsg(" (HeadSet profile)");
6240 if (Profile.CarKitProfile) printmsg(" (CarKit profile)"); 6383 if (Profile.CarKitProfile) printmsg(" (CarKit profile)");
6241 printf("\n"); 6384 printf("\n");
6242 for (j=0;j<Profile.FeaturesNumber;j++) { 6385 for (j=0;j<Profile.FeaturesNumber;j++) {
6243 special = false; 6386 special = false;
6244 switch (Profile.FeatureID[j]) { 6387 switch (Profile.FeatureID[j]) {
6245 case Profile_MessageToneID: 6388 case Profile_MessageToneID:
6246 case Profile_RingtoneID: 6389 case Profile_RingtoneID:
6247 special = true; 6390 special = true;
6248 if (Profile.FeatureID[j] == Profile_RingtoneID) { 6391 if (Profile.FeatureID[j] == Profile_RingtoneID) {
6249 printmsg("Ringtone ID : "); 6392 printmsg("Ringtone ID : ");
6250 } else { 6393 } else {
6251 printmsg("Message alert tone ID : "); 6394 printmsg("Message alert tone ID : ");
6252 } 6395 }
6253 if (UnicodeLength(GSM_GetRingtoneName(&Info,Profile.FeatureValue[j]))!=0) { 6396 if (UnicodeLength(GSM_GetRingtoneName(&Info,Profile.FeatureValue[j]))!=0) {
6254 printmsg("\"%s\"\n",DecodeUnicodeConsole(GSM_GetRingtoneName(&Info,Profile.FeatureValue[j]))); 6397 printmsg("\"%s\"\n",DecodeUnicodeConsole(GSM_GetRingtoneName(&Info,Profile.FeatureValue[j])));
6255 } else { 6398 } else {
6256 printmsg("%i\n",Profile.FeatureValue[j]); 6399 printmsg("%i\n",Profile.FeatureValue[j]);
6257 } 6400 }
6258 break; 6401 break;
6259 case Profile_CallerGroups: 6402 case Profile_CallerGroups:
6260 special = true; 6403 special = true;
6261 printmsg("Call alert for :"); 6404 printmsg("Call alert for :");
6262 for (k=0;k<5;k++) { 6405 for (k=0;k<5;k++) {
6263 if (Profile.CallerGroups[k]) { 6406 if (Profile.CallerGroups[k]) {
6264 if (!callerinit[k]) { 6407 if (!callerinit[k]) {
6265 caller[k].Type = GSM_CallerGroupLogo; 6408 caller[k].Type = GSM_CallerGroupLogo;
6266 caller[k].Location = k + 1; 6409 caller[k].Location = k + 1;
6267 error=Phone->GetBitmap(&s,&caller[k]); 6410 error=Phone->GetBitmap(&s,&caller[k]);
6268 if (error == ERR_SECURITYERROR) { 6411 if (error == ERR_SECURITYERROR) {
6269 NOKIA_GetDefaultCallerGroupName(&s,&caller[k]); 6412 NOKIA_GetDefaultCallerGroupName(&s,&caller[k]);
6270 } else { 6413 } else {
6271 Print_Error(error); 6414 Print_Error(error);
6272 } 6415 }
6273 callerinit[k]= true; 6416 callerinit[k]= true;
6274 } 6417 }
6275 printmsg(" \"%s\"",DecodeUnicodeConsole(caller[k].Text)); 6418 printmsg(" \"%s\"",DecodeUnicodeConsole(caller[k].Text));
6276 } 6419 }
6277 } 6420 }
6278 printf("\n"); 6421 printf("\n");
6279 break; 6422 break;
6280 case Profile_ScreenSaverNumber: 6423 case Profile_ScreenSaverNumber:
6281 special = true; 6424 special = true;
6282 printmsg("Screen saver number : "); 6425 printmsg("Screen saver number : ");
6283 printmsg("%i\n",Profile.FeatureValue[j]); 6426 printmsg("%i\n",Profile.FeatureValue[j]);
6284 break; 6427 break;
6285 case Profile_CallAlert : printmsg("Incoming call alert : "); break; 6428 case Profile_CallAlert : printmsg("Incoming call alert : "); break;
6286 case Profile_RingtoneVolume : printmsg("Ringtone volume : "); break; 6429 case Profile_RingtoneVolume : printmsg("Ringtone volume : "); break;
6287 case Profile_Vibration : printmsg("Vibrating alert : "); break; 6430 case Profile_Vibration : printmsg("Vibrating alert : "); break;
6288 case Profile_MessageTone: printmsg("Message alert tone : "); break; 6431 case Profile_MessageTone: printmsg("Message alert tone : "); break;
6289 case Profile_KeypadTone : printmsg("Keypad tones : "); break; 6432 case Profile_KeypadTone : printmsg("Keypad tones : "); break;
6290 case Profile_WarningTone: printmsg("Warning (games) tones : "); break; 6433 case Profile_WarningTone: printmsg("Warning (games) tones : "); break;
6291 case Profile_ScreenSaver: printmsg("Screen saver : "); break; 6434 case Profile_ScreenSaver: printmsg("Screen saver : "); break;
6292 case Profile_ScreenSaverTime: printmsg("Screen saver timeout : "); break; 6435 case Profile_ScreenSaverTime: printmsg("Screen saver timeout : "); break;
6293 case Profile_AutoAnswer : printmsg("Automatic answer : "); break; 6436 case Profile_AutoAnswer : printmsg("Automatic answer : "); break;
6294 case Profile_Lights : printmsg("Lights : "); break; 6437 case Profile_Lights : printmsg("Lights : "); break;
6295 default: 6438 default:
6296 printmsg("Unknown\n"); 6439 printmsg("Unknown\n");
6297 special = true; 6440 special = true;
6298 } 6441 }
6299 if (!special) { 6442 if (!special) {
6300 switch (Profile.FeatureValue[j]) { 6443 switch (Profile.FeatureValue[j]) {
6301 case PROFILE_VOLUME_LEVEL1 : 6444 case PROFILE_VOLUME_LEVEL1 :
6302 case PROFILE_KEYPAD_LEVEL1 : printmsg("Level 1\n"); break; 6445 case PROFILE_KEYPAD_LEVEL1 : printmsg("Level 1\n"); break;
6303 case PROFILE_VOLUME_LEVEL2 : 6446 case PROFILE_VOLUME_LEVEL2 :
6304 case PROFILE_KEYPAD_LEVEL2 : printmsg("Level 2\n"); break; 6447 case PROFILE_KEYPAD_LEVEL2 : printmsg("Level 2\n"); break;
6305 case PROFILE_VOLUME_LEVEL3 : 6448 case PROFILE_VOLUME_LEVEL3 :
6306 case PROFILE_KEYPAD_LEVEL3 : printmsg("Level 3\n"); break; 6449 case PROFILE_KEYPAD_LEVEL3 : printmsg("Level 3\n"); break;
6307 case PROFILE_VOLUME_LEVEL4 : printmsg("Level 4\n"); break; 6450 case PROFILE_VOLUME_LEVEL4 : printmsg("Level 4\n"); break;
6308 case PROFILE_VOLUME_LEVEL5 : printmsg("Level 5\n"); break; 6451 case PROFILE_VOLUME_LEVEL5 : printmsg("Level 5\n"); break;
6309 case PROFILE_MESSAGE_NOTONE : 6452 case PROFILE_MESSAGE_NOTONE :
6310 case PROFILE_AUTOANSWER_OFF : 6453 case PROFILE_AUTOANSWER_OFF :
6311 case PROFILE_LIGHTS_OFF : 6454 case PROFILE_LIGHTS_OFF :
6312 case PROFILE_SAVER_OFF : 6455 case PROFILE_SAVER_OFF :
6313 case PROFILE_WARNING_OFF : 6456 case PROFILE_WARNING_OFF :
6314 case PROFILE_CALLALERT_OFF : 6457 case PROFILE_CALLALERT_OFF :
6315 case PROFILE_VIBRATION_OFF : 6458 case PROFILE_VIBRATION_OFF :
6316 case PROFILE_KEYPAD_OFF : printmsg("Off\n"); break; 6459 case PROFILE_KEYPAD_OFF : printmsg("Off\n"); break;
6317 case PROFILE_CALLALERT_RINGING : printmsg("Ringing\n"); break; 6460 case PROFILE_CALLALERT_RINGING : printmsg("Ringing\n"); break;
6318 case PROFILE_CALLALERT_BEEPONCE : 6461 case PROFILE_CALLALERT_BEEPONCE :
6319 case PROFILE_MESSAGE_BEEPONCE : printmsg("Beep once\n"); break; 6462 case PROFILE_MESSAGE_BEEPONCE : printmsg("Beep once\n"); break;
6320 case PROFILE_CALLALERT_RINGONCE : printmsg("Ring once\n");break; 6463 case PROFILE_CALLALERT_RINGONCE : printmsg("Ring once\n");break;
6321 case PROFILE_CALLALERT_ASCENDING : printmsg("Ascending\n"); break; 6464 case PROFILE_CALLALERT_ASCENDING : printmsg("Ascending\n"); break;
6322 case PROFILE_CALLALERT_CALLERGROUPS : printmsg("Caller groups\n");break; 6465 case PROFILE_CALLALERT_CALLERGROUPS : printmsg("Caller groups\n");break;
6323 case PROFILE_MESSAGE_STANDARD : printmsg("Standard\n"); break; 6466 case PROFILE_MESSAGE_STANDARD : printmsg("Standard\n"); break;
6324 case PROFILE_MESSAGE_SPECIAL : printmsg("Special\n"); break; 6467 case PROFILE_MESSAGE_SPECIAL : printmsg("Special\n"); break;
6325 case PROFILE_MESSAGE_ASCENDING : printmsg("Ascending\n"); break; 6468 case PROFILE_MESSAGE_ASCENDING : printmsg("Ascending\n"); break;
6326 case PROFILE_MESSAGE_PERSONAL : printmsg("Personal\n"); break; 6469 case PROFILE_MESSAGE_PERSONAL : printmsg("Personal\n"); break;
6327 case PROFILE_AUTOANSWER_ON : 6470 case PROFILE_AUTOANSWER_ON :
6328 case PROFILE_WARNING_ON : 6471 case PROFILE_WARNING_ON :
6329 case PROFILE_SAVER_ON : 6472 case PROFILE_SAVER_ON :
6330 case PROFILE_VIBRATION_ON : printmsg("On\n"); break; 6473 case PROFILE_VIBRATION_ON : printmsg("On\n"); break;
6331 case PROFILE_VIBRATION_FIRST : printmsg("Vibrate first\n");break; 6474 case PROFILE_VIBRATION_FIRST : printmsg("Vibrate first\n");break;
6332 case PROFILE_LIGHTS_AUTO : printmsg("Auto\n"); break; 6475 case PROFILE_LIGHTS_AUTO : printmsg("Auto\n"); break;
6333 case PROFILE_SAVER_TIMEOUT_5SEC : printmsg("5 seconds\n"); break; 6476 case PROFILE_SAVER_TIMEOUT_5SEC : printmsg("5 seconds\n"); break;
6334 case PROFILE_SAVER_TIMEOUT_20SEC : printmsg("20 seconds\n"); break; 6477 case PROFILE_SAVER_TIMEOUT_20SEC : printmsg("20 seconds\n"); break;
6335 case PROFILE_SAVER_TIMEOUT_1MIN : printmsg("1 minute\n"); break; 6478 case PROFILE_SAVER_TIMEOUT_1MIN : printmsg("1 minute\n"); break;
6336 case PROFILE_SAVER_TIMEOUT_2MIN : printmsg("2 minutes\n");break; 6479 case PROFILE_SAVER_TIMEOUT_2MIN : printmsg("2 minutes\n");break;
6337 case PROFILE_SAVER_TIMEOUT_5MIN : printmsg("5 minutes\n");break; 6480 case PROFILE_SAVER_TIMEOUT_5MIN : printmsg("5 minutes\n");break;
6338 case PROFILE_SAVER_TIMEOUT_10MIN : printmsg("10 minutes\n");break; 6481 case PROFILE_SAVER_TIMEOUT_10MIN : printmsg("10 minutes\n");break;
6339 default : printmsg("UNKNOWN\n"); 6482 default : printmsg("UNKNOWN\n");
6340 } 6483 }
6341 } 6484 }
6342 } 6485 }
6343 printf("\n"); 6486 printf("\n");
6344 } 6487 }
6345 6488
6346 GSM_Terminate(); 6489 GSM_Terminate();
6347} 6490}
6348 6491
6349static void GetSpeedDial(int argc, char *argv[]) 6492static void GetSpeedDial(int argc, char *argv[])
6350{ 6493{
6351 GSM_SpeedDial SpeedDial; 6494 GSM_SpeedDial SpeedDial;
6352 GSM_MemoryEntry Phonebook; 6495 GSM_MemoryEntry Phonebook;
6353 int start,stop,Name,Number,Group; 6496 int start,stop,Name,Number,Group;
6354 6497
6355 GetStartStop(&start, &stop, 2, argc, argv); 6498 GetStartStop(&start, &stop, 2, argc, argv);
6356 6499
6357 GSM_Init(true); 6500 GSM_Init(true);
6358 6501
6359 for (i=start;i<=stop;i++) { 6502 for (i=start;i<=stop;i++) {
6360 SpeedDial.Location=i; 6503 SpeedDial.Location=i;
6361 error=Phone->GetSpeedDial(&s,&SpeedDial); 6504 error=Phone->GetSpeedDial(&s,&SpeedDial);
6362 printmsg("%i.",i); 6505 printmsg("%i.",i);
6363 switch (error) { 6506 switch (error) {
6364 case ERR_EMPTY: 6507 case ERR_EMPTY:
6365 printmsg(" speed dial not assigned\n"); 6508 printmsg(" speed dial not assigned\n");
6366 break; 6509 break;
6367 default: 6510 default:
6368 Print_Error(error); 6511 Print_Error(error);
6369 6512
6370 Phonebook.Location= SpeedDial.MemoryLocation; 6513 Phonebook.Location= SpeedDial.MemoryLocation;
@@ -6382,855 +6525,878 @@ static void GetSpeedDial(int argc, char *argv[])
6382 GSM_Terminate(); 6525 GSM_Terminate();
6383} 6526}
6384 6527
6385static void ResetPhoneSettings(int argc, char *argv[]) 6528static void ResetPhoneSettings(int argc, char *argv[])
6386{ 6529{
6387 GSM_ResetSettingsType Type; 6530 GSM_ResetSettingsType Type;
6388 6531
6389 if (mystrncasecmp(argv[2],"PHONE",0)) { Type = GSM_RESET_PHONESETTINGS; 6532 if (mystrncasecmp(argv[2],"PHONE",0)) { Type = GSM_RESET_PHONESETTINGS;
6390 } else if (mystrncasecmp(argv[2],"UIF",0)) { Type = GSM_RESET_USERINTERFACE; 6533 } else if (mystrncasecmp(argv[2],"UIF",0)) { Type = GSM_RESET_USERINTERFACE;
6391 } else if (mystrncasecmp(argv[2],"ALL",0)) { Type = GSM_RESET_USERINTERFACE_PHONESETTINGS; 6534 } else if (mystrncasecmp(argv[2],"ALL",0)) { Type = GSM_RESET_USERINTERFACE_PHONESETTINGS;
6392 } else if (mystrncasecmp(argv[2],"DEV",0)) { Type = GSM_RESET_DEVICE; 6535 } else if (mystrncasecmp(argv[2],"DEV",0)) { Type = GSM_RESET_DEVICE;
6393 } else if (mystrncasecmp(argv[2],"FACTORY",0)) { Type = GSM_RESET_FULLFACTORY; 6536 } else if (mystrncasecmp(argv[2],"FACTORY",0)) { Type = GSM_RESET_FULLFACTORY;
6394 } else { 6537 } else {
6395 printmsg("What type of reset phone settings (\"%s\") ?\n",argv[2]); 6538 printmsg("What type of reset phone settings (\"%s\") ?\n",argv[2]);
6396 exit(-1); 6539 exit(-1);
6397 } 6540 }
6398 6541
6399 GSM_Init(true); 6542 GSM_Init(true);
6400 6543
6401 error=Phone->ResetPhoneSettings(&s,Type); 6544 error=Phone->ResetPhoneSettings(&s,Type);
6402 Print_Error(error); 6545 Print_Error(error);
6403 6546
6404 GSM_Terminate(); 6547 GSM_Terminate();
6405} 6548}
6406 6549
6407#if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4) 6550#if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4)
6408static void NokiaSecurityCode(int argc, char *argv[]) 6551static void NokiaSecurityCode(int argc, char *argv[])
6409{ 6552{
6410 GSM_Init(true); 6553 GSM_Init(true);
6411 6554
6412#ifdef GSM_ENABLE_NOKIA_DCT3 6555#ifdef GSM_ENABLE_NOKIA_DCT3
6413 DCT3GetSecurityCode(argc,argv); 6556 DCT3GetSecurityCode(argc,argv);
6414#endif 6557#endif
6415#ifdef GSM_ENABLE_NOKIA_DCT4 6558#ifdef GSM_ENABLE_NOKIA_DCT4
6416 //DCT4ResetSecurityCode(argc, argv); 6559 //DCT4ResetSecurityCode(argc, argv);
6417 DCT4GetSecurityCode(argc,argv); 6560 DCT4GetSecurityCode(argc,argv);
6418#endif 6561#endif
6419 6562
6420 GSM_Terminate(); 6563 GSM_Terminate();
6421} 6564}
6422 6565
6423static void NokiaSetPhoneMenus(int argc, char *argv[]) 6566static void NokiaSetPhoneMenus(int argc, char *argv[])
6424{ 6567{
6425 GSM_Init(true); 6568 GSM_Init(true);
6426 6569
6427#ifdef GSM_ENABLE_NOKIA_DCT3 6570#ifdef GSM_ENABLE_NOKIA_DCT3
6428 DCT3SetPhoneMenus (argc, argv); 6571 DCT3SetPhoneMenus (argc, argv);
6429#endif 6572#endif
6430#ifdef GSM_ENABLE_NOKIA_DCT4 6573#ifdef GSM_ENABLE_NOKIA_DCT4
6431 DCT4SetPhoneMenus (argc, argv); 6574 DCT4SetPhoneMenus (argc, argv);
6432#endif 6575#endif
6433 6576
6434 GSM_Terminate(); 6577 GSM_Terminate();
6435} 6578}
6436 6579
6437static void NokiaSelfTests(int argc, char *argv[]) 6580static void NokiaSelfTests(int argc, char *argv[])
6438{ 6581{
6439 GSM_Init(true); 6582 GSM_Init(true);
6440 6583
6441#ifdef GSM_ENABLE_NOKIA_DCT3 6584#ifdef GSM_ENABLE_NOKIA_DCT3
6442 DCT3SelfTests(argc, argv); 6585 DCT3SelfTests(argc, argv);
6443#endif 6586#endif
6444#ifdef GSM_ENABLE_NOKIA_DCT4 6587#ifdef GSM_ENABLE_NOKIA_DCT4
6445 DCT4SelfTests(argc, argv); 6588 DCT4SelfTests(argc, argv);
6446#endif 6589#endif
6447 6590
6448 GSM_Terminate(); 6591 GSM_Terminate();
6449} 6592}
6450#endif 6593#endif
6451 6594
6452static void DeleteAllSMS(int argc, char *argv[]) 6595static void DeleteAllSMS(int argc, char *argv[])
6453{ 6596{
6454 GSM_MultiSMSMessage sms; 6597 GSM_MultiSMSMessage sms;
6455 GSM_SMSFolders folders; 6598 GSM_SMSFolders folders;
6456 int foldernum; 6599 int foldernum;
6457 bool start = true; 6600 bool start = true;
6458 6601
6459 GSM_Init(true); 6602 GSM_Init(true);
6460 6603
6461 error=Phone->GetSMSFolders(&s, &folders); 6604 error=Phone->GetSMSFolders(&s, &folders);
6462 Print_Error(error); 6605 Print_Error(error);
6463 6606
6464 GetStartStop(&foldernum, NULL, 2, argc, argv); 6607 GetStartStop(&foldernum, NULL, 2, argc, argv);
6465 if (foldernum > folders.Number) { 6608 if (foldernum > folders.Number) {
6466 printmsg("Too high folder number (max. %i)\n",folders.Number); 6609 printmsg("Too high folder number (max. %i)\n",folders.Number);
6467 GSM_Terminate(); 6610 GSM_Terminate();
6468 exit(-1); 6611 exit(-1);
6469 } 6612 }
6470 6613
6471 printmsg("Deleting SMS from \"%s\" folder: ",DecodeUnicodeConsole(folders.Folder[foldernum-1].Name)); 6614 printmsg("Deleting SMS from \"%s\" folder: ",DecodeUnicodeConsole(folders.Folder[foldernum-1].Name));
6472 6615
6473 while (error == ERR_NONE) { 6616 while (error == ERR_NONE) {
6474 sms.SMS[0].Folder=0x00; 6617 sms.SMS[0].Folder=0x00;
6475 error=Phone->GetNextSMS(&s, &sms, start); 6618 error=Phone->GetNextSMS(&s, &sms, start);
6476 switch (error) { 6619 switch (error) {
6477 case ERR_EMPTY: 6620 case ERR_EMPTY:
6478 break; 6621 break;
6479 default: 6622 default:
6480 Print_Error(error); 6623 Print_Error(error);
6481 if (sms.SMS[0].Folder == foldernum) { 6624 if (sms.SMS[0].Folder == foldernum) {
6482 sms.SMS[0].Folder=0x00; 6625 sms.SMS[0].Folder=0x00;
6483 error=Phone->DeleteSMS(&s, &sms.SMS[0]); 6626 error=Phone->DeleteSMS(&s, &sms.SMS[0]);
6484 Print_Error(error); 6627 Print_Error(error);
6485 printmsg("*"); 6628 printmsg("*");
6486 } 6629 }
6487 } 6630 }
6488 start=false; 6631 start=false;
6489 } 6632 }
6490 6633
6491 printf("\n"); 6634 printf("\n");
6492 6635
6493 GSM_Terminate(); 6636 GSM_Terminate();
6494} 6637}
6495 6638
6496static void SendDTMF(int argc, char *argv[]) 6639static void SendDTMF(int argc, char *argv[])
6497{ 6640{
6498 GSM_Init(true); 6641 GSM_Init(true);
6499 6642
6500 error=Phone->SendDTMF(&s,argv[2]); 6643 error=Phone->SendDTMF(&s,argv[2]);
6501 Print_Error(error); 6644 Print_Error(error);
6502 6645
6503 GSM_Terminate(); 6646 GSM_Terminate();
6504} 6647}
6505 6648
6506static void GetDisplayStatus(int argc, char *argv[]) 6649static void GetDisplayStatus(int argc, char *argv[])
6507{ 6650{
6508 GSM_DisplayFeatures Features; 6651 GSM_DisplayFeatures Features;
6509 int i; 6652 int i;
6510 6653
6511 GSM_Init(true); 6654 GSM_Init(true);
6512 6655
6513 error=Phone->GetDisplayStatus(&s,&Features); 6656 error=Phone->GetDisplayStatus(&s,&Features);
6514 Print_Error(error); 6657 Print_Error(error);
6515 6658
6516 printmsg("Current display features :\n"); 6659 printmsg("Current display features :\n");
6517 6660
6518 for (i=0;i<Features.Number;i++) { 6661 for (i=0;i<Features.Number;i++) {
6519 switch(Features.Feature[i]) { 6662 switch(Features.Feature[i]) {
6520 case GSM_CallActive : printmsg("Call active\n");break; 6663 case GSM_CallActive : printmsg("Call active\n");break;
6521 case GSM_UnreadSMS : printmsg("Unread SMS\n");break; 6664 case GSM_UnreadSMS : printmsg("Unread SMS\n");break;
6522 case GSM_VoiceCall : printmsg("Voice call\n");break; 6665 case GSM_VoiceCall : printmsg("Voice call\n");break;
6523 case GSM_FaxCall : printmsg("Fax call\n");break; 6666 case GSM_FaxCall : printmsg("Fax call\n");break;
6524 case GSM_DataCall : printmsg("Data call\n");break; 6667 case GSM_DataCall : printmsg("Data call\n");break;
6525 case GSM_KeypadLocked : printmsg("Keypad locked\n");break; 6668 case GSM_KeypadLocked : printmsg("Keypad locked\n");break;
6526 case GSM_SMSMemoryFull: printmsg("SMS memory full\n"); 6669 case GSM_SMSMemoryFull: printmsg("SMS memory full\n");
6527 } 6670 }
6528 } 6671 }
6529 6672
6530 GSM_Terminate(); 6673 GSM_Terminate();
6531} 6674}
6532 6675
6533static void SetAutoNetworkLogin(int argc, char *argv[]) 6676static void SetAutoNetworkLogin(int argc, char *argv[])
6534{ 6677{
6535 GSM_Init(true); 6678 GSM_Init(true);
6536 6679
6537 error=Phone->SetAutoNetworkLogin(&s); 6680 error=Phone->SetAutoNetworkLogin(&s);
6538 Print_Error(error); 6681 Print_Error(error);
6539 6682
6540 GSM_Terminate(); 6683 GSM_Terminate();
6541} 6684}
6542 6685
6543#ifdef DEBUG 6686#ifdef DEBUG
6544static void MakeConvertTable(int argc, char *argv[]) 6687static void MakeConvertTable(int argc, char *argv[])
6545{ 6688{
6546 unsigned char InputBuffer[10000], Buffer[10000]; 6689 unsigned char InputBuffer[10000], Buffer[10000];
6547 FILE *file; 6690 FILE *file;
6548 int size,i,j=0; 6691 int size,i,j=0;
6549 6692
6550 file = fopen(argv[2], "rb"); 6693 file = fopen(argv[2], "rb");
6551 if (file == NULL) Print_Error(ERR_CANTOPENFILE); 6694 if (file == NULL) Print_Error(ERR_CANTOPENFILE);
6552 size=fread(InputBuffer, 1, 10000-1, file); 6695 size=fread(InputBuffer, 1, 10000-1, file);
6553 fclose(file); 6696 fclose(file);
6554 InputBuffer[size] = 0; 6697 InputBuffer[size] = 0;
6555 InputBuffer[size+1] = 0; 6698 InputBuffer[size+1] = 0;
6556 6699
6557 ReadUnicodeFile(Buffer,InputBuffer); 6700 ReadUnicodeFile(Buffer,InputBuffer);
6558 6701
6559 for(i=0;i<((int)UnicodeLength(Buffer));i++) { 6702 for(i=0;i<((int)UnicodeLength(Buffer));i++) {
6560 j++; 6703 j++;
6561 if (j==100) { 6704 if (j==100) {
6562 printf("\"\\\n\""); 6705 printf("\"\\\n\"");
6563 j=0; 6706 j=0;
6564 } 6707 }
6565 printf("\\x%02x\\x%02x",Buffer[i*2],Buffer[i*2+1]); 6708 printf("\\x%02x\\x%02x",Buffer[i*2],Buffer[i*2+1]);
6566 } 6709 }
6567 printf("\\x00\\x00"); 6710 printf("\\x00\\x00");
6568} 6711}
6569#endif 6712#endif
6570 6713
6571static void ListNetworks(int argc, char *argv[]) 6714static void ListNetworks(int argc, char *argv[])
6572{ 6715{
6573 extern unsigned char *GSM_Networks[]; 6716 extern unsigned char *GSM_Networks[];
6717 extern unsigned char *GSM_Countries[];
6574 int i=0; 6718 int i=0;
6719 char country[4]="";
6575 6720
6576 printmsg("Network Name\n\n"); 6721 if (argc>2) {
6722 while (GSM_Countries[i*2]!=NULL) {
6723 if (!strncmp(GSM_Countries[i*2+1],argv[2],strlen(argv[2]))) {
6724 strcpy(country,GSM_Countries[i*2]);
6725 printmsg("Networks for %s:\n\n",GSM_Countries[i*2+1]);
6726 break;
6727 }
6728 i++;
6729 }
6730 if (!*country) {
6731 printmsg("Unknown country name.");
6732 exit(-1);
6733 }
6734 }
6735 printmsg("Network Name\n");
6736 i=0;
6577 while (GSM_Networks[i*2]!=NULL) { 6737 while (GSM_Networks[i*2]!=NULL) {
6578 printmsg("%s %s\n", GSM_Networks[i*2], GSM_Networks[i*2+1]); 6738 if (argc>2) {
6739 if (!strncmp(GSM_Networks[i*2],country,strlen(country))) {
6740 printmsg("%s %s\n", GSM_Networks[i*2], GSM_Networks[i*2+1]);
6741 }
6742 } else {
6743 printmsg("%s %s\n", GSM_Networks[i*2], GSM_Networks[i*2+1]);
6744 }
6579 i++; 6745 i++;
6580 } 6746 }
6581} 6747}
6582 6748
6583static void Version(int argc, char *argv[]) 6749static void Version(int argc, char *argv[])
6584{ 6750{
6585 // unsigned char buff[10]; 6751 // unsigned char buff[10];
6586 // int len; 6752 // int len;
6587 6753
6588 printmsg("[Gammu version %s built %s %s]\n\n",VERSION,__TIME__,__DATE__); 6754 printmsg("[Gammu version %s built %s %s",VERSION,__TIME__,__DATE__);
6755 if (strlen(GetCompiler()) != 0) printmsg(" in %s",GetCompiler());
6756 printmsg("]\n\n");
6589 6757
6590#ifdef DEBUG 6758#ifdef DEBUG
6591 printf("GSM_SMSMessage - %i\n",sizeof(GSM_SMSMessage)); 6759 printf("GSM_SMSMessage - %i\n",sizeof(GSM_SMSMessage));
6592 printf("GSM_SMSC - %i\n",sizeof(GSM_SMSC)); 6760 printf("GSM_SMSC - %i\n",sizeof(GSM_SMSC));
6593 printf("GSM_SMS_State - %i\n",sizeof(GSM_SMS_State)); 6761 printf("GSM_SMS_State - %i\n",sizeof(GSM_SMS_State));
6594 printf("GSM_UDHHeader - %i\n",sizeof(GSM_UDHHeader)); 6762 printf("GSM_UDHHeader - %i\n",sizeof(GSM_UDHHeader));
6595 printf("bool - %i\n",sizeof(bool)); 6763 printf("bool - %i\n",sizeof(bool));
6596 printf("GSM_DateTime - %i\n",sizeof(GSM_DateTime)); 6764 printf("GSM_DateTime - %i\n",sizeof(GSM_DateTime));
6597 printf("int - %i\n",sizeof(int)); 6765 printf("int - %i\n",sizeof(int));
6598 printf("GSM_NetworkInfo - %i\n",sizeof(GSM_NetworkInfo)); 6766 printf("GSM_NetworkInfo - %i\n",sizeof(GSM_NetworkInfo));
6599#endif 6767#endif
6600 6768
6601 //len=DecodeBASE64("AXw", buff, 3); 6769 //len=DecodeBASE64("AXw", buff, 3);
6602 //DumpMessage(stdout, buff, len); 6770 //DumpMessage(stdout, buff, len);
6603} 6771}
6604 6772
6605static void GetFMStation(int argc, char *argv[]) 6773static void GetFMStation(int argc, char *argv[])
6606{ 6774{
6607 GSM_FMStation Station; 6775 GSM_FMStation Station;
6608 int start,stop; 6776 int start,stop;
6609 6777
6610 GetStartStop(&start, &stop, 2, argc, argv); 6778 GetStartStop(&start, &stop, 2, argc, argv);
6611 6779
6612 GSM_Init(true); 6780 GSM_Init(true);
6613 6781
6614 for (i=start;i<=stop;i++) { 6782 for (i=start;i<=stop;i++) {
6615 Station.Location=i; 6783 Station.Location=i;
6616 error=Phone->GetFMStation(&s,&Station); 6784 error=Phone->GetFMStation(&s,&Station);
6617 switch (error) { 6785 switch (error) {
6618 case ERR_EMPTY: 6786 case ERR_EMPTY:
6619 printmsg("Entry number %i is empty\n",i); 6787 printmsg("Entry number %i is empty\n",i);
6620 break; 6788 break;
6621 case ERR_NONE: 6789 case ERR_NONE:
6622 printmsg("Entry number %i\nStation name : \"%s\"\nFrequency : %.1f MHz\n", 6790 printmsg("Entry number %i\nStation name : \"%s\"\nFrequency : %.1f MHz\n",
6623 i,DecodeUnicodeConsole(Station.StationName), 6791 i,DecodeUnicodeConsole(Station.StationName),
6624 Station.Frequency); 6792 Station.Frequency);
6625 break; 6793 break;
6626 default: 6794 default:
6627 Print_Error(error); 6795 Print_Error(error);
6628 } 6796 }
6629 } 6797 }
6630 GSM_Terminate(); 6798 GSM_Terminate();
6631} 6799}
6632 6800
6633static void GetFileSystemStatus(int argc, char *argv[]) 6801static void GetFileSystemStatus(int argc, char *argv[])
6634{ 6802{
6635 GSM_FileSystemStatusStatus; 6803 GSM_FileSystemStatusStatus;
6636 6804
6637 GSM_Init(true); 6805 GSM_Init(true);
6638 6806
6639 error = Phone->GetFileSystemStatus(&s,&Status); 6807 error = Phone->GetFileSystemStatus(&s,&Status);
6640 if (error != ERR_NOTSUPPORTED && error != ERR_NOTIMPLEMENTED) { 6808 if (error != ERR_NOTSUPPORTED && error != ERR_NOTIMPLEMENTED) {
6641 Print_Error(error); 6809 Print_Error(error);
6642 printmsg("\nFree memory: %i, total memory: %i\n",Status.Free,Status.Free+Status.Used); 6810 printmsg("\nFree memory: %i, total memory: %i\n",Status.Free,Status.Free+Status.Used);
6643 } 6811 }
6644 6812
6645 GSM_Terminate(); 6813 GSM_Terminate();
6646} 6814}
6647 6815
6648static void GetFileSystem(int argc, char *argv[]) 6816static void GetFileSystem(int argc, char *argv[])
6649{ 6817{
6650 bool Start = true; 6818 bool Start = true;
6651 GSM_File Files; 6819 GSM_File Files;
6652 int j; 6820 int j;
6653 GSM_FileSystemStatusStatus; 6821 GSM_FileSystemStatusStatus;
6654 char FolderName[256]; 6822 char FolderName[256];
6655 6823
6656 GSM_Init(true); 6824 GSM_Init(true);
6657 6825
6658 while (1) { 6826 while (1) {
6659 error = Phone->GetNextFileFolder(&s,&Files,Start); 6827 error = Phone->GetNextFileFolder(&s,&Files,Start);
6660 if (error == ERR_EMPTY) break; 6828 if (error == ERR_EMPTY) break;
6661 Print_Error(error); 6829 Print_Error(error);
6662 6830
6663 if (argc <= 2 || !mystrncasecmp(argv[2],"-flatall",0)) { 6831 if (argc <= 2 || !mystrncasecmp(argv[2],"-flatall",0)) {
6664 if (strlen(Files.ID_FullName) < 5 && strlen(Files.ID_FullName) != 0) { 6832 if (strlen(Files.ID_FullName) < 5 && strlen(Files.ID_FullName) != 0) {
6665 printf("%5s.",Files.ID_FullName); 6833 printf("%5s.",Files.ID_FullName);
6666 } 6834 }
6667 if (Files.Protected) { 6835 if (Files.Protected) {
6668 printf("P"); 6836 printf("P");
6669 } else { 6837 } else {
6670 printf(" "); 6838 printf(" ");
6671 } 6839 }
6672 if (Files.ReadOnly) { 6840 if (Files.ReadOnly) {
6673 printf("R"); 6841 printf("R");
6674 } else { 6842 } else {
6675 printf(" "); 6843 printf(" ");
6676 } 6844 }
6677 if (Files.Hidden) { 6845 if (Files.Hidden) {
6678 printf("H"); 6846 printf("H");
6679 } else { 6847 } else {
6680 printf(" "); 6848 printf(" ");
6681 } 6849 }
6682 if (Files.System) { 6850 if (Files.System) {
6683 printf("S"); 6851 printf("S");
6684 } else { 6852 } else {
6685 printf(" "); 6853 printf(" ");
6686 } 6854 }
6687 if (argc > 2 && mystrncasecmp(argv[2],"-flat",0)) { 6855 if (argc > 2 && mystrncasecmp(argv[2],"-flat",0)) {
6688 if (!Files.Folder) { 6856 if (!Files.Folder) {
6689 if (mystrncasecmp(argv[2],"-flatall",0)) { 6857 if (mystrncasecmp(argv[2],"-flatall",0)) {
6690 if (!Files.ModifiedEmpty) { 6858 if (!Files.ModifiedEmpty) {
6691 printf(" %30s",OSDateTime(Files.Modified,false)); 6859 printf(" %30s",OSDateTime(Files.Modified,false));
6692 } else printf(" %30c",0x20); 6860 } else printf(" %30c",0x20);
6693 printf(" %9i",Files.Used); 6861 printf(" %9i",Files.Used);
6694 printf(" "); 6862 printf(" ");
6695 } else printf("|-- "); 6863 } else printf("|-- ");
6696 } else printf("Folder "); 6864 } else printf("Folder ");
6697 } else { 6865 } else {
6698 if (Files.Level != 1) { 6866 if (Files.Level != 1) {
6699 for (j=0;j<Files.Level-2;j++) printf(" | "); 6867 for (j=0;j<Files.Level-2;j++) printf(" | ");
6700 printf(" |-- "); 6868 printf(" |-- ");
6701 } 6869 }
6702 if (Files.Folder) printf("Folder "); 6870 if (Files.Folder) printf("Folder ");
6703 } 6871 }
6704 printf("\"%s\"",DecodeUnicodeConsole(Files.Name)); 6872 printf("\"%s\"",DecodeUnicodeConsole(Files.Name));
6705 printf("\n");
6706
6707 Start = false;
6708 } else if (argc > 2 && mystrncasecmp(argv[2],"-flatall",0)) { 6873 } else if (argc > 2 && mystrncasecmp(argv[2],"-flatall",0)) {
6709 /* format for a folder ID;Folder;FOLDER_NAME;[FOLDER_PARAMETERS] 6874 /* format for a folder ID;Folder;FOLDER_NAME;[FOLDER_PARAMETERS]
6710 * format for a file ID;File;FOLDER_NAME;FILE_NAME;DATESTAMP;FILE_SIZE;[FILE_PARAMETERS] */ 6875 * format for a file ID;File;FOLDER_NAME;FILE_NAME;DATESTAMP;FILE_SIZE;[FILE_PARAMETERS] */
6711 if (!Files.Folder) { 6876 if (!Files.Folder) {
6712 printf("%s;File;",Files.ID_FullName); 6877 printf("%s;File;",Files.ID_FullName);
6713 printf("\"%s\";",FolderName); 6878 printf("\"%s\";",FolderName);
6714 printf("\"%s\";",DecodeUnicodeConsole(Files.Name)); 6879 printf("\"%s\";",DecodeUnicodeConsole(Files.Name));
6715 if (!Files.ModifiedEmpty) { 6880 if (!Files.ModifiedEmpty) {
6716 printf("\"%s\";",OSDateTime(Files.Modified,false)); 6881 printf("\"%s\";",OSDateTime(Files.Modified,false));
6717 } else printf("\"%c\";",0x20); 6882 } else printf("\"%c\";",0x20);
6718 printf("%i;",Files.Used); 6883 printf("%i;",Files.Used);
6719 } else { 6884 } else {
6720 printf("%s;Folder;",Files.ID_FullName); 6885 printf("%s;Folder;",Files.ID_FullName);
6721 printf("\"%s\";",DecodeUnicodeConsole(Files.Name)); 6886 printf("\"%s\";",DecodeUnicodeConsole(Files.Name));
6722 strcpy(FolderName,DecodeUnicodeConsole(Files.Name)); 6887 strcpy(FolderName,DecodeUnicodeConsole(Files.Name));
6723 } 6888 }
6724 6889
6725 if (Files.Protected) printf("P"); 6890 if (Files.Protected) printf("P");
6726 if (Files.ReadOnly) printf("R"); 6891 if (Files.ReadOnly) printf("R");
6727 if (Files.Hidden) printf("H"); 6892 if (Files.Hidden) printf("H");
6728 if (Files.System) printf("S"); 6893 if (Files.System) printf("S");
6729
6730 printf("\n");
6731
6732 Start = false;
6733 } 6894 }
6895 Start = false;
6734 } 6896 }
6735 6897
6736 error = Phone->GetFileSystemStatus(&s,&Status); 6898 error = Phone->GetFileSystemStatus(&s,&Status);
6737 if (error != ERR_NOTSUPPORTED && error != ERR_NOTIMPLEMENTED) { 6899 if (error != ERR_NOTSUPPORTED && error != ERR_NOTIMPLEMENTED) {
6738 Print_Error(error); 6900 Print_Error(error);
6739 printmsg("\nFree memory: %i, total memory: %i\n",Status.Free,Status.Free+Status.Used); 6901 printmsg("\nFree memory: %i, total memory: %i\n",Status.Free,Status.Free+Status.Used);
6740 } 6902 }
6741 6903
6742 GSM_Terminate(); 6904 GSM_Terminate();
6743} 6905}
6744 6906
6745static void GetOneFile(GSM_File *File, bool newtime, int i) 6907static void GetOneFile(GSM_File *File, bool newtime, int i)
6746{ 6908{
6747 FILE *file; 6909 FILE *file;
6748 bool start; 6910 bool start;
6749 unsigned char buffer[5000]; 6911 unsigned char buffer[5000];
6750 struct utimbuf filedate; 6912 struct utimbuf filedate;
6751 6913
6752 if (File->Buffer != NULL) { 6914 if (File->Buffer != NULL) {
6753 free(File->Buffer); 6915 free(File->Buffer);
6754 File->Buffer = NULL; 6916 File->Buffer = NULL;
6755 } 6917 }
6756 File->Used = 0; 6918 File->Used = 0;
6757 start = true; 6919 start = true;
6758 6920
6759 error = ERR_NONE; 6921 error = ERR_NONE;
6760 while (error == ERR_NONE) { 6922 while (error == ERR_NONE) {
6761 error = Phone->GetFilePart(&s,File); 6923 error = Phone->GetFilePart(&s,File);
6762 if (error == ERR_NONE || error == ERR_EMPTY || error == ERR_WRONGCRC) { 6924 if (error == ERR_NONE || error == ERR_EMPTY || error == ERR_WRONGCRC) {
6763 if (start) { 6925 if (start) {
6764 printmsg("Getting \"%s\": ", DecodeUnicodeConsole(File->Name)); 6926 printmsg("Getting \"%s\": ", DecodeUnicodeConsole(File->Name));
6765 start = false; 6927 start = false;
6766 } 6928 }
6767 if (File->Folder) { 6929 if (File->Folder) {
6768 free(File->Buffer); 6930 free(File->Buffer);
6769 GSM_Terminate(); 6931 GSM_Terminate();
6770 printmsg("it's folder. Please give only file names\n"); 6932 printmsg("it's folder. Please give only file names\n");
6771 exit(-1); 6933 exit(-1);
6772 } 6934 }
6773 printmsg("*"); 6935 printmsg("*");
6774 if (error == ERR_EMPTY) break; 6936 if (error == ERR_EMPTY) break;
6775 if (error == ERR_WRONGCRC) { 6937 if (error == ERR_WRONGCRC) {
6776 printmsg("WARNING: File checksum calculated by phone doesn't match with value calculated by Gammu. File damaged or error in Gammu\n"); 6938 printmsg("WARNING: File checksum calculated by phone doesn't match with value calculated by Gammu. File damaged or error in Gammu\n");
6777 break; 6939 break;
6778 } 6940 }
6779 } 6941 }
6780 Print_Error(error); 6942 Print_Error(error);
6781 } 6943 }
6782 printf("\n"); 6944 printf("\n");
6783 if (File->Used != 0) { 6945 if (File->Used != 0) {
6784 sprintf(buffer,"%s",DecodeUnicodeConsole(File->Name)); 6946 sprintf(buffer,"%s",DecodeUnicodeConsole(File->Name));
6785 file = fopen(buffer,"wb"); 6947 file = fopen(buffer,"wb");
6786 if (file == NULL) { 6948 if (file == NULL) {
6787 sprintf(buffer,"file%s",File->ID_FullName); 6949 sprintf(buffer,"file%s",File->ID_FullName);
6788 file = fopen(buffer,"wb"); 6950 file = fopen(buffer,"wb");
6789 } 6951 }
6790 if (file == NULL) { 6952 if (file == NULL) {
6791 sprintf(buffer,"file%i",i); 6953 sprintf(buffer,"file%i",i);
6792 file = fopen(buffer,"wb"); 6954 file = fopen(buffer,"wb");
6793 } 6955 }
6794 printmsg(" Saving to %s\n",buffer); 6956 printmsg(" Saving to %s\n",buffer);
6795 if (!file) Print_Error(ERR_CANTOPENFILE); 6957 if (!file) Print_Error(ERR_CANTOPENFILE);
6796 fwrite(File->Buffer,1,File->Used,file); 6958 fwrite(File->Buffer,1,File->Used,file);
6797 fclose(file); 6959 fclose(file);
6798 if (!newtime && !File->ModifiedEmpty) { 6960 if (!newtime && !File->ModifiedEmpty) {
6799 /* access time */ 6961 /* access time */
6800 filedate.actime = Fill_Time_T(File->Modified, 8); 6962 filedate.actime = Fill_Time_T(File->Modified, 8);
6801 /* modification time */ 6963 /* modification time */
6802 filedate.modtime = Fill_Time_T(File->Modified, 8); 6964 filedate.modtime = Fill_Time_T(File->Modified, 8);
6803 dbgprintf("Setting date of %s\n",buffer); 6965 dbgprintf("Setting date of %s\n",buffer);
6804 utime(buffer,&filedate); 6966 utime(buffer,&filedate);
6805 } 6967 }
6806 } 6968 }
6807} 6969}
6808 6970
6809static void GetFiles(int argc, char *argv[]) 6971static void GetFiles(int argc, char *argv[])
6810{ 6972{
6811 GSM_File File; 6973 GSM_File File;
6812 int i; 6974 int i;
6813 bool newtime = false; 6975 bool newtime = false;
6814 6976
6815 File.Buffer = NULL; 6977 File.Buffer = NULL;
6816 6978
6817 GSM_Init(true); 6979 GSM_Init(true);
6818 6980
6819 for (i=2;i<argc;i++) { 6981 for (i=2;i<argc;i++) {
6820 if (mystrncasecmp(argv[i],"-newtime",0)) { 6982 if (mystrncasecmp(argv[i],"-newtime",0)) {
6821 newtime = true; 6983 newtime = true;
6822 continue; 6984 continue;
6823 } 6985 }
6824 6986
6825 strcpy(File.ID_FullName,argv[i]); 6987 strcpy(File.ID_FullName,argv[i]);
6826 GetOneFile(&File, newtime, i); 6988 GetOneFile(&File, newtime, i);
6827 } 6989 }
6828 6990
6829 free(File.Buffer); 6991 free(File.Buffer);
6830 GSM_Terminate(); 6992 GSM_Terminate();
6831} 6993}
6832 6994
6833static void GetFileFolder(int argc, char *argv[]) 6995static void GetFileFolder(int argc, char *argv[])
6834{ 6996{
6835 bool Start = true; 6997 bool Start = true;
6836 GSM_File File; 6998 GSM_File File;
6837 int level=0,allnum=0,num=0,filelevel=0; 6999 int level=0,allnum=0,num=0,filelevel=0;
6838 bool newtime = false, found; 7000 bool newtime = false, found;
6839 7001
6840 File.Buffer = NULL; 7002 File.Buffer = NULL;
6841 7003
6842 GSM_Init(true); 7004 GSM_Init(true);
6843 7005
6844 for (i=2;i<argc;i++) { 7006 for (i=2;i<argc;i++) {
6845 if (mystrncasecmp(argv[i],"-newtime",0)) { 7007 if (mystrncasecmp(argv[i],"-newtime",0)) {
6846 newtime = true; 7008 newtime = true;
6847 continue; 7009 continue;
6848 } 7010 }
6849 allnum++; 7011 allnum++;
6850 } 7012 }
6851 7013
6852 while (allnum != num) { 7014 while (allnum != num) {
6853 error = Phone->GetNextFileFolder(&s,&File,Start); 7015 error = Phone->GetNextFileFolder(&s,&File,Start);
6854 if (error == ERR_EMPTY) break; 7016 if (error == ERR_EMPTY) break;
6855 Print_Error(error); 7017 Print_Error(error);
6856 7018
6857 if (level == 0) { 7019 if (level == 0) {
6858 /* We search for file or folder */ 7020 /* We search for file or folder */
6859 found = false; 7021 found = false;
6860 for (i=2;i<argc;i++) { 7022 for (i=2;i<argc;i++) {
6861 if (mystrncasecmp(argv[i],"-newtime",0)) { 7023 if (mystrncasecmp(argv[i],"-newtime",0)) {
6862 continue; 7024 continue;
6863 } 7025 }
6864 if (!strcmp(File.ID_FullName,argv[i])) { 7026 if (!strcmp(File.ID_FullName,argv[i])) {
6865 found = true; 7027 found = true;
6866 if (File.Folder) { 7028 if (File.Folder) {
6867 level = 1; 7029 level = 1;
6868 filelevel = File.Level + 1; 7030 filelevel = File.Level + 1;
6869 Start = false; 7031 Start = false;
6870 } else { 7032 } else {
6871 level = 2; 7033 level = 2;
6872 } 7034 }
6873 break; 7035 break;
6874 } 7036 }
6875 } 7037 }
6876 if (found && File.Folder) continue; 7038 if (found && File.Folder) continue;
6877 } 7039 }
6878 if (level == 1) { 7040 if (level == 1) {
6879 /* We have folder */ 7041 /* We have folder */
6880 dbgprintf("%i %i\n",File.Level,filelevel); 7042 dbgprintf("%i %i\n",File.Level,filelevel);
6881 if (File.Level != filelevel) { 7043 if (File.Level != filelevel) {
6882 level = 0; 7044 level = 0;
6883 num++; 7045 num++;
6884 } 7046 }
6885 } 7047 }
6886 7048
6887 if (level != 0 && !File.Folder) GetOneFile(&File, newtime,num); 7049 if (level != 0 && !File.Folder) GetOneFile(&File, newtime,num);
6888 7050
6889 if (level == 2) { 7051 if (level == 2) {
6890 level = 0; 7052 level = 0;
6891 num++; 7053 num++;
6892 } 7054 }
6893 7055
6894 Start = false; 7056 Start = false;
6895 } 7057 }
6896 7058
6897 free(File.Buffer); 7059 free(File.Buffer);
6898 GSM_Terminate(); 7060 GSM_Terminate();
6899} 7061}
6900 7062
6901static void AddFile(int argc, char *argv[]) 7063static void AddFile(int argc, char *argv[])
6902{ 7064{
6903 GSM_File File; 7065 GSM_File File;
6904 int Pos = 0,i,nextlong; 7066 int Pos = 0,i,nextlong;
6905 7067
6906 File.Buffer = NULL; 7068 File.Buffer = NULL;
6907 strcpy(File.ID_FullName,argv[2]); 7069 strcpy(File.ID_FullName,argv[2]);
6908 error = GSM_ReadFile(argv[3], &File); 7070 error = GSM_ReadFile(argv[3], &File);
6909 Print_Error(error); 7071 Print_Error(error);
6910 EncodeUnicode(File.Name,argv[3],strlen(argv[3])); 7072 EncodeUnicode(File.Name,argv[3],strlen(argv[3]));
6911 GSM_IdentifyFileFormat(&File); 7073 GSM_IdentifyFileFormat(&File);
6912 7074
6913 File.Protected = false; 7075 File.Protected = false;
6914 File.ReadOnly= false; 7076 File.ReadOnly= false;
6915 File.Hidden= false; 7077 File.Hidden= false;
6916 File.System= false; 7078 File.System= false;
6917 7079
6918 if (argc > 4) { 7080 if (argc > 4) {
6919 nextlong = 0; 7081 nextlong = 0;
6920 for (i=4;i<argc;i++) { 7082 for (i=4;i<argc;i++) {
6921 switch(nextlong) { 7083 switch(nextlong) {
6922 case 0: 7084 case 0:
6923 if (mystrncasecmp(argv[i],"-type",0)) { 7085 if (mystrncasecmp(argv[i],"-type",0)) {
6924 nextlong = 1; 7086 nextlong = 1;
6925 continue; 7087 continue;
6926 } 7088 }
6927 if (mystrncasecmp(argv[i],"-protected",0)) { 7089 if (mystrncasecmp(argv[i],"-protected",0)) {
6928 File.Protected = true; 7090 File.Protected = true;
6929 continue; 7091 continue;
6930 } 7092 }
6931 if (mystrncasecmp(argv[i],"-readonly",0)) { 7093 if (mystrncasecmp(argv[i],"-readonly",0)) {
6932 File.ReadOnly = true; 7094 File.ReadOnly = true;
6933 continue; 7095 continue;
6934 } 7096 }
6935 if (mystrncasecmp(argv[i],"-hidden",0)) { 7097 if (mystrncasecmp(argv[i],"-hidden",0)) {
6936 File.Hidden = true; 7098 File.Hidden = true;
6937 continue; 7099 continue;
6938 } 7100 }
6939 if (mystrncasecmp(argv[i],"-system",0)) { 7101 if (mystrncasecmp(argv[i],"-system",0)) {
6940 File.System = true; 7102 File.System = true;
6941 continue; 7103 continue;
6942 } 7104 }
6943 if (mystrncasecmp(argv[i],"-newtime",0)) { 7105 if (mystrncasecmp(argv[i],"-newtime",0)) {
6944 File.ModifiedEmpty = true; 7106 File.ModifiedEmpty = true;
6945 continue; 7107 continue;
6946 } 7108 }
6947 printmsg("Parameter \"%s\" unknown\n",argv[i]); 7109 printmsg("Parameter \"%s\" unknown\n",argv[i]);
6948 exit(-1); 7110 exit(-1);
6949 case 1: 7111 case 1:
6950 if (mystrncasecmp(argv[i],"JAR",0)) { 7112 if (mystrncasecmp(argv[i],"JAR",0)) {
6951 File.Type = GSM_File_Java_JAR; 7113 File.Type = GSM_File_Java_JAR;
6952 } else if (mystrncasecmp(argv[i],"JPG",0)) { 7114 } else if (mystrncasecmp(argv[i],"JPG",0)) {
6953 File.Type = GSM_File_Image_JPG; 7115 File.Type = GSM_File_Image_JPG;
6954 } else if (mystrncasecmp(argv[i],"BMP",0)) { 7116 } else if (mystrncasecmp(argv[i],"BMP",0)) {
6955 File.Type = GSM_File_Image_BMP; 7117 File.Type = GSM_File_Image_BMP;
6956 } else if (mystrncasecmp(argv[i],"WBMP",0)) { 7118 } else if (mystrncasecmp(argv[i],"WBMP",0)) {
6957 File.Type = GSM_File_Image_WBMP; 7119 File.Type = GSM_File_Image_WBMP;
6958 } else if (mystrncasecmp(argv[i],"GIF",0)) { 7120 } else if (mystrncasecmp(argv[i],"GIF",0)) {
6959 File.Type = GSM_File_Image_GIF; 7121 File.Type = GSM_File_Image_GIF;
6960 } else if (mystrncasecmp(argv[i],"PNG",0)) { 7122 } else if (mystrncasecmp(argv[i],"PNG",0)) {
6961 File.Type = GSM_File_Image_PNG; 7123 File.Type = GSM_File_Image_PNG;
6962 } else if (mystrncasecmp(argv[i],"MIDI",0)) { 7124 } else if (mystrncasecmp(argv[i],"MIDI",0)) {
6963 File.Type = GSM_File_Sound_MIDI; 7125 File.Type = GSM_File_Sound_MIDI;
6964 } else if (mystrncasecmp(argv[i],"AMR",0)) { 7126 } else if (mystrncasecmp(argv[i],"AMR",0)) {
6965 File.Type = GSM_File_Sound_AMR; 7127 File.Type = GSM_File_Sound_AMR;
6966 } else if (mystrncasecmp(argv[i],"NRT",0)) { 7128 } else if (mystrncasecmp(argv[i],"NRT",0)) {
6967 File.Type = GSM_File_Sound_NRT; 7129 File.Type = GSM_File_Sound_NRT;
6968 } else if (mystrncasecmp(argv[i],"3GP",0)) { 7130 } else if (mystrncasecmp(argv[i],"3GP",0)) {
6969 File.Type = GSM_File_Video_3GP; 7131 File.Type = GSM_File_Video_3GP;
6970 } else { 7132 } else {
6971 printmsg("What file type (\"%s\") ?\n",argv[i]); 7133 printmsg("What file type (\"%s\") ?\n",argv[i]);
6972 exit(-1); 7134 exit(-1);
6973 } 7135 }
6974 nextlong = 0; 7136 nextlong = 0;
6975 break; 7137 break;
6976 } 7138 }
6977 } 7139 }
6978 if (nextlong!=0) { 7140 if (nextlong!=0) {
6979 printmsg("Parameter missed...\n"); 7141 printmsg("Parameter missed...\n");
6980 exit(-1); 7142 exit(-1);
6981 } 7143 }
6982 } 7144 }
6983 7145
6984 GSM_Init(true); 7146 GSM_Init(true);
6985 7147
6986 error = ERR_NONE; 7148 error = ERR_NONE;
6987 while (error == ERR_NONE) { 7149 while (error == ERR_NONE) {
6988 error = Phone->AddFilePart(&s,&File,&Pos); 7150 error = Phone->AddFilePart(&s,&File,&Pos);
6989 if (error != ERR_EMPTY && error != ERR_WRONGCRC) Print_Error(error); 7151 if (error != ERR_EMPTY && error != ERR_WRONGCRC) Print_Error(error);
6990 printmsgerr("%cWriting: %i percent",13,Pos*100/File.Used); 7152 printmsgerr("%cWriting: %i percent",13,Pos*100/File.Used);
6991 } 7153 }
6992 printmsgerr("\n"); 7154 printmsgerr("\n");
6993 if (error == ERR_WRONGCRC) { 7155 if (error == ERR_WRONGCRC) {
6994 printmsg("WARNING: File checksum calculated by phone doesn't match with value calculated by Gammu. File damaged or error in Gammu\n"); 7156 printmsg("WARNING: File checksum calculated by phone doesn't match with value calculated by Gammu. File damaged or error in Gammu\n");
6995 } 7157 }
6996 7158
6997 free(File.Buffer); 7159 free(File.Buffer);
6998 GSM_Terminate(); 7160 GSM_Terminate();
6999} 7161}
7000 7162
7001static void AddFolder(int argc, char *argv[]) 7163static void AddFolder(int argc, char *argv[])
7002{ 7164{
7003 GSM_File File; 7165 GSM_File File;
7004 7166
7005 strcpy(File.ID_FullName,argv[2]); 7167 strcpy(File.ID_FullName,argv[2]);
7006 EncodeUnicode(File.Name,argv[3],strlen(argv[3])); 7168 EncodeUnicode(File.Name,argv[3],strlen(argv[3]));
7007 File.ReadOnly = false; 7169 File.ReadOnly = false;
7008 7170
7009 GSM_Init(true); 7171 GSM_Init(true);
7010 7172
7011 error = Phone->AddFolder(&s,&File); 7173 error = Phone->AddFolder(&s,&File);
7012 Print_Error(error); 7174 Print_Error(error);
7013 7175
7014 GSM_Terminate(); 7176 GSM_Terminate();
7015} 7177}
7016 7178
7017struct NokiaFolderInfo { 7179struct NokiaFolderInfo {
7018 char*model; 7180 char*model;
7019 char *parameter; 7181 char *parameter;
7020 char*folder; 7182 char*folder;
7021 char *level; 7183 char *level;
7022}; 7184};
7023 7185
7024static struct NokiaFolderInfo Folder[] = { 7186static struct NokiaFolderInfo Folder[] = {
7025 /* Language indepedent in DCT4 */ 7187 /* Language indepedent in DCT4 */
7026 {"", "MMSUnreadInbox", "INBOX","3"}, 7188 {"", "MMSUnreadInbox", "INBOX","3"},
7027 {"", "MMSReadInbox", "INBOX","3"}, 7189 {"", "MMSReadInbox", "INBOX","3"},
7028 {"", "MMSOutbox", "OUTBOX","3"}, 7190 {"", "MMSOutbox", "OUTBOX","3"},
7029 {"", "MMSSent", "SENT", "3"}, 7191 {"", "MMSSent", "SENT", "3"},
7030 {"", "MMSDrafts", "DRAFTS","3"}, 7192 {"", "MMSDrafts", "DRAFTS","3"},
7031 {"", "Application", "applications","3"}, 7193 {"", "Application", "applications","3"},
7032 {"", "Game", "games","3"}, 7194 {"", "Game", "games","3"},
7033 /* Language depedent in DCT4 */ 7195 /* Language depedent in DCT4 */
7034 {"", "Gallery", "Pictures","2"}, /* 3510 */ 7196 {"", "Gallery", "Pictures","2"}, /* 3510 */
7035 {"", "Gallery", "Graphics","3"}, /* 3510i */ 7197 {"", "Gallery", "Graphics","3"}, /* 3510i */
7036 {"", "Gallery", "Images","3"}, /* 6610 */ 7198 {"", "Gallery", "Images","3"}, /* 6610 */
7037 {"3510", "Gallery", "", "8"}, 7199 {"3510", "Gallery", "", "8"},
7038 {"3510i","Gallery", "", "3"}, 7200 {"3510i","Gallery", "", "3"},
7039 {"5100", "Gallery", "", "3"}, 7201 {"5100", "Gallery", "", "3"},
7040 {"6220", "Gallery", "", "5"}, 7202 {"6220", "Gallery", "", "5"},
7203 {"6610", "Gallery", "", "2"},
7204 {"7210", "Gallery", "", "2"},
7041 {"", "Tones", "Tones","3"}, 7205 {"", "Tones", "Tones","3"},
7042 {"3510i","Tones", "", "4"}, 7206 {"3510i","Tones", "", "4"},
7043 {"5100", "Tones", "", "4"}, 7207 {"5100", "Tones", "", "4"},
7044 {"6220", "Tones", "", "6"}, 7208 {"6220", "Tones", "", "6"},
7209 {"6610", "Tones", "", "4"},
7210 {"7210", "Tones", "", "4"},
7045 /* Language indepedent in OBEX */ 7211 /* Language indepedent in OBEX */
7046 {"obex", "MMSUnreadInbox", "", "predefMessages\\predefINBOX"}, 7212 {"obex", "MMSUnreadInbox", "", "predefMessages\\predefINBOX"},
7047 {"obex", "MMSReadInbox", "", "predefMessages\\predefINBOX"}, 7213 {"obex", "MMSReadInbox", "", "predefMessages\\predefINBOX"},
7048 {"obex", "MMSOutbox", "", "predefMessages\\predefOUTBOX"}, 7214 {"obex", "MMSOutbox", "", "predefMessages\\predefOUTBOX"},
7049 {"obex", "MMSSent", "", "predefMessages\\predefSENT" }, 7215 {"obex", "MMSSent", "", "predefMessages\\predefSENT" },
7050 {"obex", "MMSDrafts", "", "predefMessages\\predefDRAFTS"}, 7216 {"obex", "MMSDrafts", "", "predefMessages\\predefDRAFTS"},
7051 // {"obex", "Application, "", "predefjava\\predefapplications"}, 7217 // {"obex", "Application, "", "predefjava\\predefapplications"},
7052 // {"obex", "Game", "", "predefjava\\predefgames"}, 7218 // {"obex", "Game", "", "predefjava\\predefgames"},
7053 {"obex", "Gallery", "", "predefgallery\\predefgraphics"}, 7219 {"obex", "Gallery", "", "predefgallery\\predefgraphics"},
7054 {"obex", "Tones", "", "predefgallery\\predeftones"}, 7220 {"obex", "Tones", "", "predefgallery\\predeftones"},
7055 7221
7056 /* End of list */ 7222 /* End of list */
7057 {"", "", "", ""} 7223 {"", "", "", ""}
7058}; 7224};
7059 7225
7060static void NokiaAddFile(int argc, char *argv[]) 7226static void NokiaAddFile(int argc, char *argv[])
7061{ 7227{
7062 GSM_File File, Files; 7228 GSM_File File, Files;
7063 FILE *file; 7229 FILE *file;
7064 GSM_DateTime DT,DT2; 7230 GSM_DateTime DT,DT2;
7065 time_t t_time1,t_time2; 7231 time_t t_time1,t_time2;
7066 unsigned char buffer[10000],JAR[500],Vendor[500],Name[500],Version[500],FileID[400]; 7232 unsigned char buffer[10000],JAR[500],Vendor[500],Name[500],Version[500],FileID[400];
7067 bool Start = true, Found = false, wasclr; 7233 bool Start = true, Found = false, wasclr;
7068 bool ModEmpty = false; 7234 bool ModEmpty = false;
7069 int i = 0, Pos, Size, Size2, nextlong; 7235 int i = 0, Pos, Size, Size2, nextlong;
7070 7236
7071 while (Folder[i].level[0] != 0) { 7237 while (Folder[i].level[0] != 0) {
7072 if (mystrncasecmp(argv[2],Folder[i].parameter,0)) { 7238 if (mystrncasecmp(argv[2],Folder[i].parameter,0)) {
7073 Found = true; 7239 Found = true;
7074 break; 7240 break;
7075 } 7241 }
7076 i++; 7242 i++;
7077 } 7243 }
7078 if (!Found) { 7244 if (!Found) {
7079 printmsg("What folder type (\"%s\") ?\n",argv[2]); 7245 printmsg("What folder type (\"%s\") ?\n",argv[2]);
7080 exit(-1); 7246 exit(-1);
7081 } 7247 }
7082 7248
7083 GSM_Init(true); 7249 GSM_Init(true);
7084 7250
7085 if (s.ConnectionType == GCT_IRDAOBEX || s.ConnectionType == GCT_BLUEOBEX) { 7251 if (s.ConnectionType == GCT_IRDAOBEX || s.ConnectionType == GCT_BLUEOBEX) {
7086 Found = false; 7252 Found = false;
7087 i = 0; 7253 i = 0;
7088 while (Folder[i].level[0] != 0) { 7254 while (Folder[i].level[0] != 0) {
7089 if (!strcmp("obex",Folder[i].model) && 7255 if (!strcmp("obex",Folder[i].model) &&
7090 mystrncasecmp(argv[2],Folder[i].parameter,0)) { 7256 mystrncasecmp(argv[2],Folder[i].parameter,0)) {
7091 strcpy(Files.ID_FullName,Folder[i].level); 7257 strcpy(Files.ID_FullName,Folder[i].level);
7092 Found = true; 7258 Found = true;
7093 break; 7259 break;
7094 } 7260 }
7095 i++; 7261 i++;
7096 } 7262 }
7097 } else { 7263 } else {
7098 printmsgerr("Searching for phone folder: "); 7264 printmsgerr("Searching for phone folder: ");
7099 while (1) { 7265 while (1) {
7100 error = Phone->GetNextFileFolder(&s,&Files,Start); 7266 error = Phone->GetNextFileFolder(&s,&Files,Start);
7101 if (error == ERR_EMPTY) break; 7267 if (error == ERR_EMPTY) break;
7102 Print_Error(error); 7268 Print_Error(error);
7103 7269
7104 if (Files.Folder) { 7270 if (Files.Folder) {
7105 dbgprintf("folder %s level %i\n",DecodeUnicodeConsole(Files.Name),Files.Level); 7271 dbgprintf("folder %s level %i\n",DecodeUnicodeConsole(Files.Name),Files.Level);
7106 Found = false; 7272 Found = false;
7107 i = 0; 7273 i = 0;
7108 while (Folder[i].level[0] != 0) { 7274 while (Folder[i].level[0] != 0) {
7109 EncodeUnicode(buffer,Folder[i].folder,strlen(Folder[i].folder)); 7275 EncodeUnicode(buffer,Folder[i].folder,strlen(Folder[i].folder));
7110 dbgprintf("comparing \"%s\" \"%s\" \"%s\"\n",s.Phone.Data.ModelInfo->model,Files.ID_FullName,Folder[i].level); 7276 dbgprintf("comparing \"%s\" \"%s\" \"%s\"\n",s.Phone.Data.ModelInfo->model,Files.ID_FullName,Folder[i].level);
7111 if (mystrncasecmp(argv[2],Folder[i].parameter,0) && 7277 if (mystrncasecmp(argv[2],Folder[i].parameter,0) &&
7112 mywstrncasecmp(Files.Name,buffer,0) && 7278 mywstrncasecmp(Files.Name,buffer,0) &&
7113 Files.Level == atoi(Folder[i].level)) { 7279 Files.Level == atoi(Folder[i].level)) {
7114 Found = true; 7280 Found = true;
7115 break; 7281 break;
7116 } 7282 }
7117 if (!strcmp(s.Phone.Data.ModelInfo->model,Folder[i].model) && 7283 if (!strcmp(s.Phone.Data.ModelInfo->model,Folder[i].model) &&
7118 mystrncasecmp(argv[2],Folder[i].parameter,0) && 7284 mystrncasecmp(argv[2],Folder[i].parameter,0) &&
7119 !strcmp(Files.ID_FullName,Folder[i].level)) { 7285 !strcmp(Files.ID_FullName,Folder[i].level)) {
7120 Found = true; 7286 Found = true;
7121 break; 7287 break;
7122 } 7288 }
7123 i++; 7289 i++;
7124 } 7290 }
7125 if (Found) break; 7291 if (Found) break;
7126 } 7292 }
7127 printmsgerr("*"); 7293 printmsgerr("*");
7128 7294
7129 Start = false; 7295 Start = false;
7130 } 7296 }
7131 printmsgerr("\n"); 7297 printmsgerr("\n");
7132 } 7298 }
7133 if (!Found) { 7299 if (!Found) {
7134 printmsg("Folder not found. Probably function not supported !\n"); 7300 printmsg("Folder not found. Probably function not supported !\n");
7135 GSM_Terminate(); 7301 GSM_Terminate();
7136 exit(-1); 7302 exit(-1);
7137 } 7303 }
7138 File.Buffer = NULL; 7304 File.Buffer = NULL;
7139 File.Protected = false; 7305 File.Protected = false;
7140 File.ReadOnly = false; 7306 File.ReadOnly = false;
7141 File.Hidden= false; 7307 File.Hidden= false;
7142 File.System= false; 7308 File.System= false;
7143 7309
7144 if (mystrncasecmp(argv[2],"Application",0) || mystrncasecmp(argv[2],"Game",0)) { 7310 if (mystrncasecmp(argv[2],"Application",0) || mystrncasecmp(argv[2],"Game",0)) {
7145 sprintf(buffer,"%s.jad",argv[3]); 7311 sprintf(buffer,"%s.jad",argv[3]);
7146 file = fopen(buffer,"rb"); 7312 file = fopen(buffer,"rb");
7147 if (file == NULL) Print_Error(ERR_CANTOPENFILE); 7313 if (file == NULL) Print_Error(ERR_CANTOPENFILE);
7148 fclose(file); 7314 fclose(file);
7149 sprintf(buffer,"%s.jar",argv[3]); 7315 sprintf(buffer,"%s.jar",argv[3]);
7150 file = fopen(buffer,"rb"); 7316 file = fopen(buffer,"rb");
7151 if (file == NULL) Print_Error(ERR_CANTOPENFILE); 7317 if (file == NULL) Print_Error(ERR_CANTOPENFILE);
7152 fclose(file); 7318 fclose(file);
7153 7319
7154 /* reading jar file */ 7320 /* reading jar file */
7155 sprintf(buffer,"%s.jar",argv[3]); 7321 sprintf(buffer,"%s.jar",argv[3]);
7156 error = GSM_ReadFile(buffer, &File); 7322 error = GSM_ReadFile(buffer, &File);
7157 Print_Error(error); 7323 Print_Error(error);
7158 Size2 = File.Used; 7324 Size2 = File.Used;
7159 7325
7160 /* reading jad file */ 7326 /* reading jad file */
7161 sprintf(buffer,"%s.jad",argv[3]); 7327 sprintf(buffer,"%s.jad",argv[3]);
7162 error = GSM_ReadFile(buffer, &File); 7328 error = GSM_ReadFile(buffer, &File);
7163 Print_Error(error); 7329 Print_Error(error);
7164 7330
7165 /* Getting values from JAD file */ 7331 /* Getting values from JAD file */
7166 error = GSM_JADFindData(File, Vendor, Name, JAR, Version, &Size); 7332 error = GSM_JADFindData(File, Vendor, Name, JAR, Version, &Size);
7167 if (error == ERR_FILENOTSUPPORTED) { 7333 if (error == ERR_FILENOTSUPPORTED) {
7168 if (Vendor[0] == 0x00) { 7334 if (Vendor[0] == 0x00) {
7169 printmsgerr("No vendor info in JAD file\n"); 7335 printmsgerr("No vendor info in JAD file\n");
7170 GSM_Terminate(); 7336 GSM_Terminate();
7171 return; 7337 return;
7172 } 7338 }
7173 if (Name[0] == 0x00) { 7339 if (Name[0] == 0x00) {
7174 printmsgerr("No name info in JAD file\n"); 7340 printmsgerr("No name info in JAD file\n");
7175 GSM_Terminate(); 7341 GSM_Terminate();
7176 return; 7342 return;
7177 } 7343 }
7178 if (JAR[0] == 0x00) { 7344 if (JAR[0] == 0x00) {
7179 printmsgerr("No JAR URL info in JAD file\n"); 7345 printmsgerr("No JAR URL info in JAD file\n");
7180 GSM_Terminate(); 7346 GSM_Terminate();
7181 return; 7347 return;
7182 } 7348 }
7183 if (Size == -1) { 7349 if (Size == -1) {
7184 printmsgerr("No JAR size info in JAD file\n"); 7350 printmsgerr("No JAR size info in JAD file\n");
7185 GSM_Terminate(); 7351 GSM_Terminate();
7186 return; 7352 return;
7187 } 7353 }
7188 } 7354 }
7189 if (Size != Size2) { 7355 if (Size != Size2) {
7190 printmsgerr("Declared JAR file size is different than real\n"); 7356 printmsgerr("Declared JAR file size is different than real\n");
7191 GSM_Terminate(); 7357 GSM_Terminate();
7192 return; 7358 return;
7193 } 7359 }
7194 printmsgerr("Adding \"%s\"",Name); 7360 printmsgerr("Adding \"%s\"",Name);
7195 if (Version[0] != 0x00) printmsgerr(" version %s",Version); 7361 if (Version[0] != 0x00) printmsgerr(" version %s",Version);
7196 printmsgerr(" created by %s\n",Vendor); 7362 printmsgerr(" created by %s\n",Vendor);
7197 7363
7198 /* Bostjan Muller 3200 RH-30 3.08 */ 7364 /* Bostjan Muller 3200 RH-30 3.08 */
7199 if (strstr(JAR,"http://") != NULL) { 7365 if (strstr(JAR,"http://") != NULL) {
7200 i = strlen(JAR)-1; 7366 i = strlen(JAR)-1;
7201 while (JAR[i] != '/') i--; 7367 while (JAR[i] != '/') i--;
7202 strcpy(buffer,JAR+i+1); 7368 strcpy(buffer,JAR+i+1);
7203 strcpy(JAR,buffer); 7369 strcpy(JAR,buffer);
7204 dbgprintf("New file name is \"%s\"\n",JAR); 7370 dbgprintf("New file name is \"%s\"\n",JAR);
7205 } 7371 }
7206 7372
7207 /* Changing all #13 or #10 to #13#10 in JAD */ 7373 /* Changing all #13 or #10 to #13#10 in JAD */
7208 Pos = 0; 7374 Pos = 0;
7209 wasclr = false; 7375 wasclr = false;
7210 for (i=0;i<File.Used;i++) { 7376 for (i=0;i<File.Used;i++) {
7211 switch (File.Buffer[i]) { 7377 switch (File.Buffer[i]) {
7212 case 0x0D: 7378 case 0x0D:
7213 case 0x0A: 7379 case 0x0A:
7214 if (!wasclr) { 7380 if (!wasclr) {
7215 buffer[Pos++] = 0x0D; 7381 buffer[Pos++] = 0x0D;
7216 buffer[Pos++] = 0x0A; 7382 buffer[Pos++] = 0x0A;
7217 wasclr = true; 7383 wasclr = true;
7218 } else wasclr = false; 7384 } else wasclr = false;
7219 break; 7385 break;
7220 default: 7386 default:
7221 buffer[Pos++] = File.Buffer[i]; 7387 buffer[Pos++] = File.Buffer[i];
7222 wasclr = false; 7388 wasclr = false;
7223 } 7389 }
7224 } 7390 }
7225 File.Buffer = realloc(File.Buffer, Pos); 7391 File.Buffer = realloc(File.Buffer, Pos);
7226 File.Used = Pos; 7392 File.Used = Pos;
7227 memcpy(File.Buffer,buffer,Pos); 7393 memcpy(File.Buffer,buffer,Pos);
7228 7394
7229 /* adding folder */ 7395 /* adding folder */
7230 strcpy(buffer,Vendor); 7396 strcpy(buffer,Vendor);
7231 strcat(buffer,Name); 7397 strcat(buffer,Name);
7232 EncodeUnicode(File.Name,buffer,strlen(buffer)); 7398 EncodeUnicode(File.Name,buffer,strlen(buffer));
7233 strcpy(File.ID_FullName,Files.ID_FullName); 7399 strcpy(File.ID_FullName,Files.ID_FullName);
7234 error = Phone->AddFolder(&s,&File); 7400 error = Phone->AddFolder(&s,&File);
7235 Print_Error(error); 7401 Print_Error(error);
7236 strcpy(FileID,File.ID_FullName); 7402 strcpy(FileID,File.ID_FullName);
@@ -7369,1064 +7535,1000 @@ static void NokiaAddFile(int argc, char *argv[])
7369 error = GSM_ReadFile(argv[3], &File); 7535 error = GSM_ReadFile(argv[3], &File);
7370 Print_Error(error); 7536 Print_Error(error);
7371 if (ModEmpty) File.ModifiedEmpty = true; 7537 if (ModEmpty) File.ModifiedEmpty = true;
7372 7538
7373 strcpy(File.ID_FullName,Files.ID_FullName); 7539 strcpy(File.ID_FullName,Files.ID_FullName);
7374 EncodeUnicode(File.Name,buffer,strlen(buffer)); 7540 EncodeUnicode(File.Name,buffer,strlen(buffer));
7375 GSM_IdentifyFileFormat(&File); 7541 GSM_IdentifyFileFormat(&File);
7376#ifdef DEVELOP 7542#ifdef DEVELOP
7377 if (mystrncasecmp(argv[2],"Gallery",0) || mystrncasecmp(argv[2],"Tones",0)) { 7543 if (mystrncasecmp(argv[2],"Gallery",0) || mystrncasecmp(argv[2],"Tones",0)) {
7378 } else { /* MMS things */ 7544 } else { /* MMS things */
7379 File.Type = GSM_File_MMS; 7545 File.Type = GSM_File_MMS;
7380 } 7546 }
7381#endif 7547#endif
7382 7548
7383 dbgprintf("Adding file to filesystem now\n"); 7549 dbgprintf("Adding file to filesystem now\n");
7384 error = ERR_NONE; 7550 error = ERR_NONE;
7385 Pos= 0; 7551 Pos= 0;
7386 while (error == ERR_NONE) { 7552 while (error == ERR_NONE) {
7387 error = Phone->AddFilePart(&s,&File,&Pos); 7553 error = Phone->AddFilePart(&s,&File,&Pos);
7388 if (error != ERR_EMPTY && error != ERR_WRONGCRC) Print_Error(error); 7554 if (error != ERR_EMPTY && error != ERR_WRONGCRC) Print_Error(error);
7389 if (File.Used != 0) printmsgerr("%cWriting file: %i percent",13,Pos*100/File.Used); 7555 if (File.Used != 0) printmsgerr("%cWriting file: %i percent",13,Pos*100/File.Used);
7390 } 7556 }
7391 printmsgerr("\n"); 7557 printmsgerr("\n");
7392 if (error == ERR_WRONGCRC) { 7558 if (error == ERR_WRONGCRC) {
7393 printmsg("WARNING: File checksum calculated by phone doesn't match with value calculated by Gammu. File damaged or error in Gammu\n"); 7559 printmsg("WARNING: File checksum calculated by phone doesn't match with value calculated by Gammu. File damaged or error in Gammu\n");
7394 } 7560 }
7395 7561
7396 free(File.Buffer); 7562 free(File.Buffer);
7397 GSM_Terminate(); 7563 GSM_Terminate();
7398} 7564}
7399 7565
7400static void DeleteFiles(int argc, char *argv[]) 7566static void DeleteFiles(int argc, char *argv[])
7401{ 7567{
7402 int i; 7568 int i;
7403 7569
7404 GSM_Init(true); 7570 GSM_Init(true);
7405 7571
7406 for (i=2;i<argc;i++) { 7572 for (i=2;i<argc;i++) {
7407 error = Phone->DeleteFile(&s,argv[i]); 7573 error = Phone->DeleteFile(&s,argv[i]);
7408 Print_Error(error); 7574 Print_Error(error);
7409 } 7575 }
7410 7576
7411 GSM_Terminate(); 7577 GSM_Terminate();
7412} 7578}
7413 7579
7414static void SaveMMSFile(int argc, char *argv[]) 7580static void SaveMMSFile(int argc, char *argv[])
7415{ 7581{
7416 FILE *file; 7582 FILE *file;
7417 unsigned char Buffer[50000],Buffer2[20][2010]; 7583 unsigned char Buffer[50000],Buffer2[20][2010];
7418 int i,nextlong = 0,len = 0; 7584 int i,nextlong = 0,len = 0;
7419 GSM_EncodeMultiPartMMSInfo Info; 7585 GSM_EncodeMultiPartMMSInfo Info;
7420 7586
7421 GSM_ClearMultiPartMMSInfo(&Info); 7587 GSM_ClearMultiPartMMSInfo(&Info);
7422 7588
7423 for (i=3;i<argc;i++) { 7589 for (i=3;i<argc;i++) {
7424 switch (nextlong) { 7590 switch (nextlong) {
7425 case 0: 7591 case 0:
7426 if (mystrncasecmp(argv[i],"-subject",0)) { 7592 if (mystrncasecmp(argv[i],"-subject",0)) {
7427 nextlong=1; 7593 nextlong=1;
7428 continue; 7594 continue;
7429 } 7595 }
7430 if (mystrncasecmp(argv[i],"-text",0)) { 7596 if (mystrncasecmp(argv[i],"-text",0)) {
7431 nextlong=2; 7597 nextlong=2;
7432 continue; 7598 continue;
7433 } 7599 }
7434 if (mystrncasecmp(argv[i],"-from",0)) { 7600 if (mystrncasecmp(argv[i],"-from",0)) {
7435 nextlong=3; 7601 nextlong=3;
7436 continue; 7602 continue;
7437 } 7603 }
7438 if (mystrncasecmp(argv[i],"-to",0)) { 7604 if (mystrncasecmp(argv[i],"-to",0)) {
7439 nextlong=4; 7605 nextlong=4;
7440 continue; 7606 continue;
7441 } 7607 }
7442 printmsg("Unknown parameter (\"%s\")\n",argv[i]); 7608 printmsg("Unknown parameter (\"%s\")\n",argv[i]);
7443 exit(-1); 7609 exit(-1);
7444 break; 7610 break;
7445 case 1: /* Subject */ 7611 case 1: /* Subject */
7446 EncodeUnicode(Info.Subject,argv[i],strlen(argv[i])); 7612 EncodeUnicode(Info.Subject,argv[i],strlen(argv[i]));
7447 nextlong = 0; 7613 nextlong = 0;
7448 break; 7614 break;
7449 case 2: /* Text */ 7615 case 2: /* Text */
7450 EncodeUnicode(Buffer2[Info.EntriesNum],argv[i],strlen(argv[i])); 7616 EncodeUnicode(Buffer2[Info.EntriesNum],argv[i],strlen(argv[i]));
7451 Info.Entries[Info.EntriesNum].ID = MMS_Text; 7617 Info.Entries[Info.EntriesNum].ID = MMS_Text;
7452 Info.Entries[Info.EntriesNum].Buffer = Buffer2[Info.EntriesNum]; 7618 Info.Entries[Info.EntriesNum].Buffer = Buffer2[Info.EntriesNum];
7453 Info.EntriesNum++; 7619 Info.EntriesNum++;
7454 nextlong = 0; 7620 nextlong = 0;
7455 break; 7621 break;
7456 case 3: /* From */ 7622 case 3: /* From */
7457 EncodeUnicode(Info.Source,argv[i],strlen(argv[i])); 7623 EncodeUnicode(Info.Source,argv[i],strlen(argv[i]));
7458 nextlong = 0; 7624 nextlong = 0;
7459 break; 7625 break;
7460 case 4: /* To */ 7626 case 4: /* To */
7461 EncodeUnicode(Info.Destination,argv[i],strlen(argv[i])); 7627 EncodeUnicode(Info.Destination,argv[i],strlen(argv[i]));
7462 nextlong = 0; 7628 nextlong = 0;
7463 break; 7629 break;
7464 } 7630 }
7465 } 7631 }
7466 if (nextlong!=0) { 7632 if (nextlong!=0) {
7467 printmsg("Parameter missed...\n"); 7633 printmsg("Parameter missed...\n");
7468 exit(-1); 7634 exit(-1);
7469 } 7635 }
7470 7636
7471 GSM_EncodeMMSFile(&Info,Buffer,&len); 7637 GSM_EncodeMMSFile(&Info,Buffer,&len);
7472 7638
7473 file = fopen(argv[2],"wb"); 7639 file = fopen(argv[2],"wb");
7474 if (file == NULL) Print_Error(ERR_CANTOPENFILE); 7640 if (file == NULL) Print_Error(ERR_CANTOPENFILE);
7475 fwrite(Buffer,1,len,file); 7641 fwrite(Buffer,1,len,file);
7476 fclose(file); 7642 fclose(file);
7477} 7643}
7478 7644
7479static void CallDivert(int argc, char *argv[]) 7645static void CallDivert(int argc, char *argv[])
7480{ 7646{
7481 GSM_MultiCallDivert cd; 7647 GSM_MultiCallDivert cd;
7482 7648
7483 if (mystrncasecmp("get",argv[2],0)) {} 7649 if (mystrncasecmp("get",argv[2],0)) {}
7484 else if (mystrncasecmp("set",argv[2],0)) {} 7650 else if (mystrncasecmp("set",argv[2],0)) {}
7485 else { 7651 else {
7486 printmsg("Unknown divert action (\"%s\")\n",argv[2]); 7652 printmsg("Unknown divert action (\"%s\")\n",argv[2]);
7487 exit(-1); 7653 exit(-1);
7488 } 7654 }
7489 7655
7490 if (mystrncasecmp("all" , argv[3],0)) {cd.Request.DivertType = GSM_DIVERT_AllTypes ;} 7656 if (mystrncasecmp("all" , argv[3],0)) {cd.Request.DivertType = GSM_DIVERT_AllTypes ;}
7491 else if (mystrncasecmp("busy" , argv[3],0)) {cd.Request.DivertType = GSM_DIVERT_Busy ;} 7657 else if (mystrncasecmp("busy" , argv[3],0)) {cd.Request.DivertType = GSM_DIVERT_Busy ;}
7492 else if (mystrncasecmp("noans" , argv[3],0)) {cd.Request.DivertType = GSM_DIVERT_NoAnswer ;} 7658 else if (mystrncasecmp("noans" , argv[3],0)) {cd.Request.DivertType = GSM_DIVERT_NoAnswer ;}
7493 else if (mystrncasecmp("outofreach", argv[3],0)) {cd.Request.DivertType = GSM_DIVERT_OutOfReach;} 7659 else if (mystrncasecmp("outofreach", argv[3],0)) {cd.Request.DivertType = GSM_DIVERT_OutOfReach;}
7494 else { 7660 else {
7495 printmsg("Unknown divert type (\"%s\")\n",argv[3]); 7661 printmsg("Unknown divert type (\"%s\")\n",argv[3]);
7496 exit(-1); 7662 exit(-1);
7497 } 7663 }
7498 7664
7499 if (mystrncasecmp("all" , argv[4],0)) {cd.Request.CallType = GSM_DIVERT_AllCalls ;} 7665 if (mystrncasecmp("all" , argv[4],0)) {cd.Request.CallType = GSM_DIVERT_AllCalls ;}
7500 else if (mystrncasecmp("voice", argv[4],0)) {cd.Request.CallType = GSM_DIVERT_VoiceCalls;} 7666 else if (mystrncasecmp("voice", argv[4],0)) {cd.Request.CallType = GSM_DIVERT_VoiceCalls;}
7501 else if (mystrncasecmp("fax" , argv[4],0)) {cd.Request.CallType = GSM_DIVERT_FaxCalls ;} 7667 else if (mystrncasecmp("fax" , argv[4],0)) {cd.Request.CallType = GSM_DIVERT_FaxCalls ;}
7502 else if (mystrncasecmp("data" , argv[4],0)) {cd.Request.CallType = GSM_DIVERT_DataCalls ;} 7668 else if (mystrncasecmp("data" , argv[4],0)) {cd.Request.CallType = GSM_DIVERT_DataCalls ;}
7503 else { 7669 else {
7504 printmsg("Unknown call type (\"%s\")\n",argv[4]); 7670 printmsg("Unknown call type (\"%s\")\n",argv[4]);
7505 exit(-1); 7671 exit(-1);
7506 } 7672 }
7507 7673
7508 GSM_Init(true); 7674 GSM_Init(true);
7509 7675
7510 if (mystrncasecmp("get", argv[2],0)) { 7676 if (mystrncasecmp("get", argv[2],0)) {
7511 error = Phone->GetCallDivert(&s,&cd); 7677 error = Phone->GetCallDivert(&s,&cd);
7512 Print_Error(error); 7678 Print_Error(error);
7513 printmsg("Query:\n Divert type: "); 7679 printmsg("Query:\n Divert type: ");
7514 } else { 7680 } else {
7515 cd.Request.Number[0] = 0; 7681 cd.Request.Number[0] = 0;
7516 cd.Request.Number[1] = 0; 7682 cd.Request.Number[1] = 0;
7517 if (argc > 5) EncodeUnicode(cd.Request.Number,argv[5],strlen(argv[5])); 7683 if (argc > 5) EncodeUnicode(cd.Request.Number,argv[5],strlen(argv[5]));
7518 7684
7519 cd.Request.Timeout = 0; 7685 cd.Request.Timeout = 0;
7520 if (argc > 6) cd.Request.Timeout = atoi(argv[6]); 7686 if (argc > 6) cd.Request.Timeout = atoi(argv[6]);
7521 7687
7522 error = Phone->SetCallDivert(&s,&cd); 7688 error = Phone->SetCallDivert(&s,&cd);
7523 Print_Error(error); 7689 Print_Error(error);
7524 printmsg("Changed:\n Divert type: "); 7690 printmsg("Changed:\n Divert type: ");
7525 } 7691 }
7526 7692
7527 switch (cd.Request.DivertType) { 7693 switch (cd.Request.DivertType) {
7528 case GSM_DIVERT_Busy : printmsg("when busy"); break; 7694 case GSM_DIVERT_Busy : printmsg("when busy"); break;
7529 case GSM_DIVERT_NoAnswer : printmsg("when not answered"); break; 7695 case GSM_DIVERT_NoAnswer : printmsg("when not answered"); break;
7530 case GSM_DIVERT_OutOfReach: printmsg("when phone off or no coverage");break; 7696 case GSM_DIVERT_OutOfReach: printmsg("when phone off or no coverage");break;
7531 case GSM_DIVERT_AllTypes : printmsg("all types of diverts"); break; 7697 case GSM_DIVERT_AllTypes : printmsg("all types of diverts"); break;
7532 default : printmsg("unknown %i",cd.Request.DivertType); break; 7698 default : printmsg("unknown %i",cd.Request.DivertType); break;
7533 } 7699 }
7534 printmsg("\n Calls type : "); 7700 printmsg("\n Calls type : ");
7535 switch (cd.Request.CallType) { 7701 switch (cd.Request.CallType) {
7536 case GSM_DIVERT_VoiceCalls: printmsg("voice"); break; 7702 case GSM_DIVERT_VoiceCalls: printmsg("voice"); break;
7537 case GSM_DIVERT_FaxCalls : printmsg("fax"); break; 7703 case GSM_DIVERT_FaxCalls : printmsg("fax"); break;
7538 case GSM_DIVERT_DataCalls : printmsg("data"); break; 7704 case GSM_DIVERT_DataCalls : printmsg("data"); break;
7539 case GSM_DIVERT_AllCalls : printmsg("data & fax & voice"); break; 7705 case GSM_DIVERT_AllCalls : printmsg("data & fax & voice"); break;
7540 default : printmsg("unknown %i",cd.Request.CallType); break; 7706 default : printmsg("unknown %i",cd.Request.CallType); break;
7541 } 7707 }
7542 printmsg("\nResponse:"); 7708 printmsg("\nResponse:");
7543 7709
7544 for (i=0;i<cd.Response.EntriesNum;i++) { 7710 for (i=0;i<cd.Response.EntriesNum;i++) {
7545 printmsg("\n Calls type : "); 7711 printmsg("\n Calls type : ");
7546 switch (cd.Response.Entries[i].CallType) { 7712 switch (cd.Response.Entries[i].CallType) {
7547 case GSM_DIVERT_VoiceCalls: printmsg("voice"); break; 7713 case GSM_DIVERT_VoiceCalls: printmsg("voice"); break;
7548 case GSM_DIVERT_FaxCalls : printmsg("fax"); break; 7714 case GSM_DIVERT_FaxCalls : printmsg("fax"); break;
7549 case GSM_DIVERT_DataCalls : printmsg("data"); break; 7715 case GSM_DIVERT_DataCalls : printmsg("data"); break;
7550 default : printmsg("unknown %i",cd.Response.Entries[i].CallType);break; 7716 default : printmsg("unknown %i",cd.Response.Entries[i].CallType);break;
7551 } 7717 }
7552 printf("\n"); 7718 printf("\n");
7553 printmsg(" Timeout : %i seconds\n",cd.Response.Entries[i].Timeout); 7719 printmsg(" Timeout : %i seconds\n",cd.Response.Entries[i].Timeout);
7554 printmsg(" Number : %s\n",DecodeUnicodeString(cd.Response.Entries[i].Number)); 7720 printmsg(" Number : %s\n",DecodeUnicodeString(cd.Response.Entries[i].Number));
7555 } 7721 }
7556 printf("\n"); 7722 printf("\n");
7557 7723
7558 GSM_Terminate(); 7724 GSM_Terminate();
7559} 7725}
7560 7726
7561
7562//#if 0
7563static void CancelAllDiverts(int argc, char *argv[]) 7727static void CancelAllDiverts(int argc, char *argv[])
7564{ 7728{
7565 GSM_Init(true); 7729 GSM_Init(true);
7566 7730
7567 error = Phone->CancelAllDiverts(&s); 7731 error = Phone->CancelAllDiverts(&s);
7568 Print_Error(error); 7732 Print_Error(error);
7569 7733
7570 GSM_Terminate(); 7734 GSM_Terminate();
7571} 7735}
7572 7736
7737typedef struct {
7738 unsigned char Connection[50];
7739} OneConnectionInfo;
7573 7740
7741typedef struct {
7742 unsigned char Device[50];
7743 OneConnectionInfo Connections[4];
7744} OneDeviceInfo;
7745
7746 int num;
7747 bool SearchOutput;
7574 7748
7575void SearchPhoneThread(OneDeviceInfo *Info) 7749void SearchPhoneThread(OneDeviceInfo *Info)
7576{ 7750{
7751 //LR
7752#if 0
7577 int j; 7753 int j;
7578 GSM_Error error; 7754 GSM_Error error;
7579 fprintf(stderr,"*********************************** \n"); 7755 GSM_StateMachiness;
7580 fprintf(stderr,"*********************************** \n"); 7756
7581 fprintf(stderr,"*********************************** \n");
7582 fprintf(stderr,"*********************************** \n");
7583 fprintf(stderr,"*********************************** \n");
7584#if 0
7585 j = 0; 7757 j = 0;
7586 while(strlen(Info->Connections[j].Connection) != 0) { 7758 while(strlen(Info->Connections[j].Connection) != 0) {
7587 memcpy(&Info->s.di,&s.di,sizeof(Debug_Info)); 7759 memcpy(&ss.di,&s.di,sizeof(Debug_Info));
7588 Info->s.msg = s.msg; 7760 ss.msg = s.msg;
7589 Info->s.ConfigNum = 1; 7761 ss.ConfigNum = 1;
7590 Info->s.opened = false; 7762 ss.opened = false;
7591 Info->s.Config[0].UseGlobalDebugFile = s.Config[0].UseGlobalDebugFile; 7763 ss.Config[0].UseGlobalDebugFile = s.Config[0].UseGlobalDebugFile;
7592 Info->s.Config[0].Localize = s.Config[0].Localize; 7764 ss.Config[0].Localize = s.Config[0].Localize;
7593 Info->s.Config[0].Device = Info->Device; 7765 ss.Config[0].Device = Info->Device;
7594 Info->s.Config[0].Connection = Info->Connections[j].Connection; 7766 ss.Config[0].Connection = Info->Connections[j].Connection;
7595 Info->s.Config[0].SyncTime = "no"; 7767 ss.Config[0].SyncTime = "no";
7596 Info->s.Config[0].DebugFile = s.Config[0].DebugFile; 7768 ss.Config[0].DebugFile = s.Config[0].DebugFile;
7597 Info->s.Config[0].Model[0] = 0; 7769 ss.Config[0].Model[0] = 0;
7598 strcpy(Info->s.Config[0].DebugLevel,s.Config[0].DebugLevel); 7770 strcpy(ss.Config[0].DebugLevel,s.Config[0].DebugLevel);
7599 Info->s.Config[0].LockDevice = "no"; 7771 ss.Config[0].LockDevice = "no";
7600 Info->s.Config[0].StartInfo = "no"; 7772 ss.Config[0].StartInfo = "no";
7601 7773
7602 error = GSM_InitConnection(&Info->s,1); 7774 error = GSM_InitConnection(&ss,1);
7603 if (SearchOutput) printf("Connection \"%s\" on device \"%s\"\n",Info->Connections[j].Connection,Info->Device); 7775 if (SearchOutput) printf("Connection \"%s\" on device \"%s\"\n",Info->Connections[j].Connection,Info->Device);
7604 if (error == ERR_NONE) { 7776 if (error == ERR_NONE) {
7605 error=Info->s.Phone.Functions->GetManufacturer(&Info->s); 7777 error=ss.Phone.Functions->GetManufacturer(&ss);
7606 if (error == ERR_NONE) { 7778 if (error == ERR_NONE) {
7607 error=Info->s.Phone.Functions->GetModel(&Info->s); 7779 error=ss.Phone.Functions->GetModel(&ss);
7608 if (error == ERR_NONE) { 7780 if (error == ERR_NONE) {
7609 if (!SearchOutput) printf("Connection \"%s\" on device \"%s\"\n",Info->Connections[j].Connection,Info->Device); 7781 if (!SearchOutput) printf("Connection \"%s\" on device \"%s\"\n",Info->Connections[j].Connection,Info->Device);
7610 printmsg(" Manufacturer : %s\n", 7782 printmsg(" Manufacturer : %s\n",
7611 Info->s.Phone.Data.Manufacturer); 7783 ss.Phone.Data.Manufacturer);
7612 printmsg(" Model : %s (%s)\n", 7784 printmsg(" Model : %s (%s)\n",
7613 Info->s.Phone.Data.ModelInfo->model, 7785 ss.Phone.Data.ModelInfo->model,
7614 Info->s.Phone.Data.Model); 7786 ss.Phone.Data.Model);
7615 } else { 7787 } else {
7616 if (SearchOutput) printf(" %s\n",print_error(error,Info->s.di.df,Info->s.msg)); 7788 if (SearchOutput) printf(" %s\n",print_error(error,ss.di.df,ss.msg));
7617 } 7789 }
7618 } else { 7790 } else {
7619 if (SearchOutput) printf(" %s\n",print_error(error,Info->s.di.df,Info->s.msg)); 7791 if (SearchOutput) printf(" %s\n",print_error(error,ss.di.df,ss.msg));
7620 } 7792 }
7621 } else { 7793 } else {
7622 if (SearchOutput) printf(" %s\n",print_error(error,Info->s.di.df,Info->s.msg)); 7794 if (SearchOutput) printf(" %s\n",print_error(error,ss.di.df,ss.msg));
7623 } 7795 }
7624 if (error != ERR_DEVICEOPENERROR) { 7796 if (error != ERR_DEVICEOPENERROR) {
7625 GSM_TerminateConnection(&Info->s); 7797 GSM_TerminateConnection(&ss);
7626 dbgprintf("Closing done\n"); 7798 dbgprintf("Closing done\n");
7627 } 7799 }
7628 if (error == ERR_DEVICEOPENERROR || error == ERR_NONE) break; 7800 if (error == ERR_DEVICEOPENERROR) break;
7629 j++; 7801 j++;
7630 } 7802 }
7631 num--; 7803 num--;
7632#endif 7804#endif
7633} 7805}
7634 7806
7635//#undef HAVE_PTHREAD
7636//#if 0
7637#if defined(WIN32) || defined(HAVE_PTHREAD) 7807#if defined(WIN32) || defined(HAVE_PTHREAD)
7638#ifdef HAVE_PTHREAD 7808#ifdef HAVE_PTHREAD
7639 pthread_t Thread[100]; 7809 pthread_t Thread[100];
7640#endif 7810#endif
7641 7811
7812OneDeviceInfo SearchDevices[60];
7813
7642void MakeSearchThread(int i) 7814void MakeSearchThread(int i)
7643{ 7815{
7644 num++; 7816 num++;
7645#ifdef HAVE_PTHREAD 7817#ifdef HAVE_PTHREAD
7646 if (pthread_create(&Thread[i],NULL,(void *)SearchPhoneThread,&SearchDevices[i])!=0) { 7818 if (pthread_create(&Thread[i],NULL,(void *)SearchPhoneThread,&SearchDevices[i])!=0) {
7647 dbgprintf("Error creating thread\n"); 7819 dbgprintf("Error creating thread\n");
7648 } 7820 }
7649#else 7821#else
7650 if (CreateThread((LPSECURITY_ATTRIBUTES)NULL,0, 7822 if (CreateThread((LPSECURITY_ATTRIBUTES)NULL,0,
7651 (LPTHREAD_START_ROUTINE)SearchPhoneThread,&SearchDevices[i], 7823 (LPTHREAD_START_ROUTINE)SearchPhoneThread,&SearchDevices[i],
7652 0,NULL)==NULL) { 7824 0,NULL)==NULL) {
7653 dbgprintf("Error creating thread\n"); 7825 dbgprintf("Error creating thread\n");
7654 } 7826 }
7655#endif 7827#endif
7656} 7828}
7657 7829
7658static void SearchPhone(int argc, char *argv[]) 7830static void SearchPhone(int argc, char *argv[])
7659{ 7831{
7660 int i,dev = 0, dev2 = 0; 7832 int i,dev = 0, dev2 = 0;
7661 7833
7662 SearchOutput = false; 7834 SearchOutput = false;
7663 if (argc == 3 && mystrncasecmp(argv[2], "-debug",0)) SearchOutput = true; 7835 if (argc == 3 && mystrncasecmp(argv[2], "-debug",0)) SearchOutput = true;
7664 7836
7665 num = 0; 7837 num = 0;
7666#ifdef WIN32 7838#ifdef WIN32
7667# ifdef GSM_ENABLE_IRDADEVICE 7839# ifdef GSM_ENABLE_IRDADEVICE
7668 sprintf(SearchDevices[dev].Device,""); 7840 sprintf(SearchDevices[dev].Device,"");
7669 sprintf(SearchDevices[dev].Connections[0].Connection,"irdaphonet"); 7841 sprintf(SearchDevices[dev].Connections[0].Connection,"irdaphonet");
7670 SearchDevices[dev].Connections[1].Connection[0] = 0; 7842 sprintf(SearchDevices[dev].Connections[1].Connection,"irdaat");
7843 SearchDevices[dev].Connections[2].Connection[0] = 0;
7671 dev++; 7844 dev++;
7672# endif 7845# endif
7673# ifdef GSM_ENABLE_SERIALDEVICE 7846# ifdef GSM_ENABLE_SERIALDEVICE
7674 dev2 = dev; 7847 dev2 = dev;
7675 for(i=0;i<10;i++) { 7848 for(i=0;i<20;i++) {
7676 sprintf(SearchDevices[dev2].Device,"com%i:",i+1); 7849 sprintf(SearchDevices[dev2].Device,"com%i:",i+1);
7677 sprintf(SearchDevices[dev2].Connections[0].Connection,"fbusdlr3"); 7850 sprintf(SearchDevices[dev2].Connections[0].Connection,"fbusdlr3");
7678 sprintf(SearchDevices[dev2].Connections[1].Connection,"fbus"); 7851 sprintf(SearchDevices[dev2].Connections[1].Connection,"fbus");
7679 sprintf(SearchDevices[dev2].Connections[2].Connection,"at19200"); 7852 sprintf(SearchDevices[dev2].Connections[2].Connection,"at19200");
7680 sprintf(SearchDevices[dev2].Connections[3].Connection,"mbus"); 7853 sprintf(SearchDevices[dev2].Connections[3].Connection,"mbus");
7681 SearchDevices[dev2].Connections[4].Connection[0] = 0; 7854 SearchDevices[dev2].Connections[4].Connection[0] = 0;
7682 dev2++; 7855 dev2++;
7683 } 7856 }
7684# endif 7857# endif
7685#endif 7858#endif
7686#ifdef __linux__ 7859#ifdef __linux__
7687# ifdef GSM_ENABLE_IRDADEVICE 7860# ifdef GSM_ENABLE_IRDADEVICE
7688 for(i=0;i<6;i++) { 7861 for(i=0;i<6;i++) {
7689 sprintf(SearchDevices[dev].Device,"/dev/ircomm%i",i); 7862 sprintf(SearchDevices[dev].Device,"/dev/ircomm%i",i);
7690 sprintf(SearchDevices[dev].Connections[0].Connection,"irdaphonet"); 7863 sprintf(SearchDevices[dev].Connections[0].Connection,"irdaphonet");
7691 sprintf(SearchDevices[dev].Connections[1].Connection,"at19200"); 7864 sprintf(SearchDevices[dev].Connections[1].Connection,"at19200");
7692 SearchDevices[dev].Connections[2].Connection[0] = 0; 7865 SearchDevices[dev].Connections[2].Connection[0] = 0;
7693 dev++; 7866 dev++;
7694 } 7867 }
7695# endif 7868# endif
7696# ifdef GSM_ENABLE_SERIALDEVICE 7869# ifdef GSM_ENABLE_SERIALDEVICE
7697 dev2 = dev; 7870 dev2 = dev;
7698 for(i=0;i<10;i++) { 7871 for(i=0;i<10;i++) {
7699 sprintf(SearchDevices[dev2].Device,"/dev/ttyS%i",i); 7872 sprintf(SearchDevices[dev2].Device,"/dev/ttyS%i",i);
7700 sprintf(SearchDevices[dev2].Connections[0].Connection,"fbusdlr3"); 7873 sprintf(SearchDevices[dev2].Connections[0].Connection,"fbusdlr3");
7701 sprintf(SearchDevices[dev2].Connections[1].Connection,"fbus"); 7874 sprintf(SearchDevices[dev2].Connections[1].Connection,"fbus");
7702 sprintf(SearchDevices[dev2].Connections[2].Connection,"at19200"); 7875 sprintf(SearchDevices[dev2].Connections[2].Connection,"at19200");
7703 sprintf(SearchDevices[dev2].Connections[3].Connection,"mbus"); 7876 sprintf(SearchDevices[dev2].Connections[3].Connection,"mbus");
7704 SearchDevices[dev2].Connections[4].Connection[0] = 0; 7877 SearchDevices[dev2].Connections[4].Connection[0] = 0;
7705 dev2++; 7878 dev2++;
7706 } 7879 }
7707 for(i=0;i<8;i++) { 7880 for(i=0;i<8;i++) {
7708 sprintf(SearchDevices[dev2].Device,"/dev/ttyD00%i",i); 7881 sprintf(SearchDevices[dev2].Device,"/dev/ttyD00%i",i);
7709 sprintf(SearchDevices[dev2].Connections[0].Connection,"fbusdlr3"); 7882 sprintf(SearchDevices[dev2].Connections[0].Connection,"fbusdlr3");
7710 sprintf(SearchDevices[dev2].Connections[1].Connection,"fbus"); 7883 sprintf(SearchDevices[dev2].Connections[1].Connection,"fbus");
7711 sprintf(SearchDevices[dev2].Connections[2].Connection,"at19200"); 7884 sprintf(SearchDevices[dev2].Connections[2].Connection,"at19200");
7712 sprintf(SearchDevices[dev2].Connections[3].Connection,"mbus"); 7885 sprintf(SearchDevices[dev2].Connections[3].Connection,"mbus");
7713 SearchDevices[dev2].Connections[4].Connection[0] = 0; 7886 SearchDevices[dev2].Connections[4].Connection[0] = 0;
7714 dev2++; 7887 dev2++;
7715 } 7888 }
7716 for(i=0;i<4;i++) { 7889 for(i=0;i<4;i++) {
7717 sprintf(SearchDevices[dev2].Device,"/dev/usb/tts/%i",i); 7890 sprintf(SearchDevices[dev2].Device,"/dev/usb/tts/%i",i);
7718 sprintf(SearchDevices[dev2].Connections[0].Connection,"fbusdlr3"); 7891 sprintf(SearchDevices[dev2].Connections[0].Connection,"fbusdlr3");
7719 sprintf(SearchDevices[dev2].Connections[1].Connection,"fbus"); 7892 sprintf(SearchDevices[dev2].Connections[1].Connection,"fbus");
7720 sprintf(SearchDevices[dev2].Connections[2].Connection,"at19200"); 7893 sprintf(SearchDevices[dev2].Connections[2].Connection,"at19200");
7721 sprintf(SearchDevices[dev2].Connections[3].Connection,"mbus"); 7894 sprintf(SearchDevices[dev2].Connections[3].Connection,"mbus");
7722 SearchDevices[dev2].Connections[4].Connection[0] = 0; 7895 SearchDevices[dev2].Connections[4].Connection[0] = 0;
7723 dev2++; 7896 dev2++;
7724 } 7897 }
7725# endif 7898# endif
7726#endif 7899#endif
7727 for(i=0;i<dev;i++) MakeSearchThread(i); 7900 for(i=0;i<dev;i++) MakeSearchThread(i);
7728 while (num != 0) my_sleep(5); 7901 while (num != 0) my_sleep(5);
7729 for(i=dev;i<dev2;i++) MakeSearchThread(i); 7902 for(i=dev;i<dev2;i++) MakeSearchThread(i);
7730 while (num != 0) my_sleep(5); 7903 while (num != 0) my_sleep(5);
7731} 7904}
7732#endif /*Support for threads */ 7905#endif /*Support for threads */
7733// #if 0 7906
7734static void NokiaGetADC(int argc, char *argv[]) 7907static void NokiaGetADC(int argc, char *argv[])
7735{ 7908{
7736 GSM_Init(true); 7909 GSM_Init(true);
7737 7910
7738#ifdef GSM_ENABLE_NOKIA_DCT3 7911#ifdef GSM_ENABLE_NOKIA_DCT3
7739 DCT3GetADC(argc,argv); 7912 DCT3GetADC(argc,argv);
7740#endif 7913#endif
7741#ifdef GSM_ENABLE_NOKIA_DCT4 7914#ifdef GSM_ENABLE_NOKIA_DCT4
7742 DCT4GetADC(argc, argv); 7915 DCT4GetADC(argc, argv);
7743#endif 7916#endif
7744 7917
7745 GSM_Terminate(); 7918 GSM_Terminate();
7746} 7919}
7747 7920
7748static void NokiaDisplayTest(int argc, char *argv[]) 7921static void NokiaDisplayTest(int argc, char *argv[])
7749{ 7922{
7750 GSM_Init(true); 7923 GSM_Init(true);
7751 7924
7752#ifdef GSM_ENABLE_NOKIA_DCT3 7925#ifdef GSM_ENABLE_NOKIA_DCT3
7753 DCT3DisplayTest(argc,argv); 7926 DCT3DisplayTest(argc,argv);
7754#endif 7927#endif
7755#ifdef GSM_ENABLE_NOKIA_DCT4 7928#ifdef GSM_ENABLE_NOKIA_DCT4
7756 DCT4DisplayTest(argc, argv); 7929 DCT4DisplayTest(argc, argv);
7757#endif 7930#endif
7758 7931
7759 GSM_Terminate(); 7932 GSM_Terminate();
7760} 7933}
7761 7934
7762static void NokiaGetT9(int argc, char *argv[]) 7935static void NokiaGetT9(int argc, char *argv[])
7763{ 7936{
7764 GSM_Init(true); 7937 GSM_Init(true);
7765 7938
7766#ifdef GSM_ENABLE_NOKIA_DCT3 7939#ifdef GSM_ENABLE_NOKIA_DCT3
7767 DCT3GetT9(argc,argv); 7940 DCT3GetT9(argc,argv);
7768#endif 7941#endif
7769#ifdef GSM_ENABLE_NOKIA_DCT4 7942#ifdef GSM_ENABLE_NOKIA_DCT4
7770 DCT4GetT9(argc, argv); 7943 DCT4GetT9(argc, argv);
7771#endif 7944#endif
7772 7945
7773 GSM_Terminate(); 7946 GSM_Terminate();
7774} 7947}
7775 7948
7776static void NokiaVibraTest(int argc, char *argv[]) 7949static void NokiaVibraTest(int argc, char *argv[])
7777{ 7950{
7778 GSM_Init(true); 7951 GSM_Init(true);
7779 7952
7780#ifdef GSM_ENABLE_NOKIA_DCT3 7953#ifdef GSM_ENABLE_NOKIA_DCT3
7781 DCT3VibraTest(argc,argv); 7954 DCT3VibraTest(argc,argv);
7782#endif 7955#endif
7783#ifdef GSM_ENABLE_NOKIA_DCT4 7956#ifdef GSM_ENABLE_NOKIA_DCT4
7784 DCT4VibraTest(argc, argv); 7957 DCT4VibraTest(argc, argv);
7785#endif 7958#endif
7786 7959
7787 GSM_Terminate(); 7960 GSM_Terminate();
7788} 7961}
7789 7962
7790static GSM_Parameters Parameters[] = { 7963static GSM_Parameters Parameters[] = {
7791 {"--identify", 0, 0, Identify, {H_Info,0}, ""}, 7964 {"--identify", 0, 0, Identify, {H_Info,0}, ""},
7792 {"--version", 0, 0, Version, {H_Other,0}, ""}, 7965 {"--version", 0, 0, Version, {H_Other,0}, ""},
7793 {"--getdisplaystatus", 0, 0, GetDisplayStatus, {H_Info,0}, ""}, 7966 {"--getdisplaystatus", 0, 0, GetDisplayStatus, {H_Info,0}, ""},
7794 {"--monitor", 0, 1, Monitor, {H_Info,H_Network,H_Call,0},"[times]"}, 7967 {"--monitor", 0, 1, Monitor, {H_Info,H_Network,H_Call,0},"[times]"},
7795 {"--setautonetworklogin", 0, 0, SetAutoNetworkLogin, {H_Network,0}, ""}, 7968 {"--setautonetworklogin", 0, 0, SetAutoNetworkLogin, {H_Network,0}, ""},
7796 {"--listnetworks", 0, 0, ListNetworks, {H_Network,0}, ""}, 7969 {"--listnetworks", 0, 1, ListNetworks, {H_Network,0}, "[country]"},
7797 {"--getgprspoint", 1, 2, GetGPRSPoint, {H_Nokia,H_Network,0}, "start [stop]"}, 7970 {"--getgprspoint", 1, 2, GetGPRSPoint, {H_Nokia,H_Network,0}, "start [stop]"},
7798 {"--addfolder", 2, 2, AddFolder, {H_Filesystem,0}, "parentfolderID name"}, 7971 {"--addfolder", 2, 2, AddFolder, {H_Filesystem,0}, "parentfolderID name"},
7799 {"--getfilesystem", 0, 1, GetFileSystem, {H_Filesystem,0}, "[-flatall|-flat]"}, 7972 {"--getfilesystem", 0, 1, GetFileSystem, {H_Filesystem,0}, "[-flatall|-flat]"},
7800 {"--getfilesystemstatus", 0, 0, GetFileSystemStatus, {H_Filesystem,0}, ""}, 7973 {"--getfilesystemstatus", 0, 0, GetFileSystemStatus, {H_Filesystem,0}, ""},
7801 {"--getfiles", 1,40, GetFiles, {H_Filesystem,0}, "ID1, ID2, ..."}, 7974 {"--getfiles", 1,40, GetFiles, {H_Filesystem,0}, "ID1, ID2, ..."},
7802 {"--getfilefolder", 1,40, GetFileFolder, {H_Filesystem,0}, "ID1, ID2, ..."}, 7975 {"--getfilefolder", 1,40, GetFileFolder, {H_Filesystem,0}, "ID1, ID2, ..."},
7803 {"--addfile", 2, 6, AddFile, {H_Filesystem,0}, "folderID name [-type JAR|BMP|PNG|GIF|JPG|MIDI|WBMP|AMR|3GP|NRT][-readonly][-protected][-system][-hidden][-newtime]"}, 7976 {"--addfile", 2, 6, AddFile, {H_Filesystem,0}, "folderID name [-type JAR|BMP|PNG|GIF|JPG|MIDI|WBMP|AMR|3GP|NRT][-readonly][-protected][-system][-hidden][-newtime]"},
7804 {"--nokiaaddfile", 2, 5, NokiaAddFile, {H_Filesystem,H_Nokia,0},"MMSUnreadInbox|MMSReadInbox|MMSOutbox|MMSDrafts|MMSSent file sender title"}, 7977 {"--nokiaaddfile", 2, 5, NokiaAddFile, {H_Filesystem,H_Nokia,0},"MMSUnreadInbox|MMSReadInbox|MMSOutbox|MMSDrafts|MMSSent file sender title"},
7805 {"--nokiaaddfile", 2, 5, NokiaAddFile, {H_Filesystem,H_Nokia,0},"Application|Game file [-readonly]"}, 7978 {"--nokiaaddfile", 2, 5, NokiaAddFile, {H_Filesystem,H_Nokia,0},"Application|Game file [-readonly]"},
7806 {"--nokiaaddfile", 2, 5, NokiaAddFile, {H_Filesystem,H_Nokia,0},"Gallery|Tones file [-name name][-protected][-readonly][-system][-hidden][-newtime]"}, 7979 {"--nokiaaddfile", 2, 5, NokiaAddFile, {H_Filesystem,H_Nokia,0},"Gallery|Tones file [-name name][-protected][-readonly][-system][-hidden][-newtime]"},
7807 {"--deletefiles", 1,20, DeleteFiles, {H_Filesystem,0}, "fileID"}, 7980 {"--deletefiles", 1,20, DeleteFiles, {H_Filesystem,0}, "fileID"},
7808 {"--playringtone", 1, 1, PlayRingtone, {H_Ringtone,0}, "file"}, 7981 {"--playringtone", 1, 1, PlayRingtone, {H_Ringtone,0}, "file"},
7809 {"--playsavedringtone", 1, 1, DCT4PlaySavedRingtone, {H_Ringtone,0}, ""}, 7982 {"--playsavedringtone", 1, 1, DCT4PlaySavedRingtone, {H_Ringtone,0}, ""},
7810 {"--getdatetime", 0, 0, GetDateTime, {H_DateTime,0}, ""}, 7983 {"--getdatetime", 0, 0, GetDateTime, {H_DateTime,0}, ""},
7811 {"--setdatetime", 0, 0, SetDateTime, {H_DateTime,0}, ""}, 7984 {"--setdatetime", 0, 0, SetDateTime, {H_DateTime,0}, ""},
7812 {"--getalarm", 0, 0, GetAlarm, {H_DateTime,0}, ""}, 7985 {"--getalarm", 0, 0, GetAlarm, {H_DateTime,0}, ""},
7813 {"--setalarm", 2, 2, SetAlarm, {H_DateTime,0}, "hour minute"}, 7986 {"--setalarm", 2, 2, SetAlarm, {H_DateTime,0}, "hour minute"},
7814 {"--resetphonesettings", 1, 1, ResetPhoneSettings, {H_Settings,0}, "PHONE|DEV|UIF|ALL|FACTORY"}, 7987 {"--resetphonesettings", 1, 1, ResetPhoneSettings, {H_Settings,0}, "PHONE|DEV|UIF|ALL|FACTORY"},
7815 {"--getmemory", 2, 3, GetMemory, {H_Memory,0}, "DC|MC|RC|ON|VM|SM|ME|FD start [stop]"}, 7988 {"--getmemory", 2, 4, GetMemory, {H_Memory,0}, "DC|MC|RC|ON|VM|SM|ME|FD start [stop [-nonempty]]"},
7816 {"--getallmemory", 1, 1, GetAllMemory, {H_Memory,0}, "DC|MC|RC|ON|VM|SM|ME|FD"}, 7989 {"--getallmemory", 1, 2, GetAllMemory, {H_Memory,0}, "DC|MC|RC|ON|VM|SM|ME|FD"},
7817 {"--searchmemory", 1, 1, SearchMemory, {H_Memory,0}, "text"}, 7990 {"--searchmemory", 1, 1, SearchMemory, {H_Memory,0}, "text"},
7818 {"--listmemorycategory", 1, 1, ListMemoryCategory, {H_Memory, H_Category,0},"text|number"}, 7991 {"--listmemorycategory", 1, 1, ListMemoryCategory, {H_Memory, H_Category,0},"text|number"},
7819 {"--getfmstation", 1, 2, GetFMStation, {H_FM,0}, "start [stop]"}, 7992 {"--getfmstation", 1, 2, GetFMStation, {H_FM,0}, "start [stop]"},
7820 {"--getsmsc", 1, 2, GetSMSC, {H_SMS,0}, "start [stop]"}, 7993 {"--getsmsc", 1, 2, GetSMSC, {H_SMS,0}, "start [stop]"},
7821 {"--getsms", 2, 3, GetSMS, {H_SMS,0}, "folder start [stop]"}, 7994 {"--getsms", 2, 3, GetSMS, {H_SMS,0}, "folder start [stop]"},
7822 {"--deletesms", 2, 3, DeleteSMS, {H_SMS,0}, "folder start [stop]"}, 7995 {"--deletesms", 2, 3, DeleteSMS, {H_SMS,0}, "folder start [stop]"},
7823 {"--deleteallsms", 1, 1, DeleteAllSMS, {H_SMS,0}, "folder"}, 7996 {"--deleteallsms", 1, 1, DeleteAllSMS, {H_SMS,0}, "folder"},
7824 {"--getsmsfolders", 0, 0, GetSMSFolders, {H_SMS,0}, ""}, 7997 {"--getsmsfolders", 0, 0, GetSMSFolders, {H_SMS,0}, ""},
7825 {"--getallsms", 0, 0, GetAllSMS, {H_SMS,0}, ""}, 7998 {"--getallsms", 0, 0, GetAllSMS, {H_SMS,0}, ""},
7826 {"--geteachsms", 0, 0, GetEachSMS, {H_SMS,0}, ""}, 7999 {"--geteachsms", 0, 0, GetEachSMS, {H_SMS,0}, ""},
7827 8000
7828 #define SMS_TEXT_OPTIONS"[-inputunicode][-16bit][-flash][-len len][-autolen len][-unicode][-enablevoice][-disablevoice][-enablefax][-disablefax][-enableemail][-disableemail][-voidsms][-replacemessages ID][-replacefile file]" 8001 #define SMS_TEXT_OPTIONS"[-inputunicode][-16bit][-flash][-len len][-autolen len][-unicode][-enablevoice][-disablevoice][-enablefax][-disablefax][-enableemail][-disableemail][-voidsms][-replacemessages ID][-replacefile file]"
7829 #define SMS_PICTURE_OPTIONS"[-text text][-unicode][-alcatelbmmi]" 8002 #define SMS_PICTURE_OPTIONS"[-text text][-unicode][-alcatelbmmi]"
7830 #define SMS_PROFILE_OPTIONS"[-name name][-bitmap bitmap][-ringtone ringtone]" 8003 #define SMS_PROFILE_OPTIONS"[-name name][-bitmap bitmap][-ringtone ringtone]"
7831 #define SMS_EMS_OPTIONS "[-unicode][-16bit][-format lcrasbiut][-text text][-unicodefiletext file][-defsound ID][-defanimation ID][-tone10 file][-tone10long file][-tone12 file][-tone12long file][-toneSE file][-toneSElong file][-fixedbitmap file][-variablebitmap file][-variablebitmaplong file][-animation frames file1 ...][-protected number]" 8004 #define SMS_EMS_OPTIONS "[-unicode][-16bit][-format lcrasbiut][-text text][-unicodefiletext file][-defsound ID][-defanimation ID][-tone10 file][-tone10long file][-tone12 file][-tone12long file][-toneSE file][-toneSElong file][-fixedbitmap file][-variablebitmap file][-variablebitmaplong file][-animation frames file1 ...][-protected number]"
7832 #define SMS_SMSTEMPLATE_OPTIONS"[-unicode][-text text][-unicodefiletext file][-defsound ID][-defanimation ID][-tone10 file][-tone10long file][-tone12 file][-tone12long file][-toneSE file][-toneSElong file][-variablebitmap file][-variablebitmaplong file][-animation frames file1 ...]" 8005 #define SMS_SMSTEMPLATE_OPTIONS"[-unicode][-text text][-unicodefiletext file][-defsound ID][-defanimation ID][-tone10 file][-tone10long file][-tone12 file][-tone12long file][-toneSE file][-toneSElong file][-variablebitmap file][-variablebitmaplong file][-animation frames file1 ...]"
7833 #define SMS_ANIMATION_OPTIONS"" 8006 #define SMS_ANIMATION_OPTIONS""
7834 #define SMS_OPERATOR_OPTIONS"[-netcode netcode][-biglogo]" 8007 #define SMS_OPERATOR_OPTIONS"[-netcode netcode][-biglogo]"
7835 #define SMS_SAVE_OPTIONS"[-folder id][-unread][-read][-unsent][-sent][-sender number]" 8008 #define SMS_SAVE_OPTIONS"[-folder id][-unread][-read][-unsent][-sent][-sender number]"
7836 #define SMS_SEND_OPTIONS"[-report][-validity HOUR|6HOURS|DAY|3DAYS|WEEK|MAX][-save [-folder number]]" 8009 #define SMS_SEND_OPTIONS"[-report][-validity HOUR|6HOURS|DAY|3DAYS|WEEK|MAX][-save [-folder number]]"
7837 #define SMS_COMMON_OPTIONS"[-smscset number][-smscnumber number][-reply][-maxsms num]" 8010 #define SMS_COMMON_OPTIONS"[-smscset number][-smscnumber number][-reply][-maxsms num]"
7838 8011
7839 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,0}, "TEXT " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_TEXT_OPTIONS}, 8012 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,0}, "TEXT " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_TEXT_OPTIONS},
7840 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Ringtone,0}, "RINGTONE file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, 8013 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Ringtone,0}, "RINGTONE file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7841 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "OPERATOR file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_OPERATOR_OPTIONS}, 8014 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "OPERATOR file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_OPERATOR_OPTIONS},
7842 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "CALLER file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, 8015 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "CALLER file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7843 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "PICTURE file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_PICTURE_OPTIONS}, 8016 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "PICTURE file " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_PICTURE_OPTIONS},
7844 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "ANIMATION frames file1 file2... " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_ANIMATION_OPTIONS}, 8017 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "ANIMATION frames file1 file2... " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_ANIMATION_OPTIONS},
7845 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSINDICATOR URL Title Sender " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, 8018 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSINDICATOR URL Title Sender " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
8019 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPINDICATOR URL Title " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7846#ifdef GSM_ENABLE_BACKUP 8020#ifdef GSM_ENABLE_BACKUP
7847 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "BOOKMARK file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, 8021 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "BOOKMARK file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7848 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPSETTINGS file location DATA|GPRS " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, 8022 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPSETTINGS file location DATA|GPRS " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7849 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSSETTINGS file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, 8023 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSSETTINGS file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7850 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Calendar,0}, "CALENDAR file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, 8024 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Calendar,0}, "CALENDAR file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7851 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_ToDo,0}, "TODO file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, 8025 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_ToDo,0}, "TODO file location " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7852 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Memory,0}, "VCARD10|VCARD21 file SM|ME location [-nokia]" SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS}, 8026 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Memory,0}, "VCARD10|VCARD21 file SM|ME location [-nokia]" SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS},
7853#endif 8027#endif
7854 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Settings,0}, "PROFILE " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_PROFILE_OPTIONS}, 8028 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,H_Settings,0}, "PROFILE " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_PROFILE_OPTIONS},
7855 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,0}, "EMS " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_EMS_OPTIONS}, 8029 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,0}, "EMS " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_EMS_OPTIONS},
7856 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,0}, "SMSTEMPLATE " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_SMSTEMPLATE_OPTIONS}, 8030 {"--savesms", 1,30, SendSaveDisplaySMS, {H_SMS,0}, "SMSTEMPLATE " SMS_SAVE_OPTIONS SMS_COMMON_OPTIONS SMS_SMSTEMPLATE_OPTIONS},
7857 8031
7858 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,0}, "TEXT destination " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_TEXT_OPTIONS}, 8032 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,0}, "TEXT destination " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_TEXT_OPTIONS},
7859 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Ringtone,0}, "RINGTONE destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, 8033 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Ringtone,0}, "RINGTONE destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7860 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "OPERATOR destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_OPERATOR_OPTIONS}, 8034 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "OPERATOR destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_OPERATOR_OPTIONS},
7861 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "CALLER destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, 8035 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "CALLER destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7862 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "PICTURE destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_PICTURE_OPTIONS}, 8036 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "PICTURE destination file " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_PICTURE_OPTIONS},
7863 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "ANIMATION destination frames file1 file2... " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_ANIMATION_OPTIONS}, 8037 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Logo,0}, "ANIMATION destination frames file1 file2... " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_ANIMATION_OPTIONS},
7864 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSINDICATOR destination URL Title Sender " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, 8038 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSINDICATOR destination URL Title Sender " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
8039 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPINDICATOR destination URL Title " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7865#ifdef GSM_ENABLE_BACKUP 8040#ifdef GSM_ENABLE_BACKUP
7866 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "BOOKMARK destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, 8041 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "BOOKMARK destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7867 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPSETTINGS destination file location DATA|GPRS " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, 8042 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_WAP,0}, "WAPSETTINGS destination file location DATA|GPRS " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7868 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSSETTINGS destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, 8043 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_MMS,0}, "MMSSETTINGS destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7869 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Calendar,0}, "CALENDAR destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, 8044 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Calendar,0}, "CALENDAR destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7870 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_ToDo,0}, "TODO destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, 8045 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_ToDo,0}, "TODO destination file location " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7871 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Memory,0}, "VCARD10|VCARD21 destination file SM|ME location [-nokia]" SMS_SEND_OPTIONS SMS_COMMON_OPTIONS}, 8046 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Memory,0}, "VCARD10|VCARD21 destination file SM|ME location [-nokia]" SMS_SEND_OPTIONS SMS_COMMON_OPTIONS},
7872#endif 8047#endif
7873 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Settings,0}, "PROFILE destination " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS ""SMS_PROFILE_OPTIONS}, 8048 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Settings,0}, "PROFILE destination " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS ""SMS_PROFILE_OPTIONS},
7874 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,0}, "EMS destination " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_EMS_OPTIONS}, 8049 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,0}, "EMS destination " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_EMS_OPTIONS},
7875 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,0}, "SMSTEMPLATE destination " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_SMSTEMPLATE_OPTIONS}, 8050 {"--sendsms", 2,30, SendSaveDisplaySMS, {H_SMS,0}, "SMSTEMPLATE destination " SMS_SEND_OPTIONS SMS_COMMON_OPTIONS SMS_SMSTEMPLATE_OPTIONS},
7876 8051
7877 {"--displaysms", 2,30, SendSaveDisplaySMS, {H_SMS,0}, "... (options like in sendsms)"}, 8052 {"--displaysms", 2,30, SendSaveDisplaySMS, {H_SMS,0}, "... (options like in sendsms)"},
7878 8053
7879 {"--addsmsfolder", 1, 1, AddSMSFolder, {H_SMS,0}, "name"}, 8054 {"--addsmsfolder", 1, 1, AddSMSFolder, {H_SMS,0}, "name"},
7880#ifdef HAVE_MYSQL_MYSQL_H 8055#ifdef HAVE_MYSQL_MYSQL_H
7881 {"--smsd", 2, 2, SMSDaemon, {H_SMS,H_Other,0}, "MYSQL configfile"}, 8056 {"--smsd", 2, 2, SMSDaemon, {H_SMS,H_Other,0}, "MYSQL configfile"},
7882#endif 8057#endif
7883 {"--smsd", 2, 2, SMSDaemon, {H_SMS,H_Other,0}, "FILES configfile"}, 8058 {"--smsd", 2, 2, SMSDaemon, {H_SMS,H_Other,0}, "FILES configfile"},
7884 {"--sendsmsdsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Other,0}, "TEXT|WAPSETTINGS|... destination FILES|MYSQL configfile ... (options like in sendsms)"}, 8059 {"--sendsmsdsms", 2,30, SendSaveDisplaySMS, {H_SMS,H_Other,0}, "TEXT|WAPSETTINGS|... destination FILES|MYSQL configfile ... (options like in sendsms)"},
7885 {"--getringtone", 1, 2, GetRingtone, {H_Ringtone,0}, "location [file]"}, 8060 {"--getringtone", 1, 2, GetRingtone, {H_Ringtone,0}, "location [file]"},
7886 {"--getphoneringtone", 1, 2, GetRingtone, {H_Ringtone,0}, "location [file]"}, 8061 {"--getphoneringtone", 1, 2, GetRingtone, {H_Ringtone,0}, "location [file]"},
7887 {"--getringtoneslist", 0, 0, GetRingtonesList, {H_Ringtone,0}, ""}, 8062 {"--getringtoneslist", 0, 0, GetRingtonesList, {H_Ringtone,0}, ""},
7888 {"--setringtone", 1, 6, SetRingtone, {H_Ringtone,0}, "file [-location location][-scale][-name name]"}, 8063 {"--setringtone", 1, 6, SetRingtone, {H_Ringtone,0}, "file [-location location][-scale][-name name]"},
7889 {"--nokiacomposer", 1, 1, NokiaComposer, {H_Ringtone,H_Nokia,0}, "file"}, 8064 {"--nokiacomposer", 1, 1, NokiaComposer, {H_Ringtone,H_Nokia,0}, "file"},
7890 {"--copyringtone", 2, 3, CopyRingtone, {H_Ringtone,0}, "source destination [RTTL|BINARY]"}, 8065 {"--copyringtone", 2, 3, CopyRingtone, {H_Ringtone,0}, "source destination [RTTL|BINARY]"},
7891 {"--getussd", 1, 1, GetUSSD, {H_Call,0}, "code"}, 8066 {"--getussd", 1, 1, GetUSSD, {H_Call,0}, "code"},
7892 {"--dialvoice", 1, 2, DialVoice, {H_Call,0}, "number [show|hide]"}, 8067 {"--dialvoice", 1, 2, DialVoice, {H_Call,0}, "number [show|hide]"},
7893 {"--getspeeddial", 1, 2, GetSpeedDial, {H_Call,H_Memory,0}, "start [stop]"}, 8068 {"--getspeeddial", 1, 2, GetSpeedDial, {H_Call,H_Memory,0}, "start [stop]"},
7894 {"--cancelcall", 0, 1, CancelCall, {H_Call,0}, "[ID]"}, 8069 {"--cancelcall", 0, 1, CancelCall, {H_Call,0}, "[ID]"},
7895 {"--answercall", 0, 1, AnswerCall, {H_Call,0}, "[ID]"}, 8070 {"--answercall", 0, 1, AnswerCall, {H_Call,0}, "[ID]"},
7896 {"--unholdcall", 1, 1, UnholdCall, {H_Call,0}, "ID"}, 8071 {"--unholdcall", 1, 1, UnholdCall, {H_Call,0}, "ID"},
7897 {"--holdcall", 1, 1, HoldCall, {H_Call,0}, "ID"}, 8072 {"--holdcall", 1, 1, HoldCall, {H_Call,0}, "ID"},
7898 {"--conferencecall", 1, 1, ConferenceCall, {H_Call,0}, "ID"}, 8073 {"--conferencecall", 1, 1, ConferenceCall, {H_Call,0}, "ID"},
7899 {"--splitcall", 1, 1, SplitCall, {H_Call,0}, "ID"}, 8074 {"--splitcall", 1, 1, SplitCall, {H_Call,0}, "ID"},
7900 {"--switchcall", 0, 1, SwitchCall, {H_Call,0}, "[ID]"}, 8075 {"--switchcall", 0, 1, SwitchCall, {H_Call,0}, "[ID]"},
7901 {"--transfercall", 0, 1, TransferCall, {H_Call,0}, "[ID]"}, 8076 {"--transfercall", 0, 1, TransferCall, {H_Call,0}, "[ID]"},
7902 {"--divert", 3, 5, CallDivert, {H_Call,0}, "get|set all|busy|noans|outofreach all|voice|fax|data [number timeout]"}, 8077 {"--divert", 3, 5, CallDivert, {H_Call,0}, "get|set all|busy|noans|outofreach all|voice|fax|data [number timeout]"},
7903 {"--canceldiverts", 0, 0, CancelAllDiverts, {H_Call,0}, ""}, 8078 {"--canceldiverts", 0, 0, CancelAllDiverts, {H_Call,0}, ""},
7904 {"--senddtmf", 1, 1, SendDTMF, {H_Call,0}, "sequence"}, 8079 {"--senddtmf", 1, 1, SendDTMF, {H_Call,0}, "sequence"},
7905 {"--getcalendarsettings", 0, 0, GetCalendarSettings, {H_Calendar,H_Settings,0},""}, 8080 {"--getcalendarsettings", 0, 0, GetCalendarSettings, {H_Calendar,H_Settings,0},""},
7906 {"--getalltodo", 0, 0, GetAllToDo, {H_ToDo,0}, ""}, 8081 {"--getalltodo", 0, 0, GetAllToDo, {H_ToDo,0}, ""},
7907 {"--listtodocategory", 1, 1, ListToDoCategory, {H_ToDo, H_Category,0}, "text|number"}, 8082 {"--listtodocategory", 1, 1, ListToDoCategory, {H_ToDo, H_Category,0}, "text|number"},
7908 {"--gettodo", 1, 2, GetToDo, {H_ToDo,0}, "start [stop]"}, 8083 {"--gettodo", 1, 2, GetToDo, {H_ToDo,0}, "start [stop]"},
7909 {"--deletetodo", 1, 2, DeleteToDo, {H_ToDo,0}, "start [stop]"}, 8084 {"--deletetodo", 1, 2, DeleteToDo, {H_ToDo,0}, "start [stop]"},
7910 {"--getnote", 1, 2, GetNote, {H_Note,0}, "start [stop]"}, 8085 {"--getallnotes", 0, 0, GetAllNotes, {H_Note,0}, ""},
7911 {"--deletecalendar", 1, 2, DeleteCalendar, {H_Calendar,0}, "start [stop]"}, 8086 {"--deletecalendar", 1, 2, DeleteCalendar, {H_Calendar,0}, "start [stop]"},
7912 {"--getallcalendar", 0, 0, GetAllCalendar, {H_Calendar,0}, ""}, 8087 {"--getallcalendar", 0, 0, GetAllCalendar, {H_Calendar,0}, ""},
7913 {"--getcalendar", 1, 2, GetCalendar, {H_Calendar,0}, "start [stop]"}, 8088 {"--getcalendar", 1, 2, GetCalendar, {H_Calendar,0}, "start [stop]"},
7914 {"--getcategory", 2, 3, GetCategory, {H_Category,H_ToDo,H_Memory,0},"TODO|PHONEBOOK start [stop]"}, 8089 {"--getcategory", 2, 3, GetCategory, {H_Category,H_ToDo,H_Memory,0},"TODO|PHONEBOOK start [stop]"},
7915 {"--getallcategory", 1, 1, GetAllCategories, {H_Category,H_ToDo,H_Memory,0},"TODO|PHONEBOOK"}, 8090 {"--getallcategory", 1, 1, GetAllCategories, {H_Category,H_ToDo,H_Memory,0},"TODO|PHONEBOOK"},
7916 {"--reset", 1, 1, Reset, {H_Other,0}, "SOFT|HARD"}, 8091 {"--reset", 1, 1, Reset, {H_Other,0}, "SOFT|HARD"},
7917 {"--getprofile", 1, 2, GetProfile, {H_Settings,0}, "start [stop]"}, 8092 {"--getprofile", 1, 2, GetProfile, {H_Settings,0}, "start [stop]"},
7918 {"--getsecuritystatus", 0, 0, GetSecurityStatus, {H_Info,0}, ""}, 8093 {"--getsecuritystatus", 0, 0, GetSecurityStatus, {H_Info,0}, ""},
7919 {"--entersecuritycode", 2, 2, EnterSecurityCode, {H_Other,0}, "PIN|PUK|PIN2|PUK2 code"}, 8094 {"--entersecuritycode", 2, 2, EnterSecurityCode, {H_Other,0}, "PIN|PUK|PIN2|PUK2 code"},
7920 {"--deletewapbookmark", 1, 2, DeleteWAPBookmark, {H_WAP,0}, "start [stop]"}, 8095 {"--deletewapbookmark", 1, 2, DeleteWAPBookmark, {H_WAP,0}, "start [stop]"},
7921 {"--getwapbookmark", 1, 2, GetWAPBookmark, {H_WAP,0}, "start [stop]"}, 8096 {"--getwapbookmark", 1, 2, GetWAPBookmark, {H_WAP,0}, "start [stop]"},
7922 {"--getwapsettings", 1, 2, GetWAPMMSSettings, {H_WAP,0}, "start [stop]"}, 8097 {"--getwapsettings", 1, 2, GetWAPMMSSettings, {H_WAP,0}, "start [stop]"},
7923 {"--getmmssettings", 1, 2, GetWAPMMSSettings, {H_MMS,0}, "start [stop]"}, 8098 {"--getmmssettings", 1, 2, GetWAPMMSSettings, {H_MMS,0}, "start [stop]"},
7924 {"--getsyncmlsettings", 1, 2, GetSyncMLSettings, {H_WAP,0}, "start [stop]"}, 8099 {"--getsyncmlsettings", 1, 2, GetSyncMLSettings, {H_WAP,0}, "start [stop]"},
7925 {"--getchatsettings", 1, 2, GetChatSettings, {H_WAP,0}, "start [stop]"}, 8100 {"--getchatsettings", 1, 2, GetChatSettings, {H_WAP,0}, "start [stop]"},
7926 {"--savemmsfile", 3, 15,SaveMMSFile, {H_MMS,0}, "file [-subject text][-text text]"}, 8101 {"--savemmsfile", 3, 15,SaveMMSFile, {H_MMS,0}, "file [-subject text][-text text]"},
7927 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "STARTUP [file]"}, 8102 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "STARTUP [file]"},
7928 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "CALLER location [file]"}, 8103 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "CALLER location [file]"},
7929 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "OPERATOR [file]"}, 8104 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "OPERATOR [file]"},
7930 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "PICTURE location [file]"}, 8105 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "PICTURE location [file]"},
7931 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "TEXT"}, 8106 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "TEXT"},
7932 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "DEALER"}, 8107 {"--getbitmap", 1, 3, GetBitmap, {H_Logo,0}, "DEALER"},
7933 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "STARTUP file|1|2|3"}, 8108 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "STARTUP file|1|2|3"},
7934 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "COLOURSTARTUP [fileID]"}, 8109 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "COLOURSTARTUP [fileID]"},
7935 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "WALLPAPER fileID"}, 8110 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "WALLPAPER fileID"},
7936 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "CALLER location [file]"}, 8111 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "CALLER location [file]"},
7937 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "OPERATOR [file [netcode]]"}, 8112 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "OPERATOR [file [netcode]]"},
7938 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "COLOUROPERATOR [fileID [netcode]]"}, 8113 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "COLOUROPERATOR [fileID [netcode]]"},
7939 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "PICTURE file location [text]"}, 8114 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "PICTURE file location [text]"},
7940 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "TEXT text"}, 8115 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "TEXT text"},
7941 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "DEALER text"}, 8116 {"--setbitmap", 1, 4, SetBitmap, {H_Logo,0}, "DEALER text"},
7942 {"--copybitmap", 1, 3, CopyBitmap, {H_Logo,0}, "inputfile [outputfile [OPERATOR|PICTURE|STARTUP|CALLER]]"}, 8117 {"--copybitmap", 1, 3, CopyBitmap, {H_Logo,0}, "inputfile [outputfile [OPERATOR|PICTURE|STARTUP|CALLER]]"},
7943 {"--presskeysequence", 1, 1, PressKeySequence, {H_Other,0}, "mMnNpPuUdD+-123456789*0#gGrRwW"}, 8118 {"--presskeysequence", 1, 1, PressKeySequence, {H_Other,0}, "mMnNpPuUdD+-123456789*0#gGrRwW"},
7944#if defined(WIN32) || defined(HAVE_PTHREAD) 8119#if defined(WIN32) || defined(HAVE_PTHREAD)
7945 {"--searchphone", 0, 1, SearchPhone, {H_Other,0}, "[-debug]"}, 8120 {"--searchphone", 0, 1, SearchPhone, {H_Other,0}, "[-debug]"},
7946#endif 8121#endif
7947#ifdef GSM_ENABLE_BACKUP 8122#ifdef GSM_ENABLE_BACKUP
7948 {"--savefile", 4, 5, SaveFile, {H_Backup,H_Calendar,0},"CALENDAR target.vcs file location"}, 8123 {"--savefile", 4, 5, SaveFile, {H_Backup,H_Calendar,0},"CALENDAR target.vcs file location"},
7949 {"--savefile", 4, 5, SaveFile, {H_Backup,H_ToDo,0}, "TODO target.vcs file location"}, 8124 {"--savefile", 4, 5, SaveFile, {H_Backup,H_ToDo,0}, "TODO target.vcs file location"},
7950 {"--savefile", 4, 5, SaveFile, {H_Backup,H_Memory,0}, "VCARD10|VCARD21 target.vcf file SM|ME location"}, 8125 {"--savefile", 4, 5, SaveFile, {H_Backup,H_Memory,0}, "VCARD10|VCARD21 target.vcf file SM|ME location"},
7951 {"--savefile", 4, 5, SaveFile, {H_Backup,H_WAP,0}, "BOOKMARK target.url file location"}, 8126 {"--savefile", 4, 5, SaveFile, {H_Backup,H_WAP,0}, "BOOKMARK target.url file location"},
7952 {"--backup", 1, 2, Backup, {H_Backup,H_Memory,H_Calendar,H_ToDo,H_Category,H_Ringtone,H_WAP,H_FM,0}, "file [-yes]"}, 8127 {"--backup", 1, 2, Backup, {H_Backup,H_Memory,H_Calendar,H_ToDo,H_Category,H_Ringtone,H_WAP,H_FM,0}, "file [-yes]"},
7953 {"--backupsms", 1, 1, BackupSMS, {H_Backup,H_SMS,0}, "file"}, 8128 {"--backupsms", 1, 1, BackupSMS, {H_Backup,H_SMS,0}, "file"},
7954 {"--restore", 1, 1, Restore, {H_Backup,H_Memory,H_Calendar,H_ToDo,H_Category,H_Ringtone,H_WAP,H_FM,0}, "file"}, 8129 {"--restore", 1, 1, Restore, {H_Backup,H_Memory,H_Calendar,H_ToDo,H_Category,H_Ringtone,H_WAP,H_FM,0}, "file"},
7955 {"--addnew", 1, 1, AddNew, {H_Backup,H_Memory,H_Calendar,H_ToDo,H_Category,H_Ringtone,H_WAP,H_FM,0}, "file"}, 8130 {"--addnew", 1, 1, AddNew, {H_Backup,H_Memory,H_Calendar,H_ToDo,H_Category,H_Ringtone,H_WAP,H_FM,0}, "file"},
7956 {"--restoresms", 1, 1, RestoreSMS, {H_Backup,H_SMS,0}, "file"}, 8131 {"--restoresms", 1, 1, RestoreSMS, {H_Backup,H_SMS,0}, "file"},
7957 {"--addsms", 2, 2, AddSMS, {H_Backup,H_SMS,0}, "folder file"}, 8132 {"--addsms", 2, 2, AddSMS, {H_Backup,H_SMS,0}, "folder file"},
7958#endif 8133#endif
7959 {"--clearall", 0, 0, ClearAll, {H_Memory,H_Calendar,H_ToDo,H_Category,H_Ringtone,H_WAP,H_FM,0},""}, 8134 {"--clearall", 0, 0, ClearAll, {H_Memory,H_Calendar,H_ToDo,H_Category,H_Ringtone,H_WAP,H_FM,0},""},
7960 {"--networkinfo", 0, 0, NetworkInfo, {H_Network,0}, ""}, 8135 {"--networkinfo", 0, 0, NetworkInfo, {H_Network,0}, ""},
7961 #ifdef GSM_ENABLE_AT 8136 #ifdef GSM_ENABLE_AT
7962 {"--siemenssatnetmon", 0, 0, ATSIEMENSSATNetmon, {H_Siemens,H_Network,0},""}, 8137 {"--siemenssatnetmon", 0, 0, ATSIEMENSSATNetmon, {H_Siemens,H_Network,0},""},
7963 {"--siemensnetmonact", 1, 1, ATSIEMENSActivateNetmon, {H_Siemens,H_Network,0}, "netmon_type (1-full, 2-simple)"}, 8138 {"--siemensnetmonact", 1, 1, ATSIEMENSActivateNetmon, {H_Siemens,H_Network,0}, "netmon_type (1-full, 2-simple)"},
7964 {"--siemensnetmonitor", 1, 1, ATSIEMENSNetmonitor, {H_Siemens,H_Network,0},"test"}, 8139 {"--siemensnetmonitor", 1, 1, ATSIEMENSNetmonitor, {H_Siemens,H_Network,0},"test"},
7965 #endif 8140 #endif
7966#ifdef GSM_ENABLE_NOKIA6110 8141#ifdef GSM_ENABLE_NOKIA6110
7967 {"--nokiagetoperatorname", 0, 0, DCT3GetOperatorName, {H_Nokia,H_Network,0}, ""}, 8142 {"--nokiagetoperatorname", 0, 0, DCT3GetOperatorName, {H_Nokia,H_Network,0}, ""},
7968 {"--nokiasetoperatorname", 0, 2, DCT3SetOperatorName, {H_Nokia,H_Network,0}, "[networkcode name]"}, 8143 {"--nokiasetoperatorname", 0, 2, DCT3SetOperatorName, {H_Nokia,H_Network,0}, "[networkcode name]"},
7969 {"--nokiadisplayoutput", 0, 0, DCT3DisplayOutput, {H_Nokia,0}, ""}, 8144 {"--nokiadisplayoutput", 0, 0, DCT3DisplayOutput, {H_Nokia,0}, ""},
7970#endif 8145#endif
7971#ifdef GSM_ENABLE_NOKIA_DCT3 8146#ifdef GSM_ENABLE_NOKIA_DCT3
7972 {"--nokianetmonitor", 1, 1, DCT3netmonitor, {H_Nokia,H_Network,0}, "test"}, 8147 {"--nokianetmonitor", 1, 1, DCT3netmonitor, {H_Nokia,H_Network,0}, "test"},
7973 {"--nokianetmonitor36", 0, 0, DCT3ResetTest36, {H_Nokia,0}, ""}, 8148 {"--nokianetmonitor36", 0, 0, DCT3ResetTest36, {H_Nokia,0}, ""},
7974 {"--nokiadebug", 1, 2, DCT3SetDebug, {H_Nokia,H_Network,0}, "filename [[v11-22][,v33-44]...]"}, 8149 {"--nokiadebug", 1, 2, DCT3SetDebug, {H_Nokia,H_Network,0}, "filename [[v11-22][,v33-44]...]"},
7975#endif 8150#endif
7976#ifdef GSM_ENABLE_NOKIA_DCT4 8151#ifdef GSM_ENABLE_NOKIA_DCT4
7977 {"--nokiasetvibralevel", 1, 1, DCT4SetVibraLevel, {H_Nokia,H_Other,0}, "level"}, 8152 {"--nokiasetvibralevel", 1, 1, DCT4SetVibraLevel, {H_Nokia,H_Other,0}, "level"},
7978 {"--nokiagetvoicerecord", 1, 1, DCT4GetVoiceRecord, {H_Nokia,H_Other,0}, "location"}, 8153 {"--nokiagetvoicerecord", 1, 1, DCT4GetVoiceRecord, {H_Nokia,H_Other,0}, "location"},
8154#ifdef GSM_ENABLE_NOKIA6510
7979 {"--nokiasetlights", 2, 2, DCT4SetLight, {H_Nokia,H_Tests,0}, "keypad|display|torch on|off"}, 8155 {"--nokiasetlights", 2, 2, DCT4SetLight, {H_Nokia,H_Tests,0}, "keypad|display|torch on|off"},
7980 {"--nokiatuneradio", 0, 0, DCT4TuneRadio, {H_Nokia,H_FM,0}, ""}, 8156 {"--nokiatuneradio", 0, 0, DCT4TuneRadio, {H_Nokia,H_FM,0}, ""},
8157#endif
7981 {"--nokiamakecamerashoot", 0, 0, DCT4MakeCameraShoot, {H_Nokia,H_Other,0}, ""}, 8158 {"--nokiamakecamerashoot", 0, 0, DCT4MakeCameraShoot, {H_Nokia,H_Other,0}, ""},
7982 {"--nokiagetscreendump", 0, 0, DCT4GetScreenDump, {H_Nokia,H_Other,0}, ""}, 8159 {"--nokiagetscreendump", 0, 0, DCT4GetScreenDump, {H_Nokia,H_Other,0}, ""},
7983#endif 8160#endif
7984#if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4) 8161#if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4)
7985 {"--nokiavibratest", 0, 0, NokiaVibraTest, {H_Nokia,H_Tests,0}, ""}, 8162 {"--nokiavibratest", 0, 0, NokiaVibraTest, {H_Nokia,H_Tests,0}, ""},
7986 {"--nokiagett9", 0, 0, NokiaGetT9, {H_Nokia,H_SMS,0}, ""}, 8163 {"--nokiagett9", 0, 0, NokiaGetT9, {H_Nokia,H_SMS,0}, ""},
7987 {"--nokiadisplaytest", 1, 1, NokiaDisplayTest, {H_Nokia,H_Tests,0}, "number"}, 8164 {"--nokiadisplaytest", 1, 1, NokiaDisplayTest, {H_Nokia,H_Tests,0}, "number"},
7988 {"--nokiagetadc", 0, 0, NokiaGetADC, {H_Nokia,H_Tests,0}, ""}, 8165 {"--nokiagetadc", 0, 0, NokiaGetADC, {H_Nokia,H_Tests,0}, ""},
7989 {"--nokiasecuritycode", 0, 0, NokiaSecurityCode, {H_Nokia,H_Info,0}, ""}, 8166 {"--nokiasecuritycode", 0, 0, NokiaSecurityCode, {H_Nokia,H_Info,0}, ""},
7990 {"--nokiaselftests", 0, 0, NokiaSelfTests, {H_Nokia,H_Tests,0}, ""}, 8167 {"--nokiaselftests", 0, 0, NokiaSelfTests, {H_Nokia,H_Tests,0}, ""},
7991 {"--nokiasetphonemenus", 0, 0, NokiaSetPhoneMenus, {H_Nokia,H_Other,0}, ""}, 8168 {"--nokiasetphonemenus", 0, 0, NokiaSetPhoneMenus, {H_Nokia,H_Other,0}, ""},
7992#endif 8169#endif
7993#ifdef DEBUG 8170#ifdef DEBUG
7994 {"--decodesniff", 2, 3, decodesniff, {H_Decode,0}, "MBUS2|IRDA file [phonemodel]"}, 8171 {"--decodesniff", 2, 3, decodesniff, {H_Decode,0}, "MBUS2|IRDA file [phonemodel]"},
7995 {"--decodebinarydump", 1, 2, decodebinarydump, {H_Decode,0}, "file [phonemodel]"}, 8172 {"--decodebinarydump", 1, 2, decodebinarydump, {H_Decode,0}, "file [phonemodel]"},
7996 {"--makeconverttable", 1, 1, MakeConvertTable, {H_Decode,0}, "file"}, 8173 {"--makeconverttable", 1, 1, MakeConvertTable, {H_Decode,0}, "file"},
7997#endif 8174#endif
7998 {"", 0, 0, NULL } 8175 {"", 0, 0, NULL }
7999}; 8176};
8000 8177
8001static HelpCategoryDescriptions HelpDescriptions[] = { 8178static HelpCategoryDescriptions HelpDescriptions[] = {
8002 {H_Call, "call", "Calls",}, 8179 {H_Call, "call", "Calls",},
8003 {H_SMS, "sms", "SMS and EMS"}, 8180 {H_SMS, "sms", "SMS and EMS"},
8004 {H_Memory, "memory","Memory (phonebooks and calls)"}, 8181 {H_Memory, "memory","Memory (phonebooks and calls)"},
8005 {H_Filesystem, "filesystem","Filesystem"}, 8182 {H_Filesystem, "filesystem","Filesystem"},
8006 {H_Logo, "logo", "Logo and pictures"}, 8183 {H_Logo, "logo", "Logo and pictures"},
8007 {H_Ringtone, "ringtone","Ringtones"}, 8184 {H_Ringtone, "ringtone","Ringtones"},
8008 {H_Calendar, "calendar","Calendar notes"}, 8185 {H_Calendar, "calendar","Calendar notes"},
8009 {H_ToDo, "todo", "To do lists"}, 8186 {H_ToDo, "todo", "To do lists"},
8010 {H_Note, "note", "Notes"}, 8187 {H_Note, "note", "Notes"},
8011 {H_DateTime, "datetime","Date, time and alarms"}, 8188 {H_DateTime, "datetime","Date, time and alarms"},
8012 {H_Category, "category","Categories"}, 8189 {H_Category, "category","Categories"},
8013#ifdef GSM_ENABLE_BACKUP 8190#ifdef GSM_ENABLE_BACKUP
8014 {H_Backup, "backup","Backing up and restoring"}, 8191 {H_Backup, "backup","Backing up and restoring"},
8015#endif 8192#endif
8016#if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4) 8193#if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4)
8017 {H_Nokia, "nokia","Nokia specific"}, 8194 {H_Nokia, "nokia","Nokia specific"},
8018#endif 8195#endif
8019#ifdef GSM_ENABLE_AT 8196#ifdef GSM_ENABLE_AT
8020 {H_Siemens, "siemens","Siemens specific"}, 8197 {H_Siemens, "siemens","Siemens specific"},
8021#endif 8198#endif
8022 {H_Network, "network","Network"}, 8199 {H_Network, "network","Network"},
8023 {H_WAP, "wap", "WAP settings and bookmarks"}, 8200 {H_WAP, "wap", "WAP settings and bookmarks"},
8024 {H_MMS, "mms", "MMS and MMS settings"}, 8201 {H_MMS, "mms", "MMS and MMS settings"},
8025 {H_Tests, "tests","Phone tests"}, 8202 {H_Tests, "tests","Phone tests"},
8026 {H_FM, "fm", "FM radio"}, 8203 {H_FM, "fm", "FM radio"},
8027 {H_Info, "info", "Phone information"}, 8204 {H_Info, "info", "Phone information"},
8028 {H_Settings, "settings","Phone settings"}, 8205 {H_Settings, "settings","Phone settings"},
8029#ifdef DEBUG 8206#ifdef DEBUG
8030 {H_Decode, "decode","Dumps decoding"}, 8207 {H_Decode, "decode","Dumps decoding"},
8031#endif 8208#endif
8032 {H_Other, "other","Functions that don't fit elsewhere"}, 8209 {H_Other, "other","Functions that don't fit elsewhere"},
8033 {0, NULL, NULL} 8210 {0, NULL, NULL}
8034}; 8211};
8035 8212
8036 8213
8037void HelpHeader(void) 8214void HelpHeader(void)
8038{ 8215{
8039 printmsg("[Gammu version %s built %s %s]\n\n",VERSION,__TIME__,__DATE__); 8216 printmsg("[Gammu version %s built %s %s]\n\n",VERSION,__TIME__,__DATE__);
8040} 8217}
8041 8218
8042static void HelpGeneral(void) 8219static void HelpGeneral(void)
8043{ 8220{
8044 inti=0; 8221 inti=0;
8045 8222
8046 HelpHeader(); 8223 HelpHeader();
8047 8224
8048 printmsg("Usage: gammu [confign] [nothing|text|textall|binary|errors] [options]\n\n"); 8225 printmsg("Usage: gammu [confign] [nothing|text|textall|binary|errors] [options]\n\n");
8049 printmsg("First parameter optionally specifies which config section to use (by default are probed all).\n"); 8226 printmsg("First parameter optionally specifies which config section to use (all are probed by default).\n");
8050 printmsg("Second parameter optionally controls debug level, next specify actions.\n\n"); 8227 printmsg("Second parameter optionally controls debug level, next one specifies actions.\n\n");
8051 8228
8052 /* We might want to put here some most used commands */ 8229 /* We might want to put here some most used commands */
8053 printmsg("For more details call help on specific topic (gammu --help topic), topics are:\n\n"); 8230 printmsg("For more details, call help on specific topic (gammu --help topic). Topics are:\n\n");
8054 8231
8055 while (HelpDescriptions[i].category != 0) { 8232 while (HelpDescriptions[i].category != 0) {
8056 printf("%11s - %s\n", HelpDescriptions[i].option, HelpDescriptions[i].description); 8233 printf("%11s - %s\n", HelpDescriptions[i].option, HelpDescriptions[i].description);
8057 i++; 8234 i++;
8058 } 8235 }
8059 printf("\n"); 8236 printf("\n");
8060} 8237}
8061 8238
8062static void HelpSplit(int cols, int len, unsigned char *buff) 8239static void HelpSplit(int cols, int len, unsigned char *buff)
8063{ 8240{
8064 int l, len2, pos, split; 8241 int l, len2, pos, split;
8065 bool in_opt,first=true; 8242 bool in_opt,first=true;
8066 char *remain, spaces[50], buffer[500]; 8243 char *remain, spaces[50], buffer[500];
8067 8244
8068 if (cols == 0) { 8245 if (cols == 0) {
8069 printf(" %s\n", buff); 8246 printf(" %s\n", buff);
8070 } else { 8247 } else {
8071 printf(" "); 8248 printf(" ");
8072 spaces[0] = 0; 8249 spaces[0] = 0;
8073 len2 = strlen(buff); 8250 len2 = strlen(buff);
8074 if (len + len2 < cols) { 8251 if (len + len2 < cols) {
8075 printf("%s\n", buff); 8252 printf("%s\n", buff);
8076 } else { 8253 } else {
8077 for(l = 0; l < len; l++) strcat(spaces, " "); 8254 for(l = 0; l < len; l++) strcat(spaces, " ");
8078 8255
8079 remain = buff; 8256 remain = buff;
8080 8257
8081 while (strlen(remain) > 0) { 8258 while (strlen(remain) > 0) {
8082 split= 0; 8259 split= 0;
8083 pos= 0; 8260 pos= 0;
8084 in_opt= false; 8261 in_opt= false;
8085 if (!first) printf(spaces); 8262 if (!first) printf(spaces);
8086 while (pos < cols - len && remain[pos] != 0) { 8263 while (pos < cols - len && remain[pos] != 0) {
8087 if (in_opt && remain[pos] == ']') { 8264 if (in_opt && remain[pos] == ']') {
8088 in_opt = false; 8265 in_opt = false;
8089 split = pos; 8266 split = pos;
8090 } else if (remain[pos] == '[') { 8267 } else if (remain[pos] == '[') {
8091 in_opt = true; 8268 in_opt = true;
8092 } else if (!in_opt && remain[pos] == ' ') { 8269 } else if (!in_opt && remain[pos] == ' ') {
8093 split = pos - 1; 8270 split = pos - 1;
8094 } 8271 }
8095 pos++; 8272 pos++;
8096 } 8273 }
8097 /* Can not be split */ 8274 /* Can not be split */
8098 if (split == 0) { 8275 if (split == 0) {
8099 printf("%s\n", remain); 8276 printf("%s\n", remain);
8100 remain += strlen(remain); 8277 remain += strlen(remain);
8101 } else { 8278 } else {
8102 first = false; 8279 first = false;
8103 split++; 8280 split++;
8104 strncpy(buffer, remain, split); 8281 strncpy(buffer, remain, split);
8105 buffer[split] = 0; 8282 buffer[split] = 0;
8106 printf("%s\n", buffer); 8283 printf("%s\n", buffer);
8107 remain += split; 8284 remain += split;
8108 if (remain[0] == ' ') remain++; 8285 if (remain[0] == ' ') remain++;
8109 } 8286 }
8110 } 8287 }
8111 } 8288 }
8112 } 8289 }
8113} 8290}
8114 8291
8115static void Help(int argc, char *argv[]) 8292static void Help(int argc, char *argv[])
8116{ 8293{
8117 int i = 0, j = 0, k, cols; 8294 int i = 0, j = 0, k, cols;
8118 bool disp; 8295 bool disp;
8119#ifdef TIOCGWINSZ 8296#ifdef TIOCGWINSZ
8120 struct winsize w; 8297 struct winsize w;
8121#endif 8298#endif
8122#if defined(WIN32) || defined(DJGPP) 8299#if defined(WIN32) || defined(DJGPP)
8123#else 8300#else
8124 char *columns; 8301 char *columns;
8125#endif 8302#endif
8126 8303
8127 /* Just --help */ 8304 /* Just --help */
8128 if (argc == 2) { 8305 if (argc == 2) {
8129 HelpGeneral(); 8306 HelpGeneral();
8130 return; 8307 return;
8131 } 8308 }
8132 8309
8133 if (!strcmp(argv[2],"all")) { 8310 if (!strcmp(argv[2],"all")) {
8134 HelpHeader(); 8311 HelpHeader();
8135 } else { 8312 } else {
8136 while (HelpDescriptions[i].category != 0) { 8313 while (HelpDescriptions[i].category != 0) {
8137 if (strcmp(argv[2], HelpDescriptions[i].option) == 0) break; 8314 if (mystrncasecmp(argv[2], HelpDescriptions[i].option,strlen(argv[2]))) break;
8138 i++; 8315 i++;
8139 } 8316 }
8140 if (HelpDescriptions[i].category == 0) { 8317 if (HelpDescriptions[i].category == 0) {
8141 HelpGeneral(); 8318 HelpGeneral();
8142 printmsg("Unknown help topic specified!\n"); 8319 printmsg("Unknown help topic specified!\n");
8143 return; 8320 return;
8144 } 8321 }
8145 HelpHeader(); 8322 HelpHeader();
8146 printmsg("Gammu parameters, topic: %s\n\n", HelpDescriptions[i].description); 8323 printmsg("Gammu parameters, topic: %s\n\n", HelpDescriptions[i].description);
8147 } 8324 }
8148 8325
8149#if defined(WIN32) || defined(DJGPP) 8326#if defined(WIN32) || defined(DJGPP)
8150 cols = 80; 8327 cols = 80;
8151#else 8328#else
8152 cols = 0; 8329 cols = 0;
8153 /* If stdout is a tty, we will wrap to columns it has */ 8330 /* If stdout is a tty, we will wrap to columns it has */
8154 if (isatty(1)) { 8331 if (isatty(1)) {
8155#ifdef TIOCGWINSZ 8332#ifdef TIOCGWINSZ
8156 if (ioctl(2, TIOCGWINSZ, &w) == 0) { 8333 if (ioctl(2, TIOCGWINSZ, &w) == 0) {
8157 if (w.ws_col > 0) cols = w.ws_col; 8334 if (w.ws_col > 0) cols = w.ws_col;
8158 } 8335 }
8159#endif 8336#endif
8160 if (cols == 0) { 8337 if (cols == 0) {
8161 columns = getenv("COLUMNS"); 8338 columns = getenv("COLUMNS");
8162 if (columns != NULL) { 8339 if (columns != NULL) {
8163 cols = atoi(columns); 8340 cols = atoi(columns);
8164 if (cols <= 0) cols = 0; 8341 if (cols <= 0) cols = 0;
8165 } 8342 }
8166 } 8343 }
8167 8344
8168 if (cols == 0) { 8345 if (cols == 0) {
8169 /* Fallback */ 8346 /* Fallback */
8170 cols = 80; 8347 cols = 80;
8171 } 8348 }
8172 } 8349 }
8173#endif 8350#endif
8174 8351
8175 while (Parameters[j].Function != NULL) { 8352 while (Parameters[j].Function != NULL) {
8176 k = 0; 8353 k = 0;
8177 disp = false; 8354 disp = false;
8178 if (!strcmp(argv[2],"all")) { 8355 if (!strcmp(argv[2],"all")) {
8179 if (j==0) disp = true; 8356 if (j==0) disp = true;
8180 if (j!=0) { 8357 if (j!=0) {
8181 if (strcmp(Parameters[j].help,Parameters[j-1].help)) { 8358 if (strcmp(Parameters[j].help,Parameters[j-1].help)) {
8182 disp = true; 8359 disp = true;
8183 } else { 8360 } else {
8184 if (strcmp(Parameters[j].parameter,Parameters[j-1].parameter)) { 8361 if (strcmp(Parameters[j].parameter,Parameters[j-1].parameter)) {
8185 disp = true; 8362 disp = true;
8186 } 8363 }
8187 } 8364 }
8188 } 8365 }
8189 } else { 8366 } else {
8190 while (Parameters[j].help_cat[k] != 0) { 8367 while (Parameters[j].help_cat[k] != 0) {
8191 if (Parameters[j].help_cat[k] == HelpDescriptions[i].category) { 8368 if (Parameters[j].help_cat[k] == HelpDescriptions[i].category) {
8192 disp = true; 8369 disp = true;
8193 break; 8370 break;
8194 } 8371 }
8195 k++; 8372 k++;
8196 } 8373 }
8197 } 8374 }
8198 if (disp) { 8375 if (disp) {
8199 printf("%s", Parameters[j].parameter); 8376 printf("%s", Parameters[j].parameter);
8200 if (Parameters[j].help[0] == 0) { 8377 if (Parameters[j].help[0] == 0) {
8201 printf("\n"); 8378 printf("\n");
8202 } else { 8379 } else {
8203 HelpSplit(cols - 1, strlen(Parameters[j].parameter) + 1, Parameters[j].help); 8380 HelpSplit(cols - 1, strlen(Parameters[j].parameter) + 1, Parameters[j].help);
8204 } 8381 }
8205 } 8382 }
8206 j++; 8383 j++;
8207 } 8384 }
8208} 8385}
8209#if 0 8386
8210#endif // 0
8211int main(int argc, char *argv[]) 8387int main(int argc, char *argv[])
8212{ 8388{
8213 8389 int z = 0,start=0,i;
8214 //fprintf(stderr,"HIIIIIIIIIIIII \n"); 8390 intonly_config = -1;
8215 //#if 0 8391#if !defined(WIN32) && !defined(DJGPP) && defined(LOCALE_PATH)
8216 static int z ,start,i; 8392 char*locale, locale_file[201];
8217 static intonly_config ;
8218#if !defined(WIN32) && defined(LOCALE_PATH)
8219 static char*locale, locale_file[201];
8220#endif 8393#endif
8221 static char*cp; 8394 char*cp;
8222 static boolcount_failed; 8395 boolcount_failed = false;
8223 z = 0; 8396
8224 start=0;only_config = -1;count_failed = false;
8225 s.opened = false; 8397 s.opened = false;
8226 s.msg = NULL; 8398 s.msg = NULL;
8227 s.ConfigNum = 0; 8399 s.ConfigNum = 0;
8228 8400
8229 setlocale(LC_ALL, ""); 8401 setlocale(LC_ALL, "");
8230#ifdef DEBUG 8402#ifdef DEBUG
8231 di.dl = DL_TEXTALL; 8403 di.dl = DL_TEXTALL;
8232 di.df = stdout; 8404 di.df = stdout;
8233#endif 8405#endif
8234 //#if 0 8406
8235 /* Any parameters? */ 8407 /* Any parameters? */
8236 if (argc == 1) { 8408 if (argc == 1) {
8237 HelpGeneral(); 8409 HelpGeneral();
8238 printmsg("Too few parameters!\n"); 8410 printmsg("Too few parameters!\n");
8239 exit(1); 8411 exit(1);
8240 } 8412 }
8241 8413
8242 /* Help? */ 8414 /* Help? */
8243 if (strncmp(argv[1 + start], "--help", 6) == 0) { 8415 if (strncmp(argv[1 + start], "--help", 6) == 0) {
8244 Help(argc - start, argv + start); 8416 Help(argc - start, argv + start);
8245 exit(1); 8417 exit(1);
8246 } 8418 }
8247 8419
8248 /* Is first parameter numeric? If so treat it as config that should be loaded. */ 8420 /* Is first parameter numeric? If so treat it as config that should be loaded. */
8249 //if (isdigit(argv[1][0])) { 8421 if (isdigit(argv[1][0])) {
8250 //only_config = atoi(argv[1]); 8422 only_config = atoi(argv[1]);
8251 //if (only_config >= 0) start++; else only_config = -1; 8423 if (only_config >= 0) start++; else only_config = -1;
8252 //} 8424 }
8253 only_config = 0;;
8254#if 0
8255 GSM_ReadConfig(NULL, &s.Config[0], 0);
8256 s.ConfigNum = 1;
8257 GSM_Config *con = &s.Config[0];
8258
8259 char* tempC;
8260 tempC = argv[argc-1]+2;
8261 if ( *tempC != 0 ) {
8262 fprintf(stderr,"Using model %s \n",tempC);
8263 strcpy(con->Model,tempC );
8264 }
8265 tempC = argv[argc-2]+2;
8266 if ( *tempC != 0 ) {
8267 fprintf(stderr,"Using device %s \n",tempC);
8268 con->Device = strdup(tempC);
8269 con->DefaultDevice = false;
8270 }
8271 tempC = argv[argc-3]+2;
8272 if ( *tempC != 0 ) {
8273 fprintf(stderr,"Using connection %s \n",tempC);
8274 con->Connection = strdup(tempC);
8275 con->DefaultConnection = false;
8276 }
8277 argc = argc-3;
8278 //#if 0
8279 if ( ! mConnection.isEmpty() ) {
8280 cfg->Connection = strdup(mConnection.latin1());
8281 cfg->DefaultConnection = false;
8282 qDebug("Connection set %s ", cfg->Connection );
8283
8284 }
8285 if ( ! mDevice.isEmpty() ) {
8286 cfg->Device = strdup(mDevice.latin1());
8287 cfg->DefaultDevice = false;
8288 qDebug("Device set %s ", cfg->Device);
8289
8290 }
8291 if ( ! mModel.isEmpty() ) {
8292 strcpy(cfg->Model,mModel.latin1() );
8293 cfg->DefaultModel = false;
8294 qDebug("Model set %s ",cfg->Model );
8295 }
8296
8297#endif
8298 8425
8426 cfg = GSM_FindGammuRC();
8427 if (cfg == NULL) printmsg("Warning: No configuration file found!\n");
8299 8428
8300 cfg=GSM_FindGammuRC();
8301 for (i = 0; i <= MAX_CONFIG_NUM; i++) { 8429 for (i = 0; i <= MAX_CONFIG_NUM; i++) {
8302 if (cfg!=NULL) { 8430 if (cfg!=NULL) {
8303 cp = INI_GetValue(cfg, "gammu", "gammucoding", false); 8431 cp = INI_GetValue(cfg, "gammu", "gammucoding", false);
8304 if (cp) di.coding = cp; 8432 if (cp) di.coding = cp;
8305 8433
8306 s.Config[i].Localize = INI_GetValue(cfg, "gammu", "gammuloc", false); 8434 s.Config[i].Localize = INI_GetValue(cfg, "gammu", "gammuloc", false);
8307 if (s.Config[i].Localize) { 8435 if (s.Config[i].Localize) {
8308 s.msg=INI_ReadFile(s.Config[i].Localize, true); 8436 s.msg=INI_ReadFile(s.Config[i].Localize, true);
8309 } else { 8437 } else {
8310#if !defined(WIN32) && defined(LOCALE_PATH) 8438#if !defined(WIN32) && !defined(DJGPP) && defined(LOCALE_PATH)
8311 locale = setlocale(LC_MESSAGES, NULL); 8439 locale = setlocale(LC_MESSAGES, NULL);
8312 if (locale != NULL) { 8440 if (locale != NULL) {
8313 snprintf(locale_file, 200, "%s/gammu_%c%c.txt", 8441 snprintf(locale_file, 200, "%s/gammu_%c%c.txt",
8314 LOCALE_PATH, 8442 LOCALE_PATH,
8315 tolower(locale[0]), 8443 tolower(locale[0]),
8316 tolower(locale[1])); 8444 tolower(locale[1]));
8317 s.msg = INI_ReadFile(locale_file, true); 8445 s.msg = INI_ReadFile(locale_file, true);
8318 } 8446 }
8319#endif 8447#endif
8320 } 8448 }
8321 } 8449 }
8322 8450
8323 /* Wanted user specific configuration? */ 8451 /* Wanted user specific configuration? */
8324
8325 if (only_config != -1) { 8452 if (only_config != -1) {
8326 /* Here we get only in first for loop */ 8453 /* Here we get only in first for loop */
8327 if (!GSM_ReadConfig(cfg, &s.Config[0], only_config)) break; 8454 if (!GSM_ReadConfig(cfg, &s.Config[0], only_config)) break;
8328 } else { 8455 } else {
8329 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break; 8456 if (!GSM_ReadConfig(cfg, &s.Config[i], i) && i != 0) break;
8330 } 8457 }
8331 s.ConfigNum++; 8458 s.ConfigNum++;
8332 8459
8333 /* We want to use only one file descriptor for global and state machine debug output */ 8460 /* We want to use only one file descriptor for global and state machine debug output */
8334 s.Config[i].UseGlobalDebugFile = true; 8461 s.Config[i].UseGlobalDebugFile = true;
8335 8462
8336 /* It makes no sense to open several debug logs... */ 8463 /* It makes no sense to open several debug logs... */
8337 if (i != 0) { 8464 if (i != 0) {
8338 strcpy(s.Config[i].DebugLevel, s.Config[0].DebugLevel); 8465 strcpy(s.Config[i].DebugLevel, s.Config[0].DebugLevel);
8339 free(s.Config[i].DebugFile); 8466 free(s.Config[i].DebugFile);
8340 s.Config[i].DebugFile = strdup(s.Config[0].DebugFile); 8467 s.Config[i].DebugFile = strdup(s.Config[0].DebugFile);
8341 } else { 8468 } else {
8342 /* Just for first config */ 8469 /* Just for first config */
8343 /* When user gave debug level on command line */ 8470 /* When user gave debug level on command line */
8344 if (argc > 1 + start && GSM_SetDebugLevel(argv[1 + start], &di)) { 8471 if (argc > 1 + start && GSM_SetDebugLevel(argv[1 + start], &di)) {
8345 /* Debug level from command line will be used with phone too */ 8472 /* Debug level from command line will be used with phone too */
8346 strcpy(s.Config[i].DebugLevel,argv[1 + start]); 8473 strcpy(s.Config[i].DebugLevel,argv[1 + start]);
8347 start++; 8474 start++;
8348 } else { 8475 } else {
8349 /* Try to set debug level from config file */ 8476 /* Try to set debug level from config file */
8350 GSM_SetDebugLevel(s.Config[i].DebugLevel, &di); 8477 GSM_SetDebugLevel(s.Config[i].DebugLevel, &di);
8351 } 8478 }
8352 /* If user gave debug file in gammurc, we will use it */ 8479 /* If user gave debug file in gammurc, we will use it */
8353 error=GSM_SetDebugFile(s.Config[i].DebugFile, &di); 8480 error=GSM_SetDebugFile(s.Config[i].DebugFile, &di);
8354 Print_Error(error); 8481 Print_Error(error);
8355 } 8482 }
8356 8483
8357 /* We wanted to read just user specified configuration. */ 8484 /* We wanted to read just user specified configuration. */
8358 if (only_config != -1) {break;} 8485 if (only_config != -1) {break;}
8359 } 8486 }
8360#if 0 8487
8361 GSM_Config *con = &s.Config[0];
8362
8363 char* tempC;
8364 tempC = argv[argc-1]+2;
8365 if ( *tempC != 0 ) {
8366 fprintf(stderr,"Using model %s \n",tempC);
8367 strcpy(con->Model,tempC );
8368 }
8369 tempC = argv[argc-2]+2;
8370 if ( *tempC != 0 ) {
8371 fprintf(stderr,"Using device %s \n",tempC);
8372 con->Device = strdup(tempC);
8373 con->DefaultDevice = false;
8374 }
8375 tempC = argv[argc-3]+2;
8376 if ( *tempC != 0 ) {
8377 fprintf(stderr,"Using connection %s \n",tempC);
8378 con->Connection = strdup(tempC);
8379 con->DefaultConnection = false;
8380 }
8381#endif
8382
8383
8384 /* Do we have enough parameters? */ 8488 /* Do we have enough parameters? */
8385 if (argc == 1 + start) { 8489 if (argc == 1 + start) {
8386 HelpGeneral(); 8490 HelpGeneral();
8387 printmsg("Too few parameters!\n"); 8491 printmsg("Too few parameters!\n");
8388 exit(-2); 8492 exit(-2);
8389 } 8493 }
8390 8494
8391 /* Check used version vs. compiled */ 8495 /* Check used version vs. compiled */
8392 if (!mystrncasecmp(GetGammuVersion(),VERSION,0)) { 8496 if (!mystrncasecmp(GetGammuVersion(),VERSION,0)) {
8393 printmsg("ERROR: version of installed libGammu.so (%s) is different to version of Gammu (%s)\n", 8497 printmsg("ERROR: version of installed libGammu.so (%s) is different to version of Gammu (%s)\n",
8394 GetGammuVersion(),VERSION); 8498 GetGammuVersion(),VERSION);
8395 exit(-1); 8499 exit(-1);
8396 } 8500 }
8397 8501
8398 /* Check parameters */ 8502 /* Check parameters */
8399 while (Parameters[z].Function != NULL) { 8503 while (Parameters[z].Function != NULL) {
8400 if (mystrncasecmp(Parameters[z].parameter,argv[1+start], 0)) { 8504 if (mystrncasecmp(Parameters[z].parameter,argv[1+start], 0)) {
8401 if (argc-2-start >= Parameters[z].min_arg && argc-2-start <= Parameters[z].max_arg) { 8505 if (argc-2-start >= Parameters[z].min_arg && argc-2-start <= Parameters[z].max_arg) {
8402 fprintf(stderr,"Executing \n");
8403 Parameters[z].Function(argc - start, argv + start); 8506 Parameters[z].Function(argc - start, argv + start);
8404 break; 8507 break;
8405 } else { 8508 } else {
8406 count_failed = true; 8509 count_failed = true;
8407 } 8510 }
8408 } 8511 }
8409 z++; 8512 z++;
8410 } 8513 }
8411 8514
8412 /* Tell user when we did nothing */ 8515 /* Tell user when we did nothing */
8413 if (Parameters[z].Function == NULL) { 8516 if (Parameters[z].Function == NULL) {
8414 HelpGeneral(); 8517 HelpGeneral();
8415 if (count_failed) { 8518 if (count_failed) {
8416 printmsg("Bad parameter count!\n"); 8519 printmsg("Bad parameter count!\n");
8417 } else { 8520 } else {
8418 printmsg("Bad option!\n"); 8521 printmsg("Bad option!\n");
8419 } 8522 }
8420 } 8523 }
8421 8524
8422 /* Close debug output if opened */ 8525 /* Close debug output if opened */
8423 if (di.df!=stdout) fclose(di.df); 8526 if (di.df!=stdout) fclose(di.df);
8424 //#endif // 0 8527
8425 fprintf(stderr,"kammu: Success. End. \n");
8426 exit(0); 8528 exit(0);
8427} 8529}
8428 8530
8429/* How should editor hadle tabs in this file? Add editor commands here. 8531/* How should editor hadle tabs in this file? Add editor commands here.
8430 * vim: noexpandtab sw=8 ts=8 sts=8: 8532 * vim: noexpandtab sw=8 ts=8 sts=8:
8431 */ 8533 */
8432 8534
diff --git a/gammu/emb/gammu/gammu.h b/gammu/emb/gammu/gammu.h
index d3de31b..ff50c9c 100644
--- a/gammu/emb/gammu/gammu.h
+++ b/gammu/emb/gammu/gammu.h
@@ -1,74 +1,74 @@
1/* (c) 2002-2003 by Marcin Wiacek and Michal Cihar */ 1/* (c) 2002-2003 by Marcin Wiacek and Michal Cihar */
2 2
3#include "../common/config.h" 3#include "../common/config.h"
4#include "../common/misc/misc.h" 4#include "../common/misc/misc.h"
5#include "../common/gsmstate.h" 5#include "../common/gsmstate.h"
6 6
7typedef enum { 7typedef enum {
8 H_Call=1, 8 H_Call=1,
9 H_SMS, 9 H_SMS,
10 H_Memory, 10 H_Memory,
11 H_Filesystem, 11 H_Filesystem,
12 H_Logo, 12 H_Logo,
13 H_Ringtone, 13 H_Ringtone,
14 H_Calendar, 14 H_Calendar,
15 H_ToDo, 15 H_ToDo,
16 H_Note, 16 H_Note,
17 H_DateTime, 17 H_DateTime,
18 H_Category, 18 H_Category,
19 H_Tests, 19 H_Tests,
20#ifdef GSM_ENABLE_BACKUP 20#ifdef GSM_ENABLE_BACKUP
21 H_Backup, 21 H_Backup,
22#endif 22#endif
23#if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4) 23#if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4)
24 H_Nokia, 24 H_Nokia,
25#endif 25#endif
26#ifdef GSM_ENABLE_AT 26#ifdef GSM_ENABLE_AT
27 H_Siemens, 27 H_Siemens,
28#endif 28#endif
29 H_Network, 29 H_Network,
30 H_WAP, 30 H_WAP,
31 H_MMS, 31 H_MMS,
32 H_FM, 32 H_FM,
33 H_Info, 33 H_Info,
34 H_Settings, 34 H_Settings,
35#ifdef DEBUG 35#ifdef DEBUG
36 H_Decode, 36 H_Decode,
37#endif 37#endif
38 H_Other 38 H_Other
39} HelpCategory; 39} HelpCategory;
40 40
41typedef struct { 41typedef struct {
42 HelpCategorycategory; 42 HelpCategorycategory;
43 char *option; 43 char *option;
44 char *description; 44 char *description;
45} HelpCategoryDescriptions; 45} HelpCategoryDescriptions;
46 46
47typedef struct { 47typedef struct {
48 char *parameter; 48 char *parameter;
49 int min_arg; 49 int min_arg;
50 int max_arg; 50 int max_arg;
51 void (*Function) (int argc, char *argv[]); 51 void (*Function) (int argc, char *argv[]);
52 HelpCategoryhelp_cat[10]; 52 HelpCategoryhelp_cat[10];
53 char *help; 53 char *help;
54} GSM_Parameters; 54} GSM_Parameters;
55 55
56 void Print_Error (GSM_Error error); 56 void Print_Error (GSM_Error error);
57 void GSM_Init (bool checkerror); 57 void GSM_Init (bool checkerror);
58 void GSM_Terminate (void); 58 void GSM_Terminate (void);
59 59
60 static GSM_StateMachines; 60 extern GSM_StateMachines;
61 static GSM_Phone_Functions*Phone; 61 extern GSM_Phone_Functions*Phone;
62 static GSM_Error error; 62 extern GSM_Error error;
63 63
64 static bool gshutdown; 64 extern volatile bool gshutdown;
65 65
66void interrupt(int sign); 66void interrupt(int sign);
67 67
68#ifdef GSM_ENABLE_BEEP 68#ifdef GSM_ENABLE_BEEP
69 void GSM_PhoneBeep (void); 69 void GSM_PhoneBeep (void);
70#endif 70#endif
71 71
72/* How should editor hadle tabs in this file? Add editor commands here. 72/* How should editor hadle tabs in this file? Add editor commands here.
73 * vim: noexpandtab sw=8 ts=8 sts=8: 73 * vim: noexpandtab sw=8 ts=8 sts=8:
74 */ 74 */
diff --git a/gammu/emb/gammu/smsd/s_files.c b/gammu/emb/gammu/smsd/s_files.c
index dac8d9c..b791e58 100644
--- a/gammu/emb/gammu/smsd/s_files.c
+++ b/gammu/emb/gammu/smsd/s_files.c
@@ -1,313 +1,360 @@
1/* (c) 2002-2003 by Joergen Thomsen */ 1/* (c) 2002-2004 by Joergen Thomsen */
2 2
3#include "../../cfg/config.h" 3#include "../../cfg/config.h"
4 4
5#include <string.h> 5#include <string.h>
6#include <stdio.h> 6#include <stdio.h>
7#include <errno.h> 7#include <errno.h>
8#include <time.h> 8#include <time.h>
9#ifdef WIN32 9#ifdef WIN32
10# include <io.h> 10# include <io.h>
11#endif 11#endif
12#if defined HAVE_DIRENT_H && defined HAVE_SCANDIR && defined HAVE_ALPHASORT 12#if defined HAVE_DIRENT_H && defined HAVE_SCANDIR && defined HAVE_ALPHASORT
13# include <dirent.h> 13# include <dirent.h>
14#endif 14#endif
15 15
16#include "../../common/misc/coding/coding.h" 16#include "../../common/misc/coding/coding.h"
17#include "../../common/service/backup/gsmback.h" 17#include "../../common/service/backup/gsmback.h"
18#include "smsdcore.h" 18#include "smsdcore.h"
19 19
20/* Save SMS from phone (called Inbox sms - it's in phone Inbox) somewhere */ 20/* Save SMS from phone (called Inbox sms - it's in phone Inbox) somewhere */
21static GSM_Error SMSDFiles_SaveInboxSMS(GSM_MultiSMSMessage sms, GSM_SMSDConfig *Config) 21static GSM_Error SMSDFiles_SaveInboxSMS(GSM_MultiSMSMessage sms, GSM_SMSDConfig *Config)
22{ 22{
23 GSM_Errorerror = ERR_NONE; 23 GSM_Errorerror = ERR_NONE;
24 int i,j; 24 int i,j;
25 unsigned char FileName[100], FullName[400], ext[4], buffer[64],buffer2[400]; 25 unsigned char FileName[100], FullName[400], ext[4], buffer[64],buffer2[400];
26 bool done; 26 bool done;
27 FILE *file; 27 FILE *file;
28#ifdef GSM_ENABLE_BACKUP 28#ifdef GSM_ENABLE_BACKUP
29 GSM_SMS_Backup backup; 29 GSM_SMS_Backup backup;
30#endif 30#endif
31 31
32 j = 0; 32 j = 0;
33 done = false; 33 done = false;
34 for (i=0;i<sms.Number && !done;i++) { 34 for (i=0;i<sms.Number && !done;i++) {
35 strcpy(ext, "txt"); 35 strcpy(ext, "txt");
36 if (sms.SMS[i].Coding == SMS_Coding_8bit) strcpy(ext, "bin"); 36 if (sms.SMS[i].Coding == SMS_Coding_8bit) strcpy(ext, "bin");
37 DecodeUnicode(sms.SMS[i].Number,buffer2); 37 DecodeUnicode(sms.SMS[i].Number,buffer2);
38 /* we loop on yy for the first SMS assuming that if xxxx_yy_00.ext is absent, 38 /* we loop on yy for the first SMS assuming that if xxxx_yy_00.ext is absent,
39 any xxxx_yy_01,02, must be garbage, that can be overwritten */ 39 any xxxx_yy_01,02, must be garbage, that can be overwritten */
40 file = NULL; 40 file = NULL;
41 do { 41 do {
42 sprintf(FileName, 42 sprintf(FileName,
43 "IN%02d%02d%02d_%02d%02d%02d_%02i_%s_%02i.%s", 43 "IN%02d%02d%02d_%02d%02d%02d_%02i_%s_%02i.%s",
44 sms.SMS[i].DateTime.Year, sms.SMS[i].DateTime.Month, sms.SMS[i].DateTime.Day, 44 sms.SMS[i].DateTime.Year, sms.SMS[i].DateTime.Month, sms.SMS[i].DateTime.Day,
45 sms.SMS[i].DateTime.Hour, sms.SMS[i].DateTime.Minute, sms.SMS[i].DateTime.Second, 45 sms.SMS[i].DateTime.Hour, sms.SMS[i].DateTime.Minute, sms.SMS[i].DateTime.Second,
46 j, buffer2, i, ext); 46 j, buffer2, i, ext);
47 strcpy(FullName, Config->inboxpath); 47 strcpy(FullName, Config->inboxpath);
48 strcat(FullName, FileName); 48 strcat(FullName, FileName);
49 if (file) fclose(file); 49 if (file) fclose(file);
50 file = fopen(FullName, "r"); 50 file = fopen(FullName, "r");
51 } while ((i == 0) && (file && (++j < 100))); 51 } while ((i == 0) && (file && (++j < 100)));
52 if (file) { 52 if (file) {
53 fclose(file); 53 fclose(file);
54 if (i == 0) { 54 if (i == 0) {
55 WriteSMSDLog("Cannot save %s. No available file names", FileName); 55 WriteSMSDLog("Cannot save %s. No available file names", FileName);
56 return ERR_CANTOPENFILE; 56 return ERR_CANTOPENFILE;
57 } 57 }
58 } 58 }
59 errno = 0; 59 errno = 0;
60 60
61 if ((sms.SMS[i].PDU == SMS_Status_Report) && mystrncasecmp(Config->deliveryreport, "log", 3)) { 61 if ((sms.SMS[i].PDU == SMS_Status_Report) && mystrncasecmp(Config->deliveryreport, "log", 3)) {
62 strcpy(buffer, DecodeUnicodeString(sms.SMS[i].Number)); 62 strcpy(buffer, DecodeUnicodeString(sms.SMS[i].Number));
63 WriteSMSDLog("Delivery report: %s to %s", DecodeUnicodeString(sms.SMS[i].Text), buffer); 63 WriteSMSDLog("Delivery report: %s to %s", DecodeUnicodeString(sms.SMS[i].Text), buffer);
64 } else { 64 } else {
65#ifdef GSM_ENABLE_BACKUP 65#ifdef GSM_ENABLE_BACKUP
66 if (mystrncasecmp(Config->inboxformat, "detail", 0)) { 66 if (mystrncasecmp(Config->inboxformat, "detail", 0)) {
67 for (j=0;j<sms.Number;j++) backup.SMS[j] = &sms.SMS[j]; 67 for (j=0;j<sms.Number;j++) backup.SMS[j] = &sms.SMS[j];
68 backup.SMS[sms.Number] = NULL; 68 backup.SMS[sms.Number] = NULL;
69 error = GSM_SaveSMSBackupFile(FullName, &backup); 69 error = GSM_SaveSMSBackupFile(FullName, &backup);
70 done = true; 70 done = true;
71 } 71 }
72#endif 72#endif
73 if (!mystrncasecmp(Config->inboxformat, "detail", 0)) { 73 if (!mystrncasecmp(Config->inboxformat, "detail", 0)) {
74 file = fopen(FullName, "wb"); 74 file = fopen(FullName, "wb");
75 if (file) { 75 if (file) {
76 switch (sms.SMS[i].Coding) { 76 switch (sms.SMS[i].Coding) {
77 case SMS_Coding_Unicode: 77 case SMS_Coding_Unicode:
78 case SMS_Coding_Default: 78 case SMS_Coding_Default:
79 79
80 DecodeUnicode(sms.SMS[i].Text,buffer2); 80 DecodeUnicode(sms.SMS[i].Text,buffer2);
81 if (mystrncasecmp(Config->inboxformat, "unicode", 0)) { 81 if (mystrncasecmp(Config->inboxformat, "unicode", 0)) {
82 buffer[0] = 0xFE; 82 buffer[0] = 0xFE;
83 buffer[1] = 0xFF; 83 buffer[1] = 0xFF;
84 fwrite(buffer,1,2,file); 84 fwrite(buffer,1,2,file);
85 fwrite(sms.SMS[i].Text,1,strlen(buffer2)*2,file); 85 fwrite(sms.SMS[i].Text,1,strlen(buffer2)*2,file);
86 } else { 86 } else {
87 fwrite(buffer2,1,strlen(buffer2),file); 87 fwrite(buffer2,1,strlen(buffer2),file);
88 } 88 }
89 break; 89 break;
90 case SMS_Coding_8bit: 90 case SMS_Coding_8bit:
91 fwrite(sms.SMS[i].Text,1,sms.SMS[i].Length,file); 91 fwrite(sms.SMS[i].Text,1,sms.SMS[i].Length,file);
92 } 92 }
93 fclose(file); 93 fclose(file);
94 } else error = ERR_CANTOPENFILE; 94 } else error = ERR_CANTOPENFILE;
95 } 95 }
96 if (error == ERR_NONE) { 96 if (error == ERR_NONE) {
97 WriteSMSDLog("%s %s", (sms.SMS[i].PDU == SMS_Status_Report?"Delivery report":"Received"), FileName); 97 WriteSMSDLog("%s %s", (sms.SMS[i].PDU == SMS_Status_Report?"Delivery report":"Received"), FileName);
98 } else { 98 } else {
99 WriteSMSDLog("Cannot save %s (%i)", FileName, errno); 99 WriteSMSDLog("Cannot save %s (%i)", FileName, errno);
100 return ERR_CANTOPENFILE; 100 return ERR_CANTOPENFILE;
101 } 101 }
102 } 102 }
103 } 103 }
104 return ERR_NONE; 104 return ERR_NONE;
105} 105}
106 106
107/* Find one multi SMS to sending and return it (or return ERR_EMPTY) 107/* Find one multi SMS to sending and return it (or return ERR_EMPTY)
108 * There is also set ID for SMS 108 * There is also set ID for SMS
109 * File extension convention:
110 * OUTxxxxx.txt : normal text SMS
111 * Options appended to the extension applying to this SMS only:
112 * d: delivery report requested
113 * f: flash SMS
114 * b: WAP bookmark as name,URL
115 * e.g. OUTG20040620_193810_123_+4512345678_xpq.txtdf
116 * is a flash text SMS requesting delivery reports
109 */ 117 */
110static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID) 118static GSM_Error SMSDFiles_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID)
111{ 119{
112 GSM_Error error = ERR_NOTSUPPORTED; 120 GSM_Error error = ERR_NOTSUPPORTED;
113 GSM_MultiPartSMSInfo SMSInfo; 121 GSM_MultiPartSMSInfo SMSInfo;
122 GSM_WAPBookmark Bookmark;
114 unsigned char FileName[100],FullName[400]; 123 unsigned char FileName[100],FullName[400];
115 unsigned char Buffer[(GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS+1)*2]; 124 unsigned char Buffer[(GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS+1)*2];
116 unsigned char Buffer2[(GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS+1)*2]; 125 unsigned char Buffer2[(GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS+1)*2];
117 FILE *File; 126 FILE *File;
118 int i, len, phlen; 127 int i, len, phlen;
119 char *pos1, *pos2; 128 char *pos1, *pos2, *options;
120#if defined HAVE_DIRENT_H && defined HAVE_SCANDIR & defined HAVE_ALPHASORT 129#if defined HAVE_DIRENT_H && defined HAVE_SCANDIR & defined HAVE_ALPHASORT
121 struct dirent **namelist = NULL; 130 struct dirent **namelist = NULL;
122 int l, m ,n; 131 int l, m ,n;
123 132
124 strcpy(FullName, Config->outboxpath); 133 strcpy(FullName, Config->outboxpath);
125 FullName[strlen(Config->outboxpath)-1] = '\0'; 134 FullName[strlen(Config->outboxpath)-1] = '\0';
126 n = scandir(FullName, &namelist, 0, alphasort); 135 n = scandir(FullName, &namelist, 0, alphasort);
127 m = 0; 136 m = 0;
128 while ((m < n) && ((*(namelist[m]->d_name) == '.') || 137 while ((m < n) && ((*(namelist[m]->d_name) == '.') || // directory and UNIX hidden file
129 !mystrncasecmp(namelist[m]->d_name,"out", 3) || 138 !mystrncasecmp(namelist[m]->d_name,"out", 3) || // must start with 'out'
130 ((strlen(namelist[m]->d_name) >= 4) && 139 ((strlen(namelist[m]->d_name) >= 4) &&
131 !mystrncasecmp(&namelist[m]->d_name[strlen(namelist[m]->d_name)-4],".txt",4) 140 !mystrncasecmp(strrchr(namelist[m]->d_name, '.'),".txt",4)
132 ) 141 )
133 ) 142 )
134 ) m++; 143 ) m++;
135 if (m < n) strcpy(FileName,namelist[m]->d_name); 144 if (m < n) strcpy(FileName,namelist[m]->d_name);
136 for (l=0; l < n; l++) free(namelist[l]); 145 for (l=0; l < n; l++) free(namelist[l]);
137 free(namelist); 146 free(namelist);
138 namelist = NULL; 147 namelist = NULL;
139 if (m >= n) return ERR_EMPTY; 148 if (m >= n) return ERR_EMPTY;
140 error = ERR_NONE; 149 error = ERR_NONE;
141#else 150#else
142#ifdef WIN32 151#ifdef WIN32
143 struct _finddata_t c_file; 152 struct _finddata_t c_file;
144 long hFile; 153 long hFile;
145 154
146 strcpy(FullName, Config->outboxpath); 155 strcpy(FullName, Config->outboxpath);
147 strcat(FullName, "OUT*.txt"); 156 strcat(FullName, "OUT*.txt*");
148 if((hFile = _findfirst( FullName, &c_file )) == -1L ) { 157 if((hFile = _findfirst( FullName, &c_file )) == -1L ) {
149 return ERR_EMPTY; 158 return ERR_EMPTY;
150 } else { 159 } else {
151 strcpy(FileName,c_file.name); 160 strcpy(FileName,c_file.name);
152 } 161 }
153 _findclose( hFile ); 162 _findclose( hFile );
154 error = ERR_NONE; 163 error = ERR_NONE;
155#endif 164#endif
156#endif 165#endif
157 if (error != ERR_NONE) return error; 166 if (error != ERR_NONE) return error;
158 167 options = strrchr(FileName, '.') + 4;
159 strcpy(FullName, Config->outboxpath); 168 strcpy(FullName, Config->outboxpath);
160 strcat(FullName, FileName); 169 strcat(FullName, FileName);
161 170
162 File = fopen(FullName, "rb"); 171 File = fopen(FullName, "rb");
163 len = fread(Buffer, 1, sizeof(Buffer)-2, File); 172 len = fread(Buffer, 1, sizeof(Buffer)-2, File);
164 fclose(File); 173 fclose(File);
165 if (len<2) return ERR_EMPTY;
166 174
167 if ((Buffer[0] != 0xFF || Buffer[1] != 0xFE) && 175 if ((len < 2) ||
168 (Buffer[0] != 0xFE || Buffer[1] != 0xFF)) { 176 (len >= 2 && ((Buffer[0] != 0xFF || Buffer[1] != 0xFE) &&
177 (Buffer[0] != 0xFE || Buffer[1] != 0xFF)))) {
169 if (len > GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS) len = GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS; 178 if (len > GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS) len = GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS;
170 EncodeUnicode(Buffer2, Buffer, len); 179 EncodeUnicode(Buffer2, Buffer, len);
171 len = len*2; 180 len = len*2;
172 memmove(Buffer, Buffer2, len); 181 memmove(Buffer, Buffer2, len);
173 } 182 }
174 183
175 Buffer[len] = 0; 184 Buffer[len] = 0;
176 Buffer[len+1] = 0; 185 Buffer[len+1] = 0;
177 ReadUnicodeFile(Buffer2,Buffer); 186 ReadUnicodeFile(Buffer2,Buffer);
178 187
188 GSM_ClearMultiPartSMSInfo(&SMSInfo);
189 sms->Number = 0;
190
179 SMSInfo.ReplaceMessage = 0; 191 SMSInfo.ReplaceMessage = 0;
180 SMSInfo.Entries[0].Buffer= Buffer2; 192 SMSInfo.Entries[0].Buffer= Buffer2;
181 SMSInfo.Class = -1; 193 SMSInfo.Class = -1;
182 SMSInfo.EntriesNum = 1; 194 SMSInfo.EntriesNum = 1;
195 Config->currdeliveryreport= -1;
196 if (strchr(options, 'd')) Config->currdeliveryreport= 1;
197 if (strchr(options, 'f')) SMSInfo.Class = 0; /* flash SMS */
198
183 if (mystrncasecmp(Config->transmitformat, "unicode", 0)) { 199 if (mystrncasecmp(Config->transmitformat, "unicode", 0)) {
184 SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong; 200 SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong;
185 SMSInfo.UnicodeCoding = true; 201 SMSInfo.UnicodeCoding = true;
186 } else if (mystrncasecmp(Config->transmitformat, "7bit", 0)) { 202 } else if (mystrncasecmp(Config->transmitformat, "7bit", 0)) {
187 SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong; 203 SMSInfo.Entries[0].ID = SMS_ConcatenatedTextLong;
188 SMSInfo.UnicodeCoding = false; 204 SMSInfo.UnicodeCoding = false;
189 } else { 205 } else {
190 /* auto */ 206 /* auto */
191 SMSInfo.Entries[0].ID = SMS_ConcatenatedAutoTextLong; 207 SMSInfo.Entries[0].ID = SMS_ConcatenatedAutoTextLong;
192 } 208 }
209
210 if (strchr(options, 'b')) { // WAP bookmark as title,URL
211 SMSInfo.Entries[0].Buffer = NULL;
212 SMSInfo.Entries[0].Bookmark = &Bookmark;
213 SMSInfo.Entries[0].ID = SMS_NokiaWAPBookmarkLong;
214 SMSInfo.Entries[0].Bookmark->Location= 0;
215 pos2 = mywstrstr(Buffer2, "\0,");
216 if (pos2 == NULL) {
217 pos2 = Buffer2;
218 } else {
219 *pos2 = '\0'; pos2++; *pos2 = '\0'; pos2++; // replace comma by zero
220 }
221
222 len = UnicodeLength(Buffer2);
223 if (len > 50) len = 50;
224 memmove(&SMSInfo.Entries[0].Bookmark->Title, Buffer2, len * 2);
225 pos1 = &SMSInfo.Entries[0].Bookmark->Title[0] + len * 2;
226 *pos1 = '\0'; pos1++; *pos1 = '\0';
227
228 len = UnicodeLength(pos2);
229 if (len > 255) len = 255;
230 memmove(&SMSInfo.Entries[0].Bookmark->Address, pos2, len * 2);
231 pos1 = &SMSInfo.Entries[0].Bookmark->Address[0] + len * 2;
232 *pos1 = '\0'; pos1++; *pos1 = '\0';
233 }
234
193 GSM_EncodeMultiPartSMS(&SMSInfo,sms); 235 GSM_EncodeMultiPartSMS(&SMSInfo,sms);
194 236
195 pos1 = FileName; 237 pos1 = FileName;
196 strcpy(ID,FileName); 238 strcpy(ID,FileName);
197 for (i = 1; i <= 3 && pos1 != NULL ; i++) pos1 = strchr(++pos1, '_'); 239 for (i = 1; i <= 3 && pos1 != NULL ; i++) pos1 = strchr(++pos1, '_');
198 if (pos1 != NULL) { 240 if (pos1 != NULL) {
199 /* OUT<priority><date>_<time>_<serialno>_<phone number>_<anything>.txt */ 241 /* OUT<priority><date>_<time>_<serialno>_<phone number>_<anything>.txt */
200 pos2 = strchr(++pos1, '_'); 242 pos2 = strchr(++pos1, '_');
201 if (pos2 != NULL) { 243 if (pos2 != NULL) {
202 phlen = strlen(pos1) - strlen(pos2); 244 phlen = strlen(pos1) - strlen(pos2);
203 } else { 245 } else {
204 /* something wrong */ 246 /* something wrong */
205 return ERR_UNKNOWN; 247 return ERR_UNKNOWN;
206 } 248 }
207 } else if (i == 2) { 249 } else if (i == 2) {
208 /* OUTxxxxxxx.txt or OUTxxxxxxx */ 250 /* OUTxxxxxxx.txt or OUTxxxxxxx */
209 pos1 = &FileName[3]; 251 pos1 = &FileName[3];
210 pos2 = strchr(pos1, '.'); 252 pos2 = strchr(pos1, '.');
211 if (pos2 == NULL) { 253 if (pos2 == NULL) {
212 phlen = strlen(pos1); 254 phlen = strlen(pos1);
213 } else { 255 } else {
214 phlen = strlen(pos1) - strlen(pos2); 256 phlen = strlen(pos1) - strlen(pos2);
215 } 257 }
216 } else if (i == 4) { 258 } else if (i == 4) {
217 /* OUT<priority>_<phone number>_<serialno>.txt */ 259 /* OUT<priority>_<phone number>_<serialno>.txt */
218 pos1 = strchr(FileName, '_'); 260 pos1 = strchr(FileName, '_');
219 pos2 = strchr(++pos1, '_'); 261 pos2 = strchr(++pos1, '_');
220 phlen = strlen(pos1) - strlen(pos2); 262 phlen = strlen(pos1) - strlen(pos2);
221 } else { 263 } else {
222 /* something wrong */ 264 /* something wrong */
223 return ERR_UNKNOWN; 265 return ERR_UNKNOWN;
224 } 266 }
225 267
226 for (len=0;len<sms->Number;len++) { 268 for (len=0;len<sms->Number;len++) {
227 EncodeUnicode(sms->SMS[len].Number, pos1, phlen); 269 EncodeUnicode(sms->SMS[len].Number, pos1, phlen);
228 } 270 }
229 271
230#ifdef DEBUG 272#ifdef DEBUG
231 if (sms->Number != 0) { 273 if (sms->Number != 0) {
232 DecodeUnicode(sms->SMS[0].Number,Buffer); 274 DecodeUnicode(sms->SMS[0].Number,Buffer);
233 dbgprintf("Found %i sms to \"%s\" with text \"%s\" cod %i lgt %i udh: t %i l %i\n", 275 dbgprintf("Found %i sms to \"%s\" with text \"%s\" cod %i lgt %i udh: t %i l %i dlr: %i fls: %i",
234 sms->Number, 276 sms->Number,
235 Buffer, 277 Buffer,
236 DecodeUnicodeString(sms->SMS[0].Text), 278 DecodeUnicodeString(sms->SMS[0].Text),
237 sms->SMS[0].Coding, 279 sms->SMS[0].Coding,
238 sms->SMS[0].Length, 280 sms->SMS[0].Length,
239 sms->SMS[0].UDH.Type, 281 sms->SMS[0].UDH.Type,
240 sms->SMS[0].UDH.Length); 282 sms->SMS[0].UDH.Length,
241 } else dbgprintf("error\n"); 283 Config->currdeliveryreport,
284 SMSInfo.Class);
285 } else dbgprintf("error: SMS-count = 0");
242#endif 286#endif
243 287
244 return ERR_NONE; 288 return ERR_NONE;
245} 289}
246 290
247/* After sending SMS is moved to Sent Items or Error Items. */ 291/* After sending SMS is moved to Sent Items or Error Items. */
248static GSM_Error SMSDFiles_MoveSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, bool alwaysDelete, bool sent) 292static GSM_Error SMSDFiles_MoveSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, bool alwaysDelete, bool sent)
249{ 293{
250 FILE *oFile,*iFile; 294 FILE *oFile,*iFile;
251 int ilen = 0, olen = 0; 295 int ilen = 0, olen = 0;
252 char Buffer[(GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS+1)*2],ifilename[400],ofilename[400]; 296 char Buffer[(GSM_MAX_SMS_LENGTH*MAX_MULTI_SMS+1)*2],ifilename[400],ofilename[400];
253 char*sourcepath, *destpath; 297 char*sourcepath, *destpath;
254 298
255 sourcepath = Config->outboxpath; 299 sourcepath = Config->outboxpath;
256 if (sent) { 300 if (sent) {
257 destpath = Config->sentsmspath; 301 destpath = Config->sentsmspath;
258 } else { 302 } else {
259 destpath = Config->errorsmspath; 303 destpath = Config->errorsmspath;
260 } 304 }
261 305
262 strcpy(ifilename, sourcepath); 306 strcpy(ifilename, sourcepath);
263 strcat(ifilename, ID); 307 strcat(ifilename, ID);
264 strcpy(ofilename, destpath); 308 strcpy(ofilename, destpath);
265 strcat(ofilename, ID); 309 strcat(ofilename, ID);
266 310
267#ifdef WIN32 311#ifdef WIN32
268 if (!mystrncasecmp(ifilename, ofilename, strlen(ofilename))) { 312 if (!mystrncasecmp(ifilename, ofilename, strlen(ofilename))) {
269#else 313#else
270 if (strcmp(ifilename, ofilename) != 0) { 314 if (strcmp(ifilename, ofilename) != 0) {
271#endif 315#endif
272 iFile = fopen(ifilename, "r"); 316 iFile = fopen(ifilename, "r");
273 ilen = fread(Buffer, 1, sizeof(Buffer), iFile); 317 ilen = fread(Buffer, 1, sizeof(Buffer), iFile);
274 fclose(iFile); 318 fclose(iFile);
275 oFile = fopen(ofilename, "w"); 319 oFile = fopen(ofilename, "w");
276 olen = fwrite(Buffer, 1, ilen, oFile); 320 olen = fwrite(Buffer, 1, ilen, oFile);
277 fclose(oFile); 321 fclose(oFile);
278 } 322 }
279 if (ilen == olen) { 323 if (ilen == olen) {
280 if ((strcmp(ifilename, "/") == 0) || (remove(ifilename) != 0)) { 324 if ((strcmp(ifilename, "/") == 0) || (remove(ifilename) != 0)) {
281 WriteSMSDLog("Could not delete %s (%i)", ifilename, errno); 325 WriteSMSDLog("Could not delete %s (%i)", ifilename, errno);
282 return ERR_UNKNOWN; 326 return ERR_UNKNOWN;
283 } 327 }
284 return ERR_NONE; 328 return ERR_NONE;
285 } else { 329 } else {
286 WriteSMSDLog("Error copying SMS %s -> %s", ifilename, ofilename); 330 WriteSMSDLog("Error copying SMS %s -> %s", ifilename, ofilename);
287 if (alwaysDelete) { 331 if (alwaysDelete) {
288 if ((strcmp(ifilename, "/") == 0) || (remove(ifilename) != 0)) 332 if ((strcmp(ifilename, "/") == 0) || (remove(ifilename) != 0))
289 WriteSMSDLog("Could not delete %s (%i)", ifilename, errno); 333 WriteSMSDLog("Could not delete %s (%i)", ifilename, errno);
290 } 334 }
291 return ERR_UNKNOWN; 335 return ERR_UNKNOWN;
292 } 336 }
293} 337}
294 338
295static GSM_Error SMSDFiles_AddSentSMSInfo(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, bool OK) 339static GSM_Error SMSDFiles_AddSentSMSInfo(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, GSM_SMSDSendingError err, int TPMR)
296{ 340{
297 if (OK) WriteSMSDLog("Transmitted %s (%s: %i) to %s", Config->SMSID, (Part == sms->Number?"total":"part"),Part,DecodeUnicodeString(sms->SMS[0].Number)); 341 if (err == SMSD_SEND_OK) WriteSMSDLog("Transmitted %s (%s: %i) to %s", Config->SMSID, (Part == sms->Number?"total":"part"),Part,DecodeUnicodeString(sms->SMS[0].Number));
298 342
299 return ERR_NONE; 343 return ERR_NONE;
300} 344}
301 345
302GSM_SMSDService SMSDFiles = { 346GSM_SMSDService SMSDFiles = {
303 NONEFUNCTION, /* Init */ 347 NONEFUNCTION, /* Init */
348 NONEFUNCTION, /* InitAfterConnect */
304 SMSDFiles_SaveInboxSMS, 349 SMSDFiles_SaveInboxSMS,
305 SMSDFiles_FindOutboxSMS, 350 SMSDFiles_FindOutboxSMS,
306 SMSDFiles_MoveSMS, 351 SMSDFiles_MoveSMS,
307 NOTSUPPORTED, /* CreateOutboxSMS*/ 352 NOTSUPPORTED, /* CreateOutboxSMS*/
308 SMSDFiles_AddSentSMSInfo 353 SMSDFiles_AddSentSMSInfo,
354 NOTSUPPORTED, /* RefreshSendStatus*/
355 NOTSUPPORTED /* RefreshPhoneStatus*/
309}; 356};
310 357
311/* How should editor hadle tabs in this file? Add editor commands here. 358/* How should editor handle tabs in this file? Add editor commands here.
312 * vim: noexpandtab sw=8 ts=8 sts=8: 359 * vim: noexpandtab sw=8 ts=8 sts=8:
313 */ 360 */
diff --git a/gammu/emb/gammu/smsd/s_files.h b/gammu/emb/gammu/smsd/s_files.h
index 5cfa05f..ed07ef3 100644
--- a/gammu/emb/gammu/smsd/s_files.h
+++ b/gammu/emb/gammu/smsd/s_files.h
@@ -1,7 +1,7 @@
1/* (c) 2002-2003 by Joergen Thomsen */ 1/* (c) 2002-2004 by Joergen Thomsen */
2 2
3extern GSM_SMSDService SMSDFiles; 3extern GSM_SMSDService SMSDFiles;
4 4
5/* How should editor hadle tabs in this file? Add editor commands here. 5/* How should editor hadle tabs in this file? Add editor commands here.
6 * vim: noexpandtab sw=8 ts=8 sts=8: 6 * vim: noexpandtab sw=8 ts=8 sts=8:
7 */ 7 */
diff --git a/gammu/emb/gammu/smsd/s_mysql.c b/gammu/emb/gammu/smsd/s_mysql.c
index dacc256..5df15e9 100644
--- a/gammu/emb/gammu/smsd/s_mysql.c
+++ b/gammu/emb/gammu/smsd/s_mysql.c
@@ -1,414 +1,724 @@
1/* (c) 2004 by Marcin Wiacek */ 1/* (c) 2004 by Marcin Wiacek */
2 2
3#include "../../cfg/config.h" 3#include "../../cfg/config.h"
4 4
5#ifdef HAVE_MYSQL_MYSQL_H 5#ifdef HAVE_MYSQL_MYSQL_H
6 6
7#include <string.h> 7#include <string.h>
8#include <stdio.h> 8#include <stdio.h>
9#include <errno.h> 9#include <errno.h>
10#include <time.h> 10#include <time.h>
11#ifdef WIN32 11#ifdef WIN32
12# include <windows.h> 12# include <windows.h>
13# pragma comment(lib, "libmysql.lib") 13# pragma comment(lib, "libmysql.lib")
14#endif 14#endif
15 15
16#include "../../common/misc/coding/coding.h" 16#include "../../common/misc/coding/coding.h"
17#include "../../common/service/backup/gsmback.h" 17#include "../../common/service/backup/gsmback.h"
18#include "../gammu.h"
18#include "smsdcore.h" 19#include "smsdcore.h"
19 20
20/* Connects to database */ 21/* Connects to database */
21static GSM_Error SMSDMySQL_Init(GSM_SMSDConfig *Config) 22static GSM_Error SMSDMySQL_Init(GSM_SMSDConfig *Config)
22{ 23{
24 unsigned char buf[400];
25 MYSQL_RES *Res;
26 MYSQL_ROW Row;
27
23 mysql_init(&Config->DB); 28 mysql_init(&Config->DB);
24 if (!mysql_real_connect(&Config->DB,Config->PC,Config->user,Config->password,Config->database,0,NULL,0)) { 29 if (!mysql_real_connect(&Config->DB,Config->PC,Config->user,Config->password,Config->database,0,NULL,0)) {
25 WriteSMSDLog("Error connecting to database: %s\n", mysql_error(&Config->DB)); 30 WriteSMSDLog("Error connecting to database: %s\n", mysql_error(&Config->DB));
26 return ERR_UNKNOWN; 31 return ERR_UNKNOWN;
32 }
33 sprintf(buf, "SELECT ID FROM `outbox` WHERE 1");
34 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
35 WriteSMSDLog("No table for outbox sms: %s\n", mysql_error(&Config->DB));
36 return ERR_UNKNOWN;
37 }
38 if (!(Res = mysql_store_result(&Config->DB))) {
39 WriteSMSDLog("No table for outbox sms: %s\n", mysql_error(&Config->DB));
40 return ERR_UNKNOWN;
27 } 41 }
42 mysql_free_result(Res);
43 sprintf(buf, "SELECT ID FROM `outbox_multipart` WHERE 1");
44 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
45 WriteSMSDLog("No table for outbox sms: %s\n", mysql_error(&Config->DB));
46 return ERR_UNKNOWN;
47 }
48 if (!(Res = mysql_store_result(&Config->DB))) {
49 WriteSMSDLog("No table for outbox sms: %s\n", mysql_error(&Config->DB));
50 return ERR_UNKNOWN;
51 }
52 mysql_free_result(Res);
53 sprintf(buf, "SELECT ID FROM `sentitems` WHERE 1");
54 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
55 WriteSMSDLog("No table for sent sms: %s\n", mysql_error(&Config->DB));
56 return ERR_UNKNOWN;
57 }
58 if (!(Res = mysql_store_result(&Config->DB))) {
59 WriteSMSDLog("No table for sent sms: %s\n", mysql_error(&Config->DB));
60 return ERR_UNKNOWN;
61 }
62 mysql_free_result(Res);
63 sprintf(buf, "SELECT ID FROM `inbox` WHERE 1");
64 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
65 WriteSMSDLog("No table for inbox sms: %s\n", mysql_error(&Config->DB));
66 return ERR_UNKNOWN;
67 }
68 if (!(Res = mysql_store_result(&Config->DB))) {
69 WriteSMSDLog("No table for inbox sms: %s\n", mysql_error(&Config->DB));
70 return ERR_UNKNOWN;
71 }
72 mysql_free_result(Res);
73 sprintf(buf, "SELECT Version FROM `gammu` WHERE 1");
74 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
75 WriteSMSDLog("No Gammu table: %s\n", mysql_error(&Config->DB));
76 return ERR_UNKNOWN;
77 }
78 if (!(Res = mysql_store_result(&Config->DB))) {
79 WriteSMSDLog("No Gammu table: %s\n", mysql_error(&Config->DB));
80 return ERR_UNKNOWN;
81 }
82 if (!(Row = mysql_fetch_row(Res))) {
83 mysql_free_result(Res);
84 WriteSMSDLog("No version info in Gammu table: %s\n", mysql_error(&Config->DB));
85 return ERR_UNKNOWN;
86 }
87 if (atoi(Row[0]) > 4) {
88 mysql_free_result(Res);
89 WriteSMSDLog("DataBase structures are from higher Gammu version");
90 WriteSMSDLog("Please update this client application");
91 return ERR_UNKNOWN;
92 }
93 if (atoi(Row[0]) < 4) {
94 mysql_free_result(Res);
95 WriteSMSDLog("DataBase structures are from older Gammu version");
96 WriteSMSDLog("Please update DataBase, if you want to use this client application");
97 return ERR_UNKNOWN;
98 }
99 mysql_free_result(Res);
100
101 return ERR_NONE;
102}
103
104static GSM_Error SMSDMySQL_InitAfterConnect(GSM_SMSDConfig *Config)
105{
106 unsigned char buf[400],buf2[200];
107
108 sprintf(buf,"DELETE FROM `phones` WHERE `IMEI` = '%s'",s.Phone.Data.IMEI);
109#ifdef DEBUG
110 fprintf(stdout,"%s\n",buf);
111#endif
112 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
113 WriteSMSDLog("Error deleting from database (Init): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
114 return ERR_UNKNOWN;
115 }
116
117 sprintf(buf2,"Gammu %s",VERSION);
118 if (strlen(GetOS()) != 0) {
119 strcat(buf2+strlen(buf2),", ");
120 strcat(buf2+strlen(buf2),GetOS());
121 }
122 if (strlen(GetCompiler()) != 0) {
123 strcat(buf2+strlen(buf2),", ");
124 strcat(buf2+strlen(buf2),GetCompiler());
125 }
126
127 sprintf(buf,"INSERT INTO `phones` (`IMEI`,`ID`,`Send`,`Receive`,`InsertIntoDB`,`TimeOut`,`Client`) VALUES ('%s','%s','yes','yes',NOW(),(NOW() + INTERVAL 10 SECOND)+0,'%s')",s.Phone.Data.IMEI,Config->PhoneID,buf2);
128#ifdef DEBUG
129 fprintf(stdout,"%s\n",buf);
130#endif
131 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
132 WriteSMSDLog("Error deleting from database (Init): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
133 return ERR_UNKNOWN;
134 }
135
28 return ERR_NONE; 136 return ERR_NONE;
29} 137}
30 138
31/* Save SMS from phone (called Inbox sms - it's in phone Inbox) somewhere */ 139/* Save SMS from phone (called Inbox sms - it's in phone Inbox) somewhere */
32static GSM_Error SMSDMySQL_SaveInboxSMS(GSM_MultiSMSMessage sms, GSM_SMSDConfig *Config) 140static GSM_Error SMSDMySQL_SaveInboxSMS(GSM_MultiSMSMessage sms, GSM_SMSDConfig *Config)
33{ 141{
34 unsigned charbuffer[10000],buffer2[200],buffer3[2]; 142 MYSQL_RES *Res;
35 int i,j,z; 143 MYSQL_ROW Row;
144 unsigned char buffer[10000],buffer2[200],buffer3[50];
145 int i,j,z;
146 GSM_DateTime DT;
147 time_t t_time1,t_time2;
148 bool found;
149 long diff;
36 150
37 for (i=0;i<sms.Number;i++) { 151 for (i=0;i<sms.Number;i++) {
38 if ((sms.SMS[i].PDU == SMS_Status_Report) && mystrncasecmp(Config->deliveryreport, "log", 3)) { 152 if (sms.SMS[i].PDU == SMS_Status_Report) {
39 strcpy(buffer, DecodeUnicodeString(sms.SMS[i].Number)); 153 strcpy(buffer2, DecodeUnicodeString(sms.SMS[i].Number));
40 WriteSMSDLog("Delivery report: %s to %s", DecodeUnicodeString(sms.SMS[i].Text), buffer); 154 if (mystrncasecmp(Config->deliveryreport, "log", 3)) {
155 WriteSMSDLog("Delivery report: %s to %s", DecodeUnicodeString(sms.SMS[i].Text), buffer2);
156 }
157
158 sprintf(buffer, "SELECT ID,Status,SendingDateTime,DeliveryDateTime,SMSCNumber FROM `sentitems` WHERE \
159 DeliveryDateTime='00000000000000' AND \
160 SenderID='%s' AND TPMR='%i' AND DestinationNumber='%s'",
161 Config->PhoneID, sms.SMS[i].MessageReference, buffer2);
162#ifdef DEBUG
163 fprintf(stdout,"%s\n",buffer);
164#endif
165 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
166 WriteSMSDLog("Error reading from database (SaveInbox): %s %s\n", buffer, mysql_error(&Config->DB));
167 return ERR_UNKNOWN;
168 }
169 if (!(Res = mysql_store_result(&Config->DB))) {
170 WriteSMSDLog("Error reading from database (SaveInbox): %s\n", mysql_error(&Config->DB));
171 return ERR_UNKNOWN;
172 }
173 found = false;
174 while ((Row = mysql_fetch_row(Res))) {
175 if (strcmp(Row[4],DecodeUnicodeString(sms.SMS[i].SMSC.Number))) {
176 if (Config->skipsmscnumber[0] == 0) continue;
177 if (strcmp(Config->skipsmscnumber,Row[4])) continue;
178 }
179 if (!strcmp(Row[1],"SendingOK") || !strcmp(Row[1],"DeliveryPending")) {
180 sprintf(buffer,"%c%c%c%c",Row[2][0],Row[2][1],Row[2][2],Row[2][3]);
181 DT.Year = atoi(buffer);
182 sprintf(buffer,"%c%c",Row[2][4],Row[2][5]);
183 DT.Month = atoi(buffer);
184 sprintf(buffer,"%c%c",Row[2][6],Row[2][7]);
185 DT.Day = atoi(buffer);
186 sprintf(buffer,"%c%c",Row[2][8],Row[2][9]);
187 DT.Hour = atoi(buffer);
188 sprintf(buffer,"%c%c",Row[2][10],Row[2][11]);
189 DT.Minute = atoi(buffer);
190 sprintf(buffer,"%c%c",Row[2][12],Row[2][13]);
191 DT.Second = atoi(buffer);
192 t_time1 = Fill_Time_T(DT,0);
193 t_time2 = Fill_Time_T(sms.SMS[i].DateTime,0);
194 diff = t_time2 - t_time1;
195 // fprintf(stderr,"diff is %i, %i-%i-%i-%i-%i and %i-%i-%i-%i-%i-%i\n",diff,
196 // DT.Year,DT.Month,DT.Day,DT.Hour,DT.Minute,DT.Second,
197 // sms.SMS[i].DateTime.Year,sms.SMS[i].DateTime.Month,sms.SMS[i].DateTime.Day,sms.SMS[i].DateTime.Hour,sms.SMS[i].DateTime.Minute,sms.SMS[i].DateTime.Second);
198 if (diff > -10 && diff < 10) {
199 found = true;
200 break;
201 }
202 }
203 }
204 if (found) {
205 sprintf(buffer,"UPDATE `sentitems` SET `DeliveryDateTime`='%04i%02i%02i%02i%02i%02i', `Status`='",
206 sms.SMS[i].SMSCTime.Year,sms.SMS[i].SMSCTime.Month,sms.SMS[i].SMSCTime.Day,
207 sms.SMS[i].SMSCTime.Hour,sms.SMS[i].SMSCTime.Minute,sms.SMS[i].SMSCTime.Second);
208 sprintf(buffer3,"%s",DecodeUnicodeString(sms.SMS[i].Text));
209 if (!strcmp(buffer3,"Delivered")) {
210 sprintf(buffer+strlen(buffer),"DeliveryOK");
211 } else if (!strcmp(buffer3,"Failed")) {
212 sprintf(buffer+strlen(buffer),"DeliveryFailed");
213 } else if (!strcmp(buffer3,"Pending")) {
214 sprintf(buffer+strlen(buffer),"DeliveryPending");
215 } else if (!strcmp(buffer3,"Unknown")) {
216 sprintf(buffer+strlen(buffer),"DeliveryUnknown");
217 }
218 sprintf(buffer+strlen(buffer),"', `StatusError` = '%i'",sms.SMS[i].DeliveryStatus);
219 sprintf(buffer+strlen(buffer)," WHERE `ID` = '%s' AND `TPMR` = '%i'",Row[0],sms.SMS[i].MessageReference);
220#ifdef DEBUG
221 fprintf(stdout,"%s\n",buffer);
222#endif
223 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
224 WriteSMSDLog("Error writing to database (SaveInboxSMS): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
225 return ERR_UNKNOWN;
226 }
227 }
228 mysql_free_result(Res);
41 continue; 229 continue;
42 } 230 }
43 if (sms.SMS[i].PDU != SMS_Deliver) continue; 231 if (sms.SMS[i].PDU != SMS_Deliver) continue;
44 buffer[0]=0; 232 buffer[0]=0;
45 sprintf(buffer+strlen(buffer),"INSERT INTO `Inbox` \ 233 sprintf(buffer+strlen(buffer),"INSERT INTO `inbox` \
46 (`DateTime`,`Text`,`SenderNumber`,`Coding`,`SMSCNumber`,`UDH`, \ 234 (`ReceivingDateTime`,`Text`,`SenderNumber`,`Coding`,`SMSCNumber`,`UDH`, \
47 `Class`,`TextDecoded`) VALUES ('%04d%02d%02d%02d%02d%02d','", 235 `Class`,`TextDecoded`,`RecipientID`) VALUES ('%04d%02d%02d%02d%02d%02d','",
48 sms.SMS[i].DateTime.Year,sms.SMS[i].DateTime.Month,sms.SMS[i].DateTime.Day, 236 sms.SMS[i].DateTime.Year,sms.SMS[i].DateTime.Month,sms.SMS[i].DateTime.Day,
49 sms.SMS[i].DateTime.Hour,sms.SMS[i].DateTime.Minute,sms.SMS[i].DateTime.Second); 237 sms.SMS[i].DateTime.Hour,sms.SMS[i].DateTime.Minute,sms.SMS[i].DateTime.Second);
50 switch (sms.SMS[i].Coding) { 238 switch (sms.SMS[i].Coding) {
51 case SMS_Coding_Unicode: 239 case SMS_Coding_Unicode:
52 case SMS_Coding_Default: 240 case SMS_Coding_Default:
53 EncodeHexUnicode(buffer+strlen(buffer),sms.SMS[i].Text,UnicodeLength(sms.SMS[i].Text)); 241 EncodeHexUnicode(buffer+strlen(buffer),sms.SMS[i].Text,UnicodeLength(sms.SMS[i].Text));
54 break; 242 break;
55 case SMS_Coding_8bit: 243 case SMS_Coding_8bit:
56 EncodeHexBin(buffer+strlen(buffer),sms.SMS[i].Text,sms.SMS[i].Length); 244 EncodeHexBin(buffer+strlen(buffer),sms.SMS[i].Text,sms.SMS[i].Length);
57 } 245 }
58 sprintf(buffer+strlen(buffer),"','%s','",DecodeUnicodeString(sms.SMS[i].Number)); 246 sprintf(buffer+strlen(buffer),"','%s','",DecodeUnicodeString(sms.SMS[i].Number));
59 switch (sms.SMS[i].Coding) { 247 switch (sms.SMS[i].Coding) {
60 case SMS_Coding_Unicode: 248 case SMS_Coding_Unicode:
61 sprintf(buffer+strlen(buffer),"Unicode"); 249 sprintf(buffer+strlen(buffer),"Unicode");
62 break; 250 break;
63 case SMS_Coding_Default: 251 case SMS_Coding_Default:
64 sprintf(buffer+strlen(buffer),"Default"); 252 sprintf(buffer+strlen(buffer),"Default");
65 break; 253 break;
66 case SMS_Coding_8bit: 254 case SMS_Coding_8bit:
67 sprintf(buffer+strlen(buffer),"8bit"); 255 sprintf(buffer+strlen(buffer),"8bit");
68 break; 256 break;
69 } 257 }
70 sprintf(buffer+strlen(buffer),"','%s'",DecodeUnicodeString(sms.SMS[i].SMSC.Number)); 258 sprintf(buffer+strlen(buffer),"','%s'",DecodeUnicodeString(sms.SMS[i].SMSC.Number));
71 if (sms.SMS[i].UDH.Type == UDH_NoUDH) { 259 if (sms.SMS[i].UDH.Type == UDH_NoUDH) {
72 sprintf(buffer+strlen(buffer),",''"); 260 sprintf(buffer+strlen(buffer),",''");
73 } else { 261 } else {
74 sprintf(buffer+strlen(buffer),",'"); 262 sprintf(buffer+strlen(buffer),",'");
75 EncodeHexBin(buffer+strlen(buffer),sms.SMS[i].UDH.Text,sms.SMS[i].UDH.Length); 263 EncodeHexBin(buffer+strlen(buffer),sms.SMS[i].UDH.Text,sms.SMS[i].UDH.Length);
76 sprintf(buffer+strlen(buffer),"'"); 264 sprintf(buffer+strlen(buffer),"'");
77 } 265 }
78 sprintf(buffer+strlen(buffer),",'%i','",sms.SMS[i].Class); 266 sprintf(buffer+strlen(buffer),",'%i','",sms.SMS[i].Class);
79 switch (sms.SMS[i].Coding) { 267 switch (sms.SMS[i].Coding) {
80 case SMS_Coding_Unicode: 268 case SMS_Coding_Unicode:
81 case SMS_Coding_Default: 269 case SMS_Coding_Default:
82 sprintf(buffer2,"%s",DecodeUnicodeString(sms.SMS[i].Text)); 270 sprintf(buffer2,"%s",DecodeUnicodeString(sms.SMS[i].Text));
83 for (j=0;j<(int)strlen(buffer2);j++) { 271 for (j=0;j<(int)strlen(buffer2);j++) {
84 sprintf(buffer3,"'"); 272 sprintf(buffer3,"'");
85 z = strlen(buffer); 273 z = strlen(buffer);
86 if (buffer2[j]==buffer3[0]) { 274 if (buffer2[j]==buffer3[0]) {
87 buffer[z+2]=0; 275 buffer[z+2]=0;
88 buffer[z+1]=buffer2[j]; 276 buffer[z+1]=buffer2[j];
89 buffer[z] ='\\'; 277 buffer[z] ='\\';
90 } else { 278 } else {
91 buffer[z+1]=0; 279 buffer[z+1]=0;
92 buffer[z] =buffer2[j]; 280 buffer[z] =buffer2[j];
93 } 281 }
94 } 282 }
95 break; 283 break;
96 case SMS_Coding_8bit: 284 case SMS_Coding_8bit:
97 break; 285 break;
98 } 286 }
99 sprintf(buffer+strlen(buffer),"')"); 287 sprintf(buffer+strlen(buffer),"','%s')",Config->PhoneID);
288#ifdef DEBUG
289 fprintf(stdout,"%s\n",buffer);
290#endif
100 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { 291 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
101 WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); 292 WriteSMSDLog("Error writing to database (SaveInbox): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
102 return ERR_UNKNOWN; 293 return ERR_UNKNOWN;
103 } 294 }
104 } 295 }
105 296
106 return ERR_NONE; 297 return ERR_NONE;
107} 298}
108 299
300static GSM_Error SMSDMySQL_RefreshSendStatus(GSM_SMSDConfig *Config, unsigned char *ID)
301{
302 unsigned char buffer[10000];
303
304 sprintf(buffer,"UPDATE `outbox` SET `SendingTimeOut`=(now() + INTERVAL 15 SECOND)+0 WHERE `ID` = '%s' AND `SendingTimeOut` < now()",ID);
305 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
306 WriteSMSDLog("Error writing to database (RefreshSendStatus): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
307 return ERR_UNKNOWN;
308 }
309#ifdef DEBUG
310 fprintf(stdout,"%s\n",buffer);
311 #endif
312 if (mysql_affected_rows(&Config->DB) == 0) return ERR_UNKNOWN;
313 return ERR_NONE;
314}
315
109/* Find one multi SMS to sending and return it (or return ERR_EMPTY) 316/* Find one multi SMS to sending and return it (or return ERR_EMPTY)
110 * There is also set ID for SMS 317 * There is also set ID for SMS
111 */ 318 */
112static GSM_Error SMSDMySQL_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID) 319static GSM_Error SMSDMySQL_FindOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID)
113{ 320{
114 unsigned char buf[400]; 321 unsigned char buf[400];
115 MYSQL_RES *Res; 322 MYSQL_RES *Res;
116 MYSQL_ROW Row; 323 MYSQL_ROW Row;
117 int i; 324 int i;
325 bool found = false;
118 326
119 sprintf(buf, "SELECT ID,DateTime FROM `Outbox` WHERE 1"); 327 sprintf(buf, "SELECT ID,InsertIntoDB,SendingDateTime,SenderID FROM `outbox` WHERE SendingDateTime < NOW() AND SendingTimeOut < NOW()");
120 if (mysql_real_query(&Config->DB,buf,strlen(buf))) { 328 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
121 WriteSMSDLog("Error reading from database: %s\n", mysql_error(&Config->DB)); 329 WriteSMSDLog("Error reading from database (FindOutbox): %s\n", mysql_error(&Config->DB));
122 return ERR_UNKNOWN; 330 return ERR_UNKNOWN;
123 } 331 }
124 if (!(Res = mysql_store_result(&Config->DB))) { 332 if (!(Res = mysql_store_result(&Config->DB))) {
125 WriteSMSDLog("Error reading from database: %s\n", mysql_error(&Config->DB)); 333 WriteSMSDLog("Error reading from database (FindOutbox): %s\n", mysql_error(&Config->DB));
126 return ERR_UNKNOWN; 334 return ERR_UNKNOWN;
127 } 335 }
128 if (!(Row = mysql_fetch_row(Res))) { 336 while ((Row = mysql_fetch_row(Res))) {
337 sprintf(ID,"%s",Row[0]);
338 sprintf(Config->DT,"%s",Row[1]);
339 if (strlen(Row[3]) == 0 || !strcmp(Row[3],Config->PhoneID)) {
340 if (SMSDMySQL_RefreshSendStatus(Config, ID)==ERR_NONE) {
341 found = true;
342 break;
343 }
344 }
345 }
346 if (!found) {
129 mysql_free_result(Res); 347 mysql_free_result(Res);
130 return ERR_EMPTY; 348 return ERR_EMPTY;
131 } 349 }
132 sprintf(ID,"%s",Row[0]); 350 mysql_free_result(Res);
133 sprintf(Config->DT,"%s",Row[1]);
134 sms->Number = 0; 351 sms->Number = 0;
135 for (i=1;i<10;i++) { 352 for (i=0;i<MAX_MULTI_SMS;i++) {
136 GSM_SetDefaultSMSData(&sms->SMS[sms->Number]); 353 GSM_SetDefaultSMSData(&sms->SMS[i]);
354 sms->SMS[i].SMSC.Number[0] = 0;
355 sms->SMS[i].SMSC.Number[1] = 0;
356 }
357 for (i=1;i<MAX_MULTI_SMS+1;i++) {
137 if (i==1) { 358 if (i==1) {
138 sprintf(buf, "SELECT Text,DestinationNumber,Coding,UDH,SMSCNumber,Class,TextDecoded,ID,MultiPart FROM `Outbox` WHERE ID='%s'",ID); 359 sprintf(buf, "SELECT Text,Coding,UDH,Class,TextDecoded,ID,DestinationNumber,MultiPart,RelativeValidity,DeliveryReport FROM `outbox` WHERE ID='%s'",ID);
139 } else { 360 } else {
140 sprintf(buf, "SELECT Text,DestinationNumber,Coding,UDH,SMSCNumber,Class,TextDecoded,ID,SequencePosition FROM `Outbox_MultiPart` WHERE ID='%s' AND SequencePosition='%i'",ID,i); 361 sprintf(buf, "SELECT Text,Coding,UDH,Class,TextDecoded,ID,SequencePosition FROM `outbox_multipart` WHERE ID='%s' AND SequencePosition='%i'",ID,i);
141 } 362 }
363#ifdef DEBUG
364 fprintf(stdout,"%s\n",buf);
365#endif
142 if (mysql_real_query(&Config->DB,buf,strlen(buf))) { 366 if (mysql_real_query(&Config->DB,buf,strlen(buf))) {
143 WriteSMSDLog("Error reading from database: %s\n", mysql_error(&Config->DB)); 367 WriteSMSDLog("Error reading from database (FindOutbox): %s\n", mysql_error(&Config->DB));
144 return ERR_UNKNOWN; 368 return ERR_UNKNOWN;
145 } 369 }
146 if (!(Res = mysql_store_result(&Config->DB))) { 370 if (!(Res = mysql_store_result(&Config->DB))) {
147 WriteSMSDLog("Error reading from database: %s\n", mysql_error(&Config->DB)); 371 WriteSMSDLog("Error reading from database (FindOutbox): %s\n", mysql_error(&Config->DB));
148 return ERR_UNKNOWN; 372 return ERR_UNKNOWN;
149 } 373 }
150 if (!(Row = mysql_fetch_row(Res))) { 374 if (!(Row = mysql_fetch_row(Res))) {
151 mysql_free_result(Res); 375 mysql_free_result(Res);
152 return ERR_NONE; 376 return ERR_NONE;
153 } 377 }
154 378
155 sms->SMS[sms->Number].Coding=SMS_Coding_Default; 379 sms->SMS[sms->Number].Coding=SMS_Coding_Default;
156 if (!strcmp(Row[2],"Unicode")) sms->SMS[sms->Number].Coding=SMS_Coding_Unicode; 380 if (!strcmp(Row[1],"Unicode")) sms->SMS[sms->Number].Coding=SMS_Coding_Unicode;
157 if (!strcmp(Row[2],"8bit")) sms->SMS[sms->Number].Coding=SMS_Coding_8bit; 381 if (!strcmp(Row[1],"8bit")) sms->SMS[sms->Number].Coding=SMS_Coding_8bit;
158 382
159 if (strlen(Row[0])==0) { 383 if (strlen(Row[0])==0) {
160 EncodeUnicode(sms->SMS[sms->Number].Text,Row[6],strlen(Row[6])); 384 EncodeUnicode(sms->SMS[sms->Number].Text,Row[4],strlen(Row[4]));
161 } else { 385 } else {
162 switch (sms->SMS[sms->Number].Coding) { 386 switch (sms->SMS[sms->Number].Coding) {
163 case SMS_Coding_Unicode: 387 case SMS_Coding_Unicode:
164 case SMS_Coding_Default: 388 case SMS_Coding_Default:
165 DecodeHexUnicode(sms->SMS[sms->Number].Text,Row[0],strlen(Row[0])); 389 DecodeHexUnicode(sms->SMS[sms->Number].Text,Row[0],strlen(Row[0]));
166 break; 390 break;
167 case SMS_Coding_8bit: 391 case SMS_Coding_8bit:
168 DecodeHexBin(sms->SMS[sms->Number].Text,Row[0],strlen(Row[0])); 392 DecodeHexBin(sms->SMS[sms->Number].Text,Row[0],strlen(Row[0]));
169 sms->SMS[sms->Number].Length=strlen(Row[0])/2; 393 sms->SMS[sms->Number].Length=strlen(Row[0])/2;
170 } 394 }
171 } 395 }
172 EncodeUnicode(sms->SMS[sms->Number].Number,Row[1],strlen(Row[1])); 396 if (i == 1) {
397 EncodeUnicode(sms->SMS[sms->Number].Number,Row[6],strlen(Row[6]));
398 } else {
399 CopyUnicodeString(sms->SMS[sms->Number].Number,sms->SMS[0].Number);
400 }
173 sms->SMS[sms->Number].UDH.Type = UDH_NoUDH; 401 sms->SMS[sms->Number].UDH.Type = UDH_NoUDH;
174 if (strlen(Row[3])!=0) { 402 if (strlen(Row[2])!=0) {
175 sms->SMS[sms->Number].UDH.Type = UDH_UserUDH; 403 sms->SMS[sms->Number].UDH.Type = UDH_UserUDH;
176 sms->SMS[sms->Number].UDH.Length = strlen(Row[3])/2; 404 sms->SMS[sms->Number].UDH.Length = strlen(Row[2])/2;
177 DecodeHexBin(sms->SMS[sms->Number].UDH.Text,Row[3],strlen(Row[3])); 405 DecodeHexBin(sms->SMS[sms->Number].UDH.Text,Row[2],strlen(Row[2]));
178 } 406 }
179 EncodeUnicode(sms->SMS[sms->Number].SMSC.Number,Row[4],strlen(Row[4])); 407 sms->SMS[sms->Number].Class = atoi(Row[3]);
180 sms->SMS[sms->Number].Class = atoi(Row[5]);
181 sms->SMS[sms->Number].PDU = SMS_Submit; 408 sms->SMS[sms->Number].PDU = SMS_Submit;
182 sms->SMS[sms->Number].SMSC.Location = 0; 409 sms->Number++;
183 sms->Number++; 410 if (i==1) {
184 if (i == 1 && !strcmp(Row[8],"false")) break; 411 Config->relativevalidity = atoi(Row[8]);
412
413 Config->currdeliveryreport = -1;
414 if (!strcmp(Row[9],"yes")) {
415 Config->currdeliveryreport = 1;
416 } else if (!strcmp(Row[9],"no")) {
417 Config->currdeliveryreport = 0;
418 }
419
420 if (!strcmp(Row[7],"false")) break;
421
422 }
185 } 423 }
424 mysql_free_result(Res);
186 return ERR_NONE; 425 return ERR_NONE;
187} 426}
188 427
189/* After sending SMS is moved to Sent Items or Error Items. */ 428/* After sending SMS is moved to Sent Items or Error Items. */
190static GSM_Error SMSDMySQL_MoveSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, bool alwaysDelete, bool sent) 429static GSM_Error SMSDMySQL_MoveSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, bool alwaysDelete, bool sent)
191{ 430{
192 char *status; 431 unsigned char buffer[10000];
193 unsigned charbuffer[10000],buffer2[200],buffer3[2];
194 int i,j,z;
195
196 if (sent) status = "OK"; else status = "Error";
197
198 for (i=0;i<sms->Number;i++) {
199 buffer[0]=0;
200 sprintf(buffer+strlen(buffer),"UPDATE `SentItems` SET `Text`='");
201
202 switch (sms->SMS[i].Coding) {
203 case SMS_Coding_Unicode:
204 case SMS_Coding_Default:
205 EncodeHexUnicode(buffer+strlen(buffer),sms->SMS[i].Text,UnicodeLength(sms->SMS[i].Text));
206 break;
207 case SMS_Coding_8bit:
208 EncodeHexBin(buffer+strlen(buffer),sms->SMS[i].Text,sms->SMS[i].Length);
209 }
210
211 sprintf(buffer+strlen(buffer),"',`DestinationNumber`='%s',`Coding`='",DecodeUnicodeString(sms->SMS[i].Number));
212
213 switch (sms->SMS[i].Coding) {
214 case SMS_Coding_Unicode:
215 sprintf(buffer+strlen(buffer),"Unicode");
216 break;
217 case SMS_Coding_Default:
218 sprintf(buffer+strlen(buffer),"Default");
219 break;
220 case SMS_Coding_8bit:
221 sprintf(buffer+strlen(buffer),"8bit");
222 break;
223 }
224
225 sprintf(buffer+strlen(buffer),"',`SMSCNumber`='%s',`UDH`='",DecodeUnicodeString(sms->SMS[i].SMSC.Number));
226 if (sms->SMS[i].UDH.Type != UDH_NoUDH) {
227 EncodeHexBin(buffer+strlen(buffer),sms->SMS[i].UDH.Text,sms->SMS[i].UDH.Length);
228 }
229 432
230 sprintf(buffer+strlen(buffer),"',`Class`='%i',`TextDecoded`='",sms->SMS[i].Class); 433 sprintf(buffer,"DELETE FROM `outbox` WHERE `ID` = '%s'",ID);
231 switch (sms->SMS[i].Coding) {
232 case SMS_Coding_Unicode:
233 case SMS_Coding_Default:
234 sprintf(buffer2,"%s",DecodeUnicodeString(sms->SMS[i].Text));
235 for (j=0;j<(int)strlen(buffer2);j++) {
236 sprintf(buffer3,"'");
237 z = strlen(buffer);
238 if (buffer2[j]==buffer3[0]) {
239 buffer[z+2]=0;
240 buffer[z+1]=buffer2[j];
241 buffer[z] ='\\';
242 } else {
243 buffer[z+1]=0;
244 buffer[z] =buffer2[j];
245 }
246 }
247 break;
248 case SMS_Coding_8bit:
249 break;
250 }
251 sprintf(buffer+strlen(buffer),"',`Status`='%s',`DateTime`='%s' ",status,Config->DT);
252 sprintf(buffer+strlen(buffer),"WHERE `ID`='%s' AND `SequencePosition`='%i'",ID,i+1);
253 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
254 WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
255 return ERR_UNKNOWN;
256 }
257 }
258 sprintf(buffer,"DELETE FROM `Outbox` WHERE `ID` = '%s'",ID);
259 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { 434 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
260 WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); 435 WriteSMSDLog("Error deleting from database (MoveSMS): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
261 return ERR_UNKNOWN; 436 return ERR_UNKNOWN;
262 } 437 }
263 sprintf(buffer,"DELETE FROM `Outbox_MultiPart` WHERE `ID` = '%s'",ID); 438 sprintf(buffer,"DELETE FROM `outbox_multipart` WHERE `ID` = '%s'",ID);
264 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { 439 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
265 WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); 440 WriteSMSDLog("Error deleting from database (MoveSMS): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
266 return ERR_UNKNOWN; 441 return ERR_UNKNOWN;
267 } 442 }
268 return ERR_NONE; 443 return ERR_NONE;
269} 444}
270 445
271/* Adds SMS to Outbox */ 446/* Adds SMS to Outbox */
272static GSM_Error SMSDMySQL_CreateOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config) 447static GSM_Error SMSDMySQL_CreateOutboxSMS(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config)
273{ 448{
274 unsigned charbuffer[10000],buffer2[200],buffer3[2],buffer4[10000]; 449 unsigned char buffer[10000],buffer2[200],buffer3[2],buffer4[10000];
275 int i,j,z; 450 int i,j,z,ID;
276 GSM_DateTimetime; 451 MYSQL_RES *Res;
452 MYSQL_ROW Row;
453
454 sprintf(buffer,"SELECT ID FROM outbox ORDER BY ID DESC LIMIT 1");
455 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
456 WriteSMSDLog("Error reading from database (CreateOutbox): %s\n", mysql_error(&Config->DB));
457 return ERR_UNKNOWN;
458 }
459 if (!(Res = mysql_store_result(&Config->DB))) {
460 WriteSMSDLog("Error reading from database (CreateOutbox): %s\n", mysql_error(&Config->DB));
461 return ERR_UNKNOWN;
462 }
463 if ((Row = mysql_fetch_row(Res))) {
464 sprintf(buffer,"%s",Row[0]);
465 ID = atoi(buffer);
466 } else {
467 ID = 0;
468 }
469 mysql_free_result(Res);
277 470
278 for (i=0;i<sms->Number;i++) { 471 for (i=0;i<sms->Number;i++) {
279 buffer[0]=0; 472 buffer[0]=0;
280 if (i==0) { 473 if (i==0) {
281 sprintf(buffer+strlen(buffer),"INSERT INTO `Outbox` (`MultiPart`,`DateTime"); 474 sprintf(buffer+strlen(buffer),"INSERT INTO `outbox` (`DeliveryReport`,`MultiPart`,`InsertIntoDB");
282 } else { 475 } else {
283 sprintf(buffer+strlen(buffer),"INSERT INTO `Outbox_MultiPart` (`SequencePosition"); 476 sprintf(buffer+strlen(buffer),"INSERT INTO `outbox_multipart` (`SequencePosition");
284 } 477 }
285 sprintf(buffer+strlen(buffer),"`,`Text`,`DestinationNumber`,`Coding`,`SMSCNumber`,`UDH`, \ 478 sprintf(buffer+strlen(buffer),"`,`Text`,");
479 if (i==0) {
480 sprintf(buffer+strlen(buffer),"`DestinationNumber`,`RelativeValidity`,");
481 }
482 sprintf(buffer+strlen(buffer),"`Coding`,`UDH`, \
286 `Class`,`TextDecoded`,`ID`) VALUES ('"); 483 `Class`,`TextDecoded`,`ID`) VALUES ('");
287 if (i==0) { 484 if (i==0) {
485 if (sms->SMS[i].PDU == SMS_Status_Report) {
486 sprintf(buffer+strlen(buffer),"yes','");
487 } else {
488 sprintf(buffer+strlen(buffer),"default','");
489 }
288 if (sms->Number == 1) { 490 if (sms->Number == 1) {
289 sprintf(buffer+strlen(buffer),"false"); 491 sprintf(buffer+strlen(buffer),"false");
290 } else { 492 } else {
291 sprintf(buffer+strlen(buffer),"true"); 493 sprintf(buffer+strlen(buffer),"true");
292 } 494 }
293 sprintf(buffer+strlen(buffer),"',NOW()"); 495 sprintf(buffer+strlen(buffer),"',NOW()");
294 } else { 496 } else {
295 sprintf(buffer+strlen(buffer),"%i'",i+1); 497 sprintf(buffer+strlen(buffer),"%i'",i+1);
296 } 498 }
297 sprintf(buffer+strlen(buffer),",'"); 499 sprintf(buffer+strlen(buffer),",'");
298 500
299 switch (sms->SMS[i].Coding) { 501 switch (sms->SMS[i].Coding) {
300 case SMS_Coding_Unicode: 502 case SMS_Coding_Unicode:
301 case SMS_Coding_Default: 503 case SMS_Coding_Default:
302 EncodeHexUnicode(buffer+strlen(buffer),sms->SMS[i].Text,UnicodeLength(sms->SMS[i].Text)); 504 EncodeHexUnicode(buffer+strlen(buffer),sms->SMS[i].Text,UnicodeLength(sms->SMS[i].Text));
303 break; 505 break;
304 case SMS_Coding_8bit: 506 case SMS_Coding_8bit:
305 EncodeHexBin(buffer+strlen(buffer),sms->SMS[i].Text,sms->SMS[i].Length); 507 EncodeHexBin(buffer+strlen(buffer),sms->SMS[i].Text,sms->SMS[i].Length);
306 } 508 }
307 sprintf(buffer+strlen(buffer),"','%s','",DecodeUnicodeString(sms->SMS[i].Number)); 509 sprintf(buffer+strlen(buffer),"',");
510 if (i==0) {
511 sprintf(buffer+strlen(buffer),"'%s',",DecodeUnicodeString(sms->SMS[i].Number));
512 if (sms->SMS[i].SMSC.Validity.Format == SMS_Validity_RelativeFormat) {
513 sprintf(buffer+strlen(buffer),"'%i',",sms->SMS[i].SMSC.Validity.Relative);
514 } else {
515 sprintf(buffer+strlen(buffer),"'-1',");
516 }
517 }
518 sprintf(buffer+strlen(buffer),"'");
308 switch (sms->SMS[i].Coding) { 519 switch (sms->SMS[i].Coding) {
309 case SMS_Coding_Unicode: 520 case SMS_Coding_Unicode:
310 sprintf(buffer+strlen(buffer),"Unicode"); 521 sprintf(buffer+strlen(buffer),"Unicode");
311 break; 522 break;
312 case SMS_Coding_Default: 523 case SMS_Coding_Default:
313 sprintf(buffer+strlen(buffer),"Default"); 524 sprintf(buffer+strlen(buffer),"Default");
314 break; 525 break;
315 case SMS_Coding_8bit: 526 case SMS_Coding_8bit:
316 sprintf(buffer+strlen(buffer),"8bit"); 527 sprintf(buffer+strlen(buffer),"8bit");
317 break; 528 break;
318 } 529 }
319 sprintf(buffer+strlen(buffer),"','%s'",DecodeUnicodeString(sms->SMS[i].SMSC.Number)); 530 sprintf(buffer+strlen(buffer),"','");
320 if (sms->SMS[i].UDH.Type == UDH_NoUDH) { 531 if (sms->SMS[i].UDH.Type != UDH_NoUDH) {
321 sprintf(buffer+strlen(buffer),",''");
322 } else {
323 sprintf(buffer+strlen(buffer),",'");
324 EncodeHexBin(buffer+strlen(buffer),sms->SMS[i].UDH.Text,sms->SMS[i].UDH.Length); 532 EncodeHexBin(buffer+strlen(buffer),sms->SMS[i].UDH.Text,sms->SMS[i].UDH.Length);
325 sprintf(buffer+strlen(buffer),"'");
326 } 533 }
327 sprintf(buffer+strlen(buffer),",'%i','",sms->SMS[i].Class); 534 sprintf(buffer+strlen(buffer),"','%i','",sms->SMS[i].Class);
328 switch (sms->SMS[i].Coding) { 535 switch (sms->SMS[i].Coding) {
329 case SMS_Coding_Unicode: 536 case SMS_Coding_Unicode:
330 case SMS_Coding_Default: 537 case SMS_Coding_Default:
331 sprintf(buffer2,"%s",DecodeUnicodeString(sms->SMS[i].Text)); 538 sprintf(buffer2,"%s",DecodeUnicodeString(sms->SMS[i].Text));
332 for (j=0;j<(int)strlen(buffer2);j++) { 539 for (j=0;j<(int)strlen(buffer2);j++) {
333 sprintf(buffer3,"'"); 540 sprintf(buffer3,"'");
334 z = strlen(buffer); 541 z = strlen(buffer);
335 if (buffer2[j]==buffer3[0]) { 542 if (buffer2[j]==buffer3[0]) {
336 buffer[z+2]=0; 543 buffer[z+2]=0;
337 buffer[z+1]=buffer2[j]; 544 buffer[z+1]=buffer2[j];
338 buffer[z] ='\\'; 545 buffer[z] ='\\';
339 } else { 546 } else {
340 buffer[z+1]=0; 547 buffer[z+1]=0;
341 buffer[z] =buffer2[j]; 548 buffer[z] =buffer2[j];
342 } 549 }
343 } 550 }
344 break; 551 break;
345 case SMS_Coding_8bit: 552 case SMS_Coding_8bit:
346 553
347 break; 554 break;
348 } 555 }
349 sprintf(buffer+strlen(buffer),"','"); 556 sprintf(buffer+strlen(buffer),"','");
350 if (i==0) { 557 if (i==0) {
351 while (true) { 558 while (true) {
352 GSM_GetCurrentDateTime(&time); 559 ID++;
353 buffer4[0] = 0; 560 sprintf(buffer4,"SELECT ID FROM sentitems WHERE ID='%i'",ID);
354 strcpy(buffer4,buffer); 561#ifdef DEBUG
355 sprintf(buffer4+strlen(buffer4),"%i')", 562 fprintf(stdout,"%s\n",buffer4);
356 time.Hour*1000000+ 563#endif
357 time.Minute*10000+
358 time.Second*100+time.Day);
359 if (mysql_real_query(&Config->DB,buffer4,strlen(buffer4))) { 564 if (mysql_real_query(&Config->DB,buffer4,strlen(buffer4))) {
360 if (mysql_errno(&Config->DB) == ER_DUP_ENTRY) { 565 WriteSMSDLog("Error reading from database (CreateOutbox): %s\n", mysql_error(&Config->DB));
361 WriteSMSDLog("Duplicated outgoing SMS ID\n");
362 continue;
363 }
364 WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
365 return ERR_UNKNOWN; 566 return ERR_UNKNOWN;
366 } 567 }
367 break; 568 if (!(Res = mysql_store_result(&Config->DB))) {
569 WriteSMSDLog("Error reading from database (CreateOutbox): %s\n", mysql_error(&Config->DB));
570 return ERR_UNKNOWN;
571 }
572 if (!(Row = mysql_fetch_row(Res))) {
573 buffer4[0] = 0;
574 strcpy(buffer4,buffer);
575 sprintf(buffer4+strlen(buffer4),"%i')",ID);
576#ifdef DEBUG
577 fprintf(stdout,"%s\n",buffer4);
578#endif
579 if (mysql_real_query(&Config->DB,buffer4,strlen(buffer4))) {
580 if (mysql_errno(&Config->DB) == ER_DUP_ENTRY) {
581 WriteSMSDLog("Duplicated outgoing SMS ID\n");
582 continue;
583 }
584 WriteSMSDLog("Error writing to database (CreateOutbox): %d %s %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB),buffer4);
585 return ERR_UNKNOWN;
586 }
587 mysql_free_result(Res);
588 break;
589 }
590 mysql_free_result(Res);
368 } 591 }
369 } else { 592 } else {
370 strcpy(buffer4,buffer); 593 strcpy(buffer4,buffer);
371 sprintf(buffer4+strlen(buffer4),"%i')", 594 sprintf(buffer4+strlen(buffer4),"%i')",ID);
372 time.Hour*1000000+ 595#ifdef DEBUG
373 time.Minute*10000+ 596 fprintf(stdout,"%s\n",buffer4);
374 time.Second*100+time.Day); 597#endif
375 if (mysql_real_query(&Config->DB,buffer4,strlen(buffer4))) { 598 if (mysql_real_query(&Config->DB,buffer4,strlen(buffer4))) {
376 WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); 599 WriteSMSDLog("Error writing to database (CreateOutbox): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
377 return ERR_UNKNOWN; 600 return ERR_UNKNOWN;
378 } 601 }
379 } 602 }
380 } 603 }
381 return ERR_NONE; 604 return ERR_NONE;
382} 605}
383 606
384static GSM_Error SMSDMySQL_AddSentSMSInfo(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, bool OK) 607
608static GSM_Error SMSDMySQL_AddSentSMSInfo(GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, GSM_SMSDSendingError err, int TPMR)
385{ 609{
386 unsigned char buffer[10000]; 610 unsigned charbuffer[10000],buffer2[200],buffer3[2],buff[50];
611 int j,z;
612
613 if (err == SMSD_SEND_OK) WriteSMSDLog("Transmitted %s (%s: %i) to %s", Config->SMSID, (Part == sms->Number?"total":"part"),Part,DecodeUnicodeString(sms->SMS[0].Number));
387 614
388 if (OK) WriteSMSDLog("Transmitted %s (%s: %i) to %s", Config->SMSID, (Part == sms->Number?"total":"part"),Part,DecodeUnicodeString(sms->SMS[0].Number)); 615 buff[0] = 0;
616 if (err == SMSD_SEND_OK) {
617 if (sms->SMS[Part-1].PDU == SMS_Status_Report) {
618 sprintf(buff,"SendingOK");
619 } else {
620 sprintf(buff,"SendingOKNoReport");
621 }
622 }
623 if (err == SMSD_SEND_SENDING_ERROR) sprintf(buff,"SendingError");
624 if (err == SMSD_SEND_ERROR) sprintf(buff,"Error");
389 625
390 buffer[0] = 0; 626 buffer[0] = 0;
391 sprintf(buffer+strlen(buffer),"INSERT INTO `SentItems` \ 627 sprintf(buffer+strlen(buffer),"INSERT INTO `sentitems` \
392 (`ID`,`SequencePosition`,`Status`,`SendingDateTime`) VALUES ("); 628 (`ID`,`SequencePosition`,`Status`,`SendingDateTime`, `SMSCNumber`, `TPMR`, \
393 sprintf(buffer+strlen(buffer),"'%s','%i','Sending',NOW())",ID,Part); 629 `SenderID`,`Text`,`DestinationNumber`,`Coding`,`UDH`,`Class`,`TextDecoded`,`InsertIntoDB`,`RelativeValidity`) VALUES (");
630 sprintf(buffer+strlen(buffer),"'%s','%i','%s',NOW(),'%s','%i','%s','",ID,Part,buff,DecodeUnicodeString(sms->SMS[Part-1].SMSC.Number),TPMR,Config->PhoneID);
631 switch (sms->SMS[Part-1].Coding) {
632 case SMS_Coding_Unicode:
633 case SMS_Coding_Default:
634 EncodeHexUnicode(buffer+strlen(buffer),sms->SMS[Part-1].Text,UnicodeLength(sms->SMS[Part-1].Text));
635 break;
636 case SMS_Coding_8bit:
637 EncodeHexBin(buffer+strlen(buffer),sms->SMS[Part-1].Text,sms->SMS[Part-1].Length);
638 }
639 sprintf(buffer+strlen(buffer),"','%s','",DecodeUnicodeString(sms->SMS[Part-1].Number));
640 switch (sms->SMS[Part-1].Coding) {
641 case SMS_Coding_Unicode:
642 sprintf(buffer+strlen(buffer),"Unicode");
643 break;
644 case SMS_Coding_Default:
645 sprintf(buffer+strlen(buffer),"Default");
646 break;
647 case SMS_Coding_8bit:
648 sprintf(buffer+strlen(buffer),"8bit");
649 break;
650 }
651 sprintf(buffer+strlen(buffer),"','");
652 if (sms->SMS[Part-1].UDH.Type != UDH_NoUDH) {
653 EncodeHexBin(buffer+strlen(buffer),sms->SMS[Part-1].UDH.Text,sms->SMS[Part-1].UDH.Length);
654 }
655 sprintf(buffer+strlen(buffer),"','%i','",sms->SMS[Part-1].Class);
656 switch (sms->SMS[Part-1].Coding) {
657 case SMS_Coding_Unicode:
658 case SMS_Coding_Default:
659 sprintf(buffer2,"%s",DecodeUnicodeString(sms->SMS[Part-1].Text));
660 for (j=0;j<(int)strlen(buffer2);j++) {
661 sprintf(buffer3,"'");
662 z = strlen(buffer);
663 if (buffer2[j]==buffer3[0]) {
664 buffer[z+2]=0;
665 buffer[z+1]=buffer2[j];
666 buffer[z] ='\\';
667 } else {
668 buffer[z+1]=0;
669 buffer[z] =buffer2[j];
670 }
671 }
672 break;
673 case SMS_Coding_8bit:
674 break;
675 }
676 sprintf(buffer+strlen(buffer),"','%s','",Config->DT);
677 if (sms->SMS[Part-1].SMSC.Validity.Format == SMS_Validity_RelativeFormat) {
678 sprintf(buffer+strlen(buffer),"%i')",sms->SMS[Part-1].SMSC.Validity.Relative);
679 } else {
680 sprintf(buffer+strlen(buffer),"-1')");
681 }
682#ifdef DEBUG
683 fprintf(stdout,"%s\n",buffer);
684 #endif
394 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) { 685 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
395 WriteSMSDLog("Error writing to database: %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB)); 686 WriteSMSDLog("Error writing to database (AddSent): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
396 return ERR_UNKNOWN; 687 return ERR_UNKNOWN;
397 } 688 }
398 return ERR_NONE; 689 return ERR_NONE;
399} 690}
400 691
692static GSM_Error SMSDMySQL_RefreshPhoneStatus(GSM_SMSDConfig *Config)
693{
694 unsigned char buffer[500];
695
696 sprintf(buffer,"UPDATE `phones` SET `TimeOut`= (NOW() + INTERVAL 10 SECOND)+0");
697 sprintf(buffer+strlen(buffer)," WHERE `IMEI` = '%s'",s.Phone.Data.IMEI);
698#ifdef DEBUG
699 fprintf(stdout,"%s\n",buffer);
700#endif
701 if (mysql_real_query(&Config->DB,buffer,strlen(buffer))) {
702 WriteSMSDLog("Error writing to database (SaveInboxSMS): %d %s\n", mysql_errno(&Config->DB), mysql_error(&Config->DB));
703 return ERR_UNKNOWN;
704 }
705 return ERR_NONE;
706}
707
401GSM_SMSDService SMSDMySQL = { 708GSM_SMSDService SMSDMySQL = {
402 SMSDMySQL_Init, 709 SMSDMySQL_Init,
710 SMSDMySQL_InitAfterConnect,
403 SMSDMySQL_SaveInboxSMS, 711 SMSDMySQL_SaveInboxSMS,
404 SMSDMySQL_FindOutboxSMS, 712 SMSDMySQL_FindOutboxSMS,
405 SMSDMySQL_MoveSMS, 713 SMSDMySQL_MoveSMS,
406 SMSDMySQL_CreateOutboxSMS, 714 SMSDMySQL_CreateOutboxSMS,
407 SMSDMySQL_AddSentSMSInfo 715 SMSDMySQL_AddSentSMSInfo,
716 SMSDMySQL_RefreshSendStatus,
717 SMSDMySQL_RefreshPhoneStatus
408}; 718};
409 719
410#endif 720#endif
411 721
412/* How should editor hadle tabs in this file? Add editor commands here. 722/* How should editor hadle tabs in this file? Add editor commands here.
413 * vim: noexpandtab sw=8 ts=8 sts=8: 723 * vim: noexpandtab sw=8 ts=8 sts=8:
414 */ 724 */
diff --git a/gammu/emb/gammu/smsd/smsdcore.c b/gammu/emb/gammu/smsd/smsdcore.c
index fbc55d3..cc9accc 100644
--- a/gammu/emb/gammu/smsd/smsdcore.c
+++ b/gammu/emb/gammu/smsd/smsdcore.c
@@ -1,507 +1,583 @@
1/* (c) 2002-2003 by Marcin Wiacek and Joergen Thomsen */ 1/* (c) 2002-2004 by Marcin Wiacek and Joergen Thomsen */
2 2
3#include <string.h> 3#include <string.h>
4#include <signal.h> 4#include <signal.h>
5#include <stdarg.h> 5#include <stdarg.h>
6#include <time.h> 6#include <time.h>
7 7
8#include "../../common/misc/coding/coding.h" 8#include "../../common/misc/coding/coding.h"
9#include "../gammu.h" 9#include "../gammu.h"
10#include "smsdcore.h" 10#include "smsdcore.h"
11#include "s_files.h" 11#include "s_files.h"
12#ifdef HAVE_MYSQL_MYSQL_H 12#ifdef HAVE_MYSQL_MYSQL_H
13# include "s_mysql.h" 13# include "s_mysql.h"
14#endif 14#endif
15 15
16 FILE *smsd_log_file = NULL; 16 FILE *smsd_log_file = NULL;
17 static int TPMR;
17static GSM_Error SendingSMSStatus; 18static GSM_Error SendingSMSStatus;
19
18static void SMSSendingSMSStatus (char *Device, int status, int mr) 20static void SMSSendingSMSStatus (char *Device, int status, int mr)
19{ 21{
20 dbgprintf("Incoming SMS device: \"%s\" status=%d, reference=%d\n",Device, status, mr); 22 dbgprintf("Incoming SMS device: \"%s\" status=%d, reference=%d\n",Device, status, mr);
23 TPMR = mr;
21 if (status==0) { 24 if (status==0) {
22 SendingSMSStatus = ERR_NONE; 25 SendingSMSStatus = ERR_NONE;
23 } else { 26 } else {
24 SendingSMSStatus = ERR_UNKNOWN; 27 SendingSMSStatus = ERR_UNKNOWN;
25 } 28 }
26} 29}
27 30
28void GSM_Terminate_SMSD(char *msg, int error, bool exitprogram, int rc) 31void GSM_Terminate_SMSD(char *msg, int error, bool exitprogram, int rc)
29{ 32{
30 int ret = ERR_NONE; 33 int ret = ERR_NONE;
31 34
32 if (s.opened) { 35 if (s.opened) {
33 WriteSMSDLog("Terminating communication"); 36 WriteSMSDLog("Terminating communication");
34 ret=GSM_TerminateConnection(&s); 37 ret=GSM_TerminateConnection(&s);
35 if (ret!=ERR_NONE) { 38 if (ret!=ERR_NONE) {
36 printf("%s\n",print_error(error,s.di.df,s.msg)); 39 printf("%s\n",print_error(error,s.di.df,s.msg));
37 if (s.opened) GSM_TerminateConnection(&s); 40 if (s.opened) GSM_TerminateConnection(&s);
38 } 41 }
39 } 42 }
40 if (error != 0) { 43 if (error != 0) {
41 WriteSMSDLog(msg, error, print_error(error,s.di.df,s.msg)); 44 WriteSMSDLog(msg, error, print_error(error,s.di.df,s.msg));
42 fprintf(stderr, msg, error, print_error(error,s.di.df,s.msg)); 45 fprintf(stderr, msg, error, print_error(error,s.di.df,s.msg));
43 fprintf(stderr, "\n"); 46 fprintf(stderr, "\n");
44 } 47 }
45 if (exitprogram) { 48 if (exitprogram) {
46 if (smsd_log_file!=NULL) fclose(smsd_log_file); 49 if (smsd_log_file!=NULL) fclose(smsd_log_file);
47 exit(rc); 50 exit(rc);
48 } 51 }
49} 52}
50 53
51#ifdef __GNUC__ 54#ifdef __GNUC__
52__attribute__((format(printf, 1, 2))) 55__attribute__((format(printf, 1, 2)))
53#endif 56#endif
54void WriteSMSDLog(char *format, ...) 57void WriteSMSDLog(char *format, ...)
55{ 58{
56 GSM_DateTime date_time; 59 GSM_DateTime date_time;
57 char Buffer[2000]; 60 char Buffer[2000];
58 va_list argp; 61 va_list argp;
59 int result; 62 int result;
60 63
61 if (smsd_log_file != NULL) { 64 if (smsd_log_file != NULL) {
62 va_start(argp, format); 65 va_start(argp, format);
63 result = vsprintf(Buffer,GetMsg(s.msg,format),argp); 66 result = vsprintf(Buffer,GetMsg(s.msg,format),argp);
64 va_end(argp); 67 va_end(argp);
65 68
66 GSM_GetCurrentDateTime(&date_time); 69 GSM_GetCurrentDateTime(&date_time);
67 70
68 fprintf(smsd_log_file,"%s %4d/%02d/%02d %02d:%02d:%02d : %s\n", 71 fprintf(smsd_log_file,"%s %4d/%02d/%02d %02d:%02d:%02d : %s\n",
69 DayOfWeek(date_time.Year, date_time.Month, date_time.Day), 72 DayOfWeek(date_time.Year, date_time.Month, date_time.Day),
70 date_time.Year, date_time.Month, date_time.Day, 73 date_time.Year, date_time.Month, date_time.Day,
71 date_time.Hour, date_time.Minute, date_time.Second,Buffer); 74 date_time.Hour, date_time.Minute, date_time.Second,Buffer);
72 fflush(smsd_log_file); 75 fflush(smsd_log_file);
73 } 76 }
74} 77}
75 78
76void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log) 79void SMSD_ReadConfig(char *filename, GSM_SMSDConfig *Config, bool log, char *service)
77{ 80{
78 INI_Section *smsdcfgfile = NULL; 81 INI_Section *smsdcfgfile = NULL;
79 GSM_Config smsdcfg; 82 GSM_Config smsdcfg;
80 unsigned char *str; 83 unsigned char *str;
81 static unsigned charemptyPath[1] = "\0"; 84 static unsigned charemptyPath[1] = "\0";
82 85
83 smsdcfgfile=INI_ReadFile(filename, false); 86 smsdcfgfile=INI_ReadFile(filename, false);
84 if (smsdcfgfile==NULL) { 87 if (smsdcfgfile==NULL) {
85 fprintf(stderr,"Can't find file \"%s\"\n",filename); 88 fprintf(stderr,"Can't find file \"%s\"\n",filename);
86 exit(-1); 89 exit(-1);
87 } 90 }
88 91
89 Config->logfilename=INI_GetValue(smsdcfgfile, "smsd", "logfile", false); 92 Config->logfilename=INI_GetValue(smsdcfgfile, "smsd", "logfile", false);
90 if (Config->logfilename != NULL) { 93 if (Config->logfilename != NULL) {
91 smsd_log_file=fopen(Config->logfilename,"ab"); 94 smsd_log_file=fopen(Config->logfilename,"ab");
92 if (smsd_log_file == NULL) { 95 if (smsd_log_file == NULL) {
93 fprintf(stderr,"Can't open file \"%s\"\n",Config->logfilename); 96 fprintf(stderr,"Can't open file \"%s\"\n",Config->logfilename);
94 exit(-1); 97 exit(-1);
95 } 98 }
96 fprintf(stderr,"Log filename is \"%s\"\n",Config->logfilename); 99 fprintf(stderr,"Log filename is \"%s\"\n",Config->logfilename);
97 } 100 }
98 if (log) WriteSMSDLog("Start GAMMU smsd"); 101 if (log) WriteSMSDLog("Start GAMMU smsd");
99 102
100 /* Include Numbers used, because we don't want create new variable */ 103 /* Include Numbers used, because we don't want create new variable */
101 Config->IncludeNumbers=INI_FindLastSectionEntry(smsdcfgfile, "gammu", false); 104 Config->IncludeNumbers=INI_FindLastSectionEntry(smsdcfgfile, "gammu", false);
102 if (Config->IncludeNumbers) { 105 if (Config->IncludeNumbers) {
103 GSM_ReadConfig(smsdcfgfile, &smsdcfg, 0); 106 GSM_ReadConfig(smsdcfgfile, &smsdcfg, 0);
104 memcpy(&s.Config,&smsdcfg,sizeof(GSM_Config)); 107 memcpy(&s.Config,&smsdcfg,sizeof(GSM_Config));
108 error=GSM_SetDebugFile(s.Config[0].DebugFile, &di);
105 } 109 }
106 110
107 Config->PINCode=INI_GetValue(smsdcfgfile, "smsd", "PIN", false); 111 Config->PINCode=INI_GetValue(smsdcfgfile, "smsd", "PIN", false);
108 if (Config->PINCode == NULL) { 112 if (Config->PINCode == NULL) {
109 if (log) WriteSMSDLog("No PIN code in %s file",filename); 113 if (log) WriteSMSDLog("No PIN code in %s file",filename);
110 fprintf(stderr,"No PIN code in %s file\n",filename); 114 fprintf(stderr,"No PIN code in %s file\n",filename);
111 exit(-1); 115 exit(-1);
112 } 116 }
113 if (log) WriteSMSDLog("PIN code is \"%s\"",Config->PINCode); 117 if (log) WriteSMSDLog("PIN code is \"%s\"",Config->PINCode);
114 118
115 Config->user = INI_GetValue(smsdcfgfile, "smsd", "user", false);
116 if (Config->user == NULL) Config->user="root";
117 Config->password = INI_GetValue(smsdcfgfile, "smsd", "password", false);
118 if (Config->password == NULL) Config->password="";
119 Config->PC = INI_GetValue(smsdcfgfile, "smsd", "pc", false);
120 if (Config->PC == NULL) Config->PC="localhost";
121 Config->database = INI_GetValue(smsdcfgfile, "smsd", "database", false);
122 if (Config->database == NULL) Config->database="sms";
123
124 str = INI_GetValue(smsdcfgfile, "smsd", "commtimeout", false); 119 str = INI_GetValue(smsdcfgfile, "smsd", "commtimeout", false);
125 if (str) Config->commtimeout=atoi(str); else Config->commtimeout = 1; 120 if (str) Config->commtimeout=atoi(str); else Config->commtimeout = 1;
126 str = INI_GetValue(smsdcfgfile, "smsd", "sendtimeout", false); 121 str = INI_GetValue(smsdcfgfile, "smsd", "sendtimeout", false);
127 if (str) Config->sendtimeout=atoi(str); else Config->sendtimeout = 10; 122 if (str) Config->sendtimeout=atoi(str); else Config->sendtimeout = 10;
128 str = INI_GetValue(smsdcfgfile, "smsd", "receivefrequency", false); 123 str = INI_GetValue(smsdcfgfile, "smsd", "receivefrequency", false);
129 if (str) Config->receivefrequency=atoi(str); else Config->receivefrequency = 0; 124 if (str) Config->receivefrequency=atoi(str); else Config->receivefrequency = 0;
130 if (log) WriteSMSDLog("commtimeout=%i, sendtimeout=%i, receivefrequency=%i", Config->commtimeout, Config->sendtimeout, Config->receivefrequency); 125 str = INI_GetValue(smsdcfgfile, "smsd", "resetfrequency", false);
126 if (str) Config->resetfrequency=atoi(str); else Config->resetfrequency = 0;
127 if (log) WriteSMSDLog("commtimeout=%i, sendtimeout=%i, receivefrequency=%i, resetfrequency=%i",
128 Config->commtimeout, Config->sendtimeout, Config->receivefrequency, Config->resetfrequency);
131 129
132 Config->deliveryreport = INI_GetValue(smsdcfgfile, "smsd", "deliveryreport", false); 130 Config->deliveryreport = INI_GetValue(smsdcfgfile, "smsd", "deliveryreport", false);
133 if (Config->deliveryreport == NULL || (!mystrncasecmp(Config->deliveryreport, "log", 3) && !mystrncasecmp(Config->deliveryreport, "sms", 3))) { 131 if (Config->deliveryreport == NULL || (!mystrncasecmp(Config->deliveryreport, "log", 3) && !mystrncasecmp(Config->deliveryreport, "sms", 3))) {
134 Config->deliveryreport = "no"; 132 Config->deliveryreport = "no";
135 } 133 }
136 if (log) WriteSMSDLog("deliveryreport = %s", Config->deliveryreport); 134 if (log) WriteSMSDLog("deliveryreport = %s", Config->deliveryreport);
137 135
138 Config->inboxpath=INI_GetValue(smsdcfgfile, "smsd", "inboxpath", false); 136 Config->PhoneID = INI_GetValue(smsdcfgfile, "smsd", "phoneid", false);
139 if (Config->inboxpath == NULL) Config->inboxpath = emptyPath; 137 if (Config->PhoneID == NULL) Config->PhoneID = "";
138 if (log) WriteSMSDLog("phoneid = %s", Config->PhoneID);
140 139
141 Config->inboxformat=INI_GetValue(smsdcfgfile, "smsd", "inboxformat", false); 140 if (!strcmp(service,"FILES")) {
142 if (Config->inboxformat == NULL || (!mystrncasecmp(Config->inboxformat, "detail", 6) && !mystrncasecmp(Config->inboxformat, "unicode", 7))) { 141 Config->inboxpath=INI_GetValue(smsdcfgfile, "smsd", "inboxpath", false);
143 Config->inboxformat = "standard"; 142 if (Config->inboxpath == NULL) Config->inboxpath = emptyPath;
144 }
145 if (log) WriteSMSDLog("Inbox is \"%s\" with format \"%s\"", Config->inboxpath, Config->inboxformat);
146 143
147 Config->outboxpath=INI_GetValue(smsdcfgfile, "smsd", "outboxpath", false); 144 Config->inboxformat=INI_GetValue(smsdcfgfile, "smsd", "inboxformat", false);
148 if (Config->outboxpath == NULL) Config->outboxpath = emptyPath; 145 if (Config->inboxformat == NULL || (!mystrncasecmp(Config->inboxformat, "detail", 6) && !mystrncasecmp(Config->inboxformat, "unicode", 7))) {
146 Config->inboxformat = "standard";
147 }
148 if (log) WriteSMSDLog("Inbox is \"%s\" with format \"%s\"", Config->inboxpath, Config->inboxformat);
149 149
150 Config->transmitformat=INI_GetValue(smsdcfgfile, "smsd", "transmitformat", false); 150 Config->outboxpath=INI_GetValue(smsdcfgfile, "smsd", "outboxpath", false);
151 if (Config->transmitformat == NULL || (!mystrncasecmp(Config->transmitformat, "auto", 4) && !mystrncasecmp(Config->transmitformat, "unicode", 7))) { 151 if (Config->outboxpath == NULL) Config->outboxpath = emptyPath;
152 Config->transmitformat = "7bit";
153 }
154 if (log) WriteSMSDLog("Outbox is \"%s\" with transmission format \"%s\"", Config->outboxpath, Config->transmitformat);
155 152
156 Config->sentsmspath=INI_GetValue(smsdcfgfile, "smsd", "sentsmspath", false); 153 Config->transmitformat=INI_GetValue(smsdcfgfile, "smsd", "transmitformat", false);
157 if (Config->sentsmspath == NULL) Config->sentsmspath = Config->outboxpath; 154 if (Config->transmitformat == NULL || (!mystrncasecmp(Config->transmitformat, "auto", 4) && !mystrncasecmp(Config->transmitformat, "unicode", 7))) {
158 if (log) WriteSMSDLog("Sent SMS moved to \"%s\"",Config->sentsmspath); 155 Config->transmitformat = "7bit";
156 }
157 if (log) WriteSMSDLog("Outbox is \"%s\" with transmission format \"%s\"", Config->outboxpath, Config->transmitformat);
159 158
160 Config->errorsmspath=INI_GetValue(smsdcfgfile, "smsd", "errorsmspath", false); 159 Config->sentsmspath=INI_GetValue(smsdcfgfile, "smsd", "sentsmspath", false);
161 if (Config->errorsmspath == NULL) Config->errorsmspath = Config->sentsmspath; 160 if (Config->sentsmspath == NULL) Config->sentsmspath = Config->outboxpath;
162 if (log) WriteSMSDLog("SMS with errors moved to \"%s\"",Config->errorsmspath); 161 if (log) WriteSMSDLog("Sent SMS moved to \"%s\"",Config->sentsmspath);
162
163 Config->errorsmspath=INI_GetValue(smsdcfgfile, "smsd", "errorsmspath", false);
164 if (Config->errorsmspath == NULL) Config->errorsmspath = Config->sentsmspath;
165 if (log) WriteSMSDLog("SMS with errors moved to \"%s\"",Config->errorsmspath);
166 }
167
168#ifdef HAVE_MYSQL_MYSQL_H
169 if (!strcmp(service,"MYSQL")) {
170 Config->skipsmscnumber = INI_GetValue(smsdcfgfile, "smsd", "skipsmscnumber", false);
171 if (Config->skipsmscnumber == NULL) Config->skipsmscnumber="";
172 Config->user = INI_GetValue(smsdcfgfile, "smsd", "user", false);
173 if (Config->user == NULL) Config->user="root";
174 Config->password = INI_GetValue(smsdcfgfile, "smsd", "password", false);
175 if (Config->password == NULL) Config->password="";
176 Config->PC = INI_GetValue(smsdcfgfile, "smsd", "pc", false);
177 if (Config->PC == NULL) Config->PC="localhost";
178 Config->database = INI_GetValue(smsdcfgfile, "smsd", "database", false);
179 if (Config->database == NULL) Config->database="sms";
180 }
181#endif
163 182
164 Config->IncludeNumbers=INI_FindLastSectionEntry(smsdcfgfile, "include_numbers", false); 183 Config->IncludeNumbers=INI_FindLastSectionEntry(smsdcfgfile, "include_numbers", false);
165 Config->ExcludeNumbers=INI_FindLastSectionEntry(smsdcfgfile, "exclude_numbers", false); 184 Config->ExcludeNumbers=INI_FindLastSectionEntry(smsdcfgfile, "exclude_numbers", false);
166 if (Config->IncludeNumbers != NULL) { 185 if (Config->IncludeNumbers != NULL) {
167 if (log) WriteSMSDLog("Include numbers available"); 186 if (log) WriteSMSDLog("Include numbers available");
168 } 187 }
169 if (Config->ExcludeNumbers != NULL) { 188 if (Config->ExcludeNumbers != NULL) {
170 if (Config->IncludeNumbers == NULL) { 189 if (Config->IncludeNumbers == NULL) {
171 if (log) WriteSMSDLog("Exclude numbers available"); 190 if (log) WriteSMSDLog("Exclude numbers available");
172 } else { 191 } else {
173 if (log) WriteSMSDLog("Exclude numbers available, but IGNORED"); 192 if (log) WriteSMSDLog("Exclude numbers available, but IGNORED");
174 } 193 }
175 } 194 }
176 195
177 Config->retries = 0; 196 Config->retries = 0;
178 Config->prevSMSID[0] = 0; 197 Config->prevSMSID[0] = 0;
198 Config->SMSC.Location = 0;
199 Config->relativevalidity = -1;
179} 200}
180 201
181bool SMSD_CheckSecurity(GSM_SMSDConfig *Config) 202bool SMSD_CheckSecurity(GSM_SMSDConfig *Config)
182{ 203{
183 GSM_SecurityCode SecurityCode; 204 GSM_SecurityCode SecurityCode;
184 GSM_Error error; 205 GSM_Error error;
185 206
186 /* Need PIN ? */ 207 /* Need PIN ? */
187 error=Phone->GetSecurityStatus(&s,&SecurityCode.Type); 208 error=Phone->GetSecurityStatus(&s,&SecurityCode.Type);
188 /* Unknown error */ 209 /* Unknown error */
189 if (error != ERR_NOTSUPPORTED && error != ERR_NONE) { 210 if (error != ERR_NOTSUPPORTED && error != ERR_NONE) {
190 WriteSMSDLog("Error getting security status (%i)", error); 211 WriteSMSDLog("Error getting security status (%i)", error);
191 return false; 212 return false;
192 } 213 }
193 /* No supported - do not check more */ 214 /* No supported - do not check more */
194 if (error == ERR_NOTSUPPORTED) return true; 215 if (error == ERR_NOTSUPPORTED) return true;
216
195 /* If PIN, try to enter */ 217 /* If PIN, try to enter */
196 switch (SecurityCode.Type) { 218 switch (SecurityCode.Type) {
197 case SEC_Pin: 219 case SEC_Pin:
198 WriteSMSDLog("Trying to enter PIN"); 220 WriteSMSDLog("Trying to enter PIN");
199 strcpy(SecurityCode.Code,Config->PINCode); 221 strcpy(SecurityCode.Code,Config->PINCode);
200 error=Phone->EnterSecurityCode(&s,SecurityCode); 222 error=Phone->EnterSecurityCode(&s,SecurityCode);
201 if (error == ERR_SECURITYERROR) { 223 if (error == ERR_SECURITYERROR) {
202 GSM_Terminate_SMSD("ERROR: incorrect PIN", error, true, -1); 224 GSM_Terminate_SMSD("ERROR: incorrect PIN", error, true, -1);
203 } 225 }
204 if (error != ERR_NONE) { 226 if (error != ERR_NONE) {
205 WriteSMSDLog("Error entering PIN (%i)", error); 227 WriteSMSDLog("Error entering PIN (%i)", error);
206 return false; 228 return false;
207 } 229 }
208 break; 230 break;
209 case SEC_SecurityCode: 231 case SEC_SecurityCode:
210 case SEC_Pin2: 232 case SEC_Pin2:
211 case SEC_Puk: 233 case SEC_Puk:
212 case SEC_Puk2: 234 case SEC_Puk2:
213 GSM_Terminate_SMSD("ERROR: phone requires not supported code type", 0, true, -1); 235 GSM_Terminate_SMSD("ERROR: phone requires not supported code type", 0, true, -1);
214 case SEC_None: 236 case SEC_None:
215 break; 237 break;
216 } 238 }
217 return true; 239 return true;
218} 240}
219 241
220bool SMSD_ReadDeleteSMS(GSM_SMSDConfig *Config, GSM_SMSDService *Service) 242bool SMSD_ReadDeleteSMS(GSM_SMSDConfig *Config, GSM_SMSDService *Service)
221{ 243{
222 bool start,process; 244 bool start,process;
223 GSM_MultiSMSMessage sms; 245 GSM_MultiSMSMessage sms;
224 unsigned char buffer[100]; 246 unsigned char buffer[100];
225 GSM_Error error=ERR_NONE; 247 GSM_Error error=ERR_NONE;
226 INI_Entry *e; 248 INI_Entry *e;
227 int i; 249 int i;
228 250
229 start=true; 251 start=true;
230 while (error == ERR_NONE && !gshutdown) { 252 while (error == ERR_NONE && !gshutdown) {
231 sms.SMS[0].Folder=0x00; 253 sms.SMS[0].Folder=0x00;
232 error=Phone->GetNextSMS(&s, &sms, start); 254 error=Phone->GetNextSMS(&s, &sms, start);
233 switch (error) { 255 switch (error) {
234 case ERR_EMPTY: 256 case ERR_EMPTY:
235 break; 257 break;
236 case ERR_NONE: 258 case ERR_NONE:
237 /* Not Inbox SMS - exit */ 259 /* Not Inbox SMS - exit */
238 if (!sms.SMS[0].InboxFolder) break; 260 if (!sms.SMS[0].InboxFolder) break;
239 process=true; 261 process=true;
240 DecodeUnicode(sms.SMS[0].Number,buffer); 262 DecodeUnicode(sms.SMS[0].Number,buffer);
241 if (Config->IncludeNumbers != NULL) { 263 if (Config->IncludeNumbers != NULL) {
242 e=Config->IncludeNumbers; 264 e=Config->IncludeNumbers;
243 process=false; 265 process=false;
244 while (1) { 266 while (1) {
245 if (e == NULL) break; 267 if (e == NULL) break;
246 if (strcmp(buffer,e->EntryValue)==0) { 268 if (strcmp(buffer,e->EntryValue)==0) {
247 process=true; 269 process=true;
248 break; 270 break;
249 } 271 }
250 e = e->Prev; 272 e = e->Prev;
251 } 273 }
252 } else if (Config->ExcludeNumbers != NULL) { 274 } else if (Config->ExcludeNumbers != NULL) {
253 e=Config->ExcludeNumbers; 275 e=Config->ExcludeNumbers;
254 process=true; 276 process=true;
255 while (1) { 277 while (1) {
256 if (e == NULL) break; 278 if (e == NULL) break;
257 if (strcmp(buffer,e->EntryValue)==0) { 279 if (strcmp(buffer,e->EntryValue)==0) {
258 process=false; 280 process=false;
259 break; 281 break;
260 } 282 }
261 e = e->Prev; 283 e = e->Prev;
262 } 284 }
263 } 285 }
264 if (process) { 286 if (process) {
265 Service->SaveInboxSMS(sms, Config); 287 Service->SaveInboxSMS(sms, Config);
266 } else { 288 } else {
267 WriteSMSDLog("Excluded %s", buffer); 289 WriteSMSDLog("Excluded %s", buffer);
268 } 290 }
269 break; 291 break;
270 default: 292 default:
271 WriteSMSDLog("Error getting SMS (%i)", error); 293 WriteSMSDLog("Error getting SMS (%i)", error);
272 return false; 294 return false;
273 } 295 }
274 if (error == ERR_NONE && sms.SMS[0].InboxFolder) { 296 if (error == ERR_NONE && sms.SMS[0].InboxFolder) {
275 for (i=0;i<sms.Number;i++) { 297 for (i=0;i<sms.Number;i++) {
276 sms.SMS[i].Folder=0; 298 sms.SMS[i].Folder=0;
277 error=Phone->DeleteSMS(&s,&sms.SMS[i]); 299 error=Phone->DeleteSMS(&s,&sms.SMS[i]);
278 switch (error) { 300 switch (error) {
279 case ERR_NONE: 301 case ERR_NONE:
280 case ERR_EMPTY: 302 case ERR_EMPTY:
281 break; 303 break;
282 default: 304 default:
283 WriteSMSDLog("Error deleting SMS (%i)", error); 305 WriteSMSDLog("Error deleting SMS (%i)", error);
284 return false; 306 return false;
285 } 307 }
286 } 308 }
287 } 309 }
288 start=false; 310 start=false;
289 } 311 }
290 return true; 312 return true;
291} 313}
292 314
293bool SMSD_CheckSMSStatus(GSM_SMSDConfig *Config,GSM_SMSDService *Service) 315bool SMSD_CheckSMSStatus(GSM_SMSDConfig *Config,GSM_SMSDService *Service)
294{ 316{
295 GSM_SMSMemoryStatusSMSStatus; 317 GSM_SMSMemoryStatusSMSStatus;
296 GSM_Error error; 318 GSM_Error error;
297 319
298 /* Do we have any SMS in phone ? */ 320 /* Do we have any SMS in phone ? */
299 error=Phone->GetSMSStatus(&s,&SMSStatus); 321 error=Phone->GetSMSStatus(&s,&SMSStatus);
300 if (error != ERR_NONE) { 322 if (error != ERR_NONE) {
301 WriteSMSDLog("Error getting SMS status (%i)", error); 323 WriteSMSDLog("Error getting SMS status (%i)", error);
302 return false; 324 return false;
303 } 325 }
304 /* Yes. We have SMS in phone */ 326 /* Yes. We have SMS in phone */
305 if (SMSStatus.SIMUsed+SMSStatus.PhoneUsed != 0) { 327 if (SMSStatus.SIMUsed+SMSStatus.PhoneUsed != 0) {
306 return SMSD_ReadDeleteSMS(Config,Service); 328 return SMSD_ReadDeleteSMS(Config,Service);
307 } 329 }
308 return true; 330 return true;
309} 331}
310 332
311bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service) 333bool SMSD_SendSMS(GSM_SMSDConfig *Config,GSM_SMSDService *Service)
312{ 334{
313 GSM_MultiSMSMessage sms; 335 GSM_MultiSMSMessage sms;
314 GSM_DateTime Date; 336 GSM_DateTime Date;
315 GSM_Error error; 337 GSM_Error error;
316 unsigned int i, j, z; 338 unsigned int i, j, z;
317 339
318 error = Service->FindOutboxSMS(&sms, Config, Config->SMSID); 340 error = Service->FindOutboxSMS(&sms, Config, Config->SMSID);
319 341
320 if (error == ERR_EMPTY || error == ERR_NOTSUPPORTED) { 342 if (error == ERR_EMPTY || error == ERR_NOTSUPPORTED) {
321 /* No outbox sms - wait few seconds and escape */ 343 /* No outbox sms - wait few seconds and escape */
322 for (j=0;j<Config->commtimeout && !gshutdown;j++) { 344 for (j=0;j<Config->commtimeout && !gshutdown;j++) {
323 GSM_GetCurrentDateTime (&Date); 345 GSM_GetCurrentDateTime (&Date);
324 i=Date.Second; 346 i=Date.Second;
325 while (i==Date.Second && !gshutdown) { 347 while (i==Date.Second && !gshutdown) {
326 my_sleep(10); 348 my_sleep(10);
327 GSM_GetCurrentDateTime(&Date); 349 GSM_GetCurrentDateTime(&Date);
328 } 350 }
351 Service->RefreshPhoneStatus(Config);
329 } 352 }
330 return true; 353 return true;
331 } 354 }
332 if (error != ERR_NONE) { 355 if (error != ERR_NONE) {
333 /* Unknown error - escape */ 356 /* Unknown error - escape */
334 WriteSMSDLog("Error in outbox on %s", Config->SMSID); 357 WriteSMSDLog("Error in outbox on %s", Config->SMSID);
335 for (i=0;i<sms.Number;i++) { 358 for (i=0;i<sms.Number;i++) {
336 Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, false); 359 Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, SMSD_SEND_ERROR, -1);
337 } 360 }
338 Service->MoveSMS(&sms,Config, Config->SMSID, true,false); 361 Service->MoveSMS(&sms,Config, Config->SMSID, true,false);
339 return false; 362 return false;
340 } 363 }
364
341 if (!gshutdown) { 365 if (!gshutdown) {
342 if (strcmp(Config->prevSMSID, Config->SMSID) == 0) { 366 if (strcmp(Config->prevSMSID, Config->SMSID) == 0) {
343 Config->retries++; 367 Config->retries++;
344 if (Config->retries > MAX_RETRIES) { 368 if (Config->retries > MAX_RETRIES) {
345 Config->retries = 0; 369 Config->retries = 0;
346 strcpy(Config->prevSMSID, ""); 370 strcpy(Config->prevSMSID, "");
347 WriteSMSDLog("Moved to errorbox: %s", Config->SMSID); 371 WriteSMSDLog("Moved to errorbox: %s", Config->SMSID);
348 for (i=0;i<sms.Number;i++) { 372 for (i=0;i<sms.Number;i++) {
349 Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, false); 373 Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, SMSD_SEND_ERROR, -1);
350 } 374 }
351 Service->MoveSMS(&sms,Config, Config->SMSID, true,false); 375 Service->MoveSMS(&sms,Config, Config->SMSID, true,false);
352 return false; 376 return false;
353 } 377 }
354 } else { 378 } else {
355 Config->retries = 0; 379 Config->retries = 0;
356 strcpy(Config->prevSMSID, Config->SMSID); 380 strcpy(Config->prevSMSID, Config->SMSID);
357 } 381 }
358 for (i=0;i<sms.Number;i++) { 382 for (i=0;i<sms.Number;i++) {
359 if (strcmp(Config->deliveryreport, "no") != 0) sms.SMS[i].PDU = SMS_Status_Report; 383 if (sms.SMS[i].SMSC.Location == 1) {
384 if (Config->SMSC.Location == 0) {
385 Config->SMSC.Location = 1;
386 error = Phone->GetSMSC(&s,&Config->SMSC);
387 if (error!=ERR_NONE) {
388 WriteSMSDLog("Error getting SMSC from phone");
389 return false;
390 }
391
392 }
393 memcpy(&sms.SMS[i].SMSC,&Config->SMSC,sizeof(GSM_SMSC));
394 sms.SMS[i].SMSC.Location = 0;
395 if (Config->relativevalidity != -1) {
396 sms.SMS[i].SMSC.Validity.Format = SMS_Validity_RelativeFormat;
397 sms.SMS[i].SMSC.Validity.Relative = Config->relativevalidity;
398 }
399 }
400
401 if (Config->currdeliveryreport == 1) {
402 sms.SMS[i].PDU = SMS_Status_Report;
403 } else {
404 if ((strcmp(Config->deliveryreport, "no") != 0 && (Config->currdeliveryreport == -1))) sms.SMS[i].PDU = SMS_Status_Report;
405 }
406
360 error=Phone->SendSMS(&s, &sms.SMS[i]); 407 error=Phone->SendSMS(&s, &sms.SMS[i]);
361 if (error!=ERR_NONE) { 408 if (error!=ERR_NONE) {
409 Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, SMSD_SEND_SENDING_ERROR, -1);
362 WriteSMSDLog("Error sending SMS %s (%i): %s", Config->SMSID, error,print_error(error,s.di.df,s.msg)); 410 WriteSMSDLog("Error sending SMS %s (%i): %s", Config->SMSID, error,print_error(error,s.di.df,s.msg));
363 return false; 411 return false;
364 } 412 }
365 j=0; 413 Service->RefreshPhoneStatus(Config);
414 j = 0;
415 TPMR = -1;
366 SendingSMSStatus = ERR_TIMEOUT; 416 SendingSMSStatus = ERR_TIMEOUT;
367 while (!gshutdown) { 417 while (!gshutdown) {
368 GSM_GetCurrentDateTime (&Date); 418 GSM_GetCurrentDateTime (&Date);
369 z=Date.Second; 419 z=Date.Second;
370 while (z==Date.Second) { 420 while (z==Date.Second) {
371 my_sleep(10); 421 my_sleep(10);
372 GSM_GetCurrentDateTime(&Date); 422 GSM_GetCurrentDateTime(&Date);
373 GSM_ReadDevice(&s,true); 423 GSM_ReadDevice(&s,true);
374 if (SendingSMSStatus != ERR_TIMEOUT) break; 424 if (SendingSMSStatus != ERR_TIMEOUT) break;
375 } 425 }
426 Service->RefreshSendStatus(Config, Config->SMSID);
427 Service->RefreshPhoneStatus(Config);
376 if (SendingSMSStatus != ERR_TIMEOUT) break; 428 if (SendingSMSStatus != ERR_TIMEOUT) break;
377 j++; 429 j++;
378 if (j>Config->sendtimeout) break; 430 if (j>Config->sendtimeout) break;
379 } 431 }
380 if (SendingSMSStatus != ERR_NONE) { 432 if (SendingSMSStatus != ERR_NONE) {
433 Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, SMSD_SEND_SENDING_ERROR, TPMR);
381 WriteSMSDLog("Error getting send status of %s (%i): %s", Config->SMSID, SendingSMSStatus,print_error(SendingSMSStatus,s.di.df,s.msg)); 434 WriteSMSDLog("Error getting send status of %s (%i): %s", Config->SMSID, SendingSMSStatus,print_error(SendingSMSStatus,s.di.df,s.msg));
382 return false; 435 return false;
383 } 436 }
384 error = Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, true); 437 error = Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, SMSD_SEND_OK, TPMR);
385 if (error!=ERR_NONE) { 438 if (error!=ERR_NONE) {
386 return false; 439 return false;
387 } 440 }
388 } 441 }
389 while ((int)i<sms.Number-1) {
390 Service->AddSentSMSInfo(&sms, Config, Config->SMSID, i+1, false);
391 i++;
392 }
393 strcpy(Config->prevSMSID, ""); 442 strcpy(Config->prevSMSID, "");
394 if (Service->MoveSMS(&sms,Config, Config->SMSID, false, true) != ERR_NONE) { 443 if (Service->MoveSMS(&sms,Config, Config->SMSID, false, true) != ERR_NONE) {
395 Service->MoveSMS(&sms,Config, Config->SMSID, true, false); 444 Service->MoveSMS(&sms,Config, Config->SMSID, true, false);
396 } 445 }
397 } 446 }
398 return true; 447 return true;
399} 448}
400 449
401void SMSDaemon(int argc, char *argv[]) 450void SMSDaemon(int argc, char *argv[])
402{ 451{
403 int errors = 255, initerrors=0; 452 int errors = 255, initerrors=0;
404 GSM_SMSDService *Service; 453 GSM_SMSDService *Service;
405 GSM_Error error; 454 GSM_Error error;
406 time_t time1; 455 time_t lastreceive, lastreset = 0;
407 GSM_SMSDConfig Config; 456 GSM_SMSDConfig Config;
408 457
409 if (!strcmp(argv[2],"FILES")) { 458 if (!strcmp(argv[2],"FILES")) {
410 Service = &SMSDFiles; 459 Service = &SMSDFiles;
411#ifdef HAVE_MYSQL_MYSQL_H 460#ifdef HAVE_MYSQL_MYSQL_H
412 } else if (!strcmp(argv[2],"MYSQL")) { 461 } else if (!strcmp(argv[2],"MYSQL")) {
413 Service = &SMSDMySQL; 462 Service = &SMSDMySQL;
414#endif 463#endif
415 } else { 464 } else {
416 fprintf(stderr,"Unknown service type (\"%s\")\n",argv[2]); 465 fprintf(stderr,"Unknown service type (\"%s\")\n",argv[2]);
417 exit(-1); 466 exit(-1);
418 } 467 }
419 468
420 SMSD_ReadConfig(argv[3], &Config, true); 469 SMSD_ReadConfig(argv[3], &Config, true, argv[2]);
421 470
422 error = Service->Init(&Config); 471 error = Service->Init(&Config);
423 if (error!=ERR_NONE) { 472 if (error!=ERR_NONE) {
424 GSM_Terminate_SMSD("Stop GAMMU smsd (%i)", error, true, -1); 473 GSM_Terminate_SMSD("Stop GAMMU smsd (%i)", error, true, -1);
425 } 474 }
426 475
427 signal(SIGINT, interrupt); 476 signal(SIGINT, interrupt);
428 signal(SIGTERM, interrupt); 477 signal(SIGTERM, interrupt);
429 fprintf(stderr,"Press Ctrl+C to stop the program ...\n"); 478 fprintf(stderr,"Press Ctrl+C to stop the program ...\n");
430 479
431 time1 = time(NULL); 480 lastreceive = time(NULL);
481 lastreset = time(NULL);
432 SendingSMSStatus = ERR_UNKNOWN; 482 SendingSMSStatus = ERR_UNKNOWN;
433 483
434 while (!gshutdown) { 484 while (!gshutdown) {
435 /* There were errors in communication - try to recover */ 485 /* There were errors in communication - try to recover */
436 if (errors > 2) { 486 if (errors > 2) {
437 if (errors != 255) { 487 if (errors != 255) {
438 WriteSMSDLog("Terminating communication (%i,%i)", error, errors); 488 WriteSMSDLog("Terminating communication (%i,%i)", error, errors);
439 error=GSM_TerminateConnection(&s); 489 error=GSM_TerminateConnection(&s);
440 } 490 }
441 if (initerrors++ > 3) my_sleep(30000); 491 if (initerrors++ > 3) my_sleep(30000);
442 WriteSMSDLog("Starting communication"); 492 WriteSMSDLog("Starting communication");
443 error=GSM_InitConnection(&s,2); 493 error=GSM_InitConnection(&s,2);
444 switch (error) { 494 switch (error) {
445 case ERR_NONE: 495 case ERR_NONE:
446 s.User.SendSMSStatus = SMSSendingSMSStatus; 496 s.User.SendSMSStatus = SMSSendingSMSStatus;
447 Phone = s.Phone.Functions; 497 Phone = s.Phone.Functions;
448 errors = 0; 498 if (errors == 255) {
499 errors = 0;
500 s.Phone.Data.IMEI[0] = 0;
501 if (!(Phone->GetIMEI(&s))) {
502 errors++;
503 } else {
504 error = Service->InitAfterConnect(&Config);
505 if (error!=ERR_NONE) {
506 GSM_Terminate_SMSD("Stop GAMMU smsd (%i)", error, true, -1);
507 }
508 Phone->SetFastSMSSending(&s,true);
509 }
510 } else {
511 errors = 0;
512 }
513 if (initerrors > 3 || initerrors < 0) {
514 error=Phone->Reset(&s, false); /* soft reset */
515 WriteSMSDLog("Reset return code: %s (%i) ", error == ERR_NONE? "OK":"ERROR", error);
516 lastreset = time(NULL);
517 my_sleep(5000);
518 }
449 /* Marcin Wiacek: FIXME. To check */ 519 /* Marcin Wiacek: FIXME. To check */
450 // di = s.di; 520 // di = s.di;
451 break; 521 break;
452 case ERR_DEVICEOPENERROR: 522 case ERR_DEVICEOPENERROR:
453 GSM_Terminate_SMSD("Can't open device (%i)", error, true, -1); 523 GSM_Terminate_SMSD("Can't open device (%i)", error, true, -1);
454 default: 524 default:
455 WriteSMSDLog("Error at init connection (%i)", error); 525 WriteSMSDLog("Error at init connection (%i)", error);
456 errors = 250; 526 errors = 250;
457 } 527 }
458 continue; 528 continue;
459 } 529 }
460 if ((difftime(time(NULL), time1) >= Config.receivefrequency) || (SendingSMSStatus != ERR_NONE)) { 530 if ((difftime(time(NULL), lastreceive) >= Config.receivefrequency) || (SendingSMSStatus != ERR_NONE)) {
461 time1 = time(NULL); 531 lastreceive = time(NULL);
462 532
463 if (!SMSD_CheckSecurity(&Config)) { 533 if (!SMSD_CheckSecurity(&Config)) {
464 errors++; 534 errors++;
465 initerrors++; 535 initerrors++;
466 continue; 536 continue;
467 } else errors=0; 537 } else errors=0;
468 538
469 initerrors = 0; 539 initerrors = 0;
470 540
471 if (!SMSD_CheckSMSStatus(&Config,Service)) { 541 if (!SMSD_CheckSMSStatus(&Config,Service)) { /* read all incoming SMS */
472 errors++; 542 errors++;
473 continue; 543 continue;
474 } else errors=0; 544 } else errors=0;
545
546 if (Config.resetfrequency > 0 && difftime(time(NULL), lastreset) >= Config.resetfrequency) { /* time for preventive reset */
547 errors = 254; initerrors = -2;
548 continue;
549 }
475 } 550 }
476 if (!SMSD_SendSMS(&Config,Service)) continue; 551 if (!SMSD_SendSMS(&Config,Service)) continue;
477 } 552 }
553 Phone->SetFastSMSSending(&s,false);
478 GSM_Terminate_SMSD("Stop GAMMU smsd", 0, false, 0); 554 GSM_Terminate_SMSD("Stop GAMMU smsd", 0, false, 0);
479} 555}
480 556
481GSM_Error SMSDaemonSendSMS(char *service, char *filename, GSM_MultiSMSMessage *sms) 557GSM_Error SMSDaemonSendSMS(char *service, char *filename, GSM_MultiSMSMessage *sms)
482{ 558{
483 GSM_SMSDService *Service; 559 GSM_SMSDService *Service;
484 GSM_SMSDConfig Config; 560 GSM_SMSDConfig Config;
485 561
486 if (!strcmp(service,"FILES")) { 562 if (!strcmp(service,"FILES")) {
487 Service = &SMSDFiles; 563 Service = &SMSDFiles;
488#ifdef HAVE_MYSQL_MYSQL_H 564#ifdef HAVE_MYSQL_MYSQL_H
489 } else if (!strcmp(service,"MYSQL")) { 565 } else if (!strcmp(service,"MYSQL")) {
490 Service = &SMSDMySQL; 566 Service = &SMSDMySQL;
491#endif 567#endif
492 } else { 568 } else {
493 fprintf(stderr,"Unknown service type (\"%s\")\n",service); 569 fprintf(stderr,"Unknown service type (\"%s\")\n",service);
494 exit(-1); 570 exit(-1);
495 } 571 }
496 572
497 SMSD_ReadConfig(filename, &Config, false); 573 SMSD_ReadConfig(filename, &Config, false, service);
498 574
499 error = Service->Init(&Config); 575 error = Service->Init(&Config);
500 if (error!=ERR_NONE) return ERR_UNKNOWN; 576 if (error!=ERR_NONE) return ERR_UNKNOWN;
501 577
502 return Service->CreateOutboxSMS(sms,&Config); 578 return Service->CreateOutboxSMS(sms,&Config);
503} 579}
504 580
505/* How should editor hadle tabs in this file? Add editor commands here. 581/* How should editor hadle tabs in this file? Add editor commands here.
506 * vim: noexpandtab sw=8 ts=8 sts=8: 582 * vim: noexpandtab sw=8 ts=8 sts=8:
507 */ 583 */
diff --git a/gammu/emb/gammu/smsd/smsdcore.h b/gammu/emb/gammu/smsd/smsdcore.h
index 23e402e..17ffe58 100644
--- a/gammu/emb/gammu/smsd/smsdcore.h
+++ b/gammu/emb/gammu/smsd/smsdcore.h
@@ -1,61 +1,78 @@
1/* (c) 2002-2003 by Marcin Wiacek and Joergen Thomsen */ 1/* (c) 2002-2004 by Marcin Wiacek and Joergen Thomsen */
2 2
3#include "../../cfg/config.h" 3#include "../../cfg/config.h"
4#undef HAVE_MYSQL_MYSQL_H 4
5#ifdef HAVE_MYSQL_MYSQL_H 5#ifdef HAVE_MYSQL_MYSQL_H
6#ifdef WIN32 6#ifdef WIN32
7# include <mysql.h> 7# include <mysql.h>
8# include <mysqld_error.h> 8# include <mysqld_error.h>
9#else 9#else
10# include <mysql/mysql.h> 10# include <mysql/mysql.h>
11# include <mysql/mysqld_error.h> 11# include <mysql/mysqld_error.h>
12#endif 12#endif
13#endif 13#endif
14 14
15#include "../../common/service/sms/gsmsms.h" 15#include "../../common/service/sms/gsmsms.h"
16#include "../../common/service/sms/gsmmulti.h" 16#include "../../common/service/sms/gsmmulti.h"
17 17
18#define MAX_RETRIES 1 18#define MAX_RETRIES 1
19 19
20 void SMSDaemon (int argc, char *argv[]); 20 void SMSDaemon (int argc, char *argv[]);
21 GSM_Error SMSDaemonSendSMS(char *service, char *filename, GSM_MultiSMSMessage *sms); 21 GSM_Error SMSDaemonSendSMS(char *service, char *filename, GSM_MultiSMSMessage *sms);
22 22
23typedef struct { 23typedef struct {
24 /* general options */ 24 /* general options */
25 INI_Entry *IncludeNumbers, *ExcludeNumbers; 25 INI_Entry *IncludeNumbers, *ExcludeNumbers;
26 unsigned int commtimeout, sendtimeout, receivefrequency; 26 unsigned int commtimeout, sendtimeout, receivefrequency;
27 unsigned intresetfrequency;
27 unsigned char *deliveryreport, *logfilename, *PINCode; 28 unsigned char *deliveryreport, *logfilename, *PINCode;
29 unsigned char*PhoneID;
28 30
29 /* options for FILES */ 31 /* options for FILES */
30 unsigned char *inboxpath, *outboxpath, *sentsmspath; 32 unsigned char *inboxpath, *outboxpath, *sentsmspath;
31 unsigned char *errorsmspath, *inboxformat, *transmitformat; 33 unsigned char *errorsmspath, *inboxformat, *transmitformat;
32 34
33 /* options for MYSQL */ 35 /* options for MYSQL */
34 unsigned char *database, *user, *password; 36 unsigned char *database, *user, *password;
35 unsigned char*PC; 37 unsigned char *PC, *skipsmscnumber;
36 38
37 /* private variables required for work */ 39 /* private variables required for work */
38 unsigned int retries; 40 int relativevalidity;
41 unsigned int retries, currdeliveryreport;
39 unsigned char SMSID[200], prevSMSID[200]; 42 unsigned char SMSID[200], prevSMSID[200];
43 GSM_SMSCSMSC;
40#ifdef HAVE_MYSQL_MYSQL_H 44#ifdef HAVE_MYSQL_MYSQL_H
41 MYSQL DB; char DT[20]; 45 MYSQL DB; char DT[20];
42#endif 46#endif
43} GSM_SMSDConfig; 47} GSM_SMSDConfig;
44 48
49typedef enum {
50 SMSD_SEND_OK = 1,
51 SMSD_SEND_SENDING_ERROR,
52 SMSD_SEND_DELIVERY_PENDING,
53 SMSD_SEND_DELIVERY_FAILED,
54 SMSD_SEND_DELIVERY_OK,
55 SMSD_SEND_DELIVERY_UNKNOWN,
56 SMSD_SEND_ERROR
57} GSM_SMSDSendingError;
58
45typedef struct { 59typedef struct {
46 GSM_Error (*Init) (GSM_SMSDConfig *Config); 60 GSM_Error (*Init) (GSM_SMSDConfig *Config);
47 GSM_Error(*SaveInboxSMS) (GSM_MultiSMSMessage sms, GSM_SMSDConfig *Config); 61 GSM_Error(*InitAfterConnect) (GSM_SMSDConfig *Config);
48 GSM_Error(*FindOutboxSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID); 62 GSM_Error(*SaveInboxSMS) (GSM_MultiSMSMessage sms, GSM_SMSDConfig *Config);
49 GSM_Error (*MoveSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, bool alwaysDelete, bool sent); 63 GSM_Error(*FindOutboxSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID);
50 GSM_Error(*CreateOutboxSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config); 64 GSM_Error (*MoveSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, bool alwaysDelete, bool sent);
51 GSM_Error(*AddSentSMSInfo) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, bool OK); 65 GSM_Error(*CreateOutboxSMS) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config);
66 GSM_Error(*AddSentSMSInfo) (GSM_MultiSMSMessage *sms, GSM_SMSDConfig *Config, unsigned char *ID, int Part, GSM_SMSDSendingError err, int TPMR);
67 GSM_Error(*RefreshSendStatus) (GSM_SMSDConfig *Config, unsigned char *ID);
68 GSM_Error(*RefreshPhoneStatus) (GSM_SMSDConfig *Config);
52} GSM_SMSDService; 69} GSM_SMSDService;
53 70
54#ifdef __GNUC__ 71#ifdef __GNUC__
55__attribute__((format(printf, 1, 2))) 72__attribute__((format(printf, 1, 2)))
56#endif 73#endif
57void WriteSMSDLog(char *format, ...); 74void WriteSMSDLog(char *format, ...);
58 75
59/* How should editor hadle tabs in this file? Add editor commands here. 76/* How should editor hadle tabs in this file? Add editor commands here.
60 * vim: noexpandtab sw=8 ts=8 sts=8: 77 * vim: noexpandtab sw=8 ts=8 sts=8:
61 */ 78 */
diff --git a/libkcal/phoneformat.cpp b/libkcal/phoneformat.cpp
index c67dc6a..16c5880 100644
--- a/libkcal/phoneformat.cpp
+++ b/libkcal/phoneformat.cpp
@@ -191,542 +191,542 @@ int PhoneFormat::initDevice(GSM_StateMachine *s)
191 cfg->Connection = strdup(mConnection.latin1()); 191 cfg->Connection = strdup(mConnection.latin1());
192 cfg->DefaultConnection = false; 192 cfg->DefaultConnection = false;
193 qDebug("Connection set %s ", cfg->Connection ); 193 qDebug("Connection set %s ", cfg->Connection );
194 194
195 } 195 }
196 if ( ! mDevice.isEmpty() ) { 196 if ( ! mDevice.isEmpty() ) {
197 cfg->Device = strdup(mDevice.latin1()); 197 cfg->Device = strdup(mDevice.latin1());
198 cfg->DefaultDevice = false; 198 cfg->DefaultDevice = false;
199 qDebug("Device set %s ", cfg->Device); 199 qDebug("Device set %s ", cfg->Device);
200 200
201 } 201 }
202 if ( ! mModel.isEmpty() ) { 202 if ( ! mModel.isEmpty() ) {
203 strcpy(cfg->Model,mModel.latin1() ); 203 strcpy(cfg->Model,mModel.latin1() );
204 cfg->DefaultModel = false; 204 cfg->DefaultModel = false;
205 qDebug("Model set %s ",cfg->Model ); 205 qDebug("Model set %s ",cfg->Model );
206 } 206 }
207 int error=GSM_InitConnection(s,3); 207 int error=GSM_InitConnection(s,3);
208 return error; 208 return error;
209} 209}
210#endif 210#endif
211ulong PhoneFormat::getCsumTodo( Todo* todo ) 211ulong PhoneFormat::getCsumTodo( Todo* todo )
212{ 212{
213 QStringList attList; 213 QStringList attList;
214 if ( todo->hasDueDate() ) 214 if ( todo->hasDueDate() )
215 attList << PhoneParser::dtToString ( todo->dtDue() ); 215 attList << PhoneParser::dtToString ( todo->dtDue() );
216 attList << todo->summary(); 216 attList << todo->summary();
217 QString completedString = "no"; 217 QString completedString = "no";
218 if ( todo->isCompleted() ) 218 if ( todo->isCompleted() )
219 completedString = "yes"; 219 completedString = "yes";
220 attList << completedString; 220 attList << completedString;
221 int prio = todo->priority(); 221 int prio = todo->priority();
222 if( prio == 2 ) prio = 1; 222 if( prio == 2 ) prio = 1;
223 if (prio == 4 ) prio = 5 ; 223 if (prio == 4 ) prio = 5 ;
224 attList << QString::number( prio ); 224 attList << QString::number( prio );
225 QString alarmString = "na"; 225 QString alarmString = "na";
226 Alarm *alarm; 226 Alarm *alarm;
227 if ( todo->alarms().count() > 0 ) { 227 if ( todo->alarms().count() > 0 ) {
228 alarm = todo->alarms().first(); 228 alarm = todo->alarms().first();
229 if ( alarm->enabled() ) { 229 if ( alarm->enabled() ) {
230 alarmString = QString::number(alarm->offset() ); 230 alarmString = QString::number(alarm->offset() );
231 } 231 }
232 } 232 }
233 attList << alarmString; 233 attList << alarmString;
234 attList << todo->categoriesStr(); 234 attList << todo->categoriesStr();
235 attList << todo->secrecyStr(); 235 attList << todo->secrecyStr();
236 return PhoneFormat::getCsum(attList ); 236 return PhoneFormat::getCsum(attList );
237 237
238} 238}
239ulong PhoneFormat::getCsumEvent( Event* event ) 239ulong PhoneFormat::getCsumEvent( Event* event )
240{ 240{
241 QStringList attList; 241 QStringList attList;
242 attList << PhoneParser::dtToString ( event->dtStart() ); 242 attList << PhoneParser::dtToString ( event->dtStart() );
243 attList << PhoneParser::dtToString ( event->dtEnd() ); 243 attList << PhoneParser::dtToString ( event->dtEnd() );
244 attList << event->summary(); 244 attList << event->summary();
245 attList << event->location(); 245 attList << event->location();
246 QString alarmString = "na"; 246 QString alarmString = "na";
247 Alarm *alarm; 247 Alarm *alarm;
248 if ( event->alarms().count() > 0 ) { 248 if ( event->alarms().count() > 0 ) {
249 alarm = event->alarms().first(); 249 alarm = event->alarms().first();
250 if ( alarm->enabled() ) { 250 if ( alarm->enabled() ) {
251 alarmString = QString::number( alarm->offset() ); 251 alarmString = QString::number( alarm->offset() );
252 } 252 }
253 } 253 }
254 attList << alarmString; 254 attList << alarmString;
255 Recurrence* rec = event->recurrence(); 255 Recurrence* rec = event->recurrence();
256 QStringList list; 256 QStringList list;
257 bool writeEndDate = false; 257 bool writeEndDate = false;
258 switch ( rec->doesRecur() ) 258 switch ( rec->doesRecur() )
259 { 259 {
260 case Recurrence::rDaily: // 0 260 case Recurrence::rDaily: // 0
261 list.append( "0" ); 261 list.append( "0" );
262 list.append( QString::number( rec->frequency() ));//12 262 list.append( QString::number( rec->frequency() ));//12
263 list.append( "0" ); 263 list.append( "0" );
264 list.append( "0" ); 264 list.append( "0" );
265 writeEndDate = true; 265 writeEndDate = true;
266 break; 266 break;
267 case Recurrence::rWeekly:// 1 267 case Recurrence::rWeekly:// 1
268 list.append( "1" ); 268 list.append( "1" );
269 list.append( QString::number( rec->frequency()) );//12 269 list.append( QString::number( rec->frequency()) );//12
270 list.append( "0" ); 270 list.append( "0" );
271 { 271 {
272 int days = 0; 272 int days = 0;
273 QBitArray weekDays = rec->days(); 273 QBitArray weekDays = rec->days();
274 int i; 274 int i;
275 for( i = 1; i <= 7; ++i ) { 275 for( i = 1; i <= 7; ++i ) {
276 if ( weekDays[i-1] ) { 276 if ( weekDays[i-1] ) {
277 days += 1 << (i-1); 277 days += 1 << (i-1);
278 } 278 }
279 } 279 }
280 list.append( QString::number( days ) ); 280 list.append( QString::number( days ) );
281 } 281 }
282 //pending weekdays 282 //pending weekdays
283 writeEndDate = true; 283 writeEndDate = true;
284 284
285 break; 285 break;
286 case Recurrence::rMonthlyPos:// 2 286 case Recurrence::rMonthlyPos:// 2
287 list.append( "2" ); 287 list.append( "2" );
288 list.append( QString::number( rec->frequency()) );//12 288 list.append( QString::number( rec->frequency()) );//12
289 289
290 writeEndDate = true; 290 writeEndDate = true;
291 { 291 {
292 int count = 1; 292 int count = 1;
293 QPtrList<Recurrence::rMonthPos> rmp; 293 QPtrList<Recurrence::rMonthPos> rmp;
294 rmp = rec->monthPositions(); 294 rmp = rec->monthPositions();
295 if ( rmp.first()->negative ) 295 if ( rmp.first()->negative )
296 count = 5 - rmp.first()->rPos - 1; 296 count = 5 - rmp.first()->rPos - 1;
297 else 297 else
298 count = rmp.first()->rPos - 1; 298 count = rmp.first()->rPos - 1;
299 list.append( QString::number( count ) ); 299 list.append( QString::number( count ) );
300 300
301 } 301 }
302 302
303 list.append( "0" ); 303 list.append( "0" );
304 break; 304 break;
305 case Recurrence::rMonthlyDay:// 3 305 case Recurrence::rMonthlyDay:// 3
306 list.append( "3" ); 306 list.append( "3" );
307 list.append( QString::number( rec->frequency()) );//12 307 list.append( QString::number( rec->frequency()) );//12
308 list.append( "0" ); 308 list.append( "0" );
309 list.append( "0" ); 309 list.append( "0" );
310 writeEndDate = true; 310 writeEndDate = true;
311 break; 311 break;
312 case Recurrence::rYearlyMonth://4 312 case Recurrence::rYearlyMonth://4
313 list.append( "4" ); 313 list.append( "4" );
314 list.append( QString::number( rec->frequency()) );//12 314 list.append( QString::number( rec->frequency()) );//12
315 list.append( "0" ); 315 list.append( "0" );
316 list.append( "0" ); 316 list.append( "0" );
317 writeEndDate = true; 317 writeEndDate = true;
318 break; 318 break;
319 319
320 default: 320 default:
321 list.append( "255" ); 321 list.append( "255" );
322 list.append( QString() ); 322 list.append( QString() );
323 list.append( "0" ); 323 list.append( "0" );
324 list.append( QString() ); 324 list.append( QString() );
325 list.append( "0" ); 325 list.append( "0" );
326 list.append( "20991231T000000" ); 326 list.append( "20991231T000000" );
327 break; 327 break;
328 } 328 }
329 if ( writeEndDate ) { 329 if ( writeEndDate ) {
330 330
331 if ( rec->endDate().isValid() ) { // 15 + 16 331 if ( rec->endDate().isValid() ) { // 15 + 16
332 list.append( "1" ); 332 list.append( "1" );
333 list.append( PhoneParser::dtToString( rec->endDate()) ); 333 list.append( PhoneParser::dtToString( rec->endDate()) );
334 } else { 334 } else {
335 list.append( "0" ); 335 list.append( "0" );
336 list.append( "20991231T000000" ); 336 list.append( "20991231T000000" );
337 } 337 }
338 338
339 } 339 }
340 attList << list.join(""); 340 attList << list.join("");
341 attList << event->categoriesStr(); 341 attList << event->categoriesStr();
342 //qDebug("csum cat %s", event->categoriesStr().latin1()); 342 //qDebug("csum cat %s", event->categoriesStr().latin1());
343 343
344 attList << event->secrecyStr(); 344 attList << event->secrecyStr();
345 return PhoneFormat::getCsum(attList ); 345 return PhoneFormat::getCsum(attList );
346} 346}
347ulong PhoneFormat::getCsum( const QStringList & attList) 347ulong PhoneFormat::getCsum( const QStringList & attList)
348{ 348{
349 int max = attList.count(); 349 int max = attList.count();
350 ulong cSum = 0; 350 ulong cSum = 0;
351 int j,k,i; 351 int j,k,i;
352 int add; 352 int add;
353 for ( i = 0; i < max ; ++i ) { 353 for ( i = 0; i < max ; ++i ) {
354 QString s = attList[i]; 354 QString s = attList[i];
355 if ( ! s.isEmpty() ){ 355 if ( ! s.isEmpty() ){
356 j = s.length(); 356 j = s.length();
357 for ( k = 0; k < j; ++k ) { 357 for ( k = 0; k < j; ++k ) {
358 int mul = k +1; 358 int mul = k +1;
359 add = s[k].unicode (); 359 add = s[k].unicode ();
360 if ( k < 16 ) 360 if ( k < 16 )
361 mul = mul * mul; 361 mul = mul * mul;
362 int ii = i+1; 362 int ii = i+1;
363 add = add * mul *ii*ii*ii; 363 add = add * mul *ii*ii*ii;
364 cSum += add; 364 cSum += add;
365 } 365 }
366 } 366 }
367 367
368 } 368 }
369 //QString dump = attList.join(","); 369 //QString dump = attList.join(",");
370 //qDebug("csum: %d %s", cSum,dump.latin1()); 370 //qDebug("csum: %d %s", cSum,dump.latin1());
371 371
372 return cSum; 372 return cSum;
373 373
374} 374}
375//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum); 375//extern "C" GSM_Error GSM_InitConnection(GSM_StateMachine *s, int ReplyNum);
376#include <stdlib.h> 376#include <stdlib.h>
377#define DEBUGMODE false 377#define DEBUGMODE false
378bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal) 378bool PhoneFormat::load( Calendar *calendar, Calendar *existingCal)
379{ 379{
380 380
381 QString fileName; 381 QString fileName;
382#ifdef _WIN32_ 382#ifdef _WIN32_
383 fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; 383 fileName = locateLocal("tmp", "tempfile.vcs")
384#else 384#else
385 fileName = "/tmp/kdepimtemp.vcs"; 385 fileName = "/tmp/kdepimtemp.vcs";
386#endif 386#endif
387#ifdef DESKTOP_VERSION 387#ifdef DESKTOP_VERSION
388 QString command ="./kammu --backup " + fileName + " -yes" ; 388 QString command ="./kammu --backup " + fileName + " -yes" ;
389#else 389#else
390 QString command ="kammu --backup " + fileName + " -yes" ; 390 QString command ="kammu --backup " + fileName + " -yes" ;
391#endif 391#endif
392 int ret = system ( command.latin1() ); 392 int ret = system ( command.latin1() );
393 if ( ret != 0 ) { 393 if ( ret != 0 ) {
394 qDebug("Error::command returned %d", ret); 394 qDebug("Error::command returned %d", ret);
395 return false; 395 return false;
396 } 396 }
397 VCalFormat vfload; 397 VCalFormat vfload;
398 vfload.setLocalTime ( true ); 398 vfload.setLocalTime ( true );
399 qDebug("loading file ..."); 399 qDebug("loading file ...");
400 400
401 if ( ! vfload.load( calendar, fileName ) ) 401 if ( ! vfload.load( calendar, fileName ) )
402 return false; 402 return false;
403 QPtrList<Event> er = calendar->rawEvents(); 403 QPtrList<Event> er = calendar->rawEvents();
404 Event* ev = er.first(); 404 Event* ev = er.first();
405 qDebug("reading events... "); 405 qDebug("reading events... ");
406 while ( ev ) { 406 while ( ev ) {
407 QStringList cat = ev->categories(); 407 QStringList cat = ev->categories();
408 if ( cat.contains( "MeetingDEF" )) { 408 if ( cat.contains( "MeetingDEF" )) {
409 ev->setCategories( QStringList() ); 409 ev->setCategories( QStringList() );
410 } 410 }
411 int id = ev->pilotId(); 411 int id = ev->pilotId();
412 Event *event; 412 Event *event;
413 event = existingCal->event( mProfileName ,QString::number( id ) ); 413 event = existingCal->event( mProfileName ,QString::number( id ) );
414 if ( event ) { 414 if ( event ) {
415 event = (Event*)event->clone(); 415 event = (Event*)event->clone();
416 copyEvent( event, ev ); 416 copyEvent( event, ev );
417 calendar->deleteEvent( ev ); 417 calendar->deleteEvent( ev );
418 calendar->addEvent( event); 418 calendar->addEvent( event);
419 } 419 }
420 else 420 else
421 event = ev; 421 event = ev;
422 uint cSum; 422 uint cSum;
423 cSum = PhoneFormat::getCsumEvent( event ); 423 cSum = PhoneFormat::getCsumEvent( event );
424 event->setCsum( mProfileName, QString::number( cSum )); 424 event->setCsum( mProfileName, QString::number( cSum ));
425 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 425 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
426 event->setID( mProfileName,QString::number( id ) ); 426 event->setID( mProfileName,QString::number( id ) );
427 ev = er.next(); 427 ev = er.next();
428 } 428 }
429 { 429 {
430 qDebug("reading todos... "); 430 qDebug("reading todos... ");
431 QPtrList<Todo> tr = calendar->rawTodos(); 431 QPtrList<Todo> tr = calendar->rawTodos();
432 Todo* ev = tr.first(); 432 Todo* ev = tr.first();
433 while ( ev ) { 433 while ( ev ) {
434 434
435 QStringList cat = ev->categories(); 435 QStringList cat = ev->categories();
436 if ( cat.contains( "MeetingDEF" )) { 436 if ( cat.contains( "MeetingDEF" )) {
437 ev->setCategories( QStringList() ); 437 ev->setCategories( QStringList() );
438 } 438 }
439 int id = ev->pilotId(); 439 int id = ev->pilotId();
440 Todo *event; 440 Todo *event;
441 event = existingCal->todo( mProfileName ,QString::number( id ) ); 441 event = existingCal->todo( mProfileName ,QString::number( id ) );
442 if ( event ) { 442 if ( event ) {
443 //qDebug("copy todo %s ", event->summary().latin1()); 443 //qDebug("copy todo %s ", event->summary().latin1());
444 444
445 event = (Todo*)event->clone(); 445 event = (Todo*)event->clone();
446 copyTodo( event, ev ); 446 copyTodo( event, ev );
447 calendar->deleteTodo( ev ); 447 calendar->deleteTodo( ev );
448 calendar->addTodo( event); 448 calendar->addTodo( event);
449 } 449 }
450 else 450 else
451 event = ev; 451 event = ev;
452 uint cSum; 452 uint cSum;
453 cSum = PhoneFormat::getCsumTodo( event ); 453 cSum = PhoneFormat::getCsumTodo( event );
454 event->setCsum( mProfileName, QString::number( cSum )); 454 event->setCsum( mProfileName, QString::number( cSum ));
455 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); 455 event->setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL );
456 event->setID( mProfileName,QString::number( id ) ); 456 event->setID( mProfileName,QString::number( id ) );
457 ev = tr.next(); 457 ev = tr.next();
458 } 458 }
459 } 459 }
460 return true; 460 return true;
461} 461}
462void PhoneFormat::copyEvent( Event* to, Event* from ) 462void PhoneFormat::copyEvent( Event* to, Event* from )
463{ 463{
464 if ( from->dtStart().isValid() ) 464 if ( from->dtStart().isValid() )
465 to->setDtStart( from->dtStart() ); 465 to->setDtStart( from->dtStart() );
466 if ( from->dtEnd().isValid() ) 466 if ( from->dtEnd().isValid() )
467 to->setDtEnd( from->dtEnd() ); 467 to->setDtEnd( from->dtEnd() );
468 if ( !from->location().isEmpty() ) 468 if ( !from->location().isEmpty() )
469 to->setLocation( from->location() ); 469 to->setLocation( from->location() );
470 if ( !from->description().isEmpty() ) 470 if ( !from->description().isEmpty() )
471 to->setDescription( from->description() ); 471 to->setDescription( from->description() );
472 if ( !from->summary().isEmpty() ) 472 if ( !from->summary().isEmpty() )
473 to->setSummary( from->summary() ); 473 to->setSummary( from->summary() );
474 474
475 if ( from->alarms().count() ) { 475 if ( from->alarms().count() ) {
476 to->clearAlarms(); 476 to->clearAlarms();
477 Alarm *a = from->alarms().first(); 477 Alarm *a = from->alarms().first();
478 Alarm *b = to->newAlarm( ); 478 Alarm *b = to->newAlarm( );
479 b->setEnabled( a->enabled() ); 479 b->setEnabled( a->enabled() );
480 if ( a->hasStartOffset() ) { 480 if ( a->hasStartOffset() ) {
481 b->setStartOffset( a->startOffset() ); 481 b->setStartOffset( a->startOffset() );
482 } 482 }
483 if ( a->hasTime() ) 483 if ( a->hasTime() )
484 b->setTime( a->time() ); 484 b->setTime( a->time() );
485 485
486 } 486 }
487 QStringList cat = to->categories(); 487 QStringList cat = to->categories();
488 QStringList catFrom = from->categories(); 488 QStringList catFrom = from->categories();
489 QString nCat; 489 QString nCat;
490 int iii; 490 int iii;
491 for ( iii = 0; iii < catFrom.count();++iii ) { 491 for ( iii = 0; iii < catFrom.count();++iii ) {
492 nCat = catFrom[iii]; 492 nCat = catFrom[iii];
493 if ( !nCat.isEmpty() ) 493 if ( !nCat.isEmpty() )
494 if ( !cat.contains( nCat )) { 494 if ( !cat.contains( nCat )) {
495 cat << nCat; 495 cat << nCat;
496 } 496 }
497 } 497 }
498 to->setCategories( cat ); 498 to->setCategories( cat );
499 Recurrence * r = new Recurrence( *from->recurrence(),to); 499 Recurrence * r = new Recurrence( *from->recurrence(),to);
500 to->setRecurrence( r ) ; 500 to->setRecurrence( r ) ;
501 501
502 502
503} 503}
504void PhoneFormat::copyTodo( Todo* to, Todo* from ) 504void PhoneFormat::copyTodo( Todo* to, Todo* from )
505{ 505{
506 if ( from->dtStart().isValid() ) 506 if ( from->dtStart().isValid() )
507 to->setDtStart( from->dtStart() ); 507 to->setDtStart( from->dtStart() );
508 if ( from->dtDue().isValid() ) 508 if ( from->dtDue().isValid() )
509 to->setDtDue( from->dtDue() ); 509 to->setDtDue( from->dtDue() );
510 if ( !from->location().isEmpty() ) 510 if ( !from->location().isEmpty() )
511 to->setLocation( from->location() ); 511 to->setLocation( from->location() );
512 if ( !from->description().isEmpty() ) 512 if ( !from->description().isEmpty() )
513 to->setDescription( from->description() ); 513 to->setDescription( from->description() );
514 if ( !from->summary().isEmpty() ) 514 if ( !from->summary().isEmpty() )
515 to->setSummary( from->summary() ); 515 to->setSummary( from->summary() );
516 516
517 if ( from->alarms().count() ) { 517 if ( from->alarms().count() ) {
518 to->clearAlarms(); 518 to->clearAlarms();
519 Alarm *a = from->alarms().first(); 519 Alarm *a = from->alarms().first();
520 Alarm *b = to->newAlarm( ); 520 Alarm *b = to->newAlarm( );
521 b->setEnabled( a->enabled() ); 521 b->setEnabled( a->enabled() );
522 if ( a->hasStartOffset() ) 522 if ( a->hasStartOffset() )
523 b->setStartOffset( a->startOffset() ); 523 b->setStartOffset( a->startOffset() );
524 if ( a->hasTime() ) 524 if ( a->hasTime() )
525 b->setTime( a->time() ); 525 b->setTime( a->time() );
526 } 526 }
527 527
528 QStringList cat = to->categories(); 528 QStringList cat = to->categories();
529 QStringList catFrom = from->categories(); 529 QStringList catFrom = from->categories();
530 QString nCat; 530 QString nCat;
531 int iii; 531 int iii;
532 for ( iii = 0; iii < catFrom.count();++iii ) { 532 for ( iii = 0; iii < catFrom.count();++iii ) {
533 nCat = catFrom[iii]; 533 nCat = catFrom[iii];
534 if ( !nCat.isEmpty() ) 534 if ( !nCat.isEmpty() )
535 if ( !cat.contains( nCat )) { 535 if ( !cat.contains( nCat )) {
536 cat << nCat; 536 cat << nCat;
537 } 537 }
538 } 538 }
539 to->setCategories( cat ); 539 to->setCategories( cat );
540 if ( from->isCompleted() ) { 540 if ( from->isCompleted() ) {
541 to->setCompleted( true ); 541 to->setCompleted( true );
542 if( from->completed().isValid() ) 542 if( from->completed().isValid() )
543 to->setCompleted( from->completed() ); 543 to->setCompleted( from->completed() );
544 } else { 544 } else {
545 // set percentcomplete only, if to->isCompleted() 545 // set percentcomplete only, if to->isCompleted()
546 if ( to->isCompleted() ) 546 if ( to->isCompleted() )
547 to->setPercentComplete(from->percentComplete()); 547 to->setPercentComplete(from->percentComplete());
548 } 548 }
549 if( to->priority() == 2 && from->priority() == 1 ) 549 if( to->priority() == 2 && from->priority() == 1 )
550 ; //skip 550 ; //skip
551 else if (to->priority() == 4 && from->priority() == 5 ) 551 else if (to->priority() == 4 && from->priority() == 5 )
552 ; 552 ;
553 else 553 else
554 to->setPriority(from->priority()); 554 to->setPriority(from->priority());
555 555
556} 556}
557#include <qcstring.h> 557#include <qcstring.h>
558 558
559void PhoneFormat::afterSave( Incidence* inc) 559void PhoneFormat::afterSave( Incidence* inc)
560{ 560{
561 uint csum; 561 uint csum;
562 inc->removeID( mProfileName ); 562 inc->removeID( mProfileName );
563 if ( inc->type() == "Event") 563 if ( inc->type() == "Event")
564 csum = PhoneFormat::getCsumEvent( (Event*) inc ); 564 csum = PhoneFormat::getCsumEvent( (Event*) inc );
565 else 565 else
566 csum = PhoneFormat::getCsumTodo( (Todo*) inc ); 566 csum = PhoneFormat::getCsumTodo( (Todo*) inc );
567 inc->setCsum( mProfileName, QString::number( csum )); 567 inc->setCsum( mProfileName, QString::number( csum ));
568 568
569 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); 569 inc->setTempSyncStat( SYNC_TEMPSTATE_NEW_ID );
570 570
571} 571}
572bool PhoneFormat::save( Calendar *calendar) 572bool PhoneFormat::save( Calendar *calendar)
573{ 573{
574 QLabel status ( i18n(" Opening device ..."), 0 ); 574 QLabel status ( i18n(" Opening device ..."), 0 );
575 int w = status.sizeHint().width()+20 ; 575 int w = status.sizeHint().width()+20 ;
576 if ( w < 200 ) w = 230; 576 if ( w < 200 ) w = 230;
577 int h = status.sizeHint().height()+20 ; 577 int h = status.sizeHint().height()+20 ;
578 int dw = QApplication::desktop()->width(); 578 int dw = QApplication::desktop()->width();
579 int dh = QApplication::desktop()->height(); 579 int dh = QApplication::desktop()->height();
580 status.setCaption(i18n("Writing to phone...") ); 580 status.setCaption(i18n("Writing to phone...") );
581 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); 581 status.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
582 status.show(); 582 status.show();
583 status.raise(); 583 status.raise();
584 qApp->processEvents(); 584 qApp->processEvents();
585 QString message; 585 QString message;
586#ifdef _WIN32_ 586#ifdef _WIN32_
587 QString fileName = locateLocal("data", "korganizer") + "\\tempfile.vcs"; 587 QString fileName = locateLocal("tmp", "tempfile.vcs")
588#else 588#else
589 QString fileName = "/tmp/kdepimtemp.vcs"; 589 QString fileName = "/tmp/kdepimtemp.vcs";
590#endif 590#endif
591 591
592 // 1 remove events which should be deleted 592 // 1 remove events which should be deleted
593 QPtrList<Event> er = calendar->rawEvents(); 593 QPtrList<Event> er = calendar->rawEvents();
594 Event* ev = er.first(); 594 Event* ev = er.first();
595 while ( ev ) { 595 while ( ev ) {
596 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 596 if ( ev->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
597 calendar->deleteEvent( ev ); 597 calendar->deleteEvent( ev );
598 } else { 598 } else {
599 599
600 } 600 }
601 ev = er.next(); 601 ev = er.next();
602 } 602 }
603 // 2 remove todos which should be deleted 603 // 2 remove todos which should be deleted
604 QPtrList<Todo> tl = calendar->rawTodos(); 604 QPtrList<Todo> tl = calendar->rawTodos();
605 Todo* to = tl.first(); 605 Todo* to = tl.first();
606 while ( to ) { 606 while ( to ) {
607 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { 607 if ( to->tempSyncStat() == SYNC_TEMPSTATE_DELETE ) {
608 calendar->deleteTodo( to ); 608 calendar->deleteTodo( to );
609 } else { 609 } else {
610 if ( to->isCompleted()) { 610 if ( to->isCompleted()) {
611 calendar->deleteTodo( to ); 611 calendar->deleteTodo( to );
612 } 612 }
613 } 613 }
614 to = tl.next(); 614 to = tl.next();
615 } 615 }
616 // 3 save file 616 // 3 save file
617 VCalFormat vfsave; 617 VCalFormat vfsave;
618 vfsave.setLocalTime ( true ); 618 vfsave.setLocalTime ( true );
619 if ( ! vfsave.save( calendar, fileName ) ) 619 if ( ! vfsave.save( calendar, fileName ) )
620 return false; 620 return false;
621 // 4 call kammu 621 // 4 call kammu
622#ifdef DESKTOP_VERSION 622#ifdef DESKTOP_VERSION
623 QString command ="./kammu --restore " + fileName ; 623 QString command ="./kammu --restore " + fileName ;
624#else 624#else
625 QString command ="kammu --restore " + fileName ; 625 QString command ="kammu --restore " + fileName ;
626#endif 626#endif
627 int ret; 627 int ret;
628 while ( (ret = system ( command.latin1())) != 0 ) { 628 while ( (ret = system ( command.latin1())) != 0 ) {
629 qDebug("Error S::command returned %d. asking users", ret); 629 qDebug("Error S::command returned %d. asking users", ret);
630 int retval = KMessageBox::warningContinueCancel(0, 630 int retval = KMessageBox::warningContinueCancel(0,
631 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel")); 631 i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone sync"),i18n("Retry"),i18n("Cancel"));
632 if ( retval != KMessageBox::Continue ) 632 if ( retval != KMessageBox::Continue )
633 return false; 633 return false;
634 } 634 }
635 635
636 // 5 reread data 636 // 5 reread data
637 message = i18n(" Rereading all data ... "); 637 message = i18n(" Rereading all data ... ");
638 status.setText ( message ); 638 status.setText ( message );
639 qApp->processEvents(); 639 qApp->processEvents();
640 CalendarLocal* calendarTemp = new CalendarLocal(); 640 CalendarLocal* calendarTemp = new CalendarLocal();
641 calendarTemp->setTimeZoneId( calendar->timeZoneId()); 641 calendarTemp->setTimeZoneId( calendar->timeZoneId());
642 if ( ! load( calendarTemp,calendar) ){ 642 if ( ! load( calendarTemp,calendar) ){
643 qDebug("error reloading calendar "); 643 qDebug("error reloading calendar ");
644 delete calendarTemp; 644 delete calendarTemp;
645 return false; 645 return false;
646 } 646 }
647 // 6 compare data 647 // 6 compare data
648 648
649//algo 6 compare event 649//algo 6 compare event
650 er = calendar->rawEvents(); 650 er = calendar->rawEvents();
651 ev = er.first(); 651 ev = er.first();
652 message = i18n(" Comparing event # "); 652 message = i18n(" Comparing event # ");
653 QPtrList<Event> er1 = calendarTemp->rawEvents(); 653 QPtrList<Event> er1 = calendarTemp->rawEvents();
654 Event* ev1; 654 Event* ev1;
655 int procCount = 0; 655 int procCount = 0;
656 while ( ev ) { 656 while ( ev ) {
657 //qDebug("event new ID %s",ev->summary().latin1()); 657 //qDebug("event new ID %s",ev->summary().latin1());
658 status.setText ( message + QString::number ( ++procCount ) ); 658 status.setText ( message + QString::number ( ++procCount ) );
659 qApp->processEvents(); 659 qApp->processEvents();
660 uint csum; 660 uint csum;
661 csum = PhoneFormat::getCsumEvent( ev ); 661 csum = PhoneFormat::getCsumEvent( ev );
662 QString cSum = QString::number( csum ); 662 QString cSum = QString::number( csum );
663 //ev->setCsum( mProfileName, cSum ); 663 //ev->setCsum( mProfileName, cSum );
664 //qDebug("Event cSum %s ", cSum.latin1()); 664 //qDebug("Event cSum %s ", cSum.latin1());
665 ev1 = er1.first(); 665 ev1 = er1.first();
666 while ( ev1 ) { 666 while ( ev1 ) {
667 if ( ev1->getCsum( mProfileName ) == cSum ) { 667 if ( ev1->getCsum( mProfileName ) == cSum ) {
668 er1.remove( ev1 ); 668 er1.remove( ev1 );
669 afterSave( ev ); 669 afterSave( ev );
670 ev->setID(mProfileName, ev1->getID(mProfileName) ); 670 ev->setID(mProfileName, ev1->getID(mProfileName) );
671 //qDebug("Event found on phone for %s ", ev->summary().latin1()); 671 //qDebug("Event found on phone for %s ", ev->summary().latin1());
672 672
673 break; 673 break;
674 } 674 }
675 ev1 = er1.next(); 675 ev1 = er1.next();
676 } 676 }
677 if ( ! ev1 ) { 677 if ( ! ev1 ) {
678 // ev->removeID(mProfileName); 678 // ev->removeID(mProfileName);
679 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1()); 679 qDebug("ERROR: No event found on phone for %s ", ev->summary().latin1());
680 } 680 }
681 681
682 682
683 ev = er.next(); 683 ev = er.next();
684 } 684 }
685 //algo 6 compare todo 685 //algo 6 compare todo
686 tl = calendar->rawTodos(); 686 tl = calendar->rawTodos();
687 to = tl.first(); 687 to = tl.first();
688 procCount = 0; 688 procCount = 0;
689 QPtrList<Todo> tl1 = calendarTemp->rawTodos(); 689 QPtrList<Todo> tl1 = calendarTemp->rawTodos();
690 Todo* to1 ; 690 Todo* to1 ;
691 message = i18n(" Comparing todo # "); 691 message = i18n(" Comparing todo # ");
692 while ( to ) { 692 while ( to ) {
693 status.setText ( message + QString::number ( ++procCount ) ); 693 status.setText ( message + QString::number ( ++procCount ) );
694 qApp->processEvents(); 694 qApp->processEvents();
695 uint csum; 695 uint csum;
696 csum = PhoneFormat::getCsumTodo( to ); 696 csum = PhoneFormat::getCsumTodo( to );
697 QString cSum = QString::number( csum ); 697 QString cSum = QString::number( csum );
698 //to->setCsum( mProfileName, cSum ); 698 //to->setCsum( mProfileName, cSum );
699 //qDebug("Todo cSum %s ", cSum.latin1()); 699 //qDebug("Todo cSum %s ", cSum.latin1());
700 Todo* to1 = tl1.first(); 700 Todo* to1 = tl1.first();
701 while ( to1 ) { 701 while ( to1 ) {
702 if ( to1->getCsum( mProfileName ) == cSum ) { 702 if ( to1->getCsum( mProfileName ) == cSum ) {
703 tl1.remove( to1 ); 703 tl1.remove( to1 );
704 afterSave( to ); 704 afterSave( to );
705 to->setID(mProfileName, to1->getID(mProfileName) ); 705 to->setID(mProfileName, to1->getID(mProfileName) );
706 break; 706 break;
707 } 707 }
708 to1 = tl1.next(); 708 to1 = tl1.next();
709 } 709 }
710 if ( ! to1 ) { 710 if ( ! to1 ) {
711 //to->removeID(mProfileName); 711 //to->removeID(mProfileName);
712 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1()); 712 qDebug("ERROR: No todo found on phone for %s ", to->summary().latin1());
713 } 713 }
714 714
715 to = tl.next(); 715 to = tl.next();
716 } 716 }
717 delete calendarTemp; 717 delete calendarTemp;
718 return true; 718 return true;
719 719
720 720
721 721
722} 722}
723 723
724 724
725QString PhoneFormat::toString( Calendar * ) 725QString PhoneFormat::toString( Calendar * )
726{ 726{
727 return QString::null; 727 return QString::null;
728} 728}
729bool PhoneFormat::fromString( Calendar *calendar, const QString & text) 729bool PhoneFormat::fromString( Calendar *calendar, const QString & text)
730{ 730{
731 return false; 731 return false;
732} 732}