diff options
author | Dan Williams <dcbw@redhat.com> | 2012-01-05 12:29:03 -0600 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2012-01-05 12:29:03 -0600 |
commit | 62d26479ff70f353bf81d0971397017ae2e353fc (patch) | |
tree | e727d9f375744922f9511ee6f52bba9d521855f6 /libqcdm | |
parent | 6e961ddd83b9f5aea64ee73ecb1398a3466d5509 (diff) |
qcdm: better handle NV item read/write status codes
Diffstat (limited to 'libqcdm')
-rw-r--r-- | libqcdm/src/commands.c | 30 | ||||
-rw-r--r-- | libqcdm/src/errors.h | 7 | ||||
-rw-r--r-- | libqcdm/src/nv-items.h | 12 | ||||
-rw-r--r-- | libqcdm/tests/test-qcdm-com.c | 14 |
4 files changed, 56 insertions, 7 deletions
diff --git a/libqcdm/src/commands.c b/libqcdm/src/commands.c index 2301baff..d48d1e9f 100644 --- a/libqcdm/src/commands.c +++ b/libqcdm/src/commands.c @@ -203,6 +203,31 @@ check_command (const char *buf, size_t len, u_int8_t cmd, size_t min_len, int *o 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 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 */ if (cmd->status != 0) { - qcdm_err (0, "The NV operation failed (status 0x%X).", - le16toh (cmd->status)); + qcdm_err (0, "The NV operation failed (status 0x%X).", le16toh (cmd->status)); if (out_error) - *out_error = -QCDM_ERROR_NVCMD_FAILED; + *out_error = nv_status_to_qcdm_error (le16toh (cmd->status)); return FALSE; } diff --git a/libqcdm/src/errors.h b/libqcdm/src/errors.h index e275ae33..51b7155c 100644 --- a/libqcdm/src/errors.h +++ b/libqcdm/src/errors.h @@ -45,6 +45,13 @@ enum { QCDM_ERROR_RESPONSE_BAD_MODE = 10, QCDM_ERROR_NVCMD_FAILED = 11, 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 diff --git a/libqcdm/src/nv-items.h b/libqcdm/src/nv-items.h index ae91585c..56f6f0b4 100644 --- a/libqcdm/src/nv-items.h +++ b/libqcdm/src/nv-items.h @@ -20,6 +20,18 @@ #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 { DIAG_NV_MODE_PREF = 10, /* Mode preference: 1x, HDR, auto */ DIAG_NV_DIR_NUMBER = 178, /* Mobile Directory Number (MDN) */ diff --git a/libqcdm/tests/test-qcdm-com.c b/libqcdm/tests/test-qcdm-com.c index 727c2578..4d99cda4 100644 --- a/libqcdm/tests/test-qcdm-com.c +++ b/libqcdm/tests/test-qcdm-com.c @@ -539,8 +539,11 @@ test_com_read_mode_pref (void *f, void *data) /* Parse the response into a result structure */ result = qcdm_cmd_nv_get_mode_pref_result (buf, reply_len, &err); if (!result) { - g_assert (err == -QCDM_ERROR_NVCMD_FAILED || err == -QCDM_ERROR_RESPONSE_BAD_PARAMETER); - return; + if ( err == -QCDM_ERROR_NVCMD_FAILED + || err == -QCDM_ERROR_RESPONSE_BAD_PARAMETER + || err == -QCDM_ERROR_NV_ERROR_INACTIVE) + return; + g_assert_cmpint (err, ==, QCDM_SUCCESS); } g_print ("\n"); @@ -608,8 +611,11 @@ test_com_read_hdr_rev_pref (void *f, void *data) /* Parse the response into a result structure */ result = qcdm_cmd_nv_get_hdr_rev_pref_result (buf, reply_len, &err); if (!result) { - g_assert (err == -QCDM_ERROR_NVCMD_FAILED || err == -QCDM_ERROR_RESPONSE_BAD_PARAMETER); - return; + if ( err == -QCDM_ERROR_NVCMD_FAILED + || err == -QCDM_ERROR_RESPONSE_BAD_PARAMETER + || err == -QCDM_ERROR_NV_ERROR_INACTIVE) + return; + g_assert_cmpint (err, ==, QCDM_SUCCESS); } g_print ("\n"); |