From 3b95fe1d10aa72c9619116d6a2c17d6874de6cb1 Mon Sep 17 00:00:00 2001 From: Pekka Pessi Date: Tue, 24 Aug 2010 13:46:08 +0200 Subject: [PATCH] gisi: Retry version query in g_isi_verify() For some mysterious reason, not all COMMON_MESSAGEs get sent to modem. This patch adds a retry counter that tries to make sure an answer is always received. --- gisi/verify.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/gisi/verify.c b/gisi/verify.c index 7ba0cdc5..fae9d131 100644 --- a/gisi/verify.c +++ b/gisi/verify.c @@ -31,6 +31,7 @@ #include "client.h" #define VERSION_TIMEOUT 5 +#define VERSION_RETRIES 2 #define COMMON_MESSAGE 0xF0 #define COMM_ISI_VERSION_GET_REQ 0x12 @@ -40,8 +41,22 @@ struct verify_data { GIsiVerifyFunc func; void *data; + guint count; }; +static GIsiRequest *send_version_query(GIsiClient *client, GIsiResponseFunc cb, + void *opaque) +{ + uint8_t msg[] = { + COMMON_MESSAGE, + COMM_ISI_VERSION_GET_REQ, + 0x00 /* Filler */ + }; + + return g_isi_request_make(client, msg, sizeof(msg), VERSION_TIMEOUT, + cb, opaque); +} + static gboolean verify_cb(GIsiClient *client, const void *restrict data, size_t len, uint16_t object, void *opaque) { @@ -51,8 +66,20 @@ static gboolean verify_cb(GIsiClient *client, const void *restrict data, gboolean alive = FALSE; - if (!msg) + if (!msg) { + + if (++vd->count < VERSION_RETRIES) { + + g_warning("Retry COMM_ISI_VERSION_GET_REQ"); + + if (send_version_query(client, verify_cb, opaque)) + return TRUE; + } + + g_warning("Timeout COMM_ISI_VERSION_GET_REQ"); + goto out; + } if (len < 2 || msg[0] != COMMON_MESSAGE) goto out; @@ -69,6 +96,7 @@ static gboolean verify_cb(GIsiClient *client, const void *restrict data, out: if (func) func(client, alive, object, vd->data); + g_free(vd); return TRUE; } @@ -87,17 +115,11 @@ GIsiRequest *g_isi_verify(GIsiClient *client, GIsiVerifyFunc func, { struct verify_data *data = g_try_new0(struct verify_data, 1); GIsiRequest *req = NULL; - uint8_t msg[] = { - COMMON_MESSAGE, - COMM_ISI_VERSION_GET_REQ, - 0x00 /* Filler */ - }; data->func = func; data->data = opaque; - req = g_isi_request_make(client, msg, sizeof(msg), VERSION_TIMEOUT, - verify_cb, data); + req = send_version_query(client, verify_cb, data); if (!req) g_free(data);