]>
Commit | Line | Data |
---|---|---|
8a67d61d | 1 | /** @file\r |
3e8c18da | 2 | Implementation of Managed Network Protocol public services.\r |
8a67d61d | 3 | \r |
87f89c08 | 4 | Copyright (c) 2005 - 2009, Intel Corporation. <BR>\r |
8a67d61d | 5 | All rights reserved. This program and the accompanying materials\r |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
8a67d61d | 13 | **/\r |
8a67d61d | 14 | \r |
6e4bac4d | 15 | #include "MnpImpl.h"\r |
8a67d61d | 16 | \r |
17 | /**\r | |
b6c4ecad | 18 | Returns the operational parameters for the current MNP child driver. May also\r |
19 | support returning the underlying SNP driver mode data. \r | |
20 | \r | |
21 | The GetModeData() function is used to read the current mode data (operational\r | |
22 | parameters) from the MNP or the underlying SNP. \r | |
23 | \r | |
3e8c18da | 24 | @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r |
25 | @param[out] MnpConfigData Pointer to storage for MNP operational parameters. Type\r | |
26 | EFI_MANAGED_NETWORK_CONFIG_DATA is defined in "Related\r | |
27 | Definitions" below.\r | |
28 | @param[out] SnpModeData Pointer to storage for SNP operational parameters. This\r | |
29 | feature may be unsupported. Type EFI_SIMPLE_NETWORK_MODE\r | |
30 | is defined in the EFI_SIMPLE_NETWORK_PROTOCOL.\r | |
b6c4ecad | 31 | \r |
32 | @retval EFI_SUCCESS The operation completed successfully.\r | |
33 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
34 | @retval EFI_UNSUPPORTED The requested feature is unsupported in this\r | |
35 | MNP implementation.\r | |
36 | @retval EFI_NOT_STARTED This MNP child driver instance has not been\r | |
37 | configured. The default values are returned in\r | |
38 | MnpConfigData if it is not NULL.\r | |
6e4bac4d | 39 | @retval Others The mode data could not be read.\r |
8a67d61d | 40 | \r |
41 | **/\r | |
42 | EFI_STATUS\r | |
43 | EFIAPI\r | |
44 | MnpGetModeData (\r | |
45 | IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r | |
6e4bac4d | 46 | OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData, OPTIONAL\r |
b6c4ecad | 47 | OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL\r |
8a67d61d | 48 | )\r |
49 | {\r | |
50 | MNP_INSTANCE_DATA *Instance;\r | |
51 | EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r | |
52 | EFI_TPL OldTpl;\r | |
53 | EFI_STATUS Status;\r | |
54 | \r | |
55 | if (This == NULL) {\r | |
56 | \r | |
57 | return EFI_INVALID_PARAMETER;\r | |
58 | }\r | |
59 | \r | |
60 | Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r | |
61 | \r | |
e48e37fc | 62 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
8a67d61d | 63 | \r |
64 | if (MnpConfigData != NULL) {\r | |
65 | //\r | |
66 | // Copy the instance configuration data.\r | |
67 | //\r | |
687a2e5f | 68 | CopyMem (MnpConfigData, &Instance->ConfigData, sizeof (*MnpConfigData));\r |
8a67d61d | 69 | }\r |
70 | \r | |
71 | if (SnpModeData != NULL) {\r | |
72 | //\r | |
73 | // Copy the underlayer Snp mode data.\r | |
74 | //\r | |
6e4bac4d | 75 | Snp = Instance->MnpServiceData->Snp;\r |
687a2e5f | 76 | CopyMem (SnpModeData, Snp->Mode, sizeof (*SnpModeData));\r |
8a67d61d | 77 | }\r |
78 | \r | |
79 | if (!Instance->Configured) {\r | |
80 | Status = EFI_NOT_STARTED;\r | |
81 | } else {\r | |
82 | Status = EFI_SUCCESS;\r | |
83 | }\r | |
84 | \r | |
e48e37fc | 85 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 86 | \r |
87 | return Status;\r | |
88 | }\r | |
89 | \r | |
90 | \r | |
91 | /**\r | |
b6c4ecad | 92 | Sets or clears the operational parameters for the MNP child driver. \r |
93 | \r | |
94 | The Configure() function is used to set, change, or reset the operational \r | |
95 | parameters for the MNP child driver instance. Until the operational parameters\r | |
96 | have been set, no network traffic can be sent or received by this MNP child\r | |
97 | driver instance. Once the operational parameters have been reset, no more\r | |
98 | traffic can be sent or received until the operational parameters have been set\r | |
99 | again.\r | |
100 | Each MNP child driver instance can be started and stopped independently of\r | |
101 | each other by setting or resetting their receive filter settings with the\r | |
102 | Configure() function.\r | |
103 | After any successful call to Configure(), the MNP child driver instance is\r | |
104 | started. The internal periodic timer (if supported) is enabled. Data can be\r | |
105 | transmitted and may be received if the receive filters have also been enabled.\r | |
106 | Note: If multiple MNP child driver instances will receive the same packet\r | |
107 | because of overlapping receive filter settings, then the first MNP child\r | |
108 | driver instance will receive the original packet and additional instances will\r | |
109 | receive copies of the original packet.\r | |
110 | Note: Warning: Receive filter settings that overlap will consume extra\r | |
111 | processor and/or DMA resources and degrade system and network performance.\r | |
112 | \r | |
6e4bac4d | 113 | @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r |
114 | @param[in] MnpConfigData Pointer to configuration data that will be assigned\r | |
115 | to the MNP child driver instance. If NULL, the MNP\r | |
116 | child driver instance is reset to startup defaults\r | |
117 | and all pending transmit and receive requests are\r | |
118 | flushed. Type EFI_MANAGED_NETWORK_CONFIG_DATA is\r | |
119 | defined in EFI_MANAGED_NETWORK_PROTOCOL.GetModeData().\r | |
8a67d61d | 120 | \r |
121 | @retval EFI_SUCCESS The operation completed successfully.\r | |
b6c4ecad | 122 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is\r |
123 | TRUE:\r | |
124 | * This is NULL.\r | |
125 | * MnpConfigData.ProtocolTypeFilter is not\r | |
126 | valid.\r | |
127 | The operational data for the MNP child driver\r | |
128 | instance is unchanged.\r | |
129 | @retval EFI_OUT_OF_RESOURCES Required system resources (usually memory)\r | |
130 | could not be allocated.\r | |
131 | The MNP child driver instance has been reset to\r | |
132 | startup defaults.\r | |
133 | @retval EFI_UNSUPPORTED The requested feature is unsupported in\r | |
134 | this [MNP] implementation. The operational data\r | |
135 | for the MNP child driver instance is unchanged.\r | |
136 | @retval EFI_DEVICE_ERROR An unexpected network or system error\r | |
137 | occurred. The MNP child driver instance has\r | |
138 | been reset to startup defaults.\r | |
6e4bac4d | 139 | @retval Others The MNP child driver instance has been reset to\r |
8a67d61d | 140 | startup defaults.\r |
141 | \r | |
142 | **/\r | |
143 | EFI_STATUS\r | |
144 | EFIAPI\r | |
145 | MnpConfigure (\r | |
146 | IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r | |
147 | IN EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL\r | |
148 | )\r | |
149 | {\r | |
150 | MNP_INSTANCE_DATA *Instance;\r | |
151 | EFI_TPL OldTpl;\r | |
152 | EFI_STATUS Status;\r | |
153 | \r | |
154 | if ((This == NULL) ||\r | |
155 | ((MnpConfigData != NULL) &&\r | |
156 | (MnpConfigData->ProtocolTypeFilter > 0) &&\r | |
157 | (MnpConfigData->ProtocolTypeFilter <= 1500))) {\r | |
158 | \r | |
159 | return EFI_INVALID_PARAMETER;\r | |
160 | }\r | |
161 | \r | |
162 | Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r | |
163 | \r | |
e48e37fc | 164 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
8a67d61d | 165 | \r |
166 | if ((MnpConfigData == NULL) && (!Instance->Configured)) {\r | |
167 | //\r | |
168 | // If the instance is not configured and a reset is requested, just return.\r | |
169 | //\r | |
170 | Status = EFI_SUCCESS;\r | |
171 | goto ON_EXIT;\r | |
172 | }\r | |
173 | \r | |
174 | //\r | |
175 | // Configure the instance.\r | |
176 | //\r | |
177 | Status = MnpConfigureInstance (Instance, MnpConfigData);\r | |
178 | \r | |
179 | ON_EXIT:\r | |
e48e37fc | 180 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 181 | \r |
182 | return Status;\r | |
183 | }\r | |
184 | \r | |
185 | \r | |
186 | /**\r | |
b6c4ecad | 187 | Translates an IP multicast address to a hardware (MAC) multicast address. This \r |
188 | function may be unsupported in some MNP implementations. \r | |
189 | \r | |
190 | The McastIpToMac() function translates an IP multicast address to a hardware\r | |
191 | (MAC) multicast address. This function may be implemented by calling the\r | |
6e4bac4d | 192 | underlying EFI_SIMPLE_NETWORK. MCastIpToMac() function, which may also be\r |
b6c4ecad | 193 | unsupported in some MNP implementations.\r |
194 | \r | |
6e4bac4d | 195 | @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r |
196 | @param[in] Ipv6Flag Set to TRUE to if IpAddress is an IPv6 multicast address.\r | |
197 | Set to FALSE if IpAddress is an IPv4 multicast address.\r | |
198 | @param[in] IpAddress Pointer to the multicast IP address (in network byte\r | |
199 | order) to convert.\r | |
200 | @param[out] MacAddress Pointer to the resulting multicast MAC address. \r | |
b6c4ecad | 201 | \r |
202 | @retval EFI_SUCCESS The operation completed successfully.\r | |
203 | @retval EFI_INVALID_PARAMETER One of the following conditions is TRUE:\r | |
204 | * This is NULL.\r | |
205 | * IpAddress is NULL.\r | |
206 | * IpAddress is not a valid multicast IP\r | |
207 | address.\r | |
208 | * MacAddress is NULL.\r | |
209 | @retval EFI_NOT_STARTED This MNP child driver instance has not been\r | |
210 | configured.\r | |
211 | @retval EFI_UNSUPPORTED The requested feature is unsupported in this\r | |
212 | MNP implementation.\r | |
213 | @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r | |
6e4bac4d | 214 | @retval Others The address could not be converted.\r |
8a67d61d | 215 | **/\r |
216 | EFI_STATUS\r | |
217 | EFIAPI\r | |
218 | MnpMcastIpToMac (\r | |
219 | IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r | |
220 | IN BOOLEAN Ipv6Flag,\r | |
221 | IN EFI_IP_ADDRESS *IpAddress,\r | |
222 | OUT EFI_MAC_ADDRESS *MacAddress\r | |
223 | )\r | |
224 | {\r | |
225 | EFI_STATUS Status;\r | |
226 | MNP_INSTANCE_DATA *Instance;\r | |
227 | EFI_SIMPLE_NETWORK_PROTOCOL *Snp;\r | |
228 | EFI_TPL OldTpl;\r | |
87f89c08 | 229 | EFI_IPv6_ADDRESS *Ip6Address;\r |
8a67d61d | 230 | \r |
231 | if ((This == NULL) || (IpAddress == NULL) || (MacAddress == NULL)) {\r | |
232 | \r | |
233 | return EFI_INVALID_PARAMETER;\r | |
234 | }\r | |
235 | \r | |
87f89c08 | 236 | Ip6Address = &IpAddress->v6;\r |
8a67d61d | 237 | \r |
87f89c08 | 238 | if ((Ipv6Flag && !IP6_IS_MULTICAST (Ip6Address)) ||\r |
239 | (!Ipv6Flag && !IP4_IS_MULTICAST (EFI_NTOHL (*IpAddress)))\r | |
240 | ) {\r | |
8a67d61d | 241 | //\r |
87f89c08 | 242 | // The IP address passed in is not a multicast address.\r |
8a67d61d | 243 | //\r |
244 | return EFI_INVALID_PARAMETER;\r | |
245 | }\r | |
246 | \r | |
247 | Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r | |
248 | \r | |
e48e37fc | 249 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
8a67d61d | 250 | \r |
251 | if (!Instance->Configured) {\r | |
252 | \r | |
253 | Status = EFI_NOT_STARTED;\r | |
254 | goto ON_EXIT;\r | |
255 | }\r | |
256 | \r | |
257 | Snp = Instance->MnpServiceData->Snp;\r | |
258 | ASSERT (Snp != NULL);\r | |
259 | \r | |
87f89c08 | 260 | ZeroMem (MacAddress, sizeof (EFI_MAC_ADDRESS)); \r |
261 | \r | |
8a67d61d | 262 | if (Snp->Mode->IfType == NET_IFTYPE_ETHERNET) {\r |
87f89c08 | 263 | if (!Ipv6Flag) {\r |
264 | //\r | |
265 | // Translate the IPv4 address into a multicast MAC address if the NIC is an\r | |
266 | // ethernet NIC according to RFC1112..\r | |
267 | //\r | |
268 | MacAddress->Addr[0] = 0x01;\r | |
269 | MacAddress->Addr[1] = 0x00;\r | |
270 | MacAddress->Addr[2] = 0x5E;\r | |
271 | MacAddress->Addr[3] = (UINT8) (IpAddress->v4.Addr[1] & 0x7F);\r | |
272 | MacAddress->Addr[4] = IpAddress->v4.Addr[2];\r | |
273 | MacAddress->Addr[5] = IpAddress->v4.Addr[3];\r | |
274 | } else {\r | |
275 | //\r | |
276 | // Translate the IPv6 address into a multicast MAC address if the NIC is an \r | |
277 | // ethernet NIC according to RFC2464.\r | |
278 | //\r | |
279 | \r | |
280 | MacAddress->Addr[0] = 0x33;\r | |
281 | MacAddress->Addr[1] = 0x33;\r | |
282 | MacAddress->Addr[2] = Ip6Address->Addr[12];\r | |
283 | MacAddress->Addr[3] = Ip6Address->Addr[13];\r | |
284 | MacAddress->Addr[4] = Ip6Address->Addr[14];\r | |
285 | MacAddress->Addr[5] = Ip6Address->Addr[15];\r | |
286 | }\r | |
8a67d61d | 287 | \r |
288 | Status = EFI_SUCCESS;\r | |
289 | } else {\r | |
290 | //\r | |
291 | // Invoke Snp to translate the multicast IP address.\r | |
292 | //\r | |
293 | Status = Snp->MCastIpToMac (\r | |
294 | Snp,\r | |
295 | Ipv6Flag,\r | |
296 | IpAddress,\r | |
297 | MacAddress\r | |
298 | );\r | |
299 | }\r | |
300 | \r | |
301 | ON_EXIT:\r | |
e48e37fc | 302 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 303 | \r |
304 | return Status;\r | |
305 | }\r | |
306 | \r | |
8a67d61d | 307 | /**\r |
b6c4ecad | 308 | Enables and disables receive filters for multicast address. This function may \r |
309 | be unsupported in some MNP implementations.\r | |
310 | \r | |
311 | The Groups() function only adds and removes multicast MAC addresses from the \r | |
312 | filter list. The MNP driver does not transmit or process Internet Group\r | |
313 | Management Protocol (IGMP) packets. If JoinFlag is FALSE and MacAddress is\r | |
314 | NULL, then all joined groups are left.\r | |
315 | \r | |
3e8c18da | 316 | @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r |
317 | @param[in] JoinFlag Set to TRUE to join this multicast group.\r | |
318 | Set to FALSE to leave this multicast group.\r | |
319 | @param[in] MacAddress Pointer to the multicast MAC group (address) to join or\r | |
320 | leave.\r | |
b6c4ecad | 321 | \r |
322 | @retval EFI_SUCCESS The requested operation completed successfully.\r | |
323 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
324 | * This is NULL.\r | |
325 | * JoinFlag is TRUE and MacAddress is NULL.\r | |
326 | * MacAddress is not a valid multicast MAC\r | |
327 | address.\r | |
328 | * The MNP multicast group settings are\r | |
329 | unchanged.\r | |
330 | @retval EFI_NOT_STARTED This MNP child driver instance has not been\r | |
331 | configured.\r | |
332 | @retval EFI_ALREADY_STARTED The supplied multicast group is already joined.\r | |
333 | @retval EFI_NOT_FOUND The supplied multicast group is not joined.\r | |
334 | @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r | |
335 | The MNP child driver instance has been reset to\r | |
336 | startup defaults.\r | |
337 | @retval EFI_UNSUPPORTED The requested feature is unsupported in this MNP\r | |
338 | implementation.\r | |
6e4bac4d | 339 | @retval Others The requested operation could not be completed.\r |
b6c4ecad | 340 | The MNP multicast group settings are unchanged.\r |
8a67d61d | 341 | \r |
342 | **/\r | |
343 | EFI_STATUS\r | |
344 | EFIAPI\r | |
345 | MnpGroups (\r | |
346 | IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r | |
347 | IN BOOLEAN JoinFlag,\r | |
348 | IN EFI_MAC_ADDRESS *MacAddress OPTIONAL\r | |
349 | )\r | |
350 | {\r | |
351 | MNP_INSTANCE_DATA *Instance;\r | |
352 | EFI_SIMPLE_NETWORK_MODE *SnpMode;\r | |
353 | MNP_GROUP_CONTROL_BLOCK *GroupCtrlBlk;\r | |
354 | MNP_GROUP_ADDRESS *GroupAddress;\r | |
e48e37fc | 355 | LIST_ENTRY *ListEntry;\r |
8a67d61d | 356 | BOOLEAN AddressExist;\r |
357 | EFI_TPL OldTpl;\r | |
358 | EFI_STATUS Status;\r | |
359 | \r | |
360 | if (This == NULL || (JoinFlag && (MacAddress == NULL))) {\r | |
361 | //\r | |
362 | // This is NULL, or it's a join operation but MacAddress is NULL.\r | |
363 | //\r | |
364 | return EFI_INVALID_PARAMETER;\r | |
365 | }\r | |
366 | \r | |
367 | Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r | |
368 | SnpMode = Instance->MnpServiceData->Snp->Mode;\r | |
369 | \r | |
e48e37fc | 370 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
8a67d61d | 371 | \r |
372 | if (!Instance->Configured) {\r | |
373 | \r | |
374 | Status = EFI_NOT_STARTED;\r | |
375 | goto ON_EXIT;\r | |
376 | }\r | |
377 | \r | |
378 | if ((!Instance->ConfigData.EnableMulticastReceive) ||\r | |
379 | ((MacAddress != NULL) && !NET_MAC_IS_MULTICAST (MacAddress, &SnpMode->BroadcastAddress, SnpMode->HwAddressSize))) {\r | |
380 | //\r | |
381 | // The instance isn't configured to do mulitcast receive. OR\r | |
382 | // the passed in MacAddress is not a mutlticast mac address.\r | |
383 | //\r | |
384 | Status = EFI_INVALID_PARAMETER;\r | |
385 | goto ON_EXIT;\r | |
386 | }\r | |
387 | \r | |
388 | Status = EFI_SUCCESS;\r | |
389 | AddressExist = FALSE;\r | |
390 | GroupCtrlBlk = NULL;\r | |
391 | \r | |
392 | if (MacAddress != NULL) {\r | |
393 | //\r | |
394 | // Search the instance's GroupCtrlBlkList to find the specific address.\r | |
395 | //\r | |
396 | NET_LIST_FOR_EACH (ListEntry, &Instance->GroupCtrlBlkList) {\r | |
397 | \r | |
398 | GroupCtrlBlk = NET_LIST_USER_STRUCT (\r | |
399 | ListEntry,\r | |
400 | MNP_GROUP_CONTROL_BLOCK,\r | |
401 | CtrlBlkEntry\r | |
402 | );\r | |
403 | GroupAddress = GroupCtrlBlk->GroupAddress;\r | |
e48e37fc | 404 | if (0 == CompareMem (\r |
8a67d61d | 405 | MacAddress,\r |
406 | &GroupAddress->Address,\r | |
407 | SnpMode->HwAddressSize\r | |
408 | )) {\r | |
409 | //\r | |
410 | // There is already the same multicast mac address configured.\r | |
411 | //\r | |
412 | AddressExist = TRUE;\r | |
413 | break;\r | |
414 | }\r | |
415 | }\r | |
416 | \r | |
417 | if (JoinFlag && AddressExist) {\r | |
418 | //\r | |
419 | // The multicast mac address to join already exists.\r | |
420 | //\r | |
421 | Status = EFI_ALREADY_STARTED;\r | |
422 | }\r | |
423 | \r | |
424 | if (!JoinFlag && !AddressExist) {\r | |
425 | //\r | |
426 | // The multicast mac address to leave doesn't exist in this instance.\r | |
427 | //\r | |
428 | Status = EFI_NOT_FOUND;\r | |
429 | }\r | |
430 | \r | |
431 | if (EFI_ERROR (Status)) {\r | |
432 | goto ON_EXIT;\r | |
433 | }\r | |
e48e37fc | 434 | } else if (IsListEmpty (&Instance->GroupCtrlBlkList)) {\r |
8a67d61d | 435 | //\r |
436 | // The MacAddress is NULL and there is no configured multicast mac address,\r | |
437 | // just return.\r | |
438 | //\r | |
439 | goto ON_EXIT;\r | |
440 | }\r | |
441 | \r | |
442 | //\r | |
443 | // OK, it is time to take action.\r | |
444 | //\r | |
445 | Status = MnpGroupOp (Instance, JoinFlag, MacAddress, GroupCtrlBlk);\r | |
446 | \r | |
447 | ON_EXIT:\r | |
e48e37fc | 448 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 449 | \r |
450 | return Status;\r | |
451 | }\r | |
452 | \r | |
8a67d61d | 453 | /**\r |
b6c4ecad | 454 | Places asynchronous outgoing data packets into the transmit queue.\r |
455 | \r | |
456 | The Transmit() function places a completion token into the transmit packet \r | |
457 | queue. This function is always asynchronous.\r | |
458 | The caller must fill in the Token.Event and Token.TxData fields in the\r | |
459 | completion token, and these fields cannot be NULL. When the transmit operation\r | |
460 | completes, the MNP updates the Token.Status field and the Token.Event is\r | |
461 | signaled.\r | |
462 | Note: There may be a performance penalty if the packet needs to be\r | |
463 | defragmented before it can be transmitted by the network device. Systems in\r | |
464 | which performance is critical should review the requirements and features of\r | |
465 | the underlying communications device and drivers.\r | |
466 | \r | |
467 | \r | |
3e8c18da | 468 | @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r |
469 | @param[in] Token Pointer to a token associated with the transmit data\r | |
6e4bac4d | 470 | descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN\r |
87f89c08 | 471 | is defined in "Related Definitions" below.\r |
b6c4ecad | 472 | \r |
473 | @retval EFI_SUCCESS The transmit completion token was cached.\r | |
8a67d61d | 474 | @retval EFI_NOT_STARTED This MNP child driver instance has not been\r |
475 | configured.\r | |
b6c4ecad | 476 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is\r |
477 | TRUE:\r | |
478 | * This is NULL.\r | |
479 | * Token is NULL.\r | |
480 | * Token.Event is NULL.\r | |
481 | * Token.TxData is NULL.\r | |
482 | * Token.TxData.DestinationAddress is not\r | |
483 | NULL and Token.TxData.HeaderLength is zero.\r | |
484 | * Token.TxData.FragmentCount is zero.\r | |
485 | * (Token.TxData.HeaderLength +\r | |
486 | Token.TxData.DataLength) is not equal to the\r | |
487 | sum of the\r | |
488 | Token.TxData.FragmentTable[].FragmentLength\r | |
489 | fields.\r | |
490 | * One or more of the\r | |
491 | Token.TxData.FragmentTable[].FragmentLength\r | |
492 | fields is zero.\r | |
493 | * One or more of the\r | |
494 | Token.TxData.FragmentTable[].FragmentBufferfields\r | |
495 | is NULL.\r | |
496 | * Token.TxData.DataLength is greater than MTU.\r | |
8a67d61d | 497 | @retval EFI_ACCESS_DENIED The transmit completion token is already in the\r |
498 | transmit queue.\r | |
499 | @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a\r | |
b6c4ecad | 500 | lack of system resources (usually memory). \r |
8a67d61d | 501 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r |
502 | The MNP child driver instance has been reset to\r | |
503 | startup defaults.\r | |
504 | @retval EFI_NOT_READY The transmit request could not be queued because\r | |
505 | the transmit queue is full.\r | |
506 | \r | |
507 | **/\r | |
508 | EFI_STATUS\r | |
509 | EFIAPI\r | |
510 | MnpTransmit (\r | |
511 | IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r | |
512 | IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token\r | |
513 | )\r | |
514 | {\r | |
515 | EFI_STATUS Status;\r | |
516 | MNP_INSTANCE_DATA *Instance;\r | |
517 | MNP_SERVICE_DATA *MnpServiceData;\r | |
518 | UINT8 *PktBuf;\r | |
519 | UINT32 PktLen;\r | |
520 | EFI_TPL OldTpl;\r | |
521 | \r | |
522 | if ((This == NULL) || (Token == NULL)) {\r | |
523 | \r | |
524 | return EFI_INVALID_PARAMETER;\r | |
525 | }\r | |
526 | \r | |
527 | Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r | |
528 | \r | |
e48e37fc | 529 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
8a67d61d | 530 | \r |
531 | if (!Instance->Configured) {\r | |
532 | \r | |
533 | Status = EFI_NOT_STARTED;\r | |
534 | goto ON_EXIT;\r | |
535 | }\r | |
536 | \r | |
537 | if (!MnpIsValidTxToken (Instance, Token)) {\r | |
538 | //\r | |
539 | // The Token is invalid.\r | |
540 | //\r | |
541 | Status = EFI_INVALID_PARAMETER;\r | |
542 | goto ON_EXIT;\r | |
543 | }\r | |
544 | \r | |
545 | MnpServiceData = Instance->MnpServiceData;\r | |
546 | NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r | |
547 | \r | |
548 | //\r | |
549 | // Build the tx packet\r | |
550 | //\r | |
551 | MnpBuildTxPacket (MnpServiceData, Token->Packet.TxData, &PktBuf, &PktLen);\r | |
552 | \r | |
553 | //\r | |
554 | // OK, send the packet synchronously.\r | |
555 | //\r | |
556 | Status = MnpSyncSendPacket (MnpServiceData, PktBuf, PktLen, Token);\r | |
557 | \r | |
558 | ON_EXIT:\r | |
e48e37fc | 559 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 560 | \r |
561 | return Status;\r | |
562 | }\r | |
563 | \r | |
564 | \r | |
565 | /**\r | |
b6c4ecad | 566 | Places an asynchronous receiving request into the receiving queue.\r |
567 | \r | |
568 | The Receive() function places a completion token into the receive packet \r | |
569 | queue. This function is always asynchronous.\r | |
570 | The caller must fill in the Token.Event field in the completion token, and\r | |
571 | this field cannot be NULL. When the receive operation completes, the MNP\r | |
572 | updates the Token.Status and Token.RxData fields and the Token.Event is\r | |
573 | signaled.\r | |
574 | \r | |
6e4bac4d | 575 | @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r |
576 | @param[in] Token Pointer to a token associated with the receive\r | |
577 | data descriptor. Type\r | |
578 | EFI_MANAGED_NETWORK_COMPLETION_TOKEN is defined in\r | |
579 | EFI_MANAGED_NETWORK_PROTOCOL.Transmit().\r | |
8a67d61d | 580 | \r |
581 | @retval EFI_SUCCESS The receive completion token was cached.\r | |
582 | @retval EFI_NOT_STARTED This MNP child driver instance has not been\r | |
583 | configured.\r | |
b6c4ecad | 584 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is\r |
585 | TRUE:\r | |
586 | * This is NULL.\r | |
587 | * Token is NULL.\r | |
588 | * Token.Event is NULL\r | |
8a67d61d | 589 | @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a\r |
590 | lack of system resources (usually memory).\r | |
591 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
592 | The MNP child driver instance has been reset to\r | |
593 | startup defaults.\r | |
594 | @retval EFI_ACCESS_DENIED The receive completion token was already in the\r | |
595 | receive queue.\r | |
596 | @retval EFI_NOT_READY The receive request could not be queued because\r | |
597 | the receive queue is full.\r | |
598 | \r | |
599 | **/\r | |
600 | EFI_STATUS\r | |
601 | EFIAPI\r | |
602 | MnpReceive (\r | |
603 | IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r | |
604 | IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token\r | |
605 | )\r | |
606 | {\r | |
607 | EFI_STATUS Status;\r | |
608 | MNP_INSTANCE_DATA *Instance;\r | |
609 | EFI_TPL OldTpl;\r | |
610 | \r | |
611 | if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) {\r | |
612 | \r | |
613 | return EFI_INVALID_PARAMETER;\r | |
614 | }\r | |
615 | \r | |
616 | Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r | |
617 | \r | |
e48e37fc | 618 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
8a67d61d | 619 | \r |
620 | if (!Instance->Configured) {\r | |
621 | \r | |
622 | Status = EFI_NOT_STARTED;\r | |
623 | goto ON_EXIT;\r | |
624 | }\r | |
625 | \r | |
626 | //\r | |
627 | // Check whether this token(event) is already in the rx token queue.\r | |
628 | //\r | |
629 | Status = NetMapIterate (&Instance->RxTokenMap, MnpTokenExist, (VOID *) Token);\r | |
630 | if (EFI_ERROR (Status)) {\r | |
631 | \r | |
632 | goto ON_EXIT;\r | |
633 | }\r | |
634 | \r | |
635 | //\r | |
636 | // Insert the Token into the RxTokenMap.\r | |
637 | //\r | |
638 | Status = NetMapInsertTail (&Instance->RxTokenMap, (VOID *) Token, NULL);\r | |
639 | \r | |
640 | if (!EFI_ERROR (Status)) {\r | |
641 | //\r | |
642 | // Try to deliver any buffered packets.\r | |
643 | //\r | |
644 | Status = MnpInstanceDeliverPacket (Instance);\r | |
36ee91ca | 645 | \r |
646 | //\r | |
647 | // Dispatch the DPC queued by the NotifyFunction of Token->Event.\r | |
648 | //\r | |
d8d26fb2 | 649 | DispatchDpc ();\r |
8a67d61d | 650 | }\r |
651 | \r | |
652 | ON_EXIT:\r | |
e48e37fc | 653 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 654 | \r |
655 | return Status;\r | |
656 | }\r | |
657 | \r | |
8a67d61d | 658 | /**\r |
b6c4ecad | 659 | Aborts an asynchronous transmit or receive request. \r |
660 | \r | |
661 | The Cancel() function is used to abort a pending transmit or receive request.\r | |
662 | If the token is in the transmit or receive request queues, after calling this\r | |
663 | function, Token.Status will be set to EFI_ABORTED and then Token.Event will be\r | |
664 | signaled. If the token is not in one of the queues, which usually means that\r | |
665 | the asynchronous operation has completed, this function will not signal the\r | |
666 | token and EFI_NOT_FOUND is returned.\r | |
667 | \r | |
3e8c18da | 668 | @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r |
669 | @param[in] Token Pointer to a token that has been issued by\r | |
670 | EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or\r | |
6e4bac4d | 671 | EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all \r |
87f89c08 | 672 | pending tokens are aborted.\r |
8a67d61d | 673 | \r |
674 | @retval EFI_SUCCESS The asynchronous I/O request was aborted and\r | |
b6c4ecad | 675 | Token.Event was signaled. When Token is NULL,\r |
676 | all pending requests were aborted and their\r | |
677 | events were signaled.\r | |
8a67d61d | 678 | @retval EFI_NOT_STARTED This MNP child driver instance has not been\r |
679 | configured.\r | |
680 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
b6c4ecad | 681 | @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O\r |
682 | request was not found in the transmit or\r | |
683 | receive queue. It has either completed or was\r | |
684 | not issued by Transmit() and Receive().\r | |
8a67d61d | 685 | \r |
686 | **/\r | |
687 | EFI_STATUS\r | |
688 | EFIAPI\r | |
689 | MnpCancel (\r | |
690 | IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r | |
691 | IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token OPTIONAL\r | |
692 | )\r | |
693 | {\r | |
694 | EFI_STATUS Status;\r | |
695 | MNP_INSTANCE_DATA *Instance;\r | |
696 | EFI_TPL OldTpl;\r | |
697 | \r | |
698 | if (This == NULL) {\r | |
699 | \r | |
700 | return EFI_INVALID_PARAMETER;\r | |
701 | }\r | |
702 | \r | |
703 | Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r | |
704 | \r | |
e48e37fc | 705 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
8a67d61d | 706 | \r |
707 | if (!Instance->Configured) {\r | |
708 | \r | |
709 | Status = EFI_NOT_STARTED;\r | |
710 | goto ON_EXIT;\r | |
711 | }\r | |
712 | \r | |
713 | //\r | |
714 | // Iterate the RxTokenMap to cancel the specified Token.\r | |
715 | //\r | |
716 | Status = NetMapIterate (&Instance->RxTokenMap, MnpCancelTokens, (VOID *) Token);\r | |
717 | \r | |
718 | if (Token != NULL) {\r | |
719 | \r | |
720 | Status = (Status == EFI_ABORTED) ? EFI_SUCCESS : EFI_NOT_FOUND;\r | |
721 | }\r | |
722 | \r | |
36ee91ca | 723 | //\r |
724 | // Dispatch the DPC queued by the NotifyFunction of the cancled token's events.\r | |
725 | //\r | |
d8d26fb2 | 726 | DispatchDpc ();\r |
36ee91ca | 727 | \r |
8a67d61d | 728 | ON_EXIT:\r |
e48e37fc | 729 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 730 | \r |
731 | return Status;\r | |
732 | }\r | |
733 | \r | |
8a67d61d | 734 | /**\r |
b6c4ecad | 735 | Polls for incoming data packets and processes outgoing data packets. \r |
736 | \r | |
737 | The Poll() function can be used by network drivers and applications to \r | |
738 | increase the rate that data packets are moved between the communications\r | |
739 | device and the transmit and receive queues.\r | |
740 | Normally, a periodic timer event internally calls the Poll() function. But, in\r | |
741 | some systems, the periodic timer event may not call Poll() fast enough to\r | |
742 | transmit and/or receive all data packets without missing packets. Drivers and\r | |
743 | applications that are experiencing packet loss should try calling the Poll()\r | |
744 | function more often.\r | |
745 | \r | |
6e4bac4d | 746 | @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r |
b6c4ecad | 747 | \r |
748 | @retval EFI_SUCCESS Incoming or outgoing data was processed.\r | |
749 | @retval EFI_NOT_STARTED This MNP child driver instance has not been\r | |
750 | configured.\r | |
751 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The\r | |
752 | MNP child driver instance has been reset to startup\r | |
753 | defaults.\r | |
754 | @retval EFI_NOT_READY No incoming or outgoing data was processed. Consider\r | |
755 | increasing the polling rate.\r | |
756 | @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive\r | |
757 | queue. Consider increasing the polling rate.\r | |
8a67d61d | 758 | \r |
759 | **/\r | |
760 | EFI_STATUS\r | |
761 | EFIAPI\r | |
762 | MnpPoll (\r | |
763 | IN EFI_MANAGED_NETWORK_PROTOCOL *This\r | |
764 | )\r | |
765 | {\r | |
766 | EFI_STATUS Status;\r | |
767 | MNP_INSTANCE_DATA *Instance;\r | |
768 | EFI_TPL OldTpl;\r | |
769 | \r | |
770 | if (This == NULL) {\r | |
771 | return EFI_INVALID_PARAMETER;\r | |
772 | }\r | |
773 | \r | |
774 | Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r | |
775 | \r | |
e48e37fc | 776 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
8a67d61d | 777 | \r |
778 | if (!Instance->Configured) {\r | |
779 | Status = EFI_NOT_STARTED;\r | |
780 | goto ON_EXIT;\r | |
781 | }\r | |
782 | \r | |
783 | //\r | |
784 | // Try to receive packets.\r | |
785 | //\r | |
786 | Status = MnpReceivePacket (Instance->MnpServiceData);\r | |
787 | \r | |
a4df47f1 | 788 | //\r |
789 | // Dispatch the DPC queued by the NotifyFunction of rx token's events.\r | |
790 | //\r | |
d8d26fb2 | 791 | DispatchDpc ();\r |
36ee91ca | 792 | \r |
8a67d61d | 793 | ON_EXIT:\r |
e48e37fc | 794 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 795 | \r |
796 | return Status;\r | |
797 | }\r | |
36ee91ca | 798 | \r |