2018-05-11 20:04:55 -04:00
|
|
|
/*
|
|
|
|
* Mitsubishi CP-D90DW Photo Printer CUPS backend
|
|
|
|
*
|
2020-02-27 18:45:26 -05:00
|
|
|
* (c) 2019-2020 Solomon Peachy <pizza@shaftnet.org>
|
2018-05-11 20:04:55 -04:00
|
|
|
*
|
|
|
|
* The latest version of this program can be found at:
|
|
|
|
*
|
|
|
|
* http://git.shaftnet.org/cgit/selphy_print.git
|
|
|
|
*
|
|
|
|
* 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
|
2020-01-17 16:50:56 -05:00
|
|
|
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
2018-05-11 20:04:55 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-3.0+
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define BACKEND mitsud90_backend
|
|
|
|
|
|
|
|
#include "backend_common.h"
|
2020-02-05 13:22:26 -05:00
|
|
|
#include "backend_mitsu.h"
|
2018-05-11 20:04:55 -04:00
|
|
|
|
|
|
|
#define USB_VID_MITSU 0x06D3
|
|
|
|
#define USB_PID_MITSU_D90 0x3B60
|
2020-02-28 15:00:39 -05:00
|
|
|
#define USB_PID_MITSU_CPM1 0x3B80
|
2018-05-11 20:04:55 -04:00
|
|
|
|
2020-02-15 20:10:01 -05:00
|
|
|
/* CPM1 stuff */
|
|
|
|
#define CPM1_LAMINATE_STRIDE 1852
|
2020-02-16 16:19:44 -05:00
|
|
|
#define CPM1_LAMINATE_FILE "M1_MAT02.raw"
|
|
|
|
#define CPM1_CPC_FNAME "CPM1_N1.csv"
|
|
|
|
#define CPM1_CPC_G1_FNAME "CPM1_G1.csv"
|
|
|
|
#define CPM1_CPC_G5_FNAME "CPM1_G5.csv"
|
|
|
|
#define CPM1_LUT_FNAME "CPM1_NL.lut"
|
2020-02-15 20:10:01 -05:00
|
|
|
|
2018-05-11 20:04:55 -04:00
|
|
|
/* Printer data structures */
|
2020-02-28 23:25:17 -05:00
|
|
|
#define COM_STATUS_TYPE_MODEL 0x01 // 10, null-terminated ASCII. 'CPD90D'
|
|
|
|
#define COM_STATUS_TYPE_x02 0x02 // 1, 0x5f ?
|
|
|
|
#define CM1_STATUS_TYPE_ISERIAL 0x03 // 24, full iSerial string in UTF16(LE)
|
|
|
|
#define CM1_STATUS_TYPE_SERIAL 0x04 // 6, serial number only (ascii)
|
|
|
|
#define CM1_STATUS_TYPE_FW_0a 0x0a // 8, 34 34 38 41 31 32 29 f4 (448A12)
|
|
|
|
#define COM_STATUS_TYPE_FW_0b 0x0b // 8, 34 31 34 42 31 31 a7 de (414D11)
|
|
|
|
#define COM_STATUS_TYPE_FW_MA 0x0c // 8, 34 31 35 41 38 31 86 bf (415A81) // MAIN FW
|
|
|
|
#define COM_STATUS_TYPE_FW_F 0x0d // 8, 34 31 36 41 35 31 dc 8a (416A51) // FPGA FW
|
|
|
|
#define COM_STATUS_TYPE_FW_T 0x0e // 8, 34 31 37 45 31 31 e7 e6 (417E11) // TABLE FW
|
|
|
|
#define COM_STATUS_TYPE_FW_0f 0x0f // 8, 34 31 38 41 31 32 6c 64 (418A12)
|
|
|
|
#define COM_STATUS_TYPE_FW_11 0x11 // 8, 34 32 31 51 31 31 74 f2 (421Q11)
|
|
|
|
#define COM_STATUS_TYPE_FW_ME 0x13 // 8, 34 31 39 45 31 31 15 bf (419E11) // MECHA FW
|
|
|
|
|
|
|
|
#define COM_STATUS_TYPE_ERROR 0x16 // 11 (see below)
|
|
|
|
#define COM_STATUS_TYPE_MECHA 0x17 // 2 (see below)
|
|
|
|
#define COM_STATUS_TYPE_x1e 0x1e // 1, power state or time? (x00)
|
|
|
|
#define COM_STATUS_TYPE_TEMP 0x1f // 1 (see below)
|
|
|
|
#define COM_STATUS_TYPE_x22 0x22 // 2, all 0 (counter?)
|
|
|
|
#define COM_STATUS_TYPE_x28 0x28 // 2, next jobid? (starts 00 01 at power cycle, increments by 1 for each print)
|
2020-03-01 12:43:37 -05:00
|
|
|
#define COM_STATUS_TYPE_x29 0x29 // 8, e0 07 00 00 21 e6 b3 22 or e0 07 80 96 3f 28 12 2d
|
2020-02-28 23:25:17 -05:00
|
|
|
#define COM_STATUS_TYPE_MEDIA 0x2a // 10 (see below)
|
|
|
|
#define COM_STATUS_TYPE_x2b 0x2b // 2, all 0 (counter?)
|
2020-03-01 12:43:37 -05:00
|
|
|
#define COM_STATUS_TYPE_x2c 0x2c // 2, 00 56 (counter?) or 00 28
|
2020-02-28 23:25:17 -05:00
|
|
|
#define COM_STATUS_TYPE_x65 0x65 // 50, see below
|
|
|
|
#define D90_STATUS_TYPE_ISEREN 0x82 // 1, 80 (iserial disabled)
|
|
|
|
#define COM_STATUS_TYPE_x83 0x83 // 1, 00
|
|
|
|
#define D90_STATUS_TYPE_x84 0x84 // 1, 00
|
2018-05-22 13:21:09 -04:00
|
|
|
|
|
|
|
//#define D90_STATUS_TYPE_x85 0x85 // 2, 00 ?? BE, wait time?
|
|
|
|
// combined total of 5.
|
|
|
|
|
2018-05-23 14:21:29 -04:00
|
|
|
struct mitsud90_fw_resp_single {
|
2018-05-22 13:21:09 -04:00
|
|
|
uint8_t version[6];
|
|
|
|
uint16_t csum;
|
2018-09-17 21:32:15 -04:00
|
|
|
} __attribute__((packed));
|
2018-05-22 13:21:09 -04:00
|
|
|
|
2018-05-11 20:04:55 -04:00
|
|
|
struct mitsud90_media_resp {
|
|
|
|
uint8_t hdr[4]; /* e4 47 44 30 */
|
2018-05-17 15:08:28 -04:00
|
|
|
struct {
|
|
|
|
uint8_t brand;
|
|
|
|
uint8_t type;
|
|
|
|
uint8_t unk_a[2];
|
|
|
|
uint16_t capacity; /* BE */
|
|
|
|
uint16_t remain; /* BE */
|
|
|
|
uint8_t unk_b[2];
|
2020-02-28 23:25:17 -05:00
|
|
|
} __attribute__((packed)) media; /* COM_STATUS_TYPE_MEDIA */
|
2018-05-17 15:08:28 -04:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2018-05-17 08:06:12 -04:00
|
|
|
struct mitsud90_status_resp {
|
2018-05-11 20:04:55 -04:00
|
|
|
uint8_t hdr[4]; /* e4 47 44 30 */
|
2020-02-28 23:25:17 -05:00
|
|
|
/* COM_STATUS_TYPE_ERROR */
|
2018-05-22 13:21:09 -04:00
|
|
|
uint8_t code[2]; /* 00 is ok, nonzero is error */
|
|
|
|
uint8_t unk[9];
|
2020-02-28 23:25:17 -05:00
|
|
|
/* COM_STATUS_TYPE_MECHA */
|
2018-05-22 13:21:09 -04:00
|
|
|
uint8_t mecha[2];
|
2020-02-28 23:25:17 -05:00
|
|
|
/* COM_STATUS_TYPE_TEMP */
|
2018-05-22 13:21:09 -04:00
|
|
|
uint8_t temp;
|
2018-05-17 08:06:12 -04:00
|
|
|
} __attribute__((packed));
|
2018-05-11 20:04:55 -04:00
|
|
|
|
2018-05-23 14:21:29 -04:00
|
|
|
struct mitsud90_info_resp {
|
|
|
|
uint8_t hdr[4]; /* e4 47 44 30 */
|
|
|
|
uint8_t model[10];
|
|
|
|
uint8_t x02;
|
|
|
|
struct mitsud90_fw_resp_single fw_vers[7];
|
|
|
|
uint8_t x1e;
|
|
|
|
uint8_t x22[2];
|
2019-12-23 21:58:05 -05:00
|
|
|
uint16_t x28;
|
2018-05-23 14:21:29 -04:00
|
|
|
uint8_t x29[8];
|
|
|
|
uint8_t x2b[2];
|
|
|
|
uint8_t x2c[2];
|
|
|
|
uint8_t x65[50];
|
2019-10-18 19:38:25 -04:00
|
|
|
uint8_t iserial;
|
2018-05-23 14:21:29 -04:00
|
|
|
uint8_t x83;
|
|
|
|
uint8_t x84;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2020-02-28 23:25:17 -05:00
|
|
|
struct mitsum1_info_resp {
|
|
|
|
uint8_t hdr[4]; /* e4 47 44 30 */
|
|
|
|
uint8_t model[10];
|
|
|
|
uint8_t x02;
|
|
|
|
struct mitsud90_fw_resp_single fw_vers[8];
|
|
|
|
uint8_t x1e;
|
|
|
|
uint8_t x22[2];
|
|
|
|
uint16_t x28;
|
|
|
|
uint8_t x29[8];
|
|
|
|
uint8_t x2b[2];
|
|
|
|
uint8_t x2c[2];
|
|
|
|
uint8_t x65[50];
|
|
|
|
uint8_t x83;
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
|
2018-05-17 15:08:28 -04:00
|
|
|
#define D90_MECHA_STATUS_IDLE 0x00
|
|
|
|
#define D90_MECHA_STATUS_PRINTING 0x50
|
|
|
|
#define D90_MECHA_STATUS_INIT 0x80
|
|
|
|
#define D90_MECHA_STATUS_INIT_FEEDCUT 0x10
|
|
|
|
|
2018-05-23 13:33:43 -04:00
|
|
|
#define D90_MECHA_STATUS_PRINT_FEEDING 0x10 // feeding ?
|
|
|
|
#define D90_MECHA_STATUS_PRINT_PRE_Y 0x21 // pre Y ?
|
|
|
|
#define D90_MECHA_STATUS_PRINT_Y 0x22 // Y ?
|
|
|
|
#define D90_MECHA_STATUS_PRINT_PRE_M 0x23 // pre M ?
|
|
|
|
#define D90_MECHA_STATUS_PRINT_M 0x24 // M ?
|
|
|
|
#define D90_MECHA_STATUS_PRINT_PRE_C 0x25 // pre C ? guess!
|
|
|
|
#define D90_MECHA_STATUS_PRINT_C 0x26 // C ?
|
|
|
|
#define D90_MECHA_STATUS_PRINT_PRE_OC 0x27 // pre OC ? guess!
|
|
|
|
#define D90_MECHA_STATUS_PRINT_OC 0x28 // O C?
|
|
|
|
#define D90_MECHA_STATUS_PRINTING_x2f 0x2f // ??
|
|
|
|
#define D90_MECHA_STATUS_PRINTING_x38 0x38 // eject ?
|
2018-05-17 15:08:28 -04:00
|
|
|
|
|
|
|
#define D90_ERROR_STATUS_OK 0x00
|
|
|
|
#define D90_ERROR_STATUS_OK_WARMING 0x40
|
|
|
|
#define D90_ERROR_STATUS_OK_COOLING 0x80
|
2018-05-22 13:21:09 -04:00
|
|
|
#define D90_ERROR_STATUS_RIBBON 0x21
|
|
|
|
#define D90_ERROR_STATUS_PAPER 0x22
|
|
|
|
#define D90_ERROR_STATUS_PAP_RIB 0x23
|
|
|
|
#define D90_ERROR_STATUS_OPEN 0x29
|
2018-05-17 15:08:28 -04:00
|
|
|
|
2018-05-16 21:57:29 -04:00
|
|
|
struct mitsud90_job_query {
|
|
|
|
uint8_t hdr[4]; /* 1b 47 44 31 */
|
|
|
|
uint16_t jobid; /* BE */
|
2020-02-25 20:58:59 -05:00
|
|
|
} __attribute__((packed));
|
2018-05-16 21:57:29 -04:00
|
|
|
|
|
|
|
struct mitsud90_job_resp {
|
|
|
|
uint8_t hdr[4]; /* e4 47 44 31 */
|
|
|
|
uint8_t unk1;
|
|
|
|
uint8_t unk2;
|
|
|
|
uint16_t unk3;
|
2020-02-25 20:58:59 -05:00
|
|
|
} __attribute__((packed));
|
2018-05-16 21:57:29 -04:00
|
|
|
|
2018-05-11 20:04:55 -04:00
|
|
|
struct mitsud90_job_hdr {
|
|
|
|
uint8_t hdr[6]; /* 1b 53 50 30 00 33 */
|
|
|
|
uint16_t cols; /* BE */
|
|
|
|
uint16_t rows; /* BE */
|
2020-02-11 21:09:45 -05:00
|
|
|
uint8_t waittime; /* 0-100 */
|
|
|
|
uint8_t unk[3]; /* 00 00 01 */ // XXX 00 01 might be the jobid?
|
2019-10-18 09:50:21 -04:00
|
|
|
uint8_t margincut; /* 1 for enabled, 0 for disabled */
|
2020-03-05 23:36:51 -05:00
|
|
|
uint8_t numcuts; /* # of cuts (0-3) but 0-8 legal */
|
2020-03-05 23:05:55 -05:00
|
|
|
/*@0x10*/
|
|
|
|
struct {
|
|
|
|
uint16_t position; // @ center?
|
2020-03-06 08:55:52 -05:00
|
|
|
uint8_t margincut; /* 0 for double cut, 1 for single */
|
2020-03-05 23:05:55 -05:00
|
|
|
uint8_t zeropad;
|
2020-03-06 08:55:52 -05:00
|
|
|
} cutlist[8] __attribute__((packed)); /* 3 is current legal max */
|
2020-02-11 21:09:45 -05:00
|
|
|
/*@x30*/uint8_t overcoat; /* 0 glossy, matte is 2 (D90) or 3 (M1) */
|
2020-03-04 20:04:02 -05:00
|
|
|
uint8_t quality; /* 0 is automatic, 5 is "fast" on M1 */
|
2020-02-11 21:09:45 -05:00
|
|
|
uint8_t colorcorr; /* Always 1 on M1 */
|
|
|
|
uint8_t sharp_h; /* Always 0 on M1 */
|
|
|
|
uint8_t sharp_v; /* Always 0 on M1 */
|
2020-03-03 11:29:52 -05:00
|
|
|
uint8_t zero_b[4]; /* 0 on D90, on M1, zero_b[3] is the not-raw flag */
|
2020-02-25 21:44:27 -05:00
|
|
|
struct {
|
|
|
|
uint16_t pano_on; /* 0x0001 when pano is on, or always 0x0002 on M1 */
|
|
|
|
uint8_t pano_tot; /* 2 or 3 */
|
|
|
|
uint8_t pano_pg; /* 1, 2, 3 */
|
|
|
|
uint16_t pano_rows; /* always 0x097c (BE), ie 2428 ie 8" print */
|
|
|
|
uint16_t pano_rows2; /* Always 0x30 less than pano_rows */
|
|
|
|
uint16_t pano_zero; /* 0x0000 */
|
|
|
|
uint16_t pano_overlap; /* always 0x0258, ie 600 or 2 inches */
|
|
|
|
uint8_t pano_unk[4]; /* 00 0c 00 06 */
|
|
|
|
} pano __attribute__((packed));
|
2020-03-01 13:04:46 -05:00
|
|
|
uint8_t zero_c[7];
|
2020-02-26 15:59:44 -05:00
|
|
|
/*@x50*/uint8_t unk_m1; /* 00 on d90 & m1 Linux, 01 on m1 (windows) */
|
2020-02-25 21:44:27 -05:00
|
|
|
uint8_t rgbrate; /* M1 only, see below */
|
2020-02-15 20:10:01 -05:00
|
|
|
uint8_t oprate; /* M1 only, see below */
|
2020-02-25 20:58:59 -05:00
|
|
|
uint8_t zero_fill[429];
|
2018-05-14 15:20:33 -04:00
|
|
|
} __attribute__((packed));
|
2018-05-11 20:04:55 -04:00
|
|
|
|
|
|
|
struct mitsud90_plane_hdr {
|
2019-10-18 19:38:25 -04:00
|
|
|
uint8_t hdr[6]; /* 1b 5a 54 01 00 09 */
|
2020-02-11 21:09:45 -05:00
|
|
|
uint16_t origin_cols; /* Leave at 0 */
|
|
|
|
uint16_t origin_rows; /* Leave at 0 */
|
2018-05-11 20:04:55 -04:00
|
|
|
uint16_t cols; /* BE */
|
|
|
|
uint16_t rows; /* BE */
|
2020-02-11 21:09:45 -05:00
|
|
|
uint8_t zero_a[6];
|
|
|
|
uint16_t lamcols; /* BE (M1 only, OC=3) should be cols+origin_cols */
|
|
|
|
uint16_t lamrows; /* BE (M1 only, OC=3) should be rows+origin_rows+12 */
|
2020-02-29 15:40:01 -05:00
|
|
|
uint8_t zero_b[8];
|
2020-02-25 21:44:27 -05:00
|
|
|
uint8_t unk_m1[8]; /* 07 e4 02 19 xx xx xx 00 always incrementing. timestamp? Only seen from win-generated jobs? */
|
2020-02-25 20:58:59 -05:00
|
|
|
uint8_t zero_fill[472];
|
|
|
|
} __attribute__((packed));
|
2018-05-11 20:04:55 -04:00
|
|
|
|
|
|
|
struct mitsud90_job_footer {
|
|
|
|
uint8_t hdr[4]; /* 1b 42 51 31 */
|
2020-03-03 11:29:52 -05:00
|
|
|
uint16_t seconds; /* BE, 0x0005 by default (windows), 0x00ff means don't wait */
|
2020-02-25 20:58:59 -05:00
|
|
|
} __attribute__((packed));
|
2018-05-11 20:04:55 -04:00
|
|
|
|
|
|
|
struct mitsud90_memcheck {
|
|
|
|
uint8_t hdr[4]; /* 1b 47 44 33 */
|
|
|
|
uint8_t unk[2]; /* 00 33 */
|
|
|
|
uint16_t cols; /* BE */
|
|
|
|
uint16_t rows; /* BE */
|
|
|
|
uint8_t unk_b[4]; /* 64 00 00 01 */
|
|
|
|
uint8_t zero_fill[498];
|
2020-02-25 20:58:59 -05:00
|
|
|
} __attribute__((packed));
|
2018-05-11 20:04:55 -04:00
|
|
|
|
|
|
|
struct mitsud90_memcheck_resp {
|
|
|
|
uint8_t hdr[4]; /* e4 47 44 43 */
|
|
|
|
uint8_t size_bad; /* 0x00 is ok */
|
|
|
|
uint8_t mem_bad; /* 0x00 is ok */
|
2020-02-25 20:58:59 -05:00
|
|
|
} __attribute__((packed));
|
2018-05-11 20:04:55 -04:00
|
|
|
|
2020-03-24 18:22:39 -04:00
|
|
|
static const char *mitsud90_mecha_statuses(const uint8_t *code)
|
2018-05-17 15:08:28 -04:00
|
|
|
{
|
|
|
|
switch (code[0]) {
|
|
|
|
case D90_MECHA_STATUS_IDLE:
|
|
|
|
return "Idle";
|
|
|
|
case D90_MECHA_STATUS_PRINTING:
|
2018-05-23 13:33:43 -04:00
|
|
|
switch (code[1]) {
|
|
|
|
case D90_MECHA_STATUS_PRINT_FEEDING:
|
|
|
|
return "Feeding Media";
|
|
|
|
case D90_MECHA_STATUS_PRINT_PRE_Y:
|
|
|
|
case D90_MECHA_STATUS_PRINT_Y:
|
|
|
|
return "Printing Yellow";
|
|
|
|
case D90_MECHA_STATUS_PRINT_PRE_M:
|
|
|
|
case D90_MECHA_STATUS_PRINT_M:
|
|
|
|
return "Printing Magenta";
|
|
|
|
case D90_MECHA_STATUS_PRINT_PRE_C:
|
|
|
|
case D90_MECHA_STATUS_PRINT_C:
|
|
|
|
return "Printing Cyan";
|
|
|
|
case D90_MECHA_STATUS_PRINT_PRE_OC:
|
|
|
|
case D90_MECHA_STATUS_PRINT_OC:
|
|
|
|
return "Applying Overcoat";
|
|
|
|
case D90_MECHA_STATUS_PRINTING_x2f:
|
|
|
|
case D90_MECHA_STATUS_PRINTING_x38:
|
|
|
|
return "Ejecting Media?";
|
|
|
|
default:
|
|
|
|
return "Printing (Unknown)";
|
|
|
|
}
|
2018-05-17 15:08:28 -04:00
|
|
|
case D90_MECHA_STATUS_INIT:
|
|
|
|
if (code[1] == D90_MECHA_STATUS_INIT_FEEDCUT)
|
|
|
|
return "Feed & Cut paper";
|
|
|
|
else
|
|
|
|
return "Initializing";
|
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-24 18:22:39 -04:00
|
|
|
static const char *mitsud90_error_codes(const uint8_t *code)
|
2018-05-16 08:03:16 -04:00
|
|
|
{
|
2018-05-17 08:06:12 -04:00
|
|
|
switch(code[0]) {
|
2018-05-17 15:08:28 -04:00
|
|
|
case D90_ERROR_STATUS_OK:
|
|
|
|
if (code[1] & D90_ERROR_STATUS_OK_WARMING)
|
2018-05-16 13:07:17 -04:00
|
|
|
return "Heating";
|
2018-05-17 15:08:28 -04:00
|
|
|
else if (code[1] & D90_ERROR_STATUS_OK_COOLING)
|
2018-05-16 13:07:17 -04:00
|
|
|
return "Cooling Down";
|
|
|
|
else
|
|
|
|
return "Idle";
|
2018-05-22 13:21:09 -04:00
|
|
|
case D90_ERROR_STATUS_RIBBON:
|
2018-05-17 08:06:12 -04:00
|
|
|
switch (code[1]) {
|
2018-05-16 13:07:17 -04:00
|
|
|
case 0x00:
|
|
|
|
return "Ribbon exhausted";
|
|
|
|
case 0x10:
|
|
|
|
return "Insufficient remaining ribbon";
|
|
|
|
case 0x20:
|
|
|
|
return "Ribbon Cue Timeout";
|
|
|
|
case 0x30:
|
|
|
|
return "Cannot Cue Ribbon";
|
|
|
|
case 0x90:
|
|
|
|
return "No ribbon";
|
|
|
|
default:
|
|
|
|
return "Unknown Ribbon Error";
|
|
|
|
}
|
2018-05-22 13:21:09 -04:00
|
|
|
case D90_ERROR_STATUS_PAPER:
|
2018-05-17 08:06:12 -04:00
|
|
|
switch (code[1]) {
|
2018-05-16 13:07:17 -04:00
|
|
|
case 0x00:
|
|
|
|
return "No paper";
|
|
|
|
case 0x02:
|
|
|
|
return "Paper exhausted";
|
|
|
|
default:
|
|
|
|
return "Unknown Paper Error";
|
|
|
|
}
|
2018-05-22 13:21:09 -04:00
|
|
|
case D90_ERROR_STATUS_PAP_RIB:
|
2018-05-17 08:06:12 -04:00
|
|
|
switch (code[1]) {
|
2018-05-16 13:07:17 -04:00
|
|
|
case 0x00:
|
|
|
|
return "Ribbon/Paper mismatch";
|
|
|
|
case 0x90:
|
|
|
|
return "Ribbon/Job mismatch";
|
|
|
|
default:
|
|
|
|
return "Unknown ribbon match error";
|
|
|
|
}
|
|
|
|
case 0x26:
|
|
|
|
return "Illegal Ribbon";
|
2018-05-16 08:03:16 -04:00
|
|
|
case 0x28:
|
|
|
|
return "Cut Bin Missing";
|
2018-05-22 13:21:09 -04:00
|
|
|
case D90_ERROR_STATUS_OPEN:
|
2018-05-17 08:06:12 -04:00
|
|
|
switch (code[1]) {
|
2018-05-16 13:07:17 -04:00
|
|
|
case 0x00:
|
|
|
|
return "Printer Open during Stop";
|
|
|
|
case 0x10:
|
|
|
|
return "Printer Open during Initialization";
|
|
|
|
case 0x90:
|
|
|
|
return "Printer Open during Printing";
|
|
|
|
default:
|
|
|
|
return "Unknown Door error";
|
|
|
|
}
|
|
|
|
case 0x2f:
|
|
|
|
return "Printer turned off during printing";
|
|
|
|
case 0x31:
|
|
|
|
return "Ink feed stop";
|
|
|
|
case 0x32:
|
|
|
|
return "Ink Skip 1 timeout";
|
|
|
|
case 0x33:
|
|
|
|
return "Ink Skip 2 timeout";
|
|
|
|
case 0x34:
|
|
|
|
return "Ink Sticking";
|
|
|
|
case 0x35:
|
|
|
|
return "Ink return stop";
|
|
|
|
case 0x36:
|
|
|
|
return "Ink Rewind timeout";
|
|
|
|
case 0x37:
|
|
|
|
return "Winding sensing error";
|
|
|
|
case 0x40:
|
|
|
|
case 0x41:
|
|
|
|
case 0x42:
|
|
|
|
case 0x43:
|
|
|
|
case 0x44:
|
|
|
|
return "Paper Jam";
|
|
|
|
case 0x60:
|
2018-05-17 08:06:12 -04:00
|
|
|
if (code[1] == 0x20)
|
2018-05-16 13:07:17 -04:00
|
|
|
return "Preheat error";
|
2018-05-17 08:06:12 -04:00
|
|
|
else if (code[1] == 0x04)
|
2018-05-16 13:07:17 -04:00
|
|
|
return "Humidity sensor error";
|
2018-05-17 08:06:12 -04:00
|
|
|
else if (code[1] & 0x1f)
|
2018-05-16 13:07:17 -04:00
|
|
|
return "Thermistor error";
|
|
|
|
else
|
|
|
|
return "Unknown error";
|
|
|
|
case 0x61:
|
2018-05-17 08:06:12 -04:00
|
|
|
if (code[1] == 0x00)
|
2018-05-16 13:07:17 -04:00
|
|
|
return "Color Sensor Error";
|
2018-05-17 08:06:12 -04:00
|
|
|
else if (code[1] & 0x10)
|
2018-05-16 13:07:17 -04:00
|
|
|
return "Matte OP Error";
|
|
|
|
else
|
|
|
|
return "Unknown error";
|
|
|
|
case 0x62:
|
|
|
|
return "Data Transfer error";
|
|
|
|
case 0x63:
|
|
|
|
return "EEPROM error";
|
|
|
|
case 0x64:
|
|
|
|
return "Flash access error";
|
|
|
|
case 0x65:
|
|
|
|
return "FPGA configuration error";
|
|
|
|
case 0x66:
|
|
|
|
return "Power voltage Error";
|
|
|
|
case 0x67:
|
|
|
|
return "RFID access error";
|
|
|
|
case 0x68:
|
2018-05-17 08:06:12 -04:00
|
|
|
if (code[1] == 0x00)
|
2018-05-16 13:07:17 -04:00
|
|
|
return "Fan Lock Error";
|
2018-05-17 08:06:12 -04:00
|
|
|
else if (code[1] == 0x90)
|
2018-05-16 13:07:17 -04:00
|
|
|
return "MDA Error";
|
|
|
|
else
|
|
|
|
return "Unknown error";
|
|
|
|
case 0x69:
|
2018-05-17 08:06:12 -04:00
|
|
|
if (code[1] == 0x10)
|
2018-05-16 13:07:17 -04:00
|
|
|
return "DDR Error";
|
2018-05-17 08:06:12 -04:00
|
|
|
else if (code[1] == 0x00)
|
2018-05-16 13:07:17 -04:00
|
|
|
return "Firmware Error";
|
|
|
|
else
|
|
|
|
return "Unknown error";
|
|
|
|
case 0x70:
|
|
|
|
case 0x71:
|
|
|
|
case 0x73:
|
|
|
|
case 0x75:
|
|
|
|
return "Mechanical Error (check ribbon and power cycle)";
|
|
|
|
case 0x82:
|
|
|
|
return "USB Timeout";
|
|
|
|
case 0x83:
|
|
|
|
return "Illegal paper size";
|
|
|
|
case 0x84:
|
|
|
|
return "Illegal parameter";
|
|
|
|
case 0x85:
|
|
|
|
return "Job Cancel";
|
|
|
|
case 0x89:
|
|
|
|
return "Last Job Error";
|
2018-05-16 08:03:16 -04:00
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-17 15:08:28 -04:00
|
|
|
static void mitsud90_dump_status(struct mitsud90_status_resp *resp)
|
|
|
|
{
|
|
|
|
INFO("Error Status: %s (%02x %02x) -- %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
|
2018-05-22 13:21:09 -04:00
|
|
|
mitsud90_error_codes(resp->code),
|
|
|
|
resp->code[0], resp->code[1],
|
|
|
|
resp->unk[0], resp->unk[1], resp->unk[2], resp->unk[3],
|
|
|
|
resp->unk[4], resp->unk[5], resp->unk[6], resp->unk[7],
|
|
|
|
resp->unk[8]);
|
2018-05-17 15:08:28 -04:00
|
|
|
INFO("Printer Status: %s (%02x %02x)\n",
|
2018-05-22 13:21:09 -04:00
|
|
|
mitsud90_mecha_statuses(resp->mecha),
|
|
|
|
resp->mecha[0], resp->mecha[1]);
|
|
|
|
INFO("Temperature Status: %s\n",
|
2020-02-11 21:09:45 -05:00
|
|
|
mitsu_temperatures(resp->temp));
|
2018-05-17 15:08:28 -04:00
|
|
|
}
|
|
|
|
|
2018-05-11 20:04:55 -04:00
|
|
|
/* Private data structure */
|
2018-06-15 14:55:03 -04:00
|
|
|
struct mitsud90_printjob {
|
2020-02-15 20:10:01 -05:00
|
|
|
size_t jobsize;
|
|
|
|
int copies;
|
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
uint8_t *databuf;
|
2020-02-05 13:22:26 -05:00
|
|
|
uint32_t datalen;
|
2020-02-15 20:10:01 -05:00
|
|
|
|
2020-02-25 20:58:59 -05:00
|
|
|
int is_raw;
|
|
|
|
|
2020-03-03 11:29:52 -05:00
|
|
|
int m1_colormode;
|
|
|
|
|
2020-02-15 20:10:01 -05:00
|
|
|
struct mitsud90_job_hdr hdr;
|
2020-03-03 19:21:47 -05:00
|
|
|
|
|
|
|
int has_footer;
|
2020-03-01 10:41:44 -05:00
|
|
|
struct mitsud90_job_footer footer;
|
2018-06-15 14:55:03 -04:00
|
|
|
};
|
|
|
|
|
2018-05-11 20:04:55 -04:00
|
|
|
struct mitsud90_ctx {
|
|
|
|
struct libusb_device_handle *dev;
|
|
|
|
uint8_t endp_up;
|
|
|
|
uint8_t endp_down;
|
|
|
|
|
|
|
|
int type;
|
2019-12-21 20:24:31 -05:00
|
|
|
char serno[7];
|
2018-05-11 20:04:55 -04:00
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
/* Used in parsing.. */
|
2018-05-14 15:20:33 -04:00
|
|
|
struct mitsud90_job_footer holdover;
|
|
|
|
int holdover_on;
|
|
|
|
|
2020-02-15 20:10:01 -05:00
|
|
|
/* For the CP-M1 family */
|
|
|
|
struct mitsu_lib lib;
|
|
|
|
|
2018-05-11 20:04:55 -04:00
|
|
|
struct marker marker;
|
|
|
|
};
|
|
|
|
|
2018-05-23 14:21:29 -04:00
|
|
|
static int mitsud90_query_media(struct mitsud90_ctx *ctx, struct mitsud90_media_resp *resp)
|
2018-05-11 20:04:55 -04:00
|
|
|
{
|
|
|
|
uint8_t cmdbuf[8];
|
|
|
|
int ret, num;
|
|
|
|
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x47;
|
|
|
|
cmdbuf[2] = 0x44;
|
|
|
|
cmdbuf[3] = 0x30;
|
|
|
|
cmdbuf[4] = 0;
|
|
|
|
cmdbuf[5] = 0;
|
|
|
|
cmdbuf[6] = 0x01; /* Number of commands */
|
2020-02-28 23:25:17 -05:00
|
|
|
cmdbuf[7] = COM_STATUS_TYPE_MEDIA;
|
2018-05-11 20:04:55 -04:00
|
|
|
|
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
cmdbuf, sizeof(cmdbuf))))
|
|
|
|
return ret;
|
|
|
|
memset(resp, 0, sizeof(*resp));
|
|
|
|
|
|
|
|
ret = read_data(ctx->dev, ctx->endp_up,
|
|
|
|
(uint8_t*) resp, sizeof(*resp), &num);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
if (num != sizeof(*resp)) {
|
|
|
|
ERROR("Short Read! (%d/%d)\n", num, (int)sizeof(*resp));
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CUPS_BACKEND_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-23 14:21:29 -04:00
|
|
|
static int mitsud90_query_status(struct mitsud90_ctx *ctx, struct mitsud90_status_resp *resp)
|
2018-05-11 20:04:55 -04:00
|
|
|
{
|
2018-05-22 13:21:09 -04:00
|
|
|
uint8_t cmdbuf[10];
|
2018-05-11 20:04:55 -04:00
|
|
|
int ret, num;
|
|
|
|
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x47;
|
|
|
|
cmdbuf[2] = 0x44;
|
|
|
|
cmdbuf[3] = 0x30;
|
|
|
|
cmdbuf[4] = 0;
|
|
|
|
cmdbuf[5] = 0;
|
2018-05-22 13:21:09 -04:00
|
|
|
cmdbuf[6] = 0x03; /* Number of commands */
|
2020-02-28 23:25:17 -05:00
|
|
|
cmdbuf[7] = COM_STATUS_TYPE_ERROR;
|
|
|
|
cmdbuf[8] = COM_STATUS_TYPE_MECHA;
|
|
|
|
cmdbuf[9] = COM_STATUS_TYPE_TEMP;
|
2018-05-11 20:04:55 -04:00
|
|
|
|
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
cmdbuf, sizeof(cmdbuf))))
|
|
|
|
return ret;
|
|
|
|
memset(resp, 0, sizeof(*resp));
|
|
|
|
|
|
|
|
ret = read_data(ctx->dev, ctx->endp_up,
|
|
|
|
(uint8_t*) resp, sizeof(*resp), &num);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
if (num != sizeof(*resp)) {
|
|
|
|
ERROR("Short Read! (%d/%d)\n", num, (int)sizeof(*resp));
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CUPS_BACKEND_OK;
|
|
|
|
}
|
|
|
|
|
2019-12-21 20:24:31 -05:00
|
|
|
static int mitsud90_get_serno(struct mitsud90_ctx *ctx)
|
|
|
|
{
|
|
|
|
uint8_t cmdbuf[32];
|
|
|
|
int ret, num;
|
|
|
|
|
|
|
|
/* Send Request */
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x61;
|
|
|
|
cmdbuf[2] = 0x36;
|
|
|
|
cmdbuf[3] = 0x36;
|
|
|
|
cmdbuf[4] = 0x41;
|
|
|
|
cmdbuf[5] = 0xbe;
|
|
|
|
cmdbuf[6] = 0x00;
|
|
|
|
cmdbuf[7] = 0x00;
|
|
|
|
|
|
|
|
cmdbuf[8] = 0x00;
|
|
|
|
cmdbuf[9] = 0x06;
|
|
|
|
cmdbuf[10] = 0x00;
|
|
|
|
cmdbuf[11] = 0x00;
|
|
|
|
cmdbuf[12] = 0x00;
|
|
|
|
cmdbuf[13] = 0x30;
|
|
|
|
cmdbuf[14] = 0xff;
|
|
|
|
cmdbuf[15] = 0xff;
|
|
|
|
|
|
|
|
cmdbuf[16] = 0xff;
|
|
|
|
cmdbuf[17] = 0xf9;
|
|
|
|
cmdbuf[18] = 0xff;
|
|
|
|
cmdbuf[19] = 0xff;
|
|
|
|
cmdbuf[20] = 0xff;
|
|
|
|
cmdbuf[21] = 0xcf;
|
|
|
|
|
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
cmdbuf, 22)))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = read_data(ctx->dev, ctx->endp_up,
|
|
|
|
cmdbuf, sizeof(cmdbuf), &num);
|
|
|
|
|
|
|
|
/* Store it */
|
|
|
|
memcpy(ctx->serno, &cmdbuf[22], 6);
|
|
|
|
ctx->serno[6] = 0;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-05-11 20:04:55 -04:00
|
|
|
/* Generic functions */
|
|
|
|
|
|
|
|
static void *mitsud90_init(void)
|
|
|
|
{
|
|
|
|
struct mitsud90_ctx *ctx = malloc(sizeof(struct mitsud90_ctx));
|
|
|
|
if (!ctx) {
|
|
|
|
ERROR("Memory Allocation Failure!\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memset(ctx, 0, sizeof(struct mitsud90_ctx));
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mitsud90_attach(void *vctx, struct libusb_device_handle *dev, int type,
|
2019-11-02 09:12:30 -04:00
|
|
|
uint8_t endp_up, uint8_t endp_down, int iface, uint8_t jobid)
|
2018-05-11 20:04:55 -04:00
|
|
|
{
|
|
|
|
struct mitsud90_ctx *ctx = vctx;
|
|
|
|
struct mitsud90_media_resp resp;
|
|
|
|
|
|
|
|
UNUSED(jobid);
|
2019-11-02 09:12:30 -04:00
|
|
|
UNUSED(iface);
|
2018-05-11 20:04:55 -04:00
|
|
|
|
|
|
|
ctx->dev = dev;
|
|
|
|
ctx->endp_up = endp_up;
|
|
|
|
ctx->endp_down = endp_down;
|
|
|
|
ctx->type = type;
|
|
|
|
|
|
|
|
if (test_mode < TEST_MODE_NOATTACH) {
|
|
|
|
if (mitsud90_query_media(ctx, &resp))
|
|
|
|
return CUPS_BACKEND_FAILED;
|
2019-12-21 20:24:31 -05:00
|
|
|
if (mitsud90_get_serno(ctx))
|
|
|
|
return CUPS_BACKEND_FAILED;
|
2018-05-11 20:04:55 -04:00
|
|
|
} else {
|
2018-05-17 15:08:28 -04:00
|
|
|
resp.media.brand = 0xff;
|
|
|
|
resp.media.type = 0x0f;
|
|
|
|
resp.media.capacity = cpu_to_be16(230);
|
|
|
|
resp.media.remain = cpu_to_be16(200);
|
2018-05-11 20:04:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ctx->marker.color = "#00FFFF#FF00FF#FFFF00";
|
2019-09-28 10:54:10 -04:00
|
|
|
ctx->marker.numtype = resp.media.type;
|
2020-02-28 23:24:28 -05:00
|
|
|
ctx->marker.name = mitsu_media_types(ctx->type, resp.media.brand, resp.media.type);
|
2018-05-17 15:08:28 -04:00
|
|
|
ctx->marker.levelmax = be16_to_cpu(resp.media.capacity);
|
|
|
|
ctx->marker.levelnow = be16_to_cpu(resp.media.remain);
|
2018-05-11 20:04:55 -04:00
|
|
|
|
2020-02-15 20:10:01 -05:00
|
|
|
if (ctx->type == P_MITSU_M1) {
|
|
|
|
#if defined(WITH_DYNAMIC)
|
2020-02-27 18:45:26 -05:00
|
|
|
/* Attempt to open the library */
|
|
|
|
if (mitsu_loadlib(&ctx->lib, ctx->type))
|
2020-02-15 20:10:01 -05:00
|
|
|
#endif
|
2020-02-27 18:45:26 -05:00
|
|
|
WARNING("Dynamic library support not loaded, will be unable to print.");
|
2020-02-15 20:10:01 -05:00
|
|
|
}
|
|
|
|
|
2020-03-04 07:09:21 -05:00
|
|
|
// XXX do some runtime checks for FW versions.
|
|
|
|
// do a MA FW comparison; CP-M1 v1.00 is 450B11. ME is 454C11
|
|
|
|
// CP-D90-P v2.10 is 415A81 or 415G11 (revA vs revB) ME is 419E11
|
|
|
|
// CP-D90DW v2.10 is 415B94 or 415E54 (??) ME is 419E42
|
|
|
|
// if nothing else, D90 v2.10 is needed for panorama.
|
|
|
|
// D90DW-P and D90DW share same USB VID/PID. Not sure how to tell
|
|
|
|
// them apart other than FW. No idea what functional differences are.
|
|
|
|
|
2018-05-11 20:04:55 -04:00
|
|
|
return CUPS_BACKEND_OK;
|
|
|
|
}
|
|
|
|
|
2020-02-15 20:10:01 -05:00
|
|
|
static void mitsud90_teardown(void *vctx) {
|
|
|
|
struct mitsud90_ctx *ctx = vctx;
|
|
|
|
|
|
|
|
if (!ctx)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ctx->type == P_MITSU_M1) {
|
|
|
|
mitsu_destroylib(&ctx->lib);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
static void mitsud90_cleanup_job(const void *vjob)
|
|
|
|
{
|
|
|
|
const struct mitsud90_printjob *job = vjob;
|
|
|
|
|
|
|
|
if (job->databuf)
|
|
|
|
free(job->databuf);
|
|
|
|
|
|
|
|
free((void*)job);
|
|
|
|
}
|
|
|
|
|
2020-02-25 20:58:59 -05:00
|
|
|
/* Sanity check some stuff */
|
|
|
|
STATIC_ASSERT(sizeof(struct mitsud90_job_hdr) == 512);
|
|
|
|
STATIC_ASSERT(sizeof(struct mitsud90_plane_hdr) == 512);
|
|
|
|
|
2020-02-29 15:40:01 -05:00
|
|
|
static int mitsud90_main_loop(void *vctx, const void *vjob);
|
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
static int mitsud90_read_parse(void *vctx, const void **vjob, int data_fd, int copies) {
|
2018-05-11 20:04:55 -04:00
|
|
|
struct mitsud90_ctx *ctx = vctx;
|
|
|
|
int i, remain;
|
|
|
|
|
2020-02-15 20:10:01 -05:00
|
|
|
struct mitsud90_printjob *job;
|
2018-06-15 14:55:03 -04:00
|
|
|
|
2018-05-11 20:04:55 -04:00
|
|
|
if (!ctx)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
job = malloc(sizeof(*job));
|
|
|
|
if (!job) {
|
|
|
|
ERROR("Memory allocation failure!\n");
|
|
|
|
return CUPS_BACKEND_RETRY_CURRENT;
|
2018-05-11 20:04:55 -04:00
|
|
|
}
|
2018-06-15 14:55:03 -04:00
|
|
|
memset(job, 0, sizeof(*job));
|
2020-02-15 20:10:01 -05:00
|
|
|
job->jobsize = sizeof(*job);
|
2018-06-15 14:55:03 -04:00
|
|
|
job->copies = copies;
|
2018-05-11 20:04:55 -04:00
|
|
|
|
|
|
|
/* Just allocate a worst-case buffer */
|
2018-06-15 14:55:03 -04:00
|
|
|
job->datalen = 0;
|
|
|
|
job->databuf = malloc(sizeof(struct mitsud90_job_hdr) +
|
2018-05-11 20:04:55 -04:00
|
|
|
sizeof(struct mitsud90_plane_hdr) +
|
2020-02-15 20:10:01 -05:00
|
|
|
1852*2729*3 + 1024);
|
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
if (!job->databuf) {
|
2018-05-11 20:04:55 -04:00
|
|
|
ERROR("Memory allocation failure!\n");
|
2018-06-17 19:17:28 -04:00
|
|
|
mitsud90_cleanup_job(job);
|
2018-05-11 20:04:55 -04:00
|
|
|
return CUPS_BACKEND_RETRY_CURRENT;
|
|
|
|
}
|
|
|
|
|
2018-05-14 15:20:33 -04:00
|
|
|
/* Make sure there's no holdover */
|
|
|
|
if (ctx->holdover_on) {
|
2018-06-15 14:55:03 -04:00
|
|
|
memcpy(job->databuf, &ctx->holdover, sizeof(ctx->holdover));
|
|
|
|
job->datalen += sizeof(ctx->holdover);
|
2018-05-14 15:20:33 -04:00
|
|
|
ctx->holdover_on = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read in first header. */
|
2018-06-15 14:55:03 -04:00
|
|
|
remain = sizeof(struct mitsud90_job_hdr) - job->datalen;
|
2018-05-11 20:04:55 -04:00
|
|
|
while (remain) {
|
2018-06-15 14:55:03 -04:00
|
|
|
i = read(data_fd, (job->databuf + job->datalen), remain);
|
2018-06-17 19:17:28 -04:00
|
|
|
if (i == 0) {
|
|
|
|
mitsud90_cleanup_job(job);
|
2018-05-11 20:04:55 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2018-06-17 19:17:28 -04:00
|
|
|
}
|
|
|
|
if (i < 0) {
|
|
|
|
mitsud90_cleanup_job(job);
|
2018-05-11 20:04:55 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2018-06-17 19:17:28 -04:00
|
|
|
}
|
2018-05-11 20:04:55 -04:00
|
|
|
remain -= i;
|
2018-06-15 14:55:03 -04:00
|
|
|
job->datalen += i;
|
2018-05-11 20:04:55 -04:00
|
|
|
}
|
2020-02-15 20:10:01 -05:00
|
|
|
/* Move over to its final resting place, and reset */
|
|
|
|
memcpy(&job->hdr, job->databuf, sizeof(job->hdr));
|
|
|
|
job->datalen = 0;
|
2018-05-11 20:04:55 -04:00
|
|
|
|
|
|
|
/* Sanity check header */
|
2020-02-15 20:10:01 -05:00
|
|
|
if (job->hdr.hdr[0] != 0x1b ||
|
|
|
|
job->hdr.hdr[1] != 0x53 ||
|
|
|
|
job->hdr.hdr[2] != 0x50 ||
|
|
|
|
job->hdr.hdr[3] != 0x30 ) {
|
2018-05-14 15:20:33 -04:00
|
|
|
ERROR("Unrecognized data format (%02x%02x%02x%02x)!\n",
|
2020-02-15 20:10:01 -05:00
|
|
|
job->hdr.hdr[0], job->hdr.hdr[1],
|
|
|
|
job->hdr.hdr[2], job->hdr.hdr[3]);
|
2018-06-17 19:17:28 -04:00
|
|
|
mitsud90_cleanup_job(job);
|
2018-05-11 20:04:55 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
}
|
|
|
|
|
2020-02-29 00:04:43 -05:00
|
|
|
/* More sanity checks */
|
|
|
|
if (job->hdr.pano.pano_on && ctx->type != P_MITSU_M1) {
|
|
|
|
ERROR("Unable to handle panorama jobs yet\n");
|
|
|
|
mitsud90_cleanup_job(job);
|
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
}
|
|
|
|
|
2020-03-05 23:36:51 -05:00
|
|
|
/* Sanity check cutlist */
|
|
|
|
if (job->hdr.numcuts > 3) {
|
|
|
|
ERROR("Cut list too long!\n");
|
|
|
|
mitsud90_cleanup_job(job);
|
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
}
|
|
|
|
if (job->hdr.numcuts >= 1) {
|
2020-03-06 00:00:26 -05:00
|
|
|
int rows = be16_to_cpu(job->hdr.rows);
|
|
|
|
for (i = 0 ; i < job->hdr.numcuts ; i++) {
|
2020-03-05 23:36:51 -05:00
|
|
|
int min_size;
|
2020-03-06 00:00:26 -05:00
|
|
|
int position = be16_to_cpu(job->hdr.cutlist[i].position);
|
|
|
|
int last_position = (i == 0) ? 0 : be16_to_cpu(job->hdr.cutlist[i-1].position);
|
|
|
|
|
|
|
|
if (i == 0)
|
|
|
|
min_size = 613;
|
2020-03-05 23:36:51 -05:00
|
|
|
else
|
2020-03-06 00:00:26 -05:00
|
|
|
min_size = (job->hdr.cutlist[i-1].margincut) ? 601 : 660; // XXX inverted?
|
|
|
|
|
|
|
|
if ((position - last_position) < min_size) {
|
|
|
|
ERROR("Minumum cut#%d length is %d rows\n", i, min_size);
|
|
|
|
mitsud90_cleanup_job(job);
|
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
}
|
|
|
|
if ((rows - position) < min_size) {
|
|
|
|
ERROR("Cut#%d is too close to end\n", i);
|
2020-03-05 23:36:51 -05:00
|
|
|
mitsud90_cleanup_job(job);
|
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
}
|
|