hostapd: fix building mini variants
authorFelix Fietkau <nbd@nbd.name>
Fri, 13 Dec 2024 10:04:04 +0000 (11:04 +0100)
committerFelix Fietkau <nbd@nbd.name>
Fri, 13 Dec 2024 10:04:48 +0000 (11:04 +0100)
Move function and add ifdef to avoid undefined reference to hmac_sha256_kdf.

Signed-off-by: Felix Fietkau <nbd@nbd.name>
package/network/services/hostapd/src/src/ap/ucode.c
package/network/services/hostapd/src/src/utils/ucode.c
package/network/services/hostapd/src/src/utils/ucode.h

index adc7c4191480ec6d7cce4812feaefc3845c73b43..e496b8b7aae5004ef9283467fb0fe8817d6bf166 100644 (file)
@@ -817,6 +817,45 @@ out:
        ucv_put(val);
 }
 
+static uc_value_t *
+uc_wpa_rkh_derive_key(uc_vm_t *vm, size_t nargs)
+{
+#ifdef CONFIG_IEEE80211R_AP
+       u8 oldkey[16];
+       char *oldkey_hex;
+       u8 key[SHA256_MAC_LEN];
+       size_t key_len = sizeof(key);
+       char key_hex[2 * ARRAY_SIZE(key) + 1];
+       uc_value_t *val = uc_fn_arg(0);
+       int i;
+
+       if (ucv_type(val) != UC_STRING)
+               return NULL;
+
+       oldkey_hex = ucv_string_get(val);
+
+       if (!hexstr2bin(oldkey_hex, key, key_len))
+               return ucv_string_new_length(oldkey_hex, 2 * ARRAY_SIZE(key));
+
+       if (hexstr2bin(oldkey_hex, oldkey, sizeof(oldkey))) {
+               wpa_printf(MSG_ERROR, "Invalid RxKH key: '%s'", oldkey_hex);
+               return NULL;
+       }
+
+       if (hmac_sha256_kdf(oldkey, sizeof(oldkey), "FT OLDKEY", NULL, 0, key, key_len) < 0) {
+               wpa_printf(MSG_ERROR, "Invalid RxKH key: '%s'", oldkey_hex);
+               return NULL;
+       }
+
+       for (i = 0; i < ARRAY_SIZE(key); i++)
+               sprintf(key_hex + 2 * i, "%02x", key[i]);
+
+       return ucv_string_new_length(key_hex, 2 * ARRAY_SIZE(key));
+#else
+       return NULL;
+#endif
+}
+
 int hostapd_ucode_init(struct hapd_interfaces *ifaces)
 {
        static const uc_function_list_t global_fns[] = {
index 50b87982ceec0be334ca8ae608a9ae6b3c9ddd5b..a1762844b5cd78ab3a8f1ff4a4cbe8ff943be22e 100644 (file)
@@ -237,40 +237,6 @@ uc_value_t *uc_wpa_sha1(uc_vm_t *vm, size_t nargs)
        return ucv_string_new_length(hash_hex, 2 * ARRAY_SIZE(hash));
 }
 
-uc_value_t *uc_wpa_rkh_derive_key(uc_vm_t *vm, size_t nargs)
-{
-       u8 oldkey[16];
-       char *oldkey_hex;
-       u8 key[SHA256_MAC_LEN];
-       size_t key_len = sizeof(key);
-       char key_hex[2 * ARRAY_SIZE(key) + 1];
-       uc_value_t *val = uc_fn_arg(0);
-       int i;
-
-       if (ucv_type(val) != UC_STRING)
-               return NULL;
-
-       oldkey_hex = ucv_string_get(val);
-
-       if (!hexstr2bin(oldkey_hex, key, key_len))
-               return ucv_string_new_length(oldkey_hex, 2 * ARRAY_SIZE(key));
-
-       if (hexstr2bin(oldkey_hex, oldkey, sizeof(oldkey))) {
-               wpa_printf(MSG_ERROR, "Invalid RxKH key: '%s'", oldkey_hex);
-               return NULL;
-       }
-
-       if (hmac_sha256_kdf(oldkey, sizeof(oldkey), "FT OLDKEY", NULL, 0, key, key_len) < 0) {
-               wpa_printf(MSG_ERROR, "Invalid RxKH key: '%s'", oldkey_hex);
-               return NULL;
-       }
-
-       for (i = 0; i < ARRAY_SIZE(key); i++)
-               sprintf(key_hex + 2 * i, "%02x", key[i]);
-
-       return ucv_string_new_length(key_hex, 2 * ARRAY_SIZE(key));
-}
-
 uc_vm_t *wpa_ucode_create_vm(void)
 {
        static uc_parse_config_t config = {
index a273c19b7bc1b175aa7be743962f8dbcdc338fa8..c083241e079cf9f100785430fc5b96d99b2c890c 100644 (file)
@@ -25,7 +25,6 @@ uc_value_t *uc_wpa_udebug_set(uc_vm_t *vm, size_t nargs);
 uc_value_t *uc_wpa_printf(uc_vm_t *vm, size_t nargs);
 uc_value_t *uc_wpa_getpid(uc_vm_t *vm, size_t nargs);
 uc_value_t *uc_wpa_sha1(uc_vm_t *vm, size_t nargs);
-uc_value_t *uc_wpa_rkh_derive_key(uc_vm_t *vm, size_t nargs);
 uc_value_t *uc_wpa_freq_info(uc_vm_t *vm, size_t nargs);
 
 #endif