Suppress warnings about non-literal format strings
[hmcfgusb] / hmuartlgw.h
1 /* HM-MOD-UART/HM-LGW-O-TW-W-EU driver
2 *
3 * Copyright (c) 2016-17 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_UPDATE_FIRMWARE 0x05
29 #define HMUARTLGW_OS_UNSOL_CREDITS 0x05
30 #define HMUARTLGW_OS_NORMAL_MODE 0x06
31 #define HMUARTLGW_OS_UPDATE_MODE 0x07
32 #define HMUARTLGW_OS_GET_CREDITS 0x08
33 #define HMUARTLGW_OS_GET_SERIAL 0x0B
34 #define HMUARTLGW_OS_SET_TIME 0x0E
35
36 #define HMUARTLGW_APP_SET_HMID 0x00
37 #define HMUARTLGW_APP_GET_HMID 0x01
38 #define HMUARTLGW_APP_SEND 0x02
39 #define HMUARTLGW_APP_SET_CURRENT_KEY 0x03 /* key index */
40 #define HMUARTLGW_APP_ACK 0x04
41 #define HMUARTLGW_APP_RECV 0x05
42 #define HMUARTLGW_APP_ADD_PEER 0x06
43 #define HMUARTLGW_APP_REMOVE_PEER 0x07
44 #define HMUARTLGW_APP_GET_PEERS 0x08
45 #define HMUARTLGW_APP_PEER_ADD_AES 0x09
46 #define HMUARTLGW_APP_PEER_REMOVE_AES 0x0A
47 #define HMUARTLGW_APP_SET_OLD_KEY 0x0F /* key index */
48 #define HMUARTLGW_APP_DEFAULT_HMID 0x10
49
50 #define HMUARTLGW_DUAL_GET_APP 0x01
51 #define HMUARTLGW_DUAL_CHANGE_APP 0x02
52
53 #define HMUARTLGW_ACK_EINPROGRESS 0x08
54
55 enum hmuartlgw_dst {
56 HMUARTLGW_OS = 0,
57 HMUARTLGW_APP = 1,
58 HMUARTLGW_DUAL = 0xfe,
59 HMUARTLGW_DUAL_ERR = 0xff,
60 };
61
62 typedef int (*hmuartlgw_cb_fn)(enum hmuartlgw_dst dst, uint8_t *buf, int buf_len, void *data);
63
64 struct hmuartlgw_dev {
65 int fd;
66 hmuartlgw_cb_fn cb;
67 void *cb_data;
68 uint8_t last_send_cnt;
69 uint8_t buf[1024];
70 int pos;
71 int unescape_next;
72 };
73
74 struct hmuartlgw_dev *hmuart_init(char *device, hmuartlgw_cb_fn cb, void *data, int app);
75 struct hmuartlgw_dev *hmlgw_init(char *device, hmuartlgw_cb_fn cb, void *data);
76 int hmuartlgw_send_raw(struct hmuartlgw_dev *dev, uint8_t *frame, int framelen);
77 int hmuartlgw_send(struct hmuartlgw_dev *dev, uint8_t *cmd, int cmdlen, enum hmuartlgw_dst dst);
78 int hmuartlgw_poll(struct hmuartlgw_dev *dev, int timeout);
79 void hmuartlgw_close(struct hmuartlgw_dev *dev);
80 void hmuartlgw_flush(struct hmuartlgw_dev *dev);
81 void hmuartlgw_enter_bootloader(struct hmuartlgw_dev *dev);
82 void hmuartlgw_enter_app(struct hmuartlgw_dev *dev);
83 void hmuartlgw_set_debug(int d);
Impressum, Datenschutz