Index: netdemo/Makefile
===================================================================
--- netdemo/Makefile	(revision 78daa9fc051f09a4deaec7ef30fd2b9c8812703c)
+++ netdemo/Makefile	(revision c87143a1734b473b7c7e238660e2071d899bbe75)
@@ -2,8 +2,8 @@
 PGM=${ARCH}/$(SAMPLE).exe
 
-MANAGERS=all
+MANAGERS=io message event semaphore timer rate_monotonic region
 
 # C source names, if any, go here -- minus the .c
-C_PIECES= init  test
+C_PIECES= init test
 C_FILES=$(C_PIECES:%=%.c)
 C_O_FILES=$(C_PIECES:%=${ARCH}/%.o)
@@ -29,9 +29,8 @@
 #
 
-override DEFINES  +=
+DEFINES  +=
 CPPFLAGS +=
 CFLAGS   +=
-CFLAGS_LD += 
-# CFLAGS_LD += -Wl,--defsym -Wl,HeapSize=0xC0000 
+CFLAGS_LD += -Wl,--defsym -Wl,HeapSize=0xC0000	# KA9Q needs more space
 CFLAGS_OPTIMIZE_V   +=
 CFLAGS_DEBUG_V   += -v -qrtems_debug
Index: netdemo/README
===================================================================
--- netdemo/README	(revision 78daa9fc051f09a4deaec7ef30fd2b9c8812703c)
+++ netdemo/README	(revision c87143a1734b473b7c7e238660e2071d899bbe75)
@@ -1,3 +1,3 @@
-A simple application to test some of the RTEMS/FreeBSD networking code.
+A simple application to test some of the KA9Q networking code.
 
     **************************
@@ -5,19 +5,23 @@
     **************************
 
-BE SURE TO LOCALIZE networkconfig.h.  FAILURE TO DO SO MAY PROVOKE YOUR
-NETWORK ADMINISTRATOR TO THE POINT WHERE VICIOUS ATTACKS WILL BE MADE
-UPON YOU.
+1. Make sure you change the definition of MY_ETHERNET_ADDRESS in init.c
+   before you try to use this program.
 
-Once this program is running on the target machine, you can test
-the network code by:
+2. If you do not use BOOTP (i.e. the `#define USE_BOOTP 1' in init.c is
+   removed), make sure you change the definition of MY_INTERNET_ADDRESS
+   before you try to use the program.
 
- Typing commands at the target console:
-    - show network statistics
-    - transmit TCP packets
-    - transmit UDP packets
-    Run `telnet target_machine 24742' on another machines.
- Everything you type should be echoed back and noted on
- the target console.
- You can run more than one telnet session at once.
- You can use port number 24743 as well.
+FAILURE TO FOLLOW THE ABOVE INSTRUCTIONS MAY PROVOKE YOUR NETWORK
+ADMINISTRATOR TO THE POINT WHERE VICIOUS ATTACKS WILL BE MADE UPON YOU.
 
+3. Once this program is running on the target machine, you can test
+   the network code by:
+	a) Typing commands at the target console:
+		s - show network statistics
+		t - transmit TCP packets
+		u - transmit UDP packets
+	b) Run `telnet target_machine 24742' on another machines.
+	   Everything you type should be echoed back and noted on
+	   the target console.
+	   You can run more than one telnet session at once.
+	   You can use port number 24743 as well.
Index: netdemo/init.c
===================================================================
--- netdemo/init.c	(revision 78daa9fc051f09a4deaec7ef30fd2b9c8812703c)
+++ netdemo/init.c	(revision c87143a1734b473b7c7e238660e2071d899bbe75)
@@ -4,6 +4,6 @@
  * This program may be distributed and used for any purpose.
  * I ask only that you:
- *    1. Leave this author information intact.
- *    2. Document any changes you make.
+ *	1. Leave this author information intact.
+ *	2. Document any changes you make.
  *
  * W. Eric Norum
@@ -14,42 +14,21 @@
  */
 
+/*#define TRACE_NETWORK_DRIVER 1 */
 #include <bsp.h>
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <rtems/rtems_bsdnet.h>
-#include "../networkconfig.h"
+#define CONFIGURE_TEST_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_TEST_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
 
-/*
- * RTEMS Startup Task
- */
-rtems_task
-Init (rtems_task_argument ignored)
-{
-  int doSocket(void);
+#define CONFIGURE_EXECUTIVE_RAM_SIZE	(512*1024)
+#define CONFIGURE_MAXIMUM_SEMAPHORES	20
+#define CONFIGURE_MAXIMUM_TASKS		20
+#define CONFIGURE_MAXIMUM_TIMERS	10
+#define CONFIGURE_MAXIMUM_PERIODS	1
 
-  printk( "Initialize network\n" );
-  rtems_bsdnet_initialize_network ();
-  printk( "Network initialized\n" );
-  rtems_bsdnet_show_inet_routes ();
-  printk( "Initiating test\n" );
-  doSocket ();
-  exit (0);
-}
+#define CONFIGURE_MICROSECONDS_PER_TICK	10486
 
-#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
-#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
-#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
-#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 20
-#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
-
-#define CONFIGURE_EXECUTIVE_RAM_SIZE (512*1024)
-#define CONFIGURE_MAXIMUM_SEMAPHORES 20
-#define CONFIGURE_MAXIMUM_TASKS      20
-
-#define CONFIGURE_MICROSECONDS_PER_TICK 10000
-
-#define CONFIGURE_INIT_TASK_STACK_SIZE (10*1024)
-#define CONFIGURE_INIT_TASK_PRIORITY   120
+#define CONFIGURE_INIT_TASK_STACK_SIZE	(10*1024)
+#define CONFIGURE_INIT_TASK_PRIORITY	100
 #define CONFIGURE_INIT_TASK_INITIAL_MODES (RTEMS_PREEMPT | \
                                            RTEMS_NO_TIMESLICE | \
@@ -60,4 +39,147 @@
 rtems_task Init (rtems_task_argument argument);
 
-#include <rtems/confdefs.h>
+#include <confdefs.h>
 
+#include <stdio.h>
+#include <rtems_ka9q.h>
+
+/*
+ * Board ethernet address
+ * REPLACE THIS WITH YOUR OWN VALUE BEFORE TRYING TO USE THIS PROGRAM!
+ */
+#define MY_ETHERNET_ADDRESS "37:1D:3E:21:2B:A5"
+
+/*
+ * Some board support packages let the network driver
+ * get the Ethernet address from the bootstrap PROM.
+ */
+#define MY_ETHERNET_ADDRESS "prom"
+
+/*
+ * Use BOOTP to get information about me?
+ */
+#define USE_BOOTP	1
+
+#if (defined (USE_BOOTP))
+#include <bootp.h>
+#else
+/*
+ * Information about me if BOOTP isn't used
+ * CHOOSE A VALUE APPROPRIATE TO YOUR NETWORK!
+ */
+#define MY_IP_ADDRESS	"128.233.14.68"
+#endif
+
+/*
+ * Suspend execution for the specified number of seconds
+ */
+static void
+delay_task (int seconds)
+{
+	rtems_interval ticksPerSecond;
+
+	rtems_clock_get (RTEMS_CLOCK_GET_TICKS_PER_SECOND, &ticksPerSecond);
+	rtems_task_wake_after (seconds * ticksPerSecond);
+}
+
+/*
+ * RTEMS Startup Task
+ */
+rtems_task
+Init (rtems_task_argument ignored)
+{
+	printf( "\n\n*** HELLO WORLD TEST ***\n" );
+	printf( "Hello World\n" );
+	printf( "*** END OF HELLO WORLD TEST ***\n" );
+
+	/*
+	 * Start KA9Q
+	 */
+	rtems_ka9q_start (50);
+
+	/*
+	 * Hook up drivers
+	 */
+#if (defined (USE_BOOTP))
+	if (rtems_ka9q_execute_command ("attach rtems broadcast y"
+					" ether " MY_ETHERNET_ADDRESS))
+#else
+	if (rtems_ka9q_execute_command ("attach rtems broadcast y"
+					" ip " MY_IP_ADDRESS
+					" ether " MY_ETHERNET_ADDRESS))
+#endif
+		rtems_panic ("Can't attach Ethernet driver.\n");
+
+#if (defined (TRACE_NETWORK_DRIVER))
+	/*
+	 * Turn on debugging
+	 */
+	if (rtems_ka9q_execute_command ("trace rtems input <stdout>")
+	 || rtems_ka9q_execute_command ("trace rtems output <stdout>")
+	 || rtems_ka9q_execute_command ("trace rtems ascii <stdout>"))
+		rtems_panic ("Can't set tracing for Ethernet driver.\n");
+#endif
+
+	/*
+	 * Configure the driver
+	 */
+	if (rtems_ka9q_execute_command ("ifconfig rtems broadcast 255.255.255.255"))
+		rtems_panic ("Can't configure Ethernet driver.\n");
+
+	/*
+	 * Add the ethernet broadcast address to the ARP table.
+	 */
+	if (rtems_ka9q_execute_command ("arp add 255.255.255.255 ether FF:FF:FF:FF:FF:FF"))
+		rtems_panic ("Can't add broadcast entry to ARP table.\n");
+
+#if (defined (USE_BOOTP))
+	{
+	int i;
+	/*
+	 * Get BOOTP information
+	 */
+	for (i = 0 ; ; ) {
+		if (rtems_ka9q_execute_command ("bootp") == 0)
+			break;
+		if (++i == 10)
+			rtems_panic ("Can't get information from BOOTP server.\n");
+		delay_task (i);
+	}
+	if (BootpFileName)
+		printf ("BOOTP filename: `%s'\n", BootpFileName);
+	else
+		printf ("BOOTP -- No filename!\n");
+	}
+#else
+	if (rtems_ka9q_execute_command ("ifconfig rtems netmask 255.255.255.0"))
+		rtems_panic ("Can't set netmask.\n");
+	if (rtems_ka9q_execute_command ("route add default rtems"))
+		rtems_panic ("Can't add default route.\n");
+	printf ("Routing table after adding default route\n");
+	rtems_ka9q_execute_command ("route");
+#endif
+
+	/*
+	 * Issue a gratuitous ARP request to update tables in
+	 * other hosts on this network.
+	 */
+	if (rtems_ka9q_execute_command ("arp gratuitous rtems"))
+		rtems_panic ("Can't send gratuitous ARP.\n");
+	
+	/*
+	 * Everything is now running
+	 */
+	printf ("NETWORK INITIALIZED!\n");
+
+	/*
+	 * See if sockets work properly
+	 */
+	doSocket ();
+
+	/*
+	 * Wind things up
+	 */
+	delay_task (2);
+	rtems_ka9q_execute_command ("detach rtems");
+	exit (0);
+}
Index: netdemo/test.c
===================================================================
--- netdemo/test.c	(revision 78daa9fc051f09a4deaec7ef30fd2b9c8812703c)
+++ netdemo/test.c	(revision c87143a1734b473b7c7e238660e2071d899bbe75)
@@ -1,4 +1,4 @@
 /*
- * Test RTEMS networking
+ * Test KA9Q networking
  *
  * This program may be distributed and used for any purpose.
@@ -13,43 +13,43 @@
  * eric@skatter.usask.ca
  */
-
 #include <stdio.h>
-#include <string.h>
-#include <errno.h>
 #include <unistd.h>
 #include <rtems.h>
-#include <rtems/rtems_bsdnet.h>
 #include <rtems/error.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
+#include <socket.h>
+#include <sockaddr.h>
+#include <netuser.h>
+#include <rtems_ka9q.h>
 
 #define NSERVER		2
 #define BASE_PORT	24742
 
-#define UDP_DATA_SINK_HOST	((10 << 24) | (0 << 16) | (2 << 8) | 255)
-#define TCP_DATA_SINK_HOST	((10 << 24) | (0 << 16) | (2 << 8) | 2)
-
-void showbroad(int s)
-{
-	int opt;
-	socklen_t optlen = sizeof opt;
-
-	if (getsockopt (s, SOL_SOCKET, SO_BROADCAST, &opt, &optlen) < 0)
-		printf ("getsockopt failed: %s\n", strerror (errno));
-	printf ("Opt:%d    Optlen:%ld\n", opt, (long)optlen);
-}
-
-static
-void
-showStatistics (void)
-{
-	rtems_bsdnet_show_inet_routes ();
-	rtems_bsdnet_show_mbuf_stats ();
-	rtems_bsdnet_show_if_stats ();
-	rtems_bsdnet_show_ip_stats ();
-	rtems_bsdnet_show_icmp_stats ();
-	rtems_bsdnet_show_udp_stats ();
-	rtems_bsdnet_show_tcp_stats ();
+#define DATA_SINK_HOST	"128.233.14.1"
+
+/*
+ * Display the contents of several KA9Q tables
+ */
+static void
+show_ka9q_tables (void)
+{
+	printf ("\n****************** MALLOC Statistics ***************\n");
+	malloc_dump ();
+	printf ("\n****************** MBUF Statistics ***************\n");
+	mbufstat ();
+	mbufsizes ();
+	printf ("\n****************** Routing Table ***************\n");
+	rtems_ka9q_execute_command ("route");
+	printf ("\n****************** ARP Table ***************\n");
+	rtems_ka9q_execute_command ("arp");
+	printf ("\n****************** Driver Statistics ***************\n");
+	rtems_ka9q_execute_command ("ifconfig rtems");
+	printf ("\n****************** Ip Statistics ***************\n");
+	rtems_ka9q_execute_command ("ip status");
+	printf ("\n****************** ICMP Statistics ***************\n");
+	rtems_ka9q_execute_command ("icmp status");
+	printf ("\n****************** UDP Statistics ***************\n");
+	rtems_ka9q_execute_command ("udp status");
+	printf ("\n****************** TCP Statistics ***************\n");
+	rtems_ka9q_execute_command ("tcp status");
 }
 
@@ -62,8 +62,7 @@
 	int s;
 	int i;
-	int opt;
 	static struct sockaddr_in myAddr, farAddr;
 	static char cbuf[800];
-	static char bigbuf[9000];
+	static char bigbuf[20000];
 
 	printf ("Create socket.\n");
@@ -72,28 +71,17 @@
 		rtems_panic ("Can't create socket: %s", strerror (errno));
 	myAddr.sin_family = AF_INET;
-	myAddr.sin_port = htons (1234);
-	myAddr.sin_addr.s_addr = htonl (INADDR_ANY);
+	myAddr.sin_port = 1234;
+	myAddr.sin_addr.s_addr = INADDR_ANY;
 	printf ("Bind socket.\n");
 	if (bind (s, (struct sockaddr *)&myAddr, sizeof myAddr) < 0)
 		rtems_panic ("Can't bind socket: %s", strerror (errno));
 	farAddr.sin_family = AF_INET;
-	farAddr.sin_port = htons (9);	/* The `discard' port */
-#if 1
-	farAddr.sin_addr.s_addr = htonl (0xFFFFFFFF);
-	if (sendto (s, cbuf, sizeof cbuf, 0, (struct sockaddr *)&farAddr, sizeof farAddr) >= 0)
-		printf ("Broadcast succeeded, but should not have!\n");
-showbroad (s);
-	opt = 1;
-	if (setsockopt (s, SOL_SOCKET, SO_BROADCAST, &opt, sizeof opt) < 0)
-		rtems_panic ("Can't set socket broadcast: %s", strerror (errno));
-showbroad (s);
-	farAddr.sin_addr.s_addr = htonl (UDP_DATA_SINK_HOST);
+	farAddr.sin_port = 9;	/* The `discard' port */
+	farAddr.sin_addr.s_addr = 0xFFFFFFFF;
 	for (i = 0 ; i < 5 ; i++) {
 		if (sendto (s, cbuf, sizeof cbuf, 0, (struct sockaddr *)&farAddr, sizeof farAddr) < 0)
 			rtems_panic ("Can't broadcast: %s", strerror (errno));
 	}
-#endif
-	farAddr.sin_addr.s_addr = htonl (UDP_DATA_SINK_HOST);
-#if 1
+	farAddr.sin_addr.s_addr = aton (DATA_SINK_HOST);
 	for (i = 0 ; i < 500 ; i++) {
 		if (sendto (s, cbuf, sizeof cbuf, 0, (struct sockaddr *)&farAddr, sizeof farAddr) < 0)
@@ -102,6 +90,4 @@
 			rtems_panic ("Can't send: %s", strerror (errno));
 	}
-#endif
-#if 1
 	for (i = 0 ; i < 2 ; i++) {
 		if (sendto (s, bigbuf, sizeof bigbuf, 0, (struct sockaddr *)&farAddr, sizeof farAddr) < 0)
@@ -110,5 +96,4 @@
 			rtems_panic ("Can't send: %s", strerror (errno));
 	}
-#endif
 	close (s);
 }
