Reverse Engineering a Samsung Scanner Button, page 1
Pages: 1 2 3 4 5 6 7 8
Isn't it aggravating that all of these great USB multi-function scanner/printer units on the market these days fail to provide any kind of Linux functionality to detect when the "Scan" button is pressed? Well, this article is going to show you how to fix this situation.
You may be wondering "Why don't you just use SANE?". Well, for reasons that I will explain later, the short answer is - you can't. SANE does not handle hardware buttons... you can only use it to initiate a scan with the software interface.
If we can somehow capture the button press, we can run the whole chain of events that occurs in order to initiate a scan and save the resulting image data to a file, just like the Windows-only driver and software does it. We can also perform some processing of the image, as well as have complete control over the destination of this file.
This guide is for those who wish to connect a USB scanner to a Linux server or workstation, and have the ability to perform a one-touch scan.
In this case, we are going to reverse engineer the USB scanner protocol of the Samsung SCX-3405w, which is a multifunction, monochrome, laser printer/scanner.
Don't be discouraged if you have a different scanner. This technique can be applied to nearly any scanner. We are going to be talking directly to the hardware.
First, a small note regarding USB behavior: USB is a host initiated protocol.
What this means to us is that, if the scanner button is pressed, the hardware (scanner ) is not capable of sending a message to the host machine. Our host machine must initiate things, so the host will have to query the scanner in order to be informed that the button has been pressed.
So our strategy cannot be to create a listening demon, running on our host, that will listen for a message from the scanner. Instead, we must query the scanner at a particular hardware address, sending a buffer for the scanner to write an answer into. We then examine this buffer and process the answer.
We will create a method to monitor the one-touch scanner button, in order to trigger a series of actions when it has been pressed. These actions will be to initiate a scan, do some slight image enhancement and then store resulting file in a specific directory named after the date and time. In this situation we are connecting the multifunction unit to a CentOS Linux host server, and we are storing the image files that are produced by the scanner on this server.
Our strategy will be to write some C code that will query a specific endpoint of the USB scanner and determine whether or not the "Scan" button has been pressed. We will keep it simple, because we only want to write code that will determine a yes/no answer and report this answer to a script which will take over from there.