15 if(!
usbrecv(kb, data_pkt, in_pkt))
17 if(in_pkt[0] != 0x0e || in_pkt[1] != 0x01){
21 short vendor, product, version, bootloader;
23 memcpy(&version, in_pkt + 8, 2);
24 memcpy(&bootloader, in_pkt + 10, 2);
25 memcpy(&vendor, in_pkt + 12, 2);
26 memcpy(&product, in_pkt + 14, 2);
27 char poll = in_pkt[16];
34 ckb_warn(
"Got vendor ID %04x (expected %04x)\n", vendor, kb->
vendor);
36 ckb_warn(
"Got product ID %04x (expected %04x)\n", product, kb->
product);
38 if(version == 0 || bootloader == 0){
51 #define FW_MAXSIZE (255 * 256)
58 int fd = open(path, O_RDONLY);
60 ckb_err(
"Failed to open firmware file %s: %s\n", path, strerror(errno));
63 ssize_t length = read(fd, fwdata,
FW_MAXSIZE + 1);
65 ckb_err(
"Failed to read firmware file %s: %s\n", path, length <= 0 ? strerror(errno) :
"Wrong size");
71 short vendor, product, version;
73 memcpy(&vendor, fwdata + 0x102, 2);
74 memcpy(&product, fwdata + 0x104, 2);
75 memcpy(&version, fwdata + 0x106, 2);
78 ckb_err(
"Firmware file %s doesn't match device (V: %04x P: %04x)\n", path, vendor, product);
81 ckb_info(
"Loading firmware version %04x from %s\n", version, path);
82 nprintf(kb, nnumber, 0,
"fwupdate %s 0/%d\n", path, (
int)length);
87 { 0x07, 0x0c, 0xf0, 0x01, 0 },
88 { 0x07, 0x0d, 0xf0, 0 },
89 { 0x7f, 0x01, 0x3c, 0 },
90 { 0x7f, 0x02, 0x3c, 0 },
91 { 0x7f, 0x03, 0x3c, 0 },
92 { 0x7f, 0x04, 0x3c, 0 },
93 { 0x7f, 0x05, 0x10, 0 }
95 int output = 0, last = 0;
97 while(output < length){
100 data_pkt[1][6] = index++;
101 while(output < length){
105 memcpy(data_pkt[npackets] + 4, fwdata + output, 60);
110 memcpy(data_pkt[npackets] + 4, fwdata + output, 16);
117 if(!
usbsend(kb, data_pkt[0], 1)){
118 ckb_err(
"Firmware update failed\n");
123 if(!
usbsend(kb, data_pkt[2], npackets - 1)){
124 ckb_err(
"Firmware update failed\n");
130 data_pkt[npackets][2] = length - last;
131 if(!
usbsend(kb, data_pkt[1], npackets)){
132 ckb_err(
"Firmware update failed\n");
136 nprintf(kb, nnumber, 0,
"fwupdate %s %d/%d\n", path, output, (
int)length);
140 { 0x07, 0x0d, 0xf0, 0x00, 0x00, 0x00, index },
141 { 0x07, 0x02, 0xf0, 0 }
143 if(!
usbsend(kb, data_pkt2[0], 2)){
144 ckb_err(
"Firmware update failed\n");
150 ckb_info(
"Firmware update complete\n");
161 int ret =
fwupdate(kb, path, nnumber);
170 nprintf(kb, nnumber, 0,
"fwupdate %s ok\n", path);
174 nprintf(kb, nnumber, 0,
"fwupdate %s invalid\n", path);
177 nprintf(kb, nnumber, 0,
"fwupdate %s fail\n", path);
void nprintf(usbdevice *kb, int nodenumber, usbmode *mode, const char *format,...)
int usb_tryreset(usbdevice *kb)
#define ckb_err(fmt, args...)
int mkfwnode(usbdevice *kb)
Writes a keyboard's firmware version and poll rate to its device node.
#define ckb_warn(fmt, args...)
#define ckb_info(fmt, args...)
#define usbrecv(kb, out_msg, in_msg)
usbrecv macro is used to wrap _usbrecv() with debugging information (file and lineno) ...
#define HAS_FEATURES(kb, feat)
Definitions for using USB interface.
int cmd_fwupdate(usbdevice *kb, usbmode *dummy1, int nnumber, int dummy2, const char *path)
int fwupdate(usbdevice *kb, const char *path, int nnumber)
#define usbsend(kb, messages, count)
usbsend macro is used to wrap _usbsend() with debugging information (file and lineno) ...
int getfwversion(usbdevice *kb)