Report found networks and send out updates
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 16 Jan 2008 02:33:04 +0000 (03:33 +0100)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 16 Jan 2008 02:33:04 +0000 (03:33 +0100)
plugins/80211.c
src/iface.c

index 3327d107ffb977018858b3e51ec16ef0a1868f96..a94551dd7caed7fb269eb50f78e9928176e14783 100644 (file)
@@ -64,6 +64,16 @@ struct iface_data {
        gchar *passphrase;
 };
 
+static void report_station(struct connman_iface *iface,
+                                               struct station_data *station)
+{
+       if (station == NULL)
+               return;
+
+       if (station->name)
+               connman_iface_indicate_station(iface, station->name);
+}
+
 static struct station_data *create_station(struct iface_data *iface,
                                                        const char *address)
 {
@@ -339,6 +349,7 @@ static void parse_scan_results(struct connman_iface *iface,
 
                switch (event->cmd) {
                case SIOCGIWAP:
+                       report_station(iface, station);
                        eth = (void *) &event->u.ap_addr.sa_data;
                        sprintf(addr, "%02X:%02X:%02X:%02X:%02X:%02X",
                                                eth->ether_addr_octet[0],
@@ -401,6 +412,8 @@ static void parse_scan_results(struct connman_iface *iface,
                len -= event->len;
        }
 
+       report_station(iface, station);
+
        printf("[802.11] found %d networks\n", num);
 }
 
index c3ca6e2b1d4b2663f3b752d7331bf0d9388953c5..1662fb7a2a9359daa55a9440c30daba2d5c260bc 100644 (file)
@@ -95,6 +95,37 @@ void __connman_iface_list(DBusMessageIter *iter)
        }
 }
 
+static void append_entry(DBusMessageIter *dict,
+                               const char *key, int type, void *val)
+{
+       DBusMessageIter entry, value;
+       const char *signature;
+
+       dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
+                                                               NULL, &entry);
+
+       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
+
+       switch (type) {
+       case DBUS_TYPE_STRING:
+               signature = DBUS_TYPE_STRING_AS_STRING;
+               break;
+       case DBUS_TYPE_UINT16:
+               signature = DBUS_TYPE_UINT16_AS_STRING;
+               break;
+       default:
+               signature = DBUS_TYPE_VARIANT_AS_STRING;
+               break;
+       }
+
+       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
+                                                       signature, &value);
+       dbus_message_iter_append_basic(&value, type, val);
+       dbus_message_iter_close_container(&entry, &value);
+
+       dbus_message_iter_close_container(dict, &entry);
+}
+
 static void state_changed(struct connman_iface *iface)
 {
        const char *str = __connman_iface_state2string(iface->state);
@@ -258,6 +289,40 @@ void connman_iface_indicate_configured(struct connman_iface *iface)
        }
 }
 
+static void append_station(DBusMessage *reply, const char *name)
+{
+       DBusMessageIter array, dict;
+
+       dbus_message_iter_init_append(reply, &array);
+
+       dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
+                       DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+                       DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
+                       DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+
+       append_entry(&dict, "ESSID", DBUS_TYPE_STRING, &name);
+
+       dbus_message_iter_close_container(&array, &dict);
+}
+
+void connman_iface_indicate_station(struct connman_iface *iface,
+                                                       const char *name)
+{
+       DBusMessage *signal;
+
+       DBG("iface %p name %s", iface, name);
+
+       signal = dbus_message_new_signal(iface->path,
+                               CONNMAN_IFACE_INTERFACE, "NetworkFound");
+       if (signal == NULL)
+               return;
+
+       append_station(signal, name);
+
+       dbus_connection_send(connection, signal, NULL);
+       dbus_message_unref(signal);
+}
+
 int connman_iface_get_ipv4(struct connman_iface *iface,
                                                struct connman_ipv4 *ipv4)
 {
@@ -443,37 +508,6 @@ static DBusMessage *scan_iface(DBusConnection *conn,
        return reply;
 }
 
-static void append_entry(DBusMessageIter *dict,
-                               const char *key, int type, void *val)
-{
-       DBusMessageIter entry, value;
-       const char *signature;
-
-       dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
-                                                               NULL, &entry);
-
-       dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
-
-       switch (type) {
-       case DBUS_TYPE_STRING:
-               signature = DBUS_TYPE_STRING_AS_STRING;
-               break;
-       case DBUS_TYPE_UINT16:
-               signature = DBUS_TYPE_UINT16_AS_STRING;
-               break;
-       default:
-               signature = DBUS_TYPE_VARIANT_AS_STRING;
-               break;
-       }
-
-       dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT,
-                                                       signature, &value);
-       dbus_message_iter_append_basic(&value, type, val);
-       dbus_message_iter_close_container(&entry, &value);
-
-       dbus_message_iter_close_container(dict, &entry);
-}
-
 static DBusMessage *get_properties(DBusConnection *conn,
                                        DBusMessage *msg, void *data)
 {
@@ -895,6 +929,7 @@ static GDBusSignalTable iface_signals[] = {
        { "StateChanged",   "s"     },
        { "SignalChanged",  "q"     },
        { "PolicyChanged",  "s"     },
+       { "NetworkFound",   "a{sv}" },
        { "NetworkChanged", "a{sv}" },
        { "IPv4Changed",    "a{sv}" },
        { },