static

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2023 License: LGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package static provides the implementation of a static software-based NFC Forum Type 4 Tag which holds a NDEF Message.

See https://gitlab.com/snippets/18718 for an example on how to use it together with the `swtag` driver.

Index

Examples

Constants

View Source
const (
	NFCForumMajorVersion = 2
	NFCForumMinorVersion = 0
)

Version of the specification implemented by this tag

View Source
const NDEFAPPLICATION = uint64(0xD2760000850101)

NDEFAPPLICATION is the name for the NDEF Application.

View Source
const NDEFFileAddress = uint16(0x8888)

NDEFFileAddress Address in which the NDEF File is stored. It is initialized to a default of 0x8888.

The valid ranges are 0x0001-E101,0xE104-3EFF, 0x4000-FFFE. Values 0x0000, 0xE102, 0xE103, 0x3F00, 0x3FFF are reserved. 0xFFFF is RFU.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tag

type Tag struct {
	// contains filtered or unexported fields
}

Tag implements a static NFC Type 4 Tags which holds a NDEFMessage.

It called static because the message that is returned is always the same regardless of how many times it is Read.

Since the static Tag implements the `tags.Tag` interface, this tag can be used with the `nfctype4/drivers/swtag`. Please check the `swtag` module documentation for more information on the different uses.

Please use static.New() to create tags, or remember to do a Tag.Initialize() as otherwise tags will refuse to work.

Example (Read)
// Let's create a NDEF Message first
payload := generic.Payload{
	Payload: []byte("\x01test.payload"),
}
ndefMessage := ndef.NewMessage(
	ndef.NFCForumWellKnownType, "U", "",
	&payload)

// Store this message in a static tag
tag := New()
err := tag.SetMessage(ndefMessage)
if err != nil {
	fmt.Println(err)
}

// To read our tag we need a nfctype4.Device configured
// with the swtag driver. The driver is connected to
// our Tag.
driver := &swtag.Driver{
	Tag: tag,
}

device := nfctype4.New(driver)

// Now we can read the message using the NFC Type 4 Tag
// operation specification
receivedMessage, err := device.Read()
if err != nil {
	fmt.Println(err)
} else {
	fmt.Println(receivedMessage)
}
Output:

urn:nfc:wkt:U:http://www.test.payload
Example (Write)
// Store this message in a static tag
tag := New()

// To read/write our tag we need a nfctype4.Device configured
// with the swtag driver. The driver is connected to
// our Tag.
driver := &swtag.Driver{
	Tag: tag,
}

device := nfctype4.New(driver)

// Now we can update the message using the NFC Type 4 Tag
// operation specification with a new message
ndefMessage := ndef.NewTextMessage("This is a new message", "en")
err := device.Update(ndefMessage)
if err != nil {
	fmt.Println(err)
	return
}

// Finally let's peek at the message stored in the tag
tagMessage := tag.GetMessage()
fmt.Println(tagMessage)
Output:

urn:nfc:wkt:T:This is a new message

func New

func New() *Tag

New returns a new *Tag in Initialized state (empty)

func (*Tag) Command

func (tag *Tag) Command(capdu *apdu.CAPDU) *apdu.RAPDU

Command lets the Software tag receive Commands (CAPDUs) and provide respones (RAPDUs) according to each command. It is the heart of the behaviour of a NFC Type 4 Tag.

func (*Tag) GetMessage

func (tag *Tag) GetMessage() *ndef.Message

GetMessage allows to retrieve the NDEF message stored in the tag. It returns nil when there is nothing stored.

func (*Tag) Initialize

func (tag *Tag) Initialize()

Initialize resets a Tag to an initialized state (empty) It will drop the memory contents if they previously existed and de-select any files.

func (*Tag) SetMessage

func (tag *Tag) SetMessage(m *ndef.Message) error

SetMessage programs the NDEF message for this tag. It returns an error if the m.Marshal() does (which would indicate and invalid message).

Notes

Bugs

  • Tag is not super-strict with the error responses in case of unexpected Commands.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL