+static void generate_random_string(char *str, int length)
+{
+ uint8_t val;
+ int i;
+ uint64_t rand;
+
+ memset(str, '\0', length);
+
+ for (i = 0; i < length-1; i++) {
+ do {
+ __connman_util_get_random(&rand);
+ val = (uint8_t)(rand % 122);
+ if (val < 48)
+ val += 48;
+ } while((val > 57 && val < 65) || (val > 90 && val < 97));
+
+ str[i] = val;
+ }
+}
+
+int connman_config_provision_mutable_service(GKeyFile *keyfile)
+{
+ struct connman_config_service *service_config;
+ struct connman_config *config;
+ char *vfile, *group = NULL;
+ char rstr[11];
+
+ DBG("");
+
+ generate_random_string(rstr, 11);
+
+ vfile = g_strdup_printf("service_mutable_%s.config", rstr);
+
+ config = create_config(vfile);
+ if (!config)
+ return -ENOMEM;
+
+ if (!load_service_from_keyfile(keyfile, config))
+ goto error;
+
+ group = g_key_file_get_start_group(keyfile);
+
+ service_config = g_hash_table_lookup(config->service_table, group+8);
+ if (!service_config)
+ goto error;
+
+ /* Specific to non file based config: */
+ g_free(service_config->config_ident);
+ service_config->config_ident = NULL;
+ g_free(service_config->config_entry);
+ service_config->config_entry = NULL;
+
+ service_config->virtual = true;
+ service_config->virtual_file = vfile;
+
+ __connman_service_provision_changed(vfile);
+
+ if (g_strcmp0(service_config->type, "wifi") == 0)
+ __connman_device_request_scan(CONNMAN_SERVICE_TYPE_WIFI);
+
+ g_free(group);
+ return 0;
+
+error:
+ DBG("Could not proceed");
+ g_hash_table_remove(config_table, vfile);
+ g_free(vfile);
+ g_free(group);
+ return -EINVAL;
+}
+