1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice

Welcome To SNBForums

SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.

If you'd like to post a question, simply register and have at it!

While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!

Raspberry Pi Zero W as USB Ethernet Gadget Not Working

Discussion in 'Asuswrt-Merlin' started by bennor, Apr 18, 2019.

  1. bennor

    bennor Occasional Visitor

    Joined:
    Mar 26, 2018
    Messages:
    37
    Are there any special settings that need to be enabled/changed to get USB Ethernet Gadget (Pi Zero W) to work with Merlin firmware 394.10_2? What I'm finding is the MAC address of the Pi Zero W USB Ethernet Gadget appears to be randomly generated by the Merlin firmware rather than pulling the MAC address from the Pi Zero W.

    On the Pi Zero W the following values have been set and do work when connected to a Windows PC. 00:22:82:ff:ff:22 is the fake MAC address used for the Pi Zero.

    config.txt: dtoverlay=dwc2
    cmdline.txt (after rootwait): modules-load=dwc2,g_ether g_ether.dev_addr=00:22:82:ff:ff:22


    What appears to be happening is every time the Pi Zero W is connected to the router's USB 2.0 port the Merlin firmware generates a line similar to the following with the CDC Ethernet Device address being changed.

    Apr 18 10:08:13 kernel: cdc_ether 2-2:1.0: usb0: register 'cdc_ether' at usb-0000:00:0b.0-2, CDC Ethernet Device, 2e:24:df:a7:6f:8c

    The end result is the router does not see or access the Pi Zero as an USB Ethernet type device. The Pi Zero is unreachable using SSH on the local network. Setting a static IP address using either the Pi Zero W fake MAC address or the firmware generated MAC address does not work to allow access to the Pi Zero W.

    I have tried various methods detailed elsewhere for setting a Pi Zero up for USB Ethernet Gadget. Tried both new and used microSD cards using the Raspberry 2019-04-08-raspbian-stretch-lite image file. With the edits previously mentioned. The Merlin firmware just doesn't seem to want to properly mount the Pi Zero W.

    Any suggestions or ideas?
    Thanks
     
  2. ColinTaylor

    ColinTaylor Part of the Furniture

    Joined:
    Mar 31, 2014
    Messages:
    8,327
    Location:
    UK
    The router doesn't support that kind of device.
     
    L&LD likes this.
  3. sfx2000

    sfx2000 Part of the Furniture

    Joined:
    Aug 11, 2011
    Messages:
    13,998
    Location:
    San Diego, CA
    Do a search on the forums, as I believe someone did get USB gadgets working... might have been on one of the HND based Asus routers, not the older 2.6 kernel...

    At least for power - Pi Zero W at max load pulls around 230 mA, which is within the capability of the USB port on the router...

    Pi-Power-Usage-Zero-W-table-768x184.png
     
  4. bennor

    bennor Occasional Visitor

    Joined:
    Mar 26, 2018
    Messages:
    37
    Did some searching before posting didn't see anything offhand. But after additional searching there is this thread from 2016 where it appears it might be possible with some extra scripting.

    https://www.snbforums.com/threads/run-script-on-usb-ethernet-gadget-plugged-in.34898/

    I currently have the Pi Zero W being powered by the router's USB 2.0 port and a USB-OTG cable with USB 2.0 to Ethernet adapter attached to it, was just looking for a way to reduce cutter and experiment with different methods by using the USB Ethernet Gadget
     
  5. bennor

    bennor Occasional Visitor

    Joined:
    Mar 26, 2018
    Messages:
    37
    After some experimentation one can connect the Pi Zero W to the Asus router (AC68U running Merlin at least) and have the Zero show up as a USB Ethernet Gadget connected wire device with an IP address assigned by the router.

    On the Pi Zero in the Boot folder edit the file config.txt and put the following code at the bottom:
    Code:
    dtoverlay=dwc2
    On the Pi Zero in the Boot folder edit the file cmdline.txt (Warning: if using Windows Note Pad turn off word wrap) and add the following code after rootwait (at the end of the line). When done one should have one single line of code.
    Code:
    modules-load=dwc2,g_ether
    Connect USB cable to the Pi Zero W's micro USB port, not the micro USB power port, connect the other end of the cable to the Asus router's USB port (I used the USB 2.0 port). The Pi will power on. No other cables or adapters are needed on the Pi.

    On the Asus router issue the following two commands via SSH:
    Code:
    ifconfig usb0 up
    brctl addif br0 usb0
    Problems:
    The router will assign a random MAC address to the Pi Zero W every time the Pi Zero W USB Ethernet Gadget device is connected. No matter what MAC address was assigned in the cmdline.txt file using g_ether.host_addr=<MAC Address>, the router would assign a random MAC address anyway to the Pi Zero W.

    After issuing the two router commands, the router will issue a random IP address (from the DHCP IP address pool) to the Pi Zero W.

    If the router or Pi Zero W is rebooted one must to reissue the two router commands. This presents obvious problems that might be solvable via additional scripting per discussions in this thread.

    If one is trying to use the Pi Zero W as a Pi-Hole or other service that requires a static IP address assigned to the Pi this presents a problem (when using the Pi Zero W via USB Ethernet Gadget) since the IP address and MAC address are changed each time the Pi or router is restarted and the two router commands issued.
     
    Last edited: Apr 19, 2019
    oso2276 and L&LD like this.
  6. bennor

    bennor Occasional Visitor

    Joined:
    Mar 26, 2018
    Messages:
    37
    Some updates: To fix the random MAC address being assigned the following worked for me.'

    With the Pi Zero W connected to the router and mounted with the router SSH two commands above, connect to the Pi via SSH and issue the following command which will create a file called g_ether.conf:
    Code:
    echo 'options g_ether host_addr='$(dmesg | awk '/: HOST MAC/{print $NF}')' dev_addr='$(dmesg | awk '/: MAC/{print $NF}') | sudo tee /etc/modprobe.d/g_ether.conf
    Make note/copy the output text as you will need it for the cmdline.txt file. It should look something like this:
    Code:
    options g_ether host_addr=82:ac:db:0f:e9:74 dev_addr=1e:30:e9:48:84:95
    While still connected to the Pi via SSH issue the following command and paste the g_ether information at the end after “modules-load=dwc2,g_ether”. Keep everything on one single line. Make sure to use the values that match the output from your router.
    Code:
    sudo nano /boot/cmdline.txt
    g_ether host_addr=82:ac:db:0f:e9:74 dev_addr=1e:30:e9:48:84:95
    Example after the rootwait text: modules-load=dwc2,g_ether g_ether host_addr=82:ac:db:0f:e9:74 dev_addr=1e:30:e9:48:84:95

    Reboot the Pi Zero W.

    Then reissue the two router SSH commands (ifconfig usb0 up & brctl addif br0 usb0) to mount the Pi Zero W in the router. The Pi should be mounted with the same MAC address now.

    Additionally one can now create a static IP address on the router's DHCP server so the Pi mounts each time with the same IP address.

    Note: There is still the issue of having to reissue the two router commands each time the Pi or router is restarted. This may possibly be fixed by using the scripting mentioned in a URL above. There is also the issue (now) that the Pi may have trouble accessing the internet using website URL names versus website URL values/numbers.
     
    L&LD likes this.
  7. bennor

    bennor Occasional Visitor

    Joined:
    Mar 26, 2018
    Messages:
    37
    Another minor update. Found that by using the Pi Zero W MAC address (for eth0) in the
    dev_addr= entry above it solved the inability to ping/access by website name (ex: www.google.com).

    So if using info above replace the MAC address in the dev_addr= with your own Pi Zero W's MAC address.

    Also discovered (at least for me) that if one has a static IP address, within the router, already set with the Pi Zero W's Ethernet (eth0) MAC address one may need to change that IP address to something else (or remove it) otherwise the Pi Zero W's usb0 connection may not load after issuing the two router commands.
     
    L&LD likes this.
  8. bennor

    bennor Occasional Visitor

    Joined:
    Mar 26, 2018
    Messages:
    37
    More updates. Now have the Pi Zero loading automatically when inserted into the router by following the procedures in this post: https://www.snbforums.com/threads/run-script-on-usb-ethernet-gadget-plugged-in.34898/#post-283331

    Note: copy the code from “/etc/hotplug2.rules” to paste into “/jffs/hotplug2.rules” file in the directions in the link above as the code in the current /etc/hotplug2.rules may be different than the one used in the link above. Then modified the code as indicated in the link's instructions.

    Needed to set permissions on the following two files. I set the permission to 0755.
    /jffs/scripts/init-start
    /jffs/scripts/script_hotplug.sh

    And set the permission to 0644 on the following file:
    /jffs/hotplug2.rules

    If using Pi-Hole one will have to run "pihole –r" on the Pi Zero W then select "Reconfigure" to rerun the Pi-Hole setup so it properly configures to use the new fixed IP address and use usb0 rather than eth0.
     
    dokape, JGrana and L&LD like this.