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