summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--bin/kdepim/WhatsNew.txt5
-rw-r--r--gammu/emb/common/phone/alcatel/alcatel.c2
-rw-r--r--gammu/emb/gammu/depend/nokia/dct3.c2
-rw-r--r--gammu/emb/gammu/depend/nokia/dct3trac/wmx.c2
-rw-r--r--gammu/emb/gammu/depend/nokia/dct4.c2
-rw-r--r--gammu/emb/gammu/depend/siemens/dsiemens.c2
-rw-r--r--kaddressbook/addresseeeditorwidget.h1
-rw-r--r--pwmanager/libcrypt/cipher/serpent.c4
-rw-r--r--pwmanager/pwmanager/binentrygen.cpp5
-rw-r--r--pwmanager/pwmanager/binentrygen.h2
-rw-r--r--pwmanager/pwmanager/blowfish.cpp2
-rw-r--r--pwmanager/pwmanager/blowfish.h4
-rw-r--r--pwmanager/pwmanager/genpasswd.cpp1
-rw-r--r--pwmanager/pwmanager/libgcryptif.h4
-rw-r--r--pwmanager/pwmanager/pwmexception.h3
-rw-r--r--pwmanager/pwmanager/randomizer.h1
16 files changed, 28 insertions, 14 deletions
diff --git a/bin/kdepim/WhatsNew.txt b/bin/kdepim/WhatsNew.txt
index cd37aac..9879ef0 100644
--- a/bin/kdepim/WhatsNew.txt
+++ b/bin/kdepim/WhatsNew.txt
@@ -1,128 +1,133 @@
1Info about the changes in new versions of KDE-Pim/Pi 1Info about the changes in new versions of KDE-Pim/Pi
2 2
3********** VERSION 2.2.8 ************ 3********** VERSION 2.2.8 ************
4 4
5 5
6I forgot what I fixed... 6I forgot what I fixed...
7 7
8Some minor fixes in KA/Pi and KO/Pi. 8Some minor fixes in KA/Pi and KO/Pi.
9 9
10KA/Pi uses popup menu now for quick category selection in contact edit dialog. 10KA/Pi uses popup menu now for quick category selection in contact edit dialog.
11 11
12In the Pi-syc mode of KO/Pi it is now possible to define specific resources which can be synced with the remote pi-sync server. 12In the Pi-syc mode of KO/Pi it is now possible to define specific resources which can be synced with the remote pi-sync server.
13This feature must be considered as unstable - it still needs some more testing. 13This feature must be considered as unstable - it still needs some more testing.
14 14
15On Wintendo now KA/Pi can sync with Outlook. The configuration of the sync needs some moer tweking.
16Fixed some gcc 4.xx compilation probs.
17Fixed an annoying cursor focus reset problem when editing and (auto-)saving journal enries in KO/Pi.
18
19
15********** VERSION 2.2.7 ************ 20********** VERSION 2.2.7 ************
16 21
17Added for Desktop Versions (Windows + Linux) the possibility to specify an email client to call if the user clicks on an emailaddress. 22Added for Desktop Versions (Windows + Linux) the possibility to specify an email client to call if the user clicks on an emailaddress.
18(Menu: Config->Global Settings->Extern.Applications: E-mail). 23(Menu: Config->Global Settings->Extern.Applications: E-mail).
19Added as default (and example) Mozilla Thunderbird settings. 24Added as default (and example) Mozilla Thunderbird settings.
20If the path to the binary in this Mozilla Thunderbird example is not matching your environment you can take these settings as an template and configure "User defined email client". 25If the path to the binary in this Mozilla Thunderbird example is not matching your environment you can take these settings as an template and configure "User defined email client".
21 26
22********** VERSION 2.2.6 ************ 27********** VERSION 2.2.6 ************
23 28
24KO/Pi: 29KO/Pi:
25Made navigation in datepicker more userfriendly when using keyboard for scrolling. 30Made navigation in datepicker more userfriendly when using keyboard for scrolling.
26KO/Pi Alarm applet: 31KO/Pi Alarm applet:
27Made font size for the two popup menus with larger font configurable: 32Made font size for the two popup menus with larger font configurable:
28Change size with menu: 33Change size with menu:
29Play Beeps->Font Size 34Play Beeps->Font Size
30Save settings such that it will be restored after next reboot with menu: 35Save settings such that it will be restored after next reboot with menu:
31Play Beeps->Config->Save. 36Play Beeps->Config->Save.
32KA/Pi: 37KA/Pi:
33Big change! Needed for the upcoming Outlook sync: 38Big change! Needed for the upcoming Outlook sync:
34(Outlook sync available appr. end of 2005) 39(Outlook sync available appr. end of 2005)
35Telephone number types are now fixed in KA/Pi 40Telephone number types are now fixed in KA/Pi
36(but still compatible with the vCard standard, of cource) 41(but still compatible with the vCard standard, of cource)
37and they are compatible with the types used by the evil empire. 42and they are compatible with the types used by the evil empire.
38That makes syncing with OL possible and make it possible to sync better with mobile devices. 43That makes syncing with OL possible and make it possible to sync better with mobile devices.
39NOTE: 44NOTE:
40All your telephone types will be converted automatically at loading/importing! 45All your telephone types will be converted automatically at loading/importing!
41Such that it may be a good idea to make a backup of the data before starting KA/Pi. 46Such that it may be a good idea to make a backup of the data before starting KA/Pi.
42But the editing of phone numbers and types has changed completely such that it is now much faster to edit/change types and numbers. 47But the editing of phone numbers and types has changed completely such that it is now much faster to edit/change types and numbers.
43HINT: 48HINT:
44To see whether there was some number for some contact not converted senseful, choose 49To see whether there was some number for some contact not converted senseful, choose
45Menu: View->Modify view 50Menu: View->Modify view
46and add "Other Phone" ( in German "Sonst. Telefon") to the view. 51and add "Other Phone" ( in German "Sonst. Telefon") to the view.
47If a type was not converted senseful to some of the 18 new, fixed types, it will get the "Other" type. 52If a type was not converted senseful to some of the 18 new, fixed types, it will get the "Other" type.
48 53
49********** VERSION 2.2.5 ************ 54********** VERSION 2.2.5 ************
50 55
51Bugfixes in KO/Pi, KA/Pi and OM/Pi. 56Bugfixes in KO/Pi, KA/Pi and OM/Pi.
52Added possibility to disable auto saving in KO/Pi. 57Added possibility to disable auto saving in KO/Pi.
53How to disable it? Good question! Next question, please? 58How to disable it? Good question! Next question, please?
54Added info about count of events/todos/journals to calendar info. 59Added info about count of events/todos/journals to calendar info.
55 60
56 61
57********** VERSION 2.2.4 ************ 62********** VERSION 2.2.4 ************
58 63
59KO/Pi alarm applet: Made font smaller and added a dealy before starting KO/Pi to avoid problems accessing data storage when an alarm did wake up the Z. 64KO/Pi alarm applet: Made font smaller and added a dealy before starting KO/Pi to avoid problems accessing data storage when an alarm did wake up the Z.
60Added 3 sec notification about a started timer. 65Added 3 sec notification about a started timer.
61 66
62KO/Pi: 67KO/Pi:
63Added export option for all data to File->Export menu. 68Added export option for all data to File->Export menu.
64Better management if a save error occours. 69Better management if a save error occours.
65Added 15 sec delay in automatic saving when Z wake up from suspend and the automatic save timer did expire - to avoid problems accessing data storage directly after wake up. 70Added 15 sec delay in automatic saving when Z wake up from suspend and the automatic save timer did expire - to avoid problems accessing data storage directly after wake up.
66Fix for displaying month names of an utf8 translated language (like Russian). I hope a Russian version of KO/Pi will be available soon. 71Fix for displaying month names of an utf8 translated language (like Russian). I hope a Russian version of KO/Pi will be available soon.
67 72
68Added duration info about multiday events. 73Added duration info about multiday events.
69Changed behaviour of "Set complete" in Todo viewer: Now Todo viewer closes not automatically. 74Changed behaviour of "Set complete" in Todo viewer: Now Todo viewer closes not automatically.
70 75
71KA/Pi: 76KA/Pi:
72Added for vCard import the option to import contact data in Latin1 format. 77Added for vCard import the option to import contact data in Latin1 format.
73 78
74********** VERSION 2.2.3 ************ 79********** VERSION 2.2.3 ************
75 80
76KO/Pi: 81KO/Pi:
77Fixed a problem with (non empty) exception dates in the exception date edit dialog of recurring events for newly created events. 82Fixed a problem with (non empty) exception dates in the exception date edit dialog of recurring events for newly created events.
78 83
79Fixed usability problem in KA/Pi: 84Fixed usability problem in KA/Pi:
80Now searching works for "all phone numbers and all addresses" if "all fields" is selected as search option. 85Now searching works for "all phone numbers and all addresses" if "all fields" is selected as search option.
81 86
82Changed some behaviour in OM/Pi mail management to make it more usable. 87Changed some behaviour in OM/Pi mail management to make it more usable.
83 88
84 89
85********** VERSION 2.2.2 ************ 90********** VERSION 2.2.2 ************
86 91
87KO/Pi: 92KO/Pi:
88Fixed a problem with the sort order of last modified date in list view. 93Fixed a problem with the sort order of last modified date in list view.
89KA/Pi: 94KA/Pi:
90Fixed a resource config read problem on windows. 95Fixed a resource config read problem on windows.
91 96
92 97
93********** VERSION 2.2.1 ************ 98********** VERSION 2.2.1 ************
94 99
95KO/Pi: 100KO/Pi:
96Fixed a problem displaying very long allday events in agenda view in single day mode. 101Fixed a problem displaying very long allday events in agenda view in single day mode.
97Fixed a problem with the default settings for new todos. 102Fixed a problem with the default settings for new todos.
98Added an error message dialog if saving of calendar files is not possible. 103Added an error message dialog if saving of calendar files is not possible.
99Made it impossible to close KO/Pi if saving fails. 104Made it impossible to close KO/Pi if saving fails.
100Fixed a problem adding calendars on windows such that these calendars can be used on the memory stick. 105Fixed a problem adding calendars on windows such that these calendars can be used on the memory stick.
101Added config options for conflict detection. 106Added config options for conflict detection.
102 107
103KA/Pi: 108KA/Pi:
104Added a config option to turn on asking before a contact is deleted. 109Added a config option to turn on asking before a contact is deleted.
105Fixed a problem with the default view and view selection at startup. 110Fixed a problem with the default view and view selection at startup.
106Formatted name is now set on import, if formatted name is empty. 111Formatted name is now set on import, if formatted name is empty.
107Fixed a problem of displaying images in the contact details view: 112Fixed a problem of displaying images in the contact details view:
108Now the wid/hei ratio is not changed. 113Now the wid/hei ratio is not changed.
109I a picture is larger than 128 pixels in wid or hei it is downscaled to 114I a picture is larger than 128 pixels in wid or hei it is downscaled to
110max 128 pixels wid/hei. 115max 128 pixels wid/hei.
111 116
112********** VERSION 2.2.0 ************ 117********** VERSION 2.2.0 ************
113 118
114New stable release! 119New stable release!
115Fixed some minor usability problems. 120Fixed some minor usability problems.
116Added writing of next alarm to a file for usage on pdaXrom. 121Added writing of next alarm to a file for usage on pdaXrom.
117 122
118 123
119************************************* 124*************************************
120 125
121You can find the complete changelog 126You can find the complete changelog
122from version 1.7.7 to 2.2.0 127from version 1.7.7 to 2.2.0
123in the source package or on 128in the source package or on
124 129
125http://www.pi-sync.net/html/changelog.html 130http://www.pi-sync.net/html/changelog.html
126 131
127 132
128 133
diff --git a/gammu/emb/common/phone/alcatel/alcatel.c b/gammu/emb/common/phone/alcatel/alcatel.c
index b75077f..718d91e 100644
--- a/gammu/emb/common/phone/alcatel/alcatel.c
+++ b/gammu/emb/common/phone/alcatel/alcatel.c
@@ -1,827 +1,827 @@
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[]; 59static 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_SetFastSMSSending(GSM_StateMachine *s, bool enable);
105 extern GSM_Error ATGEN_SetIncomingCB (GSM_StateMachine *s, bool enable); 105 extern GSM_Error ATGEN_SetIncomingCB (GSM_StateMachine *s, bool enable);
106 extern GSM_Error ATGEN_SetIncomingSMS (GSM_StateMachine *s, bool enable); 106 extern GSM_Error ATGEN_SetIncomingSMS (GSM_StateMachine *s, bool enable);
107 107
108/** 108/**
109 * 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
110 * 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
111 * that I found... 111 * that I found...
112 */ 112 */
113unsigned char GSM_AlcatelAlphabet[] = 113unsigned char GSM_AlcatelAlphabet[] =
114{ 114{
115 /* in phone unicode description*/ 115 /* in phone unicode description*/
116 0x80, 0x00,0x20, /* empty */ 116 0x80, 0x00,0x20, /* empty */
117 0x81, 0x00,0x20, /* empty*/ 117 0x81, 0x00,0x20, /* empty*/
118 0x82, 0x00,0x20, /* empty*/ 118 0x82, 0x00,0x20, /* empty*/
119 0x83, 0x00,0x20, /* empty*/ 119 0x83, 0x00,0x20, /* empty*/
120 120
121 0x84, 0x00,0xe7, /* c cedilla*/ 121 0x84, 0x00,0xe7, /* c cedilla*/
122 0x85, 0x20,0x26, /* ... */ 122 0x85, 0x20,0x26, /* ... */
123 0x86, 0x03,0xc0, /* pi */ 123 0x86, 0x03,0xc0, /* pi */
124 0x87, 0x01,0x3e, /* l caron*/ 124 0x87, 0x01,0x3e, /* l caron*/
125 0x88, 0x00,0xc0, /* A grave*/ 125 0x88, 0x00,0xc0, /* A grave*/
126 0x89, 0x00,0xc1, /* A acute*/ 126 0x89, 0x00,0xc1, /* A acute*/
127 0x8a, 0x00,0xc2, /* A circumflex*/ 127 0x8a, 0x00,0xc2, /* A circumflex*/
128 0x8b, 0x00,0xc3, /* A tilde*/ 128 0x8b, 0x00,0xc3, /* A tilde*/
129 0x8c, 0x00,0xc8, /* E grave*/ 129 0x8c, 0x00,0xc8, /* E grave*/
130 0x8d, 0x00,0xca, /* E circumflex*/ 130 0x8d, 0x00,0xca, /* E circumflex*/
131 0x8e, 0x00,0xcb, /* E diaresis*/ 131 0x8e, 0x00,0xcb, /* E diaresis*/
132 0x8f, 0x00,0xcc, /* I grave*/ 132 0x8f, 0x00,0xcc, /* I grave*/
133 0x90, 0x00,0xcd, /* I acute*/ 133 0x90, 0x00,0xcd, /* I acute*/
134 0x91, 0x00,0xd0, /* ETH */ 134 0x91, 0x00,0xd0, /* ETH */
135 0x92, 0x00,0xd2, /* O grave*/ 135 0x92, 0x00,0xd2, /* O grave*/
136 0x93, 0x00,0xd3, /* O acute*/ 136 0x93, 0x00,0xd3, /* O acute*/
137 0x94, 0x00,0xd4, /* O circumflex*/ 137 0x94, 0x00,0xd4, /* O circumflex*/
138 0x95, 0x00,0xd5, /* O tilde*/ 138 0x95, 0x00,0xd5, /* O tilde*/
139 0x96, 0x00,0xd9, /* U grave*/ 139 0x96, 0x00,0xd9, /* U grave*/
140 0x97, 0x00,0xda, /* U acute*/ 140 0x97, 0x00,0xda, /* U acute*/
141 0x98, 0x00,0xe1, /* a acute*/ 141 0x98, 0x00,0xe1, /* a acute*/
142 0x99, 0x00,0xe2, /* a circumflex*/ 142 0x99, 0x00,0xe2, /* a circumflex*/
143 0x9a, 0x00,0xe3, /* a tilde*/ 143 0x9a, 0x00,0xe3, /* a tilde*/
144 0x9b, 0x00,0xea, /* e circumflex*/ 144 0x9b, 0x00,0xea, /* e circumflex*/
145 0x9c, 0x00,0xeb, /* e diaresis*/ 145 0x9c, 0x00,0xeb, /* e diaresis*/
146 0x9d, 0x00,0xed, /* i acute*/ 146 0x9d, 0x00,0xed, /* i acute*/
147 0x9e, 0x00,0xee, /* i circumflex*/ 147 0x9e, 0x00,0xee, /* i circumflex*/
148 0x9f, 0x00,0xef, /* i diaresis*/ 148 0x9f, 0x00,0xef, /* i diaresis*/
149 0xa0, 0x00,0xf3, /* o acute*/ 149 0xa0, 0x00,0xf3, /* o acute*/
150 0xa1, 0x00,0xf4, /* o circumflex*/ 150 0xa1, 0x00,0xf4, /* o circumflex*/
151 0xa2, 0x00,0xf5, /* o tilde*/ 151 0xa2, 0x00,0xf5, /* o tilde*/
152 0xa3, 0x00,0xfa, /* u acute*/ 152 0xa3, 0x00,0xfa, /* u acute*/
153 0xa4, 0x00,0xa2, /* cent */ 153 0xa4, 0x00,0xa2, /* cent */
154 0xa5, 0x00,0x5b, /* [ */ 154 0xa5, 0x00,0x5b, /* [ */
155 0xa6, 0x01,0x59, /* r caron*/ 155 0xa6, 0x01,0x59, /* r caron*/
156 0xa7, 0x01,0x0d, /* c caron*/ 156 0xa7, 0x01,0x0d, /* c caron*/
157 0xa8, 0x01,0x61, /* s caron*/ 157 0xa8, 0x01,0x61, /* s caron*/
158 0xa9, 0x01,0x1b, /* e caron*/ 158 0xa9, 0x01,0x1b, /* e caron*/
159 0xaa, 0x01,0x6f, /* u ring*/ 159 0xaa, 0x01,0x6f, /* u ring*/
160 0xab, 0x00,0xfd, /* y acute*/ 160 0xab, 0x00,0xfd, /* y acute*/
161 0xac, 0x00,0xf0, /* eth */ 161 0xac, 0x00,0xf0, /* eth */
162 0xad, 0x01,0x07, /* c acute*/ 162 0xad, 0x01,0x07, /* c acute*/
163 0xae, 0x01,0x19, /* e ogonek*/ 163 0xae, 0x01,0x19, /* e ogonek*/
164 0xaf, 0x01,0x05, /* a ogonek*/ 164 0xaf, 0x01,0x05, /* a ogonek*/
165 0xb0, 0x01,0x7c, /* z dot*/ 165 0xb0, 0x01,0x7c, /* z dot*/
166 0xb1, 0x01,0x7a, /* z acute*/ 166 0xb1, 0x01,0x7a, /* z acute*/
167 0xb2, 0x01,0x5b, /* s acute*/ 167 0xb2, 0x01,0x5b, /* s acute*/
168 0xb3, 0x01,0x44, /* n acute*/ 168 0xb3, 0x01,0x44, /* n acute*/
169 0xb4, 0x01,0x42, /* l stroke*/ 169 0xb4, 0x01,0x42, /* l stroke*/
170 170
171 0xb5, 0x00,0x20, /* empty*/ 171 0xb5, 0x00,0x20, /* empty*/
172 172
173 0xb6, 0x01,0x48, /* n caron*/ 173 0xb6, 0x01,0x48, /* n caron*/
174 0xb7, 0x01,0x65, /* t caron*/ 174 0xb7, 0x01,0x65, /* t caron*/
175 175
176 0xb8, 0x00,0x20, /* empty*/ 176 0xb8, 0x00,0x20, /* empty*/
177 177
178 0xb9, 0x01,0x7e, /* z caron*/ 178 0xb9, 0x01,0x7e, /* z caron*/
179 0xba, 0x01,0xe7, /* g caron*/ 179 0xba, 0x01,0xe7, /* g caron*/
180 180
181 0xbb, 0x00,0x20, /* empty*/ 181 0xbb, 0x00,0x20, /* empty*/
182 0xbc, 0x00,0x20, /* empty*/ 182 0xbc, 0x00,0x20, /* empty*/
183 183
184 0xbd, 0x1e,0x20, /* G macron*/ 184 0xbd, 0x1e,0x20, /* G macron*/
185 0xbe, 0x1e,0x21, /* g macron*/ 185 0xbe, 0x1e,0x21, /* g macron*/
186 0xbf, 0x01,0x5e, /* S cedilla*/ 186 0xbf, 0x01,0x5e, /* S cedilla*/
187 0xc0, 0x01,0x5f, /* s cedilla*/ 187 0xc0, 0x01,0x5f, /* s cedilla*/
188 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 */
189 0xc2, 0x01,0x31, /* i dotless*/ 189 0xc2, 0x01,0x31, /* i dotless*/
190 0xc3, 0x01,0x68, /* U tilde*/ 190 0xc3, 0x01,0x68, /* U tilde*/
191 0xc4, 0x01,0x50, /* O dbl acute*/ 191 0xc4, 0x01,0x50, /* O dbl acute*/
192 0xc5, 0x01,0x69, /* u tilde*/ 192 0xc5, 0x01,0x69, /* u tilde*/
193 0xc6, 0x01,0x51, /* o dbl acute*/ 193 0xc6, 0x01,0x51, /* o dbl acute*/
194 0xc7, 0x27,0xa9, /* => */ 194 0xc7, 0x27,0xa9, /* => */
195 0xc8, 0x27,0xa8, /* filled =>*/ 195 0xc8, 0x27,0xa8, /* filled =>*/
196 0xc9, 0x00,0xd7, /* x */ 196 0xc9, 0x00,0xd7, /* x */
197 0xca, 0x00,0x5d, /* ] */ 197 0xca, 0x00,0x5d, /* ] */
198 0xcb, 0x26,0x0f, /* phone*/ 198 0xcb, 0x26,0x0f, /* phone*/
199 0xcc, 0x01,0x0f, /* d caron*/ 199 0xcc, 0x01,0x0f, /* d caron*/
200 200
201 0xcd, 0x00,0x20, /* empty*/ 201 0xcd, 0x00,0x20, /* empty*/
202 202
203 0xce, 0x00,0x7e, /* ~ */ 203 0xce, 0x00,0x7e, /* ~ */
204 0xcf, 0x00,0x5c, /* \ */ 204 0xcf, 0x00,0x5c, /* \ */
205 0xd0, 0x00,0x5e, /* ^ */ 205 0xd0, 0x00,0x5e, /* ^ */
206 206
207 0xd1, 0x00,0x20, /* empty*/ 207 0xd1, 0x00,0x20, /* empty*/
208 208
209 0xd2, 0x00,0x7b, /* { */ 209 0xd2, 0x00,0x7b, /* { */
210 0xd3, 0x00,0x7c, /* | */ 210 0xd3, 0x00,0x7c, /* | */
211 0xd4, 0x00,0x7d, /* } */ 211 0xd4, 0x00,0x7d, /* } */
212 212
213 0xd5, 0x00,0x20, /* empty*/ 213 0xd5, 0x00,0x20, /* empty*/
214 214
215 0xd6, 0x01,0x63, /* t cedilla*/ 215 0xd6, 0x01,0x63, /* t cedilla*/
216 216
217 0xd7, 0x00,0x20, /* empty*/ 217 0xd7, 0x00,0x20, /* empty*/
218 0xd8, 0x00,0x20, /* empty*/ 218 0xd8, 0x00,0x20, /* empty*/
219 0xd9, 0x00,0x20, /* empty*/ 219 0xd9, 0x00,0x20, /* empty*/
220 0xda, 0x00,0x20, /* empty*/ 220 0xda, 0x00,0x20, /* empty*/
221 0xdb, 0x00,0x20, /* empty*/ 221 0xdb, 0x00,0x20, /* empty*/
222 0xdc, 0x00,0x20, /* empty*/ 222 0xdc, 0x00,0x20, /* empty*/
223 0xdd, 0x00,0x20, /* empty*/ 223 0xdd, 0x00,0x20, /* empty*/
224 0xde, 0x00,0x20, /* empty*/ 224 0xde, 0x00,0x20, /* empty*/
225 0xdf, 0x00,0x20, /* empty*/ 225 0xdf, 0x00,0x20, /* empty*/
226 0xe0, 0x00,0x20, /* empty*/ 226 0xe0, 0x00,0x20, /* empty*/
227 227
228 0xe1, 0x00,0x20, /* two candles*/ /* FIXME */ 228 0xe1, 0x00,0x20, /* two candles*/ /* FIXME */
229 229
230 0xe2, 0x00,0x20, /* empty*/ 230 0xe2, 0x00,0x20, /* empty*/
231 0xe3, 0x00,0x20, /* empty*/ 231 0xe3, 0x00,0x20, /* empty*/
232 0xe4, 0x00,0x20, /* empty*/ 232 0xe4, 0x00,0x20, /* empty*/
233 233
234 0xe5, 0x01,0xce, /* a caron*/ 234 0xe5, 0x01,0xce, /* a caron*/
235 0xe6, 0x01,0x01, /* a macron*/ 235 0xe6, 0x01,0x01, /* a macron*/
236 0xe7, 0x01,0x13, /* e macron*/ 236 0xe7, 0x01,0x13, /* e macron*/
237 0xe8, 0x01,0x2b, /* i macron*/ 237 0xe8, 0x01,0x2b, /* i macron*/
238 0xe9, 0x01,0x4d, /* o macron*/ 238 0xe9, 0x01,0x4d, /* o macron*/
239 0xea, 0x01,0x6b, /* u macron*/ 239 0xea, 0x01,0x6b, /* u macron*/
240 0xeb, 0x00,0x41, /* A */ 240 0xeb, 0x00,0x41, /* A */
241 0xec, 0x00,0x40, /* @ */ 241 0xec, 0x00,0x40, /* @ */
242 0xed, 0x00,0x20,/* some strange char :-) */ /* FIXME */ 242 0xed, 0x00,0x20,/* some strange char :-) */ /* FIXME */
243 243
244 0xee, 0x00,0x20, /* big key stroken*/ /* FIXME */ 244 0xee, 0x00,0x20, /* big key stroken*/ /* FIXME */
245 0xef, 0x00,0x20, /* big key*/ /* FIXME */ 245 0xef, 0x00,0x20, /* big key*/ /* FIXME */
246 246
247 0xf0, 0x00,0x20, /* empty*/ 247 0xf0, 0x00,0x20, /* empty*/
248 248
249 0xf1, 0x00,0x31, /* 1 */ 249 0xf1, 0x00,0x31, /* 1 */
250 0xf2, 0x00,0x21, /* bold !*/ 250 0xf2, 0x00,0x21, /* bold !*/
251 0xf3, 0x26,0x0e, /* black phone*/ 251 0xf3, 0x26,0x0e, /* black phone*/
252 0xf4, 0x00,0x26, /* & */ 252 0xf4, 0x00,0x26, /* & */
253 0xf5, 0x23,0x7e, /* bell */ 253 0xf5, 0x23,0x7e, /* bell */
254 0xf6, 0x26,0x6a, /* note */ 254 0xf6, 0x26,0x6a, /* note */
255 255
256 0xf7, 0x27,0x13, /* okay inv*/ /* FIXME */ 256 0xf7, 0x27,0x13, /* okay inv*/ /* FIXME */
257 0xf8, 0x27,0x13, /* okay */ 257 0xf8, 0x27,0x13, /* okay */
258 258
259 0xf9, 0x00,0x20, /* empty*/ 259 0xf9, 0x00,0x20, /* empty*/
260 260
261 0xfa, 0x00,0x20, /* key */ /* FIXME */ 261 0xfa, 0x00,0x20, /* key */ /* FIXME */
262 262
263 0xfb, 0x00,0x20, /* empty*/ 263 0xfb, 0x00,0x20, /* empty*/
264 264
265 0xfc, 0x20,0xac, /* Euro */ 265 0xfc, 0x20,0xac, /* Euro */
266 0xfd, 0x21,0x97, /* NE arrow*/ 266 0xfd, 0x21,0x97, /* NE arrow*/
267 0xfe, 0x21,0x98, /* SE arrow*/ 267 0xfe, 0x21,0x98, /* SE arrow*/
268 268
269 0xff, 0x00,0x20, /* empty*/ 269 0xff, 0x00,0x20, /* empty*/
270 270
271 0x00, 0x00,0x00 271 0x00, 0x00,0x00
272}; 272};
273 273
274/* This is being called from atgen */ 274/* This is being called from atgen */
275 GSM_Error ALCATEL_ProtocolVersionReply(GSM_Protocol_Message msg, GSM_StateMachine *s) 275 GSM_Error ALCATEL_ProtocolVersionReply(GSM_Protocol_Message msg, GSM_StateMachine *s)
276{ 276{
277 char *str, *str2; 277 char *str, *str2;
278/* 278/*
279 * Reply received here looks like: 279 * Reply received here looks like:
280 * 1 "AT+CPROT=?" 280 * 1 "AT+CPROT=?"
281 * 2 "+CPROT: 0,"V1.0",1" 281 * 2 "+CPROT: 0,"V1.0",1"
282 * 3 "+CPROT: 16,"V1.1",16" 282 * 3 "+CPROT: 16,"V1.1",16"
283 * 4 "OK" 283 * 4 "OK"
284 */ 284 */
285 switch (s->Phone.Data.Priv.ATGEN.ReplyState) { 285 switch (s->Phone.Data.Priv.ATGEN.ReplyState) {
286 case AT_Reply_OK: 286 case AT_Reply_OK:
287 str = strstr(msg.Buffer, "\"V"); 287 str = strstr(msg.Buffer, "\"V");
288 if (str == NULL) return ERR_UNKNOWNRESPONSE; 288 if (str == NULL) return ERR_UNKNOWNRESPONSE;
289 str += 2; 289 str += 2;
290 while((str2 = strstr(str, "\"V")) != NULL) str = str2 + 2; 290 while((str2 = strstr(str, "\"V")) != NULL) str = str2 + 2;
291 if (strncmp(str, "1.0", 3) == 0) { 291 if (strncmp(str, "1.0", 3) == 0) {
292 s->Phone.Data.Priv.ALCATEL.ProtocolVersion = V_1_0; 292 s->Phone.Data.Priv.ALCATEL.ProtocolVersion = V_1_0;
293 } else if (strncmp(str, "1.1", 3) == 0) { 293 } else if (strncmp(str, "1.1", 3) == 0) {
294 s->Phone.Data.Priv.ALCATEL.ProtocolVersion = V_1_1; 294 s->Phone.Data.Priv.ALCATEL.ProtocolVersion = V_1_1;
295 } else { 295 } else {
296 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");
297 return ERR_NOTIMPLEMENTED; 297 return ERR_NOTIMPLEMENTED;
298 } 298 }
299 return ERR_NONE; 299 return ERR_NONE;
300 case AT_Reply_Error: 300 case AT_Reply_Error:
301 case AT_Reply_CMSError: 301 case AT_Reply_CMSError:
302 return ATGEN_HandleCMSError(s); 302 return ATGEN_HandleCMSError(s);
303 default: 303 default:
304 return ERR_UNKNOWNRESPONSE; 304 return ERR_UNKNOWNRESPONSE;
305 } 305 }
306} 306}
307 307
308static GSM_Error ALCATEL_SetBinaryMode(GSM_StateMachine *s) 308static GSM_Error ALCATEL_SetBinaryMode(GSM_StateMachine *s)
309{ 309{
310 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 310 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
311 GSM_Error error; 311 GSM_Error error;
312 312
313 if (Priv->Mode == ModeBinary) return ERR_NONE; 313 if (Priv->Mode == ModeBinary) return ERR_NONE;
314 314
315 dbgprintf ("Changing to binary mode\n"); 315 dbgprintf ("Changing to binary mode\n");
316 316
317 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);
318 if (error != ERR_NONE) return error; 318 if (error != ERR_NONE) return error;
319 319
320 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);
321 if (error != ERR_NONE) return error; 321 if (error != ERR_NONE) return error;
322 322
323 if (Priv->ProtocolVersion == V_1_0) { 323 if (Priv->ProtocolVersion == V_1_0) {
324 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);
325 } else { 325 } else {
326 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);
327 } 327 }
328 328
329 if (error == ERR_TIMEOUT && s->Speed != 19200) { 329 if (error == ERR_TIMEOUT && s->Speed != 19200) {
330 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");
331 } 331 }
332 332
333 if (error != ERR_NONE) return error; 333 if (error != ERR_NONE) return error;
334 334
335 dbgprintf ("Changing protocol to Alcabus\n"); 335 dbgprintf ("Changing protocol to Alcabus\n");
336 336
337 s->Protocol.Functions = &ALCABUSProtocol; 337 s->Protocol.Functions = &ALCABUSProtocol;
338 error = s->Protocol.Functions->Initialise(s); 338 error = s->Protocol.Functions->Initialise(s);
339 if (error != ERR_NONE) { 339 if (error != ERR_NONE) {
340 s->Protocol.Functions = &ATProtocol; 340 s->Protocol.Functions = &ATProtocol;
341 return error; 341 return error;
342 } 342 }
343 s->Phone.Functions->ReplyFunctions= ALCATELReplyFunctions; 343 s->Phone.Functions->ReplyFunctions= ALCATELReplyFunctions;
344 Priv->Mode = ModeBinary; 344 Priv->Mode = ModeBinary;
345 Priv->BinaryItem = 0; 345 Priv->BinaryItem = 0;
346 Priv->BinaryType = 0; 346 Priv->BinaryType = 0;
347 Priv->BinaryState = StateAttached; 347 Priv->BinaryState = StateAttached;
348 return ERR_NONE; 348 return ERR_NONE;
349} 349}
350 350
351static 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) {
352 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 352 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
353 GSM_Error error; 353 GSM_Error error;
354 unsigned char attach_buffer[] = {0x00, 0x00, 0x7C ,0x20}; 354 unsigned char attach_buffer[] = {0x00, 0x00, 0x7C ,0x20};
355 unsigned char detach_buffer[] = {0x00, 0x01, 0x7C ,0x00}; 355 unsigned char detach_buffer[] = {0x00, 0x01, 0x7C ,0x00};
356 unsigned char start_buffer[] = 356 unsigned char start_buffer[] =
357 {0x00, 0x04, 0x7C, 0x80, /* 4 byte database id follows */ 357 {0x00, 0x04, 0x7C, 0x80, /* 4 byte database id follows */
358 0x12, 0x34, 0x56, 0x78}; 358 0x12, 0x34, 0x56, 0x78};
359 unsigned char end_buffer[] = 359 unsigned char end_buffer[] =
360 {0x00, 0x04, 0x7C, 0x82, 360 {0x00, 0x04, 0x7C, 0x82,
361 0x00, /* type */ 361 0x00, /* type */
362 0x00, 0x00, 0x00, 0x00}; /* TimeStamp */ 362 0x00, 0x00, 0x00, 0x00}; /* TimeStamp */
363 unsigned char close_buffer[] = 363 unsigned char close_buffer[] =
364 {0x00, 0x04, 364 {0x00, 0x04,
365 0x00, /*type */ 365 0x00, /*type */
366 0x23, 0x01}; 366 0x23, 0x01};
367 unsigned char select1_buffer[] = 367 unsigned char select1_buffer[] =
368 {0x00, 0x00, 368 {0x00, 0x00,
369 0x00, /*type */ 369 0x00, /*type */
370 0x20}; 370 0x20};
371 unsigned char select2_buffer[] = 371 unsigned char select2_buffer[] =
372 {0x00, 0x04, 372 {0x00, 0x04,
373 0x00, /*type */ 373 0x00, /*type */
374 0x22, 0x01, 0x00}; 374 0x22, 0x01, 0x00};
375 unsigned char begin_buffer[] = 375 unsigned char begin_buffer[] =
376 {0x00, 0x04, 0x7C, 0x81, 376 {0x00, 0x04, 0x7C, 0x81,
377 0x00, /*type */ 377 0x00, /*type */
378 0x00, 0x85, 0x00}; 378 0x00, 0x85, 0x00};
379 unsigned char commit_buffer[] = 379 unsigned char commit_buffer[] =
380 {0x00, 0x04, 380 {0x00, 0x04,
381 0x00, /*type */ 381 0x00, /*type */
382 0x20, 0x01}; 382 0x20, 0x01};
383 383
384 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);
385 error = ALCATEL_SetBinaryMode(s); 385 error = ALCATEL_SetBinaryMode(s);
386 if (error != ERR_NONE) return error; 386 if (error != ERR_NONE) return error;
387 387
388 /* Do we need to do anything? */ 388 /* Do we need to do anything? */
389 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;
390 390
391 /* 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 */
392 if (Priv->BinaryState == StateEdit) { 392 if (Priv->BinaryState == StateEdit) {
393 /* Something has changed, we will have to reread fields! */ 393 /* Something has changed, we will have to reread fields! */
394 Priv->CurrentFieldsItem = -1; 394 Priv->CurrentFieldsItem = -1;
395 switch (Priv->BinaryType) { 395 switch (Priv->BinaryType) {
396 case TypeCalendar: 396 case TypeCalendar:
397 commit_buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR; 397 commit_buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR;
398 break; 398 break;
399 case TypeContacts: 399 case TypeContacts:
400 commit_buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 400 commit_buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
401 break; 401 break;
402 case TypeToDo: 402 case TypeToDo:
403 commit_buffer[2] = ALCATEL_SYNC_TYPE_TODO; 403 commit_buffer[2] = ALCATEL_SYNC_TYPE_TODO;
404 break; 404 break;
405 } 405 }
406 dbgprintf ("Commiting edited record\n"); 406 dbgprintf ("Commiting edited record\n");
407 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);
408 if (error != ERR_NONE) return error; 408 if (error != ERR_NONE) return error;
409 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelCommit2); 409 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelCommit2);
410 if (error != ERR_NONE) return error; 410 if (error != ERR_NONE) return error;
411 Priv->BinaryState = StateSession; 411 Priv->BinaryState = StateSession;
412 Priv->BinaryItem = 0; 412 Priv->BinaryItem = 0;
413 } 413 }
414 414
415 /* Do we want to edit something of same type? */ 415 /* Do we want to edit something of same type? */
416 if ((state == StateEdit) && (type == Priv->BinaryType)) { 416 if ((state == StateEdit) && (type == Priv->BinaryType)) {
417 /* 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
418 * 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
419 * mode. 419 * mode.
420 */ 420 */
421 Priv->BinaryState = StateEdit; 421 Priv->BinaryState = StateEdit;
422 Priv->BinaryItem = item; 422 Priv->BinaryItem = item;
423 return ERR_NONE; 423 return ERR_NONE;
424 } 424 }
425 425
426 /* 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 */
427 if ((state == Priv->BinaryState) && (type == Priv->BinaryType)) { 427 if ((state == Priv->BinaryState) && (type == Priv->BinaryType)) {
428 return ERR_NONE; 428 return ERR_NONE;
429 } 429 }
430 430
431 /* Do we need to close session? */ 431 /* Do we need to close session? */
432 if (Priv->BinaryState == StateSession) { 432 if (Priv->BinaryState == StateSession) {
433 dbgprintf ("Ending session\n"); 433 dbgprintf ("Ending session\n");
434 switch (Priv->BinaryType) { 434 switch (Priv->BinaryType) {
435 case TypeCalendar: 435 case TypeCalendar:
436 end_buffer[4] = ALCATEL_BEGIN_SYNC_CALENDAR; 436 end_buffer[4] = ALCATEL_BEGIN_SYNC_CALENDAR;
437 break; 437 break;
438 case TypeContacts: 438 case TypeContacts:
439 end_buffer[4] = ALCATEL_BEGIN_SYNC_CONTACTS; 439 end_buffer[4] = ALCATEL_BEGIN_SYNC_CONTACTS;
440 break; 440 break;
441 case TypeToDo: 441 case TypeToDo:
442 end_buffer[4] = ALCATEL_BEGIN_SYNC_TODO; 442 end_buffer[4] = ALCATEL_BEGIN_SYNC_TODO;
443 break; 443 break;
444 } 444 }
445 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);
446 if (error != ERR_NONE) return error; 446 if (error != ERR_NONE) return error;
447 447
448 switch (Priv->BinaryType) { 448 switch (Priv->BinaryType) {
449 case TypeCalendar: 449 case TypeCalendar:
450 close_buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR; 450 close_buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR;
451 break; 451 break;
452 case TypeContacts: 452 case TypeContacts:
453 close_buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 453 close_buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
454 break; 454 break;
455 case TypeToDo: 455 case TypeToDo:
456 close_buffer[2] = ALCATEL_SYNC_TYPE_TODO; 456 close_buffer[2] = ALCATEL_SYNC_TYPE_TODO;
457 break; 457 break;
458 } 458 }
459 dbgprintf ("Closing session\n"); 459 dbgprintf ("Closing session\n");
460 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);
461 if (error != ERR_NONE) return error; 461 if (error != ERR_NONE) return error;
462 462
463 dbgprintf ("Detaching binary mode\n"); 463 dbgprintf ("Detaching binary mode\n");
464 GSM_WaitFor (s, detach_buffer, 4, 0x02, ALCATEL_TIMEOUT, ID_AlcatelDetach); 464 GSM_WaitFor (s, detach_buffer, 4, 0x02, ALCATEL_TIMEOUT, ID_AlcatelDetach);
465 465
466 Priv->BinaryState = StateAttached; 466 Priv->BinaryState = StateAttached;
467 Priv->BinaryType = 0; 467 Priv->BinaryType = 0;
468 } 468 }
469 469
470 /* Do we need to open session? */ 470 /* Do we need to open session? */
471 if (state == StateSession || state == StateEdit) { 471 if (state == StateSession || state == StateEdit) {
472 dbgprintf ("Starting session for %s\n", 472 dbgprintf ("Starting session for %s\n",
473 (type == TypeCalendar ? "Calendar" : 473 (type == TypeCalendar ? "Calendar" :
474 (type == TypeToDo ? "Todo" : 474 (type == TypeToDo ? "Todo" :
475 (type == TypeContacts ? "Contacts" : 475 (type == TypeContacts ? "Contacts" :
476 "Unknown!")))); 476 "Unknown!"))));
477 /* Fill up buffers */ 477 /* Fill up buffers */
478 switch (type) { 478 switch (type) {
479 case TypeCalendar: 479 case TypeCalendar:
480 select1_buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR; 480 select1_buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR;
481 select2_buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR; 481 select2_buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR;
482 begin_buffer[4] = ALCATEL_BEGIN_SYNC_CALENDAR; 482 begin_buffer[4] = ALCATEL_BEGIN_SYNC_CALENDAR;
483 break; 483 break;
484 case TypeContacts: 484 case TypeContacts:
485 select1_buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 485 select1_buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
486 select2_buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 486 select2_buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
487 begin_buffer[4] = ALCATEL_BEGIN_SYNC_CONTACTS; 487 begin_buffer[4] = ALCATEL_BEGIN_SYNC_CONTACTS;
488 break; 488 break;
489 case TypeToDo: 489 case TypeToDo:
490 select1_buffer[2] = ALCATEL_SYNC_TYPE_TODO; 490 select1_buffer[2] = ALCATEL_SYNC_TYPE_TODO;
491 select2_buffer[2] = ALCATEL_SYNC_TYPE_TODO; 491 select2_buffer[2] = ALCATEL_SYNC_TYPE_TODO;
492 begin_buffer[4] = ALCATEL_BEGIN_SYNC_TODO; 492 begin_buffer[4] = ALCATEL_BEGIN_SYNC_TODO;
493 break; 493 break;
494 } 494 }
495 dbgprintf ("Attaching in binary mode\n"); 495 dbgprintf ("Attaching in binary mode\n");
496 496
497 /* Communicate */ 497 /* Communicate */
498 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);
499 if (error != ERR_NONE) return error; 499 if (error != ERR_NONE) return error;
500 500
501 smprintf(s,"Start session\n"); 501 smprintf(s,"Start session\n");
502 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);
503 if (error != ERR_NONE) return error; 503 if (error != ERR_NONE) return error;
504 504
505 smprintf(s,"Select type\n"); 505 smprintf(s,"Select type\n");
506 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);
507 if (error != ERR_NONE) return error; 507 if (error != ERR_NONE) return error;
508 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);
509 if (error != ERR_NONE) return error; 509 if (error != ERR_NONE) return error;
510 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelSelect3); 510 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelSelect3);
511 if (error != ERR_NONE) return error; 511 if (error != ERR_NONE) return error;
512 512
513 smprintf(s,"Begin transfer\n"); 513 smprintf(s,"Begin transfer\n");
514 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);
515 if (error != ERR_NONE) return error; 515 if (error != ERR_NONE) return error;
516 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelBegin2); 516 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelBegin2);
517 if (error != ERR_NONE) return error; 517 if (error != ERR_NONE) return error;
518 518
519 Priv->BinaryState = StateSession; 519 Priv->BinaryState = StateSession;
520 Priv->BinaryType = type; 520 Priv->BinaryType = type;
521 /* Do we want to edit something of same type? */ 521 /* Do we want to edit something of same type? */
522 if ((state == StateEdit) && (type == Priv->BinaryType)) { 522 if ((state == StateEdit) && (type == Priv->BinaryType)) {
523 Priv->BinaryState = StateEdit; 523 Priv->BinaryState = StateEdit;
524 Priv->BinaryItem = item; 524 Priv->BinaryItem = item;
525 return ERR_NONE; 525 return ERR_NONE;
526 } 526 }
527 } 527 }
528 return ERR_NONE; 528 return ERR_NONE;
529} 529}
530 530
531static GSM_Error ALCATEL_SetATMode(GSM_StateMachine *s) 531static GSM_Error ALCATEL_SetATMode(GSM_StateMachine *s)
532{ 532{
533 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 533 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
534 GSM_Error error; 534 GSM_Error error;
535 535
536 if (Priv->Mode == ModeAT) return ERR_NONE; 536 if (Priv->Mode == ModeAT) return ERR_NONE;
537 537
538 error = ALCATEL_GoToBinaryState(s, StateAttached, 0, 0); 538 error = ALCATEL_GoToBinaryState(s, StateAttached, 0, 0);
539 if (error != ERR_NONE) return error; 539 if (error != ERR_NONE) return error;
540 540
541 error = s->Protocol.Functions->Terminate(s); 541 error = s->Protocol.Functions->Terminate(s);
542 if (error != ERR_NONE) return error; 542 if (error != ERR_NONE) return error;
543 543
544 dbgprintf ("Changing protocol to AT\n"); 544 dbgprintf ("Changing protocol to AT\n");
545 s->Protocol.Functions = &ATProtocol; 545 s->Protocol.Functions = &ATProtocol;
546 s->Phone.Functions->ReplyFunctions= ATGENReplyFunctions; 546 s->Phone.Functions->ReplyFunctions= ATGENReplyFunctions;
547 Priv->Mode = ModeAT; 547 Priv->Mode = ModeAT;
548 s->Phone.Data.Priv.ATGEN.PBKCharset= 0; 548 s->Phone.Data.Priv.ATGEN.PBKCharset= 0;
549 s->Phone.Data.Priv.ATGEN.PBKMemory= 0; 549 s->Phone.Data.Priv.ATGEN.PBKMemory= 0;
550 550
551 my_sleep(100); 551 my_sleep(100);
552 552
553 /* 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,
554 * 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
555 * intetionally ignored. 555 * intetionally ignored.
556 */ 556 */
557 GSM_WaitFor (s, "AT\r", 3, 0x00, 0, ID_IncomingFrame); 557 GSM_WaitFor (s, "AT\r", 3, 0x00, 0, ID_IncomingFrame);
558 558
559 return ERR_NONE; 559 return ERR_NONE;
560} 560}
561 561
562static GSM_Error ALCATEL_Initialise(GSM_StateMachine *s) 562static GSM_Error ALCATEL_Initialise(GSM_StateMachine *s)
563{ 563{
564 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 564 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
565 GSM_Error error; 565 GSM_Error error;
566 566
567 Priv->Mode = ModeAT; 567 Priv->Mode = ModeAT;
568 568
569 Priv->CalendarItems = NULL; 569 Priv->CalendarItems = NULL;
570 Priv->ContactsItems = NULL; 570 Priv->ContactsItems = NULL;
571 Priv->ToDoItems = NULL; 571 Priv->ToDoItems = NULL;
572 Priv->CalendarItemsCount = 0; 572 Priv->CalendarItemsCount = 0;
573 Priv->ToDoItemsCount = 0; 573 Priv->ToDoItemsCount = 0;
574 Priv->ContactsItemsCount = 0; 574 Priv->ContactsItemsCount = 0;
575 Priv->CurrentFields[0] = 0; 575 Priv->CurrentFields[0] = 0;
576 Priv->CurrentFieldsCount = 0; 576 Priv->CurrentFieldsCount = 0;
577 Priv->CurrentFieldsItem = 0; 577 Priv->CurrentFieldsItem = 0;
578 Priv->CurrentFieldsType = 0; 578 Priv->CurrentFieldsType = 0;
579 Priv->ProtocolVersion = V_1_0; 579 Priv->ProtocolVersion = V_1_0;
580 Priv->CurrentFieldsItem = -1; 580 Priv->CurrentFieldsItem = -1;
581 581
582 Priv->CurrentCategoriesCount = 0; 582 Priv->CurrentCategoriesCount = 0;
583 Priv->CurrentCategoriesType = 0; 583 Priv->CurrentCategoriesType = 0;
584 584
585 s->Protocol.Functions = &ATProtocol; 585 s->Protocol.Functions = &ATProtocol;
586 s->Phone.Functions->ReplyFunctions= ATGENReplyFunctions; 586 s->Phone.Functions->ReplyFunctions= ATGENReplyFunctions;
587 587
588 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) {
589 smprintf(s,"AT initialisation failed, trying to stop binary mode...\n"); 589 smprintf(s,"AT initialisation failed, trying to stop binary mode...\n");
590 s->Protocol.Functions = &ALCABUSProtocol; 590 s->Protocol.Functions = &ALCABUSProtocol;
591 error = s->Protocol.Functions->Terminate(s); 591 error = s->Protocol.Functions->Terminate(s);
592 s->Protocol.Functions = &ATProtocol; 592 s->Protocol.Functions = &ATProtocol;
593 593
594 error = ATGEN_Initialise(s); 594 error = ATGEN_Initialise(s);
595 if (error != ERR_NONE) return error; 595 if (error != ERR_NONE) return error;
596 } 596 }
597 597
598 return ERR_NONE; 598 return ERR_NONE;
599} 599}
600 600
601static GSM_Error ALCATEL_Terminate(GSM_StateMachine *s) 601static GSM_Error ALCATEL_Terminate(GSM_StateMachine *s)
602{ 602{
603 GSM_Error error; 603 GSM_Error error;
604 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 604 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
605 605
606 free(Priv->CalendarItems); 606 free(Priv->CalendarItems);
607 free(Priv->ContactsItems); 607 free(Priv->ContactsItems);
608 free(Priv->ToDoItems); 608 free(Priv->ToDoItems);
609 error = ALCATEL_SetATMode(s); 609 error = ALCATEL_SetATMode(s);
610 return ATGEN_Terminate(s); 610 return ATGEN_Terminate(s);
611} 611}
612 612
613/* finds whether id is set in the phone */ 613/* finds whether id is set in the phone */
614static GSM_Error ALCATEL_IsIdAvailable(GSM_StateMachine *s, int id) { 614static GSM_Error ALCATEL_IsIdAvailable(GSM_StateMachine *s, int id) {
615 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 615 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
616 int i; 616 int i;
617 617
618 if (id > ALCATEL_MAX_LOCATION) return ERR_INVALIDLOCATION; 618 if (id > ALCATEL_MAX_LOCATION) return ERR_INVALIDLOCATION;
619 619
620 switch (Priv->BinaryType) { 620 switch (Priv->BinaryType) {
621 case TypeCalendar: 621 case TypeCalendar:
622 Priv->CurrentList = &(Priv->CalendarItems); 622 Priv->CurrentList = &(Priv->CalendarItems);
623 Priv->CurrentCount = &(Priv->CalendarItemsCount); 623 Priv->CurrentCount = &(Priv->CalendarItemsCount);
624 break; 624 break;
625 case TypeContacts: 625 case TypeContacts:
626 Priv->CurrentList = &(Priv->ContactsItems); 626 Priv->CurrentList = &(Priv->ContactsItems);
627 Priv->CurrentCount = &(Priv->ContactsItemsCount); 627 Priv->CurrentCount = &(Priv->ContactsItemsCount);
628 break; 628 break;
629 case TypeToDo: 629 case TypeToDo:
630 Priv->CurrentList = &(Priv->ToDoItems); 630 Priv->CurrentList = &(Priv->ToDoItems);
631 Priv->CurrentCount = &(Priv->ToDoItemsCount); 631 Priv->CurrentCount = &(Priv->ToDoItemsCount);
632 break; 632 break;
633 } 633 }
634 634
635 for (i=0; i<*Priv->CurrentCount; i++) { 635 for (i=0; i<*Priv->CurrentCount; i++) {
636 if ((*Priv->CurrentList)[i] == id) return ERR_NONE; 636 if ((*Priv->CurrentList)[i] == id) return ERR_NONE;
637 } 637 }
638 638
639 return ERR_EMPTY; 639 return ERR_EMPTY;
640} 640}
641 641
642/* finds next id that is available in the phone */ 642/* finds next id that is available in the phone */
643static GSM_Error ALCATEL_GetNextId(GSM_StateMachine *s, int *id) { 643static GSM_Error ALCATEL_GetNextId(GSM_StateMachine *s, int *id) {
644 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 644 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
645 int i = 0; 645 int i = 0;
646 int next = ALCATEL_MAX_LOCATION; 646 int next = ALCATEL_MAX_LOCATION;
647 647
648 switch (Priv->BinaryType) { 648 switch (Priv->BinaryType) {
649 case TypeCalendar: 649 case TypeCalendar:
650 Priv->CurrentList = &(Priv->CalendarItems); 650 Priv->CurrentList = &(Priv->CalendarItems);
651 Priv->CurrentCount = &(Priv->CalendarItemsCount); 651 Priv->CurrentCount = &(Priv->CalendarItemsCount);
652 break; 652 break;
653 case TypeContacts: 653 case TypeContacts:
654 Priv->CurrentList = &(Priv->ContactsItems); 654 Priv->CurrentList = &(Priv->ContactsItems);
655 Priv->CurrentCount = &(Priv->ContactsItemsCount); 655 Priv->CurrentCount = &(Priv->ContactsItemsCount);
656 break; 656 break;
657 case TypeToDo: 657 case TypeToDo:
658 Priv->CurrentList = &(Priv->ToDoItems); 658 Priv->CurrentList = &(Priv->ToDoItems);
659 Priv->CurrentCount = &(Priv->ToDoItemsCount); 659 Priv->CurrentCount = &(Priv->ToDoItemsCount);
660 break; 660 break;
661 } 661 }
662 662
663 for (i=0; i<*Priv->CurrentCount; i++) { 663 for (i=0; i<*Priv->CurrentCount; i++) {
664 if (((*Priv->CurrentList)[i] > *id) && ((*Priv->CurrentList)[i] < next )) { 664 if (((*Priv->CurrentList)[i] > *id) && ((*Priv->CurrentList)[i] < next )) {
665 next = (*Priv->CurrentList)[i]; 665 next = (*Priv->CurrentList)[i];
666 } 666 }
667 } 667 }
668 if (next == ALCATEL_MAX_LOCATION) { 668 if (next == ALCATEL_MAX_LOCATION) {
669 return ERR_EMPTY; 669 return ERR_EMPTY;
670 } else { 670 } else {
671 *id = next; 671 *id = next;
672 return ERR_NONE; 672 return ERR_NONE;
673 } 673 }
674} 674}
675 675
676static GSM_Error ALCATEL_ReplyGetIds(GSM_Protocol_Message msg, GSM_StateMachine *s) 676static GSM_Error ALCATEL_ReplyGetIds(GSM_Protocol_Message msg, GSM_StateMachine *s)
677{ 677{
678 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL; 678 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL;
679 int count,i,pos; 679 int count,i,pos;
680 680
681 count = msg.Buffer[10]; 681 count = msg.Buffer[10];
682 *Priv->CurrentCount += count; 682 *Priv->CurrentCount += count;
683 683
684 *Priv->CurrentList = (int *)realloc(*Priv->CurrentList, (*Priv->CurrentCount + 1)* sizeof(int)); 684 *Priv->CurrentList = (int *)realloc(*Priv->CurrentList, (*Priv->CurrentCount + 1)* sizeof(int));
685 if (*Priv->CurrentList == NULL) return ERR_MOREMEMORY; 685 if (*Priv->CurrentList == NULL) return ERR_MOREMEMORY;
686 686
687 for (i = 0; i < count; i++) { 687 for (i = 0; i < count; i++) {
688 pos = 11 + (4 * i); 688 pos = 11 + (4 * i);
689 (*Priv->CurrentList)[*Priv->CurrentCount - count + i] = msg.Buffer[pos + 3] + 689 (*Priv->CurrentList)[*Priv->CurrentCount - count + i] = msg.Buffer[pos + 3] +
690 (msg.Buffer[pos + 2] << 8) + 690 (msg.Buffer[pos + 2] << 8) +
691 (msg.Buffer[pos + 1] << 16) + 691 (msg.Buffer[pos + 1] << 16) +
692 (msg.Buffer[pos] << 24); 692 (msg.Buffer[pos] << 24);
693 } 693 }
694 (*Priv->CurrentList)[*Priv->CurrentCount] = 0; 694 (*Priv->CurrentList)[*Priv->CurrentCount] = 0;
695 695
696 /* If last byte is 0, then we transmitted all items */ 696 /* If last byte is 0, then we transmitted all items */
697 Priv->TransferCompleted = msg.Buffer[4 + msg.Buffer[4]] == 0; 697 Priv->TransferCompleted = msg.Buffer[4 + msg.Buffer[4]] == 0;
698 return ERR_NONE; 698 return ERR_NONE;
699} 699}
700 700
701static GSM_Error ALCATEL_GetAvailableIds(GSM_StateMachine *s, bool refresh) 701static GSM_Error ALCATEL_GetAvailableIds(GSM_StateMachine *s, bool refresh)
702{ 702{
703 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 703 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
704 GSM_Error error; 704 GSM_Error error;
705 int i; 705 int i;
706 unsigned char buffer[] = 706 unsigned char buffer[] =
707 {0x00, 0x04, 707 {0x00, 0x04,
708 0x00, /*type */ 708 0x00, /*type */
709 0x2F, 0x01}; 709 0x2F, 0x01};
710 710
711 if (Priv->BinaryState != StateSession) return ERR_UNKNOWN; 711 if (Priv->BinaryState != StateSession) return ERR_UNKNOWN;
712 712
713 switch (Priv->BinaryType) { 713 switch (Priv->BinaryType) {
714 case TypeCalendar: 714 case TypeCalendar:
715 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR; 715 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR;
716 Priv->CurrentList= &(Priv->CalendarItems); 716 Priv->CurrentList= &(Priv->CalendarItems);
717 Priv->CurrentCount= &(Priv->CalendarItemsCount); 717 Priv->CurrentCount= &(Priv->CalendarItemsCount);
718 break; 718 break;
719 case TypeContacts: 719 case TypeContacts:
720 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 720 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
721 Priv->CurrentList= &(Priv->ContactsItems); 721 Priv->CurrentList= &(Priv->ContactsItems);
722 Priv->CurrentCount= &(Priv->ContactsItemsCount); 722 Priv->CurrentCount= &(Priv->ContactsItemsCount);
723 break; 723 break;
724 case TypeToDo: 724 case TypeToDo:
725 buffer[2] = ALCATEL_SYNC_TYPE_TODO; 725 buffer[2] = ALCATEL_SYNC_TYPE_TODO;
726 Priv->CurrentList= &(Priv->ToDoItems); 726 Priv->CurrentList= &(Priv->ToDoItems);
727 Priv->CurrentCount= &(Priv->ToDoItemsCount); 727 Priv->CurrentCount= &(Priv->ToDoItemsCount);
728 break; 728 break;
729 } 729 }
730 730
731 if (*Priv->CurrentList != NULL) { 731 if (*Priv->CurrentList != NULL) {
732 if (!refresh) return ERR_NONE; 732 if (!refresh) return ERR_NONE;
733 free(*Priv->CurrentList); 733 free(*Priv->CurrentList);
734 *Priv->CurrentList = NULL; 734 *Priv->CurrentList = NULL;
735 } 735 }
736 smprintf(s,"Reading items list\n"); 736 smprintf(s,"Reading items list\n");
737 737
738 *Priv->CurrentCount = 0; 738 *Priv->CurrentCount = 0;
739 Priv->TransferCompleted = false; 739 Priv->TransferCompleted = false;
740 740
741 error=GSM_WaitFor (s, buffer, 5, 0x02, ALCATEL_TIMEOUT, ID_AlcatelGetIds1); 741 error=GSM_WaitFor (s, buffer, 5, 0x02, ALCATEL_TIMEOUT, ID_AlcatelGetIds1);
742 if (error != ERR_NONE) return error; 742 if (error != ERR_NONE) return error;
743 743
744 while (!Priv->TransferCompleted) { 744 while (!Priv->TransferCompleted) {
745 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelGetIds2); 745 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelGetIds2);
746 if (error != ERR_NONE) return error; 746 if (error != ERR_NONE) return error;
747 } 747 }
748 748
749 i = 0; 749 i = 0;
750 smprintf(s,"Received %d ids: ", *Priv->CurrentCount); 750 smprintf(s,"Received %d ids: ", *Priv->CurrentCount);
751 for (i=0; i < *Priv->CurrentCount; i++) { 751 for (i=0; i < *Priv->CurrentCount; i++) {
752 smprintf(s,"%x ", (*Priv->CurrentList)[i]); 752 smprintf(s,"%x ", (*Priv->CurrentList)[i]);
753 } 753 }
754 smprintf(s,"\n"); 754 smprintf(s,"\n");
755 755
756 return ERR_NONE; 756 return ERR_NONE;
757} 757}
758 758
759static GSM_Error ALCATEL_ReplyGetFields(GSM_Protocol_Message msg, GSM_StateMachine *s) 759static GSM_Error ALCATEL_ReplyGetFields(GSM_Protocol_Message msg, GSM_StateMachine *s)
760{ 760{
761 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL; 761 GSM_Phone_ALCATELData *Priv = &s->Phone.Data.Priv.ALCATEL;
762 int i; 762 int i;
763 763
764 if (msg.Buffer[14] > GSM_PHONEBOOK_ENTRIES) { 764 if (msg.Buffer[14] > GSM_PHONEBOOK_ENTRIES) {
765 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]);
766 Priv->CurrentFieldsCount = GSM_PHONEBOOK_ENTRIES; 766 Priv->CurrentFieldsCount = GSM_PHONEBOOK_ENTRIES;
767 } else { 767 } else {
768 Priv->CurrentFieldsCount = msg.Buffer[14]; 768 Priv->CurrentFieldsCount = msg.Buffer[14];
769 } 769 }
770 770
771 Priv->CurrentFields[Priv->CurrentFieldsCount] = 0; 771 Priv->CurrentFields[Priv->CurrentFieldsCount] = 0;
772 772
773 for (i = 0; i < Priv->CurrentFieldsCount; i++) { 773 for (i = 0; i < Priv->CurrentFieldsCount; i++) {
774 Priv->CurrentFields[i] = msg.Buffer[15 + i]; 774 Priv->CurrentFields[i] = msg.Buffer[15 + i];
775 } 775 }
776 776
777 return ERR_NONE; 777 return ERR_NONE;
778} 778}
779 779
780static GSM_Error ALCATEL_GetFields(GSM_StateMachine *s, int id) { 780static GSM_Error ALCATEL_GetFields(GSM_StateMachine *s, int id) {
781 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL; 781 GSM_Phone_ALCATELData*Priv = &s->Phone.Data.Priv.ALCATEL;
782 GSM_Error error; 782 GSM_Error error;
783 int i; 783 int i;
784 unsigned char buffer[] = 784 unsigned char buffer[] =
785 {0x00, 0x04, 785 {0x00, 0x04,
786 0x00, /* type */ 786 0x00, /* type */
787 0x30, 0x01, 787 0x30, 0x01,
788 0x00, 0x00, 0x00, 0x00}; /* item */ 788 0x00, 0x00, 0x00, 0x00}; /* item */
789 789
790 if (Priv->BinaryState != StateSession) return ERR_UNKNOWN; 790 if (Priv->BinaryState != StateSession) return ERR_UNKNOWN;
791 if ((Priv->CurrentFieldsItem == id) && (Priv->CurrentFieldsType == Priv->BinaryType)) return ERR_NONE; 791 if ((Priv->CurrentFieldsItem == id) && (Priv->CurrentFieldsType == Priv->BinaryType)) return ERR_NONE;
792 792
793 smprintf(s,"Reading item fields (%d)\n", id); 793 smprintf(s,"Reading item fields (%d)\n", id);
794 794
795 buffer[5] = (id >> 24); 795 buffer[5] = (id >> 24);
796 buffer[6] = ((id >> 16) & 0xff); 796 buffer[6] = ((id >> 16) & 0xff);
797 buffer[7] = ((id >> 8) & 0xff); 797 buffer[7] = ((id >> 8) & 0xff);
798 buffer[8] = (id & 0xff); 798 buffer[8] = (id & 0xff);
799 799
800 switch (Priv->BinaryType) { 800 switch (Priv->BinaryType) {
801 case TypeCalendar: 801 case TypeCalendar:
802 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR; 802 buffer[2] = ALCATEL_SYNC_TYPE_CALENDAR;
803 break; 803 break;
804 case TypeContacts: 804 case TypeContacts:
805 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS; 805 buffer[2] = ALCATEL_SYNC_TYPE_CONTACTS;
806 break; 806 break;
807 case TypeToDo: 807 case TypeToDo:
808 buffer[2] = ALCATEL_SYNC_TYPE_TODO; 808 buffer[2] = ALCATEL_SYNC_TYPE_TODO;
809 break; 809 break;
810 } 810 }
811 811
812 Priv->CurrentFieldsItem = id; 812 Priv->CurrentFieldsItem = id;
813 Priv->CurrentFieldsType = Priv->BinaryType; 813 Priv->CurrentFieldsType = Priv->BinaryType;
814 814
815 error=GSM_WaitFor (s, buffer, 9, 0x02, ALCATEL_TIMEOUT, ID_AlcatelGetFields1); 815 error=GSM_WaitFor (s, buffer, 9, 0x02, ALCATEL_TIMEOUT, ID_AlcatelGetFields1);
816 if (error != ERR_NONE) return error; 816 if (error != ERR_NONE) return error;
817 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelGetFields2); 817 error=GSM_WaitFor (s, 0, 0, 0x00, ALCATEL_TIMEOUT, ID_AlcatelGetFields2);
818 if (error != ERR_NONE) return error; 818 if (error != ERR_NONE) return error;
819 819
820 i = 0; 820 i = 0;
821 smprintf(s,"Received %d fields: ", Priv->CurrentFieldsCount); 821 smprintf(s,"Received %d fields: ", Priv->CurrentFieldsCount);
822 for (i=0; i < Priv->CurrentFieldsCount; i++) { 822 for (i=0; i < Priv->CurrentFieldsCount; i++) {
823 smprintf(s,"%x ", Priv->CurrentFields[i]); 823 smprintf(s,"%x ", Priv->CurrentFields[i]);
824 } 824 }
825 smprintf(s,"\n"); 825 smprintf(s,"\n");
826 826
827 return ERR_NONE; 827 return ERR_NONE;
diff --git a/gammu/emb/gammu/depend/nokia/dct3.c b/gammu/emb/gammu/depend/nokia/dct3.c
index b9e47ea..bda7532 100644
--- a/gammu/emb/gammu/depend/nokia/dct3.c
+++ b/gammu/emb/gammu/depend/nokia/dct3.c
@@ -1,786 +1,786 @@
1/* (c) 2002-2004 by Marcin Wiacek */ 1/* (c) 2002-2004 by Marcin Wiacek */
2/* MSID by Walek */ 2/* MSID by Walek */
3 3
4#include "../../../common/gsmstate.h" 4#include "../../../common/gsmstate.h"
5 5
6#ifdef GSM_ENABLE_NOKIA_DCT3 6#ifdef GSM_ENABLE_NOKIA_DCT3
7 7
8#include <string.h> 8#include <string.h>
9#include <signal.h> 9#include <signal.h>
10 10
11#include "../../../common/misc/coding/coding.h" 11#include "../../../common/misc/coding/coding.h"
12#include "../../../common/gsmcomon.h" 12#include "../../../common/gsmcomon.h"
13#include "../../../common/service/gsmpbk.h" 13#include "../../../common/service/gsmpbk.h"
14#include "../../../common/phone/nokia/dct3/dct3func.h" 14#include "../../../common/phone/nokia/dct3/dct3func.h"
15#include "../../../common/phone/pfunc.h" 15#include "../../../common/phone/pfunc.h"
16#include "../../gammu.h" 16#include "../../gammu.h"
17 17
18extern GSM_Reply_Function UserReplyFunctions3[]; 18static GSM_Reply_Function UserReplyFunctions3[];
19 19
20/* ------- some usefull functions ----------------------------------------- */ 20/* ------- some usefull functions ----------------------------------------- */
21 21
22GSM_Error CheckDCT3Only() 22GSM_Error CheckDCT3Only()
23{ 23{
24 bool found = false; 24 bool found = false;
25 25
26 /* Checking if phone is DCT3 */ 26 /* Checking if phone is DCT3 */
27#ifdef GSM_ENABLE_NOKIA6110 27#ifdef GSM_ENABLE_NOKIA6110
28 if (strstr(N6110Phone.models, s.Phone.Data.ModelInfo->model) != NULL) found = true; 28 if (strstr(N6110Phone.models, s.Phone.Data.ModelInfo->model) != NULL) found = true;
29#endif 29#endif
30#ifdef GSM_ENABLE_NOKIA7110 30#ifdef GSM_ENABLE_NOKIA7110
31 if (strstr(N7110Phone.models, s.Phone.Data.ModelInfo->model) != NULL) found = true; 31 if (strstr(N7110Phone.models, s.Phone.Data.ModelInfo->model) != NULL) found = true;
32#endif 32#endif
33#ifdef GSM_ENABLE_NOKIA9210 33#ifdef GSM_ENABLE_NOKIA9210
34 if (strstr(N9210Phone.models, s.Phone.Data.ModelInfo->model) != NULL) found = true; 34 if (strstr(N9210Phone.models, s.Phone.Data.ModelInfo->model) != NULL) found = true;
35#endif 35#endif
36 if (!found) return ERR_NOTSUPPORTED; 36 if (!found) return ERR_NOTSUPPORTED;
37 37
38 if (s.ConnectionType!=GCT_MBUS2 && s.ConnectionType!=GCT_FBUS2 && 38 if (s.ConnectionType!=GCT_MBUS2 && s.ConnectionType!=GCT_FBUS2 &&
39 s.ConnectionType!=GCT_FBUS2DLR3 && s.ConnectionType!=GCT_FBUS2BLUE && 39 s.ConnectionType!=GCT_FBUS2DLR3 && s.ConnectionType!=GCT_FBUS2BLUE &&
40 s.ConnectionType!=GCT_FBUS2IRDA && s.ConnectionType!=GCT_IRDAPHONET && 40 s.ConnectionType!=GCT_FBUS2IRDA && s.ConnectionType!=GCT_IRDAPHONET &&
41 s.ConnectionType!=GCT_BLUEFBUS2) { 41 s.ConnectionType!=GCT_BLUEFBUS2) {
42 return ERR_OTHERCONNECTIONREQUIRED; 42 return ERR_OTHERCONNECTIONREQUIRED;
43 } 43 }
44 return ERR_NONE; 44 return ERR_NONE;
45} 45}
46 46
47static void CheckDCT3() 47static void CheckDCT3()
48{ 48{
49 GSM_Error error; 49 GSM_Error error;
50 50
51 error = CheckDCT3Only(); 51 error = CheckDCT3Only();
52 switch (error) { 52 switch (error) {
53 case ERR_NOTSUPPORTED: 53 case ERR_NOTSUPPORTED:
54 Print_Error(ERR_NOTSUPPORTED); 54 Print_Error(ERR_NOTSUPPORTED);
55 break; 55 break;
56 case ERR_OTHERCONNECTIONREQUIRED: 56 case ERR_OTHERCONNECTIONREQUIRED:
57 printf("Can't do it with current phone protocol\n"); 57 printf("Can't do it with current phone protocol\n");
58 GSM_TerminateConnection(&s); 58 GSM_TerminateConnection(&s);
59 exit(-1); 59 exit(-1);
60 default: 60 default:
61 break; 61 break;
62 } 62 }
63} 63}
64 64
65static bool answer_yes3(char *text) 65static bool answer_yes3(char *text)
66{ 66{
67 int len; 67 int len;
68 char ans[99]; 68 char ans[99];
69 69
70 while (1) { 70 while (1) {
71 printf("%s (yes/no) ? ",text); 71 printf("%s (yes/no) ? ",text);
72 len=GetLine(stdin, ans, 99); 72 len=GetLine(stdin, ans, 99);
73 if (len==-1) exit(-1); 73 if (len==-1) exit(-1);
74 if (mystrncasecmp(ans, "yes",0)) return true; 74 if (mystrncasecmp(ans, "yes",0)) return true;
75 if (mystrncasecmp(ans, "no" ,0)) return false; 75 if (mystrncasecmp(ans, "no" ,0)) return false;
76 } 76 }
77} 77}
78 78
79/* ------------------- functions ------------------------------------------- */ 79/* ------------------- functions ------------------------------------------- */
80 80
81static FILE *DCT3T9File; 81static FILE *DCT3T9File;
82 82
83static GSM_Error DCT3_ReplyGetT9(GSM_Protocol_Message msg, GSM_StateMachine *s) 83static GSM_Error DCT3_ReplyGetT9(GSM_Protocol_Message msg, GSM_StateMachine *s)
84{ 84{
85 int DCT3T9Size; 85 int DCT3T9Size;
86 86
87 DCT3T9Size = msg.Length - 6; 87 DCT3T9Size = msg.Length - 6;
88 fwrite(msg.Buffer+6,1,DCT3T9Size,DCT3T9File); 88 fwrite(msg.Buffer+6,1,DCT3T9Size,DCT3T9File);
89 return ERR_NONE; 89 return ERR_NONE;
90} 90}
91 91
92void DCT3GetT9(int argc, char *argv[]) 92void DCT3GetT9(int argc, char *argv[])
93{ 93{
94 int i; 94 int i;
95 unsigned char req[] = {0x00, 0x01, 0xAE, 0x02, 0x00, 95 unsigned char req[] = {0x00, 0x01, 0xAE, 0x02, 0x00,
96 0x00};/* Part number */ 96 0x00};/* Part number */
97 97
98//"00 01 AE 00" gets some control values 98//"00 01 AE 00" gets some control values
99 99
100 if (CheckDCT3Only()!=ERR_NONE) return; 100 if (CheckDCT3Only()!=ERR_NONE) return;
101 101
102 DCT3T9File = fopen("T9", "w"); 102 DCT3T9File = fopen("T9", "w");
103 if (DCT3T9File == NULL) return; 103 if (DCT3T9File == NULL) return;
104 104
105 s.User.UserReplyFunctions=UserReplyFunctions3; 105 s.User.UserReplyFunctions=UserReplyFunctions3;
106 106
107 for (i=0;i<5;i++) { 107 for (i=0;i<5;i++) {
108 req[5] = i; 108 req[5] = i;
109 error=GSM_WaitFor (&s, req, 6, 0x40, 4, ID_User3); 109 error=GSM_WaitFor (&s, req, 6, 0x40, 4, ID_User3);
110 Print_Error(error); 110 Print_Error(error);
111 } 111 }
112 112
113 fclose(DCT3T9File); 113 fclose(DCT3T9File);
114} 114}
115 115
116void DCT3VibraTest(int argc, char *argv[]) 116void DCT3VibraTest(int argc, char *argv[])
117{ 117{
118 unsigned char ans[200]; 118 unsigned char ans[200];
119 unsigned char SetLevel[4] = {0x00, 0x01, 0xA3, 119 unsigned char SetLevel[4] = {0x00, 0x01, 0xA3,
120 0xff};/* Level */ 120 0xff};/* Level */
121 121
122 if (CheckDCT3Only()!=ERR_NONE) return; 122 if (CheckDCT3Only()!=ERR_NONE) return;
123 123
124 s.User.UserReplyFunctions=UserReplyFunctions3; 124 s.User.UserReplyFunctions=UserReplyFunctions3;
125 125
126 error=DCT3_EnableSecurity (&s, 0x01); 126 error=DCT3_EnableSecurity (&s, 0x01);
127 Print_Error(error); 127 Print_Error(error);
128 128
129 error=GSM_WaitFor (&s, SetLevel, 4, 0x40, 4, ID_User3); 129 error=GSM_WaitFor (&s, SetLevel, 4, 0x40, 4, ID_User3);
130 Print_Error(error); 130 Print_Error(error);
131 131
132 printf("Press any key to continue...\n"); 132 printf("Press any key to continue...\n");
133 GetLine(stdin, ans, 99); 133 GetLine(stdin, ans, 99);
134 134
135 SetLevel[3] = 0x00; 135 SetLevel[3] = 0x00;
136 error=GSM_WaitFor (&s, SetLevel, 4, 0x40, 4, ID_User3); 136 error=GSM_WaitFor (&s, SetLevel, 4, 0x40, 4, ID_User3);
137} 137}
138 138
139static GSM_Error DCT3_ReplyPhoneTests(GSM_Protocol_Message msg, GSM_StateMachine *s) 139static GSM_Error DCT3_ReplyPhoneTests(GSM_Protocol_Message msg, GSM_StateMachine *s)
140{ 140{
141 int i; 141 int i;
142 142
143 for (i=0;i<msg.Buffer[3];i++) { 143 for (i=0;i<msg.Buffer[3];i++) {
144 switch (i) { 144 switch (i) {
145 case 0: printf("Unknown(%02i) ",i);break; 145 case 0: printf("Unknown(%02i) ",i);break;
146 case 1: printf("MCU ROM checksum (startup)");break; 146 case 1: printf("MCU ROM checksum (startup)");break;
147 case 2: printf("MCU RAM interface (startup)");break; 147 case 2: printf("MCU RAM interface (startup)");break;
148 case 3: printf("MCU RAM component ");break; 148 case 3: printf("MCU RAM component ");break;
149 case 4: printf("MCU EEPROM interface (startup)");break; 149 case 4: printf("MCU EEPROM interface (startup)");break;
150 case 5: printf("MCU EEPROM component ");break; 150 case 5: printf("MCU EEPROM component ");break;
151 case 6: printf("Real Time Clock battery (startup)");break; 151 case 6: printf("Real Time Clock battery (startup)");break;
152 case 7: printf("CCONT interface (startup)");break; 152 case 7: printf("CCONT interface (startup)");break;
153 case 8: printf("AD converter (startup)");break; 153 case 8: printf("AD converter (startup)");break;
154 case 9: printf("SW Reset ");break; 154 case 9: printf("SW Reset ");break;
155 case 10:printf("Power Off ");break; 155 case 10:printf("Power Off ");break;
156 case 11:printf("Security Data ");break; 156 case 11:printf("Security Data ");break;
157 case 12:printf("EEPROM Tune checksum (startup)");break; 157 case 12:printf("EEPROM Tune checksum (startup)");break;
158 case 13:printf("PPM checksum (startup)");break; 158 case 13:printf("PPM checksum (startup)");break;
159 case 14:printf("MCU download DSP (startup)");break; 159 case 14:printf("MCU download DSP (startup)");break;
160 case 15:printf("DSP alive (startup)");break; 160 case 15:printf("DSP alive (startup)");break;
161 case 16:printf("COBBA serial (startup)");break; 161 case 16:printf("COBBA serial (startup)");break;
162 case 17:printf("COBBA paraller (startup)");break; 162 case 17:printf("COBBA paraller (startup)");break;
163 case 18:printf("EEPROM security checksum (startup)");break; 163 case 18:printf("EEPROM security checksum (startup)");break;
164 case 19:printf("PPM validity (startup)");break; 164 case 19:printf("PPM validity (startup)");break;
165 case 20:printf("Warranty state (startup)");break; 165 case 20:printf("Warranty state (startup)");break;
166 case 21:printf("Simlock check/SW version (startup)");break; 166 case 21:printf("Simlock check/SW version (startup)");break;
167 case 22:printf("IMEI check? ");break;/*from PC-Locals1.3.is OK?*/ 167 case 22:printf("IMEI check? ");break;/*from PC-Locals1.3.is OK?*/
168 default:printf("Unknown(%02i) ",i);break; 168 default:printf("Unknown(%02i) ",i);break;
169 } 169 }
170 switch (msg.Buffer[4+i]) { 170 switch (msg.Buffer[4+i]) {
171 case 0: printf(" : passed"); break; 171 case 0: printf(" : passed"); break;
172 case 0xff:printf(" : not executed"); break; 172 case 0xff:printf(" : not executed"); break;
173 case 254: printf(" : fail"); break; 173 case 254: printf(" : fail"); break;
174 default: printf(" : result unknown(%i)",msg.Buffer[4+i]);break; 174 default: printf(" : result unknown(%i)",msg.Buffer[4+i]);break;
175 } 175 }
176 printf("\n"); 176 printf("\n");
177 } 177 }
178 178
179 return ERR_NONE; 179 return ERR_NONE;
180} 180}
181 181
182void DCT3SelfTests(int argc, char *argv[]) 182void DCT3SelfTests(int argc, char *argv[])
183{ 183{
184 unsigned char buffer[3] = {0x00,0x01,0xcf}; 184 unsigned char buffer[3] = {0x00,0x01,0xcf};
185 unsigned char buffer3[8] = {0x00,0x01,0xce,0x1d,0xfe,0x23,0x00,0x00}; 185 unsigned char buffer3[8] = {0x00,0x01,0xce,0x1d,0xfe,0x23,0x00,0x00};
186 int i; 186 int i;
187 187
188 if (CheckDCT3Only()!=ERR_NONE) return; 188 if (CheckDCT3Only()!=ERR_NONE) return;
189 189
190 error=DCT3_EnableSecurity (&s, 0x01); 190 error=DCT3_EnableSecurity (&s, 0x01);
191 Print_Error(error); 191 Print_Error(error);
192 192
193 if (answer_yes3("Run all tests now ?")) { 193 if (answer_yes3("Run all tests now ?")) {
194 /* make almost all tests */ 194 /* make almost all tests */
195 error = s.Protocol.Functions->WriteMessage(&s, buffer3, 8, 0x40); 195 error = s.Protocol.Functions->WriteMessage(&s, buffer3, 8, 0x40);
196 Print_Error(error); 196 Print_Error(error);
197 197
198 GSM_Terminate(); 198 GSM_Terminate();
199 199
200 while (!false) { 200 while (!false) {
201 GSM_Init(false); 201 GSM_Init(false);
202 if (error==ERR_NONE) break; 202 if (error==ERR_NONE) break;
203 GSM_Terminate(); 203 GSM_Terminate();
204 } 204 }
205 205
206 my_sleep(400); 206 my_sleep(400);
207 } 207 }
208 208
209 s.User.UserReplyFunctions=UserReplyFunctions3; 209 s.User.UserReplyFunctions=UserReplyFunctions3;
210 210
211 for (i=0;i<10;i++) { 211 for (i=0;i<10;i++) {
212 error=GSM_WaitFor (&s, buffer, 3, 0x40, 4, ID_User1); 212 error=GSM_WaitFor (&s, buffer, 3, 0x40, 4, ID_User1);
213 if (error == ERR_NONE) break; 213 if (error == ERR_NONE) break;
214 } 214 }
215} 215}
216 216
217struct DCT3ADCInfo { 217struct DCT3ADCInfo {
218 char *name; 218 char *name;
219 char *unit; 219 char *unit;
220 int x; 220 int x;
221 intpos1; 221 intpos1;
222 intpos2; 222 intpos2;
223}; 223};
224 224
225static struct DCT3ADCInfo DCT3ADC[] = { 225static struct DCT3ADCInfo DCT3ADC[] = {
226 {"Battery voltage:", "mV", 1, 3, 2}, 226 {"Battery voltage:", "mV", 1, 3, 2},
227 // {"Charger voltage:", "mV", 1, -1, 7}, 227 // {"Charger voltage:", "mV", 1, -1, 7},
228 // {"Charger current:", "mA", 1, -1, 5}, 228 // {"Charger current:", "mA", 1, -1, 5},
229 {"Battery type:", "mAh", 1, 4, 3}, 229 {"Battery type:", "mAh", 1, 4, 3},
230 {"Battery temperature:", "mK", 10, 5, 4}, 230 {"Battery temperature:", "mK", 10, 5, 4},
231 // {"Accessory detection:", "mV", 1, -1, -1}, 231 // {"Accessory detection:", "mV", 1, -1, -1},
232 {"RSSI:", "", 1, 2, -1}, 232 {"RSSI:", "", 1, 2, -1},
233 // {"VCXO temperature:", "mV", 1, -1, -1}, 233 // {"VCXO temperature:", "mV", 1, -1, -1},
234 // {"Hook information:", "mV", 1, -1, -1}, 234 // {"Hook information:", "mV", 1, -1, -1},
235 235
236 {"", "", 1, -1, -1} 236 {"", "", 1, -1, -1}
237}; 237};
238 238
239 unsigned char DCT3ADCBuf[200]; 239 unsigned char DCT3ADCBuf[200];
240 int DCT3ADCInt; 240 int DCT3ADCInt;
241 241
242static GSM_Error DCT3_ReplyGetADC(GSM_Protocol_Message msg, GSM_StateMachine *s) 242static GSM_Error DCT3_ReplyGetADC(GSM_Protocol_Message msg, GSM_StateMachine *s)
243{ 243{
244 switch (msg.Buffer[2]) { 244 switch (msg.Buffer[2]) {
245 case 0x68: 245 case 0x68:
246 memcpy(DCT3ADCBuf,msg.Buffer+4,msg.Length-4); 246 memcpy(DCT3ADCBuf,msg.Buffer+4,msg.Length-4);
247 return ERR_NONE; 247 return ERR_NONE;
248 case 0x91: 248 case 0x91:
249 DCT3ADCInt = msg.Buffer[4]*256+msg.Buffer[5]; 249 DCT3ADCInt = msg.Buffer[4]*256+msg.Buffer[5];
250 return ERR_NONE; 250 return ERR_NONE;
251 } 251 }
252 return ERR_UNKNOWNRESPONSE; 252 return ERR_UNKNOWNRESPONSE;
253} 253}
254 254
255void DCT3GetADC(int argc, char *argv[]) 255void DCT3GetADC(int argc, char *argv[])
256{ 256{
257 int i = 0; 257 int i = 0;
258 unsigned charGetRaw[] = {0x00, 0x01, 0x68}; 258 unsigned charGetRaw[] = {0x00, 0x01, 0x68};
259 unsigned charGetUnit[] = {0x00, 0x01, 0x91, 259 unsigned charGetUnit[] = {0x00, 0x01, 0x91,
260 0x02}; /* Test number */ 260 0x02}; /* Test number */
261 261
262 if (CheckDCT3Only()!=ERR_NONE) return; 262 if (CheckDCT3Only()!=ERR_NONE) return;
263 263
264 s.User.UserReplyFunctions=UserReplyFunctions3; 264 s.User.UserReplyFunctions=UserReplyFunctions3;
265 265
266 error=DCT3_EnableSecurity (&s, 0x02); 266 error=DCT3_EnableSecurity (&s, 0x02);
267 Print_Error(error); 267 Print_Error(error);
268 268
269 error=GSM_WaitFor (&s, GetRaw, 3, 0x40, 6, ID_User3); 269 error=GSM_WaitFor (&s, GetRaw, 3, 0x40, 6, ID_User3);
270 Print_Error(error); 270 Print_Error(error);
271 271
272 while (1) { 272 while (1) {
273 printf(" %30s ",DCT3ADC[i].name); 273 printf(" %30s ",DCT3ADC[i].name);
274 if (DCT3ADC[i].pos1 != -1) { 274 if (DCT3ADC[i].pos1 != -1) {
275 printf("raw "); 275 printf("raw ");
276 printf("%10i ", 276 printf("%10i ",
277 DCT3ADCBuf[(DCT3ADC[i].pos1-1)*2]*256+ 277 DCT3ADCBuf[(DCT3ADC[i].pos1-1)*2]*256+
278 DCT3ADCBuf[(DCT3ADC[i].pos1-1)*2+1]); 278 DCT3ADCBuf[(DCT3ADC[i].pos1-1)*2+1]);
279 } 279 }
280 if (DCT3ADC[i].pos2 != -1) { 280 if (DCT3ADC[i].pos2 != -1) {
281 printf("unit result "); 281 printf("unit result ");
282 GetUnit[3] = DCT3ADC[i].pos2; 282 GetUnit[3] = DCT3ADC[i].pos2;
283 error=GSM_WaitFor (&s, GetUnit, 6, 0x40, 4, ID_User3); 283 error=GSM_WaitFor (&s, GetUnit, 6, 0x40, 4, ID_User3);
284 Print_Error(error); 284 Print_Error(error);
285 printf("%10i ",DCT3ADCInt*DCT3ADC[i].x); 285 printf("%10i ",DCT3ADCInt*DCT3ADC[i].x);
286 printf("%s\n",DCT3ADC[i].unit); 286 printf("%s\n",DCT3ADC[i].unit);
287 } 287 }
288 i++; 288 i++;
289 if (DCT3ADC[i].name[0] == 0x00) break; 289 if (DCT3ADC[i].name[0] == 0x00) break;
290 } 290 }
291 291
292 error=DCT3_EnableSecurity (&s, 0x01); 292 error=DCT3_EnableSecurity (&s, 0x01);
293 Print_Error(error); 293 Print_Error(error);
294} 294}
295 295
296void DCT3DisplayTest(int argc, char *argv[]) 296void DCT3DisplayTest(int argc, char *argv[])
297{ 297{
298 unsigned char ans[200]; 298 unsigned char ans[200];
299 unsigned char req[] = {0x00, 0x01, 0xD3, 299 unsigned char req[] = {0x00, 0x01, 0xD3,
300 0x03, /* 3=set, 2=clear */ 300 0x03, /* 3=set, 2=clear */
301 0x03}; /* test number */ 301 0x03}; /* test number */
302 302
303 if (CheckDCT3Only()!=ERR_NONE) return; 303 if (CheckDCT3Only()!=ERR_NONE) return;
304 304
305 if (atoi(argv[2]) != 1 && atoi(argv[2]) != 2) { 305 if (atoi(argv[2]) != 1 && atoi(argv[2]) != 2) {
306 printf("Give 1 or 2 as test number\n"); 306 printf("Give 1 or 2 as test number\n");
307 } 307 }
308 308
309 s.User.UserReplyFunctions=UserReplyFunctions3; 309 s.User.UserReplyFunctions=UserReplyFunctions3;
310 310
311 req[4] = atoi(argv[2]); 311 req[4] = atoi(argv[2]);
312 s.Protocol.Functions->WriteMessage(&s, req, 5, 0x40); 312 s.Protocol.Functions->WriteMessage(&s, req, 5, 0x40);
313 313
314 printf("Press any key to continue...\n"); 314 printf("Press any key to continue...\n");
315 GetLine(stdin, ans, 99); 315 GetLine(stdin, ans, 99);
316 316
317 req[3] = 0x02; 317 req[3] = 0x02;
318 req[4] = 0x03; 318 req[4] = 0x03;
319 s.Protocol.Functions->WriteMessage(&s, req, 5, 0x40); 319 s.Protocol.Functions->WriteMessage(&s, req, 5, 0x40);
320 320
321 error=DCT3_EnableSecurity (&s, 0x03); 321 error=DCT3_EnableSecurity (&s, 0x03);
322 Print_Error(error); 322 Print_Error(error);
323} 323}
324 324
325void DCT3netmonitor(int argc, char *argv[]) 325void DCT3netmonitor(int argc, char *argv[])
326{ 326{
327 char value[100]; 327 char value[100];
328 328
329 GSM_Init(true); 329 GSM_Init(true);
330 330
331 CheckDCT3(); 331 CheckDCT3();
332 332
333 error=DCT3_Netmonitor(&s, atoi(argv[2]), value); 333 error=DCT3_Netmonitor(&s, atoi(argv[2]), value);
334 Print_Error(error); 334 Print_Error(error);
335 335
336 printf("%s\n",value); 336 printf("%s\n",value);
337#ifdef GSM_ENABLE_BEEP 337#ifdef GSM_ENABLE_BEEP
338 if (atoi(argv[2]) == 243) GSM_PhoneBeep(); 338 if (atoi(argv[2]) == 243) GSM_PhoneBeep();
339#endif 339#endif
340 GSM_Terminate(); 340 GSM_Terminate();
341} 341}
342 342
343static GSM_Error DCT3_ReplyGetMSID(GSM_Protocol_Message msg, GSM_StateMachine *s) 343static GSM_Error DCT3_ReplyGetMSID(GSM_Protocol_Message msg, GSM_StateMachine *s)
344{ 344{
345 int i; 345 int i;
346 346
347 printf("MSID : "); 347 printf("MSID : ");
348 for (i=5;i<18;i++) printf("%02x",msg.Buffer[i]); 348 for (i=5;i<18;i++) printf("%02x",msg.Buffer[i]);
349 printf("\n"); 349 printf("\n");
350 return ERR_NONE; 350 return ERR_NONE;
351} 351}
352 352
353static GSM_Error DCT3_ReplyGetDSPROM(GSM_Protocol_Message msg, GSM_StateMachine *s) 353static GSM_Error DCT3_ReplyGetDSPROM(GSM_Protocol_Message msg, GSM_StateMachine *s)
354{ 354{
355 printf("DSP ROM : %c\n",msg.Buffer[5]); 355 printf("DSP ROM : %c\n",msg.Buffer[5]);
356 return ERR_NONE; 356 return ERR_NONE;
357} 357}
358 358
359static GSM_Error DCT3_ReplySimlockInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 359static GSM_Error DCT3_ReplySimlockInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
360{ 360{
361 inti, j; 361 inti, j;
362 charuni[100], buffer[50]; 362 charuni[100], buffer[50];
363 363
364 j=0; 364 j=0;
365 for (i=0; i < 12; i++) { 365 for (i=0; i < 12; i++) {
366 if (j<24) { 366 if (j<24) {
367 uni[j]='0' + (msg.Buffer[9+i] >> 4); 367 uni[j]='0' + (msg.Buffer[9+i] >> 4);
368 j++; 368 j++;
369 } 369 }
370 if (j!=15) { 370 if (j!=15) {
371 if (j<24) { 371 if (j<24) {
372 uni[j]='0' + (msg.Buffer[9+i] & 0x0f); 372 uni[j]='0' + (msg.Buffer[9+i] & 0x0f);
373 j++; 373 j++;
374 } 374 }
375 } else j++; 375 } else j++;
376 } 376 }
377 377
378 strncpy(buffer,uni,5); 378 strncpy(buffer,uni,5);
379 buffer[5]=0; 379 buffer[5]=0;
380 printf("Simlock 1 : MCC+MNC %10s, %s, %s, counter %i\n", 380 printf("Simlock 1 : MCC+MNC %10s, %s, %s, counter %i\n",
381 buffer, 381 buffer,
382 ((msg.Buffer[6] & 1) == 1)==0?"opened":"CLOSED", 382 ((msg.Buffer[6] & 1) == 1)==0?"opened":"CLOSED",
383 ((msg.Buffer[5] & 1) != 1)==0?"user ":"factory", 383 ((msg.Buffer[5] & 1) != 1)==0?"user ":"factory",
384 msg.Buffer[21]); 384 msg.Buffer[21]);
385 385
386 strncpy(buffer,uni+16,4); 386 strncpy(buffer,uni+16,4);
387 buffer[4]=0; 387 buffer[4]=0;
388 printf("Simlock 2 : GID1 %10s, %s, %s, counter %i\n", 388 printf("Simlock 2 : GID1 %10s, %s, %s, counter %i\n",
389 buffer, 389 buffer,
390 ((msg.Buffer[6] & 4) == 4)==0?"opened":"CLOSED", 390 ((msg.Buffer[6] & 4) == 4)==0?"opened":"CLOSED",
391 ((msg.Buffer[5] & 4) != 4)==0?"user ":"factory", 391 ((msg.Buffer[5] & 4) != 4)==0?"user ":"factory",
392 msg.Buffer[23]); 392 msg.Buffer[23]);
393 393
394 strncpy(buffer,uni+20,4); 394 strncpy(buffer,uni+20,4);
395 buffer[4]=0; 395 buffer[4]=0;
396 printf("Simlock 3 : GID2 %10s, %s, %s, counter %i\n", 396 printf("Simlock 3 : GID2 %10s, %s, %s, counter %i\n",
397 buffer, 397 buffer,
398 ((msg.Buffer[6] & 8) == 8)==0?"opened":"CLOSED", 398 ((msg.Buffer[6] & 8) == 8)==0?"opened":"CLOSED",
399 ((msg.Buffer[5] & 8) != 8)==0?"user ":"factory", 399 ((msg.Buffer[5] & 8) != 8)==0?"user ":"factory",
400 msg.Buffer[24]); 400 msg.Buffer[24]);
401 401
402 strncpy(buffer,uni+5,10); 402 strncpy(buffer,uni+5,10);
403 buffer[10]=0; 403 buffer[10]=0;
404 printf("Simlock 4 : MSIN %10s, %s, %s, counter %i\n", 404 printf("Simlock 4 : MSIN %10s, %s, %s, counter %i\n",
405 buffer, 405 buffer,
406 ((msg.Buffer[6] & 2) == 2)==0?"opened":"CLOSED", 406 ((msg.Buffer[6] & 2) == 2)==0?"opened":"CLOSED",
407 ((msg.Buffer[5] & 2) != 2)==0?"user ":"factory", 407 ((msg.Buffer[5] & 2) != 2)==0?"user ":"factory",
408 msg.Buffer[22]); 408 msg.Buffer[22]);
409 409
410 return ERR_NONE; 410 return ERR_NONE;
411} 411}
412 412
413static GSM_Error DCT3_ReplyGetMCUchkSum(GSM_Protocol_Message msg, GSM_StateMachine *s) 413static GSM_Error DCT3_ReplyGetMCUchkSum(GSM_Protocol_Message msg, GSM_StateMachine *s)
414{ 414{
415 int i; 415 int i;
416 416
417 if (msg.Buffer[3] == 0x12) printf("Language Pack: %c\n",msg.Buffer[5]); 417 if (msg.Buffer[3] == 0x12) printf("Language Pack: %c\n",msg.Buffer[5]);
418 if (msg.Buffer[3] == 0x02) { 418 if (msg.Buffer[3] == 0x02) {
419 printf("MCU checksum : "); 419 printf("MCU checksum : ");
420 for (i=5;i<9;i++) printf("%c",msg.Buffer[i]); 420 for (i=5;i<9;i++) printf("%c",msg.Buffer[i]);
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#ifdef GSM_ENABLE_NOKIA6110
614 unsigned char req6110[] = {0x00, 0x01, 0x6e, 614 unsigned char req6110[] = {0x00, 0x01, 0x6e,
615 0x01};/* Code type */ 615 0x01};/* Code type */
616#endif 616#endif
617#if defined(GSM_ENABLE_NOKIA7110) || defined(GSM_ENABLE_NOKIA9210) 617#if defined(GSM_ENABLE_NOKIA7110) || defined(GSM_ENABLE_NOKIA9210)
618 unsigned char req71_91[] = {N7110_FRAME_HEADER, 0xee, 618 unsigned char req71_91[] = {N7110_FRAME_HEADER, 0xee,
619 0x1c};/* Setting */ 619 0x1c};/* Setting */
620#endif 620#endif
621 621
622 if (CheckDCT3Only()!=ERR_NONE) return; 622 if (CheckDCT3Only()!=ERR_NONE) return;
623 623
624 error=DCT3_EnableSecurity (&s, 0x01); 624 error=DCT3_EnableSecurity (&s, 0x01);
625 Print_Error(error); 625 Print_Error(error);
626 626
627 s.User.UserReplyFunctions=UserReplyFunctions3; 627 s.User.UserReplyFunctions=UserReplyFunctions3;
628 628
629#ifdef GSM_ENABLE_NOKIA6110 629#ifdef GSM_ENABLE_NOKIA6110
630 if (strstr(N6110Phone.models, s.Phone.Data.ModelInfo->model) != NULL) { 630 if (strstr(N6110Phone.models, s.Phone.Data.ModelInfo->model) != NULL) {
631 error=GSM_WaitFor (&s, req6110, 4, 0x40, 4, ID_User6); 631 error=GSM_WaitFor (&s, req6110, 4, 0x40, 4, ID_User6);
632 } 632 }
633#endif 633#endif
634#ifdef GSM_ENABLE_NOKIA7110 634#ifdef GSM_ENABLE_NOKIA7110
635 if (strstr(N7110Phone.models, s.Phone.Data.ModelInfo->model) != NULL) { 635 if (strstr(N7110Phone.models, s.Phone.Data.ModelInfo->model) != NULL) {
636 error=GSM_WaitFor (&s, req71_91, 5, 0x7a, 4, ID_User6); 636 error=GSM_WaitFor (&s, req71_91, 5, 0x7a, 4, ID_User6);
637 } 637 }
638#endif 638#endif
639#ifdef GSM_ENABLE_NOKIA9210 639#ifdef GSM_ENABLE_NOKIA9210
640 if (strstr(N9210Phone.models, s.Phone.Data.ModelInfo->model) != NULL) { 640 if (strstr(N9210Phone.models, s.Phone.Data.ModelInfo->model) != NULL) {
641 error=GSM_WaitFor (&s, req71_91, 5, 0x7a, 4, ID_User6); 641 error=GSM_WaitFor (&s, req71_91, 5, 0x7a, 4, ID_User6);
642 } 642 }
643#endif 643#endif
644 Print_Error(error); 644 Print_Error(error);
645} 645}
646 646
647#ifdef GSM_ENABLE_NOKIA6110 647#ifdef GSM_ENABLE_NOKIA6110
648 648
649static GSM_Error DCT3_ReplyGetOperatorName(GSM_Protocol_Message msg, GSM_StateMachine *s) 649static GSM_Error DCT3_ReplyGetOperatorName(GSM_Protocol_Message msg, GSM_StateMachine *s)
650{ 650{
651 unsigned char buffer[10]; 651 unsigned char buffer[10];
652 652
653 NOKIA_DecodeNetworkCode(msg.Buffer+5, buffer); 653 NOKIA_DecodeNetworkCode(msg.Buffer+5, buffer);
654 buffer[6] = 0; 654 buffer[6] = 0;
655 printf("Network : %s (%s ",buffer,DecodeUnicodeString(GSM_GetNetworkName(buffer))); 655 printf("Network : %s (%s ",buffer,DecodeUnicodeString(GSM_GetNetworkName(buffer)));
656 printf(", %s)\n", DecodeUnicodeString(GSM_GetCountryName(buffer))); 656 printf(", %s)\n", DecodeUnicodeString(GSM_GetCountryName(buffer)));
657 printf("Name : \"%s\"\n",msg.Buffer+8); 657 printf("Name : \"%s\"\n",msg.Buffer+8);
658 658
659 return ERR_NONE; 659 return ERR_NONE;
660} 660}
661 661
662void DCT3GetOperatorName(int argc, char *argv[]) 662void DCT3GetOperatorName(int argc, char *argv[])
663{ 663{
664 unsigned char req[] = {0x00,0x01,0x8c,0x00}; 664 unsigned char req[] = {0x00,0x01,0x8c,0x00};
665 665
666 GSM_Init(true); 666 GSM_Init(true);
667 667
668 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);
669 CheckDCT3(); 669 CheckDCT3();
670 670
671 error=DCT3_EnableSecurity (&s, 0x01); 671 error=DCT3_EnableSecurity (&s, 0x01);
672 Print_Error(error); 672 Print_Error(error);
673 673
674 s.User.UserReplyFunctions=UserReplyFunctions3; 674 s.User.UserReplyFunctions=UserReplyFunctions3;
675 675
676 error=GSM_WaitFor (&s, req, 4, 0x40, 4, ID_User5); 676 error=GSM_WaitFor (&s, req, 4, 0x40, 4, ID_User5);
677 Print_Error(error); 677 Print_Error(error);
678 678
679 GSM_Terminate(); 679 GSM_Terminate();
680} 680}
681 681
682static GSM_Error DCT3_ReplySetOperatorName(GSM_Protocol_Message msg, GSM_StateMachine *s) 682static GSM_Error DCT3_ReplySetOperatorName(GSM_Protocol_Message msg, GSM_StateMachine *s)
683{ 683{
684 printf("Operator name set OK\n"); 684 printf("Operator name set OK\n");
685 return ERR_NONE; 685 return ERR_NONE;
686} 686}
687 687
688void DCT3SetOperatorName(int argc, char *argv[]) 688void DCT3SetOperatorName(int argc, char *argv[])
689{ 689{
690 int i = 0; 690 int i = 0;
691 unsigned char req[256] = {0x00,0x01,0x8b,0x00, 691 unsigned char req[256] = {0x00,0x01,0x8b,0x00,
692 0x00,0x00, /* MCC */ 692 0x00,0x00, /* MCC */
693 0x00}; /* MNC */ 693 0x00}; /* MNC */
694 694
695 GSM_Init(true); 695 GSM_Init(true);
696 696
697 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);
698 CheckDCT3(); 698 CheckDCT3();
699 699
700 error=DCT3_EnableSecurity (&s, 0x01); 700 error=DCT3_EnableSecurity (&s, 0x01);
701 Print_Error(error); 701 Print_Error(error);
702 702
703 s.User.UserReplyFunctions=UserReplyFunctions3; 703 s.User.UserReplyFunctions=UserReplyFunctions3;
704 704
705 switch (argc) { 705 switch (argc) {
706 case 2: 706 case 2:
707 case 3:NOKIA_EncodeNetworkCode(req+4,"000 00"); 707 case 3:NOKIA_EncodeNetworkCode(req+4,"000 00");
708 req[7] = 0x00; 708 req[7] = 0x00;
709 i = 1; 709 i = 1;
710 break; 710 break;
711 case 4: NOKIA_EncodeNetworkCode(req+4,argv[2]); 711 case 4: NOKIA_EncodeNetworkCode(req+4,argv[2]);
712 strncpy(req+7,argv[3],200); 712 strncpy(req+7,argv[3],200);
713 i = strlen(argv[3]); 713 i = strlen(argv[3]);
714 } 714 }
715 715
716 error=GSM_WaitFor (&s, req, 8+i, 0x40, 4, ID_User7); 716 error=GSM_WaitFor (&s, req, 8+i, 0x40, 4, ID_User7);
717 Print_Error(error); 717 Print_Error(error);
718 718
719 GSM_Terminate(); 719 GSM_Terminate();
720} 720}
721 721
722static GSM_Error DCT3_ReplyDisplayOutput(GSM_Protocol_Message msg, GSM_StateMachine *s) 722static GSM_Error DCT3_ReplyDisplayOutput(GSM_Protocol_Message msg, GSM_StateMachine *s)
723{ 723{
724 unsigned char buf[100]; 724 unsigned char buf[100];
725 725
726 switch (msg.Buffer[3]) { 726 switch (msg.Buffer[3]) {
727 case 0x50: 727 case 0x50:
728 dbgprintf("Display string received\n"); 728 dbgprintf("Display string received\n");
729 memcpy(buf,msg.Buffer+8,msg.Buffer[7]*2); 729 memcpy(buf,msg.Buffer+8,msg.Buffer[7]*2);
730 buf[msg.Buffer[7]*2] = 0; 730 buf[msg.Buffer[7]*2] = 0;
731 buf[msg.Buffer[7]*2+1] = 0; 731 buf[msg.Buffer[7]*2+1] = 0;
732 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));
733 return ERR_NONE; 733 return ERR_NONE;
734 case 0x54: 734 case 0x54:
735 dbgprintf("Display output set\n"); 735 dbgprintf("Display output set\n");
736 return ERR_NONE; 736 return ERR_NONE;
737 } 737 }
738 return ERR_UNKNOWNRESPONSE; 738 return ERR_UNKNOWNRESPONSE;
739} 739}
740 740
741void DCT3DisplayOutput(int argc, char *argv[]) 741void DCT3DisplayOutput(int argc, char *argv[])
742{ 742{
743 unsigned char req[] = {N6110_FRAME_HEADER, 0x53, 743 unsigned char req[] = {N6110_FRAME_HEADER, 0x53,
744 0x01}; //1 = enable, 2 = disable 744 0x01}; //1 = enable, 2 = disable
745 745
746 GSM_Init(true); 746 GSM_Init(true);
747 747
748 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);
749 CheckDCT3(); 749 CheckDCT3();
750 750
751 s.User.UserReplyFunctions=UserReplyFunctions3; 751 s.User.UserReplyFunctions=UserReplyFunctions3;
752 752
753 error=GSM_WaitFor (&s, req, 5, 0x0d, 4, ID_User7); 753 error=GSM_WaitFor (&s, req, 5, 0x0d, 4, ID_User7);
754 Print_Error(error); 754 Print_Error(error);
755 755
756 signal(SIGINT, interrupt); 756 signal(SIGINT, interrupt);
757 printf("Press Ctrl+C to break...\n"); 757 printf("Press Ctrl+C to break...\n");
758 printf("Entering monitor mode...\n\n"); 758 printf("Entering monitor mode...\n\n");
759 759
760 while (!gshutdown) { 760 while (!gshutdown) {
761 GSM_ReadDevice(&s,true); 761 GSM_ReadDevice(&s,true);
762 my_sleep(10); 762 my_sleep(10);
763 } 763 }
764 764
765 req[4] = 0x02; 765 req[4] = 0x02;
766 error=GSM_WaitFor (&s, req, 5, 0x0d, 4, ID_User7); 766 error=GSM_WaitFor (&s, req, 5, 0x0d, 4, ID_User7);
767 Print_Error(error); 767 Print_Error(error);
768 768
769 GSM_Terminate(); 769 GSM_Terminate();
770} 770}
771#endif 771#endif
772 772
773static GSM_Reply_Function UserReplyFunctions3[] = { 773static GSM_Reply_Function UserReplyFunctions3[] = {
774#ifdef GSM_ENABLE_NOKIA6110 774#ifdef GSM_ENABLE_NOKIA6110
775 {DCT3_ReplyDisplayOutput, "\x0D",0x03,0x50,ID_IncomingFrame}, 775 {DCT3_ReplyDisplayOutput, "\x0D",0x03,0x50,ID_IncomingFrame},
776 {DCT3_ReplyDisplayOutput, "\x0D",0x03,0x54,ID_User7 }, 776 {DCT3_ReplyDisplayOutput, "\x0D",0x03,0x54,ID_User7 },
777#endif 777#endif
778 778
779 {DCT3_ReplyEnableSecurity2, "\x40",0x02,0x64,ID_EnableSecurity}, 779 {DCT3_ReplyEnableSecurity2, "\x40",0x02,0x64,ID_EnableSecurity},
780 {DCT3_ReplyResetTest36, "\x40",0x02,0x65,ID_User2 }, 780 {DCT3_ReplyResetTest36, "\x40",0x02,0x65,ID_User2 },
781 {DCT3_ReplyGetADC, "\x40",0x02,0x68,ID_User3 }, 781 {DCT3_ReplyGetADC, "\x40",0x02,0x68,ID_User3 },
782 {DCT3_ReplyGetPPS, "\x40",0x02,0x6A,ID_User4 }, 782 {DCT3_ReplyGetPPS, "\x40",0x02,0x6A,ID_User4 },
783 {DCT3_ReplySetPPS, "\x40",0x02,0x6B,ID_User4 }, 783 {DCT3_ReplySetPPS, "\x40",0x02,0x6B,ID_User4 },
784 {DCT3_Reply61GetSecurityCode, "\x40",0x02,0x6E,ID_User6 }, 784 {DCT3_Reply61GetSecurityCode, "\x40",0x02,0x6E,ID_User6 },
785 {DCT3_ReplySimlockInfo, "\x40",0x02,0x8A,ID_User3 }, 785 {DCT3_ReplySimlockInfo, "\x40",0x02,0x8A,ID_User3 },
786#ifdef GSM_ENABLE_NOKIA6110 786#ifdef GSM_ENABLE_NOKIA6110
diff --git a/gammu/emb/gammu/depend/nokia/dct3trac/wmx.c b/gammu/emb/gammu/depend/nokia/dct3trac/wmx.c
index 64eda37..e46d9dd 100644
--- a/gammu/emb/gammu/depend/nokia/dct3trac/wmx.c
+++ b/gammu/emb/gammu/depend/nokia/dct3trac/wmx.c
@@ -1,480 +1,480 @@
1/** 1/**
2 * Nokia DCT3 Firmware Debug Trace Monitor 2 * Nokia DCT3 Firmware Debug Trace Monitor
3 * wumpus 2003 -- www.blacksphere.tk 3 * wumpus 2003 -- www.blacksphere.tk
4 * SIM stuff by The Monty 4 * SIM stuff by The Monty
5 * 5 *
6 * Command line arguments: 6 * Command line arguments:
7 * gammu --nokiadebug v00-0F,20,21 7 * gammu --nokiadebug v00-0F,20,21
8 * (v=verbose) 8 * (v=verbose)
9 */ 9 */
10 10
11#include "../../../../common/gsmstate.h" 11#include "../../../../common/gsmstate.h"
12 12
13#ifdef GSM_ENABLE_NOKIA_DCT3 13#ifdef GSM_ENABLE_NOKIA_DCT3
14 14
15#include <string.h> 15#include <string.h>
16#include <signal.h> 16#include <signal.h>
17 17
18#include "../../../../common/misc/coding/coding.h" 18#include "../../../../common/misc/coding/coding.h"
19#include "../../../../common/gsmcomon.h" 19#include "../../../../common/gsmcomon.h"
20#include "../../../../common/gsmstate.h" 20#include "../../../../common/gsmstate.h"
21#include "../../../../common/service/gsmpbk.h" 21#include "../../../../common/service/gsmpbk.h"
22#include "../../../../common/phone/nokia/dct3/dct3func.h" 22#include "../../../../common/phone/nokia/dct3/dct3func.h"
23#include "../../../gammu.h" 23#include "../../../gammu.h"
24#include "../dct3.h" 24#include "../dct3.h"
25#include "wmx.h" 25#include "wmx.h"
26#include "wmx-util.h" 26#include "wmx-util.h"
27#include "wmx-gsm.h" 27#include "wmx-gsm.h"
28#include "wmx-sim.h" 28#include "wmx-sim.h"
29#include "wmx-list.h" 29#include "wmx-list.h"
30 30
31extern GSM_Reply_Function UserReplyFunctionsX[]; 31static GSM_Reply_Function UserReplyFunctionsX[];
32 32
33/* Global variables suck */ 33/* Global variables suck */
34 GSMDecoder *gsmdec; 34 GSMDecoder *gsmdec;
35 struct wmx_tracestruct *traces; 35 struct wmx_tracestruct *traces;
36 36
37static GSM_Error DCT3_ReplySwitchDebug(GSM_Protocol_Message msg, GSM_StateMachine *s) 37static GSM_Error DCT3_ReplySwitchDebug(GSM_Protocol_Message msg, GSM_StateMachine *s)
38{ 38{
39 switch(msg.Buffer[2]) { 39 switch(msg.Buffer[2]) {
40 case 0x70: 40 case 0x70:
41 printf("Debug Trace Enabled\n"); 41 printf("Debug Trace Enabled\n");
42 break; 42 break;
43 case 0x71: 43 case 0x71:
44 printf("Debug Trace Disabled\n"); 44 printf("Debug Trace Disabled\n");
45 break; 45 break;
46 } 46 }
47 return ERR_NONE; 47 return ERR_NONE;
48} 48}
49 49
50/** 50/**
51 * RPC confirmation/reply 51 * RPC confirmation/reply
52 */ 52 */
53static GSM_Error DCT3_ReplyRPC(GSM_Protocol_Message msg, GSM_StateMachine *s) 53static GSM_Error DCT3_ReplyRPC(GSM_Protocol_Message msg, GSM_StateMachine *s)
54{ 54{
55 printf("RPC Reply "); 55 printf("RPC Reply ");
56 printf("call=%02x rettype=%02x data=", msg.Buffer[2], msg.Buffer[3]); 56 printf("call=%02x rettype=%02x data=", msg.Buffer[2], msg.Buffer[3]);
57 if(msg.Buffer[3] == 3) { 57 if(msg.Buffer[3] == 3) {
58 /* string */ 58 /* string */
59 printf("%s", &msg.Buffer[4]); 59 printf("%s", &msg.Buffer[4]);
60 } else { 60 } else {
61 dumpraw("RPC Reply data", &msg.Buffer[4], msg.Length-4); 61 dumpraw("RPC Reply data", &msg.Buffer[4], msg.Length-4);
62 } 62 }
63 printf("\n"); 63 printf("\n");
64 return ERR_NONE; 64 return ERR_NONE;
65} 65}
66 66
67/* disassemble mdisnd (0x18xx) packet */ 67/* disassemble mdisnd (0x18xx) packet */
68static void mdisnd_data(unsigned char type, unsigned char *buffer, size_t length) 68static void mdisnd_data(unsigned char type, unsigned char *buffer, size_t length)
69{ 69{
70 GSMDecoder_l1l2data dat; 70 GSMDecoder_l1l2data dat;
71 size_t x; 71 size_t x;
72 int ch; 72 int ch;
73 73
74 if(type==0x1B && length>2) { 74 if(type==0x1B && length>2) {
75 /* channel packet */ 75 /* channel packet */
76 ch = buffer[1]; 76 ch = buffer[1];
77 dat.tx = GSMDECODER_SEND; 77 dat.tx = GSMDECODER_SEND;
78 dat.ch = ch; 78 dat.ch = ch;
79 printf("%02X ch=%02X ",buffer[0],ch); 79 printf("%02X ch=%02X ",buffer[0],ch);
80 if (ch == 0x80 || ch == 0xB0) { 80 if (ch == 0x80 || ch == 0xB0) {
81 printf("\n"); 81 printf("\n");
82 GSMDecoder_L2packet(gsmdec, &dat, &buffer[2], length-2); 82 GSMDecoder_L2packet(gsmdec, &dat, &buffer[2], length-2);
83 } else if (ch == 0x70) { 83 } else if (ch == 0x70) {
84 dumpraw("MDI send ch70 prefix", &buffer[2], 2); 84 dumpraw("MDI send ch70 prefix", &buffer[2], 2);
85 printf("\n"); 85 printf("\n");
86 GSMDecoder_L2packet(gsmdec, &dat, &buffer[4], length-4); 86 GSMDecoder_L2packet(gsmdec, &dat, &buffer[4], length-4);
87 } else { 87 } else {
88 dumpraw("MDI recv 1B packet", &buffer[2], length-2); 88 dumpraw("MDI recv 1B packet", &buffer[2], length-2);
89 } 89 }
90 } else { 90 } else {
91 /* hex */ 91 /* hex */
92 for(x=0; x<length; x++) { 92 for(x=0; x<length; x++) {
93 printf("%02x ",buffer[x]&0xFF); 93 printf("%02x ",buffer[x]&0xFF);
94 } 94 }
95 } 95 }
96} 96}
97 97
98/* disassemble mdircv (0x19xx) packet */ 98/* disassemble mdircv (0x19xx) packet */
99static void mdircv_data(unsigned char type, unsigned char *buffer, size_t length) 99static void mdircv_data(unsigned char type, unsigned char *buffer, size_t length)
100{ 100{
101 size_t x; 101 size_t x;
102 int ch; 102 int ch;
103 GSMDecoder_l1l2data dat; 103 GSMDecoder_l1l2data dat;
104 104
105 if (type==0x80 && length>1) { 105 if (type==0x80 && length>1) {
106 // buffer[0] channel 106 // buffer[0] channel
107 // buffer[1] flag1 107 // buffer[1] flag1
108 // buffer[2] flag2 108 // buffer[2] flag2
109 // buffer[3..5] timestamp 109 // buffer[3..5] timestamp
110 // buffer[6..7] unknown_hw1 110 // buffer[6..7] unknown_hw1
111 // buffer[8..9] unknown_hw2 111 // buffer[8..9] unknown_hw2
112 ch = buffer[0]; 112 ch = buffer[0];
113 dat.tx = GSMDECODER_RECEIVE; 113 dat.tx = GSMDECODER_RECEIVE;
114 dat.ch = ch; 114 dat.ch = ch;
115 dat.bsic = buffer[1]; 115 dat.bsic = buffer[1];
116 dat.err = buffer[2]; 116 dat.err = buffer[2];
117 dat.seq = (buffer[3]<<16)|(buffer[4]<<8)|(buffer[5]); 117 dat.seq = (buffer[3]<<16)|(buffer[4]<<8)|(buffer[5]);
118 dat.arfcn = (buffer[6]<<8)|buffer[7]; 118 dat.arfcn = (buffer[6]<<8)|buffer[7];
119 dat.timeshift = (buffer[8]<<8)|buffer[9]; 119 dat.timeshift = (buffer[8]<<8)|buffer[9];
120 120
121 printf("ch=%02X bsic=%i err=%i t=%06X arfcn=%i shift=%i", 121 printf("ch=%02X bsic=%i err=%i t=%06X arfcn=%i shift=%i",
122 ch, buffer[1], buffer[2], 122 ch, buffer[1], buffer[2],
123 dat.seq, dat.arfcn, dat.timeshift 123 dat.seq, dat.arfcn, dat.timeshift
124 ); 124 );
125 125
126 //dumpraw("MDI recv 80 header", &buffer[6], 4); 126 //dumpraw("MDI recv 80 header", &buffer[6], 4);
127 printf(" "); 127 printf(" ");
128 if(buffer[2] == 0) { /* unencrypted */ 128 if(buffer[2] == 0) { /* unencrypted */
129 if(ch == 0x70) { 129 if(ch == 0x70) {
130 /* Normal header + 2b prefix */ 130 /* Normal header + 2b prefix */
131 dumpraw("MDI recv ch70 prefix", &buffer[10], 2); 131 dumpraw("MDI recv ch70 prefix", &buffer[10], 2);
132 printf("\n"); 132 printf("\n");
133 GSMDecoder_L2packet(gsmdec, &dat, &buffer[12], length-12); 133 GSMDecoder_L2packet(gsmdec, &dat, &buffer[12], length-12);
134 } else if (ch == 0x80 || ch == 0xB0) { 134 } else if (ch == 0x80 || ch == 0xB0) {
135 /* Normal header */ 135 /* Normal header */
136 printf("\n"); 136 printf("\n");
137 GSMDecoder_L2packet(gsmdec, &dat, &buffer[10], length-10); 137 GSMDecoder_L2packet(gsmdec, &dat, &buffer[10], length-10);
138 } else if (ch == 0x50 || ch == 0x60) { 138 } else if (ch == 0x50 || ch == 0x60) {
139 /* Short header */ 139 /* Short header */
140 140
141 printf("\n"); 141 printf("\n");
142 GSMDecoder_L2short_packet(gsmdec, &dat, &buffer[10], length-10); 142 GSMDecoder_L2short_packet(gsmdec, &dat, &buffer[10], length-10);
143 } else { 143 } else {
144 dumpraw("MDI send 80 packet", &buffer[10], length-10); 144 dumpraw("MDI send 80 packet", &buffer[10], length-10);
145 } 145 }
146 } else { 146 } else {
147 /* Encrypted (?) */ 147 /* Encrypted (?) */
148 dumpraw("MDI send err 80", &buffer[10], length-10); 148 dumpraw("MDI send err 80", &buffer[10], length-10);
149 } 149 }
150 } else { 150 } else {
151 /* hex */ 151 /* hex */
152 for(x=0; x<length; x++) { 152 for(x=0; x<length; x++) {
153 printf("%02x ",buffer[x]&0xFF); 153 printf("%02x ",buffer[x]&0xFF);
154 } 154 }
155 } 155 }
156} 156}
157 157
158static GSM_Error DCT3_ReplyDebugTrace(GSM_Protocol_Message msg, GSM_StateMachine *s) 158static GSM_Error DCT3_ReplyDebugTrace(GSM_Protocol_Message msg, GSM_StateMachine *s)
159{ 159{
160 int x; 160 int x;
161 int id,timestamp,number,length; 161 int id,timestamp,number,length;
162 struct wmx_tracetype *minor; 162 struct wmx_tracetype *minor;
163 char *desc; 163 char *desc;
164 164
165 //printf("Debug Trace Received\n"); 165 //printf("Debug Trace Received\n");
166 /* parse frame 166 /* parse frame
167 Debug trace packet: 167 Debug trace packet:
168 packet type 0x00 168 packet type 0x00
169 source subsystem 0x01 (LOCAL) 169 source subsystem 0x01 (LOCAL)
170 verder formaat zie notebook 170 verder formaat zie notebook
171 0x08 ID (payload=offset 0x02 here) 171 0x08 ID (payload=offset 0x02 here)
172 0x0A timestamp 172 0x0A timestamp
173 0x0C seq nr 173 0x0C seq nr
174 0x0D .. parameters 174 0x0D .. parameters
175 */ 175 */
176 id = ((msg.Buffer[2]&0xFF)<<8)|(msg.Buffer[3]&0xFF); 176 id = ((msg.Buffer[2]&0xFF)<<8)|(msg.Buffer[3]&0xFF);
177 timestamp = ((msg.Buffer[4]&0xFF)<<8)|(msg.Buffer[5]&0xFF); 177 timestamp = ((msg.Buffer[4]&0xFF)<<8)|(msg.Buffer[5]&0xFF);
178 number = msg.Buffer[6]&0xFF; 178 number = msg.Buffer[6]&0xFF;
179 length = msg.Buffer[7]&0xFF; 179 length = msg.Buffer[7]&0xFF;
180 180
181 /* filter */ 181 /* filter */
182 //if((id&0xFF00)==0x1900 && id != 0x1980) 182 //if((id&0xFF00)==0x1900 && id != 0x1980)
183 //return GE_NONE; 183 //return GE_NONE;
184 //printf("%02x\n",msg.Buffer[10]); 184 //printf("%02x\n",msg.Buffer[10]);
185 //if(msg.Buffer[10]!=0x40) 185 //if(msg.Buffer[10]!=0x40)
186 //return GE_NONE; 186 //return GE_NONE;
187 /* Query trace type name */ 187 /* Query trace type name */
188 desc = "Unknown"; 188 desc = "Unknown";
189 if(traces != NULL) { 189 if(traces != NULL) {
190 minor = wmx_tracestruct_queryminor(traces, id); 190 minor = wmx_tracestruct_queryminor(traces, id);
191 if(minor != NULL) desc = minor->desc; 191 if(minor != NULL) desc = minor->desc;
192 } 192 }
193 printf("<%04X> %s\n", id, desc); 193 printf("<%04X> %s\n", id, desc);
194 printf("t=%04x nr=%02x: ", timestamp, number); 194 printf("t=%04x nr=%02x: ", timestamp, number);
195 195
196 /* TODO -- decode debug types on phone type */ 196 /* TODO -- decode debug types on phone type */
197 switch(id>>8) { 197 switch(id>>8) {
198 case 0x33: 198 case 0x33:
199 case 0x34: 199 case 0x34:
200 case 0x35: 200 case 0x35:
201 case 0x37: 201 case 0x37:
202 case 0x38: 202 case 0x38:
203 case 0x39: 203 case 0x39:
204 case 0x3A: 204 case 0x3A:
205 case 0x3B: 205 case 0x3B:
206 case 0x3C: 206 case 0x3C:
207 case 0x5F: 207 case 0x5F:
208 /* text */ 208 /* text */
209 /* skip length byte */ 209 /* skip length byte */
210 printf("\""); 210 printf("\"");
211 for(x=8; x<msg.Length; x++) { 211 for(x=8; x<msg.Length; x++) {
212 printf("%c",msg.Buffer[x]&0xFF); 212 printf("%c",msg.Buffer[x]&0xFF);
213 } 213 }
214 printf("\""); 214 printf("\"");
215 break; 215 break;
216 /* 216 /*
217 case 0x6801: 217 case 0x6801:
218 for(x=8; x<msg.Length; x++) { 218 for(x=8; x<msg.Length; x++) {
219 printf("%02x%c ",msg.Buffer[x]&0xFF,msg.Buffer[x]&0xFF); 219 printf("%02x%c ",msg.Buffer[x]&0xFF,msg.Buffer[x]&0xFF);
220 } 220 }
221 break; 221 break;
222 */ 222 */
223 case 0x18: /* MDISND */ 223 case 0x18: /* MDISND */
224 224
225 /* skip these: 225 /* skip these:
226 +00 length 226 +00 length
227 +01 type (also xx in 0x18xx) 227 +01 type (also xx in 0x18xx)
228 */ 228 */
229 if(msg.Length<10 || msg.Buffer[9]!=(id&0xFF)) { 229 if(msg.Length<10 || msg.Buffer[9]!=(id&0xFF)) {
230 printf("C %02X: param:%02x", id&0xFF, msg.Buffer[8]); 230 printf("C %02X: param:%02x", id&0xFF, msg.Buffer[8]);
231 } else { 231 } else {
232 //printf("D %02X: ", id&0xFF); 232 //printf("D %02X: ", id&0xFF);
233 printf("D %02X: ", id&0xFF); 233 printf("D %02X: ", id&0xFF);
234 mdisnd_data((unsigned char)(id&0xFF), (unsigned char*)&msg.Buffer[10], msg.Length-10); 234 mdisnd_data((unsigned char)(id&0xFF), (unsigned char*)&msg.Buffer[10], msg.Length-10);
235 } 235 }
236 break; 236 break;
237 case 0x19: /* MDIRCV */ 237 case 0x19: /* MDIRCV */
238 if(msg.Length<10 || msg.Buffer[9]!=(id&0xFF)) { 238 if(msg.Length<10 || msg.Buffer[9]!=(id&0xFF)) {
239 printf("C %02X: param:%02x", id&0xFF, msg.Buffer[8]); 239 printf("C %02X: param:%02x", id&0xFF, msg.Buffer[8]);
240 } else { 240 } else {
241 printf("D %02X: ", id&0xFF); 241 printf("D %02X: ", id&0xFF);
242 mdircv_data((unsigned char)(id&0xFF), (unsigned char*)&msg.Buffer[10], msg.Length-10); 242 mdircv_data((unsigned char)(id&0xFF), (unsigned char*)&msg.Buffer[10], msg.Length-10);
243 //dumpraw((unsigned char*)&msg.Buffer[10], msg.Length-10); 243 //dumpraw((unsigned char*)&msg.Buffer[10], msg.Length-10);
244 } 244 }
245 break; 245 break;
246 case 0x20: /* 0x25 SIM commands */ 246 case 0x20: /* 0x25 SIM commands */
247 /* 247 /*
248 for(x=8;x<msg.Length;x++) 248 for(x=8;x<msg.Length;x++)
249 printf("%02x ", msg.Buffer[x]&0xFF); 249 printf("%02x ", msg.Buffer[x]&0xFF);
250 */ 250 */
251 printf("SIM command "); 251 printf("SIM command ");
252 if(msg.Buffer[8]==0xa0) { // check if valid (class=a0) 252 if(msg.Buffer[8]==0xa0) { // check if valid (class=a0)
253 simCommand_data(msg.Buffer[9], (unsigned char)(id&0xFF), (unsigned char*)&msg.Buffer[10], msg.Length-10); 253 simCommand_data(msg.Buffer[9], (unsigned char)(id&0xFF), (unsigned char*)&msg.Buffer[10], msg.Length-10);
254 // TODO: pass the msg.Buffer[9] and skip 1rst arg 254 // TODO: pass the msg.Buffer[9] and skip 1rst arg
255 } else { 255 } else {
256 printf("Unknown 0x25 packet (NOT SIM cmd): "); 256 printf("Unknown 0x25 packet (NOT SIM cmd): ");
257 for(x=8;x<msg.Length;x++) printf("%02x ", msg.Buffer[x]&0xFF); 257 for(x=8;x<msg.Length;x++) printf("%02x ", msg.Buffer[x]&0xFF);
258 printf("\n"); 258 printf("\n");
259 } 259 }
260 break; 260 break;
261 case 0x22: /* 0x27 SIM answer to command (error/ok/etc..) */ 261 case 0x22: /* 0x27 SIM answer to command (error/ok/etc..) */
262 if(msg.Length<10) { 262 if(msg.Length<10) {
263 // Unknown response 263 // Unknown response
264 for(x=0;x<msg.Length-10;x++) printf("%02x ", msg.Buffer[x]&0xFF); 264 for(x=0;x<msg.Length-10;x++) printf("%02x ", msg.Buffer[x]&0xFF);
265 printf(" (Unknown 0x27 packet ? ? )\n"); 265 printf(" (Unknown 0x27 packet ? ? )\n");
266 } else { 266 } else {
267 simAnswer_Process((unsigned char)(id&0xFF), (unsigned char*)&msg.Buffer[8], length); 267 simAnswer_Process((unsigned char)(id&0xFF), (unsigned char*)&msg.Buffer[8], length);
268 } 268 }
269 break; 269 break;
270 case 0x23: /* 0x28 SIM response data to commands */ 270 case 0x23: /* 0x28 SIM response data to commands */
271 if(msg.Length<10) { 271 if(msg.Length<10) {
272 // Unknown response 272 // Unknown response
273 for(x=0;x<msg.Length-10;x++) printf("%02x ", msg.Buffer[x]&0xFF); 273 for(x=0;x<msg.Length-10;x++) printf("%02x ", msg.Buffer[x]&0xFF);
274 printf(" (Unknown 0x28 packet)\n"); 274 printf(" (Unknown 0x28 packet)\n");
275 } else { 275 } else {
276 simResponse_Process((unsigned char)(id&0xFF), (unsigned char*)&msg.Buffer[8], length); 276 simResponse_Process((unsigned char)(id&0xFF), (unsigned char*)&msg.Buffer[8], length);
277 } 277 }
278 break; 278 break;
279 default: 279 default:
280 /* hex */ 280 /* hex */
281 for(x=8; x<msg.Length; x++) { 281 for(x=8; x<msg.Length; x++) {
282 printf("%02x ",msg.Buffer[x]&0xFF); 282 printf("%02x ",msg.Buffer[x]&0xFF);
283 } 283 }
284 break; 284 break;
285 } 285 }
286 printf("\n"); 286 printf("\n");
287 return ERR_NONE; 287 return ERR_NONE;
288} 288}
289 289
290 290
291static GSM_Error DCT3_ReplyMyPacket(GSM_Protocol_Message msg, GSM_StateMachine *s) 291static GSM_Error DCT3_ReplyMyPacket(GSM_Protocol_Message msg, GSM_StateMachine *s)
292{ 292{
293 int x; 293 int x;
294 294
295 printf("MyPacket "); 295 printf("MyPacket ");
296 for(x=0; x<msg.Length; x++) { 296 for(x=0; x<msg.Length; x++) {
297 printf("%02x ",msg.Buffer[x]&0xFF); 297 printf("%02x ",msg.Buffer[x]&0xFF);
298 } 298 }
299 printf("\n"); 299 printf("\n");
300 return ERR_NONE; 300 return ERR_NONE;
301} 301}
302 302
303#define ID_DebugTrace 0x666 303#define ID_DebugTrace 0x666
304#define ID_DebugSwitch 0x667 304#define ID_DebugSwitch 0x667
305 #define ID_RPC 0x668 305 #define ID_RPC 0x668
306 306
307void DCT3SetDebug(int argc, char *argv[]) 307void DCT3SetDebug(int argc, char *argv[])
308 { 308 {
309 int x,count; 309 int x,count;
310 unsigned int y; 310 unsigned int y;
311 unsigned char reqDisable[] = {0x01, 0x01, 0x71}; 311 unsigned char reqDisable[] = {0x01, 0x01, 0x71};
312 // unsigned char reqTest[] = {0x01, 0x01, 0x96, 0xFF, 0xFF}; 312 // unsigned char reqTest[] = {0x01, 0x01, 0x96, 0xFF, 0xFF};
313 313
314 /* RPC testing packets: */ 314 /* RPC testing packets: */
315 315
316 /* RPC: Get version */ 316 /* RPC: Get version */
317 //unsigned char reqTest2[] = {0x01, 0x01, 0x00, 0x03, 0x00}; 317 //unsigned char reqTest2[] = {0x01, 0x01, 0x00, 0x03, 0x00};
318 /* RPC: read I/O 0x6D mask 0xFF */ 318 /* RPC: read I/O 0x6D mask 0xFF */
319 //unsigned char reqTest2[] = {0x01, 0x01, 0x02, 0x01, 0x02, 0x6D, 0xFF}; /* */ 319 //unsigned char reqTest2[] = {0x01, 0x01, 0x02, 0x01, 0x02, 0x6D, 0xFF}; /* */
320 /* RPC: write I/O 0x03 mask 0xFF value 0x31 */ 320 /* RPC: write I/O 0x03 mask 0xFF value 0x31 */
321 //unsigned char reqTest2[] = {0x01, 0x01, 0x01, 0x01, 0x07, 0x03, 0xFF, 0x31}; /* write I/O */ 321 //unsigned char reqTest2[] = {0x01, 0x01, 0x01, 0x01, 0x07, 0x03, 0xFF, 0x31}; /* write I/O */
322 322
323 /* RPC: write forged FBUS packet to MDISND */ 323 /* RPC: write forged FBUS packet to MDISND */
324 // unsigned char reqTest2[] = {0x01, 0x01, 0x16, 0x01, 0x06, 324 // unsigned char reqTest2[] = {0x01, 0x01, 0x16, 0x01, 0x06,
325 //0x14, // R0 -- length 325 //0x14, // R0 -- length
326 //0x05, // R1 -- MDI type identifier 0x05(FBUS) 326 //0x05, // R1 -- MDI type identifier 0x05(FBUS)
327 //0x1e, 0x0c, 0x00, 0x66, 327 //0x1e, 0x0c, 0x00, 0x66,
328 //0x00, 0x0e, 0x01, 0x01, 328 //0x00, 0x0e, 0x01, 0x01,
329 //0x66, 0x55, 0x44, 0x33, 329 //0x66, 0x55, 0x44, 0x33,
330 //0x0d, 0x01, 0x01, 0x01, 330 //0x0d, 0x01, 0x01, 0x01,
331 //0x1b, 0x58, 0x01, 0x44}; 331 //0x1b, 0x58, 0x01, 0x44};
332 //1805 t=cb37 nr=e2 :D 05: 332 //1805 t=cb37 nr=e2 :D 05:
333 333
334 /* debug enable packet */ 334 /* debug enable packet */
335 unsigned char reqEnable[] = { 335 unsigned char reqEnable[] = {
336 0x00, 0x01, 0x70, 336 0x00, 0x01, 0x70,
337 /* Debug bits 337 /* Debug bits
338 byte[bit>>3]&(1<<(7-(bit&7))) 338 byte[bit>>3]&(1<<(7-(bit&7)))
339 */ 339 */
340 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00 */ 340 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x00 */
341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40 */ 341 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x40 */
342 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80 */ 342 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x80 */
343 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */ 343 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xC0 */
344 /* Debug verbose bits 344 /* Debug verbose bits
345 byte[bit>>3]&(1<<(7-(bit&7))) 345 byte[bit>>3]&(1<<(7-(bit&7)))
346 */ 346 */
347 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 347 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
348 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 348 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
349 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 349 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
350 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 350 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
351 }; 351 };
352 352
353 #define ENABLE_BIT(bit,verbose) reqEnable[3 + (bit>>3)] |= 1<<(7-(bit&7)); if(verbose){reqEnable[3 + 32 + (bit>>3)] |= 1<<(7-(bit&7));} 353 #define ENABLE_BIT(bit,verbose) reqEnable[3 + (bit>>3)] |= 1<<(7-(bit&7)); if(verbose){reqEnable[3 + 32 + (bit>>3)] |= 1<<(7-(bit&7));}
354 354
355 /* Enable some bit 355 /* Enable some bit
356 TODO command line or GUI interface 356 TODO command line or GUI interface
357 */ 357 */
358 //ENABLE_BIT(0x18, 1);/* Enable MDISND debugging */ 358 //ENABLE_BIT(0x18, 1);/* Enable MDISND debugging */
359 //ENABLE_BIT(0x19, 1);/* Enable MDIRCV debugging */ 359 //ENABLE_BIT(0x19, 1);/* Enable MDIRCV debugging */
360 //ENABLE_BIT(0x31, 1); 360 //ENABLE_BIT(0x31, 1);
361 361
362 gsmdec = GSMDecoder_new(); 362 gsmdec = GSMDecoder_new();
363 /* Open XML file .. needs to be argument */ 363 /* Open XML file .. needs to be argument */
364 { 364 {
365 FILE *xout = fopen("out.xml", "w"); 365 FILE *xout = fopen("out.xml", "w");
366 GSMDecoder_xmlout(gsmdec, xout); 366 GSMDecoder_xmlout(gsmdec, xout);
367 } 367 }
368 printf("Debug Trace Mode -- wumpus 2003\n"); 368 printf("Debug Trace Mode -- wumpus 2003\n");
369 traces = wmx_tracestruct_load(argv[2]); 369 traces = wmx_tracestruct_load(argv[2]);
370 if(traces == NULL) 370 if(traces == NULL)
371 printf("Warning: could not load trace description file %s\n", argv[2]); 371 printf("Warning: could not load trace description file %s\n", argv[2]);
372 printf("Activating ranges:\n"); 372 printf("Activating ranges:\n");
373 count = 0; 373 count = 0;
374 for(x=3; x<argc; x++) { 374 for(x=3; x<argc; x++) {
375 char *ptr = argv[x]; 375 char *ptr = argv[x];
376 unsigned from,to,verbose; 376 unsigned from,to,verbose;
377 377
378 while(*ptr) { 378 while(*ptr) {
379 verbose = 0; 379 verbose = 0;
380 if(*ptr == 'v') { 380 if(*ptr == 'v') {
381 verbose = 1; 381 verbose = 1;
382 ptr++; 382 ptr++;
383 } 383 }
384 to = from = strtol(ptr, &ptr, 16); 384 to = from = strtol(ptr, &ptr, 16);
385 if(*ptr == '-') { 385 if(*ptr == '-') {
386 ptr ++; 386 ptr ++;
387 to = strtol(ptr, &ptr, 16); 387 to = strtol(ptr, &ptr, 16);
388 } 388 }
389 if(*ptr != ',' && *ptr != 0) { 389 if(*ptr != ',' && *ptr != 0) {
390 printf("Invalid parameter '%s'\n", argv[x]); 390 printf("Invalid parameter '%s'\n", argv[x]);
391 return; 391 return;
392 } 392 }
393 if(*ptr == ',') 393 if(*ptr == ',')
394 ptr++; 394 ptr++;
395 if(from > 0xFF) from=0xFF; 395 if(from > 0xFF) from=0xFF;
396 if(to > 0xFF) to=0xFF; 396 if(to > 0xFF) to=0xFF;
397 printf(" %02x-%02x verbose=%i\n",from,to,verbose); 397 printf(" %02x-%02x verbose=%i\n",from,to,verbose);
398 for(y=from; y<=to; y++) { 398 for(y=from; y<=to; y++) {
399 ENABLE_BIT(y, verbose); 399 ENABLE_BIT(y, verbose);
400 count++; 400 count++;
401 } 401 }
402 } 402 }
403 } 403 }
404 if(count == 0) { 404 if(count == 0) {
405 printf("Nothing activated -- bailing out\n"); 405 printf("Nothing activated -- bailing out\n");
406 return; 406 return;
407 } 407 }
408 //ENABLE_BIT(0x20, 1); /* SIM commands (literal) */ 408 //ENABLE_BIT(0x20, 1); /* SIM commands (literal) */
409 //ENABLE_BIT(0x21, 1); /* SIML2 commands (literal) */ 409 //ENABLE_BIT(0x21, 1); /* SIML2 commands (literal) */
410 //ENABLE_BIT(0x22, 1); /* SIM commands (literal) */ 410 //ENABLE_BIT(0x22, 1); /* SIM commands (literal) */
411 //ENABLE_BIT(0x3B, 1);/* PHCTRL state */ 411 //ENABLE_BIT(0x3B, 1);/* PHCTRL state */
412 412
413 GSM_Init(true); 413 GSM_Init(true);
414 414
415 /* We Need DCT3 */ 415 /* We Need DCT3 */
416 if (CheckDCT3Only()!=ERR_NONE) return; 416 if (CheckDCT3Only()!=ERR_NONE) return;
417 417
418 error=DCT3_EnableSecurity (&s, 0x01); 418 error=DCT3_EnableSecurity (&s, 0x01);
419 Print_Error(error); 419 Print_Error(error);
420 420
421 s.User.UserReplyFunctions=UserReplyFunctionsX; 421 s.User.UserReplyFunctions=UserReplyFunctionsX;
422 422
423 //error=GSM_WaitFor (&s, reqTest, sizeof(reqTest), 0x40, 1, ID_DebugSwitch); 423 //error=GSM_WaitFor (&s, reqTest, sizeof(reqTest), 0x40, 1, ID_DebugSwitch);
424 424
425 //error=GSM_WaitFor (&s, reqTest2, sizeof(reqTest2), 0xD1, 4, ID_RPC); 425 //error=GSM_WaitFor (&s, reqTest2, sizeof(reqTest2), 0xD1, 4, ID_RPC);
426 426
427 /* Enable Debug Mode */ 427 /* Enable Debug Mode */
428 error=GSM_WaitFor (&s, reqEnable, sizeof(reqEnable), 0x40, 4, ID_DebugSwitch); 428 error=GSM_WaitFor (&s, reqEnable, sizeof(reqEnable), 0x40, 4, ID_DebugSwitch);
429 429
430 Print_Error(error); 430 Print_Error(error);
431 signal(SIGINT, interrupt); 431 signal(SIGINT, interrupt);
432 printf("Press Ctrl+C to interrupt...\n"); 432 printf("Press Ctrl+C to interrupt...\n");
433 x=0; 433 x=0;
434 434
435 /* 435 /*
436 while(x<100) { 436 while(x<100) {
437 //printf(": %02x\n",x); 437 //printf(": %02x\n",x);
438 s.Phone.Data.RequestID= ID_DebugTrace; 438 s.Phone.Data.RequestID= ID_DebugTrace;
439 res = s.Device.Functions->ReadDevice(&s, buff, 255); 439 res = s.Device.Functions->ReadDevice(&s, buff, 255);
440 if(res) { 440 if(res) {
441 printf("%02x\n",x); 441 printf("%02x\n",x);
442 for(y=0;y<res;y++) { 442 for(y=0;y<res;y++) {
443 //printf("%02x\n",x,buff[y]&0xFF); 443 //printf("%02x\n",x,buff[y]&0xFF);
444 s.Protocol.Functions->StateMachine(&s,buff[y]); 444 s.Protocol.Functions->StateMachine(&s,buff[y]);
445 x++; 445 x++;
446 } 446 }
447 } 447 }
448 } 448 }
449 */ 449 */
450 ; 450 ;
451 451
452 /* todo: wait and dump for some time */ 452 /* todo: wait and dump for some time */
453 while (!gshutdown) { 453 while (!gshutdown) {
454 GSM_ReadDevice(&s,true); 454 GSM_ReadDevice(&s,true);
455 my_sleep(10); 455 my_sleep(10);
456 } 456 }
457 signal(SIGINT, SIG_DFL); 457 signal(SIGINT, SIG_DFL);
458 printf("Disabling\n"); 458 printf("Disabling\n");
459 error=GSM_WaitFor (&s, reqDisable, sizeof(reqDisable), 0x40, 10, ID_DebugSwitch); 459 error=GSM_WaitFor (&s, reqDisable, sizeof(reqDisable), 0x40, 10, ID_DebugSwitch);
460 Print_Error(error); 460 Print_Error(error);
461 461
462 GSMDecoder_free(gsmdec); 462 GSMDecoder_free(gsmdec);
463} 463}
464 464
465static GSM_Reply_Function UserReplyFunctionsX[] = { 465static GSM_Reply_Function UserReplyFunctionsX[] = {
466 {DCT3_ReplySwitchDebug, "\x40",0x02,0x70,ID_DebugSwitch }, 466 {DCT3_ReplySwitchDebug, "\x40",0x02,0x70,ID_DebugSwitch },
467 {DCT3_ReplySwitchDebug, "\x40",0x02,0x71,ID_DebugSwitch }, 467 {DCT3_ReplySwitchDebug, "\x40",0x02,0x71,ID_DebugSwitch },
468 {DCT3_ReplyDebugTrace, "\x00",0x00,0x00,ID_IncomingFrame}, 468 {DCT3_ReplyDebugTrace, "\x00",0x00,0x00,ID_IncomingFrame},
469 {DCT3_ReplyMyPacket, "\x40",0x00,0x00,ID_IncomingFrame}, 469 {DCT3_ReplyMyPacket, "\x40",0x00,0x00,ID_IncomingFrame},
470 470
471 {DCT3_ReplyRPC, "\xD2",0x00,0x00,ID_RPC }, 471 {DCT3_ReplyRPC, "\xD2",0x00,0x00,ID_RPC },
472 472
473 {NULL, "\x00",0x00,0x00,ID_None } 473 {NULL, "\x00",0x00,0x00,ID_None }
474 }; 474 };
475 475
476#endif 476#endif
477 477
478/* How should editor hadle tabs in this file? Add editor commands here. 478/* How should editor hadle tabs in this file? Add editor commands here.
479 * vim: noexpandtab sw=8 ts=8 sts=8: 479 * vim: noexpandtab sw=8 ts=8 sts=8:
480 */ 480 */
diff --git a/gammu/emb/gammu/depend/nokia/dct4.c b/gammu/emb/gammu/depend/nokia/dct4.c
index 4bf958d..43d8f09 100644
--- a/gammu/emb/gammu/depend/nokia/dct4.c
+++ b/gammu/emb/gammu/depend/nokia/dct4.c
@@ -1,784 +1,784 @@
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[]; 16static 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 s.ConnectionType!=GCT_FBUS2DKU5) {
40 return ERR_OTHERCONNECTIONREQUIRED; 40 return ERR_OTHERCONNECTIONREQUIRED;
41 } 41 }
42 return ERR_NONE; 42 return ERR_NONE;
43} 43}
44 44
45static void CheckDCT4() 45static void CheckDCT4()
46{ 46{
47 GSM_Error error; 47 GSM_Error error;
48 48
49 error = CheckDCT4Only(); 49 error = CheckDCT4Only();
50 switch (error) { 50 switch (error) {
51 case ERR_NOTSUPPORTED: 51 case ERR_NOTSUPPORTED:
52 Print_Error(ERR_NOTSUPPORTED); 52 Print_Error(ERR_NOTSUPPORTED);
53 break; 53 break;
54 case ERR_OTHERCONNECTIONREQUIRED: 54 case ERR_OTHERCONNECTIONREQUIRED:
55 printf("Can't do it with current phone protocol\n"); 55 printf("Can't do it with current phone protocol\n");
56 GSM_TerminateConnection(&s); 56 GSM_TerminateConnection(&s);
57 exit(-1); 57 exit(-1);
58 default: 58 default:
59 break; 59 break;
60 } 60 }
61} 61}
62 62
63static bool answer_yes2(char *text) 63static bool answer_yes2(char *text)
64{ 64{
65 int len; 65 int len;
66 char ans[99]; 66 char ans[99];
67 67
68 while (1) { 68 while (1) {
69 printf("%s (yes/no) ? ",text); 69 printf("%s (yes/no) ? ",text);
70 len=GetLine(stdin, ans, 99); 70 len=GetLine(stdin, ans, 99);
71 if (len==-1) exit(-1); 71 if (len==-1) exit(-1);
72 if (mystrncasecmp(ans, "yes",0)) return true; 72 if (mystrncasecmp(ans, "yes",0)) return true;
73 if (mystrncasecmp(ans, "no" ,0)) return false; 73 if (mystrncasecmp(ans, "no" ,0)) return false;
74 } 74 }
75} 75}
76 76
77/* ------------------- functions ------------------------------------------- */ 77/* ------------------- functions ------------------------------------------- */
78 78
79static DCT4_Feature DCT4Features[] = { 79static DCT4_Feature DCT4Features[] = {
80 {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,""}}},///??
81 {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,""}}},
82 {DCT4_GEA1, "GEA1 support indication", {{1,"on"},{0,"off"},{0,""}}}, 82 {DCT4_GEA1, "GEA1 support indication", {{1,"on"},{0,"off"},{0,""}}},
83 {DCT4_EOTD, "EOTD support", {{1,"on"},{0,"off"},{0,""}}}, 83 {DCT4_EOTD, "EOTD support", {{1,"on"},{0,"off"},{0,""}}},
84 {DCT4_WAP_PUSH, "WAP push", {{1,"on"},{0,"off"},{0,""}}}, 84 {DCT4_WAP_PUSH, "WAP push", {{1,"on"},{0,"off"},{0,""}}},
85 {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,""}}},
86 {DCT4_JAVA_TCK, "Java TCK support", {{1,"on"},{0,"off"},{0,""}}}, 86 {DCT4_JAVA_TCK, "Java TCK support", {{1,"on"},{0,"off"},{0,""}}},
87 87
88 {DCT4_ALS, "Alternate Line Service (ALS)", {{1,"on"},{0,"off"},{0,""}}}, 88 {DCT4_ALS, "Alternate Line Service (ALS)", {{1,"on"},{0,"off"},{0,""}}},
89 {DCT4_A52, "Ciphering alghoritm A52", {{1,"on"},{0,"off"},{0,""}}}, 89 {DCT4_A52, "Ciphering alghoritm A52", {{1,"on"},{0,"off"},{0,""}}},
90 {DCT4_CSP, "Customer Service Profile", {{0,"off"},{1,"on"},{0,""}}}, 90 {DCT4_CSP, "Customer Service Profile", {{0,"off"},{1,"on"},{0,""}}},
91 {DCT4_EONS, "EONS support", {{1,"on"},{0,"off"},{0,""}}}, 91 {DCT4_EONS, "EONS support", {{1,"on"},{0,"off"},{0,""}}},
92 {DCT4_3GINDICATOR, "3G indicator", {{1,"on"},{0,"off"},{0,""}}}, 92 {DCT4_3GINDICATOR, "3G indicator", {{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_PHONE_NAME, "Display both number and name for incoming calls",{{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 {DCT4_DISPLAY_WAP_PROFILE, "Display selected WAP profile name instead of Home option menu in Services",{{1,"on"},{0,"off"},{0,""}}},
95 95
96 {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,""}}},
97 {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,""}}},
98 {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,""}}},
99 99
100 {DCT4_BLUETOOTH_MENU, "Bluetooth menu", {{1,"on"},{0,"off"},{0,""}}}, 100 {DCT4_BLUETOOTH_MENU, "Bluetooth menu", {{1,"on"},{0,"off"},{0,""}}},
101 {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,""}}},
102 {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,""}}},
103 {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,""}}},
104 {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,""}}},
105 {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,""}}},
106 {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,""}}},
107 {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,""}}},
108 {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,""}}},
109 {DCT4_CONFIRM_ALS, "Confirm using ALS", {{1,"on"},{0,"off"},{0,""}}}, 109 {DCT4_CONFIRM_ALS, "Confirm using ALS", {{1,"on"},{0,"off"},{0,""}}},
110 {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,""}}},
111 111
112 {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,""}}},
113 113
114#ifdef DEBUG 114#ifdef DEBUG
115 {DCT4_TEST,"",{{1,"1"},{0,"0"}}}, 115 {DCT4_TEST,"",{{1,"1"},{0,"0"}}},
116#endif 116#endif
117 117
118 {0, "", {{0,""}}} 118 {0, "", {{0,""}}}
119}; 119};
120 120
121static DCT4_Phone_Features DCT4PhoneFeatures[] = { 121static DCT4_Phone_Features DCT4PhoneFeatures[] = {
122 /*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},
123 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 123 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
124 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 124 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
125 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 125 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
126 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 126 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
127 {DCT4_EONS,28},{DCT4_3GINDICATOR,30},{DCT4_INSTANT_MESS_MENU,33}, 127 {DCT4_EONS,28},{DCT4_3GINDICATOR,30},{DCT4_INSTANT_MESS_MENU,33},
128 {DCT4_CONFIRM_ALS,35}, 128 {DCT4_CONFIRM_ALS,35},
129 {0,0}}}, 129 {0,0}}},
130 /*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},
131 {DCT4_GEA1,15},{DCT4_EOTD,18},{DCT4_WAP_SETTINGS_MENU,20}, 131 {DCT4_GEA1,15},{DCT4_EOTD,18},{DCT4_WAP_SETTINGS_MENU,20},
132 {DCT4_DISPLAY_PHONE_NAME,21},{DCT4_WAP_GOTO_MENU,23}, 132 {DCT4_DISPLAY_PHONE_NAME,21},{DCT4_WAP_GOTO_MENU,23},
133 {DCT4_SERVICES_GAMES_APP_GALLERY,26},{DCT4_3GINDICATOR,28}, 133 {DCT4_SERVICES_GAMES_APP_GALLERY,26},{DCT4_3GINDICATOR,28},
134 {DCT4_DISPLAY_WAP_PROFILE,31},{DCT4_SAT_CONFIRM_MENU,33}, 134 {DCT4_DISPLAY_WAP_PROFILE,31},{DCT4_SAT_CONFIRM_MENU,33},
135 {DCT4_CONFIRM_ALS,34},{DCT4_EONS,40},{DCT4_ALWAYS_ONLINE,45}, 135 {DCT4_CONFIRM_ALS,34},{DCT4_EONS,40},{DCT4_ALWAYS_ONLINE,45},
136 {0,0}}}, 136 {0,0}}},
137 /*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},
138 {DCT4_GEA1,15},{DCT4_EOTD,18},{DCT4_WAP_SETTINGS_MENU,20}, 138 {DCT4_GEA1,15},{DCT4_EOTD,18},{DCT4_WAP_SETTINGS_MENU,20},
139 {DCT4_DISPLAY_PHONE_NAME,21},{DCT4_WAP_GOTO_MENU,23}, 139 {DCT4_DISPLAY_PHONE_NAME,21},{DCT4_WAP_GOTO_MENU,23},
140 {DCT4_SERVICES_GAMES_APP_GALLERY,26},{DCT4_3GINDICATOR,28}, 140 {DCT4_SERVICES_GAMES_APP_GALLERY,26},{DCT4_3GINDICATOR,28},
141 {DCT4_DISPLAY_WAP_PROFILE,31},{DCT4_SAT_CONFIRM_MENU,33}, 141 {DCT4_DISPLAY_WAP_PROFILE,31},{DCT4_SAT_CONFIRM_MENU,33},
142 {DCT4_CONFIRM_ALS,34},{DCT4_EONS,40},{DCT4_ALWAYS_ONLINE,45}, 142 {DCT4_CONFIRM_ALS,34},{DCT4_EONS,40},{DCT4_ALWAYS_ONLINE,45},
143 {0,0}}}, 143 {0,0}}},
144 /*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},
145 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 145 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
146 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 146 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
147 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 147 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
148 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 148 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
149 /*MORE*/ {0,0}}}, 149 /*MORE*/ {0,0}}},
150 /*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},
151 {DCT4_GAMES_WAP_DOWNLOAD,7},{DCT4_GAMES_SCORE_SEND,8}, 151 {DCT4_GAMES_WAP_DOWNLOAD,7},{DCT4_GAMES_SCORE_SEND,8},
152 {DCT4_GAMES_URL_CHECK,9},{DCT4_GPRS_PCCH,13}, 152 {DCT4_GAMES_URL_CHECK,9},{DCT4_GPRS_PCCH,13},
153 {DCT4_GEA1,15},{DCT4_ALWAYS_ONLINE,18},{0,0}}}, 153 {DCT4_GEA1,15},{DCT4_ALWAYS_ONLINE,18},{0,0}}},
154 /*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},
155 {DCT4_DISPLAY_PHONE_NAME,14},{DCT4_WAP_GOTO_MENU,15}, 155 {DCT4_DISPLAY_PHONE_NAME,14},{DCT4_WAP_GOTO_MENU,15},
156 {DCT4_WAP_SETTINGS_MENU,16},{DCT4_SERVICES_GAMES_APP_GALLERY,19}, 156 {DCT4_WAP_SETTINGS_MENU,16},{DCT4_SERVICES_GAMES_APP_GALLERY,19},
157 {DCT4_DISPLAY_WAP_PROFILE,25},{0,0}}}, 157 {DCT4_DISPLAY_WAP_PROFILE,25},{0,0}}},
158 /*3650*/ {"NHL-8",{{DCT4_ALS,1},{0,0}}}, 158 /*3650*/ {"NHL-8",{{DCT4_ALS,1},{0,0}}},
159 /*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},
160 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 160 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
161 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 161 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
162 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 162 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
163 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 163 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
164 {DCT4_EONS,28}, 164 {DCT4_EONS,28},
165 // {DCT4_5100_IDENTIFY,10}, 165 // {DCT4_5100_IDENTIFY,10},
166 {0,0}}}, 166 {0,0}}},
167 /*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},
168 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 168 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
169 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 169 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
170 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 170 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
171 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 171 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
172 {DCT4_EONS,28}, 172 {DCT4_EONS,28},
173 // {DCT4_5100_IDENTIFY,10}, 173 // {DCT4_5100_IDENTIFY,10},
174 {0,0}}}, 174 {0,0}}},
175 /*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},
176 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 176 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
177 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 177 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
178 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 178 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
179 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 179 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
180 {0,0}}}, 180 {0,0}}},
181 /*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},
182 {DCT4_GEA1,14},{DCT4_EOTD,17},{DCT4_WAP_SETTINGS_MENU,19}, 182 {DCT4_GEA1,14},{DCT4_EOTD,17},{DCT4_WAP_SETTINGS_MENU,19},
183 {DCT4_DISPLAY_PHONE_NAME,20},{DCT4_WAP_GOTO_MENU,22}, 183 {DCT4_DISPLAY_PHONE_NAME,20},{DCT4_WAP_GOTO_MENU,22},
184 {DCT4_WAP_BOOKMARKS_MENU2,24},{DCT4_SERVICES_GAMES_APP_GALLERY,25}, 184 {DCT4_WAP_BOOKMARKS_MENU2,24},{DCT4_SERVICES_GAMES_APP_GALLERY,25},
185 {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},
186 {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},
187 {0,0}}}, 187 {0,0}}},
188 /*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},
189 {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},
190 {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}}},
191 /*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},
192 {DCT4_GAMES_SCORE_SEND,8},{DCT4_GAMES_URL_CHECK,9}, 192 {DCT4_GAMES_SCORE_SEND,8},{DCT4_GAMES_URL_CHECK,9},
193 {DCT4_BLUETOOTH_MENU,10},{DCT4_USE_PREF_SIM_NET,11}, 193 {DCT4_BLUETOOTH_MENU,10},{DCT4_USE_PREF_SIM_NET,11},
194 {DCT4_GPRS_PCCH,13},{DCT4_GEA1,15},{DCT4_EOTD,16}, 194 {DCT4_GPRS_PCCH,13},{DCT4_GEA1,15},{DCT4_EOTD,16},
195 {DCT4_ALWAYS_ONLINE,17},{DCT4_JAVA_GAMES_MENU,18}, 195 {DCT4_ALWAYS_ONLINE,17},{DCT4_JAVA_GAMES_MENU,18},
196 {DCT4_WAP_BOOKMARKS_MENU,20},{DCT4_WAP_SETTINGS_MENU,21}, 196 {DCT4_WAP_BOOKMARKS_MENU,20},{DCT4_WAP_SETTINGS_MENU,21},
197 {DCT4_WAP_PUSH,28},{DCT4_WAP_GOTO_MENU,29},{0,0}}}, 197 {DCT4_WAP_PUSH,28},{DCT4_WAP_GOTO_MENU,29},{0,0}}},
198 /*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},
199 {DCT4_GAMES_SCORE_SEND,8},{DCT4_GAMES_URL_CHECK,9}, 199 {DCT4_GAMES_SCORE_SEND,8},{DCT4_GAMES_URL_CHECK,9},
200 {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}}},
201 /*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},
202 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 202 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
203 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 203 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
204 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 204 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
205 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 205 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
206 {0,0}}}, 206 {0,0}}},
207 /*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},
208 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 208 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
209 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 209 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
210 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 210 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
211 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 211 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
212 /*MORE*/ {0,0}}}, 212 /*MORE*/ {0,0}}},
213 /*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},
214 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 214 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
215 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 215 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
216 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 216 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
217 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 217 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
218 {0,0}}}, 218 {0,0}}},
219 /*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},
220 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 220 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
221 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 221 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
222 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 222 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
223 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 223 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
224 {0,0}}}, 224 {0,0}}},
225 /*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},
226 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12}, 226 {DCT4_GEA1,9},{DCT4_ALWAYS_ONLINE,11},{DCT4_EOTD,12},
227 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18}, 227 {DCT4_DISPLAY_PHONE_NAME,17},{DCT4_WAP_GOTO_MENU,18},
228 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22}, 228 {DCT4_WAP_SETTINGS_MENU,19},{DCT4_SERVICES_GAMES_APP_GALLERY,22},
229 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27}, 229 {DCT4_DISPLAY_WAP_PROFILE,26},{DCT4_SAT_CONFIRM_MENU,27},
230 /*MORE*/ {0,0}}}, 230 /*MORE*/ {0,0}}},
231 /*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},
232 {DCT4_GAMES_SCORE_SEND,8},{DCT4_GAMES_URL_CHECK,9},{DCT4_GPRS_PCCH,13}, 232 {DCT4_GAMES_SCORE_SEND,8},{DCT4_GAMES_URL_CHECK,9},{DCT4_GPRS_PCCH,13},
233 {DCT4_ALWAYS_ONLINE,18},{0,0}}}, 233 {DCT4_ALWAYS_ONLINE,18},{0,0}}},
234 {"", {{0,0}}} 234 {"", {{0,0}}}
235}; 235};
236 236
237static GSM_Error DCT4_ReplySetPPS(GSM_Protocol_Message msg, GSM_StateMachine *s) 237static GSM_Error DCT4_ReplySetPPS(GSM_Protocol_Message msg, GSM_StateMachine *s)
238{ 238{
239 printf("Setting done OK\n"); 239 printf("Setting done OK\n");
240 return ERR_NONE; 240 return ERR_NONE;
241} 241}
242 242
243void DCT4SetPhoneMenus(int argc, char *argv[]) 243void DCT4SetPhoneMenus(int argc, char *argv[])
244{ 244{
245 int current = 10,i=0,j,z; 245 int current = 10,i=0,j,z;
246 unsigned char reqSet[200] = { 246 unsigned char reqSet[200] = {
247 N7110_FRAME_HEADER,0x04,0x00,0x01,0x47,0x48,0x02, 247 N7110_FRAME_HEADER,0x04,0x00,0x01,0x47,0x48,0x02,
248 0x00}; /* Number of changed features */ 248 0x00}; /* Number of changed features */
249 249
250 if (CheckDCT4Only()!=ERR_NONE) return; 250 if (CheckDCT4Only()!=ERR_NONE) return;
251 251
252 s.User.UserReplyFunctions=UserReplyFunctions4; 252 s.User.UserReplyFunctions=UserReplyFunctions4;
253 253
254 while (DCT4PhoneFeatures[i].Model[0] != 0x00) { 254 while (DCT4PhoneFeatures[i].Model[0] != 0x00) {
255 if (!strcmp(DCT4PhoneFeatures[i].Model,s.Phone.Data.Model)) { 255 if (!strcmp(DCT4PhoneFeatures[i].Model,s.Phone.Data.Model)) {
256 j = 0; 256 j = 0;
257 while (DCT4PhoneFeatures[i].Features[j].Name != 0x00) { 257 while (DCT4PhoneFeatures[i].Features[j].Name != 0x00) {
258 z = 0; 258 z = 0;
259 while (DCT4Features[z].Name != 0x00) { 259 while (DCT4Features[z].Name != 0x00) {
260 if (DCT4Features[z].Name == DCT4PhoneFeatures[i].Features[j].Name) { 260 if (DCT4Features[z].Name == DCT4PhoneFeatures[i].Features[j].Name) {
261 printf("%s : %s\n",DCT4Features[z].Text,DCT4Features[z].Values[0].Text); 261 printf("%s : %s\n",DCT4Features[z].Text,DCT4Features[z].Values[0].Text);
262 reqSet[9]++; /* Number of features */ 262 reqSet[9]++; /* Number of features */
263 reqSet[current++] = DCT4PhoneFeatures[i].Features[j].Number; /* Feature number */ 263 reqSet[current++] = DCT4PhoneFeatures[i].Features[j].Number; /* Feature number */
264 reqSet[current++] = DCT4Features[z].Values[0].Value; /* Value */ 264 reqSet[current++] = DCT4Features[z].Values[0].Value; /* Value */
265 break; 265 break;
266 } 266 }
267 z++; 267 z++;
268 } 268 }
269 j++; 269 j++;
270 } 270 }
271 } 271 }
272 i++; 272 i++;
273 } 273 }
274 274
275 if (current == 10) { 275 if (current == 10) {
276 printf("Sorry, but configuration matrix for this model is not added yet. Please report\n"); 276 printf("Sorry, but configuration matrix for this model is not added yet. Please report\n");
277 return; 277 return;
278 } 278 }
279 279
280 reqSet[current++] = 0x00; 280 reqSet[current++] = 0x00;
281 reqSet[current++] = 0x00; 281 reqSet[current++] = 0x00;
282 282
283 error=GSM_WaitFor (&s, reqSet, current, 0x1b, 4, ID_User1); 283 error=GSM_WaitFor (&s, reqSet, current, 0x1b, 4, ID_User1);
284 Print_Error(error); 284 Print_Error(error);
285} 285}
286 286
287DCT4_Phone_Tests DCT4Tests; 287DCT4_Phone_Tests DCT4Tests;
288 288
289static GSM_Error DCT4_ReplyTestsNames(GSM_Protocol_Message msg, GSM_StateMachine *s) 289static GSM_Error DCT4_ReplyTestsNames(GSM_Protocol_Message msg, GSM_StateMachine *s)
290{ 290{
291 int i,pos; 291 int i,pos;
292 292
293 DCT4Tests.Num = msg.Buffer[5]; 293 DCT4Tests.Num = msg.Buffer[5];
294 pos = 6; 294 pos = 6;
295 295
296 smprintf(s,"%i names for phone tests received\n",msg.Buffer[5]); 296 smprintf(s,"%i names for phone tests received\n",msg.Buffer[5]);
297 for (i=0;i<msg.Buffer[5];i++) { 297 for (i=0;i<msg.Buffer[5];i++) {
298 strcpy(DCT4Tests.Tests[i].Name,msg.Buffer+pos+4); 298 strcpy(DCT4Tests.Tests[i].Name,msg.Buffer+pos+4);
299 DCT4Tests.Tests[i].ID = msg.Buffer[pos+2]; 299 DCT4Tests.Tests[i].ID = msg.Buffer[pos+2];
300 smprintf(s,"%x.\"%s\"\n",DCT4Tests.Tests[i].ID,DCT4Tests.Tests[i].Name); 300 smprintf(s,"%x.\"%s\"\n",DCT4Tests.Tests[i].ID,DCT4Tests.Tests[i].Name);
301 pos+=msg.Buffer[pos+1]; 301 pos+=msg.Buffer[pos+1];
302 } 302 }
303 303
304 return ERR_NONE; 304 return ERR_NONE;
305} 305}
306 306
307static GSM_Error DCT4_ReplyTestsStartup(GSM_Protocol_Message msg, GSM_StateMachine *s) 307static GSM_Error DCT4_ReplyTestsStartup(GSM_Protocol_Message msg, GSM_StateMachine *s)
308{ 308{
309 int i,pos,j; 309 int i,pos,j;
310 bool found; 310 bool found;
311 311
312 pos = 10; 312 pos = 10;
313 313
314 for (i=0;i<msg.Buffer[8];i++) { 314 for (i=0;i<msg.Buffer[8];i++) {
315 found = false; 315 found = false;
316 for (j=0;j<DCT4Tests.Num;j++) { 316 for (j=0;j<DCT4Tests.Num;j++) {
317 if (DCT4Tests.Tests[j].ID == msg.Buffer[pos]) { 317 if (DCT4Tests.Tests[j].ID == msg.Buffer[pos]) {
318 DCT4Tests.Tests[j].Startup = true; 318 DCT4Tests.Tests[j].Startup = true;
319 found = true; 319 found = true;
320 break; 320 break;
321 } 321 }
322 } 322 }
323 if (!found) printf("%x ",msg.Buffer[pos]); 323 if (!found) printf("%x ",msg.Buffer[pos]);
324 pos++; 324 pos++;
325 } 325 }
326 326
327 return ERR_NONE; 327 return ERR_NONE;
328} 328}
329 329
330static GSM_Error DCT4_ReplyTestsStatus(GSM_Protocol_Message msg, GSM_StateMachine *s) 330static GSM_Error DCT4_ReplyTestsStatus(GSM_Protocol_Message msg, GSM_StateMachine *s)
331{ 331{
332 int i,pos,j; 332 int i,pos,j;
333 333
334 pos = 6; 334 pos = 6;
335 335
336 smprintf(s,"%i status entries for phone tests received\n",msg.Buffer[5]); 336 smprintf(s,"%i status entries for phone tests received\n",msg.Buffer[5]);
337 for (i=0;i<msg.Buffer[5];i++) { 337 for (i=0;i<msg.Buffer[5];i++) {
338 for (j=0;j<DCT4Tests.Num;j++) { 338 for (j=0;j<DCT4Tests.Num;j++) {
339 if (DCT4Tests.Tests[j].ID == msg.Buffer[pos+2]) { 339 if (DCT4Tests.Tests[j].ID == msg.Buffer[pos+2]) {
340 printf("\"%40s\" : ",DCT4Tests.Tests[j].Name); 340 printf("\"%40s\" : ",DCT4Tests.Tests[j].Name);
341 switch(msg.Buffer[pos+3]) { 341 switch(msg.Buffer[pos+3]) {
342 case 0x00: printf("Passed"); break; 342 case 0x00: printf("Passed"); break;
343 case 0x01: printf("Fail"); break; 343 case 0x01: printf("Fail"); break;
344 case 0x03: printf("Not executed"); break; 344 case 0x03: printf("Not executed"); break;
345 case 0x06: printf("No signal"); break; 345 case 0x06: printf("No signal"); break;
346 case 0x0D: printf("Timeout"); break; 346 case 0x0D: printf("Timeout"); break;
347 default : printf("Unknown (%x)",msg.Buffer[pos+3]); 347 default : printf("Unknown (%x)",msg.Buffer[pos+3]);
348 } 348 }
349 if (DCT4Tests.Tests[j].Startup) printf(" (startup)"); 349 if (DCT4Tests.Tests[j].Startup) printf(" (startup)");
350 printf("\n"); 350 printf("\n");
351 break; 351 break;
352 } 352 }
353 } 353 }
354 pos+=msg.Buffer[pos+1]; 354 pos+=msg.Buffer[pos+1];
355 } 355 }
356 356
357 return ERR_NONE; 357 return ERR_NONE;
358} 358}
359 359
360void DCT4SelfTests(int argc, char *argv[]) 360void DCT4SelfTests(int argc, char *argv[])
361{ 361{
362 int j; 362 int j;
363 unsigned char GetDoneST[6] = {0x00, 0x08, 0x01, 0x04, 0x01, 0x00}; 363 unsigned char GetDoneST[6] = {0x00, 0x08, 0x01, 0x04, 0x01, 0x00};
364 unsigned char GetDoneST2[6] = {0x00, 0x08, 0x02, 0x04, 0x02, 0x00}; 364 unsigned char GetDoneST2[6] = {0x00, 0x08, 0x02, 0x04, 0x02, 0x00};
365 unsigned char GetNames[6] = {0x00, 0x08, 0x03, 0x06, 0x03, 0x00}; 365 unsigned char GetNames[6] = {0x00, 0x08, 0x03, 0x06, 0x03, 0x00};
366 unsigned char GetStatus[6] = {0x00, 0x08, 0x04, 0x02, 0x03, 0x00}; 366 unsigned char GetStatus[6] = {0x00, 0x08, 0x04, 0x02, 0x03, 0x00};
367 367
368 unsigned char RunALL[6] = {0x00, 0x06, 0x04, 0x00, 0x03, 0x00}; 368 unsigned char RunALL[6] = {0x00, 0x06, 0x04, 0x00, 0x03, 0x00};
369 369
370 //unsigned char GetID[6] = {0x00, 0x08, 0x00, 0x04, 0x03, 0x00};//tests ID 370 //unsigned char GetID[6] = {0x00, 0x08, 0x00, 0x04, 0x03, 0x00};//tests ID
371 371
372 if (CheckDCT4Only()!=ERR_NONE) return; 372 if (CheckDCT4Only()!=ERR_NONE) return;
373 373
374 s.User.UserReplyFunctions=UserReplyFunctions4; 374 s.User.UserReplyFunctions=UserReplyFunctions4;
375 375
376 if (answer_yes2("Run all tests now ?")) { 376 if (answer_yes2("Run all tests now ?")) {
377 error=GSM_WaitFor (&s, RunALL, 6, 0x35, 4, ID_User1); 377 error=GSM_WaitFor (&s, RunALL, 6, 0x35, 4, ID_User1);
378 Print_Error(error); 378 Print_Error(error);
379 } 379 }
380 380
381 error=GSM_WaitFor (&s, GetNames, 6, 0x35, 4, ID_User1); 381 error=GSM_WaitFor (&s, GetNames, 6, 0x35, 4, ID_User1);
382 Print_Error(error); 382 Print_Error(error);
383 383
384 for (j=0;j<DCT4Tests.Num;j++) DCT4Tests.Tests[j].Startup = false; 384 for (j=0;j<DCT4Tests.Num;j++) DCT4Tests.Tests[j].Startup = false;
385 385
386 error=GSM_WaitFor (&s, GetDoneST, 6, 0x35, 4, ID_User3); 386 error=GSM_WaitFor (&s, GetDoneST, 6, 0x35, 4, ID_User3);
387 Print_Error(error); 387 Print_Error(error);
388 388
389 error=GSM_WaitFor (&s, GetDoneST2, 6, 0x35, 4, ID_User3); 389 error=GSM_WaitFor (&s, GetDoneST2, 6, 0x35, 4, ID_User3);
390 Print_Error(error); 390 Print_Error(error);
391 391
392 error=GSM_WaitFor (&s, GetStatus, 6, 0x35, 4, ID_User2); 392 error=GSM_WaitFor (&s, GetStatus, 6, 0x35, 4, ID_User2);
393 Print_Error(error); 393 Print_Error(error);
394} 394}
395 395
396static GSM_Error DCT4_ReplyVibra(GSM_Protocol_Message msg, GSM_StateMachine *s) 396static GSM_Error DCT4_ReplyVibra(GSM_Protocol_Message msg, GSM_StateMachine *s)
397{ 397{
398#ifdef DEBUG 398#ifdef DEBUG
399 switch (msg.Buffer[3]) { 399 switch (msg.Buffer[3]) {
400 case 0x0D : dbgprintf("Vibra state set OK\n"); break; 400 case 0x0D : dbgprintf("Vibra state set OK\n"); break;
401 case 0x0F : dbgprintf("Vibra power set OK\n"); break; 401 case 0x0F : dbgprintf("Vibra power set OK\n"); break;
402 } 402 }
403#endif 403#endif
404 return ERR_NONE; 404 return ERR_NONE;
405} 405}
406 406
407static GSM_Error DCT4EnableVibra(GSM_StateMachine *s, bool enable) 407static GSM_Error DCT4EnableVibra(GSM_StateMachine *s, bool enable)
408{ 408{
409 /* Enables or disables vibra */ 409 /* Enables or disables vibra */
410 unsigned char Control[6] = {N7110_FRAME_HEADER,0x0C, 410 unsigned char Control[6] = {N7110_FRAME_HEADER,0x0C,
411 0x01, /* 0x01 = On, 0x00 = Off */ 411 0x01, /* 0x01 = On, 0x00 = Off */
412 0x00}; 412 0x00};
413 413
414 if (!enable) Control[4] = 0x00; 414 if (!enable) Control[4] = 0x00;
415 return GSM_WaitFor (s, Control, 6, 0x1C, 4, ID_User3); 415 return GSM_WaitFor (s, Control, 6, 0x1C, 4, ID_User3);
416} 416}
417 417
418void DCT4SetVibraLevel(int argc, char *argv[]) 418void DCT4SetVibraLevel(int argc, char *argv[])
419{ 419{
420 GSM_DateTimeDate; 420 GSM_DateTimeDate;
421 unsigned inti,j; 421 unsigned inti,j;
422 422
423 /* Set vibra level */ 423 /* Set vibra level */
424 unsigned char SetLevel[6] = {N7110_FRAME_HEADER,0x0E, 424 unsigned char SetLevel[6] = {N7110_FRAME_HEADER,0x0E,
425 0x64,/* Vibra power (in percent) */ 425 0x64,/* Vibra power (in percent) */
426 0x00}; 426 0x00};
427 427
428 GSM_Init(true); 428 GSM_Init(true);
429 429
430 CheckDCT4(); 430 CheckDCT4();
431 431
432 s.User.UserReplyFunctions=UserReplyFunctions4; 432 s.User.UserReplyFunctions=UserReplyFunctions4;
433 433
434 SetLevel[4] = atoi(argv[2]); 434 SetLevel[4] = atoi(argv[2]);
435 error=GSM_WaitFor (&s, SetLevel, 6, 0x1C, 4, ID_User3); 435 error=GSM_WaitFor (&s, SetLevel, 6, 0x1C, 4, ID_User3);
436 Print_Error(error); 436 Print_Error(error);
437 437
438 error=DCT4EnableVibra(&s, true); 438 error=DCT4EnableVibra(&s, true);
439 Print_Error(error); 439 Print_Error(error);
440 440
441 for (i=0;i<3;i++) { 441 for (i=0;i<3;i++) {
442 GSM_GetCurrentDateTime (&Date); 442 GSM_GetCurrentDateTime (&Date);
443 j=Date.Second; 443 j=Date.Second;
444 while (j==Date.Second) { 444 while (j==Date.Second) {
445 my_sleep(10); 445 my_sleep(10);
446 GSM_GetCurrentDateTime(&Date); 446 GSM_GetCurrentDateTime(&Date);
447 } 447 }
448 } 448 }
449 449
450 error=DCT4EnableVibra(&s, false); 450 error=DCT4EnableVibra(&s, false);
451 Print_Error(error); 451 Print_Error(error);
452 452
453 GSM_Terminate(); 453 GSM_Terminate();
454} 454}
455 455
456void DCT4VibraTest(int argc, char *argv[]) 456void DCT4VibraTest(int argc, char *argv[])
457{ 457{
458 unsigned char ans[200]; 458 unsigned char ans[200];
459 459
460 if (CheckDCT4Only()!=ERR_NONE) return; 460 if (CheckDCT4Only()!=ERR_NONE) return;
461 461
462 s.User.UserReplyFunctions=UserReplyFunctions4; 462 s.User.UserReplyFunctions=UserReplyFunctions4;
463 463
464 error=DCT4EnableVibra(&s, true); 464 error=DCT4EnableVibra(&s, true);
465 Print_Error(error); 465 Print_Error(error);
466 466
467 printf("Press any key to continue...\n"); 467 printf("Press any key to continue...\n");
468 GetLine(stdin, ans, 99); 468 GetLine(stdin, ans, 99);
469 469
470 error=DCT4EnableVibra(&s, false); 470 error=DCT4EnableVibra(&s, false);
471 Print_Error(error); 471 Print_Error(error);
472} 472}
473 473
474#ifdef DEBUG 474#ifdef DEBUG
475static GSM_Error DCT4_ReplyResetSecurityCode(GSM_Protocol_Message msg, GSM_StateMachine *s) 475static GSM_Error DCT4_ReplyResetSecurityCode(GSM_Protocol_Message msg, GSM_StateMachine *s)
476{ 476{
477 switch (msg.Buffer[3]) { 477 switch (msg.Buffer[3]) {
478 case 0x05: 478 case 0x05:
479 printf("Security code set to \"12345\"\n"); 479 printf("Security code set to \"12345\"\n");
480 return ERR_NONE; 480 return ERR_NONE;
481 case 0x06: 481 case 0x06:
482 printf("Unknown reason. Can't reset your security code\n"); 482 printf("Unknown reason. Can't reset your security code\n");
483 return ERR_UNKNOWN; 483 return ERR_UNKNOWN;
484 } 484 }
485 return ERR_UNKNOWNRESPONSE; 485 return ERR_UNKNOWNRESPONSE;
486} 486}
487 487
488void DCT4ResetSecurityCode(int argc, char *argv[]) 488void DCT4ResetSecurityCode(int argc, char *argv[])
489{ 489{
490 unsigned inti; 490 unsigned inti;
491 unsigned char ResetCode[30] = {0x00,0x06,0x03,0x04,0x01, 491 unsigned char ResetCode[30] = {0x00,0x06,0x03,0x04,0x01,
492 '1','2','3','4','5','6','7','8','9','0',/* Old code */ 492 '1','2','3','4','5','6','7','8','9','0',/* Old code */
493 0x00, 493 0x00,
494 '1','2','3','4','5',0x00,0x00,0x00,0x00,0x00, /* New code */ 494 '1','2','3','4','5',0x00,0x00,0x00,0x00,0x00, /* New code */
495 0x00}; 495 0x00};
496 496
497 if (CheckDCT4Only()!=ERR_NONE) return; 497 if (CheckDCT4Only()!=ERR_NONE) return;
498 498
499 s.User.UserReplyFunctions=UserReplyFunctions4; 499 s.User.UserReplyFunctions=UserReplyFunctions4;
500 500
501 error=GSM_WaitFor (&s, ResetCode, 27, 0x08, 4, ID_User2); 501 error=GSM_WaitFor (&s, ResetCode, 27, 0x08, 4, ID_User2);
502 if (error == ERR_UNKNOWN) { 502 if (error == ERR_UNKNOWN) {
503 if (answer_yes2("Try brutal force ?")) { 503 if (answer_yes2("Try brutal force ?")) {
504 for (i=10000;i<9999999;i++) { 504 for (i=10000;i<9999999;i++) {
505 printf("Trying %i\n",i); 505 printf("Trying %i\n",i);
506 memset(ResetCode+6,0,22); 506 memset(ResetCode+6,0,22);
507 sprintf(ResetCode+5,"%i",i); 507 sprintf(ResetCode+5,"%i",i);
508 sprintf(ResetCode+16,"12345"); 508 sprintf(ResetCode+16,"12345");
509 error=GSM_WaitFor (&s, ResetCode, 27, 0x08, 4, ID_User2); 509 error=GSM_WaitFor (&s, ResetCode, 27, 0x08, 4, ID_User2);
510 if (error == ERR_NONE) break; 510 if (error == ERR_NONE) break;
511 } 511 }
512 } 512 }
513 } else Print_Error(error); 513 } else Print_Error(error);
514} 514}
515#endif 515#endif
516 516
517char SecLength; 517char SecLength;
518 518
519static GSM_Error DCT4_ReplyGetSecurityCode(GSM_Protocol_Message msg, GSM_StateMachine *s) 519static GSM_Error DCT4_ReplyGetSecurityCode(GSM_Protocol_Message msg, GSM_StateMachine *s)
520{ 520{
521 if (msg.Length > 12) { 521 if (msg.Length > 12) {
522 SecLength = msg.Buffer[13]; 522 SecLength = msg.Buffer[13];
523 if ((msg.Buffer[17]+18) == msg.Length) { 523 if ((msg.Buffer[17]+18) == msg.Length) {
524 printf("Security code is %s\n",msg.Buffer+18); 524 printf("Security code is %s\n",msg.Buffer+18);
525 // DumpMessage(stdout, msg.Buffer, msg.Length); 525 // DumpMessage(stdout, msg.Buffer, msg.Length);
526 } 526 }
527 } 527 }
528 return ERR_NONE; 528 return ERR_NONE;
529} 529}
530 530
531void DCT4GetSecurityCode(int argc, char *argv[]) 531void DCT4GetSecurityCode(int argc, char *argv[])
532{ 532{
533 GSM_Error error; 533 GSM_Error error;
534 unsigned char getlen[]={0x00, 0x08, 0x01, 0x0C, 534 unsigned char getlen[]={0x00, 0x08, 0x01, 0x0C,
535 0x00, 0x23, //ID 535 0x00, 0x23, //ID
536 0x00, 0x00, //Index 536 0x00, 0x00, //Index
537 0x00, 0x00}; 537 0x00, 0x00};
538 unsigned char read[]={0x00, 0x08, 0x02, 0x04, 538 unsigned char read[]={0x00, 0x08, 0x02, 0x04,
539 0x00, 0x23, //ID 539 0x00, 0x23, //ID
540 0x00, 0x00, //Index 540 0x00, 0x00, //Index
541 0x00, 0x00, 0x00, 0x00, 0x00, 541 0x00, 0x00, 0x00, 0x00, 0x00,
542 0x00, 0x00, 0x00, 0x00, 542 0x00, 0x00, 0x00, 0x00,
543 0x00}; //Length 543 0x00}; //Length
544 544
545 if (CheckDCT4Only()!=ERR_NONE) return; 545 if (CheckDCT4Only()!=ERR_NONE) return;
546 546
547 s.User.UserReplyFunctions=UserReplyFunctions4; 547 s.User.UserReplyFunctions=UserReplyFunctions4;
548 548
549 SecLength = 0; 549 SecLength = 0;
550 error=GSM_WaitFor (&s, getlen, sizeof(getlen), 0x23, 1, ID_User1); 550 error=GSM_WaitFor (&s, getlen, sizeof(getlen), 0x23, 1, ID_User1);
551 Print_Error(error); 551 Print_Error(error);
552 if (SecLength != 0) { 552 if (SecLength != 0) {
553 read[17] = SecLength; 553 read[17] = SecLength;
554 error=GSM_WaitFor (&s, read, sizeof(read), 0x23, 5, ID_User1); 554 error=GSM_WaitFor (&s, read, sizeof(read), 0x23, 5, ID_User1);
555 Print_Error(error); 555 Print_Error(error);
556 } 556 }
557} 557}
558 558
559static GSM_Error DCT4_ReplyGetVoiceRecord(GSM_Protocol_Message msg, GSM_StateMachine *s) 559static GSM_Error DCT4_ReplyGetVoiceRecord(GSM_Protocol_Message msg, GSM_StateMachine *s)
560{ 560{
561 int i=18,j; 561 int i=18,j;
562 unsigned charBuffer[100]; 562 unsigned charBuffer[100];
563 563
564 switch (msg.Buffer[3]) { 564 switch (msg.Buffer[3]) {
565 case 0x05: 565 case 0x05:
566 dbgprintf("Part of voice record received\n"); 566 dbgprintf("Part of voice record received\n");
567 if (msg.Length == 6) { 567 if (msg.Length == 6) {
568 dbgprintf("Empty\n"); 568 dbgprintf("Empty\n");
569 return ERR_EMPTY; 569 return ERR_EMPTY;
570 } 570 }
571 *s->Phone.Data.VoiceRecord = 0; 571 *s->Phone.Data.VoiceRecord = 0;
572 while (i<msg.Length) { 572 while (i<msg.Length) {
573 s->Phone.Data.PhoneString[(*s->Phone.Data.VoiceRecord)++] = msg.Buffer[i+1]; 573 s->Phone.Data.PhoneString[(*s->Phone.Data.VoiceRecord)++] = msg.Buffer[i+1];
574 s->Phone.Data.PhoneString[(*s->Phone.Data.VoiceRecord)++] = msg.Buffer[i]; 574 s->Phone.Data.PhoneString[(*s->Phone.Data.VoiceRecord)++] = msg.Buffer[i];
575 i += 2; 575 i += 2;
576 } 576 }
577 return ERR_NONE; 577 return ERR_NONE;
578 case 0x0D: 578 case 0x0D:
579 dbgprintf("Last part of voice record is %02x %02x\n",msg.Buffer[11],msg.Buffer[12]); 579 dbgprintf("Last part of voice record is %02x %02x\n",msg.Buffer[11],msg.Buffer[12]);
580 dbgprintf("Token is %02x\n",msg.Buffer[13]); 580 dbgprintf("Token is %02x\n",msg.Buffer[13]);
581 s->Phone.Data.PhoneString[0] = msg.Buffer[11]; 581 s->Phone.Data.PhoneString[0] = msg.Buffer[11];
582 s->Phone.Data.PhoneString[1] = msg.Buffer[12]; 582 s->Phone.Data.PhoneString[1] = msg.Buffer[12];
583 s->Phone.Data.PhoneString[2] = msg.Buffer[13]; 583 s->Phone.Data.PhoneString[2] = msg.Buffer[13];
584 return ERR_NONE; 584 return ERR_NONE;
585 break; 585 break;
586 case 0x31: 586 case 0x31:
587 dbgprintf("Names of voice records received\n"); 587 dbgprintf("Names of voice records received\n");
588 j = 33; 588 j = 33;
589 for (i=0;i<msg.Buffer[9];i++) { 589 for (i=0;i<msg.Buffer[9];i++) {
590 memcpy(Buffer,msg.Buffer+(j+1),msg.Buffer[j]); 590 memcpy(Buffer,msg.Buffer+(j+1),msg.Buffer[j]);
591 Buffer[msg.Buffer[j]] = 0; 591 Buffer[msg.Buffer[j]] = 0;
592 Buffer[msg.Buffer[j]+1] = 0; 592 Buffer[msg.Buffer[j]+1] = 0;
593 dbgprintf("%i. \"%s\"\n",i+1,DecodeUnicodeString(Buffer)); 593 dbgprintf("%i. \"%s\"\n",i+1,DecodeUnicodeString(Buffer));
594 if (i==*s->Phone.Data.VoiceRecord) { 594 if (i==*s->Phone.Data.VoiceRecord) {
595 sprintf(s->Phone.Data.PhoneString,"%s.wav",DecodeUnicodeString(Buffer)); 595 sprintf(s->Phone.Data.PhoneString,"%s.wav",DecodeUnicodeString(Buffer));
596 return ERR_NONE; 596 return ERR_NONE;
597 } 597 }
598 if (i != msg.Buffer[9] - 1) { 598 if (i != msg.Buffer[9] - 1) {
599 j+=msg.Buffer[j] + 1; 599 j+=msg.Buffer[j] + 1;
600 if (msg.Buffer[j] == 0x00 && msg.Buffer[j+1]==0x00) j+=2; 600 if (msg.Buffer[j] == 0x00 && msg.Buffer[j+1]==0x00) j+=2;
601 j+=23; 601 j+=23;
602 } 602 }
603 } 603 }
604 return ERR_EMPTY; 604 return ERR_EMPTY;
605 } 605 }
606 return ERR_UNKNOWNRESPONSE; 606 return ERR_UNKNOWNRESPONSE;
607} 607}
608 608
609void DCT4GetVoiceRecord(int argc, char *argv[]) 609void DCT4GetVoiceRecord(int argc, char *argv[])
610{ 610{
611 /* Voice records names */ 611 /* Voice records names */
612 unsigned char ReqNames[200] = { 612 unsigned char ReqNames[200] = {
613 N7110_FRAME_HEADER, 613 N7110_FRAME_HEADER,
614 0x30,0x01,0x55,0x00,0x00,0xFF,0xFF,0x01,0x01,0x55,0x55}; 614 0x30,0x01,0x55,0x00,0x00,0xFF,0xFF,0x01,0x01,0x55,0x55};
615 /* Voice record token */ 615 /* Voice record token */
616 unsigned char ReqToken[200] = { 616 unsigned char ReqToken[200] = {
617 N7110_FRAME_HEADER,0x0C,0x00,0x44,0x00, 617 N7110_FRAME_HEADER,0x0C,0x00,0x44,0x00,
618 0x00, /* Location: 0, 1, ... */ 618 0x00, /* Location: 0, 1, ... */
619 0x55,0x55}; 619 0x55,0x55};
620 /* Voice record part */ 620 /* Voice record part */
621 unsigned char ReqGet[200] = { 621 unsigned char ReqGet[200] = {
622 N7110_FRAME_HEADER,0x04,0x00,0x44, 622 N7110_FRAME_HEADER,0x04,0x00,0x44,
623 0x00,0x00,/* Location: 0, 1, ... */ 623 0x00,0x00,/* Location: 0, 1, ... */
624 0x55,0x55,0x00, 624 0x55,0x55,0x00,
625 625
626 0x00,0x00, /* Part Location*/ 626 0x00,0x00, /* Part Location*/
627 0x00,0x00,0x00, 627 0x00,0x00,0x00,
628 628
629 0x04, /* ??? */ 629 0x04, /* ??? */
630 630
631 0x00}; /* Token */ 631 0x00}; /* Token */
632 632
633 /* WAV file headers */ 633 /* WAV file headers */
634 unsigned char WAV_Header[] = { 634 unsigned char WAV_Header[] = {
635 'R','I','F','F', 635 'R','I','F','F',
636 0x00,0x00,0x00,0x00,/* Length */ 636 0x00,0x00,0x00,0x00,/* Length */
637 'W','A','V','E'}; 637 'W','A','V','E'};
638 unsigned char FMT_Header[] = {'f','m','t',' ', 638 unsigned char FMT_Header[] = {'f','m','t',' ',
639 0x14,0x00,0x00,0x00,0x31,0x00,0x01,0x00,0x40,0x1f, 639 0x14,0x00,0x00,0x00,0x31,0x00,0x01,0x00,0x40,0x1f,
640 0x00,0x00,0x59,0x06,0x00,0x00,0x41,0x00,0x00,0x00, 640 0x00,0x00,0x59,0x06,0x00,0x00,0x41,0x00,0x00,0x00,
641 0x02,0x00,0x40,0x01,'f', 'a', 'c', 't', 0x04,0x00, 641 0x02,0x00,0x40,0x01,'f', 'a', 'c', 't', 0x04,0x00,
642 0x00,0x00, 642 0x00,0x00,
643 0x00,0x73,0x00,0x00};/* Seems to be some length */ 643 0x00,0x73,0x00,0x00};/* Seems to be some length */
644 unsigned char DATA_Header[] = { 644 unsigned char DATA_Header[] = {
645 'd','a','t','a', 645 'd','a','t','a',
646 0x00,0x00,0x00,0x00};/* Length */ 646 0x00,0x00,0x00,0x00};/* Length */
647 647
648 long wavfilesize=0; 648 long wavfilesize=0;
649 unsigned charFileName[100], Buffer[10000], Token; 649 unsigned charFileName[100], Buffer[10000], Token;
650 unsigned int Location, size=0, CurrentLocation = 0, TokenLocation; 650 unsigned int Location, size=0, CurrentLocation = 0, TokenLocation;
651 int i; 651 int i;
652 FILE *WAVFile; 652 FILE *WAVFile;
653 653
654 Location = atoi(argv[2]); 654 Location = atoi(argv[2]);
655 if (Location == 0x00) { 655 if (Location == 0x00) {
656 printf("Please numerate locations from 1\n"); 656 printf("Please numerate locations from 1\n");
657 return; 657 return;
658 } 658 }
659 Location--; 659 Location--;
660 660
661 GSM_Init(true); 661 GSM_Init(true);
662 662
663 CheckDCT4(); 663 CheckDCT4();
664 664
665 s.User.UserReplyFunctions=UserReplyFunctions4; 665 s.User.UserReplyFunctions=UserReplyFunctions4;
666 666
667 s.Phone.Data.VoiceRecord = &Location; 667 s.Phone.Data.VoiceRecord = &Location;
668 s.Phone.Data.PhoneString = FileName; 668 s.Phone.Data.PhoneString = FileName;
669 dbgprintf("Getting voice record name\n"); 669 dbgprintf("Getting voice record name\n");
670 error=GSM_WaitFor (&s, ReqNames, 14, 0x4A, 4, ID_User4); 670 error=GSM_WaitFor (&s, ReqNames, 14, 0x4A, 4, ID_User4);
671 Print_Error(error); 671 Print_Error(error);
672 672
673 s.Phone.Data.PhoneString = Buffer; 673 s.Phone.Data.PhoneString = Buffer;
674 ReqToken[7] = Location; 674 ReqToken[7] = Location;
675 dbgprintf("Getting voice record token\n"); 675 dbgprintf("Getting voice record token\n");
676 error=GSM_WaitFor (&s, ReqToken, 10, 0x23, 4, ID_User4); 676 error=GSM_WaitFor (&s, ReqToken, 10, 0x23, 4, ID_User4);
677 Print_Error(error); 677 Print_Error(error);
678 TokenLocation = Buffer[0] * 256 + Buffer[1]; 678 TokenLocation = Buffer[0] * 256 + Buffer[1];
679 Token = Buffer[2]; 679 Token = Buffer[2];
680 680
681 WAVFile = fopen(FileName, "wb"); 681 WAVFile = fopen(FileName, "wb");
682 682
683 fwrite(&WAV_Header, 1, sizeof(WAV_Header),WAVFile); 683 fwrite(&WAV_Header, 1, sizeof(WAV_Header),WAVFile);
684 fwrite(&FMT_Header, 1, sizeof(FMT_Header),WAVFile); 684 fwrite(&FMT_Header, 1, sizeof(FMT_Header),WAVFile);
685 fwrite(&DATA_Header, 1, sizeof(DATA_Header),WAVFile); 685 fwrite(&DATA_Header, 1, sizeof(DATA_Header),WAVFile);
686 686
687 s.Phone.Data.VoiceRecord = &size; 687 s.Phone.Data.VoiceRecord = &size;
688 s.Phone.Data.PhoneString = Buffer; 688 s.Phone.Data.PhoneString = Buffer;
689 ReqGet[7] = Location; 689 ReqGet[7] = Location;
690 fprintf(stderr,"Getting voice record and saving to \"%s\": ",FileName); 690 fprintf(stderr,"Getting voice record and saving to \"%s\": ",FileName);
691 while (1) { 691 while (1) {
692 dbgprintf("Getting next part of voice record\n"); 692 dbgprintf("Getting next part of voice record\n");
693 fprintf(stderr,"."); 693 fprintf(stderr,".");
694 error=GSM_WaitFor (&s, ReqGet, 18, 0x23, 4, ID_User4); 694 error=GSM_WaitFor (&s, ReqGet, 18, 0x23, 4, ID_User4);
695 if (error == ERR_NONE) { 695 if (error == ERR_NONE) {
696 wavfilesize += size; 696 wavfilesize += size;
697 fwrite(Buffer,1,size,WAVFile); 697 fwrite(Buffer,1,size,WAVFile);
698 } 698 }
699 if (error == ERR_EMPTY) break; 699 if (error == ERR_EMPTY) break;
700 Print_Error(error); 700 Print_Error(error);
701 CurrentLocation += 4; 701 CurrentLocation += 4;
702 ReqGet[11] = CurrentLocation / 256; 702 ReqGet[11] = CurrentLocation / 256;
703 ReqGet[12] = CurrentLocation % 256; 703 ReqGet[12] = CurrentLocation % 256;
704 if (CurrentLocation+4 > TokenLocation) break; 704 if (CurrentLocation+4 > TokenLocation) break;
705 } 705 }
706 dbgprintf("Getting first part in last sequence of voice record\n"); 706 dbgprintf("Getting first part in last sequence of voice record\n");
707 for (i=255;i>=0;i--) { 707 for (i=255;i>=0;i--) {
708 ReqGet[16] = i; 708 ReqGet[16] = i;
709 ReqGet[17] = Token; 709 ReqGet[17] = Token;
710 fprintf(stderr,"."); 710 fprintf(stderr,".");
711 error=GSM_WaitFor (&s, ReqGet, 18, 0x23, 4, ID_User4); 711 error=GSM_WaitFor (&s, ReqGet, 18, 0x23, 4, ID_User4);
712 if (error == ERR_NONE) { 712 if (error == ERR_NONE) {
713 wavfilesize += size; 713 wavfilesize += size;
714 fwrite(Buffer,1,size,WAVFile); 714 fwrite(Buffer,1,size,WAVFile);
715 break; 715 break;
716 } 716 }
717 if (error != ERR_EMPTY) Print_Error(error); 717 if (error != ERR_EMPTY) Print_Error(error);
718 } 718 }
719 while (1) { 719 while (1) {
720 dbgprintf("Getting next part of last sequence in voice record\n"); 720 dbgprintf("Getting next part of last sequence in voice record\n");
721 CurrentLocation += 4; 721 CurrentLocation += 4;
722 ReqGet[11] = CurrentLocation / 256; 722 ReqGet[11] = CurrentLocation / 256;
723 ReqGet[12] = CurrentLocation % 256; 723 ReqGet[12] = CurrentLocation % 256;
724 fprintf(stderr,"."); 724 fprintf(stderr,".");
725 error=GSM_WaitFor (&s, ReqGet, 18, 0x23, 4, ID_User4); 725 error=GSM_WaitFor (&s, ReqGet, 18, 0x23, 4, ID_User4);
726 if (error == ERR_NONE) { 726 if (error == ERR_NONE) {
727 wavfilesize += size; 727 wavfilesize += size;
728 fwrite(Buffer,1,size,WAVFile); 728 fwrite(Buffer,1,size,WAVFile);
729 } 729 }
730 if (error == ERR_EMPTY) break; 730 if (error == ERR_EMPTY) break;
731 Print_Error(error); 731 Print_Error(error);
732 } 732 }
733 fprintf(stderr,"\n"); 733 fprintf(stderr,"\n");
734 734
735 wavfilesize += sizeof(WAV_Header) + sizeof(FMT_Header) + sizeof(DATA_Header); 735 wavfilesize += sizeof(WAV_Header) + sizeof(FMT_Header) + sizeof(DATA_Header);
736 WAV_Header[4] = (unsigned char)(wavfilesize % 256); 736 WAV_Header[4] = (unsigned char)(wavfilesize % 256);
737 WAV_Header[5] = (unsigned char)(wavfilesize / 256); 737 WAV_Header[5] = (unsigned char)(wavfilesize / 256);
738 WAV_Header[6] = (unsigned char)(wavfilesize / (256*256)); 738 WAV_Header[6] = (unsigned char)(wavfilesize / (256*256));
739 WAV_Header[7] = (unsigned char)(wavfilesize / (256*256*256)); 739 WAV_Header[7] = (unsigned char)(wavfilesize / (256*256*256));
740 740
741 /* FIXME */ 741 /* FIXME */
742 FMT_Header[36]= (unsigned char)(((wavfilesize - 238) * 5 ) % 256); 742 FMT_Header[36]= (unsigned char)(((wavfilesize - 238) * 5 ) % 256);
743 FMT_Header[37]= (unsigned char)(((wavfilesize - 238) * 5 ) / 256); 743 FMT_Header[37]= (unsigned char)(((wavfilesize - 238) * 5 ) / 256);
744 FMT_Header[38]= (unsigned char)(((wavfilesize - 238) * 5 ) / (256*256)); 744 FMT_Header[38]= (unsigned char)(((wavfilesize - 238) * 5 ) / (256*256));
745 FMT_Header[39]= (unsigned char)(((wavfilesize - 238) * 5 ) / (256*256*256)); 745 FMT_Header[39]= (unsigned char)(((wavfilesize - 238) * 5 ) / (256*256*256));
746 746
747 wavfilesize = wavfilesize - 54 - 6; 747 wavfilesize = wavfilesize - 54 - 6;
748 DATA_Header[4] = (unsigned char)(wavfilesize % 256); 748 DATA_Header[4] = (unsigned char)(wavfilesize % 256);
749 DATA_Header[5] = (unsigned char)(wavfilesize / 256); 749 DATA_Header[5] = (unsigned char)(wavfilesize / 256);
750 DATA_Header[6] = (unsigned char)(wavfilesize / (256*256)); 750 DATA_Header[6] = (unsigned char)(wavfilesize / (256*256));
751 DATA_Header[7] = (unsigned char)(wavfilesize / (256*256*256)); 751 DATA_Header[7] = (unsigned char)(wavfilesize / (256*256*256));
752 752
753 fseek( WAVFile, 0, SEEK_SET); 753 fseek( WAVFile, 0, SEEK_SET);
754 fwrite(&WAV_Header, 1, sizeof(WAV_Header),WAVFile); 754 fwrite(&WAV_Header, 1, sizeof(WAV_Header),WAVFile);
755 fwrite(&FMT_Header, 1, sizeof(FMT_Header),WAVFile); 755 fwrite(&FMT_Header, 1, sizeof(FMT_Header),WAVFile);
756 fwrite(&DATA_Header, 1, sizeof(DATA_Header),WAVFile); 756 fwrite(&DATA_Header, 1, sizeof(DATA_Header),WAVFile);
757 757
758 fclose(WAVFile); 758 fclose(WAVFile);
759 759
760 GSM_Terminate(); 760 GSM_Terminate();
761} 761}
762 762
763static GSM_Error DCT4_ReplyGetBTInfo(GSM_Protocol_Message msg, GSM_StateMachine *s) 763static GSM_Error DCT4_ReplyGetBTInfo(GSM_Protocol_Message msg, GSM_StateMachine *s)
764{ 764{
765 printf("device address %02x%02x%02x%02x%02x%02x\n", 765 printf("device address %02x%02x%02x%02x%02x%02x\n",
766 msg.Buffer[9],msg.Buffer[10],msg.Buffer[11], 766 msg.Buffer[9],msg.Buffer[10],msg.Buffer[11],
767 msg.Buffer[12],msg.Buffer[13],msg.Buffer[14]); 767 msg.Buffer[12],msg.Buffer[13],msg.Buffer[14]);
768 return ERR_NONE; 768 return ERR_NONE;
769} 769}
770 770
771static GSM_Error DCT4_ReplyGetSimlock(GSM_Protocol_Message msg, GSM_StateMachine *s) 771static GSM_Error DCT4_ReplyGetSimlock(GSM_Protocol_Message msg, GSM_StateMachine *s)
772{ 772{
773 int i; 773 int i;
774 774
775 switch (msg.Buffer[3]) { 775 switch (msg.Buffer[3]) {
776 case 0x0D: 776 case 0x0D:
777 dbgprintf("Simlock info received\n"); 777 dbgprintf("Simlock info received\n");
778 dbgprintf("Config_Data: "); 778 dbgprintf("Config_Data: ");
779 for (i=14;i<22;i++) { 779 for (i=14;i<22;i++) {
780 dbgprintf("%02x",msg.Buffer[i]); 780 dbgprintf("%02x",msg.Buffer[i]);
781 } 781 }
782 dbgprintf("\n"); 782 dbgprintf("\n");
783 dbgprintf("Profile_Bits: "); 783 dbgprintf("Profile_Bits: ");
784 for (i=22;i<30;i++) { 784 for (i=22;i<30;i++) {
diff --git a/gammu/emb/gammu/depend/siemens/dsiemens.c b/gammu/emb/gammu/depend/siemens/dsiemens.c
index dc54102..a34bc3b 100644
--- a/gammu/emb/gammu/depend/siemens/dsiemens.c
+++ b/gammu/emb/gammu/depend/siemens/dsiemens.c
@@ -1,363 +1,363 @@
1/* (c) by Walek */ 1/* (c) by Walek */
2 2
3#include "../../../common/gsmstate.h" 3#include "../../../common/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 8
9#include "../../../common/misc/coding/coding.h" 9#include "../../../common/misc/coding/coding.h"
10#include "../../../common/gsmcomon.h" 10#include "../../../common/gsmcomon.h"
11#include "../../../common/service/gsmnet.h" 11#include "../../../common/service/gsmnet.h"
12#include "../../../common/phone/at/atgen.h" 12#include "../../../common/phone/at/atgen.h"
13#include "../../gammu.h" 13#include "../../gammu.h"
14#include "dsiemens.h" 14#include "dsiemens.h"
15#include "chiffre.h" 15#include "chiffre.h"
16 16
17extern GSM_Error ATGEN_GetSIMIMSI (GSM_StateMachine *s, char *IMSI); 17extern GSM_Error ATGEN_GetSIMIMSI (GSM_StateMachine *s, char *IMSI);
18extern GSM_Error ATGEN_GetMemoryStatus (GSM_StateMachine *s, GSM_MemoryStatus *status); 18extern GSM_Error ATGEN_GetMemoryStatus (GSM_StateMachine *s, GSM_MemoryStatus *status);
19extern GSM_Error ATGEN_SetMemory (GSM_StateMachine *s, GSM_MemoryEntry *pbk); 19extern GSM_Error ATGEN_SetMemory (GSM_StateMachine *s, GSM_MemoryEntry *pbk);
20extern GSM_Reply_Function UserReplyFunctionsAtS[]; 20static GSM_Reply_Function UserReplyFunctionsAtS[];
21 21
22 bool new_variable; 22 bool new_variable;
23GSM_Error CheckSiemens() 23GSM_Error CheckSiemens()
24{ 24{
25 if (s.Phone.Data.Priv.ATGEN.Manufacturer != AT_Siemens) return ERR_NOTSUPPORTED; 25 if (s.Phone.Data.Priv.ATGEN.Manufacturer != AT_Siemens) return ERR_NOTSUPPORTED;
26 return ERR_NONE; 26 return ERR_NONE;
27} 27}
28 28
29GSM_Error ATSIEMENS_Reply_GetSAT(GSM_Protocol_Message msg, GSM_StateMachine *s) 29GSM_Error ATSIEMENS_Reply_GetSAT(GSM_Protocol_Message msg, GSM_StateMachine *s)
30{ 30{
31 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN; 31 GSM_Phone_ATGENData *Priv = &s->Phone.Data.Priv.ATGEN;
32 GSM_SAT_Measure_results MeasureResult; 32 GSM_SAT_Measure_results MeasureResult;
33 unsigned char buf[256]; 33 unsigned char buf[256];
34 int length,i,rep,ChNo=1,j=0,result=0,origARFCN=0; 34 int length,i,rep,ChNo=1,j=0,result=0,origARFCN=0;
35 int freq_tmp,frequency[24]; 35 int freq_tmp,frequency[24];
36 GSM_NetworkInfo Network; 36 GSM_NetworkInfo Network;
37 37
38 if (Priv->ReplyState!=AT_Reply_OK) return ERR_UNKNOWN; 38 if (Priv->ReplyState!=AT_Reply_OK) return ERR_UNKNOWN;
39 if (s->Protocol.Data.AT.EditMode) s->Protocol.Data.AT.EditMode = false; 39 if (s->Protocol.Data.AT.EditMode) s->Protocol.Data.AT.EditMode = false;
40 if (strstr(GetLineString(msg.Buffer,Priv->Lines,2),"SSTK")) { 40 if (strstr(GetLineString(msg.Buffer,Priv->Lines,2),"SSTK")) {
41 length = strlen(GetLineString(msg.Buffer,Priv->Lines,2))-7; 41 length = strlen(GetLineString(msg.Buffer,Priv->Lines,2))-7;
42 DecodeHexBin(buf, GetLineString(msg.Buffer,Priv->Lines,2)+7,length); 42 DecodeHexBin(buf, GetLineString(msg.Buffer,Priv->Lines,2)+7,length);
43 if (buf[0]==0x7f) { 43 if (buf[0]==0x7f) {
44 new_variable=true; 44 new_variable=true;
45 return ERR_NONE; 45 return ERR_NONE;
46 } 46 }
47 else return ERR_UNKNOWN; 47 else return ERR_UNKNOWN;
48 } 48 }
49 if (!strstr(GetLineString(msg.Buffer,Priv->Lines,3),"SSTK")) return ERR_UNKNOWN; 49 if (!strstr(GetLineString(msg.Buffer,Priv->Lines,3),"SSTK")) return ERR_UNKNOWN;
50 50
51 length = strlen(GetLineString(msg.Buffer,Priv->Lines,3))-7; 51 length = strlen(GetLineString(msg.Buffer,Priv->Lines,3))-7;
52 DecodeHexBin(buf, GetLineString(msg.Buffer,Priv->Lines,3)+7,length); 52 DecodeHexBin(buf, GetLineString(msg.Buffer,Priv->Lines,3)+7,length);
53 53
54 if (buf[3]!=0x26) return ERR_UNKNOWN; 54 if (buf[3]!=0x26) return ERR_UNKNOWN;
55 55
56#ifdef DEBUG 56#ifdef DEBUG
57 dbgprintf ("SAT command: Provide Local Information\nFunction: "); 57 dbgprintf ("SAT command: Provide Local Information\nFunction: ");
58 switch (buf[4]) { 58 switch (buf[4]) {
59 case 00: dbgprintf ("Loc Info\n"); break; 59 case 00: dbgprintf ("Loc Info\n"); break;
60 case 01: dbgprintf ("IMEI\n"); break; 60 case 01: dbgprintf ("IMEI\n"); break;
61 case 02: dbgprintf ("Network Measure\n"); break; 61 case 02: dbgprintf ("Network Measure\n"); break;
62 case 03: dbgprintf ("Date time and timezone\n");break; 62 case 03: dbgprintf ("Date time and timezone\n");break;
63 case 04: dbgprintf ("Language setting\n"); break; 63 case 04: dbgprintf ("Language setting\n"); break;
64 case 05: dbgprintf ("Timing advance\n"); break; 64 case 05: dbgprintf ("Timing advance\n"); break;
65 } 65 }
66#endif 66#endif
67 /* Loc Info (MCC, MNC, LAC, Cell ID) */ 67 /* Loc Info (MCC, MNC, LAC, Cell ID) */
68 if (buf[4]==00) { 68 if (buf[4]==00) {
69 DecodeBCD (Network.NetworkCode,buf+14,2); 69 DecodeBCD (Network.NetworkCode,buf+14,2);
70 Network.NetworkCode[3] = ' '; 70 Network.NetworkCode[3] = ' ';
71 DecodeBCD (Network.NetworkCode+4,buf+16,1); 71 DecodeBCD (Network.NetworkCode+4,buf+16,1);
72 EncodeHexBin (Network.LAC,buf+17,2); 72 EncodeHexBin (Network.LAC,buf+17,2);
73 EncodeHexBin (Network.CID,buf+19,2); 73 EncodeHexBin (Network.CID,buf+19,2);
74 74
75 printf(" Network code : %s\n",Network.NetworkCode); 75 printf(" Network code : %s\n",Network.NetworkCode);
76 printf(" Network name for Gammu : %s\n", 76 printf(" Network name for Gammu : %s\n",
77 DecodeUnicodeString(GSM_GetNetworkName(Network.NetworkCode))); 77 DecodeUnicodeString(GSM_GetNetworkName(Network.NetworkCode)));
78 printf(" CID : %s\n",Network.CID); 78 printf(" CID : %s\n",Network.CID);
79 printf(" LAC : %s\n",Network.LAC); 79 printf(" LAC : %s\n",Network.LAC);
80 } 80 }
81 81
82 /* Network Measure */ 82 /* Network Measure */
83 if (buf[4]==02) { 83 if (buf[4]==02) {
84 84
85 for (i=0;i<24;i++) frequency[i]=0; 85 for (i=0;i<24;i++) frequency[i]=0;
86 if (!new_variable) { 86 if (!new_variable) {
87 GetBufferI(buf+32,&j,&result,7); 87 GetBufferI(buf+32,&j,&result,7);
88 result &= 0x67; 88 result &= 0x67;
89 if (result !=0x47) return ERR_NOTSUPPORTED; 89 if (result !=0x47) return ERR_NOTSUPPORTED;
90 } 90 }
91#ifdef DEBUG 91#ifdef DEBUG
92 if (new_variable)dbgprintf ("New variable Bitmap format\n"); 92 if (new_variable)dbgprintf ("New variable Bitmap format\n");
93 else dbgprintf ("Old variable Bitmap format\n"); 93 else dbgprintf ("Old variable Bitmap format\n");
94#endif 94#endif
95 GetBufferI(buf+32,&j,&origARFCN,10); 95 GetBufferI(buf+32,&j,&origARFCN,10);
96 /* 10 bit origin ARFCN or first frequency (new variable format) */ 96 /* 10 bit origin ARFCN or first frequency (new variable format) */
97#ifdef DEBUG 97#ifdef DEBUG
98 dbgprintf("Origin BCCH = %i\n",origARFCN); 98 dbgprintf("Origin BCCH = %i\n",origARFCN);
99#endif 99#endif
100 rep = buf[31]*8; 100 rep = buf[31]*8;
101 if (!new_variable ){ 101 if (!new_variable ){
102 for (i=0;i<rep;i++){ 102 for (i=0;i<rep;i++){
103 result = 0; 103 result = 0;
104 GetBufferI(buf+32,&j,&result,1); 104 GetBufferI(buf+32,&j,&result,1);
105 if (result) { 105 if (result) {
106 frequency[ChNo]=i+origARFCN+1; 106 frequency[ChNo]=i+origARFCN+1;
107 ChNo++; 107 ChNo++;
108 } 108 }
109 } 109 }
110 } 110 }
111 else { 111 else {
112 frequency[ChNo++]=origARFCN; 112 frequency[ChNo++]=origARFCN;
113 for (i=0; i<rep; i+=10){ 113 for (i=0; i<rep; i+=10){
114 result = 0; 114 result = 0;
115 GetBufferI(buf+32,&j,&result,10); 115 GetBufferI(buf+32,&j,&result,10);
116 if (!result) break; 116 if (!result) break;
117 frequency[ChNo++]=result; 117 frequency[ChNo++]=result;
118 } 118 }
119 j=1; 119 j=1;
120 while (j) { 120 while (j) {
121 j=0; 121 j=0;
122 for (i=0; i<ChNo-1; i++){ 122 for (i=0; i<ChNo-1; i++){
123 if (frequency[i] > frequency[i+1]){ 123 if (frequency[i] > frequency[i+1]){
124 freq_tmp=frequency[i]; 124 freq_tmp=frequency[i];
125 frequency[i]=frequency[i+1]; 125 frequency[i]=frequency[i+1];
126 frequency[i+1]=freq_tmp; 126 frequency[i+1]=freq_tmp;
127 j=1; 127 j=1;
128 } 128 }
129 } 129 }
130 } 130 }
131 }; 131 };
132#ifdef DEBUG 132#ifdef DEBUG
133 dbgprintf("Neighbor BCCH list: "); 133 dbgprintf("Neighbor BCCH list: ");
134 for (i=1;i<ChNo;i++) dbgprintf ("%d ",frequency[i]); 134 for (i=1;i<ChNo;i++) dbgprintf ("%d ",frequency[i]);
135 dbgprintf ("\n"); 135 dbgprintf ("\n");
136#endif 136#endif
137 j= 0; 137 j= 0;
138 result= 0; 138 result= 0;
139 GetBufferI(buf+14,&j,&result,1); 139 GetBufferI(buf+14,&j,&result,1);
140 if (result) MeasureResult.BA_used=true; 140 if (result) MeasureResult.BA_used=true;
141 else MeasureResult.BA_used=false; 141 else MeasureResult.BA_used=false;
142 142
143 result= 0; 143 result= 0;
144 GetBufferI(buf+14,&j,&result,1); 144 GetBufferI(buf+14,&j,&result,1);
145 if (result) MeasureResult.DTX_used=true; 145 if (result) MeasureResult.DTX_used=true;
146 else MeasureResult.DTX_used=false; 146 else MeasureResult.DTX_used=false;
147 147
148 result= 0; 148 result= 0;
149 GetBufferI(buf+14,&j,&result,6); 149 GetBufferI(buf+14,&j,&result,6);
150 MeasureResult.RXLEV_FullServicingCell=result-110; 150 MeasureResult.RXLEV_FullServicingCell=result-110;
151 151
152 j++;//skip spare bit 152 j++;//skip spare bit
153 result= 0; 153 result= 0;
154 GetBufferI(buf+14,&j,&result,1); 154 GetBufferI(buf+14,&j,&result,1);
155 if (result) MeasureResult.MeasValid=true; 155 if (result) MeasureResult.MeasValid=true;
156 else MeasureResult.MeasValid=false; 156 else MeasureResult.MeasValid=false;
157 157
158 result= 0; 158 result= 0;
159 GetBufferI(buf+14,&j,&result,6); 159 GetBufferI(buf+14,&j,&result,6);
160 MeasureResult.RXLEV_SubServicingCell=result-110; 160 MeasureResult.RXLEV_SubServicingCell=result-110;
161 161
162 j++;//skip spare bit 162 j++;//skip spare bit
163 result= 0; 163 result= 0;
164 GetBufferI(buf+14,&j,&result,3); 164 GetBufferI(buf+14,&j,&result,3);
165 MeasureResult.RXQUAL_FullServicingCell=result; 165 MeasureResult.RXQUAL_FullServicingCell=result;
166 166
167 result= 0; 167 result= 0;
168 GetBufferI(buf+14,&j,&result,3); 168 GetBufferI(buf+14,&j,&result,3);
169 MeasureResult.RXQUAL_SubServicingCell=result; 169 MeasureResult.RXQUAL_SubServicingCell=result;
170 170
171 printf ("RX Level FULL Servicing Cell = %i\n",MeasureResult.RXLEV_FullServicingCell); 171 printf ("RX Level FULL Servicing Cell = %i\n",MeasureResult.RXLEV_FullServicingCell);
172 printf ("RX Level Sub Servicing Cell = %i\n",MeasureResult.RXLEV_FullServicingCell); 172 printf ("RX Level Sub Servicing Cell = %i\n",MeasureResult.RXLEV_FullServicingCell);
173 173
174 printf ("RX Quality Full Servicing Cell = %i\n",MeasureResult.RXQUAL_FullServicingCell); 174 printf ("RX Quality Full Servicing Cell = %i\n",MeasureResult.RXQUAL_FullServicingCell);
175 printf ("RX Quality Sub Servicing Cell = %i\n",MeasureResult.RXQUAL_SubServicingCell); 175 printf ("RX Quality Sub Servicing Cell = %i\n",MeasureResult.RXQUAL_SubServicingCell);
176 176
177 result= 0; 177 result= 0;
178 GetBufferI(buf+14,&j,&result,3); 178 GetBufferI(buf+14,&j,&result,3);
179 MeasureResult.NO_NCELL_M=result; 179 MeasureResult.NO_NCELL_M=result;
180 180
181 rep=MeasureResult.NO_NCELL_M; 181 rep=MeasureResult.NO_NCELL_M;
182 182
183 for (i=0;i<MeasureResult.NO_NCELL_M;i++) { 183 for (i=0;i<MeasureResult.NO_NCELL_M;i++) {
184 result= 0; 184 result= 0;
185 GetBufferI(buf+14,&j,&result,6); 185 GetBufferI(buf+14,&j,&result,6);
186 MeasureResult.NeighbourCell[i].RxLev = result-110; 186 MeasureResult.NeighbourCell[i].RxLev = result-110;
187 187
188 result= 0; 188 result= 0;
189 GetBufferI(buf+14,&j,&result,5); 189 GetBufferI(buf+14,&j,&result,5);
190 if (new_variable) 190 if (new_variable)
191 MeasureResult.NeighbourCell[i].ChFreq = frequency[result+1]; 191 MeasureResult.NeighbourCell[i].ChFreq = frequency[result+1];
192 else MeasureResult.NeighbourCell[i].ChFreq = frequency[result]; 192 else MeasureResult.NeighbourCell[i].ChFreq = frequency[result];
193 193
194 result= 0; 194 result= 0;
195 GetBufferI(buf+14,&j,&result,3); 195 GetBufferI(buf+14,&j,&result,3);
196 MeasureResult.NeighbourCell[i].NB = 10 * result; 196 MeasureResult.NeighbourCell[i].NB = 10 * result;
197 result= 0; 197 result= 0;
198 GetBufferI(buf+14,&j,&result,3); 198 GetBufferI(buf+14,&j,&result,3);
199 MeasureResult.NeighbourCell[i].NB += result; 199 MeasureResult.NeighbourCell[i].NB += result;
200 200
201 if (MeasureResult.NeighbourCell[i].ChFreq) 201 if (MeasureResult.NeighbourCell[i].ChFreq)
202 printf("CH = %i,\t",MeasureResult.NeighbourCell[i].ChFreq); 202 printf("CH = %i,\t",MeasureResult.NeighbourCell[i].ChFreq);
203 else 203 else
204 printf("CH = Unknown\t"); 204 printf("CH = Unknown\t");
205 printf("RX Lev = %i dBm\t",MeasureResult.NeighbourCell[i].RxLev); 205 printf("RX Lev = %i dBm\t",MeasureResult.NeighbourCell[i].RxLev);
206 printf("BSIC CELL = %i\n",MeasureResult.NeighbourCell[i].NB); 206 printf("BSIC CELL = %i\n",MeasureResult.NeighbourCell[i].NB);
207 } 207 }
208 } 208 }
209#ifdef DEBUG 209#ifdef DEBUG
210 if (buf[4]==05) { //Timing Advance 210 if (buf[4]==05) { //Timing Advance
211 if (buf[11]) dbgprintf ("Unknown Timing Advance\n"); 211 if (buf[11]) dbgprintf ("Unknown Timing Advance\n");
212 else dbgprintf ("Timing Advance = %i\n",buf[14] & 0x3f); 212 else dbgprintf ("Timing Advance = %i\n",buf[14] & 0x3f);
213 } 213 }
214#endif 214#endif
215 return ERR_NONE; 215 return ERR_NONE;
216} 216}
217 217
218GSM_Error ATSIEMENS_Reply_GetNetmon(GSM_Protocol_Message msg, GSM_StateMachine *s) 218GSM_Error ATSIEMENS_Reply_GetNetmon(GSM_Protocol_Message msg, GSM_StateMachine *s)
219{ 219{
220 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 220 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
221 int i=2; 221 int i=2;
222 222
223 if (!strstr(GetLineString(msg.Buffer,Priv->Lines,1),"AT^S^MI")) return ERR_UNKNOWN; 223 if (!strstr(GetLineString(msg.Buffer,Priv->Lines,1),"AT^S^MI")) return ERR_UNKNOWN;
224 while (strlen(GetLineString(msg.Buffer,Priv->Lines,i+1))) 224 while (strlen(GetLineString(msg.Buffer,Priv->Lines,i+1)))
225 printf("%s\n",GetLineString(msg.Buffer,Priv->Lines,i++)); 225 printf("%s\n",GetLineString(msg.Buffer,Priv->Lines,i++));
226 printf("\n"); 226 printf("\n");
227 return ERR_NONE; 227 return ERR_NONE;
228} 228}
229 229
230GSM_Error ATSIEMENS_GetSAT(GSM_StateMachine *s) 230GSM_Error ATSIEMENS_GetSAT(GSM_StateMachine *s)
231{ 231{
232 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 232 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
233 GSM_Error error; 233 GSM_Error error;
234 unsigned char *reqSAT[]= {"D009810301260082028182", 234 unsigned char *reqSAT[]= {"D009810301260082028182",
235 "D009810301260282028182", 235 "D009810301260282028182",
236 "D009810301260582028182"},req[32]; 236 "D009810301260582028182"},req[32];
237 int i,len; 237 int i,len;
238 238
239 if (Priv->Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED; 239 if (Priv->Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED;
240 240
241 sprintf(req, "AT^SSTK=?\r"); 241 sprintf(req, "AT^SSTK=?\r");
242 error = GSM_WaitFor (s, req, strlen(req), 0x00, 3, ID_User1); 242 error = GSM_WaitFor (s, req, strlen(req), 0x00, 3, ID_User1);
243 243
244 for (i=0;i<3;i++){ 244 for (i=0;i<3;i++){
245 len = strlen(reqSAT[i]); 245 len = strlen(reqSAT[i]);
246 s->Protocol.Data.AT.EditMode = true; 246 s->Protocol.Data.AT.EditMode = true;
247 sprintf(req, "AT^SSTK=%i,1\r",len/2); 247 sprintf(req, "AT^SSTK=%i,1\r",len/2);
248 error = GSM_WaitFor (s, req, strlen(req), 0x00, 3, ID_User1); 248 error = GSM_WaitFor (s, req, strlen(req), 0x00, 3, ID_User1);
249 s->Phone.Data.DispatchError= ERR_TIMEOUT; 249 s->Phone.Data.DispatchError= ERR_TIMEOUT;
250 s->Phone.Data.RequestID = ID_User1; 250 s->Phone.Data.RequestID = ID_User1;
251 error = s->Protocol.Functions->WriteMessage(s, reqSAT[i], len, 0x00); 251 error = s->Protocol.Functions->WriteMessage(s, reqSAT[i], len, 0x00);
252 if (error!=ERR_NONE) return error; 252 if (error!=ERR_NONE) return error;
253 error = s->Protocol.Functions->WriteMessage(s, "\x1A", 1, 0x00); 253 error = s->Protocol.Functions->WriteMessage(s, "\x1A", 1, 0x00);
254 if (error!=ERR_NONE) return error; 254 if (error!=ERR_NONE) return error;
255 error = GSM_WaitForOnce (s, NULL,0x00, 0x00, 4); 255 error = GSM_WaitForOnce (s, NULL,0x00, 0x00, 4);
256 if (error!=ERR_NONE) return error; 256 if (error!=ERR_NONE) return error;
257 } 257 }
258 return ERR_NONE; 258 return ERR_NONE;
259} 259}
260 260
261GSM_Error ATSIEMENS_GetNetmon(GSM_StateMachine *s,int test_no) 261GSM_Error ATSIEMENS_GetNetmon(GSM_StateMachine *s,int test_no)
262{ 262{
263 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 263 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
264 unsigned char req[32]; 264 unsigned char req[32];
265 265
266 if (Priv->Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED; 266 if (Priv->Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED;
267 sprintf(req, "AT^S^MI=%d\r",test_no); 267 sprintf(req, "AT^S^MI=%d\r",test_no);
268 printf ("Siemens NetMonitor test #%i\n",test_no); 268 printf ("Siemens NetMonitor test #%i\n",test_no);
269 return GSM_WaitFor(s, req, strlen(req), 0x00, 3, ID_User2); 269 return GSM_WaitFor(s, req, strlen(req), 0x00, 3, ID_User2);
270} 270}
271 271
272GSM_Error ATSIEMENS_ActivateNetmon (GSM_StateMachine *s,int netmon_type) 272GSM_Error ATSIEMENS_ActivateNetmon (GSM_StateMachine *s,int netmon_type)
273{ 273{
274 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN; 274 GSM_Phone_ATGENData*Priv = &s->Phone.Data.Priv.ATGEN;
275 unsigned char req[32]; 275 unsigned char req[32];
276 276
277 if (Priv->Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED; 277 if (Priv->Manufacturer!=AT_Siemens) return ERR_NOTSUPPORTED;
278 278
279 sprintf(req, "AT\r"); 279 sprintf(req, "AT\r");
280 printf ("Activate Siemens NetMonitor\n"); 280 printf ("Activate Siemens NetMonitor\n");
281 siemens_code (req,req,2); 281 siemens_code (req,req,2);
282 282
283 return GSM_WaitFor(s, req, strlen(req), 0x00, 3, ID_User2); 283 return GSM_WaitFor(s, req, strlen(req), 0x00, 3, ID_User2);
284} 284}
285 285
286void ATSIEMENSActivateNetmon(int argc, char *argv[]) 286void ATSIEMENSActivateNetmon(int argc, char *argv[])
287{ 287{
288 GSM_MemoryStatus status; 288 GSM_MemoryStatus status;
289 GSM_MemoryEntry pbk; 289 GSM_MemoryEntry pbk;
290 int netmon_type, pbk_maxlocation; 290 int netmon_type, pbk_maxlocation;
291 char imsi[15], NetMonCode[32]; 291 char imsi[15], NetMonCode[32];
292 292
293 GSM_Init(true); 293 GSM_Init(true);
294 if (CheckSiemens()==ERR_NOTSUPPORTED) Print_Error(ERR_NOTSUPPORTED); 294 if (CheckSiemens()==ERR_NOTSUPPORTED) Print_Error(ERR_NOTSUPPORTED);
295 s.User.UserReplyFunctions=UserReplyFunctionsAtS; 295 s.User.UserReplyFunctions=UserReplyFunctionsAtS;
296 296
297 printf ("Activate NetMonitor...\n"); 297 printf ("Activate NetMonitor...\n");
298 netmon_type = atoi(argv[2]); 298 netmon_type = atoi(argv[2]);
299 299
300 if ((netmon_type==1) || (netmon_type==2)) { 300 if ((netmon_type==1) || (netmon_type==2)) {
301 error = ATGEN_GetSIMIMSI (&s,imsi); 301 error = ATGEN_GetSIMIMSI (&s,imsi);
302 Print_Error(error); 302 Print_Error(error);
303 siemens_code(imsi,NetMonCode,netmon_type); 303 siemens_code(imsi,NetMonCode,netmon_type);
304 304
305 status.MemoryType = MEM_SM; 305 status.MemoryType = MEM_SM;
306 error = ATGEN_GetMemoryStatus (&s,&status); 306 error = ATGEN_GetMemoryStatus (&s,&status);
307 Print_Error(error); 307 Print_Error(error);
308 308
309 pbk_maxlocation = status.MemoryUsed+status.MemoryFree; 309 pbk_maxlocation = status.MemoryUsed+status.MemoryFree;
310 pbk.MemoryType = MEM_SM; 310 pbk.MemoryType = MEM_SM;
311 pbk.Location = pbk_maxlocation; 311 pbk.Location = pbk_maxlocation;
312 pbk.EntriesNum = 2; 312 pbk.EntriesNum = 2;
313 pbk.Entries[0].EntryType = PBK_Number_General; 313 pbk.Entries[0].EntryType = PBK_Number_General;
314 EncodeUnicode (pbk.Entries[0].Text,NetMonCode,strlen(NetMonCode)); 314 EncodeUnicode (pbk.Entries[0].Text,NetMonCode,strlen(NetMonCode));
315 pbk.Entries[1].EntryType = PBK_Text_Name; 315 pbk.Entries[1].EntryType = PBK_Text_Name;
316 sprintf (NetMonCode,"Net Monitor"); 316 sprintf (NetMonCode,"Net Monitor");
317 EncodeUnicode (pbk.Entries[1].Text,NetMonCode,strlen(NetMonCode)); 317 EncodeUnicode (pbk.Entries[1].Text,NetMonCode,strlen(NetMonCode));
318 error = ATGEN_SetMemory (&s, &pbk); 318 error = ATGEN_SetMemory (&s, &pbk);
319 Print_Error(error); 319 Print_Error(error);
320 } 320 }
321 else printf ("NetMonitor type should be:\n1 - full Netmon\n2 - simple NetMon\n"); 321 else printf ("NetMonitor type should be:\n1 - full Netmon\n2 - simple NetMon\n");
322 322
323 GSM_Terminate(); 323 GSM_Terminate();
324} 324}
325 325
326void ATSIEMENSSATNetmon(int argc, char *argv[]) 326void ATSIEMENSSATNetmon(int argc, char *argv[])
327{ 327{
328 GSM_Init(true); 328 GSM_Init(true);
329 if (CheckSiemens()==ERR_NOTSUPPORTED) Print_Error(ERR_NOTSUPPORTED); 329 if (CheckSiemens()==ERR_NOTSUPPORTED) Print_Error(ERR_NOTSUPPORTED);
330 s.User.UserReplyFunctions=UserReplyFunctionsAtS; 330 s.User.UserReplyFunctions=UserReplyFunctionsAtS;
331 331
332 printf ("Getting Siemens Sim Aplication Toolkit NetMonitor...\n"); 332 printf ("Getting Siemens Sim Aplication Toolkit NetMonitor...\n");
333 333
334 error=ATSIEMENS_GetSAT(&s); 334 error=ATSIEMENS_GetSAT(&s);
335 Print_Error(error); 335 Print_Error(error);
336 GSM_Terminate(); 336 GSM_Terminate();
337} 337}
338 338
339void ATSIEMENSNetmonitor(int argc, char *argv[]) 339void ATSIEMENSNetmonitor(int argc, char *argv[])
340{ 340{
341 int test_no; 341 int test_no;
342 342
343 GSM_Init(true); 343 GSM_Init(true);
344 if (CheckSiemens()==ERR_NOTSUPPORTED) Print_Error(ERR_NOTSUPPORTED); 344 if (CheckSiemens()==ERR_NOTSUPPORTED) Print_Error(ERR_NOTSUPPORTED);
345 s.User.UserReplyFunctions=UserReplyFunctionsAtS; 345 s.User.UserReplyFunctions=UserReplyFunctionsAtS;
346 346
347 printf ("Getting Siemens NetMonitor...\n"); 347 printf ("Getting Siemens NetMonitor...\n");
348 test_no = atoi(argv[2]); 348 test_no = atoi(argv[2]);
349 error = ATSIEMENS_GetNetmon (&s,test_no+1); 349 error = ATSIEMENS_GetNetmon (&s,test_no+1);
350 Print_Error(error); 350 Print_Error(error);
351 GSM_Terminate(); 351 GSM_Terminate();
352} 352}
353 353
354static GSM_Reply_Function UserReplyFunctionsAtS[] = { 354static GSM_Reply_Function UserReplyFunctionsAtS[] = {
355 {ATSIEMENS_Reply_GetSAT, "AT^SSTK", 0x00,0x00,ID_User1}, 355 {ATSIEMENS_Reply_GetSAT, "AT^SSTK", 0x00,0x00,ID_User1},
356 {ATSIEMENS_Reply_GetNetmon, "AT^S^MI", 0x00,0x00,ID_User2}, 356 {ATSIEMENS_Reply_GetNetmon, "AT^S^MI", 0x00,0x00,ID_User2},
357 {NULL, "\x00", 0x00,0x00,ID_None} 357 {NULL, "\x00", 0x00,0x00,ID_None}
358}; 358};
359#endif 359#endif
360 360
361/* How should editor hadle tabs in this file? Add editor commands here. 361/* How should editor hadle tabs in this file? Add editor commands here.
362 * vim: noexpandtab sw=8 ts=8 sts=8: 362 * vim: noexpandtab sw=8 ts=8 sts=8:
363 */ 363 */
diff --git a/kaddressbook/addresseeeditorwidget.h b/kaddressbook/addresseeeditorwidget.h
index df9965d..816bbb5 100644
--- a/kaddressbook/addresseeeditorwidget.h
+++ b/kaddressbook/addresseeeditorwidget.h
@@ -1,192 +1,193 @@
1/* 1/*
2 This file is part of KAddressBook. 2 This file is part of KAddressBook.
3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com> 3 Copyright (c) 2002 Mike Pilone <mpilone@slac.com>
4 4
5 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version. 8 (at your option) any later version.
9 9
10 This program is distributed in the hope that it will be useful, 10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details. 13 GNU General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software 16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 18
19 As a special exception, permission is given to link this program 19 As a special exception, permission is given to link this program
20 with any edition of Qt, and distribute the resulting executable, 20 with any edition of Qt, and distribute the resulting executable,
21 without including the source code for Qt in the source distribution. 21 without including the source code for Qt in the source distribution.
22*/ 22*/
23 23
24#ifndef ADDRESSEEEDITORWIDGET_H 24#ifndef ADDRESSEEEDITORWIDGET_H
25#define ADDRESSEEEDITORWIDGET_H 25#define ADDRESSEEEDITORWIDGET_H
26 26
27#include <qdatetime.h> 27#include <qdatetime.h>
28#include <qpopupmenu.h> 28#include <qpopupmenu.h>
29#include <qcombobox.h>
29 30
30#include <kabc/addressee.h> 31#include <kabc/addressee.h>
31#include <kdialogbase.h> 32#include <kdialogbase.h>
32#include <kjanuswidget.h> 33#include <kjanuswidget.h>
33 34
34#include "extensionwidget.h" 35#include "extensionwidget.h"
35 36
36class AddresseeConfig; 37class AddresseeConfig;
37class QCheckBox; 38class QCheckBox;
38class QSpinBox; 39class QSpinBox;
39class QTabWidget; 40class QTabWidget;
40 41
41#ifndef KAB_EMBEDDED 42#ifndef KAB_EMBEDDED
42class QTextEdit; 43class QTextEdit;
43#else //KAB_EMBEDDED 44#else //KAB_EMBEDDED
44class QMultiLineEdit; 45class QMultiLineEdit;
45#endif //KAB_EMBEDDED 46#endif //KAB_EMBEDDED
46 47
47class KComboBox; 48class KComboBox;
48class KDateEdit; 49class KDateEdit;
49class KLineEdit; 50class KLineEdit;
50class KSqueezedTextLabel; 51class KSqueezedTextLabel;
51 52
52class AddressEditWidget; 53class AddressEditWidget;
53class EmailEditWidget; 54class EmailEditWidget;
54class GeoWidget; 55class GeoWidget;
55class ImageWidget; 56class ImageWidget;
56class KABCore; 57class KABCore;
57class KeyWidget; 58class KeyWidget;
58class PhoneEditWidget; 59class PhoneEditWidget;
59class SecrecyWidget; 60class SecrecyWidget;
60class SoundWidget; 61class SoundWidget;
61 62
62namespace KPIM 63namespace KPIM
63{ 64{
64 class CategorySelectDialog; 65 class CategorySelectDialog;
65 class CategoryEditDialog; 66 class CategoryEditDialog;
66} 67}
67 68
68namespace KABC { class AddressBook; } 69namespace KABC { class AddressBook; }
69 70
70class AddresseeEditorWidget : public ExtensionWidget 71class AddresseeEditorWidget : public ExtensionWidget
71{ 72{
72 Q_OBJECT 73 Q_OBJECT
73 74
74 public: 75 public:
75 AddresseeEditorWidget( KABCore *core, bool isExtension, 76 AddresseeEditorWidget( KABCore *core, bool isExtension,
76 QWidget *parent, const char *name = 0 ); 77 QWidget *parent, const char *name = 0 );
77 ~AddresseeEditorWidget(); 78 ~AddresseeEditorWidget();
78 79
79 void setAddressee( const KABC::Addressee& ); 80 void setAddressee( const KABC::Addressee& );
80 const KABC::Addressee &addressee(); 81 const KABC::Addressee &addressee();
81 82
82 void contactsSelectionChanged(); 83 void contactsSelectionChanged();
83 84
84 void load(); 85 void load();
85 void save(); 86 void save();
86 87
87 bool dirty(); 88 bool dirty();
88 89
89 QString title() const; 90 QString title() const;
90 QString identifier() const; 91 QString identifier() const;
91 92
92 protected slots: 93 protected slots:
93 void showCatPopup(); 94 void showCatPopup();
94 void selectedCatPopup( int ); 95 void selectedCatPopup( int );
95 void setRole2FN(); 96 void setRole2FN();
96 void setCompany2FN(); 97 void setCompany2FN();
97 void textChanged( const QString& ); 98 void textChanged( const QString& );
98 void pageChanged( QWidget *wdg ); 99 void pageChanged( QWidget *wdg );
99 100
100 /** 101 /**
101 Emits the modified signal and sets the dirty flag. Any slot 102 Emits the modified signal and sets the dirty flag. Any slot
102 that modifies data should use this method instead of calling emit 103 that modifies data should use this method instead of calling emit
103 modified() directly. 104 modified() directly.
104 */ 105 */
105 void emitModified(); 106 void emitModified();
106 107
107 void dateChanged( QDate ); 108 void dateChanged( QDate );
108 void invalidDate(); 109 void invalidDate();
109 void nameTextChanged( const QString& ); 110 void nameTextChanged( const QString& );
110 void nameBoxChanged(); 111 void nameBoxChanged();
111 void nameButtonClicked(); 112 void nameButtonClicked();
112 void categoryButtonClicked(); 113 void categoryButtonClicked();
113 114
114 /** 115 /**
115 Called whenever the categories change in the categories dialog. 116 Called whenever the categories change in the categories dialog.
116 */ 117 */
117 void categoriesSelected( const QStringList& ); 118 void categoriesSelected( const QStringList& );
118 119
119 /** 120 /**
120 Edits which categories are available in the CategorySelectDialog. 121 Edits which categories are available in the CategorySelectDialog.
121 */ 122 */
122 void editCategories(); 123 void editCategories();
123 124
124 private: 125 private:
125 AddresseeConfig * mAConfig; 126 AddresseeConfig * mAConfig;
126 void initGUI(); 127 void initGUI();
127 void setupTab1(); 128 void setupTab1();
128 void setupTab1_1(); 129 void setupTab1_1();
129 void setupTab2(); 130 void setupTab2();
130 void setupTab2_1(); 131 void setupTab2_1();
131 void setupTab3(); 132 void setupTab3();
132 void setupTab3_1(); 133 void setupTab3_1();
133 134
134 KABC::Addressee mAddressee; 135 KABC::Addressee mAddressee;
135 int mFormattedNameType; 136 int mFormattedNameType;
136 bool mDirty; 137 bool mDirty;
137 bool mIsExtension; 138 bool mIsExtension;
138 bool mBlockSignals; 139 bool mBlockSignals;
139 140
140 // GUI 141 // GUI
141 KPIM::CategorySelectDialog *mCategoryDialog; 142 KPIM::CategorySelectDialog *mCategoryDialog;
142 KPIM::CategoryEditDialog *mCategoryEditDialog; 143 KPIM::CategoryEditDialog *mCategoryEditDialog;
143 QTabWidget *mTabWidget; 144 QTabWidget *mTabWidget;
144 145
145 // Tab1 and Tab1_1 146 // Tab1 and Tab1_1
146 KLineEdit *mNameEdit; 147 KLineEdit *mNameEdit;
147 KLineEdit *mRoleEdit; 148 KLineEdit *mRoleEdit;
148 KLineEdit *mOrgEdit; 149 KLineEdit *mOrgEdit;
149 150
150 KSqueezedTextLabel *mFormattedNameLabel; 151 KSqueezedTextLabel *mFormattedNameLabel;
151 AddressEditWidget *mAddressEditWidget; 152 AddressEditWidget *mAddressEditWidget;
152 EmailEditWidget *mEmailWidget; 153 EmailEditWidget *mEmailWidget;
153 PhoneEditWidget *mPhoneEditWidget; 154 PhoneEditWidget *mPhoneEditWidget;
154 KLineEdit *mURLEdit; 155 KLineEdit *mURLEdit;
155 KLineEdit *mIMAddressEdit; 156 KLineEdit *mIMAddressEdit;
156 QPushButton *mCategoryEdit; 157 QPushButton *mCategoryEdit;
157 QPopupMenu *mCatPopup; 158 QPopupMenu *mCatPopup;
158 SecrecyWidget *mSecrecyWidget; 159 SecrecyWidget *mSecrecyWidget;
159 KSqueezedTextLabel *mNameLabel; 160 KSqueezedTextLabel *mNameLabel;
160 161
161 // Tab2 and Tab2_2 162 // Tab2 and Tab2_2
162 KLineEdit *mDepartmentEdit; 163 KLineEdit *mDepartmentEdit;
163 KLineEdit *mOfficeEdit; 164 KLineEdit *mOfficeEdit;
164 KLineEdit *mProfessionEdit; 165 KLineEdit *mProfessionEdit;
165 KLineEdit *mManagerEdit; 166 KLineEdit *mManagerEdit;
166 KLineEdit *mAssistantEdit; 167 KLineEdit *mAssistantEdit;
167 KLineEdit *mNicknameEdit; 168 KLineEdit *mNicknameEdit;
168 KLineEdit *mSpouseEdit; 169 KLineEdit *mSpouseEdit;
169 KLineEdit *mChildEdit; 170 KLineEdit *mChildEdit;
170 QComboBox *mGenderBox; 171 QComboBox *mGenderBox;
171 KDateEdit *mBirthdayPicker; 172 KDateEdit *mBirthdayPicker;
172 KDateEdit *mAnniversaryPicker; 173 KDateEdit *mAnniversaryPicker;
173#ifndef KAB_EMBEDDED 174#ifndef KAB_EMBEDDED
174 QTextEdit *mNoteEdit; 175 QTextEdit *mNoteEdit;
175#else //KAB_EMBEDDED 176#else //KAB_EMBEDDED
176 QMultiLineEdit *mNoteEdit; 177 QMultiLineEdit *mNoteEdit;
177#endif //KAB_EMBEDDED 178#endif //KAB_EMBEDDED
178 179
179 QSpinBox *mTimeZoneSpin; 180 QSpinBox *mTimeZoneSpin;
180 QSpinBox *mGeoLat; 181 QSpinBox *mGeoLat;
181 QSpinBox *mGeoLon; 182 QSpinBox *mGeoLon;
182 183
183 // Tab3 184 // Tab3
184 GeoWidget *mGeoWidget; 185 GeoWidget *mGeoWidget;
185 ImageWidget *mImageWidget; 186 ImageWidget *mImageWidget;
186#ifndef KAB_EMBEDDED 187#ifndef KAB_EMBEDDED
187 SoundWidget *mSoundWidget; 188 SoundWidget *mSoundWidget;
188#endif //KAB_EMBEDDED 189#endif //KAB_EMBEDDED
189 KeyWidget *mKeyWidget; 190 KeyWidget *mKeyWidget;
190}; 191};
191 192
192#endif 193#endif
diff --git a/pwmanager/libcrypt/cipher/serpent.c b/pwmanager/libcrypt/cipher/serpent.c
index d606d9f..fb5df20 100644
--- a/pwmanager/libcrypt/cipher/serpent.c
+++ b/pwmanager/libcrypt/cipher/serpent.c
@@ -1,979 +1,979 @@
1/* serpent.c - Implementation of the Serpent encryption algorithm. 1/* serpent.c - Implementation of the Serpent encryption algorithm.
2 *Copyright (C) 2003 Free Software Foundation, Inc. 2 *Copyright (C) 2003 Free Software Foundation, Inc.
3 * 3 *
4 * This file is part of Libgcrypt. 4 * This file is part of Libgcrypt.
5 * 5 *
6 * Libgcrypt is free software; you can redistribute it and/or modify 6 * Libgcrypt is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser general Public License as 7 * it under the terms of the GNU Lesser general Public License as
8 * published by the Free Software Foundation; either version 2.1 of 8 * published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version. 9 * the License, or (at your option) any later version.
10 * 10 *
11 * Libgcrypt is distributed in the hope that it will be useful, 11 * Libgcrypt is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details. 14 * GNU Lesser General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU Lesser General Public 16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software 17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA. 19 * 02111-1307, USA.
20 */ 20 */
21 21
22#include <config.h> 22#include <config.h>
23 23
24#include <string.h> 24#include <string.h>
25#include <stdio.h> 25#include <stdio.h>
26 26
27#include "types.h" 27#include "types.h"
28#include "g10lib.h" 28#include "g10lib.h"
29#include "cipher.h" 29#include "cipher.h"
30#include "bithelp.h" 30#include "bithelp.h"
31 31
32/* Number of rounds per Serpent encrypt/decrypt operation. */ 32/* Number of rounds per Serpent encrypt/decrypt operation. */
33#define ROUNDS 32 33#define ROUNDS 32
34 34
35/* Magic number, used during generating of the subkeys. */ 35/* Magic number, used during generating of the subkeys. */
36#define PHI 0x9E3779B9 36#define PHI 0x9E3779B9
37 37
38/* Internal types. */ 38/* Internal types. */
39typedef byte byte_t; 39typedef byte byte_t;
40typedef u32 u32_t; 40typedef u32 u32_t;
41 41
42/* Serpent works on 128 bit blocks. */ 42/* Serpent works on 128 bit blocks. */
43typedef u32_t serpent_block_t[4]; 43typedef u32_t serpent_block_t[4];
44 44
45/* Serpent key, provided by the user. If the original key is shorter 45/* Serpent key, provided by the user. If the original key is shorter
46 than 256 bits, it is padded. */ 46 than 256 bits, it is padded. */
47typedef u32_t serpent_key_t[8]; 47typedef u32_t serpent_key_t[8];
48 48
49/* The key schedule consists of 33 128 bit subkeys. */ 49/* The key schedule consists of 33 128 bit subkeys. */
50typedef u32_t serpent_subkeys_t[ROUNDS + 1][4]; 50typedef u32_t serpent_subkeys_t[ROUNDS + 1][4];
51 51
52/* A Serpent context. */ 52/* A Serpent context. */
53typedef struct serpent_context 53typedef struct serpent_context
54{ 54{
55 serpent_subkeys_t keys;/* Generated subkeys. */ 55 serpent_subkeys_t keys;/* Generated subkeys. */
56} serpent_context_t; 56} serpent_context_t;
57 57
58#define byte_swap_32(x) \ 58#define byte_swap_32(x) \
59 (0 \ 59 (0 \
60 | (((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \ 60 | (((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) \
61 | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)); 61 | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24));
62 62
63/* These are the S-Boxes of Serpent. They are copied from Serpents 63/* These are the S-Boxes of Serpent. They are copied from Serpents
64 reference implementation (the optimized one, contained in 64 reference implementation (the optimized one, contained in
65 `floppy2') and are therefore: 65 `floppy2') and are therefore:
66 66
67 Copyright (C) 1998 Ross Anderson, Eli Biham, Lars Knudsen. 67 Copyright (C) 1998 Ross Anderson, Eli Biham, Lars Knudsen.
68 68
69 To quote the Serpent homepage 69 To quote the Serpent homepage
70 (http://www.cl.cam.ac.uk/~rja14/serpent.html): 70 (http://www.cl.cam.ac.uk/~rja14/serpent.html):
71 71
72 "Serpent is now completely in the public domain, and we impose no 72 "Serpent is now completely in the public domain, and we impose no
73 restrictions on its use. This was announced on the 21st August at 73 restrictions on its use. This was announced on the 21st August at
74 the First AES Candidate Conference. The optimised implementations 74 the First AES Candidate Conference. The optimised implementations
75 in the submission package are now under the GNU PUBLIC LICENSE 75 in the submission package are now under the GNU PUBLIC LICENSE
76 (GPL), although some comments in the code still say otherwise. You 76 (GPL), although some comments in the code still say otherwise. You
77 are welcome to use Serpent for any application." */ 77 are welcome to use Serpent for any application." */
78 78
79#define SBOX0(a, b, c, d, w, x, y, z) \ 79#define SBOX0(a, b, c, d, w, x, y, z) \
80 { \ 80 { \
81 register unsigned long t02, t03, t05, t06, t07, t08, t09; \ 81 register unsigned long t02, t03, t05, t06, t07, t08, t09; \
82 register unsigned long t11, t12, t13, t14, t15, t17, t01; \ 82 register unsigned long t11, t12, t13, t14, t15, t17, t01; \
83 t01 = b ^ c ; \ 83 t01 = b ^ c ; \
84 t02 = a | d ; \ 84 t02 = a | d ; \
85 t03 = a ^ b ; \ 85 t03 = a ^ b ; \
86 z = t02 ^ t01; \ 86 z = t02 ^ t01; \
87 t05 = c | z ; \ 87 t05 = c | z ; \
88 t06 = a ^ d ; \ 88 t06 = a ^ d ; \
89 t07 = b | c ; \ 89 t07 = b | c ; \
90 t08 = d & t05; \ 90 t08 = d & t05; \
91 t09 = t03 & t07; \ 91 t09 = t03 & t07; \
92 y = t09 ^ t08; \ 92 y = t09 ^ t08; \
93 t11 = t09 & y ; \ 93 t11 = t09 & y ; \
94 t12 = c ^ d ; \ 94 t12 = c ^ d ; \
95 t13 = t07 ^ t11; \ 95 t13 = t07 ^ t11; \
96 t14 = b & t06; \ 96 t14 = b & t06; \
97 t15 = t06 ^ t13; \ 97 t15 = t06 ^ t13; \
98 w = ~ t15; \ 98 w = ~ t15; \
99 t17 = w ^ t14; \ 99 t17 = w ^ t14; \
100 x = t12 ^ t17; \ 100 x = t12 ^ t17; \
101 } 101 }
102 102
103#define SBOX0_INVERSE(a, b, c, d, w, x, y, z) \ 103#define SBOX0_INVERSE(a, b, c, d, w, x, y, z) \
104 { \ 104 { \
105 register unsigned long t02, t03, t04, t05, t06, t08, t09, t10; \ 105 register unsigned long t02, t03, t04, t05, t06, t08, t09, t10; \
106 register unsigned long t12, t13, t14, t15, t17, t18, t01; \ 106 register unsigned long t12, t13, t14, t15, t17, t18, t01; \
107 t01 = c ^ d ; \ 107 t01 = c ^ d ; \
108 t02 = a | b ; \ 108 t02 = a | b ; \
109 t03 = b | c ; \ 109 t03 = b | c ; \
110 t04 = c & t01; \ 110 t04 = c & t01; \
111 t05 = t02 ^ t01; \ 111 t05 = t02 ^ t01; \
112 t06 = a | t04; \ 112 t06 = a | t04; \
113 y = ~ t05; \ 113 y = ~ t05; \
114 t08 = b ^ d ; \ 114 t08 = b ^ d ; \
115 t09 = t03 & t08; \ 115 t09 = t03 & t08; \
116 t10 = d | y ; \ 116 t10 = d | y ; \
117 x = t09 ^ t06; \ 117 x = t09 ^ t06; \
118 t12 = a | t05; \ 118 t12 = a | t05; \
119 t13 = x ^ t12; \ 119 t13 = x ^ t12; \
120 t14 = t03 ^ t10; \ 120 t14 = t03 ^ t10; \
121 t15 = a ^ c ; \ 121 t15 = a ^ c ; \
122 z = t14 ^ t13; \ 122 z = t14 ^ t13; \
123 t17 = t05 & t13; \ 123 t17 = t05 & t13; \
124 t18 = t14 | t17; \ 124 t18 = t14 | t17; \
125 w = t15 ^ t18; \ 125 w = t15 ^ t18; \
126 } 126 }
127 127
128#define SBOX1(a, b, c, d, w, x, y, z) \ 128#define SBOX1(a, b, c, d, w, x, y, z) \
129 { \ 129 { \
130 register unsigned long t02, t03, t04, t05, t06, t07, t08; \ 130 register unsigned long t02, t03, t04, t05, t06, t07, t08; \
131 register unsigned long t10, t11, t12, t13, t16, t17, t01; \ 131 register unsigned long t10, t11, t12, t13, t16, t17, t01; \
132 t01 = a | d ; \ 132 t01 = a | d ; \
133 t02 = c ^ d ; \ 133 t02 = c ^ d ; \
134 t03 = ~ b ; \ 134 t03 = ~ b ; \
135 t04 = a ^ c ; \ 135 t04 = a ^ c ; \
136 t05 = a | t03; \ 136 t05 = a | t03; \
137 t06 = d & t04; \ 137 t06 = d & t04; \
138 t07 = t01 & t02; \ 138 t07 = t01 & t02; \
139 t08 = b | t06; \ 139 t08 = b | t06; \
140 y = t02 ^ t05; \ 140 y = t02 ^ t05; \
141 t10 = t07 ^ t08; \ 141 t10 = t07 ^ t08; \
142 t11 = t01 ^ t10; \ 142 t11 = t01 ^ t10; \
143 t12 = y ^ t11; \ 143 t12 = y ^ t11; \
144 t13 = b & d ; \ 144 t13 = b & d ; \
145 z = ~ t10; \ 145 z = ~ t10; \
146 x = t13 ^ t12; \ 146 x = t13 ^ t12; \
147 t16 = t10 | x ; \ 147 t16 = t10 | x ; \
148 t17 = t05 & t16; \ 148 t17 = t05 & t16; \
149 w = c ^ t17; \ 149 w = c ^ t17; \
150 } 150 }
151 151
152#define SBOX1_INVERSE(a, b, c, d, w, x, y, z) \ 152#define SBOX1_INVERSE(a, b, c, d, w, x, y, z) \
153 { \ 153 { \
154 register unsigned long t02, t03, t04, t05, t06, t07, t08; \ 154 register unsigned long t02, t03, t04, t05, t06, t07, t08; \
155 register unsigned long t09, t10, t11, t14, t15, t17, t01; \ 155 register unsigned long t09, t10, t11, t14, t15, t17, t01; \
156 t01 = a ^ b ; \ 156 t01 = a ^ b ; \
157 t02 = b | d ; \ 157 t02 = b | d ; \
158 t03 = a & c ; \ 158 t03 = a & c ; \
159 t04 = c ^ t02; \ 159 t04 = c ^ t02; \
160 t05 = a | t04; \ 160 t05 = a | t04; \
161 t06 = t01 & t05; \ 161 t06 = t01 & t05; \
162 t07 = d | t03; \ 162 t07 = d | t03; \
163 t08 = b ^ t06; \ 163 t08 = b ^ t06; \
164 t09 = t07 ^ t06; \ 164 t09 = t07 ^ t06; \
165 t10 = t04 | t03; \ 165 t10 = t04 | t03; \
166 t11 = d & t08; \ 166 t11 = d & t08; \
167 y = ~ t09; \ 167 y = ~ t09; \
168 x = t10 ^ t11; \ 168 x = t10 ^ t11; \
169 t14 = a | y ; \ 169 t14 = a | y ; \
170 t15 = t06 ^ x ; \ 170 t15 = t06 ^ x ; \
171 z = t01 ^ t04; \ 171 z = t01 ^ t04; \
172 t17 = c ^ t15; \ 172 t17 = c ^ t15; \
173 w = t14 ^ t17; \ 173 w = t14 ^ t17; \
174 } 174 }
175 175
176#define SBOX2(a, b, c, d, w, x, y, z) \ 176#define SBOX2(a, b, c, d, w, x, y, z) \
177 { \ 177 { \
178 register unsigned long t02, t03, t05, t06, t07, t08; \ 178 register unsigned long t02, t03, t05, t06, t07, t08; \
179 register unsigned long t09, t10, t12, t13, t14, t01; \ 179 register unsigned long t09, t10, t12, t13, t14, t01; \
180 t01 = a | c ; \ 180 t01 = a | c ; \
181 t02 = a ^ b ; \ 181 t02 = a ^ b ; \
182 t03 = d ^ t01; \ 182 t03 = d ^ t01; \
183 w = t02 ^ t03; \ 183 w = t02 ^ t03; \
184 t05 = c ^ w ; \ 184 t05 = c ^ w ; \
185 t06 = b ^ t05; \ 185 t06 = b ^ t05; \
186 t07 = b | t05; \ 186 t07 = b | t05; \
187 t08 = t01 & t06; \ 187 t08 = t01 & t06; \
188 t09 = t03 ^ t07; \ 188 t09 = t03 ^ t07; \
189 t10 = t02 | t09; \ 189 t10 = t02 | t09; \
190 x = t10 ^ t08; \ 190 x = t10 ^ t08; \
191 t12 = a | d ; \ 191 t12 = a | d ; \
192 t13 = t09 ^ x ; \ 192 t13 = t09 ^ x ; \
193 t14 = b ^ t13; \ 193 t14 = b ^ t13; \
194 z = ~ t09; \ 194 z = ~ t09; \
195 y = t12 ^ t14; \ 195 y = t12 ^ t14; \
196 } 196 }
197 197
198#define SBOX2_INVERSE(a, b, c, d, w, x, y, z) \ 198#define SBOX2_INVERSE(a, b, c, d, w, x, y, z) \
199 { \ 199 { \
200 register unsigned long t02, t03, t04, t06, t07, t08, t09; \ 200 register unsigned long t02, t03, t04, t06, t07, t08, t09; \
201 register unsigned long t10, t11, t12, t15, t16, t17, t01; \ 201 register unsigned long t10, t11, t12, t15, t16, t17, t01; \
202 t01 = a ^ d ; \ 202 t01 = a ^ d ; \
203 t02 = c ^ d ; \ 203 t02 = c ^ d ; \
204 t03 = a & c ; \ 204 t03 = a & c ; \
205 t04 = b | t02; \ 205 t04 = b | t02; \
206 w = t01 ^ t04; \ 206 w = t01 ^ t04; \
207 t06 = a | c ; \ 207 t06 = a | c ; \
208 t07 = d | w ; \ 208 t07 = d | w ; \
209 t08 = ~ d ; \ 209 t08 = ~ d ; \
210 t09 = b & t06; \ 210 t09 = b & t06; \
211 t10 = t08 | t03; \ 211 t10 = t08 | t03; \
212 t11 = b & t07; \ 212 t11 = b & t07; \
213 t12 = t06 & t02; \ 213 t12 = t06 & t02; \
214 z = t09 ^ t10; \ 214 z = t09 ^ t10; \
215 x = t12 ^ t11; \ 215 x = t12 ^ t11; \
216 t15 = c & z ; \ 216 t15 = c & z ; \
217 t16 = w ^ x ; \ 217 t16 = w ^ x ; \
218 t17 = t10 ^ t15; \ 218 t17 = t10 ^ t15; \
219 y = t16 ^ t17; \ 219 y = t16 ^ t17; \
220 } 220 }
221 221
222#define SBOX3(a, b, c, d, w, x, y, z) \ 222#define SBOX3(a, b, c, d, w, x, y, z) \
223 { \ 223 { \
224 register unsigned long t02, t03, t04, t05, t06, t07, t08; \ 224 register unsigned long t02, t03, t04, t05, t06, t07, t08; \
225 register unsigned long t09, t10, t11, t13, t14, t15, t01; \ 225 register unsigned long t09, t10, t11, t13, t14, t15, t01; \
226 t01 = a ^ c ; \ 226 t01 = a ^ c ; \
227 t02 = a | d ; \ 227 t02 = a | d ; \
228 t03 = a & d ; \ 228 t03 = a & d ; \
229 t04 = t01 & t02; \ 229 t04 = t01 & t02; \
230 t05 = b | t03; \ 230 t05 = b | t03; \
231 t06 = a & b ; \ 231 t06 = a & b ; \
232 t07 = d ^ t04; \ 232 t07 = d ^ t04; \
233 t08 = c | t06; \ 233 t08 = c | t06; \
234 t09 = b ^ t07; \ 234 t09 = b ^ t07; \
235 t10 = d & t05; \ 235 t10 = d & t05; \
236 t11 = t02 ^ t10; \ 236 t11 = t02 ^ t10; \
237 z = t08 ^ t09; \ 237 z = t08 ^ t09; \
238 t13 = d | z ; \ 238 t13 = d | z ; \
239 t14 = a | t07; \ 239 t14 = a | t07; \
240 t15 = b & t13; \ 240 t15 = b & t13; \
241 y = t08 ^ t11; \ 241 y = t08 ^ t11; \
242 w = t14 ^ t15; \ 242 w = t14 ^ t15; \
243 x = t05 ^ t04; \ 243 x = t05 ^ t04; \
244 } 244 }
245 245
246#define SBOX3_INVERSE(a, b, c, d, w, x, y, z) \ 246#define SBOX3_INVERSE(a, b, c, d, w, x, y, z) \
247 { \ 247 { \
248 register unsigned long t02, t03, t04, t05, t06, t07, t09; \ 248 register unsigned long t02, t03, t04, t05, t06, t07, t09; \
249 register unsigned long t11, t12, t13, t14, t16, t01; \ 249 register unsigned long t11, t12, t13, t14, t16, t01; \
250 t01 = c | d ; \ 250 t01 = c | d ; \
251 t02 = a | d ; \ 251 t02 = a | d ; \
252 t03 = c ^ t02; \ 252 t03 = c ^ t02; \
253 t04 = b ^ t02; \ 253 t04 = b ^ t02; \
254 t05 = a ^ d ; \ 254 t05 = a ^ d ; \
255 t06 = t04 & t03; \ 255 t06 = t04 & t03; \
256 t07 = b & t01; \ 256 t07 = b & t01; \
257 y = t05 ^ t06; \ 257 y = t05 ^ t06; \
258 t09 = a ^ t03; \ 258 t09 = a ^ t03; \
259 w = t07 ^ t03; \ 259 w = t07 ^ t03; \
260 t11 = w | t05; \ 260 t11 = w | t05; \
261 t12 = t09 & t11; \ 261 t12 = t09 & t11; \
262 t13 = a & y ; \ 262 t13 = a & y ; \
263 t14 = t01 ^ t05; \ 263 t14 = t01 ^ t05; \
264 x = b ^ t12; \ 264 x = b ^ t12; \
265 t16 = b | t13; \ 265 t16 = b | t13; \
266 z = t14 ^ t16; \ 266 z = t14 ^ t16; \
267 } 267 }
268 268
269#define SBOX4(a, b, c, d, w, x, y, z) \ 269#define SBOX4(a, b, c, d, w, x, y, z) \
270 { \ 270 { \
271 register unsigned long t02, t03, t04, t05, t06, t08, t09; \ 271 register unsigned long t02, t03, t04, t05, t06, t08, t09; \
272 register unsigned long t10, t11, t12, t13, t14, t15, t16, t01; \ 272 register unsigned long t10, t11, t12, t13, t14, t15, t16, t01; \
273 t01 = a | b ; \ 273 t01 = a | b ; \
274 t02 = b | c ; \ 274 t02 = b | c ; \
275 t03 = a ^ t02; \ 275 t03 = a ^ t02; \
276 t04 = b ^ d ; \ 276 t04 = b ^ d ; \
277 t05 = d | t03; \ 277 t05 = d | t03; \
278 t06 = d & t01; \ 278 t06 = d & t01; \
279 z = t03 ^ t06; \ 279 z = t03 ^ t06; \
280 t08 = z & t04; \ 280 t08 = z & t04; \
281 t09 = t04 & t05; \ 281 t09 = t04 & t05; \
282 t10 = c ^ t06; \ 282 t10 = c ^ t06; \
283 t11 = b & c ; \ 283 t11 = b & c ; \
284 t12 = t04 ^ t08; \ 284 t12 = t04 ^ t08; \
285 t13 = t11 | t03; \ 285 t13 = t11 | t03; \
286 t14 = t10 ^ t09; \ 286 t14 = t10 ^ t09; \
287 t15 = a & t05; \ 287 t15 = a & t05; \
288 t16 = t11 | t12; \ 288 t16 = t11 | t12; \
289 y = t13 ^ t08; \ 289 y = t13 ^ t08; \
290 x = t15 ^ t16; \ 290 x = t15 ^ t16; \
291 w = ~ t14; \ 291 w = ~ t14; \
292 } 292 }
293 293
294#define SBOX4_INVERSE(a, b, c, d, w, x, y, z) \ 294#define SBOX4_INVERSE(a, b, c, d, w, x, y, z) \
295 { \ 295 { \
296 register unsigned long t02, t03, t04, t05, t06, t07, t09; \ 296 register unsigned long t02, t03, t04, t05, t06, t07, t09; \
297 register unsigned long t10, t11, t12, t13, t15, t01; \ 297 register unsigned long t10, t11, t12, t13, t15, t01; \
298 t01 = b | d ; \ 298 t01 = b | d ; \
299 t02 = c | d ; \ 299 t02 = c | d ; \
300 t03 = a & t01; \ 300 t03 = a & t01; \
301 t04 = b ^ t02; \ 301 t04 = b ^ t02; \
302 t05 = c ^ d ; \ 302 t05 = c ^ d ; \
303 t06 = ~ t03; \ 303 t06 = ~ t03; \
304 t07 = a & t04; \ 304 t07 = a & t04; \
305 x = t05 ^ t07; \ 305 x = t05 ^ t07; \
306 t09 = x | t06; \ 306 t09 = x | t06; \
307 t10 = a ^ t07; \ 307 t10 = a ^ t07; \
308 t11 = t01 ^ t09; \ 308 t11 = t01 ^ t09; \
309 t12 = d ^ t04; \ 309 t12 = d ^ t04; \
310 t13 = c | t10; \ 310 t13 = c | t10; \
311 z = t03 ^ t12; \ 311 z = t03 ^ t12; \
312 t15 = a ^ t04; \ 312 t15 = a ^ t04; \
313 y = t11 ^ t13; \ 313 y = t11 ^ t13; \
314 w = t15 ^ t09; \ 314 w = t15 ^ t09; \
315 } 315 }
316 316
317#define SBOX5(a, b, c, d, w, x, y, z) \ 317#define SBOX5(a, b, c, d, w, x, y, z) \
318 { \ 318 { \
319 register unsigned long t02, t03, t04, t05, t07, t08, t09; \ 319 register unsigned long t02, t03, t04, t05, t07, t08, t09; \
320 register unsigned long t10, t11, t12, t13, t14, t01; \ 320 register unsigned long t10, t11, t12, t13, t14, t01; \
321 t01 = b ^ d ; \ 321 t01 = b ^ d ; \
322 t02 = b | d ; \ 322 t02 = b | d ; \
323 t03 = a & t01; \ 323 t03 = a & t01; \
324 t04 = c ^ t02; \ 324 t04 = c ^ t02; \
325 t05 = t03 ^ t04; \ 325 t05 = t03 ^ t04; \
326 w = ~ t05; \ 326 w = ~ t05; \
327 t07 = a ^ t01; \ 327 t07 = a ^ t01; \
328 t08 = d | w ; \ 328 t08 = d | w ; \
329 t09 = b | t05; \ 329 t09 = b | t05; \
330 t10 = d ^ t08; \ 330 t10 = d ^ t08; \
331 t11 = b | t07; \ 331 t11 = b | t07; \
332 t12 = t03 | w ; \ 332 t12 = t03 | w ; \
333 t13 = t07 | t10; \ 333 t13 = t07 | t10; \
334 t14 = t01 ^ t11; \ 334 t14 = t01 ^ t11; \
335 y = t09 ^ t13; \ 335 y = t09 ^ t13; \
336 x = t07 ^ t08; \ 336 x = t07 ^ t08; \
337 z = t12 ^ t14; \ 337 z = t12 ^ t14; \
338 } 338 }
339 339
340#define SBOX5_INVERSE(a, b, c, d, w, x, y, z) \ 340#define SBOX5_INVERSE(a, b, c, d, w, x, y, z) \
341 { \ 341 { \
342 register unsigned long t02, t03, t04, t05, t07, t08, t09; \ 342 register unsigned long t02, t03, t04, t05, t07, t08, t09; \
343 register unsigned long t10, t12, t13, t15, t16, t01; \ 343 register unsigned long t10, t12, t13, t15, t16, t01; \
344 t01 = a & d ; \ 344 t01 = a & d ; \
345 t02 = c ^ t01; \ 345 t02 = c ^ t01; \
346 t03 = a ^ d ; \ 346 t03 = a ^ d ; \
347 t04 = b & t02; \ 347 t04 = b & t02; \
348 t05 = a & c ; \ 348 t05 = a & c ; \
349 w = t03 ^ t04; \ 349 w = t03 ^ t04; \
350 t07 = a & w ; \ 350 t07 = a & w ; \
351 t08 = t01 ^ w ; \ 351 t08 = t01 ^ w ; \
352 t09 = b | t05; \ 352 t09 = b | t05; \
353 t10 = ~ b ; \ 353 t10 = ~ b ; \
354 x = t08 ^ t09; \ 354 x = t08 ^ t09; \
355 t12 = t10 | t07; \ 355 t12 = t10 | t07; \
356 t13 = w | x ; \ 356 t13 = w | x ; \
357 z = t02 ^ t12; \ 357 z = t02 ^ t12; \
358 t15 = t02 ^ t13; \ 358 t15 = t02 ^ t13; \
359 t16 = b ^ d ; \ 359 t16 = b ^ d ; \
360 y = t16 ^ t15; \ 360 y = t16 ^ t15; \
361 } 361 }
362 362
363#define SBOX6(a, b, c, d, w, x, y, z) \ 363#define SBOX6(a, b, c, d, w, x, y, z) \
364 { \ 364 { \
365 register unsigned long t02, t03, t04, t05, t07, t08, t09, t10; \ 365 register unsigned long t02, t03, t04, t05, t07, t08, t09, t10; \
366 register unsigned long t11, t12, t13, t15, t17, t18, t01; \ 366 register unsigned long t11, t12, t13, t15, t17, t18, t01; \
367 t01 = a & d ; \ 367 t01 = a & d ; \
368 t02 = b ^ c ; \ 368 t02 = b ^ c ; \
369 t03 = a ^ d ; \ 369 t03 = a ^ d ; \
370 t04 = t01 ^ t02; \ 370 t04 = t01 ^ t02; \
371 t05 = b | c ; \ 371 t05 = b | c ; \
372 x = ~ t04; \ 372 x = ~ t04; \
373 t07 = t03 & t05; \ 373 t07 = t03 & t05; \
374 t08 = b & x ; \ 374 t08 = b & x ; \
375 t09 = a | c ; \ 375 t09 = a | c ; \
376 t10 = t07 ^ t08; \ 376 t10 = t07 ^ t08; \
377 t11 = b | d ; \ 377 t11 = b | d ; \
378 t12 = c ^ t11; \ 378 t12 = c ^ t11; \
379 t13 = t09 ^ t10; \ 379 t13 = t09 ^ t10; \
380 y = ~ t13; \ 380 y = ~ t13; \
381 t15 = x & t03; \ 381 t15 = x & t03; \
382 z = t12 ^ t07; \ 382 z = t12 ^ t07; \
383 t17 = a ^ b ; \ 383 t17 = a ^ b ; \
384 t18 = y ^ t15; \ 384 t18 = y ^ t15; \
385 w = t17 ^ t18; \ 385 w = t17 ^ t18; \
386 } 386 }
387 387
388#define SBOX6_INVERSE(a, b, c, d, w, x, y, z) \ 388#define SBOX6_INVERSE(a, b, c, d, w, x, y, z) \
389 { \ 389 { \
390 register unsigned long t02, t03, t04, t05, t06, t07, t08, t09; \ 390 register unsigned long t02, t03, t04, t05, t06, t07, t08, t09; \
391 register unsigned long t12, t13, t14, t15, t16, t17, t01; \ 391 register unsigned long t12, t13, t14, t15, t16, t17, t01; \
392 t01 = a ^ c ; \ 392 t01 = a ^ c ; \
393 t02 = ~ c ; \ 393 t02 = ~ c ; \
394 t03 = b & t01; \ 394 t03 = b & t01; \
395 t04 = b | t02; \ 395 t04 = b | t02; \
396 t05 = d | t03; \ 396 t05 = d | t03; \
397 t06 = b ^ d ; \ 397 t06 = b ^ d ; \
398 t07 = a & t04; \ 398 t07 = a & t04; \
399 t08 = a | t02; \ 399 t08 = a | t02; \
400 t09 = t07 ^ t05; \ 400 t09 = t07 ^ t05; \
401 x = t06 ^ t08; \ 401 x = t06 ^ t08; \
402 w = ~ t09; \ 402 w = ~ t09; \
403 t12 = b & w ; \ 403 t12 = b & w ; \
404 t13 = t01 & t05; \ 404 t13 = t01 & t05; \
405 t14 = t01 ^ t12; \ 405 t14 = t01 ^ t12; \
406 t15 = t07 ^ t13; \ 406 t15 = t07 ^ t13; \
407 t16 = d | t02; \ 407 t16 = d | t02; \
408 t17 = a ^ x ; \ 408 t17 = a ^ x ; \
409 z = t17 ^ t15; \ 409 z = t17 ^ t15; \
410 y = t16 ^ t14; \ 410 y = t16 ^ t14; \
411 } 411 }
412 412
413#define SBOX7(a, b, c, d, w, x, y, z) \ 413#define SBOX7(a, b, c, d, w, x, y, z) \
414 { \ 414 { \
415 register unsigned long t02, t03, t04, t05, t06, t08, t09, t10; \ 415 register unsigned long t02, t03, t04, t05, t06, t08, t09, t10; \
416 register unsigned long t11, t13, t14, t15, t16, t17, t01; \ 416 register unsigned long t11, t13, t14, t15, t16, t17, t01; \
417 t01 = a & c ; \ 417 t01 = a & c ; \
418 t02 = ~ d ; \ 418 t02 = ~ d ; \
419 t03 = a & t02; \ 419 t03 = a & t02; \
420 t04 = b | t01; \ 420 t04 = b | t01; \
421 t05 = a & b ; \ 421 t05 = a & b ; \
422 t06 = c ^ t04; \ 422 t06 = c ^ t04; \
423 z = t03 ^ t06; \ 423 z = t03 ^ t06; \
424 t08 = c | z ; \ 424 t08 = c | z ; \
425 t09 = d | t05; \ 425 t09 = d | t05; \
426 t10 = a ^ t08; \ 426 t10 = a ^ t08; \
427 t11 = t04 & z ; \ 427 t11 = t04 & z ; \
428 x = t09 ^ t10; \ 428 x = t09 ^ t10; \
429 t13 = b ^ x ; \ 429 t13 = b ^ x ; \
430 t14 = t01 ^ x ; \ 430 t14 = t01 ^ x ; \
431 t15 = c ^ t05; \ 431 t15 = c ^ t05; \
432 t16 = t11 | t13; \ 432 t16 = t11 | t13; \
433 t17 = t02 | t14; \ 433 t17 = t02 | t14; \
434 w = t15 ^ t17; \ 434 w = t15 ^ t17; \
435 y = a ^ t16; \ 435 y = a ^ t16; \
436 } 436 }
437 437
438#define SBOX7_INVERSE(a, b, c, d, w, x, y, z) \ 438#define SBOX7_INVERSE(a, b, c, d, w, x, y, z) \
439 { \ 439 { \
440 register unsigned long t02, t03, t04, t06, t07, t08, t09; \ 440 register unsigned long t02, t03, t04, t06, t07, t08, t09; \
441 register unsigned long t10, t11, t13, t14, t15, t16, t01; \ 441 register unsigned long t10, t11, t13, t14, t15, t16, t01; \
442 t01 = a & b ; \ 442 t01 = a & b ; \
443 t02 = a | b ; \ 443 t02 = a | b ; \
444 t03 = c | t01; \ 444 t03 = c | t01; \
445 t04 = d & t02; \ 445 t04 = d & t02; \
446 z = t03 ^ t04; \ 446 z = t03 ^ t04; \
447 t06 = b ^ t04; \ 447 t06 = b ^ t04; \
448 t07 = d ^ z ; \ 448 t07 = d ^ z ; \
449 t08 = ~ t07; \ 449 t08 = ~ t07; \
450 t09 = t06 | t08; \ 450 t09 = t06 | t08; \
451 t10 = b ^ d ; \ 451 t10 = b ^ d ; \
452 t11 = a | d ; \ 452 t11 = a | d ; \
453 x = a ^ t09; \ 453 x = a ^ t09; \
454 t13 = c ^ t06; \ 454 t13 = c ^ t06; \
455 t14 = c & t11; \ 455 t14 = c & t11; \
456 t15 = d | x ; \ 456 t15 = d | x ; \
457 t16 = t01 | t10; \ 457 t16 = t01 | t10; \
458 w = t13 ^ t15; \ 458 w = t13 ^ t15; \
459 y = t14 ^ t16; \ 459 y = t14 ^ t16; \
460 } 460 }
461 461
462/* XOR BLOCK1 into BLOCK0. */ 462/* XOR BLOCK1 into BLOCK0. */
463#define BLOCK_XOR(block0, block1) \ 463#define BLOCK_XOR(block0, block1) \
464 { \ 464 { \
465 block0[0] ^= block1[0]; \ 465 block0[0] ^= block1[0]; \
466 block0[1] ^= block1[1]; \ 466 block0[1] ^= block1[1]; \
467 block0[2] ^= block1[2]; \ 467 block0[2] ^= block1[2]; \
468 block0[3] ^= block1[3]; \ 468 block0[3] ^= block1[3]; \
469 } 469 }
470 470
471/* Copy BLOCK_SRC to BLOCK_DST. */ 471/* Copy BLOCK_SRC to BLOCK_DST. */
472#define BLOCK_COPY(block_dst, block_src) \ 472#define BLOCK_COPY(block_dst, block_src) \
473 { \ 473 { \
474 block_dst[0] = block_src[0]; \ 474 block_dst[0] = block_src[0]; \
475 block_dst[1] = block_src[1]; \ 475 block_dst[1] = block_src[1]; \
476 block_dst[2] = block_src[2]; \ 476 block_dst[2] = block_src[2]; \
477 block_dst[3] = block_src[3]; \ 477 block_dst[3] = block_src[3]; \
478 } 478 }
479 479
480/* Apply SBOX number WHICH to to the block found in ARRAY0 at index 480/* Apply SBOX number WHICH to to the block found in ARRAY0 at index
481 INDEX, writing the output to the block found in ARRAY1 at index 481 INDEX, writing the output to the block found in ARRAY1 at index
482 INDEX. */ 482 INDEX. */
483#define SBOX(which, array0, array1, index) \ 483#define SBOX(which, array0, array1, index) \
484 SBOX##which (array0[index + 0], array0[index + 1], \ 484 SBOX##which (array0[index + 0], array0[index + 1], \
485 array0[index + 2], array0[index + 3], \ 485 array0[index + 2], array0[index + 3], \
486 array1[index + 0], array1[index + 1], \ 486 array1[index + 0], array1[index + 1], \
487 array1[index + 2], array1[index + 3]); 487 array1[index + 2], array1[index + 3]);
488 488
489/* Apply inverse SBOX number WHICH to to the block found in ARRAY0 at 489/* Apply inverse SBOX number WHICH to to the block found in ARRAY0 at
490 index INDEX, writing the output to the block found in ARRAY1 at 490 index INDEX, writing the output to the block found in ARRAY1 at
491 index INDEX. */ 491 index INDEX. */
492#define SBOX_INVERSE(which, array0, array1, index) \ 492#define SBOX_INVERSE(which, array0, array1, index) \
493 SBOX##which##_INVERSE (array0[index + 0], array0[index + 1], \ 493 SBOX##which##_INVERSE (array0[index + 0], array0[index + 1], \
494 array0[index + 2], array0[index + 3], \ 494 array0[index + 2], array0[index + 3], \
495 array1[index + 0], array1[index + 1], \ 495 array1[index + 0], array1[index + 1], \
496 array1[index + 2], array1[index + 3]); 496 array1[index + 2], array1[index + 3]);
497 497
498/* Apply the linear transformation to BLOCK. */ 498/* Apply the linear transformation to BLOCK. */
499#define LINEAR_TRANSFORMATION(block) \ 499#define LINEAR_TRANSFORMATION(block) \
500 { \ 500 { \
501 block[0] = rol (block[0], 13); \ 501 block[0] = rol (block[0], 13); \
502 block[2] = rol (block[2], 3); \ 502 block[2] = rol (block[2], 3); \
503 block[1] = block[1] ^ block[0] ^ block[2]; \ 503 block[1] = block[1] ^ block[0] ^ block[2]; \
504 block[3] = block[3] ^ block[2] ^ (block[0] << 3); \ 504 block[3] = block[3] ^ block[2] ^ (block[0] << 3); \
505 block[1] = rol (block[1], 1); \ 505 block[1] = rol (block[1], 1); \
506 block[3] = rol (block[3], 7); \ 506 block[3] = rol (block[3], 7); \
507 block[0] = block[0] ^ block[1] ^ block[3]; \ 507 block[0] = block[0] ^ block[1] ^ block[3]; \
508 block[2] = block[2] ^ block[3] ^ (block[1] << 7); \ 508 block[2] = block[2] ^ block[3] ^ (block[1] << 7); \
509 block[0] = rol (block[0], 5); \ 509 block[0] = rol (block[0], 5); \
510 block[2] = rol (block[2], 22); \ 510 block[2] = rol (block[2], 22); \
511 } 511 }
512 512
513/* Apply the inverse linear transformation to BLOCK. */ 513/* Apply the inverse linear transformation to BLOCK. */
514#define LINEAR_TRANSFORMATION_INVERSE(block) \ 514#define LINEAR_TRANSFORMATION_INVERSE(block) \
515 { \ 515 { \
516 block[2] = ror (block[2], 22); \ 516 block[2] = ror (block[2], 22); \
517 block[0] = ror (block[0] , 5); \ 517 block[0] = ror (block[0] , 5); \
518 block[2] = block[2] ^ block[3] ^ (block[1] << 7); \ 518 block[2] = block[2] ^ block[3] ^ (block[1] << 7); \
519 block[0] = block[0] ^ block[1] ^ block[3]; \ 519 block[0] = block[0] ^ block[1] ^ block[3]; \
520 block[3] = ror (block[3], 7); \ 520 block[3] = ror (block[3], 7); \
521 block[1] = ror (block[1], 1); \ 521 block[1] = ror (block[1], 1); \
522 block[3] = block[3] ^ block[2] ^ (block[0] << 3); \ 522 block[3] = block[3] ^ block[2] ^ (block[0] << 3); \
523 block[1] = block[1] ^ block[0] ^ block[2]; \ 523 block[1] = block[1] ^ block[0] ^ block[2]; \
524 block[2] = ror (block[2], 3); \ 524 block[2] = ror (block[2], 3); \
525 block[0] = ror (block[0], 13); \ 525 block[0] = ror (block[0], 13); \
526 } 526 }
527 527
528/* Apply a Serpent round to BLOCK, using the SBOX number WHICH and the 528/* Apply a Serpent round to BLOCK, using the SBOX number WHICH and the
529 subkeys contained in SUBKEYS. Use BLOCK_TMP as temporary storage. 529 subkeys contained in SUBKEYS. Use BLOCK_TMP as temporary storage.
530 This macro increments `round'. */ 530 This macro increments `round'. */
531#define ROUND(which, subkeys, block, block_tmp) \ 531#define ROUND(which, subkeys, block, block_tmp) \
532 { \ 532 { \
533 BLOCK_XOR (block, subkeys[round]); \ 533 BLOCK_XOR (block, subkeys[round]); \
534 round++; \ 534 round++; \
535 SBOX (which, block, block_tmp, 0); \ 535 SBOX (which, block, block_tmp, 0); \
536 LINEAR_TRANSFORMATION (block_tmp); \ 536 LINEAR_TRANSFORMATION (block_tmp); \
537 BLOCK_COPY (block, block_tmp); \ 537 BLOCK_COPY (block, block_tmp); \
538 } 538 }
539 539
540/* Apply the last Serpent round to BLOCK, using the SBOX number WHICH 540/* Apply the last Serpent round to BLOCK, using the SBOX number WHICH
541 and the subkeys contained in SUBKEYS. Use BLOCK_TMP as temporary 541 and the subkeys contained in SUBKEYS. Use BLOCK_TMP as temporary
542 storage. The result will be stored in BLOCK_TMP. This macro 542 storage. The result will be stored in BLOCK_TMP. This macro
543 increments `round'. */ 543 increments `round'. */
544#define ROUND_LAST(which, subkeys, block, block_tmp) \ 544#define ROUND_LAST(which, subkeys, block, block_tmp) \
545 { \ 545 { \
546 BLOCK_XOR (block, subkeys[round]); \ 546 BLOCK_XOR (block, subkeys[round]); \
547 round++; \ 547 round++; \
548 SBOX (which, block, block_tmp, 0); \ 548 SBOX (which, block, block_tmp, 0); \
549 BLOCK_XOR (block_tmp, subkeys[round]); \ 549 BLOCK_XOR (block_tmp, subkeys[round]); \
550 round++; \ 550 round++; \
551 } 551 }
552 552
553/* Apply an inverse Serpent round to BLOCK, using the SBOX number 553/* Apply an inverse Serpent round to BLOCK, using the SBOX number
554 WHICH and the subkeys contained in SUBKEYS. Use BLOCK_TMP as 554 WHICH and the subkeys contained in SUBKEYS. Use BLOCK_TMP as
555 temporary storage. This macro increments `round'. */ 555 temporary storage. This macro increments `round'. */
556#define ROUND_INVERSE(which, subkey, block, block_tmp) \ 556#define ROUND_INVERSE(which, subkey, block, block_tmp) \
557 { \ 557 { \
558 LINEAR_TRANSFORMATION_INVERSE (block); \ 558 LINEAR_TRANSFORMATION_INVERSE (block); \
559 SBOX_INVERSE (which, block, block_tmp, 0); \ 559 SBOX_INVERSE (which, block, block_tmp, 0); \
560 BLOCK_XOR (block_tmp, subkey[round]); \ 560 BLOCK_XOR (block_tmp, subkey[round]); \
561 round--; \ 561 round--; \
562 BLOCK_COPY (block, block_tmp); \ 562 BLOCK_COPY (block, block_tmp); \
563 } 563 }
564 564
565/* Apply the first Serpent round to BLOCK, using the SBOX number WHICH 565/* Apply the first Serpent round to BLOCK, using the SBOX number WHICH
566 and the subkeys contained in SUBKEYS. Use BLOCK_TMP as temporary 566 and the subkeys contained in SUBKEYS. Use BLOCK_TMP as temporary
567 storage. The result will be stored in BLOCK_TMP. This macro 567 storage. The result will be stored in BLOCK_TMP. This macro
568 increments `round'. */ 568 increments `round'. */
569#define ROUND_FIRST_INVERSE(which, subkeys, block, block_tmp) \ 569#define ROUND_FIRST_INVERSE(which, subkeys, block, block_tmp) \
570 { \ 570 { \
571 BLOCK_XOR (block, subkeys[round]); \ 571 BLOCK_XOR (block, subkeys[round]); \
572 round--; \ 572 round--; \
573 SBOX_INVERSE (which, block, block_tmp, 0); \ 573 SBOX_INVERSE (which, block, block_tmp, 0); \
574 BLOCK_XOR (block_tmp, subkeys[round]); \ 574 BLOCK_XOR (block_tmp, subkeys[round]); \
575 round--; \ 575 round--; \
576 } 576 }
577 577
578/* Convert the user provided key KEY of KEY_LENGTH bytes into the 578/* Convert the user provided key KEY of KEY_LENGTH bytes into the
579 internally used format. */ 579 internally used format. */
580static void 580static void
581serpent_key_prepare (const byte_t *key, unsigned int key_length, 581serpent_key_prepare (const byte_t *key, unsigned int key_length,
582 serpent_key_t key_prepared) 582 serpent_key_t key_prepared)
583{ 583{
584 int i; 584 int i;
585 585
586 /* Copy key. */ 586 /* Copy key. */
587 for (i = 0; i < key_length / 4; i++) 587 for (i = 0; i < key_length / 4; i++)
588 { 588 {
589#ifdef WORDS_BIGENDIAN 589#ifdef WORDS_BIGENDIAN
590 key_prepared[i] = byte_swap_32 (((u32_t *) key)[i]); 590 key_prepared[i] = byte_swap_32 (((u32_t *) key)[i]);
591#else 591#else
592 key_prepared[i] = ((u32_t *) key)[i]; 592 key_prepared[i] = ((u32_t *) key)[i];
593#endif 593#endif
594 } 594 }
595 595
596 if (i < 8) 596 if (i < 8)
597 { 597 {
598 /* Key must be padded according to the Serpent 598 /* Key must be padded according to the Serpent
599 specification. */ 599 specification. */
600 key_prepared[i] = 0x00000001; 600 key_prepared[i] = 0x00000001;
601 601
602 for (i++; i < 8; i++) 602 for (i++; i < 8; i++)
603 key_prepared[i] = 0; 603 key_prepared[i] = 0;
604 } 604 }
605} 605}
606 606
607/* Derive the 33 subkeys from KEY and store them in SUBKEYS. */ 607/* Derive the 33 subkeys from KEY and store them in SUBKEYS. */
608static void 608static void
609serpent_subkeys_generate (serpent_key_t key, serpent_subkeys_t subkeys) 609serpent_subkeys_generate (serpent_key_t key, serpent_subkeys_t subkeys)
610{ 610{
611 u32_t w_real[140]; /* The `prekey'. */ 611 u32_t w_real[140]; /* The `prekey'. */
612 u32_t k[132]; 612 u32_t k[132];
613 u32_t *w = &w_real[8]; 613 u32_t *w = &w_real[8];
614 int i, j; 614 int i, j;
615 615
616 /* Initialize with key values. */ 616 /* Initialize with key values. */
617 for (i = 0; i < 8; i++) 617 for (i = 0; i < 8; i++)
618 w[i - 8] = key[i]; 618 w[i - 8] = key[i];
619 619
620 /* Expand to intermediate key using the affine recurrence. */ 620 /* Expand to intermediate key using the affine recurrence. */
621 for (i = 0; i < 132; i++) 621 for (i = 0; i < 132; i++)
622 w[i] = rol (w[i - 8] ^ w[i - 5] ^ w[i - 3] ^ w[i - 1] ^ PHI ^ i, 11); 622 w[i] = rol (w[i - 8] ^ w[i - 5] ^ w[i - 3] ^ w[i - 1] ^ PHI ^ i, 11);
623 623
624 /* Calculate subkeys via S-Boxes, in bitslice mode. */ 624 /* Calculate subkeys via S-Boxes, in bitslice mode. */
625 SBOX (3, w, k, 0); 625 SBOX (3, w, k, 0);
626 SBOX (2, w, k, 4); 626 SBOX (2, w, k, 4);
627 SBOX (1, w, k, 8); 627 SBOX (1, w, k, 8);
628 SBOX (0, w, k, 12); 628 SBOX (0, w, k, 12);
629 SBOX (7, w, k, 16); 629 SBOX (7, w, k, 16);
630 SBOX (6, w, k, 20); 630 SBOX (6, w, k, 20);
631 SBOX (5, w, k, 24); 631 SBOX (5, w, k, 24);
632 SBOX (4, w, k, 28); 632 SBOX (4, w, k, 28);
633 SBOX (3, w, k, 32); 633 SBOX (3, w, k, 32);
634 SBOX (2, w, k, 36); 634 SBOX (2, w, k, 36);
635 SBOX (1, w, k, 40); 635 SBOX (1, w, k, 40);
636 SBOX (0, w, k, 44); 636 SBOX (0, w, k, 44);
637 SBOX (7, w, k, 48); 637 SBOX (7, w, k, 48);
638 SBOX (6, w, k, 52); 638 SBOX (6, w, k, 52);
639 SBOX (5, w, k, 56); 639 SBOX (5, w, k, 56);
640 SBOX (4, w, k, 60); 640 SBOX (4, w, k, 60);
641 SBOX (3, w, k, 64); 641 SBOX (3, w, k, 64);
642 SBOX (2, w, k, 68); 642 SBOX (2, w, k, 68);
643 SBOX (1, w, k, 72); 643 SBOX (1, w, k, 72);
644 SBOX (0, w, k, 76); 644 SBOX (0, w, k, 76);
645 SBOX (7, w, k, 80); 645 SBOX (7, w, k, 80);
646 SBOX (6, w, k, 84); 646 SBOX (6, w, k, 84);
647 SBOX (5, w, k, 88); 647 SBOX (5, w, k, 88);
648 SBOX (4, w, k, 92); 648 SBOX (4, w, k, 92);
649 SBOX (3, w, k, 96); 649 SBOX (3, w, k, 96);
650 SBOX (2, w, k, 100); 650 SBOX (2, w, k, 100);
651 SBOX (1, w, k, 104); 651 SBOX (1, w, k, 104);
652 SBOX (0, w, k, 108); 652 SBOX (0, w, k, 108);
653 SBOX (7, w, k, 112); 653 SBOX (7, w, k, 112);
654 SBOX (6, w, k, 116); 654 SBOX (6, w, k, 116);
655 SBOX (5, w, k, 120); 655 SBOX (5, w, k, 120);
656 SBOX (4, w, k, 124); 656 SBOX (4, w, k, 124);
657 SBOX (3, w, k, 128); 657 SBOX (3, w, k, 128);
658 658
659 /* Renumber subkeys. */ 659 /* Renumber subkeys. */
660 for (i = 0; i < ROUNDS + 1; i++) 660 for (i = 0; i < ROUNDS + 1; i++)
661 for (j = 0; j < 4; j++) 661 for (j = 0; j < 4; j++)
662 subkeys[i][j] = k[4 * i + j]; 662 subkeys[i][j] = k[4 * i + j];
663} 663}
664 664
665/* Initialize CONTEXT with the key KEY of KEY_LENGTH bits. */ 665/* Initialize CONTEXT with the key KEY of KEY_LENGTH bits. */
666static void 666static void
667serpent_setkey_internal (serpent_context_t *context, 667serpent_setkey_internal (serpent_context_t *context,
668 const byte_t *key, unsigned int key_length) 668 const byte_t *key, unsigned int key_length)
669{ 669{
670 serpent_key_t key_prepared; 670 serpent_key_t key_prepared;
671 671
672 serpent_key_prepare (key, key_length, key_prepared); 672 serpent_key_prepare (key, key_length, key_prepared);
673 serpent_subkeys_generate (key_prepared, context->keys); 673 serpent_subkeys_generate (key_prepared, context->keys);
674 _gcry_burn_stack (272 * sizeof (u32_t)); 674 _gcry_burn_stack (272 * sizeof (u32_t));
675} 675}
676 676 static const char *serpent_test (void);
677/* Initialize CTX with the key KEY of KEY_LENGTH bytes. */ 677/* Initialize CTX with the key KEY of KEY_LENGTH bytes. */
678static gcry_err_code_t 678static gcry_err_code_t
679serpent_setkey (void *ctx, 679serpent_setkey (void *ctx,
680 const byte_t *key, unsigned int key_length) 680 const byte_t *key, unsigned int key_length)
681{ 681{
682 serpent_context_t *context = ctx; 682 serpent_context_t *context = ctx;
683 static const char *serpent_test_ret; 683 static const char *serpent_test_ret;
684 static int serpent_init_done; 684 static int serpent_init_done;
685 gcry_err_code_t ret = GPG_ERR_NO_ERROR; 685 gcry_err_code_t ret = GPG_ERR_NO_ERROR;
686 686
687 if (! serpent_init_done) 687 if (! serpent_init_done)
688 { 688 {
689 /* Execute a self-test the first time, Serpent is used. */ 689 /* Execute a self-test the first time, Serpent is used. */
690 static const char *serpent_test (void); 690
691 691
692 serpent_test_ret = serpent_test (); 692 serpent_test_ret = serpent_test ();
693 if (serpent_test_ret) 693 if (serpent_test_ret)
694 log_error ("Serpent test failure: %s\n", serpent_test_ret); 694 log_error ("Serpent test failure: %s\n", serpent_test_ret);
695 serpent_init_done = 1; 695 serpent_init_done = 1;
696 } 696 }
697 697
698 if (serpent_test_ret) 698 if (serpent_test_ret)
699 ret = GPG_ERR_SELFTEST_FAILED; 699 ret = GPG_ERR_SELFTEST_FAILED;
700 else 700 else
701 { 701 {
702 serpent_setkey_internal (context, key, key_length); 702 serpent_setkey_internal (context, key, key_length);
703 _gcry_burn_stack (sizeof (serpent_key_t)); 703 _gcry_burn_stack (sizeof (serpent_key_t));
704 } 704 }
705 705
706 return ret; 706 return ret;
707} 707}
708 708
709static void 709static void
710serpent_encrypt_internal (serpent_context_t *context, 710serpent_encrypt_internal (serpent_context_t *context,
711 const serpent_block_t input, serpent_block_t output) 711 const serpent_block_t input, serpent_block_t output)
712{ 712{
713 serpent_block_t b, b_next; 713 serpent_block_t b, b_next;
714 int round = 0; 714 int round = 0;
715 715
716#ifdef WORDS_BIGENDIAN 716#ifdef WORDS_BIGENDIAN
717 b[0] = byte_swap_32 (input[0]); 717 b[0] = byte_swap_32 (input[0]);
718 b[1] = byte_swap_32 (input[1]); 718 b[1] = byte_swap_32 (input[1]);
719 b[2] = byte_swap_32 (input[2]); 719 b[2] = byte_swap_32 (input[2]);
720 b[3] = byte_swap_32 (input[3]); 720 b[3] = byte_swap_32 (input[3]);
721#else 721#else
722 b[0] = input[0]; 722 b[0] = input[0];
723 b[1] = input[1]; 723 b[1] = input[1];
724 b[2] = input[2]; 724 b[2] = input[2];
725 b[3] = input[3]; 725 b[3] = input[3];
726#endif 726#endif
727 727
728 ROUND (0, context->keys, b, b_next); 728 ROUND (0, context->keys, b, b_next);
729 ROUND (1, context->keys, b, b_next); 729 ROUND (1, context->keys, b, b_next);
730 ROUND (2, context->keys, b, b_next); 730 ROUND (2, context->keys, b, b_next);
731 ROUND (3, context->keys, b, b_next); 731 ROUND (3, context->keys, b, b_next);
732 ROUND (4, context->keys, b, b_next); 732 ROUND (4, context->keys, b, b_next);
733 ROUND (5, context->keys, b, b_next); 733 ROUND (5, context->keys, b, b_next);
734 ROUND (6, context->keys, b, b_next); 734 ROUND (6, context->keys, b, b_next);
735 ROUND (7, context->keys, b, b_next); 735 ROUND (7, context->keys, b, b_next);
736 ROUND (0, context->keys, b, b_next); 736 ROUND (0, context->keys, b, b_next);
737 ROUND (1, context->keys, b, b_next); 737 ROUND (1, context->keys, b, b_next);
738 ROUND (2, context->keys, b, b_next); 738 ROUND (2, context->keys, b, b_next);
739 ROUND (3, context->keys, b, b_next); 739 ROUND (3, context->keys, b, b_next);
740 ROUND (4, context->keys, b, b_next); 740 ROUND (4, context->keys, b, b_next);
741 ROUND (5, context->keys, b, b_next); 741 ROUND (5, context->keys, b, b_next);
742 ROUND (6, context->keys, b, b_next); 742 ROUND (6, context->keys, b, b_next);
743 ROUND (7, context->keys, b, b_next); 743 ROUND (7, context->keys, b, b_next);
744 ROUND (0, context->keys, b, b_next); 744 ROUND (0, context->keys, b, b_next);
745 ROUND (1, context->keys, b, b_next); 745 ROUND (1, context->keys, b, b_next);
746 ROUND (2, context->keys, b, b_next); 746 ROUND (2, context->keys, b, b_next);
747 ROUND (3, context->keys, b, b_next); 747 ROUND (3, context->keys, b, b_next);
748 ROUND (4, context->keys, b, b_next); 748 ROUND (4, context->keys, b, b_next);
749 ROUND (5, context->keys, b, b_next); 749 ROUND (5, context->keys, b, b_next);
750 ROUND (6, context->keys, b, b_next); 750 ROUND (6, context->keys, b, b_next);
751 ROUND (7, context->keys, b, b_next); 751 ROUND (7, context->keys, b, b_next);
752 ROUND (0, context->keys, b, b_next); 752 ROUND (0, context->keys, b, b_next);
753 ROUND (1, context->keys, b, b_next); 753 ROUND (1, context->keys, b, b_next);
754 ROUND (2, context->keys, b, b_next); 754 ROUND (2, context->keys, b, b_next);
755 ROUND (3, context->keys, b, b_next); 755 ROUND (3, context->keys, b, b_next);
756 ROUND (4, context->keys, b, b_next); 756 ROUND (4, context->keys, b, b_next);
757 ROUND (5, context->keys, b, b_next); 757 ROUND (5, context->keys, b, b_next);
758 ROUND (6, context->keys, b, b_next); 758 ROUND (6, context->keys, b, b_next);
759 759
760 ROUND_LAST (7, context->keys, b, b_next); 760 ROUND_LAST (7, context->keys, b, b_next);
761 761
762#ifdef WORDS_BIGENDIAN 762#ifdef WORDS_BIGENDIAN
763 output[0] = byte_swap_32 (b_next[0]); 763 output[0] = byte_swap_32 (b_next[0]);
764 output[1] = byte_swap_32 (b_next[1]); 764 output[1] = byte_swap_32 (b_next[1]);
765 output[2] = byte_swap_32 (b_next[2]); 765 output[2] = byte_swap_32 (b_next[2]);
766 output[3] = byte_swap_32 (b_next[3]); 766 output[3] = byte_swap_32 (b_next[3]);
767#else 767#else
768 output[0] = b_next[0]; 768 output[0] = b_next[0];
769 output[1] = b_next[1]; 769 output[1] = b_next[1];
770 output[2] = b_next[2]; 770 output[2] = b_next[2];
771 output[3] = b_next[3]; 771 output[3] = b_next[3];
772#endif 772#endif
773} 773}
774 774
775static void 775static void
776serpent_decrypt_internal (serpent_context_t *context, 776serpent_decrypt_internal (serpent_context_t *context,
777 const serpent_block_t input, serpent_block_t output) 777 const serpent_block_t input, serpent_block_t output)
778{ 778{
779 serpent_block_t b, b_next; 779 serpent_block_t b, b_next;
780 int round = ROUNDS; 780 int round = ROUNDS;
781 781
782#ifdef WORDS_BIGENDIAN 782#ifdef WORDS_BIGENDIAN
783 b_next[0] = byte_swap_32 (input[0]); 783 b_next[0] = byte_swap_32 (input[0]);
784 b_next[1] = byte_swap_32 (input[1]); 784 b_next[1] = byte_swap_32 (input[1]);
785 b_next[2] = byte_swap_32 (input[2]); 785 b_next[2] = byte_swap_32 (input[2]);
786 b_next[3] = byte_swap_32 (input[3]); 786 b_next[3] = byte_swap_32 (input[3]);
787#else 787#else
788 b_next[0] = input[0]; 788 b_next[0] = input[0];
789 b_next[1] = input[1]; 789 b_next[1] = input[1];
790 b_next[2] = input[2]; 790 b_next[2] = input[2];
791 b_next[3] = input[3]; 791 b_next[3] = input[3];
792#endif 792#endif
793 793
794 ROUND_FIRST_INVERSE (7, context->keys, b_next, b); 794 ROUND_FIRST_INVERSE (7, context->keys, b_next, b);
795 795
796 ROUND_INVERSE (6, context->keys, b, b_next); 796 ROUND_INVERSE (6, context->keys, b, b_next);
797 ROUND_INVERSE (5, context->keys, b, b_next); 797 ROUND_INVERSE (5, context->keys, b, b_next);
798 ROUND_INVERSE (4, context->keys, b, b_next); 798 ROUND_INVERSE (4, context->keys, b, b_next);
799 ROUND_INVERSE (3, context->keys, b, b_next); 799 ROUND_INVERSE (3, context->keys, b, b_next);
800 ROUND_INVERSE (2, context->keys, b, b_next); 800 ROUND_INVERSE (2, context->keys, b, b_next);
801 ROUND_INVERSE (1, context->keys, b, b_next); 801 ROUND_INVERSE (1, context->keys, b, b_next);
802 ROUND_INVERSE (0, context->keys, b, b_next); 802 ROUND_INVERSE (0, context->keys, b, b_next);
803 ROUND_INVERSE (7, context->keys, b, b_next); 803 ROUND_INVERSE (7, context->keys, b, b_next);
804 ROUND_INVERSE (6, context->keys, b, b_next); 804 ROUND_INVERSE (6, context->keys, b, b_next);
805 ROUND_INVERSE (5, context->keys, b, b_next); 805 ROUND_INVERSE (5, context->keys, b, b_next);
806 ROUND_INVERSE (4, context->keys, b, b_next); 806 ROUND_INVERSE (4, context->keys, b, b_next);
807 ROUND_INVERSE (3, context->keys, b, b_next); 807 ROUND_INVERSE (3, context->keys, b, b_next);
808 ROUND_INVERSE (2, context->keys, b, b_next); 808 ROUND_INVERSE (2, context->keys, b, b_next);
809 ROUND_INVERSE (1, context->keys, b, b_next); 809 ROUND_INVERSE (1, context->keys, b, b_next);
810 ROUND_INVERSE (0, context->keys, b, b_next); 810 ROUND_INVERSE (0, context->keys, b, b_next);
811 ROUND_INVERSE (7, context->keys, b, b_next); 811 ROUND_INVERSE (7, context->keys, b, b_next);
812 ROUND_INVERSE (6, context->keys, b, b_next); 812 ROUND_INVERSE (6, context->keys, b, b_next);
813 ROUND_INVERSE (5, context->keys, b, b_next); 813 ROUND_INVERSE (5, context->keys, b, b_next);
814 ROUND_INVERSE (4, context->keys, b, b_next); 814 ROUND_INVERSE (4, context->keys, b, b_next);
815 ROUND_INVERSE (3, context->keys, b, b_next); 815 ROUND_INVERSE (3, context->keys, b, b_next);
816 ROUND_INVERSE (2, context->keys, b, b_next); 816 ROUND_INVERSE (2, context->keys, b, b_next);
817 ROUND_INVERSE (1, context->keys, b, b_next); 817 ROUND_INVERSE (1, context->keys, b, b_next);
818 ROUND_INVERSE (0, context->keys, b, b_next); 818 ROUND_INVERSE (0, context->keys, b, b_next);
819 ROUND_INVERSE (7, context->keys, b, b_next); 819 ROUND_INVERSE (7, context->keys, b, b_next);
820 ROUND_INVERSE (6, context->keys, b, b_next); 820 ROUND_INVERSE (6, context->keys, b, b_next);
821 ROUND_INVERSE (5, context->keys, b, b_next); 821 ROUND_INVERSE (5, context->keys, b, b_next);
822 ROUND_INVERSE (4, context->keys, b, b_next); 822 ROUND_INVERSE (4, context->keys, b, b_next);
823 ROUND_INVERSE (3, context->keys, b, b_next); 823 ROUND_INVERSE (3, context->keys, b, b_next);
824 ROUND_INVERSE (2, context->keys, b, b_next); 824 ROUND_INVERSE (2, context->keys, b, b_next);
825 ROUND_INVERSE (1, context->keys, b, b_next); 825 ROUND_INVERSE (1, context->keys, b, b_next);
826 ROUND_INVERSE (0, context->keys, b, b_next); 826 ROUND_INVERSE (0, context->keys, b, b_next);
827 827
828 828
829#ifdef WORDS_BIGENDIAN 829#ifdef WORDS_BIGENDIAN
830 output[0] = byte_swap_32 (b_next[0]); 830 output[0] = byte_swap_32 (b_next[0]);
831 output[1] = byte_swap_32 (b_next[1]); 831 output[1] = byte_swap_32 (b_next[1]);
832 output[2] = byte_swap_32 (b_next[2]); 832 output[2] = byte_swap_32 (b_next[2]);
833 output[3] = byte_swap_32 (b_next[3]); 833 output[3] = byte_swap_32 (b_next[3]);
834#else 834#else
835 output[0] = b_next[0]; 835 output[0] = b_next[0];
836 output[1] = b_next[1]; 836 output[1] = b_next[1];
837 output[2] = b_next[2]; 837 output[2] = b_next[2];
838 output[3] = b_next[3]; 838 output[3] = b_next[3];
839#endif 839#endif
840} 840}
841 841
842static void 842static void
843serpent_encrypt (void *ctx, byte_t *buffer_out, const byte_t *buffer_in) 843serpent_encrypt (void *ctx, byte_t *buffer_out, const byte_t *buffer_in)
844{ 844{
845 serpent_context_t *context = ctx; 845 serpent_context_t *context = ctx;
846 846
847 serpent_encrypt_internal (context, 847 serpent_encrypt_internal (context,
848 (const u32_t *) buffer_in, (u32_t *) buffer_out); 848 (const u32_t *) buffer_in, (u32_t *) buffer_out);
849 _gcry_burn_stack (2 * sizeof (serpent_block_t)); 849 _gcry_burn_stack (2 * sizeof (serpent_block_t));
850} 850}
851 851
852static void 852static void
853serpent_decrypt (void *ctx, byte *buffer_out, const byte *buffer_in) 853serpent_decrypt (void *ctx, byte *buffer_out, const byte *buffer_in)
854{ 854{
855 serpent_context_t *context = ctx; 855 serpent_context_t *context = ctx;
856 856
857 serpent_decrypt_internal (context, 857 serpent_decrypt_internal (context,
858 (const u32_t *) buffer_in, 858 (const u32_t *) buffer_in,
859 (u32_t *) buffer_out); 859 (u32_t *) buffer_out);
860 _gcry_burn_stack (2 * sizeof (serpent_block_t)); 860 _gcry_burn_stack (2 * sizeof (serpent_block_t));
861} 861}
862 862
863 863
864 864
865/* Serpent test. */ 865/* Serpent test. */
866 866
867static const char * 867static const char *
868serpent_test (void) 868serpent_test (void)
869{ 869{
870 serpent_context_t context; 870 serpent_context_t context;
871 unsigned char scratch[16]; 871 unsigned char scratch[16];
872 unsigned int i; 872 unsigned int i;
873 873
874 static struct test 874 static struct test
875 { 875 {
876 int key_length; 876 int key_length;
877 unsigned char key[32]; 877 unsigned char key[32];
878 unsigned char text_plain[16]; 878 unsigned char text_plain[16];
879 unsigned char text_cipher[16]; 879 unsigned char text_cipher[16];
880 } test_data[] = 880 } test_data[] =
881 { 881 {
882 { 882 {
883 16, 883 16,
884 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 884 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
885 "\xD2\x9D\x57\x6F\xCE\xA3\xA3\xA7\xED\x90\x99\xF2\x92\x73\xD7\x8E", 885 "\xD2\x9D\x57\x6F\xCE\xA3\xA3\xA7\xED\x90\x99\xF2\x92\x73\xD7\x8E",
886 "\xB2\x28\x8B\x96\x8A\xE8\xB0\x86\x48\xD1\xCE\x96\x06\xFD\x99\x2D" 886 "\xB2\x28\x8B\x96\x8A\xE8\xB0\x86\x48\xD1\xCE\x96\x06\xFD\x99\x2D"
887 }, 887 },
888 { 888 {
889 24, 889 24,
890 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 890 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
891 "\x00\x00\x00\x00\x00\x00\x00\x00", 891 "\x00\x00\x00\x00\x00\x00\x00\x00",
892 "\xD2\x9D\x57\x6F\xCE\xAB\xA3\xA7\xED\x98\x99\xF2\x92\x7B\xD7\x8E", 892 "\xD2\x9D\x57\x6F\xCE\xAB\xA3\xA7\xED\x98\x99\xF2\x92\x7B\xD7\x8E",
893 "\x13\x0E\x35\x3E\x10\x37\xC2\x24\x05\xE8\xFA\xEF\xB2\xC3\xC3\xE9" 893 "\x13\x0E\x35\x3E\x10\x37\xC2\x24\x05\xE8\xFA\xEF\xB2\xC3\xC3\xE9"
894 }, 894 },
895 { 895 {
896 32, 896 32,
897 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 897 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
898 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 898 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
899 "\xD0\x95\x57\x6F\xCE\xA3\xE3\xA7\xED\x98\xD9\xF2\x90\x73\xD7\x8E", 899 "\xD0\x95\x57\x6F\xCE\xA3\xE3\xA7\xED\x98\xD9\xF2\x90\x73\xD7\x8E",
900 "\xB9\x0E\xE5\x86\x2D\xE6\x91\x68\xF2\xBD\xD5\x12\x5B\x45\x47\x2B" 900 "\xB9\x0E\xE5\x86\x2D\xE6\x91\x68\xF2\xBD\xD5\x12\x5B\x45\x47\x2B"
901 }, 901 },
902 { 902 {
903 32, 903 32,
904 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 904 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
905 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 905 "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
906 "\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00", 906 "\x00\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00",
907 "\x20\x61\xA4\x27\x82\xBD\x52\xEC\x69\x1E\xC3\x83\xB0\x3B\xA7\x7C" 907 "\x20\x61\xA4\x27\x82\xBD\x52\xEC\x69\x1E\xC3\x83\xB0\x3B\xA7\x7C"
908 }, 908 },
909 { 909 {
910 0 910 0
911 }, 911 },
912 }; 912 };
913 913
914 for (i = 0; test_data[i].key_length; i++) 914 for (i = 0; test_data[i].key_length; i++)
915 { 915 {
916 serpent_setkey_internal (&context, test_data[i].key, 916 serpent_setkey_internal (&context, test_data[i].key,
917 test_data[i].key_length); 917 test_data[i].key_length);
918 serpent_encrypt_internal (&context, 918 serpent_encrypt_internal (&context,
919 (const u32_t *) test_data[i].text_plain, 919 (const u32_t *) test_data[i].text_plain,
920 (u32_t *) scratch); 920 (u32_t *) scratch);
921 921
922 if (memcmp (scratch, test_data[i].text_cipher, sizeof (serpent_block_t))) 922 if (memcmp (scratch, test_data[i].text_cipher, sizeof (serpent_block_t)))
923 switch (test_data[i].key_length) 923 switch (test_data[i].key_length)
924 { 924 {
925 case 16: 925 case 16:
926 return "Serpent-128 test encryption failed."; 926 return "Serpent-128 test encryption failed.";
927 case 24: 927 case 24:
928 return "Serpent-192 test encryption failed."; 928 return "Serpent-192 test encryption failed.";
929 case 32: 929 case 32:
930 return "Serpent-256 test encryption failed."; 930 return "Serpent-256 test encryption failed.";
931 } 931 }
932 932
933 serpent_decrypt_internal (&context, 933 serpent_decrypt_internal (&context,
934 (const u32_t *) test_data[i].text_cipher, 934 (const u32_t *) test_data[i].text_cipher,
935 (u32_t *) scratch); 935 (u32_t *) scratch);
936 if (memcmp (scratch, test_data[i].text_plain, sizeof (serpent_block_t))) 936 if (memcmp (scratch, test_data[i].text_plain, sizeof (serpent_block_t)))
937 switch (test_data[i].key_length) 937 switch (test_data[i].key_length)
938 { 938 {
939 case 16: 939 case 16:
940 return "Serpent-128 test decryption failed."; 940 return "Serpent-128 test decryption failed.";
941 case 24: 941 case 24:
942 return "Serpent-192 test decryption failed."; 942 return "Serpent-192 test decryption failed.";
943 case 32: 943 case 32:
944 return "Serpent-256 test decryption failed."; 944 return "Serpent-256 test decryption failed.";
945 } 945 }
946 } 946 }
947 947
948 return NULL; 948 return NULL;
949} 949}
950 950
951 951
952 952
953/* "SERPENT" is an alias for "SERPENT128". */ 953/* "SERPENT" is an alias for "SERPENT128". */
954static const char *cipher_spec_serpent128_aliases[] = 954static const char *cipher_spec_serpent128_aliases[] =
955 { 955 {
956 "SERPENT", 956 "SERPENT",
957 NULL, 957 NULL,
958 }; 958 };
959 959
960gcry_cipher_spec_t _gcry_cipher_spec_serpent128 = 960gcry_cipher_spec_t _gcry_cipher_spec_serpent128 =
961 { 961 {
962 "SERPENT128", cipher_spec_serpent128_aliases, NULL, 16, 128, 962 "SERPENT128", cipher_spec_serpent128_aliases, NULL, 16, 128,
963 sizeof (serpent_context_t), 963 sizeof (serpent_context_t),
964 serpent_setkey, serpent_encrypt, serpent_decrypt, 964 serpent_setkey, serpent_encrypt, serpent_decrypt,
965 }; 965 };
966 966
967gcry_cipher_spec_t _gcry_cipher_spec_serpent192 = 967gcry_cipher_spec_t _gcry_cipher_spec_serpent192 =
968 { 968 {
969 "SERPENT192", NULL, NULL, 16, 192, 969 "SERPENT192", NULL, NULL, 16, 192,
970 sizeof (serpent_context_t), 970 sizeof (serpent_context_t),
971 serpent_setkey, serpent_encrypt, serpent_decrypt, 971 serpent_setkey, serpent_encrypt, serpent_decrypt,
972 }; 972 };
973 973
974gcry_cipher_spec_t _gcry_cipher_spec_serpent256 = 974gcry_cipher_spec_t _gcry_cipher_spec_serpent256 =
975 { 975 {
976 "SERPENT256", NULL, NULL, 16, 256, 976 "SERPENT256", NULL, NULL, 16, 256,
977 sizeof (serpent_context_t), 977 sizeof (serpent_context_t),
978 serpent_setkey, serpent_encrypt, serpent_decrypt, 978 serpent_setkey, serpent_encrypt, serpent_decrypt,
979 }; 979 };
diff --git a/pwmanager/pwmanager/binentrygen.cpp b/pwmanager/pwmanager/binentrygen.cpp
index 7d5ae45..f156a5e 100644
--- a/pwmanager/pwmanager/binentrygen.cpp
+++ b/pwmanager/pwmanager/binentrygen.cpp
@@ -1,71 +1,72 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager 14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20
21#include "binentrygen.h" 20#include "binentrygen.h"
22#include "base64.h" 21#include "base64.h"
23#include "pwmexception.h"
24 22
23#include "pwmexception.h"
24#include "globalstuff.h"
25 25
26void BinEntryGen::encode(const QByteArray &data, 26void BinEntryGen::encode(const QByteArray &data,
27 PwMDataItem *ret, 27 PwMDataItem *ret,
28 DataType type) 28 DataType type)
29{ 29{
30 ret->clear(); 30 ret->clear();
31 ret->name = tostr(static_cast<int>(type)); 31 ret->name = tostr(static_cast<int>(type));
32 ret->binary = true; 32 ret->binary = true;
33 if (data.size() == 0) 33 if (data.size() == 0)
34 return; 34 return;
35 Base64 b64; 35 Base64 b64;
36 string d(data.data(), data.size()); 36 string d(data.data(), data.size());
37 ret->pw = b64.encode(d); 37 ret->pw = b64.encode(d);
38} 38}
39 39
40void BinEntryGen::decode(const PwMDataItem &data, 40void BinEntryGen::decode(const PwMDataItem &data,
41 QByteArray *ret, 41 QByteArray *ret,
42 DataType *type) 42 DataType *type)
43{ 43{
44 BUG_ON(!data.binary); 44 BUG_ON(!data.binary);
45 int t = strtol(data.name.c_str(), 0, 10); 45 int t = strtol(data.name.c_str(), 0, 10);
46 *type = static_cast<DataType>(t); 46 *type = static_cast<DataType>(t);
47 switch (*type) { 47 switch (*type) {
48 case None: 48 case None:
49 case KWalletMap: 49 case KWalletMap:
50 case KWalletStream: 50 case KWalletStream:
51 break; 51 break;
52 default: 52 default:
53 *type = None; 53 *type = None;
54 } 54 }
55 if (data.pw == "") { 55 if (data.pw == "") {
56 ret->fill(0); 56 ret->fill(0);
57 ret->resize(0); 57 ret->resize(0);
58 return; 58 return;
59 } 59 }
60 Base64 b64; 60 Base64 b64;
61 string d(b64.decode(data.pw)); 61 string d(b64.decode(data.pw));
62 ret->duplicate(d.c_str(), d.length()); 62 ret->duplicate(d.c_str(), d.length());
63} 63}
64 64
65BinEntryGen::DataType BinEntryGen::binType(const PwMDataItem &data) 65BinEntryGen::DataType BinEntryGen::binType(const PwMDataItem &data)
66{ 66{
67 if (!data.binary) 67 if (!data.binary)
68 return None; 68 return None;
69 int type = strtol(data.name.c_str(), 0, 10); 69 int type = strtol(data.name.c_str(), 0, 10);
70 return (static_cast<DataType>(type)); 70 return (static_cast<DataType>(type));
71} 71}
72
diff --git a/pwmanager/pwmanager/binentrygen.h b/pwmanager/pwmanager/binentrygen.h
index a58cd42..49288aa 100644
--- a/pwmanager/pwmanager/binentrygen.h
+++ b/pwmanager/pwmanager/binentrygen.h
@@ -1,65 +1,65 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager 14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#ifndef __BINENTRYGEN_H 20#ifndef __BINENTRYGEN_H
21#define __BINENTRYGEN_H 21#define __BINENTRYGEN_H
22 22
23#include "pwmdoc.h"
24 23
25#include <qcstring.h> 24#include <qcstring.h>
26 25
26#include "pwmdoc.h"
27 27
28/** Binary entry generator. 28/** Binary entry generator.
29 * This generator generates a normal struct PwMDataItem 29 * This generator generates a normal struct PwMDataItem
30 * from binary data (using base64 encoding). 30 * from binary data (using base64 encoding).
31 * This mechanism is used to support the binary interface functions 31 * This mechanism is used to support the binary interface functions
32 * of the KWallet emulation, for example. 32 * of the KWallet emulation, for example.
33 * 33 *
34 * The format of the encoded binary data as a PwMDataItem is as follows: 34 * The format of the encoded binary data as a PwMDataItem is as follows:
35 * 35 *
36 * PwMDataItem::desc contains the normal description string for 36 * PwMDataItem::desc contains the normal description string for
37 * this entry. Nothing surprising. 37 * this entry. Nothing surprising.
38 * PwMDataItem::name contains the "DataType" number in ascii format. 38 * PwMDataItem::name contains the "DataType" number in ascii format.
39 * PwMDataItem::pw contains the base64 encoded data stream. 39 * PwMDataItem::pw contains the base64 encoded data stream.
40 * PwMDataItem::binary is always true for binary entries. 40 * PwMDataItem::binary is always true for binary entries.
41 * All other PwMDataItems are currently unused by BinEntryGen. 41 * All other PwMDataItems are currently unused by BinEntryGen.
42 */ 42 */
43class BinEntryGen 43class BinEntryGen
44{ 44{
45public: 45public:
46 enum DataType 46 enum DataType
47 { 47 {
48 None = 0, 48 None = 0,
49 KWalletMap, 49 KWalletMap,
50 KWalletStream 50 KWalletStream
51 }; 51 };
52 52
53public: 53public:
54 BinEntryGen() { } 54 BinEntryGen() { }
55 55
56 /** Encode the binary "data" and return it in "ret" */ 56 /** Encode the binary "data" and return it in "ret" */
57 void encode(const QByteArray &data, PwMDataItem *ret, DataType type); 57 void encode(const QByteArray &data, PwMDataItem *ret, DataType type);
58 /** Decode the "data" and return it as binary "ret" */ 58 /** Decode the "data" and return it as binary "ret" */
59 void decode(const PwMDataItem &data, QByteArray *ret, DataType *type); 59 void decode(const PwMDataItem &data, QByteArray *ret, DataType *type);
60 60
61 /** Return the data type for this binary data item */ 61 /** Return the data type for this binary data item */
62 DataType binType(const PwMDataItem &data); 62 DataType binType(const PwMDataItem &data);
63}; 63};
64 64
65#endif // __BINENTRYGEN_H 65#endif // __BINENTRYGEN_H
diff --git a/pwmanager/pwmanager/blowfish.cpp b/pwmanager/pwmanager/blowfish.cpp
index 2ca58ce..ee29756 100644
--- a/pwmanager/pwmanager/blowfish.cpp
+++ b/pwmanager/pwmanager/blowfish.cpp
@@ -1,579 +1,579 @@
1/* 2003.05.02: Derived from libgcrypt-1.1.12 by Michael Buesch */ 1/* 2003.05.02: Derived from libgcrypt-1.1.12 by Michael Buesch */
2 2
3/* blowfish.c - Blowfish encryption 3/* blowfish.c - Blowfish encryption
4 *Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc. 4 *Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc.
5 * 5 *
6 * This file is part of Libgcrypt. 6 * This file is part of Libgcrypt.
7 * 7 *
8 * Libgcrypt is free software; you can redistribute it and/or modify 8 * Libgcrypt is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser general Public License as 9 * it under the terms of the GNU Lesser general Public License as
10 * published by the Free Software Foundation; either version 2.1 of 10 * published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version. 11 * the License, or (at your option) any later version.
12 * 12 *
13 * Libgcrypt is distributed in the hope that it will be useful, 13 * Libgcrypt is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details. 16 * GNU Lesser General Public License for more details.
17 * 17 *
18 * You should have received a copy of the GNU Lesser General Public 18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this program; if not, write to the Free Software 19 * License along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 * 21 *
22 * For a description of the algorithm, see: 22 * For a description of the algorithm, see:
23 * Bruce Schneier: Applied Cryptography. John Wiley & Sons, 1996. 23 * Bruce Schneier: Applied Cryptography. John Wiley & Sons, 1996.
24 * ISBN 0-471-11709-9. Pages 336 ff. 24 * ISBN 0-471-11709-9. Pages 336 ff.
25 */ 25 */
26 26
27/* Test values: 27/* Test values:
28 * key "abcdefghijklmnopqrstuvwxyz"; 28 * key "abcdefghijklmnopqrstuvwxyz";
29 * plain "BLOWFISH" 29 * plain "BLOWFISH"
30 * cipher 32 4E D0 FE F4 13 A2 03 30 * cipher 32 4E D0 FE F4 13 A2 03
31 * 31 *
32 */ 32 */
33 33
34/*************************************************************************** 34/***************************************************************************
35 * copyright (C) 2004 by Ulf Schenk 35 * copyright (C) 2004 by Ulf Schenk
36 * This file is originaly based on version 1.0.1 of pwmanager 36 * This file is originaly based on version 1.0.1 of pwmanager
37 * and was modified to run on embedded devices that run microkde 37 * and was modified to run on embedded devices that run microkde
38 * 38 *
39 * $Id$ 39 * $Id$
40 **************************************************************************/ 40 **************************************************************************/
41 41
42 42
43#include <string.h> 43#include <string.h>
44#include <stdlib.h> 44#include <stdlib.h>
45 45
46#include "blowfish.h"
47#include "globalstuff.h" 46#include "globalstuff.h"
48 47
48#include "blowfish.h"
49 49
50/* precomputed S boxes */ 50/* precomputed S boxes */
51static const uint32_t ks0[256] = { 51static const uint32_t ks0[256] = {
52 0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7, 0xB8E1AFED, 0x6A267E96, 52 0xD1310BA6, 0x98DFB5AC, 0x2FFD72DB, 0xD01ADFB7, 0xB8E1AFED, 0x6A267E96,
53 0xBA7C9045, 0xF12C7F99, 0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16, 53 0xBA7C9045, 0xF12C7F99, 0x24A19947, 0xB3916CF7, 0x0801F2E2, 0x858EFC16,
54 0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E, 0x0D95748F, 0x728EB658, 54 0x636920D8, 0x71574E69, 0xA458FEA3, 0xF4933D7E, 0x0D95748F, 0x728EB658,
55 0x718BCD58, 0x82154AEE, 0x7B54A41D, 0xC25A59B5, 0x9C30D539, 0x2AF26013, 55 0x718BCD58, 0x82154AEE, 0x7B54A41D, 0xC25A59B5, 0x9C30D539, 0x2AF26013,
56 0xC5D1B023, 0x286085F0, 0xCA417918, 0xB8DB38EF, 0x8E79DCB0, 0x603A180E, 56 0xC5D1B023, 0x286085F0, 0xCA417918, 0xB8DB38EF, 0x8E79DCB0, 0x603A180E,
57 0x6C9E0E8B, 0xB01E8A3E, 0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60, 57 0x6C9E0E8B, 0xB01E8A3E, 0xD71577C1, 0xBD314B27, 0x78AF2FDA, 0x55605C60,
58 0xE65525F3, 0xAA55AB94, 0x57489862, 0x63E81440, 0x55CA396A, 0x2AAB10B6, 58 0xE65525F3, 0xAA55AB94, 0x57489862, 0x63E81440, 0x55CA396A, 0x2AAB10B6,
59 0xB4CC5C34, 0x1141E8CE, 0xA15486AF, 0x7C72E993, 0xB3EE1411, 0x636FBC2A, 59 0xB4CC5C34, 0x1141E8CE, 0xA15486AF, 0x7C72E993, 0xB3EE1411, 0x636FBC2A,
60 0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E, 0xAFD6BA33, 0x6C24CF5C, 60 0x2BA9C55D, 0x741831F6, 0xCE5C3E16, 0x9B87931E, 0xAFD6BA33, 0x6C24CF5C,
61 0x7A325381, 0x28958677, 0x3B8F4898, 0x6B4BB9AF, 0xC4BFE81B, 0x66282193, 61 0x7A325381, 0x28958677, 0x3B8F4898, 0x6B4BB9AF, 0xC4BFE81B, 0x66282193,
62 0x61D809CC, 0xFB21A991, 0x487CAC60, 0x5DEC8032, 0xEF845D5D, 0xE98575B1, 62 0x61D809CC, 0xFB21A991, 0x487CAC60, 0x5DEC8032, 0xEF845D5D, 0xE98575B1,
63 0xDC262302, 0xEB651B88, 0x23893E81, 0xD396ACC5, 0x0F6D6FF3, 0x83F44239, 63 0xDC262302, 0xEB651B88, 0x23893E81, 0xD396ACC5, 0x0F6D6FF3, 0x83F44239,
64 0x2E0B4482, 0xA4842004, 0x69C8F04A, 0x9E1F9B5E, 0x21C66842, 0xF6E96C9A, 64 0x2E0B4482, 0xA4842004, 0x69C8F04A, 0x9E1F9B5E, 0x21C66842, 0xF6E96C9A,
65 0x670C9C61, 0xABD388F0, 0x6A51A0D2, 0xD8542F68, 0x960FA728, 0xAB5133A3, 65 0x670C9C61, 0xABD388F0, 0x6A51A0D2, 0xD8542F68, 0x960FA728, 0xAB5133A3,
66 0x6EEF0B6C, 0x137A3BE4, 0xBA3BF050, 0x7EFB2A98, 0xA1F1651D, 0x39AF0176, 66 0x6EEF0B6C, 0x137A3BE4, 0xBA3BF050, 0x7EFB2A98, 0xA1F1651D, 0x39AF0176,
67 0x66CA593E, 0x82430E88, 0x8CEE8619, 0x456F9FB4, 0x7D84A5C3, 0x3B8B5EBE, 67 0x66CA593E, 0x82430E88, 0x8CEE8619, 0x456F9FB4, 0x7D84A5C3, 0x3B8B5EBE,
68 0xE06F75D8, 0x85C12073, 0x401A449F, 0x56C16AA6, 0x4ED3AA62, 0x363F7706, 68 0xE06F75D8, 0x85C12073, 0x401A449F, 0x56C16AA6, 0x4ED3AA62, 0x363F7706,
69 0x1BFEDF72, 0x429B023D, 0x37D0D724, 0xD00A1248, 0xDB0FEAD3, 0x49F1C09B, 69 0x1BFEDF72, 0x429B023D, 0x37D0D724, 0xD00A1248, 0xDB0FEAD3, 0x49F1C09B,
70 0x075372C9, 0x80991B7B, 0x25D479D8, 0xF6E8DEF7, 0xE3FE501A, 0xB6794C3B, 70 0x075372C9, 0x80991B7B, 0x25D479D8, 0xF6E8DEF7, 0xE3FE501A, 0xB6794C3B,
71 0x976CE0BD, 0x04C006BA, 0xC1A94FB6, 0x409F60C4, 0x5E5C9EC2, 0x196A2463, 71 0x976CE0BD, 0x04C006BA, 0xC1A94FB6, 0x409F60C4, 0x5E5C9EC2, 0x196A2463,
72 0x68FB6FAF, 0x3E6C53B5, 0x1339B2EB, 0x3B52EC6F, 0x6DFC511F, 0x9B30952C, 72 0x68FB6FAF, 0x3E6C53B5, 0x1339B2EB, 0x3B52EC6F, 0x6DFC511F, 0x9B30952C,
73 0xCC814544, 0xAF5EBD09, 0xBEE3D004, 0xDE334AFD, 0x660F2807, 0x192E4BB3, 73 0xCC814544, 0xAF5EBD09, 0xBEE3D004, 0xDE334AFD, 0x660F2807, 0x192E4BB3,
74 0xC0CBA857, 0x45C8740F, 0xD20B5F39, 0xB9D3FBDB, 0x5579C0BD, 0x1A60320A, 74 0xC0CBA857, 0x45C8740F, 0xD20B5F39, 0xB9D3FBDB, 0x5579C0BD, 0x1A60320A,
75 0xD6A100C6, 0x402C7279, 0x679F25FE, 0xFB1FA3CC, 0x8EA5E9F8, 0xDB3222F8, 75 0xD6A100C6, 0x402C7279, 0x679F25FE, 0xFB1FA3CC, 0x8EA5E9F8, 0xDB3222F8,
76 0x3C7516DF, 0xFD616B15, 0x2F501EC8, 0xAD0552AB, 0x323DB5FA, 0xFD238760, 76 0x3C7516DF, 0xFD616B15, 0x2F501EC8, 0xAD0552AB, 0x323DB5FA, 0xFD238760,
77 0x53317B48, 0x3E00DF82, 0x9E5C57BB, 0xCA6F8CA0, 0x1A87562E, 0xDF1769DB, 77 0x53317B48, 0x3E00DF82, 0x9E5C57BB, 0xCA6F8CA0, 0x1A87562E, 0xDF1769DB,
78 0xD542A8F6, 0x287EFFC3, 0xAC6732C6, 0x8C4F5573, 0x695B27B0, 0xBBCA58C8, 78 0xD542A8F6, 0x287EFFC3, 0xAC6732C6, 0x8C4F5573, 0x695B27B0, 0xBBCA58C8,
79 0xE1FFA35D, 0xB8F011A0, 0x10FA3D98, 0xFD2183B8, 0x4AFCB56C, 0x2DD1D35B, 79 0xE1FFA35D, 0xB8F011A0, 0x10FA3D98, 0xFD2183B8, 0x4AFCB56C, 0x2DD1D35B,
80 0x9A53E479, 0xB6F84565, 0xD28E49BC, 0x4BFB9790, 0xE1DDF2DA, 0xA4CB7E33, 80 0x9A53E479, 0xB6F84565, 0xD28E49BC, 0x4BFB9790, 0xE1DDF2DA, 0xA4CB7E33,
81 0x62FB1341, 0xCEE4C6E8, 0xEF20CADA, 0x36774C01, 0xD07E9EFE, 0x2BF11FB4, 81 0x62FB1341, 0xCEE4C6E8, 0xEF20CADA, 0x36774C01, 0xD07E9EFE, 0x2BF11FB4,
82 0x95DBDA4D, 0xAE909198, 0xEAAD8E71, 0x6B93D5A0, 0xD08ED1D0, 0xAFC725E0, 82 0x95DBDA4D, 0xAE909198, 0xEAAD8E71, 0x6B93D5A0, 0xD08ED1D0, 0xAFC725E0,
83 0x8E3C5B2F, 0x8E7594B7, 0x8FF6E2FB, 0xF2122B64, 0x8888B812, 0x900DF01C, 83 0x8E3C5B2F, 0x8E7594B7, 0x8FF6E2FB, 0xF2122B64, 0x8888B812, 0x900DF01C,
84 0x4FAD5EA0, 0x688FC31C, 0xD1CFF191, 0xB3A8C1AD, 0x2F2F2218, 0xBE0E1777, 84 0x4FAD5EA0, 0x688FC31C, 0xD1CFF191, 0xB3A8C1AD, 0x2F2F2218, 0xBE0E1777,
85 0xEA752DFE, 0x8B021FA1, 0xE5A0CC0F, 0xB56F74E8, 0x18ACF3D6, 0xCE89E299, 85 0xEA752DFE, 0x8B021FA1, 0xE5A0CC0F, 0xB56F74E8, 0x18ACF3D6, 0xCE89E299,
86 0xB4A84FE0, 0xFD13E0B7, 0x7CC43B81, 0xD2ADA8D9, 0x165FA266, 0x80957705, 86 0xB4A84FE0, 0xFD13E0B7, 0x7CC43B81, 0xD2ADA8D9, 0x165FA266, 0x80957705,
87 0x93CC7314, 0x211A1477, 0xE6AD2065, 0x77B5FA86, 0xC75442F5, 0xFB9D35CF, 87 0x93CC7314, 0x211A1477, 0xE6AD2065, 0x77B5FA86, 0xC75442F5, 0xFB9D35CF,
88 0xEBCDAF0C, 0x7B3E89A0, 0xD6411BD3, 0xAE1E7E49, 0x00250E2D, 0x2071B35E, 88 0xEBCDAF0C, 0x7B3E89A0, 0xD6411BD3, 0xAE1E7E49, 0x00250E2D, 0x2071B35E,
89 0x226800BB, 0x57B8E0AF, 0x2464369B, 0xF009B91E, 0x5563911D, 0x59DFA6AA, 89 0x226800BB, 0x57B8E0AF, 0x2464369B, 0xF009B91E, 0x5563911D, 0x59DFA6AA,
90 0x78C14389, 0xD95A537F, 0x207D5BA2, 0x02E5B9C5, 0x83260376, 0x6295CFA9, 90 0x78C14389, 0xD95A537F, 0x207D5BA2, 0x02E5B9C5, 0x83260376, 0x6295CFA9,
91 0x11C81968, 0x4E734A41, 0xB3472DCA, 0x7B14A94A, 0x1B510052, 0x9A532915, 91 0x11C81968, 0x4E734A41, 0xB3472DCA, 0x7B14A94A, 0x1B510052, 0x9A532915,
92 0xD60F573F, 0xBC9BC6E4, 0x2B60A476, 0x81E67400, 0x08BA6FB5, 0x571BE91F, 92 0xD60F573F, 0xBC9BC6E4, 0x2B60A476, 0x81E67400, 0x08BA6FB5, 0x571BE91F,
93 0xF296EC6B, 0x2A0DD915, 0xB6636521, 0xE7B9F9B6, 0xFF34052E, 0xC5855664, 93 0xF296EC6B, 0x2A0DD915, 0xB6636521, 0xE7B9F9B6, 0xFF34052E, 0xC5855664,
94 0x53B02D5D, 0xA99F8FA1, 0x08BA4799, 0x6E85076A 94 0x53B02D5D, 0xA99F8FA1, 0x08BA4799, 0x6E85076A
95}; 95};
96 96
97static const uint32_t ks1[256] = { 97static const uint32_t ks1[256] = {
98 0x4B7A70E9, 0xB5B32944, 0xDB75092E, 0xC4192623, 0xAD6EA6B0, 0x49A7DF7D, 98 0x4B7A70E9, 0xB5B32944, 0xDB75092E, 0xC4192623, 0xAD6EA6B0, 0x49A7DF7D,
99 0x9CEE60B8, 0x8FEDB266, 0xECAA8C71, 0x699A17FF, 0x5664526C, 0xC2B19EE1, 99 0x9CEE60B8, 0x8FEDB266, 0xECAA8C71, 0x699A17FF, 0x5664526C, 0xC2B19EE1,
100 0x193602A5, 0x75094C29, 0xA0591340, 0xE4183A3E, 0x3F54989A, 0x5B429D65, 100 0x193602A5, 0x75094C29, 0xA0591340, 0xE4183A3E, 0x3F54989A, 0x5B429D65,
101 0x6B8FE4D6, 0x99F73FD6, 0xA1D29C07, 0xEFE830F5, 0x4D2D38E6, 0xF0255DC1, 101 0x6B8FE4D6, 0x99F73FD6, 0xA1D29C07, 0xEFE830F5, 0x4D2D38E6, 0xF0255DC1,
102 0x4CDD2086, 0x8470EB26, 0x6382E9C6, 0x021ECC5E, 0x09686B3F, 0x3EBAEFC9, 102 0x4CDD2086, 0x8470EB26, 0x6382E9C6, 0x021ECC5E, 0x09686B3F, 0x3EBAEFC9,
103 0x3C971814, 0x6B6A70A1, 0x687F3584, 0x52A0E286, 0xB79C5305, 0xAA500737, 103 0x3C971814, 0x6B6A70A1, 0x687F3584, 0x52A0E286, 0xB79C5305, 0xAA500737,
104 0x3E07841C, 0x7FDEAE5C, 0x8E7D44EC, 0x5716F2B8, 0xB03ADA37, 0xF0500C0D, 104 0x3E07841C, 0x7FDEAE5C, 0x8E7D44EC, 0x5716F2B8, 0xB03ADA37, 0xF0500C0D,
105 0xF01C1F04, 0x0200B3FF, 0xAE0CF51A, 0x3CB574B2, 0x25837A58, 0xDC0921BD, 105 0xF01C1F04, 0x0200B3FF, 0xAE0CF51A, 0x3CB574B2, 0x25837A58, 0xDC0921BD,
106 0xD19113F9, 0x7CA92FF6, 0x94324773, 0x22F54701, 0x3AE5E581, 0x37C2DADC, 106 0xD19113F9, 0x7CA92FF6, 0x94324773, 0x22F54701, 0x3AE5E581, 0x37C2DADC,
107 0xC8B57634, 0x9AF3DDA7, 0xA9446146, 0x0FD0030E, 0xECC8C73E, 0xA4751E41, 107 0xC8B57634, 0x9AF3DDA7, 0xA9446146, 0x0FD0030E, 0xECC8C73E, 0xA4751E41,
108 0xE238CD99, 0x3BEA0E2F, 0x3280BBA1, 0x183EB331, 0x4E548B38, 0x4F6DB908, 108 0xE238CD99, 0x3BEA0E2F, 0x3280BBA1, 0x183EB331, 0x4E548B38, 0x4F6DB908,
109 0x6F420D03, 0xF60A04BF, 0x2CB81290, 0x24977C79, 0x5679B072, 0xBCAF89AF, 109 0x6F420D03, 0xF60A04BF, 0x2CB81290, 0x24977C79, 0x5679B072, 0xBCAF89AF,
110 0xDE9A771F, 0xD9930810, 0xB38BAE12, 0xDCCF3F2E, 0x5512721F, 0x2E6B7124, 110 0xDE9A771F, 0xD9930810, 0xB38BAE12, 0xDCCF3F2E, 0x5512721F, 0x2E6B7124,
111 0x501ADDE6, 0x9F84CD87, 0x7A584718, 0x7408DA17, 0xBC9F9ABC, 0xE94B7D8C, 111 0x501ADDE6, 0x9F84CD87, 0x7A584718, 0x7408DA17, 0xBC9F9ABC, 0xE94B7D8C,
112 0xEC7AEC3A, 0xDB851DFA, 0x63094366, 0xC464C3D2, 0xEF1C1847, 0x3215D908, 112 0xEC7AEC3A, 0xDB851DFA, 0x63094366, 0xC464C3D2, 0xEF1C1847, 0x3215D908,
113 0xDD433B37, 0x24C2BA16, 0x12A14D43, 0x2A65C451, 0x50940002, 0x133AE4DD, 113 0xDD433B37, 0x24C2BA16, 0x12A14D43, 0x2A65C451, 0x50940002, 0x133AE4DD,
114 0x71DFF89E, 0x10314E55, 0x81AC77D6, 0x5F11199B, 0x043556F1, 0xD7A3C76B, 114 0x71DFF89E, 0x10314E55, 0x81AC77D6, 0x5F11199B, 0x043556F1, 0xD7A3C76B,
115 0x3C11183B, 0x5924A509, 0xF28FE6ED, 0x97F1FBFA, 0x9EBABF2C, 0x1E153C6E, 115 0x3C11183B, 0x5924A509, 0xF28FE6ED, 0x97F1FBFA, 0x9EBABF2C, 0x1E153C6E,
116 0x86E34570, 0xEAE96FB1, 0x860E5E0A, 0x5A3E2AB3, 0x771FE71C, 0x4E3D06FA, 116 0x86E34570, 0xEAE96FB1, 0x860E5E0A, 0x5A3E2AB3, 0x771FE71C, 0x4E3D06FA,
117 0x2965DCB9, 0x99E71D0F, 0x803E89D6, 0x5266C825, 0x2E4CC978, 0x9C10B36A, 117 0x2965DCB9, 0x99E71D0F, 0x803E89D6, 0x5266C825, 0x2E4CC978, 0x9C10B36A,
118 0xC6150EBA, 0x94E2EA78, 0xA5FC3C53, 0x1E0A2DF4, 0xF2F74EA7, 0x361D2B3D, 118 0xC6150EBA, 0x94E2EA78, 0xA5FC3C53, 0x1E0A2DF4, 0xF2F74EA7, 0x361D2B3D,
119 0x1939260F, 0x19C27960, 0x5223A708, 0xF71312B6, 0xEBADFE6E, 0xEAC31F66, 119 0x1939260F, 0x19C27960, 0x5223A708, 0xF71312B6, 0xEBADFE6E, 0xEAC31F66,
120 0xE3BC4595, 0xA67BC883, 0xB17F37D1, 0x018CFF28, 0xC332DDEF, 0xBE6C5AA5, 120 0xE3BC4595, 0xA67BC883, 0xB17F37D1, 0x018CFF28, 0xC332DDEF, 0xBE6C5AA5,
121 0x65582185, 0x68AB9802, 0xEECEA50F, 0xDB2F953B, 0x2AEF7DAD, 0x5B6E2F84, 121 0x65582185, 0x68AB9802, 0xEECEA50F, 0xDB2F953B, 0x2AEF7DAD, 0x5B6E2F84,
122 0x1521B628, 0x29076170, 0xECDD4775, 0x619F1510, 0x13CCA830, 0xEB61BD96, 122 0x1521B628, 0x29076170, 0xECDD4775, 0x619F1510, 0x13CCA830, 0xEB61BD96,
123 0x0334FE1E, 0xAA0363CF, 0xB5735C90, 0x4C70A239, 0xD59E9E0B, 0xCBAADE14, 123 0x0334FE1E, 0xAA0363CF, 0xB5735C90, 0x4C70A239, 0xD59E9E0B, 0xCBAADE14,
124 0xEECC86BC, 0x60622CA7, 0x9CAB5CAB, 0xB2F3846E, 0x648B1EAF, 0x19BDF0CA, 124 0xEECC86BC, 0x60622CA7, 0x9CAB5CAB, 0xB2F3846E, 0x648B1EAF, 0x19BDF0CA,
125 0xA02369B9, 0x655ABB50, 0x40685A32, 0x3C2AB4B3, 0x319EE9D5, 0xC021B8F7, 125 0xA02369B9, 0x655ABB50, 0x40685A32, 0x3C2AB4B3, 0x319EE9D5, 0xC021B8F7,
126 0x9B540B19, 0x875FA099, 0x95F7997E, 0x623D7DA8, 0xF837889A, 0x97E32D77, 126 0x9B540B19, 0x875FA099, 0x95F7997E, 0x623D7DA8, 0xF837889A, 0x97E32D77,
127 0x11ED935F, 0x16681281, 0x0E358829, 0xC7E61FD6, 0x96DEDFA1, 0x7858BA99, 127 0x11ED935F, 0x16681281, 0x0E358829, 0xC7E61FD6, 0x96DEDFA1, 0x7858BA99,
128 0x57F584A5, 0x1B227263, 0x9B83C3FF, 0x1AC24696, 0xCDB30AEB, 0x532E3054, 128 0x57F584A5, 0x1B227263, 0x9B83C3FF, 0x1AC24696, 0xCDB30AEB, 0x532E3054,
129 0x8FD948E4, 0x6DBC3128, 0x58EBF2EF, 0x34C6FFEA, 0xFE28ED61, 0xEE7C3C73, 129 0x8FD948E4, 0x6DBC3128, 0x58EBF2EF, 0x34C6FFEA, 0xFE28ED61, 0xEE7C3C73,
130 0x5D4A14D9, 0xE864B7E3, 0x42105D14, 0x203E13E0, 0x45EEE2B6, 0xA3AAABEA, 130 0x5D4A14D9, 0xE864B7E3, 0x42105D14, 0x203E13E0, 0x45EEE2B6, 0xA3AAABEA,
131 0xDB6C4F15, 0xFACB4FD0, 0xC742F442, 0xEF6ABBB5, 0x654F3B1D, 0x41CD2105, 131 0xDB6C4F15, 0xFACB4FD0, 0xC742F442, 0xEF6ABBB5, 0x654F3B1D, 0x41CD2105,
132 0xD81E799E, 0x86854DC7, 0xE44B476A, 0x3D816250, 0xCF62A1F2, 0x5B8D2646, 132 0xD81E799E, 0x86854DC7, 0xE44B476A, 0x3D816250, 0xCF62A1F2, 0x5B8D2646,
133 0xFC8883A0, 0xC1C7B6A3, 0x7F1524C3, 0x69CB7492, 0x47848A0B, 0x5692B285, 133 0xFC8883A0, 0xC1C7B6A3, 0x7F1524C3, 0x69CB7492, 0x47848A0B, 0x5692B285,
134 0x095BBF00, 0xAD19489D, 0x1462B174, 0x23820E00, 0x58428D2A, 0x0C55F5EA, 134 0x095BBF00, 0xAD19489D, 0x1462B174, 0x23820E00, 0x58428D2A, 0x0C55F5EA,
135 0x1DADF43E, 0x233F7061, 0x3372F092, 0x8D937E41, 0xD65FECF1, 0x6C223BDB, 135 0x1DADF43E, 0x233F7061, 0x3372F092, 0x8D937E41, 0xD65FECF1, 0x6C223BDB,
136 0x7CDE3759, 0xCBEE7460, 0x4085F2A7, 0xCE77326E, 0xA6078084, 0x19F8509E, 136 0x7CDE3759, 0xCBEE7460, 0x4085F2A7, 0xCE77326E, 0xA6078084, 0x19F8509E,
137 0xE8EFD855, 0x61D99735, 0xA969A7AA, 0xC50C06C2, 0x5A04ABFC, 0x800BCADC, 137 0xE8EFD855, 0x61D99735, 0xA969A7AA, 0xC50C06C2, 0x5A04ABFC, 0x800BCADC,
138 0x9E447A2E, 0xC3453484, 0xFDD56705, 0x0E1E9EC9, 0xDB73DBD3, 0x105588CD, 138 0x9E447A2E, 0xC3453484, 0xFDD56705, 0x0E1E9EC9, 0xDB73DBD3, 0x105588CD,
139 0x675FDA79, 0xE3674340, 0xC5C43465, 0x713E38D8, 0x3D28F89E, 0xF16DFF20, 139 0x675FDA79, 0xE3674340, 0xC5C43465, 0x713E38D8, 0x3D28F89E, 0xF16DFF20,
140 0x153E21E7, 0x8FB03D4A, 0xE6E39F2B, 0xDB83ADF7 140 0x153E21E7, 0x8FB03D4A, 0xE6E39F2B, 0xDB83ADF7
141}; 141};
142 142
143static const uint32_t ks2[256] = { 143static const uint32_t ks2[256] = {
144 0xE93D5A68, 0x948140F7, 0xF64C261C, 0x94692934, 0x411520F7, 0x7602D4F7, 144 0xE93D5A68, 0x948140F7, 0xF64C261C, 0x94692934, 0x411520F7, 0x7602D4F7,
145 0xBCF46B2E, 0xD4A20068, 0xD4082471, 0x3320F46A, 0x43B7D4B7, 0x500061AF, 145 0xBCF46B2E, 0xD4A20068, 0xD4082471, 0x3320F46A, 0x43B7D4B7, 0x500061AF,
146 0x1E39F62E, 0x97244546, 0x14214F74, 0xBF8B8840, 0x4D95FC1D, 0x96B591AF, 146 0x1E39F62E, 0x97244546, 0x14214F74, 0xBF8B8840, 0x4D95FC1D, 0x96B591AF,
147 0x70F4DDD3, 0x66A02F45, 0xBFBC09EC, 0x03BD9785, 0x7FAC6DD0, 0x31CB8504, 147 0x70F4DDD3, 0x66A02F45, 0xBFBC09EC, 0x03BD9785, 0x7FAC6DD0, 0x31CB8504,
148 0x96EB27B3, 0x55FD3941, 0xDA2547E6, 0xABCA0A9A, 0x28507825, 0x530429F4, 148 0x96EB27B3, 0x55FD3941, 0xDA2547E6, 0xABCA0A9A, 0x28507825, 0x530429F4,
149 0x0A2C86DA, 0xE9B66DFB, 0x68DC1462, 0xD7486900, 0x680EC0A4, 0x27A18DEE, 149 0x0A2C86DA, 0xE9B66DFB, 0x68DC1462, 0xD7486900, 0x680EC0A4, 0x27A18DEE,
150 0x4F3FFEA2, 0xE887AD8C, 0xB58CE006, 0x7AF4D6B6, 0xAACE1E7C, 0xD3375FEC, 150 0x4F3FFEA2, 0xE887AD8C, 0xB58CE006, 0x7AF4D6B6, 0xAACE1E7C, 0xD3375FEC,
151 0xCE78A399, 0x406B2A42, 0x20FE9E35, 0xD9F385B9, 0xEE39D7AB, 0x3B124E8B, 151 0xCE78A399, 0x406B2A42, 0x20FE9E35, 0xD9F385B9, 0xEE39D7AB, 0x3B124E8B,
152 0x1DC9FAF7, 0x4B6D1856, 0x26A36631, 0xEAE397B2, 0x3A6EFA74, 0xDD5B4332, 152 0x1DC9FAF7, 0x4B6D1856, 0x26A36631, 0xEAE397B2, 0x3A6EFA74, 0xDD5B4332,
153 0x6841E7F7, 0xCA7820FB, 0xFB0AF54E, 0xD8FEB397, 0x454056AC, 0xBA489527, 153 0x6841E7F7, 0xCA7820FB, 0xFB0AF54E, 0xD8FEB397, 0x454056AC, 0xBA489527,
154 0x55533A3A, 0x20838D87, 0xFE6BA9B7, 0xD096954B, 0x55A867BC, 0xA1159A58, 154 0x55533A3A, 0x20838D87, 0xFE6BA9B7, 0xD096954B, 0x55A867BC, 0xA1159A58,
155 0xCCA92963, 0x99E1DB33, 0xA62A4A56, 0x3F3125F9, 0x5EF47E1C, 0x9029317C, 155 0xCCA92963, 0x99E1DB33, 0xA62A4A56, 0x3F3125F9, 0x5EF47E1C, 0x9029317C,
156 0xFDF8E802, 0x04272F70, 0x80BB155C, 0x05282CE3, 0x95C11548, 0xE4C66D22, 156 0xFDF8E802, 0x04272F70, 0x80BB155C, 0x05282CE3, 0x95C11548, 0xE4C66D22,
157 0x48C1133F, 0xC70F86DC, 0x07F9C9EE, 0x41041F0F, 0x404779A4, 0x5D886E17, 157 0x48C1133F, 0xC70F86DC, 0x07F9C9EE, 0x41041F0F, 0x404779A4, 0x5D886E17,
158 0x325F51EB, 0xD59BC0D1, 0xF2BCC18F, 0x41113564, 0x257B7834, 0x602A9C60, 158 0x325F51EB, 0xD59BC0D1, 0xF2BCC18F, 0x41113564, 0x257B7834, 0x602A9C60,
159 0xDFF8E8A3, 0x1F636C1B, 0x0E12B4C2, 0x02E1329E, 0xAF664FD1, 0xCAD18115, 159 0xDFF8E8A3, 0x1F636C1B, 0x0E12B4C2, 0x02E1329E, 0xAF664FD1, 0xCAD18115,
160 0x6B2395E0, 0x333E92E1, 0x3B240B62, 0xEEBEB922, 0x85B2A20E, 0xE6BA0D99, 160 0x6B2395E0, 0x333E92E1, 0x3B240B62, 0xEEBEB922, 0x85B2A20E, 0xE6BA0D99,
161 0xDE720C8C, 0x2DA2F728, 0xD0127845, 0x95B794FD, 0x647D0862, 0xE7CCF5F0, 161 0xDE720C8C, 0x2DA2F728, 0xD0127845, 0x95B794FD, 0x647D0862, 0xE7CCF5F0,
162 0x5449A36F, 0x877D48FA, 0xC39DFD27, 0xF33E8D1E, 0x0A476341, 0x992EFF74, 162 0x5449A36F, 0x877D48FA, 0xC39DFD27, 0xF33E8D1E, 0x0A476341, 0x992EFF74,
163 0x3A6F6EAB, 0xF4F8FD37, 0xA812DC60, 0xA1EBDDF8, 0x991BE14C, 0xDB6E6B0D, 163 0x3A6F6EAB, 0xF4F8FD37, 0xA812DC60, 0xA1EBDDF8, 0x991BE14C, 0xDB6E6B0D,
164 0xC67B5510, 0x6D672C37, 0x2765D43B, 0xDCD0E804, 0xF1290DC7, 0xCC00FFA3, 164 0xC67B5510, 0x6D672C37, 0x2765D43B, 0xDCD0E804, 0xF1290DC7, 0xCC00FFA3,
165 0xB5390F92, 0x690FED0B, 0x667B9FFB, 0xCEDB7D9C, 0xA091CF0B, 0xD9155EA3, 165 0xB5390F92, 0x690FED0B, 0x667B9FFB, 0xCEDB7D9C, 0xA091CF0B, 0xD9155EA3,
166 0xBB132F88, 0x515BAD24, 0x7B9479BF, 0x763BD6EB, 0x37392EB3, 0xCC115979, 166 0xBB132F88, 0x515BAD24, 0x7B9479BF, 0x763BD6EB, 0x37392EB3, 0xCC115979,
167 0x8026E297, 0xF42E312D, 0x6842ADA7, 0xC66A2B3B, 0x12754CCC, 0x782EF11C, 167 0x8026E297, 0xF42E312D, 0x6842ADA7, 0xC66A2B3B, 0x12754CCC, 0x782EF11C,
168 0x6A124237, 0xB79251E7, 0x06A1BBE6, 0x4BFB6350, 0x1A6B1018, 0x11CAEDFA, 168 0x6A124237, 0xB79251E7, 0x06A1BBE6, 0x4BFB6350, 0x1A6B1018, 0x11CAEDFA,
169 0x3D25BDD8, 0xE2E1C3C9, 0x44421659, 0x0A121386, 0xD90CEC6E, 0xD5ABEA2A, 169 0x3D25BDD8, 0xE2E1C3C9, 0x44421659, 0x0A121386, 0xD90CEC6E, 0xD5ABEA2A,
170 0x64AF674E, 0xDA86A85F, 0xBEBFE988, 0x64E4C3FE, 0x9DBC8057, 0xF0F7C086, 170 0x64AF674E, 0xDA86A85F, 0xBEBFE988, 0x64E4C3FE, 0x9DBC8057, 0xF0F7C086,
171 0x60787BF8, 0x6003604D, 0xD1FD8346, 0xF6381FB0, 0x7745AE04, 0xD736FCCC, 171 0x60787BF8, 0x6003604D, 0xD1FD8346, 0xF6381FB0, 0x7745AE04, 0xD736FCCC,
172 0x83426B33, 0xF01EAB71, 0xB0804187, 0x3C005E5F, 0x77A057BE, 0xBDE8AE24, 172 0x83426B33, 0xF01EAB71, 0xB0804187, 0x3C005E5F, 0x77A057BE, 0xBDE8AE24,
173 0x55464299, 0xBF582E61, 0x4E58F48F, 0xF2DDFDA2, 0xF474EF38, 0x8789BDC2, 173 0x55464299, 0xBF582E61, 0x4E58F48F, 0xF2DDFDA2, 0xF474EF38, 0x8789BDC2,
174 0x5366F9C3, 0xC8B38E74, 0xB475F255, 0x46FCD9B9, 0x7AEB2661, 0x8B1DDF84, 174 0x5366F9C3, 0xC8B38E74, 0xB475F255, 0x46FCD9B9, 0x7AEB2661, 0x8B1DDF84,
175 0x846A0E79, 0x915F95E2, 0x466E598E, 0x20B45770, 0x8CD55591, 0xC902DE4C, 175 0x846A0E79, 0x915F95E2, 0x466E598E, 0x20B45770, 0x8CD55591, 0xC902DE4C,
176 0xB90BACE1, 0xBB8205D0, 0x11A86248, 0x7574A99E, 0xB77F19B6, 0xE0A9DC09, 176 0xB90BACE1, 0xBB8205D0, 0x11A86248, 0x7574A99E, 0xB77F19B6, 0xE0A9DC09,
177 0x662D09A1, 0xC4324633, 0xE85A1F02, 0x09F0BE8C, 0x4A99A025, 0x1D6EFE10, 177 0x662D09A1, 0xC4324633, 0xE85A1F02, 0x09F0BE8C, 0x4A99A025, 0x1D6EFE10,
178 0x1AB93D1D, 0x0BA5A4DF, 0xA186F20F, 0x2868F169, 0xDCB7DA83, 0x573906FE, 178 0x1AB93D1D, 0x0BA5A4DF, 0xA186F20F, 0x2868F169, 0xDCB7DA83, 0x573906FE,
179 0xA1E2CE9B, 0x4FCD7F52, 0x50115E01, 0xA70683FA, 0xA002B5C4, 0x0DE6D027, 179 0xA1E2CE9B, 0x4FCD7F52, 0x50115E01, 0xA70683FA, 0xA002B5C4, 0x0DE6D027,
180 0x9AF88C27, 0x773F8641, 0xC3604C06, 0x61A806B5, 0xF0177A28, 0xC0F586E0, 180 0x9AF88C27, 0x773F8641, 0xC3604C06, 0x61A806B5, 0xF0177A28, 0xC0F586E0,
181 0x006058AA, 0x30DC7D62, 0x11E69ED7, 0x2338EA63, 0x53C2DD94, 0xC2C21634, 181 0x006058AA, 0x30DC7D62, 0x11E69ED7, 0x2338EA63, 0x53C2DD94, 0xC2C21634,
182 0xBBCBEE56, 0x90BCB6DE, 0xEBFC7DA1, 0xCE591D76, 0x6F05E409, 0x4B7C0188, 182 0xBBCBEE56, 0x90BCB6DE, 0xEBFC7DA1, 0xCE591D76, 0x6F05E409, 0x4B7C0188,
183 0x39720A3D, 0x7C927C24, 0x86E3725F, 0x724D9DB9, 0x1AC15BB4, 0xD39EB8FC, 183 0x39720A3D, 0x7C927C24, 0x86E3725F, 0x724D9DB9, 0x1AC15BB4, 0xD39EB8FC,
184 0xED545578, 0x08FCA5B5, 0xD83D7CD3, 0x4DAD0FC4, 0x1E50EF5E, 0xB161E6F8, 184 0xED545578, 0x08FCA5B5, 0xD83D7CD3, 0x4DAD0FC4, 0x1E50EF5E, 0xB161E6F8,
185 0xA28514D9, 0x6C51133C, 0x6FD5C7E7, 0x56E14EC4, 0x362ABFCE, 0xDDC6C837, 185 0xA28514D9, 0x6C51133C, 0x6FD5C7E7, 0x56E14EC4, 0x362ABFCE, 0xDDC6C837,
186 0xD79A3234, 0x92638212, 0x670EFA8E, 0x406000E0 186 0xD79A3234, 0x92638212, 0x670EFA8E, 0x406000E0
187}; 187};
188 188
189static const uint32_t ks3[256] = { 189static const uint32_t ks3[256] = {
190 0x3A39CE37, 0xD3FAF5CF, 0xABC27737, 0x5AC52D1B, 0x5CB0679E, 0x4FA33742, 190 0x3A39CE37, 0xD3FAF5CF, 0xABC27737, 0x5AC52D1B, 0x5CB0679E, 0x4FA33742,
191 0xD3822740, 0x99BC9BBE, 0xD5118E9D, 0xBF0F7315, 0xD62D1C7E, 0xC700C47B, 191 0xD3822740, 0x99BC9BBE, 0xD5118E9D, 0xBF0F7315, 0xD62D1C7E, 0xC700C47B,
192 0xB78C1B6B, 0x21A19045, 0xB26EB1BE, 0x6A366EB4, 0x5748AB2F, 0xBC946E79, 192 0xB78C1B6B, 0x21A19045, 0xB26EB1BE, 0x6A366EB4, 0x5748AB2F, 0xBC946E79,
193 0xC6A376D2, 0x6549C2C8, 0x530FF8EE, 0x468DDE7D, 0xD5730A1D, 0x4CD04DC6, 193 0xC6A376D2, 0x6549C2C8, 0x530FF8EE, 0x468DDE7D, 0xD5730A1D, 0x4CD04DC6,
194 0x2939BBDB, 0xA9BA4650, 0xAC9526E8, 0xBE5EE304, 0xA1FAD5F0, 0x6A2D519A, 194 0x2939BBDB, 0xA9BA4650, 0xAC9526E8, 0xBE5EE304, 0xA1FAD5F0, 0x6A2D519A,
195 0x63EF8CE2, 0x9A86EE22, 0xC089C2B8, 0x43242EF6, 0xA51E03AA, 0x9CF2D0A4, 195 0x63EF8CE2, 0x9A86EE22, 0xC089C2B8, 0x43242EF6, 0xA51E03AA, 0x9CF2D0A4,
196 0x83C061BA, 0x9BE96A4D, 0x8FE51550, 0xBA645BD6, 0x2826A2F9, 0xA73A3AE1, 196 0x83C061BA, 0x9BE96A4D, 0x8FE51550, 0xBA645BD6, 0x2826A2F9, 0xA73A3AE1,
197 0x4BA99586, 0xEF5562E9, 0xC72FEFD3, 0xF752F7DA, 0x3F046F69, 0x77FA0A59, 197 0x4BA99586, 0xEF5562E9, 0xC72FEFD3, 0xF752F7DA, 0x3F046F69, 0x77FA0A59,
198 0x80E4A915, 0x87B08601, 0x9B09E6AD, 0x3B3EE593, 0xE990FD5A, 0x9E34D797, 198 0x80E4A915, 0x87B08601, 0x9B09E6AD, 0x3B3EE593, 0xE990FD5A, 0x9E34D797,
199 0x2CF0B7D9, 0x022B8B51, 0x96D5AC3A, 0x017DA67D, 0xD1CF3ED6, 0x7C7D2D28, 199 0x2CF0B7D9, 0x022B8B51, 0x96D5AC3A, 0x017DA67D, 0xD1CF3ED6, 0x7C7D2D28,
200 0x1F9F25CF, 0xADF2B89B, 0x5AD6B472, 0x5A88F54C, 0xE029AC71, 0xE019A5E6, 200 0x1F9F25CF, 0xADF2B89B, 0x5AD6B472, 0x5A88F54C, 0xE029AC71, 0xE019A5E6,
201 0x47B0ACFD, 0xED93FA9B, 0xE8D3C48D, 0x283B57CC, 0xF8D56629, 0x79132E28, 201 0x47B0ACFD, 0xED93FA9B, 0xE8D3C48D, 0x283B57CC, 0xF8D56629, 0x79132E28,
202 0x785F0191, 0xED756055, 0xF7960E44, 0xE3D35E8C, 0x15056DD4, 0x88F46DBA, 202 0x785F0191, 0xED756055, 0xF7960E44, 0xE3D35E8C, 0x15056DD4, 0x88F46DBA,
203 0x03A16125, 0x0564F0BD, 0xC3EB9E15, 0x3C9057A2, 0x97271AEC, 0xA93A072A, 203 0x03A16125, 0x0564F0BD, 0xC3EB9E15, 0x3C9057A2, 0x97271AEC, 0xA93A072A,
204 0x1B3F6D9B, 0x1E6321F5, 0xF59C66FB, 0x26DCF319, 0x7533D928, 0xB155FDF5, 204 0x1B3F6D9B, 0x1E6321F5, 0xF59C66FB, 0x26DCF319, 0x7533D928, 0xB155FDF5,
205 0x03563482, 0x8ABA3CBB, 0x28517711, 0xC20AD9F8, 0xABCC5167, 0xCCAD925F, 205 0x03563482, 0x8ABA3CBB, 0x28517711, 0xC20AD9F8, 0xABCC5167, 0xCCAD925F,
206 0x4DE81751, 0x3830DC8E, 0x379D5862, 0x9320F991, 0xEA7A90C2, 0xFB3E7BCE, 206 0x4DE81751, 0x3830DC8E, 0x379D5862, 0x9320F991, 0xEA7A90C2, 0xFB3E7BCE,
207 0x5121CE64, 0x774FBE32, 0xA8B6E37E, 0xC3293D46, 0x48DE5369, 0x6413E680, 207 0x5121CE64, 0x774FBE32, 0xA8B6E37E, 0xC3293D46, 0x48DE5369, 0x6413E680,
208 0xA2AE0810, 0xDD6DB224, 0x69852DFD, 0x09072166, 0xB39A460A, 0x6445C0DD, 208 0xA2AE0810, 0xDD6DB224, 0x69852DFD, 0x09072166, 0xB39A460A, 0x6445C0DD,
209 0x586CDECF, 0x1C20C8AE, 0x5BBEF7DD, 0x1B588D40, 0xCCD2017F, 0x6BB4E3BB, 209 0x586CDECF, 0x1C20C8AE, 0x5BBEF7DD, 0x1B588D40, 0xCCD2017F, 0x6BB4E3BB,
210 0xDDA26A7E, 0x3A59FF45, 0x3E350A44, 0xBCB4CDD5, 0x72EACEA8, 0xFA6484BB, 210 0xDDA26A7E, 0x3A59FF45, 0x3E350A44, 0xBCB4CDD5, 0x72EACEA8, 0xFA6484BB,
211 0x8D6612AE, 0xBF3C6F47, 0xD29BE463, 0x542F5D9E, 0xAEC2771B, 0xF64E6370, 211 0x8D6612AE, 0xBF3C6F47, 0xD29BE463, 0x542F5D9E, 0xAEC2771B, 0xF64E6370,
212 0x740E0D8D, 0xE75B1357, 0xF8721671, 0xAF537D5D, 0x4040CB08, 0x4EB4E2CC, 212 0x740E0D8D, 0xE75B1357, 0xF8721671, 0xAF537D5D, 0x4040CB08, 0x4EB4E2CC,
213 0x34D2466A, 0x0115AF84, 0xE1B00428, 0x95983A1D, 0x06B89FB4, 0xCE6EA048, 213 0x34D2466A, 0x0115AF84, 0xE1B00428, 0x95983A1D, 0x06B89FB4, 0xCE6EA048,
214 0x6F3F3B82, 0x3520AB82, 0x011A1D4B, 0x277227F8, 0x611560B1, 0xE7933FDC, 214 0x6F3F3B82, 0x3520AB82, 0x011A1D4B, 0x277227F8, 0x611560B1, 0xE7933FDC,
215 0xBB3A792B, 0x344525BD, 0xA08839E1, 0x51CE794B, 0x2F32C9B7, 0xA01FBAC9, 215 0xBB3A792B, 0x344525BD, 0xA08839E1, 0x51CE794B, 0x2F32C9B7, 0xA01FBAC9,
216 0xE01CC87E, 0xBCC7D1F6, 0xCF0111C3, 0xA1E8AAC7, 0x1A908749, 0xD44FBD9A, 216 0xE01CC87E, 0xBCC7D1F6, 0xCF0111C3, 0xA1E8AAC7, 0x1A908749, 0xD44FBD9A,
217 0xD0DADECB, 0xD50ADA38, 0x0339C32A, 0xC6913667, 0x8DF9317C, 0xE0B12B4F, 217 0xD0DADECB, 0xD50ADA38, 0x0339C32A, 0xC6913667, 0x8DF9317C, 0xE0B12B4F,
218 0xF79E59B7, 0x43F5BB3A, 0xF2D519FF, 0x27D9459C, 0xBF97222C, 0x15E6FC2A, 218 0xF79E59B7, 0x43F5BB3A, 0xF2D519FF, 0x27D9459C, 0xBF97222C, 0x15E6FC2A,
219 0x0F91FC71, 0x9B941525, 0xFAE59361, 0xCEB69CEB, 0xC2A86459, 0x12BAA8D1, 219 0x0F91FC71, 0x9B941525, 0xFAE59361, 0xCEB69CEB, 0xC2A86459, 0x12BAA8D1,
220 0xB6C1075E, 0xE3056A0C, 0x10D25065, 0xCB03A442, 0xE0EC6E0E, 0x1698DB3B, 220 0xB6C1075E, 0xE3056A0C, 0x10D25065, 0xCB03A442, 0xE0EC6E0E, 0x1698DB3B,
221 0x4C98A0BE, 0x3278E964, 0x9F1F9532, 0xE0D392DF, 0xD3A0342B, 0x8971F21E, 221 0x4C98A0BE, 0x3278E964, 0x9F1F9532, 0xE0D392DF, 0xD3A0342B, 0x8971F21E,
222 0x1B0A7441, 0x4BA3348C, 0xC5BE7120, 0xC37632D8, 0xDF359F8D, 0x9B992F2E, 222 0x1B0A7441, 0x4BA3348C, 0xC5BE7120, 0xC37632D8, 0xDF359F8D, 0x9B992F2E,
223 0xE60B6F47, 0x0FE3F11D, 0xE54CDA54, 0x1EDAD891, 0xCE6279CF, 0xCD3E7E6F, 223 0xE60B6F47, 0x0FE3F11D, 0xE54CDA54, 0x1EDAD891, 0xCE6279CF, 0xCD3E7E6F,
224 0x1618B166, 0xFD2C1D05, 0x848FD2C5, 0xF6FB2299, 0xF523F357, 0xA6327623, 224 0x1618B166, 0xFD2C1D05, 0x848FD2C5, 0xF6FB2299, 0xF523F357, 0xA6327623,
225 0x93A83531, 0x56CCCD02, 0xACF08162, 0x5A75EBB5, 0x6E163697, 0x88D273CC, 225 0x93A83531, 0x56CCCD02, 0xACF08162, 0x5A75EBB5, 0x6E163697, 0x88D273CC,
226 0xDE966292, 0x81B949D0, 0x4C50901B, 0x71C65614, 0xE6C6C7BD, 0x327A140A, 226 0xDE966292, 0x81B949D0, 0x4C50901B, 0x71C65614, 0xE6C6C7BD, 0x327A140A,
227 0x45E1D006, 0xC3F27B9A, 0xC9AA53FD, 0x62A80F00, 0xBB25BFE2, 0x35BDD2F6, 227 0x45E1D006, 0xC3F27B9A, 0xC9AA53FD, 0x62A80F00, 0xBB25BFE2, 0x35BDD2F6,
228 0x71126905, 0xB2040222, 0xB6CBCF7C, 0xCD769C2B, 0x53113EC0, 0x1640E3D3, 228 0x71126905, 0xB2040222, 0xB6CBCF7C, 0xCD769C2B, 0x53113EC0, 0x1640E3D3,
229 0x38ABBD60, 0x2547ADF0, 0xBA38209C, 0xF746CE76, 0x77AFA1C5, 0x20756060, 229 0x38ABBD60, 0x2547ADF0, 0xBA38209C, 0xF746CE76, 0x77AFA1C5, 0x20756060,
230 0x85CBFE4E, 0x8AE88DD8, 0x7AAAF9B0, 0x4CF9AA7E, 0x1948C25C, 0x02FB8A8C, 230 0x85CBFE4E, 0x8AE88DD8, 0x7AAAF9B0, 0x4CF9AA7E, 0x1948C25C, 0x02FB8A8C,
231 0x01C36AE4, 0xD6EBE1F9, 0x90D4F869, 0xA65CDEA0, 0x3F09252D, 0xC208E69F, 231 0x01C36AE4, 0xD6EBE1F9, 0x90D4F869, 0xA65CDEA0, 0x3F09252D, 0xC208E69F,
232 0xB74E6132, 0xCE77E25B, 0x578FDFE3, 0x3AC372E6 232 0xB74E6132, 0xCE77E25B, 0x578FDFE3, 0x3AC372E6
233}; 233};
234 234
235static const uint32_t ps[BLOWFISH_ROUNDS + 2] = { 235static const uint32_t ps[BLOWFISH_ROUNDS + 2] = {
236 0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, 0xA4093822, 0x299F31D0, 236 0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344, 0xA4093822, 0x299F31D0,
237 0x082EFA98, 0xEC4E6C89, 0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C, 237 0x082EFA98, 0xEC4E6C89, 0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
238 0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917, 0x9216D5D9, 0x8979FB1B 238 0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917, 0x9216D5D9, 0x8979FB1B
239}; 239};
240 240
241void Blowfish::burn_stack(int bytes) 241void Blowfish::burn_stack(int bytes)
242{ 242{
243 char buf[64]; 243 char buf[64];
244 244
245 memset(buf, 0, sizeof buf); 245 memset(buf, 0, sizeof buf);
246 bytes -= sizeof buf; 246 bytes -= sizeof buf;
247 if (bytes > 0) 247 if (bytes > 0)
248 burn_stack(bytes); 248 burn_stack(bytes);
249} 249}
250 250
251void Blowfish::do_encrypt(uint32_t * ret_xl, uint32_t * ret_xr) 251void Blowfish::do_encrypt(uint32_t * ret_xl, uint32_t * ret_xr)
252{ 252{
253#if BLOWFISH_ROUNDS == 16 253#if BLOWFISH_ROUNDS == 16
254 uint32_t xl, xr, *s0, *s1, *s2, *s3, *p; 254 uint32_t xl, xr, *s0, *s1, *s2, *s3, *p;
255 255
256 xl = *ret_xl; 256 xl = *ret_xl;
257 xr = *ret_xr; 257 xr = *ret_xr;
258 p = bc.p; 258 p = bc.p;
259 s0 = bc.s0; 259 s0 = bc.s0;
260 s1 = bc.s1; 260 s1 = bc.s1;
261 s2 = bc.s2; 261 s2 = bc.s2;
262 s3 = bc.s3; 262 s3 = bc.s3;
263 263
264 R(xl, xr, 0, p, s0, s1, s2, s3); 264 R(xl, xr, 0, p, s0, s1, s2, s3);
265 R(xr, xl, 1, p, s0, s1, s2, s3); 265 R(xr, xl, 1, p, s0, s1, s2, s3);
266 R(xl, xr, 2, p, s0, s1, s2, s3); 266 R(xl, xr, 2, p, s0, s1, s2, s3);
267 R(xr, xl, 3, p, s0, s1, s2, s3); 267 R(xr, xl, 3, p, s0, s1, s2, s3);
268 R(xl, xr, 4, p, s0, s1, s2, s3); 268 R(xl, xr, 4, p, s0, s1, s2, s3);
269 R(xr, xl, 5, p, s0, s1, s2, s3); 269 R(xr, xl, 5, p, s0, s1, s2, s3);
270 R(xl, xr, 6, p, s0, s1, s2, s3); 270 R(xl, xr, 6, p, s0, s1, s2, s3);
271 R(xr, xl, 7, p, s0, s1, s2, s3); 271 R(xr, xl, 7, p, s0, s1, s2, s3);
272 R(xl, xr, 8, p, s0, s1, s2, s3); 272 R(xl, xr, 8, p, s0, s1, s2, s3);
273 R(xr, xl, 9, p, s0, s1, s2, s3); 273 R(xr, xl, 9, p, s0, s1, s2, s3);
274 R(xl, xr, 10, p, s0, s1, s2, s3); 274 R(xl, xr, 10, p, s0, s1, s2, s3);
275 R(xr, xl, 11, p, s0, s1, s2, s3); 275 R(xr, xl, 11, p, s0, s1, s2, s3);
276 R(xl, xr, 12, p, s0, s1, s2, s3); 276 R(xl, xr, 12, p, s0, s1, s2, s3);
277 R(xr, xl, 13, p, s0, s1, s2, s3); 277 R(xr, xl, 13, p, s0, s1, s2, s3);
278 R(xl, xr, 14, p, s0, s1, s2, s3); 278 R(xl, xr, 14, p, s0, s1, s2, s3);
279 R(xr, xl, 15, p, s0, s1, s2, s3); 279 R(xr, xl, 15, p, s0, s1, s2, s3);
280 280
281 xl ^= p[BLOWFISH_ROUNDS]; 281 xl ^= p[BLOWFISH_ROUNDS];
282 xr ^= p[BLOWFISH_ROUNDS + 1]; 282 xr ^= p[BLOWFISH_ROUNDS + 1];
283 283
284 *ret_xl = xr; 284 *ret_xl = xr;
285 *ret_xr = xl; 285 *ret_xr = xl;
286 286
287#else 287#else
288 uint32_t xl, xr, temp, *p; 288 uint32_t xl, xr, temp, *p;
289 int i; 289 int i;
290 290
291 xl = *ret_xl; 291 xl = *ret_xl;
292 xr = *ret_xr; 292 xr = *ret_xr;
293 p = bc.p; 293 p = bc.p;
294 294
295 for (i = 0; i < BLOWFISH_ROUNDS; i++) { 295 for (i = 0; i < BLOWFISH_ROUNDS; i++) {
296 xl ^= p[i]; 296 xl ^= p[i];
297 xr ^= function_F(xl); 297 xr ^= function_F(xl);
298 temp = xl; 298 temp = xl;
299 xl = xr; 299 xl = xr;
300 xr = temp; 300 xr = temp;
301 } 301 }
302 temp = xl; 302 temp = xl;
303 xl = xr; 303 xl = xr;
304 xr = temp; 304 xr = temp;
305 305
306 xr ^= p[BLOWFISH_ROUNDS]; 306 xr ^= p[BLOWFISH_ROUNDS];
307 xl ^= p[BLOWFISH_ROUNDS + 1]; 307 xl ^= p[BLOWFISH_ROUNDS + 1];
308 308
309 *ret_xl = xl; 309 *ret_xl = xl;
310 *ret_xr = xr; 310 *ret_xr = xr;
311#endif 311#endif
312} 312}
313 313
314void Blowfish::do_decrypt(uint32_t * ret_xl, uint32_t * ret_xr) 314void Blowfish::do_decrypt(uint32_t * ret_xl, uint32_t * ret_xr)
315{ 315{
316#if BLOWFISH_ROUNDS == 16 316#if BLOWFISH_ROUNDS == 16
317 uint32_t xl, xr, *s0, *s1, *s2, *s3, *p; 317 uint32_t xl, xr, *s0, *s1, *s2, *s3, *p;
318 318
319 xl = *ret_xl; 319 xl = *ret_xl;
320 xr = *ret_xr; 320 xr = *ret_xr;
321 p = bc.p; 321 p = bc.p;
322 s0 = bc.s0; 322 s0 = bc.s0;
323 s1 = bc.s1; 323 s1 = bc.s1;
324 s2 = bc.s2; 324 s2 = bc.s2;
325 s3 = bc.s3; 325 s3 = bc.s3;
326 326
327 R(xl, xr, 17, p, s0, s1, s2, s3); 327 R(xl, xr, 17, p, s0, s1, s2, s3);
328 R(xr, xl, 16, p, s0, s1, s2, s3); 328 R(xr, xl, 16, p, s0, s1, s2, s3);
329 R(xl, xr, 15, p, s0, s1, s2, s3); 329 R(xl, xr, 15, p, s0, s1, s2, s3);
330 R(xr, xl, 14, p, s0, s1, s2, s3); 330 R(xr, xl, 14, p, s0, s1, s2, s3);
331 R(xl, xr, 13, p, s0, s1, s2, s3); 331 R(xl, xr, 13, p, s0, s1, s2, s3);
332 R(xr, xl, 12, p, s0, s1, s2, s3); 332 R(xr, xl, 12, p, s0, s1, s2, s3);
333 R(xl, xr, 11, p, s0, s1, s2, s3); 333 R(xl, xr, 11, p, s0, s1, s2, s3);
334 R(xr, xl, 10, p, s0, s1, s2, s3); 334 R(xr, xl, 10, p, s0, s1, s2, s3);
335 R(xl, xr, 9, p, s0, s1, s2, s3); 335 R(xl, xr, 9, p, s0, s1, s2, s3);
336 R(xr, xl, 8, p, s0, s1, s2, s3); 336 R(xr, xl, 8, p, s0, s1, s2, s3);
337 R(xl, xr, 7, p, s0, s1, s2, s3); 337 R(xl, xr, 7, p, s0, s1, s2, s3);
338 R(xr, xl, 6, p, s0, s1, s2, s3); 338 R(xr, xl, 6, p, s0, s1, s2, s3);
339 R(xl, xr, 5, p, s0, s1, s2, s3); 339 R(xl, xr, 5, p, s0, s1, s2, s3);
340 R(xr, xl, 4, p, s0, s1, s2, s3); 340 R(xr, xl, 4, p, s0, s1, s2, s3);
341 R(xl, xr, 3, p, s0, s1, s2, s3); 341 R(xl, xr, 3, p, s0, s1, s2, s3);
342 R(xr, xl, 2, p, s0, s1, s2, s3); 342 R(xr, xl, 2, p, s0, s1, s2, s3);
343 343
344 xl ^= p[1]; 344 xl ^= p[1];
345 xr ^= p[0]; 345 xr ^= p[0];
346 346
347 *ret_xl = xr; 347 *ret_xl = xr;
348 *ret_xr = xl; 348 *ret_xr = xl;
349 349
350#else 350#else
351 uint32_t xl, xr, temp, *p; 351 uint32_t xl, xr, temp, *p;
352 int i; 352 int i;
353 353
354 xl = *ret_xl; 354 xl = *ret_xl;
355 xr = *ret_xr; 355 xr = *ret_xr;
356 p = bc.p; 356 p = bc.p;
357 357
358 for (i = BLOWFISH_ROUNDS + 1; i > 1; i--) { 358 for (i = BLOWFISH_ROUNDS + 1; i > 1; i--) {
359 xl ^= p[i]; 359 xl ^= p[i];
360 xr ^= function_F(xl); 360 xr ^= function_F(xl);
361 temp = xl; 361 temp = xl;
362 xl = xr; 362 xl = xr;
363 xr = temp; 363 xr = temp;
364 } 364 }
365 365
366 temp = xl; 366 temp = xl;
367 xl = xr; 367 xl = xr;
368 xr = temp; 368 xr = temp;
369 369
370 xr ^= p[1]; 370 xr ^= p[1];
371 xl ^= p[0]; 371 xl ^= p[0];
372 372
373 *ret_xl = xl; 373 *ret_xl = xl;
374 *ret_xr = xr; 374 *ret_xr = xr;
375#endif 375#endif
376} 376}
377 377
378void Blowfish::do_encrypt_block(byte * outbuf, byte * inbuf) 378void Blowfish::do_encrypt_block(byte * outbuf, byte * inbuf)
379{ 379{
380 uint32_t d1, d2; 380 uint32_t d1, d2;
381 381
382 d1 = inbuf[0] << 24 | inbuf[1] << 16 | inbuf[2] << 8 | inbuf[3]; 382 d1 = inbuf[0] << 24 | inbuf[1] << 16 | inbuf[2] << 8 | inbuf[3];
383 d2 = inbuf[4] << 24 | inbuf[5] << 16 | inbuf[6] << 8 | inbuf[7]; 383 d2 = inbuf[4] << 24 | inbuf[5] << 16 | inbuf[6] << 8 | inbuf[7];
384 do_encrypt(&d1, &d2); 384 do_encrypt(&d1, &d2);
385 outbuf[0] = (d1 >> 24) & 0xff; 385 outbuf[0] = (d1 >> 24) & 0xff;
386 outbuf[1] = (d1 >> 16) & 0xff; 386 outbuf[1] = (d1 >> 16) & 0xff;
387 outbuf[2] = (d1 >> 8) & 0xff; 387 outbuf[2] = (d1 >> 8) & 0xff;
388 outbuf[3] = d1 & 0xff; 388 outbuf[3] = d1 & 0xff;
389 outbuf[4] = (d2 >> 24) & 0xff; 389 outbuf[4] = (d2 >> 24) & 0xff;
390 outbuf[5] = (d2 >> 16) & 0xff; 390 outbuf[5] = (d2 >> 16) & 0xff;
391 outbuf[6] = (d2 >> 8) & 0xff; 391 outbuf[6] = (d2 >> 8) & 0xff;
392 outbuf[7] = d2 & 0xff; 392 outbuf[7] = d2 & 0xff;
393} 393}
394 394
395void Blowfish::encrypt_block(byte * outbuf, byte * inbuf) 395void Blowfish::encrypt_block(byte * outbuf, byte * inbuf)
396{ 396{
397 do_encrypt_block(outbuf, inbuf); 397 do_encrypt_block(outbuf, inbuf);
398 burn_stack(64); 398 burn_stack(64);
399} 399}
400 400
401void Blowfish::do_decrypt_block(byte * outbuf, byte * inbuf) 401void Blowfish::do_decrypt_block(byte * outbuf, byte * inbuf)
402{ 402{
403 uint32_t d1, d2; 403 uint32_t d1, d2;
404 404
405 d1 = inbuf[0] << 24 | inbuf[1] << 16 | inbuf[2] << 8 | inbuf[3]; 405 d1 = inbuf[0] << 24 | inbuf[1] << 16 | inbuf[2] << 8 | inbuf[3];
406 d2 = inbuf[4] << 24 | inbuf[5] << 16 | inbuf[6] << 8 | inbuf[7]; 406 d2 = inbuf[4] << 24 | inbuf[5] << 16 | inbuf[6] << 8 | inbuf[7];
407 do_decrypt(&d1, &d2); 407 do_decrypt(&d1, &d2);
408 outbuf[0] = (d1 >> 24) & 0xff; 408 outbuf[0] = (d1 >> 24) & 0xff;
409 outbuf[1] = (d1 >> 16) & 0xff; 409 outbuf[1] = (d1 >> 16) & 0xff;
410 outbuf[2] = (d1 >> 8) & 0xff; 410 outbuf[2] = (d1 >> 8) & 0xff;
411 outbuf[3] = d1 & 0xff; 411 outbuf[3] = d1 & 0xff;
412 outbuf[4] = (d2 >> 24) & 0xff; 412 outbuf[4] = (d2 >> 24) & 0xff;
413 outbuf[5] = (d2 >> 16) & 0xff; 413 outbuf[5] = (d2 >> 16) & 0xff;
414 outbuf[6] = (d2 >> 8) & 0xff; 414 outbuf[6] = (d2 >> 8) & 0xff;
415 outbuf[7] = d2 & 0xff; 415 outbuf[7] = d2 & 0xff;
416} 416}
417 417
418void Blowfish::decrypt_block(byte * outbuf, byte * inbuf) 418void Blowfish::decrypt_block(byte * outbuf, byte * inbuf)
419{ 419{
420 do_decrypt_block(outbuf, inbuf); 420 do_decrypt_block(outbuf, inbuf);
421 burn_stack(64); 421 burn_stack(64);
422} 422}
423 423
424bool Blowfish::selfTest() 424bool Blowfish::selfTest()
425{ 425{
426 byte plain1[] = "BLOWFISH"; 426 byte plain1[] = "BLOWFISH";
427 byte key1[] = "abcdefghijklmnopqrstuvwxyz"; 427 byte key1[] = "abcdefghijklmnopqrstuvwxyz";
428 byte cipher1[] = "\x32\x4E\xD0\xFE\xF4\x13\xA2\x03"; 428 byte cipher1[] = "\x32\x4E\xD0\xFE\xF4\x13\xA2\x03";
429 byte plain2[] = "\xFE\xDC\xBA\x98\x76\x54\x32\x10"; 429 byte plain2[] = "\xFE\xDC\xBA\x98\x76\x54\x32\x10";
430 byte key2[] = "\x41\x79\x6E\xA0\x52\x61\x6E\xE4"; 430 byte key2[] = "\x41\x79\x6E\xA0\x52\x61\x6E\xE4";
431 byte cipher2[] = "\xE1\x13\xF4\x10\x2C\xFC\xCE\x43"; 431 byte cipher2[] = "\xE1\x13\xF4\x10\x2C\xFC\xCE\x43";
432 byte buffer[8]; 432 byte buffer[8];
433 433
434 Blowfish blowfish; 434 Blowfish blowfish;
435 435
436 blowfish.bf_setkey(key1, array_size(key1) - 1); 436 blowfish.bf_setkey(key1, array_size(key1) - 1);
437 blowfish.bf_encrypt(buffer, plain1, array_size(plain1) - 1); 437 blowfish.bf_encrypt(buffer, plain1, array_size(plain1) - 1);
438 if (unlikely(memcmp(buffer, cipher1, array_size(cipher1) - 1))) 438 if (unlikely(memcmp(buffer, cipher1, array_size(cipher1) - 1)))
439 return false; 439 return false;
440 440
441 blowfish.bf_decrypt(buffer, buffer, array_size(buffer)); 441 blowfish.bf_decrypt(buffer, buffer, array_size(buffer));
442 if (unlikely(memcmp(buffer, plain1, array_size(plain1) - 1))) 442 if (unlikely(memcmp(buffer, plain1, array_size(plain1) - 1)))
443 return false; 443 return false;
444 444
445 blowfish.bf_setkey(key2, array_size(key2) - 1); 445 blowfish.bf_setkey(key2, array_size(key2) - 1);
446 blowfish.bf_encrypt(buffer, plain2, array_size(plain2) - 1); 446 blowfish.bf_encrypt(buffer, plain2, array_size(plain2) - 1);
447 if (unlikely(memcmp(buffer, cipher2, array_size(cipher2) - 1))) 447 if (unlikely(memcmp(buffer, cipher2, array_size(cipher2) - 1)))
448 return false; 448 return false;
449 449
450 blowfish.bf_decrypt(buffer, buffer, array_size(buffer)); 450 blowfish.bf_decrypt(buffer, buffer, array_size(buffer));
451 if (unlikely(memcmp(buffer, plain2, array_size(plain2) - 1))) 451 if (unlikely(memcmp(buffer, plain2, array_size(plain2) - 1)))
452 return false; 452 return false;
453 453
454 return true; 454 return true;
455} 455}
456 456
457int Blowfish::do_bf_setkey(byte * key, unsigned int keylen) 457int Blowfish::do_bf_setkey(byte * key, unsigned int keylen)
458{ 458{
459 int i, j; 459 int i, j;
460 uint32_t data, datal, datar; 460 uint32_t data, datal, datar;
461 461
462 for (i = 0; i < BLOWFISH_ROUNDS + 2; ++i) 462 for (i = 0; i < BLOWFISH_ROUNDS + 2; ++i)
463 bc.p[i] = ps[i]; 463 bc.p[i] = ps[i];
464 for (i = 0; i < 256; ++i) { 464 for (i = 0; i < 256; ++i) {
465 bc.s0[i] = ks0[i]; 465 bc.s0[i] = ks0[i];
466 bc.s1[i] = ks1[i]; 466 bc.s1[i] = ks1[i];
467 bc.s2[i] = ks2[i]; 467 bc.s2[i] = ks2[i];
468 bc.s3[i] = ks3[i]; 468 bc.s3[i] = ks3[i];
469 } 469 }
470 470
471 for (i = j = 0; i < BLOWFISH_ROUNDS + 2; ++i) { 471 for (i = j = 0; i < BLOWFISH_ROUNDS + 2; ++i) {
472#ifdef BIG_ENDIAN_HOST 472#ifdef BIG_ENDIAN_HOST
473 ((byte *) & data)[0] = key[j]; 473 ((byte *) & data)[0] = key[j];
474 ((byte *) & data)[1] = key[(j + 1) % keylen]; 474 ((byte *) & data)[1] = key[(j + 1) % keylen];
475 ((byte *) & data)[2] = key[(j + 2) % keylen]; 475 ((byte *) & data)[2] = key[(j + 2) % keylen];
476 ((byte *) & data)[3] = key[(j + 3) % keylen]; 476 ((byte *) & data)[3] = key[(j + 3) % keylen];
477#else 477#else
478 ((byte *) & data)[3] = key[j]; 478 ((byte *) & data)[3] = key[j];
479 ((byte *) & data)[2] = key[(j + 1) % keylen]; 479 ((byte *) & data)[2] = key[(j + 1) % keylen];
480 ((byte *) & data)[1] = key[(j + 2) % keylen]; 480 ((byte *) & data)[1] = key[(j + 2) % keylen];
481 ((byte *) & data)[0] = key[(j + 3) % keylen]; 481 ((byte *) & data)[0] = key[(j + 3) % keylen];
482#endif 482#endif
483 bc.p[i] ^= data; 483 bc.p[i] ^= data;
484 j = (j + 4) % keylen; 484 j = (j + 4) % keylen;
485 } 485 }
486 486
487 datal = datar = 0; 487 datal = datar = 0;
488 for (i = 0; i < BLOWFISH_ROUNDS + 2; i += 2) { 488 for (i = 0; i < BLOWFISH_ROUNDS + 2; i += 2) {
489 do_encrypt(&datal, &datar); 489 do_encrypt(&datal, &datar);
490 bc.p[i] = datal; 490 bc.p[i] = datal;
491 bc.p[i + 1] = datar; 491 bc.p[i + 1] = datar;
492 } 492 }
493 for (i = 0; i < 256; i += 2) { 493 for (i = 0; i < 256; i += 2) {
494 do_encrypt(&datal, &datar); 494 do_encrypt(&datal, &datar);
495 bc.s0[i] = datal; 495 bc.s0[i] = datal;
496 bc.s0[i + 1] = datar; 496 bc.s0[i + 1] = datar;
497 } 497 }
498 for (i = 0; i < 256; i += 2) { 498 for (i = 0; i < 256; i += 2) {
499 do_encrypt(&datal, &datar); 499 do_encrypt(&datal, &datar);
500 bc.s1[i] = datal; 500 bc.s1[i] = datal;
501 bc.s1[i + 1] = datar; 501 bc.s1[i + 1] = datar;
502 } 502 }
503 for (i = 0; i < 256; i += 2) { 503 for (i = 0; i < 256; i += 2) {
504 do_encrypt(&datal, &datar); 504 do_encrypt(&datal, &datar);
505 bc.s2[i] = datal; 505 bc.s2[i] = datal;
506 bc.s2[i + 1] = datar; 506 bc.s2[i + 1] = datar;
507 } 507 }
508 for (i = 0; i < 256; i += 2) { 508 for (i = 0; i < 256; i += 2) {
509 do_encrypt(&datal, &datar); 509 do_encrypt(&datal, &datar);
510 bc.s3[i] = datal; 510 bc.s3[i] = datal;
511 bc.s3[i + 1] = datar; 511 bc.s3[i + 1] = datar;
512 } 512 }
513 513
514 /* Check for weak key. A weak key is a key in which a value in */ 514 /* Check for weak key. A weak key is a key in which a value in */
515 /* the P-array (here c) occurs more than once per table. */ 515 /* the P-array (here c) occurs more than once per table. */
516 for (i = 0; i < 255; ++i) { 516 for (i = 0; i < 255; ++i) {
517 for (j = i + 1; j < 256; ++j) { 517 for (j = i + 1; j < 256; ++j) {
518 if ((bc.s0[i] == bc.s0[j]) || (bc.s1[i] == bc.s1[j]) || 518 if ((bc.s0[i] == bc.s0[j]) || (bc.s1[i] == bc.s1[j]) ||
519 (bc.s2[i] == bc.s2[j]) || (bc.s3[i] == bc.s3[j])) 519 (bc.s2[i] == bc.s2[j]) || (bc.s3[i] == bc.s3[j]))
520 return 1; 520 return 1;
521 } 521 }
522 } 522 }
523 523
524 return 0; 524 return 0;
525} 525}
526 526
527int Blowfish::bf_setkey(byte * key, unsigned int keylen) 527int Blowfish::bf_setkey(byte * key, unsigned int keylen)
528{ 528{
529 int rc = do_bf_setkey(key, keylen); 529 int rc = do_bf_setkey(key, keylen);
530 burn_stack(64); 530 burn_stack(64);
531 return rc; 531 return rc;
532} 532}
533 533
534int Blowfish::bf_encrypt(byte * outbuf, byte * inbuf, unsigned int inbuf_len) 534int Blowfish::bf_encrypt(byte * outbuf, byte * inbuf, unsigned int inbuf_len)
535{ 535{
536 if (unlikely(inbuf_len % 8)) 536 if (unlikely(inbuf_len % 8))
537 return 1; 537 return 1;
538 538
539 unsigned int i = 0; 539 unsigned int i = 0;
540 while (i < inbuf_len) { 540 while (i < inbuf_len) {
541 encrypt_block(outbuf + i, inbuf + i); 541 encrypt_block(outbuf + i, inbuf + i);
542 i += 8; 542 i += 8;
543 } 543 }
544 return 0; 544 return 0;
545} 545}
546 546
547int Blowfish::bf_decrypt(byte * outbuf, byte * inbuf, unsigned int inbuf_len) 547int Blowfish::bf_decrypt(byte * outbuf, byte * inbuf, unsigned int inbuf_len)
548{ 548{
549 if (unlikely(inbuf_len % 8)) 549 if (unlikely(inbuf_len % 8))
550 return 1; 550 return 1;
551 551
552 unsigned int i = 0; 552 unsigned int i = 0;
553 while (i < inbuf_len) { 553 while (i < inbuf_len) {
554 decrypt_block(outbuf + i, inbuf + i); 554 decrypt_block(outbuf + i, inbuf + i);
555 i += 8; 555 i += 8;
556 } 556 }
557 return 0; 557 return 0;
558} 558}
559 559
560void Blowfish::padNull(string *buf) 560void Blowfish::padNull(string *buf)
561{ 561{
562 buf->append(1, (char)0x01); 562 buf->append(1, (char)0x01);
563 string::size_type append_null = 8 - (buf->length() % 8); 563 string::size_type append_null = 8 - (buf->length() % 8);
564 buf->append(append_null, (char)0x00); 564 buf->append(append_null, (char)0x00);
565} 565}
566 566
567bool Blowfish::unpadNull(string *buf) 567bool Blowfish::unpadNull(string *buf)
568{ 568{
569 if (unlikely(buf->size() % 8)) 569 if (unlikely(buf->size() % 8))
570 return false; 570 return false;
571 string::size_type pos = buf->length() - 1; 571 string::size_type pos = buf->length() - 1;
572 while ((*buf)[pos] != (char)0x01) { 572 while ((*buf)[pos] != (char)0x01) {
573 if (unlikely(pos == 0)) 573 if (unlikely(pos == 0))
574 return false; 574 return false;
575 --pos; 575 --pos;
576 } 576 }
577 buf->erase(pos, buf->length() - pos); 577 buf->erase(pos, buf->length() - pos);
578 return true; 578 return true;
579} 579}
diff --git a/pwmanager/pwmanager/blowfish.h b/pwmanager/pwmanager/blowfish.h
index 5129eab..862cccb 100644
--- a/pwmanager/pwmanager/blowfish.h
+++ b/pwmanager/pwmanager/blowfish.h
@@ -1,129 +1,131 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch * 3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * blowfish.c - Blowfish encryption * 6 * blowfish.c - Blowfish encryption *
7 * Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc. * 7 * Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc. *
8 * * 8 * *
9 * This program is free software; you can redistribute it and/or modify * 9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License version 2 * 10 * it under the terms of the GNU General Public License version 2 *
11 * as published by the Free Software Foundation. * 11 * as published by the Free Software Foundation. *
12 * * 12 * *
13 ***************************************************************************/ 13 ***************************************************************************/
14 14
15/*************************************************************************** 15/***************************************************************************
16 * copyright (C) 2004 by Ulf Schenk 16 * copyright (C) 2004 by Ulf Schenk
17 * This file is originaly based on version 1.0.1 of pwmanager 17 * This file is originaly based on version 1.0.1 of pwmanager
18 * and was modified to run on embedded devices that run microkde 18 * and was modified to run on embedded devices that run microkde
19 * 19 *
20 * $Id$ 20 * $Id$
21 **************************************************************************/ 21 **************************************************************************/
22 22
23#ifndef BLOWFISH_H 23#ifndef BLOWFISH_H
24#define BLOWFISH_H 24#define BLOWFISH_H
25 25
26#include "pwmexception.h" 26//#include "pwmexception.h"
27#ifndef _WIN32_ 27#ifndef _WIN32_
28#include <stdint.h> 28#include <stdint.h>
29#else 29#else
30 30
31#endif 31#endif
32#include <string> 32#include <string>
33using std::string; 33using std::string;
34 34
35 #define BLOWFISH_BLOCKSIZE8 35 #define BLOWFISH_BLOCKSIZE8
36 #define BLOWFISH_ROUNDS 16 36 #define BLOWFISH_ROUNDS 16
37 #define CIPHER_ALGO_BLOWFISH 4/* blowfish 128 bit key */ 37 #define CIPHER_ALGO_BLOWFISH 4/* blowfish 128 bit key */
38 38
39#ifndef _WIN32_ 39#ifndef _WIN32_
40 typedef uint8_t byte; 40 typedef uint8_t byte;
41#else 41#else
42#define uint8_t Q_UINT8 42#define uint8_t Q_UINT8
43#define byte Q_UINT8 43#define byte Q_UINT8
44#define uint32_t Q_UINT32 44#define uint32_t Q_UINT32
45#endif 45#endif
46 46
47//#include "pwmexception.h"
48
47/** blowfish encryption algorithm. 49/** blowfish encryption algorithm.
48 * Derived from libgcrypt-1.1.12 50 * Derived from libgcrypt-1.1.12
49 */ 51 */
50class Blowfish 52class Blowfish
51{ 53{
52 struct BLOWFISH_context 54 struct BLOWFISH_context
53 { 55 {
54 uint32_t s0[256]; 56 uint32_t s0[256];
55 uint32_t s1[256]; 57 uint32_t s1[256];
56 uint32_t s2[256]; 58 uint32_t s2[256];
57 uint32_t s3[256]; 59 uint32_t s3[256];
58 uint32_t p[BLOWFISH_ROUNDS+2]; 60 uint32_t p[BLOWFISH_ROUNDS+2];
59 }; 61 };
60 62
61public: 63public:
62 Blowfish() {} 64 Blowfish() {}
63 static bool selfTest(); 65 static bool selfTest();
64 66
65 /** set key to encrypt. if return == 1, it is a weak key. */ 67 /** set key to encrypt. if return == 1, it is a weak key. */
66 int bf_setkey( byte *key, unsigned int keylen ); 68 int bf_setkey( byte *key, unsigned int keylen );
67 /** encrypt inbuf and return it in outbuf. 69 /** encrypt inbuf and return it in outbuf.
68 * inbuf and outbuf have to be: buf % 8 == 0 70 * inbuf and outbuf have to be: buf % 8 == 0
69 * You may check this with getPaddedLen() and pad with NULL. 71 * You may check this with getPaddedLen() and pad with NULL.
70 */ 72 */
71 int bf_encrypt( byte *outbuf, byte *inbuf, unsigned int inbuf_len ); 73 int bf_encrypt( byte *outbuf, byte *inbuf, unsigned int inbuf_len );
72 /** decrypt inbuf and return it in outbuf. 74 /** decrypt inbuf and return it in outbuf.
73 * inbuf and outbuf have to be: buf % 8 == 0 75 * inbuf and outbuf have to be: buf % 8 == 0
74 * You may check this with getPaddedLen() and pad with NULL. 76 * You may check this with getPaddedLen() and pad with NULL.
75 */ 77 */
76 int bf_decrypt( byte *outbuf, byte *inbuf, unsigned int inbuf_len ); 78 int bf_decrypt( byte *outbuf, byte *inbuf, unsigned int inbuf_len );
77 /** returns the length, the sting has to be padded to */ 79 /** returns the length, the sting has to be padded to */
78 static unsigned int getPaddedLen(unsigned int inLen) 80 static unsigned int getPaddedLen(unsigned int inLen)
79 { return ((8 - (inLen % 8)) + inLen); } 81 { return ((8 - (inLen % 8)) + inLen); }
80 /** pad up to 8 bytes. */ 82 /** pad up to 8 bytes. */
81 static void padNull(string *buf); 83 static void padNull(string *buf);
82 /** remove padded data */ 84 /** remove padded data */
83 static bool unpadNull(string *buf); 85 static bool unpadNull(string *buf);
84 86
85protected: 87protected:
86#if BLOWFISH_ROUNDS != 16 88#if BLOWFISH_ROUNDS != 16
87 uint32_t function_F( uint32_t x) 89 uint32_t function_F( uint32_t x)
88 { 90 {
89 uint16_t a, b, c, d; 91 uint16_t a, b, c, d;
90 #ifdef BIG_ENDIAN_HOST 92 #ifdef BIG_ENDIAN_HOST
91 a = ((byte *) & x)[0]; 93 a = ((byte *) & x)[0];
92 b = ((byte *) & x)[1]; 94 b = ((byte *) & x)[1];
93 c = ((byte *) & x)[2]; 95 c = ((byte *) & x)[2];
94 d = ((byte *) & x)[3]; 96 d = ((byte *) & x)[3];
95 #else 97 #else
96 a = ((byte *) & x)[3]; 98 a = ((byte *) & x)[3];
97 b = ((byte *) & x)[2]; 99 b = ((byte *) & x)[2];
98 c = ((byte *) & x)[1]; 100 c = ((byte *) & x)[1];
99 d = ((byte *) & x)[0]; 101 d = ((byte *) & x)[0];
100 #endif 102 #endif
101 return ((bc.s0[a] + bc.s1[b]) ^ bc.s2[c]) + bc.s3[d]; 103 return ((bc.s0[a] + bc.s1[b]) ^ bc.s2[c]) + bc.s3[d];
102 } 104 }
103#endif 105#endif
104 void R(uint32_t &l, uint32_t &r, uint32_t i, uint32_t *p, 106 void R(uint32_t &l, uint32_t &r, uint32_t i, uint32_t *p,
105 uint32_t *s0, uint32_t *s1, uint32_t *s2, uint32_t *s3) 107 uint32_t *s0, uint32_t *s1, uint32_t *s2, uint32_t *s3)
106 { 108 {
107 l ^= p[i]; 109 l ^= p[i];
108 #ifdef BIG_ENDIAN_HOST 110 #ifdef BIG_ENDIAN_HOST
109 r ^= (( s0[((byte*)&l)[0]] + s1[((byte*)&l)[1]]) 111 r ^= (( s0[((byte*)&l)[0]] + s1[((byte*)&l)[1]])
110 ^ s2[((byte*)&l)[2]]) + s3[((byte*)&l)[3]]; 112 ^ s2[((byte*)&l)[2]]) + s3[((byte*)&l)[3]];
111 #else 113 #else
112 r ^= (( s0[((byte*)&l)[3]] + s1[((byte*)&l)[2]]) 114 r ^= (( s0[((byte*)&l)[3]] + s1[((byte*)&l)[2]])
113 ^ s2[((byte*)&l)[1]]) + s3[((byte*)&l)[0]]; 115 ^ s2[((byte*)&l)[1]]) + s3[((byte*)&l)[0]];
114 #endif 116 #endif
115 } 117 }
116 void encrypt_block(byte *outbuf, byte *inbuf); 118 void encrypt_block(byte *outbuf, byte *inbuf);
117 void decrypt_block(byte *outbuf, byte *inbuf); 119 void decrypt_block(byte *outbuf, byte *inbuf);
118 void burn_stack(int bytes); 120 void burn_stack(int bytes);
119 void do_encrypt(uint32_t *ret_xl, uint32_t *ret_xr); 121 void do_encrypt(uint32_t *ret_xl, uint32_t *ret_xr);
120 void do_decrypt(uint32_t *ret_xl, uint32_t *ret_xr); 122 void do_decrypt(uint32_t *ret_xl, uint32_t *ret_xr);
121 void do_encrypt_block(byte *outbuf, byte *inbuf); 123 void do_encrypt_block(byte *outbuf, byte *inbuf);
122 void do_decrypt_block(byte *outbuf, byte *inbuf); 124 void do_decrypt_block(byte *outbuf, byte *inbuf);
123 int do_bf_setkey(byte *key, unsigned int keylen); 125 int do_bf_setkey(byte *key, unsigned int keylen);
124 126
125protected: 127protected:
126 struct BLOWFISH_context bc; 128 struct BLOWFISH_context bc;
127}; 129};
128 130
129#endif 131#endif
diff --git a/pwmanager/pwmanager/genpasswd.cpp b/pwmanager/pwmanager/genpasswd.cpp
index b0cceff..41078b3 100644
--- a/pwmanager/pwmanager/genpasswd.cpp
+++ b/pwmanager/pwmanager/genpasswd.cpp
@@ -1,192 +1,193 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager 14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#include "genpasswd.h" 20#include "genpasswd.h"
21#include "pwmexception.h" 21#include "pwmexception.h"
22#include "randomizer.h" 22#include "randomizer.h"
23#include "globalstuff.h"
23 24
24 25
25/* how often can a char of the same charset be reused in order */ 26/* how often can a char of the same charset be reused in order */
26 #define FILTER_MAX_CHARSET_REUSE3 27 #define FILTER_MAX_CHARSET_REUSE3
27/* re-randomize all charsets on every iteration (0/1) */ 28/* re-randomize all charsets on every iteration (0/1) */
28 #define RERAND_CHARSET 0 29 #define RERAND_CHARSET 0
29 30
30 31
31struct staticCharsetStruct 32struct staticCharsetStruct
32{ 33{
33 const char *lower; 34 const char *lower;
34 const char *upper; 35 const char *upper;
35 const char *num; 36 const char *num;
36 const char *special; 37 const char *special;
37 const char *blank; 38 const char *blank;
38}; 39};
39 40
40static struct staticCharsetStruct staticCharset = { 41static struct staticCharsetStruct staticCharset = {
41 "abcdefghijklmnopqrstuvwxyz", 42 "abcdefghijklmnopqrstuvwxyz",
42 "ABCDEFGHIJKLMNOPQRSTUVWXYZ", 43 "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
43 "0123456789", 44 "0123456789",
44 "!\"§$%&/()=?,.-;:_+", 45 "!\"§$%&/()=?,.-;:_+",
45 " " 46 " "
46}; 47};
47 48
48 49
49GenPasswd::GenPasswd() 50GenPasswd::GenPasswd()
50 : length (8) 51 : length (8)
51 , useFilter (true) 52 , useFilter (true)
52{ 53{
53 dynCharset.setAutoDelete(true); 54 dynCharset.setAutoDelete(true);
54} 55}
55 56
56void GenPasswd::setCharset(bool lower, 57void GenPasswd::setCharset(bool lower,
57 bool upper, 58 bool upper,
58 bool num, 59 bool num,
59 bool special, 60 bool special,
60 bool blank, 61 bool blank,
61 QString user) 62 QString user)
62{ 63{
63 unsigned int sanityCheck = 0; 64 unsigned int sanityCheck = 0;
64 dynCharset_element *tmpElement; 65 dynCharset_element *tmpElement;
65 dynCharset.clear(); 66 dynCharset.clear();
66 if (lower) { 67 if (lower) {
67 tmpElement = new dynCharset_element; 68 tmpElement = new dynCharset_element;
68 tmpElement->refCnt = 0; 69 tmpElement->refCnt = 0;
69 tmpElement->data = staticCharset.lower; 70 tmpElement->data = staticCharset.lower;
70 dynCharset.append(tmpElement); 71 dynCharset.append(tmpElement);
71 ++sanityCheck; 72 ++sanityCheck;
72 } 73 }
73 if (upper) { 74 if (upper) {
74 tmpElement = new dynCharset_element; 75 tmpElement = new dynCharset_element;
75 tmpElement->refCnt = 0; 76 tmpElement->refCnt = 0;
76 tmpElement->data = staticCharset.upper; 77 tmpElement->data = staticCharset.upper;
77 dynCharset.append(tmpElement); 78 dynCharset.append(tmpElement);
78 ++sanityCheck; 79 ++sanityCheck;
79 } 80 }
80 if (num) { 81 if (num) {
81 tmpElement = new dynCharset_element; 82 tmpElement = new dynCharset_element;
82 tmpElement->refCnt = 0; 83 tmpElement->refCnt = 0;
83 tmpElement->data = staticCharset.num; 84 tmpElement->data = staticCharset.num;
84 dynCharset.append(tmpElement); 85 dynCharset.append(tmpElement);
85 ++sanityCheck; 86 ++sanityCheck;
86 } 87 }
87 if (special) { 88 if (special) {
88 tmpElement = new dynCharset_element; 89 tmpElement = new dynCharset_element;
89 tmpElement->refCnt = 0; 90 tmpElement->refCnt = 0;
90 tmpElement->data = staticCharset.special; 91 tmpElement->data = staticCharset.special;
91 dynCharset.append(tmpElement); 92 dynCharset.append(tmpElement);
92 ++sanityCheck; 93 ++sanityCheck;
93 } 94 }
94 if (blank) { 95 if (blank) {
95 tmpElement = new dynCharset_element; 96 tmpElement = new dynCharset_element;
96 tmpElement->refCnt = 0; 97 tmpElement->refCnt = 0;
97 tmpElement->data = staticCharset.blank; 98 tmpElement->data = staticCharset.blank;
98 dynCharset.append(tmpElement); 99 dynCharset.append(tmpElement);
99 } 100 }
100 if (!user.isEmpty()) { 101 if (!user.isEmpty()) {
101 tmpElement = new dynCharset_element; 102 tmpElement = new dynCharset_element;
102 tmpElement->refCnt = 0; 103 tmpElement->refCnt = 0;
103 tmpElement->data = user; 104 tmpElement->data = user;
104 dynCharset.append(tmpElement); 105 dynCharset.append(tmpElement);
105 if (likely(user.length() >= 2)) 106 if (likely(user.length() >= 2))
106 ++sanityCheck; 107 ++sanityCheck;
107 } 108 }
108 BUG_ON(!sanityCheck); 109 BUG_ON(!sanityCheck);
109 rndDynCharset(); 110 rndDynCharset();
110} 111}
111 112
112void GenPasswd::rndDynCharset() 113void GenPasswd::rndDynCharset()
113{ 114{
114 QString tmpData; 115 QString tmpData;
115 int pos; 116 int pos;
116 Randomizer *rnd = Randomizer::obj(); 117 Randomizer *rnd = Randomizer::obj();
117 // QPtrList<dynCharset_element>::iterator is not available in QT-3.1 118 // QPtrList<dynCharset_element>::iterator is not available in QT-3.1
118 unsigned int i, cnt = dynCharset.count(); 119 unsigned int i, cnt = dynCharset.count();
119 dynCharset_element *p; 120 dynCharset_element *p;
120 for (i = 0; i < cnt; ++i) { 121 for (i = 0; i < cnt; ++i) {
121 p = dynCharset.at(i); 122 p = dynCharset.at(i);
122 PWM_ASSERT(p); 123 PWM_ASSERT(p);
123 tmpData = QString::null; 124 tmpData = QString::null;
124 while (p->data.length()) { 125 while (p->data.length()) {
125 pos = rnd->genRndInt() % p->data.length(); 126 pos = rnd->genRndInt() % p->data.length();
126 tmpData.append(p->data.at(pos)); 127 tmpData.append(p->data.at(pos));
127 p->data.remove(pos, 1); 128 p->data.remove(pos, 1);
128 } 129 }
129 p->data = tmpData; 130 p->data = tmpData;
130 } 131 }
131} 132}
132 133
133QString GenPasswd::gen() 134QString GenPasswd::gen()
134{ 135{
135 BUG_ON(dynCharset.count() <= 0); 136 BUG_ON(dynCharset.count() <= 0);
136 BUG_ON(length < 1); 137 BUG_ON(length < 1);
137 dynCharset_element *curCharset; 138 dynCharset_element *curCharset;
138 QString ret; 139 QString ret;
139 int i; 140 int i;
140 for (i = 0; i < length; ++i) { 141 for (i = 0; i < length; ++i) {
141 curCharset = selectNextCharset(); 142 curCharset = selectNextCharset();
142#if RERAND_CHARSET != 0 143#if RERAND_CHARSET != 0
143 rndDynCharset(); 144 rndDynCharset();
144#endif // RERAND_CHARSET 145#endif // RERAND_CHARSET
145 ret += genNewRandom(curCharset); 146 ret += genNewRandom(curCharset);
146 } 147 }
147 return ret; 148 return ret;
148} 149}
149 150
150GenPasswd::dynCharset_element * GenPasswd::selectNextCharset() 151GenPasswd::dynCharset_element * GenPasswd::selectNextCharset()
151{ 152{
152 dynCharset_element *ret; 153 dynCharset_element *ret;
153 int numCharsets = dynCharset.count(); 154 int numCharsets = dynCharset.count();
154 BUG_ON(numCharsets <= 0); 155 BUG_ON(numCharsets <= 0);
155 if (numCharsets == 1) 156 if (numCharsets == 1)
156 return dynCharset.at(0); 157 return dynCharset.at(0);
157 Randomizer *rnd = Randomizer::obj(); 158 Randomizer *rnd = Randomizer::obj();
158 if (useFilter) { 159 if (useFilter) {
159 // find out which charsets are allowed (filtering) 160 // find out which charsets are allowed (filtering)
160 QPtrList<dynCharset_element> allowedCharsets; 161 QPtrList<dynCharset_element> allowedCharsets;
161 // QPtrList<dynCharset_element>::iterator is not available in QT-3.1 162 // QPtrList<dynCharset_element>::iterator is not available in QT-3.1
162 unsigned int i, cnt = dynCharset.count(); 163 unsigned int i, cnt = dynCharset.count();
163 dynCharset_element *p; 164 dynCharset_element *p;
164 for (i = 0; i < cnt; ++i) { 165 for (i = 0; i < cnt; ++i) {
165 p = dynCharset.at(i); 166 p = dynCharset.at(i);
166 PWM_ASSERT(p); 167 PWM_ASSERT(p);
167 if (p->refCnt < FILTER_MAX_CHARSET_REUSE) { 168 if (p->refCnt < FILTER_MAX_CHARSET_REUSE) {
168 allowedCharsets.append(p); 169 allowedCharsets.append(p);
169 } else { 170 } else {
170 p->refCnt = 0; 171 p->refCnt = 0;
171 } 172 }
172 } 173 }
173 int numAllowedCharsets = allowedCharsets.count(); 174 int numAllowedCharsets = allowedCharsets.count();
174 BUG_ON(numAllowedCharsets <= 0); 175 BUG_ON(numAllowedCharsets <= 0);
175 // now get a random charset out of the allowed 176 // now get a random charset out of the allowed
176 unsigned int randomPos = rnd->genRndUInt() % numAllowedCharsets; 177 unsigned int randomPos = rnd->genRndUInt() % numAllowedCharsets;
177 ret = allowedCharsets.at(randomPos); 178 ret = allowedCharsets.at(randomPos);
178 ret->refCnt++; 179 ret->refCnt++;
179 return ret; 180 return ret;
180 } 181 }
181 // all charsets are allowed here (no filtering). Get a random. 182 // all charsets are allowed here (no filtering). Get a random.
182 unsigned int randomPos = rnd->genRndUInt() % numCharsets; 183 unsigned int randomPos = rnd->genRndUInt() % numCharsets;
183 ret = dynCharset.at(randomPos); 184 ret = dynCharset.at(randomPos);
184 return ret; 185 return ret;
185} 186}
186 187
187QChar GenPasswd::genNewRandom(const dynCharset_element *charset) 188QChar GenPasswd::genNewRandom(const dynCharset_element *charset)
188{ 189{
189 Randomizer *rnd = Randomizer::obj(); 190 Randomizer *rnd = Randomizer::obj();
190 int pos = rnd->genRndInt() % charset->data.length(); 191 int pos = rnd->genRndInt() % charset->data.length();
191 return charset->data.at(pos); 192 return charset->data.at(pos);
192} 193}
diff --git a/pwmanager/pwmanager/libgcryptif.h b/pwmanager/pwmanager/libgcryptif.h
index 9a987a2..a08d678 100644
--- a/pwmanager/pwmanager/libgcryptif.h
+++ b/pwmanager/pwmanager/libgcryptif.h
@@ -1,177 +1,179 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2004 by Michael Buesch * 3 * copyright (C) 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * hashPassphrase() is derived from GnuPG and is * 6 * hashPassphrase() is derived from GnuPG and is *
7 * Copyright (C) 1998, 1999, 2000, 2001, 2003 * 7 * Copyright (C) 1998, 1999, 2000, 2001, 2003 *
8 * Free Software Foundation, Inc. * 8 * Free Software Foundation, Inc. *
9 * * 9 * *
10 * This program is free software; you can redistribute it and/or modify * 10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License version 2 * 11 * it under the terms of the GNU General Public License version 2 *
12 * as published by the Free Software Foundation. * 12 * as published by the Free Software Foundation. *
13 * * 13 * *
14 ***************************************************************************/ 14 ***************************************************************************/
15 15
16/*************************************************************************** 16/***************************************************************************
17 * copyright (C) 2004 by Ulf Schenk 17 * copyright (C) 2004 by Ulf Schenk
18 * This file is originaly based on version 1.1 of pwmanager 18 * This file is originaly based on version 1.1 of pwmanager
19 * and was modified to run on embedded devices that run microkde 19 * and was modified to run on embedded devices that run microkde
20 * 20 *
21 * $Id$ 21 * $Id$
22 **************************************************************************/ 22 **************************************************************************/
23 23
24#ifndef __LIBGCRYPTIF_H 24#ifndef __LIBGCRYPTIF_H
25#define __LIBGCRYPTIF_H 25#define __LIBGCRYPTIF_H
26 26
27#include "pwmexception.h"
28 27
29//#undef CONFIG_PWMANAGER_GCRY // for debugging only. 28//#undef CONFIG_PWMANAGER_GCRY // for debugging only.
30#ifdef CONFIG_PWMANAGER_GCRY 29#ifdef CONFIG_PWMANAGER_GCRY
31 30
32#include <stddef.h> 31#include <stddef.h>
33#include <sys/types.h> 32#include <sys/types.h>
34#ifndef _WIN32_ 33#ifndef _WIN32_
35#include <stdint.h> 34#include <stdint.h>
36#else 35#else
37#define uint8_t Q_UINT8 36#define uint8_t Q_UINT8
38#define byte Q_UINT8 37#define byte Q_UINT8
39#define uint32_t Q_UINT32 38#define uint32_t Q_UINT32
40#endif 39#endif
41 #define STRING2KEY_SALTLEN8 40 #define STRING2KEY_SALTLEN8
42 41
42#include "pwmexception.h"
43
44
43/** interface class for the libgcrypt cipher and hash algorithms 45/** interface class for the libgcrypt cipher and hash algorithms
44 * NOTE: Always allocate 1024 extra bytes for the inBuf (for padding) 46 * NOTE: Always allocate 1024 extra bytes for the inBuf (for padding)
45 */ 47 */
46class LibGCryptIf 48class LibGCryptIf
47{ 49{
48protected: 50protected:
49 struct STRING2KEY 51 struct STRING2KEY
50 { 52 {
51 int mode; 53 int mode;
52 int hash_algo; 54 int hash_algo;
53 uint8_t salt[STRING2KEY_SALTLEN]; 55 uint8_t salt[STRING2KEY_SALTLEN];
54 uint32_t count; 56 uint32_t count;
55 }; 57 };
56 struct DEK 58 struct DEK
57 { 59 {
58 size_t keylen; 60 size_t keylen;
59 uint8_t key[32]; // this is the largest used keylen (256 bit) 61 uint8_t key[32]; // this is the largest used keylen (256 bit)
60 }; 62 };
61 63
62public: 64public:
63 LibGCryptIf() { } 65 LibGCryptIf() { }
64 /** is libgcrypt available? */ 66 /** is libgcrypt available? */
65 static bool available() 67 static bool available()
66 { return true; } 68 { return true; }
67 /** encrypt data. _algo is the PWM_CRYPT_* ID 69 /** encrypt data. _algo is the PWM_CRYPT_* ID
68 * of the algorithm. 70 * of the algorithm.
69 */ 71 */
70 PwMerror encrypt(unsigned char **outBuf, 72 PwMerror encrypt(unsigned char **outBuf,
71 size_t *outBufLen, 73 size_t *outBufLen,
72 unsigned char *inBuf, 74 unsigned char *inBuf,
73 size_t inBufLen, 75 size_t inBufLen,
74 const unsigned char *key, 76 const unsigned char *key,
75 size_t keylen, 77 size_t keylen,
76 char _algo, 78 char _algo,
77 char _hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase 79 char _hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase
78); 80);
79 /** decrypt data. _algo is the PWM_CRYPT_* ID 81 /** decrypt data. _algo is the PWM_CRYPT_* ID
80 * of the algorithm. 82 * of the algorithm.
81 */ 83 */
82 PwMerror decrypt(unsigned char **outBuf, 84 PwMerror decrypt(unsigned char **outBuf,
83 size_t *outBufLen, 85 size_t *outBufLen,
84 const unsigned char *inBuf, 86 const unsigned char *inBuf,
85 size_t inBufLen, 87 size_t inBufLen,
86 const unsigned char *key, 88 const unsigned char *key,
87 size_t keylen, 89 size_t keylen,
88 char _algo, 90 char _algo,
89 char _hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase 91 char _hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase
90); 92);
91 /** hash data. _algo is the PWM_HASH_* ID of the hash */ 93 /** hash data. _algo is the PWM_HASH_* ID of the hash */
92 PwMerror hash(unsigned char **outBuf, 94 PwMerror hash(unsigned char **outBuf,
93 size_t *outBufLen, 95 size_t *outBufLen,
94 const unsigned char *inBuf, 96 const unsigned char *inBuf,
95 size_t inBufLen, 97 size_t inBufLen,
96 char _algo); 98 char _algo);
97 /** returns the length of the hash. _algo is the PWM_HASH_* 99 /** returns the length of the hash. _algo is the PWM_HASH_*
98 * id of the hash. returns 0 on error. 100 * id of the hash. returns 0 on error.
99 */ 101 */
100 unsigned int hashLength(char _algo); 102 unsigned int hashLength(char _algo);
101 103
102protected: 104protected:
103 /** returns the total buffer length */ 105 /** returns the total buffer length */
104 size_t getBufLen(size_t inBufLen, size_t boundary) 106 size_t getBufLen(size_t inBufLen, size_t boundary)
105 { 107 {
106 return ((boundary - (inBufLen % boundary)) + inBufLen); 108 return ((boundary - (inBufLen % boundary)) + inBufLen);
107 } 109 }
108 /** pad the data up to the given boundary. 110 /** pad the data up to the given boundary.
109 * "buf" has to be big enough! 111 * "buf" has to be big enough!
110 */ 112 */
111 void padData(unsigned char *buf, 113 void padData(unsigned char *buf,
112 size_t bufLen, 114 size_t bufLen,
113 size_t boundary); 115 size_t boundary);
114 /** unpad the data */ 116 /** unpad the data */
115 void unpadData(const unsigned char *buf, 117 void unpadData(const unsigned char *buf,
116 size_t *bufLen); 118 size_t *bufLen);
117 /** maps the PWM_CRYPT_* ID of an algorithm 119 /** maps the PWM_CRYPT_* ID of an algorithm
118 * to the libgcrypt GCRY_CIPHER_* ID 120 * to the libgcrypt GCRY_CIPHER_* ID
119 */ 121 */
120 int mapCipherId(char algo); 122 int mapCipherId(char algo);
121 /** maps the PWM_HASH_* ID of an algorithm 123 /** maps the PWM_HASH_* ID of an algorithm
122 * to the libgcrypt GCRY_MD_* ID 124 * to the libgcrypt GCRY_MD_* ID
123 */ 125 */
124 int mapHashId(char algo); 126 int mapHashId(char algo);
125 /** hash a passphrase to a cipher key */ 127 /** hash a passphrase to a cipher key */
126 bool hashPassphrase(const unsigned char *pw, 128 bool hashPassphrase(const unsigned char *pw,
127 size_t pwlen, 129 size_t pwlen,
128 unsigned char *salt, 130 unsigned char *salt,
129 unsigned char *key, 131 unsigned char *key,
130 size_t keylen, 132 size_t keylen,
131 bool create, 133 bool create,
132 char _hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase 134 char _hashalgo //US BUG: pass _hashalgo because we need it in hashPassphrase
133); 135);
134 /** hash a passphrase to a cipher key */ 136 /** hash a passphrase to a cipher key */
135 bool doHashPassphrase(DEK *dek, 137 bool doHashPassphrase(DEK *dek,
136 const unsigned char *pw, 138 const unsigned char *pw,
137 size_t pwlen, 139 size_t pwlen,
138 STRING2KEY *s2k, 140 STRING2KEY *s2k,
139 bool create); 141 bool create);
140}; 142};
141 143
142 144
143#else // CONFIG_PWMANAGER_GCRY 145#else // CONFIG_PWMANAGER_GCRY
144/** libgcrypt is not installed. This is a NOP wrapper. */ 146/** libgcrypt is not installed. This is a NOP wrapper. */
145class LibGCryptIf 147class LibGCryptIf
146{ 148{
147public: 149public:
148 LibGCryptIf() { } 150 LibGCryptIf() { }
149 static bool available() 151 static bool available()
150 { return false; } 152 { return false; }
151 PwMerror encrypt(unsigned char **, 153 PwMerror encrypt(unsigned char **,
152 size_t *, 154 size_t *,
153 unsigned char *, 155 unsigned char *,
154 size_t, 156 size_t,
155 const unsigned char *, 157 const unsigned char *,
156 size_t, 158 size_t,
157 char) 159 char)
158 { return e_cryptNotImpl; } 160 { return e_cryptNotImpl; }
159 PwMerror decrypt(unsigned char **, 161 PwMerror decrypt(unsigned char **,
160 size_t *, 162 size_t *,
161 const unsigned char *, 163 const unsigned char *,
162 size_t, 164 size_t,
163 const unsigned char *, 165 const unsigned char *,
164 size_t, 166 size_t,
165 char) 167 char)
166 { return e_cryptNotImpl; } 168 { return e_cryptNotImpl; }
167 PwMerror hash(unsigned char **, 169 PwMerror hash(unsigned char **,
168 size_t *, 170 size_t *,
169 const unsigned char *, 171 const unsigned char *,
170 size_t, 172 size_t,
171 char) 173 char)
172 { return e_hashNotImpl; } 174 { return e_hashNotImpl; }
173 unsigned int hashLength(char) 175 unsigned int hashLength(char)
174 { return 0; } 176 { return 0; }
175}; 177};
176#endif // CONFIG_PWMANAGER_GCRY 178#endif // CONFIG_PWMANAGER_GCRY
177#endif // __LIBGCRYPTIF_H 179#endif // __LIBGCRYPTIF_H
diff --git a/pwmanager/pwmanager/pwmexception.h b/pwmanager/pwmanager/pwmexception.h
index 301ebd7..7f5a3a6 100644
--- a/pwmanager/pwmanager/pwmexception.h
+++ b/pwmanager/pwmanager/pwmexception.h
@@ -1,217 +1,218 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch * 3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.0.1 of pwmanager 14 * This file is originaly based on version 1.0.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#ifndef __PWMEXCEPTION_H 20#ifndef __PWMEXCEPTION_H
21#define __PWMEXCEPTION_H 21#define __PWMEXCEPTION_H
22 22
23#include "globalstuff.h" 23//#include "globalstuff.h"
24 24
25#include <iostream> 25#include <iostream>
26#include <string> 26#include <string>
27using std::string; 27using std::string;
28using std::cerr; 28using std::cerr;
29using std::cout; 29using std::cout;
30using std::endl; 30using std::endl;
31 31
32/* This is an internal function to reduce code-overhead 32/* This is an internal function to reduce code-overhead
33 * of the BUG(), WARN(), TOD0() and FiXME() macros. Please use 33 * of the BUG(), WARN(), TOD0() and FiXME() macros. Please use
34 * these macros instead of calling this function directly. 34 * these macros instead of calling this function directly.
35 */ 35 */
36void pwmFatal(const char *id, 36void pwmFatal(const char *id,
37 const char *file, 37 const char *file,
38 int line); 38 int line);
39 39
40/** Use PWM_ASSERT(condition) for debugging assertions. 40/** Use PWM_ASSERT(condition) for debugging assertions.
41 * "condition" is eaten up and replaced with a NOP 41 * "condition" is eaten up and replaced with a NOP
42 * when debugging is disabled. 42 * when debugging is disabled.
43 * 43 *
44 * PWM_ASSERT_NOEAT(condition) is the same as PWM_ASSERT(condition), 44 * PWM_ASSERT_NOEAT(condition) is the same as PWM_ASSERT(condition),
45 * but it does _not_ eat up "condition" and ensures that 45 * but it does _not_ eat up "condition" and ensures that
46 * condition is always evaluated. 46 * condition is always evaluated.
47 */ 47 */
48#ifdef PWM_ASSERT 48#ifdef PWM_ASSERT
49# undef PWM_ASSERT 49# undef PWM_ASSERT
50#endif 50#endif
51#ifdef PWM_ASSERT_NOEAT 51#ifdef PWM_ASSERT_NOEAT
52# undef PWM_ASSERT_NOEAT 52# undef PWM_ASSERT_NOEAT
53#endif 53#endif
54#ifdef PWM_DEBUG 54#ifdef PWM_DEBUG
55 # define PWM_ASSERT(x) do { \ 55 # define PWM_ASSERT(x) do { \
56 if (unlikely(!(x))) { \ 56 if (unlikely(!(x))) { \
57 cerr << "PWM_ASSERT failed: (" << #x\ 57 cerr << "PWM_ASSERT failed: (" << #x\
58 << ") in " << __FILE__ \ 58 << ") in " << __FILE__ \
59 << ":" << __LINE__ \ 59 << ":" << __LINE__ \
60 << endl; \ 60 << endl; \
61 } \ 61 } \
62 } while (0) 62 } while (0)
63 # define PWM_ASSERT_NOEAT(x)do { PWM_ASSERT(x); } while (0) 63 # define PWM_ASSERT_NOEAT(x)do { PWM_ASSERT(x); } while (0)
64#else // PWM_DEBUG 64#else // PWM_DEBUG
65 # define PWM_ASSERT(x) do { } while (0) 65 # define PWM_ASSERT(x) do { } while (0)
66 # define PWM_ASSERT_NOEAT(x)do { if (x) ; } while (0) 66 # define PWM_ASSERT_NOEAT(x)do { if (x) ; } while (0)
67#endif // PWM_DEBUG 67#endif // PWM_DEBUG
68 68
69/** Insert a BUG() into code paths which clearly show 69/** Insert a BUG() into code paths which clearly show
70 * a bug in the code and which should, under normal 70 * a bug in the code and which should, under normal
71 * circumstances, never execute. 71 * circumstances, never execute.
72 */ 72 */
73#ifdef BUG 73#ifdef BUG
74# undef BUG 74# undef BUG
75#endif 75#endif
76 #define BUG()do { pwmFatal("BUG", __FILE__, __LINE__); } while (0) 76 #define BUG()do { pwmFatal("BUG", __FILE__, __LINE__); } while (0)
77 77
78/** Use BUG_ON(condition) to print a bug-message if "condition" 78/** Use BUG_ON(condition) to print a bug-message if "condition"
79 * is true. This is also enabled in non-debugging code. 79 * is true. This is also enabled in non-debugging code.
80 */ 80 */
81#ifdef BUG_ON 81#ifdef BUG_ON
82# undef BUG_ON 82# undef BUG_ON
83#endif 83#endif
84 #define BUG_ON(x) do { if (unlikely(x))BUG(); } while (0) 84 #define BUG_ON(x) do { if (unlikely(x))BUG(); } while (0)
85 85
86/** Insert a WARN() into code-paths which should not 86/** Insert a WARN() into code-paths which should not
87 * execute normally, but if they do it's non-fatal. 87 * execute normally, but if they do it's non-fatal.
88 */ 88 */
89#ifdef WARN 89#ifdef WARN
90# undef WARN 90# undef WARN
91#endif 91#endif
92 #define WARN()do { pwmFatal("badness", __FILE__, __LINE__); } while (0) 92 #define WARN()do { pwmFatal("badness", __FILE__, __LINE__); } while (0)
93 93
94/** Same as BUG_ON() but prints a warning-message */ 94/** Same as BUG_ON() but prints a warning-message */
95#ifdef WARN_ON 95#ifdef WARN_ON
96# undef WARN_ON 96# undef WARN_ON
97#endif 97#endif
98 #define WARN_ON(x) do { if (unlikely(x))WARN(); } while (0) 98 #define WARN_ON(x) do { if (unlikely(x))WARN(); } while (0)
99 99
100/** Insert this into code which is incomplete */ 100/** Insert this into code which is incomplete */
101#ifdef TODO 101#ifdef TODO
102# undef TODO 102# undef TODO
103#endif 103#endif
104 #define TODO()do { pwmFatal("TODO", __FILE__, __LINE__); } while (0) 104 #define TODO()do { pwmFatal("TODO", __FILE__, __LINE__); } while (0)
105 105
106/** Insert this into code which likely contains bugs */ 106/** Insert this into code which likely contains bugs */
107#ifdef FIXME 107#ifdef FIXME
108# undef FIXME 108# undef FIXME
109#endif 109#endif
110 #define FIXME()do { pwmFatal("FIXME", __FILE__, __LINE__); } while (0) 110 #define FIXME()do { pwmFatal("FIXME", __FILE__, __LINE__); } while (0)
111 111
112 112
113/** PwM error codes */ 113/** PwM error codes */
114enum PwMerror { 114enum PwMerror {
115 e_success = 0, 115 e_success = 0,
116 116
117 // file access errors 117 // file access errors
118 e_filename, 118 e_filename,
119 e_readFile, 119 e_readFile,
120 e_writeFile, 120 e_writeFile,
121 e_openFile, 121 e_openFile,
122 e_accessFile, // permission error, etc... 122 e_accessFile, // permission error, etc...
123 e_fileGeneric, 123 e_fileGeneric,
124 e_alreadyOpen, 124 e_alreadyOpen,
125 125
126 // other file errors 126 // other file errors
127 e_fileVer, 127 e_fileVer,
128 e_fileFormat, // format error 128 e_fileFormat, // format error
129 e_unsupportedFormat,// completely unsupported format 129 e_unsupportedFormat,// completely unsupported format
130 e_setFilePointer, 130 e_setFilePointer,
131 e_fileBackup, 131 e_fileBackup,
132 e_fileCorrupt, // file data has correct format, 132 e_fileCorrupt, // file data has correct format,
133 // but is corrupt (checksum error, etc) 133 // but is corrupt (checksum error, etc)
134 134
135 // password errors 135 // password errors
136 e_wrongPw, 136 e_wrongPw,
137 e_getPw, 137 e_getPw,
138 e_weakPw, 138 e_weakPw,
139 e_noPw, 139 e_noPw,
140 140
141 // action not implemented errors 141 // action not implemented errors
142 e_hashNotImpl, 142 e_hashNotImpl,
143 e_cryptNotImpl, 143 e_cryptNotImpl,
144 144
145 // argument/parameter errors 145 // argument/parameter errors
146 e_incompleteArg, 146 e_incompleteArg,
147 e_invalidArg, 147 e_invalidArg,
148 148
149 // misc 149 // misc
150 e_writeHeader, 150 e_writeHeader,
151 e_serializeDta, 151 e_serializeDta,
152 e_enc, 152 e_enc,
153 e_entryExists, 153 e_entryExists,
154 e_categoryExists, 154 e_categoryExists,
155 e_maxAllowedEntr,// no more entries can be added. 155 e_maxAllowedEntr,// no more entries can be added.
156 e_outOfMem, 156 e_outOfMem,
157 e_lock, // error while (un)locking 157 e_lock, // error while (un)locking
158 e_docNotSaved, // doc wasn't saved to a file, yet. 158 e_docNotSaved, // doc wasn't saved to a file, yet.
159 e_docIsEmpty, 159 e_docIsEmpty,
160 e_binEntry, 160 e_binEntry,
161 e_normalEntry, 161 e_normalEntry,
162 e_syncError, 162 e_syncError,
163 163
164 e_generic 164 e_generic
165}; 165};
166 166
167/** can be used for general exception faults */ 167/** can be used for general exception faults */
168class PwMException 168class PwMException
169{ 169{
170public: 170public:
171 enum exceptionId 171 enum exceptionId
172 { 172 {
173 EX_GENERIC = 0, 173 EX_GENERIC = 0,
174 EX_OPEN, 174 EX_OPEN,
175 EX_CLOSE, 175 EX_CLOSE,
176 EX_READ, 176 EX_READ,
177 EX_WRITE, 177 EX_WRITE,
178 EX_LOAD_MODULE, 178 EX_LOAD_MODULE,
179 EX_PARSE 179 EX_PARSE
180 }; 180 };
181 181
182public: 182public:
183 PwMException(exceptionId id = EX_GENERIC, 183 PwMException(exceptionId id = EX_GENERIC,
184 const char *message = "") 184 const char *message = "")
185 { 185 {
186 exId = id; 186 exId = id;
187 exMsg = message; 187 exMsg = message;
188 } 188 }
189 189
190 exceptionId getId() 190 exceptionId getId()
191 { return exId; } 191 { return exId; }
192 const char* getMessage() 192 const char* getMessage()
193 { return exMsg; } 193 { return exMsg; }
194 194
195protected: 195protected:
196 /** ID of this exception */ 196 /** ID of this exception */
197 exceptionId exId; 197 exceptionId exId;
198 /** additional error-message for this exception */ 198 /** additional error-message for this exception */
199 const char *exMsg; 199 const char *exMsg;
200}; 200};
201 201
202void __printInfo(const string &msg); 202void __printInfo(const string &msg);
203void __printWarn(const string &msg); 203void __printWarn(const string &msg);
204void __printError(const string &msg); 204void __printError(const string &msg);
205 205
206#ifdef PWM_DEBUG 206#ifdef PWM_DEBUG
207 void __printDebug(const string &msg); 207 void __printDebug(const string &msg);
208 # define printDebug(x)__printDebug(x) 208 # define printDebug(x)__printDebug(x)
209#else 209#else
210 # define printDebug(x)do { } while (0) 210 # define printDebug(x)do { } while (0)
211#endif 211#endif
212 212
213 #define printInfo(x)__printInfo(x) 213 #define printInfo(x)__printInfo(x)
214 #define printWarn(x)__printWarn(x) 214 #define printWarn(x)__printWarn(x)
215 #define printError(x)__printError(x) 215 #define printError(x)__printError(x)
216 216
217#include "globalstuff.h"
217#endif // __PWMEXCEPTION_H 218#endif // __PWMEXCEPTION_H
diff --git a/pwmanager/pwmanager/randomizer.h b/pwmanager/pwmanager/randomizer.h
index f2a6015..44cc28e 100644
--- a/pwmanager/pwmanager/randomizer.h
+++ b/pwmanager/pwmanager/randomizer.h
@@ -1,86 +1,87 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * copyright (C) 2003, 2004 by Michael Buesch * 3 * copyright (C) 2003, 2004 by Michael Buesch *
4 * email: mbuesch@freenet.de * 4 * email: mbuesch@freenet.de *
5 * * 5 * *
6 * This program is free software; you can redistribute it and/or modify * 6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License version 2 * 7 * it under the terms of the GNU General Public License version 2 *
8 * as published by the Free Software Foundation. * 8 * as published by the Free Software Foundation. *
9 * * 9 * *
10 ***************************************************************************/ 10 ***************************************************************************/
11 11
12/*************************************************************************** 12/***************************************************************************
13 * copyright (C) 2004 by Ulf Schenk 13 * copyright (C) 2004 by Ulf Schenk
14 * This file is originaly based on version 1.1 of pwmanager 14 * This file is originaly based on version 1.1 of pwmanager
15 * and was modified to run on embedded devices that run microkde 15 * and was modified to run on embedded devices that run microkde
16 * 16 *
17 * $Id$ 17 * $Id$
18 **************************************************************************/ 18 **************************************************************************/
19 19
20#ifndef __RANDOMIZER_H 20#ifndef __RANDOMIZER_H
21#define __RANDOMIZER_H 21#define __RANDOMIZER_H
22 22
23#include "pwmexception.h" 23#include "pwmexception.h"
24#include "globalstuff.h"
24 25
25#ifndef PWM_EMBEDDED 26#ifndef PWM_EMBEDDED
26#include <qmutex.h> 27#include <qmutex.h>
27#endif 28#endif
28 29
29#include <string> 30#include <string>
30 31
31using std::string; 32using std::string;
32 33
33class QFile; 34class QFile;
34 35
35/** Randomizer to get random values. 36/** Randomizer to get random values.
36 * This class is thread-safe. 37 * This class is thread-safe.
37 * You should always use the instance returned by 38 * You should always use the instance returned by
38 * obj() to use it. 39 * obj() to use it.
39 */ 40 */
40class Randomizer 41class Randomizer
41{ 42{
42public: 43public:
43 Randomizer(); 44 Randomizer();
44 ~Randomizer(); 45 ~Randomizer();
45 46
46 static Randomizer * obj() 47 static Randomizer * obj()
47 { 48 {
48 PWM_ASSERT(rndObj); 49 PWM_ASSERT(rndObj);
49 return rndObj; 50 return rndObj;
50 } 51 }
51 static void init() 52 static void init()
52 { 53 {
53 PWM_ASSERT(!rndObj); 54 PWM_ASSERT(!rndObj);
54 rndObj = new Randomizer; 55 rndObj = new Randomizer;
55 } 56 }
56 static void cleanup() 57 static void cleanup()
57 { 58 {
58 delete_ifnot_null(rndObj); 59 delete_ifnot_null(rndObj);
59 } 60 }
60 61
61 /** generate random char */ 62 /** generate random char */
62 char genRndChar(); 63 char genRndChar();
63 /** generate random int */ 64 /** generate random int */
64 int genRndInt(); 65 int genRndInt();
65 /** generate a random unsigned int */ 66 /** generate a random unsigned int */
66 unsigned int genRndUInt(); 67 unsigned int genRndUInt();
67 68
68 /** returns a buffer with random data */ 69 /** returns a buffer with random data */
69 string genRndBuf(size_t len); 70 string genRndBuf(size_t len);
70 /** returns a buffer with random data */ 71 /** returns a buffer with random data */
71 void genRndBuf(unsigned char *buf, size_t len); 72 void genRndBuf(unsigned char *buf, size_t len);
72 73
73protected: 74protected:
74 /** random-device-node (if available. Otherwise NULL) */ 75 /** random-device-node (if available. Otherwise NULL) */
75 QFile *rndDev; 76 QFile *rndDev;
76#ifndef PWM_EMBEDDED 77#ifndef PWM_EMBEDDED
77 /** mutex for accessing the public functions thread-save */ 78 /** mutex for accessing the public functions thread-save */
78 QMutex mutex; 79 QMutex mutex;
79#endif 80#endif
80 /** seed value for fallback - rand_r() */ 81 /** seed value for fallback - rand_r() */
81 unsigned int seed; 82 unsigned int seed;
82 /** static Randomizer object returned by obj() */ 83 /** static Randomizer object returned by obj() */
83 static Randomizer *rndObj; 84 static Randomizer *rndObj;
84}; 85};
85 86
86#endif // __RANDOMIZER_H 87#endif // __RANDOMIZER_H