title: Android NFC Card emulation with fixed UID
body: <p>I've downloaded NFC parts from AOSP and I'm looking for the method used by Android to generate the random UID used by card emulation. My goal is to fix the UID instead of having a different one each time there is a communication with the target. I found inside "libnfc-nci" module the file "nfa_ce_act.c" containing this:</p>
  
  <pre><code>void nfa_ce_t3t_generate_rand_nfcid (UINT8 nfcid2[NCI_RF_F_UID_LEN])
  {
  UINT32 rand_seed = GKI_get_tick_count ();
  
  /* For Type-3 tag, nfcid2 starts witn 02:fe */
  nfcid2[0] = 0x02;
  nfcid2[1] = 0xFE;
  
  /* The remaining 6 bytes are random */
  nfcid2[2] = (UINT8) (rand_seed &amp; 0xFF);
  nfcid2[3] = (UINT8) (rand_seed&gt;&gt;8 &amp; 0xFF);
  rand_seed&gt;&gt;=(rand_seed&amp;3);
  nfcid2[4] = (UINT8) (rand_seed &amp; 0xFF);
  nfcid2[5] = (UINT8) (rand_seed&gt;&gt;8 &amp; 0xFF);
  rand_seed&gt;&gt;=(rand_seed&amp;3);
  nfcid2[6] = (UINT8) (rand_seed &amp; 0xFF);
  nfcid2[7] = (UINT8) (rand_seed&gt;&gt;8 &amp; 0xFF);
  }
  </code></pre>
  
  <p>This method generate an UID for FeliCa tags. I'm not able to find the one for ISO14443 cards (MIFARE) which generate an UID beginning with 0x08 by default. According to Martijn Coenen, as explained in his G+ Post, it's something possible.</p>
  
  <blockquote>
    <p>Sorry, I realize many people wanted this, but it's not possible in the official version. (You could of course do it with some AOSP hacking). The reason is that HCE is designed around background operation. If we allow apps to set the UID, every app possibly wants to set their own UID, and there's no way to resolve the conflict. We hope that with HCE, NFC infrastructure will move to higher levels of the protocol stack to do authentication instead of relying on the UID (which is easily cloned anyway).
    <a href="https://plus.google.com/+MartijnCoenen/posts/iX6LLoQmZLZ">https://plus.google.com/+MartijnCoenen/posts/iX6LLoQmZLZ</a></p>
  </blockquote>
  
  <p>Is anyone know how to achieve it?</p>
  
  <p>Thanks</p>