Skip to content
This repository was archived by the owner on Aug 24, 2022. It is now read-only.

Show the host ip in fastboot #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/vars.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
39 changes: 38 additions & 1 deletion libfastboot/fastboot_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <fastboot.h>
#include <usb.h>
#include <tcp.h>
#include <vars.h>
#include <transport.h>

/* USB */
Expand Down Expand Up @@ -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"
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
15 changes: 15 additions & 0 deletions libkernelflinger/vars.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why use static? what about define local variable char host_ip[ANDROID_PROP_VALUE_MAX] in fastboot_get_host_ip(), then call get_host_ip(char *host_ip) to get host ip.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be consistent with other functions implemented in vars.c, such as get_device_id, get_property_bootloader etc.


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;
Expand Down