Parser for Connection Handover records

This library provides a parser for Connection Handover records that can be used to decode NDEF records generated by the Connection Handover messages and records library. The output of this library is a descriptor with the same content as the one that would be used to encode the data with the Connection Handover messages and records library.

This library should be used together with the Parser for messages and records in the following way:

  1. Obtain the NDEF message descriptor by parsing raw NDEF message data with the Parser for messages and records.

  2. Search for Connection NDEF records inside the NDEF message descriptor.

  3. If there are any such NDEF records, use this library to parse them and print their content.

  4. The Connection Handover Records contains the local NDEF message with the Connection Handover Local NDEF Records, use this library to first check their type and next parse them and print their content.

The following code sample demonstrates how to use this module:

static void ndef_ch_rec_analyze(const struct nfc_ndef_record_desc *ndef_rec_desc)
{
	int err;
	uint8_t hs_buf[NFC_NDEF_REC_PARSER_BUFF_SIZE];
	uint32_t hs_buf_len = sizeof(hs_buf);
	uint8_t ac_buf[NFC_NDEF_REC_PARSER_BUFF_SIZE];
	uint32_t ac_buf_len = sizeof(ac_buf);
	struct nfc_ndef_ch_rec *ch_rec;
	struct nfc_ndef_ch_ac_rec *ac_rec;

	err = nfc_ndef_ch_rec_parse(ndef_rec_desc, hs_buf, &hs_buf_len);
	if (err) {
		printk("Error during parsing Handover Select record: %d\n",
		       err);
		return;
	}

	ch_rec = (struct nfc_ndef_ch_rec *)hs_buf;

	printk("Handover Select Record payload");

	nfc_ndef_ch_rec_printout(ch_rec);

	for (size_t i = 0; i < ch_rec->local_records->record_count; i++) {
		if (nfc_ndef_ch_ac_rec_check(ch_rec->local_records->record[i])) {
			err = nfc_ndef_ch_ac_rec_parse(ch_rec->local_records->record[i],
						       ac_buf, &ac_buf_len);
			if (err) {
				printk("Error during parsing AC record: %d\n",
				       err);
				return;
			}

			ac_rec = (struct nfc_ndef_ch_ac_rec *)ac_buf;

			nfc_ndef_ac_rec_printout(ac_rec);
		}
	}
}

This library is used in the NFC: Tag reader sample.

API documentation

Header file: include/nfc/ndef/ch_rec_parser.h
Source file: subsys/nfc/ndef/ch_rec_parser.c
group nfc_ndef_ch_record_parser

Parser for NDEF Connection Handover Records.

Records

Enums

enum nfc_ndef_ch_rec_type

NFC NDEF Connection Handover Record type.

Values:

enumerator NFC_NDEF_CH_REC_TYPE_HANDOVER_SELECT

NFC NDEF Connection Handover Select Record.

enumerator NFC_NDEF_CH_REC_TYPE_HANDOVER_REQUEST

NFC NDEF Connection Handover Request Record.

enumerator NFC_NDEF_CH_REC_TYPE_HANDOVER_INITIATE

NFC NDEF Connection Handover Initiate Record.

enumerator NFC_NDEF_CH_REC_TYPE_HANDOVER_MEDIATION

NFC NDEF Connection Handover Mediation Record.

Functions

bool nfc_ndef_ch_ac_rec_check(const struct nfc_ndef_record_desc *rec_desc)

Check if an NDEF Record is the Alternative Carrier Record.

Parameters:
  • rec_desc[in] General NDEF Record descriptor.

Return values:
  • true – If the NDEF Record Type is Alternative Carrier Record.

  • false – If the NDEF Record Type is different.

bool nfc_ndef_ch_cr_rec_check(const struct nfc_ndef_record_desc *rec_desc)

Check if an NDEF Record is the Handover Collision Resolution Record.

Parameters:
  • rec_desc[in] General NDEF Record descriptor.

Return values:
  • true – If the NDEF Record Type is Handover Collision Resolution Record.

  • false – If the NDEF Record Type is different.

bool nfc_ndef_ch_hc_rec_check(const struct nfc_ndef_record_desc *rec_desc)

Check if an NDEF Record is the Handover Carrier Record.

Parameters:
  • rec_desc[in] General NDEF Record descriptor.

Return values:
  • true – If the NDEF Record Type is the Handover Carrier Record.

  • false – If the NDEF Record Type is different.

bool nfc_ndef_ch_rec_check(const struct nfc_ndef_record_desc *rec_desc, enum nfc_ndef_ch_rec_type rec_type)

Check if an NDEF Record is the fallowing Handover Connection Record:

  • Handover Select Record

  • Handover Request Record

  • Handover Mediation Record

  • Handover Initiate Record

Parameters:
  • rec_desc[in] General NDEF Record descriptor.

  • rec_type[in] Connection Handover Record type to check.

Return values:
  • true – If the NDEF Record Type is rec_type Record.

  • false – If the NDEF Record Type is different.

int nfc_ndef_ch_rec_parse(const struct nfc_ndef_record_desc *rec_desc, uint8_t *result_buf, uint32_t *result_buf_len)

Parse the fallowing NDEF Connection Handover Records:

  • Handover Select Record

  • Handover Request Record

  • Handover Mediation Record

  • Handover Initiate Record

This function only parses NDEF Record descriptors with Connection Handover Type. Parsing results are stored in the Handover Connection Record descriptor (nfc_ndef_ch_rec).

Parameters:
  • rec_desc[in] General NDEF Record descriptor.

  • result_buf[out] The buffer that will be used to hold the Connection Hendover Record descriptor. After parsing is completed successfully, the first address in the buffer is filled by the NDEF Record descriptor (nfc_ndef_ch_rec), which provides a full description of the parsed NDEF Record.

  • result_buf_len[inout] As input: size of the result_buf buffer As output: size of the reserved (used) part of the result_buf buffer.

Return values:

0 – If the operation was successful. Otherwise, a (negative) error code is returned.

int nfc_ndef_ch_ac_rec_parse(const struct nfc_ndef_record_desc *rec_desc, uint8_t *result_buf, uint32_t *result_buf_len)

Parse an NDEF Alternative Carrier Record.

This function only parses NDEF Record descriptors with Alternative Carrier Record Type. Parsing results are stored in the Alternative Carrier Record descriptor (nfc_ndef_ch_ac_rec).

Parameters:
  • rec_desc[in] General NDEF Record descriptor.

  • result_buf[out] The buffer that will be used to hold the Alternative Carrier Record descriptor. After parsing is completed successfully, the first address in the buffer is filled by the NDEF Record descriptor (nfc_ndef_ch_ac_rec), which provides a full description of the parsed NDEF Record.

  • result_buf_len[inout] As input: size of the result_buf buffer As output: size of the reserved (used) part of the result_buf buffer.

Return values:

0 – If the operation was successful. Otherwise, a (negative) error code is returned.

int nfc_ndef_ch_cr_rec_parse(const struct nfc_ndef_record_desc *rec_desc, struct nfc_ndef_ch_cr_rec *cr_rec)

Parse an NDEF Collision Resolution Record.

This function only parses NDEF Record descriptors with Collision Resolution Record Type. Parsing results are stored in the Collision Resolution Record descriptor (nfc_ndef_ch_cr_rec).

Parameters:
  • rec_desc[in] General NDEF Record descriptor.

  • cr_rec[out] Parsed Collision Resolution Record descriptor. After parsing is completed successfully it is filled with Collision Resolution parsed data.

Return values:

0 – If the operation was successful. Otherwise, a (negative) error code is returned.

int nfc_ndef_ch_hc_rec_parse(const struct nfc_ndef_record_desc *rec_desc, uint8_t *result_buf, uint32_t *result_buf_len)

Parse an NDEF Handover Carrier Record.

This function only parses NDEF Record descriptors with Handover Carrier Record Type. Parsing results are stored in the Handover Carrier Record descriptor (nfc_ndef_ch_hc_rec).

Parameters:
  • rec_desc[in] General NDEF Record descriptor.

  • result_buf[out] The buffer that will be used to hold the Handover Carrier Record descriptor. After parsing is completed successfully, the first address in the buffer is filled by the NDEF Record descriptor (nfc_ndef_ch_hc_rec), which provides a full description of the parsed NDEF Record.

  • result_buf_len[inout] As input: size of the result_buf buffer As output: size of the reserved (used) part of the result_buf buffer.

Return values:

0 – If the operation was successful. Otherwise, a (negative) error code is returned.

void nfc_ndef_ch_rec_printout(const struct nfc_ndef_ch_rec *ch_rec)

Print the parsed contents of the fallowing Connection Handover Records:

  • Handover Select Record

  • Handover Request Record

  • Handover Mediation Record

  • Handover Initiate Record

Parameters:
  • ch_rec[in] Descriptor of the Connection Handover Record that should be printed.

void nfc_ndef_ac_rec_printout(const struct nfc_ndef_ch_ac_rec *ac_rec)

Print the parsed contents of an NDEF Alternative Carrier Record.

Parameters:
  • ac_rec[in] Descriptor of the Alternative Carrier Record that should be printed.

void nfc_ndef_hc_rec_printout(const struct nfc_ndef_ch_hc_rec *hc_rec)

Print the parsed contents of an NDEF Handover Carrier Record.

Parameters:
  • hc_rec[in] Descriptor of the Handover Carrier Record that should be printed.

void nfc_ndef_cr_rec_printout(const struct nfc_ndef_ch_cr_rec *cr_rec)

Print the parsed contents of an NDEF Collision Resolution Record.

Parameters:
  • cr_rec[in] Descriptor of the Collision Resolution Record that should be printed.