ESPHome 2026.3.0-dev
Loading...
Searching...
No Matches
nci_core.h
Go to the documentation of this file.
1#pragma once
2
4
5#include <vector>
6
7namespace esphome {
8namespace nfc {
9
10// Header info
11static constexpr uint8_t NCI_PKT_HEADER_SIZE = 3; // NCI packet (pkt) headers are always three bytes
12static constexpr uint8_t NCI_PKT_MT_GID_OFFSET = 0; // NCI packet (pkt) MT and GID offsets
13static constexpr uint8_t NCI_PKT_OID_OFFSET = 1; // NCI packet (pkt) OID offset
14static constexpr uint8_t NCI_PKT_LENGTH_OFFSET = 2; // NCI packet (pkt) message length (size) offset
15static constexpr uint8_t NCI_PKT_PAYLOAD_OFFSET = 3; // NCI packet (pkt) payload offset
16// Important masks
17static constexpr uint8_t NCI_PKT_MT_MASK = 0xE0; // NCI packet (pkt) message type mask
18static constexpr uint8_t NCI_PKT_PBF_MASK = 0x10; // packet boundary flag bit
19static constexpr uint8_t NCI_PKT_GID_MASK = 0x0F;
20static constexpr uint8_t NCI_PKT_OID_MASK = 0x3F;
21// Message types
22static constexpr uint8_t NCI_PKT_MT_DATA = 0x00; // For sending commands to NFC endpoint (card/tag)
23static constexpr uint8_t NCI_PKT_MT_CTRL_COMMAND = 0x20; // For sending commands to NFCC
24static constexpr uint8_t NCI_PKT_MT_CTRL_RESPONSE = 0x40; // Response from NFCC to commands
25static constexpr uint8_t NCI_PKT_MT_CTRL_NOTIFICATION = 0x60; // Notification from NFCC
26// GIDs
27static constexpr uint8_t NCI_CORE_GID = 0x0;
28static constexpr uint8_t RF_GID = 0x1;
29static constexpr uint8_t NFCEE_GID = 0x1;
30static constexpr uint8_t NCI_PROPRIETARY_GID = 0xF;
31// OIDs
32static constexpr uint8_t NCI_CORE_RESET_OID = 0x00;
33static constexpr uint8_t NCI_CORE_INIT_OID = 0x01;
34static constexpr uint8_t NCI_CORE_SET_CONFIG_OID = 0x02;
35static constexpr uint8_t NCI_CORE_GET_CONFIG_OID = 0x03;
36static constexpr uint8_t NCI_CORE_CONN_CREATE_OID = 0x04;
37static constexpr uint8_t NCI_CORE_CONN_CLOSE_OID = 0x05;
38static constexpr uint8_t NCI_CORE_CONN_CREDITS_OID = 0x06;
39static constexpr uint8_t NCI_CORE_GENERIC_ERROR_OID = 0x07;
40static constexpr uint8_t NCI_CORE_INTERFACE_ERROR_OID = 0x08;
41
42static constexpr uint8_t RF_DISCOVER_MAP_OID = 0x00;
43static constexpr uint8_t RF_SET_LISTEN_MODE_ROUTING_OID = 0x01;
44static constexpr uint8_t RF_GET_LISTEN_MODE_ROUTING_OID = 0x02;
45static constexpr uint8_t RF_DISCOVER_OID = 0x03;
46static constexpr uint8_t RF_DISCOVER_SELECT_OID = 0x04;
47static constexpr uint8_t RF_INTF_ACTIVATED_OID = 0x05;
48static constexpr uint8_t RF_DEACTIVATE_OID = 0x06;
49static constexpr uint8_t RF_FIELD_INFO_OID = 0x07;
50static constexpr uint8_t RF_T3T_POLLING_OID = 0x08;
51static constexpr uint8_t RF_NFCEE_ACTION_OID = 0x09;
52static constexpr uint8_t RF_NFCEE_DISCOVERY_REQ_OID = 0x0A;
53static constexpr uint8_t RF_PARAMETER_UPDATE_OID = 0x0B;
54
55static constexpr uint8_t NFCEE_DISCOVER_OID = 0x00;
56static constexpr uint8_t NFCEE_MODE_SET_OID = 0x01;
57// Interfaces
58static constexpr uint8_t INTF_NFCEE_DIRECT = 0x00;
59static constexpr uint8_t INTF_FRAME = 0x01;
60static constexpr uint8_t INTF_ISODEP = 0x02;
61static constexpr uint8_t INTF_NFCDEP = 0x03;
62static constexpr uint8_t INTF_TAGCMD = 0x80; // NXP proprietary
63// Bit rates
64static constexpr uint8_t NFC_BIT_RATE_106 = 0x00;
65static constexpr uint8_t NFC_BIT_RATE_212 = 0x01;
66static constexpr uint8_t NFC_BIT_RATE_424 = 0x02;
67static constexpr uint8_t NFC_BIT_RATE_848 = 0x03;
68static constexpr uint8_t NFC_BIT_RATE_1695 = 0x04;
69static constexpr uint8_t NFC_BIT_RATE_3390 = 0x05;
70static constexpr uint8_t NFC_BIT_RATE_6780 = 0x06;
71// Protocols
72static constexpr uint8_t PROT_UNDETERMINED = 0x00;
73static constexpr uint8_t PROT_T1T = 0x01;
74static constexpr uint8_t PROT_T2T = 0x02;
75static constexpr uint8_t PROT_T3T = 0x03;
76static constexpr uint8_t PROT_ISODEP = 0x04;
77static constexpr uint8_t PROT_NFCDEP = 0x05;
78static constexpr uint8_t PROT_T5T = 0x06;
79static constexpr uint8_t PROT_MIFARE = 0x80;
80// RF Technologies
81static constexpr uint8_t NFC_RF_TECH_A = 0x00;
82static constexpr uint8_t NFC_RF_TECH_B = 0x01;
83static constexpr uint8_t NFC_RF_TECH_F = 0x02;
84static constexpr uint8_t NFC_RF_TECH_15693 = 0x03;
85// RF Technology & Modes
86static constexpr uint8_t MODE_MASK = 0xF0;
87static constexpr uint8_t MODE_LISTEN_MASK = 0x80;
88static constexpr uint8_t MODE_POLL = 0x00;
89
90static constexpr uint8_t TECH_PASSIVE_NFCA = 0x00;
91static constexpr uint8_t TECH_PASSIVE_NFCB = 0x01;
92static constexpr uint8_t TECH_PASSIVE_NFCF = 0x02;
93static constexpr uint8_t TECH_ACTIVE_NFCA = 0x03;
94static constexpr uint8_t TECH_ACTIVE_NFCF = 0x05;
95static constexpr uint8_t TECH_PASSIVE_15693 = 0x06;
96// Status codes
97static constexpr uint8_t STATUS_OK = 0x00;
98static constexpr uint8_t STATUS_REJECTED = 0x01;
99static constexpr uint8_t STATUS_RF_FRAME_CORRUPTED = 0x02;
100static constexpr uint8_t STATUS_FAILED = 0x03;
101static constexpr uint8_t STATUS_NOT_INITIALIZED = 0x04;
102static constexpr uint8_t STATUS_SYNTAX_ERROR = 0x05;
103static constexpr uint8_t STATUS_SEMANTIC_ERROR = 0x06;
104static constexpr uint8_t STATUS_INVALID_PARAM = 0x09;
105static constexpr uint8_t STATUS_MESSAGE_SIZE_EXCEEDED = 0x0A;
106static constexpr uint8_t DISCOVERY_ALREADY_STARTED = 0xA0;
107static constexpr uint8_t DISCOVERY_TARGET_ACTIVATION_FAILED = 0xA1;
108static constexpr uint8_t DISCOVERY_TEAR_DOWN = 0xA2;
109static constexpr uint8_t RF_TRANSMISSION_ERROR = 0xB0;
110static constexpr uint8_t RF_PROTOCOL_ERROR = 0xB1;
111static constexpr uint8_t RF_TIMEOUT_ERROR = 0xB2;
112static constexpr uint8_t NFCEE_INTERFACE_ACTIVATION_FAILED = 0xC0;
113static constexpr uint8_t NFCEE_TRANSMISSION_ERROR = 0xC1;
114static constexpr uint8_t NFCEE_PROTOCOL_ERROR = 0xC2;
115static constexpr uint8_t NFCEE_TIMEOUT_ERROR = 0xC3;
116// Deactivation types/reasons
117static constexpr uint8_t DEACTIVATION_TYPE_IDLE = 0x00;
118static constexpr uint8_t DEACTIVATION_TYPE_SLEEP = 0x01;
119static constexpr uint8_t DEACTIVATION_TYPE_SLEEP_AF = 0x02;
120static constexpr uint8_t DEACTIVATION_TYPE_DISCOVERY = 0x03;
121// RF discover map modes
122static constexpr uint8_t RF_DISCOVER_MAP_MODE_POLL = 0x1;
123static constexpr uint8_t RF_DISCOVER_MAP_MODE_LISTEN = 0x2;
124// RF discover notification types
125static constexpr uint8_t RF_DISCOVER_NTF_NT_LAST = 0x00;
126static constexpr uint8_t RF_DISCOVER_NTF_NT_LAST_RL = 0x01;
127static constexpr uint8_t RF_DISCOVER_NTF_NT_MORE = 0x02;
128// Important message offsets
129static constexpr uint8_t RF_DISCOVER_NTF_DISCOVERY_ID = 0 + NCI_PKT_HEADER_SIZE;
130static constexpr uint8_t RF_DISCOVER_NTF_PROTOCOL = 1 + NCI_PKT_HEADER_SIZE;
131static constexpr uint8_t RF_DISCOVER_NTF_MODE_TECH = 2 + NCI_PKT_HEADER_SIZE;
132static constexpr uint8_t RF_DISCOVER_NTF_RF_TECH_LENGTH = 3 + NCI_PKT_HEADER_SIZE;
133static constexpr uint8_t RF_DISCOVER_NTF_RF_TECH_PARAMS = 4 + NCI_PKT_HEADER_SIZE;
134static constexpr uint8_t RF_INTF_ACTIVATED_NTF_DISCOVERY_ID = 0 + NCI_PKT_HEADER_SIZE;
135static constexpr uint8_t RF_INTF_ACTIVATED_NTF_INTERFACE = 1 + NCI_PKT_HEADER_SIZE;
136static constexpr uint8_t RF_INTF_ACTIVATED_NTF_PROTOCOL = 2 + NCI_PKT_HEADER_SIZE;
137static constexpr uint8_t RF_INTF_ACTIVATED_NTF_MODE_TECH = 3 + NCI_PKT_HEADER_SIZE;
138static constexpr uint8_t RF_INTF_ACTIVATED_NTF_MAX_SIZE = 4 + NCI_PKT_HEADER_SIZE;
139static constexpr uint8_t RF_INTF_ACTIVATED_NTF_INIT_CRED = 5 + NCI_PKT_HEADER_SIZE;
140static constexpr uint8_t RF_INTF_ACTIVATED_NTF_RF_TECH_LENGTH = 6 + NCI_PKT_HEADER_SIZE;
141static constexpr uint8_t RF_INTF_ACTIVATED_NTF_RF_TECH_PARAMS = 7 + NCI_PKT_HEADER_SIZE;
142
143} // namespace nfc
144} // namespace esphome
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7