Skip to contentSkip to conversation

efi_loader: net: add support to send http requests and parse http headers

PATCH Superseded Adriano Cordova 1 participant 1 message Nov 8, 2024

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH 10/15 efi_loader: net: add support to send http requests and parse http headers

Add network-stack agnostic way to send an http request and parse http headers from efi drivers. This uses wget as a backend and communicates with it via the struct wget_http_info 'wget_info'.

The function efi_net_do_request allocates a buffer on behalf of an efi application using efi_alloc and passes it to wget to receive the data. If the method is GET and the buffer is too small, it re-allocates the buffer based on the last received Content-Length header and tries again. If the method is HEAD it just issues one request. So issuing a HEAD request (to update Content-Length) and then a GET request is preferred but not required.

The function efi_net_parse_headers parses a raw buffer containing an http header into an array of EFI specific 'http_header' structs.

---
 include/efi_loader.h     |  13 ++++
 lib/efi_loader/efi_net.c | 128 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 141 insertions(+)
include/efi_loader.h +13 -0
index c37c1a4660..a19505d4cc 100644
@@ -16,6 +16,7 @@
 #include <image.h>
 #include <pe.h>
 #include <linux/list.h>
+#include <linux/sizes.h>
 #include <linux/oid_registry.h>
 
 struct blk_desc;
@@ -136,6 +137,18 @@ void efi_net_get_addr(struct efi_ipv4_address *ip,
 void efi_net_set_addr(struct efi_ipv4_address *ip,
 		      struct efi_ipv4_address *mask,
 		      struct efi_ipv4_address *gw);
+efi_status_t efi_net_do_request(u8 *url, enum efi_http_method method,
+				ulong *buffer, ulong *file_size, char *headers_buffer);
+#define MAX_HTTP_HEADERS_SIZE SZ_64K
+#define MAX_HTTP_HEADERS 100
+#define MAX_HTTP_HEADER_NAME 128
+#define MAX_HTTP_HEADER_VALUE 512
+struct http_header {
+	uchar name[MAX_HTTP_HEADER_NAME];
+	uchar value[MAX_HTTP_HEADER_VALUE];
+};
+
+void efi_net_parse_headers(ulong *num_headers, struct http_header *headers);
 #else
 static inline void efi_net_set_dp(const char *dev, const char *server) { }
 static inline void efi_net_get_dp(void **dp) { }
lib/efi_loader/efi_net.c +128 -0

137 lines not on this page · raw message

Signature · 1 line
2.43.0