* [PATCH] allow setting wiphy.perm_addr after driver probe
@ 2014-08-11 18:04 Daniel Gimpelevich
2014-08-11 20:25 ` Marcel Holtmann
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Gimpelevich @ 2014-08-11 18:04 UTC (permalink / raw)
To: John W. Linville
Cc: linux-wireless, Johannes Berg, David S. Miller, netdev,
linux-kernel
On embedded devices, often the BSSID of an access point must be set from
userspace during the boot process. This provides a relatively clean way
of doing that without major side effects.
Signed-off-by: Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us>
---
--- a/net/wireless/sysfs.c 2014-04-19 08:36:52.048511623 -0700
+++ b/net/wireless/sysfs.c 2014-04-19 08:38:09.196894176 -0700
@@ -24,18 +24,30 @@
return container_of(dev, struct cfg80211_registered_device, wiphy.dev);
}
-#define SHOW_FMT(name, fmt, member) \
+#define SHOW_FMT(name, fmt, member, perm) \
static ssize_t name ## _show(struct device *dev, \
struct device_attribute *attr, \
char *buf) \
{ \
return sprintf(buf, fmt "\n", dev_to_rdev(dev)->member); \
} \
-static DEVICE_ATTR_RO(name)
+static DEVICE_ATTR_ ## perm(name)
-SHOW_FMT(index, "%d", wiphy_idx);
-SHOW_FMT(macaddress, "%pM", wiphy.perm_addr);
-SHOW_FMT(address_mask, "%pM", wiphy.addr_mask);
+static ssize_t macaddress_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ u8 temp[ETH_ALEN];
+
+ if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", temp, temp + 1,
+ temp + 2, temp + 3, temp + 4, temp + 5) == ETH_ALEN)
+ memcpy(dev_to_rdev(dev)->wiphy.perm_addr, temp, ETH_ALEN);
+ return count;
+}
+
+SHOW_FMT(index, "%d", wiphy_idx, RO);
+SHOW_FMT(macaddress, "%pM", wiphy.perm_addr, RW);
+SHOW_FMT(address_mask, "%pM", wiphy.addr_mask, RO);
static ssize_t name_show(struct device *dev,
struct device_attribute *attr,
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] allow setting wiphy.perm_addr after driver probe
2014-08-11 18:04 [PATCH] allow setting wiphy.perm_addr after driver probe Daniel Gimpelevich
@ 2014-08-11 20:25 ` Marcel Holtmann
2014-08-11 20:40 ` Daniel Gimpelevich
0 siblings, 1 reply; 11+ messages in thread
From: Marcel Holtmann @ 2014-08-11 20:25 UTC (permalink / raw)
To: Daniel Gimpelevich
Cc: John W. Linville, linux-wireless@vger.kernel.org Wireless,
Johannes Berg, David S. Miller, Network Development, linux-kernel
Hi Daniel,
> On embedded devices, often the BSSID of an access point must be set from
> userspace during the boot process. This provides a relatively clean way
> of doing that without major side effects.
>
> Signed-off-by: Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us>
> ---
> --- a/net/wireless/sysfs.c 2014-04-19 08:36:52.048511623 -0700
> +++ b/net/wireless/sysfs.c 2014-04-19 08:38:09.196894176 -0700
> @@ -24,18 +24,30 @@
> return container_of(dev, struct cfg80211_registered_device, wiphy.dev);
> }
>
> -#define SHOW_FMT(name, fmt, member) \
> +#define SHOW_FMT(name, fmt, member, perm) \
> static ssize_t name ## _show(struct device *dev, \
> struct device_attribute *attr, \
> char *buf) \
> { \
> return sprintf(buf, fmt "\n", dev_to_rdev(dev)->member); \
> } \
> -static DEVICE_ATTR_RO(name)
> +static DEVICE_ATTR_ ## perm(name)
>
> -SHOW_FMT(index, "%d", wiphy_idx);
> -SHOW_FMT(macaddress, "%pM", wiphy.perm_addr);
> -SHOW_FMT(address_mask, "%pM", wiphy.addr_mask);
> +static ssize_t macaddress_store(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t count)
> +{
> + u8 temp[ETH_ALEN];
> +
> + if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", temp, temp + 1,
> + temp + 2, temp + 3, temp + 4, temp + 5) == ETH_ALEN)
> + memcpy(dev_to_rdev(dev)->wiphy.perm_addr, temp, ETH_ALEN);
> + return count;
> +}
> +
> +SHOW_FMT(index, "%d", wiphy_idx, RO);
> +SHOW_FMT(macaddress, "%pM", wiphy.perm_addr, RW);
> +SHOW_FMT(address_mask, "%pM", wiphy.addr_mask, RO);
isn't this dangerous to just allow writing to wiphy.perm_addr via sysfs. We ran into the same issue with Bluetooth and ROM only devices that have to unique address. Doing this via sysfs seems the wrong approach. It is messy and full of potential race conditions. I clearly opted against the sysfs solution for Bluetooth. Instead we build an infrastructure that allowed doing it cleanly via the Bluetooth mgmt API. Controllers that have no unique address are brought up as unconfigured and userspace clearly knows that it has to take steps to get an address programmed into the controller.
And I think something similar should be done for WiFi. It might be better to not create the initial wlan0 netdev interface if the hardware has not a single unique address available. That way the supplicant can just either get one from the flash filesystem or make up a proper random one before creating the netdev interface.
Regards
Marcel
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH] allow setting wiphy.perm_addr after driver probe
2014-08-11 20:25 ` Marcel Holtmann
@ 2014-08-11 20:40 ` Daniel Gimpelevich
2014-08-11 20:56 ` Marcel Holtmann
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Gimpelevich @ 2014-08-11 20:40 UTC (permalink / raw)
To: Marcel Holtmann
Cc: John W. Linville, linux-wireless@vger.kernel.org Wireless,
Johannes Berg, David S. Miller, Network Development, linux-kernel
On Mon, 2014-08-11 at 13:25 -0700, Marcel Holtmann wrote:
> isn't this dangerous to just allow writing to wiphy.perm_addr via
> sysfs. We ran into the same issue with Bluetooth and ROM only devices
> that have to unique address. Doing this via sysfs seems the wrong
> approach. It is messy and full of potential race conditions. I clearly
> opted against the sysfs solution for Bluetooth. Instead we build an
> infrastructure that allowed doing it cleanly via the Bluetooth mgmt
> API. Controllers that have no unique address are brought up as
> unconfigured and userspace clearly knows that it has to take steps to
> get an address programmed into the controller.
My inclination is to agree; however, this does not exist for WiFi and
implementing it would require modifying every single driver.
> And I think something similar should be done for WiFi. It might be
> better to not create the initial wlan0 netdev interface if the
> hardware has not a single unique address available. That way the
> supplicant can just either get one from the flash filesystem or make
> up a proper random one before creating the netdev interface.
>
The initial wlan0 netdev interface is *not* created, but the PHY records
a MAC address that cannot be overriden at the level that this sysfs node
reads. Perhaps a compromise would be to create a single new syscall to
write to it?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] allow setting wiphy.perm_addr after driver probe
2014-08-11 20:40 ` Daniel Gimpelevich
@ 2014-08-11 20:56 ` Marcel Holtmann
2014-08-11 21:04 ` Daniel Gimpelevich
0 siblings, 1 reply; 11+ messages in thread
From: Marcel Holtmann @ 2014-08-11 20:56 UTC (permalink / raw)
To: Daniel Gimpelevich
Cc: John W. Linville, linux-wireless@vger.kernel.org Wireless,
Johannes Berg, David S. Miller, Network Development, linux-kernel
Hi Daniel,
>> isn't this dangerous to just allow writing to wiphy.perm_addr via
>> sysfs. We ran into the same issue with Bluetooth and ROM only devices
>> that have to unique address. Doing this via sysfs seems the wrong
>> approach. It is messy and full of potential race conditions. I clearly
>> opted against the sysfs solution for Bluetooth. Instead we build an
>> infrastructure that allowed doing it cleanly via the Bluetooth mgmt
>> API. Controllers that have no unique address are brought up as
>> unconfigured and userspace clearly knows that it has to take steps to
>> get an address programmed into the controller.
>
> My inclination is to agree; however, this does not exist for WiFi and
> implementing it would require modifying every single driver.
so what? That is not a reason to just hack something into sysfs. If it means every driver needs to be modified, then that has to be done.
>> And I think something similar should be done for WiFi. It might be
>> better to not create the initial wlan0 netdev interface if the
>> hardware has not a single unique address available. That way the
>> supplicant can just either get one from the flash filesystem or make
>> up a proper random one before creating the netdev interface.
>>
> The initial wlan0 netdev interface is *not* created, but the PHY records
> a MAC address that cannot be overriden at the level that this sysfs node
> reads. Perhaps a compromise would be to create a single new syscall to
> write to it?
The initial wlan0 can be removed as every other netdev attached to the wiphy. It can also be as easily re-created.
Since the wiphy does not have a valid MAC address, my proposal here would be to just not create the wlan0 in the first place. This means that the wiphy can be still discovered via nl80211.
It also means that the wlan0 netdev needs to be created by userspace now. And a valid NL80211_ATTR_MAC be provided. Similar to what is already done for P2P devices at the moment. That should just solve the problem.
We really do not want to announce a netdev when registering the wiphy device and then having to mess with its MAC address via sysfs somehow. This all needs to be properly reflected over RTNL.
Regards
Marcel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] allow setting wiphy.perm_addr after driver probe
2014-08-11 20:56 ` Marcel Holtmann
@ 2014-08-11 21:04 ` Daniel Gimpelevich
2014-08-11 22:41 ` Marcel Holtmann
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Gimpelevich @ 2014-08-11 21:04 UTC (permalink / raw)
To: Marcel Holtmann
Cc: John W. Linville, linux-wireless@vger.kernel.org Wireless,
Johannes Berg, David S. Miller, Network Development, linux-kernel
On Mon, 2014-08-11 at 13:56 -0700, Marcel Holtmann wrote:
> The initial wlan0 can be removed as every other netdev attached to the
> wiphy. It can also be as easily re-created.
>
> Since the wiphy does not have a valid MAC address, my proposal here
> would be to just not create the wlan0 in the first place. This means
> that the wiphy can be still discovered via nl80211.
I repeat, currently wlan0 is *not* created.
> It also means that the wlan0 netdev needs to be created by userspace
> now. And a valid NL80211_ATTR_MAC be provided. Similar to what is
> already done for P2P devices at the moment. That should just solve the
> problem.
The creation of wlan0 already comes from userspace, but the PHY has its
own MAC.
> We really do not want to announce a netdev when registering the wiphy
> device and then having to mess with its MAC address via sysfs somehow.
> This all needs to be properly reflected over RTNL.
>
Again, no netdev is announced. There just isn't a way to set the MAC of
the wiphy device itself.
How about this: What if the driver were to leave the MAC at all zeros
initially, and sysfs could set that if and only if it's all zeros at the
time?
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] allow setting wiphy.perm_addr after driver probe
2014-08-11 21:04 ` Daniel Gimpelevich
@ 2014-08-11 22:41 ` Marcel Holtmann
2014-08-11 23:12 ` Daniel Gimpelevich
0 siblings, 1 reply; 11+ messages in thread
From: Marcel Holtmann @ 2014-08-11 22:41 UTC (permalink / raw)
To: Daniel Gimpelevich
Cc: John W. Linville, linux-wireless@vger.kernel.org Wireless,
Johannes Berg, David S. Miller, Network Development, linux-kernel
Hi Daniel,
>> The initial wlan0 can be removed as every other netdev attached to the
>> wiphy. It can also be as easily re-created.
>>
>> Since the wiphy does not have a valid MAC address, my proposal here
>> would be to just not create the wlan0 in the first place. This means
>> that the wiphy can be still discovered via nl80211.
>
> I repeat, currently wlan0 is *not* created.
what kind of hardware are you actually using here?
>> It also means that the wlan0 netdev needs to be created by userspace
>> now. And a valid NL80211_ATTR_MAC be provided. Similar to what is
>> already done for P2P devices at the moment. That should just solve the
>> problem.
>
> The creation of wlan0 already comes from userspace, but the PHY has its
> own MAC.
>
>> We really do not want to announce a netdev when registering the wiphy
>> device and then having to mess with its MAC address via sysfs somehow.
>> This all needs to be properly reflected over RTNL.
>>
> Again, no netdev is announced. There just isn't a way to set the MAC of
> the wiphy device itself.
>
> How about this: What if the driver were to leave the MAC at all zeros
> initially, and sysfs could set that if and only if it's all zeros at the
> time?
Internally it might do that, but I do not see it exposing the NL80211_ATTR_MAC when you get the attributes for wiphy.
So I am still saying that when you do NL80211_CMD_NEW_INTERFACE allow providing NL80211_ATTR_MAC to set the MAC address to be used. It might be useful that the wiphy exposes an attribute saying that it does not have a default MAC address, but that should be it. I do not like these magic 00:00:00:00:00:00 games. As I mentioned earlier, in Bluetooth we just deal with allowing the driver to set a flag that it does not have a valid address. And then the core takes care of dealing with it.
Regards
Marcel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] allow setting wiphy.perm_addr after driver probe
2014-08-11 22:41 ` Marcel Holtmann
@ 2014-08-11 23:12 ` Daniel Gimpelevich
2014-08-11 23:56 ` Marcel Holtmann
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Gimpelevich @ 2014-08-11 23:12 UTC (permalink / raw)
To: Marcel Holtmann
Cc: John W. Linville, linux-wireless@vger.kernel.org Wireless,
Johannes Berg, David S. Miller, Network Development, linux-kernel
On Mon, 2014-08-11 at 15:41 -0700, Marcel Holtmann wrote:
> what kind of hardware are you actually using here?
>
It's ath9k on MIPS under OpenWrt.
>
> Internally it might do that, but I do not see it exposing the
> NL80211_ATTR_MAC when you get the attributes for wiphy.
When wlan0 is created, it can be created with its own MAC irrespective
of the wiphy MAC. In OpenWrt, the wlan0 MAC can be supplied and assigned
to a netdev created on a specific wiphy identified by its MAC, and if
that cannot be predicted, there is no wlan0.
> So I am still saying that when you do NL80211_CMD_NEW_INTERFACE allow
> providing NL80211_ATTR_MAC to set the MAC address to be used. It might
> be useful that the wiphy exposes an attribute saying that it does not
> have a default MAC address, but that should be it. I do not like these
> magic 00:00:00:00:00:00 games. As I mentioned earlier, in Bluetooth we
> just deal with allowing the driver to set a flag that it does not have
> a valid address. And then the core takes care of dealing with it.
>
An attribute saying there is no default MAC is helpful only if there is
a way to supply a new default to the wiphy.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH] allow setting wiphy.perm_addr after driver probe
2014-08-11 23:12 ` Daniel Gimpelevich
@ 2014-08-11 23:56 ` Marcel Holtmann
[not found] ` <52896C9C-8560-4CE4-A1FB-C896D766EC87-kz+m5ild9QBg9hUCZPvPmw@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Marcel Holtmann @ 2014-08-11 23:56 UTC (permalink / raw)
To: Daniel Gimpelevich
Cc: John W. Linville, linux-wireless@vger.kernel.org Wireless,
Johannes Berg, David S. Miller, Network Development, linux-kernel
Hi Daniel,
>> Internally it might do that, but I do not see it exposing the
>> NL80211_ATTR_MAC when you get the attributes for wiphy.
>
> When wlan0 is created, it can be created with its own MAC irrespective
> of the wiphy MAC. In OpenWrt, the wlan0 MAC can be supplied and assigned
> to a netdev created on a specific wiphy identified by its MAC, and if
> that cannot be predicted, there is no wlan0.
the way I read the nl80211 code is that the NL80211_CMD_NEW_INTERFACE requires a wiphy device to be specified. And that is actually just a number. So I have no idea what the MAC has to here.
>> So I am still saying that when you do NL80211_CMD_NEW_INTERFACE allow
>> providing NL80211_ATTR_MAC to set the MAC address to be used. It might
>> be useful that the wiphy exposes an attribute saying that it does not
>> have a default MAC address, but that should be it. I do not like these
>> magic 00:00:00:00:00:00 games. As I mentioned earlier, in Bluetooth we
>> just deal with allowing the driver to set a flag that it does not have
>> a valid address. And then the core takes care of dealing with it.
>>
> An attribute saying there is no default MAC is helpful only if there is
> a way to supply a new default to the wiphy.
Why does the wiphy need to know the MAC if it is always specified from userspace when actually creating the new netdev interface. Works for P2P devices, so why wouldn't it work for access point and station mode?
Regards
Marcel
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2014-08-12 8:43 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-08-11 18:04 [PATCH] allow setting wiphy.perm_addr after driver probe Daniel Gimpelevich
2014-08-11 20:25 ` Marcel Holtmann
2014-08-11 20:40 ` Daniel Gimpelevich
2014-08-11 20:56 ` Marcel Holtmann
2014-08-11 21:04 ` Daniel Gimpelevich
2014-08-11 22:41 ` Marcel Holtmann
2014-08-11 23:12 ` Daniel Gimpelevich
2014-08-11 23:56 ` Marcel Holtmann
[not found] ` <52896C9C-8560-4CE4-A1FB-C896D766EC87-kz+m5ild9QBg9hUCZPvPmw@public.gmane.org>
2014-08-12 0:01 ` Daniel Gimpelevich
2014-08-12 7:59 ` Marcel Holtmann
[not found] ` <70001DBA-E1CE-49D6-9A37-6F7CE31B61E6-kz+m5ild9QBg9hUCZPvPmw@public.gmane.org>
2014-08-12 8:43 ` Jonas Gorski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).