Add rfkill plugin
PATCH 1/1 Add rfkill plugin
The plugin allows us to restore the previous power state on adapters when the killswitch on them has been unblocked.
Otherwise we end up with the adapter disabled when coming back from a soft killswitch.
Cheers
Quoted 1 line
From
bf8b7c07542bd7acb4f9f98ba2165475f0ad9d65Mon Sep 17 00:00:00 2001
From: Bastien Nocera <[email protected]>
Date: Tue, 28 Jul 2009 17:25:34 +0100
Subject: [PATCH] Add rfkill plugin
The plugin allows us to restore the previous power state on adapters when the killswitch on them has been unblocked.
--- plugins/Makefile.am | 3 + plugins/rfkill.c | 199 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/adapter.c | 23 ++++-- src/adapter.h | 1 + 4 files changed, 219 insertions(+), 7 deletions(-) create mode 100644 plugins/rfkill.c
plugins/Makefile.am +3 -0
@@ -15,6 +15,9 @@ endif builtin_modules += hciops builtin_sources += hciops.c +builtin_modules += rfkill +builtin_sources += rfkill.c + if NETLINK plugin_LTLIBRARIES += netlink.la netlink_la_LIBADD = @NETLINK_LIBS@
plugins/rfkill.c new file +199 -0
199 lines not on this page · raw message
src/adapter.c +16 -7
@@ -483,21 +483,30 @@ done:return 0 ; } -static DBusMessage *set_powered (DBusConnection *conn,DBusMessage *msg, -gboolean powered,void *data) +int adapter_set_powered (struct btd_adapter *adapter,gboolean powered) { -struct btd_adapter *adapter = data;uint8_t mode; -int err; mode = powered ?get_mode (&adapter->bdaddr,"on" ) :MODE_OFF ;if (mode == adapter->mode) -return dbus_message_new_method_return (msg); +return -EALREADY ; - err =set_mode (adapter, mode); -if (err <0 ) +return set_mode (adapter, mode); +} + +static DBusMessage *set_powered (DBusConnection *conn,DBusMessage *msg, +gboolean powered,void *data) +{ +struct btd_adapter *adapter = data; +int err; + + err =adapter_set_powered (adapter, powered); +if (err <0 ) { +if (err == -EALREADY ) +return dbus_message_new_method_return (msg);return failed_strerror (msg, -err); + }return dbus_message_new_method_return (msg); }
src/adapter.h +1 -0
@@ -110,6 +110,7 @@ void adapter_get_address(struct btd_adapter *adapter, bdaddr_t *bdaddr);void adapter_set_state (struct btd_adapter *adapter,int state);int adapter_get_state (struct btd_adapter *adapter);gboolean adapter_is_ready (struct btd_adapter *adapter); +int adapter_set_powered (struct btd_adapter *adapter,gboolean powered);struct remote_dev_info *adapter_search_found_devices (struct btd_adapter *adapter,struct remote_dev_info *match); void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
Signature · 1 line
1.6.2.5
Marcel Holtmann
maintainerHi Bastien,
Quoted 5 lines
The plugin allows us to restore the previous power state on adapters when the killswitch on them has been unblocked.
Otherwise we end up with the adapter disabled when coming back from a soft killswitch.
I think that having this as a plugin is overkill. I would just integrate this as src/rfkill.c. Especially since it has no dependencies.
Regards
Marcel
Quoted 10 lines · Marcel Holtmann
Hi Bastien,
Quoted 5 lines
The plugin allows us to restore the previous power state on adapters when the killswitch on them has been unblocked.
Otherwise we end up with the adapter disabled when coming back from a soft killswitch.
I think that having this as a plugin is overkill. I would just integrate this as
src/rfkill.c. Especially since it has no dependencies.
It would mean it's harder to change its behaviour. Surely, it would make more sense for this to be a plugin than for HCI operations to be.
Given that you don't use an object system with typing, it's probably one or 2 function calls off. To me, it makes sense to have parts of the core as plugins if it means that the core is leaner because of it.
Marcel Holtmann
maintainerHi Bastien,
Quoted 11 lines
Quoted 8 lines
Quoted 5 lines
The plugin allows us to restore the previous power state on adapters when the killswitch on them has been unblocked.
Otherwise we end up with the adapter disabled when coming back from a soft killswitch.
I think that having this as a plugin is overkill. I would just integrate this as
src/rfkill.c. Especially since it has no dependencies.It would mean it's harder to change its behaviour. Surely, it would make more sense for this to be a plugin than for HCI operations to be.
the HCI operation are becoming/are a plugin, because we wanna switch to netlink in the long term. However to do this, we need to separate them first.
Quoted 3 lines
Given that you don't use an object system with typing, it's probably one or 2 function calls off. To me, it makes sense to have parts of the core as plugins if it means that the core is leaner because of it.
Okay. Since we have built-in plugins, it makes no big difference.
Regards
Marcel
Quoted 5 lines · Bastien Nocera
The plugin allows us to restore the previous power state on adapters when the killswitch on them has been unblocked.
Otherwise we end up with the adapter disabled when coming back from a soft killswitch.
Just a note that __u32 causes failures with newer GCCs (not sure why), using uint32_t instead fixes the problem.
I'll send another patch when this one gets committed.
Marcel Holtmann
maintainerHi Bastien,
Quoted 10 lines
Quoted 5 lines
The plugin allows us to restore the previous power state on adapters when the killswitch on them has been unblocked.
Otherwise we end up with the adapter disabled when coming back from a soft killswitch.
Just a note that
__u32causes failures with newer GCCs (not sure why), usinguint32_tinstead fixes the problem.I'll send another patch when this one gets committed.
I didn't commit this patch, because it should be part of bluetoothd and not a plugin and as I mentioned before honor the RememberPowered setting for system where other entities control that.
However I did push a RFKILL skeleton that that all the lifting except bringing the adapter up. Hijacking the set_powered D-Bus command is the wrong approach. We need a properly exported adapter_up() function for this.
Regards
Marcel
Quoted 8 lines · Marcel Holtmann
Hi Bastien,
Quoted 6 lines
Quoted 5 lines
The plugin allows us to restore the previous power state on adapters when the killswitch on them has been unblocked.
Otherwise we end up with the adapter disabled when coming back from a soft killswitch.
Quoted 7 lines
Quoted 4 lines
Just a note that
__u32causes failures with newer GCCs (not sure why), usinguint32_tinstead fixes the problem.I'll send another patch when this one gets committed.
I didn't commit this patch, because it should be part of bluetoothd and not a plugin
You said you didn't mind:
http://thread.gmane.org/gmane.linux.bluez.kernel/2981/focus=2986
Quoted 4 lines
Okay. Since we have built-in plugins, it makes no big difference.
and as I mentioned before honor the RememberPowered setting for system where other entities control that.
That's what that does:
+ if (main_opts.remember_powered == FALSE)
+ return 0;
Quoted 2 lines
However I did push a RFKILL skeleton that that all the lifting except bringing the adapter up.
Which is pretty much the same as the code I sent, and the code in connman. What's the point of putting this in the core when it does the exact same as the plugin save for a level of indirection?
Quoted 3 lines
Hijacking the
set_poweredD-Bus command is the
wrong approach. We need a properly exportedadapter_up()function for this.
I believe I tried exporting adapter_up() but it didn't work.
Marcel Holtmann
maintainerHi Bastien,
Quoted 25 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
The plugin allows us to restore the previous power state on adapters when the killswitch on them has been unblocked.
Otherwise we end up with the adapter disabled when coming back from a soft killswitch.
Quoted 7 lines
Quoted 4 lines
Just a note that
__u32causes failures with newer GCCs (not sure why), usinguint32_tinstead fixes the problem.I'll send another patch when this one gets committed.
I didn't commit this patch, because it should be part of bluetoothd and not a plugin
You said you didn't mind:
http://thread.gmane.org/gmane.linux.bluez.kernel/2981/focus=2986Quoted 4 lines
Okay. Since we have built-in plugins, it makes no big difference.
and as I mentioned before honor the RememberPowered setting for system where other entities control that.
That's what that does:
(quoted diff) +2
-0+ if (main_opts.remember_powered == FALSE) + return 0;
Quoted 6 lines
Quoted 2 lines
However I did push a RFKILL skeleton that that all the lifting except bringing the adapter up.
Which is pretty much the same as the code I sent, and the code in connman. What's the point of putting this in the core when it does the exact same as the plugin save for a level of indirection?
I changed my mind, because of the main_opts. We don't wanna export the options in the long term. So using src/rfkill.c seems more logical at this point of time.
Quoted 5 lines
Quoted 3 lines
Hijacking the
set_poweredD-Bus command is the
wrong approach. We need a properly exportedadapter_up()function for this.I believe I tried exporting
adapter_up()but it didn't work.
Johan, Luiz, any reason why this would not work. What needs to be done to bring up the adapter. Besides calling the ioctl() directly which we don't wanna do anymore.
Regards
Marcel
Quoted 30 lines · Marcel Holtmann
Hi Bastien,
Quoted 28 lines
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
The plugin allows us to restore the previous power state on adapters when the killswitch on them has been unblocked.
Otherwise we end up with the adapter disabled when coming back from a soft killswitch.
Quoted 7 lines
Quoted 4 lines
Just a note that
__u32causes failures with newer GCCs (not sure why), usinguint32_tinstead fixes the problem.I'll send another patch when this one gets committed.
I didn't commit this patch, because it should be part of bluetoothd and not a plugin
You said you didn't mind:
http://thread.gmane.org/gmane.linux.bluez.kernel/2981/focus=2986Quoted 4 lines
Okay. Since we have built-in plugins, it makes no big difference.
and as I mentioned before honor the RememberPowered setting for system where other entities control that.
That's what that does:
(quoted diff) +2
-0+ if (main_opts.remember_powered == FALSE) + return 0;Quoted 3 lines
However I did push a RFKILL skeleton that that all the lifting except bringing the adapter up.
Quoted 7 lines
Quoted 3 lines
Which is pretty much the same as the code I sent, and the code in connman. What's the point of putting this in the core when it does the exact same as the plugin save for a level of indirection?
I changed my mind, because of the
main_opts. We don't wanna export the options in the long term. So usingsrc/rfkill.cseems more logical at this point of time.
We could have exported some of the settings through manager_get_*(), for example manager_get_remember_powered(), for use by plugins.
The point is moot now anyway.
Hi Marcel,
Quoted 9 lines · Marcel Holtmann
Quoted 5 lines
Quoted 3 lines
Hijacking the
set_poweredD-Bus command is the
wrong approach. We need a properly exportedadapter_up()function for this.I believe I tried exporting
adapter_up()but it didn't work.Johan, Luiz, any reason why this would not work. What needs to be done to bring up the adapter. Besides calling the
ioctl()directly which we don't wanna do anymore.
adapter_up() is more of a callback that's responsible for doing the necessary initializations *after* adapter has just gone up, so it's not the right function to call when you want to bring it up (i.e. call the ioctl). I believe all code paths for bringing the adapter up call set_mode in src/adapter.c which in turn calls adapter_ops->set_powered (which calls the ioctl in the case of hciops).
So having a btd_adapter_set_powered exported to plugins (which is what Bastien's patch seems to do) makes sense to me in this case. I might actually need something similar for maemo in order to handle our offline mode better (maemo specific plugin to catch the MCE offline mode signal and then call btd_adapter_set_powered).
Johan
Quoted 20 lines · Johan Hedberg
Hi Marcel,
Quoted 9 lines · Marcel Holtmann
Quoted 5 lines
Quoted 3 lines
Hijacking the
set_poweredD-Bus command is the
wrong approach. We need a properly exportedadapter_up()function for this.I believe I tried exporting
adapter_up()but it didn't work.Johan, Luiz, any reason why this would not work. What needs to be done to bring up the adapter. Besides calling the
ioctl()directly which we don't wanna do anymore.
adapter_up()is more of a callback that's responsible for doing the necessary initializations *after* adapter has just gone up, so it's not the right function to call when you want to bring it up (i.e. call the ioctl). I believe all code paths for bringing the adapter up callset_modeinsrc/adapter.cwhich in turn callsadapter_ops->set_powered(which calls the ioctl in the case of hciops).
Quoted 5 lines
So having a
btd_adapter_set_poweredexported to plugins (which is what Bastien's patch seems to do) makes sense to me in this case. I might actually need something similar for maemo in order to handle our offline mode better (maemo specific plugin to catch the MCE offline mode signal and then callbtd_adapter_set_powered).
Hence why it would probably be a good thing to have as a plugin :)
Luiz Augusto von Dentz
maintainerHi,
On Wed, Jul 29, 2009 at 6:44 PM, Johan Hedberg<[email protected]> wro= te:
Quoted 4 lines
adapter_up()is more of a callback that's responsible for doing the necessary initializations *after* adapter has just gone up, so it's not the right function to call when you want to bring it up (i.e. call the ioctl). I believe all code paths for bringing the adapter up call set_mod=
e
Quoted 1 line
in
src/adapter.cwhich in turn callsadapter_ops->set_powered(which call=
s
Quoted 7 lines
the ioctl in the case of hciops).
So having a
btd_adapter_set_poweredexported to plugins (which is what Bastien's patch seems to do) makes sense to me in this case. I might actually need something similar for maemo in order to handle our offline mode better (maemo specific plugin to catch the MCE offline mode signal and then callbtd_adapter_set_powered).
Yep, sounds good to me too, plugins can have references to adapters so I guess this is perfectly fine. Also I don't think there is much to be protected here since powered property is readwrite and can be changed by any dbus client. This also makes me wonder what is the purpose of rfkill when we can anyone can set powered directly?
--=20
Luiz Augusto von Dentz
Engenheiro de Computa=E7=E3o
Marcel Holtmann
maintainerHi Luiz,
Quoted 13 lines
Quoted 7 lines
adapter_up()is more of a callback that's responsible for doing the necessary initializations *after* adapter has just gone up, so it's not the right function to call when you want to bring it up (i.e. call the ioctl). I believe all code paths for bringing the adapter up callset_modeinsrc/adapter.cwhich in turn callsadapter_ops->set_powered(which calls the ioctl in the case of hciops).Quoted 5 lines
So having a
btd_adapter_set_poweredexported to plugins (which is what Bastien's patch seems to do) makes sense to me in this case. I might actually need something similar for maemo in order to handle our offline mode better (maemo specific plugin to catch the MCE offline mode signal and then callbtd_adapter_set_powered).
Quoted 5 lines
Yep, sounds good to me too, plugins can have references to adapters so I guess this is perfectly fine. Also I don't think there is much to be protected here since powered property is readwrite and can be changed by any dbus client. This also makes me wonder what is the purpose of rfkill when we can anyone can set powered directly?
if it is rfkilled, then hciconfig hci0 up will return -ERFKILL. We fixed this for the 2.6.31 kernel. WiFi behaves the same now. So you can't just go ahead and bring it up again, you do have to unblock it. And you can only unblock softkilled devices. If it is hardkilled via a hardware switch for example, there is nothing you can do to bring it back up except flipping the hardware switch.
Regards
Marcel
Marcel Holtmann
maintainerHi Johan,
Quoted 17 lines
Quoted 9 lines
Quoted 5 lines
Quoted 3 lines
Hijacking the
set_poweredD-Bus command is the
wrong approach. We need a properly exportedadapter_up()function for this.I believe I tried exporting
adapter_up()but it didn't work.Johan, Luiz, any reason why this would not work. What needs to be done to bring up the adapter. Besides calling the
ioctl()directly which we don't wanna do anymore.
adapter_up()is more of a callback that's responsible for doing the necessary initializations *after* adapter has just gone up, so it's not the right function to call when you want to bring it up (i.e. call the ioctl). I believe all code paths for bringing the adapter up callset_modeinsrc/adapter.cwhich in turn callsadapter_ops->set_powered(which calls the ioctl in the case of hciops).
Quoted 5 lines
So having a
btd_adapter_set_poweredexported to plugins (which is what Bastien's patch seems to do) makes sense to me in this case. I might actually need something similar for maemo in order to handle our offline mode better (maemo specific plugin to catch the MCE offline mode signal and then callbtd_adapter_set_powered).
then I leave this with you to export that function correctly. It should be a separate patch anyway.
I would disagree with the MCE offline handling as a plugin. First off all, why is it not integrated into RFKILL. Second off all, it could just use RFKILL or RememberPowered=false and change Powered by itself. The listening to offline signal is the wrong design.
Regards
Marcel
Hi Marcel,
Quoted 8 lines · Marcel Holtmann
Quoted 5 lines
So having a
btd_adapter_set_poweredexported to plugins (which is what Bastien's patch seems to do) makes sense to me in this case. I might actually need something similar for maemo in order to handle our offline mode better (maemo specific plugin to catch the MCE offline mode signal and then callbtd_adapter_set_powered).then I leave this with you to export that function correctly. It should be a separate patch anyway.
Ok. Maybe Bastien can split this out from his original patch? Note that the function should probably have the btd_ prefix since the idea has been that only functions like that get exported to plugins (not sure if it's actually enforced yet though).
Quoted 4 lines
I would disagree with the MCE offline handling as a plugin. First off all, why is it not integrated into RFKILL. Second off all, it could just use RFKILL or RememberPowered=false and change Powered by itself. The listening to offline signal is the wrong design.
You're probably right, however this is what I have to live with in the current maemo version. I've added David to CC so he can comment on the possibility of replacing MCE offline/normal mode signals with rfkill in the future.
Johan