Ok, here's exactly what I did, no rooting of HTC desired:
Setup bind9 and NAT etc...
note:
1: if you just do sudo echo 1 > /proc/sys/net/ipv4/ip_forward you will get a permissions error, so here's a script for the process
2: You can make iptables more specific about how it does things by adding parameters for specific devices.
cd ~
echo '!/bin/bash
apt-get install bind9
iptables -A POSTROUTING -t nat -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward' > setup_bind9_nat.sh
chmod +x setup_bind9_nat.sh
sudo ./setup_bind9_nat.sh
now plug in you're phone and select 'internet pass through'
wait for the device to appear in:
ifconfig
check it is also in:
arp
I found I had to unplug the device then plug it in again for it to appear in arp, things don't work properly if arp doesn't show the device.
The device will then sit waiting for HTC Sync to send it a message so you have to mock HTC Syncs message:
#change this line to be more specific if you have more than one usb network device
phone_usb_device="usb"
get_ip ()
{
arp -n | grep $phone_usb_device | awk '{print $1}'
}
#TODO: This needs a timeout and loop needs cleaning up, but works fine and borrowed from another post.
echo "waiting for IP on computer usb"
while [[ `get_ip` < 192 ]];do sleep 2; done
phoneip=`get_ip`
echo "IP adress is $phoneip "
echo -n -e "\x00\x02\x00\x00" | nc -q 2 $phoneip 6000 > /dev/null
I may write a version of this using D-Bus so the latter part executes automatically when the device is plugged in etc....
Ok here's my work in progress, I couldn't find anything 'generic' on d-bus so I opted for a bit of a hack solution using udev.. This isn't perfect, for instance the command gets run twice, so I'll have to see if I can filter the matching parameters a bit better, also add a timeout on the last script, just incase and see if I can replace arp with something a little better, say looking in /proc
here.s my .rules file from /etc/udev/rules.d I created
cat /etc/udev/rules.d/htc-desire.rules
You can call it anything you like but DON'T START IT WITH A NUMBER, that way it gets run last of all.
Add the following to the file as sudo using an editor of you're choice etc....
#KERNEL=="usb?" or DRIVERS=="usb" not sure which is best, may need extra mode information too from usb device.
SUBSYSTEM=="net", DRIVERS=="usb", ATTRS{manufacturer}=="HTC", ATTRS{idProduct}=="0ffe", RUN+="/home/olli/chain_mock_htc_sync.sh $kernel"
Ubuntu is setup to create the file with the correct permissions already
ls -lrt /etc/udev/rules.d/htc-desire.rules
-rw-r--r-- 1 root root 248 Jun 26 22:09 htc-desire.rules
Basically, if you don't see those 3 'r's,
sudo chmod a+r /etc/udev/rules.d/htc-desire.rules
Then you'll need two further files, one to chain the other, since RUN from udev will block everything else (even though it's run last!!)...hmm...
anyhow:
I created the files in my home directory for now "/home/olli/" ... so remember to replace the '/home/olli/' bit with whereever you create the files:
so for me, cd to my home directory.
cd ~
create a file called
chain_mock_htc_sync.sh
containing the following:
#!/bin/bash
/home/olli/mock_htc_sync.sh "$1" &
exit
make it executable
chmod +x chain_mock_htc_sync.sh
create another file called
mock_htc_sync.sh
containg the following
#!/bin/bash
#change this line to be more specific if you have more than one usb network device
phone_usb_device="$1"
get_ip ()
{
arp -n | grep $phone_usb_device | awk '{print $1}'
}
#TODO: This needs a timeout and loop needs cleaning up, but works fine and borrowed from another post.
echo "waiting for IP on computer $phone_usb_device"
while [[ `get_ip` /dev/null
Make it executable:
chmod +x mock_htc_sync.sh
Hopefully I should have a nice tidied up version soon as pos. (probably tomorrow).