[OM2008] USB events -> scripts?

Joel Newkirk freerunner at newkirk.us
Fri Dec 12 19:09:09 CET 2008


In my work to bring sanity to basic networking I explored this.  For 2008.x
the solution I ended with was udev.  Two files in my netfix tarball pertain
to this:



#/etc/udev/rules.d/usbnet

subsystem=="power_supply", RUN+="/etc/udev/scripts/usbnet.sh" 




#/etc/udev/scripts/usbnet.sh

#!/bin/sh
# when USB is plugged/unplugged in device mode, udev triggers this script
on power change
# udevd does clearenv(). Export shell PATH to children.                    
                                                               
export PATH 
if [[ $(cat /sys/devices/platform/s3c2410-ohci/usb_mode) = "device" ]]
then
    if [[ $(cat
/sys/devices/platform/s3c2440-i2c/i2c-adapter/i2c-0/0-0073/chgmode) =
"play-only" ]]
    then
	ifdown usb0
    else
	ifup usb0
	sleep 5
	if [[ $(ping -c2 -q $(ip r | grep usb0 | grep default | cut -d' ' -f3) |
grep loss | cut -d' ' -f4) = 0 ]]
	then
	    ifdown usb0
	fi
    fi
fi



The only problem with this approach so far is that on powerup it doesn't
trigger, only on USB insertion after fully booted.

j



On Fri, 12 Dec 2008 09:48:41 -0800, "Sargun Dhillon"
<xbmodder+openmoko at gmail.com> wrote:
> You might even want to look at oeventsd, part of FSO ( freesmartphone.org
> ).
> URL:
>
http://git.freesmartphone.org/?p=specs.git;a=blob_plain;f=html/org.freesmartphone.Events.html;hb=HEAD
> 
> 
> On Fri, Dec 12, 2008 at 4:25 AM, Pander <pander at users.sourceforge.net>
> wrote:
>> On Fri, December 12, 2008 12:35, Vasco Névoa wrote:
>>>
>>> Hi all.
>>>
>>> I want to run a script automatically every time the USB is plugged or
>>> unplugged.
>>
>> This is in the udev rules.
>>
>> See
>>
>
http://lists.openmoko.org/pipermail/community/2008-November/thread.html#35417
>> for ideas concerning keybaords and
>> https://bugs.launchpad.net/ubuntu/+bug/289548 concerning networking.
>>
>>> Where should I hook in the scripts? /etc/apm/?/... or somewhere else?
>>> I've looked into using the /etc/network/interfaces, but this doesn't
>>> work because usb0 does not get "downed" on unplug - so it is always
>>> "up" since booting...
>>>
>>> Thanks,
>>>
>>> Vasco.
>>>
>>> _______________________________________________
>>> Openmoko community mailing list
>>> community at lists.openmoko.org
>>> http://lists.openmoko.org/mailman/listinfo/community
>>>
>>
>>
>>
>> _______________________________________________
>> Openmoko community mailing list
>> community at lists.openmoko.org
>> http://lists.openmoko.org/mailman/listinfo/community
>>
> 
> _______________________________________________
> Openmoko community mailing list
> community at lists.openmoko.org
> http://lists.openmoko.org/mailman/listinfo/community
-- 
Joel Newkirk
http://jthinks.com      (blog)
http://newkirk.us/om (FR stuff)





More information about the community mailing list