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

📄 nvdiag.c

📁 free sources for gsm
💻 C
📖 第 1 页 / 共 3 页
字号:
/*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*

              Nonvolatile Storage Diagnostics Packet Processing

General Description
  Diagnostic packet processing routines for NV memory operations.

Copyright (c) 1990-2005 by QUALCOMM, Incorporated.  All Rights Reserved.
*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*/

/*===========================================================================

                           Edit History

$Header: //depot/asic/msmshared/services/diag/nvdiag.c#31 $

when       who     what, where, why
--------   ---     ----------------------------------------------------------
03/14/05   as      Added MEID support
02/18/04   as      Fixed critical lint errors.
12/23/04   ec      Added code for multiple items NV Write with stacking items
                   in a single request packet.
11/02/04   as      Featurized the NV items in unreadable_nv_item() that are 
                   key related using a debug feature FEATURE_FFA_DEBUG_KEYS. 
10/06/04   as      Added code to prevent write access from diag, for a subset
                   of nv items
10/04/04   as      Made unreadable nv items protected by SPC for sp_nv_write 
09/14/04   as      Made passwords unreadable, to prevent cloning phones
05/18/04   as      Added code to prevent overwriting a nonzero ESN, in
                   nvdiag_write 
02/23/04   as      Updated SP_NV_WRITE_ITEM when the feature 
                   FEATURE_SSPR_ENHANCEMENTS is defined.
10/06/03   as      Added read access to mobile IP provisioning items.
05/07/03   jct     Added featurization to dissallow certain operations that
                   can access memory (FEATURE_DIAG_DISALLOW_MEM_OPS):
                      DIAG_NV_PEEK_F
                      DIAG_NV_POKE_F
05/05/03   as      Added NV_RTRE_CONFIG_I,NV_UIM_PREF_PROTOCOL_I to 
                   sp_nv_write_item()
01/08/03   ma      featurization for GSM PLT
08/20/02   lad     FEATURE_DIAG_COUPLED_ARCHITECTURE/1X support.
01/21/02   as      Moved diag_nv_read(), diag_nv_write to diagnv.c
09/18/01   jal     Fixed allocation for NV_READ response.  Fixed handling
                   of SPC unlocking.
08/20/01   jal     Updated for core VU
06/27/01   jal     Created file.
===========================================================================*/
#ifdef __cplusplus
  extern "C" {
#endif

#include "comdef.h"
#include "customer.h"

#include "diagcmd.h"
#include "diag.h"
#include "diagnv.h"
#include "diagdiag.h"
#include "nvdiag.h"
#include "diagtune.h"

#ifdef FEATURE_IS2000
  #include "mccreg.h"
#endif

#include "nv.h"

#include "msg.h"

extern boolean diag_set_sp_state( diag_sp_type sp );
#ifdef _SAMSUNG_MP_IMEI_WRITE
static  char  input_imei_ascii2[(9-1)*2]={'\0',};  //sec_ui2_kkw_20050921_4 
#endif


/*===========================================================================

                DEFINITIONS AND DECLARATIONS FOR MODULE

This section contains definitions for constants, macros, types, variables
and other items needed by this module.

===========================================================================*/
/* Tell lint that we are OK with the fact that pkt_len and req are not
** used in some of the packets, as this is dictated by the awesome design */
/*lint -esym(715,pkt_len,req) */



#if !defined (FEATURE_HWTC)
/*===========================================================================

FUNCTION NVDIAG_PEEK

DESCRIPTION
  This procedure processes a request to peek into Non-Volatile memory.

DEPENDENCIES
  None.

RETURN VALUE
  Pointer to response packet.

SIDE EFFECTS
  None.

===========================================================================*/
PACKED void * nvdiag_peek (
  PACKED void *req_pkt,
  uint16 pkt_len     
)
{
  nvdiag_peek_rsp_type *rsp;
  const int rsp_len = sizeof (nvdiag_peek_rsp_type);
  nvdiag_peek_req_type *req = (nvdiag_peek_req_type *) req_pkt;
  nv_stat_enum_type nv_status;

  /*----------------------------------------------------------------------
    Check security, since this is a secure funciton
  ----------------------------------------------------------------------*/
  if (diag_get_security_state () == DIAG_SEC_LOCKED)
  {
    return (diagpkt_err_rsp (DIAG_BAD_SEC_MODE_F, req_pkt, pkt_len));
  }

  /*---------------------------------------------------------------------
    Check requested length against maximum allowed length.
  ----------------------------------------------------------------------*/
  if (req->length > NV_MAX_PEEK_SIZE)
  {
    return (diagpkt_err_rsp (DIAG_BAD_PARM_F, req_pkt, pkt_len));
  }

  rsp = (nvdiag_peek_rsp_type *) diagpkt_alloc (DIAG_NV_PEEK_F, rsp_len);

  if (rsp)
  {
    rsp->peeknv.address = req->address;
    rsp->peeknv.length = req->length;
    
    /*----------------------------------------------------------------------
      Send a command to the NV task to peek at the data.  diag will wait
      here until NV returns the data.
    -----------------------------------------------------------------------*/
    nv_status = diagnv_peek ((nv_peek_type *) &rsp->peeknv);
  
    /*--------------------------------------------------------------------
      If NV had trouble with the command, it must have been the fault of
      the data in the packet :).  Send error reply.
    ---------------------------------------------------------------------*/
  
    if (nv_status != NV_DONE_S)
    {
      /* fill in our own errpkt here. */
      diagpkt_set_cmd_code (rsp, DIAG_BAD_PARM_F);
  
      memcpy ((void*) ((DIAG_BAD_CMD_F_rsp_type *) rsp)->pkt,
              (void *) req,
              sizeof (DIAG_BAD_CMD_F_rsp_type) - 1);
    }
  }

  return (rsp);

} /* nvdiag_peek */



/*===========================================================================

FUNCTION NVDIAG_POKE

DESCRIPTION
  This procedure processes a request to poke into Non-Volatile memory.

DEPENDENCIES
  None.

RETURN VALUE
  Pointer to response packet.

SIDE EFFECTS
  None.

===========================================================================*/
PACKED void * nvdiag_poke (
  PACKED void *req_pkt,
  uint16 pkt_len     
)
{
  nvdiag_poke_cmd_type *req = (nvdiag_poke_cmd_type *) req_pkt;
  nvdiag_poke_cmd_type *rsp;
  const int rsp_len = sizeof (nvdiag_poke_cmd_type);
  nv_stat_enum_type nv_status;

  /*----------------------------------------------------------------------
    Check security, since this is a secure funciton
  ----------------------------------------------------------------------*/
  if (diag_get_security_state () == DIAG_SEC_LOCKED)
  {
    return (diagpkt_err_rsp (DIAG_BAD_SEC_MODE_F, req_pkt, pkt_len));
  }

  /*------------------------------------------------------------------------
    Check requested poke length against maximum allowed poke length.
  -------------------------------------------------------------------------*/
  if (req->nvpoke.length > DIAG_MAX_NV_POKE)
  {
    return (diagpkt_err_rsp (DIAG_BAD_PARM_F, req_pkt, pkt_len));
  }

  /*-----------------------------------------------------------------------
    Packet looks ok, format a command to NV to write the poke data. Diag
    will wait for the response.
  -----------------------------------------------------------------------*/
  nv_status = diagnv_poke (&req->nvpoke);

  /*------------------------------------------------------------------------
    If NV complains, it must be because of bad data in the packet, so send
    an error reply.
  ------------------------------------------------------------------------*/

  if (nv_status != NV_DONE_S)
  {
    return (diagpkt_err_rsp (DIAG_BAD_PARM_F, req_pkt, pkt_len));
  }

 /*----------------------------------------------------------------------
   NV returned ok, so finish the response packet. (Its just an echo of
   the request packet).
 ----------------------------------------------------------------------*/
  rsp = (nvdiag_poke_cmd_type *) diagpkt_alloc (DIAG_NV_POKE_F, rsp_len);

  if (rsp == NULL)
  {
    /* If we can't allocate, diagpkt_err_rsp() can't either. */
    return (NULL);
  }

  rsp->nvpoke = req->nvpoke;

  return (rsp);

} /* nvdiag_poke */
#endif /* !defined (FEATURE_HWTC) */



/*===========================================================================

FUNCTION SP_NV_WRITE_ITEM

DESCRIPTION
  This procedure checks the given nv item type to see if it's a Service
  Programming item, which should not be written until the SPC
  has been entered, or security unlocked.

DEPENDENCIES
  None.

RETURN VALUE
  TRUE if it is a Service Programming item,
  FALSE if not

SIDE EFFECTS
  None.

============================================================================*/
static boolean sp_nv_write_item (
  nv_items_enum_type item
)
{
  switch (item) {
    case NV_SLOT_CYCLE_INDEX_I:
    case NV_CDMA_SID_LOCK_I:
    case NV_CDMA_SID_ACQ_I:
    case NV_ANALOG_SID_LOCK_I:
    case NV_ANALOG_SID_ACQ_I:
    case NV_ANALOG_FIRSTCHP_I:
    case NV_ANALOG_HOME_SID_I:
    case NV_ANALOG_REG_I:
    case NV_PCDMACH_I:
    case NV_SCDMACH_I:
    case NV_NAM_CHKSUM_I:
    case NV_MIN1_I:
    case NV_MIN2_I:
    case NV_MOB_TERM_HOME_I:
    case NV_MOB_TERM_FOR_SID_I:
    case NV_MOB_TERM_FOR_NID_I:
    case NV_ACCOLC_I:
    case NV_HOME_SID_NID_I:
    case NV_SID_NID_I:
    case NV_MIN_CHKSUM_I:
    case NV_SEC_CODE_I:
    case NV_IMSI_MCC_I:
    case NV_IMSI_11_12_I:
    case NV_DIR_NUMBER_I:
    case NV_FSC_I:
    case NV_WDC_I:
    case NV_FSC2_I:
    case NV_FSC2_CHKSUM_I:
    case NV_IMSI_ADDR_NUM_I:
    case NV_DIR_NUMBER_PCS_I:
    case NV_OTKSL_I:
    case NV_RTRE_CONFIG_I:
    case NV_UIM_PREF_PROTOCOL_I:
    case NV_PAP_USER_ID_I:
    case NV_PAP_PASSWORD_I:
    case NV_A_KEY_I:
    case NV_A_KEY_CHKSUM_I:
    case NV_SSD_A_I:
    case NV_SSD_B_I:
    case NV_UP_KEY_I:
    case NV_ROAMING_LIST_I:
    case NV_ROAMING_LIST_683_I:   
    case NV_HDR_AN_AUTH_PASSWORD_I:
    case NV_HDR_AN_AUTH_PASSWD_LONG_I:
    case NV_HDR_AN_PPP_PASSWORD_I:
    case NV_PPP_PASSWORD_I:
    case NV_DS_MIP_SS_USER_PROF_I:
    case NV_DS_MIP_DMU_MN_AUTH_I:

      return (TRUE);

    default:
      return (FALSE);
  }
} /* sp_nv_write_item */



#ifdef FEATURE_NV_WRITE_ONLINE
/*===========================================================================

FUNCTION DRAM_NV_WRITE_ITEM

DESCRIPTION
  This procedure checks the given nv item type to see if it's accessible
  using the "NV WRITE ONLINE" command which modifies both the NV ITEM
  as well as the variable that shadows the NV ITEM and actually gets
  used.

DEPENDENCIES
  None.

RETURN VALUE
  TRUE if it is allowed to be written to by "NV WRITE ONLINE" command,
  FALSE if not

SIDE EFFECTS
  None.

============================================================================*/
static boolean dram_nv_write_item (
  nv_items_enum_type item
)
{
  switch (item) {
    case NV_AUTO_LOCK_I:
    case NV_AUTO_NAM_I:
    case NV_BEEP_LVL_I:
    case NV_CALL_BEEP_I:
    case NV_CALL_FADE_ALERT_I:
    case NV_CONT_KEY_DTMF_I:
    case NV_CURR_NAM_I:
    case NV_LOCK_CODE_I:
    case NV_SPEAKER_LVL_I:
    case NV_SVC_AREA_ALERT_I:
    case NV_AUTO_ANSWER_I:
    case NV_EAR_LVL_I:
    case NV_LOCK_I:
    case NV_BEEP_SPKR_LVL_I:
    case NV_VOICE_PRIV_I:
    case NV_CDMA_PREF_SERV_I:
    case NV_AIR_TIMER_I:
    case NV_ROAM_TIMER_I:
    case NV_AIR_CNT_I:
    case NV_ROAM_CNT_I:

      return (TRUE);

    default:
      return (FALSE);
  } /* switch (item) */

} /* dram_nv_write_item */
#endif /* #ifdef FEATURE_NV_WRITE_ONLINE */



/*===========================================================================

FUNCTION SP_NV_READ_ITEM

DESCRIPTION
  This procedure checks the given nv item type to see if it's a Service
  Programming item, which should not be read until the SPC has been
  entered, or security unlocked.

DEPENDENCIES
  None.

RETURN VALUE
  TRUE if it is a Service Programming item,
  FALSE if not

SIDE EFFECTS
  None.

⌨️ 快捷键说明

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