nm-setting-gsm.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  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 - 2013 Red Hat, Inc.
  19. * Copyright 2007 - 2008 Novell, Inc.
  20. */
  21. #include "nm-default.h"
  22. #include <string.h>
  23. #include "nm-setting-gsm.h"
  24. #include "nm-utils.h"
  25. #include "nm-setting-private.h"
  26. #include "nm-core-enum-types.h"
  27. /**
  28. * SECTION:nm-setting-gsm
  29. * @short_description: Describes GSM/3GPP-based mobile broadband properties
  30. *
  31. * The #NMSettingGsm object is a #NMSetting subclass that describes
  32. * properties that allow connections to 3GPP-based mobile broadband
  33. * networks, including those using GPRS/EDGE and UMTS/HSPA technology.
  34. */
  35. G_DEFINE_TYPE (NMSettingGsm, nm_setting_gsm, NM_TYPE_SETTING)
  36. #define NM_SETTING_GSM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_GSM, NMSettingGsmPrivate))
  37. typedef struct {
  38. char *number; /* For dialing, duh */
  39. char *username;
  40. char *password;
  41. NMSettingSecretFlags password_flags;
  42. /* Restrict connection to certain devices or SIMs */
  43. char *device_id;
  44. char *sim_id;
  45. char *sim_operator_id;
  46. char *apn; /* NULL for dynamic */
  47. char *network_id; /* for manual registration or NULL for automatic */
  48. char *pin;
  49. NMSettingSecretFlags pin_flags;
  50. gboolean home_only;
  51. guint32 mtu;
  52. } NMSettingGsmPrivate;
  53. enum {
  54. PROP_0,
  55. PROP_NUMBER,
  56. PROP_USERNAME,
  57. PROP_PASSWORD,
  58. PROP_PASSWORD_FLAGS,
  59. PROP_APN,
  60. PROP_NETWORK_ID,
  61. PROP_PIN,
  62. PROP_PIN_FLAGS,
  63. PROP_HOME_ONLY,
  64. PROP_DEVICE_ID,
  65. PROP_SIM_ID,
  66. PROP_SIM_OPERATOR_ID,
  67. PROP_MTU,
  68. LAST_PROP
  69. };
  70. /**
  71. * nm_setting_gsm_new:
  72. *
  73. * Creates a new #NMSettingGsm object with default values.
  74. *
  75. * Returns: the new empty #NMSettingGsm object
  76. **/
  77. NMSetting *
  78. nm_setting_gsm_new (void)
  79. {
  80. return (NMSetting *) g_object_new (NM_TYPE_SETTING_GSM, NULL);
  81. }
  82. /**
  83. * nm_setting_gsm_get_number:
  84. * @setting: the #NMSettingGsm
  85. *
  86. * Returns: the #NMSettingGsm:number property of the setting
  87. **/
  88. const char *
  89. nm_setting_gsm_get_number (NMSettingGsm *setting)
  90. {
  91. g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
  92. return NM_SETTING_GSM_GET_PRIVATE (setting)->number;
  93. }
  94. /**
  95. * nm_setting_gsm_get_username:
  96. * @setting: the #NMSettingGsm
  97. *
  98. * Returns: the #NMSettingGsm:username property of the setting
  99. **/
  100. const char *
  101. nm_setting_gsm_get_username (NMSettingGsm *setting)
  102. {
  103. g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
  104. return NM_SETTING_GSM_GET_PRIVATE (setting)->username;
  105. }
  106. /**
  107. * nm_setting_gsm_get_password:
  108. * @setting: the #NMSettingGsm
  109. *
  110. * Returns: the #NMSettingGsm:password property of the setting
  111. **/
  112. const char *
  113. nm_setting_gsm_get_password (NMSettingGsm *setting)
  114. {
  115. g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
  116. return NM_SETTING_GSM_GET_PRIVATE (setting)->password;
  117. }
  118. /**
  119. * nm_setting_gsm_get_password_flags:
  120. * @setting: the #NMSettingGsm
  121. *
  122. * Returns: the #NMSettingSecretFlags pertaining to the #NMSettingGsm:password
  123. **/
  124. NMSettingSecretFlags
  125. nm_setting_gsm_get_password_flags (NMSettingGsm *setting)
  126. {
  127. g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NM_SETTING_SECRET_FLAG_NONE);
  128. return NM_SETTING_GSM_GET_PRIVATE (setting)->password_flags;
  129. }
  130. /**
  131. * nm_setting_gsm_get_apn:
  132. * @setting: the #NMSettingGsm
  133. *
  134. * Returns: the #NMSettingGsm:apn property of the setting
  135. **/
  136. const char *
  137. nm_setting_gsm_get_apn (NMSettingGsm *setting)
  138. {
  139. g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
  140. return NM_SETTING_GSM_GET_PRIVATE (setting)->apn;
  141. }
  142. /**
  143. * nm_setting_gsm_get_network_id:
  144. * @setting: the #NMSettingGsm
  145. *
  146. * Returns: the #NMSettingGsm:network-id property of the setting
  147. **/
  148. const char *
  149. nm_setting_gsm_get_network_id (NMSettingGsm *setting)
  150. {
  151. g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
  152. return NM_SETTING_GSM_GET_PRIVATE (setting)->network_id;
  153. }
  154. /**
  155. * nm_setting_gsm_get_pin:
  156. * @setting: the #NMSettingGsm
  157. *
  158. * Returns: the #NMSettingGsm:pin property of the setting
  159. **/
  160. const char *
  161. nm_setting_gsm_get_pin (NMSettingGsm *setting)
  162. {
  163. g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
  164. return NM_SETTING_GSM_GET_PRIVATE (setting)->pin;
  165. }
  166. /**
  167. * nm_setting_gsm_get_pin_flags:
  168. * @setting: the #NMSettingGsm
  169. *
  170. * Returns: the #NMSettingSecretFlags pertaining to the #NMSettingGsm:pin
  171. **/
  172. NMSettingSecretFlags
  173. nm_setting_gsm_get_pin_flags (NMSettingGsm *setting)
  174. {
  175. g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NM_SETTING_SECRET_FLAG_NONE);
  176. return NM_SETTING_GSM_GET_PRIVATE (setting)->pin_flags;
  177. }
  178. /**
  179. * nm_setting_gsm_get_home_only:
  180. * @setting: the #NMSettingGsm
  181. *
  182. * Returns: the #NMSettingGsm:home-only property of the setting
  183. **/
  184. gboolean
  185. nm_setting_gsm_get_home_only (NMSettingGsm *setting)
  186. {
  187. g_return_val_if_fail (NM_IS_SETTING_GSM (setting), FALSE);
  188. return NM_SETTING_GSM_GET_PRIVATE (setting)->home_only;
  189. }
  190. /**
  191. * nm_setting_gsm_get_device_id:
  192. * @setting: the #NMSettingGsm
  193. *
  194. * Returns: the #NMSettingGsm:device-id property of the setting
  195. *
  196. * Since: 1.2
  197. **/
  198. const char *
  199. nm_setting_gsm_get_device_id (NMSettingGsm *setting)
  200. {
  201. g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
  202. return NM_SETTING_GSM_GET_PRIVATE (setting)->device_id;
  203. }
  204. /**
  205. * nm_setting_gsm_get_sim_id:
  206. * @setting: the #NMSettingGsm
  207. *
  208. * Returns: the #NMSettingGsm:sim-id property of the setting
  209. *
  210. * Since: 1.2
  211. **/
  212. const char *
  213. nm_setting_gsm_get_sim_id (NMSettingGsm *setting)
  214. {
  215. g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
  216. return NM_SETTING_GSM_GET_PRIVATE (setting)->sim_id;
  217. }
  218. /**
  219. * nm_setting_gsm_get_sim_operator_id:
  220. * @setting: the #NMSettingGsm
  221. *
  222. * Returns: the #NMSettingGsm:sim-operator-id property of the setting
  223. *
  224. * Since: 1.2
  225. **/
  226. const char *
  227. nm_setting_gsm_get_sim_operator_id (NMSettingGsm *setting)
  228. {
  229. g_return_val_if_fail (NM_IS_SETTING_GSM (setting), NULL);
  230. return NM_SETTING_GSM_GET_PRIVATE (setting)->sim_operator_id;
  231. }
  232. /**
  233. * nm_setting_gsm_get_mtu:
  234. * @setting: the #NMSettingGsm
  235. *
  236. * Returns: the #NMSettingGsm:mtu property of the setting
  237. *
  238. * Since: 1.8
  239. **/
  240. guint32
  241. nm_setting_gsm_get_mtu (NMSettingGsm *setting)
  242. {
  243. g_return_val_if_fail (NM_IS_SETTING_GSM (setting), 0);
  244. return NM_SETTING_GSM_GET_PRIVATE (setting)->mtu;
  245. }
  246. static gboolean
  247. verify (NMSetting *setting, NMConnection *connection, GError **error)
  248. {
  249. NMSettingGsmPrivate *priv = NM_SETTING_GSM_GET_PRIVATE (setting);
  250. if (priv->number && !priv->number[0]) {
  251. g_set_error_literal (error,
  252. NM_CONNECTION_ERROR,
  253. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  254. _("property is empty"));
  255. g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_NUMBER);
  256. return FALSE;
  257. }
  258. if (priv->apn) {
  259. guint32 apn_len = strlen (priv->apn);
  260. guint32 i;
  261. if (apn_len < 1 || apn_len > 64) {
  262. g_set_error (error,
  263. NM_CONNECTION_ERROR,
  264. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  265. _("property value '%s' is empty or too long (>64)"),
  266. priv->apn);
  267. g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_APN);
  268. return FALSE;
  269. }
  270. /* APNs roughly follow the same rules as DNS domain names. Allowed
  271. * characters are a-z, 0-9, . and -. GSM 03.03 Section 9.1 states:
  272. *
  273. * The syntax of the APN shall follow the Name Syntax defined in
  274. * RFC 2181 [14] and RFC 1035 [15]. The APN consists of one or
  275. * more labels. Each label is coded as one octet length field
  276. * followed by that number of octets coded as 8 bit ASCII characters.
  277. * Following RFC 1035 [15] the labels should consist only of the
  278. * alphabetic characters (A-Z and a-z), digits (0-9) and the
  279. * dash (-). The case of alphabetic characters is not significant.
  280. *
  281. * A dot (.) is commonly used to separate parts of the APN, and
  282. * apparently the underscore (_) is used as well. RFC 2181 indicates
  283. * that no restrictions of any kind are placed on DNS labels, and thus
  284. * it would appear that none are placed on APNs either, but many modems
  285. * and networks will fail to accept APNs that include odd characters
  286. * like space ( ) and such.
  287. */
  288. for (i = 0; i < apn_len; i++) {
  289. if ( !g_ascii_isalnum (priv->apn[i])
  290. && (priv->apn[i] != '.')
  291. && (priv->apn[i] != '_')
  292. && (priv->apn[i] != '-')) {
  293. g_set_error (error,
  294. NM_CONNECTION_ERROR,
  295. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  296. _("'%s' contains invalid char(s) (use [A-Za-z._-])"),
  297. priv->apn);
  298. g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_APN);
  299. return FALSE;
  300. }
  301. }
  302. }
  303. if (priv->username && !strlen (priv->username)) {
  304. g_set_error_literal (error,
  305. NM_CONNECTION_ERROR,
  306. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  307. _("property is empty"));
  308. g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_USERNAME);
  309. return FALSE;
  310. }
  311. if (priv->network_id) {
  312. guint32 nid_len = strlen (priv->network_id);
  313. guint32 i;
  314. /* Accept both 5 and 6 digit MCC/MNC codes */
  315. if ((nid_len < 5) || (nid_len > 6)) {
  316. g_set_error (error,
  317. NM_CONNECTION_ERROR,
  318. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  319. _("'%s' length is invalid (should be 5 or 6 digits)"),
  320. priv->network_id);
  321. g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_NETWORK_ID);
  322. return FALSE;
  323. }
  324. for (i = 0; i < nid_len; i++) {
  325. if (!g_ascii_isdigit (priv->network_id[i])) {
  326. g_set_error (error,
  327. NM_CONNECTION_ERROR,
  328. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  329. _("'%s' is not a number"),
  330. priv->network_id);
  331. g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_NETWORK_ID);
  332. return FALSE;
  333. }
  334. }
  335. }
  336. if (priv->device_id && !priv->device_id[0]) {
  337. g_set_error_literal (error,
  338. NM_CONNECTION_ERROR,
  339. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  340. _("property is empty"));
  341. g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_DEVICE_ID);
  342. return FALSE;
  343. }
  344. if (priv->sim_id && !priv->sim_id[0]) {
  345. g_set_error_literal (error,
  346. NM_CONNECTION_ERROR,
  347. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  348. _("property is empty"));
  349. g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_SIM_ID);
  350. return FALSE;
  351. }
  352. if (priv->sim_operator_id) {
  353. size_t len = strlen (priv->sim_operator_id);
  354. const char *p = priv->sim_operator_id;
  355. if (len == 0 || (len != 5 && len != 6)) {
  356. g_set_error_literal (error,
  357. NM_CONNECTION_ERROR,
  358. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  359. _("property is empty or wrong size"));
  360. g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_SIM_OPERATOR_ID);
  361. return FALSE;
  362. }
  363. while (p && *p) {
  364. if (!g_ascii_isdigit (*p++)) {
  365. g_set_error_literal (error,
  366. NM_CONNECTION_ERROR,
  367. NM_CONNECTION_ERROR_INVALID_PROPERTY,
  368. _("property must contain only digits"));
  369. g_prefix_error (error, "%s.%s: ", NM_SETTING_GSM_SETTING_NAME, NM_SETTING_GSM_SIM_OPERATOR_ID);
  370. return FALSE;
  371. }
  372. }
  373. }
  374. return TRUE;
  375. }
  376. static gboolean
  377. verify_secrets (NMSetting *setting, NMConnection *connection, GError **error)
  378. {
  379. return _nm_setting_verify_secret_string (NM_SETTING_GSM_GET_PRIVATE (setting)->password,
  380. NM_SETTING_GSM_SETTING_NAME,
  381. NM_SETTING_GSM_PASSWORD,
  382. error);
  383. }
  384. static GPtrArray *
  385. need_secrets (NMSetting *setting)
  386. {
  387. NMSettingGsmPrivate *priv = NM_SETTING_GSM_GET_PRIVATE (setting);
  388. GPtrArray *secrets = NULL;
  389. if (priv->password && *priv->password)
  390. return NULL;
  391. if (priv->username) {
  392. if (!(priv->password_flags & NM_SETTING_SECRET_FLAG_NOT_REQUIRED)) {
  393. secrets = g_ptr_array_sized_new (1);
  394. g_ptr_array_add (secrets, NM_SETTING_GSM_PASSWORD);
  395. }
  396. }
  397. return secrets;
  398. }
  399. static void
  400. nm_setting_gsm_init (NMSettingGsm *setting)
  401. {
  402. }
  403. static void
  404. finalize (GObject *object)
  405. {
  406. NMSettingGsmPrivate *priv = NM_SETTING_GSM_GET_PRIVATE (object);
  407. g_free (priv->number);
  408. g_free (priv->username);
  409. g_free (priv->password);
  410. g_free (priv->apn);
  411. g_free (priv->network_id);
  412. g_free (priv->pin);
  413. g_free (priv->device_id);
  414. g_free (priv->sim_id);
  415. g_free (priv->sim_operator_id);
  416. G_OBJECT_CLASS (nm_setting_gsm_parent_class)->finalize (object);
  417. }
  418. static void
  419. set_property (GObject *object, guint prop_id,
  420. const GValue *value, GParamSpec *pspec)
  421. {
  422. NMSettingGsmPrivate *priv = NM_SETTING_GSM_GET_PRIVATE (object);
  423. char *tmp;
  424. switch (prop_id) {
  425. case PROP_NUMBER:
  426. g_free (priv->number);
  427. priv->number = g_value_dup_string (value);
  428. break;
  429. case PROP_USERNAME:
  430. g_free (priv->username);
  431. priv->username = g_value_dup_string (value);
  432. break;
  433. case PROP_PASSWORD:
  434. g_free (priv->password);
  435. priv->password = g_value_dup_string (value);
  436. break;
  437. case PROP_PASSWORD_FLAGS:
  438. priv->password_flags = g_value_get_flags (value);
  439. break;
  440. case PROP_APN:
  441. g_free (priv->apn);
  442. priv->apn = NULL;
  443. tmp = g_value_dup_string (value);
  444. if (tmp)
  445. priv->apn = g_strstrip (tmp);
  446. break;
  447. case PROP_NETWORK_ID:
  448. g_free (priv->network_id);
  449. priv->network_id = NULL;
  450. tmp = g_value_dup_string (value);
  451. if (tmp)
  452. priv->network_id = g_strstrip (tmp);
  453. break;
  454. case PROP_PIN:
  455. g_free (priv->pin);
  456. priv->pin = g_value_dup_string (value);
  457. break;
  458. case PROP_PIN_FLAGS:
  459. priv->pin_flags = g_value_get_flags (value);
  460. break;
  461. case PROP_HOME_ONLY:
  462. priv->home_only = g_value_get_boolean (value);
  463. break;
  464. case PROP_DEVICE_ID:
  465. g_free (priv->device_id);
  466. priv->device_id = g_value_dup_string (value);
  467. break;
  468. case PROP_SIM_ID:
  469. g_free (priv->sim_id);
  470. priv->sim_id = g_value_dup_string (value);
  471. break;
  472. case PROP_SIM_OPERATOR_ID:
  473. g_free (priv->sim_operator_id);
  474. priv->sim_operator_id = g_value_dup_string (value);
  475. break;
  476. case PROP_MTU:
  477. priv->mtu = g_value_get_uint (value);
  478. break;
  479. default:
  480. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  481. break;
  482. }
  483. }
  484. static void
  485. get_property (GObject *object, guint prop_id,
  486. GValue *value, GParamSpec *pspec)
  487. {
  488. NMSettingGsm *setting = NM_SETTING_GSM (object);
  489. switch (prop_id) {
  490. case PROP_NUMBER:
  491. g_value_set_string (value, nm_setting_gsm_get_number (setting));
  492. break;
  493. case PROP_USERNAME:
  494. g_value_set_string (value, nm_setting_gsm_get_username (setting));
  495. break;
  496. case PROP_PASSWORD:
  497. g_value_set_string (value, nm_setting_gsm_get_password (setting));
  498. break;
  499. case PROP_PASSWORD_FLAGS:
  500. g_value_set_flags (value, nm_setting_gsm_get_password_flags (setting));
  501. break;
  502. case PROP_APN:
  503. g_value_set_string (value, nm_setting_gsm_get_apn (setting));
  504. break;
  505. case PROP_NETWORK_ID:
  506. g_value_set_string (value, nm_setting_gsm_get_network_id (setting));
  507. break;
  508. case PROP_PIN:
  509. g_value_set_string (value, nm_setting_gsm_get_pin (setting));
  510. break;
  511. case PROP_PIN_FLAGS:
  512. g_value_set_flags (value, nm_setting_gsm_get_pin_flags (setting));
  513. break;
  514. case PROP_HOME_ONLY:
  515. g_value_set_boolean (value, nm_setting_gsm_get_home_only (setting));
  516. break;
  517. case PROP_DEVICE_ID:
  518. g_value_set_string (value, nm_setting_gsm_get_device_id (setting));
  519. break;
  520. case PROP_SIM_ID:
  521. g_value_set_string (value, nm_setting_gsm_get_sim_id (setting));
  522. break;
  523. case PROP_SIM_OPERATOR_ID:
  524. g_value_set_string (value, nm_setting_gsm_get_sim_operator_id (setting));
  525. break;
  526. case PROP_MTU:
  527. g_value_set_uint (value, nm_setting_gsm_get_mtu (setting));
  528. break;
  529. default:
  530. G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  531. break;
  532. }
  533. }
  534. static void
  535. nm_setting_gsm_class_init (NMSettingGsmClass *klass)
  536. {
  537. GObjectClass *object_class = G_OBJECT_CLASS (klass);
  538. NMSettingClass *setting_class = NM_SETTING_CLASS (klass);
  539. GArray *properties_override = _nm_sett_info_property_override_create_array ();
  540. g_type_class_add_private (klass, sizeof (NMSettingGsmPrivate));
  541. object_class->set_property = set_property;
  542. object_class->get_property = get_property;
  543. object_class->finalize = finalize;
  544. setting_class->verify = verify;
  545. setting_class->verify_secrets = verify_secrets;
  546. setting_class->need_secrets = need_secrets;
  547. /**
  548. * NMSettingGsm:number:
  549. *
  550. * Number to dial when establishing a PPP data session with the GSM-based
  551. * mobile broadband network. Many modems do not require PPP for connections
  552. * to the mobile network and thus this property should be left blank, which
  553. * allows NetworkManager to select the appropriate settings automatically.
  554. **/
  555. g_object_class_install_property
  556. (object_class, PROP_NUMBER,
  557. g_param_spec_string (NM_SETTING_GSM_NUMBER, "", "",
  558. NULL,
  559. G_PARAM_READWRITE |
  560. G_PARAM_STATIC_STRINGS));
  561. /**
  562. * NMSettingGsm:username:
  563. *
  564. * The username used to authenticate with the network, if required. Many
  565. * providers do not require a username, or accept any username. But if a
  566. * username is required, it is specified here.
  567. **/
  568. g_object_class_install_property
  569. (object_class, PROP_USERNAME,
  570. g_param_spec_string (NM_SETTING_GSM_USERNAME, "", "",
  571. NULL,
  572. G_PARAM_READWRITE |
  573. G_PARAM_STATIC_STRINGS));
  574. /**
  575. * NMSettingGsm:password:
  576. *
  577. * The password used to authenticate with the network, if required. Many
  578. * providers do not require a password, or accept any password. But if a
  579. * password is required, it is specified here.
  580. **/
  581. g_object_class_install_property
  582. (object_class, PROP_PASSWORD,
  583. g_param_spec_string (NM_SETTING_GSM_PASSWORD, "", "",
  584. NULL,
  585. G_PARAM_READWRITE |
  586. NM_SETTING_PARAM_SECRET |
  587. G_PARAM_STATIC_STRINGS));
  588. /**
  589. * NMSettingGsm:password-flags:
  590. *
  591. * Flags indicating how to handle the #NMSettingGsm:password property.
  592. **/
  593. g_object_class_install_property
  594. (object_class, PROP_PASSWORD_FLAGS,
  595. g_param_spec_flags (NM_SETTING_GSM_PASSWORD_FLAGS, "", "",
  596. NM_TYPE_SETTING_SECRET_FLAGS,
  597. NM_SETTING_SECRET_FLAG_NONE,
  598. G_PARAM_READWRITE |
  599. G_PARAM_STATIC_STRINGS));
  600. /**
  601. * NMSettingGsm:apn:
  602. *
  603. * The GPRS Access Point Name specifying the APN used when establishing a
  604. * data session with the GSM-based network. The APN often determines how
  605. * the user will be billed for their network usage and whether the user has
  606. * access to the Internet or just a provider-specific walled-garden, so it
  607. * is important to use the correct APN for the user's mobile broadband plan.
  608. * The APN may only be composed of the characters a-z, 0-9, ., and - per GSM
  609. * 03.60 Section 14.9.
  610. **/
  611. g_object_class_install_property
  612. (object_class, PROP_APN,
  613. g_param_spec_string (NM_SETTING_GSM_APN, "", "",
  614. NULL,
  615. G_PARAM_READWRITE |
  616. G_PARAM_STATIC_STRINGS));
  617. /**
  618. * NMSettingGsm:network-id:
  619. *
  620. * The Network ID (GSM LAI format, ie MCC-MNC) to force specific network
  621. * registration. If the Network ID is specified, NetworkManager will
  622. * attempt to force the device to register only on the specified network.
  623. * This can be used to ensure that the device does not roam when direct
  624. * roaming control of the device is not otherwise possible.
  625. **/
  626. g_object_class_install_property
  627. (object_class, PROP_NETWORK_ID,
  628. g_param_spec_string (NM_SETTING_GSM_NETWORK_ID, "", "",
  629. NULL,
  630. G_PARAM_READWRITE |
  631. G_PARAM_STATIC_STRINGS));
  632. /**
  633. * NMSettingGsm:pin:
  634. *
  635. * If the SIM is locked with a PIN it must be unlocked before any other
  636. * operations are requested. Specify the PIN here to allow operation of the
  637. * device.
  638. **/
  639. g_object_class_install_property
  640. (object_class, PROP_PIN,
  641. g_param_spec_string (NM_SETTING_GSM_PIN, "", "",
  642. NULL,
  643. G_PARAM_READWRITE |
  644. NM_SETTING_PARAM_SECRET |
  645. G_PARAM_STATIC_STRINGS));
  646. /**
  647. * NMSettingGsm:pin-flags:
  648. *
  649. * Flags indicating how to handle the #NMSettingGsm:pin property.
  650. **/
  651. g_object_class_install_property
  652. (object_class, PROP_PIN_FLAGS,
  653. g_param_spec_flags (NM_SETTING_GSM_PIN_FLAGS, "", "",
  654. NM_TYPE_SETTING_SECRET_FLAGS,
  655. NM_SETTING_SECRET_FLAG_NONE,
  656. G_PARAM_READWRITE |
  657. G_PARAM_STATIC_STRINGS));
  658. /**
  659. * NMSettingGsm:home-only:
  660. *
  661. * When %TRUE, only connections to the home network will be allowed.
  662. * Connections to roaming networks will not be made.
  663. **/
  664. g_object_class_install_property
  665. (object_class, PROP_HOME_ONLY,
  666. g_param_spec_boolean (NM_SETTING_GSM_HOME_ONLY, "", "",
  667. FALSE,
  668. G_PARAM_READWRITE |
  669. G_PARAM_STATIC_STRINGS));
  670. /**
  671. * NMSettingGsm:device-id:
  672. *
  673. * The device unique identifier (as given by the WWAN management service)
  674. * which this connection applies to. If given, the connection will only
  675. * apply to the specified device.
  676. *
  677. * Since: 1.2
  678. **/
  679. g_object_class_install_property
  680. (object_class, PROP_DEVICE_ID,
  681. g_param_spec_string (NM_SETTING_GSM_DEVICE_ID, "", "",
  682. NULL,
  683. G_PARAM_READWRITE |
  684. G_PARAM_STATIC_STRINGS));
  685. /**
  686. * NMSettingGsm:sim-id:
  687. *
  688. * The SIM card unique identifier (as given by the WWAN management service)
  689. * which this connection applies to. If given, the connection will apply
  690. * to any device also allowed by #NMSettingGsm:device-id which contains a
  691. * SIM card matching the given identifier.
  692. *
  693. * Since: 1.2
  694. **/
  695. g_object_class_install_property
  696. (object_class, PROP_SIM_ID,
  697. g_param_spec_string (NM_SETTING_GSM_SIM_ID, "", "",
  698. NULL,
  699. G_PARAM_READWRITE |
  700. G_PARAM_STATIC_STRINGS));
  701. /**
  702. * NMSettingGsm:sim-operator-id:
  703. *
  704. * A MCC/MNC string like "310260" or "21601" identifying the specific
  705. * mobile network operator which this connection applies to. If given,
  706. * the connection will apply to any device also allowed by
  707. * #NMSettingGsm:device-id and #NMSettingGsm:sim-id which contains a SIM
  708. * card provisioned by the given operator.
  709. *
  710. * Since: 1.2
  711. **/
  712. g_object_class_install_property
  713. (object_class, PROP_SIM_OPERATOR_ID,
  714. g_param_spec_string (NM_SETTING_GSM_SIM_OPERATOR_ID, "", "",
  715. NULL,
  716. G_PARAM_READWRITE |
  717. G_PARAM_STATIC_STRINGS));
  718. /**
  719. * NMSettingGsm:mtu:
  720. *
  721. * If non-zero, only transmit packets of the specified size or smaller,
  722. * breaking larger packets up into multiple frames.
  723. *
  724. * Since: 1.8
  725. **/
  726. g_object_class_install_property
  727. (object_class, PROP_MTU,
  728. g_param_spec_uint (NM_SETTING_GSM_MTU, "", "",
  729. 0, G_MAXUINT32, 0,
  730. G_PARAM_READWRITE |
  731. G_PARAM_CONSTRUCT |
  732. NM_SETTING_PARAM_FUZZY_IGNORE |
  733. G_PARAM_STATIC_STRINGS));
  734. /* Ignore incoming deprecated properties */
  735. _properties_override_add_dbus_only (properties_override,
  736. "allowed-bands",
  737. G_VARIANT_TYPE_UINT32,
  738. NULL,
  739. NULL);
  740. _properties_override_add_dbus_only (properties_override,
  741. "network-type",
  742. G_VARIANT_TYPE_INT32,
  743. NULL,
  744. NULL);
  745. _nm_setting_class_commit_full (setting_class, NM_META_SETTING_TYPE_GSM,
  746. NULL, properties_override);
  747. }