1 /* HM-sniffer 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>
33 #include <sys/socket.h>
34 #include <netinet/in.h>
35 #include <arpa/inet.h>
36 #include <libusb-1.0/libusb.h>
42 char *hm_message_types(uint8_t type
)
49 return "Configuration";
82 return "Water sensor";
85 return "Climate event";
88 return "Weather event";
96 static void dissect_hm(uint8_t *buf
, int len
)
100 for (i
= 0; i
< len
; i
++) {
101 printf("%02X", buf
[i
]);
104 printf("Packet information:\n");
105 printf("\tLength: %u\n", buf
[0]);
106 printf("\tMessage ID: %u\n", buf
[1]);
107 printf("\tSender: %02x%02x%02x\n", buf
[4], buf
[5], buf
[6]);
108 printf("\tReceiver: %02x%02x%02x\n", buf
[7], buf
[8], buf
[9]);
109 printf("\tControl Byte: 0x%02x\n", buf
[2]);
110 printf("\t\tFlags: ");
111 if (buf
[2] & (1 << 0)) printf("WAKEUP ");
112 if (buf
[2] & (1 << 1)) printf("WAKEMEUP ");
113 if (buf
[2] & (1 << 2)) printf("CFG ");
114 if (buf
[2] & (1 << 3)) printf("? ");
115 if (buf
[2] & (1 << 4)) printf("BURST ");
116 if (buf
[2] & (1 << 5)) printf("BIDI ");
117 if (buf
[2] & (1 << 6)) printf("RPTED ");
118 if (buf
[2] & (1 << 7)) printf("RPTEN ");
120 printf("\tMessage type: %s (0x%02x)\n", hm_message_types(buf
[3]), buf
[3]);
121 printf("\tMesage: ");
122 for (i
= 10; i
< len
; i
++) {
123 printf("%02X", buf
[i
]);
131 static void parse_hmcfgusb(uint8_t *buf
, int buf_len
, void *data
)
138 dissect_hm(buf
+ 13, buf
[13] + 1);
145 hexdump(buf
, buf_len
, "Unknown> ");
151 int main(int argc
, char **argv
)
153 struct hmcfgusb_dev
*dev
;
156 hmcfgusb_set_debug(0);
158 dev
= hmcfgusb_init(parse_hmcfgusb
, NULL
);
160 fprintf(stderr
, "Can't initialize HM-CFG-USB!\n");
164 hmcfgusb_send(dev
, (unsigned char*)"A\00\00\00", 3, 1);
169 fd
= hmcfgusb_poll(dev
, 3600);
171 fprintf(stderr
, "activity on unknown fd %d!\n", fd
);
173 } else if (fd
== -1) {
175 perror("hmcfgusb_poll");