27 NetbufList = &(Sockbuf->DataQueue->BufList);
33 return NET_LIST_HEAD (NetbufList,
NET_BUF, List);
54 NetbufList = &(Sockbuf->DataQueue->BufList);
56 if ((SockEntry->List.ForwardLink == NetbufList) ||
57 (SockEntry->List.BackLink == &SockEntry->List) ||
58 (SockEntry->List.ForwardLink == &SockEntry->List)
64 return NET_LIST_USER_STRUCT (SockEntry->List.ForwardLink,
NET_BUF, List);
107 ASSERT ((SockBuffer !=
NULL) && (IsUrg !=
NULL) && (BufLen > 0));
113 ASSERT (RcvBufEntry !=
NULL);
121 *IsUrg = (BOOLEAN)((TcpRsvData->UrgLen > 0) ?
TRUE :
FALSE);
123 if (*IsUrg && (TcpRsvData->UrgLen < RcvBufEntry->TotalSize)) {
124 DataLen =
MIN (TcpRsvData->UrgLen, BufLen);
126 if (DataLen < TcpRsvData->UrgLen) {
127 TcpRsvData->UrgLen = TcpRsvData->UrgLen - DataLen;
129 TcpRsvData->UrgLen = 0;
139 DataLen = RcvBufEntry->TotalSize;
141 RcvBufEntry =
SockBufNext (SockBuffer, RcvBufEntry);
143 while ((BufLen > DataLen) && (RcvBufEntry !=
NULL)) {
146 Urg = (BOOLEAN)((TcpRsvData->UrgLen > 0) ?
TRUE :
FALSE);
152 if (*IsUrg && (TcpRsvData->UrgLen < RcvBufEntry->TotalSize)) {
153 if (TcpRsvData->UrgLen + DataLen < BufLen) {
154 TcpRsvData->UrgLen = 0;
156 TcpRsvData->UrgLen = TcpRsvData->UrgLen - (BufLen - DataLen);
159 return MIN (TcpRsvData->UrgLen + DataLen, BufLen);
162 DataLen += RcvBufEntry->TotalSize;
164 RcvBufEntry =
SockBufNext (SockBuffer, RcvBufEntry);
167 DataLen =
MIN (BufLen, DataLen);
198 ASSERT (RxData->DataLength >= RcvdBytes);
200 RxData->DataLength = RcvdBytes;
201 RxData->UrgentFlag = IsUrg;
206 for (Index = 0; (Index < RxData->FragmentCount) && (RcvdBytes > 0); Index++) {
207 Fragment = &RxData->FragmentTable[Index];
208 CopyBytes =
MIN ((UINT32)(Fragment->FragmentLength), RcvdBytes);
211 Sock->RcvBuffer.DataQueue,
214 Fragment->FragmentBuffer
217 Fragment->FragmentLength = CopyBytes;
218 RcvdBytes -= CopyBytes;
249 while ((FreeSpace >= Sock->SndBuffer.LowWater) && !
IsListEmpty (&Sock->SndTokenList)) {
250 SockToken = NET_LIST_HEAD (
251 &(Sock->SndTokenList),
261 &(Sock->ProcessingSndTokenList),
269 TxData = SndToken->Packet.TxData;
271 DataLen = TxData->DataLength;
274 if (EFI_ERROR (Status)) {
278 if (DataLen >= FreeSpace) {
281 FreeSpace -= DataLen;
309 UINT32 TokenRcvdBytes;
313 ASSERT (Sock !=
NULL);
317 RxData = RcvToken->Packet.RxData;
334 return TokenRcvdBytes;
366 TxData->FragmentCount,
373 if (
NULL == SndData) {
376 "SockKProcessSndData: Failed to call NetBufferFromExt\n")
379 return EFI_OUT_OF_RESOURCES;
387 if (TxData->Urgent) {
390 if (EFI_ERROR (Status)) {
398 if (EFI_ERROR (Status)) {
409 if (EFI_ERROR (Status)) {
432 ASSERT ((Sock !=
NULL) && (PendingTokenList !=
NULL));
435 SockToken = NET_LIST_HEAD (
441 Token = SockToken->
Token;
461 ASSERT (Sock->ConnectionToken !=
NULL);
464 Sock->ConnectionToken =
NULL;
492 SockToken = NET_LIST_HEAD (
493 &Parent->ListenTokenList,
499 ListenToken->NewChildHandle = Sock->SockHandle;
511 "SockWakeListenToken: accept a socket, now conncnt is %d",
531 UINT32 TokenRcvdBytes;
535 ASSERT (Sock->RcvBuffer.DataQueue !=
NULL);
537 RcvdBytes = (Sock->RcvBuffer.DataQueue)->BufSize;
539 ASSERT (RcvdBytes > 0);
541 while (RcvdBytes > 0 && !
IsListEmpty (&Sock->RcvTokenList)) {
542 SockToken = NET_LIST_HEAD (
551 if (0 == TokenRcvdBytes) {
557 RcvdBytes -= TokenRcvdBytes;
587 return EFI_NOT_FOUND;
593 Entry = SpecifiedTokenList->ForwardLink;
594 while (Entry != SpecifiedTokenList) {
595 SockToken = NET_LIST_USER_STRUCT (Entry,
SOCK_TOKEN, TokenList);
602 Entry = SpecifiedTokenList->ForwardLink;
605 if (Token == (VOID *)SockToken->
Token) {
613 Status = EFI_NOT_FOUND;
615 Entry = Entry->ForwardLink;
641 UINTN ProtocolLength;
643 ASSERT ((SockInitData !=
NULL) && (SockInitData->ProtoHandler !=
NULL));
645 ASSERT ((SockInitData->ProtoData !=
NULL) && (SockInitData->DataSize <= PROTO_RESERVED_LEN));
647 if (SockInitData->IpVersion == IP_VERSION_4) {
648 TcpProtocolGuid = &gEfiTcp4ProtocolGuid;
651 TcpProtocolGuid = &gEfiTcp6ProtocolGuid;
655 Parent = SockInitData->
Parent;
660 "SockCreate: Socket parent has reached its connection limit with %d ConnCnt and %d BackLog\n",
670 DEBUG ((DEBUG_ERROR,
"SockCreate: No resource to create a new socket\n"));
687 "SockCreate: No resource to allocate SndBuffer for new socket\n")
697 "SockCreate: No resource to allocate RcvBuffer for new socket\n")
706 Sock->
BackLog = SockInitData->BackLog;
710 Sock->Type = SockInitData->Type;
712 Sock->State = SockInitData->State;
715 Sock->
Context = SockInitData->Context;
721 Sock->IpVersion = SockInitData->IpVersion;
733 Status =
gBS->InstallMultipleProtocolInterfaces (
740 if (EFI_ERROR (Status)) {
743 "SockCreate: Install TCP protocol in socket failed with %r\n",
750 if (Parent !=
NULL) {
762 "SockCreate: Create a new socket and add to parent, now conncnt is %d\n",
771 if (EFI_ERROR (Status)) {
781 gBS->UninstallMultipleProtocolInterfaces (
834 if (Sock->Parent !=
NULL) {
836 (Sock->Parent->ConnCnt)--;
840 "SockDestroy: Delete a unaccepted socket from parent now conncnt is %d\n",
841 Sock->Parent->ConnCnt)
863 ASSERT (Sock !=
NULL);
879 if (Sock->ConnectionToken !=
NULL) {
881 Sock->ConnectionToken =
NULL;
884 if (Sock->CloseToken !=
NULL) {
886 Sock->CloseToken =
NULL;
899 Child = NET_LIST_HEAD (
900 &Sock->ConnectionList,
944 InitData.
BackLog = Sock->BackLog;
946 InitData.State = Sock->State;
948 InitData.Type = Sock->Type;
952 InitData.IpVersion = Sock->IpVersion;
953 InitData.
Protocol = &(Sock->NetProtocol);
956 InitData.
Context = Sock->Context;
957 InitData.ProtoData = Sock->ProtoReserved;
958 InitData.DataSize =
sizeof (Sock->ProtoReserved);
962 if (
NULL == ClonedSock) {
963 DEBUG ((DEBUG_ERROR,
"SockClone: no resource to create a cloned sock\n"));
968 ClonedSock->ConfigureState = Sock->ConfigureState;
989 ASSERT (SO_CONNECTING == Sock->State);
993 if (
NULL == Sock->Parent) {
1015 if (Sock->CloseToken !=
NULL) {
1017 Sock->CloseToken =
NULL;
1023 if (Sock->Parent !=
NULL) {
1047 ASSERT (!
IsListEmpty (&Sock->ProcessingSndTokenList));
1048 ASSERT (Count <= (Sock->SndBuffer.DataQueue)->BufSize);
1056 SockToken = NET_LIST_HEAD (
1057 &(Sock->ProcessingSndTokenList),
1062 SndToken = SockToken->
Token;
1106 Sock->SndBuffer.DataQueue,
1132 (Sock !=
NULL) && (Sock->RcvBuffer.DataQueue !=
NULL) &&
1133 UrgLen <= NetBuffer->TotalSize
1136 NET_GET_REF (NetBuffer);
1138 ((
TCP_RSV_DATA *)(NetBuffer->ProtoData))->UrgLen = UrgLen;
1164 ASSERT (Sock !=
NULL && ((SOCK_SND_BUF == Which) || (SOCK_RCV_BUF == Which)));
1166 if (SOCK_SND_BUF == Which) {
1167 SockBuffer = &(Sock->SndBuffer);
1169 SockBuffer = &(Sock->RcvBuffer);
1172 BufferCC = (SockBuffer->
DataQueue)->BufSize;
1174 if (BufferCC >= SockBuffer->
HighWater) {
1178 return SockBuffer->
HighWater - BufferCC;
1203 Err = Sock->SockError;
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
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)
NODE Child(IN NODE LoopVar6, IN UINT8 LoopVar5)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define DEBUG(Expression)
UINT32 EFIAPI NetbufQueTrim(IN OUT NET_BUF_QUEUE *NbufQue, IN UINT32 Len)
UINT32 EFIAPI NetbufQueCopy(IN NET_BUF_QUEUE *NbufQue, IN UINT32 Offset, IN UINT32 Len, OUT UINT8 *Dest)
VOID EFIAPI NetbufQueFlush(IN OUT NET_BUF_QUEUE *NbufQue)
NET_BUF_QUEUE *EFIAPI NetbufQueAlloc(VOID)
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 NetbufQueFree(IN NET_BUF_QUEUE *NbufQue)
VOID EFIAPI NetbufQueAppend(IN OUT NET_BUF_QUEUE *NbufQue, IN OUT NET_BUF *Nbuf)
#define GET_RCV_DATASIZE(Sock)
#define SOCK_NO_MORE_DATA(Sock)
@ SockStream
This socket providing stream service.
#define SOCK_IS_UNCONFIGURED(Sock)
#define SOCK_IS_LISTENING(Sock)
#define SOCK_SND
Need protocol to send something.
EFI_STATUS SockDestroyChild(IN OUT SOCKET *Sock)
#define SOCK_IS_CONNECTED(Sock)
#define SOCK_SNDURG
Need protocol to send urgent data.
#define SOCK_ERROR(Sock, Error)
#define SOCK_SNDPUSH
Need protocol to send pushed data.
EFI_STATUS SockProcessTcpSndData(IN SOCKET *Sock, IN VOID *TcpTxData)
VOID SockDestroy(IN OUT SOCKET *Sock)
VOID SockDataRcvd(IN OUT SOCKET *Sock, IN OUT NET_BUF *NetBuffer, IN UINT32 UrgLen)
VOID SockProcessSndToken(IN OUT SOCKET *Sock)
VOID SockFlushPendingToken(IN SOCKET *Sock, IN OUT LIST_ENTRY *PendingTokenList)
VOID SockWakeConnToken(IN OUT SOCKET *Sock)
SOCKET * SockCreate(IN SOCK_INIT_DATA *SockInitData)
UINT32 SockTcpDataToRcv(IN SOCK_BUFFER *SockBuffer, OUT BOOLEAN *IsUrg, IN UINT32 BufLen)
VOID SockConnFlush(IN OUT SOCKET *Sock)
NET_BUF * SockBufNext(IN SOCK_BUFFER *Sockbuf, IN NET_BUF *SockEntry)
UINT32 SockGetFreeSpace(IN SOCKET *Sock, IN UINT32 Which)
VOID SockNoMoreData(IN OUT SOCKET *Sock)
SOCKET * SockClone(IN SOCKET *Sock)
UINT32 SockGetDataToSend(IN SOCKET *Sock, IN UINT32 Offset, IN UINT32 Len, OUT UINT8 *Dest)
VOID SockSetState(IN OUT SOCKET *Sock, IN UINT8 State)
VOID SockWakeRcvToken(IN OUT SOCKET *Sock)
UINT32 SockProcessRcvToken(IN OUT SOCKET *Sock, IN OUT SOCK_IO_TOKEN *RcvToken)
VOID SockWakeListenToken(IN OUT SOCKET *Sock)
EFI_STATUS SockCancelToken(IN SOCK_COMPLETION_TOKEN *Token, IN OUT LIST_ENTRY *SpecifiedTokenList)
VOID SockConnClosed(IN OUT SOCKET *Sock)
VOID SockSetTcpRxData(IN SOCKET *Sock, IN VOID *TcpRxData, IN UINT32 RcvdBytes, IN BOOLEAN IsUrg)
NET_BUF * SockBufFirst(IN SOCK_BUFFER *Sockbuf)
VOID SockDataSent(IN OUT SOCKET *Sock, IN UINT32 Count)
VOID EFIAPI SockFreeFoo(IN VOID *Arg)
VOID SockConnEstablished(IN OUT SOCKET *Sock)
#define SIGNAL_TOKEN(Token, TokenStatus)
#define EFI_CONNECTION_FIN
EFI_LOCK *EFIAPI EfiInitializeLock(IN OUT EFI_LOCK *Lock, IN EFI_TPL Priority)
NET_BUF_QUEUE * DataQueue
The queue to buffer data.
UINT32 LowWater
The low water mark of sock_buffer.
UINT32 HighWater
The buffersize upper limit of sock_buffer.
UINT32 SndBufferSize
The high water mark of send buffer.
SOCK_PROTO_HANDLER ProtoHandler
The handler of protocol for socket request.
SOCKET * Parent
The parent of this socket.
EFI_HANDLE DriverBinding
The driver binding handle.
VOID * Context
The context of the callback.
UINT32 BackLog
The connection limit for listening socket.
UINT32 RcvBufferSize
The high water mark of receive buffer.
SOCK_CREATE_CALLBACK CreateCallback
Callback after created.
SOCK_DESTROY_CALLBACK DestroyCallback
Callback before destroyed.
LIST_ENTRY TokenList
The entry to add in the token list.
SOCK_COMPLETION_TOKEN * Token
The application's token.
UINT32 RemainDataLen
Unprocessed data length.
SOCK_BUFFER RcvBuffer
Receive buffer of received data.
LIST_ENTRY ConnectionList
the connections maintained by this socket
UINT8 ProtoReserved[PROTO_RESERVED_LEN]
Data fields reserved for protocol.
SOCKET * Parent
listening parent that accept the connection
UINT32 Signature
Signature of the socket.
EFI_LOCK Lock
The lock of socket.
EFI_HANDLE SockHandle
The virtual handle of the socket.
EFI_STATUS SockError
The error returned by low layer protocol.
UINT32 BackLog
the limit of connection to this socket
SOCK_DESTROY_CALLBACK DestroyCallback
Callback before destroyed.
NET_PROTOCOL NetProtocol
TCP4 or TCP6 protocol socket used.
SOCK_PROTO_HANDLER ProtoHandler
The request handler of protocol.
EFI_HANDLE DriverBinding
Socket's driver binding protocol.
UINT32 ConnCnt
the current count of connections to it
SOCK_BUFFER SndBuffer
Send buffer of application's data.
SOCK_CREATE_CALLBACK CreateCallback
Callback after created.
VOID * Context
The context of the callback.