gnokii-users
[Top][All Lists]
Advanced

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

3110 prevent sm_block_many() the patch!


From: Osma Suominen
Subject: 3110 prevent sm_block_many() the patch!
Date: Thu, 27 Feb 2003 09:45:35 +0200 (EET)

Hi again,

I forgot the patch from my last message. Here it is.

-Osma

Index: common/links/fbus-3110.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/common/links/fbus-3110.c,v
retrieving revision 1.20
diff -u -r1.20 fbus-3110.c
--- common/links/fbus-3110.c    26 Feb 2003 22:02:17 -0000      1.20
+++ common/links/fbus-3110.c    27 Feb 2003 07:44:05 -0000
@@ -53,6 +53,7 @@
 static gn_error fb3110_message_send(u16 messagesize, u8 messagetype, unsigned 
char *message, struct gn_statemachine *state);
 static void fb3110_tx_ack_send(u8 *message, int length, struct gn_statemachine 
*state);
 static void fb3110_sequence_number_update(struct gn_statemachine *state);
+static int fb3110_message_type_fold(int type);

 /* FIXME - win32 stuff! */

@@ -148,7 +149,7 @@
                                dprintf("\n");
                                /* Transfer message to state machine */
                                sm_incoming_acknowledge(state);
-                               sm_incoming_function(i->buffer[0], i->buffer, 
i->frame_len, state);
+                               
sm_incoming_function(fb3110_message_type_fold(i->buffer[0]), i->buffer, 
i->frame_len, state);

                                /* Send an ack */
                                fb3110_tx_ack_send(i->buffer, i->frame_len, 
state);
@@ -380,4 +381,47 @@

        if (FBUSINST(state)->request_sequence_number > 0x17 || 
FBUSINST(state)->request_sequence_number < 0x10)
                FBUSINST(state)->request_sequence_number = 0x10;
+}
+
+/* The 3110 protocol has a tendency to use different message types to
+ * indicate succesful and failed actions. These are not handled very well by
+ * the gnokii internals, so they are "folded" together and dealt with in the
+ * 3110 code instead. The logic is that each success/failure message type
+ * pair is reported as the type of the message to indicate success.
+ * The argument is the original message type i.e. first byte of message. */
+
+static int fb3110_message_type_fold(int type)
+{
+       switch (type) {
+       case 0x15:
+       case 0x16:
+       case 0x17:
+               return 0x16;    /* initialization */
+       case 0x21:
+       case 0x22:
+               return 0x21;    /* send DTMF */
+       case 0x28:
+       case 0x29:
+               return 0x28;    /* SMS sent */
+       case 0x2a:
+       case 0x2b:
+               return 0x2a;    /* SMS saved */
+       case 0x2c:
+       case 0x2d:
+               return 0x2c;    /* SMS read */
+       case 0x2e:
+       case 0x2f:
+               return 0x2e;    /* SMS deleted */
+       case 0x3d:
+       case 0x3e:
+               return 0x3d;    /* SMSC set */
+       case 0x44:
+       case 0x45:
+               return 0x44;    /* mem location set */
+       case 0x46:
+       case 0x47:
+               return 0x46;    /* mem location read */
+       default:
+               return type;    /* all others left as-is */
+       }
 }
