gnokii-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

3110 phonebook handling [patch]


From: Osma Suominen
Subject: 3110 phonebook handling [patch]
Date: Fri, 30 May 2003 15:33:02 +0300 (EEST)

Hello again,

I implemented phonebook handling on the 3110. It's not thoroughly tested
but "works for me". It's a bit unclear where in the code sanity checks
should be made. e.g. the 6100 series driver makes a lot of them while
the AT driver doesn't. Example situation is that advanced phonebook
features (like subentries) are used on a phone that doesn't support
them - where should it be caught? This code doesn't do a lot of checks
but those could be added easily.

This is meant to be applied after the sms data encoding patch but
probably works independently as well.

And then I'm heading for the data calls part, which is hard...probably I
need to rewrite the fbus-3110 code and hack the statemachine as well.

-Osma

--- common/phones/nk3110-smsdata.c      2003-05-29 21:09:51.000000000 +0300
+++ common/phones/nk3110.c      2003-05-29 22:26:54.000000000 +0300
@@ -63,6 +63,8 @@
 static gn_error P3110_GetSMSMessage(gn_data *data, struct gn_statemachine 
*state);
 static gn_error P3110_DeleteSMSMessage(gn_data *data, struct gn_statemachine 
*state);
 static gn_error P3110_SendSMSMessage(gn_data *data, struct gn_statemachine 
*state, bool save_sms);
+static gn_error P3110_ReadPhonebook(gn_data *data, struct gn_statemachine 
*state);
+static gn_error P3110_WritePhonebook(gn_data *data, struct gn_statemachine 
*state);
 static gn_error P3110_IncomingNothing(int messagetype, unsigned char *message, 
int length, gn_data *data, struct gn_statemachine *state);
 static gn_error P3110_IncomingCall(int messagetype, unsigned char *buffer, int 
length, gn_data *data, struct gn_statemachine *state);
 static gn_error P3110_IncomingCallAnswered(int messagetype, unsigned char 
*buffer, int length, gn_data *data, struct gn_statemachine *state);
@@ -80,6 +82,8 @@
 static gn_error P3110_IncomingSMSDelivered(int messagetype, unsigned char 
*buffer, int length, gn_data *data, struct gn_statemachine *state);
 static gn_error P3110_IncomingNoSMSInfo(int messagetype, unsigned char 
*buffer, int length, gn_data *data, struct gn_statemachine *state);
 static gn_error P3110_IncomingSMSInfo(int messagetype, unsigned char *buffer, 
int length, gn_data *data, struct gn_statemachine *state);
+static gn_error P3110_IncomingPhonebookRead(int messagetype, unsigned char 
*message, int length, gn_data *data, struct gn_statemachine *state);
+static gn_error P3110_IncomingPhonebookWrite(int messagetype, unsigned char 
*message, int length, gn_data *data, struct gn_statemachine *state);
 static gn_error P3110_IncomingPINEntered(int messagetype, unsigned char 
*buffer, int length, gn_data *data, struct gn_statemachine *state);
 static gn_error P3110_IncomingStatusInfo(int messagetype, unsigned char 
*buffer, int length, gn_data *data, struct gn_statemachine *state);
 static gn_error P3110_IncomingPhoneInfo(int messagetype, unsigned char 
*buffer, int length, gn_data *data, struct gn_statemachine *state);
@@ -125,6 +129,12 @@
        { 0x3f, P3110_IncomingNothing },
        { 0x40, P3110_IncomingNoSMSInfo },
        { 0x41, P3110_IncomingSMSInfo },
+       { 0x42, P3110_IncomingNothing },
+       { 0x43, P3110_IncomingNothing },
+       { 0x44, P3110_IncomingPhonebookWrite },
+       { 0x45, P3110_IncomingPhonebookWrite },
+       { 0x46, P3110_IncomingPhonebookRead },
+       { 0x47, P3110_IncomingPhonebookRead },
        { 0x48, P3110_IncomingPINEntered },
        { 0x4a, P3110_IncomingNothing },
        { 0x4b, P3110_IncomingStatusInfo },
@@ -179,7 +189,10 @@
        case GN_OP_GetMemoryStatus:
                return P3110_GetMemoryStatus(data, state);
        case GN_OP_ReadPhonebook:
+               return P3110_ReadPhonebook(data, state);
        case GN_OP_WritePhonebook:
+               return P3110_WritePhonebook(data, state);
+
        case GN_OP_GetPowersource:
        case GN_OP_GetAlarm:
        case GN_OP_GetSMSStatus:
@@ -464,6 +477,42 @@
        return GN_ERR_FAILED;
 }

