Socket.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. /** @file
  2. Common head file for TCP socket.
  3. Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #ifndef _SOCKET_H_
  7. #define _SOCKET_H_
  8. #include <Uefi.h>
  9. #include <Protocol/Tcp4.h>
  10. #include <Protocol/Tcp6.h>
  11. #include <Library/NetLib.h>
  12. #include <Library/DebugLib.h>
  13. #include <Library/BaseMemoryLib.h>
  14. #include <Library/MemoryAllocationLib.h>
  15. #include <Library/UefiRuntimeServicesTableLib.h>
  16. #include <Library/UefiBootServicesTableLib.h>
  17. #include <Library/UefiLib.h>
  18. #include <Library/DpcLib.h>
  19. #define SOCK_SND_BUF 0
  20. #define SOCK_RCV_BUF 1
  21. #define SOCK_BUFF_LOW_WATER (2 * 1024)
  22. #define SOCK_RCV_BUFF_SIZE (8 * 1024)
  23. #define SOCK_SND_BUFF_SIZE (8 * 1024)
  24. #define SOCK_BACKLOG 5
  25. #define PROTO_RESERVED_LEN 20
  26. #define SO_NO_MORE_DATA 0x0001
  27. //
  28. //
  29. //
  30. // When a socket is created it enters into SO_UNCONFIGURED,
  31. // no actions can be taken on this socket, only after calling
  32. // SockConfigure. The state transition diagram of socket is
  33. // as following:
  34. //
  35. // SO_UNCONFIGURED --- SO_CONFIGURED --- SO_CONNECTING
  36. // ^ | |
  37. // | ---> SO_LISTENING |
  38. // | |
  39. // |------------------SO_DISCONNECTING<-- SO_CONNECTED
  40. //
  41. // A passive socket can only go into SO_LISTENING and
  42. // SO_UNCONFIGURED state. SO_XXXING state is a middle state
  43. // when a socket is undergoing a protocol procedure such
  44. // as requesting a TCP connection.
  45. //
  46. //
  47. //
  48. ///
  49. /// Socket state
  50. ///
  51. #define SO_CLOSED 0
  52. #define SO_LISTENING 1
  53. #define SO_CONNECTING 2
  54. #define SO_CONNECTED 3
  55. #define SO_DISCONNECTING 4
  56. ///
  57. /// Socket configure state
  58. ///
  59. #define SO_UNCONFIGURED 0
  60. #define SO_CONFIGURED_ACTIVE 1
  61. #define SO_CONFIGURED_PASSIVE 2
  62. #define SO_NO_MAPPING 3
  63. ///
  64. /// The request issued from socket layer to protocol layer.
  65. ///
  66. #define SOCK_ATTACH 0 ///< Attach current socket to a new PCB
  67. #define SOCK_DETACH 1 ///< Detach current socket from the PCB
  68. #define SOCK_CONFIGURE 2 ///< Configure attached PCB
  69. #define SOCK_FLUSH 3 ///< Flush attached PCB
  70. #define SOCK_SND 4 ///< Need protocol to send something
  71. #define SOCK_SNDPUSH 5 ///< Need protocol to send pushed data
  72. #define SOCK_SNDURG 6 ///< Need protocol to send urgent data
  73. #define SOCK_CONSUMED 7 ///< Application has retrieved data from socket
  74. #define SOCK_CONNECT 8 ///< Need to connect to a peer
  75. #define SOCK_CLOSE 9 ///< Need to close the protocol process
  76. #define SOCK_ABORT 10 ///< Need to reset the protocol process
  77. #define SOCK_POLL 11 ///< Need to poll to the protocol layer
  78. #define SOCK_ROUTE 12 ///< Need to add a route information
  79. #define SOCK_MODE 13 ///< Need to get the mode data of the protocol
  80. #define SOCK_GROUP 14 ///< Need to join a mcast group
  81. /**
  82. Set socket SO_NO_MORE_DATA flag.
  83. @param[in] Sock Pointer to the socket
  84. **/
  85. #define SOCK_NO_MORE_DATA(Sock) ((Sock)->Flag |= SO_NO_MORE_DATA)
  86. /**
  87. Check whether the socket is unconfigured.
  88. @param[in] Sock Pointer to the socket.
  89. @retval TRUE The socket is unconfigured.
  90. @retval FALSE The socket is not unconfigured.
  91. **/
  92. #define SOCK_IS_UNCONFIGURED(Sock) ((Sock)->ConfigureState == SO_UNCONFIGURED)
  93. /**
  94. Check whether the socket is configured.
  95. @param[in] Sock Pointer to the socket
  96. @retval TRUE The socket is configured
  97. @retval FALSE The socket is not configured
  98. **/
  99. #define SOCK_IS_CONFIGURED(Sock) \
  100. (((Sock)->ConfigureState == SO_CONFIGURED_ACTIVE) || \
  101. ((Sock)->ConfigureState == SO_CONFIGURED_PASSIVE))
  102. /**
  103. Check whether the socket is configured to active mode.
  104. @param[in] Sock Pointer to the socket.
  105. @retval TRUE The socket is configured to active mode.
  106. @retval FALSE The socket is not configured to active mode.
  107. **/
  108. #define SOCK_IS_CONFIGURED_ACTIVE(Sock) ((Sock)->ConfigureState == SO_CONFIGURED_ACTIVE)
  109. /**
  110. Check whether the socket is configured to passive mode.
  111. @param[in] Sock Pointer to the socket.
  112. @retval TRUE The socket is configured to passive mode.
  113. @retval FALSE The socket is not configured to passive mode.
  114. **/
  115. #define SOCK_IS_CONNECTED_PASSIVE(Sock) ((Sock)->ConfigureState == SO_CONFIGURED_PASSIVE)
  116. /**
  117. Check whether the socket is mapped.
  118. @param[in] Sock Pointer to the socket.
  119. @retval TRUE The socket is not mapping.
  120. @retval FALSE The socket is mapped.
  121. **/
  122. #define SOCK_IS_NO_MAPPING(Sock) ((Sock)->ConfigureState == SO_NO_MAPPING)
  123. /**
  124. Check whether the socket is closed.
  125. @param[in] Sock Pointer to the socket.
  126. @retval TRUE The socket is closed.
  127. @retval FALSE The socket is not closed.
  128. **/
  129. #define SOCK_IS_CLOSED(Sock) ((Sock)->State == SO_CLOSED)
  130. /**
  131. Check whether the socket is listening.
  132. @param[in] Sock Pointer to the socket.
  133. @retval TRUE The socket is listening.
  134. @retval FALSE The socket is not listening.
  135. **/
  136. #define SOCK_IS_LISTENING(Sock) ((Sock)->State == SO_LISTENING)
  137. /**
  138. Check whether the socket is connecting.
  139. @param[in] Sock Pointer to the socket.
  140. @retval TRUE The socket is connecting.
  141. @retval FALSE The socket is not connecting.
  142. **/
  143. #define SOCK_IS_CONNECTING(Sock) ((Sock)->State == SO_CONNECTING)
  144. /**
  145. Check whether the socket has connected.
  146. @param[in] Sock Pointer to the socket.
  147. @retval TRUE The socket has connected.
  148. @retval FALSE The socket has not connected.
  149. **/
  150. #define SOCK_IS_CONNECTED(Sock) ((Sock)->State == SO_CONNECTED)
  151. /**
  152. Check whether the socket is disconnecting.
  153. @param[in] Sock Pointer to the socket.
  154. @retval TRUE The socket is disconnecting.
  155. @retval FALSE The socket is not disconnecting.
  156. **/
  157. #define SOCK_IS_DISCONNECTING(Sock) ((Sock)->State == SO_DISCONNECTING)
  158. /**
  159. Check whether the socket is no more data.
  160. @param[in] Sock Pointer to the socket.
  161. @retval TRUE The socket is no more data.
  162. @retval FALSE The socket still has data.
  163. **/
  164. #define SOCK_IS_NO_MORE_DATA(Sock) (0 != ((Sock)->Flag & SO_NO_MORE_DATA))
  165. /**
  166. Set the size of the receive buffer.
  167. @param[in] Sock Pointer to the socket.
  168. @param[in] Size The size to set.
  169. **/
  170. #define SET_RCV_BUFFSIZE(Sock, Size) ((Sock)->RcvBuffer.HighWater = (Size))
  171. /**
  172. Get the size of the receive buffer.
  173. @param[in] Sock Pointer to the socket.
  174. @return The receive buffer size.
  175. **/
  176. #define GET_RCV_BUFFSIZE(Sock) ((Sock)->RcvBuffer.HighWater)
  177. /**
  178. Get the size of the receive data.
  179. @param[in] Sock Pointer to the socket.
  180. @return The received data size.
  181. **/
  182. #define GET_RCV_DATASIZE(Sock) (((Sock)->RcvBuffer.DataQueue)->BufSize)
  183. /**
  184. Set the size of the send buffer.
  185. @param[in] Sock Pointer to the socket.
  186. @param[in] Size The size to set.
  187. **/
  188. #define SET_SND_BUFFSIZE(Sock, Size) ((Sock)->SndBuffer.HighWater = (Size))
  189. /**
  190. Get the size of the send buffer.
  191. @param[in] Sock Pointer to the socket.
  192. @return The send buffer size.
  193. **/
  194. #define GET_SND_BUFFSIZE(Sock) ((Sock)->SndBuffer.HighWater)
  195. /**
  196. Get the size of the send data.
  197. @param[in] Sock Pointer to the socket.
  198. @return The send data size.
  199. **/
  200. #define GET_SND_DATASIZE(Sock) (((Sock)->SndBuffer.DataQueue)->BufSize)
  201. /**
  202. Set the backlog value of the socket.
  203. @param[in] Sock Pointer to the socket.
  204. @param[in] Value The value to set.
  205. **/
  206. #define SET_BACKLOG(Sock, Value) ((Sock)->BackLog = (Value))
  207. /**
  208. Get the backlog value of the socket.
  209. @param[in] Sock Pointer to the socket.
  210. @return The backlog value.
  211. **/
  212. #define GET_BACKLOG(Sock) ((Sock)->BackLog)
  213. /**
  214. Set the socket with error state.
  215. @param[in] Sock Pointer to the socket.
  216. @param[in] Error The error state.
  217. **/
  218. #define SOCK_ERROR(Sock, Error) ((Sock)->SockError = (Error))
  219. #define SOCK_SIGNATURE SIGNATURE_32 ('S', 'O', 'C', 'K')
  220. #define SOCK_FROM_THIS(a) CR ((a), SOCKET, NetProtocol, SOCK_SIGNATURE)
  221. #define SOCK_FROM_TOKEN(Token) (((SOCK_TOKEN *) (Token))->Sock)
  222. #define PROTO_TOKEN_FORM_SOCK(SockToken, Type) ((Type *) (((SOCK_TOKEN *) (SockToken))->Token))
  223. typedef struct _TCP_SOCKET SOCKET;
  224. ///
  225. /// Socket completion token
  226. ///
  227. typedef struct _SOCK_COMPLETION_TOKEN {
  228. EFI_EVENT Event; ///< The event to be issued
  229. EFI_STATUS Status; ///< The status to be issued
  230. } SOCK_COMPLETION_TOKEN;
  231. typedef union {
  232. VOID *RxData;
  233. VOID *TxData;
  234. } SOCK_IO_DATA;
  235. ///
  236. /// The application token with data packet
  237. ///
  238. typedef struct _SOCK_IO_TOKEN {
  239. SOCK_COMPLETION_TOKEN Token;
  240. SOCK_IO_DATA Packet;
  241. } SOCK_IO_TOKEN;
  242. ///
  243. /// The socket type.
  244. ///
  245. typedef enum {
  246. SockDgram, ///< This socket providing datagram service
  247. SockStream ///< This socket providing stream service
  248. } SOCK_TYPE;
  249. ///
  250. /// The buffer structure of rcvd data and send data used by socket.
  251. ///
  252. typedef struct _SOCK_BUFFER {
  253. UINT32 HighWater; ///< The buffersize upper limit of sock_buffer
  254. UINT32 LowWater; ///< The low water mark of sock_buffer
  255. NET_BUF_QUEUE *DataQueue; ///< The queue to buffer data
  256. } SOCK_BUFFER;
  257. /**
  258. The handler of protocol for request from socket.
  259. @param[in] Socket The socket issuing the request to protocol.
  260. @param[in] Request The request issued by socket.
  261. @param[in] RequestData The request related data.
  262. @retval EFI_SUCCESS The socket request is completed successfully.
  263. @retval other The error status returned by the corresponding TCP
  264. layer function.
  265. **/
  266. typedef
  267. EFI_STATUS
  268. (*SOCK_PROTO_HANDLER) (
  269. IN SOCKET *Socket,
  270. IN UINT8 Request,
  271. IN VOID *RequestData
  272. );
  273. /**
  274. The Callback function called after the TCP socket is created.
  275. @param[in] This Pointer to the socket just created.
  276. @param[in] Context Context of the socket.
  277. @retval EFI_SUCCESS This protocol installed successfully.
  278. @retval other Some error occurred.
  279. **/
  280. typedef
  281. EFI_STATUS
  282. (*SOCK_CREATE_CALLBACK) (
  283. IN SOCKET *This,
  284. IN VOID *Context
  285. );
  286. /**
  287. The callback function called before the TCP socket is to be destroyed.
  288. @param[in] This The TCP socket to be destroyed.
  289. @param[in] Context The context.
  290. **/
  291. typedef
  292. VOID
  293. (*SOCK_DESTROY_CALLBACK) (
  294. IN SOCKET *This,
  295. IN VOID *Context
  296. );
  297. ///
  298. /// The initialize data for create a new socket.
  299. ///
  300. typedef struct _SOCK_INIT_DATA {
  301. SOCK_TYPE Type;
  302. UINT8 State;
  303. SOCKET *Parent; ///< The parent of this socket
  304. UINT32 BackLog; ///< The connection limit for listening socket
  305. UINT32 SndBufferSize; ///< The high water mark of send buffer
  306. UINT32 RcvBufferSize; ///< The high water mark of receive buffer
  307. UINT8 IpVersion;
  308. VOID *Protocol; ///< The pointer to protocol function template
  309. ///< wanted to install on socket
  310. //
  311. // Callbacks after socket is created and before socket is to be destroyed.
  312. //
  313. SOCK_CREATE_CALLBACK CreateCallback; ///< Callback after created
  314. SOCK_DESTROY_CALLBACK DestroyCallback; ///< Callback before destroyed
  315. VOID *Context; ///< The context of the callback
  316. //
  317. // Opaque protocol data.
  318. //
  319. VOID *ProtoData;
  320. UINT32 DataSize;
  321. SOCK_PROTO_HANDLER ProtoHandler; ///< The handler of protocol for socket request
  322. EFI_HANDLE DriverBinding; ///< The driver binding handle
  323. } SOCK_INIT_DATA;
  324. ///
  325. /// The union type of TCP4 and TCP6 protocol.
  326. ///
  327. typedef union _NET_PROTOCOL {
  328. EFI_TCP4_PROTOCOL Tcp4Protocol; ///< Tcp4 protocol
  329. EFI_TCP6_PROTOCOL Tcp6Protocol; ///< Tcp6 protocol
  330. } NET_PROTOCOL;
  331. ///
  332. /// The socket structure representing a network service access point.
  333. ///
  334. struct _TCP_SOCKET {
  335. //
  336. // Socket description information
  337. //
  338. UINT32 Signature; ///< Signature of the socket
  339. EFI_HANDLE SockHandle; ///< The virtual handle of the socket
  340. EFI_HANDLE DriverBinding; ///< Socket's driver binding protocol
  341. EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
  342. EFI_DEVICE_PATH_PROTOCOL *DevicePath;
  343. LIST_ENTRY Link;
  344. UINT8 ConfigureState;
  345. SOCK_TYPE Type;
  346. UINT8 State;
  347. UINT16 Flag;
  348. EFI_LOCK Lock; ///< The lock of socket
  349. SOCK_BUFFER SndBuffer; ///< Send buffer of application's data
  350. SOCK_BUFFER RcvBuffer; ///< Receive buffer of received data
  351. EFI_STATUS SockError; ///< The error returned by low layer protocol
  352. BOOLEAN InDestroy;
  353. //
  354. // Fields used to manage the connection request
  355. //
  356. UINT32 BackLog; ///< the limit of connection to this socket
  357. UINT32 ConnCnt; ///< the current count of connections to it
  358. SOCKET *Parent; ///< listening parent that accept the connection
  359. LIST_ENTRY ConnectionList; ///< the connections maintained by this socket
  360. //
  361. // The queue to buffer application's asynchronous token
  362. //
  363. LIST_ENTRY ListenTokenList;
  364. LIST_ENTRY RcvTokenList;
  365. LIST_ENTRY SndTokenList;
  366. LIST_ENTRY ProcessingSndTokenList;
  367. SOCK_COMPLETION_TOKEN *ConnectionToken; ///< app's token to signal if connected
  368. SOCK_COMPLETION_TOKEN *CloseToken; ///< app's token to signal if closed
  369. //
  370. // Interface for low level protocol
  371. //
  372. SOCK_PROTO_HANDLER ProtoHandler; ///< The request handler of protocol
  373. UINT8 ProtoReserved[PROTO_RESERVED_LEN]; ///< Data fields reserved for protocol
  374. UINT8 IpVersion;
  375. NET_PROTOCOL NetProtocol; ///< TCP4 or TCP6 protocol socket used
  376. //
  377. // Callbacks after socket is created and before socket is to be destroyed.
  378. //
  379. SOCK_CREATE_CALLBACK CreateCallback; ///< Callback after created
  380. SOCK_DESTROY_CALLBACK DestroyCallback; ///< Callback before destroyed
  381. VOID *Context; ///< The context of the callback
  382. };
  383. ///
  384. /// The token structure buffered in socket layer.
  385. ///
  386. typedef struct _SOCK_TOKEN {
  387. LIST_ENTRY TokenList; ///< The entry to add in the token list
  388. SOCK_COMPLETION_TOKEN *Token; ///< The application's token
  389. UINT32 RemainDataLen; ///< Unprocessed data length
  390. SOCKET *Sock; ///< The pointer to the socket this token
  391. ///< belongs to
  392. } SOCK_TOKEN;
  393. ///
  394. /// Reserved data to access the NET_BUF delivered by TCP driver.
  395. ///
  396. typedef struct _TCP_RSV_DATA {
  397. UINT32 UrgLen;
  398. } TCP_RSV_DATA;
  399. //
  400. // Socket provided operations for low layer protocol implemented in SockImpl.c
  401. //
  402. /**
  403. Set the state of the socket.
  404. @param[in, out] Sock Pointer to the socket.
  405. @param[in] State The new socket state to be set.
  406. **/
  407. VOID
  408. SockSetState (
  409. IN OUT SOCKET *Sock,
  410. IN UINT8 State
  411. );
  412. /**
  413. Clone a new socket including its associated protocol control block.
  414. @param[in] Sock Pointer to the socket to be cloned.
  415. @return Pointer to the newly cloned socket. If NULL, an error condition occurred.
  416. **/
  417. SOCKET *
  418. SockClone (
  419. IN SOCKET *Sock
  420. );
  421. /**
  422. Called by the low layer protocol to indicate the socket a connection is
  423. established.
  424. This function just changes the socket's state to SO_CONNECTED
  425. and signals the token used for connection establishment.
  426. @param[in, out] Sock Pointer to the socket associated with the
  427. established connection.
  428. **/
  429. VOID
  430. SockConnEstablished (
  431. IN OUT SOCKET *Sock
  432. );
  433. /**
  434. Called by the low layer protocol to indicate that the connection is closed.
  435. This function flushes the socket, sets the state to SO_CLOSED, and signals
  436. the close token.
  437. @param[in, out] Sock Pointer to the socket associated with the closed
  438. connection.
  439. **/
  440. VOID
  441. SockConnClosed (
  442. IN OUT SOCKET *Sock
  443. );
  444. /**
  445. Called by low layer protocol to indicate that some data is sent or processed.
  446. This function trims the sent data in the socket send buffer and signals the data
  447. token, if proper.
  448. @param[in, out] Sock Pointer to the socket.
  449. @param[in] Count The length of the data processed or sent, in bytes.
  450. **/
  451. VOID
  452. SockDataSent (
  453. IN OUT SOCKET *Sock,
  454. IN UINT32 Count
  455. );
  456. /**
  457. Called by the low layer protocol to copy some data in socket send
  458. buffer starting from the specific offset to a buffer provided by
  459. the caller.
  460. @param[in] Sock Pointer to the socket.
  461. @param[in] Offset The start point of the data to be copied.
  462. @param[in] Len The length of the data to be copied.
  463. @param[out] Dest Pointer to the destination to copy the data.
  464. @return The data size copied.
  465. **/
  466. UINT32
  467. SockGetDataToSend (
  468. IN SOCKET *Sock,
  469. IN UINT32 Offset,
  470. IN UINT32 Len,
  471. OUT UINT8 *Dest
  472. );
  473. /**
  474. Called by the low layer protocol to deliver received data to socket layer.
  475. This function appends the data to the socket receive buffer, set the
  476. urgent data length, then checks if any receive token can be signaled.
  477. @param[in, out] Sock Pointer to the socket.
  478. @param[in, out] NetBuffer Pointer to the buffer that contains the received data.
  479. @param[in] UrgLen The length of the urgent data in the received data.
  480. **/
  481. VOID
  482. SockDataRcvd (
  483. IN OUT SOCKET *Sock,
  484. IN OUT NET_BUF *NetBuffer,
  485. IN UINT32 UrgLen
  486. );
  487. /**
  488. Get the length of the free space of the specific socket buffer.
  489. @param[in] Sock Pointer to the socket.
  490. @param[in] Which Flag to indicate which socket buffer to check:
  491. either send buffer or receive buffer.
  492. @return The length of the free space, in bytes.
  493. **/
  494. UINT32
  495. SockGetFreeSpace (
  496. IN SOCKET *Sock,
  497. IN UINT32 Which
  498. );
  499. /**
  500. Called by the low layer protocol to indicate that there will be no more data
  501. from the communication peer.
  502. This function sets the socket's state to SO_NO_MORE_DATA and signals all queued
  503. IO tokens with the error status EFI_CONNECTION_FIN.
  504. @param[in, out] Sock Pointer to the socket.
  505. **/
  506. VOID
  507. SockNoMoreData (
  508. IN OUT SOCKET *Sock
  509. );
  510. //
  511. // Socket provided operations for user interface implemented in SockInterface.c
  512. //
  513. /**
  514. Create a socket and its associated protocol control block
  515. with the initial data SockInitData and protocol specific
  516. data ProtoData.
  517. @param[in] SockInitData Initial data to setting the socket.
  518. @return Pointer to the newly created socket. If NULL, an error condition occurred.
  519. **/
  520. SOCKET *
  521. SockCreateChild (
  522. IN SOCK_INIT_DATA *SockInitData
  523. );
  524. /**
  525. Destroy the socket Sock and its associated protocol control block.
  526. @param[in, out] Sock The socket to be destroyed.
  527. @retval EFI_SUCCESS The socket Sock was destroyed successfully.
  528. @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.
  529. **/
  530. EFI_STATUS
  531. SockDestroyChild (
  532. IN OUT SOCKET *Sock
  533. );
  534. /**
  535. Configure the specific socket Sock using configuration data ConfigData.
  536. @param[in] Sock Pointer to the socket to be configured.
  537. @param[in] ConfigData Pointer to the configuration data.
  538. @retval EFI_SUCCESS The socket configured successfully.
  539. @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
  540. socket is already configured.
  541. **/
  542. EFI_STATUS
  543. SockConfigure (
  544. IN SOCKET *Sock,
  545. IN VOID *ConfigData
  546. );
  547. /**
  548. Initiate a connection establishment process.
  549. @param[in] Sock Pointer to the socket to initiate the
  550. connection.
  551. @param[in] Token Pointer to the token used for the connection
  552. operation.
  553. @retval EFI_SUCCESS The connection initialized successfully.
  554. @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
  555. socket is closed, or the socket is not configured to
  556. be an active one, or the token is already in one of
  557. this socket's lists.
  558. @retval EFI_NO_MAPPING The IP address configuration operation is not
  559. finished.
  560. @retval EFI_NOT_STARTED The socket is not configured.
  561. **/
  562. EFI_STATUS
  563. SockConnect (
  564. IN SOCKET *Sock,
  565. IN VOID *Token
  566. );
  567. /**
  568. Issue a listen token to get an existed connected network instance,
  569. or wait for a connection if there is none.
  570. @param[in] Sock Pointer to the socket to accept connections.
  571. @param[in] Token The token to accept a connection.
  572. @retval EFI_SUCCESS Either a connection is accepted or the Token is
  573. buffered for further acceptance.
  574. @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
  575. socket is closed, or the socket is not configured to
  576. be a passive one, or the token is already in one of
  577. this socket's lists.
  578. @retval EFI_NO_MAPPING The IP address configuration operation is not
  579. finished.
  580. @retval EFI_NOT_STARTED The socket is not configured.
  581. @retval EFI_OUT_OF_RESOURCE Failed to buffer the Token due to memory limit.
  582. **/
  583. EFI_STATUS
  584. SockAccept (
  585. IN SOCKET *Sock,
  586. IN VOID *Token
  587. );
  588. /**
  589. Issue a token with data to the socket to send out.
  590. @param[in] Sock Pointer to the socket to process the token with
  591. data.
  592. @param[in] Token The token with data that needs to send out.
  593. @retval EFI_SUCCESS The token processed successfully.
  594. @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
  595. socket is closed, or the socket is not in a
  596. synchronized state , or the token is already in one
  597. of this socket's lists.
  598. @retval EFI_NO_MAPPING The IP address configuration operation is not
  599. finished.
  600. @retval EFI_NOT_STARTED The socket is not configured.
  601. @retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to a memory limit.
  602. **/
  603. EFI_STATUS
  604. SockSend (
  605. IN SOCKET *Sock,
  606. IN VOID *Token
  607. );
  608. /**
  609. Issue a token to get data from the socket.
  610. @param[in] Sock Pointer to the socket to get data from.
  611. @param[in] Token The token to store the received data from the
  612. socket.
  613. @retval EFI_SUCCESS The token processed successfully.
  614. @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
  615. socket is closed, or the socket is not in a
  616. synchronized state , or the token is already in one
  617. of this socket's lists.
  618. @retval EFI_NO_MAPPING The IP address configuration operation is not
  619. finished.
  620. @retval EFI_NOT_STARTED The socket is not configured.
  621. @retval EFI_CONNECTION_FIN The connection is closed and there is no more data.
  622. @retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to a memory limit.
  623. **/
  624. EFI_STATUS
  625. SockRcv (
  626. IN SOCKET *Sock,
  627. IN VOID *Token
  628. );
  629. /**
  630. Reset the socket and its associated protocol control block.
  631. @param[in, out] Sock Pointer to the socket to be flushed.
  632. @retval EFI_SUCCESS The socket flushed successfully.
  633. @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.
  634. **/
  635. EFI_STATUS
  636. SockFlush (
  637. IN OUT SOCKET *Sock
  638. );
  639. /**
  640. Close or abort the socket associated connection.
  641. @param[in, out] Sock Pointer to the socket of the connection to close
  642. or abort.
  643. @param[in] Token The token for close operation.
  644. @param[in] OnAbort TRUE for aborting the connection, FALSE to close it.
  645. @retval EFI_SUCCESS The close or abort operation initialized
  646. successfully.
  647. @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
  648. socket is closed, or the socket is not in a
  649. synchronized state , or the token is already in one
  650. of this socket's lists.
  651. @retval EFI_NO_MAPPING The IP address configuration operation is not
  652. finished.
  653. @retval EFI_NOT_STARTED The socket is not configured.
  654. **/
  655. EFI_STATUS
  656. SockClose (
  657. IN OUT SOCKET *Sock,
  658. IN VOID *Token,
  659. IN BOOLEAN OnAbort
  660. );
  661. /**
  662. Abort the socket associated connection, listen, transmission or receive request.
  663. @param[in, out] Sock Pointer to the socket to abort.
  664. @param[in] Token Pointer to a token that has been issued by
  665. Connect(), Accept(), Transmit() or Receive(). If
  666. NULL, all pending tokens issued by the four
  667. functions listed above will be aborted.
  668. @retval EFI_UNSUPPORTED The operation is not supported in the current
  669. implementation.
  670. **/
  671. EFI_STATUS
  672. SockCancel (
  673. IN OUT SOCKET *Sock,
  674. IN VOID *Token
  675. );
  676. /**
  677. Get the mode data of the low layer protocol.
  678. @param[in] Sock Pointer to the socket to get mode data from.
  679. @param[in, out] Mode Pointer to the data to store the low layer mode
  680. information.
  681. @retval EFI_SUCCESS The mode data was obtained successfully.
  682. @retval EFI_NOT_STARTED The socket is not configured.
  683. **/
  684. EFI_STATUS
  685. SockGetMode (
  686. IN SOCKET *Sock,
  687. IN OUT VOID *Mode
  688. );
  689. /**
  690. Add or remove route information in IP route table associated
  691. with this socket.
  692. @param[in] Sock Pointer to the socket associated with the IP route
  693. table to operate on.
  694. @param[in] RouteInfo Pointer to the route information to be processed.
  695. @retval EFI_SUCCESS The route table updated successfully.
  696. @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.
  697. @retval EFI_NO_MAPPING The IP address configuration operation is not
  698. finished.
  699. @retval EFI_NOT_STARTED The socket is not configured.
  700. **/
  701. EFI_STATUS
  702. SockRoute (
  703. IN SOCKET *Sock,
  704. IN VOID *RouteInfo
  705. );
  706. #endif