hsw-nbt 1.2.0
OPTIGA Authenticate NBT Host Library for C
nbt-cmd.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2024-2026 Infineon Technologies AG
2// SPDX-License-Identifier: MIT
3
8#ifndef NBT_CMD_H
9#define NBT_CMD_H
10
12#include "infineon/nbt-apdu.h"
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19/* Function identifiers */
20
24#define NBT_AUTHENTICATE_TAG UINT8_C(0x01)
25
29#define NBT_APPLET_VERSION UINT8_C(0x02)
30
34#define NBT_AVAILABLE_MEMORY UINT8_C(0x03)
35
39#define NBT_CHANGE_PASSWORD UINT8_C(0x04)
40
44#define NBT_CREATE_PASSWORD UINT8_C(0x05)
45
49#define NBT_DELETE_PASSWORD UINT8_C(0x06)
50
54#define NBT_GET_DATA UINT8_C(0x07)
55
59#define NBT_GET_FAP_BYTES UINT8_C(0x08)
60
64#define NBT_READ_BINARY UINT8_C(0x09)
65
69#define NBT_READ_FAP_WITH_PASSWORD UINT8_C(0x0A)
70
74#define NBT_PARSE_FAP_BYTES UINT8_C(0x0B)
75
79#define NBT_PASS_THROUGH_FETCH_DATA UINT8_C(0x0C)
80
84#define NBT_PASS_THROUGH_PUT_RESPONSE UINT8_C(0x0D)
85
89#define NBT_SELECT_APPLICATION UINT8_C(0x0E)
90
94#define NBT_SELECT_FILE_BY_ID UINT8_C(0x0F)
95
99#define NBT_UNBLOCK_PASSWORD UINT8_C(0x10)
100
104#define NBT_UPDATE_BINARY UINT8_C(0x11)
105
109#define NBT_UPDATE_FAP_BYTES_WITH_PASSWORD UINT8_C(0x12)
110
114#define NBT_UPDATE_RECURSIVE_BINARY UINT8_C(0x13)
115
119#define NBT_FAP_FILE_ID UINT16_C(0xE1AF)
120
124#define NBT_NDEF_FILE_ID UINT16_C(0xE104)
125
129#define NBT_TOTAL_FILE UINT8_C(0x07)
130
135#define NBT_FAP_ACCESS_CONDITION_LENGTH UINT8_C(0x06)
136
140#define NBT_FILE_ID_LENGTH UINT8_C(0x02)
141
145#define NBT_MAX_LE UINT16_C(0x00FF)
146
150#define NBT_MAX_LC UINT16_C(0x00FF)
151
155#define NBT_PASSWORD_ID_MASK UINT8_C(0x1F)
156
160#define NBT_SIZE_OF_FAP_FILE UINT8_C(0x2A)
161
166#define NBT_RECURSIVE_READ_INIT_OFFSET UINT16_C(0x0000)
167
172#define NBT_RECURSIVE_UPDATE_INIT_OFFSET UINT16_C(0x0000)
173
178#define NBT_RECURSIVE_READ_INIT_MSG_LEN UINT8_C(0xFF)
179
215
219typedef enum
220{
225 NBT_ACCESS_ALWAYS = UINT8_C(0x40),
226
231 NBT_ACCESS_NEVER = UINT8_C(0x00),
232
238 NBT_ACCESS_PASSWORD_PROTECTED = UINT8_C(0x80)
240
247typedef enum
248{
249 NBT_BIT_MASK_STATE_L4_EXIT = UINT16_C(0x0040),
252 NBT_BIT_MASK_STATE_L4_ENTRY = UINT16_C(0x0020),
255 NBT_BIT_MASK_STATE_FIELD_EXIT = UINT16_C(0x0010),
259 UINT16_C(0x0008),
263 UINT16_C(0x0004),
266 UINT16_C(0x0002),
269 UINT16_C(0x0001)
271
283
295ifx_status_t nbt_select_file(nbt_cmd_t *self, uint16_t file_id);
296
313 const ifx_blob_t *read_password,
314 const ifx_blob_t *write_password);
315
329 uint8_t binary_data_length);
330
345 uint32_t data_length, const uint8_t *data);
346
364 const ifx_blob_t *master_password,
365 const ifx_blob_t *new_password);
366
382 const ifx_blob_t *master_password);
383
397
419 const ifx_blob_t *master_password,
420 uint8_t new_password_id,
421 const ifx_blob_t *new_password,
422 uint16_t pwd_resp, uint16_t pwd_limit);
423
441 const ifx_blob_t *master_password,
442 uint8_t password_id);
443
458ifx_status_t nbt_get_data(nbt_cmd_t *self, uint16_t get_data_rcp);
459
472 nbt_applet_version_t *applet_version);
473
486 nbt_cmd_t *self, nbt_available_memory_t *available_memory);
487
503 const uint8_t *password_id);
504
518 const nbt_file_access_policy_t *fap_policy);
519
536 nbt_cmd_t *self, const nbt_file_access_policy_t *fap_policy,
537 const ifx_blob_t *master_password);
538
552 const ifx_blob_t *policy_bytes);
553
572 nbt_cmd_t *self, const ifx_blob_t *policy_bytes,
573 const ifx_blob_t *master_password);
574
600 uint8_t no_of_fap_policies,
601 nbt_file_access_policy_t *fap_policies);
602
620 nbt_file_access_policy_t *fap_policies);
621
641 const ifx_blob_t *master_password,
642 nbt_file_access_policy_t *fap_policies);
643
655
671 nbt_cmd_t *self, const ifx_blob_t *master_password);
672
693 ifx_apdu_response_t *response);
694
714 uint16_t *pass_through_status_word);
715
734 const ifx_apdu_response_t *response, ifx_blob_t *nfc_apdu);
735
755 ifx_apdu_t *nfc_apdu);
756
782 nbt_cmd_t *self, const ifx_apdu_response_t *pass_through_response_data,
783 ifx_apdu_response_t *response);
784
804 const ifx_blob_t *read_password);
805
841 const ifx_blob_t *read_password);
842
862
883 const ifx_blob_t *write_password,
884 ifx_blob_t *ndef_bytes);
885
903 ifx_blob_t *ndef_bytes);
904
924 const ifx_blob_t *write_password,
925 ifx_blob_t *ndef_bytes);
926
943
944#ifdef __cplusplus
945}
946
947#endif /* __cplusplus */
948#endif /* NBT_CMD_H */
uint32_t ifx_status_t
Custom return code type used by all Infineon host software libraries.
Definition ifx-error.h:91
Provides the library and module identifiers code of the library.
NBT protocol API for exchanging APDUs with NBT product.
ifx_status_t nbt_delete_password(nbt_cmd_t *self, const ifx_blob_t *master_password, uint8_t password_id)
Deletes an existing password, when the FAP file update operation is allowed with ALWAYS access condit...
ifx_status_t nbt_update_fap(nbt_cmd_t *self, const nbt_file_access_policy_t *fap_policy)
Updates file access conditions in FAP file, if FAP file is update always (not password protected).
ifx_status_t nbt_parse_fap_bytes(const ifx_blob_t *fap_bytes, uint8_t no_of_fap_policies, nbt_file_access_policy_t *fap_policies)
Parse response (APDU response type) bytes to array of nbt_file_access_policy_t type object of FAP fil...
ifx_status_t nbt_ndef_read(nbt_cmd_t *self)
Reads NDEF file with password and returns the NDEF message byte data. Method performs the select file...
ifx_status_t nbt_read_binary(nbt_cmd_t *self, uint16_t offset, uint8_t binary_data_length)
Reads the binary data from the currently selected elementary file.
ifx_status_t nbt_pass_through_decode_apdu_bytes(const ifx_apdu_response_t *response, ifx_blob_t *nfc_apdu)
Gets the pass-through NFC APDU in byte array from the response of pass_through_fetch_data() command.
ifx_status_t nbt_update_fap_bytes(nbt_cmd_t *self, const ifx_blob_t *policy_bytes)
Updates file access conditions in FAP file from policy bytes, if FAP file is update always (not passw...
nbt_access_condition
Enumeration defines the access condition of file access policy.
Definition nbt-cmd.h:220
@ NBT_ACCESS_NEVER
Access is not allowed to the file, if file is configured with NEVER access condition.
Definition nbt-cmd.h:231
@ NBT_ACCESS_ALWAYS
No password verification is required, if the file is configured with ALWAYS access condition.
Definition nbt-cmd.h:225
@ NBT_ACCESS_PASSWORD_PROTECTED
Access is allowed only after password verification, if the file is configured with PASSWORD_PROTECTED...
Definition nbt-cmd.h:238
ifx_status_t nbt_pass_through_fetch_data(nbt_cmd_t *self, ifx_apdu_response_t *response)
Issues a pass-through fetch data APDU command. This command can be issued from host devices through I...
ifx_status_t nbt_pass_through_decode_sw(const ifx_apdu_response_t *response, uint16_t *pass_through_status_word)
Gets the pass-through status word from the response of pass_through_fetch_data() command.
ifx_status_t nbt_ndef_update_with_id(nbt_cmd_t *self, uint16_t file_id, ifx_blob_t *ndef_bytes)
Updates the NDEF file with FileID. Method performs the select file with file_id and then update binar...
ifx_status_t nbt_select_application(nbt_cmd_t *self)
Selects the NBT application.
ifx_status_t nbt_read_fap_bytes(nbt_cmd_t *self)
Reads binary data (fap bytes of elementary files) from FAP file.
ifx_status_t nbt_ndef_update_with_id_password(nbt_cmd_t *self, uint16_t file_id, const ifx_blob_t *write_password, ifx_blob_t *ndef_bytes)
Updates NDEF file with FileID, 4-byte password (Optional). Method performs the select file with file_...
nbt_bit_mask_for_pass_through_status_word
Enumeration provides the bit masks to verify the status of pass-though status words.
Definition nbt-cmd.h:248
@ NBT_BIT_MASK_STATE_FIELD_ENTRY
Definition nbt-cmd.h:258
@ NBT_BIT_MASK_STATE_L4_ENTRY
Definition nbt-cmd.h:252
@ NBT_BIT_MASK_NFC_FIELD_IS_PRESENT
Definition nbt-cmd.h:268
@ NBT_BIT_MASK_STATE_L4_EXIT
Definition nbt-cmd.h:249
@ NBT_BIT_MASK_PASS_THROUGH_APDU_AVAILABLE
Definition nbt-cmd.h:262
@ NBT_BIT_MASK_LAYER_4_ACTIVE
Definition nbt-cmd.h:265
@ NBT_BIT_MASK_STATE_FIELD_EXIT
Definition nbt-cmd.h:255
ifx_status_t nbt_ndef_update(nbt_cmd_t *self, ifx_blob_t *ndef_bytes)
Updates NDEF file default ndef FileID (E104), Method performs the select file with file_id and then u...
ifx_status_t nbt_select_file(nbt_cmd_t *self, uint16_t file_id)
Selects the elementary file (EF) with the FileID.
ifx_status_t nbt_change_password(nbt_cmd_t *self, uint8_t pwd_id, const ifx_blob_t *master_password, const ifx_blob_t *new_password)
Changes an existing password with a new password. If the FAP file update operation is password protec...
ifx_status_t nbt_read_fap_bytes_with_password(nbt_cmd_t *self, const ifx_blob_t *master_password)
Reads binary data (fap bytes of elementary files) from FAP file. If FAP file is not password protecte...
ifx_status_t nbt_read_fap(nbt_cmd_t *self, nbt_file_access_policy_t *fap_policies)
Reads binary data (fap bytes of elementary files) from FAP file and store the fap bytes into nbt_file...
uint8_t nbt_access_condition_get(nbt_access_condition access_type, const uint8_t *password_id)
Get the access condition policy byte for NFC read/write and I2C read/write interface password ID as N...
ifx_status_t nbt_ndef_update_with_password(nbt_cmd_t *self, const ifx_blob_t *write_password, ifx_blob_t *ndef_bytes)
Updates NDEF file with 4-byte password (Optional) and default NDEF file Id (E104)....
ifx_status_t nbt_ndef_read_with_id_password(nbt_cmd_t *self, uint16_t file_id, const ifx_blob_t *read_password)
Reads NDEF file with password and return the NDEF message byte data. Method performs the select file ...
ifx_status_t nbt_get_data_applet_version(nbt_cmd_t *self, nbt_applet_version_t *applet_version)
Issues a get data command to retrieve the applet version information.
ifx_status_t nbt_ndef_read_with_password(nbt_cmd_t *self, const ifx_blob_t *read_password)
Reads NDEF file with password and returns the NDEF message byte data. Method performs the select file...
ifx_status_t nbt_read_fap_with_password(nbt_cmd_t *self, const ifx_blob_t *master_password, nbt_file_access_policy_t *fap_policies)
Reads binary data (access condition policy bytes of elementary files) from FAP file and store the fap...
ifx_status_t nbt_select_file_with_password(nbt_cmd_t *self, uint16_t file_id, const ifx_blob_t *read_password, const ifx_blob_t *write_password)
Selects the elementary file with FileID and read or write password. Note that the status word of the ...
ifx_status_t nbt_pass_through_decode_apdu(const ifx_apdu_response_t *response, ifx_apdu_t *nfc_apdu)
Gets the pass-through NFC APDU in APDU format from the response of pass_through_fetch_data() command.
ifx_status_t nbt_create_password(nbt_cmd_t *self, const ifx_blob_t *master_password, uint8_t new_password_id, const ifx_blob_t *new_password, uint16_t pwd_resp, uint16_t pwd_limit)
Creates a new password. If create password command is password-protected then the password to authent...
ifx_status_t nbt_authenticate_tag(nbt_cmd_t *self, const ifx_blob_t *challenge)
Issues an authenticate tag command, which generates the signature on the challenge and can be used fo...
ifx_status_t nbt_get_data(nbt_cmd_t *self, uint16_t get_data_rcp)
Issues a get data command to retrieve the NBT application specific information like applet version an...
ifx_status_t nbt_ndef_read_with_id(nbt_cmd_t *self, uint16_t file_id)
Reads NDEF file and return the NDEF message byte data. Method performs the select file and then read ...
ifx_status_t nbt_update_fap_with_password(nbt_cmd_t *self, const nbt_file_access_policy_t *fap_policy, const ifx_blob_t *master_password)
Updates file access conditions in FAP file. when FAP file is password protected(optional)....
ifx_status_t nbt_update_fap_bytes_with_password(nbt_cmd_t *self, const ifx_blob_t *policy_bytes, const ifx_blob_t *master_password)
Updates file access conditions in FAP file from policy bytes. When FAP file is password protected (op...
ifx_status_t nbt_unblock_password(nbt_cmd_t *self, uint8_t pwd_id, const ifx_blob_t *master_password)
Unblocks the password, which is in blocked state because wrong password limit exceeds.
ifx_status_t nbt_update_binary(nbt_cmd_t *self, uint16_t offset, uint32_t data_length, const uint8_t *data)
Updates the binary data into the currently selected elementary file.
ifx_status_t nbt_get_data_available_memory(nbt_cmd_t *self, nbt_available_memory_t *available_memory)
Issues a get data command to retrieve the available memory.
ifx_status_t nbt_pass_through_put_response(nbt_cmd_t *self, const ifx_apdu_response_t *pass_through_response_data, ifx_apdu_response_t *response)
Sends the response to pass-through fetch data command, forwarding the response over the NFC interface...
Response parser for apdu-nbt commands.
Data storage struct for APDU response information.
Definition ifx-apdu.h:130
Data storage for APDU fields.
Definition ifx-apdu.h:89
Data storage for data and data length where both are required as parameters.
Definition ifx-utils.h:189
Structure for the applet version.
Structure for the available memory.
Generic NBT command set structure for building and performing NBT commands.
Definition nbt-apdu.h:76
Store the file access condition for both NFC and I2C (read/write operation) interface with FileID.
Definition nbt-cmd.h:185
uint8_t i2c_read_access_condition
I2C read access condition (always, never access condition, and password protected with password ID)
Definition nbt-cmd.h:195
uint16_t file_id
2 bytes of FileID
Definition nbt-cmd.h:189
uint8_t nfc_write_access_condition
NFC write access condition (always, never access condition, and password protected with password ID)
Definition nbt-cmd.h:213
uint8_t nfc_read_access_condition
NFC read access condition (always, never access condition, and password protected with password ID)
Definition nbt-cmd.h:207
uint8_t i2c_write_access_condition
I2C write access condition (always, never access condition, and password protected with password ID)
Definition nbt-cmd.h:201