static void set_path(struct sim_data *sd, struct parcel *rilp, const int fileid, const guchar *path, const guint path_len) { guchar db_path[6] = { 0x00 }; char *hex_path = NULL; int len = 0; DBG(""); if (path_len > 0 && path_len < 7) { memcpy(db_path, path, path_len); len = path_len; } else if (sd->app_type == RIL_APPTYPE_USIM) { len = sim_ef_db_get_path_3g(fileid, db_path); } else if (sd->app_type == RIL_APPTYPE_SIM) { len = sim_ef_db_get_path_2g(fileid, db_path); } else { ofono_error("Unsupported app_type: 0%x", sd->app_type); } if (len > 0) { hex_path = encode_hex(db_path, len, 0); parcel_w_string(rilp, (char *) hex_path); g_ril_append_print_buf(sd->ril, "%spath=%s,", print_buf, hex_path); g_free(hex_path); } else if (fileid == SIM_EF_ICCID_FILEID || fileid == SIM_EFPL_FILEID) { /* * Special catch-all for EF_ICCID (unique card ID) * and EF_PL files which exist in the root directory. * As the sim_info_cb function may not have yet * recorded the app_type for the SIM, and the path * for both files is the same for 2g|3g, just hard-code. * * See 'struct ef_db' in: * ../../src/simutil.c for more details. */ parcel_w_string(rilp, (char *) ROOTMF); } else { /* * The only known case of this is EFPHASE_FILED (0x6FAE). * The ef_db table ( see /src/simutil.c ) entry for * EFPHASE contains a value of 0x0000 for it's * 'parent3g' member. This causes a NULL path to * be returned. */ DBG("db_get_path*() returned empty path."); parcel_w_string(rilp, NULL); } }
static void test_get_2g_path(void) { unsigned char path[6]; unsigned int len; unsigned char path1[] = { 0x3F, 0x00, 0x7F, 0x20 }; len = sim_ef_db_get_path_2g(SIM_EFPNN_FILEID, path); g_assert(len == 4); g_assert(!memcmp(path, path1, len)); }
static char *get_path(int vendor, guint app_type, const int fileid, const unsigned char *path, unsigned int path_len) { unsigned char db_path[6] = { 0x00 }; unsigned char *comm_path = db_path; int len = 0; if (path_len > 0 && path_len < 7) { memcpy(db_path, path, path_len); len = path_len; goto done; } switch (app_type) { case RIL_APPTYPE_USIM: len = sim_ef_db_get_path_3g(fileid, db_path); break; case RIL_APPTYPE_SIM: len = sim_ef_db_get_path_2g(fileid, db_path); break; default: ofono_error("Unsupported app_type: 0%x", app_type); return NULL; } done: /* * db_path contains the ID of the MF, but MediaTek modems return an * error if we do not remove it. Other devices work the other way * around: they need the MF in the path. In fact MTK behaviour seem to * be the right one: to have the MF in the file is forbidden following * ETSI TS 102 221, section 8.4.2 (we are accessing the card in mode * "select by path from MF", see 3gpp 27.007, +CRSM). */ if (vendor == OFONO_RIL_VENDOR_MTK && len >= (int) ROOTMF_SZ && memcmp(db_path, ROOTMF, ROOTMF_SZ) == 0) { comm_path = db_path + ROOTMF_SZ; len -= ROOTMF_SZ; } if (len == 0) return NULL; return encode_hex(comm_path, len, 0); }
static gboolean set_path(GRil *ril, guint app_type, struct parcel *rilp, const int fileid, const guchar *path, const guint path_len) { unsigned char db_path[6] = { 0x00 }; unsigned char *comm_path = db_path; char *hex_path = NULL; int len = 0; if (path_len > 0 && path_len < 7) { memcpy(db_path, path, path_len); len = path_len; } else if (app_type == RIL_APPTYPE_USIM) { len = sim_ef_db_get_path_3g(fileid, db_path); } else if (app_type == RIL_APPTYPE_SIM) { len = sim_ef_db_get_path_2g(fileid, db_path); } else { ofono_error("Unsupported app_type: 0%x", app_type); return FALSE; } /* * db_path contains the ID of the MF, but MediaTek modems return an * error if we do not remove it. Other devices work the other way * around: they need the MF in the path. In fact MTK behaviour seem to * be the right one: to have the MF in the file is forbidden following * ETSI TS 102 221, section 8.4.2 (we are accessing the card in mode * "select by path from MF", see 3gpp 27.007, +CRSM). */ if (g_ril_vendor(ril) == OFONO_RIL_VENDOR_MTK && len >= (int) ROOTMF_SZ && memcmp(db_path, ROOTMF, ROOTMF_SZ) == 0) { comm_path = db_path + ROOTMF_SZ; len -= ROOTMF_SZ; } if (len > 0) { hex_path = encode_hex(comm_path, len, 0); parcel_w_string(rilp, hex_path); g_ril_append_print_buf(ril, "%spath=%s,", print_buf, hex_path); g_free(hex_path); } else { /* * The only known case of this is EFPHASE_FILED (0x6FAE). * The ef_db table ( see /src/simutil.c ) entry for * EFPHASE contains a value of 0x0000 for it's * 'parent3g' member. This causes a NULL path to * be returned. * (EF_PHASE does not exist for USIM) */ parcel_w_string(rilp, NULL); g_ril_append_print_buf(ril, "%spath=(null),", print_buf); } return TRUE; }