2013-07-14 15:55:35 -04:00
|
|
|
/*
|
2013-07-18 23:00:58 -04:00
|
|
|
* Sony UP-DR150 Photo Printer CUPS backend -- libusb-1.0 version
|
2013-07-14 15:55:35 -04:00
|
|
|
*
|
2018-02-22 06:02:49 -05:00
|
|
|
* (c) 2013-2018 Solomon Peachy <pizza@shaftnet.org>
|
2013-07-14 15:55:35 -04:00
|
|
|
*
|
|
|
|
* The latest version of this program can be found at:
|
2014-01-13 05:41:48 -05:00
|
|
|
*
|
2013-08-20 20:10:21 -04:00
|
|
|
* http://git.shaftnet.org/cgit/selphy_print.git
|
2014-01-13 05:41:48 -05:00
|
|
|
*
|
2013-07-14 15:55:35 -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]
|
|
|
|
*
|
2017-11-17 13:34:26 -05:00
|
|
|
* SPDX-License-Identifier: GPL-3.0+
|
|
|
|
*
|
2013-07-14 15:55:35 -04: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 updr150_backend
|
|
|
|
|
2013-07-18 08:46:44 -04:00
|
|
|
#include "backend_common.h"
|
2013-07-14 15:55:35 -04:00
|
|
|
|
2019-03-15 22:57:13 -04:00
|
|
|
/* Printer status
|
|
|
|
--> 1b e0 00 00 00 00 XX 00 [[ XX is 0xe on UPD895, 0xf on others ]]
|
|
|
|
<-- this struct
|
|
|
|
*/
|
|
|
|
struct sony_updsts {
|
|
|
|
uint8_t hdr[2]; /* 0x0d 0x00 */
|
2019-03-17 13:15:27 -04:00
|
|
|
uint8_t printing; /* 0xe0 if printing, 0x00 otherwise */
|
2019-03-15 22:57:13 -04:00
|
|
|
uint8_t remain; /* Number of remaining pages */
|
|
|
|
uint8_t zero1;
|
|
|
|
uint8_t sts1; /* primary status */
|
|
|
|
uint8_t sts2; /* seconday status */
|
|
|
|
uint8_t sts3; /* tertiary status */
|
|
|
|
uint8_t zero2[2];
|
|
|
|
uint16_t max_cols; /* BE */
|
|
|
|
uint16_t max_rows; /* BE */
|
|
|
|
uint8_t percent; /* 0-99, if job is printing */
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2019-03-17 13:15:27 -04:00
|
|
|
/* Private data structures */
|
2018-06-15 14:55:03 -04:00
|
|
|
struct updr150_printjob {
|
|
|
|
uint8_t *databuf;
|
|
|
|
int datalen;
|
2019-03-17 13:15:27 -04:00
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
int copies;
|
2019-03-17 13:15:27 -04:00
|
|
|
uint16_t rows;
|
|
|
|
uint16_t cols;
|
|
|
|
uint32_t imglen;
|
2018-06-15 14:55:03 -04:00
|
|
|
};
|
|
|
|
|
2013-07-18 08:46:44 -04:00
|
|
|
struct updr150_ctx {
|
2013-07-14 15:55:35 -04:00
|
|
|
struct libusb_device_handle *dev;
|
2013-07-18 08:46:44 -04:00
|
|
|
uint8_t endp_up;
|
|
|
|
uint8_t endp_down;
|
2015-08-12 22:56:29 -04:00
|
|
|
int type;
|
2013-07-14 15:55:35 -04:00
|
|
|
|
2019-03-17 13:15:27 -04:00
|
|
|
int native_bpp;
|
|
|
|
|
|
|
|
struct sony_updsts stsbuf;
|
2019-03-10 17:03:07 -04:00
|
|
|
|
2018-04-29 14:07:08 -04:00
|
|
|
struct marker marker;
|
2013-07-18 08:46:44 -04:00
|
|
|
};
|
2013-07-14 15:55:35 -04:00
|
|
|
|
2019-03-17 13:15:27 -04:00
|
|
|
/* Now for the code */
|
2013-07-19 09:23:53 -04:00
|
|
|
static void* updr150_init(void)
|
2013-07-18 08:46:44 -04:00
|
|
|
{
|
|
|
|
struct updr150_ctx *ctx = malloc(sizeof(struct updr150_ctx));
|
2015-06-23 20:32:41 -04:00
|
|
|
if (!ctx) {
|
|
|
|
ERROR("Memory Allocation Failure!");
|
2013-07-18 08:46:44 -04:00
|
|
|
return NULL;
|
2015-06-23 20:32:41 -04:00
|
|
|
}
|
2013-07-18 08:46:44 -04:00
|
|
|
memset(ctx, 0, sizeof(struct updr150_ctx));
|
2013-07-19 09:23:53 -04:00
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
2018-05-09 23:09:01 -04:00
|
|
|
static int updr150_attach(void *vctx, struct libusb_device_handle *dev, int type,
|
2018-04-27 15:07:43 -04:00
|
|
|
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
|
2013-07-19 09:23:53 -04:00
|
|
|
{
|
|
|
|
struct updr150_ctx *ctx = vctx;
|
|
|
|
|
2013-11-23 19:51:55 -05:00
|
|
|
UNUSED(jobid);
|
|
|
|
|
2013-07-19 09:23:53 -04:00
|
|
|
ctx->dev = dev;
|
2013-07-18 08:46:44 -04:00
|
|
|
ctx->endp_up = endp_up;
|
|
|
|
ctx->endp_down = endp_down;
|
2018-05-09 23:09:01 -04:00
|
|
|
ctx->type = type;
|
2014-04-25 11:39:15 -04:00
|
|
|
|
2019-03-17 13:15:27 -04:00
|
|
|
if (ctx->type == P_SONY_UPD895 || ctx->type == P_SONY_UPD897) {
|
2019-03-10 17:03:07 -04:00
|
|
|
ctx->marker.color = "#000000"; /* Ie black! */
|
2019-03-17 13:15:27 -04:00
|
|
|
ctx->native_bpp = 1;
|
|
|
|
} else {
|
2019-03-10 17:03:07 -04:00
|
|
|
ctx->marker.color = "#00FFFF#FF00FF#FFFF00";
|
2019-03-17 13:15:27 -04:00
|
|
|
ctx->native_bpp = 3;
|
|
|
|
}
|
2019-03-10 17:03:07 -04:00
|
|
|
|
2018-04-29 14:07:08 -04:00
|
|
|
ctx->marker.name = "Unknown";
|
|
|
|
ctx->marker.levelmax = -1;
|
|
|
|
ctx->marker.levelnow = -2;
|
|
|
|
|
2018-04-27 15:07:43 -04:00
|
|
|
return CUPS_BACKEND_OK;
|
2013-07-18 08:46:44 -04:00
|
|
|
}
|
2013-07-14 15:55:35 -04:00
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
static void updr150_cleanup_job(const void *vjob)
|
|
|
|
{
|
|
|
|
const struct updr150_printjob *job = vjob;
|
|
|
|
|
|
|
|
if (job->databuf)
|
|
|
|
free(job->databuf);
|
|
|
|
|
|
|
|
free((void*)job);
|
|
|
|
}
|
|
|
|
|
2013-07-18 08:46:44 -04:00
|
|
|
static void updr150_teardown(void *vctx) {
|
|
|
|
struct updr150_ctx *ctx = vctx;
|
2013-07-14 15:55:35 -04:00
|
|
|
|
2013-07-18 08:46:44 -04:00
|
|
|
if (!ctx)
|
|
|
|
return;
|
2013-07-14 15:55:35 -04:00
|
|
|
|
2013-07-18 08:46:44 -04:00
|
|
|
free(ctx);
|
|
|
|
}
|
2013-07-17 19:47:47 -04:00
|
|
|
|
2019-03-10 17:03:07 -04:00
|
|
|
static char* upd895_statuses(uint8_t code)
|
|
|
|
{
|
|
|
|
switch (code) {
|
|
|
|
case 0x00:
|
|
|
|
return "Idle";
|
|
|
|
case 0x08:
|
|
|
|
return "Door open";
|
|
|
|
case 0x40:
|
|
|
|
return "No paper";
|
|
|
|
case 0x80:
|
|
|
|
return "Idle";
|
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-17 13:15:27 -04:00
|
|
|
static int sony_get_status(struct updr150_ctx *ctx, struct sony_updsts *buf)
|
2019-03-10 17:03:07 -04:00
|
|
|
{
|
|
|
|
int ret, num = 0;
|
|
|
|
uint8_t query[7] = { 0x1b, 0xe0, 0, 0, 0, 0x0e, 0 };
|
|
|
|
|
2019-03-15 22:57:13 -04:00
|
|
|
if (ctx->type != P_SONY_UPD895)
|
|
|
|
query[5] = 0x0f;
|
|
|
|
|
2019-03-10 17:03:07 -04:00
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
query, sizeof(query))))
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
2019-03-17 13:15:27 -04:00
|
|
|
ret = read_data(ctx->dev, ctx->endp_up, (uint8_t*) buf, sizeof(*buf),
|
|
|
|
&num);
|
2019-03-10 17:03:07 -04:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
2019-03-15 22:57:13 -04:00
|
|
|
#if 0
|
|
|
|
if (ctx->type == P_SONY_UPD895 && ret != 14)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
else if (ret != 15)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
#endif
|
2019-03-10 17:03:07 -04:00
|
|
|
|
|
|
|
return CUPS_BACKEND_OK;
|
|
|
|
}
|
|
|
|
|
2018-09-29 20:50:37 -04:00
|
|
|
#define MAX_PRINTJOB_LEN (2048*2764*3 + 2048)
|
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
static int updr150_read_parse(void *vctx, const void **vjob, int data_fd, int copies) {
|
2013-07-18 08:46:44 -04:00
|
|
|
struct updr150_ctx *ctx = vctx;
|
2014-02-11 13:41:15 -05:00
|
|
|
int len, run = 1;
|
2018-06-15 14:55:03 -04:00
|
|
|
uint32_t copies_offset = 0;
|
|
|
|
|
|
|
|
struct updr150_printjob *job = NULL;
|
2013-07-14 15:55:35 -04:00
|
|
|
|
2013-07-18 08:46:44 -04:00
|
|
|
if (!ctx)
|
2014-04-25 11:41:35 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-07-14 15:55:35 -04:00
|
|
|
|
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-01-21 20:34:00 -05:00
|
|
|
}
|
2018-06-15 14:55:03 -04:00
|
|
|
memset(job, 0, sizeof(*job));
|
|
|
|
job->copies = copies;
|
2014-01-19 19:53:45 -05:00
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
job->datalen = 0;
|
|
|
|
job->databuf = malloc(MAX_PRINTJOB_LEN);
|
|
|
|
if (!job->databuf) {
|
2013-07-14 15:55:35 -04:00
|
|
|
ERROR("Memory allocation failure!\n");
|
2018-06-17 19:17:28 -04:00
|
|
|
updr150_cleanup_job(job);
|
2018-02-16 10:49:21 -05:00
|
|
|
return CUPS_BACKEND_RETRY_CURRENT;
|
2013-07-14 15:55:35 -04:00
|
|
|
}
|
|
|
|
|
2014-01-19 19:53:45 -05:00
|
|
|
while(run) {
|
2014-02-11 13:41:15 -05:00
|
|
|
int i;
|
2014-01-19 19:53:45 -05:00
|
|
|
int keep = 0;
|
2018-06-15 14:55:03 -04:00
|
|
|
i = read(data_fd, job->databuf + job->datalen, 4);
|
2018-06-17 19:17:28 -04:00
|
|
|
if (i < 0) {
|
|
|
|
updr150_cleanup_job(job);
|
2014-04-25 11:41:35 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2018-06-17 19:17:28 -04:00
|
|
|
}
|
2014-01-20 19:41:52 -05:00
|
|
|
if (i == 0)
|
|
|
|
break;
|
2014-01-19 19:53:45 -05:00
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
memcpy(&len, job->databuf + job->datalen, sizeof(len));
|
2014-01-24 09:58:10 -05:00
|
|
|
len = le32_to_cpu(len);
|
2014-01-19 19:53:45 -05:00
|
|
|
|
|
|
|
/* Filter out chunks we don't send to the printer */
|
2018-08-13 17:57:52 -04:00
|
|
|
if (len & 0xf0000000) {
|
|
|
|
switch (len) {
|
|
|
|
case 0xfffffff3:
|
|
|
|
if(dyesub_debug)
|
|
|
|
DEBUG("Block ID '%08x' (len %d)\n", len, 0);
|
|
|
|
len = 0;
|
|
|
|
if (ctx->type == P_SONY_UPDR150)
|
|
|
|
run = 0;
|
|
|
|
break;
|
|
|
|
case 0xfffffff7:
|
|
|
|
if(dyesub_debug)
|
|
|
|
DEBUG("Block ID '%08x' (len %d)\n", len, 0);
|
|
|
|
len = 0;
|
|
|
|
if (ctx->type == P_SONY_UPCR10)
|
|
|
|
run = 0;
|
|
|
|
break;
|
|
|
|
case 0xfffffff8: // 895
|
|
|
|
case 0xfffffff4: // 897
|
|
|
|
if(dyesub_debug)
|
|
|
|
DEBUG("Block ID '%08x' (len %d)\n", len, 0);
|
|
|
|
len = 0;
|
2019-03-08 18:38:19 -05:00
|
|
|
if (ctx->type == P_SONY_UPD895 || ctx->type == P_SONY_UPD897)
|
2018-08-13 17:57:52 -04:00
|
|
|
run = 0;
|
|
|
|
break;
|
2019-03-08 18:38:19 -05:00
|
|
|
case 0xffffff97:
|
|
|
|
if(dyesub_debug)
|
|
|
|
DEBUG("Block ID '%08x' (len %d)\n", len, 12);
|
|
|
|
len = 12;
|
|
|
|
break;
|
|
|
|
case 0xffffffef:
|
|
|
|
if (ctx->type == P_SONY_UPD895 || ctx->type == P_SONY_UPD897) {
|
|
|
|
if(dyesub_debug)
|
|
|
|
DEBUG("Block ID '%08x' (len %d)\n", len, 0);
|
|
|
|
len = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Intentional Fallthrough */
|
2018-08-13 17:57:52 -04:00
|
|
|
case 0xffffffeb:
|
|
|
|
case 0xffffffee:
|
|
|
|
case 0xfffffff5:
|
2014-01-19 19:53:45 -05:00
|
|
|
if(dyesub_debug)
|
2018-08-13 17:57:52 -04:00
|
|
|
DEBUG("Block ID '%08x' (len %d)\n", len, 4);
|
|
|
|
len = 4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if(dyesub_debug)
|
|
|
|
DEBUG("Block ID '%08x' (len %d)\n", len, 0);
|
|
|
|
len = 0;
|
|
|
|
break;
|
2014-01-19 19:53:45 -05:00
|
|
|
}
|
2018-08-13 17:57:52 -04:00
|
|
|
} else {
|
|
|
|
/* Only keep these chunks */
|
|
|
|
if(dyesub_debug)
|
|
|
|
DEBUG("Data block (len %d)\n", len);
|
2019-03-08 18:38:19 -05:00
|
|
|
if (len > 0)
|
|
|
|
keep = 1;
|
2014-01-19 19:53:45 -05:00
|
|
|
}
|
|
|
|
if (keep)
|
2018-06-15 14:55:03 -04:00
|
|
|
job->datalen += sizeof(uint32_t);
|
2014-01-19 19:53:45 -05:00
|
|
|
|
|
|
|
/* Read in the data chunk */
|
|
|
|
while(len > 0) {
|
2018-06-15 14:55:03 -04:00
|
|
|
i = read(data_fd, job->databuf + job->datalen, len);
|
2018-06-17 19:17:28 -04:00
|
|
|
if (i < 0) {
|
|
|
|
updr150_cleanup_job(job);
|
2014-04-25 11:41:35 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2018-06-17 19:17:28 -04:00
|
|
|
}
|
2014-01-26 15:05:02 -05:00
|
|
|
if (i == 0)
|
|
|
|
break;
|
2014-04-25 11:39:15 -04:00
|
|
|
|
2019-03-15 20:57:10 -04:00
|
|
|
/* Work out offset of copies command */
|
2019-03-17 13:15:27 -04:00
|
|
|
if (job->databuf[job->datalen] == 0x1b) {
|
|
|
|
switch (job->databuf[job->datalen + 1]) {
|
|
|
|
case 0xee:
|
|
|
|
if (i == 7)
|
|
|
|
copies_offset = job->datalen + 11;
|
|
|
|
else
|
|
|
|
copies_offset = job->datalen + 7;
|
|
|
|
break;
|
|
|
|
case 0xe1:
|
|
|
|
memcpy(&job->cols, job->databuf + job->datalen + 14, sizeof(uint16_t));
|
|
|
|
memcpy(&job->rows, job->databuf + job->datalen + 16, sizeof(uint16_t));
|
|
|
|
job->cols = be16_to_cpu(job->cols);
|
|
|
|
job->rows = be16_to_cpu(job->rows);
|
|
|
|
break;
|
|
|
|
case 0xea:
|
|
|
|
memcpy(&job->imglen, job->databuf + job->datalen + 6, sizeof(uint32_t));
|
|
|
|
job->imglen = be32_to_cpu(job->imglen);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-04-25 11:39:15 -04:00
|
|
|
}
|
|
|
|
|
2014-01-19 19:53:45 -05:00
|
|
|
if (keep)
|
2018-06-15 14:55:03 -04:00
|
|
|
job->datalen += i;
|
2014-01-19 19:53:45 -05:00
|
|
|
len -= i;
|
|
|
|
}
|
2013-07-14 15:55:35 -04:00
|
|
|
}
|
2018-06-17 19:17:28 -04:00
|
|
|
if (!job->datalen) {
|
|
|
|
updr150_cleanup_job(job);
|
2014-04-25 11:41:35 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2018-06-17 19:17:28 -04:00
|
|
|
}
|
2014-01-20 19:41:52 -05:00
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
/* Some models specify copies in the print job */
|
|
|
|
if (copies_offset) {
|
2019-03-16 12:21:06 -04:00
|
|
|
uint16_t tmp = copies;
|
|
|
|
tmp = cpu_to_be16(copies);
|
|
|
|
memcpy(job->databuf + copies_offset, &tmp, sizeof(tmp));
|
2018-06-15 14:55:03 -04:00
|
|
|
job->copies = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
*vjob = job;
|
|
|
|
|
2014-04-25 11:41:35 -04:00
|
|
|
return CUPS_BACKEND_OK;
|
2013-07-18 08:46:44 -04:00
|
|
|
}
|
2013-07-14 15:55:35 -04:00
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
static int updr150_main_loop(void *vctx, const void *vjob) {
|
2013-07-18 08:46:44 -04:00
|
|
|
struct updr150_ctx *ctx = vctx;
|
2017-08-05 18:46:55 -04:00
|
|
|
int i, ret;
|
2018-06-15 14:55:03 -04:00
|
|
|
int copies;
|
|
|
|
|
|
|
|
const struct updr150_printjob *job = vjob;
|
2013-07-14 15:55:35 -04:00
|
|
|
|
2013-07-18 08:46:44 -04:00
|
|
|
if (!ctx)
|
2014-04-25 11:41:35 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2018-06-15 14:55:03 -04:00
|
|
|
if (!job)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-07-14 15:55:35 -04:00
|
|
|
|
2018-06-15 14:55:03 -04:00
|
|
|
copies = job->copies;
|
2014-04-25 11:39:15 -04:00
|
|
|
|
2013-07-14 15:55:35 -04:00
|
|
|
top:
|
2019-03-17 13:15:27 -04:00
|
|
|
/* Send Unknown CMD. Resets? */
|
|
|
|
if (ctx->type == P_SONY_UPD897) {
|
|
|
|
const uint8_t cmdbuf[7] = { 0x1b, 0x1f, 0, 0, 0, 0, 0 };
|
|
|
|
ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
cmdbuf, sizeof(cmdbuf));
|
2019-03-10 17:03:07 -04:00
|
|
|
if (ret)
|
2019-03-17 13:15:27 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
}
|
2019-03-10 17:03:07 -04:00
|
|
|
|
2019-03-17 13:15:27 -04:00
|
|
|
/* Query printer status */
|
|
|
|
ret = sony_get_status(ctx, &ctx->stsbuf);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
|
|
|
/* Sanity check job parameters */
|
|
|
|
if (job->rows > ctx->stsbuf.max_rows ||
|
|
|
|
job->cols > ctx->stsbuf.max_cols) {
|
|
|
|
ERROR("Job dimensions (%u/%u) exceed printer max (%u/%u)\n",
|
|
|
|
job->cols, job->rows,
|
|
|
|
ctx->stsbuf.max_cols,
|
|
|
|
ctx->stsbuf.max_rows);
|
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
}
|
|
|
|
if (job->imglen != (uint32_t)(job->rows * job->cols * ctx->native_bpp))
|
|
|
|
{
|
|
|
|
ERROR("Job data length mismatch!\n");
|
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for idle */
|
|
|
|
if (ctx->stsbuf.sts1 != 0x00) {
|
|
|
|
if (ctx->stsbuf.sts1 == 0x80) {
|
|
|
|
INFO("Waiting for printer idle...\n");
|
|
|
|
sleep(1);
|
|
|
|
goto top;
|
2019-03-10 17:03:07 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-17 13:15:27 -04:00
|
|
|
/* Send RESET */
|
|
|
|
if (ctx->type != P_SONY_UPD895) {
|
|
|
|
const uint8_t rstbuf[7] = { 0x1b, 0x16, 0, 0, 0, 0, 0 };
|
|
|
|
ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
rstbuf, sizeof(rstbuf));
|
|
|
|
if (ret)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0 /* Unknown query */
|
|
|
|
if (ctx->type == P_SONY_UPD897) {
|
|
|
|
// -> 1b e6 00 00 00 08 00
|
|
|
|
// <- ???
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Send over job */
|
2017-08-05 18:46:55 -04:00
|
|
|
i = 0;
|
2018-06-15 14:55:03 -04:00
|
|
|
while (i < job->datalen) {
|
2014-01-26 15:05:02 -05:00
|
|
|
uint32_t len;
|
2018-06-15 14:55:03 -04:00
|
|
|
memcpy(&len, job->databuf + i, sizeof(len));
|
2014-01-26 15:05:02 -05:00
|
|
|
len = le32_to_cpu(len);
|
2014-01-19 19:53:45 -05:00
|
|
|
|
|
|
|
i += sizeof(uint32_t);
|
|
|
|
|
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
2018-06-15 14:55:03 -04:00
|
|
|
job->databuf + i, len)))
|
2014-04-25 11:41:35 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2014-01-26 15:05:02 -05:00
|
|
|
|
2014-01-19 19:53:45 -05:00
|
|
|
i += len;
|
2013-07-14 15:55:35 -04:00
|
|
|
}
|
|
|
|
|
2019-03-17 13:15:27 -04:00
|
|
|
// XXX generate and send copy cmd instead of using the offset.
|
|
|
|
// 1b ee 00 00 00 02 00 NN NN (BE)
|
|
|
|
|
2019-03-10 17:03:07 -04:00
|
|
|
/* Check for idle, if appropriate */
|
2019-03-15 20:57:10 -04:00
|
|
|
if (ctx->type == P_SONY_UPD895 || ctx->type == P_SONY_UPD897) {
|
2019-03-10 17:03:07 -04:00
|
|
|
retry:
|
|
|
|
sleep(1);
|
|
|
|
|
2019-03-17 13:15:27 -04:00
|
|
|
ret = sony_get_status(ctx, &ctx->stsbuf);
|
2019-03-10 17:03:07 -04:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2019-03-17 13:15:27 -04:00
|
|
|
switch (ctx->stsbuf.sts1) {
|
2019-03-10 17:03:07 -04:00
|
|
|
case 0x00:
|
|
|
|
goto done;
|
|
|
|
case 0x80:
|
|
|
|
break;
|
|
|
|
default:
|
2019-03-17 13:15:27 -04:00
|
|
|
ERROR("Printer error: %s (%02x)\n", upd895_statuses(ctx->stsbuf.sts1),
|
|
|
|
ctx->stsbuf.sts1);
|
2019-03-10 17:03:07 -04:00
|
|
|
return CUPS_BACKEND_STOP;
|
|
|
|
}
|
|
|
|
|
2019-03-17 13:15:27 -04:00
|
|
|
if (fast_return && ctx->stsbuf.printing > 0) {
|
2019-03-10 17:03:07 -04:00
|
|
|
INFO("Fast return mode enabled.\n");
|
|
|
|
} else {
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-14 15:55:35 -04:00
|
|
|
/* Clean up */
|
|
|
|
if (terminate)
|
|
|
|
copies = 1;
|
|
|
|
|
2019-03-10 17:03:07 -04:00
|
|
|
done:
|
2014-01-22 09:10:34 -05:00
|
|
|
INFO("Print complete (%d copies remaining)\n", copies - 1);
|
2013-07-14 15:55:35 -04:00
|
|
|
|
|
|
|
if (copies && --copies) {
|
|
|
|
goto top;
|
|
|
|
}
|
|
|
|
|
2014-04-25 11:41:35 -04:00
|
|
|
return CUPS_BACKEND_OK;
|
2013-07-14 15:55:35 -04:00
|
|
|
}
|
|
|
|
|
2019-03-10 17:03:07 -04:00
|
|
|
static int upd895_dump_status(struct updr150_ctx *ctx)
|
|
|
|
{
|
2019-03-17 13:15:27 -04:00
|
|
|
int ret = sony_get_status(ctx, &ctx->stsbuf);
|
2019-03-10 17:03:07 -04:00
|
|
|
if (ret < 0)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
2019-03-17 13:15:27 -04:00
|
|
|
ctx->stsbuf.max_cols = be16_to_cpu(ctx->stsbuf.max_cols);
|
|
|
|
ctx->stsbuf.max_rows = be16_to_cpu(ctx->stsbuf.max_rows);
|
|
|
|
|
|
|
|
INFO("Printer status: %s (%02x)\n", upd895_statuses(ctx->stsbuf.sts1), ctx->stsbuf.sts1);
|
|
|
|
if (ctx->stsbuf.printing == 0x0e0 && ctx->stsbuf.sts1 == 0x80)
|
|
|
|
INFO("Remaining copies: %d\n", ctx->stsbuf.remain);
|
2019-03-10 17:03:07 -04:00
|
|
|
|
|
|
|
return CUPS_BACKEND_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void updr150_cmdline(void)
|
|
|
|
{
|
|
|
|
DEBUG("\t\t[ -s ] # Query printer status (only UP-D895)\n");
|
|
|
|
}
|
|
|
|
|
2015-08-13 21:09:56 -04:00
|
|
|
static int updr150_cmdline_arg(void *vctx, int argc, char **argv)
|
|
|
|
{
|
2015-08-24 17:28:10 -04:00
|
|
|
struct updr150_ctx *ctx = vctx;
|
2015-08-13 21:09:56 -04:00
|
|
|
int i, j = 0;
|
|
|
|
|
2015-08-24 17:28:10 -04:00
|
|
|
if (!ctx)
|
|
|
|
return -1;
|
|
|
|
|
2019-03-10 17:03:07 -04:00
|
|
|
while ((i = getopt(argc, argv, GETOPT_LIST_GLOBAL "s")) >= 0) {
|
2015-08-13 21:09:56 -04:00
|
|
|
switch(i) {
|
|
|
|
GETOPT_PROCESS_GLOBAL
|
2019-03-10 17:03:07 -04:00
|
|
|
case 's':
|
2019-03-15 20:57:10 -04:00
|
|
|
if (ctx->type == P_SONY_UPD895 ||
|
|
|
|
ctx->type == P_SONY_UPD897)
|
2019-03-10 17:03:07 -04:00
|
|
|
j = upd895_dump_status(ctx);
|
|
|
|
break;
|
2015-08-13 21:09:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (j) return j;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-04-29 14:07:08 -04:00
|
|
|
static int updr150_query_markers(void *vctx, struct marker **markers, int *count)
|
|
|
|
{
|
|
|
|
struct updr150_ctx *ctx = vctx;
|
|
|
|
|
|
|
|
*markers = &ctx->marker;
|
|
|
|
*count = 1;
|
|
|
|
|
2019-03-15 20:57:10 -04:00
|
|
|
if (ctx->type == P_SONY_UPD895 ||
|
|
|
|
ctx->type == P_SONY_UPD897) {
|
2019-03-17 13:15:27 -04:00
|
|
|
int ret = sony_get_status(ctx, &ctx->stsbuf);
|
2019-03-10 17:03:07 -04:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
2019-03-17 13:15:27 -04:00
|
|
|
if (ctx->stsbuf.sts1 == 0x40 ||
|
|
|
|
ctx->stsbuf.sts1 == 0x08) {
|
2019-03-10 17:03:07 -04:00
|
|
|
ctx->marker.levelnow = 0;
|
2019-03-15 20:57:10 -04:00
|
|
|
STATE("+media-empty");
|
|
|
|
} else {
|
2019-03-10 17:03:07 -04:00
|
|
|
ctx->marker.levelnow = -3;
|
2019-03-15 20:57:10 -04:00
|
|
|
STATE("-media-empty");
|
|
|
|
}
|
2019-03-10 17:03:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-29 14:07:08 -04:00
|
|
|
return CUPS_BACKEND_OK;
|
|
|
|
}
|
|
|
|
|
2018-03-16 15:35:00 -04:00
|
|
|
static const char *sonyupdr150_prefixes[] = {
|
2018-09-22 09:11:14 -04:00
|
|
|
"sonyupdr150", // Family name.
|
2018-09-25 14:35:37 -04:00
|
|
|
"sony-updr150", "sony-updr200", "sony-upcr10l",
|
2018-09-22 09:11:14 -04:00
|
|
|
// Backwards compatibility
|
|
|
|
"sonyupdr200", "sonyupcr10",
|
2019-03-08 18:38:19 -05:00
|
|
|
"sony-upd895", "sony-upd897",
|
|
|
|
// "sony-upd898",
|
2018-04-17 09:38:42 -04:00
|
|
|
NULL
|
2018-03-16 15:35:00 -04:00
|
|
|
};
|
|
|
|
|
2018-08-13 17:57:52 -04:00
|
|
|
/* Exported */
|
|
|
|
#define USB_VID_SONY 0x054C
|
|
|
|
#define USB_PID_SONY_UPDR150 0x01E8
|
|
|
|
#define USB_PID_SONY_UPDR200 0x035F
|
|
|
|
#define USB_PID_SONY_UPCR10 0x0226
|
2019-03-08 18:38:19 -05:00
|
|
|
#define USB_PID_SONY_UPD895 0x0049
|
|
|
|
#define USB_PID_SONY_UPD897 0x01E7
|
2018-08-13 17:57:52 -04:00
|
|
|
//#define USB_PID_SONY_UPD898 XXXXX // 0x589a?
|
|
|
|
|
2013-07-18 08:46:44 -04:00
|
|
|
struct dyesub_backend updr150_backend = {
|
2019-03-08 18:38:19 -05:00
|
|
|
.name = "Sony UP-DR150/UP-DR200/UP-CR10/UP-D895/UP-D897",
|
2019-03-17 13:15:27 -04:00
|
|
|
.version = "0.32",
|
2018-03-16 15:35:00 -04:00
|
|
|
.uri_prefixes = sonyupdr150_prefixes,
|
2015-10-05 09:44:04 -04:00
|
|
|
.cmdline_arg = updr150_cmdline_arg,
|
2019-03-10 17:03:07 -04:00
|
|
|
.cmdline_usage = updr150_cmdline,
|
2013-07-18 08:46:44 -04:00
|
|
|
.init = updr150_init,
|
2013-07-19 09:23:53 -04:00
|
|
|
.attach = updr150_attach,
|
2013-07-18 08:46:44 -04:00
|
|
|
.teardown = updr150_teardown,
|
2018-06-15 14:55:03 -04:00
|
|
|
.cleanup_job = updr150_cleanup_job,
|
2013-07-18 08:46:44 -04:00
|
|
|
.read_parse = updr150_read_parse,
|
|
|
|
.main_loop = updr150_main_loop,
|
2018-04-29 14:07:08 -04:00
|
|
|
.query_markers = updr150_query_markers,
|
2013-07-18 23:39:36 -04:00
|
|
|
.devices = {
|
2018-09-22 09:11:14 -04:00
|
|
|
{ USB_VID_SONY, USB_PID_SONY_UPDR150, P_SONY_UPDR150, NULL, "sony-updr150"},
|
|
|
|
{ USB_VID_SONY, USB_PID_SONY_UPDR200, P_SONY_UPDR150, NULL, "sony-updr200"},
|
2018-09-25 14:35:37 -04:00
|
|
|
{ USB_VID_SONY, USB_PID_SONY_UPCR10, P_SONY_UPCR10, NULL, "sony-upcr10l"},
|
2019-03-08 18:38:19 -05:00
|
|
|
{ USB_VID_SONY, USB_PID_SONY_UPD895, P_SONY_UPD895, NULL, "sonyupd895"},
|
|
|
|
{ USB_VID_SONY, USB_PID_SONY_UPD897, P_SONY_UPD897, NULL, "sony-upd897"},
|
2018-08-13 17:57:52 -04:00
|
|
|
// { USB_VID_SONY, USB_PID_SONY_UPD898MD, P_SONY_UPD89x, NULL, "sonyupd898"},
|
2018-03-16 15:35:00 -04:00
|
|
|
{ 0, 0, 0, NULL, NULL}
|
2013-07-18 23:39:36 -04:00
|
|
|
}
|
2013-07-18 08:46:44 -04:00
|
|
|
};
|
|
|
|
|
2019-03-15 22:57:13 -04:00
|
|
|
/* Sony spool file format
|
2013-07-14 15:55:35 -04:00
|
|
|
|
|
|
|
The spool file is a series of 4-byte commands, followed by optional
|
|
|
|
arguments. The purpose of the commands is unknown, but they presumably
|
|
|
|
instruct the driver to perform certain things.
|
|
|
|
|
2018-08-13 17:57:52 -04:00
|
|
|
If you treat these 4 bytes as a 32-bit little-endian number, if any of the
|
2019-03-15 22:57:13 -04:00
|
|
|
least significant 4 bits are non-zero, the value is is to
|
2014-05-06 09:49:55 -04:00
|
|
|
be interpreted as a driver command. If the most significant bits are
|
|
|
|
zero, the value signifies that the following N bytes of data should be
|
|
|
|
sent to the printer as-is.
|
2014-01-17 23:21:23 -05:00
|
|
|
|
|
|
|
Known driver "commands":
|
2013-07-14 15:55:35 -04:00
|
|
|
|
2019-03-15 22:57:13 -04:00
|
|
|
97 ff ff ff
|
|
|
|
eb ff ff ff ?? 00 00 00
|
|
|
|
ec ff ff ff ?? 00 00 00
|
|
|
|
ed ff ff ff ?? 00 00 00
|
|
|
|
ee ff ff ff ?? 00 00 00
|
|
|
|
ef ff ff ff XX 00 00 00 # XX == print size (0x01/0x02/0x03/0x04)
|
|
|
|
ef ff ff ff # On UP-D895/897
|
|
|
|
f3 ff ff ff
|
|
|
|
f4 ff ff ff # End of job on UP-D897
|
|
|
|
f5 ff ff ff YY 00 00 00 # YY == ??? (seen 0x01)
|
|
|
|
f7 ff ff ff # End of job on UP-D895
|
2013-07-14 15:55:35 -04:00
|
|
|
|
|
|
|
All printer commands start with 0x1b, and are at least 7 bytes long.
|
2019-03-15 22:57:13 -04:00
|
|
|
General Command format:
|
|
|
|
|
|
|
|
1b XX ?? ?? ?? LL 00 # XX is cmd, LL is data or response length.
|
|
|
|
|
|
|
|
UNKNOWN QUERY
|
|
|
|
|
|
|
|
<- 1b 03 00 00 00 13 00
|
|
|
|
-> 70 00 00 00 00 00 00 0b 00 00 00 00 00 00 00 00
|
|
|
|
00 00 00
|
|
|
|
|
|
|
|
UNKNOWN CMD (UP-DR & SL)
|
|
|
|
|
|
|
|
<- 1b 0a 00 00 00 00 00
|
|
|
|
|
|
|
|
PRINT DIMENSIONS
|
|
|
|
|
|
|
|
<- 1b 15 00 00 00 0d 00
|
|
|
|
<- 00 00 00 00 ZZ QQ QQ WW WW YY YY XX XX
|
|
|
|
|
|
|
|
QQ/WW/YY/XX are (origin_cols/origin_rows/cols/rows) in BE.
|
|
|
|
ZZ is 0x07 on UP-DR series, 0x01 on UP-D89x series.
|
|
|
|
|
|
|
|
RESET
|
|
|
|
|
|
|
|
<- 1b 16 00 00 00 00 00
|
|
|
|
|
|
|
|
UNKNOWN CMD (UP-DR & SL)
|
|
|
|
|
|
|
|
<- 1b 17 00 00 00 00 00
|
|
|
|
|
2019-03-17 13:15:27 -04:00
|
|
|
UNKNOWN CMD (UP-D897)
|
|
|
|
|
|
|
|
<- 1b 1f 00 00 00 00 00
|
|
|
|
|
2019-03-15 22:57:13 -04:00
|
|
|
SET PARAM
|
|
|
|
|
|
|
|
<- 1b c0 00 NN LL 00 00 # LL is response length, NN is number.
|
|
|
|
<- [ NN bytes]
|
|
|
|
|
|
|
|
QUERY PARAM
|
|
|
|
|
|
|
|
<- 1b c1 00 NN LL 00 00 # LL is response length, NN is number.
|
|
|
|
-> [ NN bytes ]
|
|
|
|
|
|
|
|
PARAMS SEEN:
|
|
|
|
|
|
|
|
02, len 06 [ 02 02 00 03 00 00 ]
|
2019-03-17 13:15:27 -04:00
|
|
|
01, len 10 [ 02 01 00 06 00 02 00 00 00 00 ] (UP-D897)
|
|
|
|
00, len 5 [ 02 01 00 01 XX ] XX == Gamma table
|
2019-03-15 22:57:13 -04:00
|
|
|
|
|
|
|
STATUS QUERY
|
|
|
|
|
|
|
|
<- 1b e0 00 00 00 XX 00 # XX = 0xe (UP-D895), 0xf (All others)
|
|
|
|
-> [14 or 15 bytes]
|
|
|
|
|
2019-03-17 13:15:27 -04:00
|
|
|
PRINT DIMENSIONS [[ May actually be PRINT START command ]]
|
2019-03-15 22:57:13 -04:00
|
|
|
|
|
|
|
<- 1b e1 00 00 00 0b 00
|
|
|
|
<- 00 80 00 00 00 00 00 XX XX YY YY # XX = cols, YY == rows
|
|
|
|
|
|
|
|
UNKNOWN
|
|
|
|
|
|
|
|
<- 1b e5 00 00 00 08 00
|
|
|
|
<- 00 00 00 00 00 00 00 XX 00 # XX = 0 on UP-D89x & SL, 1 on up-dr series.
|
|
|
|
|
2019-03-17 13:15:27 -04:00
|
|
|
UNKNOWN (UP-D897)
|
|
|
|
|
|
|
|
<- 1b e6 00 00 00 08 00
|
|
|
|
<- 07 00 00 00 00 00 00 00
|
|
|
|
|
2019-03-15 22:57:13 -04:00
|
|
|
DATA TRANSFER
|
|
|
|
|
|
|
|
<- 1b ea 00 00 00 00 ZZ ZZ ZZ ZZ 00 # ZZ is BIG ENDIAN
|
|
|
|
<- [ ZZ ZZ ZZ ZZ bytes of data ]
|
|
|
|
|
|
|
|
UNKNOWN (UPDR series)
|
|
|
|
|
|
|
|
<- 1b ef 00 00 00 06 00
|
|
|
|
-> 05 00 00 00 00 22
|
|
|
|
|
|
|
|
COPIES
|
|
|
|
|
|
|
|
<- 1b ee 00 00 00 02 00
|
|
|
|
<- NN NN # Number of copies (BE, 1-???)
|
|
|
|
|
2013-07-14 15:55:35 -04:00
|
|
|
|
|
|
|
**************************************************************** |