From 2d4b954be95ad5bef23f9a0068c9c97a8f4037c4 Mon Sep 17 00:00:00 2001 From: tick Date: Mon, 12 Nov 2007 09:38:04 +0000 Subject: keeping track of current registration state internally in gsmd. Without this the"gsmd->dev_state.registered" variable had bogus values. (Andrew) git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@3390 99fdad57-331a-0410-800a-d7fa5415bdb3 --- src/gsmd/atcmd.c | 2 +- src/gsmd/unsolicited.c | 33 +++++++++++++++++++++++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) (limited to 'src/gsmd') diff --git a/src/gsmd/atcmd.c b/src/gsmd/atcmd.c index 3592918..1f2e04e 100644 --- a/src/gsmd/atcmd.c +++ b/src/gsmd/atcmd.c @@ -668,7 +668,7 @@ int cancel_atcmd(struct gsmd *g, struct gsmd_atcmd *cmd) } llist_add(&cmd->list, &g->pending_atcmds); - return atcmd_done(g, cur, "OK"); + return atcmd_done(g, cur, "ERROR"); } void atcmd_drain(int fd) diff --git a/src/gsmd/unsolicited.c b/src/gsmd/unsolicited.c index e9f3568..4819571 100644 --- a/src/gsmd/unsolicited.c +++ b/src/gsmd/unsolicited.c @@ -145,9 +145,31 @@ static int creg_parse(char *buf, int len, const char *param, struct gsmd *gsmd) { const char *comma = strchr(param, ','); - struct gsmd_ucmd *ucmd = usock_build_event(GSMD_MSG_EVENT, GSMD_EVT_NETREG, - sizeof(struct gsmd_evt_auxdata)); + struct gsmd_ucmd *ucmd; struct gsmd_evt_auxdata *aux; + int prev_registered = gsmd->dev_state.registered; + int state; + char *end; + + state = strtol(param, &end, 10); + if (!(end > param)) { + gsmd_log(GSMD_ERROR, "Bad +CREG format, not updating state\n"); + return -EINVAL; + } + + /* Update our knowledge about our state */ + gsmd->dev_state.registered = + (state == GSMD_NETREG_REG_HOME || + state == GSMD_NETREG_REG_ROAMING); + + /* Intialise things that depend on network registration */ + if (gsmd->dev_state.registered && !prev_registered) { + sms_cb_network_init(gsmd); + } + + /* Notify clients */ + ucmd = usock_build_event(GSMD_MSG_EVENT, GSMD_EVT_NETREG, + sizeof(struct gsmd_evt_auxdata)); if (!ucmd) return -ENOMEM; aux = (struct gsmd_evt_auxdata *) ucmd->buf; @@ -163,13 +185,8 @@ static int creg_parse(char *buf, int len, const char *param, } else aux->u.netreg.lac = aux->u.netreg.ci = 0; - /* Intialise things that depend on network registration */ - if (aux->u.netreg.state == GSMD_NETREG_REG_HOME || - aux->u.netreg.state == GSMD_NETREG_REG_ROAMING) { - sms_cb_network_init(gsmd); - } - return usock_evt_send(gsmd, ucmd, GSMD_EVT_NETREG); + } /* Chapter 7.11, call waiting */ -- cgit v1.2.3