This commit was generated by cvs2svn to compensate for changes in r158,
[gnokii.git] / common / phones / nk7110.c
index bd3f164..4dd584d 100644 (file)
@@ -7,8 +7,7 @@
   A Linux/Unix toolset and driver for Nokia mobile phones.
 
   Copyright (C) 2000 Hugh Blemings & Pavel Janík ml.
   A Linux/Unix toolset and driver for Nokia mobile phones.
 
   Copyright (C) 2000 Hugh Blemings & Pavel Janík ml.
-  Copyright (C) 2000 Chris Kemp
-  Copyright (C) 2001 Markus Plail, Pawe³ Kot
+  Copytight (C) 2000 Chris Kemp
 
   Released under the terms of the GNU GPL, see file COPYING for more details.
 
 
   Released under the terms of the GNU GPL, see file COPYING for more details.
 
 
   The various routines are called P7110_(whatever).
 
 
   The various routines are called P7110_(whatever).
 
+  $Log$
+  Revision 1.1.1.5  2002/04/03 00:08:10  short
+  Found in "gnokii-working" directory, some November-patches version
+
+  Revision 1.15  2001/11/08 16:47:48  pkot
+  Start fiddling with 7110 and SMS
+
+  Revision 1.14  2001/09/09 21:45:49  machek
+  Cleanups from Ladislav Michl <ladis@psi.cz>:
+
+  *) do *not* internationalize debug messages
+
+  *) some whitespace fixes, do not use //
+
+  *) break is unneccessary after return
+
+  Revision 1.13  2001/08/16 23:59:32  pkot
+  Fixed (hopefully) timezone mismash (Sheldon Hearn)
+
+  Revision 1.12  2001/08/09 12:34:34  pkot
+  3330 and 6250 support - I have no idea if it does work (mygnokii)
+
+  Revision 1.11  2001/07/05 10:54:53  pkot
+  Solaris 2.7 fixes - should be harmless for other OSes (Michael Wiedmann)
+
+  Revision 1.10  2001/06/27 23:52:49  pkot
+  7110/6210 updates (Marian Jancar)
+
+  Revision 1.9  2001/06/10 23:49:49  pkot
+  Small fixes to hide compilation warnings and allow gnokii.c to compile
+
+  Revision 1.8  2001/05/24 20:47:30  chris
+  More updating of 7110 code and some of xgnokii_lowlevel changed over.
+
+  Revision 1.7  2001/05/07 16:24:04  pkot
+  DLR-3P temporary fix. How should I do it better?
+
+  Revision 1.6  2001/03/23 13:40:24  chris
+  Pavel's patch and a few fixes.
+
+  Revision 1.5  2001/03/22 16:17:06  chris
+  Tidy-ups and fixed gnokii/Makefile and gnokii/ChangeLog which I somehow corrupted.
+
+  Revision 1.4  2001/03/21 23:36:06  chris
+  Added the statemachine
+  This will break gnokii --identify and --monitor except for 6210/7110
+
+  Revision 1.3  2001/03/13 01:24:03  pkot
+  Code cleanup - no warnings during compilation
+
+  Revision 1.2  2001/03/13 01:23:18  pkot
+  Windows updates (Manfred Jonsson)
+
+  Revision 1.1  2001/02/21 19:57:07  chris
+  More fiddling with the directory layout
+
+  Revision 1.1  2001/02/16 14:29:53  chris
+  Restructure of common/.  Fixed a problem in fbus-phonet.c
+  Lots of dprintfs for Marcin
+  Any size xpm can now be loaded (eg for 7110 startup logos)
+  nk7110 code detects 7110/6210 and alters startup logo size to suit
+  Moved Marcin's extended phonebook code into gnokii.c
+
+  Revision 1.7  2001/02/06 21:15:35  chris
+  Preliminary irda support for 7110 etc.  Not well tested!
+
+  Revision 1.6  2001/02/03 23:56:15  chris
+  Start of work on irda support (now we just need fbus-irda.c!)
+  Proper unicode support in 7110 code (from pkot)
+
+  Revision 1.5  2001/02/01 15:17:31  pkot
+  Fixed --identify and added Manfred's manufacturer patch
+
+  Revision 1.4  2001/01/29 17:14:42  chris
+  dprintf now in misc.h (and fiddling with 7110 code)
+
+  Revision 1.3  2001/01/23 15:32:41  chris
+  Pavel's 'break' and 'static' corrections.
+  Work on logos for 7110.
+
+  Revision 1.2  2001/01/17 02:54:54  chris
+  More 7110 work.  Use with care! (eg it is not possible to delete phonebook entries)
+  I can now edit my phonebook in xgnokii but it is 'work in progress'.
+
+  Revision 1.1  2001/01/14 22:46:59  chris
+  Preliminary 7110 support (dlr9 only) and the beginnings of a new structure
+
+
 */
 
 #include <string.h>
 */
 
 #include <string.h>
 
 /* Some globals */
 
 
 /* Some globals */
 
-static const SMSMessage_Layout nk7110_deliver = {
-       true,
-       0, 21, 0, 0, 7, 0, 0, -1, 24, 23, 0, 21,
-       9, true, 25, true, 37, -1,
-       5, 4,
-       44, true
-};
-
-static const SMSMessage_Layout nk7110_submit = {
-       true,
-       -1, 18, 18, 18, -1, 19, 20, -1, 22, 21, 18, 18,
-       6, true, 23, true, -1, -1,
-       -1, -1,
-       42, true
-};
-
-static const SMSMessage_Layout nk7110_delivery_report = {
-       true,
-       0, 0, 0, 0, 7, 0, 0, 0, 23, 22, -1, 21,
-       9, true, 24, true, 36, 43,
-       5, 4,
-       23, true
-};
-
-static const SMSMessage_Layout nk7110_picture = {
-       true,
-       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-       9, true, 22, true, 34, -1,
-       0, 0,
-       47, true
-};
-
-static SMSMessage_PhoneLayout nk7110_layout;
-
 static GSM_IncomingFunctionType P7110_IncomingFunctions[] = {
        { P7110_MSG_FOLDER,     P7110_IncomingFolder },
        { P7110_MSG_SMS,        P7110_IncomingSMS },
 static GSM_IncomingFunctionType P7110_IncomingFunctions[] = {
        { P7110_MSG_FOLDER,     P7110_IncomingFolder },
        { P7110_MSG_SMS,        P7110_IncomingSMS },
@@ -83,7 +136,6 @@ static GSM_IncomingFunctionType P7110_IncomingFunctions[] = {
        { P7110_MSG_CLOCK,      P7110_IncomingClock },
        { P7110_MSG_IDENTITY,   P7110_Incoming0x1b },
        { P7110_MSG_STLOGO,     P7110_IncomingStartup },
        { P7110_MSG_CLOCK,      P7110_IncomingClock },
        { P7110_MSG_IDENTITY,   P7110_Incoming0x1b },
        { P7110_MSG_STLOGO,     P7110_IncomingStartup },
-       { P7110_MSG_DIVERT,     P7110_IncomingCallDivert },
        { 0, NULL }
 };
 
        { 0, NULL }
 };
 
@@ -92,7 +144,7 @@ GSM_Phone phone_nokia_7110 = {
        PGEN_IncomingDefault,
         /* Mobile phone information */
        {
        PGEN_IncomingDefault,
         /* Mobile phone information */
        {
-               "7110|6210|6250",      /* Supported models */
+               "7110|6210|6250", /* Supported models */
                7,                     /* Max RF Level */
                0,                     /* Min RF Level */
                GRF_Percentage,        /* RF level units */
                7,                     /* Max RF Level */
                0,                     /* Min RF Level */
                GRF_Percentage,        /* RF level units */
@@ -100,9 +152,9 @@ GSM_Phone phone_nokia_7110 = {
                0,                     /* Min Battery Level */
                GBU_Percentage,        /* Battery level units */
                GDT_DateTime,          /* Have date/time support */
                0,                     /* Min Battery Level */
                GBU_Percentage,        /* Battery level units */
                GDT_DateTime,          /* Have date/time support */
-               GDT_TimeOnly,          /* Alarm supports time only */
+               GDT_TimeOnly,            /* Alarm supports time only */
                1,                     /* Alarms available - FIXME */
                1,                     /* Alarms available - FIXME */
-               60, 96,                /* Startup logo size - 7110 is fixed at init */
+               60, 96,                /* Startup logo size - 7110 is fixed at init*/
                21, 78,                /* Op logo size */
                14, 72                 /* Caller logo size */
        },
                21, 78,                /* Op logo size */
                14, 72                 /* Caller logo size */
        },
@@ -152,11 +204,7 @@ static GSM_Error P7110_Functions(GSM_Operation op, GSM_Data *data, GSM_Statemach
                return P7110_GetCalendarNote(data, state);
        case GOP_GetSMS:
                return P7110_GetSMS(data, state);
                return P7110_GetCalendarNote(data, state);
        case GOP_GetSMS:
                return P7110_GetSMS(data, state);
-       case GOP_SendSMS:
-               return P7110_SendSMS(data, state);
-       case GOP_CallDivert:
-               return P7110_CallDivert(data, state);
-/* I'm not sure yet if folder functions will be shared or local
+/* I'm not suer yet if folder functions will be shared or local
        case GOP_GetSMSFolders:
                return P7110_GetSMSFolders(data, state);
        case GOP_GetSMSFolderStatus:
        case GOP_GetSMSFolders:
                return P7110_GetSMSFolders(data, state);
        case GOP_GetSMSFolderStatus:
@@ -180,22 +228,11 @@ static GSM_Error P7110_Initialise(GSM_Statemachine *state)
        /* Copy in the phone info */
        memcpy(&(state->Phone), &phone_nokia_7110, sizeof(GSM_Phone));
 
        /* Copy in the phone info */
        memcpy(&(state->Phone), &phone_nokia_7110, sizeof(GSM_Phone));
 
-       /* SMS Layout */
-       nk7110_layout.Type = 8; /* Locate the Type of the mesage field */
-       nk7110_layout.Deliver = nk7110_deliver;
-       nk7110_layout.Submit = nk7110_submit;
-       nk7110_layout.DeliveryReport = nk7110_delivery_report;
-       nk7110_layout.Picture = nk7110_picture;
-       layout = nk7110_layout;
-
-       dprintf("Connecting\n");
        while (!connected) {
                switch (state->Link.ConnectionType) {
        while (!connected) {
                switch (state->Link.ConnectionType) {
-               case GCT_DAU9P:
-                       if (try == 0) try = 1;
                case GCT_Serial:
                        if (try > 1) return GE_NOTSUPPORTED;
                case GCT_Serial:
                        if (try > 1) return GE_NOTSUPPORTED;
-                       err = FBUS_Initialise(&(state->Link), state, 1 - try);
+                       err = FBUS_Initialise(&(state->Link), state);
                        break;
                case GCT_Infrared:
                case GCT_Irda:
                        break;
                case GCT_Infrared:
                case GCT_Irda:
@@ -208,7 +245,7 @@ static GSM_Error P7110_Initialise(GSM_Statemachine *state)
                }
 
                if (err != GE_NONE) {
                }
 
                if (err != GE_NONE) {
-                       dprintf("Error in link initialisation: %d\n", err);
+                       dprintf("Error in link initialisation\n");
                        try++;
                        continue;
                }
                        try++;
                        continue;
                }
@@ -274,12 +311,13 @@ static GSM_Error P7110_IncomingBattLevel(int messagetype, unsigned char *message
                        *(data->BatteryLevel) = message[5];
                        dprintf("Battery level %f\n",*(data->BatteryLevel));
                }
                        *(data->BatteryLevel) = message[5];
                        dprintf("Battery level %f\n",*(data->BatteryLevel));
                }
+               return GE_NONE;
                break;
        default:
                dprintf("Unknown subtype of type 0x17 (%d)\n", message[3]);
                return GE_UNKNOWN;
                break;
        default:
                dprintf("Unknown subtype of type 0x17 (%d)\n", message[3]);
                return GE_UNKNOWN;
+               break;
        }
        }
-       return GE_NONE;
 }
 
 static GSM_Error P7110_GetRFLevel(GSM_Data *data, GSM_Statemachine *state)
 }
 
 static GSM_Error P7110_GetRFLevel(GSM_Data *data, GSM_Statemachine *state)
@@ -354,6 +392,7 @@ static GSM_Error P7110_IncomingNetwork(int messagetype, unsigned char *message,
                        }
                        blockstart += blockstart[1];
                }
                        }
                        blockstart += blockstart[1];
                }
+               return GE_NONE;
                break;
        case 0x82:
                if (data->RFLevel) { 
                break;
        case 0x82:
                if (data->RFLevel) { 
@@ -361,15 +400,16 @@ static GSM_Error P7110_IncomingNetwork(int messagetype, unsigned char *message,
                        *(data->RFLevel) = message[4];
                        dprintf("RF level %f\n",*(data->RFLevel));
                }
                        *(data->RFLevel) = message[4];
                        dprintf("RF level %f\n",*(data->RFLevel));
                }
+               return GE_NONE;
                break;
        case 0xa4:
                dprintf("Op Logo Set OK\n");
                break;
        case 0xa4:
                dprintf("Op Logo Set OK\n");
-               break;
+               return GE_NONE;
        default:
                dprintf("Unknown subtype of type 0x0a (%d)\n", message[3]);
                return GE_UNKNOWN;
        default:
                dprintf("Unknown subtype of type 0x0a (%d)\n", message[3]);
                return GE_UNKNOWN;
+               break;
        }
        }
-       return GE_NONE;
 }
 
 static GSM_Error P7110_GetMemoryStatus(GSM_Data *data, GSM_Statemachine *state)
 }
 
 static GSM_Error P7110_GetMemoryStatus(GSM_Data *data, GSM_Statemachine *state)
@@ -400,11 +440,14 @@ static GSM_Error P7110_IncomingPhonebook(int messagetype, unsigned char *message
                                data->MemoryStatus->Used = (message[16] << 8) + message[17];
                                data->MemoryStatus->Free = ((message[14] << 8) + message[15]) - data->MemoryStatus->Used;
                                dprintf("Memory status - location = %d\n", (message[8] << 8) + message[9]);
                                data->MemoryStatus->Used = (message[16] << 8) + message[17];
                                data->MemoryStatus->Free = ((message[14] << 8) + message[15]) - data->MemoryStatus->Used;
                                dprintf("Memory status - location = %d\n", (message[8] << 8) + message[9]);
+                               return GE_NONE;
                        } else {
                                dprintf("Unknown error getting mem status\n");
                                return GE_NOTIMPLEMENTED;
                        } else {
                                dprintf("Unknown error getting mem status\n");
                                return GE_NOTIMPLEMENTED;
+                               
                        }
                }
                        }
                }
+               return GE_NONE;
                break;
        case 0x08:  /* Read Memory response */
                if (data->PhonebookEntry) {
                break;
        case 0x08:  /* Read Memory response */
                if (data->PhonebookEntry) {
@@ -553,19 +596,20 @@ static GSM_Error P7110_IncomingPhonebook(int messagetype, unsigned char *message
                        }
                        blockstart += blockstart[3];
                }
                        }
                        blockstart += blockstart[3];
                }
+               return GE_NONE;
                break;
        case 0x0c:
                switch (message[6]) {
                break;
        case 0x0c:
                switch (message[6]) {
-               case 0x3d: return GE_PHBOOKWRITEFAILED;
-               case 0x3e: return GE_PHBOOKWRITEFAILED;
-               default: return GE_NONE;
+               case 0x3d: return GE_PHBOOKWRITEFAILED; break;
+               case 0x3e: return GE_PHBOOKWRITEFAILED; break;
+               default: return GE_NONE; break; 
                }
                break;  
        default:
                dprintf("Unknown subtype of type 0x03 (%d)\n", message[3]);
                return GE_UNKNOWN;
                }
                break;  
        default:
                dprintf("Unknown subtype of type 0x03 (%d)\n", message[3]);
                return GE_UNKNOWN;
+               break;
        }
        }
-       return GE_NONE;
 }
 
 /* Just as an example.... */
 }
 
 /* Just as an example.... */
@@ -576,7 +620,6 @@ static GSM_Error P7110_Identify(GSM_Data *data, GSM_Statemachine *state)
        unsigned char req2[] = {FBUS_FRAME_HEADER, 0x03, 0x01, 0x32};
   
        dprintf("Identifying...\n");
        unsigned char req2[] = {FBUS_FRAME_HEADER, 0x03, 0x01, 0x32};
   
        dprintf("Identifying...\n");
-       PNOK_GetManufacturer(data->Manufacturer);
        if (SM_SendMessage(state, 4, 0x1b, req) != GE_NONE) return GE_NOTREADY;
        if (SM_SendMessage(state, 6, 0x1b, req2) != GE_NONE) return GE_NOTREADY;
        SM_WaitFor(state, data, 0x1b);
        if (SM_SendMessage(state, 4, 0x1b, req) != GE_NONE) return GE_NOTREADY;
        if (SM_SendMessage(state, 6, 0x1b, req2) != GE_NONE) return GE_NOTREADY;
        SM_WaitFor(state, data, 0x1b);
@@ -596,6 +639,7 @@ static GSM_Error P7110_Incoming0x1b(int messagetype, unsigned char *message, int
                        snprintf(data->Imei, GSM_MAX_IMEI_LENGTH, "%s", message + 4);
                        dprintf("Received imei %s\n",data->Imei);
                }
                        snprintf(data->Imei, GSM_MAX_IMEI_LENGTH, "%s", message + 4);
                        dprintf("Received imei %s\n",data->Imei);
                }
+               return GE_NONE;
                break;
        case 04:
                if (data->Model) { 
                break;
        case 04:
                if (data->Model) { 
@@ -606,201 +650,132 @@ static GSM_Error P7110_Incoming0x1b(int messagetype, unsigned char *message, int
                        snprintf(data->Revision, GSM_MAX_REVISION_LENGTH, "%s", message + 7);
                        dprintf("Received revision %s\n",data->Revision);
                }
                        snprintf(data->Revision, GSM_MAX_REVISION_LENGTH, "%s", message + 7);
                        dprintf("Received revision %s\n",data->Revision);
                }
+               return GE_NONE;
                break;
        default:
                dprintf("Unknown subtype of type 0x1b (%d)\n", message[3]);
                return GE_UNKNOWN;
                break;
        default:
                dprintf("Unknown subtype of type 0x1b (%d)\n", message[3]);
                return GE_UNKNOWN;
+               break;
        }
        }
