From: Marcel Holtmann Date: Wed, 16 Jan 2008 02:33:04 +0000 (+0100) Subject: Report found networks and send out updates X-Git-Tag: 0.1~420 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b6af353282ffb3a90f9cce4aa408ac2347117f11;p=platform%2Fupstream%2Fconnman.git Report found networks and send out updates --- diff --git a/plugins/80211.c b/plugins/80211.c index 3327d107..a94551dd 100644 --- a/plugins/80211.c +++ b/plugins/80211.c @@ -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); } diff --git a/src/iface.c b/src/iface.c index c3ca6e2b..1662fb7a 100644 --- a/src/iface.c +++ b/src/iface.c @@ -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}" }, { },