1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef DEVICE_NFC_NFC_TAG_H_
6#define DEVICE_NFC_NFC_TAG_H_
7
8#include "device/nfc/nfc_tag_technology.h"
9
10namespace device {
11
12// NfcTag represents a remote NFC tag. An NFC tag is a passive NFC device,
13// powered by the NFC field of the local adapter while it is in range. Tags
14// can come in many forms, such as stickers, key fobs, or even embedded in a
15// more sofisticated device.
16//
17// Tags can have a wide range of capabilities. Simple tags just offer
18// read/write semantics, and contain some one time programmable areas to make
19// read-only. More complex tags offer math operations and per-sector access
20// control and authentication. The most sophisticated tags contain operating
21// environments allowing complex interactions with the code executing on the
22// tag.
23//
24// The NfcTag class facilitates possible interactions with a tag. The most
25// common usage of a tag is to exchange NDEF messages, but different kinds of
26// I/O can be performed using the NfcTagTechnology classes.
27class NfcTag {
28 public:
29  // NFC tag types.
30  enum TagType {
31    kTagType1,
32    kTagType2,
33    kTagType3,
34    kTagType4,
35    kTagTypeUnknown,
36  };
37
38  // NFC protocols that a tag can support. A tag will usually support only one
39  // of these.
40  enum Protocol {
41    kProtocolFelica,
42    kProtocolIsoDep,
43    kProtocolJewel,
44    kProtocolMifare,
45    kProtocolNfcDep,
46    kProtocolUnknown
47  };
48
49  // Interface for observing changes from NFC tags.
50  class Observer {
51   public:
52    virtual ~Observer() {}
53
54    // Called when the tag type has been determined.
55    virtual void TagTypeChanged(NfcTag* tag, TagType type) {}
56
57    // Called when the write access to the tag has been determined or changed.
58    virtual void TagWritePermissionChanged(NfcTag* tag, bool read_only) {}
59
60    // Called when the underlying NFC protocol has been determined.
61    virtual void TagSupportedProtocolChanged(NfcTag* tag, Protocol protocol) {}
62
63    // Called when all initial values of the tag properties have been received
64    // from the remote tag and |tag| is ready to use.
65    virtual void TagReady(NfcTag* tag) {}
66  };
67
68  virtual ~NfcTag();
69
70  // Adds and removes observers for events on this NFC tag. If monitoring
71  // multiple tags, check the |tag| parameter of observer methods to determine
72  // which tag is issuing the event.
73  virtual void AddObserver(Observer* observer) = 0;
74  virtual void RemoveObserver(Observer* observer) = 0;
75
76  // Returns the unique identifier assigned to this tag.
77  virtual std::string GetIdentifier() const = 0;
78
79  // Returns the current tag's NFC forum specified "type".
80  virtual TagType GetType() const = 0;
81
82  // Returns true, if this tag is read-only and cannot be written to.
83  virtual bool IsReadOnly() const = 0;
84
85  // Returns the current tag's supported NFC protocol.
86  virtual Protocol GetSupportedProtocol() const = 0;
87
88  // Returns a bitmask of the tag I/O technologies supported by this tag.
89  virtual NfcTagTechnology::TechnologyTypeMask
90      GetSupportedTechnologies() const = 0;
91
92  // Returns true, if all tag properties have been received from the remote tag
93  // and this object is ready to use.
94  virtual bool IsReady() const = 0;
95
96  // Returns a pointer to the NDEF technology object that allows I/O on NDEF
97  // records. If NDEF is not supported by this tag, operations that are
98  // performed on the returned instance may not succeed. Users can determine
99  // support by calling NfcTagTechnology::IsSupportedByTag. The returned
100  // instance is owned by this tag.
101  virtual NfcNdefTagTechnology* GetNdefTagTechnology() = 0;
102
103 protected:
104  NfcTag();
105
106 private:
107  DISALLOW_COPY_AND_ASSIGN(NfcTag);
108};
109
110}  // namespace device
111
112#endif  // DEVICE_NFC_NFC_TAG_H_
113