Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions doc/connman-api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,17 @@ Properties boolean Attached [readonly]
boolean Powered [readwrite]

Controls whether packet radio use is allowed. Setting
this value to off detaches the modem from the
Packet Domain network.
this value and PoweredForMMS to off detaches the modem
from the Packet Domain network.

boolean PoweredForMMS [readwrite]

As Powered, it controls whether packet radio use is
allowed. When any of them is set, the use of packet
radio is allowed. When both are false, the modem is
asked to detach from the Packet Domain. The reason for
having both is to be able to send/receive MMS without
internet data on.

Connection Context hierarchy
=================
Expand Down
85 changes: 81 additions & 4 deletions src/gprs.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ struct ofono_gprs {
ofono_bool_t driver_attached;
ofono_bool_t roaming_allowed;
ofono_bool_t powered;
ofono_bool_t powered_for_mms;
ofono_bool_t detach_forced;
ofono_bool_t suspended;
int status;
int flags;
Expand Down Expand Up @@ -857,7 +859,16 @@ static void pri_activate_callback(const struct ofono_error *error, void *data)
if (gc->settings->interface != NULL) {
pri_ifupdown(gc->settings->interface, TRUE);

if (ctx->type == OFONO_GPRS_CONTEXT_TYPE_MMS &&
/*
* Activate route when NetworkManager does not do that for us.
* In the case of combined contexts that can happen if we have
* not activated cellular data.
* TODO: Consider using only ofono for setting up routes to the
* MMS proxy.
*/
if ((ctx->type == OFONO_GPRS_CONTEXT_TYPE_MMS ||
(ctx->type == OFONO_GPRS_CONTEXT_TYPE_INTERNET
&& !ctx->gprs->powered)) &&
gc->settings->ipv4)
pri_update_mms_context_settings(ctx);

Expand Down Expand Up @@ -1593,6 +1604,11 @@ static void gprs_netreg_removed(struct ofono_gprs *gprs)
gprs_attached_update(gprs);
}

static ofono_bool_t gprs_is_powered(struct ofono_gprs *gprs)
{
return (gprs->powered || gprs->powered_for_mms) && !gprs->detach_forced;
}

static void gprs_netreg_update(struct ofono_gprs *gprs)
{
ofono_bool_t attach;
Expand All @@ -1602,7 +1618,7 @@ static void gprs_netreg_update(struct ofono_gprs *gprs)
attach = attach || (gprs->roaming_allowed &&
gprs->netreg_status == NETWORK_REGISTRATION_STATUS_ROAMING);

attach = attach && gprs->powered;
attach = attach && gprs_is_powered(gprs);

if (gprs->driver_attached == attach)
return;
Expand Down Expand Up @@ -1686,6 +1702,46 @@ static void notify_powered_change(struct ofono_gprs *gprs)
}
}

static void modem_notify_mms_powered_change(struct ofono_modem *modem,
void *data)
{
struct ofono_atom *atom;
struct ofono_gprs *gprs;
struct ofono_modem *modem_notif = data;
struct ofono_atom *atom_notif;
struct ofono_gprs *gprs_notif;
const char *path = ofono_modem_get_path(modem);

if (strcmp(path, ofono_modem_get_path(modem_notif)) == 0)
return;

if (!ofono_modem_is_standby(modem))
return;

atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_GPRS);
if (atom == NULL)
return;

gprs = __ofono_atom_get_data(atom);

if (gprs->driver->set_attached == NULL)
return;

atom_notif = __ofono_modem_find_atom(modem_notif, OFONO_ATOM_TYPE_GPRS);
gprs_notif = __ofono_atom_get_data(atom_notif);

gprs->detach_forced = gprs_notif->powered_for_mms;

gprs_netreg_update(gprs);
}

static void notify_mms_powered_change(struct ofono_gprs *gprs)
{
struct ofono_modem *modem = __ofono_atom_get_modem(gprs->atom);

__ofono_modem_foreach(modem_notify_mms_powered_change, modem);
}

static DBusMessage *gprs_get_properties(DBusConnection *conn,
DBusMessage *msg, void *data)
{
Expand Down Expand Up @@ -1722,6 +1778,10 @@ static DBusMessage *gprs_get_properties(DBusConnection *conn,
value = gprs->powered;
ofono_dbus_dict_append(&dict, "Powered", DBUS_TYPE_BOOLEAN, &value);

value = gprs->powered_for_mms;
ofono_dbus_dict_append(&dict, "PoweredForMMS",
DBUS_TYPE_BOOLEAN, &value);

if (gprs->attached) {
value = gprs->suspended;
ofono_dbus_dict_append(&dict, "Suspended",
Expand Down Expand Up @@ -1804,6 +1864,23 @@ static DBusMessage *gprs_set_property(DBusConnection *conn,
gprs_netreg_update(gprs);

notify_powered_change(gprs);
} else if (!strcmp(property, "PoweredForMMS")) {
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);

dbus_message_iter_get_basic(&var, &value);

if (gprs->powered_for_mms == (ofono_bool_t) value)
return dbus_message_new_method_return(msg);

gprs->powered_for_mms = value;

gprs_netreg_update(gprs);

notify_mms_powered_change(gprs);
} else {
return __ofono_error_invalid_args(msg);
}
Expand Down Expand Up @@ -2336,7 +2413,7 @@ static DBusMessage *gprs_reset_contexts(DBusConnection *conn,
if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_INVALID))
return __ofono_error_invalid_args(msg);

if (gprs->powered)
if (gprs_is_powered(gprs))
return __ofono_error_not_allowed(msg);

for (l = gprs->contexts; l; l = l->next) {
Expand Down Expand Up @@ -2449,7 +2526,7 @@ void ofono_gprs_status_notify(struct ofono_gprs *gprs, int status)
return;

/* We registered without being powered */
if (gprs->powered == FALSE)
if (gprs_is_powered(gprs) == FALSE)
goto detach;

if (gprs->roaming_allowed == FALSE &&
Expand Down
20 changes: 20 additions & 0 deletions test/disable-mms
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/python3

import dbus
import sys

bus = dbus.SystemBus()

if len(sys.argv) == 2:
path = sys.argv[1]
else:
manager = dbus.Interface(bus.get_object('org.ofono', '/'),
'org.ofono.Manager')
modems = manager.GetModems()
path = modems[0][0]

print("Disabling MMS data on modem %s..." % path)
cm = dbus.Interface(bus.get_object('org.ofono', path),
'org.ofono.ConnectionManager')

cm.SetProperty("PoweredForMMS", dbus.Boolean(0))
20 changes: 20 additions & 0 deletions test/enable-mms
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/python3

import dbus
import sys

bus = dbus.SystemBus()

if len(sys.argv) == 2:
path = sys.argv[1]
else:
manager = dbus.Interface(bus.get_object('org.ofono', '/'),
'org.ofono.Manager')
modems = manager.GetModems()
path = modems[0][0]

print("Enabling MMS data for modem %s..." % path)
cm = dbus.Interface(bus.get_object('org.ofono', path),
'org.ofono.ConnectionManager')

cm.SetProperty("PoweredForMMS", dbus.Boolean(1))