Example #1
0
int
main (void)
{
	/* Initialize GPIO (sets up clock) */
	GPIOInit ();

	/* Set LED port pin to output */
	GPIOSetDir (LED_PORT, LED_BIT, 1);
	GPIOSetValue (LED_PORT, LED_BIT, LED_OFF);

	/* Init Power Management Routines */
	pmu_init ();

	/* UART setup */
	UARTInit (115200, 0);

	/* CDC USB Initialization */
	init_usbserial ();

	/* Init RFID */
	rfid_init ();

	/* Init emulation triggers */
	trigger_init ();

	/* RUN RFID loop */
	loop_rfid ();

	return 0;
}
Example #2
0
static int init()
{
	unsigned char buf[0x3f];
	int rc;

	printf("initializing librfid\n");
	rfid_init();

	printf("opening reader handle\n");
	rh = rfid_reader_open(NULL, RFID_READER_CM5121);
	if (!rh) {
		fprintf(stderr, "error, no cm5121 handle\n");
		return -1;
	}

	printf("opening layer2 handle\n");
	l2h = rfid_layer2_init(rh, RFID_LAYER2_ISO14443A);
	//l2h = rfid_layer2_init(rh, RFID_LAYER2_ISO14443B);
	if (!l2h) {
		fprintf(stderr, "error during iso14443a_init\n");
		return -1;
	}

	//rc632_register_dump(rh->ah, buf);

	printf("running layer2 anticol\n");
	rc = rfid_layer2_open(l2h);
	if (rc < 0) {
		fprintf(stderr, "error during layer2_open\n");
		return rc;
	}

	return 0;
}
Example #3
0
int main(int argc, char **argv) {
	(void) argc;
	(void) argv;

	check_config();

	setbuf(stdout, NULL);
	setbuf(stderr, NULL);
	log("tuerd (rev " GIT_REV  ") starting up");

	if(getenv("TUERD_DEBUG"))
		debug = 1;

	debug("Debugging enabled. This allows people to be tracked!");

	// initialize git
	git_init();

	// initialize nfc
	nfc_device *nfc_dev = rfid_init();
	if(!nfc_dev)
		die("rfid_init failed");

	// initialize watchdog handler
	struct sigaction sa;
	sa.sa_handler = sigalarm;
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = 0;

	sigaction(SIGALRM, &sa, NULL);

	while(1) {
		debug("-----------------");
		debug("waiting for event");

		if(!rfid_poll(nfc_dev))
			die("rfid_poll failed");

		debug("successfully got target");

		alarm(10);

		if(rfid_authenticate_any(nfc_dev, get_key_git)) {
			debug("auth succeeded, opening door");
			open_door();
			alarm(0);

			sleep(10);
		} else {
			debug("auth failed");
			alarm(0);

			sleep(1);
		}
	}

	return EXIT_SUCCESS;
}
Example #4
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns	    : none
 *******************************************************************************/
void ICACHE_FLASH_ATTR user_init(void) {
    // stdout_init();
    rfid_init(RFID_ANY);

    system_init_done_cb(user_init_done);

    debug("\n\nSDK version: %s\n", system_get_sdk_version());
    debug("Firmware: %s\n", config_firmware_bin());
    memory_info();

    user_config_init();
    user_config_load();
    user_config_load_private_key();
    user_config_load_certificate();

    user_events_init();

    // Scan
    webserver_register_handler_callback(DEVICES_URL,   devices_handler);
    webserver_register_handler_callback(WIFI_SCAN_URL, wifi_scan_handler);

    // Native Devices
    user_button_init();
    user_relay_init();
    user_adc_init();

    // UART Devices
    mod_rfid_init();

    // I2C Devices
    i2c_master_gpio_init();
    mod_rgb_init();
    mod_tc_mk2_init();
    mod_io2_init();
    mod_irda_init();

    // SPI Devices
    mod_led_8x8_rgb_init();

    webserver_init();
}
Example #5
0
void board_init_devices(void) {
#if defined(ENVIRONMENT_SENSOR)
    kputs("Initializing i2c\n");
    i2c_init();

    kputs("Initializing Devices... Light,");
    light_init();
#ifdef REPORT_TYPE_GYRO
    kputs("Gyro, ");
    gyro_init();
#endif
#ifdef REPORT_TYPE_ACCEL
    kputs("Accell, ");
    accel_init();
#endif
#ifdef REPORT_TYPE_HUMID
    kputs("Humid, ");
    humid_init();
#endif
    kputs("PIR\n");
    pir_init();
#elif defined POWER_STRIP_MONITOR
    kputs("Initializing Devices... Power\n");
    powermon_init();
#endif

#ifdef USE_PN532
    kputs("Initializing RFID reader... \n");
    rfid_init();
#endif

#ifdef USE_MACHXO2_PMCO2
    kputs("Initializing CO2 and PM extension...\n");
    machxo2_init();
#endif

#ifdef USE_DOOR_SENSORS
    kputs("Initializing Door Sensors...\n");
    door_sensors_init();
#endif
}
Example #6
0
File: main.c Project: hangpt/bt-mfc
int main(int argc,char ** argv)
{
	RDBG("\n");
	rfid_device * rd= rfid_new_device(RFID_READER_HF_READER_ICDREC,RFID_READER_BUS_UART,(void *)argv[1]);
	if(rd){
		RDBG("\n");
		if(rfid_init(rd) != RFID_ESUCCESS) return -1;
		rfid_poll_target(rd);
#if 1
		mifare_tag  tag;
		memset(&tag,0,sizeof(mifare_tag));
		mifare_get_tag(rd,&tag);
		tag.tag.type = MIFARE_CLASSIC_1K;
		tag.tag.uid_len =4;
		tag.reader_handler = rd;
		mifare_classic_register_eeprom_key(&tag,1,MFC_KEY_A,31);
//		mifare_classic_deregister_eeprom_key(&tag,1,MFC_KEY_A);
		mifare_classic_authenticate(&tag,1,NULL,MFC_KEY_A);
#endif
		rfid_deinit(rd);
	}
	RDBG("\n");
	return 0;
}
Example #7
0
void sns_rfid_Init(void)
{
    rfid_init();

    gpio_set_out( sns_rfid_STATUS_LED );
}
Example #8
0
/* scan for devices */
RESPONSECODE initLib()
{
	RESPONSECODE rv;
	
	rfid_init();
	if (reader_init() < 0)
	{
		Log1(PCSC_LOG_CRITICAL, "reader_init() failed");
		return IFD_COMMUNICATION_ERROR;
	}
	layer2 = RFID_LAYER2_ISO14443A;
	protocol = RFID_PROTOCOL_TCL;
/*
	if (adapter_id < 0)
	{
		fprintf(stderr, "couldn't get adapter: error code %d: %s\n",
				errno, strerror(errno));
		return IFD_COMMUNICATION_ERROR;
	}
	
	scan_sock = hci_open_dev(adapter_id);
	if (scan_sock < 0)
	{
		Log1(PCSC_LOG_CRITICAL, "opening socket failed");
		return IFD_COMMUNICATION_ERROR;
	}
	
	len = 8;
	max_rsp = 255;
	flags = IREQ_CACHE_FLUSH;
	devices = (inquiry_info*) malloc(max_rsp * sizeof(inquiry_info));
	
	// scan
	num_rsp = hci_inquiry(adapter_id, len, max_rsp, NULL, &devices, flags);
	
	if (num_rsp < 0)
	{
		Log1(PCSC_LOG_CRITICAL, "hci_inquiry failed");
		return IFD_COMMUNICATION_ERROR;
	}
	
	if (num_rsp == 0)
	{
		Log1(PCSC_LOG_CRITICAL, "no devices found");
		return IFD_COMMUNICATION_ERROR;
	}
	
	// try to find the service on every device
	for (i = 0; i < num_rsp; ++i)
	{
		ba2str(&(devices + i)->bdaddr, addr);
		memset(name, 0, sizeof(name));
		if (0 != hci_read_remote_name(scan_sock, &(devices + i)->bdaddr,
									  sizeof(name), name, 0))
		{
			strcpy(name, "[unknown]");
		}
		printf("trying: %s %s\n", addr, name);
		
		// return first found
		if (getService(devices->bdaddr) == IFD_SUCCESS)
		{
			return IFD_SUCCESS;
		}
	}*/
	return IFD_SUCCESS;
}