Saturday, June 26, 2010

Advanced Printer Sharing with hotplug

Hotplug is a set of scripts running upon certain predefined conditions. On today's Linux system, hotplug can do many things from auto mounting USB drive, pairing bluetooth devices to network configuration.

Seldom mentioned, but DD-WRT does offer (very preliminary) hotplug support. With almost no info on the web, the job is done by digging though DD-WRT's source code and various Linux documents.

  1. Replace DD-WRT's event handler with our own
    By default, DD-WRT registers /sbin/hotplug to handle all hotplug requests but the program, /sbin/hotplug doesn't follow standard hotplug rules, and, per my understanding, is a dummy and does nothing at all. So let's replace it with our own

    Create a startup script /opt/etc/init.d/hotplugd with only one line:

    echo /opt/sbin/hotplug > /proc/sys/kernel/hotplug

    Then set it to run upon start up
    chmod a+x /opt/etc/init.d/hotplugd
    ln -s /opt/etc/init.d/hotplugd /opt/etc/init.d/S95hotplugd

    run
    /opt/etc/init.d/hotplugd
    and check the result:
    cat /proc/sys/kernel/hotplug

    The output should be /opt/sbin/hotplug, which is our new event handler.

  2. Test drive hotplug
    So how does the hotplug work? below script will give you some idea to start with:
    Create /opt/sbin/hotplug with following:

    #!/bin/sh

    #For Debugging
    echo "Customized hotplug" >> /tmp/hotplug.log
    echo -------------$(date)----------- >> /tmp/hotplug.log
    set >> /tmp/hotplug.log

    set it as executable
    chmod a+x /opt/sbin/hotplug

    Unplug the printer, wait few seconds and plug the printer back.  Check the log by typing:
    cat /tmp/hotplug.log

    You can see there are bunch of environmental variables logged, two of them are worth noting:
    ACTION The value for "ACTION" variable can be "add" or "remove", corresponding to device plugin and removal.
    PRODUCT This is the unique device ID for the USB device, my printer is HP 1020 and value is 3f0/2b17/100.

    In a full Linux system, hotplug is much more complex. My script is a quick dirty hack but should be sufficient to handle USB printers.

  3. Configure hotplug to upload firmware to the printer
    Some GDI printer(aka Windows printer) will require extra work on Linux. Below is an example of my HP Laserjet 1020 but also applies to other HP laser printers like 1000, 1005, 1018, P1005, P1008, P1505 etc..
    You'll need two things to start with:
    The printer's firmware -- this must be in the printer before printing. Some of popular HP printers' can be downloaded from http://oleg.wl500g.info/hplj/
    usb_printerid -- this is used to detect if the firmware is already in place to prevent duplicated firmware uploading. Above link has one but that's for Broadcom devices. So I compile one for Atheros routers. Download here. Extract and put it to the router(samba, ftp or WinSCP).

    Assume we have the firmware in /opt/usr/local/lib/ and usb_printerid in /opt/usr/local/bin/, run
    chmod a+x /opt/usr/local/bin/usb_printerid

    And finally, here is the full script /opt/sbin/hotplug

    #!/bin/sh

    #For Debugging
    #echo "Customized hotplug" >> /tmp/hotplug.log
    #echo -------------$(date)----------- >> /tmp/hotplug.log
    #set >> /tmp/hotplug.log

    P910ND='/opt/usr/sbin/p910nd'
    PRINTERID='/opt/usr/local/bin/usb_printerid'
    FIRMWARE='/opt/usr/local/lib/sihp1020.dl'
    #replace it with your printer's firmware.

    if [ $DEVTYPE == 'usb_device' ] && [ $PRODUCT == '3f0/2b17/100' ]; then
    #replace with your printer's device id.
      if [  $ACTION == 'add' ]; then
        #check and upload firmware
        ${PRINTERID} /dev/usb/lp0 | grep -q FWVER || cat ${FIRMWARE} > /dev/usb/lp0
        #kill and restart p910nd
        kill -9 $(pidof p9100d)
        ${P910ND}  -b -f /dev/usb/lp0 0
      fi

      if [ $ACTION == 'remove' ]; then
        #printer removed, lets stop p910nd
        kill -9 $(pidof p9100d)
      fi
    fi

    The above script will upload firmware to printer then start p910nd daemon upon printer plug-in and stop p910nd when it's removed.

  4. Modified p910nd startup script
    With above script, DD-WRT will automatically configure the printer after the router is fully booted. However, similar approach has to be done during startup as the hotplug does not take effect at that moment.
    For unknown reasons, DD-WRT will NOT create /dev/usb/lp0 for printer even we have printer support enabled. As a result, we can't use this device node to detect the printer's presence.

    Here is a modified version of /opt/etc/init.d/p910nd startup script.

    source /mnt/root/.profile

    mkdir -m 755 -p /dev/usb
    mknod -m 660 /dev/usb/lp0 c 180 0
    sleep 1

    P910ND='/opt/usr/sbin/p910nd'
    PRINTER_ID='/opt/usr/local/bin/usb_printerid'
    FIRMWARE='/opt/usr/local/lib/sihp1020.dl'
    #replace with yours
    PNAME='LaserJet'
    #printer name id string, see below

    i=$(find /sys/devices/platform/ -name product -exec cat {} \; | grep -c ${PNAME})

    if [ $i != '0' ]; then
         ${PRINTER_ID} /dev/usb/lp0 | grep -q FWVER || cat ${FIRMWARE} > /dev/usb/lp0
         kill -9 `pidof p9100d`
         ${P910ND}  -b -f /dev/usb/lp0 0
    fi

    Notice the PNAME='LaserJet' line. The 'LaserJet" is part of the printer's name and can be used to check if the printer is plugged. To determine yours, run

    find /sys/devices/platform/ -name product -exec cat {} \;

    The result looks like that:
    HP LaserJet 1020 #printer
    DataTravelerMini #USB flash drive
    Atheros AR91xx built-in EHCI controller #USB controller

