2014-12-11 16:16:56 -05:00
|
|
|
/*
|
2016-10-13 12:50:30 -04:00
|
|
|
* Mitsubishi CP-9xxx Photo Printer Family CUPS backend
|
2014-12-11 16:16:56 -05:00
|
|
|
*
|
2024-01-20 17:59:48 -05:00
|
|
|
* (c) 2014-2024 Solomon Peachy <pizza@shaftnet.org>
|
2014-12-11 16:16:56 -05:00
|
|
|
*
|
|
|
|
* The latest version of this program can be found at:
|
|
|
|
*
|
2024-05-29 20:34:43 -04:00
|
|
|
* https://git.shaftnet.org/gitea/slp/selphy_print.git
|
2014-12-11 16:16:56 -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
|
2020-01-17 16:50:56 -05:00
|
|
|
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
2014-12-11 16:16:56 -05:00
|
|
|
*
|
2017-11-17 13:34:26 -05:00
|
|
|
* SPDX-License-Identifier: GPL-3.0+
|
|
|
|
*
|
2014-12-11 16:16:56 -05:00
|
|
|
*/
|
|
|
|
|
2019-09-28 11:05:42 -04:00
|
|
|
#define BACKEND mitsu9550_backend
|
2014-12-11 16:16:56 -05:00
|
|
|
|
2019-09-28 11:05:42 -04:00
|
|
|
#include "backend_common.h"
|
2020-02-05 13:22:26 -05:00
|
|
|
#include "backend_mitsu.h"
|
2014-12-11 16:16:56 -05:00
|
|
|
|
2020-02-16 16:19:44 -05:00
|
|
|
#define MITSU_M98xx_LAMINATE_FILE "M98MATTE.raw"
|
|
|
|
#define MITSU_M98xx_DATATABLE_FILE "M98TABLE.dat"
|
|
|
|
#define MITSU_M98xx_LUT_FILE "M98XXL01.lut"
|
2020-06-03 23:15:04 -04:00
|
|
|
#define MITSU_CP30D_LUT_FILE "CP30LT_1.lut"
|
2018-01-21 21:36:29 -05:00
|
|
|
#define LAMINATE_STRIDE 1868
|
|
|
|
|
2014-12-11 16:16:56 -05:00
|
|
|
/* Spool file structures */
|
2016-10-12 23:28:54 -04:00
|
|
|
|
|
|
|
/* Print parameters1 */
|
2014-12-11 16:16:56 -05:00
|
|
|
struct mitsu9550_hdr1 {
|
2019-03-08 13:59:45 -05:00
|
|
|
uint8_t cmd[4]; /* 1b 57 20 2e */
|
2016-10-12 23:28:54 -04:00
|
|
|
uint8_t unk[10]; /* 00 0a 10 00 [...] */
|
2019-03-08 13:59:45 -05:00
|
|
|
uint16_t cols; /* BE */
|
|
|
|
uint16_t rows; /* BE */
|
|
|
|
uint8_t matte; /* CP9810/9820 only. 01 for matte, 00 glossy */
|
2016-10-12 20:29:02 -04:00
|
|
|
uint8_t null[31];
|
2014-12-11 16:16:56 -05:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2016-10-12 23:28:54 -04:00
|
|
|
/* Print parameters2 */
|
2014-12-11 16:16:56 -05:00
|
|
|
struct mitsu9550_hdr2 {
|
2019-03-08 13:59:45 -05:00
|
|
|
uint8_t cmd[4]; /* 1b 57 21 2e */
|
|
|
|
uint8_t unk[24]; /* 00 80 00 22 08 03 [...] */
|
|
|
|
uint16_t copies; /* BE, 1-680 */
|
2014-12-14 18:10:01 -05:00
|
|
|
uint8_t null[2];
|
2019-03-08 13:59:45 -05:00
|
|
|
uint8_t cut; /* 00 == normal, 83 == 2x6*2 */
|
2014-12-25 08:23:18 -05:00
|
|
|
uint8_t unkb[5];
|
2019-03-08 13:59:45 -05:00
|
|
|
uint8_t mode; /* 00 == fine, 80 == superfine */
|
2020-03-01 08:50:15 -05:00
|
|
|
uint8_t unkc[11]; /* 00 [...] 00 01 ; note [7][8][9] are cp98xx extensions for sharpness/reversed/lut */
|
2014-12-11 16:16:56 -05:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2016-10-12 23:28:54 -04:00
|
|
|
/* Fine Deep selection (9550 only) */
|
2014-12-11 16:16:56 -05:00
|
|
|
struct mitsu9550_hdr3 {
|
2019-03-08 13:59:45 -05:00
|
|
|
uint8_t cmd[4]; /* 1b 57 22 2e */
|
|
|
|
uint8_t unk[7]; /* 00 40 00 [...] */
|
|
|
|
uint8_t mode2; /* 00 == normal, 01 == finedeep */
|
2016-09-28 14:15:04 -04:00
|
|
|
uint8_t null[38];
|
2014-12-11 16:16:56 -05:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2016-10-12 23:28:54 -04:00
|
|
|
/* Error policy? */
|
2014-12-11 16:16:56 -05:00
|
|
|
struct mitsu9550_hdr4 {
|
2019-03-08 13:59:45 -05:00
|
|
|
uint8_t cmd[4]; /* 1b 57 26 2e */
|
|
|
|
uint8_t unk[46]; /* 00 70 00 00 00 00 00 00 01 01 00 [...] */
|
2014-12-11 16:16:56 -05:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2016-10-13 08:12:20 -04:00
|
|
|
/* Data plane header */
|
2014-12-11 16:16:56 -05:00
|
|
|
struct mitsu9550_plane {
|
2019-03-08 13:59:45 -05:00
|
|
|
uint8_t cmd[4]; /* 1b 5a 54 XX */ /* XX == 0x10 if 16bpp, 0x00 for 8bpp */
|
2018-04-19 08:15:01 -04:00
|
|
|
uint16_t col_offset; /* BE, normally 0, where we start dumping data */
|
2016-10-23 09:32:43 -04:00
|
|
|
uint16_t row_offset; /* BE, normally 0, where we start dumping data */
|
|
|
|
uint16_t cols; /* BE */
|
|
|
|
uint16_t rows; /* BE */
|
2014-12-11 16:16:56 -05:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2018-04-18 20:52:32 -04:00
|
|
|
/* Command header */
|
2014-12-14 19:09:32 -05:00
|
|
|
struct mitsu9550_cmd {
|
|
|
|
uint8_t cmd[4];
|
2014-12-11 16:16:56 -05:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2017-05-05 08:06:28 -04:00
|
|
|
/* Private data structure */
|
2018-06-15 14:55:03 -04:00
|
|
|
struct mitsu9550_printjob {
|
2021-09-30 14:52:11 -04:00
|
|
|
struct dyesub_job_common common;
|
2020-02-11 17:22:39 -05:00
|
|
|
|
2016-10-13 08:12:20 -04:00
|
|
|
uint8_t *databuf;
|
|
|
|
uint32_t datalen;
|
|
|
|
|
|
|
|
uint16_t rows;
|
|
|
|
uint16_t cols;
|
|
|
|
uint32_t plane_len;
|
2018-06-17 22:24:15 -04:00
|
|
|
int is_raw;
|
2016-10-13 08:12:20 -04:00
|
|
|
|
|
|
|
/* Parse headers separately */
|
|
|
|
struct mitsu9550_hdr1 hdr1;
|
|
|
|
int hdr1_present;
|
|
|
|
struct mitsu9550_hdr2 hdr2;
|
|
|
|
int hdr2_present;
|
|
|
|
struct mitsu9550_hdr3 hdr3;
|
|
|
|
int hdr3_present;
|
|
|
|
struct mitsu9550_hdr4 hdr4;
|
|
|
|
int hdr4_present;
|
2018-06-15 14:55:03 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct mitsu9550_ctx {
|
2020-08-11 20:27:26 -04:00
|
|
|
struct dyesub_connection *conn;
|
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
int is_s;
|
|
|
|
int is_98xx;
|
2020-12-05 18:14:33 -05:00
|
|
|
int need_lib;
|
2020-05-18 14:00:49 -04:00
|
|
|
int footer_len;
|
2020-06-03 23:15:04 -04:00
|
|
|
const char *lut_fname;
|
2018-06-15 14:55:03 -04:00
|
|
|
|
2020-12-04 20:02:44 -05:00
|
|
|
char fwver[7]; /* 6 + null */
|
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
struct marker marker;
|
2018-04-18 20:52:32 -04:00
|
|
|
|
|
|
|
/* CP98xx stuff */
|
2020-02-05 13:22:26 -05:00
|
|
|
struct mitsu_lib lib;
|
2020-02-08 22:38:27 -05:00
|
|
|
const struct mitsu98xx_data *m98xxdata;
|
2016-10-13 08:12:20 -04:00
|
|
|
};
|
|
|
|
|
2014-12-11 16:16:56 -05:00
|
|
|
/* Printer data structures */
|
2020-12-04 23:35:19 -05:00
|
|
|
#define CP9XXX_STS_x20 0x20
|
|
|
|
#define CP9XXX_STS_x21 0x21 /* struct mitsu9550_status2 */
|
|
|
|
#define CP9XXX_STS_x22 0x22
|
|
|
|
#define CP9XXX_STS_FWVER 0x23
|
|
|
|
#define CP9XXX_STS_MEDIA 0x24 /* struct mitsu9550_media */
|
|
|
|
#define CP9XXX_STS_x26 0x26
|
|
|
|
#define CP9XXX_STS_x30 0x30 /* struct mitsu9550_status */
|
2020-12-05 16:39:12 -05:00
|
|
|
#define CP9XXX_STS_x32 0x32 /* struct mitsucp30_status */
|
2020-12-03 21:40:10 -05:00
|
|
|
|
2014-12-11 16:16:56 -05:00
|
|
|
struct mitsu9550_media {
|
2014-12-14 20:52:21 -05:00
|
|
|
uint8_t hdr[2]; /* 24 2e */
|
|
|
|
uint8_t unk[12];
|
|
|
|
uint8_t type;
|
2021-07-09 20:35:53 -04:00
|
|
|
uint8_t unka[11];
|
|
|
|
uint16_t unkb; /* 0d 00 (CP9810), 00 00 (others?) */
|
|
|
|
uint16_t max; /* BE, prints per media */
|
2020-12-03 21:40:10 -05:00
|
|
|
uint16_t remain2; /* BE, prints remaining (CP30)*/
|
2021-07-09 20:35:53 -04:00
|
|
|
uint16_t remain; /* BE, prints remaining (Everything else) */
|
2014-12-14 20:52:21 -05:00
|
|
|
uint8_t unkc[14];
|
2014-12-11 16:16:56 -05:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct mitsu9550_status {
|
2014-12-14 20:52:21 -05:00
|
|
|
uint8_t hdr[2]; /* 30 2e */
|
|
|
|
uint8_t null[4];
|
2014-12-15 09:11:41 -05:00
|
|
|
uint8_t sts1; // MM
|
2014-12-20 12:43:22 -05:00
|
|
|
uint8_t nullb[1];
|
2016-09-28 14:15:04 -04:00
|
|
|
uint16_t copies; // BE, NN
|
2016-10-31 14:02:23 -04:00
|
|
|
uint8_t sts2; // ZZ (9600 only?)
|
|
|
|
uint8_t nullc[5];
|
2014-12-15 09:11:41 -05:00
|
|
|
uint8_t sts3; // QQ
|
|
|
|
uint8_t sts4; // RR
|
|
|
|
uint8_t sts5; // SS
|
2014-12-14 20:52:21 -05:00
|
|
|
uint8_t nulld[25];
|
2014-12-15 09:11:41 -05:00
|
|
|
uint8_t sts6; // TT
|
|
|
|
uint8_t sts7; // UU
|
2014-12-14 20:52:21 -05:00
|
|
|
uint8_t nulle[2];
|
2014-12-11 16:16:56 -05:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2020-12-05 16:39:12 -05:00
|
|
|
struct mitsucp30_status {
|
|
|
|
uint8_t hdr[2]; /* 32 2e */
|
|
|
|
uint8_t zero[2];
|
|
|
|
uint16_t serno[13]; /* UTF16, BE */
|
|
|
|
uint8_t sts; /* CP30_STS_* */
|
|
|
|
uint8_t sts2;
|
|
|
|
uint8_t zerob;
|
|
|
|
uint16_t err; /* CP30_ERR_* */
|
|
|
|
uint8_t zeroc[2];
|
|
|
|
uint8_t remain; /* on media */
|
|
|
|
uint8_t zerod[9];
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
#define CP30_STS_IDLE 0x00
|
|
|
|
#define CP30_STS_PRINT 0x20
|
|
|
|
|
|
|
|
#define CP30_STS_PRINT_A 0x10 //Load
|
|
|
|
#define CP30_STS_PRINT_B 0x20 //Y
|
|
|
|
#define CP30_STS_PRINT_C 0x30 //M
|
|
|
|
#define CP30_STS_PRINT_D 0x40 //C
|
|
|
|
#define CP30_STS_PRINT_E 0x60 //Eject?
|
|
|
|
|
|
|
|
#define CP30_ERR_OK 0x0000
|
|
|
|
#define CP30_ERR_NOPC 0x0303
|
|
|
|
#define CP30_ERR_NORIBBON 0x0101
|
2020-12-05 19:04:18 -05:00
|
|
|
#define CP30_ERR_TRAYFULL 0x1404
|
2020-12-05 16:39:12 -05:00
|
|
|
|
2014-12-11 16:16:56 -05:00
|
|
|
struct mitsu9550_status2 {
|
2020-12-04 23:35:19 -05:00
|
|
|
uint8_t hdr[2]; /* 21 2e */
|
2018-05-04 08:34:57 -04:00
|
|
|
uint8_t unk[40];
|
2016-10-31 13:44:56 -04:00
|
|
|
uint16_t remain; /* BE, media remaining */
|
2016-10-31 14:02:23 -04:00
|
|
|
uint8_t unkb[4]; /* 0a 00 00 01 */
|
2014-12-11 16:16:56 -05:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
2021-09-30 11:37:14 -04:00
|
|
|
static int mitsu9550_main_loop(void *vctx, const void *vjob, int wait_for_return);
|
2018-06-19 09:04:17 -04:00
|
|
|
|
2020-12-05 19:04:18 -05:00
|
|
|
static const char *cp30_errors(uint16_t err)
|
|
|
|
{
|
|
|
|
switch(err){
|
|
|
|
case CP30_ERR_OK: return "None";
|
|
|
|
case CP30_ERR_NOPC: return "No Paper Cassette";
|
|
|
|
case CP30_ERR_NORIBBON: return "No Ribbon Loaded";
|
|
|
|
case CP30_ERR_TRAYFULL: return "Output Tray Full";
|
|
|
|
default: return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-05 21:05:03 -05:00
|
|
|
static const char *cp30_media_types(uint16_t remain)
|
|
|
|
{
|
|
|
|
switch(remain) {
|
|
|
|
case 80: return "CK30S";
|
|
|
|
case 50: return "CK30L";
|
|
|
|
default: return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-11 16:16:56 -05:00
|
|
|
#define CMDBUF_LEN 64
|
|
|
|
#define READBACK_LEN 128
|
|
|
|
|
2020-12-04 23:35:19 -05:00
|
|
|
#define QUERY_STATUS_I \
|
2023-11-01 14:11:58 -04:00
|
|
|
const struct mitsu9550_status *sts = (struct mitsu9550_status*) rdbuf; \
|
|
|
|
const struct mitsucp30_status *sts30 = (struct mitsucp30_status*) rdbuf; \
|
|
|
|
const struct mitsu9550_media *media = (struct mitsu9550_media *) rdbuf; \
|
2020-12-04 23:35:19 -05:00
|
|
|
uint16_t donor; \
|
|
|
|
/* media */ \
|
2020-12-05 16:39:12 -05:00
|
|
|
ret = mitsu9550_get_status(ctx, rdbuf, CP9XXX_STS_MEDIA); \
|
2020-12-04 23:35:19 -05:00
|
|
|
if (ret < 0) \
|
|
|
|
return CUPS_BACKEND_FAILED; \
|
|
|
|
\
|
|
|
|
if (ctx->conn->type == P_MITSU_CP30D) { \
|
|
|
|
donor = be16_to_cpu(media->remain2); \
|
|
|
|
} else { \
|
|
|
|
donor = be16_to_cpu(media->remain); \
|
|
|
|
} \
|
|
|
|
if (donor != ctx->marker.levelnow) { \
|
|
|
|
ctx->marker.levelnow = donor; \
|
|
|
|
dump_markers(&ctx->marker, 1, 0); \
|
|
|
|
} \
|
|
|
|
/* Sanity-check media response */ \
|
|
|
|
if ((media->remain == 0 && media->remain2 == 0) || media->max == 0) { \
|
|
|
|
ERROR("Printer out of media!\n"); \
|
2021-09-29 22:54:07 -04:00
|
|
|
return CUPS_BACKEND_STOP; \
|
2020-12-04 23:35:19 -05:00
|
|
|
} \
|
|
|
|
|
|
|
|
#define QUERY_STATUS_II \
|
2020-12-05 19:15:46 -05:00
|
|
|
if (ctx->conn->type != P_MITSU_CP30D) { \
|
2020-12-05 16:39:12 -05:00
|
|
|
/* struct mitsu9550_status2 *sts2 = (struct mitsu9550_status2*) rdbuf; */ \
|
|
|
|
ret = mitsu9550_get_status(ctx, rdbuf, CP9XXX_STS_x21); \
|
2020-12-05 19:15:46 -05:00
|
|
|
if (ret < 0) \
|
|
|
|
return CUPS_BACKEND_FAILED; \
|
2020-12-05 16:39:12 -05:00
|
|
|
/* XXX validate status2 ? */ \
|
|
|
|
}
|
2020-12-04 23:35:19 -05:00
|
|
|
|
|
|
|
#define QUERY_STATUS_III \
|
|
|
|
/* Check for known errors */ \
|
|
|
|
if (sts->sts2 != 0) { \
|
|
|
|
ERROR("Printer cover open!\n"); \
|
|
|
|
return CUPS_BACKEND_STOP; \
|
2020-12-05 16:39:12 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#define QUERY_STATUS_IIIB \
|
|
|
|
/* Check for known errors */ \
|
2020-12-05 19:04:18 -05:00
|
|
|
if (sts30->err != CP30_ERR_OK) { \
|
|
|
|
ERROR("%s (%04x)!\n", cp30_errors(be16_to_cpu(sts30->err)), be16_to_cpu(sts30->err)); \
|
2020-12-05 16:39:12 -05:00
|
|
|
return CUPS_BACKEND_STOP; \
|
|
|
|
}
|
2020-12-04 23:35:19 -05:00
|
|
|
|
|
|
|
#define QUERY_STATUS_IV \
|
2020-12-05 16:39:12 -05:00
|
|
|
if (ctx->conn->type == P_MITSU_CP30D) { \
|
|
|
|
ret = mitsu9550_get_status(ctx, rdbuf, CP9XXX_STS_x32); \
|
|
|
|
if (ret < 0) \
|
|
|
|
return CUPS_BACKEND_FAILED; \
|
|
|
|
\
|
|
|
|
if (sts30->sts != CP30_STS_IDLE) { \
|
|
|
|
sleep(1); \
|
|
|
|
goto top; \
|
|
|
|
} \
|
|
|
|
QUERY_STATUS_IIIB; \
|
|
|
|
} else { \
|
2020-12-04 23:35:19 -05:00
|
|
|
ret = mitsu9550_get_status(ctx, rdbuf, CP9XXX_STS_x30); \
|
|
|
|
if (ret < 0) \
|
|
|
|
return CUPS_BACKEND_FAILED; \
|
|
|
|
\
|
|
|
|
/* Make sure we're idle */ \
|
2020-12-05 16:39:12 -05:00
|
|
|
if (sts->sts5 != 0) { \
|
2020-12-04 23:35:19 -05:00
|
|
|
sleep(1); \
|
|
|
|
goto top; \
|
|
|
|
} \
|
|
|
|
QUERY_STATUS_III; \
|
|
|
|
} \
|
2016-08-17 21:16:15 -04:00
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
static int mitsu98xx_fillmatte(struct mitsu9550_printjob *job)
|
2018-04-19 08:15:01 -04:00
|
|
|
{
|
2020-02-05 13:22:26 -05:00
|
|
|
int ret;
|
2018-04-19 08:15:01 -04:00
|
|
|
|
|
|
|
/* Fill in the lamination plane header */
|
2018-06-15 14:55:03 -04:00
|
|
|
struct mitsu9550_plane *matte = (struct mitsu9550_plane *)(job->databuf + job->datalen);
|
2018-04-19 08:15:01 -04:00
|
|
|
matte->cmd[0] = 0x1b;
|
|
|
|
matte->cmd[1] = 0x5a;
|
|
|
|
matte->cmd[2] = 0x54;
|
|
|
|
matte->cmd[3] = 0x10;
|
|
|
|
matte->row_offset = 0;
|
|
|
|
matte->col_offset = 0;
|
2023-10-09 21:47:32 -04:00
|
|
|
matte->cols = cpu_to_be16(job->cols);
|
|
|
|
matte->rows = cpu_to_be16(job->rows);
|
2018-06-15 14:55:03 -04:00
|
|
|
job->datalen += sizeof(struct mitsu9550_plane);
|
2018-04-19 08:15:01 -04:00
|
|
|
|
2020-02-05 13:22:26 -05:00
|
|
|
ret = mitsu_readlamdata(MITSU_M98xx_LAMINATE_FILE, LAMINATE_STRIDE,
|
|
|
|
job->databuf, &job->datalen,
|
|
|
|
job->rows, job->cols, 2);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2018-04-19 08:15:01 -04:00
|
|
|
|
|
|
|
/* Fill in the lamination plane footer */
|
2018-06-15 14:55:03 -04:00
|
|
|
job->databuf[job->datalen++] = 0x1b;
|
|
|
|
job->databuf[job->datalen++] = 0x50;
|
|
|
|
job->databuf[job->datalen++] = 0x56;
|
|
|
|
job->databuf[job->datalen++] = 0x00;
|
2018-04-19 08:15:01 -04:00
|
|
|
|
|
|
|
return CUPS_BACKEND_OK;
|
|
|
|
}
|
|
|
|
|
2020-12-03 21:40:10 -05:00
|
|
|
static int mitsu9550_get_status(struct mitsu9550_ctx *ctx, uint8_t *resp, int type);
|
2020-03-24 18:22:39 -04:00
|
|
|
static const char *mitsu9550_media_types(uint8_t type, uint8_t is_s);
|
2018-04-19 08:15:01 -04:00
|
|
|
|
2014-12-11 16:16:56 -05:00
|
|
|
static void *mitsu9550_init(void)
|
|
|
|
{
|
|
|
|
struct mitsu9550_ctx *ctx = malloc(sizeof(struct mitsu9550_ctx));
|
2015-06-23 20:32:41 -04:00
|
|
|
if (!ctx) {
|
|
|
|
ERROR("Memory Allocation Failure!\n");
|
2014-12-11 16:16:56 -05:00
|
|
|
return NULL;
|
2015-06-23 20:32:41 -04:00
|
|
|
}
|
2014-12-11 16:16:56 -05:00
|
|
|
memset(ctx, 0, sizeof(struct mitsu9550_ctx));
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
static int mitsu9550_attach(void *vctx, struct dyesub_connection *conn, uint8_t jobid)
|
2014-12-11 16:16:56 -05:00
|
|
|
{
|
|
|
|
struct mitsu9550_ctx *ctx = vctx;
|
2018-04-27 15:40:09 -04:00
|
|
|
struct mitsu9550_media media;
|
2014-12-11 16:16:56 -05:00
|
|
|
|
|
|
|
UNUSED(jobid);
|
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
ctx->conn = conn;
|
2016-08-17 21:16:15 -04:00
|
|
|
|
2023-10-04 20:12:15 -04:00
|
|
|
if (ctx->conn->type == P_MITSU_9500S ||
|
|
|
|
ctx->conn->type == P_MITSU_9550S ||
|
|
|
|
ctx->conn->type == P_MITSU_9600S ||
|
2023-10-02 09:31:35 -04:00
|
|
|
ctx->conn->type == P_MITSU_9800S ||
|
|
|
|
ctx->conn->type == P_MITSU_9820S)
|
2016-10-14 07:42:24 -04:00
|
|
|
ctx->is_s = 1;
|
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
if (ctx->conn->type == P_MITSU_9800 ||
|
|
|
|
ctx->conn->type == P_MITSU_9800S ||
|
2023-10-02 09:31:35 -04:00
|
|
|
ctx->conn->type == P_MITSU_9820S ||
|
2020-08-11 20:27:26 -04:00
|
|
|
ctx->conn->type == P_MITSU_9810) {
|
2018-04-18 20:52:32 -04:00
|
|
|
ctx->is_98xx = 1;
|
2020-12-05 18:14:33 -05:00
|
|
|
ctx->need_lib = 1;
|
2020-06-03 23:15:04 -04:00
|
|
|
ctx->lut_fname = MITSU_M98xx_LUT_FILE;
|
|
|
|
}
|
2018-04-18 20:52:32 -04:00
|
|
|
|
2020-12-05 18:14:33 -05:00
|
|
|
if (ctx->conn->type == P_MITSU_CP30D) {
|
|
|
|
ctx->need_lib = 1;
|
|
|
|
}
|
|
|
|
if (ctx->need_lib) {
|
2020-02-05 13:22:26 -05:00
|
|
|
#if defined(WITH_DYNAMIC)
|
2020-02-27 11:53:31 -05:00
|
|
|
/* Attempt to open the library */
|
2020-08-11 20:27:26 -04:00
|
|
|
if (mitsu_loadlib(&ctx->lib, ctx->conn->type))
|
2019-02-26 07:23:14 -05:00
|
|
|
#endif
|
2020-02-27 11:53:31 -05:00
|
|
|
WARNING("Dynamic library support not loaded, will be unable to print.");
|
|
|
|
}
|
|
|
|
|
2020-08-11 20:27:26 -04:00
|
|
|
if (ctx->conn->type == P_MITSU_CP30D) {
|
2020-05-18 14:00:49 -04:00
|
|
|
ctx->footer_len = 6;
|
2020-06-03 23:15:04 -04:00
|
|
|
ctx->lut_fname = MITSU_CP30D_LUT_FILE;
|
|
|
|
} else {
|
2020-05-18 14:00:49 -04:00
|
|
|
ctx->footer_len = 4;
|
2020-06-03 23:15:04 -04:00
|
|
|
}
|
2020-05-18 14:00:49 -04:00
|
|
|
|
2018-05-12 12:17:24 -04:00
|
|
|
if (test_mode < TEST_MODE_NOATTACH) {
|
2020-12-04 20:02:44 -05:00
|
|
|
uint8_t buf[48];
|
2020-12-04 23:35:19 -05:00
|
|
|
if (mitsu9550_get_status(ctx, (uint8_t*) &media, CP9XXX_STS_MEDIA))
|
2018-05-12 12:17:24 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2020-12-04 20:02:44 -05:00
|
|
|
|
|
|
|
/* Get FW Version */
|
2020-12-04 23:35:19 -05:00
|
|
|
if (mitsu9550_get_status(ctx, buf, CP9XXX_STS_FWVER))
|
2020-12-04 20:02:44 -05:00
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
memcpy(ctx->fwver, &buf[6], 6);
|
|
|
|
ctx->fwver[6] = 0;
|
|
|
|
// XXX get serial number too?
|
2018-05-12 12:17:24 -04:00
|
|
|
} else {
|
2018-09-21 15:20:38 -04:00
|
|
|
int media_code = 0x2;
|
|
|
|
if (getenv("MEDIA_CODE"))
|
2024-01-20 17:59:48 -05:00
|
|
|
media_code = strtol(getenv("MEDIA_CODE"), NULL, 16) & 0xf;
|
2018-09-21 15:20:38 -04:00
|
|
|
|
2018-05-12 12:17:24 -04:00
|
|
|
media.max = cpu_to_be16(400);
|
2018-05-12 18:33:39 -04:00
|
|
|
media.remain = cpu_to_be16(330);
|
2020-12-03 21:40:10 -05:00
|
|
|
media.remain2 = cpu_to_be16(330);
|
2018-09-21 15:20:38 -04:00
|
|
|
media.type = media_code;
|
2020-12-04 20:02:44 -05:00
|
|
|
ctx->fwver[0] = 0;
|
2018-05-12 12:17:24 -04:00
|
|
|
}
|
|
|
|
|
2018-04-27 15:40:09 -04:00
|
|
|
ctx->marker.color = "#00FFFF#FF00FF#FFFF00";
|
2019-09-28 10:54:10 -04:00
|
|
|
ctx->marker.numtype = media.type;
|
2018-04-27 15:40:09 -04:00
|
|
|
ctx->marker.levelmax = be16_to_cpu(media.max);
|
2020-12-03 21:40:10 -05:00
|
|
|
|
|
|
|
if (ctx->conn->type == P_MITSU_CP30D) {
|
2020-12-05 21:05:03 -05:00
|
|
|
ctx->marker.name = cp30_media_types(be16_to_cpu(media.max));
|
2020-12-03 21:40:10 -05:00
|
|
|
ctx->marker.levelnow = be16_to_cpu(media.remain2);
|
|
|
|
} else {
|
2020-12-05 21:05:03 -05:00
|
|
|
ctx->marker.name = mitsu9550_media_types(media.type, ctx->is_s);
|
2020-12-03 21:40:10 -05:00
|
|
|
ctx->marker.levelnow = be16_to_cpu(media.remain);
|
|
|
|
}
|
2018-04-27 15:07:43 -04:00
|
|
|
|
|
|
|
return CUPS_BACKEND_OK;
|
2014-12-11 16:16:56 -05:00
|
|
|
}
|
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
static void mitsu9550_cleanup_job(const void *vjob)
|
|
|
|
{
|
|
|
|
const struct mitsu9550_printjob *job = vjob;
|
|
|
|
|
|
|
|
if (job->databuf)
|
|
|
|
free(job->databuf);
|
|
|
|
|
|
|
|
free((void*)job);
|
|
|
|
}
|
|
|
|
|
2014-12-11 16:16:56 -05:00
|
|
|
static void mitsu9550_teardown(void *vctx) {
|
|
|
|
struct mitsu9550_ctx *ctx = vctx;
|
|
|
|
|
|
|
|
if (!ctx)
|
|
|
|
return;
|
|
|
|
|
2020-02-05 13:22:26 -05:00
|
|
|
if (ctx->m98xxdata)
|
2020-02-08 22:38:27 -05:00
|
|
|
ctx->lib.CP98xx_DestroyData(ctx->m98xxdata);
|
2020-02-05 13:22:26 -05:00
|
|
|
|
|
|
|
mitsu_destroylib(&ctx->lib);
|
2019-02-26 07:23:14 -05:00
|
|
|
|
2014-12-11 16:16:56 -05:00
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
static int mitsu9550_read_parse(void *vctx, const void **vjob, int data_fd, int copies) {
|
2014-12-11 16:16:56 -05:00
|
|
|
struct mitsu9550_ctx *ctx = vctx;
|
2016-10-13 08:12:20 -04:00
|
|
|
uint8_t buf[sizeof(struct mitsu9550_hdr1)];
|
2023-10-04 10:34:47 -04:00
|
|
|
int planes = 3, i;
|
|
|
|
uint32_t planelen = 0, remain = 0;
|
2014-12-11 16:16:56 -05:00
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
struct mitsu9550_printjob *job = NULL;
|
|
|
|
|
2014-12-11 16:16:56 -05: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;
|
2014-12-11 16:16:56 -05:00
|
|
|
}
|
2018-06-15 14:55:03 -04:00
|
|
|
memset(job, 0, sizeof(*job));
|
2023-10-04 10:34:47 -04:00
|
|
|
job->is_raw = 0;
|
2021-09-30 14:52:11 -04:00
|
|
|
job->common.jobsize = sizeof(*job);
|
|
|
|
job->common.copies = copies;
|
2016-10-13 08:12:20 -04:00
|
|
|
|
|
|
|
top:
|
2023-10-04 10:34:47 -04:00
|
|
|
/* Read in first two bytes */
|
|
|
|
i = read(data_fd, buf, 2);
|
|
|
|
if (i == 0) {
|
|
|
|
mitsu9550_cleanup_job(job);
|
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
}
|
|
|
|
if (i < 0) {
|
|
|
|
mitsu9550_cleanup_job(job);
|
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
}
|
|
|
|
if (buf[0] != 0x1b) {
|
|
|
|
ERROR("Unrecognized cmd sequence (%02x %02x)!\n",
|
|
|
|
buf[0], buf[1]);
|
2023-11-01 14:11:58 -04:00
|
|
|
mitsu9550_cleanup_job(job);
|
2023-10-04 10:34:47 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
}
|
|
|
|
switch (buf[1]) {
|
|
|
|
case 0x57:
|
|
|
|
remain = sizeof(buf) - 2;
|
|
|
|
break;
|
|
|
|
case 0x5a:
|
|
|
|
remain = sizeof(struct mitsu9550_plane) - 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERROR("Unrecognized cmd sequence (%02x %02x)!\n",
|
|
|
|
buf[0], buf[1]);
|
2023-11-01 14:11:58 -04:00
|
|
|
mitsu9550_cleanup_job(job);
|
2023-10-04 10:34:47 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read in remainder of header */
|
|
|
|
while (remain) {
|
|
|
|
i = read(data_fd, buf + 2, remain);
|
2018-06-17 21:08:17 -04:00
|
|
|
if (i == 0) {
|
|
|
|
mitsu9550_cleanup_job(job);
|
2014-12-11 16:16:56 -05:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2018-06-17 21:08:17 -04:00
|
|
|
}
|
|
|
|
if (i < 0) {
|
|
|
|
mitsu9550_cleanup_job(job);
|
2014-12-11 16:16:56 -05:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2018-06-17 21:08:17 -04:00
|
|
|
}
|
2014-12-11 16:16:56 -05:00
|
|
|
remain -= i;
|
|
|
|
}
|
|
|
|
|
2023-10-04 10:34:47 -04:00
|
|
|
if (buf[1] == 0x5a) {
|
|
|
|
/* We're in the data portion now, bail on header processing */
|
|
|
|
if (ctx->is_98xx && buf[3] == 0x10) {
|
|
|
|
job->is_raw = 1;
|
|
|
|
planelen *= 2;
|
|
|
|
if (job->hdr1.matte)
|
|
|
|
planes ++;
|
|
|
|
} else if (ctx->is_98xx && buf[3] == 0x80) {
|
|
|
|
planelen *= 3;
|
|
|
|
planes = 1;
|
2016-10-13 08:12:20 -04:00
|
|
|
}
|
2023-10-04 10:34:47 -04:00
|
|
|
goto hdr_done;
|
2016-10-13 08:12:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(buf[2]) {
|
|
|
|
case 0x20: /* header 1 */
|
2018-06-15 14:55:03 -04:00
|
|
|
memcpy(&job->hdr1, buf, sizeof(job->hdr1));
|
|
|
|
job->hdr1_present = 1;
|
2016-10-23 09:32:43 -04:00
|
|
|
|
|
|
|
/* Work out printjob size */
|
2018-06-15 14:55:03 -04:00
|
|
|
job->rows = be16_to_cpu(job->hdr1.rows);
|
|
|
|
job->cols = be16_to_cpu(job->hdr1.cols);
|
|
|
|
planelen = job->rows * job->cols;
|
2016-10-23 09:32:43 -04:00
|
|
|
|
2016-10-13 08:12:20 -04:00
|
|
|
break;
|
|
|
|
case 0x21: /* header 2 */
|
2018-06-15 14:55:03 -04:00
|
|
|
memcpy(&job->hdr2, buf, sizeof(job->hdr2));
|
|
|
|
job->hdr2_present = 1;
|
2016-10-13 08:12:20 -04:00
|
|
|
break;
|
|
|
|
case 0x22: /* header 3 */
|
2018-06-15 14:55:03 -04:00
|
|
|
memcpy(&job->hdr3, buf, sizeof(job->hdr3));
|
|
|
|
job->hdr3_present = 1;
|
2016-10-13 08:12:20 -04:00
|
|
|
break;
|
|
|
|
case 0x26: /* header 4 */
|
2018-06-15 14:55:03 -04:00
|
|
|
memcpy(&job->hdr4, buf, sizeof(job->hdr4));
|
|
|
|
job->hdr4_present = 1;
|
2016-10-13 08:12:20 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ERROR("Unrecognized header format (%02x)!\n", buf[2]);
|
2018-06-17 21:08:17 -04:00
|
|
|
mitsu9550_cleanup_job(job);
|
2014-12-11 16:16:56 -05:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
}
|
|
|
|
|
2016-10-13 08:12:20 -04:00
|
|
|
/* Read in the next chunk */
|
|
|
|
goto top;
|
|
|
|
|
|
|
|
hdr_done:
|
|
|
|
|
2023-10-04 10:34:47 -04:00
|
|
|
/* 9550S/9800S doesn't typically sent over hdr4! */
|
2023-10-04 20:12:15 -04:00
|
|
|
if (ctx->conn->type == P_MITSU_9500S ||
|
|
|
|
ctx->conn->type == P_MITSU_9550S ||
|
|
|
|
ctx->conn->type == P_MITSU_9600S ||
|
2023-10-04 10:34:47 -04:00
|
|
|
ctx->conn->type == P_MITSU_9800S ||
|
|
|
|
ctx->conn->type == P_MITSU_9820S) {
|
|
|
|
/* XXX Has to do with error policy, but not sure what.
|
|
|
|
Mitsu9550-S/9800-S will set this based on a command,
|
|
|
|
but it's not part of the standard job spool */
|
|
|
|
job->hdr4_present = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable matte if the printer doesn't support it */
|
|
|
|
if (job->hdr1.matte) {
|
|
|
|
if (ctx->conn->type != P_MITSU_9810 &&
|
|
|
|
ctx->conn->type != P_MITSU_9820S) {
|
|
|
|
WARNING("Matte not supported on this printer, disabling\n");
|
|
|
|
job->hdr1.matte = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-18 20:52:32 -04:00
|
|
|
/* Read in CP98xx data tables if necessary */
|
2018-06-17 22:24:15 -04:00
|
|
|
if (ctx->is_98xx && !job->is_raw && !ctx->m98xxdata) {
|
2020-02-16 16:19:44 -05:00
|
|
|
char full[2048];
|
2020-02-27 11:53:31 -05:00
|
|
|
|
|
|
|
if (!ctx->lib.dl_handle) {
|
|
|
|
ERROR("!!! Image Processing Library not found, aborting!\n");
|
|
|
|
mitsu9550_cleanup_job(job);
|
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
}
|
|
|
|
|
2020-02-16 16:19:44 -05:00
|
|
|
snprintf(full, sizeof(full), "%s/%s", corrtable_path, MITSU_M98xx_DATATABLE_FILE);
|
|
|
|
|
2019-01-13 15:44:29 -05:00
|
|
|
DEBUG("Reading in 98xx data from disk\n");
|
2020-02-16 16:19:44 -05:00
|
|
|
ctx->m98xxdata = ctx->lib.CP98xx_GetData(full);
|
2020-02-08 22:38:27 -05:00
|
|
|
if (!ctx->m98xxdata) {
|
2020-02-17 10:33:37 -05:00
|
|
|
ERROR("Unable to read 98xx data table file '%s'\n", full);
|
2019-03-08 13:59:45 -05:00
|
|
|
}
|
2018-04-18 20:52:32 -04:00
|
|
|
}
|
|
|
|
|
2023-10-04 10:34:47 -04:00
|
|
|
/* Work out the raw job size */
|
|
|
|
remain = planes * (planelen + sizeof(struct mitsu9550_plane)) + (ctx->footer_len * (job->hdr1.matte ? 2 : 1));
|
2018-04-19 08:15:01 -04:00
|
|
|
|
2016-10-23 09:32:43 -04:00
|
|
|
/* Allocate buffer for the payload */
|
2018-06-15 14:55:03 -04:00
|
|
|
job->datalen = 0;
|
|
|
|
job->databuf = malloc(remain);
|
|
|
|
if (!job->databuf) {
|
2014-12-11 16:16:56 -05:00
|
|
|
ERROR("Memory allocation failure!\n");
|
2018-06-17 21:08:17 -04:00
|
|
|
mitsu9550_cleanup_job(job);
|
2018-02-16 10:49:21 -05:00
|
|
|
return CUPS_BACKEND_RETRY_CURRENT;
|
2014-12-11 16:16:56 -05:00
|
|
|
}
|
|
|
|
|
2016-10-23 09:32:43 -04:00
|
|
|
/* Load up the data blocks.*/
|
2023-10-04 10:34:47 -04:00
|
|
|
while(planes--) {
|
2016-10-23 11:59:29 -04:00
|
|
|
/* Note that 'buf' needs to be already filled here! */
|
2016-10-23 09:32:43 -04:00
|
|
|
struct mitsu9550_plane *plane = (struct mitsu9550_plane *)buf;
|
|
|
|
|
|
|
|
/* Sanity check header... */
|
|
|
|
if (plane->cmd[0] != 0x1b ||
|
|
|
|
plane->cmd[1] != 0x5a ||
|
|
|
|
plane->cmd[2] != 0x54) {
|
2020-12-05 16:39:12 -05:00
|
|
|
ERROR("Unrecognized data read @%d (%02x%02x%02x%02x)!\n",
|
|
|
|
job->datalen,
|
2018-05-09 10:47:19 -04:00
|
|
|
plane->cmd[0], plane->cmd[1], plane->cmd[2], plane->cmd[3]);
|
2018-06-17 21:08:17 -04:00
|
|
|
mitsu9550_cleanup_job(job);
|
2016-10-23 09:32:43 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Work out the length of this block */
|
2023-10-04 10:34:47 -04:00
|
|
|
remain = be16_to_cpu(plane->rows) * be16_to_cpu(plane->cols);
|
2016-10-23 09:32:43 -04:00
|
|
|
if (plane->cmd[3] == 0x10)
|
2023-10-04 10:34:47 -04:00
|
|
|
remain *= 2;
|
2018-05-09 11:04:57 -04:00
|
|
|
if (plane->cmd[3] == 0x80)
|
2023-10-04 10:34:47 -04:00
|
|
|
remain *= 3;
|
2016-10-23 09:32:43 -04:00
|
|
|
|
2023-10-04 10:34:47 -04:00
|
|
|
if (planelen != remain) {
|
|
|
|
ERROR("Plane length mismatch! job %d vs plane %d\n", planelen, remain);
|
|
|
|
mitsu9550_cleanup_job(job);
|
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move plane header into job buffer */
|
|
|
|
memcpy(job->databuf + job->datalen, buf, sizeof(struct mitsu9550_plane));
|
|
|
|
job->datalen += sizeof(struct mitsu9550_plane);
|
|
|
|
|
|
|
|
/* Final plane and Matte plane get an additional footer */
|
|
|
|
if (planes == 0 || (planes == 1 && job->hdr1.matte && job->is_raw))
|
|
|
|
remain += ctx->footer_len;
|
2016-10-23 09:32:43 -04:00
|
|
|
|
2023-10-04 10:34:47 -04:00
|
|
|
/* Read in the plane data */
|
|
|
|
while(remain) {
|
|
|
|
i = read(data_fd, |