-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathprinthex.c
55 lines (54 loc) · 2.02 KB
/
printhex.c
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
54
55
// printhex, example userspace code for interfacing with piProx and decoding the HID Corporate 1000 format
// Copyright (C) 2017 Nash Kaminski
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <http://www.gnu.org/licenses/>.
#include "libpiprox.h"
int main(int argc, char **argv){
const char devnode[] = "/dev/prox";
piprox_state_t prox;
piprox_hidcorp1k_t hidcorp1k;
int rv;
/* open the device node and initialize the internal state */
if(argc > 1){
rv = piprox_open(&prox, argv[1]);
}
else{
rv = piprox_open(&prox, devnode);
}
if(rv < 0){
fprintf(stderr, "piprox_open failed, return code is %d\n", rv);
return 1;
}
while(1){
printf("Waiting for card...\n");
/* Read a card */
rv = piprox_read(&prox);
printf("Read %d bytes from reader\n", rv);
if(rv > 0){
/* If the read was successful, print the data and attempt a corp1k decode */
piprox_print(&prox, STDOUT_FILENO);
rv = piprox_hidcorp1k_parse(&prox, &hidcorp1k);
if(rv == 0){
printf("Card data is smaller than 5 bytes\n");
} else if(rv < 0){
printf("Parity error on parity check %d in HID Corp. 1000 decoding\n", -rv);
} else{
printf("HID Corporate 1000 decoding done, facility=%d cardnum=%d\n", hidcorp1k.facility, hidcorp1k.cardnum);
}
} else {
return 1;
}
}
return 0;
}