~ubuntu-branches/ubuntu/wily/wpa/wily-proposed

« back to all changes in this revision

Viewing changes to wpa_supplicant/dbus/dbus_new.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2014-12-19 13:29:30 UTC
  • Revision ID: package-import@ubuntu.com-20141219132930-szagdp0wtfh89cuh
Tags: 2.1-0ubuntu6
debian/patches/dbus-available-sta.patch: Make the list of connected
stations available on DBus for hotspot mode; along with some of the
station properties, such as rx/tx packets, bytes, capabilities, etc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include "dbus_common_i.h"
25
25
#include "dbus_new_handlers_p2p.h"
26
26
#include "p2p/p2p.h"
 
27
#include "ap/sta_info.h"
27
28
 
28
29
#ifdef CONFIG_AP /* until needed by something else */
29
30
 
878
879
 * Notify listeners about event related with station
879
880
 */
880
881
static void wpas_dbus_signal_sta(struct wpa_supplicant *wpa_s,
881
 
                                 const u8 *sta, const char *sig_name)
 
882
                                 const u8 *sta, const char *sig_name,
 
883
                                 int properties)
882
884
{
883
885
        struct wpas_dbus_priv *iface;
884
886
        DBusMessage *msg;
885
 
        char sta_mac[WPAS_DBUS_OBJECT_PATH_MAX];
886
 
        char *dev_mac;
 
887
        DBusMessageIter iter;
 
888
        char sta_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
 
889
        char *path;
887
890
 
888
 
        os_snprintf(sta_mac, WPAS_DBUS_OBJECT_PATH_MAX, MACSTR, MAC2STR(sta));
889
 
        dev_mac = sta_mac;
 
891
        os_snprintf(sta_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
 
892
                    "%s/" WPAS_DBUS_NEW_STAS_PART "/" COMPACT_MACSTR,
 
893
                    wpa_s->dbus_new_path, MAC2STR(sta));
 
894
        path = sta_obj_path;
890
895
 
891
896
        iface = wpa_s->global->dbus;
892
897
 
895
900
                return;
896
901
 
897
902
        msg = dbus_message_new_signal(wpa_s->dbus_new_path,
898
 
                                      WPAS_DBUS_NEW_IFACE_INTERFACE, sig_name);
 
903
                                      WPAS_DBUS_NEW_IFACE_INTERFACE,
 
904
                                      sig_name);
899
905
        if (msg == NULL)
900
906
                return;
901
907
 
902
 
        if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &dev_mac,
903
 
                                     DBUS_TYPE_INVALID))
904
 
                dbus_connection_send(iface->con, msg, NULL);
905
 
        else
906
 
                wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
907
 
        dbus_message_unref(msg);
908
 
 
909
 
        wpa_printf(MSG_DEBUG, "dbus: Station MAC address '%s' '%s'",
910
 
                   sta_mac, sig_name);
 
908
        dbus_message_iter_init_append(msg, &iter);
 
909
        if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
 
910
                                            &path))
 
911
                goto err;
 
912
 
 
913
        if (properties) {
 
914
                if (!wpa_dbus_get_object_properties(iface, path,
 
915
                                                    WPAS_DBUS_NEW_IFACE_STA,
 
916
                                                    &iter))
 
917
                        goto err;
 
918
        }
 
919
 
 
920
        wpa_printf(MSG_DEBUG, "dbus: Station MAC address '" MACSTR "' '%s'",
 
921
                   MAC2STR(sta), sig_name);
 
922
 
 
923
        dbus_connection_send(iface->con, msg, NULL);
 
924
        dbus_message_unref(msg);
 
925
        return;
 
926
 
 
927
err:
 
928
        wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
 
929
        dbus_message_unref(msg);
911
930
}
912
931
 
913
932
 
921
940
void wpas_dbus_signal_sta_authorized(struct wpa_supplicant *wpa_s,
922
941
                                     const u8 *sta)
923
942
{
924
 
        wpas_dbus_signal_sta(wpa_s, sta, "StaAuthorized");
 
943
        wpas_dbus_signal_sta(wpa_s, sta, "StaAuthorized", TRUE);
925
944
}
926
945
 
927
946
 
935
954
void wpas_dbus_signal_sta_deauthorized(struct wpa_supplicant *wpa_s,
936
955
                                       const u8 *sta)
937
956
{
938
 
        wpas_dbus_signal_sta(wpa_s, sta, "StaDeauthorized");
 
957
        wpas_dbus_signal_sta(wpa_s, sta, "StaDeauthorized", FALSE);
939
958
}
940
959
 
941
960
 
1817
1836
        case WPAS_DBUS_PROP_BSSS:
1818
1837
                prop = "BSSs";
1819
1838
                break;
 
1839
        case WPAS_DBUS_PROP_STAS:
 
1840
                prop = "Stations";
 
1841
                break;
1820
1842
        case WPAS_DBUS_PROP_CURRENT_AUTH_MODE:
1821
1843
                prop = "CurrentAuthMode";
