Use glib's byte order functions
This commit is contained in:
parent
294f9ad447
commit
6f633cc771
3 changed files with 9 additions and 35 deletions
|
@ -148,7 +148,7 @@ static int send_cmd(struct fp_dev *dev, unsigned char seq_a,
|
||||||
|
|
||||||
/* Write header */
|
/* Write header */
|
||||||
strncpy(buf, "Ciao", 4);
|
strncpy(buf, "Ciao", 4);
|
||||||
len = cpu_to_le16(len);
|
len = GUINT16_TO_LE(len);
|
||||||
buf[4] = seq_a;
|
buf[4] = seq_a;
|
||||||
buf[5] = seq_b | ((len & 0xf00) >> 8);
|
buf[5] = seq_b | ((len & 0xf00) >> 8);
|
||||||
buf[6] = len & 0x00ff;
|
buf[6] = len & 0x00ff;
|
||||||
|
@ -158,7 +158,7 @@ static int send_cmd(struct fp_dev *dev, unsigned char seq_a,
|
||||||
memcpy(buf + 7, data, len);
|
memcpy(buf + 7, data, len);
|
||||||
|
|
||||||
/* Append CRC */
|
/* Append CRC */
|
||||||
crc = cpu_to_be16(udf_crc(buf + 4, urblen - 6));
|
crc = GUINT16_TO_BE(udf_crc(buf + 4, urblen - 6));
|
||||||
buf[urblen - 2] = crc >> 8;
|
buf[urblen - 2] = crc >> 8;
|
||||||
buf[urblen - 1] = crc & 0xff;
|
buf[urblen - 1] = crc & 0xff;
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ static int send_cmd28(struct fp_dev *dev, unsigned char subcmd,
|
||||||
|
|
||||||
fp_dbg("seq=%02x subcmd=%02x with %d bytes of data", seq, subcmd, innerlen);
|
fp_dbg("seq=%02x subcmd=%02x with %d bytes of data", seq, subcmd, innerlen);
|
||||||
|
|
||||||
_innerlen = cpu_to_le16(innerlen + 3);
|
_innerlen = GUINT16_TO_LE(innerlen + 3);
|
||||||
buf[0] = 0x28;
|
buf[0] = 0x28;
|
||||||
buf[1] = _innerlen & 0x00ff;
|
buf[1] = _innerlen & 0x00ff;
|
||||||
buf[2] = (_innerlen & 0xff00) >> 8;
|
buf[2] = (_innerlen & 0xff00) >> 8;
|
||||||
|
@ -233,7 +233,7 @@ static unsigned char *__read_msg(struct fp_dev *dev, size_t *data_len)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = le16_to_cpu(((buf[5] & 0xf) << 8) | buf[6]);
|
len = GUINT16_FROM_LE(((buf[5] & 0xf) << 8) | buf[6]);
|
||||||
|
|
||||||
if (r != MSG_READ_BUF_SIZE && (len + 9) < r) {
|
if (r != MSG_READ_BUF_SIZE && (len + 9) < r) {
|
||||||
/* Check that the length claimed inside the message is in line with
|
/* Check that the length claimed inside the message is in line with
|
||||||
|
@ -263,7 +263,7 @@ static unsigned char *__read_msg(struct fp_dev *dev, size_t *data_len)
|
||||||
}
|
}
|
||||||
|
|
||||||
computed_crc = udf_crc(buf + 4, len + 3);
|
computed_crc = udf_crc(buf + 4, len + 3);
|
||||||
msg_crc = le16_to_cpu((buf[len + 8] << 8) | buf[len + 7]);
|
msg_crc = GUINT16_FROM_LE((buf[len + 8] << 8) | buf[len + 7]);
|
||||||
if (computed_crc != msg_crc) {
|
if (computed_crc != msg_crc) {
|
||||||
fp_err("CRC failed, got %04x expected %04x", msg_crc, computed_crc);
|
fp_err("CRC failed, got %04x expected %04x", msg_crc, computed_crc);
|
||||||
goto err;
|
goto err;
|
||||||
|
@ -301,7 +301,7 @@ retry:
|
||||||
|
|
||||||
code_a = buf[4];
|
code_a = buf[4];
|
||||||
code_b = buf[5] & 0xf0;
|
code_b = buf[5] & 0xf0;
|
||||||
len = le16_to_cpu(((buf[5] & 0xf) << 8) | buf[6]);
|
len = GUINT16_FROM_LE(((buf[5] & 0xf) << 8) | buf[6]);
|
||||||
fp_dbg("A=%02x B=%02x len=%d", code_a, code_b, len);
|
fp_dbg("A=%02x B=%02x len=%d", code_a, code_b, len);
|
||||||
|
|
||||||
if (code_a && !code_b) {
|
if (code_a && !code_b) {
|
||||||
|
@ -346,7 +346,7 @@ retry:
|
||||||
}
|
}
|
||||||
|
|
||||||
innerlen = innerbuf[1] | (innerbuf[2] << 8);
|
innerlen = innerbuf[1] | (innerbuf[2] << 8);
|
||||||
innerlen = le16_to_cpu(innerlen) - 3;
|
innerlen = GUINT16_FROM_LE(innerlen) - 3;
|
||||||
_subcmd = innerbuf[5];
|
_subcmd = innerbuf[5];
|
||||||
fp_dbg("device responds to subcmd %x with %d bytes", _subcmd, innerlen);
|
fp_dbg("device responds to subcmd %x with %d bytes", _subcmd, innerlen);
|
||||||
if (seq)
|
if (seq)
|
||||||
|
|
|
@ -188,7 +188,7 @@ retry:
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
type = be16_to_cpu(*((uint16_t *) buf));
|
type = GUINT16_FROM_BE(*((uint16_t *) buf));
|
||||||
fp_dbg("irq type %04x", type);
|
fp_dbg("irq type %04x", type);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -212,7 +212,7 @@ static int get_irq_with_type(struct fp_img_dev *dev, uint16_t irqtype,
|
||||||
r = get_irq(dev, irqbuf, timeout);
|
r = get_irq(dev, irqbuf, timeout);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
hdr = be16_to_cpu(*((uint16_t *) irqbuf));
|
hdr = GUINT16_FROM_BE(*((uint16_t *) irqbuf));
|
||||||
} while (hdr != irqtype);
|
} while (hdr != irqtype);
|
||||||
|
|
||||||
if (discarded > 0)
|
if (discarded > 0)
|
||||||
|
|
|
@ -21,22 +21,11 @@
|
||||||
#define __FPRINT_INTERNAL_H__
|
#define __FPRINT_INTERNAL_H__
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <usb.h>
|
#include <usb.h>
|
||||||
|
|
||||||
#ifdef __DARWIN_NULL
|
|
||||||
/* Darwin does endianness slightly differently */
|
|
||||||
#include <machine/endian.h>
|
|
||||||
#define __BYTE_ORDER BYTE_ORDER
|
|
||||||
#define __LITTLE_ENDIAN LITTLE_ENDIAN
|
|
||||||
#define __BIG_ENDIAN BIG_ENDIAN
|
|
||||||
#else /* Linux */
|
|
||||||
#include <endian.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <fprint.h>
|
#include <fprint.h>
|
||||||
|
|
||||||
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
|
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
|
||||||
|
@ -201,20 +190,5 @@ int fpi_img_detect_minutiae(struct fp_img_dev *imgdev, struct fp_img *img,
|
||||||
int fpi_img_compare_print_data(struct fp_print_data *enrolled_print,
|
int fpi_img_compare_print_data(struct fp_print_data *enrolled_print,
|
||||||
struct fp_print_data *new_print);
|
struct fp_print_data *new_print);
|
||||||
|
|
||||||
#define bswap16(x) (((x & 0xff) << 8) | (x >> 8))
|
|
||||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
|
||||||
#define cpu_to_le16(x) (x)
|
|
||||||
#define le16_to_cpu(x) (x)
|
|
||||||
#define cpu_to_be16(x) bswap16(x)
|
|
||||||
#define be16_to_cpu(x) bswap16(x)
|
|
||||||
#elif __BYTE_ORDER == __BIG_ENDIAN
|
|
||||||
#define cpu_to_le16(x) bswap16(x)
|
|
||||||
#define le16_to_cpu(x) bswap16(x)
|
|
||||||
#define cpu_to_be16(x) (x)
|
|
||||||
#define be16_to_cpu(x) (x)
|
|
||||||
#else
|
|
||||||
#error "Unrecognized endianness"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue