]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Definitions for the socket library.\r | |
3 | \r | |
4 | Copyright (c) 2011, Intel Corporation\r | |
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 | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
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 | |
13 | **/\r | |
14 | \r | |
15 | #ifndef _SOCKET_INTERNALS_H_\r | |
16 | #define _SOCKET_INTERNALS_H_\r | |
17 | \r | |
18 | #include <Uefi.h>\r | |
19 | \r | |
20 | //----------------------------------------------------------------------\r | |
21 | //\r | |
22 | // The following private files are required to support file descriptors\r | |
23 | //\r | |
24 | \r | |
25 | #include <kfile.h>\r | |
26 | #include <MainData.h>\r | |
27 | \r | |
28 | #include <Efi/SysEfi.h>\r | |
29 | \r | |
30 | //\r | |
31 | // End of private files\r | |
32 | //\r | |
33 | //----------------------------------------------------------------------\r | |
34 | \r | |
35 | #include <Library/DebugLib.h>\r | |
36 | #include <Library/UefiBootServicesTableLib.h>\r | |
37 | #include <Library/UefiLib.h>\r | |
38 | \r | |
39 | #include <Protocol/EfiSocket.h>\r | |
40 | #include <Protocol/ServiceBinding.h>\r | |
41 | \r | |
42 | #include <sys/errno.h>\r | |
43 | #include <sys/poll.h>\r | |
44 | #include <sys/EfiSysCall.h>\r | |
45 | #include <sys/socket.h>\r | |
46 | \r | |
47 | //------------------------------------------------------------------------------\r | |
48 | // Support Routines\r | |
49 | //------------------------------------------------------------------------------\r | |
50 | \r | |
51 | /**\r | |
52 | Translate from the socket file descriptor to the socket protocol.\r | |
53 | \r | |
54 | @param [in] s Socket file descriptor returned from ::socket.\r | |
55 | \r | |
56 | @param [in] ppDescriptor Address to receive the descriptor structure\r | |
57 | address for the file\r | |
58 | @param [in] pErrno Address of the errno variable\r | |
59 | \r | |
60 | @return A pointer to the EFI_SOCKET_PROTOCOL structure or NULL if\r | |
61 | an invalid file descriptor was passed in.\r | |
62 | \r | |
63 | **/\r | |
64 | EFI_SOCKET_PROTOCOL *\r | |
65 | BslFdToSocketProtocol (\r | |
66 | int s,\r | |
67 | struct __filedes ** ppDescriptor,\r | |
68 | int * pErrno\r | |
69 | );\r | |
70 | \r | |
71 | /**\r | |
72 | Close the socket\r | |
73 | \r | |
74 | The BslSocketClose routine is called indirectly from the close file\r | |
75 | system routine. This routine closes the socket and returns the\r | |
76 | status to the caller.\r | |
77 | \r | |
78 | @param[in] pDescriptor Descriptor address for the file\r | |
79 | \r | |
80 | @return This routine returns 0 upon success and -1 upon failure.\r | |
81 | In the case of failure, ::errno contains more information.\r | |
82 | \r | |
83 | **/\r | |
84 | int\r | |
85 | EFIAPI\r | |
86 | BslSocketClose (\r | |
87 | struct __filedes * pDescriptor\r | |
88 | );\r | |
89 | \r | |
90 | /**\r | |
91 | Worker routine to close the socket.\r | |
92 | \r | |
93 | @param[in] pSocketProtocol Socket protocol structure address\r | |
94 | \r | |
95 | @param[in] pErrno Address of the ::errno variable\r | |
96 | \r | |
97 | @retval EFI_SUCCESS Successfully closed the socket\r | |
98 | \r | |
99 | **/\r | |
100 | EFI_STATUS\r | |
101 | BslSocketCloseWork (\r | |
102 | IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r | |
103 | IN int * pErrno\r | |
104 | );\r | |
105 | \r | |
106 | /**\r | |
107 | Poll the socket for activity\r | |
108 | \r | |
109 | @param [in] pDescriptor Descriptor address for the file\r | |
110 | \r | |
111 | @param [in] Events Mask of events to detect\r | |
112 | \r | |
113 | @return Detected events for the socket\r | |
114 | \r | |
115 | **/\r | |
116 | short\r | |
117 | EFIAPI\r | |
118 | BslSocketPoll (\r | |
119 | IN struct __filedes * pDescriptor,\r | |
120 | IN short Events\r | |
121 | );\r | |
122 | \r | |
123 | /**\r | |
124 | Build a file descriptor for a socket.\r | |
125 | \r | |
126 | @param [in] pSocketProtocol Socket protocol structure address\r | |
127 | \r | |
128 | @param [in] pErrno Address of the errno variable\r | |
129 | \r | |
130 | @return The file descriptor for the socket or -1 if an error occurs.\r | |
131 | \r | |
132 | **/\r | |
133 | int\r | |
134 | BslSocketProtocolToFd (\r | |
135 | IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r | |
136 | IN int * pErrno\r | |
137 | );\r | |
138 | \r | |
139 | /**\r | |
140 | Read support routine for sockets\r | |
141 | \r | |
142 | The BslSocketRead routine is called indirectly by the read file\r | |
143 | system routine. This routine is typically used for SOCK_STREAM\r | |
144 | because it waits for receive data from the target system specified\r | |
145 | in the ::connect call.\r | |
146 | \r | |
147 | @param [in] pDescriptor Descriptor address for the file\r | |
148 | @param [in] pOffset File offset\r | |
149 | @param [in] LengthInBytes Number of bytes to read\r | |
150 | @param [in] pBuffer Address of the buffer to receive the data\r | |
151 | \r | |
152 | @return The number of bytes read or -1 if an error occurs.\r | |
153 | In the case of an error, ::errno contains more details.\r | |
154 | \r | |
155 | **/\r | |
156 | ssize_t\r | |
157 | EFIAPI\r | |
158 | BslSocketRead (\r | |
159 | struct __filedes *pDescriptor,\r | |
160 | off_t * pOffset,\r | |
161 | size_t LengthInBytes,\r | |
162 | void * pBuffer\r | |
163 | );\r | |
164 | \r | |
165 | /**\r | |
166 | Write support routine for sockets\r | |
167 | \r | |
168 | @param [in] pDescriptor Descriptor address for the file\r | |
169 | @param [in] pOffset File offset\r | |
170 | @param [in] LengthInBytes Number of bytes to write\r | |
171 | @param [in] pBuffer Address of the data\r | |
172 | \r | |
173 | @return The number of bytes written or -1 if an error occurs.\r | |
174 | In the case of an error, ::errno contains more details.\r | |
175 | \r | |
176 | **/\r | |
177 | ssize_t\r | |
178 | EFIAPI\r | |
179 | BslSocketWrite (\r | |
180 | struct __filedes *pDescriptor,\r | |
181 | off_t * pOffset,\r | |
182 | size_t LengthInBytes,\r | |
183 | const void * pBuffer\r | |
184 | );\r | |
185 | \r | |
186 | /**\r | |
187 | Validate the socket's file descriptor\r | |
188 | \r | |
189 | @param [in] pDescriptor Descriptor for the file\r | |
190 | \r | |
191 | @param [in] pErrno Address of the errno variable\r | |
192 | \r | |
193 | @return A pointer to the EFI_SOCKET_PROTOCOL structure or NULL if\r | |
194 | an invalid file descriptor was passed in.\r | |
195 | \r | |
196 | **/\r | |
197 | EFI_SOCKET_PROTOCOL *\r | |
198 | BslValidateSocketFd (\r | |
199 | struct __filedes * pDescriptor,\r | |
200 | int * pErrno\r | |
201 | );\r | |
202 | \r | |
203 | //------------------------------------------------------------------------------\r | |
204 | \r | |
205 | #endif // _SOCKET_INTERNALS_H_\r |