gnokii-users
[Top][All Lists]
Advanced

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

3110 memory type ugliness fix (patch)


From: Osma Suominen
Subject: 3110 memory type ugliness fix (patch)
Date: Wed, 12 Feb 2003 21:46:21 +0200 (EET)

Hi,

here's a patch that fixes some of the ugliness related to memory type
settings in the 3110 driver. I'll soon post other patches like this that
clan up hardcoded stuff or other ugly code in the 3110 driver, one
feature at a time as requested by Pawel.

This memory type code compiles and sems to run OK but as my 3110 only
has SIM memory I can't test it very thoroughly. I don't think it's at
least any worse than the old code it replaces...

-Osma


diff -u -r1.26 nk3110.c
--- common/phones/nk3110.c      4 Feb 2003 22:42:49 -0000       1.26
+++ common/phones/nk3110.c      12 Feb 2003 19:40:24 -0000
@@ -88,6 +88,7 @@
 static gn_error P3110_IncomingPhoneInfo(int messagetype, unsigned char 
*buffer, int length, gn_data *data, struct gn_statemachine *state);

 static int sms_header_encode(gn_data *data, struct gn_statemachine *state, 
unsigned char *req, int ulength, bool save_sms);
+static int get_memory_type(gn_memory_type memory_type);

 static gn_incoming_function_type incoming_functions[] = {
        { 0x0a, P3110_IncomingNothing },
@@ -306,7 +307,7 @@

 static gn_error P3110_GetSMSMessage(gn_data *data, struct gn_statemachine 
*state)
 {
-       int timeout, c;
+       int timeout, c, memory_type;
        u8 response = 0, request[2];
        gn_error error = GN_ERR_INTERNALERROR;

@@ -316,19 +317,10 @@

        if (!data->raw_sms) return GN_ERR_INTERNALERROR;

-       switch(data->raw_sms->memory_type) {
-       case GN_MT_ME:
-               data->raw_sms->memory_type = 1; /* 3 in 8110, 1 is GMT_CB */
-               break;
-       case GN_MT_SM:
-               data->raw_sms->memory_type = 2;
-               break;
-       default:
-               return  GN_ERR_INVALIDMEMORYTYPE;
-       }
-
        /* Set memory type and location in the request */
-       request[0] = data->raw_sms->memory_type;
+       memory_type = get_memory_type(data->raw_sms->memory_type);
+       if(memory_type == 0) return GN_ERR_INVALIDMEMORYTYPE;
+       request[0] = memory_type;
        request[1] = data->raw_sms->number;

        /* 0x25 messages requests the contents of an SMS message
@@ -387,7 +379,7 @@

 static gn_error P3110_DeleteSMSMessage(gn_data *data, struct gn_statemachine 
*state)
 {
-       int timeout, c;
+       int timeout, c, memory_type;
        u8 response = 0, request[2];
        gn_error error = GN_ERR_INTERNALERROR;

@@ -395,19 +387,10 @@

        KeepAliveTimer = P3110_KEEPALIVE_TIMEOUT;

-       switch(data->raw_sms->memory_type) {
-       case GN_MT_ME:
-               data->raw_sms->memory_type = 1; /* 3 in 8110, 1 is GMT_CB */
-               break;
-       case GN_MT_SM:
-               data->raw_sms->memory_type = 2;
-               break;
-       default:
-               return  GN_ERR_INVALIDMEMORYTYPE;
-       }
-
        /* Set memory type and location in the request */
-       request[0] = data->raw_sms->memory_type;
+       memory_type = get_memory_type(data->raw_sms->memory_type);
+       if(memory_type == 0) return GN_ERR_INVALIDMEMORYTYPE;
+       request[0] = memory_type;
        request[1] = data->raw_sms->number;

        /* 0x26 message deletes an SMS message from the phone.
@@ -1166,8 +1149,7 @@
        dprintf("smsc:'%s' remote:'%s'", smsc, remote);

        if(save_sms) { /* make header for saving SMS */
-/*             req[pos++] = data->raw_sms->memory_type; */
-               req[pos++] = 0x02;      /* FIXME MT always SIM for now */
+               req[pos++] = get_memory_type(data->raw_sms->memory_type);
                req[pos++] = data->raw_sms->status;
                req[pos++] = 0x01;      /* status byte for "saved SMS" */
        } else { /* make header for sending SMS */
@@ -1216,3 +1198,16 @@

        return pos;     /* length of encoded header is returned */
 }
+
+static int get_memory_type(gn_memory_type memory_type) {
+       int result;
+
+       switch(memory_type) {
+       case GN_MT_CB:  result = 0x01; break;
+       case GN_MT_SM:  result = 0x02; break;
+       case GN_MT_ME:  result = 0x03; break;
+       case GN_MT_ON:  result = 0x04; break;
+       default:        result = 0; break;      /* error code */
+       }
+       return result;
+}


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




reply via email to

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