-
Notifications
You must be signed in to change notification settings - Fork 9
/
session.h
62 lines (48 loc) · 1.37 KB
/
session.h
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
56
57
58
59
60
61
62
#ifndef SCSNIFF_SESSION_H
#define SCSNIFF_SESSION_H
#include <sys/time.h>
#include "packet.h"
#include "atr.h"
#include "data.h"
#include "pps.h"
enum session_state {
INIT = 0,
ATR,
IDLE,
PPS,
T0_DATA,
T1_DATA,
};
#define SESSION_BUFLEN (512)
typedef void (*set_baudrate_fn)(int fd, unsigned baudrate);
typedef void (*completed_packet_fn)(struct packet *packet);
typedef void (*log_msg_fn)(const char *msg);
// Per-session fields, to be reset when card is.
struct current_session {
unsigned char buf[SESSION_BUFLEN];
unsigned buf_index;
enum session_state state;
struct timeval buf_time;
unsigned protocol_version;
unsigned baudrate;
unsigned inverse_convention;
struct atr atr;
struct pps pps;
struct data data;
};
struct session {
set_baudrate_fn set_baudrate;
int serial_fd;
unsigned base_baudrate;
completed_packet_fn completed_packet;
log_msg_fn log_msg;
struct current_session curr;
};
void session_init(struct session *session, completed_packet_fn completed_packet,
set_baudrate_fn set_baudrate, log_msg_fn log_msg, int fd,
unsigned baudrate);
void session_reset(struct session *session);
void session_add_byte(struct session *session, unsigned char data);
// For testing
unsigned char convert_from_inverse(unsigned char data);
#endif // SCSNIFF_SESSION_H