Exemple #1
0
bool silvia_nfc_card::status()
{
	if (!connected) return false;
	
	if (nfc_initiator_target_is_present(device, &target) != 0)
	{
		connected = false;
	}
	
	return connected;
}
Exemple #2
0
int main(int argc, char** argv) {
    
    memset(&mtDump, 0x00, sizeof(mtDump));
    Credentials crd;
    char cmd[200];
    
    signal(SIGINT, stop_polling);
    
    
    nfc_init(&RT.context);
    
    if (RT.context == NULL) {
          ERR("Unable to init libnfc (malloc)");
          exit(EXIT_FAILURE);
        }
        TagInit(&RT);
      
    while(run){
        
            if(ScanForTag(&RT)){
                if(N_read_card(RT,&mtDump)){
                    if(NDDEF_DEGenerate(&crd, &mtDump)){
                        if(Credentials_Check(&crd)){
                            printf("\nGood\n");
                            memset(cmd, 0x00, sizeof(cmd));
                            //snprintf(cmd,200,"startx /usr/bin/nice -n 18 /usr/bin/rdesktop -a 24 -x 6 -P -r sound:local -u %s -p %s -f %s",crd.user,crd.password, crd.VM);
                            //printf("%s",cmd);
                            //system(cmd);
                            printf("Waiting for card removing...");
                            sleep(1);
                            while (0 == nfc_initiator_target_is_present(RT.device, NULL)) {}
                            nfc_perror(RT.device, "nfc_initiator_target_is_present");
                            printf("done.\n");
                        }
                    }
                }
            }
        
        //nfc_idle(RT.device);
        //nfc_exit(RT.context);
        sleep(1);
    }
    if (RT.device != NULL)
        nfc_abort_command(RT.device);
    else {
      nfc_exit(RT.context);
      exit(EXIT_SUCCESS);
    }
}
int main(int argc, const char *argv[])
{
    nfc_device *pnd;
    nfc_target nt;

    nfc_context *context;

    nfc_init(&context);
    if(context == NULL) {
        printf("unable to init (malloc)\n");
        exit(EXIT_FAILURE);
    }

    pnd = nfc_open(context, NULL);

    if (pnd == NULL) {
        printf("ERROR: %s\n", "Unable to open NFC Device.");
        exit(EXIT_FAILURE);
    }

    if (nfc_initiator_init(pnd) < 0) {
        nfc_perror(pnd, "nfc_initiator_init");
        exit(EXIT_FAILURE);
    }

    printf("NFC reader: %s opened\n", nfc_device_get_name(pnd));

    const nfc_modulation nmMifare = {
        .nmt = NMT_ISO14443A,
        .nbr = NBR_106,
    };

    for(int i = 0; i < 24; i++) {
        if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) > 0) {
            printf("The following (NFC) card was found:\n");
            print_card(nt.nti.nai.abtUid, nt.nti.nai.szUidLen);
        }
        while (0 == nfc_initiator_target_is_present(pnd, NULL)){}
    }

    nfc_close(pnd);

    nfc_exit(context);

    exit(EXIT_SUCCESS);   
}
Exemple #4
0
/*
 * Returns true if last selected tag is still present.
 */
bool freefare_selected_tag_is_present(nfc_device *device)
{
    return (nfc_initiator_target_is_present(device, NULL) == NFC_SUCCESS);
}