w3c / web-nfc

Web NFC
https://w3c.github.io/web-nfc/
Other
313 stars 69 forks source link

Support TNEP: Poller Device + new record types #559

Open markus-becker-tridonic-com opened 4 years ago

markus-becker-tridonic-com commented 4 years ago

From https://nfc-forum.org/product/nfc-forum-tag-ndef-exchange-protocol-tnep-candidate-specification-1-0/:

The TNEP 1.0 Technical Specification supports the bi-directional exchange of NDEF messages based on the communication protocol used by the NFC Forum Tag devices of Type 2, 3, 4 and 5. The new TNEP protocol offers a simple protocol for NFC IoT devices to exchange data between an NFC enabled phone and the IoT Device. For example, this protocol can be used to configure and read smart meter devices, to control the thermostatic radiator valve or to configure the lightning device in your smart home.

Would be nice to support this with web-nfc and/or a library on top of web-nfc.

Devices based on Nordic chips implement TNEP tag-wise: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/include/nfc/tnep/tnep.html

kenchris commented 4 years ago

Is this a replacement for SNEP which is being deprecated in Android?

NFC Simple Exchange Protocol

The SNEP is a simple protocol for doing peer-to-peer (P2P) NDEF transfers. It is not supported by CoreNFC (iOS) and it is being deprecated on Android (where is branded Android Beam) due to security issues).

markus-becker-tridonic-com commented 4 years ago

I do not know much more than what is written in https://futureiot.tech/nfc-forum-releases-new-specifications-to-improve-connectivity-of-iot-devices/.

zolkis commented 4 years ago

Stack explained here: https://nfc-forum.org/our-work/specification-releases/specifications/#specs image

kenchris commented 4 years ago

https://www.businesswire.com/news/home/20190612005060/en/NFC-Forum-Enhances-Connectivity-IoT-Devices-New

I guess we need some native (Android etc) support before we can consider supporting this?

zolkis commented 4 years ago

We have not exposed SNEP directly, so I wonder do we have to expose TNEP directly, or can it be encapsulated? What TNEP specific interactions or options need to be exposed to web pages?

And yes, a prerequisite is Android support for this.

markus-becker-tridonic-com commented 4 years ago

https://www.businesswire.com/news/home/20190612005060/en/NFC-Forum-Enhances-Connectivity-IoT-Devices-New

I guess we need some native (Android etc) support before we can consider supporting this?

Isn't it layered on top of NDEF without the need of P2P? According to the stack it seems below NDEF.

The Nordic library https://github.com/NordicPlayground/fw-nrfconnect-nrf/blob/master/subsys/nfc/tnep/tag.c seems to be layered on top of NDEF.

kenchris commented 4 years ago

From my quick look at this, this looks like an official HCE (host card emulation) API, so it will probably need something like that. I think it is great with an official HCE API but it requires Android moving to this new API or us to emulate it ontop of what is already there.

This probably requires a lot of research

Update: One part of it TNEP Tag Device act similar to a NDEF version of HCE, where as TNEP Polling Device is more similar to how an active device (say Android phone) works today.

There are a few extra records that we will need to support.

kenchris commented 4 years ago

New records to support: https://nfc-forum.org/our-work/specification-releases/specifications/nfc-forum-assigned-numbers-register/

image

beaufortfrancois commented 4 years ago

What is the platform support of those records?

kenchris commented 4 years ago

I don't think you need any platform support for those as long as you can write well-known records, like smart poster without native support - can we do that?

This here basically shows what they contain in the payload:

image

You can create these record on Android:

image

Just choose Well known and manually construct the payload

kenchris commented 4 years ago

As far as I understand - only Tag Type 2, 3, 4, 5 have been updated to support TNEP:

image

I assume this means that any TNEP Polling Device can only read these tag types (not non-standard like Mifare, or NFC Forum Type 1) and Android HCE (which emulates Type 4)

kenchris commented 4 years ago

From reading source code:

#define NFC_TNEP_VERSION 0x10
enum nfc_tnep_comm_mode {
    /** Single response communication mode */
    NFC_TNEP_COMM_MODE_SINGLE_RESPONSE,
    /** Service specific communication mode */
    NFC_TNEP_COMM_MODE_SERVICE_SPECYFIC = 0xFE
};
/** Maximum Service Waiting Time. */
#define NFC_TNEP_TAG_MAX_WAIT_TIME 63
/** Maximum Waiting Time extension. */
#define NFC_TNEP_TAG_MAX_N_WAIT_TIME 15
enum nfc_tnep_status_value {
    /** Success */
    NFC_TNEP_STATUS_SUCCESS,
    /** TNEP protocol error */
    NFC_TNEP_STATUS_PROTOCOL_ERROR,
    /** First service error code. */
    NFC_TNEP_STATUS_SERVICE_ERROR_BEGIN = 0x80,
    /** Last service error code. */
    NFC_TNEP_STATUS_SERVICE_ERROR_END = 0xFE,
};

Service Parameters Record "Tp" payload

byte: version (0x10) byte: uri length in bytes uri length bytes: uri byte: communication_mode (0x01 single response, 0xFE service specific) byte: min_time (0...63 - converted to time units using protocol specified formula) byte: max_time_ext (0...15 repetitions) 2 bytes (Big Endian): max_size in bytes

TNEP status "Te" payload

byte: status (0x01 success, 0x02 protocol error, 0x80...0xFE service specific errors)

Service Select "Ts" payload

byte: uri length in bytes uri length bytes: uri

kenchris commented 4 years ago

It also seems like we could implement the TNEP Tag Device API on top of Android HCE (Host Card Emulation, Type 4 Tag emulation + ISO-DEP / APDU). We considered this already as a replacement for SNEP (NDEF push).

It is exactly how it is accomplished on the Nordic devices, if you check the Tag Device demo:

https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.sdk5.v12.2.0%2Fgroup__nfc__t4t__lib.html

kenchris commented 4 years ago

Split the Tag Device part out into https://github.com/w3c/web-nfc/issues/563

markus-becker-tridonic-com commented 4 years ago

Would it be possible to test TNEP with WebNFC right now using external type records or would one have to wait until Tp, Te and Ts have been added to the specification and implementation?

kenchris commented 4 years ago

@markus-becker-tridonic-com you would have to wait until that is added yes.

kenchris commented 4 years ago

Did some exploration here: https://github.com/w3c/web-nfc/issues/567