3 * neard - Near Field Communication manager
5 * Copyright (C) 2011 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #define NFC_HEADER_SIZE 1
31 #define NFC_MAX_NFCID1_LEN 10
33 enum near_tag_sub_type {
34 NEAR_TAG_NFC_T2_MIFARE_ULTRALIGHT = 0, // SAK 0x00
35 NEAR_TAG_NFC_T2_MIFARE_CLASSIC_1K, // SAK:0x08
36 NEAR_TAG_NFC_T2_MIFARE_MINI, // SAK 0x09
37 NEAR_TAG_NFC_T2_MIFARE_CLASSIC_4K, // SAK:0x18
38 NEAR_TAG_NFC_T2_MIFARE_DESFIRE, // SAK:0x20
39 NEAR_TAG_NFC_T2_JCOP30, // SAK:0x28
40 NEAR_TAG_NFC_T2_MIFARE_4K_EMUL, // SAK:0x38
41 NEAR_TAG_NFC_T2_MIFARE_1K_INFINEON, // SAK:0x88
42 NEAR_TAG_NFC_T2_MPCOS, // SAK:0x98
43 NEAR_TAG_NFC_SUBTYPE_UNKNOWN = 0xFF
46 enum near_tag_memory_layout {
47 NEAR_TAG_MEMORY_STATIC = 0,
48 NEAR_TAG_MEMORY_DYNAMIC,
49 NEAR_TAG_MEMORY_OTHER,
50 NEAR_TAG_MEMORY_UNKNOWN = 0xFF
53 typedef void (*near_tag_io_cb) (uint32_t adapter_idx, uint32_t target_idx,
56 struct near_ndef_message;
58 #define NEAR_TAG_PRIORITY_LOW -100
59 #define NEAR_TAG_PRIORITY_DEFAULT 0
60 #define NEAR_TAG_PRIORITY_HIGH 100
62 struct near_tag_driver {
66 int (*read)(uint32_t adapter_idx, uint32_t target_idx,
68 int (*write)(uint32_t adapter_idx, uint32_t target_idx,
69 struct near_ndef_message *ndef,
71 int (*check_presence)(uint32_t adapter_idx, uint32_t target_idx,
73 int (*format)(uint32_t adapter_idx, uint32_t target_idx,
79 struct near_tag *near_tag_get_tag(uint32_t adapter_idx, uint32_t target_idx);
80 void near_tag_set_ro(struct near_tag *tag, near_bool_t readonly);
81 void near_tag_set_blank(struct near_tag *tag, near_bool_t blank);
82 near_bool_t near_tag_get_blank(struct near_tag *tag);
83 int near_tag_add_data(uint32_t adapter_idx, uint32_t target_idx,
84 uint8_t *data, size_t data_length);
85 int near_tag_add_records(struct near_tag *tag, GList *records,
86 near_tag_io_cb cb, int status);
87 enum near_tag_sub_type near_tag_get_subtype(uint32_t adapter_idx,
89 uint8_t *near_tag_get_nfcid(uint32_t adapter_idx, uint32_t target_idx,
91 int near_tag_set_nfcid(uint32_t adapter_idx, uint32_t target_idx,
92 uint8_t *nfcid, size_t nfcid_len);
93 uint8_t *near_tag_get_data(struct near_tag *tag, size_t *data_length);
94 uint32_t near_tag_get_adapter_idx(struct near_tag *tag);
95 uint32_t near_tag_get_target_idx(struct near_tag *tag);
96 int near_tag_add_ndef(struct near_tag *tag, uint8_t *ndef_data, size_t ndef_length);
97 int near_tag_driver_register(struct near_tag_driver *driver);
98 void near_tag_driver_unregister(struct near_tag_driver *driver);
99 void near_tag_set_memory_layout(struct near_tag *tag,
100 enum near_tag_memory_layout);
101 enum near_tag_memory_layout near_tag_get_memory_layout(struct near_tag *tag);
102 void near_tag_set_max_ndef_size(struct near_tag *tag, uint16_t size);
103 uint16_t near_tag_get_max_ndef_size(struct near_tag *tag);
104 void near_tag_set_c_apdu_max_size(struct near_tag *tag, uint16_t size);
105 uint16_t near_tag_get_c_apdu_max_size(struct near_tag *tag);
106 void near_tag_set_idm(struct near_tag *tag, uint8_t *idm, uint8_t len);
107 uint8_t *near_tag_get_idm(struct near_tag *tag, uint8_t *len);
108 void near_tag_set_attr_block(struct near_tag *tag, uint8_t *attr, uint8_t len);
109 uint8_t *near_tag_get_attr_block(struct near_tag *tag, uint8_t *len);
110 void near_tag_set_ic_type(struct near_tag *tag, uint8_t ic_type);
111 uint8_t near_tag_get_ic_type(struct near_tag *tag);