⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aci_ext_pers.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 2 页
字号:
    {
      switch (personalisation_type)
      {
        case SIMLOCK_SIM: personalisation_status.locks1=(UBYTE)FldSet(personalisation_status.locks1,plock,SIMLOCK_BLOCKED); break;
        case SIMLOCK_NETWORK: personalisation_status.locks1=(UBYTE)FldSet(personalisation_status.locks1,nlock,SIMLOCK_BLOCKED); break;
        case SIMLOCK_NETWORK_SUBSET: personalisation_status.locks1=(UBYTE)FldSet(personalisation_status.locks1,nslock,SIMLOCK_BLOCKED); break;
        case SIMLOCK_SERVICE_PROVIDER: personalisation_status.locks1=(UBYTE)FldSet(personalisation_status.locks1,splock,SIMLOCK_BLOCKED); break;
        case SIMLOCK_CORPORATE: personalisation_status.locks2=(UBYTE)FldSet(personalisation_status.locks2,clock,SIMLOCK_BLOCKED); break;
        default: return SIMLOCK_FAIL;
      }
      return SIMLOCK_BLOCKED;
    }
    return SIMLOCK_FAIL;
  }

  switch (personalisation_type)
  { /* the case (UBYTE)lock to help lint is save since if lock==SIMLOCK_FAIL==-1 is checked above! */
    case SIMLOCK_SIM: personalisation_status.locks1 = (UBYTE)FldSet(personalisation_status.locks1,plock,(UBYTE)lock);break;
    case SIMLOCK_NETWORK: personalisation_status.locks1 = (UBYTE)FldSet(personalisation_status.locks1,nlock,(UBYTE)lock);break;
    case SIMLOCK_NETWORK_SUBSET: personalisation_status.locks1 = (UBYTE)FldSet(personalisation_status.locks1,nslock,(UBYTE)lock);break;
    case SIMLOCK_SERVICE_PROVIDER: personalisation_status.locks1 = (UBYTE)FldSet(personalisation_status.locks1,splock,(UBYTE)lock);break;
    case SIMLOCK_CORPORATE: personalisation_status.locks2 = (UBYTE)FldSet(personalisation_status.locks2,clock,(UBYTE)lock);break;
    default: return SIMLOCK_FAIL;
  }

  /* Correct PIN, reset lock count and unblock, if blocked */
  personalisation_status.cnt = 0;    /* Correct PIN, reset lock count */

  /* save changes to PCM here ! */
  aci_ext_personalisation_save();

  return lock;
}

void aci_ext_personalisation_checkfirstsim( )
{
  int imsicount = 0;
  TRACE_FUNCTION("aci_ext_personalisation_checkfirstsim()");

  /* If personalisation on first SIM is enabled, transport the given IMSI to the SIM personalisation area */
  if (FldGet(personalisation_status.locks2,flock) EQ SIMLOCK_ENABLED)
  {
    /* Move IMSI of inserted SIM into the first free "slot" of SIM personalisation. */
    imsicount = personalisation_sim.count;
    personalisation_sim.data[imsicount].c_field = simShrdPrm.imsi.c_field;
    memcpy(&personalisation_sim.data[imsicount].imsi, simShrdPrm.imsi.field,MAX_IMSI-1);
    personalisation_sim.count++;

    personalisation_status.locks1 = (UBYTE)FldSet(personalisation_status.locks1, plock, SIMLOCK_ENABLED);
    personalisation_status.locks2 = (UBYTE)FldSet(personalisation_status.locks2, flock, SIMLOCK_DISABLED);


    /* save changes to PCM here ! */
  aci_ext_personalisation_save();
  }
}

/* internal methods ------------------------------------------------------------- */

/*
  PURPOSE : Fills the extended SIM Lock record with defaults if
            only the simple SIM Lock Record is available.
*/
LOCAL void pcm_fill_sim_lock (EF_SIMLCKEXT * simlck)
{
  TRACE_FUNCTION("pcm_fill_sim_lock()");

  if (aci_slock_sim_lock_field EQ SLOCK_PCM_NRM)
  {
    /*
     * PCM contains SIMLOCK record. Must be mapped to the internal
     * used SIMLOCKEXT record.
     *
     * gidl1, gidl2 to the end of record:
     */
    simlck->gidl1 = simlck->len_sp_imsi;
    simlck->gidl2 = simlck->sp_imsi [0];
    /*
     * IMSI must be copied for the other locks
     * N-Lock   digits 1..5, rest filled with 0x09 to suppress compare
     * SP-Lock  digits 1..5, rest filled with 0x09 to suppress compare
     * NS-Lock  digits 1..7, rest filled with 0x09 to suppress compare
     * C-Lock   digits 1..5, rest filled with 0x09 to suppress compare
     */
    memset (simlck->n_imsi, 0x09, MAX_IMSI_LEN);
    memcpy (simlck->n_imsi, simlck->p_imsi, 5);
    simlck->len_n_imsi = 5;

    memset (simlck->sp_imsi, 0x09, MAX_IMSI_LEN);
    memcpy (simlck->sp_imsi, simlck->p_imsi, 5);
    simlck->len_sp_imsi = 5;

    memset (simlck->ns_imsi, 0x09, MAX_IMSI_LEN);
    memcpy (simlck->ns_imsi, simlck->p_imsi, 7);
    simlck->len_ns_imsi = 7;

    memset (simlck->c_imsi, 0x09, MAX_IMSI_LEN);
    memcpy (simlck->c_imsi, simlck->p_imsi, 5);
    simlck->len_c_imsi = 5;
    /*
     * initialise unblock imsi so that it never will fit
     */
    simlck->len_u_imsi = 0;
  }
}

/*
  * ---------------------------------------------------------------------------
  * PURPOSE : Reads the SIM LOCK Record content from PCM
  * ---------------------------------------------------------------------------
  */
LOCAL UBYTE pcm_get_sim_lock (EF_SIMLCKEXT * simlck)
{
  #ifdef WIN32
  memcpy(simlck, &simlock_pcm_memory, SIZE_EF_SIMLCKEXT);
  return PCM_OK;
  #else

  UBYTE version;
  UBYTE sim_lock_type = 0;

  TRACE_FUNCTION("pcm_get_sim_lock()");


  if (aci_slock_sim_lock_field EQ NOT_PRESENT_8BIT)
  {
    if (pcm_ReadFile((UBYTE *) EF_SIMLCK_ID,
                     SIZE_EF_SIMLCK,
                     (UBYTE *) simlck,
                     &version) EQ PCM_OK)
    {
      aci_slock_sim_lock_field = SLOCK_PCM_NRM;
      pcm_fill_sim_lock (simlck);
      return PCM_OK;
    }
    if (pcm_ReadFile((UBYTE *) EF_SIMLCKEXT_ID,
                     SIZE_EF_SIMLCKEXT,
                     (UBYTE *) simlck,
                     &version) EQ PCM_OK)
    {
      aci_slock_sim_lock_field = SLOCK_PCM_EXT;
      return PCM_OK;
    }
    return PCM_NVRAM_ACCS_FAIL;
  }

  if (aci_slock_sim_lock_field EQ SLOCK_PCM_NRM)
  {
    if (pcm_ReadFile((UBYTE *) EF_SIMLCK_ID,
                     SIZE_EF_SIMLCK,
                     (UBYTE *) simlck,
                     &version) EQ PCM_OK)
    {
      pcm_fill_sim_lock (simlck);
      return PCM_OK;
    }
  }

  if (aci_slock_sim_lock_field EQ SLOCK_PCM_EXT)
  {
    if (pcm_ReadFile((UBYTE *) EF_SIMLCKEXT_ID,
                     SIZE_EF_SIMLCKEXT,
                     (UBYTE *) simlck,
                     &version) EQ PCM_OK)
    {
      return PCM_OK;
    }
  }
  return PCM_NVRAM_ACCS_FAIL;

  #endif
}

/*
  * ---------------------------------------------------------------------------
  PURPOSE : Saves the SIM LOCK Record content into PCM
  * ---------------------------------------------------------------------------
*/

LOCAL void pcm_set_sim_lock (EF_SIMLCKEXT * simlck)
{
  TRACE_FUNCTION("pcm_set_sim_lock()");

  #ifdef WIN32
  memcpy(&simlock_pcm_memory, simlck, SIZE_EF_SIMLCKEXT);
  #else

  if (aci_slock_sim_lock_field EQ SLOCK_PCM_NRM)
  {
    /*
     * set GDL1 and 2 on the expected location
     * => len_sp_imsi = gdl1, sp_imsi[0] = gdl2
     */
    simlck->len_sp_imsi = simlck->gidl1;
    simlck->sp_imsi [0] = simlck->gidl2;
    pcm_WriteFile((UBYTE *) EF_SIMLCK_ID,SIZE_EF_SIMLCK,
                                (UBYTE *) simlck);
  }
  else
    pcm_WriteFile((UBYTE *) EF_SIMLCKEXT_ID,SIZE_EF_SIMLCKEXT,
                                 (UBYTE *) simlck);

  #endif
}

/*
  PURPOSE : convert bcd to ASCII

*/

LOCAL void decodeB2A (U8 *bcd, U8 bcd_len, U8 *ascii)
{
    int i;

    TRACE_FUNCTION("simDecodeB2A()");

    for (i = 0; i < bcd_len * 2; i++)
    {
        ascii[i] = (i & 1) ? (bcd[i/2] >> 4) + '0'
                        : (bcd[i/2] & 0x0f) + '0';
        if (ascii[i] > '9')
        {
            ascii[i] = 0;
            break;
        }
    }
    ascii[i] = 0;
}

#define FFS_MELOCK_STATUS "/gsm/MELOCK/status"
#define FFS_MELOCK_NW "/gsm/MELOCK/Network"
#define FFS_MELOCK_NS "/gsm/MELOCK/NetworkSubnet"
#define FFS_MELOCK_SP "/gsm/MELOCK/Service"
#define FFS_MELOCK_CP "/gsm/MELOCK/Corporate"
#define FFS_MELOCK_SM "/gsm/MELOCK/SIMLock"

#ifdef ACI_PERSONALISTION_USE_FFS
static effs_t flash_pers_write()
{
  effs_t result;
  /*changed to pass addresses of data structures NOT actual data structure*/
  result = FFS_fwrite(FFS_MELOCK_STATUS,  &personalisation_status, sizeof(personalisation_status));
  if (result NEQ EFFS_OK)
    return result;
  result = FFS_fwrite(FFS_MELOCK_NW,  &personalisation_nw, sizeof(personalisation_nw));
  if (result NEQ EFFS_OK)
    return result;
  result = FFS_fwrite(FFS_MELOCK_NS,  &personalisation_ns, sizeof(personalisation_ns));
  if (result NEQ EFFS_OK)
    return result;
  result = FFS_fwrite(FFS_MELOCK_SP,  &personalisation_sp, sizeof(personalisation_sp));
  if (result NEQ EFFS_OK)
    return result;
  result = FFS_fwrite(FFS_MELOCK_CP,  &personalisation_cp, sizeof(personalisation_cp));
  if (result NEQ EFFS_OK)
    return result;
  result = FFS_fwrite(FFS_MELOCK_SM,  &personalisation_sim, sizeof(personalisation_sim));
  if (result NEQ EFFS_OK)
    return result;
  return result;
}

LOCAL effs_t flash_pers_read()
{
  effs_t result;
  result = FFS_fread(FFS_MELOCK_STATUS,  &personalisation_status, sizeof(personalisation_status));
  if (result NEQ EFFS_OK)
    return result;

  /* Optimization: Read personalisation data only, if needed (lock is not disabled) */
  if (aci_ext_personalisation_get_status(SIMLOCK_NETWORK) NEQ SIMLOCK_DISABLED)
  {
    result = FFS_fread(FFS_MELOCK_NW,  &personalisation_nw, sizeof(personalisation_nw));
    if (result NEQ EFFS_OK)
      return result;
  }

  if (aci_ext_personalisation_get_status(SIMLOCK_NETWORK_SUBSET)  NEQ SIMLOCK_DISABLED)
  {
    result = FFS_fread(FFS_MELOCK_NS,  &personalisation_ns, sizeof(personalisation_ns));
    if (result NEQ EFFS_OK)
      return result;
  }
  if (aci_ext_personalisation_get_status(SIMLOCK_SERVICE_PROVIDER) NEQ SIMLOCK_DISABLED)
  {
    result = FFS_fread(FFS_MELOCK_SP,  &personalisation_sp, sizeof(personalisation_sp));
    if (result NEQ EFFS_OK)
      return result;
  }
  if (aci_ext_personalisation_get_status(SIMLOCK_CORPORATE) NEQ SIMLOCK_DISABLED)
  {
    result = FFS_fread(FFS_MELOCK_CP,  &personalisation_cp, sizeof(personalisation_cp));
    if (result NEQ EFFS_OK)
      return result;
  }
  if (aci_ext_personalisation_get_status(SIMLOCK_SIM) NEQ SIMLOCK_DISABLED)
  {
    result = FFS_fread(FFS_MELOCK_SM,  &personalisation_sim, sizeof(personalisation_sim));
    if (result NEQ EFFS_OK)
      return result;
  }
  return result;

}
#endif /* ACI_PERSONALISTION_USE_FFS */


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -