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