Index: common/phones/nk3110.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/common/phones/nk3110.c,v
retrieving revision 1.32
diff -u -r1.32 nk3110.c
--- common/phones/nk3110.c      26 Feb 2003 00:15:48 -0000      1.32
+++ common/phones/nk3110.c      27 Feb 2003 07:44:06 -0000
@@ -73,17 +73,12 @@
 static gn_error P3110_IncomingEndOfOutgoingCall2(int messagetype, unsigned 
char *buffer, int length, gn_data *data, struct gn_statemachine *state);
 static gn_error P3110_IncomingRestart(int messagetype, unsigned char *buffer, 
int length, gn_data *data, struct gn_statemachine *state);
 static gn_error P3110_IncomingInitFrame_0x15(int messagetype, unsigned char 
*buffer, int length, gn_data *data, struct gn_statemachine *state);
-static gn_error P3110_IncomingInitFrame_0x16(int messagetype, unsigned char 
*buffer, int length, gn_data *data, struct gn_statemachine *state);
-static gn_error P3110_IncomingInitFrame_0x17(int messagetype, unsigned char 
*buffer, int length, gn_data *data, struct gn_statemachine *state);
+static gn_error P3110_IncomingInitFrame(int messagetype, unsigned char 
*buffer, int length, gn_data *data, struct gn_statemachine *state);
 static gn_error P3110_IncomingSMSUserData(int messagetype, unsigned char 
*buffer, int length, gn_data *data, struct gn_statemachine *state);
 static gn_error P3110_IncomingSMSSend(int messagetype, unsigned char *buffer, 
int length, gn_data *data, struct gn_statemachine *state);
-static gn_error P3110_IncomingSMSSendError(int messagetype, unsigned char 
*buffer, int length, gn_data *data, struct gn_statemachine *state);
 static gn_error P3110_IncomingSMSSave(int messagetype, unsigned char *buffer, 
int length, gn_data *data, struct gn_statemachine *state);
-static gn_error P3110_IncomingSMSSaveError(int messagetype, unsigned char 
*buffer, int length, gn_data *data, struct gn_statemachine *state);
 static gn_error P3110_IncomingSMSHeader(int messagetype, unsigned char 
*buffer, int length, gn_data *data, struct gn_statemachine *state);
-static gn_error P3110_IncomingSMSError(int messagetype, unsigned char *buffer, 
int length, gn_data *data, struct gn_statemachine *state);
 static gn_error P3110_IncomingSMSDelete(int messagetype, unsigned char 
*buffer, int length, gn_data *data, struct gn_statemachine *state);
-static gn_error P3110_IncomingSMSDeleteError(int messagetype, unsigned char 
*buffer, int length, gn_data *data, struct gn_statemachine *state);
 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);
@@ -106,8 +101,8 @@
        { 0x12, P3110_IncomingEndOfOutgoingCall2 },
        { 0x13, P3110_IncomingRestart },
        { 0x15, P3110_IncomingInitFrame_0x15 },
-       { 0x16, P3110_IncomingInitFrame_0x16 },
-       { 0x17, P3110_IncomingInitFrame_0x17 },
+       { 0x16, P3110_IncomingInitFrame },
+       { 0x17, P3110_IncomingInitFrame },
        { 0x20, P3110_IncomingNothing },
        /*{ 0x21, P3110_IncomingDTMFSucess },*/
        /*{ 0x22, P3110_IncomingDTMFFailure },*/
@@ -117,14 +112,14 @@
        { 0x26, P3110_IncomingNothing },
        { 0x27, P3110_IncomingSMSUserData },
        { 0x28, P3110_IncomingSMSSend },
-       { 0x29, P3110_IncomingSMSSendError },
+       { 0x29, P3110_IncomingSMSSend },
        { 0x2a, P3110_IncomingSMSSave },
-       { 0x2b, P3110_IncomingSMSSaveError },
+       { 0x2b, P3110_IncomingSMSSave },
        /* ... */
        { 0x2c, P3110_IncomingSMSHeader },
-       { 0x2d, P3110_IncomingSMSError },
+       { 0x2d, P3110_IncomingSMSHeader },
        { 0x2e, P3110_IncomingSMSDelete },
-       { 0x2f, P3110_IncomingSMSDeleteError },
+       { 0x2f, P3110_IncomingSMSDelete },
        /* ... */
        { 0x32, P3110_IncomingSMSDelivered },
        { 0x3f, P3110_IncomingNothing },
@@ -686,7 +681,6 @@
        return GN_ERR_NONE;
 }

-
 /* 0x16 messages are sent by the phone during initialisation, to response
    to the 0x15 message.
    Sequence bytes have been observed to change with differing software
@@ -695,21 +689,21 @@
    and 0x01 when not (e.g. when SIM card isn't inserted to phone or when
    it is waiting for PIN) */

