Posted: Sun Feb 08, 2009 9:19 Post subject: USB Hotplug Script Support
Hey everyone,
I was wondering if anyone has investigated the possibility of enabling the use of a hotplug daemon in order to allow the use of hotplug scripts when devices are connected.
I'm trying to get a Laserjet 1018 printer working with DD-WRT, but it's not possible without the ability to upload firmware when the USB connection is detected. Any assistance would be much appreciated. What all is involved in possibly adding hotplug script support? There is a Tomato build with this functionality currently enabled, but DD-WRT has many more features.
it is possible to use a printer with dd-wrt. i have 2 printers on my router, and one USB drive connected using a 4 USB extension port. all working fine.
first you have to install the drivers for USB
then you have to install the drivers for printer support.
then you have to setup your computer to use tcp/ip port for printing
this is fully documented in the wiki, search for it.
For usb drives hot-plug script support can be enabled via the web-GUI (on v24-pre-sp2 firmwares that have usb support in the web-GUI). Its called run-on-mount, and Slim Samba2 depends on this functionality.
So some level of hot-plug support/detection is already enabled in dd-wrt. I suppose its only a question of tapping into this functionality, to have a run-a-script-on-new-usb-device-detection.
I have already completed everything you mentioned. The HP LJ1018 will not work without the ability to upload a 120 KB firmware file every time the device is detected. If the devices is turned off and back on it will no longer accept print jobs. If the device goes into sleep mode after an hour and you try to print it will no longer accept print jobs. This makes it unusable unless USB hotplug script support is enabled in DD-WRT.
The HP LJ1018 will not work without the ability to upload a 120 KB firmware file every time the device is detected.
What du you mean when you say upload?
The firmware file is stored on eg. /jffs or /mnt?
and then needs an insmod command to run in order to be recognized by dd-wrt?
or some other command?
I guess what I am saying: what do you specifically do to get the driver to work in the first place?
Once the steps to success are listed, maybe someone will be able to fill in "the missing link" in the process, for the auto-detect-on-wake-up to start working.
What do you know about the tricks they do in Tomato to have this process working?
The firmware is stored on the router in /jffs. It's a approximately 120 kb file named sihp1018.dl.
They use the following hotplug script:
if [ $PRODUCT = "3f0/4117/100" ] (this is the printer's product code)
then
if [ $ACTION = "add" ]
then
sleep 5
cat /jffs/sihp1018.dl > /dev/usb/lp0
fi
fi
fi
My understanding is that DD-WRT currently cannot execute scripts like this for printers on detection or removal.
The normal Tomato firmware is not able to do this (or USB at all), but the firmware available and discussed in this thread: http://www.linksysinfo.org/forums/showthread.php?t=60185 has been modded in order to have USB and hotplug scripts. The source code is loaded in a git repository as well, but I'm not knowledgeable enough to know how to proceed.
I wrote a script to automatically load the printer driver when a printer is connected and kill it when it is disconnected....
Just add that line and bob's your uncle...
Search for it in the forum....
If you can't find it, I will send the link this evening _________________ Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge
If you save this as /jffs/usbprinter you can run it as /jffs/usbprinter &
Code:
#!/bin/sh
# Printer monitoring script
while sleep 60
do
isdaemon=`ps | grep -v grep | grep -c p9100`
if [ $isdaemon == 0 ]; then
# No daemon running
# Start daemon if printer is attached
if [ -e /dev/usb/lp0 ]; then
/opt/bin/p910nd -b -f /dev/usb/lp0 0
sleep 1
cat /jffs/sihp1018.dl > /dev/usb/lp0
fi
else
if [ ! -e /dev/usb/lp0 ]; then
# No Printer attached but daemon running
# Kill daemon
process=`pidof p9100d`
kill $process
fi
fi
done
_________________ Asus RT16N + OTRW
Kingston 4GB USB-disk 128 MB swap + 1.4GB ext3 on /opt + 2 GB ext3 on /mnt
Copperjet 1616 modem in ZipB-config
Asterisk, pixelserv & Pound running on router
Another Asus RT16N as WDS-bridge
while sleep 60
do
isdaemon=`ps | grep -v grep | grep -c p9100`
if [ $isdaemon == 0 ]; then
# No daemon running
# Start daemon if printer is attached
if [ -e /dev/usb/lp0 ]; then
/opt/bin/p910nd -b -f /dev/usb/lp0 0
sleep 1
cat /jffs/sihp1020.dl > /dev/usb/lp0
fi
else
if [ ! -e /dev/usb/lp0 ]; then
# No Printer attached but daemon running
# Kill daemon
process=`pidof p9100d`
kill $process
fi
fi
done
It looks like the watchprinter script is not executed given this error:
sh: eval: line 4: /jffs/watchprinter: not found
If you save this as /jffs/usbprinter you can run it as /jffs/usbprinter &
Code:
#!/bin/sh
# Printer monitoring script
while sleep 60
do
isdaemon=`ps | grep -v grep | grep -c p9100`
if [ $isdaemon == 0 ]; then
# No daemon running
# Start daemon if printer is attached
if [ -e /dev/usb/lp0 ]; then
/opt/bin/p910nd -b -f /dev/usb/lp0 0
sleep 1
cat /jffs/sihp1018.dl > /dev/usb/lp0
fi
else
if [ ! -e /dev/usb/lp0 ]; then
# No Printer attached but daemon running
# Kill daemon
process=`pidof p9100d`
kill $process
fi
fi
done
Do I need to install anything else on the router for this to work? Optware? Maybe I just need it broken down a little more...
If I get this working, then this router will do EVERYTHING I want. Then I can back up the settings with your other great script Frater.
====================
edit: Okay, i tried the script saving as /jffs/usbprinter, making executable, and running on startup with /jffs/usbprinter &
I am using DD-WRT v24-sp2 (09/18/10) mini-usb-nas - build 15230M NEWD-2 K2.6 Eko on a Belkin Play F7D4302v1. This router is just newly supported so I don't think I can go older.
Anyway, the script seems to die because of the location of p910d which is not in the /opt/bin location as this version already has printer support built in. Do I need a modified script for this new firmware? Do I require Optware still?
I've been using DD-WRT for 3 years, but only on the old neutered Linksys units, so this functionality is all new to me!
Anyway, the script seems to die because of the location of p910d which is not in the /opt/bin location as this version already has printer support built in. Do I need a modified script for this new firmware? Do I require Optware still?
Thanks
You don't need optware, just redirect all the "opt/bin/p910nd" for the direction of yours. Usually "jffs/usr/sbin/p910nd"
EDIT: only put the "cat sp...." line if your printer is an HP 1018, 1020, p1005, p1006 and few others
Anyway, the script seems to die because of the location of p910d which is not in the /opt/bin location as this version already has printer support built in. Do I need a modified script for this new firmware? Do I require Optware still?
Thanks
You don't need optware, just redirect all the "opt/bin/p910nd" for the direction of yours. Usually "jffs/usr/sbin/p910nd"
EDIT: only put the "cat sp...." line if your printer is an HP 1018, 1020, p1005, p1006 and few others
Thanks, I do have one of those printers.
So, taking a look with SCP onto the router, it seems that p910d lives in /usr/sbin , so I changed the reference to there.
my startup script is:
mknod -m 660 /dev/usb/lp0 c 180 0
/jffs/usbprinter &
Still does not seem to work. Frustrating, but thanks for the help!
my printer is hp 1018, so i have downloaded sihp1018.dl to /jffs/
I am running DD-WRT v24-sp2 (09/18/10) mini-usb-nas - build 15230M NEWD-2 K2.6 Eko with usb already installed. Since it is a K26 version, do I have to use a slightly different script? I followed you link but couldn't tell... thanks