📄 lan.h
字号:
#include <zebra.h>#include "if.h"#include "vty.h"#include "sockunion.h"#include "prefix.h"#include "command.h"#include "memory.h"#include "ioctl.h"#include "connected.h"#include "log.h"#include "zclient.h"#include "zebra/interface.h"#include "zebra/rtadv.h"#include "zebra/rib.h"#include "zebra/zserv.h"#include "zebra/redistribute.h"#include "zebra/debug.h"#include "linux8305.h"/*------sunl-------*/#define SPEED 1<<13 /*-----speed select----*/#define AUTO 1<<12 /*----auto negotiation enable-----*/#define DULPLEX 1<<8 /*----dulplex mode----*//* Prototypes. */void lan_init();/*-------the-struct-of-lan-port---------*/struct lan{ /* lan port number. */ char port[2]; /* mode*/ char mode[8]; };static vector lanvec;struct lan lanneg[4];struct cmd_node lan_node ={ CONFIG_NODE, "%s(config-lan)# ", 1};intlan_config_write(struct vty *vty){/* int i; for(i=0; i<4; i++) { vty_out (vty, "negotiation %s %s %s", lanneg[i].port, lanneg[i].mode, VTY_NEWLINE); } vty_out (vty, "!%s", VTY_NEWLINE);*/ return 1;}#if 1int configurePortAuto(u_int8_t phyAddr){ u_int16_t data; int ret = 0; /*Init Pin*/ InitSerialInterface(); data= SMIRead(phyAddr, 0); /*read data from 8305*/ SetBit(data, AUTO); /*auto negotiation enable=1*/ /*write the data to 8305*/ if((ret = SMIWrite(phyAddr, 0, data)) == -1) { printf("Writing is error!!!\n"); return -1; } return 0;}int configureEthernetPort(u_int8_t phyAddr, u_int16_t speed, u_int16_t duplex){ u_int16_t data; int ret = 0; /*Init Pin*/ InitSerialInterface(); data= SMIRead(phyAddr, 0); /*read data from 8305*/ ClrBit(data, AUTO); /*auto negotiation disable=0*/ /*dulplex mode*/ if(duplex==1) { SetBit(data, DULPLEX); /*full dulplex*/ } else if(duplex==0) { ClrBit(data, DULPLEX); /*half dulplex*/ } /*speed select*/ if(speed==1) { SetBit(data, SPEED); /*speed=100M*/ } else if(speed==0) { ClrBit(data, SPEED); /*speed=10M*/ } /*write the data to 8305*/ if((ret = SMIWrite(phyAddr, 0, data)) == -1) { printf("Writing is error!!!\n"); return -1; } return 0;}/*Configure the ethernet ports on KT505*/DEFUN (config_lan_negotiation, config_lan_negotiation_cmd, "negotiation (0|1|2|3) (10half|10full|100half|100full|auto)", "Configure the ethernet ports\n"){ u_int16_t data_read; if( strcmp(argv[0], "0") == 0 )/*set port 0 ,register 0*/ { if( strcmp(argv[1], "100full") == 0 ) { if( configureEthernetPort(0, 1, 1) == 0 ) { lanneg[0].mode=strdup(argv[1]); vty_out (vty, "port0 negotiation is 100full%s", VTY_NEWLINE); } } else if(strcmp(argv[1], "100half") == 0) { if( configureEthernetPort(0, 1, 0) == 0 ) { lanneg[0].mode=strdup("100half"); vty_out (vty, "port0 negotiation is 100half%s", VTY_NEWLINE); } } else if(strcmp(argv[1], "10full") == 0) { if( configureEthernetPort(0, 0, 1) == 0 ) { lanneg[0].mode="10full"; vty_out (vty, "port0 negotiation is 10full%s", VTY_NEWLINE); } } else if(strcmp(argv[1], "10half") == 0) { if( configureEthernetPort(0, 0, 0) == 0 ) { lanneg[0].mode="10half"; vty_out (vty, "port0 negotiation is 10half%s", VTY_NEWLINE); } } else if(strcmp(argv[1], "auto") == 0) { if( configurePortAuto(0) == 0 ) { lanneg[0].mode="auto"; vty_out (vty, "port0 negotiation is auto%s", VTY_NEWLINE); } } } else if( strcmp(argv[0], "1") == 0 )/*set port 1 ,register 0*/ { if( strcmp(argv[1], "100full") == 0 ) { if( configureEthernetPort(1, 1, 1) == 0 ) { lanneg[1].mode="100full"; vty_out (vty, "port1 negotiation is 100full%s", VTY_NEWLINE); } } else if(strcmp(argv[1], "100half") == 0) { if( configureEthernetPort(1, 1, 0) == 0 ) { lanneg[1].mode="100half"; vty_out (vty, "port1 negotiation is 100half%s", VTY_NEWLINE); } } else if(strcmp(argv[1], "10full") == 0) { if( configureEthernetPort(1, 0, 1) == 0 ) { lanneg[1].mode="10full"; vty_out (vty, "port1 negotiation is 10full%s", VTY_NEWLINE); } } else if(strcmp(argv[1], "10half") == 0) { if( configureEthernetPort(1, 0, 0) == 0 ) { lanneg[1].mode="10half"; vty_out (vty, "port1 negotiation is 10half%s", VTY_NEWLINE); } } else if(strcmp(argv[1], "auto") == 0) { if( configurePortAuto(1) == 0 ) { lanneg[1].mode="auto"; vty_out (vty, "port1 negotiation is auto%s", VTY_NEWLINE); } } } else if( strcmp(argv[0], "2") == 0 )/*set port 2 ,register 0*/ { if( strcmp(argv[1], "100full") == 0 ) { if( configureEthernetPort(2, 1, 1) == 0 ) { lanneg[2].mode="100full"; vty_out (vty, "port2 negotiation is 100full%s", VTY_NEWLINE); } } else if(strcmp(argv[1], "100half") == 0) { if( configureEthernetPort(2, 1, 0) == 0 ) { lanneg[2].mode="100half"; vty_out (vty, "port2 negotiation is 100half%s", VTY_NEWLINE); } } else if(strcmp(argv[1], "10full") == 0) { if( configureEthernetPort(2, 0, 1) == 0 ) { lanneg[2].mode="10full"; vty_out (vty, "port2 negotiation is 10full%s", VTY_NEWLINE); } } else if(strcmp(argv[1], "10half") == 0) { if( configureEthernetPort(2, 0, 0) == 0 ) { lanneg[2].mode="10half"; vty_out (vty, "port2 negotiation is 10half%s", VTY_NEWLINE); } } else if(strcmp(argv[1], "auto") == 0) { if( configurePortAuto(2) == 0 ) { lanneg[2].mode="auto"; vty_out (vty, "port2 negotiation is auto%s", VTY_NEWLINE); } } } else if( strcmp(argv[0], "3") == 0 )/*set port 3 ,register 0*/ { if( strcmp(argv[1], "100full") == 0 ) { if( configureEthernetPort(3, 1, 1) == 0 ) { lanneg[3].mode="100full"; vty_out (vty, "port3 negotiation is 100full%s", VTY_NEWLINE); } } else if(strcmp(argv[1], "100half") == 0) { if( configureEthernetPort(3, 1, 0) == 0 ) { lanneg[3].mode="100half"; vty_out (vty, "port3 negotiation is 100half%s", VTY_NEWLINE); } } else if(strcmp(argv[1], "10full") == 0) { if( configureEthernetPort(3, 0, 1) == 0 ) { lanneg[3].mode="10full"; vty_out (vty, "port3 negotiation is 10full%s", VTY_NEWLINE); } } else if(strcmp(argv[1], "10half") == 0) { if( configureEthernetPort(3, 0, 0) == 0 ) { lanneg[3].mode="10half"; vty_out (vty, "port3 negotiation is 10half%s", VTY_NEWLINE); } } else if(strcmp(argv[1], "auto") == 0) { if( configurePortAuto(3) == 0 ) { lanneg[3].mode="auto"; vty_out (vty, "port3 negotiation is auto%s", VTY_NEWLINE); } } } data_read= SMIRead(0, 0); vty_out (vty, "read the data is %d\n", data_read); return CMD_SUCCESS;}#endifvoid lan_init(){ lanvec = vector_init (VECTOR_MIN_SIZE); printf("sunlei here!\n"); lanneg[0].port=strdup("0"); lanneg[1].port=strdup("1"); lanneg[2].port=strdup("2"); lanneg[3].port=strdup("3"); /* Install configuration write function. */ install_node (&lan_node, lan_config_write); printf("sunlei2 here!\n");// install_default (LAN_NODE); printf("sunlei3 here!\n");// install_element(LAN_NODE, &config_lan_negotiation_cmd); printf("sunlei 4here!\n");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -