All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] TODO: Add owner to implement the Lockdown property
@ 2010-11-19 21:37 Gustavo F. Padovan
  2010-11-19 21:37 ` [PATCH 2/3] Add __ofono_error_access_denied() Gustavo F. Padovan
  2010-11-23 11:05 ` [PATCH 1/3] TODO: Add owner to implement the Lockdown property Denis Kenzior
  0 siblings, 2 replies; 9+ messages in thread
From: Gustavo F. Padovan @ 2010-11-19 21:37 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 463 bytes --]

---
 TODO |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/TODO b/TODO
index dec43fd..36afaeb 100644
--- a/TODO
+++ b/TODO
@@ -475,6 +475,7 @@ Miscellaneous
 
   Priority: Medium
   Complexity: C2
+  Owner: Gustavo F Padovan <padovan@profusion.mobi>
 
 - TTY (hearing impaired) support.  Add a new oFono atom type that will enable
   the user to enable or disable the TTY support on the modem.  Support for
-- 
1.7.3.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/3] Add __ofono_error_access_denied()
  2010-11-19 21:37 [PATCH 1/3] TODO: Add owner to implement the Lockdown property Gustavo F. Padovan
@ 2010-11-19 21:37 ` Gustavo F. Padovan
  2010-11-19 21:37   ` [PATCH 3/3] Add Lockdown property to Modem interface Gustavo F. Padovan
  2010-11-23 11:12   ` [PATCH 2/3] Add __ofono_error_access_denied() Denis Kenzior
  2010-11-23 11:05 ` [PATCH 1/3] TODO: Add owner to implement the Lockdown property Denis Kenzior
  1 sibling, 2 replies; 9+ messages in thread
From: Gustavo F. Padovan @ 2010-11-19 21:37 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1173 bytes --]

---
 src/dbus.c  |    6 ++++++
 src/ofono.h |    1 +
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/src/dbus.c b/src/dbus.c
index 8a685aa..d7ad564 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -342,6 +342,12 @@ DBusMessage *__ofono_error_canceled(DBusMessage *msg)
 					"Operation has been canceled");
 }
 
+DBusMessage *__ofono_error_access_denied(DBusMessage *msg)
+{
+	return g_dbus_create_error(msg, OFONO_ERROR_INTERFACE ".AccessDenied",
+					"Operation not permitted");
+}
+
 void __ofono_dbus_pending_reply(DBusMessage **msg, DBusMessage *reply)
 {
 	DBusConnection *conn = ofono_dbus_get_connection();
diff --git a/src/ofono.h b/src/ofono.h
index 4d76d20..a24dc34 100644
--- a/src/ofono.h
+++ b/src/ofono.h
@@ -57,6 +57,7 @@ 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);
 
 void __ofono_dbus_pending_reply(DBusMessage **msg, DBusMessage *reply);
 
-- 
1.7.3.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/3] Add Lockdown property to Modem interface
  2010-11-19 21:37 ` [PATCH 2/3] Add __ofono_error_access_denied() Gustavo F. Padovan
@ 2010-11-19 21:37   ` Gustavo F. Padovan
  2010-11-19 22:20     ` [PATCH] Add test script for the Lockdown property Gustavo F. Padovan
  2010-11-23 13:50     ` [PATCH 3/3] Add Lockdown property to Modem interface Denis Kenzior
  2010-11-23 11:12   ` [PATCH 2/3] Add __ofono_error_access_denied() Denis Kenzior
  1 sibling, 2 replies; 9+ messages in thread
From: Gustavo F. Padovan @ 2010-11-19 21:37 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 5680 bytes --]

Setting Lockdown to TRUE means power down the modem and hold a lock that
only permits the lock's owner power up the modem back. When released
it restores the last state of the modem before holding the lock.
---
 doc/modem-api.txt |   10 +++++
 src/modem.c       |  114 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 124 insertions(+), 0 deletions(-)

diff --git a/doc/modem-api.txt b/doc/modem-api.txt
index c48375e..3dd6dde 100644
--- a/doc/modem-api.txt
+++ b/doc/modem-api.txt
@@ -37,6 +37,16 @@ Properties	boolean Powered [readwrite]
 			Boolean representing the rf state of the modem.
 			Online is false in flight mode.
 
+		boolean Lockdown [readwrite]
+
+			Boolean representing the lock state of the modem.
+			Setting it to true, makes the calling application hold
+			the modem lock and power it down. Setting to false
+			makes the it restore the modem state before the
+			lockdown and release the modem lock. Only the
+			application that holds the lock can power up the modem.
+			If the the application exits Lockdown is set to false.
+
 		boolean Emergency [readonly, optional, experimental]
 
 			Boolean representing the emergency mode of the
diff --git a/src/modem.c b/src/modem.c
index 704de29..83b9cee 100644
--- a/src/modem.c
+++ b/src/modem.c
@@ -72,6 +72,9 @@ struct ofono_modem {
 	ofono_bool_t		powered;
 	ofono_bool_t		powered_pending;
 	ofono_bool_t		reset;
+	ofono_bool_t		lockdown;
+	char			*lock_owner;
+	guint			lock_watch;
 	guint			timeout;
 	ofono_bool_t		online;
 	GHashTable		*properties;
@@ -429,6 +432,9 @@ static void online_cb(const struct ofono_error *error, void *data)
 			return;
 		}
 
+		if (!modem->pending)
+			return;
+
 		reply = dbus_message_new_method_return(modem->pending);
 	} else {
 		reply = __ofono_error_failed(modem->pending);
@@ -537,6 +543,9 @@ void __ofono_modem_append_properties(struct ofono_modem *modem,
 	ofono_dbus_dict_append(dict, "Powered", DBUS_TYPE_BOOLEAN,
 				&modem->powered);
 
+	ofono_dbus_dict_append(dict, "Lockdown", DBUS_TYPE_BOOLEAN,
+				&modem->lockdown);
+
 	devinfo_atom = __ofono_modem_find_atom(modem, OFONO_ATOM_TYPE_DEVINFO);
 
 	/* We cheat a little here and don't check the registered status */
@@ -671,6 +680,22 @@ static gboolean set_powered_timeout(gpointer user)
 	return FALSE;
 }
 
+static void lockdown_disconnect(DBusConnection *conn, void *user_data)
+{
+	struct ofono_modem *modem = user_data;
+
+	DBG("");
+
+	g_free(modem->lock_owner);
+
+	modem->lockdown = FALSE;
+
+	ofono_dbus_signal_property_changed(conn, modem->path,
+					OFONO_MODEM_INTERFACE,
+					"Lockdown", DBUS_TYPE_BOOLEAN,
+					&modem->lockdown);
+}
+
 static DBusMessage *modem_set_property(DBusConnection *conn,
 					DBusMessage *msg, void *data)
 {
@@ -713,6 +738,9 @@ static DBusMessage *modem_set_property(DBusConnection *conn,
 		if (modem->powered == powered)
 			return dbus_message_new_method_return(msg);
 
+		if (modem->lockdown)
+			return __ofono_error_access_denied(msg);
+
 		err = set_powered(modem, powered);
 		if (err < 0) {
 			if (err != -EINPROGRESS)
@@ -744,6 +772,92 @@ static DBusMessage *modem_set_property(DBusConnection *conn,
 		return NULL;
 	}
 
+	if (g_str_equal(name, "Lockdown")) {
+		ofono_bool_t lockdown, powered;
+		const char *caller;
+		int err;
+
+		if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_BOOLEAN)
+			return __ofono_error_invalid_args(msg);
+
+		dbus_message_iter_get_basic(&var, &lockdown);
+
+		if (modem->pending != NULL)
+			return __ofono_error_busy(msg);
+
+		if (modem->lockdown == lockdown)
+			return dbus_message_new_method_return(msg);
+
+		if (modem->powered != modem->powered_pending || modem->reset)
+			return __ofono_error_not_available(msg);
+
+		caller = dbus_message_get_sender(msg);
+
+		if (lockdown) {
+			modem->lock_owner = g_strdup(caller);
+
+			modem->lock_watch = g_dbus_add_service_watch(conn,
+					modem->lock_owner, NULL,
+					lockdown_disconnect, modem, NULL);
+
+			if (modem->lock_watch == 0) {
+				g_free(modem->lock_owner);
+				return __ofono_error_failed(msg);
+			}
+
+			modem->old_state = modem->modem_state;
+			powered = FALSE;
+		} else {
+			if (g_strcmp0(caller, modem->lock_owner))
+				return __ofono_error_access_denied(msg);
+
+			g_free(modem->lock_owner);
+			g_dbus_remove_watch(conn, modem->lock_watch);
+
+			if (modem->old_state > MODEM_STATE_POWER_OFF)
+				powered = TRUE;
+			else
+				powered = FALSE;
+		}
+
+		modem->lockdown = lockdown;
+
+		g_dbus_send_reply(conn, msg, DBUS_TYPE_INVALID);
+
+		ofono_dbus_signal_property_changed(conn, modem->path,
+						OFONO_MODEM_INTERFACE,
+						"Lockdown", DBUS_TYPE_BOOLEAN,
+						&lockdown);
+
+		err = set_powered(modem, powered);
+		if (err < 0) {
+			if (err != -EINPROGRESS)
+				return __ofono_error_failed(msg);
+
+			modem->pending = dbus_message_ref(msg);
+			modem->timeout = g_timeout_add_seconds(20,
+						set_powered_timeout, modem);
+			return NULL;
+		}
+
+		ofono_dbus_signal_property_changed(conn, modem->path,
+						OFONO_MODEM_INTERFACE,
+						"Powered", DBUS_TYPE_BOOLEAN,
+						&powered);
+
+		if (powered) {
+			modem_change_state(modem, MODEM_STATE_PRE_SIM);
+
+			/* Force SIM Ready for devies with no sim atom */
+			if (__ofono_modem_find_atom(modem,
+						OFONO_ATOM_TYPE_SIM) == NULL)
+				sim_state_watch(OFONO_SIM_STATE_READY, modem);
+		} else
+			modem_change_state(modem, MODEM_STATE_POWER_OFF);
+
+		return NULL;
+	}
+
 	return __ofono_error_invalid_args(msg);
 }
 
-- 
1.7.3.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH] Add test script for the Lockdown property
  2010-11-19 21:37   ` [PATCH 3/3] Add Lockdown property to Modem interface Gustavo F. Padovan
@ 2010-11-19 22:20     ` Gustavo F. Padovan
  2010-11-23 13:50     ` [PATCH 3/3] Add Lockdown property to Modem interface Denis Kenzior
  1 sibling, 0 replies; 9+ messages in thread
From: Gustavo F. Padovan @ 2010-11-19 22:20 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 952 bytes --]

---
 test/lockdown-modem |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
 create mode 100755 test/lockdown-modem

diff --git a/test/lockdown-modem b/test/lockdown-modem
new file mode 100755
index 0000000..73f2199
--- /dev/null
+++ b/test/lockdown-modem
@@ -0,0 +1,25 @@
+#!/usr/bin/python
+
+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 "Locking and disconnecting modem %s..." % path
+modem = dbus.Interface(bus.get_object('org.ofono', path),
+						'org.ofono.Modem')
+
+modem.SetProperty("Lockdown", dbus.Boolean(1))
+
+print "press ENTER to power up and unlock the modem %s" % path
+sys.stdin.readline()
+
+modem.SetProperty("Lockdown", dbus.Boolean(0))
-- 
1.7.3.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] TODO: Add owner to implement the Lockdown property
  2010-11-19 21:37 [PATCH 1/3] TODO: Add owner to implement the Lockdown property Gustavo F. Padovan
  2010-11-19 21:37 ` [PATCH 2/3] Add __ofono_error_access_denied() Gustavo F. Padovan
@ 2010-11-23 11:05 ` Denis Kenzior
  1 sibling, 0 replies; 9+ messages in thread
