105 lines
2.3 KiB
C
105 lines
2.3 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include <nfc/nfc.h>
|
|
#include <nfc/nfc-types.h>
|
|
|
|
#include "tts.h"
|
|
#include "ldap.h"
|
|
|
|
static nfc_device_t *g_NFCDevice = NULL;
|
|
|
|
const nfc_modulation_t g_NFCModulations[5] = {
|
|
{ .nmt = NMT_ISO14443A, .nbr = NBR_106 },
|
|
{ .nmt = NMT_ISO14443B, .nbr = NBR_106 },
|
|
{ .nmt = NMT_FELICA, .nbr = NBR_212 },
|
|
{ .nmt = NMT_FELICA, .nbr = NBR_424 },
|
|
{ .nmt = NMT_JEWEL, .nbr = NBR_106 },
|
|
};
|
|
const size_t g_NFCModulationCount = 5;
|
|
|
|
void poll_nfc(void)
|
|
{
|
|
nfc_target_t Target;
|
|
bool Result = nfc_initiator_poll_target(g_NFCDevice, g_NFCModulations, g_NFCModulationCount, 20, 2, &Target);
|
|
|
|
if (Result)
|
|
{
|
|
if (Target.nm.nmt != NMT_ISO14443A)
|
|
return;
|
|
|
|
if (Target.nti.nai.szUidLen != 4)
|
|
return;
|
|
|
|
printf("Scanned Mifare %x.\n", *(int *)Target.nti.nai.abtUid);
|
|
|
|
char MifareID[5];
|
|
sprintf(MifareID, "%04x", *(int *)Target.nti.nai.abtUid);
|
|
|
|
char DN[128];
|
|
int DNLength = 128;
|
|
int LDAPResult = ldap_dn_by_mifare(MifareID, DN, &DNLength);
|
|
|
|
if (LDAPResult > 0)
|
|
{
|
|
if (LDAPResult == 1)
|
|
{
|
|
tts_speak("Nieznana karta.");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
tts_speak("Nieznany błąd.");
|
|
return;
|
|
}
|
|
}
|
|
printf("This appears to be %s.\n", DN);
|
|
|
|
char WelcomeMessage[200];
|
|
sprintf(WelcomeMessage, "Cześć %s.", DN);
|
|
tts_speak(WelcomeMessage);
|
|
}
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
nfc_device_desc_t *Devices;
|
|
|
|
size_t NumDevices;
|
|
Devices = (nfc_device_desc_t *) malloc(10 * sizeof(*Devices));
|
|
nfc_list_devices(Devices, 10, &NumDevices);
|
|
|
|
if (NumDevices == 0)
|
|
{
|
|
fprintf(stderr, "Error: No NFC device found.\n");
|
|
return 1;
|
|
}
|
|
|
|
if (NumDevices > 1)
|
|
{
|
|
fprintf(stderr, "Error: More than one NFC device found.\n");
|
|
return 1;
|
|
}
|
|
|
|
g_NFCDevice = nfc_connect(&Devices[0]);
|
|
|
|
if (g_NFCDevice == NULL)
|
|
{
|
|
fprintf(stderr, "Error: Could not connect to NFC device.\n");
|
|
return 1;
|
|
}
|
|
|
|
nfc_initiator_init(g_NFCDevice);
|
|
printf("Connected to NFC device.\n");
|
|
|
|
//tts_speak("Lodówka zainicjalizowana.");
|
|
tts_speak("Zażółć gęślą jaźń.");
|
|
|
|
while (1)
|
|
{
|
|
poll_nfc();
|
|
}
|
|
|
|
return 0;
|
|
}
|