]> git.kernelconcepts.de Git - karo-tx-redboot.git/blobdiff - packages/redboot/v2_0/src/net/net_io.c
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / redboot / v2_0 / src / net / net_io.c
index d87c4bdbbfca9d4dc77ce38dc5a43f18148f607d..2430ac0773a21e0b4b49148dc2b37722e409e60c 100644 (file)
@@ -170,8 +170,10 @@ static void net_io_putc(void*, cyg_uint8);
 // Special characters used by Telnet - must be interpretted here
 #define TELNET_IAC    0xFF // Interpret as command (escape)
 #define TELNET_IP     0xF4 // Interrupt process
-#define TELNET_WONT   0xFC // I Won't do it
+#define TELNET_WILL   0xFB // I Will do XXX
+#define TELNET_WONT   0xFC // I Won't do XXX
 #define TELNET_DO     0xFD // Will you XXX
+#define TELNET_DONT   0xFE // Don't you XXX
 #define TELNET_TM     0x06 // Time marker (special DO/WONT after IP)
 
 static cyg_bool
@@ -248,6 +250,14 @@ net_io_getc_nonblock(void* __ch_data, cyg_uint8* ch)
         net_io_putc(__ch_data, TELNET_WONT);
         net_io_putc(__ch_data, esc);
         return false;  // Ignore this whole thing!
+    case TELNET_WILL:
+        // Telnet WILL option
+        while (!_net_io_getc_nonblock(__ch_data, &esc)) ;                
+        // Respond with DONT option
+        net_io_putc(__ch_data, TELNET_IAC);
+        net_io_putc(__ch_data, TELNET_DONT);
+        net_io_putc(__ch_data, esc);
+        return false;  // Ignore this whole thing!
     default:
         return false;
     }
@@ -584,7 +594,7 @@ RedBoot_idle(net_io_test, RedBoot_IDLE_NETIO);
 CYG_HAL_TABLE_BEGIN( __NETDEVTAB__, netdev );
 CYG_HAL_TABLE_END( __NETDEVTAB_END__, netdev );
 
-RedBoot_init(net_init, RedBoot_INIT_LAST);
+RedBoot_init(net_init, RedBoot_INIT_NET);
 
 static void
 show_addrs(void)
@@ -673,7 +683,7 @@ net_init(void)
     unsigned index;
     struct eth_drv_sc *primary_net = (struct eth_drv_sc *)0;
 #if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
-    char *default_devname;
+    char *default_devname = CYGDAT_REDBOOT_DEFAULT_NETWORK_DEVICE;
     int default_index;
 #endif
 #ifdef CYGDAT_REDBOOT_DEFAULT_BOOTP_SERVER_IP_ADDR
@@ -730,7 +740,7 @@ net_init(void)
        primary_net = __local_enet_sc;
     } else
 #endif
-#endif
+#endif // (CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
     for (index = 0; (t = net_devtab_entry(index)) != NULL; index++) {
 #ifdef CYGSEM_REDBOOT_NETWORK_INIT_ONE_DEVICE
        if (index == default_index)
@@ -742,9 +752,13 @@ net_init(void)
                 primary_net = __local_enet_sc;
             }
 #if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
+#   ifdef CYGSEM_REDBOOT_NETWORK_INIT_ONE_DEVICE
+            break;
+#   else
             if (index == default_index) {
                 primary_net = __local_enet_sc;
             }
+#   endif // CYGSEM_REDBOOT_NETWORK_INIT_ONE_DEVICE
 #endif
         }
     }
@@ -779,7 +793,8 @@ net_init(void)
             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));
+                diag_printf("Warning: IP address %s in use\n",
+                           inet_ntoa((in_addr_t *)&__local_ip_addr));
             }
         }
     }
@@ -803,7 +818,10 @@ net_init(void)
 
 static char usage[] = "[-b] [-l <local_ip_address>[/<mask_len>]] [-h <server_address>]"
 #ifdef CYGPKG_REDBOOT_NETWORKING_DNS
-       " [-d <dns_server_address]"
+       " [-d <dns_server_address>]"
+#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_FCONFIG_DOMAIN                                                  
+        " [-D <dns_domain_name>]" 
+#endif
 #endif
         ;
 
@@ -818,7 +836,7 @@ RedBoot_cmd("ip_address",
 void 
 do_ip_addr(int argc, char *argv[])
 {
-    struct option_info opts[4];
+    struct option_info opts[5];
     char *ip_addr, *host_addr;
     bool ip_addr_set, host_addr_set;
     bool do_bootp = false;
@@ -826,13 +844,25 @@ do_ip_addr(int argc, char *argv[])
 #ifdef CYGPKG_REDBOOT_NETWORKING_DNS
     char *dns_addr;
     bool dns_addr_set;
+#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_FCONFIG_DOMAIN 
+    char *dns_domain;
+    bool dns_domain_set;
+#endif
 #endif
     int num_opts;
+    if (!have_net) {
+       net_init();
+    }
+    if (!have_net) {
+        diag_printf("Sorry, networking is not available.\n");
+        return;
+    }
 
     init_opts(&opts[0], 'l', true, OPTION_ARG_TYPE_STR, 
-              (void *)&ip_addr, (bool *)&ip_addr_set, "local IP address");
+              &ip_addr, &ip_addr_set, "local IP address");
     init_opts(&opts[1], 'h', true, OPTION_ARG_TYPE_STR, 
-              (void *)&host_addr, (bool *)&host_addr_set, "default server address");
+              &host_addr, &host_addr_set, "default server address");
     init_opts(&opts[2], 'b', false, OPTION_ARG_TYPE_FLG,
               &do_bootp, 0, "use BOOTP");
     num_opts = 3;
@@ -840,8 +870,12 @@ do_ip_addr(int argc, char *argv[])
     init_opts(&opts[num_opts], 'd', true, OPTION_ARG_TYPE_STR, 
               (void *)&dns_addr, (bool *)&dns_addr_set, "DNS server address");
     num_opts++;
+#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_FCONFIG_DOMAIN 
+    init_opts(&opts[num_opts], 'D', true, OPTION_ARG_TYPE_STR, 
+              (void *)&dns_domain, (bool *)&dns_domain_set, "DNS domain");
+    num_opts++;
+#endif
 #endif
-
     CYG_ASSERT(num_opts <= NUM_ELEMS(opts), "Too many options");
 
     if (!scan_opts(argc, argv, 1, opts, num_opts, 0, 0, "")) {
@@ -857,11 +891,11 @@ do_ip_addr(int argc, char *argv[])
         char *slash_pos;
         /* see if the (optional) mask length was given */
         if( (slash_pos = strchr(ip_addr, '/')) ) {
-           unsigned long mask_len;
+            unsigned long mask_len;
             unsigned long mask;
             *slash_pos = '\0';
             slash_pos++;
-            if (!parse_num(slash_pos, &mask_len, 0, 0) ||
+            if( !parse_num(slash_pos, &mask_len, 0, 0) ||  
                 mask_len <= 0 || mask_len > 32 ) {
                 diag_printf("Invalid mask length: %s\n", slash_pos);
                 return;
@@ -888,6 +922,11 @@ do_ip_addr(int argc, char *argv[])
     if (dns_addr_set) {
         set_dns(dns_addr);
     }
+#ifdef CYGPKG_REDBOOT_NETWORKING_DNS_FCONFIG_DOMAIN 
+    if (dns_domain_set) {
+      setdomainname(dns_domain, strlen(dns_domain));
+    }
+#endif
 #endif
     show_addrs();
     if (!have_net) {