wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2004 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 25 | #include <command.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 26 | #include <stdio_dev.h> |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 27 | #include <net.h> |
| 28 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
Joe Hershberger | 45f4a23 | 2012-07-31 06:09:17 +0000 | [diff] [blame^] | 31 | #ifndef CONFIG_NETCONSOLE_BUFFER_SIZE |
| 32 | #define CONFIG_NETCONSOLE_BUFFER_SIZE 512 |
| 33 | #endif |
| 34 | |
| 35 | static char input_buffer[CONFIG_NETCONSOLE_BUFFER_SIZE]; |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 36 | static int input_size; /* char count in input buffer */ |
| 37 | static int input_offset; /* offset to valid chars in input buffer */ |
| 38 | static int input_recursion; |
| 39 | static int output_recursion; |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 40 | static int net_timeout; |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 41 | static uchar nc_ether[6]; /* server enet address */ |
| 42 | static IPaddr_t nc_ip; /* server ip */ |
Joe Hershberger | d0f5396 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 43 | static short nc_out_port; /* target output port */ |
| 44 | static short nc_in_port; /* source input port */ |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 45 | static const char *output_packet; /* used by first send udp */ |
| 46 | static int output_packet_len; |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 47 | |
Luca Ceresoli | 428ab36 | 2011-04-18 06:19:50 +0000 | [diff] [blame] | 48 | static void nc_wait_arp_handler(uchar *pkt, unsigned dest, |
| 49 | IPaddr_t sip, unsigned src, |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 50 | unsigned len) |
| 51 | { |
Joe Hershberger | d4bb76a | 2012-05-23 07:59:14 +0000 | [diff] [blame] | 52 | net_set_state(NETLOOP_SUCCESS); /* got arp reply - quit net loop */ |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Luca Ceresoli | 428ab36 | 2011-04-18 06:19:50 +0000 | [diff] [blame] | 55 | static void nc_handler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 56 | unsigned len) |
| 57 | { |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 58 | if (input_size) |
Joe Hershberger | d4bb76a | 2012-05-23 07:59:14 +0000 | [diff] [blame] | 59 | net_set_state(NETLOOP_SUCCESS); /* got input - quit net loop */ |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 62 | static void nc_timeout(void) |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 63 | { |
Joe Hershberger | d4bb76a | 2012-05-23 07:59:14 +0000 | [diff] [blame] | 64 | net_set_state(NETLOOP_SUCCESS); |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 67 | void NcStart(void) |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 68 | { |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 69 | if (!output_packet_len || memcmp(nc_ether, NetEtherNullAddr, 6)) { |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 70 | /* going to check for input packet */ |
Joe Hershberger | f50357b | 2012-05-23 07:59:15 +0000 | [diff] [blame] | 71 | net_set_udp_handler(nc_handler); |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 72 | NetSetTimeout(net_timeout, nc_timeout); |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 73 | } else { |
| 74 | /* send arp request */ |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 75 | uchar *pkt; |
Joe Hershberger | f50357b | 2012-05-23 07:59:15 +0000 | [diff] [blame] | 76 | net_set_arp_handler(nc_wait_arp_handler); |
Joe Hershberger | 6fe8b45 | 2012-05-23 07:58:04 +0000 | [diff] [blame] | 77 | pkt = (uchar *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE; |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 78 | memcpy(pkt, output_packet, output_packet_len); |
Joe Hershberger | d0f5396 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 79 | NetSendUDPPacket(nc_ether, nc_ip, nc_out_port, nc_in_port, |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 80 | output_packet_len); |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 84 | int nc_input_packet(uchar *pkt, unsigned dest, unsigned src, unsigned len) |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 85 | { |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 86 | int end, chunk; |
| 87 | |
Joe Hershberger | d0f5396 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 88 | if (dest != nc_in_port || !len) |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 89 | return 0; /* not for us */ |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 90 | |
Joe Hershberger | 05a377b | 2012-05-23 08:01:04 +0000 | [diff] [blame] | 91 | debug_cond(DEBUG_DEV_PKT, "input: \"%*.*s\"\n", len, len, pkt); |
| 92 | |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 93 | if (input_size == sizeof(input_buffer)) |
| 94 | return 1; /* no space */ |
| 95 | if (len > sizeof(input_buffer) - input_size) |
| 96 | len = sizeof(input_buffer) - input_size; |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 97 | |
| 98 | end = input_offset + input_size; |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 99 | if (end > sizeof(input_buffer)) |
| 100 | end -= sizeof(input_buffer); |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 101 | |
| 102 | chunk = len; |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 103 | if (end + len > sizeof(input_buffer)) { |
| 104 | chunk = sizeof(input_buffer) - end; |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 105 | memcpy(input_buffer, pkt + chunk, len - chunk); |
| 106 | } |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 107 | memcpy(input_buffer + end, pkt, chunk); |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 108 | |
| 109 | input_size += len; |
| 110 | |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 111 | return 1; |
| 112 | } |
| 113 | |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 114 | static void nc_send_packet(const char *buf, int len) |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 115 | { |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 116 | struct eth_device *eth; |
| 117 | int inited = 0; |
| 118 | uchar *pkt; |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 119 | uchar *ether; |
| 120 | IPaddr_t ip; |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 121 | |
Joe Hershberger | 05a377b | 2012-05-23 08:01:04 +0000 | [diff] [blame] | 122 | debug_cond(DEBUG_DEV_PKT, "output: \"%*.*s\"\n", len, len, buf); |
| 123 | |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 124 | eth = eth_get_dev(); |
| 125 | if (eth == NULL) |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 126 | return; |
| 127 | |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 128 | if (!memcmp(nc_ether, NetEtherNullAddr, 6)) { |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 129 | if (eth->state == ETH_STATE_ACTIVE) |
| 130 | return; /* inside net loop */ |
| 131 | output_packet = buf; |
| 132 | output_packet_len = len; |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 133 | NetLoop(NETCONS); /* wait for arp reply and send packet */ |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 134 | output_packet_len = 0; |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 135 | return; |
| 136 | } |
| 137 | |
| 138 | if (eth->state != ETH_STATE_ACTIVE) { |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 139 | if (eth_init(gd->bd) < 0) |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 140 | return; |
| 141 | inited = 1; |
| 142 | } |
Joe Hershberger | 6fe8b45 | 2012-05-23 07:58:04 +0000 | [diff] [blame] | 143 | pkt = (uchar *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE; |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 144 | memcpy(pkt, buf, len); |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 145 | ether = nc_ether; |
| 146 | ip = nc_ip; |
Joe Hershberger | d0f5396 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 147 | NetSendUDPPacket(ether, ip, nc_out_port, nc_in_port, len); |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 148 | |
| 149 | if (inited) |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 150 | eth_halt(); |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Mike Frysinger | 31da77e | 2009-12-21 14:19:12 -0500 | [diff] [blame] | 153 | static int nc_start(void) |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 154 | { |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 155 | int netmask, our_ip; |
Joe Hershberger | d0f5396 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 156 | char *p; |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 157 | |
Joe Hershberger | d0f5396 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 158 | nc_out_port = 6666; /* default port */ |
| 159 | nc_in_port = nc_out_port; |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 160 | |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 161 | if (getenv("ncip")) { |
wdenk | b21608e | 2005-04-20 09:28:54 +0000 | [diff] [blame] | 162 | |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 163 | nc_ip = getenv_IPaddr("ncip"); |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 164 | if (!nc_ip) |
| 165 | return -1; /* ncip is 0.0.0.0 */ |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 166 | p = strchr(getenv("ncip"), ':'); |
Joe Hershberger | d0f5396 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 167 | if (p != NULL) { |
| 168 | nc_out_port = simple_strtoul(p + 1, NULL, 10); |
| 169 | nc_in_port = nc_out_port; |
| 170 | } |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 171 | } else |
Joe Hershberger | d0f5396 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 172 | nc_ip = ~0; /* ncip is not set, so broadcast */ |
| 173 | |
| 174 | p = getenv("ncoutport"); |
| 175 | if (p != NULL) |
| 176 | nc_out_port = simple_strtoul(p, NULL, 10); |
| 177 | p = getenv("ncinport"); |
| 178 | if (p != NULL) |
| 179 | nc_in_port = simple_strtoul(p, NULL, 10); |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 180 | |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 181 | our_ip = getenv_IPaddr("ipaddr"); |
| 182 | netmask = getenv_IPaddr("netmask"); |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 183 | |
| 184 | if (nc_ip == ~0 || /* 255.255.255.255 */ |
| 185 | ((netmask & our_ip) == (netmask & nc_ip) && /* on the same net */ |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 186 | (netmask | nc_ip) == ~0)) /* broadcast to our net */ |
| 187 | memset(nc_ether, 0xff, sizeof(nc_ether)); |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 188 | else |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 189 | memset(nc_ether, 0, sizeof(nc_ether)); /* force arp request */ |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 190 | |
Joe Hershberger | 6a9ed16 | 2012-05-23 07:59:23 +0000 | [diff] [blame] | 191 | /* |
| 192 | * Initialize the static IP settings and buffer pointers |
| 193 | * incase we call NetSendUDPPacket before NetLoop |
| 194 | */ |
| 195 | net_init(); |
| 196 | |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 197 | return 0; |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Mike Frysinger | 31da77e | 2009-12-21 14:19:12 -0500 | [diff] [blame] | 200 | static void nc_putc(char c) |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 201 | { |
| 202 | if (output_recursion) |
| 203 | return; |
| 204 | output_recursion = 1; |
| 205 | |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 206 | nc_send_packet(&c, 1); |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 207 | |
| 208 | output_recursion = 0; |
| 209 | } |
| 210 | |
Mike Frysinger | 31da77e | 2009-12-21 14:19:12 -0500 | [diff] [blame] | 211 | static void nc_puts(const char *s) |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 212 | { |
wdenk | b21608e | 2005-04-20 09:28:54 +0000 | [diff] [blame] | 213 | int len; |
| 214 | |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 215 | if (output_recursion) |
| 216 | return; |
| 217 | output_recursion = 1; |
| 218 | |
Michael Walle | 9227aed | 2011-10-07 12:27:50 +0000 | [diff] [blame] | 219 | len = strlen(s); |
| 220 | while (len) { |
Joe Hershberger | 45f4a23 | 2012-07-31 06:09:17 +0000 | [diff] [blame^] | 221 | int send_len = min(len, sizeof(input_buffer)); |
Michael Walle | 9227aed | 2011-10-07 12:27:50 +0000 | [diff] [blame] | 222 | nc_send_packet(s, send_len); |
| 223 | len -= send_len; |
| 224 | s += send_len; |
| 225 | } |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 226 | |
| 227 | output_recursion = 0; |
| 228 | } |
| 229 | |
Mike Frysinger | 31da77e | 2009-12-21 14:19:12 -0500 | [diff] [blame] | 230 | static int nc_getc(void) |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 231 | { |
wdenk | b21608e | 2005-04-20 09:28:54 +0000 | [diff] [blame] | 232 | uchar c; |
| 233 | |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 234 | input_recursion = 1; |
| 235 | |
| 236 | net_timeout = 0; /* no timeout */ |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 237 | while (!input_size) |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 238 | NetLoop(NETCONS); |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 239 | |
| 240 | input_recursion = 0; |
| 241 | |
wdenk | b21608e | 2005-04-20 09:28:54 +0000 | [diff] [blame] | 242 | c = input_buffer[input_offset++]; |
| 243 | |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 244 | if (input_offset >= sizeof(input_buffer)) |
| 245 | input_offset -= sizeof(input_buffer); |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 246 | input_size--; |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 247 | |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 248 | return c; |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 249 | } |
| 250 | |
Mike Frysinger | 31da77e | 2009-12-21 14:19:12 -0500 | [diff] [blame] | 251 | static int nc_tstc(void) |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 252 | { |
| 253 | struct eth_device *eth; |
| 254 | |
| 255 | if (input_recursion) |
| 256 | return 0; |
| 257 | |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 258 | if (input_size) |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 259 | return 1; |
| 260 | |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 261 | eth = eth_get_dev(); |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 262 | if (eth && eth->state == ETH_STATE_ACTIVE) |
| 263 | return 0; /* inside net loop */ |
| 264 | |
| 265 | input_recursion = 1; |
| 266 | |
| 267 | net_timeout = 1; |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 268 | NetLoop(NETCONS); /* kind of poll */ |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 269 | |
| 270 | input_recursion = 0; |
| 271 | |
wdenk | a0ebde5 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 272 | return input_size != 0; |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 275 | int drv_nc_init(void) |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 276 | { |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 277 | struct stdio_dev dev; |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 278 | int rc; |
| 279 | |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 280 | memset(&dev, 0, sizeof(dev)); |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 281 | |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 282 | strcpy(dev.name, "nc"); |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 283 | dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM; |
| 284 | dev.start = nc_start; |
| 285 | dev.putc = nc_putc; |
| 286 | dev.puts = nc_puts; |
| 287 | dev.getc = nc_getc; |
| 288 | dev.tstc = nc_tstc; |
| 289 | |
Joe Hershberger | 107b3d0 | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 290 | rc = stdio_register(&dev); |
wdenk | b8fb619 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 291 | |
| 292 | return (rc == 0) ? 1 : rc; |
| 293 | } |