/** Configures the uIP stack ready for network traffic processing. */ void uIPManagement_Init(void) { /* uIP Timing Initialization */ clock_init(); timer_set(&ConnectionTimer, CLOCK_SECOND / 2); timer_set(&ARPTimer, CLOCK_SECOND * 10); /* uIP Stack Initialization */ uip_init(); uip_arp_init(); /* DHCP/Server IP Settings Initialization */ if (USB_CurrentMode == USB_MODE_Device) { MACAddress.addr[0] = SERVER_MAC_ADDRESS[0]; MACAddress.addr[1] = SERVER_MAC_ADDRESS[1]; MACAddress.addr[2] = SERVER_MAC_ADDRESS[2]; MACAddress.addr[3] = SERVER_MAC_ADDRESS[3]; MACAddress.addr[4] = SERVER_MAC_ADDRESS[4]; MACAddress.addr[5] = SERVER_MAC_ADDRESS[5]; #if defined(ENABLE_DHCP_SERVER) DHCPServerApp_Init(); #endif uip_ipaddr_t IPAddress, Netmask, GatewayIPAddress; uip_ipaddr(&IPAddress, DEVICE_IP_ADDRESS[0], DEVICE_IP_ADDRESS[1], DEVICE_IP_ADDRESS[2], DEVICE_IP_ADDRESS[3]); uip_ipaddr(&Netmask, DEVICE_NETMASK[0], DEVICE_NETMASK[1], DEVICE_NETMASK[2], DEVICE_NETMASK[3]); uip_ipaddr(&GatewayIPAddress, DEVICE_GATEWAY[0], DEVICE_GATEWAY[1], DEVICE_GATEWAY[2], DEVICE_GATEWAY[3]); uip_sethostaddr(&IPAddress); uip_setnetmask(&Netmask); uip_setdraddr(&GatewayIPAddress); } else { #if defined(ENABLE_DHCP_CLIENT) DHCPClientApp_Init(); #else uip_ipaddr_t IPAddress, Netmask, GatewayIPAddress; uip_ipaddr(&IPAddress, DEVICE_IP_ADDRESS[0], DEVICE_IP_ADDRESS[1], DEVICE_IP_ADDRESS[2], DEVICE_IP_ADDRESS[3]); uip_ipaddr(&Netmask, DEVICE_NETMASK[0], DEVICE_NETMASK[1], DEVICE_NETMASK[2], DEVICE_NETMASK[3]); uip_ipaddr(&GatewayIPAddress, DEVICE_GATEWAY[0], DEVICE_GATEWAY[1], DEVICE_GATEWAY[2], DEVICE_GATEWAY[3]); uip_sethostaddr(&IPAddress); uip_setnetmask(&Netmask); uip_setdraddr(&GatewayIPAddress); #endif } /* Virtual Webserver Ethernet Address Configuration */ uip_setethaddr(MACAddress); /* HTTP Webserver Initialization */ HTTPServerApp_Init(); /* TELNET Server Initialization */ #if defined(ENABLE_TELNET_SERVER) TELNETServerApp_Init(); #endif }
int _tcpip_init(void) { uip_ipaddr_t ipaddr; timer_set(&periodic_timer, CLOCK_SECOND/2); timer_set(&arp_timer, CLOCK_SECOND * 10); timer_set(&cli_timer, CLOCK_SECOND); mt76xx_dev_init(); uip_init(); //Printf_High("Tcp INIT \n"); #ifdef CONFIG_SOFTAP uip_ipaddr(ipaddr, 192,168,81,1); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 192,168,81,1); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 255,255,255,0); uip_setnetmask(ipaddr); // Printf_High("TcpIP IniT===\n"); uip_gethostaddr(ipaddr); #endif iot_udp_app_init(); iot_tcp_app_init(); #ifndef CONFIG_SOFTAP if (IoTpAd.ComCfg.Use_DHCP!=1) { uip_ipaddr(ipaddr, IoTpAd.ComCfg.STATIC_IP[0],IoTpAd.ComCfg.STATIC_IP[1], IoTpAd.ComCfg.STATIC_IP[2],IoTpAd.ComCfg.STATIC_IP[3]); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr,IoTpAd.ComCfg.SubnetMask_IP[0], IoTpAd.ComCfg.SubnetMask_IP[1], IoTpAd.ComCfg.SubnetMask_IP[2], IoTpAd.ComCfg.SubnetMask_IP[3]); uip_setnetmask(ipaddr); uip_ipaddr(ipaddr, IoTpAd.ComCfg.GateWay_IP[0], IoTpAd.ComCfg.GateWay_IP[1], IoTpAd.ComCfg.GateWay_IP[2], IoTpAd.ComCfg.GateWay_IP[3]); uip_setdraddr(ipaddr); #if CFG_SUPPORT_DNS uip_ipaddr(ipaddr, IoTpAd.ComCfg.DNS_IP[0],IoTpAd.ComCfg.DNS_IP[1], IoTpAd.ComCfg.DNS_IP[2],IoTpAd.ComCfg.DNS_IP[3]); resolv_conf(ipaddr); resolv_query("www.ablecloud.cn"); #endif dhcpc_set_state(STATE_CONFIG_DONE); } #endif cli_fd = -1; return 0; }
void uip_server_init(chanend xtcp[], int num_xtcp, xtcp_ipconfig_t* ipconfig, unsigned char mac_address[6]) { if (ipconfig != NULL) memcpy(&uip_static_ipconfig, ipconfig, sizeof(xtcp_ipconfig_t)); memcpy(&uip_ethaddr, mac_address, 6); uip_init(); #if UIP_IGMP igmp_init(); #endif if (ipconfig != NULL && (*((int*)ipconfig->ipaddr) != 0)) { uip_static_ip = 1; } if (ipconfig == NULL) { uip_ipaddr_t ipaddr; uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_sethostaddr(ipaddr); uip_setdraddr(ipaddr); uip_setnetmask(ipaddr); uip_setsubnetaddr(); } else { uip_sethostaddr(ipconfig->ipaddr); uip_setdraddr(ipconfig->gateway); uip_setnetmask(ipconfig->netmask); uip_setsubnetaddr(); #ifdef XTCP_VERBOSE_DEBUG printstr("Address: ");uip_printip4(uip_hostaddr);printstr("\n"); printstr("Gateway: ");uip_printip4(uip_draddr);printstr("\n"); printstr("Netmask: ");uip_printip4(uip_netmask);printstr("\n"); #endif } { #if UIP_USE_AUTOIP int hwsum = mac_address[0] + mac_address[1] + mac_address[2] + mac_address[3] + mac_address[4] + mac_address[5]; autoip_init(hwsum + (hwsum << 16) + (hwsum << 24)); #endif #if UIP_USE_DHCP dhcpc_init(uip_ethaddr.addr, 6); #endif xtcpd_init(xtcp, num_xtcp); } }
int _tcpip_init(void) { uip_ipaddr_t ipaddr; timer_set(&periodic_timer, CLOCK_SECOND/2); timer_set(&arp_timer, CLOCK_SECOND * 10); timer_set(&cli_timer, CLOCK_SECOND); mt76xx_dev_init(); uip_init(); #ifdef CONFIG_SOFTAP uip_ipaddr(ipaddr, UIP_IPADDR0,UIP_IPADDR1,UIP_IPADDR2,UIP_IPADDR3); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, UIP_IPADDR0,UIP_IPADDR1,UIP_IPADDR2,UIP_IPADDR3); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, UIP_NETMASK0,UIP_NETMASK1,UIP_NETMASK2,UIP_NETMASK3); uip_setnetmask(ipaddr); uip_gethostaddr(ipaddr); #endif iot_udp_app_init(); iot_tcp_app_init(); #ifdef CONFIG_STATION if (IoTpAd.ComCfg.Use_DHCP!=1) { uip_ipaddr(ipaddr, IoTpAd.ComCfg.STATIC_IP[0],IoTpAd.ComCfg.STATIC_IP[1], IoTpAd.ComCfg.STATIC_IP[2],IoTpAd.ComCfg.STATIC_IP[3]); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr,IoTpAd.ComCfg.SubnetMask_IP[0], IoTpAd.ComCfg.SubnetMask_IP[1], IoTpAd.ComCfg.SubnetMask_IP[2], IoTpAd.ComCfg.SubnetMask_IP[3]); uip_setnetmask(ipaddr); uip_ipaddr(ipaddr, IoTpAd.ComCfg.GateWay_IP[0], IoTpAd.ComCfg.GateWay_IP[1], IoTpAd.ComCfg.GateWay_IP[2], IoTpAd.ComCfg.GateWay_IP[3]); uip_setdraddr(ipaddr); #if CFG_SUPPORT_DNS uip_ipaddr(ipaddr, IoTpAd.ComCfg.DNS_IP[0],IoTpAd.ComCfg.DNS_IP[1], IoTpAd.ComCfg.DNS_IP[2],IoTpAd.ComCfg.DNS_IP[3]); resolv_conf(ipaddr); resolv_query("www.baidu.com"); #endif dhcpc_set_state(STATE_CONFIG_DONE); } #endif cli_fd = -1; return 0; }
void uip_linkup() { if (get_uip_xtcp_ifstate()) uip_xtcp_down(); if (uip_static_ip) { #if UIP_CONF_IPV6 uip_ipaddr_t ipaddr; uip_ipaddr(ipaddr, uip_static_ipconfig.ipaddr[0], uip_static_ipconfig.ipaddr[1], uip_static_ipconfig.ipaddr[2], uip_static_ipconfig.ipaddr[3]); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, uip_static_ipconfig.gateway[0], uip_static_ipconfig.gateway[1], uip_static_ipconfig.gateway[2], uip_static_ipconfig.gateway[3]); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, uip_static_ipconfig.netmask[0], uip_static_ipconfig.netmask[1], uip_static_ipconfig.netmask[2], uip_static_ipconfig.netmask[3]); uip_setnetmask(ipaddr); uip_setsubnetaddr(); #else uip_sethostaddr(uip_static_ipconfig.ipaddr); uip_setdraddr(uip_static_ipconfig.gateway); uip_setnetmask(uip_static_ipconfig.netmask); uip_setsubnetaddr(); #endif uip_xtcp_up(); } else { dhcp_done = 0; #if UIP_USE_DHCP dhcpc_stop(); #endif #if UIP_USE_AUTOIP #if UIP_USE_DHCP autoip_stop(); #else autoip_start(); #endif #endif #if UIP_USE_DHCP dhcpc_start(); #endif } }
void dhcpc_configured(const struct dhcpc_state *s) { uip_sethostaddr(s->ipaddr); uip_setnetmask(s->netmask); uip_setdraddr(s->default_router); resolv_conf(s->dnsaddr); }
/** * dhcpc_configured: Global function for uIP DHCPC to use, * notification of DHCP configuration. * \param s Pointer to DHCP state instance */ void dhcpc_configured(const struct dhcpc_state *s) { u8_t *pAddr; printf("\n\r"); printf("=== DHCP Configurations ===\n\r"); pAddr = (u8_t *)s->ipaddr; printf("- IP : %d.%d.%d.%d\n\r", pAddr[0], pAddr[1], pAddr[2], pAddr[3]); pAddr = (u8_t *)s->netmask; printf("- Mask : %d.%d.%d.%d\n\r", pAddr[0], pAddr[1], pAddr[2], pAddr[3]); pAddr = (u8_t *)s->default_router; printf("- GW : %d.%d.%d.%d\n\r", pAddr[0], pAddr[1], pAddr[2], pAddr[3]); pAddr = (u8_t *)s->dnsaddr; printf("- DNS : %d.%d.%d.%d\n\r", pAddr[0], pAddr[1], pAddr[2], pAddr[3]); printf("===========================\n\r\n"); uip_sethostaddr(s->ipaddr); uip_setnetmask(s->netmask); uip_setdraddr(s->default_router); #ifdef __RESOLV_H__ resolv_conf(s->dnsaddr); #else printf("DNS NOT enabled in the demo\n\r"); #endif }
void stack_init(void) { uip_ipaddr_t ipaddr; struct uip_eth_addr mac; mac.addr[0] = mac_addr[0]; mac.addr[1] = mac_addr[1]; mac.addr[2] = mac_addr[2]; mac.addr[3] = mac_addr[3]; mac.addr[4] = mac_addr[4]; mac.addr[5] = mac_addr[5]; timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); timer_set(&self_arp_timer, CLOCK_SECOND * 30); uip_init(); uip_setethaddr(mac); udpapp_init(); tcp_app_init(); uip_ipaddr(ipaddr, local_ip[0], local_ip[1], local_ip[2], local_ip[3]); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, gateway_ip[0],gateway_ip[1],gateway_ip[2],gateway_ip[3]); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, subnet_mask[0],subnet_mask[1],subnet_mask[2],subnet_mask[3]); uip_setnetmask(ipaddr); }
void Network::init(void) { // two timers for tcp/ip timer_set(&periodic_timer, CLOCK_SECOND / 2); /* 0.5s */ timer_set(&arp_timer, CLOCK_SECOND * 10); /* 10s */ // Initialize the uIP TCP/IP stack. uip_init(); uip_setethaddr(mac_address); if (!use_dhcp) { // manual setup of ip uip_ipaddr_t tip; /* local IP address */ uip_ipaddr(tip, ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]); uip_sethostaddr(tip); /* host IP address */ printf("IP Addr: %d.%d.%d.%d\n", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]); uip_ipaddr(tip, ipgw[0], ipgw[1], ipgw[2], ipgw[3]); uip_setdraddr(tip); /* router IP address */ printf("IP GW: %d.%d.%d.%d\n", ipgw[0], ipgw[1], ipgw[2], ipgw[3]); uip_ipaddr(tip, ipmask[0], ipmask[1], ipmask[2], ipmask[3]); uip_setnetmask(tip); /* mask */ printf("IP mask: %d.%d.%d.%d\n", ipmask[0], ipmask[1], ipmask[2], ipmask[3]); setup_servers(); }else{ #if UIP_CONF_UDP dhcpc_init(mac_address, sizeof(mac_address)); dhcpc_request(); printf("Getting IP address....\n"); #endif } }
void setup_usb(void) { uip_ipaddr_t hostaddr, netmask, defrouter; uip_ipaddr(&hostaddr, 10,0,0,2); uip_ipaddr(&netmask, 255,0,0,0); uip_ipaddr(&defrouter, 10,0,0,1); uip_sethostaddr(&hostaddr); uip_setnetmask(&netmask); uip_setdraddr(&defrouter); /* uip_over_mesh_set_net(&hostaddr, &netmask); uip_fw_register(&slipif); uip_over_mesh_set_gateway_netif(&slipif); uip_fw_default(&meshif); uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); */ printf("uIP started with IP address %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr)); #ifdef WITH_USB printf("Setting up USB\n"); usb_setup(); printf("usb setup done\n"); usb_cdc_eth_set_ifaddr(&hostaddr); usb_cdc_eth_setup(); #endif printf("cdc_eth setup done\n"); }
static int dhcp_apply_options(uint8_t tag, uint8_t length, uint8_t *value, void *data) { switch (tag) { case DhcpTagSubnetMask: if (length < 4) { printf("Truncated subnet mask.\n"); return 1; } else { uip_ipaddr_t netmask; uip_ipaddr(&netmask, value[0], value[1], value[2], value[3]); uip_setnetmask(&netmask); return 0; } case DhcpTagDefaultRouter: if (length < 4) { printf("Truncated routers.\n"); return 1; } else { uip_ipaddr_t router; uip_ipaddr(&router, value[0], value[1], value[2], value[3]); uip_setdraddr(&router); return 0; } } return 0; }
/* ----------------------------------------------------------------------------- * When a cable is plugged in, this function is called * ---------------------------------------------------------------------------*/ void uip_linkup() { if (uip_xtcp_get_ifstate()){ uip_xtcp_down(); } #if UIP_CONF_IPV4 if (uip_static_ip) { uip_sethostaddr(&uip_static_ipconfig.ipaddr); uip_setdraddr(&uip_static_ipconfig.gateway); uip_setnetmask(&uip_static_ipconfig.netmask); uip_xtcp_up(); } else { dhcp_done = 0; #if UIP_USE_DHCP dhcpc_stop(); #endif #if UIP_USE_AUTOIP #if UIP_USE_DHCP autoip_stop(); #else autoip_start(); #endif #endif #if UIP_USE_DHCP dhcpc_start(); #endif } #endif /* UIP_CONF_IPVx */ }
/** Configures the uIP stack ready for network traffic processing. */ void uIPManagement_Init(void) { /* uIP Timing Initialization */ clock_init(); timer_set(&ConnectionTimer, CLOCK_SECOND / 2); timer_set(&ARPTimer, CLOCK_SECOND * 10); /* uIP Stack Initialization */ uip_init(); uip_arp_init(); uip_setethaddr(MACAddress); /* DHCP/Server IP Settings Initialization */ #if defined(ENABLE_DHCP_CLIENT) HaveIPConfiguration = false; DHCPClientApp_Init(); #else HaveIPConfiguration = true; uip_ipaddr_t IPAddress, Netmask, GatewayIPAddress; uip_ipaddr(&IPAddress, DEVICE_IP_ADDRESS[0], DEVICE_IP_ADDRESS[1], DEVICE_IP_ADDRESS[2], DEVICE_IP_ADDRESS[3]); uip_ipaddr(&Netmask, DEVICE_NETMASK[0], DEVICE_NETMASK[1], DEVICE_NETMASK[2], DEVICE_NETMASK[3]); uip_ipaddr(&GatewayIPAddress, DEVICE_GATEWAY[0], DEVICE_GATEWAY[1], DEVICE_GATEWAY[2], DEVICE_GATEWAY[3]); uip_sethostaddr(&IPAddress); uip_setnetmask(&Netmask); uip_setdraddr(&GatewayIPAddress); #endif /* HTTP Webserver Initialization */ HTTPServerApp_Init(); /* TELNET Server Initialization */ #if defined(ENABLE_TELNET_SERVER) TELNETServerApp_Init(); #endif }
/*-----------------------------------------------------------------------------------*/ static void apply_tcpipconfig(void) { uip_ipaddr_t addr; nullterminate(ipaddr); if(uiplib_ipaddrconv(ipaddr, &addr)) { uip_sethostaddr(&addr); } nullterminate(netmask); if(uiplib_ipaddrconv(netmask, &addr)) { uip_setnetmask(&addr); } nullterminate(gateway); if(uiplib_ipaddrconv(gateway, &addr)) { uip_setdraddr(&addr); } #if UIP_UDP nullterminate(dnsserver); if(uiplib_ipaddrconv(dnsserver, &addr)) { resolv_conf(&addr); } #endif /* UIP_UDP */ }
static void net_configure(void) { struct in_addr addr; #if defined(CONFIG_EXAMPLE_POLL_NOMAC) uint8_t mac[IFHWADDRLEN]; #endif /* Configure uIP */ /* Many embedded network interfaces must have a software assigned MAC */ #ifdef CONFIG_EXAMPLE_POLL_NOMAC mac[0] = 0x00; mac[1] = 0xe0; mac[2] = 0xb0; mac[3] = 0x0b; mac[4] = 0xba; mac[5] = 0xbe; uip_setmacaddr("eth0", mac); #endif /* Set up our host address */ addr.s_addr = HTONL(CONFIG_EXAMPLE_POLL_IPADDR); uip_sethostaddr("eth0", &addr); /* Set up the default router address */ addr.s_addr = HTONL(CONFIG_EXAMPLE_POLL_DRIPADDR); uip_setdraddr("eth0", &addr); /* Setup the subnet mask */ addr.s_addr = HTONL(CONFIG_EXAMPLE_POLL_NETMASK); uip_setnetmask("eth0", &addr); }
int igmp_main(int argc, char *argv[]) { struct in_addr addr; #if defined(CONFIG_EXAMPLES_IGMP_NOMAC) uint8_t mac[IFHWADDRLEN]; #endif message("Configuring Ethernet...\n"); /* Many embedded network interfaces must have a software assigned MAC */ #ifdef CONFIG_EXAMPLES_IGMP_NOMAC mac[0] = 0x00; mac[1] = 0xe0; mac[2] = 0xde; mac[3] = 0xad; mac[4] = 0xbe; mac[5] = 0xef; uip_setmacaddr("eth0", mac); #endif /* Set up our host address */ addr.s_addr = HTONL(CONFIG_EXAMPLES_IGMP_IPADDR); uip_sethostaddr("eth0", &addr); /* Set up the default router address */ addr.s_addr = HTONL(CONFIG_EXAMPLES_IGMP_DRIPADDR); uip_setdraddr("eth0", &addr); /* Setup the subnet mask */ addr.s_addr = HTONL(CONFIG_EXAMPLES_IGMP_NETMASK); uip_setnetmask("eth0", &addr); /* Not much of a test for now */ /* Join the group */ message("Join group...\n"); addr.s_addr = HTONL(CONFIG_EXAMPLES_IGMP_GRPADDR); ipmsfilter("eth0", &addr, MCAST_INCLUDE); /* Wait a while */ message("Wait for timeout...\n"); sleep(5); /* Leave the group */ message("Leave group...\n"); ipmsfilter("eth0", &addr, MCAST_EXCLUDE); /* Wait a while */ sleep(5); message("Exiting...\n"); return 0; }
//***************************************************************************** // // Callback for when DHCP client has been configured. // //***************************************************************************** void dhcpc_configured(const struct dhcpc_state *s) { uip_sethostaddr(&s->ipaddr); uip_setnetmask(&s->netmask); uip_setdraddr(&s->default_router); ShowIPAddress(s->ipaddr); }
//***************************************************************************** // // Callback for when DHCP client has been configured. // //***************************************************************************** void dhcpc_configured(const struct dhcpc_state *s) { uip_sethostaddr(&s->ipaddr); uip_setnetmask(&s->netmask); uip_setdraddr(&s->default_router); DisplayIPAddress((void *)&s->ipaddr, 18, 24); }
void IP_config(void) { #if UIP_UDP // if DHCP is enabled, then initialize via DHCP, else use static settings if (config.dhcpenable) { dhcpc_init(); } else { uip_sethostaddr(config.ipaddr); uip_setnetmask(config.netmask); uip_setdraddr(config.gateway); } #else // UIP_UDP // configure the interface with static settings uip_sethostaddr(config.ipaddr); uip_setnetmask(config.netmask); uip_setdraddr(config.gateway); #endif // UIP_UDP }
void dhcpc_configured(const struct dhcpc_state *s) { uip_sethostaddr(&s->ipaddr); uip_setnetmask(&s->netmask); uip_setdraddr(&s->default_router); printf("IP: %d.%d.%d.%d\n", s->ipaddr[0] & 0xff, s->ipaddr[0] >> 8, s->ipaddr[1] & 0xff, s->ipaddr[1] >> 8); }
void dhcp_parse_ack(void) { uint8_t got_ack = 0; uint8_t op, len; uint8_t *opt_ptr; struct dhcp_message *message = (struct dhcp_message *)uip_appdata; if(message->op != DHCP_OP_REPLY || message->xid != dhcp_s.xid) { return; } /* Skip magic cookie */ opt_ptr = message->options + 4; do { op = *opt_ptr++; len = *opt_ptr++; switch(op) { case DHCP_OPTION_SUBNETMASK: memcpy(&dhcp_s.subnet_mask, opt_ptr, sizeof(dhcp_s.subnet_mask)); break; case DHCP_OPTION_ROUTER: memcpy(&dhcp_s.gateway_addr, opt_ptr, sizeof(dhcp_s.gateway_addr)); break; case DHCP_OPTION_ADDR_TIME: memcpy(&dhcp_s.lease_time, opt_ptr, sizeof(dhcp_s.lease_time)); dhcp_s.lease_time = ntohl(dhcp_s.lease_time); break; case DHCP_OPTION_MSG_TYPE: if(*opt_ptr == DHCPACK) got_ack = 1; break; } opt_ptr += len; } while(op != DHCP_OPTION_END); if(got_ack) { uip_sethostaddr(&dhcp_s.ip_addr); uip_setnetmask(&dhcp_s.subnet_mask); uip_setdraddr(&dhcp_s.gateway_addr); dhcp_s.dhcp_renew_time = get_clock() + dhcp_s.lease_time * CLOCK_TICKS_PER_SECOND / 2; dhcp_s.state = DHCP_STATE_WAIT_RENEW; } }
static void set_eeprom_addr() { uip_ipaddr_t ipaddr; erip(ipaddr, EE_IP4_ADDR); uip_sethostaddr(ipaddr); erip(ipaddr, EE_IP4_GATEWAY); uip_setdraddr(ipaddr); erip(ipaddr, EE_IP4_NETMASK); uip_setnetmask(ipaddr); ip_initialized(); }
void network_config_load (void) { /* load settings from eeprom */ #ifdef EEPROM_SUPPORT eeprom_restore(mac, uip_ethaddr.addr, 6); #else memcpy_P(uip_ethaddr.addr, PSTR(CONF_ETHERRAPE_MAC), 6); #endif #if defined(BOOTP_SUPPORT) \ || (IPV6_SUPPORT && !defined(IPV6_STATIC_SUPPORT)) \ || DHCP_SUPPORT return; #else uip_ipaddr_t ip; (void) ip; /* Keep GCC quiet. */ /* Configure the IP address. */ #ifdef EEPROM_SUPPORT /* Please Note: ip and &ip are NOT the same (cpp hell) */ eeprom_restore_ip(ip, &ip); #else set_CONF_ETHERRAPE_IP(&ip); #endif uip_sethostaddr(&ip); /* Configure prefix length (IPv6). */ #ifdef IPV6_SUPPORT uip_setprefixlen(CONF_ENC_IP6_PREFIX_LEN); #endif #ifdef IPV4_SUPPORT /* Configure the netmask (IPv4). */ #ifdef EEPROM_SUPPORT /* Please Note: ip and &ip are NOT the same (cpp hell) */ eeprom_restore_ip(netmask, &ip); #else set_CONF_ETHERRAPE_IP4_NETMASK(&ip); #endif uip_setnetmask(&ip); #endif /* IPV4_SUPPORT */ /* Configure the default gateway */ #ifdef EEPROM_SUPPORT /* Please Note: ip and &ip are NOT the same (cpp hell) */ eeprom_restore_ip(gateway, &ip); #else set_CONF_ETHERRAPE_GATEWAY(&ip); #endif uip_setdraddr(&ip); #endif /* No autoconfiguration. */ }
asmlinkage void sys_uip_ip_init_k(unsigned char *hostaddr, unsigned char*draddr, unsigned char* netmask) { uip_ipaddr_t ipaddr; uip_ipaddr(ipaddr, hostaddr[0], hostaddr[1], hostaddr[2], hostaddr[3]); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, draddr[0], draddr[1], draddr[2], draddr[3]); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, netmask[0], netmask[1], netmask[2], netmask[3]); uip_setnetmask(ipaddr); }
void network_config_load (void) { /* load settings from eeprom */ #ifdef EEPROM_SUPPORT eeprom_restore (mac, uip_ethaddr.addr, 6); #else #if defined(BOOTLOADER_SUPPORT) && BOOTLOADER_START_ADDRESS > UINT16_MAX uint_farptr_t src = pgm_get_far_address (conf_mac); uint8_t *dst = uip_ethaddr.addr; for (uint8_t i = 6; i; i--) *dst++ = pgm_read_byte_far (src++); #else memcpy_P (uip_ethaddr.addr, conf_mac, 6); #endif #endif #if (defined(IPV4_SUPPORT) && !defined(BOOTP_SUPPORT) && !defined(DHCP_SUPPORT)) || defined(IPV6_STATIC_SUPPORT) uip_ipaddr_t ip; /* Configure the IP address. */ #ifdef EEPROM_SUPPORT /* Please Note: ip and &ip are NOT the same (cpp hell) */ eeprom_restore_ip (ip, &ip); #else set_CONF_ETHERRAPE_IP (&ip); #endif uip_sethostaddr (&ip); /* Configure prefix length (IPv6). */ #ifdef IPV6_SUPPORT uip_setprefixlen (CONF_ENC_IP6_PREFIX_LEN); #endif #ifdef IPV4_SUPPORT /* Configure the netmask (IPv4). */ #ifdef EEPROM_SUPPORT /* Please Note: ip and &ip are NOT the same (cpp hell) */ eeprom_restore_ip (netmask, &ip); #else set_CONF_ETHERRAPE_IP4_NETMASK (&ip); #endif uip_setnetmask (&ip); #endif /* IPV4_SUPPORT */ /* Configure the default gateway */ #ifdef EEPROM_SUPPORT /* Please Note: ip and &ip are NOT the same (cpp hell) */ eeprom_restore_ip (gateway, &ip); #else set_CONF_ETHERRAPE_GATEWAY (&ip); #endif uip_setdraddr (&ip); #endif /* No autoconfiguration. */ }
//配置网卡硬件,并设置MAC地址 //返回值:0,正常;1,失败; u8 tapdev_init(void) { u32 wait_count; u8 i, res = 0; #ifndef DHCP_ENABLE uip_ipaddr_t ipaddr; #endif res = ENC28J60_Init((u8*)Modbus.mac_addr); //初始化ENC28J60 //把IP地址和MAC地址写入缓存区 for (i = 0; i < 6; i++) { uip_ethaddr.addr[i] = Modbus.mac_addr[i]; } //指示灯状态:0x476 is PHLCON LEDA(绿)=links status, LEDB(红)=receive/transmit //PHLCON:PHY 模块LED 控制寄存器 ENC28J60_PHY_Write(PHLCON, 0x0476); uip_init(); //uIP初始化 if(Modbus.tcp_type == 0) { U8_T temp[4]; uip_ipaddr(ipaddr, Modbus.ip_addr[0], Modbus.ip_addr[1], Modbus.ip_addr[2], Modbus.ip_addr[3]); //设置本地设置IP地址 uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, Modbus.getway[0], Modbus.getway[1], Modbus.getway[2], Modbus.getway[3]); //设置网关IP地址(其实就是你路由器的IP地址) uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, Modbus.subnet[0], Modbus.subnet[1], Modbus.subnet[2], Modbus.subnet[3]); //设置网络掩码 uip_setnetmask(ipaddr); // flag_dhcp_configured = 2; temp[0] = Modbus.ip_addr[0]; temp[1] = Modbus.ip_addr[1]; temp[2] = Modbus.ip_addr[2]; temp[3] = Modbus.ip_addr[3]; temp[0] |= (255 - Modbus.subnet[0]); temp[1] |= (255 - Modbus.subnet[1]); temp[2] |= (255 - Modbus.subnet[2]); temp[3] |= (255 - Modbus.subnet[3]); uip_ipaddr(uip_hostaddr_submask,temp[0], temp[1],temp[2] ,temp[3]); delay_ms(1); } else // DHCP { // flag_dhcp_configured = 0; dhcpc_init(Modbus.mac_addr, 6); dhcpc_request(); } // printf("res=%u\n\r",res); return res; }
void main(int argc, char **argv) { contiki_argc = argc; contiki_argv = argv; #else /* WITH_ARGS */ void main(void) { #endif /* WITH_ARGS */ process_init(); #if 1 ethernet_config = config_read("contiki.cfg"); #else { static struct ethernet_config config = {0xDE08, "cs8900a.eth"}; uip_ipaddr_t addr; uip_ipaddr(&addr, 192,168,0,128); uip_sethostaddr(&addr); uip_ipaddr(&addr, 255,255,255,0); uip_setnetmask(&addr); uip_ipaddr(&addr, 192,168,0,1); uip_setdraddr(&addr); uip_ipaddr(&addr, 192,168,0,1); uip_nameserver_update(&addr, UIP_NAMESERVER_INFINITE_LIFETIME); ethernet_config = &config; } #endif procinit_init(); process_start((struct process *)ðernet_process, (void *)ethernet_config); autostart_start(autostart_processes); log_message("Contiki up and running ...", ""); while(1) { process_run(); etimer_request_poll(); } }
void dhcpc_configured(const struct dhcpc_state *s) { uip_sethostaddr(s->ipaddr); uip_setnetmask(s->netmask); uip_setdraddr(s->default_router); #if CFG_SUPPORT_DNS resolv_conf(s->dnsaddr); resolv_query("www.ablecloud.cn"); #endif }
int sendmail_main(int argc, char *argv[]) { struct in_addr addr; #if defined(CONFIG_EXAMPLES_SENDMAIL_NOMAC) uint8_t mac[IFHWADDRLEN]; #endif void *handle; printf("sendmail: To: %s\n", g_recipient); printf("sendmail: From: %s\n", g_sender); printf("sendmail: Subject: %s\n", g_subject); printf("sendmail: Body: %s\n", g_msg_body); /* Many embedded network interfaces must have a software assigned MAC */ #ifdef CONFIG_EXAMPLES_SENDMAIL_NOMAC mac[0] = 0x00; mac[1] = 0xe0; mac[2] = 0xde; mac[3] = 0xad; mac[4] = 0xbe; mac[5] = 0xef; uip_setmacaddr("eth0", mac); #endif /* Set up our host address */ addr.s_addr = HTONL(CONFIG_EXAMPLES_SENDMAIL_IPADDR); uip_sethostaddr("eth0", &addr); /* Set up the default router address */ addr.s_addr = HTONL(CONFIG_EXAMPLES_SENDMAIL_DRIPADDR); uip_setdraddr("eth0", &addr); /* Setup the subnet mask */ addr.s_addr = HTONL(CONFIG_EXAMPLES_SENDMAIL_NETMASK); uip_setnetmask("eth0", &addr); /* Then send the mail */ uip_ipaddr(addr.s_addr, 127, 0, 0, 1); handle = smtp_open(); if (handle) { smtp_configure(handle, g_host_name, &addr.s_addr); smtp_send(handle, g_recipient, NULL, g_sender, g_subject, g_msg_body, strlen(g_msg_body)); smtp_close(handle); } return 0; }
void dhcpc_configured(const struct dhcpc_state *s) { #ifdef MY_DEBUG //rprintf("IP : %d.%d.%d.%d\n", uip_ipaddr1(s->ipaddr), uip_ipaddr2(s->ipaddr), uip_ipaddr3(s->ipaddr), uip_ipaddr4(s->ipaddr)); //rprintf("NM : %d.%d.%d.%d\n", uip_ipaddr1(s->netmask), uip_ipaddr2(s->netmask), uip_ipaddr3(s->netmask), uip_ipaddr4(s->netmask)); //rprintf("GW : %d.%d.%d.%d\n", uip_ipaddr1(s->default_router), uip_ipaddr2(s->default_router), uip_ipaddr3(s->default_router), uip_ipaddr4(s->default_router)); #endif uip_sethostaddr(s->ipaddr); uip_setnetmask(s->netmask); uip_setdraddr(s->default_router); }