+static bool wfd_service_registered = false;
+
+static void start_autoscan(struct connman_device *device);
+static int tech_set_tethering(struct connman_technology *technology,
+ const char *identifier, const char *passphrase,
+ const char *bridge, bool enabled);
+
+#if defined TIZEN_EXT
+#define NETCONFIG_SERVICE "net.netconfig"
+#define NETCONFIG_WIFI_PATH "/net/netconfig/wifi"
+#define NETCONFIG_WIFI_INTERFACE NETCONFIG_SERVICE ".wifi"
+
+struct enc_method_call_data {
+ DBusConnection *connection;
+ struct connman_network *network;
+};
+
+static struct enc_method_call_data encrypt_request_data;
+
+static void encryption_request_reply(DBusPendingCall *call,
+ void *user_data)
+{
+ DBusMessage *reply;
+ DBusError error;
+ DBusMessageIter args;
+ char *out_data;
+ struct connman_service *service;
+ gchar* encrypted_value = NULL;
+ struct connman_network *network = encrypt_request_data.network;
+
+ DBG("");
+
+ reply = dbus_pending_call_steal_reply(call);
+
+ dbus_error_init(&error);
+ if (dbus_set_error_from_message(&error, reply)) {
+ DBG("send_encryption_request() %s %s", error.name, error.message);
+ dbus_error_free(&error);
+ goto done;
+ }
+
+ if (dbus_message_iter_init(reply, &args) == FALSE)
+ goto done;
+
+ dbus_message_iter_get_basic(&args, &out_data);
+
+ encrypted_value = g_strdup((const gchar *)out_data);
+ service = connman_service_lookup_from_network(network);
+
+ if (!service) {
+ DBG("encryption result: no service");
+ goto done;
+ }
+
+ if (connman_service_get_favorite(service)) {
+ __connman_service_set_passphrase(service, encrypted_value);
+ __connman_service_save(service);
+ } else
+ connman_network_set_string(network, "WiFi.Passphrase",
+ encrypted_value);
+
+ DBG("encryption result: succeeded");
+
+done:
+ dbus_message_unref(reply);
+ dbus_pending_call_unref(call);
+ dbus_connection_unref(encrypt_request_data.connection);
+ g_free(encrypted_value);
+
+ encrypt_request_data.connection = NULL;
+ encrypt_request_data.network = NULL;
+}
+
+static int send_encryption_request(const char *passphrase,
+ struct connman_network *network)
+{
+ DBusConnection *connection = NULL;
+ DBusMessage *msg = NULL;
+ DBusPendingCall *call;
+
+ if (!passphrase) {
+ DBG("Invalid parameter");
+ return -EINVAL;
+ }
+
+ connection = connman_dbus_get_connection();
+ if (!connection) {
+ DBG("dbus connection does not exist");
+ return -EINVAL;
+ }
+
+ msg = dbus_message_new_method_call(NETCONFIG_SERVICE, NETCONFIG_WIFI_PATH,
+ NETCONFIG_WIFI_INTERFACE, "EncryptPassphrase");
+ if (!msg) {
+ dbus_connection_unref(connection);
+ return -EINVAL;
+ }
+
+ dbus_message_append_args(msg, DBUS_TYPE_STRING, &passphrase,
+ DBUS_TYPE_INVALID);
+
+ if (!dbus_connection_send_with_reply(connection, msg,
+ &call, DBUS_TIMEOUT_USE_DEFAULT)) {
+ dbus_message_unref(msg);
+ dbus_connection_unref(connection);
+ return -EIO;
+ }
+
+ if (!call) {
+ dbus_message_unref(msg);
+ dbus_connection_unref(connection);
+ return -EIO;
+ }
+
+ encrypt_request_data.connection = connection;
+ encrypt_request_data.network = network;
+
+ dbus_pending_call_set_notify(call, encryption_request_reply, NULL, NULL);
+ dbus_message_unref(msg);
+
+ return 0;
+}
+#endif
+
+static int p2p_tech_probe(struct connman_technology *technology)
+{
+ p2p_technology = technology;
+
+ return 0;
+}
+
+static void p2p_tech_remove(struct connman_technology *technology)
+{
+ p2p_technology = NULL;
+}
+
+static struct connman_technology_driver p2p_tech_driver = {
+ .name = "p2p",
+ .type = CONNMAN_SERVICE_TYPE_P2P,
+ .probe = p2p_tech_probe,
+ .remove = p2p_tech_remove,
+};
+
+static bool is_p2p_connecting(void)
+{
+ GList *list;
+
+ for (list = iface_list; list; list = list->next) {
+ struct wifi_data *wifi = list->data;
+
+ if (wifi->p2p_connecting)
+ return true;
+ }
+
+ return false;
+}
+
+static void add_pending_wifi_device(struct wifi_data *wifi)
+{
+ if (g_list_find(pending_wifi_device, wifi))
+ return;
+
+ pending_wifi_device = g_list_append(pending_wifi_device, wifi);
+}
+
+#if defined TIZEN_EXT_WIFI_MESH
+struct wifi_mesh_info {
+ struct wifi_data *wifi;
+ GSupplicantInterface *interface;
+ struct connman_mesh *mesh;
+ char *parent_ifname;
+ char *ifname;
+ char *identifier;
+ int index;
+};
+
+struct mesh_change_peer_status_info {
+ char *peer_address;
+ enum connman_mesh_peer_status peer_status;
+ mesh_change_peer_status_cb_t callback;
+ void *user_data;
+};
+
+static struct connman_technology_driver mesh_tech_driver = {
+ .name = "mesh",
+ .type = CONNMAN_SERVICE_TYPE_MESH,
+};
+
+static void mesh_interface_create_callback(int result,
+ GSupplicantInterface *interface,
+ void *user_data)
+{
+ struct wifi_mesh_info *mesh_info = user_data;
+ struct wifi_data *wifi;
+ bool success = false;
+
+ DBG("result %d ifname %s, mesh_info %p", result,
+ g_supplicant_interface_get_ifname(interface),
+ mesh_info);
+
+ if (result < 0 || !mesh_info)
+ goto done;
+
+ wifi = mesh_info->wifi;
+
+ mesh_info->interface = interface;
+ mesh_info->identifier = connman_inet_ifaddr(mesh_info->ifname);
+ mesh_info->index = connman_inet_ifindex(mesh_info->ifname);
+ DBG("Mesh Interface identifier %s", mesh_info->identifier);
+ wifi->mesh_interface = true;
+ wifi->mesh_info = mesh_info;
+ g_supplicant_interface_set_data(interface, wifi);
+ success = true;
+
+done:
+ connman_mesh_notify_interface_create(success);
+}
+
+static int add_mesh_interface(const char *ifname, const char *parent_ifname)
+{
+ GList *list;
+ struct wifi_data *wifi;
+ struct wifi_mesh_info *mesh_info;
+ const char *wifi_ifname;
+ bool parent_found = false;
+ const char *driver = "nl80211";
+
+ for (list = iface_list; list; list = list->next) {
+ wifi = list->data;
+
+ if (!g_supplicant_interface_has_mesh(wifi->interface))
+ continue;
+
+ wifi_ifname = g_supplicant_interface_get_ifname(wifi->interface);
+ if (!wifi_ifname)
+ continue;
+
+ if (!g_strcmp0(wifi_ifname, parent_ifname)) {
+ parent_found = true;
+ break;
+ }
+ }
+
+ if (!parent_found) {
+ DBG("Parent interface %s doesn't exist", parent_ifname);
+ return -ENODEV;
+ }
+
+ mesh_info = g_try_malloc0(sizeof(struct wifi_mesh_info));
+ if (!mesh_info)
+ return -ENOMEM;
+
+ mesh_info->wifi = wifi;
+ mesh_info->ifname = g_strdup(ifname);
+ mesh_info->parent_ifname = g_strdup(parent_ifname);
+
+ g_supplicant_mesh_interface_create(ifname, driver, NULL, parent_ifname,
+ mesh_interface_create_callback, mesh_info);
+ return -EINPROGRESS;
+}
+
+static void mesh_interface_remove_callback(int result,
+ GSupplicantInterface *interface,
+ void *user_data)
+{
+ struct wifi_data *wifi = user_data;
+ struct wifi_mesh_info *mesh_info = wifi->mesh_info;
+ bool success = false;
+
+ DBG("result %d mesh_info %p", result, mesh_info);
+
+ if (result < 0 || !mesh_info)
+ goto done;
+
+ mesh_info->interface = NULL;
+ g_free(mesh_info->parent_ifname);
+ g_free(mesh_info->ifname);
+ g_free(mesh_info->identifier);
+ g_free(mesh_info);
+ wifi->mesh_interface = false;
+ wifi->mesh_info = NULL;
+ success = true;
+
+done:
+ connman_mesh_notify_interface_remove(success);
+}
+
+static int remove_mesh_interface(const char *ifname)
+{
+ GList *list;
+ struct wifi_data *wifi;
+ struct wifi_mesh_info *mesh_info;
+ bool mesh_if_found = false;
+ int ret;
+
+ for (list = iface_list; list; list = list->next) {
+ wifi = list->data;
+
+ if (wifi->mesh_interface) {
+ mesh_if_found = true;
+ break;
+ }
+ }
+
+ if (!mesh_if_found) {
+ DBG("Mesh interface %s doesn't exist", ifname);
+ return -ENODEV;
+ }
+
+ mesh_info = wifi->mesh_info;
+ ret = g_supplicant_interface_remove(mesh_info->interface,
+ mesh_interface_remove_callback, wifi);
+ if (ret < 0)
+ return ret;
+
+ return -EINPROGRESS;
+}
+
+static void mesh_disconnect_callback(int result,
+ GSupplicantInterface *interface, void *user_data)
+{
+ struct connman_mesh *mesh = user_data;
+
+ DBG("result %d interface %p mesh %p", result, interface, mesh);
+}
+
+static int mesh_peer_disconnect(struct connman_mesh *mesh)
+{
+ GList *list;
+ struct wifi_data *wifi;
+ struct wifi_mesh_info *mesh_info;
+ bool mesh_if_found = false;
+ GSupplicantInterface *interface;
+
+ for (list = iface_list; list; list = list->next) {
+ wifi = list->data;
+
+ if (wifi->mesh_interface) {
+ mesh_if_found = true;
+ break;
+ }
+ }
+
+ if (!mesh_if_found) {
+ DBG("Mesh interface is not created");
+ return -ENODEV;
+ }
+
+ mesh_info = wifi->mesh_info;
+
+ interface = mesh_info->interface;
+ return g_supplicant_interface_disconnect(interface,
+ mesh_disconnect_callback, mesh);
+}
+
+static void mesh_connect_callback(int result, GSupplicantInterface *interface,
+ void *user_data)
+{
+ struct connman_mesh *mesh = user_data;
+ DBG("mesh %p result %d", mesh, result);
+
+ if (result < 0)
+ connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_FAILURE);
+ else
+ connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_ASSOCIATION);
+}
+
+static GSupplicantSecurity mesh_network_security(const char *security)
+{
+ if (g_str_equal(security, "none"))
+ return G_SUPPLICANT_SECURITY_NONE;
+ else if (g_str_equal(security, "sae"))
+ return G_SUPPLICANT_SECURITY_SAE;
+
+ return G_SUPPLICANT_SECURITY_UNKNOWN;
+}
+
+static void mesh_ssid_init(GSupplicantSSID *ssid, struct connman_mesh *mesh)
+{
+ const char *name;
+ const char *security;
+
+ if (ssid->ssid)
+ g_free(ssid->ssid);
+
+ memset(ssid, 0, sizeof(*ssid));
+ ssid->mode = G_SUPPLICANT_MODE_MESH;
+
+ security = connman_mesh_get_security(mesh);
+ ssid->security = mesh_network_security(security);
+
+ if (ssid->security == G_SUPPLICANT_SECURITY_SAE)
+ ssid->passphrase = connman_mesh_get_passphrase(mesh);
+
+ ssid->freq = connman_mesh_get_frequency(mesh);
+ name = connman_mesh_get_name(mesh);
+ if (name) {
+ ssid->ssid_len = strlen(name);
+ ssid->ssid = g_malloc0(ssid->ssid_len + 1);
+ memcpy(ssid->ssid, name, ssid->ssid_len);
+ ssid->scan_ssid = 1;
+ }
+}
+
+static int mesh_peer_connect(struct connman_mesh *mesh)
+{
+ GList *list;
+ struct wifi_data *wifi;
+ struct wifi_mesh_info *mesh_info;
+ bool mesh_if_found = false;
+ GSupplicantInterface *interface;
+ GSupplicantSSID *ssid;
+
+ for (list = iface_list; list; list = list->next) {
+ wifi = list->data;
+
+ if (wifi->mesh_interface) {
+ mesh_if_found = true;
+ break;
+ }
+ }
+
+ if (!mesh_if_found) {
+ DBG("Mesh interface is not created");
+ return -ENODEV;
+ }
+
+ mesh_info = wifi->mesh_info;
+
+ interface = mesh_info->interface;
+
+ ssid = g_try_malloc0(sizeof(GSupplicantSSID));
+ if (!ssid)
+ return -ENOMEM;
+
+ mesh_info->mesh = mesh;
+
+ mesh_ssid_init(ssid, mesh);
+ return g_supplicant_interface_connect(interface, ssid,
+ mesh_connect_callback, mesh);
+}
+
+static void mesh_peer_change_status_callback(int result,
+ GSupplicantInterface *interface,
+ void *user_data)
+{
+ struct mesh_change_peer_status_info *data = user_data;
+
+ DBG("result %d Peer Status %d", result, data->peer_status);
+
+ if (result == 0 && data->peer_status == CONNMAN_MESH_PEER_REMOVE) {
+ /* WLAN_REASON_MESH_PEERING_CANCELLED = 52 */
+ connman_mesh_remove_connected_peer(data->peer_address, 52);
+ }
+
+ if (data->callback)
+ data->callback(result, data->user_data);
+
+ g_free(data->peer_address);
+ g_free(data);
+ return;
+}
+
+static int mesh_change_peer_status(const char *peer_address,
+ enum connman_mesh_peer_status status,
+ mesh_change_peer_status_cb_t callback, void *user_data)
+{
+ GList *list;
+ struct wifi_data *wifi;
+ struct wifi_mesh_info *mesh_info;
+ bool mesh_if_found = false;
+ GSupplicantInterface *interface;
+ struct mesh_change_peer_status_info *data;
+ const char *method;
+
+ for (list = iface_list; list; list = list->next) {
+ wifi = list->data;
+
+ if (wifi->mesh_interface) {
+ mesh_if_found = true;
+ break;
+ }
+ }
+
+ if (!mesh_if_found) {
+ DBG("Mesh interface is not created");
+ return -ENODEV;
+ }
+
+ mesh_info = wifi->mesh_info;
+
+ interface = mesh_info->interface;
+
+ switch (status) {
+ case CONNMAN_MESH_PEER_ADD:
+ method = "MeshPeerAdd";
+ break;
+ case CONNMAN_MESH_PEER_REMOVE:
+ method = "MeshPeerRemove";
+ break;
+ default:
+ DBG("Invalid method");
+ return -EINVAL;
+ }
+
+ data = g_try_malloc0(sizeof(struct mesh_change_peer_status_info));
+ if (data == NULL) {
+ DBG("Memory allocation failed");
+ return -ENOMEM;
+ }
+
+ data->peer_address = g_strdup(peer_address);
+ data->peer_status = status;
+ data->callback = callback;
+ data->user_data = user_data;
+
+ return g_supplicant_interface_mesh_peer_change_status(interface,
+ mesh_peer_change_status_callback, peer_address, method,
+ data);
+}
+
+static struct connman_mesh_driver mesh_driver = {
+ .add_interface = add_mesh_interface,
+ .remove_interface = remove_mesh_interface,
+ .connect = mesh_peer_connect,
+ .disconnect = mesh_peer_disconnect,
+ .change_peer_status = mesh_change_peer_status,
+};
+
+static void mesh_support(GSupplicantInterface *interface)
+{
+ DBG("");
+
+ if (!g_supplicant_interface_has_mesh(interface))
+ return;
+
+ if (connman_technology_driver_register(&mesh_tech_driver) < 0) {
+ DBG("Could not register Mesh technology driver");
+ return;
+ }
+
+ connman_mesh_driver_register(&mesh_driver);
+}
+
+static void check_mesh_technology(void)
+{
+ bool mesh_exists = false;
+ GList *list;
+
+ for (list = iface_list; list; list = list->next) {
+ struct wifi_data *w = list->data;
+
+ if (w->interface &&
+ g_supplicant_interface_has_mesh(w->interface))
+ mesh_exists = true;
+ }
+
+ if (!mesh_exists) {
+ connman_technology_driver_unregister(&mesh_tech_driver);
+ connman_mesh_driver_unregister(&mesh_driver);
+ }
+}
+
+static void mesh_group_started(GSupplicantInterface *interface)
+{
+ struct wifi_data *wifi;
+ struct wifi_mesh_info *mesh_info;
+ struct connman_mesh *mesh;
+ const unsigned char *ssid;
+ unsigned int ssid_len;
+ char name[33];
+
+ ssid = g_supplicant_interface_get_mesh_group_ssid(interface, &ssid_len);
+ memcpy(name, ssid, ssid_len);
+ name[ssid_len] = '\0';
+ DBG("name %s", name);
+ wifi = g_supplicant_interface_get_data(interface);
+ DBG("wifi %p", wifi);
+
+ if (!wifi)
+ return;
+
+ mesh_info = wifi->mesh_info;
+ if (!mesh_info)
+ return;
+
+ mesh = mesh_info->mesh;
+ if (!mesh)
+ return;
+
+ connman_mesh_peer_set_state(mesh, CONNMAN_MESH_STATE_CONFIGURATION);
+}
+
+static void mesh_group_removed(GSupplicantInterface *interface)
+{
+ struct wifi_data *wifi;
+ struct wifi_mesh_info *mesh_info;
+ struct connman_mesh *mesh;
+ const unsigned char *ssid;
+ unsigned int ssid_len;
+ int disconnect_reason;
+ char name[33];
+
+ ssid = g_supplicant_interface_get_mesh_group_ssid(interface, &ssid_len);
+ memcpy(name, ssid, ssid_len);
+ name[ssid_len] = '\0';
+ DBG("name %s", name);
+
+ disconnect_reason = g_supplicant_mesh_get_disconnect_reason(interface);
+ DBG("Disconnect Reason %d", disconnect_reason);