]> git.zerfleddert.de Git - hmcfgusb/blob - hmuartlgw.h
hmuartlgw: simplify crc check
[hmcfgusb] / hmuartlgw.h
1 /* HM-MOD-UART/HM-LGW-O-TW-W-EU driver
2 *
3 * Copyright (c) 2016 Michael Gernoth <michael@gernoth.net>
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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
21 * IN THE SOFTWARE.
22 */
23
24 #define HMUARTLGW_OS_GET_APP 0x00
25 #define HMUARTLGW_OS_GET_FIRMWARE 0x02
26 #define HMUARTLGW_OS_CHANGE_APP 0x03
27 #define HMUARTLGW_OS_ACK 0x04
28 #define HMUARTLGW_OS_UNSOL_CREDITS 0x05
29 #define HMUARTLGW_OS_NORMAL_MODE 0x06
30 #define HMUARTLGW_OS_UPDATE_MODE 0x07
31 #define HMUARTLGW_OS_GET_CREDITS 0x08
32 #define HMUARTLGW_OS_GET_SERIAL 0x0B
33 #define HMUARTLGW_OS_SET_TIME 0x0E
34
35 #define HMUARTLGW_APP_SET_HMID 0x00
36 #define HMUARTLGW_APP_GET_HMID 0x01
37 #define HMUARTLGW_APP_SEND 0x02
38 #define HMUARTLGW_APP_SET_CURRENT_KEY 0x03 /* key index */
39 #define HMUARTLGW_APP_ACK 0x04
40 #define HMUARTLGW_APP_RECV 0x05
41 #define HMUARTLGW_APP_ADD_PEER 0x06
42 #define HMUARTLGW_APP_REMOVE_PEER 0x07
43 #define HMUARTLGW_APP_GET_PEERS 0x08
44 #define HMUARTLGW_APP_PEER_ADD_AES 0x09
45 #define HMUARTLGW_APP_PEER_REMOVE_AES 0x0A
46 #define HMUARTLGW_APP_SET_OLD_KEY 0x0F /* key index */
47 #define HMUARTLGW_APP_DEFAULT_HMID 0x10
48
49 #define HMUARTLGW_ACK_EINPROGRESS 0x08
50
51 enum hmuartlgw_dst {
52 HMUARTLGW_OS = 0,
53 HMUARTLGW_APP = 1,
54 };
55
56 typedef int (*hmuartlgw_cb_fn)(enum hmuartlgw_dst dst, uint8_t *buf, int buf_len, void *data);
57
58 struct hmuartlgw_dev {
59 int fd;
60 hmuartlgw_cb_fn cb;
61 void *cb_data;
62 uint8_t last_send_cnt;
63 uint8_t buf[1024];
64 int pos;
65 int unescape_next;
66 };
67
68 struct hmuartlgw_dev *hmuart_init(char *device, hmuartlgw_cb_fn cb, void *data);
69 struct hmuartlgw_dev *hmlgw_init(char *device, hmuartlgw_cb_fn cb, void *data);
70 int hmuartlgw_send_raw(struct hmuartlgw_dev *dev, uint8_t *frame, int framelen);
71 int hmuartlgw_send(struct hmuartlgw_dev *dev, uint8_t *cmd, int cmdlen, enum hmuartlgw_dst dst);
72 int hmuartlgw_poll(struct hmuartlgw_dev *dev, int timeout);
73 void hmuartlgw_close(struct hmuartlgw_dev *dev);
74 void hmuartlgw_flush(struct hmuartlgw_dev *dev);
75 void hmuartlgw_enter_bootloader(struct hmuartlgw_dev *dev);
76 void hmuartlgw_enter_app(struct hmuartlgw_dev *dev);
77 void hmuartlgw_set_debug(int d);
Impressum, Datenschutz