void SEC_InitializeNetworking(uint_32 pcbs, uint_32 msgs, uint_32 sockets, boolean dhcp) { int_32 error; IPCFG_IP_ADDRESS_DATA ip_data; _enet_address enet_address; /* runtime RTCS configuration */ _RTCSPCB_init = pcbs; _RTCS_msgpool_init = msgs; _RTCS_socket_part_init = sockets; error = RTCS_create(); if (error == RTCS_OK) { ip_data.ip = ENET_IPADDR; ip_data.mask = ENET_IPMASK; ip_data.gateway = ENET_IPGATEWAY; ENET_get_mac_address(BSP_DEFAULT_ENET_DEVICE, ENET_IPADDR, enet_address); ipcfg_init_device(BSP_DEFAULT_ENET_DEVICE, enet_address); ipcfg_add_dns_ip(BSP_DEFAULT_ENET_DEVICE,LWDNS_server_ipaddr); // check link status printf("\nWaiting for ethernet cable plug in ... "); while(!ipcfg_get_link_active(BSP_DEFAULT_ENET_DEVICE)) {}; printf("Cable connected\n"); /* If DHCP Enabled, get IP address from DHCP server */ if (dhcp) { printf("\nDHCP bind ... "); error = ipcfg_bind_dhcp_wait(BSP_DEFAULT_ENET_DEVICE, 1, &ip_data); if (error != IPCFG_ERROR_OK) { printf("Error %08x!\n", error); } else { printf("Successful!\n"); } } else { /* Else bind with static IP */ printf ("\nStatic IP bind ... "); error = ipcfg_bind_staticip(BSP_DEFAULT_ENET_DEVICE, &ip_data); if (error != IPCFG_ERROR_OK) { printf("Error %08x!\n",error); } else { printf("Successful!\n"); } } if (error == IPCFG_ERROR_OK) { ipcfg_get_ip(BSP_DEFAULT_ENET_DEVICE, &ip_data); printf("\nIP Address : %d.%d.%d.%d\n",IPBYTES(ip_data.ip)); printf("\nSubnet Address : %d.%d.%d.%d\n",IPBYTES(ip_data.mask)); printf("\nGateway Address : %d.%d.%d.%d\n",IPBYTES(ip_data.gateway)); printf("\nDNS Address : %d.%d.%d.%d\n",IPBYTES(ipcfg_get_dns_ip(BSP_DEFAULT_ENET_DEVICE,0))); } } else { printf("\nRTCS_Create failed !\n"); _task_block(); } }
void SEC_InitializeNetworking(uint_32 pcbs, uint_32 msgs, uint_32 sockets, boolean dhcp) { int_32 error; IPCFG_IP_ADDRESS_DATA ip_data; _enet_address enet_address; #if PSP_MQX_CPU_IS_MCF51CN _enet_handle ehandle; _rtcs_if_handle ihandle; #endif /* runtime RTCS configuration */ _RTCSPCB_init = pcbs; _RTCS_msgpool_init = msgs; _RTCS_socket_part_init = sockets; error = RTCS_create(); if (error == RTCS_OK) { ip_data.ip = ENET_IPADDR; ip_data.mask = ENET_IPMASK; ip_data.gateway = ENET_IPGATEWAY; #if RTCSCFG_ENABLE_LWDNS LWDNS_server_ipaddr = ENET_IPDNS; #endif ENET_get_mac_address(BSP_DEFAULT_ENET_DEVICE, ENET_IPADDR, enet_address); #if PSP_MQX_CPU_IS_MCF51CN ENET_initialize_ex(&ENET_param, BSP_DEFAULT_ENET_DEVICE, &ehandle); if (RTCS_if_add(ehandle, RTCS_IF_ENET, &ihandle) == 0) { if (ipcfg_init_interface(-1, ihandle) != 0) { RTCS_if_remove(ihandle); ENET_shutdown(ehandle); _task_block(); } } else { ENET_shutdown(ehandle); } #else ipcfg_init_device(BSP_DEFAULT_ENET_DEVICE, enet_address); #endif ipcfg_add_dns_ip(BSP_DEFAULT_ENET_DEVICE,LWDNS_server_ipaddr); // check link status printf("\nWaiting for ethernet cable plug in ... "); while(!ipcfg_get_link_active(BSP_DEFAULT_ENET_DEVICE)) {}; printf("Cable connected\n"); /* If DHCP Enabled, get IP address from DHCP server */ if (dhcp) { printf("\nDHCP bind ... "); error = ipcfg_bind_dhcp_wait(BSP_DEFAULT_ENET_DEVICE, 1, &ip_data); if (error != IPCFG_ERROR_OK) { printf("Error %08x!\n", error); } else { printf("Successful!\n"); } } else { /* Else bind with static IP */ printf ("\nStatic IP bind ... "); error = ipcfg_bind_staticip(BSP_DEFAULT_ENET_DEVICE, &ip_data); if (error != IPCFG_ERROR_OK) { printf("Error %08x!\n",error); } else { printf("Successful!\n"); } } if (error == IPCFG_ERROR_OK) { ipcfg_get_ip(BSP_DEFAULT_ENET_DEVICE, &ip_data); printf("\nIP Address : %d.%d.%d.%d\n",IPBYTES(ip_data.ip)); printf("\nSubnet Address : %d.%d.%d.%d\n",IPBYTES(ip_data.mask)); printf("\nGateway Address : %d.%d.%d.%d\n",IPBYTES(ip_data.gateway)); printf("\nDNS Address : %d.%d.%d.%d\n",IPBYTES(ipcfg_get_dns_ip(BSP_DEFAULT_ENET_DEVICE,0))); } } else { printf("\nRTCS_Create failed !\n"); _task_block(); } SEC_GetTime(); }
static int32_t Shell_ipconfig_status (uint32_t enet_device) { IPCFG_STATE state; bool link; bool task; _enet_address mac = {0}; IPCFG_IP_ADDRESS_DATA ip_data ; #if RTCSCFG_IPCFG_ENABLE_DNS _ip_address dns; #endif #if RTCSCFG_IPCFG_ENABLE_BOOT _ip_address tftp_serveraddress; unsigned char *tftp_servername; unsigned char *boot_filename; #endif #if RTCSCFG_ENABLE_IP6 uint32_t result; uint32_t n; IPCFG6_GET_ADDR_DATA data; char prn_addr6[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"]; #endif state = ipcfg_get_state (enet_device); if (state != IPCFG_STATE_INIT) { link = ipcfg_get_link_active (enet_device); task = ipcfg_task_status (); ipcfg_get_mac (enet_device, mac); ipcfg_get_ip (enet_device, &ip_data); #if RTCSCFG_IPCFG_ENABLE_DNS dns = ipcfg_get_dns_ip (enet_device, 0); #endif #if RTCSCFG_IPCFG_ENABLE_BOOT tftp_serveraddress = ipcfg_get_tftp_serveraddress (enet_device); tftp_servername = ipcfg_get_tftp_servername (enet_device); boot_filename = ipcfg_get_boot_filename (enet_device); #endif printf ("Eth# : %d\n", enet_device); printf ("Link : %s\n", link ? "on" : "off"); printf ("MAC : %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); #if RTCSCFG_ENABLE_IP4 printf ("IP4 : %d.%d.%d.%d Type: %s\n", IPBYTES(ip_data.ip), ipcfg_get_state_string (state) ); printf ("IP4 Mask : %d.%d.%d.%d\n", IPBYTES(ip_data.mask)); #if RTCSCFG_ENABLE_GATEWAYS printf ("IP4 Gate : %d.%d.%d.%d\n", IPBYTES(ip_data.gateway)); #endif #if RTCSCFG_IPCFG_ENABLE_DNS printf ("IP4 DNS : %d.%d.%d.%d\n", IPBYTES(dns)); #endif #endif /* RTCSCFG_ENABLE_IP4 */ /************************************************/ #if RTCSCFG_ENABLE_IP6 n = 0; while(!ipcfg6_get_addr(enet_device, n, &data)) { if(inet_ntop(AF_INET6,&data.ip_addr, prn_addr6, sizeof(prn_addr6))) { printf("IP6 : %s ",prn_addr6); /* IPv6 address state */ printf("State: "); switch(data.ip_addr_state) { case IP6_ADDR_STATE_PREFERRED: printf("PREFERRED "); break; case IP6_ADDR_STATE_TENTATIVE: printf("TENTATIVE "); break; case IP6_ADDR_STATE_NOT_USED: printf("NOT_USED "); break; default: printf("%d ", data.ip_addr_state); break; } /* IPv6 address type */ printf("Type: "); switch(data.ip_addr_type) { case IP6_ADDR_TYPE_MANUAL: printf("MANUAL\n"); break; case IP6_ADDR_TYPE_AUTOCONFIGURABLE: printf("AUTOCONFIGURABLE\n"); break; default: printf("%d\n", data.ip_addr_type); break; } } else { printf("IP6 : ERROR IP CONVERT\n"); } n++; } /* Print Scope ID.*/ printf("ScopeID : %d\n", ipcfg6_get_scope_id(enet_device)); #endif /* RTCSCFG_ENABLE_IP6 */ #if RTCSCFG_ENABLE_IP4 #if RTCSCFG_IPCFG_ENABLE_BOOT printf ("TFTP: %d.%d.%d.%d '%s'\n", IPBYTES(tftp_serveraddress), tftp_servername); printf ("BOOT: '%s'\n", boot_filename); #endif #endif /* RTCSCFG_ENABLE_IP4 */ printf ("Link status task %s\n", task ? "running" : "stopped"); } else { printf ("Ethernet device %d not yet initialized.\n", enet_device); } return SHELL_EXIT_SUCCESS; }
void rtcs_init() { IPCFG_IP_ADDRESS_DATA ip_data; _enet_address enet_address; uint_32 error = RTCS_create(); if (error != RTCS_OK) { printf("\nRTCS failed to initialize, error = %X", error); _task_block(); } _IP_forward = TRUE; #ifdef BSP_ENET_DEVICE_COUNT #if (BSP_ENET_DEVICE_COUNT > 0) /*Following section is relevant only in case there as some enet driver available in BSP (FEC, MACNET, WIFI or other enet driver)*/ ip_data.ip = ENET_IPADDR; ip_data.mask = ENET_IPMASK; ip_data.gateway = ENET_GATEWAY; /* calcualte unique mac address from IP ADDRES */ ENET_get_mac_address (ENET_DEVICE, ENET_IPADDR, enet_address); error = ipcfg_init_device (ENET_DEVICE, enet_address); if (error != RTCS_OK) { printf("\nFailed to initialize ethernet device, error = %X", error); _task_block(); } #if RTCSCFG_ENABLE_LWDNS LWDNS_server_ipaddr = ENET_GATEWAY; ipcfg_add_dns_ip(ENET_DEVICE,LWDNS_server_ipaddr); #endif /* RTCSCFG_ENABLE_LWDNS */ printf("\nWaiting for ethernet cable plug in ... "); while(!ipcfg_get_link_active(ENET_DEVICE)) {}; printf("Cable connected\n"); #if RTCS_DHCP printf("Contacting DHCP server ... "); error = ipcfg_bind_dhcp_wait(ENET_DEVICE, FALSE, &ip_data); #else printf("Setting static IP address ... "); error = ipcfg_bind_staticip (ENET_DEVICE, &ip_data); #endif /* RTCS_DHCP */ if (error != IPCFG_ERROR_OK) { printf("\nRTCS failed to bind interface with IPv4, error = %X", error); _task_block(); } else { printf("OK\n"); } ipcfg_get_ip(ENET_DEVICE, &ip_data); printf("\nIP Address : %d.%d.%d.%d\n",IPBYTES(ip_data.ip)); printf("\nSubnet Address : %d.%d.%d.%d\n",IPBYTES(ip_data.mask)); printf("\nGateway Address : %d.%d.%d.%d\n",IPBYTES(ip_data.gateway)); printf("\nDNS Address : %d.%d.%d.%d\n",IPBYTES(ipcfg_get_dns_ip(ENET_DEVICE,0))); #endif /* BSP_ENET_DEVICE_COUNT > 0 */ #endif /* BSP_ENET_DEVICE_COUNT */ #if RTCS_PPP PPP_start(); #endif /* RTCS_PPP */ /* TODO: start server(s) in separate tasks */ }