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