📄 cmd_net.c
字号:
/* * vivi/net/cmd_net.c * * Based on u-boot * * $Id: cmd_net.c,v 1.0 2004/08/12 11:14:01 kingmonkey Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Description: net command routines . * */ #include "config.h" #include "printk.h"#include "command.h"#include "machine.h"#include "priv_data.h"#include "mtd/mtd.h"#include "net.h"#include "bootp.h"#include "tftp.h"#include "rarp.h"#include <string.h>extern unsigned long downfilesize;unsigned long load_addr = RAM_BASE;static user_subcommand_t net_cmds[];const char net_config_magic[8] = {'N', 'E', 'T', '-', 'C', 'O', 'N', 'F'};#ifdef CONFIG_CMD_PINGvoid command_net_ping(int argc, const char *argv[]){ switch(argc){ case 2: NetPingIP = string_to_ip(argv[1]); NetLoop(PING); break; default: printk("param is invalid\n"); return; } return;}#endif#ifdef CONFIG_CMD_TFTPvoid command_net_tftp(int argc, const char *argv[]){ switch(argc){ case 2: sprintf(BootFile, "%s", argv[1]); NetLoop(TFTP); break; case 3: global_bd->serverip = string_to_ip(argv[1]); sprintf(BootFile, "%s", argv[2]); NetLoop(TFTP); break; default: printk("param is invalid\n"); return; } return;}#endifvoid command_write_flash(int argc, const char *argv[]){ unsigned long to; size_t size; mtd_partition_t *dst_part; int flag; if (downfilesize<=0) { printk("Please download the code to write firset\n"); return; } switch(argc){ case 2: if (strncmp("flash", argv[0], 5)==0){ dst_part = get_mtd_partition(argv[1]); if (dst_part == NULL) { printk("Could not found \"%s\" partition\n", argv[2]); return; } to = dst_part->offset; size = dst_part->size; flag = dst_part->flag; if (downfilesize>size){ printk("An image size is too large to write flash. wanted = 0x%08lx, loaded = 0x%08lx\n", size, downfilesize); return; } write_to_flash(to, downfilesize, load_addr, flag); }else{ printk("Parameter Invalid\n"); } }}void command_net_set(int argc, const char *argv[]){ int i; char *s = argv[1]; char *e; if(argc=3){ if (strncmp("mac", argv[1], 3) == 0) { for (i=0; i<6; ++i) { global_bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0; if (s) s = (*e) ? e+1 : e; } }else if(strncmp("ipaddr", argv[1], 6) == 0) { global_bd->bi_ip_addr = string_to_ip(argv[2]); }else if(strncmp("serverip", argv[1], 8) == 0) { global_bd->serverip = string_to_ip(argv[2]); }else if(strncmp("netmask", argv[1], 7) == 0) { global_bd->netmask = string_to_ip(argv[2]); }else if(strncmp("gateway", argv[1], 7) == 0) { global_bd->gatewayip = string_to_ip(argv[2]); }else{ printk("Parameter Invalid\n"); } }}void command_net_save(int argc, const char *argv[]){ if (argc != 1) { invalid_cmd("net save", net_cmds); return; } if (save_priv_data_blk()) printk("Could not save vivi private data\n"); else printk("Saved vivi private data\n");}void command_net_show(int argc, const char *argv[]){ net_config *bd=global_bd; int i; printk("Current Network Configuration\n"); printk("Ethernet Address: "); for (i=0; i<6; ++i) {printk("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);} printk("\n"); printk("IP Address: "); print_IPaddr(bd->bi_ip_addr); printk("\n"); printk("Net Mask: "); print_IPaddr(bd->netmask); printk("\n"); printk("Gateway: "); print_IPaddr(bd->gatewayip); printk("\n"); printk("Server IP: "); print_IPaddr(bd->serverip); printk("\n");}static void command_net_help(int argc, const char **argv){ print_usage("net", net_cmds);}void command_net(int argc, const char **argv){ net_config *bd = global_bd;// int i; bd->vlan = (ushort)-1; bd->nvlan =(ushort)-1; switch(argc) { case 1: command_net_show(argc-1, argv+1); command_net_help(0, NULL); return; default: execsubcmd(net_cmds, argc-1, argv+1); }}user_command_t net_cmd = { "net", command_net, NULL, "net [ping|tftp|set|mac| show| help] \t\t-- Network Manage"};static user_subcommand_t net_cmds[] = {#ifdef CONFIG_CMD_PING{ "ping", command_net_ping, "ping <ipaddr> \t\t-- Ping function"},#endif#ifdef CONFIG_CMD_TFTP{ "tftp", command_net_tftp, "tftp <serverip> <filename> \t-- Download code From TFTP Server"}, #endif{ "flash", command_write_flash, "flash <partname> \t\t-- Flash downloaded code to part"}, { "set", command_net_set, "set mac <mac address> \t-- Set net Configuration"}, { "save", command_net_save, "save \t\t\t-- Save parameter table to flash memeory"}, { "show", command_net_show, "show \t\t\t-- Show Current network Configuration"}, { "help", command_net_help, "help"}, { NULL, NULL, NULL }};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -