📄 nvimw.c
字号:
/*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*
N V I T E M M A N A G E R W R I T E S E R V I C E S
GENERAL DESCRIPTION
This module provides the NV write services using EFS. The module writes the
requested item based on the item attributes.
EXTERNALIZED FUNCTIONS
nvimw_write
This is the function which writes NV items with EFS simulation.
INITIALIZATION AND SEQUENCING REQUIREMENTS
Copyright (c) 1999, 2000 by QUALCOMM Incorporated. All Rights Reserved.
Copyright (c) 2001 by QUALCOMM, Incorporated. All Rights Reserved.
*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*/
/*===========================================================================
EDIT HISTORY FOR MODULE
$PVCSPath: L:/src/asw/MSM5200/drivers/vcs/nvimw.c_v 1.10 28 Nov 2001 12:05:54 pingguan $
$Header: //depot/asic/msmshared/services/meta_nv/nvimw.c#13 $ $DateTime: 2005/11/11 20:18:29 $ $Author: pratapc $
when who what, where, why
-------- --- ----------------------------------------------------------
10/21/06 ck Switched SMS to items files to support more than 255
messages.
02/26/05 pc Added support for SFS_ACCESSOR function based write
operation on IMEI.
02/23/05 pc Added a check to see if MEID is already written. Write is
only permitted if prev value of MEID is either all 0s or FFs.
02/20/05 pc Added support for special treatment for write operations on
DEVICE_SERIAL_NO. Featurised the same under
FEATURE_NV_SUPPORT_FLASH_OTP.
09/22/04 gr Mainlined code under NV_TEMP_AUTO_RESERVATIONS. This
allowed for some simplification of the SMS write functions.
03/30/04 pg Put back in support for NV_DIR_NUMBER_I for now since there
are still other places reference it.
10/15/03 pg Removed nvt_translate_to_internal() and
nvt_translate_to_external().
09/03/03 pg Obsoleted NV_DIR_NUMBER_I.
05/30/03 pg Removed unused variable from nvimw_write_rf_cal_date().
02/11/03 pg Indicates out of memory when null confirmation code returned
in nvimw_write_sms.
01/28/03 pg Made NV_PPP_PASSWORD_I a non-invariant.
01/21/03 pg Fixed write location for roaming list in
nvimw_write_fixed_array().
11/27/01 pg Removed support NV_RF_NV_LOADED_DATE_I from nvimw_write().
Removed function nvimw_write_rf_nv_loaded_date().
NV_RF_NV_LOADED_DATE_I is no longer an invariant item.
11/21/01 pg Corrected FEATURE_NV_EXTENDED_UI to NV_FEATURE_EXTENDED_UI
in nvimw_write_stdial().
10/22/01 pg Moved a variable declaration to the right place to avoid
compiler warnings.
10/10/01 pg Added support for NV_RF_CAL_DATE_I, NV_RF_NV_LOADED_DATE_I,
and NV_RF_CAL_DAT_FILE_I under FEATURE_RFCAL_VERSION.
These items are readonly once they are initialized.
Modified nvimw_write_bd_addr() and nvimw_write_imei() to
be more efficient.
09/27/01 pg Added support for dynamic item NV_SMS_GW_I under
FEATURE_GWSMS.
09/24/01 pg Removed support for NV_IMEI_I and NV_IMEI_CHKSUM_I.
These items are no longer used.
Added support for special item NV_UE_IMEI_I.
04/13/01 pg Added support for special items NV_IMEI_I and
NV_IMEI_CHKSUM_I.
04/04/01 pg Modified nvimw_write_bd_addr() to fix write error.
04/02/01 pg Fixed typo in function nvimw_write_bd_addr().
03/30/01 pg Made changes to make use of the files generated by NVC.
Ported to simba MSM5200.
10/24/00 ts Added NV item access to the RUIM driver when defined.
10/05/00 pg Merged TigerII and PP/PPG archive.
09/21/00 rp Moved includes of target.h and comdef.h before
#ifdef FEATURE_NV_ITEM_MGR which is around all code.
09/20/00 pg Added support for invariant item NV_BD_ADDR_I associated
with FEATURE_BT.
Added #ifdef FEATURE_NV_ITEM_MGR to whole file.
04-09-00 pg Fixed write failure of NV_PAP_PASSWORD_I.
11-11-99 rp Removed SMS directory create as it is now done during
initialization.
10-27-99 rp In nvimw_write_sms needed to remove an amount_rsvd check
as this amount is as large as an FS block size.
10-25-99 rp Updated nvimw_write_sms to check amount_rsvd vs write
length after freeing memory for old message.
10-08-99 pg Added featurelized support for writing NV_UP_KEY_I in
nvimw_write() and simplified nvimw_write_rental_cnt(),
nvimw_write_rental_timer(), nvimw_do_rental_timer_write(),
and nvimw_increment() because wearing out of eeprom bits is
no longer a concern and writing NV_RENTAL_TIMER_I and
NV_RENTAL_CNT_I can (almost) be treated as regular item
writes.
08-13-99 rp Initial ASW version.
07-27-99 rp Cleaned up compiler warnings for fact_data.
07-26-99 rp Updated NV_FACTORY_INFO_I support to write to Flash
and copy to the fact_data cache.
07-07-99 rp Added NV_FEATURE_DIAG_WINS to featurize "diag wins"
07-06-99 rp Added "diag wins" on NV writes feature.
07-06-99 rp Added support for NV_FACTORY_INFO_I including function
nvimw_write_factory() which also supports poke command.
06-23-99 rp Added support for reservation requests to use "revertable"
files, also cleaned up compiler warnings
06-18-99 rp Removed formation of confirmation code as fs_ops now
returns count as part of confirmation code.
06-14-99 rp Added validate reservation length check to write_sms
06-09-99 rp Added support for updating nvi_memavail_data
and cleaned up support for permanent system files.
05-26-99 rp Added support for permanent system files.
05-17-99 rp Now using fs_test in nvimw_write_sms to check for SMS file
existence
05-07-99 rp Will allow mutiple writes to the ESN of 0 when the current
value is 0.
04-30-99 rp Initial version.
===========================================================================*/
/*===========================================================================
INCLUDE FILES FOR MODULE
===========================================================================*/
#include "target.h"
#include "comdef.h"
#ifdef FEATURE_NV_ITEM_MGR
#include "nvimw.h"
#include "fs.h"
#include "nvi.h"
#include "msg.h"
#include "crc.h"
#include "err.h"
#include "memory.h"
#include "dog.h"
#include "nvimr.h"
#include "nv_op.h"
#ifdef FEATURE_NV_RUIM
#include "nvruimi.h"
#endif
#ifdef FEATURE_NV_SUPPORT_FLASH_OTP
#include "flash_otp.h"
#endif
#include "fs_public.h"
#include <stdio.h>
#ifdef _SAMSUNG_BREW_COMMON
#ifdef FEATURE_FACTORY_TESTMODE
#include "ftm.h"
extern ftm_mode_type ftm_mode;
#endif
#ifdef _SAMSUNG_MP_NV_BACKUP
extern boolean cm_mp_nv;
#endif
#endif // _SAMSUNG_BREW_COMMON
/*===========================================================================
DEFINITIONS AND DECLARATIONS FOR MODULE
This section contains definitions for constants, macros, types, variables
and other items needed by this module.
===========================================================================*/
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* */
/* DATA DEFINITIONS */
/* */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
extern nvi_item_type nvi_item;
#ifdef NV_FEATURE_RENTAL_ITEMS
#error code not present
#endif
#ifdef NV_FEATURE_FACTORY_INFO
/* Factory data block cache for peek/poke access */
extern byte fact_data[NVIM_FACTORY_DATA_SIZE];
#endif
extern boolean nv_prl_valid_data[NV_MAX_NAMS];
extern word nv_prl_version_data[NV_MAX_NAMS];
#ifdef _SAMSUNG_MP_CUSTOM_RESET
extern boolean keystr;
#endif
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* */
/* REX Timers and Queues */
/* */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* */
/* Local Data */
/* */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
#ifdef NV_FEATURE_DIAG_WINS
static boolean write_gate_open = TRUE;
#endif
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* */
/* Debug Data */
/* */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* */
/* Macros */
/* */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/*===========================================================================
FUNCTION NVIMW_TRANSLATE_TO_INTERNAL
DESCRIPTION
This function translates a digit frome external representation to
internal 4 bit NVM storage representation.
DEPENDENCIES
None.
RETURN VALUE
The 4 bit digit value.
SIDE EFFECTS
None.
===========================================================================*/
static byte nvimw_translate_to_internal
(
byte digit /* External digit representation */
)
{
if ((digit >= '0') && (digit <= '9')) return(digit - '0');
else if (digit == '*' ) return(0x0A);
else if (digit == '#' ) return(0x0B);
else if (digit == '-' ) return(0x0C);
else if (digit == 'P' ) return(0x0D);
else if (digit == 'T' ) return(0x0E);
else if (digit == 'L' ) return(0x0F);
else {
ERR("Illegal dial digit",0,0,0);
return(0x0C);
}
} /* nvimw_translate_to_internal */
/********************** TEMPORARY ******************************************/
/************* Remove this function after cross-update is removed **********/
/*===========================================================================
FUNCTION NVT_TRANSLATE_TO_EXTERNAL
DESCRIPTION
This function translates a digit frome internal 4 bit NVM storage
to external 8 bit ASCII representation.
DEPENDENCIES
None.
RETURN VALUE
The 8 bit ASCII digit value.
SIDE EFFECTS
None.
===========================================================================*/
static byte nvt_translate_to_external
(
byte digit /* Internal digit representation */
)
{
if ((digit > 0) && (digit <= 0x09)) return(digit + '0');
else if (digit == 0x0A) return('0');
else if (digit == 0x0B) return('*');
else if (digit == 0x0C) return('#');
else return(' ');
} /* nvt_translate_to_external */
/********************** TEMPORARY ******************************************/
/*===========================================================================
FUNCTION NVT_TRANSLATE_TO_INTERNAL
DESCRIPTION
This function translates a digit frome external representation to
internal 4 bit NVM storage representation.
DEPENDENCIES
None.
RETURN VALUE
The 4 bit digit value.
SIDE EFFECTS
None.
===========================================================================*/
static byte nvt_translate_to_internal
(
byte digit /* External digit representation */
)
{
if ((digit > '0') && (digit <= '9')) return(digit - '0');
else if (digit == '0') return(0x0A);
else if (digit == '*') return(0x0B);
else if (digit == '#') return(0x0C);
else return(0x0F);
} /* nvt_translate_to_internal */
/*===========================================================================
FUNCTION NVIMW_WRITE_ESN
DESCRIPTION
This function processed a write command to the NV_ESN_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_esn
(
nv_cmd_type *cmd_ptr /* Command block */
)
{
nv_stat_enum_type status; /* Function return value */
fs_rsp_msg_type rsp_msg; /* Response message from EFS operation */
dword local_esn; /* tmp buffer for esn */
nvim_efs_params *efs_params = nv_op_get_fparams(cmd_ptr->item);
/* Read the current ESN value */
status = nvim_read_efs(efs_params->rd_handle,/* file handle */
nv_op_get_file_pos(cmd_ptr->item), /* file position */
&local_esn, /* data ptr */
sizeof(local_esn)); /* data count */
if (status != NV_DONE_S)
{
return status;
}
/* The ESN may only be written once */
if ((local_esn != 0) &&
(local_esn != (dword)0xFFFFFFFFUL))
{
/* The file is now considered read-only */
return NV_READONLY_S;
}
/* The PST may try to write a value of 0 one or more times,
simply return success if the current ESN value is 0 */
if (cmd_ptr->data_ptr->esn.esn == 0)
{
/* No reason to write, simply return success */
if (local_esn == 0)
{
return status;
}
}
/* 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;
}
/* Open for write access */
/* The ESN may only be written once, all subsequent writes will fail */
if ((status = nvim_open_write(efs_params)) != NV_DONE_S)
{
return status;
}
/* Write the ESN, the ESN checksum, and the ESN valid flag. */
status = nvim_write_efs(efs_params->wr_handle, /* file handle */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -