📄 nvimw.c
字号:
nv_op_get_file_pos(cmd_ptr->item), /* file position */
&cmd_ptr->data_ptr->esn, /* data ptr */
sizeof(nvi_item.esn)); /* data count */
if (status == NV_DONE_S)
{
nvi_item.esn_chksum = crc_30_calc((byte *)&cmd_ptr->data_ptr->esn,
sizeof(nvi_item.esn) * 8);
fs_write(efs_params->wr_handle, /* file handle */
&nvi_item.esn_chksum, /* source to store bytes */
sizeof(nvi_item.esn_chksum), /* # bytes to write */
NULL, /* callback_function */
&rsp_msg); /* message ptr */
if( (rsp_msg.write.status != FS_OKAY_S) ||
(rsp_msg.write.count != sizeof(nvi_item.esn_chksum)) )
{
status = NV_FAIL_S;
}
if (status == NV_DONE_S)
{
nvi_item.esn_valid = crc_30_calc((byte *)&nvi_item.esn_chksum,
sizeof(nvi_item.esn_valid) * 8);
fs_write(efs_params->wr_handle, /* file handle */
&nvi_item.esn_valid, /* source to store bytes */
sizeof(nvi_item.esn_valid), /* # bytes to write */
NULL, /* callback_function */
&rsp_msg); /* message ptr */
if( (rsp_msg.write.status != FS_OKAY_S) ||
(rsp_msg.write.count != sizeof(nvi_item.esn_valid)) )
{
status = NV_FAIL_S;
}
}
}
/* Close for write access */
(void) nvim_close_write(efs_params);
/* Turn back on permanent file attribute */
if ((status = nvim_update_fs_item_file_attrs(efs_params,
FS_FA_SYS_PERMANENT)) != NV_DONE_S)
{
return status;
}
return status;
}
/*===========================================================================
FUNCTION NVIMW_WRITE_ROAMING_LIST
DESCRIPTION
This function writes the roaming list. Handled as a special case in the
item manager.
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_roaming_list
(
nv_cmd_type *cmd_ptr
)
{
word item_size; /* Size of item (in bytes) */
nv_stat_enum_type status; /* Function return value */
/* Check for illegal NAM */
if(cmd_ptr->data_ptr->roaming_list.nam >= NV_MAX_NAMS)
{
return NV_BADPARM_S;
}
/* Get its size */
item_size = NV_ROAMING_LIST_HEADER_SIZE +
nv_max_size_of_roaming_list();
MSG_MED("size: %d", item_size, 0, 0);
status = nvimw_write_fixed_array(cmd_ptr->item,
cmd_ptr->data_ptr->roaming_list.nam,
(void *) &(cmd_ptr->data_ptr->roaming_list.prl_version),
item_size);
nv_prl_version_data[cmd_ptr->data_ptr->roaming_list.nam] =
cmd_ptr->data_ptr->roaming_list.prl_version;
nv_prl_valid_data[cmd_ptr->data_ptr->roaming_list.nam] =
cmd_ptr->data_ptr->roaming_list.valid;
return status;
} /* nvimw_write_roaming_list */
/*===========================================================================
FUNCTION NVIMW_WRITE_FACTORY
DESCRIPTION
This function writes data to the factory data block ($SYS.FACTORY file).
It temporarily turns off the permanent file attribute on the $SYS.FACTORY
file in order to write the data.
DEPENDENCIES
None.
RETURN VALUE
NV_DONE_S if it worked
Or the failure status from the lower levels.
SIDE EFFECTS
None
===========================================================================*/
nv_stat_enum_type nvimw_write_factory
(
PACKED void *data_ptr, /* Pointer to write data */
word size /* Size of data to write */
)
{
nv_stat_enum_type status; /* Status to return */
fs_rsp_msg_type rsp_msg; /* EFS response status */
fs_handle_type fhandle; /* Handle of file to write to */
/* Update attributes before opening */
/* Turn off permanent file attribute in order to write */
if ((status = nvim_update_file_attrs(nvim_factory_file(),
FS_FA_UNRESTRICTED)) != NV_DONE_S)
{
return status;
}
/* Open the factory data file */
fs_open(nvim_factory_file(), /* Name of file to open */
FS_OA_READWRITE, /* Open mode */
NULL, /* No optional parameters */
NULL, /* Callback function ptr */
&rsp_msg); /* Response message ptr */
fhandle = rsp_msg.open.handle; /* save file handle */
if (fhandle == FS_NULL_HANDLE)
{
ERR("Unable to open factory data file %s",
nvim_factory_file(), 0, 0);
return NV_FAIL_S;
}
status = nvim_write_efs(fhandle, /* file handle */
FACTORY_FILE_RESERVED, /* file position */
data_ptr, /* data ptr */
size); /* data count */
/* Close this file */
fs_close(fhandle, /* Handle of file to close */
NULL, /* Callback function ptr */
&rsp_msg); /* Response message ptr */
if (status != NV_DONE_S)
{
ERR("Failed to write to factory file", 0, 0, 0);
return status;
}
/* Now, update the attributes */
/* Turn back on permanent file attribute */
status = nvim_update_file_attrs(nvim_factory_file(), FS_FA_SYS_PERMANENT);
return status;
}
/*===========================================================================
FUNCTION NVIMW_WRITE_DIAL
DESCRIPTION
This function processes write requests for speed dial number. It performs
translations necessary from external to internal format and then attempts
to write the NVM item using EFS services.
DEPENDENCIES
None.
RETURN VALUE
Status of write operation.
SIDE EFFECTS
None.
===========================================================================*/
LOCAL nv_stat_enum_type nvimw_write_dial
(
nv_items_enum_type item, /* Item to access */
byte index_range, /* Maximum allowed range for index */
byte index, /* speed dial # */
nv_dial_type *dial_ptr /* Pointer to write source buffer */
)
{
word i; /* Index through speed dial numbers */
byte ndigits; /* # of digits to process */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Check for illegal offset into the array */
if (index >= index_range) return NV_BADPARM_S;
/* First copy the digits count from external buffer to internal */
/* buffer, making sure that only the maximum number allowed can */
/* be stored. When copying translate digits to internal type. */
nvi_item.dial.num_digits = MIN(dial_ptr->num_digits, NV_MAX_DIAL_DIGITS);
ndigits = nvi_item.dial.num_digits;
for (i = 0; i < ndigits; i++) {
/* Copy the digits, compressing from one digit per byte into two */
/* digits per byte. Even bytes are stored in least significant */
/* digit, odd bytes in most significant digit. */
if ((i%2) == 0) {
nvi_item.dial.digits[i/2] =
nvimw_translate_to_internal(dial_ptr->digits[i]);
} else {
nvi_item.dial.digits[i/2] |=
(byte)(nvimw_translate_to_internal(dial_ptr->digits[i]) << 4);
}
} /* for */
/* Copy the name to internal type. */
(void)memcpy((void *) nvi_item.dial.letters, (void *) dial_ptr->letters,
NV_MAX_LTRS);
#ifdef NV_FEATURE_EXTENDED_UI
nvi_item.dial.status = dial_ptr->status;
#endif
/* Write out item. */
/* Note that this data structure has a target specific member,
* which dictates the member name we start the write into, in order
* to skip the 'active' byte.
*/
return nvimw_write_fixed_array(
item,
index,
#ifdef NV_FEATURE_EXTENDED_UI
&nvi_item.dial.status, /* skip "active" item */
#else
&nvi_item.dial.num_digits, /* skip "active" item */
#endif
sizeof(nvi_item.dial));
} /* nvimw_write_dial */
/*===========================================================================
FUNCTION NVIMW_WRITE_STDIAL
DESCRIPTION
This function processes write requests for stack dial number. It performs
translations necessary from external to internal format and then attempts
to write the NVM item using EFS services.
DEPENDENCIES
None.
RETURN VALUE
Status of write operation.
SIDE EFFECTS
None.
===========================================================================*/
LOCAL nv_stat_enum_type nvimw_write_stdial
(
nv_items_enum_type item, /* Item to access */
byte index_range, /* Maximum allowed range for index */
byte index, /* speed dial # */
nv_stdial_type *dial_ptr /* Pointer to external write source buffer */
)
{
word i; /* Index through stack dial numbers */
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Check if the index is within the range */
if (index >= index_range) return NV_BADPARM_S;
/* First copy the digits count from external buffer to internal */
/* buffer, making sure that only the maximum number allowed can */
/* be stored. When copying translate digits to internal type. */
nvi_item.stack.num_digits = MIN(dial_ptr->num_digits, NV_MAX_DIAL_DIGITS);
for (i = 0; i < nvi_item.stack.num_digits; i++) {
/* Copy the digits, compressing from one digit per byte into two */
/* digits per byte. Even bytes are stored in least significant */
/* digit, odd bytes in most significant digit. */
if ((i%2) == 0) {
nvi_item.stack.digits[i/2] = nvimw_translate_to_internal(dial_ptr->digits[i]);
} else {
nvi_item.stack.digits[i/2] |= (byte)(nvimw_translate_to_internal(dial_ptr->digits[i]) << 4);
}
} /* for */
/* Copy the name to internal type. */
(void)memcpy((void *) nvi_item.stack.letters, (void *) dial_ptr->letters,
NV_MAX_LTRS);
#ifdef NV_FEATURE_EXTENDED_UI
nvi_item.stack.status = dial_ptr->status;
nvi_item.stack.time_stamp = dial_ptr->time_stamp;
nvi_item.stack.duration = dial_ptr->duration;
#endif
/* Write out item. */
/* Note that this data structure has a target specific member,
* which dictates the member name we start the write into, in order
* to skip the 'active' byte.
*/
return nvimw_write_fixed_array(
item,
index,
#ifdef NV_FEATURE_EXTENDED_UI
&nvi_item.stack.status, /* skip "active" item */
#else
&nvi_item.stack.num_digits, /* skip "active" item */
#endif
sizeof(nvi_item.stack));
} /* nvimw_write_stdial */
/*===========================================================================
FUNCTION NVIMW_WRITE_SMS
DESCRIPTION
This function writes to an sms 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
(
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.address;
/* Insure we are doing an sms_gw operation */
if ((cmd_ptr->item != NV_SMS_I) ||
(sms_index >= NVI_MAX_SMS_ADDR) ||
(cmd_ptr->data_ptr->sms.length > NV_SMS_DATA_SIZ)) {
status = NV_BADPARM_S;
} else {
/* Create the filename */
(void) snprintf(sms_name, sizeof(sms_name), "/nvm/sms_%05d",
cmd_ptr->data_ptr->sms.address);
/* Unlink the file before writing to it as the size may be different */
if (cmd_ptr->cmd == NV_REPLACE_F)
(void) efs_unlink(sms_name);
/* Write the item */
return_size = efs_put(sms_name, (byte*)&(cmd_ptr->data_ptr->sms.address),
(sizeof(nvi_sms_gw_type) + cmd_ptr->data_ptr->sms.length),
O_CREAT, 0777);
if(return_size == -1)
{
MSG_HIGH("Write failed for SMS item address %d",
cmd_ptr->data_ptr->sms.address, 0, 0);
status = NV_FAIL_S;
}
}
return status;
} /* nvimw_write_sms */
#ifdef FEATURE_GWSMS
/*===========================================================================
FUNCTION NVIMW_WRITE_SMS_GW
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -