TianoCore EDK2 master
Loading...
Searching...
No Matches
Socket.h
Go to the documentation of this file.
1
10#ifndef _SOCKET_H_
11#define _SOCKET_H_
12
13#include <Uefi.h>
14
15#include <Protocol/Tcp4.h>
16#include <Protocol/Tcp6.h>
17
18#include <Library/NetLib.h>
19#include <Library/DebugLib.h>
24#include <Library/UefiLib.h>
25#include <Library/DpcLib.h>
26
27#define SOCK_SND_BUF 0
28#define SOCK_RCV_BUF 1
29
30#define SOCK_BUFF_LOW_WATER (2 * 1024)
31#define SOCK_RCV_BUFF_SIZE (8 * 1024)
32#define SOCK_SND_BUFF_SIZE (8 * 1024)
33#define SOCK_BACKLOG 5
34
35#define PROTO_RESERVED_LEN 20
36
37#define SO_NO_MORE_DATA 0x0001
38
39//
40//
41//
42// When a socket is created it enters into SO_UNCONFIGURED,
43// no actions can be taken on this socket, only after calling
44// SockConfigure. The state transition diagram of socket is
45// as following:
46//
47// SO_UNCONFIGURED --- SO_CONFIGURED --- SO_CONNECTING
48// ^ | |
49// | ---> SO_LISTENING |
50// | |
51// |------------------SO_DISCONNECTING<-- SO_CONNECTED
52//
53// A passive socket can only go into SO_LISTENING and
54// SO_UNCONFIGURED state. SO_XXXING state is a middle state
55// when a socket is undergoing a protocol procedure such
56// as requesting a TCP connection.
57//
58//
59//
60
64#define SO_CLOSED 0
65#define SO_LISTENING 1
66#define SO_CONNECTING 2
67#define SO_CONNECTED 3
68#define SO_DISCONNECTING 4
69
73#define SO_UNCONFIGURED 0
74#define SO_CONFIGURED_ACTIVE 1
75#define SO_CONFIGURED_PASSIVE 2
76#define SO_NO_MAPPING 3
77
81#define SOCK_ATTACH 0
82#define SOCK_DETACH 1
83#define SOCK_CONFIGURE 2
84#define SOCK_FLUSH 3
85#define SOCK_SND 4
86#define SOCK_SNDPUSH 5
87#define SOCK_SNDURG 6
88#define SOCK_CONSUMED 7
89#define SOCK_CONNECT 8
90#define SOCK_CLOSE 9
91#define SOCK_ABORT 10
92#define SOCK_POLL 11
93#define SOCK_ROUTE 12
94#define SOCK_MODE 13
95#define SOCK_GROUP 14
96
103#define SOCK_NO_MORE_DATA(Sock) ((Sock)->Flag |= SO_NO_MORE_DATA)
104
114#define SOCK_IS_UNCONFIGURED(Sock) ((Sock)->ConfigureState == SO_UNCONFIGURED)
115
125#define SOCK_IS_CONFIGURED(Sock) \
126 (((Sock)->ConfigureState == SO_CONFIGURED_ACTIVE) || \
127 ((Sock)->ConfigureState == SO_CONFIGURED_PASSIVE))
128
138#define SOCK_IS_CONFIGURED_ACTIVE(Sock) ((Sock)->ConfigureState == SO_CONFIGURED_ACTIVE)
139
149#define SOCK_IS_CONNECTED_PASSIVE(Sock) ((Sock)->ConfigureState == SO_CONFIGURED_PASSIVE)
150
160#define SOCK_IS_NO_MAPPING(Sock) ((Sock)->ConfigureState == SO_NO_MAPPING)
161
171#define SOCK_IS_CLOSED(Sock) ((Sock)->State == SO_CLOSED)
172
182#define SOCK_IS_LISTENING(Sock) ((Sock)->State == SO_LISTENING)
183
193#define SOCK_IS_CONNECTING(Sock) ((Sock)->State == SO_CONNECTING)
194
204#define SOCK_IS_CONNECTED(Sock) ((Sock)->State == SO_CONNECTED)
205
215#define SOCK_IS_DISCONNECTING(Sock) ((Sock)->State == SO_DISCONNECTING)
216
226#define SOCK_IS_NO_MORE_DATA(Sock) (0 != ((Sock)->Flag & SO_NO_MORE_DATA))
227
235#define SET_RCV_BUFFSIZE(Sock, Size) ((Sock)->RcvBuffer.HighWater = (Size))
236
245#define GET_RCV_BUFFSIZE(Sock) ((Sock)->RcvBuffer.HighWater)
246
255#define GET_RCV_DATASIZE(Sock) (((Sock)->RcvBuffer.DataQueue)->BufSize)
256
264#define SET_SND_BUFFSIZE(Sock, Size) ((Sock)->SndBuffer.HighWater = (Size))
265
274#define GET_SND_BUFFSIZE(Sock) ((Sock)->SndBuffer.HighWater)
275
284#define GET_SND_DATASIZE(Sock) (((Sock)->SndBuffer.DataQueue)->BufSize)
285
293#define SET_BACKLOG(Sock, Value) ((Sock)->BackLog = (Value))
294
303#define GET_BACKLOG(Sock) ((Sock)->BackLog)
304
312#define SOCK_ERROR(Sock, Error) ((Sock)->SockError = (Error))
313
314#define SOCK_SIGNATURE SIGNATURE_32 ('S', 'O', 'C', 'K')
315
316#define SOCK_FROM_THIS(a) CR ((a), SOCKET, NetProtocol, SOCK_SIGNATURE)
317
318#define SOCK_FROM_TOKEN(Token) (((SOCK_TOKEN *) (Token))->Sock)
319
320#define PROTO_TOKEN_FORM_SOCK(SockToken, Type) ((Type *) (((SOCK_TOKEN *) (SockToken))->Token))
321
322typedef struct _TCP_SOCKET SOCKET;
323
331
332typedef union {
333 VOID *RxData;
334 VOID *TxData;
336
340typedef struct _SOCK_IO_TOKEN {
342 SOCK_IO_DATA Packet;
344
348typedef enum {
352
356typedef struct _SOCK_BUFFER {
357 UINT32 HighWater;
358 UINT32 LowWater;
361
374typedef
377 IN SOCKET *Socket,
378 IN UINT8 Request,
379 IN VOID *RequestData
380 );
381
392typedef
395 IN SOCKET *This,
396 IN VOID *Context
397 );
398
406typedef
407VOID
409 IN SOCKET *This,
410 IN VOID *Context
411 );
412
416typedef struct _SOCK_INIT_DATA {
417 SOCK_TYPE Type;
418 UINT8 State;
419
421 UINT32 BackLog;
424 UINT8 IpVersion;
425 VOID *Protocol;
427
428 //
429 // Callbacks after socket is created and before socket is to be destroyed.
430 //
433 VOID *Context;
434
435 //
436 // Opaque protocol data.
437 //
438 VOID *ProtoData;
439 UINT32 DataSize;
440
442
445
449typedef union _NET_PROTOCOL {
457 //
458 // Socket description information
459 //
460 UINT32 Signature;
463 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
464 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
465 LIST_ENTRY Link;
466 UINT8 ConfigureState;
467 SOCK_TYPE Type;
468 UINT8 State;
469 UINT16 Flag;
474 BOOLEAN InDestroy;
475
476 //
477 // Fields used to manage the connection request
478 //
479 UINT32 BackLog;
480 UINT32 ConnCnt;
483 //
484 // The queue to buffer application's asynchronous token
485 //
486 LIST_ENTRY ListenTokenList;
487 LIST_ENTRY RcvTokenList;
488 LIST_ENTRY SndTokenList;
489 LIST_ENTRY ProcessingSndTokenList;
490
493 //
494 // Interface for low level protocol
495 //
497 UINT8 ProtoReserved[PROTO_RESERVED_LEN];
498 UINT8 IpVersion;
500 //
501 // Callbacks after socket is created and before socket is to be destroyed.
502 //
505 VOID *Context;
506};
507
511typedef struct _SOCK_TOKEN {
518
522typedef struct _TCP_RSV_DATA {
523 UINT32 UrgLen;
525
526//
527// Socket provided operations for low layer protocol implemented in SockImpl.c
528//
529
537VOID
539 IN OUT SOCKET *Sock,
540 IN UINT8 State
541 );
542
551SOCKET *
552SockClone (
553 IN SOCKET *Sock
554 );
555
567VOID
569 IN OUT SOCKET *Sock
570 );
571
582VOID
584 IN OUT SOCKET *Sock
585 );
586
597VOID
599 IN OUT SOCKET *Sock,
600 IN UINT32 Count
601 );
602
616UINT32
618 IN SOCKET *Sock,
619 IN UINT32 Offset,
620 IN UINT32 Len,
621 OUT UINT8 *Dest
622 );
623
635VOID
637 IN OUT SOCKET *Sock,
638 IN OUT NET_BUF *NetBuffer,
639 IN UINT32 UrgLen
640 );
641
652UINT32
654 IN SOCKET *Sock,
655 IN UINT32 Which
656 );
657
668VOID
670 IN OUT SOCKET *Sock
671 );
672
673//
674// Socket provided operations for user interface implemented in SockInterface.c
675//
676
687SOCKET *
689 IN SOCK_INIT_DATA *SockInitData
690 );
691
703 IN OUT SOCKET *Sock
704 );
705
719 IN SOCKET *Sock,
720 IN VOID *ConfigData
721 );
722
743 IN SOCKET *Sock,
744 IN VOID *Token
745 );
746
768 IN SOCKET *Sock,
769 IN VOID *Token
770 );
771
791SockSend (
792 IN SOCKET *Sock,
793 IN VOID *Token
794 );
795
816SockRcv (
817 IN SOCKET *Sock,
818 IN VOID *Token
819 );
820
831SockFlush (
832 IN OUT SOCKET *Sock
833 );
834
855SockClose (
856 IN OUT SOCKET *Sock,
857 IN VOID *Token,
858 IN BOOLEAN OnAbort
859 );
860
875 IN OUT SOCKET *Sock,
876 IN VOID *Token
877 );
878
892 IN SOCKET *Sock,
893 IN OUT VOID *Mode
894 );
895
912SockRoute (
913 IN SOCKET *Sock,
914 IN VOID *RouteInfo
915 );
916
917#endif
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
EFI_STATUS SockFlush(IN OUT SOCKET *Sock)
VOID SockDataRcvd(IN OUT SOCKET *Sock, IN OUT NET_BUF *NetBuffer, IN UINT32 UrgLen)
Definition: SockImpl.c:1125
SOCKET * SockCreateChild(IN SOCK_INIT_DATA *SockInitData)
struct _TCP_RSV_DATA TCP_RSV_DATA
EFI_STATUS SockClose(IN OUT SOCKET *Sock, IN VOID *Token, IN BOOLEAN OnAbort)
struct _SOCK_IO_TOKEN SOCK_IO_TOKEN
EFI_STATUS SockConnect(IN SOCKET *Sock, IN VOID *Token)
EFI_STATUS(* SOCK_CREATE_CALLBACK)(IN SOCKET *This, IN VOID *Context)
Definition: Socket.h:394
struct _SOCK_COMPLETION_TOKEN SOCK_COMPLETION_TOKEN
EFI_STATUS SockRcv(IN SOCKET *Sock, IN VOID *Token)
struct _SOCK_INIT_DATA SOCK_INIT_DATA
UINT32 SockGetFreeSpace(IN SOCKET *Sock, IN UINT32 Which)
Definition: SockImpl.c:1156
EFI_STATUS(* SOCK_PROTO_HANDLER)(IN SOCKET *Socket, IN UINT8 Request, IN VOID *RequestData)
Definition: Socket.h:376
SOCK_TYPE
Definition: Socket.h:348
@ SockDgram
This socket providing datagram service.
Definition: Socket.h:349
@ SockStream
This socket providing stream service.
Definition: Socket.h:350
VOID SockNoMoreData(IN OUT SOCKET *Sock)
Definition: SockImpl.c:1192
SOCKET * SockClone(IN SOCKET *Sock)
Definition: SockImpl.c:937
UINT32 SockGetDataToSend(IN SOCKET *Sock, IN UINT32 Offset, IN UINT32 Len, OUT UINT8 *Dest)
Definition: SockImpl.c:1096
VOID SockSetState(IN OUT SOCKET *Sock, IN UINT8 State)
Definition: SockImpl.c:920
struct _SOCK_TOKEN SOCK_TOKEN
union _NET_PROTOCOL NET_PROTOCOL
EFI_STATUS SockRoute(IN SOCKET *Sock, IN VOID *RouteInfo)
EFI_STATUS SockDestroyChild(IN OUT SOCKET *Sock)
EFI_STATUS SockSend(IN SOCKET *Sock, IN VOID *Token)
VOID SockConnClosed(IN OUT SOCKET *Sock)
Definition: SockImpl.c:1011
EFI_STATUS SockAccept(IN SOCKET *Sock, IN VOID *Token)
struct _SOCK_BUFFER SOCK_BUFFER
VOID SockDataSent(IN OUT SOCKET *Sock, IN UINT32 Count)
Definition: SockImpl.c:1039
EFI_STATUS SockGetMode(IN SOCKET *Sock, IN OUT VOID *Mode)
VOID SockConnEstablished(IN OUT SOCKET *Sock)
Definition: SockImpl.c:985
EFI_STATUS SockCancel(IN OUT SOCKET *Sock, IN VOID *Token)
VOID(* SOCK_DESTROY_CALLBACK)(IN SOCKET *This, IN VOID *Context)
Definition: Socket.h:408
EFI_STATUS SockConfigure(IN SOCKET *Sock, IN VOID *ConfigData)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
NET_BUF_QUEUE * DataQueue
The queue to buffer data.
Definition: Socket.h:359
UINT32 LowWater
The low water mark of sock_buffer.
Definition: Socket.h:358
UINT32 HighWater
The buffersize upper limit of sock_buffer.
Definition: Socket.h:357
EFI_STATUS Status
The status to be issued.
Definition: Socket.h:329
EFI_EVENT Event
The event to be issued.
Definition: Socket.h:328
UINT32 SndBufferSize
The high water mark of send buffer.
Definition: Socket.h:422
SOCK_PROTO_HANDLER ProtoHandler
The handler of protocol for socket request.
Definition: Socket.h:441
VOID * Protocol
Definition: Socket.h:425
SOCKET * Parent
The parent of this socket.
Definition: Socket.h:420
EFI_HANDLE DriverBinding
The driver binding handle.
Definition: Socket.h:443
VOID * Context
The context of the callback.
Definition: Socket.h:433
UINT32 BackLog
The connection limit for listening socket.
Definition: Socket.h:421
UINT32 RcvBufferSize
The high water mark of receive buffer.
Definition: Socket.h:423
SOCK_CREATE_CALLBACK CreateCallback
Callback after created.
Definition: Socket.h:431
SOCK_DESTROY_CALLBACK DestroyCallback
Callback before destroyed.
Definition: Socket.h:432
LIST_ENTRY TokenList
The entry to add in the token list.
Definition: Socket.h:512
SOCKET * Sock
Definition: Socket.h:515
SOCK_COMPLETION_TOKEN * Token
The application's token.
Definition: Socket.h:513
UINT32 RemainDataLen
Unprocessed data length.
Definition: Socket.h:514
SOCK_BUFFER RcvBuffer
Receive buffer of received data.
Definition: Socket.h:472
LIST_ENTRY ConnectionList
the connections maintained by this socket
Definition: Socket.h:482
UINT8 ProtoReserved[PROTO_RESERVED_LEN]
Data fields reserved for protocol.
Definition: Socket.h:497
SOCKET * Parent
listening parent that accept the connection
Definition: Socket.h:481
UINT32 Signature
Signature of the socket.
Definition: Socket.h:460
EFI_LOCK Lock
The lock of socket.
Definition: Socket.h:470
EFI_HANDLE SockHandle
The virtual handle of the socket.
Definition: Socket.h:461
EFI_STATUS SockError
The error returned by low layer protocol.
Definition: Socket.h:473
SOCK_COMPLETION_TOKEN * CloseToken
app's token to signal if closed
Definition: Socket.h:492
UINT32 BackLog
the limit of connection to this socket
Definition: Socket.h:479
SOCK_DESTROY_CALLBACK DestroyCallback
Callback before destroyed.
Definition: Socket.h:504
NET_PROTOCOL NetProtocol
TCP4 or TCP6 protocol socket used.
Definition: Socket.h:499
SOCK_PROTO_HANDLER ProtoHandler
The request handler of protocol.
Definition: Socket.h:496
EFI_HANDLE DriverBinding
Socket's driver binding protocol.
Definition: Socket.h:462
UINT32 ConnCnt
the current count of connections to it
Definition: Socket.h:480
SOCK_BUFFER SndBuffer
Send buffer of application's data.
Definition: Socket.h:471
SOCK_COMPLETION_TOKEN * ConnectionToken
app's token to signal if connected
Definition: Socket.h:491
SOCK_CREATE_CALLBACK CreateCallback
Callback after created.
Definition: Socket.h:503
VOID * Context
The context of the callback.
Definition: Socket.h:505
EFI_TCP4_PROTOCOL Tcp4Protocol
Tcp4 protocol.
Definition: Socket.h:450
EFI_TCP6_PROTOCOL Tcp6Protocol
Tcp6 protocol.
Definition: Socket.h:451