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

📄 nvimw.c

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

DESCRIPTION
  This function writes to an sms_gw EFS file.

DEPENDENCIES
  None.

RETURN VALUE
  NV_DONE_S    if it worked
  NV_BADPARM_S if requested bytes are out of range for NVM

SIDE EFFECTS
  None

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

LOCAL nv_stat_enum_type nvimw_write_sms_gw
(
  nv_cmd_type         *cmd_ptr       /* Command block */
)
{
  uint16              sms_index;     /* SMS message slot to be written */
  char sms_name[20];
  int return_size;
  nv_stat_enum_type status= NV_DONE_S; /* Status returned to calling proc */

  sms_index = cmd_ptr->data_ptr->sms_gw.address;

  /* Insure we are doing an sms_gw operation */
  if ((cmd_ptr->item != NV_SMS_GW_I) ||
      (sms_index >= NVI_MAX_SMS_ADDR) ||
      (cmd_ptr->data_ptr->sms_gw.length > NV_SMS_GW_DATA_SIZ)) {
    status = NV_BADPARM_S;
  } else {

    /* Create the filename */
    snprintf(sms_name, sizeof(sms_name), "/nvm/sms_gw_%05d",
                                         cmd_ptr->data_ptr->sms_gw.address);

    /* Unlink the file before writing to it as the size may be different */
    if (cmd_ptr->cmd == NV_REPLACE_F)
      efs_unlink(sms_name);

    /* Write the item */
    return_size = efs_put(sms_name, (byte*)&(cmd_ptr->data_ptr->sms_gw.address),
                   (sizeof(nvi_sms_gw_type) + cmd_ptr->data_ptr->sms_gw.length),
                   O_CREAT, 0777);

    if(return_size == -1)
    {
      MSG_HIGH("Write failed for SMS item address %d",
                      cmd_ptr->data_ptr->sms_gw.address, 0, 0);
     status = NV_FAIL_S;
    }
  }
  return status;
} /* nvimw_write_sms_gw */
#endif

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

FUNCTION NVIMW_WRITE_DIR_NUMBER

DESCRIPTION
  This function performs the "cross-update" between NV_DIR_NUMBER_I and
  NV_DIR_NUMBER_PCS_I.  That is, a write to either item is translated
  and copied to the other item as well.  THIS IS A TEMPORARY FUNCTION
  ONLY USED TO EASE THE TRANSITION FROM THE OLD STRUCTURE TO THE NEW.

DEPENDENCIES
  None.

RETURN VALUE
  NV_DONE_S    if it worked
  other        if a called function returns a failure status

SIDE EFFECTS
  None

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

