]>
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 | |
26 | Connect to the socket driver\r | |
27 | \r | |
28 | @param [in] ppSocketProtocol Address to receive the socket protocol address\r | |
29 | \r | |
30 | @retval 0 Successfully returned the socket protocol\r | |
31 | @retval other Value for errno\r | |
32 | **/\r | |
33 | int\r | |
34 | EslServiceGetProtocol (\r | |
35 | IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol\r | |
36 | )\r | |
37 | {\r | |
38 | EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding;\r | |
39 | int RetVal;\r | |
40 | EFI_HANDLE SocketHandle;\r | |
41 | EFI_STATUS Status;\r | |
42 | \r | |
43 | //\r | |
44 | // Locate the socket protocol\r | |
45 | //\r | |
46 | Status = gBS->LocateProtocol ( &gEfiSocketServiceBindingProtocolGuid,\r | |
47 | NULL,\r | |
48 | (VOID **)&pServiceBinding );\r | |
49 | if ( !EFI_ERROR ( Status )) {\r | |
50 | //\r | |
51 | // Create a new socket\r | |
52 | //\r | |
53 | SocketHandle = NULL;\r | |
54 | Status = pServiceBinding->CreateChild ( pServiceBinding,\r | |
55 | &SocketHandle );\r | |
56 | if ( !EFI_ERROR ( Status )) {\r | |
57 | //\r | |
58 | // Get the socket protocol\r | |
59 | //\r | |
60 | Status = gBS->OpenProtocol ( SocketHandle,\r | |
61 | &gEfiSocketProtocolGuid,\r | |
62 | (VOID **)ppSocketProtocol,\r | |
63 | NULL,\r | |
64 | NULL,\r | |
65 | EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL );\r | |
66 | if ( !EFI_ERROR ( Status )) {\r | |
67 | //\r | |
68 | // Success!\r | |
69 | //\r | |
70 | RetVal = 0;\r | |
71 | }\r | |
72 | else {\r | |
73 | DEBUG (( DEBUG_ERROR,\r | |
74 | "ERROR - No socket protocol on 0x%08x, Status: %r\r\n",\r | |
75 | SocketHandle,\r | |
76 | Status ));\r | |
77 | RetVal = ENODEV;\r | |
78 | }\r | |
79 | }\r | |
80 | else {\r | |
81 | //\r | |
82 | // Translate the error\r | |
83 | //\r | |
84 | DEBUG (( DEBUG_ERROR,\r | |
85 | "ERROR - CreateChild failed, Status: %r\r\n",\r | |
86 | Status ));\r | |
87 | switch ( Status ) {\r | |
88 | case EFI_SUCCESS:\r | |
89 | RetVal = 0;\r | |
90 | break;\r | |
91 | \r | |
92 | case EFI_ACCESS_DENIED:\r | |
93 | case EFI_WRITE_PROTECTED:\r | |
94 | RetVal = EACCES;\r | |
95 | break;\r | |
96 | \r | |
97 | case EFI_NO_RESPONSE:\r | |
98 | RetVal = EHOSTUNREACH;\r | |
99 | break;\r | |
100 | \r | |
101 | case EFI_BAD_BUFFER_SIZE:\r | |
102 | case EFI_BUFFER_TOO_SMALL:\r | |
103 | case EFI_INVALID_PARAMETER:\r | |
104 | RetVal = EINVAL;\r | |
105 | break;\r | |
106 | \r | |
107 | case EFI_DEVICE_ERROR:\r | |
108 | case EFI_MEDIA_CHANGED:\r | |
109 | case EFI_NO_MEDIA:\r | |
110 | case EFI_VOLUME_CORRUPTED:\r | |
111 | RetVal = EIO;\r | |
112 | break;\r | |
113 | \r | |
114 | case EFI_NOT_FOUND:\r | |
115 | RetVal = ENOENT;\r | |
116 | break;\r | |
117 | \r | |
118 | default:\r | |
119 | case EFI_OUT_OF_RESOURCES:\r | |
120 | RetVal = ENOMEM;\r | |
121 | break;\r | |
122 | \r | |
123 | case EFI_VOLUME_FULL:\r | |
124 | RetVal = ENOSPC;\r | |
125 | break;\r | |
126 | \r | |
127 | case EFI_UNSUPPORTED:\r | |
128 | RetVal = ENOSYS;\r | |
129 | break;\r | |
130 | \r | |
131 | case EFI_NO_MAPPING:\r | |
132 | RetVal = ENXIO;\r | |
133 | break;\r | |
134 | \r | |
135 | case EFI_LOAD_ERROR:\r | |
136 | RetVal = ESRCH;\r | |
137 | break;\r | |
138 | \r | |
139 | case EFI_TIMEOUT:\r | |
140 | RetVal = ETIMEDOUT;\r | |
141 | break;\r | |
142 | \r | |
143 | case EFI_NOT_READY:\r | |
144 | RetVal = EWOULDBLOCK;\r | |
145 | break;\r | |
146 | }\r | |
147 | }\r | |
148 | }\r | |
149 | else {\r | |
150 | DEBUG (( DEBUG_ERROR,\r | |
151 | "ERROR - No socket service binding protocol, Status: %r\r\n",\r | |
152 | Status ));\r | |
153 | RetVal = ENODEV;\r | |
154 | }\r | |
155 | \r | |
156 | //\r | |
157 | // Return the operation status\r | |
158 | //\r | |
159 | return RetVal;\r | |
160 | }\r |