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

📄 nvimnv.c

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

LOCAL nv_stat_enum_type  nv_init_rental_cnt (void)
{
#ifdef NV_FEATURE_RENTAL_ITEMS
#error code not present
#else

  return NV_DONE_S;

#endif
}

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

FUNCTION NV_INIT_PRL_DATA

DESCRIPTION
  This function initializes the "prl_valid_data" and "prl_version_data"
  state data items.  These are maintained as NV state data so the functions
  "nv_prl_is_valid()" and "nv_prl_version()" can return an immediate
  response.

DEPENDENCIES
  None.

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

SIDE EFFECTS
  None.

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

LOCAL void  nv_init_prl_data (void)
{
  byte                         nam;
  nv_roaming_list_header_type  prl_header;
  nv_stat_enum_type            status;

  for (nam=0; nam<NV_MAX_NAMS; nam++)
  {
    /* For each nam, read the prl header */
    status = nvim_read_efs(nvim_prl_fs_params(nam)->rd_handle,/* file handle */
                           0,                         /* file position */
                           &prl_header,               /* data ptr */
                           NV_ROAMING_LIST_HEADER_SIZE);/* data count */
    /* Set state data items -- note that the item's active flag */
    /* occupies the "nam" field in the external type.           */
    if ((status == NV_DONE_S) && ((boolean)prl_header.nam == TRUE)) {
      nv_prl_version_data[nam] = prl_header.prl_version;
      nv_prl_valid_data[nam] = prl_header.valid;
    }
    else {
      nv_prl_version_data[nam] = NV_PRL_VERSION_INVALID;
      nv_prl_valid_data[nam] = FALSE;
    }
  }

  return;
}


