]>
cvs.zerfleddert.de Git - hmcfgusb/blob - flash-hmcfgusb.c
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
;
82 uint8_t out
[0x40]; //FIXME!!!
89 hmcfgusb_set_debug(0);
91 memset(&rdata
, 0, sizeof(rdata
));
93 dev
= hmcfgusb_init(parse_hmcfgusb
, &rdata
);
95 fprintf(stderr
, "Can't initialize HM-CFG-USB\n");
98 printf("HM-CFG-USB opened!\n");
100 fd
= open("hmusbif.enc", O_RDONLY
);
102 perror("Can't open hmusbif.enc");
108 memset(buf
, 0, sizeof(buf
));
109 r
= read(fd
, buf
, sizeof(buf
));
116 memset(out
, 0, sizeof(out
));
117 for (i
= 0; i
< r
; i
+=2) {
118 out
[i
/2] = (ascii_to_nibble(buf
[i
]) & 0xf)<< 4;
119 out
[i
/2] |= ascii_to_nibble(buf
[i
+1]) & 0xf;
122 printf("Flashing %d bytes...\n", cnt
);
123 hmcfgusb_send(dev
, out
, r
/2, 1);