+static gn_error P3110_ReadPhonebook(gn_data *data, struct gn_statemachine 
*state)
+{
+       unsigned char req[2];
+
+       req[0] = get_memory_type(data->phonebook_entry->memory_type);
+       req[1] = data->phonebook_entry->location;
+
+       if (sm_message_send(2, 0x43, req, state) != GN_ERR_NONE)
+               return GN_ERR_NOTREADY;
+
+       return sm_block(0x46, data, state);
+}
+
+static gn_error P3110_WritePhonebook(gn_data *data, struct gn_statemachine 
*state)
+{
+       int namelen, numberlen;
+       unsigned char req[256];
+
+       req[0] = get_memory_type(data->phonebook_entry->memory_type);
+       req[1] = data->phonebook_entry->location;
+
+       namelen = strlen(data->phonebook_entry->name);
+       numberlen = strlen(data->phonebook_entry->number);
+
+       req[2] = namelen;
+       memcpy(req + 3, data->phonebook_entry->name, namelen);
+
+       req[3 + namelen] = numberlen;
+       memcpy(req + 3 + namelen + 1, data->phonebook_entry->number, numberlen);
+
+       if (sm_message_send(3 + namelen + 1 + numberlen, 0x42, req, state) != 
GN_ERR_NONE)
+               return GN_ERR_NOTREADY;
+
+       return sm_block(0x44, data, state);
+}
+
 static gn_error P3110_IncomingNothing(int messagetype, unsigned char *message, 
int length, gn_data *data, struct gn_statemachine *state)
 {
        return GN_ERR_NONE;
@@ -944,6 +993,65 @@
        return GN_ERR_NONE;
 }

+static gn_error P3110_IncomingPhonebookRead(int messagetype, unsigned char 
*message, int length, gn_data *data, struct gn_statemachine *state)
+{
+       int namelen, numberlen;
+
+       if(!data->phonebook_entry) return GN_ERR_INTERNALERROR;
+
+       switch (message[0]) { /* unfold message type */
+       case 0x46:
+               dprintf("Phonebook read OK\n");
+               break;
+       case 0x47:
+               /* 0x74 is the only seen error code */
+               if (message[2] == 0x74)
+                       return GN_ERR_INVALIDLOCATION;
+               else
+                       return GN_ERR_EMPTYLOCATION;
+       default:
+               return GN_ERR_INTERNALERROR;
+       }
+
+       /* empty locations are reported with empty name and number, so
+        * check for that case here */
+
+       if (message[2] == 0x00 && message[3] == 0x00)
+               return GN_ERR_EMPTYLOCATION;
+
+       data->phonebook_entry->caller_group = 0;
+       data->phonebook_entry->subentries_count = 0;
+
+       namelen = message[2];
+
+       memcpy(data->phonebook_entry->name, message + 3, namelen);
+       *(data->phonebook_entry->name + namelen) = '\0';
+
+       numberlen = message[3 + namelen];
+
+       memcpy(data->phonebook_entry->number, message + 3 + namelen + 1, 
numberlen);
+       *(data->phonebook_entry->number + numberlen) = '\0';
+
+       return GN_ERR_NONE;
+}
+
+static gn_error P3110_IncomingPhonebookWrite(int messagetype, unsigned char 
*message, int length, gn_data *data, struct gn_statemachine *state)
+{
+       switch (message[0]) { /* unfold message type */
+       case 0x44:
+               dprintf("Phonebook written OK\n");
+               return GN_ERR_NONE;
+       case 0x45:
+               dprintf("Phonebook write failed (0x%02x)\n", message[2]);
+               switch(message[2]) {
+                       case 0x74:      return GN_ERR_INVALIDLOCATION;
+                       case 0x66:      return GN_ERR_ENTRYTOOLONG;
+                       default:        return GN_ERR_UNKNOWN;
+               }
+       default:
+               return GN_ERR_INTERNALERROR;
+       }
+}

 /* 0x48 is sent during power-on of the phone, after the 0x13
    message is received and the PIN (if any) has been entered
--- common/links/fbus-3110.c.orig       2003-05-29 22:42:31.000000000 +0300
+++ common/links/fbus-3110.c    2003-05-29 22:20:17.000000000 +0300
@@ -297,6 +297,10 @@
                   SMS message center details.  Phone responds with an ack to
                   our 0x3f request then sends an 0x41 message that has the
                   actual data in it. */
+       case 0x42:
+               /* ack for phonebook write */
+       case 0x43:
+               /* ack for phonebook read */
        case 0x4a:
                /* 0x4a message is a response to our 0x4a request, assumed to
                   be a keepalive message of sorts.  No response required. */

-- 
*** Osma Suominen *** address@hidden *** http://www.iki.fi/ozone/ ***




reply via email to

[Prev in Thread] Current Thread [Next in Thread]