3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
26 #ifdef CONFIG_NETCONSOLE
32 #ifndef CONFIG_NET_MULTI
33 #error define CONFIG_NET_MULTI to use netconsole
36 static uchar nc_buf = 0; /* input buffer */
37 static int input_recursion = 0;
38 static int output_recursion = 0;
39 static int net_timeout;
41 static void nc_wait_arp_handler (uchar * pkt, unsigned dest, unsigned src,
44 NetState = NETLOOP_SUCCESS; /* got arp reply - quit net loop */
47 static void nc_handler (uchar * pkt, unsigned dest, unsigned src,
51 NetState = NETLOOP_SUCCESS; /* got input - quit net loop */
54 static void nc_timeout (void)
56 NetState = NETLOOP_SUCCESS;
61 if (memcmp (NetServerEther, NetEtherNullAddr, 6)) {
62 /* going to check for input packet */
63 NetSetHandler (nc_handler);
64 NetSetTimeout (net_timeout, nc_timeout);
66 /* send arp request */
67 NetSetHandler (nc_wait_arp_handler);
68 NetSendUDPPacket (NetServerEther, NetServerIP, 6665, 6666, 0);
72 int nc_input_packet (uchar * pkt, unsigned dest, unsigned src, unsigned len)
74 if (dest != 6666 || !len)
75 return 0; /* not for us */
81 static void nc_send_packet (const char *buf, int len)
83 DECLARE_GLOBAL_DATA_PTR;
85 struct eth_device *eth;
89 if (!memcmp (NetServerEther, NetEtherNullAddr, 6))
92 if ((eth = eth_get_dev ()) == NULL) {
96 if (eth->state != ETH_STATE_ACTIVE) {
97 if (eth_init (gd->bd) < 0)
101 pkt = (uchar *) NetTxPacket + NetEthHdrSize () + IP_HDR_SIZE;
102 memcpy (pkt, buf, len);
103 NetSendUDPPacket (NetServerEther, NetServerIP, 6666, 6665, len);
111 if (memcmp (NetServerEther, NetEtherNullAddr, 6))
114 return NetLoop (NETCONS); /* wait for arp reply */
117 void nc_putc (char c)
119 if (output_recursion)
121 output_recursion = 1;
123 nc_send_packet (&c, 1);
125 output_recursion = 0;
128 void nc_puts (const char *s)
130 if (output_recursion)
132 output_recursion = 1;
134 int len = strlen (s);
139 nc_send_packet (s, len);
141 output_recursion = 0;
148 net_timeout = 0; /* no timeout */
162 struct eth_device *eth;
170 eth = eth_get_dev ();
171 if (eth && eth->state == ETH_STATE_ACTIVE)
172 return 0; /* inside net loop */
177 NetLoop (NETCONS); /* kind of poll */
184 int drv_nc_init (void)
189 memset (&dev, 0, sizeof (dev));
191 strcpy (dev.name, "nc");
192 dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
193 dev.start = nc_start;
199 rc = device_register (&dev);
201 return (rc == 0) ? 1 : rc;
204 #endif /* CONFIG_NETCONSOLE */