Skip to contentSkip to conversation

Writing to /sys/class/rfkill/*/state fails

2.6.31-rc2 In review Corentin Chary 6 participants 10 messages Jul 10, 2009 – Jul 26, 2009 5 messages not in the archive Rfkill

lore
Share & tools
lore
#6 lore raw
In reply to Darren Salt
Quoted 46 lines · Darren Salt

[full quoting for linux-{kernel,wireless} & the perpetrator]

I demand that Thiemo Nagel may or may not have written...

Quoted 28 lines
Quoted 27 lines · Corentin Chary
Quoted 25 lines · Thiemo Nagel
Quoted 9 lines · Corentin Chary
Quoted 7 lines · Thiemo Nagel

I just tested the new GSM rfkill in 2.6.31-rc2 and I get the following on my EeePC 1000HGO:

  eee:/# cat /sys/class/rfkill/rfkill2/name
  eeepc-wwan3g
  eee:/# echo 0 > /sys/class/rfkill/rfkill2/state
  bash: echo: write error: Operation not permitted
What could be the reason for that?
Quoted 12 lines

Reading the kernel source I can find:
        /*
         * The intention was that userspace can only take control over
         * a given device when/if rfkill-input doesn't control it due
         * to user_claim. Since user_claim is currently unsupported,
         * we never support changing the state from userspace -- this
         * can be implemented again later.
         */
It seems that rfkill should be controlled by /dev/rfkill (cf Documentation/rfkill.txt).
Maybe network-manager can control that .. But I'm not sure. Maybe you should CC the wireless mailing list.

Thanks for the quick reply.  The interesting thing is, that the direct access works well for eeepc-wlan and eeepc-bluetooth rfkills.  I've CC'd debian-eeepc-devel, maybe they know something.

Quoted 7 lines
Quoted 5 lines

Are you sure that it works with newer kernels ? This commit should have broken it for all rfkill. commit 19d337dff95cbf76edd3ad95c0cee2732c3e1ec5
  Author: Johannes Berg <[email protected]>
  Date:   Tue Jun 2 13:01:37 2009 +0200

You're right, all rfkills work with 2.6.30, but none works with 2.6.31-rc2.

This is the first that I've heard of this. I'd not noticed since I've not needed Bluetooth on my 901 recently.

Quoted 2 lines

For the debian-eeepc folks:  2.6.31-rc2 breaks bluetooth toggling using eeepc-acpi-scripts, but WLAN toggling still works.

Quoted 8 lines

