]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
DBus: Add dict helper for uint16 arrays
authorDamien Dejean <damiendejean@chromium.org>
Tue, 20 Feb 2024 12:11:40 +0000 (12:11 +0000)
committerJouni Malinen <j@w1.fi>
Sat, 9 Mar 2024 15:05:29 +0000 (17:05 +0200)
Extend dict helper to support uint16 arrays.

Signed-off-by: Damien Dejean <damiendejean@chromium.org>
wpa_supplicant/dbus/dbus_dict_helpers.c
wpa_supplicant/dbus/dbus_dict_helpers.h

index fdf7b1258030199afa58a8a0ca2adb291080e848..27003eb44e59da780ac2eec01365e4cef503fb02 100644 (file)
@@ -706,6 +706,59 @@ done:
 }
 
 
+#define UINT16_ARRAY_CHUNK_SIZE 18
+#define UINT16_ARRAY_ITEM_SIZE (sizeof(dbus_uint16_t))
+
+static dbus_bool_t _wpa_dbus_dict_entry_get_uint16_array(
+       DBusMessageIter *iter, struct wpa_dbus_dict_entry *entry)
+{
+       dbus_uint32_t count = 0;
+       dbus_uint16_t *buffer, *nbuffer;
+
+       entry->uint16array_value = NULL;
+       entry->array_type = DBUS_TYPE_UINT16;
+
+       buffer = os_calloc(UINT16_ARRAY_CHUNK_SIZE, UINT16_ARRAY_ITEM_SIZE);
+       if (!buffer)
+               return FALSE;
+
+       entry->array_len = 0;
+       while (dbus_message_iter_get_arg_type(iter) == DBUS_TYPE_UINT16) {
+               dbus_uint16_t value;
+
+               if ((count % UINT16_ARRAY_CHUNK_SIZE) == 0 && count != 0) {
+                       nbuffer = os_realloc_array(
+                               buffer, count + UINT16_ARRAY_CHUNK_SIZE,
+                               UINT16_ARRAY_ITEM_SIZE);
+                       if (!nbuffer) {
+                               os_free(buffer);
+                               wpa_printf(MSG_ERROR,
+                                          "dbus: %s out of memory trying to retrieve the uint16 array",
+                                          __func__);
+                               return FALSE;
+                       }
+                       buffer = nbuffer;
+               }
+
+               dbus_message_iter_get_basic(iter, &value);
+               buffer[count] = value;
+               entry->array_len = ++count;
+               dbus_message_iter_next(iter);
+       }
+       entry->uint16array_value = buffer;
+       wpa_hexdump_key(MSG_MSGDUMP, "dbus: uint16 array contents",
+                       entry->bytearray_value, entry->array_len);
+
+       /* Zero-length arrays are valid. */
+       if (entry->array_len == 0) {
+               os_free(entry->uint16array_value);
+               entry->uint16array_value = NULL;
+       }
+
+       return TRUE;
+}
+
+
 #define STR_ARRAY_CHUNK_SIZE 8
 #define STR_ARRAY_ITEM_SIZE (sizeof(char *))
 
@@ -873,6 +926,10 @@ static dbus_bool_t _wpa_dbus_dict_entry_get_array(
                success = _wpa_dbus_dict_entry_get_byte_array(&iter_array,
                                                              entry);
                break;
+       case DBUS_TYPE_UINT16:
+               success = _wpa_dbus_dict_entry_get_uint16_array(&iter_array,
+                                                               entry);
+               break;
        case DBUS_TYPE_STRING:
                success = _wpa_dbus_dict_entry_get_string_array(&iter_array,
                                                                array_type,
@@ -1081,6 +1138,9 @@ void wpa_dbus_dict_entry_clear(struct wpa_dbus_dict_entry *entry)
                case DBUS_TYPE_BYTE:
                        os_free(entry->bytearray_value);
                        break;
+               case DBUS_TYPE_UINT16:
+                       os_free(entry->uint16array_value);
+                       break;
                case DBUS_TYPE_STRING:
                        if (!entry->strarray_value)
                                break;
index cc9e26fa9b06197c7fec57f56ae9e685c5f9742a..1d33689a8e4412ac3227e5c550ee694663702451 100644 (file)
@@ -139,6 +139,7 @@ struct wpa_dbus_dict_entry {
                dbus_uint64_t uint64_value;
                double double_value;
                char *bytearray_value;
+               dbus_uint16_t *uint16array_value;
                char **strarray_value;
                struct wpabuf **binarray_value;
        };