From: Denis Kenzior @ 2010-11-23 11:05 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 228 bytes --]

Hi Gustavo,

On 11/19/2010 03:37 PM, Gustavo F. Padovan wrote:
> ---
>  TODO |    1 +
>  1 files changed, 1 insertions(+), 0 deletions(-)
> 

Patch has been applied.  Thanks for taking up this task.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] Add __ofono_error_access_denied()
  2010-11-19 21:37 ` [PATCH 2/3] Add __ofono_error_access_denied() Gustavo F. Padovan
  2010-11-19 21:37   ` [PATCH 3/3] Add Lockdown property to Modem interface Gustavo F. Padovan
@ 2010-11-23 11:12   ` Denis Kenzior
  1 sibling, 0 replies; 9+ messages in thread
From: Denis Kenzior @ 2010-11-23 11:12 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 240 bytes --]

Hi Gustavo,

On 11/19/2010 03:37 PM, Gustavo F. Padovan wrote:
> ---
>  src/dbus.c  |    6 ++++++
>  src/ofono.h |    1 +
>  2 files changed, 7 insertions(+), 0 deletions(-)
> 

Patch has been applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] Add Lockdown property to Modem interface
  2010-11-19 21:37   ` [PATCH 3/3] Add Lockdown property to Modem interface Gustavo F. Padovan
  2010-11-19 22:20     ` [PATCH] Add test script for the Lockdown property Gustavo F. Padovan
@ 2010-11-23 13:50     ` Denis Kenzior
  2010-11-23 17:53       ` Gustavo F. Padovan
  1 sibling, 1 reply; 9+ messages in thread
From: Denis Kenzior @ 2010-11-23 13:50 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1660 bytes --]

Hi Gustavo,

On 11/19/2010 03:37 PM, Gustavo F. Padovan wrote:
> Setting Lockdown to TRUE means power down the modem and hold a lock that
> only permits the lock's owner power up the modem back. When released
> it restores the last state of the modem before holding the lock.
> ---
>  doc/modem-api.txt |   10 +++++
>  src/modem.c       |  114 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 124 insertions(+), 0 deletions(-)
> 
> diff --git a/doc/modem-api.txt b/doc/modem-api.txt
> index c48375e..3dd6dde 100644
> --- a/doc/modem-api.txt
> +++ b/doc/modem-api.txt
> @@ -37,6 +37,16 @@ Properties	boolean Powered [readwrite]
>  			Boolean representing the rf state of the modem.
>  			Online is false in flight mode.
>  
> +		boolean Lockdown [readwrite]
> +
> +			Boolean representing the lock state of the modem.
> +			Setting it to true, makes the calling application hold
> +			the modem lock and power it down. Setting to false
> +			makes the it restore the modem state before the
> +			lockdown and release the modem lock. Only the
> +			application that holds the lock can power up the modem.
> +			If the the application exits Lockdown is set to false.
> +

So me and Marcel discussed this briefly and I think we want to modify
the behavior slightly.  When Lockdown is set to True, the modem should
be brought down to Powered=Off state, and setting the Powered property
should return an error.

When Lockdown is set to False from True, only the lock is lifted.
Powered state still has to be triggered manually.  This should make the
implementation a little simpler.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] Add Lockdown property to Modem interface
  2010-11-23 13:50     ` [PATCH 3/3] Add Lockdown property to Modem interface Denis Kenzior
@ 2010-11-23 17:53       ` Gustavo F. Padovan
  2010-11-23 21:43         ` Denis Kenzior
  0 siblings, 1 reply; 9+ messages in thread
From: Gustavo F. Padovan @ 2010-11-23 17:53 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1977 bytes --]

Hi Denis,

* Denis Kenzior <denkenz@gmail.com> [2010-11-23 07:50:18 -0600]:

