📄 nvimr.c
字号:
fs_rsp_msg_type msg_rsp; /* Response message from EFS operation */
nvim_efs_params *efs_params = nv_op_get_fparams(item);
fs_file_position_type fpos = nv_op_get_file_pos(item);
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Read active flag first. The active flag is the 1st byte of an item */
/* If the item is active then read and */
/* set ok status, else do not read and set not active status. */
fs_seek( efs_params->rd_handle, /* file handle */
FS_SEEK_SET, /* origin */
fpos, /* position */
NULL, /* callback_function */
&msg_rsp); /* message ptr */
if(msg_rsp.seek.status != FS_OKAY_S)
{
if(msg_rsp.seek.status == FS_BAD_SEEK_POS_S)
{
/* Unable to seek to item not written */
return NV_NOTACTIVE_S;
}
else
{
//ERR("Seek error during read in %s at %d",
// efs_params->fname, fpos, 0);
ERR("Seek error during read item %d", item, 0, 0);
return NV_FAIL_S;
}
}
fs_read( efs_params->rd_handle, /* file handle */
&active, /* where to store bytes */
sizeof(active), /* # bytes to read */
NULL, /* callback_function */
&msg_rsp); /* message ptr */
if( (msg_rsp.read.status != FS_OKAY_S) ||
(msg_rsp.read.count != sizeof(active)) )
{
//ERR("Failed to read active flag in %s at %d",
// efs_params->fname, fpos, 0);
ERR("Failed to read active flag for item %d", item, 0, 0);
status = NV_FAIL_S;
}
else
{
/* Everything went fine in the read set the NV status to DONE */
status = NV_DONE_S;
}
if(status != NV_DONE_S) return status;
/* We test the active flag explicitly for 'TRUE' since it was initially
* set to true (or false), and any other value, except false, would
* indicate aprevious write error, which should be treated as a 'false'
* active flag.
*/
if (active == TRUE) {
/* read item, skipping the active flag */
fs_read(efs_params->rd_handle, /* file handle */
data_ptr, /* where to store bytes */
size-sizeof(active), /* # bytes to read */
NULL, /* callback_function */
&msg_rsp); /* message ptr */
if( (msg_rsp.read.status != FS_OKAY_S) ||
(msg_rsp.read.count != (size-sizeof(active))) )
{
//ERR("Failed to read all data in %s at %d",
// efs_params->fname, fpos, 0);
ERR("Failed to read all data for item %d", item, 0, 0);
return NV_FAIL_S;
}
return NV_DONE_S;
}
else
{
return NV_NOTACTIVE_S;
}
} /* nvimr_read_fixed */
/*===========================================================================
FUNCTION NVIMR_READ_FIXED_ARRAY
DESCRIPTION
This function reads an fixed array type item into the local buffer. If the
item is not active, then it is not read and a status code is returned.
DEPENDENCIES
None.
RETURN VALUE
NV_DONE_S if it worked
NV_NOTACTIVE_S if the item is not active.
SIDE EFFECTS
None
===========================================================================*/
nv_stat_enum_type nvimr_read_fixed_array
(
nv_items_enum_type item, /* NV index of the item */
word index, /* index within array of type */
PACKED void *data_ptr, /* Pointer to where to put read bytes */
word size /* Size of item */
)
{
boolean active; /* Indicator of whether the item is active */
fs_rsp_msg_type msg_rsp; /* Response message from EFS operation */
nvim_efs_params *efs_params;
fs_file_position_type fpos;
/* Roaming list requires special processing */
#ifdef NV_FEATURE_IS683A_PRL
if (item == NV_ROAMING_LIST_683_I)
#else
if (item == NV_ROAMING_LIST_I)
#endif
{
/* Setup file info */
efs_params = nvim_prl_fs_params(index);
fpos = 0;
}
else { /* Not the roaming list special case */
efs_params = nv_op_get_fparams(item);
fpos = nv_op_get_file_pos(item) + (index*size);
}
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Read active flag first. The active flag is the 1st byte of an item */
/* If the item is active then read and */
/* set ok status, else do not read and set not active status. */
fs_seek( efs_params->rd_handle, /* file handle */
FS_SEEK_SET, /* origin */
fpos, /* position */
NULL, /* callback_function */
&msg_rsp); /* message ptr */
if(msg_rsp.seek.status != FS_OKAY_S)
{
if(msg_rsp.seek.status == FS_BAD_SEEK_POS_S)
{
/* Unable to seek to item not written */
return NV_NOTACTIVE_S;
}
else
{
//ERR("Seek error during read in %s at %d",
// efs_params->fname, fpos, 0);
ERR("Seek error during read item %d", item, 0, 0);
return NV_FAIL_S;
}
}
fs_read( efs_params->rd_handle, /* file handle */
&active, /* where to store bytes */
sizeof(active), /* # bytes to read */
NULL, /* callback_function */
&msg_rsp); /* message ptr */
if( (msg_rsp.read.status != FS_OKAY_S) ||
(msg_rsp.read.count != sizeof(active)) )
{
//ERR("Failed to read active flag in %s at %d",
// efs_params->fname, fpos, 0);
ERR("Failed to read active flag for item %d", item, 0, 0);
return NV_FAIL_S;
}
/* We test the active flag explicitly for 'TRUE' since it was initially
* set to true (or false), and any other value, except false, would
* indicate aprevious write error, which should be treated as a 'false'
* active flag.
*/
if (active == TRUE) {
fs_read( efs_params->rd_handle, /* file handle */
data_ptr, /* where to store bytes */
size-sizeof(active), /* # bytes to read */
NULL, /* callback_function */
&msg_rsp); /* message ptr */
if( (msg_rsp.read.status != FS_OKAY_S) ||
(msg_rsp.read.count != (size-sizeof(active))) )
{
//ERR("Failed to read all data in %s at %d",
// efs_params->fname, fpos, 0);
ERR("Failed to read all data for item %d",item, 0, 0);
return NV_FAIL_S;
}
}
else
{
return NV_NOTACTIVE_S;
}
return NV_DONE_S;
} /* nvimr_read_fixed_array */
/*===========================================================================
FUNCTION NVIMR_READ
DESCRIPTION
This procedure processes NVM read requests. It checks to make sure
that a valid item has been requested, it reads the NVM item using EFS
services and it performs the translation from internal NVM format to
external format. If the item being read requires no special processing,
it is passed on to nvimio_io().
DEPENDENCIES
None.
RETURN VALUE
Status of read operation.
SIDE EFFECTS
None.
===========================================================================*/
#ifdef _SAMSUNG_BCOM_BT //sec_layer1_jhlee_050503_1
#define FEATURE_BT
#endif
nv_stat_enum_type nvimr_read
(
nv_cmd_type *cmd_ptr /* Pointer to Command block */
)
{
nv_stat_enum_type status; /* Status to return to calling procedure */
/* This is ugly but saves 128 bytes of static RAM, by not keeping 2
* static copies of the nv enum. */
dword local_esn_chksum; /* buffer for esn chksum */
word array_size; /* Array size of the item */
byte index; /* Index into array items */
#ifdef FEATURE_NV_SUPPORT_FLASH_OTP
FlashOTP_ReturnType otp_ret_val;
FlashOTP_ProtectOp_ReturnType otp_prot_ret_val;
byte local_imei[NV_UE_IMEI_SIZE];
nvim_efs_params *efs_params;
int i;
#endif
#ifdef FEATURE_NV_SFS_PRIVATE
int num_imei_bytes;
#endif
nvim_efs_params *fparams;
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* If item code is out of range return with bad parameter status. */
if (cmd_ptr->item >= NV_MAX_I)
{
return NV_BADPARM_S;
}
else {
#ifdef FEATURE_NV_RUIM
/* If the R-UIM supports the item,
* return the status else use "regular" NVM.
*/
if ( nvruim_read(cmd_ptr, &status) == NV_RUIM_SUPPORTS_ITEM )
return status;
#endif
switch (cmd_ptr->item) {
/* read up data item, do special processing if required */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* This item is a special case for writes, so it has no generic path in
* nvimio_io(). Thus we have to handle the read of this item specially.
*/
case NV_ESN_I:
fparams = nv_op_get_fparams(cmd_ptr->item);
return nvim_read_efs(fparams->rd_handle, /* file handle */
nv_op_get_file_pos(cmd_ptr->item), /* file position */
&cmd_ptr->data_ptr->esn, /* data ptr */
sizeof(nvi_item.esn)); /* data count */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* ESN checksum read returns the status of */
/* the checksum, NOT the checksum itself. */
case NV_ESN_CHKSUM_I:
/* First read the ESN itself into a local buffer. */
fparams = nv_op_get_fparams(NV_ESN_I);
status = nvim_read_efs(fparams->rd_handle,/* file handle */
nv_op_get_file_pos(NV_ESN_I), /* file position */
&nvi_item.esn, /* data ptr */
sizeof(nvi_item.esn)); /* data count */
if(status != NV_DONE_S) return status;
/* Next read the ESN checksum into a local buffer. */
fparams = nv_op_get_fparams(NV_ESN_CHKSUM_I);
status = nvim_read_efs(fparams->rd_handle, /* file handle */
nv_op_get_file_pos(NV_ESN_CHKSUM_I), /* file position */
&local_esn_chksum, /* data ptr */
sizeof(local_esn_chksum)); /* data count */
if(status != NV_DONE_S) return status;
/* Next compute the ESN checksum and compare against */
/* the stored checksum. Return its status to caller. */
if (crc_30_calc((byte *)&nvi_item.esn,
sizeof(nvi_item.esn) * 8) == local_esn_chksum) {
cmd_ptr->data_ptr->esn_chksum.chksum = NV_VALID_ESN_CHKSUM;
} else {
cmd_ptr->data_ptr->esn_chksum.chksum = ~NV_VALID_ESN_CHKSUM;
}
return NV_DONE_S;
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
#ifdef FEATURE_NV_SUPPORT_FLASH_OTP
case NV_UE_IMEI_I:
/* Check whether OTP area is programmed */
otp_prot_ret_val = flash_otp_status();
/* If the protection is not active, then return NV data */
if ((otp_prot_ret_val == FLASH_OTP_PROTECTION_INACTIVE) ||
(otp_prot_ret_val == FLASH_OTP_NOT_SUPPORTED))
{
/* Read from NV */
status = nvimr_read_fixed(cmd_ptr->item,
(byte *)cmd_ptr->data_ptr,
nv_op_get_size(cmd_ptr->item));
return status;
}
else
{
/* Read from OTP Area */
otp_ret_val = flash_otp_operation(FLASH_OTP_OP_IMEI_READ,
(uint8 *)local_imei);
if (otp_ret_val != FLASH_OTP_IO_SUCCESS)
{
MSG_HIGH ("OTP Read failure",0,0,0);
return (NV_FAIL_S);
}
/* Read from NV */
status = nvimr_read_fixed(cmd_ptr->item,
(byte *)cmd_ptr->data_ptr,
nv_op_get_size(cmd_ptr->item));
if ( (status != NV_DONE_S) && (status != NV_NOTACTIVE_S) )
{
MSG_HIGH ("NV Read failure for IMEI",0,0,0);
return status;
}
/* If the IMEI got wiped out, then set it from OTP area */
if ( status == NV_NOTACTIVE_S )
{
for (i=0; i<NV_UE_IMEI_SIZE; i++)
cmd_ptr->data_ptr->ue_imei.ue_imei[i] = local_imei[i];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -