From: Dan Williams <dcbw@redhat.com>
To: Luis Carlos Cobo <luisca@cozybit.com>
Cc: linux-wireless@vger.kernel.org, johannes@sipsolutions.net
Subject: Re: [PATCH 1/6] mac80211: allow no mac address until firmware load
Date: Sun, 27 Jul 2008 11:22:16 -0400 [thread overview]
Message-ID: <1217172136.2700.21.camel@localhost.localdomain> (raw)
In-Reply-To: <48763814.27052c0a.1794.2095@mx.google.com>
On Thu, 2008-07-10 at 16:57 +0200, Luis Carlos Cobo wrote:
> Originally by Johannes Berg. This patch adds support for devices that do not
> report their MAC address until the firmware is loaded. While the address is not
> known, a multicast on is used.
Johannes, thoughts on this? Is there a better way to do it for devices
that don't know their MAC address until firmware load?
Dan
> Signed-off-by: Luis Carlos Cobo <luisca@cozybit.com>
> Tested-by: Javier Cardona <javier@cozybit.com>
> ---
> net/mac80211/ieee80211_i.h | 1 +
> net/mac80211/main.c | 61 ++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 62 insertions(+), 0 deletions(-)
>
> diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
> index c916c2f..8e8c0eb 100644
> --- a/net/mac80211/ieee80211_i.h
> +++ b/net/mac80211/ieee80211_i.h
> @@ -551,6 +551,7 @@ struct ieee80211_local {
> const struct ieee80211_ops *ops;
>
> struct net_device *mdev; /* wmaster# - "master" 802.11 device */
> + unsigned int hwid;
> int open_count;
> int monitors, cooked_mntrs;
> /* number of interfaces with corresponding FIF_ flags */
> diff --git a/net/mac80211/main.c b/net/mac80211/main.c
> index cf477ad..2204aa5 100644
> --- a/net/mac80211/main.c
> +++ b/net/mac80211/main.c
> @@ -178,6 +178,20 @@ static inline int identical_mac_addr_allowed(int type1, int type2)
> type2 == IEEE80211_IF_TYPE_VLAN)));
> }
>
> +static void calculate_invalid_mac(u8 *addr, unsigned int hwid)
> +{
> + /*
> + * Random multicast, private use address with hwid mixed in.
> + * Must be multicast to let is_valid_ether_addr() fail on it.
> + */
> + addr[0] = 0xe7;
> + addr[1] = 0xc4;
> + addr[2] = 0x2e ^ ((hwid >> 24) & 0xFF);
> + addr[3] = 0xdd ^ ((hwid >> 16) & 0xFF);
> + addr[4] = 0xcb ^ ((hwid >> 8) & 0xFF);
> + addr[5] = 0x8c ^ ((hwid >> 0) & 0xFF);
> +}
> +
> static int ieee80211_open(struct net_device *dev)
> {
> struct ieee80211_sub_if_data *sdata, *nsdata;
> @@ -187,9 +201,17 @@ static int ieee80211_open(struct net_device *dev)
> u32 changed = 0;
> int res;
> bool need_hw_reconfig = 0;
> + u8 inval_addr[ETH_ALEN];
>
> sdata = IEEE80211_DEV_TO_SUB_IF(dev);
>
> + calculate_invalid_mac(inval_addr, local->hwid);
> +
> + /* fail early if user set an invalid address */
> + if (compare_ether_addr(dev->dev_addr, inval_addr) &&
> + !is_valid_ether_addr(dev->dev_addr))
> + return -EADDRNOTAVAIL;
> +
> /* we hold the RTNL here so can safely walk the list */
> list_for_each_entry(nsdata, &local->interfaces, list) {
> struct net_device *ndev = nsdata->dev;
> @@ -288,6 +310,32 @@ static int ieee80211_open(struct net_device *dev)
> ieee80211_led_radio(local, local->hw.conf.radio_enabled);
> }
>
> + /*
> + * Check all interfaces and copy the hopefully now-present
> + * MAC address to those that have the special invalid one.
> + */
> + list_for_each_entry(nsdata, &local->interfaces, list) {
> + struct net_device *ndev = nsdata->dev;
> +
> + /*
> + * No need to check netif_running since we do not allow
> + * it to start up with this invalid address.
> + */
> + if (compare_ether_addr(inval_addr, ndev->dev_addr) == 0)
> + memcpy(ndev->dev_addr,
> + local->hw.wiphy->perm_addr,
> + ETH_ALEN);
> + }
> +
> + /*
> + * Validate the MAC address for this device.
> + */
> + if (!is_valid_ether_addr(dev->dev_addr)) {
> + if (!local->open_count && local->ops->stop)
> + local->ops->stop(local_to_hw(local));
> + return -EADDRNOTAVAIL;
> + }
> +
> switch (sdata->vif.type) {
> case IEEE80211_IF_TYPE_VLAN:
> list_add(&sdata->u.vlan.list, &sdata->u.vlan.ap->u.ap.vlans);
> @@ -995,6 +1043,8 @@ void ieee80211_if_setup(struct net_device *dev)
> dev->open = ieee80211_open;
> dev->stop = ieee80211_stop;
> dev->destructor = ieee80211_if_free;
> + /* we will validate the address ourselves in ->open */
> + dev->validate_addr = NULL;
> }
>
> /* everything else */
> @@ -1571,6 +1621,8 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
> struct ieee80211_local *local;
> int priv_size;
> struct wiphy *wiphy;
> + static atomic_t hw_counter = ATOMIC_INIT(0);
> + u8 inval_addr[ETH_ALEN];
>
> /* Ensure 32-byte alignment of our private data and hw private data.
> * We use the wiphy priv data for both our ieee80211_local and for
> @@ -1601,6 +1653,15 @@ struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
> local = wiphy_priv(wiphy);
> local->hw.wiphy = wiphy;
>
> + /*
> + * Hack for devices that cannot read the mac address until they are
> + * started... keep an invalid multicast address as the device MAC...
> + * Read on in ieee80211_open().
> + */
> + local->hwid = atomic_inc_return(&hw_counter);
> + calculate_invalid_mac(inval_addr, local->hwid);
> + memcpy(local->hw.wiphy->perm_addr, inval_addr, ETH_ALEN);
> +
> local->hw.priv = (char *)local +
> ((sizeof(struct ieee80211_local) +
> NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
next prev parent reply other threads:[~2008-07-27 15:24 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-10 14:57 [PATCH 1/6] mac80211: allow no mac address until firmware load Luis Carlos Cobo
2008-07-27 15:22 ` Dan Williams [this message]
2008-07-28 13:23 ` Johannes Berg
2008-07-28 13:44 ` Michael Buesch
2008-07-28 13:56 ` Luis Carlos Cobo
2008-07-28 14:00 ` Michael Buesch
2008-07-28 14:59 ` Dan Williams
2008-07-28 15:07 ` Johannes Berg
2008-07-28 15:14 ` Dan Williams
2008-07-28 15:58 ` Tomas Winkler
2008-07-28 16:22 ` Dan Williams
2008-07-30 11:17 ` Luis Carlos Cobo
2008-07-30 11:35 ` Dan Williams
2008-07-30 14:30 ` John W. Linville
2008-07-30 14:52 ` Luis Carlos Cobo
2008-07-28 13:57 ` Dan Williams
2008-07-28 14:25 ` Michael Buesch
2008-07-28 14:44 ` Tomas Winkler
2008-07-28 14:49 ` Johannes Berg
2008-07-28 14:57 ` Dan Williams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1217172136.2700.21.camel@localhost.localdomain \
--to=dcbw@redhat.com \
--cc=johannes@sipsolutions.net \
--cc=linux-wireless@vger.kernel.org \
--cc=luisca@cozybit.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).