meta-quanta: common: set locally administered bit to usb-network
We hope the MAC address of the usb-network is locally administered address,
so it needs to set locally administered bit (0x02) to the first octet of the
MAC address.
(From meta-quanta rev: ebe01d25bbb5b139feb7c9b089f322e45a28a68e)
Signed-off-by: George Hung <george.hung@quantatw.com>
Change-Id: I9bd0702359479514b385daf447a9747fd270e351
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
diff --git a/meta-quanta/meta-common/recipes-quanta/network/usb-network/usb-network.sh b/meta-quanta/meta-common/recipes-quanta/network/usb-network/usb-network.sh
index 444d4ae..6840f9f 100644
--- a/meta-quanta/meta-common/recipes-quanta/network/usb-network/usb-network.sh
+++ b/meta-quanta/meta-common/recipes-quanta/network/usb-network/usb-network.sh
@@ -1,5 +1,25 @@
#!/bin/bash
+mac_config="/usr/share/mac-address/config.txt"
+dev_mac_path="/tmp/usb0_dev"
+host_mac_path="/tmp/usb0_host"
+
+check_usb_local_administered() {
+ is_enable="$(cat ${mac_config} | grep 'USBLAA')"
+ echo ${is_enable}
+}
+
+# Set the locally administered bit (the second least-significant
+# bit of the first octet) of the MAC address
+set_local_administered_bit() {
+ mac="$(cat $1)"
+ first_byte="${mac:0:2}"
+ first_byte="$((0x$first_byte|2))"
+ first_byte="$(printf "%02x\n" "$first_byte")"
+ mac="${first_byte}${mac:2}"
+ echo $mac
+}
+
cd /sys/kernel/config/usb_gadget
if [ ! -f "g1" ]; then
@@ -17,16 +37,24 @@
mkdir -p configs/c.1/strings/0x409
echo "ECM" > configs/c.1/strings/0x409/configuration
+
+ if [[ $(check_usb_local_administered) == "USBLAA=true" ]]; then
+ dev_mac="$(set_local_administered_bit $dev_mac_path)"
+ host_mac="$(set_local_administered_bit $host_mac_path)"
+ echo $dev_mac > $dev_mac_path
+ echo $host_mac > $host_mac_path
+ fi
+
mkdir -p functions/ecm.usb0
- cat /tmp/usb0_dev > functions/ecm.usb0/dev_addr # write device mac address
- cat /tmp/usb0_host > functions/ecm.usb0/host_addr # write usb mac address
+ cat $dev_mac_path > functions/ecm.usb0/dev_addr # write device mac address
+ cat $host_mac_path > functions/ecm.usb0/host_addr # write usb mac address
ln -s functions/ecm.usb0 configs/c.1
echo "$UDC" > UDC
- rm /tmp/usb0_dev
- rm /tmp/usb0_host
+ rm $dev_mac_path
+ rm $host_mac_path
fi