-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathNFCTag.hpp
executable file
·69 lines (65 loc) · 2.42 KB
/
NFCTag.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* This file is part of the Capibara zero project(https://capibarazero.github.io/).
* Copyright (c) 2024 Andrea Canale.
*
* 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, version 3.
*
* 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/>.
*/
#ifndef NFCTAG_H
#define NFCTAG_H
#include <stdint.h>
#include <map>
#include "nfc_framework.hpp"
class NFCTag
{
private:
uint8_t *data;
bool ultralight = false;
bool ntag = false;
bool felica = false;
uint8_t *uid;
uint8_t *pmm;
uint16_t sys_code;
size_t pages_num;
/*
We can't take block position using array index
otherwise we would have enormous array with empty block
so is better to track block information in a map
*/
uint8_t felica_data[14][16] = {0};
inline size_t get_block_size() { return ntag ? NTAG_PAGE_SIZE : BLOCK_SIZE; }
public:
NFCTag(uint8_t *new_data, size_t uid_length);
// Constructor for NTAG
NFCTag(uint8_t *new_data, size_t uid_length, size_t pages);
// Constructor for FeliCa
NFCTag(uint8_t *idm, uint8_t *_pmm, uint16_t _sys_code);
NFCTag(uint8_t *idm, uint8_t *_pmm, uint16_t _sys_code, uint8_t data[14][16]);
~NFCTag(){};
inline uint8_t *get_uid() { return uid; };
uint8_t *get_data();
void get_felica_data(uint8_t new_data[14][16]) { memcpy(new_data, felica_data, 14*16); };
inline size_t get_data_size() { return ultralight ? MIFARE_CLASSIC_SIZE : MIFARE_ULTRALIGHT_SIZE; };
inline bool is_ultralight() { return ultralight; };
inline bool is_ntag() { return ntag; }
void get_block(int index, uint8_t *block);
inline size_t get_blocks_count() {
if(ntag)
return pages_num;
return ultralight ? MIFARE_ULTRALIGHT_BLOCKS : MIFARE_CLASSIC_BLOCKS;
};
inline uint8_t get_bcc() { return ultralight ? 0 : data[5]; };
inline uint8_t get_sak() { return ultralight ? data[8] : data[6]; };
void get_atqa(uint8_t *atqa);
FelicaSystemCodes get_sys_code();
};
#endif