gnokii-users
[Top][All Lists]
Advanced

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

[PATCH] AT phones - move global variables into state


From: Ladislav Michl
Subject: [PATCH] AT phones - move global variables into state
Date: Thu, 5 Dec 2002 16:41:36 +0100
User-agent: Mutt/1.2.5i

Hi,

this is an attemt to move global variables into state. As a side effect is now
possible to use correct charset for Bosch phones :)

commets and sugestions will be appreciated.

Index: include/phones/atgen.h
===================================================================
RCS file: /cvsroot/gnokii/gnokii/include/phones/atgen.h,v
retrieving revision 1.10
diff -u -r1.10 atgen.h
--- include/phones/atgen.h      25 Nov 2002 22:11:36 -0000      1.10
+++ include/phones/atgen.h      5 Dec 2002 15:18:05 -0000
@@ -53,6 +53,22 @@
 typedef gn_error (*GSM_RecvFunctionType)(int type, unsigned char *buffer, int 
length, GSM_Data *data, GSM_Statemachine *state);
 typedef gn_error (*AT_SendFunctionType)(GSM_Data *data, GSM_Statemachine *s);
 
+GSM_RecvFunctionType AT_InsertRecvFunction(int type, GSM_RecvFunctionType 
func, GSM_Statemachine *state);
+AT_SendFunctionType AT_InsertSendFunction(int type, AT_SendFunctionType func, 
GSM_Statemachine *state);
+
+typedef struct {
+       AT_SendFunctionType Functions[GOPAT_Max];
+       GSM_IncomingFunctionType IncomingFunctions[GOPAT_Max];
+       int if_pos;
+
+       GSM_MemoryType memorytype;
+       GSM_MemoryType smsmemorytype;
+       GSMAT_Charset defaultcharset;
+       GSMAT_Charset charset;
+} AT_DriverInstance;
+
+#define AT_DRVINST(s) ((AT_DriverInstance *)((s)->Phone.DriverInstance))
+
 typedef struct {
        char *line1;
        char *line2;
@@ -60,9 +76,6 @@
        char *line4; /* When reading SMS there are 4 ouput lines. Maybe create 
a table here? */
        int length;
 } AT_LineBuffer;
-
-GSM_RecvFunctionType AT_InsertRecvFunction(int type, GSM_RecvFunctionType 
func);
-AT_SendFunctionType AT_InsertSendFunction(int type, AT_SendFunctionType func);
 
 gn_error AT_SetMemoryType(GSM_MemoryType mt, GSM_Statemachine *state);
 
Index: common/phones/atbosch.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/common/phones/atbosch.c,v
retrieving revision 1.2
diff -u -r1.2 atbosch.c
--- common/phones/atbosch.c     5 Dec 2002 11:01:58 -0000       1.2
+++ common/phones/atbosch.c     5 Dec 2002 15:18:35 -0000
@@ -43,6 +43,7 @@
 
 static gn_error GetCharset(GSM_Data *data, GSM_Statemachine *state)
 {
+       AT_DRVINST(state)->charset = CHARGSM;
        strcpy(data->Model, "GSM");
        return GN_ERR_NONE;
 }
@@ -110,15 +111,15 @@
 
 void AT_InitBosch(GSM_Statemachine *state, char *foundmodel, char *setupmodel)
 {
-       AT_InsertRecvFunction(GOPAT_GetCharset, NULL);
-       AT_InsertSendFunction(GOPAT_GetCharset, GetCharset);
-       AT_InsertRecvFunction(GOPAT_SetCharset, NULL);
-       AT_InsertSendFunction(GOPAT_SetCharset, SetCharset);
-       replygetsms = AT_InsertRecvFunction(GOP_GetSMS, ReplyGetSMS);
+       AT_InsertRecvFunction(GOPAT_GetCharset, NULL, state);
+       AT_InsertSendFunction(GOPAT_GetCharset, GetCharset, state);
+       AT_InsertRecvFunction(GOPAT_SetCharset, NULL, state);
+       AT_InsertSendFunction(GOPAT_SetCharset, SetCharset, state);
+       replygetsms = AT_InsertRecvFunction(GOP_GetSMS, ReplyGetSMS, state);
        /* phone lacks many usefull commands :( */
-       AT_InsertSendFunction(GOP_GetBatteryLevel, Unsupported);
-       AT_InsertSendFunction(GOP_GetRFLevel, Unsupported);
-       AT_InsertSendFunction(GOP_GetSecurityCodeStatus, Unsupported);
-       AT_InsertSendFunction(GOP_EnterSecurityCode, Unsupported);
-       AT_InsertSendFunction(GOP_SaveSMS, Unsupported);
+       AT_InsertSendFunction(GOP_GetBatteryLevel, Unsupported, state);
+       AT_InsertSendFunction(GOP_GetRFLevel, Unsupported, state);
+       AT_InsertSendFunction(GOP_GetSecurityCodeStatus, Unsupported, state);
+       AT_InsertSendFunction(GOP_EnterSecurityCode, Unsupported, state);
+       AT_InsertSendFunction(GOP_SaveSMS, Unsupported, state);
 }
Index: common/phones/ateric.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/common/phones/ateric.c,v
retrieving revision 1.6
diff -u -r1.6 ateric.c
--- common/phones/ateric.c      28 Sep 2002 23:51:37 -0000      1.6
+++ common/phones/ateric.c      5 Dec 2002 15:18:35 -0000
@@ -40,7 +40,6 @@
 #include "phones/atgen.h"
 #include "phones/ateric.h"
 #include "links/atbus.h"
-#include "links/cbus.h"
 
 
 static gn_error GetMemoryStatus(GSM_Data *data,  GSM_Statemachine *state)
@@ -48,14 +47,13 @@
        char req[128];
        gn_error ret;
 
-       ret = AT_SetMemoryType(data->MemoryStatus->MemoryType,  state);
-       if (ret != GN_ERR_NONE)
+       ret = AT_SetMemoryType(data->MemoryStatus->MemoryType, state);
+       if (ret)
                return ret;
        sprintf(req, "AT+CPBR=?\r\n");
-       if (SM_SendMessage(state, 11, GOP_GetMemoryStatus, req) != GN_ERR_NONE)
+       if (SM_SendMessage(state, 11, GOP_GetMemoryStatus, req))
                return GN_ERR_NOTREADY;
-       ret = SM_Block(state, data, GOP_GetMemoryStatus);
-       return ret;
+       return SM_Block(state, data, GOP_GetMemoryStatus);
 }
 
 
@@ -86,6 +84,6 @@
 
 void AT_InitEricsson(GSM_Statemachine *state, char *foundmodel, char 
*setupmodel)
 {
-       AT_InsertRecvFunction(GOP_GetMemoryStatus, ReplyMemoryStatus);
-       AT_InsertSendFunction(GOP_GetMemoryStatus, GetMemoryStatus);
+       AT_InsertRecvFunction(GOP_GetMemoryStatus, ReplyMemoryStatus, state);
+       AT_InsertSendFunction(GOP_GetMemoryStatus, GetMemoryStatus, state);
 }
Index: common/phones/atgen.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/common/phones/atgen.c,v
retrieving revision 1.61
diff -u -r1.61 atgen.c
--- common/phones/atgen.c       5 Dec 2002 11:25:34 -0000       1.61
+++ common/phones/atgen.c       5 Dec 2002 15:18:36 -0000
@@ -98,8 +98,6 @@
 
 
 /* Mobile phone information */
-static AT_SendFunctionType AT_Functions[GOPAT_Max];
-static GSM_IncomingFunctionType IncomingFunctions[GOPAT_Max];
 static AT_FunctionInitType AT_FunctionInit[] = {
        { GOP_Init, NULL, Reply },
        { GOP_Terminate, PGEN_Terminate, Reply }, /* Replyfunction must not be 
NULL */
@@ -134,7 +132,7 @@
 
 
 GSM_Phone phone_at = {
-       IncomingFunctions,
+       NULL,
        PGEN_IncomingDefault,
        {
                "AT|AT-HW|dancall",     /* Supported models */
@@ -155,11 +153,6 @@
        NULL
 };
 
-static GSM_MemoryType memorytype = GMT_XX;
-static GSM_MemoryType smsmemorytype = GMT_XX;
-static GSMAT_Charset atdefaultcharset = CHARNONE;
-static GSMAT_Charset atcharset = CHARNONE;
-
 static char *memorynames[] = {
        "ME", /* Internal memory of the mobile equipment */
        "SM", /* SIM card memory */
@@ -176,42 +169,54 @@
 };
 
 
-GSM_RecvFunctionType AT_InsertRecvFunction(int type, GSM_RecvFunctionType func)
+static gn_error Functions(GSM_Operation op, GSM_Data *data, GSM_Statemachine 
*state)
 {
-       static int pos = 0;
-       int i;
+       AT_DriverInstance *drvinst = AT_DRVINST(state);
+       if (op == GOP_Init)
+               return Initialise(data, state);
+       if ((op > GOP_Init) && (op < GOPAT_Max))
+               if (drvinst->Functions[op])
+                       return (*(drvinst->Functions[op]))(data, state);
+       return GN_ERR_NOTIMPLEMENTED;
+}
+
+GSM_RecvFunctionType AT_InsertRecvFunction(int type, GSM_RecvFunctionType 
func, GSM_Statemachine *state)
+{
+       AT_DriverInstance *drvinst = AT_DRVINST(state);
        GSM_RecvFunctionType oldfunc;
+       int i;
 
        if (type >= GOPAT_Max) {
                return (GSM_RecvFunctionType) -1;
        }
-       if (pos == 0) {
-               IncomingFunctions[pos].MessageType = type;
-               IncomingFunctions[pos].Functions = func;
-               pos++;
+       if (drvinst->if_pos == 0) {
+               drvinst->IncomingFunctions[0].MessageType = type;
+               drvinst->IncomingFunctions[0].Functions = func;
+               drvinst->if_pos++;
                return NULL;
        }
-       for (i = 0; i < pos; i++) {
-               if (IncomingFunctions[i].MessageType == type) {
-                       oldfunc = IncomingFunctions[i].Functions;
-                       IncomingFunctions[i].Functions = func;
+       for (i = 0; i < drvinst->if_pos; i++) {
+               if (drvinst->IncomingFunctions[i].MessageType == type) {
+                       oldfunc = drvinst->IncomingFunctions[i].Functions;
+                       drvinst->IncomingFunctions[i].Functions = func;
                        return oldfunc;
                }
        }
-       if (pos < GOPAT_Max-1) {
-               IncomingFunctions[pos].MessageType = type;
-               IncomingFunctions[pos].Functions = func;
-               pos++;
+       if (drvinst->if_pos < GOPAT_Max-1) {
+               drvinst->IncomingFunctions[drvinst->if_pos].MessageType = type;
+               drvinst->IncomingFunctions[drvinst->if_pos].Functions = func;
+               drvinst->if_pos++;
        }
        return NULL;
 }
 
-AT_SendFunctionType AT_InsertSendFunction(int type, AT_SendFunctionType func)
+AT_SendFunctionType AT_InsertSendFunction(int type, AT_SendFunctionType func, 
GSM_Statemachine *state)
 {
+       AT_DriverInstance *drvinst = AT_DRVINST(state);
        AT_SendFunctionType f;
 
-       f = AT_Functions[type];
-       AT_Functions[type] = func;
+       f = drvinst->Functions[type];
+       drvinst->Functions[type] = func;
        return f;
 }
 
@@ -249,26 +254,28 @@
  */
 static void StoreDefaultCharset(GSM_Statemachine *state)
 {
+       AT_DriverInstance *drvinst = AT_DRVINST(state);
        GSM_Data data;
-       gn_error ret;
        char buf[256];
+       gn_error ret;
 
        GSM_DataClear(&data);
        data.Model = buf;
        ret = state->Phone.Functions(GOPAT_GetCharset, &data, state);
        if (ret) return;
-       if (!strncmp(buf, "GSM", 3)) atdefaultcharset = CHARGSM;
-       if (strstr(buf, "437")) atdefaultcharset = CHARCP437;
+       if (!strncmp(buf, "GSM", 3)) drvinst->defaultcharset = CHARGSM;
+       if (strstr(buf, "437")) drvinst->defaultcharset = CHARCP437;
        return;
 }
 
 gn_error AT_SetMemoryType(GSM_MemoryType mt, GSM_Statemachine *state)
 {
+       AT_DriverInstance *drvinst = AT_DRVINST(state);
+       GSM_Data data;
        char req[32];
        gn_error ret = GN_ERR_NONE;
-       GSM_Data data;
 
-       if (mt != memorytype) {
+       if (mt != drvinst->memorytype) {
                sprintf(req, "AT+CPBS=\"%s\"\r", memorynames[mt]);
                ret = SM_SendMessage(state, 13, GOP_Init, req);
                if (ret)
@@ -276,18 +283,19 @@
                GSM_DataClear(&data);
                ret = SM_BlockNoRetry(state, &data, GOP_Init);
                if (ret == GN_ERR_NONE)
-                       memorytype = mt;
+                       drvinst->memorytype = mt;
        }
        return ret;
 }
 
 gn_error AT_SetSMSMemoryType(GSM_MemoryType mt, GSM_Statemachine *state)
 {
+       AT_DriverInstance *drvinst = AT_DRVINST(state);
+       GSM_Data data;
        char req[32];
        gn_error ret = GN_ERR_NONE;
-       GSM_Data data;
 
-       if (mt != smsmemorytype) {
+       if (mt != drvinst->smsmemorytype) {
                sprintf(req, "AT+CPMS=\"%s\"\r", memorynames[mt]);
                ret = SM_SendMessage(state, 13, GOP_Init, req);
                if (ret != GN_ERR_NONE)
@@ -295,7 +303,7 @@
                GSM_DataClear(&data);
                ret = SM_BlockNoRetry(state, &data, GOP_Init);
                if (ret == GN_ERR_NONE)
-                       smsmemorytype = mt;
+                       drvinst->smsmemorytype = mt;
        }
        return ret;
 }
@@ -334,11 +342,12 @@
  */
 static gn_error AT_SetCharset(GSM_Data *data, GSM_Statemachine *state)
 {
-       char charsets[256];
+       AT_DriverInstance *drvinst = AT_DRVINST(state);
        GSM_Data tmpdata;
+       char charsets[256];
        gn_error ret;
 
-       if (atcharset != CHARNONE)
+       if (drvinst->charset != CHARNONE)
                return GN_ERR_NONE;
        /* check if ucs2 is available */
        ret = SM_SendMessage(state, 10, GOPAT_GetCharset, "AT+CSCS=?\r");
@@ -359,13 +368,13 @@
                GSM_DataClear(&tmpdata);
                ret = SM_BlockNoRetry(state, &tmpdata, GOP_Init);
                if (ret == GN_ERR_NONE)
-                       atcharset = CHARUCS2;
+                       drvinst->charset = CHARUCS2;
        }
-       if (atcharset != CHARNONE)
+       if (drvinst->charset != CHARNONE)
                return GN_ERR_NONE;
        /* no ucs2 charset found or error occured */
-       if (atdefaultcharset == CHARGSM) {
-               atcharset = CHARGSM;
+       if (drvinst->defaultcharset == CHARGSM) {
+               drvinst->charset = CHARGSM;
                if (!strstr(charsets, "HEX")) {
                        /* no hex charset found! */
                        return GN_ERR_NONE;
@@ -377,7 +386,7 @@
                GSM_DataClear(&tmpdata);
                ret = SM_BlockNoRetry(state, &tmpdata, GOP_Init);
                if (ret == GN_ERR_NONE)
-                       atcharset = CHARHEXGSM;
+                       drvinst->charset = CHARHEXGSM;
        } else {
                ret = SM_SendMessage(state, 14, GOP_Init, "AT+CSCS=\"GSM\"\r");
                if (ret)
@@ -385,7 +394,7 @@
                GSM_DataClear(&tmpdata);
                ret = SM_BlockNoRetry(state, &tmpdata, GOP_Init);
                if (ret == GN_ERR_NONE)
-                       atcharset = CHARGSM;
+                       drvinst->charset = CHARGSM;
        }
        return ret;
 }
@@ -413,13 +422,13 @@
 {
        gn_error ret;
 
-       if ((ret = Functions(GOP_GetModel, data, state)))
+       if ((ret = state->Phone.Functions(GOP_GetModel, data, state)))
                return ret;
-       if ((ret = Functions(GOP_GetManufacturer, data, state)))
+       if ((ret = state->Phone.Functions(GOP_GetManufacturer, data, state)))
                return ret;
-       if ((ret = Functions(GOP_GetRevision, data, state)))
+       if ((ret = state->Phone.Functions(GOP_GetRevision, data, state)))
                return ret;
-       return Functions(GOP_GetImei, data, state);
+       return state->Phone.Functions(GOP_GetImei, data, state);
 }
 
 static gn_error AT_GetModel(GSM_Data *data, GSM_Statemachine *state)
@@ -502,6 +511,7 @@
 
 static gn_error AT_WritePhonebook(GSM_Data *data, GSM_Statemachine *state)
 {
+       AT_DriverInstance *drvinst = AT_DRVINST(state);
        int len, ofs;
        char req[256], *tmp;
        gn_error ret;
@@ -521,7 +531,7 @@
                              data->PhonebookEntry->Number[0] == '+' ? "145" : 
"129");
                len = strlen(data->PhonebookEntry->Name);
                tmp = req + ofs;
-               switch (atcharset) {
+               switch (drvinst->charset) {
                case CHARGSM:
                        len = char_encode_ascii(tmp, 
data->PhonebookEntry->Name, len);
                        break;
@@ -617,7 +627,7 @@
        if (!data->RawSMS) return GN_ERR_INTERNALERROR;
 
        /* Select PDU mode */
-       error = Functions(GOPAT_SetPDUMode, data, state);
+       error = state->Phone.Functions(GOPAT_SetPDUMode, data, state);
        if (error) {
                dprintf("PDU mode not supported\n");
                return error;
@@ -737,18 +747,9 @@
        return SM_BlockNoRetry(state, data, GOP_EnterSecurityCode);
 }
 
-static gn_error Functions(GSM_Operation op, GSM_Data *data, GSM_Statemachine 
*state)
-{
-       if (op == GOP_Init)
-               return Initialise(data, state);
-       if ((op > GOP_Init) && (op < GOPAT_Max))
-               if (AT_Functions[op])
-                       return (*AT_Functions[op])(data, state);
-       return GN_ERR_NOTIMPLEMENTED;
-}
-
 static gn_error ReplyReadPhonebook(int messagetype, unsigned char *buffer, int 
length, GSM_Data *data, GSM_Statemachine *state)
 {
+       AT_DriverInstance *drvinst = AT_DRVINST(state);
        AT_LineBuffer buf;
        char *pos, *endpos;
        int l;
@@ -805,7 +806,7 @@
                                endpos--;
                        }
                        l = endpos - pos;
-                       switch (atcharset) {
+                       switch (drvinst->charset) {
                        case CHARGSM:
                                char_decode_ascii(data->PhonebookEntry->Name, 
pos, l);
                                *(data->PhonebookEntry->Name + l) = '\0';
@@ -841,33 +842,31 @@
 
        splitlines(&buf);
        
-       if (data->MessageCenter) {
-               if (strstr(buf.line2,"+CSCA")) {
-                       pos = strchr(buf.line2 + 8, '\"');
-                       if (pos) {
-                               *pos++ = '\0';
-                               data->MessageCenter->No = 1;
-                               strncpy(data->MessageCenter->SMSC.Number, 
buf.line2 + 8, MAX_BCD_STRING_LENGTH);
-                               
data->MessageCenter->SMSC.Number[MAX_BCD_STRING_LENGTH - 1] = '\0';
-                               /* Now we look for the number type */
-                               data->MessageCenter->SMSC.Type = 0;
-                               aux = strchr(pos, ',');
-                               if (aux)
-                                       data->MessageCenter->SMSC.Type = 
atoi(++aux);
-                               else if (data->MessageCenter->SMSC.Number[0] == 
'+')
-                                       data->MessageCenter->SMSC.Type = 
SMS_International;
-                               if (!data->MessageCenter->SMSC.Type)
-                                       data->MessageCenter->SMSC.Type = 
SMS_Unknown;
-                       } else {
-                               data->MessageCenter->No = 0;
-                               strncpy(data->MessageCenter->Name, "SMS 
Center", GSM_MAX_SMS_CENTER_NAME_LENGTH);
+       if (data->MessageCenter && strstr(buf.line2,"+CSCA")) {
+               pos = strchr(buf.line2 + 8, '\"');
+               if (pos) {
+                       *pos++ = '\0';
+                       data->MessageCenter->No = 1;
+                       strncpy(data->MessageCenter->SMSC.Number, buf.line2 + 
8, MAX_BCD_STRING_LENGTH);
+                       data->MessageCenter->SMSC.Number[MAX_BCD_STRING_LENGTH 
- 1] = '\0';
+                       /* Now we look for the number type */
+                       data->MessageCenter->SMSC.Type = 0;
+                       aux = strchr(pos, ',');
+                       if (aux)
+                               data->MessageCenter->SMSC.Type = atoi(++aux);
+                       else if (data->MessageCenter->SMSC.Number[0] == '+')
+                               data->MessageCenter->SMSC.Type = 
SMS_International;
+                       if (!data->MessageCenter->SMSC.Type)
                                data->MessageCenter->SMSC.Type = SMS_Unknown;
-                       }
-                       data->MessageCenter->DefaultName = 1; /* use default 
name */
-                       data->MessageCenter->Format = SMS_FText; /* whatever */
-                       data->MessageCenter->Validity = SMS_VMax;
-                       strcpy(data->MessageCenter->Recipient.Number, "") ;
+               } else {
+                       data->MessageCenter->No = 0;
+                       strncpy(data->MessageCenter->Name, "SMS Center", 
GSM_MAX_SMS_CENTER_NAME_LENGTH);
+                       data->MessageCenter->SMSC.Type = SMS_Unknown;
                }
+               data->MessageCenter->DefaultName = 1; /* use default name */
+               data->MessageCenter->Format = SMS_FText; /* whatever */
+               data->MessageCenter->Validity = SMS_VMax;
+               strcpy(data->MessageCenter->Recipient.Number, "") ;
        }
        return GN_ERR_NONE;
 }
@@ -885,22 +884,20 @@
 
        splitlines(&buf);
 
-       if (data->MemoryStatus) {
-               if (strstr(buf.line2,"+CPBS")) {
-                       pos = strchr(buf.line2, ',');
-                       if (pos) {
-                               data->MemoryStatus->Used = atoi(++pos);
-                       } else {
-                               data->MemoryStatus->Used = 100;
-                               data->MemoryStatus->Free = 0;
-                               return GN_ERR_UNKNOWN;
-                       }
-                       pos = strchr(pos, ',');
-                       if (pos) {
-                               data->MemoryStatus->Free = atoi(++pos) - 
data->MemoryStatus->Used;
-                       } else {
-                               return GN_ERR_UNKNOWN;
-                       }
+       if (data->MemoryStatus && strstr(buf.line2,"+CPBS")) {
+               pos = strchr(buf.line2, ',');
+               if (pos) {
+                       data->MemoryStatus->Used = atoi(++pos);
+               } else {
+                       data->MemoryStatus->Used = 100;
+                       data->MemoryStatus->Free = 0;
+                       return GN_ERR_UNKNOWN;
+               }
+               pos = strchr(pos, ',');
+               if (pos) {
+                       data->MemoryStatus->Free = atoi(++pos) - 
data->MemoryStatus->Used;
+               } else {
+                       return GN_ERR_UNKNOWN;
                }
        }
        return GN_ERR_NONE;
@@ -1179,25 +1176,37 @@
 
 static gn_error Initialise(GSM_Data *setupdata, GSM_Statemachine *state)
 {
+       AT_DriverInstance *drvinst;
        GSM_Data data;
-       gn_error ret;
+       gn_error ret = GN_ERR_NONE;
        char model[20];
        char manufacturer[20];
        int i;
 
        dprintf("Initializing AT capable mobile phone ...\n");
-
+       
        /* Copy in the phone info */
        memcpy(&(state->Phone), &phone_at, sizeof(GSM_Phone));
 
+       if (!(drvinst = malloc(sizeof(AT_DriverInstance))))
+               return GN_ERR_MEMORYFULL;
+
+       state->Phone.IncomingFunctions = drvinst->IncomingFunctions;
+       AT_DRVINST(state) = drvinst;
+       drvinst->memorytype = GMT_XX;
+       drvinst->smsmemorytype = GMT_XX;
+       drvinst->defaultcharset = CHARNONE;
+       drvinst->charset = CHARNONE;
+
+       drvinst->if_pos = 0;
        for (i = 0; i < GOPAT_Max; i++) {
-               AT_Functions[i] = NULL;
-               IncomingFunctions[i].MessageType = 0;
-               IncomingFunctions[i].Functions = NULL;
+               drvinst->Functions[i] = NULL;
+               drvinst->IncomingFunctions[i].MessageType = 0;
+               drvinst->IncomingFunctions[i].Functions = NULL;
        }
        for (i = 0; i < ARRAY_LEN(AT_FunctionInit); i++) {
-               AT_InsertSendFunction(AT_FunctionInit[i].gop, 
AT_FunctionInit[i].sfunc);
-               AT_InsertRecvFunction(AT_FunctionInit[i].gop, 
AT_FunctionInit[i].rfunc);
+               AT_InsertSendFunction(AT_FunctionInit[i].gop, 
AT_FunctionInit[i].sfunc, state);
+               AT_InsertRecvFunction(AT_FunctionInit[i].gop, 
AT_FunctionInit[i].rfunc, state);
        }
 
        switch (state->Link.ConnectionType) {
@@ -1213,10 +1222,11 @@
                        ret = ATBUS_Initialise(state, false);
                break;
        default:
-               return GN_ERR_NOTSUPPORTED;
+               ret = GN_ERR_NOTSUPPORTED;
                break;
        }
-       if (ret != GN_ERR_NONE) return ret;
+       if (ret) 
+               goto out;
 
        SM_Initialise(state);
 
@@ -1236,11 +1246,12 @@
        GSM_DataClear(&data);
        data.Model = model;
        ret = state->Phone.Functions(GOP_GetModel, &data, state);
-       if (ret != GN_ERR_NONE) return ret;
-       GSM_DataClear(&data);
+       if (ret) 
+               goto out;
        data.Manufacturer = manufacturer;
        ret = state->Phone.Functions(GOP_GetManufacturer, &data, state);
-       if (ret != GN_ERR_NONE) return ret;
+       if (ret)
+               goto out;
 
        if (!strncasecmp(manufacturer, "bosch", 5))
                AT_InitBosch(state, model, setupdata->Model);
@@ -1254,8 +1265,13 @@
        StoreDefaultCharset(state);
 
        dprintf("Initialisation completed\n");
-
-       return GN_ERR_NONE;
+out:
+       if (ret) {
+               dprintf("Initialization failed (%d)\n", ret);
+               free(AT_DRVINST(state));
+               AT_DRVINST(state) = NULL;
+       }
+       return ret;
 }
 
 void splitlines(AT_LineBuffer *buf)
Index: common/phones/atnok.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/common/phones/atnok.c,v
retrieving revision 1.5
diff -u -r1.5 atnok.c
--- common/phones/atnok.c       28 Sep 2002 23:51:37 -0000      1.5
+++ common/phones/atnok.c       5 Dec 2002 15:18:36 -0000
@@ -40,7 +40,7 @@
 #include "phones/atgen.h"
 #include "phones/atnok.h"
 #include "links/atbus.h"
-#include "links/cbus.h"
+
 
 static AT_SendFunctionType writephonebook;
 
@@ -60,5 +60,5 @@
        /* 8210. if you write to the phonebook of a eg 7110 all extended */
        /* information will be lost. */
        if (strncasecmp("8210", foundmodel, 4))
-               writephonebook = AT_InsertSendFunction(GOP_WritePhonebook,  
WritePhonebook);
+               writephonebook = AT_InsertSendFunction(GOP_WritePhonebook,  
WritePhonebook, state);
 }
Index: common/phones/atsie.c
===================================================================
RCS file: /cvsroot/gnokii/gnokii/common/phones/atsie.c,v
retrieving revision 1.6
diff -u -r1.6 atsie.c
--- common/phones/atsie.c       28 Sep 2002 23:51:37 -0000      1.6
+++ common/phones/atsie.c       5 Dec 2002 15:18:36 -0000
@@ -40,7 +40,7 @@
 #include "phones/atgen.h"
 #include "phones/atsie.h"
 #include "links/atbus.h"
-#include "links/cbus.h"
+
 
 static AT_SendFunctionType writephonebook;
 
@@ -65,5 +65,5 @@
 {
        /* names for s35 etc must be escaped */
        if (foundmodel && !strncasecmp("35", foundmodel + 1, 2))
-               writephonebook = AT_InsertSendFunction(GOP_WritePhonebook, 
WritePhonebook);
+               writephonebook = AT_InsertSendFunction(GOP_WritePhonebook, 
WritePhonebook, state);
 }




reply via email to

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