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
diff --git a/libese/ese.c b/libese/ese.c
index 1e49e22..2a0048f 100644
--- a/libese/ese.c
+++ b/libese/ese.c
@@ -14,8 +14,8 @@
* limitations under the License.
*/
-#include <ese/ese.h>
-#include <ese/log.h>
+#include "include/ese/ese.h"
+#include "include/ese/log.h"
#include "ese_private.h"
@@ -27,84 +27,91 @@
};
#define ESE_MESSAGES(x) (sizeof(x) / sizeof((x)[0]))
-/* TODO(wad): Make the default visibility on this one default default? */
-API const char *ese_name(struct EseInterface *ese) {
- if (!ese)
+API const char *ese_name(const struct EseInterface *ese) {
+ if (!ese) {
return kNullEse;
- if (ese->ops->name)
+ }
+ if (ese->ops->name) {
return ese->ops->name;
+ }
return kUnknownHw;
}
API int ese_open(struct EseInterface *ese, void *hw_opts) {
- if (!ese)
+ if (!ese) {
return -1;
+ }
ALOGV("opening interface '%s'", ese_name(ese));
- if (ese->ops->open)
+ if (ese->ops->open) {
return ese->ops->open(ese, hw_opts);
+ }
return 0;
}
-API const char *ese_error_message(struct EseInterface *ese) {
+API const char *ese_error_message(const struct EseInterface *ese) {
return ese->error.message;
}
-API int ese_error_code(struct EseInterface *ese) { return ese->error.code; }
+API int ese_error_code(const struct EseInterface *ese) {
+ return ese->error.code;
+}
-API int ese_error(struct EseInterface *ese) { return ese->error.is_err; }
+API bool ese_error(const struct EseInterface *ese) { return ese->error.is_err; }
API void ese_set_error(struct EseInterface *ese, int code) {
- if (!ese)
+ if (!ese) {
return;
+ }
/* Negative values are reserved for API wide messages. */
ese->error.code = code;
- ese->error.is_err = 1;
+ ese->error.is_err = true;
if (code < 0) {
code = -(code + 1); /* Start at 0. */
- if ((size_t)(code) >= ESE_MESSAGES(kEseErrorMessages)) {
+ if ((uint32_t)(code) >= ESE_MESSAGES(kEseErrorMessages)) {
LOG_ALWAYS_FATAL("Unknown global error code passed to ese_set_error(%d)",
code);
}
ese->error.message = kEseErrorMessages[code];
return;
}
- if ((size_t)(code) >= ese->errors_count) {
+ if ((uint32_t)(code) >= ese->ops->errors_count) {
LOG_ALWAYS_FATAL("Unknown hw error code passed to ese_set_error(%d)", code);
}
- ese->error.message = ese->errors[code];
+ ese->error.message = ese->ops->errors[code];
}
/* Blocking. */
-API int ese_transceive(struct EseInterface *ese, uint8_t *const tx_buf,
- size_t tx_len, uint8_t *rx_buf, size_t rx_max) {
- size_t recvd = 0;
- if (!ese)
+API int ese_transceive(struct EseInterface *ese, const uint8_t *tx_buf,
+ uint32_t tx_len, uint8_t *rx_buf, uint32_t rx_max) {
+ uint32_t recvd = 0;
+ if (!ese) {
return -1;
- while (1) {
- if (ese->ops->transceive) {
- recvd = ese->ops->transceive(ese, tx_buf, tx_len, rx_buf, rx_max);
- break;
- }
- if (ese->ops->hw_transmit && ese->ops->hw_receive) {
- ese->ops->hw_transmit(ese, tx_buf, tx_len, 1);
- if (ese->error.is_err)
- break;
- recvd = ese->ops->hw_receive(ese, rx_buf, rx_max, 1);
- break;
- }
- ese_set_error(ese, -1);
- break;
}
- if (ese->error.is_err)
- return -1;
- return recvd;
+
+ if (ese->ops->transceive) {
+ recvd = ese->ops->transceive(ese, tx_buf, tx_len, rx_buf, rx_max);
+ return ese_error(ese) ? -1 : recvd;
+ }
+
+ if (ese->ops->hw_transmit && ese->ops->hw_receive) {
+ ese->ops->hw_transmit(ese, tx_buf, tx_len, 1);
+ if (!ese_error(ese)) {
+ recvd = ese->ops->hw_receive(ese, rx_buf, rx_max, 1);
+ }
+ return ese_error(ese) ? -1 : recvd;
+ }
+
+ ese_set_error(ese, kEseGlobalErrorNoTransceive);
+ return -1;
}
-API int ese_close(struct EseInterface *ese) {
- if (!ese)
- return -1;
+API void ese_close(struct EseInterface *ese) {
+ if (!ese) {
+ return;
+ }
ALOGV("closing interface '%s'", ese_name(ese));
- if (!ese->ops->close)
- return 0;
- return ese->ops->close(ese);
+ if (!ese->ops->close) {
+ return;
+ }
+ ese->ops->close(ese);
}