Re: [OpenWrt-Devel] [PATCH 3/7] [package] mac80211: Use PCS wifi mac address logic for PCS devices

2012-11-10 Thread Felix Fietkau
On 2012-11-09 11:10 PM, Daniel Dickinson wrote:
 ---
  package/mac80211/files/lib/wifi/mac80211.sh |   38 
 ---
  1 file changed, 34 insertions(+), 4 deletions(-)
 
 diff --git a/package/mac80211/files/lib/wifi/mac80211.sh 
 b/package/mac80211/files/lib/wifi/mac80211.sh
 index ad5845b..873332d 100644
 --- a/package/mac80211/files/lib/wifi/mac80211.sh
 +++ b/package/mac80211/files/lib/wifi/mac80211.sh
 @@ -295,15 +295,37 @@ get_freq() {
  mac80211_generate_mac() {
   local off=$1
   local mac=$2
 + local radio=$3
   local oIFS=$IFS; IFS=:; set -- $mac; IFS=$oIFS
  
 - local b2mask=0x00
 - [ $off -gt 0 ]  b2mask=0x02
  
 - printf %02x:%s:%s:%s:%02x:%02x \
 + # For cr5000 and cap324 the manufacturer has reserved
 +# MAC addresses such that wifi vifs get unique addresses
 + # with their OUI.  The models are not necessarily able
 +# to be determined by anything other than a file in the
 +# firmware (i.e. the board definitions sometimes are
 + # shared with other users of the same basic device, therefore
 + # we use a special file to determine if it's an applicable device).
 +
 + if [ -s /usr/cloud/model ]; then
 + case model in $(cat /usr/cloud/model)
 + cr5000 | cap324 )   
 + printf %s:%s:%s:%02x:%s:%s\n \
 + $1 $2 $3 \
 + $(( ( 0x$4  0xf0 ) | $off )) \
 + $5 $6
 +
 + ;;
 + esac
 +else
 + local b2mask=0x00
 + [ $off -gt 0 ]  b2mask=0x02
 +
 + printf %02x:%s:%s:%s:%02x:%02x \
   $(( 0x$1 | $b2mask )) $2 $3 $4 \
   $(( (0x$5 + ($off / 0x100)) % 0x100 )) \
   $(( (0x$6 + $off) % 0x100 ))
 + fi
  }
  
  enable_mac80211() {
 @@ -398,7 +420,15 @@ enable_mac80211() {
   config_get macaddr $device macaddr
   config_get vif_mac $vif macaddr
   [ -n $vif_mac ] || {
 - vif_mac=$(mac80211_generate_mac $macidx $macaddr)
 + if [ -s /usr/cloud/model ]; then
 + case model in $(cat /usr/cloud/model)
 + cr5000 | cap324 )
 + vif_mac=$(mac80211_generate_mac 
 $macidx${device#radio} $macaddr)
 + ;;
 + esac
 + else
 + vif_mac=$(mac80211_generate_mac $macidx 
 $macaddr)
 + fi
   macidx=$(($macidx + 1))
   }
   [ $mode = ap ] || ifconfig $ifname hw ether $vif_mac
 
Why the /usr/cloud/model hack? Can you find a more generic way to
abstract this instead of hardcoding model specific stuff in the mac80211
script?

- Felix
___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


[OpenWrt-Devel] [PATCH 3/7] [package] mac80211: Use PCS wifi mac address logic for PCS devices

2012-11-09 Thread Daniel Dickinson
---
 package/mac80211/files/lib/wifi/mac80211.sh |   38 ---
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/package/mac80211/files/lib/wifi/mac80211.sh 
b/package/mac80211/files/lib/wifi/mac80211.sh
index ad5845b..873332d 100644
--- a/package/mac80211/files/lib/wifi/mac80211.sh
+++ b/package/mac80211/files/lib/wifi/mac80211.sh
@@ -295,15 +295,37 @@ get_freq() {
 mac80211_generate_mac() {
local off=$1
local mac=$2
+   local radio=$3
local oIFS=$IFS; IFS=:; set -- $mac; IFS=$oIFS
 
-   local b2mask=0x00
-   [ $off -gt 0 ]  b2mask=0x02
 
-   printf %02x:%s:%s:%s:%02x:%02x \
+   # For cr5000 and cap324 the manufacturer has reserved
+# MAC addresses such that wifi vifs get unique addresses
+   # with their OUI.  The models are not necessarily able
+# to be determined by anything other than a file in the
+# firmware (i.e. the board definitions sometimes are
+   # shared with other users of the same basic device, therefore
+   # we use a special file to determine if it's an applicable device).
+
+   if [ -s /usr/cloud/model ]; then
+   case model in $(cat /usr/cloud/model)
+   cr5000 | cap324 )   
+   printf %s:%s:%s:%02x:%s:%s\n \
+   $1 $2 $3 \
+   $(( ( 0x$4  0xf0 ) | $off )) \
+   $5 $6
+
+   ;;
+   esac
+else
+   local b2mask=0x00
+   [ $off -gt 0 ]  b2mask=0x02
+
+   printf %02x:%s:%s:%s:%02x:%02x \
$(( 0x$1 | $b2mask )) $2 $3 $4 \
$(( (0x$5 + ($off / 0x100)) % 0x100 )) \
$(( (0x$6 + $off) % 0x100 ))
+   fi
 }
 
 enable_mac80211() {
@@ -398,7 +420,15 @@ enable_mac80211() {
config_get macaddr $device macaddr
config_get vif_mac $vif macaddr
[ -n $vif_mac ] || {
-   vif_mac=$(mac80211_generate_mac $macidx $macaddr)
+   if [ -s /usr/cloud/model ]; then
+   case model in $(cat /usr/cloud/model)
+   cr5000 | cap324 )
+   vif_mac=$(mac80211_generate_mac 
$macidx${device#radio} $macaddr)
+   ;;
+   esac
+   else
+   vif_mac=$(mac80211_generate_mac $macidx 
$macaddr)
+   fi
macidx=$(($macidx + 1))
}
[ $mode = ap ] || ifconfig $ifname hw ether $vif_mac
-- 
1.7.9.5

___
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel