]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Network/Ip4Dxe/Ip4Input.h
[Change summary]:
[mirror_edk2.git] / MdeModulePkg / Universal / Network / Ip4Dxe / Ip4Input.h
1 /** @file
2
3 Copyright (c) 2005 - 2009, Intel Corporation.<BR>
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 **/
13
14 #ifndef __EFI_IP4_INPUT_H__
15 #define __EFI_IP4_INPUT_H__
16
17 #define IP4_MIN_HEADLEN 20
18 #define IP4_MAX_HEADLEN 60
19
20 #define IP4_ASSEMLE_HASH_SIZE 31
21 #define IP4_FRAGMENT_LIFE 120
22 #define IP4_MAX_PACKET_SIZE 65535
23
24 ///
25 /// Per packet information for input process. LinkFlag specifies whether
26 /// the packet is received as Link layer unicast, multicast or broadcast.
27 /// The CastType is the IP layer cast type, such as IP multicast or unicast.
28 /// Start, End and Length are staffs used to assemble the packets. Start
29 /// is the sequence number of the first byte of data in the packet. Length
30 /// is the number of bytes of data. End = Start + Length, that is, the
31 /// sequence number of last byte + 1. Each assembled packet has a count down
32 /// life. If it isn't consumed before Life reaches zero, the packet is released.
33 ///
34 typedef struct {
35 UINTN LinkFlag;
36 INTN CastType;
37 INTN Start;
38 INTN End;
39 INTN Length;
40 UINT32 Life;
41 EFI_STATUS Status;
42 } IP4_CLIP_INFO;
43
44 ///
45 /// Structure used to assemble IP packets.
46 ///
47 typedef struct {
48 LIST_ENTRY Link;
49
50 //
51 // Identity of one IP4 packet. Each fragment of a packet has
52 // the same (Dst, Src, Id, Protocol).
53 //
54 IP4_ADDR Dst;
55 IP4_ADDR Src;
56 UINT16 Id;
57 UINT8 Protocol;
58
59 INTN TotalLen;
60 INTN CurLen;
61 LIST_ENTRY Fragments; // List of all the fragments of this packet
62
63 IP4_HEAD *Head; // IP head of the first fragment
64 IP4_CLIP_INFO *Info; // Per packet info of the first fragment
65 INTN Life; // Count down life for the packet.
66 } IP4_ASSEMBLE_ENTRY;
67
68 ///
69 /// Each Ip service instance has an assemble table to reassemble
70 /// the packets before delivery to its children. It is organized
71 /// as hash table.
72 ///
73 typedef struct {
74 LIST_ENTRY Bucket[IP4_ASSEMLE_HASH_SIZE];
75 } IP4_ASSEMBLE_TABLE;
76
77 #define IP4_GET_CLIP_INFO(Packet) ((IP4_CLIP_INFO *) ((Packet)->ProtoData))
78
79 #define IP4_ASSEMBLE_HASH(Dst, Src, Id, Proto) \
80 (((Dst) + (Src) + ((Id) << 16) + (Proto)) % IP4_ASSEMLE_HASH_SIZE)
81
82 #define IP4_RXDATA_WRAP_SIZE(NumFrag) \
83 (sizeof (IP4_RXDATA_WRAP) + sizeof (EFI_IP4_FRAGMENT_DATA) * ((NumFrag) - 1))
84
85 /**
86 Initialize an already allocated assemble table. This is generally
87 the assemble table embedded in the IP4 service instance.
88
89 @param[in, out] Table The assemble table to initialize.
90
91 **/
92 VOID
93 Ip4InitAssembleTable (
94 IN OUT IP4_ASSEMBLE_TABLE *Table
95 );
96
97 /**
98 Clean up the assemble table: remove all the fragments
99 and assemble entries.
100
101 @param[in] Table The assemble table to clean up
102
103 **/
104 VOID
105 Ip4CleanAssembleTable (
106 IN IP4_ASSEMBLE_TABLE *Table
107 );
108
109 /**
110 The IP4 input routine. It is called by the IP4_INTERFACE when a
111 IP4 fragment is received from MNP.
112
113 @param[in] Ip4Instance The IP4 child that request the receive, most like
114 it is NULL.
115 @param[in] Packet The IP4 packet received.
116 @param[in] IoStatus The return status of receive request.
117 @param[in] Flag The link layer flag for the packet received, such
118 as multicast.
119 @param[in] Context The IP4 service instance that own the MNP.
120
121 **/
122 VOID
123 Ip4AccpetFrame (
124 IN IP4_PROTOCOL *Ip4Instance,
125 IN NET_BUF *Packet,
126 IN EFI_STATUS IoStatus,
127 IN UINT32 Flag,
128 IN VOID *Context
129 );
130
131 /**
132 Demultiple the packet. the packet delivery is processed in two
133 passes. The first pass will enque a shared copy of the packet
134 to each IP4 child that accepts the packet. The second pass will
135 deliver a non-shared copy of the packet to each IP4 child that
136 has pending receive requests. Data is copied if more than one
137 child wants to consume the packet because each IP child needs
138 its own copy of the packet to make changes.
139
140 @param[in] IpSb The IP4 service instance that received the packet
141 @param[in] Head The header of the received packet
142 @param[in] Packet The data of the received packet
143
144 @retval EFI_NOT_FOUND No IP child accepts the packet
145 @retval EFI_SUCCESS The packet is enqueued or delivered to some IP
146 children.
147
148 **/
149 EFI_STATUS
150 Ip4Demultiplex (
151 IN IP4_SERVICE *IpSb,
152 IN IP4_HEAD *Head,
153 IN NET_BUF *Packet
154 );
155
156 /**
157 Enqueue a received packet to all the IP children that share
158 the same interface.
159
160 @param[in] IpSb The IP4 service instance that receive the packet
161 @param[in] Head The header of the received packet
162 @param[in] Packet The data of the received packet
163 @param[in] IpIf The interface to enqueue the packet to
164
165 @return The number of the IP4 children that accepts the packet
166
167 **/
168 INTN
169 Ip4InterfaceEnquePacket (
170 IN IP4_SERVICE *IpSb,
171 IN IP4_HEAD *Head,
172 IN NET_BUF *Packet,
173 IN IP4_INTERFACE *IpIf
174 );
175
176 /**
177 Deliver the received packets to upper layer if there are both received
178 requests and enqueued packets. If the enqueued packet is shared, it will
179 duplicate it to a non-shared packet, release the shared packet, then
180 deliver the non-shared packet up.
181
182 @param[in] IpInstance The IP child to deliver the packet up.
183
184 @retval EFI_OUT_OF_RESOURCES Failed to allocate resources to deliver the
185 packets.
186 @retval EFI_SUCCESS All the enqueued packets that can be delivered
187 are delivered up.
188
189 **/
190 EFI_STATUS
191 Ip4InstanceDeliverPacket (
192 IN IP4_PROTOCOL *IpInstance
193 );
194
195 /**
196 Timeout the fragment and enqueued packets.
197
198 @param[in] IpSb The IP4 service instance to timeout
199
200 **/
201 VOID
202 Ip4PacketTimerTicking (
203 IN IP4_SERVICE *IpSb
204 );
205
206 #endif