USB device ID to determine network address?
I'm trying to come up with a way to have a different network address assigned to different USB devices (a Zaurus and a cell phone; the former uses usbnet, the latter usblan). This would be a lot like the case of having two USB ethernet devices for a router, or a USB ethernet device and a USB cable modem. So far in /etc/hotplug/usb.agent I have added stuff like this:
usb_idVendor=$((0x$1))
usb_idProduct=$((0x$2))
usb_bcdDevice=$((0x$3))
ifconfig > /tmp/nets
rm -rf /tmp/lastusb
mkdir /tmp/lastusb
touch /tmp/lastusb/"${usb_idVendor}:${usb_idProduct}"
echo -n "${usb_idVendor}:${usb_idProduct}" > /tmp/lastusbdev
/bin/sync
sleep 1then /etc/init.d/net.usb0 and net.usb1 both look like this:
start() {
ebegin "Bringing ${IFACE} up"
echo "Bringing ${IFACE} up" > /var/log/usb0.log
if [ -e /tmp/lastusb/1245:36914 ]
then
/sbin/ifconfig ${IFACE} 192.168.129.200 up 2>/dev/null
else
/sbin/ifconfig ${IFACE} 192.168.1.1 up 2>/dev/null
fi
/etc/init.d/dhcp start
eend 0
}It's acting as though the file modifications in /tmp are not completed before the init.d script gets called, because for example after plugging in the zaurus, I have to plug in the phone twice before it gets the correct address, and vice-versa. But I added the /tmp/nets thing to see if that is true, and actually /tmp/nets ends up containing the network state before the hotplug, just as I would have expected.
Anyway it's kindof inelegant, and I was wondering if this problem has already been solved in some other way?
Actually, it might be better if there was some way to have one device always get interface usb0 and the other always get usb1, even if only one of them is actually plugged in; then I could just configure the different addresses in /etc/conf.d/net. (This is a gentoo system.)
Alternatively if the init.d script had some other way to get the device which is being configured....
Or, if there was a config file to map devices to their properties like network address for network devices, mount location for mass storage devices, tty for modem devices or printers, etc. so all that stuff could be maintained in one config file.
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&opÌk
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 5 lines · Shawn Rutledge
Or, if there was a config file to map devices to their properties like network address for network devices, mount location for mass storage devices, tty for modem devices or printers, etc. so all that stuff could be maintained in one config file.
Yes there is. Try using udev to manage your network devices instead of custom scripts :)
thanks,
greg k-h
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
Quoted 3 lines · Shawn Rutledge
I'm trying to come up with a way to have a different network address assigned to different USB devices (a Zaurus and a cell phone; the former uses usbnet, the latter usblan).
As of 2.6.13 both should work just fine with "usbnet".
- Dave
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies from IBM. Find simple to follow Roadmaps, straightforward articles, informative Webcasts and more! Get everything you need to get up to speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel