Increase NFC-A guard time to work around B5 issue.

Increase NFC-A guard time in reader mode, to make
sure we properly wake up BCM20791B05 devices.

Bug: 10852675
Change-Id: Ia30972d5d7850171bc58068c5d6896025eb6c2c1
diff --git a/nci/jni/NativeNfcManager.cpp b/nci/jni/NativeNfcManager.cpp
index 8d27c3b..0c7ba8b 100755
--- a/nci/jni/NativeNfcManager.cpp
+++ b/nci/jni/NativeNfcManager.cpp
@@ -150,6 +150,8 @@
 
 static UINT16 sCurrentConfigLen;
 static UINT8 sConfig[256];
+static UINT8 sLongGuardTime[] = { 0x00, 0x20 };
+static UINT8 sDefaultGuardTime[] = { 0x00, 0x11 };
 
 /////////////////////////////////////////////////////////////
 /////////////////////////////////////////////////////////////
@@ -1042,6 +1044,31 @@
     ALOGD ("%s: exit", __FUNCTION__);
 }
 
+void enableDisableLongGuardTime (bool enable)
+{
+    // TODO
+    // This is basically a work-around for an issue
+    // in BCM20791B5: if a reader is configured as follows
+    // 1) Only polls for NFC-A
+    // 2) Cuts field between polls
+    // 3) Has a short guard time (~5ms)
+    // the BCM20791B5 doesn't wake up when such a reader
+    // is polling it. Unfortunately the default reader
+    // mode configuration on Android matches those
+    // criteria. To avoid the issue, increase the guard
+    // time when in reader mode.
+    //
+    // Proper fix is firmware patch for B5 controllers.
+    SyncEventGuard guard(sNfaSetConfigEvent);
+    tNFA_STATUS stat = NFA_SetConfig(NCI_PARAM_ID_T1T_RDR_ONLY, 2,
+            enable ? sLongGuardTime : sDefaultGuardTime);
+    if (stat == NFA_STATUS_OK)
+        sNfaSetConfigEvent.wait ();
+    else
+        ALOGE("%s: Could not configure longer guard time", __FUNCTION__);
+    return;
+}
+
 void enableDisableLptd (bool enable)
 {
     // This method is *NOT* thread-safe. Right now
@@ -1825,6 +1852,7 @@
            tech_mask |= NFA_TECHNOLOGY_MASK_KOVIO;
 
         enableDisableLptd(false);
+        enableDisableLongGuardTime(true);
         NFA_SetRfDiscoveryDuration(READER_MODE_DISCOVERY_DURATION);
         restartPollingWithTechMask(tech_mask);
     }
@@ -1840,6 +1868,7 @@
         NFA_EnableListening();
 
         enableDisableLptd(true);
+        enableDisableLongGuardTime(false);
         NFA_SetRfDiscoveryDuration(nat->discovery_duration);
         restartPollingWithTechMask(nat->tech_mask);
     }