[sane-devel] Canon I-Sensys MF4780w "push mode" scanning

Alexander Lyashuk mooskagh at gmail.com
Sun Aug 22 09:13:47 BST 2021


I think I'm close to making it work, although I had to write some code
rather than use sane for polling the buttons.

Few observations:
1. In the MFNP scanner command 50 (0x32), subcommands 2 and 3, sane sends
the hostname UTF-16 (or USC-2) encoded.
MF4780w expects it in ASCII (or UTF-8?). Which means that if I poll my
device with SANE, it's displayed as an empty line.
Possibly that's a difference between MFNP and BJNP protocols, or maybe
printer/scanner tells the codepage to use in earlier packets.

2. When I select "Scanner" -> "Computer" -> "<hostname>" -> {"B/W" /
"Color" / "Custom 1" / "Custom 2"} on my device, the response to my MFNP
command 50 subcommand 2 looks like this:
Payload: 00 00 80 00 00 50 85 f4 00 00 00 05 00 00 00 04 01 00 00 00 00
                                                      ^^ ^^
                                                      |   \ This "01" is
either 01 or 02 or 03 or 04 depending whether it's "B/W" or "Color" and so
on
                                                       \ Instead of this
"04", "00" is returned when the scanner is in stand by mode
`scanimage -A` doesn't return values of the buttons for some reason. I'm
not sure why exactly (e.g. maybe printer is confused with UTF-16 hostname,
maybe the button location in the response is not where SANE looks for it,
maybe dialog_id is lost somewhere).

3. Before scanning, the Windows driver also sends MFNP command 64 (0x40),
with this payload:
Payload: f3 20 00 00 00 00 00 00 0c 00
Return payload is something like:
Payload: 06 06 03 01 00 41 03 00 41 00 01 00 00 76
It seems to return printer/scanner's settings (I tried to change paper size
etc in settings and the line changed), but I think the only useful piece of
information for scanning is the last bit: that 0x76 becomes 0x77 when there
is something in the scanner feeder.

4. After sending the response, the scanner goes into the listening mode,
and you can scan from any program using SANE (I suspect you can even do
that from a different host).
That means that after handing the initial handshake by sending those UDP
packets manually, the rest looks promising with scanning through SANE.
The main worry that I have is whether SANE will be able to handle scanning
multiple pages in a flatbed while being controlled from the scanner side.


I'll keep you posted for any progress that I'll have. Any further advice
would be appreciated.


On Sun, Aug 15, 2021 at 8:54 PM Alexander Lyashuk <mooskagh at gmail.com>
wrote:

> Thanks for the suggestion, but I actually don't have any windows machine
> that I can use for that.
>
> I only started windows in a virtualbox to observe the network traffic
> between it and the scanner.
> (and also I reboot my laptop to windows sometimes, mentioning that just to
> explain why I used "windows machines" in plural in my previous message)
>
> If you suggest that the scanner itself would upload documents via SMB,
> unfortunately MF4780w is quite old and doesn't support that, as well as
> other convenient options like scanning to email, so unless I'm missing
> something I'm stuck with using either MFNP or WSD.
>
> On Sun, Aug 15, 2021 at 7:36 PM Jörn-Ingo Weigert <jiweigert at gmail.com>
> wrote:
>
>> Just a guess without having that scanner model:
>>
>> You should be able to use your desired mode, when you share a folder on
>> windows and set  both access and security to "everyone" in the properties
>> of the shared folder.
>>
>> In the settings of your scanner you should enable "SMB" protocol too.
>>
>> Hope that help you
>>
>> Alexander Lyashuk <mooskagh at gmail.com> schrieb am So., 15. Aug. 2021,
>> 12:31:
>>
>>> One more thing to add, maybe WSD will be an easier option.
>>>
>>> It's possible to enable WSD support for this scanner.
>>>
>>> In that case, I also can scan in "Remote scanner" mode through the
>>> sane-airscan backend.
>>> I can also start scanning to the windows machines from the scanner
>>> through WSD (when I select "Scan" -> "Computer", all windows machines in my
>>> local network appear, even ones without Canon drivers, unlike it was with
>>> MFNP-only mode).
>>>
>>> However, when I do `scanimage --device-name=airscan:w0:mf4780w -A`
>>> similarly to what I attempted with MFNP mode, no new lines appear in the
>>> list of destinations.
>>> Also `scanimage -A` doesn't show the state of buttons in this case.
>>>
>>>
>>> On Sun, Aug 15, 2021 at 11:43 AM Alexander Lyashuk <mooskagh at gmail.com>
>>> wrote:
>>>
>>>> Hi sane-devel,
>>>>
>>>> I have a Canon i-Sensys MF4780w network scanner/printer.
>>>>
>>>> It has two ways to start scanning:
>>>> - "Remote scanner" / "pull mode", when you enable that mode on the
>>>> device and then continue on the computer.
>>>> - "Computer" / "push mode", where you select the destination and
>>>> initiate scanning from the scanner itself.
>>>>
>>>> My scanner works well in "Remote scanner" mode (through the pixma
>>>> backend, I've added "mfnp://10.162.0.7" to pixma.conf).
>>>> I'd like to be able to initiate the scans from the scanner (in
>>>> "Computer"/push mode) though, so that I can set up a headless server which
>>>> will upload documents to Google Drive.
>>>>
>>>> So far I failed to set it up that way, and I wonder whether there is
>>>> any hope.
>>>>
>>>> When I select "Scan" -> "Computer" on my scanner,
>>>> - First I have to select the destination.
>>>> - Then I select the mode (Color/BnW/Custom1/Custom2).
>>>>
>>>> I checked what Windows does to appear in the list of destinations, and
>>>> it seems that it sends an MFNP message to the scanner every 5 seconds and
>>>> so.
>>>>
>>>> I tried to do the same from Linux by calling `scanimage -A` in the
>>>> loop. When I did that, a selectable extra empty line indeed appeared in the
>>>> list of destinations on the scanner. I checked the messages from Windows
>>>> and Linux in network sniffer and it appears that Windows sends the hostname
>>>> in ASCII format, while on Linux it's UTF-16, that's the likely reason why
>>>> the scanner cannot display the destination name properly.
>>>> I wouldn't mind having an empty line as a hostname though as long as it
>>>> would work.
>>>>
>>>> When I select "Scan" -> "Computer" -> "empty line" -> "Custom 1" (or
>>>> BnW/Custom2/Color), both --button-1 and --button-2 still show value [0] in
>>>> `scanimage -A`, so I cannot find any way to know I should start scanning.
>>>>
>>>> I also tried to use scanbd, but it appears not to be able to find the
>>>> scanner at all:
>>>>
>>>> [root]# SANE_CONFIG_DIR=/usr/local/etc/scanbd/ ./scanbd -f -d7
>>>> ./scanbd: reading config file /usr/local/etc/scanbd/scanbd.conf
>>>> ./scanbd: debug on: level: 7
>>>> ./scanbd: dropping privs to uid root
>>>> ./scanbd: dropping privs to gid scanner
>>>> ./scanbd: drop privileges to gid: 96
>>>> ./scanbd: Running as effective gid 96
>>>> ./scanbd: drop privileges to uid: 0
>>>> ./scanbd: Running as effective uid 0
>>>> ./scanbd: dbus_init
>>>> ./scanbd: dbus match
>>>> type='signal',interface='org.freedesktop.Hal.Manager'
>>>> ./scanbd: SANE_CONFIG_DIR=/usr/local/etc/scanbd/
>>>> ./scanbd: sane version 1.0
>>>> ./scanbd: Scanning for local-only devices
>>>> ./scanbd: start_sane_threads
>>>> ./scanbd: no devices, not starting any polling thread
>>>> ./scanbd: start dbus thread
>>>> ./scanbd: Not Primary Owner (-1)
>>>> ./scanbd: Name Error (Connection ":1.219" is not allowed to own the
>>>> service "de.kmux.scanbd.server" due to security policies in the
>>>> configuration file)
>>>> ./scanbd: udev init
>>>> ./scanbd: get udev monitor
>>>> ./scanbd: udev fd is non-blocking, now setting to blocking mode
>>>> ./scanbd: start udev thread
>>>> ./scanbd: udev thread started
>>>>
>>>> Note the string "Scanning for local-only devices", does it mean it
>>>> doesn't attempt to scan network devices?
>>>>
>>>> Any suggestions on what to try next would be very appreciated.
>>>>
>>>> Thanks!
>>>>
>>>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/sane-devel/attachments/20210822/41f36382/attachment.htm>


More information about the sane-devel mailing list