]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Provide efi_uri_path() to construct a URI device path
authorMichael Brown <mcb30@ipxe.org>
Fri, 16 Oct 2020 14:09:15 +0000 (15:09 +0100)
committerMichael Brown <mcb30@ipxe.org>
Mon, 19 Oct 2020 12:07:40 +0000 (13:07 +0100)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/ipxe/efi/efi_path.h
src/interface/efi/efi_path.c

index c1d53e7645abc77dbaaed664b6f99ce65aaf2862..f52410e364a7fd9c8e24f6f95fe670d87a48acf7 100644 (file)
@@ -13,11 +13,13 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <ipxe/efi/efi.h>
 #include <ipxe/efi/Protocol/DevicePath.h>
 
+struct uri;
 struct usb_function;
 
 extern EFI_DEVICE_PATH_PROTOCOL *
 efi_path_end ( EFI_DEVICE_PATH_PROTOCOL *path );
 extern size_t efi_path_len ( EFI_DEVICE_PATH_PROTOCOL *path );
+extern EFI_DEVICE_PATH_PROTOCOL * efi_uri_path ( struct uri *uri );
 extern EFI_DEVICE_PATH_PROTOCOL * efi_usb_path ( struct usb_function *func );
 
 extern EFI_DEVICE_PATH_PROTOCOL * efi_describe ( struct interface *interface );
index 162400a0f4faab73fb405173aa1410bcde4c8b92..6201c023ea6cb75033c0d9a4271325d56fb28266 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <stdlib.h>
 #include <string.h>
+#include <ipxe/uri.h>
 #include <ipxe/usb.h>
 #include <ipxe/efi/efi.h>
 #include <ipxe/efi/efi_driver.h>
@@ -60,6 +61,48 @@ size_t efi_path_len ( EFI_DEVICE_PATH_PROTOCOL *path ) {
        return ( ( ( void * ) end ) - ( ( void * ) path ) );
 }
 
+/**
+ * Construct EFI device path for URI
+ *
+ * @v uri              URI
+ * @ret path           EFI device path, or NULL on error
+ *
+ * The caller is responsible for eventually calling free() on the
+ * allocated device path.
+ */
+EFI_DEVICE_PATH_PROTOCOL * efi_uri_path ( struct uri *uri ) {
+       EFI_DEVICE_PATH_PROTOCOL *path;
+       EFI_DEVICE_PATH_PROTOCOL *end;
+       URI_DEVICE_PATH *uripath;
+       size_t uri_len;
+       size_t uripath_len;
+       size_t len;
+
+       /* Calculate device path length */
+       uri_len = ( format_uri ( uri, NULL, 0 ) + 1 /* NUL */ );
+       uripath_len = ( sizeof ( *uripath ) + uri_len );
+       len = ( uripath_len + sizeof ( *end ) );
+
+       /* Allocate device path */
+       path = zalloc ( len );
+       if ( ! path )
+               return NULL;
+
+       /* Construct device path */
+       uripath = ( ( void * ) path );
+       uripath->Header.Type = MESSAGING_DEVICE_PATH;
+       uripath->Header.SubType = MSG_URI_DP;
+       uripath->Header.Length[0] = ( uripath_len & 0xff );
+       uripath->Header.Length[1] = ( uripath_len >> 8 );
+       format_uri ( uri, uripath->Uri, uri_len );
+       end = ( ( ( void * ) path ) + uripath_len );
+       end->Type = END_DEVICE_PATH_TYPE;
+       end->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE;
+       end->Length[0] = sizeof ( *end );
+
+       return path;
+}
+
 /**
  * Construct EFI device path for USB function
  *