]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/UseSocketDxe/UseSocketDxe.c
StdLib, StdLibPrivateInternalFiles: Clean up comments, Remove debugging code, Define...
[mirror_edk2.git] / StdLib / UseSocketDxe / UseSocketDxe.c
1 /** @file
2 Implement the connection to the socket driver
3
4 Copyright (c) 2011, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include <Uefi.h>
16
17 #include <Library/DebugLib.h>
18 #include <Library/UefiBootServicesTableLib.h>
19 #include <Library/UefiLib.h>
20
21 #include <Protocol/EfiSocket.h>
22 #include <Protocol/ServiceBinding.h>
23
24
25 /**
26 Connect to the EFI socket library
27
28 This routine establishes a connection to the socket driver
29 and returns the API (::EFI_SOCKET_PROTOCOL address) to the
30 socket file system layer in BsdSocketLib. This routine looks for
31 the gEfiSocketServiceBindingProtocolGuid to locate the socket
32 driver. This routine then creates a child handle and locates
33 the gEfiSocketProtocolGuid protocol on that handle to get the
34 ::EFI_SOCKET_PROTOCOL structure address.
35
36 This routine is called from the ::socket routine in BsdSocketLib
37 to create the data structure and initialize the API for a socket.
38 Note that this implementation is only used by socket applications
39 that link directly to UseSocketDxe.
40
41 @param [in] ppSocketProtocol Address to receive the ::EFI_SOCKET_PROTOCOL
42 structure address
43
44 @return Value for ::errno, zero (0) indicates success.
45
46 **/
47 int
48 EslServiceGetProtocol (
49 IN EFI_SOCKET_PROTOCOL ** ppSocketProtocol
50 )
51 {
52 EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding;
53 int RetVal;
54 EFI_HANDLE SocketHandle;
55 EFI_STATUS Status;
56
57 //
58 // Locate the socket protocol
59 //
60 Status = gBS->LocateProtocol ( &gEfiSocketServiceBindingProtocolGuid,
61 NULL,
62 (VOID **)&pServiceBinding );
63 if ( !EFI_ERROR ( Status )) {
64 //
65 // Create a new socket
66 //
67 SocketHandle = NULL;
68 Status = pServiceBinding->CreateChild ( pServiceBinding,
69 &SocketHandle );
70 if ( !EFI_ERROR ( Status )) {
71 //
72 // Get the socket protocol
73 //
74 Status = gBS->OpenProtocol ( SocketHandle,
75 &gEfiSocketProtocolGuid,
76 (VOID **)ppSocketProtocol,
77 NULL,
78 NULL,
79 EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL );
80 if ( !EFI_ERROR ( Status )) {
81 //
82 // Success!
83 //
84 RetVal = 0;
85 }
86 else {
87 DEBUG (( DEBUG_ERROR,
88 "ERROR - No socket protocol on 0x%08x, Status: %r\r\n",
89 SocketHandle,
90 Status ));
91 RetVal = ENODEV;
92 }
93 }
94 else {
95 //
96 // Translate the error
97 //
98 DEBUG (( DEBUG_ERROR,
99 "ERROR - CreateChild failed, Status: %r\r\n",
100 Status ));
101 switch ( Status ) {
102 case EFI_SUCCESS:
103 RetVal = 0;
104 break;
105
106 case EFI_ACCESS_DENIED:
107 case EFI_WRITE_PROTECTED:
108 RetVal = EACCES;
109 break;
110
111 case EFI_NO_RESPONSE:
112 RetVal = EHOSTUNREACH;
113 break;
114
115 case EFI_BAD_BUFFER_SIZE:
116 case EFI_BUFFER_TOO_SMALL:
117 case EFI_INVALID_PARAMETER:
118 RetVal = EINVAL;
119 break;
120
121 case EFI_DEVICE_ERROR:
122 case EFI_MEDIA_CHANGED:
123 case EFI_NO_MEDIA:
124 case EFI_VOLUME_CORRUPTED:
125 RetVal = EIO;
126 break;
127
128 case EFI_NOT_FOUND:
129 RetVal = ENOENT;
130 break;
131
132 default:
133 case EFI_OUT_OF_RESOURCES:
134 RetVal = ENOMEM;
135 break;
136
137 case EFI_VOLUME_FULL:
138 RetVal = ENOSPC;
139 break;
140
141 case EFI_UNSUPPORTED:
142 RetVal = ENOSYS;
143 break;
144
145 case EFI_NO_MAPPING:
146 RetVal = ENXIO;
147 break;
148
149 case EFI_LOAD_ERROR:
150 RetVal = ESRCH;
151 break;
152
153 case EFI_TIMEOUT:
154 RetVal = ETIMEDOUT;
155 break;
156
157 case EFI_NOT_READY:
158 RetVal = EWOULDBLOCK;
159 break;
160 }
161 }
162 }
163 else {
164 DEBUG (( DEBUG_ERROR,
165 "ERROR - Socket driver not loaded, Status: %r\r\n",
166 Status ));
167 RetVal = ENODEV;
168 }
169
170 //
171 // Return the operation status
172 //
173 return RetVal;
174 }