From bd3f1498ccd05a9aac192f84bf3f40189ff3a0d6 Mon Sep 17 00:00:00 2001 From: tick Date: Thu, 25 Oct 2007 11:53:03 +0000 Subject: handle CME and CMS errors (Erin Yueh) git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@3267 99fdad57-331a-0410-800a-d7fa5415bdb3 --- src/gsmd/atcmd.c | 5 ++ src/gsmd/unsolicited.c | 174 ++++++++++++++++++++++++++++--------------------- 2 files changed, 103 insertions(+), 76 deletions(-) (limited to 'src/gsmd') diff --git a/src/gsmd/atcmd.c b/src/gsmd/atcmd.c index 2ef6a10..69e1d12 100644 --- a/src/gsmd/atcmd.c +++ b/src/gsmd/atcmd.c @@ -206,6 +206,7 @@ static int ml_parse(const char *buf, int len, void *ctx) struct gsmd_atcmd *cmd = NULL; int rc = 0; int cme_error = 0; + int cms_error = 0; DEBUGP("buf=`%s'(%d)\n", buf, len); @@ -269,6 +270,7 @@ static int ml_parse(const char *buf, int len, void *ctx) DEBUGP("error number %lu\n", err_nr); if (cmd) cmd->ret = err_nr; + cms_error = 1; goto final_cb; } @@ -399,6 +401,9 @@ final_cb: if (cmd && cme_error) generate_event_from_cme(g, cmd->ret); + + if (cmd && cms_error) + generate_event_from_cms(g, cmd->ret); if (!cmd->cb) { gsmd_log(GSMD_NOTICE, "command without cb!!!\n"); diff --git a/src/gsmd/unsolicited.c b/src/gsmd/unsolicited.c index 0cef5ca..e9f3568 100644 --- a/src/gsmd/unsolicited.c +++ b/src/gsmd/unsolicited.c @@ -441,13 +441,13 @@ static unsigned int errors_creating_events[] = { GSM0707_CME_SIM_NOT_INSERTED, GSM0707_CME_SIM_PIN_REQUIRED, GSM0707_CME_SIM_PUK_REQUIRED, - GSM0707_CME_SIM_FAILURE, +/* GSM0707_CME_SIM_FAILURE, GSM0707_CME_SIM_BUSY, - GSM0707_CME_SIM_WRONG, + GSM0707_CME_SIM_WRONG,*/ GSM0707_CME_SIM_PIN2_REQUIRED, GSM0707_CME_SIM_PUK2_REQUIRED, - GSM0707_CME_MEMORY_FULL, - GSM0707_CME_MEMORY_FAILURE, +/* GSM0707_CME_MEMORY_FULL, + GSM0707_CME_MEMORY_FAILURE,*/ GSM0707_CME_NETPERS_PIN_REQUIRED, GSM0707_CME_NETPERS_PUK_REQUIRED, GSM0707_CME_NETSUBSET_PIN_REQUIRED, @@ -470,84 +470,106 @@ static int is_in_array(unsigned int val, unsigned int *arr, unsigned int arr_len return 0; } - int generate_event_from_cme(struct gsmd *g, unsigned int cme_error) { struct gsmd_ucmd *gu; struct gsmd_evt_auxdata *eaux; - if (!is_in_array(cme_error, errors_creating_events, - ARRAY_SIZE(errors_creating_events))) - return 0; + + if (!is_in_array(cme_error, errors_creating_events, + ARRAY_SIZE(errors_creating_events))) { + + gu = usock_build_event(GSMD_MSG_EVENT, GSMD_EVT_IN_ERROR, sizeof(*eaux)); + if (!gu) + return -1; + eaux = ((void *)gu) + sizeof(*gu); + eaux->u.cme_err.number = cme_error; + return usock_evt_send(g, gu, GSMD_EVT_IN_ERROR); + } + else { + gu = usock_build_event(GSMD_MSG_EVENT, GSMD_EVT_PIN, sizeof(*eaux)); + if (!gu) + return -1; + eaux = ((void *)gu) + sizeof(*gu); - gu = usock_build_event(GSMD_MSG_EVENT, GSMD_EVT_PIN, sizeof(*eaux)); + switch (cme_error) { + case GSM0707_CME_PH_SIM_PIN_REQUIRED: + eaux->u.pin.type = GSMD_PIN_PH_SIM_PIN; + break; + case GSM0707_CME_PH_FSIM_PIN_REQUIRED: + eaux->u.pin.type = GSMD_PIN_PH_FSIM_PIN; + break; + case GSM0707_CME_PH_FSIM_PUK_REQUIRED: + eaux->u.pin.type = GSMD_PIN_PH_FSIM_PUK; + break; + case GSM0707_CME_SIM_PIN_REQUIRED: + eaux->u.pin.type = GSMD_PIN_SIM_PIN; + break; + case GSM0707_CME_SIM_PUK_REQUIRED: + eaux->u.pin.type = GSMD_PIN_SIM_PUK; + break; + case GSM0707_CME_SIM_PIN2_REQUIRED: + eaux->u.pin.type = GSMD_PIN_SIM_PIN2; + break; + case GSM0707_CME_SIM_PUK2_REQUIRED: + eaux->u.pin.type = GSMD_PIN_SIM_PUK2; + break; + case GSM0707_CME_NETPERS_PIN_REQUIRED: + eaux->u.pin.type = GSMD_PIN_PH_NET_PIN; + break; + case GSM0707_CME_NETPERS_PUK_REQUIRED: + eaux->u.pin.type = GSMD_PIN_PH_NET_PUK; + break; + case GSM0707_CME_NETSUBSET_PIN_REQUIRED: + eaux->u.pin.type = GSMD_PIN_PH_NETSUB_PIN; + break; + case GSM0707_CME_NETSUBSET_PUK_REQUIRED: + eaux->u.pin.type = GSMD_PIN_PH_NETSUB_PUK; + break; + case GSM0707_CME_PROVIDER_PIN_REQUIRED: + eaux->u.pin.type = GSMD_PIN_PH_SP_PIN; + break; + case GSM0707_CME_PROVIDER_PUK_REQUIRED: + eaux->u.pin.type = GSMD_PIN_PH_SP_PUK; + break; + case GSM0707_CME_CORPORATE_PIN_REQUIRED: + eaux->u.pin.type = GSMD_PIN_PH_CORP_PIN; + break; + case GSM0707_CME_CORPORATE_PUK_REQUIRED: + eaux->u.pin.type = GSMD_PIN_PH_CORP_PUK; + break; + + case GSM0707_CME_SIM_FAILURE: + case GSM0707_CME_SIM_BUSY: + case GSM0707_CME_SIM_WRONG: + case GSM0707_CME_MEMORY_FULL: + case GSM0707_CME_MEMORY_FAILURE: + case GSM0707_CME_PHONE_FAILURE: + case GSM0707_CME_PHONE_NOCONNECT: + case GSM0707_CME_PHONE_ADAPT_RESERVED: + case GSM0707_CME_SIM_NOT_INSERTED: + /* FIXME */ + talloc_free(gu); + return 0; + break; + default: + talloc_free(gu); + return 0; + break; + } + return usock_evt_send(g, gu, GSMD_EVT_PIN); + } +} + +int generate_event_from_cms(struct gsmd *g, unsigned int cms_error) +{ + struct gsmd_ucmd *gu; + struct gsmd_evt_auxdata *eaux; + + gu = usock_build_event(GSMD_MSG_EVENT, GSMD_EVT_IN_ERROR, sizeof(*eaux)); if (!gu) return -1; eaux = ((void *)gu) + sizeof(*gu); - - switch (cme_error) { - case GSM0707_CME_PH_SIM_PIN_REQUIRED: - eaux->u.pin.type = GSMD_PIN_PH_SIM_PIN; - break; - case GSM0707_CME_PH_FSIM_PIN_REQUIRED: - eaux->u.pin.type = GSMD_PIN_PH_FSIM_PIN; - break; - case GSM0707_CME_PH_FSIM_PUK_REQUIRED: - eaux->u.pin.type = GSMD_PIN_PH_FSIM_PUK; - break; - case GSM0707_CME_SIM_PIN_REQUIRED: - eaux->u.pin.type = GSMD_PIN_SIM_PIN; - break; - case GSM0707_CME_SIM_PUK_REQUIRED: - eaux->u.pin.type = GSMD_PIN_SIM_PUK; - break; - case GSM0707_CME_SIM_PIN2_REQUIRED: - eaux->u.pin.type = GSMD_PIN_SIM_PIN2; - break; - case GSM0707_CME_SIM_PUK2_REQUIRED: - eaux->u.pin.type = GSMD_PIN_SIM_PUK2; - break; - case GSM0707_CME_NETPERS_PIN_REQUIRED: - eaux->u.pin.type = GSMD_PIN_PH_NET_PIN; - break; - case GSM0707_CME_NETPERS_PUK_REQUIRED: - eaux->u.pin.type = GSMD_PIN_PH_NET_PUK; - break; - case GSM0707_CME_NETSUBSET_PIN_REQUIRED: - eaux->u.pin.type = GSMD_PIN_PH_NETSUB_PIN; - break; - case GSM0707_CME_NETSUBSET_PUK_REQUIRED: - eaux->u.pin.type = GSMD_PIN_PH_NETSUB_PUK; - break; - case GSM0707_CME_PROVIDER_PIN_REQUIRED: - eaux->u.pin.type = GSMD_PIN_PH_SP_PIN; - break; - case GSM0707_CME_PROVIDER_PUK_REQUIRED: - eaux->u.pin.type = GSMD_PIN_PH_SP_PUK; - break; - case GSM0707_CME_CORPORATE_PIN_REQUIRED: - eaux->u.pin.type = GSMD_PIN_PH_CORP_PIN; - break; - case GSM0707_CME_CORPORATE_PUK_REQUIRED: - eaux->u.pin.type = GSMD_PIN_PH_CORP_PUK; - break; - - case GSM0707_CME_SIM_FAILURE: - case GSM0707_CME_SIM_BUSY: - case GSM0707_CME_SIM_WRONG: - case GSM0707_CME_MEMORY_FULL: - case GSM0707_CME_MEMORY_FAILURE: - case GSM0707_CME_PHONE_FAILURE: - case GSM0707_CME_PHONE_NOCONNECT: - case GSM0707_CME_PHONE_ADAPT_RESERVED: - case GSM0707_CME_SIM_NOT_INSERTED: - /* FIXME */ - talloc_free(gu); - return 0; - break; - default: - talloc_free(gu); - return 0; - break; - } - return usock_evt_send(g, gu, GSMD_EVT_PIN); + eaux->u.cms_err.number = cms_error; + return usock_evt_send(g, gu, GSMD_EVT_IN_ERROR); } + -- cgit v1.2.3