2 Support routines for PxeBc.
4 Copyright (c) 2007 - 2011, 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.
46 @retval EFI_SUCCESS The configuration settings were set, changed, or reset successfully.
47 @retval EFI_NO_MAPPING When using a default address, configuration (DHCP, BOOTP,
48 RARP, etc.) is not finished yet.
49 @retval EFI_INVALID_PARAMETER One or more following conditions are TRUE:
50 @retval EFI_ALREADY_STARTED The EFI UDPv4 Protocol instance is already started/configured
51 and must be stopped/reset before it can be reconfigured.
52 @retval EFI_ACCESS_DENIED UdpConfigData. AllowDuplicatePort is FALSE
53 and UdpConfigData.StationPort is already used by
55 @retval EFI_OUT_OF_RESOURCES The EFI UDPv4 Protocol driver cannot allocate memory for this
56 EFI UDPv4 Protocol instance.
57 @retval EFI_DEVICE_ERROR An unexpected network or system error occurred and this instance
59 @retval Others Please examine the function Udp4->Routes(Udp4, FALSE, &mZeroIp4Addr, &mZeroIp4Addr, Gateway) returns.
63 PxeBcConfigureUdpWriteInstance (
64 IN EFI_UDP4_PROTOCOL
*Udp4
,
65 IN EFI_IPv4_ADDRESS
*StationIp
,
66 IN EFI_IPv4_ADDRESS
*SubnetMask
,
67 IN EFI_IPv4_ADDRESS
*Gateway
,
68 IN OUT UINT16
*SrcPort
71 EFI_UDP4_CONFIG_DATA Udp4CfgData
;
74 ZeroMem (&Udp4CfgData
, sizeof (Udp4CfgData
));
76 Udp4CfgData
.ReceiveTimeout
= PXEBC_DEFAULT_LIFETIME
;
77 Udp4CfgData
.TypeOfService
= DEFAULT_ToS
;
78 Udp4CfgData
.TimeToLive
= DEFAULT_TTL
;
79 Udp4CfgData
.AllowDuplicatePort
= TRUE
;
81 CopyMem (&Udp4CfgData
.StationAddress
, StationIp
, sizeof (*StationIp
));
82 CopyMem (&Udp4CfgData
.SubnetMask
, SubnetMask
, sizeof (*SubnetMask
));
84 Udp4CfgData
.StationPort
= *SrcPort
;
87 // Reset the instance.
89 Udp4
->Configure (Udp4
, NULL
);
91 Status
= Udp4
->Configure (Udp4
, &Udp4CfgData
);
92 if (!EFI_ERROR (Status
) && (Gateway
->Addr
[0] != 0)) {
94 // basic configuration OK, need to add the default route entry
96 Status
= Udp4
->Routes (Udp4
, FALSE
, &mZeroIp4Addr
, &mZeroIp4Addr
, Gateway
);
97 if (EFI_ERROR (Status
)) {
101 Udp4
->Configure (Udp4
, NULL
);
105 if (!EFI_ERROR (Status
) && (*SrcPort
== 0)) {
106 Udp4
->GetModeData (Udp4
, &Udp4CfgData
, NULL
, NULL
, NULL
);
107 *SrcPort
= Udp4CfgData
.StationPort
;
115 Convert number to ASCII value.
117 @param Number Numeric value to convert to decimal ASCII value.
118 @param Buffer Buffer to place ASCII version of the Number.
119 @param Length Length of Buffer.
132 Remainder
= Number
% 10;
135 Buffer
[Length
] = (UINT8
) ('0' + Remainder
);
141 Convert unsigned int number to decimal number.
143 @param Number The unsigned int number will be converted.
144 @param Buffer Pointer to the buffer to store the decimal number after transform.
146 @return the length of the number after transform.
163 TempStr
[Index
] = (CHAR8
) ('0' + (Number
% 10));
164 Number
= Number
/ 10;
165 } while (Number
!= 0);
167 AsciiStrCpy (Buffer
, &TempStr
[Index
]);
169 return AsciiStrLen (Buffer
);
174 Convert ASCII numeric string to a UINTN value.
176 @param Buffer Pointer to the 8-byte unsigned int value.
178 @return UINTN value of the ASCII string.
190 while ((Character
= *Buffer
++) != '\0') {
191 Value
= MultU64x32 (Value
, 10) + (Character
- '0');