Clean up and refactor; new hw support

(Originally, https://android-review.googlesource.com/#/c/341550/)

This change addresses portability, a pn80t platform abstraction, and
nq-nci support.

Refactor/clean up:
- Adds darwin-sysdeps.c to help avoid reverting again.
- 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
Change-Id: I8fc320c8c236282ed103ef3ee3cb8c0dc99d8bcb
Test: unittests pass, tested ese-relay on hardware forwarding globalplatform pro
diff --git a/examples/Android.bp b/examples/Android.bp
index d4a6960..1678ba0 100644
--- a/examples/Android.bp
+++ b/examples/Android.bp
@@ -14,27 +14,19 @@
 // limitations under the License.
 //
 
-example_static_libraries = []
-
-example_shared_libraries = [
-    "liblog",
-    "libese",
-    "libese-teq1",
-    "libese-hw-nxp-pn80t-spidev",
-]
-
 cc_binary {
     name: "ese_nxp_sample",
     srcs: ["ese_nxp_sample.c"],
     host_supported: false,
-    shared_libs: example_shared_libraries,
-
     target: {
-      darwin: {
-        enabled: false,
-      },
-      windows: {
-        enabled: false,
-      },
+        darwin: {
+            enabled: false,
+        },
     },
+    shared_libs: [
+        "liblog",
+        "libese",
+        "libese-teq1",
+        "libese-hw-nxp-pn80t-nq-nci",
+    ],
 }
diff --git a/examples/ese_nxp_sample.c b/examples/ese_nxp_sample.c
index 392ce63..7eae531 100644
--- a/examples/ese_nxp_sample.c
+++ b/examples/ese_nxp_sample.c
@@ -22,19 +22,17 @@
 #include <unistd.h>
 
 #include <ese/ese.h>
-/* Note, the struct could be build just as well. */
-#include <ese/hw/nxp/pn80t/boards/hikey-spidev.h>
-ESE_INCLUDE_HW(ESE_HW_NXP_PN80T_SPIDEV);
+ESE_INCLUDE_HW(ESE_HW_NXP_PN80T_NQ_NCI);
 
 /* APDU: CLA INS P1-P2 Lc Data Le */
 struct Apdu {
-  size_t length;
+  uint32_t length;
   const uint8_t *bytes;
   const char *desc;
 };
 
 struct ApduSession {
-  size_t count;
+  uint32_t count;
   const char *desc;
   const struct Apdu *apdus[];
 };
@@ -63,6 +61,10 @@
         },
 };
 
+const struct ApduSession kEmptySession = {
+    .count = 0, .desc = "Empty session (cooldown only)", .apdus = {},
+};
+
 /* Define the loader service sessions here! */
 const uint8_t kSelectJcopIdentifyBytes[] = {
     0x00, 0xA4, 0x04, 0x00, 0x09, 0xA0, 0x00,
@@ -75,17 +77,18 @@
 };
 
 const struct ApduSession *kSessions[] = {
-    &kGetCplcSession,
+    &kGetCplcSession, &kEmptySession,
 };
 
 int main() {
-  struct EseInterface ese = ESE_INITIALIZER(ESE_HW_NXP_PN80T_SPIDEV);
+  struct EseInterface ese = ESE_INITIALIZER(ESE_HW_NXP_PN80T_NQ_NCI);
+  void *ese_hw_open_data = NULL;
   size_t s = 0;
   for (; s < sizeof(kSessions) / sizeof(kSessions[0]); ++s) {
     int recvd;
-    size_t apdu_index = 0;
+    uint32_t apdu_index = 0;
     uint8_t rx_buf[1024];
-    if (ese_open(&ese, (void *)(&nxp_boards_hikey_spidev))) {
+    if (ese_open(&ese, ese_hw_open_data) < 0) {
       printf("Cannot open hw\n");
       if (ese_error(&ese))
         printf("eSE error (%d): %s\n", ese_error_code(&ese),
@@ -94,10 +97,10 @@
     }
     printf("Running session %s\n", kSessions[s]->desc);
     for (; apdu_index < kSessions[s]->count; ++apdu_index) {
-      size_t i;
+      uint32_t i;
       const struct Apdu *apdu = kSessions[s]->apdus[apdu_index];
-      printf("Sending APDU %zu: %s\n", apdu_index, apdu->desc);
-      printf("Sending %zu bytes to card\n", apdu->length);
+      printf("Sending APDU %u: %s\n", apdu_index, apdu->desc);
+      printf("Sending %u bytes to card\n", apdu->length);
       printf("TX: ");
       for (i = 0; i < apdu->length; ++i)
         printf("%.2X ", apdu->bytes[i]);