From 408af976742e6ffedf48fa42792955a633e357ed Mon Sep 17 00:00:00 2001 From: Adriano Cordova Date: Mon, 11 Nov 2024 18:08:56 -0300 Subject: net: wget: add definition of struct wget_http_info The struct wget_http_info exposes the HTTP information of the last HTTP request issued by wget, and it controls whether the efi bootdevice is set, and whether the buffer size needs to be checked (lwip stack only). This information is otherwise discarded. The wget_http_info struct can be used by HTTP drivers to have more control over HTTP requests. Signed-off-by: Adriano Cordova Reviewed-by: Heinrich Schuchardt --- include/net-common.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'include') diff --git a/include/net-common.h b/include/net-common.h index fd7c5e7b488..8985b81c2d2 100644 --- a/include/net-common.h +++ b/include/net-common.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -506,4 +507,51 @@ int wget_with_dns(ulong dst_addr, char *uri); bool wget_validate_uri(char *uri); //int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]); +/** + * enum wget_http_method - http method + */ +enum wget_http_method { + WGET_HTTP_METHOD_GET, + WGET_HTTP_METHOD_POST, + WGET_HTTP_METHOD_PATCH, + WGET_HTTP_METHOD_OPTIONS, + WGET_HTTP_METHOD_CONNECT, + WGET_HTTP_METHOD_HEAD, + WGET_HTTP_METHOD_PUT, + WGET_HTTP_METHOD_DELETE, + WGET_HTTP_METHOD_TRACE, + WGET_HTTP_METHOD_MAX +}; + +/** + * define MAX_HTTP_HEADERS_SIZE - maximum headers buffer size + * + * When receiving http headers, wget fills a buffer with up + * to MAX_HTTP_HEADERS_SIZE bytes of header information. + */ +#define MAX_HTTP_HEADERS_SIZE SZ_64K + +/** + * struct wget_http_info - wget parameters + * @method: HTTP Method. Filled by client. + * @status_code: HTTP status code. Filled by wget. + * @file_size: download size. Filled by wget. + * @buffer_size: size of client-provided buffer. Filled by client. + * @set_bootdev: set boot device with download. Filled by client. + * @check_buffer_size: check download does not exceed buffer size. + * Filled by client. + * @hdr_cont_len: content length according to headers. Filled by wget + * @headers: buffer for headers. Filled by wget. + */ +struct wget_http_info { + enum wget_http_method method; + u32 status_code; + ulong file_size; + ulong buffer_size; + bool set_bootdev; + bool check_buffer_size; + u32 hdr_cont_len; + char *headers; +}; + #endif /* __NET_COMMON_H__ */ -- cgit v1.2.3 From 1de93fda99f800aa1919268035fa2dd0e5109610 Mon Sep 17 00:00:00 2001 From: Adriano Cordova Date: Mon, 11 Nov 2024 18:08:57 -0300 Subject: net: wget: Add interface to issue wget_requests using wget_http_info Declare and define a global default struct wget_http_info and an interface to issue wget requests providing a custom struct wget_http_info. This code is common to legacy wget and lwip wget. The idea is that the command wget should use the default wget_http_info and other internal u-boot code can call wget_request with their own wget_http_info struct. Signed-off-by: Adriano Cordova --- include/net-common.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/net-common.h b/include/net-common.h index 8985b81c2d2..1efb0db9ff5 100644 --- a/include/net-common.h +++ b/include/net-common.h @@ -554,4 +554,8 @@ struct wget_http_info { char *headers; }; +extern struct wget_http_info default_wget_info; +extern struct wget_http_info *wget_info; +int wget_request(ulong dst_addr, char *uri, struct wget_http_info *info); + #endif /* __NET_COMMON_H__ */ -- cgit v1.2.3 From de28a2a5f2ad93b156b39c2aee24cb5d01c7e619 Mon Sep 17 00:00:00 2001 From: Adriano Cordova Date: Mon, 11 Nov 2024 18:08:59 -0300 Subject: net: wget: make wget_with_dns return value compatible with its lwip version There are two wget_with_dns functions, one in the legacy network stack and one in lwip, but the return values are not compatible. This commit modifies the legacy version of wget_with_dns so that the return values are compatible: 0 on success, otherwise a negative error. This way wget_with_dns can be called in a network stack agnostic way. Signed-off-by: Adriano Cordova --- include/net-common.h | 2 +- include/net-lwip.h | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) (limited to 'include') diff --git a/include/net-common.h b/include/net-common.h index 1efb0db9ff5..3cd0f343744 100644 --- a/include/net-common.h +++ b/include/net-common.h @@ -495,7 +495,7 @@ int do_tftpb(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]); * * @dst_addr: destination address to download the file * @uri: uri string of target file of wget - * Return: downloaded file size, negative if failed + * Return: zero on success, negative if failed */ int wget_with_dns(ulong dst_addr, char *uri); /** diff --git a/include/net-lwip.h b/include/net-lwip.h index 1c3583f82a1..4d7f9387d1d 100644 --- a/include/net-lwip.h +++ b/include/net-lwip.h @@ -16,15 +16,6 @@ void net_lwip_remove_netif(struct netif *netif); struct netif *net_lwip_get_netif(void); int net_lwip_rx(struct udevice *udev, struct netif *netif); -/** - * wget_with_dns() - runs dns host IP address resulution before wget - * - * @dst_addr: destination address to download the file - * @uri: uri string of target file of wget - * Return: downloaded file size, negative if failed - */ - -int wget_with_dns(ulong dst_addr, char *uri); /** * wget_validate_uri() - varidate the uri * -- cgit v1.2.3 From 9063dba2d326e07682338cdb636787e99f1bf3f5 Mon Sep 17 00:00:00 2001 From: Adriano Cordova Date: Mon, 11 Nov 2024 18:09:45 -0300 Subject: net: net_utils: Move ip_to_string to lib/net_utils.c The function string_to_ip is already in net_utils, which is compiled unconditionally, but ip_to_string is currently only accessible if the legacy network stack is selected. This commit puts ip_to_string in net_utils.c and removes it from the legacy network code. Signed-off-by: Adriano Cordova Reviewed-by: Heinrich Schuchardt --- include/net-common.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include') diff --git a/include/net-common.h b/include/net-common.h index 3cd0f343744..b7a519e36db 100644 --- a/include/net-common.h +++ b/include/net-common.h @@ -426,6 +426,16 @@ void string_to_enetaddr(const char *addr, uint8_t *enetaddr); */ struct in_addr string_to_ip(const char *s); +/** + * ip_to_string() - Convert a string to ip address + * + * Implemented in lib/net_utils.c (built unconditionally) + * + * @x: Input ip to parse + * @s: string containing the parsed ip address + */ +void ip_to_string(struct in_addr x, char *s); + /* copy a filename (allow for "..." notation, limit length) */ void copy_filename(char *dst, const char *src, int size); -- cgit v1.2.3