+
+int ws_add_vsie(wfd_oem_vsie_frames_e frame_id, const char* vsie)
+{
+ __WDP_LOG_FUNC_ENTER__;
+ GDBusConnection *g_dbus = NULL;
+ GVariant *value = NULL;
+ GVariantBuilder *bytearray_builder = NULL;
+ dbus_method_param_s params;
+ int res = 0;
+ int i = 0;
+ size_t vsie_len = 0;
+
+ unsigned char *bytearray = NULL;
+ size_t bytearray_len = 0;
+
+ if (frame_id < 0 || frame_id >= WFD_OEM_VSIE_FRAME_MAX ||
+ vsie == NULL) {
+ WDP_LOGE("Invalid parameter");
+ return -1;
+ }
+
+ if (!g_pd) {
+ WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ g_dbus = g_pd->g_dbus;
+ if (!g_dbus) {
+ WDP_LOGE("DBus connection is NULL");
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ vsie_len = strlen(vsie);
+ if (vsie_len == 0) {
+ WDP_LOGE("vsie length is zero");
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ bytearray_len = (vsie_len % 2) ? ((vsie_len / 2) + 1) : (vsie_len / 2);
+
+ bytearray = (unsigned char *) g_try_malloc0(bytearray_len);
+ if (bytearray == NULL) {
+ WDP_LOGE("Failed to allocate memory to bytearray");
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ if (__ws_hex_str_to_bin(vsie, bytearray, bytearray_len) < 0) {
+ WDP_LOGE("invalid vsie string");
+ g_free(bytearray);
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ memset(¶ms, 0x0, sizeof(dbus_method_param_s));
+ dbus_set_method_param(¶ms, "VendorElemAdd", g_pd->iface_path,
+ g_dbus);
+
+ bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
+ for (i = 0; i < bytearray_len; i++)
+ g_variant_builder_add(bytearray_builder, "y", bytearray[i]);
+
+ value = g_variant_new("(iay)", frame_id, bytearray_builder);
+ g_variant_builder_unref(bytearray_builder);
+
+ params.params = value;
+
+ res = dbus_method_call(¶ms, SUPPLICANT_IFACE, NULL, NULL);
+ if (res < 0) {
+ WDP_LOGE("Failed to send command to wpa_supplicant");
+ g_free(bytearray);
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ WDP_LOGD("Succeeded to add vsie: Frame ID [%d], VSIE [%s]", frame_id,
+ vsie);
+
+ g_free(bytearray);
+ __WDP_LOG_FUNC_EXIT__;
+ return 0;
+}
+
+int ws_get_vsie(wfd_oem_vsie_frames_e frame_id, char **vsie)
+{
+ __WDP_LOG_FUNC_ENTER__;
+ GDBusConnection *g_dbus = NULL;
+ GVariant *param = NULL;
+ GVariant *reply = NULL;
+ GError *error = NULL;
+
+ if (frame_id < 0 || frame_id >= WFD_OEM_VSIE_FRAME_MAX ||
+ vsie == NULL) {
+ WDP_LOGE("Invalid parameter");
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ if (!g_pd) {
+ WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ g_dbus = g_pd->g_dbus;
+ if (!g_dbus) {
+ WDP_LOGE("DBus connection is NULL");
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ param = g_variant_new("(i)", frame_id);
+
+ reply = g_dbus_connection_call_sync(
+ g_pd->g_dbus,
+ SUPPLICANT_SERVICE, /* bus name */
+ g_pd->iface_path, /* object path */
+ SUPPLICANT_IFACE, /* interface name */
+ "VendorElemGet", /* method name */
+ param, /* GVariant *params */
+ NULL, /* reply_type */
+ G_DBUS_CALL_FLAGS_NONE, /* flags */
+ SUPPLICANT_TIMEOUT, /* timeout */
+ NULL, /* cancellable */
+ &error); /* error */
+
+ if (error != NULL) {
+ WDP_LOGE("Error! Failed to get vsie: [%s]", error->message);
+ g_error_free(error);
+ if (reply)
+ g_variant_unref(reply);
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ if (reply != NULL) {
+ DEBUG_G_VARIANT("Reply : ", reply);
+
+ GVariantIter *iter = NULL;
+ unsigned char *vsie_bytes = NULL;
+ int vsie_len = 0;
+
+ g_variant_get(reply, "(ay)", &iter);
+ if (iter == NULL) {
+ WDP_LOGD("vsie is not present");
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ vsie_len = __ws_unpack_ay_malloc(&vsie_bytes, iter);
+ if (vsie_bytes == NULL) {
+ WDP_LOGD("vsie_bytes not allocated");
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ __ws_byte_to_txt(vsie_bytes, vsie, vsie_len);
+ if (!vsie) {
+ g_free(vsie_bytes);
+ WDP_LOGE("vsie not allocated.");
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ g_free(vsie_bytes);
+ }
+
+ WDP_LOGD("Succeeded to get vsie: Frame ID [%d], VSIE [%s]", frame_id,
+ *vsie);
+ __WDP_LOG_FUNC_EXIT__;
+ return 0;
+}
+
+int ws_remove_vsie(wfd_oem_vsie_frames_e frame_id, const char *vsie)
+{
+ __WDP_LOG_FUNC_ENTER__;
+ GDBusConnection *g_dbus = NULL;
+ GVariantBuilder *bytearray_builder = NULL;
+ GVariant *value = NULL;
+ dbus_method_param_s params;
+ int res = 0;
+ int i = 0;
+ size_t vsie_len = 0;
+
+ unsigned char *bytearray = NULL;
+ size_t bytearray_len = 0;
+
+ if (frame_id < 0 || frame_id >= WFD_OEM_VSIE_FRAME_MAX ||
+ vsie == NULL) {
+ WDP_LOGE("Invalid parameter");
+ return -1;
+ }
+
+ if (!g_pd) {
+ WDP_LOGE("ws_dbus_plugin_data_s is not created yet");
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ g_dbus = g_pd->g_dbus;
+ if (!g_dbus) {
+ WDP_LOGE("DBus connection is NULL");
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ vsie_len = strlen(vsie);
+ if (vsie_len == 0) {
+ WDP_LOGE("vsie length is zero");
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ bytearray_len = (vsie_len % 2) ? ((vsie_len / 2) + 1) : (vsie_len / 2);
+
+ bytearray = (unsigned char *) g_try_malloc0(bytearray_len);
+ if (bytearray == NULL) {
+ WDP_LOGE("Failed to allocate memory to bytearray");
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ if (__ws_hex_str_to_bin(vsie, bytearray, bytearray_len) < 0) {
+ WDP_LOGE("invalid vsie string");
+ g_free(bytearray);
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ memset(¶ms, 0x0, sizeof(dbus_method_param_s));
+ dbus_set_method_param(¶ms, "VendorElemRem", g_pd->iface_path,
+ g_dbus);
+
+ bytearray_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
+ for (i = 0; i < bytearray_len; i++)
+ g_variant_builder_add(bytearray_builder, "y", bytearray[i]);
+
+ value = g_variant_new("(iay)", frame_id, bytearray_builder);
+ g_variant_builder_unref(bytearray_builder);
+
+ params.params = value;
+
+ res = dbus_method_call(¶ms, SUPPLICANT_IFACE, NULL, NULL);
+ if (res < 0) {
+ WDP_LOGE("Failed to send command to wpa_supplicant");
+ g_free(bytearray);
+ __WDP_LOG_FUNC_EXIT__;
+ return -1;
+ }
+
+ WDP_LOGD("Succeeded to remove vsie: Frame ID [%d], VSIE [%s]", frame_id,
+ vsie);
+ g_free(bytearray);
+ __WDP_LOG_FUNC_EXIT__;
+ return 0;
+}