FSVO "works" (http://bugzilla.kernel.org/show_bug.cgi?id=13390), but that's a different problem.

I consider this a regression. It breaks an interface which, though flawed, is ideally suited for scripting use and which eeepc-acpi-scripts uses in shell scripts.

/dev/rfkill is not useful in shell scripts.

Maybe it would be possible with an rfkill command line tool (in C) ? Is there such a tool somewhere ?

Signature · 2 lines
Corentin Chary
http://xf.iksaif.net - http://uffs.org
#7 lore raw

Hi Corentin,

Quoted 47 lines
Quoted 47 lines

I demand that Thiemo Nagel may or may not have written...

Quoted 28 lines
Quoted 27 lines · Corentin Chary
Quoted 25 lines · Thiemo Nagel
Quoted 9 lines · Corentin Chary
Quoted 7 lines · Thiemo Nagel

I just tested the new GSM rfkill in 2.6.31-rc2 and I get the following on my EeePC 1000HGO:

  eee:/# cat /sys/class/rfkill/rfkill2/name
  eeepc-wwan3g
  eee:/# echo 0 > /sys/class/rfkill/rfkill2/state
  bash: echo: write error: Operation not permitted
What could be the reason for that?
Quoted 12 lines

Reading the kernel source I can find:
/*
* The intention was that userspace can only take control over
* a given device when/if rfkill-input doesn't control it due
* to user_claim. Since user_claim is currently unsupported,
* we never support changing the state from userspace -- this
* can be implemented again later.
*/
It seems that rfkill should be controlled by /dev/rfkill (cf Documentation/rfkill.txt).
Maybe network-manager can control that .. But I'm not sure. Maybe you should CC the wireless mailing list.

Thanks for the quick reply. The interesting thing is, that the direct access works well for eeepc-wlan and eeepc-bluetooth rfkills. I've CC'd debian-eeepc-devel, maybe they know something.

Quoted 7 lines
Quoted 5 lines

Are you sure that it works with newer kernels ? This commit should have broken it for all rfkill.
commit 19d337dff95cbf76edd3ad95c0cee2732c3e1ec5
Author: Johannes Berg <[email protected]>
Date: Tue Jun 2 13:01:37 2009 +0200

You're right, all rfkills work with 2.6.30, but none works with 2.6.31-rc2.

This is the first that I've heard of this. I'd not noticed since I've not needed Bluetooth on my 901 recently.

Quoted 2 lines

For the debian-eeepc folks: 2.6.31-rc2 breaks bluetooth toggling using eeepc-acpi-scripts, but WLAN toggling still works.

FSVO "works" (http://bugzilla.kernel.org/show_bug.cgi?id=13390), but that's a different problem.

Quoted 8 lines
Quoted 5 lines

I consider this a regression. It breaks an interface which, though flawed, is ideally suited for scripting use and which eeepc-acpi-scripts uses in shell scripts.

/dev/rfkill is not useful in shell scripts.

Maybe it would be possible with an rfkill command line tool (in C) ? Is there such a tool somewhere ?

yes there is:

http://git.sipsolutions.net/?p=rfkill.git

Regards

Marcel

#5 lore raw
In reply to a message not in the archive

[full quoting for linux-{kernel,wireless} & the perpetrator]

I demand that Thiemo Nagel may or may not have written...

Quoted 28 lines
Quoted 27 lines · Corentin Chary
Quoted 25 lines · Thiemo Nagel
Quoted 9 lines · Corentin Chary
Quoted 7 lines · Thiemo Nagel

I just tested the new GSM rfkill in 2.6.31-rc2 and I get the following on my EeePC 1000HGO:

  eee:/# cat /sys/class/rfkill/rfkill2/name
  eeepc-wwan3g
  eee:/# echo 0 > /sys/class/rfkill/rfkill2/state
  bash: echo: write error: Operation not permitted
What could be the reason for that?
Quoted 12 lines

Reading the kernel source I can find:
/*
* The intention was that userspace can only take control over
* a given device when/if rfkill-input doesn't control it due
* to user_claim. Since user_claim is currently unsupported,
* we never support changing the state from userspace -- this
* can be implemented again later.
*/
It seems that rfkill should be controlled by /dev/rfkill (cf Documentation/rfkill.txt).
Maybe network-manager can control that .. But I'm not sure. Maybe you should CC the wireless mailing list.

Thanks for the quick reply. The interesting thing is, that the direct access works well for eeepc-wlan and eeepc-bluetooth rfkills. I've CC'd debian-eeepc-devel, maybe they know something.

Quoted 7 lines
Quoted 5 lines

Are you sure that it works with newer kernels ? This commit should have broken it for all rfkill.
commit 19d337dff95cbf76edd3ad95c0cee2732c3e1ec5
Author: Johannes Berg <[email protected]>
Date: Tue Jun 2 13:01:37 2009 +0200

You're right, all rfkills work with 2.6.30, but none works with 2.6.31-rc2.

This is the first that I've heard of this. I'd not noticed since I've not needed Bluetooth on my 901 recently.

Quoted 2 lines

For the debian-eeepc folks: 2.6.31-rc2 breaks bluetooth toggling using eeepc-acpi-scripts, but WLAN toggling still works.

FSVO "works" (http://bugzilla.kernel.org/show_bug.cgi?id=13390), but that's a different problem.

I consider this a regression. It breaks an interface which, though flawed, is ideally suited for scripting use and which eeepc-acpi-scripts uses in shell scripts.

/dev/rfkill is not useful in shell scripts.

Trying to read from it to determine the current state (and only the current state) results in the shell effectively hanging, and parsing is less than trivial. So either we continue to use .../state or eeepc-acpi-scripts needs a complete rewrite of the ACPI event-handling scripts in something other than sh (probably perl) and would need a daemon instead of having scripts launched from acpid (well, that or they'd need a helper binary or two).

Writing to it is doable, though slightly interesting. "echo 1 >/..." is ideal.

We can't just drop support for older kernels ‒ at least, not yet – though fortunately, prior to this breakage, all that we had to cope with were changed file names; the content can be treated identically. We don't have to deal with hard-blocked states, which helps...

Signature · 5 lines
| Darren Salt            | linux at youmustbejoking | nr. Ashington, | Doon
| using Debian GNU/Linux | or ds    ,demon,co,uk    | Northumberland | Army
| + Buy local produce. Try to walk or cycle. TRANSPORT CAUSES GLOBAL WARMING.

Passwords are implemented as a result of insecurity.
maintainer
#8 lore raw

PATCH 1/1 rfkill: allow toggling soft state in sysfs again

Apparently there actually _are_ tools that try to set this in sysfs even though it wasn't supposed to be used this way without claiming first. Guess what: now that I've cleaned it all up it doesn't matter and we can simply allow setting the soft-block state in sysfs.

---
*shrug*, I don't like it, but whatever...

Please test & report.

 net/rfkill/core.c |   27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)
net/rfkill/core.c +19 -8
@@ -648,15 +648,26 @@ static ssize_t rfkill_state_store(struct
 				  struct device_attribute *attr,
 				  const char *buf, size_t count)
 {
-	/*
-	 * The intention was that userspace can only take control over
-	 * a given device when/if rfkill-input doesn't control it due
-	 * to user_claim. Since user_claim is currently unsupported,
-	 * we never support changing the state from userspace -- this
-	 * can be implemented again later.
-	 */
+	struct rfkill *rfkill = to_rfkill(dev);
+	unsigned long state;
+	int err;
+
+	if (!capable(CAP_NET_ADMIN))
+		return -EPERM;
+
+	err = strict_strtoul(buf, 0, &state);
+	if (err)
+		return err;
+
+	if (state != RFKILL_USER_STATE_SOFT_BLOCKED &&
+	    state != RFKILL_USER_STATE_UNBLOCKED)
+		return -EINVAL;
+
+	mutex_lock(&rfkill_global_mutex);
+	rfkill_set_block(rfkill, state == RFKILL_USER_STATE_SOFT_BLOCKED);
+	mutex_unlock(&rfkill_global_mutex);
 
-	return -EPERM;
+	return err ?: count;
 }
 
 static ssize_t rfkill_claim_show(struct device *dev,
Tested-by on v1 1/1
#9 lore raw

Re: [PATCH 2.6.31] rfkill: allow toggling soft state in sysfs again

I demand that Johannes Berg may or may not have written...

Quoted 2 lines

Apparently there actually _are_ tools that try to set this in sysfs even though it wasn't supposed to be used this way without claiming first.

Then it should have been documented as such. I don't see anything about this in Documentation/rfkill.txt (as found in 2.6.30), other than a vague statement that "Kernel handles events", which isn't exactly helpful :-\

Quoted 2 lines

Guess what: now that I've cleaned it all up it doesn't matter and we can simply allow setting the soft-block state in sysfs.

:-)

Quoted 3 lines

---
*shrug*, I don't like it, but whatever...

I do. It means that we have a nice simple text-based interface for use in scripts (for now), and a binary interface which is better suited to the likes of desktop applications.

Quoted 1 line

Please test & report.

With the patch applied, Bluetooth toggling is working again, so you get to add this:

[snip]

Signature · 5 lines
| Darren Salt            | linux at youmustbejoking | nr. Ashington, | Doon
| using Debian GNU/Linux | or ds    ,demon,co,uk    | Northumberland | Army
| + Output *more* particulate pollutants.      BUFFER AGAINST GLOBAL WARMING.

For sale: one complete set of hen's teeth.
maintainer
#10 lore raw

Re: [PATCH 2.6.31] rfkill: allow toggling soft state in sysfs again

Quoted 8 lines · Darren Salt

I demand that Johannes Berg may or may not have written...

Quoted 2 lines

Apparently there actually _are_ tools that try to set this in sysfs even though it wasn't supposed to be used this way without claiming first.

Then it should have been documented as such. I don't see anything about this in Documentation/rfkill.txt (as found in 2.6.30), other than a vague statement that "Kernel handles events", which isn't exactly helpful :-\

Oh, it's not just that rfkill was horrible, the documentation matched :) All the SHOUTING in it about what you must and must not do but nothing actually helpful :)

Quoted 5 lines
Quoted 1 line

*shrug*, I don't like it, but whatever...

I do. It means that we have a nice simple text-based interface for use in scripts (for now), and a binary interface which is better suited to the likes of desktop applications.

Indeed, and as long as you expect to only use soft toggle... problem is that you won't know whether it's soft-toggled or not while it's hard-blocked (off)!

Quoted 6 lines
Quoted 1 line

Please test & report.

With the patch applied, Bluetooth toggling is working again, so you get to add this:

Ok, John, please pick up the patch.

johannes

#11 lore raw

Re: [PATCH 2.6.31] rfkill: allow toggling soft state in sysfs again

I demand that Johannes Berg may or may not have written...

Quoted 2 lines · Darren Salt
Quoted 1 line

I demand that Johannes Berg may or may not have written...

[snip]

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

*shrug*, I don't like it, but whatever...

I do. It means that we have a nice simple text-based interface for use in scripts (for now), and a binary interface which is better suited to the likes of desktop applications.

Indeed, and as long as you expect to only use soft toggle... problem is that you won't know whether it's soft-toggled or not while it's hard-blocked (off)!

Which is fine for eeepc-acpi-scripts and anything else which doesn't care about hard-blocking because the hardware doesn't do that.

eeepc-acpi-scripts should eventually use your rfkill utility, though. (I intend to make sure that it does so.)

[snip]

Signature · 5 lines
| Darren Salt            | linux at youmustbejoking | nr. Ashington, | Doon
| using Debian GNU/Linux | or ds    ,demon,co,uk    | Northumberland | Army
|   Kill all extremists!

A large dog will have a surprising effect on your life.
#12 lore raw

Re: [Acpi4asus-user] [PATCH 2.6.31] rfkill: allow toggling soft state in sysfs again

In reply to Johannes Berg
Quoted 24 lines · Johannes Berg
Quoted 8 lines · Darren Salt

I demand that Johannes Berg may or may not have written...

Quoted 2 lines

Apparently there actually _are_ tools that try to set this in sysfs even though it wasn't supposed to be used this way without claiming first.

Then it should have been documented as such. I don't see anything about this in Documentation/rfkill.txt (as found in 2.6.30), other than a vague statement that "Kernel handles events", which isn't exactly helpful :-\

Oh, it's not just that rfkill was horrible, the documentation matched :) All the SHOUTING in it about what you must and must not do but nothing actually helpful :)

Quoted 5 lines
Quoted 1 line

*shrug*, I don't like it, but whatever...

I do. It means that we have a nice simple text-based interface for use in scripts (for now), and a binary interface which is better suited to the likes of desktop applications.

Indeed, and as long as you expect to only use soft toggle... problem is that you won't know whether it's soft-toggled or not while it's hard-blocked (off)!

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Please test & report.

With the patch applied, Bluetooth toggling is working again, so you get to add this:

Ok, John, please pick up the patch.

Is there anything going on with the patch?

Surely it's not in -rc4.

Rafael

Tested-by Darren Salt
#13 lore raw

Re: [Acpi4asus-user] [PATCH 2.6.31] rfkill: allow toggling soft state in sysfs again

Quoted 30 lines · Rafael J. Wysocki
Quoted 29 lines · Johannes Berg
Quoted 8 lines · Darren Salt

I demand that Johannes Berg may or may not have written...

Quoted 2 lines

Apparently there actually _are_ tools that try to set this in sysfs even though it wasn't supposed to be used this way without claiming first.

Then it should have been documented as such. I don't see anything about this in Documentation/rfkill.txt (as found in 2.6.30), other than a vague statement that "Kernel handles events", which isn't exactly helpful :-\

Oh, it's not just that rfkill was horrible, the documentation matched :) All the SHOUTING in it about what you must and must not do but nothing actually helpful :)

Quoted 5 lines
Quoted 1 line

*shrug*, I don't like it, but whatever...

I do. It means that we have a nice simple text-based interface for use in scripts (for now), and a binary interface which is better suited to the likes of desktop applications.

Indeed, and as long as you expect to only use soft toggle... problem is that you won't know whether it's soft-toggled or not while it's hard-blocked (off)!

Quoted 5 lines
Quoted 1 line

Please test & report.

With the patch applied, Bluetooth toggling is working again, so you get to add this:

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Ok, John, please pick up the patch.

Is there anything going on with the patch?

Surely it's not in -rc4.

commit f54c142725ad2ba33c3ee627873cb6966bf05447

Author: Johannes Berg <[email protected]>
Date:   Fri Jul 10 21:41:39 2009 +0200

rfkill: allow toggling soft state in sysfs again

Apparently there actually _are_ tools that try to set this in sysfs even though it wasn't supposed to be used this way without claiming first. Guess what: now that I've cleaned it all up it doesn't matter and we can simply allow setting the soft-block state in sysfs.

Didn't make -rc4, should be in -rc5.

John

Signature · 3 lines
John W. Linville		Someday the world will need a hero, and you
[email protected]			might be all we have.  Be ready.
			¡Viva Honduras Libre!
#14 lore raw

Re: [Acpi4asus-user] [PATCH 2.6.31] rfkill: allow toggling soft state in sysfs again

Quoted 51 lines · John W. Linville
Quoted 30 lines · Rafael J. Wysocki
Quoted 29 lines · Johannes Berg
Quoted 8 lines · Darren Salt

I demand that Johannes Berg may or may not have written...

Quoted 2 lines

Apparently there actually _are_ tools that try to set this in sysfs even though it wasn't supposed to be used this way without claiming first.

Then it should have been documented as such. I don't see anything about this in Documentation/rfkill.txt (as found in 2.6.30), other than a vague statement that "Kernel handles events", which isn't exactly helpful :-\

Oh, it's not just that rfkill was horrible, the documentation matched :) All the SHOUTING in it about what you must and must not do but nothing actually helpful :)

Quoted 5 lines
Quoted 1 line

*shrug*, I don't like it, but whatever...

I do. It means that we have a nice simple text-based interface for use in scripts (for now), and a binary interface which is better suited to the likes of desktop applications.

Indeed, and as long as you expect to only use soft toggle... problem is that you won't know whether it's soft-toggled or not while it's hard-blocked (off)!

Quoted 5 lines
Quoted 1 line

Please test & report.

With the patch applied, Bluetooth toggling is working again, so you get to add this:

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Ok, John, please pick up the patch.

Is there anything going on with the patch?

Surely it's not in -rc4.

commit f54c142725ad2ba33c3ee627873cb6966bf05447

Author: Johannes Berg <[email protected]>
Date:   Fri Jul 10 21:41:39 2009 +0200

rfkill: allow toggling soft state in sysfs again

Apparently there actually _are_ tools that try to set this in sysfs even though it wasn't supposed to be used this way without claiming first. Guess what: now that I've cleaned it all up it doesn't matter and we can simply allow setting the soft-block state in sysfs.

Quoted 5 lines

Didn't make -rc4, should be in -rc5.

Great, thanks!

Best,
Rafael