📄 etherif.lst
字号:
C51 COMPILER V7.07 ETHERIF 01/14/2009 14:46:41 PAGE 1
C51 COMPILER V7.07, COMPILATION OF MODULE ETHERIF
OBJECT MODULE PLACED IN .\etherif.obj
COMPILER INVOKED BY: D:\KEIL\C51\BIN\C51.EXE ..\Netif\etherif.c BROWSE DEBUG OBJECTEXTEND PRINT(.\etherif.lst) OBJECT(.\
-etherif.obj)
stmt level source
1 /*
2 * Copyright (c) 2003 Electric Application Laboratory of NAN KAI University
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25 * OF SUCH DAMAGE.
26 *
27 * Author: Li Zhanglin <wzzlin@nankai.edu.cn>
28 *
29 */
30
31 #include "..\GloblDef\GloblDef.h"
32 #include "..\TCPIP\TCPIPmem.h"
33 #include "..\TCPIP\IP.h"
34 #include "..\Netif\etherif.h"
35 #include "..\Netif\ARP.h"
36 #include "..\TCPIP\Netif.h"
37
38
39 /* call output to put a packet from IP layer to device. After
40 Ip layer selected a device, it use output to send this packet.
41 MemHead contain a packet and Netif tell dirver which netif it
42 is. NOTE:MemHead->pStart point to pIPHead
43 return:
44 TRUE: send successfuly.*/
45 BOOL EtherOutput(struct SMemHead DT_XDATA *MemHead,struct SNetIf DT_XDATA* NetIf,
46 IP_ADDR DestIP) REENTRANT_SIG
47 {
48 1 DWORD NextIP; /* next host to receive the packet in rout */
49 1 struct SEtherHead DT_XDATA * pEtherHead;
50 1 struct SMemHead DT_XDATA *p;
51 1
52 1 pEtherHead = (struct SEtherHead DT_XDATA *)(MemHead->pStart - sizeof(struct SEtherHead));
53 1
54 1 /* if DestIP in this subnet ... */
C51 COMPILER V7.07 ETHERIF 01/14/2009 14:46:41 PAGE 2
55 1 if((NetIf->NetMask & NetIf->IPAddr) == (NetIf->NetMask & DestIP))
56 1 NextIP = DestIP;
57 1 else
58 1 NextIP = NetIf->GateWay;
59 1
60 1 /* find Ether addr of NextIP */
61 1 if(ARPFind(pEtherHead->DestAddr,NextIP) == FALSE)
62 1 {
63 2 /* send a arp query */
64 2 if((p = ARPQuery(NetIf,NextIP)) != NULL)
65 2 {
66 3 ((struct SEtherDevice DT_XDATA *)(NetIf->Info))->send(
67 3 p->pStart,sizeof(struct SARPPacket) +
68 3 sizeof(struct SEtherHead));
69 3
70 3 MemFree(p);
71 3 }
72 2 }
73 1 else
74 1 {
75 2 /* fill ehter header, DestAddr already filled in ARPFind */
76 2 MemCopy(pEtherHead->ScrAddr,
77 2 ((struct SEtherDevice DT_XDATA *)(NetIf->Info))->Addr,ETHER_ADDR_LEN);
78 2
79 2 pEtherHead->type = htons(ETHER_TYPE_IP);
80 2
81 2 /* send the packet. packet lenth is less than MemHead size */
82 2 return ((struct SEtherDevice DT_XDATA *)(NetIf->Info))->send(
83 2 pEtherHead,(WORD)(MemHead->pEnd - (BYTE DT_XDATA *)pEtherHead));
84 2 }
85 1 return FALSE;
86 1 /* free MemHead when it is acked in tcp model */
87 1 }
88
89 /* this function is called periodically.Get a packet from specific
90 device. If there is a packet, call NetIf->Input to do more */
91 void EtherInput(struct SNetIf DT_XDATA * NetIf) REENTRANT_SIG
92 {
93 1 struct SMemHead DT_XDATA *MemHead;
94 1 struct SEtherHead DT_XDATA *pEtherHead;
95 1 struct SMemHead DT_XDATA *p;
96 1
97 1 /* if there is a packet to deal with */
98 1 while((MemHead = ((struct SEtherDevice DT_XDATA *)(NetIf->Info))->recv())
99 1 != NULL)
100 1 {
101 2 /* Note, pStart point to EtherHead */
102 2 pEtherHead = (struct SEtherHead DT_XDATA *)(MemHead->pStart);
103 2
104 2 /* which packet type */
105 2 switch(ntohs(pEtherHead->type))
106 2 {
107 3 case ETHER_TYPE_IP:
108 3 /* before pass to IP layer, let MemHead->pStart point
109 3 to IP header */
110 3 MemHead->pStart += sizeof(struct SEtherHead);
111 3
112 3 /* pass to IP layer for more dealing */
113 3 IPInput(MemHead);
114 3 break;
115 3
116 3 case ETHER_TYPE_ARP:
C51 COMPILER V7.07 ETHERIF 01/14/2009 14:46:41 PAGE 3
117 3 if((p = ARPInput(MemHead,NetIf)) != NULL)
118 3 {
119 4 /* a arp reply need to be send */
120 4 ((struct SEtherDevice DT_XDATA *)(NetIf->Info))->send(
121 4 p->pStart,sizeof(struct SARPPacket)
122 4 + sizeof(struct SEtherHead));
123 4
124 4 MemFree(p);
125 4 }
126 3 /* 'MemHead' is freed in ARPInput() */
127 3 break;
128 3 default:
129 3
130 3 /* unknown packet type free */
131 3 MemFree(MemHead);
132 3 }
133 2 }
134 1 }
135 /* ethernet device init */
136 void EtherDevInit(struct SEtherDevice DT_XDATA * pDevice, BYTE EtherAddr[],
137 BOOL (DT_CODE * send)(void DT_XDATA *buf, WORD size) REENTRANT_SIG,
138 struct SMemHead DT_XDATA *(DT_CODE * recv)() REENTRANT_SIG) REENTRANT_MUL
139 {
140 1 MemCopy(pDevice->Addr,EtherAddr,ETHER_ADDR_LEN);
141 1 pDevice->recv = recv;
142 1 pDevice->send = send;
143 1 }
144
145
146
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 942 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 9
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -