Skip to contentSkip to conversation

bcm43xx-d80211: proper implementation of virtual interface support

PATCH In review Michael Buesch 6 participants 8 messages May 1, 2006 – May 5, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bcm43xx-d80211: proper implementation of virtual interface support

Hi,

Jiri, please review this patch for things that might look strange to you. :)

--

This replaces the bcm43xx-d80211 virtual interfaces hack by a correct implementation with support for monitor during oper.

drivers/net/wireless/d80211/bcm43xx/bcm43xx.h +30 -3
Index: wireless-dev/drivers/net/wireless/d80211/bcm43xx/bcm43xx.h
===================================================================
@@ -626,10 +626,34 @@
 	u8 algorithm;
 };
 
+struct bcm43xx_interface {
+	struct list_head list;
+	/* Interface type (IEEE80211_IF_TYPE_XXX). */
+	int type;
+	/* Opaque ID from the ieee80211 subsystem. Do not modify. */
+	int if_id;
+	/* MAC address for this interface. */
+	u8 *mac_addr;
+	/* BSSID (if any). */
+	u8 *bssid;
+};
+
+struct bcm43xx_interface_list {
+	/* Linked list of active interfaces. */
+	struct list_head list;
+	/* Shortcut pointer to the AP interface (if any). */
+	struct bcm43xx_interface *ap_if;
+
+	/* Usage counters of the internal operation modes. */
+	u16 opmode_ap;
+	u16 opmode_adhoc;
+	u16 opmode_monitor;
+	u16 opmode_promisc;
+};
+
 struct bcm43xx_private {
 	struct ieee80211_hw *ieee;
 	struct ieee80211_low_level_stats ieee_stats;
-	int iw_mode;
 
 	struct net_device *net_dev;
 	struct pci_dev *pci_dev;
@@ -653,6 +677,11 @@
 	    short_slot:1,		/* TRUE, if short slot timing is enabled. */
 	    firmware_norelease:1;	/* Do not release the firmware. Used on suspend. */
 
+	/* One physical device can have one or more virtual
+	 * interfaces. This stores and manages the virtual interfaces.
+	 */
+	struct bcm43xx_interface_list interfaces;
+	/* Various statistics about the physical device. */
 	struct bcm43xx_stats stats;
 
 	/* Bus type we are connected to.
@@ -716,8 +745,6 @@
 
 	/* Informational stuff. */
 	char nick[IW_ESSID_MAX_SIZE + 1];
-	u8 bssid[ETH_ALEN];
-	int interfaces;
 
 	/* encryption/decryption */
 	u16 security_offset;
drivers/net/wireless/d80211/bcm43xx/bcm43xx_leds.c +1 -1
Index: wireless-dev/drivers/net/wireless/d80211/bcm43xx/bcm43xx_leds.c
===================================================================
@@ -217,7 +217,7 @@
 				bcm43xx_led_blink_stop(led, 0);
 			continue;
 		case BCM43xx_LED_APTRANSFER:
-			if (bcm->iw_mode == IW_MODE_MASTER) {
+			if (bcm->interfaces.opmode_ap) {
 				if (transferring) {
 					interval = BCM43xx_LEDBLINK_FAST;
 					turn_on = 1;
drivers/net/wireless/d80211/bcm43xx/bcm43xx_main.c +199 -90

413 lines not on this page · raw message

drivers/net/wireless/d80211/bcm43xx/bcm43xx_phy.c +2 -2
Index: wireless-dev/drivers/net/wireless/d80211/bcm43xx/bcm43xx_phy.c
===================================================================
@@ -94,7 +94,7 @@
 		bcm43xx_mac_suspend(bcm);
 		spin_lock(&phy->lock);
 	} else {
-		if (bcm->iw_mode != IW_MODE_MASTER)
+		if (bcm->interfaces.opmode_ap == 0)
 			bcm43xx_power_saving_ctl_bits(bcm, -1, 1);
 	}
 	phy->is_locked = 1;
@@ -111,7 +111,7 @@
 			bcm43xx_mac_enable(bcm);
 		}
 	} else {
-		if (bcm->iw_mode != IW_MODE_MASTER)
+		if (bcm->interfaces.opmode_ap == 0)
 			bcm43xx_power_saving_ctl_bits(bcm, -1, -1);
 	}
 	phy->is_locked = 0;
Signature · 1 line
Greetings Michael.
#1 lore raw
Quoted 21 lines · Michael Buesch
drivers/net/wireless/d80211/bcm43xx/bcm43xx.h +15 -0
@@ -626,10 +626,34 @@
 	u8 algorithm;
 };
 