#ifdef FEATURE_NV_HANDOVER_BLOCK
/*======================================================================
FUNCTION NVI_HANDOVER_CHECK

DESCRIPTION
  This function checks for the presence of a 1.0 compatible handover block.
  If it is found, the items are inserted into the current nv.

DEPENDENCIES
  EFS must be initialized.  The item manager must also have completed
  nv_init.  This routine expects to be called at the end of NV_INIT.
======================================================================*/
void
nvi_handover_check()
{
  fs_rsp_msg_type response;
  fs_handle_type handle;
  nvi_handover_header_type header;
  word crc16;
  static byte buffer[32];
  word count;
  word size_left;
  nvi_handover_item_header_type item_head;
  nv_item_type      item;
  nv_cmd_type       cmd;

  /* Determine if the transition file is present. */
  fs_open ("$SYS.HAND.000",
           FS_OA_READONLY,
           NULL, NULL,
           &response);
  if (response.open.status != FS_OKAY_S) {
    MSG_LOW ("No handover block file detected.", 0, 0, 0);
    return;
  }

  handle = response.open.handle;

  /* Read in the header. */
  fs_read (handle, (void *) &header, sizeof (header), NULL, &response);
  if (response.read.status != FS_OKAY_S
      || response.read.count != sizeof (header)) {
    MSG_MED ("Unable to read handover block header", 0, 0, 0);
    return;
  }

  if (header.verno_maj != NVI_HANDOVER_VERNO_MAJ ||
      header.verno_min != NVI_HANDOVER_VERNO_MIN ||
      header.nv_format_ver != NVI_FORMAT_VER) {
    MSG_MED ("Handover head has incorrect version", 0, 0, 0);
    return;
  }

  /* Do not check the offset. */

  /* Go through and compute the CRC. */
  crc16 = (word) CRC_16_STEP_SEED;
  size_left = header.size;
  while (size_left > 0) {
    count = size_left;
    if (count > sizeof (buffer))
      count = sizeof (buffer);

    fs_read (handle, buffer, count, NULL, &response);
    if (response.read.status != FS_OKAY_S
   || response.read.count != count) {
      MSG_MED ("Unable to read handover block data", 0, 0, 0);
      return;
    }

    crc16 = crc_16_step (crc16, buffer, count);

    size_left -= count;
  }

  /* Then compute the CRC of the header. */
  crc16  = crc_16_step (crc16, (byte *) &header, sizeof (header));

  if (crc16 != CRC_16_OK) {
    MSG_MED ("Invalid CRC for handover block data", 0, 0, 0);
    return;
  }

  MSG_MED ("Handover block detected", 0, 0, 0);

  /* Rewind the file back. */
  fs_seek (handle, FS_SEEK_SET, sizeof (header), NULL, &response);
  if (response.seek.status != FS_OKAY_S) {
    MSG_MED ("Unable to rewind file", 0, 0, 0);
    return;
  }

  size_left = header.size;
  while (size_left > 0) {
    /* Read in an item. */
    fs_read (handle, (void *) &item_head, sizeof (item_head),
        NULL, &response);
    if (response.read.status != FS_OKAY_S
   || response.read.count != sizeof (item_head)) {
      MSG_MED ("Unable to read handover item header", 0, 0, 0);
      // goto cleanup;
      return;
    }

    size_left -= sizeof (item_head);

    MSG_HIGH ("Handover item: %d, size %d",
         item_head.nv_item_number,
         item_head.item_size,
         0);

    /* Read in the raw data. */
    fs_read (handle, (void *) &item, item_head.item_size, NULL, &response);
    if (response.read.status != FS_OKAY_S
   || response.read.count != item_head.item_size) {
      MSG_MED ("Unable to read handover item", 0, 0, 0);
      // goto cleanup;
      return;
    }

    /* Write the item to NV. */
    cmd.item     = (nv_items_enum_type) item_head.nv_item_number;
    cmd.data_ptr = &item;
    if (nvimw_write (&cmd) != NV_DONE_S)
      {
   MSG_HIGH ("Unable to write handover item: %d, size %d",
        item_head.nv_item_number,
        item_head.item_size, 0);
      }

    size_left -= item_head.item_size;
  }

  fs_close (handle, NULL, &response);

  /* If we made it to this point, then the handover block has been
     updated, so remove the file. */
  fs_remove ("$SYS.HAND.000", NULL, &response);
  if (response.rmfile.status != FS_OKAY_S) {
    MSG_MED ("Unable to remove handover block file", 0, 0, 0);
  }
}
#endif /* FEATURE_NV_HANDOVER_BLOCK */


#ifdef FEATURE_NV_CNV
/*======================================================================
FUNCTION NVI_CNV_CHECK

DESCRIPTION
  This function checks for the presence of a CNV file in EFS.
  If it is found, the items are inserted into the current nv.

DEPENDENCIES
  EFS must be initialized.  The item manager must also have completed
  nv_init.  This routine expects to be called at the end of NV_INIT.

RETURN VALUE
  None

SIDE EFFECTS
  NV items could be updated if a valid CNV fileis present.

======================================================================*/
void nvi_cnv_check(void)
{
  int       file_handle = NULL;
  struct    fs_stat sbuf;
  fs_off_t  offset;
  fs_size_t size;
  word      crc16;
  static    byte buffer[32];
  uint32    count;
  uint32    size_left;
  uint8     pad_size;


  cnv_item_hdr_type item_head;
  static nv_item_type      item;
  nv_cmd_type       cmd;

  /* Open the file */
  file_handle = efs_open(cnv_file, O_RDWR);
  if (file_handle < 0)
  {
    MSG_HIGH ("Cannot open CNV file", 0, 0, 0);
    return;
  }

  /* Stat to get the file size */
  if (efs_fstat(file_handle, &sbuf) < 0)
  {
    MSG_HIGH ("Error on fstat of CNV file",0,0,0);
    return;
  }

  /* Cycle thru the contents to check CRC */
  crc16 = (word) CRC_16_STEP_SEED;

  size_left = sbuf.st_size;
  while (size_left > 0) {
    count = size_left;
    if (count > sizeof (buffer))
      count = sizeof (buffer);

    size = efs_read(file_handle, buffer, count);
    if (size != count)
    {
      MSG_MED ("Unable to read CNV data", 0, 0, 0);
      return;
    }

    crc16 = crc_16_step (crc16, buffer, count);
    size_left -= count;
  }

  if (crc16 != CRC_16_OK) {
    MSG_HIGH ("Invalid CRC for CNV data", 0, 0, 0);
    return;
  }

  MSG_MED ("Valid CNV file detected", 0, 0, 0);

  /* Rewind the file back to the first item and ignore the header
     for now */
  offset = efs_lseek (file_handle, sizeof(cnv_header_type), SEEK_SET);

  if (offset < 0)
  {
    MSG_HIGH ("Cannot seek to the beginning of the file",0,0,0);
    return;
  }

  size_left = sbuf.st_size - (sizeof(cnv_header_type) + sizeof(crc16)
                                          + sizeof(cnv_item_hdr_type));

  while (size_left > 0)
  {
    /* Read in an item. */
    size = efs_read (file_handle, (void *) &item_head, sizeof (item_head));
    if (size != sizeof (item_head))
    {
      MSG_MED ("Unable to read handover item header", 0, 0, 0);
      return;
    }

    size_left -= sizeof (item_head);

    MSG_MED ("CNV item: %d, size %d", item_head.nv_item_number,
               item_head.nv_item_size, 0);

    /* Read in the raw data. */
    size = efs_read (file_handle, (void *) &item, item_head.nv_item_size);
    if (size != item_head.nv_item_size)
    {
      MSG_MED ("Unable to read CNV item", 0, 0, 0);
      return;
    }

    /* Write the item to NV. */
    cmd.item     = (nv_items_enum_type) item_head.nv_item_number;
    cmd.cmd      = NV_WRITE_F;
    cmd.data_ptr = &item;

    if (nvimw_write (&cmd) != NV_DONE_S)
    {
      MSG_HIGH ("Unable to write handover item: %d, size %d",
                 item_head.nv_item_number, item_head.nv_item_size, 0);
    }

    pad_size = 0;
    if ((item_head.nv_item_size % 4) != 0)
    {
      pad_size = 4 - (item_head.nv_item_size % 4);

      offset = efs_lseek(file_handle, pad_size, SEEK_CUR);
      if (offset < 0)
      {
        MSG_HIGH ("Cannot seek forward to the next item",0,0,0);
        return;
      }
    }
    size_left -= (item_head.nv_item_size + pad_size);
  }

  /* Close the file */
  efs_close (file_handle);

  /* Remove the file since we are done updating the NV items */
  if (efs_unlink (cnv_file) < 0)
  {
    MSG_HIGH ("Unable to remove CNV file", 0, 0, 0);
  }
} /* nvi_cnv_check */
#endif

#ifdef _SAMSUNG_HW_RF
/*===========================================================================

FUNCTION NV_WRITE_ITEM

DESCRIPTION
  This function is used for write the value of a NV item

DEPENDENCIES
  None

RETURN VALUE
  Status 

SIDE EFFECTS
  None
===========================================================================*/
nv_stat_enum_type nv_write_item
(
  nv_items_enum_type   item,
  nv_item_type *         nv_data
)
{
  nv_stat_enum_type  status;        /* Status to return to calling procedure */

  local_cmd.item        = item;     /* EFS item */
  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    = nv_data;  /* NV item data*/

  status = nvimw_write(&local_cmd);

  return status;
}

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

FUNCTION NV_REBUILD_DEFAULTS

DESCRIPTION
  This function assigns default values for each NV item.
  Example)
   NV_RRC_INTEGRITY_ENABLED_I 
   nvi.rrc_integrity_enabled = FALSE;
   nv_write_item(NV_RRC_INTEGRITY_ENABLED_I, &nvi);

DEPENDENCIES
  None.

⌨️ 快捷键说明

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