diff options
author | Will Drewry <wad@google.com> | 2017-03-10 11:03:59 -0600 |
---|---|---|
committer | Will Drewry <wad@google.com> | 2017-03-10 11:04:45 -0600 |
commit | ed4a7a70c0f8a69188aab74fecf65f9c31b1f57c (patch) | |
tree | 42f5d63de80e71a896939333c570a00428fe4a4e /libese-hw/ese_hw_fake.c | |
parent | 5359f551f3e585a915c08d95b033da75e7962691 (diff) | |
download | libese-ed4a7a70c0f8a69188aab74fecf65f9c31b1f57c.tar.gz |
Clean up and refactor; new hw support
This change addresses portability, a pn80t platform abstraction, and
nq-nci support.
Refactor/clean up:
- Clean up Android.bp
- T=1: moved T=1 to using bit_specs to keep some
of the readability of bitfields without incurring
weird toolchain side effects.
- T=1 will still rely on compilers keeping uchars
aligned and check it with a div-by-zero build
assertion.
- ESE platform specific methods are now wrapped.
- Adjusted error message constant usage.
- Enclosing {} for every if statement.
- Moved to relative headers for inclusion into other code
bases.
- Added a comment to log.h to make debugging easier globally
in libese code.
PN80T:
- Common code now shared across different
wire configurations.
- Add support for kernel based driver (called nq-nci)
which interacts with the nq-nci behavior for power
management.
- Added cooldown/end of session code to pn80t/common.c
- Migrated the ese_nxp_sample code to NQ_NCI and added the empty
session to test the cooldown code submission.
Bug: 34193473,35105409
Test: unittests pass, tested ese-relay on hardware forwarding globalplatform pro
Change-Id: I82e8af9af7a560e558f9bb8423aceae61d902509
Diffstat (limited to 'libese-hw/ese_hw_fake.c')
-rw-r--r-- | libese-hw/ese_hw_fake.c | 93 |
1 files changed, 49 insertions, 44 deletions
diff --git a/libese-hw/ese_hw_fake.c b/libese-hw/ese_hw_fake.c index 8fe514f..310ef06 100644 --- a/libese-hw/ese_hw_fake.c +++ b/libese-hw/ese_hw_fake.c @@ -16,7 +16,28 @@ * Minimal functions that only validate arguments. */ -#include <ese/ese.h> +#include "../libese/include/ese/ese.h" + +enum EseFakeHwError { + kEseFakeHwErrorEarlyClose, + kEseFakeHwErrorReceiveDuringTransmit, + kEseFakeHwErrorInvalidReceiveSize, + kEseFakeHwErrorTransmitDuringReceive, + kEseFakeHwErrorInvalidTransmitSize, + kEseFakeHwErrorTranscieveWhileBusy, + kEseFakeHwErrorEmptyTransmit, + kEseFakeHwErrorMax, +}; + +static const char *kErrorMessages[] = { + "Interface closed without finishing transmission.", + "Receive called without completing transmission.", + "Invalid receive buffer supplied with non-zero length.", + "Transmit called without completing reception.", + "Invalid transmit buffer supplied with non-zero length.", + "Transceive called while other I/O in process.", + "Transmitted no data.", /* Can reach this by setting tx_len = 0. */ +}; static int fake_open(struct EseInterface *ese, void *hw_opts __attribute__((unused))) { @@ -25,50 +46,45 @@ static int fake_open(struct EseInterface *ese, return 0; } -static int fake_close(struct EseInterface *ese) { - if (!ese) - return -1; +static void fake_close(struct EseInterface *ese) { if (!ese->pad[0] || !ese->pad[1]) { /* Set by caller. ese->error.is_error = 1; */ - ese_set_error(ese, 0); - return -1; + ese_set_error(ese, kEseFakeHwErrorEarlyClose); + return; } - return 0; } -static size_t fake_receive(struct EseInterface *ese, uint8_t *buf, size_t len, - int complete) { - if (!ese) - return -1; +static uint32_t fake_receive(struct EseInterface *ese, uint8_t *buf, + uint32_t len, int complete) { if (!ese->pad[1]) { - ese_set_error(ese, 1); + ese_set_error(ese, kEseFakeHwErrorReceiveDuringTransmit); return -1; } ese->pad[0] = complete; if (!buf && len) { - ese_set_error(ese, 2); + ese_set_error(ese, kEseFakeHwErrorInvalidReceiveSize); return -1; } - if (!len) + if (!len) { return 0; + } return len; } -static size_t fake_transmit(struct EseInterface *ese, const uint8_t *buf, - size_t len, int complete) { - if (!ese) - return -1; +static uint32_t fake_transmit(struct EseInterface *ese, const uint8_t *buf, + uint32_t len, int complete) { if (!ese->pad[0]) { - ese_set_error(ese, 3); + ese_set_error(ese, kEseFakeHwErrorTransmitDuringReceive); return -1; } ese->pad[1] = complete; if (!buf && len) { - ese_set_error(ese, 4); + ese_set_error(ese, kEseFakeHwErrorInvalidTransmitSize); return -1; } - if (!len) + if (!len) { return 0; + } return len; } @@ -76,7 +92,7 @@ static int fake_poll(struct EseInterface *ese, uint8_t poll_for, float timeout, int complete) { /* Poll begins a receive-train so transmit needs to be completed. */ if (!ese->pad[1]) { - ese_set_error(ese, 1); + ese_set_error(ese, kEseFakeHwErrorReceiveDuringTransmit); return -1; } if (timeout == 0.0f) { @@ -91,26 +107,27 @@ static int fake_poll(struct EseInterface *ese, uint8_t poll_for, float timeout, return 0; } -size_t fake_transceive(struct EseInterface *ese, const uint8_t *tx_buf, - size_t tx_len, uint8_t *rx_buf, size_t rx_len) { - size_t processed = 0; +uint32_t fake_transceive(struct EseInterface *ese, const uint8_t *tx_buf, + uint32_t tx_len, uint8_t *rx_buf, uint32_t rx_len) { + uint32_t processed = 0; if (!ese->pad[0] || !ese->pad[1]) { - ese_set_error(ese, 5); + ese_set_error(ese, kEseFakeHwErrorTranscieveWhileBusy); return 0; } while (processed < tx_len) { - size_t sent = fake_transmit(ese, tx_buf, tx_len, 0); + uint32_t sent = fake_transmit(ese, tx_buf, tx_len, 0); if (sent == 0) { - if (ese->error.is_err) + if (ese_error(ese)) { return 0; - ese_set_error(ese, 6); + } + ese_set_error(ese, kEseFakeHwErrorEmptyTransmit); return 0; } processed += sent; } fake_transmit(ese, NULL, 0, 1); /* Complete. */ if (fake_poll(ese, 0xad, 10, 0) != 1) { - ese_set_error(ese, -2); + ese_set_error(ese, kEseGlobalErrorPollTimedOut); return 0; } /* A real implementation would have protocol errors to contend with. */ @@ -127,20 +144,8 @@ static const struct EseOperations ops = { .poll = &fake_poll, .close = &fake_close, .opts = NULL, + .errors = kErrorMessages, + .errors_count = sizeof(kErrorMessages), }; ESE_DEFINE_HW_OPS(ESE_HW_FAKE, ops); -/* TODO(wad) move opts to data. -const void *ESE_HW_FAKE_data = NULL; -*/ - -static const char *kErrorMessages[] = { - "Interface closed without finishing transmission.", - "Receive called without completing transmission.", - "Invalid receive buffer supplied with non-zero length.", - "Transmit called without completing reception.", - "Invalid transmit buffer supplied with non-zero length.", - "Transceive called while other I/O in process.", - "Transmitted no data.", /* Can reach this by setting tx_len = 0. */ -}; -ESE_DEFINE_HW_ERRORS(ESE_HW_FAKE, kErrorMessages); |