]>
Commit | Line | Data |
---|---|---|
dc361cc5 | 1 | /** @file\r |
f737cfb9 | 2 | Support routines for PxeBc.\r |
3 | \r | |
6d3ea23f | 4 | Copyright (c) 2007 - 2009, Intel Corporation.<BR> \r |
dc361cc5 | 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 | |
dc361cc5 | 13 | **/\r |
14 | \r | |
15 | \r | |
16 | #include "PxeBcImpl.h"\r | |
17 | \r | |
18 | \r | |
19 | /**\r | |
f737cfb9 | 20 | This function returns SMBIOS string given the string number.\r |
21 | \r | |
dc361cc5 | 22 | @param Smbios Pointer to SMBIOS structure\r |
23 | @param StringNumber String number to return. 0 is used to skip all\r | |
24 | strings and point to the next SMBIOS structure.\r | |
25 | \r | |
26 | @return Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == 0\r | |
27 | \r | |
28 | **/\r | |
dc361cc5 | 29 | CHAR8 *\r |
30 | GetSmbiosString (\r | |
31 | IN SMBIOS_STRUCTURE_POINTER *Smbios,\r | |
32 | IN UINT16 StringNumber\r | |
33 | )\r | |
34 | {\r | |
35 | UINT16 Index;\r | |
36 | CHAR8 *String;\r | |
37 | \r | |
38 | //\r | |
39 | // Skip over formatted section\r | |
40 | //\r | |
41 | String = (CHAR8 *) (Smbios->Raw + Smbios->Hdr->Length);\r | |
42 | \r | |
43 | //\r | |
44 | // Look through unformated section\r | |
45 | //\r | |
46 | for (Index = 1; Index <= StringNumber || StringNumber == 0; Index++) {\r | |
47 | if (StringNumber == Index) {\r | |
48 | return String;\r | |
49 | }\r | |
50 | //\r | |
51 | // Skip string\r | |
52 | //\r | |
53 | for (; *String != 0; String++)\r | |
54 | ;\r | |
55 | String++;\r | |
56 | \r | |
57 | if (*String == 0) {\r | |
58 | //\r | |
59 | // If double NULL then we are done.\r | |
60 | // Return pointer to next structure in Smbios.\r | |
61 | // if you pass in a 0 you will always get here\r | |
62 | //\r | |
63 | Smbios->Raw = (UINT8 *)++String;\r | |
64 | return NULL;\r | |
65 | }\r | |
66 | }\r | |
67 | \r | |
68 | return NULL;\r | |
69 | }\r | |
70 | \r | |
71 | \r | |
72 | /**\r | |
f737cfb9 | 73 | This function gets system guid and serial number from the smbios table.\r |
dc361cc5 | 74 | \r |
f737cfb9 | 75 | @param SystemGuid The pointer of returned system guid.\r |
76 | @param SystemSerialNumber The pointer of returned system serial number.\r | |
dc361cc5 | 77 | \r |
78 | @retval EFI_SUCCESS Successfully get the system guid and system serial\r | |
f737cfb9 | 79 | number.\r |
80 | @retval EFI_NOT_FOUND Not find the SMBIOS table.\r | |
dc361cc5 | 81 | \r |
82 | **/\r | |
83 | EFI_STATUS\r | |
84 | GetSmbiosSystemGuidAndSerialNumber (\r | |
85 | IN EFI_GUID *SystemGuid,\r | |
86 | OUT CHAR8 **SystemSerialNumber\r | |
87 | )\r | |
88 | {\r | |
89 | EFI_STATUS Status;\r | |
90 | SMBIOS_TABLE_ENTRY_POINT *SmbiosTable;\r | |
91 | SMBIOS_STRUCTURE_POINTER Smbios;\r | |
92 | SMBIOS_STRUCTURE_POINTER SmbiosEnd;\r | |
93 | UINT16 Index;\r | |
94 | \r | |
95 | Status = EfiGetSystemConfigurationTable (&gEfiSmbiosTableGuid, (VOID **) &SmbiosTable);\r | |
96 | \r | |
97 | if (EFI_ERROR (Status)) {\r | |
98 | return EFI_NOT_FOUND;\r | |
99 | }\r | |
100 | \r | |
101 | Smbios.Hdr = (SMBIOS_STRUCTURE *) (UINTN) SmbiosTable->TableAddress;\r | |
102 | SmbiosEnd.Raw = (UINT8 *) (UINTN) (SmbiosTable->TableAddress + SmbiosTable->TableLength);\r | |
103 | \r | |
104 | for (Index = 0; Index < SmbiosTable->TableLength; Index++) {\r | |
105 | if (Smbios.Hdr->Type == 1) {\r | |
106 | if (Smbios.Hdr->Length < 0x19) {\r | |
107 | //\r | |
108 | // Older version did not support Guid and Serial number\r | |
109 | //\r | |
110 | continue;\r | |
111 | }\r | |
112 | //\r | |
113 | // SMBIOS tables are byte packed so we need to do a byte copy to\r | |
114 | // prevend alignment faults on Itanium-based platform.\r | |
115 | //\r | |
116 | CopyMem (SystemGuid, &Smbios.Type1->Uuid, sizeof (EFI_GUID));\r | |
117 | *SystemSerialNumber = GetSmbiosString (&Smbios, Smbios.Type1->SerialNumber);\r | |
118 | \r | |
119 | return EFI_SUCCESS;\r | |
120 | }\r | |
121 | //\r | |
122 | // Make Smbios point to the next record\r | |
123 | //\r | |
124 | GetSmbiosString (&Smbios, 0);\r | |
125 | \r | |
126 | if (Smbios.Raw >= SmbiosEnd.Raw) {\r | |
127 | //\r | |
128 | // SMBIOS 2.1 incorrectly stated the length of SmbiosTable as 0x1e.\r | |
129 | // given this we must double check against the length of the structure.\r | |
130 | //\r | |
131 | return EFI_SUCCESS;\r | |
132 | }\r | |
133 | }\r | |
134 | \r | |
135 | return EFI_SUCCESS;\r | |
136 | }\r | |
137 | \r | |
138 | \r | |
139 | /**\r | |
f737cfb9 | 140 | The common notify function associated with various PxeBc events. \r |
dc361cc5 | 141 | \r |
f737cfb9 | 142 | @param Event The event signaled.\r |
143 | @param Context The context.\r | |
dc361cc5 | 144 | \r |
dc361cc5 | 145 | **/\r |
146 | VOID\r | |
6d3ea23f | 147 | EFIAPI\r |
dc361cc5 | 148 | PxeBcCommonNotify (\r |
149 | IN EFI_EVENT Event,\r | |
150 | IN VOID *Context\r | |
151 | )\r | |
152 | {\r | |
153 | *((BOOLEAN *) Context) = TRUE;\r | |
154 | }\r | |
155 | \r | |
f737cfb9 | 156 | \r |
157 | /**\r | |
158 | This function initialize(or configure) the Udp4Write instance.\r | |
159 | \r | |
160 | @param Udp4 Pointer to the EFI_UDP4_PROTOCOL instance.\r | |
161 | @param StationIp Pointer to the station ip address.\r | |
162 | @param SubnetMask Pointer to the subnetmask of the station ip address.\r | |
163 | @param Gateway Pointer to the gateway ip address.\r | |
164 | @param SrcPort Pointer to the srouce port of the station.\r | |
165 | \r | |
166 | @retval EFI_SUCCESS The configuration settings were set, changed, or reset successfully.\r | |
167 | @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,\r | |
168 | RARP, etc.) is not finished yet.\r | |
169 | @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:\r | |
170 | @retval EFI_ALREADY_STARTED The EFI UDPv4 Protocol instance is already started/configured\r | |
171 | and must be stopped/reset before it can be reconfigured.\r | |
172 | @retval EFI_ACCESS_DENIED UdpConfigData. AllowDuplicatePort is FALSE\r | |
173 | and UdpConfigData.StationPort is already used by\r | |
174 | other instance.\r | |
175 | @retval EFI_OUT_OF_RESOURCES The EFI UDPv4 Protocol driver cannot allocate memory for this\r | |
176 | EFI UDPv4 Protocol instance.\r | |
177 | @retval EFI_DEVICE_ERROR An unexpected network or system error occurred and this instance\r | |
178 | was not opened.\r | |
179 | @retval Others Please examine the function Udp4->Routes(Udp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway) returns.\r | |
180 | \r | |
181 | **/\r | |
8792362f | 182 | EFI_STATUS\r |
183 | PxeBcConfigureUdpWriteInstance (\r | |
184 | IN EFI_UDP4_PROTOCOL *Udp4,\r | |
185 | IN EFI_IPv4_ADDRESS *StationIp,\r | |
186 | IN EFI_IPv4_ADDRESS *SubnetMask,\r | |
187 | IN EFI_IPv4_ADDRESS *Gateway,\r | |
188 | IN OUT UINT16 *SrcPort\r | |
189 | )\r | |
190 | {\r | |
191 | EFI_UDP4_CONFIG_DATA Udp4CfgData;\r | |
192 | EFI_STATUS Status;\r | |
193 | \r | |
194 | ZeroMem (&Udp4CfgData, sizeof (Udp4CfgData));\r | |
195 | \r | |
196 | Udp4CfgData.ReceiveTimeout = 1000;\r | |
197 | Udp4CfgData.TypeOfService = DEFAULT_ToS;\r | |
198 | Udp4CfgData.TimeToLive = DEFAULT_TTL;\r | |
319075ff | 199 | Udp4CfgData.AllowDuplicatePort = TRUE;\r |
8792362f | 200 | \r |
201 | CopyMem (&Udp4CfgData.StationAddress, StationIp, sizeof (*StationIp));\r | |
202 | CopyMem (&Udp4CfgData.SubnetMask, SubnetMask, sizeof (*SubnetMask));\r | |
203 | \r | |
204 | Udp4CfgData.StationPort = *SrcPort;\r | |
205 | \r | |
206 | //\r | |
207 | // Reset the instance.\r | |
208 | //\r | |
209 | Udp4->Configure (Udp4, NULL);\r | |
210 | \r | |
211 | Status = Udp4->Configure (Udp4, &Udp4CfgData);\r | |
212 | if (!EFI_ERROR (Status) && (Gateway->Addr[0] != 0)) {\r | |
213 | //\r | |
214 | // basic configuration OK, need to add the default route entry\r | |
215 | //\r | |
216 | Status = Udp4->Routes (Udp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway);\r | |
217 | if (EFI_ERROR (Status)) {\r | |
218 | //\r | |
219 | // roll back\r | |
220 | //\r | |
221 | Udp4->Configure (Udp4, NULL);\r | |
222 | }\r | |
223 | }\r | |
224 | \r | |
225 | if (!EFI_ERROR (Status) && (*SrcPort == 0)) {\r | |
226 | Udp4->GetModeData (Udp4, &Udp4CfgData, NULL, NULL, NULL);\r | |
227 | *SrcPort = Udp4CfgData.StationPort;\r | |
228 | }\r | |
229 | \r | |
230 | return Status;\r | |
231 | }\r | |
232 | \r | |
dc361cc5 | 233 | \r |
234 | /**\r | |
f737cfb9 | 235 | Convert number to ASCII value.\r |
dc361cc5 | 236 | \r |
237 | @param Number Numeric value to convert to decimal ASCII value.\r | |
f737cfb9 | 238 | @param Buffer Buffer to place ASCII version of the Number.\r |
dc361cc5 | 239 | @param Length Length of Buffer.\r |
240 | \r | |
dc361cc5 | 241 | **/\r |
242 | VOID\r | |
243 | CvtNum (\r | |
244 | IN UINTN Number,\r | |
245 | IN UINT8 *Buffer,\r | |
f737cfb9 | 246 | IN UINTN Length\r |
dc361cc5 | 247 | )\r |
248 | {\r | |
249 | UINTN Remainder;\r | |
250 | \r | |
894d038a | 251 | while (Length > 0) {\r |
dc361cc5 | 252 | Remainder = Number % 10;\r |
253 | Number /= 10;\r | |
894d038a | 254 | Length--;\r |
dc361cc5 | 255 | Buffer[Length] = (UINT8) ('0' + Remainder);\r |
256 | }\r | |
257 | }\r | |
258 | \r | |
259 | \r | |
260 | /**\r | |
f737cfb9 | 261 | Convert unsigned int number to decimal number.\r |
dc361cc5 | 262 | \r |
f737cfb9 | 263 | @param Number The unsigned int number will be converted.\r |
264 | @param Buffer Pointer to the buffer to store the decimal number after transform.\r | |
dc361cc5 | 265 | \r |
f737cfb9 | 266 | @return the length of the number after transform.\r |
dc361cc5 | 267 | \r |
268 | **/\r | |
269 | UINTN\r | |
270 | UtoA10 (\r | |
271 | IN UINTN Number,\r | |
272 | IN CHAR8 *Buffer\r | |
273 | )\r | |
274 | {\r | |
275 | UINTN Index;\r | |
276 | CHAR8 TempStr[64];\r | |
277 | \r | |
278 | Index = 63;\r | |
279 | TempStr[Index] = 0;\r | |
280 | \r | |
281 | do {\r | |
282 | Index--;\r | |
283 | TempStr[Index] = (CHAR8) ('0' + (Number % 10));\r | |
284 | Number = Number / 10;\r | |
285 | } while (Number != 0);\r | |
286 | \r | |
287 | AsciiStrCpy (Buffer, &TempStr[Index]);\r | |
288 | \r | |
289 | return AsciiStrLen (Buffer);\r | |
290 | }\r | |
291 | \r | |
292 | \r | |
293 | /**\r | |
f737cfb9 | 294 | Convert ASCII numeric string to a UINTN value.\r |
dc361cc5 | 295 | \r |
f737cfb9 | 296 | @param Buffer Pointer to the 8-byte unsigned int value.\r |
dc361cc5 | 297 | \r |
f737cfb9 | 298 | @return UINTN value of the ASCII string.\r |
dc361cc5 | 299 | \r |
300 | **/\r | |
301 | UINT64\r | |
302 | AtoU64 (\r | |
303 | IN UINT8 *Buffer\r | |
304 | )\r | |
305 | {\r | |
306 | UINT64 Value;\r | |
307 | UINT8 Character;\r | |
308 | \r | |
309 | Value = 0;\r | |
310 | while ((Character = *Buffer++) != '\0') {\r | |
311 | Value = MultU64x32 (Value, 10) + (Character - '0');\r | |
312 | }\r | |
313 | \r | |
314 | return Value;\r | |
315 | }\r | |
316 | \r |