---
src/network.c | 122
1 files changed, 96 insertions(+), 26 deletions(-)
diff --git a/src/network.c b/src/network.c
index bf61472..07f9cdf 100644
--- a/src/network.c
+++ b/src/network.c
@@ -42,7 +42,8 @@
enum network_registration_mode {
NETWORK_REGISTRATION_MODE_AUTO =0,
- NETWORK_REGISTRATION_MODE_MANUAL = 1,
+ NETWORK_REGISTRATION_MODE_AUTO_ONLY = 1,
+ NETWORK_REGISTRATION_MODE_MANUAL = 2,
};
#define SETTINGS_STORE netreg
@@ -98,6 +99,8 @@ static const char *registration_mode_to_string(int mode)
switch (mode) {
case NETWORK_REGISTRATION_MODE_AUTO:
return auto;
+ case NETWORK_REGISTRATION_MODE_AUTO_ONLY:
+ return auto-only;
case NETWORK_REGISTRATION_MODE_MANUAL:
return manual;
}
@@ -143,6 +146,42 @@ static char **network_operator_technologies(struct
network_operator_data *opd)
return techs;
}
+static void registration_status_callback(const struct ofono_error *error,
+ int status, int lac, int ci, int tech,
+ void *data)
+{
+ struct ofono_netreg *netreg = data;
+
+ if (error-type != OFONO_ERROR_TYPE_NO_ERROR) {
+ DBG(Error during registration status query);
+ return;
+ }
+
+ ofono_netreg_status_notify(netreg, status, lac, ci, tech);
+}
+
+static void init_register(const struct ofono_error *error, void *data)
+{
+ struct ofono_netreg *netreg = data;
+
+ if (netreg-driver-registration_status == NULL)
+ return;
+
+ netreg-driver-registration_status(netreg,
+ registration_status_callback, netreg);
+}
+
+static void enforce_auto_only(struct ofono_netreg *netreg)
+{
+ if (netreg-mode != NETWORK_REGISTRATION_MODE_MANUAL)
+ return;
+
+ if (netreg-driver-register_auto == NULL)
+ return;
+
+ netreg-driver-register_auto(netreg, init_register, netreg);
+}
+
static void set_registration_mode(struct ofono_netreg *netreg, int mode)
{
DBusConnection *conn;
@@ -152,6 +191,9 @@ static void set_registration_mode(struct ofono_netreg
*netreg, int mode)
if (netreg-mode == mode)
return;
+ if (mode == NETWORK_REGISTRATION_MODE_AUTO_ONLY)
+ enforce_auto_only(netreg);
+
netreg-mode = mode;
if (netreg-settings) {
@@ -170,20 +212,6 @@ static void set_registration_mode(struct ofono_netreg
*netreg, int mode)
Mode, DBUS_TYPE_STRING, strmode);
}
-static void registration_status_callback(const struct ofono_error *error,
- int status, int lac, int ci, int tech,
- void *data)
-{
- struct ofono_netreg *netreg = data;
-
- if (error-type != OFONO_ERROR_TYPE_NO_ERROR) {
- DBG(Error during registration status query);
- return;
- }
-
- ofono_netreg_status_notify(netreg, status, lac, ci, tech);
-}
-
static void register_callback(const struct ofono_error *error, void *data)
{
struct ofono_netreg *netreg = data;
@@ -211,15 +239,6 @@ out:
registration_status_callback, netreg);
}
-static void init_register(const struct ofono_error *error, void *data)
-{
- struct ofono_netreg *netreg = data;
-
- if (netreg-driver-registration_status)
- netreg-driver-registration_status(netreg,
- registration_status_callback, netreg);
-}
-
static struct network_operator_data *
network_operator_create(const struct ofono_network_operator *op)
{
@@ -586,6 +605,9 @@ static DBusMessage
*network_operator_register(DBusConnection *conn,
struct network_operator_data *opd = data;
struct ofono_netreg *netreg = opd-netreg;
+ if (netreg-mode == NETWORK_REGISTRATION_MODE_AUTO_ONLY)
+ return __ofono_error_access_denied(msg);
+
if (netreg-pending)
return __ofono_error_busy(msg);
@@ -828,6 +850,9 @@ static DBusMessage *network_register(DBusConnection *conn,
{
struct ofono_netreg *netreg = data;
+ if (netreg-mode == NETWORK_REGISTRATION_MODE_AUTO_ONLY)
+ return __ofono_error_access_denied(msg);
+
if (netreg-pending)
return __ofono_error_busy(msg);
@@ -947,6 +972,9 @@ static DBusMessage *network_scan(DBusConnection *conn,
{
struct ofono_netreg *netreg = data;
+ if (netreg-mode == NETWORK_REGISTRATION_MODE_AUTO_ONLY)
+ return __ofono_error_access_denied(msg);
+
if (netreg-pending)
return __ofono_error_busy(msg);
@@ -1364,7 +1392,7 @@ static void init_registration_status(const struct
ofono_error