3 Copyright (c) 2007 - 2008, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 Support routines for PxeBc
24 #include "PxeBcImpl.h"
29 @param Smbios Pointer to SMBIOS structure
30 @param StringNumber String number to return. 0 is used to skip all
31 strings and point to the next SMBIOS structure.
33 @return Pointer to string, or pointer to next SMBIOS strcuture if StringNumber == 0
36 // GC_NOTO: function comment is missing 'Routine Description:'
39 IN SMBIOS_STRUCTURE_POINTER
*Smbios
,
40 IN UINT16 StringNumber
47 // Skip over formatted section
49 String
= (CHAR8
*) (Smbios
->Raw
+ Smbios
->Hdr
->Length
);
52 // Look through unformated section
54 for (Index
= 1; Index
<= StringNumber
|| StringNumber
== 0; Index
++) {
55 if (StringNumber
== Index
) {
61 for (; *String
!= 0; String
++)
67 // If double NULL then we are done.
68 // Return pointer to next structure in Smbios.
69 // if you pass in a 0 you will always get here
71 Smbios
->Raw
= (UINT8
*)++String
;
81 This function gets system guid and serial number from the smbios table
83 @param SystemGuid The pointer of returned system guid
84 @param SystemSerialNumber The pointer of returned system serial number
86 @retval EFI_SUCCESS Successfully get the system guid and system serial
88 @retval EFI_NOT_FOUND Not find the SMBIOS table
92 GetSmbiosSystemGuidAndSerialNumber (
93 IN EFI_GUID
*SystemGuid
,
94 OUT CHAR8
**SystemSerialNumber
98 SMBIOS_TABLE_ENTRY_POINT
*SmbiosTable
;
99 SMBIOS_STRUCTURE_POINTER Smbios
;
100 SMBIOS_STRUCTURE_POINTER SmbiosEnd
;
103 Status
= EfiGetSystemConfigurationTable (&gEfiSmbiosTableGuid
, (VOID
**) &SmbiosTable
);
105 if (EFI_ERROR (Status
)) {
106 return EFI_NOT_FOUND
;
109 Smbios
.Hdr
= (SMBIOS_STRUCTURE
*) (UINTN
) SmbiosTable
->TableAddress
;
110 SmbiosEnd
.Raw
= (UINT8
*) (UINTN
) (SmbiosTable
->TableAddress
+ SmbiosTable
->TableLength
);
112 for (Index
= 0; Index
< SmbiosTable
->TableLength
; Index
++) {
113 if (Smbios
.Hdr
->Type
== 1) {
114 if (Smbios
.Hdr
->Length
< 0x19) {
116 // Older version did not support Guid and Serial number
121 // SMBIOS tables are byte packed so we need to do a byte copy to
122 // prevend alignment faults on Itanium-based platform.
124 CopyMem (SystemGuid
, &Smbios
.Type1
->Uuid
, sizeof (EFI_GUID
));
125 *SystemSerialNumber
= GetSmbiosString (&Smbios
, Smbios
.Type1
->SerialNumber
);
130 // Make Smbios point to the next record
132 GetSmbiosString (&Smbios
, 0);
134 if (Smbios
.Raw
>= SmbiosEnd
.Raw
) {
136 // SMBIOS 2.1 incorrectly stated the length of SmbiosTable as 0x1e.
137 // given this we must double check against the length of the structure.
148 GC_NOTO: Add function description
150 @param Event GC_NOTO: add argument description
151 @param Context GC_NOTO: add argument description
153 @return GC_NOTO: add return values
162 *((BOOLEAN
*) Context
) = TRUE
;
166 PxeBcConfigureUdpWriteInstance (
167 IN EFI_UDP4_PROTOCOL
*Udp4
,
168 IN EFI_IPv4_ADDRESS
*StationIp
,
169 IN EFI_IPv4_ADDRESS
*SubnetMask
,
170 IN EFI_IPv4_ADDRESS
*Gateway
,
171 IN OUT UINT16
*SrcPort
174 EFI_UDP4_CONFIG_DATA Udp4CfgData
;
177 ZeroMem (&Udp4CfgData
, sizeof (Udp4CfgData
));
179 Udp4CfgData
.ReceiveTimeout
= 1000;
180 Udp4CfgData
.TypeOfService
= DEFAULT_ToS
;
181 Udp4CfgData
.TimeToLive
= DEFAULT_TTL
;
183 CopyMem (&Udp4CfgData
.StationAddress
, StationIp
, sizeof (*StationIp
));
184 CopyMem (&Udp4CfgData
.SubnetMask
, SubnetMask
, sizeof (*SubnetMask
));
186 Udp4CfgData
.StationPort
= *SrcPort
;
189 // Reset the instance.
191 Udp4
->Configure (Udp4
, NULL
);
193 Status
= Udp4
->Configure (Udp4
, &Udp4CfgData
);
194 if (!EFI_ERROR (Status
) && (Gateway
->Addr
[0] != 0)) {
196 // basic configuration OK, need to add the default route entry
198 Status
= Udp4
->Routes (Udp4
, FALSE
, &mZeroIp4Addr
, &mZeroIp4Addr
, Gateway
);
199 if (EFI_ERROR (Status
)) {
203 Udp4
->Configure (Udp4
, NULL
);
207 if (!EFI_ERROR (Status
) && (*SrcPort
== 0)) {
208 Udp4
->GetModeData (Udp4
, &Udp4CfgData
, NULL
, NULL
, NULL
);
209 *SrcPort
= Udp4CfgData
.StationPort
;
217 Convert number to ASCII value
219 @param Number Numeric value to convert to decimal ASCII value.
220 @param Buffer Buffer to place ASCII version of the Number
221 @param Length Length of Buffer.
236 Remainder
= Number
% 10;
238 Buffer
[Length
] = (UINT8
) ('0' + Remainder
);
244 GC_NOTO: Add function description
246 @param Number GC_NOTO: add argument description
247 @param Buffer GC_NOTO: add argument description
249 @return GC_NOTO: add return values
266 TempStr
[Index
] = (CHAR8
) ('0' + (Number
% 10));
267 Number
= Number
/ 10;
268 } while (Number
!= 0);
270 AsciiStrCpy (Buffer
, &TempStr
[Index
]);
272 return AsciiStrLen (Buffer
);
277 Convert ASCII numeric string to a UINTN value
279 @param Number Numeric value to convert to decimal ASCII value.
280 @param Buffer Buffer to place ASCII version of the Number
282 @retval Value UINTN value of the ASCII string.
294 while ((Character
= *Buffer
++) != '\0') {
295 Value
= MultU64x32 (Value
, 10) + (Character
- '0');