2013-10-05 09:55:29 -04:00
|
|
|
/*
|
|
|
|
* Mitsubishi CP-D70/D707 Photo Printer CUPS backend -- libusb-1.0 version
|
|
|
|
*
|
2015-01-05 21:39:22 -05:00
|
|
|
* (c) 2013-2015 Solomon Peachy <pizza@shaftnet.org>
|
2013-10-05 09:55:29 -04:00
|
|
|
*
|
|
|
|
* The latest version of this program can be found at:
|
2013-10-05 11:52:37 -04:00
|
|
|
*
|
2013-10-05 09:55:29 -04:00
|
|
|
* http://git.shaftnet.org/cgit/selphy_print.git
|
2013-10-05 11:52:37 -04:00
|
|
|
*
|
2013-10-05 09:55:29 -04:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 3 of the License, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* [http://www.gnu.org/licenses/gpl-3.0.html]
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include "backend_common.h"
|
|
|
|
|
|
|
|
#define USB_VID_MITSU 0x06D3
|
|
|
|
#define USB_PID_MITSU_D70X 0x3B30
|
2014-03-10 14:08:30 -04:00
|
|
|
#define USB_PID_MITSU_K60 0x3B31
|
2014-12-02 23:45:32 -05:00
|
|
|
//#define USB_PID_MITSU_D80 XXXXXX
|
2014-12-25 09:20:50 -05:00
|
|
|
#define USB_VID_KODAK 0x040a
|
|
|
|
#define USB_PID_KODAK305 0x404f
|
2013-10-05 09:55:29 -04:00
|
|
|
|
|
|
|
/* Private data stucture */
|
|
|
|
struct mitsu70x_ctx {
|
|
|
|
struct libusb_device_handle *dev;
|
|
|
|
uint8_t endp_up;
|
|
|
|
uint8_t endp_down;
|
|
|
|
|
|
|
|
uint8_t *databuf;
|
|
|
|
int datalen;
|
2014-10-03 20:30:09 -04:00
|
|
|
|
|
|
|
uint16_t rows;
|
|
|
|
uint16_t cols;
|
|
|
|
|
2014-10-02 19:29:47 -04:00
|
|
|
int k60;
|
2013-10-05 09:55:29 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Program states */
|
|
|
|
enum {
|
|
|
|
S_IDLE = 0,
|
|
|
|
S_SENT_ATTN,
|
2014-10-03 20:30:09 -04:00
|
|
|
S_SENT_HDR,
|
2013-10-05 09:55:29 -04:00
|
|
|
S_SENT_DATA,
|
|
|
|
S_FINISHED,
|
|
|
|
};
|
|
|
|
|
2014-09-19 20:39:04 -04:00
|
|
|
/* Printer data structures */
|
2014-10-03 20:30:09 -04:00
|
|
|
struct mitsu70x_state {
|
|
|
|
uint32_t hdr;
|
|
|
|
uint8_t data[22];
|
2014-10-03 20:35:05 -04:00
|
|
|
} __attribute__((packed));
|
2014-12-29 14:21:39 -05:00
|
|
|
|
2014-09-19 20:39:04 -04:00
|
|
|
struct mitsu70x_status_deck {
|
2014-12-29 18:57:40 -05:00
|
|
|
uint16_t present; /* 0x80 for NOT present, 0x00 otherwise */
|
|
|
|
uint16_t unk[9];
|
|
|
|
uint16_t capacity; /* media capacity */
|
|
|
|
uint16_t remain; /* media remaining */
|
|
|
|
uint16_t unkb[2];
|
|
|
|
uint16_t prints; /* lifetime prints on deck? */
|
|
|
|
uint16_t unkc[1];
|
|
|
|
uint16_t blank[16]; /* All fields are 0x8000 */
|
2014-12-29 14:21:39 -05:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct mitsu70x_status_ver {
|
|
|
|
char ver[6];
|
|
|
|
uint8_t unk[2]; /* checksum? */
|
2014-10-03 20:35:05 -04:00
|
|
|
} __attribute__((packed));
|
2014-12-29 14:21:39 -05:00
|
|
|
|
2014-09-19 20:39:04 -04:00
|
|
|
struct mitsu70x_status_resp {
|
2014-12-29 14:21:39 -05:00
|
|
|
uint8_t hdr[4];
|
|
|
|
uint8_t unk[36];
|
|
|
|
int16_t model[6]; /* LE, UTF-16 */
|
|
|
|
int16_t serno[6]; /* LE, UTF-16 */
|
|
|
|
struct mitsu70x_status_ver vers[7];
|
|
|
|
uint8_t null[8];
|
2014-09-19 20:39:04 -04:00
|
|
|
struct mitsu70x_status_deck lower;
|
|
|
|
struct mitsu70x_status_deck upper;
|
2014-10-03 20:35:05 -04:00
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct mitsu70x_hdr {
|
|
|
|
uint32_t cmd;
|
|
|
|
uint8_t zero0[12];
|
|
|
|
|
|
|
|
uint16_t cols;
|
|
|
|
uint16_t rows;
|
|
|
|
uint16_t lamcols;
|
|
|
|
uint16_t lamrows;
|
|
|
|
uint8_t superfine;
|
|
|
|
uint8_t zero1[7];
|
|
|
|
|
|
|
|
uint8_t deck;
|
|
|
|
uint8_t zero2[7];
|
|
|
|
uint8_t zero3;
|
|
|
|
uint8_t laminate;
|
|
|
|
uint8_t zero4[6];
|
|
|
|
|
|
|
|
uint8_t multicut;
|
|
|
|
uint8_t zero5[15];
|
|
|
|
|
|
|
|
uint8_t zero6[448];
|
|
|
|
} __attribute__((packed));
|
2014-09-19 20:39:04 -04:00
|
|
|
|
2014-10-03 20:30:09 -04:00
|
|
|
#define CMDBUF_LEN 512
|
|
|
|
#define READBACK_LEN 256
|
|
|
|
|
2013-10-05 09:55:29 -04:00
|
|
|
static void *mitsu70x_init(void)
|
|
|
|
{
|
|
|
|
struct mitsu70x_ctx *ctx = malloc(sizeof(struct mitsu70x_ctx));
|
|
|
|
if (!ctx)
|
|
|
|
return NULL;
|
|
|
|
memset(ctx, 0, sizeof(struct mitsu70x_ctx));
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2013-10-05 11:52:37 -04:00
|
|
|
static void mitsu70x_attach(void *vctx, struct libusb_device_handle *dev,
|
|
|
|
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
|
2013-10-05 09:55:29 -04:00
|
|
|
{
|
|
|
|
struct mitsu70x_ctx *ctx = vctx;
|
2014-10-02 19:29:47 -04:00
|
|
|
struct libusb_device *device;
|
|
|
|
struct libusb_device_descriptor desc;
|
2013-10-05 09:55:29 -04:00
|
|
|
|
2013-11-23 19:51:55 -05:00
|
|
|
UNUSED(jobid);
|
|
|
|
|
2013-10-05 11:52:37 -04:00
|
|
|
ctx->dev = dev;
|
2013-10-05 09:55:29 -04:00
|
|
|
ctx->endp_up = endp_up;
|
|
|
|
ctx->endp_down = endp_down;
|
2014-10-02 19:29:47 -04:00
|
|
|
|
|
|
|
device = libusb_get_device(dev);
|
|
|
|
libusb_get_device_descriptor(device, &desc);
|
|
|
|
|
|
|
|
if (desc.idProduct == USB_PID_MITSU_K60)
|
|
|
|
ctx->k60 = 1;
|
2014-12-29 08:39:05 -05:00
|
|
|
|
|
|
|
if (desc.idProduct == USB_PID_KODAK305)
|
|
|
|
ctx->k60 = 1;
|
|
|
|
|
2013-10-05 09:55:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void mitsu70x_teardown(void *vctx) {
|
|
|
|
struct mitsu70x_ctx *ctx = vctx;
|
|
|
|
|
|
|
|
if (!ctx)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (ctx->databuf)
|
|
|
|
free(ctx->databuf);
|
|
|
|
free(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mitsu70x_read_parse(void *vctx, int data_fd) {
|
|
|
|
struct mitsu70x_ctx *ctx = vctx;
|
2014-01-17 22:50:29 -05:00
|
|
|
uint8_t hdr[1024];
|
|
|
|
int i, remain;
|
2014-12-29 18:57:40 -05:00
|
|
|
struct mitsu70x_hdr *mhdr = (struct mitsu70x_hdr*)(hdr + sizeof(struct mitsu70x_hdr));
|
2013-10-05 09:55:29 -04:00
|
|
|
|
|
|
|
if (!ctx)
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-10-05 09:55:29 -04:00
|
|
|
|
2014-01-21 20:34:00 -05:00
|
|
|
if (ctx->databuf) {
|
2014-01-17 22:50:29 -05:00
|
|
|
free(ctx->databuf);
|
2014-01-21 20:34:00 -05:00
|
|
|
ctx->databuf = NULL;
|
|
|
|
}
|
2014-01-17 22:50:29 -05:00
|
|
|
|
|
|
|
/* Read in initial header */
|
|
|
|
remain = sizeof(hdr);
|
|
|
|
while (remain > 0) {
|
|
|
|
i = read(data_fd, hdr + sizeof(hdr) - remain, remain);
|
2014-01-20 19:41:52 -05:00
|
|
|
if (i == 0)
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2014-01-17 22:50:29 -05:00
|
|
|
if (i < 0)
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2014-01-17 22:50:29 -05:00
|
|
|
remain -= i;
|
2014-01-13 18:30:30 -05:00
|
|
|
}
|
2014-01-17 22:50:29 -05:00
|
|
|
|
|
|
|
/* Sanity check */
|
2013-10-05 09:55:29 -04:00
|
|
|
if (hdr[0] != 0x1b ||
|
|
|
|
hdr[1] != 0x45 ||
|
|
|
|
hdr[2] != 0x57 ||
|
|
|
|
hdr[3] != 0x55) {
|
|
|
|
ERROR("Unrecognized data format!\n");
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2013-10-05 09:55:29 -04:00
|
|
|
}
|
|
|
|
|
2014-01-17 22:50:29 -05:00
|
|
|
/* Work out printjob size */
|
2014-12-29 08:54:14 -05:00
|
|
|
ctx->cols = be16_to_cpu(mhdr->cols);
|
|
|
|
ctx->rows = be16_to_cpu(mhdr->rows);
|
2014-10-03 20:30:09 -04:00
|
|
|
|
2014-12-29 08:54:14 -05:00
|
|
|
remain = ctx->rows * ctx->cols * 2;
|
2014-01-17 22:50:29 -05:00
|
|
|
remain = (remain + 511) / 512 * 512; /* Round to nearest 512 bytes. */
|
|
|
|
remain *= 3; /* One for each plane */
|
2014-03-11 15:07:48 -04:00
|
|
|
|
2014-01-17 22:50:29 -05:00
|
|
|
if (mhdr->laminate) {
|
2014-12-29 08:54:14 -05:00
|
|
|
i = be16_to_cpu(mhdr->lamcols) * be16_to_cpu(mhdr->lamrows) * 2;
|
2014-01-17 22:50:29 -05:00
|
|
|
i = (i + 511) / 512 * 512; /* Round to nearest 512 bytes. */
|
|
|
|
remain += i;
|
|
|
|
}
|
|
|
|
|
2014-03-11 15:07:48 -04:00
|
|
|
ctx->databuf = malloc(sizeof(hdr) + remain);
|
2013-10-05 09:55:29 -04:00
|
|
|
if (!ctx->databuf) {
|
|
|
|
ERROR("Memory allocation failure!\n");
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-10-05 09:55:29 -04:00
|
|
|
}
|
|
|
|
|
2014-01-17 22:50:29 -05:00
|
|
|
memcpy(ctx->databuf, &hdr, sizeof(hdr));
|
|
|
|
ctx->datalen += sizeof(hdr);
|
|
|
|
|
|
|
|
/* Read in the spool data */
|
|
|
|
while(remain) {
|
2014-03-11 15:07:48 -04:00
|
|
|
i = read(data_fd, ctx->databuf + ctx->datalen, remain);
|
|
|
|
if (i == 0)
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2014-01-17 22:50:29 -05:00
|
|
|
if (i < 0)
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2014-03-11 15:07:48 -04:00
|
|
|
ctx->datalen += i;
|
2014-01-17 22:50:29 -05:00
|
|
|
remain -= i;
|
|
|
|
}
|
2013-10-05 09:55:29 -04:00
|
|
|
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_OK;
|
2013-10-05 09:55:29 -04:00
|
|
|
}
|
|
|
|
|
2014-10-03 20:30:09 -04:00
|
|
|
static int mitsu70x_do_pagesetup(struct mitsu70x_ctx *ctx)
|
|
|
|
{
|
|
|
|
uint8_t cmdbuf[CMDBUF_LEN];
|
|
|
|
uint8_t rdbuf[READBACK_LEN];
|
|
|
|
|
2014-12-29 08:54:14 -05:00
|
|
|
uint16_t tmp;
|
|
|
|
|
2014-10-03 20:30:09 -04:00
|
|
|
int num, ret;
|
|
|
|
|
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x56;
|
|
|
|
cmdbuf[2] = 0x33;
|
|
|
|
cmdbuf[3] = 0x00;
|
2014-12-29 08:54:14 -05:00
|
|
|
tmp = cpu_to_be16(ctx->cols);
|
|
|
|
memcpy(cmdbuf + 4, &tmp, 2);
|
|
|
|
tmp = cpu_to_be16(ctx->rows);
|
|
|
|
memcpy(cmdbuf + 6, &tmp, 2);
|
2014-10-03 20:30:09 -04:00
|
|
|
cmdbuf[8] = 0x00; // or 0x80??
|
|
|
|
cmdbuf[9] = 0x00;
|
|
|
|
|
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
cmdbuf, 10)))
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
|
|
|
/* Read in the printer status */
|
|
|
|
ret = read_data(ctx->dev, ctx->endp_up,
|
|
|
|
rdbuf, READBACK_LEN, &num);
|
|
|
|
if (ret < 0)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
|
|
|
if (num != 6) {
|
|
|
|
ERROR("Short Read! (%d/%d)\n", num, 26);
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure response is sane */
|
2014-10-03 20:54:23 -04:00
|
|
|
if (rdbuf[0] != 0xe4 ||
|
2014-10-03 20:30:09 -04:00
|
|
|
rdbuf[1] != 0x56 ||
|
2014-10-03 20:52:47 -04:00
|
|
|
rdbuf[2] != 0x33) {
|
2014-10-03 20:30:09 -04:00
|
|
|
ERROR("Unknown response from printer\n");
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mitsu70x_get_state(struct mitsu70x_ctx *ctx, struct mitsu70x_state *resp)
|
|
|
|
{
|
|
|
|
uint8_t cmdbuf[CMDBUF_LEN];
|
|
|
|
int num, ret;
|
|
|
|
|
|
|
|
/* Send Printer Query */
|
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x56;
|
|
|
|
cmdbuf[2] = 0x31;
|
|
|
|
cmdbuf[3] = 0x30;
|
|
|
|
cmdbuf[4] = 0x00;
|
|
|
|
cmdbuf[5] = 0x00;
|
|
|
|
|
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
cmdbuf, 6)))
|
|
|
|
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 0;
|
|
|
|
}
|
2013-10-05 09:55:29 -04:00
|
|
|
|
2014-09-19 20:39:04 -04:00
|
|
|
static int mitsu70x_get_status(struct mitsu70x_ctx *ctx, struct mitsu70x_status_resp *resp)
|
|
|
|
{
|
|
|
|
uint8_t cmdbuf[CMDBUF_LEN];
|
|
|
|
int num, ret;
|
|
|
|
|
|
|
|
/* Send Printer Query */
|
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x1b;
|
|
|
|
cmdbuf[1] = 0x56;
|
|
|
|
cmdbuf[2] = 0x32;
|
|
|
|
cmdbuf[3] = 0x30;
|
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
cmdbuf, 4)))
|
|
|
|
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 0;
|
|
|
|
}
|
|
|
|
|
2013-10-05 09:55:29 -04:00
|
|
|
static int mitsu70x_main_loop(void *vctx, int copies) {
|
|
|
|
struct mitsu70x_ctx *ctx = vctx;
|
|
|
|
|
2014-10-03 20:30:09 -04:00
|
|
|
struct mitsu70x_state rdbuf, rdbuf2;
|
2013-10-05 09:55:29 -04:00
|
|
|
|
|
|
|
int last_state = -1, state = S_IDLE;
|
2014-10-03 20:30:09 -04:00
|
|
|
int ret;
|
2013-10-05 09:55:29 -04:00
|
|
|
|
|
|
|
if (!ctx)
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-10-05 09:55:29 -04:00
|
|
|
|
|
|
|
top:
|
|
|
|
if (state != last_state) {
|
2013-12-21 22:15:18 -05:00
|
|
|
if (dyesub_debug)
|
|
|
|
DEBUG("last_state %d new %d\n", last_state, state);
|
2013-10-05 09:55:29 -04:00
|
|
|
}
|
|
|
|
|
2014-10-03 20:30:09 -04:00
|
|
|
ret = mitsu70x_get_state(ctx, &rdbuf);
|
|
|
|
if (ret)
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2014-03-12 10:53:26 -04:00
|
|
|
|
2014-10-03 20:30:09 -04:00
|
|
|
if (memcmp(&rdbuf, &rdbuf2, sizeof(rdbuf))) {
|
|
|
|
memcpy(&rdbuf2, &rdbuf, sizeof(rdbuf));
|
2013-10-05 09:55:29 -04:00
|
|
|
} else if (state == last_state) {
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
last_state = state;
|
|
|
|
|
2013-10-05 11:52:37 -04:00
|
|
|
fflush(stderr);
|
2013-10-05 09:55:29 -04:00
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case S_IDLE:
|
|
|
|
INFO("Waiting for printer idle\n");
|
2014-10-03 21:32:40 -04:00
|
|
|
#if 0 // XXX no idea if this works..
|
2014-10-03 20:52:47 -04:00
|
|
|
if (rdbuf.data[9] != 0x00) {
|
2013-10-05 09:55:29 -04:00
|
|
|
break;
|
|
|
|
}
|
2014-10-03 21:32:40 -04:00
|
|
|
#endif
|
2013-10-05 09:55:29 -04:00
|
|
|
INFO("Sending attention sequence\n");
|
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
2014-12-29 18:57:40 -05:00
|
|
|
ctx->databuf, sizeof(struct mitsu70x_hdr))))
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2014-10-03 20:30:09 -04:00
|
|
|
|
2013-10-05 09:55:29 -04:00
|
|
|
state = S_SENT_ATTN;
|
2014-09-19 20:39:04 -04:00
|
|
|
break;
|
2014-10-03 20:30:09 -04:00
|
|
|
case S_SENT_ATTN: {
|
|
|
|
struct mitsu70x_status_resp resp;
|
|
|
|
ret = mitsu70x_get_status(ctx, &resp);
|
2014-07-30 20:40:31 -04:00
|
|
|
if (ret < 0)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
2014-10-03 20:30:09 -04:00
|
|
|
/* Yes, do it twice.. */
|
2014-07-30 20:40:31 -04:00
|
|
|
|
2014-09-19 20:39:04 -04:00
|
|
|
ret = mitsu70x_get_status(ctx, &resp);
|
|
|
|
if (ret < 0)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
|
|
|
// XXX check resp for sanity?
|
|
|
|
|
2014-10-03 20:30:09 -04:00
|
|
|
state = S_SENT_HDR;
|
2014-09-19 20:39:04 -04:00
|
|
|
break;
|
|
|
|
}
|
2014-10-03 20:30:09 -04:00
|
|
|
case S_SENT_HDR:
|
|
|
|
INFO("Sending Page setup sequence\n");
|
|
|
|
if ((ret = mitsu70x_do_pagesetup(ctx)))
|
|
|
|
return ret;
|
|
|
|
|
2013-10-05 09:55:29 -04:00
|
|
|
INFO("Sending header sequence\n");
|
|
|
|
|
2014-10-02 19:29:47 -04:00
|
|
|
/* K60 may require fixups */
|
|
|
|
if (ctx->k60) {
|
2014-12-29 18:57:40 -05:00
|
|
|
struct mitsu70x_hdr *hdr = (struct mitsu70x_hdr*) (ctx->databuf + sizeof(struct mitsu70x_hdr));
|
2014-10-02 19:29:47 -04:00
|
|
|
/* K60 only has a lower deck */
|
2014-12-29 15:52:55 -05:00
|
|
|
hdr->deck = 1;
|
2014-10-02 19:29:47 -04:00
|
|
|
|
|
|
|
/* 4x6 prints on 6x8 media need multicut mode */
|
2014-12-29 08:54:14 -05:00
|
|
|
if (ctx->cols == 0x0748 &&
|
|
|
|
ctx->rows == 0x04c2)
|
2014-12-29 15:52:55 -05:00
|
|
|
hdr->multicut = 1;
|
2014-10-02 19:29:47 -04:00
|
|
|
}
|
|
|
|
|
2013-10-05 09:55:29 -04:00
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
2014-12-29 18:57:40 -05:00
|
|
|
ctx->databuf + sizeof(struct mitsu70x_hdr),
|
|
|
|
sizeof(struct mitsu70x_hdr))))
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2014-09-19 20:39:04 -04:00
|
|
|
|
2013-10-05 09:55:29 -04:00
|
|
|
INFO("Sending data\n");
|
|
|
|
|
2014-12-29 15:38:34 -05:00
|
|
|
{
|
2014-12-29 08:39:31 -05:00
|
|
|
/* K60 and 305 need data sent in 256K chunks, but the first
|
|
|
|
chunk needs to subtract the length of the 512-byte header */
|
2014-12-29 18:57:40 -05:00
|
|
|
int chunk = 256*1024 - sizeof(struct mitsu70x_hdr);
|
2014-12-29 08:39:31 -05:00
|
|
|
int sent = 1024;
|
|
|
|
while (ctx->datalen > 0) {
|
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
ctx->databuf + sent, chunk)))
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
sent += chunk;
|
|
|
|
chunk = ctx->datalen - sent;
|
|
|
|
if (chunk > 256*1024)
|
|
|
|
chunk = 256*1024;
|
|
|
|
}
|
|
|
|
}
|
2014-04-25 11:38:01 -04:00
|
|
|
|
2013-10-05 09:55:29 -04:00
|
|
|
state = S_SENT_DATA;
|
|
|
|
break;
|
|
|
|
case S_SENT_DATA:
|
|
|
|
INFO("Waiting for printer to acknowledge completion\n");
|
|
|
|
|
|
|
|
state = S_FINISHED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (state != S_FINISHED)
|
|
|
|
goto top;
|
|
|
|
|
|
|
|
/* Clean up */
|
|
|
|
if (terminate)
|
|
|
|
copies = 1;
|
|
|
|
|
2014-01-22 09:10:34 -05:00
|
|
|
INFO("Print complete (%d copies remaining)\n", copies - 1);
|
2013-10-05 09:55:29 -04:00
|
|
|
|
|
|
|
if (copies && --copies) {
|
|
|
|
state = S_IDLE;
|
|
|
|
goto top;
|
|
|
|
}
|
|
|
|
|
2014-04-25 11:38:01 -04:00
|
|
|
return CUPS_BACKEND_OK;
|
2013-10-05 09:55:29 -04:00
|
|
|
}
|
|
|
|
|
2014-09-19 20:39:04 -04:00
|
|
|
static void mitsu70x_dump_status(struct mitsu70x_status_resp *resp)
|
2013-10-05 11:52:37 -04:00
|
|
|
{
|
2014-12-29 14:21:39 -05:00
|
|
|
unsigned int i;
|
2015-01-10 17:42:34 -05:00
|
|
|
|
2014-12-29 14:21:39 -05:00
|
|
|
INFO("Model : ");
|
|
|
|
for (i = 0 ; i < 6 ; i++) {
|
2014-12-30 09:51:58 -05:00
|
|
|
DEBUG2("%c", le16_to_cpu(resp->model[i]) & 0x7f);
|
2014-12-29 14:21:39 -05:00
|
|
|
}
|
|
|
|
DEBUG2("\n");
|
|
|
|
INFO("Serial Number : ");
|
|
|
|
for (i = 0 ; i < 6 ; i++) {
|
2014-12-30 09:51:58 -05:00
|
|
|
DEBUG2("%c", le16_to_cpu(resp->serno[i]) & 0x7f);
|
2014-12-29 14:21:39 -05:00
|
|
|
}
|
|
|
|
DEBUG2("\n");
|
2014-12-29 16:04:08 -05:00
|
|
|
for (i = 0 ; i < 7 ; i++) {
|
|
|
|
char buf[7];
|
|
|
|
if (resp->vers[i].ver[5] == '@') /* "DUMMY@" */
|
|
|
|
continue;
|
|
|
|
memcpy(buf, resp->vers[i].ver, 6);
|
|
|
|
buf[6] = 0;
|
2014-12-30 09:51:58 -05:00
|
|
|
INFO("Component #%d ID: %s (%02x%02x)\n",
|
2014-12-29 16:04:08 -05:00
|
|
|
i, buf, resp->vers[i].unk[0], resp->vers[i].unk[1]);
|
|
|
|
}
|
2014-12-29 18:57:40 -05:00
|
|
|
if (resp->upper.present) { /* IOW, Not present */
|
|
|
|
INFO("Prints remaining: %03d/%03d\n",
|
|
|
|
be16_to_cpu(resp->lower.remain),
|
|
|
|
be16_to_cpu(resp->lower.capacity));
|
2014-03-11 14:34:07 -04:00
|
|
|
} else {
|
2014-12-29 18:57:40 -05:00
|
|
|
INFO("Prints remaining: Lower: %03d/%03d\n"
|
|
|
|
" Upper: %03d/%03d\n",
|
2014-09-19 20:39:04 -04:00
|
|
|
be16_to_cpu(resp->lower.remain),
|
2014-12-29 18:57:40 -05:00
|
|
|
be16_to_cpu(resp->lower.capacity),
|
|
|
|
be16_to_cpu(resp->upper.remain),
|
|
|
|
be16_to_cpu(resp->upper.capacity));
|
2014-03-11 14:34:07 -04:00
|
|
|
}
|
2014-09-19 20:39:04 -04:00
|
|
|
}
|
2013-10-05 11:52:37 -04:00
|
|
|
|
2014-09-19 20:39:04 -04:00
|
|
|
static int mitsu70x_query_status(struct mitsu70x_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct mitsu70x_status_resp resp;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = mitsu70x_get_status(ctx, &resp);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
mitsu70x_dump_status(&resp);
|
|
|
|
|
|
|
|
return ret;
|
2013-10-05 11:52:37 -04:00
|
|
|
}
|
|
|
|
|
2014-12-29 14:21:39 -05:00
|
|
|
static int mitsu70x_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, char *buf, int buf_len)
|
|
|
|
{
|
|
|
|
int ret, i;
|
|
|
|
struct mitsu70x_status_resp resp;
|
|
|
|
|
|
|
|
struct mitsu70x_ctx ctx = {
|
|
|
|
.dev = dev,
|
|
|
|
.endp_up = endp_up,
|
|
|
|
.endp_down = endp_down,
|
|
|
|
};
|
|
|
|
|
|
|
|
ret = mitsu70x_get_status(&ctx, &resp);
|
|
|
|
|
|
|
|
if (buf_len > 6) /* Will we ever have a buffer under 6 bytes? */
|
|
|
|
buf_len = 6;
|
|
|
|
|
|
|
|
for (i = 0 ; i < buf_len ; i++) {
|
2014-12-30 09:51:58 -05:00
|
|
|
*buf++ = le16_to_cpu(resp.serno[i]) & 0x7f;
|
2014-12-29 14:21:39 -05:00
|
|
|
}
|
|
|
|
*buf = 0; /* Null-terminate the returned string */
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-10 20:10:36 -05:00
|
|
|
static void mitsu70x_cmdline(void)
|
2013-10-05 11:52:37 -04:00
|
|
|
{
|
2014-02-10 20:10:36 -05:00
|
|
|
DEBUG("\t\t[ -s ] # Query status\n");
|
2013-10-05 11:52:37 -04:00
|
|
|
}
|
|
|
|
|
2014-02-10 20:10:36 -05:00
|
|
|
static int mitsu70x_cmdline_arg(void *vctx, int argc, char **argv)
|
2013-10-05 11:52:37 -04:00
|
|
|
{
|
|
|
|
struct mitsu70x_ctx *ctx = vctx;
|
2014-02-11 22:45:14 -05:00
|
|
|
int i, j = 0;
|
2014-02-10 20:10:36 -05:00
|
|
|
|
|
|
|
/* Reset arg parsing */
|
|
|
|
optind = 1;
|
|
|
|
opterr = 0;
|
|
|
|
while ((i = getopt(argc, argv, "s")) >= 0) {
|
|
|
|
switch(i) {
|
|
|
|
case 's':
|
2014-02-11 22:45:14 -05:00
|
|
|
if (ctx) {
|
2014-09-19 20:39:04 -04:00
|
|
|
j = mitsu70x_query_status(ctx);
|
2014-02-11 22:45:14 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
2014-02-10 20:10:36 -05:00
|
|
|
default:
|
|
|
|
break; /* Ignore completely */
|
|
|
|
}
|
2014-02-11 22:45:14 -05:00
|
|
|
|
|
|
|
if (j) return j;
|
2014-02-10 20:10:36 -05:00
|
|
|
}
|
2013-10-05 11:52:37 -04:00
|
|
|
|
2014-02-10 20:10:36 -05:00
|
|
|
return 0;
|
2013-10-05 11:52:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-05 09:55:29 -04:00
|
|
|
/* Exported */
|
|
|
|
struct dyesub_backend mitsu70x_backend = {
|
2014-03-10 14:08:30 -04:00
|
|
|
.name = "Mitsubishi CP-D70/D707/K60",
|
2014-12-30 09:51:58 -05:00
|
|
|
.version = "0.31",
|
2013-10-05 09:55:29 -04:00
|
|
|
.uri_prefix = "mitsu70x",
|
2013-10-05 11:52:37 -04:00
|
|
|
.cmdline_usage = mitsu70x_cmdline,
|
|
|
|
.cmdline_arg = mitsu70x_cmdline_arg,
|
2013-10-05 09:55:29 -04:00
|
|
|
.init = mitsu70x_init,
|
|
|
|
.attach = mitsu70x_attach,
|
|
|
|
.teardown = mitsu70x_teardown,
|
|
|
|
.read_parse = mitsu70x_read_parse,
|
|
|
|
.main_loop = mitsu70x_main_loop,
|
2014-12-29 14:21:39 -05:00
|
|
|
.query_serno = mitsu70x_query_serno,
|
2013-10-05 11:52:37 -04:00
|
|
|
.devices = {
|
2014-03-11 14:34:07 -04:00
|
|
|
{ USB_VID_MITSU, USB_PID_MITSU_D70X, P_MITSU_D70X, ""},
|
|
|
|
{ USB_VID_MITSU, USB_PID_MITSU_K60, P_MITSU_D70X, ""},
|
2014-12-02 23:45:32 -05:00
|
|
|
// { USB_VID_MITSU, USB_PID_MITSU_D80, P_MITSU_D70X, ""},
|
2014-12-25 09:20:50 -05:00
|
|
|
{ USB_VID_KODAK, USB_PID_KODAK305, P_MITSU_D70X, ""},
|
2013-10-05 09:55:29 -04:00
|
|
|
{ 0, 0, 0, ""}
|
|
|
|
}
|
|
|
|
};
|
2013-10-07 15:15:23 -04:00
|
|
|
|
2014-12-29 14:21:39 -05:00
|
|
|
/* Mitsubish CP-D70DW/CP-D707DW/CP-K60DW-S/CP-D80DW/Kodak 305 data format
|
2013-10-07 15:15:23 -04:00
|
|
|
|
|
|
|
Spool file consists of two headers followed by three image planes
|
|
|
|
and an optional lamination data plane. All blocks are rounded up to
|
|
|
|
a 512-byte boundary.
|
|
|
|
|
|
|
|
All multi-byte numbers are big endian, ie MSB first.
|
|
|
|
|
|
|
|
Header 1: (Init)
|
|
|
|
|
|
|
|
1b 45 57 55 00 00 00 00 00 00 00 00 00 00 00 00
|
|
|
|
(padded by NULLs to a 512-byte boundary)
|
|
|
|
|
2014-12-29 14:21:39 -05:00
|
|
|
Header 2: (Header)
|
2013-10-07 15:15:23 -04:00
|
|
|
|
2014-12-29 14:21:39 -05:00
|
|
|
1b 5a 54 PP 00 00 00 00 00 00 00 00 00 00 00 00
|
2013-10-07 15:15:23 -04:00
|
|
|
XX XX YY YY QQ QQ ZZ ZZ SS 00 00 00 00 00 00 00
|
2013-11-24 10:17:08 -05:00
|
|
|
UU 00 00 00 00 00 00 00 00 TT 00 00 00 00 00 00
|
2014-03-11 18:44:58 -04:00
|
|
|
RR 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
|
|
|
|
|
2013-10-07 15:15:23 -04:00
|
|
|
(padded by NULLs to a 512-byte boundary)
|
|
|
|
|
2014-12-29 14:21:39 -05:00
|
|
|
PP == 0x01 on D70x/D80, 0x02 on K60/305
|
2013-10-07 15:15:23 -04:00
|
|
|
XX XX == columns
|
|
|
|
YY YY == rows
|
|
|
|
QQ QQ == lamination columns (equal to XX XX)
|
|
|
|
ZZ ZZ == lamination rows (YY YY + 12)
|
2014-12-29 14:21:39 -05:00
|
|
|
SS == Print mode: 00 = Fine, 03 = SuperFine (D70x/D80 only), 04 = UltraFine
|
2014-03-11 18:44:58 -04:00
|
|
|
(Matte requires Superfine or Ultrafine)
|
2014-12-29 14:21:39 -05:00
|
|
|
UU == 00 = Auto, 01 = Lower Deck (required for K60/305), 02 = Upper Deck
|
|
|
|
TT == lamination: 00 glossy, 02 matte.
|
|
|
|
RR == 00 (normal), 01 = (Double-cut 4x6), 05 = (double-cut 2x6)
|
2013-10-07 15:15:23 -04:00
|
|
|
|
|
|
|
Data planes:
|
|
|
|
16-bit data, rounded up to 512-byte block (XX * YY * 2 bytes)
|
|
|
|
|
2014-12-29 14:21:39 -05:00
|
|
|
Lamination plane: (only present if QQ and ZZ are nonzero)
|
2013-10-07 15:15:23 -04:00
|
|
|
16-byte data, rounded up to 512-byte block (QQ * ZZ * 2 bytes)
|
|
|
|
|
|
|
|
********************************************************************
|
|
|
|
|
2014-12-29 14:21:39 -05:00
|
|
|
Command format:
|
2013-10-07 15:15:23 -04:00
|
|
|
|
|
|
|
-> 1b 56 32 30
|
2014-03-11 14:34:07 -04:00
|
|
|
<- [256 byte payload]
|
2013-10-07 15:15:23 -04:00
|
|
|
|
2014-12-29 18:57:40 -05:00
|
|
|
PRINTER STATUS
|
2014-03-11 18:44:58 -04:00
|
|
|
|
|
|
|
e4 56 32 30 00 00 00 00 00 00 00 00 00 00 00 00 .V20............
|
|
|
|
00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 00 ................
|
|
|
|
44 80 00 00 5f 00 00 3d 43 00 50 00 44 00 37 00 D..._..=C.P.D.7.
|
|
|
|
30 00 44 00 30 00 30 00 31 00 31 00 31 00 37 00 0.D.0.0.1.1.1.7.
|
|
|
|
33 31 36 54 31 33 21 a3 33 31 35 42 31 32 f5 e5 316T13!.315B12..
|
|
|
|
33 31 39 42 31 31 a3 fb 33 31 38 45 31 32 50 0d 319B11..318E12P.
|
|
|
|
33 31 37 41 32 32 a3 82 44 55 4d 4d 59 40 00 00 317A22..DUMMY@..
|
|
|
|
44 55 4d 4d 59 40 00 00 00 00 00 00 00 00 00 00 DUMMY@..........
|
|
|
|
|
2014-12-29 18:57:40 -05:00
|
|
|
LOWER DECK STATUS
|
2013-10-07 15:15:23 -04:00
|
|
|
|
2014-12-29 18:57:40 -05:00
|
|
|
00 00 00 00 00 00 02 04 3f 00 00 04 96 00 00 00 MM MM: media capacity
|
|
|
|
ff 0f 01 00 MM MM NN NN 00 00 00 00 05 28 75 80 NN NN: prints remaining
|
2014-03-11 18:44:58 -04:00
|
|
|
80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00
|
|
|
|
80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00
|
2013-10-07 15:15:23 -04:00
|
|
|
|
2014-12-29 18:57:40 -05:00
|
|
|
alt (some sort of error state)
|
2014-10-03 20:30:09 -04:00
|
|
|
|
|
|
|
00 00 00 0a 05 05 01 d5 38 00 00 00 14 00 00 00
|
|
|
|
ff ff ff ff ff ff ff ff ff ff 00 00 00 27 72 80
|
|
|
|
80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00
|
|
|
|
80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00
|
|
|
|
|
2014-12-29 18:57:40 -05:00
|
|
|
UPPER DECK STATUS (if present)
|
2014-03-11 14:34:07 -04:00
|
|
|
|
2014-12-29 18:57:40 -05:00
|
|
|
XX XX 00 00 00 00 01 ee 3d 00 00 06 39 00 00 00 MM MM: media capacity
|
|
|
|
ff 02 00 00 MM MM NN NN 00 00 00 00 06 67 78 00 NN NN: prints remaining
|
|
|
|
80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00 XX XX: 0x80 00 if no deck
|
2014-03-11 18:44:58 -04:00
|
|
|
80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00
|
2013-10-07 15:15:23 -04:00
|
|
|
|
2014-12-29 18:57:40 -05:00
|
|
|
alt (no deck present)
|
2014-03-11 14:34:07 -04:00
|
|
|
|
2014-03-11 18:44:58 -04:00
|
|
|
80 00 00 00 00 00 00 ff ff 00 00 00 00 00 00 00
|
|
|
|
ff ff ff ff ff ff ff ff ff ff 00 00 00 00 80 00
|
|
|
|
80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00
|
|
|
|
80 00 80 00 80 00 80 00 80 00 80 00 80 00 80 00
|
2014-03-11 14:34:07 -04:00
|
|
|
|
2013-10-07 15:15:23 -04:00
|
|
|
-> 1b 56 31 30 00 00
|
|
|
|
<- [26 byte payload]
|
|
|
|
|
2014-03-11 18:44:58 -04:00
|
|
|
CP-D707DW:
|
|
|
|
|
2014-07-30 20:40:31 -04:00
|
|
|
e4 56 31 30 00 00 00 XX YY ZZ 00 00 TT 00 00 00
|
|
|
|
00 00 00 00 WW 00 00 00 00 00
|
2014-03-11 18:44:58 -04:00
|
|
|
|
2014-10-03 20:52:47 -04:00
|
|
|
XX/YY/ZZ and WW/TT are unknown. Observed values:
|
|
|
|
|
|
|
|
00 00 00 00/00
|
|
|
|
40 80 a0 80/0f
|
|
|
|
80 80 a0
|
|
|
|
40 80 90
|
|
|
|
40 80 00
|
|
|
|
|
|
|
|
also seen:
|
|
|
|
|
2014-10-03 20:30:09 -04:00
|
|
|
e4 56 31 30 00 00 00 00 00 00 00 00 0f 00 00 00
|
|
|
|
00 0a 05 05 80 00 00 00 00 00
|
|
|
|
|
|
|
|
e4 56 31 30 00 00 00 40 80 90 10 00 0f 00 00 00
|
|
|
|
00 0a 05 05 80 00 00 00 00 00
|
|
|
|
|
2014-10-03 21:32:40 -04:00
|
|
|
e4 56 31 30 00 00 00 00 40 80 00 00 00 ff 40 00
|
|
|
|
00 00 00 00 80 00 00 00 00 00
|
|
|
|
|
2014-10-03 20:52:47 -04:00
|
|
|
print just submitted:
|
2014-10-03 20:30:09 -04:00
|
|
|
|
2014-10-03 20:52:47 -04:00
|
|
|
e4 56 31 30 00 00 00 00 40 20 00 00 00 8c 00 00
|
|
|
|
00 00 00 00 80 00 00 00 00 00
|
2014-03-11 18:44:58 -04:00
|
|
|
|
2014-10-03 21:32:40 -04:00
|
|
|
prints running...
|
|
|
|
|
|
|
|
e4 56 31 30 00 00 00 00 40 20 00 00 00 cf 00 20
|
|
|
|
00 00 00 00 80 00 00 00 00 00
|
|
|
|
|
|