Gentoo Archives: gentoo-user

From: R0b0t1 <r030t1@×××××.com>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Ethernet-over-USB confusion
Date: Tue, 26 Jun 2018 18:44:31
Message-Id: CAAD4mYjKbpghbS0k1L=rrtLMxF_PSQ5naG92jP50t+Jfh9UrRw@mail.gmail.com
In Reply to: [gentoo-user] Ethernet-over-USB confusion by tuxic@posteo.de
1 On Tue, Jun 26, 2018 at 12:47 PM, <tuxic@××××××.de> wrote:
2 > Hi,
3 >
4 > short question:
5 >
6 > I want to access my Raspberry Pi Zero W via Ethernet-over-USB
7 > via ssh.
8 > On the Raspberry I have to include a module called g_ether.
9 > After rebooting I can see a new interface whith an IP assigned
10 > via ifconfig.
11 > On my PC I see a new inteface and dmesg tells me, that
12 > usb0 was renamed to a hillarious cryoted other name
13 > and this <name> also shows up when using ifconfig.
14 > But it has a complete different IP assigned,
15 >
16 > But I cannot ssh into the SoC even if the IP
17 > address is corrected manually.
18 >
19
20 Can you SSH into it at all via some other interface? Can you ping it?
21 Try g_multi so that you can have a serial terminal to log in with. If
22 possible switch to using g_ffs. I have included a script at the end of
23 my message which will create both CM and ACM (serial) endpoints.
24
25
26 On the device, bring up the interface and give a fixed static IP to
27 the interface. A route should be created but if not route everything
28 on that subnet through the gadget ethernet device.
29
30 On the host, bring up the interface and give a fixed static IP to the
31 interface. A route should be created but if not route everything on
32 that subnet through the gadget ethernet device.
33
34 It may be necessary to bring up the device first.
35
36 > What modules do I need loaded exactlu on the PC
37 > and on the SoC?
38 >
39
40 If usbX shows up and is renamed then you have the proper driver
41 loaded. There should be a message labelled "cdc_XXX." By default
42 g_ether should use CDC ECM (Ethernet control model), but it is also
43 possible to use CDC EEM (Ethernet emulation model), CDC NCM (network
44 control model), or RNDIS (remote network driver interface
45 specification, Windows).
46
47 Of the protocols ECM is the simplest, and in theory should have the
48 worst throughput do to inefficiency when wrapping Ethernet frames.
49 However in my tests it had the highest throughput by a few Mb/s
50 (~90Mbit). EEM and NCM were tied (88Mbit) though NCM is the newest and
51 may eventually surpass the others. RNDIS was slower by 10-15Mb/s
52 (70Mbit) and a full specification does not exist. However, it may be
53 necessary if you wish to easily use your device with Windows machines.
54
55 Cheers,
56 R0b0t1
57
58 ---
59
60 #!/bin/bash
61 set -euo pipefail
62
63 # General configuration:
64 GADGET_NAME="testgadget"
65 LANGUAGE=0x409
66 MANUFACTURER="R0b0t1"
67 PRODUCT="Test Gadget"
68
69 # Function configuration:
70 HOST_ADDRESS="1a:55:89:a2:69:42"
71 DEV_ADDRESS="1a:55:89:a2:69:41"
72
73
74 if [ "$EUID" -ne 0 ]; then
75 echo "This script must run as root."
76 exit 1
77 fi
78
79
80 echo "Loading libcomposite..."
81 CONFIGFS="/sys/kernel/config/usb_gadget"
82 GADGET="$CONFIGFS/$GADGET_NAME"
83 modprobe libcomposite
84
85 while [ ! -d $CONFIGFS ]; do
86 sleep 0.01
87 done
88
89
90 echo "Cleaning existing gadget..."
91 find $GADGET/configs/*/* -maxdepth 0 -type l -exec rm {} \; || true
92 find $GADGET/configs/*/strings/* -maxdepth 0 -type d -exec rmdir {} \; || true
93 find $GADGET/os_desc/* -maxdepth 0 -type l -exec rm {} \; || true
94 find $GADGET/functions/* -maxdepth 0 -type d -exec rmdir {} \; || true
95 find $GADGET/strings/* -maxdepth 0 -type d -exec rmdir {} \; || true
96 find $GADGET/configs/* -maxdepth 0 -type d -exec rmdir {} \; || true
97 rmdir $GADGET || true
98
99 #find "$GADGET/configs" -maxdepth 2 -type l -exec "rm" {} \;
100 #find "$GADGET"/configs/*/strings/* -maxdepth 0 -type d -exec "rmdir" {} \;
101 #find "$GADGET"/os_desc/* -maxdepth 0 -type l -exec "rm" {} \;
102 #find "$GADGET"/configs/functions/* -maxdepth 0 -type d -exec "rmdir" {} \;
103 #find "$GADGET"/configs/* -maxdepth 0 -type d -exec "rmdir" {} \;
104 #rmdir "$GADGET"
105
106 echo "Creating gadget..."
107 mkdir "$GADGET"
108 cd "$GADGET"
109
110 echo "Configuring device identifiers..."
111 echo 0x1d6b > idVendor # Linux Foundation
112 echo 0x0104 > idProduct # Multifunction Composite Gadget
113 echo 0x0001 > bcdDevice # v0.1.0
114 echo 0x0200 > bcdUSB # USB 2.0
115 mkdir "strings/$LANGUAGE"
116 echo "$MANUFACTURER" > "strings/$LANGUAGE/manufacturer"
117 echo "$PRODUCT" > "strings/$LANGUAGE/product"
118
119 echo "Configuring composite device..."
120 echo 0xEF > bDeviceClass
121 echo 0x02 > bDeviceSubClass
122 echo 0x01 > bDeviceProtocol
123
124 # This is necessary for multifunction devices to work with Windows due
125 to deficiencies in the same's driver stack.
126 echo "Configuring OS-specific descriptors..."
127 echo 1 > os_desc/use
128 echo 0xcd > os_desc/b_vendor_code
129 echo MSFT100 > os_desc/qw_sign
130
131 echo "Creating Ethernet endpoint (CDC NCM) (1/1)..."
132 mkdir "functions/ncm.usb0"
133 #echo "$HOST_ADDRESS" > "functions/ncm.usb0/host_addr"
134 #echo "$DEV_ADDRESS" > "functions/ncm.usb0/dev_addr"
135
136 echo "Creating serial endpoint (1/2)..."
137 mkdir "functions/acm.usb0"
138
139 echo "Creating configuration..."
140 mkdir "configs/c.1"
141 echo 500 > "configs/c.1/MaxPower"
142 mkdir "configs/c.1/strings/$LANGUAGE"
143 echo "Config 1" > "configs/c.1/strings/$LANGUAGE/configuration"
144 ln -s "functions/ncm.usb0" "configs/c.1"
145 ln -s "functions/acm.usb0" "configs/c.1"
146 ln -s "configs/c.1" "os_desc/c.1"
147
148 echo "Attaching device..."
149 udevadm settle
150 ls "/sys/class/udc/" > UDC
151
152 echo "Done."