X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FNetwork%2FTcp4Dxe%2FTcp4Misc.c;h=95f47f91bc40b41c2474480e858ae91ca2a3ee81;hb=185395a4a21dcb11bd59db256077a3b29d92ff55;hp=863ebc1ea0e014066cd70c22d6d22eb94a7e1855;hpb=4f6e31e47bc014da5055fa03779888d87c5e4c2a;p=mirror_edk2.git diff --git a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c index 863ebc1ea0..95f47f91bc 100644 --- a/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c +++ b/MdeModulePkg/Universal/Network/Tcp4Dxe/Tcp4Misc.c @@ -1,23 +1,15 @@ /** @file + Misc support routines for tcp. -Copyright (c) 2005 - 2006, Intel Corporation -All rights reserved. This program and the accompanying materials +Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at -http://opensource.org/licenses/bsd-license.php +http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module Name: - - Tcp4Misc.c - -Abstract: - - Misc support routines for tcp. - - **/ @@ -25,12 +17,12 @@ Abstract: #include -NET_LIST_ENTRY mTcpRunQue = { +LIST_ENTRY mTcpRunQue = { &mTcpRunQue, &mTcpRunQue }; -NET_LIST_ENTRY mTcpListenQue = { +LIST_ENTRY mTcpListenQue = { &mTcpListenQue, &mTcpListenQue }; @@ -57,12 +49,10 @@ CHAR16 *mTcpStateName[] = { @param Tcb Pointer to the TCP_CB of this TCP instance. - @return None - **/ VOID TcpInitTcbLocal ( - IN TCP_CB *Tcb + IN OUT TCP_CB *Tcb ) { // @@ -85,9 +75,11 @@ TcpInitTcbLocal ( Tcb->RcvWnd = GET_RCV_BUFFSIZE (Tcb->Sk); // - // Fisrt window size is never scaled + // First window size is never scaled // - Tcb->RcvWndScale = 0; + Tcb->RcvWndScale = 0; + + Tcb->ProbeTimerOn = FALSE; } @@ -99,19 +91,17 @@ TcpInitTcbLocal ( intial info. @param Opt Pointer to the options announced by the peer. - @return None - **/ VOID TcpInitTcbPeer ( - IN TCP_CB *Tcb, - IN TCP_SEG *Seg, - IN TCP_OPTION *Opt + IN OUT TCP_CB *Tcb, + IN TCP_SEG *Seg, + IN TCP_OPTION *Opt ) { UINT16 RcvMss; - ASSERT (Tcb && Seg && Opt); + ASSERT ((Tcb != NULL) && (Seg != NULL) && (Opt != NULL)); ASSERT (TCP_FLG_ON (Seg->Flag, TCP_FLG_SYN)); Tcb->SndWnd = Seg->Wnd; @@ -167,6 +157,8 @@ TcpInitTcbPeer ( TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_SND_TS); TCP_SET_FLG (Tcb->CtrlFlag, TCP_CTRL_RCVD_TS); + Tcb->TsRecent = Opt->TSVal; + // // Compute the effective SndMss per RFC1122 // section 4.2.2.6. If timestamp option is @@ -183,17 +175,17 @@ TcpInitTcbPeer ( @param Local Pointer to the local (IP, Port). @param Remote Pointer to the remote (IP, Port). - @return Pointer to the TCP_CB with the least number of wildcard, if NULL no match is found. + @return Pointer to the TCP_CB with the least number of wildcard, + if NULL no match is found. **/ -STATIC TCP_CB * TcpLocateListenTcb ( IN TCP_PEER *Local, IN TCP_PEER *Remote ) { - NET_LIST_ENTRY *Entry; + LIST_ENTRY *Entry; TCP_CB *Node; TCP_CB *Match; INTN Last; @@ -207,8 +199,7 @@ TcpLocateListenTcb ( if ((Local->Port != Node->LocalEnd.Port) || !TCP_PEER_MATCH (Remote, &Node->RemoteEnd) || - !TCP_PEER_MATCH (Local, &Node->LocalEnd) - ) { + !TCP_PEER_MATCH (Local, &Node->LocalEnd)) { continue; } @@ -249,7 +240,7 @@ TcpLocateListenTcb ( @param Addr Pointer to the IP address needs to match. @param Port The port number needs to match. - @return The Tcb which matches the paire exists or not. + @return The Tcb which matches the paire exists or not. **/ BOOLEAN @@ -259,7 +250,7 @@ TcpFindTcbByPeer ( ) { TCP_PORTNO LocalPort; - NET_LIST_ENTRY *Entry; + LIST_ENTRY *Entry; TCP_CB *Tcb; ASSERT ((Addr != NULL) && (Port != 0)); @@ -300,7 +291,7 @@ TcpFindTcbByPeer ( @param Syn Whether to search the listen sockets, if TRUE, the listen sockets are searched. - @return Pointer to the related TCP_CB, if NULL no match is found. + @return Pointer to the related TCP_CB, if NULL no match is found. **/ TCP_CB * @@ -314,7 +305,7 @@ TcpLocateTcb ( { TCP_PEER Local; TCP_PEER Remote; - NET_LIST_ENTRY *Entry; + LIST_ENTRY *Entry; TCP_CB *Tcb; Local.Port = LocalPort; @@ -332,8 +323,8 @@ TcpLocateTcb ( if (TCP_PEER_EQUAL (&Remote, &Tcb->RemoteEnd) && TCP_PEER_EQUAL (&Local, &Tcb->LocalEnd)) { - NetListRemoveEntry (&Tcb->List); - NetListInsertHead (&mTcpRunQue, &Tcb->List); + RemoveEntryList (&Tcb->List); + InsertHeadList (&mTcpRunQue, &Tcb->List); return Tcb; } @@ -364,19 +355,16 @@ TcpInsertTcb ( IN TCP_CB *Tcb ) { - NET_LIST_ENTRY *Entry; - NET_LIST_ENTRY *Head; + LIST_ENTRY *Entry; + LIST_ENTRY *Head; TCP_CB *Node; - TCP4_PROTO_DATA *TcpProto; ASSERT ( - Tcb && - ( - (Tcb->State == TCP_LISTEN) || - (Tcb->State == TCP_SYN_SENT) || - (Tcb->State == TCP_SYN_RCVD) || - (Tcb->State == TCP_CLOSED) - ) + (Tcb != NULL) && + ((Tcb->State == TCP_LISTEN) || + (Tcb->State == TCP_SYN_SENT) || + (Tcb->State == TCP_SYN_RCVD) || + (Tcb->State == TCP_CLOSED)) ); if (Tcb->LocalEnd.Port == 0) { @@ -402,21 +390,18 @@ TcpInsertTcb ( } } - NetListInsertHead (Head, &Tcb->List); - - TcpProto = (TCP4_PROTO_DATA *) Tcb->Sk->ProtoReserved; - TcpSetVariableData (TcpProto->TcpService); + InsertHeadList (Head, &Tcb->List); return 0; } /** - Clone a TCP_CB from Tcb. + Clone a TCB_CB from Tcb. @param Tcb Pointer to the TCP_CB to be cloned. - @return Pointer to the new cloned TCP_CB, if NULL error condition occurred. + @return Pointer to the new cloned TCP_CB, if NULL error condition occurred. **/ TCP_CB * @@ -426,28 +411,28 @@ TcpCloneTcb ( { TCP_CB *Clone; - Clone = NetAllocatePool (sizeof (TCP_CB)); + Clone = AllocatePool (sizeof (TCP_CB)); if (Clone == NULL) { return NULL; } - NetCopyMem (Clone, Tcb, sizeof (TCP_CB)); + CopyMem (Clone, Tcb, sizeof (TCP_CB)); // // Increate the reference count of the shared IpInfo. // NET_GET_REF (Tcb->IpInfo); - NetListInit (&Clone->List); - NetListInit (&Clone->SndQue); - NetListInit (&Clone->RcvQue); + InitializeListHead (&Clone->List); + InitializeListHead (&Clone->SndQue); + InitializeListHead (&Clone->RcvQue); Clone->Sk = SockClone (Tcb->Sk); if (Clone->Sk == NULL) { - TCP4_DEBUG_ERROR (("TcpCloneTcb: failed to clone a sock\n")); - NetFreePool (Clone); + DEBUG ((EFI_D_ERROR, "TcpCloneTcb: failed to clone a sock\n")); + FreePool (Clone); return NULL; } @@ -460,9 +445,7 @@ TcpCloneTcb ( /** Compute an ISS to be used by a new connection. - None - - @return The result ISS. + @return The result ISS. **/ TCP_SEQNO @@ -478,9 +461,9 @@ TcpGetIss ( /** Get the local mss. - None + @param Sock Pointer to the socket to get mss - @return The mss size. + @return The mss size. **/ UINT16 @@ -488,19 +471,19 @@ TcpGetRcvMss ( IN SOCKET *Sock ) { - EFI_SIMPLE_NETWORK_MODE SnpMode; + EFI_IP4_MODE_DATA Ip4Mode; TCP4_PROTO_DATA *TcpProto; EFI_IP4_PROTOCOL *Ip; - ASSERT (Sock); + ASSERT (Sock != NULL); TcpProto = (TCP4_PROTO_DATA *) Sock->ProtoReserved; - Ip = TcpProto->TcpService->IpIo->Ip; - ASSERT (Ip); + Ip = TcpProto->TcpService->IpIo->Ip.Ip4; + ASSERT (Ip != NULL); - Ip->GetModeData (Ip, NULL, NULL, &SnpMode); + Ip->GetModeData (Ip, &Ip4Mode, NULL, NULL); - return (UINT16) (SnpMode.MaxPacketSize - 40); + return (UINT16) (Ip4Mode.MaxPacketSize - sizeof (TCP_HEAD)); } @@ -510,17 +493,19 @@ TcpGetRcvMss ( @param Tcb Pointer to the TCP_CB of this TCP instance. @param State The state to be set. - @return None - **/ VOID TcpSetState ( - IN TCP_CB *Tcb, - IN UINT8 State + IN OUT TCP_CB *Tcb, + IN UINT8 State ) { - TCP4_DEBUG_TRACE ( - ("Tcb (%x) state %s --> %s\n", + ASSERT (Tcb->State < (sizeof (mTcpStateName) / sizeof (CHAR16 *))); + ASSERT (State < (sizeof (mTcpStateName) / sizeof (CHAR16 *))); + + DEBUG ( + (EFI_D_INFO, + "Tcb (%p) state %s --> %s\n", Tcb, mTcpStateName[Tcb->State], mTcpStateName[State]) @@ -547,6 +532,8 @@ TcpSetState ( SockConnClosed (Tcb->Sk); + break; + default: break; } } @@ -560,7 +547,7 @@ TcpSetState ( @param HeadSum The checksum value of the fixed part of pseudo header. - @return The checksum value. + @return The checksum value. **/ UINT16 @@ -574,15 +561,14 @@ TcpChecksum ( Checksum = NetbufChecksum (Nbuf); Checksum = NetAddChecksum (Checksum, HeadSum); - Checksum = NetAddChecksum ( - Checksum, - HTONS ((UINT16) Nbuf->TotalSize) - ); + Checksum = NetAddChecksum ( + Checksum, + HTONS ((UINT16) Nbuf->TotalSize) + ); return (UINT16) ~Checksum; } - /** Translate the information from the head of the received TCP segment Nbuf contains and fill it into a TCP_SEG structure. @@ -590,13 +576,13 @@ TcpChecksum ( @param Tcb Pointer to the TCP_CB of this TCP instance. @param Nbuf Pointer to the buffer contains the TCP segment. - @return Pointer to the TCP_SEG that contains the translated TCP head information. + @return Pointer to the TCP_SEG that contains the translated TCP head information. **/ TCP_SEG * TcpFormatNetbuf ( - IN TCP_CB *Tcb, - IN NET_BUF *Nbuf + IN TCP_CB *Tcb, + IN OUT NET_BUF *Nbuf ) { TCP_SEG *Seg; @@ -604,6 +590,7 @@ TcpFormatNetbuf ( Seg = TCPSEG_NETBUF (Nbuf); Head = (TCP_HEAD *) NetbufGetByte (Nbuf, 0, NULL); + ASSERT (Head != NULL); Nbuf->Tcp = Head; Seg->Seq = NTOHL (Head->Seq); @@ -639,8 +626,6 @@ TcpFormatNetbuf ( @param Tcb Pointer to the TCP_CB of the connection to be reset. - @return None - **/ VOID TcpResetConnection ( @@ -671,7 +656,7 @@ TcpResetConnection ( Nhead->Ack = HTONL (Tcb->RcvNxt); Nhead->SrcPort = Tcb->LocalEnd.Port; Nhead->DstPort = Tcb->RemoteEnd.Port; - Nhead->HeadLen = (sizeof (TCP_HEAD) >> 2); + Nhead->HeadLen = (UINT8) (sizeof (TCP_HEAD) >> 2); Nhead->Res = 0; Nhead->Wnd = HTONS (0xFFFF); Nhead->Checksum = 0; @@ -685,17 +670,15 @@ TcpResetConnection ( /** - Initialize an active connection, + Initialize an active connection. @param Tcb Pointer to the TCP_CB that wants to initiate a connection. - @return None - **/ VOID TcpOnAppConnect ( - IN TCP_CB *Tcb + IN OUT TCP_CB *Tcb ) { TcpInitTcbLocal (Tcb); @@ -712,20 +695,18 @@ TcpOnAppConnect ( @param Tcb Pointer to the TCP_CB of this TCP instance. - @return None. - **/ VOID TcpOnAppClose ( - IN TCP_CB *Tcb + IN OUT TCP_CB *Tcb ) { - ASSERT (Tcb); + ASSERT (Tcb != NULL); - if (!NetListIsEmpty (&Tcb->RcvQue) || GET_RCV_DATASIZE (Tcb->Sk)) { + if (!IsListEmpty (&Tcb->RcvQue) || GET_RCV_DATASIZE (Tcb->Sk) != 0) { - TCP4_DEBUG_WARN (("TcpOnAppClose: connection reset " - "because data is lost for TCB %x\n", Tcb)); + DEBUG ((EFI_D_WARN, "TcpOnAppClose: connection reset " + "because data is lost for TCB %p\n", Tcb)); TcpResetConnection (Tcb); TcpClose (Tcb); @@ -747,6 +728,8 @@ TcpOnAppClose ( case TCP_CLOSE_WAIT: TcpSetState (Tcb, TCP_LAST_ACK); break; + default: + break; } TcpToSendData (Tcb, 1); @@ -754,8 +737,7 @@ TcpOnAppClose ( /** - Check whether the application's newly delivered data - can be sent out. + Check whether the application's newly delivered data can be sent out. @param Tcb Pointer to the TCP_CB of this TCP instance. @@ -767,29 +749,25 @@ TcpOnAppClose ( **/ INTN TcpOnAppSend ( - IN TCP_CB *Tcb + IN OUT TCP_CB *Tcb ) { switch (Tcb->State) { case TCP_CLOSED: return -1; - break; case TCP_LISTEN: return -1; - break; case TCP_SYN_SENT: case TCP_SYN_RCVD: return 0; - break; case TCP_ESTABLISHED: case TCP_CLOSE_WAIT: TcpToSendData (Tcb, 0); return 0; - break; case TCP_FIN_WAIT_1: case TCP_FIN_WAIT_2: @@ -797,6 +775,8 @@ TcpOnAppSend ( case TCP_LAST_ACK: case TCP_TIME_WAIT: return -1; + + default: break; } @@ -810,9 +790,8 @@ TcpOnAppSend ( @param Tcb Pointer to the TCP_CB of this TCP instance. - **/ -INTN +VOID TcpOnAppConsume ( IN TCP_CB *Tcb ) @@ -821,17 +800,14 @@ TcpOnAppConsume ( switch (Tcb->State) { case TCP_CLOSED: - return -1; - break; + return; case TCP_LISTEN: - return -1; - break; + return; case TCP_SYN_SENT: case TCP_SYN_RCVD: - return 0; - break; + return; case TCP_ESTABLISHED: TcpOld = TcpRcvWinOld (Tcb); @@ -839,14 +815,14 @@ TcpOnAppConsume ( if (TcpOld < Tcb->RcvMss) { - TCP4_DEBUG_TRACE (("TcpOnAppConsume: send a window" - " update for a window closed Tcb(%x)\n", Tcb)); + DEBUG ((EFI_D_INFO, "TcpOnAppConsume: send a window" + " update for a window closed Tcb %p\n", Tcb)); TcpSendAck (Tcb); } else if (Tcb->DelayedAck == 0) { - TCP4_DEBUG_TRACE (("TcpOnAppConsume: scheduled a delayed" - " ACK to update window for Tcb(%x)\n", Tcb)); + DEBUG ((EFI_D_INFO, "TcpOnAppConsume: scheduled a delayed" + " ACK to update window for Tcb %p\n", Tcb)); Tcb->DelayedAck = 1; } @@ -855,19 +831,18 @@ TcpOnAppConsume ( break; case TCP_CLOSE_WAIT: - return 0; - break; + return; case TCP_FIN_WAIT_1: case TCP_FIN_WAIT_2: case TCP_CLOSING: case TCP_LAST_ACK: case TCP_TIME_WAIT: - return -1; + return; + + default: break; } - - return -1; } @@ -877,16 +852,14 @@ TcpOnAppConsume ( @param Tcb Pointer to the TCP_CB of the TCP instance. - @return None. - **/ VOID TcpOnAppAbort ( IN TCP_CB *Tcb ) { - TCP4_DEBUG_WARN (("TcpOnAppAbort: connection reset " - "issued by application for TCB %x\n", Tcb)); + DEBUG ((EFI_D_WARN, "TcpOnAppAbort: connection reset " + "issued by application for TCB %p\n", Tcb)); switch (Tcb->State) { case TCP_SYN_RCVD: @@ -896,258 +869,58 @@ TcpOnAppAbort ( case TCP_CLOSE_WAIT: TcpResetConnection (Tcb); break; + default: + break; } TcpSetState (Tcb, TCP_CLOSED); } - /** - Set the Tdp4 variable data. - - @param Tcp4Service Tcp4 service data. - - @retval EFI_OUT_OF_RESOURCES There are not enough resources to set the variable. - @retval other Set variable failed. - -**/ -EFI_STATUS -TcpSetVariableData ( - IN TCP4_SERVICE_DATA *Tcp4Service - ) -{ - UINT32 NumConfiguredInstance; - NET_LIST_ENTRY *Entry; - TCP_CB *TcpPcb; - TCP4_PROTO_DATA *TcpProto; - UINTN VariableDataSize; - EFI_TCP4_VARIABLE_DATA *Tcp4VariableData; - EFI_TCP4_SERVICE_POINT *Tcp4ServicePoint; - CHAR16 *NewMacString; - EFI_STATUS Status; - - NumConfiguredInstance = 0; - - // - // Go through the running queue to count the instances. - // - NET_LIST_FOR_EACH (Entry, &mTcpRunQue) { - TcpPcb = NET_LIST_USER_STRUCT (Entry, TCP_CB, List); - - TcpProto = (TCP4_PROTO_DATA *) TcpPcb->Sk->ProtoReserved; - - if (TcpProto->TcpService == Tcp4Service) { - // - // This tcp instance belongs to the Tcp4Service. - // - NumConfiguredInstance++; - } - } - - // - // Go through the listening queue to count the instances. - // - NET_LIST_FOR_EACH (Entry, &mTcpListenQue) { - TcpPcb = NET_LIST_USER_STRUCT (Entry, TCP_CB, List); - - TcpProto = (TCP4_PROTO_DATA *) TcpPcb->Sk->ProtoReserved; - - if (TcpProto->TcpService == Tcp4Service) { - // - // This tcp instance belongs to the Tcp4Service. - // - NumConfiguredInstance++; - } - } - - // - // Calculate the size of the Tcp4VariableData. As there may be no Tcp4 child, - // we should add extra buffer for the service points only if the number of configured - // children is more than 1. - // - VariableDataSize = sizeof (EFI_TCP4_VARIABLE_DATA); - - if (NumConfiguredInstance > 1) { - VariableDataSize += sizeof (EFI_TCP4_SERVICE_POINT) * (NumConfiguredInstance - 1); - } - - Tcp4VariableData = NetAllocatePool (VariableDataSize); - if (Tcp4VariableData == NULL) { - return EFI_OUT_OF_RESOURCES; - } - - Tcp4VariableData->DriverHandle = Tcp4Service->DriverBindingHandle; - Tcp4VariableData->ServiceCount = NumConfiguredInstance; - - Tcp4ServicePoint = &Tcp4VariableData->Services[0]; - - // - // Go through the running queue to fill the service points. - // - NET_LIST_FOR_EACH (Entry, &mTcpRunQue) { - TcpPcb = NET_LIST_USER_STRUCT (Entry, TCP_CB, List); - - TcpProto = (TCP4_PROTO_DATA *) TcpPcb->Sk->ProtoReserved; - - if (TcpProto->TcpService == Tcp4Service) { - // - // This tcp instance belongs to the Tcp4Service. - // - Tcp4ServicePoint->InstanceHandle = TcpPcb->Sk->SockHandle; - NetCopyMem (&Tcp4ServicePoint->LocalAddress, &TcpPcb->LocalEnd.Ip, sizeof (EFI_IPv4_ADDRESS)); - Tcp4ServicePoint->LocalPort = NTOHS (TcpPcb->LocalEnd.Port); - NetCopyMem (&Tcp4ServicePoint->RemoteAddress, &TcpPcb->RemoteEnd.Ip, sizeof (EFI_IPv4_ADDRESS)); - Tcp4ServicePoint->RemotePort = NTOHS (TcpPcb->RemoteEnd.Port); - - Tcp4ServicePoint++; - } - } - - // - // Go through the listening queue to fill the service points. - // - NET_LIST_FOR_EACH (Entry, &mTcpListenQue) { - TcpPcb = NET_LIST_USER_STRUCT (Entry, TCP_CB, List); - - TcpProto = (TCP4_PROTO_DATA *) TcpPcb->Sk->ProtoReserved; - - if (TcpProto->TcpService == Tcp4Service) { - // - // This tcp instance belongs to the Tcp4Service. - // - Tcp4ServicePoint->InstanceHandle = TcpPcb->Sk->SockHandle; - NetCopyMem (&Tcp4ServicePoint->LocalAddress, &TcpPcb->LocalEnd.Ip, sizeof (EFI_IPv4_ADDRESS)); - Tcp4ServicePoint->LocalPort = NTOHS (TcpPcb->LocalEnd.Port); - NetCopyMem (&Tcp4ServicePoint->RemoteAddress, &TcpPcb->RemoteEnd.Ip, sizeof (EFI_IPv4_ADDRESS)); - Tcp4ServicePoint->RemotePort = NTOHS (TcpPcb->RemoteEnd.Port); - - Tcp4ServicePoint++; - } - } - - // - // Get the mac string. - // - Status = NetLibGetMacString ( - Tcp4Service->ControllerHandle, - Tcp4Service->DriverBindingHandle, - &NewMacString - ); - if (EFI_ERROR (Status)) { - goto ON_ERROR; - } - - if (Tcp4Service->MacString != NULL) { - // - // The variable is set already, we're going to update it. - // - if (StrCmp (Tcp4Service->MacString, NewMacString) != 0) { - // - // The mac address is changed, delete the previous variable first. - // - gRT->SetVariable ( - Tcp4Service->MacString, - &gEfiTcp4ServiceBindingProtocolGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS, - 0, - NULL - ); - } - - NetFreePool (Tcp4Service->MacString); - } - - Tcp4Service->MacString = NewMacString; - - Status = gRT->SetVariable ( - Tcp4Service->MacString, - &gEfiTcp4ServiceBindingProtocolGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS, - VariableDataSize, - (VOID *) Tcp4VariableData - ); - -ON_ERROR: - - NetFreePool (Tcp4VariableData); - - return Status; -} - - -/** - Clear the variable and free the resource. + Install the device path protocol on the TCP instance. - @param Tcp4Service Tcp4 service data. + @param Sock Pointer to the socket representing the TCP instance. - @return None. + @retval EFI_SUCCESS The device path protocol is installed. + @retval other Failed to install the device path protocol. **/ -VOID -TcpClearVariableData ( - IN TCP4_SERVICE_DATA *Tcp4Service - ) -{ - ASSERT (Tcp4Service->MacString != NULL); - - gRT->SetVariable ( - Tcp4Service->MacString, - &gEfiTcp4ServiceBindingProtocolGuid, - EFI_VARIABLE_BOOTSERVICE_ACCESS, - 0, - NULL - ); - - NetFreePool (Tcp4Service->MacString); - Tcp4Service->MacString = NULL; -} - EFI_STATUS TcpInstallDevicePath ( IN SOCKET *Sock ) -/*++ - -Routine Description: - - Install the device path protocol on the TCP instance. - -Arguments: - - Sock - Pointer to the socket representing the TCP instance. - -Returns: - - EFI_SUCCESS - The device path protocol is installed. - other - Failed to install the device path protocol. - ---*/ { TCP4_PROTO_DATA *TcpProto; TCP4_SERVICE_DATA *TcpService; TCP_CB *Tcb; IPv4_DEVICE_PATH Ip4DPathNode; EFI_STATUS Status; + TCP_PORTNO LocalPort; + TCP_PORTNO RemotePort; TcpProto = (TCP4_PROTO_DATA *) Sock->ProtoReserved; TcpService = TcpProto->TcpService; Tcb = TcpProto->TcpPcb; + LocalPort = NTOHS (Tcb->LocalEnd.Port); + RemotePort = NTOHS (Tcb->RemoteEnd.Port); NetLibCreateIPv4DPathNode ( &Ip4DPathNode, TcpService->ControllerHandle, Tcb->LocalEnd.Ip, - NTOHS (Tcb->LocalEnd.Port), + LocalPort, Tcb->RemoteEnd.Ip, - NTOHS (Tcb->RemoteEnd.Port), + RemotePort, EFI_IP_PROTO_TCP, Tcb->UseDefaultAddr ); + IP4_COPY_ADDRESS (&Ip4DPathNode.SubnetMask, &Tcb->SubnetMask); + Sock->DevicePath = AppendDevicePathNode ( - Sock->ParentDevicePath, - (EFI_DEVICE_PATH_PROTOCOL *) &Ip4DPathNode - ); + Sock->ParentDevicePath, + (EFI_DEVICE_PATH_PROTOCOL *) &Ip4DPathNode + ); if (Sock->DevicePath == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -1159,7 +932,7 @@ Returns: Sock->DevicePath ); if (EFI_ERROR (Status)) { - NetFreePool (Sock->DevicePath); + FreePool (Sock->DevicePath); } return Status;