This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RedBoot - ARP improvements


When using a static IP address, this will broadcast that 
address to the network to check for duplicates.

Has the side effect of fixing a hardware issue on the Motorola 
MPC850 (A&M Adder) that won't receive any packets on the ethernet 
until one has been sent.  This caused the board to be silent when 
using a fixed IP address - you couldn't talk to it until it talked 
on the network :-(

-- 
Gary Thomas <gary@mlbassoc.com>
MLB Associates
Index: redboot/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/ChangeLog,v
retrieving revision 1.117
diff -u -5 -p -r1.117 ChangeLog
--- redboot/current/ChangeLog	15 Jul 2003 01:51:38 -0000	1.117
+++ redboot/current/ChangeLog	15 Jul 2003 16:20:44 -0000
@@ -1,5 +1,15 @@
+2003-07-15  Gary Thomas  <gary@mlbassoc.com>
+
+	* include/net/net.h: 
+	* src/net/arp.c (__arp_request): Allow ARP of self - used during
+	initialization to "broadcast" that an IP address is in use.
+
+	* src/net/net_io.c (net_init): When using a static IP, send an
+	initial ARP to see if any other node is using this address.
+	Also, some minor cosmetic cleanups to remove warnings.
+
 2003-07-15  Jonathan Larmour  <jifl@eCosCentric.com>
 
 	* doc/redboot_installing.sgml (AT91): Tell users to switch JP1
 	(or SW1 for EB40) when installing, and warn them in no
 	uncertain terms the consequences of failing to do so.
Index: redboot/current/include/net/net.h
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/include/net/net.h,v
retrieving revision 1.16
diff -u -5 -p -r1.16 net.h
--- redboot/current/include/net/net.h	20 Mar 2003 15:44:40 -0000	1.16
+++ redboot/current/include/net/net.h	15 Jul 2003 16:16:32 -0000
@@ -7,11 +7,11 @@
 //==========================================================================
 //####ECOSGPLCOPYRIGHTBEGIN####
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
-// Copyright (C) 2002 Gary Thomas
+// Copyright (C) 2002, 2003 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
 // Software Foundation; either version 2 or (at your option) any later version.
 //
@@ -431,11 +431,11 @@ extern void __arp_handler(pktbuf_t *pkt)
  * Find the ethernet address of the machine with the given
  * ip address.
  * Return true and fills in 'eth_addr' if successful, false
  * if unsuccessful.
  */
-extern int __arp_request(ip_addr_t *ip_addr, enet_addr_t *eth_addr);
+extern int __arp_request(ip_addr_t *ip_addr, enet_addr_t *eth_addr, int allow_self);
 
 /*
  * Lookup an address from the local ARP cache.  If not found,
  * then call 'arp_request' to find it.  [Basically just a cached
  * version of 'arp_request']
Index: redboot/current/src/net/arp.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/net/arp.c,v
retrieving revision 1.6
diff -u -5 -p -r1.6 arp.c
--- redboot/current/src/net/arp.c	9 Jul 2002 20:23:48 -0000	1.6
+++ redboot/current/src/net/arp.c	15 Jul 2003 16:19:04 -0000
@@ -7,11 +7,11 @@
 //==========================================================================
 //####ECOSGPLCOPYRIGHTBEGIN####
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
-// Copyright (C) 2002 Gary Thomas
+// Copyright (C) 2002, 2003 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
 // Software Foundation; either version 2 or (at your option) any later version.
 //
@@ -111,22 +111,24 @@ __arp_handler(pktbuf_t *pkt)
  * ip address.
  * Return 0 and fills in 'eth_addr' if successful,
  *       -1 if unsuccessful.
  */
 int
-__arp_request(ip_addr_t *ip_addr, enet_addr_t *eth_addr)
+__arp_request(ip_addr_t *ip_addr, enet_addr_t *eth_addr, int allow_self)
 {
     pktbuf_t *pkt;
     arp_header_t *arp;
     unsigned long retry_start;
     enet_addr_t   bcast_addr;
     int           retry;
 
-    // Special case request for self
-    if (!memcmp(ip_addr, __local_ip_addr, 4)) {
-        memcpy(eth_addr, __local_enet_addr, sizeof(enet_addr_t));
-        return 0;
+    if (!allow_self) {
+        // Special case request for self
+        if (!memcmp(ip_addr, __local_ip_addr, 4)) {
+            memcpy(eth_addr, __local_enet_addr, sizeof(enet_addr_t));
+            return 0;
+        }
     }
 
     /* just fail if can't get a buffer */
     if ((pkt = __pktbuf_alloc(ARP_PKT_SIZE)) == NULL)
 	return -1;
@@ -197,11 +199,11 @@ __arp_lookup(ip_addr_t *host, ip_route_t
     } else if (!__ip_addr_local(host)) {
         // non-local IP address -- look up Gateway's Ethernet address
         host = &__local_ip_gate;
 #endif
     }
-    if (__arp_request(host, &rt->enet_addr) < 0) {
+    if (__arp_request(host, &rt->enet_addr, 0) < 0) {
         return -1;
     } else {
         memcpy(&routes[next_arp], rt, sizeof(*rt));
         if (++next_arp == NUM_ARP) next_arp = 0;
         return 0;
Index: redboot/current/src/net/net_io.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/net/net_io.c,v
retrieving revision 1.33
diff -u -5 -p -r1.33 net_io.c
--- redboot/current/src/net/net_io.c	26 Jun 2003 05:29:45 -0000	1.33
+++ redboot/current/src/net/net_io.c	15 Jul 2003 16:17:03 -0000
@@ -7,11 +7,11 @@
 //==========================================================================
 //####ECOSGPLCOPYRIGHTBEGIN####
 // -------------------------------------------
 // This file is part of eCos, the Embedded Configurable Operating System.
 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
-// Copyright (C) 2002 Gary Thomas
+// Copyright (C) 2002, 2003 Gary Thomas
 //
 // eCos is free software; you can redistribute it and/or modify it under
 // the terms of the GNU General Public License as published by the Free
 // Software Foundation; either version 2 or (at your option) any later version.
 //
@@ -677,12 +677,11 @@ net_init(void)
     flash_get_config("net_device", &default_devname, CONFIG_NETPORT);
 #endif
     flash_get_config("net_debug", &net_debug, CONFIG_BOOL);
     flash_get_config("gdb_port", &gdb_port, CONFIG_INT);
     flash_get_config("bootp", &use_bootp, CONFIG_BOOL);
-    if (!use_bootp)
-    {
+    if (!use_bootp) {
         flash_get_IP("bootp_my_ip", &__local_ip_addr);
 #ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
         flash_get_IP("bootp_my_ip_mask", &__local_ip_mask);
         flash_get_IP("bootp_my_gateway_ip", &__local_ip_gate);
 #endif
@@ -715,11 +714,11 @@ net_init(void)
 	if (t->init(t))
             t->status = CYG_NETDEVTAB_STATUS_AVAIL;
 	else
 #endif
 	{
-	    for (index = 0; t = net_devtab_entry(index); index++) {
+	    for (index = 0; (t = net_devtab_entry(index)) != NULL; index++) {
 #if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
 		if (index == default_index)
 		    continue;
 #endif
 		if (t->init(t)) {
@@ -759,11 +758,16 @@ net_init(void)
                 diag_printf("Can't get BOOTP info, using default IP address\n");
                 have_net = true;
             }
         }
     } else {
+        enet_addr_t enet_addr;
         have_net = true;  // Assume values in FLASH were OK
+        // Tell the world that we are using this fixed IP address
+        if (__arp_request((ip_addr_t *)__local_ip_addr, &enet_addr, 1) >= 0) {
+            diag_printf("Warning: IP address %s in use\n", inet_ntoa((in_addr_t *)&__local_ip_addr));
+        }
     }
     if (have_net) {
         diag_printf("Ethernet %s: MAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
                     __local_enet_sc->dev_name,
                     __local_enet_addr[0],
@@ -823,11 +827,12 @@ do_ip_addr(int argc, char *argv[])
         if( (slash_pos = strchr(ip_addr, '/')) ) {
             int mask_len;
             unsigned long mask;
             *slash_pos = '\0';
             slash_pos++;
-            if( !parse_num(slash_pos, &mask_len, 0, 0) ||  mask_len <= 0 || mask_len > 32 ) {
+            if( !parse_num(slash_pos, (unsigned long *)&mask_len, 0, 0) ||  
+                mask_len <= 0 || mask_len > 32 ) {
                 diag_printf("Invalid mask length: %s\n", slash_pos);
                 return;
             }
             mask = htonl((0xffffffff << (32-mask_len))&0xffffffff);
             memcpy(&__local_ip_mask, &mask, 4);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]