-static gn_error P3110_IncomingInitFrame_0x16(int messagetype, unsigned char 
*message, int length, gn_data *data, struct gn_statemachine *state)
-{
-       DRVINSTANCE(state)->sim_available = (message[2] == 0x02);
-       dprintf("SIM available: %s.\n", (DRVINSTANCE(state)->sim_available ? 
"Yes" : "No"));
-       return GN_ERR_NONE;
-}
-
-
-static gn_error P3110_IncomingInitFrame_0x17(int messagetype, unsigned char 
*message, int length, gn_data *data, struct gn_statemachine *state)
+static gn_error P3110_IncomingInitFrame(int messagetype, unsigned char 
*message, int length, gn_data *data, struct gn_statemachine *state)
 {
-       dprintf("0x17 Registration Response: Failure!\n");
-       return GN_ERR_NONE;
+       switch (message[0]) { /* unfold message type */
+       case 0x16:
+               DRVINSTANCE(state)->sim_available = (message[2] == 0x02);
+               dprintf("SIM available: %s.\n", 
(DRVINSTANCE(state)->sim_available ? "Yes" : "No"));
+               return GN_ERR_NONE;
+       case 0x17:
+               dprintf("0x17 Registration Response: Failure!\n");
+               return GN_ERR_NONE;
+       default:
+               return GN_ERR_INTERNALERROR;
+       }
 }

-
 /* 0x27 messages are a little unusual when sent by the phone in that
    they can either be an acknowledgement of an 0x27 message we sent
    to the phone with message text in it or they could
@@ -754,58 +748,69 @@
    TP-MR is send from phone within 0x32 message. TP-MR is increased
    by phone after each sent SMS */

-static gn_error P3110_IncomingSMSSend(int messagetype, unsigned char *message, 
int length, gn_data *data, struct gn_statemachine *state)
-{
-       dprintf("SMS send OK (0x%02hhx)\n", message[2]);
-       data->raw_sms->number = (int) message[2];
-       return GN_ERR_NONE;
-}
-
-
 /* 0x29 messages are sent by the phone to indicate an error in
    sending an SMS message.  Observed values are 0x65 0x15 when
    the phone originated SMS was disabled by the network for
    the particular phone.  0x65 0x26 was observed too, whereupon
    the message was retried. */

-static gn_error P3110_IncomingSMSSendError(int messagetype, unsigned char 
*message, int length, gn_data *data, struct gn_statemachine *state)
+static gn_error P3110_IncomingSMSSend(int messagetype, unsigned char *message, 
int length, gn_data *data, struct gn_statemachine *state)
 {
-       dprintf("SMS send failed (0x%02hhx 0x%02hhx)\n", message[2], 
message[3]);
-       return GN_ERR_FAILED;
+       switch (message[0]) { /* unfold message type */
+       case 0x28:
+               dprintf("SMS send OK (0x%02hhx)\n", message[2]);
+               data->raw_sms->number = (int) message[2];
+               return GN_ERR_NONE;
+       case 0x29:
+               dprintf("SMS send failed (0x%02hhx 0x%02hhx)\n", message[2], 
message[3]);
+               return GN_ERR_FAILED;
+       default:
+               return GN_ERR_INTERNALERROR;
+       }
 }

 /* 0x2a messages are sent by the phone to acknowledge succesful
    saving of an SMS message. */

-static gn_error P3110_IncomingSMSSave(int messagetype, unsigned char *message, 
int length, gn_data *data, struct gn_statemachine *state)
-{
-       dprintf("SMS save OK (0x%02hhx)\n", message[2]);
-       data->raw_sms->number = (int) message[2];
-       return GN_ERR_NONE;
-}
-
-
 /* 0x2b messages are sent by the phone to indicate an error in
    saving an SMS message. */

-static gn_error P3110_IncomingSMSSaveError(int messagetype, unsigned char 
*message, int length, gn_data *data, struct gn_statemachine *state)
+static gn_error P3110_IncomingSMSSave(int messagetype, unsigned char *message, 
int length, gn_data *data, struct gn_statemachine *state)
 {
-       dprintf("SMS send failed (0x%02hhx)\n", message[2]);
-       return GN_ERR_FAILED;
+       switch (message[0]) { /* unfold message type */
+       case 0x2a:
+               dprintf("SMS save OK (0x%02hhx)\n", message[2]);
+               data->raw_sms->number = (int) message[2];
+               return GN_ERR_NONE;
+       case 0x2b:
+               dprintf("SMS send failed (0x%02hhx)\n", message[2]);
+               return GN_ERR_FAILED;
+       default:
+               return GN_ERR_INTERNALERROR;
+       }
 }

-
 /* 0x2c messages are generated by the phone when we request an SMS
    message with an 0x25 message.  Appears to have the same fields
    as the 0x30 notification but with one extra.  Immediately after
    the 0x2c nessage, the phone sends 0x27 message(s) */

+/* 0x2d messages are generated when an SMS message is requested
+   that does not exist or is empty. */
+
 static gn_error P3110_IncomingSMSHeader(int messagetype, unsigned char 
*message, int length, gn_data *data, struct gn_statemachine *state)
 {
        int smsc_length, remote_length, l;
        gn_gsm_number_type smsc_number_type, remote_number_type;
        unsigned char smsc[256], remote[256];   /* should be enough for anyone 
*/

+       if (message[0] == 0x2d) { /* unfold message type */
+               if (message[2] == 0x74)
+                       return GN_ERR_INVALIDLOCATION;
+               else
+                       return GN_ERR_EMPTYLOCATION;
+       } else if (message[0] != 0x2c) return GN_ERR_INTERNALERROR;
+
        if (!data->raw_sms) {
                dprintf("Unrequested SMS header received. Ignoring.\n");
                return GN_ERR_INTERNALERROR;
@@ -877,41 +882,28 @@
        return GN_ERR_NONE;
 }

-
-/* 0x2d messages are generated when an SMS message is requested
-   that does not exist or is empty. */
-
-static gn_error P3110_IncomingSMSError(int messagetype, unsigned char 
*message, int length, gn_data *data, struct gn_statemachine *state)
-{
-       if (message[2] == 0x74)
-               return GN_ERR_INVALIDLOCATION;
-       else
-               return GN_ERR_EMPTYLOCATION;
-}
-
-
 /* 0x2e messages are generated when an SMS message is deleted
    successfully. */

-static gn_error P3110_IncomingSMSDelete(int messagetype, unsigned char 
*message, int length, gn_data *data, struct gn_statemachine *state)
-{
-       return GN_ERR_NONE;
-}
-
-
 /* 0x2f messages are generated when an SMS message is deleted
    that does not exist.  Unlike responses to a getsms message
    no error is returned when the entry is already empty */

-static gn_error P3110_IncomingSMSDeleteError(int messagetype, unsigned char 
*message, int length, gn_data *data, struct gn_statemachine *state)
+static gn_error P3110_IncomingSMSDelete(int messagetype, unsigned char 
*message, int length, gn_data *data, struct gn_statemachine *state)
 {
-       /* Note 0x74 is the only value that has been seen! */
-       if (message[2] == 0x74)
-               return GN_ERR_INVALIDLOCATION;
-       else
-               return GN_ERR_EMPTYLOCATION;
+       switch (message[0]) { /* unfold message type */
+       case 0x2e:
+               return GN_ERR_NONE;
+       case 0x2f:
+               /* Note 0x74 is the only value that has been seen! */
+               if (message[2] == 0x74)
+                       return GN_ERR_INVALIDLOCATION;
+               else
+                       return GN_ERR_EMPTYLOCATION;
+       default:
+               return GN_ERR_INTERNALERROR;
+       }
 }
-

 /* 0x32 messages are generated when delivery notification arrives
    to phone from network */

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




reply via email to

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