-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession.hpp
47 lines (36 loc) · 1.32 KB
/
session.hpp
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
//
// PCD - PICC communication
//
#pragma once
#include <MFRC522.h>
#include "detail/iseq.hpp"
#include "detail/optional.hpp"
namespace nfc {
constexpr size_t uid_size = 10;
constexpr size_t key_size = 6;
constexpr size_t block_size = 16;
constexpr size_t crc_size = 2;
constexpr size_t blocks_per_sector_nb = 4;
enum class Status { OK, NO_CARD_DETECTED, NO_UID_RECEIVED, BAD_KEY, NO_ACTIVE_PICC, HALT_DENIED, ACCESS_DENIED, FATAL };
enum class Access {
FREE = 0b000,
READ_ONLY_A = 0b100,
RELOADABLE_VALUE_BLOCK = 0b110,
READ_ONLY = 0b101,
NONE = 0b111
};
enum class KeyType { KEY_A, KEY_B };
template<typename T>
using Optional = detail::Optional_base<T, Status>;
void init_mfrc522();
Status select();
Optional<uint8_t[uid_size]> get_uid();
Optional<uint8_t[block_size + crc_size]> read(uint8_t, const uint8_t *, KeyType);
Status write(uint8_t, const uint8_t *, KeyType, const uint8_t *);
Optional<int32_t> read_value(uint8_t, const uint8_t *, KeyType);
Status write_value(uint8_t, const uint8_t *, KeyType, int32_t);
Status increment(uint8_t, const uint8_t *, KeyType, int32_t = 1);
Status decrement(uint8_t, const uint8_t *, KeyType, int32_t = 1);
Status set_access(uint8_t, const uint8_t *, KeyType, const Access *);
Status seal_sector(uint8_t, uint8_t *, KeyType, uint8_t *, uint8_t *, const Access *);
} // namespace nfc