-       return GE_NONE;
 }
 
 
 /* handle messages of type 0x14 (SMS Handling, Folders, Logos.. */
 static GSM_Error P7110_IncomingFolder(int messagetype, unsigned char *message, int length, GSM_Data *data)
 {
 }
 
 
 /* handle messages of type 0x14 (SMS Handling, Folders, Logos.. */
 static GSM_Error P7110_IncomingFolder(int messagetype, unsigned char *message, int length, GSM_Data *data)
 {
-        int i, j;
-        int nextfolder = 0x10;
-        bool found;
-
+#if 0
+        int off, offset;
+        int wc,i,j,tmp=0;
         switch (message[3]) {
         /* getfolders */
         case 0x7B:
                 i = 5;
         switch (message[3]) {
         /* getfolders */
         case 0x7B:
                 i = 5;
-               memset(data->SMSFolderList, 0, sizeof(SMS_FolderList));
-               dprintf("Message: %d SMS Folders received:\n", message[4]);
-
-               strcpy(data->SMSFolderList->Folder[1].Name, "               ");
-               data->SMSFolderList->number = message[4];
+                data->SMSFolders->number = message[4];
+                dprintf("Message: %d SMS Folders received:\n", data->SMSFolders->number);
       
                 for (j = 0; j < message[4]; j++) {
       
                 for (j = 0; j < message[4]; j++) {
-                       int len;
-                        strcpy(data->SMSFolderList->Folder[j].Name, "               ");
-                        data->SMSFolderList->FolderID[j] = message[i];
-                        dprintf("Folder Index: %d", data->SMSFolderList->FolderID[j]);
-                        i += 2;
+                        strcpy(data->SMSFolders->Folder[j].Name, "               ");
+                        data->SMSFolders->FoldersID[j] = message[i];
+                        dprintf("Folder Index: %d", data->SMSFolders->FoldersID[j]);
+                        i = i + 2;
                         dprintf("   Folder name: ");
                         dprintf("   Folder name: ");
-                       len = 0;
-                       /* search for next folder's index number, i.e. length of folder name */
-                       while (message[i+1] != nextfolder && i < length) {
-                               i += 2;
-                               len++;
-                       }
-                       /* see nk7110.txt */
-                       nextfolder += 0x08;
-                       if (nextfolder == 0x28) nextfolder++;
-                       i -= 2 * len +1;
-                       DecodeUnicode(data->SMSFolderList->Folder[j].Name, message + i, len);
-                       dprintf("%s\n", data->SMSFolderList->Folder[j].Name);
-                       i += 2 * len + 2;
+                        tmp = 0;
+                        while ((message[i] != 0x00) & (message[i+1] == 0x00)) {
+                                wc = message[i] | (message[i+1] << 8);
+                               data->SMSFolders->Folder[j].Name[tmp] = DecodeWithUnicodeAlphabet(wc);
+                                dprintf("%c", data->SMSFolders->Folder[j].Name[tmp]);
+                                tmp++;
+                                i = i + 2;
+                        }
+                        dprintf("\n");
+                        tmp = 0;
+                        i = i + 1;
                 }
                 break;
 
         /* getfolderstatus */
         case 0x6C:
                 }
                 break;
 
         /* getfolderstatus */
         case 0x6C:
-               memset(data->SMSFolder, 0, sizeof(SMS_Folder));
                 dprintf("Message: SMS Folder status received: \n" );
                 dprintf("Message: SMS Folder status received: \n" );
-               data->SMSFolder->FolderID = data->SMSMessage->MemoryType;
-                data->SMSFolder->number = (message[5] * 256) + message[5];
-                dprintf("Message: Number of Entries: %i\n" , data->SMSFolder->number);
+                data->OneSMSFolder->number = (message[5] * 256) + message[5];
+                dprintf("Message: Number of Entries: %i\n" , data->OneSMSFolder->number);
                 dprintf("Message: IDs of Entries : ");
                 dprintf("Message: IDs of Entries : ");
-                for (i = 0; i < message[4] * 256 + message[5]; i++) {
-                        data->SMSFolder->locations[i] = message[6+(i*2)] * 256 + message[(i*2)+7];
-                        dprintf("%d, ", data->SMSFolder->locations[i]);
+                for (i=0;i<message[4]*256+message[5];i++) {
+                        data->OneSMSFolder->locations[i]=message[6+(i*2)]*256+message[(i*2)+7];
+                        dprintf("%d, ", data->OneSMSFolder->locations[i]);
                 }
                 dprintf("\n");
                 break;
 
         /* getsms */    
         case 0x08:
                 }
                 dprintf("\n");
                 break;
 
         /* getsms */    
         case 0x08:
-                for (i = 0; i < length; i ++)
+                for (i = 0; i < length-2; i ++)
                         if (isprint(message[i]))
                                 dprintf("[%02x%c]", message[i], message[i]);
                         else
                                 dprintf("[%02x ]", message[i]);
                 dprintf("\n");
 
                         if (isprint(message[i]))
                                 dprintf("[%02x%c]", message[i], message[i]);
                         else
                                 dprintf("[%02x ]", message[i]);
                 dprintf("\n");
 
-               memset(data->SMSMessage, 0, sizeof(GSM_SMSMessage));
-
-               /* Number of SMS in folder */
-               data->SMSMessage->Number = message[7];
-
-               /* MessageType/FolderID */
-               data->SMSMessage->MemoryType = message[5];
+                dprintf("Message: Getting SMS  %i " , data->SMSMessage->Location);
+                dprintf("in Folder  %i\n", data->SMSMessage->Destination);
+                if (message[5] != data->SMSMessage->Destination) {
+                        dprintf("Invalid SMS location (Folder)\n");
+                        return GE_INVALIDSMSLOCATION;
+                }
+                if ((message[6] * 256 + message[7]) != data->SMSMessage->Location) {
+                        dprintf("Invalid SMS location (ID)\n");
+                        return GE_INVALIDSMSLOCATION;
+                }
 
 
-               /* Short Message status */
-               data->SMSMessage->Status = message[4];
-               dprintf("\tStatus: ");
-               switch (data->SMSMessage->Status) {
-               case SMS_Read:
-                       dprintf("READ\n");
-                       break;
-               case SMS_Unread:
-                       dprintf("UNREAD\n");
-                       break;
-               case SMS_Sent:
-                       dprintf("SENT\n");
-                       break;
-               case SMS_Unsent:
-                       dprintf("UNSENT\n");
-                       break;
-               default:
-                       dprintf("UNKNOWN\n");
-                       break;
-               }
-               /* See if message# is given back by phone. If not and status is unread */
-               /* we want it, if status is not unread it's a "random" message given back */
-               /* by the phone because we want a message of which the # doesn't exist */
-               found = false;
-               for (i = 0; i < data->SMSFolder->number; i++) {
-                       if (data->SMSMessage->Number == data->SMSFolder->locations[i]) 
-                               found = true;
-               }
-               if (found==false && data->SMSMessage->Status != SMS_Unread) return GE_INVALIDSMSLOCATION;
+                /* Status see nk7110.txt */
+                data->SMSMessage->Status = message[4];
 
 
-               DecodePDUSMS(message, data->SMSMessage, length);
+                if (message[8]==0x01) data->SMSMessage->Type = SMS_Deliver_Report;
+                offset=4;
+                if (data->SMSMessage->Status == SMS_MO_SENT) offset=5;
+                off = 0;
+                if (message[9+12] & 0x40) { /* UDH header available */
 
 
+                        off = (message[9+31+offset] + 1); /* Length of UDH header */
+    
+                        dprintf("   UDH header available (length %i)\n",off);
+                }
+                  
+                DecodeSMSHeader(message, length, data->SMSMessage, 9, offset);
+                DecodeTextSMS(message, length, data->SMSMessage, 9, offset, off);
+              
                 break;
                 break;
-
-               /* get list of SMS pictures */
-               case 0x97:
-               dprintf("Getting list of SMS pictures...\n");
-               for (i = 0; i < length; i ++)
-                       if (isprint(message[i]))
-                               dprintf("[%02x%c]", message[i], message[i]);
-                       else
-                               dprintf("[%02x ]", message[i]);
-               dprintf("\n");
-               break;
+    
         default:
 
         default:
 
-               for (i = 0; i < length; i ++)
+               for (i = 0; i < length-2; i ++)
                        if (isprint(message[i]))
                                dprintf("[%02x%c]", message[i], message[i]);
                        else
                                dprintf("[%02x ]", message[i]);
                 dprintf("\n");
                 dprintf("Message: Unknown message of type 14 : %d  length: %d\n", message[3], length);
                        if (isprint(message[i]))
                                dprintf("[%02x%c]", message[i], message[i]);
                        else
                                dprintf("[%02x ]", message[i]);
                 dprintf("\n");
                 dprintf("Message: Unknown message of type 14 : %d  length: %d\n", message[3], length);
-               return GE_UNKNOWN;
+               break;
         }
         }
+#endif
         return GE_NONE;
 }
 
 static GSM_Error P7110_GetSMS(GSM_Data *data, GSM_Statemachine *state)
 {
         return GE_NONE;
 }
 
 static GSM_Error P7110_GetSMS(GSM_Data *data, GSM_Statemachine *state)
 {
-       unsigned char req_folders[] = {FBUS_FRAME_HEADER, 0x7a, 0x00, 0x00};
-       unsigned char req_status[] = {FBUS_FRAME_HEADER, 0x6b, 
-                               0x08, // Folder ID
-                               0x0f, 0x01};
-       unsigned char req_sms[] = {FBUS_FRAME_HEADER, 0x07, 
+       unsigned char req[] = {FBUS_FRAME_HEADER, 0x07, 
                                0x08, // FolderID
                                0x00, 
                                0x01, // Location
                                0x01, 0x65, 0x01};
                                0x08, // FolderID
                                0x00, 
                                0x01, // Location
                                0x01, 0x65, 0x01};
-       unsigned char req_list[] = {FBUS_FRAME_HEADER, 0x96, 
-                                        0x09, /* location */
-                                        0x0f, 0x07};
-       GSM_Error error;
-
-       /* just testiung picture listing */
-       req_list[4] = data->SMSMessage->MemoryType;
-       if (SM_SendMessage(state, 7, 0x14, req_list) != GE_NONE) return GE_NOTREADY;
-       error = SM_Block(state, data, 0x14);
-
-       /* see if the message we want is from the last read folder, i.e. */
-       /* we don't have to get folder status again */
-       if (data->SMSMessage->MemoryType != data->SMSFolder->FolderID) {
-
-               dprintf("Getting list of SMS folders...\n");
-               if (SM_SendMessage(state, 6, 0x14, req_folders) != GE_NONE) return GE_NOTREADY;
-               error = SM_Block(state, data, 0x14);
-
-               if (data->SMSMessage->MemoryType > data->SMSFolderList->FolderID[data->SMSFolderList->number-1])
-                       return GE_INVALIDMEMORYTYPE;
-               data->SMSFolder->FolderID = data->SMSMessage->MemoryType;
-               req_status[4] = data->SMSMessage->MemoryType;
-
-               dprintf("Getting entries for SMS folder %i...\n", data->SMSMessage->MemoryType);
-               if (SM_SendMessage(state, 7, 0x14, req_status) != GE_NONE) return GE_NOTREADY;
-               error = SM_Block(state, data, 0x14);
-       }
-        
+      
        dprintf("Getting SMS...\n");
        dprintf("Getting SMS...\n");
-       req_sms[4] = data->SMSMessage->MemoryType;
-       req_sms[6] = data->SMSMessage->Number;
-       if (SM_SendMessage(state, 10, 0x14, req_sms) != GE_NONE) return GE_NOTREADY;
+       req[4] = data->SMSMessage->MemoryType;
+       req[6] = data->SMSMessage->Location;
+       if (SM_SendMessage(state, 10, 0x14, req) != GE_NONE) return GE_NOTREADY;
        return SM_Block(state, data, 0x14);
 }
 
        return SM_Block(state, data, 0x14);
 }
 
