Implement CGREG query
authorDenis Kenzior <denkenz@gmail.com>
Wed, 18 Nov 2009 16:34:23 +0000 (10:34 -0600)
committerDenis Kenzior <denkenz@gmail.com>
Wed, 18 Nov 2009 16:34:23 +0000 (10:34 -0600)
Some modems do not properly send CGREG notifications when the context is
attached / detached.  We manually query the registration state of GPRS
to make sure that if the modem is indeed attached, the state is
reflected properly

src/gprs.c

index 488f6d7..6b88fcb 100644 (file)
@@ -360,6 +360,8 @@ static void pri_activate_callback(const struct ofono_error *error,
        DBusConnection *conn = ofono_dbus_get_connection();
        dbus_bool_t value;
 
+       DBG("%p %s", ctx, interface);
+
        if (error->type != OFONO_ERROR_TYPE_NO_ERROR) {
                ofono_debug("Activating context failed with error: %s",
                                telephony_error_to_str(error));
@@ -866,16 +868,34 @@ static void gprs_attached_update(struct ofono_gprs *gprs)
                                "Attached", DBUS_TYPE_BOOLEAN, &value);
 }
 
-static void gprs_attach_callback(const struct ofono_error *error, void *data)
+static void registration_status_cb(const struct ofono_error *error,
+                                       int status, int lac, int ci, int tech,
+                                       void *data)
 {
        struct ofono_gprs *gprs = data;
 
+       if (error->type == OFONO_ERROR_TYPE_NO_ERROR)
+               ofono_gprs_status_notify(gprs, status, lac, ci, tech);
+
        gprs->flags &= ~GPRS_FLAG_ATTACHING;
+}
+
+static void gprs_attach_callback(const struct ofono_error *error, void *data)
+{
+       struct ofono_gprs *gprs = data;
 
        if (error->type == OFONO_ERROR_TYPE_NO_ERROR) {
                gprs->driver_attached = !gprs->driver_attached;
                gprs_attached_update(gprs);
        }
+
+       if (gprs->driver->registration_status) {
+               gprs->driver->registration_status(gprs, registration_status_cb,
+                                                       gprs);
+               return;
+       }
+
+       gprs->flags &= ~GPRS_FLAG_ATTACHING;
 }
 
 static void gprs_netreg_update(struct ofono_gprs *gprs)