@@ -131,13 +116,12 @@
 		rtems_panic ("Can't create socket: %s", strerror (errno));
 	myAddr.sin_family = AF_INET;
-	myAddr.sin_port = htons (1234);
-	myAddr.sin_addr.s_addr = htonl (INADDR_ANY);
+	myAddr.sin_port = 1234;
+	myAddr.sin_addr.s_addr = INADDR_ANY;
 	printf ("Bind socket.\n");
 	if (bind (s, (struct sockaddr *)&myAddr, sizeof myAddr) < 0)
 		rtems_panic ("Can't bind socket: %s", strerror (errno));
 	farAddr.sin_family = AF_INET;
-	farAddr.sin_port = htons (9);	/* The `discard' port */
-	farAddr.sin_addr.s_addr = htonl (TCP_DATA_SINK_HOST);
-	printf ("Connect socket.\n");
+	farAddr.sin_port = 9;	/* The `discard' port */
+	farAddr.sin_addr.s_addr = aton (DATA_SINK_HOST);
 	if (connect (s, (struct sockaddr *)&farAddr, sizeof farAddr) < 0) {
 		printf ("Can't connect socket: %s\n", strerror (errno));
@@ -145,5 +129,4 @@
 		return;
 	}
-	printf ("Write to socket.\n");
 	for (i = 0 ; i < 500 ; i++) {
 		if (write (s, cbuf, sizeof cbuf) < 0)
@@ -173,5 +156,5 @@
 
 	for (;;) {
-#if 1
+#if 0
 		n = read (fd, cbuf, sizeof cbuf);
 #else
@@ -188,4 +171,6 @@
 		if (send (fd, cbuf, n, 0) < 0)
 			rtems_panic ("Error sending message: %s", strerror (errno));
+		if (cbuf[0] == '\007')
+			show_ka9q_tables ();
 		if (cbuf[0] == 'Q')
 			break;
@@ -202,5 +187,5 @@
 	int s, s1;
 	struct sockaddr_in myAddr, farAddr;
-	socklen_t addrlen;
+	int addrlen;
 	rtems_id tid;
 	rtems_task_priority my_priority;
@@ -213,5 +198,5 @@
 		rtems_panic ("Can't create socket: %s", strerror (errno));
 	myAddr.sin_family = AF_INET;
-	myAddr.sin_port = htons (port);
+	myAddr.sin_port = port;
 	myAddr.sin_addr.s_addr = INADDR_ANY;
 	memset (myAddr.sin_zero, '\0', sizeof myAddr.sin_zero);
@@ -229,5 +214,5 @@
 			rtems_panic ("Can't accept connection: %s", strerror (errno));
 		else
-			printf ("ACCEPTED:%lX\n", ntohl (farAddr.sin_addr.s_addr));
+			printf ("ACCEPTED:%lX\n", farAddr.sin_addr.s_addr);
 
 		/*
@@ -273,5 +258,4 @@
 	rtems_task_priority my_priority;
 
-#if 1
 	/*
 	 * Spawn other servers
@@ -296,5 +280,4 @@
 		}
 	}
-#endif
 
 	/*
@@ -321,7 +304,10 @@
 
 		case 's':
-			showStatistics ();
-			break;
-		}
-	}
-}
+			/*
+			 * Show what's been accomplished
+			 */
+			show_ka9q_tables ();
+			break;
+		}
+	}
+}
