static void prvInitialise_uIP( void ) { uip_ipaddr_t xIPAddr; xTimerHandle xARPTimer, xPeriodicTimer; uip_init(); uip_ipaddr( &xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 ); uip_sethostaddr( &xIPAddr ); uip_ipaddr( &xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 ); uip_setnetmask( &xIPAddr ); prvSetMACAddress(); httpd_init(); /* Create the queue used to sent TCP/IP events to the uIP stack. */ xEMACEventQueue = xQueueCreate( uipEVENT_QUEUE_LENGTH, sizeof( unsigned long ) ); /* Create and start the uIP timers. */ xARPTimer = xTimerCreate( ( signed char * ) "ARPTimer", /* Just a name that is helpful for debugging, not used by the kernel. */ ( 10000UL / portTICK_RATE_MS ), /* Timer period. */ pdTRUE, /* Autor-reload. */ ( void * ) uipARP_TIMER, prvUIPTimerCallback ); xPeriodicTimer = xTimerCreate( ( signed char * ) "PeriodicTimer", ( 500UL / portTICK_RATE_MS ), pdTRUE, /* Autor-reload. */ ( void * ) uipPERIODIC_TIMER, prvUIPTimerCallback ); /* Sanity check that the timers were indeed created. */ configASSERT( xARPTimer ); configASSERT( xPeriodicTimer ); configASSERT( xEMACEventQueue ); /* These commands will block indefinitely until they succeed, so there is no point in checking their return values. */ xTimerStart( xARPTimer, portMAX_DELAY ); xTimerStart( xPeriodicTimer, portMAX_DELAY ); }
//Connect to a remote host and associate the file_handle with the connection. //returns true on success, false on failure (eg, no more uip connection slots available ) //Note that success does not indicate the connection was establshed; watch the file handle's status for state changes. bool socket_connect( file_handle_t file_handle, struct inetaddr_t *remote_address ) { struct file_t* file = file_get_by_handle( file_handle ); if( file == NULL ) return false; u16_t ipaddr[2]; uip_ipaddr(ipaddr, remote_address->addr1,remote_address->addr2,remote_address->addr3,remote_address->addr4); struct uip_conn *conn = uip_connect(ipaddr, htons( remote_address->port ) ); if( conn == NULL ) return false; conn->appstate[0] = file_handle; file->state = OpenPending; return true; }
/*---------------------------------------------------------------------------*/ void dhcpc_request(void) { uip_ipaddr_t ipaddr; if(s.state == STATE_INITIAL) { uip_ipaddr(&ipaddr, 0,0,0,0); uip_sethostaddr(&ipaddr); handle_dhcp(PROCESS_EVENT_NONE, NULL); } }
void netif_set_addr(struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask, struct ip_addr *gw) { uip_ipaddr_t hipaddr; uip_ipaddr(hipaddr, RT_LWIP_IPADDR0,RT_LWIP_IPADDR1,RT_LWIP_IPADDR2,RT_LWIP_IPADDR3); uip_sethostaddr(hipaddr); uip_ipaddr(hipaddr, RT_LWIP_GWADDR0,RT_LWIP_GWADDR1,RT_LWIP_GWADDR2,RT_LWIP_GWADDR3); uip_setdraddr(hipaddr); uip_ipaddr(hipaddr, RT_LWIP_MSKADDR0,RT_LWIP_MSKADDR1,RT_LWIP_MSKADDR2,RT_LWIP_MSKADDR3); uip_setnetmask(hipaddr); uip_ethaddr.addr[0] = mymac[0]; uip_ethaddr.addr[1] = mymac[1]; uip_ethaddr.addr[2] = mymac[2]; uip_ethaddr.addr[3] = mymac[3]; uip_ethaddr.addr[4] = mymac[4]; uip_ethaddr.addr[5] = mymac[5]; uip_setethaddr(uip_ethaddr); return ; }
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 uip_task_init(const uint8 *ipbuf, const uint8 *netmask, const uint8 *mac) { uip_ipaddr_t ipaddr; uip_init(); uip_arp_init(); uip_ipaddr(ipaddr, ipbuf[0], ipbuf[1], ipbuf[2], ipbuf[3]); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, netmask[0], netmask[1], netmask[2], netmask[3]); uip_setnetmask(ipaddr); uip_ethaddr.addr[0] = mac[0]; uip_ethaddr.addr[1] = mac[1]; uip_ethaddr.addr[2] = mac[2]; uip_ethaddr.addr[3] = mac[3]; uip_ethaddr.addr[4] = mac[4]; uip_ethaddr.addr[5] = mac[5]; }
/*---------------------------------------------------------------------------*/ void dhcpc_request(void) { uip_ipaddr_t ipaddr; if(s.state == STATE_INITIAL) { uip_ipaddr(&ipaddr, 0,0,0,0); uip_sethostaddr(&ipaddr); s.task = posTaskCreate(dhcpTask, NULL, 1, 1000); POS_SETTASKNAME(s.task, "uip:dhcpc"); } }
/*---------------------------------------------------------------------------*/ void udpHandler_init(void) { uip_ipaddr_t addr; struct uip_udp_conn *c; uip_ipaddr(&addr, 192,168,0,199); c = uip_udp_new(&addr, HTONS(0)); if(c != NULL) { uip_udp_bind(c, HTONS(1101)); } }
/** 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 }
static void prvInitialise_uIP( void ) { TimerHandle_t xARPTimer, xPeriodicTimer; uip_ipaddr_t xIPAddr; const unsigned long ul_uIPEventQueueLength = 10UL; /* Initialise the uIP stack. */ uip_init(); uip_ipaddr( &xIPAddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 ); uip_sethostaddr( &xIPAddr ); uip_ipaddr( &xIPAddr, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3 ); uip_setnetmask( &xIPAddr ); prvSetMACAddress(); httpd_init(); /* Create the queue used to sent TCP/IP events to the uIP stack. */ xEMACEventQueue = xQueueCreate( ul_uIPEventQueueLength, sizeof( unsigned long ) ); /* Create and start the uIP timers. */ xARPTimer = xTimerCreate( "ARPTimer", /* Just a name that is helpful for debugging, not used by the kernel. */ ( 10000UL / portTICK_PERIOD_MS ), /* Timer period. */ pdTRUE, /* Autor-reload. */ ( void * ) uipARP_TIMER, prvUIPTimerCallback ); xPeriodicTimer = xTimerCreate( "PeriodicTimer", ( 50 / portTICK_PERIOD_MS ), pdTRUE, /* Autor-reload. */ ( void * ) uipPERIODIC_TIMER, prvUIPTimerCallback ); configASSERT( xARPTimer ); configASSERT( xPeriodicTimer ); xTimerStart( xARPTimer, portMAX_DELAY ); xTimerStart( xPeriodicTimer, portMAX_DELAY ); }
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); } }
PROCESS_THREAD(init_process, ev, data) { uip_ipaddr_t addr; PROCESS_BEGIN(); uip_ipaddr(&addr, 192,168,2,2); uip_sethostaddr(&addr); uip_ipaddr(&addr, 192,168,2,1); uip_setdraddr(&addr); uip_ipaddr(&addr, 255,255,255,0); uip_setnetmask(&addr); printf("init\n"); program_handler_add(&netconf_dsc, "Network setup", 1); program_handler_add(&ftp_dsc, "FTP client", 1); program_handler_add(&www_dsc, "Web browser", 1); program_handler_add(&processes_dsc, "Processes", 1); program_handler_add(&shell_dsc, "Command shell", 1); program_handler_add(&calc_dsc, "Calculator", 1); /* program_handler_add(&email_dsc, "E-mail", 1);*/ program_handler_add(&irc_dsc, "IRC", 1); /* program_handler_add(&vnc_dsc, "VNC client", 1);*/ program_handler_add(&dhcp_dsc, "DHCP client", 1); uip_fw_default(&tapif); while(1) { PROCESS_WAIT_EVENT(); } PROCESS_END(); }
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 network_setup() { printf("network_setup\n"); uip_ipaddr_t ipaddr; uip_ipaddr_t gatewayAddr; uip_ipaddr_t netmaskAddr; uip_lladdr.addr[0] = MAC_ADDRESS[0]; uip_lladdr.addr[1] = MAC_ADDRESS[1]; uip_lladdr.addr[2] = MAC_ADDRESS[2]; uip_lladdr.addr[3] = MAC_ADDRESS[3]; uip_lladdr.addr[4] = MAC_ADDRESS[4]; uip_lladdr.addr[5] = MAC_ADDRESS[5]; uip_ipaddr(&ipaddr, 192, 168, 0, 101); uip_sethostaddr(&ipaddr); uip_ipaddr(&gatewayAddr, 192, 168, 0, 1); uip_setdraddr(&gatewayAddr); uip_ipaddr(&netmaskAddr, 255, 255, 255, 0); uip_setnetmask(&netmaskAddr); tcpip_set_outputfunc(enc28j60_tcp_output); enc28j60_init(uip_lladdr.addr); uip_init(); uip_arp_init(); printf("Start RS232UDP Process\n"); process_start(&rs232udp_process, NULL); printf("Start network Process\n"); process_start(&network_process, NULL); printf("END network_setup\n"); }
void network_init(void) { uip_listen(HTONS(NETWORK_PORT_GCODE)); uip_listen(HTONS(NETWORK_PORT_DEBUG)); // Listen on a UDP port uip_ipaddr_t addr; struct uip_udp_conn *c; uip_ipaddr(&addr, 0,0,0,0); c = uip_udp_new(&addr, HTONS(0)); if(c != NULL) uip_udp_bind(c, HTONS(NETWORK_PORT_GCODE)); }
static void tdtp_connect(void) { struct uip_conn *conn; uip_ipaddr_t ipaddr; uip_ipaddr(&ipaddr, 10, 69, 69, 1); conn = uip_connect(&ipaddr, htons(6969)); if(conn == NULL) { #ifdef MOG_DEBUG printf("failure out of ports\r\n"); #endif tdtp_state=1; } }
/*---------------------------------------------------------------------------*/ void init_net(void) { int i; uip_ipaddr_t hostaddr, netmask; rimeaddr_t rimeaddr; /* Init Rime */ ctimer_init(); rimeaddr.u8[0] = node_id & 0xff; rimeaddr.u8[1] = node_id >> 8; rimeaddr_set_node_addr(&rimeaddr); printf("Rime started with address: "); for(i = 0; i < sizeof(rimeaddr_node_addr.u8) - 1; i++) { printf("%d.", rimeaddr_node_addr.u8[i]); } printf("%d\n", rimeaddr_node_addr.u8[i]); /* Init uIPv4 */ process_start(&tcpip_process, NULL); process_start(&uip_fw_process, NULL); process_start(&slip_process, NULL); uip_init(); uip_fw_init(); uip_ipaddr(&hostaddr, 172, 16, rimeaddr_node_addr.u8[1], rimeaddr_node_addr.u8[0]); uip_ipaddr(&netmask, 255,255,0,0); uip_sethostaddr(&hostaddr); uip_setnetmask(&netmask); uip_fw_register(&wsn_if); uip_fw_default(&slip_if); rs232_set_input(slip_input_byte); printf("uIP started with IP address: %d.%d.%d.%d\n", uip_ipaddr_to_quad(&hostaddr)); /* uIPv4 <-> COOJA's packet radio */ /*tcpip_set_outputfunc(sender);*/ cooja_radio.set_receive_function(receiver); }
void dhcp_init(void) { uip_ipaddr_t ipaddr; uip_ipaddr(&ipaddr, 255, 255, 255, 255); dhcp_s.conn = uip_udp_new(&ipaddr, HTONS(DHCP_SERVER_PORT)); uip_udp_bind(dhcp_s.conn, HTONS(DHCP_CLIENT_PORT)); dhcp_s.xid = random(); dhcp_s.dhcp_renew_time = get_clock() + 2 * CLOCK_TICKS_PER_SECOND + (random() % (3 * CLOCK_TICKS_PER_SECOND)); dhcp_s.state = DHCP_STATE_BOOT_WAIT; }
int twitter_resolve(cb_resolve_status_t cb_resolve_status, struct process *parent) { state.cb_resolve_status = cb_resolve_status; state.parent = parent; #if UIP_UDP resolv_query(DEFAULT_HOST); process_start(&twitter_resolve_process, NULL); return 1; #else /* UIP_UDP */ uip_ipaddr(ip_address, DEFAULT_IP[0], DEFAULT_IP[1], DEFAULT_IP[2], DEFAULT_IP[3]); return 0; #endif /* UIP_UDP */ }
void udpapp_init(void) { uip_ipaddr_t addr; struct uip_udp_conn *c; uip_ipaddr(&addr, 255, 255, 255, 255); c = uip_udp_new(&addr, HTONS(0)); if(c != NULL) { uip_udp_bind(c, HTONS(2222)); } s.state = STATE_INIT; PT_INIT(&s.pt); }
void udpapp_init(void) { uip_ipaddr_t addr; struct uip_udp_conn *c; uip_ipaddr(&addr, 192,168,1,23); c = uip_udp_new(&addr, HTONS(0)); if(c != NULL) { uip_udp_bind(c, HTONS(12344)); } s.state = STATE_INIT; PT_INIT(&s.pt); }
/*---------------------------------------------------------------------------*/ rt_err_t eth_device_init(struct eth_device* dev, const char* name) { uip_ipaddr_t ipaddr; rt_device_register(&(dev->fops), name, RT_DEVICE_FLAG_RDWR); dev->fops.type = RT_Device_Class_NetIf; /* uip_ipaddr(ipaddr, RT_UIP_IPADDR0,RT_UIP_IPADDR1,RT_UIP_IPADDR2,RT_UIP_IPADDR3); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, RT_UIP_GWADDR0,RT_UIP_GWADDR1,RT_UIP_GWADDR2,RT_UIP_GWADDR3); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, RT_UIP_MSKADDR0,RT_UIP_MSKADDR1,RT_UIP_MSKADDR2,RT_UIP_MSKADDR3); uip_setnetmask(ipaddr); */ uip_ipaddr(ipaddr, 192,168,0,2); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 192,168,0,1); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 255,255,255,0); uip_setnetmask(ipaddr); return RT_EOK; }
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; }
/******************************************************************************* * 函数名:InitNet * 输 入: * 输 出: * 功能说明:初始化网络硬件、UIP协议栈、配置本机IP地址 */ void InitNet(void) { uip_ipaddr_t ipaddr; /* 检测网卡芯片 */ { uint32_t vid; vid = dm9k_ReadID(); if (vid == DM9000A_ID_OK) { //printf("DM9000AE Detect Ok, vid&pid = %08X\n\r", vid); } else { //printf("DM9000AE Detect Failed, vid&pid = %08X, Expected = %08X\n\r", vid, DM9000A_ID_OK); } } tapdev_init(); //printf("uip_init\n\r"); uip_init(); //printf("uip ip address : 192,168,20,11\n\r"); uip_ipaddr(ipaddr, 192,168,20,11); uip_sethostaddr(ipaddr); //printf("uip route address : 192,168,20,1\n\r"); uip_ipaddr(ipaddr, 192,168,20,1); uip_setdraddr(ipaddr); //printf("uip net mask : 255,255,255,0\n\r"); uip_ipaddr(ipaddr, 255,255,255,0); uip_setnetmask(ipaddr); }
void bootp_net_init(void) { uip_ipaddr_t ip; uip_ipaddr(&ip, 255,255,255,255); uip_udp_conn_t *bootp_conn = uip_udp_new(&ip, HTONS(BOOTPS_PORT), bootp_net_main); if(! bootp_conn) return; /* dammit. */ uip_udp_bind(bootp_conn, HTONS(BOOTPC_PORT)); bootp_conn->appstate.bootp.retry_timer = 0; }
/*---------------------------------------------------------------------------*/ void dhcpc_request(void) { u16_t ipaddr[2]; //sendString("\r\ndhcpc request called"); if(s.state == STATE_INITIAL) { //sendString("\r\ndhcpc request init state"); #if defined PORT_APP_MAPPER dhcpc_running = 1; #endif uip_ipaddr(ipaddr, 0,0,0,0); uip_sethostaddr(ipaddr); //handle_dhcp(); } }
/*---------------------------------------------------------------------------*/ void dhcpc_init(const void *mac_addr, int mac_len) { uip_ipaddr_t addr; s.mac_addr = mac_addr; s.mac_len = mac_len; s.state = STATE_INITIAL; uip_ipaddr(addr, 255,255,255,255); s.conn = uip_udp_new(&addr, HTONS(DHCPC_SERVER_PORT)); if(s.conn != NULL) { uip_udp_bind(s.conn, HTONS(DHCPC_CLIENT_PORT)); } PT_INIT(&s.pt); }
static void _mqttclient_broker_connect(void) { struct uip_conn *uc; uip_ipaddr_t ip; uip_ipaddr(&ip, MQTT_BROKER_IP_ADDR0, MQTT_BROKER_IP_ADDR1, MQTT_BROKER_IP_ADDR2, MQTT_BROKER_IP_ADDR3); uc = uip_connect(&ip, htons(MQTT_BROKER_PORT)); if (uc == NULL) { return; } uc->appstate.conn = &_mqtt; update_state(MQTTCLIENT_BROKER_CONNECTING); }
/*---------------------------------------------------------------------------*/ struct uip_udp_conn * udp_broadcast_new(uint16_t port, void *appstate) { uip_ipaddr_t addr; struct uip_udp_conn *conn; #if UIP_CONF_IPV6 uip_create_linklocal_allnodes_mcast(&addr); #else uip_ipaddr(&addr, 255,255,255,255); #endif /* UIP_CONF_IPV6 */ conn = udp_new(&addr, port, appstate); if(conn != NULL) { udp_bind(conn, port); } return conn; }
void tcp_cli_app1_init(void) { UIP_CONN *tcp_conn=NULL; uip_ipaddr_t raddr; uint8 iot_srv_ip[MAC_IP_LEN] = TCP_CLI_APP1_IOT_SRV_IP; uip_ipaddr(raddr, iot_srv_ip[0],iot_srv_ip[1], iot_srv_ip[2],iot_srv_ip[3]); /* Specify remote address and port here. */ tcp_conn = uip_connect(&raddr, HTONS(TCP_CLI_APP1_REMOTE_PORT)); if (tcp_conn) { tcp_conn->lport = HTONS(TCP_CLI_APP1_LOCAL_PORT); } else { printf_high("connect fail\n"); } }