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); } }
void dhcpc_configured(const struct dhcpc_state *s) { #ifdef XTCP_VERBOSE_DEBUG printf("dhcp: ");uip_printip4(s->ipaddr);printf("\n"); #endif #if UIP_USE_AUTOIP autoip_stop(); #endif uip_sethostaddr(s->ipaddr); uip_setdraddr(s->default_router); uip_setnetmask(s->netmask); uip_xtcp_up(); dhcp_done = 1; }
void autoip_configured(uip_ipaddr_t autoip_ipaddr) { if (!dhcp_done) { uip_ipaddr_t ipaddr; #ifdef XTCP_VERBOSE_DEBUG printf("ipv4ll: "); uip_printip4(autoip_ipaddr); printf("\n"); #endif /* XTCP_VERBOSE_DEBUG */ uip_sethostaddr(autoip_ipaddr); uip_ipaddr(ipaddr, 255, 255, 0, 0); uip_setnetmask(ipaddr); uip_ipaddr(ipaddr, 0, 0, 0, 0); uip_setdraddr(ipaddr); uip_xtcp_up(); } }
/* ----------------------------------------------------------------------------- * Initialise the uip_server * -------------------------------------------------------------------------- */ void uip_server_init(chanend xtcp[], int num_xtcp, xtcp_ipconfig_t *ipconfig, unsigned char *mac_address) { if (ipconfig != NULL) memcpy(&uip_static_ipconfig, ipconfig, sizeof(xtcp_ipconfig_t)); /* set the mac_adress */ memcpy(&uip_lladdr, mac_address, 6); #if 0 //XXX CHSC: not necessary? Be carefully with erasing the mac address... /* The following line sets the uIP's link-layer address. This must be done * before the tcpip_process is started since in its initialisation * routine the function uip_netif_init() will be called from inside * uip_init()and there the default IPv6 address will be set by combining * the link local prefix (fe80::/64)and the link layer address. */ rimeaddr_copy((rimeaddr_t*) &uip_lladdr.addr, &rimeaddr_node_addr); #endif //TODO chsc: port the rtimer module (if really needed) // /* rtimers needed for radio cycling */ // rtimer_init(); /* Initialise the process module */ process_init(); /* etimers must be started before ctimer_init */ process_start(&etimer_process, NULL); ctimer_init(); /* this calls have to be made before the uip_init * not exactely proved why. CHSC * */ etimer_request_poll(); process_run(); uip_init(); #if UIP_CONF_IPV6 && UIP_CONF_IPV6_RPL rpl_init(); #endif /* UIP_CONF_IPV6_RPL */ #if UIP_IGMP igmp_init(); #endif /* UIP_IGMP */ if (ipconfig != NULL && (*((int*)ipconfig->ipaddr.u8) != 0)) { uip_static_ip = 1; } if (ipconfig == NULL) { uip_ipaddr_t ipaddr; #if UIP_CONF_IPV4 uip_ipaddr(&ipaddr, 0, 0, 0, 0); uip_sethostaddr(&ipaddr); uip_setdraddr(&ipaddr); uip_setnetmask(&ipaddr); #elif UIP_CONF_IPV6 uip_ip6addr(&ipaddr, 0, 0, 0, 0 , 0, 0, 0, 0); #endif /* UIP_CONF_IPVx */ } else { #if UIP_CONF_IPV4 uip_sethostaddr(&ipconfig->ipaddr); uip_setdraddr(&ipconfig->gateway); uip_setnetmask(&ipconfig->netmask); #ifdef XTCP_VERBOSE_DEBUG printf("Address: ");uip_printip4(uip_hostaddr);printf("\n"); printf("Gateway: ");uip_printip4(uip_draddr);printf("\n"); printf("Netmask: ");uip_printip4(uip_netmask);printf("\n"); #endif /* XTCP_VERBOSE_DEBUG */ #elif UIP_CONF_IPV6 #endif /* UIP_CONF_IPVx */ } #if UIP_CONF_IPV4 { #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_lladdr.addr, 6); #endif } #endif /* UIP_CONF_IPV4 */ xtcpd_init(xtcp, num_xtcp); }