linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Arend van Spriel" <arend@broadcom.com>
To: "John W. Linville" <linville@tuxdriver.com>
Cc: "Linux Wireless List" <linux-wireless@vger.kernel.org>,
	"Arend van Spriel" <arend@broadcom.com>
Subject: [PATCH 8/9] brcm80211: smac: only provide valid regulatory hint
Date: Wed, 11 Apr 2012 11:52:50 +0200	[thread overview]
Message-ID: <1334137971-3972-9-git-send-email-arend@broadcom.com> (raw)
In-Reply-To: <1334137971-3972-1-git-send-email-arend@broadcom.com>

The driver provides a regulatory hint to cfg80211 as obtained from the
SPROM. Mostly, this will be a two-letter ISO country code. However, it
may obtain special country code similar to the world regulatory domain
as used in cfg80211. This patch avoids setting these special codes as
the hint is lost to cfg80211.

Reviewed-by: Pieter-Paul Giesberts <pieterpg@broadcom.com>
Reviewed-by: Brett Rudley <brudley@broadcom.com>
Signed-off-by: Arend van Spriel <arend@broadcom.com>
---
 drivers/net/wireless/brcm80211/brcmsmac/channel.c |   36 ++++++++++++++++++++-
 1 files changed, 35 insertions(+), 1 deletions(-)

diff --git a/drivers/net/wireless/brcm80211/brcmsmac/channel.c b/drivers/net/wireless/brcm80211/brcmsmac/channel.c
index 55e9f45..0efe88e 100644
--- a/drivers/net/wireless/brcm80211/brcmsmac/channel.c
+++ b/drivers/net/wireless/brcm80211/brcmsmac/channel.c
@@ -628,6 +628,40 @@ brcms_c_country_aggregate_map(struct brcms_cm_info *wlc_cm, const char *ccode,
 	return false;
 }
 
+/*
+ * Indicates whether the country provided is valid to pass
+ * to cfg80211 or not.
+ *
+ * returns true if valid; false if not.
+ */
+static bool brcms_c_country_valid(const char *ccode)
+{
+	/*
+	 * only allow ascii alpha uppercase for the first 2
+	 * chars.
+	 */
+	if (!((0x80 & ccode[0]) == 0 && ccode[0] >= 0x41 && ccode[0] <= 0x5A &&
+	      (0x80 & ccode[1]) == 0 && ccode[1] >= 0x41 && ccode[1] <= 0x5A &&
+	      ccode[2] == '\0'))
+		return false;
+
+	/*
+	 * do not match ISO 3166-1 user assigned country codes
+	 * that may be in the driver table
+	 */
+	if (!strcmp("AA", ccode) ||        /* AA */
+	    !strcmp("ZZ", ccode) ||        /* ZZ */
+	    ccode[0] == 'X' ||             /* XA - XZ */
+	    (ccode[0] == 'Q' &&            /* QM - QZ */
+	     (ccode[1] >= 'M' && ccode[1] <= 'Z')))
+		return false;
+
+	if (!strcmp("NA", ccode))
+		return false;
+
+	return true;
+}
+
 /* Lookup a country info structure from a null terminated country
  * abbreviation and regrev directly with no translation.
  */
@@ -1089,7 +1123,7 @@ struct brcms_cm_info *brcms_c_channel_mgr_attach(struct brcms_c_info *wlc)
 
 	/* store the country code for passing up as a regulatory hint */
 	ccode = getvar(wlc->hw->sih, BRCMS_SROM_CCODE);
-	if (ccode)
+	if (ccode && brcms_c_country_valid(ccode))
 		strncpy(wlc->pub->srom_ccode, ccode, BRCM_CNTRY_BUF_SZ - 1);
 
 	/*
-- 
1.7.5.4



  parent reply	other threads:[~2012-04-11  9:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-11  9:52 [PATCH 0/9] brcm80211: minor bug fixes for broadcom driver Arend van Spriel
2012-04-11  9:52 ` [PATCH 1/9] brcm80211: fmac: make brcmf_net_attach() static Arend van Spriel
2012-04-11  9:52 ` [PATCH 2/9] brcm80211: fmac: remove primary mac address handling from brcmf_net_attach Arend van Spriel
2012-04-11  9:52 ` [PATCH 3/9] brcm80211: fmac: register primary net device with device mac address Arend van Spriel
2012-04-11  9:52 ` [PATCH 4/9] brcm80211: fmac: add frame header extension support Arend van Spriel
2012-04-11  9:52 ` [PATCH 5/9] brcm80211: fmac: postpone dongle RF enabling Arend van Spriel
2012-04-11  9:52 ` [PATCH 6/9] brcm80211: fmac: clean up chip id table Arend van Spriel
2012-04-11  9:52 ` [PATCH 7/9] brcm80211: smac: do not use US as fallback regulatory hint Arend van Spriel
2012-04-13 14:48   ` Seth Forshee
2012-04-16  8:20     ` Arend van Spriel
2012-04-11  9:52 ` Arend van Spriel [this message]
2012-04-11  9:52 ` [PATCH 9/9] brcm80211: smac: resume transmit fifo upon receiving frames Arend van Spriel
2012-04-13 17:57 ` [PATCH 0/9] brcm80211: minor bug fixes for broadcom driver John W. Linville
2012-04-16  8:51   ` Arend van Spriel
2012-04-16 17:18     ` John W. Linville

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=1334137971-3972-9-git-send-email-arend@broadcom.com \
    --to=arend@broadcom.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.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).