forked from Baael/moxa-nport-driver-3.11
-
Notifications
You must be signed in to change notification settings - Fork 0
/
npreal2d.h
292 lines (255 loc) · 7.06 KB
/
npreal2d.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#ifndef _NPREAL2D_H
#define _NPREAL2D_H
#include "redund.h"
#undef FD_SETSIZE
#define FD_SETSIZE 1024
#define NPREAL_ASPP_COMMAND_SET 1
#define NPREAL_LOCAL_COMMAND_SET 2
/* local command set */
#define LOCAL_CMD_TTY_USED 1
#define LOCAL_CMD_TTY_UNUSED 2
#define NPREAL_NET_CONNECTED 3
#define NPREAL_NET_DISCONNECTED 4
#define NPREAL_NET_SETTING 5
/*
* * Moxa tty definition
* */
#define ASPP_CMD_NOTIFY 0x26
#define ASPP_CMD_POLLING 0x27
#define ASPP_CMD_ALIVE 0x28
#define ASPP_CMD_IOCTL 16
#define ASPP_CMD_FLOWCTRL 17
#define ASPP_CMD_LSTATUS 19
#define ASPP_CMD_LINECTRL 18
#define ASPP_CMD_FLUSH 20
#define ASPP_CMD_OQUEUE 22
#define ASPP_CMD_SETBAUD 23
#define ASPP_CMD_START_BREAK 33
#define ASPP_CMD_STOP_BREAK 34
#define ASPP_CMD_START_NOTIFY 36
#define ASPP_CMD_STOP_NOTIFY 37
#define ASPP_CMD_HOST 43
#define ASPP_CMD_PORT_INIT 44
#define ASPP_CMD_WAIT_OQUEUE 47
#define ASPP_CMD_IQUEUE 21
#define ASPP_CMD_XONXOFF 24
#define ASPP_CMD_PORT_RESET 32
#define ASPP_CMD_RESENT_TIME 46
#define ASPP_CMD_TX_FIFO 48
#define ASPP_CMD_SETXON 51
#define ASPP_CMD_SETXOFF 52
#define CMD_RETRIEVE 1
#define CMD_RESPONSE 2
#define CMD_CONNECTED 3
#define CMD_DISCONNECTED 4
#define CMD_NET_SETTING 5
#define CMD_GET_TTY_STATUS 6
/* The following defines the server type */
#define DE311 311
#define DE301 301
#define DE302 302
#define DE304 304
#define DE331 331
#define DE332 332
#define DE334 334
#define DE303 303
#define DE308 308
#define DE309 309
#define CN2100 2100
#define CN2500 2500
#define CMD_BUFFER_SIZE 84 /* temporary cmd buffer size */
/*dsci command for ipv6*/
#define EX_VERSION 1
#define DSCI_IPV6 0x79
#define DSCI_IPV6_RESPONS 0xF9
/* CATALOG */
#define KERNEL_FUN 0x0001
#define NETWORK_CONFIG 0x0002
/* SUBCODE */
#define DSC_ENUMSEARCH 0x0001
#define DSC_GETNETSTAT_V6 0x0004
#define MAX_SOCK_V6 64
#define IPADDR2 1
#define BUF_LEN 1024
#define HEADER_LEN 12
#define REDUNDANT_MARK 0xbeef
#define REDUNDANT_VERSION 0x01
#define REDUNDANT_HDRLEN 0x0c
#define REDUNDANT_PUSH 0x02
#define REDUNDANT_ACK 0x04
#define ACK_BIT 8
struct net_node_setting
{
int32_t server_type;
int32_t disable_fifo;
};
typedef struct _TTYINFO
{
char mpt_name[40]; /* Master pseudo TTY name */
char ip_addr_s[40]; /* print format of IP address */
struct redund_struct redund;
char redundant_ip_addr_s[40]; /* print format of IP address for redundant_mode */
int redundant_mode;
u_char ip6_addr[16]; /* Server IP address */
int af; /*IP type*/
char scope_id[10];
int reconn_flag; /*1:reconnect 0:not reconnect*/
int32_t server_type;
int32_t disable_fifo;
int tcp_port; /* Server TCP port for data */
int cmd_port; /* Server TCP port for cmd */
int local_tcp_port; /* Client TCP port for data */
int local_cmd_port; /* Client TCP port for cmd */
int mpt_fd; /* Master pseudo tty file handle*/
int sock_fd; /* TCP Socket handle */
int sock_cmd_fd; /* TCP Socket handlefor cmd */
int state; /* TCP connection state */
char * mpt_bufptr; /* Master pseudo TTY data buffer*/
int mpt_datakeep;
int mpt_dataofs;
char * sock_bufptr; /* TCP socket data buffer */
int sock_datakeep;
int sock_dataofs;
char mpt_cmdbuf[CMD_BUFFER_SIZE];/* TTY cmd buffer*/
int mpt_cmdkeep;
char sock_cmdbuf[CMD_BUFFER_SIZE];/* TCP cmd buffer */
int sock_cmdkeep;
int error_flags;
time_t time_out; /* Using for TCP connection check */
int serv_index;
char tcp_wait_id;
time_t tty_used_timestamp;
time_t first_servertime;
int sameflag;
#ifdef SSL_ON
SSL * pssl;
int ssl_enable;
time_t ssl_time;
#endif
int pipe_port[2];
char ttyname[160];
char ttyname2[160];
char curname[160];
int alive_check_cnt;
}
TTYINFO;
typedef struct _ConnMsg
{
TTYINFO * infop;
int status;
char tcp_wait_id;
int connect[2];
int8_t session;
}
ConnMsg;
typedef struct _SERVERINFO
{
u_char ip6_addr[16];
int af;
u_short dev_type;
u_short serial_no;
time_t last_servertime;
time_t next_sendtime;
//Below is for DSCI protocol.
uint32_t ap_id;
u_short hw_id;
unsigned char mac[6];
u_short dsci_ver;
u_short start_item;
}
SERVINFO;
typedef struct _DSCI_HEADER
{
unsigned char opcode;
unsigned char result;
u_short length;
uint32_t id;
}
DSCI_HEADER;
typedef struct _DSCI_RET_HEADER
{
uint32_t ap_id;
u_short hw_id;
unsigned char mac[6];
}
DSCI_RET_HEADER;
typedef struct _DSCI_DA_DATA
{
uint32_t ap_id;
u_short hw_id;
unsigned char mac[6];
}
DSCI_DA_DATA;
typedef struct _DSCI_NET_STAT
{
uint32_t remote_ip;
uint32_t local_ip;
u_short remote_port;
u_short local_port;
char sock_type;
unsigned char status;
unsigned char reverse[2];
}
DSCI_NET_STAT;
typedef struct _DSCI_NET_STAT_IPV6
{
u_char remote_ip[16];
u_char local_ip[16];
u_short remote_port;
u_short local_port;
char sock_type;
unsigned char status;
unsigned char reverse[2];
}
DSCI_NET_STAT_IPV6;
typedef struct _EX_HEADER
{
u_char ex_vision;
char reservd[3];
u_short catalog;
u_short subcode;
}EX_HEADER;
union sock_addr
{
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
};
#define STATE_INIT 0
#define STATE_MPT_OPEN 1
#define STATE_CONN_FAIL 2
#define STATE_TCP_OPEN 3
#define STATE_TCP_CONN 4
#ifdef SSL_ON
#define STATE_SSL_CONN 5
#define STATE_TCP_CLOSE 6
#define STATE_TCP_WAIT 7
#define STATE_MPT_REOPEN 8
#define STATE_TTY_WAIT 9
#define STATE_RW_DATA 10
#define STATE_REMOTE_LISTEN 11
#else
#define STATE_TCP_CLOSE 5
#define STATE_TCP_WAIT 6
#define STATE_MPT_REOPEN 7
#define STATE_TTY_WAIT 8
#define STATE_RW_DATA 9
#define STATE_REMOTE_LISTEN 10
#endif
#define CONNECT_OK 0
#define CONNECT_FAIL 1
#define CLOSE_OK 2
#define TCP_LISTEN 1
#define TCP_CONNECTED 4
#define ERROR_MPT_OPEN 0x0001
#define ERROR_TCP_OPEN 0x0002
#define ERROR_TCP_CONN 0x0004
#define ERROR_FORK 0x0008
#define BUFFER_SIZE 1024 /* temporary data buffer size */
#define MAX_TTYS 256 /* max. handling TTYs number */
#define MAX_PORTS 16 /* max. port of server is 16 */
#define IS_IPV4 0
#define IS_IPV6 1
#ifdef OFFLINE_POLLING
#define POLLING_ALIVE_TIME 30
#endif
#endif /* _NPREAL2D_H */