⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eth.c

📁 Boot code for ADM5120 with serial console for Edimax router.
💻 C
字号:
/*****************************************************************************;;    Project : Edimax;    Creator :;    File    : eth.c;    Abstract:;;*****************************************************************************/#include <ctype.h>#include <irqlib.h>#include <memlib.h>#include <param.h>#include <eth.h>#include <skbuff.h>#include <if_5120.h>#include <buart.h>#include <test_def.h>#define DEF_BRG_CTRL_FLAG		0x00// Imported Functionextern void panic(void);PEthPktQueue_OBJ EthPktQueue;static char local_mac[6];/****************//* InitBridge:	*//****************/UINT32 InitEthPktQueue(){	if ((EthPktQueue = MemAlloc(sizeof(EthPktQueue_OBJ), TRUE)) == NULL)		return 1;	EthPktQueue->iqH_head = EthPktQueue->iqH_tail = NULL;	EthPktQueue->iqL_head = EthPktQueue->iqL_tail = NULL;	EthPktQueue->CtrlFlag = DEF_BRG_CTRL_FLAG;	return 0;}/************************//* IndicateRxPacketL:	*//************************/void IndicateRxPacketL(PDRV_PACKET_DESC Pkt){	/**********************************************************/	/* This function MUST be called with interrupts disabled! */	/**********************************************************/	if (Pkt == NULL)		return;//	Pkt->Next = NULL;	// was already commented out	if (EthPktQueue->iqL_head == NULL) {		EthPktQueue->iqL_head = EthPktQueue->iqL_tail = Pkt;	} else {		EthPktQueue->iqL_tail->Next = Pkt;		EthPktQueue->iqL_tail = Pkt;	}}void eth_init(unsigned char *macsrc){	memcpy(local_mac, macsrc, 6);}int eth_send(struct sk_buff *skb, unsigned char *dest_addr, unsigned short proto){	int s,i;	UINT8 *buf;	PDRV_PACKET_DESC Pkt;	struct ethhdr *eth_hdr;	eth_hdr = (struct ethhdr *) skb_push(skb, ETH_HLEN);	memcpy(eth_hdr->h_dest, dest_addr, ETH_ALEN);	memcpy(eth_hdr->h_source, local_mac, ETH_ALEN);	eth_hdr->h_proto = htons(proto);	// Get a free packet for the transmitting descriptor	Pkt = (PDRV_PACKET_DESC) Am5120_GetFreePkt();	// Fill in the packet...	buf = Pkt->Buf + Pkt->buf1off;	memcpy(buf, skb->data, skb->len);	Pkt->PktLen = skb->len;	if ((Pkt->PktLen) < 0x3c) {		for (i = Pkt->PktLen; i < 60; i++) {			*(buf + i) = 0x00;			Pkt->PktLen++;		}	}	SendPacketsL(Pkt);}int eth_rcv(struct sk_buff *skb){	static int rxcount = 0;	PDRV_PACKET_DESC Pkt;	UINT32 srcport, srcvlan;	UINT8 *buf;	int irq_state;	   	irq_state = mips_int_lock();    Pkt = EthPktQueue->iqL_head;	if (EthPktQueue->iqL_head != NULL) {		if (EthPktQueue->iqL_head == EthPktQueue->iqL_tail)			EthPktQueue->iqL_head = EthPktQueue->iqL_tail = NULL;		else			EthPktQueue->iqL_head = Pkt->Next;		Pkt->Next = NULL;	}    mips_int_unlock(irq_state);	if (Pkt != NULL) {		srcport = Pkt->SrcPort;		buf = Pkt->Buf + Pkt->buf1off;		// EthPktQueue->v_statis[srcvlan].RxPkt ++;	// was already commented out		rxcount++;		skb->len = Pkt->PktLen;		memcpy(skb->data, buf, skb->len);		Am5120_RefreePkt(Pkt);		return 0;	}	return -1;}int eth_rcv_packet(struct sk_buff *skb){	struct ethhdr *eth_hdr;	int ip_protocol;		ip_protocol = 0;	if (eth_rcv(skb) != -1) {		ip_protocol = -1;		eth_hdr = (struct ethhdr *) (skb->data);		skb_pull(skb, ETH_HLEN);		if (ntohs(eth_hdr->h_proto) == ETH_P_ARP)			arp_rcv_packet(skb);		else if(ntohs(eth_hdr->h_proto) == ETH_P_IP)		 	ip_protocol = 1;	}	return ip_protocol;}void eth_skb_reserve(struct sk_buff *skb){	skb_reserve(skb, ETH_HLEN);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -