return FIDO_OK;
}
-/*
- * Workaround for OpenBSD <=6.6-current (as of 201910) bug that loses
- * sync of DATA0/DATA1 sequence bit across uhid open/close.
- * Send pings until we get a response - early pings with incorrect
- * sequence bits will be ignored as duplicate packets by the device.
- */
-static int
-terrible_ping_kludge(struct hid_openbsd *ctx)
-{
- u_char data[256];
- int i, n;
- struct pollfd pfd;
-
- if (sizeof(data) < ctx->report_out_len + 1)
- return -1;
- for (i = 0; i < 4; i++) {
- memset(data, 0, sizeof(data));
- /* broadcast channel ID */
- data[1] = 0xff;
- data[2] = 0xff;
- data[3] = 0xff;
- data[4] = 0xff;
- /* Ping command */
- data[5] = 0x81;
- /* One byte ping only, Vasili */
- data[6] = 0;
- data[7] = 1;
- fido_log_debug("%s: send ping %d", __func__, i);
- if (fido_hid_write(ctx, data, ctx->report_out_len + 1) == -1)
- return -1;
- fido_log_debug("%s: wait reply", __func__);
- memset(&pfd, 0, sizeof(pfd));
- pfd.fd = ctx->fd;
- pfd.events = POLLIN;
- if ((n = poll(&pfd, 1, 100)) == -1) {
- fido_log_debug("%s: poll: %s", __func__, strerror(errno));
- return -1;
- } else if (n == 0) {
- fido_log_debug("%s: timed out", __func__);
- continue;
- }
- if (fido_hid_read(ctx, data, ctx->report_out_len, 250) == -1)
- return -1;
- /*
- * Ping isn't always supported on the broadcast channel,
- * so we might get an error, but we don't care - we're
- * synched now.
- */
- fido_log_debug("%s: got reply", __func__);
- fido_log_xxd(data, ctx->report_out_len);
- return 0;
- }
- fido_log_debug("%s: no response", __func__);
- return -1;
-}
-
void *
fido_hid_open(const char *path)
{
fido_log_debug("%s: inlen = %zu outlen = %zu", __func__,
ret->report_in_len, ret->report_out_len);
- /*
- * OpenBSD (as of 201910) has a bug that causes it to lose
- * track of the DATA0/DATA1 sequence toggle across uhid device
- * open and close. This is a terrible hack to work around it.
- */
- if (terrible_ping_kludge(ret) != 0) {
- fido_hid_close(ret);
- return NULL;
- }
-
return (ret);
}