From 2b9b1ae6d3a0d75a3c59bfb6cb295f3d9edaa84d Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Thu, 1 Nov 2012 10:05:03 +0100 Subject: [PATCH] sim: Fix the quirk handling of CPIN for Wavecom The Wavecom Q2XXX support broke in commit 72ce19bf3e87b5e73c053f7ea1. This is because at_cpin_cb called decode_at_error with final and not with OK. This lead to an error being set in the error variable and the new code returns early when an error is set. The addition of the terminator in at_sim_probe for Wavecom broke in git commit ac524be99f8c72a2593e4ffcecad8beea7679e55 because terminators can not be added on cloned chats. Move the addition of the terminator from the atmodem to the wavecom plugin. Use the same terminator for Q2XXX and the normal Wavecom class. The WAVECOM terminator has been tested on a Q2XXX modem. Apply the CPIN quirk for both WAVECOM and WAVECOM_Q2XXX inside the sim.c file. Introduce needs_wavecom_sim_quirk to handle it for WAVECOM and WAVECOM_Q2XXX. --- drivers/atmodem/sim.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c index cf3345cf..ea3b1808 100644 --- a/drivers/atmodem/sim.c +++ b/drivers/atmodem/sim.c @@ -967,6 +967,12 @@ static void at_pin_retries_query(struct ofono_sim *sim, CALLBACK_WITH_FAILURE(cb, NULL, data); } +static int needs_wavecom_sim_quirk(int vendor) +{ + return vendor == OFONO_VENDOR_WAVECOM || + vendor == OFONO_VENDOR_WAVECOM_Q2XXX; +} + static void at_cpin_cb(gboolean ok, GAtResult *result, gpointer user_data) { struct cb_data *cbd = user_data; @@ -980,7 +986,7 @@ static void at_cpin_cb(gboolean ok, GAtResult *result, gpointer user_data) int len = sizeof(at_sim_name) / sizeof(*at_sim_name); const char *final = g_at_result_final_response(result); - if (sd->vendor == OFONO_VENDOR_WAVECOM && ok && strlen(final) > 7) + if (needs_wavecom_sim_quirk(sd->vendor) && ok && strlen(final) > 7) decode_at_error(&error, "OK"); else decode_at_error(&error, final); @@ -990,8 +996,7 @@ static void at_cpin_cb(gboolean ok, GAtResult *result, gpointer user_data) return; } - if (sd->vendor == OFONO_VENDOR_WAVECOM || - sd->vendor == OFONO_VENDOR_WAVECOM_Q2XXX) { + if (needs_wavecom_sim_quirk(sd->vendor)) { /* +CPIN: */ pin_required = final + 7; } else { @@ -1402,19 +1407,8 @@ static int at_sim_probe(struct ofono_sim *sim, unsigned int vendor, sd->chat = g_at_chat_clone(chat); sd->vendor = vendor; - switch (sd->vendor) { - case OFONO_VENDOR_WAVECOM: - g_at_chat_add_terminator(sd->chat, "+CPIN:", 6, TRUE); - break; - case OFONO_VENDOR_MBM: + if (sd->vendor == OFONO_VENDOR_MBM) g_at_chat_send(sd->chat, "AT*EPEE=1", NULL, NULL, NULL, NULL); - break; - case OFONO_VENDOR_WAVECOM_Q2XXX: - g_at_chat_add_terminator(chat, "+CPIN: READY", -1, TRUE); - break; - default: - break; - } ofono_sim_set_data(sim, sd); g_idle_add(at_sim_register, sim);