DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2011-03-04 17:24:48

psyko57
Member
Registered: 2011-03-04
Posts: 8

USB keyboard or similar

Hi all,

I wonder how to manage an USB keyboard (or similar like a barcode scanner) with the DNS323...

What i want to do is to launch a script with what i type on the keyboard as parameter for example.
(for example if i type test[enter] i want to launch the command ./myscript test)

Do you see a way to do this ?

Thanks in advance.

Offline

 

#2 2011-03-07 14:59:49

psyko57
Member
Registered: 2011-03-04
Posts: 8

Re: USB keyboard or similar

Nobody have ANY idea to do that ?

Thanks.

Offline

 

#3 2011-03-07 18:26:50

fordem
Member
Registered: 2007-01-26
Posts: 1938

Re: USB keyboard or similar

Well - for starters, you're going to need to compile the appropriate HID (human interface device) driver for the processor and load it, and seeing as there's no display ...

Understand this - the possibilities are limited only by your capabilities - however, there is a point of what is known as "diminishing returns", when it would just be simpler to start with standard PC and do what you need.

Offline

 

#4 2011-03-07 23:03:01

dhub
Member
Registered: 2011-01-01
Posts: 112

Re: USB keyboard or similar

Actually, I could see some value in this since it would provide an easy way to add additional buttons to the NAS.

It would have some serious potential if combined with say a USB display device (say a usb picture frame) or a Mimo usb monitor. 

I could also see it being useful in things like reloaded fun plug scripts, say have the script terminate if the user is holding down a key on the keyboard (would be handy for a hanging reloaded script)

Offline

 

#5 2011-03-07 23:23:12

FunFiler
Member
Registered: 2010-05-23
Posts: 577

Re: USB keyboard or similar

Personally I see little value in it (actually, none). You can telnet/ssh into the unit and perform any action and even see what you are typing and the responses. I purchased these units since I specifically wanted a headless device, low power consumption, small space etc. The last thing I want is another keyboard (larger than the unit itself). Everything I need to script is done and I rarely telnet in any more. I have 2xDNS-323 units and 3 full Linux servers. None have mice, keyboards or monitors. I can telnet in from a PC, my smartphone or a number of other devices locally wired, wireless or remote.

Last edited by FunFiler (2011-03-07 23:27:24)


3 * (DNS-323 with 2 * 2TB) = 12TB Running FW v1.08 & FFP v0.5
Useful Links: Transmission, Transmission Remote, Automatic

Offline

 

#6 2011-03-08 10:34:05

Mijzelf
Member / Developer
Registered: 2008-07-05
Posts: 709

Re: USB keyboard or similar

Actually I have connected a keyboard to my NAS. (Only the PCB, btw). I use it as a cheap IO device. The leds are exchanged by optocouplers, and so I can 3 external devices by toggling the keyboard leds. I suppose it's also possible to use it as IO input, by shorting one or more of the keyboard matrix lines, but I never tried.

Offline

 

#7 2011-03-08 10:50:27

psyko57
Member
Registered: 2011-03-04
Posts: 8

Re: USB keyboard or similar

fordem wrote:

you're going to need to compile the appropriate HID (human interface device) driver for the processor and load it

Thanks for the advice, any good links to start with this ?

FunFiler wrote:

Personally I see little value in it (actually, none).

Think about a barcode scanner for example : you just scan something and the NAS will do what you want (to manage your books for example) You don't need any display or thing like that (you can maybe let the front leds blink to inform the user that the action was successful)

Mijzelf wrote:

Actually I have connected a keyboard to my NAS. (Only the PCB, btw).

Nice job ! How exactly did you do that ?

Thanks for your responses wink

Offline

 

#8 2011-03-08 14:41:20

Mijzelf
Member / Developer
Registered: 2008-07-05
Posts: 709

Re: USB keyboard or similar

psyko57 wrote:

How exactly did you do that ?

First, I didn't do it on a DNS-323, but on a ZyXEL NSA-220. Same SoC, other box. As fordem said, you need to compile the appropriate HID driver, usbhid.ko in this case, and maybe some dependencies. Load it, plugin the keyboard, and the keyboard is found as /dev/tty0.

I use setleds to toggle the leds:

Code:

setleds -L +num </dev/tty0
sleep 2
setleds -L -num </dev/tty0

Although I didn't try I suppose you can read the keystrokes with

Code:

cat /dev/tty0

But a problem could be that this stream won't end, so you can't do

Code:

CMD=` cat /dev/tty0 `

in your script. You'll need a readln functionality. Don't know if there is a standard script tool for it.

Offline

 

#9 2011-03-10 10:53:35

psyko57
Member
Registered: 2011-03-04
Posts: 8

Re: USB keyboard or similar

Mijzelf wrote:

you need to compile the appropriate HID driver, usbhid.ko in this case, and maybe some dependencies.

Thanks, but can you give me more hint on how to do this ?
Thanks a lot.

Offline

 

#10 2011-03-10 18:24:08

Mijzelf
Member / Developer
Registered: 2008-07-05
Posts: 709

Re: USB keyboard or similar

I have no experience in compiling kernel modules for a 323. I *think* you need to build a cross compiling environment first. Or at least you need the same compiler as mentioned in

Code:

cat /proc/version

and the kernelsources.

But maybe you can just use the module here.

Offline

 

#11 2011-03-10 21:30:52

dhub
Member
Registered: 2011-01-01
Posts: 112

Re: USB keyboard or similar

I'm using the reloaded method to run debian squeeze with the debian kernel and kernel modules (I don't want to overwrite the dlink firmware since I don't have a serial console)

