--- drivers/isimodem/gprs.c | 131 ++++++++-------------------------------------- 1 files changed, 23 insertions(+), 108 deletions(-)
diff --git a/drivers/isimodem/gprs.c b/drivers/isimodem/gprs.c index ea90704..ad5a768 100644 --- a/drivers/isimodem/gprs.c +++ b/drivers/isimodem/gprs.c @@ -62,6 +62,8 @@ struct gprs_data { static void configure_resp_cb(const GIsiMessage *msg, void *opaque) { + struct isi_cb_data *cbd = opaque; + ofono_gprs_cb_t cb = cbd->cb; const uint8_t *data = g_isi_msg_data(msg); if (g_isi_msg_error(msg) < 0) { @@ -75,26 +77,13 @@ static void configure_resp_cb(const GIsiMessage *msg, void *opaque) if (g_isi_msg_data_len(msg) < 1) return; - if (data[0] != GPDS_OK) + if (data[0] != GPDS_OK) { DBG("GPDS configure failed: %s", gpds_status_name(data[0])); -} - -static void set_attach_mode(struct ofono_gprs *gprs, int attached) -{ - struct gprs_data *gd = ofono_gprs_get_data(gprs); - - const unsigned char msg[] = { - GPDS_CONFIGURE_REQ, - attached ? GPDS_ATTACH_MODE_AUTOMATIC : GPDS_ATTACH_MODE_MANUAL, - GPDS_MT_ACT_MODE_REJECT, - GPDS_CLASSC_MODE_DEFAULT, - GPDS_AOL_CTX_DEFAULT, - 0x00, - 0x00 - }; + CALLBACK_WITH_FAILURE(cb, cbd->data); + return; + } - g_isi_client_send(gd->client, msg, sizeof(msg), - configure_resp_cb, gprs, NULL); + CALLBACK_WITH_SUCCESS(cb, cbd->data); } static void detach_ind_cb(const GIsiMessage *msg, void *opaque) @@ -114,8 +103,6 @@ static void detach_ind_cb(const GIsiMessage *msg, void *opaque) DBG("detached: %s (0x%02"PRIx8")", gpds_isi_cause_name(data[0]), data[0]); - set_attach_mode(gprs, FALSE); - ofono_gprs_detached_notify(gprs); } @@ -324,101 +311,29 @@ static void isi_gprs_remove(struct ofono_gprs *gprs) g_free(gd); } -static void attach_resp_cb(const GIsiMessage *msg, void *opaque) -{ - struct isi_cb_data *cbd = opaque; - ofono_gprs_cb_t cb = cbd->cb; - const uint8_t *data = g_isi_msg_data(msg); - - if (g_isi_msg_error(msg) < 0) { - DBG("ISI message error: %d", g_isi_msg_error(msg)); - goto error; - } - - if (g_isi_msg_id(msg) != GPDS_ATTACH_RESP) - return; - - if (g_isi_msg_data_len(msg) < 2) - goto error; - - if (data[0] != GPDS_OK) { - DBG("attach failed: %s", gpds_status_name(data[0])); - goto error; - } - - set_attach_mode(cbd->user, TRUE); - - CALLBACK_WITH_SUCCESS(cb, cbd->data); - return; - -error: - CALLBACK_WITH_FAILURE(cb, cbd->data); -} - -static void detach_resp_cb(const GIsiMessage *msg, void *opaque) -{ - struct isi_cb_data *cbd = opaque; - ofono_gprs_cb_t cb = cbd->cb; - const uint8_t *data = g_isi_msg_data(msg); - - if (g_isi_msg_error(msg) < 0) { - DBG("ISI client error: %d", g_isi_msg_error(msg)); - goto error; - } - - if (g_isi_msg_id(msg) != GPDS_DETACH_RESP) - return; - - if (g_isi_msg_data_len(msg) < 2) - goto error; - - if (data[0] != GPDS_OK) { - DBG("detach failed: %s", gpds_status_name(data[0])); - goto error; - } - - set_attach_mode(cbd->user, FALSE); - - CALLBACK_WITH_SUCCESS(cb, cbd->data); - return; - -error: - CALLBACK_WITH_FAILURE(cb, cbd->data); -} - -static void isi_gprs_set_attached(struct ofono_gprs *gprs, int attached, +static void isi_gprs_set_attach_policy(struct ofono_gprs *gprs, + ofono_bool_t always_on, ofono_gprs_cb_t cb, void *data) { struct gprs_data *gd = ofono_gprs_get_data(gprs); struct isi_cb_data *cbd = isi_cb_data_new(gprs, cb, data); + const unsigned char msg[] = { + GPDS_CONFIGURE_REQ, + always_on ? GPDS_ATTACH_MODE_AUTOMATIC + : GPDS_ATTACH_MODE_MANUAL, + GPDS_MT_ACT_MODE_REJECT, + GPDS_CLASSC_MODE_DEFAULT, + GPDS_AOL_CTX_DEFAULT, + 0x00, + 0x00 + }; if (cbd == NULL || gd == NULL) goto error; - if (attached) { - const unsigned char msg[] = { - GPDS_ATTACH_REQ, - GPDS_FOLLOW_OFF - }; - - if (g_isi_client_send_with_timeout(gd->client, - msg, sizeof(msg), - GPDS_ATTACH_TIMEOUT, attach_resp_cb, - cbd, g_free)) - return; - } else { - const unsigned char msg[] = { - GPDS_DETACH_REQ, - 0x00, /* filler */ - 0x00 /* sub-blocks */ - }; - - if (g_isi_client_send_with_timeout(gd->client, - msg, sizeof(msg), - GPDS_DETACH_TIMEOUT, detach_resp_cb, - cbd, g_free)) - return; - } + if (g_isi_client_send(gd->client, msg, sizeof(msg), + configure_resp_cb, cbd, g_free)) + return; error: CALLBACK_WITH_FAILURE(cb, data); @@ -493,7 +408,7 @@ static struct ofono_gprs_driver driver = { .name = "isimodem", .probe = isi_gprs_probe, .remove = isi_gprs_remove, - .set_attached = isi_gprs_set_attached, + .set_attach_policy = isi_gprs_set_attach_policy, .attached_status = isi_gprs_attached_status, }; -- 1.7.1 _______________________________________________ ofono mailing list ofono@ofono.org http://lists.ofono.org/listinfo/ofono