summaryrefslogtreecommitdiff
path: root/libgammu/phone/nokia
diff options
context:
space:
mode:
Diffstat (limited to 'libgammu/phone/nokia')
-rw-r--r--libgammu/phone/nokia/dct3/dct3comm.h16
-rw-r--r--libgammu/phone/nokia/dct3/dct3func.c1571
-rw-r--r--libgammu/phone/nokia/dct3/dct3func.h81
-rw-r--r--libgammu/phone/nokia/dct3/n0650.c168
-rw-r--r--libgammu/phone/nokia/dct3/n0650.h18
-rw-r--r--libgammu/phone/nokia/dct3/n6110.c2947
-rw-r--r--libgammu/phone/nokia/dct3/n6110.h43
-rw-r--r--libgammu/phone/nokia/dct3/n7110.c1793
-rw-r--r--libgammu/phone/nokia/dct3/n7110.h45
-rw-r--r--libgammu/phone/nokia/dct3/n9210.c419
-rw-r--r--libgammu/phone/nokia/dct3/n9210.h17
-rw-r--r--libgammu/phone/nokia/dct4s40/6510/6510cal.c1353
-rw-r--r--libgammu/phone/nokia/dct4s40/6510/6510cal.h51
-rw-r--r--libgammu/phone/nokia/dct4s40/6510/6510file.c2609
-rw-r--r--libgammu/phone/nokia/dct4s40/6510/6510file.h32
-rw-r--r--libgammu/phone/nokia/dct4s40/6510/n6510.c4627
-rw-r--r--libgammu/phone/nokia/dct4s40/6510/n6510.h127
-rw-r--r--libgammu/phone/nokia/dct4s40/dct4func.c113
-rw-r--r--libgammu/phone/nokia/dct4s40/dct4func.h29
-rw-r--r--libgammu/phone/nokia/dct4s40/n3320.c293
-rw-r--r--libgammu/phone/nokia/dct4s40/n3320.h29
-rw-r--r--libgammu/phone/nokia/nauto.c187
-rw-r--r--libgammu/phone/nokia/ncommon.h103
-rw-r--r--libgammu/phone/nokia/nfunc.c2713
-rw-r--r--libgammu/phone/nokia/nfunc.h97
-rw-r--r--libgammu/phone/nokia/nfuncold.c228
-rw-r--r--libgammu/phone/nokia/nfuncold.h18
-rw-r--r--libgammu/phone/nokia/wd2/n3650.c461
-rw-r--r--libgammu/phone/nokia/wd2/n3650.h28
29 files changed, 20216 insertions, 0 deletions
diff --git a/libgammu/phone/nokia/dct3/dct3comm.h b/libgammu/phone/nokia/dct3/dct3comm.h
new file mode 100644
index 0000000..0b3e42e
--- /dev/null
+++ b/libgammu/phone/nokia/dct3/dct3comm.h
@@ -0,0 +1,16 @@
+/* (c) 2002-2003 by Marcin Wiacek */
+
+#ifndef phone_nokia_dct3common_h
+#define phone_nokia_dct3common_h
+
+typedef struct {
+ int Locations[4];
+ int CurrentLocation;
+ int ID;
+} DCT3_WAPSettings_Locations;
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct3/dct3func.c b/libgammu/phone/nokia/dct3/dct3func.c
new file mode 100644
index 0000000..3fa4501
--- /dev/null
+++ b/libgammu/phone/nokia/dct3/dct3func.c
@@ -0,0 +1,1571 @@
+/* (c) 2001-2004 by Marcin Wiacek */
+/* resetting DCT4 phones settings (c) by Walek */
+/* based on some Markus Plail, Pavel Janik & others work from Gnokii (www.gnokii.org)
+ * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
+ * GNU GPL version 2 or later
+ */
+/* Due to a problem in the source code management, the names of some of
+ * the authors have unfortunately been lost. We do not mean to belittle
+ * their efforts and hope they will contact us to see their names
+ * properly added to the Copyright notice above.
+ * Having published their contributions under the terms of the GNU
+ * General Public License (GPL) [version 2], the Copyright of these
+ * authors will remain respected by adhering to the license they chose
+ * to publish their code under.
+ */
+
+#include <string.h> /* memcpy only */
+#include <stdio.h>
+#include <ctype.h>
+
+#include "../../../gsmstate.h"
+#include "../../../misc/coding/coding.h"
+#include "../../../service/gsmnet.h"
+#include "../../../service/gsmlogo.h"
+#include "../../pfunc.h"
+#include "../nfunc.h"
+#include "dct3func.h"
+
+#include <gammu-config.h>
+
+#ifdef GSM_ENABLE_NOKIA_DCT3
+
+GSM_Error DCT3_DeleteWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
+{
+ GSM_Error error;
+
+ /* We have to enable WAP frames in phone */
+ error=DCT3DCT4_EnableWAPFunctions(s);
+ if (error!=ERR_NONE) return error;
+
+ return DCT3DCT4_DeleteWAPBookmarkPart(s,bookmark);
+}
+
+GSM_Error DCT3_GetWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
+{
+ GSM_Error error;
+
+ /* We have to enable WAP frames in phone */
+ error=DCT3DCT4_EnableWAPFunctions(s);
+ if (error!=ERR_NONE) return error;
+
+ return DCT3DCT4_GetWAPBookmarkPart(s,bookmark);
+}
+
+GSM_Error DCT3_ReplyPressKey(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ switch (msg->Buffer[2]) {
+ case 0x46:
+ smprintf(s, "Pressing key OK\n");
+ if (Data->PressKey) return ERR_NONE;
+ break;
+ case 0x47:
+ smprintf(s, "Releasing key OK\n");
+ if (!Data->PressKey) return ERR_NONE;
+ break;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+GSM_Error DCT3_PressKey(GSM_StateMachine *s, GSM_KeyCode Key, gboolean Press)
+{
+ unsigned char PressReq[] = {0x00, 0x01, 0x46, 0x00, 0x01,
+ 0x0a}; /* Key code */
+ unsigned char ReleaseReq[] = {0x00, 0x01, 0x47, 0x00, 0x01, 0x0c};
+
+ if (Press) {
+ PressReq[5] = Key;
+ s->Phone.Data.PressKey = TRUE;
+ smprintf(s, "Pressing key\n");
+ return GSM_WaitFor (s, PressReq, 6, 0xd1, 4, ID_PressKey);
+ } else {
+ s->Phone.Data.PressKey = FALSE;
+ smprintf(s, "Releasing key\n");
+ return GSM_WaitFor (s, ReleaseReq, 6, 0xd1, 4, ID_PressKey);
+ }
+}
+
+GSM_Error DCT3_ReplyPlayTone(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Tone played\n");
+ return ERR_NONE;
+}
+
+GSM_Error DCT3_PlayTone(GSM_StateMachine *s, int Herz, unsigned char Volume, gboolean start)
+{
+ GSM_Error error;
+ unsigned char req[] = {0x00,0x01,0x8f,
+ 0x00, /* Volume */
+ 0x00, /* HerzLo */
+ 0x00}; /* HerzHi */
+
+ if (start) {
+ error=DCT3_EnableSecurity (s, 0x01);
+ if (error!=ERR_NONE) return error;
+ }
+
+ /* For Herz==255*255 we have silent */
+ if (Herz!=255*255) {
+ req[3]=Volume;
+ req[5]=Herz%256;
+ req[4]=Herz/256;
+ } else {
+ req[3]=0;
+ req[5]=0;
+ req[4]=0;
+ }
+
+ return GSM_WaitFor (s, req, 6, 0x40, 4, ID_PlayTone);
+}
+
+#ifdef GSM_ENABLE_CELLBROADCAST
+
+GSM_Error DCT3_ReplyIncomingCB(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_CBMessage CB;
+ int i;
+ char Buffer[300];
+
+ smprintf(s, "CB received\n");
+ CB.Channel = msg->Buffer[7];
+ i = GSM_UnpackEightBitsToSeven(0, msg->Buffer[9], msg->Buffer[9], msg->Buffer+10, Buffer);
+ i = msg->Buffer[9] - 1;
+ while (i!=0) {
+ if (Buffer[i] == 13) i = i - 1; else break;
+ }
+ DecodeDefault(CB.Text, Buffer, i + 1, TRUE, NULL);
+ smprintf(s, "Channel %i, text \"%s\"\n",CB.Channel,DecodeUnicodeString(CB.Text));
+ if (s->Phone.Data.EnableIncomingCB && s->User.IncomingCB!=NULL) {
+ s->User.IncomingCB(s, &CB, s->User.IncomingCBUserData);
+ }
+ return ERR_NONE;
+}
+
+GSM_Error DCT3_ReplySetIncomingCB(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x21:
+ smprintf(s, "CB set\n");
+ return ERR_NONE;
+ case 0x22:
+ smprintf(s, "CB not set\n");
+ return ERR_UNKNOWN;
+ case 0xCA:
+ smprintf(s, "No network and no CB\n");
+ return ERR_SECURITYERROR;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+#endif
+
+GSM_Error DCT3_SetIncomingCB(GSM_StateMachine *s, gboolean enable)
+{
+#ifdef GSM_ENABLE_CELLBROADCAST
+ unsigned char reqOn[] = {N6110_FRAME_HEADER, 0x20, 0x01,
+ 0x01, 0x00, 0x00, 0x01, 0x01};
+ unsigned char reqOff[] = {N6110_FRAME_HEADER, 0x20, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00};
+
+ if (s->Phone.Data.EnableIncomingCB!=enable) {
+ s->Phone.Data.EnableIncomingCB = enable;
+ if (enable) {
+ smprintf(s, "Enabling incoming CB\n");
+ return GSM_WaitFor(s, reqOn, 10, 0x02, 4, ID_SetIncomingCB);
+ } else {
+ smprintf(s, "Disabling incoming CB\n");
+ return GSM_WaitFor(s, reqOff, 10, 0x02, 4, ID_SetIncomingCB);
+ }
+ }
+ return ERR_NONE;
+#else
+ return ERR_SOURCENOTAVAILABLE;
+#endif
+}
+
+GSM_Error DCT3_ReplySetSMSC(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "SMSC set\n");
+ return ERR_NONE;
+}
+
+GSM_Error DCT3_SetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc)
+{
+ unsigned char req[100] = {N6110_FRAME_HEADER, 0x30, 0x64};
+
+ memset(req+6,0,100-6);
+
+ /* SMSC location */
+ req[5] = smsc->Location;
+
+ /* SMSC format */
+ switch (smsc->Format) {
+ case SMS_FORMAT_Text : req[7] = 0x00; break;
+ case SMS_FORMAT_Fax : req[7] = 0x22; break;
+ case SMS_FORMAT_Pager : req[7] = 0x26; break;
+ case SMS_FORMAT_Email : req[7] = 0x32; break;
+ }
+
+ /* SMS validity */
+ req[9] = smsc->Validity.Relative;
+
+ /* Default number for SMS messages */
+ req[10] = GSM_PackSemiOctetNumber(smsc->DefaultNumber, req+11, TRUE);
+
+ /* SMSC number */
+ req[22] = GSM_PackSemiOctetNumber(smsc->Number, req+23, FALSE);
+
+ /* SMSC name */
+ memcpy(req + 34, DecodeUnicodeString(smsc->Name),UnicodeLength(smsc->Name));
+
+ smprintf(s, "Setting SMSC\n");
+ return GSM_WaitFor (s, req, 35+UnicodeLength(smsc->Name), 0x02, 4, ID_SetSMSC);
+}
+
+GSM_Error DCT3_ReplyEnableSecurity(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "State of security commands set\n");
+ return ERR_NONE;
+}
+
+/* If you set make some things (for example, change Security Code from
+ * phone's menu, disable and enable phone), it won't answer for 0x40 frames
+ * and you won't be able to play tones, get netmonitor, etc.
+ * This function do thing called "Enabling extended security commands"
+ * and it enables 0x40 frame functions.
+ * This frame can also some other things - see below
+ */
+GSM_Error DCT3_EnableSecurity (GSM_StateMachine *s, unsigned char status)
+{
+ unsigned char req[] = {0x00, 0x01, 0x64,
+ 0x01}; /* 0x00/0x01 - off/on,
+ * 0x03/0x04 - soft/hard reset,
+ * 0x06 - CONTACT SERVICE
+ */
+
+ /* 0x06 MAKES CONTACT SERVICE! BE CAREFULL! */
+ /* When use 0x03 and had during session changed time & date
+ * some phones (like 6150 or 6210) can ask for time & date after reset
+ * or disable clock on the screen
+ */
+ if (status!=0x06) req[3] = status;
+ smprintf(s, "Setting state of security commands\n");
+ return GSM_WaitFor (s, req, 4, 0x40, 4, ID_EnableSecurity);
+}
+
+GSM_Error DCT3_ReplyGetIMEI(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ memcpy(s->Phone.Data.IMEI,msg->Buffer + 4, 16);
+ smprintf(s, "Received IMEI %s\n",s->Phone.Data.IMEI);
+ return ERR_NONE;
+}
+
+GSM_Error DCT3_GetIMEI (GSM_StateMachine *s)
+{
+ unsigned char req[] = {0x00, 0x01, 0x66, 0x00};
+ GSM_Error error;
+
+ if (strlen(s->Phone.Data.IMEI)!=0) return ERR_NONE;
+
+ error=DCT3_EnableSecurity (s, 0x01);
+ if (error!=ERR_NONE) return error;
+
+ smprintf(s, "Getting IMEI\n");
+ return GSM_WaitFor (s, req, 4, 0x40, 2, ID_GetIMEI);
+}
+
+GSM_Error DCT3_ReplySIMLogin(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Login for SIM card\n");
+ return ERR_NONE;
+}
+
+GSM_Error DCT3_ReplySIMLogout(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Logout for SIM card\n");
+ return ERR_NONE;
+}
+
+GSM_Error DCT3_ReplyGetDateTime(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "Date & time received\n");
+ if (msg->Buffer[4]==0x01) {
+ NOKIA_DecodeDateTime(s, msg->Buffer+8, s->Phone.Data.DateTime, TRUE, FALSE);
+ return ERR_NONE;
+ }
+ smprintf(s, "Not set in phone\n");
+ return ERR_EMPTY;
+}
+
+GSM_Error DCT3_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time, unsigned char msgtype)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x62};
+
+ s->Phone.Data.DateTime=date_time;
+ smprintf(s, "Getting date & time\n");
+ return GSM_WaitFor (s, req, 4, msgtype, 4, ID_GetDateTime);
+}
+
+GSM_Error DCT3_ReplyGetAlarm(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "Alarm: ");
+ if (msg->Buffer[8]==0x02) {
+ smprintf(s, "set to %02i:%02i\n", msg->Buffer[9], msg->Buffer[10]);
+ Data->Alarm->Repeating = TRUE;
+ Data->Alarm->Text[0] = 0;
+ Data->Alarm->Text[1] = 0;
+ Data->Alarm->DateTime.Hour = msg->Buffer[9];
+ Data->Alarm->DateTime.Minute = msg->Buffer[10];
+ Data->Alarm->DateTime.Second = 0;
+ return ERR_NONE;
+ }
+ smprintf(s, "not set\n");
+ return ERR_EMPTY;
+}
+
+GSM_Error DCT3_GetAlarm(GSM_StateMachine *s, GSM_Alarm *Alarm, unsigned char msgtype)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x6d};
+
+ if (Alarm->Location!=1) return ERR_NOTSUPPORTED;
+
+ s->Phone.Data.Alarm=Alarm;
+ smprintf(s, "Getting alarm\n");
+ return GSM_WaitFor (s, req, 4, msgtype, 4, ID_GetAlarm);
+}
+
+GSM_Error DCT3_ReplySetDateTime(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "Date & time: ");
+ if (msg->Buffer[4]==0x01) {
+ smprintf(s, "set OK\n");
+ return ERR_NONE;
+ }
+ smprintf(s, "error setting\n");
+ return ERR_UNKNOWN;
+}
+
+GSM_Error DCT3_SetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time, unsigned char msgtype)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x60, 0x01, 0x01, 0x07,
+ 0x00, 0x00, /* Year */
+ 0x00, /* Month */
+ 0x00, /* Day */
+ 0x00, /* Hour */
+ 0x00, /* Minute */
+ 0x00}; /* Unknown. Not seconds */
+
+ NOKIA_EncodeDateTime(s, req+7, date_time);
+ smprintf(s, "Setting date & time\n");
+ return GSM_WaitFor (s, req, 14, msgtype, 4, ID_SetDateTime);
+}
+
+GSM_Error DCT3_ReplySetAlarm(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "Alarm: ");
+ if (msg->Buffer[4]==0x01) {
+ smprintf(s, "set OK\n");
+ return ERR_NONE;
+ }
+ smprintf(s, "error setting\n");
+ return ERR_UNKNOWN;
+}
+
+GSM_Error DCT3_SetAlarm(GSM_StateMachine *s, GSM_Alarm *Alarm, unsigned char msgtype)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x6b, 0x01, 0x20, 0x03,
+ 0x02, /* Unknown. Not for enabling/disabling */
+ 0x00, /* Hour */
+ 0x00, /* Minute */
+ 0x00}; /* Unknown. Not seconds */
+
+ if (Alarm->Location != 1) return ERR_NOTSUPPORTED;
+
+ req[8] = Alarm->DateTime.Hour;
+ req[9] = Alarm->DateTime.Minute;
+
+ smprintf(s, "Setting alarm\n");
+ return GSM_WaitFor (s, req, 11, msgtype, 4, ID_SetAlarm);
+}
+
+GSM_Error DCT3_ReplyWaitSMSC(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Waiting for SMSC reply\n");
+ return ERR_NONE;
+}
+
+GSM_Error DCT3_ReplyGetSMSC(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int i;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+ size_t pos;
+ GSM_Error error;
+
+ switch (msg->Buffer[3]) {
+ case 0x34:
+ smprintf(s, "SMSC received\n");
+ Data->SMSC->Format = SMS_FORMAT_Text;
+ switch (msg->Buffer[6]) {
+ case 0x00: Data->SMSC->Format = SMS_FORMAT_Text; break;
+ case 0x22: Data->SMSC->Format = SMS_FORMAT_Fax; break;
+ case 0x26: Data->SMSC->Format = SMS_FORMAT_Pager; break;
+ case 0x32: Data->SMSC->Format = SMS_FORMAT_Email; break;
+ }
+ Data->SMSC->Validity.Format = SMS_Validity_RelativeFormat;
+ Data->SMSC->Validity.Relative = msg->Buffer[8];
+ if (msg->Buffer[8] == 0x00) Data->SMSC->Validity.Relative = SMS_VALID_Max_Time;
+
+ i=33;
+ while (msg->Buffer[i]!=0) {i++;}
+ i=i-33;
+ if (i>GSM_MAX_SMSC_NAME_LENGTH) {
+ smprintf(s, "Too long name\n");
+ return ERR_UNKNOWNRESPONSE;
+ }
+ EncodeUnicode(Data->SMSC->Name,msg->Buffer+33,i);
+ smprintf(s, "Name \"%s\"\n", DecodeUnicodeString(Data->SMSC->Name));
+
+ pos = 9;
+ error = GSM_UnpackSemiOctetNumber(&(s->di), Data->SMSC->DefaultNumber, msg->Buffer, &pos, msg->Length, TRUE);
+ if (error != ERR_NONE) {
+ return error;
+ }
+ smprintf(s, "Default number \"%s\"\n", DecodeUnicodeString(Data->SMSC->DefaultNumber));
+
+ pos = 21;
+ error = GSM_UnpackSemiOctetNumber(&(s->di), Data->SMSC->Number, msg->Buffer, &pos, msg->Length, FALSE);
+ if (error != ERR_NONE) {
+ return error;
+ }
+ smprintf(s, "Number \"%s\"\n", DecodeUnicodeString(Data->SMSC->Number));
+
+ return ERR_NONE;
+ case 0x35:
+ smprintf(s, "Getting SMSC failed\n");
+ return ERR_INVALIDLOCATION;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+GSM_Error DCT3_GetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x33, 0x64,
+ 0x00}; /* Location */
+
+ if (smsc->Location==0x00) return ERR_INVALIDLOCATION;
+
+ req[5]=smsc->Location;
+
+ s->Phone.Data.SMSC=smsc;
+ smprintf(s, "Getting SMSC\n");
+ return GSM_WaitFor (s, req, 6, 0x02, 4, ID_GetSMSC);
+}
+
+GSM_Error DCT3_ReplyGetNetworkInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int count;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+#ifdef DEBUG
+ GSM_NetworkInfo NetInfo;
+ char name[100];
+
+ NetInfo.GPRS = 0;
+ smprintf(s, "Network info received\n");
+ smprintf(s, "Status : ");
+ switch (msg->Buffer[8]) {
+ case 0x01: smprintf(s, "home network"); break;
+ case 0x02: smprintf(s, "roaming network"); break;
+ case 0x03: smprintf(s, "requesting network"); break;
+ case 0x04: smprintf(s, "not registered in the network"); break;
+ default : smprintf(s, "unknown");
+ }
+ smprintf(s, "\n");
+ smprintf(s, "Network selection : %s\n", msg->Buffer[9]==1?"manual":"automatic");
+ if (msg->Buffer[8]<0x03) {
+ sprintf(NetInfo.CID, "%02X%02X", msg->Buffer[10], msg->Buffer[11]);
+ smprintf(s, "CID : %s\n", NetInfo.CID);
+
+ sprintf(NetInfo.LAC, "%02X%02X", msg->Buffer[12], msg->Buffer[13]);
+ smprintf(s, "LAC : %s\n", NetInfo.LAC);
+
+ NOKIA_DecodeNetworkCode(msg->Buffer+14,NetInfo.NetworkCode);
+ smprintf(s, "Network code : %s\n", NetInfo.NetworkCode);
+ smprintf(s, "Network name for Gammu : %s ",
+ DecodeUnicodeString(GSM_GetNetworkName(NetInfo.NetworkCode)));
+ smprintf(s, "(%s)\n",DecodeUnicodeString(GSM_GetCountryName(NetInfo.NetworkCode)));
+
+ if (msg->Length>18) {
+ if (msg->Buffer[18]==0x00) {
+ /* In 6210 name is in "normal" Unicode */
+ memcpy(name,msg->Buffer+18,msg->Buffer[17]*2);
+ name[msg->Buffer[17]*2] =0x00;
+ name[msg->Buffer[17]*2+1]=0x00;
+ smprintf(s, "Network name for phone : %s\n",DecodeUnicodeString(name));
+ } else {
+ /* In 9210 first 0x00 is cut from Unicode string */
+ name[0] = 0;
+ memcpy(name+1,msg->Buffer+18,msg->Buffer[17]*2);
+ name[msg->Buffer[17]*2+1]=0x00;
+ name[msg->Buffer[17]*2+2]=0x00;
+ smprintf(s, "Network name for phone : %s\n",DecodeUnicodeString(name));
+ }
+ }
+ }
+#endif
+ if (Data->RequestID==ID_GetNetworkInfo) {
+ Data->NetworkInfo->NetworkName[0] = 0x00;
+ Data->NetworkInfo->NetworkName[1] = 0x00;
+ Data->NetworkInfo->State = 0;
+ switch (msg->Buffer[8]) {
+ case 0x01: Data->NetworkInfo->State = GSM_HomeNetwork; break;
+ case 0x02: Data->NetworkInfo->State = GSM_RoamingNetwork; break;
+ case 0x03: Data->NetworkInfo->State = GSM_RequestingNetwork; break;
+ case 0x04: Data->NetworkInfo->State = GSM_NoNetwork; break;
+ }
+ if (Data->NetworkInfo->State == GSM_HomeNetwork || Data->NetworkInfo->State == GSM_RoamingNetwork) {
+ if (msg->Buffer[18]==0x00) {
+ /* In 6210 name is in "normal" Unicode */
+ memcpy(Data->NetworkInfo->NetworkName,msg->Buffer+18,msg->Buffer[17]*2);
+ Data->NetworkInfo->NetworkName[msg->Buffer[17]*2] = 0x00;
+ Data->NetworkInfo->NetworkName[msg->Buffer[17]*2+1] = 0x00;
+ } else {
+ /* In 9210 first 0x00 is cut from Unicode string */
+ Data->NetworkInfo->NetworkName[0] = 0;
+ memcpy(Data->NetworkInfo->NetworkName+1,msg->Buffer+18,msg->Buffer[17]*2);
+ Data->NetworkInfo->NetworkName[msg->Buffer[17]*2+1]=0x00;
+ Data->NetworkInfo->NetworkName[msg->Buffer[17]*2+2]=0x00;
+ }
+ NOKIA_DecodeNetworkCode(msg->Buffer+14,Data->NetworkInfo->NetworkCode);
+ sprintf(Data->NetworkInfo->CID, "%02X%02X", msg->Buffer[10], msg->Buffer[11]);
+ sprintf(Data->NetworkInfo->LAC, "%02X%02X", msg->Buffer[12], msg->Buffer[13]);
+ }
+ }
+ /* 6210/6250/7110 */
+ if (Data->RequestID==ID_GetBitmap) {
+ if (msg->Buffer[4]==0x02) {
+ smprintf(s, "Operator logo available\n");
+ count = 7;
+ /* skip network info */
+ count += msg->Buffer[count];
+ count ++;
+ Data->Bitmap->BitmapWidth = msg->Buffer[count++];
+ Data->Bitmap->BitmapHeight = msg->Buffer[count++];
+ count+=4;
+ PHONE_DecodeBitmap(GSM_Nokia7110OperatorLogo,msg->Buffer+count,Data->Bitmap);
+ NOKIA_DecodeNetworkCode(msg->Buffer+14,Data->Bitmap->NetworkCode);
+ } else {
+ Data->Bitmap->BitmapWidth = 78;
+ Data->Bitmap->BitmapHeight = 21;
+ GSM_ClearBitmap(Data->Bitmap);
+ strcpy(Data->Bitmap->NetworkCode,"000 00");
+ }
+ }
+ return ERR_NONE;
+}
+
+GSM_Error DCT3_GetNetworkInfo(GSM_StateMachine *s, GSM_NetworkInfo *netinfo)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x70};
+
+ netinfo->GPRS = 0;
+ s->Phone.Data.NetworkInfo=netinfo;
+ smprintf(s, "Getting network info\n");
+ return GSM_WaitFor (s, req, 4, 0x0a, 4, ID_GetNetworkInfo);
+}
+
+GSM_Error DCT3_ReplyDialCommand(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Answer for call commands\n");
+ return ERR_NONE;
+}
+
+GSM_Error DCT3_DialVoice(GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber)
+{
+ unsigned int i = 0;
+ GSM_Error error;
+ unsigned char req[100] = {0x00, 0x01, 0x7c,
+ 0x01}; /* call command */
+
+ if (ShowNumber != GSM_CALL_DefaultNumberPresence) return ERR_NOTSUPPORTED;
+
+ error=DCT3_EnableSecurity (s, 0x01);
+ if (error!=ERR_NONE) return error;
+
+ for (i=0; i < strlen(number); i++) req[4+i]=number[i];
+ req[4+i+1]=0;
+
+ smprintf(s, "Making voice call\n");
+ return GSM_WaitFor (s, req, 4+strlen(number)+1, 0x40, 4, ID_DialVoice);
+}
+
+static GSM_Error DCT3_CancelAllCalls(GSM_StateMachine *s)
+{
+ GSM_Error error;
+ unsigned char req[] = {0x00, 0x01, 0x7c,
+ 0x03}; /* call command */
+
+ error=DCT3_EnableSecurity (s, 0x01);
+ if (error!=ERR_NONE) return error;
+
+ smprintf(s, "Canceling calls\n");
+ return GSM_WaitFor (s, req, 4, 0x40, 4, ID_CancelCall);
+}
+
+GSM_Error DCT3_CancelCall(GSM_StateMachine *s, int ID, gboolean all)
+{
+ if (!all) return DCT3DCT4_CancelCall(s,ID);
+ return DCT3_CancelAllCalls(s);
+}
+
+GSM_Error DCT3_AnswerAllCalls(GSM_StateMachine *s)
+{
+ GSM_Error error;
+ unsigned char req[] = {0x00, 0x01, 0x7c,
+ 0x02}; /* call command */
+
+ error=DCT3_EnableSecurity (s, 0x01);
+ if (error!=ERR_NONE) return error;
+
+ smprintf(s, "Answering calls\n");
+ return GSM_WaitFor (s, req, 4, 0x40, 4, ID_AnswerCall);
+}
+
+GSM_Error DCT3_Reset(GSM_StateMachine *s, gboolean hard)
+{
+ GSM_Error error;
+
+ if (hard) {
+ error=DCT3_EnableSecurity(s, 0x04);
+ } else {
+ error=DCT3_EnableSecurity(s, 0x03);
+ }
+ if (error == ERR_NONE) {
+ s->Phone.Data.EnableIncomingSMS = FALSE;
+ s->Phone.Data.EnableIncomingCB = FALSE;
+ }
+ return error;
+}
+
+GSM_Error DCT3_ReplyGetWAPBookmark(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ return DCT3DCT4_ReplyGetWAPBookmark (msg,s,FALSE);
+}
+
+GSM_Error DCT3_SetWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
+{
+ GSM_Error error;
+ int count = 4, location;
+ unsigned char req[600] = {N6110_FRAME_HEADER, 0x09};
+
+ /* We have to enable WAP frames in phone */
+ error=DCT3DCT4_EnableWAPFunctions(s);
+ if (error!=ERR_NONE) return error;
+
+ location = bookmark->Location - 1;
+ if (bookmark->Location == 0) location = 0xffff;
+ req[count++] = (location & 0xff00) >> 8;
+ req[count++] = location & 0x00ff;
+
+ count += NOKIA_SetUnicodeString(s, req+count, bookmark->Title, FALSE);
+ count += NOKIA_SetUnicodeString(s, req+count, bookmark->Address, FALSE);
+
+ /* unknown */
+ req[count++] = 0x01; req[count++] = 0x80; req[count++] = 0x00;
+ req[count++] = 0x00; req[count++] = 0x00; req[count++] = 0x00;
+ req[count++] = 0x00; req[count++] = 0x00; req[count++] = 0x00;
+
+ smprintf(s, "Setting WAP bookmark\n");
+ error = GSM_WaitFor (s, req, count, 0x3f, 4, ID_SetWAPBookmark);
+ if (error != ERR_NONE) {
+ if (error == ERR_INSIDEPHONEMENU || error == ERR_EMPTY || error == ERR_FULL) {
+ DCT3DCT4_DisableConnectionFunctions(s);
+ }
+ return error;
+ }
+
+ return DCT3DCT4_DisableConnectionFunctions(s);
+}
+
+GSM_Error DCT3_ReplyGetWAPSettings(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int tmp,Number;
+/* int tmp2; */
+ GSM_Phone_Data *Data = &s->Phone.Data;
+#ifdef GSM_ENABLE_NOKIA6110
+ GSM_Phone_N6110Data *Priv6110 = &s->Phone.Data.Priv.N6110;
+#endif
+#ifdef GSM_ENABLE_NOKIA7110
+ GSM_Phone_N7110Data *Priv7110 = &s->Phone.Data.Priv.N7110;
+#endif
+
+ switch(msg->Buffer[3]) {
+ case 0x16:
+ smprintf(s, "WAP settings part 1 received OK\n");
+
+ tmp = 4;
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[0].Title,FALSE);
+ smprintf(s, "Title: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[0].Title));
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[0].HomePage,FALSE);
+ smprintf(s, "Homepage: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[0].HomePage));
+#ifdef DEBUG
+ smprintf(s, "Connection type: ");
+ switch (msg->Buffer[tmp]) {
+ case 0x00: smprintf(s, "temporary\n"); break;
+ case 0x01: smprintf(s, "continuous\n"); break;
+ default: smprintf(s, "unknown\n");
+ }
+ smprintf(s, "Connection security: ");
+ switch (msg->Buffer[tmp+13]) {
+ case 0x00: smprintf(s, "off\n"); break;
+ case 0x01: smprintf(s, "on\n"); break;
+ default: smprintf(s, "unknown\n");
+ }
+#endif
+ Data->WAPSettings->Settings[0].IsContinuous = FALSE;
+ if (msg->Buffer[tmp] == 0x01) Data->WAPSettings->Settings[0].IsContinuous = TRUE;
+ Data->WAPSettings->Settings[0].IsSecurity = FALSE;
+ if (msg->Buffer[tmp+13] == 0x01) Data->WAPSettings->Settings[0].IsSecurity = TRUE;
+
+ /* I'm not sure here. Experimental values from 6210 5.56 */
+/* tmp2 = DecodeUnicodeLength(Data->WAPSettings->Settings[0].Title); */
+/* if (tmp2 != 0) tmp2 --; */
+/* tmp2 += tmp; */
+ if (!(UnicodeLength(Data->WAPSettings->Settings[0].Title)) % 2) tmp++;
+ if (UnicodeLength(Data->WAPSettings->Settings[0].HomePage)!=0) tmp++;
+
+ smprintf(s, "ID for writing %i\n",msg->Buffer[tmp+5]);
+
+ smprintf(s, "Current set location in phone %i\n",msg->Buffer[tmp+6]);
+
+ smprintf(s, "1 location %i\n",msg->Buffer[tmp+8]);
+ smprintf(s, "2 location %i\n",msg->Buffer[tmp+9]);
+ smprintf(s, "3 location %i\n",msg->Buffer[tmp+10]);
+ smprintf(s, "4 location %i\n",msg->Buffer[tmp+11]);
+#ifdef GSM_ENABLE_NOKIA7110
+ if (strstr(N7110Phone.models, Data->ModelInfo->model) != NULL) {
+ Priv7110->WAPLocations.ID = msg->Buffer[tmp+5];
+ Priv7110->WAPLocations.CurrentLocation = msg->Buffer[tmp+6];
+ Priv7110->WAPLocations.Locations[0] = msg->Buffer[tmp+8];
+ Priv7110->WAPLocations.Locations[1] = msg->Buffer[tmp+9];
+ Priv7110->WAPLocations.Locations[2] = msg->Buffer[tmp+10];
+ Priv7110->WAPLocations.Locations[3] = msg->Buffer[tmp+11];
+
+/* Priv7110->WAPLocations.CurrentLocation = msg->Buffer[tmp2+1]; */
+/* Priv7110->WAPLocations.Locations[0] = msg->Buffer[tmp2+3]; */
+/* Priv7110->WAPLocations.Locations[1] = msg->Buffer[tmp2+4]; */
+/* Priv7110->WAPLocations.Locations[2] = msg->Buffer[tmp2+5]; */
+/* Priv7110->WAPLocations.Locations[3] = msg->Buffer[tmp2+6]; */
+ }
+#endif
+#ifdef GSM_ENABLE_NOKIA6110
+ if (strstr(N6110Phone.models, Data->ModelInfo->model) != NULL) {
+ Priv6110->WAPLocations.ID = msg->Buffer[tmp+5];
+ Priv6110->WAPLocations.CurrentLocation = msg->Buffer[tmp+6];
+ Priv6110->WAPLocations.Locations[0] = msg->Buffer[tmp+8];
+ Priv6110->WAPLocations.Locations[1] = msg->Buffer[tmp+9];
+ Priv6110->WAPLocations.Locations[2] = msg->Buffer[tmp+10];
+ Priv6110->WAPLocations.Locations[3] = msg->Buffer[tmp+11];
+ }
+#endif
+ return ERR_NONE;
+ case 0x17:
+ smprintf(s, "WAP settings part 1 receiving error\n");
+ switch (msg->Buffer[4]) {
+ case 0x01:
+ smprintf(s, "Security error. Inside WAP settings menu\n");
+ return ERR_INSIDEPHONEMENU;
+ case 0x02:
+ smprintf(s, "Invalid or empty\n");
+ return ERR_INVALIDLOCATION;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ case 0x1c:
+ smprintf(s, "WAP settings part 2 received OK\n");
+ Number = Data->WAPSettings->Number;
+ switch (msg->Buffer[5]) {
+ case 0x00:
+ Data->WAPSettings->Settings[Number].Bearer = WAPSETTINGS_BEARER_SMS;
+ smprintf(s, "Settings for SMS bearer:\n");
+ tmp = 6;
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[Number].Service,FALSE);
+ smprintf(s, "Service number: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].Service));
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[Number].Server,FALSE);
+ smprintf(s, "Server number: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].Server));
+ break;
+ case 0x01:
+ Data->WAPSettings->Settings[Number].Bearer = WAPSETTINGS_BEARER_DATA;
+ smprintf(s, "Settings for data bearer:\n");
+ Data->WAPSettings->Settings[Number].ManualLogin = FALSE;
+ tmp = 10;
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[Number].IPAddress,FALSE);
+ smprintf(s, "IP address: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].IPAddress));
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[Number].DialUp,FALSE);
+ smprintf(s, "Dial-up number: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].DialUp));
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[Number].User,FALSE);
+ smprintf(s, "User name: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].User));
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[Number].Password,FALSE);
+ smprintf(s, "Password: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].Password));
+#ifdef DEBUG
+ smprintf(s, "Authentication type: ");
+ switch (msg->Buffer[6]) {
+ case 0x00: smprintf(s, "normal\n"); break;
+ case 0x01: smprintf(s, "secure\n"); break;
+ default: smprintf(s, "unknown\n"); break;
+ }
+ smprintf(s, "Data call type: ");
+ switch (msg->Buffer[7]) {
+ case 0x00: smprintf(s, "analogue\n"); break;
+ case 0x01: smprintf(s, "ISDN\n"); break;
+ default: smprintf(s, "unknown\n"); break;
+ }
+ smprintf(s, "Data call speed: ");
+ switch (msg->Buffer[9]) {
+ case 0x01: smprintf(s, "9600\n"); break;
+ case 0x02: smprintf(s, "14400\n"); break;
+ default: smprintf(s, "unknown\n"); break;
+ }
+#endif
+ Data->WAPSettings->Settings[Number].IsNormalAuthentication=TRUE;
+ if (msg->Buffer[6]==0x01) Data->WAPSettings->Settings[Number].IsNormalAuthentication=FALSE;
+ Data->WAPSettings->Settings[Number].IsISDNCall=FALSE;
+ if (msg->Buffer[7]==0x01) Data->WAPSettings->Settings[Number].IsISDNCall=TRUE;
+ Data->WAPSettings->Settings[Number].Speed = WAPSETTINGS_SPEED_9600;
+ if (msg->Buffer[9]==0x02) Data->WAPSettings->Settings[Number].Speed = WAPSETTINGS_SPEED_14400;
+ break;
+ case 0x02:
+ Data->WAPSettings->Settings[Number].Bearer=WAPSETTINGS_BEARER_USSD;
+ smprintf(s, "Settings for USSD bearer:\n");
+ tmp = 7;
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[Number].Service,FALSE);
+#ifdef DEBUG
+ if (msg->Buffer[6]==0x01)
+ smprintf(s, "Service number: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].Service));
+ else
+ smprintf(s, "IP address: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].Service));
+#endif
+ Data->WAPSettings->Settings[Number].IsIP=TRUE;
+ if (msg->Buffer[6]==0x01) Data->WAPSettings->Settings[Number].IsIP=FALSE;
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[Number].Code,FALSE);
+ smprintf(s, "Service code: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[Number].Code));
+ }
+ Data->WAPSettings->Number++;
+ return ERR_NONE;
+ case 0x1d:
+ smprintf(s, "Incorrect WAP settings location\n");
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+GSM_Error DCT3_GetWAPSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings)
+{
+#ifdef GSM_ENABLE_NOKIA6110
+ GSM_Phone_N6110Data *Priv6110 = &s->Phone.Data.Priv.N6110;
+#endif
+#ifdef GSM_ENABLE_NOKIA7110
+ GSM_Phone_N7110Data *Priv7110 = &s->Phone.Data.Priv.N7110;
+#endif
+ GSM_Error error;
+ int i;
+ unsigned char req[] = {N6110_FRAME_HEADER,0x15,
+ 0x00}; /* Location */
+ unsigned char req2[] = {N6110_FRAME_HEADER,0x1b,
+ 0x00}; /* Location */
+
+ /* We have to enable WAP frames in phone */
+ error=DCT3DCT4_EnableWAPFunctions(s);
+ if (error!=ERR_NONE) return error;
+
+ s->Phone.Data.WAPSettings = settings;
+ settings->Number = 0;
+ settings->ReadOnly = FALSE;
+
+ req[4] = settings->Location-1;
+ smprintf(s, "Getting WAP settings part 1\n");
+ error = GSM_WaitFor (s, req, 5, 0x3f, 4, ID_GetConnectSet);
+ if (error != ERR_NONE) return error;
+
+#ifdef GSM_ENABLE_NOKIA7110
+ if (strstr(N7110Phone.models, s->Phone.Data.ModelInfo->model) != NULL) {
+ for (i=0;i<4;i++) {
+ req2[4] = Priv7110->WAPLocations.Locations[i];
+ smprintf(s, "Getting WAP settings part 2\n");
+ error=GSM_WaitFor (s, req2, 5, 0x3f, 4, ID_GetConnectSet);
+ if (error != ERR_NONE) return error;
+ if (Priv7110->WAPLocations.Locations[i] == Priv7110->WAPLocations.CurrentLocation) {
+ settings->ActiveBearer = settings->Settings[settings->Number-1].Bearer;
+ }
+ }
+ }
+#endif
+#ifdef GSM_ENABLE_NOKIA6110
+ if (strstr(N6110Phone.models, s->Phone.Data.ModelInfo->model) != NULL) {
+ for (i=0;i<4;i++) {
+ req2[4] = Priv6110->WAPLocations.Locations[i];
+ smprintf(s, "Getting WAP settings part 2\n");
+ error=GSM_WaitFor (s, req2, 5, 0x3f, 4, ID_GetConnectSet);
+ if (error != ERR_NONE) return error;
+ if (Priv6110->WAPLocations.Locations[i] == Priv6110->WAPLocations.CurrentLocation) {
+ settings->ActiveBearer = settings->Settings[settings->Number-1].Bearer;
+ }
+ }
+ }
+#endif
+ if (error == ERR_NONE) {
+ for (i=1;i<3;i++) {
+ CopyUnicodeString(settings->Settings[i].Title,settings->Settings[0].Title);
+ CopyUnicodeString(settings->Settings[i].HomePage,settings->Settings[0].HomePage);
+ settings->Settings[i].IsContinuous = settings->Settings[0].IsContinuous;
+ settings->Settings[i].IsSecurity = settings->Settings[0].IsSecurity;
+
+ settings->Settings[i].IsContinuous = settings->Settings[0].IsContinuous;
+ settings->Settings[i].IsSecurity = settings->Settings[0].IsSecurity;
+ }
+ error = DCT3DCT4_GetActiveConnectSet(s);
+ }
+ if (error != ERR_NONE) return error;
+
+ settings->Proxy[0] = 0x00;
+ settings->Proxy[1] = 0x00;
+ settings->ProxyPort = 8080;
+
+ settings->Proxy2[0] = 0x00;
+ settings->Proxy2[1] = 0x00;
+ settings->Proxy2Port = 8080;
+
+ return DCT3DCT4_DisableConnectionFunctions(s);
+}
+
+GSM_Error DCT3_ReplySetWAPSettings(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch(msg->Buffer[3]) {
+ case 0x19:
+ smprintf(s, "WAP settings part 1 set OK\n");
+ return ERR_NONE;
+ case 0x1a:
+ smprintf(s, "WAP settings part 1 setting error\n");
+ switch (msg->Buffer[4]) {
+ case 0x01:
+ smprintf(s, "Security error. Inside WAP settings menu\n");
+ return ERR_INSIDEPHONEMENU;
+ case 0x02:
+ smprintf(s, "Incorrect data\n");
+ return ERR_UNKNOWN;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ case 0x1F:
+ smprintf(s, "WAP settings part 2 set OK\n");
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+GSM_Error DCT3_SetWAPSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings)
+{
+#ifdef GSM_ENABLE_NOKIA6110
+ GSM_Phone_N6110Data *Priv6110 = &s->Phone.Data.Priv.N6110;
+#endif
+#ifdef GSM_ENABLE_NOKIA7110
+ GSM_Phone_N7110Data *Priv7110 = &s->Phone.Data.Priv.N7110;
+#endif
+ GSM_Error error;
+ GSM_MultiWAPSettings settings2;
+ int i,pos,phone1=-1,phone2=-1,phone3=-1;
+ int ID=0,locations[4] = {0, 0, 0, 0},loc1=-1,loc2=-1,loc3=-1;
+ unsigned char req[] = {N6110_FRAME_HEADER,0x15,
+ 0x00, 0x00}; /* Location */
+ unsigned char req2[] = {N6110_FRAME_HEADER,0x1b,
+ 0x00, 0x00}; /* Location */
+ unsigned char SetReq[200] = {N7110_FRAME_HEADER, 0x18,
+ 0x00}; /* Location */
+ unsigned char SetReq2[200] = {N7110_FRAME_HEADER, 0x1e,
+ 0x00}; /* Location */
+
+ /* We have to enable WAP frames in phone */
+ error=DCT3DCT4_EnableWAPFunctions(s);
+ if (error!=ERR_NONE) return error;
+
+ s->Phone.Data.WAPSettings = &settings2;
+ settings2.Number = 0;
+
+ req[4] = settings->Location-1;
+ smprintf(s, "Getting WAP settings part 1\n");
+ error = GSM_WaitFor (s, req, 6, 0x3f, 4, ID_GetConnectSet);
+ if (error != ERR_NONE) return error;
+
+#ifdef GSM_ENABLE_NOKIA6110
+ if (strstr(N6110Phone.models, s->Phone.Data.ModelInfo->model) != NULL) {
+ for (i=0;i<4;i++) locations[i] = Priv6110->WAPLocations.Locations[i];
+ ID = Priv6110->WAPLocations.ID;
+ }
+#endif
+#ifdef GSM_ENABLE_NOKIA7110
+ if (strstr(N7110Phone.models, s->Phone.Data.ModelInfo->model) != NULL) {
+ for (i=0;i<4;i++) locations[i] = Priv7110->WAPLocations.Locations[i];
+ ID = Priv7110->WAPLocations.ID;
+ }
+#endif
+
+ /* Now we get info about supported types by phone and their locations */
+ for (i=0;i<4;i++) {
+ settings2.Number = 0;
+ settings2.Settings[0].Bearer = 0;
+ req2[4] = locations[i];
+ smprintf(s, "Getting WAP settings part 2\n");
+ error=GSM_WaitFor (s, req2, 6, 0x3f, 4, ID_GetConnectSet);
+ if (error != ERR_NONE) return error;
+ switch (settings2.Settings[0].Bearer) {
+ case WAPSETTINGS_BEARER_DATA: phone1 = locations[i]; break;
+ case WAPSETTINGS_BEARER_SMS : phone2 = locations[i]; break;
+ case WAPSETTINGS_BEARER_USSD: phone3 = locations[i]; break;
+ default : break;
+ }
+ if (error != ERR_NONE) return error;
+ }
+
+ /* We have some phone locations and some data to set. We try to
+ * find info about locations in phone used to write concrete bearers
+ */
+ for (i=0;i<settings->Number;i++) {
+ if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_DATA) {
+ if (phone1 != -1) loc1=i;
+ }
+ if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_SMS) {
+ if (phone2 != -1) loc2=i;
+ }
+ if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_USSD) {
+ if (phone3 != -1) loc3=i;
+ }
+ }
+
+ pos = 5;
+ memset(SetReq + pos, 0, 200 - pos);
+ SetReq[4] = settings->Location - 1;
+ if (loc1 != -1) {
+ /* Name */
+ pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc1].Title, FALSE);
+ /* HomePage */
+ pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc1].HomePage, FALSE);
+ if (settings->Settings[loc1].IsContinuous) SetReq[pos] = 0x01;
+ pos++;
+ SetReq[pos++] = ID;
+
+ SetReq[pos] = phone1; /* bearer */
+ switch (settings->ActiveBearer) {
+ case WAPSETTINGS_BEARER_DATA:
+ if (loc1 != -1) SetReq[pos] = phone1;
+ break;
+ case WAPSETTINGS_BEARER_SMS:
+ if (loc2 != -1) SetReq[pos] = phone2;
+ break;
+ case WAPSETTINGS_BEARER_USSD:
+ if (loc3 != -1) SetReq[pos] = phone3;
+ break;
+ default: break;
+ }
+ pos++;
+
+ if (settings->Settings[loc1].IsSecurity) SetReq[pos] = 0x01;
+ pos++;
+ } else if (loc2 != -1) {
+ /* Name */
+ pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc2].Title, FALSE);
+ /* HomePage */
+ pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc2].HomePage, FALSE);
+ if (settings->Settings[loc2].IsContinuous) SetReq[pos] = 0x01;
+ pos++;
+ SetReq[pos++] = ID;
+
+ SetReq[pos] = phone2; /* bearer */
+ switch (settings->ActiveBearer) {
+ case WAPSETTINGS_BEARER_DATA:
+ if (loc1 != -1) SetReq[pos] = phone1;
+ break;
+ case WAPSETTINGS_BEARER_SMS:
+ if (loc2 != -1) SetReq[pos] = phone2;
+ break;
+ case WAPSETTINGS_BEARER_USSD:
+ if (loc3 != -1) SetReq[pos] = phone3;
+ break;
+ default: break;
+ }
+ pos++;
+
+ if (settings->Settings[loc2].IsSecurity) SetReq[pos] = 0x01;
+ pos++;
+ } else if (loc3 != -1) {
+ /* Name */
+ pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc3].Title, FALSE);
+ /* HomePage */
+ pos += NOKIA_SetUnicodeString(s, SetReq + pos, settings->Settings[loc3].HomePage, FALSE);
+ if (settings->Settings[loc3].IsContinuous) SetReq[pos] = 0x01;
+ pos++;
+ SetReq[pos++] = ID;
+
+ SetReq[pos] = phone3; /* bearer */
+ switch (settings->ActiveBearer) {
+ case WAPSETTINGS_BEARER_DATA:
+ if (loc1 != -1) SetReq[pos] = phone1;
+ break;
+ case WAPSETTINGS_BEARER_SMS:
+ if (loc2 != -1) SetReq[pos] = phone2;
+ break;
+ case WAPSETTINGS_BEARER_USSD:
+ if (loc3 != -1) SetReq[pos] = phone3;
+ break;
+ default: break;
+ }
+ pos++;
+
+ if (settings->Settings[loc3].IsSecurity) SetReq[pos] = 0x01;
+ pos++;
+ } else {
+ return ERR_UNKNOWN; /* We have to have write something known */
+ }
+ memcpy(SetReq + pos, "\x01\x80\x00\x00\x00\x00\x00\x00\x00", 9);
+ pos += 9;
+
+ smprintf(s, "Writing WAP settings part 1\n");
+ error=GSM_WaitFor (s, SetReq, pos, 0x3f, 4, ID_SetConnectSet);
+ if (error != ERR_NONE) return error;
+
+ /* Data */
+ if (phone1 != -1) {
+ pos = 4;
+ memset(SetReq2 + pos, 0, 200 - pos);
+ SetReq2[pos++] = phone1;
+ SetReq2[pos++] = 0x02;
+ SetReq2[pos++] = 0x01; /* GSMdata */
+ if (loc1 != -1) {
+ if (!settings->Settings[loc1].IsNormalAuthentication) SetReq2[pos] = 0x01;
+ }
+ pos++;
+ if (loc1 != -1) {
+ if (settings->Settings[loc1].IsISDNCall) SetReq2[pos] = 0x01;
+ }
+ pos++;
+ if (loc1 != -1) {
+ switch (settings->Settings[loc1].Speed) {
+ case WAPSETTINGS_SPEED_9600 : SetReq2[pos++] = 0x01; break;
+ case WAPSETTINGS_SPEED_14400 : SetReq2[pos++] = 0x02; break;
+ default : SetReq2[pos++] = 0x02; break;
+ }
+ switch (settings->Settings[loc1].Speed) {
+ case WAPSETTINGS_SPEED_9600 : SetReq2[pos++] = 0x01; break;
+ case WAPSETTINGS_SPEED_14400 : SetReq2[pos++] = 0x02; break;
+ default : SetReq2[pos++] = 0x02; break;
+ }
+ } else pos+=2;
+ if (loc1 != -1) {
+ /* IP */
+ pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc1].IPAddress, FALSE);
+ /* Number */
+ pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc1].DialUp, FALSE);
+ /* Username */
+ pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc1].User, FALSE);
+ /* Password */
+ pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc1].Password, FALSE);
+ } else pos+=5;
+ memcpy(SetReq2 + pos, "\x80\x00\x00\x00\x00\x00\x00\x00", 8);
+ pos += 8;
+ smprintf(s, "Writing WAP settings part 2 (Data bearer)\n");
+ error=GSM_WaitFor (s, SetReq2, pos, 0x3f, 4, ID_SetConnectSet);
+ if (error != ERR_NONE) return error;
+ }
+ /* SMS */
+ if (phone2 != -1) {
+ pos = 4;
+ memset(SetReq2 + pos, 0, 200 - pos);
+ SetReq2[pos++] = phone2;
+ SetReq2[pos++] = 0x02;
+ SetReq2[pos++] = 0x00; /* SMS */
+ if (loc2 != -1) {
+ /* Service number */
+ pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc2].Service, FALSE);
+ /* Server number */
+ pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc2].Server, FALSE);
+ } else pos += 2;
+ memcpy(SetReq2 + pos, "\x80\x00\x00\x00\x00\x00\x00\x00", 8);
+ pos += 8;
+ smprintf(s, "Writing WAP settings part 2 (SMS bearer)\n");
+ error=GSM_WaitFor (s, SetReq2, pos, 0x3f, 4, ID_SetConnectSet);
+ if (error != ERR_NONE) return error;
+ }
+ /* USSD */
+ if (phone3 != -1) {
+ pos = 4;
+ memset(SetReq2 + pos, 0, 200 - pos);
+ SetReq2[pos++] = phone3;
+ SetReq2[pos++] = 0x02;
+ SetReq2[pos++] = 0x02; /* USSD */
+ if (loc3 != -1) {
+ if (!settings->Settings[loc3].IsIP) SetReq2[pos] = 0x01;
+ }
+ pos++;
+ if (loc3 != -1) {
+ /* Service number or IP address */
+ pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc3].Service, FALSE);
+ /* Code number */
+ pos += NOKIA_SetUnicodeString(s, SetReq2 + pos, settings->Settings[loc3].Code, FALSE);
+ } else pos+=2;
+ memcpy(SetReq2 + pos, "\x80\x00\x00\x00\x00\x00\x00\x00", 8);
+ pos += 8;
+ smprintf(s, "Writing WAP settings part 2 (USSD bearer)\n");
+ error=GSM_WaitFor (s, SetReq2, pos, 0x3f, 4, ID_SetConnectSet);
+ if (error != ERR_NONE) return error;
+ }
+ error = DCT3DCT4_SetActiveConnectSet(s, settings);
+ if (error != ERR_NONE) return error;
+
+ return DCT3DCT4_DisableConnectionFunctions(s);
+}
+
+GSM_Error DCT3_ReplySendSMSMessage(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x02:
+ smprintf(s, "SMS sent OK\n");
+ if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s,0,msg->Buffer[5], s->User.SendSMSStatusUserData);
+ return ERR_NONE;
+ case 0x03:
+ smprintf(s, "Error %i\n",msg->Buffer[6]);
+ if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s,msg->Buffer[6],-1, s->User.SendSMSStatusUserData);
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+GSM_Error DCT3_SendSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms)
+{
+ int length;
+ GSM_Error error;
+ unsigned char req[256] = {N6110_FRAME_HEADER, 0x01, 0x02, 0x00};
+
+ error=PHONE_EncodeSMSFrame(s,sms,req+6,PHONE_SMSSubmit,&length, TRUE);
+ if (error != ERR_NONE) return error;
+
+ smprintf(s, "Sending sms\n");
+ return s->Protocol.Functions->WriteMessage(s, req, 6+length, 0x02);
+}
+
+GSM_Error DCT3_ReplyNetmonitor(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x00:
+ smprintf(s, "Netmonitor correctly set\n");
+ break;
+ default:
+ smprintf(s, "Menu %i\n",msg->Buffer[3]);
+ smprintf(s, "%s\n",msg->Buffer+4);
+ strcpy(s->Phone.Data.Netmonitor,msg->Buffer+4);
+ break;
+ }
+ return ERR_NONE;
+}
+
+GSM_Error DCT3_Netmonitor(GSM_StateMachine *s, int testnumber, char *value)
+{
+ GSM_Error error;
+ unsigned char req[] = {0x00, 0x01, 0x7e,
+ 0x00}; /* Test number */
+
+ value[0] = 0;
+
+ error=DCT3_EnableSecurity (s, 0x01);
+ if (error != ERR_NONE) return error;
+
+ req[3] = testnumber;
+
+ smprintf(s, "Getting netmonitor test\n");
+ s->Phone.Data.Netmonitor = value;
+ return GSM_WaitFor (s, req, 4, 0x40, 4, ID_Netmonitor);
+}
+
+GSM_Error DCT3_GetManufactureMonth(GSM_StateMachine *s, char *value)
+{
+ GSM_Error error;
+
+ error=DCT3_EnableSecurity (s, 0x01);
+ if (error != ERR_NONE) return error;
+ return NOKIA_GetPhoneString(s,"\x00\x01\xCC\x02",4,0x40,value,ID_GetManufactureMonth,5);
+}
+
+GSM_Error DCT3_GetProductCode(GSM_StateMachine *s, char *value)
+{
+ GSM_Error error;
+
+ if (strlen(s->Phone.Data.ProductCodeCache)!=0) {
+ strcpy(value,s->Phone.Data.ProductCodeCache);
+ return ERR_NONE;
+ }
+
+ error=DCT3_EnableSecurity (s, 0x01);
+ if (error != ERR_NONE) return error;
+ return NOKIA_GetPhoneString(s,"\x00\x01\xCA\x01",4,0x40,value,ID_GetProductCode,5);
+}
+
+GSM_Error DCT3_GetOriginalIMEI(GSM_StateMachine *s, char *value)
+{
+ GSM_Error error;
+
+ error=DCT3_EnableSecurity (s, 0x01);
+ if (error != ERR_NONE) return error;
+ return NOKIA_GetPhoneString(s,"\x00\x01\xCC\x01",4,0x40,value,ID_GetOriginalIMEI,5);
+}
+
+GSM_Error DCT3_GetHardware(GSM_StateMachine *s, char *value)
+{
+ GSM_Error error;
+
+ if (strlen(s->Phone.Data.HardwareCache)!=0) {
+ strcpy(value,s->Phone.Data.HardwareCache);
+ return ERR_NONE;
+ }
+
+ error=DCT3_EnableSecurity (s, 0x01);
+ if (error != ERR_NONE) return error;
+ return NOKIA_GetPhoneString(s,"\x00\x01\xC8\x05",4,0x40,value,ID_GetHardware,5);
+}
+
+GSM_Error DCT3_GetPPM(GSM_StateMachine *s, char *value)
+{
+ GSM_Error error;
+
+ error=DCT3_EnableSecurity (s, 0x01);
+ if (error != ERR_NONE) return error;
+ return NOKIA_GetPhoneString(s,"\x00\x01\xC8\x12",4,0x40,value,ID_GetPPM,5);
+}
+
+GSM_Error DCT3_GetSMSStatus(GSM_StateMachine *s, GSM_SMSMemoryStatus *status)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x36, 0x64};
+
+ s->Phone.Data.SMSStatus=status;
+ smprintf(s, "Getting SMS status\n");
+ return GSM_WaitFor (s, req, 5, 0x14, 4, ID_GetSMSStatus);
+
+ /* 6210 family doesn't show in frame with SMS status info
+ * about Templates. We get separately info about this SMS folder.
+ */
+}
+
+GSM_Error DCT3_ReplyDeleteSMSMessage(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch(msg->Buffer[3]) {
+ case 0x0b:
+ smprintf(s, "SMS deleted\n");
+ return ERR_NONE;
+ case 0x0c:
+ smprintf(s, "Error deleting SMS\n");
+ switch (msg->Buffer[4]) {
+ case 0x00:
+ /* Not tested on 6210 */
+ smprintf(s, "Unknown meaning, SMS seems to be deleted\n");
+ return ERR_NONE;
+ case 0x02:
+ /* Not tested on 6210 */
+ smprintf(s, "Invalid location\n");
+ return ERR_INVALIDLOCATION;
+ case 0x06:
+ /* Not tested on 6210 */
+ smprintf(s, "Phone is OFF\n");
+ return ERR_PHONEOFF;
+ default:
+ smprintf(s, "Unknown error: %02x\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+GSM_Error N71_92_ReplyGetSignalQuality(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "Network level received: %i\n",msg->Buffer[4]);
+ Data->SignalQuality->SignalStrength = -1;
+ Data->SignalQuality->SignalPercent = ((int)msg->Buffer[4]);
+ Data->SignalQuality->BitErrorRate = -1;
+ return ERR_NONE;
+}
+
+GSM_Error N71_92_GetSignalQuality(GSM_StateMachine *s, GSM_SignalQuality *sig)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x81};
+
+ s->Phone.Data.SignalQuality = sig;
+ smprintf(s, "Getting network level\n");
+ return GSM_WaitFor (s, req, 4, 0x0a, 4, ID_GetSignalQuality);
+}
+
+GSM_Error N71_92_ReplyGetBatteryCharge(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "Battery level received: %i\n",msg->Buffer[5]);
+ Data->BatteryCharge->BatteryPercent = ((int)msg->Buffer[5]);
+ Data->BatteryCharge->ChargeState = 0;
+ return ERR_NONE;
+}
+
+GSM_Error N71_92_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x02};
+
+ s->Phone.Data.BatteryCharge = bat;
+ smprintf(s, "Getting battery level\n");
+ return GSM_WaitFor (s, req, 4, 0x17, 4, ID_GetBatteryCharge);
+}
+
+GSM_Error N71_92_ReplyPhoneSetting(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Bitmap_Types BmpType;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ switch (msg->Buffer[4]) {
+ case 0x02:
+ if (Data->RequestID == ID_GetBitmap || Data->RequestID == ID_EachFrame) {
+ smprintf(s, "Welcome note text received\n");
+ CopyUnicodeString(Data->Bitmap->Text,msg->Buffer+6);
+ smprintf(s, "Text is \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Text));
+ return ERR_NONE;
+ }
+ if (Data->RequestID == ID_SetBitmap || Data->RequestID == ID_EachFrame) {
+ smprintf(s, "Startup text set\n");
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+ case 0x15:
+ if (Data->RequestID == ID_GetBitmap || Data->RequestID == ID_EachFrame) {
+ smprintf(s, "Startup logo received\n");
+ BmpType=GSM_Nokia7110StartupLogo;
+ if (msg->Buffer[17]==0x60) BmpType=GSM_Nokia6210StartupLogo;
+ if (msg->Buffer[17]==0xc0) BmpType=GSM_NokiaStartupLogo;
+ PHONE_DecodeBitmap(BmpType, msg->Buffer+22, Data->Bitmap);
+ return ERR_NONE;
+ }
+ if (Data->RequestID == ID_SetBitmap || Data->RequestID == ID_EachFrame) {
+ smprintf(s, "Startup logo set\n");
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+ case 0x17:
+ if (Data->RequestID == ID_GetBitmap || Data->RequestID == ID_EachFrame) {
+ smprintf(s, "Dealer note text received\n");
+ CopyUnicodeString(Data->Bitmap->Text,msg->Buffer+6);
+ smprintf(s, "Text is \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Text));
+ return ERR_NONE;
+ }
+ if (Data->RequestID == ID_SetBitmap || Data->RequestID == ID_EachFrame) {
+ smprintf(s, "Dealer text set\n");
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+GSM_Error N71_92_GetPhoneSetting(GSM_StateMachine *s, int Request, int Setting)
+{
+ unsigned char req[] = {N7110_FRAME_HEADER, 0xee,
+ 0x1c}; /* Setting */
+
+ req[4]=Setting;
+ return GSM_WaitFor (s, req, 5, 0x7a, 4, Request);
+}
+
+GSM_Error N71_92_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
+{
+ return DCT3_GetDateTime(s, date_time, 0x19);
+}
+
+GSM_Error N71_92_SetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
+{
+ return DCT3_SetDateTime(s, date_time, 0x19);
+}
+
+GSM_Error DCT3_DecodeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *SMS, unsigned char *buffer)
+{
+ switch (buffer[12] & 0x03) {
+ case 0x00:
+ smprintf(s, "SMS type - deliver\n");
+ SMS->PDU = SMS_Deliver;
+ return GSM_DecodeSMSFrame(&(s->di), SMS,buffer,PHONE_SMSDeliver);
+ case 0x01:
+ smprintf(s, "SMS type - submit\n");
+ SMS->PDU = SMS_Submit;
+ return GSM_DecodeSMSFrame(&(s->di), SMS,buffer,PHONE_SMSSubmit);
+ case 0x02:
+ smprintf(s, "SMS type - delivery report\n");
+ SMS->PDU = SMS_Status_Report;
+ return GSM_DecodeSMSFrame(&(s->di), SMS,buffer,PHONE_SMSStatusReport);
+ }
+ return ERR_UNKNOWN;
+}
+
+GSM_Error N61_91_ReplySetOpLogo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x31:
+ smprintf(s, "Operator logo set OK\n");
+ return ERR_NONE;
+ case 0x32:
+ smprintf(s, "Error setting operator logo\n");
+ switch (msg->Buffer[4]) {
+ case 0x7d:
+ smprintf(s, "Too high location ?\n");
+ return ERR_INVALIDLOCATION;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ }
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+GSM_Error N61_71_ReplyResetPhoneSettings(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Phone settings cleaned OK\n");
+ return ERR_NONE;
+}
+
+GSM_Error N61_71_ResetPhoneSettings(GSM_StateMachine *s, GSM_ResetSettingsType Type)
+{
+ GSM_Error error;
+ unsigned char req[] = {0x00, 0x01, 0x65,
+ 0x01}; /* Reset type */
+
+ switch (Type) {
+ case GSM_RESET_PHONESETTINGS : req[3] = 0x01; break;
+ case GSM_RESET_DEVICE : req[3] = 0x02; break;
+ case GSM_RESET_USERINTERFACE : req[3] = 0x08; break;
+ case GSM_RESET_USERINTERFACE_PHONESETTINGS : req[3] = 0x38; break;
+ case GSM_RESET_FULLFACTORY : req[3] = 0xff; break;
+ }
+
+ error=DCT3_EnableSecurity (s, 0x01);
+ if (error != ERR_NONE) return error;
+
+ return GSM_WaitFor (s, req, 4, 0x40, 4, ID_ResetPhoneSettings);
+}
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct3/dct3func.h b/libgammu/phone/nokia/dct3/dct3func.h
new file mode 100644
index 0000000..a3499b1
--- /dev/null
+++ b/libgammu/phone/nokia/dct3/dct3func.h
@@ -0,0 +1,81 @@
+/* (c) 2002-2003 by Marcin Wiacek */
+
+#ifndef phone_nokia_dct3_h
+#define phone_nokia_dct3_h
+
+#include "../ncommon.h"
+
+GSM_Error DCT3_ReplyPressKey (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplyPlayTone (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplyEnableSecurity (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplyGetIMEI (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplyGetSMSC (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplyWaitSMSC (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplySIMLogin (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplySIMLogout (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplyGetDateTime (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplyGetAlarm (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplySetDateTime (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplySetAlarm (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplyDialCommand (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplyGetWAPBookmark (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplyGetNetworkInfo (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplySendSMSMessage (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplySetSMSC (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplyGetWAPSettings (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplySetWAPSettings (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplyNetmonitor (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplyDeleteSMSMessage (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N71_92_ReplyGetSignalQuality (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N71_92_ReplyGetBatteryCharge (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N71_92_ReplyPhoneSetting (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N61_71_ReplyResetPhoneSettings(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N61_91_ReplySetOpLogo (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+#ifdef GSM_ENABLE_CELLBROADCAST
+GSM_Error DCT3_ReplySetIncomingCB (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3_ReplyIncomingCB (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+#endif
+
+GSM_Error DCT3_DeleteWAPBookmark (GSM_StateMachine *s, GSM_WAPBookmark *bookmark);
+GSM_Error DCT3_GetWAPBookmark (GSM_StateMachine *s, GSM_WAPBookmark *bookmark);
+GSM_Error DCT3_PressKey (GSM_StateMachine *s, GSM_KeyCode Key, gboolean Press);
+GSM_Error DCT3_PlayTone (GSM_StateMachine *s, int Herz, unsigned char Volume, gboolean start);
+GSM_Error DCT3_EnableSecurity (GSM_StateMachine *s, unsigned char status );
+GSM_Error DCT3_GetIMEI (GSM_StateMachine *s);
+GSM_Error DCT3_GetSMSC (GSM_StateMachine *s, GSM_SMSC *smsc );
+GSM_Error DCT3_GetNetworkInfo (GSM_StateMachine *s, GSM_NetworkInfo *netinfo );
+GSM_Error DCT3_DialVoice (GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber);
+GSM_Error DCT3_Reset (GSM_StateMachine *s, gboolean hard );
+GSM_Error DCT3_CancelCall (GSM_StateMachine *s, int ID, gboolean all);
+GSM_Error DCT3_AnswerAllCalls (GSM_StateMachine *s);
+GSM_Error DCT3_SendSMSMessage (GSM_StateMachine *s, GSM_SMSMessage *sms );
+GSM_Error DCT3_GetAlarm (GSM_StateMachine *s, GSM_Alarm *Alarm, unsigned char msgtype);
+GSM_Error DCT3_GetDateTime (GSM_StateMachine *s, GSM_DateTime *date_time, unsigned char msgtype );
+GSM_Error DCT3_SetAlarm (GSM_StateMachine *s, GSM_Alarm *Alarm, unsigned char msgtype);
+GSM_Error DCT3_SetDateTime (GSM_StateMachine *s, GSM_DateTime *date_time, unsigned char msgtype );
+GSM_Error DCT3_SetIncomingCB (GSM_StateMachine *s, gboolean enable );
+GSM_Error DCT3_GetSMSStatus (GSM_StateMachine *s, GSM_SMSMemoryStatus *status );
+GSM_Error DCT3_SetSMSC (GSM_StateMachine *s, GSM_SMSC *smsc );
+GSM_Error DCT3_GetWAPSettings (GSM_StateMachine *s, GSM_MultiWAPSettings *settings );
+GSM_Error DCT3_SetWAPSettings (GSM_StateMachine *s, GSM_MultiWAPSettings *settings);
+GSM_Error DCT3_SetWAPBookmark (GSM_StateMachine *s, GSM_WAPBookmark *bookmark);
+GSM_Error DCT3_Netmonitor (GSM_StateMachine *s, int testnumber, char *value );
+GSM_Error DCT3_GetManufactureMonth (GSM_StateMachine *s, char *value );
+GSM_Error DCT3_GetProductCode (GSM_StateMachine *s, char *value);
+GSM_Error DCT3_GetOriginalIMEI (GSM_StateMachine *s, char *value);
+GSM_Error DCT3_GetHardware (GSM_StateMachine *s, char *value);
+GSM_Error DCT3_GetPPM (GSM_StateMachine *s, char *value);
+GSM_Error N61_71_ResetPhoneSettings (GSM_StateMachine *s, GSM_ResetSettingsType Type);
+GSM_Error N71_92_GetBatteryCharge (GSM_StateMachine *s, GSM_BatteryCharge *bat);
+GSM_Error N71_92_GetSignalQuality (GSM_StateMachine *s, GSM_SignalQuality *sig);
+GSM_Error N71_92_GetPhoneSetting (GSM_StateMachine *s, int Request, int Setting);
+GSM_Error N71_92_GetDateTime (GSM_StateMachine *s, GSM_DateTime *date_time );
+GSM_Error N71_92_SetDateTime (GSM_StateMachine *s, GSM_DateTime *date_time );
+
+GSM_Error DCT3_DecodeSMSFrame (GSM_StateMachine *s, GSM_SMSMessage *SMS, unsigned char *buffer);
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct3/n0650.c b/libgammu/phone/nokia/dct3/n0650.c
new file mode 100644
index 0000000..4c1ee15
--- /dev/null
+++ b/libgammu/phone/nokia/dct3/n0650.c
@@ -0,0 +1,168 @@
+/* (c) 2004 by Marcin Wiacek */
+
+#include <string.h>
+#include <time.h>
+
+#include "../../../gsmcomon.h"
+#include "../../../gsmstate.h"
+#include "../nfunc.h"
+
+#ifdef GSM_ENABLE_NOKIA650
+
+static GSM_Reply_Function N650ReplyFunctions[] = {
+ {DCT3DCT4_ReplyGetModelFirmware,"\xD2",0x02,0x00,ID_GetModel },
+ {DCT3DCT4_ReplyGetModelFirmware,"\xD2",0x02,0x00,ID_GetFirmware },
+
+ {NULL, "\x00",0x00,0x00,ID_None }
+};
+
+GSM_Phone_Functions N650Phone = {
+ "0650",
+ N650ReplyFunctions,
+ NOTSUPPORTED, /* Install */
+ NONEFUNCTION, /* Initialise */
+ NONEFUNCTION, /* Terminate */
+ GSM_DispatchMessage,
+ NOTSUPPORTED, /* ShowStartInfo */
+ NOKIA_GetManufacturer,
+ DCT3DCT4_GetModel,
+ DCT3DCT4_GetFirmware,
+ NOTSUPPORTED, /* GetIMEI */
+ NOTSUPPORTED, /* GetOriginalIMEI */
+ NOTSUPPORTED, /* GetManufactureMonth */
+ NOTSUPPORTED, /* GetProductCode */
+ NOTSUPPORTED, /* GetHardware */
+ NOTSUPPORTED, /* GetPPM */
+ NOTSUPPORTED, /* GetSIMIMSI */
+ NOTSUPPORTED, /* GetDateTime */
+ NOTSUPPORTED, /* SetDateTime */
+ NOTSUPPORTED, /* GetAlarm */
+ NOTSUPPORTED, /* SetAlarm */
+ NOTSUPPORTED, /* GetLocale */
+ NOTSUPPORTED, /* SetLocale */
+ NOTSUPPORTED, /* PressKey */
+ NOTSUPPORTED, /* Reset */
+ NOTSUPPORTED, /* ResetPhoneSettings */
+ NOTSUPPORTED, /* EnterSecurityCode */
+ NOTSUPPORTED, /* GetSecurityStatus */
+ NOTSUPPORTED, /* GetDisplayStatus */
+ NOTSUPPORTED, /* SetAutoNetworkLogin */
+ NOTSUPPORTED, /* GetBatteryCharge */
+ NOTSUPPORTED, /* GetSignalQuality */
+ NOTSUPPORTED, /* GetNetworkInfo */
+ NOTSUPPORTED, /* GetCategory */
+ NOTSUPPORTED, /* AddCategory */
+ NOTSUPPORTED, /* GetCategoryStatus */
+ NOTSUPPORTED, /* GetMemoryStatus */
+ NOTSUPPORTED, /* GetMemory */
+ NOTSUPPORTED, /* GetNextMemory */
+ NOTSUPPORTED, /* SetMemory */
+ NOTSUPPORTED, /* AddMemory */
+ NOTSUPPORTED, /* DeleteMemory */
+ NOTIMPLEMENTED, /* DeleteAllMemory */
+ NOTSUPPORTED, /* GetSpeedDial */
+ NOTSUPPORTED, /* SetSpeedDial */
+ NOTSUPPORTED, /* GetSMSC */
+ NOTSUPPORTED, /* SetSMSC */
+ NOTSUPPORTED, /* GetSMSStatus */
+ NOTSUPPORTED, /* GetSMS */
+ NOTSUPPORTED, /* GetNextSMS */
+ NOTSUPPORTED, /* SetSMS */
+ NOTSUPPORTED, /* AddSMS */
+ NOTSUPPORTED, /* DeleteSMS */
+ NOTSUPPORTED, /* SendSMSMessage */
+ NOTSUPPORTED, /* SendSavedSMS */
+ NOTSUPPORTED, /* SetFastSMSSending */
+ NOTSUPPORTED, /* SetIncomingSMS */
+ NOTSUPPORTED, /* SetIncomingCB */
+ NOTSUPPORTED, /* GetSMSFolders */
+ NOTSUPPORTED, /* AddSMSFolder */
+ NOTSUPPORTED, /* DeleteSMSFolder */
+ NOTSUPPORTED, /* DialVoice */
+ NOTIMPLEMENTED, /* DialService */
+ NOTSUPPORTED, /* AnswerCall */
+ NOTSUPPORTED, /* CancelCall */
+ NOTSUPPORTED, /* HoldCall */
+ NOTSUPPORTED, /* UnholdCall */
+ NOTSUPPORTED, /* ConferenceCall */
+ NOTSUPPORTED, /* SplitCall */
+ NOTSUPPORTED, /* TransferCall */
+ NOTSUPPORTED, /* SwitchCall */
+ NOTSUPPORTED, /* GetCallDivert */
+ NOTSUPPORTED, /* SetCallDivert */
+ NOTSUPPORTED, /* CancelAllDiverts */
+ NOTSUPPORTED, /* SetIncomingCall */
+ NOTSUPPORTED, /* SetIncomingUSSD */
+ NOTSUPPORTED, /* SendDTMF */
+ NOTSUPPORTED, /* GetRingtone */
+ NOTSUPPORTED, /* SetRingtone */
+ NOTSUPPORTED, /* GetRingtonesInfo */
+ NOTSUPPORTED, /* DeleteUserRingtones */
+ NOTSUPPORTED, /* PlayTone */
+ NOTSUPPORTED, /* GetWAPBookmark */
+ NOTSUPPORTED, /* SetWAPBookmark */
+ NOTSUPPORTED, /* DeleteWAPBookmark */
+ NOTSUPPORTED, /* GetWAPSettings */
+ NOTSUPPORTED, /* SetWAPSettings */
+ NOTSUPPORTED, /* GetSyncMLSettings */
+ NOTSUPPORTED, /* SetSyncMLSettings */
+ NOTSUPPORTED, /* GetChatSettings */
+ NOTSUPPORTED, /* SetChatSettings */
+ NOTSUPPORTED, /* GetMMSSettings */
+ NOTSUPPORTED, /* SetMMSSettings */
+ NOTSUPPORTED, /* GetMMSFolders */
+ NOTSUPPORTED, /* GetNextMMSFileInfo */
+ NOTSUPPORTED, /* GetBitmap */
+ NOTSUPPORTED, /* SetBitmap */
+ NOTSUPPORTED, /* GetToDoStatus */
+ NOTSUPPORTED, /* GetToDo */
+ NOTSUPPORTED, /* GetNextToDo */
+ NOTSUPPORTED, /* SetToDo */
+ NOTSUPPORTED, /* AddToDo */
+ NOTSUPPORTED, /* DeleteToDo */
+ NOTSUPPORTED, /* DeleteAllToDo */
+ NOTSUPPORTED, /* GetCalendarStatus */
+ NOTSUPPORTED, /* GetCalendar */
+ NOTSUPPORTED, /* GetNextCalendar */
+ NOTSUPPORTED, /* SetCalendar */
+ NOTSUPPORTED, /* AddCalendar */
+ NOTSUPPORTED, /* DeleteCalendar */
+ NOTSUPPORTED, /* DeleteAllCalendar */
+ NOTSUPPORTED, /* GetCalendarSettings */
+ NOTSUPPORTED, /* SetCalendarSettings */
+ NOTSUPPORTED, /* GetNoteStatus */
+ NOTSUPPORTED, /* GetNote */
+ NOTSUPPORTED, /* GetNextNote */
+ NOTSUPPORTED, /* SetNote */
+ NOTSUPPORTED, /* AddNote */
+ NOTSUPPORTED, /* DeleteNote */
+ NOTSUPPORTED, /* DeleteAllNotes */
+ NOTSUPPORTED, /* GetProfile */
+ NOTSUPPORTED, /* SetProfile */
+ NOTSUPPORTED, /* GetFMStation */
+ NOTSUPPORTED, /* SetFMStation */
+ NOTSUPPORTED, /* ClearFMStations */
+ NOTSUPPORTED, /* GetNextFileFolder */
+ NOTSUPPORTED, /* GetFolderListing */
+ NOTSUPPORTED, /* GetNextRootFolder */
+ NOTSUPPORTED, /* SetFileAttributes */
+ NOTSUPPORTED, /* GetFilePart */
+ NOTSUPPORTED, /* AddFilePart */
+ NOTSUPPORTED, /* SendFilePart */
+ NOTSUPPORTED, /* GetFileSystemStatus */
+ NOTSUPPORTED, /* DeleteFile */
+ NOTSUPPORTED, /* AddFolder */
+ NOTSUPPORTED, /* DeleteFolder */
+ NOTSUPPORTED, /* GetGPRSAccessPoint */
+ NOTSUPPORTED, /* SetGPRSAccessPoint */
+ NOTSUPPORTED, /* GetScreenshot */
+ NOTSUPPORTED, /* SetPower */
+ NOTSUPPORTED, /* PostConnect */
+ NONEFUNCTION /* PreAPICall */
+};
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct3/n0650.h b/libgammu/phone/nokia/dct3/n0650.h
new file mode 100644
index 0000000..be491eb
--- /dev/null
+++ b/libgammu/phone/nokia/dct3/n0650.h
@@ -0,0 +1,18 @@
+/* (c) 2004 by Marcin Wiacek */
+
+#ifndef n650_h
+#define n650_h
+
+typedef struct {
+ int fake;
+} GSM_Phone_N650Data;
+
+#ifndef GSM_USED_MBUS2
+# define GSM_USED_MBUS2
+#endif
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct3/n6110.c b/libgammu/phone/nokia/dct3/n6110.c
new file mode 100644
index 0000000..f98b9e3
--- /dev/null
+++ b/libgammu/phone/nokia/dct3/n6110.c
@@ -0,0 +1,2947 @@
+/* (c) 2001-2004 by Marcin Wiacek */
+/* 5210 calendar IDs by Frederick Ros */
+/* based on some Markus Plail, Pavel Janik & others work from Gnokii (www.gnokii.org)
+ * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
+ * GNU GPL version 2 or later
+ */
+/* Due to a problem in the source code management, the names of some of
+ * the authors have unfortunately been lost. We do not mean to belittle
+ * their efforts and hope they will contact us to see their names
+ * properly added to the Copyright notice above.
+ * Having published their contributions under the terms of the GNU
+ * General Public License (GPL) [version 2], the Copyright of these
+ * authors will remain respected by adhering to the license they chose
+ * to publish their code under.
+ */
+
+#include <gammu-config.h>
+
+#ifdef GSM_ENABLE_NOKIA6110
+
+#include <string.h>
+
+#include <gammu-nokia.h>
+#include <gammu-config.h>
+
+#include "../../../misc/coding/coding.h"
+#include "../../../misc/locales.h"
+#include "../../../gsmcomon.h"
+#include "../../../service/gsmlogo.h"
+#include "../../../service/gsmring.h"
+#include "../../../service/gsmnet.h"
+#include "../../pfunc.h"
+#include "../nfunc.h"
+#include "n6110.h"
+#include "dct3func.h"
+
+static unsigned char N6110_MEMORY_TYPES[] = {
+ MEM_ME, 0x02,
+ MEM_SM, 0x03,
+ MEM_ON, 0x05,
+ MEM_DC, 0x07,
+ MEM_RC, 0x08,
+ MEM_MC, 0x09,
+ MEM_VM, 0x0b,
+ 0x00, 0x00
+};
+
+static GSM_Error N6110_ReplyGetPhoneLanguage(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ N6110_Language lang = N6110_Auto;
+
+ if (msg->Buffer[3] == 0x15) return ERR_NONE;
+
+ smprintf(s, "Phone language is %02x\n",msg->Buffer[6]);
+ switch (msg->Buffer[6]) {
+ case 0x21: lang = N6110_Europe; break; /* Polish */
+ }
+ s->Phone.Data.Priv.N6110.PhoneLanguage = lang;
+ return ERR_NONE;
+}
+
+static GSM_Error N6110_GetPhoneLanguage(GSM_StateMachine *s)
+{
+ unsigned char feat_req[] = {N6110_FRAME_HEADER, 0x13, 0x01,
+ 0x00, /* Profile location */
+ 0x00}; /* Feature number */
+
+ s->Phone.Data.Priv.N6110.PhoneLanguage = N6110_Auto;
+
+ feat_req[5] = 0;
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PROFILES33)) {
+ feat_req[6] = 0x1E;
+ } else {
+ feat_req[6] = 0x21;
+ }
+ smprintf(s, "Getting profile feature\n");
+ return GSM_WaitFor (s, feat_req, 7, 0x05, 4, ID_GetLanguage);
+}
+
+struct N6110_Lang_Char {
+ N6110_Language Lang;
+ unsigned char Phone;
+ unsigned char Unicode1;
+ unsigned char Unicode2;
+};
+
+static struct N6110_Lang_Char N6110_Lang_Table[] = {
+{N6110_Europe,0x13,0x01,0x04},/* Latin capital letter a with ogonek */
+{N6110_Europe,0x14,0x01,0x05},/* Latin small letter a with ogonek */
+{N6110_Europe,0x15,0x01,0x06},/* Latin capital letter c with acute */
+{N6110_Europe,0x17,0x01,0x07},/* Latin small letter c with acute */
+{N6110_Europe,0x1D,0x01,0x18},/* Latin capital letter e with ogonek */
+{N6110_Europe,0x1E,0x01,0x19},/* Latin small letter e with ogonek */
+{N6110_Europe,0x83,0x00,0xD3},/* Latin capital letter o with acute */
+{N6110_Europe,0x8E,0x01,0x41},/* Latin capital letter l with stroke */
+{N6110_Europe,0x90,0x01,0x42},/* Latin small letter l with stroke */
+{N6110_Europe,0x92,0x01,0x43},/* Latin capital letter n with acute */
+{N6110_Europe,0x93,0x01,0x44},/* Latin small letter n with acute */
+{N6110_Europe,0x9A,0x00,0xF3},/* Latin small letter o with acute */
+{N6110_Europe,0xB2,0x20,0xAC},/* euro */
+{N6110_Europe,0xB5,0x01,0x5A},/* Latin capital letter s with acute */
+{N6110_Europe,0xB6,0x01,0x5B},/* Latin small letter s with acute */
+{N6110_Europe,0xE7,0x01,0x79},/* Latin capital letter z with acute */
+{N6110_Europe,0xEE,0x01,0x7A},/* Latin small letter z with acute */
+{N6110_Europe,0xF4,0x01,0x7C},/* Latin small letter z with dot above */
+{N6110_Europe,0xF0,0x01,0x7B},/* Latin capital letter z with dot above */
+{0,0,0,0}
+};
+
+static void N6110_EncodeUnicode(GSM_StateMachine *s, unsigned char *dest, const unsigned char *src, int len)
+{
+ int i_len = 0, o_len, i;
+ gammu_char_t wc;
+ GSM_Phone_N6110Data *Priv = &s->Phone.Data.Priv.N6110;
+ gboolean found;
+
+ for (o_len = 0; i_len < len; o_len++) {
+ found = FALSE;
+ if (Priv->PhoneLanguage != N6110_Auto) {
+ i = 0;
+ while(1) {
+ if (N6110_Lang_Table[i].Lang == 0) break;
+ if (N6110_Lang_Table[i].Lang == Priv->PhoneLanguage &&
+ N6110_Lang_Table[i].Phone == src[i_len]) {
+ dest[o_len*2] = N6110_Lang_Table[i].Unicode1;
+ dest[(o_len*2)+1] = N6110_Lang_Table[i].Unicode2;
+ i_len++;
+ found = TRUE;
+ break;
+ }
+ i++;
+ }
+ }
+ if (!found) {
+ i_len += EncodeWithUnicodeAlphabet(&src[i_len], &wc);
+ dest[o_len*2] = (wc >> 8) & 0xff;
+ dest[(o_len*2)+1] = wc & 0xff;
+ }
+ }
+ dest[o_len*2] = 0;
+ dest[(o_len*2)+1] = 0;
+}
+
+
+/* Pavel Janik */
+/* This function provides Nokia authentication protocol.
+ * Nokia authentication protocol is used in the communication between Nokia
+ * mobile phones (e.g. Nokia 6110) and Nokia Cellular Data Suite software,
+ * commercially sold by Nokia Corp.
+ * The authentication scheme is based on the token send by the phone to the
+ * software. The software does it's magic (see the function
+ * N6110_GetNokiaAuthentication) and returns the result back to the phone.
+ * If the result is correct the phone responds with the message "Accessory
+ * connected!" displayed on the LCD. Otherwise it will display "Accessory not
+ * supported" and some functions will not be available for use (?).
+ * The specification of the protocol is not publicly available, no comment.
+ */
+static void N6110_GetNokiaAuthentication(unsigned char *Imei, unsigned char *MagicBytes, unsigned char *MagicResponse)
+{
+ int i, j, CRC=0;
+ unsigned char Temp[16]; /* This is our temporary working area. */
+
+ /* Here we put FAC (Final Assembly Code) and serial number into our area. */
+ Temp[0] = Imei[6]; Temp[1] = Imei[7];
+ Temp[2] = Imei[8]; Temp[3] = Imei[9];
+ Temp[4] = Imei[10]; Temp[5] = Imei[11];
+ Temp[6] = Imei[12]; Temp[7] = Imei[13];
+
+ /* And now the TAC (Type Approval Code). */
+ Temp[8] = Imei[2]; Temp[9] = Imei[3];
+ Temp[10] = Imei[4]; Temp[11] = Imei[5];
+
+ /* And now we pack magic bytes from the phone. */
+ Temp[12] = MagicBytes[0]; Temp[13] = MagicBytes[1];
+ Temp[14] = MagicBytes[2]; Temp[15] = MagicBytes[3];
+
+ for (i=0; i<=11; i++) if (Temp[i + 1]& 1) Temp[i]<<=1;
+ switch (Temp[15] & 0x03) {
+ case 1:
+ case 2: j = Temp[13] & 0x07;
+ for (i=0; i<=3; i++) Temp[i+j] ^= Temp[i+12];
+ break;
+ default: j = Temp[14] & 0x07;
+ for (i=0; i<=3; i++) Temp[i + j] |= Temp[i + 12];
+ }
+ for (i=0; i<=15; i++) CRC ^= Temp[i];
+ for (i=0; i<=15; i++) {
+ switch (Temp[15 - i] & 0x06) {
+ case 0: j = Temp[i] | CRC; break;
+ case 2:
+ case 4: j = Temp[i] ^ CRC; break;
+ case 6: j = Temp[i] & CRC; break;
+ }
+ if (j == CRC) j = 0x2c;
+ if (Temp[i] == 0) j = 0;
+ MagicResponse[i] = j;
+ }
+}
+
+static GSM_Error N6110_ReplyGetMagicBytes(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_N6110Data *Priv = &s->Phone.Data.Priv.N6110;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ sprintf(Data->IMEI, "%s", msg->Buffer+9);
+ sprintf(Data->HardwareCache, "%s", msg->Buffer+39);
+ sprintf(Data->ProductCodeCache, "%s", msg->Buffer+31);
+
+ smprintf(s, "Message: Mobile phone identification received:\n");
+ smprintf(s, "IMEI : %s\n", msg->Buffer+9);
+ smprintf(s, "Model : %s\n", msg->Buffer+25);
+ smprintf(s, "Production Code : %s\n", msg->Buffer+31);
+ smprintf(s, "HW : %s\n", msg->Buffer+39);
+ smprintf(s, "Firmware : %s\n", msg->Buffer+44);
+
+ /* These bytes are probably the source of the "Accessory not connected"
+ * messages on the phone when trying to emulate NCDS... I hope....
+ * UPDATE: of course, now we have the authentication algorithm.
+ */
+ smprintf(s, " Magic bytes : %02x %02x %02x %02x\n", msg->Buffer[50], msg->Buffer[51], msg->Buffer[52], msg->Buffer[53]);
+
+ Priv->MagicBytes[0]=msg->Buffer[50];
+ Priv->MagicBytes[1]=msg->Buffer[51];
+ Priv->MagicBytes[2]=msg->Buffer[52];
+ Priv->MagicBytes[3]=msg->Buffer[53];
+
+ return ERR_NONE;
+}
+
+static GSM_Error N6110_MakeAuthentication(GSM_StateMachine *s)
+{
+ GSM_Phone_N6110Data *Priv = &s->Phone.Data.Priv.N6110;
+ GSM_Error error;
+ unsigned char connect4[] = {N6110_FRAME_HEADER, 0x10};
+ unsigned char magic_connect[] = {
+ N6110_FRAME_HEADER, 0x12,
+ /* The real magic goes here ... These bytes are filled in
+ * with the function N6110_GetNokiaAuthentication. */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ /* NOKIA&GNOKII Accessory */
+ 'N', 'O', 'K', 'I', 'A', '&', 'N', 'O', 'K', 'I', 'A',
+ 'a', 'c', 'c', 'e', 's', 's', 'o', 'r', 'y',
+ 0x00, 0x00, 0x00, 0x00};
+
+ smprintf(s, "Getting magic bytes for authentication\n");
+ error=GSM_WaitFor (s, connect4, 4, 0x64, 4, ID_MakeAuthentication);
+ if (error!=ERR_NONE) return error;
+
+ N6110_GetNokiaAuthentication(s->Phone.Data.IMEI, Priv->MagicBytes, magic_connect+4);
+ smprintf(s, "Sending authentication bytes\n");
+ return s->Protocol.Functions->WriteMessage(s, magic_connect, 45, 0x64);
+}
+
+
+static GSM_Error N6110_ShowStartInfo(GSM_StateMachine *s, gboolean enable UNUSED)
+{
+ GSM_Error error=ERR_NONE;
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_MAGICBYTES)) {
+ if (s->ConnectionType == GCT_FBUS2 ||
+ s->ConnectionType == GCT_FBUS2IRDA) {
+ error=N6110_MakeAuthentication(s);
+ }
+ }
+ return error;
+}
+
+static GSM_Error N6110_Initialise (GSM_StateMachine *s)
+{
+#ifdef DEBUG
+ DCT3_SetIncomingCB(s,TRUE);
+#endif
+ N6110_GetPhoneLanguage(s);
+ return ERR_NONE;
+}
+
+static GSM_Error N6110_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
+{
+ return DCT3_GetDateTime(s, date_time, 0x11);
+}
+
+static GSM_Error N6110_GetAlarm(GSM_StateMachine *s, GSM_Alarm *Alarm)
+{
+ return DCT3_GetAlarm(s, Alarm, 0x11);
+}
+
+static GSM_Error N6110_SetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
+{
+ return DCT3_SetDateTime(s, date_time, 0x11);
+}
+
+static GSM_Error N6110_SetAlarm(GSM_StateMachine *s, GSM_Alarm *Alarm)
+{
+ return DCT3_SetAlarm(s, Alarm, 0x11);
+}
+
+static GSM_Error N6110_ReplyGetMemory(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int count;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "Phonebook entry received\n");
+ switch (msg->Buffer[3]) {
+ case 0x02:
+ Data->Memory->EntriesNum = 0;
+ count=5;
+ /* If name is not empty */
+ if (msg->Buffer[count]!=0x00) {
+ if (msg->Buffer[count]>GSM_PHONEBOOK_TEXT_LENGTH) {
+ smprintf(s, "Too long text\n");
+ return ERR_UNKNOWNRESPONSE;
+ }
+ Data->Memory->Entries[Data->Memory->EntriesNum].EntryType=PBK_Text_Name;
+ Data->Memory->Entries[Data->Memory->EntriesNum].Location = PBK_Location_Unknown;
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOPBKUNICODE)) {
+ if (Data->Memory->MemoryType==MEM_DC ||
+ Data->Memory->MemoryType==MEM_RC ||
+ Data->Memory->MemoryType==MEM_MC ||
+ Data->Memory->MemoryType==MEM_ME) {
+ N6110_EncodeUnicode(s,Data->Memory->Entries[Data->Memory->EntriesNum].Text,
+ msg->Buffer+count+1,msg->Buffer[count]);
+ } else {
+ EncodeUnicode(Data->Memory->Entries[Data->Memory->EntriesNum].Text,
+ msg->Buffer+count+1,msg->Buffer[count]);
+ }
+ } else {
+ memcpy(Data->Memory->Entries[Data->Memory->EntriesNum].Text,
+ msg->Buffer+count+1,msg->Buffer[count]);
+ Data->Memory->Entries[Data->Memory->EntriesNum].Text[msg->Buffer[count]]=0x00;
+ Data->Memory->Entries[Data->Memory->EntriesNum].Text[msg->Buffer[count]+1]=0x00;
+ }
+ smprintf(s, "Name \"%s\"\n",
+ DecodeUnicodeString(Data->Memory->Entries[Data->Memory->EntriesNum].Text));
+ Data->Memory->EntriesNum++;
+ }
+ count=count+msg->Buffer[count]+1;
+
+ /* If number is empty */
+ if (msg->Buffer[count]==0x00) return ERR_EMPTY;
+
+ if (msg->Buffer[count]>GSM_PHONEBOOK_TEXT_LENGTH) {
+ smprintf(s, "Too long text\n");
+ return ERR_UNKNOWNRESPONSE;
+ }
+ Data->Memory->Entries[Data->Memory->EntriesNum].EntryType = PBK_Number_General;
+ Data->Memory->Entries[Data->Memory->EntriesNum].Location = PBK_Location_Unknown;
+ Data->Memory->Entries[Data->Memory->EntriesNum].VoiceTag = 0;
+ Data->Memory->Entries[Data->Memory->EntriesNum].SMSList[0] = 0;
+ EncodeUnicode(Data->Memory->Entries[Data->Memory->EntriesNum].Text,
+ msg->Buffer+count+1,msg->Buffer[count]);
+ smprintf(s, "Number \"%s\"\n",
+ DecodeUnicodeString(Data->Memory->Entries[Data->Memory->EntriesNum].Text));
+ Data->Memory->EntriesNum++;
+ count=count+msg->Buffer[count]+1;
+
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOCALLER)) {
+ if (msg->Buffer[count]<5) {
+ Data->Memory->Entries[Data->Memory->EntriesNum].EntryType=PBK_Caller_Group;
+ Data->Memory->Entries[Data->Memory->EntriesNum].Location = PBK_Location_Unknown;
+ smprintf(s, "Caller group \"%i\"\n",msg->Buffer[count]);
+ Data->Memory->Entries[Data->Memory->EntriesNum].Number=msg->Buffer[count]+1;
+ Data->Memory->EntriesNum++;
+ }
+ }
+ count++;
+
+ if (Data->Memory->MemoryType==MEM_DC ||
+ Data->Memory->MemoryType==MEM_RC ||
+ Data->Memory->MemoryType==MEM_MC) {
+ NOKIA_DecodeDateTime(s, msg->Buffer+count+1,&Data->Memory->Entries[Data->Memory->EntriesNum].Date, TRUE, FALSE);
+ Data->Memory->Entries[Data->Memory->EntriesNum].EntryType=PBK_Date;
+ Data->Memory->Entries[Data->Memory->EntriesNum].Location = PBK_Location_Unknown;
+
+ /* These values are set, when date and time unavailable in phone.
+ * Values from 3310 - in other can be different */
+ if (Data->Memory->Entries[2].Date.Day !=20 ||
+ Data->Memory->Entries[2].Date.Month !=1 ||
+ Data->Memory->Entries[2].Date.Year !=2118||
+ Data->Memory->Entries[2].Date.Hour !=3 ||
+ Data->Memory->Entries[2].Date.Minute!=14 ||
+ Data->Memory->Entries[2].Date.Second!=7)
+ Data->Memory->EntriesNum++;
+ }
+
+ return ERR_NONE;
+ default:
+ switch (msg->Buffer[4]) {
+ case 0x6f:
+ smprintf(s, "Phone is OFF\n");
+ return ERR_PHONEOFF;
+ case 0x74:
+ /* TODO: check if not too high */
+ smprintf(s, "ERROR: Empty ????\n");
+ Data->Memory->EntriesNum = 0;
+ return ERR_EMPTY;
+ case 0x7d:
+ smprintf(s, "ERROR: Invalid memory type\n");
+ return ERR_NOTSUPPORTED;
+ case 0x8d:
+ smprintf(s, "ERROR: no PIN\n");
+ return ERR_SECURITYERROR;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ }
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6110_GetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x01,
+ 0x00, /* memory type */
+ 0x00, /* location */
+ 0x00};
+
+ if (entry->Location > 255) return ERR_INVALIDLOCATION;
+
+ req[4] = NOKIA_GetMemoryType(s, entry->MemoryType,N6110_MEMORY_TYPES);
+ if (req[4]==0xff) return ERR_NOTSUPPORTED;
+
+ req[5] = entry->Location;
+ if (entry->MemoryType==MEM_DC || entry->MemoryType==MEM_RC || entry->MemoryType==MEM_MC) req[5]--;
+
+ s->Phone.Data.Memory=entry;
+ smprintf(s, "Getting phonebook entry\n");
+ return GSM_WaitFor (s, req, 7, 0x03, 4, ID_GetMemory);
+}
+
+static GSM_Error N6110_ReplyGetMemoryStatus(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "Memory status received\n");
+ switch (msg->Buffer[3]) {
+ case 0x08:
+ smprintf(s, "Memory type: %i\n",msg->Buffer[4]);
+
+ smprintf(s, "Free : %i\n",msg->Buffer[5]);
+ Data->MemoryStatus->MemoryFree=msg->Buffer[5];
+
+ smprintf(s, "Used : %i\n",msg->Buffer[6]);
+ Data->MemoryStatus->MemoryUsed=msg->Buffer[6];
+
+ return ERR_NONE;
+ case 0x09:
+ switch (msg->Buffer[4]) {
+ case 0x6f:
+ smprintf(s, "Phone is probably powered off.\n");
+ return ERR_TIMEOUT;
+ case 0x7d:
+ smprintf(s, "Memory type not supported by phone model.\n");
+ return ERR_NOTSUPPORTED;
+ case 0x8d:
+ smprintf(s, "Waiting for security code.\n");
+ return ERR_SECURITYERROR;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ default:
+ return ERR_UNKNOWNRESPONSE;
+ }
+}
+
+static GSM_Error N6110_GetMemoryStatus(GSM_StateMachine *s, GSM_MemoryStatus *Status)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x07,
+ 0x00}; /* memory type */
+
+ req[4] = NOKIA_GetMemoryType(s, Status->MemoryType,N6110_MEMORY_TYPES);
+ if (req[4]==0xff) return ERR_NOTSUPPORTED;
+
+ s->Phone.Data.MemoryStatus=Status;
+ smprintf(s, "Getting memory status\n");
+ return GSM_WaitFor (s, req, 5, 0x03, 4, ID_GetMemoryStatus);
+}
+
+static GSM_Error N6110_ReplyGetSMSStatus(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "SMS status received\n");
+ switch (msg->Buffer[3]) {
+ case 0x37:
+ smprintf(s, "SIM size : %i\n",msg->Buffer[7]);
+ smprintf(s, "Used in SIM : %i\n",msg->Buffer[10]);
+ smprintf(s, "Unread in SIM : %i\n",msg->Buffer[11]);
+ Data->SMSStatus->SIMUsed = msg->Buffer[10];
+ Data->SMSStatus->SIMUnRead = msg->Buffer[11];
+ Data->SMSStatus->SIMSize = msg->Buffer[7];
+ Data->SMSStatus->PhoneUsed = 0;
+ Data->SMSStatus->PhoneUnRead = 0;
+ Data->SMSStatus->PhoneSize = 0;
+ Data->SMSStatus->TemplatesUsed = 0;
+ return ERR_NONE;
+ case 0x38:
+ smprintf(s, "Error. No PIN ?\n");
+ return ERR_SECURITYERROR;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+GSM_Error N6110_ReplyGetSMSMessage(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "SMS Message received\n");
+ switch(msg->Buffer[3]) {
+ case 0x08:
+ GSM_SetDefaultReceivedSMSData(&(Data->GetSMSMessage->SMS[0]));
+ Data->GetSMSMessage->Number = 1;
+ Data->GetSMSMessage->SMS[0].Name[0] = 0;
+ Data->GetSMSMessage->SMS[0].Name[1] = 0;
+ Data->GetSMSMessage->SMS[0].Memory = MEM_SM;
+ NOKIA_DecodeSMSState(s, msg->Buffer[4], &Data->GetSMSMessage->SMS[0]);
+ switch (msg->Buffer[7]) {
+ case 0x00: case 0x01: /* Report or SMS_Deliver */
+ Data->GetSMSMessage->SMS[0].Folder = 0x01;
+ Data->GetSMSMessage->SMS[0].InboxFolder = TRUE;
+ break;
+ case 0x02: /* SMS_Submit */
+ Data->GetSMSMessage->SMS[0].Folder = 0x02;
+ Data->GetSMSMessage->SMS[0].InboxFolder = FALSE;
+ break;
+ default:
+ return ERR_UNKNOWNRESPONSE;
+ }
+ return DCT3_DecodeSMSFrame(s, &Data->GetSMSMessage->SMS[0],msg->Buffer+8);
+ case 0x09:
+ switch (msg->Buffer[4]) {
+ case 0x00:
+ smprintf(s, "Unknown. Probably phone too busy\n");
+ return ERR_UNKNOWN;
+ case 0x02:
+ smprintf(s, "Too high location ?\n");
+ return ERR_INVALIDLOCATION;
+ case 0x06:
+ smprintf(s, "Phone is OFF\n");
+ return ERR_PHONEOFF;
+ case 0x07:
+ smprintf(s, "Empty\n");
+ return ERR_EMPTY;
+ case 0x0c:
+ smprintf(s, "Access error. No PIN ?\n");
+ return ERR_SECURITYERROR;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ }
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6110_GetSMSMessage(GSM_StateMachine *s, GSM_MultiSMSMessage *sms)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x07, 0x02,
+ 0x00, /* Location */
+ 0x01, 0x64};
+
+ if (sms->SMS[0].Folder!=0x00) return ERR_NOTSUPPORTED;
+
+ req[5] = sms->SMS[0].Location;
+
+ s->Phone.Data.GetSMSMessage=sms;
+ smprintf(s, "Getting sms\n");
+ return GSM_WaitFor (s, req, 8, 0x02, 4, ID_GetSMSMessage);
+}
+
+static GSM_Error N6110_GetNextSMSMessage(GSM_StateMachine *s, GSM_MultiSMSMessage *sms, gboolean start)
+{
+ GSM_Phone_N6110Data *Priv = &s->Phone.Data.Priv.N6110;
+ GSM_Error error;
+
+ if (start) {
+ error=s->Phone.Functions->GetSMSStatus(s,&Priv->LastSMSStatus);
+ if (error!=ERR_NONE) return error;
+ Priv->LastSMSRead=0;
+ sms->SMS[0].Location=0;
+ }
+ while (TRUE) {
+ sms->SMS[0].Location++;
+ if (Priv->LastSMSRead>=(Priv->LastSMSStatus.SIMUsed+Priv->LastSMSStatus.PhoneUsed+Priv->LastSMSStatus.TemplatesUsed)) return ERR_EMPTY;
+ error=s->Phone.Functions->GetSMS(s, sms);
+ if (error==ERR_NONE) {
+ Priv->LastSMSRead++;
+ break;
+ }
+ if (error != ERR_EMPTY) return error;
+ }
+ return error;
+}
+
+static GSM_Error N6110_ReplyGetStatus(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+#ifdef DEBUG
+ smprintf(s, "Phone status received :\n");
+ smprintf(s, "Mode : ");
+ switch (msg->Buffer[4]) {
+ case 0x01: smprintf(s, "registered within the network\n"); break;
+ case 0x02: smprintf(s, "call in progress\n"); break; /* ringing or already answered call */
+ case 0x03: smprintf(s, "waiting for security code\n"); break;
+ case 0x04: smprintf(s, "powered off\n"); break;
+ default : smprintf(s, "unknown\n");
+ }
+ smprintf(s, "Power source : ");
+ switch (msg->Buffer[7]) {
+ case 0x01: smprintf(s, "AC/DC\n"); break;
+ case 0x02: smprintf(s, "battery\n"); break;
+ default : smprintf(s, "unknown\n");
+ }
+ smprintf(s, "Battery Level : %d\n", msg->Buffer[8]);
+ smprintf(s, "Signal strength : %d\n", msg->Buffer[5]);
+#endif
+
+ switch (Data->RequestID) {
+ case ID_GetBatteryCharge:
+ Data->BatteryCharge->BatteryPercent = ((int)msg->Buffer[8])*25;
+ switch (msg->Buffer[7]) {
+ case 0x01: Data->BatteryCharge->ChargeState = GSM_BatteryConnected; break;
+ case 0x02: Data->BatteryCharge->ChargeState = GSM_BatteryPowered; break;
+ default : Data->BatteryCharge->ChargeState = 0;
+ }
+ return ERR_NONE;
+ case ID_GetSignalQuality:
+ Data->SignalQuality->SignalPercent = ((int)msg->Buffer[5])*25;
+ return ERR_NONE;
+ default:
+ return ERR_UNKNOWNRESPONSE;
+ }
+}
+
+static GSM_Error N6110_GetStatus(GSM_StateMachine *s, int ID)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x01};
+
+ return GSM_WaitFor (s, req, 4, 0x04, 4, ID);
+}
+
+static GSM_Error N6110_GetSignalQuality(GSM_StateMachine *s, GSM_SignalQuality *sig)
+{
+ char value[100];
+ GSM_Error error;
+
+ sig->BitErrorRate = -1;
+ sig->SignalStrength = -1; /* TODO for netmon */
+
+ smprintf(s, "Getting network level\n");
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_POWER_BATT)) {
+ error = DCT3_Netmonitor(s, 1, value);
+ if (error!=ERR_NONE) return error;
+ sig->SignalPercent = 100;
+ if (value[4]!='-') {
+ if (value[5]=='9' && value[6]>'4') sig->SignalPercent = 25;
+ if (value[5]=='9' && value[6]<'5') sig->SignalPercent = 50;
+ if (value[5]=='8' && value[6]>'4') sig->SignalPercent = 75;
+ } else sig->SignalPercent = 0;
+ return ERR_NONE;
+ } else {
+ s->Phone.Data.SignalQuality = sig;
+ return N6110_GetStatus(s, ID_GetSignalQuality);
+ }
+}
+
+static GSM_Error N6110_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat)
+{
+ char value[100];
+ GSM_Error error;
+
+ smprintf(s, "Getting battery level\n");
+ GSM_ClearBatteryCharge(bat);
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_POWER_BATT)) {
+ error = DCT3_Netmonitor(s, 23, value);
+ if (error!=ERR_NONE) return error;
+ bat->BatteryPercent = 100;
+ bat->ChargeState = 0;
+ if (value[29]=='7') bat->BatteryPercent = 75;
+ if (value[29]=='5') bat->BatteryPercent = 50;
+ if (value[29]=='2') bat->BatteryPercent = 25;
+ return ERR_NONE;
+ } else {
+ s->Phone.Data.BatteryCharge = bat;
+ return N6110_GetStatus(s, ID_GetBatteryCharge);
+ }
+}
+
+static GSM_Error N6110_ReplySaveSMSMessage(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "SMS message saving status\n");
+ switch (msg->Buffer[3]) {
+ case 0x05:
+ smprintf(s, "Saved at location %i\n",msg->Buffer[5]);
+ Data->SaveSMSMessage->Location=msg->Buffer[5];
+ return ERR_NONE;
+ case 0x06:
+ switch (msg->Buffer[4]) {
+ case 0x02:
+ smprintf(s, "All locations busy\n");
+ return ERR_FULL;
+ case 0x03:
+ smprintf(s, "Too high ?\n");
+ return ERR_INVALIDLOCATION;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ }
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6110_PrivSetSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms)
+{
+ int length;
+ GSM_Error error;
+ unsigned char req[256] = {N6110_FRAME_HEADER, 0x04,
+ 0x00, /* SMS status */
+ 0x02,
+ 0x00, /* SMS location */
+ 0x02}; /* SMS type */
+
+ req[6] = sms->Location;
+ if (sms->Folder==1) { /* Inbox */
+ req[4] = 1; /* SMS status - GSM_Read */
+ req[7] = 0x00; /* SMS type */
+ sms->PDU = SMS_Deliver;
+ error=PHONE_EncodeSMSFrame(s,sms,req+8,PHONE_SMSDeliver,&length,TRUE);
+ } else { /* Outbox */
+ req[4] = 5; /* SMS status - GSM_Sent */
+ req[7] = 0x02; /* SMS type */
+ sms->PDU = SMS_Submit;
+ error=PHONE_EncodeSMSFrame(s,sms,req+8,PHONE_SMSSubmit,&length,TRUE);
+ }
+ if (error != ERR_NONE) return error;
+
+ /* SMS State - GSM_Read -> GSM_Unread and GSM_Sent -> GSM_UnSent */
+ if (sms->State == SMS_UnSent || sms->State == SMS_UnRead) req[4] |= 0x02;
+
+ sms->Memory = MEM_SM;
+
+ s->Phone.Data.SaveSMSMessage=sms;
+ smprintf(s, "Saving sms\n");
+ return GSM_WaitFor (s, req, 8+length, 0x14, 4, ID_SaveSMSMessage);
+}
+
+static GSM_Error N6110_SetSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
+{
+ if (sms->Location == 0) return ERR_INVALIDLOCATION;
+ return N6110_PrivSetSMSMessage(s, sms);
+}
+
+static GSM_Error N6110_AddSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
+{
+ sms->Location = 0;
+ return N6110_PrivSetSMSMessage(s, sms);
+}
+
+static GSM_Error N6110_ReplySetRingtone(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x37:
+ smprintf(s, "Ringtone set OK\n");
+ return ERR_NONE;
+ case 0x38:
+ smprintf(s, "Error setting ringtone\n");
+ switch (msg->Buffer[4]) {
+ case 0x7d:
+ smprintf(s, "Too high location ?\n");
+ return ERR_INVALIDLOCATION;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ }
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6110_ReplySetBinRingtone(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[4]) {
+ case 0x00:
+ smprintf(s, "Set at location %i\n",msg->Buffer[3]+1);
+ return ERR_NONE;
+ default:
+ smprintf(s, "Invalid location. Too high ?\n");
+ return ERR_INVALIDLOCATION;
+ }
+}
+
+static GSM_Error N6110_SetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength)
+{
+ GSM_NetworkInfo NetInfo;
+ GSM_Error error;
+ size_t size=200,current=8;
+ GSM_UDHHeader UDHHeader;
+ unsigned char req[1000] = {N6110_FRAME_HEADER, 0x36,
+ 0x00, /* Location */
+ 0x00,0x78};
+ unsigned char reqBin[1000] = {0x00,0x01,0xa0,0x00,0x00,0x0c,0x01,0x2c};
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NORING)) return ERR_NOTSUPPORTED;
+ if (Ringtone->Location == 0) return ERR_INVALIDLOCATION;
+
+ switch (Ringtone->Format) {
+ case RING_NOTETONE:
+ if (Ringtone->Location==255) {
+ /* Only 6110, 6130 and 6150 support it */
+ if (strcmp(s->Phone.Data.Model,"NSE-3") == 0 || strcmp(s->Phone.Data.Model,"NSK-3") == 0 ||
+ strcmp(s->Phone.Data.Model,"NSM-1") == 0) {
+ req[0] = 0x0c;
+ req[1] = 0x01;
+ UDHHeader.Type = UDH_NokiaRingtone;
+ GSM_EncodeUDHHeader(&(s->di), &UDHHeader);
+ /* We copy UDH now */
+ memcpy(req+2,UDHHeader.Text,UDHHeader.Length);
+ *maxlength=GSM_EncodeNokiaRTTLRingtone(Ringtone, req+2+UDHHeader.Length, &size);
+ error = s->Protocol.Functions->WriteMessage(s, req, 2+UDHHeader.Length+size, 0x12);
+ if (error!=ERR_NONE) return error;
+ sleep(1);
+ /* We have to make something (not important, what) now */
+ /* no answer from phone*/
+ return DCT3_GetNetworkInfo(s,&NetInfo);
+ } else {
+ return ERR_NOTSUPPORTED;
+ }
+ }
+ *maxlength=GSM_EncodeNokiaRTTLRingtone(Ringtone, req+7, &size);
+ req[4] = Ringtone->Location - 1;
+ smprintf(s, "Setting ringtone\n");
+ return GSM_WaitFor (s, req, 7 + size, 0x05, 4, ID_SetRingtone);
+ case RING_NOKIABINARY:
+ error=DCT3_EnableSecurity (s, 0x01);
+ if (error!=ERR_NONE) return error;
+ memcpy(reqBin+current,DecodeUnicodeString(Ringtone->Name),UnicodeLength(Ringtone->Name));
+ current += UnicodeLength(Ringtone->Name);
+ reqBin[current++] = 0x00;
+ reqBin[current++] = 0x00;
+ reqBin[current++] = 0x00;/*xxx*/
+ memcpy(reqBin+current,Ringtone->NokiaBinary.Frame,Ringtone->NokiaBinary.Length);
+ current=current+Ringtone->NokiaBinary.Length;
+ reqBin[3]=Ringtone->Location-1;
+ if (!strcmp(s->Phone.Data.ModelInfo->model,"3210")) reqBin[5]=0x10;
+ smprintf(s, "Setting binary ringtone\n");
+ return GSM_WaitFor (s, reqBin, current, 0x40, 4, ID_SetRingtone);
+ case RING_MIDI:
+ case RING_MMF:
+ return ERR_NOTSUPPORTED;
+ }
+ return ERR_NOTSUPPORTED;
+}
+
+static GSM_Error N6110_ReplyGetOpLogo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int count=5;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "Operator logo received\n");
+ NOKIA_DecodeNetworkCode(msg->Buffer+count,Data->Bitmap->NetworkCode);
+ count = count + 3;
+ smprintf(s, "Network code : %s\n", Data->Bitmap->NetworkCode);
+ smprintf(s, "Network name for Gammu : %s ",
+ DecodeUnicodeString(GSM_GetNetworkName(Data->Bitmap->NetworkCode)));
+ smprintf(s, "(%s)\n",DecodeUnicodeString(GSM_GetCountryName(Data->Bitmap->NetworkCode)));
+
+ count = count + 3; /* We ignore size */
+ Data->Bitmap->BitmapWidth = msg->Buffer[count++];
+ Data->Bitmap->BitmapHeight = msg->Buffer[count++];
+ count++;
+ PHONE_DecodeBitmap(GSM_NokiaOperatorLogo,msg->Buffer+count,Data->Bitmap);
+ return ERR_NONE;
+}
+
+static GSM_Error N6110_ReplyGetStartup(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int i, count = 5;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "Startup logo & notes received\n");
+ for (i=0;i<msg->Buffer[4];i++) {
+ switch (msg->Buffer[count++]) {
+ case 0x01:
+ smprintf(s, "Startup logo\n");
+ if (Data->Bitmap->Type == GSM_StartupLogo) {
+ Data->Bitmap->BitmapHeight = msg->Buffer[count++];
+ Data->Bitmap->BitmapWidth = msg->Buffer[count++];
+ PHONE_DecodeBitmap(GSM_NokiaStartupLogo, msg->Buffer + count, Data->Bitmap);
+ } else {
+ count = count + 2;
+ }
+ count = count + PHONE_GetBitmapSize(GSM_NokiaStartupLogo,0,0);
+ break;
+ case 0x02:
+ smprintf(s, "Welcome note\n");
+ if (Data->Bitmap->Type == GSM_WelcomeNote_Text) {
+ EncodeUnicode(Data->Bitmap->Text,msg->Buffer+count, msg->Buffer[count]);
+ smprintf(s, "Text is \"%s\"\n",Data->Bitmap->Text);
+ }
+ count = count + msg->Buffer[count] + 1;
+ break;
+ case 0x03:
+ smprintf(s, "Dealer welcome note\n");
+ if (Data->Bitmap->Type == GSM_DealerNote_Text) {
+ EncodeUnicode(Data->Bitmap->Text,msg->Buffer+count, msg->Buffer[count]);
+ smprintf(s, "Text is \"%s\"\n",Data->Bitmap->Text);
+ }
+ count = count + msg->Buffer[count] + 1;
+ break;
+ default:
+ smprintf(s, "Unknown block\n");
+ return ERR_UNKNOWNRESPONSE;
+ }
+ }
+ return ERR_NONE;
+}
+
+static GSM_Error N6110_ReplyGetCallerLogo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int count;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ switch (msg->Buffer[3]) {
+ case 0x11:
+ smprintf(s, "Caller group info received\n");
+ EncodeUnicode(Data->Bitmap->Text,msg->Buffer+6,msg->Buffer[5]);
+ smprintf(s, "Name : \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Text));
+ Data->Bitmap->DefaultName = FALSE;
+ if (msg->Buffer[5] == 0x00) Data->Bitmap->DefaultName = TRUE;
+ count = msg->Buffer[5] + 6;
+ Data->Bitmap->RingtoneID = msg->Buffer[count++];
+ Data->Bitmap->DefaultRingtone = FALSE;
+ Data->Bitmap->FileSystemPicture = FALSE;
+ Data->Bitmap->FileSystemRingtone = FALSE;
+ if (Data->Bitmap->RingtoneID == 16) Data->Bitmap->DefaultRingtone = TRUE;
+ smprintf(s, "Ringtone ID: %02x\n",Data->Bitmap->RingtoneID);
+ Data->Bitmap->BitmapEnabled=(msg->Buffer[count++]==1);
+#ifdef DEBUG
+ smprintf(s, "Caller group logo ");
+ if (Data->Bitmap->BitmapEnabled) {
+ smprintf(s, "enabled\n");
+ } else {
+ smprintf(s, "disabled\n");
+ }
+#endif
+ count = count + 3; /* We ignore size */
+ Data->Bitmap->BitmapWidth = msg->Buffer[count++];
+ Data->Bitmap->BitmapHeight = msg->Buffer[count++];
+ count++;
+ PHONE_DecodeBitmap(GSM_NokiaCallerLogo,msg->Buffer+count,Data->Bitmap);
+ Data->Bitmap->DefaultBitmap = FALSE;
+ return ERR_NONE;
+ case 0x12:
+ smprintf(s, "Error getting caller group info\n");
+ return ERR_INVALIDLOCATION;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6110_ReplyGetSetPicture(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int count = 5, i;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+ GSM_Error error;
+ size_t pos;
+
+ switch (msg->Buffer[3]) {
+ case 0x02:
+ smprintf(s, "Picture Image received\n");
+ if (msg->Buffer[count]!=0) {
+ pos = 5;
+ error = GSM_UnpackSemiOctetNumber(&(s->di), Data->Bitmap->Sender, msg->Buffer, &pos, msg->Length, TRUE);
+ if (error != ERR_NONE) {
+ return error;
+ }
+ /* Convert number of semioctets to number of chars */
+ i = msg->Buffer[5];
+ if (i % 2) i++;
+ i=i / 2 + 1;
+ count = count + i + 1;
+ } else {
+ Data->Bitmap->Sender[0] = 0x00;
+ Data->Bitmap->Sender[1] = 0x00;
+ count+=2;
+ }
+ smprintf(s, "Sender : \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Sender));
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOPICTUREUNI) ||
+ (!strcmp(Data->Model,"NHM-5") && Data->VerNum < 5.79)) {
+ count++;
+ EncodeUnicode(Data->Bitmap->Text,msg->Buffer+count+1,msg->Buffer[count]);
+ count += UnicodeLength(Data->Bitmap->Text) + 1;
+ } else {
+ if (!strcmp(Data->Model,"NHM-5")) {
+ i = msg->Buffer[count] * 256 + msg->Buffer[count+1];
+ } else {
+ /* 3410 4.26 */
+ i = msg->Buffer[count] * 256 + msg->Buffer[count+1] - 2;
+ count += 2;
+ }
+ memcpy(Data->Bitmap->Text,msg->Buffer+count+2,i);
+ Data->Bitmap->Text[i] = 0;
+ Data->Bitmap->Text[i+1] = 0;
+ count += i + 2;
+ }
+ smprintf(s, "Text : \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Text));
+ Data->Bitmap->BitmapWidth = msg->Buffer[count++];
+ Data->Bitmap->BitmapHeight = msg->Buffer[count++];
+ PHONE_DecodeBitmap(GSM_NokiaPictureImage, msg->Buffer + count + 2, Data->Bitmap);
+#ifdef DEBUG
+ if (GSM_global_debug.dl == DL_TEXTALL || GSM_global_debug.dl == DL_TEXTALLDATE)
+ GSM_PrintBitmap(GSM_global_debug.df,Data->Bitmap);
+#endif
+ return ERR_NONE;
+ case 0x04:
+ smprintf(s, "Picture Image set OK\n");
+ return ERR_NONE;
+ case 0x05:
+ smprintf(s, "Can't set Picture Image - invalid location ?\n");
+ return ERR_INVALIDLOCATION;
+ case 0x06:
+ smprintf(s, "Can't get Picture Image - invalid location ?\n");
+ return ERR_INVALIDLOCATION;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6110_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
+{
+ GSM_Error error;
+ unsigned char req[10] = {N6110_FRAME_HEADER};
+
+ s->Phone.Data.Bitmap=Bitmap;
+ switch (Bitmap->Type) {
+ case GSM_StartupLogo:
+ case GSM_WelcomeNote_Text:
+ case GSM_DealerNote_Text:
+ if (Bitmap->Type == GSM_StartupLogo && GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NOSTARTUP)) return ERR_NOTSUPPORTED;
+ req[3] = 0x16;
+ return GSM_WaitFor (s, req, 4, 0x05, 4, ID_GetBitmap);
+ case GSM_CallerGroupLogo:
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NOCALLER)) return ERR_NOTSUPPORTED;
+ req[3] = 0x10;
+ req[4] = Bitmap->Location - 1;
+ error = GSM_WaitFor (s, req, 5, 0x03, 4, ID_GetBitmap);
+ if (error==ERR_NONE) NOKIA_GetDefaultCallerGroupName(Bitmap);
+ return error;
+ case GSM_OperatorLogo:
+ req[3] = 0x33;
+ req[4] = 0x01;
+ return GSM_WaitFor (s, req, 5, 0x05, 4, ID_GetBitmap);
+ case GSM_PictureImage:
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NOPICTURE)) return ERR_NOTSUPPORTED;
+ req[3] = 0x01;
+ req[4] = Bitmap->Location - 1;
+ return GSM_WaitFor (s, req, 5, 0x47, 4, ID_GetBitmap);
+ default:
+ break;
+ }
+ return ERR_NOTSUPPORTED;
+}
+
+static GSM_Error N6110_ReplySetProfileFeature(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x11:
+ smprintf(s, "Feature of profile set\n");
+ return ERR_NONE;
+ case 0x12:
+ smprintf(s, "Error setting profile feature\n");
+ return ERR_NOTSUPPORTED;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6110_SetProfileFeature(GSM_StateMachine *s, unsigned char profile, unsigned char feature, unsigned char value)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x10, 0x01,
+ 0x00, /* Profile */
+ 0x00, /* Feature */
+ 0x00}; /* Value */
+
+ req[5]=profile;
+ req[6]=feature;
+ req[7]=value;
+ smprintf(s, "Setting profile feature\n");
+ return GSM_WaitFor (s, req, 8, 0x05, 4, ID_SetProfile);
+}
+
+static GSM_Error N6110_ReplySetStartup(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Startup logo set OK\n");
+ return ERR_NONE;
+}
+
+static GSM_Error N6110_ReplySetCallerLogo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x14:
+ smprintf(s, "Caller group set OK\n");
+ return ERR_NONE;
+ case 0x15:
+ smprintf(s, "Error setting caller group\n");
+ return ERR_INVALIDLOCATION;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6110_SetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
+{
+ unsigned char reqPreview[1000] = {0x0c,0x01};
+ unsigned char req[600] = {N6110_FRAME_HEADER};
+ GSM_UDH UDHType = UDH_NokiaOperatorLogo;
+ size_t count = 0, textlen, Width, Height;
+ GSM_UDHHeader UDHHeader;
+ GSM_NetworkInfo NetInfo;
+ GSM_Error error;
+
+ switch (Bitmap->Type) {
+ case GSM_CallerGroupLogo:
+ case GSM_OperatorLogo:
+ if (Bitmap->Location == 255) {
+ /* Only 6110, 6130 and 6150 support it */
+ if (strcmp(s->Phone.Data.Model,"NSE-3") == 0 || strcmp(s->Phone.Data.Model,"NSK-3") == 0 ||
+ strcmp(s->Phone.Data.Model,"NSM-1") == 0) {
+ if (Bitmap->Type==GSM_CallerGroupLogo) UDHType = UDH_NokiaCallerLogo;
+ UDHHeader.Type = UDHType;
+ GSM_EncodeUDHHeader(&(s->di), &UDHHeader);
+ /* We copy UDH now */
+ memcpy(reqPreview+2,UDHHeader.Text,UDHHeader.Length);
+ count = count + UDHHeader.Length;
+ if (Bitmap->Type == GSM_OperatorLogo) {
+ NOKIA_EncodeNetworkCode(reqPreview+count,Bitmap->NetworkCode);
+ count = count + 3;
+ } else {
+ if (Bitmap->DefaultBitmap) {
+ Bitmap->BitmapWidth = 72;
+ Bitmap->BitmapHeight = 14;
+ GSM_ClearBitmap(Bitmap);
+ }
+ }
+ NOKIA_CopyBitmap(GSM_NokiaOperatorLogo,Bitmap,reqPreview, &count);
+ reqPreview[count]=0x00;
+ error = s->Protocol.Functions->WriteMessage(s, reqPreview, count + 1, 0x12);
+ if (error!=ERR_NONE) return error;
+ sleep(1);
+ /* We have to make something (not important, what) now */
+ /* no answer from phone*/
+ return DCT3_GetNetworkInfo(s,&NetInfo);
+ } else {
+ smprintf(s, "%s\n",s->Phone.Data.Model);
+ return ERR_NOTSUPPORTED;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+
+ count = 3;
+
+ switch (Bitmap->Type) {
+ case GSM_StartupLogo:
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NOSTARTUP)) return ERR_NOTSUPPORTED;
+ if (Bitmap->Location != 1) {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NOSTARTANI)) return ERR_NOTSUPPORTED;
+ }
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NOSTARTANI)) {
+ if (!strcmp(s->Phone.Data.ModelInfo->model,"3210")) {
+ error = N6110_SetProfileFeature(s,0,0x2e,((unsigned char)(Bitmap->Location-1)));
+ } else {
+ error = N6110_SetProfileFeature(s,0,0x29,((unsigned char)(Bitmap->Location-1)));
+ }
+ if (error == ERR_NOTSUPPORTED) error = ERR_SECURITYERROR;
+ if (error != ERR_NONE) return error;
+ if (Bitmap->Location != 1) return ERR_NONE;
+ }
+ req[count++] = 0x18;
+ req[count++] = 0x01; /* One block */
+ req[count++] = 0x01;
+ PHONE_GetBitmapWidthHeight(GSM_NokiaStartupLogo, &Width, &Height);
+ req[count++] = Height;
+ req[count++] = Width;
+ PHONE_EncodeBitmap(GSM_NokiaStartupLogo, req + count, Bitmap);
+ count = count + PHONE_GetBitmapSize(GSM_NokiaStartupLogo,0,0);
+ return GSM_WaitFor (s, req, count, 0x05, 4, ID_SetBitmap);
+ case GSM_WelcomeNote_Text:
+ case GSM_DealerNote_Text:
+ req[count++] = 0x18;
+ req[count++] = 0x01; /* One block */
+ if (Bitmap->Type == GSM_WelcomeNote_Text) {
+ req[count++] = 0x02;
+ } else {
+ req[count++] = 0x03;
+ }
+ textlen = UnicodeLength(Bitmap->Text);
+ req[count++] = textlen;
+ memcpy(req + count,DecodeUnicodeString(Bitmap->Text),textlen);
+ count += textlen;
+ return GSM_WaitFor (s, req, count, 0x05, 4, ID_SetBitmap);
+ case GSM_CallerGroupLogo:
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NOCALLER)) return ERR_NOTSUPPORTED;
+ req[count++] = 0x13;
+ req[count++] = Bitmap->Location - 1;
+ if (Bitmap->DefaultName) {
+ req[count++] = 0;
+ } else {
+ textlen = UnicodeLength(Bitmap->Text);
+ req[count++] = textlen;
+ memcpy(req+count,DecodeUnicodeString(Bitmap->Text),textlen);
+ count += textlen;
+ }
+ if (Bitmap->DefaultRingtone) {
+ req[count++] = 16;
+ } else {
+ req[count++] = Bitmap->RingtoneID;
+ }
+ /* Value here is number of phone menu connected
+ * with caller logo in Nokia 61x0: 0x00 = Off, 0x01 = On,
+ * 0x02 = View Graphics, 0x03 = Send Graphics,
+ * 0x04 = Send via IR. For higher menu option connected with
+ * caller logo is not displayed
+ */
+ if (Bitmap->DefaultBitmap) {
+ Bitmap->BitmapWidth = 72;
+ Bitmap->BitmapHeight = 14;
+ GSM_ClearBitmap(Bitmap);
+ req[count++] = 0;
+ } else {
+ if (Bitmap->BitmapEnabled) req[count++] = 0x01; else req[count++] = 0x00;
+ }
+ req[count++] = (PHONE_GetBitmapSize(GSM_NokiaCallerLogo,0,0) + 4) / 256;
+ req[count++] = (PHONE_GetBitmapSize(GSM_NokiaCallerLogo,0,0) + 4) % 256;
+ NOKIA_CopyBitmap(GSM_NokiaCallerLogo, Bitmap, req, &count);
+ return GSM_WaitFor (s, req, count, 0x03, 4, ID_SetBitmap);
+ case GSM_OperatorLogo:
+ req[count++] = 0x30;
+ req[count++] = 0x01;
+ NOKIA_EncodeNetworkCode(req+count, Bitmap->NetworkCode);
+ count = count + 3;
+ req[count++] = (PHONE_GetBitmapSize(GSM_NokiaOperatorLogo,0,0) + 4) / 256;
+ req[count++] = (PHONE_GetBitmapSize(GSM_NokiaOperatorLogo,0,0) + 4) % 256;
+ NOKIA_CopyBitmap(GSM_NokiaOperatorLogo, Bitmap, req, &count);
+ return GSM_WaitFor (s, req, count, 0x05, 4, ID_SetBitmap);
+ case GSM_PictureImage:
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NOPICTURE)) return ERR_NOTSUPPORTED;
+ req[count++] = 0x03;
+ req[count++] = Bitmap->Location - 1;
+ if (Bitmap->Sender[0]!=0 || Bitmap->Sender[1]!=0) {
+ req[count]=GSM_PackSemiOctetNumber(Bitmap->Sender, req+count+1,TRUE);
+ /* Convert number of semioctets to number of chars and add count */
+ textlen = req[count];
+ if (textlen % 2) textlen++;
+ count += textlen / 2 + 1;
+ count++;
+ } else {
+ req[count++] = 0x00;
+ req[count++] = 0x00;
+ }
+ req[count++] = 0x00;
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOPICTUREUNI) ||
+ (!strcmp(s->Phone.Data.Model,"NHM-5") && s->Phone.Data.VerNum < 5.79)) {
+ textlen = UnicodeLength(Bitmap->Text);
+ req[count++] = textlen;
+ memcpy(req+count,DecodeUnicodeString(Bitmap->Text),textlen);
+ count += textlen;
+ } else {
+ textlen = UnicodeLength(Bitmap->Text)*2;
+ if (!strcmp(s->Phone.Data.Model,"NHM-5")) {
+ req[count++] = textlen;
+ } else {
+ /* 3410 4.26 */
+ req[count++] = textlen+2;
+ req[count++] = 0x00;
+ req[count++] = 0x1e;
+ }
+ memcpy(req+count,Bitmap->Text,textlen);
+ count += textlen;
+ }
+ NOKIA_CopyBitmap(GSM_NokiaPictureImage, Bitmap, req, &count);
+ return GSM_WaitFor (s, req, count, 0x47, 4, ID_SetBitmap);
+ default:
+ break;
+ }
+ return ERR_NOTSUPPORTED;
+}
+
+static GSM_Error N6110_ReplyCallInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+ int tmp, count;
+ GSM_Call call;
+
+ call.CallIDAvailable = TRUE;
+ call.Status = 0;
+ smprintf(s, "Call info, ");
+ switch (msg->Buffer[3]) {
+ case 0x02:
+ smprintf(s, "Call established, waiting for answer\n");
+ call.Status = GSM_CALL_CallEstablished;
+ break;
+ case 0x03:
+ smprintf(s, "Call started\n");
+ /* no phone number in frame */
+ call.Status = GSM_CALL_CallStart;
+ break;
+ case 0x04:
+ smprintf(s, "Remote end hang up\n");
+ smprintf(s, "CC : %i\n",msg->Buffer[6]);
+ call.Status = GSM_CALL_CallRemoteEnd;
+ call.StatusCode = msg->Buffer[6];
+ break;
+ case 0x05:
+ smprintf(s, "Incoming call\n");
+ smprintf(s, "Number : \"");
+ count=msg->Buffer[6];
+ for (tmp=0; tmp <count; tmp++) smprintf(s, "%c", msg->Buffer[7+tmp]);
+ smprintf(s, "\"\nName : \"");
+ for (tmp=0; tmp<msg->Buffer[7+count]; tmp++) smprintf(s, "%c", msg->Buffer[8+count+tmp]);
+ smprintf(s, "\"\n");
+
+ call.Status = GSM_CALL_IncomingCall;
+ EncodeUnicode(call.PhoneNumber, msg->Buffer+7, msg->Buffer[6]);
+ break;
+ case 0x07:
+ smprintf(s, "Call answer initiated\n");
+ break;
+ case 0x09:
+ smprintf(s, "Call released\n");
+ call.Status = GSM_CALL_CallLocalEnd;
+ break;
+ case 0x0a:
+ smprintf(s, "Call is being released\n");
+ break;
+ case 0x23:
+ smprintf(s, "Call held\n");
+ call.Status = GSM_CALL_CallHeld;
+ break;
+ case 0x25:
+ smprintf(s, "Call resumed\n");
+ call.Status = GSM_CALL_CallResumed;
+ break;
+ case 0x27:
+ smprintf(s, "Call switched\n");
+ /* incorrect call id in frame - 6150 5.22 */
+ call.CallIDAvailable = FALSE;
+ call.Status = GSM_CALL_CallSwitched;
+ break;
+ case 0x29:
+ smprintf(s, "Joining call to the conference (conference)\n");
+ break;
+ case 0x2A:
+ smprintf(s, "Removing call from the conference (split)\n");
+ break;
+ }
+ if (call.CallIDAvailable) smprintf(s, "Call ID : %d\n",msg->Buffer[4]);
+ if (Data->EnableIncomingCall && s->User.IncomingCall!=NULL && call.Status != 0) {
+ if (call.CallIDAvailable) call.CallID = msg->Buffer[4];
+ s->User.IncomingCall(s, &call, s->User.IncomingCallUserData);
+ }
+ if (s->Phone.Data.RequestID == ID_CancelCall) {
+ if (msg->Buffer[3] == 0x09) {
+ if (s->Phone.Data.CallID == msg->Buffer[4]) return ERR_NONE;
+ /* when we canceled call and see frame about other
+ * call releasing, we don't give ERR_NONE for "our"
+ * call release command
+ */
+ return ERR_NEEDANOTHERANSWER;
+ }
+ }
+ if (s->Phone.Data.RequestID == ID_AnswerCall) {
+ if (msg->Buffer[3] == 0x07) {
+ if (s->Phone.Data.CallID == msg->Buffer[4]) return ERR_NONE;
+ return ERR_NEEDANOTHERANSWER;
+ }
+ }
+ if (s->Phone.Data.RequestID == ID_UnholdCall) {
+ if (msg->Buffer[3] == 0x25) {
+ if (s->Phone.Data.CallID == msg->Buffer[4]) return ERR_NONE;
+ return ERR_NEEDANOTHERANSWER;
+ }
+ }
+ if (s->Phone.Data.RequestID == ID_HoldCall) {
+ if (msg->Buffer[3] == 0x23) {
+ if (s->Phone.Data.CallID == msg->Buffer[4]) return ERR_NONE;
+ return ERR_NEEDANOTHERANSWER;
+ }
+ }
+ if (s->Phone.Data.RequestID == ID_ConferenceCall) {
+ if (msg->Buffer[3] == 0x29) {
+ if (s->Phone.Data.CallID == msg->Buffer[4]) return ERR_NONE;
+ return ERR_NEEDANOTHERANSWER;
+ }
+ }
+ if (s->Phone.Data.RequestID == ID_SplitCall) {
+ if (msg->Buffer[3] == 0x2B) {
+ if (s->Phone.Data.CallID == msg->Buffer[4]) return ERR_NONE;
+ return ERR_NEEDANOTHERANSWER;
+ }
+ }
+ return ERR_NONE;
+}
+
+static GSM_Error N6110_DeleteSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x0a, 0x02,
+ 0x00}; /* Location */
+
+ if (sms->Folder!=0x00) return ERR_NOTSUPPORTED;
+
+ req[5]=sms->Location;
+
+ smprintf(s, "Deleting sms\n");
+ return GSM_WaitFor (s, req, 6, 0x14, 4, ID_DeleteSMSMessage);
+}
+
+static GSM_Error N6110_ReplySetMemory(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "Reply for writing memory\n");
+ switch (msg->Buffer[3]) {
+ case 0x05:
+ smprintf(s, "Done OK\n");
+ return ERR_NONE;
+ case 0x06:
+ smprintf(s, "Error\n");
+ switch (msg->Buffer[4]) {
+ case 0x7d:
+ smprintf(s, "Too high location ?\n");
+ return ERR_INVALIDLOCATION;
+ case 0x90:
+ smprintf(s, "Too long name...or other error\n");
+ return ERR_NOTSUPPORTED;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ }
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6110_SetMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
+{
+ int current, Group, Name, Number, i;
+ unsigned char req[128] = {N6110_FRAME_HEADER, 0x04,
+ 0x00, /* memory type */
+ 0x00}; /* location */
+
+ if (entry->Location == 0) return ERR_NOTSUPPORTED;
+ if (entry->Location > 255) return ERR_INVALIDLOCATION;
+
+ GSM_PhonebookFindDefaultNameNumberGroup(entry, &Name, &Number, &Group);
+
+ req[4] = NOKIA_GetMemoryType(s, entry->MemoryType,N6110_MEMORY_TYPES);
+ req[5] = entry->Location;
+
+ current = 7;
+
+ for (i=0;i<entry->EntriesNum;i++) {
+ entry->Entries[i].AddError = ERR_NOTSUPPORTED;
+ }
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOPBKUNICODE)) {
+ if (Name != -1) {
+ req[6] = UnicodeLength(entry->Entries[Name].Text);
+ memcpy(req+current,DecodeUnicodeString(entry->Entries[Name].Text),UnicodeLength(entry->Entries[Name].Text));
+ current += UnicodeLength(entry->Entries[Name].Text);
+ entry->Entries[Name].AddError = ERR_NONE;
+ } else req[6] = 0;
+ } else {
+ if (Name != -1) {
+ req[6] = UnicodeLength(entry->Entries[Name].Text)*2+2;
+ memcpy(req+current,entry->Entries[Name].Text,UnicodeLength(entry->Entries[Name].Text)*2);
+ current += UnicodeLength(entry->Entries[Name].Text)*2;
+ entry->Entries[Name].AddError = ERR_NONE;
+ } else req[6] = 0;
+ req[current++]=0x00;
+ req[current++]=0x00;
+ }
+
+ if (Number != -1) {
+ req[current++]=UnicodeLength(entry->Entries[Number].Text);
+ memcpy(req+current,DecodeUnicodeString(entry->Entries[Number].Text),UnicodeLength(entry->Entries[Number].Text));
+ current += UnicodeLength(entry->Entries[Number].Text);
+ entry->Entries[Number].AddError = ERR_NONE;
+ } else req[current++] = 0;
+
+ /* This allow to save 14 characters name into SIM memory, when
+ * no caller group is selected. */
+ if (Group == -1) {
+ req[current++] = 0xff;
+ } else {
+ req[current++] = entry->Entries[Group].Number-1;
+ entry->Entries[Group].AddError = ERR_NONE;
+ }
+
+ smprintf(s, "Writing phonebook entry\n");
+ return GSM_WaitFor (s, req, current, 0x03, 4, ID_SetMemory);
+}
+
+static GSM_Error N6110_DeleteMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
+{
+ GSM_MemoryEntry dwa;
+
+ dwa.Location = entry->Location;
+ dwa.MemoryType = entry->MemoryType;
+ dwa.EntriesNum = 0;
+
+ return N6110_SetMemory(s, &dwa);
+}
+
+GSM_Error N6110_ReplyGetRingtone(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+ char buffer[2000];
+ GSM_Error error;
+ size_t i,end,start;
+
+ smprintf(s, "Ringtone received\n");
+ switch (msg->Buffer[4]) {
+ case 0x00:
+ switch (Data->Ringtone->Format) {
+ case RING_NOTETONE:
+ memcpy(buffer,msg->Buffer,msg->Length);
+ i=7;
+ if (buffer[9]==0x4a && buffer[10]==0x3a) i=8;
+ buffer[i]=0x02;
+ error=GSM_DecodeNokiaRTTLRingtone(Data->Ringtone, buffer+i, msg->Length-i);
+ if (error!=ERR_NONE) return ERR_EMPTY;
+ return ERR_NONE;
+ case RING_NOKIABINARY:
+ i=8;
+ while (msg->Buffer[i]!=0) {
+ i++;
+ if (i >= GSM_MAX_RINGTONE_NAME_LENGTH) {
+ smprintf(s, "Ringtone name too long!\n");
+ return ERR_MOREMEMORY;
+ }
+ if (i > msg->Length) {
+ return ERR_EMPTY;
+ }
+ }
+ EncodeUnicode(Data->Ringtone->Name,msg->Buffer+8,i-8);
+ smprintf(s, "Name \"%s\"\n",DecodeUnicodeString(Data->Ringtone->Name));
+ /* Looking for start && end */
+ end=0;start=0;i=0;
+ while (TRUE) {
+ if (start!=0) {
+ if (msg->Buffer[i]==0x07 && msg->Buffer[i+1]==0x0b) {
+ end=i+2; break;
+ }
+ if (msg->Buffer[i]==0x0e && msg->Buffer[i+1]==0x0b) {
+ end=i+2; break;
+ }
+ } else {
+ if (msg->Buffer[i]==0x02 && msg->Buffer[i+1]==0xfc && msg->Buffer[i+2]==0x09) {
+ start = i;
+ }
+ }
+ i++;
+ if (i==msg->Length-3) return ERR_EMPTY;
+ }
+ /* Copying frame */
+ memcpy(Data->Ringtone->NokiaBinary.Frame,msg->Buffer+start,end-start);
+ Data->Ringtone->NokiaBinary.Length=end-start;
+#ifdef DEBUG
+ if (s->di.dl == DL_TEXTALL || s->di.dl == DL_TEXTALLDATE) DumpMessage(&s->di, Data->Ringtone->NokiaBinary.Frame, Data->Ringtone->NokiaBinary.Length);
+#endif
+ return ERR_NONE;
+ case RING_MIDI:
+ case RING_MMF:
+ return ERR_NOTSUPPORTED;
+ }
+ smprintf(s, "Ringtone format is %i\n",Data->Ringtone->Format);
+ break;
+ default:
+ smprintf(s, "Invalid location. Too high ?\n");
+ return ERR_INVALIDLOCATION;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6110_GetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, gboolean PhoneRingtone)
+{
+ GSM_Error error;
+ unsigned char req[] = {0x00, 0x01, 0x9e,
+ 0x00}; /* location */
+
+ if (PhoneRingtone) return ERR_NOTSUPPORTED;
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NORING)) return ERR_NOTSUPPORTED;
+ if (Ringtone->Location == 0) return ERR_INVALIDLOCATION;
+
+ if (Ringtone->Format == 0x00) {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_RING_SM)) {
+ Ringtone->Format = RING_NOTETONE;
+ } else {
+ Ringtone->Format = RING_NOKIABINARY;
+ }
+ }
+
+ switch (Ringtone->Format) {
+ case RING_NOTETONE:
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_RING_SM)) return ERR_NOTSUPPORTED;
+ break;
+ case RING_NOKIABINARY:
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_RING_SM)) return ERR_NOTSUPPORTED;
+ break;
+ case RING_MIDI:
+ case RING_MMF:
+ return ERR_NOTSUPPORTED;
+ }
+
+ error=DCT3_EnableSecurity (s, 0x01);
+ if (error!=ERR_NONE) return error;
+
+ req[3]=Ringtone->Location-1;
+ s->Phone.Data.Ringtone=Ringtone;
+ smprintf(s, "Getting (binary) ringtone\n");
+ return GSM_WaitFor (s, req, 4, 0x40, 4, ID_GetRingtone);
+}
+
+static GSM_Error N6110_ReplyGetSecurityStatus(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ *s->Phone.Data.SecurityStatus = msg->Buffer[4];
+
+#ifdef DEBUG
+ smprintf(s, "Security code status\n");
+ switch(msg->Buffer[4]) {
+ case SEC_SecurityCode: smprintf(s, "waiting for Security Code.\n"); break;
+ case SEC_Pin : smprintf(s, "waiting for PIN.\n"); break;
+ case SEC_Pin2 : smprintf(s, "waiting for PIN2.\n"); break;
+ case SEC_Puk : smprintf(s, "waiting for PUK.\n"); break;
+ case SEC_Puk2 : smprintf(s, "waiting for PUK2.\n"); break;
+ case SEC_None : smprintf(s, "nothing to enter.\n"); break;
+ default : smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+#endif
+ return ERR_NONE;
+}
+
+static GSM_Error N6110_GetSecurityStatus(GSM_StateMachine *s, GSM_SecurityCodeType *Status)
+{
+ unsigned char req[4] = {N6110_FRAME_HEADER, 0x07};
+
+ s->Phone.Data.SecurityStatus=Status;
+ smprintf(s, "Getting security code status\n");
+ return GSM_WaitFor (s, req, 4, 0x08, 2, ID_GetSecurityStatus);
+}
+
+static GSM_Error N6110_ReplyEnterSecurityCode(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x0b:
+ smprintf(s, "Security code OK\n");
+ return ERR_NONE;
+ case 0x0c:
+ switch (msg->Buffer[4]) {
+ case 0x88:
+ smprintf(s, "Wrong code\n");
+ return ERR_SECURITYERROR;
+ case 0x8b:
+ smprintf(s, "Not required\n");
+ return ERR_NONE;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ }
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6110_EnterSecurityCode(GSM_StateMachine *s, GSM_SecurityCode *Code)
+{
+ int len = 0;
+ unsigned char req[15] = {N6110_FRAME_HEADER, 0x0a,
+ 0x00}; /* Type of code to enter */
+
+ req[4]=Code->Type;
+
+ len = strlen(Code->Code);
+ memcpy(req+5,Code->Code,len);
+ req[5+len]=0x00;
+ req[6+len]=0x00;
+
+ smprintf(s, "Entering security code\n");
+ return GSM_WaitFor (s, req, 7+len, 0x08, 4, ID_EnterSecurityCode);
+}
+
+static GSM_Error N6110_ReplyGetSpeedDial(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ switch (msg->Buffer[3]) {
+ case 0x17:
+ smprintf(s, "Speed dial received\n");
+ switch (msg->Buffer[4]) {
+ case 0x02:
+ Data->SpeedDial->MemoryType = MEM_ME;
+ smprintf(s, "ME ");
+ break;
+ case 0x03:
+ Data->SpeedDial->MemoryType = MEM_SM;
+ smprintf(s, "SIM ");
+ break;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ Data->SpeedDial->MemoryLocation = msg->Buffer[5];
+ if (msg->Buffer[5] == 0x00) Data->SpeedDial->MemoryLocation = Data->SpeedDial->Location;
+ Data->SpeedDial->MemoryNumberID = 2;
+ smprintf(s, "location %i\n",Data->SpeedDial->MemoryLocation);
+ return ERR_NONE;
+ case 0x18:
+ smprintf(s, "Error getting speed dial. Invalid location\n");
+ return ERR_INVALIDLOCATION;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6110_GetSpeedDial(GSM_StateMachine *s, GSM_SpeedDial *SpeedDial)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x16,
+ 0x01}; /* location */
+
+ req[4] = SpeedDial->Location;
+
+ s->Phone.Data.SpeedDial=SpeedDial;
+ smprintf(s, "Getting speed dial\n");
+ return GSM_WaitFor (s, req, 5, 0x03, 4, ID_GetSpeedDial);
+}
+
+static GSM_Error N6110_ReplySendDTMF(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x40:
+ smprintf(s, "During sending DTMF\n");
+ return ERR_NONE;
+ case 0x51:
+ smprintf(s, "DTMF sent OK\n");
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6110_ReplyGetDisplayStatus(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int i;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "Display status received\n");
+ if (Data->RequestID == ID_GetDisplayStatus) Data->DisplayFeatures->Number=0;
+ for (i=0;i<msg->Buffer[4];i++) {
+ if (msg->Buffer[2*i+6] == 0x02) {
+#ifdef DEBUG
+ switch (msg->Buffer[2*i+5]) {
+ case 0x01: smprintf(s, "Call in progress\n"); break;
+ case 0x02: smprintf(s, "Unknown\n"); break;
+ case 0x03: smprintf(s, "Unread SMS\n"); break;
+ case 0x04: smprintf(s, "Voice call\n"); break;
+ case 0x05: smprintf(s, "Fax call active\n"); break;
+ case 0x06: smprintf(s, "Data call active\n"); break;
+ case 0x07: smprintf(s, "Keyboard lock\n"); break;
+ case 0x08: smprintf(s, "SMS storage full\n"); break;
+ }
+#endif
+ if (Data->RequestID == ID_GetDisplayStatus) {
+ switch (msg->Buffer[2*i+5]) {
+ case 0x01: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_CallActive;
+ break;
+ case 0x03: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_UnreadSMS;
+ break;
+ case 0x04: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_VoiceCall;
+ break;
+ case 0x05: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_FaxCall;
+ break;
+ case 0x06: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_DataCall;
+ break;
+ case 0x07: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_KeypadLocked;
+ break;
+ case 0x08: Data->DisplayFeatures->Feature[Data->DisplayFeatures->Number] = GSM_SMSMemoryFull;
+ break;
+ }
+ if (msg->Buffer[2*i+5]!=0x02) Data->DisplayFeatures->Number++;
+ }
+ }
+ }
+ return ERR_NONE;
+}
+
+static GSM_Error N6110_GetDisplayStatus(GSM_StateMachine *s, GSM_DisplayFeatures *features)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x51};
+
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_DISPSTATUS)) return ERR_NOTSUPPORTED;
+
+ s->Phone.Data.DisplayFeatures = features;
+ smprintf(s, "Getting display status\n");
+ return GSM_WaitFor (s, req, 4, 0x0d, 4, ID_GetDisplayStatus);
+}
+
+static GSM_Profile_PhoneTableValue Profile6110[] = {
+ {Profile_KeypadTone, PROFILE_KEYPAD_LEVEL1, 0x00,0x00},
+ {Profile_KeypadTone, PROFILE_KEYPAD_LEVEL2, 0x00,0x01},
+ {Profile_KeypadTone, PROFILE_KEYPAD_LEVEL3, 0x00,0x02},
+ {Profile_KeypadTone, PROFILE_KEYPAD_OFF, 0x00,0xff},
+ {Profile_Lights, PROFILE_LIGHTS_OFF, 0x01,0x00},
+ {Profile_Lights, PROFILE_LIGHTS_AUTO, 0x01,0x01},
+ {Profile_CallAlert, PROFILE_CALLALERT_RINGING, 0x02,0x01},
+ {Profile_CallAlert, PROFILE_CALLALERT_BEEPONCE, 0x02,0x02},
+ {Profile_CallAlert, PROFILE_CALLALERT_OFF, 0x02,0x04},
+ {Profile_CallAlert, PROFILE_CALLALERT_RINGONCE, 0x02,0x05},
+ {Profile_CallAlert, PROFILE_CALLALERT_ASCENDING, 0x02,0x06},
+ {Profile_CallAlert, PROFILE_CALLALERT_CALLERGROUPS,0x02,0x07},
+ /* Ringtone ID */
+ {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL1, 0x04,0x06},
+ {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL2, 0x04,0x07},
+ {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL3, 0x04,0x08},
+ {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL4, 0x04,0x09},
+ {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL5, 0x04,0x0a},
+ {Profile_MessageTone, PROFILE_MESSAGE_NOTONE, 0x05,0x00},
+ {Profile_MessageTone, PROFILE_MESSAGE_STANDARD, 0x05,0x01},
+ {Profile_MessageTone, PROFILE_MESSAGE_SPECIAL, 0x05,0x02},
+ {Profile_MessageTone, PROFILE_MESSAGE_BEEPONCE, 0x05,0x03},
+ {Profile_MessageTone, PROFILE_MESSAGE_ASCENDING, 0x05,0x04},
+ {Profile_Vibration, PROFILE_VIBRATION_OFF, 0x06,0x00},
+ {Profile_Vibration, PROFILE_VIBRATION_ON, 0x06,0x01},
+ {Profile_WarningTone, PROFILE_WARNING_OFF, 0x07,0xff},
+ {Profile_WarningTone, PROFILE_WARNING_ON, 0x07,0x04},
+ /* Caller groups */
+ {Profile_AutoAnswer, PROFILE_AUTOANSWER_OFF, 0x09,0x00},
+ {Profile_AutoAnswer, PROFILE_AUTOANSWER_ON, 0x09,0x01},
+ {0x00, 0x00, 0x00,0x00}
+};
+
+static GSM_Profile_PhoneTableValue Profile3310[] = {
+ {Profile_KeypadTone, PROFILE_KEYPAD_LEVEL1, 0x00,0x00},
+ {Profile_KeypadTone, PROFILE_KEYPAD_LEVEL2, 0x00,0x01},
+ {Profile_KeypadTone, PROFILE_KEYPAD_LEVEL3, 0x00,0x02},
+ {Profile_KeypadTone, PROFILE_KEYPAD_OFF, 0x00,0xff},
+ {Profile_CallAlert, PROFILE_CALLALERT_RINGING, 0x01,0x01},
+ {Profile_CallAlert, PROFILE_CALLALERT_BEEPONCE, 0x01,0x02},
+ {Profile_CallAlert, PROFILE_CALLALERT_OFF, 0x01,0x04},
+ {Profile_CallAlert, PROFILE_CALLALERT_RINGONCE, 0x01,0x05},
+ {Profile_CallAlert, PROFILE_CALLALERT_ASCENDING, 0x01,0x06},
+ /* Ringtone ID */
+ {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL1, 0x03,0x06},
+ {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL2, 0x03,0x07},
+ {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL3, 0x03,0x08},
+ {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL4, 0x03,0x09},
+ {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL5, 0x03,0x0a},
+ {Profile_MessageTone, PROFILE_MESSAGE_NOTONE, 0x04,0x00},
+ {Profile_MessageTone, PROFILE_MESSAGE_STANDARD, 0x04,0x01},
+ {Profile_MessageTone, PROFILE_MESSAGE_SPECIAL, 0x04,0x02},
+ {Profile_MessageTone, PROFILE_MESSAGE_BEEPONCE, 0x04,0x03},
+ {Profile_MessageTone, PROFILE_MESSAGE_ASCENDING, 0x04,0x04},
+ {Profile_MessageTone, PROFILE_MESSAGE_PERSONAL, 0x04,0x05},
+ {Profile_Vibration, PROFILE_VIBRATION_OFF, 0x05,0x00},
+ {Profile_Vibration, PROFILE_VIBRATION_ON, 0x05,0x01},
+ {Profile_Vibration, PROFILE_VIBRATION_FIRST, 0x05,0x02},
+ {Profile_WarningTone, PROFILE_WARNING_OFF, 0x06,0xff},
+ {Profile_WarningTone, PROFILE_WARNING_ON, 0x06,0x04},
+ {Profile_ScreenSaver, PROFILE_SAVER_OFF, 0x07,0x00},
+ {Profile_ScreenSaver, PROFILE_SAVER_ON, 0x07,0x01},
+ {Profile_ScreenSaverTime,PROFILE_SAVER_TIMEOUT_5SEC, 0x08,0x00},
+ {Profile_ScreenSaverTime,PROFILE_SAVER_TIMEOUT_20SEC, 0x08,0x01},
+ {Profile_ScreenSaverTime,PROFILE_SAVER_TIMEOUT_1MIN, 0x08,0x02},
+ {Profile_ScreenSaverTime,PROFILE_SAVER_TIMEOUT_2MIN, 0x08,0x03},
+ {Profile_ScreenSaverTime,PROFILE_SAVER_TIMEOUT_5MIN, 0x08,0x04},
+ {Profile_ScreenSaverTime,PROFILE_SAVER_TIMEOUT_10MIN, 0x08,0x05},
+ {0x00, 0x00, 0x00,0x00}
+};
+
+static GSM_Error N6110_ReplyGetProfileFeature(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ switch (msg->Buffer[3]) {
+ case 0x0d: /* Maybe this is handled completely wrong */
+ case 0x14:
+ smprintf(s, "Profile feature %02x with value %02x\n",msg->Buffer[6],msg->Buffer[8]);
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PROFILES33)) {
+ switch (msg->Buffer[6]) {
+ case 0x02:
+ smprintf(s, "Ringtone ID\n");
+ Data->Profile->FeatureID [Data->Profile->FeaturesNumber] = Profile_RingtoneID;
+ Data->Profile->FeatureValue [Data->Profile->FeaturesNumber] = msg->Buffer[8];
+ Data->Profile->FeaturesNumber++;
+ break;
+ case 0x09 :
+ smprintf(s, "screen saver number\n");
+ Data->Profile->FeatureID [Data->Profile->FeaturesNumber] = Profile_ScreenSaverNumber;
+ Data->Profile->FeatureValue [Data->Profile->FeaturesNumber] = msg->Buffer[8] + 1;
+ Data->Profile->FeaturesNumber++;
+ break;
+ case 0x24:
+ smprintf(s, "selected profile\n");
+ if (msg->Buffer[8] + 1 == Data->Profile->Location) Data->Profile->Active = TRUE;
+ break;
+ default:
+ NOKIA_FindFeatureValue(s, Profile3310,msg->Buffer[6],msg->Buffer[8],Data,FALSE);
+ }
+ return ERR_NONE;
+ }
+ switch (msg->Buffer[6]) {
+ case 0x01: /* Lights */
+ if (Data->Profile->CarKitProfile) {
+ NOKIA_FindFeatureValue(s, Profile6110,msg->Buffer[6],msg->Buffer[8],Data,FALSE);
+ }
+ break;
+ case 0x03:
+ smprintf(s, "Ringtone ID\n");
+ Data->Profile->FeatureID [Data->Profile->FeaturesNumber] = Profile_RingtoneID;
+ Data->Profile->FeatureValue [Data->Profile->FeaturesNumber] = msg->Buffer[8];
+ Data->Profile->FeaturesNumber++;
+ break;
+ case 0x08: /* Caller groups */
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PROFILES51)) {
+ NOKIA_FindFeatureValue(s, Profile6110,msg->Buffer[6],msg->Buffer[8],Data,TRUE);
+ }
+ break;
+ case 0x09: /* Autoanswer */
+ if (Data->Profile->CarKitProfile || Data->Profile->HeadSetProfile) {
+ NOKIA_FindFeatureValue(s, Profile6110,msg->Buffer[6],msg->Buffer[8],Data,FALSE);
+ }
+ break;
+ case 0x2A:
+ smprintf(s, "selected profile\n");
+ if (msg->Buffer[8] + 1 == Data->Profile->Location) Data->Profile->Active = TRUE;
+ break;
+ default:
+ NOKIA_FindFeatureValue(s, Profile6110,msg->Buffer[6],msg->Buffer[8],Data,FALSE);
+ }
+ return ERR_NONE;
+ case 0x15:
+ smprintf(s, "Invalid profile location\n");
+ return ERR_INVALIDLOCATION;
+ case 0x1b:
+ Data->Profile->Name[0] = 0;
+ Data->Profile->Name[1] = 0;
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PROFILES33)) {
+ EncodeUnicode(Data->Profile->Name,msg->Buffer+10,msg->Buffer[9]);
+ } else {
+ if (msg->Length > 0x0A) {
+ CopyUnicodeString(Data->Profile->Name,msg->Buffer+10);
+ }
+ }
+ smprintf(s, "Profile name: \"%s\"\n",Data->Profile->Name);
+ Data->Profile->DefaultName = FALSE;
+ if (msg->Buffer[9]==0x00) Data->Profile->DefaultName = TRUE;
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6110_GetProfile(GSM_StateMachine *s, GSM_Profile *Profile)
+{
+ GSM_Error error;
+ int i,j;
+ unsigned char name_req[] = {N6110_FRAME_HEADER, 0x1a, 0x00};
+ unsigned char feat_req[] = {N6110_FRAME_HEADER, 0x13, 0x01,
+ 0x00, /* Profile location */
+ 0x00}; /* Feature number */
+
+ s->Phone.Data.Profile=Profile;
+
+ smprintf(s, "Getting profile name\n");
+ error = GSM_WaitFor (s, name_req, 5, 0x05, 4, ID_GetProfile);
+ if (error!=ERR_NONE) return error;
+ if (Profile->DefaultName) {
+ NOKIA_GetDefaultProfileName(Profile);
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PROFILES51)) {
+ switch(Profile->Location) {
+ case 1: EncodeUnicode(Profile->Name,_("Personal"),strlen(_("Personal")));
+ break;
+ case 2: EncodeUnicode(Profile->Name,_("Car"),strlen(_("Car")));
+ break;
+ case 3: EncodeUnicode(Profile->Name,_("Headset"),strlen(_("Headset")));
+ break;
+ }
+ }
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PROFILES33)) {
+ switch(Profile->Location) {
+ case 1: EncodeUnicode(Profile->Name,_("General"),strlen(_("General")));
+ break;
+ case 2: EncodeUnicode(Profile->Name,_("Silent"),strlen(_("Silent")));
+ break;
+ case 3: EncodeUnicode(Profile->Name,_("Discreet"),strlen(_("Discreet")));
+ break;
+ case 4: EncodeUnicode(Profile->Name,_("Loud"),strlen(_("Loud")));
+ break;
+ case 5: EncodeUnicode(Profile->Name,_("My style"),strlen(_("My style")));
+ break;
+ case 6: Profile->Name[0] = 0; Profile->Name[1] = 0;
+ break;
+ }
+ }
+ }
+
+ Profile->FeaturesNumber = 0;
+
+ Profile->CarKitProfile = FALSE;
+ Profile->HeadSetProfile = FALSE;
+ if (Profile->Location == 6) Profile->CarKitProfile = TRUE;
+ if (Profile->Location == 7) Profile->HeadSetProfile = TRUE;
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PROFILES51)) {
+ if (Profile->Location == 2) Profile->CarKitProfile = TRUE;
+ if (Profile->Location == 3) Profile->HeadSetProfile = TRUE;
+ }
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PROFILES33)) {
+ Profile->HeadSetProfile = FALSE; /* fixme */
+ Profile->CarKitProfile = FALSE;
+ }
+
+ for (i = 0x00; i <= 0x09; i++) {
+ feat_req[5] = Profile->Location - 1;
+ feat_req[6] = i;
+ smprintf(s, "Getting profile feature\n");
+ error = GSM_WaitFor (s, feat_req, 7, 0x05, 4, ID_GetProfile);
+ if (error!=ERR_NONE) return error;
+ }
+
+ for (i=0;i<Profile->FeaturesNumber;i++) {
+ if (Profile->FeatureID[i] == Profile_CallAlert &&
+ Profile->FeatureValue[i] != PROFILE_CALLALERT_CALLERGROUPS) {
+ for (j=0;j<5;j++) Profile->CallerGroups[j] = TRUE;
+ }
+ }
+
+ Profile->Active = FALSE;
+ feat_req[5] = 0;
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PROFILES33)) {
+ feat_req[6] = 0x24;
+ } else {
+ feat_req[6] = 0x2A;
+ }
+ smprintf(s, "Getting profile feature\n");
+ error = GSM_WaitFor (s, feat_req, 7, 0x05, 4, ID_GetProfile);
+
+ return error;
+}
+
+static GSM_Error N6110_SetProfile(GSM_StateMachine *s, GSM_Profile *Profile)
+{
+ int i;
+ gboolean found;
+ unsigned char ID,Value;
+ GSM_Error error;
+ GSM_Profile_PhoneTableValue *ProfilePhone = Profile6110;
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PROFILES33)) ProfilePhone = Profile3310;
+
+ for (i=0;i<Profile->FeaturesNumber;i++) {
+ found = FALSE;
+ if (ProfilePhone == Profile3310) {
+ switch (Profile->FeatureID[i]) {
+ case Profile_RingtoneID:
+ ID = 0x02;
+ Value = Profile->FeatureValue[i];
+ found = TRUE;
+ break;
+ case Profile_ScreenSaverNumber:
+ ID = 0x09;
+ Value = Profile->FeatureValue[i];
+ found = TRUE;
+ break;
+ default:
+ found=NOKIA_FindPhoneFeatureValue(
+ s,
+ ProfilePhone,
+ Profile->FeatureID[i],Profile->FeatureValue[i],
+ &ID,&Value);
+ }
+ }
+ if (ProfilePhone == Profile6110) {
+ switch (Profile->FeatureID[i]) {
+ case Profile_RingtoneID:
+ ID = 0x03;
+ Value = Profile->FeatureValue[i];
+ found = TRUE;
+ break;
+ default:
+ found=NOKIA_FindPhoneFeatureValue(
+ s,
+ ProfilePhone,
+ Profile->FeatureID[i],Profile->FeatureValue[i],
+ &ID,&Value);
+ }
+ }
+ if (found) {
+ error=N6110_SetProfileFeature (s,((unsigned char)(Profile->Location-1)),ID,Value);
+ if (error!=ERR_NONE) return error;
+ }
+ }
+ return ERR_NONE;
+}
+
+static GSM_Error N6110_ReplyIncomingSMS(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+ GSM_SMSMessage sms;
+
+#ifdef DEBUG
+ smprintf(s, "SMS message received\n");
+ sms.State = SMS_UnRead;
+ sms.InboxFolder = TRUE;
+ DCT3_DecodeSMSFrame(s, &sms,msg->Buffer+7);
+#endif
+ if (Data->EnableIncomingSMS && s->User.IncomingSMS!=NULL) {
+ sms.State = SMS_UnRead;
+ sms.InboxFolder = TRUE;
+ DCT3_DecodeSMSFrame(s, &sms,msg->Buffer+7);
+
+ s->User.IncomingSMS(s, &sms, s->User.IncomingSMSUserData);
+ }
+ return ERR_NONE;
+}
+
+static GSM_Error N6110_ReplyAddCalendar(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "Writing calendar note: ");
+ switch (msg->Buffer[4]) {
+ case 0x01:
+ smprintf(s, "OK\n");
+ return ERR_NONE;
+ case 0x02:
+ smprintf(s, "OK, but text was shortened\n");
+ return ERR_NONE;
+ case 0x73:
+ case 0x7d:
+ smprintf(s, "error\n");
+ return ERR_UNKNOWN;
+ case 0x81:
+ smprintf(s,"during editing notes in phone menu\n");
+ return ERR_INSIDEPHONEMENU;
+ default:
+ smprintf(s, "unknown ERROR %i\n",msg->Buffer[4]);
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6110_AddCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note)
+{
+ gboolean Reminder3310 = FALSE;
+ int Text, Time, Alarm, Phone, EndTime, Location, i, current, j;
+ unsigned char req[200] = {N6110_FRAME_HEADER, 0x64, 0x01, 0x10,
+ 0x00, /* Length of the rest of the frame */
+ 0x00, /* Calendar note type */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x66, 0x01};
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOCALENDAR)) return ERR_NOTSUPPORTED;
+
+ GSM_CalendarFindDefaultTextTimeAlarmPhone(Note, &Text, &Time, &Alarm, &Phone, &EndTime, &Location);
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_CAL52)) {
+ switch(Note->Type) {
+ case GSM_CAL_REMINDER: req[7]=0x01; break;
+ case GSM_CAL_CALL : req[7]=0x02; break;
+ case GSM_CAL_MEETING : req[7]=0x03; break;
+ case GSM_CAL_BIRTHDAY: req[7]=0x04; break;
+ case GSM_CAL_T_ATHL : req[7]=0x05; break;
+ case GSM_CAL_T_BALL : req[7]=0x06; break;
+ case GSM_CAL_T_CYCL : req[7]=0x07; break;
+ case GSM_CAL_T_BUDO : req[7]=0x08; break;
+ case GSM_CAL_T_DANC : req[7]=0x09; break;
+ case GSM_CAL_T_EXTR : req[7]=0x0a; break;
+ case GSM_CAL_T_FOOT : req[7]=0x0b; break;
+ case GSM_CAL_T_GOLF : req[7]=0x0c; break;
+ case GSM_CAL_T_GYM : req[7]=0x0d; break;
+ case GSM_CAL_T_HORS : req[7]=0x0e; break;
+ case GSM_CAL_T_HOCK : req[7]=0x0f; break;
+ case GSM_CAL_T_RACE : req[7]=0x10; break;
+ case GSM_CAL_T_RUGB : req[7]=0x11; break;
+ case GSM_CAL_T_SAIL : req[7]=0x12; break;
+ case GSM_CAL_T_STRE : req[7]=0x13; break;
+ case GSM_CAL_T_SWIM : req[7]=0x14; break;
+ case GSM_CAL_T_TENN : req[7]=0x15; break;
+ case GSM_CAL_T_TRAV : req[7]=0x16; break;
+ case GSM_CAL_T_WINT : req[7]=0x17; break;
+ default : req[7]=0x01; break;
+ }
+ } else {
+ switch(Note->Type) {
+ case GSM_CAL_CALL : req[7]=0x02; break;
+ case GSM_CAL_MEETING : req[7]=0x03; break;
+ case GSM_CAL_BIRTHDAY: req[7]=0x04; break;
+ case GSM_CAL_REMINDER:
+ default : req[7]=0x01; break;
+ }
+ }
+
+ if (Time == -1) return ERR_UNKNOWN;
+ NOKIA_EncodeDateTime(s, req+8, &Note->Entries[Time].Date);
+ req[14] = Note->Entries[Time].Date.Second;
+
+ if (Alarm != -1) {
+ NOKIA_EncodeDateTime(s, req+15, &Note->Entries[Alarm].Date);
+ req[21] = Note->Entries[Alarm].Date.Second;
+ }
+
+ current = 23;
+
+ if (Text != -1) {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_CAL52) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_CAL82)) {
+ req[22] = UnicodeLength(Note->Entries[Text].Text)*2;
+ memcpy(req+current,Note->Entries[Text].Text,UnicodeLength(Note->Entries[Text].Text)*2);
+ current += UnicodeLength(Note->Entries[Text].Text)*2;
+ } else {
+ req[22] = UnicodeLength(Note->Entries[Text].Text);
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_CAL33)) {
+ Reminder3310 = TRUE;
+ if (!strcmp(s->Phone.Data.ModelInfo->model,"3310") && s->Phone.Data.VerNum<5.11) {
+ if (Note->Type!=GSM_CAL_REMINDER) Reminder3310 = FALSE;
+ }
+ if (!strcmp(s->Phone.Data.ModelInfo->model,"3330") && s->Phone.Data.VerNum<=4.50) {
+ if (Note->Type!=GSM_CAL_REMINDER) Reminder3310 = FALSE;
+ }
+ if (Reminder3310) {
+ req[22]++; /* one additional char */
+ req[current++] = 0x01; /* we use now subset 1 */
+ for (i=0;i<((int)UnicodeLength(Note->Entries[Text].Text));i++) {
+ j = EncodeWithUTF8Alphabet(Note->Entries[Text].Text[i*2]*256+Note->Entries[Text].Text[i*2+1],req+current);
+ if (j > 1) {
+ req[23]= 0x03; /* use subset 3 */
+ req[22]+=j-1; /* few additional chars */
+ current+=j;
+ } else {
+ current+=DecodeWithUnicodeAlphabet(((gammu_char_t)(Note->Entries[Text].Text[i*2]*256+Note->Entries[Text].Text[i*2+1])),req+current);
+ }
+ }
+ }
+ }
+ if (!Reminder3310) {
+ memcpy(req+current,DecodeUnicodeString(Note->Entries[Text].Text),UnicodeLength(Note->Entries[Text].Text));
+ current += UnicodeLength(Note->Entries[Text].Text);
+ }
+ }
+ } else req[22] = 0x00;
+
+ if (Note->Type == GSM_CAL_CALL) {
+ if (Phone != -1) {
+ req[current++] = UnicodeLength(Note->Entries[Phone].Text);
+ memcpy(req+current,DecodeUnicodeString(Note->Entries[Phone].Text),UnicodeLength(Note->Entries[Phone].Text));
+ current += UnicodeLength(Note->Entries[Phone].Text);
+ } else req[current++] = 0x00;
+ }
+
+ req[6] = current - 8;
+
+ smprintf(s, "Writing calendar note\n");
+ return GSM_WaitFor (s, req, current, 0x13, 4, ID_SetCalendarNote);
+}
+
+static GSM_Error N6110_ReplyDeleteCalendar(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "Deleting calendar note: ");
+ switch (msg->Buffer[4]) {
+ case 0x01:
+ smprintf(s, "done OK\n");
+ return ERR_NONE;
+ case 0x81:
+ smprintf(s,"during editing notes in phone menu\n");
+ return ERR_INSIDEPHONEMENU;
+ case 0x93:
+ smprintf(s, "Can't be done - too high location ?\n");
+ return ERR_INVALIDLOCATION;
+ default:
+ smprintf(s, "unknown ERROR %i\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+}
+
+static GSM_Error N6110_DeleteCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x68,
+ 0x00}; /* Location */
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOCALENDAR)) return ERR_NOTSUPPORTED;
+
+ req[4] = Note->Location;
+
+ smprintf(s, "Deleting calendar note\n");
+ return GSM_WaitFor (s, req, 5, 0x13, 5, ID_DeleteCalendarNote);
+}
+
+/* for example: "Euro_char" text */
+static void Decode3310Subset3(int j, GSM_Protocol_Message *msg, GSM_Phone_Data *Data)
+{
+ gammu_char_t wc;
+ int len = 0,i,w;
+ GSM_CalendarEntry *Entry = Data->Cal;
+
+ i = j;
+ while (i!=msg->Buffer[23]) {
+ w = DecodeWithUTF8Alphabet(msg->Buffer+24+i,&wc,msg->Buffer[23]-i);
+ if (w>1) {
+ i+=w;
+ } else {
+ EncodeWithUnicodeAlphabet(msg->Buffer+24+i,&wc);
+ }
+ Entry->Entries[Entry->EntriesNum].Text[len++] = (wc >> 8) & 0xff;
+ Entry->Entries[Entry->EntriesNum].Text[len++] = wc & 0xff;
+ i++;
+ }
+ Entry->Entries[Entry->EntriesNum].Text[len++] = 0;
+ Entry->Entries[Entry->EntriesNum].Text[len++] = 0;
+}
+
+/* For example: "a with : above" char */
+static void Decode3310Subset2(int j, GSM_Protocol_Message *msg, GSM_Phone_Data *Data)
+{
+ int len = 0;
+ int i;
+ GSM_CalendarEntry *Entry = Data->Cal;
+
+ i = j;
+ while (i!=msg->Buffer[23]) {
+ Entry->Entries[Entry->EntriesNum].Text[len++] = 0x00;
+ Entry->Entries[Entry->EntriesNum].Text[len++] = msg->Buffer[24+i];
+ i++;
+ }
+ Entry->Entries[Entry->EntriesNum].Text[len++] = 0;
+ Entry->Entries[Entry->EntriesNum].Text[len++] = 0;
+}
+
+static GSM_Error N6110_ReplyGetNextCalendar(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int i = 0;
+ gboolean SpecialSubSet = FALSE;
+ GSM_CalendarEntry *Entry = s->Phone.Data.Cal;
+
+ switch (msg->Buffer[4]) {
+ case 0x01:
+ smprintf(s, "Calendar note received\n");
+ switch (msg->Buffer[8]) {
+ case 0x01: Entry->Type = GSM_CAL_REMINDER; break;
+ case 0x02: Entry->Type = GSM_CAL_CALL; break;
+ case 0x03: Entry->Type = GSM_CAL_MEETING; break;
+ case 0x04: Entry->Type = GSM_CAL_BIRTHDAY; break;
+ case 0x05: Entry->Type = GSM_CAL_T_ATHL; break;
+ case 0x06: Entry->Type = GSM_CAL_T_BALL; break;
+ case 0x07: Entry->Type = GSM_CAL_T_CYCL; break;
+ case 0x08: Entry->Type = GSM_CAL_T_BUDO; break;
+ case 0x09: Entry->Type = GSM_CAL_T_DANC; break;
+ case 0x0a: Entry->Type = GSM_CAL_T_EXTR; break;
+ case 0x0b: Entry->Type = GSM_CAL_T_FOOT; break;
+ case 0x0c: Entry->Type = GSM_CAL_T_GOLF; break;
+ case 0x0d: Entry->Type = GSM_CAL_T_GYM; break;
+ case 0x0e: Entry->Type = GSM_CAL_T_HORS; break;
+ case 0x0f: Entry->Type = GSM_CAL_T_HOCK; break;
+ case 0x10: Entry->Type = GSM_CAL_T_RACE; break;
+ case 0x11: Entry->Type = GSM_CAL_T_RUGB; break;
+ case 0x12: Entry->Type = GSM_CAL_T_SAIL; break;
+ case 0x13: Entry->Type = GSM_CAL_T_STRE; break;
+ case 0x14: Entry->Type = GSM_CAL_T_SWIM; break;
+ case 0x15: Entry->Type = GSM_CAL_T_TENN; break;
+ case 0x16: Entry->Type = GSM_CAL_T_TRAV; break;
+ case 0x17: Entry->Type = GSM_CAL_T_WINT; break;
+ default :
+ smprintf(s, "Unknown note type %i\n",msg->Buffer[8]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+#ifdef DEBUG
+ switch (msg->Buffer[8]) {
+ case 0x01: smprintf(s, "Reminder\n"); break;
+ case 0x02: smprintf(s, "Call\n"); break;
+ case 0x03: smprintf(s, "Meeting\n"); break;
+ case 0x04: smprintf(s, "Birthday\n"); break;
+ }
+#endif
+ Entry->EntriesNum = 0;
+
+ NOKIA_DecodeDateTime(s, msg->Buffer+9, &Entry->Entries[0].Date, TRUE, FALSE);
+ smprintf(s, "Time : %02i-%02i-%04i %02i:%02i:%02i\n",
+ Entry->Entries[0].Date.Day,Entry->Entries[0].Date.Month,Entry->Entries[0].Date.Year,
+ Entry->Entries[0].Date.Hour,Entry->Entries[0].Date.Minute,Entry->Entries[0].Date.Second);
+ Entry->Entries[0].EntryType = CAL_START_DATETIME;
+ Entry->EntriesNum++;
+
+ NOKIA_DecodeDateTime(s, msg->Buffer+16, &Entry->Entries[1].Date, TRUE, FALSE);
+ if (Entry->Entries[1].Date.Year!=0) {
+ smprintf(s, "Alarm : %02i-%02i-%04i %02i:%02i:%02i\n",
+ Entry->Entries[1].Date.Day,Entry->Entries[1].Date.Month,Entry->Entries[1].Date.Year,
+ Entry->Entries[1].Date.Hour,Entry->Entries[1].Date.Minute,Entry->Entries[1].Date.Second);
+ Entry->Entries[1].EntryType = CAL_TONE_ALARM_DATETIME;
+ Entry->EntriesNum++;
+ } else {
+ smprintf(s, "No alarm\n");
+ }
+
+ if (Entry->Type == GSM_CAL_BIRTHDAY) {
+ Entry->Entries[Entry->EntriesNum].EntryType = CAL_REPEAT_FREQUENCY;
+ Entry->Entries[Entry->EntriesNum].Number = 1;
+ Entry->EntriesNum++;
+ Entry->Entries[Entry->EntriesNum].EntryType = CAL_REPEAT_DAY;
+ Entry->Entries[Entry->EntriesNum].Number = Entry->Entries[0].Date.Day;
+ Entry->EntriesNum++;
+ Entry->Entries[Entry->EntriesNum].EntryType = CAL_REPEAT_MONTH;
+ Entry->Entries[Entry->EntriesNum].Number = Entry->Entries[0].Date.Month;
+ Entry->EntriesNum++;
+ }
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_CAL52) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_CAL82)) {
+ memcpy(Entry->Entries[Entry->EntriesNum].Text,msg->Buffer+24,msg->Buffer[23]);
+ Entry->Entries[Entry->EntriesNum].Text[msg->Buffer[23] ]=0;
+ Entry->Entries[Entry->EntriesNum].Text[msg->Buffer[23]+1]=0;
+ } else {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_CAL33)) {
+ /* first char is subset for 33xx and reminders */
+ if (Entry->Type == GSM_CAL_REMINDER) {
+ i=1;
+ smprintf(s, "Subset %i in reminder note !\n",msg->Buffer[24]);
+ }
+ SpecialSubSet = TRUE;
+ switch (msg->Buffer[24]) {
+ case 2 : Decode3310Subset2(i,msg,&s->Phone.Data); break;
+ case 3 : Decode3310Subset3(i,msg,&s->Phone.Data); break;
+ default : SpecialSubSet = FALSE; break;
+ }
+ }
+ if (!SpecialSubSet) {
+ N6110_EncodeUnicode(s,Entry->Entries[Entry->EntriesNum].Text,msg->Buffer+24+i,msg->Buffer[23]-i);
+ }
+ }
+ smprintf(s, "Text \"%s\"\n",DecodeUnicodeString(Entry->Entries[Entry->EntriesNum].Text));
+ if (msg->Buffer[23] != 0x00) {
+ Entry->Entries[Entry->EntriesNum].EntryType = CAL_TEXT;
+ Entry->EntriesNum++;
+ }
+
+ if (Entry->Type == GSM_CAL_CALL) {
+ EncodeUnicode(Entry->Entries[Entry->EntriesNum].Text,msg->Buffer+24+msg->Buffer[23]+1,msg->Buffer[24+msg->Buffer[23]]);
+ smprintf(s, "Phone : \"%s\"\n",DecodeUnicodeString(Entry->Entries[Entry->EntriesNum].Text));
+ if (msg->Buffer[24+msg->Buffer[23]] != 0x00) {
+ Entry->Entries[Entry->EntriesNum].EntryType = CAL_PHONE;
+ Entry->EntriesNum++;
+ }
+ }
+ return ERR_NONE;
+ case 0x93:
+ smprintf(s, "Can't get calendar note - too high location?\n");
+ return ERR_INVALIDLOCATION;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6110_GetNextCalendarNote(GSM_StateMachine *s, GSM_CalendarEntry *Note, gboolean start)
+{
+ int Text, Time, Alarm, Phone, EndTime, Location;
+ GSM_Error error;
+ GSM_DateTime date_time;
+ GSM_Phone_N6110Data *Priv = &s->Phone.Data.Priv.N6110;
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x66,
+ 0x00}; /* Location */
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOCALENDAR)) return ERR_NOTSUPPORTED;
+
+ if (start) {
+ Priv->LastCalendarPos = 1;
+ } else {
+ Priv->LastCalendarPos++;
+ }
+
+ Note->Location = Priv->LastCalendarPos;
+ req[4] = Priv->LastCalendarPos;
+
+ s->Phone.Data.Cal=Note;
+ smprintf(s, "Getting calendar note\n");
+ error=GSM_WaitFor (s, req, 5, 0x13, 4, ID_GetCalendarNote);
+
+ GSM_CalendarFindDefaultTextTimeAlarmPhone(Note, &Text, &Time, &Alarm, &Phone, &EndTime, &Location);
+ /* 2090 year is set for example in 3310 */
+ if (error == ERR_NONE && Note->Entries[Time].Date.Year == 2090) {
+ error=N6110_GetDateTime(s, &date_time);
+ if (error == ERR_NONE) Note->Entries[Time].Date.Year = date_time.Year;
+ }
+ if (error == ERR_INVALIDLOCATION) error = ERR_EMPTY;
+ return error;
+}
+
+GSM_Error N6110_ReplyUSSDInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ unsigned char buffer[2000];
+ int tmp;
+ GSM_USSDMessage ussd;
+
+ tmp=GSM_UnpackEightBitsToSeven(0, msg->Buffer[7], 82, msg->Buffer+8, buffer);
+ buffer[tmp] = 0;
+
+ smprintf(s, "USSD reply: \"%s\"\n",buffer);
+
+ if (s->Phone.Data.EnableIncomingUSSD && s->User.IncomingUSSD!=NULL) {
+ EncodeUnicode(ussd.Text,buffer,strlen(buffer));
+ /**
+ * @todo: Should determine status.
+ */
+ ussd.Status = USSD_Unknown;
+ s->User.IncomingUSSD(s, &ussd, s->User.IncomingUSSDUserData);
+ }
+
+ return ERR_NONE;
+}
+
+GSM_Error N6110_AnswerCall(GSM_StateMachine *s, int ID, gboolean all)
+{
+ GSM_Error error;
+ unsigned char req1[] = {N6110_FRAME_HEADER, 0x42, 0x05, 0x01,
+ 0x07, 0xa2, 0x88, 0x81, 0x21, 0x15, 0x63, 0xa8,
+ 0x00, 0x00, 0x07, 0xa3, 0xb8, 0x81, 0x20, 0x15,
+ 0x63, 0x80};
+
+ if (!all) {
+ smprintf(s, "Answering call part 1\n");
+ error = GSM_WaitFor (s, req1, 24, 0x01, 5, ID_AnswerCall);
+ if (error != ERR_NONE) return error;
+ return DCT3DCT4_AnswerCall(s,ID);
+ }
+
+ return DCT3_AnswerAllCalls(s);
+}
+
+static GSM_Error N6110_DialVoice(GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber)
+{
+ unsigned int pos = 4;
+ unsigned char req[100] = {N6110_FRAME_HEADER,0x01,
+ 0x0c}; /* Length of number */
+
+ if (ShowNumber == GSM_CALL_DefaultNumberPresence) return DCT3_DialVoice(s,number,ShowNumber);
+
+ req[pos++] = strlen(number);
+ memcpy(req+pos,number,strlen(number));
+ pos += strlen(number);
+ req[pos++] = 0x05; /* call type: voice - 0x05, data - 0x01 */
+ req[pos++] = 0x01;
+ req[pos++] = 0x01;
+ req[pos++] = 0x05;
+ req[pos++] = 0x81;
+ switch (ShowNumber) {
+ case GSM_CALL_HideNumber:
+ req[pos++] = 0x02;
+ break;
+ case GSM_CALL_ShowNumber:
+ req[pos++] = 0x03;
+ break;
+ case GSM_CALL_DefaultNumberPresence:
+ req[pos++] = 0x01;
+ break;
+ }
+ req[pos++] = 0x00;
+ req[pos++] = 0x00;
+
+ smprintf(s, "Making voice call\n");
+ return GSM_WaitFor (s, req, pos, 0x01, 4, ID_DialVoice);
+}
+
+GSM_Error N6110_UnholdCall(GSM_StateMachine *s, int ID)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x24, 0x00, 0x02};
+
+ req[4] = (unsigned char)ID;
+ s->Phone.Data.CallID = ID;
+
+ smprintf(s, "Unholding call\n");
+ return GSM_WaitFor (s, req, 6, 0x01, 4, ID_UnholdCall);
+}
+
+GSM_Error N6110_HoldCall(GSM_StateMachine *s, int ID)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x22, 0x00, 0x00};
+
+ req[4] = (unsigned char)ID;
+ s->Phone.Data.CallID = ID;
+
+ smprintf(s, "Unholding call\n");
+ return GSM_WaitFor (s, req, 6, 0x01, 4, ID_HoldCall);
+}
+
+/* Joining selected call to current (and making conference) */
+GSM_Error N6110_ConferenceCall(GSM_StateMachine *s, int ID)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x28, 0x00, 0x01};
+
+ req[4] = (unsigned char)ID;
+ s->Phone.Data.CallID = ID;
+
+ smprintf(s, "Conference call\n");
+ return GSM_WaitFor (s, req, 6, 0x01, 4, ID_ConferenceCall);
+}
+
+/* Removing selected call from conference and making private call with it
+ * (conference call is on hold) */
+GSM_Error N6110_SplitCall(GSM_StateMachine *s, int ID)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x2A, 0x00, 0x01};
+
+ req[4] = (unsigned char)ID;
+ s->Phone.Data.CallID = ID;
+
+ smprintf(s, "Split call\n");
+ return GSM_WaitFor (s, req, 6, 0x01, 4, ID_SplitCall);
+}
+
+/* This probably need more investigation */
+GSM_Error N6110_SwitchCall(GSM_StateMachine *s, int ID, gboolean next)
+{
+/* unsigned char req[] = {N6110_FRAME_HEADER, 0x20}; calls info */
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x26, 0x00};
+
+ s->Phone.Data.CallID = ID;
+
+ if (next) {
+ smprintf(s, "Switch call\n");
+ return GSM_WaitFor (s, req, 4, 0x01, 4, ID_SwitchCall);
+ } else {
+ req[4] = (unsigned char)ID;
+
+ smprintf(s, "Switch call\n");
+ return GSM_WaitFor (s, req, 5, 0x01, 4, ID_SwitchCall);
+ }
+}
+
+/* This probably need more investigation */
+GSM_Error N6110_TransferCall(GSM_StateMachine *s, int ID, gboolean next)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x2C, 0x00};
+
+ s->Phone.Data.CallID = ID;
+
+ if (next) {
+ smprintf(s, "Transfer call\n");
+ return GSM_WaitFor (s, req, 4, 0x01, 4, ID_TransferCall);
+ } else {
+ req[4] = (unsigned char)ID;
+
+ smprintf(s, "Transfer call\n");
+ return GSM_WaitFor (s, req, 5, 0x01, 4, ID_TransferCall);
+ }
+}
+
+static GSM_Reply_Function N6110ReplyFunctions[] = {
+ {N6110_ReplyCallInfo, "\x01",0x03,0x02,ID_IncomingFrame },
+ {N6110_ReplyCallInfo, "\x01",0x03,0x03,ID_IncomingFrame },
+ {N6110_ReplyCallInfo, "\x01",0x03,0x04,ID_IncomingFrame },
+ {N6110_ReplyCallInfo, "\x01",0x03,0x05,ID_IncomingFrame },
+ {N6110_ReplyCallInfo, "\x01",0x03,0x07,ID_AnswerCall },
+ {N6110_ReplyCallInfo, "\x01",0x03,0x07,ID_IncomingFrame },
+ {N6110_ReplyCallInfo, "\x01",0x03,0x09,ID_CancelCall },
+ {N6110_ReplyCallInfo, "\x01",0x03,0x09,ID_IncomingFrame },
+ {N6110_ReplyCallInfo, "\x01",0x03,0x0A,ID_IncomingFrame },
+ {N6110_ReplyCallInfo, "\x01",0x03,0x23,ID_HoldCall },
+ {N6110_ReplyCallInfo, "\x01",0x03,0x23,ID_IncomingFrame },
+ {N6110_ReplyCallInfo, "\x01",0x03,0x25,ID_UnholdCall },
+ {N6110_ReplyCallInfo, "\x01",0x03,0x25,ID_IncomingFrame },
+ {N6110_ReplyCallInfo, "\x01",0x03,0x27,ID_IncomingFrame },
+ {N6110_ReplyCallInfo, "\x01",0x03,0x29,ID_ConferenceCall },
+ {N6110_ReplyCallInfo, "\x01",0x03,0x29,ID_IncomingFrame },
+ {N6110_ReplyCallInfo, "\x01",0x03,0x2B,ID_SplitCall },
+ {N6110_ReplyCallInfo, "\x01",0x03,0x2B,ID_IncomingFrame },
+ {N6110_ReplySendDTMF, "\x01",0x03,0x40,ID_SendDTMF },
+ {NoneReply, "\x01",0x03,0x40,ID_DialVoice },
+ {NoneReply, "\x01",0x03,0x40,ID_IncomingFrame },
+ {NoneReply, "\x01",0x03,0x43,ID_AnswerCall },
+ {N6110_ReplySendDTMF, "\x01",0x03,0x51,ID_SendDTMF },
+
+ {DCT3_ReplySendSMSMessage, "\x02",0x03,0x02,ID_IncomingFrame },
+ {DCT3_ReplySendSMSMessage, "\x02",0x03,0x03,ID_IncomingFrame },
+ {N6110_ReplyIncomingSMS, "\x02",0x03,0x10,ID_IncomingFrame },
+#ifdef GSM_ENABLE_CELLBROADCAST
+ {DCT3_ReplySetIncomingCB, "\x02",0x03,0x21,ID_SetIncomingCB },
+ {DCT3_ReplySetIncomingCB, "\x02",0x03,0x22,ID_SetIncomingCB },
+ {DCT3_ReplyIncomingCB, "\x02",0x03,0x23,ID_IncomingFrame },
+#endif
+ {DCT3_ReplySetSMSC, "\x02",0x03,0x31,ID_SetSMSC },
+ {DCT3_ReplyGetSMSC, "\x02",0x03,0x34,ID_GetSMSC },
+ {DCT3_ReplyGetSMSC, "\x02",0x03,0x35,ID_GetSMSC },
+ {DCT3_ReplyWaitSMSC, "\x02",0x03,0xc9,ID_IncomingFrame },
+
+ {N6110_ReplyGetMemory, "\x03",0x03,0x02,ID_GetMemory },
+ {N6110_ReplyGetMemory, "\x03",0x03,0x03,ID_GetMemory },
+ {N6110_ReplySetMemory, "\x03",0x03,0x05,ID_SetMemory },
+ {N6110_ReplySetMemory, "\x03",0x03,0x06,ID_SetMemory },
+ {N6110_ReplyGetMemoryStatus, "\x03",0x03,0x08,ID_GetMemoryStatus },
+ {N6110_ReplyGetMemoryStatus, "\x03",0x03,0x09,ID_GetMemoryStatus },
+ {N6110_ReplyGetCallerLogo, "\x03",0x03,0x11,ID_GetBitmap },
+ {N6110_ReplyGetCallerLogo, "\x03",0x03,0x12,ID_GetBitmap },
+ {N6110_ReplySetCallerLogo, "\x03",0x03,0x14,ID_SetBitmap },
+ {N6110_ReplySetCallerLogo, "\x03",0x03,0x15,ID_SetBitmap },
+ {N6110_ReplyGetSpeedDial, "\x03",0x03,0x17,ID_GetSpeedDial },
+ {N6110_ReplyGetSpeedDial, "\x03",0x03,0x18,ID_GetSpeedDial },
+ /* 0x1A, 0x1B - reply set speed dial */
+
+ {N6110_ReplyGetStatus, "\x04",0x03,0x02,ID_GetSignalQuality },
+ {N6110_ReplyGetStatus, "\x04",0x03,0x02,ID_GetBatteryCharge },
+
+ {N6110_ReplyGetProfileFeature, "\x05",0x03,0x0d,ID_GetProfile },
+ {N6110_ReplySetProfileFeature, "\x05",0x03,0x11,ID_SetProfile },
+ {N6110_ReplySetProfileFeature, "\x05",0x03,0x12,ID_SetProfile },
+ {N6110_ReplyGetProfileFeature, "\x05",0x03,0x14,ID_GetProfile },
+ {N6110_ReplyGetPhoneLanguage, "\x05",0x03,0x14,ID_GetLanguage },
+ {N6110_ReplyGetProfileFeature, "\x05",0x03,0x15,ID_GetProfile },
+ {N6110_ReplyGetPhoneLanguage, "\x05",0x03,0x15,ID_GetLanguage },
+ {N6110_ReplyGetStartup, "\x05",0x03,0x17,ID_GetBitmap },
+ {N6110_ReplySetStartup, "\x05",0x03,0x19,ID_SetBitmap },
+ {N6110_ReplyGetProfileFeature, "\x05",0x03,0x1b,ID_GetProfile },
+ {N61_91_ReplySetOpLogo, "\x05",0x03,0x31,ID_SetBitmap },
+ {N61_91_ReplySetOpLogo, "\x05",0x03,0x32,ID_SetBitmap },
+ {N6110_ReplyGetOpLogo, "\x05",0x03,0x34,ID_GetBitmap },
+ {N6110_ReplySetRingtone, "\x05",0x03,0x37,ID_SetRingtone },
+ {N6110_ReplySetRingtone, "\x05",0x03,0x38,ID_SetRingtone },
+
+ {DCT3DCT4_ReplyCallDivert, "\x06",0x03,0x02,ID_Divert },
+ {DCT3DCT4_ReplyCallDivert, "\x06",0x03,0x03,ID_Divert },
+ {N6110_ReplyUSSDInfo, "\x06",0x03,0x05,ID_IncomingFrame },
+ {NoneReply, "\x06",0x03,0x06,ID_IncomingFrame },/* incoming call divert info */
+
+ {N6110_ReplyGetSecurityStatus, "\x08",0x03,0x08,ID_GetSecurityStatus },
+ {N6110_ReplyEnterSecurityCode, "\x08",0x03,0x0b,ID_EnterSecurityCode },
+ {N6110_ReplyEnterSecurityCode, "\x08",0x03,0x0c,ID_EnterSecurityCode },
+
+ {DCT3_ReplySIMLogin, "\x09",0x03,0x80,ID_IncomingFrame },
+ {DCT3_ReplySIMLogout, "\x09",0x03,0x81,ID_IncomingFrame },
+
+ {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_GetNetworkInfo },
+ {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_IncomingFrame },
+
+ {N6110_ReplyGetDisplayStatus, "\x0D",0x03,0x52,ID_GetDisplayStatus },
+ {N6110_ReplyGetDisplayStatus, "\x0D",0x03,0x52,ID_IncomingFrame },
+
+ {DCT3_ReplySetDateTime, "\x11",0x03,0x61,ID_SetDateTime },
+ {DCT3_ReplyGetDateTime, "\x11",0x03,0x63,ID_GetDateTime },
+ {DCT3_ReplySetAlarm, "\x11",0x03,0x6C,ID_SetAlarm },
+ {DCT3_ReplyGetAlarm, "\x11",0x03,0x6E,ID_GetAlarm },
+
+ {N6110_ReplyAddCalendar, "\x13",0x03,0x65,ID_SetCalendarNote },
+ {N6110_ReplyAddCalendar, "\x13",0x03,0x65,ID_IncomingFrame },
+ {N6110_ReplyGetNextCalendar, "\x13",0x03,0x67,ID_GetCalendarNote },
+ {N6110_ReplyDeleteCalendar, "\x13",0x03,0x69,ID_DeleteCalendarNote },
+ {N6110_ReplyDeleteCalendar, "\x13",0x03,0x69,ID_IncomingFrame },
+
+ {N6110_ReplySaveSMSMessage, "\x14",0x03,0x05,ID_SaveSMSMessage },
+ {N6110_ReplySaveSMSMessage, "\x14",0x03,0x06,ID_SaveSMSMessage },
+ {N6110_ReplyGetSMSMessage, "\x14",0x03,0x08,ID_GetSMSMessage },
+ {N6110_ReplyGetSMSMessage, "\x14",0x03,0x09,ID_GetSMSMessage },
+ {DCT3_ReplyDeleteSMSMessage, "\x14",0x03,0x0B,ID_DeleteSMSMessage },
+ {DCT3_ReplyDeleteSMSMessage, "\x14",0x03,0x0C,ID_DeleteSMSMessage },
+ {N6110_ReplyGetSMSStatus, "\x14",0x03,0x37,ID_GetSMSStatus },
+ {N6110_ReplyGetSMSStatus, "\x14",0x03,0x38,ID_GetSMSStatus },
+
+ {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x01,ID_EnableConnectFunc },
+ {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x02,ID_EnableConnectFunc },
+ {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x04,ID_DisableConnectFunc },
+ {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x05,ID_DisableConnectFunc },
+ {DCT3_ReplyGetWAPBookmark, "\x3f",0x03,0x07,ID_GetWAPBookmark },
+ {DCT3_ReplyGetWAPBookmark, "\x3f",0x03,0x08,ID_GetWAPBookmark },
+ {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0A,ID_SetWAPBookmark },
+ {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0B,ID_SetWAPBookmark },
+ {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0D,ID_DeleteWAPBookmark },
+ {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0E,ID_DeleteWAPBookmark },
+ {DCT3DCT4_ReplyGetActiveConnectSet,"\x3f",0x03,0x10,ID_GetConnectSet },
+ {DCT3DCT4_ReplySetActiveConnectSet,"\x3f",0x03,0x13,ID_SetConnectSet },
+ {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x16,ID_GetConnectSet },
+ {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x17,ID_GetConnectSet },
+ {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x19,ID_SetConnectSet },
+ {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x1A,ID_SetConnectSet },
+ {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x1C,ID_GetConnectSet },
+ {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x1D,ID_GetConnectSet },
+ {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x1F,ID_SetConnectSet },
+
+ {DCT3_ReplyEnableSecurity, "\x40",0x02,0x64,ID_EnableSecurity },
+ {N61_71_ReplyResetPhoneSettings, "\x40",0x02,0x65,ID_ResetPhoneSettings },
+ {DCT3_ReplyGetIMEI, "\x40",0x02,0x66,ID_GetIMEI },
+ {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_DialVoice },
+ {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_CancelCall },
+ {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_AnswerCall },
+ {DCT3_ReplyNetmonitor, "\x40",0x02,0x7E,ID_Netmonitor },
+ {DCT3_ReplyPlayTone, "\x40",0x02,0x8F,ID_PlayTone },
+ {N6110_ReplyGetRingtone, "\x40",0x02,0x9E,ID_GetRingtone },
+ {N6110_ReplySetBinRingtone, "\x40",0x02,0xA0,ID_SetRingtone },
+ {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetHardware },
+ {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetPPM },
+ {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCA,ID_GetProductCode },
+ {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetManufactureMonth},
+ {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetOriginalIMEI },
+
+ {N6110_ReplyGetSetPicture, "\x47",0x03,0x02,ID_GetBitmap },
+ {N6110_ReplyGetSetPicture, "\x47",0x03,0x04,ID_SetBitmap },
+ {N6110_ReplyGetSetPicture, "\x47",0x03,0x05,ID_SetBitmap },
+ {N6110_ReplyGetSetPicture, "\x47",0x03,0x06,ID_GetBitmap },
+
+ {N6110_ReplyGetMagicBytes, "\x64",0x00,0x00,ID_MakeAuthentication },
+
+ {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetModel },
+ {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetFirmware },
+ {DCT3_ReplyPressKey, "\xD2",0x02,0x46,ID_PressKey },
+ {DCT3_ReplyPressKey, "\xD2",0x02,0x47,ID_PressKey },
+
+ {NULL, "\x00",0x00,0x00,ID_None }
+};
+
+GSM_Phone_Functions N6110Phone = {
+ "2100|3210|3310|3330|3390|3390b|3410|3610|5110|5110i|5130|5190|5210|5510|6110|6130|6150|6190|8210|8250|8290|8850|8855|8890",
+ N6110ReplyFunctions,
+ NOTSUPPORTED, /* Install */
+ N6110_Initialise,
+ PHONE_Terminate,
+ GSM_DispatchMessage,
+ N6110_ShowStartInfo,
+ NOKIA_GetManufacturer,
+ DCT3DCT4_GetModel,
+ DCT3DCT4_GetFirmware,
+ DCT3_GetIMEI,
+ DCT3_GetOriginalIMEI,
+ DCT3_GetManufactureMonth,
+ DCT3_GetProductCode,
+ DCT3_GetHardware,
+ DCT3_GetPPM,
+ NOTSUPPORTED, /* GetSIMIMSI */
+ N6110_GetDateTime,
+ N6110_SetDateTime,
+ N6110_GetAlarm,
+ N6110_SetAlarm,
+ NOTSUPPORTED, /* GetLocale */
+ NOTSUPPORTED, /* SetLocale */
+ DCT3_PressKey,
+ DCT3_Reset,
+ N61_71_ResetPhoneSettings,
+ N6110_EnterSecurityCode,
+ N6110_GetSecurityStatus,
+ N6110_GetDisplayStatus,
+ NOTIMPLEMENTED, /* SetAutoNetworkLogin */
+ N6110_GetBatteryCharge,
+ N6110_GetSignalQuality,
+ DCT3_GetNetworkInfo,
+ NOTSUPPORTED, /* GetCategory */
+ NOTSUPPORTED, /* AddCategory */
+ NOTSUPPORTED, /* GetCategoryStatus */
+ N6110_GetMemoryStatus,
+ N6110_GetMemory,
+ NOTIMPLEMENTED, /* GetNextMemory */
+ N6110_SetMemory,
+ NOTIMPLEMENTED, /* AddMemory */
+ N6110_DeleteMemory,
+ NOTIMPLEMENTED, /* DeleteAllMemory */
+ N6110_GetSpeedDial,
+ NOTIMPLEMENTED, /* SetSpeedDial */
+ DCT3_GetSMSC,
+ DCT3_SetSMSC,
+ DCT3_GetSMSStatus,
+ N6110_GetSMSMessage,
+ N6110_GetNextSMSMessage,
+ N6110_SetSMS,
+ N6110_AddSMS,
+ N6110_DeleteSMSMessage,
+ DCT3_SendSMSMessage,
+ NOTSUPPORTED, /* SendSavedSMS */
+ NOTSUPPORTED, /* SetFastSMSSending */
+ NOKIA_SetIncomingSMS,
+ DCT3_SetIncomingCB,
+ PHONE_GetSMSFolders,
+ NOTSUPPORTED, /* AddSMSFolder */
+ NOTSUPPORTED, /* DeleteSMSFolder */
+ N6110_DialVoice,
+ NOTIMPLEMENTED, /* DialService */
+ N6110_AnswerCall,
+ DCT3_CancelCall,
+ N6110_HoldCall,
+ N6110_UnholdCall,
+ N6110_ConferenceCall,
+ N6110_SplitCall,
+ N6110_TransferCall,
+ N6110_SwitchCall,
+ DCT3DCT4_GetCallDivert,
+ DCT3DCT4_SetCallDivert,
+ DCT3DCT4_CancelAllDiverts,
+ NOKIA_SetIncomingCall,
+ NOKIA_SetIncomingUSSD,
+ DCT3DCT4_SendDTMF,
+ N6110_GetRingtone,
+ N6110_SetRingtone,
+ NOTSUPPORTED, /* GetRingtonesInfo */
+ NOTSUPPORTED, /* DeleteUserRingtones */
+ DCT3_PlayTone,
+ DCT3_GetWAPBookmark,
+ DCT3_SetWAPBookmark,
+ DCT3_DeleteWAPBookmark,
+ DCT3_GetWAPSettings,
+ DCT3_SetWAPSettings,
+ NOTSUPPORTED, /* GetSyncMLSettings */
+ NOTSUPPORTED, /* SetSyncMLSettings */
+ NOTSUPPORTED, /* GetChatSettings */
+ NOTSUPPORTED, /* SetChatSettings */
+ NOTSUPPORTED, /* GetMMSSettings */
+ NOTSUPPORTED, /* SetMMSSettings */
+ NOTSUPPORTED, /* GetMMSFolders */
+ NOTSUPPORTED, /* GetNextMMSFileInfo */
+ N6110_GetBitmap,
+ N6110_SetBitmap,
+ NOTSUPPORTED, /* GetToDoStatus */
+ NOTSUPPORTED, /* GetToDo */
+ NOTSUPPORTED, /* GetNextToDo */
+ NOTSUPPORTED, /* SetToDo */
+ NOTSUPPORTED, /* AddToDo */
+ NOTSUPPORTED, /* DeleteToDo */
+ NOTSUPPORTED, /* DeleteAllToDo */
+ NOTIMPLEMENTED, /* GetCalendarStatus */
+ NOTIMPLEMENTED, /* GetCalendar */
+ N6110_GetNextCalendarNote,
+ NOTIMPLEMENTED, /* SetCalendar */
+ N6110_AddCalendarNote,
+ N6110_DeleteCalendarNote,
+ NOTIMPLEMENTED, /* DeleteAllCalendar */
+ NOTSUPPORTED, /* GetCalendarSettings */
+ NOTSUPPORTED, /* SetCalendarSettings */
+ NOTSUPPORTED, /* GetNoteStatus */
+ NOTSUPPORTED, /* GetNote */
+ NOTSUPPORTED, /* GetNextNote */
+ NOTSUPPORTED, /* SetNote */
+ NOTSUPPORTED, /* AddNote */
+ NOTSUPPORTED, /* DeleteNote */
+ NOTSUPPORTED, /* DeleteAllNotes */
+ N6110_GetProfile,
+ N6110_SetProfile,
+ NOTSUPPORTED, /* GetFMStation */
+ NOTSUPPORTED, /* SetFMStation */
+ NOTSUPPORTED, /* ClearFMStations */
+ NOTSUPPORTED, /* GetNextFileFolder */
+ NOTSUPPORTED, /* GetFolderListing */
+ NOTSUPPORTED, /* GetNextRootFolder */
+ NOTSUPPORTED, /* SetFileAttributes */
+ NOTSUPPORTED, /* GetFilePart */
+ NOTSUPPORTED, /* AddFile */
+ NOTSUPPORTED, /* SendFilePart */
+ NOTSUPPORTED, /* GetFileSystemStatus */
+ NOTSUPPORTED, /* DeleteFile */
+ NOTSUPPORTED, /* AddFolder */
+ NOTSUPPORTED, /* DeleteFolder */
+ NOTSUPPORTED, /* GetGPRSAccessPoint */
+ NOTSUPPORTED, /* SetGPRSAccessPoint */
+ NOTSUPPORTED, /* GetScreenshot */
+ NOTSUPPORTED, /* SetPower */
+ NOTSUPPORTED, /* PostConnect */
+ NONEFUNCTION /* PreAPICall */
+};
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct3/n6110.h b/libgammu/phone/nokia/dct3/n6110.h
new file mode 100644
index 0000000..fbf0cdf
--- /dev/null
+++ b/libgammu/phone/nokia/dct3/n6110.h
@@ -0,0 +1,43 @@
+/* (c) 2002-2003 by Marcin Wiacek */
+
+#ifndef n6110_h
+#define n6110_h
+
+#include <gammu-config.h>
+#include <gammu-message.h>
+#include "dct3comm.h"
+
+typedef enum {
+ N6110_Auto = 1,
+ N6110_Europe
+} N6110_Language;
+
+typedef struct {
+ unsigned char MagicBytes[4];
+ int LastCalendarPos;
+ DCT3_WAPSettings_Locations WAPLocations;
+
+ GSM_SMSMemoryStatus LastSMSStatus;
+ int LastSMSRead;
+
+ N6110_Language PhoneLanguage;
+} GSM_Phone_N6110Data;
+
+#ifndef GSM_USED_MBUS2
+# define GSM_USED_MBUS2
+#endif
+#ifndef GSM_USED_FBUS2
+# define GSM_USED_FBUS2
+#endif
+#ifndef GSM_USED_FBUS2IRDA
+# define GSM_USED_FBUS2IRDA
+#endif
+#ifndef GSM_USED_IRDAPHONET
+# define GSM_USED_IRDAPHONET
+#endif
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct3/n7110.c b/libgammu/phone/nokia/dct3/n7110.c
new file mode 100644
index 0000000..4a26597
--- /dev/null
+++ b/libgammu/phone/nokia/dct3/n7110.c
@@ -0,0 +1,1793 @@
+/* (c) 2001-2004 by Marcin Wiacek */
+/* based on some Markus Plail work from Gnokii (www.gnokii.org)
+ * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
+ * GNU GPL version 2 or later
+ */
+/* Due to a problem in the source code management, the names of some of
+ * the authors have unfortunately been lost. We do not mean to belittle
+ * their efforts and hope they will contact us to see their names
+ * properly added to the Copyright notice above.
+ * Having published their contributions under the terms of the GNU
+ * General Public License (GPL) [version 2], the Copyright of these
+ * authors will remain respected by adhering to the license they chose
+ * to publish their code under.
+ */
+
+#include <gammu-config.h>
+
+#ifdef GSM_ENABLE_NOKIA7110
+
+#include <string.h>
+#include <time.h>
+
+#include <gammu-nokia.h>
+
+#include "../../../misc/coding/coding.h"
+#include "../../../gsmcomon.h"
+#include "../../../service/gsmlogo.h"
+#include "../../../service/gsmring.h"
+#include "../../../service/gsmnet.h"
+#include "../../../service/sms/gsmmulti.h"
+#include "../../pfunc.h"
+#include "../nfunc.h"
+#include "../nfuncold.h"
+#include "n7110.h"
+#include "dct3func.h"
+
+static GSM_Error N7110_GetAlarm(GSM_StateMachine *s, GSM_Alarm *Alarm)
+{
+ return DCT3_GetAlarm(s, Alarm, 0x19);
+}
+
+static GSM_Error N7110_SetAlarm(GSM_StateMachine *s, GSM_Alarm *Alarm)
+{
+ return DCT3_SetAlarm(s, Alarm, 0x19);
+}
+
+static GSM_Error N7110_ReplyGetMemory(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "Phonebook entry received\n");
+
+ if (msg->Buffer[6] == 0x0f)
+ return N71_65_ReplyGetMemoryError(msg->Buffer[10], s);
+
+ return N71_65_DecodePhonebook(s, Data->Memory,Data->Bitmap,Data->SpeedDial,msg->Buffer+18,msg->Length-18,FALSE);
+}
+
+static GSM_Error N7110_GetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry)
+{
+ unsigned char req[] = {N7110_FRAME_HEADER, 0x07, 0x01, 0x01, 0x00, 0x01, 0x02,
+ 0x05, /* memory type */
+ 0x00, 0x00, /* location */
+ 0x00, 0x00};
+
+ req[9] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES);
+ if (req[9]==0xff) return ERR_NOTSUPPORTED;
+
+ if (entry->Location==0x00) return ERR_INVALIDLOCATION;
+
+ req[10] = entry->Location / 256;
+ req[11] = entry->Location % 256;
+
+ s->Phone.Data.Memory=entry;
+ smprintf(s, "Getting phonebook entry\n");
+ return GSM_WaitFor (s, req, 14, 0x03, 4, ID_GetMemory);
+}
+
+static GSM_Error N7110_ReplyGetMemoryStatus(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "Memory status received\n");
+ /* Quess ;-)) */
+ if (msg->Buffer[10]==0x10) {
+ Data->MemoryStatus->MemoryFree = msg->Buffer[14]*256 + msg->Buffer[15];
+ } else {
+ Data->MemoryStatus->MemoryFree = msg->Buffer[18];
+ }
+ smprintf(s, " Size : %i\n",Data->MemoryStatus->MemoryFree);
+ Data->MemoryStatus->MemoryUsed = msg->Buffer[16]*256 + msg->Buffer[17];
+ smprintf(s, " Used : %i\n",Data->MemoryStatus->MemoryUsed);
+ Data->MemoryStatus->MemoryFree -= Data->MemoryStatus->MemoryUsed;
+ smprintf(s, " Free : %i\n",Data->MemoryStatus->MemoryFree);
+ return ERR_NONE;
+}
+
+static GSM_Error N7110_GetMemoryStatus(GSM_StateMachine *s, GSM_MemoryStatus *Status)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x03, 0x02,
+ 0x05}; /* Memory type */
+
+ req[5] = NOKIA_GetMemoryType(s, Status->MemoryType,N71_65_MEMORY_TYPES);
+ if (req[5]==0xff) return ERR_NOTSUPPORTED;
+
+ s->Phone.Data.MemoryStatus=Status;
+ smprintf(s, "Getting memory status\n");
+ return GSM_WaitFor (s, req, 6, 0x03, 4, ID_GetMemoryStatus);
+}
+
+static void N7110_GetSMSLocation(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char *folderid, unsigned int *location)
+{
+ int ifolderid;
+
+ /* simulate flat SMS memory */
+ if (sms->Folder==0x00) {
+ ifolderid = sms->Location / GSM_PHONE_MAXSMSINFOLDER;
+ *folderid = (ifolderid + 1) * 0x08;
+ *location = sms->Location - ifolderid * GSM_PHONE_MAXSMSINFOLDER;
+ } else {
+ *folderid = sms->Folder * 0x08;
+ *location = sms->Location;
+ }
+ smprintf(s, "SMS folder %i & location %i -> 7110 folder %i & location %i\n",
+ sms->Folder,sms->Location,*folderid,*location);
+}
+
+static void N7110_SetSMSLocation(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char folderid, int location)
+{
+ sms->Folder = 0;
+ sms->Location = (folderid / 0x08 - 1) * GSM_PHONE_MAXSMSINFOLDER + location;
+ smprintf(s, "7110 folder %i & location %i -> SMS folder %i & location %i\n",
+ folderid,location,sms->Folder,sms->Location);
+}
+
+static GSM_Error N7110_ReplyGetSMSFolders(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int j,current=5;
+ unsigned char buffer[200];
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ switch (msg->Buffer[3]) {
+ case 0x7B:
+ smprintf(s, "Names for SMS folders received\n");
+ Data->SMSFolders->Number=msg->Buffer[4];
+ for (j=0;j<msg->Buffer[4];j++) {
+ smprintf(s, "Folder index: %02x",msg->Buffer[current]);
+ current++;
+ smprintf(s, ", folder name: \"");
+ CopyUnicodeString(buffer,msg->Buffer+current);
+ if ((UnicodeLength(buffer))>GSM_MAX_SMS_FOLDER_NAME_LEN) {
+ smprintf(s, "Too long text\n");
+ return ERR_UNKNOWNRESPONSE;
+ }
+ CopyUnicodeString(Data->SMSFolders->Folder[j].Name,buffer);
+ smprintf(s, "%s\"\n",DecodeUnicodeString(buffer));
+ current=current+2+UnicodeLength(buffer)*2;
+ Data->SMSFolders->Folder[j].InboxFolder = FALSE;
+ if (j==0) Data->SMSFolders->Folder[j].InboxFolder = TRUE;
+ Data->SMSFolders->Folder[j].OutboxFolder = FALSE;
+ /**
+ * @todo We should detect outbox here.
+ */
+ Data->SMSFolders->Folder[j].Memory = MEM_ME;
+ if (j==0 || j==1) Data->SMSFolders->Folder[j].InboxFolder = MEM_MT;
+ }
+ return ERR_NONE;
+ case 0x7C:
+ smprintf(s, "Security error ? No PIN ?\n");
+ return ERR_SECURITYERROR;
+ case 0xCA:
+ smprintf(s, "Wait a moment. Phone is during power on and busy now\n");
+ return ERR_SECURITYERROR;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N7110_GetSMSFolders(GSM_StateMachine *s, GSM_SMSFolders *folders)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x7A, 0x00, 0x00};
+
+ s->Phone.Data.SMSFolders=folders;
+ smprintf(s, "Getting SMS folders\n");
+ return GSM_WaitFor (s, req, 6, 0x14, 4, ID_GetSMSFolders);
+}
+
+static GSM_Error N7110_ReplyGetSMSFolderStatus(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int i;
+ GSM_Phone_N7110Data *Priv = &s->Phone.Data.Priv.N7110;
+
+ smprintf(s, "SMS folder status received\n");
+ Priv->LastSMSFolder.Number=msg->Buffer[4]*256+msg->Buffer[5];
+ smprintf(s, "Number of Entries: %i\n",Priv->LastSMSFolder.Number);
+ smprintf(s, "Locations: ");
+ for (i=0;i<Priv->LastSMSFolder.Number;i++) {
+ Priv->LastSMSFolder.Location[i]=msg->Buffer[6+(i*2)]*256+msg->Buffer[(i*2)+7];
+ if (Priv->LastSMSFolder.Location[i] > GSM_PHONE_MAXSMSINFOLDER) {
+ smprintf(s, "Increase GSM_PHONE_MAXSMSINFOLDER\n");
+ return ERR_UNKNOWNRESPONSE;
+ }
+ smprintf(s, "%i ",Priv->LastSMSFolder.Location[i]);
+ }
+ smprintf(s, "\n");
+ NOKIA_SortSMSFolderStatus(s, &Priv->LastSMSFolder);
+ return ERR_NONE;
+}
+
+static GSM_Error N7110_PrivGetSMSFolderStatus(GSM_StateMachine *s, int folderid)
+{
+ unsigned char req[] = {N7110_FRAME_HEADER, 0x6b,
+ 0x08, /* folderID */
+ 0x0F, 0x01};
+
+ req[4] = folderid;
+
+ smprintf(s, "Getting SMS folder status\n");
+ return GSM_WaitFor (s, req, 7, 0x14, 4, ID_GetSMSFolderStatus);
+}
+
+static GSM_Error N7110_GetSMSFolderStatus(GSM_StateMachine *s, int folderid)
+{
+ GSM_Error error;
+ int i;
+ GSM_NOKIASMSFolder folder;
+
+ error = N7110_PrivGetSMSFolderStatus(s,folderid);
+ /* 0x08 contais read Inbox, 0xf8 unread Inbox.
+ * we want all msg from Inbox, so read both 0x08 and 0xf8 */
+ if (folderid==0x08 && error==ERR_NONE) {
+ folder=s->Phone.Data.Priv.N7110.LastSMSFolder;
+ error = N7110_PrivGetSMSFolderStatus(s,0xf8);
+ if (error==ERR_NONE) {
+ for (i=0;i<folder.Number;i++) {
+ s->Phone.Data.Priv.N7110.LastSMSFolder.Location[s->Phone.Data.Priv.N7110.LastSMSFolder.Number++]=folder.Location[i];
+ }
+ }
+ }
+ return error;
+}
+
+static GSM_SMSMessageLayout N7110_SMSTemplate = {
+ 36 /* SMS Text */, 17 /* Phone number */,
+ 255 /* SMSC Number */, 15 /* TPDCS */,
+ 255 /* SendingDateTime */, 255 /* SMSCDateTime */,
+ 255 /* TPStatus */, 16 /* TPUDL */,
+ 255 /* TPVP */, 12 /* firstbyte */,
+ 13 /* TPMR */, 255 /* TPPID?? */};
+
+static GSM_Error N7110_ReplyGetSMSMessage(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int i;
+ size_t Width, Height;
+ unsigned char output[500], output2[500];
+ GSM_Phone_Data *Data = &s->Phone.Data;
+ size_t pos;
+ GSM_Error error;
+
+ switch(msg->Buffer[3]) {
+ case 0x08:
+ switch (msg->Buffer[8]) {
+ case 0x00:
+ case 0x01:
+ smprintf(s, "SMS message\n");
+ if (Data->RequestID == ID_GetSMSMessage) {
+ Data->GetSMSMessage->Number=1;
+ NOKIA_DecodeSMSState(s, msg->Buffer[4], &Data->GetSMSMessage->SMS[0]);
+ DCT3_DecodeSMSFrame(s, &Data->GetSMSMessage->SMS[0],msg->Buffer+9);
+ return ERR_NONE;
+ }
+ FALLTHROUGH;
+ case 0x02:
+ smprintf(s, "SMS template\n");
+ if (Data->RequestID == ID_GetSMSMessage) {
+ Data->GetSMSMessage->Number=1;
+ NOKIA_DecodeSMSState(s, msg->Buffer[4], &Data->GetSMSMessage->SMS[0]);
+ Data->GetSMSMessage->SMS[0].PDU=SMS_Submit;
+ GSM_DecodeSMSFrame(&(s->di), &Data->GetSMSMessage->SMS[0],msg->Buffer+9,N7110_SMSTemplate);
+ return ERR_NONE;
+ }
+ FALLTHROUGH;
+ case 0x07:
+ smprintf(s, "Picture Image\n");
+ switch (Data->RequestID) {
+ case ID_GetBitmap:
+ PHONE_GetBitmapWidthHeight(GSM_NokiaPictureImage, &Width, &Height);
+ Data->Bitmap->BitmapWidth = Width;
+ Data->Bitmap->BitmapHeight = Height;
+ PHONE_DecodeBitmap(GSM_NokiaPictureImage, msg->Buffer + 51, Data->Bitmap);
+ pos = 22;
+ error = GSM_UnpackSemiOctetNumber(&(s->di), Data->Bitmap->Sender, msg->Buffer, &pos, msg->Length, TRUE);
+ if (error != ERR_NONE) {
+ return error;
+ }
+#ifdef DEBUG
+ pos = 9;
+ error = GSM_UnpackSemiOctetNumber(&(s->di), output, msg->Buffer, &pos, msg->Length, TRUE);
+ if (error != ERR_NONE) {
+ return error;
+ }
+ smprintf(s, "SMSC : %s\n",DecodeUnicodeString(output));
+#endif
+ Data->Bitmap->Text[0] = 0;
+ Data->Bitmap->Text[1] = 0;
+ if (msg->Length!=304) {
+ GSM_UnpackEightBitsToSeven(0, msg->Length-304, msg->Length-304, msg->Buffer+52+PHONE_GetBitmapSize(GSM_NokiaPictureImage,0,0),output);
+ DecodeDefault(Data->Bitmap->Text, output, msg->Length - 304, TRUE, NULL);
+ }
+ return ERR_NONE;
+ case ID_GetSMSMessage:
+ Data->GetSMSMessage->Number = 0;
+ i = 0;
+ output[i++] = 0x30; /* Smart Messaging 3.0 */
+ output[i++] = SM30_OTA;
+ output[i++] = 0x01; /* Length */
+ output[i++] = 0x00; /* Length */
+ output[i++] = 0x00;
+ PHONE_GetBitmapWidthHeight(GSM_NokiaPictureImage, &Width, &Height);
+ output[i++] = Width;
+ output[i++] = Height;
+ output[i++] = 0x01;
+ memcpy(output+i,msg->Buffer+51,PHONE_GetBitmapSize(GSM_NokiaPictureImage,0,0));
+ i = i + PHONE_GetBitmapSize(GSM_NokiaPictureImage,0,0);
+ if (msg->Length!=304) {
+ output[i++] = SM30_UNICODETEXT;
+ output[i++] = 0;
+ output[i++] = 0; /* Length - later changed */
+ GSM_UnpackEightBitsToSeven(0, msg->Length-304, msg->Length-304, msg->Buffer+52+PHONE_GetBitmapSize(GSM_NokiaPictureImage,0,0),output2);
+ DecodeDefault(output+i, output2, msg->Length - 304, TRUE, NULL);
+ output[i - 1] = UnicodeLength(output+i) * 2;
+ i = i + output[i-1];
+ }
+ GSM_MakeMultiPartSMS(&(s->di), Data->GetSMSMessage,output,i,UDH_NokiaProfileLong,SMS_Coding_8bit,1,0);
+ for (i=0;i<3;i++) {
+ Data->GetSMSMessage->SMS[i].Number[0]=0;
+ Data->GetSMSMessage->SMS[i].Number[1]=0;
+ }
+ return ERR_NONE;
+ default:
+ smprintf(s, "Unknown SMS type: %i\n",msg->Buffer[8]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ default:
+ smprintf(s, "Unknown SMS type: %i\n",msg->Buffer[8]);
+ }
+ break;
+ case 0x09:
+ switch (msg->Buffer[4]) {
+ case 0x02:
+ smprintf(s, "Too high location ?\n");
+ return ERR_INVALIDLOCATION;
+ case 0x07:
+ smprintf(s, "Empty\n");
+ return ERR_EMPTY;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ case 0x6F:
+ smprintf(s, "SMS message info received\n");
+ if (msg->Length == 43) {
+ Data->GetSMSMessage->SMS[0].Name[0] = 0;
+ Data->GetSMSMessage->SMS[0].Name[1] = 0;
+ } else {
+ CopyUnicodeString(Data->GetSMSMessage->SMS[0].Name,msg->Buffer+43);
+ }
+ smprintf(s, "Name: \"%s\"\n",DecodeUnicodeString(Data->GetSMSMessage->SMS[0].Name));
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N7110_PrivGetSMSMessage(GSM_StateMachine *s, GSM_MultiSMSMessage *sms)
+{
+ GSM_Error error;
+ unsigned char folderid;
+ unsigned int location;
+ int i;
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x07,
+ 0x08, /* folder ID */
+ 0x00, 0x05, /* location */
+ 0x01, 0x65, 0x01};
+ unsigned char NameReq[] = {N6110_FRAME_HEADER, 0x6E,
+ 0x08, /* folder ID */
+ 0x00, 0x05}; /* location */
+
+ N7110_GetSMSLocation(s, &sms->SMS[0], &folderid, &location);
+
+ req[4]=folderid;
+ req[5]=location / 256;
+ req[6]=location % 256;
+
+ s->Phone.Data.GetSMSMessage=sms;
+ smprintf(s, "Getting sms\n");
+ error=GSM_WaitFor (s, req, 10, 0x14, 4, ID_GetSMSMessage);
+ if (error==ERR_NONE) {
+ NameReq[4] = folderid;
+ NameReq[5] = location / 256;
+ NameReq[6] = location;
+ smprintf(s, "Getting sms info\n");
+ error=GSM_WaitFor (s, NameReq, 7, 0x14, 4, ID_GetSMSMessage);
+ if (error != ERR_NONE) return error;
+ for (i=0;i<sms->Number;i++) {
+ N7110_SetSMSLocation(s, &sms->SMS[i], folderid, location);
+ sms->SMS[i].Folder = folderid/0x08;
+ sms->SMS[i].InboxFolder = TRUE;
+ if (folderid/0x08 != 0x01) sms->SMS[i].InboxFolder = FALSE;
+ CopyUnicodeString(sms->SMS[i].Name,sms->SMS[0].Name);
+ sms->SMS[i].Memory = MEM_ME;
+ if (folderid/0x08 == 0x01 || folderid/0x08 == 0x02) {
+ sms->SMS[i].Memory = MEM_MT;
+ if (folderid/0x08 == 0x01) { /* Inbox */
+ if (sms->SMS[i].State == SMS_Sent) sms->SMS[i].Memory = MEM_ME;
+ if (sms->SMS[i].State == SMS_UnSent) sms->SMS[i].Memory = MEM_ME;
+ if (sms->SMS[i].State == SMS_Read) sms->SMS[i].Memory = MEM_SM;
+ if (sms->SMS[i].State == SMS_UnRead) sms->SMS[i].Memory = MEM_SM;
+ }
+ if (folderid/0x08 == 0x02) { /* Outbox */
+ if (sms->SMS[i].State == SMS_Sent) sms->SMS[i].Memory = MEM_SM;
+ if (sms->SMS[i].State == SMS_UnSent) sms->SMS[i].Memory = MEM_SM;
+ if (sms->SMS[i].State == SMS_Read) sms->SMS[i].Memory = MEM_ME;
+ if (sms->SMS[i].State == SMS_UnRead) sms->SMS[i].Memory = MEM_ME;
+ }
+ }
+ }
+ }
+ return error;
+}
+
+static GSM_Error N7110_GetSMSMessage(GSM_StateMachine *s, GSM_MultiSMSMessage *sms)
+{
+ GSM_Error error;
+ unsigned char folderid;
+ unsigned int location;
+ GSM_Phone_N7110Data *Priv = &s->Phone.Data.Priv.N7110;
+ int i;
+ gboolean found = FALSE;
+
+ N7110_GetSMSLocation(s, &(sms->SMS[0]), &folderid, &location);
+ error=N7110_GetSMSFolderStatus(s, folderid);
+ if (error!=ERR_NONE) return error;
+ for (i=0;i<Priv->LastSMSFolder.Number;i++) {
+ if (Priv->LastSMSFolder.Location[i]==location) {
+ found = TRUE;
+ break;
+ }
+ }
+ if (!found) return ERR_EMPTY;
+ return N7110_PrivGetSMSMessage(s,sms);
+}
+
+static GSM_Error N7110_GetNextSMSMessage(GSM_StateMachine *s, GSM_MultiSMSMessage *sms, gboolean start)
+{
+ GSM_Phone_N7110Data *Priv = &s->Phone.Data.Priv.N7110;
+ unsigned char folderid;
+ unsigned int location;
+ GSM_Error error;
+ int i;
+ gboolean findnextfolder = FALSE;
+
+ if (start) {
+ folderid=0x00;
+ findnextfolder=TRUE;
+ error=N7110_GetSMSFolders(s,&Priv->LastSMSFolders);
+ if (error!=ERR_NONE) return error;
+ } else {
+ N7110_GetSMSLocation(s, &(sms->SMS[0]), &folderid, &location);
+ for (i=0;i<Priv->LastSMSFolder.Number;i++) {
+ if (Priv->LastSMSFolder.Location[i]==location) break;
+ }
+ /* Is this last location in this folder ? */
+ if (i==Priv->LastSMSFolder.Number-1) {
+ findnextfolder=TRUE;
+ } else {
+ location=Priv->LastSMSFolder.Location[i+1];
+ }
+ }
+ if (findnextfolder) {
+ Priv->LastSMSFolder.Number=0;
+ while (Priv->LastSMSFolder.Number==0) {
+ folderid=folderid+0x08;
+ /* Too high folder number */
+ if ((folderid/0x08)>Priv->LastSMSFolders.Number) return ERR_EMPTY;
+ /* Get next folder status */
+ error=N7110_GetSMSFolderStatus(s, folderid);
+ if (error!=ERR_NONE) return error;
+ /* First location from this folder */
+ location=Priv->LastSMSFolder.Location[0];
+ }
+ }
+ N7110_SetSMSLocation(s, &sms->SMS[0], folderid, location);
+
+ return N7110_PrivGetSMSMessage(s, sms);
+}
+
+static int N7110_ReturnBinaryRingtoneLocation(char *model)
+{
+ if (strcmp(model,"NSE-5") == 0) return 0x72; /* first 0x72 - 7110 */
+ if (strcmp(model,"NPE-3") == 0) return 0x89; /* first 0x89 - 6210 */
+ if (strcmp(model,"NHM-3") == 0) return 0x89; /* quess for 6250 */
+ return 0;
+}
+
+static GSM_Error N7110_ReplyGetRingtone(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int tmp;
+ size_t i;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "Ringtone received\n");
+ switch (msg->Buffer[3]) {
+ case 0x23:
+ tmp=0;i=4;
+ while (msg->Buffer[i]!=0 || msg->Buffer[i+1]!=0) {
+ tmp++;
+ i=i+2;
+ if (i>msg->Length) return ERR_EMPTY;
+ }
+ memcpy(Data->Ringtone->Name,msg->Buffer+6,tmp*2);
+ smprintf(s, "Name \"%s\"\n",DecodeUnicodeString(Data->Ringtone->Name));
+ /* Looking for end */
+ i=37;
+ while (TRUE) {
+ if (msg->Buffer[i]==0x07 && msg->Buffer[i+1]==0x0b) {
+ i=i+2; break;
+ }
+ if (msg->Buffer[i]==0x0e && msg->Buffer[i+1]==0x0b) {
+ i=i+2; break;
+ }
+ i++;
+ if (i==msg->Length) return ERR_EMPTY;
+ }
+ /* Copying frame */
+ memcpy(Data->Ringtone->NokiaBinary.Frame,msg->Buffer+37,i-37);
+ Data->Ringtone->NokiaBinary.Length=i-37;
+ return ERR_NONE;
+ case 0x24:
+ smprintf(s, "Invalid location. Too high ?\n");
+ return ERR_INVALIDLOCATION;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N7110_GetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, gboolean PhoneRingtone)
+{
+ unsigned char req[] = {N7110_FRAME_HEADER, 0x22, 0x00, 0x00};
+
+ if (PhoneRingtone) return ERR_NOTSUPPORTED;
+ if (Ringtone->Format == 0x00) Ringtone->Format = RING_NOKIABINARY;
+
+ switch (Ringtone->Format) {
+ case RING_NOTETONE:
+ /* In the future get binary and convert */
+ return ERR_NOTSUPPORTED;
+ case RING_NOKIABINARY:
+ req[5]=N7110_ReturnBinaryRingtoneLocation(s->Phone.Data.Model)+Ringtone->Location;
+ s->Phone.Data.Ringtone=Ringtone;
+ smprintf(s, "Getting binary ringtone\n");
+ return GSM_WaitFor (s, req, 6, 0x1f, 4, ID_GetRingtone);
+ case RING_MIDI:
+ case RING_MMF:
+ return ERR_NOTSUPPORTED;
+ }
+ return ERR_NOTSUPPORTED;
+}
+
+static GSM_Error N7110_ReplyGetPictureImageInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int i;
+ GSM_Phone_N7110Data *Priv = &s->Phone.Data.Priv.N7110;
+
+ smprintf(s, "Received info for Picture Images\n");
+ smprintf(s, "Number : %i\n",msg->Buffer[4]*256+msg->Buffer[5]);
+ smprintf(s, "Locations :");
+ Priv->LastPictureImageFolder.Number=msg->Buffer[4]*256+msg->Buffer[5];
+ for (i=0;i<Priv->LastPictureImageFolder.Number;i++) {
+ Priv->LastPictureImageFolder.Location[i]=msg->Buffer[6+i*2]*256+msg->Buffer[7+i*2];
+ smprintf(s, " %i",Priv->LastPictureImageFolder.Location[i]);
+ }
+ smprintf(s, "\n");
+ return ERR_NONE;
+}
+
+static GSM_Error N7110_GetPictureImageLocation(GSM_StateMachine *s, GSM_Bitmap *Bitmap, unsigned char *folder, int *location)
+{
+ GSM_Phone_N7110Data *Priv = &s->Phone.Data.Priv.N7110;
+ GSM_SMSFolders folders;
+ GSM_Error error;
+ int i, j = 0, count = 0;
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x96,
+ 0x00, /* Folder ID */
+ 0x0f, 0x07};
+
+ /* Just to have some defined values */
+ *folder = 0;
+ *location = 0;
+
+ error=N7110_GetSMSFolders (s, &folders);
+ if (error!=ERR_NONE) return error;
+
+ for (i=0;i<folders.Number;i++) {
+ req[4] = (i+1) * 0x08; /* SMS folder ID */
+ error = GSM_WaitFor (s, req, 7, 0x14, 4, ID_GetBitmap);
+ if (error!=ERR_NONE) return error;
+ for (j=0;j<Priv->LastPictureImageFolder.Number;j++) {
+ count++;
+ if (count==Bitmap->Location) break;
+ }
+ if (count==Bitmap->Location) break;
+ }
+ if (count!=Bitmap->Location) return ERR_INVALIDLOCATION;
+ *folder = (i+1) * 0x08; /* SMS Folder ID */
+ *location = Priv->LastPictureImageFolder.Location[j];
+ return ERR_NONE;
+}
+
+static GSM_Error N7110_GetPictureImage(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
+{
+ unsigned char folder;
+ int location;
+ GSM_Error error;
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x07,
+ 0x00, /* Folder ID */
+ 0x00, 0x00, /* Location */
+ 0x00, 0x64};
+
+ error = N7110_GetPictureImageLocation(s, Bitmap, &folder, &location);
+ switch (error) {
+ case ERR_NONE:
+ req[4] = folder;
+ req[5] = location / 256;
+ req[6] = location % 256;
+ return GSM_WaitFor (s, req, 9, 0x14, 4, ID_GetBitmap);
+ default:
+ return error;
+ }
+}
+
+static GSM_Error N7110_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
+{
+ GSM_MemoryEntry pbk;
+ GSM_Error error;
+ unsigned char OpReq[] = {N6110_FRAME_HEADER, 0x70};
+
+ s->Phone.Data.Bitmap=Bitmap;
+ switch (Bitmap->Type) {
+ case GSM_StartupLogo:
+ smprintf(s, "Getting startup logo\n");
+ return N71_92_GetPhoneSetting(s, ID_GetBitmap, 0x15);
+ case GSM_WelcomeNote_Text:
+ smprintf(s, "Getting welcome note\n");
+ return N71_92_GetPhoneSetting(s, ID_GetBitmap, 0x02);
+ case GSM_DealerNote_Text:
+ smprintf(s, "Getting dealer note\n");
+ return N71_92_GetPhoneSetting(s, ID_GetBitmap, 0x17);
+ case GSM_CallerGroupLogo:
+ pbk.MemoryType = (GSM_MemoryType)MEM7110_CG;
+ pbk.Location = Bitmap->Location;
+ smprintf(s, "Getting caller group logo\n");
+ error=N7110_GetMemory(s,&pbk);
+ if (error==ERR_NONE) NOKIA_GetDefaultCallerGroupName(Bitmap);
+ return error;
+ case GSM_OperatorLogo:
+ smprintf(s, "Getting operator logo\n");
+ /* This is like DCT3_GetNetworkInfo */
+ return GSM_WaitFor (s, OpReq, 4, 0x0a, 4, ID_GetBitmap);
+ case GSM_PictureImage:
+ /* 7110 doesn't support it */
+ if (strcmp(s->Phone.Data.Model,"NSE-5") == 0) return ERR_NOTSUPPORTED;
+ return N7110_GetPictureImage(s, Bitmap);
+ default:
+ break;
+ }
+ return ERR_NOTSUPPORTED;
+}
+
+static GSM_Error N7110_SetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength)
+{
+ GSM_Ringtone dest;
+ GSM_Error error;
+ GSM_NetworkInfo NetInfo;
+ size_t size=200;
+ unsigned char req[1000] = {0x7C, 0x01, 0x00, 0x0D, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00}; /*Length*/
+ unsigned char req2[4000] = {N7110_FRAME_HEADER, 0x1F, 0x00,
+ 0x87, /* Location */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+ switch (Ringtone->Format) {
+ case RING_NOTETONE:
+ if (Ringtone->Location==255) {
+ /* 7110 doesn't support it */
+ if (strcmp(s->Phone.Data.Model,"NSE-5") == 0) return ERR_NOTSUPPORTED;
+ *maxlength=GSM_EncodeNokiaRTTLRingtone(Ringtone, req+11, &size);
+ req[10] = size;
+ error = s->Protocol.Functions->WriteMessage(s, req, size+11, 0x00);
+ if (error!=ERR_NONE) return error;
+ sleep(1);
+ /* We have to make something (not important, what) now */
+ /* no answer from phone*/
+ return DCT3_GetNetworkInfo(s,&NetInfo);
+ }
+ GSM_RingtoneConvert(&dest, Ringtone, RING_NOKIABINARY);
+ break;
+ case RING_NOKIABINARY:
+ memcpy(&dest,Ringtone,sizeof(GSM_Ringtone));
+ break;
+ default:
+ return ERR_NOTSUPPORTED;
+ }
+ req2[5]=N7110_ReturnBinaryRingtoneLocation(s->Phone.Data.Model)+Ringtone->Location;
+ CopyUnicodeString(req2+6,Ringtone->Name);
+ memcpy(req2+37,dest.NokiaBinary.Frame,dest.NokiaBinary.Length);
+ error = s->Protocol.Functions->WriteMessage(s, req2, 37+dest.NokiaBinary.Length, 0x1F);
+ if (error!=ERR_NONE) return error;
+ sleep(1);
+ /* We have to make something (not important, what) now */
+ /* no answer from phone*/
+ return DCT3_GetNetworkInfo(s,&NetInfo);
+}
+
+static GSM_Error N7110_ReplySaveSMSMessage(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ switch (msg->Buffer[3]) {
+ case 0x05:
+ smprintf(s, "SMS message saving status\n");
+ smprintf(s, "Saved in folder %i at location %i\n",msg->Buffer[4], msg->Buffer[5]*256+msg->Buffer[6]);
+ if (msg->Buffer[4] == 0xf8) {
+ N7110_SetSMSLocation(s, Data->SaveSMSMessage,0x08,msg->Buffer[5]*256+msg->Buffer[6]);
+ Data->SaveSMSMessage->Folder = 0x01;
+ } else {
+ N7110_SetSMSLocation(s, Data->SaveSMSMessage,msg->Buffer[4],msg->Buffer[5]*256+msg->Buffer[6]);
+ Data->SaveSMSMessage->Folder = msg->Buffer[4] / 0x08;
+ }
+ return ERR_NONE;
+ case 0x06:
+ smprintf(s, "SMS message saving status\n");
+ switch (msg->Buffer[4]) {
+ case 0x03:
+ smprintf(s, "Too high location ?\n");
+ return ERR_INVALIDLOCATION;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ }
+ break;
+ case 0x84:
+ smprintf(s, "Name for SMS changed OK to \"%s\"\n",DecodeUnicodeString(msg->Buffer+7));
+ smprintf(s, "Saved in folder %i at location %i\n",msg->Buffer[4], msg->Buffer[5]*256+msg->Buffer[6]);
+ if (msg->Buffer[4] == 0xf8) {
+ N7110_SetSMSLocation(s, Data->SaveSMSMessage,0x08,msg->Buffer[5]*256+msg->Buffer[6]);
+ Data->SaveSMSMessage->Folder = 0x01;
+ } else {
+ N7110_SetSMSLocation(s, Data->SaveSMSMessage,msg->Buffer[4],msg->Buffer[5]*256+msg->Buffer[6]);
+ Data->SaveSMSMessage->Folder = msg->Buffer[4] / 0x08;
+ }
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N7110_PrivSetSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms)
+{
+ int length;
+ unsigned int location;
+ unsigned char folderid, folder;
+ GSM_Error error;
+ unsigned char req[256] = {N6110_FRAME_HEADER, 0x04,
+ 0x03, /* sms status */
+ 0x10, /* folder */
+ 0x00,0x00, /* location */
+ 0x00};
+ unsigned char NameReq[200] = {N6110_FRAME_HEADER, 0x83};
+
+ switch (sms->State) {
+ case SMS_Read : req[4] = 0x01; break;
+ case SMS_UnRead : req[4] = 0x03; break;
+ case SMS_Sent : req[4] = 0x05; break;
+ case SMS_UnSent : req[4] = 0x07; break;
+ }
+
+ N7110_GetSMSLocation(s, sms, &folderid, &location);
+ req[5] = folderid;
+ req[6] = location / 256;
+ req[7] = location % 256;
+
+ sms->Memory = MEM_ME;
+ /* Outbox */
+ if (folderid == 0x10 && (sms->State == SMS_Sent || sms->State == SMS_UnSent)) {
+ sms->PDU = SMS_Submit; /* We will use SIM Outbox */
+ sms->Memory = MEM_SM;
+ }
+ /* Inbox */
+ if (folderid == 0x08 && (sms->State == SMS_UnRead || sms->State == SMS_Read)) {
+ if (sms->State == SMS_UnRead) req[5] = 0xf8; /* We will use SIM Inbox */
+ sms->Memory = MEM_SM;
+ }
+
+ switch (sms->PDU) {
+ case SMS_Deliver:
+ error = PHONE_EncodeSMSFrame(s,sms,req+9,PHONE_SMSDeliver,&length,TRUE);
+ break;
+ case SMS_Submit:
+ smprintf(s, "Saving SMS template\n");
+ error = PHONE_EncodeSMSFrame(s,sms,req+9,N7110_SMSTemplate,&length,TRUE);
+ req[8] = 0x02; /* SMS Template info */
+ break;
+ default:
+ return ERR_UNKNOWN;
+ }
+ if (error != ERR_NONE) return error;
+
+ s->Phone.Data.SaveSMSMessage=sms;
+ smprintf(s, "Saving sms\n");
+ error=GSM_WaitFor (s, req, 9+length, 0x14, 4, ID_SaveSMSMessage);
+ if (error == ERR_NONE && UnicodeLength(sms->Name)!=0) {
+ folder = sms->Folder;
+ sms->Folder = 0;
+ N7110_GetSMSLocation(s, sms, &folderid, &location);
+ length = 4;
+ NameReq[length++] = folderid;
+ NameReq[length++] = location / 256;
+ NameReq[length++] = location % 256;
+ CopyUnicodeString(NameReq+length, sms->Name);
+ length = length+UnicodeLength(sms->Name)*2;
+ NameReq[length++] = 0;
+ NameReq[length++] = 0;
+ error=GSM_WaitFor (s, NameReq, length, 0x14, 4, ID_SaveSMSMessage);
+ sms->Folder = folder;
+ }
+ return error;
+}
+
+static GSM_Error N7110_SetSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
+{
+ unsigned int location;
+ unsigned char folderid;
+
+ N7110_GetSMSLocation(s, sms, &folderid, &location);
+ if (location == 0) return ERR_INVALIDLOCATION;
+ return N7110_PrivSetSMSMessage(s, sms);
+}
+
+static GSM_Error N7110_AddSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
+{
+ unsigned int location;
+ unsigned char folderid;
+
+ N7110_GetSMSLocation(s, sms, &folderid, &location);
+ location = 0;
+ N7110_SetSMSLocation(s, sms, folderid, location);
+ return N7110_PrivSetSMSMessage(s, sms);
+}
+
+static GSM_Error N7110_ReplyClearOperatorLogo(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Clearing operator logo.....\n");
+ return ERR_NONE;
+}
+
+static GSM_Error N7110_ReplySetOperatorLogo(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Setting operator logo.....\n");
+ return ERR_NONE;
+}
+
+static GSM_Error N7110_SetCallerLogo(GSM_StateMachine *s, GSM_Bitmap *bitmap)
+{
+ int block=0, i;
+ size_t Width, Height;
+ unsigned int count = 18;
+ char string[500];
+ unsigned char req[500] = {N6110_FRAME_HEADER, 0x0b, 0x00,
+ 0x01, 0x01, 0x00, 0x00, 0x0c,
+ 0x00, 0x10, /* memory type */
+ 0x00, 0x00, /* location */
+ 0x00, 0x00, 0x00};
+
+ req[13] = bitmap->Location;
+
+ /* Enabling/disabling logo */
+ if (bitmap->DefaultBitmap) {
+ string[0] = 0; /* disabling */
+ } else {
+ string[0] = bitmap->BitmapEnabled?1:0;
+ }
+ string[1] = 0;
+ count += N71_65_PackPBKBlock(s, N7110_PBK_LOGOON, 2, block++, string, req + count);
+
+ /* Ringtone */
+ if (!bitmap->DefaultRingtone) {
+ string[0] = bitmap->RingtoneID;
+ string[1] = 0;
+ count += N71_65_PackPBKBlock(s, N7110_PBK_RINGTONE_ID, 2, block++, string, req + count);
+ }
+
+ /* Number of group */
+ string[0] = bitmap->Location;
+ string[1] = 0;
+ count += N71_65_PackPBKBlock(s, N7110_PBK_GROUP, 2, block++, string, req + count);
+
+ /* Name */
+ if (!bitmap->DefaultName) {
+ i = UnicodeLength(bitmap->Text) * 2;
+ string[0] = i + 2;
+ memcpy(string + 1, bitmap->Text, i);
+ string[i + 1] = 0;
+ count += N71_65_PackPBKBlock(s, N7110_PBK_NAME, i + 2, block++, string, req + count);
+ }
+
+ /* Logo */
+ if (bitmap->DefaultBitmap) {
+ bitmap->BitmapWidth = 72;
+ bitmap->BitmapHeight = 14;
+ GSM_ClearBitmap(bitmap);
+ }
+ PHONE_GetBitmapWidthHeight(GSM_NokiaCallerLogo, &Width, &Height);
+ string[0] = Width;
+ string[1] = Height;
+ string[2] = 0;
+ string[3] = 0;
+ string[4] = PHONE_GetBitmapSize(GSM_NokiaCallerLogo,0,0);
+ PHONE_EncodeBitmap(GSM_NokiaCallerLogo, string + 5, bitmap);
+ count += N71_65_PackPBKBlock(s, N7110_PBK_GROUPLOGO, PHONE_GetBitmapSize(GSM_NokiaCallerLogo,0,0) + 5, block++, string, req + count);
+
+ req[17] = block;
+
+ return GSM_WaitFor (s, req, count, 0x03, 4, ID_SetBitmap);
+}
+
+static GSM_Error N7110_ReplySetPicture(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "Picture Image written OK, folder %i, location %i\n",msg->Buffer[4],msg->Buffer[5]*256+msg->Buffer[6]);
+ return ERR_NONE;
+}
+
+static GSM_Error N7110_SetPictureImage(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
+{
+ unsigned char folder;
+ GSM_Error error;
+ int location, i, count;
+ size_t Width, Height;
+ GSM_Phone_Bitmap_Types Type = GSM_NokiaPictureImage;
+ unsigned char req[500] = {N6110_FRAME_HEADER, 0x50, 0x07,
+ 0x00, /* location */
+ 0x00, 0x00, /* index */
+ 0x07};
+
+ error=N7110_GetPictureImageLocation(s, Bitmap, &folder, &location);
+ switch (error) {
+ case ERR_NONE:
+ req[5] = folder;
+ req[6] = location / 256;
+ req[7] = location % 256;
+ break;
+ case ERR_INVALIDLOCATION:
+ req[5] = 0x21; /* Save in Templates folder */
+ req[6] = 0;
+ req[7] = 0;
+ break;
+ default:
+ return error;
+ }
+
+ /* Cleaning */
+ for (i=0;i<36;i++) req[i+9]=0;
+
+ count=8;
+ if (UnicodeLength(Bitmap->Text)==0) {
+ count+=2 ;req[count]=0x0c;
+ count+=2 ;req[count]=0x0d;
+ count+=2 ;req[count]=0x0e;
+ count+=2 ;req[count]=0x0f;
+ count+=2 ;req[count]=0x10;
+ count+=2 ;req[count]=0x11;
+ count+=23;req[count]=0x02;
+ count++ ;
+ } else {
+ count+=2 ;req[count]=0x54;
+ count++ ;req[count]=0xd4;
+ count++ ;req[count]=0x0d;
+ count+=2 ;req[count]=0x0e;
+ count+=2 ;req[count]=0x0f;
+ count+=2 ;req[count]=0x10;
+ count+=2 ;req[count]=0x11;
+ count+=21;req[count]=0x01;
+ count+=3 ;
+ }
+ req[count] = 0x01;
+ count+=2;
+ req[count++] = 0x01;
+ PHONE_GetBitmapWidthHeight(Type, &Width, &Height);
+ req[count++] = Width;
+ req[count++] = Height;
+ req[count++] = PHONE_GetBitmapSize(Type,0,0) / 256;
+ req[count++] = PHONE_GetBitmapSize(Type,0,0) % 256;
+ PHONE_EncodeBitmap(Type, req + count, Bitmap);
+ count += PHONE_GetBitmapSize(Type,0,0);
+ if (UnicodeLength(Bitmap->Text)!=0) {
+ req[count] = UnicodeLength(Bitmap->Text);
+ GSM_PackSevenBitsToEight(0, Bitmap->Text, req+count+1,strlen(Bitmap->Text));
+ count = count + req[count];
+ } else {
+ req[count++]=0x00;
+ }
+ req[count++]=0x00;
+ smprintf(s, "Setting Picture Image\n");
+ return GSM_WaitFor (s, req, count, 0x14, 4, ID_SetBitmap);
+}
+
+static GSM_Error N7110_SetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
+{
+ GSM_Error error;
+ GSM_Phone_Bitmap_Types Type;
+ size_t Width, Height, i;
+ unsigned char reqStartup[1000] = {N7110_FRAME_HEADER, 0xec,
+ 0x15, /* Startup Logo setting */
+ 0x00, 0x00, 0x00, 0x04, 0xc0, 0x02, 0x00,
+ 0x00, /* Bitmap height */
+ 0xc0, 0x03, 0x00,
+ 0x00, /* Bitmap width */
+ 0xc0, 0x04, 0x03, 0x00};
+ unsigned char reqOp[1000] = {N7110_FRAME_HEADER, 0xa3, 0x01,
+ 0x00, /* logo disabled */
+ 0x00, 0xf0, 0x00, /* network code (000 00) */
+ 0x00 ,0x04,
+ 0x08, /* length of rest */
+ 0x00, 0x00, /* Bitmap width / height */
+ 0x00,
+ 0x00, /* Bitmap size */
+ 0x00, 0x00};
+ unsigned char reqClrOp[] = {0x00, 0x01, 0x00, 0xaf, 0x00};
+ unsigned char reqStartupText[500] = {N7110_FRAME_HEADER, 0xec,
+ 0x02}; /* Startup Text setting */
+
+ switch (Bitmap->Type) {
+ case GSM_StartupLogo:
+ if (Bitmap->Location!=1) return ERR_NOTSUPPORTED;
+ Type=GSM_Nokia6210StartupLogo;
+ if (strcmp(s->Phone.Data.Model,"NSE-5") == 0) Type=GSM_Nokia7110StartupLogo;
+ PHONE_GetBitmapWidthHeight(Type, &Width, &Height);
+ reqStartup[12] = Height;
+ reqStartup[16] = Width;
+ PHONE_EncodeBitmap(Type, reqStartup + 21, Bitmap);
+ smprintf(s, "Setting startup logo\n");
+ return GSM_WaitFor (s, reqStartup, 21+PHONE_GetBitmapSize(Type,0,0), 0x7A, 4, ID_SetBitmap);
+ case GSM_WelcomeNote_Text:
+ CopyUnicodeString(reqStartupText + 5, Bitmap->Text);
+ i = 6 + UnicodeLength(Bitmap->Text) * 2;
+ reqStartupText[i++] = 0;
+ reqStartupText[i++] = 0;
+ return GSM_WaitFor (s, reqStartupText, i, 0x7A, 4, ID_SetBitmap);
+ case GSM_DealerNote_Text:
+ reqStartupText[4] = 0x17;
+ CopyUnicodeString(reqStartupText + 5, Bitmap->Text);
+ i = 6 + UnicodeLength(Bitmap->Text) * 2;
+ reqStartupText[i++] = 0;
+ reqStartupText[i++] = 0;
+ return GSM_WaitFor (s, reqStartupText, i, 0x7A, 4, ID_SetBitmap);
+ case GSM_OperatorLogo:
+ /* We want to set operator logo, not clear */
+ if (strcmp(Bitmap->NetworkCode,"000 00")) {
+ reqOp[5] = 0x01; /* Logo enabled */
+ NOKIA_EncodeNetworkCode(reqOp+6, Bitmap->NetworkCode);
+ Type = GSM_Nokia7110OperatorLogo;
+ reqOp[11] = 8 + PHONE_GetBitmapSize(Type,0,0);
+ PHONE_GetBitmapWidthHeight(Type, &Width, &Height);
+ reqOp[12]=Width;
+ reqOp[13]=Height;
+ reqOp[15]=PHONE_GetBitmapSize(Type,0,0);
+ PHONE_EncodeBitmap(Type, reqOp + 18, Bitmap);
+ smprintf(s, "Setting operator logo\n");
+ return GSM_WaitFor (s, reqOp, 18+PHONE_GetBitmapSize(Type,0,0), 0x0A, 4, ID_SetBitmap);
+ } else {
+ smprintf(s, "Clearing operator logo\n");
+ for (i=0;i<5;i++) {
+ reqClrOp[4]=i;
+ error=GSM_WaitFor (s, reqClrOp, 5, 0x0A, 4, ID_SetBitmap);
+ if (error!=ERR_NONE) return error;
+ }
+ return GSM_WaitFor (s, reqOp, 18, 0x0A, 4, ID_SetBitmap);
+ }
+ case GSM_CallerGroupLogo:
+ return N7110_SetCallerLogo(s,Bitmap);
+ case GSM_PictureImage:
+ return N7110_SetPictureImage(s,Bitmap);
+ default:
+ break;
+ }
+ return ERR_NOTSUPPORTED;
+}
+
+static GSM_Error N7110_ReplyDeleteMemory(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Phonebook entry deleted\n");
+ return ERR_NONE;
+}
+
+static GSM_Error N7110_DeleteMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
+{
+ unsigned char req[] = {N7110_FRAME_HEADER, 0x0f, 0x00, 0x01,
+ 0x04, 0x00, 0x00, 0x0c, 0x01, 0xff,
+ 0x00, 0x01, /* location */
+ 0x05, /* memory type */
+ 0x00, 0x00, 0x00};
+
+ req[12] = entry->Location / 256;
+ req[13] = entry->Location % 256;
+
+ req[14] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES);
+ if (req[14]==0xff) return ERR_NOTSUPPORTED;
+
+ smprintf(s, "Deleting phonebook entry\n");
+ return GSM_WaitFor (s, req, 18, 0x03, 4, ID_SetMemory);
+}
+
+static GSM_Error N7110_SetMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
+{
+ int count = 18;
+ size_t blocks;
+ unsigned char req[5000] = {N7110_FRAME_HEADER, 0x0b, 0x00,
+ 0x01, 0x01, 0x00, 0x00, 0x0c,
+ 0x00, 0x00, /* memory type */
+ 0x00, 0x00, /* location */
+ 0x00, 0x00, 0x00};
+
+ if (entry->Location == 0) return ERR_NOTSUPPORTED;
+
+ req[11] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES);
+ if (req[11]==0xff) return ERR_NOTSUPPORTED;
+
+ req[12] = entry->Location >> 8;
+ req[13] = entry->Location & 0xff;
+
+ count = count + N71_65_EncodePhonebookFrame(s, req+18, entry, &blocks, FALSE, GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_VOICETAGS));
+ req[17] = blocks;
+
+ smprintf(s, "Writing phonebook entry\n");
+ return GSM_WaitFor (s, req, count, 0x03, 4, ID_SetMemory);
+}
+
+static GSM_Error N7110_DeleteSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
+{
+ unsigned char folderid;
+ unsigned int location;
+ unsigned char req[] = {N7110_FRAME_HEADER, 0x0a,
+ 0x00, /* folder */
+ 0x00, 0x00, /* location */
+ 0x01};
+
+ N7110_GetSMSLocation(s, sms, &folderid, &location);
+ req[4] = folderid;
+ req[5] = location / 256;
+ req[6] = location % 256;
+
+ smprintf(s, "Deleting sms\n");
+ return GSM_WaitFor (s, req, 8, 0x14, 4, ID_DeleteSMSMessage);
+}
+
+static GSM_Error N7110_ReplyGetSMSStatus(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "SMS status received\n");
+ switch (msg->Buffer[3]) {
+ case 0x37:
+ smprintf(s, "SIM size : %i\n",msg->Buffer[8]*256+msg->Buffer[9]);
+ smprintf(s, "Used in phone memory : %i\n",msg->Buffer[10]*256+msg->Buffer[11]);
+ smprintf(s, "Unread in phone memory : %i\n",msg->Buffer[12]*256+msg->Buffer[13]);
+ smprintf(s, "Used in SIM : %i\n",msg->Buffer[14]*256+msg->Buffer[15]);
+ smprintf(s, "Unread in SIM : %i\n",msg->Buffer[16]*256+msg->Buffer[17]);
+ Data->SMSStatus->SIMSize = msg->Buffer[8]*256+msg->Buffer[9];
+ Data->SMSStatus->PhoneUsed = msg->Buffer[10]*256+msg->Buffer[11];
+ Data->SMSStatus->PhoneUnRead = msg->Buffer[12]*256+msg->Buffer[13];
+ Data->SMSStatus->PhoneSize = 150;
+ Data->SMSStatus->SIMUsed = msg->Buffer[14]*256+msg->Buffer[15];
+ Data->SMSStatus->SIMUnRead = msg->Buffer[16]*256+msg->Buffer[17];
+ return ERR_NONE;
+ case 0x38:
+ smprintf(s, "Error. No PIN ?\n");
+ return ERR_SECURITYERROR;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N7110_GetSMSStatus(GSM_StateMachine *s, GSM_SMSMemoryStatus *status)
+{
+ GSM_Error error;
+ GSM_Phone_N7110Data *Priv = &s->Phone.Data.Priv.N7110;
+
+ error = DCT3_GetSMSStatus(s,status);
+ if (error != ERR_NONE) return error;
+
+ /* 6210 family doesn't show in frame with SMS status info
+ * about Templates. We get separately info about this SMS folder.
+ */
+ error = N7110_GetSMSFolderStatus(s, 0x20);
+ if (error != ERR_NONE) return error;
+ status->TemplatesUsed = Priv->LastSMSFolder.Number;
+
+ return ERR_NONE;
+}
+
+static GSM_Error N7110_ReplyGetProfileFeature(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ switch (msg->Buffer[3]) {
+ case 0x02:
+ smprintf(s, "Profile feature %02x with value %02x\n",msg->Buffer[6],msg->Buffer[10]);
+ switch (msg->Buffer[6]) {
+ case 0x03:
+ smprintf(s, "Ringtone ID\n");
+ Data->Profile->FeatureID [Data->Profile->FeaturesNumber] = Profile_RingtoneID;
+ Data->Profile->FeatureValue [Data->Profile->FeaturesNumber] = msg->Buffer[10];
+ Data->Profile->FeaturesNumber++;
+ break;
+ case 0x08: /* Caller groups */
+ NOKIA_FindFeatureValue(s, Profile71_65,msg->Buffer[6],msg->Buffer[10],Data,TRUE);
+ break;
+ case 0x09: /* Autoanswer */
+ if (Data->Profile->CarKitProfile || Data->Profile->HeadSetProfile) {
+ NOKIA_FindFeatureValue(s, Profile71_65,msg->Buffer[6],msg->Buffer[10],Data,FALSE);
+ }
+ break;
+ case 0xff :
+ CopyUnicodeString(Data->Profile->Name, msg->Buffer+10);
+ smprintf(s, "profile Name: \"%s\"\n", DecodeUnicodeString(Data->Profile->Name));
+ Data->Profile->DefaultName = FALSE;
+ break;
+ default:
+ NOKIA_FindFeatureValue(s, Profile71_65,msg->Buffer[6],msg->Buffer[10],Data,FALSE);
+ }
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N7110_GetProfile(GSM_StateMachine *s, GSM_Profile *Profile)
+{
+ GSM_Error error;
+ int i;
+ unsigned char Features[12] = {0x00,0x02,0x03,0x04,0x05,0x06,
+ 0x07,0x08,0x09,0xff,
+ 0x0a,0x22};
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x01, 0x01, 0x01, 0x01,
+ 0x00, /* Profile Location */
+ 0xff}; /* Feature number */
+
+ if (Profile->Location > 7) return ERR_INVALIDLOCATION;
+
+ Profile->CarKitProfile = FALSE;
+ Profile->HeadSetProfile = FALSE;
+ if (Profile->Location == 6) Profile->CarKitProfile = TRUE;
+ if (Profile->Location == 7) Profile->HeadSetProfile = TRUE;
+
+ Profile->FeaturesNumber = 0;
+
+ s->Phone.Data.Profile=Profile;
+ for (i = 0; i < 10; i++) {
+ req[7] = Profile->Location;
+ req[8] = Features[i];
+ smprintf(s, "Getting profile feature\n");
+ error = GSM_WaitFor (s, req, 9, 0x39, 4, ID_GetProfile);
+ if (error!=ERR_NONE) return error;
+ }
+ NOKIA_GetDefaultProfileName(Profile);
+ Profile->Active = FALSE;
+ return error;
+}
+
+static GSM_Error N7110_ReplySetProfileFeature(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Profile feature set\n");
+ return ERR_NONE;
+}
+
+static GSM_Error N7110_SetProfile(GSM_StateMachine *s, GSM_Profile *Profile)
+{
+ int i;
+ gboolean found;
+ GSM_Error error;
+ unsigned char ID,Value;
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x03, 0x01, 0x01, 0x03,
+ 0x02, /* feature number */
+ 0x01, /* Profile Location */
+ 0x01,
+ 0xff}; /* Value */
+
+ for (i=0;i<Profile->FeaturesNumber;i++) {
+ found = FALSE;
+ switch (Profile->FeatureID[i]) {
+ case Profile_RingtoneID:
+ ID = 0x03;
+ Value = Profile->FeatureValue[i];
+ found = TRUE;
+ break;
+ default:
+ found=NOKIA_FindPhoneFeatureValue(
+ s,
+ Profile71_65,
+ Profile->FeatureID[i],Profile->FeatureValue[i],
+ &ID,&Value);
+ }
+ if (found) {
+ req[7] = ID;
+ req[8] = Profile->Location;
+ req[10] = Value;
+ smprintf(s, "Setting profile feature\n");
+ error = GSM_WaitFor (s, req, 11, 0x39, 4, ID_SetProfile);
+ if (error!=ERR_NONE) return error;
+ }
+ }
+ return ERR_NONE;
+}
+
+static GSM_Error N7110_GetSpeedDial(GSM_StateMachine *s, GSM_SpeedDial *SpeedDial)
+{
+ GSM_MemoryEntry pbk;
+ GSM_Error error;
+
+ pbk.MemoryType = (GSM_MemoryType)MEM7110_SP;
+ pbk.Location = SpeedDial->Location;
+ SpeedDial->MemoryLocation = 0;
+ s->Phone.Data.SpeedDial = SpeedDial;
+
+ smprintf(s, "Getting speed dial\n");
+ error=N7110_GetMemory(s,&pbk);
+ switch (error) {
+ case ERR_NOTSUPPORTED:
+ smprintf(s, "No speed dials set in phone\n");
+ return ERR_EMPTY;
+ case ERR_NONE:
+ if (SpeedDial->MemoryLocation == 0) {
+ smprintf(s, "Speed dial not assigned or error in firmware\n");
+ return ERR_EMPTY;
+ }
+ return ERR_NONE;
+ default:
+ return error;
+ }
+}
+
+static GSM_Error N7110_ReplyIncomingSMS(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_SMSMessage sms;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+#ifdef DEBUG
+ smprintf(s, "SMS message received\n");
+ sms.State = SMS_UnRead;
+ sms.InboxFolder = TRUE;
+ DCT3_DecodeSMSFrame(s, &sms,msg->Buffer+8);
+#endif
+ if (Data->EnableIncomingSMS && s->User.IncomingSMS!=NULL) {
+ sms.State = SMS_UnRead;
+ sms.InboxFolder = TRUE;
+ DCT3_DecodeSMSFrame(s, &sms,msg->Buffer+8);
+
+ s->User.IncomingSMS(s, &sms, s->User.IncomingSMSUserData);
+ }
+ return ERR_NONE;
+}
+
+static GSM_Error N7110_Initialise (GSM_StateMachine *s)
+{
+#ifdef DEBUG
+ DCT3_SetIncomingCB(s,TRUE);
+#endif
+#ifdef GSM_ENABLE_N71_92INCOMINGINFO
+ /* Enables various things like incoming SMS, call info, etc. */
+ return N71_65_EnableFunctions (s, "\x01\x02\x06\x0A\x14\x17", 6);
+#endif
+ return ERR_NONE;
+}
+
+static GSM_Error N7110_ReplyGetCalendarInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ /* Old method 1 for accessing calendar */
+ return N71_65_ReplyGetCalendarInfo1(msg, s, &s->Phone.Data.Priv.N7110.LastCalendar);
+}
+
+#ifdef DEBUG
+static GSM_Error N7110_ReplyGetCalendarNotePos(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ /* Old method 1 for accessing calendar */
+ return N71_65_ReplyGetCalendarNotePos1(msg, s, &s->Phone.Data.Priv.N7110.FirstCalendarPos);
+}
+#endif
+
+static GSM_Error N7110_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, gboolean start)
+{
+ return N71_65_GetNextCalendar1(s,Note,start,&s->Phone.Data.Priv.N7110.LastCalendar,&s->Phone.Data.Priv.N7110.LastCalendarYear,&s->Phone.Data.Priv.N7110.LastCalendarPos);
+/* return N71_65_GetNextCalendar2(s,Note,start,&s->Phone.Data.Priv.N7110.LastCalendarYear,&s->Phone.Data.Priv.N7110.LastCalendarPos); */
+}
+
+static GSM_Error N7110_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *Status)
+{
+ GSM_Error error;
+
+ /* Method 1 */
+ error=N71_65_GetCalendarInfo1(s, &s->Phone.Data.Priv.N7110.LastCalendar);
+ if (error!=ERR_NONE) return error;
+ /**
+ * @todo This should be acquired from phone
+ */
+ Status->Free = 100;
+ Status->Used = s->Phone.Data.Priv.N6510.LastCalendar.Number;
+ return ERR_NONE;
+
+ /* Method 2 */
+/* return GE_NOTSUPPORTED; */
+}
+
+static GSM_Error N7110_AddCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note)
+{
+/* return N71_65_AddCalendar1(s, Note, NULL); */
+ return N71_65_AddCalendar2(s,Note);
+}
+
+static GSM_Error N7110_ReplyGetNetworkInfoError(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Probably means no PIN\n");
+ return ERR_SECURITYERROR;
+}
+
+static GSM_Error N7110_SetIncomingCall(GSM_StateMachine *s, gboolean enable)
+{
+#ifndef GSM_ENABLE_N71_92INCOMINGINFO
+ return ERR_SOURCENOTAVAILABLE;
+#else
+ return NOKIA_SetIncomingCall(s,enable);
+#endif
+}
+
+static GSM_Error N7110_SetIncomingUSSD(GSM_StateMachine *s, gboolean enable)
+{
+#ifndef GSM_ENABLE_N71_92INCOMINGINFO
+ return ERR_SOURCENOTAVAILABLE;
+#else
+ return NOKIA_SetIncomingUSSD(s,enable);
+#endif
+}
+
+static GSM_Error N7110_SetIncomingSMS(GSM_StateMachine *s, gboolean enable)
+{
+#ifndef GSM_ENABLE_N71_92INCOMINGINFO
+ return ERR_SOURCENOTAVAILABLE;
+#else
+ return NOKIA_SetIncomingSMS(s,enable);
+#endif
+}
+
+GSM_Error N7110_AnswerCall(GSM_StateMachine *s, int ID, gboolean all)
+{
+ if (!all) return DCT3DCT4_AnswerCall(s,ID);
+ return DCT3_AnswerAllCalls(s);
+}
+
+GSM_Error N7110_SetCallDivert(GSM_StateMachine *s, GSM_CallDivert *divert)
+{
+ GSM_Error error;
+ int i;
+
+ /* No answer from phone side */
+ i = s->ReplyNum;
+ s->ReplyNum = 1;
+ error = DCT3DCT4_SetCallDivert(s,divert);
+ s->ReplyNum = i;
+ return error;
+}
+
+GSM_Error N7110_CancelAllDiverts(GSM_StateMachine *s)
+{
+ GSM_Error error;
+ int i;
+
+ /* No answer from phone side */
+ i = s->ReplyNum;
+ s->ReplyNum = 1;
+ error = DCT3DCT4_CancelAllDiverts(s);
+ s->ReplyNum = i;
+ return error;
+}
+
+static GSM_Reply_Function N7110ReplyFunctions[] = {
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x02,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x03,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x04,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x05,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x07,ID_AnswerCall },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x07,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x09,ID_CancelCall },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x09,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x0A,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x0B,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x0C,ID_IncomingFrame },
+ {N71_65_ReplySendDTMF, "\x01",0x03,0x51,ID_SendDTMF },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x53,ID_IncomingFrame },
+ {N71_65_ReplySendDTMF, "\x01",0x03,0x59,ID_SendDTMF },
+ {N71_65_ReplySendDTMF, "\x01",0x03,0x5E,ID_SendDTMF },
+
+ {DCT3_ReplySendSMSMessage, "\x02",0x03,0x02,ID_IncomingFrame },
+ {DCT3_ReplySendSMSMessage, "\x02",0x03,0x03,ID_IncomingFrame },
+ {N7110_ReplyIncomingSMS, "\x02",0x03,0x10,ID_IncomingFrame },
+#ifdef GSM_ENABLE_CELLBROADCAST
+ {DCT3_ReplySetIncomingCB, "\x02",0x03,0x21,ID_SetIncomingCB },
+ {DCT3_ReplySetIncomingCB, "\x02",0x03,0x22,ID_SetIncomingCB },
+ {DCT3_ReplyIncomingCB, "\x02",0x03,0x23,ID_IncomingFrame },
+#endif
+ {DCT3_ReplySetSMSC, "\x02",0x03,0x31,ID_SetSMSC },
+ {DCT3_ReplyGetSMSC, "\x02",0x03,0x34,ID_GetSMSC },
+ {DCT3_ReplyGetSMSC, "\x02",0x03,0x35,ID_GetSMSC },
+#ifdef GSM_ENABLE_CELLBROADCAST
+ {DCT3_ReplySetIncomingCB, "\x02",0x03,0xCA,ID_SetIncomingCB },
+#endif
+
+ {N7110_ReplyGetMemoryStatus, "\x03",0x03,0x04,ID_GetMemoryStatus },
+ {N7110_ReplyGetMemory, "\x03",0x03,0x08,ID_GetMemory },
+ {N71_65_ReplyWritePhonebook, "\x03",0x03,0x0C,ID_SetBitmap },
+ {N71_65_ReplyWritePhonebook, "\x03",0x03,0x0C,ID_SetMemory },
+ {N7110_ReplyDeleteMemory, "\x03",0x03,0x10,ID_SetMemory },
+
+ {N71_65_ReplyUSSDInfo, "\x06",0x03,0x03,ID_IncomingFrame },
+ {NoneReply, "\x06",0x03,0x06,ID_IncomingFrame },
+
+ {DCT3_ReplySIMLogin, "\x09",0x03,0x80,ID_IncomingFrame },
+ {DCT3_ReplySIMLogout, "\x09",0x03,0x81,ID_IncomingFrame },
+
+ {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_GetNetworkInfo },
+ {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_GetBitmap },
+ {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_IncomingFrame },
+ {N7110_ReplyGetNetworkInfoError, "\x0A",0x03,0x72,ID_GetNetworkInfo },
+ {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x73,ID_IncomingFrame },
+ {N71_92_ReplyGetSignalQuality, "\x0A",0x03,0x82,ID_GetSignalQuality },
+ {N7110_ReplySetOperatorLogo, "\x0A",0x03,0xA4,ID_SetBitmap },
+ {N7110_ReplyClearOperatorLogo, "\x0A",0x03,0xB0,ID_SetBitmap },
+ {NoneReply, "\x0A",0x03,0xB5,ID_IncomingFrame },
+
+#ifdef DEBUG
+ {N71_65_ReplyAddCalendar1, "\x13",0x03,0x02,ID_SetCalendarNote },/*method 1*/
+ {N71_65_ReplyAddCalendar1, "\x13",0x03,0x04,ID_SetCalendarNote },/*method 1*/
+ {N71_65_ReplyAddCalendar1, "\x13",0x03,0x06,ID_SetCalendarNote },/*method 1*/
+ {N71_65_ReplyAddCalendar1, "\x13",0x03,0x08,ID_SetCalendarNote },/*method 1*/
+#endif
+ {N71_65_ReplyDelCalendar, "\x13",0x03,0x0C,ID_DeleteCalendarNote },
+ {N71_65_ReplyGetNextCalendar1, "\x13",0x03,0x1A,ID_GetCalendarNote },/*method 1*/
+#ifdef DEBUG
+ {N7110_ReplyGetCalendarNotePos, "\x13",0x03,0x32,ID_GetCalendarNotePos },/*method 1*/
+#endif
+ {N7110_ReplyGetCalendarInfo, "\x13",0x03,0x3B,ID_GetCalendarNotesInfo},/*method 1*/
+#ifdef DEBUG
+ {N71_65_ReplyGetNextCalendar2, "\x13",0x03,0x3F,ID_GetCalendarNote },/*method 2*/
+#endif
+ {N71_65_ReplyAddCalendar2, "\x13",0x03,0x41,ID_SetCalendarNote },/*method 2*/
+
+ {N7110_ReplySaveSMSMessage, "\x14",0x03,0x05,ID_SaveSMSMessage },
+ {N7110_ReplySaveSMSMessage, "\x14",0x03,0x06,ID_SaveSMSMessage },
+ {N7110_ReplyGetSMSMessage, "\x14",0x03,0x08,ID_GetSMSMessage },
+ {N7110_ReplyGetSMSMessage, "\x14",0x03,0x08,ID_GetBitmap },
+ {N7110_ReplyGetSMSMessage, "\x14",0x03,0x09,ID_GetSMSMessage },
+ {DCT3_ReplyDeleteSMSMessage, "\x14",0x03,0x0B,ID_DeleteSMSMessage },
+ {DCT3_ReplyDeleteSMSMessage, "\x14",0x03,0x0C,ID_DeleteSMSMessage },
+ {N7110_ReplyGetSMSStatus, "\x14",0x03,0x37,ID_GetSMSStatus },
+ {N7110_ReplyGetSMSStatus, "\x14",0x03,0x38,ID_GetSMSStatus },
+ {N7110_ReplySetPicture, "\x14",0x03,0x51,ID_SetBitmap },
+ {N7110_ReplyGetSMSFolderStatus, "\x14",0x03,0x6C,ID_GetSMSFolderStatus },
+ {N7110_ReplyGetSMSMessage, "\x14",0x03,0x6F,ID_GetSMSMessage },
+ {N7110_ReplyGetSMSFolders, "\x14",0x03,0x7B,ID_GetSMSFolders },
+ {N7110_ReplyGetSMSFolders, "\x14",0x03,0x7C,ID_GetSMSFolders },
+ {N7110_ReplySaveSMSMessage, "\x14",0x03,0x84,ID_SaveSMSMessage },
+ {N7110_ReplyGetPictureImageInfo, "\x14",0x03,0x97,ID_GetBitmap },
+ {N7110_ReplyGetSMSFolders, "\x14",0x03,0xCA,ID_GetSMSFolders },
+
+ {N71_92_ReplyGetBatteryCharge, "\x17",0x03,0x03,ID_GetBatteryCharge },
+
+ {DCT3_ReplySetDateTime, "\x19",0x03,0x61,ID_SetDateTime },
+ {DCT3_ReplyGetDateTime, "\x19",0x03,0x63,ID_GetDateTime },
+ {DCT3_ReplySetAlarm, "\x19",0x03,0x6C,ID_SetAlarm },
+ {DCT3_ReplyGetAlarm, "\x19",0x03,0x6E,ID_GetAlarm },
+
+ {N7110_ReplyGetRingtone, "\x1f",0x03,0x23,ID_GetRingtone },
+ {N7110_ReplyGetRingtone, "\x1f",0x03,0x24,ID_GetRingtone },
+
+ {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x01,ID_EnableConnectFunc },
+ {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x02,ID_EnableConnectFunc },
+ {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x04,ID_DisableConnectFunc },
+ {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x05,ID_DisableConnectFunc },
+ {DCT3_ReplyGetWAPBookmark, "\x3f",0x03,0x07,ID_GetWAPBookmark },
+ {DCT3_ReplyGetWAPBookmark, "\x3f",0x03,0x08,ID_GetWAPBookmark },
+ {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0A,ID_SetWAPBookmark },
+ {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0B,ID_SetWAPBookmark },
+ {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0D,ID_DeleteWAPBookmark },
+ {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0E,ID_DeleteWAPBookmark },
+ {DCT3DCT4_ReplyGetActiveConnectSet,"\x3f",0x03,0x10,ID_GetConnectSet },
+ {DCT3DCT4_ReplySetActiveConnectSet,"\x3f",0x03,0x13,ID_SetConnectSet },
+ {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x16,ID_GetConnectSet },
+ {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x17,ID_GetConnectSet },
+ {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x19,ID_SetConnectSet },
+ {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x1A,ID_SetConnectSet },
+ {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x1C,ID_GetConnectSet },
+ {DCT3_ReplyGetWAPSettings, "\x3f",0x03,0x1D,ID_GetConnectSet },
+ {DCT3_ReplySetWAPSettings, "\x3f",0x03,0x1F,ID_SetConnectSet },
+
+ {N7110_ReplyGetProfileFeature, "\x39",0x03,0x02,ID_GetProfile },
+ {N7110_ReplySetProfileFeature, "\x39",0x03,0x04,ID_SetProfile },
+
+ {DCT3_ReplyEnableSecurity, "\x40",0x02,0x64,ID_EnableSecurity },
+ {N61_71_ReplyResetPhoneSettings, "\x40",0x02,0x65,ID_ResetPhoneSettings },
+ {DCT3_ReplyGetIMEI, "\x40",0x02,0x66,ID_GetIMEI },
+ {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_DialVoice },
+ {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_CancelCall },
+ {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_AnswerCall },
+ {DCT3_ReplyNetmonitor, "\x40",0x02,0x7E,ID_Netmonitor },
+ {DCT3_ReplyPlayTone, "\x40",0x02,0x8F,ID_PlayTone },
+ {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetHardware },
+ {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetPPM },
+ {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCA,ID_GetProductCode },
+ {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetManufactureMonth },
+ {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetOriginalIMEI },
+ {NoneReply, "\x40",0x02,0xFF,ID_IncomingFrame },
+
+ {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x02,ID_GetBitmap },
+ {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x02,ID_SetBitmap },
+ {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x15,ID_GetBitmap },
+ {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x15,ID_SetBitmap },
+ {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x17,ID_GetBitmap },
+ {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x17,ID_SetBitmap },
+
+ {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetModel },
+ {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetFirmware },
+ {DCT3_ReplyPressKey, "\xD2",0x02,0x46,ID_PressKey },
+ {DCT3_ReplyPressKey, "\xD2",0x02,0x47,ID_PressKey },
+
+ {NULL, "\x00",0x00,0x00,ID_None }
+};
+
+GSM_Phone_Functions N7110Phone = {
+ "6210|6250|7110|7190",
+ N7110ReplyFunctions,
+ NOTSUPPORTED, /* Install */
+ N7110_Initialise,
+ PHONE_Terminate,
+ GSM_DispatchMessage,
+ NOTSUPPORTED, /* ShowStartInfo */
+ NOKIA_GetManufacturer,
+ DCT3DCT4_GetModel,
+ DCT3DCT4_GetFirmware,
+ DCT3_GetIMEI,
+ DCT3_GetOriginalIMEI,
+ DCT3_GetManufactureMonth,
+ DCT3_GetProductCode,
+ DCT3_GetHardware,
+ DCT3_GetPPM,
+ NOTSUPPORTED, /* GetSIMIMSI */
+ N71_92_GetDateTime,
+ N71_92_SetDateTime,
+ N7110_GetAlarm,
+ N7110_SetAlarm,
+ NOTSUPPORTED, /* GetLocale */
+ NOTSUPPORTED, /* SetLocale */
+ DCT3_PressKey,
+ DCT3_Reset,
+ N61_71_ResetPhoneSettings,
+ NOTSUPPORTED, /* EnterSecurityCode */
+ NOTSUPPORTED, /* GetSecurityStatus */
+ NOTSUPPORTED, /* GetDisplayStatus */
+ NOTIMPLEMENTED, /* SetAutoNetworkLogin */
+ N71_92_GetBatteryCharge,
+ N71_92_GetSignalQuality,
+ DCT3_GetNetworkInfo,
+ NOTSUPPORTED, /* GetCategory */
+ NOTSUPPORTED, /* AddCategory */
+ NOTSUPPORTED, /* GetCategoryStatus */
+ N7110_GetMemoryStatus,
+ N7110_GetMemory,
+ NOTIMPLEMENTED, /* GetNextMemory */
+ N7110_SetMemory,
+ NOTIMPLEMENTED, /* AddMemory */
+ N7110_DeleteMemory,
+ NOTIMPLEMENTED, /* DeleteAllMemory */
+ N7110_GetSpeedDial,
+ NOTIMPLEMENTED, /* SetSpeedDial */
+ DCT3_GetSMSC,
+ DCT3_SetSMSC,
+ N7110_GetSMSStatus,
+ N7110_GetSMSMessage,
+ N7110_GetNextSMSMessage,
+ N7110_SetSMS,
+ N7110_AddSMS,
+ N7110_DeleteSMS,
+ DCT3_SendSMSMessage,
+ NOTSUPPORTED, /* SendSavedSMS */
+ NOTSUPPORTED, /* SetFastSMSSending */
+ N7110_SetIncomingSMS,
+ DCT3_SetIncomingCB,
+ N7110_GetSMSFolders,
+ NOTIMPLEMENTED, /* AddSMSFolder */
+ NOTIMPLEMENTED, /* DeleteSMSFolder */
+ DCT3_DialVoice,
+ NOTIMPLEMENTED, /* DialService */
+ N7110_AnswerCall,
+ DCT3_CancelCall,
+ NOTIMPLEMENTED, /* HoldCall */
+ NOTIMPLEMENTED, /* UnholdCall */
+ NOTIMPLEMENTED, /* ConferenceCall */
+ NOTIMPLEMENTED, /* SplitCall */
+ NOTIMPLEMENTED, /* TransferCall */
+ NOTIMPLEMENTED, /* SwitchCall */
+ NOTSUPPORTED, /* GetCallDivert */
+ N7110_SetCallDivert,
+ N7110_CancelAllDiverts,
+ N7110_SetIncomingCall,
+ N7110_SetIncomingUSSD,
+ DCT3DCT4_SendDTMF,
+ N7110_GetRingtone,
+ N7110_SetRingtone,
+ NOTSUPPORTED, /* GetRingtonesInfo */
+ NOTSUPPORTED, /* DeleteUserRingtones */
+ DCT3_PlayTone,
+ DCT3_GetWAPBookmark,
+ DCT3_SetWAPBookmark,
+ DCT3_DeleteWAPBookmark,
+ DCT3_GetWAPSettings,
+ DCT3_SetWAPSettings,
+ NOTSUPPORTED, /* GetSyncMLSettings */
+ NOTSUPPORTED, /* SetSyncMLSettings */
+ NOTSUPPORTED, /* GetChatSettings */
+ NOTSUPPORTED, /* SetChatSettings */
+ NOTSUPPORTED, /* GetMMSSettings */
+ NOTSUPPORTED, /* SetMMSSettings */
+ NOTSUPPORTED, /* GetMMSFolders */
+ NOTSUPPORTED, /* GetNextMMSFileInfo */
+ N7110_GetBitmap,
+ N7110_SetBitmap,
+ NOTSUPPORTED, /* GetToDoStatus */
+ NOTSUPPORTED, /* GetToDo */
+ NOTSUPPORTED, /* GetNextToDo */
+ NOTSUPPORTED, /* SetToDo */
+ NOTSUPPORTED, /* AddToDo */
+ NOTSUPPORTED, /* DeleteToDo */
+ NOTSUPPORTED, /* DeleteAllToDo */
+ N7110_GetCalendarStatus,
+ NOTIMPLEMENTED, /* GetCalendar */
+ N7110_GetNextCalendar,
+ NOTIMPLEMENTED, /* SetCalendar */
+ N7110_AddCalendar,
+ N71_65_DelCalendar,
+ NOTIMPLEMENTED, /* DeleteAllCalendar */
+ NOTSUPPORTED, /* GetCalendarSettings */
+ NOTSUPPORTED, /* SetCalendarSettings */
+ NOTSUPPORTED, /* GetNoteStatus */
+ NOTSUPPORTED, /* GetNote */
+ NOTSUPPORTED, /* GetNextNote */
+ NOTSUPPORTED, /* SetNote */
+ NOTSUPPORTED, /* AddNote */
+ NOTSUPPORTED, /* DeleteNote */
+ NOTSUPPORTED, /* DeleteAllNotes */
+ N7110_GetProfile,
+ N7110_SetProfile,
+ NOTSUPPORTED, /* GetFMStation */
+ NOTSUPPORTED, /* SetFMStation */
+ NOTSUPPORTED, /* ClearFMStations */
+ NOTSUPPORTED, /* GetNextFileFolder */
+ NOTSUPPORTED, /* GetFolderListing */
+ NOTSUPPORTED, /* GetNextRootFolder */
+ NOTSUPPORTED, /* SetFileAttributes */
+ NOTSUPPORTED, /* GetFilePart */
+ NOTSUPPORTED, /* AddFile */
+ NOTSUPPORTED, /* SendFilePart */
+ NOTSUPPORTED, /* GetFileSystemStatus */
+ NOTSUPPORTED, /* DeleteFile */
+ NOTSUPPORTED, /* AddFolder */
+ NOTSUPPORTED, /* DeleteFolder */
+ NOTSUPPORTED, /* GetGPRSAccessPoint */
+ NOTSUPPORTED, /* SetGPRSAccessPoint */
+ NOTSUPPORTED, /* GetScreenshot */
+ NOTSUPPORTED, /* SetPower */
+ NOTSUPPORTED, /* PostConnect */
+ NONEFUNCTION /* PreAPICall */
+};
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct3/n7110.h b/libgammu/phone/nokia/dct3/n7110.h
new file mode 100644
index 0000000..a7934c2
--- /dev/null
+++ b/libgammu/phone/nokia/dct3/n7110.h
@@ -0,0 +1,45 @@
+/* (c) 2002-2003 by Marcin Wiacek */
+
+#ifndef n7110_h
+#define n7110_h
+
+#include "../ncommon.h"
+#include "dct3comm.h"
+
+typedef struct {
+ int LastCalendarYear;
+ int LastCalendarPos;
+ GSM_NOKIACalToDoLocations LastCalendar;
+ int FirstCalendarPos;
+
+ GSM_NOKIASMSFolder LastSMSFolder;
+ GSM_SMSFolders LastSMSFolders;
+ GSM_NOKIASMSFolder LastPictureImageFolder;
+
+ DCT3_WAPSettings_Locations WAPLocations;
+} GSM_Phone_N7110Data;
+
+#ifndef GSM_USED_MBUS2
+# define GSM_USED_MBUS2
+#endif
+#ifndef GSM_USED_FBUS2
+# define GSM_USED_FBUS2
+#endif
+#ifndef GSM_USED_FBUS2DLR3
+# define GSM_USED_FBUS2DLR3
+#endif
+#ifndef GSM_USED_FBUS2BLUE
+# define GSM_USED_FBUS2BLUE
+#endif
+#ifndef GSM_USED_IRDAPHONET
+# define GSM_USED_IRDAPHONET
+#endif
+#ifndef GSM_USED_BLUEFBUS2
+# define GSM_USED_BLUEFBUS2
+#endif
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct3/n9210.c b/libgammu/phone/nokia/dct3/n9210.c
new file mode 100644
index 0000000..c0860d7
--- /dev/null
+++ b/libgammu/phone/nokia/dct3/n9210.c
@@ -0,0 +1,419 @@
+/* (c) 2002-2003 by Marcin Wiacek */
+
+#include <gammu-config.h>
+
+#ifdef GSM_ENABLE_NOKIA9210
+
+#include <string.h>
+#include <time.h>
+
+#include "../../../misc/coding/coding.h"
+#include "../../../gsmcomon.h"
+#include "../../../service/gsmlogo.h"
+#include "../../../service/gsmnet.h"
+#include "../../../service/sms/gsmmulti.h"
+#include "../../pfunc.h"
+#include "../nfunc.h"
+#include "n9210.h"
+#include "dct3func.h"
+
+static GSM_Error N9210_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
+{
+ unsigned char OpReq[] = {N6110_FRAME_HEADER, 0x70};
+
+ s->Phone.Data.Bitmap=Bitmap;
+ switch (Bitmap->Type) {
+ case GSM_OperatorLogo:
+ smprintf(s, "Getting operator logo\n");
+ /* This is like DCT3_GetNetworkInfo */
+ return GSM_WaitFor (s, OpReq, 4, 0x0a, 4, ID_GetBitmap);
+ case GSM_StartupLogo:
+ smprintf(s, "Getting startup logo\n");
+ return N71_92_GetPhoneSetting(s, ID_GetBitmap, 0x15);
+ case GSM_WelcomeNote_Text:
+ smprintf(s, "Getting welcome note\n");
+ return N71_92_GetPhoneSetting(s, ID_GetBitmap, 0x02);
+ default:
+ break;
+ }
+ return ERR_NOTSUPPORTED;
+}
+
+static GSM_Error N9210_ReplySetOpLogo(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Operator logo clear/set\n");
+ return ERR_NONE;
+}
+
+static GSM_Error N9210_SetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
+{
+ GSM_Error error;
+ GSM_Phone_Bitmap_Types Type;
+ size_t Width, Height, i,count=3;
+ unsigned char req[600] = { N7110_FRAME_HEADER };
+ unsigned char reqStartup[1000] = {
+ N6110_FRAME_HEADER, 0xec,
+ 0x15, /* Startup Logo setting */
+ 0x04, 0x00, 0x00, 0x00, 0x30, 0x00,
+ 0x02, 0xc0, 0x54, 0x00, 0x03, 0xc0,
+ 0xf8, 0xf8, 0x01, 0x04};
+ unsigned char reqStartupText[500] = {
+ N7110_FRAME_HEADER, 0xec,
+ 0x02}; /* Startup Text setting */
+ unsigned char reqClrOp[] = {
+ N7110_FRAME_HEADER, 0xAF,
+ 0x02}; /* Number of logo = 0 - 0x04 */
+
+ switch (Bitmap->Type) {
+ case GSM_StartupLogo:
+ if (Bitmap->Location!=1) return ERR_NOTSUPPORTED;
+ Type=GSM_NokiaStartupLogo;
+ PHONE_GetBitmapWidthHeight(Type, &Width, &Height);
+ PHONE_EncodeBitmap(Type, reqStartup + 21, Bitmap);
+ smprintf(s, "Setting startup logo\n");
+ return GSM_WaitFor (s, reqStartup, 21+PHONE_GetBitmapSize(Type,0,0), 0x7A, 4, ID_SetBitmap);
+ case GSM_WelcomeNote_Text:
+ /* Nokia bug: Unicode text is moved one char to left */
+ CopyUnicodeString(reqStartupText + 4, Bitmap->Text);
+ reqStartupText[4] = 0x02;
+ i = 5 + UnicodeLength(Bitmap->Text) * 2;
+ reqStartupText[i++] = 0;
+ reqStartupText[i++] = 0;
+ return GSM_WaitFor (s, reqStartupText, i, 0x7A, 4, ID_SetBitmap);
+ case GSM_OperatorLogo:
+ /* First part for clearing logo */
+ if (!strcmp(Bitmap->NetworkCode,"000 00")) {
+ for (i=0;i<5;i++) {
+ reqClrOp[4] = i;
+ error=GSM_WaitFor (s, reqClrOp, 5, 0x0A, 4, ID_SetBitmap);
+ if (error != ERR_NONE) return error;
+ }
+ }
+ Type=GSM_NokiaOperatorLogo;
+ req[count++] = 0xA3;
+ req[count++] = 0x01;
+ req[count++] = 0x00; /* Logo removed */
+ NOKIA_EncodeNetworkCode(req+count, "000 00");
+ count = count + 3;
+ req[count++] = 0x00;
+ req[count++] = 0x04;
+ req[count++] = 0x08; /* Length of rest + 2 */
+ memcpy(req+count, "\x00\x00\x00\x00\x00\x00", 6);
+ count += 6;
+ error=GSM_WaitFor (s, req, count, 0x0A, 4, ID_SetBitmap);
+ if (error != ERR_NONE) return error;
+ /* We wanted only clear - now exit */
+ if (!strcmp(Bitmap->NetworkCode,"000 00")) return error;
+
+ /* Now setting logo */
+ count=3;
+ req[count++] = 0xA3;
+ req[count++] = 0x01;
+ req[count++] = 0x01; /* Logo set */
+ NOKIA_EncodeNetworkCode(req+count, Bitmap->NetworkCode);
+ count = count + 3;
+ req[count++] = 0x00;
+ req[count++] = 0x04;
+ req[count++] = PHONE_GetBitmapSize(Type,0,0)+8;
+ PHONE_GetBitmapWidthHeight(Type, &Width, &Height);
+ req[count++] = Width;
+ req[count++] = Height;
+ req[count++] = PHONE_GetBitmapSize(Type,0,0);
+ req[count++] = 0x00;
+ req[count++] = 0x00;
+ req[count++] = 0x00;
+ PHONE_EncodeBitmap(Type, req+count, Bitmap);
+ return GSM_WaitFor (s, req, count+PHONE_GetBitmapSize(Type,0,0), 0x0A, 4, ID_SetBitmap);
+ default:
+ break;
+ }
+ return ERR_NOTSUPPORTED;
+}
+
+static GSM_Error N9210_ReplyIncomingSMS(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_SMSMessage sms;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+#ifdef DEBUG
+ smprintf(s, "SMS message received\n");
+ sms.State = SMS_UnRead;
+ sms.InboxFolder = TRUE;
+ DCT3_DecodeSMSFrame(s, &sms,msg->Buffer+5);
+#endif
+ if (Data->EnableIncomingSMS && s->User.IncomingSMS!=NULL) {
+ sms.State = SMS_UnRead;
+ sms.InboxFolder = TRUE;
+ DCT3_DecodeSMSFrame(s, &sms,msg->Buffer+5);
+
+ s->User.IncomingSMS(s, &sms, s->User.IncomingSMSUserData);
+ }
+ return ERR_NONE;
+}
+
+#ifdef GSM_ENABLE_N71_92INCOMINGINFO
+static GSM_Error N9210_ReplySetIncomingSMS(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x0e:
+ s->Phone.Data.EnableIncomingSMS = TRUE;
+ smprintf(s, "Incoming SMS enabled\n");
+ return ERR_NONE;
+ case 0x0f:
+ smprintf(s, "Error enabling incoming SMS\n");
+ switch (msg->Buffer[4]) {
+ case 0x0c:
+ smprintf(s, "No PIN ?\n");
+ return ERR_SECURITYERROR;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ }
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N9210_SetIncomingSMS(GSM_StateMachine *s, gboolean enable)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x0d, 0x00, 0x00, 0x02};
+
+ if (enable!=s->Phone.Data.EnableIncomingSMS) {
+ if (enable) {
+ smprintf(s, "Enabling incoming SMS\n");
+ return GSM_WaitFor (s, req, 7, 0x02, 4, ID_SetIncomingSMS);
+ } else {
+ s->Phone.Data.EnableIncomingSMS = FALSE;
+ smprintf(s, "Disabling incoming SMS\n");
+ }
+ }
+ return ERR_NONE;
+}
+#else
+static GSM_Error N9210_SetIncomingSMS(GSM_StateMachine *s UNUSED, gboolean enable UNUSED)
+{
+ return ERR_SOURCENOTAVAILABLE;
+}
+#endif
+
+static GSM_Error N9210_Initialise (GSM_StateMachine *s)
+{
+#ifdef DEBUG
+ DCT3_SetIncomingCB(s,TRUE);
+
+#ifdef GSM_ENABLE_N71_92INCOMINGINFO
+ N9210_SetIncomingSMS(s,TRUE);
+#endif
+
+#endif
+ return ERR_NONE;
+}
+
+GSM_Error N9210_AnswerCall(GSM_StateMachine *s, int ID, gboolean all)
+{
+ if (!all) return DCT3DCT4_AnswerCall(s,ID);
+ return DCT3_AnswerAllCalls(s);
+}
+
+static GSM_Reply_Function N9210ReplyFunctions[] = {
+ {DCT3_ReplySendSMSMessage, "\x02",0x03,0x02,ID_IncomingFrame },
+ {DCT3_ReplySendSMSMessage, "\x02",0x03,0x03,ID_IncomingFrame },
+#ifdef GSM_ENABLE_N71_92INCOMINGINFO
+ {N9210_ReplySetIncomingSMS, "\x02",0x03,0x0E,ID_SetIncomingSMS },
+ {N9210_ReplySetIncomingSMS, "\x02",0x03,0x0F,ID_SetIncomingSMS },
+#endif
+ {N9210_ReplyIncomingSMS, "\x02",0x03,0x11,ID_IncomingFrame },
+#ifdef GSM_ENABLE_CELLBROADCAST
+ {DCT3_ReplySetIncomingCB, "\x02",0x03,0x21,ID_SetIncomingCB },
+ {DCT3_ReplySetIncomingCB, "\x02",0x03,0x22,ID_SetIncomingCB },
+ {DCT3_ReplyIncomingCB, "\x02",0x03,0x23,ID_IncomingFrame },
+#endif
+ {DCT3_ReplySetSMSC, "\x02",0x03,0x31,ID_SetSMSC },
+ {DCT3_ReplyGetSMSC, "\x02",0x03,0x34,ID_GetSMSC },
+ {DCT3_ReplyGetSMSC, "\x02",0x03,0x35,ID_GetSMSC },
+
+ {N61_91_ReplySetOpLogo, "\x05",0x03,0x31,ID_SetBitmap },
+ {N61_91_ReplySetOpLogo, "\x05",0x03,0x32,ID_SetBitmap },
+
+ {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_GetNetworkInfo },
+ {DCT3_ReplyGetNetworkInfo, "\x0A",0x03,0x71,ID_IncomingFrame },
+ {N71_92_ReplyGetSignalQuality, "\x0A",0x03,0x82,ID_GetSignalQuality },
+ {N9210_ReplySetOpLogo, "\x0A",0x03,0xA4,ID_SetBitmap },
+ {N9210_ReplySetOpLogo, "\x0A",0x03,0xB0,ID_SetBitmap },
+
+ {N71_92_ReplyGetBatteryCharge, "\x17",0x03,0x03,ID_GetBatteryCharge },
+
+ {DCT3_ReplySetDateTime, "\x19",0x03,0x61,ID_SetDateTime },
+ {DCT3_ReplyGetDateTime, "\x19",0x03,0x63,ID_GetDateTime },
+
+ {DCT3_ReplyEnableSecurity, "\x40",0x02,0x64,ID_EnableSecurity },
+ {DCT3_ReplyGetIMEI, "\x40",0x02,0x66,ID_GetIMEI },
+ {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_DialVoice },
+ {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_CancelCall },
+ {DCT3_ReplyDialCommand, "\x40",0x02,0x7C,ID_AnswerCall },
+ {DCT3_ReplyNetmonitor, "\x40",0x02,0x7E,ID_Netmonitor },
+ {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetHardware },
+ {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xC8,ID_GetPPM },
+ {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCA,ID_GetProductCode },
+ {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetManufactureMonth },
+ {NOKIA_ReplyGetPhoneString, "\x40",0x02,0xCC,ID_GetOriginalIMEI },
+
+ {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x02,ID_GetBitmap },
+ {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x02,ID_SetBitmap },
+ {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x15,ID_GetBitmap },
+ {N71_92_ReplyPhoneSetting, "\x7a",0x04,0x15,ID_SetBitmap },
+
+ {DCT3DCT4_ReplyGetModelFirmware,"\xD2",0x02,0x00,ID_GetModel },
+ {DCT3DCT4_ReplyGetModelFirmware,"\xD2",0x02,0x00,ID_GetFirmware },
+
+ {NULL, "\x00",0x00,0x00,ID_None }
+};
+
+GSM_Phone_Functions N9210Phone = {
+ "9210|9210i",
+ N9210ReplyFunctions,
+ NOTSUPPORTED, /* Install */
+ N9210_Initialise,
+ PHONE_Terminate,
+ GSM_DispatchMessage,
+ NOTSUPPORTED, /* ShowStartInfo */
+ NOKIA_GetManufacturer,
+ DCT3DCT4_GetModel,
+ DCT3DCT4_GetFirmware,
+ DCT3_GetIMEI,
+ DCT3_GetOriginalIMEI,
+ DCT3_GetManufactureMonth,
+ DCT3_GetProductCode,
+ DCT3_GetHardware,
+ DCT3_GetPPM,
+ NOTSUPPORTED, /* GetSIMIMSI */
+ N71_92_GetDateTime,
+ N71_92_SetDateTime,
+ NOTIMPLEMENTED, /* GetAlarm */
+ NOTIMPLEMENTED, /* SetAlarm */
+ NOTSUPPORTED, /* GetLocale */
+ NOTSUPPORTED, /* SetLocale */
+ NOTIMPLEMENTED, /* PressKey */
+ NOTIMPLEMENTED, /* Reset */
+ NOTIMPLEMENTED, /* ResetPhoneSettings */
+ NOTSUPPORTED, /* EnterSecurityCode */
+ NOTSUPPORTED, /* GetSecurityStatus */
+ NOTSUPPORTED, /* GetDisplayStatus */
+ NOTIMPLEMENTED, /* SetAutoNetworkLogin */
+ N71_92_GetBatteryCharge,
+ N71_92_GetSignalQuality,
+ DCT3_GetNetworkInfo,
+ NOTSUPPORTED, /* GetCategory */
+ NOTSUPPORTED, /* AddCategory */
+ NOTSUPPORTED, /* GetCategoryStatus */
+ NOTIMPLEMENTED, /* GetMemoryStatus */
+ NOTIMPLEMENTED, /* GetMemory */
+ NOTIMPLEMENTED, /* GetNextMemory */
+ NOTIMPLEMENTED, /* SetMemory */
+ NOTIMPLEMENTED, /* AddMemory */
+ NOTIMPLEMENTED, /* DeleteMemory */
+ NOTIMPLEMENTED, /* DeleteAllMemory */
+ NOTIMPLEMENTED, /* GetSpeedDial */
+ NOTIMPLEMENTED, /* SetSpeedDial */
+ DCT3_GetSMSC,
+ DCT3_SetSMSC, /* FIXME: test it */
+ NOTIMPLEMENTED, /* GetSMSStatus */
+ NOTIMPLEMENTED, /* GetSMS */
+ NOTIMPLEMENTED, /* GetNextSMS */
+ NOTIMPLEMENTED, /* SetSMS */
+ NOTIMPLEMENTED, /* AddSMS */
+ NOTIMPLEMENTED, /* DeleteSMS */
+ DCT3_SendSMSMessage,
+ NOTSUPPORTED, /* SendSavedSMS */
+ NOTSUPPORTED, /* SetFastSMSSending */
+ N9210_SetIncomingSMS,
+ DCT3_SetIncomingCB,
+ NOTIMPLEMENTED, /* GetSMSFolders */
+ NOTSUPPORTED, /* AddSMSFolder */
+ NOTSUPPORTED, /* DeleteSMSFolder */
+ DCT3_DialVoice,
+ NOTIMPLEMENTED, /* DialService */
+ N9210_AnswerCall,
+ DCT3_CancelCall,
+ NOTSUPPORTED, /* HoldCall */
+ NOTSUPPORTED, /* UnholdCall */
+ NOTSUPPORTED, /* ConferenceCall */
+ NOTSUPPORTED, /* SplitCall */
+ NOTSUPPORTED, /* TransferCall */
+ NOTSUPPORTED, /* SwitchCall */
+ NOTSUPPORTED, /* GetCallDivert */
+ NOTSUPPORTED, /* SetCallDivert */
+ NOTSUPPORTED, /* CancelAllDiverts */
+ NOTSUPPORTED, /* SetIncomingCall */
+ NOTIMPLEMENTED, /* SetIncomingUSSD */
+ NOTSUPPORTED, /* SendDTMF */
+ NOTIMPLEMENTED, /* GetRingtone */
+ NOTIMPLEMENTED, /* SetRingtone */
+ NOTSUPPORTED, /* GetRingtonesInfo */
+ NOTSUPPORTED, /* DeleteUserRingtones */
+ NOTSUPPORTED, /* PlayTone */
+ NOTIMPLEMENTED, /* GetWAPBookmark */
+ NOTIMPLEMENTED, /* SetWAPBookmark */
+ NOTIMPLEMENTED, /* DeleteWAPBookmark */
+ NOTIMPLEMENTED, /* GetWAPSettings */
+ NOTSUPPORTED, /* SetWAPSettings */
+ NOTSUPPORTED, /* GetSyncMLSettings */
+ NOTSUPPORTED, /* SetSyncMLSettings */
+ NOTSUPPORTED, /* GetChatSettings */
+ NOTSUPPORTED, /* SetChatSettings */
+ NOTSUPPORTED, /* GetMMSSettings */
+ NOTSUPPORTED, /* SetMMSSettings */
+ NOTSUPPORTED, /* GetMMSFolders */
+ NOTSUPPORTED, /* GetNextMMSFileInfo */
+ N9210_GetBitmap,
+ N9210_SetBitmap,
+ NOTSUPPORTED, /* GetToDoStatus */
+ NOTSUPPORTED, /* GetToDo */
+ NOTSUPPORTED, /* GetNextToDo */
+ NOTSUPPORTED, /* SetToDo */
+ NOTSUPPORTED, /* AddToDo */
+ NOTSUPPORTED, /* DeleteToDo */
+ NOTSUPPORTED, /* DeleteAllToDo */
+ NOTSUPPORTED, /* GetCalendarStatus */
+ NOTSUPPORTED, /* GetCalendar */
+ NOTSUPPORTED, /* GetNextCalendar */
+ NOTSUPPORTED, /* SetCalendar */
+ NOTSUPPORTED, /* AddCalendar */
+ NOTSUPPORTED, /* DeleteCalendar */
+ NOTSUPPORTED, /* DeleteAllCalendar */
+ NOTSUPPORTED, /* GetCalendarSettings */
+ NOTSUPPORTED, /* SetCalendarSettings */
+ NOTSUPPORTED, /* GetNoteStatus */
+ NOTSUPPORTED, /* GetNote */
+ NOTSUPPORTED, /* GetNextNote */
+ NOTSUPPORTED, /* SetNote */
+ NOTSUPPORTED, /* AddNote */
+ NOTSUPPORTED, /* DeleteNote */
+ NOTSUPPORTED, /* DeleteAllNotes */
+ NOTIMPLEMENTED, /* GetProfile */
+ NOTSUPPORTED, /* SetProfile */
+ NOTSUPPORTED, /* GetFMStation */
+ NOTSUPPORTED, /* SetFMStation */
+ NOTSUPPORTED, /* ClearFMStations */
+ NOTSUPPORTED, /* GetNextFileFolder */
+ NOTSUPPORTED, /* GetFolderListing */
+ NOTSUPPORTED, /* GetNextRootFolder */
+ NOTSUPPORTED, /* SetFileAttributes */
+ NOTSUPPORTED, /* GetFilePart */
+ NOTSUPPORTED, /* AddFile */
+ NOTSUPPORTED, /* SendFilePart */
+ NOTSUPPORTED, /* GetFileSystemStatus */
+ NOTSUPPORTED, /* DeleteFile */
+ NOTSUPPORTED, /* AddFolder */
+ NOTSUPPORTED, /* DeleteFolder */
+ NOTSUPPORTED, /* GetGPRSAccessPoint */
+ NOTSUPPORTED, /* SetGPRSAccessPoint */
+ NOTSUPPORTED, /* GetScreenshot */
+ NOTSUPPORTED, /* SetPower */
+ NOTSUPPORTED, /* PostConnect */
+ NONEFUNCTION /* PreAPICall */
+};
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct3/n9210.h b/libgammu/phone/nokia/dct3/n9210.h
new file mode 100644
index 0000000..8998532
--- /dev/null
+++ b/libgammu/phone/nokia/dct3/n9210.h
@@ -0,0 +1,17 @@
+/* (c) 2002-2003 by Marcin Wiacek */
+
+#ifndef n9210_h
+#define n9210_h
+
+#ifndef GSM_USED_MBUS2
+# define GSM_USED_MBUS2
+#endif
+#ifndef GSM_USED_FBUS2
+# define GSM_USED_FBUS2
+#endif
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct4s40/6510/6510cal.c b/libgammu/phone/nokia/dct4s40/6510/6510cal.c
new file mode 100644
index 0000000..a5a70d0
--- /dev/null
+++ b/libgammu/phone/nokia/dct4s40/6510/6510cal.c
@@ -0,0 +1,1353 @@
+/* (c) 2002-2005 by Marcin Wiacek */
+
+#include <gammu-config.h>
+
+#ifdef GSM_ENABLE_NOKIA6510
+
+#include <string.h>
+#include <time.h>
+
+#include "../../../../misc/coding/coding.h"
+#include "../../../../gsmcomon.h"
+#include "../../../../service/gsmlogo.h"
+#include "../../../../service/gsmcal.h"
+#include "../../nfunc.h"
+#include "../../nfuncold.h"
+#include "../../../pfunc.h"
+#include "../dct4func.h"
+#include "n6510.h"
+
+/* method 3 */
+GSM_Error N6510_ReplyGetCalendarInfo3(GSM_Protocol_Message *msg, GSM_StateMachine *s, GSM_NOKIACalToDoLocations *Last)
+{
+ size_t i=0,j=0;
+
+ while (Last->Location[j] != 0x00) j++;
+ if (j >= GSM_MAXCALENDARTODONOTES) {
+ smprintf(s, "Increase GSM_MAXCALENDARTODONOTES\n");
+ return ERR_MOREMEMORY;
+ }
+ if (j == 0) {
+ Last->Number = msg->Buffer[8]*256 + msg->Buffer[9];
+ smprintf(s, "Number of Entries: %i\n", Last->Number);
+ }
+ smprintf(s, "Locations: ");
+ while (14+(i*4) <= msg->Length) {
+ Last->Location[j] = msg->Buffer[12+i*4]*256 + msg->Buffer[13+i*4];
+ smprintf(s, "%i ", Last->Location[j]);
+ i++;
+ j++;
+ }
+ smprintf(s, "\nNumber of Entries in frame: %ld\n", (long)i);
+ Last->Location[j] = 0;
+ smprintf(s, "\n");
+ if (i == 1 && msg->Buffer[12+0*4]*256+msg->Buffer[13+0*4] == 0) return ERR_EMPTY;
+ if (i == 0) return ERR_EMPTY;
+ return ERR_NONE;
+}
+
+/* method 3 */
+GSM_Error N6510_GetCalendarInfo3(GSM_StateMachine *s, GSM_NOKIACalToDoLocations *Last, char Type)
+{
+ GSM_Error error = ERR_UNKNOWN;
+ int i;
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x9E, 0xFF, 0xFF, 0x00, 0x00,
+ 0x00, 0x00, /* First location */
+ 0x00}; /* 0 = calendar, 1 = ToDo in 6610 style, 2 = Notes */
+
+ Last->Location[0] = 0x00;
+ Last->Number = 0;
+
+ req[10] = Type;
+ if (Type == 0) {
+ smprintf(s, "Getting locations for calendar method 3\n");
+ error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetCalendarNotesInfo);
+ } else if (Type == 1) {
+ smprintf(s, "Getting locations for ToDo method 2\n");
+ error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetToDo);
+ } else if (Type == 2) {
+ smprintf(s, "Getting locations for Notes\n");
+ error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetNote);
+ }
+ if (error != ERR_NONE && error != ERR_EMPTY) return error;
+
+ while (1) {
+ i=0;
+ while (Last->Location[i] != 0x00) i++;
+ smprintf(s, "i = %i last_number = %i\n",i,Last->Number);
+ if (i == Last->Number) break;
+ if (i != Last->Number && error == ERR_EMPTY) {
+ smprintf(s, "Phone doesn't support some notes with this method. Workaround\n");
+ Last->Number = i;
+ break;
+ }
+ req[8] = Last->Location[i-1] / 256;
+ req[9] = Last->Location[i-1] % 256;
+ if (Type == 0) {
+ smprintf(s, "Getting locations for calendar method 3\n");
+ error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetCalendarNotesInfo);
+ } else if (Type == 1) {
+ smprintf(s, "Getting locations for todo method 2\n");
+ error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetToDo);
+ } else if (Type == 2) {
+ smprintf(s, "Getting locations for Notes\n");
+ error = GSM_WaitFor (s, req, 11, 0x13, 4, ID_GetNote);
+ }
+ if (error != ERR_NONE && error != ERR_EMPTY) return error;
+ }
+ return ERR_NONE;
+}
+
+/* method 3 */
+GSM_Error N6510_ReplyGetCalendar3(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_CalendarEntry *entry = s->Phone.Data.Cal;
+ unsigned long diff;
+ int i;
+ gboolean found = FALSE;
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ int len;
+
+ smprintf(s, "Calendar note received method 3\n");
+
+ smprintf(s,"Note type %02i: ",msg->Buffer[27]);
+ switch(msg->Buffer[27]) {
+ case 0x00: smprintf(s,"Reminder\n"); entry->Type = GSM_CAL_REMINDER; break;
+ case 0x01: smprintf(s,"Meeting\n"); entry->Type = GSM_CAL_MEETING; break;
+ case 0x02: smprintf(s,"Call\n"); entry->Type = GSM_CAL_CALL; break;
+ case 0x04: smprintf(s,"Birthday\n"); entry->Type = GSM_CAL_BIRTHDAY; break;
+ case 0x08: smprintf(s,"Memo\n"); entry->Type = GSM_CAL_MEMO; break;
+ case 0x20: smprintf(s,"Birthday\n"); entry->Type = GSM_CAL_BIRTHDAY; break;
+ default : smprintf(s,"unknown\n"); entry->Type = GSM_CAL_MEMO;
+ }
+
+ smprintf(s,"StartTime: %04i-%02i-%02i %02i:%02i\n",
+ msg->Buffer[28]*256+msg->Buffer[29],
+ msg->Buffer[30],msg->Buffer[31],msg->Buffer[32],
+ msg->Buffer[33]);
+ GSM_GetCurrentDateTime(&entry->Entries[0].Date);
+ entry->Entries[0].Date.Year = msg->Buffer[28]*256+msg->Buffer[29];
+ if (entry->Type == GSM_CAL_BIRTHDAY) {
+ entry->Entries[0].Date.Year = entry->Entries[0].Date.Year;
+ smprintf(s,"%i\n",entry->Entries[0].Date.Year);
+ }
+ entry->Entries[0].Date.Month = msg->Buffer[30];
+ entry->Entries[0].Date.Day = msg->Buffer[31];
+ entry->Entries[0].Date.Hour = msg->Buffer[32];
+ entry->Entries[0].Date.Minute = msg->Buffer[33];
+ /* Garbage seen with 3510i 3.51 */
+ if (entry->Entries[0].Date.Month == 0 &&
+ entry->Entries[0].Date.Day == 0 &&
+ entry->Entries[0].Date.Hour == 0 &&
+ entry->Entries[0].Date.Minute == 0)
+ return ERR_EMPTY;
+ entry->Entries[0].Date.Second = 0;
+ entry->Entries[0].EntryType = CAL_START_DATETIME;
+ entry->EntriesNum++;
+
+ GSM_GetCalendarRecurranceRepeat(&(s->di), msg->Buffer+40, msg->Buffer+46, entry);
+
+ if (entry->Type != GSM_CAL_BIRTHDAY) {
+ smprintf(s,"EndTime: %04i-%02i-%02i %02i:%02i\n",
+ msg->Buffer[34]*256+msg->Buffer[35],
+ msg->Buffer[36],msg->Buffer[37],msg->Buffer[38],
+ msg->Buffer[39]);
+ entry->Entries[entry->EntriesNum].Date.Year = msg->Buffer[34]*256+msg->Buffer[35];
+ entry->Entries[entry->EntriesNum].Date.Month = msg->Buffer[36];
+ entry->Entries[entry->EntriesNum].Date.Day = msg->Buffer[37];
+ entry->Entries[entry->EntriesNum].Date.Hour = msg->Buffer[38];
+ entry->Entries[entry->EntriesNum].Date.Minute = msg->Buffer[39];
+ entry->Entries[entry->EntriesNum].Date.Second = 0;
+ entry->Entries[entry->EntriesNum].EntryType = CAL_END_DATETIME;
+ entry->EntriesNum++;
+ }
+
+ smprintf(s, "Note icon: %02x\n",msg->Buffer[21]);
+ for(i=0;i<Priv->CalendarIconsNum;i++) {
+ if (Priv->CalendarIconsTypes[i] == entry->Type) {
+ found = TRUE;
+ }
+ }
+ if (!found) {
+ Priv->CalendarIconsTypes[Priv->CalendarIconsNum] = entry->Type;
+ Priv->CalendarIcons [Priv->CalendarIconsNum] = msg->Buffer[21];
+ Priv->CalendarIconsNum++;
+ }
+
+ if (msg->Buffer[14] == 0xFF && msg->Buffer[15] == 0xFF && msg->Buffer[16] == 0xff && msg->Buffer[17] == 0xff) {
+ smprintf(s, "No alarm\n");
+ } else {
+ diff = ((unsigned int)msg->Buffer[14]) << 24;
+ diff += ((unsigned int)msg->Buffer[15]) << 16;
+ diff += ((unsigned int)msg->Buffer[16]) << 8;
+ diff += msg->Buffer[17];
+
+ memcpy(&entry->Entries[entry->EntriesNum].Date,&entry->Entries[0].Date,sizeof(GSM_DateTime));
+ GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, FALSE, 60);
+ smprintf(s, "Alarm date : %02i-%02i-%04i %02i:%02i:%02i\n",
+ entry->Entries[entry->EntriesNum].Date.Day, entry->Entries[entry->EntriesNum].Date.Month,
+ entry->Entries[entry->EntriesNum].Date.Year, entry->Entries[entry->EntriesNum].Date.Hour,
+ entry->Entries[entry->EntriesNum].Date.Minute,entry->Entries[entry->EntriesNum].Date.Second);
+
+ entry->Entries[entry->EntriesNum].EntryType = CAL_TONE_ALARM_DATETIME;
+ if (msg->Buffer[22]==0x00 && msg->Buffer[23]==0x00 &&
+ msg->Buffer[24]==0x00 && msg->Buffer[25]==0x00) {
+ entry->Entries[entry->EntriesNum].EntryType = CAL_SILENT_ALARM_DATETIME;
+ smprintf(s, "Alarm type : Silent\n");
+ }
+ entry->EntriesNum++;
+ }
+
+ if (entry->Type == GSM_CAL_BIRTHDAY) {
+ if (msg->Buffer[42] == 0xff && msg->Buffer[43] == 0xff) {
+ entry->Entries[0].Date.Year = 0;
+ } else {
+ entry->Entries[0].Date.Year = msg->Buffer[42]*256+msg->Buffer[43];
+ }
+ }
+
+ len = msg->Buffer[50] * 256 + msg->Buffer[51];
+ if (len > GSM_MAX_CALENDAR_TEXT_LENGTH) {
+ smprintf(s, "Calendar text too long (%d), truncating to %d\n", len, GSM_MAX_CALENDAR_TEXT_LENGTH);
+ len = GSM_MAX_CALENDAR_TEXT_LENGTH;
+ }
+ memcpy(entry->Entries[entry->EntriesNum].Text,
+ msg->Buffer + 54,
+ len * 2);
+ entry->Entries[entry->EntriesNum].Text[len * 2] = 0;
+ entry->Entries[entry->EntriesNum].Text[len * 2 + 1] = 0;
+ entry->Entries[entry->EntriesNum].EntryType = CAL_TEXT;
+ entry->EntriesNum++;
+ smprintf(s, "Note text: \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum-1].Text));
+
+ if (entry->Type == GSM_CAL_CALL) {
+ memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+(54+msg->Buffer[51]*2), msg->Buffer[52]*2);
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[52]*2] = 0;
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[52]*2+1] = 0;
+ entry->Entries[entry->EntriesNum].EntryType = CAL_PHONE;
+ entry->EntriesNum++;
+ }
+ if (entry->Type == GSM_CAL_MEETING) {
+ memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+(54+msg->Buffer[51]*2), msg->Buffer[52]*2);
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[52]*2] = 0;
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[52]*2+1] = 0;
+ entry->Entries[entry->EntriesNum].EntryType = CAL_LOCATION;
+ entry->EntriesNum++;
+ }
+
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_PrivGetGenericCalendar3(GSM_StateMachine *s, int Location, GSM_Phone_RequestID ID)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER,0x7D,0x00,0x00,0x00,0x00,
+ 0x00,0x99, /* Location */
+ 0xff,0xff,0xff,0xff};
+
+ req[8] = Location / 256;
+ req[9] = Location % 256;
+
+ return GSM_WaitFor (s, req, 14, 0x13, 4, ID);
+}
+
+static GSM_Error N6510_PrivGetCalendar3(GSM_StateMachine *s, GSM_CalendarEntry *Note, gboolean start, int *LastCalendarYear)
+{
+ GSM_Error error;
+ GSM_DateTime date_time;
+
+ if (start) {
+ /* We have to get current year. It's NOT written in frame for
+ * Birthday
+ */
+ error=s->Phone.Functions->GetDateTime(s,&date_time);
+ switch (error) {
+ case ERR_EMPTY:
+ case ERR_NOTIMPLEMENTED:
+ GSM_GetCurrentDateTime(&date_time);
+ break;
+ case ERR_NONE:
+ break;
+ default:
+ return error;
+ }
+ *LastCalendarYear = date_time.Year;
+ }
+
+ Note->EntriesNum = 0;
+ Note->Entries[0].Date.Year = *LastCalendarYear;
+
+ s->Phone.Data.Cal=Note;
+ smprintf(s, "Getting calendar note method 3\n");
+ return N6510_PrivGetGenericCalendar3(s, Note->Location, ID_GetCalendarNote);
+}
+
+/* method 3 */
+static GSM_Error N6510_GetNextCalendar3(GSM_StateMachine *s, GSM_CalendarEntry *Note, gboolean start, GSM_NOKIACalToDoLocations *LastCalendar, int *LastCalendarYear, int *LastCalendarPos)
+{
+ GSM_Error error;
+ gboolean start2;
+
+ if (start) {
+ error=N6510_GetCalendarInfo3(s,LastCalendar,0);
+ if (error!=ERR_NONE) return error;
+ if (LastCalendar->Number == 0) return ERR_EMPTY;
+
+ *LastCalendarPos = 0;
+ } else {
+ (*LastCalendarPos)++;
+ }
+
+ error = ERR_EMPTY;
+ start2 = start;
+ while (error == ERR_EMPTY) {
+ if (*LastCalendarPos >= LastCalendar->Number) return ERR_EMPTY;
+
+ Note->Location = LastCalendar->Location[*LastCalendarPos];
+ error=N6510_PrivGetCalendar3(s, Note, start2, LastCalendarYear);
+ if (error == ERR_EMPTY) (*LastCalendarPos)++;
+
+ start2 = FALSE;
+ }
+ return error;
+}
+
+GSM_Error N6510_ReplyGetCalendarInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x3B:
+ /* Old method 1 for accessing calendar */
+ return N71_65_ReplyGetCalendarInfo1(msg, s, &s->Phone.Data.Priv.N6510.LastCalendar);
+ case 0x9F:
+ smprintf(s, "Info with calendar notes locations received method 3\n");
+ return N6510_ReplyGetCalendarInfo3(msg, s, &s->Phone.Data.Priv.N6510.LastCalendar);
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+/* method 3 */
+GSM_Error N6510_ReplyGetCalendarNotePos3(GSM_Protocol_Message *msg, GSM_StateMachine *s,int *FirstCalendarPos)
+{
+ smprintf(s, "First calendar location: %i\n",msg->Buffer[8]*256+msg->Buffer[9]);
+ *FirstCalendarPos = msg->Buffer[8]*256+msg->Buffer[9];
+ return ERR_NONE;
+}
+
+/* method 3 */
+static GSM_Error N6510_GetCalendarNotePos3(GSM_StateMachine *s)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x95, 0x00};
+
+ smprintf(s, "Getting first free calendar note location\n");
+ return GSM_WaitFor (s, req, 5, 0x13, 4, ID_GetCalendarNotePos);
+}
+
+GSM_Error N6510_ReplyGetCalendarNotePos(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0xf0:
+ return ERR_NOTSUPPORTED;
+ case 0x32:
+ /* Old method 1 for accessing calendar */
+ return N71_65_ReplyGetCalendarNotePos1(msg, s,&s->Phone.Data.Priv.N6510.FirstCalendarPos);
+ case 0x96:
+ return N6510_ReplyGetCalendarNotePos3(msg, s,&s->Phone.Data.Priv.N6510.FirstCalendarPos);
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_FindCalendarIconID3(GSM_StateMachine *s, GSM_CalendarEntry *Entry, unsigned char *ID)
+{
+ int i,j,LastCalendarYear;
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ GSM_CalendarEntry Note;
+ GSM_NOKIACalToDoLocations LastCalendar1,LastCalendar2;
+ GSM_Error error;
+ gboolean found;
+
+ for(i=0;i<Priv->CalendarIconsNum;i++) {
+ if (Priv->CalendarIconsTypes[i] == Entry->Type) {
+ *ID = Priv->CalendarIcons[i];
+ return ERR_NONE;
+ }
+ }
+
+ smprintf(s, "Starting finding note ID\n");
+
+ error=N6510_GetCalendarInfo3(s, &Priv->LastCalendar,0);
+ memcpy(&LastCalendar1,&Priv->LastCalendar,sizeof(GSM_NOKIACalToDoLocations));
+ if (error != ERR_NONE) return error;
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL35) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL65) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62)) {
+ error=N71_65_AddCalendar2(s,Entry);
+ } else {
+ /* First method 1 was used for meeting only
+ * but it made problems with 6230 RH-12 4.44
+ * (probably for other Series 40 2.0 phones too)
+ * For now meeting, call and memo uses method 1
+ * Please note, that method 1 is the oldest one and in some
+ * moment Nokia can remove it from firmware
+ */
+/* if (Entry->Type == GSM_CAL_MEETING) { */
+ if (Entry->Type == GSM_CAL_MEETING || Entry->Type == GSM_CAL_CALL || Entry->Type == GSM_CAL_MEMO) {
+ error=N71_65_AddCalendar1(s, Entry, &s->Phone.Data.Priv.N6510.FirstCalendarPos);
+ } else {
+ error=N71_65_AddCalendar2(s,Entry);
+ }
+ }
+ if (error != ERR_NONE) return error;
+
+ error=N6510_GetCalendarInfo3(s, &Priv->LastCalendar,0);
+ memcpy(&LastCalendar2,&Priv->LastCalendar,sizeof(GSM_NOKIACalToDoLocations));
+ if (error != ERR_NONE) return error;
+
+ smprintf(s,"Number of entries: %i %i\n",LastCalendar1.Number,LastCalendar2.Number);
+
+ for(i=0;i<LastCalendar2.Number;i++) {
+ found = TRUE;
+ for(j=0;j<LastCalendar1.Number;j++) {
+ if (LastCalendar1.Location[j] == LastCalendar2.Location[i]) {
+ found = FALSE;
+ break;
+ }
+ }
+ if (found) {
+ Note.Location = LastCalendar2.Location[i];
+ error=N6510_PrivGetCalendar3(s, &Note, TRUE, &LastCalendarYear);
+ if (error != ERR_NONE) return error;
+
+ error=N71_65_DelCalendar(s, &Note);
+ if (error != ERR_NONE) return error;
+
+ smprintf(s, "Ending finding note ID\n");
+
+ for(j=0;j<Priv->CalendarIconsNum;j++) {
+ if (Priv->CalendarIconsTypes[j] == Entry->Type) {
+ *ID = Priv->CalendarIcons[j];
+ return ERR_NONE;
+ }
+ }
+ return ERR_UNKNOWN;
+ }
+ }
+
+ return ERR_UNKNOWN;
+}
+
+/* method 3 */
+GSM_Error N6510_ReplyAddCalendar3(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Calendar note added\n");
+ return ERR_NONE;
+}
+
+/* method 3 */
+static GSM_Error N6510_AddCalendar3(GSM_StateMachine *s, GSM_CalendarEntry *Note, int *FirstCalendarPos)
+{
+ GSM_CalendarNoteType NoteType, OldNoteType;
+ time_t t_time1,t_time2;
+ long diff;
+ GSM_Error error;
+ GSM_DateTime DT,date_time;
+ int Text, Time, Alarm, Phone, EndTime, Location, count=54;
+ unsigned char req[5000] = {
+ N6110_FRAME_HEADER, 0x65,
+ 0x00, /* 0 = calendar, 1 = todo */
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, /* location */
+ 0x00, 0x00, 0x00, 0x00,
+ 0xFF, 0xFF, 0xFF, 0xFF, /* alarm */
+ 0x80, 0x00, 0x00,
+ 0x01, /* note icon */
+ 0xFF, 0xFF, 0xFF, 0xFF, /* alarm type */
+ 0x00, /* 0x02 or 0x00 */
+ 0x01, /* note type */
+ 0x07, 0xD0, 0x01, 0x12, 0x0C, 0x00, /* start date/time */
+ 0x07, 0xD0, 0x01, 0x12, 0x0C, 0x00, /* end date/time */
+ 0x00, 0x00, /* recurrance */
+ 0x00, 0x00, /* birth year */
+ 0x20, /* ToDo priority */
+ 0x00, /* ToDo completed ? */
+ 0x00, 0x00, /* How many times repeat cal note or 0 */
+ 0x00,
+ 0x00, /* note text length */
+ 0x00, /* phone length/meeting place */
+ 0x00, 0x00, 0x00};
+
+ error=N6510_GetCalendarNotePos3(s);
+ if (error!=ERR_NONE) return error;
+ Note->Location = *FirstCalendarPos;
+ req[8] = *FirstCalendarPos/256;
+ req[9] = *FirstCalendarPos%256;
+
+ NoteType = N71_65_FindCalendarType(Note->Type, s->Phone.Data.ModelInfo);
+
+ switch(NoteType) {
+ case GSM_CAL_REMINDER : req[27]=0x00; req[26]=0x02; break;
+ case GSM_CAL_MEETING : req[27]=0x01; break;
+ case GSM_CAL_CALL : req[27]=0x02; break;
+ case GSM_CAL_BIRTHDAY : req[27]=0x04; break;
+ case GSM_CAL_MEMO : req[27]=0x08; break;
+ default : return ERR_UNKNOWN;
+ }
+
+ OldNoteType = Note->Type;
+ Note->Type = NoteType;
+ error=N6510_FindCalendarIconID3(s, Note, &req[21]);
+ Note->Type = OldNoteType;
+ if (error!=ERR_NONE) return error;
+
+ GSM_CalendarFindDefaultTextTimeAlarmPhone(Note, &Text, &Time, &Alarm, &Phone, &EndTime, &Location);
+
+ if (Time == -1) {
+ smprintf(s,"No time!\n");
+ return ERR_UNKNOWN;
+ }
+ smprintf(s, "Time OK\n");
+ memcpy(&DT,&Note->Entries[Time].Date,sizeof(GSM_DateTime));
+ req[28] = DT.Year / 256;
+ req[29] = DT.Year % 256;
+ req[30] = DT.Month;
+ req[31] = DT.Day;
+ req[32] = DT.Hour;
+ req[33] = DT.Minute;
+
+ if (NoteType == GSM_CAL_BIRTHDAY) {
+ error=s->Phone.Functions->GetDateTime(s,&date_time);
+ switch (error) {
+ case ERR_EMPTY:
+ case ERR_NOTIMPLEMENTED:
+ GSM_GetCurrentDateTime(&date_time);
+ break;
+ case ERR_NONE:
+ break;
+ default:
+ return error;
+ }
+ req[28] = date_time.Year / 256;
+ req[29] = date_time.Year % 256;
+ if (DT.Year == 0) {
+ req[42] = 0xff;
+ req[43] = 0xff;
+ } else {
+ req[42] = DT.Year / 256;
+ req[43] = DT.Year % 256;
+ }
+ }
+
+ if (EndTime != -1) memcpy(&DT,&Note->Entries[EndTime].Date,sizeof(GSM_DateTime));
+
+ req[34] = DT.Year / 256;
+ req[35] = DT.Year % 256;
+ req[36] = DT.Month;
+ req[37] = DT.Day;
+ req[38] = DT.Hour;
+ req[39] = DT.Minute;
+ if (NoteType == GSM_CAL_BIRTHDAY) {
+ req[34] = date_time.Year / 256;
+ req[35] = date_time.Year % 256;
+ }
+
+ GSM_SetCalendarRecurranceRepeat(&(s->di), req+40, req+52, Note);
+
+ if (Alarm != -1) {
+ memcpy(&DT,&Note->Entries[Time].Date,sizeof(GSM_DateTime));
+ if (Note->Entries[Alarm].EntryType == CAL_SILENT_ALARM_DATETIME) {
+ req[22] = 0x00; req[23] = 0x00; req[24] = 0x00; req[25] = 0x00;
+ }
+ if (NoteType == GSM_CAL_BIRTHDAY) DT.Year = date_time.Year;
+ t_time2 = Fill_Time_T(DT);
+ t_time1 = Fill_Time_T(Note->Entries[Alarm].Date);
+ diff = (t_time1-t_time2)/60;
+
+ smprintf(s, " Difference : %li seconds or minutes\n", -diff);
+ req[14] = (unsigned char)(-diff >> 24);
+ req[15] = (unsigned char)(-diff >> 16);
+ req[16] = (unsigned char)(-diff >> 8);
+ req[17] = (unsigned char)(-diff);
+ }
+
+ if (Text != -1) {
+ req[48] = UnicodeLength(Note->Entries[Text].Text) / 256;
+ req[49] = UnicodeLength(Note->Entries[Text].Text) % 256;
+ CopyUnicodeString(req + 54, Note->Entries[Text].Text);
+ count += req[49] * 2 + (req[48] * 256) * 2;
+ }
+
+ if (Phone != -1 && NoteType == GSM_CAL_CALL) {
+ req[50] = UnicodeLength(Note->Entries[Phone].Text);
+ CopyUnicodeString(req+54+req[49]*2,Note->Entries[Phone].Text);
+ count+= req[50]*2;
+ }
+
+ if (Location != -1 && NoteType == GSM_CAL_MEETING) {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL65) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL35)) {
+ } else {
+ req[50] = UnicodeLength(Note->Entries[Location].Text);
+ CopyUnicodeString(req+54+req[49]*2,Note->Entries[Location].Text);
+ count+= req[50]*2;
+ }
+ }
+
+ req[count++] = 0x00;
+
+ smprintf(s, "Writing calendar note method 3\n");
+ return GSM_WaitFor (s, req, count, 0x13, 4, ID_SetCalendarNote);
+}
+
+GSM_Error N6510_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, gboolean start)
+{
+#ifdef GSM_FORCE_DCT4_CALENDAR_6210
+ /* Method 1. Some features missed. Not working with some notes in 3510 */
+ return N71_65_GetNextCalendar1(s,Note,start,&s->Phone.Data.Priv.N6510.LastCalendar,&s->Phone.Data.Priv.N6510.LastCalendarYear,&s->Phone.Data.Priv.N6510.LastCalendarPos);
+#endif
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62)) {
+ /* Method 1. Some features missed. Not working with some notes in 3510 */
+ return N71_65_GetNextCalendar1(s,Note,start,&s->Phone.Data.Priv.N6510.LastCalendar,&s->Phone.Data.Priv.N6510.LastCalendarYear,&s->Phone.Data.Priv.N6510.LastCalendarPos);
+
+ /* Method 2. In known phones texts of notes cut to 50 chars. Some features missed */
+/* return N71_65_GetNextCalendar2(s,Note,start,&s->Phone.Data.Priv.N6510.LastCalendarYear,&s->Phone.Data.Priv.N6510.LastCalendarPos); */
+ } else {
+ /* Method 3. All DCT4 features supported. Not supported by 8910 */
+ return N6510_GetNextCalendar3(s,Note,start,&s->Phone.Data.Priv.N6510.LastCalendar,&s->Phone.Data.Priv.N6510.LastCalendarYear,&s->Phone.Data.Priv.N6510.LastCalendarPos);
+ }
+}
+
+GSM_Error N6510_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *Status)
+{
+ GSM_Error error;
+
+#ifdef GSM_FORCE_DCT4_CALENDAR_6210
+ /* Method 1 */
+ error=N71_65_GetCalendarInfo1(s, &s->Phone.Data.Priv.N6510.LastCalendar);
+ if (error!=ERR_NONE) return error;
+ Status->Used = s->Phone.Data.Priv.N6510.LastCalendar.Number;
+ return ERR_NONE;
+#endif
+
+ /**
+ * @todo This should be acquired from phone
+ */
+ Status->Free = 100;
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62)) {
+ /* Method 1 */
+ error=N71_65_GetCalendarInfo1(s, &s->Phone.Data.Priv.N6510.LastCalendar);
+ if (error!=ERR_NONE) return error;
+ Status->Used = s->Phone.Data.Priv.N6510.LastCalendar.Number;
+ return ERR_NONE;
+
+ /* Method 2 */
+/* return ERR_NOTSUPPORTED; */
+ } else {
+ /* Method 3 */
+ error=N6510_GetCalendarInfo3(s,&s->Phone.Data.Priv.N6510.LastCalendar,0);
+ if (error!=ERR_NONE) return error;
+ Status->Used = s->Phone.Data.Priv.N6510.LastCalendar.Number;
+ return ERR_NONE;
+ }
+}
+
+GSM_Error N6510_AddCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note)
+{
+#ifdef GSM_FORCE_DCT4_CALENDAR_6210
+ return N71_65_AddCalendar2(s,Note);
+#endif
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62)) {
+ return N71_65_AddCalendar2(s,Note);
+/* return N71_65_AddCalendar1(s, Note, &s->Phone.Data.Priv.N6510.FirstCalendarPos); */
+ } else {
+ /* Method 3. All DCT4 features supported. Not supported by 8910 */
+ return N6510_AddCalendar3(s, Note, &s->Phone.Data.Priv.N6510.FirstCalendarPos);
+ }
+}
+
+GSM_Error N6510_ReplyGetNoteInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ return N6510_ReplyGetCalendarInfo3(msg, s, &s->Phone.Data.Priv.N6510.LastNote);
+}
+
+GSM_Error N6510_ReplyGetNote(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int len;
+
+ smprintf(s, "Note received\n");
+ len = msg->Buffer[50] * 256 + msg->Buffer[51];
+ if (len > GSM_MAX_NOTE_TEXT_LENGTH) {
+ smprintf(s, "Note too long (%d), truncating to %d\n", len, GSM_MAX_NOTE_TEXT_LENGTH);
+ len = GSM_MAX_NOTE_TEXT_LENGTH;
+ }
+ memcpy(s->Phone.Data.Note->Text,
+ msg->Buffer + 54,
+ len * 2);
+ s->Phone.Data.Note->Text[len * 2] = 0;
+ s->Phone.Data.Note->Text[(len * 2) + 1] = 0;
+ return ERR_NONE;
+}
+
+GSM_Error N6510_GetNextNote(GSM_StateMachine *s, GSM_NoteEntry *Note, gboolean start)
+{
+ GSM_Error error;
+ GSM_NOKIACalToDoLocations *LastNote = &s->Phone.Data.Priv.N6510.LastNote;
+
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOTES)) return ERR_NOTSUPPORTED;
+
+ if (start) {
+ error=N6510_GetCalendarInfo3(s,LastNote,2);
+ if (error!=ERR_NONE) return error;
+ Note->Location = 1;
+ } else {
+ Note->Location++;
+ }
+
+ if (Note->Location > LastNote->Number) return ERR_EMPTY;
+
+ s->Phone.Data.Note = Note;
+ smprintf(s, "Getting note\n");
+ return N6510_PrivGetGenericCalendar3(s, LastNote->Location[Note->Location-1], ID_GetNote);
+}
+
+GSM_Error N6510_DeleteNote(GSM_StateMachine *s, GSM_NoteEntry *Not)
+{
+ GSM_Error error;
+ GSM_NOKIACalToDoLocations *LastNote = &s->Phone.Data.Priv.N6510.LastNote;
+ GSM_CalendarEntry Note;
+
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOTES)) return ERR_NOTSUPPORTED;
+
+ error=N6510_GetCalendarInfo3(s,LastNote,2);
+ if (error!=ERR_NONE) return error;
+
+ smprintf(s, "Deleting Note\n");
+
+ if (Not->Location > LastNote->Number || Not->Location == 0) return ERR_INVALIDLOCATION;
+
+ Note.Location = LastNote->Location[Not->Location-1];
+ return N71_65_DelCalendar(s,&Note);
+}
+
+GSM_Error N6510_ReplyGetNoteFirstLoc(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "First Note location: %i\n",msg->Buffer[8]*256+msg->Buffer[9]);
+ s->Phone.Data.Note->Location = msg->Buffer[8]*256+msg->Buffer[9];
+ return ERR_NONE;
+}
+
+GSM_Error N6510_ReplyAddNote(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Note added\n");
+ return ERR_NONE;
+}
+
+GSM_Error N6510_AddNote(GSM_StateMachine *s, GSM_NoteEntry *Not)
+{
+ GSM_Error error;
+ int count=54;
+ unsigned char reqLoc[] = {N6110_FRAME_HEADER, 0x95,
+ 0x02}; /* 1 = todo, 2 = note */
+ unsigned char req[GSM_MAX_NOTE_TEXT_LENGTH + 500] = {
+ N6110_FRAME_HEADER, 0x65,
+ 0x02, /* 0 = calendar, 1 = todo, 2 = note */
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, /* location */
+ 0x00, 0x00, 0x00, 0x00,
+ 0xFF, 0xFF, 0xFF, 0xFF, /* alarm */
+ 0x80, 0x00, 0x00,
+ 0xA9, /* note icon */
+ 0x00, 0x00, 0x00, 0x00, /* alarm type */
+ 0x00, /* 0x02 or 0x00 */
+ 0x80, /* note type */
+ 0x07, 0xD2, 0x01, 0x01, 0x00, 0x00, /* start date/time */
+ 0x07, 0xD2, 0x01, 0x11, 0x00, 0x00, /* end date/time */
+ 0x00, 0x00, /* recurrance */
+ 0xFF, 0xFF, /* birth year */
+ 0x00, /* ToDo priority */
+ 0x00, /* ToDo completed ? */
+ 0x00, 0x00, 0x00,
+ 0x00, /* note text length */
+ 0x00, /* phone length/meeting place */
+ 0x00, 0x00, 0x00};
+ size_t length;
+
+ s->Phone.Data.Note = Not;
+
+ smprintf(s, "Getting first free Note location\n");
+ error = GSM_WaitFor (s, reqLoc, 5, 0x13, 4, ID_SetNote);
+ if (error!=ERR_NONE) return error;
+ req[8] = Not->Location / 256;
+ req[9] = Not->Location % 256;
+
+ length = UnicodeLength(Not->Text);
+ req[48] = length / 256;
+ req[49] = length % 256;
+ CopyUnicodeString(req + 54, Not->Text);
+ count += length * 2;
+
+ req[count++] = 0x00;
+
+ smprintf(s, "Adding Note\n");
+ return GSM_WaitFor (s, req, count, 0x13, 4, ID_SetNote);
+}
+
+GSM_Error N6510_GetNoteStatus(GSM_StateMachine *s, GSM_ToDoStatus *status)
+{
+ GSM_NOKIACalToDoLocations *LastNote = &s->Phone.Data.Priv.N6510.LastNote;
+ GSM_Error error;
+
+ error = N6510_GetCalendarInfo3(s,LastNote,2);
+ if (error!=ERR_NONE) return error;
+
+ status->Used = LastNote->Number;
+ return ERR_NONE;
+}
+
+/* ToDo support - 6310 style */
+GSM_Error N6510_ReplyGetToDoStatus1(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int i;
+ GSM_NOKIACalToDoLocations *Last = &s->Phone.Data.Priv.N6510.LastToDo;
+
+ smprintf(s, "TODO locations received\n");
+ Last->Number=msg->Buffer[6]*256+msg->Buffer[7];
+ smprintf(s, "Number of Entries: %i\n",Last->Number);
+ smprintf(s, "Locations: ");
+ for (i=0;i<Last->Number;i++) {
+ Last->Location[i]=msg->Buffer[12+(i*4)]*256+msg->Buffer[(i*4)+13];
+ smprintf(s, "%i ",Last->Location[i]);
+ }
+ smprintf(s, "\n");
+ return ERR_NONE;
+}
+
+/* ToDo support - 6310 style */
+static GSM_Error N6510_GetToDoStatus1(GSM_StateMachine *s, GSM_ToDoStatus *status)
+{
+ GSM_Error error;
+ GSM_NOKIACalToDoLocations *LastToDo = &s->Phone.Data.Priv.N6510.LastToDo;
+ unsigned char reqLoc[] = {
+ N6110_FRAME_HEADER,
+ 0x15, 0x01, 0x00, 0x00,
+ 0x00, 0x00, 0x00};
+
+ smprintf(s, "Getting ToDo locations\n");
+ error = GSM_WaitFor (s, reqLoc, 10, 0x55, 4, ID_GetToDo);
+ if (error != ERR_NONE) return error;
+
+ status->Used = LastToDo->Number;
+ /**
+ * @todo This should be acquired from phone
+ */
+ status->Free = 100;
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_GetToDoStatus2(GSM_StateMachine *s, GSM_ToDoStatus *status)
+{
+ GSM_NOKIACalToDoLocations *LastToDo = &s->Phone.Data.Priv.N6510.LastToDo;
+ GSM_Error error;
+
+ error = N6510_GetCalendarInfo3(s,LastToDo,1);
+ if (error!=ERR_NONE) return error;
+
+ status->Used = LastToDo->Number;
+ /**
+ * @todo This should be acquired from phone
+ */
+ status->Free = 100;
+ return ERR_NONE;
+}
+
+GSM_Error N6510_GetToDoStatus(GSM_StateMachine *s, GSM_ToDoStatus *status)
+{
+ status->Used = 0;
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO63)) {
+ return N6510_GetToDoStatus1(s, status);
+ } else if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO66)) {
+ return N6510_GetToDoStatus2(s, status);
+ } else {
+ return ERR_NOTSUPPORTED;
+ }
+}
+
+/* ToDo support - 6310 style */
+GSM_Error N6510_ReplyGetToDo1(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_ToDoEntry *Last = s->Phone.Data.ToDo;
+
+ smprintf(s, "TODO received method 1\n");
+
+ /**
+ * @todo There might be better type.
+ */
+ Last->Type = GSM_CAL_MEMO;
+
+ switch (msg->Buffer[4]) {
+ case 1 : Last->Priority = GSM_Priority_High; break;
+ case 2 : Last->Priority = GSM_Priority_Medium; break;
+ case 3 : Last->Priority = GSM_Priority_Low; break;
+ default : return ERR_UNKNOWN;
+ }
+ smprintf(s, "Priority: %i\n",msg->Buffer[4]);
+
+ CopyUnicodeString(Last->Entries[0].Text,msg->Buffer+14);
+ Last->Entries[0].EntryType = TODO_TEXT;
+ Last->EntriesNum = 1;
+ smprintf(s, "Text: \"%s\"\n",DecodeUnicodeString(Last->Entries[0].Text));
+
+ return ERR_NONE;
+}
+
+/* ToDo support - 6310 style */
+static GSM_Error N6510_GetNextToDo1(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, gboolean refresh)
+{
+ GSM_Error error;
+ GSM_ToDoStatus status;
+ GSM_NOKIACalToDoLocations *LastToDo = &s->Phone.Data.Priv.N6510.LastToDo;
+ unsigned char reqGet[] = {
+ N6110_FRAME_HEADER,
+ 0x03, 0x00, 0x00, 0x80, 0x00,
+ 0x00, 0x17}; /* Location */
+
+ if (refresh) {
+ error = N6510_GetToDoStatus(s, &status);
+ if (error != ERR_NONE) return error;
+ ToDo->Location = 1;
+ } else {
+ ToDo->Location++;
+ }
+ if (ToDo->Location > LastToDo->Number) return ERR_EMPTY;
+
+ reqGet[8] = LastToDo->Location[ToDo->Location-1] / 256;
+ reqGet[9] = LastToDo->Location[ToDo->Location-1] % 256;
+ s->Phone.Data.ToDo = ToDo;
+ smprintf(s, "Getting ToDo\n");
+ return GSM_WaitFor (s, reqGet, 10, 0x55, 4, ID_GetToDo);
+}
+
+GSM_Error N6510_ReplyGetToDoStatus2(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ return N6510_ReplyGetCalendarInfo3(msg, s, &s->Phone.Data.Priv.N6510.LastToDo);
+}
+
+/* Similiar to getting calendar method 3 */
+GSM_Error N6510_ReplyGetToDo2(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_ToDoEntry *Last = s->Phone.Data.ToDo;
+ GSM_DateTime Date;
+ unsigned long diff;
+ int len;
+
+ smprintf(s, "ToDo received method 2\n");
+
+ /**
+ * @todo There might be better type.
+ */
+ Last->Type = GSM_CAL_MEMO;
+
+ switch (msg->Buffer[44]) {
+ case 0x10: Last->Priority = GSM_Priority_Low; break;
+ case 0x20: Last->Priority = GSM_Priority_Medium; break;
+ case 0x30: Last->Priority = GSM_Priority_High; break;
+ default : return ERR_UNKNOWN;
+ }
+
+ len = msg->Buffer[50] * 256 + msg->Buffer[51];
+ if (len > GSM_MAX_TODO_TEXT_LENGTH) {
+ smprintf(s, "Todo text too long (%d), truncating to %d\n", len, GSM_MAX_TODO_TEXT_LENGTH);
+ len = GSM_MAX_TODO_TEXT_LENGTH;
+ }
+ memcpy(Last->Entries[0].Text,
+ msg->Buffer + 54,
+ len * 2);
+ Last->Entries[0].Text[len * 2] = 0;
+ Last->Entries[0].Text[(len * 2) + 1] = 0;
+ Last->Entries[0].EntryType = TODO_TEXT;
+ smprintf(s, "Text: \"%s\"\n",DecodeUnicodeString(Last->Entries[0].Text));
+
+ smprintf(s,"EndTime: %04i-%02i-%02i %02i:%02i\n",
+ msg->Buffer[34]*256+msg->Buffer[35],
+ msg->Buffer[36],msg->Buffer[37],msg->Buffer[38],
+ msg->Buffer[39]);
+ Date.Year = msg->Buffer[34]*256+msg->Buffer[35];
+ Date.Month = msg->Buffer[36];
+ Date.Day = msg->Buffer[37];
+ Date.Hour = msg->Buffer[38];
+ Date.Minute = msg->Buffer[39];
+ Date.Second = 0;
+ Date.Timezone = 0;
+ Last->Entries[1].EntryType = TODO_END_DATETIME;
+ memcpy(&Last->Entries[1].Date, &Date, sizeof(GSM_DateTime));
+
+ smprintf(s,"StartTime: %04i-%02i-%02i %02i:%02i\n",
+ msg->Buffer[28]*256+msg->Buffer[29],
+ msg->Buffer[30],msg->Buffer[31],msg->Buffer[32],
+ msg->Buffer[33]);
+ Date.Year = msg->Buffer[28]*256+msg->Buffer[29];
+ Date.Month = msg->Buffer[30];
+ Date.Day = msg->Buffer[31];
+ Date.Hour = msg->Buffer[32];
+ Date.Minute = msg->Buffer[33];
+ Date.Second = 0;
+ Date.Timezone = 0;
+
+ Last->EntriesNum = 2;
+
+ if (msg->Buffer[45] == 0x01) {
+ Last->Entries[2].Number = msg->Buffer[45];
+ Last->Entries[2].EntryType = TODO_COMPLETED;
+ Last->EntriesNum++;
+ smprintf(s,"Completed\n");
+ }
+
+ if (msg->Buffer[14] == 0xFF && msg->Buffer[15] == 0xFF && msg->Buffer[16] == 0xff && msg->Buffer[17] == 0xff) {
+ smprintf(s, "No alarm\n");
+ } else {
+ diff = ((unsigned int)msg->Buffer[14]) << 24;
+ diff += ((unsigned int)msg->Buffer[15]) << 16;
+ diff += ((unsigned int)msg->Buffer[16]) << 8;
+ diff += msg->Buffer[17];
+
+ memcpy(&Last->Entries[Last->EntriesNum].Date,&Date,sizeof(GSM_DateTime));
+ GetTimeDifference(diff, &Last->Entries[Last->EntriesNum].Date, FALSE, 60);
+ smprintf(s, "Alarm date : %02i-%02i-%04i %02i:%02i:%02i\n",
+ Last->Entries[Last->EntriesNum].Date.Day, Last->Entries[Last->EntriesNum].Date.Month,
+ Last->Entries[Last->EntriesNum].Date.Year, Last->Entries[Last->EntriesNum].Date.Hour,
+ Last->Entries[Last->EntriesNum].Date.Minute,Last->Entries[Last->EntriesNum].Date.Second);
+
+ Last->Entries[Last->EntriesNum].EntryType = TODO_ALARM_DATETIME;
+ if (msg->Buffer[22]==0x00 && msg->Buffer[23]==0x00 &&
+ msg->Buffer[24]==0x00 && msg->Buffer[25]==0x00)
+ {
+ Last->Entries[Last->EntriesNum].EntryType = TODO_SILENT_ALARM_DATETIME;
+ smprintf(s, "Alarm type : Silent\n");
+ }
+ Last->EntriesNum++;
+ }
+
+ return ERR_NONE;
+}
+
+/* ToDo support - 6610 style */
+static GSM_Error N6510_GetNextToDo2(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, gboolean refresh)
+{
+ GSM_Error error;
+ GSM_NOKIACalToDoLocations *LastToDo = &s->Phone.Data.Priv.N6510.LastToDo;
+
+ if (refresh) {
+ error=N6510_GetCalendarInfo3(s,LastToDo,1);
+ if (error!=ERR_NONE) return error;
+ ToDo->Location = 1;
+ } else {
+ ToDo->Location++;
+ }
+
+ if (ToDo->Location > LastToDo->Number) return ERR_EMPTY;
+
+ s->Phone.Data.ToDo = ToDo;
+ smprintf(s, "Getting todo method 2\n");
+ return N6510_PrivGetGenericCalendar3(s, LastToDo->Location[ToDo->Location-1], ID_GetToDo);
+}
+
+GSM_Error N6510_GetNextToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, gboolean refresh)
+{
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO63)) {
+ return N6510_GetNextToDo1(s, ToDo, refresh);
+ } else if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO66)) {
+ return N6510_GetNextToDo2(s, ToDo, refresh);
+ } else {
+ return ERR_NOTSUPPORTED;
+ }
+}
+
+/* ToDo support - 6310 style */
+GSM_Error N6510_ReplyDeleteAllToDo1(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "All TODO deleted\n");
+ return ERR_NONE;
+}
+
+/* ToDo support - 6310 style */
+GSM_Error N6510_DeleteAllToDo1(GSM_StateMachine *s)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x11};
+
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO63)) {
+ return ERR_NOTSUPPORTED;
+ }
+
+ smprintf(s, "Deleting all ToDo method 1\n");
+ return GSM_WaitFor (s, req, 4, 0x55, 4, ID_DeleteAllToDo);
+}
+
+GSM_Error N6510_DeleteToDo2(GSM_StateMachine *s, GSM_ToDoEntry *ToDo)
+{
+ GSM_Error error;
+ GSM_NOKIACalToDoLocations *LastToDo = &s->Phone.Data.Priv.N6510.LastToDo;
+ GSM_CalendarEntry Note;
+
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO66)) {
+ return ERR_NOTSUPPORTED;
+ }
+
+ error=N6510_GetCalendarInfo3(s,LastToDo,1);
+ if (error!=ERR_NONE) return error;
+
+ smprintf(s, "Deleting ToDo method 2\n");
+
+ if (ToDo->Location > LastToDo->Number || ToDo->Location == 0) return ERR_INVALIDLOCATION;
+
+ Note.Location = LastToDo->Location[ToDo->Location-1];
+ return N71_65_DelCalendar(s,&Note);
+}
+
+/* ToDo support - 6310 style */
+GSM_Error N6510_ReplyGetToDoFirstLoc1(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "TODO first location received method 1: %02x\n",msg->Buffer[9]);
+ s->Phone.Data.ToDo->Location = msg->Buffer[9];
+ return ERR_NONE;
+}
+
+/* ToDo support - 6310 style */
+GSM_Error N6510_ReplyAddToDo1(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "TODO set OK\n");
+ return ERR_NONE;
+}
+
+/* ToDo support - 6310 style */
+static GSM_Error N6510_AddToDo1(GSM_StateMachine *s, GSM_ToDoEntry *ToDo)
+{
+ int Text, Alarm, EndTime, Completed, ulen, Phone;
+ GSM_Error error;
+ unsigned char reqLoc[] = {N6110_FRAME_HEADER, 0x0F};
+ unsigned char reqSet[500] = {
+ N6110_FRAME_HEADER, 0x01,
+ 0x03, /* Priority */
+ 0x00, /* Length of text */
+ 0x80,0x00,0x00,
+ 0x18}; /* Location */
+
+ s->Phone.Data.ToDo = ToDo;
+
+ smprintf(s, "Getting first ToDo location\n");
+ error = GSM_WaitFor (s, reqLoc, 4, 0x55, 4, ID_SetToDo);
+ if (error != ERR_NONE) return error;
+ reqSet[9] = ToDo->Location;
+
+ switch (ToDo->Priority) {
+ case GSM_Priority_Low : reqSet[4] = 3; break;
+ case GSM_Priority_Medium: reqSet[4] = 2; break;
+ case GSM_Priority_High : reqSet[4] = 1; break;
+ default: break;
+ }
+
+ GSM_ToDoFindDefaultTextTimeAlarmCompleted(ToDo, &Text, &Alarm, &Completed, &EndTime, &Phone);
+
+ if (Text == -1) return ERR_NOTSUPPORTED; /* XXX: shouldn't this be handled different way? */
+ ulen = UnicodeLength(ToDo->Entries[Text].Text);
+ reqSet[5] = ulen+1;
+ CopyUnicodeString(reqSet+10,ToDo->Entries[Text].Text);
+ reqSet[10+ulen*2] = 0x00;
+ reqSet[10+ulen*2+1] = 0x00;
+ smprintf(s, "Adding ToDo method 1\n");
+ return GSM_WaitFor (s, reqSet, 12+ulen*2, 0x55, 4, ID_SetToDo);
+}
+
+GSM_Error N6510_ReplyAddToDo2(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "ToDo added method 2\n");
+ return ERR_NONE;
+}
+
+GSM_Error N6510_ReplyGetToDoFirstLoc2(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "First ToDo location method 2: %i\n",msg->Buffer[8]*256+msg->Buffer[9]);
+ s->Phone.Data.ToDo->Location = msg->Buffer[8]*256+msg->Buffer[9];
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_AddToDo2(GSM_StateMachine *s, GSM_ToDoEntry *ToDo)
+{
+ GSM_CalendarEntry Note;
+ time_t t_time1,t_time2;
+ long diff;
+ GSM_Error error;
+ GSM_DateTime DT;
+ int Text, Alarm, EndTime, Completed, count=54, Phone;
+ unsigned char reqLoc[] = {N6110_FRAME_HEADER, 0x95,
+ 0x01}; /* 1 = todo, 2 = note */
+ unsigned char req[GSM_MAX_TODO_TEXT_LENGTH + 500] = {
+ N6110_FRAME_HEADER, 0x65,
+ 0x01, /* 0 = calendar, 1 = todo */
+ 0x00, 0x00, 0x00,
+ 0x00, 0x00, /* location */
+ 0x00, 0x00, 0x00, 0x00,
+ 0xFF, 0xFF, 0xFF, 0xFF, /* alarm */
+ 0x80, 0x00, 0x00,
+ 0x01, /* note icon */
+ 0xFF, 0xFF, 0xFF, 0xFF, /* alarm type */
+ 0x00, /* 0x02 or 0x00 */
+ 0x01, /* note type */
+ 0x07, 0xD0, 0x01, 0x12, 0x0C, 0x00, /* start date/time */
+ 0x07, 0xD0, 0x01, 0x12, 0x0C, 0x00, /* end date/time */
+ 0x00, 0x00, /* recurrance */
+ 0x00, 0x00, /* birth year */
+ 0x20, /* ToDo priority */
+ 0x00, /* ToDo completed ? */
+ 0x00, 0x00, /* How many times repeat cal note or 0 */
+ 0x00,
+ 0x00, /* note text length */
+ 0x00, /* phone length/meeting place */
+ 0x00, 0x00, 0x00};
+
+ s->Phone.Data.ToDo = ToDo;
+
+ smprintf(s, "Getting first free ToDo location method 2\n");
+ error = GSM_WaitFor (s, reqLoc, 5, 0x13, 4, ID_SetToDo);
+ if (error!=ERR_NONE) return error;
+ req[8] = ToDo->Location/256;
+ req[9] = ToDo->Location%256;
+
+ Note.Type = GSM_CAL_MEETING;
+ DT.Year = 2004; DT.Month = 1; DT.Day = 1;
+ DT.Hour = 12; DT.Minute = 12; DT.Second = 0;
+ DT.Timezone = 0;
+ memcpy(&Note.Entries[0].Date,&DT,sizeof(GSM_DateTime));
+ Note.Entries[0].EntryType = CAL_START_DATETIME;
+ memcpy(&Note.Entries[1].Date,&DT,sizeof(GSM_DateTime));
+ Note.Entries[1].EntryType = CAL_END_DATETIME;
+ EncodeUnicode(Note.Entries[2].Text,"ala",3);
+ Note.Entries[2].EntryType = CAL_TEXT;
+ Note.EntriesNum = 3;
+ error=N6510_FindCalendarIconID3(s, &Note, &req[21]);
+ if (error!=ERR_NONE) return error;
+
+ switch (ToDo->Priority) {
+ case GSM_Priority_Low : req[44] = 0x10; break;
+ case GSM_Priority_Medium: req[44] = 0x20; break;
+ case GSM_Priority_High : req[44] = 0x30; break;
+ default: break;
+ }
+
+ GSM_ToDoFindDefaultTextTimeAlarmCompleted(ToDo, &Text, &Alarm, &Completed, &EndTime, &Phone);
+
+ if (Completed != -1) req[45] = 0x01;
+
+ if (EndTime == -1) {
+ GSM_GetCurrentDateTime(&DT);
+ } else {
+ memcpy(&DT,&ToDo->Entries[EndTime].Date,sizeof(GSM_DateTime));
+ }
+ /*Start time*/
+ req[28] = DT.Year / 256;
+ req[29] = DT.Year % 256;
+ req[30] = DT.Month;
+ req[31] = DT.Day;
+ req[32] = DT.Hour;
+ req[33] = DT.Minute;
+ /*End time*/
+ req[34] = DT.Year / 256;
+ req[35] = DT.Year % 256;
+ req[36] = DT.Month;
+ req[37] = DT.Day;
+ req[38] = DT.Hour;
+ req[39] = DT.Minute;
+
+ if (Alarm != -1) {
+ if (ToDo->Entries[Alarm].EntryType == TODO_SILENT_ALARM_DATETIME)
+ {
+ req[22] = 0x00; req[23] = 0x00; req[24] = 0x00; req[25] = 0x00;
+ }
+ t_time2 = Fill_Time_T(DT);
+ t_time1 = Fill_Time_T(ToDo->Entries[Alarm].Date);
+ diff = (t_time1-t_time2)/60;
+
+ smprintf(s, " Difference : %li seconds or minutes\n", -diff);
+ req[14] = (unsigned char)(-diff >> 24);
+ req[15] = (unsigned char)(-diff >> 16);
+ req[16] = (unsigned char)(-diff >> 8);
+ req[17] = (unsigned char)(-diff);
+ }
+
+ if (Text != -1) {
+ req[48] = UnicodeLength(ToDo->Entries[Text].Text) / 256;
+ req[49] = UnicodeLength(ToDo->Entries[Text].Text) % 256;
+ CopyUnicodeString(req + 54, ToDo->Entries[Text].Text);
+ count += req[49] * 2 + (req[48] * 256) * 2;
+ }
+
+ req[count++] = 0x00;
+
+ smprintf(s, "Adding ToDo method 2\n");
+ return GSM_WaitFor (s, req, count, 0x13, 4, ID_SetToDo);
+}
+
+GSM_Error N6510_AddToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo)
+{
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO63)) {
+ return N6510_AddToDo1(s, ToDo);
+ } else if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_TODO66)) {
+ return N6510_AddToDo2(s, ToDo);
+ } else {
+ return ERR_NOTSUPPORTED;
+ }
+}
+
+GSM_Error N6510_ReplyGetCalendarSettings(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_CalendarSettings *sett = s->Phone.Data.CalendarSettings;
+
+ switch (msg->Buffer[3]) {
+ case 0x86:
+ smprintf(s, "Auto deleting setting received\n");
+ sett->AutoDelete = msg->Buffer[4];
+ return ERR_NONE;
+ case 0x8E:
+ smprintf(s, "Start day for calendar received\n");
+ switch(msg->Buffer[4]) {
+ case 0x04:
+ sett->StartDay = 1;
+ return ERR_NONE;
+ case 0x03:
+ sett->StartDay = 6;
+ return ERR_NONE;
+ case 0x02:
+ sett->StartDay = 7;
+ return ERR_NONE;
+ case 0x01:
+ sett->StartDay = 1;
+ return ERR_NONE;
+ }
+ break;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+GSM_Error N6510_GetCalendarSettings(GSM_StateMachine *s, GSM_CalendarSettings *settings)
+{
+ GSM_Error error;
+ unsigned char req1[] = {N6110_FRAME_HEADER, 0x85};
+ unsigned char req2[] = {N6110_FRAME_HEADER, 0x8D};
+
+ s->Phone.Data.CalendarSettings = settings;
+
+ smprintf(s, "Getting auto delete\n");
+ error = GSM_WaitFor (s, req1, 4, 0x13, 4, ID_GetCalendarSettings);
+ if (error != ERR_NONE) return error;
+
+ smprintf(s, "Getting start day for week\n");
+ return GSM_WaitFor (s, req2, 4, 0x13, 4, ID_GetCalendarSettings);
+}
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct4s40/6510/6510cal.h b/libgammu/phone/nokia/dct4s40/6510/6510cal.h
new file mode 100644
index 0000000..da09ffa
--- /dev/null
+++ b/libgammu/phone/nokia/dct4s40/6510/6510cal.h
@@ -0,0 +1,51 @@
+
+/* calendar */
+
+GSM_Error N6510_ReplyGetCalendarInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyGetCalendar3(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, gboolean start);
+
+GSM_Error N6510_ReplyGetCalendarNotePos(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyAddCalendar3(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_AddCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note);
+
+GSM_Error N6510_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *Status);
+
+/* notes */
+
+GSM_Error N6510_ReplyGetNoteInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyGetNote(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_GetNextNote(GSM_StateMachine *s, GSM_NoteEntry *Note, gboolean start);
+
+GSM_Error N6510_DeleteNote(GSM_StateMachine *s, GSM_NoteEntry *Not);
+
+GSM_Error N6510_ReplyGetNoteFirstLoc(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyAddNote(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_AddNote(GSM_StateMachine *s, GSM_NoteEntry *Not);
+
+GSM_Error N6510_GetNoteStatus(GSM_StateMachine *s, GSM_ToDoStatus *status);
+
+/* todo */
+
+GSM_Error N6510_ReplyGetToDoStatus2(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyGetToDoStatus1(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_GetToDoStatus(GSM_StateMachine *s, GSM_ToDoStatus *status);
+
+GSM_Error N6510_ReplyGetToDo1(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyGetToDo2(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_GetNextToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo, gboolean refresh);
+
+GSM_Error N6510_ReplyDeleteAllToDo1(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_DeleteAllToDo1(GSM_StateMachine *s);
+GSM_Error N6510_DeleteToDo2(GSM_StateMachine *s, GSM_ToDoEntry *ToDo);
+
+GSM_Error N6510_ReplyGetToDoFirstLoc1(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyGetToDoFirstLoc2(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyAddToDo1(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyAddToDo2(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_AddToDo(GSM_StateMachine *s, GSM_ToDoEntry *ToDo);
+
+/* calendar settings */
+
+GSM_Error N6510_ReplyGetCalendarSettings(GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_GetCalendarSettings(GSM_StateMachine *s, GSM_CalendarSettings *settings);
diff --git a/libgammu/phone/nokia/dct4s40/6510/6510file.c b/libgammu/phone/nokia/dct4s40/6510/6510file.c
new file mode 100644
index 0000000..952c69c
--- /dev/null
+++ b/libgammu/phone/nokia/dct4s40/6510/6510file.c
@@ -0,0 +1,2609 @@
+/* (c) 2003-2006 by Marcin Wiacek */
+/* function for making CRC for filesystem (c) 2003 by Michael Schroeder */
+
+#include <gammu-config.h>
+
+#ifdef GSM_ENABLE_NOKIA6510
+
+#include <string.h>
+#include <time.h>
+
+#include "../../../../misc/coding/coding.h"
+#include "../../../../gsmcomon.h"
+#include "../../../../service/gsmlogo.h"
+#include "../../nfunc.h"
+#include "../../nfuncold.h"
+#include "../../../pfunc.h"
+#include "../dct4func.h"
+#include "n6510.h"
+#include "../../../../../libgammu/misc/string.h"
+
+/* shared */
+
+/**
+ * Shifts data in file cache by defined count.
+ *
+ * \param move How to move entries. +10 means that i entry will become
+ * i + 10, while -10 means that entries will be moved backwards. Of
+ * course starting at the beginning of the list. So 10 entry will become 0.
+ */
+static GSM_Error N6510_ShiftFileCache(GSM_StateMachine *s, int move)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ int i;
+
+ if (move < 0) {
+ for (i = 0; i < Priv->FilesLocationsUsed + move; i++) {
+ memcpy(&Priv->FilesCache[i], &Priv->FilesCache[i - move], sizeof(GSM_File));
+ smprintf(s, "Copying %i to %i\n", i - move, i);
+ }
+ } else {
+ for (i = Priv->FilesLocationsUsed - 1; i >= 0; i--) {
+ memcpy(&Priv->FilesCache[i + move], &Priv->FilesCache[i], sizeof(GSM_File));
+ smprintf(s, "Copying %i to %i\n", i, i + move);
+ }
+ }
+
+ Priv->FilesLocationsUsed += move;
+
+ return ERR_NONE;
+}
+/**
+ * Allocates enough entries in file cache.
+ *
+ * \param requested Number of files which are requested.
+ */
+static GSM_Error N6510_AllocFileCache(GSM_StateMachine *s, int requested)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ int newsize;
+
+ /* Maybe there is already enough allocated */
+ if (Priv->FilesLocationsAvail >= requested) return ERR_NONE;
+
+ /* Do not allocate one by one */
+ newsize = requested + 10;
+
+ /* Reallocate memory */
+ Priv->FilesCache = (GSM_File *)realloc(Priv->FilesCache, newsize * sizeof(GSM_File));
+ if (Priv->FilesCache == NULL) return ERR_MOREMEMORY;
+
+ /* Store new cache size */
+ Priv->FilesLocationsAvail = newsize;
+
+ return ERR_NONE;
+}
+
+static int N6510_FindFileCheckSum12(GSM_StateMachine *s, unsigned char *ptr, int len)
+{
+ int acc, i, accx;
+
+ accx = 0;
+ acc = 0xffff;
+ while (len--) {
+ accx = (accx & 0xffff00ff) | (acc & 0xff00);
+ acc = (acc & 0xffff00ff) | (*ptr++ << 8);
+ for (i = 0; i < 8; i++) {
+ acc <<= 1;
+ if (acc & 0x10000) acc ^= 0x1021;
+ if (accx & 0x80000000) acc ^= 0x1021;
+ accx <<= 1;
+ }
+ }
+ smprintf(s, "Checksum from Gammu is %04X\n",(acc & 0xffff));
+ return (acc & 0xffff);
+}
+
+GSM_Error N6510_ReplyGetFilePart12(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int old;
+
+ smprintf(s,"File part received\n");
+ old = s->Phone.Data.File->Used;
+ s->Phone.Data.File->Used += msg->Buffer[6]*256*256*256+
+ msg->Buffer[7]*256*256+
+ msg->Buffer[8]*256+
+ msg->Buffer[9];
+ smprintf(s,"Length of file part: %i\n",
+ msg->Buffer[6]*256*256*256+
+ msg->Buffer[7]*256*256+
+ msg->Buffer[8]*256+
+ msg->Buffer[9]);
+ s->Phone.Data.File->Buffer = (unsigned char *)realloc(s->Phone.Data.File->Buffer,s->Phone.Data.File->Used);
+ memcpy(s->Phone.Data.File->Buffer+old,msg->Buffer+10,s->Phone.Data.File->Used-old);
+ return ERR_NONE;
+}
+
+GSM_Error N6510_ReplyGetFileCRC12(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+
+ Priv->FileCheckSum = msg->Buffer[6] * 256 + msg->Buffer[7];
+ smprintf(s,"File checksum from phone is %04X\n",Priv->FileCheckSum);
+ return ERR_NONE;
+}
+
+/* filesystem 1 */
+
+static GSM_Error N6510_GetFileCRC1(GSM_StateMachine *s, unsigned char *id)
+{
+ unsigned char GetCRC[] = {
+ N7110_FRAME_HEADER, 0x42, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x1E}; /* file ID */
+
+ GetCRC[8] = atoi(DecodeUnicodeString(id)) / 256;
+ GetCRC[9] = atoi(DecodeUnicodeString(id)) % 256;
+ smprintf(s,"Getting CRC for file in filesystem\n");
+ return GSM_WaitFor (s, GetCRC, 10, 0x6D, 4, ID_GetCRC);
+}
+
+GSM_Error N6510_ReplyGetFileFolderInfo1(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_File *File = s->Phone.Data.FileInfo;
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ int i, newsize;
+ unsigned char buffer[500];
+ GSM_Error error;
+
+ switch (msg->Buffer[3]) {
+ case 0x15:
+ smprintf(s,"File or folder details received\n");
+ CopyUnicodeString(File->Name,msg->Buffer+10);
+ if (msg->Length == 14) {
+ smprintf(s,"File not exist\n");
+ return ERR_FILENOTEXIST;
+ }
+ if (!strncmp(DecodeUnicodeString(File->Name),"GMSTemp",7)) return ERR_EMPTY;
+ if (File->Name[0] == 0x00 && File->Name[1] == 0x00) return ERR_UNKNOWN;
+
+/* EncodeHexUnicode (buffer, File->Name, UnicodeLength(File->Name)); */
+/* smprintf(s,"Name encoded: %s\n",buffer); */
+
+ i = msg->Buffer[8]*256+msg->Buffer[9];
+ smprintf(s, "%02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
+ msg->Buffer[i-5],msg->Buffer[i-4],msg->Buffer[i-3],
+ msg->Buffer[i-2],msg->Buffer[i-1],msg->Buffer[i],
+ msg->Buffer[i+1],msg->Buffer[i+2],msg->Buffer[i+3]);
+
+ File->Folder = FALSE;
+ if (msg->Buffer[i-5] == 0x00 && msg->Buffer[i-3]==0x02) File->Folder = TRUE;
+
+ File->ReadOnly = FALSE;
+ File->Protected = FALSE;
+ File->System = FALSE;
+ File->Hidden = FALSE;
+ if (msg->Buffer[i+2] == 0x01) File->Protected = TRUE;
+ if (msg->Buffer[i+4] == 0x01) File->ReadOnly = TRUE;
+ if (msg->Buffer[i+5] == 0x01) File->Hidden = TRUE;
+ if (msg->Buffer[i+6] == 0x01) File->System = TRUE;/* fixme */
+
+ File->ModifiedEmpty = FALSE;
+ NOKIA_DecodeDateTime(s, msg->Buffer+i-22, &File->Modified, TRUE, FALSE);
+ if (File->Modified.Year == 0x00) File->ModifiedEmpty = TRUE;
+ if (File->Modified.Year == 0xffff) File->ModifiedEmpty = TRUE;
+ smprintf(s, "%02x %02x %02x %02x\n",msg->Buffer[i-22],msg->Buffer[i-21],msg->Buffer[i-20],msg->Buffer[i-19]);
+
+ Priv->FileToken = msg->Buffer[i-10]*256+msg->Buffer[i-9];
+ Priv->ParentID = msg->Buffer[i]*256+msg->Buffer[i+1];
+ smprintf(s,"ParentID is %i\n",Priv->ParentID);
+
+ File->Type = GSM_File_Other;
+ if (msg->Length > 240){
+ i = 227;
+ if (msg->Buffer[i]==0x02 && msg->Buffer[i+2]==0x01)
+ File->Type = GSM_File_Image_JPG;
+ else if (msg->Buffer[i]==0x02 && msg->Buffer[i+2]==0x02)
+ File->Type = GSM_File_Image_BMP;
+ else if (msg->Buffer[i]==0x02 && msg->Buffer[i+2]==0x07)
+ File->Type = GSM_File_Image_BMP;
+ else if (msg->Buffer[i]==0x02 && msg->Buffer[i+2]==0x03)
+ File->Type = GSM_File_Image_PNG;
+ else if (msg->Buffer[i]==0x02 && msg->Buffer[i+2]==0x05)
+ File->Type = GSM_File_Image_GIF;
+ else if (msg->Buffer[i]==0x02 && msg->Buffer[i+2]==0x09)
+ File->Type = GSM_File_Image_WBMP;
+ else if (msg->Buffer[i]==0x04 && msg->Buffer[i+2]==0x01)
+ File->Type = GSM_File_Sound_AMR;
+ else if (msg->Buffer[i]==0x04 && msg->Buffer[i+2]==0x02)
+ File->Type = GSM_File_Sound_MIDI;
+ else if (msg->Buffer[i]==0x08 && msg->Buffer[i+2]==0x05)
+ File->Type = GSM_File_Video_3GP;
+ else if (msg->Buffer[i]==0x10 && msg->Buffer[i+2]==0x01)
+ File->Type = GSM_File_Java_JAR;
+ else if (msg->Buffer[i]==0x00 && msg->Buffer[i+2]==0x01)
+ File->Type = GSM_File_MMS;
+ }
+ return ERR_NONE;
+ case 0x2F:
+ smprintf(s,"File or folder used bytes received\n");
+ File->Used = msg->Buffer[6]*256*256*256+
+ msg->Buffer[7]*256*256+
+ msg->Buffer[8]*256+
+ msg->Buffer[9];
+ return ERR_NONE;
+ case 0x33:
+ if (s->Phone.Data.RequestID == ID_GetFileInfo) {
+
+ newsize = msg->Buffer[8] * 256 + msg->Buffer[9];
+
+ error = N6510_AllocFileCache(s, Priv->FilesLocationsUsed + newsize);
+ if (error != ERR_NONE) return error;
+
+ error = N6510_ShiftFileCache(s, newsize);
+ if (error != ERR_NONE) return error;
+
+ for (i = 0; i < newsize; i++) {
+ sprintf(buffer,"%i",msg->Buffer[13+i*4-1]*256 + msg->Buffer[13+i*4]);
+ EncodeUnicode(Priv->FilesCache[i].ID_FullName,buffer,strlen(buffer));
+ Priv->FilesCache[i].Level = File->Level+1;
+ smprintf(s, "%s ",DecodeUnicodeString(Priv->FilesCache[i].ID_FullName));
+ }
+ smprintf(s, "\n");
+ }
+ if ((msg->Buffer[8]*256+msg->Buffer[9]) != 0x00) File->Folder = TRUE;
+ return ERR_NONE;
+ case 0xf0:
+ smprintf(s, "File system is not supported\n");
+ return ERR_NOTSUPPORTED;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_GetFileFolderInfo1(GSM_StateMachine *s, GSM_File *File, gboolean full)
+{
+ GSM_Error error;
+ unsigned char req[10] = {
+ N7110_FRAME_HEADER,
+ 0x14, /* 0x14 - info, 0x22 - free/total, 0x2E - used, 0x32 - sublocations */
+ 0x01, /* 0x00 for sublocations reverse sorting, 0x01 for free */
+ 0x00, 0x00, 0x01,
+ 0x00, 0x01}; /* Folder or file number */
+
+ s->Phone.Data.FileInfo = File;
+ req[8] = atoi(DecodeUnicodeString(File->ID_FullName)) / 256;
+ req[9] = atoi(DecodeUnicodeString(File->ID_FullName)) % 256;
+
+ req[3] = 0x14;
+ req[4] = 0x01;
+ smprintf(s,"Getting info for file in filesystem\n");
+ error=GSM_WaitFor (s, req, 10, 0x6D, 4, ID_GetFileInfo);
+ if (error != ERR_NONE) return error;
+
+ if (full) {
+ req[3] = 0x32;
+ req[4] = 0x00;
+ smprintf(s,"Getting subfolders for filesystem\n");
+ error=GSM_WaitFor (s, req, 10, 0x6D, 4, ID_GetFileInfo);
+ if (error != ERR_NONE) return error;
+ }
+
+ if (!File->Folder) {
+ req[3] = 0x2E;
+ req[4] = 0x01;
+ smprintf(s,"Getting used memory for file in filesystem\n");
+ return GSM_WaitFor (s, req, 10, 0x6D, 4, ID_GetFileInfo);
+ }
+
+ return error;
+}
+
+static GSM_Error N6510_GetNextFileFolder1(GSM_StateMachine *s, GSM_File *File, gboolean start)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ GSM_Error error;
+ unsigned char buffer[5];
+
+ if (start) {
+ error = N6510_AllocFileCache(s, 1);
+ if (error != ERR_NONE) return error;
+
+ Priv->FilesLocationsUsed = 1;
+
+ sprintf(buffer,"%i",0x01);
+ EncodeUnicode(Priv->FilesCache[0].ID_FullName,buffer,strlen(buffer));
+ Priv->FilesCache[0].Level = 1;
+ }
+
+ while (1) {
+ if (Priv->FilesLocationsUsed == 0) return ERR_EMPTY;
+
+ CopyUnicodeString(File->ID_FullName,Priv->FilesCache[0].ID_FullName);
+ File->Level = Priv->FilesCache[0].Level;
+
+ error = N6510_ShiftFileCache(s, -1);
+ if (error != ERR_NONE) return error;
+
+ error = N6510_GetFileFolderInfo1(s, File, TRUE);
+ if (error == ERR_EMPTY) continue;
+ return error;
+ }
+}
+
+GSM_Error N6510_ReplyGetFileSystemStatus1(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x23:
+ if (!strcmp(s->Phone.Data.ModelInfo->model,"6310i")) {
+ smprintf(s,"File or folder total bytes received\n");
+ s->Phone.Data.FileSystemStatus->Free =
+ 3*256*256 + msg->Buffer[8]*256 + msg->Buffer[9] -
+ s->Phone.Data.FileSystemStatus->Used;
+ } else {
+ smprintf(s,"File or folder free bytes received\n");
+ s->Phone.Data.FileSystemStatus->Free =
+ msg->Buffer[6]*256*256*256+
+ msg->Buffer[7]*256*256+
+ msg->Buffer[8]*256+
+ msg->Buffer[9];
+ }
+ return ERR_NONE;
+ case 0x2F:
+ smprintf(s,"File or folder used bytes received\n");
+ s->Phone.Data.FileSystemStatus->Used =
+ msg->Buffer[6]*256*256*256+
+ msg->Buffer[7]*256*256+
+ msg->Buffer[8]*256+
+ msg->Buffer[9];
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_GetFileSystemStatus1(GSM_StateMachine *s, GSM_FileSystemStatus *status)
+{
+ GSM_Error error;
+ unsigned char req[10] = {
+ N7110_FRAME_HEADER,
+ 0x22, /* 0x14 - info, 0x22 - free/total, 0x2E - used, 0x32 - sublocations */
+ 0x01, /* 0x00 for sublocations reverse sorting, 0x01 for free */
+ 0x00, 0x00, 0x01,
+ 0x00, 0x01}; /* Folder or file number */
+
+ /* Used memory by types */
+ status->UsedImages = 0;
+ status->UsedSounds = 0;
+ status->UsedThemes = 0;
+ s->Phone.Data.FileSystemStatus = status;
+
+ status->Free = 0;
+
+ req[3] = 0x2E;
+ req[4] = 0x01;
+ smprintf(s, "Getting used/total memory in filesystem\n");
+ error = GSM_WaitFor (s, req, 10, 0x6D, 4, ID_FileSystemStatus);
+ if (error != ERR_NONE) return error;
+
+ req[3] = 0x22;
+ req[4] = 0x01;
+ smprintf(s, "Getting free memory in filesystem\n");
+ return GSM_WaitFor (s, req, 10, 0x6D, 4, ID_FileSystemStatus);
+}
+
+static GSM_Error N6510_GetFilePart1(GSM_StateMachine *s, GSM_File *File, int *Handle UNUSED, size_t *Size)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ int old;
+ GSM_Error error;
+ unsigned char req[] = {
+ N7110_FRAME_HEADER, 0x0E, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x01, /* Folder or file number */
+ 0x00, 0x00, 0x00, 0x00, /* Start from xxx byte */
+ 0x00, 0x00,
+ 0x03, 0xE8}; /* Read xxx bytes */
+
+ if (File->Used == 0x00) {
+ error = N6510_GetFileFolderInfo1(s, File, FALSE);
+ if (error != ERR_NONE) return error;
+
+ if (File->Folder) return ERR_SHOULDBEFILE;
+
+ (*Size) = File->Used;
+ File->Used = 0;
+ }
+
+ old = File->Used;
+ req[8] = atoi(DecodeUnicodeString(File->ID_FullName)) / 256;
+ req[9] = atoi(DecodeUnicodeString(File->ID_FullName)) % 256;
+ req[10] = old / (256*256*256);
+ req[11] = old / (256*256);
+ req[12] = old / 256;
+ req[13] = old % 256;
+
+ s->Phone.Data.File = File;
+ smprintf(s, "Getting file part from filesystem\n");
+ error=GSM_WaitFor (s, req, 18, 0x6D, 4, ID_GetFile);
+ if (error != ERR_NONE) return error;
+ if (File->Used - old != (0x03 * 256 + 0xE8)) {
+ error = N6510_GetFileCRC1(s, File->ID_FullName);
+ if (error != ERR_NONE) return error;
+
+ if (N6510_FindFileCheckSum12(s, File->Buffer, File->Used) != Priv->FileCheckSum) {
+ smprintf(s,"File2 checksum is %i, File checksum is %i\n",N6510_FindFileCheckSum12(s, File->Buffer, File->Used),Priv->FileCheckSum);
+ return ERR_WRONGCRC;
+ }
+ return ERR_EMPTY;
+ }
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_SetReadOnly1(GSM_StateMachine *s, unsigned char *ID, gboolean enable)
+{
+ unsigned char SetAttr[] = {
+ N7110_FRAME_HEADER, 0x18,
+ 0x00, /* state */
+ 0x00, 0x00, 0x01,
+ 0x00, 0x20}; /* File ID */
+
+ if (!enable) SetAttr[4] = 0x06;
+
+ SetAttr[8] = atoi(DecodeUnicodeString(ID)) / 256;
+ SetAttr[9] = atoi(DecodeUnicodeString(ID)) % 256;
+ smprintf(s, "Setting readonly attribute\n");
+ return GSM_WaitFor (s, SetAttr, 10, 0x6D, 4, ID_SetAttrib);
+}
+
+static GSM_Error N6510_SetFileAttributes1(GSM_StateMachine *s, GSM_File *File)
+{
+ GSM_Error error;
+ GSM_File file2;
+
+ memset(&file2, 0, sizeof(file2));
+
+ CopyUnicodeString(file2.ID_FullName,File->ID_FullName);
+ error = N6510_GetFileFolderInfo1(s, &file2, FALSE);
+ if (error != ERR_NONE) return error;
+
+ /* setting folder attrib works, but we block it */
+ if (file2.Folder) return ERR_SHOULDBEFILE;
+
+ /* todo */
+ if (file2.System != File->System ||
+ file2.Hidden != File->Hidden ||
+ file2.Protected != File->Protected) {
+ return ERR_NOTSUPPORTED;
+ }
+
+ return N6510_SetReadOnly1(s, File->ID_FullName, File->ReadOnly);
+}
+
+/* function checks if there is file/folder with searched name in folder with specified ID */
+static GSM_Error N6510_SearchForFileName1(GSM_StateMachine *s, GSM_File *File)
+{
+ GSM_Error error;
+ GSM_File *BackupCache, *NewFiles;
+ int FilesLocationsUsed,FilesLocationsUsed2,i;
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+
+ File->Folder = FALSE;
+
+ /* making backup */
+ BackupCache = (GSM_File *)malloc(sizeof(GSM_File) * Priv->FilesLocationsUsed);
+ if (BackupCache == NULL) return ERR_MOREMEMORY;
+ memcpy(BackupCache, Priv->FilesCache, sizeof(GSM_File) * Priv->FilesLocationsUsed);
+ FilesLocationsUsed = Priv->FilesLocationsUsed;
+
+ /* Allocate new cache */
+ error = N6510_AllocFileCache(s, 1);
+ if (error != ERR_NONE) {
+ free(BackupCache);
+ return error;
+ }
+
+ /* putting own data */
+ Priv->FilesCache[0].Level = 1;
+ Priv->FilesLocationsUsed = 1;
+ CopyUnicodeString(Priv->FilesCache[0].ID_FullName,File->ID_FullName);
+
+ /* checking */
+ error = N6510_GetFileFolderInfo1(s, &Priv->FilesCache[0], TRUE);
+
+ /* backuping new data */
+ NewFiles = (GSM_File *)malloc(sizeof(GSM_File) * Priv->FilesLocationsUsed);
+ if (NewFiles == NULL) {
+ free(BackupCache);
+ BackupCache=NULL;
+ return ERR_MOREMEMORY;
+ }
+ memcpy(NewFiles, Priv->FilesCache, sizeof(GSM_File) * Priv->FilesLocationsUsed);
+ FilesLocationsUsed2 = Priv->FilesLocationsUsed;
+
+ /* restoring */
+ memcpy(Priv->FilesCache, BackupCache, sizeof(GSM_File) * FilesLocationsUsed);
+ free(BackupCache);
+ BackupCache=NULL;
+ Priv->FilesLocationsUsed = FilesLocationsUsed;
+
+ if (error != ERR_NONE) {
+ free(NewFiles);
+ NewFiles=NULL;
+ return error;
+ }
+
+ for (i = 0; i < FilesLocationsUsed2; i++) {
+ smprintf(s, "ID is %s\n",DecodeUnicodeString(NewFiles[i].ID_FullName));
+ error = N6510_GetFileFolderInfo1(s, &NewFiles[i], FALSE);
+ if (error == ERR_EMPTY) continue;
+ if (error != ERR_NONE) {
+ free(NewFiles);
+ NewFiles=NULL;
+ return error;
+ }
+ smprintf(s, "%s",DecodeUnicodeString(File->Name));
+ smprintf(s, "%s \n",DecodeUnicodeString(NewFiles[i].Name));
+ if (mywstrncasecmp(NewFiles[i].Name,File->Name,0)) {
+ smprintf(s, "the same\n");
+ File->Folder = NewFiles[i].Folder;
+ free(NewFiles);
+ NewFiles=NULL;
+ return ERR_NONE;
+ }
+ }
+ free(NewFiles);
+ NewFiles=NULL;
+ return ERR_EMPTY;
+}
+
+GSM_Error N6510_ReplyAddFileHeader1(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ unsigned char buffer[5];
+
+ switch (msg->Buffer[3]) {
+ case 0x03:
+ smprintf(s,"File header added\n");
+ sprintf(buffer,"%i",msg->Buffer[8]*256+msg->Buffer[9]);
+ EncodeUnicode(s->Phone.Data.File->ID_FullName,buffer,strlen(buffer));
+ return ERR_NONE;
+ case 0x13:
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+GSM_Error N6510_ReplyAddFilePart1(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s UNUSED)
+{
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_AddFilePart1(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle UNUSED)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ GSM_File File2;
+ GSM_Error error;
+ int j;
+ unsigned char Header[20 + (2 * (GSM_MAX_FILENAME_ID_LENGTH + 1))] = {
+ N7110_FRAME_HEADER, 0x02, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x0C, /* parent folder ID */
+ 0x00, 0x00, 0x00, 0xE8};
+ unsigned char Add[15000] = {
+ N7110_FRAME_HEADER, 0x40, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x04, /* file ID */
+ 0x00, 0x00,
+ 0x01, 0x28}; /* length */
+ unsigned char end[30] = {
+ N7110_FRAME_HEADER, 0x40, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x04, /* file ID */
+ 0x00, 0x00, 0x00, 0x00};
+
+ memset(&File2, 0, sizeof(File2));
+
+ s->Phone.Data.File = File;
+
+ if (*Pos == 0) {
+ error = N6510_SearchForFileName1(s,File);
+ if (error == ERR_NONE) return ERR_FILEALREADYEXIST;
+ if (error != ERR_EMPTY) return error;
+
+ Header[8] = atoi(DecodeUnicodeString(File->ID_FullName)) / 256;
+ Header[9] = atoi(DecodeUnicodeString(File->ID_FullName)) % 256;
+ memset(Header+14, 0x00, 300);
+ CopyUnicodeString(Header+14,File->Name);
+ Header[222] = File->Used / (256*256*256);
+ Header[223] = File->Used / (256*256);
+ Header[224] = File->Used / 256;
+ Header[225] = File->Used % 256;
+ switch(File->Type) {
+ case GSM_File_Image_JPG : Header[231]=0x02; Header[233]=0x01; break;
+ case GSM_File_Image_BMP : Header[231]=0x02; Header[233]=0x02; break;
+ case GSM_File_Image_PNG : Header[231]=0x02; Header[233]=0x03; break;
+ case GSM_File_Image_GIF : Header[231]=0x02; Header[233]=0x05; break;
+ case GSM_File_Image_WBMP : Header[231]=0x02; Header[233]=0x09; break;
+ case GSM_File_Sound_AMR : Header[231]=0x04; Header[233]=0x01; break;
+ case GSM_File_Sound_MIDI : Header[231]=0x04; Header[233]=0x05; break; /* Header[238]=0x01; */
+ case GSM_File_Sound_NRT : Header[231]=0x04; Header[233]=0x06; break;
+ case GSM_File_Video_3GP : Header[231]=0x08; Header[233]=0x05; break;
+ case GSM_File_Java_JAR : Header[231]=0x10; Header[233]=0x01; break;
+ case GSM_File_MMS:
+ Header[214]=0x07;
+ Header[215]=0xd3;
+ Header[216]=0x06;
+ Header[217]=0x01;
+ Header[218]=0x12;
+ Header[219]=0x13;
+ Header[220]=0x29;
+ Header[233]=0x01;
+ break;
+ default : Header[231]=0x01; Header[233]=0x05;
+ }
+ Header[235] = 0x01;
+ Header[236] = atoi(DecodeUnicodeString(File->ID_FullName)) / 256;
+ Header[237] = atoi(DecodeUnicodeString(File->ID_FullName)) % 256;
+ if (File->Protected) Header[238] = 0x01; /* Nokia forward lock */
+ if (File->Hidden) Header[241] = 0x01;
+ if (File->System) Header[242] = 0x01; /* fixme */
+ smprintf(s, "Adding file header\n");
+ error=GSM_WaitFor (s, Header, 246, 0x6D, 4, ID_AddFile);
+ if (error != ERR_NONE) return error;
+ }
+
+ j = 1000;
+ if (File->Used - *Pos < 1000) j = File->Used - *Pos;
+ Add[ 8] = atoi(DecodeUnicodeString(File->ID_FullName)) / 256;
+ Add[ 9] = atoi(DecodeUnicodeString(File->ID_FullName)) % 256;
+ Add[12] = j / 256;
+ Add[13] = j % 256;
+ memcpy(Add+14,File->Buffer+(*Pos),j);
+ smprintf(s, "Adding file part %ld %i\n", (long)*Pos,j);
+ error=GSM_WaitFor (s, Add, 14+j, 0x6D, 4, ID_AddFile);
+ if (error != ERR_NONE) return error;
+ *Pos = *Pos + j;
+
+ if (j < 1000) {
+ /* FIXME: This looks strange */
+ end[8] = atoi(DecodeUnicodeString(File->ID_FullName)) / 256;
+ end[9] = atoi(DecodeUnicodeString(File->ID_FullName)) % 256;
+ smprintf(s, "Frame for ending adding file\n");
+ error = GSM_WaitFor (s, end, 14, 0x6D, 4, ID_AddFile);
+ if (error != ERR_NONE) return error;
+
+ CopyUnicodeString(File2.ID_FullName,File->ID_FullName);
+ error = N6510_GetFileFolderInfo1(s, &File2, FALSE);
+ if (error != ERR_NONE) return error;
+
+ if (!File->ModifiedEmpty) {
+ Header[3] = 0x12;
+ Header[4] = 0x01;
+ Header[12] = 0x00;
+ Header[13] = 0xE8;
+ Header[8] = atoi(DecodeUnicodeString(File->ID_FullName)) / 256;
+ Header[9] = atoi(DecodeUnicodeString(File->ID_FullName)) % 256;
+ memset(Header+14, 0x00, 300);
+ CopyUnicodeString(Header+14,File->Name);
+ NOKIA_EncodeDateTime(s,Header+214,&File->Modified);
+ /* When you save too big file for phone and it changes
+ * size (some part is cut by firmware), you HAVE to write
+ * here correct file size. In other case filesystem
+ * will be damaged
+ */
+ Header[224] = File2.Used / 256;
+ Header[225] = File2.Used % 256;
+ Header[226] = Priv->FileToken / 256;
+ Header[227] = Priv->FileToken % 256;
+ switch(File->Type) {
+ case GSM_File_Image_JPG : Header[231]=0x02; Header[233]=0x01; break;
+ case GSM_File_Image_BMP : Header[231]=0x02; Header[233]=0x02; break;
+ case GSM_File_Image_PNG : Header[231]=0x02; Header[233]=0x03; break;
+ case GSM_File_Image_GIF : Header[231]=0x02; Header[233]=0x05; break;
+ case GSM_File_Image_WBMP : Header[231]=0x02; Header[233]=0x09; break;
+ case GSM_File_Sound_AMR : Header[231]=0x04; Header[233]=0x01; break;
+ case GSM_File_Sound_MIDI : Header[231]=0x04; Header[233]=0x05; break; /* Header[238]=0x01; */
+ case GSM_File_Sound_NRT : Header[231]=0x04; Header[233]=0x06; break;
+ case GSM_File_Video_3GP : Header[231]=0x08; Header[233]=0x05; break;
+ case GSM_File_Java_JAR : Header[231]=0x10; Header[233]=0x01; break;
+ case GSM_File_MMS:
+ Header[214]=0x07;
+ Header[215]=0xd3;
+ Header[216]=0x06;
+ Header[217]=0x01;
+ Header[218]=0x12;
+ Header[219]=0x13;
+ Header[220]=0x29;
+ Header[233]=0x01;
+ break;
+ default : Header[231]=0x01; Header[233]=0x05;
+ }
+ Header[235] = 0x01;
+ Header[236] = Priv->ParentID / 256;
+ Header[237] = Priv->ParentID % 256;
+ smprintf(s, "Adding file header\n");
+ error=GSM_WaitFor (s, Header, 246, 0x6D, 4, ID_AddFile);
+ if (error != ERR_NONE) return error;
+ }
+
+ /* Can't delete from phone menu */
+ if (File->ReadOnly) {
+ error = N6510_SetReadOnly1(s, File->ID_FullName, TRUE);
+ if (error != ERR_NONE) return error;
+ }
+
+ error = N6510_GetFileCRC1(s, File->ID_FullName);
+ if (error != ERR_NONE) return error;
+
+ if (N6510_FindFileCheckSum12(s, File->Buffer, File->Used) != Priv->FileCheckSum) {
+ smprintf(s,"File2 checksum is %i, File checksum is %i\n",N6510_FindFileCheckSum12(s, File->Buffer, File->Used),Priv->FileCheckSum);
+ return ERR_WRONGCRC;
+ }
+
+ return ERR_EMPTY;
+ }
+
+ return ERR_NONE;
+}
+
+GSM_Error N6510_ReplyDeleteFileFolder1(GSM_Protocol_Message *msg, GSM_StateMachine *s UNUSED)
+{
+ if (msg->Buffer[4] == 0x01) {
+ return ERR_NONE;
+ } else if (msg->Buffer[4] == 0x04) {
+ return ERR_FILENOTEXIST;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_PrivDeleteFileFolder1(GSM_StateMachine *s, unsigned char *ID, gboolean file)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ GSM_File File;
+ GSM_Error error;
+ unsigned char Delete[40] = {
+ N7110_FRAME_HEADER, 0x1E, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x35}; /* File ID */
+
+ memset(&File, 0, sizeof(File));
+
+ Priv->FilesLocationsUsed = 0;
+ CopyUnicodeString(File.ID_FullName,ID);
+ error = N6510_GetFileFolderInfo1(s, &File, TRUE);
+ if (error != ERR_NONE) return error;
+ if (file) {
+ if (File.Folder) return ERR_SHOULDBEFILE;
+ } else {
+ if (!File.Folder) return ERR_SHOULDBEFOLDER;
+ /* dont allow to delete non empty folder */
+ if (Priv->FilesLocationsUsed != 0) return ERR_FOLDERNOTEMPTY;
+ }
+
+ error = N6510_SetReadOnly1(s, ID, FALSE);
+ if (error != ERR_NONE) return error;
+
+ /* FIXME: This looks wrong */
+ Delete[8] = atoi(DecodeUnicodeString(ID)) / 256;
+ Delete[9] = atoi(DecodeUnicodeString(ID)) % 256;
+
+ return GSM_WaitFor (s, Delete, 10, 0x6D, 4, ID_DeleteFile);
+}
+
+static GSM_Error N6510_DeleteFile1(GSM_StateMachine *s, unsigned char *ID)
+{
+ return N6510_PrivDeleteFileFolder1(s,ID,TRUE);
+}
+
+static GSM_Error N6510_DeleteFolder1(GSM_StateMachine *s, unsigned char *ID)
+{
+ return N6510_PrivDeleteFileFolder1(s,ID,FALSE);
+}
+
+GSM_Error N6510_ReplyAddFolder1(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ unsigned char buffer[5];
+
+ sprintf(buffer,"%i",msg->Buffer[8]*256+msg->Buffer[9]);
+ EncodeUnicode(s->Phone.Data.File->ID_FullName,buffer,strlen(buffer));
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_AddFolder1(GSM_StateMachine *s, GSM_File *File)
+{
+ GSM_File File2;
+ GSM_Error error;
+ unsigned char Header[20 + (2 * (GSM_MAX_FILENAME_ID_LENGTH + 1))] = {
+ N7110_FRAME_HEADER, 0x04, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x0C, /* parent folder ID */
+ 0x00, 0x00, 0x00, 0xE8};
+
+ memset(&File2, 0, sizeof(File2));
+
+ CopyUnicodeString(File2.ID_FullName,File->ID_FullName);
+ error = N6510_GetFileFolderInfo1(s, &File2, FALSE);
+ if (error != ERR_NONE) return error;
+ if (!File2.Folder) return ERR_SHOULDBEFOLDER;
+
+ Header[8] = atoi(DecodeUnicodeString(File->ID_FullName)) / 256;
+ Header[9] = atoi(DecodeUnicodeString(File->ID_FullName)) % 256;
+ memset(Header+14, 0x00, 300);
+ CopyUnicodeString(Header+14,File->Name);
+ Header[233] = 0x02;
+ Header[235] = 0x01;
+ Header[236] = atoi(DecodeUnicodeString(File->ID_FullName)) / 256;
+ Header[237] = atoi(DecodeUnicodeString(File->ID_FullName)) % 256;
+
+ s->Phone.Data.File = File;
+ smprintf(s, "Adding folder\n");
+ error = GSM_WaitFor (s, Header, 246, 0x6D, 4, ID_AddFolder);
+ if (error != ERR_NONE) return error;
+
+ if (!strcmp(DecodeUnicodeString(File->ID_FullName),"0")) return ERR_FILEALREADYEXIST;
+
+ /* Can't delete from phone menu */
+ if (File->ReadOnly) {
+ error = N6510_SetReadOnly1(s, File->ID_FullName, TRUE);
+ if (error != ERR_NONE) return error;
+ }
+
+ return error;
+}
+
+static GSM_Error N6510_GetFolderListing1(GSM_StateMachine *s, GSM_File *File, gboolean start)
+{
+ GSM_Error error;
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+
+ if (start) {
+ Priv->FilesLocationsUsed = 0;
+
+ error = N6510_GetFileFolderInfo1(s, File, TRUE);
+ if (error != ERR_NONE) return error;
+
+ if (!File->Folder) return ERR_SHOULDBEFOLDER;
+ }
+
+ while (TRUE) {
+ if (Priv->FilesLocationsUsed == 0) return ERR_EMPTY;
+
+ memcpy(File,&Priv->FilesCache[0],sizeof(GSM_File));
+ error = N6510_GetFileFolderInfo1(s, File, FALSE);
+ if (error != ERR_NONE) return error;
+
+ error = N6510_ShiftFileCache(s, -1);
+ if (error != ERR_NONE) return error;
+
+ break;
+ }
+ return error;
+}
+
+/* filesystem 2 */
+
+GSM_Error N6510_ReplyOpenFile2(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ if (msg->Buffer[4]==0) {
+ smprintf(s,"File opened and handle received\n");
+ s->Phone.Data.FileHandle = msg->Buffer[6]*256*256*256+
+ msg->Buffer[7]*256*256+
+ msg->Buffer[8]*256+
+ msg->Buffer[9];
+ smprintf(s,"File handle: %i\n",
+ msg->Buffer[6]*256*256*256+
+ msg->Buffer[7]*256*256+
+ msg->Buffer[8]*256+
+ msg->Buffer[9]);
+ return ERR_NONE;
+ } else if (msg->Buffer[4] == 0x03) {
+ smprintf(s,"You can't open already existing folder\n");
+ return ERR_FILEALREADYEXIST;
+ } else if (msg->Buffer[4] == 0x06) {
+ smprintf(s,"File not exist\n");
+ return ERR_FILENOTEXIST;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_OpenFile2(GSM_StateMachine *s, char *Name, int *Handle, gboolean Create)
+{
+ unsigned char req[20 + (2 * (GSM_MAX_FILENAME_ID_LENGTH + 1))] =
+ {N6110_FRAME_HEADER, 0x72,
+ 0x00, /* mode 0 - open read only, 0x11 - read write create */
+ 0x02,
+ 0xFF, 0xFF}; /* name length */
+ int Pos = 8;
+ GSM_Error error;
+
+ if (Create) req[4] = 0x11;
+ req[6] = (UnicodeLength(Name)*2 + 2)/ 256 ;
+ req[7] = (UnicodeLength(Name)*2 + 2)% 256 ;
+ CopyUnicodeString(req+8,Name);
+ if (req[9] == 'a' || req[9] == 'A') req[9] = 'b';
+ if (req[9] == 'd' || req[9] == 'D') req[9] = 'a';
+ Pos+=UnicodeLength(Name)*2;
+ req[Pos++] = 0;
+ req[Pos++] = 0;
+
+ smprintf(s, "Opening file\n");
+ error = GSM_WaitFor (s, req, Pos, 0x6D, 4, ID_OpenFile);
+ if (error==ERR_NONE) (*Handle) = s->Phone.Data.FileHandle;
+ return error;
+}
+
+static GSM_Error N6510_CloseFile2(GSM_StateMachine *s, int *Handle)
+{
+ unsigned char req[200] = {N6110_FRAME_HEADER, 0x74, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00}; /* file handle */
+
+ req[6] = (*Handle) / (256*256*256);
+ req[7] = (*Handle) / (256*256);
+ req[8] = (*Handle) / 256;
+ req[9] = (*Handle) % 256;
+
+ smprintf(s, "Closing file\n");
+ return GSM_WaitFor (s, req, 10, 0x6D, 4, ID_CloseFile);
+}
+
+static GSM_Error N6510_GetFileCRC2(GSM_StateMachine *s, int *Handle)
+{
+ unsigned char req2[15000] = {
+ N7110_FRAME_HEADER, 0x66, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00}; /* handle */
+
+ req2[6] = (*Handle) / (256*256*256);
+ req2[7] = (*Handle) / (256*256);
+ req2[8] = (*Handle) / 256;
+ req2[9] = (*Handle) % 256;
+ return GSM_WaitFor (s, req2, 10, 0x6D, 8, ID_GetCRC);
+}
+
+GSM_Error N6510_ReplyGetFileFolderInfo2(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ GSM_File *FileInfo = s->Phone.Data.FileInfo;
+ GSM_File *File;
+ GSM_Error error;
+
+ switch (msg->Buffer[3]) {
+ case 0x69:
+ case 0x6D:
+ switch (msg->Buffer[4]) {
+ case 0x0C:
+ smprintf(s,"Probably no MMC card\n");
+ Priv->filesystem2error = ERR_MEMORY;
+ Priv->FilesEnd = TRUE;
+ return ERR_MEMORY;
+ case 0x00:
+ case 0x0D:
+ switch (msg->Buffer[5]) {
+ case 0x00:
+ break;
+ case 0x06:
+ smprintf(s,"File not exist\n");
+ return ERR_FILENOTEXIST;
+ case 0x0C:
+ smprintf(s,"Probably no MMC card\n");
+ return ERR_MEMORY;
+ default:
+ smprintf(s,"unknown status code\n");
+ return ERR_UNKNOWNRESPONSE;
+ }
+ smprintf(s,"File or folder details received\n");
+
+ if (msg->Buffer[3] == 0x69) {
+ /* File/Folder without can not be handled */
+ if (UnicodeLength(msg->Buffer+32) == 0) {
+ smprintf(s, "Ignoring file without name!\n");
+ return ERR_NONE;
+ }
+ error = N6510_AllocFileCache(s, Priv->FilesLocationsUsed + 1);
+ if (error != ERR_NONE) {
+ return error;
+ }
+
+ error = N6510_ShiftFileCache(s, 1);
+ if (error != ERR_NONE) return error;
+
+ File = &Priv->FilesCache[1];
+
+ File->Level = Priv->FilesCache[0].Level + 1;
+
+ CopyUnicodeString(File->Name,msg->Buffer+32);
+ smprintf(s,"\"%s\"\n",DecodeUnicodeString(File->Name));
+
+ CopyUnicodeString(File->ID_FullName,FileInfo->ID_FullName);
+ EncodeUnicode(File->ID_FullName+UnicodeLength(File->ID_FullName)*2,"/",1);
+ CopyUnicodeString(File->ID_FullName+UnicodeLength(File->ID_FullName)*2,msg->Buffer+32);
+ smprintf(s,"\"%s\"\n",DecodeUnicodeString(File->ID_FullName));
+ } else {
+ File = FileInfo;
+ }
+
+ smprintf(s, "File type: 0x%02X\n", msg->Buffer[29]);
+ if ((msg->Buffer[29] & 0x10) == 0x10) {
+ File->Folder = TRUE;
+ smprintf(s,"Folder\n");
+ } else {
+ File->Folder = FALSE;
+ smprintf(s,"File\n");
+ File->Used = msg->Buffer[10]*256*256*256+
+ msg->Buffer[11]*256*256+
+ msg->Buffer[12]*256+
+ msg->Buffer[13];
+ smprintf(s,"Size %ld bytes\n", (long)File->Used);
+ }
+ File->ReadOnly = FALSE;
+ if ((msg->Buffer[29] & 1) == 1) {
+ File->ReadOnly = TRUE;
+ smprintf(s,"Readonly\n");
+ }
+ File->Hidden = FALSE;
+ if ((msg->Buffer[29] & 2) == 2) {
+ File->Hidden = TRUE;
+ smprintf(s,"Hidden\n");
+ }
+ File->System = FALSE;
+ if ((msg->Buffer[29] & 4) == 4) {
+ File->System = TRUE;
+ smprintf(s,"System\n");
+ }
+ File->Protected = FALSE;
+ if ((msg->Buffer[29] & 0x40) == 0x40) {
+ File->Protected = TRUE;
+ smprintf(s,"Protected\n");
+ }
+
+ File->ModifiedEmpty = FALSE;
+ NOKIA_DecodeDateTime(s, msg->Buffer+14, &File->Modified, TRUE, FALSE);
+ if (File->Modified.Year == 0x00) File->ModifiedEmpty = TRUE;
+ if (File->Modified.Year == 0xffff) File->ModifiedEmpty = TRUE;
+
+ if (msg->Buffer[3] == 0x69 && msg->Buffer[4] == 0) Priv->FilesEnd = TRUE;
+
+ return ERR_NONE;
+ case 0x06:
+ smprintf(s,"File or folder details received - not available ?\n");
+ Priv->filesystem2error = ERR_FILENOTEXIST;
+ Priv->FilesEnd = TRUE;
+ return ERR_FILENOTEXIST;
+ case 0x0E:
+ smprintf(s,"File or folder details received - empty\n");
+ Priv->FilesEnd = TRUE;
+ return ERR_NONE;
+ }
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_GetFileFolderInfo2(GSM_StateMachine *s, GSM_File *File)
+{
+ int Pos=6;
+ unsigned char req[20 + (2 * (GSM_MAX_FILENAME_ID_LENGTH + 1))] = {
+ N7110_FRAME_HEADER,0x6C,
+ 0xFF, 0xFF}; /* name length */
+
+ s->Phone.Data.FileInfo = File;
+
+ req[4] = (UnicodeLength(File->ID_FullName)*2 + 2)/256;
+ req[5] = (UnicodeLength(File->ID_FullName)*2 + 2)%256;
+ CopyUnicodeString(req+6,File->ID_FullName);
+ if (req[7] == 'a' || req[7] == 'A') req[7] = 'b';
+ if (req[7] == 'd' || req[7] == 'D') req[7] = 'a';
+ Pos+=UnicodeLength(File->ID_FullName)*2;
+ req[Pos++] = 0;
+ req[Pos++] = 0;
+
+ smprintf(s,"Getting info for file in filesystem\n");
+ return GSM_WaitFor (s, req, Pos, 0x6D, 4, ID_GetFileInfo);
+}
+
+static GSM_Error N6510_PrivGetFolderListing2(GSM_StateMachine *s, GSM_File *File)
+{
+ GSM_Error error;
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ unsigned char req[20 + (2 * (GSM_MAX_FILENAME_ID_LENGTH + 1))] = {
+ N6110_FRAME_HEADER, 0x68,
+ 0xFF, 0xFF}; /* name length */
+ int Pos = 6, i = 0;
+
+ req[4] = (UnicodeLength(File->ID_FullName)*2 + 6)/ 256 ;
+ req[5] = (UnicodeLength(File->ID_FullName)*2 + 6)% 256 ;
+ CopyUnicodeString(req+6,File->ID_FullName);
+ if (req[7] == 'a' || req[7] == 'A') req[7] = 'b';
+ if (req[7] == 'd' || req[7] == 'D') req[7] = 'a';
+ Pos+=UnicodeLength(File->ID_FullName)*2;
+ req[Pos++] = 0;
+ req[Pos++] = '/';
+ req[Pos++] = 0;
+ req[Pos++] = '*';
+ req[Pos++] = 0;
+ req[Pos++] = 0;
+
+ smprintf(s, "Getting folder info %s\n",DecodeUnicodeString(File->ID_FullName));
+
+ Priv->filesystem2error = ERR_NONE;
+ s->Phone.Data.FileInfo = File;
+ Priv->FilesEnd = FALSE;
+ error = s->Protocol.Functions->WriteMessage(s, req, Pos, 0x6D);
+ if (error!=ERR_NONE) return error;
+
+ while (!Priv->FilesEnd) {
+ usleep(1000);
+ if (GSM_ReadDevice(s,TRUE) <= 0) {
+ i++;
+ } else {
+ i=0;
+ }
+ if (i == 3) {
+ smprintf(s,"Connection broken or WELL KNOWN phone firmware problem (which makes, that not all files are reported)\n");
+ Priv->filesystem2error = ERR_FOLDERPART;
+ return ERR_NONE;
+ }
+ }
+
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_GetNextFileFolder2(GSM_StateMachine *s, GSM_File *File, gboolean start)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ GSM_Error error;
+
+ if (start) {
+ error = N6510_AllocFileCache(s, 2);
+ if (error != ERR_NONE) return error;
+
+ Priv->FilesLocationsUsed = 2;
+
+ Priv->FilesCache[0].Level = 1;
+ Priv->FilesCache[0].Folder = TRUE;
+ Priv->FilesCache[0].Level = 1;
+ Priv->FilesCache[0].ReadOnly = FALSE;
+ Priv->FilesCache[0].System = FALSE;
+ Priv->FilesCache[0].Hidden = FALSE;
+ Priv->FilesCache[0].Protected = FALSE;
+ EncodeUnicode(Priv->FilesCache[0].ID_FullName,"d:",2);
+ EncodeUnicode(Priv->FilesCache[0].Name,"D (Permanent_memory 2)",22);
+
+ Priv->FilesCache[1].Level = 1;
+ Priv->FilesCache[1].Folder = TRUE;
+ Priv->FilesCache[1].Level = 1;
+ Priv->FilesCache[1].ReadOnly = FALSE;
+ Priv->FilesCache[1].System = FALSE;
+ Priv->FilesCache[1].Hidden = FALSE;
+ Priv->FilesCache[1].Protected = FALSE;
+ EncodeUnicode(Priv->FilesCache[1].ID_FullName,"a:",2);
+ EncodeUnicode(Priv->FilesCache[1].Name,"A (Memory card)",15);
+ }
+
+ smprintf(s, "Currently %i locations\n",Priv->FilesLocationsUsed);
+ if (Priv->FilesLocationsUsed == 0) return ERR_EMPTY;
+
+
+ if (!Priv->FilesCache[0].Folder) {
+ memcpy(File,&Priv->FilesCache[0],sizeof(GSM_File));
+ error = N6510_ShiftFileCache(s, -1);
+ if (error != ERR_NONE) return error;
+ smprintf(s, "Returning file %s, level %d\n", DecodeUnicodeString(File->ID_FullName), File->Level);
+ return ERR_NONE;
+ }
+
+ memcpy(File,&Priv->FilesCache[0],sizeof(GSM_File));
+ error = N6510_PrivGetFolderListing2(s, File);
+ if (error != ERR_NONE) return error;
+
+ memcpy(File,&Priv->FilesCache[0],sizeof(GSM_File));
+ error = N6510_ShiftFileCache(s, -1);
+ if (error != ERR_NONE) return error;
+
+ smprintf(s, "Returning folder %s, level %d\n", DecodeUnicodeString(File->ID_FullName), File->Level);
+
+ if (Priv->filesystem2error == ERR_FOLDERPART) return ERR_FOLDERPART;
+
+ return error;
+}
+
+static GSM_Error N6510_GetFilePart2(GSM_StateMachine *s, GSM_File *File, int *Handle, size_t *Size)
+{
+ int old,j;
+ GSM_Error error;
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ unsigned char req[] = {
+ N7110_FRAME_HEADER, 0x5E, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01, /* file handle */
+ 0x00, 0x00, 0x00, 0x00, /* position */
+ 0x00, 0x00, 0x03, 0xE8, /* length */
+ 0x00, 0x00, 0x03, 0xE8}; /* buffer length */
+
+ if (File->Used == 0x00) {
+ error = N6510_GetFileFolderInfo2(s, File);
+ if (error != ERR_NONE) return error;
+
+ if (File->Folder) return ERR_SHOULDBEFILE;
+
+ error = N6510_OpenFile2(s, File->ID_FullName, Handle, FALSE);
+ if (error != ERR_NONE) return error;
+
+ for (j=UnicodeLength(File->ID_FullName)-1;j>0;j--) {
+ if (File->ID_FullName[j*2+1] == '\\' || File->ID_FullName[j*2+1] == '/') break;
+ }
+ if (File->ID_FullName[j*2+1] == '\\' || File->ID_FullName[j*2+1] == '/') {
+ CopyUnicodeString(File->Name,File->ID_FullName+j*2+2);
+ } else {
+ CopyUnicodeString(File->Name,File->ID_FullName);
+ }
+
+ (*Size) = File->Used;
+ File->Used = 0;
+ }
+
+ req[6] = (*Handle) / (256*256*256);
+ req[7] = (*Handle) / (256*256);
+ req[8] = (*Handle) / 256;
+ req[9] = (*Handle) % 256;
+
+ old = File->Used;
+ req[10] = old / (256*256*256);
+ req[11] = old / (256*256);
+ req[12] = old / 256;
+ req[13] = old % 256;
+
+ s->Phone.Data.File = File;
+ smprintf(s, "Getting file part from filesystem\n");
+ error=GSM_WaitFor (s, req, 22, 0x6D, 4, ID_GetFile);
+ if (error != ERR_NONE) return error;
+
+ if (File->Used - old != (0x03 * 256 + 0xE8)) {
+ error = N6510_GetFileCRC2(s, Handle);
+ if (error != ERR_NONE) return error;
+
+ error = N6510_CloseFile2(s, Handle);
+ if (error != ERR_NONE) return error;
+
+ if (N6510_FindFileCheckSum12(s, File->Buffer, File->Used) != Priv->FileCheckSum) {
+ smprintf(s,"File2 checksum is %i, File checksum is %i\n",N6510_FindFileCheckSum12(s, File->Buffer, File->Used),Priv->FileCheckSum);
+ return ERR_WRONGCRC;
+ }
+
+ return ERR_EMPTY;
+ }
+ return ERR_NONE;
+}
+
+GSM_Error N6510_ReplySetFileDate2(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s UNUSED)
+{
+ return ERR_NONE;
+}
+
+GSM_Error N6510_ReplySetAttrib2(GSM_Protocol_Message *msg, GSM_StateMachine *s UNUSED)
+{
+ if (msg->Buffer[4] == 0x00) {
+ return ERR_NONE;
+ } else if (msg->Buffer[4] == 0x06) {
+ return ERR_FILENOTEXIST;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_SetFileAttributes2(GSM_StateMachine *s, GSM_File *File)
+{
+ int P = 10;
+ GSM_Error error;
+ GSM_File File2;
+ unsigned char Header2[20 + (2 * (GSM_MAX_FILENAME_ID_LENGTH + 1))] = {
+ N7110_FRAME_HEADER, 0x6E,
+ 0x00, 0x0c}; /* name len */
+
+ memcpy(&File2,File,sizeof(GSM_File));
+
+ error = N6510_GetFileFolderInfo2(s, File);
+ if (error != ERR_NONE) return error;
+
+ /* haven't checked. */
+ if (File->Folder) return ERR_SHOULDBEFILE;
+
+ Header2[4] = (UnicodeLength(File2.ID_FullName) + 1)/ 256 ;
+ Header2[5] = (UnicodeLength(File2.ID_FullName) + 1)% 256 ;
+ Header2[6] = 0x00;
+ Header2[7] = 0x00;
+ Header2[8] = 0x00;
+ Header2[9] = 0x00;
+ if (File2.ReadOnly) Header2[9] += 1;
+ if (File2.Hidden) Header2[9] += 2;
+ if (File2.System) Header2[9] += 4;
+ if (File2.Protected) Header2[9] += 0x40;
+ CopyUnicodeString(Header2+10,File2.ID_FullName);
+ if (Header2[11] == 'a' || Header2[11] == 'A') Header2[11] = 'b';
+ if (Header2[11] == 'd' || Header2[11] == 'D') Header2[11] = 'a';
+ P+=UnicodeLength(File2.ID_FullName)*2;
+ Header2[P++] = 0;
+ Header2[P++] = 0;
+ error = GSM_WaitFor (s, Header2, P, 0x6D, 4, ID_SetAttrib);
+ if (error != ERR_NONE) return error;
+
+ error = N6510_GetFileFolderInfo2(s, File);
+ if (error != ERR_NONE) return error;
+
+ /* mmc doesn't support protected */
+ if (File2.System != File->System ||
+ File2.ReadOnly != File->ReadOnly ||
+ File2.Hidden != File->Hidden ) {
+/* File2.Protected != File->Protected) { */
+ return ERR_NOTSUPPORTED;
+ }
+
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_AddFilePart2(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle)
+{
+ GSM_Error error;
+ int j,P;
+/* GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510; */
+/* unsigned char buffer[500]; */
+ unsigned char req[15000] = {
+ N7110_FRAME_HEADER, 0x58, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, /* handle */
+ 0x00, 0x00, 0x04, 0x00}; /* buffer len */
+ unsigned char Header[20 + (2 * (GSM_MAX_FILENAME_ID_LENGTH + 1))] = {
+ N7110_FRAME_HEADER, 0x86,
+ 0x00, 0x0c}; /* name len */
+
+ s->Phone.Data.File = File;
+
+ if (*Pos == 0) {
+ EncodeUnicode(File->ID_FullName+UnicodeLength(File->ID_FullName)*2,"/",1);
+ CopyUnicodeString(File->ID_FullName+UnicodeLength(File->ID_FullName)*2,File->Name);
+
+ error = N6510_GetFileFolderInfo2(s, File);
+ switch (error) {
+ case ERR_FILENOTEXIST:
+ break;
+ case ERR_NONE:
+ return ERR_FILEALREADYEXIST;
+ default:
+ return error;
+ }
+
+ error = N6510_OpenFile2(s, File->ID_FullName, Handle, TRUE);
+ if (error != ERR_NONE) return error;
+ }
+
+ req[6] = (*Handle) / (256*256*256);
+ req[7] = (*Handle) / (256*256);
+ req[8] = (*Handle) / 256;
+ req[9] = (*Handle) % 256;
+
+ j = 2000;
+ if (File->Used - *Pos < 2000) j = File->Used - *Pos;
+ req[10] = j / (256*256*256);
+ req[11] = j / (256*256);
+ req[12] = j / 256;
+ req[13] = j % 256;
+ memcpy(req+14,File->Buffer+(*Pos),j);
+
+ smprintf(s, "Adding file part %ld %i\n",(long)*Pos,j);
+ error=GSM_WaitFor (s, req, 14+j, 0x6D, 4, ID_AddFile);
+ if (error != ERR_NONE) return error;
+ *Pos = *Pos + j;
+
+ if (j < 2000) {
+ error = N6510_CloseFile2(s, Handle);
+ if (error != ERR_NONE) return error;
+
+ P = 14;
+ Header[4] = (UnicodeLength(File->ID_FullName) + 1)/ 256 ;
+ Header[5] = (UnicodeLength(File->ID_FullName) + 1)% 256 ;
+ Header[6] = File->Modified.Year / 256;
+ Header[7] = File->Modified.Year % 256;
+ Header[8] = File->Modified.Month;
+ Header[9] = File->Modified.Day;
+ Header[10] = 0x00;
+ Header[11] = File->Modified.Hour;
+ Header[12] = File->Modified.Minute;
+ Header[13] = File->Modified.Second;
+ CopyUnicodeString(Header+14,File->ID_FullName);
+ if (Header[15] == 'a' || Header[15] == 'A') Header[15] = 'b';
+ if (Header[15] == 'd' || Header[15] == 'D') Header[15] = 'a';
+ P+=UnicodeLength(File->ID_FullName)*2;
+ req[P++] = 0;
+ req[P++] = 0;
+ smprintf(s,"Setting file date\n");
+ error = GSM_WaitFor (s, Header, P, 0x6D, 4, ID_AddFile);
+ if (error != ERR_NONE) return error;
+
+ error = N6510_SetFileAttributes2(s,File);
+ if (error != ERR_NONE) return error;
+
+/* error = N6510_OpenFile2(s, File->ID_FullName, Handle, FALSE); */
+/* if (error != ERR_NONE) return error; */
+/* if ((*Handle) == 0) { */
+/* error = N6510_OpenFile2(s, File->ID_FullName, Handle, FALSE); */
+/* if (error != ERR_NONE) return error; */
+/* } */
+/* error = N6510_GetFileCRC2(s, Handle); */
+/* if (error != ERR_NONE) return error; */
+/* error = N6510_CloseFile2(s, Handle); */
+/* if (error != ERR_NONE) return error; */
+/* if (N6510_FindFileCheckSum12(s, File->Buffer, File->Used) != Priv->FileCheckSum) { */
+/* smprintf(s,"File2 checksum is %i, File checksum is %i\n",N6510_FindFileCheckSum12(s, File->Buffer, File->Used),Priv->FileCheckSum); */
+/* return ERR_WRONGCRC; */
+/* } */
+
+ return ERR_EMPTY;
+ }
+
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_GetFolderListing2(GSM_StateMachine *s, GSM_File *File, gboolean start)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ GSM_Error error;
+
+ if (start) {
+ if (strcasecmp(DecodeUnicodeString(File->ID_FullName),"a:") == 0 ||
+ strcasecmp(DecodeUnicodeString(File->ID_FullName),"a:\\") == 0 ||
+ strcasecmp(DecodeUnicodeString(File->ID_FullName),"d:") == 0 ||
+ strcasecmp(DecodeUnicodeString(File->ID_FullName),"d:\\") == 0) {
+ } else {
+ /* we must check, if user gave folder name or not */
+ error = N6510_GetFileFolderInfo2(s, File);
+ if (error != ERR_NONE) return error;
+ if (!File->Folder) return ERR_SHOULDBEFOLDER;
+ }
+
+ error = N6510_AllocFileCache(s, 1);
+ if (error != ERR_NONE) return error;
+
+ Priv->FilesLocationsUsed = 1;
+
+ error = N6510_PrivGetFolderListing2(s, File);
+ if (error != ERR_NONE) return error;
+
+ memcpy(File,&Priv->FilesCache[0],sizeof(GSM_File));
+
+ error = N6510_ShiftFileCache(s, -1);
+ if (error != ERR_NONE) return error;
+ }
+
+ if (Priv->FilesLocationsUsed == 0) return ERR_EMPTY;
+
+ memcpy(File,&Priv->FilesCache[0],sizeof(GSM_File));
+
+ error = N6510_ShiftFileCache(s, -1);
+ if (error != ERR_NONE) return error;
+
+ if (start) {
+ if (Priv->filesystem2error == ERR_FOLDERPART) return ERR_FOLDERPART;
+ }
+ return ERR_NONE;
+}
+
+GSM_Error N6510_ReplyDeleteFile2(GSM_Protocol_Message *msg, GSM_StateMachine *s UNUSED)
+{
+ if (msg->Buffer[4] == 0x00) {
+ return ERR_NONE;
+ } else if (msg->Buffer[4] == 0x03) {
+ /* trying to delete read only */
+ return ERR_UNKNOWN;
+ } else if (msg->Buffer[4] == 0x06) {
+ return ERR_FILENOTEXIST;
+ }
+
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_DeleteFile2(GSM_StateMachine *s, unsigned char *ID)
+{
+ unsigned char req[20 + (2 * (GSM_MAX_FILENAME_ID_LENGTH + 1))] = {
+ N7110_FRAME_HEADER, 0x62};
+ int Pos = 6;
+ GSM_File file;
+ GSM_Error error;
+
+ /* first remove readonly */
+ file.ReadOnly = FALSE;
+ file.Hidden = FALSE;
+ file.System = FALSE;
+ file.Protected = FALSE;
+
+ CopyUnicodeString(file.ID_FullName,ID);
+ error = N6510_SetFileAttributes2(s,&file);
+ if (error != ERR_NONE) return error;
+
+ req[4] = (UnicodeLength(ID)*2 + 2)/ 256 ;
+ req[5] = (UnicodeLength(ID)*2 + 2)% 256 ;
+ CopyUnicodeString(req+6,ID);
+ if (req[7] == 'a' || req[7] == 'A') req[7] = 'b';
+ if (req[7] == 'd' || req[7] == 'D') req[7] = 'a';
+ Pos+=UnicodeLength(ID)*2;
+ req[Pos++] = 0;
+ req[Pos++] = 0;
+
+ smprintf(s,"Deleting file\n");
+ return GSM_WaitFor (s, req, Pos, 0x6D, 4, ID_DeleteFile);
+}
+
+GSM_Error N6510_ReplyAddFolder2(GSM_Protocol_Message *msg, GSM_StateMachine *s UNUSED)
+{
+ if (msg->Buffer[4] == 0x00) {
+ return ERR_NONE;
+ } if (msg->Buffer[4] == 0x04) {
+ return ERR_FILEALREADYEXIST;
+ } if (msg->Buffer[4] == 0x06) {
+ return ERR_FILENOTEXIST;
+ } if (msg->Buffer[4] == 0x0C) {
+ return ERR_MEMORY;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_AddFolder2(GSM_StateMachine *s, GSM_File *File)
+{
+ GSM_Error error;
+ unsigned char req[20 + (2 * (GSM_MAX_FILENAME_ID_LENGTH + 1))] = {
+ N7110_FRAME_HEADER, 0x64};
+ int Pos = 6;
+ int Len = 0;
+
+ Len = UnicodeLength(File->ID_FullName)*2 + 2;
+
+ CopyUnicodeString(req+6,File->ID_FullName);
+ Pos+=UnicodeLength(File->ID_FullName)*2;
+ if (DecodeUnicodeString(File->ID_FullName)[UnicodeLength(File->ID_FullName)-1] != '\\' &&
+ DecodeUnicodeString(File->ID_FullName)[UnicodeLength(File->ID_FullName)-1] != '/') {
+ req[Pos++] = 0;
+ req[Pos++] = '/';
+ Len += 2;
+ }
+ CopyUnicodeString(req+Pos,File->Name);
+ if (req[Pos+1] == 'a' || req[Pos+1] == 'A') req[Pos+1] = 'b';
+ if (req[Pos+1] == 'd' || req[Pos+1] == 'D') req[Pos+1] = 'a';
+ Pos += UnicodeLength(File->Name)*2;
+ Len += UnicodeLength(File->Name)*2;
+ req[Pos++] = 0;
+ req[Pos++] = 0;
+ req[4] = Len / 256 ;
+ req[5] = Len % 256 ;
+ smprintf(s,"Adding folder\n");
+ error=GSM_WaitFor (s, req, Pos, 0x6D, 4, ID_AddFolder);
+ if (error == ERR_NONE) memcpy(File->ID_FullName,req+6,Pos);
+ return error;
+}
+
+GSM_Error N6510_ReplyDeleteFolder2(GSM_Protocol_Message *msg, GSM_StateMachine *s UNUSED)
+{
+ if (msg->Buffer[4] == 0x00) {
+ return ERR_NONE;
+ } if (msg->Buffer[4] == 0x03) {
+ return ERR_SHOULDBEFOLDER;
+ } if (msg->Buffer[4] == 0x06) {
+ return ERR_FILENOTEXIST;
+ } if (msg->Buffer[4] == 0x0C) {
+ return ERR_MEMORY;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_DeleteFolder2(GSM_StateMachine *s, unsigned char *ID)
+{
+ GSM_File File2;
+ GSM_Error error;
+ unsigned char req[20 + (2 * (GSM_MAX_FILENAME_ID_LENGTH + 1))] = {
+ N7110_FRAME_HEADER, 0x6A};
+ int Pos = 6;
+
+ /* we don't want to allow deleting non empty folders */
+ CopyUnicodeString(File2.ID_FullName,ID);
+ error = N6510_GetFolderListing2(s, &File2, TRUE);
+ switch (error) {
+ case ERR_EMPTY:
+ break;
+ case ERR_NONE:
+ return ERR_FOLDERNOTEMPTY;
+ default:
+ return error;
+ }
+
+ req[4] = (UnicodeLength(ID)*2 + 2)/ 256 ;
+ req[5] = (UnicodeLength(ID)*2 + 2)% 256 ;
+ CopyUnicodeString(req+6,ID);
+ if (req[7] == 'a' || req[7] == 'A') req[7] = 'b';
+ if (req[7] == 'd' || req[7] == 'D') req[7] = 'a';
+ Pos+=UnicodeLength(ID)*2;
+ req[Pos++] = 0;
+ req[Pos++] = 0;
+
+ smprintf(s,"Deleting folder\n");
+ return GSM_WaitFor (s, req, Pos, 0x6D, 4, ID_DeleteFolder);
+}
+
+/* shared */
+
+GSM_Error N6510_GetFolderListing(GSM_StateMachine *s, GSM_File *File, gboolean start)
+{
+ GSM_Error error;
+ GSM_File File2;
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
+
+ if (DecodeUnicodeString(File->ID_FullName)[0] == 'c' ||
+ DecodeUnicodeString(File->ID_FullName)[0] == 'C') {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILE1)) {
+ return ERR_NOTSUPPORTED;
+ }
+
+ memcpy(&File2,File,sizeof(GSM_File));
+ CopyUnicodeString(File2.ID_FullName,File->ID_FullName+3*2);
+ error = N6510_GetFolderListing1(s,&File2,start);
+ memcpy(File,&File2,sizeof(GSM_File));
+ /* GetFolderListing changes ID */
+ EncodeUnicode(File->ID_FullName,"c:/",3);
+ CopyUnicodeString(File->ID_FullName+UnicodeLength(File->ID_FullName)*2,File2.ID_FullName);
+ return error;
+ } else {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_FILES2)) {
+ return N6510_GetFolderListing2(s,File,start);
+ } else {
+ return ERR_NOTSUPPORTED;
+ }
+ }
+}
+
+GSM_Error N6510_GetNextFileFolder(GSM_StateMachine *s, GSM_File *File, gboolean start)
+{
+ GSM_Error error;
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ char buf[20 + (2 * (GSM_MAX_FILENAME_ID_LENGTH + 1))];
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
+
+ if (start) {
+ Priv->UseFs1 = TRUE;
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ /* series 40 3.0 don't have filesystem 1 */
+ Priv->UseFs1 = FALSE;
+ }
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILE1)) {
+ Priv->UseFs1 = FALSE;
+ }
+ }
+ if (Priv->UseFs1) {
+ error = N6510_GetNextFileFolder1(s,File,start);
+ if (error == ERR_EMPTY) {
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_FILES2)) {
+ return error;
+ }
+ Priv->UseFs1 = FALSE;
+ start = TRUE;
+ } else {
+ if (error == ERR_NONE) {
+ sprintf(buf,"c:/%s",DecodeUnicodeString(File->ID_FullName));
+ EncodeUnicode(File->ID_FullName,buf,strlen(buf));
+
+ if (File->Level != 1) return error;
+
+ buf[0] = 0;
+ buf[1] = 0;
+ CopyUnicodeString(buf,File->Name);
+ EncodeUnicode(File->Name,"C (",3);
+ CopyUnicodeString(File->Name+6,buf);
+ EncodeUnicode(File->Name+UnicodeLength(File->Name)*2,")",1);
+ }
+ return error;
+ }
+ }
+ return N6510_GetNextFileFolder2(s,File,start);
+}
+
+GSM_Error N6510_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle, size_t *Size)
+{
+ GSM_File File2;
+ char buf[20 + (2 * (GSM_MAX_FILENAME_ID_LENGTH + 1))];
+ GSM_Error error;
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
+
+ if (DecodeUnicodeString(File->ID_FullName)[0] == 'c' ||
+ DecodeUnicodeString(File->ID_FullName)[0] == 'C') {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILE1)) {
+ return ERR_NOTSUPPORTED;
+ }
+ memcpy(&File2,File,sizeof(GSM_File));
+ CopyUnicodeString(File2.ID_FullName,File->ID_FullName+3*2);
+ error = N6510_GetFilePart1(s,&File2, Handle, Size);
+ CopyUnicodeString(buf,File->ID_FullName);
+ memcpy(File,&File2,sizeof(GSM_File));
+ CopyUnicodeString(File->ID_FullName,buf);
+ return error;
+ } else {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_FILES2)) {
+ return N6510_GetFilePart2(s,File, Handle, Size);
+ } else {
+ return ERR_NOTSUPPORTED;
+ }
+ }
+}
+
+GSM_Error N6510_AddFilePart(GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle)
+{
+ GSM_File File2;
+ GSM_Error error;
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
+
+ if (DecodeUnicodeString(File->ID_FullName)[0] == 'c' ||
+ DecodeUnicodeString(File->ID_FullName)[0] == 'C') {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILE1)) {
+ return ERR_NOTSUPPORTED;
+ }
+
+ memcpy(&File2,File,sizeof(GSM_File));
+ CopyUnicodeString(File2.ID_FullName,File->ID_FullName+3*2);
+ error = N6510_AddFilePart1(s,&File2,Pos,Handle);
+ memcpy(File,&File2,sizeof(GSM_File));
+ /* addfilepart returns new ID */
+ EncodeUnicode(File->ID_FullName,"c:/",3);
+ CopyUnicodeString(File->ID_FullName+UnicodeLength(File->ID_FullName)*2,File2.ID_FullName);
+ return error;
+ } else {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_FILES2)) {
+ return N6510_AddFilePart2(s,File,Pos,Handle);
+ } else {
+ return ERR_NOTSUPPORTED;
+ }
+ }
+}
+
+GSM_Error N6510_DeleteFile(GSM_StateMachine *s, unsigned char *ID)
+{
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
+
+ if (DecodeUnicodeString(ID)[0] == 'c' ||
+ DecodeUnicodeString(ID)[0] == 'C') {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILE1)) {
+ return ERR_NOTSUPPORTED;
+ }
+
+ return N6510_DeleteFile1(s,ID+6);
+ } else {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_FILES2)) {
+ return N6510_DeleteFile2(s,ID);
+ } else {
+ return ERR_NOTSUPPORTED;
+ }
+ }
+}
+
+GSM_Error N6510_AddFolder(GSM_StateMachine *s, GSM_File *File)
+{
+ GSM_File File2;
+ GSM_Error error;
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
+
+ if (DecodeUnicodeString(File->ID_FullName)[0] == 'c' ||
+ DecodeUnicodeString(File->ID_FullName)[0] == 'C') {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILE1)) {
+ return ERR_NOTSUPPORTED;
+ }
+ memcpy(&File2,File,sizeof(GSM_File));
+ CopyUnicodeString(File2.ID_FullName,File->ID_FullName+3*2);
+ error = N6510_AddFolder1(s,&File2);
+ memcpy(File,&File2,sizeof(GSM_File));
+ /* addfolder returns new ID */
+ EncodeUnicode(File->ID_FullName,"c:/",3);
+ CopyUnicodeString(File->ID_FullName+UnicodeLength(File->ID_FullName)*2,File2.ID_FullName);
+ return error;
+ } else {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_FILES2)) {
+ return N6510_AddFolder2(s,File);
+ } else {
+ return ERR_NOTSUPPORTED;
+ }
+ }
+}
+
+GSM_Error N6510_DeleteFolder(GSM_StateMachine *s, unsigned char *ID)
+{
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
+
+ if (DecodeUnicodeString(ID)[0] == 'c' ||
+ DecodeUnicodeString(ID)[0] == 'C') {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILE1)) {
+ return ERR_NOTSUPPORTED;
+ }
+ return N6510_DeleteFolder1(s,ID+6);
+ } else {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_FILES2)) {
+ return N6510_DeleteFolder2(s,ID);
+ } else {
+ return ERR_NOTSUPPORTED;
+ }
+ }
+}
+
+GSM_Error N6510_GetFileSystemStatus(GSM_StateMachine *s, GSM_FileSystemStatus *status)
+{
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_FILES2)) {
+ return ERR_NOTSUPPORTED;
+ } else {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILE1)) {
+ return ERR_NOTSUPPORTED;
+ }
+ return N6510_GetFileSystemStatus1(s,status);
+ }
+}
+
+GSM_Error N6510_SetFileAttributes(GSM_StateMachine *s, GSM_File *File)
+{
+ GSM_File File2;
+ char buf[20 + (2 * (GSM_MAX_FILENAME_ID_LENGTH + 1))];
+ GSM_Error error;
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
+
+ if (DecodeUnicodeString(File->ID_FullName)[0] == 'c' ||
+ DecodeUnicodeString(File->ID_FullName)[0] == 'C') {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILE1)) {
+ return ERR_NOTSUPPORTED;
+ }
+ memcpy(&File2,File,sizeof(GSM_File));
+ CopyUnicodeString(File2.ID_FullName,File->ID_FullName+3*2);
+ error = N6510_SetFileAttributes1(s,&File2);
+ CopyUnicodeString(buf,File->ID_FullName);
+ memcpy(File,&File2,sizeof(GSM_File));
+ CopyUnicodeString(File->ID_FullName,buf);
+ return error;
+ } else {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_FILES2)) {
+ return N6510_SetFileAttributes2(s,File);
+ } else {
+ return ERR_NOTSUPPORTED;
+ }
+ }
+}
+
+GSM_Error N6510_GetNextRootFolder(GSM_StateMachine *s, GSM_File *File)
+{
+ GSM_Error error;
+ GSM_File File2;
+ unsigned char buffer[5];
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
+
+ memset(&File2, 0, sizeof(File2));
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILE1)) {
+ if (UnicodeLength(File->ID_FullName) == 0) {
+ EncodeUnicode(File->ID_FullName,"d:",2);
+ EncodeUnicode(File->Name,"D (Permanent_memory 2)",22);
+ } else if (!strcmp(DecodeUnicodeString(File->ID_FullName),"d:")) {
+ EncodeUnicode(File->ID_FullName,"a:",2);
+ error = N6510_GetFolderListing2(s, File, TRUE);
+ if (error != ERR_NONE && error != ERR_EMPTY) return ERR_EMPTY;
+ EncodeUnicode(File->Name,"A (Memory card)",15);
+ EncodeUnicode(File->ID_FullName,"a:",2);
+ } else {
+ return ERR_EMPTY;
+ }
+ return ERR_NONE;
+ }
+
+ if (UnicodeLength(File->ID_FullName) == 0) {
+ sprintf(buffer,"%i",0x01);
+ EncodeUnicode(File2.ID_FullName,buffer,strlen(buffer));
+ File2.Level = 1;
+
+ error = N6510_GetFileFolderInfo1(s, &File2, FALSE);
+ if (error != ERR_NONE) return error;
+ }
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_FILES2)) {
+ if (UnicodeLength(File->ID_FullName) == 0) {
+ memcpy(File,&File2,sizeof(GSM_File));
+ EncodeUnicode(File->Name,"C (",3);
+ CopyUnicodeString(File->Name+6,File2.Name);
+ EncodeUnicode(File->Name+UnicodeLength(File->Name)*2,")",1);
+ sprintf(buffer,"c:\\%i",0x01);
+ EncodeUnicode(File->ID_FullName,buffer,strlen(buffer));
+ } else if (!strcmp(DecodeUnicodeString(File->ID_FullName),"c:\\1")) {
+ EncodeUnicode(File->ID_FullName,"d:",2);
+ EncodeUnicode(File->Name,"D (Permanent_memory 2)",22);
+ } else if (!strcmp(DecodeUnicodeString(File->ID_FullName),"d:")) {
+ EncodeUnicode(File->ID_FullName,"a:",2);
+ error = N6510_GetFolderListing2(s, File, TRUE);
+ if (error != ERR_NONE && error != ERR_EMPTY) return ERR_EMPTY;
+ EncodeUnicode(File->Name,"A (Memory card)",15);
+ EncodeUnicode(File->ID_FullName,"a:",2);
+ } else {
+ return ERR_EMPTY;
+ }
+ return ERR_NONE;
+ }
+ if (UnicodeLength(File->ID_FullName) == 0) {
+ memcpy(File,&File2,sizeof(GSM_File));
+ EncodeUnicode(File->Name,"C (",3);
+ CopyUnicodeString(File->Name+6,File2.Name);
+ EncodeUnicode(File->Name+UnicodeLength(File->Name)*2,")",1);
+ sprintf(buffer,"c:\\%i",0x01);
+ EncodeUnicode(File->ID_FullName,buffer,strlen(buffer));
+ } else if (!strcmp(DecodeUnicodeString(File->ID_FullName),"c:\\1")) {
+ return ERR_EMPTY;
+ }
+ return ERR_NONE;
+}
+
+GSM_Error N6510_PrivGet3220FilesystemMMSFolders(GSM_StateMachine *s, GSM_MMSFolders *folders)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ gboolean Start = TRUE;
+ GSM_File Files;
+ GSM_Error error;
+
+ memset(&Files, 0, sizeof(Files));
+
+ EncodeUnicode(Files.ID_FullName,"d:/predefmessages",17);
+
+ folders->Number = 0;
+
+ smprintf(s, "Getting MMS folders\n");
+ while (1) {
+ error = N6510_GetFolderListing(s,&Files,Start);
+ if (error == ERR_EMPTY) return ERR_NONE;
+ if (error != ERR_NONE) return error;
+
+ Start = FALSE;
+
+ folders->Folder[folders->Number].InboxFolder = FALSE;
+ if (!strcmp(DecodeUnicodeString(Files.Name),"predefinbox")) {
+ folders->Folder[folders->Number].InboxFolder = TRUE;
+ }
+
+ CopyUnicodeString(Priv->MMSFoldersID2[folders->Number],Files.ID_FullName);
+
+ if (!strcmp(DecodeUnicodeString(Files.Name),"predefinbox")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Inbox",5);
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"predefsent")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Sent items",10);
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"predefoutbox")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Outbox",6);
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"predefdrafts")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Templates",9);
+ } else {
+ continue;
+ }
+
+ folders->Number++;
+ }
+}
+
+/* Series 40 3.0 */
+GSM_Error N6510_PrivGetFilesystemMMSFolders(GSM_StateMachine *s, GSM_MMSFolders *folders)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ gboolean Start = TRUE;
+ GSM_File Files;
+ GSM_Error error;
+
+ memset(&Files, 0, sizeof(Files));
+
+ EncodeUnicode(Files.ID_FullName,"d:/predefmessages",17);
+
+ folders->Number = 0;
+
+ smprintf(s, "Getting MMS folders\n");
+ while (1) {
+ error = N6510_GetFolderListing(s,&Files,Start);
+ if (error == ERR_EMPTY) return ERR_NONE;
+ if (error != ERR_NONE) return error;
+
+ Start = FALSE;
+
+ if (!strcmp(DecodeUnicodeString(Files.Name),"exchange")) {
+ continue;
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"predefdrafts")) {
+ continue;
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"predefsent")) {
+ continue;
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"predefoutbox")) {
+ continue;
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"predefinbox")) {
+ continue;
+ }
+
+ folders->Folder[folders->Number].InboxFolder = FALSE;
+ if (!strcmp(DecodeUnicodeString(Files.Name),"1")) {
+ folders->Folder[folders->Number].InboxFolder = TRUE;
+ }
+
+ CopyUnicodeString(Priv->MMSFoldersID2[folders->Number],Files.ID_FullName);
+
+ if (!strcmp(DecodeUnicodeString(Files.Name),"1")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Inbox",5);
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"3")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Sent items",10);
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"4")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Saved messages",14);
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"5")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Drafts",6);
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"6")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Templates",9);
+ } else {
+ CopyUnicodeString(folders->Folder[folders->Number].Name,Files.Name);
+ }
+
+ folders->Number++;
+ }
+}
+
+GSM_Error N6510_GetMMSFolders(GSM_StateMachine *s, GSM_MMSFolders *folders)
+{
+ GSM_Error error;
+ GSM_File Files;
+ gboolean Start = TRUE;
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ int i;
+
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOFILESYSTEM)) return ERR_NOTSUPPORTED;
+
+ memset(&Files, 0, sizeof(Files));
+
+ for (i=0;i<10;i++) {
+ Priv->MMSFoldersID2[i][0] = 0;
+ Priv->MMSFoldersID2[i][1] = 0;
+ }
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_3220_MMS)) {
+ return N6510_PrivGet3220FilesystemMMSFolders(s,folders);
+ }
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ return N6510_PrivGetFilesystemMMSFolders(s,folders);
+ }
+
+ EncodeUnicode(Files.ID_FullName,"c:/1",4);
+ while (1) {
+ error = N6510_GetFolderListing(s,&Files,Start);
+ if (error == ERR_EMPTY) break;
+ if (error != ERR_NONE) return error;
+ Start = FALSE;
+ if (!Files.Folder || strcmp(DecodeUnicodeConsole(Files.Name),"Messages")) {
+ continue;
+ }
+ Start = TRUE;
+ folders->Number = 0;
+
+ while (1) {
+ error = N6510_GetFolderListing(s,&Files,Start);
+ if (error == ERR_EMPTY) return ERR_NONE;
+ if (error != ERR_NONE) return error;
+ Start = FALSE;
+ if (!Files.Folder) continue;
+ CopyUnicodeString(folders->Folder[folders->Number].Name,Files.Name);
+ CopyUnicodeString(Priv->MMSFoldersID2[folders->Number],Files.ID_FullName);
+ folders->Folder[folders->Number].InboxFolder = FALSE;
+ if (!strcmp(DecodeUnicodeString(Files.Name),"Inbox")) {
+ folders->Folder[folders->Number].InboxFolder = TRUE;
+ }
+ folders->Number++;
+ }
+ }
+
+ /* 6230i */
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_FILES2)) {
+ EncodeUnicode(Files.ID_FullName,"d:/predefmessages",17);
+ folders->Number = 0;
+ Start = TRUE;
+ while (1) {
+ error = N6510_GetFolderListing(s,&Files,Start);
+ if (error == ERR_EMPTY) break;
+ if (error != ERR_NONE) return error;
+ Start = FALSE;
+ if (!Files.Folder) continue;
+ folders->Folder[folders->Number].InboxFolder = FALSE;
+ if (!strcmp(DecodeUnicodeString(Files.Name),"predefinbox")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Inbox",5);
+ folders->Folder[folders->Number].InboxFolder = TRUE;
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"predefoutbox")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Outbox",6);
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"predefsent")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Sent items",10);
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"predefdrafts")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Drafts",6);
+ } else {
+ CopyUnicodeString(folders->Folder[folders->Number].Name,Files.Name);
+ }
+ CopyUnicodeString(Priv->MMSFoldersID2[folders->Number],Files.ID_FullName);
+ folders->Number++;
+ }
+
+ return ERR_NONE;
+ }
+
+ return ERR_NOTSUPPORTED;
+}
+
+GSM_Error N6510_GetNextMMSFileInfo(GSM_StateMachine *s, unsigned char *FileID, int *MMSFolder, gboolean start)
+{
+ GSM_MMSFolders folders;
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ GSM_Error error;
+ GSM_File file;
+ int Handle;
+ size_t Size;
+
+ if (start) {
+ error = N6510_GetMMSFolders(s, &folders);
+ if (error != ERR_NONE)
+ return error;
+
+ Priv->MMSFolderNum = 0;
+ Priv->MMSFolderError = ERR_EMPTY;
+ }
+
+ while(TRUE) {
+ if (Priv->MMSFolderError == ERR_NONE) {
+ Priv->MMSFolderError = N6510_GetFolderListing(s,&Priv->MMSFile,FALSE);
+ if (Priv->MMSFolderError != ERR_EMPTY && Priv->MMSFolderError != ERR_NONE)
+ return Priv->MMSFolderError;
+ }
+
+ if (Priv->MMSFolderError == ERR_EMPTY) {
+ while (1) {
+ if (UnicodeLength(Priv->MMSFoldersID2[Priv->MMSFolderNum]) == 0)
+ return ERR_EMPTY;
+
+ CopyUnicodeString(Priv->MMSFile.ID_FullName,Priv->MMSFoldersID2[Priv->MMSFolderNum]);
+ Priv->MMSFolderNum++;
+
+ Priv->MMSFolderError = N6510_GetFolderListing(s,&Priv->MMSFile,TRUE);
+ if (Priv->MMSFolderError == ERR_EMPTY)
+ continue;
+ if (Priv->MMSFolderError != ERR_NONE)
+ return Priv->MMSFolderError;
+ break;
+ }
+ }
+ (*MMSFolder) = Priv->MMSFolderNum;
+ CopyUnicodeString(FileID,Priv->MMSFile.ID_FullName);
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ CopyUnicodeString(file.ID_FullName,FileID);
+ file.Used = 0;
+ file.Buffer = NULL;
+ error = N6510_GetFilePart2(s, &file, &Handle, &Size);
+ if (error == ERR_NONE) {
+ error = N6510_CloseFile2(s, &Handle);
+ if (error != ERR_NONE)
+ return error;
+ } else if (error != ERR_EMPTY) {
+ return error;
+ }
+
+ /* 0x00 = SMS, 0x01,0x03 = MMS */
+ if (file.Buffer[6] != 0x00) {
+ free(file.Buffer);
+ file.Buffer = NULL;
+ break;
+ }
+ free(file.Buffer);
+ file.Buffer = NULL;
+ } else {
+ break;
+ }
+ }
+
+ return ERR_NONE;
+}
+
+/* Series 40 3.0 */
+GSM_Error N6510_PrivGetFilesystemSMSFolders(GSM_StateMachine *s, GSM_SMSFolders *folders, gboolean real)
+{
+ gboolean Start = TRUE;
+ GSM_File Files;
+ GSM_Error error;
+
+ EncodeUnicode(Files.ID_FullName,"d:/predefmessages",17);
+
+ folders->Number = 0;
+
+ smprintf(s, "Getting SMS folders\n");
+ while (1) {
+ error = N6510_GetFolderListing(s,&Files,Start);
+ if (error == ERR_EMPTY) return ERR_NONE;
+ if (error != ERR_NONE) return error;
+
+ Start = FALSE;
+
+ smprintf(s, "Folder name: '%s'\n", DecodeUnicodeString(Files.Name));
+
+ if (!strcmp(DecodeUnicodeString(Files.Name),"exchange")) {
+ continue;
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"predefdrafts")) {
+ continue;
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"predefsent")) {
+ continue;
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"predefoutbox")) {
+ continue;
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"predefinbox")) {
+ continue;
+ }
+
+ folders->Folder[folders->Number].InboxFolder = FALSE;
+ if (!strcmp(DecodeUnicodeString(Files.Name),"1")) {
+ folders->Folder[folders->Number].InboxFolder = TRUE;
+ }
+ folders->Folder[folders->Number].OutboxFolder = FALSE;
+ if (!strcmp(DecodeUnicodeString(Files.Name),"2")) {
+ folders->Folder[folders->Number].OutboxFolder = TRUE;
+ }
+ if (real) {
+ CopyUnicodeString(folders->Folder[folders->Number].Name,Files.Name);
+ } else {
+ if (!strcmp(DecodeUnicodeString(Files.Name),"1")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Inbox",5);
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"2")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Outbox",6);
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"3")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Sent items",10);
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"4")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Saved messages",14);
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"5")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Drafts",6);
+ } else if (!strcmp(DecodeUnicodeString(Files.Name),"6")) {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"Templates",9);
+ } else {
+ EncodeUnicode(folders->Folder[folders->Number].Name,"User folder ",12);
+ CopyUnicodeString(folders->Folder[folders->Number].Name + 24, Files.Name);
+ }
+ }
+ folders->Folder[folders->Number].Memory = MEM_ME;
+ smprintf(s, "Folder[%d] = \"%s\", memory: %s, inbox: %d, outbox: %d\n",
+ folders->Number,
+ DecodeUnicodeString(folders->Folder[folders->Number].Name),
+ GSM_MemoryTypeToString(folders->Folder[folders->Number].Memory),
+ folders->Folder[folders->Number].InboxFolder,
+ folders->Folder[folders->Number].OutboxFolder);
+ folders->Number++;
+ }
+}
+
+/* Series 40 3.0 */
+GSM_Error N6510_GetFilesystemSMSFolders(GSM_StateMachine *s, GSM_SMSFolders *folders)
+{
+ return N6510_PrivGetFilesystemSMSFolders(s, folders, FALSE);
+}
+
+/* Series 40 3.0 */
+static void N26510_GetSMSLocation(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char *folderid, int *location)
+{
+ int ifolderid;
+
+ /* simulate flat SMS memory */
+ if (sms->Folder==0x00) {
+ ifolderid = sms->Location / GSM_PHONE_MAXSMSINFOLDER;
+ *folderid = ifolderid + 0x01;
+ *location = sms->Location - ifolderid * GSM_PHONE_MAXSMSINFOLDER;
+ } else {
+ *folderid = sms->Folder;
+ *location = sms->Location;
+ }
+ smprintf(s, "SMS folder %i & location %i -> 6510 folder %i & location %i\n",
+ sms->Folder,sms->Location,*folderid,*location);
+}
+
+/* Series 40 3.0 */
+static void N26510_SetSMSLocation(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char folderid, int location)
+{
+ sms->Folder = 0;
+ sms->Location = (folderid - 0x01) * GSM_PHONE_MAXSMSINFOLDER + location;
+ smprintf(s, "6510 folder %i & location %i -> SMS folder %i & location %i\n",
+ folderid,location,sms->Folder,sms->Location);
+}
+
+/* Series 40 3.0 */
+GSM_Error N6510_DecodeFilesystemSMS(GSM_StateMachine *s, GSM_MultiSMSMessage *sms, GSM_File *FFF, int location)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ size_t parse_len, pos;
+ int loc;
+ GSM_Error error;
+ gboolean unknown, has_number;
+
+ sms->Number = 1;
+ sms->SMS[0].OtherNumbersNum = 0;
+
+ loc = sms->SMS[0].Location;
+
+ if (FFF->Used < 96) {
+ smprintf(s, "Too short message data!\n");
+ return ERR_CORRUPTED;
+ }
+
+ /* Copy recipient/sender number */
+ /* Data we get from PDU seem to be bogus */
+ /* This might be later overwriten using tags at the end of file */
+ CopyUnicodeString(sms->SMS[0].Number, FFF->Buffer + 94);
+ smprintf(s, "SMS number: %s\n", DecodeUnicodeString(sms->SMS[0].Number));
+ has_number = FALSE;
+
+ /* Do we have any PDU data? */
+ if (FFF->Buffer[7] > 0 && FFF->Used > 176) {
+ /* Parse PDU data */
+ error = GSM_DecodePDUFrame(&(s->di), &(sms->SMS[0]), FFF->Buffer + 176, FFF->Used - 176, &parse_len, FALSE);
+ if (error != ERR_NONE) return error;
+
+ sms->SMS[0].Location = loc;
+
+ switch (sms->SMS[0].PDU) {
+ case SMS_Deliver:
+ sms->SMS[0].State = SMS_Read; /* @bug FIXME: this is wrong */
+ break;
+ case SMS_Submit:
+ sms->SMS[0].State = SMS_Sent; /* @bug FIXME: this is wrong */
+ break;
+ case SMS_Status_Report:
+ sms->SMS[0].State = SMS_Read; /* @bug FIXME: this is wrong */
+ break;
+ }
+
+ if (parse_len != FFF->Buffer[7]) {
+ smprintf(s, "ERROR: Parsed PDU data have different length than header says!\n");
+ return ERR_CORRUPTED;
+ }
+ } else {
+ GSM_SetDefaultReceivedSMSData(&sms->SMS[0]);
+ sms->SMS[0].PDU = SMS_Submit;
+ sms->SMS[0].State = SMS_Read; /* @bug FIXME: this is wrong */
+ }
+
+ /* Process structured data */
+ pos = 176 + FFF->Buffer[7];
+
+ /* No structured data? */
+ if (pos >= FFF->Used) {
+ goto done;
+ }
+
+ /* First master block - 0x01 <WORD LENGTH> */
+ if (FFF->Buffer[pos] != 0x01) {
+ smprintf(s, "Unknown block in SMS data after PDU: 0x%02x\n", FFF->Buffer[pos]);
+ DumpMessage(&(s->di), FFF->Buffer + pos, FFF->Used - pos);
+ return ERR_UNKNOWN;
+ }
+ pos += 3;
+
+ while (pos < FFF->Used) {
+ unknown = FALSE;
+ if (pos + 1 >= FFF->Used) {
+ if (pos + 1 == FFF->Used && FFF->Buffer[pos] == 0x00) {
+ smprintf(s, "File padded with 0x00, assuming it is okay\n");
+ break;
+ }
+ smprintf(s, "ERROR: Reach end of file before type of block!\n");
+ return ERR_BUG;
+ }
+ if (FFF->Buffer[pos] == 0x00) {
+ smprintf(s, "WARNING: 0x00 block, assuming rest is just junk!\n");
+ break;
+ }
+ if (pos + 2 == FFF->Used && FFF->Buffer[pos] == 0x01) {
+ smprintf(s, "WARNING: 0x01 block, assuming rest is just junk!\n");
+ break;
+ }
+ if (pos + 2 >= FFF->Used) {
+ smprintf(s, "ERROR: Reach end of file before size of block!\n");
+ return ERR_BUG;
+ }
+ switch (FFF->Buffer[pos]) {
+ case 0x02: /* SMSC number, ASCII */
+ if (FFF->Buffer[pos + 2] <= 1) break;
+ if (FFF->Buffer[pos + 2] - 1 > GSM_MAX_NUMBER_LENGTH) {
+ smprintf(s, "WARNING: Too long SMS number, ignoring!\n");
+ } else {
+ EncodeUnicode(sms->SMS[0].SMSC.Number, FFF->Buffer + pos + 3, FFF->Buffer[pos + 2]);
+ }
+ break;
+ case 0x03: /* Name, unicode */
+ if (FFF->Buffer[pos + 2] <= 1) break;
+ if (FFF->Buffer[pos + 2]/2 - 1 > GSM_MAX_SMS_NAME_LENGTH) {
+ smprintf(s, "WARNING: Too long SMS name, ignoring!\n");
+ } else {
+ CopyUnicodeString(sms->SMS[0].Name, FFF->Buffer + pos + 3);
+ }
+ break;
+ case 0x04: /* Sender, unicode */
+ case 0x05: /* Recipient, unicode */
+ case 0x2b: /* some text (Sender?), unicode */
+ if (FFF->Buffer[pos + 2] <= 1) break;
+ if (FFF->Buffer[pos + 2]/2 - 1 > GSM_MAX_NUMBER_LENGTH) {
+ smprintf(s, "WARNING: Too long SMS number, ignoring!\n");
+ } else {
+ if (!has_number) {
+ CopyUnicodeString(sms->SMS[0].Number, FFF->Buffer + pos + 3);
+ has_number = TRUE;
+ } else {
+ if (sms->SMS[0].OtherNumbersNum < GSM_SMS_OTHER_NUMBERS) {
+ CopyUnicodeString(sms->SMS[0].OtherNumbers[sms->SMS[0].OtherNumbersNum++], FFF->Buffer + pos + 3);
+ } else {
+ smprintf(s, "WARNING: Too many recipients, ignoring some!\n");
+ }
+ }
+ }
+ break;
+ case 0x25: /* Some unicode text (Name?) */
+ case 0x20: /* Some ascii text (GmailId) */
+ unknown = TRUE;
+ break;
+ case 0x01:
+ /* This is probably 0 = received, 1 = sent */
+ if (FFF->Buffer[pos + 2] != 1 ||
+ (FFF->Buffer[pos + 3] != 0x00 && FFF->Buffer[pos + 3] != 0x01)) {
+ unknown = TRUE;
+ }
+ break;
+ case 0x0c:
+ /* This seems to be message ID (per number) */
+ break;
+ case 0x24:
+ /* 24$|00 |01 |01 */
+ /* 24$|00 |01 |00 */
+ if ((FFF->Buffer[pos + 2] != 1 || FFF->Buffer[pos + 3] != 1) &&
+ (FFF->Buffer[pos + 2] != 1 || FFF->Buffer[pos + 3] != 0)) {
+ unknown = TRUE;
+ }
+ break;
+ case 0x07:
+ /* 07 |00 |01 |00 */
+ if (FFF->Buffer[pos + 2] != 1 || (FFF->Buffer[pos + 3] != 0x0F && FFF->Buffer[pos + 3] != 0x0e && FFF->Buffer[pos + 3] != 0x00)) {
+ unknown = TRUE;
+ }
+ break;
+ case 0x0b:
+ case 0x0e:
+ case 0x22:
+ /* 22"|00 |01 |84 */
+ case 0x26:
+ case 0x27:
+ case 0x2a:
+ case 0x2f:
+ case 0x08:
+ if (FFF->Buffer[pos + 2] != 1 || FFF->Buffer[pos + 3] != 0x00) {
+ unknown = TRUE;
+ }
+ break;
+ case 0x06:
+ case 0x09:
+ case 0x12:
+ /* Some ID: 12 |00 |04 |355|EA |6En|D2 */
+ case 0x23:
+ /* Some ID: 23#|00 |04 |00 |00 |09 |A6 */
+ case 0x2D:
+ /* Some ID: 2D-|00 |04 |00 |00 |00 |00 */
+ if (FFF->Buffer[pos + 2] != 4 ||
+ FFF->Buffer[pos + 3] != 0x00 ||
+ FFF->Buffer[pos + 4] != 0x00 ||
+ FFF->Buffer[pos + 5] != 0x00 ||
+ FFF->Buffer[pos + 6] != 0x00
+ ) {
+ unknown = TRUE;
+ }
+ break;
+ case 0x0f:
+ if (FFF->Buffer[pos + 2] != 2 ||
+ FFF->Buffer[pos + 3] != 0x00 ||
+ FFF->Buffer[pos + 4] != 0x00
+ ) {
+ unknown = TRUE;
+ }
+ break;
+ default:
+ unknown = TRUE;
+ break;
+ }
+ if (unknown) {
+ smprintf(s, "WARNING: Unknown block 0x%02x, see <https://wammu.eu/support/bugs/> how to report\n", FFF->Buffer[pos]);
+ DumpMessage(&(s->di), FFF->Buffer + pos, 3 + (FFF->Buffer[pos + 1] << 8) + FFF->Buffer[pos + 2]);
+#ifdef DEBUG
+ } else {
+ smprintf(s, "Decoded block 0x%02x\n", FFF->Buffer[pos]);
+ DumpMessage(&(s->di), FFF->Buffer + pos, 3 + (FFF->Buffer[pos + 1] << 8) + FFF->Buffer[pos + 2]);
+#endif
+ }
+ pos += 3 + (FFF->Buffer[pos + 1] << 8) + FFF->Buffer[pos + 2];
+ }
+
+done:
+ sms->SMS[0].DateTime = FFF->Modified;
+ sms->SMS[0].DateTime.Timezone = 0;
+
+ free(FFF->Buffer);
+ FFF->Buffer = NULL;
+
+ N26510_SetSMSLocation(s, &sms->SMS[0], 0, location);
+
+ sms->SMS[0].Folder = Priv->SMSFileFolder;
+ smprintf(s, "Folder[%d] %s: %d\n", sms->SMS[0].Folder, DecodeUnicodeString(Priv->LastSMSFolders.Folder[sms->SMS[0].Folder].Name), Priv->LastSMSFolders.Folder[sms->SMS[0].Folder].InboxFolder);
+ sms->SMS[0].InboxFolder = Priv->LastSMSFolders.Folder[sms->SMS[0].Folder].InboxFolder;
+ sms->SMS[0].Location = 0; /* fixme */
+
+ return ERR_NONE;
+}
+
+GSM_Error N6510_GetNextFilesystemSMS(GSM_StateMachine *s, GSM_MultiSMSMessage *sms, gboolean start)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ unsigned char folderid;
+ int location,Handle;
+ size_t Size;
+ GSM_Error error;
+ GSM_File FFF;
+ gboolean start2=start;
+
+ GSM_SetDefaultReceivedSMSData(&sms->SMS[0]);
+
+ while (TRUE) {
+ if (start2) {
+ Priv->SMSFileError = ERR_EMPTY;
+ Priv->SMSFileFolder = 0;
+ location = 1;
+ error=N6510_PrivGetFilesystemSMSFolders(s,&Priv->LastSMSFolders,TRUE);
+ if (error!=ERR_NONE) return error;
+ } else {
+ sms->SMS[0].Folder = 0;
+ N26510_GetSMSLocation(s, &sms->SMS[0], &folderid, &location);
+ location++;
+ if (Priv->SMSFileError != ERR_EMPTY) {
+ Priv->SMSFileError = N6510_GetFolderListing(s,&Priv->SMSFile,FALSE);
+ }
+ }
+ start2 = FALSE;
+ while (Priv->SMSFileError == ERR_EMPTY) {
+ Priv->SMSFileFolder++;
+ /* Too high folder number */
+ if (Priv->SMSFileFolder > Priv->LastSMSFolders.Number) {
+ return ERR_EMPTY;
+ }
+
+ EncodeUnicode(Priv->SMSFile.ID_FullName, "d:/predefmessages/", 18);
+ CopyUnicodeString(Priv->SMSFile.ID_FullName + 36, Priv->LastSMSFolders.Folder[Priv->SMSFileFolder-1].Name);
+ smprintf(s,"folder name is %s\n", DecodeUnicodeString(Priv->SMSFile.ID_FullName));
+
+ Priv->SMSFileError = N6510_GetFolderListing(s,&Priv->SMSFile,TRUE);
+ }
+
+ /* readfile */
+ FFF.Buffer= NULL;
+ FFF.Used = 0;
+ FFF.ID_FullName[0] = 0;
+ FFF.ID_FullName[1] = 0;
+ CopyUnicodeString(FFF.ID_FullName,Priv->SMSFile.ID_FullName);
+ smprintf(s,"sms file name is %s\n",DecodeUnicodeString(FFF.ID_FullName));
+ error = ERR_NONE;
+ while (error == ERR_NONE) {
+ error = N6510_GetFilePart(s,&FFF,&Handle,&Size);
+ /* if mms, don't read all */
+ if (error==ERR_NONE && FFF.Used>5 && FFF.Buffer[6] != 0x00) {
+ error = N6510_CloseFile2(s, &Handle);
+ if (error != ERR_NONE) return error;
+ break;
+ }
+ }
+ if (FFF.Buffer != NULL) {
+ DumpMessage(&s->di, FFF.Buffer, FFF.Used);
+
+ /* 0x00 = SMS, 0x01,0x03 = MMS
+ * We care only messages with PDU */
+ if (FFF.Buffer[6] == 0x00 && FFF.Buffer[7] != 0) break;
+
+
+ smprintf(s,"mms file");
+ free(FFF.Buffer);
+ FFF.Buffer = NULL;
+ }
+ }
+
+ return N6510_DecodeFilesystemSMS(s, sms, &FFF, location);
+}
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct4s40/6510/6510file.h b/libgammu/phone/nokia/dct4s40/6510/6510file.h
new file mode 100644
index 0000000..12810e9
--- /dev/null
+++ b/libgammu/phone/nokia/dct4s40/6510/6510file.h
@@ -0,0 +1,32 @@
+
+GSM_Error N6510_GetFileSystemStatus (GSM_StateMachine *s, GSM_FileSystemStatus *status);
+GSM_Error N6510_GetNextFileFolder (GSM_StateMachine *s, GSM_File *File, gboolean start);
+GSM_Error N6510_GetFolderListing (GSM_StateMachine *s, GSM_File *File, gboolean start);
+GSM_Error N6510_AddFolder (GSM_StateMachine *s, GSM_File *File);
+GSM_Error N6510_DeleteFolder (GSM_StateMachine *s, unsigned char *ID);
+GSM_Error N6510_GetFilePart (GSM_StateMachine *s, GSM_File *File, int *Handle, size_t *Size);
+GSM_Error N6510_AddFilePart (GSM_StateMachine *s, GSM_File *File, size_t *Pos, int *Handle);
+GSM_Error N6510_DeleteFile (GSM_StateMachine *s, unsigned char *ID);
+GSM_Error N6510_SetFileAttributes (GSM_StateMachine *s, GSM_File *File);
+GSM_Error N6510_GetNextRootFolder (GSM_StateMachine *s, GSM_File *File);
+GSM_Error N6510_GetMMSFolders (GSM_StateMachine *s, GSM_MMSFolders *folders);
+GSM_Error N6510_GetNextMMSFileInfo (GSM_StateMachine *s, unsigned char *FileID, int *MMSFolder, gboolean start);
+GSM_Error N6510_GetFilesystemSMSFolders (GSM_StateMachine *s, GSM_SMSFolders *folders);
+GSM_Error N6510_GetNextFilesystemSMS (GSM_StateMachine *s, GSM_MultiSMSMessage *sms, gboolean start);
+
+GSM_Error N6510_ReplyGetFileCRC12 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplySetAttrib2 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplySetFileDate2 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyOpenFile2 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyGetFileFolderInfo1 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyGetFileFolderInfo2 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyGetFileFolderListing2 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyGetFileSystemStatus1 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyGetFilePart12 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyAddFileHeader1 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyAddFilePart1 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyDeleteFile2 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyAddFolder1 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyAddFolder2 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyDeleteFolder2 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N6510_ReplyDeleteFileFolder1 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
diff --git a/libgammu/phone/nokia/dct4s40/6510/n6510.c b/libgammu/phone/nokia/dct4s40/6510/n6510.c
new file mode 100644
index 0000000..86f1cdc
--- /dev/null
+++ b/libgammu/phone/nokia/dct4s40/6510/n6510.c
@@ -0,0 +1,4627 @@
+/* (c) 2002-2005 by Marcin Wiacek */
+/* based on some Markus Plail, Pawel Kot work from Gnokii (www.gnokii.org)
+ * (C) 1999-2000 Hugh Blemings & Pavel Janik ml. (C) 2001-2004 Pawel Kot
+ * GNU GPL version 2 or later
+ */
+/* Due to a problem in the source code management, the names of some of
+ * the authors have unfortunately been lost. We do not mean to belittle
+ * their efforts and hope they will contact us to see their names
+ * properly added to the Copyright notice above.
+ * Having published their contributions under the terms of the GNU
+ * General Public License (GPL) [version 2], the Copyright of these
+ * authors will remain respected by adhering to the license they chose
+ * to publish their code under.
+ */
+
+#include <gammu-config.h>
+
+#ifdef GSM_ENABLE_NOKIA6510
+
+#include <string.h>
+#include <time.h>
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
+#include <gammu-nokia.h>
+
+#include "../../../../misc/coding/coding.h"
+#include "../../../../misc/locales.h"
+#include "../../../../gsmcomon.h"
+#include "../../../../service/gsmlogo.h"
+#include "../../../../service/gsmnet.h"
+#include "../../../../service/gsmring.h"
+#include "../../../../service/sms/gsmmulti.h"
+#include "../../nfunc.h"
+#include "../../nfuncold.h"
+#include "../../../pfunc.h"
+#include "../dct4func.h"
+#include "n6510.h"
+#include "6510cal.h"
+#include "6510file.h"
+
+static GSM_Error N6510_Initialise (GSM_StateMachine *s)
+{
+ s->Phone.Data.Priv.N6510.CalendarIconsNum = 0;
+ s->Phone.Data.Priv.N6510.LastFreeMemoryLocation = 0;
+ s->Phone.Data.Priv.N6510.LastFreeMemoryType = 0;
+ s->Phone.Data.Priv.N6510.FilesLocationsAvail = 0;
+ s->Phone.Data.Priv.N6510.FilesLocationsUsed = 0;
+ s->Phone.Data.Priv.N6510.FilesCache = NULL;
+ s->Phone.Data.Priv.N6510.ScreenWidth = 0;
+ s->Phone.Data.Priv.N6510.ScreenHeight = 0;
+
+ /* Default timeout for cables */
+ s->Phone.Data.Priv.N6510.Timeout = 8;
+ if (s->ConnectionType == GCT_IRDAPHONET || s->ConnectionType == GCT_FBUS2IRDA) {
+ s->Phone.Data.Priv.N6510.Timeout = 40;
+ }
+ if (s->ConnectionType == GCT_BLUEPHONET || s->ConnectionType == GCT_BLUEFBUS2) {
+ s->Phone.Data.Priv.N6510.Timeout = 20;
+ }
+
+ /* Enables various things like incoming SMS, call info, etc. */
+ return N71_65_EnableFunctions (s, "\x01\x02\x06\x0A\x14\x17\x39", 7);
+}
+
+static GSM_Error N6510_Terminate (GSM_StateMachine *s)
+{
+ free(s->Phone.Data.Priv.N6510.FilesCache);
+ s->Phone.Data.Priv.N6510.FilesCache = NULL;
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_ReplyGetMemory(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "Phonebook entry received\n");
+ if (msg->Buffer[6] == 0x0f)
+ return N71_65_ReplyGetMemoryError(msg->Buffer[10], s);
+
+ if (msg->Length < 22) {
+ return ERR_UNKNOWN;
+ }
+ return N71_65_DecodePhonebook(s,
+ s->Phone.Data.Memory,
+ s->Phone.Data.Bitmap,
+ s->Phone.Data.SpeedDial,
+ msg->Buffer + 22,
+ msg->Length - 22,
+ FALSE);
+}
+
+static GSM_Error N6510_GetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry)
+{
+ GSM_Error error;
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x07, 0x01, 0x01, 0x00, 0x01,
+ 0xfe, 0x10, /* memory type */
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x01, /* location */
+ 0x00, 0x00, 0x01};
+
+ req[9] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES);
+ if (req[9]==0xff) return ERR_NOTSUPPORTED;
+
+ if (entry->Location==0x00) return ERR_INVALIDLOCATION;
+
+ req[14] = entry->Location / 256;
+ req[15] = entry->Location % 256;
+
+ s->Phone.Data.Memory=entry;
+ smprintf(s, "Getting phonebook entry\n");
+ error = GSM_WaitFor (s, req, 19, 0x03, s->Phone.Data.Priv.N6510.Timeout, ID_GetMemory);
+ if (error == ERR_WORKINPROGRESS) {
+ sleep(2);
+ smprintf(s, "Retrying to get phonebook entry\n");
+ error = GSM_WaitFor (s, req, 19, 0x03, s->Phone.Data.Priv.N6510.Timeout, ID_GetMemory);
+ }
+ if (entry->MemoryType == MEM_DC || entry->MemoryType == MEM_RC || entry->MemoryType == MEM_MC) {
+ /* 6111 */
+ if (error == ERR_NOTSUPPORTED) return ERR_EMPTY;
+ }
+ return error;
+}
+
+static GSM_Error N6510_ReplyGetMemoryStatus(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "Memory status received\n");
+ /* Quess ;-)) */
+ if (msg->Buffer[14]==0x10) {
+ Data->MemoryStatus->MemoryFree = msg->Buffer[18]*256 + msg->Buffer[19];
+ Data->MemoryStatus->MemoryUsed = msg->Buffer[20]*256 + msg->Buffer[21];
+ } else if (msg->Buffer[14]==0x02) {
+ Data->MemoryStatus->MemoryFree = msg->Buffer[22];
+ Data->MemoryStatus->MemoryUsed = msg->Buffer[21];
+ } else {
+ Data->MemoryStatus->MemoryFree = msg->Buffer[17];
+ Data->MemoryStatus->MemoryUsed = msg->Buffer[20]*256 + msg->Buffer[21];
+ }
+ smprintf(s, "Size : %i\n",Data->MemoryStatus->MemoryFree);
+ smprintf(s, "Used : %i\n",Data->MemoryStatus->MemoryUsed);
+ Data->MemoryStatus->MemoryFree -= Data->MemoryStatus->MemoryUsed;
+ smprintf(s, "Free : %i\n",Data->MemoryStatus->MemoryFree);
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_GetMemoryStatus(GSM_StateMachine *s, GSM_MemoryStatus *Status)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x03, 0x02,
+ 0x00, /* memory type */
+ 0x55, 0x55, 0x55, 0x00};
+
+ req[5] = NOKIA_GetMemoryType(s, Status->MemoryType,N71_65_MEMORY_TYPES);
+ if (req[5]==0xff) return ERR_NOTSUPPORTED;
+
+ s->Phone.Data.MemoryStatus=Status;
+ smprintf(s, "Getting memory status\n");
+ return GSM_WaitFor (s, req, 10, 0x03, s->Phone.Data.Priv.N6510.Timeout, ID_GetMemoryStatus);
+}
+
+static GSM_Error N6510_ReplyGetSMSC(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int i, current, j;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+ size_t pos;
+ GSM_Error error;
+
+ switch (msg->Buffer[4]) {
+ case 0x00:
+ smprintf(s, "SMSC received\n");
+ break;
+ case 0x02:
+ smprintf(s, "SMSC empty\n");
+ return ERR_INVALIDLOCATION;
+ case 0x09:
+ smprintf(s, "SMSC empty???\n");
+ return ERR_INVALIDLOCATION;
+ default:
+ smprintf(s, "Unknown SMSC state: %02x\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ memset(Data->SMSC,0,sizeof(GSM_SMSC));
+ Data->SMSC->Location = msg->Buffer[8];
+ Data->SMSC->Format = SMS_FORMAT_Text;
+ switch (msg->Buffer[10]) {
+ case 0x00: Data->SMSC->Format = SMS_FORMAT_Text; break;
+ case 0x22: Data->SMSC->Format = SMS_FORMAT_Fax; break;
+ case 0x26: Data->SMSC->Format = SMS_FORMAT_Pager; break;
+ case 0x32: Data->SMSC->Format = SMS_FORMAT_Email; break;
+ }
+ Data->SMSC->Validity.Format = SMS_Validity_RelativeFormat;
+ Data->SMSC->Validity.Relative = msg->Buffer[12];
+ if (msg->Buffer[12] == 0x00) Data->SMSC->Validity.Relative = SMS_VALID_Max_Time;
+
+ current = 14;
+ for (i=0;i<msg->Buffer[13];i++) {
+ switch (msg->Buffer[current]) {
+ case 0x81:
+ j=current+4;
+ while (msg->Buffer[j]!=0) {j++;}
+ j=j-33;
+ if (j>GSM_MAX_SMSC_NAME_LENGTH) {
+ smprintf(s, "Too long name\n");
+ return ERR_UNKNOWNRESPONSE;
+ }
+ CopyUnicodeString(Data->SMSC->Name,msg->Buffer+current+4);
+ smprintf(s, " Name \"%s\"\n", DecodeUnicodeString(Data->SMSC->Name));
+ break;
+ case 0x82:
+ switch (msg->Buffer[current+2]) {
+ case 0x01:
+ pos = current + 4;
+ error = GSM_UnpackSemiOctetNumber(&(s->di), Data->SMSC->DefaultNumber, msg->Buffer, &pos, msg->Length, TRUE);
+ if (error != ERR_NONE) {
+ return error;
+ }
+ smprintf(s, " Default number \"%s\"\n", DecodeUnicodeString(Data->SMSC->DefaultNumber));
+ break;
+ case 0x02:
+ pos = current + 4;
+ error = GSM_UnpackSemiOctetNumber(&(s->di), Data->SMSC->Number, msg->Buffer, &pos, msg->Length, FALSE);
+ if (error != ERR_NONE) {
+ return error;
+ }
+ smprintf(s, " Number \"%s\"\n", DecodeUnicodeString(Data->SMSC->Number));
+ break;
+ default:
+ smprintf(s, "Unknown SMSC number: %02x\n",msg->Buffer[current+2]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ break;
+ default:
+ smprintf(s, "Unknown SMSC block: %02x\n",msg->Buffer[current]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ current = current + msg->Buffer[current+1];
+ }
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_GetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x14,
+ 0x01, /* location */
+ 0x00};
+
+ if (smsc->Location==0x00) return ERR_INVALIDLOCATION;
+
+ req[4]=smsc->Location;
+
+ s->Phone.Data.SMSC=smsc;
+ smprintf(s, "Getting SMSC\n");
+ return GSM_WaitFor (s, req, 6, 0x02, s->Phone.Data.Priv.N6510.Timeout, ID_GetSMSC);
+}
+
+static GSM_Error N6510_ReplySetSMSC(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[4]) {
+ case 0x00:
+ smprintf(s, "SMSC set OK\n");
+ return ERR_NONE;
+ case 0x02:
+ smprintf(s, "Invalid SMSC location\n");
+ return ERR_INVALIDLOCATION;
+ default:
+ smprintf(s, "Unknown SMSC state: %02x\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+}
+
+static GSM_Error N6510_SetSMSC(GSM_StateMachine *s, GSM_SMSC *smsc)
+{
+ int count = 13,i;
+ unsigned char req[256] = {N6110_FRAME_HEADER,
+ 0x12, 0x55, 0x01, 0x0B, 0x34,
+ 0x05, /* Location */
+ 0x00,
+ 0x00, /* Format */
+ 0x00,
+ 0xFF}; /* Validity */
+
+ req[8] = smsc->Location;
+ switch (smsc->Format) {
+ case SMS_FORMAT_Text: req[10] = 0x00; break;
+ case SMS_FORMAT_Fax: req[10] = 0x22; break;
+ case SMS_FORMAT_Pager: req[10] = 0x26; break;
+ case SMS_FORMAT_Email: req[10] = 0x32; break;
+ }
+ req[12] = smsc->Validity.Relative;
+
+ /* We have now blocks. Number of blocks = 3 */
+ req[count++] = 0x03;
+
+ /* -------------- SMSC number ----------------- */
+ /* Block type: number */
+ req[count++] = 0x82;
+ /* Offset to next block */
+ req[count++] = 0x1A;
+ /* Type of number: SMSC number */
+ req[count++] = 0x02;
+ req[count] = GSM_PackSemiOctetNumber(smsc->Number, req+count+2, FALSE) + 1;
+ if (req[count]>18) {
+ smprintf(s, "Too long SMSC number in frame\n");
+ return ERR_UNKNOWN;
+ }
+ req[count+1] = req[count] - 1;
+ count += 23;
+
+ /* --------------- Default number ------------- */
+ /* Block type: number */
+ req[count++] = 0x82;
+ /* Offset to next block */
+ req[count++] = 0x14;
+ /* Type of number: default number */
+ req[count++] = 0x01;
+ req[count] = GSM_PackSemiOctetNumber(smsc->DefaultNumber, req+count+2, TRUE) + 1;
+ if (req[count]*2>12) {
+ smprintf(s, "Too long SMSC number in frame\n");
+ return ERR_UNKNOWN;
+ }
+ req[count+1] = req[count] - 1;
+ count += 17;
+
+ /* -------------- SMSC name ------------------- */
+ req[count++] = 0x81;
+ req[count++] = UnicodeLength(smsc->Name)*2 + 2 + 4;
+ req[count++] = UnicodeLength(smsc->Name)*2 + 2;
+ req[count++] = 0x00;
+ /* Can't make CopyUnicodeString(req+count,sms->Name) !!!!
+ * with MSVC6 count is changed then
+ */
+ i = count;
+ CopyUnicodeString(req+i,smsc->Name);
+ count += UnicodeLength(smsc->Name)*2 + 2;
+
+ smprintf(s, "Setting SMSC\n");
+ return GSM_WaitFor (s, req, count, 0x02, s->Phone.Data.Priv.N6510.Timeout, ID_SetSMSC);
+}
+
+static GSM_Error N6510_ReplyGetNetworkInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int current = msg->Buffer[7]+7, pos;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+ GSM_NetworkInfo network_info_local, *network_info;
+
+ if (msg->Buffer[3] == 0xf0) {
+ return ERR_NOTSUPPORTED;
+ }
+
+ if (Data->RequestID == ID_GetNetworkInfo) {
+ network_info = Data->NetworkInfo;
+ } else {
+ network_info = &network_info_local;
+ }
+
+ network_info->NetworkName[0] = 0x00;
+ network_info->NetworkName[1] = 0x00;
+
+ switch (msg->Buffer[8]) {
+ case 0x00:
+ smprintf(s, "home network\n");
+ network_info->State = GSM_HomeNetwork;
+ break;
+ case 0x01:
+ smprintf(s, "roaming network\n");
+ network_info->State = GSM_RoamingNetwork;
+ break;
+ case 0x04:
+ smprintf(s, "not logged");
+ network_info->State = GSM_NoNetwork;
+ break;
+ case 0x06:
+ smprintf(s, "SIM card rejected\n");
+ network_info->State = GSM_RegistrationDenied;
+ break;
+ case 0x09:
+ smprintf(s, "not logged");
+ network_info->State = GSM_NoNetwork;
+ break;
+ default:
+ smprintf(s, "unknown %i!\n",msg->Buffer[8]);
+ network_info->State = GSM_NetworkStatusUnknown;
+ }
+ if (network_info->State == GSM_HomeNetwork || network_info->State == GSM_RoamingNetwork) {
+ pos = 10;
+ NOKIA_GetUnicodeString(s, &pos, msg->Buffer, network_info->NetworkName, TRUE);
+ smprintf(s, "Network name: %s ", DecodeUnicodeString(network_info->NetworkName));
+ NOKIA_DecodeNetworkCode(msg->Buffer + (current + 7), network_info->NetworkCode);
+ smprintf(s, "Network code: %s\n", network_info->NetworkCode);
+ smprintf(s, "Network name in libGammu: %s ", DecodeUnicodeString(GSM_GetNetworkName(network_info->NetworkCode)));
+ sprintf(network_info->LAC, "%02X%02X", msg->Buffer[current+1], msg->Buffer[current+2]);
+ smprintf(s, "LAC: %s\n", network_info->LAC);
+ sprintf(network_info->CID, "%02X%02X", msg->Buffer[current+5], msg->Buffer[current+6]);
+ smprintf(s, "CID: %s\n", network_info->CID);
+ }
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_GetNetworkInfo(GSM_StateMachine *s, GSM_NetworkInfo *netinfo)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x00, 0x00};
+
+ netinfo->GPRS = 0;
+ s->Phone.Data.NetworkInfo=netinfo;
+ smprintf(s, "Getting network info\n");
+ return GSM_WaitFor (s, req, 5, 0x0a, s->Phone.Data.Priv.N6510.Timeout, ID_GetNetworkInfo);
+}
+
+static GSM_Error N6510_EncodeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char *req, GSM_SMSMessageLayout *Layout, int *length)
+{
+ int count = 0, pos1, pos2, pos3, pos4, pos5;
+ GSM_Error error;
+
+ memset(Layout,255,sizeof(GSM_SMSMessageLayout));
+
+ req[count++] = 0x01;
+ if (sms->PDU != SMS_Deliver) {
+ req[count++] = 0x02;
+ } else {
+ req[count++] = 0x00;
+ }
+
+ pos1 = count; count++;
+ /* firstbyte set in SMS Layout */
+ Layout->firstbyte = count; count++;
+ if (sms->PDU != SMS_Deliver) {
+ Layout->TPMR = count; count++;
+
+ Layout->TPPID = count; count++;
+
+ /* TP.DCS set in SMS layout */
+ Layout->TPDCS = count; count++;
+ req[count++] = 0x00;
+ } else {
+ Layout->TPPID = count; count++;
+ /* TP.DCS set in SMS layout */
+ Layout->TPDCS = count; count++;
+ Layout->DateTime = count; count += 7;
+ req[count++] = 0x55;
+ req[count++] = 0x55;
+ req[count++] = 0x55;
+ }
+
+ /* We have now blocks. Number of blocks = 3 or 4 */
+ if (sms->PDU != SMS_Deliver) {
+ req[count++] = 0x04;
+ } else {
+ req[count++] = 0x03;
+ }
+
+ /* -------------- Phone number ------------- */
+ /* Block type: number */
+ req[count++] = 0x82;
+ /* Offset to next block */
+ req[count++] = 0x10;
+ /* Type of number: default number */
+ req[count++] = 0x01;
+ pos4 = count; count++;
+ /* now coded Number in SMS Layout */
+ Layout->Number = count; count+= 12;
+
+ /* -------------- SMSC number -------------- */
+ /* Block type: number */
+ req[count++] = 0x82;
+ /* Offset to next block */
+ req[count++] = 0x10;
+ /* Type of number: SMSC number */
+ req[count++] = 0x02;
+ pos5 = count; count++;
+ /* now coded SMSC number in SMS Layout */
+ Layout->SMSCNumber = count; count += 12;
+
+ /* -------------- SMS validity ------------- */
+ if (sms->PDU != SMS_Deliver) {
+ /* Block type: validity */
+ req[count++] = 0x08;
+ req[count++] = 0x04;
+ /* data length */
+ req[count++] = 0x01;
+ Layout->TPVP = count; count++;
+ }
+
+ /* --------------- SMS text ---------------- */
+ /* Block type: SMS text */
+ req[count++] = 0x80;
+ /* this the same as req[11] but starting from req[42] */
+ pos2 = count; count++;
+ pos3 = count; count++;
+ /* FIXME*/
+ Layout->TPUDL = count; count++;
+ /* SMS text and UDH coded in SMS Layout */
+ Layout->Text = count;
+
+ error = PHONE_EncodeSMSFrame(s,sms,req,*Layout,length,FALSE);
+ if (error != ERR_NONE) return error;
+
+ req[pos1] = *length - 1;
+ req[pos2] = *length - Layout->Text + 6;
+ req[pos3] = *length - Layout->Text;
+
+ /* Convert number of semioctets to number of chars */
+ req[pos4] = req[Layout->Number] + 4;
+ if (req[pos4] % 2) req[pos4]++;
+ req[pos4] /= 2;
+
+ req[pos5] = req[Layout->SMSCNumber] + 1;
+
+ if (req[pos4]>12 || req[pos5]>12) {
+ smprintf(s, "Too long phone number in frame\n");
+ return ERR_UNKNOWN;
+ }
+
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_ReplyGetSMSFolders(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int j, num = 0;
+ size_t pos;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ switch (msg->Buffer[3]) {
+ case 0x13:
+ smprintf(s, "SMS folders names received\n");
+ Data->SMSFolders->Number = msg->Buffer[5]+2;
+ pos = 6;
+ for (j=0;j<msg->Buffer[5];j++) {
+ while (TRUE) {
+ if (msg->Buffer[pos] == msg->Buffer[6] &&
+ msg->Buffer[pos+1] == msg->Buffer[7]) break;
+ if (pos+4 > msg->Length) return ERR_UNKNOWNRESPONSE;
+ pos++;
+ }
+ pos+=4;
+ smprintf(s, "Folder index: %02x",msg->Buffer[pos - 2]);
+ if (msg->Buffer[pos - 1]>GSM_MAX_SMS_FOLDER_NAME_LEN) {
+ smprintf(s, "Too long text\n");
+ return ERR_UNKNOWNRESPONSE;
+ }
+ CopyUnicodeString(Data->SMSFolders->Folder[num].Name,msg->Buffer + pos);
+ smprintf(s, ", folder name: \"%s\"\n",DecodeUnicodeString(Data->SMSFolders->Folder[num].Name));
+ Data->SMSFolders->Folder[num].InboxFolder = FALSE;
+ Data->SMSFolders->Folder[num].Memory = MEM_ME;
+ if (num == 0x01) { /* OUTBOX SIM */
+ Data->SMSFolders->Folder[0].Memory = MEM_SM;
+ Data->SMSFolders->Folder[0].InboxFolder = TRUE;
+ Data->SMSFolders->Folder[0].OutboxFolder = FALSE;
+
+ Data->SMSFolders->Folder[1].Memory = MEM_SM;
+ Data->SMSFolders->Folder[1].InboxFolder = FALSE;
+ Data->SMSFolders->Folder[1].OutboxFolder = TRUE;
+
+ CopyUnicodeString(Data->SMSFolders->Folder[2].Name,Data->SMSFolders->Folder[0].Name);
+ Data->SMSFolders->Folder[2].Memory = MEM_ME;
+ Data->SMSFolders->Folder[2].InboxFolder = TRUE;
+ Data->SMSFolders->Folder[2].OutboxFolder = FALSE;
+
+ CopyUnicodeString(Data->SMSFolders->Folder[3].Name,Data->SMSFolders->Folder[1].Name);
+ Data->SMSFolders->Folder[3].Memory = MEM_ME;
+ Data->SMSFolders->Folder[3].InboxFolder = FALSE;
+ Data->SMSFolders->Folder[3].OutboxFolder = TRUE;
+
+ num+=2;
+ }
+ num++;
+ }
+ return ERR_NONE;
+ case 0xf0:
+ smprintf(s, "HINT: Maybe phone needs F_SMS_FILES?\n");
+ break;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+GSM_Error N6510_GetSMSFoldersS40_30(GSM_StateMachine *s UNUSED, GSM_SMSFolders *folders)
+{
+ folders->Number=4;
+ EncodeUnicode(folders->Folder[0].Name,_("SIM"),strlen(_("SIM")));
+ EncodeUnicode(folders->Folder[1].Name,_("Inbox"),strlen(_("Inbox")));
+ EncodeUnicode(folders->Folder[2].Name,_("Sent items"),strlen(_("Sent items")));
+ EncodeUnicode(folders->Folder[3].Name,_("Saved items"),strlen(_("Saved items")));
+ folders->Folder[0].InboxFolder = TRUE;
+ folders->Folder[1].InboxFolder = TRUE;
+ folders->Folder[2].InboxFolder = FALSE;
+ folders->Folder[3].InboxFolder = FALSE;
+ folders->Folder[0].OutboxFolder = TRUE;
+ folders->Folder[1].OutboxFolder = FALSE;
+ folders->Folder[2].OutboxFolder = TRUE;
+ folders->Folder[3].OutboxFolder = FALSE;
+ folders->Folder[0].Memory = MEM_SM;
+ folders->Folder[1].Memory = MEM_ME;
+ folders->Folder[2].Memory = MEM_ME;
+ folders->Folder[3].Memory = MEM_ME;
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_GetSMSFolders(GSM_StateMachine *s, GSM_SMSFolders *folders)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x12, 0x00, 0x00};
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SMS_FILES)) return N6510_GetFilesystemSMSFolders(s,folders);
+ return N6510_GetSMSFoldersS40_30(s,folders);
+ }
+
+ s->Phone.Data.SMSFolders=folders;
+ smprintf(s, "Getting SMS folders\n");
+ return GSM_WaitFor (s, req, 6, 0x14, s->Phone.Data.Priv.N6510.Timeout, ID_GetSMSFolders);
+}
+
+static GSM_Error N6510_ReplyGetSMSFolderStatus(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int i;
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+
+ smprintf(s, "SMS folder status received\n");
+ Priv->LastSMSFolder.Number=msg->Buffer[6]*256+msg->Buffer[7];
+ smprintf(s, "Number of Entries: %i\n",Priv->LastSMSFolder.Number);
+ smprintf(s, "Locations: ");
+ for (i=0;i<Priv->LastSMSFolder.Number;i++) {
+ Priv->LastSMSFolder.Location[i]=msg->Buffer[8+(i*2)]*256+msg->Buffer[(i*2)+9];
+ smprintf(s, "%i ",Priv->LastSMSFolder.Location[i]);
+ }
+ smprintf(s, "\n");
+ NOKIA_SortSMSFolderStatus(s, &Priv->LastSMSFolder);
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_GetSMSFolderStatus(GSM_StateMachine *s, int folderid)
+{
+ unsigned char req[] = {N7110_FRAME_HEADER, 0x0C,
+ 0x01, /* 0x01=SIM, 0x02=ME */
+ 0x00, /* Folder ID */
+ 0x0f, 0x55, 0x55, 0x55};
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ switch (folderid) {
+ case 0x01: req[5] = 0x01; break; /* SIM */
+ default : req[5] = folderid; req[4] = 0x02; break; /* ME folders */
+ }
+ } else {
+ switch (folderid) {
+ case 0x01: req[5] = 0x02; break; /* INBOX SIM */
+ case 0x02: req[5] = 0x03; break; /* OUTBOX SIM */
+ default : req[5] = folderid - 1; req[4] = 0x02; break; /* ME folders */
+ }
+ }
+
+ smprintf(s, "Getting SMS folder status\n");
+ return GSM_WaitFor (s, req, 10, 0x14, s->Phone.Data.Priv.N6510.Timeout, ID_GetSMSFolderStatus);
+}
+
+static void N6510_GetSMSLocation(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char *folderid, unsigned int *location)
+{
+ int ifolderid;
+
+ /* simulate flat SMS memory */
+ if (sms->Folder==0x00) {
+ ifolderid = sms->Location / GSM_PHONE_MAXSMSINFOLDER;
+ *folderid = ifolderid + 0x01;
+ *location = sms->Location - ifolderid * GSM_PHONE_MAXSMSINFOLDER;
+ if (*folderid == 0x1B) (*folderid)=0x99; /* 0x1A is Outbox in 6230i */
+ } else {
+ *folderid = sms->Folder;
+ *location = sms->Location;
+ if (*folderid == 0x1A) (*folderid)=0x99; /* 0x1A is Outbox in 6230i */
+ }
+ smprintf(s, "SMS folder %i & location %i -> 6510 folder %i & location %i\n",
+ sms->Folder,sms->Location,*folderid,*location);
+}
+
+static void N6510_SetSMSLocation(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char folderid, int location)
+{
+ sms->Folder = 0;
+ sms->Location = (folderid - 0x01) * GSM_PHONE_MAXSMSINFOLDER + location;
+ smprintf(s, "6510 folder %i & location %i -> SMS folder %i & location %i\n",
+ folderid,location,sms->Folder,sms->Location);
+}
+
+static GSM_Error N6510_DecodeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *sms, unsigned char *buffer, size_t *current2)
+{
+ int i, current, blocks=0, SMSTemplateDateTime = 0;
+ GSM_SMSMessageLayout Layout;
+ GSM_Error error;
+
+ memset(&Layout,255,sizeof(GSM_SMSMessageLayout));
+ Layout.firstbyte = 2;
+ switch (buffer[0]) {
+ case 0x00:
+ smprintf(s, "SMS deliver\n");
+ sms->PDU = SMS_Deliver;
+ Layout.TPPID = 3;
+ Layout.TPDCS = 4;
+ Layout.DateTime = 5;
+ blocks = 15;
+ break;
+ case 0x01:
+ smprintf(s, "Delivery report\n");
+ sms->PDU = SMS_Status_Report;
+ Layout.TPMR = 3;
+ Layout.TPStatus = 4;
+ Layout.DateTime = 5;
+ Layout.SMSCTime = 12;
+ blocks = 19;
+ break;
+ case 0x02:
+ smprintf(s, "SMS template\n");
+ sms->PDU = SMS_Submit;
+ Layout.TPMR = 3;
+ Layout.TPPID = 4;
+ Layout.TPDCS = 5;
+ blocks = 7;
+ break;
+ }
+ current = blocks + 1;
+ for (i=0;i<buffer[blocks];i++) {
+ switch (buffer[current]) {
+ case 0x08:
+ smprintf(s, "SMSC timestamp (ignored)\n");
+ break;
+ case 0x80:
+ smprintf(s, "SMS text\n");
+ if (buffer[current + 2] > buffer[current + 3]) {
+ Layout.TPUDL = current + 2;
+ } else {
+ Layout.TPUDL = current + 3;
+ }
+ Layout.Text = current + 4;
+ break;
+ case 0x82:
+ switch (buffer[current+2]) {
+ case 0x01:
+ smprintf(s, "Phone number\n");
+ Layout.Number = current + 4;
+ break;
+ case 0x02:
+ smprintf(s, "SMSC number\n");
+ Layout.SMSCNumber = current + 4;
+ break;
+ default:
+ smprintf(s, "Unknown number\n");
+ break;
+ }
+ break;
+ case 0x84:
+ smprintf(s, "Date and time of saving for SMS template\n");
+ SMSTemplateDateTime = current + 2;
+ break;
+ default:
+ smprintf(s, "Unknown block %02x\n",buffer[current]);
+ }
+ current = current + buffer[current + 1];
+ }
+ error = GSM_DecodeSMSFrame(&(s->di), sms,buffer,Layout);
+ if (SMSTemplateDateTime != 0) {
+ sms->PDU = SMS_Deliver;
+ NOKIA_DecodeDateTime(s, buffer+SMSTemplateDateTime, &sms->DateTime, TRUE, FALSE);
+ }
+ (*current2) = current;
+ return error;
+}
+
+GSM_Error N6510_ReplyGetSMSMessage(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ size_t i,j;
+ size_t Width, Height;
+ unsigned char output[500]; /* output2[500]; */
+ GSM_Phone_Data *Data = &s->Phone.Data;
+ GSM_Error error;
+
+ switch(msg->Buffer[3]) {
+ case 0x03:
+ smprintf(s, "SMS Message received\n");
+ GSM_SetDefaultReceivedSMSData(Data->GetSMSMessage->SMS);
+ Data->GetSMSMessage->Number=1;
+ NOKIA_DecodeSMSState(s, msg->Buffer[5], &(Data->GetSMSMessage->SMS[0]));
+ if (msg->Length < 15) {
+ smprintf(s, "No message data!\n");
+ Data->GetSMSMessage->SMS[0].PDU = SMS_Deliver;
+ return ERR_NONE;
+ }
+ switch (msg->Buffer[14]) {
+ case 0x00:
+ case 0x01:
+ case 0x02:
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ Data->GetSMSMessage->Number=0;
+ i = 14;
+ while (TRUE) {
+ error = N6510_DecodeSMSFrame(s, &Data->GetSMSMessage->SMS[Data->GetSMSMessage->Number],msg->Buffer+i,&j);
+ if (error != ERR_NONE) return error;
+ NOKIA_DecodeSMSState(s, msg->Buffer[5], &Data->GetSMSMessage->SMS[Data->GetSMSMessage->Number]);
+ i+=j;
+ Data->GetSMSMessage->Number++;
+ if (i>=msg->Length) break;
+ }
+ return error;
+ } else {
+ return N6510_DecodeSMSFrame(s, &Data->GetSMSMessage->SMS[0],msg->Buffer+14,&j);
+ }
+ case 0xA0:
+ smprintf(s, "Picture Image\n");
+ Data->GetSMSMessage->Number = 0;
+ i = 0;
+ output[i++] = 0x30; /* Smart Messaging 3.0 */
+ output[i++] = SM30_OTA;
+ output[i++] = 0x01; /* Length */
+ output[i++] = 0x00; /* Length */
+ output[i++] = 0x00;
+ PHONE_GetBitmapWidthHeight(GSM_NokiaPictureImage, &Width, &Height);
+ output[i++] = Width;
+ output[i++] = Height;
+ output[i++] = 0x01;
+ memcpy(output+i,msg->Buffer+30,PHONE_GetBitmapSize(GSM_NokiaPictureImage,0,0));
+ i = i + PHONE_GetBitmapSize(GSM_NokiaPictureImage,0,0);
+#if 0
+ if (msg->Length!=282) {
+ output[i++] = SM30_UNICODETEXT;
+ output[i++] = 0;
+ output[i++] = 0; /* Length - later changed */
+ GSM_UnpackEightBitsToSeven(0, msg->Length-282, msg->Length-304, msg->Buffer+282,output2);
+ DecodeDefault(output+i, output2, msg->Length - 282, TRUE, NULL);
+ output[i - 1] = UnicodeLength(output+i) * 2;
+ i = i + output[i-1];
+ }
+#endif
+ GSM_MakeMultiPartSMS(&(s->di), Data->GetSMSMessage,output,i,UDH_NokiaProfileLong,SMS_Coding_8bit,1,0);
+ for (i=0;i<3;i++) {
+ Data->GetSMSMessage->SMS[i].Number[0]=0;
+ Data->GetSMSMessage->SMS[i].Number[1]=0;
+ }
+ if (Data->Bitmap != NULL) {
+ Data->Bitmap->Location = 0;
+ PHONE_GetBitmapWidthHeight(GSM_NokiaPictureImage, &Width, &Height);
+ Data->Bitmap->BitmapWidth = Width;
+ Data->Bitmap->BitmapHeight = Height;
+ PHONE_DecodeBitmap(GSM_NokiaPictureImage, msg->Buffer + 30, Data->Bitmap);
+ Data->Bitmap->Sender[0] = 0x00;
+ Data->Bitmap->Sender[1] = 0x00;
+ Data->Bitmap->Text[0] = 0;
+ Data->Bitmap->Text[1] = 0;
+ }
+ return ERR_NONE;
+ default:
+ smprintf(s, "Unknown SMS type: %i\n",msg->Buffer[8]);
+ }
+ break;
+ case 0x0f:
+ smprintf(s, "SMS message info received\n");
+ CopyUnicodeString(Data->GetSMSMessage->SMS[0].Name,msg->Buffer+52);
+ smprintf(s, "Name: \"%s\"\n",DecodeUnicodeString(Data->GetSMSMessage->SMS[0].Name));
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_PrivGetSMSMessageBitmap(GSM_StateMachine *s, GSM_MultiSMSMessage *sms, GSM_Bitmap *bitmap)
+{
+ GSM_Error error;
+ unsigned char folderid,namebuffer[200];
+ unsigned int location;
+ int i;
+ unsigned char req[] = {
+ N6110_FRAME_HEADER,
+ 0x02, /* msg type: 0x02 for getting sms, 0x0e for sms status */
+ 0x01, /* 0x01=SIM, 0x02=ME */
+ 0x00, /* FolderID */
+ 0x00, 0x02, /* Location */
+ 0x01, 0x00};
+
+ N6510_GetSMSLocation(s, &sms->SMS[0], &folderid, &location);
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ switch (folderid) {
+ case 0x01: req[5] = 0x01; break; /* SIM */
+ default : req[5] = folderid; req[4] = 0x02; break; /* ME folders */
+ }
+ } else {
+ switch (folderid) {
+ case 0x01: req[5] = 0x02; break; /* INBOX SIM */
+ case 0x02: req[5] = 0x03; break; /* OUTBOX SIM */
+ default : req[5] = folderid - 1; req[4] = 0x02; break; /* ME folders */
+ }
+ }
+
+ req[6]=location / 256;
+ req[7]=location % 256;
+
+ s->Phone.Data.GetSMSMessage = sms;
+ s->Phone.Data.Bitmap = bitmap;
+ smprintf(s, "Getting sms message info\n");
+ req[3] = 0x0e; req[8] = 0x55; req[9] = 0x55;
+ error=GSM_WaitFor (s, req, 10, 0x14, s->Phone.Data.Priv.N6510.Timeout, ID_GetSMSMessage);
+ if (error!=ERR_NONE) return error;
+ CopyUnicodeString(namebuffer,sms->SMS[0].Name);
+
+ smprintf(s, "Getting sms\n");
+ req[3] = 0x02; req[8] = 0x01; req[9] = 0x00;
+ error = GSM_WaitFor (s, req, 10, 0x14, s->Phone.Data.Priv.N6510.Timeout, ID_GetSMSMessage);
+ if (error == ERR_NONE) {
+ if (sms->Number == 0) {
+ return ERR_EMPTY;
+ }
+ for (i=0;i<sms->Number;i++) {
+ N6510_SetSMSLocation(s, &sms->SMS[i], folderid, location);
+ sms->SMS[i].Folder = folderid;
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ sms->SMS[i].InboxFolder = TRUE;
+ if (folderid > 2) sms->SMS[i].InboxFolder = FALSE;
+ sms->SMS[i].Memory = MEM_ME;
+ if (folderid == 0x01) sms->SMS[i].Memory = MEM_SM;
+ } else {
+ sms->SMS[i].InboxFolder = TRUE;
+ if (folderid != 0x01 && folderid != 0x03) sms->SMS[i].InboxFolder = FALSE;
+ sms->SMS[i].Memory = MEM_ME;
+ if (folderid == 0x01 || folderid == 0x02) sms->SMS[i].Memory = MEM_SM;
+ }
+
+ CopyUnicodeString(sms->SMS[i].Name,namebuffer);
+ }
+ }
+ return error;
+}
+
+static GSM_Error N6510_GetSMSMessage(GSM_StateMachine *s, GSM_MultiSMSMessage *sms)
+{
+ GSM_Error error;
+ unsigned char folderid;
+ unsigned int location;
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ int i;
+ gboolean found = FALSE;
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SMS_FILES)) return ERR_NOTSUPPORTED;
+ }
+
+ /* Clear SMS structure of any possible junk */
+ GSM_SetDefaultReceivedSMSData(&(sms->SMS[0]));
+
+ N6510_GetSMSLocation(s, &(sms->SMS[0]), &folderid, &location);
+ error=N6510_GetSMSFolderStatus(s, folderid);
+ if (error!=ERR_NONE) return error;
+ for (i=0;i<Priv->LastSMSFolder.Number;i++) {
+ if (Priv->LastSMSFolder.Location[i]==location) {
+ found = TRUE;
+ break;
+ }
+ }
+ if (!found) return ERR_EMPTY;
+ return N6510_PrivGetSMSMessageBitmap(s,sms,NULL);
+}
+
+static GSM_Error N6510_GetNextSMSMessageBitmap(GSM_StateMachine *s, GSM_MultiSMSMessage *sms, gboolean start, GSM_Bitmap *bitmap)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ unsigned char folderid;
+ unsigned int location;
+ GSM_Error error;
+ int i;
+ gboolean findnextfolder = FALSE;
+
+ if (start) {
+ folderid = 0x00;
+ findnextfolder = TRUE;
+ error=N6510_GetSMSFolders(s,&Priv->LastSMSFolders);
+ if (error!=ERR_NONE) return error;
+ } else {
+ N6510_GetSMSLocation(s, &(sms->SMS[0]), &folderid, &location);
+ for (i=0;i<Priv->LastSMSFolder.Number;i++) {
+ if (Priv->LastSMSFolder.Location[i]==location) break;
+ }
+ /* Is this last location in this folder ? */
+ if (i==Priv->LastSMSFolder.Number-1) {
+ findnextfolder=TRUE;
+ } else {
+ location=Priv->LastSMSFolder.Location[i+1];
+ }
+ }
+ if (findnextfolder) {
+ Priv->LastSMSFolder.Number=0;
+ while (Priv->LastSMSFolder.Number==0) {
+ folderid++;
+ /* Too high folder number */
+ if ((folderid-1)>=Priv->LastSMSFolders.Number) return ERR_EMPTY;
+ /* Get next folder status */
+ error=N6510_GetSMSFolderStatus(s, folderid);
+ if (error!=ERR_NONE) return error;
+ /* First location from this folder */
+ location=Priv->LastSMSFolder.Location[0];
+ }
+ }
+ N6510_SetSMSLocation(s, &sms->SMS[0], folderid, location);
+
+ return N6510_PrivGetSMSMessageBitmap(s, sms, bitmap);
+}
+
+static GSM_Error N6510_GetNextSMSMessage(GSM_StateMachine *s, GSM_MultiSMSMessage *sms, gboolean start)
+{
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30) &&
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SMS_FILES)) {
+ return N6510_GetNextFilesystemSMS(s,sms,start);
+ }
+
+ return N6510_GetNextSMSMessageBitmap(s, sms, start, NULL);
+}
+
+static GSM_Error N6510_ReplyStartupNoteLogo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ if (Data->RequestID == ID_GetBitmap) {
+ switch (msg->Buffer[4]) {
+ case 0x01:
+ smprintf(s, "Welcome note text received\n");
+ CopyUnicodeString(Data->Bitmap->Text,msg->Buffer+6);
+ smprintf(s, "Text is \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Text));
+ return ERR_NONE;
+ case 0x10:
+ smprintf(s, "Dealer note text received\n");
+ CopyUnicodeString(Data->Bitmap->Text,msg->Buffer+6);
+ smprintf(s, "Text is \"%s\"\n",DecodeUnicodeString(Data->Bitmap->Text));
+ return ERR_NONE;
+ case 0x0f:
+ smprintf(s, "Startup logo received\n");
+ PHONE_DecodeBitmap(GSM_Nokia7110StartupLogo, msg->Buffer + 22, Data->Bitmap);
+ return ERR_NONE;
+ }
+ }
+ if (Data->RequestID == ID_SetBitmap) {
+ switch (msg->Buffer[4]) {
+ case 0x01:
+ case 0x10:
+ case 0x0f:
+ case 0x25:
+ return ERR_NONE;
+ }
+ }
+ return ERR_UNKNOWN;
+}
+
+static GSM_Error N6510_GetPictureImage(GSM_StateMachine *s, GSM_Bitmap *Bitmap, int *location)
+{
+ GSM_MultiSMSMessage sms;
+ int Number;
+ GSM_Bitmap bitmap;
+ GSM_Error error;
+
+ sms.SMS[0].Folder = 0;
+ Number = 0;
+ bitmap.Location = 255;
+ error=N6510_GetNextSMSMessageBitmap(s, &sms, TRUE, &bitmap);
+ while (error == ERR_NONE) {
+ if (bitmap.Location != 255) {
+ Number++;
+ if (Number == Bitmap->Location) {
+ bitmap.Location = Bitmap->Location;
+ memcpy(Bitmap,&bitmap,sizeof(GSM_Bitmap));
+ *location = sms.SMS[0].Location;
+ return ERR_NONE;
+ }
+ }
+ bitmap.Location = 255;
+ sms.SMS[0].Folder = 0;
+ error=N6510_GetNextSMSMessageBitmap(s, &sms, FALSE, &bitmap);
+ }
+ return ERR_INVALIDLOCATION;
+}
+
+static GSM_Error N6510_GetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
+{
+ unsigned char reqOp [] = {N6110_FRAME_HEADER, 0x23, 0x00, 0x00, 0x55, 0x55, 0x55};
+ unsigned char reqStartup[] = {N6110_FRAME_HEADER, 0x02, 0x0f};
+ unsigned char reqNote [] = {N6110_FRAME_HEADER, 0x02, 0x01, 0x00};
+ GSM_MemoryEntry pbk;
+ GSM_Error error;
+ int Location;
+
+ s->Phone.Data.Bitmap=Bitmap;
+ switch (Bitmap->Type) {
+ case GSM_StartupLogo:
+ Bitmap->BitmapWidth = 96;
+ Bitmap->BitmapHeight = 65;
+ GSM_ClearBitmap(Bitmap);
+ smprintf(s, "Getting startup logo\n");
+ return GSM_WaitFor (s, reqStartup, 5, 0x7A, s->Phone.Data.Priv.N6510.Timeout, ID_GetBitmap);
+ case GSM_DealerNote_Text:
+ reqNote[4] = 0x10;
+ smprintf(s, "Getting dealer note\n");
+ return GSM_WaitFor (s, reqNote, 6, 0x7A, s->Phone.Data.Priv.N6510.Timeout, ID_GetBitmap);
+ case GSM_WelcomeNote_Text:
+ smprintf(s, "Getting welcome note\n");
+ return GSM_WaitFor (s, reqNote, 6, 0x7A, s->Phone.Data.Priv.N6510.Timeout, ID_GetBitmap);
+ case GSM_CallerGroupLogo:
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PBK35)) return ERR_NOTSUPPORTED;
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_6230iCALLER)) {
+ pbk.MemoryType = (GSM_MemoryType)MEM6510_CG2;
+ pbk.Location = Bitmap->Location;
+ smprintf(s, "Getting caller group logo method 2\n");
+ return N6510_GetMemory(s,&pbk);
+ }
+ Bitmap->BitmapWidth = 72;
+ Bitmap->BitmapHeight = 14;
+ GSM_ClearBitmap(Bitmap);
+ pbk.MemoryType = (GSM_MemoryType)MEM7110_CG;
+ pbk.Location = Bitmap->Location;
+ smprintf(s, "Getting caller group logo\n");
+ error=N6510_GetMemory(s,&pbk);
+ if (error==ERR_NONE) NOKIA_GetDefaultCallerGroupName(Bitmap);
+ return error;
+ case GSM_OperatorLogo:
+ smprintf(s, "Getting operator logo\n");
+ return GSM_WaitFor (s, reqOp, 9, 0x0A, s->Phone.Data.Priv.N6510.Timeout, ID_GetBitmap);
+ case GSM_PictureImage:
+ return N6510_GetPictureImage(s, Bitmap, &Location);
+ default:
+ break;
+ }
+ return ERR_NOTSUPPORTED;
+}
+
+static GSM_Error N6510_ReplyGetIncSignalQuality(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "Network level changed to: %i\n",msg->Buffer[4]);
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_ReplyGetSignalQuality(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "Network level received: %i\n",msg->Buffer[8]);
+ Data->SignalQuality->SignalStrength = -1;
+ Data->SignalQuality->SignalPercent = ((int)msg->Buffer[8]);
+ Data->SignalQuality->BitErrorRate = -1;
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_GetSignalQuality(GSM_StateMachine *s, GSM_SignalQuality *sig)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x0B, 0x00, 0x02, 0x00, 0x00, 0x00};
+
+ s->Phone.Data.SignalQuality = sig;
+ smprintf(s, "Getting network level\n");
+ return GSM_WaitFor (s, req, 9, 0x0a, s->Phone.Data.Priv.N6510.Timeout * 3, ID_GetSignalQuality);
+}
+
+static GSM_Error N6510_IncomingBatteryCharge(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "Incoming battery level received???: %i\n",
+ msg->Buffer[9]*100/7);
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_ReplyGetBatteryCharge(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ Data->BatteryCharge->BatteryPercent = ((int)(msg->Buffer[9]*100/msg->Buffer[8]));
+ Data->BatteryCharge->ChargeState = 0;
+
+ smprintf(s, "Battery level received: %i\n",
+ Data->BatteryCharge->BatteryPercent);
+
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_GetBatteryCharge(GSM_StateMachine *s, GSM_BatteryCharge *bat)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x0A, 0x02, 0x00};
+
+ GSM_ClearBatteryCharge(bat);
+ s->Phone.Data.BatteryCharge = bat;
+ smprintf(s, "Getting battery level\n");
+ return GSM_WaitFor (s, req, 6, 0x17, s->Phone.Data.Priv.N6510.Timeout, ID_GetBatteryCharge);
+}
+
+static GSM_Error N6510_ReplyGetWAPBookmark(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ return DCT3DCT4_ReplyGetWAPBookmark (msg, s, TRUE);
+}
+
+static GSM_Error N6510_ReplyGetOperatorLogo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ if (msg->Buffer[3] == 0xf0) return ERR_NOTSUPPORTED;
+
+ smprintf(s, "Operator logo received\n");
+ if (msg->Length <= 18) {
+ smprintf(s, "Packet too short to contain operator logo\n");
+ return ERR_EMPTY;
+ }
+ NOKIA_DecodeNetworkCode(msg->Buffer+12,Data->Bitmap->NetworkCode);
+ smprintf(s, "Network code %s\n",Data->Bitmap->NetworkCode);
+ Data->Bitmap->BitmapWidth = msg->Buffer[20];
+ Data->Bitmap->BitmapHeight = msg->Buffer[21];
+ PHONE_DecodeBitmap(GSM_Nokia6510OperatorLogo,msg->Buffer+26,Data->Bitmap);
+ return ERR_NONE;
+}
+
+GSM_Error N6510_ReplyDeleteMemory(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ if (msg->Buffer[5] == 0x1) {
+ switch (msg->Buffer[6]) {
+ case 0x0f:
+ switch (msg->Buffer[10]) {
+ case 0x21:
+ smprintf(s, "Still busy processing the last command\n");
+ return ERR_BUSY;
+ case 0x3B:
+ smprintf(s, "Nothing to delete\n");
+ return ERR_NONE;
+ case 0x33:
+ smprintf(s, "Entry is read only\n");
+ return ERR_READ_ONLY;
+ default:
+ smprintf(s, "ERROR: unknown 0x%x\n", msg->Buffer[10]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ }
+ }
+ smprintf(s, "Phonebook entry deleted\n");
+ return ERR_NONE;
+}
+
+GSM_Error N6510_DeleteMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
+{
+ unsigned char req[] = {N7110_FRAME_HEADER, 0x0f, 0x55, 0x01,
+ 0x04, 0x55, 0x00, 0x10, 0xFF, 0x02,
+ 0x00, 0x01, /* location */
+ 0x00, 0x00, 0x00, 0x00,
+ 0x05, /* memory type */
+ 0x55, 0x55, 0x55};
+
+ req[12] = entry->Location / 256;
+ req[13] = entry->Location % 256;
+
+ req[18] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES);
+ if (req[18]==0xff) return ERR_NOTSUPPORTED;
+
+ smprintf(s, "Deleting phonebook entry\n");
+ return GSM_WaitFor (s, req, 22, 0x03, s->Phone.Data.Priv.N6510.Timeout, ID_SetMemory);
+}
+
+static GSM_Error N6510_SetMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
+{
+ int count = 22;
+ size_t blocks;
+ unsigned char req[5000] = {
+ N7110_FRAME_HEADER, 0x0b, 0x00, 0x01, 0x01, 0x00, 0x00, 0x10, 0x02,
+ 0x00, /* memory type */
+ 0x00, 0x00, /* location */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00}; /* Number of blocks */
+ GSM_Error error;
+ GSM_MemoryEntry tmp;
+ GSM_MemoryStatus status;
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+
+ if (entry->Location == 0) {
+ /*
+ * We want to remember last location so that we don't check the
+ * same place again and again.
+ */
+ if (Priv->LastFreeMemoryType != entry->MemoryType) {
+ Priv->LastFreeMemoryLocation = 0;
+ Priv->LastFreeMemoryType = entry->MemoryType;
+ status.MemoryType = entry->MemoryType;
+ error = N6510_GetMemoryStatus(s, &status);
+ if (error != ERR_NONE) return error;
+ Priv->LastFreeMemorySize = status.MemoryUsed + status.MemoryFree;
+ }
+
+ /* Advance beyond last used location */
+ tmp.MemoryType = entry->MemoryType;
+ error = ERR_NONE;
+ for (tmp.Location = Priv->LastFreeMemoryLocation + 1;
+ tmp.Location < Priv->LastFreeMemorySize;
+ tmp.Location++) {
+ error = N6510_GetMemory(s, &tmp);
+ if (error != ERR_NONE) break;
+ }
+ if (error == ERR_NONE) {
+ /* Memory full */
+ return ERR_FULL;
+ } else if (error != ERR_EMPTY) {
+ /* Other failure */
+ return error;
+ }
+ /* We've got the location */
+ entry->Location = tmp.Location;
+ smprintf(s, "Found empty location: %d\n", entry->Location);
+ }
+
+ req[11] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES);
+ if (req[11]==0xff) return ERR_NOTSUPPORTED;
+
+ req[12] = entry->Location / 256;
+ req[13] = entry->Location % 256;
+
+ count = count + N71_65_EncodePhonebookFrame(s, req+22, entry, &blocks, TRUE, GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_VOICETAGS));
+ req[21] = blocks;
+
+ smprintf(s, "Writing phonebook entry\n");
+ return GSM_WaitFor (s, req, count, 0x03, s->Phone.Data.Priv.N6510.Timeout, ID_SetMemory);
+}
+
+static GSM_Error N6510_AddMemory(GSM_StateMachine *s, GSM_MemoryEntry *entry)
+{
+ entry->Location = 0;
+ return N6510_SetMemory(s, entry);
+}
+
+static GSM_Error N6510_ReplySetOperatorLogo(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Operator logo set OK\n");
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_SetCallerLogo(GSM_StateMachine *s, GSM_Bitmap *bitmap)
+{
+ char string[500];
+ int block=0, i;
+ size_t Width, Height;
+ unsigned int count = 22;
+ unsigned char req[500] = {
+ N6110_FRAME_HEADER, 0x0b, 0x00, 0x01, 0x01, 0x00, 0x00, 0x10,
+ 0xfe, 0x00, /* memory type */
+ 0x00, 0x00, /* location */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+ /* Set memory type */
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_6230iCALLER)) {
+ req[11] = MEM6510_CG2;
+ } else {
+ req[11] = MEM7110_CG;
+ }
+
+ req[13] = bitmap->Location;
+
+ /* Enabling/disabling logo */
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_6230iCALLER)) {
+ string[0] = bitmap->BitmapEnabled?1:0;
+ string[1] = 0;
+ count += N71_65_PackPBKBlock(s, N7110_PBK_LOGOON, 2, block++, string, req + count);
+ }
+
+ /* Ringtone */
+ if (!bitmap->DefaultRingtone) {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_6230iCALLER)) {
+ string[0] = 0x00;
+ string[1] = 0x00;
+ string[2] = 0x00;
+ string[3] = 0x10;
+ string[4] = 0x00;
+ string[5] = 0x00;
+ string[6] = bitmap->RingtoneID;
+ string[7] = 0x00;
+ string[8] = 0x00;
+ string[9] = 0x00;
+ count += N71_65_PackPBKBlock(s, N6510_PBK_RINGTONEFILE_ID, 10, block++, string, req + count);
+ req[count - 1] = 0x01;
+ } else if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PBKTONEGAL)) {
+ /* do nothing ? */
+ } else {
+ string[0] = 0x00;
+ string[1] = 0x00;
+ string[2] = bitmap->RingtoneID;
+ count += N71_65_PackPBKBlock(s, N7110_PBK_RINGTONE_ID, 3, block++, string, req + count);
+ count --;
+ req[count-5] = 8;
+ }
+ }
+
+ /* Number of group */
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_6230iCALLER)) {
+ string[0] = bitmap->Location;
+ string[1] = 0;
+ count += N71_65_PackPBKBlock(s, N7110_PBK_GROUP, 2, block++, string, req + count);
+ }
+
+ /* Name */
+ if (!bitmap->DefaultName) {
+ i = UnicodeLength(bitmap->Text) * 2;
+ string[0] = i + 2;
+ memcpy(string + 1, bitmap->Text, i);
+ string[i + 1] = 0;
+ count += N71_65_PackPBKBlock(s, N7110_PBK_NAME, i + 2, block++, string, req + count);
+ }
+
+ /* Logo */
+ if (!bitmap->DefaultBitmap) {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_6230iCALLER)) {
+ /* write N6510_PBK_PICTURE_ID ? */
+ } else {
+ PHONE_GetBitmapWidthHeight(GSM_NokiaCallerLogo, &Width, &Height);
+ string[0] = Width;
+ string[1] = Height;
+ string[2] = 0;
+ string[3] = 0;
+ string[4] = PHONE_GetBitmapSize(GSM_NokiaCallerLogo,0,0);
+ PHONE_EncodeBitmap(GSM_NokiaCallerLogo, string + 5, bitmap);
+ count += N71_65_PackPBKBlock(s, N7110_PBK_GROUPLOGO, PHONE_GetBitmapSize(GSM_NokiaCallerLogo,0,0) + 5, block++, string, req + count);
+ }
+ }
+
+ req[21] = block;
+
+ return GSM_WaitFor (s, req, count, 0x03, s->Phone.Data.Priv.N6510.Timeout, ID_SetBitmap);
+}
+
+static GSM_Error N6510_ReplySetPicture(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "Picture Image written OK, folder %i, location %i\n",msg->Buffer[4],msg->Buffer[5]*256+msg->Buffer[6]);
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_SetBitmap(GSM_StateMachine *s, GSM_Bitmap *Bitmap)
+{
+ GSM_SMSMessage sms;
+ GSM_Phone_Bitmap_Types Type;
+ size_t Width, Height, i, count;
+ unsigned char folderid;
+ unsigned int location;
+ GSM_NetworkInfo NetInfo;
+ GSM_Error error;
+ unsigned char reqStartup[1000] = {
+ N7110_FRAME_HEADER, 0x04, 0x0F,
+ 0x00, 0x00, 0x00,
+ 0x04, 0xC0, 0x02, 0x00,
+ 0x41, 0xC0, 0x03, 0x00,
+ 0x60, 0xC0, 0x04};
+ unsigned char reqColourWallPaper[200] = {
+ N6110_FRAME_HEADER, 0x07, 0x00, 0x00, 0x00, 0xD5,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x00,
+ 0x18}; /* Bitmap ID */
+ unsigned char reqColourStartup[200] = {
+ N6110_FRAME_HEADER, 0x04, 0x25, 0x00, 0x01, 0x00, 0x18};
+ unsigned char reqOp[1000] = {
+ N7110_FRAME_HEADER, 0x25, 0x01,
+ 0x55, 0x00, 0x00, 0x55,
+ 0x01, /* 0x01 - not set, 0x02 - set */
+ 0x0C, 0x08,
+ 0x62, 0xF0, 0x10, /* Network code */
+ 0x03, 0x55, 0x55};
+ unsigned char reqColourOp[200] = {
+ N6110_FRAME_HEADER,
+ 0x07, 0x00, 0x00, 0x00, 0xE7, 0x00, 0x00, 0x00, 0xF9, 0x00,
+ 0x08, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00,
+ 0x18, /* File ID */
+ 0x00,
+ 0x00, 0x00, 0x00}; /* Network code */
+ unsigned char reqNote[200] = {N6110_FRAME_HEADER, 0x04, 0x01};
+ unsigned char reqPicture[2000] = {
+ N6110_FRAME_HEADER, 0x00,
+ 0x02, 0x05, /* SMS folder */
+ 0x00, 0x00, /* location */
+ 0x01, 0x01, 0xa0, 0x02, 0x01, 0x40, 0x00, 0x34,
+ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x55, 0x55, 0x55, 0x03, 0x82, 0x10,
+ 0x01, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82, 0x10,
+ 0x02, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x04,
+ 0x00, 0x00, 0xa1, 0x55, 0x01, 0x08, 0x00, 0x00,
+ 0x00, 0x01, 0x48, 0x1c, 0x00, 0xfc, 0x00};
+
+ switch (Bitmap->Type) {
+ case GSM_ColourWallPaper_ID:
+ reqColourWallPaper[21] = Bitmap->ID;
+ smprintf(s, "Setting colour wall paper\n");
+ return GSM_WaitFor (s, reqColourWallPaper, 22, 0x43, s->Phone.Data.Priv.N6510.Timeout, ID_SetBitmap);
+ case GSM_StartupLogo:
+ Type = GSM_Nokia7110StartupLogo;
+ switch (Bitmap->Location) {
+ case 1: PHONE_EncodeBitmap(Type, reqStartup + 22, Bitmap);
+ break;
+ case 2: memset(reqStartup+5,0x00,15);
+ PHONE_ClearBitmap(Type, reqStartup + 22,0,0);
+ break;
+ default: return ERR_NOTSUPPORTED;
+ }
+ smprintf(s, "Setting startup logo\n");
+ return GSM_WaitFor (s, reqStartup, 22+PHONE_GetBitmapSize(Type,0,0), 0x7A, s->Phone.Data.Priv.N6510.Timeout, ID_SetBitmap);
+ case GSM_DealerNote_Text:
+ reqNote[4] = 0x10;
+ CopyUnicodeString(reqNote + 5, Bitmap->Text);
+ i = 6 + UnicodeLength(Bitmap->Text) * 2;
+ reqNote[i++] = 0;
+ reqNote[i] = 0;
+ return GSM_WaitFor (s, reqNote, i, 0x7A, s->Phone.Data.Priv.N6510.Timeout, ID_SetBitmap);
+ case GSM_WelcomeNote_Text:
+ CopyUnicodeString(reqNote + 5, Bitmap->Text);
+ i = 6 + UnicodeLength(Bitmap->Text) * 2;
+ reqNote[i++] = 0;
+ reqNote[i] = 0;
+ return GSM_WaitFor (s, reqNote, i, 0x7A, s->Phone.Data.Priv.N6510.Timeout, ID_SetBitmap);
+ case GSM_OperatorLogo:
+ /* We want to set operator logo, not clear */
+ if (strcmp(Bitmap->NetworkCode,"000 00")) {
+ memset(reqOp + 19, 0, 281);
+ NOKIA_EncodeNetworkCode(reqOp+12, Bitmap->NetworkCode);
+ Type = GSM_Nokia6510OperatorLogo;
+ reqOp[9] = 0x02; /* Logo enabled */
+ reqOp[18] = 0x1a; /* FIXME */
+ reqOp[19] = PHONE_GetBitmapSize(Type,0,0) + 8 + 29 + 2;
+ PHONE_GetBitmapWidthHeight(Type, &Width, &Height);
+ reqOp[20] = Width;
+ reqOp[21] = Height;
+ reqOp[22] = 0x00;
+ reqOp[23] = PHONE_GetBitmapSize(Type,0,0) + 29;
+ reqOp[24] = 0x00;
+ reqOp[25] = PHONE_GetBitmapSize(Type,0,0) + 29;
+ PHONE_EncodeBitmap(Type, reqOp + 26, Bitmap);
+ smprintf(s, "Setting operator logo\n");
+ return GSM_WaitFor (s, reqOp, reqOp[19]+reqOp[11]+10, 0x0A, s->Phone.Data.Priv.N6510.Timeout, ID_SetBitmap);
+ } else {
+ error=N6510_GetNetworkInfo(s,&NetInfo);
+ if (error != ERR_NONE) return error;
+ NOKIA_EncodeNetworkCode(reqOp+12, NetInfo.NetworkCode);
+ smprintf(s, "Clearing operator logo\n");
+ return GSM_WaitFor (s, reqOp, 18, 0x0A, s->Phone.Data.Priv.N6510.Timeout, ID_SetBitmap);
+ }
+ case GSM_ColourOperatorLogo_ID:
+ /* We want to set operator logo, not clear */
+ if (strcmp(Bitmap->NetworkCode,"000 00")) {
+ EncodeBCD(reqColourOp+23, Bitmap->NetworkCode, 6, FALSE);
+ reqColourOp[21] = Bitmap->ID;
+ }
+ smprintf(s, "Setting colour operator logo\n");
+ return GSM_WaitFor (s, reqColourOp, 26, 0x43, s->Phone.Data.Priv.N6510.Timeout, ID_SetBitmap);
+ case GSM_ColourStartupLogo_ID:
+ switch (Bitmap->Location) {
+ case 0: reqColourStartup[6] = 0x00;
+ reqColourStartup[8] = 0x00;
+ smprintf(s, "Setting colour startup logo\n");
+ return GSM_WaitFor (s, reqColourStartup, 9, 0x7A, s->Phone.Data.Priv.N6510.Timeout, ID_SetBitmap);
+ case 1: reqColourStartup[8] = Bitmap->ID;
+ smprintf(s, "Setting colour startup logo\n");
+ return GSM_WaitFor (s, reqColourStartup, 9, 0x7A, s->Phone.Data.Priv.N6510.Timeout, ID_SetBitmap);
+ default:return ERR_NOTSUPPORTED;
+ }
+ case GSM_CallerGroupLogo:
+ return N6510_SetCallerLogo(s,Bitmap);
+ case GSM_PictureImage:
+ error = N6510_GetPictureImage(s, Bitmap, &sms.Location);
+ if (error == ERR_NONE) {
+ sms.Folder = 0;
+ N6510_GetSMSLocation(s, &sms, &folderid, &location);
+ switch (folderid) {
+ case 0x01: reqPicture[5] = 0x02; break; /* INBOX SIM */
+ case 0x02: reqPicture[5] = 0x03; break; /* OUTBOX SIM */
+ default : reqPicture[5] = folderid - 1; reqPicture[4] = 0x02; break; /* ME folders */
+ }
+ reqPicture[6]=location / 256;
+ reqPicture[7]=location;
+ }
+ Type = GSM_NokiaPictureImage;
+ count = 78;
+ PHONE_EncodeBitmap(Type, reqPicture + count, Bitmap);
+ count += PHONE_GetBitmapSize(Type,0,0);
+ smprintf(s, "Setting Picture Image\n");
+ return GSM_WaitFor (s, reqPicture, count, 0x14, s->Phone.Data.Priv.N6510.Timeout, ID_SetBitmap);
+ default:
+ break;
+ }
+ return ERR_NOTSUPPORTED;
+}
+
+static GSM_Error N6510_ReplyGetRingtoneID(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+
+ smprintf(s, "Ringtone ID received\n");
+ Priv->RingtoneID = msg->Buffer[15];
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_ReplySetBinRingtone(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Binary ringtone set\n");
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_SetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, int *maxlength)
+{
+ GSM_Error error;
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ GSM_NetworkInfo NetInfo;
+ size_t size=200, current;
+ unsigned char GetIDReq[] = {
+ N7110_FRAME_HEADER, 0x01, 0x00, 0x00,
+ 0x00, 0xFF, 0x06, 0xE1, 0x00,
+ 0xFF, 0x06, 0xE1, 0x01, 0x42};
+ unsigned char SetPreviewReq[1000] = {
+ 0xAE, /* Ringtone ID */
+ 0x01, 0x00, 0x0D, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00}; /*Length*/
+ unsigned char AddBinaryReq[33000] = {
+ N7110_FRAME_HEADER, 0x0E, 0x7F, 0xFF, 0xFE};
+
+ if (Ringtone->Format == RING_NOTETONE && Ringtone->Location==255)
+ {
+ smprintf(s, "Getting ringtone ID\n");
+ error=GSM_WaitFor (s, GetIDReq, 14, 0xDB, s->Phone.Data.Priv.N6510.Timeout, ID_SetRingtone);
+ if (error != ERR_NONE) return error;
+ *maxlength=GSM_EncodeNokiaRTTLRingtone(Ringtone, SetPreviewReq+11, &size);
+ SetPreviewReq[0] = Priv->RingtoneID;
+ SetPreviewReq[10] = size;
+ smprintf(s, "Setting ringtone\n");
+ error = s->Protocol.Functions->WriteMessage(s, SetPreviewReq, size+11, 0x00);
+ if (error!=ERR_NONE) return error;
+ sleep(1);
+ /* We have to make something (not important, what) now */
+ /* no answer from phone*/
+ return s->Phone.Functions->GetNetworkInfo(s,&NetInfo);
+ }
+ if (Ringtone->Format == RING_NOKIABINARY) {
+ AddBinaryReq[7] = UnicodeLength(Ringtone->Name);
+ CopyUnicodeString(AddBinaryReq+8,Ringtone->Name);
+ current = 8 + UnicodeLength(Ringtone->Name)*2;
+ AddBinaryReq[current++] = Ringtone->NokiaBinary.Length/256 + 1;
+ AddBinaryReq[current++] = Ringtone->NokiaBinary.Length%256 + 1;
+ AddBinaryReq[current++] = 0x00;
+ memcpy(AddBinaryReq+current,Ringtone->NokiaBinary.Frame,Ringtone->NokiaBinary.Length);
+ current += Ringtone->NokiaBinary.Length;
+ smprintf(s, "Adding binary ringtone\n");
+ return GSM_WaitFor (s, AddBinaryReq, current, 0x1F, s->Phone.Data.Priv.N6510.Timeout, ID_SetRingtone);
+ }
+ if (Ringtone->Format == RING_MIDI) {
+ AddBinaryReq[7] = UnicodeLength(Ringtone->Name);
+ CopyUnicodeString(AddBinaryReq+8,Ringtone->Name);
+ current = 8 + UnicodeLength(Ringtone->Name)*2;
+ AddBinaryReq[current++] = Ringtone->NokiaBinary.Length/256;
+ AddBinaryReq[current++] = Ringtone->NokiaBinary.Length%256;
+ memcpy(AddBinaryReq+current,Ringtone->NokiaBinary.Frame,Ringtone->NokiaBinary.Length);
+ current += Ringtone->NokiaBinary.Length;
+ AddBinaryReq[current++] = 0x00;
+ AddBinaryReq[current++] = 0x00;
+ smprintf(s, "Adding binary or MIDI ringtone\n");
+ return GSM_WaitFor (s, AddBinaryReq, current, 0x1F, s->Phone.Data.Priv.N6510.Timeout, ID_SetRingtone);
+ }
+ return ERR_NOTSUPPORTED;
+}
+
+static GSM_Error N6510_ReplyDeleteRingtones(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Ringtones deleted\n");
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_DeleteUserRingtones(GSM_StateMachine *s)
+{
+ unsigned char DelAllRingtoneReq[] = {N7110_FRAME_HEADER, 0x10, 0x7F, 0xFE};
+
+ smprintf(s, "Deleting all user ringtones\n");
+ return GSM_WaitFor (s, DelAllRingtoneReq, 6, 0x1F, s->Phone.Data.Priv.N6510.Timeout, ID_SetRingtone);
+}
+
+static GSM_Error N6510_ReplyPressKey(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ if (msg->Buffer[3] == 0x33) {
+ smprintf(s, "Key auto released\n");
+ } else if (msg->Buffer[3] == 0x12) {
+ smprintf(s, "Key pressed\n");
+ } else {
+ return ERR_UNKNOWN;
+ }
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_PressKey(GSM_StateMachine *s, GSM_KeyCode Key, gboolean Press)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x11, 0x00, 0x01, 0x00, 0x00,
+ 0x00, /* Event */
+ 0x01}; /* Number of presses */
+
+ if (Key != GSM_KEY_GREEN) {
+ smprintf(s, "Mapping for key code %d missing!\n", Key);
+ return ERR_NOTIMPLEMENTED;
+ }
+
+ req[7] = Key;
+ if (Press) {
+ req[8] = NOKIA_PRESSPHONEKEY;
+ s->Phone.Data.PressKey = TRUE;
+ smprintf(s, "Pressing key\n");
+ } else {
+ req[8] = NOKIA_RELEASEPHONEKEY;
+ s->Phone.Data.PressKey = FALSE;
+ smprintf(s, "Releasing key\n");
+ }
+ return GSM_WaitFor (s, req, 10, 0x0c, s->Phone.Data.Priv.N6510.Timeout, ID_PressKey);
+}
+
+static GSM_Error N6510_EnableConnectionFunctions(GSM_StateMachine *s, N6510_Connection_Settings Type)
+{
+ GSM_Error error;
+ unsigned char req2[] = {N6110_FRAME_HEADER, 0x00, 0x01};
+ unsigned char req3[] = {N6110_FRAME_HEADER, 0x00, 0x03};
+ unsigned char req4[] = {N6110_FRAME_HEADER, 0x00, 0x04};
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_6230iWAP)) return ERR_NOTSUPPORTED;
+
+ if (Type == N6510_MMS_SETTINGS && GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOMMS)) return ERR_NOTSUPPORTED;
+ if (Type == N6510_CHAT_SETTINGS && !GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CHAT)) return ERR_NOTSUPPORTED;
+ if (Type == N6510_SYNCML_SETTINGS && !GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SYNCML)) return ERR_NOTSUPPORTED;
+
+ error=DCT3DCT4_DisableConnectionFunctions(s);
+ if (error!=ERR_NONE) return error;
+
+ switch (Type) {
+ case N6510_WAP_SETTINGS:
+ return DCT3DCT4_EnableWAPFunctions(s);
+ case N6510_MMS_SETTINGS:
+ smprintf(s, "Enabling MMS\n");
+ return GSM_WaitFor (s, req2, 5, 0x3f, s->Phone.Data.Priv.N6510.Timeout, ID_EnableConnectFunc);
+ case N6510_SYNCML_SETTINGS:
+ smprintf(s, "Enabling SyncML\n");
+ return GSM_WaitFor (s, req3, 5, 0x3f, 5, ID_EnableConnectFunc);
+ case N6510_CHAT_SETTINGS:
+ smprintf(s, "Enabling Chat\n");
+ return GSM_WaitFor (s, req4, 5, 0x3f, 5, ID_EnableConnectFunc);
+ default:
+ return ERR_UNKNOWN;
+ }
+}
+
+static GSM_Error N6510_ReplyGetConnectionSettings(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ int tmp,num=0,i;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+ unsigned char buff[2000];
+
+ switch(msg->Buffer[3]) {
+ case 0x16:
+ smprintf(s, "Connection settings received OK\n");
+
+ Data->WAPSettings->Number = Priv->BearerNumber;
+
+ Data->WAPSettings->Proxy[0] = 0x00;
+ Data->WAPSettings->Proxy[1] = 0x00;
+ Data->WAPSettings->ProxyPort = 8080;
+
+ Data->WAPSettings->Proxy2[0] = 0x00;
+ Data->WAPSettings->Proxy2[1] = 0x00;
+ Data->WAPSettings->Proxy2Port = 8080;
+
+ tmp = 4;
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[0].Title,TRUE);
+ CopyUnicodeString(Data->WAPSettings->Settings[1].Title,Data->WAPSettings->Settings[0].Title);
+ smprintf(s, "Title: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[0].Title));
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[0].HomePage,TRUE);
+ CopyUnicodeString(Data->WAPSettings->Settings[1].HomePage,Data->WAPSettings->Settings[0].HomePage);
+ smprintf(s, "Homepage: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[0].HomePage));
+
+#ifdef DEBUG
+ smprintf(s, "Connection type: ");
+ switch (msg->Buffer[tmp]) {
+ case 0x00: smprintf(s, "temporary\n"); break;
+ case 0x01: smprintf(s, "continuous\n"); break;
+ default: smprintf(s, "unknown\n");
+ }
+ smprintf(s, "Connection security: ");
+ switch (msg->Buffer[tmp+1]) {
+ case 0x00: smprintf(s, "off\n"); break;
+ case 0x01: smprintf(s, "on\n"); break;
+ default: smprintf(s, "unknown\n");
+ }
+ smprintf(s, "Bearer: ");
+ switch (msg->Buffer[tmp+2]) {
+ case 0x01: smprintf(s, "GSM data\n"); break;
+ case 0x03: smprintf(s, "GPRS\n"); break;
+ default: smprintf(s, "unknown\n");
+ }
+ if (msg->Buffer[tmp+3] == 0x01) smprintf(s, "locked\n");
+#endif
+ Data->WAPSettings->Settings[0].IsContinuous = FALSE;
+ if (msg->Buffer[tmp] == 0x01) Data->WAPSettings->Settings[0].IsContinuous = TRUE;
+ Data->WAPSettings->Settings[1].IsContinuous = Data->WAPSettings->Settings[0].IsContinuous;
+
+ Data->WAPSettings->Settings[0].IsSecurity = FALSE;
+ if (msg->Buffer[tmp+1] == 0x01) Data->WAPSettings->Settings[0].IsSecurity = TRUE;
+ Data->WAPSettings->Settings[1].IsSecurity = Data->WAPSettings->Settings[0].IsSecurity;
+
+ Data->WAPSettings->ActiveBearer = WAPSETTINGS_BEARER_DATA;
+ if (msg->Buffer[tmp+2] == 0x03) Data->WAPSettings->ActiveBearer = WAPSETTINGS_BEARER_GPRS;
+
+ Data->WAPSettings->ReadOnly = FALSE;
+ if (msg->Buffer[tmp+3] == 0x01) Data->WAPSettings->ReadOnly = TRUE;
+
+ tmp+=3;
+
+ if (Priv->BearerNumber == 2) {
+ /* Here starts settings for data bearer */
+ Data->WAPSettings->Settings[0].Bearer = WAPSETTINGS_BEARER_DATA;
+ while ((msg->Buffer[tmp] != 0x01) || (msg->Buffer[tmp + 1] != 0x00)) tmp++;
+ tmp += 4;
+
+#ifdef DEBUG
+ smprintf(s, "Authentication type: ");
+ switch (msg->Buffer[tmp]) {
+ case 0x00: smprintf(s, "normal\n"); break;
+ case 0x01: smprintf(s, "secure\n"); break;
+ default: smprintf(s, "unknown\n"); break;
+ }
+ smprintf(s, "Data call type: ");
+ switch (msg->Buffer[tmp+1]) {
+ case 0x00: smprintf(s, "analogue\n"); break;
+ case 0x01: smprintf(s, "ISDN\n"); break;
+ default: smprintf(s, "unknown\n"); break;
+ }
+ smprintf(s, "Data call speed: ");
+ switch (msg->Buffer[tmp+2]) {
+ case 0x00: smprintf(s, "automatic\n"); break;
+ case 0x01: smprintf(s, "9600\n"); break;
+ case 0x02: smprintf(s, "14400\n"); break;
+ default: smprintf(s, "unknown\n"); break;
+ }
+ smprintf(s, "Login Type: ");
+ switch (msg->Buffer[tmp+4]) {
+ case 0x00: smprintf(s, "manual\n"); break;
+ case 0x01: smprintf(s, "automatic\n"); break;
+ default: smprintf(s, "unknown\n"); break;
+ }
+#endif
+ Data->WAPSettings->Settings[0].IsNormalAuthentication=TRUE;
+ if (msg->Buffer[tmp]==0x01) Data->WAPSettings->Settings[0].IsNormalAuthentication=FALSE;
+
+ Data->WAPSettings->Settings[0].IsISDNCall=FALSE;
+ if (msg->Buffer[tmp+1]==0x01) Data->WAPSettings->Settings[0].IsISDNCall=TRUE;
+
+ switch (msg->Buffer[tmp+2]) {
+ case 0x00: Data->WAPSettings->Settings[0].Speed=WAPSETTINGS_SPEED_AUTO; break;
+ case 0x01: Data->WAPSettings->Settings[0].Speed=WAPSETTINGS_SPEED_9600; break;
+ case 0x02: Data->WAPSettings->Settings[0].Speed=WAPSETTINGS_SPEED_14400; break;
+ default:
+ smprintf(s, "Unknown speed settings: 0x%0x\n", msg->Buffer[tmp+2]);
+ Data->WAPSettings->Settings[0].Speed=WAPSETTINGS_SPEED_AUTO;
+ break;
+ }
+
+ Data->WAPSettings->Settings[0].ManualLogin=FALSE;
+ if (msg->Buffer[tmp+4]==0x00) Data->WAPSettings->Settings[0].ManualLogin = TRUE;
+
+ tmp+=5;
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[0].IPAddress,FALSE);
+ smprintf(s, "IP address: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[0].IPAddress));
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[0].DialUp,TRUE);
+ smprintf(s, "Dial-up number: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[0].DialUp));
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[0].User,TRUE);
+ smprintf(s, "User name: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[0].User));
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[0].Password,TRUE);
+ smprintf(s, "Password: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[0].Password));
+
+ num = 1;
+ } else {
+ num = 0;
+ }
+
+ /* Here starts settings for gprs bearer */
+ Data->WAPSettings->Settings[num].Bearer = WAPSETTINGS_BEARER_GPRS;
+ while (msg->Buffer[tmp] != 0x03) tmp++;
+ tmp += 4;
+
+#ifdef DEBUG
+ smprintf(s, "Authentication type: ");
+ switch (msg->Buffer[tmp]) {
+ case 0x00: smprintf(s, "normal\n"); break;
+ case 0x01: smprintf(s, "secure\n"); break;
+ default: smprintf(s, "unknown\n"); break;
+ }
+ smprintf(s, "GPRS connection: ");
+ switch (msg->Buffer[tmp+1]) {
+ case 0x00: smprintf(s, "ALWAYS online\n"); break;
+ case 0x01: smprintf(s, "when needed\n"); break;
+ default: smprintf(s, "unknown\n"); break;
+ }
+ smprintf(s, "Login Type: ");
+ switch (msg->Buffer[tmp+2]) {
+ case 0x00: smprintf(s, "manual\n"); break;
+ case 0x01: smprintf(s, "automatic\n"); break;
+ default: smprintf(s, "unknown\n"); break;
+ }
+#endif
+ Data->WAPSettings->Settings[num].IsNormalAuthentication=TRUE;
+ if (msg->Buffer[tmp]==0x01) Data->WAPSettings->Settings[num].IsNormalAuthentication=FALSE;
+
+ Data->WAPSettings->Settings[num].IsISDNCall=FALSE;
+ Data->WAPSettings->Settings[num].Speed = WAPSETTINGS_SPEED_AUTO;
+
+ Data->WAPSettings->Settings[num].IsContinuous = TRUE;
+ if (msg->Buffer[tmp+1] == 0x01) Data->WAPSettings->Settings[num].IsContinuous = FALSE;
+
+ Data->WAPSettings->Settings[num].ManualLogin=FALSE;
+ if (msg->Buffer[tmp+2]==0x00) Data->WAPSettings->Settings[num].ManualLogin = TRUE;
+
+ tmp+=3;
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[num].DialUp,FALSE);
+ smprintf(s, "Access point: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[num].DialUp));
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[num].IPAddress,TRUE);
+ smprintf(s, "IP address: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[num].IPAddress));
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[num].User,TRUE);
+ smprintf(s, "User name: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[num].User));
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPSettings->Settings[num].Password,TRUE);
+ smprintf(s, "Password: \"%s\"\n",DecodeUnicodeString(Data->WAPSettings->Settings[num].Password));
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_WAPMMSPROXY)) {
+ if (msg->Buffer[tmp] == 0x00 && msg->Buffer[tmp+1] == 0x00) tmp = tmp+2;
+
+ memcpy(buff,msg->Buffer+tmp+10,msg->Buffer[tmp+4]);
+ buff[msg->Buffer[tmp+4]] = 0x00;
+ smprintf(s, "Proxy 1: \"%s\", port %i\n",buff,msg->Buffer[tmp+6]*256+msg->Buffer[tmp+7]);
+ EncodeUnicode(Data->WAPSettings->Proxy,buff,strlen(buff));
+ Data->WAPSettings->ProxyPort = msg->Buffer[tmp+6]*256+msg->Buffer[tmp+7];
+
+ memcpy(buff,msg->Buffer+tmp+10+msg->Buffer[tmp+4],msg->Buffer[tmp+5]);
+ buff[msg->Buffer[tmp+5]] = 0x00;
+ smprintf(s, "Proxy 2: \"%s\", port %i\n",buff,msg->Buffer[tmp+8]*256+msg->Buffer[tmp+9]);
+ EncodeUnicode(Data->WAPSettings->Proxy2,buff,strlen(buff));
+ Data->WAPSettings->Proxy2Port = msg->Buffer[tmp+8]*256+msg->Buffer[tmp+9];
+
+ tmp = tmp + msg->Buffer[tmp+3] + 19;
+
+ for (i=0;i<4;i++) {
+#ifdef DEBUG
+ smprintf(s, "Proxy data %i\n",i+1);
+ if (msg->Buffer[tmp+2]!=0) memcpy(buff,msg->Buffer+tmp+9,msg->Buffer[tmp+2]*2);
+ buff[msg->Buffer[tmp+2]*2] =0;
+ buff[msg->Buffer[tmp+2]*2+1]=0;
+ smprintf(s, "IP: \"%s\"",DecodeUnicodeString(buff));
+ smprintf(s, ", port %i\n",msg->Buffer[tmp+3]*256+msg->Buffer[tmp+4]);
+#endif
+ tmp = tmp + msg->Buffer[tmp];
+ }
+
+#ifdef DEBUG
+ smprintf(s, "%02x %02x\n",msg->Buffer[tmp],msg->Buffer[tmp+1]);
+ smprintf(s, "Port %i\n",msg->Buffer[tmp+3]*256+msg->Buffer[tmp+4]);
+ tmp = tmp + msg->Buffer[tmp];
+#endif
+ }
+
+ return ERR_NONE;
+ case 0xf0:
+ /*
+ * Don't know exactly what 0x0f means, but the message is too short
+ * to contain information:
+ *
+ * 01 |58X|00 |F0 |01 |15 |00 |00 |00 |00
+ */
+ smprintf(s, "Connection settings receiving error, assuming empty\n");
+ return ERR_EMPTY;
+ case 0x11:
+ case 0x17:
+ smprintf(s, "Connection settings receiving error\n");
+ switch (msg->Buffer[4]) {
+ case 0x01:
+ smprintf(s, "Security error. Inside phone settings menu\n");
+ return ERR_INSIDEPHONEMENU;
+ case 0x02:
+ case 0x03: /* Guess */
+ smprintf(s, "Invalid or empty\n");
+ return ERR_INVALIDLOCATION;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_GetConnectionSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings, N6510_Connection_Settings Type)
+{
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ GSM_Error error;
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x15,
+ 0x00}; /* Location */
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) return ERR_NOTSUPPORTED;
+ if (!strcmp(s->Phone.Data.ModelInfo->model,"6020")) return ERR_NOTSUPPORTED;
+
+ error = N6510_EnableConnectionFunctions(s, Type);
+ if (error!=ERR_NONE) return error;
+
+ req[4] = settings->Location-1;
+ s->Phone.Data.WAPSettings = settings;
+
+ switch (Type) {
+ case N6510_MMS_SETTINGS:
+ smprintf(s, "Getting MMS settings\n");
+ Priv->BearerNumber = 1;
+ break;
+ case N6510_WAP_SETTINGS:
+ smprintf(s, "Getting WAP settings\n");
+ Priv->BearerNumber = 2;
+ break;
+ case N6510_SYNCML_SETTINGS:
+ smprintf(s, "Getting SyncML settings\n");
+ Priv->BearerNumber = 2;
+ break;
+ case N6510_CHAT_SETTINGS:
+ smprintf(s, "Getting Chat settings\n");
+ Priv->BearerNumber = 1;
+ break;
+ }
+
+ error=GSM_WaitFor (s, req, 5, 0x3f, s->Phone.Data.Priv.N6510.Timeout, ID_GetConnectSet);
+ if (error != ERR_NONE) {
+ if (error == ERR_INVALIDLOCATION || error == ERR_INSIDEPHONEMENU) {
+ DCT3DCT4_DisableConnectionFunctions(s);
+ }
+ return error;
+ }
+
+ error=DCT3DCT4_GetActiveConnectSet(s);
+ if (error != ERR_NONE) return error;
+
+ return DCT3DCT4_DisableConnectionFunctions(s);
+}
+
+static GSM_Error N6510_GetWAPSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings)
+{
+ return N6510_GetConnectionSettings(s, settings, N6510_WAP_SETTINGS);
+}
+
+static GSM_Error N6510_GetMMSSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings)
+{
+ return N6510_GetConnectionSettings(s, settings, N6510_MMS_SETTINGS);
+}
+
+static GSM_Error N6510_ReplyGetSyncMLSettings(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_SyncMLSettings *Sett = s->Phone.Data.SyncMLSettings;
+
+ smprintf(s, "SyncML settings received OK\n");
+ CopyUnicodeString(Sett->User,msg->Buffer+18);
+ CopyUnicodeString(Sett->Password,msg->Buffer+86);
+ CopyUnicodeString(Sett->PhonebookDataBase,msg->Buffer+130);
+ CopyUnicodeString(Sett->CalendarDataBase,msg->Buffer+234);
+ CopyUnicodeString(Sett->Server,msg->Buffer+338);
+
+ Sett->SyncPhonebook = FALSE;
+ Sett->SyncCalendar = FALSE;
+ if ((msg->Buffer[598] & 0x02)==0x02) Sett->SyncCalendar = TRUE;
+ if ((msg->Buffer[598] & 0x01)==0x01) Sett->SyncPhonebook = TRUE;
+
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_ReplyGetSyncMLName(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_SyncMLSettings *Sett = s->Phone.Data.SyncMLSettings;
+
+ smprintf(s, "SyncML names received OK\n");
+
+ CopyUnicodeString(Sett->Name,msg->Buffer+18);
+
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_GetSyncMLSettings(GSM_StateMachine *s, GSM_SyncMLSettings *settings)
+{
+ GSM_Error error;
+/* unsigned char NameReq[] = {N6110_FRAME_HEADER, 0x05, */
+/* 0x00, 0x00, 0x00, 0x31, 0x00, */
+/* 0x06, 0x00, 0x00, 0x00, 0xDE, 0x00, 0x00}; */
+/* unsigned char GetActive[] = {N6110_FRAME_HEADER, 0x05, */
+/* 0x00, 0x00, 0x00, 0x31, 0x00, */
+/* 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00}; */
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x05,
+ 0x00, 0x00, 0x00, 0x31, 0x00,
+ 0x01, /* location */
+ 0x00, 0x00, 0x02, 0x46, 0x00, 0x00};
+
+ settings->Connection.Location = settings->Location;
+ error = N6510_GetConnectionSettings(s, &settings->Connection, N6510_SYNCML_SETTINGS);
+ if (error != ERR_NONE) return error;
+
+ settings->Active = settings->Connection.Active;
+
+ settings->Name[0] = 0;
+ settings->Name[1] = 0;
+ s->Phone.Data.SyncMLSettings = settings;
+
+/* smprintf(s, "Getting SyncML settings name\n"); */
+/* error = GSM_WaitFor (s, NameReq, 16, 0x43, s->Phone.Data.Priv.N6510.Timeout, ID_GetSyncMLName); */
+/* if (error != ERR_NONE) return error; */
+
+ req[9] = settings->Location - 1;
+ smprintf(s, "Getting additional SyncML settings\n");
+ return GSM_WaitFor (s, req, 16, 0x43, s->Phone.Data.Priv.N6510.Timeout, ID_GetSyncMLSettings);
+}
+
+static GSM_Error N6510_ReplyGetChatSettings(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_ChatSettings *Sett = s->Phone.Data.ChatSettings;
+ int i;
+
+ Sett->Name[0] = 0;
+ Sett->Name[1] = 0;
+ Sett->HomePage[0] = 0;
+ Sett->HomePage[1] = 0;
+ Sett->User[0] = 0;
+ Sett->User[1] = 0;
+ Sett->Password[0] = 0;
+ Sett->Password[1] = 0;
+
+ switch(msg->Buffer[3]) {
+ case 0x3B:
+ smprintf(s, "Chat settings received OK\n");
+ memcpy(Sett->Name,msg->Buffer+20,msg->Buffer[12]*2);
+ Sett->Name[msg->Buffer[12]*2] = 0;
+ Sett->Name[msg->Buffer[12]*2+1] = 0;
+ memcpy(Sett->HomePage,msg->Buffer+20+msg->Buffer[12]*2,msg->Buffer[15]*2);
+ Sett->HomePage[msg->Buffer[15]*2] = 0;
+ Sett->HomePage[msg->Buffer[15]*2+1] = 0;
+ i = msg->Buffer[12]*2 + msg->Buffer[15]*2 + 29;
+ memcpy(Sett->User,msg->Buffer+i+3,msg->Buffer[i]*2);
+ Sett->User[msg->Buffer[i]*2] = 0;
+ Sett->User[msg->Buffer[i]*2+1] = 0;
+ memcpy(Sett->Password,msg->Buffer+i+3+msg->Buffer[i]*2,msg->Buffer[i+1]*2);
+ Sett->Password[msg->Buffer[i+1]*2] = 0;
+ Sett->Password[msg->Buffer[i+1]*2+1] = 0;
+ return ERR_NONE;
+ case 0x3C:
+ smprintf(s, "Empty chat settings received\n");
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_GetChatSettings(GSM_StateMachine *s, GSM_ChatSettings *settings)
+{
+ GSM_Error error;
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x3a,
+ 0x09, /* location */
+ 0x01, 0x0e};
+
+ settings->Connection.Location = settings->Location;
+ error = N6510_GetConnectionSettings(s, &settings->Connection, N6510_CHAT_SETTINGS);
+ if (error != ERR_NONE) return error;
+
+ settings->Active = settings->Connection.Active;
+
+ s->Phone.Data.ChatSettings = settings;
+ req[4] = settings->Location - 1;
+ smprintf(s, "Getting additional Chat settings\n");
+ return GSM_WaitFor (s, req, 7, 0x3f, s->Phone.Data.Priv.N6510.Timeout, ID_GetChatSettings);
+}
+
+static GSM_Error N6510_ReplySetConnectionSettings(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x19:
+ smprintf(s, "Connection settings cleaned\n");
+ return ERR_NONE;
+ case 0x1a:
+ smprintf(s, "Connection settings setting status\n");
+ switch (msg->Buffer[4]) {
+ case 0x01:
+ smprintf(s, "Security error. Inside phone settings menu\n");
+ return ERR_INSIDEPHONEMENU;
+ case 0x03:
+ smprintf(s, "Invalid location\n");
+ return ERR_INVALIDLOCATION;
+ case 0x05:
+ smprintf(s, "Written OK\n");
+ return ERR_NONE;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ case 0x28:
+ case 0x2B:
+ smprintf(s, "Set OK\n");
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_SetConnectionSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings, N6510_Connection_Settings Type)
+{
+ GSM_Error error;
+ int i, pad = 0, length, pos = 5, loc1=-1,loc2=-1,port;
+ unsigned char *Proxy;
+ unsigned char req[2000] = {N6110_FRAME_HEADER, 0x18,
+ 0x00}; /* Location */
+ unsigned char Lock[5] = {N6110_FRAME_HEADER, 0x27,
+ 0x00}; /* Location */
+ unsigned char UnLock[5] = {N6110_FRAME_HEADER, 0x2A,
+ 0x00}; /* Location */
+
+ error = N6510_EnableConnectionFunctions(s, Type);
+ if (error!=ERR_NONE) return error;
+
+ memset(req + pos, 0, 1000 - pos);
+
+ req[4] = settings->Location-1;
+
+ for (i=0;i<settings->Number;i++) {
+ if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_DATA) loc1=i;
+ if (settings->Settings[i].Bearer == WAPSETTINGS_BEARER_GPRS) loc2=i;
+ }
+
+ if (loc1 != -1) {
+ /* Name */
+ length = UnicodeLength(settings->Settings[loc1].Title);
+ if (!(length % 2)) pad = 1;
+ pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc1].Title, FALSE);
+
+ /* Home */
+ length = UnicodeLength(settings->Settings[loc1].HomePage);
+ if (((length + pad) % 2)) pad = 2; else pad = 0;
+ pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc1].HomePage, TRUE);
+
+ if (settings->Settings[loc1].IsContinuous) {
+ req[pos] = 0x01;
+ }
+ pos++;
+ if (settings->Settings[loc1].IsSecurity) {
+ req[pos] = 0x01;
+ }
+ pos++;
+ } else if (loc2 != -1) {
+ /* Name */
+ length = UnicodeLength(settings->Settings[loc2].Title);
+ if (!(length % 2)) pad = 1;
+ pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc2].Title, FALSE);
+
+ /* Home */
+ length = UnicodeLength(settings->Settings[loc2].HomePage);
+ if (((length + pad) % 2)) pad = 2; else pad = 0;
+ pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc2].HomePage, TRUE);
+
+ if (settings->Settings[loc2].IsContinuous) {
+ req[pos] = 0x01;
+ }
+ pos++;
+ if (settings->Settings[loc2].IsSecurity) {
+ req[pos] = 0x01;
+ }
+ pos++;
+ } else {
+ /* Name */
+ length = 0;
+ if (!(length % 2)) pad = 1;
+ pos ++;
+
+ /* Home */
+ length = 0;
+ if (((length + pad) % 2)) pad = 2; else pad = 0;
+ pos += 2;
+
+ pos += 2;
+ }
+
+ if (Type == N6510_MMS_SETTINGS || Type == N6510_CHAT_SETTINGS) {
+ req[pos++] = 0x03; /* active bearer: GPRS */
+ } else {
+ if (settings->ActiveBearer == WAPSETTINGS_BEARER_GPRS && loc2 != -1) {
+ req[pos++] = 0x03; /* active bearer: GPRS */
+ } else {
+ req[pos++] = 0x01; /* active bearer: data set */
+ }
+ }
+
+ /* Number of sent bearers */
+ if (Type == N6510_MMS_SETTINGS || Type == N6510_CHAT_SETTINGS) {
+ req[pos] = 0x01;
+ } else {
+ req[pos] = 0x02;
+ }
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_WAPMMSPROXY)) req[pos] += 2;
+ pos++;
+ pos += pad;
+
+ if (Type != N6510_MMS_SETTINGS && Type != N6510_CHAT_SETTINGS) {
+ /* GSM data block */
+ memcpy(req + pos, "\x01\x00", 2); pos += 2;
+
+ if (loc1 != -1) {
+ length = UnicodeLength(settings->Settings[loc1].IPAddress)*2+1;
+ length += UnicodeLength(settings->Settings[loc1].DialUp) *2+2;
+ length += UnicodeLength(settings->Settings[loc1].User) *2+2;
+ length += UnicodeLength(settings->Settings[loc1].Password) *2+2;
+ } else {
+ length = 1 + 2 + 2 + 2;
+ }
+ length += 11;
+ req[pos++] = length / 256;
+ req[pos++] = length % 256;
+
+ if (loc1 != -1) {
+ if (!settings->Settings[loc1].IsNormalAuthentication) {
+ req[pos]=0x01;
+ }
+ pos++;
+ if (settings->Settings[loc1].IsISDNCall) {
+ req[pos]=0x01;
+ }
+ pos++;
+ switch (settings->Settings[loc1].Speed) {
+ case WAPSETTINGS_SPEED_AUTO : break;
+ case WAPSETTINGS_SPEED_9600 : req[pos]=0x01; break;
+ case WAPSETTINGS_SPEED_14400 : req[pos]=0x02; break;
+ }
+ pos++;
+ req[pos++]=0x01;
+ if (!settings->Settings[loc1].ManualLogin) {
+ req[pos] = 0x01;
+ }pos++;
+
+ pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc1].IPAddress, FALSE);
+ pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc1].DialUp, TRUE);
+ pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc1].User, TRUE);
+ pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc1].Password, TRUE);
+ } else {
+ pos += 3;
+ req[pos++]=0x01;
+ pos += 8;
+ }
+
+ /* Padding */
+ pos+=2;
+ }
+
+ /* GPRS block */
+ memcpy(req + pos, "\x03\x00", 2); pos += 2;
+
+ if (loc2 != -1) {
+ length = UnicodeLength(settings->Settings[loc2].DialUp) *2+1;
+ length += UnicodeLength(settings->Settings[loc2].IPAddress)*2+2;
+ length += UnicodeLength(settings->Settings[loc2].User) *2+2;
+ length += UnicodeLength(settings->Settings[loc2].Password) *2+2;
+ } else {
+ length = 7;
+ }
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_WAPMMSPROXY)) length+=2;
+ length += 7;
+ req[pos++] = length / 256;
+ req[pos++] = length % 256;
+
+ if (loc2 != -1) {
+ if (!settings->Settings[loc2].IsNormalAuthentication) {
+ req[pos] = 0x01;
+ }
+ pos++;
+ if (!settings->Settings[loc2].IsContinuous) {
+ req[pos] = 0x01;
+ }
+ pos++;
+ if (!settings->Settings[loc2].ManualLogin) {
+ req[pos] = 0x01;
+ }
+ pos++;
+
+ pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc2].DialUp, FALSE);
+ pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc2].IPAddress, TRUE);
+ pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc2].User, TRUE);
+ pos += NOKIA_SetUnicodeString(s, req + pos, settings->Settings[loc2].Password, TRUE);
+ } else {
+ pos += 10;
+ }
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_WAPMMSPROXY)) {
+ req[pos++] = 0x00;
+ req[pos++] = 0x00;
+
+ /* Proxy block */
+ req[pos++] = 0x06;
+ req[pos++] = 0x01;
+ if (UnicodeLength(settings->Proxy)!=0 ||
+ UnicodeLength(settings->Proxy2)!=0) {
+ req[pos++] = (UnicodeLength(settings->Proxy)+UnicodeLength(settings->Proxy2)+13)/256;
+ req[pos++] = (UnicodeLength(settings->Proxy)+UnicodeLength(settings->Proxy2)+13)%256;
+ } else {
+ req[pos++] = (UnicodeLength(settings->Proxy)+UnicodeLength(settings->Proxy2)+12)/256;
+ req[pos++] = (UnicodeLength(settings->Proxy)+UnicodeLength(settings->Proxy2)+12)%256;
+ }
+ req[pos++] = UnicodeLength(settings->Proxy);
+ req[pos++] = UnicodeLength(settings->Proxy2);
+ req[pos++] = settings->ProxyPort/256;
+ req[pos++] = settings->ProxyPort%256;
+ req[pos++] = settings->Proxy2Port/256;
+ req[pos++] = settings->Proxy2Port%256;
+ if (UnicodeLength(settings->Proxy)!=0) {
+ sprintf(req+pos,"%s",DecodeUnicodeString(settings->Proxy));
+ pos+=UnicodeLength(settings->Proxy);
+ }
+ if (UnicodeLength(settings->Proxy2)!=0) {
+ sprintf(req+pos,"%s",DecodeUnicodeString(settings->Proxy2));
+ pos+=UnicodeLength(settings->Proxy2);
+ }
+ if (UnicodeLength(settings->Proxy)!=0 ||
+ UnicodeLength(settings->Proxy2)!=0) {
+ req[pos++] = 0x00;
+ }
+ req[pos++] = 0x00; req[pos++] = 0x00;
+ req[pos++] = 0x07; /* unknown */
+ req[pos++] = 0x00; req[pos++] = 0x00;
+ req[pos++] = 0x80; /* unknown */
+ req[pos++] = 0x01; /* unknown */
+ req[pos++] = 0x05; /* unknown */
+ req[pos++] = 0x00; req[pos++] = 0x00;
+
+ /* Proxy data blocks */
+ for (i=0;i<4;i++) {
+ port = 8080;
+ Proxy = NULL;
+ if (i==0) {
+ port = settings->ProxyPort;
+ Proxy = settings->Proxy;
+ } else if (i==1) {
+ port = settings->Proxy2Port;
+ Proxy = settings->Proxy2;
+ }
+ req[pos++] = 0x08; req[pos++] = 0x00;
+ if (Proxy != NULL && UnicodeLength(Proxy)!=0) {
+ if (UnicodeLength(Proxy)%2 != 0) {
+ req[pos++] = (12 + (UnicodeLength(Proxy)+1)*2)/256;
+ req[pos++] = (12 + (UnicodeLength(Proxy)+1)*2)%256;
+ } else {
+ req[pos++] = (12 + UnicodeLength(Proxy)*2)/256;
+ req[pos++] = (12 + UnicodeLength(Proxy)*2)%256;
+ }
+ } else {
+ req[pos++] = 12/256;
+ req[pos++] = 12%256;
+ }
+ req[pos++] = i+1;
+ if (Proxy != NULL) {
+ req[pos++] = UnicodeLength(Proxy);
+ } else {
+ req[pos++] = 0;
+ }
+ req[pos++] = port/256;
+ req[pos++] = port%256;
+ req[pos++] = 0x00;
+
+ req[pos++] = 0x00;
+ req[pos++] = 0x01;
+
+ req[pos++] = 0x00;
+ if (Proxy != NULL && UnicodeLength(Proxy)!=0) {
+ CopyUnicodeString(req+pos,Proxy);
+ pos+=UnicodeLength(Proxy)*2;
+ if (UnicodeLength(Proxy)%2 != 0) {
+ req[pos++] = 0x00;
+ req[pos++] = 0x00;
+ }
+ }
+ }
+
+ req[pos++] = 0x09; req[pos++] = 0x00; req[pos++] = 0x00;
+ req[pos++] = 0x0C; req[pos++] = 0x02; req[pos++] = 0x00;
+ req[pos++] = 0x00; req[pos++] = 0x02; req[pos++] = 0x00;
+ req[pos++] = 0x00; req[pos++] = 0x00; req[pos++] = 0x00;
+ } else {
+ /* end of blocks ? */
+ memcpy(req + pos, "\x80\x00\x00\x0c", 4); pos += 4;
+ }
+
+ UnLock[4] = settings->Location-1;
+ smprintf(s, "Making Connection settings read-write\n");
+ error = GSM_WaitFor (s, UnLock, 5, 0x3f, s->Phone.Data.Priv.N6510.Timeout, ID_SetConnectSet);
+ if (error != ERR_NONE) return error;
+
+ switch (Type) {
+ case N6510_MMS_SETTINGS:
+ smprintf(s, "Setting MMS settings\n");
+ break;
+ case N6510_CHAT_SETTINGS:
+ smprintf(s, "Setting Chat settings\n");
+ break;
+ case N6510_WAP_SETTINGS:
+ smprintf(s, "Setting WAP settings\n");
+ break;
+ case N6510_SYNCML_SETTINGS:
+ smprintf(s, "Setting SyncML settings\n");
+ break;
+ }
+ error = GSM_WaitFor (s, req, pos, 0x3f, s->Phone.Data.Priv.N6510.Timeout, ID_SetConnectSet);
+ if (error != ERR_NONE) {
+ if (error == ERR_INSIDEPHONEMENU || error == ERR_INVALIDLOCATION) {
+ DCT3DCT4_DisableConnectionFunctions(s);
+ }
+ return error;
+ }
+
+ if (settings->ReadOnly) {
+ Lock[4] = settings->Location-1;
+ smprintf(s, "Making Connection settings readonly\n");
+ error = GSM_WaitFor (s, Lock, 5, 0x3f, s->Phone.Data.Priv.N6510.Timeout, ID_SetConnectSet);
+ if (error != ERR_NONE) return error;
+ }
+
+ error = DCT3DCT4_SetActiveConnectSet(s, settings);
+ if (error != ERR_NONE) return error;
+
+ return DCT3DCT4_DisableConnectionFunctions(s);
+}
+
+static GSM_Error N6510_SetWAPSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings)
+{
+ return N6510_SetConnectionSettings(s, settings, N6510_WAP_SETTINGS);
+}
+
+static GSM_Error N6510_SetMMSSettings(GSM_StateMachine *s, GSM_MultiWAPSettings *settings)
+{
+ return N6510_SetConnectionSettings(s, settings, N6510_MMS_SETTINGS);
+}
+
+static GSM_Error N6510_ReplyGetOriginalIMEI(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ if (msg->Buffer[7] == 0x00) {
+ smprintf(s, "No SIM card\n");
+ return ERR_NOSIM;
+ } else {
+ return NOKIA_ReplyGetPhoneString(msg, s);
+ }
+}
+
+static GSM_Error N6510_GetOriginalIMEI(GSM_StateMachine *s, char *value)
+{
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) return ERR_NOTSUPPORTED;
+
+ return NOKIA_GetPhoneString(s,"\x00\x07\x02\x01\x00\x01",6,0x42,value,ID_GetOriginalIMEI,14);
+}
+
+static GSM_Error N6510_ReplyGetSMSStatus(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ switch (msg->Buffer[3]) {
+ case 0x09:
+ switch (msg->Buffer[4]) {
+ case 0x00:
+ smprintf(s, "Max. in phone memory : %i\n",msg->Buffer[10]*256+msg->Buffer[11]);
+ smprintf(s, "Used in phone memory : %i\n",msg->Buffer[12]*256+msg->Buffer[13]);
+ smprintf(s, "Unread in phone memory : %i\n",msg->Buffer[14]*256+msg->Buffer[15]);
+ smprintf(s, "Max. in SIM : %i\n",msg->Buffer[22]*256+msg->Buffer[23]);
+ smprintf(s, "Used in SIM : %i\n",msg->Buffer[24]*256+msg->Buffer[25]);
+ smprintf(s, "Unread in SIM : %i\n",msg->Buffer[26]*256+msg->Buffer[27]);
+ Data->SMSStatus->PhoneSize = msg->Buffer[10]*256+msg->Buffer[11];
+ Data->SMSStatus->PhoneUsed = msg->Buffer[12]*256+msg->Buffer[13];
+ Data->SMSStatus->PhoneUnRead = msg->Buffer[14]*256+msg->Buffer[15];
+ Data->SMSStatus->SIMSize = msg->Buffer[22]*256+msg->Buffer[23];
+ Data->SMSStatus->SIMUsed = msg->Buffer[24]*256+msg->Buffer[25];
+ Data->SMSStatus->SIMUnRead = msg->Buffer[26]*256+msg->Buffer[27];
+ return ERR_NONE;
+ case 0x0f:
+ smprintf(s, "No PIN\n");
+ return ERR_SECURITYERROR;
+ default:
+ smprintf(s, "ERROR: unknown SMS status %i\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ case 0x1a:
+ smprintf(s, "Wait a moment. Phone is during power on and busy now\n");
+ return ERR_SECURITYERROR;
+ case 0xf0:
+ /* 01 |00 |00 |F0ð|01 |12 |00 |00 |00 */
+ smprintf(s, "Handling of this reply is not known, please help!\n");
+ return ERR_NOTIMPLEMENTED;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_GetSMSStatus(GSM_StateMachine *s, GSM_SMSMemoryStatus *status)
+{
+ GSM_Error error;
+ GSM_Phone_N6510Data *Priv = &s->Phone.Data.Priv.N6510;
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x08, 0x00, 0x00};
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) return ERR_NOTSUPPORTED;
+
+ s->Phone.Data.SMSStatus=status;
+ smprintf(s, "Getting SMS status\n");
+ error = GSM_WaitFor (s, req, 6, 0x14, 20, ID_GetSMSStatus);
+ if (error != ERR_NONE) return error;
+
+ /* DCT4 family doesn't show in frame with SMS status info
+ * about Templates. We get separately info about this SMS folder.
+ */
+ error = N6510_GetSMSFolderStatus(s, 0x06);
+ if (error != ERR_NONE) return error;
+ status->TemplatesUsed = Priv->LastSMSFolder.Number;
+
+ return error;
+}
+
+static GSM_Error N6510_ReplyDeleteSMSMessage(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x05:
+ smprintf(s, "SMS deleted OK\n");
+ return ERR_NONE;
+ case 0x06:
+ switch (msg->Buffer[4]) {
+ case 0x02:
+ smprintf(s, "Invalid location\n");
+ return ERR_INVALIDLOCATION;
+ default:
+ smprintf(s, "Unknown error: %02x\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_DeleteSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms)
+{
+ unsigned char folderid;
+ unsigned int location;
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x04,
+ 0x01, /* 0x01=SM, 0x02=ME */
+ 0x00, /* FolderID */
+ 0x00, 0x02, /* Location */
+ 0x0F, 0x55};
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SMS_FILES)) return ERR_NOTSUPPORTED;
+ }
+
+ N6510_GetSMSLocation(s, sms, &folderid, &location);
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ switch (folderid) {
+ case 0x01: req[5] = 0x01; break; /* SIM */
+ default : req[5] = folderid; req[4] = 0x02; break; /* ME folders */
+ }
+ } else {
+ switch (folderid) {
+ case 0x01: req[5] = 0x02; break; /* INBOX SIM */
+ case 0x02: req[5] = 0x03; break; /* OUTBOX SIM */
+ default : req[5] = folderid - 1; req[4] = 0x02; break; /* ME folders */
+ }
+ }
+ req[6]=location / 256;
+ req[7]=location % 256;
+
+ smprintf(s, "Deleting sms\n");
+ return GSM_WaitFor (s, req, 10, 0x14, s->Phone.Data.Priv.N6510.Timeout, ID_DeleteSMSMessage);
+}
+
+static GSM_Error N6510_ReplySendSMSMessage(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[8]) {
+ case 0x00:
+ smprintf(s, "SMS sent OK, TPMR for sent sms is %d\n",msg->Buffer[10]);
+ if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s,0,msg->Buffer[10], s->User.SendSMSStatusUserData);
+ return ERR_NONE;
+ default:
+ smprintf(s, "SMS not sent OK, error code probably %i\n",msg->Buffer[8]);
+ if (s->User.SendSMSStatus!=NULL) s->User.SendSMSStatus(s,msg->Buffer[8],msg->Buffer[10], s->User.SendSMSStatusUserData);
+ return ERR_NONE;
+ }
+}
+
+static GSM_Error N6510_SendSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms)
+{
+ int length = 11;
+ GSM_Error error;
+ GSM_SMSMessageLayout Layout;
+ unsigned char req [300] = {
+ N6110_FRAME_HEADER, 0x02, 0x00, 0x00, 0x00, 0x55, 0x55};
+
+ if (sms->PDU == SMS_Deliver) sms->PDU = SMS_Submit;
+ memset(req+9,0x00,sizeof(req) - 9);
+ error=N6510_EncodeSMSFrame(s, sms, req + 9, &Layout, &length);
+ if (error != ERR_NONE) return error;
+
+ smprintf(s, "Sending sms\n");
+ return s->Protocol.Functions->WriteMessage(s, req, length + 9, 0x02);
+}
+
+static GSM_Error N6510_ReplyGetSecurityStatus(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ if (msg->Buffer[3] == 0xf0) {
+ return ERR_NOTSUPPORTED;
+ }
+
+ smprintf(s, "Security Code status received: ");
+ switch (msg->Buffer[4]) {
+ case 0x01 : smprintf(s, "waiting for Security Code.\n"); *Data->SecurityStatus = SEC_SecurityCode; break;
+ case 0x07 :
+ case 0x02 : smprintf(s, "waiting for PIN.\n"); *Data->SecurityStatus = SEC_Pin; break;
+ case 0x03 : smprintf(s, "waiting for PUK.\n"); *Data->SecurityStatus = SEC_Puk; break;
+ case 0x05 : smprintf(s, "PIN ok, SIM ok\n"); *Data->SecurityStatus = SEC_None; break;
+ case 0x06 : smprintf(s, "No input status\n"); *Data->SecurityStatus = SEC_None; break;
+ case 0x16 : smprintf(s, "No SIM card\n"); return ERR_NOSIM;
+ case 0x1A : smprintf(s, "SIM card rejected!\n"); *Data->SecurityStatus = SEC_None; break;
+ default : smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_GetSecurityStatus(GSM_StateMachine *s, GSM_SecurityCodeType *Status)
+{
+ unsigned char req[5] = {N6110_FRAME_HEADER, 0x11, 0x00};
+
+ s->Phone.Data.SecurityStatus=Status;
+ smprintf(s, "Getting security code status\n");
+ return GSM_WaitFor (s, req, 5, 0x08, 2, ID_GetSecurityStatus);
+}
+
+static GSM_Error N6510_ReplyEnterSecurityCode(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x08:
+ smprintf(s, "Security code OK\n");
+ return ERR_NONE;
+ case 0x09:
+ switch (msg->Buffer[4]) {
+ case 0x06:
+ smprintf(s, "Wrong PIN\n");
+ return ERR_SECURITYERROR;
+ case 0x09:
+ smprintf(s, "Wrong PUK\n");
+ return ERR_SECURITYERROR;
+ default:
+ smprintf(s, "ERROR: unknown security code status %i\n",msg->Buffer[4]);
+ }
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_EnterSecurityCode(GSM_StateMachine *s, GSM_SecurityCode *Code)
+{
+ int len = 0;
+ unsigned char req[15] = {N6110_FRAME_HEADER, 0x07,
+ 0x00}; /* Code type */
+
+ switch (Code->Type) {
+ case SEC_Pin : req[4] = 0x02; break;
+ case SEC_Puk : req[4] = 0x03; break;/* FIXME */
+ default : return ERR_NOTSUPPORTED;
+ }
+
+ len = strlen(Code->Code);
+ memcpy(req+5,Code->Code,len);
+ req[5+len]=0x00;
+
+ smprintf(s, "Entering security code\n");
+ return GSM_WaitFor (s, req, 6+len, 0x08, s->Phone.Data.Priv.N6510.Timeout, ID_EnterSecurityCode);
+}
+
+static GSM_Error N6510_ReplySaveSMSMessage(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ unsigned char folder;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ switch (msg->Buffer[3]) {
+ case 0x01:
+ switch (msg->Buffer[4]) {
+ case 0x00:
+ smprintf(s, "Done OK\n");
+ break;
+ case 0x02:
+ smprintf(s, "Incorrect location\n");
+ return ERR_INVALIDLOCATION;
+ case 0x03:
+ smprintf(s, "Memory full (for example no empty space in SIM)\n");
+ return ERR_FULL;
+ case 0x05:
+ smprintf(s, "Incorrect folder\n");
+ return ERR_INVALIDLOCATION;
+ default:
+ smprintf(s, "ERROR: unknown reply on saving message %i\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+
+ smprintf(s, "Folder info: %i %i\n",msg->Buffer[5],msg->Buffer[8]);
+ Data->SaveSMSMessage->Memory = MEM_ME;
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ folder = msg->Buffer[8];
+ } else {
+ folder = msg->Buffer[8] + 1;
+ /* inbox,outbox */
+ if (msg->Buffer[8] == 0x02 || msg->Buffer[8] == 0x03) {
+ if (msg->Buffer[5] == 0x01) {
+ folder = msg->Buffer[8] - 1;
+ Data->SaveSMSMessage->Memory = MEM_SM;
+ }
+ }
+ }
+ N6510_SetSMSLocation(s, Data->SaveSMSMessage,folder,msg->Buffer[6]*256+msg->Buffer[7]);
+ smprintf(s, "Saved in folder %i at location %i\n",folder, msg->Buffer[6]*256+msg->Buffer[7]);
+ Data->SaveSMSMessage->Folder = folder;
+ return ERR_NONE;
+ case 0x17:
+ smprintf(s, "SMS name changed\n");
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_PrivSetSMSMessage(GSM_StateMachine *s, GSM_SMSMessage *sms)
+{
+ int length = 11;
+ unsigned int location;
+ unsigned char folderid, folder;
+ GSM_SMSMessageLayout Layout;
+ GSM_Error error;
+ unsigned char req [300] = {
+ N6110_FRAME_HEADER, 0x00,
+ 0x01, /* 1 = SIM, 2 = ME */
+ 0x02, /* Folder */
+ 0x00, 0x01, /* Location */
+ 0x01}; /* SMS state */
+ unsigned char NameReq[200] = {
+ N6110_FRAME_HEADER, 0x16,
+ 0x01, /* 1 = SIM, 2 = ME */
+ 0x02, /* Folder */
+ 0x00, 0x01}; /* Location */
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SMS_FILES)) return ERR_NOTSUPPORTED;
+ }
+
+ N6510_GetSMSLocation(s, sms, &folderid, &location);
+ if (folderid == 0x99) return ERR_INVALIDLOCATION;
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ switch (folderid) {
+ case 0x02: req[4] = 0x02; req[5] = 0x02; break; /* inbox */
+ /* sms saved to sent items make problems later during reading */
+ /* case 0x03: req[4] = 0x02; req[5] = 0x03; break; //sent items */
+ default : return ERR_NOTSUPPORTED; /* at least 6111 doesn't support saving to other */
+ }
+ } else {
+ switch (folderid) {
+ case 0x01: req[5] = 0x02; break; /* INBOX SIM */
+ case 0x02: req[5] = 0x03; break; /* OUTBOX SIM */
+ default : req[5] = folderid - 1; req[4] = 0x02; break; /* ME folders */
+ }
+ }
+ req[6]=location / 256;
+ req[7]=location % 256;
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ switch (sms->PDU) {
+ case SMS_Status_Report: /* this is SMS submit with delivery report request */
+ case SMS_Submit:
+ break;
+ case SMS_Deliver:
+ /* Sent items */
+ if (folderid == 0x03) sms->PDU = SMS_Submit;
+ break;
+ default:
+ return ERR_UNKNOWN;
+ }
+ } else {
+ switch (sms->PDU) {
+ case SMS_Status_Report: /* this is SMS submit with delivery report request */
+ case SMS_Submit:
+ /* Inbox */
+ if (folderid == 0x01 || folderid == 0x03) sms->PDU = SMS_Deliver;
+ break;
+ case SMS_Deliver:
+ /* SIM Outbox */
+ if (folderid == 0x02) sms->PDU = SMS_Submit;
+ break;
+ default:
+ return ERR_UNKNOWN;
+ }
+ if (sms->PDU == SMS_Deliver) {
+ switch (sms->State) {
+ case SMS_Sent : /* We use GSM_Read, because phone return error */
+ case SMS_Read : req[8] = 0x01; break;
+ case SMS_UnSent : /* We use GSM_UnRead, because phone return error */
+ case SMS_UnRead : req[8] = 0x03; break;
+ }
+ } else {
+ switch (sms->State) {
+ case SMS_Sent : /* We use GSM_Sent, because phone change folder */
+ case SMS_Read : req[8] = 0x05; break;
+ case SMS_UnSent : /* We use GSM_UnSent, because phone change folder */
+ case SMS_UnRead : req[8] = 0x07; break;
+ }
+ }
+ }
+ memset(req+9,0x00,sizeof(req) - 9);
+ error=N6510_EncodeSMSFrame(s, sms, req + 9, &Layout, &length);
+ if (error != ERR_NONE) return error;
+
+ s->Phone.Data.SaveSMSMessage=sms;
+ smprintf(s, "Saving sms\n");
+ error=GSM_WaitFor (s, req, length+9, 0x14, s->Phone.Data.Priv.N6510.Timeout, ID_SaveSMSMessage);
+ if (error != ERR_NONE) return error;
+
+ /* no adding to SIM SMS */
+ if (UnicodeLength(sms->Name)==0 || sms->Folder < 3) return ERR_NONE;
+
+ folder = sms->Folder;
+ sms->Folder = 0;
+ N6510_GetSMSLocation(s, sms, &folderid, &location);
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ switch (folderid) {
+ case 0x03: NameReq[4] = 0x02; NameReq[5] = 0x02; break; /* sent items */
+ case 0x02: NameReq[4] = 0x02; NameReq[5] = 0x03; break; /* inbox */
+ default : return ERR_NOTSUPPORTED; /* at least 6111 doesn't support saving to other */
+ }
+ } else {
+ switch (folderid) {
+ case 0x01: NameReq[5] = 0x02; break; /* INBOX SIM */
+ case 0x02: NameReq[5] = 0x03; break; /* OUTBOX SIM */
+ default : NameReq[5] = folderid - 1; NameReq[4] = 0x02; break; /* ME folders */
+ }
+ }
+ NameReq[6]=location / 256;
+ NameReq[7]=location % 256;
+ length = 8;
+ CopyUnicodeString(NameReq+length, sms->Name);
+ length = length+UnicodeLength(sms->Name)*2;
+ NameReq[length++] = 0;
+ NameReq[length++] = 0;
+ error=GSM_WaitFor (s, NameReq, length, 0x14, s->Phone.Data.Priv.N6510.Timeout, ID_SaveSMSMessage);
+ sms->Folder = folder;
+ return error;
+}
+
+static GSM_Error N6510_SetSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
+{
+ unsigned int location;
+ unsigned char folderid;
+
+ N6510_GetSMSLocation(s, sms, &folderid, &location);
+ if (location == 0) return ERR_INVALIDLOCATION;
+ return N6510_PrivSetSMSMessage(s, sms);
+}
+
+static GSM_Error N6510_AddSMS(GSM_StateMachine *s, GSM_SMSMessage *sms)
+{
+ unsigned int location;
+ unsigned char folderid;
+
+ N6510_GetSMSLocation(s, sms, &folderid, &location);
+ location = 0;
+ N6510_SetSMSLocation(s, sms, folderid, location);
+ return N6510_PrivSetSMSMessage(s, sms);
+}
+
+static GSM_Error N6510_ReplyGetDateTime(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "Date & time received\n");
+ if (msg->Buffer[4]==0x01) {
+ NOKIA_DecodeDateTime(s, msg->Buffer+10, s->Phone.Data.DateTime, TRUE, FALSE);
+ return ERR_NONE;
+ }
+ smprintf(s, "Not set in phone\n");
+ return ERR_EMPTY;
+}
+
+static GSM_Error N6510_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x0A, 0x00, 0x00};
+
+ s->Phone.Data.DateTime=date_time;
+ smprintf(s, "Getting date & time\n");
+ return GSM_WaitFor (s, req, 6, 0x19, s->Phone.Data.Priv.N6510.Timeout, ID_GetDateTime);
+}
+
+static GSM_Error N6510_ReplySetDateTime(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Date & time set\n");
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_SetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER,
+ 0x01, 0x00, 0x01, 0x01, 0x0c, 0x01, 0x03,
+ 0x00, 0x00, /* Year */
+ 0x08, 0x01, /* Month & Day */
+ 0x15, 0x1f, /* Hours & Minutes */
+ 0x2b, /* Second ? */
+ 0x00};
+
+ NOKIA_EncodeDateTime(s, req+10, date_time);
+ req[16] = date_time->Second;
+ smprintf(s, "Setting date & time\n");
+ return GSM_WaitFor (s, req, 18, 0x19, s->Phone.Data.Priv.N6510.Timeout, ID_SetDateTime);
+}
+
+static GSM_Error N6510_ReplyGetManufactureMonth(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ if (msg->Buffer[7] == 0x00) {
+ smprintf(s, "No SIM card\n");
+ return ERR_NOSIM;
+ } else {
+ sprintf(s->Phone.Data.PhoneString,"%02i/%04i",msg->Buffer[13],msg->Buffer[14]*256+msg->Buffer[15]);
+ return ERR_NONE;
+ }
+}
+
+static GSM_Error N6510_GetManufactureMonth(GSM_StateMachine *s, char *value)
+{
+ unsigned char req[6] = {0x00, 0x05, 0x02, 0x01, 0x00, 0x02};
+/* unsigned char req[6] = {0x00, 0x03, 0x04, 0x0B, 0x01, 0x00}; */
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) return ERR_NOTSUPPORTED;
+
+ s->Phone.Data.PhoneString=value;
+ smprintf(s, "Getting manufacture month\n");
+ return GSM_WaitFor (s, req, 6, 0x42, 2, ID_GetManufactureMonth);
+/* return GSM_WaitFor (s, req, 6, 0x1B, 2, ID_GetManufactureMonth); */
+}
+
+static GSM_Error N6510_ReplyGetAlarm(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ switch(msg->Buffer[3]) {
+ case 0x1A:
+ smprintf(s, " Alarm: %02d:%02d\n", msg->Buffer[14], msg->Buffer[15]);
+ Data->Alarm->Repeating = TRUE;
+ Data->Alarm->Text[0] = 0;
+ Data->Alarm->Text[1] = 0;
+ Data->Alarm->DateTime.Hour = msg->Buffer[14];
+ Data->Alarm->DateTime.Minute = msg->Buffer[15];
+ Data->Alarm->DateTime.Second = 0;
+ return ERR_NONE;
+ case 0x20:
+ smprintf(s, "Alarm state received\n");
+ if (msg->Buffer[37] == 0x01) {
+ smprintf(s, " Not set in phone\n");
+ return ERR_EMPTY;
+ }
+ smprintf(s, "Enabled\n");
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_GetAlarm(GSM_StateMachine *s, GSM_Alarm *Alarm)
+{
+ unsigned char StateReq[] = {N6110_FRAME_HEADER, 0x1f, 0x01, 0x00};
+ unsigned char GetReq [] = {N6110_FRAME_HEADER, 0x19, 0x00, 0x02};
+ GSM_Error error;
+
+ if (Alarm->Location != 1) return ERR_NOTSUPPORTED;
+
+ s->Phone.Data.Alarm=Alarm;
+ smprintf(s, "Getting alarm state\n");
+ error = GSM_WaitFor (s, StateReq, 6, 0x19, s->Phone.Data.Priv.N6510.Timeout, ID_GetAlarm);
+ if (error != ERR_NONE) return error;
+
+ smprintf(s, "Getting alarm\n");
+ return GSM_WaitFor (s, GetReq, 6, 0x19, s->Phone.Data.Priv.N6510.Timeout, ID_GetAlarm);
+}
+
+static GSM_Error N6510_ReplySetAlarm(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Alarm set\n");
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_SetAlarm(GSM_StateMachine *s, GSM_Alarm *Alarm)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER,
+ 0x11, 0x00, 0x01, 0x01, 0x0c, 0x02,
+ 0x01, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, /* Hours, Minutes */
+ 0x00, 0x00, 0x00 };
+
+ if (Alarm->Location != 1) return ERR_NOTSUPPORTED;
+
+ req[14] = Alarm->DateTime.Hour;
+ req[15] = Alarm->DateTime.Minute;
+
+ smprintf(s, "Setting alarm\n");
+ return GSM_WaitFor (s, req, 19, 0x19, s->Phone.Data.Priv.N6510.Timeout, ID_SetAlarm);
+}
+
+static GSM_Error N6510_ReplyGetRingtonesInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int tmp,i;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "Ringtones info received\n");
+ memset(Data->RingtonesInfo,0,sizeof(GSM_AllRingtonesInfo));
+ if (msg->Buffer[4] * 256 + msg->Buffer[5] == 0x00) return ERR_EMPTY;
+ Data->RingtonesInfo->Number = msg->Buffer[4] * 256 + msg->Buffer[5];
+ /* allocate array of ringtones based on number */
+ Data->RingtonesInfo->Ringtone = calloc(Data->RingtonesInfo->Number, sizeof(GSM_RingtoneInfo));
+ tmp = 6;
+ for (i=0;i<Data->RingtonesInfo->Number;i++) {
+ Data->RingtonesInfo->Ringtone[i].Group = msg->Buffer[tmp+4];
+ Data->RingtonesInfo->Ringtone[i].ID = msg->Buffer[tmp+2] * 256 + msg->Buffer[tmp+3];
+ memcpy(Data->RingtonesInfo->Ringtone[i].Name,msg->Buffer+tmp+8,(msg->Buffer[tmp+6]*256+msg->Buffer[tmp+7])*2);
+ smprintf(s, "%5i (%5i). \"%s\"\n",
+ Data->RingtonesInfo->Ringtone[i].ID,
+ Data->RingtonesInfo->Ringtone[i].Group,
+ DecodeUnicodeString(Data->RingtonesInfo->Ringtone[i].Name));
+ tmp = tmp + (msg->Buffer[tmp]*256+msg->Buffer[tmp+1]);
+ }
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_PrivGetRingtonesInfo(GSM_StateMachine *s, GSM_AllRingtonesInfo *Info, gboolean AllRingtones)
+{
+ GSM_Error error;
+ unsigned char UserReq[8] = {N7110_FRAME_HEADER, 0x07, 0x00, 0x00, 0x00, 0x02};
+/* unsigned char All_Req[9] = {N7110_FRAME_HEADER, 0x07, 0x00, 0x00, 0xFE, 0x00, 0x7D}; */
+ unsigned char All_Req[8] = {N7110_FRAME_HEADER, 0x07, 0x00, 0x00, 0x00, 0x00};
+
+ s->Phone.Data.RingtonesInfo=Info;
+ smprintf(s, "Getting binary ringtones ID\n");
+ if (AllRingtones) {
+/* error = GSM_WaitFor (s, All_Req, 9, 0x1f, s->Phone.Data.Priv.N6510.Timeout, ID_GetRingtonesInfo); */
+ error = GSM_WaitFor (s, All_Req, 8, 0x1f, s->Phone.Data.Priv.N6510.Timeout, ID_GetRingtonesInfo);
+ if (error == ERR_EMPTY && Info->Number == 0) return ERR_NOTSUPPORTED;
+ return error;
+ } else {
+ error = GSM_WaitFor (s, UserReq, 8, 0x1f, s->Phone.Data.Priv.N6510.Timeout, ID_GetRingtonesInfo);
+ if (error == ERR_EMPTY && Info->Number == 0) return ERR_NOTSUPPORTED;
+ return error;
+ }
+}
+
+static GSM_Error N6510_GetRingtonesInfo(GSM_StateMachine *s, GSM_AllRingtonesInfo *Info)
+{
+ return N6510_PrivGetRingtonesInfo(s, Info, TRUE);
+}
+
+static GSM_Error N6510_ReplyGetRingtone(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ size_t tmp,i;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "Ringtone received\n");
+ memcpy(Data->Ringtone->Name,msg->Buffer+8,msg->Buffer[7]*2);
+ Data->Ringtone->Name[msg->Buffer[7]*2]=0;
+ Data->Ringtone->Name[msg->Buffer[7]*2+1]=0;
+ smprintf(s, "Name \"%s\"\n",DecodeUnicodeString(Data->Ringtone->Name));
+ if (msg->Buffer[msg->Buffer[7]*2+10] == 'M' &&
+ msg->Buffer[msg->Buffer[7]*2+11] == 'T' &&
+ msg->Buffer[msg->Buffer[7]*2+12] == 'h' &&
+ msg->Buffer[msg->Buffer[7]*2+13] == 'd') {
+ smprintf(s,"MIDI\n");
+ tmp = msg->Buffer[7]*2+10;
+ i = msg->Length - 2; /* ?????? */
+ Data->Ringtone->Format = RING_MIDI;
+ } else {
+ /* Looking for end */
+ i=8+msg->Buffer[7]*2+3;
+ tmp = i;
+ while (TRUE) {
+ if (msg->Buffer[i]==0x07 && msg->Buffer[i+1]==0x0b) {
+ i=i+2; break;
+ }
+ i++;
+ if (i==msg->Length) return ERR_EMPTY;
+ }
+ }
+ /* Copying frame */
+ memcpy(Data->Ringtone->NokiaBinary.Frame,msg->Buffer+tmp,i-tmp);
+ Data->Ringtone->NokiaBinary.Length=i-tmp;
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_GetRingtone(GSM_StateMachine *s, GSM_Ringtone *Ringtone, gboolean PhoneRingtone)
+{
+ GSM_AllRingtonesInfo Info = {0, NULL};
+ GSM_Error error;
+ unsigned char req2[6] = {N7110_FRAME_HEADER, 0x12,
+ 0x00, 0xe7}; /* Location */
+
+ if (Ringtone->Format == 0x00) Ringtone->Format = RING_NOKIABINARY;
+
+ switch (Ringtone->Format) {
+ case RING_NOTETONE:
+ /* In the future get binary and convert */
+ return ERR_NOTSUPPORTED;
+ case RING_NOKIABINARY:
+ s->Phone.Data.Ringtone = Ringtone;
+ Info.Number = 0;
+ error=N6510_PrivGetRingtonesInfo(s, &Info, PhoneRingtone);
+ if (error != ERR_NONE) return error;
+ if (Ringtone->Location > Info.Number) return ERR_INVALIDLOCATION;
+ req2[4] = Info.Ringtone[Ringtone->Location-1].ID / 256;
+ req2[5] = Info.Ringtone[Ringtone->Location-1].ID % 256;
+ smprintf(s, "Getting binary ringtone\n");
+ error = GSM_WaitFor (s, req2, 6, 0x1f, s->Phone.Data.Priv.N6510.Timeout, ID_GetRingtone);
+ if (Info.Ringtone) {
+ free(Info.Ringtone);
+ Info.Ringtone=NULL;
+ }
+ return error;
+ case RING_MIDI:
+ case RING_MMF:
+ return ERR_NOTSUPPORTED;
+ }
+ return ERR_NOTSUPPORTED;
+}
+
+static GSM_Error N6510_PlayTone(GSM_StateMachine *s, int Herz, unsigned char Volume, gboolean start)
+{
+ GSM_Error error;
+ unsigned char reqStart[] = {
+ 0x00,0x06,0x01,0x00,0x07,0x00 };
+ unsigned char reqPlay[] = {
+ 0x00,0x06,0x01,0x14,0x05,0x04,
+ 0x00,0x00,0x00,0x03,0x03,0x08,
+ 0x00,0x00,0x00,0x01,0x00,0x00,
+ 0x03,0x08,0x01,0x00,
+ 0x07,0xd0, /*Frequency */
+ 0x00,0x00,0x03,0x08,0x02,0x00,0x00,
+ 0x05, /*Volume */
+ 0x00,0x00};
+ unsigned char reqOff[] = {
+ 0x00,0x06,0x01,0x14,0x05,0x05,
+ 0x00,0x00,0x00,0x01,0x03,0x08,
+ 0x05,0x00,0x00,0x08,0x00,0x00};
+/* unsigned char reqOff2[] = { */
+/* 0x00,0x06,0x01,0x14,0x05,0x04, */
+/* 0x00,0x00,0x00,0x01,0x03,0x08, */
+/* 0x00,0x00,0x00,0x00,0x00,0x00}; */
+
+ if (start) {
+ smprintf(s, "Enabling sound - part 1\n");
+ error=GSM_WaitFor (s, reqStart, 6, 0x0b, s->Phone.Data.Priv.N6510.Timeout, ID_PlayTone);
+ if (error!=ERR_NONE) return error;
+ smprintf(s, "Enabling sound - part 2 (disabling sound command)\n");
+ error=GSM_WaitFor (s, reqOff, 18, 0x0b, s->Phone.Data.Priv.N6510.Timeout, ID_PlayTone);
+ if (error!=ERR_NONE) return error;
+ }
+
+ /* For Herz==255*255 we have silent */
+ if (Herz!=255*255) {
+ reqPlay[23] = Herz%256;
+ reqPlay[22] = Herz/256;
+ reqPlay[31] = Volume;
+ smprintf(s, "Playing sound\n");
+ return GSM_WaitFor (s, reqPlay, 34, 0x0b, s->Phone.Data.Priv.N6510.Timeout, ID_PlayTone);
+ } else {
+ reqPlay[23] = 0;
+ reqPlay[22] = 0;
+ reqPlay[31] = 0;
+ smprintf(s, "Playing silent sound\n");
+ return GSM_WaitFor (s, reqPlay, 34, 0x0b, s->Phone.Data.Priv.N6510.Timeout, ID_PlayTone);
+
+/* smprintf(s, "Disabling sound - part 1\n"); */
+/* error=GSM_WaitFor (s, reqOff, 18, 0x0b, s->Phone.Data.Priv.N6510.Timeout, ID_PlayTone); */
+/* if (error!=ERR_NONE) return error; */
+/* smprintf(s, "Disabling sound - part 2\n"); */
+/* return GSM_WaitFor (s, reqOff2, 18, 0x0b, s->Phone.Data.Priv.N6510.Timeout, ID_PlayTone); */
+ }
+}
+
+static GSM_Error N6510_ReplyGetPPM(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+ size_t pos = 6,len;
+
+ smprintf(s, "Received phone info\n");
+
+ while(pos < msg->Length) {
+ if (msg->Buffer[pos] == 0x55 && msg->Buffer[pos+1] == 0x55) {
+ while(1) {
+ if (msg->Buffer[pos] != 0x55) break;
+ pos++;
+ }
+ }
+ len = pos;
+ while(len < msg->Length) {
+ if (msg->Buffer[len] == 0x00 && msg->Buffer[len+1] == 0x00) break;
+ len++;
+ }
+ while(len < msg->Length) {
+ if (msg->Buffer[len] != 0x00) break;
+ len++;
+ }
+ len = len-pos;
+ smprintf(s, "Block with ID %02x",msg->Buffer[pos]);
+#ifdef DEBUG
+ if (s->di.dl == DL_TEXTALL || s->di.dl == DL_TEXTALLDATE) DumpMessage(&s->di, msg->Buffer+pos, len);
+#endif
+ switch (msg->Buffer[pos]) {
+ case 0x49:
+ smprintf(s, "hardware version\n");
+ break;
+ case 0x58:
+ pos += 3;
+ while (msg->Buffer[pos] != 0x00) pos++;
+ Data->PhoneString[0] = msg->Buffer[pos - 1];
+ Data->PhoneString[1] = 0x00;
+ smprintf(s, "PPM %s\n",Data->PhoneString);
+ return ERR_NONE;
+ default:
+ break;
+ }
+ pos += len;
+ }
+ return ERR_NOTSUPPORTED;
+}
+
+static GSM_Error N6510_GetPPM(GSM_StateMachine *s,char *value)
+{
+/* unsigned char req[6] = {N6110_FRAME_HEADER, 0x07, 0x01, 0xff}; */
+ unsigned char req[6] = {N6110_FRAME_HEADER, 0x07, 0x01, 0x00};
+
+ s->Phone.Data.PhoneString=value;
+ smprintf(s, "Getting PPM\n");
+ return GSM_WaitFor (s, req, 6, 0x1b, 3, ID_GetPPM);
+}
+
+static GSM_Error N6510_GetSpeedDial(GSM_StateMachine *s, GSM_SpeedDial *SpeedDial)
+{
+ GSM_MemoryEntry pbk;
+ GSM_Error error;
+
+ pbk.MemoryType = (GSM_MemoryType)MEM7110_SP;
+ pbk.Location = SpeedDial->Location;
+ SpeedDial->MemoryLocation = 0;
+ s->Phone.Data.SpeedDial = SpeedDial;
+
+ smprintf(s, "Getting speed dial\n");
+ error=N6510_GetMemory(s,&pbk);
+ switch (error) {
+ case ERR_NOTSUPPORTED:
+ smprintf(s, "No speed dials set in phone\n");
+ return ERR_EMPTY;
+ case ERR_NONE:
+ if (SpeedDial->MemoryLocation == 0) {
+ smprintf(s, "Speed dial not assigned or error in firmware\n");
+ return ERR_EMPTY;
+ }
+ return ERR_NONE;
+ default:
+ return error;
+ }
+}
+
+static GSM_Error N6510_ReplyGetProfile(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ unsigned char *blockstart;
+ int i,j;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ switch (msg->Buffer[3]) {
+ case 0x02:
+ blockstart = msg->Buffer + 7;
+ for (i = 0; i < 11; i++) {
+ smprintf(s, "Profile feature %02x ",blockstart[1]);
+#ifdef DEBUG
+ if (s->di.dl == DL_TEXTALL || s->di.dl == DL_TEXTALLDATE) DumpMessage(&s->di, blockstart, blockstart[0]);
+#endif
+
+ switch (blockstart[1]) {
+ case 0x03:
+ smprintf(s, "Ringtone ID\n");
+ Data->Profile->FeatureID [Data->Profile->FeaturesNumber] = Profile_RingtoneID;
+ Data->Profile->FeatureValue [Data->Profile->FeaturesNumber] = blockstart[7];
+ if (blockstart[7] == 0x00) {
+ Data->Profile->FeatureValue[Data->Profile->FeaturesNumber] = blockstart[10];
+ }
+ Data->Profile->FeaturesNumber++;
+ break;
+ case 0x05: /* SMS tone */
+ j = Data->Profile->FeaturesNumber;
+ NOKIA_FindFeatureValue(s, Profile71_65,blockstart[1],blockstart[7],Data,FALSE);
+ if (j == Data->Profile->FeaturesNumber) {
+ Data->Profile->FeatureID [Data->Profile->FeaturesNumber] = Profile_MessageTone;
+ Data->Profile->FeatureValue [Data->Profile->FeaturesNumber] = PROFILE_MESSAGE_PERSONAL;
+ Data->Profile->FeaturesNumber++;
+ Data->Profile->FeatureID [Data->Profile->FeaturesNumber] = Profile_MessageToneID;
+ Data->Profile->FeatureValue [Data->Profile->FeaturesNumber] = blockstart[7];
+ Data->Profile->FeaturesNumber++;
+ }
+ break;
+ case 0x08: /* Caller groups */
+ NOKIA_FindFeatureValue(s, Profile71_65,blockstart[1],blockstart[7],Data,TRUE);
+ break;
+ case 0x0c :
+ CopyUnicodeString(Data->Profile->Name,blockstart + 7);
+ smprintf(s, "profile Name: \"%s\"\n", DecodeUnicodeString(Data->Profile->Name));
+ Data->Profile->DefaultName = FALSE;
+ break;
+ default:
+ NOKIA_FindFeatureValue(s, Profile71_65,blockstart[1],blockstart[7],Data,FALSE);
+ }
+ blockstart = blockstart + blockstart[0];
+ }
+ return ERR_NONE;
+ case 0x06:
+ Data->Profile->Active = FALSE;
+ if (Data->Profile->Location == msg->Buffer[5]) Data->Profile->Active = TRUE;
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_GetProfile(GSM_StateMachine *s, GSM_Profile *Profile)
+{
+ unsigned char req[150] = {N6110_FRAME_HEADER, 0x01, 0x01, 0x0C, 0x01};
+ unsigned char reqActive[] = {N6110_FRAME_HEADER, 0x05};
+ int i, length = 7;
+ GSM_Error error;
+
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PROFILES)) return ERR_NOTSUPPORTED;
+
+/* if (!strcmp(s->Phone.Data.ModelInfo->model,"3510")) { */
+/* if (s->Phone.Data.VerNum>3.37) return ERR_NOTSUPPORTED; */
+/* if (!strcmp(s->Phone.Data.ModelInfo->model,"6230")) { */
+/* if (!strcmp(s->Phone.Data.ModelInfo->model,"6220")) { */
+/* if (!strcmp(s->Phone.Data.ModelInfo->model,"5140")) { */
+/* if (!strcmp(s->Phone.Data.ModelInfo->model,"6230i")) { */
+/* if (!strcmp(s->Phone.Data.ModelInfo->model,"6020")) { */
+
+ if (Profile->Location>5) return ERR_INVALIDLOCATION;
+
+ for (i = 0; i < 0x0a; i++) {
+ req[length++] = 0x04;
+ req[length++] = Profile->Location;
+ req[length++] = i;
+ req[length++] = 0x01;
+ }
+
+ req[length++] = 0x04;
+ req[length++] = Profile->Location;
+ req[length++] = 0x0c;
+ req[length++] = 0x01;
+
+ req[length++] = 0x04;
+
+ Profile->CarKitProfile = FALSE;
+ Profile->HeadSetProfile = FALSE;
+
+ Profile->FeaturesNumber = 0;
+
+ s->Phone.Data.Profile=Profile;
+ smprintf(s, "Getting profile\n");
+ error = GSM_WaitFor (s, req, length, 0x39, s->Phone.Data.Priv.N6510.Timeout, ID_GetProfile);
+ if (error != ERR_NONE) return error;
+
+ smprintf(s, "Checking, which profile is active\n");
+ return GSM_WaitFor (s, reqActive, 4, 0x39, s->Phone.Data.Priv.N6510.Timeout, ID_GetProfile);
+}
+
+static GSM_Error N6510_ReplySetProfile(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ unsigned char *blockstart;
+ int i;
+
+ smprintf(s, "Response to profile writing received!\n");
+
+ blockstart = msg->Buffer + 6;
+ for (i = 0; i < msg->Buffer[5]; i++) {
+ switch (blockstart[2]) {
+ case 0x00: smprintf(s, "keypad tone level"); break;
+ case 0x02: smprintf(s, "call alert"); break;
+ case 0x03: smprintf(s, "ringtone"); break;
+ case 0x04: smprintf(s, "ringtone volume"); break;
+ case 0x05: smprintf(s, "SMS tone"); break;
+ case 0x06: smprintf(s, "vibration"); break;
+ case 0x07: smprintf(s, "warning tone level"); break;
+ case 0x08: smprintf(s, "caller groups"); break;
+ case 0x09: smprintf(s, "automatic answer"); break;
+ case 0x0c: smprintf(s, "name"); break;
+ default:
+ smprintf(s, "Unknown block type %02x", blockstart[2]);
+ break;
+ }
+ if (msg->Buffer[4] == 0x00) {
+ smprintf(s, ": set OK\n");
+ } else {
+ smprintf(s, ": setting error %i\n", msg->Buffer[4]);
+ }
+ blockstart = blockstart + blockstart[1];
+ }
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_SetProfile(GSM_StateMachine *s, GSM_Profile *Profile)
+{
+ int i, length = 7, blocks = 0;
+ gboolean found;
+ unsigned char ID,Value;
+ unsigned char req[150] = {N6110_FRAME_HEADER, 0x03, 0x01,
+ 0x06, /* Number of blocks */
+ 0x03};
+
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PROFILES)) return ERR_NOTSUPPORTED;
+
+ if (Profile->Location>5) return ERR_INVALIDLOCATION;
+
+ for (i=0;i<Profile->FeaturesNumber;i++) {
+ found = FALSE;
+ switch (Profile->FeatureID[i]) {
+ case Profile_RingtoneID:
+ ID = 0x03;
+ Value = Profile->FeatureValue[i];
+ found = TRUE;
+ break;
+ default:
+ found=NOKIA_FindPhoneFeatureValue(
+ s,
+ Profile71_65,
+ Profile->FeatureID[i],Profile->FeatureValue[i],
+ &ID,&Value);
+ }
+ if (found) {
+ req[length] = 0x09;
+ req[length + 1] = ID;
+ req[length + 2] = Profile->Location;
+ memcpy(req + length + 4, "\x00\x00\x01", 3);
+ req[length + 8] = 0x03;
+ req[length + 3] = req[length + 7] = Value;
+ blocks++;
+ length += 9;
+ }
+ }
+
+ smprintf(s, "Setting profile\n");
+ return GSM_WaitFor (s, req, length, 0x39, s->Phone.Data.Priv.N6510.Timeout, ID_SetProfile);
+}
+
+static GSM_Error N6510_ReplyIncomingCB(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x21:
+ smprintf(s, "Ignoring cell broadcast ok event\n");
+ break;
+ case 0x22:
+ smprintf(s, "Ignoring cell broadcast fail event\n");
+ break;
+ case 0x23:
+ smprintf(s, "Ignoring cell broadcast read event\n");
+ break;
+ default:
+ smprintf(s, "Ignoring cell broadcast event 0x%02x\n", msg->Buffer[3]);
+ break;
+ }
+ return ERR_NONE;
+}
+static GSM_Error N6510_ReplyIncomingSMS(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_SMSMessage sms;
+ size_t i;
+
+#ifdef DEBUG
+ smprintf(s, "SMS message received\n");
+ N6510_DecodeSMSFrame(s, &sms, msg->Buffer+10,&i);
+#endif
+
+ if (s->Phone.Data.EnableIncomingSMS && s->User.IncomingSMS!=NULL) {
+ GSM_SetDefaultSMSData(&sms);
+
+ sms.State = SMS_UnRead;
+ sms.InboxFolder = TRUE;
+
+ N6510_DecodeSMSFrame(s, &sms, msg->Buffer+10,&i);
+
+ s->User.IncomingSMS(s, &sms, s->User.IncomingSMSUserData);
+ }
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_DialVoice(GSM_StateMachine *s, char *number, GSM_CallShowNumber ShowNumber)
+{
+ unsigned int pos2 = 15;
+ unsigned int pos = 4;
+ unsigned char req2[100] = {N6110_FRAME_HEADER,0x01,
+ 0x00,0x02,0x07,0x04,
+ 0x01, /* 1 - voice, 2 - data */
+ 0x00,0x03,
+ 0x18, /* length of rest + 1 */
+ 0x00,0x00,0x00};
+ unsigned char req[100] = {N6110_FRAME_HEADER,0x01,
+ 0x0c}; /* Number length */
+ GSM_Error error;
+
+ /* USSD not supported */
+ if (number[0] == '*') return ERR_NOTSUPPORTED;
+ if (number[0] == '#') return ERR_NOTSUPPORTED;
+
+ req[pos++] = strlen(number);
+ EncodeUnicode(req+pos,number,strlen(number));
+ pos += strlen(number)*2;
+ req[pos++] = 0x05; /* call type: voice - 0x05, data - 0x01 */
+ req[pos++] = 0x01;
+ req[pos++] = 0x05;
+ req[pos++] = 0x00;
+ req[pos++] = 0x02;
+ req[pos++] = 0x00;
+ req[pos++] = 0x00;
+ switch (ShowNumber) {
+ case GSM_CALL_HideNumber:
+ req[pos++] = 0x02;
+ break;
+ case GSM_CALL_ShowNumber:
+ req[pos++] = 0x03;
+ break;
+ case GSM_CALL_DefaultNumberPresence:
+ req[pos++] = 0x01;
+ break;
+ }
+ smprintf(s, "Making voice call\n");
+ error = GSM_WaitFor (s, req, pos, 0x01, s->Phone.Data.Priv.N6510.Timeout, ID_DialVoice);
+ if (error != ERR_NOTSUPPORTED) return error;
+
+ if (ShowNumber != GSM_CALL_DefaultNumberPresence) return ERR_NOTSUPPORTED;
+
+ req2[11] = strlen(number)*2+6;
+ req2[pos2++] = strlen(number);
+ EncodeUnicode(req2+pos2,number,strlen(number));
+ pos2 += strlen(number)*2;
+
+ smprintf(s, "Making voice call\n");
+ error = GSM_WaitFor (s, req2, pos2, 0x01, s->Phone.Data.Priv.N6510.Timeout, ID_DialVoice);
+ if (error == ERR_NOTSUPPORTED) return ERR_NONE;
+ return error;
+}
+
+static GSM_Error N6510_ReplyLogIntoNetwork(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Probably phone says: I log into network\n");
+ return ERR_NONE;
+}
+
+void N6510_EncodeFMFrequency(double freq, unsigned char *buff)
+{
+ unsigned int freq2;
+
+ freq2 = (unsigned int)(freq * 100);
+ freq2 = freq2 - 0xffff;
+ buff[0] = freq2 / 0x100;
+ buff[1] = freq2 % 0x100;
+}
+
+void N6510_DecodeFMFrequency(double *freq, unsigned char *buff)
+{
+ *freq = (double)(0xffff + buff[0] * 0x100 + buff[1])/1000.0;
+}
+
+static GSM_Error N6510_ReplyGetFMStatus(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "getting FM status OK\n");
+ memcpy(s->Phone.Data.Priv.N6510.FMStatus,msg->Buffer,msg->Length);
+ s->Phone.Data.Priv.N6510.FMStatusLength = msg->Length;
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_GetFMStatus(GSM_StateMachine *s)
+{
+ unsigned char req[7] = {N6110_FRAME_HEADER, 0x0d, 0x00, 0x00, 0x01};
+
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_RADIO)) return ERR_NOTSUPPORTED;
+ return GSM_WaitFor (s, req, 7, 0x3E, 2, ID_GetFMStation);
+}
+
+static GSM_Error N6510_ReplyGetFMStation(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ unsigned char name[GSM_MAX_FMSTATION_LENGTH*2+2];
+ int length;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ switch (msg->Buffer[3]) {
+ case 0x06:
+ smprintf(s, "Received FM station\n");
+ length = msg->Buffer[8];
+ if (length > GSM_MAX_FMSTATION_LENGTH) {
+ smprintf(s, "FM station name too long (%d), truncating!\n", length);
+ length = GSM_MAX_FMSTATION_LENGTH;
+ }
+ memcpy(name,msg->Buffer+18,length*2);
+ name[length*2] = 0x00;
+ name[length*2+1] = 0x00;
+ CopyUnicodeString(Data->FMStation->StationName,name);
+ smprintf(s,"Station name: \"%s\"\n",DecodeUnicodeString(Data->FMStation->StationName));
+ N6510_DecodeFMFrequency(&Data->FMStation->Frequency, msg->Buffer+16);
+ return ERR_NONE;
+ case 0x16:
+ smprintf(s, "Received FM station. Empty ?\n");
+ return ERR_EMPTY;
+ case 0xf0:
+ smprintf(s, "FM radio not supported\n");
+ return ERR_NOTSUPPORTED;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_GetFMStation (GSM_StateMachine *s, GSM_FMStation *FMStation)
+{
+ GSM_Error error;
+ int location;
+ unsigned char req[7] = {N6110_FRAME_HEADER, 0x05,
+ 0x00, /* location */
+ 0x00,0x01};
+
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_RADIO)) return ERR_NOTSUPPORTED;
+ if (FMStation->Location > GSM_MAX_FM_STATION) return ERR_INVALIDLOCATION;
+
+ s->Phone.Data.FMStation = FMStation;
+
+ error = N6510_GetFMStatus(s);
+ if (error != ERR_NONE) return error;
+
+ location = FMStation->Location-1;
+ if (s->Phone.Data.Priv.N6510.FMStatus[14+location] == 0xFF) return ERR_EMPTY;
+ req[4] = s->Phone.Data.Priv.N6510.FMStatus[14+location];
+
+ smprintf(s, "Getting FM Station %i\n",FMStation->Location);
+ return GSM_WaitFor (s, req, 7, 0x3E, 2, ID_GetFMStation);
+}
+
+static GSM_Error N6510_ReplySetFMStation(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+#ifdef DEBUG
+ switch (msg->Buffer[4]){
+ case 0x03: smprintf(s, "FM stations cleaned\n"); break;
+ case 0x11: smprintf(s, "Setting FM station status OK\n"); break;
+ case 0x12: smprintf(s, "Setting FM station OK\n"); break;
+ }
+#endif
+ return ERR_NONE;
+}
+
+static GSM_Error N6510_ClearFMStations (GSM_StateMachine *s)
+{
+ unsigned char req[7] = {N6110_FRAME_HEADER, 0x03,0x0f,0x00,0x01};
+
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_RADIO)) return ERR_NOTSUPPORTED;
+
+ smprintf(s, "Cleaning FM Stations\n");
+ return GSM_WaitFor (s, req, 7, 0x3E, 2, ID_SetFMStation);
+}
+
+static GSM_Error N6510_SetFMStation (GSM_StateMachine *s, GSM_FMStation *FMStation)
+{
+ unsigned int len, location;
+ GSM_Error error;
+ unsigned char setstatus[36] = {N6110_FRAME_HEADER,0x11,0x00,0x01,0x01,
+ 0x00,0x00,0x1c,0x00,0x14,0x00,0x00,
+ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
+ 0xff,0xff,0xff,0xff,0xff,0x01};
+ unsigned char req[64] = {N6110_FRAME_HEADER, 0x12,0x00,0x01,0x00,
+ 0x00, /* 0x0e + (strlen(name) * 2) */
+ 0x00, /* strlen(name) */
+ 0x14,0x09,0x00,
+ 0x00, /* location */
+ 0x00,0x00,0x01,
+ 0x00, /* freqHi */
+ 0x00, /* freqLo */
+ 0x01};
+
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_RADIO)) return ERR_NOTSUPPORTED;
+
+ s->Phone.Data.FMStation = FMStation;
+ location = FMStation->Location-1;
+
+ error = N6510_GetFMStatus(s);
+ if (error != ERR_NONE) return error;
+
+ memcpy(setstatus+14,s->Phone.Data.Priv.N6510.FMStatus+14,20);
+ setstatus [14+location] = location;
+
+ smprintf(s, "Setting FM status %i\n",FMStation->Location);
+ error = GSM_WaitFor (s, setstatus, 36 , 0x3E, 2, ID_SetFMStation);
+ if (error != ERR_NONE) return error;
+
+ req[12] = location;
+
+ /* Name */
+ len = UnicodeLength(FMStation->StationName);
+ req[8] = len;
+ req[7] = 0x0e + len * 2;
+ memcpy (req+18,FMStation->StationName,len*2);
+
+ /* Frequency */
+ N6510_EncodeFMFrequency(FMStation->Frequency, req+16);
+
+ smprintf(s, "Setting FM Station %i\n",FMStation->Location);
+ return GSM_WaitFor (s, req, 0x13+len*2, 0x3E, 2, ID_SetFMStation);
+}
+
+static GSM_Error N6510_ReplySetLight(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Light set\n");
+ return ERR_NONE;
+}
+
+GSM_Error N6510_SetLight(GSM_StateMachine *s, N6510_PHONE_LIGHTS light, gboolean enable)
+{
+ unsigned char req[14] = {
+ N6110_FRAME_HEADER, 0x05,
+ 0x01, /* 0x01 = Display, 0x03 = keypad */
+ 0x01, /* 0x01 = Enable, 0x02 = disable */
+ 0x00, 0x00, 0x00, 0x01,
+ 0x05, 0x04, 0x02, 0x00};
+
+ req[4] = light;
+ if (!enable) req[5] = 0x02;
+ smprintf(s, "Setting light\n");
+ return GSM_WaitFor (s, req, 14, 0x3A, s->Phone.Data.Priv.N6510.Timeout, ID_SetLight);
+}
+
+static GSM_Error N6510_ShowStartInfo(GSM_StateMachine *s, gboolean enable)
+{
+ GSM_Error error;
+
+ if (enable) {
+ error=N6510_SetLight(s,N6510_LIGHT_DISPLAY,TRUE);
+ if (error != ERR_NONE) return error;
+
+ error=N6510_SetLight(s,N6510_LIGHT_TORCH,TRUE);
+ if (error != ERR_NONE) return error;
+
+ return N6510_SetLight(s,N6510_LIGHT_KEYPAD,TRUE);
+ } else {
+ error=N6510_SetLight(s,N6510_LIGHT_DISPLAY,FALSE);
+ if (error != ERR_NONE) return error;
+
+ error=N6510_SetLight(s,N6510_LIGHT_TORCH,FALSE);
+ if (error != ERR_NONE) return error;
+
+ return N6510_SetLight(s,N6510_LIGHT_KEYPAD,FALSE);
+ }
+}
+
+static GSM_Error N6510_ReplyGetGPRSAccessPoint(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_GPRSAccessPoint *point = s->Phone.Data.GPRSPoint;
+
+ switch (msg->Buffer[13]) {
+ case 0x01:
+ smprintf(s,"Active GPRS point received\n");
+ point->Active = FALSE;
+ if (point->Location == msg->Buffer[18]) point->Active = TRUE;
+ return ERR_NONE;
+ case 0xD2:
+ smprintf(s,"Names for GPRS points received\n");
+ CopyUnicodeString(point->Name,msg->Buffer+18+(point->Location-1)*42);
+ smprintf(s,"\"%s\"\n",DecodeUnicodeString(point->Name));
+ return ERR_NONE;
+ case 0xF2:
+ smprintf(s,"URL for GPRS points received\n");
+ CopyUnicodeString(point->URL,msg->Buffer+18+(point->Location-1)*202);
+ smprintf(s,"\"%s\"\n",DecodeUnicodeString(point->URL));
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_GetGPRSAccessPoint(GSM_StateMachine *s, GSM_GPRSAccessPoint *point)
+{
+ GSM_Error error;
+ unsigned char URL[] = {
+ N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00,
+ 0x00, 0x00, 0x00, 0x03, 0xF2, 0x00, 0x00};
+ unsigned char Name[] = {
+ N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0xD2, 0x00, 0x00};
+ unsigned char Active[] = {
+ N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00,
+ 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00};
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOGPRSPOINT)) return ERR_NOTSUPPORTED;
+ if (point->Location < 1) return ERR_UNKNOWN;
+ if (point->Location > 5) return ERR_INVALIDLOCATION;
+
+ s->Phone.Data.GPRSPoint = point;
+
+ smprintf(s, "Getting GPRS access point name\n");
+ error=GSM_WaitFor (s, Name, 16, 0x43, s->Phone.Data.Priv.N6510.Timeout, ID_GetGPRSPoint);
+ if (error != ERR_NONE) return error;
+
+ smprintf(s, "Getting GPRS access point URL\n");
+ error=GSM_WaitFor (s, URL, 16, 0x43, s->Phone.Data.Priv.N6510.Timeout, ID_GetGPRSPoint);
+ if (error != ERR_NONE) return error;
+
+ smprintf(s, "Getting number of active GPRS access point\n");
+ error=GSM_WaitFor (s, Active, 16, 0x43, s->Phone.Data.Priv.N6510.Timeout, ID_GetGPRSPoint);
+ if (error != ERR_NONE) return error;
+
+ if (UnicodeLength(point->URL)==0 && UnicodeLength(point->Name)==0) return ERR_EMPTY;
+ return error;
+}
+
+static GSM_Error N6510_ReplySetGPRSAccessPoint1(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[13]) {
+ case 0x01:
+ case 0xD2:
+ case 0xF2:
+ memcpy(s->Phone.Data.Priv.N6510.GPRSPoints,msg->Buffer,msg->Length);
+ s->Phone.Data.Priv.N6510.GPRSPointsLength = msg->Length;
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_SetGPRSAccessPoint(GSM_StateMachine *s, GSM_GPRSAccessPoint *point)
+{
+ unsigned char *buff = s->Phone.Data.Priv.N6510.GPRSPoints;
+ GSM_Error error;
+ unsigned char URL[] = {
+ N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00,
+ 0x00, 0x00, 0x00, 0x03, 0xF2, 0x00, 0x00};
+ unsigned char Name[] = {
+ N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00,
+ 0x01, 0x00, 0x00, 0x00, 0xD2, 0x00, 0x00};
+ unsigned char Active[] = {
+ N7110_FRAME_HEADER, 0x05, 0x00, 0x00, 0x00, 0x2C, 0x00,
+ 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00};
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NOGPRSPOINT)) return ERR_NOTSUPPORTED;
+ if (point->Location < 1) return ERR_UNKNOWN;
+ if (point->Location > 5) return ERR_INVALIDLOCATION;
+
+ s->Phone.Data.GPRSPoint = point;
+
+ smprintf(s, "Getting GPRS access point name\n");
+ error=GSM_WaitFor (s, Name, 16, 0x43, s->Phone.Data.Priv.N6510.Timeout, ID_SetGPRSPoint);
+ if (error != ERR_NONE) return error;
+ CopyUnicodeString(buff+18+(point->Location-1)*42,point->Name);
+ buff[0] = 0x00;
+ buff[1] = 0x01;
+ buff[2] = 0x01;
+ buff[3] = 0x07;
+ smprintf(s, "Setting GPRS access point name\n");
+ error=GSM_WaitFor (s, buff, s->Phone.Data.Priv.N6510.GPRSPointsLength, 0x43, s->Phone.Data.Priv.N6510.Timeout, ID_SetGPRSPoint);
+ if (error != ERR_NONE) return error;
+
+ smprintf(s, "Getting GPRS access point URL\n");
+ error=GSM_WaitFor (s, URL, 16, 0x43, s->Phone.Data.Priv.N6510.Timeout, ID_SetGPRSPoint);
+ if (error != ERR_NONE) return error;
+ CopyUnicodeString(buff+18+(point->Location-1)*42,point->URL);
+ buff[0] = 0x00;
+ buff[1] = 0x01;
+ buff[2] = 0x01;
+ buff[3] = 0x07;
+ smprintf(s, "Setting GPRS access point URL\n");
+ error=GSM_WaitFor (s, buff, s->Phone.Data.Priv.N6510.GPRSPointsLength, 0x43, s->Phone.Data.Priv.N6510.Timeout, ID_SetGPRSPoint);
+ if (error != ERR_NONE) return error;
+
+ if (point->Active) {
+ smprintf(s, "Getting number of active GPRS access point\n");
+ error=GSM_WaitFor (s, Active, 16, 0x43, s->Phone.Data.Priv.N6510.Timeout, ID_SetGPRSPoint);
+ if (error != ERR_NONE) return error;
+ buff[0] = 0x00;
+ buff[1] = 0x01;
+ buff[2] = 0x01;
+ buff[3] = 0x07;
+ buff[18]= point->Location;
+ smprintf(s, "Setting number of active GPRS access point\n");
+ error=GSM_WaitFor (s, buff, s->Phone.Data.Priv.N6510.GPRSPointsLength, 0x43, s->Phone.Data.Priv.N6510.Timeout, ID_SetGPRSPoint);
+ if (error != ERR_NONE) return error;
+ }
+
+ return error;
+}
+
+static GSM_Error N6510_ReplyGetLocale(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Locale *locale = s->Phone.Data.Locale;
+
+ switch (msg->Buffer[3]) {
+ case 0x8A:
+ smprintf(s, "Date settings received\n");
+ switch (msg->Buffer[4]) {
+ case 0x00:
+ locale->DateFormat = GSM_Date_DDMMYYYY;
+ locale->DateSeparator = '.';
+ break;
+ case 0x01:
+ locale->DateFormat = GSM_Date_MMDDYYYY;
+ locale->DateSeparator = '.';
+ break;
+ case 0x02:
+ locale->DateFormat = GSM_Date_YYYYMMDD;
+ locale->DateSeparator = '.';
+ break;
+ case 0x04:
+ locale->DateFormat = GSM_Date_DDMMYYYY;
+ locale->DateSeparator = '/';
+ break;
+ case 0x05:
+ locale->DateFormat = GSM_Date_MMDDYYYY;
+ locale->DateSeparator = '/';
+ break;
+ case 0x06:
+ locale->DateFormat = GSM_Date_YYYYMMDD;
+ locale->DateSeparator = '/';
+ break;
+ case 0x08:
+ locale->DateFormat = GSM_Date_DDMMYYYY;
+ locale->DateSeparator = '-';
+ break;
+ case 0x09:
+ locale->DateFormat = GSM_Date_MMDDYYYY;
+ locale->DateSeparator = '-';
+ break;
+ case 0x0A:
+ locale->DateFormat = GSM_Date_YYYYMMDD;
+ locale->DateSeparator = '-';
+ break;
+ default:/* FIXME */
+ locale->DateFormat = GSM_Date_DDMMYYYY;
+ locale->DateSeparator = '/';
+ break;
+ }
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error N6510_GetLocale(GSM_StateMachine *s, GSM_Locale *locale)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x89};
+
+ s->Phone.Data.Locale = locale;
+
+ smprintf(s, "Getting date format\n");
+ return GSM_WaitFor (s, req, 4, 0x13, s->Phone.Data.Priv.N6510.Timeout, ID_GetLocale);
+}
+
+GSM_Error N6510_CancelCall(GSM_StateMachine *s, int ID, gboolean all)
+{
+ if (all) return ERR_NOTSUPPORTED;
+ return DCT3DCT4_CancelCall(s,ID);
+}
+
+GSM_Error N6510_AnswerCall(GSM_StateMachine *s, int ID, gboolean all)
+{
+ if (all) return ERR_NOTSUPPORTED;
+ return DCT3DCT4_AnswerCall(s,ID);
+}
+
+static GSM_Error N6510_ReplyAddSMSFolder(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s,"SMS folder \"%s\" has been added\n",DecodeUnicodeString(msg->Buffer+10));
+ return ERR_NONE;
+}
+
+GSM_Error N6510_AddSMSFolder(GSM_StateMachine *s, unsigned char *name)
+{
+ unsigned char req[200] = {N6110_FRAME_HEADER, 0x10, 0x01, 0x00, 0x01,
+ 0x00, /* Length */
+ 0x00, 0x00};
+
+ CopyUnicodeString(req+10,name);
+ req[7] = UnicodeLength(name)*2 + 6;
+
+ smprintf(s, "Adding SMS folder\n");
+ return GSM_WaitFor (s, req, req[7] + 6, 0x14, s->Phone.Data.Priv.N6510.Timeout, ID_AddSMSFolder);
+}
+
+static GSM_Error N6510_SetWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
+{
+ GSM_Error error;
+ int count=4, location;
+ unsigned char req[600] = {N6110_FRAME_HEADER, 0x09};
+
+ /* We have to enable WAP frames in phone */
+ error=N6510_EnableConnectionFunctions(s,N6510_WAP_SETTINGS);
+ if (error!=ERR_NONE) return error;
+
+ location = bookmark->Location - 1;
+ if (bookmark->Location == 0) location = 0xffff;
+ req[count++] = (location & 0xff00) >> 8;
+ req[count++] = location & 0x00ff;
+
+ count += NOKIA_SetUnicodeString(s, req+count, bookmark->Title, TRUE);
+ count += NOKIA_SetUnicodeString(s, req+count, bookmark->Address, TRUE);
+
+ req[count++] = 0x00;
+ req[count++] = 0x00;
+ req[count++] = 0x00;
+ req[count++] = 0x00;
+
+ smprintf(s, "Setting WAP bookmark\n");
+ error = GSM_WaitFor (s, req, count, 0x3f, s->Phone.Data.Priv.N6510.Timeout, ID_SetWAPBookmark);
+ if (error != ERR_NONE) {
+ if (error == ERR_INSIDEPHONEMENU || error == ERR_EMPTY || error == ERR_FULL) {
+ DCT3DCT4_DisableConnectionFunctions(s);
+ }
+ return error;
+ }
+
+ return DCT3DCT4_DisableConnectionFunctions(s);
+}
+
+GSM_Error N6510_DeleteWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
+{
+ GSM_Error error;
+
+ /* We have to enable WAP frames in phone */
+ error=N6510_EnableConnectionFunctions(s,N6510_WAP_SETTINGS);
+ if (error!=ERR_NONE) return error;
+
+ return DCT3DCT4_DeleteWAPBookmarkPart(s,bookmark);
+}
+
+GSM_Error N6510_GetWAPBookmark(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
+{
+ GSM_Error error;
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) return ERR_NOTSUPPORTED;
+
+ /* We have to enable WAP frames in phone */
+ error=N6510_EnableConnectionFunctions(s,N6510_WAP_SETTINGS);
+ if (error!=ERR_NONE) return error;
+
+ return DCT3DCT4_GetWAPBookmarkPart(s,bookmark);
+}
+
+static GSM_Error DCT4_ReplyGetScreenDump(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int len;
+
+ /* Data is at offset 10 */
+
+ len = msg->Buffer[7] | (msg->Buffer[6] << 8);
+ smprintf(s, "Received screenshot part, length %d\n", len);
+ s->Phone.Data.Picture->Buffer = realloc(s->Phone.Data.Picture->Buffer, s->Phone.Data.Picture->Length + len);
+ if (s->Phone.Data.Picture->Buffer == NULL) {
+ return ERR_MOREMEMORY;
+ }
+ memcpy(s->Phone.Data.Picture->Buffer + s->Phone.Data.Picture->Length, msg->Buffer + 10, len);
+ s->Phone.Data.Picture->Length += len;
+ if (len < 500) {
+ return ERR_NONE;
+ }
+ return ERR_NEEDANOTHERANSWER;
+}
+
+static GSM_Error DCT4_ReplyGetScreenInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ s->Phone.Data.Priv.N6510.ScreenWidth = msg->Buffer[5] | (msg->Buffer[4] << 8);
+ s->Phone.Data.Priv.N6510.ScreenHeight = msg->Buffer[7] | (msg->Buffer[6] << 8);
+ smprintf(s, "Screen size %dx%d\n", s->Phone.Data.Priv.N6510.ScreenWidth, s->Phone.Data.Priv.N6510.ScreenHeight);
+
+ return ERR_NONE;
+}
+
+GSM_Error DCT4_Screenshot(GSM_StateMachine *s, GSM_BinaryPicture *picture)
+{
+ unsigned char req_data[] = {N6110_FRAME_HEADER, 0x07, 0x01, 0x00};
+ unsigned char req_screen[] = {N6110_FRAME_HEADER, 0x06, 0x01, 0x00};
+ unsigned char bmp_header[] = {0x42, 0x4D, /* BMP magic "BM" */
+ 0, 0, 0, 0, /* Size of BMP in bytes */
+ 0, 0, 0, 0, /* reserved */
+ 0x7a, 0, 0, 0 , /* Offset of data */
+ 0x6c, 0, 0, 0, /* Size of header */
+ 0, 0, 0, 0, /* width */
+ 0, 0, 0, 0, /* height */
+ 1, 0, /* color planes */
+ 32, 0, /* bpp */
+ 3, 0, 0, 0, /* compression, BI_BITFIELDS */
+ 32, 0, 0, 0, /* Size of image pixel */
+ 0x13,0x0b,0x00,0x00, /* XPelsPerMeter */
+ 0x13,0x0b,0x00,0x00, /* YPelsPerMeter */
+ 0, 0, 0, 0, /* palette */
+ 0, 0, 0, 0, /* important colors */
+ 0, 0xFF, 0, 0, /* red mask */
+ 0, 0, 0xFF, 0, /* green mask */
+ 0, 0, 0, 0xFF, /* blue mask */
+ 0xFF, 0, 0, 0, /* alpha mask */
+ 0x20, 0x6E, 0x69, 0x57, /* LCS_WINDOWS_COLOR_SPACE */
+ 0, 0, 0, 0, /* CIEXYZTRIPLE */
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0,
+ 0, 0, 0, 0, /* red gamma */
+ 0, 0, 0, 0, /* green gamma */
+ 0, 0, 0, 0, /* blue gamma */
+ };
+ GSM_Error error;
+ int tmp;
+
+ /* Get screen size */
+ error = GSM_WaitFor(s, req_screen, 6, 0x0E, 4, ID_GetScreenSize);
+ if (error != ERR_NONE) {
+ return error;
+ }
+
+ /* Allocate buffer */
+ s->Phone.Data.Picture = picture;
+ picture->Type = PICTURE_BMP;
+ picture->Buffer = malloc(sizeof(bmp_header));
+ if (picture->Buffer == NULL) {
+ return ERR_MOREMEMORY;
+ }
+ memcpy(picture->Buffer, bmp_header, sizeof(bmp_header));
+ picture->Length = sizeof(bmp_header);
+
+ /* Fill BMP header */
+#define STORE_INT(data, pos) picture->Buffer[pos] = data & 0xff; picture->Buffer[pos + 1] = (data >> 8) & 0xff; picture->Buffer[pos + 2] = (data >> 16) & 0xff; picture->Buffer[pos + 3] = (data >> 24) & 0xff;
+ /* Size */
+ tmp = 0x7a + (s->Phone.Data.Priv.N6510.ScreenWidth * s->Phone.Data.Priv.N6510.ScreenHeight * 4);
+ STORE_INT(tmp, 2);
+ tmp = s->Phone.Data.Priv.N6510.ScreenWidth;
+ STORE_INT(tmp, 18);
+ tmp = -s->Phone.Data.Priv.N6510.ScreenHeight;
+ STORE_INT(tmp, 22);
+
+ /* And fill in bitmap */
+ return GSM_WaitFor(s, req_data, 6, 0x0E, 4, ID_Screenshot);
+}
+
+
+static GSM_Reply_Function N6510ReplyFunctions[] = {
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x02,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x03,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x04,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x05,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x07,ID_AnswerCall },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x07,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x09,ID_CancelCall },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x09,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x0A,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x0B,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x0C,ID_DialVoice },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x0C,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x0F,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x10,ID_DialVoice },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x10,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x23,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x25,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x27,ID_IncomingFrame },
+ {N71_65_ReplySendDTMF, "\x01",0x03,0x51,ID_SendDTMF },
+ {N71_65_ReplySendDTMF, "\x01",0x03,0xf0,ID_SendDTMF },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0x53,ID_IncomingFrame },
+ {N71_65_ReplySendDTMF, "\x01",0x03,0x59,ID_SendDTMF },
+ {N71_65_ReplySendDTMF, "\x01",0x03,0x5E,ID_SendDTMF },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0xA6,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0xD2,ID_IncomingFrame },
+ {N71_65_ReplyCallInfo, "\x01",0x03,0xD3,ID_IncomingFrame },
+ {N6510_ReplyPressKey, "\x01",0x03,0x33,ID_PressKey },
+ {N6510_ReplyPressKey, "\x01",0x03,0x12,ID_PressKey },
+
+ {N6510_ReplySendSMSMessage, "\x02",0x03,0x03,ID_IncomingFrame },
+ {N6510_ReplyIncomingSMS, "\x02",0x03,0x04,ID_IncomingFrame },
+ {N6510_ReplySetSMSC, "\x02",0x03,0x13,ID_SetSMSC },
+ {N6510_ReplyGetSMSC, "\x02",0x03,0x15,ID_GetSMSC },
+ {N6510_ReplyIncomingCB, "\x02",0x03,0x21,ID_IncomingFrame },
+ {N6510_ReplyIncomingCB, "\x02",0x03,0x22,ID_IncomingFrame },
+ {N6510_ReplyIncomingCB, "\x02",0x03,0x23,ID_IncomingFrame },
+
+ {N6510_ReplyGetMemoryStatus, "\x03",0x03,0x04,ID_GetMemoryStatus },
+ {N6510_ReplyGetMemory, "\x03",0x03,0x08,ID_GetMemory },
+ {N71_65_ReplyWritePhonebook, "\x03",0x03,0x0C,ID_SetBitmap },
+ {N71_65_ReplyWritePhonebook, "\x03",0x03,0x0C,ID_SetMemory },
+ {N6510_ReplyDeleteMemory, "\x03",0x03,0x10,ID_SetMemory },
+
+ {DCT3DCT4_ReplyCallDivert, "\x06",0x03,0x02,ID_Divert },
+ {N71_65_ReplyUSSDInfo, "\x06",0x03,0x03,ID_IncomingFrame },
+ {NoneReply, "\x06",0x03,0x06,ID_IncomingFrame },
+ {NoneReply, "\x06",0x03,0x09,ID_IncomingFrame },
+
+ {N6510_ReplyEnterSecurityCode, "\x08",0x03,0x08,ID_EnterSecurityCode },
+ {N6510_ReplyEnterSecurityCode, "\x08",0x03,0x09,ID_EnterSecurityCode },
+ {N6510_ReplyGetSecurityStatus, "\x08",0x03,0x12,ID_GetSecurityStatus },
+ {N6510_ReplyGetSecurityStatus, "\x08",0x03,0xf0,ID_GetSecurityStatus },
+
+ {N6510_ReplyGetNetworkInfo, "\x0A",0x03,0x01,ID_GetNetworkInfo },
+ {N6510_ReplyGetNetworkInfo, "\x0A",0x03,0xf0,ID_GetNetworkInfo },
+ {N6510_ReplyGetSignalQuality, "\x0A",0x03,0x0C,ID_GetSignalQuality },
+ {N6510_ReplyGetOperatorLogo, "\x0A",0x03,0x24,ID_GetBitmap },
+ {N6510_ReplyGetOperatorLogo, "\x0A",0x03,0xf0,ID_GetBitmap },
+ {N6510_ReplySetOperatorLogo, "\x0A",0x03,0x26,ID_SetBitmap },
+ /* This needs to be last of type */
+ {N6510_ReplyGetNetworkInfo, "\x0A",0x03,0x01,ID_IncomingFrame },
+ {N6510_ReplyLogIntoNetwork, "\x0A",0x03,0x02,ID_IncomingFrame },
+ {NoneReply, "\x0A",0x03,0x16,ID_IncomingFrame },
+ {N6510_ReplyGetIncSignalQuality, "\x0A",0x03,0x1E,ID_IncomingFrame },
+ {NoneReply, "\x0A",0x03,0x20,ID_IncomingFrame },
+ {N6510_ReplyGetNetworkInfo, "\x0A",0x03,0xf0,ID_IncomingFrame },
+
+ {NoneReply, "\x0B",0x03,0x01,ID_PlayTone },
+ {NoneReply, "\x0B",0x03,0x15,ID_PlayTone },
+ {NoneReply, "\x0B",0x03,0x16,ID_PlayTone },
+
+ {N71_65_ReplyAddCalendar1, "\x13",0x03,0x02,ID_SetCalendarNote },
+ {N71_65_ReplyAddCalendar1, "\x13",0x03,0x04,ID_SetCalendarNote },
+ {N71_65_ReplyAddCalendar1, "\x13",0x03,0x06,ID_SetCalendarNote },
+ {N71_65_ReplyAddCalendar1, "\x13",0x03,0x08,ID_SetCalendarNote },
+ {N71_65_ReplyDelCalendar, "\x13",0x03,0x0C,ID_DeleteCalendarNote },
+ {N71_65_ReplyDelCalendar, "\x13",0x03,0xF0,ID_DeleteCalendarNote },
+ {N71_65_ReplyGetNextCalendar1, "\x13",0x03,0x1A,ID_GetCalendarNote },/*method 1*/
+ {N6510_ReplyGetCalendarNotePos, "\x13",0x03,0x32,ID_GetCalendarNotePos },/*method 1*/
+ {N6510_ReplyGetCalendarNotePos, "\x13",0x03,0xF0,ID_GetCalendarNotePos },/*method 1*/
+ {N6510_ReplyGetCalendarInfo, "\x13",0x03,0x3B,ID_GetCalendarNotesInfo},/*method 1*/
+#ifdef DEBUG
+ {N71_65_ReplyGetNextCalendar2, "\x13",0x03,0x3F,ID_GetCalendarNote },
+#endif
+ {N71_65_ReplyAddCalendar2, "\x13",0x03,0x41,ID_SetCalendarNote },/*method 2*/
+ {N6510_ReplyAddCalendar3, "\x13",0x03,0x66,ID_SetCalendarNote },/*method 3*/
+ {N6510_ReplyAddToDo2, "\x13",0x03,0x66,ID_SetToDo },
+ {N6510_ReplyAddNote, "\x13",0x03,0x66,ID_SetNote },
+ {N6510_ReplyGetCalendar3, "\x13",0x03,0x7E,ID_GetCalendarNote },/*method 3*/
+ {N6510_ReplyGetToDo2, "\x13",0x03,0x7E,ID_GetToDo },
+ {N6510_ReplyGetNote, "\x13",0x03,0x7E,ID_GetNote },
+ {N6510_ReplyGetCalendarSettings, "\x13",0x03,0x86,ID_GetCalendarSettings },
+ {N6510_ReplyGetLocale, "\x13",0x03,0x8A,ID_GetLocale },
+ {N6510_ReplyGetCalendarSettings, "\x13",0x03,0x8E,ID_GetCalendarSettings },
+ {N6510_ReplyGetCalendarNotePos, "\x13",0x03,0x96,ID_GetCalendarNotePos },/*method 3*/
+ {N6510_ReplyGetToDoFirstLoc2, "\x13",0x03,0x96,ID_SetToDo },
+ {N6510_ReplyGetNoteFirstLoc, "\x13",0x03,0x96,ID_SetNote },
+ {N6510_ReplyGetCalendarInfo, "\x13",0x03,0x9F,ID_GetCalendarNotesInfo},/*method 3*/
+ {N6510_ReplyGetToDoStatus2, "\x13",0x03,0x9F,ID_GetToDo },
+ {N6510_ReplyGetNoteInfo, "\x13",0x03,0x9F,ID_GetNote },
+
+ {N6510_ReplySaveSMSMessage, "\x14",0x03,0x01,ID_SaveSMSMessage },
+ {N6510_ReplySetPicture, "\x14",0x03,0x01,ID_SetBitmap },
+ {N6510_ReplyGetSMSMessage, "\x14",0x03,0x03,ID_GetSMSMessage },
+ {N6510_ReplyDeleteSMSMessage, "\x14",0x03,0x05,ID_DeleteSMSMessage },
+ {N6510_ReplyDeleteSMSMessage, "\x14",0x03,0x06,ID_DeleteSMSMessage },
+ {N6510_ReplyGetSMSStatus, "\x14",0x03,0x09,ID_GetSMSStatus },
+ {N6510_ReplyGetSMSFolderStatus, "\x14",0x03,0x0d,ID_GetSMSFolderStatus },
+ {N6510_ReplyGetSMSMessage, "\x14",0x03,0x0f,ID_GetSMSMessage },
+ {N6510_ReplyAddSMSFolder, "\x14",0x03,0x11,ID_AddSMSFolder },
+ {N6510_ReplyGetSMSFolders, "\x14",0x03,0x13,ID_GetSMSFolders },
+ {N6510_ReplySaveSMSMessage, "\x14",0x03,0x17,ID_SaveSMSMessage },
+ {N6510_ReplyGetSMSStatus, "\x14",0x03,0x1a,ID_GetSMSStatus },
+ {N6510_ReplyGetSMSStatus, "\x14",0x03,0xf0,ID_GetSMSStatus },
+
+ {DCT4_ReplySetPhoneMode, "\x15",0x03,0x64,ID_Reset },
+ {DCT4_ReplyGetPhoneMode, "\x15",0x03,0x65,ID_Reset },
+ {NoneReply, "\x15",0x03,0x68,ID_Reset },
+
+ {N6510_ReplyGetBatteryCharge, "\x17",0x03,0x0B,ID_GetBatteryCharge },
+ {N6510_IncomingBatteryCharge, "\x17",0x03,0x2c,ID_IncomingFrame },
+
+ {N6510_ReplySetDateTime, "\x19",0x03,0x02,ID_SetDateTime },
+ {N6510_ReplyGetDateTime, "\x19",0x03,0x0B,ID_GetDateTime },
+ {N6510_ReplySetAlarm, "\x19",0x03,0x12,ID_SetAlarm },
+ {N6510_ReplyGetAlarm, "\x19",0x03,0x1A,ID_GetAlarm },
+ {N6510_ReplyGetAlarm, "\x19",0x03,0x20,ID_GetAlarm },
+
+ {DCT4_ReplyGetIMEI, "\x1B",0x03,0x01,ID_GetIMEI },
+ {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x08,ID_GetHardware },
+ {N6510_ReplyGetPPM, "\x1B",0x03,0x08,ID_GetPPM },
+ {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x0C,ID_GetProductCode },
+
+ /* 0x1C - vibra */
+
+ {N6510_ReplyGetRingtonesInfo, "\x1f",0x03,0x08,ID_GetRingtonesInfo },
+ {N6510_ReplyDeleteRingtones, "\x1f",0x03,0x11,ID_SetRingtone },
+ {N6510_ReplyGetRingtone, "\x1f",0x03,0x13,ID_GetRingtone },
+ {N6510_ReplySetBinRingtone, "\x1f",0x03,0x0F,ID_SetRingtone },
+
+ /* 0x23 - voice records */
+
+ {N6510_ReplyGetProfile, "\x39",0x03,0x02,ID_GetProfile },
+ {N6510_ReplySetProfile, "\x39",0x03,0x04,ID_SetProfile },
+ {N6510_ReplyGetProfile, "\x39",0x03,0x06,ID_GetProfile },
+
+ {N6510_ReplySetLight, "\x3A",0x03,0x06,ID_SetLight },
+
+ {N6510_ReplyGetFMStation, "\x3E",0x03,0x06,ID_GetFMStation },
+ {N6510_ReplyGetFMStatus, "\x3E",0x03,0x0E,ID_GetFMStation },
+ {N6510_ReplySetFMStation, "\x3E",0x03,0x15,ID_SetFMStation },
+ {N6510_ReplyGetFMStation, "\x3E",0x03,0x16,ID_GetFMStation },
+ {N6510_ReplyGetFMStation, "\x3E",0x03,0xF0,ID_GetFMStation },
+
+ {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x01,ID_EnableConnectFunc },
+ {DCT3DCT4_ReplyEnableConnectFunc, "\x3f",0x03,0x02,ID_EnableConnectFunc },
+ {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x04,ID_DisableConnectFunc },
+ {DCT3DCT4_ReplyDisableConnectFunc,"\x3f",0x03,0x05,ID_DisableConnectFunc },
+ {N6510_ReplyGetWAPBookmark, "\x3f",0x03,0x07,ID_GetWAPBookmark },
+ {N6510_ReplyGetWAPBookmark, "\x3f",0x03,0x08,ID_GetWAPBookmark },
+ {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0A,ID_SetWAPBookmark },
+ {DCT3DCT4_ReplySetWAPBookmark, "\x3f",0x03,0x0B,ID_SetWAPBookmark },
+ {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0D,ID_DeleteWAPBookmark },
+ {DCT3DCT4_ReplyDelWAPBookmark, "\x3f",0x03,0x0E,ID_DeleteWAPBookmark },
+ {DCT3DCT4_ReplyGetActiveConnectSet,"\x3f",0x03,0x10,ID_GetConnectSet },
+ {DCT3DCT4_ReplySetActiveConnectSet,"\x3f",0x03,0x13,ID_SetConnectSet },
+ {N6510_ReplyGetConnectionSettings,"\x3f",0x03,0x11,ID_GetConnectSet },
+ {N6510_ReplyGetConnectionSettings,"\x3f",0x03,0x16,ID_GetConnectSet },
+ {N6510_ReplyGetConnectionSettings,"\x3f",0x03,0x17,ID_GetConnectSet },
+ {N6510_ReplySetConnectionSettings,"\x3f",0x03,0x19,ID_SetConnectSet },
+ {N6510_ReplySetConnectionSettings,"\x3f",0x03,0x1A,ID_SetConnectSet },
+ {N6510_ReplySetConnectionSettings,"\x3f",0x03,0x28,ID_SetConnectSet },
+ {N6510_ReplySetConnectionSettings,"\x3f",0x03,0x2B,ID_SetConnectSet },
+ {N6510_ReplyGetChatSettings, "\x3f",0x03,0x3B,ID_GetChatSettings },
+ {N6510_ReplyGetChatSettings, "\x3f",0x03,0x3C,ID_GetChatSettings },
+ {N6510_ReplyGetConnectionSettings,"\x3f",0x03,0xf0,ID_GetConnectSet },
+
+ {N6510_ReplyGetOriginalIMEI, "\x42",0x07,0x00,ID_GetOriginalIMEI },
+ {N6510_ReplyGetManufactureMonth, "\x42",0x07,0x00,ID_GetManufactureMonth },
+ {N6510_ReplyGetOriginalIMEI, "\x42",0x07,0x01,ID_GetOriginalIMEI },
+ {N6510_ReplyGetManufactureMonth, "\x42",0x07,0x02,ID_GetManufactureMonth },
+
+ {N6510_ReplySetOperatorLogo, "\x43",0x03,0x08,ID_SetBitmap },
+ {N6510_ReplyGetGPRSAccessPoint, "\x43",0x03,0x06,ID_GetGPRSPoint },
+ {N6510_ReplySetGPRSAccessPoint1, "\x43",0x03,0x06,ID_SetGPRSPoint },
+ {N6510_ReplyGetSyncMLSettings, "\x43",0x03,0x06,ID_GetSyncMLSettings },
+ {N6510_ReplyGetSyncMLName, "\x43",0x03,0x06,ID_GetSyncMLName },
+ {NoneReply, "\x43",0x03,0x08,ID_SetGPRSPoint },
+
+ /* 0x4A - voice records */
+
+ /* 0x53 - simlock */
+
+ {N6510_ReplyAddToDo1, "\x55",0x03,0x02,ID_SetToDo },
+ {N6510_ReplyGetToDo1, "\x55",0x03,0x04,ID_GetToDo },
+ {N6510_ReplyGetToDoFirstLoc1, "\x55",0x03,0x10,ID_SetToDo },
+ {N6510_ReplyDeleteAllToDo1, "\x55",0x03,0x12,ID_DeleteAllToDo },
+ {N6510_ReplyGetToDoStatus1, "\x55",0x03,0x16,ID_GetToDo },
+
+ {N6510_ReplyAddFileHeader1, "\x6D",0x03,0x03,ID_AddFile },
+ {N6510_ReplyAddFolder1, "\x6D",0x03,0x05,ID_AddFolder },
+ {N6510_ReplyGetFilePart12, "\x6D",0x03,0x0F,ID_GetFile },/* filesystem1&2 */
+ {N6510_ReplyAddFileHeader1, "\x6D",0x03,0x13,ID_AddFile },
+ {N6510_ReplyGetFileFolderInfo1, "\x6D",0x03,0x15,ID_GetFileInfo },
+ {NoneReply, "\x6D",0x03,0x19,ID_SetAttrib },
+ {N6510_ReplyDeleteFileFolder1, "\x6D",0x03,0x1F,ID_DeleteFile },
+ {N6510_ReplyGetFileSystemStatus1, "\x6D",0x03,0x23,ID_FileSystemStatus },
+ {N6510_ReplyGetFileFolderInfo1, "\x6D",0x03,0x2F,ID_GetFileInfo },
+ {N6510_ReplyGetFileSystemStatus1, "\x6D",0x03,0x2F,ID_FileSystemStatus },
+ {N6510_ReplyGetFileFolderInfo1, "\x6D",0x03,0x33,ID_GetFileInfo },
+ {N6510_ReplyGetFileFolderInfo1, "\x6D",0x03,0xF0,ID_GetFileInfo },
+ {N6510_ReplyAddFilePart1, "\x6D",0x03,0x41,ID_AddFile },
+ {N6510_ReplyGetFileCRC12, "\x6D",0x03,0x43,ID_GetCRC },
+ {NoneReply, "\x6D",0x03,0x59,ID_AddFile },/* filesystem2 */
+ {N6510_ReplyGetFilePart12, "\x6D",0x03,0x5F,ID_GetFile },/* filesystem2 */
+ {N6510_ReplyDeleteFile2, "\x6D",0x03,0x63,ID_DeleteFile },/* filesystem2 */
+ {N6510_ReplyAddFolder2, "\x6D",0x03,0x65,ID_AddFolder },/* filesystem2 */
+ {N6510_ReplyGetFileCRC12, "\x6D",0x03,0x67,ID_GetCRC },/* filesystem2 */
+ {N6510_ReplyGetFileFolderInfo2, "\x6D",0x03,0x69,ID_IncomingFrame },/* filesystem2 */
+ {N6510_ReplyDeleteFolder2, "\x6D",0x03,0x6B,ID_DeleteFolder },/* filesystem2 */
+ {N6510_ReplyGetFileFolderInfo2, "\x6D",0x03,0x6D,ID_GetFileInfo },/* filesystem2 */
+ {N6510_ReplySetAttrib2, "\x6D",0x03,0x6F,ID_SetAttrib },/* filesystem2 */
+ {N6510_ReplyOpenFile2, "\x6D",0x03,0x73,ID_OpenFile },/* filesystem2 */
+ {NoneReply, "\x6D",0x03,0x75,ID_CloseFile },/* filesystem2 */
+ {N6510_ReplySetFileDate2, "\x6D",0x03,0x87,ID_AddFile },/* filesystem2 */
+
+ {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x01,ID_GetBitmap },
+ {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x01,ID_SetBitmap },
+ {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x0F,ID_GetBitmap },
+ {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x0F,ID_SetBitmap },
+ {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x10,ID_GetBitmap },
+ {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x10,ID_SetBitmap },
+ {N6510_ReplyStartupNoteLogo, "\x7A",0x04,0x25,ID_SetBitmap },
+
+ {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetModel },
+ {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetFirmware },
+
+ /* 0xD7 - Bluetooth */
+
+ {N6510_ReplyGetRingtoneID, "\xDB",0x03,0x02,ID_SetRingtone },
+
+ {DCT4_ReplyGetScreenDump, "\x0E",0x00,0x00,ID_Screenshot },
+ {DCT4_ReplyGetScreenInfo, "\x0E",0x00,0x00,ID_GetScreenSize },
+
+ {NULL, "\x00",0x00,0x00,ID_None }
+};
+
+GSM_Phone_Functions N6510Phone = {
+ "1100|1100a|1100b|1112|1200|1209|1600|1650|1680|2600|2610|2630|2650|2660|2680|2760|3100|3100b|3105|3108|3109c|3200|3200a|3205|3220|3300|3510|3510i|3530|3589i|3590|3595|5000|5100|5140|5140i|5200|5220|5300|5310|6020|6020b|6021|6030|6060|6070|6085|6086|6100|6101|6103|6111|6125|6131|6151|6170|6200|6220|6220c|6225|6230|6230i|6233|6234|6270|6275i|6280|6300|6303c|6310|6310i|6340i|6385|6500c|6500s|6510|6600|6610|6610i|6800|6810|6820|6822|7200|7210|7210s|7230|7250|7250i|7260|7270|7360|7370|7500|7600|7900|8310|8390|8800|8910|8910i",
+ N6510ReplyFunctions,
+ NOTSUPPORTED, /* Install */
+ N6510_Initialise,
+ N6510_Terminate,
+ GSM_DispatchMessage,
+ N6510_ShowStartInfo,
+ NOKIA_GetManufacturer,
+ DCT3DCT4_GetModel,
+ DCT3DCT4_GetFirmware,
+ DCT4_GetIMEI,
+ N6510_GetOriginalIMEI,
+ N6510_GetManufactureMonth,
+ DCT4_GetProductCode,
+ DCT4_GetHardware,
+ N6510_GetPPM,
+ NOTSUPPORTED, /* GetSIMIMSI */
+ N6510_GetDateTime,
+ N6510_SetDateTime,
+ N6510_GetAlarm,
+ N6510_SetAlarm,
+ N6510_GetLocale,
+ NOTSUPPORTED, /* SetLocale */
+ N6510_PressKey,
+ DCT4_Reset,
+ NOTIMPLEMENTED, /* ResetPhoneSettings */
+ N6510_EnterSecurityCode,
+ N6510_GetSecurityStatus,
+ NOTSUPPORTED, /* GetDisplayStatus */
+ NOTIMPLEMENTED, /* SetAutoNetworkLogin */
+ N6510_GetBatteryCharge,
+ N6510_GetSignalQuality,
+ N6510_GetNetworkInfo,
+ NOTSUPPORTED, /* GetCategory */
+ NOTSUPPORTED, /* AddCategory */
+ NOTSUPPORTED, /* GetCategoryStatus */
+ N6510_GetMemoryStatus,
+ N6510_GetMemory,
+ NOTIMPLEMENTED, /* GetNextMemory */
+ N6510_SetMemory,
+ N6510_AddMemory,
+ N6510_DeleteMemory,
+ NOTIMPLEMENTED, /* DeleteAllMemory */
+ N6510_GetSpeedDial,
+ NOTIMPLEMENTED, /* SetSpeedDial */
+ N6510_GetSMSC,
+ N6510_SetSMSC,
+ N6510_GetSMSStatus,
+ N6510_GetSMSMessage,
+ N6510_GetNextSMSMessage,
+ N6510_SetSMS,
+ N6510_AddSMS,
+ N6510_DeleteSMSMessage,
+ N6510_SendSMSMessage,
+ NOTSUPPORTED, /* SendSavedSMS */
+ NOTSUPPORTED, /* SetFastSMSSending */
+ NOKIA_SetIncomingSMS,
+ NOTIMPLEMENTED, /* SetIncomingCB */
+ N6510_GetSMSFolders,
+ N6510_AddSMSFolder,
+ NOTIMPLEMENTED, /* DeleteSMSFolder */
+ N6510_DialVoice,
+ NOTIMPLEMENTED, /* DialService */
+ N6510_AnswerCall,
+ N6510_CancelCall,
+ NOTIMPLEMENTED, /* HoldCall */
+ NOTIMPLEMENTED, /* UnholdCall */
+ NOTIMPLEMENTED, /* ConferenceCall */
+ NOTIMPLEMENTED, /* SplitCall */
+ NOTIMPLEMENTED, /* TransferCall */
+ NOTIMPLEMENTED, /* SwitchCall */
+ DCT3DCT4_GetCallDivert,
+ DCT3DCT4_SetCallDivert,
+ DCT3DCT4_CancelAllDiverts,
+ NOKIA_SetIncomingCall,
+ NOKIA_SetIncomingUSSD,
+ DCT3DCT4_SendDTMF,
+ N6510_GetRingtone,
+ N6510_SetRingtone,
+ N6510_GetRingtonesInfo,
+ N6510_DeleteUserRingtones,
+ N6510_PlayTone,
+ N6510_GetWAPBookmark,
+ N6510_SetWAPBookmark,
+ N6510_DeleteWAPBookmark,
+ N6510_GetWAPSettings,
+ N6510_SetWAPSettings,
+ N6510_GetSyncMLSettings,
+ NOTSUPPORTED, /* SetSyncMLSettings */
+ N6510_GetChatSettings,
+ NOTSUPPORTED, /* SetChatSettings */
+ N6510_GetMMSSettings,
+ N6510_SetMMSSettings,
+ N6510_GetMMSFolders,
+ N6510_GetNextMMSFileInfo,
+ N6510_GetBitmap,
+ N6510_SetBitmap,
+ N6510_GetToDoStatus,
+ NOTIMPLEMENTED, /* GetToDo */
+ N6510_GetNextToDo,
+ NOTIMPLEMENTED, /* SetToDo */
+ N6510_AddToDo,
+ N6510_DeleteToDo2,
+ N6510_DeleteAllToDo1,
+ N6510_GetCalendarStatus,
+ NOTIMPLEMENTED, /* GetCalendar */
+ N6510_GetNextCalendar,
+ NOTIMPLEMENTED, /* SetCalendar */
+ N6510_AddCalendar,
+ N71_65_DelCalendar,
+ NOTIMPLEMENTED, /* DeleteAllCalendar */
+ N6510_GetCalendarSettings,
+ NOTSUPPORTED, /* SetCalendarSettings */
+ N6510_GetNoteStatus,
+ NOTIMPLEMENTED, /* GetNote */
+ N6510_GetNextNote,
+ NOTIMPLEMENTED, /* SetNote */
+ N6510_AddNote,
+ N6510_DeleteNote,
+ NOTSUPPORTED, /* DeleteAllNotes */
+ N6510_GetProfile,
+ N6510_SetProfile,
+ N6510_GetFMStation,
+ N6510_SetFMStation,
+ N6510_ClearFMStations,
+ N6510_GetNextFileFolder,
+ N6510_GetFolderListing,
+ N6510_GetNextRootFolder,
+ N6510_SetFileAttributes,
+ N6510_GetFilePart,
+ N6510_AddFilePart,
+ NOTSUPPORTED, /* SendFilePart */
+ N6510_GetFileSystemStatus,
+ N6510_DeleteFile,
+ N6510_AddFolder,
+ N6510_DeleteFolder,
+ N6510_GetGPRSAccessPoint,
+ N6510_SetGPRSAccessPoint,
+ DCT4_Screenshot,
+ NOTSUPPORTED, /* SetPower */
+ NOTSUPPORTED, /* PostConnect */
+ NONEFUNCTION /* PreAPICall */
+};
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct4s40/6510/n6510.h b/libgammu/phone/nokia/dct4s40/6510/n6510.h
new file mode 100644
index 0000000..32fadbb
--- /dev/null
+++ b/libgammu/phone/nokia/dct4s40/6510/n6510.h
@@ -0,0 +1,127 @@
+/* (c) 2002-2005 by Marcin Wiacek */
+
+#ifndef n6510_h
+#define n6510_h
+
+#include "../../ncommon.h"
+
+typedef enum {
+ N6510_MMS_SETTINGS = 0x01,
+ N6510_CHAT_SETTINGS,
+
+ N6510_WAP_SETTINGS,
+ N6510_SYNCML_SETTINGS
+} N6510_Connection_Settings;
+
+typedef enum {
+ N6510_LIGHT_DISPLAY = 0x01,
+ N6510_LIGHT_KEYPAD = 0x03,
+ N6510_LIGHT_TORCH = 0x10
+} N6510_PHONE_LIGHTS;
+
+typedef struct {
+ int LastCalendarYear;
+ int LastCalendarPos;
+ GSM_NOKIACalToDoLocations LastCalendar;
+ int FirstCalendarPos;
+ unsigned char CalendarIcons[10];
+ GSM_CalendarNoteType CalendarIconsTypes[10];
+ int CalendarIconsNum;
+
+ GSM_NOKIASMSFolder LastSMSFolder;
+ GSM_SMSFolders LastSMSFolders;
+ GSM_File SMSFile;
+ GSM_Error SMSFileError;
+ int SMSFileFolder;
+
+ GSM_NOKIACalToDoLocations LastToDo;
+
+ GSM_NOKIACalToDoLocations LastNote;
+
+ unsigned char RingtoneID; /* When set with preview */
+
+ GSM_File *FilesCache; //[GSM_PHONE_MAXSMSINFOLDER];
+ int FilesLocationsUsed;
+ int FilesLocationsAvail;
+ int FileToken;
+ int ParentID;
+ int FileCheckSum;
+ gboolean FilesEnd;
+ gboolean UseFs1;
+ GSM_Error filesystem2error;
+
+ unsigned char FMStatus[4000];
+ int FMStatusLength;
+
+ unsigned char GPRSPoints[4000];
+ int GPRSPointsLength;
+
+ int BearerNumber;
+
+ unsigned char PhoneMode;
+
+ char MMSFoldersID2[10][80];
+ GSM_File MMSFile;
+ int MMSFolderNum;
+ GSM_Error MMSFolderError;
+
+ /**
+ * Last location we used for adding memory entry.
+ */
+ int LastFreeMemoryLocation;
+ /**
+ * Last type of memory used for LastFreeMemoryLocation.
+ */
+ GSM_MemoryType LastFreeMemoryType;
+ /**
+ * Size of memory when starting last free memory lookup.
+ */
+ int LastFreeMemorySize;
+ /**
+ * Communication timeout. This needs to be higher for unreliable
+ * links as IrDA.
+ */
+ int Timeout;
+ int ScreenWidth;
+ int ScreenHeight;
+} GSM_Phone_N6510Data;
+
+void N6510_EncodeFMFrequency(double freq, unsigned char *buff);
+void N6510_DecodeFMFrequency(double *freq, unsigned char *buff);
+
+#ifndef GSM_USED_MBUS2
+# define GSM_USED_MBUS2
+#endif
+#ifndef GSM_USED_FBUS2
+# define GSM_USED_FBUS2
+#endif
+#ifndef GSM_USED_FBUS2DLR3
+# define GSM_USED_FBUS2DLR3
+#endif
+#ifndef GSM_USED_DKU2PHONET
+# define GSM_USED_DKU2PHONET
+#endif
+#ifndef GSM_USED_DKU2AT
+# define GSM_USED_DKU2AT
+#endif
+#ifndef GSM_USED_DKU5FBUS2
+# define GSM_USED_DKU5FBUS2
+#endif
+#ifndef GSM_USED_PHONETBLUE
+# define GSM_USED_PHONETBLUE
+#endif
+#ifndef GSM_USED_IRDAPHONET
+# define GSM_USED_IRDAPHONET
+#endif
+#ifndef GSM_USED_BLUEPHONET
+# define GSM_USED_BLUEPHONET
+#endif
+#ifndef GSM_USED_FBUS2PL2303
+# define GSM_USED_FBUS2PL2303
+#endif
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct4s40/dct4func.c b/libgammu/phone/nokia/dct4s40/dct4func.c
new file mode 100644
index 0000000..8de03cb
--- /dev/null
+++ b/libgammu/phone/nokia/dct4s40/dct4func.c
@@ -0,0 +1,113 @@
+/* (c) 2002-2003 by Marcin Wiacek */
+
+#include <string.h>
+#include <time.h>
+
+#include <gammu-config.h>
+
+#include "../../../misc/coding/coding.h"
+#include "../../../service/gsmlogo.h"
+#include "../nfunc.h"
+#include "../nfuncold.h"
+#include "../../pfunc.h"
+#include "dct4func.h"
+
+#ifdef GSM_ENABLE_NOKIA_DCT4
+
+GSM_Error DCT4_ReplyGetPhoneMode(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ s->Phone.Data.PhoneString[0] = msg->Buffer[4];
+ return ERR_NONE;
+}
+
+GSM_Error DCT4_GetPhoneMode(GSM_StateMachine *s)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x02, 0x00, 0x00};
+
+ smprintf(s,"Getting phone mode\n");
+
+ return GSM_WaitFor (s, req, 6, 0x15, 4, ID_Reset);
+}
+
+GSM_Error DCT4_ReplySetPhoneMode(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s UNUSED)
+{
+ return ERR_NONE;
+}
+
+GSM_Error DCT4_SetPhoneMode(GSM_StateMachine *s, DCT4_PHONE_MODE mode)
+{
+ unsigned char PhoneMode[10];
+ int i;
+ GSM_Error error;
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x01,
+ 0x04, /* phone mode */
+ 0x00};
+
+ if (s->ConnectionType != GCT_FBUS2) return ERR_OTHERCONNECTIONREQUIRED;
+
+ s->Phone.Data.PhoneString = PhoneMode;
+ req[4] = mode;
+
+ smprintf(s,"Going to phone mode %i\n",mode);
+ error = GSM_WaitFor (s, req, 6, 0x15, 4, ID_Reset);
+ if (error != ERR_NONE) return error;
+ for (i=0;i<20;i++) {
+ error=DCT4_GetPhoneMode(s);
+ if (error != ERR_NONE) return error;
+ if (PhoneMode[0] == mode) break;
+ usleep(500000);
+ }
+
+ return ERR_NONE;
+}
+
+GSM_Error DCT4_ReplyGetIMEI(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ memcpy(s->Phone.Data.IMEI,msg->Buffer + 10, 16);
+ smprintf(s, "Received IMEI %s\n",s->Phone.Data.IMEI);
+ return ERR_NONE;
+}
+
+GSM_Error DCT4_GetIMEI (GSM_StateMachine *s)
+{
+ unsigned char req[5] = {N6110_FRAME_HEADER, 0x00, 0x41};
+
+ smprintf(s, "Getting IMEI\n");
+ return GSM_WaitFor (s, req, 5, 0x1B, 2, ID_GetIMEI);
+}
+
+GSM_Error DCT4_GetHardware(GSM_StateMachine *s, char *value)
+{
+ return NOKIA_GetPhoneString(s,"\x00\x03\x02\x07\x00\x02",6,0x1b,value,ID_GetHardware,10);
+}
+
+GSM_Error DCT4_GetProductCode(GSM_StateMachine *s, char *value)
+{
+ return NOKIA_GetPhoneString(s,"\x00\x03\x04\x0b\x00\x02",6,0x1b,value,ID_GetProductCode,10);
+}
+
+GSM_Error DCT4_Reset(GSM_StateMachine *s, gboolean hard)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x05,
+ 0x80, /* 0x80 - reset, 0x00 - off */
+ 0x00};
+/* unsigned char TimeReq[] = {N6110_FRAME_HEADER, 0x0E, 0x00, 0x00}; */
+
+ if (hard) return ERR_NOTSUPPORTED;
+
+/* error = DCT4_SetPhoneMode(s, DCT4_MODE_TEST); */
+/* if (error != ERR_NONE) return error; */
+/* error = DCT4_SetPhoneMode(s, DCT4_MODE_NORMAL); */
+/* if (error != ERR_NONE) return error; */
+
+ s->Phone.Data.EnableIncomingSMS = FALSE;
+ s->Phone.Data.EnableIncomingCB = FALSE;
+
+ return GSM_WaitFor (s, req, 6, 0x15, 2, ID_Reset);
+}
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct4s40/dct4func.h b/libgammu/phone/nokia/dct4s40/dct4func.h
new file mode 100644
index 0000000..b3d8962
--- /dev/null
+++ b/libgammu/phone/nokia/dct4s40/dct4func.h
@@ -0,0 +1,29 @@
+/* (c) 2002-2003 by Marcin Wiacek */
+
+#ifndef dct4func_h
+#define dct4func_h
+
+#include "../ncommon.h"
+
+typedef enum {
+ DCT4_MODE_NORMAL = 0x01,
+ DCT4_MODE_TEST = 0x04,
+ DCT4_MODE_LOCAL = 0x05
+} DCT4_PHONE_MODE;
+
+GSM_Error DCT4_ReplyGetPhoneMode (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT4_ReplySetPhoneMode (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT4_ReplyGetIMEI (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+
+GSM_Error DCT4_GetPhoneMode (GSM_StateMachine *s);
+GSM_Error DCT4_SetPhoneMode (GSM_StateMachine *s, DCT4_PHONE_MODE mode);
+GSM_Error DCT4_GetIMEI (GSM_StateMachine *s);
+GSM_Error DCT4_GetHardware (GSM_StateMachine *s, char *value);
+GSM_Error DCT4_GetProductCode (GSM_StateMachine *s, char *value);
+GSM_Error DCT4_Reset (GSM_StateMachine *s, gboolean hard);
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct4s40/n3320.c b/libgammu/phone/nokia/dct4s40/n3320.c
new file mode 100644
index 0000000..3da384b
--- /dev/null
+++ b/libgammu/phone/nokia/dct4s40/n3320.c
@@ -0,0 +1,293 @@
+/* (c) 2004 by Marcin Wiacek */
+
+#include <gammu-config.h>
+
+#ifdef GSM_ENABLE_NOKIA3320
+
+#include <string.h>
+#include <time.h>
+
+#include "../../../gsmcomon.h"
+#include "../../../misc/coding/coding.h"
+#include "../../../service/gsmlogo.h"
+#include "../nfunc.h"
+#include "../nfuncold.h"
+#include "../../pfunc.h"
+#include "n3320.h"
+
+static GSM_Error N3320_ReplyGetMemory(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "Phonebook entry received\n");
+ if (msg->Buffer[6] == 0x0f)
+ return N71_65_ReplyGetMemoryError(msg->Buffer[10], s);
+
+ return N71_65_DecodePhonebook(s, s->Phone.Data.Memory, s->Phone.Data.Bitmap, s->Phone.Data.SpeedDial, msg->Buffer+22, msg->Length-22,TRUE);
+}
+
+static GSM_Error N3320_GetMemory (GSM_StateMachine *s, GSM_MemoryEntry *entry)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x07, 0x01, 0x01, 0x00, 0x01,
+ 0xfe, 0x10, /* memory type */
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x01, /* location */
+ 0x00, 0x00, 0x01};
+
+ req[9] = NOKIA_GetMemoryType(s, entry->MemoryType,N71_65_MEMORY_TYPES);
+ if (entry->MemoryType == MEM_SM) return ERR_NOTSUPPORTED;
+ if (req[9]==0xff) return ERR_NOTSUPPORTED;
+
+ if (entry->Location==0x00) return ERR_INVALIDLOCATION;
+
+ req[14] = entry->Location / 256;
+ req[15] = entry->Location % 256;
+
+ s->Phone.Data.Memory=entry;
+ smprintf(s, "Getting phonebook entry\n");
+ return GSM_WaitFor (s, req, 19, 0x03, 4, ID_GetMemory);
+}
+
+static GSM_Error N3320_ReplyGetMemoryStatus(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "Memory status received\n");
+ /* Quess ;-)) */
+ if (msg->Buffer[14]==0x10) {
+ Data->MemoryStatus->MemoryFree = msg->Buffer[18]*256 + msg->Buffer[19];
+ } else {
+ Data->MemoryStatus->MemoryFree = msg->Buffer[17];
+ }
+ smprintf(s, "Size : %i\n",Data->MemoryStatus->MemoryFree);
+ Data->MemoryStatus->MemoryUsed = msg->Buffer[20]*256 + msg->Buffer[21];
+ smprintf(s, "Used : %i\n",Data->MemoryStatus->MemoryUsed);
+ Data->MemoryStatus->MemoryFree -= Data->MemoryStatus->MemoryUsed;
+ smprintf(s, "Free : %i\n",Data->MemoryStatus->MemoryFree);
+ return ERR_NONE;
+}
+
+static GSM_Error N3320_GetMemoryStatus(GSM_StateMachine *s, GSM_MemoryStatus *Status)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x03, 0x02,
+ 0x00, /* memory type */
+ 0x55, 0x55, 0x55, 0x00};
+
+ req[5] = NOKIA_GetMemoryType(s, Status->MemoryType,N71_65_MEMORY_TYPES);
+ if (Status->MemoryType == MEM_SM) return ERR_NOTSUPPORTED;
+ if (req[5]==0xff) return ERR_NOTSUPPORTED;
+
+ s->Phone.Data.MemoryStatus=Status;
+ smprintf(s, "Getting memory status\n");
+ return GSM_WaitFor (s, req, 10, 0x03, 4, ID_GetMemoryStatus);
+}
+
+static GSM_Error N3320_ReplyGetDateTime(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ smprintf(s, "Date & time received\n");
+ if (msg->Buffer[4]==0x01) {
+ NOKIA_DecodeDateTime(s, msg->Buffer+10, s->Phone.Data.DateTime, TRUE, FALSE);
+ return ERR_NONE;
+ }
+ smprintf(s, "Not set in phone\n");
+ return ERR_EMPTY;
+}
+
+static GSM_Error N3320_GetDateTime(GSM_StateMachine *s, GSM_DateTime *date_time)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x0A, 0x00, 0x00};
+
+ s->Phone.Data.DateTime=date_time;
+ smprintf(s, "Getting date & time\n");
+ return GSM_WaitFor (s, req, 6, 0x19, 4, ID_GetDateTime);
+}
+
+static GSM_Error N3320_GetNextCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note, gboolean start)
+{
+ return N71_65_GetNextCalendar1(s,Note,start,&s->Phone.Data.Priv.N3320.LastCalendar,&s->Phone.Data.Priv.N3320.LastCalendarYear,&s->Phone.Data.Priv.N3320.LastCalendarPos);
+}
+
+static GSM_Error N3320_GetCalendarStatus(GSM_StateMachine *s, GSM_CalendarStatus *Status)
+{
+ GSM_Error error;
+
+ /* Method 1 */
+ error=N71_65_GetCalendarInfo1(s, &s->Phone.Data.Priv.N3320.LastCalendar);
+ if (error!=ERR_NONE) return error;
+
+ /**
+ * @todo This should be acquired from phone
+ */
+ Status->Free = 100;
+ Status->Used = s->Phone.Data.Priv.N3320.LastCalendar.Number;
+ return ERR_NONE;
+}
+
+static GSM_Error N3320_ReplyGetCalendarInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ return N71_65_ReplyGetCalendarInfo1(msg, s, &s->Phone.Data.Priv.N3320.LastCalendar);
+}
+
+static GSM_Reply_Function N3320ReplyFunctions[] = {
+ {N3320_ReplyGetMemoryStatus, "\x03",0x03,0x04,ID_GetMemoryStatus },
+ {N3320_ReplyGetMemory, "\x03",0x03,0x08,ID_GetMemory },
+
+ {N71_65_ReplyGetNextCalendar1, "\x13",0x03,0x1A,ID_GetCalendarNote },/*method 1*/
+ {N3320_ReplyGetCalendarInfo, "\x13",0x03,0x3B,ID_GetCalendarNotesInfo},/*method 1*/
+
+ {N3320_ReplyGetDateTime, "\x19",0x03,0x0B,ID_GetDateTime },
+
+ {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetModel },
+ {DCT3DCT4_ReplyGetModelFirmware, "\xD2",0x02,0x00,ID_GetFirmware },
+
+ {NULL, "\x00",0x00,0x00,ID_None }
+};
+
+GSM_Phone_Functions N3320Phone = {
+ "3320",
+ N3320ReplyFunctions,
+ NOTSUPPORTED, /* Install */
+ NONEFUNCTION, /* Initialise */
+ NONEFUNCTION, /* Terminate */
+ GSM_DispatchMessage,
+ NOTSUPPORTED, /* ShowStartInfo */
+ NOKIA_GetManufacturer,
+ DCT3DCT4_GetModel,
+ DCT3DCT4_GetFirmware,
+ NOTSUPPORTED, /* GetIMEI */
+ NOTSUPPORTED, /* GetOriginalIMEI */
+ NOTSUPPORTED, /* GetManufactureMonth */
+ NOTSUPPORTED, /* GetProductCode */
+ NOTSUPPORTED, /* GetHardware */
+ NOTSUPPORTED, /* GetPPM */
+ NOTSUPPORTED, /* GetSIMIMSI */
+ N3320_GetDateTime,
+ NOTSUPPORTED, /* SetDateTime */
+ NOTSUPPORTED, /* GetAlarm */
+ NOTSUPPORTED, /* SetAlarm */
+ NOTSUPPORTED, /* GetLocale */
+ NOTSUPPORTED, /* SetLocale */
+ NOTSUPPORTED, /* PressKey */
+ NOTSUPPORTED, /* Reset */
+ NOTSUPPORTED, /* ResetPhoneSettings */
+ NOTSUPPORTED, /* EnterSecurityCode */
+ NOTSUPPORTED, /* GetSecurityStatus */
+ NOTSUPPORTED, /* GetDisplayStatus */
+ NOTSUPPORTED, /* SetAutoNetworkLogin */
+ NOTSUPPORTED, /* GetBatteryCharge */
+ NOTSUPPORTED, /* GetSignalQuality */
+ NOTSUPPORTED, /* GetNetworkInfo */
+ NOTSUPPORTED, /* GetCategory */
+ NOTSUPPORTED, /* AddCategory */
+ NOTSUPPORTED, /* GetCategoryStatus */
+ N3320_GetMemoryStatus,
+ N3320_GetMemory,
+ NOTSUPPORTED, /* GetNextMemory */
+ NOTSUPPORTED, /* SetMemory */
+ NOTSUPPORTED, /* AddMemory */
+ NOTSUPPORTED, /* DeleteMemory */
+ NOTIMPLEMENTED, /* DeleteAllMemory */
+ NOTSUPPORTED, /* GetSpeedDial */
+ NOTSUPPORTED, /* SetSpeedDial */
+ NOTSUPPORTED, /* GetSMSC */
+ NOTSUPPORTED, /* SetSMSC */
+ NOTSUPPORTED, /* GetSMSStatus */
+ NOTSUPPORTED, /* GetSMS */
+ NOTSUPPORTED, /* GetNextSMS */
+ NOTSUPPORTED, /* SetSMS */
+ NOTSUPPORTED, /* AddSMS */
+ NOTSUPPORTED, /* DeleteSMS */
+ NOTSUPPORTED, /* SendSMS */
+ NOTSUPPORTED, /* SendSavedSMS */
+ NOTSUPPORTED, /* SetFastSMSSending */
+ NOTSUPPORTED, /* SetIncomingSMS */
+ NOTSUPPORTED, /* SetIncomingCB */
+ NOTSUPPORTED, /* GetSMSFolders */
+ NOTSUPPORTED, /* AddSMSFolder */
+ NOTSUPPORTED, /* DeleteSMSFolder */
+ NOTIMPLEMENTED, /* DialVoice */
+ NOTIMPLEMENTED, /* DialService */
+ NOTIMPLEMENTED, /* AnswerCall */
+ NOTIMPLEMENTED, /* CancelCall */
+ NOTIMPLEMENTED, /* HoldCall */
+ NOTIMPLEMENTED, /* UnholdCall */
+ NOTIMPLEMENTED, /* ConferenceCall */
+ NOTIMPLEMENTED, /* SplitCall */
+ NOTIMPLEMENTED, /* TransferCall */
+ NOTIMPLEMENTED, /* SwitchCall */
+ NOTSUPPORTED, /* GetCallDivert */
+ NOTSUPPORTED, /* SetCallDivert */
+ NOTSUPPORTED, /* CancelAllDiverts */
+ NOTIMPLEMENTED, /* SetIncomingCall */
+ NOTIMPLEMENTED, /* SetIncomingUSSD */
+ NOTSUPPORTED, /* SendDTMF */
+ NOTSUPPORTED, /* GetRingtone */
+ NOTSUPPORTED, /* SetRingtone */
+ NOTSUPPORTED, /* GetRingtonesInfo */
+ NOTIMPLEMENTED, /* DeleteUserRingtones */
+ NOTSUPPORTED, /* PlayTone */
+ NOTSUPPORTED, /* GetWAPBookmark */
+ NOTSUPPORTED, /* SetWAPBookmark */
+ NOTSUPPORTED, /* DeleteWAPBookmark */
+ NOTSUPPORTED, /* GetWAPSettings */
+ NOTSUPPORTED, /* SetWAPSettings */
+ NOTSUPPORTED, /* GetSyncMLSettings */
+ NOTSUPPORTED, /* SetSyncMLSettings */
+ NOTSUPPORTED, /* GetChatSettings */
+ NOTSUPPORTED, /* SetChatSettings */
+ NOTSUPPORTED, /* GetMMSSettings */
+ NOTSUPPORTED, /* SetMMSSettings */
+ NOTSUPPORTED, /* GetMMSFolders */
+ NOTSUPPORTED, /* GetNextMMSFile */
+ NOTSUPPORTED, /* GetBitmap */
+ NOTSUPPORTED, /* SetBitmap */
+ NOTSUPPORTED, /* GetToDoStatus */
+ NOTSUPPORTED, /* GetToDo */
+ NOTSUPPORTED, /* GetNextToDo */
+ NOTSUPPORTED, /* SetToDo */
+ NOTSUPPORTED, /* AddToDo */
+ NOTSUPPORTED, /* DeleteToDo */
+ NOTSUPPORTED, /* DeleteAllToDo */
+ N3320_GetCalendarStatus,
+ NOTIMPLEMENTED, /* GetCalendar */
+ N3320_GetNextCalendar,
+ NOTIMPLEMENTED, /* SetCalendar */
+ NOTSUPPORTED, /* AddCalendar */
+ NOTSUPPORTED, /* DeleteCalendar */
+ NOTIMPLEMENTED, /* DeleteAllCalendar */
+ NOTSUPPORTED, /* GetCalendarSettings */
+ NOTSUPPORTED, /* SetCalendarSettings */
+ NOTSUPPORTED, /* GetNoteStatus */
+ NOTSUPPORTED, /* GetNote */
+ NOTSUPPORTED, /* GetNextNote */
+ NOTSUPPORTED, /* SetNote */
+ NOTSUPPORTED, /* AddNote */
+ NOTSUPPORTED, /* DeleteNote */
+ NOTSUPPORTED, /* DeleteAllNotes */
+ NOTSUPPORTED, /* GetProfile */
+ NOTSUPPORTED, /* SetProfile */
+ NOTSUPPORTED, /* GetFMStation */
+ NOTSUPPORTED, /* SetFMStation */
+ NOTSUPPORTED, /* ClearFMStations */
+ NOTSUPPORTED, /* GetNextFileFolder */
+ NOTSUPPORTED, /* GetFolderListing */
+ NOTSUPPORTED, /* GetNextRootFolder */
+ NOTSUPPORTED, /* SetFileAttributes */
+ NOTSUPPORTED, /* GetFilePart */
+ NOTIMPLEMENTED, /* AddFilePart */
+ NOTSUPPORTED, /* SendFilePart */
+ NOTSUPPORTED, /* GetFileSystemStatus */
+ NOTIMPLEMENTED, /* DeleteFile */
+ NOTIMPLEMENTED, /* AddFolder */
+ NOTSUPPORTED, /* DeleteFolder */
+ NOTSUPPORTED, /* GetGPRSAccessPoint */
+ NOTSUPPORTED, /* SetGPRSAccessPoint */
+ NOTSUPPORTED, /* GetScreenshot */
+ NOTSUPPORTED, /* SetPower */
+ NOTSUPPORTED, /* PostConnect */
+ NONEFUNCTION /* PreAPICall */
+};
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/dct4s40/n3320.h b/libgammu/phone/nokia/dct4s40/n3320.h
new file mode 100644
index 0000000..f50cf82
--- /dev/null
+++ b/libgammu/phone/nokia/dct4s40/n3320.h
@@ -0,0 +1,29 @@
+/* (c) 2004 by Marcin Wiacek */
+
+#ifndef n3320_h
+#define n3320_h
+
+#include "../ncommon.h"
+
+#ifndef GSM_USED_MBUS2
+# define GSM_USED_MBUS2
+#endif
+#ifndef GSM_USED_FBUS2
+# define GSM_USED_FBUS2
+#endif
+
+typedef struct {
+ int LastCalendarYear;
+ int LastCalendarPos;
+ GSM_NOKIACalToDoLocations LastCalendar;
+ int FirstCalendarPos;
+ unsigned char CalendarIcons[10];
+ GSM_CalendarNoteType CalendarIconsTypes[10];
+ int CalendarIconsNum;
+} GSM_Phone_N3320Data;
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/nauto.c b/libgammu/phone/nokia/nauto.c
new file mode 100644
index 0000000..6633723
--- /dev/null
+++ b/libgammu/phone/nokia/nauto.c
@@ -0,0 +1,187 @@
+/* (c) 2002-2003 by Marcin Wiacek */
+
+#include <string.h>
+#include <time.h>
+
+#include "../../gsmcomon.h"
+#include "../../gsmstate.h"
+#include "nfunc.h"
+
+#if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4)
+
+static GSM_Reply_Function NAUTOReplyFunctions[] = {
+ {DCT3DCT4_ReplyGetModelFirmware,"\xD2",0x02,0x00,ID_GetModel },
+ {DCT3DCT4_ReplyGetModelFirmware,"\xD2",0x02,0x00,ID_GetFirmware },
+
+ {NULL, "\x00",0x00,0x00,ID_None }
+};
+
+/**
+ * Some phones/cables need some time to initialize, this function gives
+ * them the time while not slowing down the usual case (GetModel is
+ * anyway later called).
+ */
+static GSM_Error NAUTO_Initialise(GSM_StateMachine *s)
+{
+ GSM_Error error = ERR_TIMEOUT;
+ int repeats = 3;
+
+ while (repeats > 0 && error == ERR_TIMEOUT) {
+ error = DCT3DCT4_GetModel(s);
+ if (error == ERR_NONE) return ERR_NONE;
+ repeats--;
+ }
+
+ return error;
+}
+
+GSM_Phone_Functions NAUTOPhone = {
+ "NAUTO",
+ NAUTOReplyFunctions,
+ NOTSUPPORTED, /* Install */
+ NAUTO_Initialise, /* Initialise */
+ NONEFUNCTION, /* Terminate */
+ GSM_DispatchMessage,
+ NOTSUPPORTED, /* ShowStartInfo */
+ NOKIA_GetManufacturer,
+ DCT3DCT4_GetModel,
+ DCT3DCT4_GetFirmware,
+ NOTSUPPORTED, /* GetIMEI */
+ NOTSUPPORTED, /* GetOriginalIMEI */
+ NOTSUPPORTED, /* GetManufactureMonth */
+ NOTSUPPORTED, /* GetProductCode */
+ NOTSUPPORTED, /* GetHardware */
+ NOTSUPPORTED, /* GetPPM */
+ NOTSUPPORTED, /* GetSIMIMSI */
+ NOTSUPPORTED, /* GetDateTime */
+ NOTSUPPORTED, /* SetDateTime */
+ NOTSUPPORTED, /* GetAlarm */
+ NOTSUPPORTED, /* SetAlarm */
+ NOTSUPPORTED, /* GetLocale */
+ NOTSUPPORTED, /* SetLocale */
+ NOTSUPPORTED, /* PressKey */
+ NOTSUPPORTED, /* Reset */
+ NOTSUPPORTED, /* ResetPhoneSettings */
+ NOTSUPPORTED, /* EnterSecurityCode */
+ NOTSUPPORTED, /* GetSecurityStatus */
+ NOTSUPPORTED, /* GetDisplayStatus */
+ NOTSUPPORTED, /* SetAutoNetworkLogin */
+ NOTSUPPORTED, /* GetBatteryCharge */
+ NOTSUPPORTED, /* GetSignalQuality */
+ NOTSUPPORTED, /* GetNetworkInfo */
+ NOTSUPPORTED, /* GetCategory */
+ NOTSUPPORTED, /* AddCategory */
+ NOTSUPPORTED, /* GetCategoryStatus */
+ NOTSUPPORTED, /* GetMemoryStatus */
+ NOTSUPPORTED, /* GetMemory */
+ NOTSUPPORTED, /* GetNextMemory */
+ NOTSUPPORTED, /* SetMemory */
+ NOTSUPPORTED, /* AddMemory */
+ NOTSUPPORTED, /* DeleteMemory */
+ NOTIMPLEMENTED, /* DeleteAllMemory */
+ NOTSUPPORTED, /* GetSpeedDial */
+ NOTSUPPORTED, /* SetSpeedDial */
+ NOTSUPPORTED, /* GetSMSC */
+ NOTSUPPORTED, /* SetSMSC */
+ NOTSUPPORTED, /* GetSMSStatus */
+ NOTSUPPORTED, /* GetSMS */
+ NOTSUPPORTED, /* GetNextSMS */
+ NOTSUPPORTED, /* SetSMS */
+ NOTSUPPORTED, /* AddSMS */
+ NOTSUPPORTED, /* DeleteSMS */
+ NOTSUPPORTED, /* SendSMSMessage */
+ NOTSUPPORTED, /* SendSavedSMS */
+ NOTSUPPORTED, /* SetFastSMSSending */
+ NOTSUPPORTED, /* SetIncomingSMS */
+ NOTSUPPORTED, /* SetIncomingCB */
+ NOTSUPPORTED, /* GetSMSFolders */
+ NOTSUPPORTED, /* AddSMSFolder */
+ NOTSUPPORTED, /* DeleteSMSFolder */
+ NOTSUPPORTED, /* DialVoice */
+ NOTIMPLEMENTED, /* DialService */
+ NOTSUPPORTED, /* AnswerCall */
+ NOTSUPPORTED, /* CancelCall */
+ NOTSUPPORTED, /* HoldCall */
+ NOTSUPPORTED, /* UnholdCall */
+ NOTSUPPORTED, /* ConferenceCall */
+ NOTSUPPORTED, /* SplitCall */
+ NOTSUPPORTED, /* TransferCall */
+ NOTSUPPORTED, /* SwitchCall */
+ NOTSUPPORTED, /* GetCallDivert */
+ NOTSUPPORTED, /* SetCallDivert */
+ NOTSUPPORTED, /* CancelAllDiverts */
+ NOTSUPPORTED, /* SetIncomingCall */
+ NOTSUPPORTED, /* SetIncomingUSSD */
+ NOTSUPPORTED, /* SendDTMF */
+ NOTSUPPORTED, /* GetRingtone */
+ NOTSUPPORTED, /* SetRingtone */
+ NOTSUPPORTED, /* GetRingtonesInfo */
+ NOTSUPPORTED, /* DeleteUserRingtones */
+ NOTSUPPORTED, /* PlayTone */
+ NOTSUPPORTED, /* GetWAPBookmark */
+ NOTSUPPORTED, /* SetWAPBookmark */
+ NOTSUPPORTED, /* DeleteWAPBookmark */
+ NOTSUPPORTED, /* GetWAPSettings */
+ NOTSUPPORTED, /* SetWAPSettings */
+ NOTSUPPORTED, /* GetSyncMLSettings */
+ NOTSUPPORTED, /* SetSyncMLSettings */
+ NOTSUPPORTED, /* GetChatSettings */
+ NOTSUPPORTED, /* SetChatSettings */
+ NOTSUPPORTED, /* GetMMSSettings */
+ NOTSUPPORTED, /* SetMMSSettings */
+ NOTSUPPORTED, /* GetMMSFolders */
+ NOTSUPPORTED, /* GetNextMMSFileInfo */
+ NOTSUPPORTED, /* GetBitmap */
+ NOTSUPPORTED, /* SetBitmap */
+ NOTSUPPORTED, /* GetToDoStatus */
+ NOTSUPPORTED, /* GetToDo */
+ NOTSUPPORTED, /* GetNextToDo */
+ NOTSUPPORTED, /* SetToDo */
+ NOTSUPPORTED, /* AddToDo */
+ NOTSUPPORTED, /* DeleteToDo */
+ NOTSUPPORTED, /* DeleteAllToDo */
+ NOTSUPPORTED, /* GetCalendarStatus */
+ NOTSUPPORTED, /* GetCalendar */
+ NOTSUPPORTED, /* GetNextCalendar */
+ NOTSUPPORTED, /* SetCalendar */
+ NOTSUPPORTED, /* AddCalendar */
+ NOTSUPPORTED, /* DeleteCalendar */
+ NOTSUPPORTED, /* DeleteAllCalendar */
+ NOTSUPPORTED, /* GetCalendarSettings */
+ NOTSUPPORTED, /* SetCalendarSettings */
+ NOTSUPPORTED, /* GetNoteStatus */
+ NOTSUPPORTED, /* GetNote */
+ NOTSUPPORTED, /* GetNextNote */
+ NOTSUPPORTED, /* SetNote */
+ NOTSUPPORTED, /* AddNote */
+ NOTSUPPORTED, /* DeleteNote */
+ NOTSUPPORTED, /* DeleteAllNotes */
+ NOTSUPPORTED, /* GetProfile */
+ NOTSUPPORTED, /* SetProfile */
+ NOTSUPPORTED, /* GetFMStation */
+ NOTSUPPORTED, /* SetFMStation */
+ NOTSUPPORTED, /* ClearFMStations */
+ NOTSUPPORTED, /* GetNextFileFolder */
+ NOTSUPPORTED, /* GetFolderListing */
+ NOTSUPPORTED, /* GetNextRootFolder */
+ NOTSUPPORTED, /* SetFileAttributes */
+ NOTSUPPORTED, /* GetFilePart */
+ NOTSUPPORTED, /* AddFilePart */
+ NOTSUPPORTED, /* SendFilePart */
+ NOTSUPPORTED, /* GetFileSystemStatus */
+ NOTSUPPORTED, /* DeleteFile */
+ NOTSUPPORTED, /* AddFolder */
+ NOTSUPPORTED, /* DeleteFolder */
+ NOTSUPPORTED, /* GetGPRSAccessPoint */
+ NOTSUPPORTED, /* SetGPRSAccessPoint */
+ NOTSUPPORTED, /* GetScreenshot */
+ NOTSUPPORTED, /* SetPower */
+ NOTSUPPORTED, /* PostConnect */
+ NONEFUNCTION /* PreAPICall */
+};
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/ncommon.h b/libgammu/phone/nokia/ncommon.h
new file mode 100644
index 0000000..817b442
--- /dev/null
+++ b/libgammu/phone/nokia/ncommon.h
@@ -0,0 +1,103 @@
+/* (c) 2001-2005 by Marcin Wiacek */
+
+#ifndef phone_nokia_common_h
+#define phone_nokia_common_h
+
+#include <gammu-limits.h>
+
+#define N6110_FRAME_HEADER 0x00, 0x01, 0x00
+#define N7110_FRAME_HEADER 0x00, 0x01, 0x01
+
+typedef enum {
+ MEM7110_CG = 0xf0, /* Caller groups memory */
+ MEM7110_SP = 0xf1, /* Speed dial memory */
+
+ MEM6510_CG2 = 0x23 /* Caller groups 2 memory */
+} GSM_71_65MemoryType;
+
+typedef enum {
+ /* DCT3 and DCT4 */
+ N7110_PBK_SIM_SPEEDDIAL = 0x04, /* Speed dial on SIM */
+ N7110_PBK_NAME = 0x07, /* Text: name (always the only one) */
+ N7110_PBK_EMAIL = 0x08, /* Text: email adress */
+ N7110_PBK_POSTAL = 0x09, /* Text: postal address */
+ N7110_PBK_NOTE = 0x0A, /* Text: note */
+ N7110_PBK_NUMBER = 0x0B, /* Phone number */
+ N7110_PBK_RINGTONE_ID = 0x0C, /* Ringtone ID */
+ N7110_PBK_DATETIME = 0x13, /* Call register: date and time */
+ N7110_PBK_MISSED = 0x19, /* Call register: with missed calls */
+ N7110_PBK_SPEEDDIAL = 0x1A, /* Speed dial */
+ N7110_PBK_GROUPLOGO = 0x1B, /* Caller group: logo */
+ N7110_PBK_LOGOON = 0x1C, /* Caller group: is logo on ? */
+ N7110_PBK_GROUP = 0x1E, /* Caller group number in pbk entry */
+ N7110_PBK_UNKNOWN2 = 0x1F, /* Mystery entry on Nokia 6700 */
+ N7110_PBK_UNKNOWN3 = 0x7E, /* Mystery entry on Nokia 6700 */
+
+ /* DCT4 only */
+ N6510_PBK_URL = 0x2C, /* Text: URL address */
+ N6510_PBK_SMSLIST_ID = 0x2E, /* SMS list assignment */
+ N6510_PBK_VOICETAG_ID = 0x2F, /* Voice tag assignment */
+ N6510_PBK_PICTURE_ID = 0x33, /* Picture ID assignment */
+ N6510_PBK_RINGTONEFILE_ID= 0x37, /* Ringtone ID from filesystem/internal*/
+ N6510_PBK_USER_ID = 0x38, /* Text: user ID */
+ N6510_PBK_UNKNOWN2 = 0x3B, /* conversation list ID ? */
+ N6510_PBK_UNKNOWN3 = 0x3C, /* Instant Messaging service list ID ? */
+ N6510_PBK_UNKNOWN4 = 0x3D, /* presence list ID ? */
+ N6510_PBK_PUSHTOTALK_ID = 0x3F, /* SIP Address (Push to Talk address) */
+ N6510_PBK_UNKNOWN5 = 0x42, /* Unknown so far */
+ N6510_PBK_GROUP2_ID = 0x43, /* Caller group type 2 ID (6230i,later)*/
+
+ /* Series 40 3.0 */
+ S4030_PBK_CALLLENGTH = 0x44,
+ S4030_PBK_FIRSTNAME = 0x46,
+ S4030_PBK_LASTNAME = 0x47,
+ S4030_PBK_POSTAL = 0x4A,
+
+ S4030_PBK_FORMALNAME = 0x52,
+ S4030_PBK_JOBTITLE = 0x54,
+ S4030_PBK_COMPANY = 0x55,
+ S4030_PBK_NICKNAME = 0x56,
+ S4030_PBK_BIRTHDAY = 0x57,
+
+ /* Unknown/Other series */
+ N2630_PBK_FAVMESSAGING = 0x65,
+ N3600_PBK_UNKNOWN1 = 0x7b, /* Unknown so far */
+ N6303_PBK_UNKNOWN1 = 0x8b,
+ N6303_PBK_UNKNOWN2 = 0x8e,
+} GSM_71_65_Phonebook_Entries_Types;
+
+typedef enum {
+ N7110_PBK_NUMBER_HOME = 0x02,
+ N7110_PBK_NUMBER_MOBILE = 0x03,
+ N7110_PBK_NUMBER_FAX = 0x04,
+ N7110_PBK_NUMBER_WORK = 0x06,
+ N7110_PBK_NUMBER_GENERAL = 0x0A
+} GSM_71_65_Phonebook_Number_Types;
+
+typedef enum {
+ S4030_PBK_POSTAL_EXTADDRESS = 0x4B,
+ S4030_PBK_POSTAL_STREET = 0x4C,
+ S4030_PBK_POSTAL_CITY = 0x4D,
+ S4030_PBK_POSTAL_STATE = 0x4E,
+ S4030_PBK_POSTAL_POSTAL = 0x4F,
+ S4030_PBK_POSTAL_COUNTRY = 0x50
+} GSM_Series40_30_Phonebook_Postal_Types;
+
+typedef struct {
+ unsigned int Location[GSM_PHONE_MAXSMSINFOLDER + 1]; /* locations of SMS messages in that folder */
+ int Number; /* number of SMS messages in that folder */
+} GSM_NOKIASMSFolder;
+
+typedef struct {
+ int Location[GSM_MAXCALENDARTODONOTES + 1];
+ int Number;
+} GSM_NOKIACalToDoLocations;
+
+#define NOKIA_PRESSPHONEKEY 0x01
+#define NOKIA_RELEASEPHONEKEY 0x02
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/nfunc.c b/libgammu/phone/nokia/nfunc.c
new file mode 100644
index 0000000..c5ab6e3
--- /dev/null
+++ b/libgammu/phone/nokia/nfunc.c
@@ -0,0 +1,2713 @@
+/* (c) 2002-2005 by Marcin Wiacek */
+/* based on some work from Ralf Thelen, Gabriele Zappi and MyGnokii */
+
+#include <string.h> /* memcpy only */
+#include <stdio.h>
+#include <ctype.h>
+#include <time.h>
+
+#include <gammu-nokia.h>
+
+#include "../../gsmstate.h"
+#include "../../gsmphones.h"
+#include "../../misc/coding/coding.h"
+#include "../../misc/locales.h"
+#include "../../service/gsmnet.h"
+#include "../../service/gsmlogo.h"
+#include "../../service/gsmcal.h"
+#include "../pfunc.h"
+#include "nfunc.h"
+
+unsigned char N71_65_MEMORY_TYPES[] = {
+ MEM_DC, 0x01,
+ MEM_MC, 0x02,
+ MEM_RC, 0x03,
+ MEM_ME, 0x05,
+ MEM_SM, 0x06,
+ MEM_VM, 0x09,
+ MEM7110_SP, 0x0e,
+ MEM7110_CG, 0x10,
+ MEM_ON, 0x17,
+ MEM6510_CG2, 0x23,
+ MEM_SL, 0x27,
+ 0x00, 0x00
+};
+
+size_t N71_65_PackPBKBlock(GSM_StateMachine *s, int id, size_t size, int no, unsigned char *buf, unsigned char *block)
+{
+ smprintf(s, "Packing phonebook block with ID = %i, block number = %i, block length = %ld\n",
+ id,
+ no+1,
+ (long)size+6);
+
+ block[0] = id;
+ block[1] = 0;
+ block[2] = (size + 6) / 256;
+ block[3] = (size + 6) % 256;
+ block[4] = no + 1;
+ memcpy(block+5, buf, size);
+ block[5+size] = 0;
+
+ return (size + 6);
+}
+
+size_t N71_65_EncodePhonebookFrame(GSM_StateMachine *s, unsigned char *req, GSM_MemoryEntry *entry, size_t *block2, gboolean DCT4, gboolean VoiceTag)
+{
+ int count=0, len, i, block=0, j;
+ unsigned char string[500];
+ unsigned char type;
+ gboolean found;
+
+ for (i = 0; i < entry->EntriesNum; i++) {
+ entry->Entries[i].AddError = ERR_NOTSUPPORTED;
+ }
+ memset(string,0,sizeof(string));
+ found = FALSE;
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ for (i = 0; i < entry->EntriesNum; i++) {
+ if (entry->Entries[i].EntryType == PBK_Text_LastName ||
+ entry->Entries[i].EntryType == PBK_Text_FirstName) {
+ if (entry->Entries[i].EntryType==PBK_Text_LastName) {
+ type = S4030_PBK_LASTNAME;
+ } else {
+ type = S4030_PBK_FIRSTNAME;
+ }
+ found = TRUE;
+ entry->Entries[i].AddError = ERR_NONE;
+ len = MIN(UnicodeLength(entry->Entries[i].Text), 126);
+ string[0] = len*2+2;
+ CopyUnicodeString(string+1,entry->Entries[i].Text);
+ string[len*2+1] = 0;
+ count += N71_65_PackPBKBlock(s, type, len * 2 + 2, block++, string, req + count);
+ }
+ }
+ for (i = 0; i < entry->EntriesNum; i++) {
+ if(entry->Entries[i].EntryType==PBK_Text_Name) {
+ if (!found) {
+ entry->Entries[i].AddError = ERR_NONE;
+ type = N7110_PBK_NAME;
+ len = MIN(UnicodeLength(entry->Entries[i].Text), 126);
+ string[0] = len*2+2;
+ CopyUnicodeString(string+1,entry->Entries[i].Text);
+ string[len*2+1] = 0;
+ count += N71_65_PackPBKBlock(s, type, len * 2 + 2, block++, string, req + count);
+ found = TRUE;
+ } else {
+ entry->Entries[i].AddError = ERR_INVALIDDATA;
+ }
+ }
+ }
+ } else {
+ for (i = 0; i < entry->EntriesNum; i++) {
+ if (entry->Entries[i].EntryType == PBK_Text_LastName ||
+ entry->Entries[i].EntryType == PBK_Text_FirstName) {
+ if (UnicodeLength(string+1) > 0) {
+ string[UnicodeLength(string+1)*2+1] = ' ';
+ }
+ CopyUnicodeString(string+UnicodeLength(string+1)*2+1,entry->Entries[i].Text);
+ entry->Entries[i].AddError = ERR_DATACONVERTED;
+ found=TRUE;
+ }
+ }
+ if (UnicodeLength(string+1) != 0) {
+ type = N7110_PBK_NAME;
+ len = MIN(UnicodeLength(string+1), 126);
+ string[0] = len*2+2;
+ string[len*2+1] = 0;
+ count += N71_65_PackPBKBlock(s, type, len * 2 + 2, block++, string, req + count);
+ }
+ for (i = 0; i < entry->EntriesNum; i++) {
+ if (entry->Entries[i].EntryType==PBK_Text_Name) {
+ if (!found) {
+ entry->Entries[i].AddError = ERR_NONE;
+ type = N7110_PBK_NAME;
+ len = MIN(UnicodeLength(entry->Entries[i].Text), 126);
+ string[0] = len*2+2;
+ CopyUnicodeString(string+1,entry->Entries[i].Text);
+ string[len*2+1] = 0;
+ count += N71_65_PackPBKBlock(s, type, len * 2 + 2, block++, string, req + count);
+ found = TRUE;
+ } else {
+ entry->Entries[i].AddError = ERR_INVALIDDATA;
+ }
+ }
+ }
+ }
+ for (i = 0; i < entry->EntriesNum; i++) {
+ type = 0;
+ if (entry->Entries[i].EntryType == PBK_Number_General && entry->Entries[i].Location == PBK_Location_Work) type = N7110_PBK_NUMBER_WORK;
+ else if (entry->Entries[i].EntryType == PBK_Number_General && entry->Entries[i].Location == PBK_Location_Home) type = N7110_PBK_NUMBER_HOME;
+ else if (entry->Entries[i].EntryType == PBK_Number_General) type = N7110_PBK_NUMBER_GENERAL;
+ if (entry->Entries[i].EntryType == PBK_Number_Mobile) type = N7110_PBK_NUMBER_MOBILE;
+ if (entry->Entries[i].EntryType == PBK_Number_Fax) type = N7110_PBK_NUMBER_FAX;
+ if (type != 0) {
+ entry->Entries[i].AddError = ERR_NONE;
+
+ string[0] = type;
+ len = MIN(UnicodeLength(entry->Entries[i].Text), 126);
+
+ string[1] = 0;
+ string[2] = 0;
+
+ /* DCT 3 */
+ if (!DCT4) string[2] = entry->Entries[i].VoiceTag;
+
+ string[3] = 0;
+ string[4] = len*2+2;
+ CopyUnicodeString(string+5,entry->Entries[i].Text);
+ string[len * 2 + 5] = 0;
+ count += N71_65_PackPBKBlock(s, N7110_PBK_NUMBER, len*2+6, block++, string, req+count);
+
+ /* DCT 4 */
+ if (DCT4 && VoiceTag) {
+ block++;
+ req[count++] = N6510_PBK_VOICETAG_ID;
+ req[count++] = 0;
+ req[count++] = 0;
+ req[count++] = 8;
+ req[count++] = 0x00;
+ req[count++] = i+1;
+ req[count++] = 0x00;
+ req[count++] = entry->Entries[i].VoiceTag;
+ }
+ if (DCT4) {
+ j = 0;
+ while (entry->Entries[i].SMSList[j] != 0) {
+ string[0] = i+1;
+ string[1] = 0x00;
+ string[2] = 0x02;
+ string[3] = 0x00;
+ string[4] = entry->Entries[i].SMSList[j];
+ string[5] = 0x00;
+ count += N71_65_PackPBKBlock(s, N6510_PBK_SMSLIST_ID, 6, block++, string, req+count);
+
+ j++;
+ }
+ }
+ continue;
+ }
+ smprintf(s, "entry num %i %i\n",i,entry->EntriesNum);
+ if (entry->Entries[i].EntryType == PBK_Text_Note) type = N7110_PBK_NOTE;
+ if (entry->Entries[i].EntryType == PBK_Text_Postal) {
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PBKNOPOSTAL)) {
+ continue;
+ }
+ type = N7110_PBK_POSTAL;
+ }
+ if (entry->Entries[i].EntryType == PBK_Text_Email) type = N7110_PBK_EMAIL;
+ if (entry->Entries[i].EntryType == PBK_Text_Email2) type = N7110_PBK_EMAIL;
+ if (entry->Entries[i].EntryType == PBK_Text_URL) {
+ entry->Entries[i].AddError = ERR_DATACONVERTED;
+ type = N7110_PBK_NOTE;
+ if (DCT4) type = N6510_PBK_URL;
+ }
+ if (type != 0) {
+ if (entry->Entries[i].AddError==ERR_NOTSUPPORTED) entry->Entries[i].AddError = ERR_NONE;
+ len = MIN(UnicodeLength(entry->Entries[i].Text), 126);
+ string[0] = len*2+2;
+ CopyUnicodeString(string+1,entry->Entries[i].Text);
+ string[len*2+1] = 0;
+ count += N71_65_PackPBKBlock(s, type, len * 2 + 2, block++, string, req + count);
+ continue;
+ }
+ if (entry->Entries[i].EntryType == PBK_Caller_Group) {
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PBK35)) {
+ entry->Entries[i].AddError = ERR_NONE;
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_6230iCALLER)) {
+ string[0] = 0;
+ string[1] = 0;
+ count += N71_65_PackPBKBlock(s, N6510_PBK_GROUP2_ID, 2, block++, string, req + count);
+ req[count-1] = entry->Entries[i].Number;
+ } else {
+ string[0] = entry->Entries[i].Number;
+ string[1] = 0;
+ count += N71_65_PackPBKBlock(s, N7110_PBK_GROUP, 2, block++, string, req + count);
+ }
+ }
+ continue;
+ }
+ if (entry->Entries[i].EntryType == PBK_RingtoneID) {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PBK35)) {
+ entry->Entries[i].AddError = ERR_NONE;
+ string[0] = 0x00;
+ string[1] = 0x00;
+ string[2] = entry->Entries[i].Number;
+ count += N71_65_PackPBKBlock(s, N7110_PBK_RINGTONE_ID, 3, block++, string, req + count);
+ count --;
+ req[count-5] = 8;
+ }
+ continue;
+ }
+ if (entry->Entries[i].EntryType == PBK_PictureID) {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PBKIMG)) {
+ entry->Entries[i].AddError = ERR_NONE;
+ string[0] = 0x00;
+ string[1] = 0x00;
+ string[2] = 0x00;
+ string[3] = 0x00;
+ string[4] = 0x01;
+ string[5] = entry->Entries[i].Number / 256;
+ string[6] = entry->Entries[i].Number % 256;
+ string[7] = 0x00;
+ string[8] = 0x00;
+ string[9] = 0x00;
+ count += N71_65_PackPBKBlock(s, N6510_PBK_PICTURE_ID, 10, block++, string, req + count);
+ req[count-1] = 0x01;
+ }
+ continue;
+ }
+ /* Maybe we should use separate feature for these new entries... */
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_SERIES40_30)) {
+ type = 0;
+ if (entry->Entries[i].EntryType == PBK_Text_FormalName) type = S4030_PBK_FORMALNAME;
+ if (entry->Entries[i].EntryType == PBK_Text_JobTitle) type = S4030_PBK_JOBTITLE;
+ if (entry->Entries[i].EntryType == PBK_Text_Company) type = S4030_PBK_COMPANY;
+ if (entry->Entries[i].EntryType == PBK_Text_NickName) type = S4030_PBK_NICKNAME;
+ if (type != 0) {
+ if (entry->Entries[i].AddError==ERR_NOTSUPPORTED) entry->Entries[i].AddError = ERR_NONE;
+ len = MIN(UnicodeLength(entry->Entries[i].Text), 126);
+ string[0] = len*2+2;
+ CopyUnicodeString(string+1,entry->Entries[i].Text);
+ string[len*2+1] = 0;
+ count += N71_65_PackPBKBlock(s, type, len * 2 + 2, block++, string, req + count);
+ continue;
+ }
+ if (entry->Entries[i].EntryType == PBK_Date) {
+ entry->Entries[i].AddError = ERR_NONE;
+
+ NOKIA_EncodeDateTime(s, string + 1, &(entry->Entries[i].Date));
+ count += N71_65_PackPBKBlock(s, S4030_PBK_BIRTHDAY, 6, block++, string, req + count);
+ continue;
+ }
+ }
+ if (entry->Entries[i].EntryType == PBK_Text_UserID) {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PBKUSER)) {
+ entry->Entries[i].AddError = ERR_NONE;
+ string[0] = UnicodeLength(entry->Entries[i].Text)*2;
+ CopyUnicodeString(string+1,entry->Entries[i].Text);
+ count += N71_65_PackPBKBlock(s, N6510_PBK_USER_ID, string[0]+2, block++, string, req+count);
+ req[count-1]--;
+ }
+ continue;
+ }
+ if (entry->Entries[i].EntryType == PBK_PushToTalkID) {
+ entry->Entries[i].AddError = ERR_NONE;
+ string[0] = UnicodeLength(entry->Entries[i].Text)*2;
+ CopyUnicodeString(string+1,entry->Entries[i].Text);
+ count += N71_65_PackPBKBlock(s, N6510_PBK_PUSHTOTALK_ID, string[0]+2, block++, string, req+count);
+ req[count-1]--;
+ continue;
+ }
+ if (entry->Entries[i].EntryType == PBK_Number_Messaging) {
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_PBKFAVORITEMESSAGE)) {
+ entry->Entries[i].AddError = ERR_INVALIDDATA;
+ /* The favorite messaging number is stored as a phone number,
+ * the phone wants an id to a previously supplied entry, so we search for that.
+ * In case there was an error in the previous entries, we stop.
+ * Otherwise we would point past the supplied entries. */
+ for (j = 0; j < i && entry->Entries[j].AddError == ERR_NONE; j++) {
+ if (mywstrncmp(entry->Entries[i].Text, entry->Entries[j].Text, -1)) {
+ string[0] = j + 1;
+ string[1] = 0x00;
+ string[2] = 0x00;
+ count += N71_65_PackPBKBlock(s, N2630_PBK_FAVMESSAGING, 3, block++, string, req + count);
+ count --;
+ req[count-5] = 8;
+ entry->Entries[i].AddError = ERR_NONE;
+ break;
+ }
+
+ }
+ }
+ continue;
+ }
+ }
+
+ *block2=block;
+
+ return count;
+}
+
+/**
+ * Copy string to GSM_MemoryEntry
+ *
+ * Return false on failure
+ */
+static gboolean N71_65_PB_CopyString(GSM_StateMachine *s,
+ GSM_MemoryEntry *entry,
+ const unsigned char *src,
+ unsigned char length)
+{
+ if ((length & 1) != 0) {
+ smprintf(s, "String length not even\n");
+ return FALSE;
+ }
+ if (length/2 > GSM_PHONEBOOK_TEXT_LENGTH) {
+ smprintf(s, "Too long text\n");
+ return FALSE;
+ }
+ memcpy(entry->Entries[entry->EntriesNum].Text, src, length);
+ /* Zero terminate the string */
+ entry->Entries[entry->EntriesNum].Text[length] = 0;
+ entry->Entries[entry->EntriesNum].Text[length + 1] = 0;
+
+ smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
+
+ return TRUE;
+}
+
+/**
+ * Decodes nokia phonebook.
+ *
+ * \bug Type casting MemoryType to int is ugly.
+ */
+GSM_Error N71_65_DecodePhonebook(GSM_StateMachine *s,
+ GSM_MemoryEntry *entry,
+ GSM_Bitmap *bitmap,
+ GSM_SpeedDial *speed,
+ unsigned char *MessageBuffer,
+ int MessageLength,
+ gboolean DayMonthReverse)
+{
+ unsigned char *Block;
+ int length = 0, i, bs = 0;
+ GSM_EntryType Type;
+ GSM_EntryLocation Location = PBK_Location_Unknown;
+ gboolean found=FALSE;
+ gboolean foundbb5add=FALSE;
+ gboolean missed_call = FALSE;
+ int favorite_messaging_numbers[10];
+ size_t used_favorite_messaging_numbers = 0;
+
+ entry->EntriesNum = 0;
+
+ if ((int)entry->MemoryType==MEM7110_CG) {
+ bitmap->Text[0] = 0x00;
+ bitmap->Text[1] = 0x00;
+ bitmap->DefaultBitmap = TRUE;
+ bitmap->DefaultRingtone = TRUE;
+ bitmap->FileSystemPicture = FALSE;
+ }
+ if ((int)entry->MemoryType==MEM6510_CG2 && GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_6230iCALLER)) {
+ bitmap->DefaultName = FALSE;
+ bitmap->DefaultBitmap = TRUE;
+ bitmap->DefaultRingtone = TRUE;
+ bitmap->FileSystemPicture = FALSE;
+ }
+
+ Block = &MessageBuffer[0];
+ while (TRUE) {
+ entry->Entries[entry->EntriesNum].AddError = ERR_NONE;
+ entry->Entries[entry->EntriesNum].SMSList[0] = 0;
+ entry->Entries[entry->EntriesNum].VoiceTag = 0;
+ if (bs != 0) {
+ length = length + bs;
+ /* bb5 */
+ if (length >= MessageLength-1) break;
+ Block = &Block[bs];
+ }
+ bs = 256*Block[2]+Block[3];
+ if (bs == 0) break;
+#ifdef DEBUG
+ smprintf(s, "Phonebook entry block 0x%02x - length %i\n",
+ Block[0], bs-6);
+ if (GSM_GetDI(s)->dl == DL_TEXTALL || GSM_GetDI(s)->dl == DL_TEXTALLDATE)
+ DumpMessage(&s->di, Block+0, bs-1);
+#endif
+ if (entry->EntriesNum==GSM_PHONEBOOK_ENTRIES) {
+ smprintf(s, "Too many entries\n");
+ return ERR_UNKNOWNRESPONSE;
+ }
+
+ Type = 0;
+ if (Block[0] == S4030_PBK_FIRSTNAME) {
+ Type = PBK_Text_FirstName; smprintf(s,"First name ");
+ }
+ if (Block[0] == S4030_PBK_LASTNAME) {
+ Type = PBK_Text_LastName; smprintf(s,"Last name ");
+ }
+ if (Type != 0) {
+ found=TRUE;
+ if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
+ return ERR_UNKNOWNRESPONSE;
+ entry->Entries[entry->EntriesNum].EntryType=Type;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ entry->EntriesNum ++;
+ }
+ }
+
+ Block = &MessageBuffer[0];
+ bs=0;
+ length=0;
+ while (TRUE) {
+ entry->Entries[entry->EntriesNum].AddError = ERR_NONE;
+ entry->Entries[entry->EntriesNum].SMSList[0] = 0;
+ entry->Entries[entry->EntriesNum].VoiceTag = 0;
+ if (bs != 0) {
+ length = length + bs;
+ if (length >= MessageLength-1) break;
+ Block = &Block[bs];
+ }
+ bs = 256*Block[2]+Block[3];
+ smprintf(s, "Phonebook entry block 0x%02x - length %i\n",
+ Block[0], bs-6);
+ if (s->di.dl == DL_TEXTALL || s->di.dl == DL_TEXTALLDATE) {
+ DumpMessage(&s->di, Block+0, bs-1);
+ }
+ if (entry->EntriesNum >= GSM_PHONEBOOK_ENTRIES) {
+ smprintf(s, "Too many entries\n");
+ return ERR_MOREMEMORY;
+ }
+
+ Type = 0;
+ if (Block[0] == N7110_PBK_NAME) {
+ if (found) continue;
+ Type = PBK_Text_Name; smprintf(s,"Name ");
+ }
+ if (Block[0] == S4030_PBK_FIRSTNAME) continue;
+ if (Block[0] == S4030_PBK_LASTNAME) continue;
+ if (Block[0] == N7110_PBK_EMAIL) {
+ Type = PBK_Text_Email; smprintf(s,"Email ");
+ }
+ if (Block[0] == N7110_PBK_POSTAL) {
+ Type = PBK_Text_Postal; smprintf(s,"Postal ");
+ }
+ if (Block[0] == N7110_PBK_NOTE) {
+ Type = PBK_Text_Note; smprintf(s,"Text note ");
+ }
+ if (Block[0] == N6510_PBK_URL) {
+ Type = PBK_Text_URL; smprintf(s,"URL ");
+ }
+ if (Block[0] == N6510_PBK_USER_ID) {
+ Type = PBK_Text_UserID; smprintf(s,"User ID:");
+ }
+ if (Type != 0) {
+ if (Block[5]/2>GSM_PHONEBOOK_TEXT_LENGTH) {
+ smprintf(s, "Too long text\n");
+ return ERR_UNKNOWNRESPONSE;
+ }
+ /* No text? */
+ if (Block[5] < 2) {
+ entry->Entries[entry->EntriesNum].Text[0] = 0;
+ entry->Entries[entry->EntriesNum].Text[1] = 0;
+ } else {
+ memcpy(entry->Entries[entry->EntriesNum].Text,Block+6,Block[5]);
+ /* Zero terminate the string */
+ entry->Entries[entry->EntriesNum].Text[Block[5]] = 0;
+ entry->Entries[entry->EntriesNum].Text[Block[5] + 1] = 0;
+ }
+ entry->Entries[entry->EntriesNum].EntryType=Type;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ smprintf(s, " \"%s\"\n",DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
+ if (Block[0] == N7110_PBK_NAME) {
+ if ((int)entry->MemoryType == MEM7110_CG || (int)entry->MemoryType == MEM6510_CG2) {
+ /* No text? */
+ if (Block[5] < 2) {
+ bitmap->Text[0] = 0;
+ bitmap->Text[1] = 0;
+ } else {
+ memcpy(bitmap->Text,Block+6,Block[5]);
+ }
+ }
+ }
+ entry->EntriesNum ++;
+ continue;
+ }
+ if (Block[0] == N7110_PBK_DATETIME) {
+ entry->Entries[entry->EntriesNum].EntryType=PBK_Date;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ NOKIA_DecodeDateTime(s, Block+6, &entry->Entries[entry->EntriesNum].Date, TRUE, DayMonthReverse);
+ if (CheckDate(&entry->Entries[entry->EntriesNum].Date) &&
+ CheckDate(&entry->Entries[entry->EntriesNum].Date)) {
+ entry->EntriesNum ++;
+ } else {
+ smprintf(s, "Datetime seems to be invalid, ignoring!\n");
+ }
+ continue;
+ }
+ if (Block[0] == N6510_PBK_PICTURE_ID) {
+ if ((int)entry->MemoryType==MEM6510_CG2) {
+ bitmap->FileSystemPicture = TRUE;
+ smprintf(s, "Picture ID \"%i\"\n",Block[10]*256+Block[11]);
+ bitmap->PictureID = Block[10]*256+Block[11];
+ } else {
+ entry->Entries[entry->EntriesNum].EntryType=PBK_PictureID;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ smprintf(s, "Picture ID \"%i\"\n",Block[10]*256+Block[11]);
+ entry->Entries[entry->EntriesNum].Number=Block[10]*256+Block[11];
+ entry->EntriesNum ++;
+ }
+ continue;
+ }
+ if (Block[0] == N7110_PBK_NUMBER) {
+ if (Block[5] == 0x00) {
+ Type = PBK_Number_General; smprintf(s,"General number ");
+ }
+ /* Not assigned dialed number */
+ if (Block[5] == 0x01) {
+ Type = PBK_Number_General; smprintf(s,"General number ");
+ }
+ if (Block[5] == 0x0B) {
+ Type = PBK_Number_General; smprintf(s,"General number ");
+ }
+ /* In many firmwares 0x55 visible after using
+ * Save from Call Register menu and saving number
+ * to existing phonebook entry */
+ if (Block[5] == 0x55) {
+ Type = PBK_Number_General; smprintf(s,"General number ");
+ }
+ /* Yet another unknown General number */
+ if (Block[5] == 0x08) {
+ Type = PBK_Number_General; smprintf(s,"General number ");
+ }
+ if (Block[5] == N7110_PBK_NUMBER_GENERAL) {
+ Type = PBK_Number_General; smprintf(s,"General number ");
+ }
+ if (Block[5] == N7110_PBK_NUMBER_WORK) {
+ Type = PBK_Number_General; Location = PBK_Location_Work; smprintf(s,"Work number ");
+ }
+ if (Block[5] == N7110_PBK_NUMBER_FAX) {
+ Type = PBK_Number_Fax; smprintf(s,"Fax number ");
+ }
+ if (Block[5] == N7110_PBK_NUMBER_MOBILE) {
+ Type = PBK_Number_Mobile; smprintf(s,"Mobile number ");
+ }
+ if (Block[5] == N7110_PBK_NUMBER_HOME) {
+ Type = PBK_Number_General; Location = PBK_Location_Home; smprintf(s,"Home number ");
+ }
+ if (Type == 0x00) {
+ smprintf(s, "Unknown number type %02x\n",Block[5]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ entry->Entries[entry->EntriesNum].EntryType=Type;
+ entry->Entries[entry->EntriesNum].Location = Location;
+ if (! N71_65_PB_CopyString(s, entry, Block+10, Block[9]))
+ return ERR_UNKNOWNRESPONSE;
+ /* DCT3 phones like 6210 */
+ entry->Entries[entry->EntriesNum].VoiceTag = Block[7];
+#ifdef DEBUG
+ if (entry->Entries[entry->EntriesNum].VoiceTag != 0) smprintf(s, "Voice tag %i assigned\n",Block[7]);
+#endif
+ entry->Entries[entry->EntriesNum].SMSList[0] = 0;
+ entry->EntriesNum ++;
+ continue;
+ }
+ /* to checking */
+ if (Block[0] == S4030_PBK_CALLLENGTH) {
+ entry->Entries[entry->EntriesNum].CallLength = Block[9]*256*256+Block[10]*256+Block[11];
+ entry->Entries[entry->EntriesNum].EntryType=PBK_CallLength;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ entry->EntriesNum ++;
+ continue;
+ }
+ if (Block[0] == S4030_PBK_POSTAL) {
+ if (Block[5] == S4030_PBK_POSTAL_EXTADDRESS) {
+ Type = PBK_Text_Custom1; smprintf(s,"Address extension ? ");
+ }
+ if (Block[5] == S4030_PBK_POSTAL_STREET) {
+ Type = PBK_Text_StreetAddress; smprintf(s,"Street ");
+ }
+ if (Block[5] == S4030_PBK_POSTAL_CITY) {
+ Type = PBK_Text_City; smprintf(s,"City ");
+ }
+ if (Block[5] == S4030_PBK_POSTAL_STATE) {
+ Type = PBK_Text_State; smprintf(s,"State ");
+ }
+ if (Block[5] == S4030_PBK_POSTAL_POSTAL) {
+ Type = PBK_Text_Postal; smprintf(s,"Postal ");
+ }
+ if (Block[5] == S4030_PBK_POSTAL_COUNTRY) {
+ Type = PBK_Text_Country; smprintf(s,"Country ");
+ }
+ if ((Type == 0x00) && (Block[7]>0)) {
+ smprintf(s, "Found new bb5 style address\n");
+ foundbb5add=TRUE;
+ continue;
+ }
+ if (Type == 0x00) {
+ smprintf(s, "Unknown address type %02x\n",Block[5]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ entry->Entries[entry->EntriesNum].EntryType=Type;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ if (! N71_65_PB_CopyString(s, entry, Block+10, Block[9]))
+ return ERR_UNKNOWNRESPONSE;
+ entry->EntriesNum ++;
+ continue;
+ }
+
+
+ if ((Block[0] == S4030_PBK_POSTAL_EXTADDRESS) && (foundbb5add==TRUE)) {
+ Type = PBK_Text_Custom1; smprintf(s,"Address extension ? ");
+ if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
+ return ERR_UNKNOWNRESPONSE;
+ entry->Entries[entry->EntriesNum].EntryType=Type;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ entry->EntriesNum ++;
+ continue;
+ }
+ if ((Block[0] == S4030_PBK_POSTAL_STREET) && (foundbb5add==TRUE)) {
+ Type = PBK_Text_StreetAddress; smprintf(s,"Street ");
+ if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
+ return ERR_UNKNOWNRESPONSE;
+ entry->Entries[entry->EntriesNum].EntryType=Type;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ entry->EntriesNum ++;
+ continue;
+ }
+ if ((Block[0] == S4030_PBK_POSTAL_CITY) && (foundbb5add==TRUE)) {
+ Type = PBK_Text_City; smprintf(s,"City ");
+ if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
+ return ERR_UNKNOWNRESPONSE;
+ entry->Entries[entry->EntriesNum].EntryType=Type;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ entry->EntriesNum ++;
+ continue;
+ }
+ if ((Block[0] == S4030_PBK_POSTAL_STATE) && (foundbb5add==TRUE)) {
+ Type = PBK_Text_State; smprintf(s,"State ");
+ if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
+ return ERR_UNKNOWNRESPONSE;
+ entry->Entries[entry->EntriesNum].EntryType=Type;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ entry->EntriesNum ++;
+ continue;
+ }
+ if ((Block[0] == S4030_PBK_POSTAL_POSTAL) && (foundbb5add==TRUE)) {
+ Type = PBK_Text_Postal; smprintf(s,"Postal ");
+ if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
+ return ERR_UNKNOWNRESPONSE;
+ entry->Entries[entry->EntriesNum].EntryType=Type;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ entry->EntriesNum ++;
+ continue;
+ }
+ if ((Block[0] == S4030_PBK_POSTAL_COUNTRY) && (foundbb5add==TRUE)) {
+ Type = PBK_Text_Country; smprintf(s,"Country ");
+ if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
+ return ERR_UNKNOWNRESPONSE;
+ entry->Entries[entry->EntriesNum].EntryType=Type;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ entry->EntriesNum ++;
+ continue;
+ }
+ if (Block[0] == S4030_PBK_FORMALNAME) {
+ Type = PBK_Text_FormalName; smprintf(s,"FormalName ");
+ if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
+ return ERR_UNKNOWNRESPONSE;
+ entry->Entries[entry->EntriesNum].EntryType=Type;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ entry->EntriesNum ++;
+ continue;
+ }
+ if (Block[0] == S4030_PBK_JOBTITLE) {
+ Type = PBK_Text_JobTitle; smprintf(s,"JobTitle ");
+ if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
+ return ERR_UNKNOWNRESPONSE;
+ entry->Entries[entry->EntriesNum].EntryType=Type;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ entry->EntriesNum ++;
+ continue;
+ }
+ if (Block[0] == S4030_PBK_COMPANY) {
+ Type = PBK_Text_Company; smprintf(s,"Company ");
+ if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
+ return ERR_UNKNOWNRESPONSE;
+ entry->Entries[entry->EntriesNum].EntryType=Type;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ entry->EntriesNum ++;
+ continue;
+ }
+ if (Block[0] == S4030_PBK_NICKNAME) {
+ Type = PBK_Text_NickName; smprintf(s,"NickName ");
+ if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
+ return ERR_UNKNOWNRESPONSE;
+ entry->Entries[entry->EntriesNum].EntryType=Type;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ entry->EntriesNum ++;
+ continue;
+ }
+ if (Block[0] == S4030_PBK_BIRTHDAY) {
+ entry->Entries[entry->EntriesNum].EntryType=PBK_Date;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ NOKIA_DecodeDateTime(s, Block+6, &entry->Entries[entry->EntriesNum].Date, FALSE, DayMonthReverse);
+ entry->EntriesNum ++;
+ continue;
+ }
+
+
+ if (Block[0] == N7110_PBK_RINGTONE_ID) {
+ if ((int)entry->MemoryType==MEM7110_CG) {
+ bitmap->RingtoneID=Block[5];
+ if (Block[5] == 0x00) bitmap->RingtoneID=Block[7];
+ smprintf(s, "Ringtone ID : %i\n",bitmap->RingtoneID);
+ bitmap->DefaultRingtone = FALSE;
+ bitmap->FileSystemRingtone = FALSE;
+ } else {
+ entry->Entries[entry->EntriesNum].EntryType=PBK_RingtoneID;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ smprintf(s, "Ringtone ID \"%i\"\n",Block[7]);
+ entry->Entries[entry->EntriesNum].Number=Block[7];
+ entry->EntriesNum ++;
+ }
+ continue;
+ }
+ if (Block[0] == N7110_PBK_LOGOON) {
+ if ((int)entry->MemoryType==MEM7110_CG) {
+ bitmap->BitmapEnabled=(Block[5]==0x00 ? FALSE : TRUE);
+ smprintf(s, "Logo : %s\n", bitmap->BitmapEnabled==TRUE ? "enabled":"disabled");
+ } else {
+ return ERR_UNKNOWNRESPONSE;
+ }
+ continue;
+ }
+ if (Block[0] == N7110_PBK_GROUPLOGO) {
+ if ((int)entry->MemoryType==MEM7110_CG) {
+ smprintf(s, "Caller logo\n");
+ PHONE_DecodeBitmap(GSM_NokiaCallerLogo, Block+10, bitmap);
+ bitmap->DefaultBitmap = FALSE;
+ } else {
+ return ERR_UNKNOWNRESPONSE;
+ }
+ continue;
+ }
+ if (Block[0] == N7110_PBK_GROUP) {
+ entry->Entries[entry->EntriesNum].EntryType=PBK_Caller_Group;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ smprintf(s, "Caller group \"%i\"\n",Block[5]);
+ entry->Entries[entry->EntriesNum].Number=Block[5];
+ if (Block[5]!=0) entry->EntriesNum ++;
+ continue;
+ }
+ if (Block[0] == N6510_PBK_VOICETAG_ID) {
+ smprintf(s, "Entry %i has voice tag %i\n",Block[5]-1,Block[7]);
+ entry->Entries[entry->EntriesNum].VoiceTag = Block[7];
+ continue;
+ }
+
+ /* 6210 5.56, SIM speed dials or ME with 1 number */
+ if (Block[0] == N7110_PBK_SIM_SPEEDDIAL) {
+ if ((int)entry->MemoryType==MEM7110_SP) {
+#ifdef DEBUG
+ smprintf(s, "location %i\n",(Block[6]*256+Block[7]));
+#endif
+ speed->MemoryType = MEM_ME;
+ if (Block[8] == 0x06) speed->MemoryType = MEM_SM;
+ speed->MemoryLocation = (Block[6]*256+Block[7]);
+ speed->MemoryNumberID = 2;
+ } else {
+ return ERR_UNKNOWNRESPONSE;
+ }
+ continue;
+ }
+
+ if (Block[0] == N7110_PBK_SPEEDDIAL) {
+ if ((int)entry->MemoryType==MEM7110_SP) {
+#ifdef DEBUG
+ switch (Block[12]) {
+ case 0x05: smprintf(s, "ME\n"); break;
+ case 0x06: smprintf(s, "SM\n"); break;
+ default : smprintf(s, "%02x\n",Block[12]);
+ }
+ smprintf(s, "location %i, number %i in location\n",
+ (Block[6]*256+Block[7])-1,Block[14]);
+#endif
+ switch (Block[12]) {
+ case 0x05: speed->MemoryType = MEM_ME; break;
+ case 0x06: speed->MemoryType = MEM_SM; break;
+ }
+ speed->MemoryLocation = (Block[6]*256+Block[7])-1;
+ speed->MemoryNumberID = Block[14];
+ } else {
+ return ERR_UNKNOWNRESPONSE;
+ }
+ continue;
+ }
+ if (Block[0] == N6510_PBK_RINGTONEFILE_ID) {
+ smprintf(s, "Ringtone ID with possibility of using filesystem\n");
+ if ((int)entry->MemoryType==MEM7110_CG) {
+ if (Block[9] == 0x01) {
+ smprintf(s, "Filesystem ringtone ID: %02x\n",Block[10]*256+Block[11]);
+ bitmap->FileSystemRingtone = TRUE;
+ } else {
+ smprintf(s, "Internal ringtone ID: %02x\n",Block[10]*256+Block[11]);
+ bitmap->FileSystemRingtone = FALSE;
+ }
+ bitmap->RingtoneID = Block[10]*256+Block[11];
+ bitmap->DefaultRingtone = FALSE;
+ } else if ((int)entry->MemoryType==MEM6510_CG2) {
+ /* FIXME */
+ smprintf(s, "Internal ringtone ID: %02x\n",Block[10]*256+Block[11]);
+ bitmap->FileSystemRingtone = FALSE;
+ bitmap->RingtoneID = Block[10]*256+Block[11];
+ bitmap->DefaultRingtone = FALSE;
+ } else {
+ /* series 40 3.0 */
+ smprintf(s, "Filesystem ringtone ID: %02x\n",Block[10]*256+Block[11]);
+ entry->Entries[entry->EntriesNum].EntryType=PBK_RingtoneID;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ entry->Entries[entry->EntriesNum].Number=Block[10]*256+Block[11];
+ entry->EntriesNum ++;
+ }
+ continue;
+ }
+ if (Block[0] == N6510_PBK_SMSLIST_ID) {
+ smprintf(s, "Entry %i is assigned to SMS list %i\n",Block[5]-1,Block[9]);
+ i = 0;
+ while(entry->Entries[Block[5]-1].SMSList[i] != 0) i++;
+ entry->Entries[Block[5]-1].SMSList[i+1] = 0;
+ entry->Entries[Block[5]-1].SMSList[i] = Block[9];
+ continue;
+ }
+ if (Block[0] == N7110_PBK_MISSED) {
+ missed_call = TRUE;
+ smprintf(s,"Unknown entry type 0x%02x data length %d\n", Block[0], bs-6);
+ continue;
+ }
+ if (Block[0] == N7110_PBK_UNKNOWN2
+ || Block[0] == N7110_PBK_UNKNOWN3
+ || Block[0] == N3600_PBK_UNKNOWN1
+ || Block[0] == N6303_PBK_UNKNOWN1
+ || Block[0] == N6303_PBK_UNKNOWN2) {
+ smprintf(s,"Unknown entry type 0x%02x data length %d\n", Block[0], bs-6);
+ continue;
+ }
+ if (Block[0] == N6510_PBK_UNKNOWN2) {
+ smprintf(s,"Unknown entry - probably ID for conversation list\n");
+ continue;
+ }
+ if (Block[0] == N6510_PBK_UNKNOWN3) {
+ smprintf(s,"Unknown entry - probably ID for Instant Messaging service list\n");
+ continue;
+ }
+ if (Block[0] == N6510_PBK_UNKNOWN4) {
+ smprintf(s,"Unknown entry - probably ID for presence list\n");
+ continue;
+ }
+ if (Block[0] == N6510_PBK_PUSHTOTALK_ID) {
+ smprintf(s,"SIP Address (Push to Talk address)\n");
+ if (! N71_65_PB_CopyString(s, entry, Block+6, Block[5]))
+ return ERR_UNKNOWNRESPONSE;
+ entry->Entries[entry->EntriesNum].EntryType=PBK_PushToTalkID;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ entry->EntriesNum ++;
+ continue;
+ }
+ if (Block[0] == N6510_PBK_UNKNOWN5) {
+ smprintf(s,"Unknown entry\n");
+ continue;
+ }
+ if (Block[0] == N6510_PBK_GROUP2_ID) {
+ smprintf(s,"Group ID (6230i or later)\n");
+
+ entry->Entries[entry->EntriesNum].EntryType=PBK_Caller_Group;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ smprintf(s, "Caller group \"%i\"\n",Block[7]);
+ entry->Entries[entry->EntriesNum].Number=Block[7];
+ entry->EntriesNum ++;
+ continue;
+ }
+ if (Block[0] == N2630_PBK_FAVMESSAGING) {
+ if (used_favorite_messaging_numbers >= sizeof(favorite_messaging_numbers) / sizeof(int)) {
+ smprintf(s, "Too many favorite messaging numbers!\n");
+ return ERR_MOREMEMORY;
+ }
+ favorite_messaging_numbers[used_favorite_messaging_numbers] = (int)Block[5];
+ used_favorite_messaging_numbers++;
+
+ continue;
+ }
+ smprintf(s, "ERROR: unknown pbk entry 0x%02x\n",Block[0]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+
+ if (entry->EntriesNum == 0) {
+ if (missed_call) {
+ smprintf(s, "Empty entry with missed call reference, adding blank number!\n");
+ entry->Entries[entry->EntriesNum].EntryType = PBK_Number_General;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ EncodeUnicode(entry->Entries[entry->EntriesNum].Text, "", 0);
+ } else {
+ return ERR_EMPTY;
+ }
+ }
+
+ /* Process favorite messaging numbers */
+ for (i = 0; i < (int)used_favorite_messaging_numbers; i++) {
+ if (entry->EntriesNum >= GSM_PHONEBOOK_ENTRIES) {
+ smprintf(s, "Too many entries\n");
+ return ERR_MOREMEMORY;
+ }
+
+ /* The phone sends an entry id. We store it as phone number because
+ * entry->Entries doesn't retain order. */
+
+ entry->Entries[entry->EntriesNum].EntryType = PBK_Number_Messaging;
+ entry->Entries[entry->EntriesNum].Location = PBK_Location_Unknown;
+ CopyUnicodeString(entry->Entries[entry->EntriesNum].Text,entry->Entries[favorite_messaging_numbers[i] - 1].Text);
+ smprintf(s,"Marked entry #%i (%s) as favorite messaging number\n",
+ favorite_messaging_numbers[i],
+ DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
+ entry->EntriesNum ++;
+ }
+ return ERR_NONE;
+}
+
+void NOKIA_GetDefaultCallerGroupName(GSM_Bitmap *Bitmap)
+{
+ Bitmap->DefaultName = FALSE;
+ if (Bitmap->Text[0]==0x00 && Bitmap->Text[1]==0x00) {
+ Bitmap->DefaultName = TRUE;
+ switch(Bitmap->Location) {
+ case 1: EncodeUnicode(Bitmap->Text,_("Family"),strlen(_("Family")));
+ break;
+ case 2: EncodeUnicode(Bitmap->Text,_("VIP"),strlen(_("VIP")));
+ break;
+ case 3: EncodeUnicode(Bitmap->Text,_("Friends"),strlen(_("Friends")));
+ break;
+ case 4: EncodeUnicode(Bitmap->Text,_("Colleagues"),strlen(_("Colleagues")));
+ break;
+ case 5: EncodeUnicode(Bitmap->Text,_("Other"),strlen(_("Other")));
+ break;
+ }
+ }
+}
+
+void NOKIA_DecodeDateTime(GSM_StateMachine *s, unsigned char* buffer, GSM_DateTime *datetime, gboolean seconds, gboolean DayMonthReverse)
+{
+ datetime->Year = buffer[0] * 256 + buffer[1];
+ /* Sometimes reversed */
+ if (datetime->Year > 3000) {
+ datetime->Year = buffer[1] * 256 + buffer[0];
+ }
+ if (DayMonthReverse) {
+ datetime->Month = buffer[3];
+ datetime->Day = buffer[2];
+ } else {
+ datetime->Month = buffer[2];
+ datetime->Day = buffer[3];
+ }
+
+ datetime->Hour = buffer[4];
+ datetime->Minute = buffer[5];
+ if (seconds) {
+ datetime->Second = buffer[6];
+ } else {
+ datetime->Second = 0;
+ }
+ datetime->Timezone = 0;
+
+ smprintf(s, "Decoding date and time\n");
+ smprintf(s, " Time: %02d:%02d:%02d\n",
+ datetime->Hour, datetime->Minute, datetime->Second);
+ smprintf(s, " Date: %4d/%02d/%02d\n",
+ datetime->Year, datetime->Month, datetime->Day);
+}
+
+void NOKIA_EncodeDateTime(GSM_StateMachine *s UNUSED, unsigned char* buffer, GSM_DateTime *datetime)
+{
+ buffer[0] = datetime->Year / 256;
+ buffer[1] = datetime->Year % 256;
+ buffer[2] = datetime->Month;
+ buffer[3] = datetime->Day;
+
+ buffer[4] = datetime->Hour;
+ buffer[5] = datetime->Minute;
+}
+
+
+#if defined(GSM_ENABLE_NOKIA_DCT3) || defined(GSM_ENABLE_NOKIA_DCT4)
+
+/* --------------------- Some general Nokia functions ---------------------- */
+
+void NOKIA_DecodeSMSState(GSM_StateMachine *s, unsigned char state, GSM_SMSMessage *sms)
+{
+ switch (state) {
+ case 0x01 : sms->State = SMS_Read; break;
+ case 0x03 : sms->State = SMS_UnRead; break;
+ case 0x05 : sms->State = SMS_Sent; break;
+ case 0x07 : sms->State = SMS_UnSent; break;
+ default :
+ sms->State = SMS_Read;
+ smprintf(s, "Unknown SMS state: %02x\n",state);
+ break;
+ }
+}
+
+GSM_Error NOKIA_ReplyGetPhoneString(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ strcpy(s->Phone.Data.PhoneString, msg->Buffer+s->Phone.Data.StartPhoneString);
+ return ERR_NONE;
+}
+
+/* Some strings are very easy. Some header, after it required string and 0x00.
+ * We can get them using this function. We give frame to send (*string),
+ * type of message (type), pointer for buffer for response (*value), request
+ * type (request) and what is start byte in response for our string
+ */
+GSM_Error NOKIA_GetPhoneString(GSM_StateMachine *s, const unsigned char *msgframe, int msglen, unsigned char msgtype, char *retvalue, GSM_Phone_RequestID request, int startresponse)
+{
+ retvalue[0] = 0;
+ s->Phone.Data.StartPhoneString = startresponse;
+ s->Phone.Data.PhoneString = retvalue;
+ return GSM_WaitFor (s, msgframe, msglen,msgtype, 4, request);
+}
+
+GSM_Error NOKIA_GetManufacturer(GSM_StateMachine *s)
+{
+ strcpy(s->Phone.Data.Manufacturer,"Nokia");
+ return ERR_NONE;
+}
+
+/* Many functions contains such strings:
+ * (1. length/256) - exist or not
+ * 2. length%256
+ * 3. string (unicode, no termination)
+ * This function read string to output and increases counter
+ */
+void NOKIA_GetUnicodeString(GSM_StateMachine *s UNUSED, int *current, unsigned char *input, unsigned char *output, gboolean FullLength)
+{
+ int length;
+
+ if (FullLength) {
+ length = (input[*current]*256+input[*current+1])*2;
+ memcpy(output,input+(*current+2),length);
+ *current = *current + 2 + length;
+ } else {
+ length = (input[*current])*2;
+ memcpy(output,input+(*current+1),length);
+ *current = *current + 1 + length;
+ }
+
+ output[length ] = 0;
+ output[length+1] = 0;
+}
+
+int NOKIA_SetUnicodeString(GSM_StateMachine *s UNUSED, unsigned char *dest, unsigned char *string, gboolean FullLength)
+{
+ int length;
+
+ length = UnicodeLength(string);
+ if (FullLength) {
+ dest[0] = length / 256;
+ dest[1] = length % 256;
+ CopyUnicodeString(dest + 2, string);
+ return 2+length*2;
+ } else {
+ dest[0] = length % 256;
+ CopyUnicodeString(dest + 1, string);
+ return 1+length*2;
+ }
+}
+
+/* Returns correct ID for concrete memory type */
+GSM_MemoryType NOKIA_GetMemoryType(GSM_StateMachine *s UNUSED, GSM_MemoryType memory_type, unsigned char *ID)
+{
+ int i=0;
+
+ while (ID[i+1]!=0x00) {
+ if (ID[i]==memory_type) return ID[i+1];
+ i=i+2;
+ }
+ return 0xff;
+}
+
+void NOKIA_SortSMSFolderStatus(GSM_StateMachine *s, GSM_NOKIASMSFolder *Folder)
+{
+ int i,j;
+
+ if (Folder->Number!=0) {
+ /* Bouble sorting */
+ i=0;
+ while (i!=Folder->Number-1) {
+ if (Folder->Location[i]>Folder->Location[i+1]) {
+ j=Folder->Location[i];
+ Folder->Location[i]=Folder->Location[i+1];
+ Folder->Location[i+1]=j;
+ i=0;
+ } else {
+ i++;
+ }
+ }
+#ifdef DEBUG
+ smprintf(s, "Locations: ");
+ for (i=0;i<Folder->Number;i++) {
+ smprintf(s, "%i ",Folder->Location[i]);
+ }
+ smprintf(s, "\n");
+#endif
+ }
+}
+
+void NOKIA_GetDefaultProfileName(GSM_Profile *Profile)
+{
+ if (Profile->DefaultName) {
+ switch(Profile->Location) {
+ case 1: EncodeUnicode(Profile->Name,_("General"),strlen(_("General")));
+ break;
+ case 2: EncodeUnicode(Profile->Name,_("Silent"),strlen(_("Silent")));
+ break;
+ case 3: EncodeUnicode(Profile->Name,_("Meeting"),strlen(_("Meeting")));
+ break;
+ case 4: EncodeUnicode(Profile->Name,_("Outdoor"),strlen(_("Outdoor")));
+ break;
+ case 5: EncodeUnicode(Profile->Name,_("Pager"),strlen(_("Pager")));
+ break;
+ case 6: EncodeUnicode(Profile->Name,_("Car"),strlen(_("Car")));
+ break;
+ case 7: EncodeUnicode(Profile->Name,_("Headset"),strlen(_("Headset")));
+ break;
+ }
+ }
+}
+
+/* - Shared for DCT3 (n6110.c, n7110.c, n9110.c) and DCT4 (n6510.c) phones - */
+
+GSM_Error DCT3DCT4_ReplyCallDivert(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_MultiCallDivert *cd = s->Phone.Data.Divert;
+ int i,pos = 11,j;
+ size_t number_pos;
+ GSM_Error error;
+
+ switch (msg->Buffer[3]) {
+ case 0x02:
+ smprintf(s,"Message: Call divert status received\n");
+ smprintf(s," Divert type: ");
+ switch (msg->Buffer[6]) {
+ case 0x43: smprintf(s,"when busy"); break;
+ case 0x3d: smprintf(s,"when not answered"); break;
+ case 0x3e: smprintf(s,"when phone off or no coverage"); break;
+ case 0x15: smprintf(s,"all types of diverts"); break;
+ default: smprintf(s,"unknown %i",msg->Buffer[6]); break;
+ }
+ if (cd == NULL) {
+ return ERR_NONE;
+ }
+ /* 6150 */
+ if (msg->Length == 0x0b) {
+ cd->EntriesNum = 0;
+ return ERR_NONE;
+ }
+ cd->EntriesNum = msg->Buffer[10];
+ for (i=0;i<cd->EntriesNum;i++) {
+ smprintf(s,"\n Calls type : ");
+ switch (msg->Buffer[pos]) {
+ case 0x0b:
+ smprintf(s,"voice");
+ cd->Entries[i].CallType = GSM_DIVERT_VoiceCalls;
+ break;
+ case 0x0d:
+ smprintf(s,"fax");
+ cd->Entries[i].CallType = GSM_DIVERT_FaxCalls;
+ break;
+ case 0x19:
+ smprintf(s,"data");
+ cd->Entries[i].CallType = GSM_DIVERT_DataCalls;
+ break;
+ default:
+ smprintf(s,"unknown %i",msg->Buffer[pos]);
+ /* 6310i */
+ cd->EntriesNum = 0;
+ return ERR_NONE;
+ }
+ smprintf(s,"\n");
+ j = pos + 2;
+ while (msg->Buffer[j] != 0x00) j++;
+ msg->Buffer[pos+1] = j - pos - 2;
+ number_pos = pos + 1;
+ error = GSM_UnpackSemiOctetNumber(&(s->di), cd->Entries[i].Number, msg->Buffer, &number_pos, msg->Length, FALSE);
+ if (error != ERR_NONE) {
+ return error;
+ }
+ smprintf(s," Number : %s\n",DecodeUnicodeString(cd->Entries[i].Number));
+ cd->Entries[i].Timeout = msg->Buffer[pos+34];
+ smprintf(s," Timeout : %i seconds\n",msg->Buffer[pos+34]);
+ pos+=35;
+ }
+ return ERR_NONE;
+ case 0x03:
+ smprintf(s,"Message: Call divert status receiving error ?\n");
+ return ERR_UNKNOWN;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+static GSM_Error DCT3DCT4_CallDivert(GSM_StateMachine *s, GSM_CallDivert *request, GSM_MultiCallDivert *response, gboolean get)
+{
+ int length = 0x09;
+ unsigned char req[55] = {N6110_FRAME_HEADER, 0x01,
+ 0x05, /* operation = Query */
+ 0x00,
+ 0x00, /* divert type */
+ 0x00, /* call type */
+ 0x00};
+
+ if (!get) {
+ if (UnicodeLength(request->Number) == 0) {
+ req[4] = 0x04;
+ } else {
+ req[4] = 0x03;
+ req[8] = 0x01;
+ req[29] = GSM_PackSemiOctetNumber(request->Number, req + 9, FALSE);
+ req[52] = request->Timeout;
+ length = 55;
+ }
+ }
+ switch (request->DivertType) {
+ case GSM_DIVERT_AllTypes : req[6] = 0x15; break;
+ case GSM_DIVERT_Busy : req[6] = 0x43; break;
+ case GSM_DIVERT_NoAnswer : req[6] = 0x3d; break;
+ case GSM_DIVERT_OutOfReach: req[6] = 0x3e; break;
+ default : return ERR_NOTIMPLEMENTED;
+ }
+
+ switch (request->CallType) {
+ case GSM_DIVERT_AllCalls : break;
+ case GSM_DIVERT_VoiceCalls: req[7] = 0x0b; break;
+ case GSM_DIVERT_FaxCalls : req[7] = 0x0d; break;
+ case GSM_DIVERT_DataCalls : req[7] = 0x19; break;
+ default : return ERR_NOTIMPLEMENTED;
+ }
+
+ s->Phone.Data.Divert = response;
+ smprintf(s, "Call divert\n");
+ return GSM_WaitFor (s, req, length, 0x06, 10, ID_Divert);
+}
+
+GSM_Error DCT3DCT4_GetCallDivert(GSM_StateMachine *s, GSM_CallDivert *request, GSM_MultiCallDivert *response)
+{
+ return DCT3DCT4_CallDivert(s, request, response, TRUE);
+}
+
+GSM_Error DCT3DCT4_SetCallDivert(GSM_StateMachine *s, GSM_CallDivert *divert)
+{
+ return DCT3DCT4_CallDivert(s, divert, NULL, FALSE);
+}
+
+GSM_Error DCT3DCT4_CancelAllDiverts(GSM_StateMachine *s)
+{
+ GSM_MultiCallDivert divert;
+ unsigned char req[55] = {N6110_FRAME_HEADER, 0x01,
+ 0x04, /* operation = Disable */
+ 0x00,
+ 0x02, /* divert type */
+ 0x00, /* call type */
+ 0x00};
+
+ s->Phone.Data.Divert = &divert;
+ smprintf(s, "Call divert\n");
+ return GSM_WaitFor (s, req, 0x09, 0x06, 10, ID_Divert);
+}
+
+GSM_Error DCT3DCT4_ReplyGetActiveConnectSet(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ Data->WAPSettings->Active = FALSE;
+ if (Data->WAPSettings->Location - 1 == msg->Buffer[4]) {
+ Data->WAPSettings->Active = TRUE;
+ }
+ return ERR_NONE;
+}
+
+GSM_Error DCT3DCT4_GetActiveConnectSet(GSM_StateMachine *s)
+{
+ unsigned char GetSetreq[] = {N6110_FRAME_HEADER, 0x0F};
+
+ smprintf(s, "Checking, if connection settings are active\n");
+ return GSM_WaitFor (s, GetSetreq, 4, 0x3f, 4, ID_GetConnectSet);
+}
+
+GSM_Error DCT3DCT4_ReplySetActiveConnectSet(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Connection settings activated\n");
+ return ERR_NONE;
+}
+
+GSM_Error DCT3DCT4_SetActiveConnectSet(GSM_StateMachine *s, GSM_MultiWAPSettings *settings)
+{
+ unsigned char reqActivate[] = {N6110_FRAME_HEADER, 0x12,
+ 0x00}; /* Location */
+
+ if (settings->Active) {
+ reqActivate[4] = settings->Location-1;
+ smprintf(s, "Activating connection settings number %i\n",settings->Location);
+ return GSM_WaitFor (s, reqActivate, 5, 0x3f, 4, ID_SetConnectSet);
+ }
+ return ERR_NONE;
+}
+
+
+GSM_Error DCT3DCT4_SendDTMF(GSM_StateMachine *s, char *DTMFSequence)
+{
+ unsigned char req[100] = {N6110_FRAME_HEADER, 0x50,
+ 0x00}; /* Length */
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_NODTMF)) return ERR_NOTSUPPORTED;
+ if (strlen(DTMFSequence) > 100 - 5) return ERR_NOTSUPPORTED;
+
+ req[4] = strlen(DTMFSequence);
+
+ memcpy(req+5,DTMFSequence,strlen(DTMFSequence));
+
+ smprintf(s, "Sending DTMF\n");
+ return GSM_WaitFor (s, req, 5+strlen(DTMFSequence), 0x01, 4, ID_SendDTMF);
+}
+
+GSM_Error DCT3DCT4_ReplyGetWAPBookmark(GSM_Protocol_Message *msg, GSM_StateMachine *s, gboolean FullLength)
+{
+ int tmp;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ smprintf(s, "WAP bookmark received\n");
+ switch (msg->Buffer[3]) {
+ case 0x07:
+ tmp = 4;
+
+ Data->WAPBookmark->Location = msg->Buffer[tmp] * 256 + msg->Buffer[tmp+1];
+ smprintf(s, "Location: %i\n",Data->WAPBookmark->Location);
+ tmp = tmp + 2;
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPBookmark->Title, FullLength);
+ smprintf(s, "Title : \"%s\"\n",DecodeUnicodeString(Data->WAPBookmark->Title));
+
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer, Data->WAPBookmark->Address, FullLength);
+ smprintf(s, "Address : \"%s\"\n",DecodeUnicodeString(Data->WAPBookmark->Address));
+
+ return ERR_NONE;
+ case 0x08:
+ switch (msg->Buffer[4]) {
+ case 0x01:
+ smprintf(s, "Security error. Inside WAP bookmarks menu\n");
+ return ERR_INSIDEPHONEMENU;
+ case 0x02:
+ smprintf(s, "Invalid or empty\n");
+ return ERR_INVALIDLOCATION;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+GSM_Error DCT3DCT4_ReplySetWAPBookmark(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x0A:
+ smprintf(s, "WAP bookmark set OK\n");
+ return ERR_NONE;
+ case 0x0B:
+ smprintf(s, "WAP bookmark setting error\n");
+ switch (msg->Buffer[4]) {
+ case 0x01:
+ smprintf(s, "Security error. Inside WAP bookmarks menu\n");
+ return ERR_INSIDEPHONEMENU;
+ case 0x02:
+ smprintf(s, "Can't write to empty location ?\n");
+ return ERR_EMPTY;
+ case 0x04:
+ smprintf(s, "Full memory\n");
+ return ERR_FULL;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+GSM_Error DCT3DCT4_ReplyEnableConnectFunc(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Connection functions enabled\n");
+ return ERR_NONE;
+}
+
+GSM_Error DCT3DCT4_EnableWAPFunctions(GSM_StateMachine *s)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x00};
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NOWAP)) return ERR_NOTSUPPORTED;
+
+ smprintf(s, "Enabling WAP\n");
+ return GSM_WaitFor (s, req, 4, 0x3f, 4, ID_EnableConnectFunc);
+}
+
+GSM_Error DCT3DCT4_ReplyDisableConnectFunc(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Connection functions disabled\n");
+ return ERR_NONE;
+}
+
+GSM_Error DCT3DCT4_DisableConnectionFunctions(GSM_StateMachine *s)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x03};
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NOWAP)) return ERR_NOTSUPPORTED;
+
+ smprintf(s, "Disabling connection settings\n");
+ return GSM_WaitFor (s, req, 4, 0x3f, 4, ID_DisableConnectFunc);
+}
+
+GSM_Error DCT3DCT4_ReplyDelWAPBookmark(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0x0D:
+ smprintf(s, "WAP bookmark deleted OK\n");
+ return ERR_NONE;
+ case 0x0E:
+ smprintf(s, "WAP bookmark deleting error\n");
+ switch (msg->Buffer[4]) {
+ case 0x01:
+ smprintf(s, "Security error. Inside WAP bookmarks menu\n");
+ return ERR_SECURITYERROR;
+ case 0x02:
+ smprintf(s, "Invalid location\n");
+ return ERR_INVALIDLOCATION;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[4]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+GSM_Error DCT3DCT4_DeleteWAPBookmarkPart(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
+{
+ GSM_Error error;
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x0C,
+ 0x00, 0x00}; /* Location */
+
+ req[5] = bookmark->Location;
+
+ smprintf(s, "Deleting WAP bookmark\n");
+ error = GSM_WaitFor (s, req, 6, 0x3f, 4, ID_DeleteWAPBookmark);
+ if (error != ERR_NONE) {
+ if (error == ERR_INVALIDLOCATION || error == ERR_INSIDEPHONEMENU) {
+ DCT3DCT4_DisableConnectionFunctions(s);
+ }
+ return error;
+ }
+
+ return DCT3DCT4_DisableConnectionFunctions(s);
+}
+
+GSM_Error DCT3DCT4_GetWAPBookmarkPart(GSM_StateMachine *s, GSM_WAPBookmark *bookmark)
+{
+ GSM_Error error;
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x06,
+ 0x00, 0x00}; /* Location */
+
+ req[5]=bookmark->Location-1;
+
+ s->Phone.Data.WAPBookmark=bookmark;
+ smprintf(s, "Getting WAP bookmark\n");
+ error = GSM_WaitFor (s, req, 6, 0x3f, 4, ID_GetWAPBookmark);
+ if (error != ERR_NONE) {
+ if (error == ERR_INVALIDLOCATION || error == ERR_INSIDEPHONEMENU) {
+ DCT3DCT4_DisableConnectionFunctions(s);
+ }
+ return error;
+ }
+
+ return DCT3DCT4_DisableConnectionFunctions(s);
+}
+
+GSM_Error DCT3DCT4_CancelCall(GSM_StateMachine *s, int ID)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x08, 0x00, 0x85};
+
+ req[4] = (unsigned char)ID;
+ s->Phone.Data.CallID = ID;
+
+ smprintf(s, "Canceling single call\n");
+ return GSM_WaitFor (s, req, 6, 0x01, 4, ID_CancelCall);
+}
+
+GSM_Error DCT3DCT4_AnswerCall(GSM_StateMachine *s, int ID)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x06, 0x00, 0x00};
+
+ req[4] = (unsigned char)ID;
+ s->Phone.Data.CallID = ID;
+
+ smprintf(s, "Answering single call\n");
+ return GSM_WaitFor (s, req, 6, 0x01, 4, ID_AnswerCall);
+}
+
+GSM_Error DCT3DCT4_ReplyGetModelFirmware(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_CutLines lines;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+
+ InitLines(&lines);
+
+ SplitLines(msg->Buffer, msg->Length, &lines, "\x20\x0A", 2, "", 0, FALSE);
+
+ strcpy(Data->Model,GetLineString(msg->Buffer, &lines, 4));
+ smprintf(s, "Received model %s\n",Data->Model);
+ Data->ModelInfo = GetModelData(s, NULL, Data->Model, NULL);
+
+ strcpy(Data->VerDate,GetLineString(msg->Buffer, &lines, 3));
+ smprintf(s, "Received firmware date %s\n",Data->VerDate);
+
+ strcpy(Data->Version,GetLineString(msg->Buffer, &lines, 2));
+ smprintf(s, "Received firmware version %s\n",Data->Version);
+ GSM_CreateFirmwareNumber(s);
+
+ FreeLines(&lines);
+
+ return ERR_NONE;
+}
+
+GSM_Error DCT3DCT4_GetModel (GSM_StateMachine *s)
+{
+ unsigned char req[5] = {N6110_FRAME_HEADER, 0x03, 0x00};
+ GSM_Error error;
+
+ if (strlen(s->Phone.Data.Model)>0) return ERR_NONE;
+
+ smprintf(s, "Getting model\n");
+ error=GSM_WaitFor (s, req, 5, 0xd1, 3, ID_GetModel);
+ if (error == ERR_NONE) {
+ smprintf_level(s, D_TEXT, "[Connected model - \"%s\"]\n",
+ s->Phone.Data.Model);
+ smprintf_level(s, D_TEXT, "[Firmware version - \"%s\"]\n",
+ s->Phone.Data.Version);
+ smprintf_level(s, D_TEXT, "[Firmware date - \"%s\"]\n",
+ s->Phone.Data.VerDate);
+ }
+ return error;
+}
+
+GSM_Error DCT3DCT4_GetFirmware (GSM_StateMachine *s)
+{
+ unsigned char req[5] = {N6110_FRAME_HEADER, 0x03, 0x00};
+ GSM_Error error;
+
+ if (strlen(s->Phone.Data.Version)>0) return ERR_NONE;
+
+ smprintf(s, "Getting firmware version\n");
+ error=GSM_WaitFor (s, req, 5, 0xd1, 3, ID_GetFirmware);
+ if (error == ERR_NONE) {
+ smprintf_level(s, D_TEXT, "[Connected model - \"%s\"]\n",
+ s->Phone.Data.Model);
+ smprintf_level(s, D_TEXT, "[Firmware version - \"%s\"]\n",
+ s->Phone.Data.Version);
+ smprintf_level(s, D_TEXT, "[Firmware date - \"%s\"]\n",
+ s->Phone.Data.VerDate);
+ }
+ return error;
+}
+
+/* ---------- Shared for n7110.c and n6510.c ------------------------------- */
+
+GSM_Error N71_65_ReplyGetMemoryError(unsigned char error, GSM_StateMachine *s)
+{
+ switch (error) {
+ case 0x21:
+ smprintf(s, "Wait for synchronisation???\n");
+ return ERR_WORKINPROGRESS;
+ case 0x24:
+ smprintf(s, "No own number???\n");
+ return ERR_NOTSUPPORTED;
+ case 0x27:
+ smprintf(s, "No PIN\n");
+ return ERR_SECURITYERROR;
+ case 0x30:
+ if (s->Phone.Data.Memory->MemoryType == MEM_ME ||
+ s->Phone.Data.Memory->MemoryType == MEM_SM) {
+ smprintf(s, "Empty entry\n");
+ return ERR_EMPTY;
+ }
+ smprintf(s, "Invalid memory type\n");
+ return ERR_NOTSUPPORTED;
+ case 0x31:
+ smprintf(s, "Invalid memory type?\n");
+ s->Phone.Data.Memory->EntriesNum = 0;
+ return ERR_EMPTY;
+ case 0x33:
+ smprintf(s, "Empty location\n");
+ s->Phone.Data.Memory->EntriesNum = 0;
+ return ERR_EMPTY;
+ case 0x34:
+ smprintf(s, "Too high location ?\n");
+ return ERR_INVALIDLOCATION;
+ case 0x3B: /* Tim Dreessen, 6230 */
+ smprintf(s, "Empty location\n");
+ s->Phone.Data.Memory->EntriesNum = 0;
+ /*
+ * This is really empty, but this entry is calculated to
+ * entries count, so we must return something.
+ */
+ return ERR_NONE;
+ case 0x3d: /* Seen on RH-105 for own number */
+ smprintf(s, "Empty location\n");
+ s->Phone.Data.Memory->EntriesNum = 0;
+ return ERR_NONE;
+ default:
+ smprintf(s, "ERROR: unknown status code 0x%x\n", error);
+ return ERR_UNKNOWNRESPONSE;
+ }
+}
+
+GSM_Error N71_65_ReplyWritePhonebook(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[6]) {
+ case 0x0f:
+ smprintf(s, "Phonebook entry writing failed\n");
+ switch (msg->Buffer[10]) {
+ case 0xf:
+ smprintf(s, "Invalid block sent\n");
+ return ERR_BUG;
+ case 0x21:
+ smprintf(s, "Still busy processing the last command\n");
+ return ERR_BUSY;
+ case 0x23:
+ smprintf(s, "Block size does not match a definition\n");
+ return ERR_BUG;
+ case 0x25:
+ smprintf(s, "when you try to save into entry with caller group assignment in phone with caller groups standard 2 (like in 6230i)\n");
+ return ERR_PERMISSION;
+ case 0x29:
+ smprintf(s, "no caller group with given number (6230i)\n");
+ return ERR_MEMORY;
+ case 0x32:
+ smprintf(s, "Ignoring ERROR: unknown 50 (probably group contains 50 entries)\n");
+ return ERR_NONE;
+ case 0x36:
+ smprintf(s, "Too long name\n");
+ return ERR_NOTSUPPORTED;
+ case 0x3c:
+ smprintf(s, "Can not add entry with 0 subentries\n");
+ return ERR_NOTSUPPORTED;
+ case 0x3d:
+ smprintf(s, "Wrong entry type\n");
+ return ERR_NOTSUPPORTED;
+ case 0x3e:
+ smprintf(s, "Too many entries\n");
+ return ERR_NOTSUPPORTED;
+ case 0x43:
+ smprintf(s, "Incorrect characters\n");
+ return ERR_NOTSUPPORTED;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[10]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ default:
+ smprintf(s, "Phonebook entry written\n");
+ return ERR_NONE;
+ }
+}
+
+gboolean NOKIA_FindPhoneFeatureValue(GSM_StateMachine *s,
+ GSM_Profile_PhoneTableValue ProfileTable[],
+ GSM_Profile_Feat_ID FeatureID,
+ GSM_Profile_Feat_Value FeatureValue,
+ unsigned char *PhoneID,
+ unsigned char *PhoneValue)
+{
+ int i=0;
+
+ smprintf(s, "Trying to find feature %i with value %i\n",FeatureID,FeatureValue);
+ while (ProfileTable[i].ID != 0x00) {
+ if (ProfileTable[i].ID == FeatureID &&
+ ProfileTable[i].Value == FeatureValue) {
+ *PhoneID = ProfileTable[i].PhoneID;
+ *PhoneValue = ProfileTable[i].PhoneValue;
+ return TRUE;
+ }
+ i++;
+ }
+ return FALSE;
+}
+
+#define PROFILE_CALLERGROUPS_GROUP1 0x01
+#define PROFILE_CALLERGROUPS_GROUP2 0x02
+#define PROFILE_CALLERGROUPS_GROUP3 0x04
+#define PROFILE_CALLERGROUPS_GROUP4 0x08
+#define PROFILE_CALLERGROUPS_GROUP5 0x10
+
+void NOKIA_FindFeatureValue(GSM_StateMachine *s,
+ GSM_Profile_PhoneTableValue ProfileTable[],
+ unsigned char ID,
+ unsigned char Value,
+ GSM_Phone_Data *Data,
+ gboolean CallerGroups)
+{
+ int i;
+
+ if (CallerGroups) {
+ smprintf(s, "Caller groups: %i\n", Value);
+ Data->Profile->FeatureID [Data->Profile->FeaturesNumber] = Profile_CallerGroups;
+ Data->Profile->FeaturesNumber++;
+ for (i=0;i<5;i++) Data->Profile->CallerGroups[i] = FALSE;
+ if ((Value & PROFILE_CALLERGROUPS_GROUP1)==PROFILE_CALLERGROUPS_GROUP1) Data->Profile->CallerGroups[0] = TRUE;
+ if ((Value & PROFILE_CALLERGROUPS_GROUP2)==PROFILE_CALLERGROUPS_GROUP2) Data->Profile->CallerGroups[1] = TRUE;
+ if ((Value & PROFILE_CALLERGROUPS_GROUP3)==PROFILE_CALLERGROUPS_GROUP3) Data->Profile->CallerGroups[2] = TRUE;
+ if ((Value & PROFILE_CALLERGROUPS_GROUP4)==PROFILE_CALLERGROUPS_GROUP4) Data->Profile->CallerGroups[3] = TRUE;
+ if ((Value & PROFILE_CALLERGROUPS_GROUP5)==PROFILE_CALLERGROUPS_GROUP5) Data->Profile->CallerGroups[4] = TRUE;
+ return;
+ }
+
+ i = 0;
+ while (ProfileTable[i].ID != 0x00) {
+ if (ProfileTable[i].PhoneID == ID &&
+ ProfileTable[i].PhoneValue == Value) {
+#ifdef DEBUG
+ switch (ProfileTable[i].ID) {
+ case Profile_KeypadTone : smprintf(s, "Keypad tones\n"); break;
+ case Profile_CallAlert : smprintf(s, "Call alert\n"); break;
+ case Profile_RingtoneVolume : smprintf(s, "Ringtone volume\n"); break;
+ case Profile_MessageTone : smprintf(s, "SMS message tones\n"); break;
+ case Profile_Vibration : smprintf(s, "Vibration\n"); break;
+ case Profile_WarningTone : smprintf(s, "Warning (ang games) tones\n"); break;
+ case Profile_AutoAnswer : smprintf(s, "Automatic answer\n"); break;
+ case Profile_Lights : smprintf(s, "Lights\n"); break;
+ case Profile_ScreenSaver : smprintf(s, "Screen Saver\n"); break;
+ case Profile_ScreenSaverTime : smprintf(s, "Screen Saver timeout\n"); break;
+ default : break;
+ }
+#endif
+ Data->Profile->FeatureID [Data->Profile->FeaturesNumber] = ProfileTable[i].ID;
+ Data->Profile->FeatureValue [Data->Profile->FeaturesNumber] = ProfileTable[i].Value;
+ Data->Profile->FeaturesNumber++;
+ break;
+ }
+ i++;
+ }
+}
+
+GSM_Profile_PhoneTableValue Profile71_65[] = {
+ {Profile_KeypadTone, PROFILE_KEYPAD_OFF, 0x00,0x00},
+ {Profile_KeypadTone, PROFILE_KEYPAD_LEVEL1, 0x00,0x01},
+ {Profile_KeypadTone, PROFILE_KEYPAD_LEVEL2, 0x00,0x02},
+ {Profile_KeypadTone, PROFILE_KEYPAD_LEVEL3, 0x00,0x03},
+ /* Lights ? */
+ {Profile_CallAlert, PROFILE_CALLALERT_RINGING, 0x02,0x00},
+ {Profile_CallAlert, PROFILE_CALLALERT_ASCENDING, 0x02,0x01},
+ {Profile_CallAlert, PROFILE_CALLALERT_RINGONCE, 0x02,0x02},
+ {Profile_CallAlert, PROFILE_CALLALERT_BEEPONCE, 0x02,0x03},
+ {Profile_CallAlert, PROFILE_CALLALERT_OFF, 0x02,0x05},
+/* {Profile_CallAlert, PROFILE_CALLALERT_CALLERGROUPS,0x02,0x07}, */
+ /* Ringtone ID */
+ {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL1, 0x04,0x00},
+ {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL2, 0x04,0x01},
+ {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL3, 0x04,0x02},
+ {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL4, 0x04,0x03},
+ {Profile_RingtoneVolume, PROFILE_VOLUME_LEVEL5, 0x04,0x04},
+ {Profile_MessageTone, PROFILE_MESSAGE_NOTONE, 0x05,0x00},
+ {Profile_MessageTone, PROFILE_MESSAGE_STANDARD, 0x05,0x01},
+ {Profile_MessageTone, PROFILE_MESSAGE_SPECIAL, 0x05,0x02},
+ {Profile_MessageTone, PROFILE_MESSAGE_BEEPONCE, 0x05,0x03},
+ {Profile_MessageTone, PROFILE_MESSAGE_ASCENDING, 0x05,0x04},
+ {Profile_Vibration, PROFILE_VIBRATION_OFF, 0x06,0x00},
+ {Profile_Vibration, PROFILE_VIBRATION_ON, 0x06,0x01},
+ {Profile_WarningTone, PROFILE_WARNING_OFF, 0x07,0x00},
+ {Profile_WarningTone, PROFILE_WARNING_ON, 0x07,0x01},
+ /* Caller groups */
+ {Profile_AutoAnswer, PROFILE_AUTOANSWER_OFF, 0x09,0x00},
+ {Profile_AutoAnswer, PROFILE_AUTOANSWER_ON, 0x09,0x01},
+ {0x00, 0x00, 0x00,0x00}
+};
+
+GSM_Error NOKIA_SetIncomingSMS(GSM_StateMachine *s, gboolean enable)
+{
+ s->Phone.Data.EnableIncomingSMS = enable;
+#ifdef DEBUG
+ if (enable) {
+ smprintf(s, "Enabling incoming SMS\n");
+ } else {
+ smprintf(s, "Disabling incoming SMS\n");
+ }
+#endif
+ return ERR_NONE;
+}
+
+GSM_Error N71_65_ReplyUSSDInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ unsigned char buffer[2000];
+ GSM_USSDMessage ussd;
+
+ if (s->Phone.Data.RequestID == ID_Divert) return ERR_NONE;
+
+ memcpy(buffer,msg->Buffer+8,msg->Buffer[7]);
+ buffer[msg->Buffer[7]] = 0x00;
+
+ smprintf(s, "USSD reply: \"%s\"\n",buffer);
+
+ if (s->Phone.Data.EnableIncomingUSSD && s->User.IncomingUSSD!=NULL) {
+ EncodeUnicode(ussd.Text,buffer,strlen(buffer));
+ /**
+ * @todo: Should determine status.
+ */
+ ussd.Status = USSD_Unknown;
+ s->User.IncomingUSSD(s, &ussd, s->User.IncomingUSSDUserData);
+ }
+
+ return ERR_NONE;
+}
+
+GSM_Error NOKIA_SetIncomingUSSD(GSM_StateMachine *s, gboolean enable)
+{
+ s->Phone.Data.EnableIncomingUSSD = enable;
+#ifdef DEBUG
+ if (enable) {
+ smprintf(s, "Enabling incoming USSD\n");
+ } else {
+ smprintf(s, "Disabling incoming USSD\n");
+ }
+#endif
+ return ERR_NONE;
+}
+
+GSM_Error NOKIA_SetIncomingCall(GSM_StateMachine *s, gboolean enable)
+{
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo,F_NOCALLINFO)) return ERR_NOTSUPPORTED;
+
+ s->Phone.Data.EnableIncomingCall = enable;
+#ifdef DEBUG
+ if (enable) {
+ smprintf(s, "Enabling incoming Call\n");
+ } else {
+ smprintf(s, "Disabling incoming Call\n");
+ }
+#endif
+ return ERR_NONE;
+}
+
+GSM_Error N71_65_ReplyCallInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_Call call;
+ int tmp;
+ unsigned char buffer[200];
+
+ call.Status = 0;
+ call.StatusCode = 0;
+ call.CallIDAvailable = TRUE;
+ call.PhoneNumber[0] = 0;
+ call.PhoneNumber[1] = 0;
+ smprintf(s, "Call info, ");
+ switch (msg->Buffer[3]) {
+ case 0x02:
+ smprintf(s, "Call established, waiting for answer\n");
+ call.Status = GSM_CALL_CallEstablished;
+ break;
+ case 0x03:
+ case 0x53:
+ case 0x05:
+ if (msg->Buffer[3] == 0x03) {
+ smprintf(s, "Call started\n");
+ call.Status = GSM_CALL_CallStart;
+ } else if (msg->Buffer[3] == 0x05) {
+ smprintf(s, "Incoming call\n");
+ call.Status = GSM_CALL_IncomingCall;
+ } else {
+ smprintf(s, "Outgoing call\n");
+ call.Status = GSM_CALL_OutgoingCall;
+ }
+/* Sample reply:
+01 |72r|02 |03 |01 |03 |07 |04 |01 |01 |01 |1C |11 |300|00 | 0B .r...........0..
+00 |333|00 |322|00 |344|00 |399|00 |399|00 |355|00 |366|00 |377 .3.2.4.9.9.5.6.7
+00 |322|00 |311|00 |311|0E |1C |300|02 |0A |00 |00 |09 |00 |4AJ .2.1.1..0......J
+00 |6Fo|00 |72r|00 |69i|00 |73s|00 |20 |00 |41A|00 |63c|00 |63c .o.r.i.s. .A.c.c
+00 |00 |00 |00 |00 |00 |00 |00 |00 |00 |00 |00 ............
+*/
+ smprintf(s, "Call mode : %i\n",msg->Buffer[5]);/* such interpretation is in gnokii */
+ /* This is probably wrong, but I need more sample data to properly parse output */
+ if (msg->Buffer[6] == 7) {
+ tmp = 14;
+ } else {
+ tmp = 6;
+ }
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer,call.PhoneNumber,FALSE);
+ smprintf(s, "Number : \"%s\"\n",DecodeUnicodeString(call.PhoneNumber));
+ /* FIXME: read name from frame */
+
+ break;
+ case 0x04:
+ smprintf(s, "Remote end hang up\n");
+ smprintf(s, "Cause Type : %i\n",msg->Buffer[5]);/* such interpretation is in gnokii */
+ smprintf(s, "CC : %i\n",msg->Buffer[6]);
+ smprintf(s, "MM(?) : %i\n",msg->Buffer[7]);
+ smprintf(s, "RR(?) : %i\n",msg->Buffer[8]);
+ call.Status = GSM_CALL_CallRemoteEnd;
+ call.StatusCode = msg->Buffer[6];
+ break;
+ case 0x07:
+ smprintf(s, "Call answer initiated\n");
+ break;
+ case 0x09:
+ smprintf(s, "Call released\n");
+ call.Status = GSM_CALL_CallLocalEnd;
+ break;
+ case 0x0a:
+ smprintf(s, "Call is being released\n");
+ break;
+ case 0x0b:
+ smprintf(s, "Meaning not known\n");
+ call.CallIDAvailable = FALSE;
+ break;
+ case 0x0c:
+ smprintf(s, "Audio status\n");
+ if (msg->Buffer[4] == 0x01) smprintf(s, "Audio enabled\n");
+ else smprintf(s, "Audio disabled\n");
+ call.CallIDAvailable = FALSE;
+ break;
+ case 0x0f: /* 6111 */
+ if (msg->Buffer[8]==0x01) {
+ smprintf(s, "Calling from phone keypad ?\n");
+ if (msg->Buffer[14]==0x03) {
+ tmp = 19;
+ } else {
+ tmp = 21;
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer,buffer,FALSE);
+ smprintf(s, "Name : \"%s\"\n",DecodeUnicodeString(buffer));
+ tmp+=7;
+ }
+ if (msg->Buffer[tmp-3]==0x11) {
+ call.PhoneNumber[0]=0;
+ call.PhoneNumber[1]='+';
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer,call.PhoneNumber+2,FALSE);
+ } else {
+ NOKIA_GetUnicodeString(s, &tmp, msg->Buffer,call.PhoneNumber,FALSE);
+ }
+ call.Status = GSM_CALL_OutgoingCall;
+ }
+ if (msg->Buffer[8]==0x00) {
+ smprintf(s, "Call released\n");
+ call.Status = GSM_CALL_CallLocalEnd;
+ }
+ break;
+ case 0x10:
+ smprintf(s, "Meaning not known\n");
+ call.CallIDAvailable = FALSE;
+ break;
+ case 0x23:
+ smprintf(s, "Call held\n");
+ call.Status = GSM_CALL_CallHeld;
+ break;
+ case 0x25:
+ smprintf(s, "Call resumed\n");
+ call.Status = GSM_CALL_CallResumed;
+ break;
+ case 0x27:
+ smprintf(s, "Call switched\n");
+ call.Status = GSM_CALL_CallSwitched;
+ break;
+ case 0xA6:
+ case 0xD2:
+ case 0xD3:
+ smprintf(s, "Meaning not known\n");
+ call.CallIDAvailable = FALSE;
+ break;
+ }
+ if (call.CallIDAvailable) smprintf(s, "Call ID : %d\n",msg->Buffer[4]);
+ if (s->Phone.Data.EnableIncomingCall && s->User.IncomingCall!=NULL && call.Status != 0) {
+ if (call.CallIDAvailable) call.CallID = msg->Buffer[4];
+ s->User.IncomingCall(s, &call, s->User.IncomingCallUserData);
+ }
+ if (s->Phone.Data.RequestID == ID_DialVoice) {
+ if (msg->Buffer[3] == 0x10) return ERR_NOTSUPPORTED;
+ }
+ if (s->Phone.Data.RequestID == ID_CancelCall) {
+ if (msg->Buffer[3] == 0x09) {
+ if (s->Phone.Data.CallID == msg->Buffer[4]) return ERR_NONE;
+ /* when we canceled call and see frame about other
+ * call releasing, we don't give ERR_NONE for "our"
+ * call release command
+ */
+ return ERR_NEEDANOTHERANSWER;
+ }
+ }
+ if (s->Phone.Data.RequestID == ID_AnswerCall) {
+ if (msg->Buffer[3] == 0x07) {
+ if (s->Phone.Data.CallID == msg->Buffer[4]) return ERR_NONE;
+ return ERR_NEEDANOTHERANSWER;
+ }
+ }
+ return ERR_NONE;
+}
+
+/* method 2 */
+GSM_Error N71_65_ReplyAddCalendar2(GSM_Protocol_Message *msg UNUSED, GSM_StateMachine *s)
+{
+ smprintf(s, "Calendar note added\n");
+ return ERR_NONE;
+}
+
+/* method 2 */
+GSM_Error N71_65_AddCalendar2(GSM_StateMachine *s, GSM_CalendarEntry *Note)
+{
+ GSM_CalendarNoteType NoteType;
+ time_t t_time1,t_time2;
+ GSM_DateTime Date,date_time;
+ GSM_Error error;
+ long diff;
+ int Text, Time, Alarm, Phone, EndTime, Location, length=25;
+ unsigned char req[5000] = {
+ N6110_FRAME_HEADER,
+ 0x40,
+ 0x00, /* frame length - 7 */
+ 0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00, /* start time saved as difference */
+ 0x00,0x00,0xff,0xff, /* alarm saved as difference */
+ 0x00, /* frame length - 7 */
+ 0x00, /* note type */
+ 0x00,0x00, /* recurrance */
+ 0x00,0x00,0x00,0x00,
+ 0x00,0x00,0x00,0x00}; /* rest depends on note type */
+
+ NoteType = N71_65_FindCalendarType(Note->Type, s->Phone.Data.ModelInfo);
+
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL65)) {
+ switch(NoteType) {
+ case GSM_CAL_MEETING : req[18] = 0x01; length = 25; break;
+ case GSM_CAL_CALL : req[18] = 0x02; length = 27; break;
+ case GSM_CAL_BIRTHDAY : req[18] = 0x04; length = 28; break;
+ case GSM_CAL_MEMO : req[18] = 0x08; length = 25; break;
+ default : return ERR_UNKNOWN;
+ }
+ } else {
+ switch(NoteType) {
+ case GSM_CAL_REMINDER : req[18] = 0x01; length = 25; break;
+ case GSM_CAL_CALL : req[18] = 0x02; length = 27; break;
+ case GSM_CAL_BIRTHDAY : req[18] = 0x04; length = 28; break;
+ case GSM_CAL_MEMO : req[18] = 0x08; length = 25; break;
+ default : return ERR_UNKNOWN;
+ }
+ }
+
+ GSM_CalendarFindDefaultTextTimeAlarmPhone(Note, &Text, &Time, &Alarm, &Phone, &EndTime, &Location);
+
+ if (Time == -1) {
+ smprintf(s, "Can not save entry without time!\n");
+ return ERR_UNKNOWN;
+ }
+ if (NoteType != GSM_CAL_BIRTHDAY) {
+ Date.Year = 2030; Date.Month = 01; Date.Day = 01;
+ Date.Hour = 00; Date.Minute = 00; Date.Second = 00;
+ } else {
+ Date.Year = 2029; Date.Month = 12; Date.Day = 31;
+ Date.Hour = 22; Date.Minute = 59; Date.Second = 58;
+ }
+ t_time1 = Fill_Time_T(Date);
+ memcpy(&Date,&Note->Entries[Time].Date,sizeof(GSM_DateTime));
+ if (NoteType != GSM_CAL_BIRTHDAY) {
+ Date.Year -= 20;
+ } else {
+ /* 6230 and probably other new models handle it differently
+ we don't make difference from 1980 year
+ */
+ if (GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL35) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL65) ||
+ GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL62)) {
+ Date.Year = 1980;
+ }
+ Date.Hour = 22; Date.Minute = 58; Date.Second = 58;
+ }
+ t_time2 = Fill_Time_T(Date);
+ diff = t_time1-t_time2;
+ smprintf(s, " Difference : %li seconds\n", -diff);
+ req[9] = (unsigned char)(-diff >> 24);
+ req[10] = (unsigned char)(-diff >> 16);
+ req[11] = (unsigned char)(-diff >> 8);
+ req[12] = (unsigned char)(-diff);
+ if (NoteType == GSM_CAL_BIRTHDAY) {
+ req[25] = Note->Entries[Time].Date.Year / 256;
+ req[26] = Note->Entries[Time].Date.Year % 256;
+ /* Recurrance = 1 year */
+ req[19] = 0xff;
+ req[20] = 0xff;
+ }
+
+ if (NoteType == GSM_CAL_CALL && Phone != -1) {
+ req[25] = UnicodeLength(Note->Entries[Phone].Text);
+ CopyUnicodeString(req+length,Note->Entries[Phone].Text);
+ length += UnicodeLength(Note->Entries[Phone].Text)*2;
+ }
+
+ if (Alarm != -1) {
+ if (NoteType == GSM_CAL_BIRTHDAY) {
+ if (Note->Entries[Alarm].EntryType == CAL_SILENT_ALARM_DATETIME) req[27] = 0x01;
+ error=s->Phone.Functions->GetDateTime(s,&date_time);
+ switch (error) {
+ case ERR_EMPTY:
+ case ERR_NOTIMPLEMENTED:
+ GSM_GetCurrentDateTime(&date_time);
+ break;
+ case ERR_NONE:
+ break;
+ default:
+ return error;
+ }
+ Date.Year = date_time.Year;
+ Date.Hour = 23;
+ Date.Minute = 59;
+ } else {
+ Date.Year += 20;
+ }
+ t_time2 = Fill_Time_T(Date);
+ t_time1 = Fill_Time_T(Note->Entries[Alarm].Date);
+ diff = t_time1-t_time2;
+
+ /* Sometimes we have difference in minutes */
+ if (NoteType == GSM_CAL_MEETING) diff = diff / 60;
+ if (!GSM_IsPhoneFeatureAvailable(s->Phone.Data.ModelInfo, F_CAL35)) {
+ if (NoteType == GSM_CAL_MEMO || NoteType == GSM_CAL_CALL) {
+ diff = diff / 60;
+ }
+ }
+
+ smprintf(s, " Difference : %li seconds or minutes\n", -diff);
+ req[13] = (unsigned char)(-diff >> 24);
+ req[14] = (unsigned char)(-diff >> 16);
+ req[15] = (unsigned char)(-diff >> 8);
+ req[16] = (unsigned char)(-diff);
+ }
+
+ GSM_SetCalendarRecurranceRepeat(&(s->di), req+19, NULL, Note);
+
+ if (Text != -1) {
+ switch (NoteType) {
+ case GSM_CAL_CALL:
+ req[26] = UnicodeLength(Note->Entries[Text].Text);
+ break;
+ default:
+ req[length++] = UnicodeLength(Note->Entries[Text].Text);
+ if (NoteType == GSM_CAL_MEMO || NoteType == GSM_CAL_MEETING) req[length++] = 0x00;
+ }
+ CopyUnicodeString(req+length,Note->Entries[Text].Text);
+ length += UnicodeLength(Note->Entries[Text].Text)*2;
+ }
+
+ req[length++] = 0x00;
+ req[length++] = 0x00;
+
+ req[4] = req[17] = length-7;
+
+ smprintf(s, "Writing calendar note method 2\n");
+ return GSM_WaitFor (s, req, length, 0x13, 4, ID_SetCalendarNote);
+}
+
+/* method 1*/
+GSM_Error N71_65_ReplyGetCalendarNotePos1(GSM_Protocol_Message *msg, GSM_StateMachine *s,int *FirstCalendarPos)
+{
+ smprintf(s, "First calendar location: %i\n",msg->Buffer[4]*256+msg->Buffer[5]);
+ *FirstCalendarPos = msg->Buffer[4]*256+msg->Buffer[5];
+ return ERR_NONE;
+}
+
+/* method 1*/
+static GSM_Error N71_65_GetCalendarNotePos1(GSM_StateMachine *s)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x31};
+
+ smprintf(s, "Getting first free calendar note location\n");
+ return GSM_WaitFor (s, req, 4, 0x13, 4, ID_GetCalendarNotePos);
+}
+
+/* method 1 */
+GSM_Error N71_65_ReplyAddCalendar1(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+#ifdef DEBUG
+ smprintf(s, "Written calendar note type ");
+ switch ((msg->Buffer[3]/2)-1) {
+ case 0: smprintf(s, "Meeting"); break;
+ case 1: smprintf(s, "Call"); break;
+ case 2: smprintf(s, "Birthday");break;
+ case 3: smprintf(s, "Reminder");break;
+ }
+ smprintf(s, " on location %d\n",msg->Buffer[4]*256+msg->Buffer[5]);
+#endif
+ return ERR_NONE;
+}
+
+/* method 1 */
+GSM_Error N71_65_AddCalendar1(GSM_StateMachine *s, GSM_CalendarEntry *Note, int *FirstCalendarPos)
+{
+ long seconds;
+ GSM_Error error;
+ GSM_DateTime DT;
+ int Text, Time, Alarm, Phone, EndTime, Location, count=12;
+ unsigned char req[5000] = {
+ N6110_FRAME_HEADER,
+ 0x01, /* note type */
+ 0x00, 0x00, /* location ? */
+ 0x00, /* entry type */
+ 0x00,
+ 0x00, 0x00, /* Year */
+ 0x00, /* Month */
+ 0x00, /* Day */
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+ error=N71_65_GetCalendarNotePos1(s);
+ if (error!=ERR_NONE) return error;
+ if (FirstCalendarPos != NULL) {
+ Note->Location = *FirstCalendarPos;
+ req[4] = *FirstCalendarPos/256;
+ req[5] = *FirstCalendarPos%256;
+ }
+
+ switch(Note->Type) {
+ case GSM_CAL_CALL : req[3]=0x03; req[6]=0x02; break;
+ case GSM_CAL_BIRTHDAY: req[3]=0x05; req[6]=0x04; break;
+ case GSM_CAL_MEMO : req[3]=0x07; req[6]=0x08; break;
+ case GSM_CAL_MEETING :
+ default : req[3]=0x01; req[6]=0x01; break;
+ }
+
+ GSM_CalendarFindDefaultTextTimeAlarmPhone(Note, &Text, &Time, &Alarm, &Phone, &EndTime, &Location);
+
+ if (Time == -1) {
+ smprintf(s, "Can not save entry without time!\n");
+ return ERR_UNKNOWN;
+ }
+ memcpy(&DT,&Note->Entries[Time].Date,sizeof(GSM_DateTime));
+ req[8] = DT.Year / 256;
+ req[9] = DT.Year % 256;
+ req[10] = DT.Month;
+ req[11] = DT.Day;
+
+ switch(Note->Type) {
+ case GSM_CAL_BIRTHDAY:
+ /* byte 12 and 13 */
+ req[count++] = 0x00;
+ req[count++] = 0x00;
+
+ /* Alarm - bytes 14 to 17 */
+ req[count++] = 0x00;
+ req[count++] = 0x00;
+ req[count++] = 0xff;
+ req[count++] = 0xff;
+ if (Alarm != -1) {
+ /* Comment from original source by Gabriele Zappi:
+ * I try with Time.Year = Alarm.Year. If negative, I increase 1 year,
+ * but only once ! This thing, because I may have Alarm period across
+ * a year. (eg. Birthday on 2001-01-10 and Alarm on 2000-12-27)
+ */
+ DT.Year = Note->Entries[Alarm].Date.Year;
+ seconds = Fill_Time_T(DT)-Fill_Time_T(Note->Entries[Alarm].Date);
+ if (seconds<0L) {
+ DT.Year++;
+ seconds = Fill_Time_T(DT)-Fill_Time_T(Note->Entries[Alarm].Date);
+ }
+ if (seconds>=0L) {
+ count -= 4;
+ /* bytes 14 to 17 */
+ req[count++] = (unsigned char)(seconds>>24);
+ req[count++] = (unsigned char)((seconds>>16) & 0xff);
+ req[count++] = (unsigned char)((seconds>>8) & 0xff);
+ req[count++] = (unsigned char)(seconds & 0xff);
+ }
+ /* byte 18 */
+ if (Note->Entries[Alarm].EntryType == CAL_SILENT_ALARM_DATETIME) req[count++] = 0x01; else req[count++] = 0x00;
+ }
+
+ /* byte 19 and next */
+ if (Text != -1) {
+ req[count++] = UnicodeLength(Note->Entries[Text].Text);
+ CopyUnicodeString(req+count,Note->Entries[Text].Text);
+ count=count+2*UnicodeLength(Note->Entries[Text].Text);
+ } else {
+ req[count++] = 0x00;
+ }
+ break;
+ case GSM_CAL_MEMO:
+ /* byte 12 and 13 */
+ GSM_SetCalendarRecurranceRepeat(&(s->di), req+count, NULL, Note);
+ count+=2;
+
+ /* byte 14 and next */
+ if (Text != -1) {
+ req[count++] = UnicodeLength(Note->Entries[Text].Text);
+ req[count++] = 0x00;
+ CopyUnicodeString(req+count,Note->Entries[Text].Text);
+ count=count+2*UnicodeLength(Note->Entries[Text].Text);
+ } else {
+ req[count++] = 0x00;
+ req[count++] = 0x00;
+ }
+ break;
+ case GSM_CAL_MEETING:
+ case GSM_CAL_CALL:
+ default:
+ /* byte 12 and 13 */
+ req[count++] = DT.Hour;
+ req[count++] = DT.Minute;
+
+ /* Alarm - byte 14 and 15 */
+ req[count++] = 0xff;
+ req[count++] = 0xff;
+ if (Alarm != -1) {
+ seconds=Fill_Time_T(DT)-Fill_Time_T(Note->Entries[Alarm].Date);
+ if (seconds>=0L) {
+ count -= 2;
+ req[count++] = (unsigned char)((seconds/60L)>>8);
+ req[count++] = (unsigned char)((seconds/60L)&0xff);
+ }
+ }
+
+ /* byte 16 and 17 */
+ GSM_SetCalendarRecurranceRepeat(&(s->di), req+count, NULL, Note);
+ count+=2;
+
+ /* byte 18 */
+ if (Text != -1) {
+ req[count++] = UnicodeLength(Note->Entries[Text].Text);
+ } else {
+ req[count++] = 0x00;
+ }
+ /* byte 19 */
+ if (Note->Type == GSM_CAL_CALL && Phone != -1) {
+ req[count++] = UnicodeLength(Note->Entries[Phone].Text);
+ } else {
+ req[count++] = 0x00;
+ }
+ if (Text != -1) {
+ CopyUnicodeString(req+count,Note->Entries[Text].Text);
+ count=count+2*UnicodeLength(Note->Entries[Text].Text);
+ }
+ if (Note->Type == GSM_CAL_CALL && Phone != -1) {
+ CopyUnicodeString(req+count,Note->Entries[Phone].Text);
+ count=count+2*UnicodeLength(Note->Entries[Phone].Text);
+ }
+ break;
+ }
+ req[count] = 0x00;
+ smprintf(s, "Writing calendar note method 1\n");
+ return GSM_WaitFor (s, req, count, 0x13, 4, ID_SetCalendarNote);
+}
+
+GSM_Error N71_65_ReplyDelCalendar(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ if (msg->Buffer[3] == 0xf0) return ERR_NOTSUPPORTED;
+
+ smprintf(s, "Deleted calendar note on location %d\n",msg->Buffer[4]*256+msg->Buffer[5]);
+ return ERR_NONE;
+}
+
+GSM_Error N71_65_DelCalendar(GSM_StateMachine *s, GSM_CalendarEntry *Note)
+{
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x0b,
+ 0x00, 0x00}; /* location */
+
+ req[4] = Note->Location / 256;
+ req[5] = Note->Location % 256;
+
+ smprintf(s, "Deleting calendar note\n");
+ return GSM_WaitFor (s, req, 6, 0x13, 4, ID_DeleteCalendarNote);
+}
+
+/* method 1 */
+GSM_Error N71_65_ReplyGetCalendarInfo1(GSM_Protocol_Message *msg, GSM_StateMachine *s, GSM_NOKIACalToDoLocations *LastCalendar)
+{
+ size_t i,j=0;
+
+ smprintf(s, "Info with calendar notes locations received method 1\n");
+ while (LastCalendar->Location[j] != 0x00) j++;
+ if (j >= GSM_MAXCALENDARTODONOTES) {
+ smprintf(s, "Increase GSM_MAXCALENDARNOTES\n");
+ return ERR_MOREMEMORY;
+ }
+ if (j == 0) {
+ LastCalendar->Number=msg->Buffer[4]*256+msg->Buffer[5];
+ smprintf(s, "Number of Entries: %i\n",LastCalendar->Number);
+ }
+ smprintf(s, "Locations: ");
+ i = 0;
+ while (9+(i*2) <= msg->Length) {
+ LastCalendar->Location[j++]=msg->Buffer[8+(i*2)]*256+msg->Buffer[9+(i*2)];
+ smprintf(s, "%i ",LastCalendar->Location[j-1]);
+ i++;
+ }
+ smprintf(s, "\nNumber of Entries in frame: %ld\n", (long)i);
+ smprintf(s, "\n");
+ LastCalendar->Location[j] = 0;
+ if (i == 1 && msg->Buffer[8+(0*2)]*256+msg->Buffer[9+(0*2)] == 0) return ERR_EMPTY;
+ if (i == 0) return ERR_EMPTY;
+ return ERR_NONE;
+}
+
+/* method 1 */
+GSM_Error N71_65_GetCalendarInfo1(GSM_StateMachine *s, GSM_NOKIACalToDoLocations *LastCalendar)
+{
+ GSM_Error error;
+ int i;
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x3a,
+ 0xFF, 0xFE}; /* First location number */
+
+ LastCalendar->Location[0] = 0x00;
+ LastCalendar->Number = 0;
+
+ smprintf(s, "Getting locations for calendar method 1\n");
+ error = GSM_WaitFor (s, req, 6, 0x13, 4, ID_GetCalendarNotesInfo);
+ if (error != ERR_NONE && error != ERR_EMPTY) return error;
+
+ while (1) {
+ i=0;
+ while (LastCalendar->Location[i] != 0x00) i++;
+ if (i == LastCalendar->Number) break;
+ if (i != LastCalendar->Number && error == ERR_EMPTY) {
+ smprintf(s, "Phone doesn't support some notes with this method. Workaround\n");
+ LastCalendar->Number = i;
+ break;
+ }
+ smprintf(s, "i = %i %i\n",i,LastCalendar->Number);
+ req[4] = LastCalendar->Location[i-1] / 256;
+ req[5] = LastCalendar->Location[i-1] % 256;
+ smprintf(s, "Getting locations for calendar\n");
+ error = GSM_WaitFor (s, req, 6, 0x13, 4, ID_GetCalendarNotesInfo);
+ if (error != ERR_NONE && error != ERR_EMPTY) return error;
+ }
+ return ERR_NONE;
+}
+
+/* method 1 */
+GSM_Error N71_65_ReplyGetNextCalendar1(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int timedelta,i;
+ GSM_CalendarEntry *entry = s->Phone.Data.Cal;
+
+ smprintf(s, "Calendar note received method 1\n");
+
+ /* Later these values can change */
+ if (msg->Buffer[6]!=0x04) { /* Here not birthday */
+ entry->Entries[0].Date.Year = msg->Buffer[8]*256+msg->Buffer[9];
+ }
+ entry->Entries[0].Date.Month = msg->Buffer[10];
+ entry->Entries[0].Date.Day = msg->Buffer[11];
+ entry->Entries[0].Date.Hour = msg->Buffer[12];
+ entry->Entries[0].Date.Minute = msg->Buffer[13];
+ entry->Entries[0].Date.Second = 0;
+ entry->Entries[0].EntryType = CAL_START_DATETIME;
+ entry->EntriesNum++;
+
+ switch (msg->Buffer[6]) {
+ case 0x01:
+ smprintf(s, "Meeting\n");
+ entry->Type = GSM_CAL_MEETING;
+
+ timedelta=msg->Buffer[14]*256+msg->Buffer[15];
+ if (timedelta != 0xffff) {
+ smprintf(s, " Difference : %i seconds\n", timedelta);
+ memcpy(&entry->Entries[1].Date,&entry->Entries[0].Date,sizeof(GSM_DateTime));
+ GetTimeDifference(timedelta, &entry->Entries[1].Date, FALSE, 60);
+ entry->Entries[1].EntryType = CAL_TONE_ALARM_DATETIME;
+ entry->EntriesNum++;
+ }
+ GSM_GetCalendarRecurranceRepeat(&(s->di), msg->Buffer + 16, NULL, entry);
+
+ memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+20, msg->Buffer[18]*2);
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[18]*2] = 0;
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[18]*2+1] = 0;
+ entry->Entries[entry->EntriesNum].EntryType = CAL_TEXT;
+ smprintf(s, "Text : \"%s\"\n", DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
+ entry->EntriesNum++;
+ return ERR_NONE;
+ case 0x02:
+ smprintf(s, "Call\n");
+ entry->Type = GSM_CAL_CALL;
+
+ timedelta=msg->Buffer[14]*256+msg->Buffer[15];
+ if (timedelta != 0xffff) {
+ smprintf(s, " Difference : %i seconds\n", timedelta);
+ memcpy(&entry->Entries[1].Date,&entry->Entries[0].Date,sizeof(GSM_DateTime));
+ GetTimeDifference(timedelta, &entry->Entries[1].Date, FALSE, 60);
+ entry->Entries[1].EntryType = CAL_TONE_ALARM_DATETIME;
+ entry->EntriesNum++;
+ }
+ GSM_GetCalendarRecurranceRepeat(&(s->di), msg->Buffer + 16, NULL, entry);
+
+ i = msg->Buffer[18] * 2;
+ if (i!=0) {
+ memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+20, i);
+ entry->Entries[entry->EntriesNum].Text[i] = 0;
+ entry->Entries[entry->EntriesNum].Text[i+1] = 0;
+ entry->Entries[entry->EntriesNum].EntryType = CAL_TEXT;
+ smprintf(s, "Text : \"%s\"\n", DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
+ entry->EntriesNum++;
+ }
+
+ memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+20+i, msg->Buffer[19]*2);
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[19]*2] = 0;
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[19]*2+1] = 0;
+ entry->Entries[entry->EntriesNum].EntryType = CAL_PHONE;
+ smprintf(s, "Phone : \"%s\"\n", DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
+ entry->EntriesNum++;
+ return ERR_NONE;
+ case 0x04:
+ smprintf(s, "Birthday\n");
+ entry->Type = GSM_CAL_BIRTHDAY;
+
+ entry->Entries[0].Date.Hour = 23;
+ entry->Entries[0].Date.Minute = 59;
+ entry->Entries[0].Date.Second = 58;
+
+ timedelta = ((unsigned int)msg->Buffer[14]) << 24;
+ timedelta += ((unsigned int)msg->Buffer[15]) << 16;
+ timedelta += ((unsigned int)msg->Buffer[16]) << 8;
+ timedelta += msg->Buffer[17];
+ if (timedelta != 0xffff) {
+ smprintf(s, " Difference : %i seconds\n", timedelta);
+ memcpy(&entry->Entries[1].Date,&entry->Entries[0].Date,sizeof(GSM_DateTime));
+ GetTimeDifference(timedelta, &entry->Entries[1].Date, FALSE, 1);
+ entry->Entries[1].EntryType = CAL_TONE_ALARM_DATETIME;
+ if (msg->Buffer[20]!=0x00) {
+ entry->Entries[1].EntryType = CAL_SILENT_ALARM_DATETIME;
+ smprintf(s, "Alarm type : Silent\n");
+ }
+ entry->EntriesNum++;
+ }
+
+ entry->Entries[0].Date.Year = msg->Buffer[18]*256 + msg->Buffer[19];
+ if (entry->Entries[0].Date.Year == 65535) entry->Entries[0].Date.Year = 0;
+ smprintf(s, "Age : %i\n",entry->Entries[0].Date.Year);
+
+ memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+22, msg->Buffer[21]*2);
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[21]*2] = 0;
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[21]*2+1] = 0;
+ entry->Entries[entry->EntriesNum].EntryType = CAL_TEXT;
+ smprintf(s, "Text : \"%s\"\n", DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
+ entry->EntriesNum++;
+
+ entry->Entries[entry->EntriesNum].EntryType = CAL_REPEAT_FREQUENCY;
+ entry->Entries[entry->EntriesNum].Number = 1;
+ entry->EntriesNum++;
+ entry->Entries[entry->EntriesNum].EntryType = CAL_REPEAT_DAY;
+ entry->Entries[entry->EntriesNum].Number = entry->Entries[0].Date.Day;
+ entry->EntriesNum++;
+ entry->Entries[entry->EntriesNum].EntryType = CAL_REPEAT_MONTH;
+ entry->Entries[entry->EntriesNum].Number = entry->Entries[0].Date.Month;
+ entry->EntriesNum++;
+
+ return ERR_NONE;
+ case 0x08:
+ smprintf(s, "Memo\n");
+ entry->Type = GSM_CAL_MEMO;
+
+ entry->Entries[0].Date.Hour = 0;
+ entry->Entries[0].Date.Minute = 0;
+
+ GSM_GetCalendarRecurranceRepeat(&(s->di), msg->Buffer + 12, NULL, entry);
+
+ memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+16, msg->Buffer[14]*2);
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[14]*2] = 0;
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[14]*2+1] = 0;
+ entry->Entries[entry->EntriesNum].EntryType = CAL_TEXT;
+ smprintf(s, "Text : \"%s\"\n", DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
+ entry->EntriesNum++;
+ return ERR_NONE;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[6]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+}
+
+/* method 1 */
+GSM_Error N71_65_GetNextCalendar1(GSM_StateMachine *s, GSM_CalendarEntry *Note, gboolean start, GSM_NOKIACalToDoLocations *LastCalendar, int *LastCalendarYear, int *LastCalendarPos)
+{
+ GSM_Error error;
+ GSM_DateTime date_time;
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x19,
+ 0x00, 0x00}; /* Location */
+
+ if (start) {
+ error=N71_65_GetCalendarInfo1(s, LastCalendar);
+ if (error!=ERR_NONE) return error;
+ if (LastCalendar->Number == 0) return ERR_EMPTY;
+
+ /* We have to get current year. It's NOT written in frame for
+ * Birthday
+ */
+ error=s->Phone.Functions->GetDateTime(s,&date_time);
+ switch (error) {
+ case ERR_EMPTY:
+ case ERR_NOTIMPLEMENTED:
+ GSM_GetCurrentDateTime(&date_time);
+ break;
+ case ERR_NONE:
+ break;
+ default:
+ return error;
+ }
+ *LastCalendarYear = date_time.Year;
+ *LastCalendarPos = 0;
+ } else {
+ (*LastCalendarPos)++;
+ }
+
+ if (*LastCalendarPos >= LastCalendar->Number) return ERR_EMPTY;
+
+ req[4] = LastCalendar->Location[*LastCalendarPos] / 256;
+ req[5] = LastCalendar->Location[*LastCalendarPos] % 256;
+
+ Note->EntriesNum = 0;
+ Note->Entries[0].Date.Year = *LastCalendarYear;
+ Note->Location = LastCalendar->Location[*LastCalendarPos];
+
+ s->Phone.Data.Cal=Note;
+ smprintf(s, "Getting calendar note method 1\n");
+ return GSM_WaitFor (s, req, 6, 0x13, 4, ID_GetCalendarNote);
+}
+
+GSM_Error N71_65_EnableFunctions(GSM_StateMachine *s,const char *buff,int len)
+{
+ unsigned char buffer[50] = {N6110_FRAME_HEADER, 0x10,
+ 0x07}; /* Length */
+
+ buffer[4] = len;
+ memcpy(buffer+5,buff,len);
+
+ /* Enables various things like incoming SMS, call info, etc. */
+ return s->Protocol.Functions->WriteMessage(s, buffer, 5+len, 0x10);
+}
+
+GSM_Error N71_65_ReplySendDTMF(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ switch (msg->Buffer[3]) {
+ case 0xf0:
+ return ERR_NOTSUPPORTED;
+ case 0x51:
+ smprintf(s, "DTMF sent OK\n");
+ return ERR_NONE;
+ case 0x59:
+ case 0x5E:
+ smprintf(s, "meaning unknown - during sending DTMF\n");
+ return ERR_NONE;
+ }
+ return ERR_UNKNOWNRESPONSE;
+}
+
+GSM_CalendarNoteType N71_65_FindCalendarType(GSM_CalendarNoteType Type, GSM_PhoneModel *model)
+{
+ switch (Type) {
+ case GSM_CAL_CALL:
+ return GSM_CAL_CALL;
+ case GSM_CAL_BIRTHDAY:
+ return GSM_CAL_BIRTHDAY;
+ case GSM_CAL_MEETING:
+ if (GSM_IsPhoneFeatureAvailable(model, F_CAL35)) {
+ return GSM_CAL_REMINDER;
+ } else return GSM_CAL_MEETING;
+ case GSM_CAL_MEMO:
+ if (GSM_IsPhoneFeatureAvailable(model, F_CAL35)) {
+ return GSM_CAL_REMINDER;
+ } else return GSM_CAL_MEMO;
+ case GSM_CAL_REMINDER:
+ if (GSM_IsPhoneFeatureAvailable(model, F_CAL62) ||
+ GSM_IsPhoneFeatureAvailable(model, F_CAL65)) {
+ return GSM_CAL_CALL;
+ } else return GSM_CAL_REMINDER;
+ default:
+ return GSM_CAL_CALL;
+ }
+}
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/nfunc.h b/libgammu/phone/nokia/nfunc.h
new file mode 100644
index 0000000..52e850a
--- /dev/null
+++ b/libgammu/phone/nokia/nfunc.h
@@ -0,0 +1,97 @@
+/* (c) 2002-2004 by Marcin Wiacek */
+
+#ifndef phone_nokia_h
+#define phone_nokia_h
+
+#include <gammu-nokia.h>
+
+#include "ncommon.h"
+#include "../../gsmstate.h"
+
+extern unsigned char N71_65_MEMORY_TYPES[];
+extern GSM_Profile_PhoneTableValue Profile71_65[];
+
+GSM_Error NOKIA_ReplyGetPhoneString (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N71_65_ReplyGetMemoryError (unsigned char error , GSM_StateMachine *s);
+GSM_Error N71_65_ReplyWritePhonebook (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N71_65_ReplyGetCalendarInfo1 (GSM_Protocol_Message *msg, GSM_StateMachine *s, GSM_NOKIACalToDoLocations *LastCalendar);
+GSM_Error N71_65_ReplyGetNextCalendar1 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N71_65_ReplyGetCalendarNotePos1 (GSM_Protocol_Message *msg, GSM_StateMachine *s,int *FirstCalendarPos);
+GSM_Error N71_65_ReplyAddCalendar1 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N71_65_ReplyAddCalendar2 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N71_65_ReplyDelCalendar (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N71_65_ReplyCallInfo (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N71_65_ReplyUSSDInfo (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3DCT4_ReplyCallDivert (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3DCT4_ReplyGetActiveConnectSet (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3DCT4_ReplySetActiveConnectSet (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3DCT4_ReplyGetWAPBookmark (GSM_Protocol_Message *msg, GSM_StateMachine *s, gboolean FullLength);
+GSM_Error DCT3DCT4_ReplySetWAPBookmark (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3DCT4_ReplyDelWAPBookmark (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3DCT4_ReplyEnableConnectFunc (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3DCT4_ReplyDisableConnectFunc (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error DCT3DCT4_ReplyGetModelFirmware (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N71_65_ReplySendDTMF (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+
+GSM_Error NOKIA_GetManufacturer (GSM_StateMachine *s);
+GSM_Error NOKIA_GetPhoneString (GSM_StateMachine *s, const unsigned char *msgframe, int msglen, unsigned char msgtype, char *retvalue, GSM_Phone_RequestID request, int startresponse);
+GSM_Error NOKIA_SetIncomingSMS (GSM_StateMachine *s, gboolean enable);
+GSM_Error NOKIA_SetIncomingCall (GSM_StateMachine *s, gboolean enable);
+GSM_Error NOKIA_SetIncomingUSSD (GSM_StateMachine *s, gboolean enable);
+GSM_Error N71_65_EnableFunctions (GSM_StateMachine *s, const char *buff,int len);
+GSM_Error N71_65_GetNextCalendar1 (GSM_StateMachine *s, GSM_CalendarEntry *Note, gboolean start, GSM_NOKIACalToDoLocations *LastCalendar, int *LastCalendarYear, int *LastCalendarPos);
+GSM_Error N71_65_AddCalendar2 (GSM_StateMachine *s, GSM_CalendarEntry *Note);
+GSM_Error N71_65_AddCalendar1 (GSM_StateMachine *s, GSM_CalendarEntry *Note, int *FirstCalendarPos);
+GSM_Error N71_65_DelCalendar (GSM_StateMachine *s, GSM_CalendarEntry *Note);
+GSM_Error N71_65_GetCalendarInfo1 (GSM_StateMachine *s, GSM_NOKIACalToDoLocations *LastCalendar);
+GSM_Error DCT3DCT4_EnableWAPFunctions (GSM_StateMachine *s);
+GSM_Error DCT3DCT4_SendDTMF (GSM_StateMachine *s, char *sequence);
+GSM_Error DCT3DCT4_DeleteWAPBookmarkPart (GSM_StateMachine *s, GSM_WAPBookmark *bookmark);
+GSM_Error DCT3DCT4_GetWAPBookmarkPart (GSM_StateMachine *s, GSM_WAPBookmark *bookmark);
+GSM_Error DCT3DCT4_DisableConnectionFunctions (GSM_StateMachine *s);
+GSM_Error DCT3DCT4_GetModel (GSM_StateMachine *s);
+GSM_Error DCT3DCT4_GetFirmware (GSM_StateMachine *s);
+GSM_Error DCT3DCT4_AnswerCall (GSM_StateMachine *s, int ID);
+GSM_Error DCT3DCT4_CancelCall (GSM_StateMachine *s, int ID);
+GSM_Error DCT3DCT4_GetActiveConnectSet (GSM_StateMachine *s);
+GSM_Error DCT3DCT4_SetActiveConnectSet (GSM_StateMachine *s, GSM_MultiWAPSettings *settings);
+GSM_Error DCT3DCT4_CancelAllDiverts (GSM_StateMachine *s);
+GSM_Error DCT3DCT4_SetCallDivert (GSM_StateMachine *s, GSM_CallDivert *divert);
+GSM_Error DCT3DCT4_GetCallDivert (GSM_StateMachine *s, GSM_CallDivert *reqest, GSM_MultiCallDivert *response);
+
+GSM_CalendarNoteType N71_65_FindCalendarType(GSM_CalendarNoteType Type, GSM_PhoneModel *model);
+int NOKIA_SetUnicodeString (GSM_StateMachine *s, unsigned char *dest, unsigned char *string, gboolean FullLength);
+void NOKIA_GetUnicodeString (GSM_StateMachine *s, int *current, unsigned char *input, unsigned char *output, gboolean FullLength);
+GSM_MemoryType NOKIA_GetMemoryType (GSM_StateMachine *s, GSM_MemoryType memory_type, unsigned char *ID);
+void NOKIA_DecodeSMSState (GSM_StateMachine *s, unsigned char state, GSM_SMSMessage *sms);
+void NOKIA_EncodeDateTime (GSM_StateMachine *s, unsigned char* buffer, GSM_DateTime *datetime);
+void NOKIA_DecodeDateTime(GSM_StateMachine *s, unsigned char* buffer, GSM_DateTime *datetime, gboolean seconds, gboolean DayMonthReverse);
+void NOKIA_SortSMSFolderStatus (GSM_StateMachine *s, GSM_NOKIASMSFolder *Folder);
+void NOKIA_FindFeatureValue(GSM_StateMachine *s,
+ GSM_Profile_PhoneTableValue ProfileTable[],
+ unsigned char ID,
+ unsigned char Value,
+ GSM_Phone_Data *Data,
+ gboolean CallerGroups);
+gboolean NOKIA_FindPhoneFeatureValue(GSM_StateMachine *s,
+ GSM_Profile_PhoneTableValue ProfileTable[],
+ GSM_Profile_Feat_ID FeatureID,
+ GSM_Profile_Feat_Value FeatureValue,
+ unsigned char *PhoneID,
+ unsigned char *PhoneValue);
+
+GSM_Error N71_65_DecodePhonebook (GSM_StateMachine *s,
+ GSM_MemoryEntry *entry,
+ GSM_Bitmap *bitmap,
+ GSM_SpeedDial *speed,
+ unsigned char *MessageBuffer,
+ int MessageLength,
+ gboolean DayMonthReverse);
+size_t N71_65_EncodePhonebookFrame (GSM_StateMachine *s, unsigned char *req, GSM_MemoryEntry *entry, size_t *block2, gboolean DCT4, gboolean VoiceTag);
+size_t N71_65_PackPBKBlock (GSM_StateMachine *s, int id, size_t size, int no, unsigned char *buf, unsigned char *block);
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/nfuncold.c b/libgammu/phone/nokia/nfuncold.c
new file mode 100644
index 0000000..a235d8c
--- /dev/null
+++ b/libgammu/phone/nokia/nfuncold.c
@@ -0,0 +1,228 @@
+/* (c) 2003 by Marcin Wiacek */
+
+#include <string.h> /* memcpy only */
+#include <stdio.h>
+#include <ctype.h>
+#include <time.h>
+
+#include "../../misc/coding/coding.h"
+#include "../../gsmstate.h"
+#include "../../service/gsmcal.h"
+#include "../pfunc.h"
+#include "nfunc.h"
+
+#ifdef DEBUG
+static void N71_65_GetCalendarAlarm(GSM_StateMachine *s, unsigned char *buffer, GSM_CalendarEntry *entry, int DT, GSM_Phone_Data *Data)
+{
+ unsigned long diff;
+
+ if (buffer[0] == 0x00 && buffer[1] == 0x00 && buffer[2] == 0xff && buffer[3] == 0xff) {
+ smprintf(s, "No alarm\n");
+ } else {
+ memcpy(&entry->Entries[entry->EntriesNum].Date,&entry->Entries[DT].Date,sizeof(GSM_DateTime));
+
+ diff = ((unsigned int)buffer[0]) << 24;
+ diff += ((unsigned int)buffer[1]) << 16;
+ diff += ((unsigned int)buffer[2]) << 8;
+ diff += buffer[3];
+ smprintf(s, " Difference : %li seconds\n", diff);
+
+ switch (entry->Type) {
+ case GSM_CAL_MEETING:
+ GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, FALSE, 60);
+ break;
+ case GSM_CAL_MEMO:
+ if (!GSM_IsPhoneFeatureAvailable(Data->ModelInfo, F_CAL35)) {
+ GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, FALSE, 60);
+ break;
+ }
+ FALLTHROUGH;
+ case GSM_CAL_CALL:
+ if (!GSM_IsPhoneFeatureAvailable(Data->ModelInfo, F_CAL35)) {
+ GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, FALSE, 60);
+ break;
+ }
+ FALLTHROUGH;
+ default:
+ GetTimeDifference(diff, &entry->Entries[entry->EntriesNum].Date, FALSE, 1);
+ }
+ smprintf(s, "Alarm date : %02i-%02i-%04i %02i:%02i:%02i\n",
+ entry->Entries[entry->EntriesNum].Date.Day, entry->Entries[entry->EntriesNum].Date.Month,
+ entry->Entries[entry->EntriesNum].Date.Year, entry->Entries[entry->EntriesNum].Date.Hour,
+ entry->Entries[entry->EntriesNum].Date.Minute,entry->Entries[entry->EntriesNum].Date.Second);
+
+ entry->Entries[entry->EntriesNum].EntryType = CAL_TONE_ALARM_DATETIME;
+ if (entry->Type == GSM_CAL_BIRTHDAY) {
+ if (buffer[14]!=0x00) entry->Entries[entry->EntriesNum].EntryType = CAL_SILENT_ALARM_DATETIME;
+ smprintf(s, "Alarm type : Silent\n");
+ }
+
+ entry->EntriesNum++;
+ }
+}
+
+/* method 2 */
+GSM_Error N71_65_ReplyGetNextCalendar2(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_DateTime Date;
+ GSM_CalendarEntry *entry = s->Phone.Data.Cal;
+ GSM_Phone_Data *Data = &s->Phone.Data;
+ int i;
+ unsigned long diff;
+
+ smprintf(s, "Calendar note received method 2\n");
+
+ if (msg->Length < 10) return ERR_EMPTY;
+
+ entry->Location = msg->Buffer[4]*256 + msg->Buffer[5];
+ smprintf(s, "Location: %i\n",entry->Location);
+
+ /* Not birthday */
+ if (msg->Buffer[21] != 0x04) {
+ Date.Year = 2030; Date.Month = 01; Date.Day = 01;
+ Date.Hour = 00; Date.Minute = 00; Date.Second = 00;
+ } else {
+ Date.Year = 2029; Date.Month = 12; Date.Day = 31;
+ Date.Hour = 22; Date.Minute = 59; Date.Second = 58;
+ }
+ diff = ((unsigned int)msg->Buffer[12]) << 24;
+ diff += ((unsigned int)msg->Buffer[13]) << 16;
+ diff += ((unsigned int)msg->Buffer[14]) << 8;
+ diff += msg->Buffer[15];
+ smprintf(s, " Difference : %li seconds\n", diff);
+ GetTimeDifference(diff, &Date, TRUE, 1);
+ Date.Year += 20;
+ entry->Entries[0].EntryType = CAL_START_DATETIME;
+
+ smprintf(s, "Note type %02x: ",msg->Buffer[21]);
+ switch (msg->Buffer[21]) {
+ case 0x01:
+ case 0x08:
+ if (msg->Buffer[21] == 0x01) {
+ smprintf(s, "Meeting or Reminder\n");
+ entry->Type = GSM_CAL_MEETING;
+ } else {
+ smprintf(s, "Memo\n");
+ Data->Cal->Type = GSM_CAL_MEMO;
+ }
+
+ memcpy(&entry->Entries[0].Date,&Date,sizeof(GSM_DateTime));
+ entry->EntriesNum++;
+
+ N71_65_GetCalendarAlarm(s, msg->Buffer+16, entry, 0, Data);
+ GSM_GetCalendarRecurranceRepeat(&(s->di), msg->Buffer+22, NULL, entry);
+
+ memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+30, msg->Buffer[28]*2);
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[28]*2] = 0;
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[28]*2+1] = 0;
+ entry->Entries[entry->EntriesNum].EntryType = CAL_TEXT;
+ break;
+ case 0x02:
+ smprintf(s, "Call\n");
+ entry->Type = GSM_CAL_CALL;
+
+ memcpy(&entry->Entries[0].Date,&Date,sizeof(GSM_DateTime));
+ entry->EntriesNum++;
+
+ N71_65_GetCalendarAlarm(s, msg->Buffer+16, entry, 0, Data);
+ GSM_GetCalendarRecurranceRepeat(&(s->di), msg->Buffer+22, NULL, entry);
+
+ i = msg->Buffer[28] * 2;
+ if (i!=0) {
+ memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+30, i);
+ entry->Entries[entry->EntriesNum].Text[i] = 0;
+ entry->Entries[entry->EntriesNum].Text[i+1] = 0;
+ entry->Entries[entry->EntriesNum].EntryType = CAL_PHONE;
+ smprintf(s, "Phone : \"%s\"\n", DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
+ entry->EntriesNum++;
+ }
+
+ memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+30+i, msg->Buffer[29]*2);
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[29]*2] = 0;
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[29]*2+1] = 0;
+ entry->Entries[entry->EntriesNum].EntryType = CAL_TEXT;
+ break;
+ case 0x04:
+ smprintf(s, "Birthday\n");
+ Data->Cal->Type = GSM_CAL_BIRTHDAY;
+
+ /* Year was set earlier */
+ entry->Entries[0].Date.Month = Date.Month;
+ entry->Entries[0].Date.Day = Date.Day;
+ entry->Entries[0].Date.Hour = 23;
+ entry->Entries[0].Date.Minute = 59;
+ entry->Entries[0].Date.Second = 58;
+ entry->EntriesNum++;
+
+ N71_65_GetCalendarAlarm(s, msg->Buffer+16, entry, 0, Data);
+ GSM_GetCalendarRecurranceRepeat(&(s->di), msg->Buffer+22, NULL, entry);
+
+ /* Birthday year */
+ entry->Entries[0].Date.Year = msg->Buffer[28]*256 + msg->Buffer[29];
+ if (msg->Buffer[28] == 0xff && msg->Buffer[29] == 0xff) entry->Entries[0].Date.Year = 0;
+ smprintf(s, "Birthday date: %02i-%02i-%04i\n",
+ entry->Entries[0].Date.Day,entry->Entries[0].Date.Month,
+ entry->Entries[0].Date.Year);
+
+ memcpy(entry->Entries[entry->EntriesNum].Text, msg->Buffer+32, msg->Buffer[31]*2);
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[31]*2] = 0;
+ entry->Entries[entry->EntriesNum].Text[msg->Buffer[31]*2+1] = 0;
+ entry->Entries[entry->EntriesNum].EntryType = CAL_TEXT;
+ break;
+ default:
+ smprintf(s, "ERROR: unknown %i\n",msg->Buffer[6]);
+ return ERR_UNKNOWNRESPONSE;
+ }
+ smprintf(s, "Text : \"%s\"\n", DecodeUnicodeString(entry->Entries[entry->EntriesNum].Text));
+ entry->EntriesNum++;
+ return ERR_NONE;
+}
+
+/* method 2 */
+/* Note: in known phones texts of notes cut to 50 chars */
+GSM_Error N71_65_GetNextCalendar2(GSM_StateMachine *s, GSM_CalendarEntry *Note, gboolean start, int *LastCalendarYear, int *LastCalendarPos)
+{
+ GSM_Error error;
+ GSM_DateTime date_time;
+ unsigned char req[] = {N6110_FRAME_HEADER, 0x3e,
+ 0xFF, 0xFE}; /* Location */
+
+ if (start) {
+ /* We have to get current year. It's NOT written in frame for
+ * Birthday
+ */
+ error=s->Phone.Functions->GetDateTime(s,&date_time);
+ switch (error) {
+ case ERR_EMPTY:
+ case ERR_NOTIMPLEMENTED:
+ GSM_GetCurrentDateTime(&date_time);
+ break;
+ case ERR_NONE:
+ break;
+ default:
+ return error;
+ }
+ *LastCalendarYear = date_time.Year;
+
+ /* First location at all */
+ req[4] = 0xFF;
+ req[5] = 0xFE;
+ } else {
+ req[4] = *LastCalendarPos / 256;
+ req[5] = *LastCalendarPos % 256;
+ }
+ Note->EntriesNum = 0;
+ Note->Entries[0].Date.Year = *LastCalendarYear;
+
+ s->Phone.Data.Cal = Note;
+ smprintf(s, "Getting calendar note method 2\n");
+ error=GSM_WaitFor (s, req, 6, 0x13, 4, ID_GetCalendarNote);
+ *LastCalendarPos = Note->Location;
+ return error;
+}
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/nfuncold.h b/libgammu/phone/nokia/nfuncold.h
new file mode 100644
index 0000000..eb90337
--- /dev/null
+++ b/libgammu/phone/nokia/nfuncold.h
@@ -0,0 +1,18 @@
+/* (c) 2003 by Marcin Wiacek */
+
+#ifndef phone_nokia2_h
+#define phone_nokia2_h
+
+#include "ncommon.h"
+#include "../../gsmstate.h"
+
+#ifdef DEBUG
+GSM_Error N71_65_ReplyGetNextCalendar2 (GSM_Protocol_Message *msg, GSM_StateMachine *s);
+GSM_Error N71_65_GetNextCalendar2 (GSM_StateMachine *s, GSM_CalendarEntry *Note, gboolean start, int *LastCalendarYear, int *LastCalendarPos);
+#endif
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/wd2/n3650.c b/libgammu/phone/nokia/wd2/n3650.c
new file mode 100644
index 0000000..ac6594e
--- /dev/null
+++ b/libgammu/phone/nokia/wd2/n3650.c
@@ -0,0 +1,461 @@
+/* (c) 2003 by Marcin Wiacek */
+
+#include "../../../gsmstate.h"
+
+#ifdef GSM_ENABLE_NOKIA3650
+
+#include <string.h>
+#include <time.h>
+
+#include "../../../gsmcomon.h"
+#include "../../../misc/coding/coding.h"
+#include "../../../service/gsmlogo.h"
+#include "../nfunc.h"
+#include "../nfuncold.h"
+#include "../../pfunc.h"
+#include "../dct4s40/dct4func.h"
+#include "n3650.h"
+
+static GSM_Error N3650_ReplyGetFilePart(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ int old;
+
+ smprintf(s,"File part received\n");
+ old = s->Phone.Data.File->Used;
+
+ if (msg->Length < 10) {
+ if (old == 0) return ERR_UNKNOWN;
+ return ERR_EMPTY;
+ }
+
+ s->Phone.Data.File->Used += msg->Buffer[10]*256*256*256+
+ msg->Buffer[11]*256*256+
+ msg->Buffer[12]*256+
+ msg->Buffer[13];
+ smprintf(s,"Length: %i\n",
+ msg->Buffer[10]*256*256*256+
+ msg->Buffer[11]*256*256+
+ msg->Buffer[12]*256+
+ msg->Buffer[13]);
+ s->Phone.Data.File->Buffer = (unsigned char *)realloc(s->Phone.Data.File->Buffer,s->Phone.Data.File->Used);
+ memcpy(s->Phone.Data.File->Buffer+old,msg->Buffer+18,s->Phone.Data.File->Used-old);
+ if (s->Phone.Data.File->Used-old < 0x03 * 256 + 0xD4) return ERR_EMPTY;
+ return ERR_NONE;
+}
+
+static GSM_Error N3650_GetFilePart(GSM_StateMachine *s, GSM_File *File, int *Handle UNUSED, size_t *Size)
+{
+ unsigned int len=10,i;
+ GSM_Error error;
+ unsigned char *req;
+ unsigned const char StartReq[11] = {
+ N7110_FRAME_HEADER, 0x0D, 0x10, 0x01, 0x07,
+ 0x24, /* len1 */
+ 0x12, /* len2 */
+ 0x0E, /* len3 */
+ 0x00}; /* File name */
+ unsigned char ContinueReq[] = {
+ N7110_FRAME_HEADER, 0x0D, 0x20, 0x01, 0xF0,
+ 0x08, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00};
+
+ if (File->Used == 0) {
+ req = malloc(strlen(File->ID_FullName) + 30);
+ if (req == NULL) {
+ return ERR_MOREMEMORY;
+ }
+ memcpy(req, StartReq, sizeof(StartReq));
+ (*Size) = 0;
+
+ sprintf(req+10,"%s",File->ID_FullName);
+ len+=strlen(File->ID_FullName)-1;
+ req[7] = strlen(File->ID_FullName) + 3;
+
+ req[8] = strlen(File->ID_FullName);
+ req[9] = 0;
+ while (File->ID_FullName[req[8]] != '\\') {
+ req[8]--;
+ req[9]++;
+ }
+ for (i=req[8];i<strlen(File->ID_FullName);i++) {
+ req[i+10] = req[i+1+10];
+ }
+ req[9]--;
+
+ EncodeUnicode(File->Name,File->ID_FullName+req[8]+1,req[9]);
+ File->Folder = FALSE;
+
+ error = DCT4_SetPhoneMode(s, DCT4_MODE_TEST);
+ if (error != ERR_NONE) return error;
+
+ s->Phone.Data.File = File;
+ return GSM_WaitFor (s, req, len, 0x58, 4, ID_GetFile);
+ }
+
+ s->Phone.Data.File = File;
+ error = GSM_WaitFor (s, ContinueReq, 14, 0x58, 4, ID_GetFile);
+
+#if 0
+ if (error == GE_EMPTY) {
+ error = DCT4_SetPhoneMode(s, DCT4_MODE_NORMAL);
+ if (error != ERR_NONE) return error;
+ return GE_EMPTY;
+ }
+#endif
+
+ return error;
+}
+
+static GSM_Error N3650_ReplyGetFolderInfo(GSM_Protocol_Message *msg, GSM_StateMachine *s)
+{
+ GSM_File *File = s->Phone.Data.FileInfo;
+ GSM_Phone_N3650Data *Priv = &s->Phone.Data.Priv.N3650;
+ int i,pos = 6;
+
+ i = Priv->FilesLocationsUsed-1;
+ while (1) {
+ if (i==Priv->FilesLocationsCurrent-1) break;
+ smprintf(s, "Copying %i to %i, max %i, current %i\n",
+ i,i+msg->Buffer[5],
+ Priv->FilesLocationsUsed,Priv->FilesLocationsCurrent);
+ memcpy(Priv->Files[i+msg->Buffer[5]],Priv->Files[i],sizeof(GSM_File));
+ i--;
+ }
+ Priv->FileEntries = msg->Buffer[5];
+ Priv->FilesLocationsUsed += msg->Buffer[5];
+ for (i=0;i<msg->Buffer[5];i++) {
+ Priv->Files[Priv->FilesLocationsCurrent+i]->Folder = TRUE;
+ if (msg->Buffer[pos+2] == 0x01) {
+ Priv->Files[Priv->FilesLocationsCurrent+i]->Folder = FALSE;
+ smprintf(s,"File ");
+ }
+ EncodeUnicode(Priv->Files[Priv->FilesLocationsCurrent+i]->Name,msg->Buffer+pos+9,msg->Buffer[pos+8]);
+ smprintf(s,"%s\n",DecodeUnicodeString(Priv->Files[Priv->FilesLocationsCurrent+i]->Name));
+ Priv->Files[Priv->FilesLocationsCurrent+i]->Level = File->Level+1;
+#ifdef __GNUC__
+#ifndef __clang__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wformat-overflow"
+#endif
+#endif
+ /* Here we check limits before doing sprintf */
+ if (strlen(File->ID_FullName) + strlen(msg->Buffer+pos+9) + 20 >= sizeof(File->ID_FullName)) {
+ return ERR_MOREMEMORY;
+ }
+ sprintf(
+ Priv->Files[Priv->FilesLocationsCurrent+i]->ID_FullName,
+ "%s\\%s",
+ File->ID_FullName,
+ msg->Buffer + pos + 9
+ );
+#ifdef __GNUC__
+#ifndef __clang__
+#pragma GCC diagnostic pop
+#endif
+#endif
+ pos += msg->Buffer[pos+1];
+ }
+ smprintf(s, "\n");
+ return ERR_NONE;
+}
+
+static GSM_Error N3650_GetFolderInfo(GSM_StateMachine *s, GSM_File *File)
+{
+ int len=10;
+ unsigned char *req;
+ unsigned const char template[11] = {
+ N7110_FRAME_HEADER, 0x0B, 0x00, 0x01, 0x07,
+ 0x18, /* folder name length + 6 */
+ 0x12, /* folder name length */
+ 0x00,
+ 0x00}; /* folder name */
+
+ req = malloc(strlen(File->ID_FullName) + 30);
+ if (req == NULL) {
+ return ERR_MOREMEMORY;
+ }
+ memcpy(req, template, sizeof(template));
+
+ /* FIXME: I doubt this works */
+ sprintf(req+10,"%s", File->ID_FullName);
+ len +=strlen(File->ID_FullName);
+ req[7] = strlen(File->ID_FullName) + 6;
+ req[8] = strlen(File->ID_FullName);
+ req[len++] = 0x00;
+ req[len++] = 0x00;
+
+ s->Phone.Data.FileInfo = File;
+ return GSM_WaitFor (s, req, len, 0x58, 4, ID_GetFile);
+}
+
+static GSM_Error N3650_GetNextFileFolder(GSM_StateMachine *s, GSM_File *File, gboolean start)
+{
+ GSM_Error error;
+ GSM_Phone_N3650Data *Priv = &s->Phone.Data.Priv.N3650;
+
+ if (start) {
+ error = DCT4_SetPhoneMode(s, DCT4_MODE_LOCAL);
+ if (error != ERR_NONE) return error;
+
+ Priv->Files[0]->Folder = TRUE;
+ Priv->Files[0]->Level = 1;
+ Priv->Files[0]->Name[0] = 0;
+ Priv->Files[0]->Name[1] = 0;
+ Priv->Files[0]->ID_FullName[0] = 'Z';
+ Priv->Files[0]->ID_FullName[1] = ':';
+ Priv->Files[0]->ID_FullName[2] = 0;
+
+ Priv->Files[1]->Folder = TRUE;
+ Priv->Files[1]->Level = 1;
+ Priv->Files[1]->Name[0] = 0;
+ Priv->Files[1]->Name[1] = 0;
+ Priv->Files[1]->ID_FullName[0] = 'E';
+ Priv->Files[1]->ID_FullName[1] = ':';
+ Priv->Files[1]->ID_FullName[2] = 0;
+
+ Priv->Files[2]->Folder = TRUE;
+ Priv->Files[2]->Level = 1;
+ Priv->Files[2]->Name[0] = 0;
+ Priv->Files[2]->Name[1] = 0;
+ Priv->Files[2]->ID_FullName[0] = 'C';
+ Priv->Files[2]->ID_FullName[1] = ':';
+ Priv->Files[2]->ID_FullName[2] = 0;
+
+ Priv->FilesLocationsUsed = 3;
+ Priv->FilesLocationsCurrent = 0;
+ Priv->FileLev = 1;
+ }
+
+ if (Priv->FilesLocationsCurrent == Priv->FilesLocationsUsed) {
+#if 0
+ error = DCT4_SetPhoneMode(s, DCT4_MODE_NORMAL);
+ if (error != ERR_NONE) return error;
+#endif
+
+ return ERR_EMPTY;
+ }
+
+ strcpy(File->ID_FullName,Priv->Files[Priv->FilesLocationsCurrent]->ID_FullName);
+ File->Level = Priv->Files[Priv->FilesLocationsCurrent]->Level;
+ File->Folder = Priv->Files[Priv->FilesLocationsCurrent]->Folder;
+ CopyUnicodeString(File->Name,Priv->Files[Priv->FilesLocationsCurrent]->Name);
+ Priv->FilesLocationsCurrent++;
+
+ if (!File->Folder) return ERR_NONE;
+
+ if (Priv->FilesLocationsCurrent > 1) {
+ if (File->ID_FullName[0]!=Priv->Files[Priv->FilesLocationsCurrent-2]->ID_FullName[0]) {
+ if (File->ID_FullName[0] == 'E') {
+ error = DCT4_SetPhoneMode(s, DCT4_MODE_TEST);
+ if (error != ERR_NONE) return error;
+ error = DCT4_SetPhoneMode(s, DCT4_MODE_TEST);
+ if (error != ERR_NONE) return error;
+ }
+ if (File->ID_FullName[0] == 'C') {
+ error = DCT4_SetPhoneMode(s, DCT4_MODE_LOCAL);
+ if (error != ERR_NONE) return error;
+ error = DCT4_SetPhoneMode(s, DCT4_MODE_LOCAL);
+ if (error != ERR_NONE) return error;
+ }
+#if 0
+ if (error != ERR_NONE) return error;
+#endif
+ }
+ }
+
+ File->ReadOnly = FALSE;
+ File->System = FALSE;
+ File->Protected = FALSE;
+ File->Hidden = FALSE;
+
+ return N3650_GetFolderInfo(s, File);
+}
+
+static GSM_Error N3650_Initialise (GSM_StateMachine *s)
+{
+ GSM_Phone_N3650Data *Priv = &s->Phone.Data.Priv.N3650;
+ int i=0;
+
+ for (i=0;i<10000;i++) {
+ Priv->Files[i] = (GSM_File *)malloc(sizeof(GSM_File));
+ if (Priv->Files[i] == NULL) return ERR_MOREMEMORY;
+ }
+ return ERR_NONE;
+}
+
+static GSM_Error N3650_Terminate(GSM_StateMachine *s)
+{
+ GSM_Phone_N3650Data *Priv = &s->Phone.Data.Priv.N3650;
+ int i;
+
+ for (i=0;i<10000;i++) {
+ free(Priv->Files[i]);
+ Priv->Files[i]=NULL;
+ }
+ return ERR_NONE;
+}
+
+static GSM_Reply_Function N3650ReplyFunctions[] = {
+ {DCT4_ReplySetPhoneMode, "\x15",0x03,0x64,ID_Reset },
+ {DCT4_ReplyGetPhoneMode, "\x15",0x03,0x65,ID_Reset },
+ {NoneReply, "\x15",0x03,0x68,ID_Reset },
+
+ {DCT4_ReplyGetIMEI, "\x1B",0x03,0x01,ID_GetIMEI },
+ {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x08,ID_GetHardware },
+ {NOKIA_ReplyGetPhoneString, "\x1B",0x03,0x0C,ID_GetProductCode },
+
+ {N3650_ReplyGetFolderInfo, "\x58",0x03,0x0C,ID_GetFile },
+ {N3650_ReplyGetFilePart, "\x58",0x03,0x0E,ID_GetFile },
+
+ {NULL, "\x00",0x00,0x00,ID_None }
+};
+
+GSM_Phone_Functions N3650Phone = {
+ "3650|NGAGE",
+ N3650ReplyFunctions,
+ NOTSUPPORTED, /* Install */
+ N3650_Initialise,
+ N3650_Terminate,
+ GSM_DispatchMessage,
+ NOTSUPPORTED, /* ShowStartInfo */
+ NOKIA_GetManufacturer,
+ DCT3DCT4_GetModel,
+ DCT3DCT4_GetFirmware,
+ DCT4_GetIMEI,
+ NOTSUPPORTED, /* GetOriginalIMEI */
+ NOTSUPPORTED, /* GetManufactureMonth */
+ DCT4_GetProductCode,
+ DCT4_GetHardware,
+ NOTSUPPORTED, /* GetPPM */
+ NOTSUPPORTED, /* GetSIMIMSI */
+ NOTSUPPORTED, /* GetDateTime */
+ NOTSUPPORTED, /* SetDateTime */
+ NOTSUPPORTED, /* GetAlarm */
+ NOTSUPPORTED, /* SetAlarm */
+ NOTSUPPORTED, /* GetLocale */
+ NOTSUPPORTED, /* SetLocale */
+ NOTSUPPORTED, /* PressKey */
+ DCT4_Reset,
+ NOTSUPPORTED, /* ResetPhoneSettings */
+ NOTSUPPORTED, /* EnterSecurityCode */
+ NOTSUPPORTED, /* GetSecurityStatus */
+ NOTSUPPORTED, /* GetDisplayStatus */
+ NOTSUPPORTED, /* SetAutoNetworkLogin */
+ NOTSUPPORTED, /* GetBatteryCharge */
+ NOTSUPPORTED, /* GetSignalQuality */
+ NOTSUPPORTED, /* GetNetworkInfo */
+ NOTSUPPORTED, /* GetCategory */
+ NOTSUPPORTED, /* AddCategory */
+ NOTSUPPORTED, /* GetCategoryStatus */
+ NOTSUPPORTED, /* GetMemoryStatus */
+ NOTSUPPORTED, /* GetMemory */
+ NOTSUPPORTED, /* GetNextMemory */
+ NOTSUPPORTED, /* SetMemory */
+ NOTSUPPORTED, /* AddMemory */
+ NOTSUPPORTED, /* DeleteMemory */
+ NOTIMPLEMENTED, /* DeleteAllMemory */
+ NOTSUPPORTED, /* GetSpeedDial */
+ NOTSUPPORTED, /* SetSpeedDial */
+ NOTSUPPORTED, /* GetSMSC */
+ NOTSUPPORTED, /* SetSMSC */
+ NOTSUPPORTED, /* GetSMSStatus */
+ NOTSUPPORTED, /* GetSMS */
+ NOTSUPPORTED, /* GetNextSMS */
+ NOTSUPPORTED, /* SetSMS */
+ NOTSUPPORTED, /* AddSMS */
+ NOTSUPPORTED, /* DeleteSMS */
+ NOTSUPPORTED, /* SendSMS */
+ NOTSUPPORTED, /* SendSavedSMS */
+ NOTSUPPORTED, /* SetFastSMSSending */
+ NOTSUPPORTED, /* SetIncomingSMS */
+ NOTSUPPORTED, /* SetIncomingCB */
+ NOTSUPPORTED, /* GetSMSFolders */
+ NOTSUPPORTED, /* AddSMSFolder */
+ NOTSUPPORTED, /* DeleteSMSFolder */
+ NOTIMPLEMENTED, /* DialVoice */
+ NOTIMPLEMENTED, /* DialService */
+ NOTIMPLEMENTED, /* AnswerCall */
+ NOTIMPLEMENTED, /* CancelCall */
+ NOTIMPLEMENTED, /* HoldCall */
+ NOTIMPLEMENTED, /* UnholdCall */
+ NOTIMPLEMENTED, /* ConferenceCall */
+ NOTIMPLEMENTED, /* SplitCall */
+ NOTIMPLEMENTED, /* TransferCall */
+ NOTIMPLEMENTED, /* SwitchCall */
+ NOTSUPPORTED, /* GetCallDivert */
+ NOTSUPPORTED, /* SetCallDivert */
+ NOTSUPPORTED, /* CancelAllDiverts */
+ NOTIMPLEMENTED, /* SetIncomingCall */
+ NOTIMPLEMENTED, /* SetIncomingUSSD */
+ NOTSUPPORTED, /* SendDTMF */
+ NOTSUPPORTED, /* GetRingtone */
+ NOTSUPPORTED, /* SetRingtone */
+ NOTSUPPORTED, /* GetRingtonesInfo */
+ NOTIMPLEMENTED, /* DeleteUserRingtones */
+ NOTSUPPORTED, /* PlayTone */
+ NOTSUPPORTED, /* GetWAPBookmark */
+ NOTSUPPORTED, /* SetWAPBookmark */
+ NOTSUPPORTED, /* DeleteWAPBookmark */
+ NOTSUPPORTED, /* GetWAPSettings */
+ NOTSUPPORTED, /* SetWAPSettings */
+ NOTSUPPORTED, /* GetSyncMLSettings */
+ NOTSUPPORTED, /* SetSyncMLSettings */
+ NOTSUPPORTED, /* GetChatSettings */
+ NOTSUPPORTED, /* SetChatSettings */
+ NOTSUPPORTED, /* GetMMSSettings */
+ NOTSUPPORTED, /* SetMMSSettings */
+ NOTSUPPORTED, /* GetMMSFolders */
+ NOTSUPPORTED, /* GetNextMMSFile */
+ NOTSUPPORTED, /* GetBitmap */
+ NOTSUPPORTED, /* SetBitmap */
+ NOTSUPPORTED, /* GetToDoStatus */
+ NOTSUPPORTED, /* GetToDo */
+ NOTSUPPORTED, /* GetNextToDo */
+ NOTSUPPORTED, /* SetToDo */
+ NOTSUPPORTED, /* AddToDo */
+ NOTSUPPORTED, /* DeleteToDo */
+ NOTSUPPORTED, /* DeleteAllToDo */
+ NOTIMPLEMENTED, /* GetCalendarStatus */
+ NOTIMPLEMENTED, /* GetCalendar */
+ NOTSUPPORTED, /* GetNextCalendar */
+ NOTIMPLEMENTED, /* SetCalendar */
+ NOTSUPPORTED, /* AddCalendar */
+ NOTSUPPORTED, /* DeleteCalendar */
+ NOTIMPLEMENTED, /* DeleteAllCalendar */
+ NOTSUPPORTED, /* GetCalendarSettings */
+ NOTSUPPORTED, /* SetCalendarSettings */
+ NOTSUPPORTED, /* GetNoteStatus */
+ NOTSUPPORTED, /* GetNote */
+ NOTSUPPORTED, /* GetNextNote */
+ NOTSUPPORTED, /* SetNote */
+ NOTSUPPORTED, /* AddNote */
+ NOTSUPPORTED, /* DeleteNote */
+ NOTSUPPORTED, /* DeleteAllNotes */
+ NOTSUPPORTED, /* GetProfile */
+ NOTSUPPORTED, /* SetProfile */
+ NOTSUPPORTED, /* GetFMStation */
+ NOTSUPPORTED, /* SetFMStation */
+ NOTSUPPORTED, /* ClearFMStations */
+ N3650_GetNextFileFolder,
+ NOTSUPPORTED, /* GetFolderListing */
+ NOTSUPPORTED, /* GetNextRootFolder */
+ NOTSUPPORTED, /* SetFileAttributes */
+ N3650_GetFilePart,
+ NOTIMPLEMENTED, /* AddFilePart */
+ NOTSUPPORTED, /* SendFilePart */
+ NOTSUPPORTED, /* GetFileSystemStatus */
+ NOTIMPLEMENTED, /* DeleteFile */
+ NOTIMPLEMENTED, /* AddFolder */
+ NOTSUPPORTED, /* DeleteFolder */
+ NOTSUPPORTED, /* GetGPRSAccessPoint */
+ NOTSUPPORTED, /* SetGPRSAccessPoint */
+ NOTSUPPORTED, /* GetScreenshot */
+ NOTSUPPORTED, /* SetPower */
+ NOTSUPPORTED, /* PostConnect */
+ NONEFUNCTION /* PreAPICall */
+};
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */
diff --git a/libgammu/phone/nokia/wd2/n3650.h b/libgammu/phone/nokia/wd2/n3650.h
new file mode 100644
index 0000000..0985a40
--- /dev/null
+++ b/libgammu/phone/nokia/wd2/n3650.h
@@ -0,0 +1,28 @@
+/* (c) 2003 by Marcin Wiacek */
+
+#ifndef n3650_h
+#define n3650_h
+
+#include "../../../gsmstate.h"
+#include "../../../service/gsmmisc.h"
+
+#ifndef GSM_USED_MBUS2
+# define GSM_USED_MBUS2
+#endif
+#ifndef GSM_USED_FBUS2
+# define GSM_USED_FBUS2
+#endif
+
+typedef struct {
+ int FileLev;
+ int FilesLocationsUsed;
+ int FilesLocationsCurrent;
+ GSM_File *Files[10000];
+ int FileEntries;
+} GSM_Phone_N3650Data;
+
+#endif
+
+/* How should editor hadle tabs in this file? Add editor commands here.
+ * vim: noexpandtab sw=8 ts=8 sts=8:
+ */