flash-hmmoduart: add utility to upgrade firmware on HM-MOD-UART
[hmcfgusb] / hmuartlgw.h
CommitLineData
3e34d2ce
MG
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
853cbce9 28#define HMUARTLGW_OS_UPDATE_FIRMWARE 0x05
3e34d2ce
MG
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
c101217d 44#define HMUARTLGW_APP_GET_PEERS 0x08
3e34d2ce
MG
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
c101217d
MG
50#define HMUARTLGW_ACK_EINPROGRESS 0x08
51
3e34d2ce
MG
52enum hmuartlgw_dst {
53 HMUARTLGW_OS = 0,
54 HMUARTLGW_APP = 1,
55};
56
57typedef int (*hmuartlgw_cb_fn)(enum hmuartlgw_dst dst, uint8_t *buf, int buf_len, void *data);
58
59struct hmuartlgw_dev {
60 int fd;
61 hmuartlgw_cb_fn cb;
62 void *cb_data;
63 uint8_t last_send_cnt;
64 uint8_t buf[1024];
65 int pos;
66 int unescape_next;
67};
68
853cbce9 69struct hmuartlgw_dev *hmuart_init(char *device, hmuartlgw_cb_fn cb, void *data, int app);
3e34d2ce
MG
70struct hmuartlgw_dev *hmlgw_init(char *device, hmuartlgw_cb_fn cb, void *data);
71int hmuartlgw_send_raw(struct hmuartlgw_dev *dev, uint8_t *frame, int framelen);
72int hmuartlgw_send(struct hmuartlgw_dev *dev, uint8_t *cmd, int cmdlen, enum hmuartlgw_dst dst);
73int hmuartlgw_poll(struct hmuartlgw_dev *dev, int timeout);
74void hmuartlgw_close(struct hmuartlgw_dev *dev);
75void hmuartlgw_flush(struct hmuartlgw_dev *dev);
76void hmuartlgw_enter_bootloader(struct hmuartlgw_dev *dev);
77void hmuartlgw_enter_app(struct hmuartlgw_dev *dev);
78void hmuartlgw_set_debug(int d);
Impressum, Datenschutz