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