static void ril_data_reg_cb(struct ril_msg *message, gpointer user_data) { struct cb_data *cbd = user_data; ofono_gprs_status_cb_t cb = cbd->cb; struct ofono_gprs *gprs = cbd->user; struct ril_gprs_data *gd = ofono_gprs_get_data(gprs); struct reply_data_reg_state *reply; gboolean attached = FALSE; gboolean notify_status = FALSE; int old_status; old_status = gd->rild_status; if (message->error == RIL_E_SUCCESS) { reply = g_ril_reply_parse_data_reg_state(gd->ril, message); if (reply == NULL) { if (cb) CALLBACK_WITH_FAILURE(cb, -1, cbd->data); return; } } else { /* * If we get a RIL error (say, radio not available) it is better * to return unknown values than to call cb with failure status. * If we do the last, ConnectionManager would not be created if * this is the first time we retrieve data status, or we can * even create infinite loops as the status in gprs atom would * not be refreshed. When we finally register we will get events * so we will try to retrieve data state again. */ ofono_error("%s: DATA_REGISTRATION_STATE reply failure: %s", __func__, ril_error_to_string(message->error)); reply = g_malloc0(sizeof(*reply)); reply->reg_state.status = NETWORK_REGISTRATION_STATUS_UNKNOWN; reply->reg_state.tech = RADIO_TECH_UNKNOWN; } /* * There are three cases that can result in this callback * running: * * 1) The driver's probe() method was called, and thus an * internal call to ril_gprs_registration_status() is * generated. No ofono cb exists. * * 2) ril_gprs_state_change() is called due to an unsolicited * event from RILD. No ofono cb exists. * * 3) The ofono code code calls the driver's attached_status() * function. A valid ofono cb exists. */ if (gd->rild_status != reply->reg_state.status) { gd->rild_status = reply->reg_state.status; if (cb == NULL) notify_status = TRUE; } /* * Override the actual status based upon the desired * attached status set by the core GPRS code ( controlled * by the ConnnectionManager's 'Powered' property ). */ attached = (reply->reg_state.status == NETWORK_REGISTRATION_STATUS_REGISTERED || reply->reg_state.status == NETWORK_REGISTRATION_STATUS_ROAMING); if (attached && gd->ofono_attached == FALSE) { DBG("attached=true; ofono_attached=false; return !REGISTERED"); reply->reg_state.status = NETWORK_REGISTRATION_STATUS_NOT_REGISTERED; /* * Further optimization so that if ril_status == * NOT_REGISTERED, ofono_attached == false, and status == * ROAMING | REGISTERED, then notify gets cleared... * * As is, this results in unecessary status notify calls * when nothing has changed. */ if (notify_status && reply->reg_state.status == old_status) notify_status = FALSE; } if (old_status == -1) { ofono_gprs_register(gprs); /* Different rild implementations use different events here */ g_ril_register(gd->ril, gd->state_changed_unsol, ril_gprs_state_change, gprs); if (reply->max_cids == 0) gd->max_cids = RIL_MAX_NUM_ACTIVE_DATA_CALLS; else if (reply->max_cids < RIL_MAX_NUM_ACTIVE_DATA_CALLS) gd->max_cids = reply->max_cids; else gd->max_cids = RIL_MAX_NUM_ACTIVE_DATA_CALLS; DBG("Setting max cids to %d", gd->max_cids); ofono_gprs_set_cid_range(gprs, 1, gd->max_cids); /* * This callback is a result of the inital call * to probe(), so should return after registration. */ g_free(reply); return; } /* Just need to notify ofono if it's already attached */ if (notify_status) { /* * If network disconnect has occurred, call detached_notify() * instead of status_notify(). */ if (!attached && (old_status == NETWORK_REGISTRATION_STATUS_REGISTERED || old_status == NETWORK_REGISTRATION_STATUS_ROAMING)) { DBG("calling ofono_gprs_detached_notify()"); ofono_gprs_detached_notify(gprs); reply->reg_state.tech = RADIO_TECH_UNKNOWN; } else { DBG("calling ofono_gprs_status_notify()"); ofono_gprs_status_notify(gprs, reply->reg_state.status); } } gd->tech = reply->reg_state.tech; ofono_gprs_bearer_notify(gprs, ril_tech_to_bearer_tech(reply->reg_state.tech)); if (cb) CALLBACK_WITH_SUCCESS(cb, reply->reg_state.status, cbd->data); g_free(reply); }
static void ril_data_reg_cb(struct ril_msg *message, gpointer user_data) { struct cb_data *cbd = user_data; ofono_gprs_status_cb_t cb = cbd->cb; struct ofono_gprs *gprs = cbd->user; struct ril_gprs_data *gd = ofono_gprs_get_data(gprs); struct reply_data_reg_state *reply; gboolean attached = FALSE; gboolean notify_status = FALSE; int old_status; old_status = gd->rild_status; if (message->error != RIL_E_SUCCESS) { ofono_error("%s: DATA_REGISTRATION_STATE reply failure: %s", __func__, ril_error_to_string(message->error)); goto error; } if ((reply = g_ril_reply_parse_data_reg_state(gd->ril, message)) == NULL) goto error; /* * There are three cases that can result in this callback * running: * * 1) The driver's probe() method was called, and thus an * internal call to ril_gprs_registration_status() is * generated. No ofono cb exists. * * 2) ril_gprs_state_change() is called due to an unsolicited * event from RILD. No ofono cb exists. * * 3) The ofono code code calls the driver's attached_status() * function. A valid ofono cb exists. */ if (gd->rild_status != reply->reg_state.status) { gd->rild_status = reply->reg_state.status; if (cb == NULL) notify_status = TRUE; } /* * Override the actual status based upon the desired * attached status set by the core GPRS code ( controlled * by the ConnnectionManager's 'Powered' property ). */ attached = (reply->reg_state.status == NETWORK_REGISTRATION_STATUS_REGISTERED || reply->reg_state.status == NETWORK_REGISTRATION_STATUS_ROAMING); if (attached && gd->ofono_attached == FALSE) { DBG("attached=true; ofono_attached=false; return !REGISTERED"); reply->reg_state.status = NETWORK_REGISTRATION_STATUS_NOT_REGISTERED; /* * Further optimization so that if ril_status == * NOT_REGISTERED, ofono_attached == false, and status == * ROAMING | REGISTERED, then notify gets cleared... * * As is, this results in unecessary status notify calls * when nothing has changed. */ if (notify_status && reply->reg_state.status == old_status) notify_status = FALSE; } if (old_status == -1) { ofono_gprs_register(gprs); /* Different rild implementations use different events here */ g_ril_register(gd->ril, gd->state_changed_unsol, ril_gprs_state_change, gprs); if (reply->max_cids == 0) gd->max_cids = RIL_MAX_NUM_ACTIVE_DATA_CALLS; else if (reply->max_cids < RIL_MAX_NUM_ACTIVE_DATA_CALLS) gd->max_cids = reply->max_cids; else gd->max_cids = RIL_MAX_NUM_ACTIVE_DATA_CALLS; DBG("Setting max cids to %d", gd->max_cids); ofono_gprs_set_cid_range(gprs, 1, gd->max_cids); /* * This callback is a result of the inital call * to probe(), so should return after registration. */ g_free(reply); return; } /* Just need to notify ofono if it's already attached */ if (notify_status) { /* * If network disconnect has occurred, call detached_notify() * instead of status_notify(). */ if (!attached && (old_status == NETWORK_REGISTRATION_STATUS_REGISTERED || old_status == NETWORK_REGISTRATION_STATUS_ROAMING)) { DBG("calling ofono_gprs_detached_notify()"); ofono_gprs_detached_notify(gprs); reply->reg_state.tech = RADIO_TECH_UNKNOWN; } else { DBG("calling ofono_gprs_status_notify()"); ofono_gprs_status_notify(gprs, reply->reg_state.status); } } if (gd->tech != reply->reg_state.tech) { gd->tech = reply->reg_state.tech; ofono_gprs_bearer_notify(gprs, ril_tech_to_bearer_tech(reply->reg_state.tech)); } if (cb) CALLBACK_WITH_SUCCESS(cb, reply->reg_state.status, cbd->data); g_free(reply); return; error: /* * For some modems DATA_REGISTRATION_STATE will return an error until we * are registered in the voice network. */ if (old_status == -1 && message->error == RIL_E_GENERIC_FAILURE) gd->status_retry_cb_id = g_timeout_add(GET_STATUS_TIMER_MS, ril_get_status_retry, gprs); if (cb) CALLBACK_WITH_FAILURE(cb, -1, cbd->data); }