Save the current and pending modes in radio_settings_data, so we can
access them later. This patch also splits the parsing of ^SYSCFG
response from the callback call. Then, it's possible to have more
properties that use the same command as is the case of frequency band
selection.
---
 drivers/huaweimodem/radio-settings.c |   68 ++++++++++++++++++++++------------
 1 files changed, 44 insertions(+), 24 deletions(-)

diff --git a/drivers/huaweimodem/radio-settings.c 
b/drivers/huaweimodem/radio-settings.c
index 30961da..38c0f3d 100644
--- a/drivers/huaweimodem/radio-settings.c
+++ b/drivers/huaweimodem/radio-settings.c
@@ -45,53 +45,64 @@ static const char *syscfg_prefix[] = { "^SYSCFG:", NULL };
 
 struct radio_settings_data {
        GAtChat *chat;
+       enum ofono_radio_access_mode mode;
+       struct {
+               enum ofono_radio_access_mode mode;
+       } pending;
 };
 
-static void syscfg_query_cb(gboolean ok, GAtResult *result, gpointer user_data)
+static ofono_bool_t syscfg_query_parse(struct radio_settings_data *rsd,
+                                       GAtResult *result)
 {
-       struct cb_data *cbd = user_data;
-       ofono_radio_settings_rat_mode_query_cb_t cb = cbd->cb;
-       enum ofono_radio_access_mode mode;
-       struct ofono_error error;
        GAtResultIter iter;
        int value;
 
-       decode_at_error(&error, g_at_result_final_response(result));
-
-       if (!ok) {
-               cb(&error, -1, cbd->data);
-               return;
-       }
-
        g_at_result_iter_init(&iter, result);
 
        if (g_at_result_iter_next(&iter, "^SYSCFG:") == FALSE)
-               goto error;
+               return FALSE;
 
        if (g_at_result_iter_next_number(&iter, &value) == FALSE)
-               goto error;
+               return FALSE;
 
        switch (value) {
        case 2:
-               mode = OFONO_RADIO_ACCESS_MODE_ANY;
+               rsd->mode = OFONO_RADIO_ACCESS_MODE_ANY;
                break;
        case 13:
-               mode = OFONO_RADIO_ACCESS_MODE_GSM;
+               rsd->mode = OFONO_RADIO_ACCESS_MODE_GSM;
                break;
        case 14:
-               mode = OFONO_RADIO_ACCESS_MODE_UMTS;
+               rsd->mode = OFONO_RADIO_ACCESS_MODE_UMTS;
                break;
        default:
-               CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
-               return;
+               return FALSE;
        }
 
-       cb(&error, mode, cbd->data);
+       return TRUE;
+}
+
+static void huawei_query_rat_mode_cb(gboolean ok, GAtResult *result,
+                                       gpointer user_data)
+{
+       struct cb_data *cbd = user_data;
+       ofono_radio_settings_rat_mode_query_cb_t cb = cbd->cb;
+       struct radio_settings_data *rsd = cbd->user;
+       struct ofono_error error;
 
-       return;
+       decode_at_error(&error, g_at_result_final_response(result));
 
-error:
-       CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+       if (!ok) {
+               cb(&error, -1, cbd->data);
+               return;
+       }
+
+       if (!syscfg_query_parse(rsd, result)) {
+               CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+               return;
+       }
+
+       cb(&error, rsd->mode, cbd->data);
 }
 
 static void huawei_query_rat_mode(struct ofono_radio_settings *rs,
@@ -100,8 +111,10 @@ static void huawei_query_rat_mode(struct 
ofono_radio_settings *rs,
        struct radio_settings_data *rsd = ofono_radio_settings_get_data(rs);
        struct cb_data *cbd = cb_data_new(cb, data);
 
+       cbd->user = rsd;
+
        if (g_at_chat_send(rsd->chat, "AT^SYSCFG?", syscfg_prefix,
-                                       syscfg_query_cb, cbd, g_free) == 0) {
+                               huawei_query_rat_mode_cb, cbd, g_free) == 0) {
                CALLBACK_WITH_FAILURE(cb, -1, data);
                g_free(cbd);
        }
@@ -111,8 +124,12 @@ static void syscfg_modify_cb(gboolean ok, GAtResult 
*result, gpointer user_data)
 {
        struct cb_data *cbd = user_data;
        ofono_radio_settings_rat_mode_set_cb_t cb = cbd->cb;
+       struct radio_settings_data *rsd = cbd->user;
        struct ofono_error error;
 
+       if (ok)
+               rsd->mode = rsd->pending.mode;
+
        decode_at_error(&error, g_at_result_final_response(result));
        cb(&error, cbd->data);
 }
@@ -147,6 +164,9 @@ static void huawei_set_rat_mode(struct ofono_radio_settings 
*rs,
        snprintf(buf, sizeof(buf), "AT^SYSCFG=%u,%u,3FFFFFFF,2,4",
                        value, acq_order);
 
+       rsd->pending.mode = mode;
+       cbd->user = rsd;
+
        if (g_at_chat_send(rsd->chat, buf, none_prefix,
                                        syscfg_modify_cb, cbd, g_free) > 0)
                return;
-- 
1.7.3.3

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to