From patchwork Sun Jun 23 13:07:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igal Chernobelsky X-Patchwork-Id: 253467 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "maxx.shmoo.com", Issuer "CA Cert Signing Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 7853F2C040F for ; Sun, 23 Jun 2013 23:08:10 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 65ABD9C14F; Sun, 23 Jun 2013 09:08:06 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CKMStjlR4YMJ; Sun, 23 Jun 2013 09:08:06 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id E3C659C16C; Sun, 23 Jun 2013 09:08:00 -0400 (EDT) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id CFCC89C14F for ; Sun, 23 Jun 2013 09:07:58 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id soPsofesB6tv for ; Sun, 23 Jun 2013 09:07:53 -0400 (EDT) Received: from devils.ext.ti.com (devils.ext.ti.com [198.47.26.153]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "mailhost.ti.com", Issuer "VeriSign Class 3 Secure Server CA - G3" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id DF3939C12C for ; Sun, 23 Jun 2013 09:07:52 -0400 (EDT) Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id r5ND7piv015167 for ; Sun, 23 Jun 2013 08:07:51 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id r5ND7pwU027628; Sun, 23 Jun 2013 08:07:51 -0500 Received: from dlelxv22.itg.ti.com (172.17.1.197) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.2.342.3; Sun, 23 Jun 2013 08:07:50 -0500 Received: from ubtsrv4.isr.asp.ti.com (ubtsrv4.isr.asp.ti.com [10.166.2.72]) by dlelxv22.itg.ti.com (8.13.8/8.13.8) with ESMTP id r5ND7ncC032732; Sun, 23 Jun 2013 08:07:50 -0500 From: Igal Chernobelsky To: Subject: [PATCH] driver_nl80211: set_country fix Date: Sun, 23 Jun 2013 16:07:46 +0300 Message-ID: <1371992866-18168-1-git-send-email-igalc@ti.com> X-Mailer: git-send-email 1.7.9 MIME-Version: 1.0 Cc: mcs-mac80211@list.ti.com, igalc@ti.com X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.11 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com Regulatory domain setting may take some time. Getting reg domain info immediately after reg domain setting returns invalid reg domain data. Loop is added to read reg domain info back and to compare set country. If read country does not match, fail to 1 sec sleep and retry get/compare again. Signed-off-by: Igal Chernobelsky --- src/drivers/driver_nl80211.c | 53 +++++++++++++++++++++++++++++++++++++++++- 1 files changed, 52 insertions(+), 1 deletions(-) diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c index f705a0c..cc5084b 100644 --- a/src/drivers/driver_nl80211.c +++ b/src/drivers/driver_nl80211.c @@ -2689,6 +2689,37 @@ static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, } +static int get_country_handler(struct nl_msg *msg, void *arg) +{ + char * alpha2 = (char *) arg; + struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); + + nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), + genlmsg_attrlen(gnlh, 0), NULL); + if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { + wpa_printf(MSG_DEBUG, "nl80211: No country information " + "available"); + return NL_SKIP; + } + os_memcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); + return NL_SKIP; +} + +static int nl80211_get_country(struct wpa_driver_nl80211_data *drv, + char *alpha2) +{ + struct nl_msg *msg; + + msg = nlmsg_alloc(); + if (!msg) + return -ENOMEM; + + nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); + return send_and_recv_msgs(drv, msg, get_country_handler, alpha2); +} + + /** * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain * @priv: driver_nl80211 private data @@ -2703,7 +2734,10 @@ static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) struct i802_bss *bss = priv; struct wpa_driver_nl80211_data *drv = bss->drv; char alpha2[3]; + char alpha2_res[3]; struct nl_msg *msg; + int count; + int ret; msg = nlmsg_alloc(); if (!msg) @@ -2718,7 +2752,24 @@ static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, alpha2); if (send_and_recv_msgs(drv, msg, NULL, NULL)) return -EINVAL; - return 0; + + /* Validate coutry setting and retry up to 3 times if not match */ + for (count = 0; count < 3; count++) { + os_memset(alpha2_res, 0, sizeof(alpha2)); + ret = nl80211_get_country(drv, alpha2_res); + if (ret) + return ret; + if (os_strncmp(alpha2, alpha2_res, 3)) { + wpa_printf(MSG_DEBUG, "wpa_driver_nl80211_set_country:" + "retry country set after delay"); + os_sleep(1, 0); + } else { + /* contry set is completed */ + return 0; + } + } + wpa_printf(MSG_ERROR, "wpa_driver_nl80211_set_country: failed"); + return -EINVAL; nla_put_failure: nlmsg_free(msg); return -EINVAL;