void cmd_process( const char* cmd ) { switch( cmd[0] ) { case WELCOME: cmd_welcome(); break; case 'b': cmd_reboot(); break; case 'e': cmd_eeprom(cmd); break; case 'i': cmd_current(); break; case 'l': cmd_line_voltage(); break; case 'm': cmd_stack_memory(); break; case 'p': cmd_power(cmd); break; case 'q': cmd_capacity(); break; case 'r': cmd_reset(); break; case 't': cmd_temperatur(); break; case 'u': cmd_voltage(); break; case 'x': eMode = eTwike; plc_force_busy(0); break; case '?': cmd_help(); break; default: strcpy_P(cmd_line, PSTR("<Unknown command, try ? for help.")); } cmd_flush(); }
static void console_command_mode_run(void) { char szTemp[256]; char *str = NULL; int len = 0, i = 0; OS_PRINTF("\nEnter command mode. 'help' to show command list(non specific)\n"); OS_PRINTF("\nEnter command mode. 'spechelp' to show specific command list\n"); while (1) { if(get_console_mode() == DOWNLOAD_MODE) { OS_PRINTF("> "); } else { OS_PRINTF("Cmd > "); } get_command(szTemp); #ifdef ENABLE_CMD_HISTORY save_command(szTemp); #endif len = strlen(szTemp); if(len <= 0) { // do nothing continue; } // trim the space at the begin of the input for(i = 0; i < len; i++) { if(szTemp[i] != ' ') { str = &szTemp[i]; break; } } // trim the space at the end of the input for(i = len-1; i >= 0; i--) { if(szTemp[i] != ' ') { szTemp[i+1] = 0; break; } } len = strlen(str); if(len <= 0) { continue; // do nothing } else { int i = 0, j =0; int showhelp = 0; testfm_p_suite_t pSuite = NULL; testfm_p_cmd_t pTest = NULL; testfm_error_code_t res = TESTFM_SUCCESS; if(!(((str[0] >= 'a') && (str[0] <= 'z')) || ((str[0] >= 'A') && (str[0] <= 'Z')))) { OS_PRINTF("CMD should start with 'a-z' and 'A-Z'.\n"); continue; } for(i = 0; i < len-1; i++) { if((j == 0) && (str[i] == ' ')) { j = i; memset(parameter_str, 0, 256); memcpy(parameter_str, &str[i+1], strlen(&str[i+1])); } if((str[i] == '-') && (str[i+1] == 'h') && (str[i-1] == ' ') && (((i+2) == len) || (str[i+2] == ' '))) { showhelp = 1; break; } } if(j != 0) str[j] = 0; if(0 == memcmp(str, "help", 4)) { // list all non specific command cmd_help(); continue; } if(0 == memcmp(str, "wizardshelp", 11)) { // list all specific command cmd_help_specific(PLATFORM_WIZARD); continue; } if(0 == memcmp(str, "magichelp", 9)) { // list all specific command cmd_help_specific(PLATFORM_MAGIC); continue; } if(0 == memcmp(str, "warriorshelp", 12)) { // list all specific command cmd_help_specific(PLATFORM_WARRIORS); continue; } if(0 == memcmp(str, "anyhelp", 7)) { // list all specific command cmd_help_specific(PLATFORM_ANY); continue; } if(0 == memcmp(str, "read", 4)) { cmd_read(); continue; } if(0 == memcmp(str, "write", 5)) { //cmd_write(); continue; } if(get_console_mode() == DOWNLOAD_MODE) { if(0 == memcmp(str, "download", 8)) { cmd_download(); continue; } if(0 == memcmp(str, "go", 2)) { cmd_go(); continue; } if(0 == memcmp(str, "reboot", 6)) { cmd_reboot(); continue; } OS_PRINTF("'%s' is not recognized as an internal or external command.\n", str); continue; } if(0 == memcmp(str, "exit", 4)) { cmd_exit(); continue; } if(0 == memcmp(str, "runall", 6)) { cmd_runall(); continue; } if(0 == memcmp(str, "statistic", 9)) { cmd_statistic(); continue; } if(0 == memcmp(str, "autorun", 7)) { //cmd_autorun(); continue; } // add the reboot cmd for white box test if(0 == memcmp(str, "reboot", 6)) { cmd_reboot(); continue; } if(testfm_find_cmd(str, &pSuite, &pTest) == FALSE) { OS_PRINTF("'%s' is not recognized as an internal or external command.\n", str); } else { if(showhelp == 1) { pTest->pHelpFunc(); } else { //OS_PRINTF(", name: %s\n", pTest->pName); res = testfm_run_cmd(pSuite, pTest); if(res != TESTFM_SUCCESS) OS_PRINTF("error code: %d\n", res); } } } } }
int cmd_ipcfg(FILE *f, int argc, char ** argv) { struct ifnet * ifn; struct route * rt; in_addr_t ipv4_addr; in_addr_t ipv4_mask = INADDR_ANY; in_addr_t gw_addr = INADDR_ANY; int use_dhcp = 0; int change = 0; char s[64]; char ip[16]; char * env; char * cp; if (argc > 1) return SHELL_ERR_EXTRA_ARGS; fprintf(f, "\n** IP configuration utility **\n\n"); /* get current configuration */ if ((ifn = get_ifn_byname("eth0")) == NULL) return -1; ifn_ipv4_get(ifn, &ipv4_addr, &ipv4_mask); if ((rt = ipv4_route_get(INADDR_ANY, INADDR_ANY)) == NULL) gw_addr = INADDR_ANY; else gw_addr = rt->rt_gateway; use_dhcp = 0; /* get environment variable */ if ((env = getenv("IPCFG")) != NULL) { strcpy(s, env); if (!inet_aton(strtok(s, " ,"), (struct in_addr *)&ipv4_addr)) { return -1; } if (inet_aton(strtok(NULL, " ,"), (struct in_addr *)&ipv4_mask)) { if (inet_aton(strtok(NULL, " ,"), (struct in_addr *)&gw_addr)) { use_dhcp = strtoul(strtok(NULL, " , "), NULL, 0); } } } for(;;) { fprintf(f, " - IP addr(%s): ", inet_ntop(AF_INET, (void *)&ipv4_addr, ip, 16)); fgets(s, 32, f); if (s[0] == '\n') break; if (inet_aton(s, (struct in_addr *)&ipv4_addr)) { change++; break; } } for(;;) { fprintf(f, " - Network mask(%s): ", inet_ntop(AF_INET, (void *)&ipv4_mask, ip, 16)); fgets(s, 32, f); if (s[0] == '\n') break; if (inet_aton(s, (struct in_addr *)&ipv4_mask)) { change++; break; } } for (;;) { fprintf(f, " - Gateway addr(%s): ", inet_ntop(AF_INET, (void *)&gw_addr, ip, 16)); fgets(s, 32, f); if (s[0] == '\n') break; if (inet_aton(s, (struct in_addr *)&gw_addr)) { change++; break; } } #if 0 for (;;) { int c; fprintf(f, " - Enable DHCP [y/n]? (%c): ", use_dhcp ? 'y' : 'n'); fgets(s, 32, f); if (s[0] == '\n') break; c = tolower(s[0]); if ((c == 'y') || (c == 'n')) { use_dhcp = (c == 'y') ? 1 : 0; change++; break; } }; #endif if (!change) { fprintf(f, "\nKeeping current configuration.\n"); return 0; } cp = s + sprintf(s, "%s", inet_ntop(AF_INET, (void *)&ipv4_addr, ip, 16)); cp += sprintf(cp, " %s", inet_ntop(AF_INET, (void *)&ipv4_mask, ip, 16)); cp += sprintf(cp, " %s", inet_ntop(AF_INET, (void *)&gw_addr, ip, 16)); sprintf(cp, " %d", use_dhcp); if (setenv("IPCFG", s, 1) < 0) { fprintf(f, "setenv() error!\n"); return -1; } fprintf(f, "\nConfiguration saved.\n"); ifn_ipv4_set(ifn, ipv4_addr, ipv4_mask); /* set the default route */ ipv4_route_del(INADDR_ANY); ipv4_route_add(INADDR_ANY, INADDR_ANY, gw_addr, ifn); #if 0 fprintf(f, "\n - Restart the system [y/n]? "); fgets(s, 32, f); if ((tolower(s[0]) == 'y')) { cmd_reboot(f, 0, NULL); }; #endif return 0; }
static INT32 command_reboot(void (*callback)(INT32 type, INT32 process, UINT8 *str)) { return (INT32)cmd_reboot(); }
int process_dcload_udp(ether_header_t *ether, ip_header_t *ip, udp_header_t *udp) { ip_udp_pseudo_header_t *pseudo; unsigned short i; command_t *command; if (tool_ip && (tool_port != ntohs(udp->src) || tool_ip != ntohl(ip->src))) return -1; pseudo = (ip_udp_pseudo_header_t *)pkt_buf; pseudo->src_ip = ip->src; pseudo->dest_ip = ip->dest; pseudo->zero = 0; pseudo->protocol = ip->protocol; pseudo->udp_length = udp->length; pseudo->src_port = udp->src; pseudo->dest_port = udp->dest; pseudo->length = udp->length; pseudo->checksum = 0; memset(pseudo->data, 0, ntohs(udp->length) - 8 + (ntohs(udp->length)%2)); memcpy(pseudo->data, udp->data, ntohs(udp->length) - 8); /* checksum == 0 means no checksum */ if (udp->checksum != 0) i = checksum((unsigned short *)pseudo, (sizeof(ip_udp_pseudo_header_t) + ntohs(udp->length) - 9 + 1)/2); else i = 0; /* checksum == 0xffff means checksum was really 0 */ if (udp->checksum == 0xffff) udp->checksum = 0; if (i != udp->checksum) { /* scif_puts("UDP CHECKSUM BAD\n"); */ return -1; } if (!tool_ip) { printf("Set dc-tool IP to 0x%x, port %d\n", ntohl(ip->src), ntohs(udp->src)); tool_ip = ntohl(ip->src); tool_port = ntohs(udp->src); memcpy(tool_mac, ether->src, 6); } else { /* if (tool_ip != ntohs(ip->src)) */ /* return -1; */ } make_ether(ether->src, ether->dest, (ether_header_t *)pkt_buf); command = (command_t *)udp->data; /* printf("Received command '%c%c%c%c'\n", */ /* command->id[0], */ /* command->id[1], */ /* command->id[2], */ /* command->id[3]); */ if (!memcmp(command->id, CMD_EXECUTE, 4)) { cmd_execute(ether, ip, udp, command); } else if (!memcmp(command->id, CMD_REBOOT, 4)) { cmd_reboot(ip, udp, command); } else if (!memcmp(command->id, CMD_LOADBIN, 4)) { cmd_loadbin(ip, udp, command); } else if (!memcmp(command->id, CMD_PARTBIN, 4)) { cmd_partbin(ip, udp, command); } else if (!memcmp(command->id, CMD_DONEBIN, 4)) { cmd_donebin(ip, udp, command); } else if (!memcmp(command->id, CMD_SENDBINQ, 4)) { cmd_sendbinq(ip, udp, command); } else if (!memcmp(command->id, CMD_SENDBIN, 4)) { cmd_sendbin(ip, udp, command); } else if (!memcmp(command->id, CMD_VERSION, 4)) { cmd_version(ip, udp, command); } else if (!memcmp(command->id, CMD_RETVAL, 4)) { cmd_retval(ip, udp, command); } else { tool_ip = 0; return -1; } return 0; }