1822
1844
                break;
1900
1922
 
1901
1923
 
1902
1924
/**
 
1925
 * wpas_dbus_sta_signal_prop_changed - Signals change of STA property
 
1926
 * @wpa_s: %wpa_supplicant network interface data
 
1927
 * @property: indicates which property has changed
 
1928
 * @address: unique BSS identifier
 
1929
 *
 
1930
 * Sends PropertyChanged signals with path, interface, and arguments depending
 
1931
 * on which property has changed.
 
1932
 */
 
1933
void wpas_dbus_sta_signal_prop_changed(struct wpa_supplicant *wpa_s,
 
1934
                                       enum wpas_dbus_bss_prop property,
 
1935
                                       u8 address[ETH_ALEN])
 
1936
{
 
1937
        char path[WPAS_DBUS_OBJECT_PATH_MAX];
 
1938
        char *prop;
 
1939
 
 
1940
        switch (property) {
 
1941
        case WPAS_DBUS_STA_PROP_ADDRESS:
 
1942
                prop = "Address";
 
1943
                break;
 
1944
        default:
 
1945
                wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
 
1946
                           __func__, property);
 
1947
                return;
 
1948
        }
 
1949
 
 
1950
        os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
 
1951
                    "%s/" WPAS_DBUS_NEW_STAS_PART "/" COMPACT_MACSTR,
 
1952
                    wpa_s->dbus_new_path, MAC2STR(address));
 
1953
 
 
1954
        wpa_dbus_mark_property_changed(wpa_s->global->dbus, path,
 
1955
                                       WPAS_DBUS_NEW_IFACE_STA, prop);
 
1956
}
 
1957
/**
1903
1958
 * wpas_dbus_signal_debug_level_changed - Signals change of debug param
1904
1959
 * @global: wpa_global structure
1905
1960
 *
2444
2499
}
2445
2500
 
2446
2501
 
 
2502
static const struct wpa_dbus_property_desc wpas_dbus_sta_properties[] = {
 
2503
        { "Address", WPAS_DBUS_NEW_IFACE_STA, "ay",
 
2504
          wpas_dbus_getter_sta_address,
 
2505
          NULL
 
2506
        },
 
2507
        { "AID", WPAS_DBUS_NEW_IFACE_STA, "q",
 
2508
          wpas_dbus_getter_sta_aid,
 
2509
          NULL
 
2510
        },
 
2511
        { "Flags", WPAS_DBUS_NEW_IFACE_STA, "u",
 
2512
          wpas_dbus_getter_sta_flags,
 
2513
          NULL
 
2514
        },
 
2515
        { "Capabilities", WPAS_DBUS_NEW_IFACE_STA, "q",
 
2516
          wpas_dbus_getter_sta_caps,
 
2517
          NULL
 
2518
        },
 
2519
        { "RxPackets", WPAS_DBUS_NEW_IFACE_STA, "t",
 
2520
          wpas_dbus_getter_sta_rx_packets,
 
2521
          NULL
 
2522
        },
 
2523
        { "TxPackets", WPAS_DBUS_NEW_IFACE_STA, "t",
 
2524
          wpas_dbus_getter_sta_tx_packets,
 
2525
          NULL
 
2526
        },
 
2527
        { "RxBytes", WPAS_DBUS_NEW_IFACE_STA, "t",
 
2528
          wpas_dbus_getter_sta_rx_bytes,
 
2529
          NULL
 
2530
        },
 
2531
        { "TxBytes", WPAS_DBUS_NEW_IFACE_STA, "t",
 
2532
          wpas_dbus_getter_sta_tx_bytes,
 
2533
          NULL
 
2534
        },
 
2535
        { NULL, NULL, NULL, NULL, NULL }
 
2536
};
 
2537
 
 
2538
 
 
2539
static const struct wpa_dbus_signal_desc wpas_dbus_sta_signals[] = {
 
2540
        /* Deprecated: use org.freedesktop.DBus.Properties.PropertiesChanged */
 
2541
        { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_STA,
 
2542
          {
 
2543
                  { "properties", "a{sv}", ARG_OUT },
 
2544
                  END_ARGS
 
2545
          }
 
2546
        },
 
2547
        { NULL, NULL, { END_ARGS } }
 
2548
};
 
2549
 
 
2550
 
 
2551
/**
 
2552
 * wpas_dbus_unregister_sta - Unregister a connected station from dbus
 
2553
 * @wpa_s: wpa_supplicant interface structure
 
2554
 * @bssid: connected station bssid
 
2555
 * @id: unique station identifier
 
2556
 * Returns: 0 on success, -1 on failure
 
2557
 *
 
2558
 * Unregisters STA representing object from dbus
 
2559
 */
 
2560
int wpas_dbus_unregister_sta(struct wpa_supplicant *wpa_s,
 
2561
                             const u8 *sta)
 
