Commit 3661d146 authored by Bastien Nocera's avatar Bastien Nocera

drivers: Remove UPEKE2 driver

The device is already handled by upektc_img driver, and its sources
still exist in git if needed.

https://bugs.freedesktop.org/show_bug.cgi?id=106514
parent 3bf55a3e
......@@ -30,7 +30,6 @@ require_aeslib='no'
require_aesX660='no'
require_aes3k='no'
require_nss='no'
enable_upeke2='no'
enable_upekts='no'
enable_upektc='no'
enable_upeksonly='no'
......@@ -67,10 +66,6 @@ for driver in `echo ${drivers} | sed -e 's/,/ /g' -e 's/,$//g'`; do
AC_DEFINE([ENABLE_UPEKTS], [], [Build UPEK TouchStrip driver])
enable_upekts="yes"
;;
upeke2)
AC_DEFINE([ENABLE_UPEKE2], [], [Build UPEK Eikon 2])
enable_upeke2="yes"
;;
upektc)
AC_DEFINE([ENABLE_UPEKTC], [], [Build UPEK TouchChip driver])
enable_upektc="yes"
......@@ -166,7 +161,6 @@ for driver in `echo ${drivers} | sed -e 's/,/ /g' -e 's/,$//g'`; do
done
AM_CONDITIONAL([ENABLE_UPEKTS], [test "$enable_upekts" = "yes"])
AM_CONDITIONAL([ENABLE_UPEKE2], [test "$enable_upeke2" = "yes"])
AM_CONDITIONAL([ENABLE_UPEKTC], [test "$enable_upektc" = "yes"])
AM_CONDITIONAL([ENABLE_UPEKSONLY], [test "$enable_upeksonly" = "yes"])
AM_CONDITIONAL([ENABLE_VCOM5S], [test "$enable_vcom5s" = "yes"])
......@@ -325,11 +319,6 @@ if test x$enable_upekts != xno ; then
else
AC_MSG_NOTICE([ upekts driver disabled])
fi
if test x$enable_upeke2 != xno ; then
AC_MSG_NOTICE([** upeke2 driver enabled])
else
AC_MSG_NOTICE([ upeke2 driver disabled (handled by upektc_img driver)])
fi
if test x$enable_upektc != xno ; then
AC_MSG_NOTICE([** upektc driver enabled])
else
......
......@@ -2,7 +2,6 @@ lib_LTLIBRARIES = libfprint.la
noinst_PROGRAMS = fprint-list-udev-rules
MOSTLYCLEANFILES = $(udev_rules_DATA)
UPEKE2_SRC = drivers/upeke2.c
UPEKTS_SRC = drivers/upekts.c
UPEKTC_SRC = drivers/upektc.c drivers/upektc.h
UPEKSONLY_SRC = drivers/upeksonly.c drivers/upeksonly.h
......@@ -25,7 +24,6 @@ VFS0050_SRC = drivers/vfs0050.c drivers/vfs0050.h
ELAN_SRC = drivers/elan.c drivers/elan.h
EXTRA_DIST = \
$(UPEKE2_SRC) \
$(UPEKTS_SRC) \
$(UPEKTC_SRC) \
$(UPEKSONLY_SRC) \
......@@ -112,10 +110,6 @@ $(udev_rules_DATA): fprint-list-udev-rules
$(builddir)/fprint-list-udev-rules > $@
endif
if ENABLE_UPEKE2
DRIVER_SRC += $(UPEKE2_SRC)
endif
if ENABLE_UPEKTS
DRIVER_SRC += $(UPEKTS_SRC)
endif
......
......@@ -343,9 +343,6 @@ static struct fp_driver * const primitive_drivers[] = {
#ifdef ENABLE_UPEKTS
&upekts_driver,
#endif
#ifdef ENABLE_UPEKE2
&upeke2_driver,
#endif
};
static struct fp_img_driver * const img_drivers[] = {
......
......@@ -33,7 +33,7 @@ enum {
VFS101_ID = 10,
VFS301_ID = 11,
AES2550_ID = 12,
UPEKE2_ID = 13,
/* UPEKE2_ID = 13 */
AES1660_ID = 14,
AES2660_ID = 15,
AES3500_ID = 16,
......
/*
* Copyright (C) 2010 Jorge Suarez de Lis <yo@jorgesuarezdelis.name>
*
* Heavily based on UPEK TouchStrip driver for libfprint
* Copyright (C) 2007-2008 Daniel Drake <dsd@gentoo.org>
*
* Based in part on libthinkfinger:
* Copyright (C) 2006-2007 Timo Hoenig <thoenig@suse.de>
* Copyright (C) 2006 Pavel Machek <pavel@suse.cz>
*
* LGPL CRC code copied from GStreamer-0.10.10:
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) 2004,2006 Thomas Vander Stichele <thomas at apestaart dot org>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version
* 2.1 of the License.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#define FP_COMPONENT "upeke2"
#include <errno.h>
#include <string.h>
#include <glib.h>
#include <libusb.h>
#include <fp_internal.h>
#include "driver_ids.h"
#define EP_IN (1 | LIBUSB_ENDPOINT_IN)
#define EP_OUT (2 | LIBUSB_ENDPOINT_OUT)
#define TIMEOUT 5000
#define MSG_READ_BUF_SIZE 0x40
#define MAX_DATA_IN_READ_BUF (MSG_READ_BUF_SIZE - 9)
enum {
UPEKE2_2016,
};
struct upeke2_dev {
gboolean enroll_passed;
gboolean first_verify_iteration;
gboolean stop_verify;
uint8_t seq; /* FIXME: improve/automate seq handling */
};
static const uint16_t crc_table[256] = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
};
static uint16_t udf_crc(unsigned char *buffer, size_t size)
{
uint16_t crc = 0;
while (size--)
crc = (uint16_t) ((crc << 8) ^
crc_table[((crc >> 8) & 0x00ff) ^ *buffer++]);
return crc;
}
/*
* MESSAGE FORMAT
*
* Messages to and from the device have the same format.
*
* Byte-wise:
* 'C' 'i' 'a' 'o' A B L <DATA> C1 C2
*
* Ciao prefixes all messages. The rightmost 4 bits of B become the uppermost
* 4 bits of L, and when combined with the lower 8 bits listed as 'L', L is
* the length of the data, <DATA> is L bytes long. C1 and C2 are the
* UDF-CRC16 for the whole message minus the Ciao prefix.
*
* When the device wants to command the driver to do something, it sends
* a message where B=0 and A!=0. The A value indicates the type of command.
* If the system is expected to respond to the command, it sends a message back
* with B=0 and A incremented.
*
* When the driver sends a command to the device, A=0 and B is used as a
* sequence counter. It starts at 0, increments by 0x10 on each command, and
* wraps around.
* After each command is sent, the device responds with another message
* indicating completion of the command including any data that was requested.
* This message has the same A and B values.
*
* When the driver is sending commands as above, and when the device is
* responding, the <DATA> seems to follow this structure:
*
* 28 L1 L2 0 0 S <INNERDATA>
*
* Where the length of <INNERDATA> is L-3, and S is some kind of subcommand
* code. L1 is the least significant bits of L, L2 is the most significant. In
* the device's response to a command, the subcommand code will be unchanged.
*
* After deducing and documenting the above, I found a few places where the
* above doesn't hold true. Those are marked with FIXME's below.
*/
#define CMD_SEQ_INCREMENT 0x10
static struct libusb_transfer *alloc_send_cmd_transfer(struct fp_dev *dev,
unsigned char seq_a, unsigned char seq_b, const unsigned char *data,
uint16_t len, libusb_transfer_cb_fn callback, void *user_data)
{
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
uint16_t crc;
/* 9 bytes extra for: 4 byte 'Ciao', 1 byte A, 1 byte B | lenHI,
* 1 byte lenLO, 2 byte CRC */
size_t urblen = len + 9;
unsigned char *buf;
if (!transfer)
return NULL;
if (!data && len > 0) {
fp_err("len>0 but no data?");
return NULL;
}
buf = g_malloc(urblen);
/* Write header */
strncpy(buf, "Ciao", 4);
len = GUINT16_TO_LE(len);
buf[4] = seq_a;
buf[5] = seq_b | ((len & 0xf00) >> 8);
buf[6] = len & 0x00ff;
/* Copy data */
if (data)
memcpy(buf + 7, data, len);
/* Append CRC */
crc = GUINT16_TO_BE(udf_crc(buf + 4, urblen - 6));
buf[urblen - 2] = crc >> 8;
buf[urblen - 1] = crc & 0xff;
libusb_fill_bulk_transfer(transfer, dev->udev, EP_OUT, buf, urblen,
callback, user_data, TIMEOUT);
return transfer;
}
static struct libusb_transfer *alloc_send_cmd28_transfer(struct fp_dev *dev,
unsigned char subcmd, const unsigned char *data, uint16_t innerlen,
libusb_transfer_cb_fn callback, void *user_data)
{
uint16_t _innerlen = innerlen;
size_t len = innerlen + 6;
unsigned char *buf = g_malloc0(len);
struct upeke2_dev *upekdev = dev->priv;
uint8_t seq = upekdev->seq + CMD_SEQ_INCREMENT;
struct libusb_transfer *ret;
fp_dbg("seq=%02x subcmd=%02x with %d bytes of data", seq, subcmd, innerlen);
_innerlen = GUINT16_TO_LE(innerlen + 3);
buf[0] = 0x28;
buf[1] = _innerlen & 0x00ff;
buf[2] = (_innerlen & 0xff00) >> 8;
buf[5] = subcmd;
memcpy(buf + 6, data, innerlen);
ret = alloc_send_cmd_transfer(dev, 0, seq, buf, len, callback, user_data);
upekdev->seq = seq;
g_free(buf);
return ret;
}
static struct libusb_transfer *alloc_send_cmdresponse_transfer(
struct fp_dev *dev, unsigned char seq, const unsigned char *data,
uint8_t len, libusb_transfer_cb_fn callback, void *user_data)
{
fp_dbg("seq=%02x len=%d", seq, len);
return alloc_send_cmd_transfer(dev, seq, 0, data, len, callback, user_data);
}
enum read_msg_status {
READ_MSG_ERROR,
READ_MSG_CMD,
READ_MSG_RESPONSE,
};
typedef void (*read_msg_cb_fn)(struct fp_dev *dev, enum read_msg_status status,
uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len,
void *user_data);
struct read_msg_data {
struct fp_dev *dev;
read_msg_cb_fn callback;
void *user_data;
};
static int __read_msg_async(struct read_msg_data *udata);
#define READ_MSG_DATA_CB_ERR(udata) (udata)->callback((udata)->dev, \
READ_MSG_ERROR, 0, 0, NULL, 0, (udata)->user_data)
static void busy_ack_sent_cb(struct libusb_transfer *transfer)
{
struct read_msg_data *udata = transfer->user_data;
if (transfer->status != LIBUSB_TRANSFER_COMPLETED ||
transfer->length != transfer->actual_length) {
READ_MSG_DATA_CB_ERR(udata);
g_free(udata);
} else {
int r = __read_msg_async(udata);
if (r < 0) {
READ_MSG_DATA_CB_ERR(udata);
g_free(udata);
}
}
libusb_free_transfer(transfer);
}
static int busy_ack_retry_read(struct read_msg_data *udata)
{
struct libusb_transfer *transfer;
int r;
transfer = alloc_send_cmdresponse_transfer(udata->dev, 0x09, NULL, 0,
busy_ack_sent_cb, udata);
if (!transfer)
return -ENOMEM;
r = libusb_submit_transfer(transfer);
if (r < 0) {
g_free(transfer->buffer);
libusb_free_transfer(transfer);
}
return r;
}
/* Returns 0 if message was handled, 1 if it was a device-busy message, and
* negative on error. */
static int __handle_incoming_msg(struct read_msg_data *udata,
unsigned char *buf)
{
uint16_t len = GUINT16_FROM_LE(((buf[5] & 0xf) << 8) | buf[6]);
uint16_t computed_crc = udf_crc(buf + 4, len + 3);
uint16_t msg_crc = GUINT16_FROM_LE((buf[len + 8] << 8) | buf[len + 7]);
unsigned char *retdata = NULL;
unsigned char code_a, code_b;
if (computed_crc != msg_crc) {
fp_err("CRC failed, got %04x expected %04x", msg_crc, computed_crc);
return -1;
}
code_a = buf[4];
code_b = buf[5] & 0xf0;
len = GUINT16_FROM_LE(((buf[5] & 0xf) << 8) | buf[6]);
fp_dbg("A=%02x B=%02x len=%d", code_a, code_b, len);
if (code_a && !code_b) {
/* device sends command to driver */
fp_dbg("cmd %x from device to driver", code_a);
if (code_a == 0x08) {
int r;
fp_dbg("device busy, send busy-ack");
r = busy_ack_retry_read(udata);
return (r < 0) ? r : 1;
}
if (len > 0) {
retdata = g_malloc(len);
memcpy(retdata, buf + 7, len);
}
udata->callback(udata->dev, READ_MSG_CMD, code_a, 0, retdata, len,
udata->user_data);
g_free(retdata);
} else if (!code_a) {
/* device sends response to a previously executed command */
unsigned char *innerbuf = buf + 7;
unsigned char _subcmd;
uint16_t innerlen;
if (len < 6) {
fp_err("cmd response too short (%d)", len);
return -1;
}
if (innerbuf[0] != 0x28) {
fp_err("cmd response without 28 byte?");
return -1;
}
/* not really sure what these 2 bytes are. on most people's hardware,
* these bytes are always 0. However, Alon Bar-Lev's hardware gives
* 0xfb 0xff during the READ28_OB initsm stage. so don't error out
* if they are different... */
if (innerbuf[3] || innerbuf[4])
fp_dbg("non-zero bytes in cmd response");
innerlen = innerbuf[1] | (innerbuf[2] << 8);
innerlen = GUINT16_FROM_LE(innerlen) - 3;
_subcmd = innerbuf[5];
fp_dbg("device responds to subcmd %x with %d bytes", _subcmd, innerlen);
if (innerlen > 0) {
retdata = g_malloc(innerlen);
memcpy(retdata, innerbuf + 6, innerlen);
}
udata->callback(udata->dev, READ_MSG_RESPONSE, code_b, _subcmd,
retdata, innerlen, udata->user_data);
g_free(retdata);
} else {
fp_err("don't know how to handle this message");
return -1;
}
return 0;
}
static void read_msg_extend_cb(struct libusb_transfer *transfer)
{
struct read_msg_data *udata = transfer->user_data;
unsigned char *buf = transfer->buffer - MSG_READ_BUF_SIZE;
int handle_result = 0;
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
fp_err("extended msg read failed, code %d", transfer->status);
goto err;
}
if (transfer->actual_length < transfer->length) {
fp_err("extended msg short read (%d/%d)", transfer->actual_length,
transfer->length);
goto err;
}
handle_result = __handle_incoming_msg(udata, buf);
if (handle_result < 0)
goto err;
goto out;
err:
READ_MSG_DATA_CB_ERR(udata);
out:
if (handle_result != 1)
g_free(udata);
g_free(buf);
libusb_free_transfer(transfer);
}
static void read_msg_cb(struct libusb_transfer *transfer)
{
struct read_msg_data *udata = transfer->user_data;
unsigned char *data = transfer->buffer;
uint16_t len;
int handle_result = 0;
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
fp_err("async msg read failed, code %d", transfer->status);
goto err;
}
if (transfer->actual_length < 9) {
fp_err("async msg read too short (%d)", transfer->actual_length);
goto err;
}
if (strncmp(data, "Ciao", 4) != 0) {
fp_err("no Ciao for you!!");
goto err;
}
len = GUINT16_FROM_LE(((data[5] & 0xf) << 8) | data[6]);
if (transfer->actual_length != MSG_READ_BUF_SIZE
&& (len + 9) > transfer->actual_length) {
/* Check that the length claimed inside the message is in line with
* the amount of data that was transferred over USB. */
fp_err("msg didn't include enough data, expected=%d recv=%d",
len + 9, transfer->actual_length);
goto err;
}
/* We use a 64 byte buffer for reading messages. However, sometimes
* messages are longer, in which case we have to do another USB bulk read
* to read the remainder. This is handled below. */
if (len > MAX_DATA_IN_READ_BUF) {
int needed = len - MAX_DATA_IN_READ_BUF;
struct libusb_transfer *etransfer = libusb_alloc_transfer(0);
int r;
if (!transfer)
goto err;
fp_dbg("didn't fit in buffer, need to extend by %d bytes", needed);
data = g_realloc((gpointer) data, MSG_READ_BUF_SIZE + needed);
libusb_fill_bulk_transfer(etransfer, udata->dev->udev, EP_IN,
data + MSG_READ_BUF_SIZE, needed, read_msg_extend_cb, udata,
TIMEOUT);
r = libusb_submit_transfer(etransfer);
if (r < 0) {
fp_err("extended read submission failed");
/* FIXME memory leak here? */
goto err;
}
libusb_free_transfer(transfer);
return;
}
handle_result = __handle_incoming_msg(udata, data);
if (handle_result < 0)
goto err;
goto out;
err:
READ_MSG_DATA_CB_ERR(udata);
out:
libusb_free_transfer(transfer);
if (handle_result != 1)
g_free(udata);
g_free(data);
}
static int __read_msg_async(struct read_msg_data *udata)
{
unsigned char *buf = g_malloc(MSG_READ_BUF_SIZE);
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
int r;
if (!transfer) {
g_free(buf);
return -ENOMEM;
}
libusb_fill_bulk_transfer(transfer, udata->dev->udev, EP_IN, buf,
MSG_READ_BUF_SIZE, read_msg_cb, udata, TIMEOUT);
r = libusb_submit_transfer(transfer);
if (r < 0) {
g_free(buf);
libusb_free_transfer(transfer);
}
return r;
}
static int read_msg_async(struct fp_dev *dev, read_msg_cb_fn callback,
void *user_data)
{
struct read_msg_data *udata = g_malloc(sizeof(*udata));
int r;
udata->dev = dev;
udata->callback = callback;
udata->user_data = user_data;
r = __read_msg_async(udata);
if (r)
g_free(udata);
return r;
}
static const unsigned char init_resp03[] = {
0x01, 0x00, 0xbc, 0x02, 0x00, 0x00, 0x00, 0x00
};
static const unsigned char init28_08[] = {
0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x31, 0x00, 0x00, 0x00, 0x38, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
0x00, 0x00, 0x05, 0x1f, 0x88, 0x59, 0x2a, 0x09, 0x7e, 0x35, 0x2f, 0x68, 0xc8, 0x10, 0x4f, 0x19,
0xd6, 0xea, 0xc8, 0xd9, 0x41, 0x73, 0x14, 0x99, 0xa8, 0x77, 0x94, 0xa0, 0x9c, 0xe3, 0x8b, 0x77,
0xf8, 0x83, 0xdc, 0x14, 0xef, 0x2b, 0x5f, 0xaa, 0xb7, 0x18, 0x3b, 0x7d, 0x11, 0x71, 0xf5, 0x95,
0x18, 0x6f, 0x40, 0xcd, 0x5d, 0xbd, 0x13, 0x58, 0x15, 0x10, 0x03, 0xdb, 0x96, 0x86, 0xc6, 0x25,
0xdd, 0x61, 0x7f, 0x54
};
/* device initialisation state machine */
enum initsm_states {
WRITE_CTRL400 = 0,
READ_MSG03,
SEND_RESP03,
READ_MSG05,
SEND28_06,
READ28_06,
SEND28_51,
READ28_51,
SEND28_07,
READ28_07,
SEND28_08,
READ28_08,
INITSM_NUM_STATES
};
static void initsm_read_msg_response_cb(struct fpi_ssm *ssm,
enum read_msg_status status, uint8_t seq,
unsigned char expect_subcmd, unsigned char subcmd)
{
struct fp_dev *dev = ssm->dev;
struct upeke2_dev *upekdev = dev->priv;
if (status != READ_MSG_RESPONSE) {
fp_err("expected response, got %d seq=%x in state %d", status, seq,
ssm->cur_state);
fpi_ssm_mark_aborted(ssm, -1);
} else if (subcmd != expect_subcmd) {
fp_warn("expected response to subcmd 0x%02x, got response to %02x in "
"state %d", expect_subcmd, subcmd, ssm->cur_state);
fpi_ssm_mark_aborted(ssm, -1);
} else if (seq != upekdev->seq) {
fp_err("expected response to cmd seq=%02x, got response to %02x "
"in state %d", upekdev->seq, seq, ssm->cur_state);
fpi_ssm_mark_aborted(ssm, -1);
} else {
fp_dbg("state %d completed", ssm->cur_state);
fpi_ssm_next_state(ssm);
}
}
static void read28_08_cb(struct fp_dev *dev, enum read_msg_status status,
uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len,
void *user_data)
{
initsm_read_msg_response_cb((struct fpi_ssm *) user_data, status, seq,
0x08, subcmd);
}
static void read28_07_cb(struct fp_dev *dev, enum read_msg_status status,
uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len,
void *user_data)
{
initsm_read_msg_response_cb((struct fpi_ssm *) user_data, status, seq,
0x07, subcmd);
}
static void read28_51_cb(struct fp_dev *dev, enum read_msg_status status,
uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len,
void *user_data)
{
initsm_read_msg_response_cb((struct fpi_ssm *) user_data, status, seq,
0x51, subcmd);
}
static void read28_06_cb(struct fp_dev *dev, enum read_msg_status status,
uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len,
void *user_data)
{
initsm_read_msg_response_cb((struct fpi_ssm *) user_data, status, seq,
0x06, subcmd);
}
static void initsm_read_msg_cmd_cb(struct fpi_ssm *ssm,
enum read_msg_status status, uint8_t expect_seq, uint8_t seq)
{
struct fp_dev *dev = ssm->dev;
struct upeke2_dev *upekdev = dev->priv;
if (status == READ_MSG_ERROR) {
fpi_ssm_mark_aborted(ssm, -1);
return;
} else if (status != READ_MSG_CMD) {
fp_err("expected command, got %d seq=%x in state %d", status, seq,
ssm->cur_state);
fpi_ssm_mark_aborted(ssm, -1);
return;
}
upekdev->seq = seq;
if (seq != expect_seq) {
fp_err("expected seq=%x, got %x in state %d", expect_seq, seq,
ssm->cur_state);
fpi_ssm_mark_aborted(ssm, -1);
return;
}
fpi_ssm_next_state(ssm);
}
static void read_msg05_cb(struct fp_dev *dev, enum read_msg_status status,
uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len,
void *user_data)
{
initsm_read_msg_cmd_cb((struct fpi_ssm *) user_data, status, 5, seq);
}
static void read_msg03_cb(struct fp_dev *dev, enum read_msg_status status,
uint8_t seq, unsigned char subcmd, unsigned char *data, size_t data_len,
void *user_data)
{
initsm_read_msg_cmd_cb((struct fpi_ssm *) user_data, status, 3, seq);
}
static void ctrl400_cb(struct libusb_transfer *transfer)
{
struct fpi_ssm *ssm = transfer->user_data;
/* FIXME check length? */
if (transfer->status == LIBUSB_TRANSFER_COMPLETED)
fpi_ssm_next_state(ssm);
else
fpi_ssm_mark_aborted(ssm, -1);
g_free(transfer->buffer);
libusb_free_transfer(transfer);
}
static void initsm_read_msg_handler(struct fpi_ssm *ssm,
read_msg_cb_fn callback)
{
int r = read_msg_async(ssm->dev, callback, ssm);
if (r < 0) {
fp_err("async read msg failed in state %d", ssm->cur_state);
fpi_ssm_mark_aborted(ssm, r);
}