1 /*
2     OW -- One-Wire filesystem
3     version 0.4 7/2/2003
4 
5     Written 2003 Paul H Alfille
6         Fuse code based on "fusexmp" {GPL} by Miklos Szeredi, mszeredi@inf.bme.hu
7         Serial code based on "xt" {GPL} by David Querbach, www.realtime.bc.ca
8         in turn based on "miniterm" by Sven Goldt, goldt@math.tu.berlin.de
9     GPL license
10     This program is free software; you can redistribute it and/or
11     modify it under the terms of the GNU General Public License
12     as published by the Free Software Foundation; either version 2
13     of the License, or (at your option) any later version.
14 
15     This program is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18     GNU General Public License for more details.
19 
20  */
21 
22 #ifndef OW_PORT_IN_H			/* tedious wrapper */
23 #define OW_PORT_IN_H
24 
25 /* struct connection_in (for each bus master) as part of ow_connection.h */
26 
27 //enum server_type { srv_unknown, srv_direct, srv_client, src_
28 /* Network connection structure */
29 enum bus_mode {
30 	bus_unknown = 0,
31 	bus_serial,
32 	bus_xport,
33 	bus_passive,
34 	bus_usb,
35 	bus_usb_monitor,
36 	bus_enet_monitor,
37 	bus_masterhub_monitor,
38 	bus_parallel,
39 	bus_server,
40 	bus_zero,
41 	bus_browse,
42 	bus_i2c,
43 	bus_ha7net,
44 	bus_ha5,
45 	bus_ha7e,
46 	bus_enet,
47 	bus_fake,
48 	bus_tester,
49 	bus_mock,
50 	bus_link,
51 	bus_masterhub,
52 	bus_pbm,
53 	bus_etherweather,
54 	bus_bad,
55 	bus_w1,
56 	bus_w1_monitor,
57 	bus_xport_control,
58 	bus_external,
59 	bus_ds1wm,
60 	bus_k1wm,
61 };
62 
63 enum com_state {
64 	cs_virgin,
65 	cs_deflowered,
66 } ;
67 
68 enum com_type {
69 	ct_unknown,
70 	ct_serial,
71 	ct_telnet,
72 	ct_tcp,
73 	ct_i2c,
74 	ct_usb,
75 	ct_netlink,
76 	ct_ftdi,
77 	ct_none,
78 } ;
79 
80 struct com_serial {
81 	struct termios oldSerialTio;    /*old serial port settings */
82 } ;
83 
84 struct com_tcp {
85 	char *host;
86 	char *service;
87 	struct addrinfo *ai;
88 	struct addrinfo *ai_ok;
89 	enum { needs_negotiation, completed_negotiation, } telnet_negotiated ; // have we attempted telnet negotiation -- reset at each OPEN
90 	int telnet_supported ; // server does telnet settings
91 } ;
92 
93 // For forward references
94 struct connection_in;
95 struct port_in ;
96 
97 struct port_in {
98 	struct port_in * next ;
99 	struct connection_in *first;
100 	int connections ;
101 	enum bus_mode busmode;
102 	char * init_data ;
103 
104 	union {
105 		struct com_serial serial ;
106 		struct com_tcp tcp ;
107 		struct com_tcp telnet ;
108 	} dev ;
109 	FILE_DESCRIPTOR_OR_PERSISTENT file_descriptor;
110 	enum com_state state ;
111 	enum com_type type ;
112 	enum { flow_none, flow_soft, flow_hard, } flow ;
113 	speed_t baud; // baud rate in the form of B9600
114 	int bits;
115 	enum { parity_none, parity_odd, parity_even, parity_mark, } parity ;
116 	enum { stop_1, stop_2, stop_15, } stop;
117 	cc_t vmin ;
118 	cc_t vtime ;
119 	struct timeval timeout ; // for serial or tcp read
120 
121 	pthread_mutex_t port_mutex;
122 };
123 
124 /* This bug-fix/workaround function seem to be fixed now... At least on
125  * the platforms I have tested it on... printf() in owserver/src/c/owserver.c
126  * returned very strange result on c->busmode before... but not anymore */
127 enum bus_mode get_busmode(const struct connection_in *c);
128 
129 void RemovePort( struct port_in * pin ) ;
130 struct port_in * AllocPort( const struct port_in * old_pin ) ;
131 struct port_in *LinkPort(struct port_in *pin) ;
132 struct port_in *NewPort(const struct port_in *pin) ;
133 struct connection_in * AddtoPort( struct port_in * pin ) ;
134 
135 #endif							/* OW_PORT_IN_H */
136