2 Support routines for PxeBc.
4 Copyright (c) 2007 - 2009, Intel Corporation.<BR>
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
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.
16 #include "PxeBcImpl.h"
20 This function returns SMBIOS string given the string number.
22 @param Smbios Pointer to SMBIOS structure
23 @param StringNumber String number to return. 0 is used to skip all
24 strings and point to the next SMBIOS structure.
26 @return Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == 0
31 IN SMBIOS_STRUCTURE_POINTER
*Smbios
,
32 IN UINT16 StringNumber
39 // Skip over formatted section
41 String
= (CHAR8
*) (Smbios
->Raw
+ Smbios
->Hdr
->Length
);
44 // Look through unformated section
46 for (Index
= 1; Index
<= StringNumber
|| StringNumber
== 0; Index
++) {
47 if (StringNumber
== Index
) {
53 for (; *String
!= 0; String
++)
59 // If double NULL then we are done.
60 // Return pointer to next structure in Smbios.
61 // if you pass in a 0 you will always get here
63 Smbios
->Raw
= (UINT8
*)++String
;
73 This function gets system guid and serial number from the smbios table.
75 @param SystemGuid The pointer of returned system guid.
76 @param SystemSerialNumber The pointer of returned system serial number.
78 @retval EFI_SUCCESS Successfully get the system guid and system serial
80 @retval EFI_NOT_FOUND Not find the SMBIOS table.
84 GetSmbiosSystemGuidAndSerialNumber (
85 IN EFI_GUID
*SystemGuid
,
86 OUT CHAR8
**SystemSerialNumber
90 SMBIOS_TABLE_ENTRY_POINT
*SmbiosTable
;
91 SMBIOS_STRUCTURE_POINTER Smbios
;
92 SMBIOS_STRUCTURE_POINTER SmbiosEnd
;
95 Status
= EfiGetSystemConfigurationTable (&gEfiSmbiosTableGuid
, (VOID
**) &SmbiosTable
);
97 if (EFI_ERROR (Status
)) {
101 Smbios
.Hdr
= (SMBIOS_STRUCTURE
*) (UINTN
) SmbiosTable
->TableAddress
;
102 SmbiosEnd
.Raw
= (UINT8
*) (UINTN
) (SmbiosTable
->TableAddress
+ SmbiosTable
->TableLength
);
104 for (Index
= 0; Index
< SmbiosTable
->TableLength
; Index
++) {
105 if (Smbios
.Hdr
->Type
== 1) {
106 if (Smbios
.Hdr
->Length
< 0x19) {
108 // Older version did not support Guid and Serial number
113 // SMBIOS tables are byte packed so we need to do a byte copy to
114 // prevend alignment faults on Itanium-based platform.
116 CopyMem (SystemGuid
, &Smbios
.Type1
->Uuid
, sizeof (EFI_GUID
));
117 *SystemSerialNumber
= GetSmbiosString (&Smbios
, Smbios
.Type1
->SerialNumber
);
122 // Make Smbios point to the next record
124 GetSmbiosString (&Smbios
, 0);
126 if (Smbios
.Raw
>= SmbiosEnd
.Raw
) {
128 // SMBIOS 2.1 incorrectly stated the length of SmbiosTable as 0x1e.
129 // given this we must double check against the length of the structure.
140 The common notify function associated with various PxeBc events.
142 @param Event The event signaled.
143 @param Context The context.
153 *((BOOLEAN
*) Context
) = TRUE
;
158 This function initialize(or configure) the Udp4Write instance.
160 @param Udp4 Pointer to the EFI_UDP4_PROTOCOL instance.
161 @param StationIp Pointer to the station ip address.
162 @param SubnetMask Pointer to the subnetmask of the station ip address.
163 @param Gateway Pointer to the gateway ip address.
164 @param SrcPort Pointer to the srouce port of the station.
166 @retval EFI_SUCCESS The configuration settings were set, changed, or reset successfully.
167 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
168 RARP, etc.) is not finished yet.
169 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:
170 @retval EFI_ALREADY_STARTED The EFI UDPv4 Protocol instance is already started/configured
171 and must be stopped/reset before it can be reconfigured.
172 @retval EFI_ACCESS_DENIED UdpConfigData. AllowDuplicatePort is FALSE
173 and UdpConfigData.StationPort is already used by
175 @retval EFI_OUT_OF_RESOURCES The EFI UDPv4 Protocol driver cannot allocate memory for this
176 EFI UDPv4 Protocol instance.
177 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred and this instance
179 @retval Others Please examine the function Udp4->Routes(Udp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway) returns.
183 PxeBcConfigureUdpWriteInstance (
184 IN EFI_UDP4_PROTOCOL
*Udp4
,
185 IN EFI_IPv4_ADDRESS
*StationIp
,
186 IN EFI_IPv4_ADDRESS
*SubnetMask
,
187 IN EFI_IPv4_ADDRESS
*Gateway
,
188 IN OUT UINT16
*SrcPort
191 EFI_UDP4_CONFIG_DATA Udp4CfgData
;
194 ZeroMem (&Udp4CfgData
, sizeof (Udp4CfgData
));
196 Udp4CfgData
.ReceiveTimeout
= 1000;
197 Udp4CfgData
.TypeOfService
= DEFAULT_ToS
;
198 Udp4CfgData
.TimeToLive
= DEFAULT_TTL
;
199 Udp4CfgData
.AllowDuplicatePort
= TRUE
;
201 CopyMem (&Udp4CfgData
.StationAddress
, StationIp
, sizeof (*StationIp
));
202 CopyMem (&Udp4CfgData
.SubnetMask
, SubnetMask
, sizeof (*SubnetMask
));
204 Udp4CfgData
.StationPort
= *SrcPort
;
207 // Reset the instance.
209 Udp4
->Configure (Udp4
, NULL
);
211 Status
= Udp4
->Configure (Udp4
, &Udp4CfgData
);
212 if (!EFI_ERROR (Status
) && (Gateway
->Addr
[0] != 0)) {
214 // basic configuration OK, need to add the default route entry
216 Status
= Udp4
->Routes (Udp4
, FALSE
, &mZeroIp4Addr
, &mZeroIp4Addr
, Gateway
);
217 if (EFI_ERROR (Status
)) {
221 Udp4
->Configure (Udp4
, NULL
);
225 if (!EFI_ERROR (Status
) && (*SrcPort
== 0)) {
226 Udp4
->GetModeData (Udp4
, &Udp4CfgData
, NULL
, NULL
, NULL
);
227 *SrcPort
= Udp4CfgData
.StationPort
;
235 Convert number to ASCII value.
237 @param Number Numeric value to convert to decimal ASCII value.
238 @param Buffer Buffer to place ASCII version of the Number.
239 @param Length Length of Buffer.
252 Remainder
= Number
% 10;
255 Buffer
[Length
] = (UINT8
) ('0' + Remainder
);
261 Convert unsigned int number to decimal number.
263 @param Number The unsigned int number will be converted.
264 @param Buffer Pointer to the buffer to store the decimal number after transform.
266 @return the length of the number after transform.
283 TempStr
[Index
] = (CHAR8
) ('0' + (Number
% 10));
284 Number
= Number
/ 10;
285 } while (Number
!= 0);
287 AsciiStrCpy (Buffer
, &TempStr
[Index
]);
289 return AsciiStrLen (Buffer
);
294 Convert ASCII numeric string to a UINTN value.
296 @param Buffer Pointer to the 8-byte unsigned int value.
298 @return UINTN value of the ASCII string.
310 while ((Character
= *Buffer
++) != '\0') {
311 Value
= MultU64x32 (Value
, 10) + (Character
- '0');