-static GSM_Error P7110_GetPicture(GSM_Data *data, GSM_Statemachine *state)
-{
-       unsigned char req_list[] = {FBUS_FRAME_HEADER, 0x96, 
-                                        0x09, /* location */
-                                        0x0f, 0x07};
-       if (SM_SendMessage(state, 7, 0x14, req_list) != GE_NONE) return GE_NOTREADY;
-       return SM_Block(state, data, 0x14);
-}
 
 
-#if 0
 static GSM_Error P7110_GetSMSFolders(GSM_Data *data, GSM_Statemachine *state)
 {
        unsigned char req[] = {FBUS_FRAME_HEADER, 0x7A, 0x00, 0x00};
 static GSM_Error P7110_GetSMSFolders(GSM_Data *data, GSM_Statemachine *state)
 {
        unsigned char req[] = {FBUS_FRAME_HEADER, 0x7A, 0x00, 0x00};
@@ -812,67 +787,39 @@ static GSM_Error P7110_GetSMSFolders(GSM_Data *data, GSM_Statemachine *state)
 
 static GSM_Error P7110_GetSMSFolderStatus(GSM_Data *data, GSM_Statemachine *state)
 {
 
 static GSM_Error P7110_GetSMSFolderStatus(GSM_Data *data, GSM_Statemachine *state)
 {
+#if 0
        unsigned char req[] = {FBUS_FRAME_HEADER, 0x6B, 
                                0x08, // Folder ID
                                0x0F, 0x01};
       
        unsigned char req[] = {FBUS_FRAME_HEADER, 0x6B, 
                                0x08, // Folder ID
                                0x0F, 0x01};
       
-        req[4] = data->SMSFolder->FolderID;
+        req[4] = data->OneSMSFolder->FolderID;
        dprintf("Getting SMS Folder Status...\n");
        if (SM_SendMessage(state, 7, 0x14, req) != GE_NONE) return GE_NOTREADY;
        return SM_Block(state, data, 0x14);
        dprintf("Getting SMS Folder Status...\n");
        if (SM_SendMessage(state, 7, 0x14, req) != GE_NONE) return GE_NOTREADY;
        return SM_Block(state, data, 0x14);
-}
 #endif
 #endif
-
-static GSM_Error P7110_SendSMS(GSM_Data *data, GSM_Statemachine *state)
-{
-       GSM_Error e = GE_NONE;
-       unsigned char req[256] = {FBUS_FRAME_HEADER, 0x01, 0x02, 0x00};
-       int length, i;
-
-       if (data->SMSMessage->MessageCenter.No) {
-               data->MessageCenter = &data->SMSMessage->MessageCenter;
-               P7110_GetSMSCenter(data, state);
-       }
-
-       length = EncodePDUSMS(data->SMSMessage, req);
-       if (!length) return GE_SMSWRONGFORMAT;
-       dprintf("Sending SMS...(%d)\n", length);
-       for (i = 0; i < length; i++) {
-               dprintf("%02x ", req[i]);
-       }
-       dprintf("\n");
-       if (SM_SendMessage(state, length, 0x02, req) != GE_NONE) return GE_NOTREADY;
-       while (1) {
-               e = SM_Block(state, data, 0x02);
-               if (e == GE_SMSSENDOK || e == GE_SMSSENDFAILED) break;
-       }
-       return e;
+       return GE_NONE;
 }
 
 static GSM_Error P7110_IncomingSMS(int messagetype, unsigned char *message, int length, GSM_Data *data)
 {
        GSM_Error       e = GE_NONE;
        int             digits, bytes;
 }
 
 static GSM_Error P7110_IncomingSMS(int messagetype, unsigned char *message, int length, GSM_Data *data)
 {
        GSM_Error       e = GE_NONE;
        int             digits, bytes;
-
-       if (!data) return GE_INTERNALERROR;
+       
+       if (!data || !data->MessageCenter) return GE_INTERNALERROR;
 
        switch (message[3]) {
        case P7110_SUBSMS_SMSC_RCVD:
 
        switch (message[3]) {
        case P7110_SUBSMS_SMSC_RCVD:
-               dprintf("SMSC Received\n");
                /* FIXME: Implement all these in gsm-sms.c */
                data->MessageCenter->No = message[4];
                data->MessageCenter->Format = message[6];
                data->MessageCenter->Validity = message[8];  /* due to changes in format */
                /* FIXME: Implement all these in gsm-sms.c */
                data->MessageCenter->No = message[4];
                data->MessageCenter->Format = message[6];
                data->MessageCenter->Validity = message[8];  /* due to changes in format */
+               
                digits = message[9];
                bytes = message[21] - 1;
                
 
                sprintf(data->MessageCenter->Name, "%s", message + 33);
                
                digits = message[9];
                bytes = message[21] - 1;
                
 
                sprintf(data->MessageCenter->Name, "%s", message + 33);
                
-               strcpy(data->MessageCenter->Recipient, GetBCDNumber(message+9));
-               strcpy(data->MessageCenter->Number, GetBCDNumber(message+21));
-               data->MessageCenter->Type = message[22];
-               
                if (strlen(data->MessageCenter->Recipient) == 0) {
                        sprintf(data->MessageCenter->Recipient, "(none)");
                }
                if (strlen(data->MessageCenter->Recipient) == 0) {
                        sprintf(data->MessageCenter->Recipient, "(none)");
                }
@@ -884,17 +831,8 @@ static GSM_Error P7110_IncomingSMS(int messagetype, unsigned char *message, int
                }
                
                break;
                }
                
                break;
-
        case P7110_SUBSMS_SMS_SENT:
        case P7110_SUBSMS_SMS_SENT:
-               dprintf("SMS sent\n");
-               e = GE_SMSSENDOK;
-               break;
-
        case P7110_SUBSMS_SEND_FAIL:
        case P7110_SUBSMS_SEND_FAIL:
-               dprintf("SMS sending failed\n");
-               e = GE_SMSSENDFAILED;
-               break;
-
        case P7110_SUBSMS_SMS_RCVD:
        case P7110_SUBSMS_CELLBRD_OK:
        case P7110_SUBSMS_CELLBRD_FAIL:
        case P7110_SUBSMS_SMS_RCVD:
        case P7110_SUBSMS_CELLBRD_OK:
        case P7110_SUBSMS_CELLBRD_FAIL:
@@ -905,7 +843,6 @@ static GSM_Error P7110_IncomingSMS(int messagetype, unsigned char *message, int
                dprintf("Subtype 0x%02x of type 0x%02x (SMS handling) not implemented\n", message[3], P7110_MSG_SMS);
                e = GE_NOTIMPLEMENTED;
                break;
                dprintf("Subtype 0x%02x of type 0x%02x (SMS handling) not implemented\n", message[3], P7110_MSG_SMS);
                e = GE_NOTIMPLEMENTED;
                break;
-
        default:
                dprintf("Unknown subtype of type 0x%02x (SMS handling): 0x%02x\n", P7110_MSG_SMS, message[3]);
                e = GE_UNKNOWN;
        default:
                dprintf("Unknown subtype of type 0x%02x (SMS handling): 0x%02x\n", P7110_MSG_SMS, message[3]);
                e = GE_UNKNOWN;
@@ -1112,80 +1049,6 @@ static GSM_Error P7110_IncomingCalendar(int messagetype, unsigned char *message,
        return e;
 }
 
        return e;
 }
 
-static GSM_Error P7110_CallDivert(GSM_Data *data, GSM_Statemachine *state)
-{
-       unsigned short length = 0x09;
-       char req[55] = { FBUS_FRAME_HEADER, 0x01, 0x00, /* operation */
-                                               0x00,
-                                               0x00, /* divert type */
-                                               0x00, /* call type */
-                                               0x00 };
-       if (!data->CallDivert) return GE_UNKNOWN;
-       switch (data->CallDivert->Operation) {
-       case GSM_CDV_Query:
-               req[4] = 0x05;
-               break;
-       case GSM_CDV_Register:
-               req[4] = 0x03;
-               length = 0x16;
-               req[8] = 0x01;
-               req[9] = SemiOctetPack(data->CallDivert->Number.number, req + 10, data->CallDivert->Number.type);
-               req[21] = data->CallDivert->Timeout;
-               break;
-       case GSM_CDV_Erasure:
-               req[4] = 0x04;
-               break;
-       default:
-               return GE_NOTIMPLEMENTED;
-       }
-       switch (data->CallDivert->CType) {
-       case GSM_CDV_AllCalls:
-               break;
-       case GSM_CDV_VoiceCalls:
-               req[7] = 0x0b;
-               break;
-       case GSM_CDV_FaxCalls:
-               req[7] = 0x0d;
-               break;
-       case GSM_CDV_DataCalls:
-               req[7] = 0x19;
-               break;
-       default:
-               return GE_NOTIMPLEMENTED;
-       }
-       switch (data->CallDivert->DType) {
-       case GSM_CDV_AllTypes:
-               req[6] = 0x15;
-               break;
-       case GSM_CDV_Busy:
-               req[6] = 0x43;
-               break;
-       case GSM_CDV_NoAnswer:
-               req[6] = 0x3d;
-               break;
-       case GSM_CDV_OutOfReach:
-               req[6] = 0x3e;
-               break;
-       default:
-               return GE_NOTIMPLEMENTED;
-       }
-       if ((data->CallDivert->DType == GSM_CDV_AllTypes) && (data->CallDivert->CType == GSM_CDV_AllCalls))
-               req[6] = 0x02;
-
-       if (SM_SendMessage(state, length, P7110_MSG_DIVERT, req) != GE_NONE) return GE_NOTREADY;
-       return SM_WaitFor(state, data, P7110_MSG_DIVERT);
-}
-
-static GSM_Error P7110_IncomingCallDivert(int messagetype, unsigned char *message, int length, GSM_Data *data)
-{
-       int i;
-       for (i = 0; i < length; i++) {
-               dprintf("%02x ", message[i]);
-       }
-       dprintf("\n");
-       return GE_NONE;
-}
-
 static int GetMemoryType(GSM_MemoryType memory_type)
 {
        int result;
 static int GetMemoryType(GSM_MemoryType memory_type)
 {
        int result;
@@ -1591,7 +1454,7 @@ static GSM_Error P7110_GetSpeedDial(GSM_Data *data, GSM_Statemachine *state)
 static GSM_Error P7110_GetSMSCenter(GSM_Data *data, GSM_Statemachine *state)
 {
        GSM_Error       error;
 static GSM_Error P7110_GetSMSCenter(GSM_Data *data, GSM_Statemachine *state)
 {
        GSM_Error       error;
-       unsigned char   req[] = {FBUS_FRAME_HEADER, P7110_SUBSMS_GET_SMSC, 0x64, 0x00};
+       unsigned char   req[2000] = {FBUS_FRAME_HEADER, P7110_SUBSMS_GET_SMSC, 0x64, 0x00};
        
        req[5] = data->MessageCenter->No;
        
        
        req[5] = data->MessageCenter->No;
        
@@ -1604,7 +1467,7 @@ static GSM_Error P7110_GetSMSCenter(GSM_Data *data, GSM_Statemachine *state)
 static GSM_Error P7110_GetClock(char req_type, GSM_Data *data, GSM_Statemachine *state)
 {
        GSM_Error       error;
 static GSM_Error P7110_GetClock(char req_type, GSM_Data *data, GSM_Statemachine *state)
 {
        GSM_Error       error;
-       unsigned char   req[] = {FBUS_FRAME_HEADER, req_type};
+       unsigned char   req[2000] = {FBUS_FRAME_HEADER, req_type};
        
        if (SM_SendMessage(state, 4, P7110_MSG_CLOCK, req) != GE_NONE) return GE_NOTREADY;
        error = SM_Block(state, data, P7110_MSG_CLOCK);
        
        if (SM_SendMessage(state, 4, P7110_MSG_CLOCK, req) != GE_NONE) return GE_NOTREADY;
        error = SM_Block(state, data, P7110_MSG_CLOCK);
@@ -1615,8 +1478,8 @@ static GSM_Error P7110_GetClock(char req_type, GSM_Data *data, GSM_Statemachine
 static GSM_Error P7110_GetCalendarNote(GSM_Data *data, GSM_Statemachine *state)
 {
        GSM_Error       error = GE_NOTREADY;
 static GSM_Error P7110_GetCalendarNote(GSM_Data *data, GSM_Statemachine *state)
 {
        GSM_Error       error = GE_NOTREADY;
-       unsigned char   req[] = {FBUS_FRAME_HEADER, P7110_SUBCAL_GET_NOTE, 0x00, 0x00};
-       unsigned char   date[] = {FBUS_FRAME_HEADER, P7110_SUBCLO_GET_DATE};
+       unsigned char   req[2000] = {FBUS_FRAME_HEADER, P7110_SUBCAL_GET_NOTE, 0x00, 0x00};
+       unsigned char   date[2000] = {FBUS_FRAME_HEADER, P7110_SUBCLO_GET_DATE};
        GSM_Data        tmpdata;
        GSM_DateTime    tmptime;
        
        GSM_Data        tmpdata;
        GSM_DateTime    tmptime;