mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-14 02:40:34 +00:00
Unexport libebitdo
Nothing is ever going to use this except fwupd, so it makes no sense adding the extra overhead.
This commit is contained in:
parent
70a6822231
commit
28bbab532a
@ -5,7 +5,6 @@ ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
|
||||
SUBDIRS = \
|
||||
libfwupd \
|
||||
libdfu \
|
||||
libebitdo \
|
||||
po \
|
||||
data \
|
||||
docs \
|
||||
|
@ -310,8 +310,6 @@ AC_CONFIG_FILES([
|
||||
Makefile
|
||||
libdfu/Makefile
|
||||
libdfu/dfu.pc
|
||||
libebitdo/Makefile
|
||||
libebitdo/ebitdo.pc
|
||||
libfwupd/fwupd-version.h
|
||||
libfwupd/fwupd.pc
|
||||
libfwupd/Makefile
|
||||
|
@ -53,6 +53,7 @@ Requires: libgusb%{?_isa} >= %{libgusb_version}
|
||||
Requires: libsoup%{?_isa} >= %{libsoup_version}
|
||||
|
||||
Obsoletes: fwupd-sign < 0.1.6
|
||||
Obsoletes: libebitdo < 0.7.5
|
||||
|
||||
%description
|
||||
fwupd is a daemon to allow session software to update device firmware.
|
||||
@ -60,6 +61,7 @@ fwupd is a daemon to allow session software to update device firmware.
|
||||
%package devel
|
||||
Summary: Development package for %{name}
|
||||
Requires: %{name}%{?_isa} = %{version}-%{release}
|
||||
Obsoletes: libebitdo-devel < 0.7.5
|
||||
|
||||
%description devel
|
||||
Files for development with %{name}.
|
||||
@ -77,19 +79,6 @@ Requires: libdfu%{?_isa} = %{version}-%{release}
|
||||
%description -n libdfu-devel
|
||||
Files for development with libdfu.
|
||||
|
||||
%package -n libebitdo
|
||||
Summary: A library for accessing 8Bitdo hardware
|
||||
|
||||
%description -n libebitdo
|
||||
A library for updating 8Bitdo USB devices.
|
||||
|
||||
%package -n libebitdo-devel
|
||||
Summary: Development package for libebitdo
|
||||
Requires: libebitdo%{?_isa} = %{version}-%{release}
|
||||
|
||||
%description -n libebitdo-devel
|
||||
Files for development with libebitdo.
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
@ -138,9 +127,6 @@ make check VERBOSE=1
|
||||
%post -n libdfu -p /sbin/ldconfig
|
||||
%postun -n libdfu -p /sbin/ldconfig
|
||||
|
||||
%post -n libebitdo -p /sbin/ldconfig
|
||||
%postun -n libebitdo -p /sbin/ldconfig
|
||||
|
||||
%files -f %{name}.lang
|
||||
%doc README.md AUTHORS NEWS
|
||||
%license COPYING
|
||||
@ -193,17 +179,6 @@ make check VERBOSE=1
|
||||
%{_libdir}/libdfu*.so
|
||||
%{_libdir}/pkgconfig/dfu.pc
|
||||
|
||||
%files -n libebitdo
|
||||
%{_bindir}/ebitdo-tool
|
||||
%{_libdir}/libebitdo*.so.*
|
||||
|
||||
%files -n libebitdo-devel
|
||||
%dir %{_includedir}/libebitdo
|
||||
%{_includedir}/ebitdo.h
|
||||
%{_includedir}/libebitdo/*.h
|
||||
%{_libdir}/libebitdo*.so
|
||||
%{_libdir}/pkgconfig/ebitdo.pc
|
||||
|
||||
%changelog
|
||||
* #LONGDATE# Richard Hughes <richard@hughsie.com> #VERSION#-0.#BUILD##ALPHATAG#
|
||||
- Update from git
|
||||
|
Can't render this file because it is too large.
|
@ -1,73 +0,0 @@
|
||||
AM_CPPFLAGS = \
|
||||
$(APPSTREAM_GLIB_CFLAGS) \
|
||||
$(GLIB_CFLAGS) \
|
||||
$(GUSB_CFLAGS) \
|
||||
$(PIE_CFLAGS) \
|
||||
-I$(top_srcdir)/libebitdo \
|
||||
-I$(top_srcdir) \
|
||||
-I$(top_builddir) \
|
||||
-DG_USB_API_IS_SUBJECT_TO_CHANGE \
|
||||
-DG_LOG_DOMAIN=\"libebitdo\" \
|
||||
-DTESTDATADIR=\""$(top_srcdir)/data/tests/ebitdo"\" \
|
||||
-DLOCALEDIR=\""$(localedir)"\"
|
||||
|
||||
lib_LTLIBRARIES = \
|
||||
libebitdo.la
|
||||
|
||||
libebitdo_includedir = $(includedir)
|
||||
libebitdo_include_HEADERS = \
|
||||
ebitdo.h
|
||||
|
||||
libebitdobase_includedir = $(libebitdo_includedir)/libebitdo
|
||||
libebitdobase_include_HEADERS = \
|
||||
ebitdo-device.h
|
||||
|
||||
libebitdo_la_SOURCES = \
|
||||
ebitdo.h \
|
||||
ebitdo-common.c \
|
||||
ebitdo-common.h \
|
||||
ebitdo-device.c \
|
||||
ebitdo-device.h
|
||||
|
||||
libebitdo_la_LIBADD = \
|
||||
$(APPSTREAM_GLIB_LIBS) \
|
||||
$(GUSB_LIBS) \
|
||||
$(GLIB_LIBS)
|
||||
|
||||
libebitdo_la_LDFLAGS = \
|
||||
$(PIE_LDFLAGS) \
|
||||
$(RELRO_LDFLAGS) \
|
||||
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
|
||||
-export-dynamic \
|
||||
-no-undefined \
|
||||
-export-symbols-regex '^ebitdo_.*'
|
||||
|
||||
libebitdo_la_CFLAGS = \
|
||||
$(PIE_CFLAGS) \
|
||||
$(WARN_CFLAGS)
|
||||
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = ebitdo.pc
|
||||
|
||||
EXTRA_DIST = \
|
||||
ebitdo.pc.in
|
||||
|
||||
bin_PROGRAMS = \
|
||||
ebitdo-tool
|
||||
|
||||
ebitdo_tool_SOURCES = \
|
||||
ebitdo-tool.c
|
||||
|
||||
ebitdo_tool_LDADD = \
|
||||
$(lib_LTLIBRARIES) \
|
||||
$(APPSTREAM_GLIB_LIBS) \
|
||||
$(GLIB_LIBS) \
|
||||
$(GUSB_LIBS) \
|
||||
$(LIBM)
|
||||
|
||||
ebitdo_tool_CFLAGS = -DEGG_TEST $(AM_CFLAGS) $(WARN_CFLAGS)
|
||||
|
||||
clean-local:
|
||||
rm -f *~
|
||||
|
||||
-include $(top_srcdir)/git.mk
|
@ -1,92 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
||||
*
|
||||
* Copyright (C) 2016 Richard Hughes <richard@hughsie.com>
|
||||
*
|
||||
* Licensed under the GNU General Public License Version 2
|
||||
*
|
||||
* 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 2 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __EBITDO_COMMON_H
|
||||
#define __EBITDO_COMMON_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* little endian */
|
||||
typedef struct __attribute__((packed)) {
|
||||
guint32 version;
|
||||
guint32 destination_addr;
|
||||
guint32 destination_len;
|
||||
guint32 reserved[4];
|
||||
} EbitdoFirmwareHeader;
|
||||
|
||||
/* little endian */
|
||||
typedef struct __attribute__((packed)) {
|
||||
guint8 pkt_len;
|
||||
guint8 type; /* EbitdoPktType */
|
||||
guint8 subtype; /* EbitdoPktCmd */
|
||||
guint16 cmd_len;
|
||||
guint8 cmd; /* EbitdoPktCmd */
|
||||
guint16 payload_len; /* optional */
|
||||
} EbitdoPkt;
|
||||
|
||||
#define EBITDO_USB_TIMEOUT 5000 /* ms */
|
||||
#define EBITDO_USB_BOOTLOADER_EP_IN 0x82
|
||||
#define EBITDO_USB_BOOTLOADER_EP_OUT 0x01
|
||||
#define EBITDO_USB_RUNTIME_EP_IN 0x81
|
||||
#define EBITDO_USB_RUNTIME_EP_OUT 0x02
|
||||
#define EBITDO_USB_EP_SIZE 64 /* bytes */
|
||||
|
||||
typedef enum {
|
||||
EBITDO_PKT_TYPE_USER_CMD = 0x00,
|
||||
EBITDO_PKT_TYPE_USER_DATA = 0x01,
|
||||
EBITDO_PKT_TYPE_MID_CMD = 0x02,
|
||||
EBITDO_PKT_TYPE_LAST
|
||||
} EbitdoPktType;
|
||||
|
||||
/* commands */
|
||||
typedef enum {
|
||||
EBITDO_PKT_CMD_FW_UPDATE_DATA = 0x00, /* update firmware data */
|
||||
EBITDO_PKT_CMD_FW_UPDATE_HEADER = 0x01, /* update firmware header */
|
||||
EBITDO_PKT_CMD_FW_UPDATE_OK = 0x02, /* mark update as successful */
|
||||
EBITDO_PKT_CMD_FW_UPDATE_ERROR = 0x03, /* update firmware error */
|
||||
EBITDO_PKT_CMD_FW_GET_VERSION = 0x04, /* get cur firmware vision */
|
||||
EBITDO_PKT_CMD_FW_SET_VERSION = 0x05, /* set firmware version */
|
||||
EBITDO_PKT_CMD_FW_SET_ENCODE_ID = 0x06, /* set app firmware encode ID */
|
||||
EBITDO_PKT_CMD_ACK = 0x14, /* acknowledge */
|
||||
EBITDO_PKT_CMD_NAK = 0x15, /* negative acknowledge */
|
||||
EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA = 0x16, /* update firmware data */
|
||||
EBITDO_PKT_CMD_TRANSFER_ABORT = 0x18, /* aborts transfer */
|
||||
EBITDO_PKT_CMD_VERIFICATION_ID = 0x19, /* verification id (only BT?) */
|
||||
EBITDO_PKT_CMD_GET_VERIFICATION_ID = 0x1a, /* verification id (only BT) */
|
||||
EBITDO_PKT_CMD_VERIFY_ERROR = 0x1b, /* verification error */
|
||||
EBITDO_PKT_CMD_VERIFY_OK = 0x1c, /* verification successful */
|
||||
EBITDO_PKT_CMD_TRANSFER_TIMEOUT = 0x1d, /* send or recieve data timeout */
|
||||
EBITDO_PKT_CMD_GET_VERSION = 0x21, /* get fw ver, joystick mode */
|
||||
EBITDO_PKT_CMD_GET_VERSION_RESPONSE = 0x22, /* get fw version response */
|
||||
EBITDO_PKT_CMD_FW_LAST
|
||||
} EbitdoPktCmd;
|
||||
|
||||
const gchar *ebitdo_pkt_cmd_to_string (EbitdoPktCmd cmd);
|
||||
const gchar *ebitdo_pkt_type_to_string (EbitdoPktType type);
|
||||
void ebitdo_dump_firmware_header (EbitdoFirmwareHeader *hdr);
|
||||
void ebitdo_dump_pkt (EbitdoPkt *hdr);
|
||||
void ebitdo_dump_raw (const gchar *title,
|
||||
const guint8 *data,
|
||||
gsize len);
|
||||
|
||||
#endif /* __EBITDO_COMMON_H */
|
@ -1,101 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
||||
*
|
||||
* Copyright (C) 2016 Richard Hughes <richard@hughsie.com>
|
||||
*
|
||||
* Licensed under the GNU Lesser General Public License Version 2.1
|
||||
*
|
||||
* 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; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef __EBITDO_DEVICE_H
|
||||
#define __EBITDO_DEVICE_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <gusb.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define EBITDO_TYPE_DEVICE (ebitdo_device_get_type ())
|
||||
G_DECLARE_DERIVABLE_TYPE (EbitdoDevice, ebitdo_device, EBITDO, DEVICE, GObject)
|
||||
|
||||
struct _EbitdoDeviceClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
/*< private >*/
|
||||
void (*_as_reserved1) (void);
|
||||
void (*_as_reserved2) (void);
|
||||
void (*_as_reserved3) (void);
|
||||
void (*_as_reserved4) (void);
|
||||
void (*_as_reserved5) (void);
|
||||
void (*_as_reserved6) (void);
|
||||
void (*_as_reserved7) (void);
|
||||
void (*_as_reserved8) (void);
|
||||
};
|
||||
|
||||
/**
|
||||
* EbitdoDeviceKind:
|
||||
* @EBITDO_DEVICE_KIND_UNKNOWN: Type invalid or not known
|
||||
* @EBITDO_DEVICE_KIND_BOOTLOADER: Bootloader
|
||||
* @EBITDO_DEVICE_KIND_FC30: FC30
|
||||
* @EBITDO_DEVICE_KIND_NES30: NES30
|
||||
* @EBITDO_DEVICE_KIND_SFC30: SFC30
|
||||
* @EBITDO_DEVICE_KIND_SNES30: SNES30
|
||||
* @EBITDO_DEVICE_KIND_FC30PRO: FC30PRO
|
||||
* @EBITDO_DEVICE_KIND_NES30PRO: NES30PRO
|
||||
* @EBITDO_DEVICE_KIND_FC30_ARCADE: FC30 ARCADE
|
||||
*
|
||||
* The device type.
|
||||
**/
|
||||
typedef enum {
|
||||
EBITDO_DEVICE_KIND_UNKNOWN,
|
||||
EBITDO_DEVICE_KIND_BOOTLOADER,
|
||||
EBITDO_DEVICE_KIND_FC30,
|
||||
EBITDO_DEVICE_KIND_NES30,
|
||||
EBITDO_DEVICE_KIND_SFC30,
|
||||
EBITDO_DEVICE_KIND_SNES30,
|
||||
EBITDO_DEVICE_KIND_FC30PRO,
|
||||
EBITDO_DEVICE_KIND_NES30PRO,
|
||||
EBITDO_DEVICE_KIND_FC30_ARCADE,
|
||||
/*< private >*/
|
||||
EBITDO_DEVICE_KIND_LAST
|
||||
} EbitdoDeviceKind;
|
||||
|
||||
EbitdoDevice *ebitdo_device_new (GUsbDevice *usb_device);
|
||||
|
||||
/* helpers */
|
||||
EbitdoDeviceKind ebitdo_device_kind_from_string (const gchar *kind);
|
||||
const gchar *ebitdo_device_kind_to_string (EbitdoDeviceKind kind);
|
||||
|
||||
/* getters */
|
||||
EbitdoDeviceKind ebitdo_device_get_kind (EbitdoDevice *device);
|
||||
GUsbDevice *ebitdo_device_get_usb_device (EbitdoDevice *device);
|
||||
const gchar *ebitdo_device_get_version (EbitdoDevice *device);
|
||||
const guint32 *ebitdo_device_get_serial (EbitdoDevice *device);
|
||||
const gchar *ebitdo_device_get_guid (EbitdoDevice *device);
|
||||
|
||||
/* object methods */
|
||||
gboolean ebitdo_device_open (EbitdoDevice *device,
|
||||
GError **error);
|
||||
gboolean ebitdo_device_close (EbitdoDevice *device,
|
||||
GError **error);
|
||||
gboolean ebitdo_device_write_firmware (EbitdoDevice *device,
|
||||
GBytes *fw,
|
||||
GFileProgressCallback progress_cb,
|
||||
gpointer progress_data,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __EBITDO_DEVICE_H */
|
@ -1,37 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
||||
*
|
||||
* Copyright (C) 2015 Richard Hughes <richard@hughsie.com>
|
||||
*
|
||||
* Licensed under the GNU Lesser General Public License Version 2.1
|
||||
*
|
||||
* 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; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/**
|
||||
* SECTION:ebitdo
|
||||
* @short_description: Helper objects for interacting with EBITDO devices.
|
||||
*/
|
||||
|
||||
#ifndef __EBITDO_H__
|
||||
#define __EBITDO_H__
|
||||
|
||||
#define __EBITDO_H_INSIDE__
|
||||
|
||||
#include <libebitdo/ebitdo-device.h>
|
||||
|
||||
#undef __EBITDO_H_INSIDE__
|
||||
|
||||
#endif /* __EBITDO_H__ */
|
||||
|
@ -1,11 +0,0 @@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: ebitdo
|
||||
Description: libebitdo is a library for communicating with 8Bitdo hardware
|
||||
Version: @VERSION@
|
||||
Requires: glib-2.0, gobject-2.0, gio-2.0
|
||||
Libs: -L${libdir} -lebitdo
|
||||
Cflags: -I${includedir}
|
@ -17,7 +17,6 @@ AM_CPPFLAGS = \
|
||||
$(ARCHIVE_CFLAGS) \
|
||||
-I$(top_srcdir) \
|
||||
-I$(top_builddir) \
|
||||
-I$(top_srcdir)/libebitdo \
|
||||
-I$(top_srcdir)/libfwupd \
|
||||
-DG_LOG_DOMAIN=\"Fu\" \
|
||||
-DLIBEXECDIR=\"$(libexecdir)\" \
|
||||
@ -36,9 +35,6 @@ FWUPD_LIBS = \
|
||||
DFU_LIBS = \
|
||||
$(top_builddir)/libdfu/libdfu.la
|
||||
|
||||
EBITDO_LIBS = \
|
||||
$(top_builddir)/libebitdo/libebitdo.la
|
||||
|
||||
bin_PROGRAMS = fwupdmgr
|
||||
|
||||
fwupdmgr_SOURCES = \
|
||||
@ -111,6 +107,25 @@ fu-resources.h: fwupd.gresource.xml
|
||||
--c-name fu \
|
||||
$(srcdir)/fwupd.gresource.xml
|
||||
|
||||
noinst_PROGRAMS += \
|
||||
fu-ebitdo-tool
|
||||
|
||||
fu_ebitdo_tool_SOURCES = \
|
||||
fu-ebitdo-common.c \
|
||||
fu-ebitdo-common.h \
|
||||
fu-ebitdo-device.c \
|
||||
fu-ebitdo-device.h \
|
||||
fu-ebitdo-tool.c
|
||||
|
||||
fu_ebitdo_tool_LDADD = \
|
||||
$(lib_LTLIBRARIES) \
|
||||
$(APPSTREAM_GLIB_LIBS) \
|
||||
$(GLIB_LIBS) \
|
||||
$(GUSB_LIBS) \
|
||||
$(LIBM)
|
||||
|
||||
fu_ebitdo_tool_CFLAGS = -DEGG_TEST $(AM_CFLAGS) $(WARN_CFLAGS)
|
||||
|
||||
pkglibexec_PROGRAMS = \
|
||||
fwupd
|
||||
|
||||
@ -119,6 +134,10 @@ fwupd_SOURCES = \
|
||||
fu-debug.h \
|
||||
fu-device.c \
|
||||
fu-device.h \
|
||||
fu-ebitdo-common.c \
|
||||
fu-ebitdo-common.h \
|
||||
fu-ebitdo-device.c \
|
||||
fu-ebitdo-device.h \
|
||||
fu-keyring.c \
|
||||
fu-keyring.h \
|
||||
fu-pending.c \
|
||||
@ -147,7 +166,6 @@ fwupd_SOURCES = \
|
||||
fwupd_LDADD = \
|
||||
$(FWUPD_LIBS) \
|
||||
$(DFU_LIBS) \
|
||||
$(EBITDO_LIBS) \
|
||||
$(APPSTREAM_GLIB_LIBS) \
|
||||
$(GUSB_LIBS) \
|
||||
$(GCAB_LIBS) \
|
||||
|
@ -21,64 +21,64 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "ebitdo-common.h"
|
||||
#include "fu-ebitdo-common.h"
|
||||
|
||||
const gchar *
|
||||
ebitdo_pkt_type_to_string (EbitdoPktType cmd)
|
||||
fu_ebitdo_pkt_type_to_string (FuEbitdoPktType cmd)
|
||||
{
|
||||
if (cmd == EBITDO_PKT_TYPE_USER_CMD)
|
||||
if (cmd == FU_EBITDO_PKT_TYPE_USER_CMD)
|
||||
return "user-cmd";
|
||||
if (cmd == EBITDO_PKT_TYPE_USER_DATA)
|
||||
if (cmd == FU_EBITDO_PKT_TYPE_USER_DATA)
|
||||
return "user-data";
|
||||
if (cmd == EBITDO_PKT_TYPE_MID_CMD)
|
||||
if (cmd == FU_EBITDO_PKT_TYPE_MID_CMD)
|
||||
return "mid-cmd";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
ebitdo_pkt_cmd_to_string (EbitdoPktCmd cmd)
|
||||
fu_ebitdo_pkt_cmd_to_string (FuEbitdoPktCmd cmd)
|
||||
{
|
||||
if (cmd == EBITDO_PKT_CMD_FW_UPDATE_DATA)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_FW_UPDATE_DATA)
|
||||
return "fw-update-data";
|
||||
if (cmd == EBITDO_PKT_CMD_FW_UPDATE_HEADER)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_FW_UPDATE_HEADER)
|
||||
return "fw-update-header";
|
||||
if (cmd == EBITDO_PKT_CMD_FW_UPDATE_OK)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_FW_UPDATE_OK)
|
||||
return "fw-update-ok";
|
||||
if (cmd == EBITDO_PKT_CMD_FW_UPDATE_ERROR)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_FW_UPDATE_ERROR)
|
||||
return "fw-update-error";
|
||||
if (cmd == EBITDO_PKT_CMD_FW_GET_VERSION)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_FW_GET_VERSION)
|
||||
return "fw-get-version";
|
||||
if (cmd == EBITDO_PKT_CMD_FW_SET_VERSION)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_FW_SET_VERSION)
|
||||
return "fw-set-version";
|
||||
if (cmd == EBITDO_PKT_CMD_FW_SET_ENCODE_ID)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_FW_SET_ENCODE_ID)
|
||||
return "fw-set-encode-id";
|
||||
if (cmd == EBITDO_PKT_CMD_ACK)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_ACK)
|
||||
return "ack";
|
||||
if (cmd == EBITDO_PKT_CMD_NAK)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_NAK)
|
||||
return "nak";
|
||||
if (cmd == EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA)
|
||||
return "update-firmware-data";
|
||||
if (cmd == EBITDO_PKT_CMD_TRANSFER_ABORT)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_TRANSFER_ABORT)
|
||||
return "transfer-abort";
|
||||
if (cmd == EBITDO_PKT_CMD_VERIFICATION_ID)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_VERIFICATION_ID)
|
||||
return "verification-id";
|
||||
if (cmd == EBITDO_PKT_CMD_GET_VERIFICATION_ID)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_GET_VERIFICATION_ID)
|
||||
return "get-verification-id";
|
||||
if (cmd == EBITDO_PKT_CMD_VERIFY_ERROR)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_VERIFY_ERROR)
|
||||
return "verify-error";
|
||||
if (cmd == EBITDO_PKT_CMD_VERIFY_OK)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_VERIFY_OK)
|
||||
return "verify-ok";
|
||||
if (cmd == EBITDO_PKT_CMD_TRANSFER_TIMEOUT)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_TRANSFER_TIMEOUT)
|
||||
return "transfer-timeout";
|
||||
if (cmd == EBITDO_PKT_CMD_GET_VERSION)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_GET_VERSION)
|
||||
return "get-version";
|
||||
if (cmd == EBITDO_PKT_CMD_GET_VERSION_RESPONSE)
|
||||
if (cmd == FU_EBITDO_PKT_CMD_GET_VERSION_RESPONSE)
|
||||
return "get-version-response";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
ebitdo_dump_raw (const gchar *title, const guint8 *data, gsize len)
|
||||
fu_ebitdo_dump_raw (const gchar *title, const guint8 *data, gsize len)
|
||||
{
|
||||
g_print ("%s:", title);
|
||||
for (gsize i = strlen (title); i < 16; i++)
|
||||
@ -92,22 +92,22 @@ ebitdo_dump_raw (const gchar *title, const guint8 *data, gsize len)
|
||||
}
|
||||
|
||||
void
|
||||
ebitdo_dump_pkt (EbitdoPkt *hdr)
|
||||
fu_ebitdo_dump_pkt (FuEbitdoPkt *hdr)
|
||||
{
|
||||
g_print ("PktLength: 0x%02x\n", hdr->pkt_len);
|
||||
g_print ("PktType: 0x%02x [%s]\n",
|
||||
hdr->type, ebitdo_pkt_type_to_string (hdr->type));
|
||||
hdr->type, fu_ebitdo_pkt_type_to_string (hdr->type));
|
||||
g_print ("CmdSubtype: 0x%02x [%s]\n",
|
||||
hdr->subtype, ebitdo_pkt_cmd_to_string (hdr->subtype));
|
||||
hdr->subtype, fu_ebitdo_pkt_cmd_to_string (hdr->subtype));
|
||||
g_print ("CmdLen: 0x%04x\n", GUINT16_FROM_LE (hdr->cmd_len));
|
||||
g_print ("Cmd: 0x%02x [%s]\n",
|
||||
hdr->cmd, ebitdo_pkt_cmd_to_string (hdr->cmd));
|
||||
hdr->cmd, fu_ebitdo_pkt_cmd_to_string (hdr->cmd));
|
||||
g_print ("Payload Len: 0x%04x\n",
|
||||
GUINT16_FROM_LE (hdr->payload_len));
|
||||
}
|
||||
|
||||
void
|
||||
ebitdo_dump_firmware_header (EbitdoFirmwareHeader *hdr)
|
||||
fu_ebitdo_dump_firmware_header (FuEbitdoFirmwareHeader *hdr)
|
||||
{
|
||||
g_print ("Version: %.2f\n",
|
||||
(gdouble) GUINT32_FROM_LE (hdr->version) / 100.f);
|
92
src/fu-ebitdo-common.h
Normal file
92
src/fu-ebitdo-common.h
Normal file
@ -0,0 +1,92 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
||||
*
|
||||
* Copyright (C) 2016 Richard Hughes <richard@hughsie.com>
|
||||
*
|
||||
* Licensed under the GNU General Public License Version 2
|
||||
*
|
||||
* 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 2 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#ifndef __FU_EBITDO_COMMON_H
|
||||
#define __FU_EBITDO_COMMON_H
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* little endian */
|
||||
typedef struct __attribute__((packed)) {
|
||||
guint32 version;
|
||||
guint32 destination_addr;
|
||||
guint32 destination_len;
|
||||
guint32 reserved[4];
|
||||
} FuEbitdoFirmwareHeader;
|
||||
|
||||
/* little endian */
|
||||
typedef struct __attribute__((packed)) {
|
||||
guint8 pkt_len;
|
||||
guint8 type; /* FuEbitdoPktType */
|
||||
guint8 subtype; /* FuEbitdoPktCmd */
|
||||
guint16 cmd_len;
|
||||
guint8 cmd; /* FuEbitdoPktCmd */
|
||||
guint16 payload_len; /* optional */
|
||||
} FuEbitdoPkt;
|
||||
|
||||
#define FU_EBITDO_USB_TIMEOUT 5000 /* ms */
|
||||
#define FU_EBITDO_USB_BOOTLOADER_EP_IN 0x82
|
||||
#define FU_EBITDO_USB_BOOTLOADER_EP_OUT 0x01
|
||||
#define FU_EBITDO_USB_RUNTIME_EP_IN 0x81
|
||||
#define FU_EBITDO_USB_RUNTIME_EP_OUT 0x02
|
||||
#define FU_EBITDO_USB_EP_SIZE 64 /* bytes */
|
||||
|
||||
typedef enum {
|
||||
FU_EBITDO_PKT_TYPE_USER_CMD = 0x00,
|
||||
FU_EBITDO_PKT_TYPE_USER_DATA = 0x01,
|
||||
FU_EBITDO_PKT_TYPE_MID_CMD = 0x02,
|
||||
FU_EBITDO_PKT_TYPE_LAST
|
||||
} FuEbitdoPktType;
|
||||
|
||||
/* commands */
|
||||
typedef enum {
|
||||
FU_EBITDO_PKT_CMD_FW_UPDATE_DATA = 0x00, /* update firmware data */
|
||||
FU_EBITDO_PKT_CMD_FW_UPDATE_HEADER = 0x01, /* update firmware header */
|
||||
FU_EBITDO_PKT_CMD_FW_UPDATE_OK = 0x02, /* mark update as successful */
|
||||
FU_EBITDO_PKT_CMD_FW_UPDATE_ERROR = 0x03, /* update firmware error */
|
||||
FU_EBITDO_PKT_CMD_FW_GET_VERSION = 0x04, /* get cur firmware vision */
|
||||
FU_EBITDO_PKT_CMD_FW_SET_VERSION = 0x05, /* set firmware version */
|
||||
FU_EBITDO_PKT_CMD_FW_SET_ENCODE_ID = 0x06, /* set app firmware encode ID */
|
||||
FU_EBITDO_PKT_CMD_ACK = 0x14, /* acknowledge */
|
||||
FU_EBITDO_PKT_CMD_NAK = 0x15, /* negative acknowledge */
|
||||
FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA = 0x16, /* update firmware data */
|
||||
FU_EBITDO_PKT_CMD_TRANSFER_ABORT = 0x18, /* aborts transfer */
|
||||
FU_EBITDO_PKT_CMD_VERIFICATION_ID = 0x19, /* verification id (only BT?) */
|
||||
FU_EBITDO_PKT_CMD_GET_VERIFICATION_ID = 0x1a, /* verification id (only BT) */
|
||||
FU_EBITDO_PKT_CMD_VERIFY_ERROR = 0x1b, /* verification error */
|
||||
FU_EBITDO_PKT_CMD_VERIFY_OK = 0x1c, /* verification successful */
|
||||
FU_EBITDO_PKT_CMD_TRANSFER_TIMEOUT = 0x1d, /* send or recieve data timeout */
|
||||
FU_EBITDO_PKT_CMD_GET_VERSION = 0x21, /* get fw ver, joystick mode */
|
||||
FU_EBITDO_PKT_CMD_GET_VERSION_RESPONSE = 0x22, /* get fw version response */
|
||||
FU_EBITDO_PKT_CMD_FW_LAST
|
||||
} FuEbitdoPktCmd;
|
||||
|
||||
const gchar *fu_ebitdo_pkt_cmd_to_string (FuEbitdoPktCmd cmd);
|
||||
const gchar *fu_ebitdo_pkt_type_to_string (FuEbitdoPktType type);
|
||||
void fu_ebitdo_dump_firmware_header (FuEbitdoFirmwareHeader *hdr);
|
||||
void fu_ebitdo_dump_pkt (FuEbitdoPkt *hdr);
|
||||
void fu_ebitdo_dump_raw (const gchar *title,
|
||||
const guint8 *data,
|
||||
gsize len);
|
||||
|
||||
#endif /* __FU_EBITDO_COMMON_H */
|
@ -24,57 +24,57 @@
|
||||
#include <string.h>
|
||||
#include <appstream-glib.h>
|
||||
|
||||
#include "ebitdo-common.h"
|
||||
#include "ebitdo-device.h"
|
||||
#include "fu-ebitdo-common.h"
|
||||
#include "fu-ebitdo-device.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
EbitdoDeviceKind kind;
|
||||
FuEbitdoDeviceKind kind;
|
||||
GUsbDevice *usb_device;
|
||||
guint32 serial[9];
|
||||
gchar *guid;
|
||||
gchar *version;
|
||||
} EbitdoDevicePrivate;
|
||||
} FuEbitdoDevicePrivate;
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (EbitdoDevice, ebitdo_device, G_TYPE_OBJECT)
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (FuEbitdoDevice, fu_ebitdo_device, G_TYPE_OBJECT)
|
||||
|
||||
#define GET_PRIVATE(o) (ebitdo_device_get_instance_private (o))
|
||||
#define GET_PRIVATE(o) (fu_ebitdo_device_get_instance_private (o))
|
||||
|
||||
/**
|
||||
* ebitdo_device_kind_from_string:
|
||||
* fu_ebitdo_device_kind_from_string:
|
||||
* @kind: the string.
|
||||
*
|
||||
* Converts the text representation to an enumerated value.
|
||||
*
|
||||
* Returns: (transfer full): a #EbitdoDeviceKind, or %EBITDO_DEVICE_KIND_UNKNOWN for unknown.
|
||||
* Returns: (transfer full): a #FuEbitdoDeviceKind, or %FU_EBITDO_DEVICE_KIND_UNKNOWN for unknown.
|
||||
*
|
||||
* Since: 0.1.0
|
||||
**/
|
||||
EbitdoDeviceKind
|
||||
ebitdo_device_kind_from_string (const gchar *kind)
|
||||
FuEbitdoDeviceKind
|
||||
fu_ebitdo_device_kind_from_string (const gchar *kind)
|
||||
{
|
||||
if (g_strcmp0 (kind, "BOOTLOADER") == 0)
|
||||
return EBITDO_DEVICE_KIND_BOOTLOADER;
|
||||
return FU_EBITDO_DEVICE_KIND_BOOTLOADER;
|
||||
if (g_strcmp0 (kind, "FC30") == 0)
|
||||
return EBITDO_DEVICE_KIND_FC30;
|
||||
return FU_EBITDO_DEVICE_KIND_FC30;
|
||||
if (g_strcmp0 (kind, "NES30") == 0)
|
||||
return EBITDO_DEVICE_KIND_NES30;
|
||||
return FU_EBITDO_DEVICE_KIND_NES30;
|
||||
if (g_strcmp0 (kind, "SFC30") == 0)
|
||||
return EBITDO_DEVICE_KIND_SFC30;
|
||||
return FU_EBITDO_DEVICE_KIND_SFC30;
|
||||
if (g_strcmp0 (kind, "SNES30") == 0)
|
||||
return EBITDO_DEVICE_KIND_SNES30;
|
||||
return FU_EBITDO_DEVICE_KIND_SNES30;
|
||||
if (g_strcmp0 (kind, "FC30PRO") == 0)
|
||||
return EBITDO_DEVICE_KIND_FC30PRO;
|
||||
return FU_EBITDO_DEVICE_KIND_FC30PRO;
|
||||
if (g_strcmp0 (kind, "NES30PRO") == 0)
|
||||
return EBITDO_DEVICE_KIND_NES30PRO;
|
||||
return FU_EBITDO_DEVICE_KIND_NES30PRO;
|
||||
if (g_strcmp0 (kind, "FC30_ARCADE") == 0)
|
||||
return EBITDO_DEVICE_KIND_FC30_ARCADE;
|
||||
return EBITDO_DEVICE_KIND_UNKNOWN;
|
||||
return FU_EBITDO_DEVICE_KIND_FC30_ARCADE;
|
||||
return FU_EBITDO_DEVICE_KIND_UNKNOWN;
|
||||
}
|
||||
|
||||
/**
|
||||
* ebitdo_device_kind_to_string:
|
||||
* @kind: the #EbitdoDeviceKind.
|
||||
* fu_ebitdo_device_kind_to_string:
|
||||
* @kind: the #FuEbitdoDeviceKind.
|
||||
*
|
||||
* Converts the enumerated value to an text representation.
|
||||
*
|
||||
@ -83,73 +83,73 @@ ebitdo_device_kind_from_string (const gchar *kind)
|
||||
* Since: 0.1.0
|
||||
**/
|
||||
const gchar *
|
||||
ebitdo_device_kind_to_string (EbitdoDeviceKind kind)
|
||||
fu_ebitdo_device_kind_to_string (FuEbitdoDeviceKind kind)
|
||||
{
|
||||
if (kind == EBITDO_DEVICE_KIND_BOOTLOADER)
|
||||
if (kind == FU_EBITDO_DEVICE_KIND_BOOTLOADER)
|
||||
return "BOOTLOADER";
|
||||
if (kind == EBITDO_DEVICE_KIND_FC30)
|
||||
if (kind == FU_EBITDO_DEVICE_KIND_FC30)
|
||||
return "FC30";
|
||||
if (kind == EBITDO_DEVICE_KIND_NES30)
|
||||
if (kind == FU_EBITDO_DEVICE_KIND_NES30)
|
||||
return "NES30";
|
||||
if (kind == EBITDO_DEVICE_KIND_SFC30)
|
||||
if (kind == FU_EBITDO_DEVICE_KIND_SFC30)
|
||||
return "SFC30";
|
||||
if (kind == EBITDO_DEVICE_KIND_SNES30)
|
||||
if (kind == FU_EBITDO_DEVICE_KIND_SNES30)
|
||||
return "SNES30";
|
||||
if (kind == EBITDO_DEVICE_KIND_FC30PRO)
|
||||
if (kind == FU_EBITDO_DEVICE_KIND_FC30PRO)
|
||||
return "FC30PRO";
|
||||
if (kind == EBITDO_DEVICE_KIND_NES30PRO)
|
||||
if (kind == FU_EBITDO_DEVICE_KIND_NES30PRO)
|
||||
return "NES30PRO";
|
||||
if (kind == EBITDO_DEVICE_KIND_FC30_ARCADE)
|
||||
if (kind == FU_EBITDO_DEVICE_KIND_FC30_ARCADE)
|
||||
return "FC30_ARCADE";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
ebitdo_device_finalize (GObject *object)
|
||||
fu_ebitdo_device_finalize (GObject *object)
|
||||
{
|
||||
EbitdoDevice *device = EBITDO_DEVICE (object);
|
||||
EbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
FuEbitdoDevice *device = FU_EBITDO_DEVICE (object);
|
||||
FuEbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
|
||||
g_free (priv->guid);
|
||||
g_free (priv->version);
|
||||
if (priv->usb_device != NULL)
|
||||
g_object_unref (priv->usb_device);
|
||||
|
||||
G_OBJECT_CLASS (ebitdo_device_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS (fu_ebitdo_device_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
ebitdo_device_init (EbitdoDevice *device)
|
||||
fu_ebitdo_device_init (FuEbitdoDevice *device)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
ebitdo_device_class_init (EbitdoDeviceClass *klass)
|
||||
fu_ebitdo_device_class_init (FuEbitdoDeviceClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
object_class->finalize = ebitdo_device_finalize;
|
||||
object_class->finalize = fu_ebitdo_device_finalize;
|
||||
}
|
||||
|
||||
/**
|
||||
* ebitdo_device_get_kind:
|
||||
* @device: a #EbitdoDevice instance.
|
||||
* fu_ebitdo_device_get_kind:
|
||||
* @device: a #FuEbitdoDevice instance.
|
||||
*
|
||||
* Gets the device kind.
|
||||
*
|
||||
* Returns: the #EbitdoDeviceKind
|
||||
* Returns: the #FuEbitdoDeviceKind
|
||||
*
|
||||
* Since: 0.1.0
|
||||
**/
|
||||
EbitdoDeviceKind
|
||||
ebitdo_device_get_kind (EbitdoDevice *device)
|
||||
FuEbitdoDeviceKind
|
||||
fu_ebitdo_device_get_kind (FuEbitdoDevice *device)
|
||||
{
|
||||
EbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
FuEbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
return priv->kind;
|
||||
}
|
||||
|
||||
/**
|
||||
* ebitdo_device_get_usb_device:
|
||||
* @device: a #EbitdoDevice instance.
|
||||
* fu_ebitdo_device_get_usb_device:
|
||||
* @device: a #FuEbitdoDevice instance.
|
||||
*
|
||||
* Gets the device usb_device if set.
|
||||
*
|
||||
@ -158,31 +158,31 @@ ebitdo_device_get_kind (EbitdoDevice *device)
|
||||
* Since: 0.1.0
|
||||
**/
|
||||
GUsbDevice *
|
||||
ebitdo_device_get_usb_device (EbitdoDevice *device)
|
||||
fu_ebitdo_device_get_usb_device (FuEbitdoDevice *device)
|
||||
{
|
||||
EbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
FuEbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
return priv->usb_device;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ebitdo_device_send (EbitdoDevice *device,
|
||||
EbitdoPktType type,
|
||||
EbitdoPktCmd subtype,
|
||||
EbitdoPktCmd cmd,
|
||||
fu_ebitdo_device_send (FuEbitdoDevice *device,
|
||||
FuEbitdoPktType type,
|
||||
FuEbitdoPktCmd subtype,
|
||||
FuEbitdoPktCmd cmd,
|
||||
const guint8 *in,
|
||||
gsize in_len,
|
||||
GError **error)
|
||||
{
|
||||
EbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
guint8 packet[EBITDO_USB_EP_SIZE];
|
||||
FuEbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
guint8 packet[FU_EBITDO_USB_EP_SIZE];
|
||||
gsize actual_length;
|
||||
guint8 ep_out = EBITDO_USB_RUNTIME_EP_OUT;
|
||||
guint8 ep_out = FU_EBITDO_USB_RUNTIME_EP_OUT;
|
||||
g_autoptr(GError) error_local = NULL;
|
||||
EbitdoPkt *hdr = (EbitdoPkt *) packet;
|
||||
FuEbitdoPkt *hdr = (FuEbitdoPkt *) packet;
|
||||
|
||||
/* different */
|
||||
if (priv->kind == EBITDO_DEVICE_KIND_BOOTLOADER)
|
||||
ep_out = EBITDO_USB_BOOTLOADER_EP_OUT;
|
||||
if (priv->kind == FU_EBITDO_DEVICE_KIND_BOOTLOADER)
|
||||
ep_out = FU_EBITDO_USB_BOOTLOADER_EP_OUT;
|
||||
|
||||
/* check size */
|
||||
if (in_len > 64 - 8) {
|
||||
@ -212,25 +212,25 @@ ebitdo_device_send (EbitdoDevice *device,
|
||||
}
|
||||
|
||||
/* debug */
|
||||
if (g_getenv ("EBITDO_DEBUG") != NULL) {
|
||||
ebitdo_dump_raw ("->DEVICE", packet, (gsize) hdr->pkt_len + 1);
|
||||
ebitdo_dump_pkt (hdr);
|
||||
if (g_getenv ("FU_EBITDO_DEBUG") != NULL) {
|
||||
fu_ebitdo_dump_raw ("->DEVICE", packet, (gsize) hdr->pkt_len + 1);
|
||||
fu_ebitdo_dump_pkt (hdr);
|
||||
}
|
||||
|
||||
/* get data from device */
|
||||
if (!g_usb_device_interrupt_transfer (priv->usb_device,
|
||||
ep_out,
|
||||
packet,
|
||||
EBITDO_USB_EP_SIZE,
|
||||
FU_EBITDO_USB_EP_SIZE,
|
||||
&actual_length,
|
||||
EBITDO_USB_TIMEOUT,
|
||||
FU_EBITDO_USB_TIMEOUT,
|
||||
NULL, /* cancellable */
|
||||
&error_local)) {
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_INVALID_DATA,
|
||||
"failed to send to device on ep 0x%02x: %s",
|
||||
(guint) EBITDO_USB_BOOTLOADER_EP_OUT,
|
||||
(guint) FU_EBITDO_USB_BOOTLOADER_EP_OUT,
|
||||
error_local->message);
|
||||
return FALSE;
|
||||
}
|
||||
@ -238,51 +238,51 @@ ebitdo_device_send (EbitdoDevice *device,
|
||||
}
|
||||
|
||||
static gboolean
|
||||
ebitdo_device_receive (EbitdoDevice *device,
|
||||
fu_ebitdo_device_receive (FuEbitdoDevice *device,
|
||||
guint8 *out,
|
||||
gsize out_len,
|
||||
GError **error)
|
||||
{
|
||||
EbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
guint8 packet[EBITDO_USB_EP_SIZE];
|
||||
FuEbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
guint8 packet[FU_EBITDO_USB_EP_SIZE];
|
||||
gsize actual_length;
|
||||
guint8 ep_in = EBITDO_USB_RUNTIME_EP_IN;
|
||||
guint8 ep_in = FU_EBITDO_USB_RUNTIME_EP_IN;
|
||||
g_autoptr(GError) error_local = NULL;
|
||||
EbitdoPkt *hdr = (EbitdoPkt *) packet;
|
||||
FuEbitdoPkt *hdr = (FuEbitdoPkt *) packet;
|
||||
|
||||
/* different */
|
||||
if (priv->kind == EBITDO_DEVICE_KIND_BOOTLOADER)
|
||||
ep_in = EBITDO_USB_BOOTLOADER_EP_IN;
|
||||
if (priv->kind == FU_EBITDO_DEVICE_KIND_BOOTLOADER)
|
||||
ep_in = FU_EBITDO_USB_BOOTLOADER_EP_IN;
|
||||
|
||||
/* get data from device */
|
||||
memset (packet, 0x0, sizeof(packet));
|
||||
if (!g_usb_device_interrupt_transfer (priv->usb_device,
|
||||
ep_in,
|
||||
packet,
|
||||
EBITDO_USB_EP_SIZE,
|
||||
FU_EBITDO_USB_EP_SIZE,
|
||||
&actual_length,
|
||||
EBITDO_USB_TIMEOUT,
|
||||
FU_EBITDO_USB_TIMEOUT,
|
||||
NULL, /* cancellable */
|
||||
&error_local)) {
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_INVALID_DATA,
|
||||
"failed to retrieve from device on ep 0x%02x: %s",
|
||||
(guint) EBITDO_USB_BOOTLOADER_EP_IN,
|
||||
(guint) FU_EBITDO_USB_BOOTLOADER_EP_IN,
|
||||
error_local->message);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* debug */
|
||||
if (g_getenv ("EBITDO_DEBUG") != NULL) {
|
||||
ebitdo_dump_raw ("<-DEVICE", packet, (gsize) hdr->pkt_len - 1);
|
||||
ebitdo_dump_pkt (hdr);
|
||||
if (g_getenv ("FU_EBITDO_DEBUG") != NULL) {
|
||||
fu_ebitdo_dump_raw ("<-DEVICE", packet, (gsize) hdr->pkt_len - 1);
|
||||
fu_ebitdo_dump_pkt (hdr);
|
||||
}
|
||||
|
||||
/* get-version (booloader) */
|
||||
if (hdr->type == EBITDO_PKT_TYPE_USER_CMD &&
|
||||
hdr->subtype == EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA &&
|
||||
hdr->cmd == EBITDO_PKT_CMD_FW_GET_VERSION) {
|
||||
if (hdr->type == FU_EBITDO_PKT_TYPE_USER_CMD &&
|
||||
hdr->subtype == FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA &&
|
||||
hdr->cmd == FU_EBITDO_PKT_CMD_FW_GET_VERSION) {
|
||||
if (out != NULL) {
|
||||
if (hdr->payload_len != out_len) {
|
||||
g_set_error (error,
|
||||
@ -294,14 +294,14 @@ ebitdo_device_receive (EbitdoDevice *device,
|
||||
return FALSE;
|
||||
}
|
||||
memcpy (out,
|
||||
packet + sizeof(EbitdoPkt),
|
||||
packet + sizeof(FuEbitdoPkt),
|
||||
hdr->payload_len);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* get-version (firmware) -- not a packet, just raw data! */
|
||||
if (hdr->pkt_len == EBITDO_PKT_CMD_GET_VERSION_RESPONSE) {
|
||||
if (hdr->pkt_len == FU_EBITDO_PKT_CMD_GET_VERSION_RESPONSE) {
|
||||
if (out != NULL) {
|
||||
if (out_len != 4) {
|
||||
g_set_error (error,
|
||||
@ -317,8 +317,8 @@ ebitdo_device_receive (EbitdoDevice *device,
|
||||
}
|
||||
|
||||
/* verification-id response */
|
||||
if (hdr->type == EBITDO_PKT_TYPE_USER_CMD &&
|
||||
hdr->subtype == EBITDO_PKT_CMD_VERIFICATION_ID) {
|
||||
if (hdr->type == FU_EBITDO_PKT_TYPE_USER_CMD &&
|
||||
hdr->subtype == FU_EBITDO_PKT_CMD_VERIFICATION_ID) {
|
||||
if (out != NULL) {
|
||||
if (hdr->cmd_len != out_len) {
|
||||
g_set_error (error,
|
||||
@ -330,22 +330,22 @@ ebitdo_device_receive (EbitdoDevice *device,
|
||||
return FALSE;
|
||||
}
|
||||
memcpy (out,
|
||||
packet + sizeof(EbitdoPkt) - 3,
|
||||
packet + sizeof(FuEbitdoPkt) - 3,
|
||||
hdr->cmd_len);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* update-firmware-data */
|
||||
if (hdr->type == EBITDO_PKT_TYPE_USER_CMD &&
|
||||
hdr->subtype == EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA &&
|
||||
if (hdr->type == FU_EBITDO_PKT_TYPE_USER_CMD &&
|
||||
hdr->subtype == FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA &&
|
||||
hdr->payload_len == 0x00) {
|
||||
if (hdr->cmd != EBITDO_PKT_CMD_ACK) {
|
||||
if (hdr->cmd != FU_EBITDO_PKT_CMD_ACK) {
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_INVALID_DATA,
|
||||
"write failed, got %s",
|
||||
ebitdo_pkt_cmd_to_string (hdr->cmd));
|
||||
fu_ebitdo_pkt_cmd_to_string (hdr->cmd));
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
@ -360,9 +360,9 @@ ebitdo_device_receive (EbitdoDevice *device,
|
||||
}
|
||||
|
||||
gboolean
|
||||
ebitdo_device_open (EbitdoDevice *device, GError **error)
|
||||
fu_ebitdo_device_open (FuEbitdoDevice *device, GError **error)
|
||||
{
|
||||
EbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
FuEbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
gdouble tmp;
|
||||
guint32 version_tmp = 0;
|
||||
guint32 serial_tmp[9];
|
||||
@ -377,16 +377,16 @@ ebitdo_device_open (EbitdoDevice *device, GError **error)
|
||||
}
|
||||
|
||||
/* in firmware mode */
|
||||
if (priv->kind != EBITDO_DEVICE_KIND_BOOTLOADER) {
|
||||
if (!ebitdo_device_send (device,
|
||||
EBITDO_PKT_TYPE_USER_CMD,
|
||||
EBITDO_PKT_CMD_GET_VERSION,
|
||||
if (priv->kind != FU_EBITDO_DEVICE_KIND_BOOTLOADER) {
|
||||
if (!fu_ebitdo_device_send (device,
|
||||
FU_EBITDO_PKT_TYPE_USER_CMD,
|
||||
FU_EBITDO_PKT_CMD_GET_VERSION,
|
||||
0,
|
||||
NULL, 0, /* in */
|
||||
error)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (!ebitdo_device_receive (device,
|
||||
if (!fu_ebitdo_device_receive (device,
|
||||
(guint8 *) &version_tmp,
|
||||
sizeof(version_tmp),
|
||||
error)) {
|
||||
@ -398,15 +398,15 @@ ebitdo_device_open (EbitdoDevice *device, GError **error)
|
||||
}
|
||||
|
||||
/* get version */
|
||||
if (!ebitdo_device_send (device,
|
||||
EBITDO_PKT_TYPE_USER_CMD,
|
||||
EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA,
|
||||
EBITDO_PKT_CMD_FW_GET_VERSION,
|
||||
if (!fu_ebitdo_device_send (device,
|
||||
FU_EBITDO_PKT_TYPE_USER_CMD,
|
||||
FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA,
|
||||
FU_EBITDO_PKT_CMD_FW_GET_VERSION,
|
||||
NULL, 0, /* in */
|
||||
error)) {
|
||||
return FALSE;
|
||||
}
|
||||
if (!ebitdo_device_receive (device,
|
||||
if (!fu_ebitdo_device_receive (device,
|
||||
(guint8 *) &version_tmp,
|
||||
sizeof(version_tmp),
|
||||
error)) {
|
||||
@ -416,16 +416,16 @@ ebitdo_device_open (EbitdoDevice *device, GError **error)
|
||||
priv->version = g_strdup_printf ("%.2f", tmp / 100.f);
|
||||
|
||||
/* get verification ID */
|
||||
if (!ebitdo_device_send (device,
|
||||
EBITDO_PKT_TYPE_USER_CMD,
|
||||
EBITDO_PKT_CMD_GET_VERIFICATION_ID,
|
||||
if (!fu_ebitdo_device_send (device,
|
||||
FU_EBITDO_PKT_TYPE_USER_CMD,
|
||||
FU_EBITDO_PKT_CMD_GET_VERIFICATION_ID,
|
||||
0x00, /* cmd */
|
||||
NULL, 0,
|
||||
error)) {
|
||||
return FALSE;
|
||||
}
|
||||
memset (serial_tmp, 0x00, sizeof (serial_tmp));
|
||||
if (!ebitdo_device_receive (device,
|
||||
if (!fu_ebitdo_device_receive (device,
|
||||
(guint8 *) &serial_tmp, sizeof(serial_tmp),
|
||||
error)) {
|
||||
return FALSE;
|
||||
@ -437,43 +437,43 @@ ebitdo_device_open (EbitdoDevice *device, GError **error)
|
||||
}
|
||||
|
||||
gboolean
|
||||
ebitdo_device_close (EbitdoDevice *device, GError **error)
|
||||
fu_ebitdo_device_close (FuEbitdoDevice *device, GError **error)
|
||||
{
|
||||
EbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
FuEbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
if (!g_usb_device_close (priv->usb_device, error))
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
ebitdo_device_get_guid (EbitdoDevice *device)
|
||||
fu_ebitdo_device_get_guid (FuEbitdoDevice *device)
|
||||
{
|
||||
EbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
FuEbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
return priv->guid;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
ebitdo_device_get_version (EbitdoDevice *device)
|
||||
fu_ebitdo_device_get_version (FuEbitdoDevice *device)
|
||||
{
|
||||
EbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
FuEbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
return priv->version;
|
||||
}
|
||||
|
||||
const guint32 *
|
||||
ebitdo_device_get_serial (EbitdoDevice *device)
|
||||
fu_ebitdo_device_get_serial (FuEbitdoDevice *device)
|
||||
{
|
||||
EbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
FuEbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
return priv->serial;
|
||||
}
|
||||
|
||||
gboolean
|
||||
ebitdo_device_write_firmware (EbitdoDevice *device, GBytes *fw,
|
||||
fu_ebitdo_device_write_firmware (FuEbitdoDevice *device, GBytes *fw,
|
||||
GFileProgressCallback progress_cb,
|
||||
gpointer progress_data,
|
||||
GError **error)
|
||||
{
|
||||
EbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
EbitdoFirmwareHeader *hdr;
|
||||
FuEbitdoDevicePrivate *priv = GET_PRIVATE (device);
|
||||
FuEbitdoFirmwareHeader *hdr;
|
||||
const guint8 *payload_data;
|
||||
const guint chunk_sz = 32;
|
||||
guint32 offset;
|
||||
@ -489,7 +489,7 @@ ebitdo_device_write_firmware (EbitdoDevice *device, GBytes *fw,
|
||||
};
|
||||
|
||||
/* corrupt */
|
||||
if (g_bytes_get_size (fw) < sizeof (EbitdoFirmwareHeader)) {
|
||||
if (g_bytes_get_size (fw) < sizeof (FuEbitdoFirmwareHeader)) {
|
||||
g_set_error_literal (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_INVALID_DATA,
|
||||
@ -498,11 +498,11 @@ ebitdo_device_write_firmware (EbitdoDevice *device, GBytes *fw,
|
||||
}
|
||||
|
||||
/* print details about the firmware */
|
||||
hdr = (EbitdoFirmwareHeader *) g_bytes_get_data (fw, NULL);
|
||||
ebitdo_dump_firmware_header (hdr);
|
||||
hdr = (FuEbitdoFirmwareHeader *) g_bytes_get_data (fw, NULL);
|
||||
fu_ebitdo_dump_firmware_header (hdr);
|
||||
|
||||
/* check the file size */
|
||||
payload_len = (guint32) (g_bytes_get_size (fw) - sizeof (EbitdoFirmwareHeader));
|
||||
payload_len = (guint32) (g_bytes_get_size (fw) - sizeof (FuEbitdoFirmwareHeader));
|
||||
if (payload_len != GUINT32_FROM_LE (hdr->destination_len)) {
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
@ -526,11 +526,11 @@ ebitdo_device_write_firmware (EbitdoDevice *device, GBytes *fw,
|
||||
}
|
||||
|
||||
/* set up the firmware header */
|
||||
if (!ebitdo_device_send (device,
|
||||
EBITDO_PKT_TYPE_USER_CMD,
|
||||
EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA,
|
||||
EBITDO_PKT_CMD_FW_UPDATE_HEADER,
|
||||
(const guint8 *) hdr, sizeof(EbitdoFirmwareHeader),
|
||||
if (!fu_ebitdo_device_send (device,
|
||||
FU_EBITDO_PKT_TYPE_USER_CMD,
|
||||
FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA,
|
||||
FU_EBITDO_PKT_CMD_FW_UPDATE_HEADER,
|
||||
(const guint8 *) hdr, sizeof(FuEbitdoFirmwareHeader),
|
||||
&error_local)) {
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
@ -539,7 +539,7 @@ ebitdo_device_write_firmware (EbitdoDevice *device, GBytes *fw,
|
||||
error_local->message);
|
||||
return FALSE;
|
||||
}
|
||||
if (!ebitdo_device_receive (device, NULL, 0, &error_local)) {
|
||||
if (!fu_ebitdo_device_receive (device, NULL, 0, &error_local)) {
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_INVALID_DATA,
|
||||
@ -550,18 +550,18 @@ ebitdo_device_write_firmware (EbitdoDevice *device, GBytes *fw,
|
||||
|
||||
/* flash the firmware in 32 byte blocks */
|
||||
payload_data = g_bytes_get_data (fw, NULL);
|
||||
payload_data += sizeof(EbitdoFirmwareHeader);
|
||||
payload_data += sizeof(FuEbitdoFirmwareHeader);
|
||||
for (offset = 0; offset < payload_len; offset += chunk_sz) {
|
||||
if (g_getenv ("EBITDO_DEBUG") != NULL) {
|
||||
if (g_getenv ("FU_EBITDO_DEBUG") != NULL) {
|
||||
g_debug ("writing %u bytes to 0x%04x of 0x%04x",
|
||||
chunk_sz, offset, payload_len);
|
||||
}
|
||||
if (progress_cb != NULL)
|
||||
progress_cb (offset, payload_len, progress_data);
|
||||
if (!ebitdo_device_send (device,
|
||||
EBITDO_PKT_TYPE_USER_CMD,
|
||||
EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA,
|
||||
EBITDO_PKT_CMD_FW_UPDATE_DATA,
|
||||
if (!fu_ebitdo_device_send (device,
|
||||
FU_EBITDO_PKT_TYPE_USER_CMD,
|
||||
FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA,
|
||||
FU_EBITDO_PKT_CMD_FW_UPDATE_DATA,
|
||||
payload_data + offset, chunk_sz,
|
||||
&error_local)) {
|
||||
g_set_error (error,
|
||||
@ -571,7 +571,7 @@ ebitdo_device_write_firmware (EbitdoDevice *device, GBytes *fw,
|
||||
offset, error_local->message);
|
||||
return FALSE;
|
||||
}
|
||||
if (!ebitdo_device_receive (device, NULL, 0, &error_local)) {
|
||||
if (!fu_ebitdo_device_receive (device, NULL, 0, &error_local)) {
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_INVALID_DATA,
|
||||
@ -591,10 +591,10 @@ ebitdo_device_write_firmware (EbitdoDevice *device, GBytes *fw,
|
||||
serial_new[0] = priv->serial[0] ^ app_key_index[priv->serial[0] & 0x0f];
|
||||
serial_new[1] = priv->serial[1] ^ app_key_index[priv->serial[1] & 0x0f];
|
||||
serial_new[2] = priv->serial[2] ^ app_key_index[priv->serial[2] & 0x0f];
|
||||
if (!ebitdo_device_send (device,
|
||||
EBITDO_PKT_TYPE_USER_CMD,
|
||||
EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA,
|
||||
EBITDO_PKT_CMD_FW_SET_ENCODE_ID,
|
||||
if (!fu_ebitdo_device_send (device,
|
||||
FU_EBITDO_PKT_TYPE_USER_CMD,
|
||||
FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA,
|
||||
FU_EBITDO_PKT_CMD_FW_SET_ENCODE_ID,
|
||||
(guint8 *) serial_new,
|
||||
sizeof(serial_new),
|
||||
&error_local)) {
|
||||
@ -607,10 +607,10 @@ ebitdo_device_write_firmware (EbitdoDevice *device, GBytes *fw,
|
||||
}
|
||||
|
||||
/* mark flash as successful */
|
||||
if (!ebitdo_device_send (device,
|
||||
EBITDO_PKT_TYPE_USER_CMD,
|
||||
EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA,
|
||||
EBITDO_PKT_CMD_FW_UPDATE_OK,
|
||||
if (!fu_ebitdo_device_send (device,
|
||||
FU_EBITDO_PKT_TYPE_USER_CMD,
|
||||
FU_EBITDO_PKT_CMD_UPDATE_FIRMWARE_DATA,
|
||||
FU_EBITDO_PKT_CMD_FW_UPDATE_OK,
|
||||
NULL, 0,
|
||||
&error_local)) {
|
||||
g_set_error (error,
|
||||
@ -620,7 +620,7 @@ ebitdo_device_write_firmware (EbitdoDevice *device, GBytes *fw,
|
||||
error_local->message);
|
||||
return FALSE;
|
||||
}
|
||||
if (!ebitdo_device_receive (device, NULL, 0, &error_local)) {
|
||||
if (!fu_ebitdo_device_receive (device, NULL, 0, &error_local)) {
|
||||
g_set_error (error,
|
||||
G_IO_ERROR,
|
||||
G_IO_ERROR_INVALID_DATA,
|
||||
@ -636,37 +636,37 @@ ebitdo_device_write_firmware (EbitdoDevice *device, GBytes *fw,
|
||||
typedef struct {
|
||||
guint16 vid;
|
||||
guint16 pid;
|
||||
EbitdoDeviceKind kind;
|
||||
} EbitdoVidPid;
|
||||
FuEbitdoDeviceKind kind;
|
||||
} FuEbitdoVidPid;
|
||||
|
||||
/**
|
||||
* ebitdo_device_new:
|
||||
* fu_ebitdo_device_new:
|
||||
*
|
||||
* Creates a new #EbitdoDevice.
|
||||
* Creates a new #FuEbitdoDevice.
|
||||
*
|
||||
* Returns: (transfer full): a #EbitdoDevice
|
||||
* Returns: (transfer full): a #FuEbitdoDevice
|
||||
*
|
||||
* Since: 0.1.0
|
||||
**/
|
||||
EbitdoDevice *
|
||||
ebitdo_device_new (GUsbDevice *usb_device)
|
||||
FuEbitdoDevice *
|
||||
fu_ebitdo_device_new (GUsbDevice *usb_device)
|
||||
{
|
||||
EbitdoDevice *device;
|
||||
EbitdoDevicePrivate *priv;
|
||||
FuEbitdoDevice *device;
|
||||
FuEbitdoDevicePrivate *priv;
|
||||
guint j;
|
||||
const EbitdoVidPid vidpids[] = {
|
||||
{ 0x0483, 0x5750, EBITDO_DEVICE_KIND_BOOTLOADER },
|
||||
{ 0x1235, 0xab11, EBITDO_DEVICE_KIND_FC30 },
|
||||
{ 0x1235, 0xab12, EBITDO_DEVICE_KIND_NES30 },
|
||||
{ 0x1235, 0xab21, EBITDO_DEVICE_KIND_SFC30 },
|
||||
{ 0x1235, 0xab20, EBITDO_DEVICE_KIND_SNES30 },
|
||||
{ 0x1002, 0x9000, EBITDO_DEVICE_KIND_FC30PRO },
|
||||
{ 0x2002, 0x9000, EBITDO_DEVICE_KIND_NES30PRO },
|
||||
{ 0x8000, 0x1002, EBITDO_DEVICE_KIND_FC30_ARCADE },
|
||||
{ 0x0000, 0x0000, EBITDO_DEVICE_KIND_UNKNOWN, NULL }
|
||||
const FuEbitdoVidPid vidpids[] = {
|
||||
{ 0x0483, 0x5750, FU_EBITDO_DEVICE_KIND_BOOTLOADER },
|
||||
{ 0x1235, 0xab11, FU_EBITDO_DEVICE_KIND_FC30 },
|
||||
{ 0x1235, 0xab12, FU_EBITDO_DEVICE_KIND_NES30 },
|
||||
{ 0x1235, 0xab21, FU_EBITDO_DEVICE_KIND_SFC30 },
|
||||
{ 0x1235, 0xab20, FU_EBITDO_DEVICE_KIND_SNES30 },
|
||||
{ 0x1002, 0x9000, FU_EBITDO_DEVICE_KIND_FC30PRO },
|
||||
{ 0x2002, 0x9000, FU_EBITDO_DEVICE_KIND_NES30PRO },
|
||||
{ 0x8000, 0x1002, FU_EBITDO_DEVICE_KIND_FC30_ARCADE },
|
||||
{ 0x0000, 0x0000, FU_EBITDO_DEVICE_KIND_UNKNOWN, NULL }
|
||||
};
|
||||
|
||||
device = g_object_new (EBITDO_TYPE_DEVICE, NULL);
|
||||
device = g_object_new (FU_EBITDO_TYPE_DEVICE, NULL);
|
||||
priv = GET_PRIVATE (device);
|
||||
priv->usb_device = g_object_ref (usb_device);
|
||||
|
||||
@ -687,5 +687,5 @@ ebitdo_device_new (GUsbDevice *usb_device)
|
||||
break;
|
||||
}
|
||||
}
|
||||
return EBITDO_DEVICE (device);
|
||||
return FU_EBITDO_DEVICE (device);
|
||||
}
|
101
src/fu-ebitdo-device.h
Normal file
101
src/fu-ebitdo-device.h
Normal file
@ -0,0 +1,101 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
||||
*
|
||||
* Copyright (C) 2016 Richard Hughes <richard@hughsie.com>
|
||||
*
|
||||
* Licensed under the GNU Lesser General Public License Version 2.1
|
||||
*
|
||||
* 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; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#ifndef __FU_EBITDO_DEVICE_H
|
||||
#define __FU_EBITDO_DEVICE_H
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <gusb.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define FU_EBITDO_TYPE_DEVICE (fu_ebitdo_device_get_type ())
|
||||
G_DECLARE_DERIVABLE_TYPE (FuEbitdoDevice, fu_ebitdo_device, FU_EBITDO, DEVICE, GObject)
|
||||
|
||||
struct _FuEbitdoDeviceClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
/*< private >*/
|
||||
void (*_as_reserved1) (void);
|
||||
void (*_as_reserved2) (void);
|
||||
void (*_as_reserved3) (void);
|
||||
void (*_as_reserved4) (void);
|
||||
void (*_as_reserved5) (void);
|
||||
void (*_as_reserved6) (void);
|
||||
void (*_as_reserved7) (void);
|
||||
void (*_as_reserved8) (void);
|
||||
};
|
||||
|
||||
/**
|
||||
* FuEbitdoDeviceKind:
|
||||
* @FU_EBITDO_DEVICE_KIND_UNKNOWN: Type invalid or not known
|
||||
* @FU_EBITDO_DEVICE_KIND_BOOTLOADER: Bootloader
|
||||
* @FU_EBITDO_DEVICE_KIND_FC30: FC30
|
||||
* @FU_EBITDO_DEVICE_KIND_NES30: NES30
|
||||
* @FU_EBITDO_DEVICE_KIND_SFC30: SFC30
|
||||
* @FU_EBITDO_DEVICE_KIND_SNES30: SNES30
|
||||
* @FU_EBITDO_DEVICE_KIND_FC30PRO: FC30PRO
|
||||
* @FU_EBITDO_DEVICE_KIND_NES30PRO: NES30PRO
|
||||
* @FU_EBITDO_DEVICE_KIND_FC30_ARCADE: FC30 ARCADE
|
||||
*
|
||||
* The device type.
|
||||
**/
|
||||
typedef enum {
|
||||
FU_EBITDO_DEVICE_KIND_UNKNOWN,
|
||||
FU_EBITDO_DEVICE_KIND_BOOTLOADER,
|
||||
FU_EBITDO_DEVICE_KIND_FC30,
|
||||
FU_EBITDO_DEVICE_KIND_NES30,
|
||||
FU_EBITDO_DEVICE_KIND_SFC30,
|
||||
FU_EBITDO_DEVICE_KIND_SNES30,
|
||||
FU_EBITDO_DEVICE_KIND_FC30PRO,
|
||||
FU_EBITDO_DEVICE_KIND_NES30PRO,
|
||||
FU_EBITDO_DEVICE_KIND_FC30_ARCADE,
|
||||
/*< private >*/
|
||||
FU_EBITDO_DEVICE_KIND_LAST
|
||||
} FuEbitdoDeviceKind;
|
||||
|
||||
FuEbitdoDevice *fu_ebitdo_device_new (GUsbDevice *usb_device);
|
||||
|
||||
/* helpers */
|
||||
FuEbitdoDeviceKind fu_ebitdo_device_kind_from_string (const gchar *kind);
|
||||
const gchar *fu_ebitdo_device_kind_to_string (FuEbitdoDeviceKind kind);
|
||||
|
||||
/* getters */
|
||||
FuEbitdoDeviceKind fu_ebitdo_device_get_kind (FuEbitdoDevice *device);
|
||||
GUsbDevice *fu_ebitdo_device_get_usb_device (FuEbitdoDevice *device);
|
||||
const gchar *fu_ebitdo_device_get_version (FuEbitdoDevice *device);
|
||||
const guint32 *fu_ebitdo_device_get_serial (FuEbitdoDevice *device);
|
||||
const gchar *fu_ebitdo_device_get_guid (FuEbitdoDevice *device);
|
||||
|
||||
/* object methods */
|
||||
gboolean fu_ebitdo_device_open (FuEbitdoDevice *device,
|
||||
GError **error);
|
||||
gboolean fu_ebitdo_device_close (FuEbitdoDevice *device,
|
||||
GError **error);
|
||||
gboolean fu_ebitdo_device_write_firmware (FuEbitdoDevice *device,
|
||||
GBytes *fw,
|
||||
GFileProgressCallback progress_cb,
|
||||
gpointer progress_data,
|
||||
GError **error);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __FU_EBITDO_DEVICE_H */
|
@ -21,11 +21,11 @@
|
||||
|
||||
#include <gusb.h>
|
||||
|
||||
#include "ebitdo-common.h"
|
||||
#include "ebitdo-device.h"
|
||||
#include "fu-ebitdo-common.h"
|
||||
#include "fu-ebitdo-device.h"
|
||||
|
||||
static void
|
||||
ebitdo_write_progress_cb (goffset current, goffset total, gpointer user_data)
|
||||
fu_ebitdo_write_progress_cb (goffset current, goffset total, gpointer user_data)
|
||||
{
|
||||
gdouble percentage = -1.f;
|
||||
if (total > 0)
|
||||
@ -40,7 +40,7 @@ main (int argc, char **argv)
|
||||
gsize len;
|
||||
guint i;
|
||||
g_autofree guint8 *data = NULL;
|
||||
g_autoptr(EbitdoDevice) dev = NULL;
|
||||
g_autoptr(FuEbitdoDevice) dev = NULL;
|
||||
g_autoptr(GBytes) fw = NULL;
|
||||
g_autoptr(GError) error = NULL;
|
||||
g_autoptr(GPtrArray) devices = NULL;
|
||||
@ -64,8 +64,8 @@ main (int argc, char **argv)
|
||||
devices = g_usb_context_get_devices (usb_ctx);
|
||||
for (i = 0; i < devices->len; i++) {
|
||||
GUsbDevice *usb_dev_tmp = g_ptr_array_index (devices, i);
|
||||
g_autoptr(EbitdoDevice) dev_tmp = ebitdo_device_new (usb_dev_tmp);
|
||||
if (ebitdo_device_get_kind (dev_tmp) != EBITDO_DEVICE_KIND_UNKNOWN) {
|
||||
g_autoptr(FuEbitdoDevice) dev_tmp = fu_ebitdo_device_new (usb_dev_tmp);
|
||||
if (fu_ebitdo_device_get_kind (dev_tmp) != FU_EBITDO_DEVICE_KIND_UNKNOWN) {
|
||||
dev = g_object_ref (dev_tmp);
|
||||
break;
|
||||
}
|
||||
@ -77,37 +77,37 @@ main (int argc, char **argv)
|
||||
return 1;
|
||||
}
|
||||
g_debug ("found %s [%04x:%04x]",
|
||||
ebitdo_device_kind_to_string (ebitdo_device_get_kind (dev)),
|
||||
g_usb_device_get_vid (ebitdo_device_get_usb_device (dev)),
|
||||
g_usb_device_get_pid (ebitdo_device_get_usb_device (dev)));
|
||||
fu_ebitdo_device_kind_to_string (fu_ebitdo_device_get_kind (dev)),
|
||||
g_usb_device_get_vid (fu_ebitdo_device_get_usb_device (dev)),
|
||||
g_usb_device_get_pid (fu_ebitdo_device_get_usb_device (dev)));
|
||||
|
||||
/* open device */
|
||||
if (!ebitdo_device_open (dev, &error)) {
|
||||
if (!fu_ebitdo_device_open (dev, &error)) {
|
||||
g_print ("Failed to open USB device: %s\n", error->message);
|
||||
return 1;
|
||||
}
|
||||
g_print ("Device Firmware Ver: %s\n", ebitdo_device_get_version (dev));
|
||||
g_print ("Device Firmware Ver: %s\n", fu_ebitdo_device_get_version (dev));
|
||||
g_print ("Device Verification ID:\n");
|
||||
for (i = 0; i < 9; i++)
|
||||
g_print ("\t%u = 0x%08x\n", i, ebitdo_device_get_serial(dev)[i]);
|
||||
g_print ("\t%u = 0x%08x\n", i, fu_ebitdo_device_get_serial(dev)[i]);
|
||||
|
||||
/* not in bootloader mode, so print what to do */
|
||||
if (ebitdo_device_get_kind (dev) != EBITDO_DEVICE_KIND_BOOTLOADER) {
|
||||
if (fu_ebitdo_device_get_kind (dev) != FU_EBITDO_DEVICE_KIND_BOOTLOADER) {
|
||||
g_print ("1. Disconnect the controller\n");
|
||||
switch (ebitdo_device_get_kind (dev)) {
|
||||
case EBITDO_DEVICE_KIND_FC30:
|
||||
case EBITDO_DEVICE_KIND_NES30:
|
||||
case EBITDO_DEVICE_KIND_SFC30:
|
||||
case EBITDO_DEVICE_KIND_SNES30:
|
||||
switch (fu_ebitdo_device_get_kind (dev)) {
|
||||
case FU_EBITDO_DEVICE_KIND_FC30:
|
||||
case FU_EBITDO_DEVICE_KIND_NES30:
|
||||
case FU_EBITDO_DEVICE_KIND_SFC30:
|
||||
case FU_EBITDO_DEVICE_KIND_SNES30:
|
||||
g_print ("2. Hold down L+R+START for 3 seconds until "
|
||||
"both LED lights flashing.\n");
|
||||
break;
|
||||
case EBITDO_DEVICE_KIND_FC30PRO:
|
||||
case EBITDO_DEVICE_KIND_NES30PRO:
|
||||
case FU_EBITDO_DEVICE_KIND_FC30PRO:
|
||||
case FU_EBITDO_DEVICE_KIND_NES30PRO:
|
||||
g_print ("2. Hold down RETURN+POWER for 3 seconds until "
|
||||
"both LED lights flashing.\n");
|
||||
break;
|
||||
case EBITDO_DEVICE_KIND_FC30_ARCADE:
|
||||
case FU_EBITDO_DEVICE_KIND_FC30_ARCADE:
|
||||
g_print ("2. Hold down L1+R1+HOME for 3 seconds until "
|
||||
"both blue LED and green LED blink.\n");
|
||||
break;
|
||||
@ -127,15 +127,15 @@ main (int argc, char **argv)
|
||||
|
||||
/* update with data blob */
|
||||
fw = g_bytes_new (data, len);
|
||||
if (!ebitdo_device_write_firmware (dev, fw,
|
||||
ebitdo_write_progress_cb, NULL,
|
||||
if (!fu_ebitdo_device_write_firmware (dev, fw,
|
||||
fu_ebitdo_write_progress_cb, NULL,
|
||||
&error)) {
|
||||
g_print ("Failed to write firmware: %s\n", error->message);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* close device */
|
||||
if (!ebitdo_device_close (dev, &error)) {
|
||||
if (!fu_ebitdo_device_close (dev, &error)) {
|
||||
g_print ("Failed to close USB device: %s\n", error->message);
|
||||
return 1;
|
||||
}
|
@ -26,7 +26,7 @@
|
||||
#include <glib-object.h>
|
||||
#include <gusb.h>
|
||||
|
||||
#include "ebitdo.h"
|
||||
#include "fu-ebitdo-device.h"
|
||||
#include "fu-device.h"
|
||||
#include "fu-provider-ebitdo.h"
|
||||
|
||||
@ -34,7 +34,7 @@ static void fu_provider_ebitdo_finalize (GObject *object);
|
||||
|
||||
typedef struct {
|
||||
GHashTable *devices; /* id : FuDevice */
|
||||
GHashTable *devices_runtime; /* id : EbitdoDevice */
|
||||
GHashTable *devices_runtime; /* id : FuEbitdoDevice */
|
||||
GUsbContext *usb_ctx;
|
||||
gboolean done_enumerate;
|
||||
} FuProviderEbitdoPrivate;
|
||||
@ -54,11 +54,11 @@ fu_provider_ebitdo_device_added (FuProviderEbitdo *provider_ebitdo,
|
||||
GError **error)
|
||||
{
|
||||
FuProviderEbitdoPrivate *priv = GET_PRIVATE (provider_ebitdo);
|
||||
EbitdoDeviceKind ebitdo_kind;
|
||||
FuEbitdoDeviceKind ebitdo_kind;
|
||||
const gchar *platform_id = NULL;
|
||||
g_autoptr(AsProfile) profile = as_profile_new ();
|
||||
g_autoptr(AsProfileTask) ptask = NULL;
|
||||
g_autoptr(EbitdoDevice) ebitdo_dev = NULL;
|
||||
g_autoptr(FuEbitdoDevice) ebitdo_dev = NULL;
|
||||
g_autoptr(FuDevice) dev = NULL;
|
||||
g_autofree gchar *name = NULL;
|
||||
|
||||
@ -69,8 +69,8 @@ fu_provider_ebitdo_device_added (FuProviderEbitdo *provider_ebitdo,
|
||||
|
||||
/* get version */
|
||||
platform_id = g_usb_device_get_platform_id (usb_device);
|
||||
ebitdo_dev = ebitdo_device_new (usb_device);
|
||||
if (ebitdo_device_get_kind (ebitdo_dev) == EBITDO_DEVICE_KIND_UNKNOWN) {
|
||||
ebitdo_dev = fu_ebitdo_device_new (usb_device);
|
||||
if (fu_ebitdo_device_get_kind (ebitdo_dev) == FU_EBITDO_DEVICE_KIND_UNKNOWN) {
|
||||
g_set_error_literal (error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_NOT_SUPPORTED,
|
||||
@ -79,36 +79,36 @@ fu_provider_ebitdo_device_added (FuProviderEbitdo *provider_ebitdo,
|
||||
}
|
||||
|
||||
/* open the device */
|
||||
if (!ebitdo_device_open (ebitdo_dev, error))
|
||||
if (!fu_ebitdo_device_open (ebitdo_dev, error))
|
||||
return FALSE;
|
||||
|
||||
/* generate name */
|
||||
ebitdo_kind = ebitdo_device_get_kind (ebitdo_dev);
|
||||
ebitdo_kind = fu_ebitdo_device_get_kind (ebitdo_dev);
|
||||
name = g_strdup_printf ("8Bitdo %s Gamepad",
|
||||
ebitdo_device_kind_to_string (ebitdo_kind));
|
||||
fu_ebitdo_device_kind_to_string (ebitdo_kind));
|
||||
|
||||
/* create the device */
|
||||
dev = fu_device_new ();
|
||||
fu_device_set_id (dev, platform_id);
|
||||
fu_device_add_flag (dev, FWUPD_DEVICE_FLAG_ALLOW_ONLINE);
|
||||
fu_device_add_guid (dev, ebitdo_device_get_guid (ebitdo_dev));
|
||||
fu_device_set_version (dev, ebitdo_device_get_version (ebitdo_dev));
|
||||
fu_device_add_guid (dev, fu_ebitdo_device_get_guid (ebitdo_dev));
|
||||
fu_device_set_version (dev, fu_ebitdo_device_get_version (ebitdo_dev));
|
||||
fu_device_set_name (dev, name);
|
||||
|
||||
/* close the device */
|
||||
if (!ebitdo_device_close (ebitdo_dev, error))
|
||||
if (!fu_ebitdo_device_close (ebitdo_dev, error))
|
||||
return FALSE;
|
||||
|
||||
/* only the bootloader can do the update */
|
||||
if (ebitdo_kind == EBITDO_DEVICE_KIND_BOOTLOADER) {
|
||||
EbitdoDevice *ebitdo_runtime;
|
||||
if (ebitdo_kind == FU_EBITDO_DEVICE_KIND_BOOTLOADER) {
|
||||
FuEbitdoDevice *ebitdo_runtime;
|
||||
fu_device_remove_flag (dev, FWUPD_DEVICE_FLAG_NEEDS_BOOTLOADER);
|
||||
|
||||
/* add the last seen runtime GUID too */
|
||||
ebitdo_runtime = g_hash_table_lookup (priv->devices_runtime, platform_id);
|
||||
if (ebitdo_runtime != NULL) {
|
||||
const gchar *guid;
|
||||
guid = ebitdo_device_get_guid (ebitdo_runtime);
|
||||
guid = fu_ebitdo_device_get_guid (ebitdo_runtime);
|
||||
g_debug ("adding runtime GUID of %s", guid);
|
||||
fu_device_add_guid (dev, guid);
|
||||
}
|
||||
@ -118,7 +118,7 @@ fu_provider_ebitdo_device_added (FuProviderEbitdo *provider_ebitdo,
|
||||
g_strdup (platform_id),
|
||||
g_object_ref (ebitdo_dev));
|
||||
g_debug ("saving runtime GUID of %s",
|
||||
ebitdo_device_get_guid (ebitdo_dev));
|
||||
fu_ebitdo_device_get_guid (ebitdo_dev));
|
||||
}
|
||||
|
||||
/* insert to hash */
|
||||
@ -149,7 +149,7 @@ fu_provider_ebitdo_update (FuProvider *provider,
|
||||
FuProviderEbitdo *provider_ebitdo = FU_PROVIDER_EBITDO (provider);
|
||||
FuProviderEbitdoPrivate *priv = GET_PRIVATE (provider_ebitdo);
|
||||
const gchar *platform_id;
|
||||
g_autoptr(EbitdoDevice) ebitdo_dev = NULL;
|
||||
g_autoptr(FuEbitdoDevice) ebitdo_dev = NULL;
|
||||
g_autoptr(GUsbDevice) usb_device = NULL;
|
||||
|
||||
/* get version */
|
||||
@ -159,8 +159,8 @@ fu_provider_ebitdo_update (FuProvider *provider,
|
||||
error);
|
||||
if (usb_device == NULL)
|
||||
return FALSE;
|
||||
ebitdo_dev = ebitdo_device_new (usb_device);
|
||||
if (ebitdo_device_get_kind (ebitdo_dev) != EBITDO_DEVICE_KIND_BOOTLOADER) {
|
||||
ebitdo_dev = fu_ebitdo_device_new (usb_device);
|
||||
if (fu_ebitdo_device_get_kind (ebitdo_dev) != FU_EBITDO_DEVICE_KIND_BOOTLOADER) {
|
||||
g_set_error_literal (error,
|
||||
FWUPD_ERROR,
|
||||
FWUPD_ERROR_NOT_SUPPORTED,
|
||||
@ -169,15 +169,15 @@ fu_provider_ebitdo_update (FuProvider *provider,
|
||||
}
|
||||
|
||||
/* write the firmware */
|
||||
if (!ebitdo_device_open (ebitdo_dev, error))
|
||||
if (!fu_ebitdo_device_open (ebitdo_dev, error))
|
||||
return FALSE;
|
||||
fu_provider_set_status (provider, FWUPD_STATUS_DEVICE_WRITE);
|
||||
if (!ebitdo_device_write_firmware (ebitdo_dev, blob_fw,
|
||||
if (!fu_ebitdo_device_write_firmware (ebitdo_dev, blob_fw,
|
||||
ebitdo_write_progress_cb, provider,
|
||||
error))
|
||||
return FALSE;
|
||||
fu_provider_set_status (provider, FWUPD_STATUS_DEVICE_RESTART);
|
||||
if (!ebitdo_device_close (ebitdo_dev, error))
|
||||
if (!fu_ebitdo_device_close (ebitdo_dev, error))
|
||||
return FALSE;
|
||||
|
||||
/* success */
|
||||
|
Loading…
Reference in New Issue
Block a user