After that, follow the previous tutorial to install printer in Windows if you haven't done so. Now enjoy the convenience of hotplug.

54 comments:

Anonymous said...

I searched thru the web just for this bit of info - could not find anywhere....
Thanks a lot.
I use dd-wrt on Asus router. I needed to send my FW to my GDI printer (HP LaserJet 1018) the hotplug way....
Keep up the good work.
BTW, your blog is so methodical as opposed to dd-wrt site which is full of confusing/contradictory/obsolete information.
Regards.

Anonymous said...

I am using your script to automatically start and kill samba once my hard disk is attached to the router. Mounting the partitions via hotplug and killing samba on remove works fine.
Unfortunately, the script fails to run samba for some reason. I am using the command "smbd -s /opt/etc/samba/smb.conf" from your previous tutorial. The command works fine from command line but not from within the script. I also tried using the absolute path to the smbd binary with no success. Any ideas?

Anonymous said...

I found out that when using id in the hotplug-script the entry "groups" is missing:

#normal output:
root $ id
uid=0(root) gid=0(root) groups=0(root)

#from script:
uid=0(root) gid=0(root)

I guess that is an issue for Samba. Can this be fixed?

Anonymous said...

have found an expert..wonderful and you have resolved my issue
hp laserjet 1020

HP LaserJet 1020 said...

GDI printer(aka Windows printer) will require extra work on Linux. Below is an example of my HP Laserjet 1020 but also applies to other HP laser printers like 1000, 1005, 1018, P1005, P1008, P1505 etc..

Apk Galaxy said...

Nice Thanks Alot For sharing

Anonymous said...

Brick Rigs Game Download
I am very comfortable and pleased to come here. Thank you very much.

Anonymous said...

Paint Tool Sai Crack Torrent
Good information.

Anonymous said...

Dr Fone Registration Code Generator
Thanks your post it really so helpful......

Abigail said...

Rosetta Stone Italian Torrents
Great tips and very easy to understand. This will definitely be very useful for me when I get a chance to start my blog.

asad said...

Rpg Maker Mv Mac Torrent
I should say thank you very much for this thought. It gives me more knowledge on this issue.

Anonymous said...

very Help Full Post. Look Some Different here at
Router Login not working
routerlogin admin page
Routerlogin
Routerlogin Net

New Year Love 2019 said...

newyear2019love.com get the new quotes

Live PSL Digital said...

Watch live streaming of PSL https://livepsldigital.com/

Happy Valentines Day 2k19 said...

Latest quotes , images and sayings about the https://happyvalentinesday2019.net/ available here.

mesotheliama said...

https://teacherappreciationweekideas.com/ teacher apprication weeks for more progress

happy new year 2019 wishes said...

