[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
3110 driver instance vars (patch)
From: |
Osma Suominen |
Subject: |
3110 driver instance vars (patch) |
Date: |
Fri, 14 Feb 2003 22:36:54 +0200 (EET) |
Hello again,
here's a patch that moves the remaining global static variables in
nk3110.c into a driver instance strucure similar to that used by
nk6100.c. Again no changes in functionality, only cleanups and
restructuring of code.
-Osma
--- common/phones/nk3110.c Fri Feb 14 22:31:39 2003
+++ common/phones/nk3110-drvinst.c Fri Feb 14 22:31:04 2003
@@ -49,6 +49,10 @@
#include "gnokii-internal.h"
#include "gsm-api.h"
+
+#define DRVINSTANCE(s) ((nk3110_driver_instance
*)((s)->driver.driver_instance))
+#define FREE(p) do { free(p); (p) = NULL; } while (0)
+
/* Prototypes */
static gn_error functions(gn_operation op, gn_data *data, struct
gn_statemachine *state);
static gn_error P3110_Initialise(struct gn_statemachine *state);
@@ -159,10 +163,14 @@
static gn_error functions(gn_operation op, gn_data *data, struct
gn_statemachine *state)
{
+ if (!DRVINSTANCE(state) && op != GN_OP_Init) return
GN_ERR_INTERNALERROR;
+
switch (op) {
case GN_OP_Init:
+ if (DRVINSTANCE(state)) return GN_ERR_INTERNALERROR;
return P3110_Initialise(state);
case GN_OP_Terminate:
+ FREE(DRVINSTANCE(state));
return pgen_terminate(data, state);
case GN_OP_GetModel:
case GN_OP_GetRevision:
@@ -200,9 +208,6 @@
}
}
-static bool SimAvailable = false;
-static int user_data_count = 0;
-
/* Initialise is the only function allowed to 'use' state */
static gn_error P3110_Initialise(struct gn_statemachine *state)
{
@@ -212,12 +217,21 @@
/* Copy in the phone info */
memcpy(&(state->driver), &driver_nokia_3110, sizeof(gn_driver));
+ if (!(DRVINSTANCE(state) = calloc(1, sizeof(nk3110_driver_instance))))
+ return GN_ERR_MEMORYFULL;
+ /* just to make things explicit: */
+ DRVINSTANCE(state)->sim_available = false;
+
/* Only serial connection is supported */
- if (state->config.connection_type != GN_CT_Serial) return
GN_ERR_NOTSUPPORTED;
+ if (state->config.connection_type != GN_CT_Serial) {
+ FREE(DRVINSTANCE(state));
+ return GN_ERR_NOTSUPPORTED;
+ }
/* Initialise FBUS link */
if (fb3110_initialise(state) != GN_ERR_NONE) {
dprintf("Error in link initialisation\n");
+ FREE(DRVINSTANCE(state));
return GN_ERR_NOTREADY;
}
@@ -229,11 +243,17 @@
simply send the same sequence observed between the W95 PC and
the phone. The init sequence may still be a bit flaky and is not
fully understood. */
- if (sm_message_send(20, 0x15, init_sequence, state) != GN_ERR_NONE)
return GN_ERR_NOTREADY;
+ if (sm_message_send(20, 0x15, init_sequence, state) != GN_ERR_NONE) {
+ FREE(DRVINSTANCE(state));
+ return GN_ERR_NOTREADY;
+ }
/* Wait for response to 0x15 sequence */
gn_data_clear(&data);
- if (sm_block(0x16, &data, state) != GN_ERR_NONE) return GN_ERR_NOTREADY;
+ if (sm_block(0x16, &data, state) != GN_ERR_NONE) {
+ FREE(DRVINSTANCE(state));
+ return GN_ERR_NOTREADY;
+ }
return GN_ERR_NONE;
}
@@ -267,7 +287,7 @@
/* Check if this type of memory is available */
switch (data->memory_status->memory_type) {
case GN_MT_SM:
- if (!SimAvailable) return GN_ERR_NOTREADY;
+ if (!(DRVINSTANCE(state)->sim_available)) return
GN_ERR_NOTREADY;
return P3110_GetSMSInfo(data, state);
case GN_MT_ME:
if (P3110_MEMORY_SIZE_ME == 0) return GN_ERR_NOTREADY;
@@ -351,7 +371,7 @@
do {
dprintf("Waiting for content frames...\n");
sm_block(0x27, data, state);
- } while (user_data_count < data->raw_sms->length);
+ } while (DRVINSTANCE(state)->user_data_count <
data->raw_sms->length);
return GN_ERR_NONE;
case 0x2d:
@@ -670,8 +690,8 @@
static gn_error P3110_IncomingInitFrame_0x16(int messagetype, unsigned char
*message, int length, gn_data *data, struct gn_statemachine *state)
{
- SimAvailable = (message[2] == 0x02);
- dprintf("SIM available: %s.\n", (SimAvailable ? "Yes" : "No"));
+ DRVINSTANCE(state)->sim_available = (message[2] == 0x02);
+ dprintf("SIM available: %s.\n", (DRVINSTANCE(state)->sim_available ?
"Yes" : "No"));
return GN_ERR_NONE;
}
@@ -697,17 +717,18 @@
if (length == 0x02) return GN_ERR_NONE;
/* This function may be called several times; it accumulates the
- * SMS content in data->raw_sms->user_data. The static global
- * user_data_count is used as a counter. */
+ * SMS content in data->raw_sms->user_data.
+ * DRVINSTANCE(state)->user_data_count is used as a counter. */
/* If this is the first block, reset accumulated message length. */
- if (message[2] == 1) user_data_count = 0;
+ if (message[2] == 1)
+ DRVINSTANCE(state)->user_data_count = 0;
- count = user_data_count + length - 3;
+ count = DRVINSTANCE(state)->user_data_count + length - 3;
- memcpy(data->raw_sms->user_data + user_data_count, message + 3, length
- 3);
+ memcpy(data->raw_sms->user_data + DRVINSTANCE(state)->user_data_count,
message + 3, length - 3);
- user_data_count += length - 3;
+ DRVINSTANCE(state)->user_data_count += length - 3;
return GN_ERR_NONE;
}
@@ -1033,7 +1054,7 @@
static gn_error P3110_IncomingPINEntered(int messagetype, unsigned char
*message, int length, gn_data *data, struct gn_statemachine *state)
{
- SimAvailable = true;
+ DRVINSTANCE(state)->sim_available = true;
dprintf("PIN [possibly] entered.\n");
return GN_ERR_NONE;
}
--- include/phones/nk3110.h Fri Feb 14 22:31:39 2003
+++ include/phones/nk3110-drvinst.h Fri Feb 14 22:30:53 2003
@@ -42,4 +42,9 @@
/* Number of times to try resending SMS (empirical) */
#define P3110_SMS_SEND_RETRY_COUNT 4
+typedef struct {
+ bool sim_available;
+ int user_data_count;
+} nk3110_driver_instance;
+
#endif /* #ifndef __phones_nk3110_h */
--
*** Osma Suominen *** address@hidden *** http://www.iki.fi/ozone/ ***
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- 3110 driver instance vars (patch),
Osma Suominen <=