summaryrefslogtreecommitdiff
path: root/src/gsmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/gsmd')
-rw-r--r--src/gsmd/unsolicited.c108
-rw-r--r--src/gsmd/usock.c27
2 files changed, 51 insertions, 84 deletions
diff --git a/src/gsmd/unsolicited.c b/src/gsmd/unsolicited.c
index 4819571..b4bf260 100644
--- a/src/gsmd/unsolicited.c
+++ b/src/gsmd/unsolicited.c
@@ -487,12 +487,40 @@ static int is_in_array(unsigned int val, unsigned int *arr, unsigned int arr_len
return 0;
}
+const int pintype_from_cme[GSM0707_CME_UNKNOWN] = {
+ [GSM0707_CME_PH_SIM_PIN_REQUIRED] = GSMD_PIN_PH_SIM_PIN,
+ [GSM0707_CME_PH_FSIM_PIN_REQUIRED] = GSMD_PIN_PH_FSIM_PIN,
+ [GSM0707_CME_PH_FSIM_PUK_REQUIRED] = GSMD_PIN_PH_FSIM_PUK,
+ [GSM0707_CME_SIM_PIN_REQUIRED] = GSMD_PIN_SIM_PIN,
+ [GSM0707_CME_SIM_PUK_REQUIRED] = GSMD_PIN_SIM_PUK,
+ [GSM0707_CME_SIM_PIN2_REQUIRED] = GSMD_PIN_SIM_PIN2,
+ [GSM0707_CME_SIM_PUK2_REQUIRED] = GSMD_PIN_SIM_PUK2,
+ [GSM0707_CME_NETPERS_PIN_REQUIRED] = GSMD_PIN_PH_NET_PIN,
+ [GSM0707_CME_NETPERS_PUK_REQUIRED] = GSMD_PIN_PH_NET_PUK,
+ [GSM0707_CME_NETSUBSET_PIN_REQUIRED] = GSMD_PIN_PH_NETSUB_PIN,
+ [GSM0707_CME_NETSUBSET_PUK_REQUIRED] = GSMD_PIN_PH_NETSUB_PUK,
+ [GSM0707_CME_PROVIDER_PIN_REQUIRED] = GSMD_PIN_PH_SP_PIN,
+ [GSM0707_CME_PROVIDER_PUK_REQUIRED] = GSMD_PIN_PH_SP_PUK,
+ [GSM0707_CME_CORPORATE_PIN_REQUIRED] = GSMD_PIN_PH_CORP_PIN,
+ [GSM0707_CME_CORPORATE_PUK_REQUIRED] = GSMD_PIN_PH_CORP_PUK,
+ /* FIXME: */
+ [GSM0707_CME_SIM_FAILURE] = 0,
+ [GSM0707_CME_SIM_BUSY] = 0,
+ [GSM0707_CME_SIM_WRONG] = 0,
+ [GSM0707_CME_MEMORY_FULL] = 0,
+ [GSM0707_CME_MEMORY_FAILURE] = 0,
+ [GSM0707_CME_PHONE_FAILURE] = 0,
+ [GSM0707_CME_PHONE_NOCONNECT] = 0,
+ [GSM0707_CME_PHONE_ADAPT_RESERVED] = 0,
+ [GSM0707_CME_SIM_NOT_INSERTED] = 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,
+ 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));
@@ -501,78 +529,18 @@ int generate_event_from_cme(struct gsmd *g, unsigned int cme_error)
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));
+ } else {
+ if (cme_error >= GSM0707_CME_UNKNOWN ||
+ !pintype_from_cme[cme_error])
+ return 0;
+
+ gu = usock_build_event(GSMD_MSG_EVENT, GSMD_EVT_PIN,
+ 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;
- }
+ eaux->u.pin.type = pintype_from_cme[cme_error];
return usock_evt_send(g, gu, GSMD_EVT_PIN);
}
}
diff --git a/src/gsmd/usock.c b/src/gsmd/usock.c
index cf3aea9..73bb3c3 100644
--- a/src/gsmd/usock.c
+++ b/src/gsmd/usock.c
@@ -185,19 +185,18 @@ static int null_cmd_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp)
/* PIN command callback. Gets called for response to AT+CPIN cmcd */
static int pin_cmd_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp)
{
- gsmd_log(GSMD_DEBUG, "pin cmd cb\n");
+ struct gsmd_user *gu = ctx;
+ struct gsmd_ucmd *ucmd = gsmd_ucmd_fill(sizeof(int), GSMD_MSG_PIN,
+ GSMD_PIN_INPUT, 0);
- /* We need to verify if there is some error */
- switch (cmd->ret) {
- case 0:
- break;
- case GSM0707_CME_INCORRECT_PASSWORD:
- /* prompt for pin again */
- break;
- default:
- /* something went wrong */
- break;
- }
+ if (!ucmd)
+ return -ENOMEM;
+
+ /* Pass a GSM07.07 CME code directly, don't issue a new PIN
+ * request because the client waits for a response to her
+ * PIN submission rather than an event. */
+ ((int *) ucmd->buf)[0] = cmd->ret;
+ usock_cmd_enqueue(ucmd, gu);
return 0;
}
@@ -409,7 +408,7 @@ struct gsmd_ucmd *gsmd_ucmd_fill(int len, u_int8_t msg_type,
ucmd = ucmd_alloc(len);
if (!ucmd)
return NULL;
-
+
ucmd->hdr.version = GSMD_PROTO_VERSION;
ucmd->hdr.msg_type = msg_type;
ucmd->hdr.msg_subtype = msg_subtype;
@@ -651,7 +650,7 @@ static int network_ownnumbers_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp)
num->service = GSMD_SERVICE_UNKNOWN;
num->name[len] = 0;
num->addr.type = type;
- num->is_last = (cmd->ret == 0, NULL);
+ num->is_last = (cmd->ret == 0);
usock_cmd_enqueue(ucmd, gu);
personal git repositories of Harald Welte. Your mileage may vary