thanks for the information.

Mr. Ronan Melone said...

Nice thoughts with great helping content. I have also been seeking such thoughfull content to learn and appy in the life. We have also created such type of content on our site. You can refer out site for more ideas.
Happy New Year 2019 Wishes Messages Sms in Bengali
Merry Christmas 2018 SMS, Wishes, Messages, Greetings in Bengali
Merry Christmas 2018 Wishes Messages in Marathi,funny christmas text sms

jhoni said...

thanks for the information.
pip camera new version 2019

El Clasico said...

Best New Year 2019 Love Quotes and wishes for Her or Him with images. Most Romantic Sayings for Girlfriend and Boyfriend to wish and propose on New

newyear2019s.com/

jhoni said...

thanks for the information.

Sketch Maker new version 2019

Happy Valentines Day 14 said...

Latest and romantic happy valentine day images

Unknown said...

Very neat blog article.Much thanks again. Really Great. anniversary quotes for husband


Sravi said...

This is certainly additionally an exceedingly wonderful offer everyone truly qualified on the lookout with. It's always not likely everyday there is chances read a little something. extremely well written article as studyplans.in . I will be sure to and return to read more of your useful information. Thanks for the post. I’ll certainly comeback.

https://apsscresult2019.in

sampath said...

latestgovtjobs2019.in
upboard10thresult2019.com

Sravi said...

This is certainly additionally an exceedingly wonderful offer everyone truly qualified on the lookout with. It's always not likely everyday there is chances read a little something. extremely well written article as click here . I will be sure to and return to read more of your useful information. Thanks for the post. I’ll certainly comeback.

Sravi said...

This is certainly additionally an exceedingly wonderful offer everyone truly qualified on the lookout with. It's always not likely everyday there is chances read a little something. extremely well written article as. I will be sure to and return to read more of your useful information. Thanks for the post. I’ll certainly comeback

Unknown said...

Thats rightly set it the way the author talks to you makes you studychat.inread more and complete the book quickly!!!
sarkari result

Dale Morris said...

Norton Customer Service phone number
McAfee contact number
Malwarebytes support
Hp printer support for mac
Canon printer technical support phone number

Kartik said...

The list could go on and on because you are one fantastic mother!
https://www.motherdayquotesi.com
motherdayquotesi

magicjack support number said...

Magicjack Live Chat,How to do Magicjack Live Chat,Magicjack Customer Service,Magicjack Customer care,Magicjack Phone Number,Magicjack Customer care Chat,Magicjack Number,Magicjack Care,Magicjack Help Support,Magicjack Support,Magicjack Technical Support,Magicjack Customer Support Support,Magicjack Toll Free Number,Magicjack Help,Magicjack Not Working,How To Connect Magicjack To Wi Fi,Magicjack Live Chat Online

kiranji_16 said...

RAGE 2
Redshift Render Crack

wasi1234 said...

cubase pro crack
recover my files crack
vray crack for sketchup
shanpc

javaid sweet said...

Thank you, I’ve recently been searching for information about this subject for a long time and yours is the best I have found out so far.Wintousb Enterprise Crack

Jonny Sin said...

IDM Crack

tayyab said...

Connectify Hotspot Pro Crack
Spyhunter Pro Crack
Cracks
Cockos Reaper Crack
Piriform Recuva Pro Crack
Cadsoft Eagle Pro Crack

Folio Raux said...

Clear the tapes and protective paper from the scanner lid, ink cartridge and paper tray.
123 hp com setup
123hp

Folio Raux said...

Check the accessories that accompanied the HP Printer with the help of the list.
123.hp.com/setup

Malik Ismail said...

Hello there, could you tell me which blog platform you're working with?
I'm thinking about starting my blog soon, but I can't decide between BlogEngine/Wordpress/B2evolution and Drupal.
I'm curious because your design appears to be unique.
I'm looking for something different than other blogs.
P.S. Please accept my apologies for straying from the topic, but I had to inquire!
filebot crack
reimage pc repair crack
cleanmymac crack
razer surround pro crack

abdul sattar said...

Hey! This is my first visit to your blog.
We are a collection of volunteers starting with one
a new project in the community in the same niche.
Your blog has provided us with useful information to work with. YOU
did a fantastic job!
screamer radio crack
final draft crack
prism video file converter crack
easeus partition master crack

Naeem said...