+struct bcm43xx_interface {
+	struct list_head list;
+	/* Interface type (IEEE80211_IF_TYPE_XXX). */
+	int type;
+	/* Opaque ID from the ieee80211 subsystem. Do not modify. */
+	int if_id;
+	/* MAC address for this interface. */
+	u8 *mac_addr;
+	/* BSSID (if any). */
+	u8 *bssid;
+};
+
+struct bcm43xx_interface_list {
+	/* Linked list of active interfaces. */
+	struct list_head list;

drivers/net/wireless/d80211/bcm43xx/bcm43xx.h line 653

Quoted 10 lines
drivers/net/wireless/d80211/bcm43xx/bcm43xx.h +10 -0
+	/* Shortcut pointer to the AP interface (if any). */
+	struct bcm43xx_interface *ap_if;
+
+	/* Usage counters of the internal operation modes. */
+	u16 opmode_ap;
+	u16 opmode_adhoc;
+	u16 opmode_monitor;
+	u16 opmode_promisc;
+};
+

This is unnecessary. AFAIK bcm43xx hardware doesn't support more than one interface at a time (not counting monitor interfaces as those are somewhat special). There is no need for the linked list.

Instead of those structures above, use something like this:

struct bcm43xx_interface {
	/* Interface type (IEEE80211_IF_TYPE_XXX). */
	int type;
	/* MAC address for this interface. */
	u8 *mac_addr;
	/* BSSID (if any). */
	u8 *bssid;
	/* Number of monitor interfaces. */
	int monitors;
	/* STA, IBSS, AP or WDS running? */
	int oper;
}

You need this structure just once per hw card.

In add_interface callback:
- If conf->type is MNTR:
- If bcm43xx_interface->oper is FALSE and bcm43xx_interface->monitors is 0, initialize the card.
- If bcm43xx_interface->monitors is 0, switch the card to monitor mode (enable promisc mode, enable receiving of control frames, etc.)
- Increase bcm43xx_interface->monitors.
- If conf->type != MNTR:
- If bcm43xx_interface->oper is TRUE, return error.
- Set bcm43xx_interface->oper to TRUE.
- Set bcm43xx_interface->type to conf->type.
- Set hw MAC address according to conf->mac_addr.
- If bcm43xx_interface->monitors is 0, initialize the card.

In remove_interface callback:
- If conf->type is MNTR:
- Decrease bcm43xx_interface->monitors.
- If bcm43xx_interface->monitors is 0, switch the card from monitor mode (disable promisc mode if not forced by set_multicast_list, disable receiving of control frames, etc.)
- If bcm43xx_interface->oper is FALSE and bcm43xx_interface->monitors is 0, deinitialize the card.
- If conf->type != MNTR:
- Set bcm43xx_interface->oper to FALSE.
- If bcm43xx_interface->monitors is 0, deinitialize the card.

In config_interface callback:
- If conf->type is MNTR, please report a bug :-)
- Assume you are configuring the only interface you have running.

Quoted 21 lines

[...]

drivers/net/wireless/d80211/bcm43xx/bcm43xx.h +20 -0
+	iface = kzalloc(sizeof(*iface), GFP_KERNEL);
+	if (!iface)
+		return -ENOMEM;
+	INIT_LIST_HEAD(&iface->list);
+	iface->type = conf->type;
+	iface->if_id = conf->if_id;
+	iface->mac_addr = conf->mac_addr;
+
+	bcm43xx_lock_mmio(bcm, flags);
+	switch (conf->type) {
+	case IEEE80211_IF_TYPE_AP:
+		/* Cannot run more than one AP or concurrently
+		 * with IBSS mode.
+		 */
+		if (bcm->interfaces.opmode_ap)
+			break;
+		if (bcm->interfaces.opmode_adhoc)
+			break;
+		bcm->interfaces.opmode_ap++;
+		bcm->interfaces.ap_if = iface;

drivers/net/wireless/d80211/bcm43xx/bcm43xx.h

Quoted 10 lines
drivers/net/wireless/d80211/bcm43xx/bcm43xx.h +10 -0
+		err = 0;
+		break;
+	case IEEE80211_IF_TYPE_STA:
+		/* Cannot run STA and AP or IBSS mode concurrently. */
+		if (bcm->interfaces.opmode_ap)
+			break;
+		if (bcm->interfaces.opmode_adhoc)
+			break;
+		err = 0;
+		break;

"ifconfig ap up ; ifconfig sta up" will succeed, while "ifconfig sta up ; ifconfig ap up" won't.

Also, you cannot allow multiple STA interfaces, unless you can configure the card to ack frames destined to several MAC addresses.

Nevertheless, this is all addressed by the solution suggested above.

Quoted 8 lines
drivers/net/wireless/d80211/bcm43xx/bcm43xx.h +8 -0
+	case IEEE80211_IF_TYPE_IBSS:
+		/* Cannot run more than one IBSS or concurrently
+		 * with AP mode.
+		 */
+		if (bcm->interfaces.opmode_ap)
+			break;
+		if (bcm->interfaces.opmode_adhoc)
+			break;

drivers/net/wireless/d80211/bcm43xx/bcm43xx.h

Quoted 10 lines
drivers/net/wireless/d80211/bcm43xx/bcm43xx.h +10 -0
+		bcm->interfaces.opmode_adhoc++;
+		err = 0;
+		break;
+	case IEEE80211_IF_TYPE_MNTR:
+		bcm->interfaces.opmode_monitor++;
+		err = 0;
+		break;
+	case IEEE80211_IF_TYPE_WDS:
+		//TODO: Uhm..., well.
+		break;

Please return more appropriate error code (-EINVAL perhaps?).

drivers/net/wireless/d80211/bcm43xx/bcm43xx.h

Quoted 3 lines
drivers/net/wireless/d80211/bcm43xx/bcm43xx.h +2 -0
+	default:
+		assert(0);
 	}

Thanks,

Signature · 2 lines
Jiri Benc
SUSE Labs
#2 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 3 lines · Jiri Benc

This is unnecessary. AFAIK bcm43xx hardware doesn't support more than one interface at a time (not counting monitor interfaces as those are somewhat special).

I wonder what exactly is causing this limitation? Why isn't it just a matter of software support?

Marcus

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)

iD8DBQFEWlUrXjXn6TzcAQkRAoa6AJ97kI8F7Q42orjNQC6HBIXwj3I/DwCgux18 RBkhEcOFBDtQGEHFq2eMxKU=
=3WoL
-----END PGP SIGNATURE-----

#3 lore raw
Quoted 7 lines · Marcus Better
Quoted 3 lines · Jiri Benc

This is unnecessary. AFAIK bcm43xx hardware doesn't support more than one interface at a time (not counting monitor interfaces as those are somewhat special).

I wonder what exactly is causing this limitation? Why isn't it just a matter of software support?

Hardware limitations probably. For example the Ralink devices. The MAC address must be written into the registers for correct behaviour. When multiple virtual interfaces are going to be used, the device should be working under multiple MAC addresses. While the device could be tricked into doing that (I believe rt61 and rt73 drivers from Ralink are making such an attempt) it could give quite some overhead when for each frame that is being send the driver should sort out from which virtual interface it came, write the matching MAC address to the register, and hope that the device will like it when the MAC address is changed so often and the RX is not being affected because of some hardware filter.

#4 lore raw

Thu, 4 May 2006 22:55:58 +0200, Ivo van Doorn pise:

Quoted 14 lines · Marcus Better
Quoted 2 lines

I wonder what exactly is causing this limitation? Why isn't it just a matter of software support?

Hardware limitations probably. For example the Ralink devices. The MAC address must be written into the registers for correct behaviour. When multiple virtual interfaces are going to be used, the device should be working under multiple MAC addresses. While the device could be tricked into doing that (I believe rt61 and rt73 drivers from Ralink are making such an attempt) it could give quite some overhead when for each frame that is being send the driver should sort out from which virtual interface it came, write the matching MAC address to the register, and hope that the device will like it when the MAC address is changed so often and the RX is not being affected because of some hardware filter.

The actual problem is with receiving. ACK frames need to be sent exactly after SIFS interval (10 or 16 microseconds depending on a PHY, +/- 10%) after last bit of the frame was received. This means it cannot be done in a software. You need to tell the hardware about MAC address you are using and hardware will ACK all frames destined to that address (well, actually only that received with valid FCS, but it doesn't matter). And most hardware don't allow to specify more MAC addresses.

Jiri

Signature · 2 lines
Jiri Benc
SUSE Labs
#5 lore raw
Quoted 9 lines

The actual problem is with receiving. ACK frames need to be sent exactly after SIFS interval (10 or 16 microseconds depending on a PHY, +/- 10%) after last bit of the frame was received. This means it cannot be done in a software. You need to tell the hardware about MAC address you are using and hardware will ACK all frames destined to that address (well, actually only that received with valid FCS, but it doesn't matter). And most hardware don't allow to specify more MAC addresses.

Jiri

Good explanation. ZD1211 allows to specify a second RX address, I wondered, what this is good for. So for ZD1211 we could support two virtual interfaces. However in AP mode one virtual device would have to send the beacons on its own. But there could be also support for one interface in AP and the other in STA mode.

Uli

Signature · 1 line
Ulrich Kunitz - [email protected]
maintainer
#6 lore raw
Quoted 2 lines · Ulrich Kunitz

But there could be also
support for one interface in AP and the other in STA mode.

That's actually a much more interesting use case for WDS.

johannes

#7 lore raw
Quoted 5 lines · Johannes Berg
Quoted 2 lines · Ulrich Kunitz

But there could be also
support for one interface in AP and the other in STA mode.

That's actually a much more interesting use case for WDS.

You don't need different MAC address for WDS.

Jiri

Signature · 2 lines
Jiri Benc
SUSE Labs