]>
Commit | Line | Data |
---|---|---|
8a67d61d | 1 | /** @file\r |
3e8c18da | 2 | Implementation of Managed Network Protocol public services.\r |
8a67d61d | 3 | \r |
6e4bac4d | 4 | Copyright (c) 2005 - 2007, 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 | |
229 | \r | |
230 | if ((This == NULL) || (IpAddress == NULL) || (MacAddress == NULL)) {\r | |
231 | \r | |
232 | return EFI_INVALID_PARAMETER;\r | |
233 | }\r | |
234 | \r | |
235 | if (Ipv6Flag) {\r | |
236 | //\r | |
237 | // Currently IPv6 isn't supported.\r | |
238 | //\r | |
239 | return EFI_UNSUPPORTED;\r | |
240 | }\r | |
241 | \r | |
242 | if (!IP4_IS_MULTICAST (EFI_NTOHL (*IpAddress))) {\r | |
243 | //\r | |
244 | // The IPv4 address passed in is not a multicast address.\r | |
245 | //\r | |
246 | return EFI_INVALID_PARAMETER;\r | |
247 | }\r | |
248 | \r | |
249 | Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r | |
250 | \r | |
e48e37fc | 251 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
8a67d61d | 252 | \r |
253 | if (!Instance->Configured) {\r | |
254 | \r | |
255 | Status = EFI_NOT_STARTED;\r | |
256 | goto ON_EXIT;\r | |
257 | }\r | |
258 | \r | |
259 | Snp = Instance->MnpServiceData->Snp;\r | |
260 | ASSERT (Snp != NULL);\r | |
261 | \r | |
262 | if (Snp->Mode->IfType == NET_IFTYPE_ETHERNET) {\r | |
263 | //\r | |
264 | // Translate the IPv4 address into a multicast MAC address if the NIC is an\r | |
265 | // ethernet NIC.\r | |
266 | //\r | |
267 | MacAddress->Addr[0] = 0x01;\r | |
268 | MacAddress->Addr[1] = 0x00;\r | |
269 | MacAddress->Addr[2] = 0x5E;\r | |
4eb65aff | 270 | MacAddress->Addr[3] = (UINT8) (IpAddress->v4.Addr[1] & 0x7F);\r |
8a67d61d | 271 | MacAddress->Addr[4] = IpAddress->v4.Addr[2];\r |
272 | MacAddress->Addr[5] = IpAddress->v4.Addr[3];\r | |
273 | \r | |
274 | Status = EFI_SUCCESS;\r | |
275 | } else {\r | |
276 | //\r | |
277 | // Invoke Snp to translate the multicast IP address.\r | |
278 | //\r | |
279 | Status = Snp->MCastIpToMac (\r | |
280 | Snp,\r | |
281 | Ipv6Flag,\r | |
282 | IpAddress,\r | |
283 | MacAddress\r | |
284 | );\r | |
285 | }\r | |
286 | \r | |
287 | ON_EXIT:\r | |
e48e37fc | 288 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 289 | \r |
290 | return Status;\r | |
291 | }\r | |
292 | \r | |
8a67d61d | 293 | /**\r |
b6c4ecad | 294 | Enables and disables receive filters for multicast address. This function may \r |
295 | be unsupported in some MNP implementations.\r | |
296 | \r | |
297 | The Groups() function only adds and removes multicast MAC addresses from the \r | |
298 | filter list. The MNP driver does not transmit or process Internet Group\r | |
299 | Management Protocol (IGMP) packets. If JoinFlag is FALSE and MacAddress is\r | |
300 | NULL, then all joined groups are left.\r | |
301 | \r | |
3e8c18da | 302 | @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r |
303 | @param[in] JoinFlag Set to TRUE to join this multicast group.\r | |
304 | Set to FALSE to leave this multicast group.\r | |
305 | @param[in] MacAddress Pointer to the multicast MAC group (address) to join or\r | |
306 | leave.\r | |
b6c4ecad | 307 | \r |
308 | @retval EFI_SUCCESS The requested operation completed successfully.\r | |
309 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is TRUE:\r | |
310 | * This is NULL.\r | |
311 | * JoinFlag is TRUE and MacAddress is NULL.\r | |
312 | * MacAddress is not a valid multicast MAC\r | |
313 | address.\r | |
314 | * The MNP multicast group settings are\r | |
315 | unchanged.\r | |
316 | @retval EFI_NOT_STARTED This MNP child driver instance has not been\r | |
317 | configured.\r | |
318 | @retval EFI_ALREADY_STARTED The supplied multicast group is already joined.\r | |
319 | @retval EFI_NOT_FOUND The supplied multicast group is not joined.\r | |
320 | @retval EFI_DEVICE_ERROR An unexpected network or system error occurred.\r | |
321 | The MNP child driver instance has been reset to\r | |
322 | startup defaults.\r | |
323 | @retval EFI_UNSUPPORTED The requested feature is unsupported in this MNP\r | |
324 | implementation.\r | |
6e4bac4d | 325 | @retval Others The requested operation could not be completed.\r |
b6c4ecad | 326 | The MNP multicast group settings are unchanged.\r |
8a67d61d | 327 | \r |
328 | **/\r | |
329 | EFI_STATUS\r | |
330 | EFIAPI\r | |
331 | MnpGroups (\r | |
332 | IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r | |
333 | IN BOOLEAN JoinFlag,\r | |
334 | IN EFI_MAC_ADDRESS *MacAddress OPTIONAL\r | |
335 | )\r | |
336 | {\r | |
337 | MNP_INSTANCE_DATA *Instance;\r | |
338 | EFI_SIMPLE_NETWORK_MODE *SnpMode;\r | |
339 | MNP_GROUP_CONTROL_BLOCK *GroupCtrlBlk;\r | |
340 | MNP_GROUP_ADDRESS *GroupAddress;\r | |
e48e37fc | 341 | LIST_ENTRY *ListEntry;\r |
8a67d61d | 342 | BOOLEAN AddressExist;\r |
343 | EFI_TPL OldTpl;\r | |
344 | EFI_STATUS Status;\r | |
345 | \r | |
346 | if (This == NULL || (JoinFlag && (MacAddress == NULL))) {\r | |
347 | //\r | |
348 | // This is NULL, or it's a join operation but MacAddress is NULL.\r | |
349 | //\r | |
350 | return EFI_INVALID_PARAMETER;\r | |
351 | }\r | |
352 | \r | |
353 | Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r | |
354 | SnpMode = Instance->MnpServiceData->Snp->Mode;\r | |
355 | \r | |
e48e37fc | 356 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
8a67d61d | 357 | \r |
358 | if (!Instance->Configured) {\r | |
359 | \r | |
360 | Status = EFI_NOT_STARTED;\r | |
361 | goto ON_EXIT;\r | |
362 | }\r | |
363 | \r | |
364 | if ((!Instance->ConfigData.EnableMulticastReceive) ||\r | |
365 | ((MacAddress != NULL) && !NET_MAC_IS_MULTICAST (MacAddress, &SnpMode->BroadcastAddress, SnpMode->HwAddressSize))) {\r | |
366 | //\r | |
367 | // The instance isn't configured to do mulitcast receive. OR\r | |
368 | // the passed in MacAddress is not a mutlticast mac address.\r | |
369 | //\r | |
370 | Status = EFI_INVALID_PARAMETER;\r | |
371 | goto ON_EXIT;\r | |
372 | }\r | |
373 | \r | |
374 | Status = EFI_SUCCESS;\r | |
375 | AddressExist = FALSE;\r | |
376 | GroupCtrlBlk = NULL;\r | |
377 | \r | |
378 | if (MacAddress != NULL) {\r | |
379 | //\r | |
380 | // Search the instance's GroupCtrlBlkList to find the specific address.\r | |
381 | //\r | |
382 | NET_LIST_FOR_EACH (ListEntry, &Instance->GroupCtrlBlkList) {\r | |
383 | \r | |
384 | GroupCtrlBlk = NET_LIST_USER_STRUCT (\r | |
385 | ListEntry,\r | |
386 | MNP_GROUP_CONTROL_BLOCK,\r | |
387 | CtrlBlkEntry\r | |
388 | );\r | |
389 | GroupAddress = GroupCtrlBlk->GroupAddress;\r | |
e48e37fc | 390 | if (0 == CompareMem (\r |
8a67d61d | 391 | MacAddress,\r |
392 | &GroupAddress->Address,\r | |
393 | SnpMode->HwAddressSize\r | |
394 | )) {\r | |
395 | //\r | |
396 | // There is already the same multicast mac address configured.\r | |
397 | //\r | |
398 | AddressExist = TRUE;\r | |
399 | break;\r | |
400 | }\r | |
401 | }\r | |
402 | \r | |
403 | if (JoinFlag && AddressExist) {\r | |
404 | //\r | |
405 | // The multicast mac address to join already exists.\r | |
406 | //\r | |
407 | Status = EFI_ALREADY_STARTED;\r | |
408 | }\r | |
409 | \r | |
410 | if (!JoinFlag && !AddressExist) {\r | |
411 | //\r | |
412 | // The multicast mac address to leave doesn't exist in this instance.\r | |
413 | //\r | |
414 | Status = EFI_NOT_FOUND;\r | |
415 | }\r | |
416 | \r | |
417 | if (EFI_ERROR (Status)) {\r | |
418 | goto ON_EXIT;\r | |
419 | }\r | |
e48e37fc | 420 | } else if (IsListEmpty (&Instance->GroupCtrlBlkList)) {\r |
8a67d61d | 421 | //\r |
422 | // The MacAddress is NULL and there is no configured multicast mac address,\r | |
423 | // just return.\r | |
424 | //\r | |
425 | goto ON_EXIT;\r | |
426 | }\r | |
427 | \r | |
428 | //\r | |
429 | // OK, it is time to take action.\r | |
430 | //\r | |
431 | Status = MnpGroupOp (Instance, JoinFlag, MacAddress, GroupCtrlBlk);\r | |
432 | \r | |
433 | ON_EXIT:\r | |
e48e37fc | 434 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 435 | \r |
436 | return Status;\r | |
437 | }\r | |
438 | \r | |
8a67d61d | 439 | /**\r |
b6c4ecad | 440 | Places asynchronous outgoing data packets into the transmit queue.\r |
441 | \r | |
442 | The Transmit() function places a completion token into the transmit packet \r | |
443 | queue. This function is always asynchronous.\r | |
444 | The caller must fill in the Token.Event and Token.TxData fields in the\r | |
445 | completion token, and these fields cannot be NULL. When the transmit operation\r | |
446 | completes, the MNP updates the Token.Status field and the Token.Event is\r | |
447 | signaled.\r | |
448 | Note: There may be a performance penalty if the packet needs to be\r | |
449 | defragmented before it can be transmitted by the network device. Systems in\r | |
450 | which performance is critical should review the requirements and features of\r | |
451 | the underlying communications device and drivers.\r | |
452 | \r | |
453 | \r | |
3e8c18da | 454 | @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r |
455 | @param[in] Token Pointer to a token associated with the transmit data\r | |
6e4bac4d | 456 | descriptor. Type EFI_MANAGED_NETWORK_COMPLETION_TOKEN\r |
457 | is defined in "Related Definitions" below.\r | |
b6c4ecad | 458 | \r |
459 | @retval EFI_SUCCESS The transmit completion token was cached.\r | |
8a67d61d | 460 | @retval EFI_NOT_STARTED This MNP child driver instance has not been\r |
461 | configured.\r | |
b6c4ecad | 462 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is\r |
463 | TRUE:\r | |
464 | * This is NULL.\r | |
465 | * Token is NULL.\r | |
466 | * Token.Event is NULL.\r | |
467 | * Token.TxData is NULL.\r | |
468 | * Token.TxData.DestinationAddress is not\r | |
469 | NULL and Token.TxData.HeaderLength is zero.\r | |
470 | * Token.TxData.FragmentCount is zero.\r | |
471 | * (Token.TxData.HeaderLength +\r | |
472 | Token.TxData.DataLength) is not equal to the\r | |
473 | sum of the\r | |
474 | Token.TxData.FragmentTable[].FragmentLength\r | |
475 | fields.\r | |
476 | * One or more of the\r | |
477 | Token.TxData.FragmentTable[].FragmentLength\r | |
478 | fields is zero.\r | |
479 | * One or more of the\r | |
480 | Token.TxData.FragmentTable[].FragmentBufferfields\r | |
481 | is NULL.\r | |
482 | * Token.TxData.DataLength is greater than MTU.\r | |
8a67d61d | 483 | @retval EFI_ACCESS_DENIED The transmit completion token is already in the\r |
484 | transmit queue.\r | |
485 | @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a\r | |
b6c4ecad | 486 | lack of system resources (usually memory). \r |
8a67d61d | 487 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r |
488 | The MNP child driver instance has been reset to\r | |
489 | startup defaults.\r | |
490 | @retval EFI_NOT_READY The transmit request could not be queued because\r | |
491 | the transmit queue is full.\r | |
492 | \r | |
493 | **/\r | |
494 | EFI_STATUS\r | |
495 | EFIAPI\r | |
496 | MnpTransmit (\r | |
497 | IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r | |
498 | IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token\r | |
499 | )\r | |
500 | {\r | |
501 | EFI_STATUS Status;\r | |
502 | MNP_INSTANCE_DATA *Instance;\r | |
503 | MNP_SERVICE_DATA *MnpServiceData;\r | |
504 | UINT8 *PktBuf;\r | |
505 | UINT32 PktLen;\r | |
506 | EFI_TPL OldTpl;\r | |
507 | \r | |
508 | if ((This == NULL) || (Token == NULL)) {\r | |
509 | \r | |
510 | return EFI_INVALID_PARAMETER;\r | |
511 | }\r | |
512 | \r | |
513 | Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r | |
514 | \r | |
e48e37fc | 515 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
8a67d61d | 516 | \r |
517 | if (!Instance->Configured) {\r | |
518 | \r | |
519 | Status = EFI_NOT_STARTED;\r | |
520 | goto ON_EXIT;\r | |
521 | }\r | |
522 | \r | |
523 | if (!MnpIsValidTxToken (Instance, Token)) {\r | |
524 | //\r | |
525 | // The Token is invalid.\r | |
526 | //\r | |
527 | Status = EFI_INVALID_PARAMETER;\r | |
528 | goto ON_EXIT;\r | |
529 | }\r | |
530 | \r | |
531 | MnpServiceData = Instance->MnpServiceData;\r | |
532 | NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);\r | |
533 | \r | |
534 | //\r | |
535 | // Build the tx packet\r | |
536 | //\r | |
537 | MnpBuildTxPacket (MnpServiceData, Token->Packet.TxData, &PktBuf, &PktLen);\r | |
538 | \r | |
539 | //\r | |
540 | // OK, send the packet synchronously.\r | |
541 | //\r | |
542 | Status = MnpSyncSendPacket (MnpServiceData, PktBuf, PktLen, Token);\r | |
543 | \r | |
544 | ON_EXIT:\r | |
e48e37fc | 545 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 546 | \r |
547 | return Status;\r | |
548 | }\r | |
549 | \r | |
550 | \r | |
551 | /**\r | |
b6c4ecad | 552 | Places an asynchronous receiving request into the receiving queue.\r |
553 | \r | |
554 | The Receive() function places a completion token into the receive packet \r | |
555 | queue. This function is always asynchronous.\r | |
556 | The caller must fill in the Token.Event field in the completion token, and\r | |
557 | this field cannot be NULL. When the receive operation completes, the MNP\r | |
558 | updates the Token.Status and Token.RxData fields and the Token.Event is\r | |
559 | signaled.\r | |
560 | \r | |
6e4bac4d | 561 | @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r |
562 | @param[in] Token Pointer to a token associated with the receive\r | |
563 | data descriptor. Type\r | |
564 | EFI_MANAGED_NETWORK_COMPLETION_TOKEN is defined in\r | |
565 | EFI_MANAGED_NETWORK_PROTOCOL.Transmit().\r | |
8a67d61d | 566 | \r |
567 | @retval EFI_SUCCESS The receive completion token was cached.\r | |
568 | @retval EFI_NOT_STARTED This MNP child driver instance has not been\r | |
569 | configured.\r | |
b6c4ecad | 570 | @retval EFI_INVALID_PARAMETER One or more of the following conditions is\r |
571 | TRUE:\r | |
572 | * This is NULL.\r | |
573 | * Token is NULL.\r | |
574 | * Token.Event is NULL\r | |
8a67d61d | 575 | @retval EFI_OUT_OF_RESOURCES The transmit data could not be queued due to a\r |
576 | lack of system resources (usually memory).\r | |
577 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred.\r | |
578 | The MNP child driver instance has been reset to\r | |
579 | startup defaults.\r | |
580 | @retval EFI_ACCESS_DENIED The receive completion token was already in the\r | |
581 | receive queue.\r | |
582 | @retval EFI_NOT_READY The receive request could not be queued because\r | |
583 | the receive queue is full.\r | |
584 | \r | |
585 | **/\r | |
586 | EFI_STATUS\r | |
587 | EFIAPI\r | |
588 | MnpReceive (\r | |
589 | IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r | |
590 | IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token\r | |
591 | )\r | |
592 | {\r | |
593 | EFI_STATUS Status;\r | |
594 | MNP_INSTANCE_DATA *Instance;\r | |
595 | EFI_TPL OldTpl;\r | |
596 | \r | |
597 | if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) {\r | |
598 | \r | |
599 | return EFI_INVALID_PARAMETER;\r | |
600 | }\r | |
601 | \r | |
602 | Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r | |
603 | \r | |
e48e37fc | 604 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
8a67d61d | 605 | \r |
606 | if (!Instance->Configured) {\r | |
607 | \r | |
608 | Status = EFI_NOT_STARTED;\r | |
609 | goto ON_EXIT;\r | |
610 | }\r | |
611 | \r | |
612 | //\r | |
613 | // Check whether this token(event) is already in the rx token queue.\r | |
614 | //\r | |
615 | Status = NetMapIterate (&Instance->RxTokenMap, MnpTokenExist, (VOID *) Token);\r | |
616 | if (EFI_ERROR (Status)) {\r | |
617 | \r | |
618 | goto ON_EXIT;\r | |
619 | }\r | |
620 | \r | |
621 | //\r | |
622 | // Insert the Token into the RxTokenMap.\r | |
623 | //\r | |
624 | Status = NetMapInsertTail (&Instance->RxTokenMap, (VOID *) Token, NULL);\r | |
625 | \r | |
626 | if (!EFI_ERROR (Status)) {\r | |
627 | //\r | |
628 | // Try to deliver any buffered packets.\r | |
629 | //\r | |
630 | Status = MnpInstanceDeliverPacket (Instance);\r | |
36ee91ca | 631 | \r |
632 | //\r | |
633 | // Dispatch the DPC queued by the NotifyFunction of Token->Event.\r | |
634 | //\r | |
635 | NetLibDispatchDpc ();\r | |
8a67d61d | 636 | }\r |
637 | \r | |
638 | ON_EXIT:\r | |
e48e37fc | 639 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 640 | \r |
641 | return Status;\r | |
642 | }\r | |
643 | \r | |
8a67d61d | 644 | /**\r |
b6c4ecad | 645 | Aborts an asynchronous transmit or receive request. \r |
646 | \r | |
647 | The Cancel() function is used to abort a pending transmit or receive request.\r | |
648 | If the token is in the transmit or receive request queues, after calling this\r | |
649 | function, Token.Status will be set to EFI_ABORTED and then Token.Event will be\r | |
650 | signaled. If the token is not in one of the queues, which usually means that\r | |
651 | the asynchronous operation has completed, this function will not signal the\r | |
652 | token and EFI_NOT_FOUND is returned.\r | |
653 | \r | |
3e8c18da | 654 | @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r |
655 | @param[in] Token Pointer to a token that has been issued by\r | |
656 | EFI_MANAGED_NETWORK_PROTOCOL.Transmit() or\r | |
6e4bac4d | 657 | EFI_MANAGED_NETWORK_PROTOCOL.Receive(). If NULL, all \r |
658 | pending tokens are aborted.\r | |
8a67d61d | 659 | \r |
660 | @retval EFI_SUCCESS The asynchronous I/O request was aborted and\r | |
b6c4ecad | 661 | Token.Event was signaled. When Token is NULL,\r |
662 | all pending requests were aborted and their\r | |
663 | events were signaled.\r | |
8a67d61d | 664 | @retval EFI_NOT_STARTED This MNP child driver instance has not been\r |
665 | configured.\r | |
666 | @retval EFI_INVALID_PARAMETER This is NULL.\r | |
b6c4ecad | 667 | @retval EFI_NOT_FOUND When Token is not NULL, the asynchronous I/O\r |
668 | request was not found in the transmit or\r | |
669 | receive queue. It has either completed or was\r | |
670 | not issued by Transmit() and Receive().\r | |
8a67d61d | 671 | \r |
672 | **/\r | |
673 | EFI_STATUS\r | |
674 | EFIAPI\r | |
675 | MnpCancel (\r | |
676 | IN EFI_MANAGED_NETWORK_PROTOCOL *This,\r | |
677 | IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token OPTIONAL\r | |
678 | )\r | |
679 | {\r | |
680 | EFI_STATUS Status;\r | |
681 | MNP_INSTANCE_DATA *Instance;\r | |
682 | EFI_TPL OldTpl;\r | |
683 | \r | |
684 | if (This == NULL) {\r | |
685 | \r | |
686 | return EFI_INVALID_PARAMETER;\r | |
687 | }\r | |
688 | \r | |
689 | Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r | |
690 | \r | |
e48e37fc | 691 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
8a67d61d | 692 | \r |
693 | if (!Instance->Configured) {\r | |
694 | \r | |
695 | Status = EFI_NOT_STARTED;\r | |
696 | goto ON_EXIT;\r | |
697 | }\r | |
698 | \r | |
699 | //\r | |
700 | // Iterate the RxTokenMap to cancel the specified Token.\r | |
701 | //\r | |
702 | Status = NetMapIterate (&Instance->RxTokenMap, MnpCancelTokens, (VOID *) Token);\r | |
703 | \r | |
704 | if (Token != NULL) {\r | |
705 | \r | |
706 | Status = (Status == EFI_ABORTED) ? EFI_SUCCESS : EFI_NOT_FOUND;\r | |
707 | }\r | |
708 | \r | |
36ee91ca | 709 | //\r |
710 | // Dispatch the DPC queued by the NotifyFunction of the cancled token's events.\r | |
711 | //\r | |
712 | NetLibDispatchDpc ();\r | |
713 | \r | |
8a67d61d | 714 | ON_EXIT:\r |
e48e37fc | 715 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 716 | \r |
717 | return Status;\r | |
718 | }\r | |
719 | \r | |
8a67d61d | 720 | /**\r |
b6c4ecad | 721 | Polls for incoming data packets and processes outgoing data packets. \r |
722 | \r | |
723 | The Poll() function can be used by network drivers and applications to \r | |
724 | increase the rate that data packets are moved between the communications\r | |
725 | device and the transmit and receive queues.\r | |
726 | Normally, a periodic timer event internally calls the Poll() function. But, in\r | |
727 | some systems, the periodic timer event may not call Poll() fast enough to\r | |
728 | transmit and/or receive all data packets without missing packets. Drivers and\r | |
729 | applications that are experiencing packet loss should try calling the Poll()\r | |
730 | function more often.\r | |
731 | \r | |
6e4bac4d | 732 | @param[in] This Pointer to the EFI_MANAGED_NETWORK_PROTOCOL instance.\r |
b6c4ecad | 733 | \r |
734 | @retval EFI_SUCCESS Incoming or outgoing data was processed.\r | |
735 | @retval EFI_NOT_STARTED This MNP child driver instance has not been\r | |
736 | configured.\r | |
737 | @retval EFI_DEVICE_ERROR An unexpected system or network error occurred. The\r | |
738 | MNP child driver instance has been reset to startup\r | |
739 | defaults.\r | |
740 | @retval EFI_NOT_READY No incoming or outgoing data was processed. Consider\r | |
741 | increasing the polling rate.\r | |
742 | @retval EFI_TIMEOUT Data was dropped out of the transmit and/or receive\r | |
743 | queue. Consider increasing the polling rate.\r | |
8a67d61d | 744 | \r |
745 | **/\r | |
746 | EFI_STATUS\r | |
747 | EFIAPI\r | |
748 | MnpPoll (\r | |
749 | IN EFI_MANAGED_NETWORK_PROTOCOL *This\r | |
750 | )\r | |
751 | {\r | |
752 | EFI_STATUS Status;\r | |
753 | MNP_INSTANCE_DATA *Instance;\r | |
754 | EFI_TPL OldTpl;\r | |
755 | \r | |
756 | if (This == NULL) {\r | |
757 | return EFI_INVALID_PARAMETER;\r | |
758 | }\r | |
759 | \r | |
760 | Instance = MNP_INSTANCE_DATA_FROM_THIS (This);\r | |
761 | \r | |
e48e37fc | 762 | OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r |
8a67d61d | 763 | \r |
764 | if (!Instance->Configured) {\r | |
765 | Status = EFI_NOT_STARTED;\r | |
766 | goto ON_EXIT;\r | |
767 | }\r | |
768 | \r | |
769 | //\r | |
770 | // Try to receive packets.\r | |
771 | //\r | |
772 | Status = MnpReceivePacket (Instance->MnpServiceData);\r | |
773 | \r | |
36ee91ca | 774 | NetLibDispatchDpc ();\r |
775 | \r | |
8a67d61d | 776 | ON_EXIT:\r |
e48e37fc | 777 | gBS->RestoreTPL (OldTpl);\r |
8a67d61d | 778 | \r |
779 | return Status;\r | |
780 | }\r | |
36ee91ca | 781 | \r |