]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[efi] Add efi_path_uri() to parse a URI from an EFI device path
authorMichael Brown <mcb30@ipxe.org>
Tue, 19 Mar 2024 15:01:25 +0000 (15:01 +0000)
committerMichael Brown <mcb30@ipxe.org>
Tue, 19 Mar 2024 15:01:25 +0000 (15:01 +0000)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/include/ipxe/efi/efi_path.h
src/interface/efi/efi_path.c

index 20ff43f645b65ff450c311e69c4ecbf32e57191f..503bd4347326f1afd2e86ab5362a37e3a6c8efc9 100644 (file)
@@ -45,6 +45,7 @@ efi_path_end ( EFI_DEVICE_PATH_PROTOCOL *path );
 extern size_t efi_path_len ( EFI_DEVICE_PATH_PROTOCOL *path );
 extern unsigned int efi_path_vlan ( EFI_DEVICE_PATH_PROTOCOL *path );
 extern int efi_path_guid ( EFI_DEVICE_PATH_PROTOCOL *path, union uuid *uuid );
+extern struct uri * efi_path_uri ( EFI_DEVICE_PATH_PROTOCOL *path );
 extern EFI_DEVICE_PATH_PROTOCOL * efi_paths ( EFI_DEVICE_PATH_PROTOCOL *first,
                                              ... );
 extern EFI_DEVICE_PATH_PROTOCOL * efi_netdev_path ( struct net_device *netdev );
index d1e22eeaa53f0cda6a22ce926459f86db7d37099..4e37d248a7ff893ccd4a347297a02e23eb29cd5a 100644 (file)
@@ -175,6 +175,46 @@ int efi_path_guid ( EFI_DEVICE_PATH_PROTOCOL *path, union uuid *guid ) {
        return rc;
 }
 
+/**
+ * Parse URI from device path
+ *
+ * @v path             Device path
+ * @ret uri            URI, or NULL if not a URI
+ */
+struct uri * efi_path_uri ( EFI_DEVICE_PATH_PROTOCOL *path ) {
+       EFI_DEVICE_PATH_PROTOCOL *next;
+       URI_DEVICE_PATH *uripath;
+       char *uristring;
+       struct uri *uri;
+       size_t len;
+
+       /* Search for URI device path */
+       for ( ; ( next = efi_path_next ( path ) ) ; path = next ) {
+               if ( ( path->Type == MESSAGING_DEVICE_PATH ) &&
+                    ( path->SubType == MSG_URI_DP ) ) {
+
+                       /* Calculate path length */
+                       uripath = container_of ( path, URI_DEVICE_PATH,
+                                                Header );
+                       len = ( ( ( path->Length[1] << 8 ) | path->Length[0] )
+                               - offsetof ( typeof ( *uripath ), Uri ) );
+
+                       /* Parse URI */
+                       uristring = zalloc ( len + 1 /* NUL */ );
+                       if ( ! uristring )
+                               return NULL;
+                       memcpy ( uristring, uripath->Uri, len );
+                       uri = parse_uri ( uristring );
+                       free ( uristring );
+
+                       return uri;
+               }
+       }
+
+       /* No URI path found */
+       return NULL;
+}
+
 /**
  * Concatenate EFI device paths
  *