> Hi Gustavo,
> 
> On 11/19/2010 03:37 PM, Gustavo F. Padovan wrote:
> > Setting Lockdown to TRUE means power down the modem and hold a lock that
> > only permits the lock's owner power up the modem back. When released
> > it restores the last state of the modem before holding the lock.
> > ---
> >  doc/modem-api.txt |   10 +++++
> >  src/modem.c       |  114 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 124 insertions(+), 0 deletions(-)
> > 
> > diff --git a/doc/modem-api.txt b/doc/modem-api.txt
> > index c48375e..3dd6dde 100644
> > --- a/doc/modem-api.txt
> > +++ b/doc/modem-api.txt
> > @@ -37,6 +37,16 @@ Properties	boolean Powered [readwrite]
> >  			Boolean representing the rf state of the modem.
> >  			Online is false in flight mode.
> >  
> > +		boolean Lockdown [readwrite]
> > +
> > +			Boolean representing the lock state of the modem.
> > +			Setting it to true, makes the calling application hold
> > +			the modem lock and power it down. Setting to false
> > +			makes the it restore the modem state before the
> > +			lockdown and release the modem lock. Only the
> > +			application that holds the lock can power up the modem.
> > +			If the the application exits Lockdown is set to false.
> > +
> 
> So me and Marcel discussed this briefly and I think we want to modify
> the behavior slightly.  When Lockdown is set to True, the modem should
> be brought down to Powered=Off state, and setting the Powered property
> should return an error.

That's what my code does.

> 
> When Lockdown is set to False from True, only the lock is lifted.
> Powered state still has to be triggered manually.  This should make the
> implementation a little simpler.

So this also means that we shall not restore the modem state when
someone set Powered to true?

-- 
Gustavo F. Padovan
http://profusion.mobi

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] Add Lockdown property to Modem interface
  2010-11-23 17:53       ` Gustavo F. Padovan
@ 2010-11-23 21:43         ` Denis Kenzior
  0 siblings, 0 replies; 9+ messages in thread
From: Denis Kenzior @ 2010-11-23 21:43 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1247 bytes --]

Hi Gustavo,

On 11/23/2010 11:53 AM, Gustavo F. Padovan wrote:
>>> +		boolean Lockdown [readwrite]
>>> +
>>> +			Boolean representing the lock state of the modem.
>>> +			Setting it to true, makes the calling application hold
>>> +			the modem lock and power it down. Setting to false
>>> +			makes the it restore the modem state before the
>>> +			lockdown and release the modem lock. Only the
>>> +			application that holds the lock can power up the modem.
>>> +			If the the application exits Lockdown is set to false.
>>> +
>>
>> So me and Marcel discussed this briefly and I think we want to modify
>> the behavior slightly.  When Lockdown is set to True, the modem should
>> be brought down to Powered=Off state, and setting the Powered property
>> should return an error.
> 
> That's what my code does.
> 

Yep.

>>
>> When Lockdown is set to False from True, only the lock is lifted.
>> Powered state still has to be triggered manually.  This should make the
>> implementation a little simpler.
> 
> So this also means that we shall not restore the modem state when
> someone set Powered to true?
> 

No, lets forget doing this for now.  I think it was making things too
complicated.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-11-23 21:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-11-19 21:37 [PATCH 1/3] TODO: Add owner to implement the Lockdown property Gustavo F. Padovan
2010-11-19 21:37 ` [PATCH 2/3] Add __ofono_error_access_denied() Gustavo F. Padovan
2010-11-19 21:37   ` [PATCH 3/3] Add Lockdown property to Modem interface Gustavo F. Padovan
2010-11-19 22:20     ` [PATCH] Add test script for the Lockdown property Gustavo F. Padovan
2010-11-23 13:50     ` [PATCH 3/3] Add Lockdown property to Modem interface Denis Kenzior
2010-11-23 17:53       ` Gustavo F. Padovan
2010-11-23 21:43         ` Denis Kenzior
2010-11-23 11:12   ` [PATCH 2/3] Add __ofono_error_access_denied() Denis Kenzior
2010-11-23 11:05 ` [PATCH 1/3] TODO: Add owner to implement the Lockdown property Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.