static void shell_network(char *str) { char *pos = str + sizeof("network"); uint8_t is_error = 0; char dstr[DSTR_BUF]; if (strncmp_P(pos, PSTR("set "), 4) == 0) { pos += 4; if (strncmp_P(pos, PSTR("ip "), 3) == 0) { pos += 3; is_error = net_conf_set_ip_string(pos); } else if (strncmp_P(pos, PSTR("gw "), 3) == 0) { pos += 3; is_error = net_conf_set_gw_string(pos); } else if (strncmp_P(pos, PSTR("nm "), 3) == 0) { pos += 3; is_error = net_conf_set_nm_string(pos); } else if (strncmp_P(pos, PSTR("dhcp "), 5) == 0) { pos += 5; is_error = net_conf_set_dhcpc_string(pos); } else { shell_output("unknown set operation: ", pos); } } else if (strncmp_P(pos, PSTR("show"), 4) == 0) { pos += 5; net_conf_get_mac_string(dstr, DSTR_BUF); shell_output("MAC: ", dstr); net_conf_get_ip_string(dstr, DSTR_BUF); shell_output("IP: ", dstr); net_conf_get_nm_string(dstr, DSTR_BUF); shell_output("NM: ", dstr); net_conf_get_gw_string(dstr, DSTR_BUF); shell_output("GW: ", dstr); } else if (strncmp_P(pos, PSTR("load"), 4) == 0) { net_conf_load(); } else if (strncmp_P(pos, PSTR("save"), 4) == 0) { net_conf_save(); } else { shell_output_P(PSTR("options: show, set, load, save"),PSTR("")); } }
int net_conf_init(void) { uip_ipaddr_t ipaddr; if (!init_load_done) net_conf_load(); init_load_done = 1; //net_conf_enable_dhcp=0; if ((net_conf_enable_dhcp != 1) && (net_conf_enable_dhcp != 0)) { // if the setting is invalid, enable by default #if UIP_CONF_BROADCAST == 1 net_conf_enable_dhcp = 1; #else net_conf_enable_dhcp = 0; #endif // update the eeprom with the correct data net_conf_save(); } // if the mac address in eeprom looks bad, use the defaults if ((net_conf_eth_addr[0] == 0xff) || ( (net_conf_eth_addr[0] == 0x00) && (net_conf_eth_addr[1] == 0x00) && (net_conf_eth_addr[2] == 0x00) && (net_conf_eth_addr[3] == 0x00) && (net_conf_eth_addr[4] == 0x00) && (net_conf_eth_addr[5] == 0x00))) { net_conf_eth_addr[0] = UIP_ETHADDR0; net_conf_eth_addr[1] = UIP_ETHADDR1; net_conf_eth_addr[2] = UIP_ETHADDR2; net_conf_eth_addr[3] = UIP_ETHADDR3; net_conf_eth_addr[4] = UIP_ETHADDR4; net_conf_eth_addr[5] = UIP_ETHADDR5; net_conf_mac_save(); } my_eth_addr.addr[0] = net_conf_eth_addr[0]; my_eth_addr.addr[1] = net_conf_eth_addr[1]; my_eth_addr.addr[2] = net_conf_eth_addr[2]; my_eth_addr.addr[3] = net_conf_eth_addr[3]; my_eth_addr.addr[4] = net_conf_eth_addr[4]; my_eth_addr.addr[5] = net_conf_eth_addr[5]; uip_setethaddr(my_eth_addr); if (!net_conf_enable_dhcp) { // if the IP looks good in flash, use it if ((net_conf_ip_addr[0] != 255) && (net_conf_ip_addr[0] != 0)) net_conf_uip_set(); else { // ip in flash didn't look good... use default uip_ipaddr(ipaddr, UIP_IPADDR0, UIP_IPADDR1, UIP_IPADDR2, UIP_IPADDR3); uip_sethostaddr(ipaddr); net_conf_ip_addr[0] = UIP_IPADDR0; net_conf_ip_addr[1] = UIP_IPADDR1; net_conf_ip_addr[2] = UIP_IPADDR2; net_conf_ip_addr[3] = UIP_IPADDR3; uip_ipaddr(ipaddr, UIP_DRIPADDR0, UIP_DRIPADDR1, UIP_DRIPADDR2, UIP_DRIPADDR3); uip_setdraddr(ipaddr); net_conf_gateway[0] = UIP_DRIPADDR0; net_conf_gateway[1] = UIP_DRIPADDR1; net_conf_gateway[2] = UIP_DRIPADDR2; net_conf_gateway[3] = UIP_DRIPADDR3; uip_ipaddr(ipaddr, UIP_NETMASK0, UIP_NETMASK1, UIP_NETMASK2, UIP_NETMASK3); uip_setnetmask(ipaddr); net_conf_net_mask[0] = UIP_NETMASK0; net_conf_net_mask[1] = UIP_NETMASK1; net_conf_net_mask[2] = UIP_NETMASK2; net_conf_net_mask[3] = UIP_NETMASK3; // update the eeprom with the correct data net_conf_save(); } } return 0; }