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_dhcp (uint32_t enet_device, uint32_t index, int32_t argc, char *argv[]) { uint32_t error; IPCFG_IP_ADDRESS_DATA auto_ip_data; bool auto_ip = FALSE ; if (argc > ++index) { if (strcmp (argv[index], "noauto") == 0) { auto_ip = FALSE; } else { if (! Shell_parse_ip_address (argv[index], &auto_ip_data.ip)) { printf ("Error in dhcp command, invalid ip address!\n"); return SHELL_EXIT_ERROR; } if (argc > ++index) { if (! Shell_parse_ip_address (argv[index], &auto_ip_data.mask)) { printf ("Error in dhcp command, invalid mask!\n"); return SHELL_EXIT_ERROR; } } else { printf ("Error in dhcp command, missing mask parameter!\n"); return SHELL_EXIT_ERROR; } #if RTCSCFG_ENABLE_GATEWAYS if (argc > ++index) { if (! Shell_parse_ip_address (argv[index], &auto_ip_data.gateway)) { printf ("Error dhcp command, invalid gateway!\n"); return SHELL_EXIT_ERROR; } } else { printf ("Error in dhcp command, missing gateway parameter!\n"); return SHELL_EXIT_ERROR; } #endif auto_ip = TRUE; } } error = ipcfg_bind_dhcp_wait (enet_device, auto_ip, &auto_ip_data); if (error != IPCFG_OK) { printf ("Error during dhcp bind %08x!\n", error); return SHELL_EXIT_ERROR; } printf ("Bind via dhcp successful.\n"); 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 */ }