[From nobody Thu Jun 25 05:54:57 2020
Received: from mail2.candelatech.com ([208.74.158.173])
 by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux))
 id 1gXaLI-00073S-BI
 for openwrt-devel@lists.openwrt.org; Thu, 13 Dec 2018 23:24:33 +0000
Received: from ben-dt4.candelatech.com (firewall.candelatech.com
 [50.251.239.81])
 by mail2.candelatech.com (Postfix) with ESMTP id B92BC40A5CB;
 Thu, 13 Dec 2018 15:24:16 -0800 (PST)
DKIM-Filter: OpenDKIM Filter v2.11.0 mail2.candelatech.com B92BC40A5CB
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=candelatech.com;
 s=default; t=1544743457;
 bh=TseHQjaFcc1Vvd6CcbBXFXije8xR2vBTiHFtvxdxkKg=;
 h=From:To:Cc:Subject:Date:From;
 b=GY+RyUOzHi4GfjOJiW7qoxRM+QbfJ9K5dslI+rO6xjQvTUjBc/x9agq0Smn+D4UN7
 LAkYAPBcjga3+ShUlJUDcjCiLoFUu5plUCjwjK8Bc3/dD5CeW2wBNPxIPQc4beB25F
 OCwfZKFW3SCZS+6miSwpBIpJfRWsS8NhLbaUX5I0=
From: greearb@candelatech.com
To: openwrt-devel@lists.openwrt.org
Cc: Ben Greear &lt;greearb@candelatech.com&gt;
Subject: [PATCH] hotplug:  Allow renaming phy devices.
Date: Thu, 13 Dec 2018 15:24:12 -0800
Message-Id: &lt;20181213232412.9109-1-greearb@candelatech.com&gt;
X-Mailer: git-send-email 2.19.2
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 
X-CRM114-CacheID: sfid-20181213_152432_406973_9D626CE5 
X-CRM114-Status: UNSURE (   5.76  )
X-CRM114-Notice: Please train this message.
X-Spam-Score: -0.2 (/)
X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary:
 Content analysis details:   (-0.2 points)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 SPF_PASS               SPF: sender matches SPF record
 -0.1 DKIM_VALID_EF          Message has a valid DKIM or DK signature from
 envelope-from domain
 -0.1 DKIM_VALID_AU          Message has a valid DKIM or DK signature from
 author's domain
 -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature
 0.1 DKIM_SIGNED            Message has a DKIM or DK signature, not necessarily
 valid

From: Ben Greear &lt;greearb@candelatech.com&gt;

uci set wireless.@wifi-device[0].phyname=wiphy0

Then reboot and/or re-plug that device, and this will
name the phy wiphy0 instead of phy0, phy1, etc.

Signed-off-by: Ben Greear &lt;greearb@candelatech.com&gt;
---
 .../kernel/mac80211/files/mac80211.hotplug    | 32 +++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/package/kernel/mac80211/files/mac80211.hotplug b/package/kernel/mac80211/files/mac80211.hotplug
index b865552661..a394e3195e 100644
--- a/package/kernel/mac80211/files/mac80211.hotplug
+++ b/package/kernel/mac80211/files/mac80211.hotplug
@@ -3,3 +3,35 @@
 [ &quot;${ACTION}&quot; = &quot;add&quot; ] &amp;&amp; {
 	/sbin/wifi config
 }
+
+
+OPATH=${DEVPATH##/devices/platform/}
+OPATH=${OPATH%%/ieee*}
+
+# For USB, OPATH looks like this at this point in this script:
+# soc/soc:usb30@0/11000000.dwc3/xhci-hcd.0.auto/usb1/1-1/1-1:1.0
+# But, the uci path has a platform/ prefix on that:
+# platform/soc/soc:usb30@0/11000000.dwc3/xhci-hcd.0.auto/usb1/1-1/1-1:1.0
+OPATH_USB=&quot;platform/$OPATH&quot;;
+
+# 10 radios is enough for anyone!
+#echo &quot;fix-wifi-mac, OPATH: $OPATH&quot; &gt;&gt; /tmp/foo.txt
+for i in `seq 0 9`;
+  do
+  BUS=`uci get wireless.@wifi-device[$i].path`
+  #echo &quot;fix-wifi-mac, BUS[$i]: $BUS&quot; &gt;&gt; /tmp/foo.txt
+  if [ &quot;$BUS &quot; == &quot;$OPATH &quot; ] || [ &quot;$BUS &quot; == &quot;$OPATH_USB &quot; ]
+      then
+      PHYNAME=${DEVPATH##*ieee80211/}
+      NPHYNAME=`uci get wireless.@wifi-device[$i].phyname`
+      #echo &quot;fix-wifi-mac, PHYNAME[$i]: $PHYNAME  NPHYNAME: $NPHYNAME&quot; &gt;&gt; /tmp/foo.txt;
+      if [ &quot;$NPHYNAME &quot; != &quot; &quot; ]
+          then
+          if [ &quot;$PHYNAME &quot; != &quot;$NPHYNAME &quot; ]
+              then
+	      #echo &quot;fix-wifi-mac, renaming...&quot; &gt;&gt; /tmp/foo.txt;
+              iw $PHYNAME set name $NPHYNAME
+          fi
+      fi
+  fi
+done
-- 
2.19.2


]