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