2013-06-27 22:45:32 -04:00
|
|
|
/*
|
2013-07-25 17:13:36 -04:00
|
|
|
* Kodak 6800/6850 Photo Printer CUPS backend -- libusb-1.0 version
|
2013-06-27 22:45:32 -04:00
|
|
|
*
|
2015-01-05 21:39:22 -05:00
|
|
|
* (c) 2013-2015 Solomon Peachy <pizza@shaftnet.org>
|
2013-06-27 22:45:32 -04:00
|
|
|
*
|
2014-06-03 20:43:31 -04:00
|
|
|
* Development of this backend was sponsored by:
|
|
|
|
*
|
|
|
|
* LiveLink Technology [ www.livelinktechnology.net ]
|
|
|
|
*
|
2013-06-27 22:45:32 -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-06-27 22:45:32 -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>
|
|
|
|
|
2013-07-18 18:03:40 -04:00
|
|
|
#include "backend_common.h"
|
|
|
|
|
2013-07-25 17:13:36 -04:00
|
|
|
#define USB_VID_KODAK 0x040A
|
|
|
|
#define USB_PID_KODAK_6800 0x4021
|
|
|
|
#define USB_PID_KODAK_6850 0x402B
|
|
|
|
|
2013-07-18 20:32:44 -04:00
|
|
|
/* File header */
|
|
|
|
struct kodak6800_hdr {
|
2014-06-02 22:16:28 -04:00
|
|
|
uint8_t hdr[9]; /* Always 03 1b 43 48 43 0a 00 04 00 [6850]
|
|
|
|
03 1b 43 48 43 0a 00 01 00 [6800] */
|
2013-07-18 20:32:44 -04:00
|
|
|
uint8_t copies;
|
|
|
|
uint16_t columns; /* BE */
|
|
|
|
uint16_t rows; /* BE */
|
2014-10-04 11:55:56 -04:00
|
|
|
uint8_t size; /* 0x06 for 6x8, 0x00 for 6x4, 0x07 for 5x7 */
|
2013-07-18 20:32:44 -04:00
|
|
|
uint8_t laminate; /* 0x01 to laminate, 0x00 for not */
|
2014-04-12 12:41:09 -04:00
|
|
|
uint8_t unk1; /* 0x00 or 0x01 (for 4x6 on 6x8 media) */
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct kodak68x0_status_readback {
|
2014-07-09 19:31:49 -04:00
|
|
|
uint8_t hdr; /* Always 01 */
|
|
|
|
uint8_t sts1; /* Always 0x02 (idle) or 0x01 (busy) */
|
|
|
|
uint8_t sts2; /* 0x01 == ready, 0x02 == no media, 0x03 == not ready */
|
2014-12-05 22:01:36 -05:00
|
|
|
uint8_t errtype; /* 0x00 none, 0x80 "control" */
|
|
|
|
uint8_t null0[2];
|
2014-07-08 21:31:10 -04:00
|
|
|
uint8_t unkA; /* 0x00 or 0x01 or 0x10 */
|
2014-12-05 22:01:36 -05:00
|
|
|
uint8_t errcode; /* Error ## */
|
2014-05-30 19:08:09 -04:00
|
|
|
uint32_t ctr0; /* Total Prints (BE) */
|
|
|
|
uint32_t ctr1; /* Total Prints (BE) */
|
2014-04-12 12:41:09 -04:00
|
|
|
uint32_t ctr2; /* Increments by 1 for each print (6850), unk (6800). BE */
|
|
|
|
uint32_t ctr3; /* Increments by 2 for each print. BE */
|
2014-12-05 22:01:36 -05:00
|
|
|
uint8_t nullB[2];
|
|
|
|
uint8_t errtype2; /* 0x00 none, 0xd0 "control" */
|
2014-06-02 22:16:28 -04:00
|
|
|
uint8_t donor; /* Percentage, 0-100 */
|
|
|
|
uint8_t unkC[2]; /* Always 00 03 */
|
2014-12-05 23:02:06 -05:00
|
|
|
uint16_t main_fw; /* seen 652, 656, 670 (6850) and 232 (6800) */
|
2014-06-02 22:16:28 -04:00
|
|
|
uint8_t unkD[2]; /* Always 00 01 */
|
2014-12-05 22:01:36 -05:00
|
|
|
uint16_t dsp_fw; /* Seen 540, 541, 560 (6850) and 131 (6800) */
|
2014-06-03 20:38:21 -04:00
|
|
|
uint8_t unk1; /* Seen 0x00, 0x01, 0x03, 0x04 */
|
2014-04-12 12:41:09 -04:00
|
|
|
uint8_t null1[2];
|
2014-06-02 22:16:28 -04:00
|
|
|
uint8_t unk2; /* Seen 0x01, 0x00 */
|
2014-04-12 12:41:09 -04:00
|
|
|
uint8_t null2;
|
2014-06-02 22:16:28 -04:00
|
|
|
uint8_t unk3; /* Seen 0x01, 0x00 */
|
2014-04-12 12:41:09 -04:00
|
|
|
uint8_t null4;
|
2014-06-02 22:16:28 -04:00
|
|
|
uint8_t unk4; /* Seen 0x01, 0x00 */
|
2014-04-12 12:41:09 -04:00
|
|
|
uint8_t null5[7];
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
|
|
|
struct kodak6800_printsize {
|
|
|
|
uint8_t hdr; /* Always 0x06 */
|
|
|
|
uint16_t width; /* BE */
|
|
|
|
uint16_t height; /* BE */
|
|
|
|
uint8_t hdr2; /* Always 0x01 */
|
2014-10-04 11:55:56 -04:00
|
|
|
uint8_t code; /* 00, 01, 02, 03, 04, 05 seen. An index? */
|
|
|
|
uint8_t code2; /* 00, 01 seen. Seems to be 1 only after a 4x6 printed. */
|
2014-04-12 12:41:09 -04:00
|
|
|
uint8_t null[2];
|
|
|
|
} __attribute__((packed));
|
|
|
|
|
2014-06-02 22:16:28 -04:00
|
|
|
#define MAX_MEDIA_LEN 128
|
|
|
|
|
2014-04-12 12:41:09 -04:00
|
|
|
struct kodak68x0_media_readback {
|
|
|
|
uint8_t hdr; /* Always 0x01 */
|
2014-07-09 19:31:49 -04:00
|
|
|
uint8_t media; /* Always 0x00 (none), 0x0b or 0x03 */
|
2014-04-26 20:20:07 -04:00
|
|
|
uint8_t null[5];
|
2014-04-12 12:41:09 -04:00
|
|
|
uint8_t count; /* Always 0x04 (6800) or 0x06 (6850)? */
|
|
|
|
struct kodak6800_printsize sizes[];
|
2013-07-18 20:32:44 -04:00
|
|
|
} __attribute__((packed));
|
2013-07-18 18:03:40 -04:00
|
|
|
|
2014-10-04 11:55:56 -04:00
|
|
|
#define KODAK68x0_MEDIA_6R 0x0b
|
|
|
|
|
2013-07-18 18:03:40 -04:00
|
|
|
#define CMDBUF_LEN 17
|
|
|
|
|
|
|
|
/* Private data stucture */
|
|
|
|
struct kodak6800_ctx {
|
|
|
|
struct libusb_device_handle *dev;
|
|
|
|
uint8_t endp_up;
|
|
|
|
uint8_t endp_down;
|
|
|
|
|
2013-07-25 17:13:36 -04:00
|
|
|
int type;
|
2014-10-04 11:55:56 -04:00
|
|
|
int media;
|
|
|
|
|
2013-07-18 20:32:44 -04:00
|
|
|
struct kodak6800_hdr hdr;
|
2013-07-18 18:03:40 -04:00
|
|
|
uint8_t *databuf;
|
|
|
|
int datalen;
|
|
|
|
};
|
2014-07-09 19:31:49 -04:00
|
|
|
#define READBACK_LEN 68
|
2013-06-27 23:02:34 -04:00
|
|
|
|
2014-12-05 22:49:02 -05:00
|
|
|
char *kodak68x0_error_codes(uint8_t code1, uint8_t code2)
|
|
|
|
{
|
|
|
|
if (code1 == 0x80 && code2 == 0xd0)
|
|
|
|
return "Control Error";
|
|
|
|
|
2014-12-05 23:02:06 -05:00
|
|
|
return "Unknown Type (please report!)";
|
2014-12-05 22:49:02 -05:00
|
|
|
}
|
|
|
|
|
2014-04-19 11:33:50 -04:00
|
|
|
static void kodak68x0_dump_mediainfo(struct kodak68x0_media_readback *media)
|
2014-04-12 12:41:09 -04:00
|
|
|
{
|
|
|
|
int i;
|
2014-10-04 11:55:56 -04:00
|
|
|
if (media->media == KODAK68x0_MEDIA_6R) {
|
|
|
|
DEBUG("Media type: 6R (Kodak 197-4096 or equivalent)\n");
|
|
|
|
} else {
|
|
|
|
DEBUG("Media type %02x (unknown, please report!)\n", media->media);
|
|
|
|
}
|
2014-04-12 12:41:09 -04:00
|
|
|
DEBUG("Legal print sizes:\n");
|
|
|
|
for (i = 0 ; i < media->count ; i++) {
|
2014-10-04 11:55:56 -04:00
|
|
|
DEBUG("\t%d: %dx%d (%02x) %s\n", i,
|
2014-04-12 12:41:09 -04:00
|
|
|
be16_to_cpu(media->sizes[i].width),
|
|
|
|
be16_to_cpu(media->sizes[i].height),
|
|
|
|
media->sizes[i].code,
|
2014-10-04 11:55:56 -04:00
|
|
|
media->sizes[i].code2? "Disallowed" : "");
|
2014-04-12 12:41:09 -04:00
|
|
|
}
|
|
|
|
DEBUG("\n");
|
|
|
|
}
|
|
|
|
|
2014-06-02 22:16:28 -04:00
|
|
|
static int kodak6800_get_mediainfo(struct kodak6800_ctx *ctx, struct kodak68x0_media_readback *media)
|
2014-04-12 12:41:09 -04:00
|
|
|
{
|
|
|
|
uint8_t req[16];
|
|
|
|
int ret, num;
|
|
|
|
|
|
|
|
memset(req, 0, sizeof(req));
|
2014-06-02 22:16:28 -04:00
|
|
|
memset(media, 0, sizeof(*media));
|
2014-04-12 12:41:09 -04:00
|
|
|
|
|
|
|
req[0] = 0x03;
|
|
|
|
req[1] = 0x1b;
|
|
|
|
req[2] = 0x43;
|
|
|
|
req[3] = 0x48;
|
|
|
|
req[4] = 0x43;
|
|
|
|
req[5] = 0x1a;
|
|
|
|
|
|
|
|
/* Send request */
|
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
req, sizeof(req))))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Get response */
|
|
|
|
ret = read_data(ctx->dev, ctx->endp_up,
|
2014-06-02 22:16:28 -04:00
|
|
|
(uint8_t*)media, MAX_MEDIA_LEN, &num);
|
2014-04-12 12:41:09 -04:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2014-06-02 22:16:28 -04:00
|
|
|
if (num < (int)sizeof(*media)) {
|
|
|
|
ERROR("Short read! (%d/%d)\n", num, (int) sizeof(*media));
|
2014-04-12 12:41:09 -04:00
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
2014-10-04 11:55:56 -04:00
|
|
|
|
|
|
|
/* Validate proper response */
|
|
|
|
if (media->hdr != 0x01 ||
|
|
|
|
media->null[0] != 0x00) {
|
|
|
|
ERROR("Unexpected response from media query!\n");
|
|
|
|
return CUPS_BACKEND_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->media = media->media;
|
|
|
|
|
2014-04-12 12:41:09 -04:00
|
|
|
return 0;
|
|
|
|
}
|
2013-06-27 22:45:32 -04:00
|
|
|
|
2014-10-04 11:55:56 -04:00
|
|
|
static void kodak68x0_dump_status(struct kodak6800_ctx *ctx, struct kodak68x0_status_readback *status)
|
2014-06-02 22:16:28 -04:00
|
|
|
{
|
2014-12-05 22:49:02 -05:00
|
|
|
if (status->errtype || status->errtype2 || status->errcode) {
|
|
|
|
DEBUG("Error code : %s (%d/%d) # %d\n",
|
|
|
|
kodak68x0_error_codes(status->errtype, status->errtype2),
|
|
|
|
status->errtype, status->errtype2, status->errcode);
|
2014-12-05 22:01:36 -05:00
|
|
|
}
|
2014-10-04 11:55:56 -04:00
|
|
|
DEBUG("Total prints : %d\n", be32_to_cpu(status->ctr0));
|
|
|
|
DEBUG("Media prints : %d\n", be32_to_cpu(status->ctr2));
|
|
|
|
if (ctx->type == P_KODAK_6850) {
|
|
|
|
int max;
|
|
|
|
if (ctx->media == KODAK68x0_MEDIA_6R) {
|
|
|
|
max = 375;
|
|
|
|
} else {
|
|
|
|
max = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (max) {
|
|
|
|
DEBUG("Remaining prints : %d\n", max - be32_to_cpu(status->ctr2));
|
|
|
|
} else {
|
|
|
|
DEBUG("Remaining prints : Unknown media type\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DEBUG("Main FW version : %d\n", be16_to_cpu(status->main_fw));
|
|
|
|
DEBUG("DSP FW version : %d\n", be16_to_cpu(status->dsp_fw));
|
|
|
|
DEBUG("Donor : %d%%\n", status->donor);
|
2014-06-02 22:16:28 -04:00
|
|
|
DEBUG("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kodak6800_get_status(struct kodak6800_ctx *ctx,
|
|
|
|
struct kodak68x0_status_readback *status)
|
|
|
|
{
|
|
|
|
uint8_t req[16];
|
|
|
|
int ret, num;
|
|
|
|
|
|
|
|
memset(req, 0, sizeof(req));
|
|
|
|
memset(status, 0, sizeof(*status));
|
|
|
|
|
|
|
|
req[0] = 0x03;
|
|
|
|
req[1] = 0x1b;
|
|
|
|
req[2] = 0x43;
|
|
|
|
req[3] = 0x48;
|
|
|
|
req[4] = 0x43;
|
|
|
|
req[5] = 0x03;
|
|
|
|
|
|
|
|
/* Send request */
|
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
req, sizeof(req))))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Get response */
|
|
|
|
ret = read_data(ctx->dev, ctx->endp_up,
|
|
|
|
(uint8_t*)status, sizeof(*status), &num);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
if (num < (int)sizeof(*status)) {
|
|
|
|
ERROR("Short read! (%d/%d)\n", num, (int) sizeof(*status));
|
2014-07-08 21:31:10 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
}
|
|
|
|
|
2014-07-09 19:31:49 -04:00
|
|
|
if (status->hdr != 0x01) {
|
2014-07-08 21:31:10 -04:00
|
|
|
ERROR("Unexpected response from status query!\n");
|
|
|
|
return CUPS_BACKEND_FAILED;
|
2014-06-02 22:16:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-08 21:59:51 -04:00
|
|
|
#define UPDATE_SIZE 1536
|
2013-07-18 18:03:40 -04:00
|
|
|
static int kodak6800_get_tonecurve(struct kodak6800_ctx *ctx, char *fname)
|
2013-07-08 21:59:51 -04:00
|
|
|
{
|
2013-07-18 18:03:40 -04:00
|
|
|
libusb_device_handle *dev = ctx->dev;
|
|
|
|
uint8_t endp_down = ctx->endp_down;
|
|
|
|
uint8_t endp_up = ctx->endp_up;
|
|
|
|
|
2013-07-08 21:59:51 -04:00
|
|
|
uint8_t cmdbuf[16];
|
|
|
|
uint8_t respbuf[64];
|
|
|
|
int ret, num = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
uint16_t *data = malloc(UPDATE_SIZE);
|
|
|
|
|
|
|
|
INFO("Dump Tone Curve to '%s'\n", fname);
|
|
|
|
|
|
|
|
/* Initial Request */
|
|
|
|
cmdbuf[0] = 0x03;
|
|
|
|
cmdbuf[1] = 0x1b;
|
|
|
|
cmdbuf[2] = 0x43;
|
|
|
|
cmdbuf[3] = 0x48;
|
|
|
|
cmdbuf[4] = 0x43;
|
|
|
|
cmdbuf[5] = 0x0c;
|
|
|
|
cmdbuf[6] = 0x54;
|
|
|
|
cmdbuf[7] = 0x4f;
|
|
|
|
cmdbuf[8] = 0x4e;
|
|
|
|
cmdbuf[9] = 0x45;
|
|
|
|
cmdbuf[10] = 0x72;
|
|
|
|
cmdbuf[11] = 0x01;
|
|
|
|
cmdbuf[12] = 0x00;
|
|
|
|
cmdbuf[13] = 0x00;
|
|
|
|
cmdbuf[14] = 0x00;
|
|
|
|
cmdbuf[15] = 0x00;
|
|
|
|
|
|
|
|
if ((ret = send_data(dev, endp_down,
|
|
|
|
cmdbuf, 16)))
|
2014-02-11 20:11:33 -05:00
|
|
|
goto done;
|
2013-07-08 21:59:51 -04:00
|
|
|
|
2013-12-21 22:55:33 -05:00
|
|
|
ret = read_data(dev, endp_up,
|
|
|
|
respbuf, sizeof(respbuf), &num);
|
|
|
|
if (ret < 0)
|
2014-02-11 20:11:33 -05:00
|
|
|
goto done;
|
2013-12-21 22:55:33 -05:00
|
|
|
|
|
|
|
if (num != 51) {
|
|
|
|
ERROR("Short read! (%d/%d)\n", num, 51);
|
2014-02-11 20:11:33 -05:00
|
|
|
ret = 4;
|
|
|
|
goto done;
|
2013-07-08 21:59:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Then we can poll the data */
|
|
|
|
cmdbuf[0] = 0x03;
|
|
|
|
cmdbuf[1] = 0x1b;
|
|
|
|
cmdbuf[2] = 0x43;
|
|
|
|
cmdbuf[3] = 0x48;
|
|
|
|
cmdbuf[4] = 0x43;
|
|
|
|
cmdbuf[5] = 0x0c;
|
|
|
|
cmdbuf[6] = 0x54;
|
|
|
|
cmdbuf[7] = 0x4f;
|
|
|
|
cmdbuf[8] = 0x4e;
|
|
|
|
cmdbuf[9] = 0x45;
|
|
|
|
cmdbuf[10] = 0x20;
|
|
|
|
for (i = 0 ; i < 24 ; i++) {
|
|
|
|
if ((ret = send_data(dev, endp_down,
|
|
|
|
cmdbuf, 11)))
|
2014-02-11 20:11:33 -05:00
|
|
|
goto done;
|
2013-07-08 21:59:51 -04:00
|
|
|
|
2013-12-21 22:55:33 -05:00
|
|
|
ret = read_data(dev, endp_up,
|
|
|
|
respbuf, sizeof(respbuf), &num);
|
|
|
|
if (ret < 0)
|
2014-02-11 20:11:33 -05:00
|
|
|
goto done;
|
|
|
|
|
2013-12-21 22:55:33 -05:00
|
|
|
if (num != 64) {
|
|
|
|
ERROR("Short read! (%d/%d)\n", num, 51);
|
2014-02-11 20:11:33 -05:00
|
|
|
ret = 4;
|
|
|
|
goto done;
|
2013-07-08 21:59:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy into buffer */
|
|
|
|
memcpy(((uint8_t*)data)+i*64, respbuf, 64);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open file and write it out */
|
|
|
|
{
|
2013-11-25 09:09:29 -05:00
|
|
|
int tc_fd = open(fname, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
|
2014-02-11 20:11:33 -05:00
|
|
|
if (tc_fd < 0) {
|
|
|
|
ret = 4;
|
|
|
|
goto done;
|
|
|
|
}
|
2013-11-25 09:09:29 -05:00
|
|
|
|
2013-07-08 21:59:51 -04:00
|
|
|
for (i = 0 ; i < 768; i++) {
|
|
|
|
/* Byteswap appropriately */
|
|
|
|
data[i] = cpu_to_be16(le16_to_cpu(data[i]));
|
|
|
|
write(tc_fd, &data[i], sizeof(uint16_t));
|
|
|
|
}
|
|
|
|
close(tc_fd);
|
|
|
|
}
|
|
|
|
|
2014-02-11 20:11:33 -05:00
|
|
|
done:
|
2013-07-08 21:59:51 -04:00
|
|
|
/* We're done */
|
|
|
|
free(data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-07-18 18:03:40 -04:00
|
|
|
static int kodak6800_set_tonecurve(struct kodak6800_ctx *ctx, char *fname)
|
2013-07-08 22:33:54 -04:00
|
|
|
{
|
2013-07-18 18:03:40 -04:00
|
|
|
libusb_device_handle *dev = ctx->dev;
|
|
|
|
uint8_t endp_down = ctx->endp_down;
|
|
|
|
uint8_t endp_up = ctx->endp_up;
|
|
|
|
|
2013-07-08 22:33:54 -04:00
|
|
|
uint8_t cmdbuf[64];
|
|
|
|
uint8_t respbuf[64];
|
|
|
|
int ret, num = 0;
|
|
|
|
int remain;
|
|
|
|
|
|
|
|
uint16_t *data = malloc(UPDATE_SIZE);
|
|
|
|
uint8_t *ptr;
|
|
|
|
|
|
|
|
INFO("Set Tone Curve from '%s'\n", fname);
|
|
|
|
|
|
|
|
/* Read in file */
|
|
|
|
int tc_fd = open(fname, O_RDONLY);
|
2014-02-11 20:11:33 -05:00
|
|
|
if (tc_fd < 0) {
|
|
|
|
ret = -1;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (read(tc_fd, data, UPDATE_SIZE) != UPDATE_SIZE) {
|
|
|
|
ret = -2;
|
|
|
|
goto done;
|
|
|
|
}
|
2013-07-08 22:33:54 -04:00
|
|
|
close(tc_fd);
|
|
|
|
|
|
|
|
/* Byteswap data to printer's format */
|
2013-11-24 10:53:39 -05:00
|
|
|
for (ret = 0; ret < (UPDATE_SIZE)/2 ; ret++) {
|
2013-07-08 22:33:54 -04:00
|
|
|
data[ret] = cpu_to_le16(be16_to_cpu(data[ret]));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initial Request */
|
|
|
|
cmdbuf[0] = 0x03;
|
|
|
|
cmdbuf[1] = 0x1b;
|
|
|
|
cmdbuf[2] = 0x43;
|
|
|
|
cmdbuf[3] = 0x48;
|
|
|
|
cmdbuf[4] = 0x43;
|
|
|
|
cmdbuf[5] = 0x0c;
|
|
|
|
cmdbuf[6] = 0x54;
|
|
|
|
cmdbuf[7] = 0x4f;
|
|
|
|
cmdbuf[8] = 0x4e;
|
|
|
|
cmdbuf[9] = 0x45;
|
|
|
|
cmdbuf[10] = 0x77;
|
|
|
|
cmdbuf[11] = 0x01;
|
|
|
|
cmdbuf[12] = 0x00;
|
|
|
|
cmdbuf[13] = 0x00;
|
|
|
|
cmdbuf[14] = 0x00;
|
|
|
|
cmdbuf[15] = 0x00;
|
|
|
|
|
|
|
|
if ((ret = send_data(dev, endp_down,
|
|
|
|
cmdbuf, 16)))
|
2014-02-11 20:11:33 -05:00
|
|
|
goto done;
|
2013-07-08 22:33:54 -04:00
|
|
|
|
2013-12-21 22:55:33 -05:00
|
|
|
ret = read_data(dev, endp_up,
|
|
|
|
respbuf, sizeof(respbuf), &num);
|
|
|
|
if (ret < 0)
|
2014-02-11 20:11:33 -05:00
|
|
|
goto done;
|
2013-12-21 22:55:33 -05:00
|
|
|
|
|
|
|
if (num != 51) {
|
|
|
|
ERROR("Short read! (%d/%d)\n", num, 51);
|
2014-02-11 20:11:33 -05:00
|
|
|
ret = 4;
|
|
|
|
goto done;
|
2013-07-08 22:33:54 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ptr = (uint8_t*) data;
|
|
|
|
remain = UPDATE_SIZE;
|
|
|
|
while (remain > 0) {
|
|
|
|
int count = remain > 63 ? 63 : remain;
|
|
|
|
|
|
|
|
cmdbuf[0] = 0x03;
|
|
|
|
memcpy(cmdbuf+1, ptr, count);
|
|
|
|
|
|
|
|
remain -= count;
|
|
|
|
ptr += count;
|
|
|
|
|
|
|
|
/* Send next block over */
|
|
|
|
if ((ret = send_data(dev, endp_down,
|
|
|
|
cmdbuf, count+1)))
|
2014-02-11 20:11:33 -05:00
|
|
|
goto done;
|
2013-07-08 22:33:54 -04:00
|
|
|
|
2013-12-21 22:55:33 -05:00
|
|
|
|
|
|
|
ret = read_data(dev, endp_up,
|
|
|
|
respbuf, sizeof(respbuf), &num);
|
|
|
|
if (ret < 0)
|
2014-02-11 20:11:33 -05:00
|
|
|
goto done;
|
2013-12-21 22:55:33 -05:00
|
|
|
|
|
|
|
if (num != 51) {
|
|
|
|
ERROR("Short read! (%d/%d)\n", num, 51);
|
2014-02-11 20:11:33 -05:00
|
|
|
ret = 4;
|
|
|
|
goto done;
|
2013-07-08 22:33:54 -04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-02-11 20:11:33 -05:00
|
|
|
done:
|
2013-07-08 22:33:54 -04:00
|
|
|
/* We're done */
|
|
|
|
free(data);
|
2014-02-11 20:11:33 -05:00
|
|
|
return ret;
|
2013-07-08 22:33:54 -04:00
|
|
|
}
|
|
|
|
|
2014-04-12 12:41:09 -04:00
|
|
|
static int kodak6800_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, char *buf, int buf_len)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
int num;
|
|
|
|
|
|
|
|
uint8_t resp[33];
|
|
|
|
uint8_t req[16];
|
|
|
|
|
|
|
|
memset(req, 0, sizeof(req));
|
|
|
|
memset(resp, 0, sizeof(resp));
|
|
|
|
|
|
|
|
req[0] = 0x03;
|
|
|
|
req[1] = 0x1b;
|
|
|
|
req[2] = 0x43;
|
|
|
|
req[3] = 0x48;
|
|
|
|
req[4] = 0x43;
|
|
|
|
req[5] = 0x03;
|
|
|
|
|
|
|
|
/* Send request */
|
|
|
|
if ((ret = send_data(dev, endp_down,
|
|
|
|
req, sizeof(req))))
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Get response */
|
|
|
|
ret = read_data(dev, endp_up,
|
|
|
|
resp, sizeof(resp) - 1, &num);
|
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
if (num != 32) {
|
|
|
|
ERROR("Short read! (%d/%d)\n", num, 32);
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
strncpy(buf, (char*)resp+24, buf_len);
|
|
|
|
buf[buf_len-1] = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-07-09 19:31:49 -04:00
|
|
|
static int kodak6850_send_init(struct kodak6800_ctx *ctx)
|
|
|
|
{
|
|
|
|
uint8_t cmdbuf[64];
|
|
|
|
uint8_t rdbuf[64];
|
|
|
|
int ret = 0, num = 0;
|
|
|
|
|
|
|
|
memset(cmdbuf, 0, CMDBUF_LEN);
|
|
|
|
cmdbuf[0] = 0x03;
|
|
|
|
cmdbuf[1] = 0x1b;
|
|
|
|
cmdbuf[2] = 0x43;
|
|
|
|
cmdbuf[3] = 0x48;
|
|
|
|
cmdbuf[4] = 0x43;
|
|
|
|
cmdbuf[5] = 0x4c;
|
|
|
|
|
|
|
|
if ((ret = send_data(ctx->dev, ctx->endp_down,
|
|
|
|
cmdbuf, CMDBUF_LEN -1)))
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
|
|
|
/* Read response */
|
|
|
|
ret = read_data(ctx->dev, ctx->endp_up,
|
|
|
|
rdbuf, READBACK_LEN, &num);
|
|
|
|
if (ret < 0)
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
|
|
|
|
if (num < 51) {
|
|
|
|
ERROR("Short read! (%d/%d)\n", num, 51);
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num != 51) {
|
|
|
|
ERROR("Unexpected readback from printer (%d/%d from 0x%02x))\n",
|
|
|
|
num, READBACK_LEN, ctx->endp_up);
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rdbuf[0] != 0x01 ||
|
|
|
|
rdbuf[2] != 0x43) {
|
|
|
|
ERROR("Unexpected response from printer init!\n");
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX I believe this the media position
|
|
|
|
// saying when we have a 4x6 left on an 8x6 blank
|
|
|
|
if (rdbuf[1] != 0x01 && rdbuf[1] != 0x00) {
|
|
|
|
ERROR("Unexpected status code (0x%02x)!\n", rdbuf[1]);
|
|
|
|
return CUPS_BACKEND_FAILED;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-10 20:10:36 -05:00
|
|
|
static void kodak6800_cmdline(void)
|
2013-06-27 22:45:32 -04:00
|
|
|
{
|
2014-02-10 20:10:36 -05:00
|
|
|
DEBUG("\t\t[ -c filename ] # Get tone curve\n");
|
|
|
|
DEBUG("\t\t[ -C filename ] # Set tone curve\n");
|
2014-04-12 12:41:09 -04:00
|
|
|
DEBUG("\t\t[ -m ] # Query media\n");
|
2014-06-02 22:16:28 -04:00
|
|
|
DEBUG("\t\t[ -s ] # Query status\n");
|
2013-07-18 18:03:40 -04:00
|
|
|
}
|
2013-06-27 22:45:32 -04:00
|
|
|
|
2014-02-10 20:10:36 -05:00
|
|
|
static int kodak6800_cmdline_arg(void *vctx, int argc, char **argv)
|
2013-07-18 18:03:40 -04:00
|
|
|
{
|
|
|
|
struct kodak6800_ctx *ctx = vctx;
|
2014-02-11 22:45:14 -05:00
|
|
|
int i, j = 0;
|
2013-06-27 22:45:32 -04:00
|
|
|
|
2014-02-10 20:10:36 -05:00
|
|
|
/* Reset arg parsing */
|
|
|
|
optind = 1;
|
|
|
|
opterr = 0;
|
2014-06-02 22:16:28 -04:00
|
|
|
while ((i = getopt(argc, argv, "C:c:ms")) >= 0) {
|
2014-02-10 20:10:36 -05:00
|
|
|
switch(i) {
|
|
|
|
case 'c':
|
2014-02-11 22:45:14 -05:00
|
|
|
if (ctx) {
|
|
|
|
j = kodak6800_get_tonecurve(ctx, optarg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
2014-02-10 20:10:36 -05:00
|
|
|
case 'C':
|
2014-02-11 22:45:14 -05:00
|
|
|
if (ctx) {
|
|
|
|
j = kodak6800_set_tonecurve(ctx, optarg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
2014-04-12 12:41:09 -04:00
|
|
|
case 'm':
|
|
|
|
if (ctx) {
|
2014-10-04 11:55:56 -04:00
|
|
|
uint8_t mediabuf[MAX_MEDIA_LEN];
|
|
|
|
struct kodak68x0_media_readback *media = (struct kodak68x0_media_readback*)mediabuf;
|
2014-06-02 22:16:28 -04:00
|
|
|
j = kodak6800_get_mediainfo(ctx, media);
|
|
|
|
if (!j)
|
|
|
|
kodak68x0_dump_mediainfo(media);
|
2014-04-12 12:41:09 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 1;
|
2014-06-02 22:16:28 -04:00
|
|
|
case 's':
|
|
|
|
if (ctx) {
|
2014-10-04 11:55:56 -04:00
|
|
|
uint8_t mediabuf[MAX_MEDIA_LEN];
|
|
|
|
struct kodak68x0_media_readback *media = (struct kodak68x0_media_readback*)mediabuf;
|
2014-06-02 22:16:28 -04:00
|
|
|
struct kodak68x0_status_readback status;
|
2014-10-04 11:55:56 -04:00
|
|
|
j = kodak6800_get_mediainfo(ctx, media);
|
2014-06-02 22:16:28 -04:00
|
|
|
if (!j)
|
2014-10-04 11:55:56 -04:00
|
|
|
j = kodak6800_get_status(ctx, &status);
|
|
|
|
if (!j)
|
|
|
|
kodak68x0_dump_status(ctx, &status);
|
2014-06-02 22:16:28 -04:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
2014-04-12 12:41:09 -04:00
|
|
|
|
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-06-27 22:45:32 -04:00
|
|
|
|
2014-02-10 20:10:36 -05:00
|
|
|
return 0;
|
2013-07-18 18:03:40 -04:00
|
|
|
}
|
2013-06-27 22:45:32 -04:00
|
|
|
|
|
|
|
|
2013-07-19 09:23:53 -04:00
|
|
|
static void *kodak6800_init(void)
|
2013-07-18 18:03:40 -04:00
|
|
|
{
|
|
|
|
struct kodak6800_ctx *ctx = malloc(sizeof(struct kodak6800_ctx));
|
|
|
|
if (!ctx)
|
|
|
|
return NULL;
|
|
|
|
memset(ctx, 0, sizeof(struct kodak6800_ctx));
|
2013-07-19 09:23:53 -04:00
|
|
|
|
2013-07-25 17:13:36 -04:00
|
|
|
ctx->type = P_ANY;
|
2014-10-04 11:55:56 -04:00
|
|
|
ctx->media = -1;
|
2013-07-25 17:13:36 -04:00
|
|
|
|
2013-07-19 09:23:53 -04:00
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void kodak6800_attach(void *vctx, struct libusb_device_handle *dev,
|
|
|
|
uint8_t endp_up, uint8_t endp_down, uint8_t jobid)
|
|
|
|
{
|
|
|
|
struct kodak6800_ctx *ctx = vctx;
|
2013-07-25 17:13:36 -04:00
|
|
|
struct libusb_device *device;
|
|
|
|
struct libusb_device_descriptor desc;
|
2013-07-19 09:23:53 -04:00
|
|
|
|
2013-11-23 19:51:55 -05:00
|
|
|
UNUSED(jobid);
|
|
|
|
|
2013-07-19 09:23:53 -04:00
|
|
|
ctx->dev = dev;
|
2013-07-18 18:03:40 -04:00
|
|
|
ctx->endp_up = endp_up;
|
|
|
|
ctx->endp_down = endp_down;
|
2013-07-25 17:13:36 -04:00
|
|
|
|
2013-07-26 16:29:22 -04:00
|
|
|
device = libusb_get_device(dev);
|
|
|
|
libusb_get_device_descriptor(device, &desc);
|
|
|
|
|
2013-07-25 17:13:36 -04:00
|
|
|
/* Map out device type */
|
|
|
|
if (desc.idProduct == USB_PID_KODAK_6850)
|
|
|
|
ctx->type = P_KODAK_6850;
|
|
|
|
else
|
|
|
|
ctx->type = P_KODAK_6800;
|
2013-07-18 18:03:40 -04:00
|
|
|
}
|
2013-06-27 22:45:32 -04:00
|
|
|
|
2013-07-18 18:03:40 -04:00
|
|
|
static void kodak6800_teardown(void *vctx) {
|
|
|
|
struct kodak6800_ctx *ctx = vctx;
|
2013-06-27 22:45:32 -04:00
|
|
|
|
2013-07-18 18:03:40 -04:00
|
|
|
if (!ctx)
|
|
|
|
return;
|
2013-06-27 22:45:32 -04:00
|
|
|
|
2013-07-18 18:03:40 -04:00
|
|
|
if (ctx->databuf)
|
|
|
|
free(ctx->databuf);
|
|
|
|
free(ctx);
|
|
|
|
}
|
2013-07-08 21:59:51 -04:00
|
|
|
|
2013-07-18 18:03:40 -04:00
|
|
|
static int kodak6800_read_parse(void *vctx, int data_fd) {
|
|
|
|
struct kodak6800_ctx *ctx = vctx;
|
2014-01-13 18:30:30 -05:00
|
|
|
int ret;
|
2013-06-27 22:45:32 -04:00
|
|
|
|
2013-07-18 18:03:40 -04:00
|
|
|
if (!ctx)
|
2014-04-25 11:34:53 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-06-27 22:45:32 -04:00
|
|
|
|
2014-01-21 20:34:00 -05:00
|
|
|
if (ctx->databuf) {
|
2014-01-17 22:54:25 -05:00
|
|
|
free(ctx->databuf);
|
2014-01-21 20:34:00 -05:00
|
|
|
ctx->databuf = NULL;
|
|
|
|
}
|
2014-01-17 22:54:25 -05:00
|
|
|
|
2013-06-27 22:45:32 -04:00
|
|
|
/* Read in then validate header */
|
2014-01-13 18:30:30 -05:00
|
|
|
ret = read(data_fd, &ctx->hdr, sizeof(ctx->hdr));
|
|
|
|
if (ret < 0 || ret != sizeof(ctx->hdr)) {
|
2014-01-20 19:41:52 -05:00
|
|
|
if (ret == 0)
|
2014-04-25 11:34:53 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
|
|
|
ERROR("Read failed (%d/%d/%d)\n",
|
2014-01-13 18:30:30 -05:00
|
|
|
ret, 0, (int)sizeof(ctx->hdr));
|
|
|
|
perror("ERROR: Read failed");
|
2014-04-25 11:34:53 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2014-01-13 18:30:30 -05:00
|
|
|
}
|
2013-07-18 20:32:44 -04:00
|
|
|
if (ctx->hdr.hdr[0] != 0x03 ||
|
|
|
|
ctx->hdr.hdr[1] != 0x1b ||
|
|
|
|
ctx->hdr.hdr[2] != 0x43 ||
|
|
|
|
ctx->hdr.hdr[3] != 0x48 ||
|
|
|
|
ctx->hdr.hdr[4] != 0x43) {
|
2013-06-27 22:45:32 -04:00
|
|
|
ERROR("Unrecognized data format!\n");
|
2014-04-25 11:34:53 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2013-06-27 22:45:32 -04:00
|
|
|
}
|
|
|
|
|
2013-07-18 20:32:44 -04:00
|
|
|
ctx->datalen = be16_to_cpu(ctx->hdr.rows) * be16_to_cpu(ctx->hdr.columns) * 3;
|
2013-07-18 18:03:40 -04:00
|
|
|
ctx->databuf = malloc(ctx->datalen);
|
|
|
|
if (!ctx->databuf) {
|
2013-06-27 22:45:32 -04:00
|
|
|
ERROR("Memory allocation failure!\n");
|
2014-04-25 11:34:53 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-06-27 22:45:32 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2013-07-18 18:03:40 -04:00
|
|
|
int remain = ctx->datalen;
|
|
|
|
uint8_t *ptr = ctx->databuf;
|
2013-06-27 22:45:32 -04:00
|
|
|
do {
|
|
|
|
ret = read(data_fd, ptr, remain);
|
|
|
|
if (ret < 0) {
|
|
|
|
ERROR("Read failed (%d/%d/%d)\n",
|
2013-07-18 18:03:40 -04:00
|
|
|
ret, remain, ctx->datalen);
|
2013-06-27 22:45:32 -04:00
|
|
|
perror("ERROR: Read failed");
|
2014-04-25 11:34:53 -04:00
|
|
|
return CUPS_BACKEND_CANCEL;
|
2013-06-27 22:45:32 -04:00
|
|
|
}
|
|
|
|
ptr += ret;
|
|
|
|
remain -= ret;
|
|
|
|
} while (remain);
|
|
|
|
}
|
|
|
|
|
2014-04-25 11:34:53 -04:00
|
|
|
return CUPS_BACKEND_OK;
|
2013-07-18 18:03:40 -04:00
|
|
|
}
|
2013-06-27 22:45:32 -04:00
|
|
|
|
2013-07-18 20:32:44 -04:00
|
|
|
static int kodak6800_main_loop(void *vctx, int copies) {
|
|
|
|
struct kodak6800_ctx *ctx = vctx;
|
2014-07-09 19:31:49 -04:00
|
|
|
struct kodak68x0_status_readback status;
|
2013-07-18 20:32:44 -04:00
|
|
|
|
|
|
|
uint8_t cmdbuf[CMDBUF_LEN];
|
|
|
|
|
2014-06-02 22:16:28 -04:00
|
|
|
uint8_t mediabuf[MAX_MEDIA_LEN];
|
|
|
|
struct kodak68x0_media_readback *media = (struct kodak68x0_media_readback*)mediabuf;
|
|
|
|
|
2013-12-21 22:55:33 -05:00
|
|
|
int num, ret;
|
2013-07-18 20:32:44 -04:00
|
|
|
|
|
|
|
if (!ctx)
|
2014-04-25 11:34:53 -04:00
|
|
|
return CUPS_BACKEND_FAILED;
|
2013-07-18 20:32:44 -04:00
|
|
|
|
2014-02-15 08:37:57 -05:00
|
|
|
/* Printer handles generating copies.. */
|
|
|
|
if (ctx->hdr.copies < copies)
|
|
|
|
ctx->hdr.copies = copies;
|
|
|
|
copies = 1;
|
|
|
|
|
2014-06-02 22:16:28 -04:00
|
|
|
/* Query loaded media */
|
|
|
|
INFO("Querying loaded media\n");
|
|
|
|