Skip to contentSkip to conversation

cfg80211: Fix incompatible interfaces combination

RFC In review Mohammed Shafi Shajakhan 2 participants 12 messages Jun 4, 2012 – Jun 5, 2012 802.11 (including cfg80211/NL80211)

lore
Share & tools
lore
#0 lore raw

RFC 1/1 cfg80211: Fix incompatible interfaces combination

From: Mohammed Shafi Shajakhan <[email protected]>

*if any interface type is not advertised by the driver via ieee80211_iface_combination make sure we will have it as a single interface only. lets that we will not add an incompatible interface if some other interface is already present. we cannot add any other interface, if the already present interface is an incompatible interface. for example in ath9k we don't advertise ADHOC in ieee80211_iface_combination structure in the driver, so it can only exist as an single interface

*if the driver is not advertising interface combination just return so that we don't break their multivif operation.

---
 net/wireless/util.c |   62 ++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 49 insertions(+), 13 deletions(-)
net/wireless/util.c +49 -13
index c64d30f..7712ac6 100644
@@ -932,22 +932,31 @@ int cfg80211_validate_beacon_int(struct cfg80211_registered_device *rdev,
 
 int cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
 				  struct wireless_dev *wdev,
-				  enum nl80211_iftype iftype)
+				  enum nl80211_iftype ntype)
 {
 	struct wireless_dev *wdev_iter;
 	int num[NUM_NL80211_IFTYPES];
 	int total = 1;
 	int i, j;
+	enum nl80211_iftype iftype;
+	bool ntype_single = true;
+	bool found_iface_comb = false;
+	bool iface_comb_allowed[NUM_NL80211_IFTYPES];
 
 	ASSERT_RTNL();
 
 	/* Always allow software iftypes */
-	if (rdev->wiphy.software_iftypes & BIT(iftype))
+	if (rdev->wiphy.software_iftypes & BIT(ntype))
+		return 0;
+
+	/* interface combination not advertised by the driver */
+	if (!rdev->wiphy.n_iface_combinations)
 		return 0;
 
 	memset(num, 0, sizeof(num));
+	memset(iface_comb_allowed, 0, sizeof(iface_comb_allowed));
 
-	num[iftype] = 1;
+	num[ntype] = 1;
 
 	mutex_lock(&rdev->devlist_mtx);
 	list_for_each_entry(wdev_iter, &rdev->netdev_list, list) {
@@ -967,6 +976,7 @@ int cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
 	if (total == 1)
 		return 0;
 
+
 	for (i = 0; i < rdev->wiphy.n_iface_combinations; i++) {
 		const struct ieee80211_iface_combination *c;
 		struct ieee80211_iface_limit *limits;
@@ -981,24 +991,50 @@ int cfg80211_can_change_interface(struct cfg80211_registered_device *rdev,
 			goto cont;
 
 		for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++) {
-			if (rdev->wiphy.software_iftypes & BIT(iftype))
+
+			if (rdev->wiphy.software_iftypes & BIT(iftype)) {
+				iface_comb_allowed[iftype] = true;
 				continue;
+			}
+
 			for (j = 0; j < c->n_limits; j++) {
-				if (!(limits[j].types & BIT(iftype)))
-					continue;
-				if (limits[j].max < num[iftype])
-					goto cont;
-				limits[j].max -= num[iftype];
+
+				if (limits[j].types & BIT(ntype))
+					ntype_single = false;
+
+				if (!num[iftype] ||
+				    (limits[j].types & BIT(iftype)))
+					iface_comb_allowed[iftype] = true;
+
+				if (!found_iface_comb) {
+
+					if (!(limits[j].types & BIT(iftype)))
+						continue;
+					if (limits[j].max < num[iftype])
+						goto cont;
+					limits[j].max -= num[iftype];
+
+				}
 			}
 		}
-		/* yay, it fits */
-		kfree(limits);
-		return 0;
+
+		found_iface_comb = true;
+
  cont:
 		kfree(limits);
 	}
 
-	return -EBUSY;
+	if (ntype_single)
+		return -EOPNOTSUPP;
+
+	for (iftype = 0; iftype < NUM_NL80211_IFTYPES; iftype++)
+		if (!iface_comb_allowed[iftype])
+			return -EOPNOTSUPP;
+
+	if (found_iface_comb)
+		return 0;
+
+	return -EOPNOTSUPP;
 }
 
 int ieee80211_get_ratemask(struct ieee80211_supported_band *sband,
Signature · 1 line
1.7.0.4
maintainer
#1 lore raw
Quoted 11 lines · Mohammed Shafi Shajakhan

From: Mohammed Shafi Shajakhan <[email protected]>

*if any interface type is not advertised by the driver via ieee80211_iface_combination make sure we will have it as a single interface only. lets that we will not add an incompatible interface if some other interface is already present. we cannot add any other interface, if the already present interface is an incompatible interface. for example in ath9k we don't advertise ADHOC in ieee80211_iface_combination structure in the driver, so it can only exist as an single interface

I'm not sure I understand what you're changing here?

Quoted 2 lines

*if the driver is not advertising interface combination just return so that we don't break their multivif operation.

Actually, we want to break multivif for drivers that don't advertise it.

johannes

#2 lore raw
Quoted 13 lines · Johannes Berg
Quoted 11 lines · Mohammed Shafi Shajakhan

From: Mohammed Shafi Shajakhan<[email protected]>

*if any interface type is not advertised by the driver via ieee80211_iface_combination make sure we will have it as a single interface only. lets that we will not add an incompatible interface if some other interface is already present. we cannot add any other interface, if the already present interface is an incompatible interface. for example in ath9k we don't advertise ADHOC in ieee80211_iface_combination structure in the driver, so it can only exist as an single interface

Quoted 1 line

I'm not sure I understand what you're changing here?

if an interface say ad-hoc is not advertised in iface combination,
with the current still we can add that interface with some other interface(removing the driver checks).

in ath9k we have

static const struct ieee80211_iface_limit if_limits[] = {
        { .max = 2048,  .types = BIT(NL80211_IFTYPE_STATION) |
                                 BIT(NL80211_IFTYPE_P2P_CLIENT) |
                                 BIT(NL80211_IFTYPE_WDS) },
        { .max = 8,     .types =
#ifdef CONFIG_MAC80211_MESH
                                 BIT(NL80211_IFTYPE_MESH_POINT) |
#endif
                                 BIT(NL80211_IFTYPE_AP) |
                                 BIT(NL80211_IFTYPE_P2P_GO) },
};

i am able to create an IBSS interface even if a STA interface is up and running in ath9k(removing the driver checks).

this patch ensures that if we have an incompatible interface, it is the only one can that can exist.

Quoted 5 lines
Quoted 3 lines

*if the driver is not advertising interface combination just return so that we don't break their multivif operation.

Actually, we want to break multivif for drivers that don't advertise it.

oh, ok.

Quoted 3 lines

johannes

Signature · 2 lines
thanks,
shafi
maintainer
#3 lore raw
Quoted 34 lines · Mohammed Shafi Shajakhan
Quoted 13 lines · Johannes Berg
Quoted 11 lines · Mohammed Shafi Shajakhan

From: Mohammed Shafi Shajakhan<[email protected]>

*if any interface type is not advertised by the driver via ieee80211_iface_combination make sure we will have it as a single interface only. lets that we will not add an incompatible interface if some other interface is already present. we cannot add any other interface, if the already present interface is an incompatible interface. for example in ath9k we don't advertise ADHOC in ieee80211_iface_combination structure in the driver, so it can only exist as an single interface

Quoted 1 line

I'm not sure I understand what you're changing here?

if an interface say ad-hoc is not advertised in iface combination, with the current still we can add that interface with some other interface(removing the driver checks).

in ath9k we have

static const struct ieee80211_iface_limit if_limits[] = {
         { .max = 2048,  .types = BIT(NL80211_IFTYPE_STATION) |
                                  BIT(NL80211_IFTYPE_P2P_CLIENT) |
                                  BIT(NL80211_IFTYPE_WDS) },
         { .max = 8,     .types =
#ifdef CONFIG_MAC80211_MESH
                                  BIT(NL80211_IFTYPE_MESH_POINT) |
#endif
                                  BIT(NL80211_IFTYPE_AP) |
                                  BIT(NL80211_IFTYPE_P2P_GO) },
};
Quoted 5 lines

i am able to create an IBSS interface even if a STA interface is up and running in ath9k(removing the driver checks).

this patch ensures that if we have an incompatible interface, it is the only one can that can exist.

Right, ok, I see that it's broken now, trying to see if there's a better fix though.

johannes

#4 lore raw
Quoted 35 lines · Johannes Berg
Quoted 34 lines · Mohammed Shafi Shajakhan
Quoted 13 lines · Johannes Berg
Quoted 11 lines · Mohammed Shafi Shajakhan

From: Mohammed Shafi Shajakhan<[email protected]>

*if any interface type is not advertised by the driver via ieee80211_iface_combination make sure we will have it as a single interface only. lets that we will not add an incompatible interface if some other interface is already present. we cannot add any other interface, if the already present interface is an incompatible interface. for example in ath9k we don't advertise ADHOC in ieee80211_iface_combination structure in the driver, so it can only exist as an single interface

Quoted 1 line

I'm not sure I understand what you're changing here?

if an interface say ad-hoc is not advertised in iface combination, with the current still we can add that interface with some other interface(removing the driver checks).

in ath9k we have

static const struct ieee80211_iface_limit if_limits[] = {
          { .max = 2048,  .types = BIT(NL80211_IFTYPE_STATION) |
                                   BIT(NL80211_IFTYPE_P2P_CLIENT) |
                                   BIT(NL80211_IFTYPE_WDS) },
          { .max = 8,     .types =
#ifdef CONFIG_MAC80211_MESH
                                   BIT(NL80211_IFTYPE_MESH_POINT) |
#endif
                                   BIT(NL80211_IFTYPE_AP) |
                                   BIT(NL80211_IFTYPE_P2P_GO) },
};
Quoted 8 lines
Quoted 5 lines

i am able to create an IBSS interface even if a STA interface is up and running in ath9k(removing the driver checks).

this patch ensures that if we have an incompatible interface, it is the only one can that can exist.

Right, ok, I see that it's broken now, trying to see if there's a better fix though.

sure, thank you.

Quoted 3 lines

johannes

Signature · 2 lines
thanks,
shafi
maintainer
#5 lore raw
Quoted 10 lines · Mohammed Shafi Shajakhan
Quoted 8 lines
Quoted 5 lines

i am able to create an IBSS interface even if a STA interface is up and running in ath9k(removing the driver checks).

this patch ensures that if we have an incompatible interface, it is the only one can that can exist.

Right, ok, I see that it's broken now, trying to see if there's a better fix though.

sure, thank you.

I'm not really sure, but if I understand the code & problem correctly I think this should also help:
http://p.sipsolutions.net/a57eeac50c248408.txt

Untested though.

johannes

#7 lore raw

Hi Johannes,

Quoted 4 lines

No, initialization was incorrect -- this is better:
http://p.sipsolutions.net/e5ab0f3e38f90d6d.txt

thanks a lot for the patch!
with the above patch ath9k seems be working fine with the single incompatible adhoc interface.
but i was just experimenting with ath9k(similar to iwlwifi having hw->wiphy->n_iface_combinations > 1) with this patch.

static const struct ieee80211_iface_limit a[] = {
        { .max = 2,     .types = BIT(NL80211_IFTYPE_STATION) },
};
static const struct ieee80211_iface_limit b[] = {
        { .max = 2,     .types = BIT(NL80211_IFTYPE_MESH_POINT) },
};
static const struct ieee80211_iface_combination if_comb[] = {
        {.limits = a,
        .n_limits = ARRAY_SIZE(a),
        .max_interfaces = 2,
        .num_different_channels = 1,
        },
        {.limits = b,
        .n_limits = ARRAY_SIZE(b),
        .max_interfaces = 2,
        .num_different_channels = 1,
        },

};

i could not add mesh interface if a managed interface is already there and vice versa. if this is the expected behavior, then fine.

dmesg
iteration 1: cfg80211_can_change_interface all_iftypes 4 and used_iftypes 84 iteration 2: cfg80211_can_change_interface all_iftypes 80 and used_iftypes 84

Signature · 2 lines
thanks,
shafi
maintainer
#8 lore raw

Hi Mohammed,

Quoted 7 lines
Quoted 3 lines

No, initialization was incorrect -- this is better:
http://p.sipsolutions.net/e5ab0f3e38f90d6d.txt

thanks a lot for the patch!
with the above patch ath9k seems be working fine with the single incompatible adhoc interface.

Ok, cool.

Quoted 23 lines

but i was just experimenting with ath9k(similar to iwlwifi having hw->wiphy->n_iface_combinations > 1) with this patch.

static const struct ieee80211_iface_limit a[] = {
         { .max = 2,     .types = BIT(NL80211_IFTYPE_STATION) },
};
static const struct ieee80211_iface_limit b[] = {
         { .max = 2,     .types = BIT(NL80211_IFTYPE_MESH_POINT) },
};
static const struct ieee80211_iface_combination if_comb[] = {
         {.limits = a,
         .n_limits = ARRAY_SIZE(a),
         .max_interfaces = 2,
         .num_different_channels = 1,
         },
         {.limits = b,
         .n_limits = ARRAY_SIZE(b),
         .max_interfaces = 2,
         .num_different_channels = 1,
         },
Quoted 4 lines

};

i could not add mesh interface if a managed interface is already there and vice versa. if this is the expected behavior, then fine.

No, that's not expected! Another bug!

We should write some unit tests for this code I guess :-)

Quoted 2 lines

iteration 1: cfg80211_can_change_interface all_iftypes 4 and used_iftypes 84 iteration 2: cfg80211_can_change_interface all_iftypes 80 and used_iftypes 84

Curious. Why did it accept it then? Where did you place the printk?

I'm handling Linus's problem right now, so it'll be a bit until I can look at this in more detail again.

johannes

#9 lore raw

Hi Johannes,

Quoted 38 lines
Quoted 7 lines
Quoted 3 lines

No, initialization was incorrect -- this is better:
http://p.sipsolutions.net/e5ab0f3e38f90d6d.txt

thanks a lot for the patch!
with the above patch ath9k seems be working fine with the single incompatible adhoc interface.

Ok, cool.

Quoted 23 lines

but i was just experimenting with ath9k(similar to iwlwifi having hw->wiphy->n_iface_combinations> 1) with this patch.

static const struct ieee80211_iface_limit a[] = {
          { .max = 2,     .types = BIT(NL80211_IFTYPE_STATION) },
};
static const struct ieee80211_iface_limit b[] = {
          { .max = 2,     .types = BIT(NL80211_IFTYPE_MESH_POINT) },
};
static const struct ieee80211_iface_combination if_comb[] = {
          {.limits = a,
          .n_limits = ARRAY_SIZE(a),
          .max_interfaces = 2,
          .num_different_channels = 1,
          },
          {.limits = b,
          .n_limits = ARRAY_SIZE(b),
          .max_interfaces = 2,
          .num_different_channels = 1,
          },
Quoted 4 lines

};

i could not add mesh interface if a managed interface is already there and vice versa. if this is the expected behavior, then fine.

Quoted 8 lines

No, that's not expected! Another bug!

We should write some unit tests for this code I guess :-)

Quoted 2 lines

iteration 1: cfg80211_can_change_interface all_iftypes 4 and used_iftypes 84 iteration 2: cfg80211_can_change_interface all_iftypes 80 and used_iftypes 84

Curious. Why did it accept it then? Where did you place the printk?

not sure whether i missed something, but it did not work for the above case. printk just inside the condition check of your patch.

if ((all_iftypes & used_iftypes) != used_iftypes) {
+ printk("\nshafi %s all_iftypes %x and used_iftypes %x", __func__, all_iftypes, used_iftypes);
+ goto cont;
+ }

i think we need to take 'all_iftypes' for all the 'n_interface_combinations' and then finally compare it with used_iftypes.

Quoted 3 lines

I'm handling Linus's problem right now, so it'll be a bit until I can look at this in more detail again.

oh ok, sure.

Signature · 2 lines
thanks,
shafi
maintainer
#10 lore raw

Hi Mohammed,

Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
static const struct ieee80211_iface_limit a[] = {
          { .max = 2,     .types = BIT(NL80211_IFTYPE_STATION) },
};
static const struct ieee80211_iface_limit b[] = {
          { .max = 2,     .types = BIT(NL80211_IFTYPE_MESH_POINT) },
};
static const struct ieee80211_iface_combination if_comb[] = {
          {.limits = a,
          .n_limits = ARRAY_SIZE(a),
          .max_interfaces = 2,
          .num_different_channels = 1,
          },
          {.limits = b,
          .n_limits = ARRAY_SIZE(b),
          .max_interfaces = 2,
          .num_different_channels = 1,
          },
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

};

