12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646 |
- /*
- * WPA Supplicant / dbus-based control interface
- * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
- * Copyright (c) 2009, Witold Sowa <witold.sowa@gmail.com>
- * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
- #include "includes.h"
- #include "common.h"
- #include "wps/wps.h"
- #include "../config.h"
- #include "../wpa_supplicant_i.h"
- #include "../bss.h"
- #include "dbus_new_helpers.h"
- #include "dbus_dict_helpers.h"
- #include "dbus_new.h"
- #include "dbus_new_handlers.h"
- #include "dbus_common.h"
- #include "dbus_common_i.h"
- /**
- * wpas_dbus_signal_interface - Send a interface related event signal
- * @wpa_s: %wpa_supplicant network interface data
- * @sig_name: signal name - InterfaceAdded or InterfaceRemoved
- * @properties: Whether to add second argument with object properties
- *
- * Notify listeners about event related with interface
- */
- static void wpas_dbus_signal_interface(struct wpa_supplicant *wpa_s,
- const char *sig_name, int properties)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- DBusMessageIter iter, iter_dict;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- msg = dbus_message_new_signal(WPAS_DBUS_NEW_PATH,
- WPAS_DBUS_NEW_INTERFACE, sig_name);
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
- &wpa_s->dbus_new_path))
- goto err;
- if (properties) {
- if (!wpa_dbus_dict_open_write(&iter, &iter_dict))
- goto err;
- wpa_dbus_get_object_properties(iface, wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_INTERFACE,
- &iter_dict);
- if (!wpa_dbus_dict_close_write(&iter, &iter_dict))
- goto err;
- }
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- return;
- err:
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_interface_added - Send a interface created signal
- * @wpa_s: %wpa_supplicant network interface data
- *
- * Notify listeners about creating new interface
- */
- static void wpas_dbus_signal_interface_added(struct wpa_supplicant *wpa_s)
- {
- wpas_dbus_signal_interface(wpa_s, "InterfaceAdded", TRUE);
- }
- /**
- * wpas_dbus_signal_interface_removed - Send a interface removed signal
- * @wpa_s: %wpa_supplicant network interface data
- *
- * Notify listeners about removing interface
- */
- static void wpas_dbus_signal_interface_removed(struct wpa_supplicant *wpa_s)
- {
- wpas_dbus_signal_interface(wpa_s, "InterfaceRemoved", FALSE);
- }
- /**
- * wpas_dbus_signal_scan_done - send scan done signal
- * @wpa_s: %wpa_supplicant network interface data
- * @success: indicates if scanning succeed or failed
- *
- * Notify listeners about finishing a scan
- */
- void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s, int success)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- dbus_bool_t succ;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_INTERFACE,
- "ScanDone");
- if (msg == NULL)
- return;
- succ = success ? TRUE : FALSE;
- if (dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &succ,
- DBUS_TYPE_INVALID))
- dbus_connection_send(iface->con, msg, NULL);
- else
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_blob - Send a BSS related event signal
- * @wpa_s: %wpa_supplicant network interface data
- * @bss_obj_path: BSS object path
- * @sig_name: signal name - BSSAdded or BSSRemoved
- * @properties: Whether to add second argument with object properties
- *
- * Notify listeners about event related with BSS
- */
- static void wpas_dbus_signal_bss(struct wpa_supplicant *wpa_s,
- const char *bss_obj_path,
- const char *sig_name, int properties)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- DBusMessageIter iter, iter_dict;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_INTERFACE,
- sig_name);
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
- &bss_obj_path))
- goto err;
- if (properties) {
- if (!wpa_dbus_dict_open_write(&iter, &iter_dict))
- goto err;
- wpa_dbus_get_object_properties(iface, bss_obj_path,
- WPAS_DBUS_NEW_IFACE_BSSID,
- &iter_dict);
- if (!wpa_dbus_dict_close_write(&iter, &iter_dict))
- goto err;
- }
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- return;
- err:
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_bss_added - Send a BSS added signal
- * @wpa_s: %wpa_supplicant network interface data
- * @bss_obj_path: new BSS object path
- *
- * Notify listeners about adding new BSS
- */
- static void wpas_dbus_signal_bss_added(struct wpa_supplicant *wpa_s,
- const char *bss_obj_path)
- {
- wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSAdded", TRUE);
- }
- /**
- * wpas_dbus_signal_bss_removed - Send a BSS removed signal
- * @wpa_s: %wpa_supplicant network interface data
- * @bss_obj_path: BSS object path
- *
- * Notify listeners about removing BSS
- */
- static void wpas_dbus_signal_bss_removed(struct wpa_supplicant *wpa_s,
- const char *bss_obj_path)
- {
- wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSRemoved", FALSE);
- }
- /**
- * wpas_dbus_signal_blob - Send a blob related event signal
- * @wpa_s: %wpa_supplicant network interface data
- * @name: blob name
- * @sig_name: signal name - BlobAdded or BlobRemoved
- *
- * Notify listeners about event related with blob
- */
- static void wpas_dbus_signal_blob(struct wpa_supplicant *wpa_s,
- const char *name, const char *sig_name)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_INTERFACE,
- sig_name);
- if (msg == NULL)
- return;
- if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
- DBUS_TYPE_INVALID))
- dbus_connection_send(iface->con, msg, NULL);
- else
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_blob_added - Send a blob added signal
- * @wpa_s: %wpa_supplicant network interface data
- * @name: blob name
- *
- * Notify listeners about adding a new blob
- */
- void wpas_dbus_signal_blob_added(struct wpa_supplicant *wpa_s,
- const char *name)
- {
- wpas_dbus_signal_blob(wpa_s, name, "BlobAdded");
- }
- /**
- * wpas_dbus_signal_blob_removed - Send a blob removed signal
- * @wpa_s: %wpa_supplicant network interface data
- * @name: blob name
- *
- * Notify listeners about removing blob
- */
- void wpas_dbus_signal_blob_removed(struct wpa_supplicant *wpa_s,
- const char *name)
- {
- wpas_dbus_signal_blob(wpa_s, name, "BlobRemoved");
- }
- /**
- * wpas_dbus_signal_network - Send a network related event signal
- * @wpa_s: %wpa_supplicant network interface data
- * @id: new network id
- * @sig_name: signal name - NetworkAdded, NetworkRemoved or NetworkSelected
- * @properties: determines if add second argument with object properties
- *
- * Notify listeners about event related with configured network
- */
- static void wpas_dbus_signal_network(struct wpa_supplicant *wpa_s,
- int id, const char *sig_name,
- int properties)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- DBusMessageIter iter, iter_dict;
- char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
- wpa_s->dbus_new_path, id);
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_INTERFACE,
- sig_name);
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- path = net_obj_path;
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
- &path))
- goto err;
- if (properties) {
- if (!wpa_dbus_dict_open_write(&iter, &iter_dict))
- goto err;
- wpa_dbus_get_object_properties(iface, net_obj_path,
- WPAS_DBUS_NEW_IFACE_NETWORK,
- &iter_dict);
- if (!wpa_dbus_dict_close_write(&iter, &iter_dict))
- goto err;
- }
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- return;
- err:
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_network_added - Send a network added signal
- * @wpa_s: %wpa_supplicant network interface data
- * @id: new network id
- *
- * Notify listeners about adding new network
- */
- static void wpas_dbus_signal_network_added(struct wpa_supplicant *wpa_s,
- int id)
- {
- wpas_dbus_signal_network(wpa_s, id, "NetworkAdded", TRUE);
- }
- /**
- * wpas_dbus_signal_network_removed - Send a network removed signal
- * @wpa_s: %wpa_supplicant network interface data
- * @id: network id
- *
- * Notify listeners about removing a network
- */
- static void wpas_dbus_signal_network_removed(struct wpa_supplicant *wpa_s,
- int id)
- {
- wpas_dbus_signal_network(wpa_s, id, "NetworkRemoved", FALSE);
- }
- /**
- * wpas_dbus_signal_network_selected - Send a network selected signal
- * @wpa_s: %wpa_supplicant network interface data
- * @id: network id
- *
- * Notify listeners about selecting a network
- */
- void wpas_dbus_signal_network_selected(struct wpa_supplicant *wpa_s, int id)
- {
- wpas_dbus_signal_network(wpa_s, id, "NetworkSelected", FALSE);
- }
- static void str_to_lower(char *s)
- {
- while (*s) {
- *s = tolower(*s);
- s++;
- }
- }
- /**
- * wpas_dbus_signal_state_changed - Send a state changed signal
- * @wpa_s: %wpa_supplicant network interface data
- * @new_state: new state wpa_supplicant is entering
- * @old_state: old state wpa_supplicant is leaving
- *
- * Notify listeners that wpa_supplicant has changed state
- */
- void wpas_dbus_signal_state_changed(struct wpa_supplicant *wpa_s,
- enum wpa_states new_state,
- enum wpa_states old_state)
- {
- struct wpas_dbus_priv *iface;
- DBusMessage *msg;
- char *new_state_str, *old_state_str;
- /* Do nothing if the control interface is not turned on */
- if (wpa_s->global == NULL)
- return;
- iface = wpa_s->global->dbus;
- if (iface == NULL)
- return;
- /* Only send signal if state really changed */
- if (new_state == old_state)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_INTERFACE,
- "StateChanged");
- if (msg == NULL)
- return;
- new_state_str = os_strdup(wpa_supplicant_state_txt(new_state));
- old_state_str = os_strdup(wpa_supplicant_state_txt(old_state));
- if (new_state_str == NULL || old_state_str == NULL)
- goto out;
- /* make state string lowercase to fit new DBus API convention */
- str_to_lower(new_state_str);
- str_to_lower(old_state_str);
- if (!dbus_message_append_args(msg,
- DBUS_TYPE_STRING, &new_state_str,
- DBUS_TYPE_STRING, &old_state_str,
- DBUS_TYPE_INVALID)) {
- wpa_printf(MSG_ERROR, "dbus: Failed to construct state change "
- "signal");
- goto out;
- }
- dbus_connection_send(iface->con, msg, NULL);
- out:
- dbus_message_unref(msg);
- os_free(new_state_str);
- os_free(old_state_str);
- }
- /**
- * wpas_dbus_signal_network_enabled_changed - Signals Enabled property changes
- * @wpa_s: %wpa_supplicant network interface data
- * @ssid: configured network which Enabled property has changed
- *
- * Sends PropertyChanged signals containing new value of Enabled property
- * for specified network
- */
- void wpas_dbus_signal_network_enabled_changed(struct wpa_supplicant *wpa_s,
- struct wpa_ssid *ssid)
- {
- struct network_handler_args args = { wpa_s, ssid };
- char path[WPAS_DBUS_OBJECT_PATH_MAX];
- os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
- wpa_s->dbus_new_path, ssid->id);
- wpa_dbus_signal_property_changed(wpa_s->global->dbus,
- (WPADBusPropertyAccessor)
- wpas_dbus_getter_enabled, &args,
- path, WPAS_DBUS_NEW_IFACE_NETWORK,
- "Enabled");
- }
- #ifdef CONFIG_WPS
- /**
- * wpas_dbus_signal_wps_event_success - Signals Success WPS event
- * @wpa_s: %wpa_supplicant network interface data
- *
- * Sends Event dbus signal with name "success" and empty dict as arguments
- */
- void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s)
- {
- DBusMessage *msg;
- DBusMessageIter iter, dict_iter;
- struct wpas_dbus_priv *iface;
- char *key = "success";
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_WPS, "Event");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
- !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
- !wpa_dbus_dict_close_write(&iter, &dict_iter))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_wps_event_fail - Signals Fail WPS event
- * @wpa_s: %wpa_supplicant network interface data
- *
- * Sends Event dbus signal with name "fail" and dictionary containing
- * "msg field with fail message number (int32) as arguments
- */
- void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
- struct wps_event_fail *fail)
- {
- DBusMessage *msg;
- DBusMessageIter iter, dict_iter;
- struct wpas_dbus_priv *iface;
- char *key = "fail";
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_WPS, "Event");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
- !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
- !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
- !wpa_dbus_dict_close_write(&iter, &dict_iter))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_wps_event_m2d - Signals M2D WPS event
- * @wpa_s: %wpa_supplicant network interface data
- *
- * Sends Event dbus signal with name "m2d" and dictionary containing
- * fields of wps_event_m2d structure.
- */
- void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
- struct wps_event_m2d *m2d)
- {
- DBusMessage *msg;
- DBusMessageIter iter, dict_iter;
- struct wpas_dbus_priv *iface;
- char *key = "m2d";
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_WPS, "Event");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
- !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
- !wpa_dbus_dict_append_uint16(&dict_iter, "config_methods",
- m2d->config_methods) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer",
- (const char *) m2d->manufacturer,
- m2d->manufacturer_len) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "model_name",
- (const char *) m2d->model_name,
- m2d->model_name_len) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "model_number",
- (const char *) m2d->model_number,
- m2d->model_number_len) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number",
- (const char *)
- m2d->serial_number,
- m2d->serial_number_len) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name",
- (const char *) m2d->dev_name,
- m2d->dev_name_len) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type",
- (const char *)
- m2d->primary_dev_type, 8) ||
- !wpa_dbus_dict_append_uint16(&dict_iter, "config_error",
- m2d->config_error) ||
- !wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id",
- m2d->dev_password_id) ||
- !wpa_dbus_dict_close_write(&iter, &dict_iter))
- wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
- else
- dbus_connection_send(iface->con, msg, NULL);
- dbus_message_unref(msg);
- }
- /**
- * wpas_dbus_signal_wps_cred - Signals new credentials
- * @wpa_s: %wpa_supplicant network interface data
- *
- * Sends signal with credentials in directory argument
- */
- void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
- const struct wps_credential *cred)
- {
- DBusMessage *msg;
- DBusMessageIter iter, dict_iter;
- struct wpas_dbus_priv *iface;
- char *auth_type[6]; /* we have six possible authorization types */
- int at_num = 0;
- char *encr_type[4]; /* we have four possible encryption types */
- int et_num = 0;
- iface = wpa_s->global->dbus;
- /* Do nothing if the control interface is not turned on */
- if (iface == NULL)
- return;
- msg = dbus_message_new_signal(wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_WPS,
- "Credentials");
- if (msg == NULL)
- return;
- dbus_message_iter_init_append(msg, &iter);
- if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
- goto nomem;
- if (cred->auth_type & WPS_AUTH_OPEN)
- auth_type[at_num++] = "open";
- if (cred->auth_type & WPS_AUTH_WPAPSK)
- auth_type[at_num++] = "wpa-psk";
- if (cred->auth_type & WPS_AUTH_SHARED)
- auth_type[at_num++] = "shared";
- if (cred->auth_type & WPS_AUTH_WPA)
- auth_type[at_num++] = "wpa-eap";
- if (cred->auth_type & WPS_AUTH_WPA2)
- auth_type[at_num++] = "wpa2-eap";
- if (cred->auth_type & WPS_AUTH_WPA2PSK)
- auth_type[at_num++] =
- "wpa2-psk";
- if (cred->encr_type & WPS_ENCR_NONE)
- encr_type[et_num++] = "none";
- if (cred->encr_type & WPS_ENCR_WEP)
- encr_type[et_num++] = "wep";
- if (cred->encr_type & WPS_ENCR_TKIP)
- encr_type[et_num++] = "tkip";
- if (cred->encr_type & WPS_ENCR_AES)
- encr_type[et_num++] = "aes";
- if (wpa_s->current_ssid) {
- if (!wpa_dbus_dict_append_byte_array(
- &dict_iter, "BSSID",
- (const char *) wpa_s->current_ssid->bssid,
- ETH_ALEN))
- goto nomem;
- }
- if (!wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
- (const char *) cred->ssid,
- cred->ssid_len) ||
- !wpa_dbus_dict_append_string_array(&dict_iter, "AuthType",
- (const char **) auth_type,
- at_num) ||
- !wpa_dbus_dict_append_string_array(&dict_iter, "EncrType",
- (const char **) encr_type,
- et_num) ||
- !wpa_dbus_dict_append_byte_array(&dict_iter, "Key",
- (const char *) cred->key,
- cred->key_len) ||
- !wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex",
- cred->key_idx) ||
- !wpa_dbus_dict_close_write(&iter, &dict_iter))
- goto nomem;
- dbus_connection_send(iface->con, msg, NULL);
- nomem:
- dbus_message_unref(msg);
- }
- #endif /* CONFIG_WPS */
- /**
- * wpas_dbus_signal_prop_changed - Signals change of property
- * @wpa_s: %wpa_supplicant network interface data
- * @property: indicates which property has changed
- *
- * Sends ProertyChanged signals with path, interface and arguments
- * depending on which property has changed.
- */
- void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
- enum wpas_dbus_prop property)
- {
- WPADBusPropertyAccessor getter;
- char *prop;
- switch (property) {
- case WPAS_DBUS_PROP_AP_SCAN:
- getter = (WPADBusPropertyAccessor) wpas_dbus_getter_ap_scan;
- prop = "ApScan";
- break;
- case WPAS_DBUS_PROP_SCANNING:
- getter = (WPADBusPropertyAccessor) wpas_dbus_getter_scanning;
- prop = "Scanning";
- break;
- case WPAS_DBUS_PROP_CURRENT_BSS:
- getter = (WPADBusPropertyAccessor)
- wpas_dbus_getter_current_bss;
- prop = "CurrentBSS";
- break;
- case WPAS_DBUS_PROP_CURRENT_NETWORK:
- getter = (WPADBusPropertyAccessor)
- wpas_dbus_getter_current_network;
- prop = "CurrentNetwork";
- break;
- default:
- wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
- __func__, property);
- return;
- }
- wpa_dbus_signal_property_changed(wpa_s->global->dbus,
- getter, wpa_s, wpa_s->dbus_new_path,
- WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
- }
- /**
- * wpas_dbus_signal_debug_level_changed - Signals change of debug param
- * @global: wpa_global structure
- *
- * Sends ProertyChanged signals informing that debug level has changed.
- */
- void wpas_dbus_signal_debug_level_changed(struct wpa_global *global)
- {
- wpa_dbus_signal_property_changed(global->dbus,
- (WPADBusPropertyAccessor)
- wpas_dbus_getter_debug_level,
- global, WPAS_DBUS_NEW_PATH,
- WPAS_DBUS_NEW_INTERFACE,
- "DebugLevel");
- }
- /**
- * wpas_dbus_signal_debug_timestamp_changed - Signals change of debug param
- * @global: wpa_global structure
- *
- * Sends ProertyChanged signals informing that debug timestamp has changed.
- */
- void wpas_dbus_signal_debug_timestamp_changed(struct wpa_global *global)
- {
- wpa_dbus_signal_property_changed(global->dbus,
- (WPADBusPropertyAccessor)
- wpas_dbus_getter_debug_timestamp,
- global, WPAS_DBUS_NEW_PATH,
- WPAS_DBUS_NEW_INTERFACE,
- "DebugTimestamp");
- }
- /**
- * wpas_dbus_signal_debug_show_keys_changed - Signals change of debug param
- * @global: wpa_global structure
- *
- * Sends ProertyChanged signals informing that debug show_keys has changed.
- */
- void wpas_dbus_signal_debug_show_keys_changed(struct wpa_global *global)
- {
- wpa_dbus_signal_property_changed(global->dbus,
- (WPADBusPropertyAccessor)
- wpas_dbus_getter_debug_show_keys,
- global, WPAS_DBUS_NEW_PATH,
- WPAS_DBUS_NEW_INTERFACE,
- "DebugShowKeys");
- }
- struct wpas_dbus_method {
- const char *name;
- const char *iface;
- WPADBusMethodHandler handler;
- struct wpa_dbus_argument args[3];
- };
- struct wpas_dbus_property {
- const char *name;
- const char *iface;
- const char *type;
- WPADBusPropertyAccessor getter;
- WPADBusPropertyAccessor setter;
- enum dbus_prop_access _access;
- };
- struct wpas_dbus_signal {
- const char *name;
- const char *iface;
- struct wpa_dbus_argument args[3];
- };
- static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
- void *priv,
- WPADBusArgumentFreeFunction priv_free,
- const struct wpas_dbus_method *methods,
- const struct wpas_dbus_property *properties,
- const struct wpas_dbus_signal *signals)
- {
- int i;
- obj_desc->user_data = priv;
- obj_desc->user_data_free_func = priv_free;
- for (i = 0; methods && methods[i].name; i++) {
- wpa_dbus_method_register(obj_desc, methods[i].iface,
- methods[i].name, methods[i].handler,
- methods[i].args);
- }
- for (i = 0; properties && properties[i].name; i++) {
- wpa_dbus_property_register(obj_desc, properties[i].iface,
- properties[i].name,
- properties[i].type,
- properties[i].getter,
- properties[i].setter,
- properties[i]._access);
- }
- for (i = 0; signals && signals[i].name; i++) {
- wpa_dbus_signal_register(obj_desc, signals[i].iface,
- signals[i].name, signals[i].args);
- }
- }
- static const struct wpas_dbus_method wpas_dbus_global_methods[] = {
- { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
- (WPADBusMethodHandler) &wpas_dbus_handler_create_interface,
- {
- { "args", "a{sv}", ARG_IN },
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
- (WPADBusMethodHandler) &wpas_dbus_handler_remove_interface,
- {
- { "path", "o", ARG_IN },
- END_ARGS
- }
- },
- { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
- (WPADBusMethodHandler) &wpas_dbus_handler_get_interface,
- {
- { "ifname", "s", ARG_IN },
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- { NULL, NULL, NULL, { END_ARGS } }
- };
- static const struct wpas_dbus_property wpas_dbus_global_properties[] = {
- { "DebugLevel", WPAS_DBUS_NEW_INTERFACE, "y",
- (WPADBusPropertyAccessor) wpas_dbus_getter_debug_level,
- (WPADBusPropertyAccessor) wpas_dbus_setter_debug_level,
- RW
- },
- { "DebugTimestamp", WPAS_DBUS_NEW_INTERFACE, "b",
- (WPADBusPropertyAccessor) wpas_dbus_getter_debug_timestamp,
- (WPADBusPropertyAccessor) wpas_dbus_setter_debug_timestamp,
- RW
- },
- { "DebugShowKeys", WPAS_DBUS_NEW_INTERFACE, "b",
- (WPADBusPropertyAccessor) wpas_dbus_getter_debug_show_keys,
- (WPADBusPropertyAccessor) wpas_dbus_setter_debug_show_keys,
- RW
- },
- { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
- (WPADBusPropertyAccessor) &wpas_dbus_getter_interfaces,
- NULL,
- R
- },
- { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
- (WPADBusPropertyAccessor) wpas_dbus_getter_eap_methods,
- NULL,
- R
- },
- { NULL, NULL, NULL, NULL, NULL, 0 }
- };
- static const struct wpas_dbus_signal wpas_dbus_global_signals[] = {
- { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
- {
- { "path", "o", ARG_OUT },
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
- {
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
- {
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { NULL, NULL, { END_ARGS } }
- };
- /**
- * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
- * @global: Pointer to global data from wpa_supplicant_init()
- * Returns: 0 on success or -1 on failure
- *
- * Initialize the dbus control interface for wpa_supplicantand and start
- * receiving commands from external programs over the bus.
- */
- int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
- {
- struct wpa_dbus_object_desc *obj_desc;
- int ret;
- obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
- if (!obj_desc) {
- wpa_printf(MSG_ERROR, "Not enough memory "
- "to create object description");
- return -1;
- }
- wpas_dbus_register(obj_desc, priv->global, NULL,
- wpas_dbus_global_methods,
- wpas_dbus_global_properties,
- wpas_dbus_global_signals);
- wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
- WPAS_DBUS_NEW_PATH);
- ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
- WPAS_DBUS_NEW_SERVICE,
- obj_desc);
- if (ret < 0)
- free_dbus_object_desc(obj_desc);
- else
- priv->dbus_new_initialized = 1;
- return ret;
- }
- /**
- * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
- * wpa_supplicant
- * @iface: Pointer to dbus private data from wpas_dbus_init()
- *
- * Deinitialize the dbus control interface that was initialized with
- * wpas_dbus_ctrl_iface_init().
- */
- void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
- {
- if (!iface->dbus_new_initialized)
- return;
- wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
- WPAS_DBUS_NEW_PATH);
- dbus_connection_unregister_object_path(iface->con,
- WPAS_DBUS_NEW_PATH);
- }
- static void wpa_dbus_free(void *ptr)
- {
- os_free(ptr);
- }
- static const struct wpas_dbus_property wpas_dbus_network_properties[] = {
- { "Properties", WPAS_DBUS_NEW_IFACE_NETWORK, "a{sv}",
- (WPADBusPropertyAccessor) wpas_dbus_getter_network_properties,
- (WPADBusPropertyAccessor) wpas_dbus_setter_network_properties,
- RW
- },
- { "Enabled", WPAS_DBUS_NEW_IFACE_NETWORK, "b",
- (WPADBusPropertyAccessor) wpas_dbus_getter_enabled,
- (WPADBusPropertyAccessor) wpas_dbus_setter_enabled,
- RW
- },
- { NULL, NULL, NULL, NULL, NULL, 0 }
- };
- static const struct wpas_dbus_signal wpas_dbus_network_signals[] = {
- { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_NETWORK,
- {
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { NULL, NULL, { END_ARGS } }
- };
- /**
- * wpas_dbus_register_network - Register a configured network with dbus
- * @wpa_s: wpa_supplicant interface structure
- * @ssid: network configuration data
- * Returns: 0 on success, -1 on failure
- *
- * Registers network representing object with dbus
- */
- int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
- struct wpa_ssid *ssid)
- {
- struct wpas_dbus_priv *ctrl_iface;
- struct wpa_dbus_object_desc *obj_desc;
- struct network_handler_args *arg = NULL;
- char *net_obj_path;
- /* Do nothing if the control interface is not turned on */
- if (wpa_s == NULL || wpa_s->global == NULL)
- return 0;
- ctrl_iface = wpa_s->global->dbus;
- if (ctrl_iface == NULL)
- return 0;
- net_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
- if (net_obj_path == NULL)
- return -1;
- os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
- wpa_s->dbus_new_path, ssid->id);
- wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
- net_obj_path);
- obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
- if (!obj_desc) {
- wpa_printf(MSG_ERROR, "Not enough memory "
- "to create object description");
- goto err;
- }
- /* allocate memory for handlers arguments */
- arg = os_zalloc(sizeof(struct network_handler_args));
- if (!arg) {
- wpa_printf(MSG_ERROR, "Not enough memory "
- "to create arguments for method");
- goto err;
- }
- arg->wpa_s = wpa_s;
- arg->ssid = ssid;
- wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
- wpas_dbus_network_properties,
- wpas_dbus_network_signals);
- if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
- wpa_s->ifname, obj_desc))
- goto err;
- wpas_dbus_signal_network_added(wpa_s, ssid->id);
- os_free(net_obj_path);
- return 0;
- err:
- os_free(net_obj_path);
- os_free(obj_desc);
- os_free(arg);
- return -1;
- }
- /**
- * wpas_dbus_unregister_network - Unregister a configured network from dbus
- * @wpa_s: wpa_supplicant interface structure
- * @nid: network id
- * Returns: 0 on success, -1 on failure
- *
- * Unregisters network representing object from dbus
- */
- int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
- {
- struct wpas_dbus_priv *ctrl_iface;
- char *net_obj_path;
- int ret;
- /* Do nothing if the control interface is not turned on */
- if (wpa_s == NULL || wpa_s->global == NULL)
- return 0;
- ctrl_iface = wpa_s->global->dbus;
- if (ctrl_iface == NULL)
- return 0;
- net_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
- if (net_obj_path == NULL)
- return -1;
- os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
- wpa_s->dbus_new_path, nid);
- wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
- net_obj_path);
- ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
- if (!ret)
- wpas_dbus_signal_network_removed(wpa_s, nid);
- os_free(net_obj_path);
- return ret;
- }
- static const struct wpas_dbus_property wpas_dbus_bss_properties[] = {
- { "SSID", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
- (WPADBusPropertyAccessor) wpas_dbus_getter_bss_ssid,
- NULL,
- R
- },
- { "BSSID", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
- (WPADBusPropertyAccessor) wpas_dbus_getter_bss_bssid,
- NULL,
- R
- },
- { "Privacy", WPAS_DBUS_NEW_IFACE_BSSID, "b",
- (WPADBusPropertyAccessor) wpas_dbus_getter_bss_privacy,
- NULL,
- R
- },
- { "Mode", WPAS_DBUS_NEW_IFACE_BSSID, "s",
- (WPADBusPropertyAccessor) wpas_dbus_getter_bss_mode,
- NULL,
- R
- },
- { "Signal", WPAS_DBUS_NEW_IFACE_BSSID, "n",
- (WPADBusPropertyAccessor) wpas_dbus_getter_bss_signal,
- NULL,
- R
- },
- { "Frequency", WPAS_DBUS_NEW_IFACE_BSSID, "q",
- (WPADBusPropertyAccessor) wpas_dbus_getter_bss_frequency,
- NULL,
- R
- },
- { "MaxRate", WPAS_DBUS_NEW_IFACE_BSSID, "q",
- (WPADBusPropertyAccessor) wpas_dbus_getter_bss_max_rate,
- NULL,
- R
- },
- { "WPAIE", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
- (WPADBusPropertyAccessor) wpas_dbus_getter_bss_wpaie,
- NULL,
- R
- },
- { "RSNIE", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
- (WPADBusPropertyAccessor) wpas_dbus_getter_bss_rsnie,
- NULL,
- R
- },
- { "WPSIE", WPAS_DBUS_NEW_IFACE_BSSID, "ay",
- (WPADBusPropertyAccessor) wpas_dbus_getter_bss_wpsie,
- NULL,
- R
- },
- { NULL, NULL, NULL, NULL, NULL, 0 }
- };
- static const struct wpas_dbus_signal wpas_dbus_bss_signals[] = {
- { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_BSSID,
- {
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { NULL, NULL, { END_ARGS } }
- };
- /**
- * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
- * @wpa_s: wpa_supplicant interface structure
- * @bssid: scanned network bssid
- * @id: unique BSS identifier
- * Returns: 0 on success, -1 on failure
- *
- * Unregisters BSS representing object from dbus
- */
- int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
- u8 bssid[ETH_ALEN], unsigned int id)
- {
- struct wpas_dbus_priv *ctrl_iface;
- char *bss_obj_path;
- /* Do nothing if the control interface is not turned on */
- if (wpa_s == NULL || wpa_s->global == NULL)
- return 0;
- ctrl_iface = wpa_s->global->dbus;
- if (ctrl_iface == NULL)
- return 0;
- bss_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
- if (bss_obj_path == NULL)
- return -1;
- os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
- wpa_s->dbus_new_path, id);
- wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
- bss_obj_path);
- if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
- wpa_printf(MSG_ERROR,
- "Cannot unregister BSSID dbus object %s.",
- bss_obj_path);
- os_free(bss_obj_path);
- return -1;
- }
- wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
- os_free(bss_obj_path);
- return 0;
- }
- /**
- * wpas_dbus_register_bss - Register a scanned BSS with dbus
- * @wpa_s: wpa_supplicant interface structure
- * @bssid: scanned network bssid
- * @id: unique BSS identifier
- * Returns: 0 on success, -1 on failure
- *
- * Registers BSS representing object with dbus
- */
- int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
- u8 bssid[ETH_ALEN], unsigned int id)
- {
- struct wpas_dbus_priv *ctrl_iface;
- struct wpa_dbus_object_desc *obj_desc;
- char *bss_obj_path;
- struct bss_handler_args *arg = NULL;
- /* Do nothing if the control interface is not turned on */
- if (wpa_s == NULL || wpa_s->global == NULL)
- return 0;
- ctrl_iface = wpa_s->global->dbus;
- if (ctrl_iface == NULL)
- return 0;
- bss_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
- if (bss_obj_path == NULL)
- return -1;
- os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
- "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
- wpa_s->dbus_new_path, id);
- obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
- if (!obj_desc) {
- wpa_printf(MSG_ERROR, "Not enough memory "
- "to create object description");
- goto err;
- }
- arg = os_zalloc(sizeof(struct bss_handler_args));
- if (!arg) {
- wpa_printf(MSG_ERROR, "Not enough memory "
- "to create arguments for handler");
- goto err;
- }
- arg->wpa_s = wpa_s;
- arg->id = id;
- wpas_dbus_register(obj_desc, arg, wpa_dbus_free, NULL,
- wpas_dbus_bss_properties,
- wpas_dbus_bss_signals);
- wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
- bss_obj_path);
- if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
- wpa_s->ifname, obj_desc)) {
- wpa_printf(MSG_ERROR,
- "Cannot register BSSID dbus object %s.",
- bss_obj_path);
- goto err;
- }
- wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
- os_free(bss_obj_path);
- return 0;
- err:
- os_free(bss_obj_path);
- os_free(obj_desc);
- os_free(arg);
- return -1;
- }
- static const struct wpas_dbus_method wpas_dbus_interface_methods[] = {
- { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) &wpas_dbus_handler_scan,
- {
- { "args", "a{sv}", ARG_IN },
- END_ARGS
- }
- },
- { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) &wpas_dbus_handler_disconnect,
- {
- END_ARGS
- }
- },
- { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) &wpas_dbus_handler_add_network,
- {
- { "args", "a{sv}", ARG_IN },
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) &wpas_dbus_handler_remove_network,
- {
- { "path", "o", ARG_IN },
- END_ARGS
- }
- },
- { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) &wpas_dbus_handler_select_network,
- {
- { "path", "o", ARG_IN },
- END_ARGS
- }
- },
- { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) &wpas_dbus_handler_add_blob,
- {
- { "name", "s", ARG_IN },
- { "data", "ay", ARG_IN },
- END_ARGS
- }
- },
- { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) &wpas_dbus_handler_get_blob,
- {
- { "name", "s", ARG_IN },
- { "data", "ay", ARG_OUT },
- END_ARGS
- }
- },
- { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
- (WPADBusMethodHandler) &wpas_dbus_handler_remove_blob,
- {
- { "name", "s", ARG_IN },
- END_ARGS
- }
- },
- #ifdef CONFIG_WPS
- { "Start", WPAS_DBUS_NEW_IFACE_WPS,
- (WPADBusMethodHandler) &wpas_dbus_handler_wps_start,
- {
- { "args", "a{sv}", ARG_IN },
- { "output", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- #endif /* CONFIG_WPS */
- { NULL, NULL, NULL, { END_ARGS } }
- };
- static const struct wpas_dbus_property wpas_dbus_interface_properties[] = {
- { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
- (WPADBusPropertyAccessor) wpas_dbus_getter_capabilities,
- NULL, R
- },
- { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
- (WPADBusPropertyAccessor) wpas_dbus_getter_state,
- NULL, R
- },
- { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
- (WPADBusPropertyAccessor) wpas_dbus_getter_scanning,
- NULL, R
- },
- { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
- (WPADBusPropertyAccessor) wpas_dbus_getter_ap_scan,
- (WPADBusPropertyAccessor) wpas_dbus_setter_ap_scan,
- RW
- },
- { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
- (WPADBusPropertyAccessor) wpas_dbus_getter_ifname,
- NULL, R
- },
- { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
- (WPADBusPropertyAccessor) wpas_dbus_getter_driver,
- NULL, R
- },
- { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
- (WPADBusPropertyAccessor) wpas_dbus_getter_bridge_ifname,
- NULL, R
- },
- { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
- (WPADBusPropertyAccessor) wpas_dbus_getter_current_bss,
- NULL, R
- },
- { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
- (WPADBusPropertyAccessor) wpas_dbus_getter_current_network,
- NULL, R
- },
- { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
- (WPADBusPropertyAccessor) wpas_dbus_getter_blobs,
- NULL, R
- },
- { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
- (WPADBusPropertyAccessor) wpas_dbus_getter_bsss,
- NULL, R
- },
- { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
- (WPADBusPropertyAccessor) wpas_dbus_getter_networks,
- NULL, R
- },
- #ifdef CONFIG_WPS
- { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
- (WPADBusPropertyAccessor) wpas_dbus_getter_process_credentials,
- (WPADBusPropertyAccessor) wpas_dbus_setter_process_credentials,
- RW
- },
- #endif /* CONFIG_WPS */
- { NULL, NULL, NULL, NULL, NULL, 0 }
- };
- static const struct wpas_dbus_signal wpas_dbus_interface_signals[] = {
- { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "success", "b", ARG_OUT },
- END_ARGS
- }
- },
- { "StateChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "newState", "s", ARG_OUT },
- { "oldState", "s", ARG_OUT },
- END_ARGS
- }
- },
- { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "path", "o", ARG_OUT },
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "name", "s", ARG_OUT },
- END_ARGS
- }
- },
- { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "name", "s", ARG_OUT },
- END_ARGS
- }
- },
- { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "path", "o", ARG_OUT },
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "path", "o", ARG_OUT },
- END_ARGS
- }
- },
- { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
- {
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- #ifdef CONFIG_WPS
- { "Event", WPAS_DBUS_NEW_IFACE_WPS,
- {
- { "name", "s", ARG_OUT },
- { "args", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
- {
- { "credentials", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
- {
- { "properties", "a{sv}", ARG_OUT },
- END_ARGS
- }
- },
- #endif /* CONFIG_WPS */
- { NULL, NULL, { END_ARGS } }
- };
- int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
- {
- struct wpa_dbus_object_desc *obj_desc = NULL;
- struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
- int next;
- /* Do nothing if the control interface is not turned on */
- if (ctrl_iface == NULL)
- return 0;
- /* Create and set the interface's object path */
- wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
- if (wpa_s->dbus_new_path == NULL)
- return -1;
- next = ctrl_iface->next_objid++;
- os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
- WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
- next);
- obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
- if (!obj_desc) {
- wpa_printf(MSG_ERROR, "Not enough memory "
- "to create object description");
- goto err;
- }
- wpas_dbus_register(obj_desc, wpa_s, NULL, wpas_dbus_interface_methods,
- wpas_dbus_interface_properties,
- wpas_dbus_interface_signals);
- wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
- wpa_s->dbus_new_path);
- if (wpa_dbus_register_object_per_iface(ctrl_iface,
- wpa_s->dbus_new_path,
- wpa_s->ifname, obj_desc))
- goto err;
- wpas_dbus_signal_interface_added(wpa_s);
- return 0;
- err:
- os_free(wpa_s->dbus_new_path);
- wpa_s->dbus_new_path = NULL;
- os_free(obj_desc);
- return -1;
- }
- int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
- {
- struct wpas_dbus_priv *ctrl_iface;
- /* Do nothing if the control interface is not turned on */
- if (wpa_s == NULL || wpa_s->global == NULL)
- return 0;
- ctrl_iface = wpa_s->global->dbus;
- if (ctrl_iface == NULL)
- return 0;
- wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
- wpa_s->dbus_new_path);
- if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
- wpa_s->dbus_new_path))
- return -1;
- wpas_dbus_signal_interface_removed(wpa_s);
- os_free(wpa_s->dbus_new_path);
- wpa_s->dbus_new_path = NULL;
- return 0;
- }
|