LOCAL nv_stat_enum_type nvimw_write_dir_number
(
  nv_cmd_type         *cmd_ptr       /* Command block */
)
{
  nv_stat_enum_type status;     /* Status to return to calling procedure */
  nv_cmd_type       local_cmd;
  nv_cmd_type       *local_cmd_ptr = &local_cmd;
  nv_item_type      local_item;
  byte              i, index;
  byte              pcs_index, gem_index;


  /* First, update the specified nv item */
  index = *((byte *)cmd_ptr->data_ptr);

  if (index >= NV_MAX_NAMS)
  {
    status = NV_BADPARM_S;
  }
  else
  {
    status = nvimw_write_fixed_array(cmd_ptr->item,
                                     index,
                                     ((byte *)cmd_ptr->data_ptr) + sizeof(index),
                                     nv_op_get_size(cmd_ptr->item));
  }

  if (status != NV_DONE_S) return status;

  /* Set up generic 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;
  local_cmd.status      = NV_DONE_S;

  /* Now do the cross update */
  if (cmd_ptr->item == NV_DIR_NUMBER_I) {
    local_cmd.item = NV_DIR_NUMBER_PCS_I;
    local_item.mob_dir_number.nam = cmd_ptr->data_ptr->dir_number.nam;
    for (i=0; i<NV_DIR_NUMB_SIZ; ++i) {
      local_item.mob_dir_number.digitn[i] =
         nvt_translate_to_internal
            (cmd_ptr->data_ptr->dir_number.dir_number[i]);
    }
    local_item.mob_dir_number.n_digits = NV_DIR_NUMB_SIZ;
  }
  else {
    if (cmd_ptr->data_ptr->mob_dir_number.n_digits > 15) {
      return NV_BADPARM_S;
    }
    local_cmd.item = NV_DIR_NUMBER_I;
    local_item.dir_number.nam = cmd_ptr->data_ptr->mob_dir_number.nam;
    for (i=0; i<NV_DIR_NUMB_SIZ; ++i) {
      local_item.dir_number.dir_number[i] = 0x20;  /* ASCII blank */
    }

    /* If n_digits is nonzero, translate and copy the digits; otherwise */
    /* we've already blanked out all the digits                         */
    if (cmd_ptr->data_ptr->mob_dir_number.n_digits != 0) {
      pcs_index = MAX(0,(cmd_ptr->data_ptr->mob_dir_number.n_digits-10));
      gem_index = MAX(0, (10-cmd_ptr->data_ptr->mob_dir_number.n_digits));
      while (gem_index < NV_DIR_NUMB_SIZ) {
        local_item.dir_number.dir_number[gem_index++] =
           nvt_translate_to_external
              (cmd_ptr->data_ptr->mob_dir_number.digitn[pcs_index++]);
      }
    }
  }

   /* Finally, update the "other" nv item */
   index = *((byte *)local_cmd_ptr->data_ptr);
   if (index >= NV_MAX_NAMS)
   {
     status = NV_BADPARM_S;
   }
   else
   {
     status = nvimw_write_fixed_array(local_cmd_ptr->item,
                                      index,
                                      ((byte *)local_cmd_ptr->data_ptr) + sizeof(index),
                                      nv_op_get_size(local_cmd_ptr->item));
 }

  return status;

} /* nvimw_write_dir_number */

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

FUNCTION NVIMW_DO_RENTAL_TIMER_WRITE

DESCRIPTION
  This function writes an arbitrary value to the rental timer item.
  Since this item is expected to be updated with very high frequency,
  it is stored in a way that minimizes EEPROM cell wear.  This unusual
  storage format calls for a special routine to write and read the
  value.

  The NV "increment" command would normally be used to update this item;
  this routine should only be used to initialize the item to some desired
  specific value.


DEPENDENCIES
  None.

RETURN VALUE
  NV_DONE_S    if it worked
  other        if a called function returns a failure status

SIDE EFFECTS
  None

===========================================================================*/
#ifdef NV_FEATURE_RENTAL_ITEMS
#error code not present
#endif

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

FUNCTION NVIMW_INCREMENT

DESCRIPTION
  This function processes NVM item "increment" requests.  Currently, only
  the rental timer item can use this operation.  This special processing
  is needed because the rental timer item is an unusually high wear item,
  expected to be written very frequently.

DEPENDENCIES
  None.

RETURN VALUE
  Status of the increment operation.

SIDE EFFECTS
  None.

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

nv_stat_enum_type nvimw_increment
(
  nv_cmd_type  *cmd_ptr          /* Command block */
)
{

/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Check that the item code is within range. */
  if (cmd_ptr->item != NV_RENTAL_TIMER_I)
    return NV_BADPARM_S;
  else {
#ifndef NV_FEATURE_RENTAL_ITEMS
  return NV_BADPARM_S;
#else
#error code not present
#endif
  }
} /* nvimw_increment */

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

FUNCTION NVIMW_WRITE_RENTAL_CNT

DESCRIPTION
  This function writes a value to the rental count item.  This special
  function is needed because this item is a fixed-pool double-buffered
  item.

DEPENDENCIES
  None.

RETURN VALUE
  NV_DONE_S    if it worked
  other        if a called function returns a failure status

SIDE EFFECTS
  None

===========================================================================*/
#ifdef NV_FEATURE_RENTAL_ITEMS
#error code not present
#endif


#ifdef _SAMSUNG_BCOM_BT //sec_layer1_jhlee_050503_1
#define FEATURE_BT
#endif

