2 Support routines for PxeBc.
4 Copyright (c) 2007 - 2017, 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
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 The common notify function associated with various PxeBc events.
22 @param Event The event signaled.
23 @param Context The context.
33 *((BOOLEAN
*) Context
) = TRUE
;
38 This function initialize(or configure) the Udp4Write instance.
40 @param Udp4 Pointer to the EFI_UDP4_PROTOCOL instance.
41 @param StationIp Pointer to the station ip address.
42 @param SubnetMask Pointer to the subnetmask of the station ip address.
43 @param Gateway Pointer to the gateway ip address.
44 @param SrcPort Pointer to the srouce port of the station.
45 @param Ttl The time to live field of the IP header.
46 @param ToS The type of service field of the IP header.
48 @retval EFI_SUCCESS The configuration settings were set, changed, or reset successfully.
49 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
50 RARP, etc.) is not finished yet.
51 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:
52 @retval EFI_ALREADY_STARTED The EFI UDPv4 Protocol instance is already started/configured
53 and must be stopped/reset before it can be reconfigured.
54 @retval EFI_ACCESS_DENIED UdpConfigData. AllowDuplicatePort is FALSE
55 and UdpConfigData.StationPort is already used by
57 @retval EFI_OUT_OF_RESOURCES The EFI UDPv4 Protocol driver cannot allocate memory for this
58 EFI UDPv4 Protocol instance.
59 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred and this instance
61 @retval Others Please examine the function Udp4->Routes(Udp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway) returns.
65 PxeBcConfigureUdpWriteInstance (
66 IN EFI_UDP4_PROTOCOL
*Udp4
,
67 IN EFI_IPv4_ADDRESS
*StationIp
,
68 IN EFI_IPv4_ADDRESS
*SubnetMask
,
69 IN EFI_IPv4_ADDRESS
*Gateway
,
70 IN OUT UINT16
*SrcPort
,
75 EFI_UDP4_CONFIG_DATA Udp4CfgData
;
78 ZeroMem (&Udp4CfgData
, sizeof (Udp4CfgData
));
80 Udp4CfgData
.ReceiveTimeout
= PXEBC_DEFAULT_LIFETIME
;
81 Udp4CfgData
.TypeOfService
= ToS
;
82 Udp4CfgData
.TimeToLive
= Ttl
;
83 Udp4CfgData
.AllowDuplicatePort
= TRUE
;
85 CopyMem (&Udp4CfgData
.StationAddress
, StationIp
, sizeof (*StationIp
));
86 CopyMem (&Udp4CfgData
.SubnetMask
, SubnetMask
, sizeof (*SubnetMask
));
88 Udp4CfgData
.StationPort
= *SrcPort
;
91 // Reset the instance.
93 Udp4
->Configure (Udp4
, NULL
);
95 Status
= Udp4
->Configure (Udp4
, &Udp4CfgData
);
96 if (!EFI_ERROR (Status
) && (Gateway
->Addr
[0] != 0)) {
98 // basic configuration OK, need to add the default route entry
100 Status
= Udp4
->Routes (Udp4
, FALSE
, &mZeroIp4Addr
, &mZeroIp4Addr
, Gateway
);
101 if (EFI_ERROR (Status
)) {
105 Udp4
->Configure (Udp4
, NULL
);
109 if (!EFI_ERROR (Status
) && (*SrcPort
== 0)) {
110 Udp4
->GetModeData (Udp4
, &Udp4CfgData
, NULL
, NULL
, NULL
);
111 *SrcPort
= Udp4CfgData
.StationPort
;
118 This function is to display the IPv4 address.
120 @param[in] Ip The pointer to the IPv4 address.
125 IN EFI_IPv4_ADDRESS
*Ip
130 for (Index
= 0; Index
< 4; Index
++) {
131 AsciiPrint ("%d", Ip
->Addr
[Index
]);
139 Convert number to ASCII value.
141 @param Number Numeric value to convert to decimal ASCII value.
142 @param Buffer Buffer to place ASCII version of the Number.
143 @param Length Length of Buffer.
155 for (; Length
> 0; Length
--) {
156 Remainder
= Number
% 10;
158 Buffer
[Length
- 1] = (UINT8
) ('0' + Remainder
);
164 Convert unsigned int number to decimal number.
166 @param Number The unsigned int number will be converted.
167 @param Buffer Pointer to the buffer to store the decimal number after transform.
168 @param[in] BufferSize The maxsize of the buffer.
170 @return the length of the number after transform.
188 TempStr
[Index
] = (CHAR8
) ('0' + (Number
% 10));
189 Number
= Number
/ 10;
190 } while (Number
!= 0);
192 AsciiStrCpyS (Buffer
, BufferSize
, &TempStr
[Index
]);
194 return AsciiStrLen (Buffer
);
199 Convert ASCII numeric string to a UINTN value.
201 @param Buffer Pointer to the 8-byte unsigned int value.
203 @return UINTN value of the ASCII string.
215 while ((Character
= *Buffer
++) != '\0') {
216 Value
= MultU64x32 (Value
, 10) + (Character
- '0');