forked from lkundrak/nets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
88 lines (77 loc) · 1.62 KB
/
common.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
/*
* Serial port over Telnet common definitilns
* Lubomir Rintel <lkundrak@v3.sk>
* License: GPL
*/
#pragma once
enum {
COM_PORT_OPTION = 44,
SE = 240,
NOP = 241,
DATA = 242,
BRK = 243,
IP = 244,
AO = 245,
AYT = 246,
EC = 247,
EL = 248,
GA = 249,
SB = 250,
WILL = 251,
WONT = 252,
DO = 253,
DONT = 254,
IAC = 255,
};
enum com_port_option {
SET_BAUDRATE = 1 ,
SET_DATASIZE = 2 ,
SET_PARITY = 3 ,
SET_STOPSIZE = 4 ,
SET_CONTROL = 5 ,
NOTIFY_LINESTATE = 6 ,
NOTIFY_MODEMSTATE = 7 ,
FLOWCONTROL_SUSPEND = 8 ,
FLOWCONTROL_RESUME = 9 ,
SET_LINESTATE_MASK = 10 ,
SET_MODEMSTATE_MASK = 11 ,
PURGE_DATA = 12 ,
};
enum {
CONTROL_REQ_FLOW = 0,
CONTROL_REQ_BREAK = 4,
CONTROL_REQ_DTR = 7,
CONTROL_REQ_RTS = 10,
CONTROL_REQ_FLOW_IN = 13,
CONTROL_REQ_RESERVED = 20,
};
union com_port_option_value {
struct {
int size;
char *str;
} signature;
int baudrate;
int datasize;
int stopsize;
int parity;
int control;
};
static inline int
control_to_req (int control)
{
if (control < CONTROL_REQ_BREAK)
return CONTROL_REQ_FLOW;
if (control < CONTROL_REQ_DTR)
return CONTROL_REQ_BREAK;
if (control < CONTROL_REQ_RTS)
return CONTROL_REQ_DTR;
if (control < CONTROL_REQ_FLOW_IN)
return CONTROL_REQ_RTS;
if (control < CONTROL_REQ_RESERVED)
return CONTROL_REQ_FLOW_IN;
return CONTROL_REQ_RESERVED;
}
typedef void (com_port_option_callback)(enum com_port_option option, union com_port_option_value *value);
int get_esc (const unsigned char *buf, int size, com_port_option_callback callback);
int get_data (const unsigned char *buf, int size);
int get_socket (const char *host, const char *service);