+void generate4bNUID(uint8_t *uid, uint8_t *nuid){
+ uint16_t crc;
+ uint8_t first, second;
+
+ ComputeCrc14443(CRC_14443_A, uid, 3, &first, &second);
+ nuid[0] |= (second & 0xE0) | 0xF;
+ nuid[1] = first;
+
+ crc = first;
+ crc |= second << 8;
+
+ UpdateCrc14443(uid[3], &crc);
+ UpdateCrc14443(uid[4], &crc);
+ UpdateCrc14443(uid[5], &crc);
+ UpdateCrc14443(uid[6], &crc);
+
+ nuid[2] = (crc >> 8) & 0xFF ;
+ nuid[3] = crc & 0xFF;
+}
+
+int CmdAnalyseNuid(const char *Cmd){
+ uint8_t nuid[4] = {0};
+ uint8_t uid[7] = {0};
+ int len = 0;
+ char cmdp = param_getchar(Cmd, 0);
+ if (strlen(Cmd) == 0|| cmdp == 'h' || cmdp == 'H') return usage_analyse_nuid();
+
+ /* selftest UID 040D681AB52281 -> NUID 8F430FEF */
+ if (cmdp == 't' || cmdp == 'T') {
+ memcpy(uid, "\x04\x0d\x68\x1a\xb5\x22\x81", 7);
+ generate4bNUID(uid, nuid);
+ if ( 0 == memcmp(nuid, "\x8f\x43\x0f\xef", 4))
+ printf("Selftest OK\n");
+ else
+ printf("Selftest Failed\n");
+ return 0;
+ }
+
+ param_gethex_ex(Cmd, 0, uid, &len);
+ if ( len%2 || len != 14) return usage_analyse_nuid();
+
+ generate4bNUID(uid, nuid);
+
+ printf("UID | %s \n", sprint_hex(uid, 7));
+ printf("NUID | %s \n", sprint_hex(nuid, 4));
+ return 0;
+}