wdenk | 68ceb29 | 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 | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 25 | #include <command.h> |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 26 | #include <stdio_dev.h> |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 27 | #include <net.h> |
| 28 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 31 | static char input_buffer[512]; |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 32 | static int input_size; /* char count in input buffer */ |
| 33 | static int input_offset; /* offset to valid chars in input buffer */ |
| 34 | static int input_recursion; |
| 35 | static int output_recursion; |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 36 | static int net_timeout; |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 37 | static uchar nc_ether[6]; /* server enet address */ |
| 38 | static IPaddr_t nc_ip; /* server ip */ |
Joe Hershberger | 7f51898 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 39 | static short nc_out_port; /* target output port */ |
| 40 | static short nc_in_port; /* source input port */ |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 41 | static const char *output_packet; /* used by first send udp */ |
| 42 | static int output_packet_len; |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 43 | |
Luca Ceresoli | 03eb129 | 2011-04-18 06:19:50 +0000 | [diff] [blame] | 44 | static void nc_wait_arp_handler(uchar *pkt, unsigned dest, |
| 45 | IPaddr_t sip, unsigned src, |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 46 | unsigned len) |
| 47 | { |
Joe Hershberger | 22f6e99 | 2012-05-23 07:59:14 +0000 | [diff] [blame] | 48 | net_set_state(NETLOOP_SUCCESS); /* got arp reply - quit net loop */ |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 49 | } |
| 50 | |
Luca Ceresoli | 03eb129 | 2011-04-18 06:19:50 +0000 | [diff] [blame] | 51 | static void nc_handler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 52 | unsigned len) |
| 53 | { |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 54 | if (input_size) |
Joe Hershberger | 22f6e99 | 2012-05-23 07:59:14 +0000 | [diff] [blame] | 55 | net_set_state(NETLOOP_SUCCESS); /* got input - quit net loop */ |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 58 | static void nc_timeout(void) |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 59 | { |
Joe Hershberger | 22f6e99 | 2012-05-23 07:59:14 +0000 | [diff] [blame] | 60 | net_set_state(NETLOOP_SUCCESS); |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 63 | void NcStart(void) |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 64 | { |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 65 | if (!output_packet_len || memcmp(nc_ether, NetEtherNullAddr, 6)) { |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 66 | /* going to check for input packet */ |
Joe Hershberger | ece223b | 2012-05-23 07:59:15 +0000 | [diff] [blame] | 67 | net_set_udp_handler(nc_handler); |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 68 | NetSetTimeout(net_timeout, nc_timeout); |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 69 | } else { |
| 70 | /* send arp request */ |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 71 | uchar *pkt; |
Joe Hershberger | ece223b | 2012-05-23 07:59:15 +0000 | [diff] [blame] | 72 | net_set_arp_handler(nc_wait_arp_handler); |
Joe Hershberger | 594c26f | 2012-05-23 07:58:04 +0000 | [diff] [blame] | 73 | pkt = (uchar *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE; |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 74 | memcpy(pkt, output_packet, output_packet_len); |
Joe Hershberger | 7f51898 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 75 | NetSendUDPPacket(nc_ether, nc_ip, nc_out_port, nc_in_port, |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 76 | output_packet_len); |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 80 | int nc_input_packet(uchar *pkt, unsigned dest, unsigned src, unsigned len) |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 81 | { |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 82 | int end, chunk; |
| 83 | |
Joe Hershberger | 7f51898 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 84 | if (dest != nc_in_port || !len) |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 85 | return 0; /* not for us */ |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 86 | |
Joe Hershberger | 4ef8d53 | 2012-05-23 08:01:04 +0000 | [diff] [blame] | 87 | debug_cond(DEBUG_DEV_PKT, "input: \"%*.*s\"\n", len, len, pkt); |
| 88 | |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 89 | if (input_size == sizeof(input_buffer)) |
| 90 | return 1; /* no space */ |
| 91 | if (len > sizeof(input_buffer) - input_size) |
| 92 | len = sizeof(input_buffer) - input_size; |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 93 | |
| 94 | end = input_offset + input_size; |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 95 | if (end > sizeof(input_buffer)) |
| 96 | end -= sizeof(input_buffer); |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 97 | |
| 98 | chunk = len; |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 99 | if (end + len > sizeof(input_buffer)) { |
| 100 | chunk = sizeof(input_buffer) - end; |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 101 | memcpy(input_buffer, pkt + chunk, len - chunk); |
| 102 | } |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 103 | memcpy(input_buffer + end, pkt, chunk); |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 104 | |
| 105 | input_size += len; |
| 106 | |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 107 | return 1; |
| 108 | } |
| 109 | |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 110 | static void nc_send_packet(const char *buf, int len) |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 111 | { |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 112 | struct eth_device *eth; |
| 113 | int inited = 0; |
| 114 | uchar *pkt; |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 115 | uchar *ether; |
| 116 | IPaddr_t ip; |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 117 | |
Joe Hershberger | 4ef8d53 | 2012-05-23 08:01:04 +0000 | [diff] [blame] | 118 | debug_cond(DEBUG_DEV_PKT, "output: \"%*.*s\"\n", len, len, buf); |
| 119 | |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 120 | eth = eth_get_dev(); |
| 121 | if (eth == NULL) |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 122 | return; |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 123 | |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 124 | if (!memcmp(nc_ether, NetEtherNullAddr, 6)) { |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 125 | if (eth->state == ETH_STATE_ACTIVE) |
| 126 | return; /* inside net loop */ |
| 127 | output_packet = buf; |
| 128 | output_packet_len = len; |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 129 | NetLoop(NETCONS); /* wait for arp reply and send packet */ |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 130 | output_packet_len = 0; |
| 131 | return; |
| 132 | } |
| 133 | |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 134 | if (eth->state != ETH_STATE_ACTIVE) { |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 135 | if (eth_init(gd->bd) < 0) |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 136 | return; |
| 137 | inited = 1; |
| 138 | } |
Joe Hershberger | 594c26f | 2012-05-23 07:58:04 +0000 | [diff] [blame] | 139 | pkt = (uchar *)NetTxPacket + NetEthHdrSize() + IP_UDP_HDR_SIZE; |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 140 | memcpy(pkt, buf, len); |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 141 | ether = nc_ether; |
| 142 | ip = nc_ip; |
Joe Hershberger | 7f51898 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 143 | NetSendUDPPacket(ether, ip, nc_out_port, nc_in_port, len); |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 144 | |
| 145 | if (inited) |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 146 | eth_halt(); |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 147 | } |
| 148 | |
Mike Frysinger | fa2744d | 2009-12-21 14:19:12 -0500 | [diff] [blame] | 149 | static int nc_start(void) |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 150 | { |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 151 | int netmask, our_ip; |
Joe Hershberger | 7f51898 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 152 | char *p; |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 153 | |
Joe Hershberger | 7f51898 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 154 | nc_out_port = 6666; /* default port */ |
| 155 | nc_in_port = nc_out_port; |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 156 | |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 157 | if (getenv("ncip")) { |
wdenk | b2323ea | 2005-04-20 09:28:54 +0000 | [diff] [blame] | 158 | |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 159 | nc_ip = getenv_IPaddr("ncip"); |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 160 | if (!nc_ip) |
| 161 | return -1; /* ncip is 0.0.0.0 */ |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 162 | p = strchr(getenv("ncip"), ':'); |
Joe Hershberger | 7f51898 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 163 | if (p != NULL) { |
| 164 | nc_out_port = simple_strtoul(p + 1, NULL, 10); |
| 165 | nc_in_port = nc_out_port; |
| 166 | } |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 167 | } else |
Joe Hershberger | 7f51898 | 2012-07-31 06:06:41 +0000 | [diff] [blame] | 168 | nc_ip = ~0; /* ncip is not set, so broadcast */ |
| 169 | |
| 170 | p = getenv("ncoutport"); |
| 171 | if (p != NULL) |
| 172 | nc_out_port = simple_strtoul(p, NULL, 10); |
| 173 | p = getenv("ncinport"); |
| 174 | if (p != NULL) |
| 175 | nc_in_port = simple_strtoul(p, NULL, 10); |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 176 | |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 177 | our_ip = getenv_IPaddr("ipaddr"); |
| 178 | netmask = getenv_IPaddr("netmask"); |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 179 | |
| 180 | if (nc_ip == ~0 || /* 255.255.255.255 */ |
| 181 | ((netmask & our_ip) == (netmask & nc_ip) && /* on the same net */ |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 182 | (netmask | nc_ip) == ~0)) /* broadcast to our net */ |
| 183 | memset(nc_ether, 0xff, sizeof(nc_ether)); |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 184 | else |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 185 | memset(nc_ether, 0, sizeof(nc_ether)); /* force arp request */ |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 186 | |
Joe Hershberger | d7310c7 | 2012-05-23 07:59:23 +0000 | [diff] [blame] | 187 | /* |
| 188 | * Initialize the static IP settings and buffer pointers |
| 189 | * incase we call NetSendUDPPacket before NetLoop |
| 190 | */ |
| 191 | net_init(); |
| 192 | |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 193 | return 0; |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Mike Frysinger | fa2744d | 2009-12-21 14:19:12 -0500 | [diff] [blame] | 196 | static void nc_putc(char c) |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 197 | { |
| 198 | if (output_recursion) |
| 199 | return; |
| 200 | output_recursion = 1; |
| 201 | |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 202 | nc_send_packet(&c, 1); |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 203 | |
| 204 | output_recursion = 0; |
| 205 | } |
| 206 | |
Mike Frysinger | fa2744d | 2009-12-21 14:19:12 -0500 | [diff] [blame] | 207 | static void nc_puts(const char *s) |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 208 | { |
wdenk | b2323ea | 2005-04-20 09:28:54 +0000 | [diff] [blame] | 209 | int len; |
| 210 | |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 211 | if (output_recursion) |
| 212 | return; |
| 213 | output_recursion = 1; |
| 214 | |
Michael Walle | 1a9845b | 2011-10-07 12:27:50 +0000 | [diff] [blame] | 215 | len = strlen(s); |
| 216 | while (len) { |
| 217 | int send_len = min(len, 512); |
| 218 | nc_send_packet(s, send_len); |
| 219 | len -= send_len; |
| 220 | s += send_len; |
| 221 | } |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 222 | |
| 223 | output_recursion = 0; |
| 224 | } |
| 225 | |
Mike Frysinger | fa2744d | 2009-12-21 14:19:12 -0500 | [diff] [blame] | 226 | static int nc_getc(void) |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 227 | { |
wdenk | b2323ea | 2005-04-20 09:28:54 +0000 | [diff] [blame] | 228 | uchar c; |
| 229 | |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 230 | input_recursion = 1; |
| 231 | |
| 232 | net_timeout = 0; /* no timeout */ |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 233 | while (!input_size) |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 234 | NetLoop(NETCONS); |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 235 | |
| 236 | input_recursion = 0; |
| 237 | |
wdenk | b2323ea | 2005-04-20 09:28:54 +0000 | [diff] [blame] | 238 | c = input_buffer[input_offset++]; |
| 239 | |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 240 | if (input_offset >= sizeof(input_buffer)) |
| 241 | input_offset -= sizeof(input_buffer); |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 242 | input_size--; |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 243 | |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 244 | return c; |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Mike Frysinger | fa2744d | 2009-12-21 14:19:12 -0500 | [diff] [blame] | 247 | static int nc_tstc(void) |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 248 | { |
| 249 | struct eth_device *eth; |
| 250 | |
| 251 | if (input_recursion) |
| 252 | return 0; |
| 253 | |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 254 | if (input_size) |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 255 | return 1; |
| 256 | |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 257 | eth = eth_get_dev(); |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 258 | if (eth && eth->state == ETH_STATE_ACTIVE) |
| 259 | return 0; /* inside net loop */ |
| 260 | |
| 261 | input_recursion = 1; |
| 262 | |
| 263 | net_timeout = 1; |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 264 | NetLoop(NETCONS); /* kind of poll */ |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 265 | |
| 266 | input_recursion = 0; |
| 267 | |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 268 | return input_size != 0; |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 271 | int drv_nc_init(void) |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 272 | { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 273 | struct stdio_dev dev; |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 274 | int rc; |
| 275 | |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 276 | memset(&dev, 0, sizeof(dev)); |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 277 | |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 278 | strcpy(dev.name, "nc"); |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 279 | dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM; |
| 280 | dev.start = nc_start; |
| 281 | dev.putc = nc_putc; |
| 282 | dev.puts = nc_puts; |
| 283 | dev.getc = nc_getc; |
| 284 | dev.tstc = nc_tstc; |
| 285 | |
Joe Hershberger | e1902ac | 2012-05-15 08:59:13 +0000 | [diff] [blame] | 286 | rc = stdio_register(&dev); |
wdenk | 68ceb29 | 2004-08-02 21:11:11 +0000 | [diff] [blame] | 287 | |
| 288 | return (rc == 0) ? 1 : rc; |
| 289 | } |