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

📄 aci_ext_pers.c

📁 是一个手机功能的模拟程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
+-----------------------------------------------------------------------------
|  Project :
|  Modul   :  J:\g23m-aci\aci_ext\aci_ext_pers.c
+-----------------------------------------------------------------------------
|  Copyright 2002 Texas Instruments Berlin, AG
|                 All rights reserved.
|
|                 This file is confidential and a trade secret of Texas
|                 Instruments Berlin, AG
|                 The receipt of or possession of this file does not convey
|                 any rights to reproduce or disclose its contents or to
|                 manufacture, use, or sell anything it may describe, in
|                 whole, or in part, without the specific written consent of
|                 Texas Instruments Berlin, AG.
+-----------------------------------------------------------------------------
|  Purpose :
+-----------------------------------------------------------------------------
*/
#include "aci_all.h"

#include "aci_cmh.h"
#include "ati_cmd.h"
#include "aci_cmd.h"

#ifdef FAX_AND_DATA
#include "aci_fd.h"
#endif    /* of #ifdef FAX_AND_DATA */

#undef ACI_PERSONALISTION_USE_FFS

#include "aci.h"
#include "psa.h"
#include "psa_sim.h"
#include "psa_sms.h"
#include "psa_mmi.h"
#include "cmh.h"
#include "phb.h"
#include "aoc.h"

#include "psa_sim.h"            /* simShrdPrm */

#ifdef WIN32
/* some testcases need that... some others cannot pass then though */
//#define SIMLOCK
#endif

#include "aci_ext_pers.h"
#include "aci_slock.h"

#include "pcm.h"                /* EF_SIMLCKEXT */

#ifdef MMI_SIMLOCK_TEST
  #define ACI_PERSONALISTION_USE_FFS
#endif

#ifdef ACI_PERSONALISTION_USE_FFS
#include "ffs.h"
#include "ffs_coat.h"
#endif /* ACI_PERSONALISTION_USE_FFS */



#define SLOCK_PCM_NRM 1         /* SIM lock data is stored as SIMLOCK to the PCM */
#define SLOCK_PCM_EXT 2         /* SIM lock data is stored as SIMLOCKEXT to the PCM */

UBYTE aci_slock_sim_lock_field = NOT_PRESENT_8BIT;  /* type of PCM record for sim lock field */

#ifdef _SIMULATION_
EF_SIMLCKEXT simlock_pcm_memory;    /* emulates the PCM memory in WIN32 environment. */
#endif

#include "aci_ext_pers_cus.h" /* the customer specific personalisation data. */

LOCAL UBYTE pcm_get_sim_lock (EF_SIMLCKEXT * simlck);
LOCAL void pcm_set_sim_lock (EF_SIMLCKEXT * simlck);

#ifdef ACI_PERSONALISTION_USE_FFS
LOCAL effs_t flash_read_result = -1; /* remeber last flash read result */
LOCAL effs_t flash_pers_write();
LOCAL effs_t flash_pers_read();
#endif

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

/*
  Load SIM lock details from PCM and put it into the actual memory structure. Returns PCM_OK if everything was okay.
  The actual PCM record is only supporting one IMSI per lock. This should be extended in the future!
  */
LOCAL UBYTE aci_ext_personalisation_load_pcm( void )
{
  EF_SIMLCKEXT simlck;
  UBYTE result;
  CHAR t_imsi[MAX_IMSI_LEN+1]={'\0'};

  #ifdef ACI_PERSONALISTION_USE_FFS
  flash_read_result = flash_pers_read();
  #endif /* ACI_PERSONALISTION_USE_FFS */

  result = pcm_get_sim_lock(&simlck);
  if (result EQ PCM_OK)
  {
    memcpy(&personalisation_status, &simlck, T_ACI_PERS_STATUS_LEN);

    #ifdef ACI_PERSONALISTION_USE_FFS
    personalisation_sim.count = (personalisation_sim.count EQ 0?1:personalisation_sim.count);
    personalisation_nw.count = (personalisation_nw.count EQ 0?1:personalisation_nw.count);
    personalisation_ns.count = (personalisation_ns.count EQ 0?1:personalisation_ns.count);
    personalisation_sp.count = (personalisation_sp.count EQ 0?1:personalisation_sp.count);
    personalisation_cp.count = (personalisation_cp.count EQ 0?1:personalisation_cp.count);
    #else /* ACI_PERSONALISTION_USE_FFS */
    personalisation_sim.count = 1;
    personalisation_nw.count = 1;
    personalisation_ns.count = 1;
    personalisation_sp.count = 1;
    personalisation_cp.count = 1;
    #endif /* ACI_PERSONALISTION_USE_FFS */
    
    memcpy(t_imsi, simlck.p_imsi, simlck.len_p_imsi);
    t_imsi[simlck.len_p_imsi] = '\0';                  /* make an ASCIIZ string */
    psaSIM_encodeIMSI(t_imsi, &personalisation_sim.data->c_field, personalisation_sim.data->imsi);

    memcpy(t_imsi, simlck.n_imsi, simlck.len_n_imsi);
    t_imsi[simlck.len_n_imsi] = '\0';
    psaSIM_encodeIMSI(t_imsi, &personalisation_nw.data->c_field, personalisation_nw.data->imsi);

    memcpy(t_imsi, simlck.ns_imsi, simlck.len_ns_imsi);
    t_imsi[simlck.len_ns_imsi] = '\0';
    psaSIM_encodeIMSI(t_imsi, &personalisation_ns.data->c_field, personalisation_ns.data->imsi);

    memcpy(t_imsi, simlck.sp_imsi, simlck.len_sp_imsi);
    t_imsi[simlck.len_sp_imsi] = '\0';
    psaSIM_encodeIMSI(t_imsi, &personalisation_sp.data->c_field, personalisation_sp.data->imsi);

    memcpy(t_imsi, simlck.c_imsi, simlck.len_c_imsi);
    t_imsi[simlck.len_c_imsi] = '\0';
    psaSIM_encodeIMSI(t_imsi, &personalisation_cp.data->c_field, personalisation_cp.data->imsi);

    personalisation_sp.data->gid1 = simlck.gidl1;
    personalisation_cp.data->gid1 = simlck.gidl1;
    personalisation_cp.data->gid2 = simlck.gidl2;
  }
  return result;
}

LOCAL void convert_personalisationstruct_to_pcm(EF_SIMLCKEXT* simlck)
{
  CHAR t_imsi[MAX_IMSI_LEN+1]={'\0'};

  memcpy(simlck,&personalisation_status,T_ACI_PERS_STATUS_LEN);

  psaSIM_decodeIMSI(personalisation_sim.data->imsi,personalisation_sim.data->c_field,t_imsi);
  simlck->len_p_imsi = strlen(t_imsi);
  memcpy(simlck->p_imsi, t_imsi, MAX_IMSI_LEN);  /* since x_imsi in ffs is only of size[15] */

  psaSIM_decodeIMSI(personalisation_nw.data->imsi,personalisation_nw.data->c_field,t_imsi);
  simlck->len_n_imsi = strlen(t_imsi);
  memcpy(simlck->n_imsi, t_imsi, MAX_IMSI_LEN);

  psaSIM_decodeIMSI(personalisation_ns.data->imsi,personalisation_ns.data->c_field,t_imsi);
  simlck->len_ns_imsi = strlen(t_imsi);
  memcpy(simlck->ns_imsi, t_imsi, MAX_IMSI_LEN);

  psaSIM_decodeIMSI(personalisation_sp.data->imsi,personalisation_sp.data->c_field,t_imsi);
  simlck->len_sp_imsi = strlen(t_imsi);
  memcpy(simlck->sp_imsi, t_imsi, MAX_IMSI_LEN);

  psaSIM_decodeIMSI(personalisation_cp.data->imsi,personalisation_cp.data->c_field,t_imsi);
  simlck->len_c_imsi = strlen(t_imsi);
  memcpy(simlck->c_imsi, t_imsi, MAX_IMSI_LEN);


  if (FldGet(personalisation_status.locks2,clock) EQ SIMLOCK_ENABLED)
  {
   simlck->gidl1 = personalisation_cp.data->gid1;
   simlck->gidl2 = personalisation_cp.data->gid2;
  }

  if (FldGet(personalisation_status.locks1,splock) EQ SIMLOCK_ENABLED)
  {
   simlck->gidl1 = personalisation_sp.data->gid1;
  }
}

/*
  Save SIM lock details from the actual memory structure and put it into PCM. Returns PCM_OK if everything was okay.
  */
LOCAL void aci_ext_personalisation_save( void )
{
  EF_SIMLCKEXT simlck;
  UBYTE result;

  result = pcm_get_sim_lock(&simlck);
  if (result EQ PCM_OK)
  {
    convert_personalisationstruct_to_pcm(&simlck);
    pcm_set_sim_lock(&simlck);
  }

  #ifdef ACI_PERSONALISTION_USE_FFS
  flash_pers_write();
  #endif
}

/*
  Initialisation of this extension. Might be used to initialise variables, set temporary data to default values and so on.
  This method will be called once before any other public method of this extension.
  */
void aci_ext_personalisation_init( void )
{
#ifndef MMI_SIMLOCK_TEST
  #ifdef WIN32
  /* initialize the faked PCM Data with the compiled data */
  convert_personalisationstruct_to_pcm(&simlock_pcm_memory);
  #endif
  aci_ext_personalisation_load_pcm();
#else /*for mmi testing, just read FFS*/
  #ifdef ACI_PERSONALISTION_USE_FFS
  flash_pers_read();
  #endif
#endif
}


/*
  ACI extension method for retrieving the data for one single personalisation type.
  This personalisation data is stored into a separate customer managed memory area
  and the customer has to implement this extension method to return the actual data
  of the questioned personalisation type.
  */
T_ACI_PERS_DATAS aci_ext_personalisation_get_data( T_SIMLOCK_TYPE personalisation_type )
{
  T_ACI_PERS_DATAS retvalue;

  TRACE_FUNCTION("aci_ext_personalisation_get_data()");

  switch (personalisation_type)
  {
    default:  /* should not occour */
    case SIMLOCK_FIRST_SIM:
    case SIMLOCK_SIM: retvalue.nw = personalisation_sim;break;
    case SIMLOCK_NETWORK: retvalue.nw = personalisation_nw;break;
    case SIMLOCK_NETWORK_SUBSET: retvalue.nw = personalisation_ns;break;
    case SIMLOCK_SERVICE_PROVIDER: retvalue.sp = personalisation_sp;break;
    case SIMLOCK_CORPORATE: retvalue.cp = personalisation_cp;break;
  }
  return retvalue;
}


/*
  ACI extension method for retrieving the status of a single personalisation type.
  The personalisation status is stored in a separate customer managed memory area
  and the customer has to implement this extension method to return the actual status
  of the questioned personalisation type.
  */
T_SIMLOCK_STATUS aci_ext_personalisation_get_status( T_SIMLOCK_TYPE personalisation_type )
{
  TRACE_FUNCTION("aci_ext_personalisation_get_status()");
  switch (personalisation_type)
  {
    case SIMLOCK_SIM:              return FldGet(personalisation_status.locks1,plock);
    case SIMLOCK_NETWORK:          return FldGet(personalisation_status.locks1,nlock);
    case SIMLOCK_NETWORK_SUBSET:   return FldGet(personalisation_status.locks1,nslock);
    case SIMLOCK_SERVICE_PROVIDER: return FldGet(personalisation_status.locks1,splock);
    case SIMLOCK_CORPORATE:        return FldGet(personalisation_status.locks2,clock);
    case SIMLOCK_FIRST_SIM:        return FldGet(personalisation_status.locks2,flock);
    default:                       return SIMLOCK_FAIL;
  }
}

/*
  ACI extension method for retrieving the status of a single personalisation type.
  The personalisation status is stored in a separate customer managed memory area
  and the customer has to implement this extension method to return the actual status
  of the questioned personalisation type.
  */
T_SIMLOCK_STATUS aci_ext_personalisation_set_status( T_SIMLOCK_TYPE personalisation_type,
  T_SIMLOCK_STATUS lock, char* passwd)
{
  U8 exp_pin[16];

  TRACE_FUNCTION("aci_ext_personalisation_set_status()");

  /* check for illegal status */
  if (lock EQ SIMLOCK_FAIL)
    return SIMLOCK_FAIL;

  /* Check, if lock is blocked. If this is the case, compare given PWD with PUK! */
  if (aci_ext_personalisation_get_status(personalisation_type) EQ SIMLOCK_BLOCKED)
    decodeB2A(personalisation_status.PUK, 8, exp_pin);
  else
  {
    switch (personalisation_type)
    {
      case SIMLOCK_SIM: decodeB2A(personalisation_status.PKey, 8, exp_pin);break;
      case SIMLOCK_NETWORK: decodeB2A(personalisation_status.NKey, 8, exp_pin);break;
      case SIMLOCK_NETWORK_SUBSET: decodeB2A(personalisation_status.NSKey, 8, exp_pin);break;
      case SIMLOCK_SERVICE_PROVIDER: decodeB2A(personalisation_status.SPKey, 8, exp_pin);break;
      case SIMLOCK_CORPORATE: decodeB2A(personalisation_status.CKey, 8, exp_pin);break;
      default: return SIMLOCK_FAIL;
    }
  }
  /*use length of stored pin NOT entered pin for comparison*/
  if (memcmp( exp_pin, passwd, strlen((char*)exp_pin) ))
  {
    /* Block personalisation lock, if tried too often! */
    personalisation_status.cnt++;
    if (personalisation_status.cnt >= personalisation_status.maxcnt)

⌨️ 快捷键说明

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