2013-12-03 22:21:44 -05:00
|
|
|
/*
|
|
|
|
* DNP DS40/DS80 Photo Printer CUPS backend -- libusb-1.0 version
|
|
|
|
*
|
2016-01-24 09:44:19 -05:00
|
|
|
* (c) 2013-2016 Solomon Peachy <pizza@shaftnet.org>
|
2013-12-03 22:21:44 -05:00
|
|
|
*
|
2013-12-17 08:31:45 -05:00
|
|
|
* Development of this backend was sponsored by:
|
|
|
|
*
|
2014-06-03 20:43:31 -04:00
|
|
|
* Marco Di Antonio and [ ilgruppodigitale.com ]
|
|
|
|
* LiveLink Technology [ www.livelinktechnology.net ]
|
2016-02-08 17:53:28 -05:00
|
|
|
* A generous benefactor who wishes to remain anonymous
|
2013-12-17 08:31:45 -05:00
|
|
|
*
|
2013-12-03 22:21:44 -05:00
|
|
|
* The latest version of this program can be found at:
|
2013-12-10 08:54:07 -05:00
|
|
|
*
|
2013-12-03 22:21:44 -05:00
|
|
|
* http://git.shaftnet.org/cgit/selphy_print.git
|
2013-12-10 08:54:07 -05:00
|
|
|
*
|
2013-12-03 22:21:44 -05: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]
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-06-22 23:51:17 -04:00
|
|
|
//#define DNP_ONLY
|
2016-02-07 09:09:42 -05:00
|
|
|
|
|
|
|
/* Enables caching of last print type to speed up
|
|
|
|
job pipelining. Without this we always have to
|
|
|
|
assume the worst */
|
|
|
|
//#define STATE_DIR "/tmp"
|
2015-06-22 23:51:17 -04:00
|
|
|
|
2013-12-03 22:21:44 -05:00
|
|
|
#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>
|
|
|
|
|
2015-08-13 21:09:56 -04:00
|
|
|
#define BACKEND dnpds40_backend
|
|
|
|
|
2013-12-03 22:21:44 -05:00
|
|
|
#include "backend_common.h"
|
|
|
|
|
2015-06-19 13:47:43 -04:00
|
|
|
#define USB_VID_CITIZEN 0x1343
|
2014-02-04 19:24:20 -05:00
|
|
|
#define USB_PID_DNP_DS40 0x0003 // Also Citizen CX
|
2014-12-03 00:10:53 -05:00
|
|
|
#define USB_PID_DNP_DS80 0x0004 // Also Citizen CX-W, and Mitsubishi CP-3800DW
|
2014-02-04 19:24:20 -05:00
|
|
|
#define USB_PID_DNP_DSRX1 0x0005 // Also Citizen CY
|
2016-06-24 16:26:21 -04:00
|
|
|
#define USB_PID_CITIZEN_CW02 0x0006
|
|
|
|
#define USB_PID_DNP_DS80D 0x0007
|
|
|
|
#define USB_PID_DNP_DS620_OLD 0x0008
|
2013-12-03 22:21:44 -05:00
|
|
|
|
2015-06-19 13:47:43 -04:00
|
|
|
#define USB_VID_DNP 0x1452
|
|
|
|
#define USB_PID_DNP_DS620 0x8b01
|
|
|
|
|
2013-12-03 22:21:44 -05:00
|
|
|
/* Private data stucture */
|
|
|
|
struct dnpds40_ctx {
|
|
|
|
struct libusb_device_handle *dev;
|
|
|
|
uint8_t endp_up;
|
|
|
|
uint8_t endp_down;
|
|
|
|
|
2014-02-02 14:11:17 -05:00
|
|
|
int type;
|
2013-12-03 22:21:44 -05:00
|
|
|
|
2015-06-17 22:57:31 -04:00
|
|
|
char *serno;
|
|
|
|
char *version;
|
|
|
|
|
2013-12-17 00:36:06 -05:00
|
|
|
int buf_needed;
|
2015-06-08 08:06:18 -04:00
|
|
|
int last_matte;
|
2015-06-08 23:17:12 -04:00
|
|
|
|
2015-06-13 17:20:19 -04:00
|
|
|
int ver_major;
|
|
|
|
int ver_minor;
|
2015-06-22 23:32:48 -04:00
|
|
|
int media;
|
2015-08-28 20:37:28 -04:00
|
|
|
int duplex_media;
|
2015-06-13 17:20:19 -04:00
|
|
|
|
2015-06-08 08:06:18 -04:00
|
|
|
uint32_t multicut;
|
2015-09-03 01:22:56 -04:00
|
|
|
uint32_t last_multicut;
|
2016-01-21 19:16:52 -05:00
|
|
|
int fullcut;
|
2015-06-08 23:17:12 -04:00
|
|
|
int matte;
|
2015-06-13 17:20:19 -04:00
|
|
|
int cutter;
|
2015-06-22 23:32:48 -04:00
|
|
|
int can_rewind;
|
2015-06-13 17:20:19 -04:00
|
|
|
|
2016-07-19 17:12:00 -04:00
|
|
|
int mediaoffset;
|
2015-07-21 17:57:23 -04:00
|
|
|
int manual_copies;
|
2016-07-19 17:12:00 -04:00
|
|
|
int correct_count;
|
2015-06-13 17:20:19 -04:00
|
|
|
int supports_6x9;
|
|
|
|
int supports_2x6;
|
2015-06-13 22:34:54 -04:00
|
|
|
int supports_3x5x2;
|
2015-06-13 17:20:19 -04:00
|
|
|
int supports_matte;
|
2016-06-26 07:18:45 -04:00
|
|
|
int supports_luster;
|
2015-06-14 09:05:55 -04:00
|
|
|
int supports_fullcut;
|
|
|
|
int supports_rewind;
|
|
|
|
int supports_standby;
|
2015-06-22 18:46:26 -04:00
|
|
|
int supports_6x4_5;
|
2015-07-11 15:12:47 -04:00
|
|
|
int supports_mqty_default;
|
2015-08-06 09:54:49 -04:00
|
|
|
int supports_iserial;
|
2016-02-03 22:53:57 -05:00
|
|
|
int supports_6x6;
|
|
|
|
int supports_5x5;
|
2015-08-28 20:46:03 -04:00
|
|
|
int supports_counterp;
|
2016-01-21 19:16:52 -05:00
|
|
|
int supports_adv_fullcut;
|
2016-07-19 17:12:00 -04:00
|
|
|
int supports_mediaoffset;
|
2014-02-02 14:17:12 -05:00
|
|
|
|
2013-12-03 22:21:44 -05:00
|
|
|
uint8_t *databuf;
|
|
|
|
int datalen;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct dnpds40_cmd {
|
2013-12-16 20:15:48 -05:00
|
|
|
uint8_t esc; /* Fixed at ascii ESC, aka 0x1B */
|
|
|
|
uint8_t p; /* Fixed at ascii 'P' aka 0x50 */
|
2013-12-03 22:21:44 -05:00
|
|
|
uint8_t arg1[6];
|
|
|
|
uint8_t arg2[16];
|
|
|
|
uint8_t arg3[8]; /* Decimal value of arg4's length, or empty */
|
2013-12-08 07:14:27 -05:00
|
|
|
uint8_t arg4[0]; /* Extra payload if arg3 is non-empty
|
|
|
|
Doesn't have to be sent in the same URB */
|
2013-12-03 22:21:44 -05:00
|
|
|
|
2013-12-08 07:14:27 -05:00
|
|
|
/* All unused elements are set to 0x20 (ie ascii space) */
|
2013-12-03 22:21:44 -05:00
|
|
|
};
|
|
|
|
|
2016-02-03 22:48:54 -05:00
|
|
|
#define MULTICUT_5x3_5 1
|
|
|
|
#define MULTICUT_6x4 2
|
|
|
|
#define MULTICUT_5x7 3
|
|
|
|
#define MULTICUT_6x8 4
|
|
|
|
#define MULTICUT_6x9 5
|
|
|
|
#define MULTICUT_8x10 6
|
|
|
|
#define MULTICUT_8x12 7
|
|
|
|
#define MULTICUT_8x4 8
|
|
|
|
#define MULTICUT_8x5 9
|
|
|
|
#define MULTICUT_8x6 10
|
|
|
|
#define MULTICUT_8x8 11
|
|
|
|
#define MULTICUT_6x4X2 12
|
|
|
|
#define MULTICUT_8x4X2 13
|
|
|
|
#define MULTICUT_8x5X2 14
|
|
|
|
#define MULTICUT_8x6X2 15
|
|
|
|
#define MULTICUT_8x5_8x4 16
|
|
|
|
#define MULTICUT_8x6_8x4 17
|
|
|
|
#define MULTICUT_8x6_8x5 18
|
|
|
|
#define MULTICUT_8x8_8x4 19
|
|
|
|
#define MULTICUT_8x4X3 20
|
|
|
|
#define MULTICUT_8xA4LEN 21
|
|
|
|
#define MULTICUT_5x3_5X2 22
|
|
|
|
#define MULTICUT_6x6 27
|
|
|
|
#define MULTICUT_5x5 29
|
|
|
|
#define MULTICUT_6x4_5 30
|
|
|
|
#define MULTICUT_6x4_5X2 31
|
|
|
|
|
|
|
|
#define MULTICUT_S_SIMPLEX 100
|
|
|
|
#define MULTICUT_S_FRONT 200
|
|
|
|
#define MULTICUT_S_BACK 300
|
|
|
|
|
|
|
|
#define MULTICUT_S_8x10 6
|
|
|
|
#define MULTICUT_S_8x12 7
|
|
|
|
#define MULTICUT_S_8x4 8
|
|
|
|
#define MULTICUT_S_8x5 9
|
|
|
|
#define MULTICUT_S_8x6 10
|
|
|
|
#define MULTICUT_S_8x8 11
|
|
|
|
#define MULTICUT_S_8x4X2 13
|
|
|
|
#define MULTICUT_S_8x5X2 14
|
|
|
|
#define MULTICUT_S_8x6X2 15
|
|
|
|
#define MULTICUT_S_8x10_5 25
|
|
|
|
#define MULTICUT_S_8x10_75 26
|
|
|
|
#define MULTICUT_S_8x4X3 28 // different than roll type.
|
|
|
|
|
2013-12-03 22:21:44 -05:00
|
|
|
#define min(__x, __y) ((__x) < (__y)) ? __x : __y
|
|
|
|
|
|
|
|
static void dnpds40_build_cmd(struct dnpds40_cmd *cmd, char *arg1, char *arg2, uint32_t arg3_len)
|
|
|
|
{
|
|
|
|
memset(cmd, 0x20, sizeof(*cmd));
|
|
|
|
cmd->esc = 0x1b;
|
|
|
|
cmd->p = 0x50;
|
|
|
|
memcpy(cmd->arg1, arg1, min(strlen(arg1), sizeof(cmd->arg1)));
|
|
|
|
memcpy(cmd->arg2, arg2, min(strlen(arg2), sizeof(cmd->arg2)));
|
2013-12-16 20:15:48 -05:00
|
|
|
if (arg3_len) {
|
2014-02-11 13:41:15 -05:00
|
|
|
char buf[9];
|
2014-02-11 20:11:33 -05:00
|
|
|
snprintf(buf, sizeof(buf), "%08u", arg3_len);
|
2013-12-16 20:15:48 -05:00
|
|
|
memcpy(cmd->arg3, buf, 8);
|
|
|
|
}
|
2013-12-04 07:37:11 -05:00
|
|
|
|
2013-12-03 22:21:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dnpds40_cleanup_string(char *start, int len)
|
|
|
|
{
|
|
|
|
char *ptr = strchr(start, 0x0d);
|
|
|
|
|
2014-02-11 20:49:08 -05:00
|
|
|
if (ptr && (ptr - start < len)) {
|
2013-12-03 22:21:44 -05:00
|
|
|
*ptr = 0x00; /* If there is a <CR>, terminate there */
|
2014-02-11 20:49:08 -05:00
|
|
|
len = ptr - start;
|
|
|
|
} else {
|
|
|
|
start[--len] = 0x00; /* force null-termination */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Trim trailing spaces */
|
|
|
|
while (len && start[len-1] == ' ') {
|
|
|
|
start[--len] = 0;
|
|
|
|
}
|
2013-12-03 22:21:44 -05:00
|
|
|
}
|
|
|
|
|
2016-07-15 18:54:02 -04:00
|
|
|
static char *dnpds40_printer_type(int type)
|
|
|
|
{
|
|
|
|
switch(type) {
|
|
|
|
case P_DNP_DS40: return "DS40";
|
|
|
|
case P_DNP_DS80: return "DS80";
|
|
|
|
case P_DNP_DS80D: return "DS80DX";
|
|
|
|
case P_DNP_DSRX1: return "DSRX1";
|
|
|
|
case P_DNP_DS620: return "DS620";
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
|
2015-06-22 23:55:48 -04:00
|
|
|
static char *dnpds40_media_types(int media)
|
2013-12-03 22:21:44 -05:00
|
|
|
{
|
2015-06-22 23:55:48 -04:00
|
|
|
switch (media) {
|
2016-06-12 12:43:12 -04:00
|
|
|
case 100: return "UNKNOWN100"; // seen in driver dumps
|
|
|
|
case 110: return "UNKNOWN110"; // seen in driver dumps
|
2013-12-03 22:21:44 -05:00
|
|
|
case 200: return "5x3.5 (L)";
|
|
|
|
case 210: return "5x7 (2L)";
|
|
|
|
case 300: return "6x4 (PC)";
|
|
|
|
case 310: return "6x8 (A5)";
|
|
|
|
case 400: return "6x9 (A5W)";
|
|
|
|
case 500: return "8x10";
|
|
|
|
case 510: return "8x12";
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "Unknown type";
|
|
|
|
}
|
|
|
|
|
2015-08-28 20:37:28 -04:00
|
|
|
static char *dnpds80_duplex_media_types(int media)
|
|
|
|
{
|
|
|
|
switch (media) {
|
|
|
|
case 100: return "8x10.75";
|
|
|
|
case 200: return "8x12";
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "Unknown type";
|
|
|
|
}
|
|
|
|
|
2015-08-28 19:30:16 -04:00
|
|
|
static char *dnpds80_duplex_statuses(int status)
|
|
|
|
{
|
|
|
|
switch (status) {
|
|
|
|
case 5000: return "No Error";
|
|
|
|
|
|
|
|
case 5500: return "Duplex Unit Not Connected";
|
|
|
|
|
|
|
|
case 5017: return "Paper Jam: Supply Sensor On";
|
|
|
|
case 5018: return "Paper Jam: Supply Sensor Off";
|
|
|
|
case 5019: return "Paper Jam: Slot Sensor On";
|
|
|
|
case 5020: return "Paper Jam: Slot Sensor Off";
|
|
|
|
case 5021: return "Paper Jam: Pass Sensor On";
|
|
|
|
case 5022: return "Paper Jam: Pass Sensor Off";
|
|
|
|
case 5023: return "Paper Jam: Shell Sensor 1 On";
|
|
|
|
case 5024: return "Paper Jam: Shell Sensor 1 Off";
|
|
|
|
case 5025: return "Paper Jam: Shell Sensor 2 On";
|
|
|
|
case 5026: return "Paper Jam: Shell Sensor 2 Off";
|
|
|
|
case 5027: return "Paper Jam: Eject Sensor On";
|
|
|
|
case 5028: return "Paper Jam: Eject Sensor Off";
|
|
|
|
case 5029: return "Paper Jam: Slot FG Sensor";
|
|
|
|
case 5030: return "Paper Jam: Shell FG Sensor";
|
|
|
|
|
|
|
|
case 5033: return "Paper Supply Sensor Off";
|
|
|
|
case 5034: return "Printer Feed Slot Sensor Off";
|
|
|
|
case 5035: return "Pinch Pass Sensor Off";
|
|
|
|
case 5036: return "Shell Pass Sensor 1 Off";
|
|
|
|
case 5037: return "Shell Pass Sensor 2 Off";
|
|
|
|
case 5038: return "Eject Sensor Off";
|
|
|
|
|
|
|
|
case 5049: return "Capstan Drive Control Error";
|
|
|
|
case 5065: return "Shell Roller Error";
|
|
|
|
|
|
|
|
case 5081: return "Pinch Open Error";
|
|
|
|
case 5082: return "Pinch Close Error";
|
|
|
|
case 5083: return "Pinch Init Error";
|
|
|
|
case 5084: return "Pinch Position Error";
|
|
|
|
|
|
|
|
case 5097: return "Pass Guide Supply Error";
|
|
|
|
case 5098: return "Pass Guide Shell Error";
|
|
|
|
case 5099: return "Pass Guide Eject Error";
|
|
|
|
case 5100: return "Pass Guide Init Error";
|
|
|
|
case 5101: return "Pass Guide Position Error";
|
|
|
|
|
|
|
|
case 5113: return "Side Guide Home Error";
|
|
|
|
case 5114: return "Side Guide Position Error";
|
|
|
|
case 5115: return "Side Guide Init Error";
|
|
|
|
|
|
|
|
case 5129: return "Act Guide Home Error";
|
|
|
|
|
|
|
|
case 5145: return "Shell Rotate Home Error";
|
|
|
|
case 5146: return "Shell Rotate Rev Error";
|
|
|
|
|
|
|
|
case 5161: return "Paper Feed Lever Down Error";
|
|
|
|
case 5162: return "Paper Feed Lever Lock Error";
|
|
|
|
case 5163: return "Paper Feed Lever Up Error";
|
|
|
|
|
|
|
|
case 5177: return "Cutter Home Error";
|
|
|
|
case 5178: return "Cutter Away Error";
|
|
|
|
case 5179: return "Cutter Init Error";
|
|
|
|
case 5180: return "Cutter Position Error";
|
|
|
|
|
|
|
|
case 5193: return "Paper Tray Removed";
|
|
|
|
case 5209: return "Cover Opened";
|
|
|
|
case 5241: return "System Error";
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "Unkown Duplexer Error";
|
|
|
|
}
|
|
|
|
|
2015-06-23 19:25:23 -04:00
|
|
|
static char *dnpds40_statuses(int status)
|
2013-12-03 22:32:08 -05:00
|
|
|
{
|
2015-08-28 19:30:16 -04:00
|
|
|
if (status >= 5000 && status <= 5999)
|
|
|
|
return dnpds80_duplex_statuses(status);
|
|
|
|
|
2015-06-23 19:25:23 -04:00
|
|
|
switch (status) {
|
2013-12-03 22:32:08 -05:00
|
|
|
case 0: return "Idle";
|
|
|
|
case 1: return "Printing";
|
|
|
|
case 500: return "Cooling Print Head";
|
|
|
|
case 510: return "Cooling Paper Motor";
|
2015-06-17 20:55:29 -04:00
|
|
|
case 900: return "Standby Mode";
|
2013-12-03 22:32:08 -05:00
|
|
|
case 1000: return "Cover Open";
|
|
|
|
case 1010: return "No Scrap Box";
|
|
|
|
case 1100: return "Paper End";
|
|
|
|
case 1200: return "Ribbon End";
|
2014-02-02 14:11:17 -05:00
|
|
|
case 1300: return "Paper Jam";
|
|
|
|
case 1400: return "Ribbon Error";
|
2013-12-03 22:32:08 -05:00
|
|
|
case 1500: return "Paper Definition Error";
|
|
|
|
case 1600: return "Data Error";
|
|
|
|
case 2000: return "Head Voltage Error";
|
|
|
|
case 2100: return "Head Position Error";
|
|
|
|
case 2200: return "Power Supply Fan Error";
|
|
|
|
case 2300: return "Cutter Error";
|
|
|
|
case 2400: return "Pinch Roller Error";
|
|
|
|
case 2500: return "Abnormal Head Temperature";
|
|
|
|
case 2600: return "Abnormal Media Temperature";
|
|
|
|
case 2610: return "Abnormal Paper Motor Temperature";
|
|
|
|
case 2700: return "Ribbon Tension Error";
|
|
|
|
case 2800: return "RF-ID Module Error";
|
|
|
|
case 3000: return "System Error";
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-08-28 19:30:16 -04:00
|
|
|
return "Unknown Error";
|
2013-12-03 22:32:08 -05:00
|
|
|
}
|
|
|
|
|
2013-12-10 21:53:46 -05:00
|
|
|
static int dnpds40_do_cmd(struct dnpds40_ctx *ctx,
|
2013-12-11 07:50:31 -05:00
|
|
|
struct dnpds40_cmd *cmd,
|
|
|
|
uint8_t *data, int len)
|
2013-12-10 21:53:46 -05:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
(uint8_t*)cmd, sizeof(*cmd))))
|
|
|
|
return ret;
|
|
|
|
|
2013-12-11 07:50:31 -05:00
|
|
|
if (data && len)
|
2013-12-10 21:53:46 -05:00
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
data, len)))
|
|
|
|
return ret;
|
|
|
|
|
2014-04-20 11:51:06 -04:00
|
|
|
return CUPS_BACKEND_OK;
|
2013-12-10 21:53:46 -05:00
|
|
|
}
|
|
|
|
|
2013-12-04 10:31:41 -05:00
|
|
|
static uint8_t * dnpds40_resp_cmd(struct dnpds40_ctx *ctx,
|
|
|
|
struct dnpds40_cmd *cmd,
|
|
|
|
int *len)
|
|
|
|
{
|
|
|
|
char tmp[9];
|
|
|
|
uint8_t *respbuf;
|
|
|
|
|
|
|
|
int ret, i, num = 0;
|
2013-12-08 07:14:27 -05:00
|
|
|
|
|
|
|
memset(tmp, 0, sizeof(tmp));
|
|
|
|
|
2013-12-10 21:53:46 -05:00
|
|
|
if ((ret = dnpds40_do_cmd(ctx, cmd, NULL, 0)))
|
2013-12-04 10:31:41 -05:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Read in the response header */
|
2013-12-21 22:55:33 -05:00
|
|
|
ret = read_data(ctx->dev, ctx->endp_up,
|
|
|
|
(uint8_t*)tmp, 8, &num);
|
|
|
|
if (ret < 0)
|
2013-12-04 10:31:41 -05:00
|
|
|
return NULL;
|
|
|
|
|
2013-12-21 22:55:33 -05:00
|
|
|
if (num != 8) {
|
|
|
|
ERROR("Short read! (%d/%d)\n", num, 8);
|
|
|
|
return NULL;
|
2013-12-11 07:50:31 -05:00
|
|
|
}
|
2013-12-04 10:31:41 -05:00
|
|
|
|
2013-12-11 07:50:31 -05:00
|
|
|
i = atoi(tmp); /* Length of payload in bytes, possibly padded */
|
2013-12-04 10:31:41 -05:00
|
|
|
respbuf = malloc(i);
|
2015-06-23 20:32:41 -04:00
|
|
|
if (!respbuf) {
|
|
|
|
ERROR("Memory allocation failure (%d bytes)!\n", i);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-12-04 10:31:41 -05:00
|
|
|
|
|
|
|
/* Read in the actual response */
|
2013-12-21 22:55:33 -05:00
|
|
|
ret = read_data(ctx->dev, ctx->endp_up,
|
|
|
|
respbuf, i, &num);
|
|
|
|
if (ret < 0) {
|
|
|
|
free(respbuf);
|
|
|
|
return NULL;
|
2013-12-11 07:50:31 -05:00
|
|
|
}
|
|
|
|
|
2013-12-21 22:55:33 -05:00
|
|
|
if (num != i) {
|
|
|
|
ERROR("Short read! (%d/%d)\n", num, i);
|
2013-12-04 10:31:41 -05:00
|
|
|
free(respbuf);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*len = num;
|
|
|
|
return respbuf;
|
|
|
|
}
|
|
|
|
|
2013-12-16 20:15:48 -05:00
|
|
|
static int dnpds40_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, char *buf, int buf_len)
|
|
|
|
{
|
|
|
|
struct dnpds40_cmd cmd;
|
|
|
|
uint8_t *resp;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
struct dnpds40_ctx ctx = {
|
|
|
|
.dev = dev,
|
|
|
|
.endp_up = endp_up,
|
|
|
|
.endp_down = endp_down,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Get Serial Number */
|
|
|
|
dnpds40_build_cmd(&cmd, "INFO", "SERIAL_NUMBER", 0);
|
|
|
|
|
|
|
|
resp = dnpds40_resp_cmd(&ctx, &cmd, &len);
|
|
|
|
if (!resp)
|
2014-04-20 11:51:06 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-12-16 20:15:48 -05:00
|
|
|
|
|
|
|
dnpds40_cleanup_string((char*)resp, len);
|
|
|
|
|
|
|
|
strncpy(buf, (char*)resp, buf_len);
|
|
|
|
buf[buf_len-1] = 0;
|
|
|
|
|
|
|
|
free(resp);
|
|
|
|
|
2014-04-20 11:51:06 -04:00
|
|
|
return CUPS_BACKEND_OK;
|
2013-12-16 20:15:48 -05:00
|
|
|
}
|
|
|
|
|
2013-12-03 22:21:44 -05:00
|
|
|
static void *dnpds40_init(void)
|
|
|
|
{
|
|
|
|
struct dnpds40_ctx *ctx = malloc(sizeof(struct dnpds40_ctx));
|
2015-06-23 20:32:41 -04:00
|
|
|
if (!ctx) {
|
|
|
|
ERROR("Memory allocation failure (%d bytes)!\n", (int)sizeof(struct dnpds40_ctx));
|
2013-12-03 22:21:44 -05:00
|
|
|
return NULL;
|
2015-06-23 20:32:41 -04:00
|
|
|
}
|
2013-12-03 22:21:44 -05:00
|
|
|
memset(ctx, 0, sizeof(struct dnpds40_ctx));
|
|
|
|
|
|
|
|
ctx->type = P_ANY;
|
2016-02-07 09:09:42 -05:00
|
|
|
|
2013-12-03 22:21:44 -05:00
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2015-06-22 18:46:26 -04:00
|
|
|
#define FW_VER_CHECK(__major, __minor) \
|
|
|
|
((ctx->ver_major > (__major)) || \
|
|
|
|
(ctx->ver_major == (__major) && ctx->ver_minor >= (__minor)))
|
|
|
|
|
2013-12-10 08:54:07 -05:00
|
|
|
static void dnpds40_attach(void *vctx, struct libusb_device_handle *dev,
|
2015-06-11 08:40:31 -04:00
|
|
|
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
|
2013-12-03 22:21:44 -05:00
|
|
|
{
|
|
|
|
struct dnpds40_ctx *ctx = vctx;
|
|
|
|
struct libusb_device *device;
|
|
|
|
struct libusb_device_descriptor desc;
|
|
|
|
|
|
|
|
UNUSED(jobid);
|
|
|
|
|
2013-12-10 08:54:07 -05:00
|
|
|
ctx->dev = dev;
|
2013-12-03 22:21:44 -05:00
|
|
|
ctx->endp_up = endp_up;
|
|
|
|
ctx->endp_down = endp_down;
|
|
|
|
|
|
|
|
device = libusb_get_device(dev);
|
|
|
|
libusb_get_device_descriptor(device, &desc);
|
|
|
|
|
2015-08-12 22:56:29 -04:00
|
|
|
ctx->type = lookup_printer_type(&dnpds40_backend,
|
|
|
|
desc.idVendor, desc.idProduct);
|
|
|
|
|
2015-06-13 17:20:19 -04:00
|
|
|
{
|
2015-06-17 22:57:31 -04:00
|
|
|
/* Get Firmware Version */
|
2015-06-13 17:20:19 -04:00
|
|
|
struct dnpds40_cmd cmd;
|
|
|
|
uint8_t *resp;
|
|
|
|
int len = 0;
|
2015-06-22 23:32:48 -04:00
|
|
|
|
2015-06-13 17:20:19 -04:00
|
|
|
dnpds40_build_cmd(&cmd, "INFO", "FVER", 0);
|
|
|
|
|
|
|
|
resp = dnpds40_resp_cmd(ctx, &cmd, &len);
|
|
|
|
if (resp) {
|
|
|
|
char *ptr;
|
|
|
|
dnpds40_cleanup_string((char*)resp, len);
|
2015-06-20 16:32:29 -04:00
|
|
|
ctx->version = strdup((char*) resp);
|
2015-06-13 17:20:19 -04:00
|
|
|
|
|
|
|
/* Parse version */
|
2015-07-04 11:03:52 -04:00
|
|
|
/* ptr = */ strtok((char*)resp, " .");
|
2015-06-13 17:20:19 -04:00
|
|
|
ptr = strtok(NULL, ".");
|
|
|
|
ctx->ver_major = atoi(ptr);
|
|
|
|
ptr = strtok(NULL, ".");
|
|
|
|
ctx->ver_minor = atoi(ptr);
|
2015-06-20 16:32:29 -04:00
|
|
|
free(resp);
|
2015-06-17 22:57:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get Serial Number */
|
|
|
|
dnpds40_build_cmd(&cmd, "INFO", "SERIAL_NUMBER", 0);
|
|
|
|
|
|
|
|
resp = dnpds40_resp_cmd(ctx, &cmd, &len);
|
|
|
|
if (resp) {
|
|
|
|
dnpds40_cleanup_string((char*)resp, len);
|
|
|
|
ctx->serno = (char*) resp;
|
|
|
|
/* Do NOT free resp! */
|
2015-06-13 17:20:19 -04:00
|
|
|
}
|
2015-06-22 23:32:48 -04:00
|
|
|
|
|
|
|
/* Query Media Info */
|
|
|
|
dnpds40_build_cmd(&cmd, "INFO", "MEDIA", 0);
|
|
|
|
|
|
|
|
resp = dnpds40_resp_cmd(ctx, &cmd, &len);
|
|
|
|
if (resp) {
|
|
|
|
char tmp[4];
|
|
|
|
|
|
|
|
dnpds40_cleanup_string((char*)resp, len);
|
|
|
|
|
|
|
|
memcpy(tmp, resp + 4, 3);
|
|
|
|
tmp[3] = 0;
|
|
|
|
|
|
|
|
ctx->media = atoi(tmp);
|
|
|
|
|
|
|
|
/* Subtract out the "mark" type */
|
|
|
|
if (ctx->media & 1)
|
|
|
|
ctx->media--;
|
|
|
|
|
|
|
|
free(resp);
|
|
|
|
}
|
2015-06-13 17:20:19 -04:00
|
|
|
}
|
|
|
|
|
2015-08-28 20:37:28 -04:00
|
|
|
if (ctx->type == P_DNP_DS80D) {
|
|
|
|
struct dnpds40_cmd cmd;
|
|
|
|
uint8_t *resp;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
/* Query Duplex Media Info */
|
|
|
|
dnpds40_build_cmd(&cmd, "INFO", "CUT_PAPER", 0);
|
|
|
|
|
|
|
|
resp = dnpds40_resp_cmd(ctx, &cmd, &len);
|
|
|
|
if (resp) {
|
|
|
|
char tmp[5];
|
|
|
|
|
|
|
|
dnpds40_cleanup_string((char*)resp, len);
|
|
|
|
|
|
|
|
memcpy(tmp, resp + 4, 4);
|
|
|
|
tmp[4] = 0;
|
|
|
|
|
|
|
|
ctx->duplex_media = atoi(tmp);
|
|
|
|
|
|
|
|
/* Subtract out the paper status */
|
|
|
|
if (ctx->duplex_media & 3)
|
|
|
|
ctx->duplex_media -= (ctx->duplex_media & 3);
|
|
|
|
|
|
|
|
free(resp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-17 22:57:31 -04:00
|
|
|
#ifdef DNP_ONLY
|
|
|
|
/* Only allow DNP printers to work. Rebadged versions should not. */
|
|
|
|
|
|
|
|
{ /* Validate USB Vendor String is "Dai Nippon Printing" */
|
|
|
|
char buf[256];
|
|
|
|
buf[0] = 0;
|
|
|
|
libusb_get_string_descriptor_ascii(dev, desc->iManufacturer, (unsigned char*)buf, STR_LEN_MAX);
|
|
|
|
sanitize_string(buf);
|
|
|
|
if (strncmp(buf, "Dai", 3))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-06-13 17:20:19 -04:00
|
|
|
/* Per-printer options */
|
2015-08-12 22:56:29 -04:00
|
|
|
switch (ctx->type) {
|
|
|
|
case P_DNP_DS40:
|
2015-06-13 17:20:19 -04:00
|
|
|
ctx->supports_6x9 = 1;
|
2015-08-28 20:46:03 -04:00
|
|
|
if (FW_VER_CHECK(1,04))
|
|
|
|
ctx->supports_counterp = 1;
|
2015-06-22 18:46:26 -04:00
|
|
|
if (FW_VER_CHECK(1,30))
|
2015-06-13 17:20:19 -04:00
|
|
|
ctx->supports_matte = 1;
|
2015-06-22 18:46:26 -04:00
|
|
|
if (FW_VER_CHECK(1,40))
|
2015-06-13 17:20:19 -04:00
|
|
|
ctx->supports_2x6 = 1;
|
|
|
|
break;
|
2015-08-12 22:56:29 -04:00
|
|
|
case P_DNP_DS80:
|
2015-08-28 20:37:28 -04:00
|
|
|
case P_DNP_DS80D:
|
2015-08-28 20:46:03 -04:00
|
|
|
if (FW_VER_CHECK(1,02))
|
|
|
|
ctx->supports_counterp = 1;
|
2015-06-22 18:46:26 -04:00
|
|
|
if (FW_VER_CHECK(1,30))
|
2015-06-13 17:20:19 -04:00
|
|
|
ctx->supports_matte = 1;
|
|
|
|
break;
|
2015-08-12 22:56:29 -04:00
|
|
|
case P_DNP_DSRX1:
|
2015-08-28 20:46:03 -04:00
|
|
|
ctx->supports_counterp = 1;
|
2015-06-13 17:20:19 -04:00
|
|
|
ctx->supports_matte = 1;
|
2015-06-22 18:46:26 -04:00
|
|
|
if (FW_VER_CHECK(1,10))
|
2016-06-12 12:43:12 -04:00
|
|
|
ctx->supports_2x6 = ctx->supports_mqty_default = 1;
|
|
|
|
if (FW_VER_CHECK(2,00)) { /* AKA RX1HS */
|
|
|
|
ctx->supports_iserial = 1;
|
|
|
|
ctx->supports_mqty_default = 0; /* Yes, removed! */
|
|
|
|
// XXX luster?
|
|
|
|
}
|
2015-06-13 17:20:19 -04:00
|
|
|
break;
|
2015-08-12 22:56:29 -04:00
|
|
|
case P_DNP_DS620:
|
2016-07-19 17:12:00 -04:00
|
|
|
ctx->correct_count = 1;
|
2015-08-28 20:46:03 -04:00
|
|
|
ctx->supports_counterp = 1;
|
2015-06-13 17:20:19 -04:00
|
|
|
ctx->supports_matte = 1;
|
|
|
|
ctx->supports_2x6 = 1;
|
2015-06-14 09:05:55 -04:00
|
|
|
ctx->supports_fullcut = 1;
|
2015-07-11 15:12:47 -04:00
|
|
|
ctx->supports_mqty_default = 1;
|
2016-07-21 17:19:17 -04:00
|
|
|
if (strchr(ctx->version, 'A'))
|
|
|
|
ctx->supports_rewind = 0;
|
|
|
|
else
|
|
|
|
ctx->supports_rewind = 1;
|
2015-06-14 09:05:55 -04:00
|
|
|
ctx->supports_standby = 1;
|
2015-08-06 09:54:49 -04:00
|
|
|
ctx->supports_iserial = 1;
|
2016-02-03 22:53:57 -05:00
|
|
|
ctx->supports_6x6 = 1;
|
|
|
|
ctx->supports_5x5 = 1;
|
2015-06-22 18:46:26 -04:00
|
|
|
if (FW_VER_CHECK(0,30))
|
2015-06-13 22:34:54 -04:00
|
|
|
ctx->supports_3x5x2 = 1;
|
2015-06-22 18:46:26 -04:00
|
|
|
if (FW_VER_CHECK(1,10))
|
|
|
|
ctx->supports_6x9 = ctx->supports_6x4_5 = 1;
|
2016-01-21 19:16:52 -05:00
|
|
|
if (FW_VER_CHECK(1,20))
|
|
|
|
ctx->supports_adv_fullcut = 1;
|
2016-06-26 07:18:45 -04:00
|
|
|
if (FW_VER_CHECK(1,30))
|
|
|
|
ctx->supports_luster = 1;
|
2015-06-13 17:20:19 -04:00
|
|
|
break;
|
|
|
|
default:
|
2015-08-12 22:56:29 -04:00
|
|
|
ERROR("Unknown vid/pid %04x/%04x (%d)\n", desc.idVendor, desc.idProduct, ctx->type);
|
2015-06-13 17:20:19 -04:00
|
|
|
return;
|
|
|
|
}
|
2016-02-07 09:17:29 -05:00
|
|
|
|
|
|
|
ctx->last_matte = -1;
|
2016-02-08 17:53:28 -05:00
|
|
|
#ifdef STATE_DIR
|
2016-02-07 09:17:29 -05:00
|
|
|
/* Check our current job's lamination vs previous job. */
|
|
|
|
{
|
|
|
|
/* Load last matte status from file */
|
|
|
|
char buf[64];
|
|
|
|
FILE *f;
|
|
|
|
snprintf(buf, sizeof(buf), STATE_DIR "/%s-last", ctx->serno);
|
|
|
|
f = fopen(buf, "r");
|
|
|
|
if (f) {
|
|
|
|
fscanf(f, "%d", &ctx->last_matte);
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2016-07-19 17:12:00 -04:00
|
|
|
|
|
|
|
if (ctx->supports_mediaoffset) {
|
|
|
|
/* Get Media Offset */
|
|
|
|
struct dnpds40_cmd cmd;
|
|
|
|
uint8_t *resp;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
dnpds40_build_cmd(&cmd, "INFO", "MEDIA_OFFSET", 0);
|
|
|
|
resp = dnpds40_resp_cmd(ctx, &cmd, &len);
|
|
|
|
if (resp) {
|
|
|
|
ctx->mediaoffset = atoi((char*)resp+4);
|
|
|
|
free(resp);
|
|
|
|
}
|
|
|
|
} else if (!ctx->correct_count) {
|
|
|
|
ctx->mediaoffset = 50;
|
|
|
|
}
|
|
|
|
|
2013-12-03 22:21:44 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dnpds40_teardown(void *vctx) {
|
|
|
|
struct dnpds40_ctx *ctx = vctx;
|
|
|
|
|
|
|
|
if (!ctx)
|
|
|
|
return;
|
|
|
|
|
2015-09-03 01:22:56 -04:00
|
|
|
if (ctx->type == P_DNP_DS80D) {
|
|
|
|
struct dnpds40_cmd cmd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Check to see if last print was the front side
|
|
|
|
of a duplex job, and if so, cancel things so we're done */
|
|
|
|
if (ctx->last_multicut >= 200 &&
|
|
|
|
ctx->last_multicut < 300) {
|
|
|
|
dnpds40_build_cmd(&cmd, "CNTRL", "DUPLEX_CANCEL", 0);
|
|
|
|
if ((ret = dnpds40_do_cmd(ctx, &cmd, NULL, 0)))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-03 22:21:44 -05:00
|
|
|
if (ctx->databuf)
|
|
|
|
free(ctx->databuf);
|
2015-06-17 22:57:31 -04:00
|
|
|
if (ctx->serno)
|
|
|
|
free(ctx->serno);
|
|
|
|
if (ctx->version)
|
|
|
|
free(ctx->version);
|
2013-12-03 22:21:44 -05:00
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
|
2015-06-23 19:40:35 -04:00
|
|
|
#define MAX_PRINTJOB_LEN (((2560*7536+1024+54))*3+1024) /* Worst-case */
|
2013-12-03 22:21:44 -05:00
|
|
|
|
|
|
|
static int dnpds40_read_parse(void *vctx, int data_fd) {
|
|
|
|
struct dnpds40_ctx *ctx = vctx;
|
2014-02-11 13:41:15 -05:00
|
|
|
int run = 1;
|
2013-12-17 00:36:06 -05:00
|
|
|
char buf[9] = { 0 };
|
2013-12-03 22:21:44 -05:00
|
|
|
|
2015-08-28 20:37:28 -04:00
|
|
|
uint32_t dpi;
|
2014-02-02 14:11:17 -05:00
|
|
|
|
2013-12-03 22:21:44 -05:00
|
|
|
if (!ctx)
|
2014-04-20 11:51:06 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-12-03 22:21:44 -05:00
|
|
|
|
2014-01-21 20:34:00 -05:00
|
|
|
if (ctx->databuf) {
|
2014-01-19 19:23:24 -05:00
|
|
|
free(ctx->databuf);
|
2014-01-21 20:34:00 -05:00
|
|
|
ctx->databuf = NULL;
|
|
|
|
}
|
2014-01-19 19:23:24 -05:00
|
|
|
|
2014-02-02 14:11:17 -05:00
|
|
|
/* There's no way to figure out the total job length in advance, we
|
|
|
|
have to parse the stream until we get to the image plane data,
|
|
|
|
and even then the stream can contain arbitrary commands later.
|
|
|
|
|
|
|
|
So instead, we allocate a buffer of the maximum possible length,
|
|
|
|
then parse the incoming stream until we hit the START command at
|
|
|
|
the end of the job.
|
|
|
|
*/
|
|
|
|
|
2013-12-17 00:36:06 -05:00
|
|
|
ctx->datalen = 0;
|
2013-12-03 22:21:44 -05:00
|
|
|
ctx->databuf = malloc(MAX_PRINTJOB_LEN);
|
|
|
|
if (!ctx->databuf) {
|
|
|
|
ERROR("Memory allocation failure!\n");
|
2014-04-20 11:51:06 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2013-12-03 22:21:44 -05:00
|
|
|
}
|
|
|
|
|
2015-05-31 18:00:39 -04:00
|
|
|
/* Clear everything out */
|
|
|
|
dpi = 0;
|
2015-08-28 20:37:28 -04:00
|
|
|
ctx->matte = 0;
|
|
|
|
ctx->cutter = 0;
|
2015-07-21 17:57:23 -04:00
|
|
|
ctx->manual_copies = 0;
|
2015-06-22 23:32:48 -04:00
|
|
|
ctx->multicut = 0;
|
2016-01-21 19:16:52 -05:00
|
|
|
ctx->fullcut = 0;
|
2015-08-28 20:37:28 -04:00
|
|
|
ctx->can_rewind = 0;
|
2015-05-31 18:00:39 -04:00
|
|
|
|
2014-01-19 19:23:24 -05:00
|
|
|
while (run) {
|
2014-02-11 13:41:15 -05:00
|
|
|
int remain, i, j;
|
2014-02-02 14:11:17 -05:00
|
|
|
/* Read in command header */
|
2013-12-17 00:36:06 -05:00
|
|
|
i = read(data_fd, ctx->databuf + ctx->datalen,
|
|
|
|
sizeof(struct dnpds40_cmd));
|
|
|
|
if (i < 0)
|
|
|
|
return i;
|
|
|
|
if (i == 0)
|
|
|
|
break;
|
|
|
|
if (i < (int) sizeof(struct dnpds40_cmd))
|
2014-04-20 11:51:06 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2013-12-17 00:36:06 -05:00
|
|
|
|
|