common: Pass bInterfaceNo into backend->query_serno() call

Also allow the USB iSerialNumber value to be ignored.
This commit is contained in:
Solomon Peachy 2019-11-06 14:18:49 -05:00
parent e0d098bfab
commit b41803ef9e
11 changed files with 26 additions and 13 deletions

View File

@ -594,14 +594,15 @@ candidate:
serial = url_encode(serial);
} else if ((serial = dict_find("SERN", dlen, dict))) {
serial = url_encode(serial);
} else if (desc->iSerialNumber) { /* Get from USB descriptor */
} else if (!(backend->flags & BACKEND_FLAG_BADISERIAL) &&
desc->iSerialNumber) { /* Get from USB descriptor, if we can trust it.. */
libusb_get_string_descriptor_ascii(dev, desc->iSerialNumber, (unsigned char*)buf, STR_LEN_MAX);
sanitize_string(buf);
serial = url_encode(buf);
} else if (backend->query_serno) { /* Get from backend hook */
buf[0] = 0;
/* Ignore result since a failure isn't critical here */
backend->query_serno(dev, endp_up, endp_down, buf, STR_LEN_MAX);
backend->query_serno(dev, endp_up, endp_down, iface, buf, STR_LEN_MAX);
serial = url_encode(buf);
}

View File

@ -198,7 +198,8 @@ struct marker {
int numtype; /* Numerical type, (-1 for unknown) */
};
#define BACKEND_FLAG_JOBLIST 0x00000001
#define BACKEND_FLAG_JOBLIST 0x00000001
#define BACKEND_FLAG_BADISERIAL 0x00000002
/* Backend Functions */
struct dyesub_backend {
@ -215,7 +216,7 @@ struct dyesub_backend {
int (*read_parse)(void *ctx, const void **job, int data_fd, int copies);
void (*cleanup_job)(const void *job);
int (*main_loop)(void *ctx, const void *job);
int (*query_serno)(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, char *buf, int buf_len); /* Optional */
int (*query_serno)(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len); /* Optional */
int (*query_markers)(void *ctx, struct marker **markers, int *count);
const struct device_id devices[];
};

View File

@ -667,7 +667,7 @@ static uint8_t *dnpds40_resp_cmd2(struct dnpds40_ctx *ctx,
#define dnpds40_resp_cmd(__ctx, __cmd, __len) dnpds40_resp_cmd2(__ctx, __cmd, __len, NULL, 0)
static int dnpds40_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, char *buf, int buf_len)
static int dnpds40_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
{
struct dnpds40_cmd cmd;
uint8_t *resp;
@ -677,6 +677,7 @@ static int dnpds40_query_serno(struct libusb_device_handle *dev, uint8_t endp_up
.dev = dev,
.endp_up = endp_up,
.endp_down = endp_down,
.iface = iface,
};
/* Get Serial Number */

View File

@ -2059,12 +2059,14 @@ static int hiti_query_counter(struct hiti_ctx *ctx, uint8_t arg, uint32_t *resp)
return CUPS_BACKEND_OK;
}
static int hiti_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, char *buf, int buf_len)
static int hiti_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
{
int ret;
uint16_t rsplen = 18;
uint8_t rspbuf[18];
UNUSED(iface);
struct hiti_ctx ctx = {
.dev = dev,
.endp_up = endp_up,

View File

@ -540,7 +540,7 @@ done:
return ret;
}
static int kodak6800_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, char *buf, int buf_len)
static int kodak6800_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
{
struct kodak6800_ctx ctx = {
.dev = dev,
@ -554,6 +554,8 @@ static int kodak6800_query_serno(struct libusb_device_handle *dev, uint8_t endp_
uint8_t resp[33];
uint8_t req[16];
UNUSED(iface);
memset(req, 0, sizeof(req));
memset(resp, 0, sizeof(resp));

View File

@ -2361,7 +2361,7 @@ static int mitsu70x_query_status(struct mitsu70x_ctx *ctx)
return ret;
}
static int mitsu70x_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, char *buf, int buf_len)
static int mitsu70x_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
{
int ret, i;
struct mitsu70x_printerstatus_resp resp = { .hdr = { 0 } };
@ -2371,6 +2371,7 @@ static int mitsu70x_query_serno(struct libusb_device_handle *dev, uint8_t endp_u
.endp_up = endp_up,
.endp_down = endp_down,
};
UNUSED(iface);
ret = mitsu70x_get_printerstatus(&ctx, &resp);

View File

@ -1566,13 +1566,15 @@ static int mitsu9550_query_status2(struct mitsu9550_ctx *ctx)
return ret;
}
static int mitsu9550_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, char *buf, int buf_len)
static int mitsu9550_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
{
struct mitsu9550_cmd cmd;
uint8_t rdbuf[READBACK_LEN];
uint8_t *ptr;
int ret, num, i;
UNUSED(iface);
cmd.cmd[0] = 0x1b;
cmd.cmd[1] = 0x72;
cmd.cmd[2] = 0x6e;

View File

@ -1205,7 +1205,7 @@ printer_error2:
return CUPS_BACKEND_FAILED;
}
static int shinkos1245_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, char *buf, int buf_len)
static int shinkos1245_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
{
struct shinkos1245_resp_getid resp;
int i;
@ -1215,6 +1215,7 @@ static int shinkos1245_query_serno(struct libusb_device_handle *dev, uint8_t end
.endp_up = endp_up,
.endp_down = endp_down,
};
UNUSED(iface);
i = shinkos1245_get_printerid(&ctx, &resp);
if (i < 0)

View File

@ -1101,7 +1101,7 @@ printer_error:
return CUPS_BACKEND_FAILED;
}
static int shinkos2145_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, char *buf, int buf_len)
static int shinkos2145_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
{
struct sinfonia_cmd_hdr cmd;
struct s2145_getunique_resp resp;
@ -1111,6 +1111,7 @@ static int shinkos2145_query_serno(struct libusb_device_handle *dev, uint8_t end
.dev = dev,
.endp_up = endp_up,
.endp_down = endp_down,
.iface = iface,
};
cmd.cmd = cpu_to_le16(SINFONIA_CMD_GETUNIQUE);

View File

@ -779,7 +779,7 @@ const char *dummy_error_codes(uint8_t major, uint8_t minor)
return "Unknown";
}
int sinfonia_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, char *buf, int buf_len)
int sinfonia_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len)
{
struct sinfonia_cmd_hdr cmd;
struct sinfonia_getserial_resp resp;
@ -787,6 +787,7 @@ int sinfonia_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint
struct sinfonia_usbdev sdev = {
.dev = dev,
.iface = iface,
.endp_up = endp_up,
.endp_down = endp_down,
.error_codes = dummy_error_codes,

View File

@ -105,7 +105,7 @@ int sinfonia_gettonecurve(struct sinfonia_usbdev *usbh, int type, char *fname);
int sinfonia_settonecurve(struct sinfonia_usbdev *usbh, int target, char *fname);
int sinfonia_button_set(struct sinfonia_usbdev *dev, int enable);
int sinfonia_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, char *buf, int buf_len);
int sinfonia_query_serno(struct libusb_device_handle *dev, uint8_t endp_up, uint8_t endp_down, int iface, char *buf, int buf_len);
int sinfonia_dumpallparams(struct sinfonia_usbdev *usbh, int known);
const char *sinfonia_paramname(struct sinfonia_usbdev *usbh, int id);