static void ril_cops_cb(struct ril_msg *message, gpointer user_data) { struct cb_data *cbd = user_data; ofono_netreg_operator_cb_t cb = cbd->cb; struct netreg_data *nd = cbd->user; struct ofono_error error; struct parcel rilp; struct ofono_network_operator op; gchar *lalpha, *salpha, *numeric; if (message->error == RIL_E_SUCCESS) { decode_ril_error(&error, "OK"); } else { ofono_error("Failed to retrive the current operator"); goto error; } ril_util_init_parcel(message, &rilp); /* Size of char ** */ if (parcel_r_int32(&rilp) == 0) goto error; lalpha = parcel_r_string(&rilp); salpha = parcel_r_string(&rilp); numeric = parcel_r_string(&rilp); /* Try to use long by default */ if (lalpha) strncpy(op.name, lalpha, OFONO_MAX_OPERATOR_NAME_LENGTH); else if (salpha) strncpy(op.name, salpha, OFONO_MAX_OPERATOR_NAME_LENGTH); else goto error; extract_mcc_mnc(numeric, op.mcc, op.mnc); /* Set to current */ op.status = OPERATOR_STATUS_CURRENT; op.tech = nd->tech; g_ril_append_print_buf(nd->ril, "(lalpha=%s, salpha=%s, numeric=%s, %s, mcc=%s, mnc=%s, %s)", lalpha, salpha, numeric, op.name, op.mcc, op.mnc, registration_tech_to_string(op.tech)); g_ril_print_response(nd->ril, message); g_free(lalpha); g_free(salpha); g_free(numeric); cb(&error, &op, cbd->data); return; error: CALLBACK_WITH_FAILURE(cb, NULL, cbd->data); }
gboolean ril_util_parse_reg(const void *data, guint len, struct ril_reg_data *reg) { GRilIoParser rilp; int nparams; gchar *sstatus = NULL, *slac = NULL, *sci = NULL; gchar *stech = NULL, *sreason = NULL, *smax = NULL; memset(reg, 0, sizeof(*reg)); /* Size of response string array * * Should be: * >= 4 for VOICE_REG reply * >= 5 for DATA_REG reply */ grilio_parser_init(&rilp, data, len); if (!grilio_parser_get_int32(&rilp, &nparams) || nparams < 4) { DBG("broken response"); return FALSE; } sstatus = grilio_parser_get_utf8(&rilp); if (!sstatus) { DBG("No sstatus value returned!"); return FALSE; } slac = grilio_parser_get_utf8(&rilp); sci = grilio_parser_get_utf8(&rilp); stech = grilio_parser_get_utf8(&rilp); nparams -= 4; reg->ril_status = atoi(sstatus); if (reg->ril_status > 10) { reg->status = reg->ril_status - 10; } else { reg->status = reg->ril_status; } /* FIXME: need to review VOICE_REGISTRATION response * as it returns ~15 parameters ( vs. 6 for DATA ). * * The first four parameters are the same for both * responses ( although status includes values for * emergency calls for VOICE response ). * * Parameters 5 & 6 have different meanings for * voice & data response. */ if (nparams--) { /* TODO: different use for CDMA */ sreason = grilio_parser_get_utf8(&rilp); if (nparams--) { /* TODO: different use for CDMA */ smax = grilio_parser_get_utf8(&rilp); if (smax) { reg->max_calls = atoi(smax); } } } reg->lac = slac ? strtol(slac, NULL, 16) : -1; reg->ci = sci ? strtol(sci, NULL, 16) : -1; reg->access_tech = ril_parse_tech(stech, ®->ril_tech); DBG("%s,%s,%s,%d,%s,%s,%s", registration_status_to_string(reg->status), slac, sci, reg->ril_tech, registration_tech_to_string(reg->access_tech), sreason, smax); g_free(sstatus); g_free(slac); g_free(sci); g_free(stech); g_free(sreason); g_free(smax); return TRUE; }