TianoCore EDK2 master
Loading...
Searching...
No Matches
MnpMain.c
Go to the documentation of this file.
1
9#include "MnpImpl.h"
10
37EFIAPI
40 OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL,
41 OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL
42 )
43{
44 MNP_INSTANCE_DATA *Instance;
46 EFI_TPL OldTpl;
47 EFI_STATUS Status;
48 UINT32 InterruptStatus;
49
50 if (This == NULL) {
51 return EFI_INVALID_PARAMETER;
52 }
53
54 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
55
56 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
57
58 if (MnpConfigData != NULL) {
59 //
60 // Copy the instance configuration data.
61 //
62 CopyMem (MnpConfigData, &Instance->ConfigData, sizeof (*MnpConfigData));
63 }
64
65 if (SnpModeData != NULL) {
66 //
67 // Copy the underlayer Snp mode data.
68 //
69 Snp = Instance->MnpServiceData->MnpDeviceData->Snp;
70
71 //
72 // Upon successful return of GetStatus(), the Snp->Mode->MediaPresent
73 // will be updated to reflect any change of media status
74 //
75 Snp->GetStatus (Snp, &InterruptStatus, NULL);
76 CopyMem (SnpModeData, Snp->Mode, sizeof (*SnpModeData));
77 }
78
79 if (!Instance->Configured) {
80 Status = EFI_NOT_STARTED;
81 } else {
82 Status = EFI_SUCCESS;
83 }
84
85 gBS->RestoreTPL (OldTpl);
86
87 return Status;
88}
89
143EFIAPI
146 IN EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL
147 )
148{
149 MNP_INSTANCE_DATA *Instance;
150 EFI_TPL OldTpl;
151 EFI_STATUS Status;
152
153 if ((This == NULL) ||
154 ((MnpConfigData != NULL) &&
155 (MnpConfigData->ProtocolTypeFilter > 0) &&
156 (MnpConfigData->ProtocolTypeFilter <= 1500))
157 )
158 {
159 return EFI_INVALID_PARAMETER;
160 }
161
162 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
163
164 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
165
166 if ((MnpConfigData == NULL) && (!Instance->Configured)) {
167 //
168 // If the instance is not configured and a reset is requested, just return.
169 //
170 Status = EFI_SUCCESS;
171 goto ON_EXIT;
172 }
173
174 //
175 // Configure the instance.
176 //
177 Status = MnpConfigureInstance (Instance, MnpConfigData);
178
179ON_EXIT:
180 gBS->RestoreTPL (OldTpl);
181
182 return Status;
183}
184
216EFIAPI
219 IN BOOLEAN Ipv6Flag,
220 IN EFI_IP_ADDRESS *IpAddress,
221 OUT EFI_MAC_ADDRESS *MacAddress
222 )
223{
224 EFI_STATUS Status;
225 MNP_INSTANCE_DATA *Instance;
227 EFI_TPL OldTpl;
228 EFI_IPv6_ADDRESS *Ip6Address;
229
230 if ((This == NULL) || (IpAddress == NULL) || (MacAddress == NULL)) {
231 return EFI_INVALID_PARAMETER;
232 }
233
234 Ip6Address = &IpAddress->v6;
235
236 if ((Ipv6Flag && !IP6_IS_MULTICAST (Ip6Address)) ||
237 (!Ipv6Flag && !IP4_IS_MULTICAST (EFI_NTOHL (*IpAddress)))
238 )
239 {
240 //
241 // The IP address passed in is not a multicast address.
242 //
243 return EFI_INVALID_PARAMETER;
244 }
245
246 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
247
248 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
249
250 if (!Instance->Configured) {
251 Status = EFI_NOT_STARTED;
252 goto ON_EXIT;
253 }
254
255 Snp = Instance->MnpServiceData->MnpDeviceData->Snp;
256 ASSERT (Snp != NULL);
257
258 ZeroMem (MacAddress, sizeof (EFI_MAC_ADDRESS));
259
260 if (Snp->Mode->IfType == NET_IFTYPE_ETHERNET) {
261 if (!Ipv6Flag) {
262 //
263 // Translate the IPv4 address into a multicast MAC address if the NIC is an
264 // ethernet NIC according to RFC1112..
265 //
266 MacAddress->Addr[0] = 0x01;
267 MacAddress->Addr[1] = 0x00;
268 MacAddress->Addr[2] = 0x5E;
269 MacAddress->Addr[3] = (UINT8)(IpAddress->v4.Addr[1] & 0x7F);
270 MacAddress->Addr[4] = IpAddress->v4.Addr[2];
271 MacAddress->Addr[5] = IpAddress->v4.Addr[3];
272 } else {
273 //
274 // Translate the IPv6 address into a multicast MAC address if the NIC is an
275 // ethernet NIC according to RFC2464.
276 //
277
278 MacAddress->Addr[0] = 0x33;
279 MacAddress->Addr[1] = 0x33;
280 MacAddress->Addr[2] = Ip6Address->Addr[12];
281 MacAddress->Addr[3] = Ip6Address->Addr[13];
282 MacAddress->Addr[4] = Ip6Address->Addr[14];
283 MacAddress->Addr[5] = Ip6Address->Addr[15];
284 }
285
286 Status = EFI_SUCCESS;
287 } else {
288 //
289 // Invoke Snp to translate the multicast IP address.
290 //
291 Status = Snp->MCastIpToMac (
292 Snp,
293 Ipv6Flag,
294 IpAddress,
295 MacAddress
296 );
297 }
298
299ON_EXIT:
300 gBS->RestoreTPL (OldTpl);
301
302 return Status;
303}
304
342EFIAPI
345 IN BOOLEAN JoinFlag,
346 IN EFI_MAC_ADDRESS *MacAddress OPTIONAL
347 )
348{
349 MNP_INSTANCE_DATA *Instance;
351 MNP_GROUP_CONTROL_BLOCK *GroupCtrlBlk;
352 MNP_GROUP_ADDRESS *GroupAddress;
353 LIST_ENTRY *ListEntry;
354 BOOLEAN AddressExist;
355 EFI_TPL OldTpl;
356 EFI_STATUS Status;
357
358 if ((This == NULL) || (JoinFlag && (MacAddress == NULL))) {
359 //
360 // This is NULL, or it's a join operation but MacAddress is NULL.
361 //
362 return EFI_INVALID_PARAMETER;
363 }
364
365 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
366 SnpMode = Instance->MnpServiceData->MnpDeviceData->Snp->Mode;
367
368 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
369
370 if (!Instance->Configured) {
371 Status = EFI_NOT_STARTED;
372 goto ON_EXIT;
373 }
374
375 if ((!Instance->ConfigData.EnableMulticastReceive) ||
376 ((MacAddress != NULL) && !NET_MAC_IS_MULTICAST (MacAddress, &SnpMode->BroadcastAddress, SnpMode->HwAddressSize)))
377 {
378 //
379 // The instance isn't configured to do multicast receive. OR
380 // the passed in MacAddress is not a multicast mac address.
381 //
382 Status = EFI_INVALID_PARAMETER;
383 goto ON_EXIT;
384 }
385
386 Status = EFI_SUCCESS;
387 AddressExist = FALSE;
388 GroupCtrlBlk = NULL;
389
390 if (MacAddress != NULL) {
391 //
392 // Search the instance's GroupCtrlBlkList to find the specific address.
393 //
394 NET_LIST_FOR_EACH (ListEntry, &Instance->GroupCtrlBlkList) {
395 GroupCtrlBlk = NET_LIST_USER_STRUCT (
396 ListEntry,
398 CtrlBlkEntry
399 );
400 GroupAddress = GroupCtrlBlk->GroupAddress;
401 if (0 == CompareMem (
402 MacAddress,
403 &GroupAddress->Address,
404 SnpMode->HwAddressSize
405 ))
406 {
407 //
408 // There is already the same multicast mac address configured.
409 //
410 AddressExist = TRUE;
411 break;
412 }
413 }
414
415 if (JoinFlag && AddressExist) {
416 //
417 // The multicast mac address to join already exists.
418 //
419 Status = EFI_ALREADY_STARTED;
420 }
421
422 if (!JoinFlag && !AddressExist) {
423 //
424 // The multicast mac address to leave doesn't exist in this instance.
425 //
426 Status = EFI_NOT_FOUND;
427 }
428
429 if (EFI_ERROR (Status)) {
430 goto ON_EXIT;
431 }
432 } else if (IsListEmpty (&Instance->GroupCtrlBlkList)) {
433 //
434 // The MacAddress is NULL and there is no configured multicast mac address,
435 // just return.
436 //
437 goto ON_EXIT;
438 }
439
440 //
441 // OK, it is time to take action.
442 //
443 Status = MnpGroupOp (Instance, JoinFlag, MacAddress, GroupCtrlBlk);
444
445ON_EXIT:
446 gBS->RestoreTPL (OldTpl);
447
448 return Status;
449}
450
507EFIAPI
511 )
512{
513 EFI_STATUS Status;
514 MNP_INSTANCE_DATA *Instance;
515 MNP_SERVICE_DATA *MnpServiceData;
516 UINT8 *PktBuf;
517 UINT32 PktLen;
518 EFI_TPL OldTpl;
519
520 if ((This == NULL) || (Token == NULL)) {
521 return EFI_INVALID_PARAMETER;
522 }
523
524 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
525
526 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
527
528 if (!Instance->Configured) {
529 Status = EFI_NOT_STARTED;
530 goto ON_EXIT;
531 }
532
533 if (!MnpIsValidTxToken (Instance, Token)) {
534 //
535 // The Token is invalid.
536 //
537 Status = EFI_INVALID_PARAMETER;
538 goto ON_EXIT;
539 }
540
541 MnpServiceData = Instance->MnpServiceData;
542 NET_CHECK_SIGNATURE (MnpServiceData, MNP_SERVICE_DATA_SIGNATURE);
543
544 //
545 // Build the tx packet
546 //
547 Status = MnpBuildTxPacket (MnpServiceData, Token->Packet.TxData, &PktBuf, &PktLen);
548 if (EFI_ERROR (Status)) {
549 goto ON_EXIT;
550 }
551
552 //
553 // OK, send the packet synchronously.
554 //
555 Status = MnpSyncSendPacket (MnpServiceData, PktBuf, PktLen, Token);
556
557ON_EXIT:
558 gBS->RestoreTPL (OldTpl);
559
560 return Status;
561}
562
599EFIAPI
603 )
604{
605 EFI_STATUS Status;
606 MNP_INSTANCE_DATA *Instance;
607 EFI_TPL OldTpl;
608
609 if ((This == NULL) || (Token == NULL) || (Token->Event == NULL)) {
610 return EFI_INVALID_PARAMETER;
611 }
612
613 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
614
615 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
616
617 if (!Instance->Configured) {
618 Status = EFI_NOT_STARTED;
619 goto ON_EXIT;
620 }
621
622 //
623 // Check whether this token(event) is already in the rx token queue.
624 //
625 Status = NetMapIterate (&Instance->RxTokenMap, MnpTokenExist, (VOID *)Token);
626 if (EFI_ERROR (Status)) {
627 goto ON_EXIT;
628 }
629
630 //
631 // Insert the Token into the RxTokenMap.
632 //
633 Status = NetMapInsertTail (&Instance->RxTokenMap, (VOID *)Token, NULL);
634 if (!EFI_ERROR (Status)) {
635 //
636 // Try to deliver any buffered packets.
637 //
638 Status = MnpInstanceDeliverPacket (Instance);
639
640 //
641 // Dispatch the DPC queued by the NotifyFunction of Token->Event.
642 //
643 DispatchDpc ();
644 }
645
646ON_EXIT:
647 gBS->RestoreTPL (OldTpl);
648
649 return Status;
650}
651
682EFIAPI
686 )
687{
688 EFI_STATUS Status;
689 MNP_INSTANCE_DATA *Instance;
690 EFI_TPL OldTpl;
691
692 if (This == NULL) {
693 return EFI_INVALID_PARAMETER;
694 }
695
696 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
697
698 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
699
700 if (!Instance->Configured) {
701 Status = EFI_NOT_STARTED;
702 goto ON_EXIT;
703 }
704
705 //
706 // Iterate the RxTokenMap to cancel the specified Token.
707 //
708 Status = NetMapIterate (&Instance->RxTokenMap, MnpCancelTokens, (VOID *)Token);
709 if (Token != NULL) {
710 Status = (Status == EFI_ABORTED) ? EFI_SUCCESS : EFI_NOT_FOUND;
711 }
712
713 //
714 // Dispatch the DPC queued by the NotifyFunction of the canceled token's events.
715 //
716 DispatchDpc ();
717
718ON_EXIT:
719 gBS->RestoreTPL (OldTpl);
720
721 return Status;
722}
723
751EFIAPI
754 )
755{
756 EFI_STATUS Status;
757 MNP_INSTANCE_DATA *Instance;
758 EFI_TPL OldTpl;
759
760 if (This == NULL) {
761 return EFI_INVALID_PARAMETER;
762 }
763
764 Instance = MNP_INSTANCE_DATA_FROM_THIS (This);
765
766 OldTpl = gBS->RaiseTPL (TPL_CALLBACK);
767
768 if (!Instance->Configured) {
769 Status = EFI_NOT_STARTED;
770 goto ON_EXIT;
771 }
772
773 //
774 // Try to receive packets.
775 //
776 Status = MnpReceivePacket (Instance->MnpServiceData->MnpDeviceData);
777
778 //
779 // Dispatch the DPC queued by the NotifyFunction of rx token's events.
780 //
781 DispatchDpc ();
782
783ON_EXIT:
784 gBS->RestoreTPL (OldTpl);
785
786 return Status;
787}
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
Definition: LinkedList.c:403
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS EFIAPI DispatchDpc(VOID)
Definition: DpcLib.c:86
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS EFIAPI MnpCancelTokens(IN OUT NET_MAP *Map, IN OUT NET_MAP_ITEM *Item, IN VOID *Arg)
Definition: MnpConfig.c:1063
EFI_STATUS MnpGroupOp(IN OUT MNP_INSTANCE_DATA *Instance, IN BOOLEAN JoinFlag, IN EFI_MAC_ADDRESS *MacAddress OPTIONAL, IN MNP_GROUP_CONTROL_BLOCK *CtrlBlk OPTIONAL)
Definition: MnpConfig.c:1816
EFI_STATUS EFIAPI MnpTokenExist(IN NET_MAP *Map, IN NET_MAP_ITEM *Item, IN VOID *Arg)
Definition: MnpConfig.c:1023
EFI_STATUS MnpConfigureInstance(IN OUT MNP_INSTANCE_DATA *Instance, IN EFI_MANAGED_NETWORK_CONFIG_DATA *ConfigData OPTIONAL)
Definition: MnpConfig.c:1404
EFI_STATUS MnpSyncSendPacket(IN MNP_SERVICE_DATA *MnpServiceData, IN UINT8 *Packet, IN UINT32 Length, IN OUT EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token)
Definition: MnpIo.c:206
EFI_STATUS MnpReceivePacket(IN OUT MNP_DEVICE_DATA *MnpDeviceData)
Definition: MnpIo.c:828
EFI_STATUS MnpInstanceDeliverPacket(IN OUT MNP_INSTANCE_DATA *Instance)
Definition: MnpIo.c:306
BOOLEAN MnpIsValidTxToken(IN MNP_INSTANCE_DATA *Instance, IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token)
Definition: MnpIo.c:22
EFI_STATUS MnpBuildTxPacket(IN MNP_SERVICE_DATA *MnpServiceData, IN EFI_MANAGED_NETWORK_TRANSMIT_DATA *TxData, OUT UINT8 **PktBuf, OUT UINT32 *PktLen)
Definition: MnpIo.c:112
EFI_STATUS EFIAPI MnpMcastIpToMac(IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN BOOLEAN Ipv6Flag, IN EFI_IP_ADDRESS *IpAddress, OUT EFI_MAC_ADDRESS *MacAddress)
Definition: MnpMain.c:217
EFI_STATUS EFIAPI MnpTransmit(IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token)
Definition: MnpMain.c:508
EFI_STATUS EFIAPI MnpGetModeData(IN EFI_MANAGED_NETWORK_PROTOCOL *This, OUT EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL, OUT EFI_SIMPLE_NETWORK_MODE *SnpModeData OPTIONAL)
Definition: MnpMain.c:38
EFI_STATUS EFIAPI MnpConfigure(IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN EFI_MANAGED_NETWORK_CONFIG_DATA *MnpConfigData OPTIONAL)
Definition: MnpMain.c:144
EFI_STATUS EFIAPI MnpReceive(IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token)
Definition: MnpMain.c:600
EFI_STATUS EFIAPI MnpCancel(IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN EFI_MANAGED_NETWORK_COMPLETION_TOKEN *Token OPTIONAL)
Definition: MnpMain.c:683
EFI_STATUS EFIAPI MnpPoll(IN EFI_MANAGED_NETWORK_PROTOCOL *This)
Definition: MnpMain.c:752
EFI_STATUS EFIAPI MnpGroups(IN EFI_MANAGED_NETWORK_PROTOCOL *This, IN BOOLEAN JoinFlag, IN EFI_MAC_ADDRESS *MacAddress OPTIONAL)
Definition: MnpMain.c:343
EFI_STATUS EFIAPI NetMapInsertTail(IN OUT NET_MAP *Map, IN VOID *Key, IN VOID *Value OPTIONAL)
Definition: DxeNetLib.c:1556
EFI_STATUS EFIAPI NetMapIterate(IN NET_MAP *Map, IN NET_MAP_CALLBACK CallBack, IN VOID *Arg OPTIONAL)
Definition: DxeNetLib.c:1800
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
UINTN EFI_TPL
Definition: UefiBaseType.h:41
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_SIMPLE_NETWORK_MODE * Mode
EFI_MAC_ADDRESS BroadcastAddress