diff options
author | tick <tick@99fdad57-331a-0410-800a-d7fa5415bdb3> | 2007-10-25 11:53:03 +0000 |
---|---|---|
committer | tick <tick@99fdad57-331a-0410-800a-d7fa5415bdb3> | 2007-10-25 11:53:03 +0000 |
commit | bd3f1498ccd05a9aac192f84bf3f40189ff3a0d6 (patch) | |
tree | 3eef8200b89bab0faa61b58857290d8cfd7c0919 /src | |
parent | b8b0521b4e9e021600411182f0b0b9a4e7f7c284 (diff) |
handle CME and CMS errors (Erin Yueh)
git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@3267 99fdad57-331a-0410-800a-d7fa5415bdb3
Diffstat (limited to 'src')
-rw-r--r-- | src/gsmd/atcmd.c | 5 | ||||
-rw-r--r-- | src/gsmd/unsolicited.c | 174 | ||||
-rw-r--r-- | src/util/event.c | 12 |
3 files changed, 114 insertions, 77 deletions
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; } |