#ifdef FEATURE_BT
/*===========================================================================

FUNCTION NVIMW_WRITE_BD_ADDR

DESCRIPTION
  This function processed a write command to the NV_BD_ADDR_I item.

DEPENDENCIES
  None.

RETURN VALUE
  NV_DONE_S if it worked error status code if it failed.

SIDE EFFECTS
  None

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

LOCAL nv_stat_enum_type nvimw_write_bd_addr
(
  nv_cmd_type         *cmd_ptr       /* Command block */
)
{
  int i;
  nv_stat_enum_type status;
  nv_bd_addr_type local_bd_addr;  /* tmp buffer for bd_addr */
  boolean all_zero_write_value;
  boolean bd_addr_empty = TRUE;


 
  nvim_efs_params *efs_params = nv_op_get_fparams(cmd_ptr->item);

  /* Read the current Bluetooth addr. value */
  status = nvimr_read_fixed(cmd_ptr->item,
                            &local_bd_addr, /* data ptr */
                            nv_op_get_size(cmd_ptr->item));

  if ((status != NV_DONE_S) && (status != NV_NOTACTIVE_S))
  {
    return status;
  }

  /* Bluetooth addr can only be written once */
  if (status == NV_DONE_S) {
    for (i=0; i<NV_BD_ADDR_SIZE; i++) {
      if (local_bd_addr.bd_addr[i] != 0) {
        bd_addr_empty = FALSE;
      }
    }

#ifdef _SAMSUNG_BCOM_BT //sec_layer1_jhlee_050503_1
      if (ftm_mode == FTM_MODE || cm_mp_nv == TRUE) 
      bd_addr_empty = TRUE;
#endif // _SAMSUNG_BCOM_BT
   
    if (!bd_addr_empty)
    {
      /* The file is now considered read-only */
      return NV_READONLY_S;
    } else {

      /* The PST may try to write a value of 0 one or more times,
       simply return success if the current BD_ADDR value is 0 */
      all_zero_write_value = TRUE;
      for (i=0; i<NV_BD_ADDR_SIZE; i++) {
        if (cmd_ptr->data_ptr->bd_addr.bd_addr[i] != 0) {
          all_zero_write_value = FALSE;
        }
      }

      if (all_zero_write_value)
      {
        return NV_DONE_S;
      }
    }
  }

  /* Turn off permanent file attribute in order to write */
  if ((status = nvim_update_fs_item_file_attrs(efs_params,
                           FS_FA_UNRESTRICTED)) != NV_DONE_S)
  {
    return status;
  }

  status = nvimw_write_fixed(cmd_ptr->item,
                             cmd_ptr->data_ptr,
                             nv_op_get_size(cmd_ptr->item));

  /* Turn back on permanent file attribute */
  if (status == NV_DONE_S) {
    status = nvim_update_fs_item_file_attrs(efs_params,
                            FS_FA_SYS_PERMANENT);
  }

  return status;
}
#endif

#ifdef FEATURE_RFCAL_VERSION
/*===========================================================================

FUNCTION NVIMW_WRITE_RF_CAL_DATE

DESCRIPTION
  This function processed a write command to the NV_RF_CAL_DATE_I item.

DEPENDENCIES
  None.

RETURN VALUE
  NV_DONE_S if it worked error status code if it failed.

SIDE EFFECTS
  None

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

LOCAL nv_stat_enum_type nvimw_write_rf_cal_date
(
  nv_cmd_type         *cmd_ptr       /* Command block */
)
{
  nv_stat_enum_type status;
  dword local_rf_cal_date;  /* tmp buffer for rf_cal_date */
  nvim_efs_params *efs_params = nv_op_get_fparams(cmd_ptr->item);

  /* Read the current rf_cal_date */
  status = nvimr_read_fixed(cmd_ptr->item,
                            &local_rf_cal_date, /* data ptr */
                            nv_op_get_size(cmd_ptr->item));

  if ((status != NV_DONE_S) && (status != NV_NOTACTIVE_S))
  {
    return status;
  }

⌨️ 快捷键说明

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