1 | /** @file
|
---|
2 | Common head file for TCP socket.
|
---|
3 |
|
---|
4 | Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
|
---|
5 |
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
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>
|
---|
20 | #include <Library/BaseMemoryLib.h>
|
---|
21 | #include <Library/MemoryAllocationLib.h>
|
---|
22 | #include <Library/UefiRuntimeServicesTableLib.h>
|
---|
23 | #include <Library/UefiBootServicesTableLib.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 |
|
---|
61 | ///
|
---|
62 | /// Socket state
|
---|
63 | ///
|
---|
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 |
|
---|
70 | ///
|
---|
71 | /// Socket configure state
|
---|
72 | ///
|
---|
73 | #define SO_UNCONFIGURED 0
|
---|
74 | #define SO_CONFIGURED_ACTIVE 1
|
---|
75 | #define SO_CONFIGURED_PASSIVE 2
|
---|
76 | #define SO_NO_MAPPING 3
|
---|
77 |
|
---|
78 | ///
|
---|
79 | /// The request issued from socket layer to protocol layer.
|
---|
80 | ///
|
---|
81 | #define SOCK_ATTACH 0 ///< Attach current socket to a new PCB
|
---|
82 | #define SOCK_DETACH 1 ///< Detach current socket from the PCB
|
---|
83 | #define SOCK_CONFIGURE 2 ///< Configure attached PCB
|
---|
84 | #define SOCK_FLUSH 3 ///< Flush attached PCB
|
---|
85 | #define SOCK_SND 4 ///< Need protocol to send something
|
---|
86 | #define SOCK_SNDPUSH 5 ///< Need protocol to send pushed data
|
---|
87 | #define SOCK_SNDURG 6 ///< Need protocol to send urgent data
|
---|
88 | #define SOCK_CONSUMED 7 ///< Application has retrieved data from socket
|
---|
89 | #define SOCK_CONNECT 8 ///< Need to connect to a peer
|
---|
90 | #define SOCK_CLOSE 9 ///< Need to close the protocol process
|
---|
91 | #define SOCK_ABORT 10 ///< Need to reset the protocol process
|
---|
92 | #define SOCK_POLL 11 ///< Need to poll to the protocol layer
|
---|
93 | #define SOCK_ROUTE 12 ///< Need to add a route information
|
---|
94 | #define SOCK_MODE 13 ///< Need to get the mode data of the protocol
|
---|
95 | #define SOCK_GROUP 14 ///< Need to join a mcast group
|
---|
96 |
|
---|
97 | /**
|
---|
98 | Set socket SO_NO_MORE_DATA flag.
|
---|
99 |
|
---|
100 | @param[in] Sock Pointer to the socket
|
---|
101 |
|
---|
102 | **/
|
---|
103 | #define SOCK_NO_MORE_DATA(Sock) ((Sock)->Flag |= SO_NO_MORE_DATA)
|
---|
104 |
|
---|
105 | /**
|
---|
106 | Check whether the socket is unconfigured.
|
---|
107 |
|
---|
108 | @param[in] Sock Pointer to the socket.
|
---|
109 |
|
---|
110 | @retval TRUE The socket is unconfigured.
|
---|
111 | @retval FALSE The socket is not unconfigured.
|
---|
112 |
|
---|
113 | **/
|
---|
114 | #define SOCK_IS_UNCONFIGURED(Sock) ((Sock)->ConfigureState == SO_UNCONFIGURED)
|
---|
115 |
|
---|
116 | /**
|
---|
117 | Check whether the socket is configured.
|
---|
118 |
|
---|
119 | @param[in] Sock Pointer to the socket
|
---|
120 |
|
---|
121 | @retval TRUE The socket is configured
|
---|
122 | @retval FALSE The socket is not configured
|
---|
123 |
|
---|
124 | **/
|
---|
125 | #define SOCK_IS_CONFIGURED(Sock) \
|
---|
126 | (((Sock)->ConfigureState == SO_CONFIGURED_ACTIVE) || \
|
---|
127 | ((Sock)->ConfigureState == SO_CONFIGURED_PASSIVE))
|
---|
128 |
|
---|
129 | /**
|
---|
130 | Check whether the socket is configured to active mode.
|
---|
131 |
|
---|
132 | @param[in] Sock Pointer to the socket.
|
---|
133 |
|
---|
134 | @retval TRUE The socket is configured to active mode.
|
---|
135 | @retval FALSE The socket is not configured to active mode.
|
---|
136 |
|
---|
137 | **/
|
---|
138 | #define SOCK_IS_CONFIGURED_ACTIVE(Sock) ((Sock)->ConfigureState == SO_CONFIGURED_ACTIVE)
|
---|
139 |
|
---|
140 | /**
|
---|
141 | Check whether the socket is configured to passive mode.
|
---|
142 |
|
---|
143 | @param[in] Sock Pointer to the socket.
|
---|
144 |
|
---|
145 | @retval TRUE The socket is configured to passive mode.
|
---|
146 | @retval FALSE The socket is not configured to passive mode.
|
---|
147 |
|
---|
148 | **/
|
---|
149 | #define SOCK_IS_CONNECTED_PASSIVE(Sock) ((Sock)->ConfigureState == SO_CONFIGURED_PASSIVE)
|
---|
150 |
|
---|
151 | /**
|
---|
152 | Check whether the socket is mapped.
|
---|
153 |
|
---|
154 | @param[in] Sock Pointer to the socket.
|
---|
155 |
|
---|
156 | @retval TRUE The socket is not mapping.
|
---|
157 | @retval FALSE The socket is mapped.
|
---|
158 |
|
---|
159 | **/
|
---|
160 | #define SOCK_IS_NO_MAPPING(Sock) ((Sock)->ConfigureState == SO_NO_MAPPING)
|
---|
161 |
|
---|
162 | /**
|
---|
163 | Check whether the socket is closed.
|
---|
164 |
|
---|
165 | @param[in] Sock Pointer to the socket.
|
---|
166 |
|
---|
167 | @retval TRUE The socket is closed.
|
---|
168 | @retval FALSE The socket is not closed.
|
---|
169 |
|
---|
170 | **/
|
---|
171 | #define SOCK_IS_CLOSED(Sock) ((Sock)->State == SO_CLOSED)
|
---|
172 |
|
---|
173 | /**
|
---|
174 | Check whether the socket is listening.
|
---|
175 |
|
---|
176 | @param[in] Sock Pointer to the socket.
|
---|
177 |
|
---|
178 | @retval TRUE The socket is listening.
|
---|
179 | @retval FALSE The socket is not listening.
|
---|
180 |
|
---|
181 | **/
|
---|
182 | #define SOCK_IS_LISTENING(Sock) ((Sock)->State == SO_LISTENING)
|
---|
183 |
|
---|
184 | /**
|
---|
185 | Check whether the socket is connecting.
|
---|
186 |
|
---|
187 | @param[in] Sock Pointer to the socket.
|
---|
188 |
|
---|
189 | @retval TRUE The socket is connecting.
|
---|
190 | @retval FALSE The socket is not connecting.
|
---|
191 |
|
---|
192 | **/
|
---|
193 | #define SOCK_IS_CONNECTING(Sock) ((Sock)->State == SO_CONNECTING)
|
---|
194 |
|
---|
195 | /**
|
---|
196 | Check whether the socket has connected.
|
---|
197 |
|
---|
198 | @param[in] Sock Pointer to the socket.
|
---|
199 |
|
---|
200 | @retval TRUE The socket has connected.
|
---|
201 | @retval FALSE The socket has not connected.
|
---|
202 |
|
---|
203 | **/
|
---|
204 | #define SOCK_IS_CONNECTED(Sock) ((Sock)->State == SO_CONNECTED)
|
---|
205 |
|
---|
206 | /**
|
---|
207 | Check whether the socket is disconnecting.
|
---|
208 |
|
---|
209 | @param[in] Sock Pointer to the socket.
|
---|
210 |
|
---|
211 | @retval TRUE The socket is disconnecting.
|
---|
212 | @retval FALSE The socket is not disconnecting.
|
---|
213 |
|
---|
214 | **/
|
---|
215 | #define SOCK_IS_DISCONNECTING(Sock) ((Sock)->State == SO_DISCONNECTING)
|
---|
216 |
|
---|
217 | /**
|
---|
218 | Check whether the socket is no more data.
|
---|
219 |
|
---|
220 | @param[in] Sock Pointer to the socket.
|
---|
221 |
|
---|
222 | @retval TRUE The socket is no more data.
|
---|
223 | @retval FALSE The socket still has data.
|
---|
224 |
|
---|
225 | **/
|
---|
226 | #define SOCK_IS_NO_MORE_DATA(Sock) (0 != ((Sock)->Flag & SO_NO_MORE_DATA))
|
---|
227 |
|
---|
228 | /**
|
---|
229 | Set the size of the receive buffer.
|
---|
230 |
|
---|
231 | @param[in] Sock Pointer to the socket.
|
---|
232 | @param[in] Size The size to set.
|
---|
233 |
|
---|
234 | **/
|
---|
235 | #define SET_RCV_BUFFSIZE(Sock, Size) ((Sock)->RcvBuffer.HighWater = (Size))
|
---|
236 |
|
---|
237 | /**
|
---|
238 | Get the size of the receive buffer.
|
---|
239 |
|
---|
240 | @param[in] Sock Pointer to the socket.
|
---|
241 |
|
---|
242 | @return The receive buffer size.
|
---|
243 |
|
---|
244 | **/
|
---|
245 | #define GET_RCV_BUFFSIZE(Sock) ((Sock)->RcvBuffer.HighWater)
|
---|
246 |
|
---|
247 | /**
|
---|
248 | Get the size of the receive data.
|
---|
249 |
|
---|
250 | @param[in] Sock Pointer to the socket.
|
---|
251 |
|
---|
252 | @return The received data size.
|
---|
253 |
|
---|
254 | **/
|
---|
255 | #define GET_RCV_DATASIZE(Sock) (((Sock)->RcvBuffer.DataQueue)->BufSize)
|
---|
256 |
|
---|
257 | /**
|
---|
258 | Set the size of the send buffer.
|
---|
259 |
|
---|
260 | @param[in] Sock Pointer to the socket.
|
---|
261 | @param[in] Size The size to set.
|
---|
262 |
|
---|
263 | **/
|
---|
264 | #define SET_SND_BUFFSIZE(Sock, Size) ((Sock)->SndBuffer.HighWater = (Size))
|
---|
265 |
|
---|
266 | /**
|
---|
267 | Get the size of the send buffer.
|
---|
268 |
|
---|
269 | @param[in] Sock Pointer to the socket.
|
---|
270 |
|
---|
271 | @return The send buffer size.
|
---|
272 |
|
---|
273 | **/
|
---|
274 | #define GET_SND_BUFFSIZE(Sock) ((Sock)->SndBuffer.HighWater)
|
---|
275 |
|
---|
276 | /**
|
---|
277 | Get the size of the send data.
|
---|
278 |
|
---|
279 | @param[in] Sock Pointer to the socket.
|
---|
280 |
|
---|
281 | @return The send data size.
|
---|
282 |
|
---|
283 | **/
|
---|
284 | #define GET_SND_DATASIZE(Sock) (((Sock)->SndBuffer.DataQueue)->BufSize)
|
---|
285 |
|
---|
286 | /**
|
---|
287 | Set the backlog value of the socket.
|
---|
288 |
|
---|
289 | @param[in] Sock Pointer to the socket.
|
---|
290 | @param[in] Value The value to set.
|
---|
291 |
|
---|
292 | **/
|
---|
293 | #define SET_BACKLOG(Sock, Value) ((Sock)->BackLog = (Value))
|
---|
294 |
|
---|
295 | /**
|
---|
296 | Get the backlog value of the socket.
|
---|
297 |
|
---|
298 | @param[in] Sock Pointer to the socket.
|
---|
299 |
|
---|
300 | @return The backlog value.
|
---|
301 |
|
---|
302 | **/
|
---|
303 | #define GET_BACKLOG(Sock) ((Sock)->BackLog)
|
---|
304 |
|
---|
305 | /**
|
---|
306 | Set the socket with error state.
|
---|
307 |
|
---|
308 | @param[in] Sock Pointer to the socket.
|
---|
309 | @param[in] Error The error state.
|
---|
310 |
|
---|
311 | **/
|
---|
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 |
|
---|
322 | typedef struct _TCP_SOCKET SOCKET;
|
---|
323 |
|
---|
324 | ///
|
---|
325 | /// Socket completion token
|
---|
326 | ///
|
---|
327 | typedef struct _SOCK_COMPLETION_TOKEN {
|
---|
328 | EFI_EVENT Event; ///< The event to be issued
|
---|
329 | EFI_STATUS Status; ///< The status to be issued
|
---|
330 | } SOCK_COMPLETION_TOKEN;
|
---|
331 |
|
---|
332 | typedef union {
|
---|
333 | VOID *RxData;
|
---|
334 | VOID *TxData;
|
---|
335 | } SOCK_IO_DATA;
|
---|
336 |
|
---|
337 | ///
|
---|
338 | /// The application token with data packet
|
---|
339 | ///
|
---|
340 | typedef struct _SOCK_IO_TOKEN {
|
---|
341 | SOCK_COMPLETION_TOKEN Token;
|
---|
342 | SOCK_IO_DATA Packet;
|
---|
343 | } SOCK_IO_TOKEN;
|
---|
344 |
|
---|
345 | ///
|
---|
346 | /// The socket type.
|
---|
347 | ///
|
---|
348 | typedef enum {
|
---|
349 | SockDgram, ///< This socket providing datagram service
|
---|
350 | SockStream ///< This socket providing stream service
|
---|
351 | } SOCK_TYPE;
|
---|
352 |
|
---|
353 | ///
|
---|
354 | /// The buffer structure of rcvd data and send data used by socket.
|
---|
355 | ///
|
---|
356 | typedef struct _SOCK_BUFFER {
|
---|
357 | UINT32 HighWater; ///< The buffersize upper limit of sock_buffer
|
---|
358 | UINT32 LowWater; ///< The low water mark of sock_buffer
|
---|
359 | NET_BUF_QUEUE *DataQueue; ///< The queue to buffer data
|
---|
360 | } SOCK_BUFFER;
|
---|
361 |
|
---|
362 | /**
|
---|
363 | The handler of protocol for request from socket.
|
---|
364 |
|
---|
365 | @param[in] Socket The socket issuing the request to protocol.
|
---|
366 | @param[in] Request The request issued by socket.
|
---|
367 | @param[in] RequestData The request related data.
|
---|
368 |
|
---|
369 | @retval EFI_SUCCESS The socket request is completed successfully.
|
---|
370 | @retval other The error status returned by the corresponding TCP
|
---|
371 | layer function.
|
---|
372 |
|
---|
373 | **/
|
---|
374 | typedef
|
---|
375 | EFI_STATUS
|
---|
376 | (*SOCK_PROTO_HANDLER) (
|
---|
377 | IN SOCKET *Socket,
|
---|
378 | IN UINT8 Request,
|
---|
379 | IN VOID *RequestData
|
---|
380 | );
|
---|
381 |
|
---|
382 | /**
|
---|
383 | The Callback function called after the TCP socket is created.
|
---|
384 |
|
---|
385 | @param[in] This Pointer to the socket just created.
|
---|
386 | @param[in] Context Context of the socket.
|
---|
387 |
|
---|
388 | @retval EFI_SUCCESS This protocol installed successfully.
|
---|
389 | @retval other Some error occurred.
|
---|
390 |
|
---|
391 | **/
|
---|
392 | typedef
|
---|
393 | EFI_STATUS
|
---|
394 | (*SOCK_CREATE_CALLBACK) (
|
---|
395 | IN SOCKET *This,
|
---|
396 | IN VOID *Context
|
---|
397 | );
|
---|
398 |
|
---|
399 | /**
|
---|
400 | The callback function called before the TCP socket is to be destroyed.
|
---|
401 |
|
---|
402 | @param[in] This The TCP socket to be destroyed.
|
---|
403 | @param[in] Context The context.
|
---|
404 |
|
---|
405 | **/
|
---|
406 | typedef
|
---|
407 | VOID
|
---|
408 | (*SOCK_DESTROY_CALLBACK) (
|
---|
409 | IN SOCKET *This,
|
---|
410 | IN VOID *Context
|
---|
411 | );
|
---|
412 |
|
---|
413 | ///
|
---|
414 | /// The initialize data for create a new socket.
|
---|
415 | ///
|
---|
416 | typedef struct _SOCK_INIT_DATA {
|
---|
417 | SOCK_TYPE Type;
|
---|
418 | UINT8 State;
|
---|
419 |
|
---|
420 | SOCKET *Parent; ///< The parent of this socket
|
---|
421 | UINT32 BackLog; ///< The connection limit for listening socket
|
---|
422 | UINT32 SndBufferSize; ///< The high water mark of send buffer
|
---|
423 | UINT32 RcvBufferSize; ///< The high water mark of receive buffer
|
---|
424 | UINT8 IpVersion;
|
---|
425 | VOID *Protocol; ///< The pointer to protocol function template
|
---|
426 | ///< wanted to install on socket
|
---|
427 |
|
---|
428 | //
|
---|
429 | // Callbacks after socket is created and before socket is to be destroyed.
|
---|
430 | //
|
---|
431 | SOCK_CREATE_CALLBACK CreateCallback; ///< Callback after created
|
---|
432 | SOCK_DESTROY_CALLBACK DestroyCallback; ///< Callback before destroyed
|
---|
433 | VOID *Context; ///< The context of the callback
|
---|
434 |
|
---|
435 | //
|
---|
436 | // Opaque protocol data.
|
---|
437 | //
|
---|
438 | VOID *ProtoData;
|
---|
439 | UINT32 DataSize;
|
---|
440 |
|
---|
441 | SOCK_PROTO_HANDLER ProtoHandler; ///< The handler of protocol for socket request
|
---|
442 |
|
---|
443 | EFI_HANDLE DriverBinding; ///< The driver binding handle
|
---|
444 | } SOCK_INIT_DATA;
|
---|
445 |
|
---|
446 | ///
|
---|
447 | /// The union type of TCP4 and TCP6 protocol.
|
---|
448 | ///
|
---|
449 | typedef union _NET_PROTOCOL {
|
---|
450 | EFI_TCP4_PROTOCOL Tcp4Protocol; ///< Tcp4 protocol
|
---|
451 | EFI_TCP6_PROTOCOL Tcp6Protocol; ///< Tcp6 protocol
|
---|
452 | } NET_PROTOCOL;
|
---|
453 | ///
|
---|
454 | /// The socket structure representing a network service access point.
|
---|
455 | ///
|
---|
456 | struct _TCP_SOCKET {
|
---|
457 | //
|
---|
458 | // Socket description information
|
---|
459 | //
|
---|
460 | UINT32 Signature; ///< Signature of the socket
|
---|
461 | EFI_HANDLE SockHandle; ///< The virtual handle of the socket
|
---|
462 | EFI_HANDLE DriverBinding; ///< Socket's driver binding protocol
|
---|
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;
|
---|
470 | EFI_LOCK Lock; ///< The lock of socket
|
---|
471 | SOCK_BUFFER SndBuffer; ///< Send buffer of application's data
|
---|
472 | SOCK_BUFFER RcvBuffer; ///< Receive buffer of received data
|
---|
473 | EFI_STATUS SockError; ///< The error returned by low layer protocol
|
---|
474 | BOOLEAN InDestroy;
|
---|
475 |
|
---|
476 | //
|
---|
477 | // Fields used to manage the connection request
|
---|
478 | //
|
---|
479 | UINT32 BackLog; ///< the limit of connection to this socket
|
---|
480 | UINT32 ConnCnt; ///< the current count of connections to it
|
---|
481 | SOCKET *Parent; ///< listening parent that accept the connection
|
---|
482 | LIST_ENTRY ConnectionList; ///< the connections maintained by this socket
|
---|
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 |
|
---|
491 | SOCK_COMPLETION_TOKEN *ConnectionToken; ///< app's token to signal if connected
|
---|
492 | SOCK_COMPLETION_TOKEN *CloseToken; ///< app's token to signal if closed
|
---|
493 | //
|
---|
494 | // Interface for low level protocol
|
---|
495 | //
|
---|
496 | SOCK_PROTO_HANDLER ProtoHandler; ///< The request handler of protocol
|
---|
497 | UINT8 ProtoReserved[PROTO_RESERVED_LEN]; ///< Data fields reserved for protocol
|
---|
498 | UINT8 IpVersion;
|
---|
499 | NET_PROTOCOL NetProtocol; ///< TCP4 or TCP6 protocol socket used
|
---|
500 | //
|
---|
501 | // Callbacks after socket is created and before socket is to be destroyed.
|
---|
502 | //
|
---|
503 | SOCK_CREATE_CALLBACK CreateCallback; ///< Callback after created
|
---|
504 | SOCK_DESTROY_CALLBACK DestroyCallback; ///< Callback before destroyed
|
---|
505 | VOID *Context; ///< The context of the callback
|
---|
506 | };
|
---|
507 |
|
---|
508 | ///
|
---|
509 | /// The token structure buffered in socket layer.
|
---|
510 | ///
|
---|
511 | typedef struct _SOCK_TOKEN {
|
---|
512 | LIST_ENTRY TokenList; ///< The entry to add in the token list
|
---|
513 | SOCK_COMPLETION_TOKEN *Token; ///< The application's token
|
---|
514 | UINT32 RemainDataLen; ///< Unprocessed data length
|
---|
515 | SOCKET *Sock; ///< The pointer to the socket this token
|
---|
516 | ///< belongs to
|
---|
517 | } SOCK_TOKEN;
|
---|
518 |
|
---|
519 | ///
|
---|
520 | /// Reserved data to access the NET_BUF delivered by TCP driver.
|
---|
521 | ///
|
---|
522 | typedef struct _TCP_RSV_DATA {
|
---|
523 | UINT32 UrgLen;
|
---|
524 | } TCP_RSV_DATA;
|
---|
525 |
|
---|
526 | //
|
---|
527 | // Socket provided operations for low layer protocol implemented in SockImpl.c
|
---|
528 | //
|
---|
529 |
|
---|
530 | /**
|
---|
531 | Set the state of the socket.
|
---|
532 |
|
---|
533 | @param[in, out] Sock Pointer to the socket.
|
---|
534 | @param[in] State The new socket state to be set.
|
---|
535 |
|
---|
536 | **/
|
---|
537 | VOID
|
---|
538 | SockSetState (
|
---|
539 | IN OUT SOCKET *Sock,
|
---|
540 | IN UINT8 State
|
---|
541 | );
|
---|
542 |
|
---|
543 | /**
|
---|
544 | Clone a new socket including its associated protocol control block.
|
---|
545 |
|
---|
546 | @param[in] Sock Pointer to the socket to be cloned.
|
---|
547 |
|
---|
548 | @return Pointer to the newly cloned socket. If NULL, an error condition occurred.
|
---|
549 |
|
---|
550 | **/
|
---|
551 | SOCKET *
|
---|
552 | SockClone (
|
---|
553 | IN SOCKET *Sock
|
---|
554 | );
|
---|
555 |
|
---|
556 | /**
|
---|
557 | Called by the low layer protocol to indicate the socket a connection is
|
---|
558 | established.
|
---|
559 |
|
---|
560 | This function just changes the socket's state to SO_CONNECTED
|
---|
561 | and signals the token used for connection establishment.
|
---|
562 |
|
---|
563 | @param[in, out] Sock Pointer to the socket associated with the
|
---|
564 | established connection.
|
---|
565 |
|
---|
566 | **/
|
---|
567 | VOID
|
---|
568 | SockConnEstablished (
|
---|
569 | IN OUT SOCKET *Sock
|
---|
570 | );
|
---|
571 |
|
---|
572 | /**
|
---|
573 | Called by the low layer protocol to indicate that the connection is closed.
|
---|
574 |
|
---|
575 | This function flushes the socket, sets the state to SO_CLOSED, and signals
|
---|
576 | the close token.
|
---|
577 |
|
---|
578 | @param[in, out] Sock Pointer to the socket associated with the closed
|
---|
579 | connection.
|
---|
580 |
|
---|
581 | **/
|
---|
582 | VOID
|
---|
583 | SockConnClosed (
|
---|
584 | IN OUT SOCKET *Sock
|
---|
585 | );
|
---|
586 |
|
---|
587 | /**
|
---|
588 | Called by low layer protocol to indicate that some data is sent or processed.
|
---|
589 |
|
---|
590 | This function trims the sent data in the socket send buffer and signals the data
|
---|
591 | token, if proper.
|
---|
592 |
|
---|
593 | @param[in, out] Sock Pointer to the socket.
|
---|
594 | @param[in] Count The length of the data processed or sent, in bytes.
|
---|
595 |
|
---|
596 | **/
|
---|
597 | VOID
|
---|
598 | SockDataSent (
|
---|
599 | IN OUT SOCKET *Sock,
|
---|
600 | IN UINT32 Count
|
---|
601 | );
|
---|
602 |
|
---|
603 | /**
|
---|
604 | Called by the low layer protocol to copy some data in socket send
|
---|
605 | buffer starting from the specific offset to a buffer provided by
|
---|
606 | the caller.
|
---|
607 |
|
---|
608 | @param[in] Sock Pointer to the socket.
|
---|
609 | @param[in] Offset The start point of the data to be copied.
|
---|
610 | @param[in] Len The length of the data to be copied.
|
---|
611 | @param[out] Dest Pointer to the destination to copy the data.
|
---|
612 |
|
---|
613 | @return The data size copied.
|
---|
614 |
|
---|
615 | **/
|
---|
616 | UINT32
|
---|
617 | SockGetDataToSend (
|
---|
618 | IN SOCKET *Sock,
|
---|
619 | IN UINT32 Offset,
|
---|
620 | IN UINT32 Len,
|
---|
621 | OUT UINT8 *Dest
|
---|
622 | );
|
---|
623 |
|
---|
624 | /**
|
---|
625 | Called by the low layer protocol to deliver received data to socket layer.
|
---|
626 |
|
---|
627 | This function appends the data to the socket receive buffer, set the
|
---|
628 | urgent data length, then checks if any receive token can be signaled.
|
---|
629 |
|
---|
630 | @param[in, out] Sock Pointer to the socket.
|
---|
631 | @param[in, out] NetBuffer Pointer to the buffer that contains the received data.
|
---|
632 | @param[in] UrgLen The length of the urgent data in the received data.
|
---|
633 |
|
---|
634 | **/
|
---|
635 | VOID
|
---|
636 | SockDataRcvd (
|
---|
637 | IN OUT SOCKET *Sock,
|
---|
638 | IN OUT NET_BUF *NetBuffer,
|
---|
639 | IN UINT32 UrgLen
|
---|
640 | );
|
---|
641 |
|
---|
642 | /**
|
---|
643 | Get the length of the free space of the specific socket buffer.
|
---|
644 |
|
---|
645 | @param[in] Sock Pointer to the socket.
|
---|
646 | @param[in] Which Flag to indicate which socket buffer to check:
|
---|
647 | either send buffer or receive buffer.
|
---|
648 |
|
---|
649 | @return The length of the free space, in bytes.
|
---|
650 |
|
---|
651 | **/
|
---|
652 | UINT32
|
---|
653 | SockGetFreeSpace (
|
---|
654 | IN SOCKET *Sock,
|
---|
655 | IN UINT32 Which
|
---|
656 | );
|
---|
657 |
|
---|
658 | /**
|
---|
659 | Called by the low layer protocol to indicate that there will be no more data
|
---|
660 | from the communication peer.
|
---|
661 |
|
---|
662 | This function sets the socket's state to SO_NO_MORE_DATA and signals all queued
|
---|
663 | IO tokens with the error status EFI_CONNECTION_FIN.
|
---|
664 |
|
---|
665 | @param[in, out] Sock Pointer to the socket.
|
---|
666 |
|
---|
667 | **/
|
---|
668 | VOID
|
---|
669 | SockNoMoreData (
|
---|
670 | IN OUT SOCKET *Sock
|
---|
671 | );
|
---|
672 |
|
---|
673 | //
|
---|
674 | // Socket provided operations for user interface implemented in SockInterface.c
|
---|
675 | //
|
---|
676 |
|
---|
677 | /**
|
---|
678 | Create a socket and its associated protocol control block
|
---|
679 | with the initial data SockInitData and protocol specific
|
---|
680 | data ProtoData.
|
---|
681 |
|
---|
682 | @param[in] SockInitData Initial data to setting the socket.
|
---|
683 |
|
---|
684 | @return Pointer to the newly created socket. If NULL, an error condition occurred.
|
---|
685 |
|
---|
686 | **/
|
---|
687 | SOCKET *
|
---|
688 | SockCreateChild (
|
---|
689 | IN SOCK_INIT_DATA *SockInitData
|
---|
690 | );
|
---|
691 |
|
---|
692 | /**
|
---|
693 | Destroy the socket Sock and its associated protocol control block.
|
---|
694 |
|
---|
695 | @param[in, out] Sock The socket to be destroyed.
|
---|
696 |
|
---|
697 | @retval EFI_SUCCESS The socket Sock was destroyed successfully.
|
---|
698 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.
|
---|
699 |
|
---|
700 | **/
|
---|
701 | EFI_STATUS
|
---|
702 | SockDestroyChild (
|
---|
703 | IN OUT SOCKET *Sock
|
---|
704 | );
|
---|
705 |
|
---|
706 | /**
|
---|
707 | Configure the specific socket Sock using configuration data ConfigData.
|
---|
708 |
|
---|
709 | @param[in] Sock Pointer to the socket to be configured.
|
---|
710 | @param[in] ConfigData Pointer to the configuration data.
|
---|
711 |
|
---|
712 | @retval EFI_SUCCESS The socket configured successfully.
|
---|
713 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
|
---|
714 | socket is already configured.
|
---|
715 |
|
---|
716 | **/
|
---|
717 | EFI_STATUS
|
---|
718 | SockConfigure (
|
---|
719 | IN SOCKET *Sock,
|
---|
720 | IN VOID *ConfigData
|
---|
721 | );
|
---|
722 |
|
---|
723 | /**
|
---|
724 | Initiate a connection establishment process.
|
---|
725 |
|
---|
726 | @param[in] Sock Pointer to the socket to initiate the
|
---|
727 | connection.
|
---|
728 | @param[in] Token Pointer to the token used for the connection
|
---|
729 | operation.
|
---|
730 |
|
---|
731 | @retval EFI_SUCCESS The connection initialized successfully.
|
---|
732 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
|
---|
733 | socket is closed, or the socket is not configured to
|
---|
734 | be an active one, or the token is already in one of
|
---|
735 | this socket's lists.
|
---|
736 | @retval EFI_NO_MAPPING The IP address configuration operation is not
|
---|
737 | finished.
|
---|
738 | @retval EFI_NOT_STARTED The socket is not configured.
|
---|
739 |
|
---|
740 | **/
|
---|
741 | EFI_STATUS
|
---|
742 | SockConnect (
|
---|
743 | IN SOCKET *Sock,
|
---|
744 | IN VOID *Token
|
---|
745 | );
|
---|
746 |
|
---|
747 | /**
|
---|
748 | Issue a listen token to get an existed connected network instance,
|
---|
749 | or wait for a connection if there is none.
|
---|
750 |
|
---|
751 | @param[in] Sock Pointer to the socket to accept connections.
|
---|
752 | @param[in] Token The token to accept a connection.
|
---|
753 |
|
---|
754 | @retval EFI_SUCCESS Either a connection is accepted or the Token is
|
---|
755 | buffered for further acceptance.
|
---|
756 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
|
---|
757 | socket is closed, or the socket is not configured to
|
---|
758 | be a passive one, or the token is already in one of
|
---|
759 | this socket's lists.
|
---|
760 | @retval EFI_NO_MAPPING The IP address configuration operation is not
|
---|
761 | finished.
|
---|
762 | @retval EFI_NOT_STARTED The socket is not configured.
|
---|
763 | @retval EFI_OUT_OF_RESOURCE Failed to buffer the Token due to memory limit.
|
---|
764 |
|
---|
765 | **/
|
---|
766 | EFI_STATUS
|
---|
767 | SockAccept (
|
---|
768 | IN SOCKET *Sock,
|
---|
769 | IN VOID *Token
|
---|
770 | );
|
---|
771 |
|
---|
772 | /**
|
---|
773 | Issue a token with data to the socket to send out.
|
---|
774 |
|
---|
775 | @param[in] Sock Pointer to the socket to process the token with
|
---|
776 | data.
|
---|
777 | @param[in] Token The token with data that needs to send out.
|
---|
778 |
|
---|
779 | @retval EFI_SUCCESS The token processed successfully.
|
---|
780 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
|
---|
781 | socket is closed, or the socket is not in a
|
---|
782 | synchronized state , or the token is already in one
|
---|
783 | of this socket's lists.
|
---|
784 | @retval EFI_NO_MAPPING The IP address configuration operation is not
|
---|
785 | finished.
|
---|
786 | @retval EFI_NOT_STARTED The socket is not configured.
|
---|
787 | @retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to a memory limit.
|
---|
788 |
|
---|
789 | **/
|
---|
790 | EFI_STATUS
|
---|
791 | SockSend (
|
---|
792 | IN SOCKET *Sock,
|
---|
793 | IN VOID *Token
|
---|
794 | );
|
---|
795 |
|
---|
796 | /**
|
---|
797 | Issue a token to get data from the socket.
|
---|
798 |
|
---|
799 | @param[in] Sock Pointer to the socket to get data from.
|
---|
800 | @param[in] Token The token to store the received data from the
|
---|
801 | socket.
|
---|
802 |
|
---|
803 | @retval EFI_SUCCESS The token processed successfully.
|
---|
804 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
|
---|
805 | socket is closed, or the socket is not in a
|
---|
806 | synchronized state , or the token is already in one
|
---|
807 | of this socket's lists.
|
---|
808 | @retval EFI_NO_MAPPING The IP address configuration operation is not
|
---|
809 | finished.
|
---|
810 | @retval EFI_NOT_STARTED The socket is not configured.
|
---|
811 | @retval EFI_CONNECTION_FIN The connection is closed and there is no more data.
|
---|
812 | @retval EFI_OUT_OF_RESOURCE Failed to buffer the token due to a memory limit.
|
---|
813 |
|
---|
814 | **/
|
---|
815 | EFI_STATUS
|
---|
816 | SockRcv (
|
---|
817 | IN SOCKET *Sock,
|
---|
818 | IN VOID *Token
|
---|
819 | );
|
---|
820 |
|
---|
821 | /**
|
---|
822 | Reset the socket and its associated protocol control block.
|
---|
823 |
|
---|
824 | @param[in, out] Sock Pointer to the socket to be flushed.
|
---|
825 |
|
---|
826 | @retval EFI_SUCCESS The socket flushed successfully.
|
---|
827 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.
|
---|
828 |
|
---|
829 | **/
|
---|
830 | EFI_STATUS
|
---|
831 | SockFlush (
|
---|
832 | IN OUT SOCKET *Sock
|
---|
833 | );
|
---|
834 |
|
---|
835 | /**
|
---|
836 | Close or abort the socket associated connection.
|
---|
837 |
|
---|
838 | @param[in, out] Sock Pointer to the socket of the connection to close
|
---|
839 | or abort.
|
---|
840 | @param[in] Token The token for close operation.
|
---|
841 | @param[in] OnAbort TRUE for aborting the connection, FALSE to close it.
|
---|
842 |
|
---|
843 | @retval EFI_SUCCESS The close or abort operation initialized
|
---|
844 | successfully.
|
---|
845 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket, or the
|
---|
846 | socket is closed, or the socket is not in a
|
---|
847 | synchronized state , or the token is already in one
|
---|
848 | of this socket's lists.
|
---|
849 | @retval EFI_NO_MAPPING The IP address configuration operation is not
|
---|
850 | finished.
|
---|
851 | @retval EFI_NOT_STARTED The socket is not configured.
|
---|
852 |
|
---|
853 | **/
|
---|
854 | EFI_STATUS
|
---|
855 | SockClose (
|
---|
856 | IN OUT SOCKET *Sock,
|
---|
857 | IN VOID *Token,
|
---|
858 | IN BOOLEAN OnAbort
|
---|
859 | );
|
---|
860 |
|
---|
861 | /**
|
---|
862 | Abort the socket associated connection, listen, transmission or receive request.
|
---|
863 |
|
---|
864 | @param[in, out] Sock Pointer to the socket to abort.
|
---|
865 | @param[in] Token Pointer to a token that has been issued by
|
---|
866 | Connect(), Accept(), Transmit() or Receive(). If
|
---|
867 | NULL, all pending tokens issued by the four
|
---|
868 | functions listed above will be aborted.
|
---|
869 |
|
---|
870 | @retval EFI_UNSUPPORTED The operation is not supported in the current
|
---|
871 | implementation.
|
---|
872 | **/
|
---|
873 | EFI_STATUS
|
---|
874 | SockCancel (
|
---|
875 | IN OUT SOCKET *Sock,
|
---|
876 | IN VOID *Token
|
---|
877 | );
|
---|
878 |
|
---|
879 | /**
|
---|
880 | Get the mode data of the low layer protocol.
|
---|
881 |
|
---|
882 | @param[in] Sock Pointer to the socket to get mode data from.
|
---|
883 | @param[in, out] Mode Pointer to the data to store the low layer mode
|
---|
884 | information.
|
---|
885 |
|
---|
886 | @retval EFI_SUCCESS The mode data was obtained successfully.
|
---|
887 | @retval EFI_NOT_STARTED The socket is not configured.
|
---|
888 |
|
---|
889 | **/
|
---|
890 | EFI_STATUS
|
---|
891 | SockGetMode (
|
---|
892 | IN SOCKET *Sock,
|
---|
893 | IN OUT VOID *Mode
|
---|
894 | );
|
---|
895 |
|
---|
896 | /**
|
---|
897 | Add or remove route information in IP route table associated
|
---|
898 | with this socket.
|
---|
899 |
|
---|
900 | @param[in] Sock Pointer to the socket associated with the IP route
|
---|
901 | table to operate on.
|
---|
902 | @param[in] RouteInfo Pointer to the route information to be processed.
|
---|
903 |
|
---|
904 | @retval EFI_SUCCESS The route table updated successfully.
|
---|
905 | @retval EFI_ACCESS_DENIED Failed to get the lock to access the socket.
|
---|
906 | @retval EFI_NO_MAPPING The IP address configuration operation is not
|
---|
907 | finished.
|
---|
908 | @retval EFI_NOT_STARTED The socket is not configured.
|
---|
909 |
|
---|
910 | **/
|
---|
911 | EFI_STATUS
|
---|
912 | SockRoute (
|
---|
913 | IN SOCKET *Sock,
|
---|
914 | IN VOID *RouteInfo
|
---|
915 | );
|
---|
916 |
|
---|
917 | #endif
|
---|