📄 net.c
字号:
#include "common.h"#include <command.h>#include <priv_data.h>#include <mtd/mtd.h>#include <net.h>#include "bootp.h"#include "tftp.h"#include "rarp.h"#include "nfs.h"#ifdef CONFIG_CMD_NETstatic user_subcommand_t net_cmds[];#ifdef CFG_CMD_PINGvoid command_net_ping(int argc, const char *argv[]){ switch(argc){ case 2: NetPingIP = string_to_ip(argv[1]); NetLoop(PING); }}#endif#ifdef CFG_CMD_TFTPvoid command_net_tftp(int argc, const char *argv[]){ bd_t *bd = &global_bd; switch(argc){ case 3: bd->serverip = string_to_ip(argv[1]); sprintf(BootFile, "%s", argv[2]); NetLoop(TFTP); break; default: printf("param is invalid\n"); return; } return;}#endifvoid command_write_flash(int argc, const char *argv[]){ char *buf; //loff_t to; unsigned long to; /* is declared to long-long type ? */ size_t size; mtd_partition_t *dst_part; int flag; bd_t *bd = &global_bd; if (bd->filesize<=0) { printk("Please download the code to write firset\n"); return; } buf = bd->fileaddr; 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 (bd->filesize>size){ printk("An image size is too large to write flash. wanted = 0x%08lx, loaded = 0x%08lx\n", size, bd->filesize); return; } write_to_flash(to, bd->filesize, bd->fileaddr, flag); }else{ printk("Parameter Invalid\n"); } }}void command_net_set(int argc, const char *argv[]){ bd_t *bd = &global_bd; switch(argc){ case 4: bd->bi_ip_addr = string_to_ip(argv[1]); bd->netmask = string_to_ip(argv[2]); bd->gatewayip = string_to_ip(argv[3]); break; } bd->updated = 1;}void command_net_mac(int argc, const char *argv[]){ bd_t *bd = &global_bd; int i; char *s = argv[1]; char *e; switch(argc){ case 2: for (i=0; i<6; ++i) { bd->bi_enetaddr[i] = s ? simple_strtoul(s, &e, 16) : 0; if (s) s = (*e) ? e+1 : e; } break; } printf("MAC Address Change to "); for (i=0; i<6; ++i) {printf("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);} printf("\n");}void command_net_show(int argc, const char *argv[]){ bd_t *bd=&global_bd; int i; printf("Current Network Configuration\n"); printf("Ethernet Address: "); for (i=0; i<6; ++i) {printf("%c%02X", i ? ':' : ' ', bd->bi_enetaddr[i]);} printf("\n"); printf("IP Address: "); print_IPaddr(bd->bi_ip_addr); printf("\n"); printf("Net Mask: "); print_IPaddr(bd->netmask); printf("\n"); printf("Gateway: "); print_IPaddr(bd->gatewayip); printf("\n"); printf("Server IP: "); print_IPaddr(bd->serverip); printf("\n");}static void command_net_help(int argc, const char **argv){ print_usage("net", net_cmds);}static user_subcommand_t net_cmds[] = {#ifdef CFG_CMD_PING{ "ping", command_net_ping, "ping ipaddr -- Ping function"},#endif#ifdef CFG_CMD_TFTP{ "tftp", command_net_tftp, "tftp <serverip> <filename> -- Download code From TFTP Server"}, #endif{ "flash", command_write_flash, "flash <partname> -- Flash downloaded code to part"}, { "set", command_net_set, "set <ipaddr> <mask> <gateway> -- Set IP Configuration"}, { "mac", command_net_mac, "mac <mac address> -- Set MAC Address"}, { "show", command_net_show, "show -- Show Current network Configuration"}, { "help", command_net_help, "help"}, { NULL, NULL, NULL }};extern unsigned char enetaddr_default[];void command_net(int argc, const char **argv){ bd_t *bd = &global_bd; int i; if (!bd->updated) { printf("Initialize Net configruation\n"); bd->bi_ip_addr = string_to_ip(CONFIG_NET_IP); bd->netmask = string_to_ip(CONFIG_NET_MASK); bd->gatewayip = string_to_ip(CONFIG_NET_GATEWAY); bd->fileaddr = 0; bd->filesize = 0; for (i=0; i<6; ++i) bd->bi_enetaddr[i] = enetaddr_default[i]; bd->updated = 1; } bd->vlan = -1; bd->nvlan = -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"};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -