* [PATCH] iw: add country IE parsing
@ 2010-02-18 2:13 Luis R. Rodriguez
2010-02-18 7:16 ` Gabor Juhos
2010-02-18 21:40 ` Lukáš Turek
0 siblings, 2 replies; 9+ messages in thread
From: Luis R. Rodriguez @ 2010-02-18 2:13 UTC (permalink / raw)
To: johannes; +Cc: linux-wireless, 8an, Luis R. Rodriguez
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3661 bytes --]
Spits out the channels as seen on the IE, useful when debugging
issues with APs. When found the equivalent distance of the
coverage class is printed out in meters.
Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
---
Sorry, resending, I mistakenly sent to lkml instead of linux-wireless.
OK so I removed the line that says we're printing IEs and also
added a distance compuation based on Lukáš Turek's forumal.
coverage = (distance + 449) / 450;
coverage/450 = distance + 499
(coverage/450) - 499 = distance
So in meters:
distance = (coverage/450) - 499
scan.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 79 insertions(+), 17 deletions(-)
diff --git a/scan.c b/scan.c
index ec63e61..2d7f15e 100644
--- a/scan.c
+++ b/scan.c
@@ -36,6 +36,23 @@ struct scan_params {
bool show_both_ie_sets;
};
+#define IEEE80211_COUNTRY_EXTENSION_ID 201
+
+struct ieee80211_country_ie_triplet {
+ union {
+ struct {
+ __u8 first_channel;
+ __u8 num_channels;
+ __s8 max_power;
+ } __attribute__ ((packed)) chans;
+ struct {
+ __u8 reg_extension_id;
+ __u8 reg_class;
+ __u8 coverage_class;
+ } __attribute__ ((packed)) ext;
+ };
+} __attribute__ ((packed));
+
static int handle_scan(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
@@ -143,29 +160,74 @@ static void print_ds(const uint8_t type, uint8_t len, const uint8_t *data)
printf(" channel %d\n", data[0]);
}
-static void print_country(const uint8_t type, uint8_t len, const uint8_t *data)
+static const char *country_env_str(char environment)
{
- int i;
-
- printf(" %.*s", 2, data);
- switch (data[2]) {
+ switch (environment) {
case 'I':
- printf(" (indoor)");
- break;
+ return "Indoor only";
case 'O':
- printf(" (outdoor)");
- break;
+ return "Outdoor only";
case ' ':
- printf(" (in/outdoor)");
- break;
+ return "Indoor/Outdoor";
default:
- printf(" (invalid environment)");
- break;
+ return "bogus";
}
- printf(", data:");
- for(i=0; i<len-3; i++)
- printf(" %.02x", data[i + 3]);
- printf("\n");
+}
+
+/*
+ * Using the inverse of the distance to coverage class
+ * formula we get that in meters
+ * distance = (coverage/450) - 499
+ */
+static int coverage_class_to_distance(__u8 coverage_class)
+{
+ return (coverage_class / 450) - 499;
+}
+
+static void print_country(const uint8_t type, uint8_t len, const uint8_t *data)
+{
+ printf(" %.*s", 2, data);
+
+ printf("\tEnvironment: %s\n", country_env_str(data[2]));
+
+ data += 3;
+ len -= 3;
+
+ if (len < 3) {
+ printf("\t\tNo country IE triplets present\n");
+ return;
+ }
+
+ while (len >= 3) {
+ int end_channel;
+ struct ieee80211_country_ie_triplet *triplet =
+ (struct ieee80211_country_ie_triplet *) data;
+
+ if (triplet->ext.reg_extension_id >= IEEE80211_COUNTRY_EXTENSION_ID) {
+ printf("\t\tExtension ID: %d Regulatory Class: %d Coverage class: %d (Approx %d meters)\n",
+ triplet->ext.reg_extension_id,
+ triplet->ext.reg_class,
+ triplet->ext.coverage_class,
+ coverage_class_to_distance(triplet->ext.coverage_class));
+
+ data += 3;
+ len -= 3;
+ continue;
+ }
+
+ /* 2 GHz */
+ if (triplet->chans.first_channel <= 14)
+ end_channel = triplet->chans.first_channel + (triplet->chans.num_channels - 1);
+ else
+ end_channel = triplet->chans.first_channel + (4 * (triplet->chans.num_channels - 1));
+
+ printf("\t\tChannels [%d - %d]\n", triplet->chans.first_channel, end_channel);
+
+ data += 3;
+ len -= 3;
+ }
+
+ return;
}
static void print_powerconstraint(const uint8_t type, uint8_t len, const uint8_t *data)
--
1.6.3.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] iw: add country IE parsing
2010-02-18 2:13 [PATCH] iw: add country IE parsing Luis R. Rodriguez
@ 2010-02-18 7:16 ` Gabor Juhos
2010-02-18 21:40 ` Lukáš Turek
1 sibling, 0 replies; 9+ messages in thread
From: Gabor Juhos @ 2010-02-18 7:16 UTC (permalink / raw)
To: Luis R. Rodriguez; +Cc: johannes, linux-wireless, 8an
Luis R. Rodriguez írta:
> Spits out the channels as seen on the IE, useful when debugging
> issues with APs. When found the equivalent distance of the
> coverage class is printed out in meters.
>
> Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
> ---
>
> Sorry, resending, I mistakenly sent to lkml instead of linux-wireless.
>
> OK so I removed the line that says we're printing IEs and also
> added a distance compuation based on Lukáš Turek's forumal.
>
> coverage = (distance + 449) / 450;
> coverage/450 = distance + 499
You have to multiply both sides of the equation by the same value.
Additionally, you did change 449 to 499.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] iw: add country IE parsing
2010-02-18 2:13 [PATCH] iw: add country IE parsing Luis R. Rodriguez
2010-02-18 7:16 ` Gabor Juhos
@ 2010-02-18 21:40 ` Lukáš Turek
2010-02-19 18:54 ` Luis R. Rodriguez
1 sibling, 1 reply; 9+ messages in thread
From: Lukáš Turek @ 2010-02-18 21:40 UTC (permalink / raw)
To: Luis R. Rodriguez; +Cc: johannes, linux-wireless
[-- Attachment #1: Type: text/plain, Size: 927 bytes --]
On 18.2.2010 03:13 Luis R. Rodriguez wrote:
> coverage = (distance + 449) / 450;
> coverage/450 = distance + 499
> (coverage/450) - 499 = distance
Inverting the formula like this doesn't make much sense...
The addition of 449 is there to round the resulting number up, because the
coverage class limits maximum distance and if it was rounded down as normal
integer division does, the resulting ACK timeout would be too low.
However, if you subtract 449 in the inverted formula, you get something like a
minimum distance for the coverage class - which doesn't mean anything,
because higher ACK timeout and slot time works for smaller distances too.
Maximum distance is what's interesting to the user. So the correct
calculation is just multiplying the coverage class by 450 as I'm doing in
print_phy_handler():
printf("\tCoverage class: %d (up to %dm)\n", coverage, 450 * coverage);
Lukas Turek
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] iw: add country IE parsing
2010-02-18 21:40 ` Lukáš Turek
@ 2010-02-19 18:54 ` Luis R. Rodriguez
0 siblings, 0 replies; 9+ messages in thread
From: Luis R. Rodriguez @ 2010-02-19 18:54 UTC (permalink / raw)
To: 8an; +Cc: johannes, linux-wireless
On Thu, Feb 18, 2010 at 1:40 PM, Lukáš Turek <8an@praha12.net> wrote:
> On 18.2.2010 03:13 Luis R. Rodriguez wrote:
>> coverage = (distance + 449) / 450;
>> coverage/450 = distance + 499
>> (coverage/450) - 499 = distance
>
> Inverting the formula like this doesn't make much sense...
>
> The addition of 449 is there to round the resulting number up, because the
> coverage class limits maximum distance and if it was rounded down as normal
> integer division does, the resulting ACK timeout would be too low.
>
> However, if you subtract 449 in the inverted formula, you get something like a
> minimum distance for the coverage class - which doesn't mean anything,
> because higher ACK timeout and slot time works for smaller distances too.
> Maximum distance is what's interesting to the user. So the correct
> calculation is just multiplying the coverage class by 450 as I'm doing in
> print_phy_handler():
>
> printf("\tCoverage class: %d (up to %dm)\n", coverage, 450 * coverage);
Thanks I'll fix and resend.
Luis
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] iw: add country IE parsing
@ 2010-02-18 2:06 Luis R. Rodriguez
0 siblings, 0 replies; 9+ messages in thread
From: Luis R. Rodriguez @ 2010-02-18 2:06 UTC (permalink / raw)
To: johannes; +Cc: linux-kernel, 8an, Luis R. Rodriguez
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3589 bytes --]
Spits out the channels as seen on the IE, useful when debugging
issues with APs. When found the equivalent distance of the
coverage class is printed out in meters.
Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
---
OK so I removed the line that says we're printing IEs and also
added a distance compuation based on Lukáš Turek's forumal.
coverage = (distance + 449) / 450;
coverage/450 = distance + 499
(coverage/450) - 499 = distance
So in meters:
distance = (coverage/450) - 499
scan.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 79 insertions(+), 17 deletions(-)
diff --git a/scan.c b/scan.c
index ec63e61..2d7f15e 100644
--- a/scan.c
+++ b/scan.c
@@ -36,6 +36,23 @@ struct scan_params {
bool show_both_ie_sets;
};
+#define IEEE80211_COUNTRY_EXTENSION_ID 201
+
+struct ieee80211_country_ie_triplet {
+ union {
+ struct {
+ __u8 first_channel;
+ __u8 num_channels;
+ __s8 max_power;
+ } __attribute__ ((packed)) chans;
+ struct {
+ __u8 reg_extension_id;
+ __u8 reg_class;
+ __u8 coverage_class;
+ } __attribute__ ((packed)) ext;
+ };
+} __attribute__ ((packed));
+
static int handle_scan(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
@@ -143,29 +160,74 @@ static void print_ds(const uint8_t type, uint8_t len, const uint8_t *data)
printf(" channel %d\n", data[0]);
}
-static void print_country(const uint8_t type, uint8_t len, const uint8_t *data)
+static const char *country_env_str(char environment)
{
- int i;
-
- printf(" %.*s", 2, data);
- switch (data[2]) {
+ switch (environment) {
case 'I':
- printf(" (indoor)");
- break;
+ return "Indoor only";
case 'O':
- printf(" (outdoor)");
- break;
+ return "Outdoor only";
case ' ':
- printf(" (in/outdoor)");
- break;
+ return "Indoor/Outdoor";
default:
- printf(" (invalid environment)");
- break;
+ return "bogus";
}
- printf(", data:");
- for(i=0; i<len-3; i++)
- printf(" %.02x", data[i + 3]);
- printf("\n");
+}
+
+/*
+ * Using the inverse of the distance to coverage class
+ * formula we get that in meters
+ * distance = (coverage/450) - 499
+ */
+static int coverage_class_to_distance(__u8 coverage_class)
+{
+ return (coverage_class / 450) - 499;
+}
+
+static void print_country(const uint8_t type, uint8_t len, const uint8_t *data)
+{
+ printf(" %.*s", 2, data);
+
+ printf("\tEnvironment: %s\n", country_env_str(data[2]));
+
+ data += 3;
+ len -= 3;
+
+ if (len < 3) {
+ printf("\t\tNo country IE triplets present\n");
+ return;
+ }
+
+ while (len >= 3) {
+ int end_channel;
+ struct ieee80211_country_ie_triplet *triplet =
+ (struct ieee80211_country_ie_triplet *) data;
+
+ if (triplet->ext.reg_extension_id >= IEEE80211_COUNTRY_EXTENSION_ID) {
+ printf("\t\tExtension ID: %d Regulatory Class: %d Coverage class: %d (Approx %d meters)\n",
+ triplet->ext.reg_extension_id,
+ triplet->ext.reg_class,
+ triplet->ext.coverage_class,
+ coverage_class_to_distance(triplet->ext.coverage_class));
+
+ data += 3;
+ len -= 3;
+ continue;
+ }
+
+ /* 2 GHz */
+ if (triplet->chans.first_channel <= 14)
+ end_channel = triplet->chans.first_channel + (triplet->chans.num_channels - 1);
+ else
+ end_channel = triplet->chans.first_channel + (4 * (triplet->chans.num_channels - 1));
+
+ printf("\t\tChannels [%d - %d]\n", triplet->chans.first_channel, end_channel);
+
+ data += 3;
+ len -= 3;
+ }
+
+ return;
}
static void print_powerconstraint(const uint8_t type, uint8_t len, const uint8_t *data)
--
1.6.3.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] iw: add country IE parsing
2010-01-20 18:20 ` Marcel Holtmann
2010-01-20 18:23 ` Johannes Berg
@ 2010-01-20 18:23 ` Luis R. Rodriguez
1 sibling, 0 replies; 9+ messages in thread
From: Luis R. Rodriguez @ 2010-01-20 18:23 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: johannes, linux-wireless
On Wed, Jan 20, 2010 at 10:20 AM, Marcel Holtmann <marcel@holtmann.org> wrote:
> Hi Luis,
>
>> I've considered showing only the channel set from the Country IE
>> but since cfg80211 now mangles contigious channel sets together
>> it seems more useful for iw to just display the individual triplets
>> separately so this patch is left intact. The triplet print is
>> kept since technically speaking this should also show the
>> regulatory extension stuff when one is found.
>
> looks like this with my Apple Airport if anyone cares:
>
> Country: CA Environment: Indoor/Outdoor
> Country IE triplets:
> Channels [1 - 11]
And like this for stupid APs:
Country: US Environment: Indoor/Outdoor
Country IE triplets:
Channels [36 - 36]
Channels [40 - 40]
Channels [44 - 44]
Channels [48 - 48]
Channels [52 - 52]
Channels [56 - 56]
Channels [60 - 60]
Channels [64 - 64]
Channels [100 - 100]
Channels [104 - 104]
Channels [108 - 108]
Channels [112 - 112]
Channels [116 - 116]
Channels [120 - 120]
Channels [124 - 124]
Channels [128 - 128]
Channels [132 - 132]
Channels [136 - 136]
Channels [140 - 140]
Channels [149 - 149]
Channels [153 - 153]
Channels [157 - 157]
Channels [161 - 161]
Channels [165 - 165]
I noted to Johannes maybe we should add a debug flag for scan and let
the parsers have the option to either output some debug format (as the
one above) or short form, for which the above would just show:
Channels [36 - 36]
Channels [100 - 165]
Anyway I am posting this again just because I've already have had a
use for this for a couple of users I help out when debugging country
IE stuff. Figured its better merged than to keep referring to external
patches.
Luis
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] iw: add country IE parsing
2010-01-20 18:20 ` Marcel Holtmann
@ 2010-01-20 18:23 ` Johannes Berg
2010-01-20 18:23 ` Luis R. Rodriguez
1 sibling, 0 replies; 9+ messages in thread
From: Johannes Berg @ 2010-01-20 18:23 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: Luis R. Rodriguez, linux-wireless
[-- Attachment #1: Type: text/plain, Size: 779 bytes --]
On Wed, 2010-01-20 at 10:20 -0800, Marcel Holtmann wrote:
> > I've considered showing only the channel set from the Country IE
> > but since cfg80211 now mangles contigious channel sets together
> > it seems more useful for iw to just display the individual triplets
> > separately so this patch is left intact. The triplet print is
> > kept since technically speaking this should also show the
> > regulatory extension stuff when one is found.
>
> looks like this with my Apple Airport if anyone cares:
>
> Country: CA Environment: Indoor/Outdoor
> Country IE triplets:
> Channels [1 - 11]
So I would still like to see it formatted as one
Foo:
per IE, so in this case someting like
Country: CA Environment:
Channels [1 - 11]
etc.
johannes
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] iw: add country IE parsing
2010-01-20 17:51 Luis R. Rodriguez
@ 2010-01-20 18:20 ` Marcel Holtmann
2010-01-20 18:23 ` Johannes Berg
2010-01-20 18:23 ` Luis R. Rodriguez
0 siblings, 2 replies; 9+ messages in thread
From: Marcel Holtmann @ 2010-01-20 18:20 UTC (permalink / raw)
To: Luis R. Rodriguez; +Cc: johannes, linux-wireless
Hi Luis,
> I've considered showing only the channel set from the Country IE
> but since cfg80211 now mangles contigious channel sets together
> it seems more useful for iw to just display the individual triplets
> separately so this patch is left intact. The triplet print is
> kept since technically speaking this should also show the
> regulatory extension stuff when one is found.
looks like this with my Apple Airport if anyone cares:
Country: CA Environment: Indoor/Outdoor
Country IE triplets:
Channels [1 - 11]
Regards
Marcel
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] iw: add country IE parsing
@ 2010-01-20 17:51 Luis R. Rodriguez
2010-01-20 18:20 ` Marcel Holtmann
0 siblings, 1 reply; 9+ messages in thread
From: Luis R. Rodriguez @ 2010-01-20 17:51 UTC (permalink / raw)
To: johannes; +Cc: linux-wireless, Luis R. Rodriguez
Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
---
I've considered showing only the channel set from the Country IE
but since cfg80211 now mangles contigious channel sets together
it seems more useful for iw to just display the individual triplets
separately so this patch is left intact. The triplet print is
kept since technically speaking this should also show the
regulatory extension stuff when one is found.
scan.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 70 insertions(+), 17 deletions(-)
diff --git a/scan.c b/scan.c
index 999aba4..26e07e6 100644
--- a/scan.c
+++ b/scan.c
@@ -36,6 +36,23 @@ struct scan_params {
bool show_both_ie_sets;
};
+#define IEEE80211_COUNTRY_EXTENSION_ID 201
+
+struct ieee80211_country_ie_triplet {
+ union {
+ struct {
+ __u8 first_channel;
+ __u8 num_channels;
+ __s8 max_power;
+ } __attribute__ ((packed)) chans;
+ struct {
+ __u8 reg_extension_id;
+ __u8 reg_class;
+ __u8 coverage_class;
+ } __attribute__ ((packed)) ext;
+ };
+} __attribute__ ((packed));
+
static int handle_scan(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
@@ -143,29 +160,65 @@ static void print_ds(const uint8_t type, uint8_t len, const uint8_t *data)
printf(" channel %d\n", data[0]);
}
-static void print_country(const uint8_t type, uint8_t len, const uint8_t *data)
+static const char *country_env_str(char environment)
{
- int i;
-
- printf(" %.*s", 2, data);
- switch (data[2]) {
+ switch (environment) {
case 'I':
- printf(" (indoor)");
- break;
+ return "Indoor only";
case 'O':
- printf(" (outdoor)");
- break;
+ return "Outdoor only";
case ' ':
- printf(" (in/outdoor)");
- break;
+ return "Indoor/Outdoor";
default:
- printf(" (invalid environment)");
- break;
+ return "bogus";
}
- printf(", data:");
- for(i=0; i<len-3; i++)
- printf(" %.02x", data[i + 3]);
- printf("\n");
+}
+
+static void print_country(const uint8_t type, uint8_t len, const uint8_t *data)
+{
+ printf(" %.*s", 2, data);
+
+ printf("\tEnvironment: %s\n", country_env_str(data[2]));
+
+ data += 3;
+ len -= 3;
+
+ if (len < 3) {
+ printf("\t\tNo country IE triplets present\n");
+ return;
+ }
+
+ printf("\tCountry IE triplets:\n");
+
+ while (len >= 3) {
+ int end_channel;
+ struct ieee80211_country_ie_triplet *triplet =
+ (struct ieee80211_country_ie_triplet *) data;
+
+ if (triplet->ext.reg_extension_id >= IEEE80211_COUNTRY_EXTENSION_ID) {
+ printf("\t\tExtension ID: %d Regulatory Class: %d Coverage class: %d\n",
+ triplet->ext.reg_extension_id,
+ triplet->ext.reg_class,
+ triplet->ext.coverage_class);
+
+ data += 3;
+ len -= 3;
+ continue;
+ }
+
+ /* 2 GHz */
+ if (triplet->chans.first_channel <= 14)
+ end_channel = triplet->chans.first_channel + (triplet->chans.num_channels - 1);
+ else
+ end_channel = triplet->chans.first_channel + (4 * (triplet->chans.num_channels - 1));
+
+ printf("\t\tChannels [%d - %d]\n", triplet->chans.first_channel, end_channel);
+
+ data += 3;
+ len -= 3;
+ }
+
+ return;
}
static void print_powerconstraint(const uint8_t type, uint8_t len, const uint8_t *data)
--
1.6.3.3
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2010-02-19 18:54 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-18 2:13 [PATCH] iw: add country IE parsing Luis R. Rodriguez
2010-02-18 7:16 ` Gabor Juhos
2010-02-18 21:40 ` Lukáš Turek
2010-02-19 18:54 ` Luis R. Rodriguez
-- strict thread matches above, loose matches on Subject: below --
2010-02-18 2:06 Luis R. Rodriguez
2010-01-20 17:51 Luis R. Rodriguez
2010-01-20 18:20 ` Marcel Holtmann
2010-01-20 18:23 ` Johannes Berg
2010-01-20 18:23 ` Luis R. Rodriguez
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.