Re: [sane-devel] AXIS 1650 support for Pixma backend - work in progress

2020-03-23 Thread Ondrej Zary
On Friday 20 March 2020 19:58:20 Rolf Bensch wrote:
> Hi Ondrej,
> 
> Many thanks for your message.
> 
> Am 20.03.20 um 18:44 schrieb Ondrej Zary:
> > Hello,
> > I have a Canon MF5730 MFP with external AXIS 1650 print server:
> > https://www.axis.com/techsup/prtsrv/axis_1650/index.htm
> >
> > I've reverse engineered the print data format and wrote CUPS driver couple 
> > of
> > years ago so printing works fine.
> >
> > Now it's time for scanning. Thanks to SANE and Pixma backend, scanning works
> > when connected directly using the USB port (except for the buttons).
> >
> > The scan mode of AXIS 1650 works as USB-over-TCP.
> > The Windows AXIS Scan Client discovers and identifies local scan-capable 
> > print
> > servers using a simple UDP-based WIMP protocol:
> > https://www.axis.com/techsup/prtsrv/axis_1650/technotes_1650.htm#2
> >
> > Then it connects to the selected print server using TCP, locking it for the
> > current user, and creates a virtual USB device so the Canon driver could be
> > used to scan.
> >
> > I've based AXIS support for Pixma backend on the BJNP code.
> > What works:
> >  - autodetection
> >  - connect
> >  - scan starts
> > What does not:
> >  - data gets messed up somehow
> >  - scan does not finish successfully
> >  - set_timeout, interrupts not implemented
> >
> >
> I just created a merge request here:
> https://gitlab.com/sane-project/backends/-/merge_requests/361.
> 
> Please check if your code still is working. I needed to fix some issues
> while merging to recent master branch.
> 
> Please follow the merge request and provide your fixes there.

Thanks. Will try it and then hopefully fix my horrible code upstream.
BTW. I can scan now!

> Hope this helps.
> 
> Cheers,
> Rolf
> 
>   *
> 
> 
>   *
> 
> 
> !361 
> 
>   *
> 
> 
>   *
> 
> 
> !361 
> 
> 


-- 
Ondrej Zary



Re: [sane-devel] AXIS 1650 support for Pixma backend - work in progress

2020-03-20 Thread Ondrej Zary
AXIS 1650 scanning support is limited to specific Canon devices only:
https://www.axis.com/techsup/prtsrv/axis_1650/printers_eur.htm

In theory, it could work as generic USB-over-TCP device but it does not. The 
firmware probably includes a whitelist of supported devices or some other way 
to know when to enable the scan feature. It also seems to do some data 
transfers automatically (like polling interrupt endpoints).

On Friday 20 March 2020 22:14:21 m. allan noah wrote:
> I'm confused- are you proposing to add a new backend that lets pixma
> scanners work over this AXIS machine, but not other scanners?
> 
> allan
> 
> On Fri, Mar 20, 2020 at 2:58 PM Rolf Bensch  wrote:
> >
> > Hi Ondrej,
> >
> > Many thanks for your message.
> >
> > Am 20.03.20 um 18:44 schrieb Ondrej Zary:
> >
> > Hello,
> > I have a Canon MF5730 MFP with external AXIS 1650 print server:
> > https://www.axis.com/techsup/prtsrv/axis_1650/index.htm
> >
> > I've reverse engineered the print data format and wrote CUPS driver couple 
> > of
> > years ago so printing works fine.
> >
> > Now it's time for scanning. Thanks to SANE and Pixma backend, scanning works
> > when connected directly using the USB port (except for the buttons).
> >
> > The scan mode of AXIS 1650 works as USB-over-TCP.
> > The Windows AXIS Scan Client discovers and identifies local scan-capable 
> > print
> > servers using a simple UDP-based WIMP protocol:
> > https://www.axis.com/techsup/prtsrv/axis_1650/technotes_1650.htm#2
> >
> > Then it connects to the selected print server using TCP, locking it for the
> > current user, and creates a virtual USB device so the Canon driver could be
> > used to scan.
> >
> > I've based AXIS support for Pixma backend on the BJNP code.
> > What works:
> >  - autodetection
> >  - connect
> >  - scan starts
> > What does not:
> >  - data gets messed up somehow
> >  - scan does not finish successfully
> >  - set_timeout, interrupts not implemented
> >
> >
> > I just created a merge request here: 
> > https://gitlab.com/sane-project/backends/-/merge_requests/361.
> >
> > Please check if your code still is working. I needed to fix some issues 
> > while merging to recent master branch.
> >
> > Please follow the merge request and provide your fixes there.
> >
> > Hope this helps.
> >
> > Cheers,
> > Rolf
> >
> >
> > !361
> >
> >
> > !361
> 
> 
> 


-- 
Ondrej Zary



Re: [sane-devel] AXIS 1650 support for Pixma backend - work in progress

2020-03-20 Thread m. allan noah
I'm confused- are you proposing to add a new backend that lets pixma
scanners work over this AXIS machine, but not other scanners?

allan

On Fri, Mar 20, 2020 at 2:58 PM Rolf Bensch  wrote:
>
> Hi Ondrej,
>
> Many thanks for your message.
>
> Am 20.03.20 um 18:44 schrieb Ondrej Zary:
>
> Hello,
> I have a Canon MF5730 MFP with external AXIS 1650 print server:
> https://www.axis.com/techsup/prtsrv/axis_1650/index.htm
>
> I've reverse engineered the print data format and wrote CUPS driver couple of
> years ago so printing works fine.
>
> Now it's time for scanning. Thanks to SANE and Pixma backend, scanning works
> when connected directly using the USB port (except for the buttons).
>
> The scan mode of AXIS 1650 works as USB-over-TCP.
> The Windows AXIS Scan Client discovers and identifies local scan-capable print
> servers using a simple UDP-based WIMP protocol:
> https://www.axis.com/techsup/prtsrv/axis_1650/technotes_1650.htm#2
>
> Then it connects to the selected print server using TCP, locking it for the
> current user, and creates a virtual USB device so the Canon driver could be
> used to scan.
>
> I've based AXIS support for Pixma backend on the BJNP code.
> What works:
>  - autodetection
>  - connect
>  - scan starts
> What does not:
>  - data gets messed up somehow
>  - scan does not finish successfully
>  - set_timeout, interrupts not implemented
>
>
> I just created a merge request here: 
> https://gitlab.com/sane-project/backends/-/merge_requests/361.
>
> Please check if your code still is working. I needed to fix some issues while 
> merging to recent master branch.
>
> Please follow the merge request and provide your fixes there.
>
> Hope this helps.
>
> Cheers,
> Rolf
>
>
> !361
>
>
> !361



-- 
"well, I stand up next to a mountain- and I chop it down with the edge
of my hand"



Re: [sane-devel] AXIS 1650 support for Pixma backend - work in progress

2020-03-20 Thread Rolf Bensch
Hi Ondrej,

Many thanks for your message.

Am 20.03.20 um 18:44 schrieb Ondrej Zary:
> Hello,
> I have a Canon MF5730 MFP with external AXIS 1650 print server:
> https://www.axis.com/techsup/prtsrv/axis_1650/index.htm
>
> I've reverse engineered the print data format and wrote CUPS driver couple of
> years ago so printing works fine.
>
> Now it's time for scanning. Thanks to SANE and Pixma backend, scanning works
> when connected directly using the USB port (except for the buttons).
>
> The scan mode of AXIS 1650 works as USB-over-TCP.
> The Windows AXIS Scan Client discovers and identifies local scan-capable print
> servers using a simple UDP-based WIMP protocol:
> https://www.axis.com/techsup/prtsrv/axis_1650/technotes_1650.htm#2
>
> Then it connects to the selected print server using TCP, locking it for the
> current user, and creates a virtual USB device so the Canon driver could be
> used to scan.
>
> I've based AXIS support for Pixma backend on the BJNP code.
> What works:
>  - autodetection
>  - connect
>  - scan starts
> What does not:
>  - data gets messed up somehow
>  - scan does not finish successfully
>  - set_timeout, interrupts not implemented
>
>
I just created a merge request here:
https://gitlab.com/sane-project/backends/-/merge_requests/361.

Please check if your code still is working. I needed to fix some issues
while merging to recent master branch.

Please follow the merge request and provide your fixes there.

Hope this helps.

Cheers,
Rolf

  *


  *


!361 

  *


  *


!361 



[sane-devel] AXIS 1650 support for Pixma backend - work in progress

2020-03-20 Thread Ondrej Zary
Hello,
I have a Canon MF5730 MFP with external AXIS 1650 print server:
https://www.axis.com/techsup/prtsrv/axis_1650/index.htm

I've reverse engineered the print data format and wrote CUPS driver couple of
years ago so printing works fine.

Now it's time for scanning. Thanks to SANE and Pixma backend, scanning works
when connected directly using the USB port (except for the buttons).

The scan mode of AXIS 1650 works as USB-over-TCP.
The Windows AXIS Scan Client discovers and identifies local scan-capable print
servers using a simple UDP-based WIMP protocol:
https://www.axis.com/techsup/prtsrv/axis_1650/technotes_1650.htm#2

Then it connects to the selected print server using TCP, locking it for the
current user, and creates a virtual USB device so the Canon driver could be
used to scan.

I've based AXIS support for Pixma backend on the BJNP code.
What works:
 - autodetection
 - connect
 - scan starts
What does not:
 - data gets messed up somehow
 - scan does not finish successfully
 - set_timeout, interrupts not implemented


diff --git a/backend/Makefile.am b/backend/Makefile.am
index a28e749f..274d5490 100644
--- a/backend/Makefile.am
+++ b/backend/Makefile.am
@@ -821,7 +821,7 @@ libsane_pint_la_CPPFLAGS = $(AM_CPPFLAGS) 
-DBACKEND_NAME=pint
 libsane_pint_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS)
 libsane_pint_la_LIBADD = $(COMMON_LIBS) libpint.la 
../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo 
../sanei/sanei_config.lo  sane_strstatus.lo
 
-libpixma_la_SOURCES = pixma.c pixma.h pixma_io_sanei.c pixma_io.h 
pixma_common.c pixma_common.h pixma_mp150.c pixma_mp730.c pixma_mp750.c 
pixma_mp810.c pixma_imageclass.c pixma_bjnp.c pixma_bjnp.h pixma_bjnp_private.h 
pixma_rename.h
+libpixma_la_SOURCES = pixma.c pixma.h pixma_io_sanei.c pixma_io.h 
pixma_common.c pixma_common.h pixma_mp150.c pixma_mp730.c pixma_mp750.c 
pixma_mp810.c pixma_imageclass.c pixma_bjnp.c pixma_bjnp.h pixma_bjnp_private.h 
pixma_rename.h pixma_axis.c pixma_axis.h
 libpixma_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=pixma
 
 nodist_libsane_pixma_la_SOURCES = pixma-s.c
diff --git a/backend/pixma_axis.c b/backend/pixma_axis.c
new file mode 100644
index ..0c2b528e
--- /dev/null
+++ b/backend/pixma_axis.c
@@ -0,0 +1,576 @@
+#undef BACKEND_NAME
+#define BACKEND_NAME axis
+
+#include  "../include/sane/config.h"
+#include  "../include/sane/sane.h"
+
+/*
+ * Standard types etc
+ */
+#ifdef HAVE_STDLIB_H
+#include 
+#endif
+#ifdef HAVE_STRING_H
+#include 
+#endif
+#include 
+#include 
+#ifdef HAVE_STDINT_H
+#include 
+#endif
+#ifdef HAVE_SYS_TYPES_H
+#include 
+#endif
+#ifdef HAVE_SYS_TIME_H
+#include 
+#endif
+
+/*
+ * networking stuff
+ */
+#ifdef HAVE_SYS_SOCKET_H
+#include 
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include 
+#endif
+#include 
+#include 
+#include 
+#include 
+#ifdef HAVE_IFADDRS_H
+#include 
+#endif
+#ifdef HAVE_SYS_SELSECT_H
+#include 
+#endif
+#ifdef HAVE_PWD_H
+#include 
+#endif
+#include 
+#ifdef HAVE_FCNTL_H
+#include 
+#endif
+
+#include "pixma_axis_private.h"
+#include "pixma_axis.h"
+#include "pixma.h"
+#include "pixma_common.h"
+
+#define MAX_PACKET_DATA_SIZE   65535
+#define RECEIVE_TIMEOUT2
+
+/* static data */
+static axis_device_t device[AXIS_NO_DEVICES];
+static int axis_no_devices = 0;
+
+extern void
+sanei_axis_init (void)
+{
+  DBG_INIT();
+  axis_no_devices = 0;
+}
+
+static char *getusername(void) {
+  static char noname[] = "sane_pixma";
+  struct passwd *pwdent;
+
+#ifdef HAVE_PWD_H
+  if (((pwdent = getpwuid(geteuid())) != NULL) && (pwdent->pw_name != NULL))
+return pwdent->pw_name;
+#endif
+  return noname;
+}
+
+static ssize_t receive_packet(int socket, void *packet, size_t len, struct 
sockaddr_in *from) {
+  fd_set rfds;
+  struct timeval tv;
+  ssize_t received;
+  socklen_t from_len = sizeof(struct sockaddr_in);
+
+  tv.tv_sec = RECEIVE_TIMEOUT;
+  tv.tv_usec = 0;
+  /* Watch socket to see when it has input. */
+  FD_ZERO();
+  FD_SET(socket, );
+
+  switch (select(socket + 1, , NULL, NULL, )) {
+  case 0:
+return 0;
+  case -1:
+DBG(LOG_CRIT, "select() failed");
+return 0;
+  default:
+received = recvfrom(socket, packet, len, 0, (struct sockaddr *)from, 
_len);
+if (received < 0) {
+  DBG(LOG_CRIT, "Error receiving packet");
+  exit(2);
+}
+/*#ifdef DEBUG
+int i;
+for (i = 0; i < received; i++)
+  fprintf(stderr, "%.2hhX ",((char *)packet)[i]);
+fprintf(stderr, "\n");
+#endif*/
+return received;
+  }
+}
+
+static ssize_t axis_send_wimp(int udp_socket, uint8_t cmd, void *data, 
uint16_t len, struct sockaddr *addr, socklen_t addrlen) {
+  uint8_t packet[MAX_PACKET_DATA_SIZE];
+  struct axis_wimp_header *header = (void *)packet;
+  ssize_t ret;
+
+  header->type = cmd;
+  header->magic = 0x03;
+  header->zero = 0x00;
+  memcpy(packet + sizeof(struct axis_wimp_header), data, len);
+  ret = sendto(udp_socket, packet, sizeof(struct axis_wimp_header) + len, 0, 
addr, addrlen);
+  if (ret != (int)sizeof(struct