The debian kernel module package does have most of the normal kernel modules (88 total) including the usbhid module.  I imagine it's about the same amount of work to get a reloaded debian environment working as it is to get the toolchain and build the modules for the dlink kernel (assuming the modules don't require a kernel setting that dlink didn't enable).

Offline

 

#12 2011-03-11 17:41:03

psyko57
Member
Registered: 2011-03-04
Posts: 8

Re: USB keyboard or similar

I've tried to load the plugin, but i can't "cat /dev/tty0"...
I'm searching other solutions...
If you have any ideas...

Offline

 

#13 2011-03-11 19:37:53

Mijzelf
Member / Developer
Registered: 2008-07-05
Posts: 709

Re: USB keyboard or similar

psyko57 wrote:

I've tried to load the plugin, but i can't "cat /dev/tty0"...

Did it load? What did dmesg say when you plugged in the keyboard?

Offline

 

#14 2011-03-11 21:44:00

psyko57
Member
Registered: 2011-03-04
Posts: 8

Re: USB keyboard or similar

dmesg wrote:

usb 1-1: new low speed USB device using ehci_platform and address 4
input: USB HID v1.10 Keyboard [USB-TMU-V1] on usb-ehci_platform.20865-1

I seems to be ok for me...

Offline

 

#15 2011-03-12 10:29:23

Mijzelf
Member / Developer
Registered: 2008-07-05
Posts: 709

Re: USB keyboard or similar

Hm. Mine says:

Code:

usb 2-1: new low speed USB device using ehci_platform and address 7
usb 2-1: configuration #1 chosen from 1 choice
input:   USB Keyboard as /class/input/input0
input: USB HID v1.10 Keyboard [  USB Keyboard] on usb-ehci_platform.16781-1
input:   USB Keyboard as /class/input/input1
input: USB HID v1.10 Device [  USB Keyboard] on usb-ehci_platform.16781-1

So it's recognized as a keyboard *and* as a device. Don't know what that means, though.
About cat /dev/tty0; do you have that node? On my system it's

Code:

crw-rw---- 1 root root 4, 0 2011-02-20 14:14 /dev/tty0

Further it's not world readable (unless you change that), so it can only be 'cat'ed by root.
When you 'cat' it, you only see the output when you press enter,

Offline

 

#16 2011-03-13 06:51:57

psyko57
Member
Registered: 2011-03-04
Posts: 8

Re: USB keyboard or similar

Yes i have tty0, with the same rights than yours...
I've tried to cat with root user but nothing appears...

Offline

 

#17 2011-03-13 10:02:07

Mijzelf
Member / Developer
Registered: 2008-07-05
Posts: 709

Re: USB keyboard or similar

Try to load usbkbd.ko

Offline

 

#18 2011-03-13 18:11:18

psyko57
Member
Registered: 2011-03-04
Posts: 8

Re: USB keyboard or similar

If i just load usbkbd i have this :

dmesg wrote:

usb 1-1: new low speed USB device using ehci_platform and address 6
input:  USB-TMU-V1 on usb-ehci_platform.20865-1

If i load both (usbkbd & usbhid) I have have the same message than the first time (post #14)

(In both cases, cat /dev/tty0 don't display anything...)

I've tried to do 'echo plop > /dev/tty0' but even with this, 'cat /dev/tty0' don't display anything... Is it normal ? Maybe we just can't 'cat' a tty ?

Thnaks a lot for your help wink

Offline

 

#19 2011-03-13 20:47:07

Mijzelf
Member / Developer
Registered: 2008-07-05
Posts: 709

Re: USB keyboard or similar

psyko57 wrote:

I've tried to do 'echo plop > /dev/tty0' but even with this, 'cat /dev/tty0' don't display anything...

(Plop?) That is normal, A 'tty' is sort of a terminal. So 'echo plop >/dev/tty0' displays plop on the monitor assigned to that tty, while reading gives the input of the keyboard, and maybe even of the mouse.

Maybe we just can't 'cat' a tty ?

I can. But it's a different box and a different kernel, and I don't know which differences are important.
Some googling on 'keyboard embedded linux' led me to SamyGO, some TV hacking project, and it gave me this script:
MouseAndKeyboard.sh:

Code:

#!/bin/sh

cd $1

# Load keyboard and mouse support
insmod ./modules/usbhid.ko
insmod ./modules/evdev.ko

# Generate input device nodes at /dtv
i=0
while [ $i -le 31 ]
do
    mknod /dtv/event$i c 13 $(($i + 64))
    i=$(( i + 1 )) 
done

I think /dtv can be translated to /dev in our case. But I must admit that there are no /dev/eventx on my box.

I un- and reconnected the keyboard, and udev made this modifications. In /dev:
crw-rw---- 1 root root    442, 2057 2011-03-13 19:34 usbdev2.10_ep00
crw-rw---- 1 root root    442, 2057 2011-03-13 19:34 usbdev2.10_ep81
crw-rw---- 1 root root    442, 2057 2011-03-13 19:34 usbdev2.10_ep82
drwxr-xr-x 2 root root         2800 2011-03-13 19:34 char
crw-rw-rw- 1 root root      5,    2 2011-03-13 19:35 ptmx
in /dev/char:
lrwxrwxrwx 1 root root 18 2011-03-13 19:34 442:2057 -> ../usbdev2.10_ep82
lrwxrwxrwx 1 root root 18 2011-03-13 19:34 189:137 -> ../bus/usb/002/010
And this 189:137 points to:
crw-rw-r-- 1 root root 189, 137 2011-03-13 19:34 010

It's not clear to me what this all means.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB