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

📄 nvimnv.c

📁 free sources for gsm
💻 C
📖 第 1 页 / 共 5 页
字号:
      status = NV_DONE_S;
   }

   return status;
}

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

FUNCTION NV_POKE

DESCRIPTION
  This function writes a number of bytes to a specified location in NVM.

DEPENDENCIES
  None.

RETURN VALUE
  NV_DONE_S    if it worked
  NV_FAIL_S    if write was unsuccessful.
  NV_BADPARM_S if range of bytes is outside of NVM range.
  Others       Failure for internal call

SIDE EFFECTS
  NVM locations are changed, bypassing normal logical NVM access.
  Under educated use may destroy internal EEPROM structures and the
  ability for the NV task to function.

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

LOCAL nv_stat_enum_type nv_poke
(
  nv_cmd_type  *cmd_ptr          /* Command block */
)
{
   word              start_addr;       /* Start address of poke */
   word              end_addr;         /* End address of poke */

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

  /* Check to make sure poke length is not too big */
  /* and that bytes are not extending beyond NVM.  */

  if (cmd_ptr->data_ptr->poke.length > NV_MAX_POKE_SIZE) return NV_BADPARM_S;

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

  start_addr       = cmd_ptr->data_ptr->poke.address;
  end_addr         = start_addr + cmd_ptr->data_ptr->poke.length - 1;

  /* Next, check for factory area */
  if ((start_addr <= end_addr) && (start_addr >= NVD_MAX_OFFSET) &&
      (end_addr <= NVD_MAX_OFFSET+NV_FACTORY_RSVD))
  {
     /* Write to the factory data file */
     return nvimnv_poke_factory(cmd_ptr);
  }

  /* The factory area is the only supported area */
  return NV_BADPARM_S;
} /* nv_poke */

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

FUNCTION NV_FREE

DESCRIPTION
  This function free's a nv item's memory allocation.

DEPENDENCIES
  None.

LIMITATIONS
  Only the SMS items support free'ing at the item level, at this time.

RETURN VALUE
  NV_DONE_S      if it worked
  NV_NOTACTIVE_S Item is not allocated
  NV_BADPARM_S   SMS item is out of range
  Others         Failure for internal call

SIDE EFFECTS
  None

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

LOCAL nv_stat_enum_type nv_free
(
  nv_cmd_type  *cmd_ptr          /* Command block */
)
{
  nv_stat_enum_type status = NV_DONE_S;
  uint16      sms_index = NVI_MAX_SMS_ADDR;   /* SMS message slot to be freed */
  char        filename[20] = "\0";

  /* only sms deletion is supported at this time */
  if ((cmd_ptr->item != NV_SMS_I) && (cmd_ptr->item != NV_SMS_GW_I))
    return NV_BADPARM_S;

#ifdef FEATURE_NV_RUIM
    if ( nvruim_free(cmd_ptr, &status) == NV_RUIM_SUPPORTS_ITEM )
      return status;
#endif

  /* Insure we have a valid sms index */
  if (cmd_ptr->item == NV_SMS_I)
     sms_index = cmd_ptr->data_ptr->sms.address;
  else if (cmd_ptr->item == NV_SMS_GW_I)
     sms_index = cmd_ptr->data_ptr->sms_gw.address;

  if(sms_index >= NVI_MAX_SMS_ADDR)
    status = NV_BADPARM_S;
  else
  {
    if (cmd_ptr->item == NV_SMS_I)
      (void) snprintf(filename, sizeof(filename), "/nvm/sms_%05d", sms_index);
    else if (cmd_ptr->item == NV_SMS_GW_I)
      (void) snprintf(filename, sizeof(filename), "/nvm/sms_gw_%05d", sms_index);
    if (efs_unlink(filename) != 0)
      status = NV_NOTACTIVE_S;
  }
  return status;
} /* nv_free */

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

FUNCTION NV_DETERMINE_ESN_VALIDITY

DESCRIPTION
  This function is determines if the current ESN has been programmed with the
  status of this check returned.

DEPENDENCIES
  None.

RETURN VALUE
  TRUE if the current ESN is non-zero with proper checksums, else FALSE

SIDE EFFECTS

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

boolean nv_determine_esn_validity( void)
{
  /* This is gross, but there is not enough stack space
   *  for these next two items so we declare them as the appear in the enum
   */
  dword             nv_item1_esn;        /* tmp buffer for esn */
  dword             nv_item2_esn_chksum; /* tmp buffer for esn checksum */
  nv_stat_enum_type status;              /* to get status of NV operations */
  fs_rsp_msg_type   read_rsp; /* Response message from READ operation */
  nvim_efs_params   *fparams = nv_op_get_fparams(NV_ESN_I);
  fs_file_position_type fpos = nv_op_get_file_pos(NV_ESN_I);

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

  /* Start by reading the ESN and returning FALSE if it is now -1        */

  status = nvim_read_efs(fparams->rd_handle,/* file handle */
                         fpos,       /* file position */
                         &nv_item1_esn,          /* data ptr */
                         sizeof(nv_item1_esn)); /* data count */
  if( (status != NV_DONE_S) ||
      (nv_item1_esn == 0xFFFFFFFFu) )  {
    /* ------------------------- */
    /* The ESN has not been set, */
    /* return FALSE              */
    /* ------------------------- */
    ERR( "ESN has not been set", 0, 0, 0);
    return FALSE;
  }

  if( nv_item1_esn == 0 )  {
    MSG_HIGH("ESN is zero for factory test",0,0,0);
  }

  /* --------------------------------------------------------------------- */
  /* To get here the ESN has been set. Determine if the checksums are      */
  /* valid. Do this be comparing calculated checksums against stored sums  */
  /* --------------------------------------------------------------------- */

  fs_read(fparams->rd_handle,  /* file handle */
          &nv_item2_esn_chksum,   /* source to store bytes */
          sizeof(nv_item2_esn_chksum),    /* # bytes to write */
          NULL,     /* callback_function */
          &read_rsp); /* message ptr */

  /* --------------------------------------------------------------------- */
  /* To get here the ESN is valid and this is not a pre-Version 5.      */
  /* Check for proper checksums and return TRUE if so, else return FALSE   */
  /* --------------------------------------------------------------------- */

  if( crc_30_calc( (byte *)&nv_item1_esn, sizeof(nv_item1_esn) * 8) !=
      nv_item2_esn_chksum)  {
    /* ------------------------- */
    /* The ESN checksum is not   */
    /* valid, return FALSE       */
    /* ------------------------- */
    ERR( "Stored ESN CHKSUM bad: %u", nv_item2_esn_chksum, 0, 0);
    return FALSE;
  } else {
    return TRUE;
  }
}

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

FUNCTION NVIMNV_BUILD_NVM

DESCRIPTION
  This function builds all NVM variables.  All 'active' flags are set
  to 'false' as all fixed item files (except sys permanent) are cleared.
  Any items that rquire an initial value are updated here

DEPENDENCIES

RETURN VALUE
  NV_DONE_S if it worked
  NV_FAIL_S if a variable could not be initialized.

SIDE EFFECTS

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

static nv_stat_enum_type nvimnv_build_nvm(void)
{
   nv_stat_enum_type  status;    /* Status to return to calling procedure */
   word               cnt;       /* Counter for attempts to write variable */

   /* Clear all appropriate fixed item files */
   nvim_nv_clear();

   /* Initialize the lock code to the default value (0000)   */
   for( cnt=0; cnt<NV_LOCK_CODE_SIZE; cnt++)  {
     local_item.lock_code.digits[ cnt] = '0';
   }
   local_cmd.item       = NV_LOCK_CODE_I;
   local_cmd.tcb_ptr    = NULL;
   local_cmd.sigs       = 0;
   local_cmd.done_q_ptr = NULL;
   local_cmd.cmd        = NV_WRITE_F;
   local_cmd.data_ptr   = &local_item;
   status = nvimw_write( &local_cmd);
   if(status != NV_DONE_S)
   {
      return status;
   }

   /* Initialize the sec code to the default value (0000)   */
   for( cnt=0; cnt<NV_SEC_CODE_SIZE; cnt++)  {
     local_item.sec_code.digits[ cnt] = '0';
   }
   local_cmd.item       = NV_SEC_CODE_I;
   local_cmd.tcb_ptr    = NULL;
   local_cmd.sigs       = 0;
   local_cmd.done_q_ptr = NULL;
   local_cmd.cmd        = NV_WRITE_F;
   local_cmd.data_ptr   = &local_item;
   status = nvimw_write( &local_cmd);

   return status;
}

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

FUNCTION NV_CLEAR_CRCS

DESCRIPTION
  This function is called to clear CRCs in NV when the NV is built. The function
  clears the NAM checksums, the MIN checksums within each NAM, and, if
  the ESN and IMEI have not already been written (assigned), the ESN, the IMEI,
  the ESN checksum, the IMEI checksum.  This action lets higher level tasks
  know that these parameters are not valid and that service programming is
  required.

DEPENDENCIES
  NVM must have been built.

RETURN VALUE
  NV_DONE_S if it worked
  NV_FAIL_S if the EEPROM access has failed

SIDE EFFECTS
  NV parameters identified above are zeroed.

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

LOCAL nv_stat_enum_type  nv_clear_crcs (void)

{
  byte                nam_idx;       /* NAM counter */
  byte                min_idx;       /* MIN counter */

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

  /* Setup command buffer parameters. */

  local_cmd.cmd = NV_WRITE_F;
  local_cmd.tcb_ptr = NULL;
  local_cmd.sigs = 0;
  local_cmd.done_q_ptr = NULL;
  local_cmd.data_ptr = &local_item;

  /* Clear all NAMs checksums and the MIN checksums for each NAM. */

  for (nam_idx = 0; nam_idx < NV_MAX_NAMS; nam_idx++) {
    local_item.nam_chksum.nam = nam_idx;
    local_item.nam_chksum.chksum = 0;
    local_cmd.item = NV_NAM_CHKSUM_I;
    local_cmd.status = nvimw_write(&local_cmd);

    MSG_LOW("NAM %d NAM checksum zero status %d", nam_idx, local_cmd.status, 0);
    if (local_cmd.status != NV_DONE_S) {
      return (local_cmd.status);
    }

    local_item.min_chksum.nam = nam_idx;
    for (min_idx = 0; min_idx < NV_MAX_MINS; min_idx++) {
      local_item.min_chksum.chksum[min_idx] = 0;
    }
    local_cmd.item = NV_MIN_CHKSUM_I;
    local_cmd.status = nvimw_write(&local_cmd);

    MSG_LOW("NAM %d MIN checksum zero status %d", nam_idx, local_cmd.status, 0);
    if (local_cmd.status != NV_DONE_S) {
      return (local_cmd.status);
    }
  } /* for */

  /* --------------------------------------------------------------------- */
  /* Next we determine if the ESN is now proper and if not then clear the  */
  /* ESN,the ESN checksum, and the ESN valid flag.                         */
  /* --------------------------------------------------------------------- */
  if( nv_determine_esn_validity() == FALSE)
  {
    /* ------------------------------------------------------------------- */
    /* The ESN has not yet been assigned/written. Zero associated items    */
    /* Note that to get here status == NV_DONE_S                           */
    /* ------------------------------------------------------------------- */

    local_item.esn.esn = 0;
    local_cmd.item = NV_ESN_I;
    local_cmd.status = nvimw_write(&local_cmd);

    MSG_LOW("ESN zero status %d", local_cmd.status, 0, 0);
    if (local_cmd.status != NV_DONE_S) {
      return local_cmd.status;
    }
  }


  return local_cmd.status;

} /* nv_clear_crcs */

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

FUNCTION NV_INIT_RENTAL_TIMER

DESCRIPTION
  This function reads the rental timer item structure out of NVRAM and
  initializes the "nv_rental_item_image" state data item.  It also
  validates the data structure and recovers from a previous bad powerdown.

DEPENDENCIES
  None.

RETURN VALUE
  NV_DONE_S if it worked
  NV_FAIL_S if the EEPROM access has failed

SIDE EFFECTS
  None.

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

LOCAL nv_stat_enum_type  nv_init_rental_timer (void)
{
#ifdef NV_FEATURE_RENTAL_ITEMS
#error code not present
#endif
  return NV_DONE_S;

}

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

FUNCTION NV_INIT_RENTAL_CNT

DESCRIPTION
  This function reads the rental count item from NVRAM and initializes
  the "nv_rental_cnt_image" state data item.  It also validates the data
  structure and recovers from a previous bad powerdown.

DEPENDENCIES
  None.

RETURN VALUE
  NV_DONE_S if it worked
  NV_FAIL_S if the EEPROM access has failed

SIDE EFFECTS
  None.

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

⌨️ 快捷键说明

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