]>
Commit | Line | Data |
---|---|---|
d7ce7006 | 1 | /** @file\r |
2 | Implement the connection to the socket driver\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 | #include <Uefi.h>\r | |
16 | \r | |
17 | #include <Library/DebugLib.h>\r | |
18 | #include <Library/UefiBootServicesTableLib.h>\r | |
19 | #include <Library/UefiLib.h>\r | |
20 | \r | |
21 | #include <Protocol/EfiSocket.h>\r | |
22 | #include <Protocol/ServiceBinding.h>\r | |
23 | \r | |
24 | \r | |
25 | /**\r | |
a88c3163 | 26 | Connect to the EFI socket library\r |
d7ce7006 | 27 | \r |
a88c3163 | 28 | This routine establishes a connection to the socket driver\r |
29 | and returns the API (::EFI_SOCKET_PROTOCOL address) to the\r | |
30 | socket file system layer in BsdSocketLib. This routine looks for\r | |
31 | the gEfiSocketServiceBindingProtocolGuid to locate the socket\r | |
32 | driver. This routine then creates a child handle and locates\r | |
33 | the gEfiSocketProtocolGuid protocol on that handle to get the\r | |
34 | ::EFI_SOCKET_PROTOCOL structure address.\r | |
35 | \r | |
36 | This routine is called from the ::socket routine in BsdSocketLib\r | |
37 | to create the data structure and initialize the API for a socket.\r | |
38 | Note that this implementation is only used by socket applications\r | |
39 | that link directly to UseSocketDxe.\r | |
40 | \r | |
41 | @param [in] ppSocketProtocol Address to receive the ::EFI_SOCKET_PROTOCOL\r | |
42 | structure address\r | |
43 | \r | |
44 | @return Value for ::errno, zero (0) indicates success.\r | |
d7ce7006 | 45 | \r |
d7ce7006 | 46 | **/\r |
47 | int\r | |
48 | EslServiceGetProtocol (\r | |
49 | IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol\r | |
50 | )\r | |
51 | {\r | |
52 | EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding;\r | |
53 | int RetVal;\r | |
54 | EFI_HANDLE SocketHandle;\r | |
55 | EFI_STATUS Status;\r | |
56 | \r | |
57 | //\r | |
58 | // Locate the socket protocol\r | |
59 | //\r | |
60 | Status = gBS->LocateProtocol ( &gEfiSocketServiceBindingProtocolGuid,\r | |
61 | NULL,\r | |
62 | (VOID **)&pServiceBinding );\r | |
63 | if ( !EFI_ERROR ( Status )) {\r | |
64 | //\r | |
65 | // Create a new socket\r | |
66 | //\r | |
67 | SocketHandle = NULL;\r | |
68 | Status = pServiceBinding->CreateChild ( pServiceBinding,\r | |
69 | &SocketHandle );\r | |
70 | if ( !EFI_ERROR ( Status )) {\r | |
71 | //\r | |
72 | // Get the socket protocol\r | |
73 | //\r | |
74 | Status = gBS->OpenProtocol ( SocketHandle,\r | |
75 | &gEfiSocketProtocolGuid,\r | |
76 | (VOID **)ppSocketProtocol,\r | |
77 | NULL,\r | |
78 | NULL,\r | |
79 | EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL );\r | |
80 | if ( !EFI_ERROR ( Status )) {\r | |
81 | //\r | |
82 | // Success!\r | |
83 | //\r | |
84 | RetVal = 0;\r | |
85 | }\r | |
86 | else {\r | |
87 | DEBUG (( DEBUG_ERROR,\r | |
88 | "ERROR - No socket protocol on 0x%08x, Status: %r\r\n",\r | |
89 | SocketHandle,\r | |
90 | Status ));\r | |
91 | RetVal = ENODEV;\r | |
92 | }\r | |
93 | }\r | |
94 | else {\r | |
95 | //\r | |
96 | // Translate the error\r | |
97 | //\r | |
98 | DEBUG (( DEBUG_ERROR,\r | |
99 | "ERROR - CreateChild failed, Status: %r\r\n",\r | |
100 | Status ));\r | |
101 | switch ( Status ) {\r | |
102 | case EFI_SUCCESS:\r | |
103 | RetVal = 0;\r | |
104 | break;\r | |
105 | \r | |
106 | case EFI_ACCESS_DENIED:\r | |
107 | case EFI_WRITE_PROTECTED:\r | |
108 | RetVal = EACCES;\r | |
109 | break;\r | |
110 | \r | |
111 | case EFI_NO_RESPONSE:\r | |
112 | RetVal = EHOSTUNREACH;\r | |
113 | break;\r | |
114 | \r | |
115 | case EFI_BAD_BUFFER_SIZE:\r | |
116 | case EFI_BUFFER_TOO_SMALL:\r | |
117 | case EFI_INVALID_PARAMETER:\r | |
118 | RetVal = EINVAL;\r | |
119 | break;\r | |
120 | \r | |
121 | case EFI_DEVICE_ERROR:\r | |
122 | case EFI_MEDIA_CHANGED:\r | |
123 | case EFI_NO_MEDIA:\r | |
124 | case EFI_VOLUME_CORRUPTED:\r | |
125 | RetVal = EIO;\r | |
126 | break;\r | |
127 | \r | |
128 | case EFI_NOT_FOUND:\r | |
129 | RetVal = ENOENT;\r | |
130 | break;\r | |
131 | \r | |
132 | default:\r | |
133 | case EFI_OUT_OF_RESOURCES:\r | |
134 | RetVal = ENOMEM;\r | |
135 | break;\r | |
136 | \r | |
137 | case EFI_VOLUME_FULL:\r | |
138 | RetVal = ENOSPC;\r | |
139 | break;\r | |
140 | \r | |
141 | case EFI_UNSUPPORTED:\r | |
142 | RetVal = ENOSYS;\r | |
143 | break;\r | |
144 | \r | |
145 | case EFI_NO_MAPPING:\r | |
146 | RetVal = ENXIO;\r | |
147 | break;\r | |
148 | \r | |
149 | case EFI_LOAD_ERROR:\r | |
150 | RetVal = ESRCH;\r | |
151 | break;\r | |
152 | \r | |
153 | case EFI_TIMEOUT:\r | |
154 | RetVal = ETIMEDOUT;\r | |
155 | break;\r | |
156 | \r | |
157 | case EFI_NOT_READY:\r | |
158 | RetVal = EWOULDBLOCK;\r | |
159 | break;\r | |
160 | }\r | |
161 | }\r | |
162 | }\r | |
163 | else {\r | |
164 | DEBUG (( DEBUG_ERROR,\r | |
a88c3163 | 165 | "ERROR - Socket driver not loaded, Status: %r\r\n",\r |
d7ce7006 | 166 | Status ));\r |
167 | RetVal = ENODEV;\r | |
168 | }\r | |
169 | \r | |
170 | //\r | |
171 | // Return the operation status\r | |
172 | //\r | |
173 | return RetVal;\r | |
174 | }\r |