comparison packages/redboot/current/src/net/net_io.c @ 143:6b5f480c6929 ecos-sw-2000-12-08

Merge from eCos master repository on 2000-12-08-02:09:36-GMT
author jlarmour
date Fri, 08 Dec 2000 03:30:06 +0000
parents 289bf90c6a9b
children 25e238959bae
comparison
equal deleted inserted replaced
142:12eccf9656f3 143:6b5f480c6929
107 static unsigned char *out_bufp; 107 static unsigned char *out_bufp;
108 108
109 // Functions in this module 109 // Functions in this module
110 static void net_io_flush(void); 110 static void net_io_flush(void);
111 static void net_io_revert_console(void); 111 static void net_io_revert_console(void);
112 static void net_io_putc(void*, cyg_uint8);
113
114 // Special characters used by Telnet - must be interpretted here
115 #define TELNET_IAC 0xFF // Interpret as command (escape)
116 #define TELNET_IP 0xF4 // Interrupt process
117 #define TELNET_WONT 0xFC // I Won't do it
118 #define TELNET_DO 0xFD // Will you XXX
119 #define TELNET_TM 0x06 // Time marker (special DO/WONT after IP)
112 120
113 static cyg_bool 121 static cyg_bool
114 net_io_getc_nonblock(void* __ch_data, cyg_uint8* ch) 122 _net_io_getc_nonblock(void* __ch_data, cyg_uint8* ch)
115 { 123 {
116 if (in_buflen == 0) { 124 if (in_buflen == 0) {
117 __tcp_poll(); 125 __tcp_poll();
118 if (tcp_sock.state == _CLOSE_WAIT) { 126 if (tcp_sock.state == _CLOSE_WAIT) {
119 // This connection is breaking 127 // This connection is breaking
142 } 150 }
143 if (in_buflen) { 151 if (in_buflen) {
144 *ch = *in_bufp++; 152 *ch = *in_bufp++;
145 in_buflen--; 153 in_buflen--;
146 return true; 154 return true;
155 } else {
156 return false;
157 }
158 }
159
160 static cyg_bool
161 net_io_getc_nonblock(void* __ch_data, cyg_uint8* ch)
162 {
163 if (_net_io_getc_nonblock(__ch_data, ch)) {
164 if (*ch == TELNET_IAC) {
165 cyg_uint8 esc;
166 // Telnet escape - need to read/handle more
167 while (!_net_io_getc_nonblock(__ch_data, &esc)) ;
168 if (esc == TELNET_IP) {
169 // Special case for ^C == Interrupt Process
170 *ch = 0x03;
171 // Just in case the other end needs synchronizing
172 net_io_putc(__ch_data, TELNET_IAC);
173 net_io_putc(__ch_data, TELNET_WONT);
174 net_io_putc(__ch_data, TELNET_TM);
175 net_io_flush();
176 return true;
177 }
178 if (esc == TELNET_DO) {
179 // Telnet DO option
180 while (!_net_io_getc_nonblock(__ch_data, &esc)) ;
181 // Respond with WONT option
182 net_io_putc(__ch_data, TELNET_IAC);
183 net_io_putc(__ch_data, TELNET_WONT);
184 net_io_putc(__ch_data, esc);
185 return false; // Ignore this whole thing!
186 }
187 }
147 } else { 188 } else {
148 return false; 189 return false;
149 } 190 }
150 } 191 }
151 192