nm-setting-wireless.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
  2. /*
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Lesser General Public
  5. * License as published by the Free Software Foundation; either
  6. * version 2 of the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with this library; if not, write to the
  15. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. * Boston, MA 02110-1301 USA.
  17. *
  18. * Copyright 2007 - 2014 Red Hat, Inc.
  19. * Copyright 2007 - 2008 Novell, Inc.
  20. */
  21. #include "nm-default.h"
  22. #include "nm-setting-wireless.h"
  23. #include <string.h>
  24. #include <net/ethernet.h>
  25. #include "nm-utils.h"
  26. #include "nm-common-macros.h"
  27. #include "nm-utils-private.h"
  28. #include "nm-setting-private.h"
  29. /**
  30. * SECTION:nm-setting-wireless
  31. * @short_description: Describes connection properties for 802.11 Wi-Fi networks
  32. *
  33. * The #NMSettingWireless object is a #NMSetting subclass that describes properties
  34. * necessary for connection to 802.11 Wi-Fi networks.
  35. **/
  36. G_DEFINE_TYPE (NMSettingWireless, nm_setting_wireless, NM_TYPE_SETTING)
  37. #define NM_SETTING_WIRELESS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_WIRELESS, NMSettingWirelessPrivate))
  38. typedef struct {
  39. GBytes *ssid;
  40. char *mode;
  41. char *band;
  42. guint32 channel;
  43. char *bssid;
  44. guint32 rate;
  45. guint32 tx_power;
  46. char *device_mac_address;
  47. char *cloned_mac_address;
  48. char *generate_mac_address_mask;
  49. GArray *mac_address_blacklist;
  50. guint32 mtu;
  51. GSList *seen_bssids;
  52. gboolean hidden;
  53. guint32 powersave;
  54. NMSettingMacRandomization mac_address_randomization;
  55. guint32 wowl;
  56. } NMSettingWirelessPrivate;
  57. enum {
  58. PROP_0,
  59. PROP_SSID,
  60. PROP_MODE,
  61. PROP_BAND,
  62. PROP_CHANNEL,
  63. PROP_BSSID,
  64. PROP_RATE,
  65. PROP_TX_POWER,
  66. PROP_MAC_ADDRESS,
  67. PROP_CLONED_MAC_ADDRESS,
  68. PROP_GENERATE_MAC_ADDRESS_MASK,
  69. PROP_MAC_ADDRESS_BLACKLIST,
  70. PROP_MTU,
  71. PROP_SEEN_BSSIDS,
  72. PROP_HIDDEN,
  73. PROP_POWERSAVE,
  74. PROP_MAC_ADDRESS_RANDOMIZATION,
  75. PROP_WAKE_ON_WLAN,
  76. LAST_PROP
  77. };
  78. static gboolean
  79. match_cipher (const char *cipher,
  80. const char *expected,
  81. guint32 wpa_flags,
  82. guint32 rsn_flags,
  83. guint32 flag)
  84. {
  85. if (strcmp (cipher, expected) != 0)
  86. return FALSE;
  87. if (!(wpa_flags & flag) && !(rsn_flags & flag))
  88. return FALSE;
  89. return TRUE;
  90. }
  91. /**
  92. * nm_setting_wireless_ap_security_compatible:
  93. * @s_wireless: a #NMSettingWireless
  94. * @s_wireless_sec: a #NMSettingWirelessSecurity or %NULL
  95. * @ap_flags: the %NM80211ApFlags of the given access point
  96. * @ap_wpa: the %NM80211ApSecurityFlags of the given access point's WPA
  97. * capabilities
  98. * @ap_rsn: the %NM80211ApSecurityFlags of the given access point's WPA2/RSN
  99. * capabilities
  100. * @ap_mode: the 802.11 mode of the AP, either Ad-Hoc or Infrastructure
  101. *
  102. * Given a #NMSettingWireless and an optional #NMSettingWirelessSecurity,
  103. * determine if the configuration given by the settings is compatible with
  104. * the security of an access point using that access point's capability flags
  105. * and mode. Useful for clients that wish to filter a set of connections
  106. * against a set of access points and determine which connections are
  107. * compatible with which access points.
  108. *
  109. * Returns: %TRUE if the given settings are compatible with the access point's
  110. * security flags and mode, %FALSE if they are not.
  111. */
  112. gboolean
  113. nm_setting_wireless_ap_security_compatible (NMSettingWireless *s_wireless,
  114. NMSettingWirelessSecurity *s_wireless_sec,
  115. NM80211ApFlags ap_flags,
  116. NM80211ApSecurityFlags ap_wpa,
  117. NM80211ApSecurityFlags ap_rsn,
  118. NM80211Mode ap_mode)
  119. {
  120. const char *key_mgmt = NULL, *cipher;
  121. guint32 num, i;
  122. gboolean found = FALSE;
  123. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (s_wireless), FALSE);
  124. if (!s_wireless_sec) {
  125. if ( (ap_flags & NM_802_11_AP_FLAGS_PRIVACY)
  126. || (ap_wpa != NM_802_11_AP_SEC_NONE)
  127. || (ap_rsn != NM_802_11_AP_SEC_NONE))
  128. return FALSE;
  129. return TRUE;
  130. }
  131. key_mgmt = nm_setting_wireless_security_get_key_mgmt (s_wireless_sec);
  132. if (!key_mgmt)
  133. return FALSE;
  134. /* Static WEP */
  135. if (!strcmp (key_mgmt, "none")) {
  136. if ( !(ap_flags & NM_802_11_AP_FLAGS_PRIVACY)
  137. || (ap_wpa != NM_802_11_AP_SEC_NONE)
  138. || (ap_rsn != NM_802_11_AP_SEC_NONE))
  139. return FALSE;
  140. return TRUE;
  141. }
  142. /* Adhoc WPA */
  143. if (!strcmp (key_mgmt, "wpa-none")) {
  144. if (ap_mode != NM_802_11_MODE_ADHOC)
  145. return FALSE;
  146. /* FIXME: validate ciphers if they're in the beacon */
  147. return TRUE;
  148. }
  149. /* Adhoc WPA2 (ie, RSN IBSS) */
  150. if (ap_mode == NM_802_11_MODE_ADHOC) {
  151. if (strcmp (key_mgmt, "wpa-psk"))
  152. return FALSE;
  153. /* Ensure the AP has RSN PSK capability */
  154. if (!(ap_rsn & NM_802_11_AP_SEC_KEY_MGMT_PSK))
  155. return FALSE;
  156. /* Fall through and check ciphers in generic WPA-PSK code */
  157. }
  158. /* Dynamic WEP or LEAP */
  159. if (!strcmp (key_mgmt, "ieee8021x")) {
  160. if (!(ap_flags & NM_802_11_AP_FLAGS_PRIVACY))
  161. return FALSE;
  162. /* If the AP is advertising a WPA IE, make sure it supports WEP ciphers */
  163. if (ap_wpa != NM_802_11_AP_SEC_NONE) {
  164. if (!(ap_wpa & NM_802_11_AP_SEC_KEY_MGMT_802_1X))
  165. return FALSE;
  166. /* quick check; can't use AP if it doesn't support at least one
  167. * WEP cipher in both pairwise and group suites.
  168. */
  169. if ( !(ap_wpa & (NM_802_11_AP_SEC_PAIR_WEP40 | NM_802_11_AP_SEC_PAIR_WEP104))
  170. || !(ap_wpa & (NM_802_11_AP_SEC_GROUP_WEP40 | NM_802_11_AP_SEC_GROUP_WEP104)))
  171. return FALSE;
  172. /* Match at least one pairwise cipher with AP's capability if the
  173. * wireless-security setting explicitly lists pairwise ciphers
  174. */
  175. num = nm_setting_wireless_security_get_num_pairwise (s_wireless_sec);
  176. for (i = 0, found = FALSE; i < num; i++) {
  177. cipher = nm_setting_wireless_security_get_pairwise (s_wireless_sec, i);
  178. if ((found = match_cipher (cipher, "wep40", ap_wpa, ap_wpa, NM_802_11_AP_SEC_PAIR_WEP40)))
  179. break;
  180. if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_wpa, NM_802_11_AP_SEC_PAIR_WEP104)))
  181. break;
  182. }
  183. if (!found && num)
  184. return FALSE;
  185. /* Match at least one group cipher with AP's capability if the
  186. * wireless-security setting explicitly lists group ciphers
  187. */
  188. num = nm_setting_wireless_security_get_num_groups (s_wireless_sec);
  189. for (i = 0, found = FALSE; i < num; i++) {
  190. cipher = nm_setting_wireless_security_get_group (s_wireless_sec, i);
  191. if ((found = match_cipher (cipher, "wep40", ap_wpa, ap_wpa, NM_802_11_AP_SEC_GROUP_WEP40)))
  192. break;
  193. if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_wpa, NM_802_11_AP_SEC_GROUP_WEP104)))
  194. break;
  195. }
  196. if (!found && num)
  197. return FALSE;
  198. }
  199. return TRUE;
  200. }
  201. /* WPA[2]-PSK and WPA[2] Enterprise */
  202. if ( !strcmp (key_mgmt, "wpa-psk")
  203. || !strcmp (key_mgmt, "wpa-eap")) {
  204. if (!strcmp (key_mgmt, "wpa-psk")) {
  205. if ( !(ap_wpa & NM_802_11_AP_SEC_KEY_MGMT_PSK)
  206. && !(ap_rsn & NM_802_11_AP_SEC_KEY_MGMT_PSK))
  207. return FALSE;
  208. } else if (!strcmp (key_mgmt, "wpa-eap")) {
  209. if ( !(ap_wpa & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
  210. && !(ap_rsn & NM_802_11_AP_SEC_KEY_MGMT_802_1X))
  211. return FALSE;
  212. }
  213. // FIXME: should handle WPA and RSN separately here to ensure that
  214. // if the Connection only uses WPA we don't match a cipher against
  215. // the AP's RSN IE instead
  216. /* Match at least one pairwise cipher with AP's capability if the
  217. * wireless-security setting explicitly lists pairwise ciphers
  218. */
  219. num = nm_setting_wireless_security_get_num_pairwise (s_wireless_sec);
  220. for (i = 0, found = FALSE; i < num; i++) {
  221. cipher = nm_setting_wireless_security_get_pairwise (s_wireless_sec, i);
  222. if ((found = match_cipher (cipher, "tkip", ap_wpa, ap_rsn, NM_802_11_AP_SEC_PAIR_TKIP)))
  223. break;
  224. if ((found = match_cipher (cipher, "ccmp", ap_wpa, ap_rsn, NM_802_11_AP_SEC_PAIR_CCMP)))
  225. break;
  226. }
  227. if (!found && num)
  228. return FALSE;
  229. /* Match at least one group cipher with AP's capability if the
  230. * wireless-security setting explicitly lists group ciphers
  231. */
  232. num = nm_setting_wireless_security_get_num_groups (s_wireless_sec);
  233. for (i = 0, found = FALSE; i < num; i++) {
  234. cipher = nm_setting_wireless_security_get_group (s_wireless_sec, i);
  235. if ((found = match_cipher (cipher, "wep40", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_WEP40)))
  236. break;
  237. if ((found = match_cipher (cipher, "wep104", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_WEP104)))
  238. break;
  239. if ((found = match_cipher (cipher, "tkip", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_TKIP)))
  240. break;
  241. if ((found = match_cipher (cipher, "ccmp", ap_wpa, ap_rsn, NM_802_11_AP_SEC_GROUP_CCMP)))
  242. break;
  243. }
  244. if (!found && num)
  245. return FALSE;
  246. return TRUE;
  247. }
  248. return FALSE;
  249. }
  250. /**
  251. * nm_setting_wireless_new:
  252. *
  253. * Creates a new #NMSettingWireless object with default values.
  254. *
  255. * Returns: (transfer full): the new empty #NMSettingWireless object
  256. **/
  257. NMSetting *
  258. nm_setting_wireless_new (void)
  259. {
  260. return (NMSetting *) g_object_new (NM_TYPE_SETTING_WIRELESS, NULL);
  261. }
  262. /**
  263. * nm_setting_wireless_get_ssid:
  264. * @setting: the #NMSettingWireless
  265. *
  266. * Returns: (transfer none): the #NMSettingWireless:ssid property of the setting
  267. **/
  268. GBytes *
  269. nm_setting_wireless_get_ssid (NMSettingWireless *setting)
  270. {
  271. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
  272. return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->ssid;
  273. }
  274. /**
  275. * nm_setting_wireless_get_mode:
  276. * @setting: the #NMSettingWireless
  277. *
  278. * Returns: the #NMSettingWireless:mode property of the setting
  279. **/
  280. const char *
  281. nm_setting_wireless_get_mode (NMSettingWireless *setting)
  282. {
  283. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
  284. return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mode;
  285. }
  286. /**
  287. * nm_setting_wireless_get_band:
  288. * @setting: the #NMSettingWireless
  289. *
  290. * Returns: the #NMSettingWireless:band property of the setting
  291. **/
  292. const char *
  293. nm_setting_wireless_get_band (NMSettingWireless *setting)
  294. {
  295. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
  296. return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->band;
  297. }
  298. /**
  299. * nm_setting_wireless_get_channel:
  300. * @setting: the #NMSettingWireless
  301. *
  302. * Returns: the #NMSettingWireless:channel property of the setting
  303. **/
  304. guint32
  305. nm_setting_wireless_get_channel (NMSettingWireless *setting)
  306. {
  307. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
  308. return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->channel;
  309. }
  310. /**
  311. * nm_setting_wireless_get_bssid:
  312. * @setting: the #NMSettingWireless
  313. *
  314. * Returns: the #NMSettingWireless:bssid property of the setting
  315. **/
  316. const char *
  317. nm_setting_wireless_get_bssid (NMSettingWireless *setting)
  318. {
  319. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
  320. return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->bssid;
  321. }
  322. /**
  323. * nm_setting_wireless_get_rate:
  324. * @setting: the #NMSettingWireless
  325. *
  326. * Returns: the #NMSettingWireless:rate property of the setting
  327. **/
  328. guint32
  329. nm_setting_wireless_get_rate (NMSettingWireless *setting)
  330. {
  331. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
  332. return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->rate;
  333. }
  334. /**
  335. * nm_setting_wireless_get_tx_power:
  336. * @setting: the #NMSettingWireless
  337. *
  338. * Returns: the #NMSettingWireless:tx-power property of the setting
  339. **/
  340. guint32
  341. nm_setting_wireless_get_tx_power (NMSettingWireless *setting)
  342. {
  343. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
  344. return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->tx_power;
  345. }
  346. /**
  347. * nm_setting_wireless_get_mac_address:
  348. * @setting: the #NMSettingWireless
  349. *
  350. * Returns: the #NMSettingWireless:mac-address property of the setting
  351. **/
  352. const char *
  353. nm_setting_wireless_get_mac_address (NMSettingWireless *setting)
  354. {
  355. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
  356. return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->device_mac_address;
  357. }
  358. /**
  359. * nm_setting_wireless_get_cloned_mac_address:
  360. * @setting: the #NMSettingWireless
  361. *
  362. * Returns: the #NMSettingWireless:cloned-mac-address property of the setting
  363. **/
  364. const char *
  365. nm_setting_wireless_get_cloned_mac_address (NMSettingWireless *setting)
  366. {
  367. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
  368. return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->cloned_mac_address;
  369. }
  370. /**
  371. * nm_setting_wireless_get_generate_mac_address_mask:
  372. * @setting: the #NMSettingWireless
  373. *
  374. * Returns: the #NMSettingWireless:generate-mac-address-mask property of the setting
  375. *
  376. * Since: 1.4
  377. **/
  378. const char *
  379. nm_setting_wireless_get_generate_mac_address_mask (NMSettingWireless *setting)
  380. {
  381. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
  382. return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->generate_mac_address_mask;
  383. }
  384. /**
  385. * nm_setting_wireless_get_mac_address_blacklist:
  386. * @setting: the #NMSettingWireless
  387. *
  388. * Returns: the #NMSettingWireless:mac-address-blacklist property of the setting
  389. **/
  390. const char * const *
  391. nm_setting_wireless_get_mac_address_blacklist (NMSettingWireless *setting)
  392. {
  393. NMSettingWirelessPrivate *priv;
  394. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
  395. priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
  396. return (const char * const *) priv->mac_address_blacklist->data;
  397. }
  398. /**
  399. * nm_setting_wireless_get_num_mac_blacklist_items:
  400. * @setting: the #NMSettingWireless
  401. *
  402. * Returns: the number of blacklisted MAC addresses
  403. **/
  404. guint32
  405. nm_setting_wireless_get_num_mac_blacklist_items (NMSettingWireless *setting)
  406. {
  407. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
  408. return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mac_address_blacklist->len;
  409. }
  410. /**
  411. * nm_setting_wireless_get_mac_blacklist_item:
  412. * @setting: the #NMSettingWireless
  413. * @idx: the zero-based index of the MAC address entry
  414. *
  415. * Returns: the blacklisted MAC address string (hex-digits-and-colons notation)
  416. * at index @idx
  417. **/
  418. const char *
  419. nm_setting_wireless_get_mac_blacklist_item (NMSettingWireless *setting, guint32 idx)
  420. {
  421. NMSettingWirelessPrivate *priv;
  422. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
  423. priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
  424. g_return_val_if_fail (idx <= priv->mac_address_blacklist->len, NULL);
  425. return g_array_index (priv->mac_address_blacklist, const char *, idx);
  426. }
  427. /**
  428. * nm_setting_wireless_add_mac_blacklist_item:
  429. * @setting: the #NMSettingWireless
  430. * @mac: the MAC address string (hex-digits-and-colons notation) to blacklist
  431. *
  432. * Adds a new MAC address to the #NMSettingWireless:mac-address-blacklist property.
  433. *
  434. * Returns: %TRUE if the MAC address was added; %FALSE if the MAC address
  435. * is invalid or was already present
  436. **/
  437. gboolean
  438. nm_setting_wireless_add_mac_blacklist_item (NMSettingWireless *setting, const char *mac)
  439. {
  440. NMSettingWirelessPrivate *priv;
  441. const char *candidate;
  442. int i;
  443. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
  444. g_return_val_if_fail (mac != NULL, FALSE);
  445. if (!nm_utils_hwaddr_valid (mac, ETH_ALEN))
  446. return FALSE;
  447. priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
  448. for (i = 0; i < priv->mac_address_blacklist->len; i++) {
  449. candidate = g_array_index (priv->mac_address_blacklist, char *, i);
  450. if (nm_utils_hwaddr_matches (mac, -1, candidate, -1))
  451. return FALSE;
  452. }
  453. mac = nm_utils_hwaddr_canonical (mac, ETH_ALEN);
  454. g_array_append_val (priv->mac_address_blacklist, mac);
  455. g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST);
  456. return TRUE;
  457. }
  458. /**
  459. * nm_setting_wireless_remove_mac_blacklist_item:
  460. * @setting: the #NMSettingWireless
  461. * @idx: index number of the MAC address
  462. *
  463. * Removes the MAC address at index @idx from the blacklist.
  464. **/
  465. void
  466. nm_setting_wireless_remove_mac_blacklist_item (NMSettingWireless *setting, guint32 idx)
  467. {
  468. NMSettingWirelessPrivate *priv;
  469. g_return_if_fail (NM_IS_SETTING_WIRELESS (setting));
  470. priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
  471. g_return_if_fail (idx < priv->mac_address_blacklist->len);
  472. g_array_remove_index (priv->mac_address_blacklist, idx);
  473. g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST);
  474. }
  475. /**
  476. * nm_setting_wireless_remove_mac_blacklist_item_by_value:
  477. * @setting: the #NMSettingWireless
  478. * @mac: the MAC address string (hex-digits-and-colons notation) to remove from
  479. * the blacklist
  480. *
  481. * Removes the MAC address @mac from the blacklist.
  482. *
  483. * Returns: %TRUE if the MAC address was found and removed; %FALSE if it was not.
  484. **/
  485. gboolean
  486. nm_setting_wireless_remove_mac_blacklist_item_by_value (NMSettingWireless *setting, const char *mac)
  487. {
  488. NMSettingWirelessPrivate *priv;
  489. const char *candidate;
  490. int i;
  491. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
  492. g_return_val_if_fail (mac != NULL, FALSE);
  493. priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
  494. for (i = 0; i < priv->mac_address_blacklist->len; i++) {
  495. candidate = g_array_index (priv->mac_address_blacklist, char *, i);
  496. if (!nm_utils_hwaddr_matches (mac, -1, candidate, -1)) {
  497. g_array_remove_index (priv->mac_address_blacklist, i);
  498. g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST);
  499. return TRUE;
  500. }
  501. }
  502. return FALSE;
  503. }
  504. /**
  505. * nm_setting_wireless_clear_mac_blacklist_items:
  506. * @setting: the #NMSettingWireless
  507. *
  508. * Removes all blacklisted MAC addresses.
  509. **/
  510. void
  511. nm_setting_wireless_clear_mac_blacklist_items (NMSettingWireless *setting)
  512. {
  513. g_return_if_fail (NM_IS_SETTING_WIRELESS (setting));
  514. g_array_set_size (NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mac_address_blacklist, 0);
  515. g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST);
  516. }
  517. /**
  518. * nm_setting_wireless_get_mtu:
  519. * @setting: the #NMSettingWireless
  520. *
  521. * Returns: the #NMSettingWireless:mtu property of the setting
  522. **/
  523. guint32
  524. nm_setting_wireless_get_mtu (NMSettingWireless *setting)
  525. {
  526. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
  527. return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mtu;
  528. }
  529. /**
  530. * nm_setting_wireless_get_hidden:
  531. * @setting: the #NMSettingWireless
  532. *
  533. * Returns: the #NMSettingWireless:hidden property of the setting
  534. **/
  535. gboolean
  536. nm_setting_wireless_get_hidden (NMSettingWireless *setting)
  537. {
  538. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
  539. return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->hidden;
  540. }
  541. /**
  542. * nm_setting_wireless_get_powersave:
  543. * @setting: the #NMSettingWireless
  544. *
  545. * Returns: the #NMSettingWireless:powersave property of the setting
  546. *
  547. * Since: 1.2
  548. **/
  549. guint32
  550. nm_setting_wireless_get_powersave (NMSettingWireless *setting)
  551. {
  552. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
  553. return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->powersave;
  554. }
  555. /**
  556. * nm_setting_wireless_get_mac_address_randomization:
  557. * @setting: the #NMSettingWireless
  558. *
  559. * Returns: the #NMSettingWireless:mac-address-randomization property of the
  560. * setting
  561. *
  562. * Since: 1.2
  563. **/
  564. NMSettingMacRandomization
  565. nm_setting_wireless_get_mac_address_randomization (NMSettingWireless *setting)
  566. {
  567. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
  568. return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->mac_address_randomization;
  569. }
  570. /**
  571. * nm_setting_wireless_add_seen_bssid:
  572. * @setting: the #NMSettingWireless
  573. * @bssid: the new BSSID to add to the list
  574. *
  575. * Adds a new Wi-Fi AP's BSSID to the previously seen BSSID list of the setting.
  576. * NetworkManager now tracks previously seen BSSIDs internally so this function
  577. * no longer has much use. Actually, changes you make using this function will
  578. * not be preserved.
  579. *
  580. * Returns: %TRUE if @bssid was already known, %FALSE if not
  581. **/
  582. gboolean
  583. nm_setting_wireless_add_seen_bssid (NMSettingWireless *setting,
  584. const char *bssid)
  585. {
  586. NMSettingWirelessPrivate *priv;
  587. char *lower_bssid;
  588. GSList *iter;
  589. gboolean found = FALSE;
  590. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), FALSE);
  591. g_return_val_if_fail (bssid != NULL, FALSE);
  592. lower_bssid = g_ascii_strdown (bssid, -1);
  593. if (!lower_bssid)
  594. return FALSE;
  595. priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
  596. for (iter = priv->seen_bssids; iter; iter = iter->next) {
  597. if (!strcmp ((char *) iter->data, lower_bssid)) {
  598. found = TRUE;
  599. break;
  600. }
  601. }
  602. if (!found) {
  603. priv->seen_bssids = g_slist_prepend (priv->seen_bssids, lower_bssid);
  604. g_object_notify (G_OBJECT (setting), NM_SETTING_WIRELESS_SEEN_BSSIDS);
  605. } else
  606. g_free (lower_bssid);
  607. return !found;
  608. }
  609. /**
  610. * nm_setting_wireless_get_num_seen_bssids:
  611. * @setting: the #NMSettingWireless
  612. *
  613. * Returns: the number of BSSIDs in the previously seen BSSID list
  614. **/
  615. guint32
  616. nm_setting_wireless_get_num_seen_bssids (NMSettingWireless *setting)
  617. {
  618. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), 0);
  619. return g_slist_length (NM_SETTING_WIRELESS_GET_PRIVATE (setting)->seen_bssids);
  620. }
  621. /**
  622. * nm_setting_wireless_get_seen_bssid:
  623. * @setting: the #NMSettingWireless
  624. * @i: index of a BSSID in the previously seen BSSID list
  625. *
  626. * Returns: the BSSID at index @i
  627. **/
  628. const char *
  629. nm_setting_wireless_get_seen_bssid (NMSettingWireless *setting,
  630. guint32 i)
  631. {
  632. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NULL);
  633. return (const char *) g_slist_nth_data (NM_SETTING_WIRELESS_GET_PRIVATE (setting)->seen_bssids, i);
  634. }
  635. static gboolean
  636. verify (NMSetting *setting, NMConnection *connection, GError **error)
  637. {
  638. NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
  639. const char *valid_modes[] = { NM_SETTING_WIRELESS_MODE_INFRA, NM_SETTING_WIRELESS_MODE_ADHOC, NM_SETTING_WIRELESS_MODE_AP, NULL };
  640. const char *valid_bands[] = { "a", "bg", NULL };
  641. GSList *iter;
  642. int i;
  643. gsize length;
  644. GError *local = NULL;
  645. if (!priv->ssid) {
  646. g_set_error_literal (error,
  647. NM_CONNECTION_ERROR,
  648. NM_CONNECTION_ERROR_MISSING_PROPERTY,
  649. _("property is missing"));
  650. g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID);
  651. return FALSE;
  652. }
  653. length = g_bytes_get_size (priv->ssid);
  654. if (length == 0 || length > 32) {
  655. g_set_error_literal (error,
  656. NM_CONNECTION_ERROR,
  657. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  658. _("SSID length is out of range <1-32> bytes"));
  659. g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SSID);
  660. return FALSE;
  661. }
  662. if (priv->mode && !g_strv_contains (valid_modes, priv->mode)) {
  663. g_set_error (error,
  664. NM_CONNECTION_ERROR,
  665. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  666. _("'%s' is not a valid Wi-Fi mode"),
  667. priv->mode);
  668. g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MODE);
  669. return FALSE;
  670. }
  671. if (priv->band && !g_strv_contains (valid_bands, priv->band)) {
  672. g_set_error (error,
  673. NM_CONNECTION_ERROR,
  674. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  675. _("'%s' is not a valid band"),
  676. priv->band);
  677. g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_BAND);
  678. return FALSE;
  679. }
  680. if (priv->channel && !priv->band) {
  681. g_set_error (error,
  682. NM_CONNECTION_ERROR,
  683. NM_CONNECTION_ERROR_MISSING_PROPERTY,
  684. _("'%s' requires setting '%s' property"),
  685. NM_SETTING_WIRELESS_CHANNEL, NM_SETTING_WIRELESS_BAND);
  686. g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_BAND);
  687. return FALSE;
  688. }
  689. if (priv->channel) {
  690. if (!nm_utils_wifi_is_channel_valid (priv->channel, priv->band)) {
  691. g_set_error (error,
  692. NM_CONNECTION_ERROR,
  693. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  694. _("'%d' is not a valid channel"),
  695. priv->channel);
  696. g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_CHANNEL);
  697. return FALSE;
  698. }
  699. }
  700. if (priv->bssid && !nm_utils_hwaddr_valid (priv->bssid, ETH_ALEN)) {
  701. g_set_error_literal (error,
  702. NM_CONNECTION_ERROR,
  703. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  704. _("property is invalid"));
  705. g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_BSSID);
  706. return FALSE;
  707. }
  708. if (priv->device_mac_address && !nm_utils_hwaddr_valid (priv->device_mac_address, ETH_ALEN)) {
  709. g_set_error_literal (error,
  710. NM_CONNECTION_ERROR,
  711. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  712. _("property is invalid"));
  713. g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MAC_ADDRESS);
  714. return FALSE;
  715. }
  716. if ( priv->cloned_mac_address
  717. && !NM_CLONED_MAC_IS_SPECIAL (priv->cloned_mac_address)
  718. && !nm_utils_hwaddr_valid (priv->cloned_mac_address, ETH_ALEN)) {
  719. g_set_error_literal (error,
  720. NM_CONNECTION_ERROR,
  721. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  722. _("property is invalid"));
  723. g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS);
  724. return FALSE;
  725. }
  726. /* generate-mac-address-mask only makes sense with cloned-mac-address "random" or
  727. * "stable". Still, let's not be so strict about that and accept the value
  728. * even if it is unused. */
  729. if (!_nm_utils_generate_mac_address_mask_parse (priv->generate_mac_address_mask,
  730. NULL, NULL, NULL, &local)) {
  731. g_set_error_literal (error,
  732. NM_CONNECTION_ERROR,
  733. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  734. local->message);
  735. g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK);
  736. g_error_free (local);
  737. return FALSE;
  738. }
  739. for (i = 0; i < priv->mac_address_blacklist->len; i++) {
  740. const char *mac = g_array_index (priv->mac_address_blacklist, const char *, i);
  741. if (!nm_utils_hwaddr_valid (mac, ETH_ALEN)) {
  742. g_set_error (error,
  743. NM_CONNECTION_ERROR,
  744. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  745. _("'%s' is not a valid MAC address"),
  746. mac);
  747. g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST);
  748. return FALSE;
  749. }
  750. }
  751. for (iter = priv->seen_bssids; iter; iter = iter->next) {
  752. if (!nm_utils_hwaddr_valid (iter->data, ETH_ALEN)) {
  753. g_set_error (error,
  754. NM_CONNECTION_ERROR,
  755. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  756. _("'%s' is not a valid MAC address"),
  757. (const char *) iter->data);
  758. g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_SEEN_BSSIDS);
  759. return FALSE;
  760. }
  761. }
  762. if (!NM_IN_SET (priv->mac_address_randomization,
  763. NM_SETTING_MAC_RANDOMIZATION_DEFAULT,
  764. NM_SETTING_MAC_RANDOMIZATION_NEVER,
  765. NM_SETTING_MAC_RANDOMIZATION_ALWAYS)) {
  766. g_set_error (error,
  767. NM_CONNECTION_ERROR,
  768. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  769. _("invalid value"));
  770. g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION);
  771. return FALSE;
  772. }
  773. if (NM_FLAGS_ANY (priv->wowl, NM_SETTING_WIRELESS_WAKE_ON_WLAN_EXCLUSIVE_FLAGS)) {
  774. if (!nm_utils_is_power_of_two (priv->wowl)) {
  775. g_set_error_literal (error,
  776. NM_CONNECTION_ERROR,
  777. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  778. _("Wake-on-WLAN mode 'default' and 'ignore' are exclusive flags"));
  779. g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME,
  780. NM_SETTING_WIRELESS_WAKE_ON_WLAN);
  781. return FALSE;
  782. }
  783. } else if (NM_FLAGS_ANY (priv->wowl, ~NM_SETTING_WIRELESS_WAKE_ON_WLAN_ALL)) {
  784. g_set_error_literal (error,
  785. NM_CONNECTION_ERROR,
  786. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  787. _("Wake-on-WLAN trying to set unknown flag"));
  788. g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME,
  789. NM_SETTING_WIRELESS_WAKE_ON_WLAN);
  790. return FALSE;
  791. }
  792. /* from here on, check for NM_SETTING_VERIFY_NORMALIZABLE conditions. */
  793. if (priv->cloned_mac_address) {
  794. if ( priv->mac_address_randomization == NM_SETTING_MAC_RANDOMIZATION_ALWAYS
  795. && nm_streq (priv->cloned_mac_address, "random"))
  796. goto mac_addr_rand_ok;
  797. if ( priv->mac_address_randomization == NM_SETTING_MAC_RANDOMIZATION_NEVER
  798. && nm_streq (priv->cloned_mac_address, "permanent"))
  799. goto mac_addr_rand_ok;
  800. if (priv->mac_address_randomization == NM_SETTING_MAC_RANDOMIZATION_DEFAULT)
  801. goto mac_addr_rand_ok;
  802. } else if (priv->mac_address_randomization == NM_SETTING_MAC_RANDOMIZATION_DEFAULT)
  803. goto mac_addr_rand_ok;
  804. g_set_error (error,
  805. NM_CONNECTION_ERROR,
  806. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  807. _("conflicting value of mac-address-randomization and cloned-mac-address"));
  808. g_prefix_error (error, "%s.%s: ", NM_SETTING_WIRELESS_SETTING_NAME, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS);
  809. return NM_SETTING_VERIFY_NORMALIZABLE;
  810. mac_addr_rand_ok:
  811. return TRUE;
  812. }
  813. static gboolean
  814. compare_property (NMSetting *setting,
  815. NMSetting *other,
  816. const GParamSpec *prop_spec,
  817. NMSettingCompareFlags flags)
  818. {
  819. NMSettingClass *setting_class;
  820. if (nm_streq (prop_spec->name, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS)) {
  821. return nm_streq0 (NM_SETTING_WIRELESS_GET_PRIVATE (setting)->cloned_mac_address,
  822. NM_SETTING_WIRELESS_GET_PRIVATE (other)->cloned_mac_address);
  823. }
  824. setting_class = NM_SETTING_CLASS (nm_setting_wireless_parent_class);
  825. return setting_class->compare_property (setting, other, prop_spec, flags);
  826. }
  827. /*****************************************************************************/
  828. static GVariant *
  829. nm_setting_wireless_get_security (NMSetting *setting,
  830. NMConnection *connection,
  831. const char *property_name)
  832. {
  833. if (nm_connection_get_setting_wireless_security (connection))
  834. return g_variant_new_string (NM_SETTING_WIRELESS_SECURITY_SETTING_NAME);
  835. else
  836. return NULL;
  837. }
  838. /**
  839. * nm_setting_wireless_get_wake_on_wlan:
  840. * @setting: the #NMSettingWireless
  841. *
  842. * Returns the Wake-on-WLAN options enabled for the connection
  843. *
  844. * Returns: the Wake-on-WLAN options
  845. *
  846. * Since: 1.12
  847. */
  848. NMSettingWirelessWakeOnWLan
  849. nm_setting_wireless_get_wake_on_wlan (NMSettingWireless *setting)
  850. {
  851. g_return_val_if_fail (NM_IS_SETTING_WIRELESS (setting), NM_SETTING_WIRELESS_WAKE_ON_WLAN_NONE);
  852. return NM_SETTING_WIRELESS_GET_PRIVATE (setting)->wowl;
  853. }
  854. static void
  855. clear_blacklist_item (char **item_p)
  856. {
  857. g_free (*item_p);
  858. }
  859. static void
  860. nm_setting_wireless_init (NMSettingWireless *setting)
  861. {
  862. NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (setting);
  863. /* We use GArray rather than GPtrArray so it will automatically be NULL-terminated */
  864. priv->mac_address_blacklist = g_array_new (TRUE, FALSE, sizeof (char *));
  865. g_array_set_clear_func (priv->mac_address_blacklist, (GDestroyNotify) clear_blacklist_item);
  866. }
  867. static void
  868. finalize (GObject *object)
  869. {
  870. NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (object);
  871. g_free (priv->mode);
  872. g_free (priv->band);
  873. if (priv->ssid)
  874. g_bytes_unref (priv->ssid);
  875. g_free (priv->bssid);
  876. g_free (priv->device_mac_address);
  877. g_free (priv->cloned_mac_address);
  878. g_free (priv->generate_mac_address_mask);
  879. g_array_unref (priv->mac_address_blacklist);
  880. g_slist_free_full (priv->seen_bssids, g_free);
  881. G_OBJECT_CLASS (nm_setting_wireless_parent_class)->finalize (object);
  882. }
  883. static void
  884. set_property (GObject *object, guint prop_id,
  885. const GValue *value, GParamSpec *pspec)
  886. {
  887. NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (object);
  888. const char * const *blacklist;
  889. const char *mac;
  890. gboolean bool_val;
  891. int i;
  892. switch (prop_id) {
  893. case PROP_SSID:
  894. if (priv->ssid)
  895. g_bytes_unref (priv->ssid);
  896. priv->ssid = g_value_dup_boxed (value);
  897. break;
  898. case PROP_MODE:
  899. g_free (priv->mode);
  900. priv->mode = g_value_dup_string (value);
  901. break;
  902. case PROP_BAND:
  903. g_free (priv->band);
  904. priv->band = g_value_dup_string (value);
  905. break;
  906. case PROP_CHANNEL:
  907. priv->channel = g_value_get_uint (value);
  908. break;
  909. case PROP_BSSID:
  910. g_free (priv->bssid);
  911. priv->bssid = g_value_dup_string (value);
  912. break;
  913. case PROP_RATE:
  914. priv->rate = g_value_get_uint (value);
  915. break;
  916. case PROP_TX_POWER:
  917. priv->tx_power = g_value_get_uint (value);
  918. break;
  919. case PROP_MAC_ADDRESS:
  920. g_free (priv->device_mac_address);
  921. priv->device_mac_address = _nm_utils_hwaddr_canonical_or_invalid (g_value_get_string (value),
  922. ETH_ALEN);
  923. break;
  924. case PROP_CLONED_MAC_ADDRESS:
  925. bool_val = !!priv->cloned_mac_address;
  926. g_free (priv->cloned_mac_address);
  927. priv->cloned_mac_address = _nm_utils_hwaddr_canonical_or_invalid (g_value_get_string (value),
  928. ETH_ALEN);
  929. if (bool_val && !priv->cloned_mac_address) {
  930. /* cloned-mac-address was set before but was now explicitly cleared.
  931. * In this case, we also clear mac-address-randomization flag */
  932. if (priv->mac_address_randomization != NM_SETTING_MAC_RANDOMIZATION_DEFAULT) {
  933. priv->mac_address_randomization = NM_SETTING_MAC_RANDOMIZATION_DEFAULT;
  934. g_object_notify (object, NM_SETTING_WIRELESS_MAC_ADDRESS);
  935. }
  936. }
  937. break;
  938. case PROP_GENERATE_MAC_ADDRESS_MASK:
  939. g_free (priv->generate_mac_address_mask);
  940. priv->generate_mac_address_mask = g_value_dup_string (value);
  941. break;
  942. case PROP_MAC_ADDRESS_BLACKLIST:
  943. blacklist = g_value_get_boxed (value);
  944. g_array_set_size (priv->mac_address_blacklist, 0);
  945. if (blacklist && *blacklist) {
  946. for (i = 0; blacklist[i]; i++) {
  947. mac = _nm_utils_hwaddr_canonical_or_invalid (blacklist[i], ETH_ALEN);
  948. g_array_append_val (priv->mac_address_blacklist, mac);
  949. }
  950. }
  951. break;
  952. case PROP_MTU:
  953. priv->mtu = g_value_get_uint (value);
  954. break;
  955. case PROP_SEEN_BSSIDS:
  956. g_slist_free_full (priv->seen_bssids, g_free);
  957. priv->seen_bssids = _nm_utils_strv_to_slist (g_value_get_boxed (value), TRUE);
  958. break;
  959. case PROP_HIDDEN:
  960. priv->hidden = g_value_get_boolean (value);
  961. break;
  962. case PROP_POWERSAVE:
  963. priv->powersave = g_value_get_uint (value);
  964. break;
  965. case PROP_MAC_ADDRESS_RANDOMIZATION:
  966. priv->mac_address_randomization = g_value_get_uint (value);
  967. break;
  968. case PROP_WAKE_ON_WLAN:
  969. priv->wowl = g_value_get_uint (value);
  970. break;
  971. default:
  972. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  973. break;
  974. }
  975. }
  976. static void
  977. get_property (GObject *object, guint prop_id,
  978. GValue *value, GParamSpec *pspec)
  979. {
  980. NMSettingWireless *setting = NM_SETTING_WIRELESS (object);
  981. NMSettingWirelessPrivate *priv = NM_SETTING_WIRELESS_GET_PRIVATE (object);
  982. switch (prop_id) {
  983. case PROP_SSID:
  984. g_value_set_boxed (value, nm_setting_wireless_get_ssid (setting));
  985. break;
  986. case PROP_MODE:
  987. g_value_set_string (value, nm_setting_wireless_get_mode (setting));
  988. break;
  989. case PROP_BAND:
  990. g_value_set_string (value, nm_setting_wireless_get_band (setting));
  991. break;
  992. case PROP_CHANNEL:
  993. g_value_set_uint (value, nm_setting_wireless_get_channel (setting));
  994. break;
  995. case PROP_BSSID:
  996. g_value_set_string (value, nm_setting_wireless_get_bssid (setting));
  997. break;
  998. case PROP_RATE:
  999. g_value_set_uint (value, nm_setting_wireless_get_rate (setting));
  1000. break;
  1001. case PROP_TX_POWER:
  1002. g_value_set_uint (value, nm_setting_wireless_get_tx_power (setting));
  1003. break;
  1004. case PROP_MAC_ADDRESS:
  1005. g_value_set_string (value, nm_setting_wireless_get_mac_address (setting));
  1006. break;
  1007. case PROP_CLONED_MAC_ADDRESS:
  1008. g_value_set_string (value, nm_setting_wireless_get_cloned_mac_address (setting));
  1009. break;
  1010. case PROP_GENERATE_MAC_ADDRESS_MASK:
  1011. g_value_set_string (value, nm_setting_wireless_get_generate_mac_address_mask (setting));
  1012. break;
  1013. case PROP_MAC_ADDRESS_BLACKLIST:
  1014. g_value_set_boxed (value, (char **) priv->mac_address_blacklist->data);
  1015. break;
  1016. case PROP_MTU:
  1017. g_value_set_uint (value, nm_setting_wireless_get_mtu (setting));
  1018. break;
  1019. case PROP_SEEN_BSSIDS:
  1020. g_value_take_boxed (value, _nm_utils_slist_to_strv (priv->seen_bssids, TRUE));
  1021. break;
  1022. case PROP_HIDDEN:
  1023. g_value_set_boolean (value, nm_setting_wireless_get_hidden (setting));
  1024. break;
  1025. case PROP_POWERSAVE:
  1026. g_value_set_uint (value, nm_setting_wireless_get_powersave (setting));
  1027. break;
  1028. case PROP_MAC_ADDRESS_RANDOMIZATION:
  1029. g_value_set_uint (value, nm_setting_wireless_get_mac_address_randomization (setting));
  1030. break;
  1031. case PROP_WAKE_ON_WLAN:
  1032. g_value_set_uint (value, nm_setting_wireless_get_wake_on_wlan (setting));
  1033. break;
  1034. default:
  1035. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  1036. break;
  1037. }
  1038. }
  1039. static void
  1040. nm_setting_wireless_class_init (NMSettingWirelessClass *klass)
  1041. {
  1042. GObjectClass *object_class = G_OBJECT_CLASS (klass);
  1043. NMSettingClass *setting_class = NM_SETTING_CLASS (klass);
  1044. GArray *properties_override = _nm_sett_info_property_override_create_array ();
  1045. g_type_class_add_private (klass, sizeof (NMSettingWirelessPrivate));
  1046. object_class->set_property = set_property;
  1047. object_class->get_property = get_property;
  1048. object_class->finalize = finalize;
  1049. setting_class->verify = verify;
  1050. setting_class->compare_property = compare_property;
  1051. /**
  1052. * NMSettingWireless:ssid:
  1053. *
  1054. * SSID of the Wi-Fi network. Must be specified.
  1055. **/
  1056. /* ---keyfile---
  1057. * property: ssid
  1058. * format: string (or decimal-byte list - obsolete)
  1059. * description: SSID of Wi-Fi network.
  1060. * example: ssid=Quick Net
  1061. * ---end---
  1062. * ---ifcfg-rh---
  1063. * property: ssid
  1064. * variable: ESSID
  1065. * description: SSID of Wi-Fi network.
  1066. * example: ESSID="Quick Net"
  1067. * ---end---
  1068. */
  1069. g_object_class_install_property
  1070. (object_class, PROP_SSID,
  1071. g_param_spec_boxed (NM_SETTING_WIRELESS_SSID, "", "",
  1072. G_TYPE_BYTES,
  1073. G_PARAM_READWRITE |
  1074. G_PARAM_STATIC_STRINGS));
  1075. /**
  1076. * NMSettingWireless:mode:
  1077. *
  1078. * Wi-Fi network mode; one of "infrastructure", "adhoc" or "ap". If blank,
  1079. * infrastructure is assumed.
  1080. **/
  1081. /* ---ifcfg-rh---
  1082. * property: mode
  1083. * variable: MODE
  1084. * values: Ad-Hoc, Managed (Auto) [case insensitive]
  1085. * description: Wi-Fi network mode.
  1086. * ---end---
  1087. */
  1088. g_object_class_install_property
  1089. (object_class, PROP_MODE,
  1090. g_param_spec_string (NM_SETTING_WIRELESS_MODE, "", "",
  1091. NULL,
  1092. G_PARAM_READWRITE |
  1093. G_PARAM_STATIC_STRINGS));
  1094. /**
  1095. * NMSettingWireless:band:
  1096. *
  1097. * 802.11 frequency band of the network. One of "a" for 5GHz 802.11a or
  1098. * "bg" for 2.4GHz 802.11. This will lock associations to the Wi-Fi network
  1099. * to the specific band, i.e. if "a" is specified, the device will not
  1100. * associate with the same network in the 2.4GHz band even if the network's
  1101. * settings are compatible. This setting depends on specific driver
  1102. * capability and may not work with all drivers.
  1103. **/
  1104. /* ---ifcfg-rh---
  1105. * property: band
  1106. * variable: BAND(+)
  1107. * values: a, bg
  1108. * description: BAND alone is honored, but CHANNEL overrides BAND since it
  1109. * implies a band.
  1110. * example: BAND=bg
  1111. * ---end---
  1112. */
  1113. g_object_class_install_property
  1114. (object_class, PROP_BAND,
  1115. g_param_spec_string (NM_SETTING_WIRELESS_BAND, "", "",
  1116. NULL,
  1117. G_PARAM_READWRITE |
  1118. G_PARAM_STATIC_STRINGS));
  1119. /**
  1120. * NMSettingWireless:channel:
  1121. *
  1122. * Wireless channel to use for the Wi-Fi connection. The device will only
  1123. * join (or create for Ad-Hoc networks) a Wi-Fi network on the specified
  1124. * channel. Because channel numbers overlap between bands, this property
  1125. * also requires the "band" property to be set.
  1126. **/
  1127. /* ---ifcfg-rh---
  1128. * property: channel
  1129. * variable: CHANNEL
  1130. * description: Channel used for the Wi-Fi communication.
  1131. * Channels greater than 14 mean "a" band, otherwise the
  1132. * band is "bg".
  1133. * example: CHANNEL=6
  1134. * ---end---
  1135. */
  1136. g_object_class_install_property
  1137. (object_class, PROP_CHANNEL,
  1138. g_param_spec_uint (NM_SETTING_WIRELESS_CHANNEL, "", "",
  1139. 0, G_MAXUINT32, 0,
  1140. G_PARAM_READWRITE |
  1141. G_PARAM_CONSTRUCT |
  1142. G_PARAM_STATIC_STRINGS));
  1143. /**
  1144. * NMSettingWireless:bssid:
  1145. *
  1146. * If specified, directs the device to only associate with the given access
  1147. * point. This capability is highly driver dependent and not supported by
  1148. * all devices. Note: this property does not control the BSSID used when
  1149. * creating an Ad-Hoc network and is unlikely to in the future.
  1150. **/
  1151. /* ---ifcfg-rh---
  1152. * property: bssid
  1153. * variable: BSSID(+)
  1154. * description: Restricts association only to a single AP.
  1155. * example: BSSID=00:1E:BD:64:83:21
  1156. * ---end---
  1157. */
  1158. g_object_class_install_property
  1159. (object_class, PROP_BSSID,
  1160. g_param_spec_string (NM_SETTING_WIRELESS_BSSID, "", "",
  1161. NULL,
  1162. G_PARAM_READWRITE |
  1163. G_PARAM_STATIC_STRINGS));
  1164. _properties_override_add_transform (properties_override,
  1165. g_object_class_find_property (G_OBJECT_CLASS (setting_class),
  1166. NM_SETTING_WIRELESS_BSSID),
  1167. G_VARIANT_TYPE_BYTESTRING,
  1168. _nm_utils_hwaddr_to_dbus,
  1169. _nm_utils_hwaddr_from_dbus);
  1170. /**
  1171. * NMSettingWireless:rate:
  1172. *
  1173. * If non-zero, directs the device to only use the specified bitrate for
  1174. * communication with the access point. Units are in Kb/s, ie 5500 = 5.5
  1175. * Mbit/s. This property is highly driver dependent and not all devices
  1176. * support setting a static bitrate.
  1177. **/
  1178. /* ---ifcfg-rh---
  1179. * property: rate
  1180. * variable: (none)
  1181. * description: This property is not handled by ifcfg-rh plugin.
  1182. * ---end---
  1183. */
  1184. g_object_class_install_property
  1185. (object_class, PROP_RATE,
  1186. g_param_spec_uint (NM_SETTING_WIRELESS_RATE, "", "",
  1187. 0, G_MAXUINT32, 0,
  1188. G_PARAM_READWRITE |
  1189. G_PARAM_CONSTRUCT |
  1190. NM_SETTING_PARAM_FUZZY_IGNORE |
  1191. G_PARAM_STATIC_STRINGS));
  1192. /**
  1193. * NMSettingWireless:tx-power:
  1194. *
  1195. * If non-zero, directs the device to use the specified transmit power.
  1196. * Units are dBm. This property is highly driver dependent and not all
  1197. * devices support setting a static transmit power.
  1198. **/
  1199. /* ---ifcfg-rh---
  1200. * property: tx-power
  1201. * variable: (none)
  1202. * description: This property is not handled by ifcfg-rh plugin.
  1203. * ---end---
  1204. */
  1205. g_object_class_install_property
  1206. (object_class, PROP_TX_POWER,
  1207. g_param_spec_uint (NM_SETTING_WIRELESS_TX_POWER, "", "",
  1208. 0, G_MAXUINT32, 0,
  1209. G_PARAM_READWRITE |
  1210. G_PARAM_CONSTRUCT |
  1211. NM_SETTING_PARAM_FUZZY_IGNORE |
  1212. G_PARAM_STATIC_STRINGS));
  1213. /**
  1214. * NMSettingWireless:mac-address:
  1215. *
  1216. * If specified, this connection will only apply to the Wi-Fi device whose
  1217. * permanent MAC address matches. This property does not change the MAC
  1218. * address of the device (i.e. MAC spoofing).
  1219. **/
  1220. /* ---keyfile---
  1221. * property: mac-address
  1222. * format: usual hex-digits-and-colons notation
  1223. * description: MAC address in traditional hex-digits-and-colons notation
  1224. * (e.g. 00:22:68:12:79:A2), or semicolon separated list of 6 bytes (obsolete)
  1225. * (e.g. 0;34;104;18;121;162).
  1226. * ---end---
  1227. * ---ifcfg-rh---
  1228. * property: mac-address
  1229. * variable: HWADDR
  1230. * description: Hardware address of the device in traditional hex-digits-and-colons
  1231. * notation (e.g. 00:22:68:14:5A:05).
  1232. * Note that for initscripts this is the current MAC address of the device as found
  1233. * during ifup. For NetworkManager this is the permanent MAC address. Or in case no
  1234. * permanent MAC address exists, the MAC address initially configured on the device.
  1235. * ---end---
  1236. */
  1237. g_object_class_install_property
  1238. (object_class, PROP_MAC_ADDRESS,
  1239. g_param_spec_string (NM_SETTING_WIRELESS_MAC_ADDRESS, "", "",
  1240. NULL,
  1241. G_PARAM_READWRITE |
  1242. G_PARAM_STATIC_STRINGS));
  1243. _properties_override_add_transform (properties_override,
  1244. g_object_class_find_property (G_OBJECT_CLASS (setting_class),
  1245. NM_SETTING_WIRELESS_MAC_ADDRESS),
  1246. G_VARIANT_TYPE_BYTESTRING,
  1247. _nm_utils_hwaddr_to_dbus,
  1248. _nm_utils_hwaddr_from_dbus);
  1249. /**
  1250. * NMSettingWireless:cloned-mac-address:
  1251. *
  1252. * If specified, request that the device use this MAC address instead.
  1253. * This is known as MAC cloning or spoofing.
  1254. *
  1255. * Beside explicitly specifying a MAC address, the special values "preserve", "permanent",
  1256. * "random" and "stable" are supported.
  1257. * "preserve" means not to touch the MAC address on activation.
  1258. * "permanent" means to use the permanent hardware address of the device.
  1259. * "random" creates a random MAC address on each connect.
  1260. * "stable" creates a hashed MAC address based on connection.stable-id and a
  1261. * machine dependent key.
  1262. *
  1263. * If unspecified, the value can be overwritten via global defaults, see manual
  1264. * of NetworkManager.conf. If still unspecified, it defaults to "preserve"
  1265. * (older versions of NetworkManager may use a different default value).
  1266. *
  1267. * On D-Bus, this field is expressed as "assigned-mac-address" or the deprecated
  1268. * "cloned-mac-address".
  1269. **/
  1270. /* ---keyfile---
  1271. * property: cloned-mac-address
  1272. * format: usual hex-digits-and-colons notation
  1273. * description: Cloned MAC address in traditional hex-digits-and-colons notation
  1274. * (e.g. 00:22:68:12:79:B2), or semicolon separated list of 6 bytes (obsolete)
  1275. * (e.g. 0;34;104;18;121;178).
  1276. * ---end---
  1277. * ---ifcfg-rh---
  1278. * property: cloned-mac-address
  1279. * variable: MACADDR
  1280. * description: Cloned (spoofed) MAC address in traditional hex-digits-and-colons
  1281. * notation (e.g. 00:22:68:14:5A:99).
  1282. * ---end---
  1283. * ---dbus---
  1284. * property: cloned-mac-address
  1285. * format: byte array
  1286. * description: This D-Bus field is deprecated in favor of "assigned-mac-address"
  1287. * which is more flexible and allows specifying special variants like "random".
  1288. * For libnm and nmcli, this field is called "cloned-mac-address".
  1289. * ---end---
  1290. */
  1291. g_object_class_install_property
  1292. (object_class, PROP_CLONED_MAC_ADDRESS,
  1293. g_param_spec_string (NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, "", "",
  1294. NULL,
  1295. G_PARAM_READWRITE |
  1296. G_PARAM_STATIC_STRINGS));
  1297. _properties_override_add_override (properties_override,
  1298. g_object_class_find_property (G_OBJECT_CLASS (setting_class),
  1299. NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS),
  1300. G_VARIANT_TYPE_BYTESTRING,
  1301. _nm_utils_hwaddr_cloned_get,
  1302. _nm_utils_hwaddr_cloned_set,
  1303. _nm_utils_hwaddr_cloned_not_set);
  1304. /* ---dbus---
  1305. * property: assigned-mac-address
  1306. * format: string
  1307. * description: The new field for the cloned MAC address. It can be either
  1308. * a hardware address in ASCII representation, or one of the special values
  1309. * "preserve", "permanent", "random" or "stable".
  1310. * This field replaces the deprecated "cloned-mac-address" on D-Bus, which
  1311. * can only contain explicit hardware addresses. Note that this property
  1312. * only exists in D-Bus API. libnm and nmcli continue to call this property
  1313. * "cloned-mac-address".
  1314. * ---end---
  1315. */
  1316. _properties_override_add_dbus_only (properties_override,
  1317. "assigned-mac-address",
  1318. G_VARIANT_TYPE_STRING,
  1319. _nm_utils_hwaddr_cloned_data_synth,
  1320. _nm_utils_hwaddr_cloned_data_set);
  1321. /**
  1322. * NMSettingWireless:generate-mac-address-mask:
  1323. *
  1324. * With #NMSettingWireless:cloned-mac-address setting "random" or "stable",
  1325. * by default all bits of the MAC address are scrambled and a locally-administered,
  1326. * unicast MAC address is created. This property allows to specify that certain bits
  1327. * are fixed. Note that the least significant bit of the first MAC address will
  1328. * always be unset to create a unicast MAC address.
  1329. *
  1330. * If the property is %NULL, it is eligible to be overwritten by a default
  1331. * connection setting. If the value is still %NULL or an empty string, the
  1332. * default is to create a locally-administered, unicast MAC address.
  1333. *
  1334. * If the value contains one MAC address, this address is used as mask. The set
  1335. * bits of the mask are to be filled with the current MAC address of the device,
  1336. * while the unset bits are subject to randomization.
  1337. * Setting "FE:FF:FF:00:00:00" means to preserve the OUI of the current MAC address
  1338. * and only randomize the lower 3 bytes using the "random" or "stable" algorithm.
  1339. *
  1340. * If the value contains one additional MAC address after the mask,
  1341. * this address is used instead of the current MAC address to fill the bits
  1342. * that shall not be randomized. For example, a value of
  1343. * "FE:FF:FF:00:00:00 68:F7:28:00:00:00" will set the OUI of the MAC address
  1344. * to 68:F7:28, while the lower bits are randomized. A value of
  1345. * "02:00:00:00:00:00 00:00:00:00:00:00" will create a fully scrambled
  1346. * globally-administered, burned-in MAC address.
  1347. *
  1348. * If the value contains more than one additional MAC addresses, one of
  1349. * them is chosen randomly. For example, "02:00:00:00:00:00 00:00:00:00:00:00 02:00:00:00:00:00"
  1350. * will create a fully scrambled MAC address, randomly locally or globally
  1351. * administered.
  1352. **/
  1353. /* ---ifcfg-rh---
  1354. * property: generate-mac-address-mask
  1355. * variable: GENERATE_MAC_ADDRESS_MASK(+)
  1356. * description: the MAC address mask for generating randomized and stable
  1357. * cloned-mac-address.
  1358. * ---end---
  1359. */
  1360. g_object_class_install_property
  1361. (object_class, PROP_GENERATE_MAC_ADDRESS_MASK,
  1362. g_param_spec_string (NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK, "", "",
  1363. NULL,
  1364. G_PARAM_READWRITE |
  1365. NM_SETTING_PARAM_FUZZY_IGNORE |
  1366. G_PARAM_STATIC_STRINGS));
  1367. /**
  1368. * NMSettingWireless:mac-address-blacklist:
  1369. *
  1370. * A list of permanent MAC addresses of Wi-Fi devices to which this
  1371. * connection should never apply. Each MAC address should be given in the
  1372. * standard hex-digits-and-colons notation (eg "00:11:22:33:44:55").
  1373. **/
  1374. /* ---keyfile---
  1375. * property: mac-address-blacklist
  1376. * format: list of MACs (separated with semicolons)
  1377. * description: MAC address blacklist.
  1378. * example: mac-address-blacklist= 00:22:68:12:79:A6;00:22:68:12:79:78
  1379. * ---end---
  1380. * ---ifcfg-rh---
  1381. * property: mac-address-blacklist
  1382. * variable: HWADDR_BLACKLIST(+)
  1383. * description: It denies usage of the connection for any device whose address
  1384. * is listed.
  1385. * ---end---
  1386. */
  1387. g_object_class_install_property
  1388. (object_class, PROP_MAC_ADDRESS_BLACKLIST,
  1389. g_param_spec_boxed (NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST, "", "",
  1390. G_TYPE_STRV,
  1391. G_PARAM_READWRITE |
  1392. NM_SETTING_PARAM_FUZZY_IGNORE |
  1393. G_PARAM_STATIC_STRINGS));
  1394. /**
  1395. * NMSettingWireless:seen-bssids:
  1396. *
  1397. * A list of BSSIDs (each BSSID formatted as a MAC address like
  1398. * "00:11:22:33:44:55") that have been detected as part of the Wi-Fi
  1399. * network. NetworkManager internally tracks previously seen BSSIDs. The
  1400. * property is only meant for reading and reflects the BSSID list of
  1401. * NetworkManager. The changes you make to this property will not be
  1402. * preserved.
  1403. **/
  1404. /* ---ifcfg-rh---
  1405. * property: seen-bssids
  1406. * variable: (none)
  1407. * description: This property is not handled by ifcfg-rh plugin.
  1408. * ---end---
  1409. */
  1410. g_object_class_install_property
  1411. (object_class, PROP_SEEN_BSSIDS,
  1412. g_param_spec_boxed (NM_SETTING_WIRELESS_SEEN_BSSIDS, "", "",
  1413. G_TYPE_STRV,
  1414. G_PARAM_READWRITE |
  1415. NM_SETTING_PARAM_FUZZY_IGNORE |
  1416. G_PARAM_STATIC_STRINGS));
  1417. /**
  1418. * NMSettingWireless:mtu:
  1419. *
  1420. * If non-zero, only transmit packets of the specified size or smaller,
  1421. * breaking larger packets up into multiple Ethernet frames.
  1422. **/
  1423. /* ---ifcfg-rh---
  1424. * property: mtu
  1425. * variable: MTU
  1426. * description: MTU of the wireless interface.
  1427. * ---end---
  1428. */
  1429. g_object_class_install_property
  1430. (object_class, PROP_MTU,
  1431. g_param_spec_uint (NM_SETTING_WIRELESS_MTU, "", "",
  1432. 0, G_MAXUINT32, 0,
  1433. G_PARAM_READWRITE |
  1434. G_PARAM_CONSTRUCT |
  1435. NM_SETTING_PARAM_FUZZY_IGNORE |
  1436. G_PARAM_STATIC_STRINGS));
  1437. /**
  1438. * NMSettingWireless:hidden:
  1439. *
  1440. * If %TRUE, indicates this network is a non-broadcasting network that hides
  1441. * its SSID. In this case various workarounds may take place, such as
  1442. * probe-scanning the SSID for more reliable network discovery. However,
  1443. * these workarounds expose inherent insecurities with hidden SSID networks,
  1444. * and thus hidden SSID networks should be used with caution.
  1445. *
  1446. * Note that marking the network as hidden may be a privacy issue for you, as
  1447. * the explicit probe-scans may be distinctly recognizable on the air.
  1448. **/
  1449. /* ---ifcfg-rh---
  1450. * property: hidden
  1451. * variable: SSID_HIDDEN(+)
  1452. * description: Whether the network hides the SSID.
  1453. * ---end---
  1454. */
  1455. g_object_class_install_property
  1456. (object_class, PROP_HIDDEN,
  1457. g_param_spec_boolean (NM_SETTING_WIRELESS_HIDDEN, "", "",
  1458. FALSE,
  1459. G_PARAM_READWRITE |
  1460. G_PARAM_STATIC_STRINGS));
  1461. /**
  1462. * NMSettingWireless:powersave:
  1463. *
  1464. * One of %NM_SETTING_WIRELESS_POWERSAVE_DISABLE (disable Wi-Fi power
  1465. * saving), %NM_SETTING_WIRELESS_POWERSAVE_ENABLE (enable Wi-Fi power
  1466. * saving), %NM_SETTING_WIRELESS_POWERSAVE_IGNORE (don't touch currently
  1467. * configure setting) or %NM_SETTING_WIRELESS_POWERSAVE_DEFAULT (use the
  1468. * globally configured value). All other values are reserved.
  1469. *
  1470. * Since: 1.2
  1471. **/
  1472. /* ---ifcfg-rh---
  1473. * property: powersave
  1474. * variable: POWERSAVE(+)
  1475. * values: default, ignore, enable, disable
  1476. * description: Enables or disables Wi-Fi power saving.
  1477. * example: POWERSAVE=enable
  1478. * ---end---
  1479. */
  1480. g_object_class_install_property
  1481. (object_class, PROP_POWERSAVE,
  1482. g_param_spec_uint (NM_SETTING_WIRELESS_POWERSAVE, "", "",
  1483. 0, G_MAXUINT32, NM_SETTING_WIRELESS_POWERSAVE_DEFAULT,
  1484. G_PARAM_READWRITE |
  1485. G_PARAM_STATIC_STRINGS));
  1486. /**
  1487. * NMSettingWireless:mac-address-randomization:
  1488. *
  1489. * One of %NM_SETTING_MAC_RANDOMIZATION_DEFAULT (never randomize unless
  1490. * the user has set a global default to randomize and the supplicant
  1491. * supports randomization), %NM_SETTING_MAC_RANDOMIZATION_NEVER (never
  1492. * randomize the MAC address), or %NM_SETTING_MAC_RANDOMIZATION_ALWAYS
  1493. * (always randomize the MAC address). This property is deprecated for
  1494. * 'cloned-mac-address'.
  1495. *
  1496. * Since: 1.2
  1497. * Deprecated: 1.4: Deprecated by NMSettingWireless:cloned-mac-address property
  1498. **/
  1499. /* ---ifcfg-rh---
  1500. * property: mac-address-randomization
  1501. * variable: MAC_ADDRESS_RANDOMIZATION(+)
  1502. * values: default, never, always
  1503. * description: Enables or disables Wi-Fi MAC address randomization.
  1504. * example: MAC_ADDRESS_RANDOMIZATION=always
  1505. * ---end---
  1506. */
  1507. g_object_class_install_property
  1508. (object_class, PROP_MAC_ADDRESS_RANDOMIZATION,
  1509. g_param_spec_uint (NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION, "", "",
  1510. 0, G_MAXUINT32, NM_SETTING_MAC_RANDOMIZATION_DEFAULT,
  1511. G_PARAM_READWRITE |
  1512. G_PARAM_STATIC_STRINGS));
  1513. /* Compatibility for deprecated property */
  1514. /* ---ifcfg-rh---
  1515. * property: security
  1516. * variable: (none)
  1517. * description: This property is deprecated and not handled by ifcfg-rh-plugin.
  1518. * ---end---
  1519. * ---dbus---
  1520. * property: security
  1521. * description: This property is deprecated, but can be set to the value
  1522. * '802-11-wireless-security' when a wireless security setting is also
  1523. * present in the connection dictionary, for compatibility with very old
  1524. * NetworkManager daemons.
  1525. * ---end---
  1526. */
  1527. _properties_override_add_dbus_only (properties_override,
  1528. "security",
  1529. G_VARIANT_TYPE_STRING,
  1530. nm_setting_wireless_get_security,
  1531. NULL);
  1532. /**
  1533. * NMSettingWireless:wake-on-wlan:
  1534. *
  1535. * The #NMSettingWirelessWakeOnWLan options to enable. Not all devices support all options.
  1536. * May be any combination of %NM_SETTING_WIRELESS_WAKE_ON_WLAN_ANY,
  1537. * %NM_SETTING_WIRELESS_WAKE_ON_WLAN_DISCONNECT,
  1538. * %NM_SETTING_WIRELESS_WAKE_ON_WLAN_MAGIC,
  1539. * %NM_SETTING_WIRELESS_WAKE_ON_WLAN_GTK_REKEY_FAILURE,
  1540. * %NM_SETTING_WIRELESS_WAKE_ON_WLAN_EAP_IDENTITY_REQUEST,
  1541. * %NM_SETTING_WIRELESS_WAKE_ON_WLAN_4WAY_HANDSHAKE,
  1542. * %NM_SETTING_WIRELESS_WAKE_ON_WLAN_RFKILL_RELEASE,
  1543. * %NM_SETTING_WIRELESS_WAKE_ON_WLAN_TCP or the special values
  1544. * %NM_SETTING_WIRELESS_WAKE_ON_WLAN_DEFAULT (to use global settings) and
  1545. * %NM_SETTING_WIRELESS_WAKE_ON_WLAN_IGNORE (to disable management of Wake-on-LAN in
  1546. * NetworkManager).
  1547. *
  1548. * Since: 1.12
  1549. **/
  1550. g_object_class_install_property
  1551. (object_class, PROP_WAKE_ON_WLAN,
  1552. g_param_spec_uint (NM_SETTING_WIRELESS_WAKE_ON_WLAN, "", "",
  1553. 0, G_MAXUINT32, NM_SETTING_WIRELESS_WAKE_ON_WLAN_DEFAULT,
  1554. G_PARAM_CONSTRUCT |
  1555. G_PARAM_READWRITE |
  1556. G_PARAM_STATIC_STRINGS));
  1557. _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_WIRELESS,
  1558. NULL, properties_override);
  1559. }