From b20d4f7633b3085b8b3d3d6fb8e5b15ba4d5ab86 Mon Sep 17 00:00:00 2001 From: "ji, zhenlong z" Date: Fri, 12 Mar 2021 13:23:43 +0800 Subject: [PATCH] Show the host ip in fastboot This is a W/A, we currently use the asset field of smbios' type_chassis struct to pass the host ip to bootloader. Tracked-On: OAM-96182 Signed-off-by: ji, zhenlong z --- include/vars.h | 1 + libfastboot/fastboot_transport.c | 39 +++++++++++++++++++++++++++++++- libkernelflinger/vars.c | 15 ++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/include/vars.h b/include/vars.h index 0136fd4a..a651f393 100644 --- a/include/vars.h +++ b/include/vars.h @@ -144,6 +144,7 @@ char *get_property_name(void); char *get_property_model(void); #endif char *get_device_id(void); +char *get_host_ip(void); CHAR16 *boot_state_to_string(UINT8 boot_state); #ifndef USER EFI_STATUS reprovision_state_vars(VOID); diff --git a/libfastboot/fastboot_transport.c b/libfastboot/fastboot_transport.c index feb96458..482b9d03 100644 --- a/libfastboot/fastboot_transport.c +++ b/libfastboot/fastboot_transport.c @@ -35,6 +35,7 @@ #include #include #include +#include #include /* USB */ @@ -172,6 +173,36 @@ static void transport_tcp_tx_cb(void *buf, UINT32 size) tx_callback(buf, size); } +static EFI_STATUS fastboot_get_host_ip(EFI_IPv4_ADDRESS *address) +{ + char *ip_ptr = NULL; + unsigned long part = 0; + size_t i; + + if (NULL == address) + return EFI_INVALID_PARAMETER; + + ip_ptr = get_host_ip(); + + for (i = 0; i < 4; ++i) { + char* end; + part = strtoul(ip_ptr, &end, 0); + if (end == ip_ptr || (*end != '_' && *end != '\0') || part > 0xff) + return EFI_INVALID_PARAMETER; + + address->Addr[i] = part; + + if (*end == '\0') + break; + ip_ptr = end + 1; + } + + if (i != 3) + return EFI_INVALID_PARAMETER; + + return EFI_SUCCESS; +} + static void print_tcpip_information(EFI_IPv4_ADDRESS *address) { #define TCPIP_INFO_FMT L"Fastboot is listening on TCP %d.%d.%d.%d:%d" @@ -188,6 +219,7 @@ static EFI_STATUS fastboot_tcp_start(start_callback_t start_cb, { EFI_STATUS ret; EFI_IPv4_ADDRESS station_address; + EFI_IPv4_ADDRESS station_address2; start_callback = start_cb; rx_callback = rx_cb; @@ -199,8 +231,13 @@ static EFI_STATUS fastboot_tcp_start(start_callback_t start_cb, if (EFI_ERROR(ret)) return ret; - print_tcpip_information(&station_address); + if (is_running_on_kvm()) { + ret = fastboot_get_host_ip(&station_address2); + if (ret == EFI_SUCCESS) + station_address = station_address2; + } + print_tcpip_information(&station_address); return EFI_SUCCESS; } diff --git a/libkernelflinger/vars.c b/libkernelflinger/vars.c index a578a309..f2aceb86 100644 --- a/libkernelflinger/vars.c +++ b/libkernelflinger/vars.c @@ -791,6 +791,21 @@ char *get_device_id(void) } #endif +/* This is a WA, we use the asset field of type_chassis to transfer the + * host ip to bootloader.*/ +char *get_host_ip(void) +{ + static char host_ip[ANDROID_PROP_VALUE_MAX]; + + if (!host_ip[0]) { + SMBIOS_TO_BUFFER(host_ip, TYPE_CHASSIS, AssetTag); + CDD_clean_string(host_ip); + debug(L"Detected host ip '%a'", host_ip); + } + + return host_ip; +} + char *get_serialno_var() { CHAR8 *data;