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 --- include/gsmd/event.h | 1 + include/gsmd/usock.h | 11 +++- src/gsmd/atcmd.c | 5 ++ src/gsmd/unsolicited.c | 174 ++++++++++++++++++++++++++++--------------------- src/util/event.c | 12 +++- 5 files changed, 124 insertions(+), 79 deletions(-) diff --git a/include/gsmd/event.h b/include/gsmd/event.h index 829b0fa..c8221b3 100644 --- a/include/gsmd/event.h +++ b/include/gsmd/event.h @@ -18,6 +18,7 @@ enum gsmd_events { GSMD_EVT_CIPHER = 13, /* Chiphering Information */ GSMD_EVT_IN_CBM = 14, /* Incoming Cell Broadcat message */ GSMD_EVT_IN_DS = 15, /* SMS Status Report */ + GSMD_EVT_IN_ERROR = 16, /* CME/CMS error */ __NUM_GSMD_EVT }; diff --git a/include/gsmd/usock.h b/include/gsmd/usock.h index f37cfa8..b9ecfc6 100644 --- a/include/gsmd/usock.h +++ b/include/gsmd/usock.h @@ -2,7 +2,8 @@ #define _GSMD_USOCK_H #include - +#include +#include #define GSMD_UNIX_SOCKET "\0gsmd" //#define GSMD_UNIX_SOCKET_TYPE SOCK_SEQPACKET #define GSMD_UNIX_SOCKET_TYPE SOCK_STREAM @@ -361,8 +362,14 @@ struct gsmd_evt_auxdata { u_int16_t net_state_gsm; u_int16_t net_state_gprs; } cipher; + struct { + enum gsm0707_cme_error number; + } cme_err; + struct { + enum gsm0705_cms_error number; + } cms_err; } u; - u_int8_t data[0]; + u_int8_t data[0]; } __attribute__ ((packed)); /* Refer to GSM 07.05 subclause 3.5.4 */ 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); } + diff --git a/src/util/event.c b/src/util/event.c index f14f906..acbd24a 100644 --- a/src/util/event.c +++ b/src/util/event.c @@ -233,6 +233,16 @@ static int cprog_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdat return 0; } +static int error_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux) +{ + if(aux->u.cme_err.number) + printf("cme error: %u\n", aux->u.cme_err.number); + else if(aux->u.cms_err.number) + printf("cme error: %u\n", aux->u.cms_err.number); + + return 0; +} + int event_init(struct lgsm_handle *lh) { int rc; @@ -246,7 +256,7 @@ int event_init(struct lgsm_handle *lh) rc |= lgsm_evt_handler_register(lh, GSMD_EVT_NETREG, &netreg_handler); rc |= lgsm_evt_handler_register(lh, GSMD_EVT_SIGNAL, &sigq_handler); rc |= lgsm_evt_handler_register(lh, GSMD_EVT_OUT_STATUS, &cprog_handler); - + rc |= lgsm_evt_handler_register(lh, GSMD_EVT_IN_ERROR, &error_handler); return rc; } -- cgit v1.2.3