dbus_new.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724
  1. /*
  2. * WPA Supplicant / dbus-based control interface
  3. * Copyright (c) 2006, Dan Williams <dcbw@redhat.com> and Red Hat, Inc.
  4. * Copyright (c) 2009, Witold Sowa <witold.sowa@gmail.com>
  5. * Copyright (c) 2009, Jouni Malinen <j@w1.fi>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Alternatively, this software may be distributed under the terms of BSD
  12. * license.
  13. *
  14. * See README and COPYING for more details.
  15. */
  16. #include "includes.h"
  17. #include "common.h"
  18. #include "wps/wps.h"
  19. #include "../config.h"
  20. #include "../wpa_supplicant_i.h"
  21. #include "../bss.h"
  22. #include "dbus_new_helpers.h"
  23. #include "dbus_dict_helpers.h"
  24. #include "dbus_new.h"
  25. #include "dbus_new_handlers.h"
  26. #include "dbus_common.h"
  27. #include "dbus_common_i.h"
  28. /**
  29. * wpas_dbus_set_path - Assign a dbus path to an interface
  30. * @wpa_s: wpa_supplicant interface structure
  31. * @path: dbus path to set on the interface
  32. * Returns: 0 on success, -1 on error
  33. */
  34. static int wpas_dbus_set_path(struct wpa_supplicant *wpa_s,
  35. const char *path)
  36. {
  37. u32 len = os_strlen(path);
  38. if (len >= WPAS_DBUS_OBJECT_PATH_MAX)
  39. return -1;
  40. if (wpa_s->dbus_new_path)
  41. return -1;
  42. wpa_s->dbus_new_path = os_strdup(path);
  43. return 0;
  44. }
  45. /**
  46. * wpas_dbus_signal_interface - Send a interface related event signal
  47. * @wpa_s: %wpa_supplicant network interface data
  48. * @sig_name: signal name - InterfaceAdded or InterfaceRemoved
  49. *
  50. * Notify listeners about event related with interface
  51. */
  52. static void wpas_dbus_signal_interface(struct wpa_supplicant *wpa_s,
  53. const char *sig_name)
  54. {
  55. struct wpas_dbus_priv *iface;
  56. DBusMessage *_signal;
  57. const char *path;
  58. iface = wpa_s->global->dbus;
  59. /* Do nothing if the control interface is not turned on */
  60. if (iface == NULL)
  61. return;
  62. path = wpas_dbus_get_path(wpa_s);
  63. if (path == NULL) {
  64. wpa_printf(MSG_ERROR, "wpas_dbus_signal_interface[dbus]: "
  65. "Interface doesn't have a dbus path. "
  66. "Can't send signal.");
  67. return;
  68. }
  69. _signal = dbus_message_new_signal(WPAS_DBUS_NEW_PATH,
  70. WPAS_DBUS_NEW_INTERFACE, sig_name);
  71. if (_signal == NULL) {
  72. wpa_printf(MSG_ERROR, "wpas_dbus_signal_interface[dbus]: "
  73. "enough memory to send scan results signal.");
  74. return;
  75. }
  76. if (dbus_message_append_args(_signal, DBUS_TYPE_OBJECT_PATH, &path,
  77. DBUS_TYPE_INVALID)) {
  78. dbus_connection_send(iface->con, _signal, NULL);
  79. } else {
  80. wpa_printf(MSG_ERROR, "wpas_dbus_signal_interface[dbus]: "
  81. "not enough memory to construct signal.");
  82. }
  83. dbus_message_unref(_signal);
  84. }
  85. /**
  86. * wpas_dbus_signal_interface_created - Send a interface created signal
  87. * @wpa_s: %wpa_supplicant network interface data
  88. *
  89. * Notify listeners about creating new interface
  90. */
  91. static void wpas_dbus_signal_interface_created(struct wpa_supplicant *wpa_s)
  92. {
  93. wpas_dbus_signal_interface(wpa_s, "InterfaceCreated");
  94. }
  95. /**
  96. * wpas_dbus_signal_interface_removed - Send a interface removed signal
  97. * @wpa_s: %wpa_supplicant network interface data
  98. *
  99. * Notify listeners about removing interface
  100. */
  101. static void wpas_dbus_signal_interface_removed(struct wpa_supplicant *wpa_s)
  102. {
  103. wpas_dbus_signal_interface(wpa_s, "InterfaceRemoved");
  104. }
  105. /**
  106. * wpas_dbus_signal_scan_done - send scan done signal
  107. * @wpa_s: %wpa_supplicant network interface data
  108. * @success: indicates if scanning succeed or failed
  109. *
  110. * Notify listeners about finishing a scan
  111. */
  112. static void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s,
  113. int success)
  114. {
  115. struct wpas_dbus_priv *iface;
  116. DBusMessage *_signal;
  117. const char *path;
  118. dbus_bool_t succ;
  119. iface = wpa_s->global->dbus;
  120. /* Do nothing if the control interface is not turned on */
  121. if (iface == NULL)
  122. return;
  123. path = wpas_dbus_get_path(wpa_s);
  124. if (path == NULL) {
  125. wpa_printf(MSG_ERROR, "wpas_dbus_signal_scan_done[dbus]: "
  126. "Interface doesn't have a dbus path. "
  127. "Can't send signal.");
  128. return;
  129. }
  130. _signal = dbus_message_new_signal(path, WPAS_DBUS_NEW_IFACE_INTERFACE,
  131. "ScanDone");
  132. if (_signal == NULL) {
  133. wpa_printf(MSG_ERROR, "wpas_dbus_signal_scan_done[dbus]: "
  134. "enough memory to send signal.");
  135. return;
  136. }
  137. succ = success ? TRUE : FALSE;
  138. if (dbus_message_append_args(_signal, DBUS_TYPE_BOOLEAN, &succ,
  139. DBUS_TYPE_INVALID)) {
  140. dbus_connection_send(iface->con, _signal, NULL);
  141. } else {
  142. wpa_printf(MSG_ERROR, "wpas_dbus_signal_scan_done[dbus]: "
  143. "not enough memory to construct signal.");
  144. }
  145. dbus_message_unref(_signal);
  146. }
  147. /**
  148. * wpas_dbus_signal_blob - Send a BSS related event signal
  149. * @wpa_s: %wpa_supplicant network interface data
  150. * @bss_obj_path: BSS object path
  151. * @sig_name: signal name - BSSAdded or BSSRemoved
  152. *
  153. * Notify listeners about event related with BSS
  154. */
  155. static void wpas_dbus_signal_bss(struct wpa_supplicant *wpa_s,
  156. const char *bss_obj_path,
  157. const char *sig_name)
  158. {
  159. struct wpas_dbus_priv *iface;
  160. DBusMessage *_signal;
  161. const char *path;
  162. iface = wpa_s->global->dbus;
  163. /* Do nothing if the control interface is not turned on */
  164. if (iface == NULL)
  165. return;
  166. path = wpas_dbus_get_path(wpa_s);
  167. if (path == NULL) {
  168. wpa_printf(MSG_ERROR, "wpas_dbus_signal_bss[dbus]: "
  169. "Interface doesn't have a dbus path. "
  170. "Can't send signal.");
  171. return;
  172. }
  173. _signal = dbus_message_new_signal(path, WPAS_DBUS_NEW_IFACE_INTERFACE,
  174. sig_name);
  175. if (_signal == NULL) {
  176. wpa_printf(MSG_ERROR, "wpas_dbus_signal_bss[dbus]: "
  177. "enough memory to send signal.");
  178. return;
  179. }
  180. if (dbus_message_append_args(_signal, DBUS_TYPE_OBJECT_PATH,
  181. &bss_obj_path, DBUS_TYPE_INVALID)) {
  182. dbus_connection_send(iface->con, _signal, NULL);
  183. } else {
  184. wpa_printf(MSG_ERROR, "wpas_dbus_signal_bss[dbus]: "
  185. "not enough memory to construct signal.");
  186. }
  187. dbus_message_unref(_signal);
  188. }
  189. /**
  190. * wpas_dbus_signal_bss_added - Send a BSS added signal
  191. * @wpa_s: %wpa_supplicant network interface data
  192. * @bss_obj_path: new BSS object path
  193. *
  194. * Notify listeners about adding new BSS
  195. */
  196. static void wpas_dbus_signal_bss_added(struct wpa_supplicant *wpa_s,
  197. const char *bss_obj_path)
  198. {
  199. wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSAdded");
  200. }
  201. /**
  202. * wpas_dbus_signal_bss_removed - Send a BSS removed signal
  203. * @wpa_s: %wpa_supplicant network interface data
  204. * @bss_obj_path: BSS object path
  205. *
  206. * Notify listeners about removing BSS
  207. */
  208. static void wpas_dbus_signal_bss_removed(struct wpa_supplicant *wpa_s,
  209. const char *bss_obj_path)
  210. {
  211. wpas_dbus_signal_bss(wpa_s, bss_obj_path, "BSSRemoved");
  212. }
  213. /**
  214. * wpas_dbus_signal_blob - Send a blob related event signal
  215. * @wpa_s: %wpa_supplicant network interface data
  216. * @name: blob name
  217. * @sig_name: signal name - BlobAdded or BlobRemoved
  218. *
  219. * Notify listeners about event related with blob
  220. */
  221. static void wpas_dbus_signal_blob(struct wpa_supplicant *wpa_s,
  222. const char *name, const char *sig_name)
  223. {
  224. struct wpas_dbus_priv *iface;
  225. DBusMessage *_signal;
  226. const char *path;
  227. iface = wpa_s->global->dbus;
  228. /* Do nothing if the control interface is not turned on */
  229. if (iface == NULL)
  230. return;
  231. path = wpas_dbus_get_path(wpa_s);
  232. if (path == NULL) {
  233. wpa_printf(MSG_ERROR, "wpas_dbus_signal_blob[dbus]: "
  234. "Interface doesn't have a dbus path. "
  235. "Can't send signal.");
  236. return;
  237. }
  238. _signal = dbus_message_new_signal(path, WPAS_DBUS_NEW_IFACE_INTERFACE,
  239. sig_name);
  240. if (_signal == NULL) {
  241. wpa_printf(MSG_ERROR, "wpas_dbus_signal_blob[dbus]: "
  242. "enough memory to send signal.");
  243. return;
  244. }
  245. if (dbus_message_append_args(_signal, DBUS_TYPE_STRING, &name,
  246. DBUS_TYPE_INVALID)) {
  247. dbus_connection_send(iface->con, _signal, NULL);
  248. } else {
  249. wpa_printf(MSG_ERROR, "wpas_dbus_signal_blob[dbus]: "
  250. "not enough memory to construct signal.");
  251. }
  252. dbus_message_unref(_signal);
  253. }
  254. /**
  255. * wpas_dbus_signal_blob_added - Send a blob added signal
  256. * @wpa_s: %wpa_supplicant network interface data
  257. * @name: blob name
  258. *
  259. * Notify listeners about adding a new blob
  260. */
  261. static void wpas_dbus_signal_blob_added(struct wpa_supplicant *wpa_s,
  262. const char *name)
  263. {
  264. wpas_dbus_signal_blob(wpa_s, name, "BlobAdded");
  265. }
  266. /**
  267. * wpas_dbus_signal_blob_removed - Send a blob removed signal
  268. * @wpa_s: %wpa_supplicant network interface data
  269. * @name: blob name
  270. *
  271. * Notify listeners about removing blob
  272. */
  273. static void wpas_dbus_signal_blob_removed(struct wpa_supplicant *wpa_s,
  274. const char *name)
  275. {
  276. wpas_dbus_signal_blob(wpa_s, name, "BlobRemoved");
  277. }
  278. /**
  279. * wpas_dbus_signal_network - Send a network related event signal
  280. * @wpa_s: %wpa_supplicant network interface data
  281. * @id: new network id
  282. * @sig_name: signal name - NetworkAdded, NetworkRemoved or NetworkSelected
  283. *
  284. * Notify listeners about event related with configured network
  285. */
  286. static void wpas_dbus_signal_network(struct wpa_supplicant *wpa_s,
  287. int id, const char *sig_name)
  288. {
  289. struct wpas_dbus_priv *iface;
  290. DBusMessage *_signal;
  291. const char *path;
  292. char *net_obj_path;
  293. iface = wpa_s->global->dbus;
  294. /* Do nothing if the control interface is not turned on */
  295. if (iface == NULL)
  296. return;
  297. path = wpas_dbus_get_path(wpa_s);
  298. if (path == NULL) {
  299. wpa_printf(MSG_ERROR, "wpas_dbus_signal_network[dbus]: "
  300. "Interface doesn't have a dbus path. "
  301. "Can't send signal.");
  302. return;
  303. }
  304. net_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  305. if (net_obj_path == NULL)
  306. return;
  307. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  308. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u", path, id);
  309. _signal = dbus_message_new_signal(path, WPAS_DBUS_NEW_IFACE_INTERFACE,
  310. sig_name);
  311. if (_signal == NULL) {
  312. wpa_printf(MSG_ERROR, "wpas_dbus_signal_network[dbus]: "
  313. "enough memory to send signal.");
  314. os_free(net_obj_path);
  315. return;
  316. }
  317. if (dbus_message_append_args(_signal, DBUS_TYPE_OBJECT_PATH,
  318. &net_obj_path, DBUS_TYPE_INVALID)) {
  319. dbus_connection_send(iface->con, _signal, NULL);
  320. } else {
  321. wpa_printf(MSG_ERROR, "wpas_dbus_signal_network[dbus]: "
  322. "not enough memory to construct signal.");
  323. }
  324. os_free(net_obj_path);
  325. dbus_message_unref(_signal);
  326. }
  327. /**
  328. * wpas_dbus_signal_network_added - Send a network added signal
  329. * @wpa_s: %wpa_supplicant network interface data
  330. * @id: new network id
  331. *
  332. * Notify listeners about adding new network
  333. */
  334. static void wpas_dbus_signal_network_added(struct wpa_supplicant *wpa_s,
  335. int id)
  336. {
  337. wpas_dbus_signal_network(wpa_s, id, "NetworkAdded");
  338. }
  339. /**
  340. * wpas_dbus_signal_network_removed - Send a network removed signal
  341. * @wpa_s: %wpa_supplicant network interface data
  342. * @id: network id
  343. *
  344. * Notify listeners about removing a network
  345. */
  346. static void wpas_dbus_signal_network_removed(struct wpa_supplicant *wpa_s,
  347. int id)
  348. {
  349. wpas_dbus_signal_network(wpa_s, id, "NetworkRemoved");
  350. }
  351. /**
  352. * wpas_dbus_signal_network_selected - Send a network selected signal
  353. * @wpa_s: %wpa_supplicant network interface data
  354. * @id: network id
  355. *
  356. * Notify listeners about selecting a network
  357. */
  358. static void wpas_dbus_signal_network_selected(struct wpa_supplicant *wpa_s,
  359. int id)
  360. {
  361. wpas_dbus_signal_network(wpa_s, id, "NetworkSelected");
  362. }
  363. /**
  364. * wpas_dbus_signal_state_changed - Send a state changed signal
  365. * @wpa_s: %wpa_supplicant network interface data
  366. * @new_state: new state wpa_supplicant is entering
  367. * @old_state: old state wpa_supplicant is leaving
  368. *
  369. * Notify listeners that wpa_supplicant has changed state
  370. */
  371. static void wpas_dbus_signal_state_changed(struct wpa_supplicant *wpa_s,
  372. enum wpa_states new_state,
  373. enum wpa_states old_state)
  374. {
  375. struct wpas_dbus_priv *iface;
  376. DBusMessage *_signal = NULL;
  377. const char *path;
  378. char *new_state_str, *old_state_str;
  379. char *tmp;
  380. /* Do nothing if the control interface is not turned on */
  381. if (wpa_s->global == NULL)
  382. return;
  383. iface = wpa_s->global->dbus;
  384. if (iface == NULL)
  385. return;
  386. /* Only send signal if state really changed */
  387. if (new_state == old_state)
  388. return;
  389. path = wpas_dbus_get_path(wpa_s);
  390. if (path == NULL) {
  391. perror("wpas_dbus_signal_state_changed[dbus]: "
  392. "interface didn't have a dbus path");
  393. wpa_printf(MSG_ERROR,
  394. "wpas_dbus_signal_state_changed[dbus]: "
  395. "interface didn't have a dbus path; can't send "
  396. "signal.");
  397. return;
  398. }
  399. _signal = dbus_message_new_signal(path, WPAS_DBUS_NEW_IFACE_INTERFACE,
  400. "StateChanged");
  401. if (_signal == NULL) {
  402. perror("wpas_dbus_signal_state_changed[dbus]: "
  403. "couldn't create dbus signal; likely out of memory");
  404. wpa_printf(MSG_ERROR,
  405. "wpas_dbus_signal_state_changed[dbus]: "
  406. "couldn't create dbus signal; likely out of "
  407. "memory.");
  408. return;
  409. }
  410. new_state_str = os_strdup(wpa_supplicant_state_txt(new_state));
  411. old_state_str = os_strdup(wpa_supplicant_state_txt(old_state));
  412. if (new_state_str == NULL || old_state_str == NULL) {
  413. perror("wpas_dbus_signal_state_changed[dbus]: "
  414. "couldn't convert state strings");
  415. wpa_printf(MSG_ERROR,
  416. "wpas_dbus_signal_state_changed[dbus]: "
  417. "couldn't convert state strings.");
  418. goto out;
  419. }
  420. /* make state string lowercase to fit new DBus API convention */
  421. tmp = new_state_str;
  422. while (*tmp) {
  423. *tmp = tolower(*tmp);
  424. tmp++;
  425. }
  426. tmp = old_state_str;
  427. while (*tmp) {
  428. *tmp = tolower(*tmp);
  429. tmp++;
  430. }
  431. if (!dbus_message_append_args(_signal,
  432. DBUS_TYPE_STRING, &new_state_str,
  433. DBUS_TYPE_STRING, &old_state_str,
  434. DBUS_TYPE_INVALID)) {
  435. perror("wpas_dbus_signal_state_changed[dbus]: "
  436. "not enough memory to construct state change signal.");
  437. wpa_printf(MSG_ERROR,
  438. "wpas_dbus_signal_state_changed[dbus]: "
  439. "not enough memory to construct state change "
  440. "signal.");
  441. goto out;
  442. }
  443. dbus_connection_send(iface->con, _signal, NULL);
  444. out:
  445. dbus_message_unref(_signal);
  446. os_free(new_state_str);
  447. os_free(old_state_str);
  448. }
  449. /**
  450. * wpas_dbus_signal_network_enabled_changed - Signals Enabled property changes
  451. * @wpa_s: %wpa_supplicant network interface data
  452. * @ssid: configured network which Enabled property has changed
  453. *
  454. * Sends PropertyChanged signals containing new value of Enabled property
  455. * for specified network
  456. */
  457. static void wpas_dbus_signal_network_enabled_changed(
  458. struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
  459. {
  460. struct network_handler_args args = {wpa_s, ssid};
  461. char path[WPAS_DBUS_OBJECT_PATH_MAX];
  462. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  463. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
  464. wpas_dbus_get_path(wpa_s), ssid->id);
  465. wpa_dbus_signal_property_changed(wpa_s->global->dbus,
  466. (WPADBusPropertyAccessor)
  467. wpas_dbus_getter_enabled, &args,
  468. path, WPAS_DBUS_NEW_IFACE_NETWORK,
  469. "Enabled");
  470. }
  471. #ifdef CONFIG_WPS
  472. /**
  473. * wpas_dbus_signal_wps_event_success - Signals Success WPS event
  474. * @wpa_s: %wpa_supplicant network interface data
  475. *
  476. * Sends Event dbus signal with name "success" and empty dict as arguments
  477. */
  478. static void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s)
  479. {
  480. DBusMessage *_signal = NULL;
  481. DBusMessageIter iter, dict_iter;
  482. struct wpas_dbus_priv *iface;
  483. char *key = "success";
  484. const char *path;
  485. iface = wpa_s->global->dbus;
  486. /* Do nothing if the control interface is not turned on */
  487. if (iface == NULL)
  488. return;
  489. path = wpas_dbus_get_path(wpa_s);
  490. if (!path) {
  491. wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_event_success"
  492. "[dbus]: interface has no dbus path set");
  493. return;
  494. }
  495. _signal = dbus_message_new_signal(path, WPAS_DBUS_NEW_IFACE_WPS,
  496. "Event");
  497. if (!_signal) {
  498. wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_event_success"
  499. "[dbus]: out of memory when creating a signal");
  500. return;
  501. }
  502. dbus_message_iter_init_append(_signal, &iter);
  503. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  504. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  505. !wpa_dbus_dict_close_write(&iter, &dict_iter)) {
  506. wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_event_success"
  507. "[dbus]: out of memory");
  508. goto out;
  509. }
  510. dbus_connection_send(iface->con, _signal, NULL);
  511. out:
  512. dbus_message_unref(_signal);
  513. }
  514. /**
  515. * wpas_dbus_signal_wps_event_fail - Signals Fail WPS event
  516. * @wpa_s: %wpa_supplicant network interface data
  517. *
  518. * Sends Event dbus signal with name "fail" and dictionary containing
  519. * "msg field with fail message number (int32) as arguments
  520. */
  521. static void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
  522. struct wps_event_fail *fail)
  523. {
  524. DBusMessage *_signal = NULL;
  525. DBusMessageIter iter, dict_iter;
  526. struct wpas_dbus_priv *iface;
  527. char *key = "fail";
  528. const char *path;
  529. iface = wpa_s->global->dbus;
  530. /* Do nothing if the control interface is not turned on */
  531. if (iface == NULL)
  532. return;
  533. path = wpas_dbus_get_path(wpa_s);
  534. if (!path) {
  535. wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_event_fail[dbus]: "
  536. "interface has no dbus path set");
  537. return;
  538. }
  539. _signal = dbus_message_new_signal(path, WPAS_DBUS_NEW_IFACE_WPS,
  540. "Event");
  541. if (!_signal) {
  542. wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_event_fail[dbus]: "
  543. "out of memory when creating a signal");
  544. return;
  545. }
  546. dbus_message_iter_init_append(_signal, &iter);
  547. if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
  548. !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
  549. !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
  550. !wpa_dbus_dict_close_write(&iter, &dict_iter)) {
  551. wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_event_fail[dbus]: "
  552. "out of memory");
  553. goto out;
  554. }
  555. dbus_connection_send(iface->con, _signal, NULL);
  556. out:
  557. dbus_message_unref(_signal);
  558. }
  559. /**
  560. * wpas_dbus_signal_wps_event_m2d - Signals M2D WPS event
  561. * @wpa_s: %wpa_supplicant network interface data
  562. *
  563. * Sends Event dbus signal with name "m2d" and dictionary containing
  564. * fields of wps_event_m2d structure.
  565. */
  566. static void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
  567. struct wps_event_m2d *m2d)
  568. {
  569. DBusMessage *_signal = NULL;
  570. DBusMessageIter iter, dict_iter;
  571. struct wpas_dbus_priv *iface;
  572. char *key = "m2d";
  573. const char *path;
  574. iface = wpa_s->global->dbus;
  575. /* Do nothing if the control interface is not turned on */
  576. if (iface == NULL)
  577. return;
  578. path = wpas_dbus_get_path(wpa_s);
  579. if (!path) {
  580. wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_event_m2d[dbus]: "
  581. "interface has no dbus path set");
  582. return;
  583. }
  584. _signal = dbus_message_new_signal(path, WPAS_DBUS_NEW_IFACE_WPS,
  585. "Event");
  586. if (!_signal) {
  587. wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_event_m2d[dbus]: "
  588. "out of memory when creating a signal");
  589. return;
  590. }
  591. dbus_message_iter_init_append(_signal, &iter);
  592. if (!(dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) &&
  593. wpa_dbus_dict_open_write(&iter, &dict_iter) &&
  594. wpa_dbus_dict_append_uint16(&dict_iter, "config_methods",
  595. m2d->config_methods) &&
  596. wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer",
  597. (const char *) m2d->manufacturer,
  598. m2d->manufacturer_len) &&
  599. wpa_dbus_dict_append_byte_array(&dict_iter, "model_name",
  600. (const char *) m2d->model_name,
  601. m2d->model_name_len) &&
  602. wpa_dbus_dict_append_byte_array(&dict_iter, "model_number",
  603. (const char *) m2d->model_number,
  604. m2d->model_number_len) &&
  605. wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number",
  606. (const char *)
  607. m2d->serial_number,
  608. m2d->serial_number_len) &&
  609. wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name",
  610. (const char *) m2d->dev_name,
  611. m2d->dev_name_len) &&
  612. wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type",
  613. (const char *)
  614. m2d->primary_dev_type, 8) &&
  615. wpa_dbus_dict_append_uint16(&dict_iter, "config_error",
  616. m2d->config_error) &&
  617. wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id",
  618. m2d->dev_password_id) &&
  619. wpa_dbus_dict_close_write(&iter, &dict_iter))) {
  620. wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_event_m2d[dbus]: "
  621. "out of memory");
  622. goto out;
  623. }
  624. dbus_connection_send(iface->con, _signal, NULL);
  625. out:
  626. dbus_message_unref(_signal);
  627. }
  628. /**
  629. * wpas_dbus_signal_wps_cred - Signals new credentials
  630. * @wpa_s: %wpa_supplicant network interface data
  631. *
  632. * Sends signal with credentials in directory argument
  633. */
  634. static void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
  635. const struct wps_credential *cred)
  636. {
  637. DBusMessage *_signal = NULL;
  638. DBusMessageIter iter, dict_iter;
  639. struct wpas_dbus_priv *iface;
  640. const char *path;
  641. char *auth_type[6]; /* we have six possible authorization types */
  642. int at_num = 0;
  643. char *encr_type[4]; /* we have four possible encryption types */
  644. int et_num = 0;
  645. iface = wpa_s->global->dbus;
  646. /* Do nothing if the control interface is not turned on */
  647. if (iface == NULL)
  648. return;
  649. path = wpas_dbus_get_path(wpa_s);
  650. if (!path) {
  651. wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_cred[dbus]: "
  652. "interface has no dbus path set");
  653. return;
  654. }
  655. _signal = dbus_message_new_signal(path, WPAS_DBUS_NEW_IFACE_WPS,
  656. "Credentials");
  657. if (!_signal) {
  658. wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_cred[dbus]: "
  659. "out of memory when creating a signal");
  660. return;
  661. }
  662. dbus_message_iter_init_append(_signal, &iter);
  663. if (!wpa_dbus_dict_open_write(&iter, &dict_iter)) {
  664. perror("wpas_dbus_signal_wps_cred[dbus]: out of memory "
  665. "when opening a dictionary");
  666. goto nomem;
  667. }
  668. if (cred->auth_type & WPS_AUTH_OPEN)
  669. auth_type[at_num++] = "open";
  670. if (cred->auth_type & WPS_AUTH_WPAPSK)
  671. auth_type[at_num++] = "wpa-psk";
  672. if (cred->auth_type & WPS_AUTH_SHARED)
  673. auth_type[at_num++] = "shared";
  674. if (cred->auth_type & WPS_AUTH_WPA)
  675. auth_type[at_num++] = "wpa-eap";
  676. if (cred->auth_type & WPS_AUTH_WPA2)
  677. auth_type[at_num++] = "wpa2-eap";
  678. if (cred->auth_type & WPS_AUTH_WPA2PSK)
  679. auth_type[at_num++] =
  680. "wpa2-psk";
  681. if (cred->encr_type & WPS_ENCR_NONE)
  682. encr_type[et_num++] = "none";
  683. if (cred->encr_type & WPS_ENCR_WEP)
  684. encr_type[et_num++] = "wep";
  685. if (cred->encr_type & WPS_ENCR_TKIP)
  686. encr_type[et_num++] = "tkip";
  687. if (cred->encr_type & WPS_ENCR_AES)
  688. encr_type[et_num++] = "aes";
  689. if (wpa_s->current_ssid) {
  690. if (!wpa_dbus_dict_append_byte_array(
  691. &dict_iter, "BSSID",
  692. (const char *) wpa_s->current_ssid->bssid,
  693. ETH_ALEN)) {
  694. perror("wpas_dbus_signal_wps_cred[dbus]: out of "
  695. "memory when appending bssid to dictionary");
  696. goto nomem;
  697. }
  698. }
  699. if (!(wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
  700. (const char *) cred->ssid,
  701. cred->ssid_len) &&
  702. wpa_dbus_dict_append_string_array(&dict_iter, "AuthType",
  703. (const char **) auth_type,
  704. at_num) &&
  705. wpa_dbus_dict_append_string_array(&dict_iter, "EncrType",
  706. (const char **) encr_type,
  707. et_num) &&
  708. wpa_dbus_dict_append_byte_array(&dict_iter, "Key",
  709. (const char *) cred->key,
  710. cred->key_len) &&
  711. wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex",
  712. cred->key_idx))) {
  713. perror("wpas_dbus_signal_wps_cred[dbus]: out of memory "
  714. "when appending to dictionary");
  715. goto nomem;
  716. }
  717. if (!wpa_dbus_dict_close_write(&iter, &dict_iter)) {
  718. perror("wpas_dbus_signal_wps_cred[dbus]: out of memory "
  719. "when closing a dictionary");
  720. goto nomem;
  721. }
  722. dbus_connection_send(iface->con, _signal, NULL);
  723. nomem:
  724. dbus_message_unref(_signal);
  725. }
  726. #endif /* CONFIG_WPS */
  727. /**
  728. * wpas_dbus_signal_prop_changed - Signals change of property
  729. * @wpa_s: %wpa_supplicant network interface data
  730. * @property: indicates which property has changed
  731. *
  732. * Sends ProertyChanged signals with path, interface and arguments
  733. * depending on which property has changed.
  734. */
  735. static void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
  736. enum wpas_dbus_prop property)
  737. {
  738. WPADBusPropertyAccessor getter;
  739. char *iface;
  740. char *prop;
  741. void *arg;
  742. switch (property) {
  743. case WPAS_DBUS_PROP_AP_SCAN:
  744. getter = (WPADBusPropertyAccessor) wpas_dbus_getter_ap_scan;
  745. arg = wpa_s;
  746. iface = WPAS_DBUS_NEW_IFACE_INTERFACE;
  747. prop = "ApScan";
  748. break;
  749. case WPAS_DBUS_PROP_SCANNING:
  750. getter = (WPADBusPropertyAccessor) wpas_dbus_getter_scanning;
  751. arg = wpa_s;
  752. iface = WPAS_DBUS_NEW_IFACE_INTERFACE;
  753. prop = "Scanning";
  754. break;
  755. case WPAS_DBUS_PROP_CURRENT_BSS:
  756. getter = (WPADBusPropertyAccessor)
  757. wpas_dbus_getter_current_bss;
  758. arg = wpa_s;
  759. iface = WPAS_DBUS_NEW_IFACE_INTERFACE;
  760. prop = "CurrentBSS";
  761. break;
  762. case WPAS_DBUS_PROP_CURRENT_NETWORK:
  763. getter = (WPADBusPropertyAccessor)
  764. wpas_dbus_getter_current_network;
  765. arg = wpa_s;
  766. iface = WPAS_DBUS_NEW_IFACE_INTERFACE;
  767. prop = "CurrentNetwork";
  768. break;
  769. default:
  770. wpa_printf(MSG_ERROR, "wpas_dbus_signal_prop_changed[dbus]: "
  771. "Unknown Property enum value %d", property);
  772. return;
  773. }
  774. wpa_dbus_signal_property_changed(wpa_s->global->dbus,
  775. getter, arg,
  776. wpas_dbus_get_path(wpa_s), iface,
  777. prop);
  778. }
  779. /**
  780. * wpas_dbus_signal_debug_params_changed - Signals change of debug params
  781. * @global: wpa_global structure
  782. *
  783. * Sends ProertyChanged signals informing that debug params has changed.
  784. */
  785. static void wpas_dbus_signal_debug_params_changed(struct wpa_global *global)
  786. {
  787. wpa_dbus_signal_property_changed(global->dbus,
  788. (WPADBusPropertyAccessor)
  789. wpas_dbus_getter_debug_params,
  790. global, WPAS_DBUS_NEW_PATH,
  791. WPAS_DBUS_NEW_INTERFACE,
  792. "DebugParams");
  793. }
  794. struct wpas_dbus_method {
  795. const char *name;
  796. const char *iface;
  797. WPADBusMethodHandler handler;
  798. struct wpa_dbus_argument args[3];
  799. };
  800. struct wpas_dbus_property {
  801. const char *name;
  802. const char *iface;
  803. const char *type;
  804. WPADBusPropertyAccessor getter;
  805. WPADBusPropertyAccessor setter;
  806. enum dbus_prop_access _access;
  807. };
  808. struct wpas_dbus_signal {
  809. const char *name;
  810. const char *iface;
  811. struct wpa_dbus_argument args[3];
  812. };
  813. static void wpas_dbus_register(struct wpa_dbus_object_desc *obj_desc,
  814. void *priv,
  815. const struct wpas_dbus_method *methods,
  816. const struct wpas_dbus_property *properties,
  817. const struct wpas_dbus_signal *signals)
  818. {
  819. int i;
  820. for (i = 0; methods && methods[i].name; i++) {
  821. wpa_dbus_method_register(obj_desc, methods[i].iface,
  822. methods[i].name, methods[i].handler,
  823. priv, NULL, methods[i].args);
  824. }
  825. for (i = 0; properties && properties[i].name; i++) {
  826. wpa_dbus_property_register(obj_desc, properties[i].iface,
  827. properties[i].name,
  828. properties[i].type,
  829. properties[i].getter,
  830. properties[i].setter,
  831. priv, NULL, properties[i]._access);
  832. }
  833. for (i = 0; signals && signals[i].name; i++) {
  834. wpa_dbus_signal_register(obj_desc, signals[i].iface,
  835. signals[i].name, signals[i].args);
  836. }
  837. }
  838. static const struct wpas_dbus_method wpas_dbus_global_methods[] = {
  839. { "CreateInterface", WPAS_DBUS_NEW_INTERFACE,
  840. (WPADBusMethodHandler) &wpas_dbus_handler_create_interface,
  841. {
  842. { "args", "a{sv}", ARG_IN },
  843. { "path", "o", ARG_OUT },
  844. END_ARGS
  845. }
  846. },
  847. { "RemoveInterface", WPAS_DBUS_NEW_INTERFACE,
  848. (WPADBusMethodHandler) &wpas_dbus_handler_remove_interface,
  849. {
  850. { "path", "o", ARG_IN },
  851. END_ARGS
  852. }
  853. },
  854. { "GetInterface", WPAS_DBUS_NEW_INTERFACE,
  855. (WPADBusMethodHandler) &wpas_dbus_handler_get_interface,
  856. {
  857. { "ifname", "s", ARG_IN },
  858. { "path", "o", ARG_OUT },
  859. END_ARGS
  860. }
  861. },
  862. { NULL, NULL, NULL, { END_ARGS } }
  863. };
  864. static const struct wpas_dbus_property wpas_dbus_global_properties[] = {
  865. { "DebugParams", WPAS_DBUS_NEW_INTERFACE, "(ibb)",
  866. (WPADBusPropertyAccessor) &wpas_dbus_getter_debug_params,
  867. (WPADBusPropertyAccessor) &wpas_dbus_setter_debug_params,
  868. RW
  869. },
  870. { "Interfaces", WPAS_DBUS_NEW_INTERFACE, "ao",
  871. (WPADBusPropertyAccessor) &wpas_dbus_getter_interfaces,
  872. NULL,
  873. R
  874. },
  875. { "EapMethods", WPAS_DBUS_NEW_INTERFACE, "as",
  876. wpas_dbus_getter_eap_methods,
  877. NULL,
  878. R
  879. },
  880. { NULL, NULL, NULL, NULL, NULL, 0 }
  881. };
  882. static const struct wpas_dbus_signal wpas_dbus_global_signals[] = {
  883. { "InterfaceAdded", WPAS_DBUS_NEW_INTERFACE,
  884. {
  885. { "path", "o", ARG_OUT },
  886. END_ARGS
  887. }
  888. },
  889. { "InterfaceRemoved", WPAS_DBUS_NEW_INTERFACE,
  890. {
  891. { "path", "o", ARG_OUT },
  892. END_ARGS
  893. }
  894. },
  895. { "PropertiesChanged", WPAS_DBUS_NEW_INTERFACE,
  896. {
  897. { "properties", "a{sv}", ARG_OUT },
  898. END_ARGS
  899. }
  900. },
  901. { NULL, NULL, { END_ARGS } }
  902. };
  903. /**
  904. * wpas_dbus_ctrl_iface_init - Initialize dbus control interface
  905. * @global: Pointer to global data from wpa_supplicant_init()
  906. * Returns: 0 on success or -1 on failure
  907. *
  908. * Initialize the dbus control interface for wpa_supplicantand and start
  909. * receiving commands from external programs over the bus.
  910. */
  911. int wpas_dbus_ctrl_iface_init(struct wpas_dbus_priv *priv)
  912. {
  913. struct wpa_dbus_object_desc *obj_desc;
  914. int ret;
  915. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  916. if (!obj_desc) {
  917. wpa_printf(MSG_ERROR, "Not enough memory "
  918. "to create object description");
  919. return -1;
  920. }
  921. wpas_dbus_register(obj_desc, priv->global, wpas_dbus_global_methods,
  922. wpas_dbus_global_properties,
  923. wpas_dbus_global_signals);
  924. wpa_printf(MSG_DEBUG, "dbus: Register D-Bus object '%s'",
  925. WPAS_DBUS_NEW_PATH);
  926. ret = wpa_dbus_ctrl_iface_init(priv, WPAS_DBUS_NEW_PATH,
  927. WPAS_DBUS_NEW_SERVICE,
  928. obj_desc);
  929. if (ret < 0)
  930. free_dbus_object_desc(obj_desc);
  931. return ret;
  932. }
  933. /**
  934. * wpas_dbus_ctrl_iface_deinit - Deinitialize dbus ctrl interface for
  935. * wpa_supplicant
  936. * @iface: Pointer to dbus private data from wpas_dbus_init()
  937. *
  938. * Deinitialize the dbus control interface that was initialized with
  939. * wpas_dbus_ctrl_iface_init().
  940. */
  941. void wpas_dbus_ctrl_iface_deinit(struct wpas_dbus_priv *iface)
  942. {
  943. wpa_printf(MSG_DEBUG, "dbus: Unregister D-Bus object '%s'",
  944. WPAS_DBUS_NEW_PATH);
  945. dbus_connection_unregister_object_path(iface->con,
  946. WPAS_DBUS_NEW_PATH);
  947. }
  948. static void wpa_dbus_free(void *ptr)
  949. {
  950. os_free(ptr);
  951. }
  952. /**
  953. * wpas_dbus_register_network - Register a configured network with dbus
  954. * @wpa_s: wpa_supplicant interface structure
  955. * @ssid: network configuration data
  956. * Returns: 0 on success, -1 on failure
  957. *
  958. * Registers network representing object with dbus
  959. */
  960. static int wpas_dbus_register_network(struct wpa_supplicant *wpa_s,
  961. struct wpa_ssid *ssid)
  962. {
  963. struct wpas_dbus_priv *ctrl_iface;
  964. struct wpa_dbus_object_desc *obj_desc;
  965. struct network_handler_args *arg1 = NULL;
  966. struct network_handler_args *arg2 = NULL;
  967. char *net_obj_path;
  968. struct wpa_dbus_argument sargs[] = {
  969. { "properties", "a{sv}", ARG_OUT },
  970. END_ARGS
  971. };
  972. /* Do nothing if the control interface is not turned on */
  973. if (wpa_s == NULL || wpa_s->global == NULL)
  974. return 0;
  975. ctrl_iface = wpa_s->global->dbus;
  976. if (ctrl_iface == NULL)
  977. return 0;
  978. net_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  979. if (net_obj_path == NULL)
  980. return -1;
  981. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  982. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  983. wpas_dbus_get_path(wpa_s), ssid->id);
  984. wpa_printf(MSG_DEBUG, "dbus: Register network object '%s'",
  985. net_obj_path);
  986. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  987. if (!obj_desc) {
  988. wpa_printf(MSG_ERROR, "Not enough memory "
  989. "to create object description");
  990. goto err;
  991. }
  992. /* allocate memory for handlers arguments */
  993. arg1 = os_zalloc(sizeof(struct network_handler_args));
  994. if (!arg1) {
  995. wpa_printf(MSG_ERROR, "Not enough memory "
  996. "to create arguments for method");
  997. goto err;
  998. }
  999. arg2 = os_zalloc(sizeof(struct network_handler_args));
  1000. if (!arg2) {
  1001. wpa_printf(MSG_ERROR, "Not enough memory "
  1002. "to create arguments for method");
  1003. goto err;
  1004. }
  1005. arg1->wpa_s = wpa_s;
  1006. arg1->ssid = ssid;
  1007. arg2->wpa_s = wpa_s;
  1008. arg2->ssid = ssid;
  1009. /* Enabled property */
  1010. wpa_dbus_property_register(obj_desc, WPAS_DBUS_NEW_IFACE_NETWORK,
  1011. "Enabled", "b",
  1012. (WPADBusPropertyAccessor)
  1013. wpas_dbus_getter_enabled,
  1014. (WPADBusPropertyAccessor)
  1015. wpas_dbus_setter_enabled,
  1016. arg1, wpa_dbus_free, RW);
  1017. /* Properties property */
  1018. wpa_dbus_property_register(obj_desc, WPAS_DBUS_NEW_IFACE_NETWORK,
  1019. "Properties", "a{sv}",
  1020. (WPADBusPropertyAccessor)
  1021. wpas_dbus_getter_network_properties,
  1022. (WPADBusPropertyAccessor)
  1023. wpas_dbus_setter_network_properties,
  1024. arg2, wpa_dbus_free, RW);
  1025. /* PropertiesChanged signal */
  1026. wpa_dbus_signal_register(obj_desc, WPAS_DBUS_NEW_IFACE_NETWORK,
  1027. "PropertiesChanged", sargs);
  1028. if (wpa_dbus_register_object_per_iface(ctrl_iface, net_obj_path,
  1029. wpa_s->ifname, obj_desc))
  1030. goto err;
  1031. wpas_dbus_signal_network_added(wpa_s, ssid->id);
  1032. os_free(net_obj_path);
  1033. return 0;
  1034. err:
  1035. os_free(net_obj_path);
  1036. os_free(obj_desc);
  1037. os_free(arg1);
  1038. os_free(arg2);
  1039. return -1;
  1040. }
  1041. /**
  1042. * wpas_dbus_unregister_network - Unregister a configured network from dbus
  1043. * @wpa_s: wpa_supplicant interface structure
  1044. * @nid: network id
  1045. * Returns: 0 on success, -1 on failure
  1046. *
  1047. * Unregisters network representing object from dbus
  1048. */
  1049. static int wpas_dbus_unregister_network(struct wpa_supplicant *wpa_s, int nid)
  1050. {
  1051. struct wpas_dbus_priv *ctrl_iface;
  1052. char *net_obj_path;
  1053. int ret;
  1054. /* Do nothing if the control interface is not turned on */
  1055. if (wpa_s == NULL || wpa_s->global == NULL)
  1056. return 0;
  1057. ctrl_iface = wpa_s->global->dbus;
  1058. if (ctrl_iface == NULL)
  1059. return 0;
  1060. net_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  1061. if (net_obj_path == NULL)
  1062. return -1;
  1063. os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1064. "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
  1065. wpas_dbus_get_path(wpa_s), nid);
  1066. wpa_printf(MSG_DEBUG, "dbus: Unregister network object '%s'",
  1067. net_obj_path);
  1068. ret = wpa_dbus_unregister_object_per_iface(ctrl_iface, net_obj_path);
  1069. if (!ret)
  1070. wpas_dbus_signal_network_removed(wpa_s, nid);
  1071. os_free(net_obj_path);
  1072. return ret;
  1073. }
  1074. /**
  1075. * wpas_dbus_unregister_bss - Unregister a scanned BSS from dbus
  1076. * @wpa_s: wpa_supplicant interface structure
  1077. * @bssid: scanned network bssid
  1078. * @id: unique BSS identifier
  1079. * Returns: 0 on success, -1 on failure
  1080. *
  1081. * Unregisters BSS representing object from dbus
  1082. */
  1083. static int wpas_dbus_unregister_bss(struct wpa_supplicant *wpa_s,
  1084. u8 bssid[ETH_ALEN], unsigned int id)
  1085. {
  1086. struct wpas_dbus_priv *ctrl_iface;
  1087. char *bss_obj_path;
  1088. /* Do nothing if the control interface is not turned on */
  1089. if (wpa_s == NULL || wpa_s->global == NULL)
  1090. return 0;
  1091. ctrl_iface = wpa_s->global->dbus;
  1092. if (ctrl_iface == NULL)
  1093. return 0;
  1094. bss_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  1095. if (bss_obj_path == NULL)
  1096. return -1;
  1097. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1098. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1099. wpas_dbus_get_path(wpa_s), id);
  1100. wpa_printf(MSG_DEBUG, "dbus: Unregister BSS object '%s'",
  1101. bss_obj_path);
  1102. if (wpa_dbus_unregister_object_per_iface(ctrl_iface, bss_obj_path)) {
  1103. wpa_printf(MSG_ERROR,
  1104. "Cannot unregister BSSID dbus object %s.",
  1105. bss_obj_path);
  1106. os_free(bss_obj_path);
  1107. return -1;
  1108. }
  1109. wpas_dbus_signal_bss_removed(wpa_s, bss_obj_path);
  1110. os_free(bss_obj_path);
  1111. return 0;
  1112. }
  1113. /**
  1114. * wpas_dbus_register_bss - Register a scanned BSS with dbus
  1115. * @wpa_s: wpa_supplicant interface structure
  1116. * @bssid: scanned network bssid
  1117. * @id: unique BSS identifier
  1118. * Returns: 0 on success, -1 on failure
  1119. *
  1120. * Registers BSS representing object with dbus
  1121. */
  1122. static int wpas_dbus_register_bss(struct wpa_supplicant *wpa_s,
  1123. u8 bssid[ETH_ALEN], unsigned int id)
  1124. {
  1125. struct wpas_dbus_priv *ctrl_iface;
  1126. struct wpa_dbus_object_desc *obj_desc;
  1127. char *bss_obj_path;
  1128. struct bss_handler_args *arg = NULL;
  1129. /* Do nothing if the control interface is not turned on */
  1130. if (wpa_s == NULL || wpa_s->global == NULL)
  1131. return 0;
  1132. ctrl_iface = wpa_s->global->dbus;
  1133. if (ctrl_iface == NULL)
  1134. return 0;
  1135. bss_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  1136. if (bss_obj_path == NULL)
  1137. return -1;
  1138. os_snprintf(bss_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
  1139. "%s/" WPAS_DBUS_NEW_BSSIDS_PART "/%u",
  1140. wpas_dbus_get_path(wpa_s), id);
  1141. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1142. if (!obj_desc) {
  1143. wpa_printf(MSG_ERROR, "Not enough memory "
  1144. "to create object description");
  1145. goto err;
  1146. }
  1147. arg = os_zalloc(sizeof(struct bss_handler_args));
  1148. if (!arg) {
  1149. wpa_printf(MSG_ERROR, "Not enough memory "
  1150. "to create arguments for handler");
  1151. goto err;
  1152. }
  1153. arg->wpa_s = wpa_s;
  1154. arg->id = id;
  1155. /* Properties property */
  1156. wpa_dbus_property_register(obj_desc, WPAS_DBUS_NEW_IFACE_BSSID,
  1157. "Properties", "a{sv}",
  1158. (WPADBusPropertyAccessor)
  1159. wpas_dbus_getter_bss_properties, NULL,
  1160. arg, wpa_dbus_free, R);
  1161. wpa_printf(MSG_DEBUG, "dbus: Register BSS object '%s'",
  1162. bss_obj_path);
  1163. if (wpa_dbus_register_object_per_iface(ctrl_iface, bss_obj_path,
  1164. wpa_s->ifname, obj_desc)) {
  1165. wpa_printf(MSG_ERROR,
  1166. "Cannot register BSSID dbus object %s.",
  1167. bss_obj_path);
  1168. goto err;
  1169. }
  1170. wpas_dbus_signal_bss_added(wpa_s, bss_obj_path);
  1171. os_free(bss_obj_path);
  1172. return 0;
  1173. err:
  1174. os_free(bss_obj_path);
  1175. os_free(obj_desc);
  1176. os_free(arg);
  1177. return -1;
  1178. }
  1179. static const struct wpas_dbus_method wpas_dbus_interface_methods[] = {
  1180. { "Scan", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1181. (WPADBusMethodHandler) &wpas_dbus_handler_scan,
  1182. {
  1183. { "args", "a{sv}", ARG_IN },
  1184. END_ARGS
  1185. }
  1186. },
  1187. { "Disconnect", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1188. (WPADBusMethodHandler) &wpas_dbus_handler_disconnect,
  1189. {
  1190. END_ARGS
  1191. }
  1192. },
  1193. { "AddNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1194. (WPADBusMethodHandler) &wpas_dbus_handler_add_network,
  1195. {
  1196. { "args", "a{sv}", ARG_IN },
  1197. { "path", "o", ARG_OUT },
  1198. END_ARGS
  1199. }
  1200. },
  1201. { "RemoveNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1202. (WPADBusMethodHandler) &wpas_dbus_handler_remove_network,
  1203. {
  1204. { "path", "o", ARG_IN },
  1205. END_ARGS
  1206. }
  1207. },
  1208. { "SelectNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1209. (WPADBusMethodHandler) &wpas_dbus_handler_select_network,
  1210. {
  1211. { "path", "o", ARG_IN },
  1212. END_ARGS
  1213. }
  1214. },
  1215. { "AddBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1216. (WPADBusMethodHandler) &wpas_dbus_handler_add_blob,
  1217. {
  1218. { "name", "s", ARG_IN },
  1219. { "data", "ay", ARG_IN },
  1220. END_ARGS
  1221. }
  1222. },
  1223. { "GetBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1224. (WPADBusMethodHandler) &wpas_dbus_handler_get_blob,
  1225. {
  1226. { "name", "s", ARG_IN },
  1227. { "data", "ay", ARG_OUT },
  1228. END_ARGS
  1229. }
  1230. },
  1231. { "RemoveBlob", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1232. (WPADBusMethodHandler) &wpas_dbus_handler_remove_blob,
  1233. {
  1234. { "name", "s", ARG_IN },
  1235. END_ARGS
  1236. }
  1237. },
  1238. #ifdef CONFIG_WPS
  1239. { "Start", WPAS_DBUS_NEW_IFACE_WPS,
  1240. (WPADBusMethodHandler) &wpas_dbus_handler_wps_start,
  1241. {
  1242. { "args", "a{sv}", ARG_IN },
  1243. { "output", "a{sv}", ARG_OUT },
  1244. END_ARGS
  1245. }
  1246. },
  1247. #endif /* CONFIG_WPS */
  1248. { NULL, NULL, NULL, { END_ARGS } }
  1249. };
  1250. static const struct wpas_dbus_property wpas_dbus_interface_properties[] = {
  1251. { "Capabilities", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{sv}",
  1252. (WPADBusPropertyAccessor) wpas_dbus_getter_capabilities,
  1253. NULL, R
  1254. },
  1255. { "State", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1256. (WPADBusPropertyAccessor) wpas_dbus_getter_state,
  1257. NULL, R
  1258. },
  1259. { "Scanning", WPAS_DBUS_NEW_IFACE_INTERFACE, "b",
  1260. (WPADBusPropertyAccessor) wpas_dbus_getter_scanning,
  1261. NULL, R
  1262. },
  1263. { "ApScan", WPAS_DBUS_NEW_IFACE_INTERFACE, "u",
  1264. (WPADBusPropertyAccessor) wpas_dbus_getter_ap_scan,
  1265. (WPADBusPropertyAccessor) wpas_dbus_setter_ap_scan,
  1266. RW
  1267. },
  1268. { "Ifname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1269. (WPADBusPropertyAccessor) wpas_dbus_getter_ifname,
  1270. NULL, R
  1271. },
  1272. { "Driver", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1273. (WPADBusPropertyAccessor) wpas_dbus_getter_driver,
  1274. NULL, R
  1275. },
  1276. { "BridgeIfname", WPAS_DBUS_NEW_IFACE_INTERFACE, "s",
  1277. (WPADBusPropertyAccessor) wpas_dbus_getter_bridge_ifname,
  1278. NULL, R
  1279. },
  1280. { "CurrentBSS", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  1281. (WPADBusPropertyAccessor) wpas_dbus_getter_current_bss,
  1282. NULL, R
  1283. },
  1284. { "CurrentNetwork", WPAS_DBUS_NEW_IFACE_INTERFACE, "o",
  1285. (WPADBusPropertyAccessor) wpas_dbus_getter_current_network,
  1286. NULL, R
  1287. },
  1288. { "Blobs", WPAS_DBUS_NEW_IFACE_INTERFACE, "a{say}",
  1289. (WPADBusPropertyAccessor) wpas_dbus_getter_blobs,
  1290. NULL, R
  1291. },
  1292. { "BSSs", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  1293. (WPADBusPropertyAccessor) wpas_dbus_getter_bsss,
  1294. NULL, R
  1295. },
  1296. { "Networks", WPAS_DBUS_NEW_IFACE_INTERFACE, "ao",
  1297. (WPADBusPropertyAccessor) wpas_dbus_getter_networks,
  1298. NULL, R
  1299. },
  1300. #ifdef CONFIG_WPS
  1301. { "ProcessCredentials", WPAS_DBUS_NEW_IFACE_WPS, "b",
  1302. (WPADBusPropertyAccessor) wpas_dbus_getter_process_credentials,
  1303. (WPADBusPropertyAccessor) wpas_dbus_setter_process_credentials,
  1304. RW
  1305. },
  1306. #endif /* CONFIG_WPS */
  1307. { NULL, NULL, NULL, NULL, NULL, 0 }
  1308. };
  1309. static const struct wpas_dbus_signal wpas_dbus_interface_signals[] = {
  1310. { "ScanDone", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1311. {
  1312. { "success", "b", ARG_OUT },
  1313. END_ARGS
  1314. }
  1315. },
  1316. { "StateChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1317. {
  1318. { "newState", "s", ARG_OUT },
  1319. { "oldState", "s", ARG_OUT },
  1320. END_ARGS
  1321. }
  1322. },
  1323. { "BSSAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1324. {
  1325. { "path", "o", ARG_OUT },
  1326. END_ARGS
  1327. }
  1328. },
  1329. { "BSSRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1330. {
  1331. { "path", "o", ARG_OUT },
  1332. END_ARGS
  1333. }
  1334. },
  1335. { "BlobAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1336. {
  1337. { "name", "s", ARG_OUT },
  1338. END_ARGS
  1339. }
  1340. },
  1341. { "BlobRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1342. {
  1343. { "name", "s", ARG_OUT },
  1344. END_ARGS
  1345. }
  1346. },
  1347. { "NetworkAdded", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1348. {
  1349. { "path", "o", ARG_OUT },
  1350. END_ARGS
  1351. }
  1352. },
  1353. { "NetworkRemoved", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1354. {
  1355. { "path", "o", ARG_OUT },
  1356. END_ARGS
  1357. }
  1358. },
  1359. { "NetworkSelected", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1360. {
  1361. { "path", "o", ARG_OUT },
  1362. END_ARGS
  1363. }
  1364. },
  1365. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_INTERFACE,
  1366. {
  1367. { "properties", "a{sv}", ARG_OUT },
  1368. END_ARGS
  1369. }
  1370. },
  1371. #ifdef CONFIG_WPS
  1372. { "Event", WPAS_DBUS_NEW_IFACE_WPS,
  1373. {
  1374. { "name", "s", ARG_OUT },
  1375. { "args", "a{sv}", ARG_OUT },
  1376. END_ARGS
  1377. }
  1378. },
  1379. { "Credentials", WPAS_DBUS_NEW_IFACE_WPS,
  1380. {
  1381. { "credentials", "a{sv}", ARG_OUT },
  1382. END_ARGS
  1383. }
  1384. },
  1385. { "PropertiesChanged", WPAS_DBUS_NEW_IFACE_WPS,
  1386. {
  1387. { "properties", "a{sv}", ARG_OUT },
  1388. END_ARGS
  1389. }
  1390. },
  1391. #endif /* CONFIG_WPS */
  1392. { NULL, NULL, { END_ARGS } }
  1393. };
  1394. static int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
  1395. {
  1396. struct wpa_dbus_object_desc *obj_desc = NULL;
  1397. char *path;
  1398. struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
  1399. int next;
  1400. /* Do nothing if the control interface is not turned on */
  1401. if (ctrl_iface == NULL)
  1402. return 0;
  1403. /* Create and set the interface's object path */
  1404. path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
  1405. if (path == NULL)
  1406. return -1;
  1407. next = ctrl_iface->next_objid++;
  1408. os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
  1409. WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
  1410. next);
  1411. if (wpas_dbus_set_path(wpa_s, path)) {
  1412. wpa_printf(MSG_DEBUG,
  1413. "Failed to set dbus path for interface %s",
  1414. wpa_s->ifname);
  1415. goto err;
  1416. }
  1417. obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
  1418. if (!obj_desc) {
  1419. wpa_printf(MSG_ERROR, "Not enough memory "
  1420. "to create object description");
  1421. goto err;
  1422. }
  1423. wpas_dbus_register(obj_desc, wpa_s, wpas_dbus_interface_methods,
  1424. wpas_dbus_interface_properties,
  1425. wpas_dbus_interface_signals);
  1426. wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'", path);
  1427. if (wpa_dbus_register_object_per_iface(ctrl_iface, path, wpa_s->ifname,
  1428. obj_desc))
  1429. goto err;
  1430. wpas_dbus_signal_interface_created(wpa_s);
  1431. os_free(path);
  1432. return 0;
  1433. err:
  1434. os_free(obj_desc);
  1435. os_free(path);
  1436. return -1;
  1437. }
  1438. static int wpas_dbus_unregister_interface(struct wpa_supplicant *wpa_s)
  1439. {
  1440. struct wpas_dbus_priv *ctrl_iface;
  1441. /* Do nothing if the control interface is not turned on */
  1442. if (wpa_s == NULL || wpa_s->global == NULL)
  1443. return 0;
  1444. ctrl_iface = wpa_s->global->dbus;
  1445. if (ctrl_iface == NULL)
  1446. return 0;
  1447. wpa_printf(MSG_DEBUG, "dbus: Unregister interface object '%s'",
  1448. wpas_dbus_get_path(wpa_s));
  1449. if (wpa_dbus_unregister_object_per_iface(ctrl_iface,
  1450. wpas_dbus_get_path(wpa_s)))
  1451. return -1;
  1452. wpas_dbus_signal_interface_removed(wpa_s);
  1453. os_free(wpa_s->dbus_new_path);
  1454. wpa_s->dbus_new_path = NULL;
  1455. return 0;
  1456. }
  1457. static struct wpas_dbus_callbacks callbacks =
  1458. {
  1459. .signal_interface_created = wpas_dbus_signal_interface_created,
  1460. .signal_interface_removed = wpas_dbus_signal_interface_removed,
  1461. .register_interface = wpas_dbus_register_interface,
  1462. .unregister_interface = wpas_dbus_unregister_interface,
  1463. .signal_scan_done = wpas_dbus_signal_scan_done,
  1464. .signal_blob_added = wpas_dbus_signal_blob_added,
  1465. .signal_blob_removed = wpas_dbus_signal_blob_removed,
  1466. .signal_network_selected = wpas_dbus_signal_network_selected,
  1467. .signal_state_changed = wpas_dbus_signal_state_changed,
  1468. .register_network = wpas_dbus_register_network,
  1469. .unregister_network = wpas_dbus_unregister_network,
  1470. .signal_network_enabled_changed =
  1471. wpas_dbus_signal_network_enabled_changed,
  1472. .register_bss = wpas_dbus_register_bss,
  1473. .unregister_bss = wpas_dbus_unregister_bss,
  1474. .signal_prop_changed = wpas_dbus_signal_prop_changed,
  1475. .signal_debug_params_changed = wpas_dbus_signal_debug_params_changed,
  1476. #ifdef CONFIG_WPS
  1477. .signal_wps_event_success = wpas_dbus_signal_wps_event_success,
  1478. .signal_wps_event_fail = wpas_dbus_signal_wps_event_fail,
  1479. .signal_wps_event_m2d = wpas_dbus_signal_wps_event_m2d,
  1480. .signal_wps_credentials = wpas_dbus_signal_wps_cred,
  1481. #endif /* CONFIG_WPS */
  1482. };
  1483. struct wpas_dbus_callbacks * wpas_dbus_get_callbacks(void)
  1484. {
  1485. return &callbacks;
  1486. }
  1487. /**
  1488. * wpas_dbus_get_path - Get an interface's dbus path
  1489. * @wpa_s: %wpa_supplicant interface structure
  1490. * Returns: Interface's dbus object path, or %NULL on error
  1491. */
  1492. const char * wpas_dbus_get_path(struct wpa_supplicant *wpa_s)
  1493. {
  1494. return wpa_s->dbus_new_path;
  1495. }