2013-07-18 08:46:44 -04:00
|
|
|
/*
|
|
|
|
* CUPS Backend common code
|
|
|
|
*
|
2016-01-24 09:44:19 -05:00
|
|
|
* (c) 2013-2016 Solomon Peachy <pizza@shaftnet.org>
|
2013-07-18 08:46:44 -04:00
|
|
|
*
|
|
|
|
* The latest version of this program can be found at:
|
2014-01-12 17:26:29 -05:00
|
|
|
*
|
2013-08-20 20:10:21 -04:00
|
|
|
* http://git.shaftnet.org/cgit/selphy_print.git
|
2014-01-12 17:26:29 -05:00
|
|
|
*
|
2013-07-18 08:46:44 -04:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 3 of the License, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* [http://www.gnu.org/licenses/gpl-3.0.html]
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
2014-02-23 22:57:22 -05:00
|
|
|
#include <libusb.h>
|
2013-07-18 08:46:44 -04:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#ifndef __BACKEND_COMMON_H
|
|
|
|
#define __BACKEND_COMMON_H
|
|
|
|
|
|
|
|
#define STR_LEN_MAX 64
|
2014-10-06 21:56:55 -04:00
|
|
|
#define STATE( ... ) fprintf(stderr, "STATE: " __VA_ARGS__ )
|
|
|
|
#define ATTR( ... ) fprintf(stderr, "ATTR: " __VA_ARGS__ )
|
|
|
|
#define PAGE( ... ) fprintf(stderr, "PAGE: " __VA_ARGS__ )
|
2013-07-18 08:46:44 -04:00
|
|
|
#define DEBUG( ... ) fprintf(stderr, "DEBUG: " __VA_ARGS__ )
|
|
|
|
#define DEBUG2( ... ) fprintf(stderr, __VA_ARGS__ )
|
|
|
|
#define INFO( ... ) fprintf(stderr, "INFO: " __VA_ARGS__ )
|
2014-02-08 18:41:29 -05:00
|
|
|
#define WARNING( ... ) fprintf(stderr, "WARNING: " __VA_ARGS__ )
|
2013-07-18 08:46:44 -04:00
|
|
|
#define ERROR( ... ) do { fprintf(stderr, "ERROR: " __VA_ARGS__ ); sleep(1); } while (0)
|
|
|
|
|
|
|
|
#if (__BYTE_ORDER == __LITTLE_ENDIAN)
|
|
|
|
#define le32_to_cpu(__x) __x
|
|
|
|
#define le16_to_cpu(__x) __x
|
|
|
|
#define be16_to_cpu(__x) ntohs(__x)
|
|
|
|
#define be32_to_cpu(__x) ntohl(__x)
|
|
|
|
#else
|
|
|
|
#define le32_to_cpu(x) \
|
|
|
|
({ \
|
|
|
|
uint32_t __x = (x); \
|
|
|
|
((uint32_t)( \
|
|
|
|
(((uint32_t)(__x) & (uint32_t)0x000000ffUL) << 24) | \
|
|
|
|
(((uint32_t)(__x) & (uint32_t)0x0000ff00UL) << 8) | \
|
|
|
|
(((uint32_t)(__x) & (uint32_t)0x00ff0000UL) >> 8) | \
|
|
|
|
(((uint32_t)(__x) & (uint32_t)0xff000000UL) >> 24) )); \
|
|
|
|
})
|
|
|
|
#define le16_to_cpu(x) \
|
|
|
|
({ \
|
|
|
|
uint16_t __x = (x); \
|
|
|
|
((uint16_t)( \
|
|
|
|
(((uint16_t)(__x) & (uint16_t)0x00ff) << 8) | \
|
2014-02-19 13:28:17 -05:00
|
|
|
(((uint16_t)(__x) & (uint16_t)0xff00) >> 8))); \
|
2013-07-18 08:46:44 -04:00
|
|
|
})
|
|
|
|
#define be32_to_cpu(__x) __x
|
|
|
|
#define be16_to_cpu(__x) __x
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define cpu_to_le16 le16_to_cpu
|
|
|
|
#define cpu_to_le32 le32_to_cpu
|
|
|
|
#define cpu_to_be16 be16_to_cpu
|
|
|
|
#define cpu_to_be32 be32_to_cpu
|
|
|
|
|
2013-11-23 19:51:55 -05:00
|
|
|
/* To cheat the compiler */
|
|
|
|
#define UNUSED(expr) do { (void)(expr); } while (0)
|
|
|
|
|
2013-07-18 08:46:44 -04:00
|
|
|
/* To enumerate supported devices */
|
|
|
|
enum {
|
|
|
|
P_ANY = 0,
|
|
|
|
P_ES1,
|
|
|
|
P_ES2_20,
|
|
|
|
P_ES3_30,
|
2014-02-08 14:45:55 -05:00
|
|
|
P_ES40,
|
|
|
|
P_CP790,
|
2013-07-18 08:46:44 -04:00
|
|
|
P_CP_XXX,
|
|
|
|
P_CP10,
|
|
|
|
P_KODAK_6800,
|
2013-07-25 15:51:45 -04:00
|
|
|
P_KODAK_6850,
|
2013-07-18 08:46:44 -04:00
|
|
|
P_KODAK_1400_805,
|
2013-11-20 21:33:46 -05:00
|
|
|
P_KODAK_605,
|
2016-01-18 11:34:58 -05:00
|
|
|
P_KODAK_305,
|
2013-07-18 08:46:44 -04:00
|
|
|
P_SHINKO_S2145,
|
2014-11-15 08:32:47 -05:00
|
|
|
P_SHINKO_S1245,
|
2015-07-26 23:05:21 -04:00
|
|
|
P_SHINKO_S6245,
|
2015-12-17 21:50:47 -05:00
|
|
|
P_SHINKO_S6145,
|
|
|
|
P_SHINKO_S6145D,
|
2013-07-18 08:46:44 -04:00
|
|
|
P_SONY_UPDR150,
|
2014-04-25 11:39:15 -04:00
|
|
|
P_SONY_UPCR10,
|
2013-10-05 09:55:29 -04:00
|
|
|
P_MITSU_D70X,
|
2016-01-18 11:34:58 -05:00
|
|
|
P_MITSU_D80,
|
2016-01-24 16:59:56 -05:00
|
|
|
P_MITSU_K60,
|
2014-12-11 16:16:56 -05:00
|
|
|
P_MITSU_9550,
|
2016-01-24 16:59:56 -05:00
|
|
|
P_MITSU_9550S,
|
2013-12-03 22:21:44 -05:00
|
|
|
P_DNP_DS40,
|
|
|
|
P_DNP_DS80,
|
2015-08-28 19:30:16 -04:00
|
|
|
P_DNP_DS80D,
|
2014-10-06 21:56:55 -04:00
|
|
|
P_CITIZEN_CW01,
|
2015-06-13 17:22:02 -04:00
|
|
|
P_DNP_DSRX1,
|
|
|
|
P_DNP_DS620,
|
2016-01-18 11:34:58 -05:00
|
|
|
P_FUJI_ASK300,
|
2013-07-18 08:46:44 -04:00
|
|
|
P_END,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct device_id {
|
|
|
|
uint16_t vid;
|
|
|
|
uint16_t pid;
|
|
|
|
int type; /* P_** */
|
|
|
|
char *manuf_str;
|
|
|
|
};
|
|
|
|
|
2013-07-18 23:39:36 -04:00
|
|
|
/* Backend Functions */
|
|
|
|
struct dyesub_backend {
|
|
|
|
char *name;
|
|
|
|
char *version;
|
|
|
|
char *uri_prefix;
|
2014-02-10 20:10:36 -05:00
|
|
|
void (*cmdline_usage)(void);
|
2013-07-19 09:23:53 -04:00
|
|
|
void *(*init)(void);
|
|
|
|
void (*attach)(void *ctx, struct libusb_device_handle *dev,
|
|
|
|
uint8_t endp_up, uint8_t endp_down, uint8_t jobid);
|
2013-07-18 23:39:36 -04:00
|
|
|
void (*teardown)(void *ctx);
|
2014-02-10 20:10:36 -05:00
|
|
|
int (*cmdline_arg)(void *ctx, int argc, char **argv);
|
2013-07-18 23:39:36 -04:00
|
|
|
int (*read_parse)(void *ctx, int data_fd);
|
|
|
|
int (*main_loop)(void *ctx, int copies);
|
2013-07-24 20:54:14 -04:00
|
|
|
int (*query_serno)(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, char *buf, int buf_len);
|
2013-07-18 23:39:36 -04:00
|
|
|
struct device_id devices[];
|
|
|
|
};
|
|
|
|
|
2013-07-18 08:46:44 -04:00
|
|
|
/* Exported functions */
|
2014-01-12 17:26:29 -05:00
|
|
|
int send_data(struct libusb_device_handle *dev, uint8_t endp,
|
2013-07-18 08:46:44 -04:00
|
|
|
uint8_t *buf, int len);
|
2013-12-21 22:39:15 -05:00
|
|
|
int read_data(struct libusb_device_handle *dev, uint8_t endp,
|
|
|
|
uint8_t *buf, int buflen, int *readlen);
|
2015-08-12 22:56:29 -04:00
|
|
|
int lookup_printer_type(struct dyesub_backend *backend, uint16_t idVendor, uint16_t idProduct);
|
2013-07-18 08:46:44 -04:00
|
|
|
|
2015-08-13 21:09:56 -04:00
|
|
|
void print_license_blurb(void);
|
|
|
|
void print_help(char *argv0, struct dyesub_backend *backend);
|
|
|
|
|
2015-08-25 18:09:24 -04:00
|
|
|
uint16_t uint16_to_packed_bcd(uint16_t val);
|
|
|
|
|
2015-08-12 22:51:45 -04:00
|
|
|
/* Global data */
|
2013-07-18 08:46:44 -04:00
|
|
|
extern int terminate;
|
2013-12-21 22:15:18 -05:00
|
|
|
extern int dyesub_debug;
|
2015-08-12 20:56:51 -04:00
|
|
|
extern int fast_return;
|
2015-08-12 22:51:45 -04:00
|
|
|
extern int extra_vid;
|
|
|
|
extern int extra_pid;
|
|
|
|
extern int extra_type;
|
2015-08-13 21:09:56 -04:00
|
|
|
extern int copies;
|
|
|
|
extern char *use_serno;
|
2015-08-29 08:24:54 -04:00
|
|
|
extern int current_page;
|
2015-08-13 21:09:56 -04:00
|
|
|
|
|
|
|
#if defined(BACKEND)
|
|
|
|
extern struct dyesub_backend BACKEND;
|
|
|
|
#endif
|
2013-07-18 08:46:44 -04:00
|
|
|
|
2014-04-20 11:05:27 -04:00
|
|
|
/* CUPS compatibility */
|
|
|
|
#define CUPS_BACKEND_OK 0 /* Sucess */
|
|
|
|
#define CUPS_BACKEND_FAILED 1 /* Failed to print use CUPS policy */
|
|
|
|
#define CUPS_BACKEND_AUTH_REQUIRED 2 /* Auth required */
|
|
|
|
#define CUPS_BACKEND_HOLD 3 /* Hold this job only */
|
|
|
|
#define CUPS_BACKEND_STOP 4 /* Stop the entire queue */
|
|
|
|
#define CUPS_BACKEND_CANCEL 5 /* Cancel print job */
|
|
|
|
#define CUPS_BACKEND_RETRY 6 /* Retry later */
|
|
|
|
#define CUPS_BACKEND_RETRY_CURRENT 7 /* Retry immediately */
|
|
|
|
|
2015-08-13 21:09:56 -04:00
|
|
|
/* Argument processing */
|
2016-07-14 21:41:14 -04:00
|
|
|
#define GETOPT_LIST_GLOBAL "d:DfGh"
|
2015-08-13 21:09:56 -04:00
|
|
|
#define GETOPT_PROCESS_GLOBAL \
|
|
|
|
case 'd': \
|
|
|
|
copies = atoi(optarg); \
|
|
|
|
break; \
|
|
|
|
case 'D': \
|
|
|
|
dyesub_debug++; \
|
|
|
|
break; \
|
|
|
|
case 'f': \
|
|
|
|
fast_return++; \
|
|
|
|
break; \
|
|
|
|
case 'G': \
|
|
|
|
print_license_blurb(); \
|
|
|
|
exit(0); \
|
|
|
|
case 'h': \
|
|
|
|
print_help(argv[0], &BACKEND); \
|
2016-07-14 21:41:14 -04:00
|
|
|
exit(0);
|
2015-08-13 21:09:56 -04:00
|
|
|
|
2013-07-18 08:46:44 -04:00
|
|
|
#endif /* __BACKEND_COMMON_H */
|