Skip to contentSkip to conversation

Move GPRS attach logic to the modem

PATCH New Rémi Denis-Courmont 1 participant 8 messages Feb 7, 2011

lore
Share & tools
lore
#0 lore raw

cover Move GPRS attach logic to the modem

Hello,

This series moves responsibility for GPRS attach to the modem.

In most cases, the modem will attach on-demand when a first context is activated. This simplifies the oFono interface and implementation.

Some operators require the device be always attached. This is managed by a new driver callback to set the attach policy.

TBD: configuration option for the policy

 doc/connman-api.txt     |    8 -
 drivers/atmodem/gprs.c  |   30 +-----
 drivers/isimodem/gprs.c |  131 ++++-----------------------
 include/gprs.h          |    3 
 src/dbus.c              |   13 --
 src/gprs.c              |  232 ++----------------------------------------------
 src/ofono.h             |    2 
 7 files changed, 45 insertions(+), 374 deletions(-)
Signature · 2 lines
Rémi Denis-Courmont
Nokia Devices R&D, Maemo Software, Helsinki
#1 lore raw

PATCH 1/7 gprs: remove RoamingAllowed property

No roaming policies need to be enforced per GPRS context rather than for the whole GPRS service. Otherwise, you would not be able to receive an MMS or even register to the IMS SIP while roaming.

---
 src/gprs.c |   51 +++------------------------------------------------
 1 files changed, 3 insertions(+), 48 deletions(-)
src/gprs.c +3 -48
index 5ea864c..b6003f7 100644
@@ -76,7 +76,6 @@ struct ofono_gprs {
 	GSList *contexts;
 	ofono_bool_t attached;
 	ofono_bool_t driver_attached;
-	ofono_bool_t roaming_allowed;
 	ofono_bool_t powered;
 	ofono_bool_t suspended;
 	int status;
@@ -1426,10 +1425,8 @@ static void gprs_netreg_update(struct ofono_gprs *gprs)
 {
 	ofono_bool_t attach;
 
-	attach = gprs->netreg_status == NETWORK_REGISTRATION_STATUS_REGISTERED;
-
-	attach = attach || (gprs->roaming_allowed &&
-		gprs->netreg_status == NETWORK_REGISTRATION_STATUS_ROAMING);
+	attach = gprs->netreg_status == NETWORK_REGISTRATION_STATUS_REGISTERED
+		|| NETWORK_REGISTRATION_STATUS_ROAMING;
 
 	attach = attach && gprs->powered;
 
@@ -1492,10 +1489,6 @@ static DBusMessage *gprs_get_properties(DBusConnection *conn,
 					DBUS_TYPE_STRING, &bearer);
 	}
 
-	value = gprs->roaming_allowed;
-	ofono_dbus_dict_append(&dict, "RoamingAllowed",
-				DBUS_TYPE_BOOLEAN, &value);
-
 	value = gprs->powered;
 	ofono_dbus_dict_append(&dict, "Powered", DBUS_TYPE_BOOLEAN, &value);
 
@@ -1537,27 +1530,7 @@ static DBusMessage *gprs_set_property(DBusConnection *conn,
 
 	dbus_message_iter_recurse(&iter, &var);
 
-	if (!strcmp(property, "RoamingAllowed")) {
-		if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BOOLEAN)
-			return __ofono_error_invalid_args(msg);
-
-		dbus_message_iter_get_basic(&var, &value);
-
-		if (gprs->roaming_allowed == (ofono_bool_t) value)
-			return dbus_message_new_method_return(msg);
-
-		gprs->roaming_allowed = value;
-
-		if (gprs->settings) {
-			g_key_file_set_integer(gprs->settings, SETTINGS_GROUP,
-						"RoamingAllowed",
-						gprs->roaming_allowed);
-			storage_sync(gprs->imsi, SETTINGS_STORE,
-					gprs->settings);
-		}
-
-		gprs_netreg_update(gprs);
-	} else if (!strcmp(property, "Powered")) {
+	if (!strcmp(property, "Powered")) {
 		if (gprs->driver->set_attached == NULL)
 			return __ofono_error_not_implemented(msg);
 
@@ -2000,10 +1973,6 @@ void ofono_gprs_status_notify(struct ofono_gprs *gprs, int status)
 	if (gprs->powered == FALSE)
 		goto detach;
 
-	if (gprs->roaming_allowed == FALSE &&
-			status == NETWORK_REGISTRATION_STATUS_ROAMING)
-		goto detach;
-
 	gprs->driver_attached = TRUE;
 	gprs_attached_update(gprs);
 
@@ -2499,7 +2468,6 @@ static void gprs_load_settings(struct ofono_gprs *gprs, const char *imsi)
 	/*
 	 * If any error occurs, simply switch to defaults.
 	 * Default to Powered = True
-	 * and RoamingAllowed = False
 	 */
 	if (error) {
 		gprs->powered = TRUE;
@@ -2507,19 +2475,6 @@ static void gprs_load_settings(struct ofono_gprs *gprs, const char *imsi)
 					"Powered", gprs->powered);
 	}
 
-	error = NULL;
-	gprs->roaming_allowed = g_key_file_get_boolean(gprs->settings,
-							SETTINGS_GROUP,
-							"RoamingAllowed",
-							&error);
-
-	if (error) {
-		gprs->roaming_allowed = FALSE;
-		g_key_file_set_boolean(gprs->settings, SETTINGS_GROUP,
-					"RoamingAllowed",
-					gprs->roaming_allowed);
-	}
-
 	groups = g_key_file_get_groups(gprs->settings, NULL);
 
 	for (i = 0; groups[i]; i++) {
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/7 doc: remove RoamingAllowed

In reply to Rémi Denis-Courmont
---
 doc/connman-api.txt |    8 --------
 1 files changed, 0 insertions(+), 8 deletions(-)
doc/connman-api.txt +0 -8
index 22c59dc..4c24701 100644
@@ -106,14 +106,6 @@ Properties	boolean Attached [readonly]
 			for an appropriate time for GPRS service to resume
 			before taking corrective action.
 
-		boolean RoamingAllowed [readwrite]
-
-			Contains whether data roaming is allowed.  In the off
-			setting, if the packet radio registration state
-			indicates that the modem is roaming, oFono will
-			automatically detach and no further connection
-			establishment will be possible.
-
 		boolean Powered [readwrite]
 
 			Controls whether packet radio use is allowed. Setting
Signature · 1 line
1.7.1
#3 lore raw

PATCH 3/7 gprs: let the modems automatically attach when activating a context

In reply to Rémi Denis-Courmont

If some really stupid modem does not support attach on demand, this really should be worked around in the specific driver (at least AT and ISI modems support this).

---
 src/dbus.c  |   13 -------------
 src/gprs.c  |    6 ------
 src/ofono.h |    2 --
 3 files changed, 0 insertions(+), 21 deletions(-)
src/dbus.c +0 -13
index 01d43cf..a635121 100644
@@ -336,19 +336,6 @@ DBusMessage *__ofono_error_in_use(DBusMessage *msg)
 			"The resource is currently in use");
 }
 
-DBusMessage *__ofono_error_not_attached(DBusMessage *msg)
-{
-	return g_dbus_create_error(msg, OFONO_ERROR_INTERFACE ".NotAttached",
-			"GPRS is not attached");
-}
-
-DBusMessage *__ofono_error_attach_in_progress(DBusMessage *msg)
-{
-	return g_dbus_create_error(msg,
-				OFONO_ERROR_INTERFACE ".AttachInProgress",
-				"GPRS Attach is in progress");
-}
-
 DBusMessage *__ofono_error_canceled(DBusMessage *msg)
 {
 	return g_dbus_create_error(msg, OFONO_ERROR_INTERFACE ".Canceled",
src/gprs.c +0 -6
index b6003f7..0a137b2 100644
@@ -1067,12 +1067,6 @@ static DBusMessage *pri_set_property(DBusConnection *conn,
 		if (ctx->active == (ofono_bool_t) value)
 			return dbus_message_new_method_return(msg);
 
-		if (value && !ctx->gprs->attached)
-			return __ofono_error_not_attached(msg);
-
-		if (ctx->gprs->flags & GPRS_FLAG_ATTACHING)
-			return __ofono_error_attach_in_progress(msg);
-
 		if (value) {
 			if (assign_context(ctx) == FALSE)
 				return __ofono_error_not_implemented(msg);
src/ofono.h +0 -2
index 6ba0187..bf2e6fe 100644
@@ -54,8 +54,6 @@ DBusMessage *__ofono_error_not_available(DBusMessage *msg);
 DBusMessage *__ofono_error_timed_out(DBusMessage *msg);
 DBusMessage *__ofono_error_sim_not_ready(DBusMessage *msg);
 DBusMessage *__ofono_error_in_use(DBusMessage *msg);
-DBusMessage *__ofono_error_not_attached(DBusMessage *msg);
-DBusMessage *__ofono_error_attach_in_progress(DBusMessage *msg);
 DBusMessage *__ofono_error_canceled(DBusMessage *msg);
 DBusMessage *__ofono_error_access_denied(DBusMessage *msg);
 
Signature · 1 line
1.7.1
#4 lore raw

PATCH 4/7 gprs: do not watch registration status or re-attach

In reply to Rémi Denis-Courmont

This is not needed since we let the modem automatically attach.

---
 src/gprs.c |  175 +++--------------------------------------------------------
 1 files changed, 9 insertions(+), 166 deletions(-)
src/gprs.c +9 -166
index 0a137b2..69cf8c7 100644
@@ -46,9 +46,6 @@
 #include "simutil.h"
 #include "util.h"
 
-#define GPRS_FLAG_ATTACHING 0x1
-#define GPRS_FLAG_RECHECK 0x2
-
 #define SETTINGS_STORE "gprs"
 #define SETTINGS_GROUP "Settings"
 #define MAX_CONTEXT_NAME_LENGTH 127
@@ -75,7 +72,6 @@ enum packet_bearer {
 struct ofono_gprs {
 	GSList *contexts;
 	ofono_bool_t attached;
-	ofono_bool_t driver_attached;
 	ofono_bool_t powered;
 	ofono_bool_t suspended;
 	int status;
@@ -85,10 +81,6 @@ struct ofono_gprs {
 	struct idmap *pid_map;
 	unsigned int last_context_id;
 	struct idmap *cid_map;
-	int netreg_status;
-	struct ofono_netreg *netreg;
-	unsigned int netreg_watch;
-	unsigned int status_watch;
 	GKeyFile *settings;
 	char *imsi;
 	DBusMessage *pending;
@@ -136,7 +128,6 @@ struct pri_context {
 	struct ofono_gprs *gprs;
 };
 
-static void gprs_netreg_update(struct ofono_gprs *gprs);
 static void gprs_deactivate_next(struct ofono_gprs *gprs);
 
 const char *packet_bearer_to_string(int bearer)
@@ -1271,7 +1262,8 @@ static void update_suspended_property(struct ofono_gprs *gprs,
 
 	gprs->suspended = suspended;
 
-	if (gprs->attached)
+	if (gprs->status == NETWORK_REGISTRATION_STATUS_REGISTERED ||
+			gprs->status == NETWORK_REGISTRATION_STATUS_ROAMING)
 		ofono_dbus_signal_property_changed(conn, path,
 					OFONO_CONNECTION_MANAGER_INTERFACE,
 					"Suspended", DBUS_TYPE_BOOLEAN, &value);
@@ -1318,8 +1310,7 @@ static void gprs_attached_update(struct ofono_gprs *gprs)
 	ofono_bool_t attached;
 	dbus_bool_t value;
 
-	attached = gprs->driver_attached &&
-		(gprs->status == NETWORK_REGISTRATION_STATUS_REGISTERED ||
+	attached = (gprs->status == NETWORK_REGISTRATION_STATUS_REGISTERED ||
 			gprs->status == NETWORK_REGISTRATION_STATUS_ROAMING);
 
 	if (attached == gprs->attached)
@@ -1371,87 +1362,6 @@ static void registration_status_cb(const struct ofono_error *error,
 
 	if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
 		ofono_gprs_status_notify(gprs, status);
-
-	if (gprs->flags & GPRS_FLAG_RECHECK) {
-		gprs->flags &= ~GPRS_FLAG_RECHECK;
-		gprs_netreg_update(gprs);
-	}
-}
-
-static void gprs_attach_callback(const struct ofono_error *error, void *data)
-{
-	struct ofono_gprs *gprs = data;
-
-	DBG("%s error = %d", __ofono_atom_get_path(gprs->atom), error->type);
-
-	gprs->flags &= ~GPRS_FLAG_ATTACHING;
-
-	if (error->type != OFONO_ERROR_TYPE_NO_ERROR)
-		gprs->driver_attached = !gprs->driver_attached;
-
-	if (gprs->driver->attached_status) {
-		gprs->driver->attached_status(gprs, registration_status_cb,
-						gprs);
-		return;
-	}
-
-	gprs_attached_update(gprs);
-
-	if (gprs->flags & GPRS_FLAG_RECHECK) {
-		gprs->flags &= ~GPRS_FLAG_RECHECK;
-		gprs_netreg_update(gprs);
-	}
-}
-
-static void gprs_netreg_removed(struct ofono_gprs *gprs)
-{
-	gprs->netreg = NULL;
-
-	gprs->flags &= ~(GPRS_FLAG_RECHECK | GPRS_FLAG_ATTACHING);
-	gprs->status_watch = 0;
-	gprs->netreg_status = NETWORK_REGISTRATION_STATUS_NOT_REGISTERED;
-	gprs->driver_attached = FALSE;
-
-	gprs_attached_update(gprs);
-}
-
-static void gprs_netreg_update(struct ofono_gprs *gprs)
-{
-	ofono_bool_t attach;
-
-	attach = gprs->netreg_status == NETWORK_REGISTRATION_STATUS_REGISTERED
-		|| NETWORK_REGISTRATION_STATUS_ROAMING;
-
-	attach = attach && gprs->powered;
-
-	if (gprs->driver_attached == attach)
-		return;
-
-	if (gprs->flags & GPRS_FLAG_ATTACHING) {
-		gprs->flags |= GPRS_FLAG_RECHECK;
-		return;
-	}
-
-	gprs->flags |= GPRS_FLAG_ATTACHING;
-
-	gprs->driver->set_attached(gprs, attach, gprs_attach_callback, gprs);
-	gprs->driver_attached = attach;
-}
-
-static void netreg_status_changed(int status, int lac, int ci, int tech,
-					const char *mcc, const char *mnc,
-					void *data)
-{
-	struct ofono_gprs *gprs = data;
-
-	DBG("%d", status);
-
-	if (gprs->netreg_status == status)
-		return;
-
-	gprs->netreg_status = status;
-
-	gprs_netreg_update(gprs);
 }
 
 static DBusMessage *gprs_get_properties(DBusConnection *conn,
@@ -1525,9 +1435,6 @@ static DBusMessage *gprs_set_property(DBusConnection *conn,
 	dbus_message_iter_recurse(&iter, &var);
 
 	if (!strcmp(property, "Powered")) {
-		if (gprs->driver->set_attached == NULL)
-			return __ofono_error_not_implemented(msg);
-
 		if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BOOLEAN)
 			return __ofono_error_invalid_args(msg);
 
@@ -1545,7 +1452,10 @@ static DBusMessage *gprs_set_property(DBusConnection *conn,
 					gprs->settings);
 		}
 
-		gprs_netreg_update(gprs);
+		if (gprs->driver->attached_status)
+			gprs->driver->attached_status(gprs,
+							registration_status_cb,
+							gprs);
 	} else {
 		return __ofono_error_invalid_args(msg);
 	}
@@ -1941,14 +1851,8 @@ void ofono_gprs_detached_notify(struct ofono_gprs *gprs)
 {
 	DBG("%s", __ofono_atom_get_path(gprs->atom));
 
-	gprs->driver_attached = FALSE;
-	gprs_attached_update(gprs);
-
-	/*
-	 * TODO: The network forced a detach, we should wait for some time
-	 * and try to re-attach.  This might also be related to a suspend
-	 * event while voicecall is active.
-	 */
+	ofono_gprs_status_notify(gprs,
+				NETWORK_REGISTRATION_STATUS_NOT_REGISTERED);
 }
 
 void ofono_gprs_status_notify(struct ofono_gprs *gprs, int status)
@@ -1956,25 +1860,7 @@ void ofono_gprs_status_notify(struct ofono_gprs *gprs, int status)
 	DBG("%s status %d", __ofono_atom_get_path(gprs->atom), status);
 
 	gprs->status = status;
-
-	if (status != NETWORK_REGISTRATION_STATUS_REGISTERED &&
-			status != NETWORK_REGISTRATION_STATUS_ROAMING) {
-		gprs_attached_update(gprs);
-		return;
-	}
-
-	/* We registered without being powered */
-	if (gprs->powered == FALSE)
-		goto detach;
-
-	gprs->driver_attached = TRUE;
 	gprs_attached_update(gprs);
-
-	return;
-
-detach:
-	gprs->flags |= GPRS_FLAG_ATTACHING;
-	gprs->driver->set_attached(gprs, FALSE, gprs_attach_callback, gprs);
 }
 
 void ofono_gprs_set_cid_range(struct ofono_gprs *gprs,
@@ -2214,18 +2100,6 @@ static void gprs_unregister(struct ofono_atom *atom)
 		gprs->cid_map = NULL;
 	}
 
-	if (gprs->netreg_watch) {
-		if (gprs->status_watch) {
-			__ofono_netreg_remove_status_watch(gprs->netreg,
-							gprs->status_watch);
-			gprs->status_watch = 0;
-		}
-
-		__ofono_modem_remove_atom_watch(modem, gprs->netreg_watch);
-		gprs->netreg_watch = 0;
-		gprs->netreg = NULL;
-	}
-
 	ofono_modem_remove_interface(modem,
 					OFONO_CONNECTION_MANAGER_INTERFACE);
 	g_dbus_unregister_interface(conn, path,
@@ -2288,31 +2162,11 @@ struct ofono_gprs *ofono_gprs_create(struct ofono_modem *modem,
 	}
 
 	gprs->status = NETWORK_REGISTRATION_STATUS_UNKNOWN;
-	gprs->netreg_status = NETWORK_REGISTRATION_STATUS_UNKNOWN;
 	gprs->pid_map = idmap_new(MAX_CONTEXTS);
 
 	return gprs;
 }
 
-static void netreg_watch(struct ofono_atom *atom,
-				enum ofono_atom_watch_condition cond,
-				void *data)
-{
-	struct ofono_gprs *gprs = data;
-
-	if (cond == OFONO_ATOM_WATCH_CONDITION_UNREGISTERED) {
-		gprs_netreg_removed(gprs);
-		return;
-	}
-
-	gprs->netreg = __ofono_atom_get_data(atom);
-	gprs->netreg_status = ofono_netreg_get_status(gprs->netreg);
-	gprs->status_watch = __ofono_netreg_add_status_watch(gprs->netreg,
-					netreg_status_changed, gprs, NULL);
-
-	gprs_netreg_update(gprs);
-}
-
 static gboolean load_context(struct ofono_gprs *gprs, const char *group)
 {
 	char *name = NULL;
@@ -2600,7 +2454,6 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
 	DBusConnection *conn = ofono_dbus_get_connection();
 	struct ofono_modem *modem = __ofono_atom_get_modem(gprs->atom);
 	const char *path = __ofono_atom_get_path(gprs->atom);
-	struct ofono_atom *netreg_atom;
 	struct ofono_atom *sim_atom;
 
 	if (!g_dbus_register_interface(conn, path,
@@ -2633,16 +2486,6 @@ void ofono_gprs_register(struct ofono_gprs *gprs)
 	if (gprs->contexts == NULL)
 		add_context(gprs, NULL, OFONO_GPRS_CONTEXT_TYPE_INTERNET);
 
-	gprs->netreg_watch = __ofono_modem_add_atom_watch(modem,
-					OFONO_ATOM_TYPE_NETREG,
-					netreg_watch, gprs, NULL);
-
-	netreg_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_NETREG);
-
-	if (netreg_atom && __ofono_atom_get_registered(netreg_atom))
-		netreg_watch(netreg_atom,
-				OFONO_ATOM_WATCH_CONDITION_REGISTERED, gprs);
-
 	__ofono_atom_register(gprs->atom, gprs_unregister);
 }
 
Signature · 1 line
1.7.1
#5 lore raw

PATCH 5/7 include: replace set_attached with set_attach_policy

In reply to Rémi Denis-Courmont
---
 include/gprs.h |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
include/gprs.h +2 -1
index 157a6f9..15c1080 100644
@@ -41,7 +41,8 @@ struct ofono_gprs_driver {
 	int (*probe)(struct ofono_gprs *gprs, unsigned int vendor,
 			void *data);
 	void (*remove)(struct ofono_gprs *gprs);
-	void (*set_attached)(struct ofono_gprs *gprs, int attached,
+	void (*set_attach_policy)(struct ofono_gprs *gprs,
+				ofono_bool_t always_on,
 				ofono_gprs_cb_t cb, void *data);
 	void (*attached_status)(struct ofono_gprs *gprs,
 					ofono_gprs_status_cb_t cb, void *data);
Signature · 1 line
1.7.1
#6 lore raw

PATCH 6/7 atmodem: dummy set_attach_policy

In reply to Rémi Denis-Courmont
---
 drivers/atmodem/gprs.c |   30 ++++++++----------------------
 1 files changed, 8 insertions(+), 22 deletions(-)
drivers/atmodem/gprs.c +8 -22
index 6e01994..3fcf17d 100644
@@ -51,31 +51,17 @@ struct gprs_data {
 	unsigned int vendor;
 };
 
-static void at_cgatt_cb(gboolean ok, GAtResult *result, gpointer user_data)
-{
-	struct cb_data *cbd = user_data;
-	ofono_gprs_cb_t cb = cbd->cb;
-	struct ofono_error error;
-
-	decode_at_error(&error, g_at_result_final_response(result));
-
-	cb(&error, cbd->data);
-}
-
-static void at_gprs_set_attached(struct ofono_gprs *gprs, int attached,
+static void at_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 cb_data *cbd = cb_data_new(cb, data);
-	char buf[64];
-
-	snprintf(buf, sizeof(buf), "AT+CGATT=%i", attached ? 1 : 0);
+	/* TODO: vendor specific stuff */
 
-	if (g_at_chat_send(gd->chat, buf, none_prefix,
-				at_cgatt_cb, cbd, g_free) > 0)
+	/* Pure standard modems only support demand-attach policy */
+	if (!always_on) {
+		CALLBACK_WITH_SUCCESS(cb, data);
 		return;
-
-	g_free(cbd);
+	}
 
 	CALLBACK_WITH_FAILURE(cb, data);
 }
@@ -401,7 +387,7 @@ static struct ofono_gprs_driver driver = {
 	.name			= "atmodem",
 	.probe			= at_gprs_probe,
 	.remove			= at_gprs_remove,
-	.set_attached		= at_gprs_set_attached,
+	.set_attach_policy	= at_gprs_set_attach_policy,
 	.attached_status	= at_gprs_registration_status,
 };
 
Signature · 1 line
1.7.1
#7 lore raw

PATCH 7/7 isi: implement set_attach_policy

In reply to Rémi Denis-Courmont
---
 drivers/isimodem/gprs.c |  131 ++++++++--------------------------------------
 1 files changed, 23 insertions(+), 108 deletions(-)
drivers/isimodem/gprs.c +23 -108
index ea90704..ad5a768 100644
@@ -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,
 };
 
Signature · 1 line
1.7.1