165 Token->Signature = IP4_FRAME_TX_SIGNATURE;
168 Token->Interface = Interface;
169 Token->IpInstance = IpInstance;
171 Token->CallBack = CallBack;
172 Token->Packet = Packet;
173 Token->Context = Context;
174 CopyMem (&Token->DstMac, &mZeroMacAddress, sizeof (Token->DstMac));
175 CopyMem (&Token->SrcMac, &Interface->Mac, sizeof (Token->SrcMac));
177 MnpToken = &(Token->MnpToken);
178 MnpToken->
Status = EFI_NOT_READY;
180 Status =
gBS->CreateEvent (
188 if (EFI_ERROR (Status)) {
193 MnpTxData = &Token->MnpTxData;
194 MnpToken->Packet.
TxData = MnpTxData;
196 MnpTxData->DestinationAddress = &Token->DstMac;
197 MnpTxData->SourceAddress = &Token->SrcMac;
198 MnpTxData->ProtocolType = IP4_ETHER_PROTO;
199 MnpTxData->DataLength = Packet->TotalSize;
200 MnpTxData->HeaderLength = 0;
202 Count = Packet->BlockOpNum;
205 MnpTxData->FragmentCount = (UINT16)Count;
222 NET_CHECK_SIGNATURE (Token, IP4_FRAME_TX_SIGNATURE);
224 gBS->CloseEvent (Token->MnpToken.Event);
249 if (ArpQue ==
NULL) {
253 ArpQue->Signature = IP4_FRAME_ARP_SIGNATURE;
257 ArpQue->Interface = Interface;
259 Status =
gBS->CreateEvent (
267 if (EFI_ERROR (Status)) {
273 CopyMem (&ArpQue->Mac, &mZeroMacAddress, sizeof (ArpQue->Mac));
292 NET_CHECK_SIGNATURE (ArpQue, IP4_FRAME_ARP_SIGNATURE);
299 gBS->CloseEvent (ArpQue->OnResolved);
332 Token->Signature = IP4_FRAME_RX_SIGNATURE;
333 Token->Interface = Interface;
334 Token->IpInstance = IpInstance;
335 Token->CallBack = CallBack;
336 Token->Context = Context;
338 MnpToken = &Token->MnpToken;
339 MnpToken->
Status = EFI_NOT_READY;
341 Status =
gBS->CreateEvent (
349 if (EFI_ERROR (Status)) {
370 NET_CHECK_SIGNATURE (Token, IP4_FRAME_RX_SIGNATURE);
372 gBS->CloseEvent (Token->MnpToken.Event);
399 NET_LIST_FOR_EACH_SAFE (Entry, Next, &ArpQue->Frames) {
402 if ((FrameToCancel ==
NULL) || FrameToCancel (Token, Context)) {
405 Token->CallBack (Token->IpInstance, Token->Packet, IoStatus, 0, Token->Context);
440 NET_LIST_FOR_EACH_SAFE (Entry, Next, &Interface->ArpQues) {
441 ArpQue = NET_LIST_USER_STRUCT (Entry,
IP4_ARP_QUE, Link);
446 Interface->Arp->Cancel (Interface->Arp, &ArpQue->Ip, ArpQue->OnResolved);
454 NET_LIST_FOR_EACH_SAFE (Entry, Next, &Interface->SentFrames) {
457 if ((FrameToCancel ==
NULL) || FrameToCancel (Token, Context)) {
458 Interface->Mnp->Cancel (Interface->Mnp, &Token->MnpToken);
492 if (Interface ==
NULL) {
496 Interface->Signature = IP4_INTERFACE_SIGNATURE;
498 Interface->RefCnt = 1;
500 Interface->Ip = IP4_ALLZERO_ADDRESS;
501 Interface->SubnetMask = IP4_ALLZERO_ADDRESS;
502 Interface->Configured =
FALSE;
504 Interface->Controller = Controller;
505 Interface->Image = ImageHandle;
506 Interface->Mnp = Mnp;
507 Interface->Arp =
NULL;
508 Interface->ArpHandle =
NULL;
513 Interface->RecvRequest =
NULL;
518 if (EFI_ERROR (Mnp->GetModeData (Mnp,
NULL, &SnpMode))) {
528 Interface->PromiscRecv =
FALSE;
550 IN IP4_ADDR SubnetMask
556 NET_CHECK_SIGNATURE (Interface, IP4_INTERFACE_SIGNATURE);
566 Interface->Ip = IpAddr;
567 Interface->SubnetMask = SubnetMask;
568 Interface->SubnetBrdcast = (IpAddr | ~SubnetMask);
569 Interface->NetBrdcast = (IpAddr | ~SubnetMask);
574 if (Interface->ArpHandle !=
NULL) {
575 if (Interface->Arp !=
NULL) {
577 Interface->ArpHandle,
578 &gEfiArpProtocolGuid,
580 Interface->Controller
583 Interface->Arp =
NULL;
587 Interface->Controller,
589 &gEfiArpServiceBindingProtocolGuid,
593 Interface->ArpHandle =
NULL;
600 if (IpAddr != IP4_ALLZERO_ADDRESS) {
602 Interface->Controller,
604 &gEfiArpServiceBindingProtocolGuid,
605 &Interface->ArpHandle
608 if (EFI_ERROR (Status)) {
612 Status =
gBS->OpenProtocol (
613 Interface->ArpHandle,
614 &gEfiArpProtocolGuid,
615 (VOID **)&Interface->Arp,
617 Interface->Controller,
618 EFI_OPEN_PROTOCOL_BY_DRIVER
621 if (EFI_ERROR (Status)) {
625 IpAddr = HTONL (IpAddr);
633 Status = Interface->Arp->Configure (Interface->Arp, &ArpConfig);
635 if (EFI_ERROR (Status)) {
637 Interface->ArpHandle,
638 &gEfiArpProtocolGuid,
640 Interface->Controller
647 Interface->Configured =
TRUE;
652 Interface->Controller,
654 &gEfiArpServiceBindingProtocolGuid,
706 if ((Token = Interface->RecvRequest) !=
NULL) {
707 OldTpl =
gBS->RaiseTPL (TPL_CALLBACK);
709 Interface->RecvRequest =
NULL;
710 Interface->Mnp->Cancel (Interface->Mnp, &Token->MnpToken);
712 gBS->RestoreTPL (OldTpl);
736 NET_CHECK_SIGNATURE (Interface, IP4_INTERFACE_SIGNATURE);
737 ASSERT (Interface->RefCnt > 0);
744 if (--Interface->RefCnt > 0) {
761 if (Interface->Arp !=
NULL) {
763 Interface->ArpHandle,
764 &gEfiArpProtocolGuid,
766 Interface->Controller
770 Interface->Controller,
772 &gEfiArpServiceBindingProtocolGuid,
809 NET_LIST_FOR_EACH_SAFE (Entry, Next, &ArpQue->Frames) {
812 ASSERT (Token->Interface->SubnetMask == IP4_ALLONE_ADDRESS);
817 if (Token->IpInstance !=
NULL) {
818 RtCacheEntry =
Ip4FindRouteCache (Token->IpInstance->RouteTable, NTOHL (ArpQue->Ip), Token->Interface->Ip);
821 if (RtCacheEntry ==
NULL) {
822 RtCacheEntry =
Ip4FindRouteCache (Token->IpSb->DefaultRouteTable, NTOHL (ArpQue->Ip), Token->Interface->Ip);
825 if (RtCacheEntry ==
NULL) {
826 Status = EFI_NO_MAPPING;
831 if (DefaultRoute ==
NULL) {
832 Status = EFI_NO_MAPPING;
839 Gateway = DefaultRoute->NextHop;
840 if (ArpQue->Ip == Gateway) {
844 Status = EFI_NO_MAPPING;
848 RtCacheEntry->NextHop = Gateway;
849 Status =
Ip4SendFrame (Token->Interface, Token->IpInstance, Token->Packet, Gateway, Token->CallBack, Token->Context, Token->IpSb);
850 if (EFI_ERROR (Status)) {
851 Status = EFI_NO_MAPPING;
861 if (RtCacheEntry !=
NULL) {
865 Token->CallBack (Token->IpInstance, Token->Packet, Status, 0, Token->Context);
894 NET_CHECK_SIGNATURE (ArpQue, IP4_FRAME_ARP_SIGNATURE);
901 if (NET_MAC_EQUAL (&ArpQue->Mac, &mZeroMacAddress, ArpQue->Interface->HwaddrLen)) {
902 if (ArpQue->Interface->SubnetMask != IP4_ALLONE_ADDRESS) {
907 IoStatus = EFI_NO_MAPPING;
925 Interface = ArpQue->Interface;
927 NET_LIST_FOR_EACH_SAFE (Entry, Next, &ArpQue->Frames) {
931 CopyMem (&Token->DstMac, &ArpQue->Mac, sizeof (Token->DstMac));
942 Status = Interface->Mnp->Transmit (Interface->Mnp, &Token->MnpToken);
943 if (EFI_ERROR (Status)) {
945 Token->CallBack (Token->IpInstance, Token->Packet, Status, 0, Token->Context);
993 NET_CHECK_SIGNATURE (Token, IP4_FRAME_TX_SIGNATURE);
1056 IN IP4_ADDR NextHop,
1068 ASSERT (Interface->Configured);
1072 if (Token ==
NULL) {
1073 return EFI_OUT_OF_RESOURCES;
1082 if (NextHop == IP4_ALLONE_ADDRESS) {
1083 CopyMem (&Token->DstMac, &Interface->BroadcastMac, sizeof (Token->DstMac));
1085 }
else if (IP4_IS_MULTICAST (NextHop)) {
1088 if (EFI_ERROR (Status)) {
1098 if ((Arp = Interface->Arp) ==
NULL) {
1099 Status = EFI_NO_MAPPING;
1106 NextHop = HTONL (NextHop);
1107 Status = Arp->Request (Arp, &NextHop,
NULL, &Token->DstMac);
1111 }
else if (Status != EFI_NOT_READY) {
1121 NET_LIST_FOR_EACH (Entry, &Interface->ArpQues) {
1122 ArpQue = NET_LIST_USER_STRUCT (Entry,
IP4_ARP_QUE, Link);
1124 if (ArpQue->Ip == NextHop) {
1132 if (Entry != &Interface->ArpQues) {
1142 if (ArpQue ==
NULL) {
1143 Status = EFI_OUT_OF_RESOURCES;
1147 Status = Arp->Request (Arp, &ArpQue->Ip, ArpQue->OnResolved, ArpQue->Mac.Addr);
1149 if (EFI_ERROR (Status) && (Status != EFI_NOT_READY)) {
1164 Status = Interface->Mnp->Transmit (Interface->Mnp, &Token->MnpToken);
1165 if (EFI_ERROR (Status)) {
1193 NET_CHECK_SIGNATURE (Frame, IP4_FRAME_RX_SIGNATURE);
1195 gBS->SignalEvent (Frame->MnpToken.Packet.
RxData->RecycleEvent);
1224 NET_CHECK_SIGNATURE (Token, IP4_FRAME_RX_SIGNATURE);
1230 Token->Interface->RecvRequest =
NULL;
1232 MnpToken = &Token->MnpToken;
1233 MnpRxData = MnpToken->Packet.
RxData;
1235 if (EFI_ERROR (MnpToken->
Status) || (MnpRxData ==
NULL)) {
1236 Token->CallBack (Token->IpInstance,
NULL, MnpToken->
Status, 0, Token->Context);
1246 Netfrag.Len = MnpRxData->DataLength;
1247 Netfrag.Bulk = MnpRxData->PacketData;
1251 if (Packet ==
NULL) {
1252 gBS->SignalEvent (MnpRxData->RecycleEvent);
1254 Token->CallBack (Token->IpInstance,
NULL, EFI_OUT_OF_RESOURCES, 0, Token->Context);
1260 Flag = (MnpRxData->BroadcastFlag ? IP4_LINK_BROADCAST : 0);
1261 Flag |= (MnpRxData->MulticastFlag ? IP4_LINK_MULTICAST : 0);
1262 Flag |= (MnpRxData->PromiscuousFlag ? IP4_LINK_PROMISC : 0);
1264 Token->CallBack (Token->IpInstance, Packet,
EFI_SUCCESS, Flag, Token->Context);
1313 NET_CHECK_SIGNATURE (Interface, IP4_INTERFACE_SIGNATURE);
1315 if (Interface->RecvRequest !=
NULL) {
1316 return EFI_ALREADY_STARTED;
1321 if (Token ==
NULL) {
1322 return EFI_OUT_OF_RESOURCES;
1325 Interface->RecvRequest = Token;
1326 Status = Interface->Mnp->Receive (Interface->Mnp, &Token->MnpToken);
1327 if (EFI_ERROR (Status)) {
1328 Interface->RecvRequest =
NULL;
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI InsertHeadList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
EFI_STATUS EFIAPI QueueDpc(IN EFI_TPL DpcTpl, IN EFI_DPC_PROCEDURE DpcProcedure, IN VOID *DpcContext OPTIONAL)
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_STATUS Ip4GetMulticastMac(IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp, IN IP4_ADDR Multicast, OUT EFI_MAC_ADDRESS *Mac)
EFI_STATUS Ip4FreeInterface(IN IP4_INTERFACE *Interface, IN IP4_PROTOCOL *IpInstance OPTIONAL)
BOOLEAN Ip4CancelInstanceFrame(IN IP4_LINK_TX_TOKEN *Frame, IN VOID *Context)
VOID EFIAPI Ip4OnFrameReceived(IN EFI_EVENT Event, IN VOID *Context)
EFI_STATUS Ip4SendFrameToDefaultRoute(IN IP4_ARP_QUE *ArpQue)
VOID EFIAPI Ip4OnArpResolvedDpc(IN VOID *Context)
VOID Ip4FreeLinkTxToken(IN IP4_LINK_TX_TOKEN *Token)
VOID EFIAPI Ip4OnFrameReceivedDpc(IN VOID *Context)
VOID EFIAPI Ip4OnFrameSentDpc(IN VOID *Context)
EFI_STATUS Ip4ReceiveFrame(IN IP4_INTERFACE *Interface, IN IP4_PROTOCOL *IpInstance OPTIONAL, IN IP4_FRAME_CALLBACK CallBack, IN VOID *Context)
IP4_INTERFACE * Ip4CreateInterface(IN EFI_MANAGED_NETWORK_PROTOCOL *Mnp, IN EFI_HANDLE Controller, IN EFI_HANDLE ImageHandle)
IP4_LINK_RX_TOKEN * Ip4CreateLinkRxToken(IN IP4_INTERFACE *Interface, IN IP4_PROTOCOL *IpInstance, IN IP4_FRAME_CALLBACK CallBack, IN VOID *Context)
EFI_STATUS Ip4SetAddress(IN OUT IP4_INTERFACE *Interface, IN IP4_ADDR IpAddr, IN IP4_ADDR SubnetMask)
IP4_LINK_TX_TOKEN * Ip4WrapLinkTxToken(IN IP4_INTERFACE *Interface, IN IP4_PROTOCOL *IpInstance OPTIONAL, IN NET_BUF *Packet, IN IP4_FRAME_CALLBACK CallBack, IN VOID *Context, IN IP4_SERVICE *IpSb)
VOID Ip4FreeArpQue(IN IP4_ARP_QUE *ArpQue, IN EFI_STATUS IoStatus)
EFI_STATUS Ip4SendFrame(IN IP4_INTERFACE *Interface, IN IP4_PROTOCOL *IpInstance OPTIONAL, IN NET_BUF *Packet, IN IP4_ADDR NextHop, IN IP4_FRAME_CALLBACK CallBack, IN VOID *Context, IN IP4_SERVICE *IpSb)
VOID Ip4CancelFrames(IN IP4_INTERFACE *Interface, IN EFI_STATUS IoStatus, IN IP4_FRAME_TO_CANCEL FrameToCancel OPTIONAL, IN VOID *Context)
VOID EFIAPI Ip4OnFrameSent(IN EFI_EVENT Event, IN VOID *Context)
IP4_ARP_QUE * Ip4CreateArpQue(IN IP4_INTERFACE *Interface, IN IP4_ADDR DestIp)
VOID EFIAPI Ip4RecycleFrame(IN VOID *Context)
VOID Ip4FreeFrameRxToken(IN IP4_LINK_RX_TOKEN *Token)
VOID Ip4CancelReceive(IN IP4_INTERFACE *Interface)
VOID EFIAPI Ip4OnArpResolved(IN EFI_EVENT Event, IN VOID *Context)
VOID Ip4CancelFrameArp(IN IP4_ARP_QUE *ArpQue, IN EFI_STATUS IoStatus, IN IP4_FRAME_TO_CANCEL FrameToCancel OPTIONAL, IN VOID *Context)
VOID(* IP4_FRAME_CALLBACK)(IN IP4_PROTOCOL *IpInstance OPTIONAL, IN NET_BUF *Packet, IN EFI_STATUS IoStatus, IN UINT32 LinkFlag, IN VOID *Context)
BOOLEAN(* IP4_FRAME_TO_CANCEL)(IP4_LINK_TX_TOKEN *Frame, VOID *Context)
IP4_ROUTE_CACHE_ENTRY * Ip4FindRouteCache(IN IP4_ROUTE_TABLE *RtTable, IN IP4_ADDR Dest, IN IP4_ADDR Src)
VOID Ip4FreeRouteCacheEntry(IN IP4_ROUTE_CACHE_ENTRY *RtCacheEntry)
EFI_STATUS EFIAPI NetbufBuildExt(IN NET_BUF *Nbuf, IN OUT NET_FRAGMENT *ExtFragment, IN OUT UINT32 *ExtNum)
EFI_STATUS EFIAPI NetLibCreateServiceChild(IN EFI_HANDLE Controller, IN EFI_HANDLE Image, IN EFI_GUID *ServiceBindingGuid, IN OUT EFI_HANDLE *ChildHandle)
EFI_STATUS EFIAPI NetLibDestroyServiceChild(IN EFI_HANDLE Controller, IN EFI_HANDLE Image, IN EFI_GUID *ServiceBindingGuid, IN EFI_HANDLE ChildHandle)
NET_BUF *EFIAPI NetbufFromExt(IN NET_FRAGMENT *ExtFragment, IN UINT32 ExtNum, IN UINT32 HeadSpace, IN UINT32 HeadLen, IN NET_VECTOR_EXT_FREE ExtFree, IN VOID *Arg OPTIONAL)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_MANAGED_NETWORK_RECEIVE_DATA * RxData
EFI_MANAGED_NETWORK_TRANSMIT_DATA * TxData
EFI_MAC_ADDRESS CurrentAddress
EFI_MAC_ADDRESS BroadcastAddress