]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/DnsDxe/ComponentName.c
NetworkPkg: Removing or adding some ASSERT statement
[mirror_edk2.git] / NetworkPkg / DnsDxe / ComponentName.c
CommitLineData
99c048ef 1/** @file\r
2Implementation of EFI_COMPONENT_NAME_PROTOCOL and EFI_COMPONENT_NAME2_PROTOCOL protocol.\r
3\r
4Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "DnsImpl.h"\r
16\r
17//\r
18// EFI Component Name Functions\r
19//\r
20/**\r
21 Retrieves a Unicode string that is the user-readable name of the EFI Driver.\r
22\r
23 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
24 @param Language A pointer to a three-character ISO 639-2 language identifier.\r
25 This is the language of the driver name that that the caller\r
26 is requesting, and it must match one of the languages specified\r
27 in SupportedLanguages. The number of languages supported by a\r
28 driver is up to the driver writer.\r
29 @param DriverName A pointer to the Unicode string to return. This Unicode string\r
30 is the name of the driver specified by This in the language\r
31 specified by Language.\r
32\r
33 @retval EFI_SUCCESS The Unicode string for the Driver specified by This\r
34 and the language specified by Language was returned\r
35 in DriverName.\r
36 @retval EFI_INVALID_PARAMETER Language is NULL.\r
37 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
38 @retval EFI_UNSUPPORTED The driver specified by This does not support the\r
39 language specified by Language.\r
40\r
41**/\r
42EFI_STATUS\r
43EFIAPI\r
44DnsComponentNameGetDriverName (\r
45 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
46 IN CHAR8 *Language,\r
47 OUT CHAR16 **DriverName\r
48 );\r
49\r
50/**\r
51 Retrieves a Unicode string that is the user readable name of the controller\r
52 that is being managed by an EFI Driver.\r
53\r
54 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
55 @param ControllerHandle The handle of a controller that the driver specified by\r
56 This is managing. This handle specifies the controller\r
57 whose name is to be returned.\r
58 @param ChildHandle The handle of the child controller to retrieve the name\r
59 of. This is an optional parameter that may be NULL. It\r
60 will be NULL for device drivers. It will also be NULL\r
61 for a bus drivers that wish to retrieve the name of the\r
62 bus controller. It will not be NULL for a bus driver\r
63 that wishes to retrieve the name of a child controller.\r
64 @param Language A pointer to a three character ISO 639-2 language\r
65 identifier. This is the language of the controller name\r
66 that the caller is requesting, and it must match one\r
67 of the languages specified in SupportedLanguages. The\r
68 number of languages supported by a driver is up to the\r
69 driver writer.\r
70 @param ControllerName A pointer to the Unicode string to return. This Unicode\r
71 string is the name of the controller specified by\r
72 ControllerHandle and ChildHandle in the language specified\r
73 by Language, from the point of view of the driver specified\r
74 by This.\r
75\r
76 @retval EFI_SUCCESS The Unicode string for the user-readable name in the\r
77 language specified by Language for the driver\r
78 specified by This was returned in DriverName.\r
79 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
80 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
81 @retval EFI_INVALID_PARAMETER Language is NULL.\r
82 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
83 @retval EFI_UNSUPPORTED The driver specified by This is not currently managing\r
84 the controller specified by ControllerHandle and\r
85 ChildHandle.\r
86 @retval EFI_UNSUPPORTED The driver specified by This does not support the\r
87 language specified by Language.\r
88\r
89**/\r
90EFI_STATUS\r
91EFIAPI\r
92DnsComponentNameGetControllerName (\r
93 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
94 IN EFI_HANDLE ControllerHandle,\r
95 IN EFI_HANDLE ChildHandle OPTIONAL,\r
96 IN CHAR8 *Language,\r
97 OUT CHAR16 **ControllerName\r
98 );\r
99\r
100\r
101///\r
102/// Component Name Protocol instance\r
103///\r
104GLOBAL_REMOVE_IF_UNREFERENCED \r
105EFI_COMPONENT_NAME_PROTOCOL gDnsComponentName = {\r
106 DnsComponentNameGetDriverName,\r
107 DnsComponentNameGetControllerName,\r
108 "eng"\r
109};\r
110\r
111///\r
112/// Component Name 2 Protocol instance\r
113///\r
114GLOBAL_REMOVE_IF_UNREFERENCED \r
115EFI_COMPONENT_NAME2_PROTOCOL gDnsComponentName2 = {\r
116 (EFI_COMPONENT_NAME2_GET_DRIVER_NAME) DnsComponentNameGetDriverName,\r
117 (EFI_COMPONENT_NAME2_GET_CONTROLLER_NAME) DnsComponentNameGetControllerName,\r
118 "en"\r
119};\r
120\r
121///\r
122/// Table of driver names\r
123///\r
124GLOBAL_REMOVE_IF_UNREFERENCED \r
125EFI_UNICODE_STRING_TABLE mDnsDriverNameTable[] = {\r
126 { "eng;en", (CHAR16 *)L"DNS Network Service Driver" },\r
127 { NULL, NULL }\r
128};\r
129\r
130GLOBAL_REMOVE_IF_UNREFERENCED EFI_UNICODE_STRING_TABLE *gDnsControllerNameTable = NULL;\r
131\r
132/**\r
133 Retrieves a Unicode string that is the user-readable name of the EFI Driver.\r
134\r
135 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
136 @param Language A pointer to a three-character ISO 639-2 language identifier.\r
137 This is the language of the driver name that that the caller\r
138 is requesting, and it must match one of the languages specified\r
139 in SupportedLanguages. The number of languages supported by a\r
140 driver is up to the driver writer.\r
141 @param DriverName A pointer to the Unicode string to return. This Unicode string\r
142 is the name of the driver specified by This in the language\r
143 specified by Language.\r
144\r
145 @retval EFI_SUCCESS The Unicode string for the Driver specified by This\r
146 and the language specified by Language was returned\r
147 in DriverName.\r
148 @retval EFI_INVALID_PARAMETER Language is NULL.\r
149 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
150 @retval EFI_UNSUPPORTED The driver specified by This does not support the\r
151 language specified by Language.\r
152\r
153**/\r
154EFI_STATUS\r
155EFIAPI\r
156DnsComponentNameGetDriverName (\r
157 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
158 IN CHAR8 *Language,\r
159 OUT CHAR16 **DriverName\r
160 )\r
161{\r
162 return LookupUnicodeString2 (\r
163 Language,\r
164 This->SupportedLanguages,\r
165 mDnsDriverNameTable,\r
166 DriverName,\r
167 (BOOLEAN)(This == &gDnsComponentName)\r
168 );\r
169}\r
170\r
171/**\r
172 Update the component name for the Dns4 child handle.\r
173\r
174 @param Dns4 A pointer to the EFI_DNS4_PROTOCOL.\r
175\r
176 \r
177 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r
178 @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r
179 \r
180**/\r
181EFI_STATUS\r
182UpdateDns4Name (\r
183 EFI_DNS4_PROTOCOL *Dns4\r
184 )\r
185{\r
186 EFI_STATUS Status;\r
187 CHAR16 HandleName[80];\r
188 EFI_DNS4_MODE_DATA ModeData;\r
189\r
190 if (Dns4 == NULL) {\r
191 return EFI_INVALID_PARAMETER;\r
192 }\r
193 \r
194 //\r
195 // Format the child name into the string buffer as:\r
196 // DNSv4 (StationIp=?, LocalPort=?)\r
197 //\r
198 Status = Dns4->GetModeData (Dns4, &ModeData);\r
199 if (EFI_ERROR (Status)) {\r
200 return Status;\r
201 }\r
202 \r
203 UnicodeSPrint (\r
204 HandleName,\r
205 sizeof (HandleName),\r
206 L"DNSv4 (StationIp=%d.%d.%d.%d, LocalPort=%d)",\r
207 ModeData.DnsConfigData.StationIp.Addr[0],\r
208 ModeData.DnsConfigData.StationIp.Addr[1],\r
209 ModeData.DnsConfigData.StationIp.Addr[2],\r
210 ModeData.DnsConfigData.StationIp.Addr[3],\r
211 ModeData.DnsConfigData.LocalPort\r
212 );\r
213\r
214 if (gDnsControllerNameTable != NULL) {\r
215 FreeUnicodeStringTable (gDnsControllerNameTable);\r
216 gDnsControllerNameTable = NULL;\r
217 }\r
218 \r
219 Status = AddUnicodeString2 (\r
220 "eng",\r
221 gDnsComponentName.SupportedLanguages,\r
222 &gDnsControllerNameTable,\r
223 HandleName,\r
224 TRUE\r
225 );\r
226 if (EFI_ERROR (Status)) {\r
227 return Status;\r
228 }\r
229 \r
230 return AddUnicodeString2 (\r
231 "en",\r
232 gDnsComponentName2.SupportedLanguages,\r
233 &gDnsControllerNameTable,\r
234 HandleName,\r
235 FALSE\r
236 );\r
237}\r
238\r
239/**\r
240 Update the component name for the Dns6 child handle.\r
241\r
242 @param Dns6 A pointer to the EFI_DNS6_PROTOCOL.\r
243\r
244 \r
245 @retval EFI_SUCCESS Update the ControllerNameTable of this instance successfully.\r
246 @retval EFI_INVALID_PARAMETER The input parameter is invalid.\r
247 \r
248**/\r
249EFI_STATUS\r
250UpdateDns6Name (\r
251 EFI_DNS6_PROTOCOL *Dns6\r
252 )\r
253{\r
254 EFI_STATUS Status;\r
255 CHAR16 HandleName[128];\r
256 EFI_DNS6_MODE_DATA ModeData;\r
257 CHAR16 Address[sizeof"ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"];\r
258\r
259 if (Dns6 == NULL) {\r
260 return EFI_INVALID_PARAMETER;\r
261 }\r
262 \r
263 //\r
264 // Format the child name into the string buffer as:\r
265 // DNSv6 (StationIp=?, LocalPort=?)\r
266 //\r
267 Status = Dns6->GetModeData (Dns6, &ModeData);\r
268 if (EFI_ERROR (Status)) {\r
269 return Status;\r
270 }\r
271\r
272 Status = NetLibIp6ToStr (&ModeData.DnsConfigData.StationIp, Address, sizeof (Address));\r
273 if (EFI_ERROR (Status)) {\r
274 return Status;\r
275 }\r
276 UnicodeSPrint (\r
277 HandleName,\r
278 sizeof (HandleName), \r
279 L"DNSv6 (StationIp=%s, LocalPort=%d)",\r
280 Address,\r
281 ModeData.DnsConfigData.LocalPort\r
282 );\r
283\r
284 if (gDnsControllerNameTable != NULL) {\r
285 FreeUnicodeStringTable (gDnsControllerNameTable);\r
286 gDnsControllerNameTable = NULL;\r
287 }\r
288 \r
289 Status = AddUnicodeString2 (\r
290 "eng",\r
291 gDnsComponentName.SupportedLanguages,\r
292 &gDnsControllerNameTable,\r
293 HandleName,\r
294 TRUE\r
295 );\r
296 if (EFI_ERROR (Status)) {\r
297 return Status;\r
298 }\r
299 \r
300 return AddUnicodeString2 (\r
301 "en",\r
302 gDnsComponentName2.SupportedLanguages,\r
303 &gDnsControllerNameTable,\r
304 HandleName,\r
305 FALSE\r
306 );\r
307}\r
308\r
309/**\r
310 Retrieves a Unicode string that is the user readable name of the controller\r
311 that is being managed by an EFI Driver.\r
312\r
313 @param This A pointer to the EFI_COMPONENT_NAME_PROTOCOL instance.\r
314 @param ControllerHandle The handle of a controller that the driver specified by\r
315 This is managing. This handle specifies the controller\r
316 whose name is to be returned.\r
317 @param ChildHandle The handle of the child controller to retrieve the name\r
318 of. This is an optional parameter that may be NULL. It\r
319 will be NULL for device drivers. It will also be NULL\r
320 for a bus drivers that wish to retrieve the name of the\r
321 bus controller. It will not be NULL for a bus driver\r
322 that wishes to retrieve the name of a child controller.\r
323 @param Language A pointer to a three character ISO 639-2 language\r
324 identifier. This is the language of the controller name\r
325 that the caller is requesting, and it must match one\r
326 of the languages specified in SupportedLanguages. The\r
327 number of languages supported by a driver is up to the\r
328 driver writer.\r
329 @param ControllerName A pointer to the Unicode string to return. This Unicode\r
330 string is the name of the controller specified by\r
331 ControllerHandle and ChildHandle in the language specified\r
332 by Language, from the point of view of the driver specified\r
333 by This.\r
334\r
335 @retval EFI_SUCCESS The Unicode string for the user-readable name in the\r
336 language specified by Language for the driver\r
337 specified by This was returned in DriverName.\r
338 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
339 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
340 @retval EFI_INVALID_PARAMETER Language is NULL.\r
341 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
342 @retval EFI_UNSUPPORTED The driver specified by This is not currently managing\r
343 the controller specified by ControllerHandle and\r
344 ChildHandle.\r
345 @retval EFI_UNSUPPORTED The driver specified by This does not support the\r
346 language specified by Language.\r
347\r
348**/\r
349EFI_STATUS\r
350EFIAPI\r
351DnsComponentNameGetControllerName (\r
352 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
353 IN EFI_HANDLE ControllerHandle,\r
354 IN EFI_HANDLE ChildHandle OPTIONAL,\r
355 IN CHAR8 *Language,\r
356 OUT CHAR16 **ControllerName\r
357 )\r
358{\r
359 EFI_STATUS Status;\r
360 EFI_DNS4_PROTOCOL *Dns4;\r
361 EFI_DNS6_PROTOCOL *Dns6;\r
362 \r
363 //\r
364 // ChildHandle must be NULL for a Device Driver\r
365 //\r
366 if (ChildHandle == NULL) {\r
367 return EFI_UNSUPPORTED;\r
368 }\r
369\r
370 //\r
371 // Make sure this driver produced ChildHandle\r
372 //\r
373 Status = EfiTestChildHandle (\r
374 ControllerHandle,\r
375 ChildHandle,\r
376 &gEfiUdp6ProtocolGuid\r
377 );\r
378 if (!EFI_ERROR (Status)) {\r
379 //\r
380 // Retrieve an instance of a produced protocol from ChildHandle\r
381 //\r
382 Status = gBS->OpenProtocol (\r
383 ChildHandle,\r
384 &gEfiDns6ProtocolGuid,\r
385 (VOID **)&Dns6,\r
386 NULL,\r
387 NULL,\r
388 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
389 );\r
390 if (EFI_ERROR (Status)) {\r
391 return Status;\r
392 }\r
393\r
394 //\r
395 // Update the component name for this child handle.\r
396 //\r
397 Status = UpdateDns6Name (Dns6);\r
398 if (EFI_ERROR (Status)) {\r
399 return Status;\r
400 }\r
401 }\r
402\r
403 //\r
404 // Make sure this driver produced ChildHandle\r
405 //\r
406 Status = EfiTestChildHandle (\r
407 ControllerHandle,\r
408 ChildHandle,\r
409 &gEfiUdp4ProtocolGuid\r
410 );\r
411 if (!EFI_ERROR (Status)) {\r
412 //\r
413 // Retrieve an instance of a produced protocol from ChildHandle\r
414 //\r
415 Status = gBS->OpenProtocol (\r
416 ChildHandle,\r
417 &gEfiDns4ProtocolGuid,\r
418 (VOID **)&Dns4,\r
419 NULL,\r
420 NULL,\r
421 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
422 );\r
423 if (EFI_ERROR (Status)) {\r
424 return Status;\r
425 }\r
426\r
427 //\r
428 // Update the component name for this child handle.\r
429 //\r
430 Status = UpdateDns4Name (Dns4);\r
431 if (EFI_ERROR (Status)) {\r
432 return Status;\r
433 }\r
434 }\r
435\r
436 return LookupUnicodeString2 (\r
437 Language,\r
438 This->SupportedLanguages,\r
439 gDnsControllerNameTable,\r
440 ControllerName,\r
441 (BOOLEAN)(This == &gDnsComponentName)\r
442 );\r
443}\r