Merge lp:~doanac/phablet-tools/rndis into lp:phablet-tools

Proposed by Andy Doan
Status: Needs review
Proposed branch: lp:~doanac/phablet-tools/rndis
Merge into: lp:phablet-tools
Diff against target: 258 lines (+149/-28)
6 files modified
debian/control (+1/-0)
debian/phablet-tools.udev (+3/-0)
debian/phablet-tools.upstart (+62/-0)
phablet-network-bridge-addif (+21/-0)
phablet-network-setup (+59/-28)
setup.py (+3/-0)
To merge this branch: bzr merge lp:~doanac/phablet-tools/rndis
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Sergio Schvezov Needs Fixing
Review via email: mp+177435@code.launchpad.net

Commit message

add rndis networking support

This sets up 2 things:

1) an upstart entry to ensure we have the proper bridged interface
in place. This interace will serve as DHCP server to all clients.

2) a udev rule that will detect when an rndis device is connected
and automatically provide that device an address

Inspired By: Jean-Baptiste Lallement and Oliver Grawert

Description of the change

add rndis networking support

This sets up 2 things:

1) an upstart entry to ensure we have the proper bridged interface
in place. This interace will serve as DHCP server to all clients.

2) a udev rule that will detect when an rndis device is connected
and automatically provide that device an address

Inspired By: Jean-Baptiste Lallement and Oliver Grawert

Tested On: mako and grouper

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

21 +# make sure we have proper permission when the device shows up as rndis
22 +SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", RUN+="udev-acl --action=$env{ACTION} --device=$env{DEVNAME}"

can you add this to android-tools-adb ?

I can do it, but it needs to be removed from here (doesn't belong)

review: Needs Fixing
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

187 + adb $ADBOPTS push $tfile /var/lib/lxc/android/pre-start.sh
188 + adb $ADBOPTS shell chmod 755 /var/lib/lxc/android/pre-start.sh

failed to copy '/tmp/tmp.KSqkeJWenb' to '/var/lib/lxc/android/pre-start.sh': Read-only file system
chmod: changing permissions of '/var/lib/lxc/android/pre-start.sh': Read-only file system

This should be read from a flag in lxc-android-config

review: Needs Fixing
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

257 + 'phablet-network-bridge-addif',

This would be better installed in libexec or something, not a stopper though

review: Needs Fixing
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

> 21 +# make sure we have proper permission when the device shows up as
> rndis
> 22 +SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", RUN+="udev-acl
> --action=$env{ACTION} --device=$env{DEVNAME}"
>
> can you add this to android-tools-adb ?
>
> I can do it, but it needs to be removed from here (doesn't belong)

This udev rule also only works on precise.

Revision history for this message
Andy Doan (doanac) wrote :

On 07/30/2013 12:52 PM, Sergio Schvezov wrote:
> Review: Needs Fixing
>
> 187 + adb $ADBOPTS push $tfile /var/lib/lxc/android/pre-start.sh
> 188 + adb $ADBOPTS shell chmod 755 /var/lib/lxc/android/pre-start.sh
>
> failed to copy '/tmp/tmp.KSqkeJWenb' to '/var/lib/lxc/android/pre-start.sh': Read-only file system
> chmod: changing permissions of '/var/lib/lxc/android/pre-start.sh': Read-only file system
>
> This should be read from a flag in lxc-android-config

Not sure I follow? If this is a read-only file, we're dead in the water.
Or are you saying check so that we can give a better error message?

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

> > 21 +# make sure we have proper permission when the device shows up as
> > rndis
> > 22 +SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", RUN+="udev-acl
> > --action=$env{ACTION} --device=$env{DEVNAME}"
> >
> > can you add this to android-tools-adb ?
> >
> > I can do it, but it needs to be removed from here (doesn't belong)
>
> This udev rule also only works on precise.

Added https://code.launchpad.net/~sergiusens/ubuntu/saucy/android-tools/lax_udev/+merge/177661

lp:~doanac/phablet-tools/rndis updated
148. By Andy Doan

remove adb permission hack

Sergio is moving this to android-tools-adbd

149. By Andy Doan

move phablet-network-bridge-addif to /lib/udev

as per sergio's review. this is where other udev scripts get located

Revision history for this message
Andy Doan (doanac) wrote :

> > 21 +# make sure we have proper permission when the device shows up as
> > rndis
> > 22 +SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", RUN+="udev-acl
> > --action=$env{ACTION} --device=$env{DEVNAME}"
> >
> > can you add this to android-tools-adb ?
> >
> > I can do it, but it needs to be removed from here (doesn't belong)
>
> This udev rule also only works on precise.

It works on raring for me.

Revision history for this message
Andy Doan (doanac) wrote :

I think I've fixed all but the lxc-android-config/read-only thing you mentioned. One question:

do we need to update the packaging so that this now depends on a specific version of android-adb-tools so we don't get adb permission issues?

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

On Tue, Jul 30, 2013 at 3:39 PM, Andy Doan <email address hidden> wrote:
> I think I've fixed all but the lxc-android-config/read-only thing you mentioned. One question:
>
> do we need to update the packaging so that this now depends on a specific version of android-adb-tools so we don't get adb permission issues?

The saucy versions use something like the MR I linked

-ACTION=="add|change", SUBSYSTEM=="usb", \
- ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="d001|d002", \
- TAG+="uaccess"
+ACTION=="add|change", SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", TAG+="uaccess"

Tool version is the same on all environments as long as you have
ppa:phablet-team/tools added.

Revision history for this message
Andy Doan (doanac) wrote :

On 07/30/2013 02:43 PM, Sergio Schvezov wrote:
> On Tue, Jul 30, 2013 at 3:39 PM, Andy Doan <email address hidden> wrote:
>> I think I've fixed all but the lxc-android-config/read-only thing you mentioned. One question:
>>
>> do we need to update the packaging so that this now depends on a specific version of android-adb-tools so we don't get adb permission issues?
>
> The saucy versions use something like the MR I linked
>
> -ACTION=="add|change", SUBSYSTEM=="usb", \
> - ATTRS{idVendor}=="18d1", ATTRS{idProduct}=="d001|d002", \
> - TAG+="uaccess"
> +ACTION=="add|change", SUBSYSTEM=="usb", ATTRS{idVendor}=="18d1", TAG+="uaccess"
>
> Tool version is the same on all environments as long as you have
> ppa:phablet-team/tools added.
>

What I was trying to say is phablet-tools now requires a specific
version android-adb-tools in order for rndis to work. ie - we merged
this today, and you ran:

  apt-get update; apt-get install phablet-tools

you'd have an outdated version of android-adb-tools, right?

Unmerged revisions

149. By Andy Doan

move phablet-network-bridge-addif to /lib/udev

as per sergio's review. this is where other udev scripts get located

148. By Andy Doan

remove adb permission hack

Sergio is moving this to android-tools-adbd

147. By Andy Doan

add rndis networking support

This sets up 2 things:

1) an upstart entry to ensure we have the proper bridged interface
in place. This interace will serve as DHCP server to all clients.

2) a udev rule that will detect when an rndis device is connected
and automatically provide that device an address

Inspired By: Jean-Baptiste Lallement and Oliver Grawert

146. By Andy Doan

break out wifi setup into its own function

This is just to help make things cleaner for adding rndis support

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2013-07-14 18:46:18 +0000
3+++ debian/control 2013-07-30 18:36:35 +0000
4@@ -25,6 +25,7 @@
5 Depends:
6 android-tools-adb (>= 4.2.2),
7 android-tools-fastboot (>= 4.2.2),
8+ bridge-utils,
9 curl,
10 python-configobj,
11 python-launchpadlib,
12
13=== added file 'debian/phablet-tools.udev'
14--- debian/phablet-tools.udev 1970-01-01 00:00:00 +0000
15+++ debian/phablet-tools.udev 2013-07-30 18:36:35 +0000
16@@ -0,0 +1,3 @@
17+# Udev rules for letting adding a usb network interface to the bridge
18+ACTION=="add|change", SUBSYSTEM=="net", DRIVERS=="usb", KERNEL=="usb[0-9]*", \
19+ATTRS{idVendor}=="18d1", RUN+="phablet-network-bridge-addif"
20
21=== added file 'debian/phablet-tools.upstart'
22--- debian/phablet-tools.upstart 1970-01-01 00:00:00 +0000
23+++ debian/phablet-tools.upstart 2013-07-30 18:36:35 +0000
24@@ -0,0 +1,62 @@
25+description "touch usb network"
26+author "Jean-Baptiste Lallement <jean-baptiste.lallement@canonical.com>"
27+
28+start on started networking
29+stop on runlevel [!023456]
30+
31+env USE_TOUCH_BRIDGE="true"
32+env TOUCH_BRIDGE="usbbr0"
33+env TOUCH_ADDR="169.254.0.1"
34+env TOUCH_NETMASK="255.255.255.0"
35+env TOUCH_NETWORK="169.254.0.1/24"
36+env TOUCH_DHCP_RANGE="169.254.0.2,169.254.0.254"
37+env TOUCH_DHCP_MAX="253"
38+env TOUCH_DHCP_CONFILE=""
39+env varrun="/var/run/touch"
40+
41+pre-start script
42+ [ -f /etc/default/touch-net ] && . /etc/default/touch-net
43+ [ "x$USE_TOUCH_BRIDGE" = "xtrue" ] || { stop; exit 0; }
44+
45+ cleanup() {
46+ # dnsmasq failed to start, clean up the bridge
47+ iptables -t nat -D POSTROUTING -s ${TOUCH_NETWORK} ! -d ${TOUCH_NETWORK} -j MASQUERADE || true
48+ ifconfig ${TOUCH_BRIDGE} down || true
49+ brctl delbr ${TOUCH_BRIDGE} || true
50+ }
51+
52+ if [ -d /sys/class/net/${TOUCH_BRIDGE} ]; then
53+ if [ ! -f ${varrun}/network_up ]; then
54+ # bridge exists, but we didn't start it
55+ stop;
56+ fi
57+ exit 0;
58+ fi
59+
60+ # set up the usb network
61+ brctl addbr ${TOUCH_BRIDGE} || { echo "Missing bridge support in kernel"; stop; exit 0; }
62+ echo 1 > /proc/sys/net/ipv4/ip_forward
63+ mkdir -p ${varrun}
64+ ifconfig ${TOUCH_BRIDGE} ${TOUCH_ADDR} netmask ${TOUCH_NETMASK} up
65+ iptables -t nat -A POSTROUTING -s ${TOUCH_NETWORK} ! -d ${TOUCH_NETWORK} -j MASQUERADE
66+
67+ dnsmasq --strict-order --bind-interfaces --pid-file=${varrun}/dnsmasq.pid --conf-file=${TOUCH_DHCP_CONFILE} --listen-address ${TOUCH_ADDR} --dhcp-range ${TOUCH_DHCP_RANGE} --dhcp-lease-max=${TOUCH_DHCP_MAX} --dhcp-no-override --except-interface=lo --interface=${TOUCH_BRIDGE} --dhcp-leasefile=/var/lib/misc/dnsmasq.${TOUCH_BRIDGE}.leases --dhcp-authoritative || cleanup
68+ [ ! -d ${varrun} ] && mkdir -p ${varrun}
69+ touch ${varrun}/network_up
70+end script
71+
72+post-stop script
73+ [ -f /etc/default/touch ] && . /etc/default/touch
74+ [ -f "${varrun}/network_up" ] || exit 0;
75+ # if $TOUCH_BRIDGE has attached interfaces, don't shut it down
76+ ls /sys/class/net/${TOUCH_BRIDGE}/brif/* > /dev/null 2>&1 && exit 0;
77+
78+ if [ -d /sys/class/net/${TOUCH_BRIDGE} ]; then
79+ ifconfig ${TOUCH_BRIDGE} down
80+ iptables -t nat -D POSTROUTING -s ${TOUCH_NETWORK} ! -d ${TOUCH_NETWORK} -j MASQUERADE || true
81+ pid=`cat ${varrun}/dnsmasq.pid 2>/dev/null` && kill -9 $pid || true
82+ rm -f ${varrun}/dnsmasq.pid
83+ brctl delbr ${TOUCH_BRIDGE}
84+ fi
85+ rm -f ${varrun}/network_up
86+end script
87
88=== added file 'phablet-network-bridge-addif'
89--- phablet-network-bridge-addif 1970-01-01 00:00:00 +0000
90+++ phablet-network-bridge-addif 2013-07-30 18:36:35 +0000
91@@ -0,0 +1,21 @@
92+#!/bin/sh
93+
94+# called by udev rules when an rndis device shows up
95+# it works in conjunction with logic set up by phablet-network-bridge to
96+# allow the target device to aquire an IP address via USB0
97+
98+BRIDGE=usbbr0
99+
100+log() {
101+ logger -t phablet-tools $*
102+}
103+
104+if [ "$ID_USB_DRIVER" != "rndis_host" ] ; then
105+ log "Unknown USB interface found"
106+ exit 0
107+fi
108+
109+log "rndis interface found: $DEVPATH"
110+DEVICE=$(basename $DEVPATH)
111+ip link set $DEVICE up
112+brctl addif $BRIDGE $DEVICE
113
114=== modified file 'phablet-network-setup'
115--- phablet-network-setup 2013-07-22 12:13:58 +0000
116+++ phablet-network-setup 2013-07-30 18:36:35 +0000
117@@ -27,6 +27,7 @@
118 -s Specify the serial of the device to install (see adb $ADBOPTS devices)
119 -i Install helper network packages (openssh-server, iw) in chroot
120 -n Select network file
121+ -r Use rndis based network from device to host
122
123 EOF
124 }
125@@ -37,7 +38,7 @@
126 CHROOTDIR="/data/ubuntu"
127 CHROOTCMD="chroot $CHROOTDIR"
128
129-while getopts "hin:s:" OPTION
130+while getopts "hin:s:r" OPTION
131 do
132 case $OPTION in
133 h)
134@@ -53,6 +54,9 @@
135 s)
136 ADBOPTS="-s $OPTARG"
137 ;;
138+ r)
139+ RNDIS=1
140+ ;;
141 ?)
142 usage
143 exit
144@@ -99,39 +103,66 @@
145 echo "$network_file"
146 }
147
148+setup_wifi() {
149+ if [ -z "$OPTION_NETWORK_FILE" ]; then
150+ network_file=$(find_active_network)
151+ else
152+ network_file=$OPTION_NETWORK_FILE
153+ fi
154+
155+ if [ ! -f "$network_file" ]
156+ then
157+ echo "Network connection file \"$network_file\" cannot be read"
158+ exit 1
159+ fi
160+
161+ echo Network file is $network_file
162+
163+ TMP_FILE=$(mktemp)
164+ sudo grep -v mac-address "$network_file" > $TMP_FILE
165+
166+ echo Provisioning network file to device
167+ adb $ADBOPTS root
168+ adb $ADBOPTS wait-for-device
169+ target_network_file=$CHROOTDIR/$NETWORK_MANAGER/active_ws_connection.conf
170+ adb $ADBOPTS push $TMP_FILE $target_network_file
171+ adb $ADBOPTS shell "chmod 600 $target_network_file"
172+
173+ rm -f $TMP_FILE
174+
175+ echo
176+}
177+
178+setup_rndis() {
179+ # ensure upon reboots the android lxc container startup doesn't overwrite
180+ # our persisted changes below. Also disable the container's adb.
181+ tfile=$(mktemp)
182+ adb $ADBOPTS pull /var/lib/lxc/android/pre-start.sh $tfile
183+ sed -i -e '/# Make sure adbd is not started automatically/{n;s/.*/#PHABLET_TOOLS_RNDIS\n#&\nmv $LXC_ROOTFS_PATH\/sbin\/adbd $LXC_ROOTFS_PATH\/sbin\/adbd.disabled\n#PHABLET_TOOLS_DISABLED/;}' -e "s/#PHABLET_TOOLS_DISABLED$/sed -i '\/setprop persist.sys.usb.config adb$\/d' \$LXC_ROOTFS_PATH\/init.rc\n#PHABLET_TOOLS_RNDIS/" $tfile
184+ adb $ADBOPTS push $tfile /var/lib/lxc/android/pre-start.sh
185+ adb $ADBOPTS shell chmod 755 /var/lib/lxc/android/pre-start.sh
186+ rm $tfile
187+
188+ adb $ADBOPTS shell sh -c "echo -n rndis,adb > /data/property/persist.sys.usb.config"
189+ adb $ADBOPTS reboot
190+ # reboots aren't instant, so wait-for-device usually needs to tries
191+ sleep 4 # give time to reboot
192+ adb $ADBOPTS wait-for-device
193+ sleep 4 # give time to reboot
194+ adb $ADBOPTS wait-for-device
195+}
196+
197 if is_flipped; then
198 echo Ubuntu is root
199 CHROOTDIR=""
200 CHROOTCMD=""
201 fi
202
203-if [ -z "$OPTION_NETWORK_FILE" ]; then
204- network_file=$(find_active_network)
205+if [ -z $RNDIS ]; then
206+ setup_wifi
207 else
208- network_file=$OPTION_NETWORK_FILE
209-fi
210-
211-if [ ! -f "$network_file" ]
212-then
213- echo "Network connection file \"$network_file\" cannot be read"
214- exit 1
215-fi
216-
217-echo Network file is $network_file
218-
219-TMP_FILE=$(mktemp)
220-sudo grep -v mac-address "$network_file" > $TMP_FILE
221-
222-echo Provisioning network file to device
223-adb $ADBOPTS root
224-adb $ADBOPTS wait-for-device
225-target_network_file=$CHROOTDIR/$NETWORK_MANAGER/active_ws_connection.conf
226-adb $ADBOPTS push $TMP_FILE $target_network_file
227-adb $ADBOPTS shell "chmod 600 $target_network_file"
228-
229-rm -f $TMP_FILE
230-
231-echo
232+ setup_rndis
233+fi
234 echo Network setup complete
235
236 if [ $OPTION_SSH -eq 1 ]; then
237@@ -139,7 +170,7 @@
238 # Indentation is going to be ugly here
239 cat > $TMP_FILE << 'EOF'
240 #!/bin/bash
241-export PATH="/sbin:/usr/sbin:/bin:/usr/bin"
242+export PATH="/sbin:/usr/sbin:/bin:/usr/bin"
243 export DEBIAN_FRONTEND=noninteractive
244 apt-get update
245 apt-get install --yes --quiet openssh-server iw
246
247=== modified file 'setup.py'
248--- setup.py 2013-07-17 16:13:33 +0000
249+++ setup.py 2013-07-30 18:36:35 +0000
250@@ -18,5 +18,8 @@
251 'phablet-test-run',
252 'repo',
253 ],
254+ data_files=[
255+ ('/lib/udev/', ['phablet-network-bridge-addif']),
256+ ],
257 test_suite='tests',
258 )

Subscribers

People subscribed via source and target branches