i could not add mesh interface if a managed interface is already there and vice versa. if this is the expected behavior, then fine.

No, that's not expected! Another bug!

Actually, I'm sorry -- clearly I wasn't paying attention before -- it is expected. The above means you can add two managed or two mesh interface, but no combinations of them. Basically, the things in if_comb are XOR, and the things inside each limit are AND.

johannes

#11 lore raw
Quoted 27 lines · Johannes Berg

Hi Mohammed,

Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
static const struct ieee80211_iface_limit a[] = {
           { .max = 2,     .types = BIT(NL80211_IFTYPE_STATION) },
};
static const struct ieee80211_iface_limit b[] = {
           { .max = 2,     .types = BIT(NL80211_IFTYPE_MESH_POINT) },
};
static const struct ieee80211_iface_combination if_comb[] = {
           {.limits = a,
           .n_limits = ARRAY_SIZE(a),
           .max_interfaces = 2,
           .num_different_channels = 1,
           },
           {.limits = b,
           .n_limits = ARRAY_SIZE(b),
           .max_interfaces = 2,
           .num_different_channels = 1,
           },

};

i could not add mesh interface if a managed interface is already there and vice versa. if this is the expected behavior, then fine.

Quoted 7 lines
Quoted 1 line
Quoted 1 line

No, that's not expected! Another bug!

Actually, I'm sorry -- clearly I wasn't paying attention before -- it is expected. The above means you can add two managed or two mesh interface, but no combinations of them. Basically, the things in if_comb are XOR, and the things inside each limit are AND.

thanks, then the updated http://p.sipsolutions.net/fedf39a8d08b28b7.txt
seems to solve the issue.

Signature · 2 lines
thanks,
shafi