2562
{
 
2563
        struct wpas_dbus_priv *ctrl_iface;
 
2564
        char sta_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
 
2565
 
 
2566
        /* Do nothing if the control interface is not turned on */
 
2567
        if (wpa_s == NULL || wpa_s->global == NULL)
 
2568
                return 0;
 
2569
        ctrl_iface = wpa_s->global->dbus;
 
2570
        if (ctrl_iface == NULL)
 
2571
                return 0;
 
2572
 
 
2573
        os_snprintf(sta_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
 
2574
                    "%s/" WPAS_DBUS_NEW_STAS_PART "/" COMPACT_MACSTR,
 
2575
                    wpa_s->dbus_new_path, MAC2STR(sta));
 
2576
 
 
2577
        wpa_printf(MSG_DEBUG, "dbus: Unregister STA object '%s'",
 
2578
                   sta_obj_path);
 
2579
        if (wpa_dbus_unregister_object_per_iface(ctrl_iface, sta_obj_path)) {
 
2580
                wpa_printf(MSG_ERROR, "dbus: Cannot unregister STA object %s",
 
2581
                           sta_obj_path);
 
2582
                return -1;
 
2583
        }
 
2584
 
 
2585
        wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_STAS);
 
2586
 
 
2587
        return 0;
 
2588
}
 
2589
 
 
2590
 
 
2591
/**
 
2592
 * wpas_dbus_register_sta - Register a scanned station with dbus
 
2593
 * @wpa_s: wpa_supplicant interface structure
 
2594
 * @bssid: connection network station
 
2595
 * @id: unique STA identifier
 
2596
 * Returns: 0 on success, -1 on failure
 
2597
 *
 
2598
 * Registers STA representing object with dbus
 
2599
 */
 
2600
int wpas_dbus_register_sta(struct wpa_supplicant *wpa_s,
 
2601
                           const u8 *sta)
 
2602
{
 
2603
        struct wpas_dbus_priv *ctrl_iface;
 
2604
        struct wpa_dbus_object_desc *obj_desc;
 
2605
        char sta_obj_path[WPAS_DBUS_OBJECT_PATH_MAX];
 
2606
        struct sta_handler_args *arg;
 
2607
 
 
2608
        /* Do nothing if the control interface is not turned on */
 
2609
        if (wpa_s == NULL || wpa_s->global == NULL)
 
2610
                return 0;
 
2611
        ctrl_iface = wpa_s->global->dbus;
 
2612
        if (ctrl_iface == NULL)
 
2613
                return 0;
 
2614
 
 
2615
        os_snprintf(sta_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
 
2616
                    "%s/" WPAS_DBUS_NEW_STAS_PART "/" COMPACT_MACSTR,
 
2617
                    wpa_s->dbus_new_path, MAC2STR(sta));
 
2618
 
 
2619
        obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
 
2620
        if (!obj_desc) {
 
2621
                wpa_printf(MSG_ERROR, "Not enough memory "
 
2622
                           "to create object description");
 
2623
                goto err;
 
2624
        }
 
2625
 
 
2626
        arg = os_zalloc(sizeof(struct sta_handler_args));
 
2627
        if (!arg) {
 
2628
                wpa_printf(MSG_ERROR, "Not enough memory "
 
2629
                           "to create arguments for handler");
 
2630
                goto err;
 
2631
        }
 
2632
        arg->wpa_s = wpa_s;
 
2633
        arg->sta = sta;
 
2634
 
 
2635
        wpas_dbus_register(obj_desc, arg, wpa_dbus_free,
 
2636
                           NULL,
 
2637
                           wpas_dbus_sta_properties,
 
2638
                           wpas_dbus_sta_signals);
 
2639
 
 
2640
        wpa_printf(MSG_DEBUG, "dbus: Register STA object '%s'",
 
2641
                   sta_obj_path);
 
2642
        if (wpa_dbus_register_object_per_iface(ctrl_iface, sta_obj_path,
 
2643
                                               wpa_s->ifname, obj_desc)) {
 
2644
                wpa_printf(MSG_ERROR,
 
2645
                           "Cannot register STA dbus object %s.",
 
2646
                           sta_obj_path);
 
2647
                goto err;
 
2648
        }
 
2649
 
 
2650
        wpas_dbus_signal_prop_changed(wpa_s, WPAS_DBUS_PROP_STAS);
 
2651
 
 
2652
        return 0;
 
2653
 
 
2654
err:
 
2655
        free_dbus_object_desc(obj_desc);
 
2656
        return -1;
 
2657
}
 
2658
 
 
2659
 
2447
2660
static const struct wpa_dbus_method_desc wpas_dbus_interface_methods[] = {
2448
2661
        { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
2449
2662
          (WPADBusMethodHandler) &wpas_dbus_handler_scan,
2906
3119
          wpas_dbus_getter_disconnect_reason,
2907
3120
          NULL
2908
3121
        },
 
3122
        { "Stations", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
 
3123
          wpas_dbus_getter_stas,
 
3124
          NULL
 
3125
        },
2909
3126
        { NULL, NULL, NULL, NULL, NULL }
2910
3127
};
2911
3128