@@ -9,11 +9,10 @@ use alloc::vec::Vec;
99use core:: ffi:: c_void;
1010use core:: net:: Ipv4Addr ;
1111use core:: time:: Duration ;
12-
12+ use log :: { debug , trace } ;
1313use uefi:: boot:: ScopedProtocol ;
1414use uefi:: prelude:: * ;
1515use uefi:: proto:: unsafe_protocol;
16- use uefi:: { print, println} ;
1716use uefi_raw:: protocol:: network:: ip4_config2:: {
1817 Ip4Config2DataType , Ip4Config2InterfaceInfo , Ip4Config2Policy , Ip4Config2Protocol ,
1918} ;
@@ -102,39 +101,33 @@ impl Ip4Config2 {
102101 } )
103102 }
104103
105- /// Bring up network interface. Does nothing in case the network
106- /// is already set up. Otherwise turns on DHCP and waits until an
107- /// IPv4 address has been assigned. Reports progress on the
108- /// console if verbose is set to true. Returns TIMEOUT error in
109- /// case DHCP configuration does not finish within 30 seconds.
110- pub fn ifup ( & mut self , verbose : bool ) -> uefi:: Result < ( ) > {
104+ /// Bring up network interface.
105+ ///
106+ /// Does nothing in case the network is already set up. Otherwise turns on
107+ /// DHCP and waits until an IPv4 address has been assigned.
108+ ///
109+ /// Returns TIMEOUT error in case DHCP configuration does not finish within
110+ /// 30 seconds.
111+ pub fn ifup ( & mut self ) -> uefi:: Result < ( ) > {
112+ const TIMEOUT_SECS : u64 = 30 ;
113+
111114 let no_address = Ipv4Addr :: from_bits ( 0 ) ;
112115
113116 let info = self . get_interface_info ( ) ?;
114117 if info. station_addr != no_address. into ( ) {
115- if verbose {
116- print ! ( "Network is already up: " ) ;
117- println ! ( "addr v4: {}" , info. station_addr) ;
118- }
118+ debug ! ( "Network is already up: addr v4: {}" , info. station_addr) ;
119119 return Ok ( ( ) ) ;
120120 }
121121
122- if verbose {
123- print ! ( "DHCP " ) ;
124- }
122+ debug ! ( "DHCP " ) ;
125123 self . set_policy ( Ip4Config2Policy :: DHCP ) ?;
126124
127- for _ in 0 ..30 {
128- if verbose {
129- print ! ( "." ) ;
130- }
125+ for _ in 0 ..TIMEOUT_SECS {
131126 boot:: stall ( Duration :: from_secs ( 1 ) ) ;
127+ trace ! ( ".\r " ) ;
132128 let info = self . get_interface_info ( ) ?;
133129 if info. station_addr != no_address. into ( ) {
134- if verbose {
135- print ! ( " OK: " ) ;
136- println ! ( "addr v4: {}" , info. station_addr) ;
137- }
130+ debug ! ( "OK: addr v4: {}" , info. station_addr) ;
138131 return Ok ( ( ) ) ;
139132 }
140133 }
0 commit comments