]>
git.zerfleddert.de Git - hmcfgusb/blob - flash-hmcfgusb.c
c7781a047b2378395a3ed07c0f2eccd94612d036
1 /* (not working) flasher for HM-CFG-USB
3 * Copyright (c) 2013 Michael Gernoth <michael@gernoth.net>
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to
7 * deal in the Software without restriction, including without limitation the
8 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 * sell copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 #include <sys/types.h>
36 #include <libusb-1.0/libusb.h>
44 static int parse_hmcfgusb(uint8_t *buf
, int buf_len
, void *data
)
56 hexdump(buf
, buf_len
, "Unknown> ");
63 static uint8_t ascii_to_nibble(uint8_t a
)
67 if ((a
>= '0') && (a
<= '9')) {
69 } else if ((a
>= 'A') && (a
<= 'F')) {
71 } else if ((a
>= 'a') && (a
<= 'f')) {
78 int main(int argc
, char **argv
)
80 struct hmcfgusb_dev
*dev
;
81 struct recv_data rdata
;
91 hmcfgusb_set_debug(0);
93 memset(&rdata
, 0, sizeof(rdata
));
95 dev
= hmcfgusb_init(parse_hmcfgusb
, &rdata
);
97 fprintf(stderr
, "Can't initialize HM-CFG-USB\n");
100 printf("HM-CFG-USB opened!\n");
102 fd
= open("hmusbif.enc", O_RDONLY
);
104 perror("Can't open hmusbif.enc");
113 memset(buf
, 0, sizeof(buf
));
114 r
= read(fd
, buf
, 4);
121 printf("can't get length information!\n");
125 len
= (ascii_to_nibble(buf
[0]) & 0xf)<< 4;
126 len
|= ascii_to_nibble(buf
[1]) & 0xf;
128 len
|= (ascii_to_nibble(buf
[2]) & 0xf)<< 4;
129 len
|= ascii_to_nibble(buf
[3]) & 0xf;
131 printf("packet length: %x\n", len
);
133 r
= read(fd
, buf
, len
* 2);
137 } else if (r
< len
* 2) {
138 printf("short read, aborting (%d < %d)\n", r
, len
* 2);
142 memset(out
, 0, sizeof(out
));
145 *outp
++ = (pkt
>> 8) & 0xff;
146 *outp
++ = pkt
& 0xff;
147 *outp
++ = (len
>> 8) & 0xff;
148 *outp
++ = len
& 0xff;
149 for (i
= 0; i
< r
; i
+=2) {
150 *outp
= (ascii_to_nibble(buf
[i
]) & 0xf)<< 4;
151 *outp
|= ascii_to_nibble(buf
[i
+1]) & 0xf;
155 printf("Flashing %d bytes...\n", cnt
);
156 hexdump(out
, outp
-out
, "F> ");
157 //hmcfgusb_send(dev, out, r/2, 1);