📄 fxp_cmd.c
字号:
/* * Created: Sep 18, 2000 * Author: Patrik Lindergren * * Copyright (c) 2000, IP Unplugged AB, SWEDEN. * All rights reserved. * Permission to use, copy, modify, and distribute this software and * its documentation is forbidden without the written permission from * the author. * */#include <stdio.h>#include <termio.h>#include <string.h>#include <setjmp.h>#include <sys/endian.h>#include <ctype.h>#include <unistd.h>#include <stdlib.h>#include <fcntl.h>#ifdef _KERNEL#undef _KERNEL#include <sys/ioctl.h>#define _KERNEL#else#include <sys/ioctl.h>#endif#include <sys/protosw.h>#include <sys/socket.h>#include <sys/socketvar.h>#include <sys/device.h>#include <net/if.h>#include <netinet/in.h>#include <netinet/if_ether.h>#include <machine/cpu.h>#include <pmon.h>#include <net/if_media.h>#include <dev/mii/miivar.h>#include <dev/pci/pcivar.h>#include <dev/pci/if_fxpreg.h>#include <dev/pci/if_fxpvar.h>void fxp_read_eeprom __P((struct fxp_softc *, u_int16_t *, int, int));void fxp_write_eeprom __P((struct fxp_softc *, u_int16_t *, int, int));intfxp_cmd (ac, av) int ac; char *av[];{ struct ifnet *ifp; struct fxp_softc *sc; u_int8_t enaddr[6]; struct ether_addr *e; int i = 1; int j; int init = 0; int dump = 0; int write = 0; if (strequ (av[i], "-i")) { i = 2; init = 1; } else if (strequ (av[i], "-d")) { i = 2; dump = 1; } else if (strequ (av[i], "-w")) { i = 2; write = 1; } for(ifp = ifnet.tqh_first; ifp != 0; ifp = ifp->if_list.tqe_next) { if(strcmp(ifp->if_xname, "lo0") == 0) continue; if(strcmp(ifp->if_xname, av[i]) == 0) break; } if(ifp == NULL) { printf("can't find device %s\n", av[i]); return(1); } sc = (struct fxp_softc *)ifp->if_softc; if(ac == 2) { /* * Read MAC address. */ fxp_read_eeprom(sc, (u_int16_t *)enaddr, 0, 3); e = (struct ether_addr *)enaddr; printf("%s = %s\n",av[1], ether_ntoa(e)); } else { if(init) { u_int16_t eeinit[] = { 0x0302, 0x0000, 0x0102, 0x014d, 0x0000, 0x1372, 0x0683, 0x4048, 0x0c00, 0x8680, 0x0000 }; fxp_write_eeprom(sc, eeinit, 3, 11); } else if(dump) { static u_int16_t eedump[14]; fxp_read_eeprom(sc, eedump, 0, 14); printf("%s = [",av[i]); for(j = 0; j < 14 ; j++) { printf(",%04x",eedump[j]); } printf("]\n"); } else if(write) { static u_int16_t eeword; static u_int16_t eeread; int temp; int offset; offset = atoi(av[i+1]); if(offset < 0 || offset > 0xff) { printf("Wrong offset value\n"); return(1); } fxp_read_eeprom(sc, (u_int16_t *)&eeread, offset, 1); printf("%s(%02x) = [%04x]? ",av[i], offset, eeread); scanf("%4x", &temp); eeword = (u_int16_t)temp; fxp_write_eeprom(sc, (u_int16_t *)&eeword, offset, 1); } else { /* Write SEEPROM */ e = ether_aton(av[i+1]); if(e == NULL) { printf("wrong format of mac address\n"); return(1); } fxp_write_eeprom(sc, (u_int16_t *)e, 0, 3); } } return 0;}/* * Command table registration * ========================== */extern const Optdesc flash_opts[];static const Cmd Cmds[] ={ {"Misc"}, {"fxp", "[-iwd] [device] [mac address]", 0, "read/program mac address", fxp_cmd, 2, 4, 0}, {0, 0}};static void init_cmd __P((void)) __attribute__ ((constructor));voidinit_cmd(){ cmdlist_expand(Cmds, 1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -