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

📄 nvdiag.c

📁 free sources for gsm
💻 C
📖 第 1 页 / 共 3 页
字号:
============================================================================*/
static boolean sp_nv_read_item (
  nv_items_enum_type item
)
{
  switch (item) {
    case NV_SEC_CODE_I:
    case NV_FSC_I:
    case NV_FSC2_I:
    case NV_FSC2_CHKSUM_I:
    case NV_OTKSL_I:
    case NV_PAP_USER_ID_I:
    case NV_PPP_USER_ID_I:
    case NV_HDR_AN_AUTH_NAI_I:

      return (TRUE);

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


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

FUNCTION UNREADABLE_NV_ITEM

DESCRIPTION
  This procedure checks the given nv item type to see if it's one of
  the few items which are never allowed to be read.

DEPENDENCIES
  None.

RETURN VALUE
  TRUE if it is unreadable.
  FALSE if it's not.

SIDE EFFECTS
  None.

============================================================================*/
static boolean unreadable_nv_item (
  nv_items_enum_type item
)
{
  switch (item) {

    /* Keys, secrets, and passwords are unreadable */
    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:
#ifndef FEATURE_FFA_DEBUG_KEYS
    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_PAP_PASSWORD_I:
    case NV_DS_MIP_SS_USER_PROF_I:
    case NV_DS_MIP_DMU_MN_AUTH_I:
#endif
    case NV_SEC_DEVICE_KEY_I :

    /* We can't read the roaming lists using the usual nv_read command */
    case NV_ROAMING_LIST_I:
    case NV_ROAMING_LIST_683_I:
      return (TRUE);

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


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

FUNCTION UNWRITABLE_NV_ITEM

DESCRIPTION
  This procedure checks the given nv item type to see if it's one of
  the few items which are never allowed to be written. 

DEPENDENCIES
  None.

RETURN VALUE
  TRUE if it is unreadable.
  FALSE if it's not.

SIDE EFFECTS
  None.

============================================================================*/
static boolean unwritable_nv_item (
  nv_items_enum_type item
)
{
  switch (item) {

    /* Keys that are not unwritable */
    case NV_SEC_DEVICE_KEY_I :
       return (TRUE);

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

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

FUNCTION NVDIAG_READ

DESCRIPTION
  This procedure processes a request to read an NV item.

DEPENDENCIES
  None.

RETURN VALUE
  Pointer to response packet.

SIDE EFFECTS
  None.

============================================================================*/
PACKED void * nvdiag_read (
  PACKED void *req_pkt,
  uint16 pkt_len     
)
{
  DIAG_NV_READ_F_req_type *req = (DIAG_NV_READ_F_req_type *) req_pkt;
  DIAG_NV_READ_F_rsp_type *rsp;
  const int rsp_len = sizeof( DIAG_NV_READ_F_rsp_type );

  nv_items_enum_type eItem = (nv_items_enum_type)req->item ;
  nv_item_type       *pItemData;


  /*-----------------------------------------------------------------------
    First check to see if this item is not allowed to be read.  If it isn't,
    we will return an error packet.  NOTE:  These items are unreadable,
    even if security is unlocked!
  -----------------------------------------------------------------------*/
  if ( unreadable_nv_item(eItem) ) {
    return( diagpkt_err_rsp( DIAG_BAD_PARM_F, req_pkt, pkt_len ));
  }
   
  /*-----------------------------------------------------------------------
    Next check to see if this item we're requesting is a SP item, and if
    it is, make sure the SPC has been entered properly first, or that
    security is unlocked.  If it hasn't, we will return an error packet.
    Also make sure the security password is not unwritten.  If the security
    password is unwritten, then we rely on the SPC state flag.
  -----------------------------------------------------------------------*/
  else  if (sp_nv_read_item(eItem) &&
       (diag_get_sp_state() == DIAG_SPC_LOCKED) &&
       ((diag_get_security_state() == DIAG_SEC_LOCKED) ||
        diag_check_password (NULL) == TRUE))
  {
    return (diagpkt_err_rsp (DIAG_BAD_SPC_MODE_F, req_pkt, pkt_len));
  }

  /*-----------------------------------------------------------------------
    Anything else is readable at any time.
  -----------------------------------------------------------------------*/
  else {
    rsp = (DIAG_NV_READ_F_rsp_type *)diagpkt_alloc( DIAG_NV_READ_F, rsp_len );

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

    /*-----------------------------------------------------------------------
      Packet command id looks ok, format a command to NV to read the item.
      will wait for the response. The response packet is the same format
      as the request packet, so start by copying the data.
    -----------------------------------------------------------------------*/
    rsp->item = req->item;
    memcpy( (void *) ( rsp->item_data ),
            (void *) ( req->item_data ),
            DIAG_NV_ITEM_SIZE);

    pItemData = (nv_item_type *) &rsp->item_data[0];

    /* Send the nv read request, and report the status of the
    ** nv operation back to dm. */
    rsp->nv_stat = diag_nv_read(eItem, pItemData);

    return ( rsp );
  }

} /* nvdiag_read */



#ifndef FEATURE_GSM_PLT 
/*===========================================================================

FUNCTION CHK_REGISTRATION_PARAMETER_CHG

DESCRIPTION
  If the specified item to be written is one of the parameter-change
  registration variables: SLOT_CYCLE_INDEX, Station Class Mark, MOB_TERM_HOME,
  MOB_TERM_FOR_SID, or MOB_TERM_FOR_NID, and if the value of that item is
  changing, this routine causes a parameter-change registration event which
  will be noticed at the appropriate time.

  Since this write happens when the phone is offline, and must be reset,
  the phone won't notice that there was a change.  So we'll "notice" the
  change here and take advantage of another cause of parameter-change
  registration listed in 6.6.5.1.6: "Parameter-change registration is
  performed whenever there is no entry in the mobile-station's SID_NID_LIST
  that matches the base-station's SID and NID."

  If the new value is different from the old one we clear out the MC
  registration values (the whole SID_NID_LIST), so that if parameter-change
  registration is the only thing enabled, registration will occur.


DEPENDENCIES
  Assumes the specified item is about to be written to NV.
  This routine should be called only from nvdiag.c's nvdiag_write().

RETURN VALUE
  None.

SIDE EFFECTS
  MC's registration lists may be reinitialized.

============================================================================*/
static void chk_registration_parameter_chg (
  DIAG_NV_WRITE_F_req_type *req
)
{
  word i;       /* Loop index */
  boolean parameter_changed = FALSE;
                /* Flag is set to TRUE if a variable which causes Parameter-
                ** Change Registration is changed.
                */
  nv_items_enum_type eItem = (nv_items_enum_type) req->item;
  nv_item_type *pItemData = (nv_item_type *) &req->item_data[0];
  nv_item_type nvitem; //XXX

  switch (eItem) {
    case NV_SLOT_CYCLE_INDEX_I:
      if ( diag_nv_read(NV_SLOT_CYCLE_INDEX_I, &nvitem) != NV_DONE_S ) {
        MSG_HIGH("Failed to read Slot Cycle Index", 0, 0, 0);
      }
      else if (nvitem.slot_cycle_index != pItemData->slot_cycle_index) {
        parameter_changed = TRUE;
      }
      break;

    case NV_SCM_I:
      if ( diag_nv_read(NV_SCM_I, &nvitem) != NV_DONE_S ) {
        MSG_HIGH("Failed to read Station Class Mark", 0, 0, 0);
      }
      else if (nvitem.scm != pItemData->scm) {
        parameter_changed = TRUE;
      }
      break;

    case NV_MOB_TERM_HOME_I:
      nvitem.mob_term_home.nam = pItemData->mob_term_home.nam;

      if ( diag_nv_read(NV_MOB_TERM_HOME_I, &nvitem) != NV_DONE_S ) {
        MSG_HIGH("Failed to read Mob_Term_Home", 0, 0, 0);
      } else {
        for (i = 0; i < NV_MAX_MINS; i++) {
          if (nvitem.mob_term_home.enabled[i] !=
                pItemData->mob_term_home.enabled[i]) {
            parameter_changed = TRUE;
          }
        }        /* end loop over the MINs' flags in this NAM    */
      }          /* end else the nv_read worked correctly        */
      break;

    case NV_MOB_TERM_FOR_SID_I:
      nvitem.mob_term_for_sid.nam = pItemData->mob_term_for_sid.nam;

      if ( diag_nv_read(NV_MOB_TERM_FOR_SID_I, &nvitem) != NV_DONE_S ) {
        MSG_HIGH("Failed to read Mob_Term_For_SID", 0, 0, 0);
      } else {
        for (i = 0; i < NV_MAX_MINS; i++) {
          if (nvitem.mob_term_for_sid.enabled[i] !=
                pItemData->mob_term_for_sid.enabled[i]) {
            parameter_changed = TRUE;
          }
        }        /* end loop over the MINs' flags in this NAM    */
      }          /* end else the nv_read worked correctly        */
      break;

    case NV_MOB_TERM_FOR_NID_I:
      nvitem.mob_term_for_nid.nam = pItemData->mob_term_for_nid.nam;

      if ( diag_nv_read(NV_MOB_TERM_FOR_NID_I, &nvitem) != NV_DONE_S ) {
        MSG_HIGH("Failed to read Mob_Term_For_NID", 0, 0, 0);
      } else {
        for (i = 0; i < NV_MAX_MINS; i++) {
          if (nvitem.mob_term_for_nid.enabled[i] !=
                pItemData->mob_term_for_nid.enabled[i]) {
            parameter_changed = TRUE;
          }
        }        /* end loop over the MINs' flags in this NAM    */
      }          /* end else the nv_read worked correctly        */
      break;

    default:
      /* nothing to do in default case */
      break;

  } /* end switch on item */

#ifdef FEATURE_IS2000
  if (parameter_changed) {
    mccreg_clear_reg();    /* clear sid_nid_list and registered flag, so   */
                           /* the phone will register if parameter-change  */
                           /* registration is the only type enabled.       */
  }
#endif

} /* chk_registration_parameter_chg */

#endif // FEATURE_GSM_PLT


#ifdef FEATURE_DIAG_MEID_ENABLE
/*===========================================================================

FUNCTION MCC_MEID_GET_PESN

DESCRIPTION
  This function creates the Pseudo-ESN (PESN) from
  the Mobile Equipment IDentifier (MEID).
  
DEPENDENCIES
  None.

RETURN VALUE
  Value of pesn

SIDE EFFECTS
  None.
 
===========================================================================*/
dword mcc_meid_get_pesn
(
    qword meid   /* Mobile Equipment Identifier */
)
{
    dword     pesn;     /* pseudo-ESN */
    unsigned long meidhash[5];  /* MEID SHA-1 digest */

    mcc_meid_create_digest( meid, meidhash);

    /* the p-ESN is in the lowest 24 bits of meidhash[4] */
    pesn = (meidhash[4] & ~NVDIAG_PESN_PREFIX_MASK) | (NVDIAG_PESN_PREFIX);

    return pesn;

}

#endif /* FEATURE_DIAG_MEID_ENABLE */

#ifdef _SAMSUNG_MP_IMEI_WRITE
//======================================================================
/* SEC_UI2_KKW_20050920_3 TO CALCULATE THE CHECKSUM OF IMEI  */
static char cal_imei_cd2()  // 盔夯篮 UISTEST.C俊 勒澜
{
  int i;
  int cd_sum = 0;
  int cd_temp = 0;
  int convert_step1[13];
  char check_digit;
  
//Step 1.
  for (i = 0; i < 14; i++)
  {
    if (i % 2 == 0)
      convert_step1[i] = input_imei_ascii2[i] - '0';  
    else 
      convert_step1[i] = (input_imei_ascii2[i] - '0') *2;
  }

//Step 2. 
  for(i = 0; i < 14; i++)
  {
    if (convert_step1[i] < 10)
    {
     cd_sum += convert_step1[i];
    }
    else
    {
      cd_temp = convert_step1[i] / 10;
      cd_sum = cd_sum + cd_temp + (convert_step1[i] % 10);
    }
  }

//Step 3.
   if (cd_sum % 10 == 0)
   {
     check_digit = '0';
   }

⌨️ 快捷键说明

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