From patchwork Sat Oct 26 20:34:15 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 3098751 Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2208B9F2B7 for ; Sat, 26 Oct 2013 20:41:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 53860202EC for ; Sat, 26 Oct 2013 20:41:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6DC88202C3 for ; Sat, 26 Oct 2013 20:41:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754049Ab3JZUkp (ORCPT ); Sat, 26 Oct 2013 16:40:45 -0400 Received: from mail-ea0-f171.google.com ([209.85.215.171]:62880 "EHLO mail-ea0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753983Ab3JZUkl (ORCPT ); Sat, 26 Oct 2013 16:40:41 -0400 Received: by mail-ea0-f171.google.com with SMTP id n15so1394931ead.2 for ; Sat, 26 Oct 2013 13:40:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=4Q8ww0d6i3aiDxrLxBYglgEYtn8qaa/00h6cVcUIUZA=; b=PAyirxakhnzmGnwi6kRPMG3P/Ef37etPvRgICcnQ7uNxMNtPM2SBJP1LXeVEp7U+HL lJCYCWDOq3Xb3QZf10rt/dItI1EGly+dWVOCZqnefUftdlQ8qypzrPsRc45X5fEWbab0 wr0MA7iAl6UUrS7cM5qytJceFXV6QmqLA/X9cuWgQJtRH02mq1Tb8RB15cm4Zf7PXL17 pZQNlYc4XHeJo3WDi+hoSWa15AhBKe5OC8TnCA3QFFRtCO4rYiguSL3LRSFyvo8VejSf omIg1s5+hZjL2Ovk/ipTHJNDuldvL5DydGs5Lp53BcmowLdmrV9cDoo3MEIL34hkYdp1 qB2Q== X-Received: by 10.14.172.133 with SMTP id t5mr13884517eel.35.1382820040056; Sat, 26 Oct 2013 13:40:40 -0700 (PDT) Received: from Pali-EliteBook.kolej.mff.cuni.cz (pali.kolej.mff.cuni.cz. [78.128.193.202]) by mx.google.com with ESMTPSA id i1sm35327553eeg.0.2013.10.26.13.40.39 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 26 Oct 2013 13:40:39 -0700 (PDT) From: =?UTF-8?q?Pali=20Roh=C3=A1r?= To: Luciano Coelho , "John W. Linville" , Johannes Berg , "David S. Miller" Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, freemangordon@abv.bg, aaro.koskinen@iki.fi, pavel@ucw.cz, sre@ring0.de, joni.lapilainen@gmail.com, pali.rohar@gmail.com Subject: [PATCH 16/16] wl1251: Add sysfs file address for setting permanent mac address Date: Sat, 26 Oct 2013 22:34:15 +0200 Message-Id: <1382819655-30430-17-git-send-email-pali.rohar@gmail.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1382819655-30430-1-git-send-email-pali.rohar@gmail.com> References: <1382819655-30430-1-git-send-email-pali.rohar@gmail.com> MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Driver wl1251 generating mac address randomly at startup and there is no way to set permanent mac address via SET_IEEE80211_PERM_ADDR. This patch export sysfs file which can set permanent mac address by userspace helper program. Patch is needed for devices which do not store mac address in internal wl1251 eeprom. Signed-off-by: Pali Rohár --- drivers/net/wireless/ti/wl1251/main.c | 52 +++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/net/wireless/ti/wl1251/main.c b/drivers/net/wireless/ti/wl1251/main.c index 29625c2..91a009c 100644 --- a/drivers/net/wireless/ti/wl1251/main.c +++ b/drivers/net/wireless/ti/wl1251/main.c @@ -1375,6 +1375,46 @@ static const struct ieee80211_ops wl1251_ops = { .get_survey = wl1251_op_get_survey, }; +static ssize_t wl1251_sysfs_show_address(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct wl1251 *wl = dev_get_drvdata(dev); + ssize_t len; + + /* FIXME: what's the maximum length of buf? page size?*/ + len = 500; + + len = snprintf(buf, len, "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x\n", + wl->mac_addr[0], wl->mac_addr[1], wl->mac_addr[2], + wl->mac_addr[3], wl->mac_addr[4], wl->mac_addr[5]); + + return len; +} + +static ssize_t wl1251_sysfs_store_address(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct wl1251 *wl = dev_get_drvdata(dev); + unsigned int addr[6]; + int ret, i; + + ret = sscanf(buf, "%2x:%2x:%2x:%2x:%2x:%2x\n", + &addr[0], &addr[1], &addr[2], + &addr[3], &addr[4], &addr[5]); + + if (ret != 6) + return -EINVAL; + + for (i = 0; i < 6; i++) + wl->mac_addr[i] = addr[i] & 0xff; + + SET_IEEE80211_PERM_ADDR(wl->hw, wl->mac_addr); + + return count; +} + static ssize_t wl1251_sysfs_show_tx_mgmt_frm_rate(struct device *dev, struct device_attribute *attr, char *buf) @@ -1584,6 +1624,10 @@ out: return count; } +static DEVICE_ATTR(address, S_IRUGO | S_IWUSR, + wl1251_sysfs_show_address, + wl1251_sysfs_store_address); + static DEVICE_ATTR(tx_mgmt_frm_rate, S_IRUGO | S_IWUSR, wl1251_sysfs_show_tx_mgmt_frm_rate, wl1251_sysfs_store_tx_mgmt_frm_rate); @@ -1728,6 +1772,14 @@ int wl1251_init_ieee80211(struct wl1251 *wl) } dev_set_drvdata(&wl1251_device.dev, wl); + /* Create sysfs file address */ + ret = device_create_file(&wl1251_device.dev, + &dev_attr_address); + if (ret < 0) { + wl1251_error("failed to create sysfs file address"); + goto out; + } + /* Create sysfs file tx_mgmt_frm_rate */ ret = device_create_file(&wl1251_device.dev, &dev_attr_tx_mgmt_frm_rate);