• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   UEFI Component Name(2) protocol implementation for Tcp4Dxe driver.
3 
4 Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>
5 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<BR>
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 "Tcp4Main.h"
16 
17 /**
18   Retrieves a Unicode string that is the user readable name of the driver.
19 
20   This function retrieves the user readable name of a driver in the form of a
21   Unicode string. If the driver specified by This has a user readable name in
22   the language specified by Language, then a pointer to the driver name is
23   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
24   by This does not support the language specified by Language,
25   then EFI_UNSUPPORTED is returned.
26 
27   @param[in]  This              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
28                                 EFI_COMPONENT_NAME_PROTOCOL instance.
29 
30   @param[in]  Language          A pointer to a Null-terminated ASCII string
31                                 array indicating the language. This is the
32                                 language of the driver name that the caller is
33                                 requesting, and it must match one of the
34                                 languages specified in SupportedLanguages. The
35                                 number of languages supported by a driver is up
36                                 to the driver writer. Language is specified
37                                 in RFC 4646 or ISO 639-2 language code format.
38 
39   @param[out]  DriverName       A pointer to the Unicode string to return.
40                                 This Unicode string is the name of the
41                                 driver specified by This in the language
42                                 specified by Language.
43 
44   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
45                                 This and the language specified by Language was
46                                 returned in DriverName.
47 
48   @retval EFI_INVALID_PARAMETER Language is NULL.
49 
50   @retval EFI_INVALID_PARAMETER DriverName is NULL.
51 
52   @retval EFI_UNSUPPORTED       The driver specified by This does not support
53                                 the language specified by Language.
54 
55 **/
56 EFI_STATUS
57 EFIAPI
58 TcpComponentNameGetDriverName (
59   IN     EFI_COMPONENT_NAME_PROTOCOL  *This,
60   IN     CHAR8                        *Language,
61      OUT CHAR16                       **DriverName
62   );
63 
64 
65 /**
66   Retrieves a Unicode string that is the user readable name of the controller
67   that is being managed by a driver.
68 
69   This function retrieves the user readable name of the controller specified by
70   ControllerHandle and ChildHandle in the form of a Unicode string. If the
71   driver specified by This has a user readable name in the language specified by
72   Language, then a pointer to the controller name is returned in ControllerName,
73   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
74   managing the controller specified by ControllerHandle and ChildHandle,
75   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
76   support the language specified by Language, then EFI_UNSUPPORTED is returned.
77 
78   @param[in]  This              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
79                                 EFI_COMPONENT_NAME_PROTOCOL instance.
80 
81   @param[in]  ControllerHandle  The handle of a controller that the driver
82                                 specified by This is managing.  This handle
83                                 specifies the controller whose name is to be
84                                 returned.
85 
86   @param[in]  ChildHandle       The handle of the child controller to retrieve
87                                 the name of.  This is an optional parameter that
88                                 may be NULL.  It will be NULL for device
89                                 drivers.  It will also be NULL for a bus drivers
90                                 that wish to retrieve the name of the bus
91                                 controller.  It will not be NULL for a bus
92                                 driver that wishes to retrieve the name of a
93                                 child controller.
94 
95   @param[in]  Language          A pointer to a Null-terminated ASCII string
96                                 array indicating the language.  This is the
97                                 language of the driver name that the caller is
98                                 requesting, and it must match one of the
99                                 languages specified in SupportedLanguages. The
100                                 number of languages supported by a driver is up
101                                 to the driver writer. Language is specified in
102                                 RFC 4646 or ISO 639-2 language code format.
103 
104   @param[out]  ControllerName   A pointer to the Unicode string to return.
105                                 This Unicode string is the name of the
106                                 controller specified by ControllerHandle and
107                                 ChildHandle in the language specified by
108                                 Language from the point of view of the driver
109                                 specified by This.
110 
111   @retval EFI_SUCCESS           The Unicode string for the user readable name in
112                                 the language specified by Language for the
113                                 driver specified by This was returned in
114                                 DriverName.
115 
116   @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
117 
118   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
119                                 EFI_HANDLE.
120 
121   @retval EFI_INVALID_PARAMETER Language is NULL.
122 
123   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
124 
125   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
126                                 managing the controller specified by
127                                 ControllerHandle and ChildHandle.
128 
129   @retval EFI_UNSUPPORTED       The driver specified by This does not support
130                                 the language specified by Language.
131 
132 **/
133 EFI_STATUS
134 EFIAPI
135 TcpComponentNameGetControllerName (
136   IN     EFI_COMPONENT_NAME_PROTOCOL  *This,
137   IN     EFI_HANDLE                   ControllerHandle,
138   IN     EFI_HANDLE                   ChildHandle        OPTIONAL,
139   IN     CHAR8                        *Language,
140      OUT CHAR16                       **ControllerName
141   );
142 
143 
144 ///
145 /// EFI Component Name Protocol
146 ///
147 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL  gTcp4ComponentName = {
148   TcpComponentNameGetDriverName,
149   TcpComponentNameGetControllerName,
150   "eng"
151 };
152 
153 ///
154 /// EFI Component Name 2 Protocol
155 ///
156 GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gTcp4ComponentName2 = {
157   (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) TcpComponentNameGetDriverName,
158   (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) TcpComponentNameGetControllerName,
159   "en"
160 };
161 
162 
163 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE mTcpDriverNameTable[] = {
164   {
165     "eng;en",
166     L"Tcp Network Service Driver"
167   },
168   {
169     NULL,
170     NULL
171   }
172 };
173 
174 GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gTcpControllerNameTable = NULL;
175 
176 /**
177   Retrieves a Unicode string that is the user readable name of the driver.
178 
179   This function retrieves the user readable name of a driver in the form of a
180   Unicode string. If the driver specified by This has a user readable name in
181   the language specified by Language, then a pointer to the driver name is
182   returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
183   by This does not support the language specified by Language,
184   then EFI_UNSUPPORTED is returned.
185 
186   @param[in]  This              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
187                                 EFI_COMPONENT_NAME_PROTOCOL instance.
188 
189   @param[in]  Language          A pointer to a Null-terminated ASCII string
190                                 array indicating the language. This is the
191                                 language of the driver name that the caller is
192                                 requesting, and it must match one of the
193                                 languages specified in SupportedLanguages. The
194                                 number of languages supported by a driver is up
195                                 to the driver writer. Language is specified
196                                 in RFC 4646 or ISO 639-2 language code format.
197 
198   @param[out]  DriverName       A pointer to the Unicode string to return.
199                                 This Unicode string is the name of the
200                                 driver specified by This in the language
201                                 specified by Language.
202 
203   @retval EFI_SUCCESS           The Unicode string for the Driver specified by
204                                 This and the language specified by Language was
205                                 returned in DriverName.
206 
207   @retval EFI_INVALID_PARAMETER Language is NULL.
208 
209   @retval EFI_INVALID_PARAMETER DriverName is NULL.
210 
211   @retval EFI_UNSUPPORTED       The driver specified by This does not support
212                                 the language specified by Language.
213 
214 **/
215 EFI_STATUS
216 EFIAPI
TcpComponentNameGetDriverName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN CHAR8 * Language,OUT CHAR16 ** DriverName)217 TcpComponentNameGetDriverName (
218   IN     EFI_COMPONENT_NAME_PROTOCOL  *This,
219   IN     CHAR8                        *Language,
220      OUT CHAR16                       **DriverName
221   )
222 {
223   return LookupUnicodeString2 (
224            Language,
225            This->SupportedLanguages,
226            mTcpDriverNameTable,
227            DriverName,
228            (BOOLEAN) (This == &gTcp4ComponentName)
229            );
230 }
231 
232 /**
233   Update the component name for the Tcp4 child handle.
234 
235   @param  Tcp4[in]                   A pointer to the EFI_TCP4_PROTOCOL.
236 
237 
238   @retval EFI_SUCCESS                Update the ControllerNameTable of this instance successfully.
239   @retval EFI_INVALID_PARAMETER      The input parameter is invalid.
240 
241 **/
242 EFI_STATUS
UpdateName(IN EFI_TCP4_PROTOCOL * Tcp4)243 UpdateName (
244   IN  EFI_TCP4_PROTOCOL             *Tcp4
245   )
246 {
247   EFI_STATUS                       Status;
248   CHAR16                           HandleName[80];
249   EFI_TCP4_CONFIG_DATA             Tcp4ConfigData;
250 
251   if (Tcp4 == NULL) {
252     return EFI_INVALID_PARAMETER;
253   }
254 
255   //
256   // Format the child name into the string buffer as:
257   // TCPv4 (SrcPort=59, DestPort=60, ActiveFlag=TRUE)
258   //
259   ZeroMem (&Tcp4ConfigData, sizeof (Tcp4ConfigData));
260   Status = Tcp4->GetModeData (Tcp4, NULL, &Tcp4ConfigData, NULL, NULL, NULL);
261   if (!EFI_ERROR (Status)) {
262     UnicodeSPrint (HandleName, sizeof (HandleName),
263       L"TCPv4 (SrcPort=%d, DestPort=%d, ActiveFlag=%s)",
264       Tcp4ConfigData.AccessPoint.StationPort,
265       Tcp4ConfigData.AccessPoint.RemotePort,
266       (Tcp4ConfigData.AccessPoint.ActiveFlag ? L"TRUE" : L"FALSE")
267       );
268   } else if (Status == EFI_NOT_STARTED) {
269     UnicodeSPrint (
270       HandleName,
271       sizeof (HandleName),
272       L"TCPv4 (Not started)"
273       );
274   } else {
275     return Status;
276   }
277 
278   if (gTcpControllerNameTable != NULL) {
279     FreeUnicodeStringTable (gTcpControllerNameTable);
280     gTcpControllerNameTable = NULL;
281   }
282 
283   Status = AddUnicodeString2 (
284              "eng",
285              gTcp4ComponentName.SupportedLanguages,
286              &gTcpControllerNameTable,
287              HandleName,
288              TRUE
289              );
290   if (EFI_ERROR (Status)) {
291     return Status;
292   }
293 
294   return AddUnicodeString2 (
295            "en",
296            gTcp4ComponentName2.SupportedLanguages,
297            &gTcpControllerNameTable,
298            HandleName,
299            FALSE
300            );
301 }
302 
303 /**
304   Retrieves a Unicode string that is the user readable name of the controller
305   that is being managed by a driver.
306 
307   This function retrieves the user readable name of the controller specified by
308   ControllerHandle and ChildHandle in the form of a Unicode string. If the
309   driver specified by This has a user readable name in the language specified by
310   Language, then a pointer to the controller name is returned in ControllerName,
311   and EFI_SUCCESS is returned.  If the driver specified by This is not currently
312   managing the controller specified by ControllerHandle and ChildHandle,
313   then EFI_UNSUPPORTED is returned.  If the driver specified by This does not
314   support the language specified by Language, then EFI_UNSUPPORTED is returned.
315 
316   @param[in]  This              A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
317                                 EFI_COMPONENT_NAME_PROTOCOL instance.
318 
319   @param[in]  ControllerHandle  The handle of a controller that the driver
320                                 specified by This is managing.  This handle
321                                 specifies the controller whose name is to be
322                                 returned.
323 
324   @param[in]  ChildHandle        The handle of the child controller to retrieve
325                                 the name of.  This is an optional parameter that
326                                 may be NULL.  It will be NULL for device
327                                 drivers.  It will also be NULL for a bus drivers
328                                 that wish to retrieve the name of the bus
329                                 controller.  It will not be NULL for a bus
330                                 driver that wishes to retrieve the name of a
331                                 child controller.
332 
333   @param[in]  Language          A pointer to a Null-terminated ASCII string
334                                 array indicating the language.  This is the
335                                 language of the driver name that the caller is
336                                 requesting, and it must match one of the
337                                 languages specified in SupportedLanguages. The
338                                 number of languages supported by a driver is up
339                                 to the driver writer. Language is specified in
340                                 RFC 4646 or ISO 639-2 language code format.
341 
342   @param[out]  ControllerName   A pointer to the Unicode string to return.
343                                 This Unicode string is the name of the
344                                 controller specified by ControllerHandle and
345                                 ChildHandle in the language specified by
346                                 Language from the point of view of the driver
347                                 specified by This.
348 
349   @retval EFI_SUCCESS           The Unicode string for the user readable name in
350                                 the language specified by Language for the
351                                 driver specified by This was returned in
352                                 DriverName.
353 
354   @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
355 
356   @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
357                                 EFI_HANDLE.
358 
359   @retval EFI_INVALID_PARAMETER Language is NULL.
360 
361   @retval EFI_INVALID_PARAMETER ControllerName is NULL.
362 
363   @retval EFI_UNSUPPORTED       The driver specified by This is not currently
364                                 managing the controller specified by
365                                 ControllerHandle and ChildHandle.
366 
367   @retval EFI_UNSUPPORTED       The driver specified by This does not support
368                                 the language specified by Language.
369 
370 **/
371 EFI_STATUS
372 EFIAPI
TcpComponentNameGetControllerName(IN EFI_COMPONENT_NAME_PROTOCOL * This,IN EFI_HANDLE ControllerHandle,IN EFI_HANDLE ChildHandle OPTIONAL,IN CHAR8 * Language,OUT CHAR16 ** ControllerName)373 TcpComponentNameGetControllerName (
374   IN     EFI_COMPONENT_NAME_PROTOCOL  *This,
375   IN     EFI_HANDLE                   ControllerHandle,
376   IN     EFI_HANDLE                   ChildHandle        OPTIONAL,
377   IN     CHAR8                        *Language,
378      OUT CHAR16                       **ControllerName
379   )
380 {
381   EFI_STATUS                    Status;
382   EFI_TCP4_PROTOCOL             *Tcp4;
383 
384   //
385   // Only provide names for child handles.
386   //
387   if (ChildHandle == NULL) {
388     return EFI_UNSUPPORTED;
389   }
390 
391   //
392   // Make sure this driver produced ChildHandle
393   //
394   Status = EfiTestChildHandle (
395              ControllerHandle,
396              ChildHandle,
397              &gEfiIp4ProtocolGuid
398              );
399   if (EFI_ERROR (Status)) {
400     return Status;
401   }
402 
403   //
404   // Retrieve an instance of a produced protocol from ChildHandle
405   //
406   Status = gBS->OpenProtocol (
407                   ChildHandle,
408                   &gEfiTcp4ProtocolGuid,
409                   (VOID **)&Tcp4,
410                   NULL,
411                   NULL,
412                   EFI_OPEN_PROTOCOL_GET_PROTOCOL
413                   );
414   if (EFI_ERROR (Status)) {
415     return Status;
416   }
417 
418   //
419   // Update the component name for this child handle.
420   //
421   Status = UpdateName (Tcp4);
422   if (EFI_ERROR (Status)) {
423     return Status;
424   }
425 
426   return LookupUnicodeString2 (
427            Language,
428            This->SupportedLanguages,
429            gTcpControllerNameTable,
430            ControllerName,
431            (BOOLEAN)(This == &gTcp4ComponentName)
432            );
433 }
434