summaryrefslogtreecommitdiff
path: root/reader_yhy.c
blob: 7ece7020fb84ae77e73bebc5ceb5efa67a1d663b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <unistd.h>
#include <sys/timerfd.h>

#include "nfcommander.h"
#include "config.h"

#include "libyhy.h"

static int reader_fd = -1;

int init(){
	char reader_version[100];

	char* port = config_get("nfc", "device");
	if(!port){
		printf("Please configure nfc.device to the reader serial port\n");
		return 1;
	}

	//TODO set cloexec, nonblock
	printf("Opening YHY reader on %s\n", port);
	reader_fd = yhy_open(port);
	if(reader_fd < 0){
		printf("Failed to open reader connection at %s\n", port);
		return 1;
	}

	if(yhy_sync_read_version(reader_fd, reader_version, sizeof(reader_version)) > 0){
		printf("Connected YHY reader reports firmware: %s\n", reader_version);
	}

	core_manage_fd(reader_fd, 1, system_reader);
	return 0;
}

int handle(int fd){
	if(fd == reader_fd){
		printf("Unhandled data on YHY fd\n");
	}
	return 0;
}

int scan(){
	printf("Scanning field\n");
	return 0;
}

static void __attribute__((destructor)) cleanup(){
	core_manage_fd(reader_fd, 0, system_reader);
	close(reader_fd);
	reader_fd = -1;
}