On the Internet, I was overjoyed to discover this establishment.
This was a fantastic read, and I owe it to you at least once.
It piqued my interest a little, and you were kind enough to keep it.
Become a fan of a new item on your site.
screamer radio crack
switch sound file converter crack
freemake video downloader crack
tenorshare reiboot crack

Ali Hashim said...

Woah! This site's template/theme appeals to me much.
It's straightforward, yet it's effective. Getting the "perfect balance" might be difficult at times.
between excellent usability and aesthetics, I think you did a fantastic job on this.
Furthermore, the blog is quite rapid to load.
I'm using Firefox. Fantastic website!
ld player crack
little snitch crack
movavi video editor plus
aurora 3d presentation crack

ISPR said...

Thanks for the wonderful message! I really enjoyed reading
You can be a good writer. Bad Alvzis Blog and Testament
He'll be back later. I want to argue
Keep up the good work, have a great weekend!
And I appreciate your work, I'm a great blogger.
This article bothered me a lot.
I will bookmark your site and continue searching for new information.
aegisub crack
aiseesoft screen rec crack
synchredible professional crack
videosolo video converter ultimate crack

Ultimate Crack said...

I like your all post. You Have Done really good Work On This Site. Thank you For The Information You provided. It helps Me a lot. It Is Very Informative Thanks For Sharing. I have also Paid This sharing. I am ImPressed For With your Post Because This post is very beneficial for me and provides new knowledge to me. This is a cleverly
written article. Good work with the hard work you have done I appreciate your work thanks for sharing it.
It Is very Wounder Full Post.
apowersoft video editor crack
apowersoft video editor crack
apowersoft video editor crack
apowersoft video editor crack

Freeversioncrack said...

I am very happy to find this blog. Thanks for sharing it. It's an amazing blog for information.
du-meter-crack
isumsoft-zip-password-refixer-crack
imyfone-lockwiper-crack
anytrans-for-ios-crack
navicat-premium-crack-download
driver-talent-pro-crack

Unknown said...

I enjoyed reading
you will be a secretary. I will definitely tag your blog
and eventually he returns from then on. This excellent site definitely has all the information I have
was required in connection with this case and I did not know who to ask.
kmsauto net crack
solidworks crack
oo defrag professional edition crack

Malik Aqib said...

Wow, amazing block structure! How long
Have you written a blog before? Working on a blog seems easy.
The overview of your website is pretty good, not to mention what it does.
In the content!
vstpatch.net
Raxco PerfectRegistry Crack
Articulate Storyline Crack
TriDef 3D Crack
Rapid SEO Tool Crack
iSumsoft ZIP Password Refixer Crack

softwear said...

I am very thankful for the effort put on by you, to help us, Thank you so much for the post it is very helpful, keep posting such type of Article.
ThunderSoft Audio Editor Deluxe Crack
Rocket LeagueRocket League Full Version
Atom Crack

Punjabians said...

Here at Karanpccrack, you will get all your favourite software. Our site has a collection of useful software. That will help for your, Visite here and get all your favourite and useful software free.
Infix PDF Editor Pro Crack

ch said...

freemake video downloader crack
movavi screen recorder crack
easy duplicate finder crack
minitab crack
unhackme crack
nero burning rom crack

procracktool said...

It's Really good blog i Like the way how you explain it.
I am grateful to read it. Thanks for sharing.
procracktool
spotify premium crack
ultraiso crack
microsoft office 2019 crack
inpage free download

Anonymous said...

Wzr-Hp-G300Nh Router: Advanced Printer Sharing With Hotplug >>>>> Download Now

>>>>> Download Full

Wzr-Hp-G300Nh Router: Advanced Printer Sharing With Hotplug >>>>> Download LINK

>>>>> Download Now

Wzr-Hp-G300Nh Router: Advanced Printer Sharing With Hotplug >>>>> Download Full

>>>>> Download LINK 59

Unknown said...

I like your all post. You have done really good work. Thank you for the information you provide, it helped me a lot. I hope to have many more entries or so from you.
Very interesting blog.
vstkey.com
LD Player Crack
PUBG PC Crack
Enscape 3D Crack

Skidrowkeyz said...

I am very impressed with your post because this post is very beneficial for me and provide a new knowledge to me.
WRC 10 Crack
eFootball PES 2021
homeguard pro crack
Crying Suns Crack

Post a Comment