qcdm: better handle NV item read/write status codes
This commit is contained in:
@@ -203,6 +203,31 @@ check_command (const char *buf, size_t len, u_int8_t cmd, size_t min_len, int *o
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
nv_status_to_qcdm_error (u_int16_t status)
|
||||||
|
{
|
||||||
|
switch (status) {
|
||||||
|
case DIAG_NV_STATUS_OK:
|
||||||
|
return QCDM_SUCCESS;
|
||||||
|
case DIAG_NV_STATUS_BUSY:
|
||||||
|
return -QCDM_ERROR_NV_ERROR_BUSY;
|
||||||
|
case DIAG_NV_STATUS_BAD_COMMAND:
|
||||||
|
return -QCDM_ERROR_NV_ERROR_BAD_COMMAND;
|
||||||
|
case DIAG_NV_STATUS_MEMORY_FULL:
|
||||||
|
return -QCDM_ERROR_NV_ERROR_MEMORY_FULL;
|
||||||
|
case DIAG_NV_STATUS_FAILED:
|
||||||
|
return -QCDM_ERROR_NV_ERROR_FAILED;
|
||||||
|
case DIAG_NV_STATUS_INACTIVE:
|
||||||
|
return -QCDM_ERROR_NV_ERROR_INACTIVE;
|
||||||
|
case DIAG_NV_STATUS_BAD_PARAMETER:
|
||||||
|
return -QCDM_ERROR_NV_ERROR_BAD_PARAMETER;
|
||||||
|
case DIAG_NV_STATUS_READ_ONLY:
|
||||||
|
return -QCDM_ERROR_NV_ERROR_READ_ONLY;
|
||||||
|
default:
|
||||||
|
return -QCDM_ERROR_NVCMD_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static qcdmbool
|
static qcdmbool
|
||||||
check_nv_cmd (DMCmdNVReadWrite *cmd, u_int16_t nv_item, int *out_error)
|
check_nv_cmd (DMCmdNVReadWrite *cmd, u_int16_t nv_item, int *out_error)
|
||||||
{
|
{
|
||||||
@@ -213,10 +238,9 @@ check_nv_cmd (DMCmdNVReadWrite *cmd, u_int16_t nv_item, int *out_error)
|
|||||||
|
|
||||||
/* NV read/write have a status byte at the end */
|
/* NV read/write have a status byte at the end */
|
||||||
if (cmd->status != 0) {
|
if (cmd->status != 0) {
|
||||||
qcdm_err (0, "The NV operation failed (status 0x%X).",
|
qcdm_err (0, "The NV operation failed (status 0x%X).", le16toh (cmd->status));
|
||||||
le16toh (cmd->status));
|
|
||||||
if (out_error)
|
if (out_error)
|
||||||
*out_error = -QCDM_ERROR_NVCMD_FAILED;
|
*out_error = nv_status_to_qcdm_error (le16toh (cmd->status));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -45,6 +45,13 @@ enum {
|
|||||||
QCDM_ERROR_RESPONSE_BAD_MODE = 10,
|
QCDM_ERROR_RESPONSE_BAD_MODE = 10,
|
||||||
QCDM_ERROR_NVCMD_FAILED = 11,
|
QCDM_ERROR_NVCMD_FAILED = 11,
|
||||||
QCDM_ERROR_SPC_LOCKED = 12,
|
QCDM_ERROR_SPC_LOCKED = 12,
|
||||||
|
QCDM_ERROR_NV_ERROR_BUSY = 13,
|
||||||
|
QCDM_ERROR_NV_ERROR_BAD_COMMAND = 14,
|
||||||
|
QCDM_ERROR_NV_ERROR_MEMORY_FULL = 15,
|
||||||
|
QCDM_ERROR_NV_ERROR_FAILED = 16,
|
||||||
|
QCDM_ERROR_NV_ERROR_INACTIVE = 17, /* NV location is not active */
|
||||||
|
QCDM_ERROR_NV_ERROR_BAD_PARAMETER = 18,
|
||||||
|
QCDM_ERROR_NV_ERROR_READ_ONLY = 19, /* NV location is read-only */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define qcdm_assert assert
|
#define qcdm_assert assert
|
||||||
|
@@ -20,6 +20,18 @@
|
|||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
/* NV read/write status codes */
|
||||||
|
typedef enum {
|
||||||
|
DIAG_NV_STATUS_OK = 0,
|
||||||
|
DIAG_NV_STATUS_BUSY = 1,
|
||||||
|
DIAG_NV_STATUS_BAD_COMMAND = 2,
|
||||||
|
DIAG_NV_STATUS_MEMORY_FULL = 3,
|
||||||
|
DIAG_NV_STATUS_FAILED = 4,
|
||||||
|
DIAG_NV_STATUS_INACTIVE = 5, /* NV location not active */
|
||||||
|
DIAG_NV_STATUS_BAD_PARAMETER = 6,
|
||||||
|
DIAG_NV_STATUS_READ_ONLY = 7, /* NV location is read-only */
|
||||||
|
} DMNVStatus;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
DIAG_NV_MODE_PREF = 10, /* Mode preference: 1x, HDR, auto */
|
DIAG_NV_MODE_PREF = 10, /* Mode preference: 1x, HDR, auto */
|
||||||
DIAG_NV_DIR_NUMBER = 178, /* Mobile Directory Number (MDN) */
|
DIAG_NV_DIR_NUMBER = 178, /* Mobile Directory Number (MDN) */
|
||||||
|
@@ -539,8 +539,11 @@ test_com_read_mode_pref (void *f, void *data)
|
|||||||
/* Parse the response into a result structure */
|
/* Parse the response into a result structure */
|
||||||
result = qcdm_cmd_nv_get_mode_pref_result (buf, reply_len, &err);
|
result = qcdm_cmd_nv_get_mode_pref_result (buf, reply_len, &err);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
g_assert (err == -QCDM_ERROR_NVCMD_FAILED || err == -QCDM_ERROR_RESPONSE_BAD_PARAMETER);
|
if ( err == -QCDM_ERROR_NVCMD_FAILED
|
||||||
return;
|
|| err == -QCDM_ERROR_RESPONSE_BAD_PARAMETER
|
||||||
|
|| err == -QCDM_ERROR_NV_ERROR_INACTIVE)
|
||||||
|
return;
|
||||||
|
g_assert_cmpint (err, ==, QCDM_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_print ("\n");
|
g_print ("\n");
|
||||||
@@ -608,8 +611,11 @@ test_com_read_hdr_rev_pref (void *f, void *data)
|
|||||||
/* Parse the response into a result structure */
|
/* Parse the response into a result structure */
|
||||||
result = qcdm_cmd_nv_get_hdr_rev_pref_result (buf, reply_len, &err);
|
result = qcdm_cmd_nv_get_hdr_rev_pref_result (buf, reply_len, &err);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
g_assert (err == -QCDM_ERROR_NVCMD_FAILED || err == -QCDM_ERROR_RESPONSE_BAD_PARAMETER);
|
if ( err == -QCDM_ERROR_NVCMD_FAILED
|
||||||
return;
|
|| err == -QCDM_ERROR_RESPONSE_BAD_PARAMETER
|
||||||
|
|| err == -QCDM_ERROR_NV_ERROR_INACTIVE)
|
||||||
|
return;
|
||||||
|
g_assert_cmpint (err, ==, QCDM_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_print ("\n");
|
g_print ("\n");
|
||||||
|
Reference in New Issue
Block a user