adapter: Bypass the target layer
[platform/upstream/neard.git] / include / tag.h
1 /*
2  *
3  *  neard - Near Field Communication manager
4  *
5  *  Copyright (C) 2011  Intel Corporation. All rights reserved.
6  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #ifndef __NEAR_TAG_H
23 #define __NEAR_TAG_H
24
25 #include <stdint.h>
26
27 #include <glib.h>
28
29 #define NFC_HEADER_SIZE 1
30
31 enum near_tag_sub_type {
32         NEAR_TAG_NFC_T2_MIFARE_ULTRALIGHT = 0,  // SAK 0x00
33         NEAR_TAG_NFC_T2_MIFARE_CLASSIC_1K,      // SAK:0x08
34         NEAR_TAG_NFC_T2_MIFARE_MINI,            // SAK 0x09
35         NEAR_TAG_NFC_T2_MIFARE_CLASSIC_4K,      // SAK:0x18
36         NEAR_TAG_NFC_T2_MIFARE_DESFIRE,         // SAK:0x20
37         NEAR_TAG_NFC_T2_JCOP30,                 // SAK:0x28
38         NEAR_TAG_NFC_T2_MIFARE_4K_EMUL,         // SAK:0x38
39         NEAR_TAG_NFC_T2_MIFARE_1K_INFINEON,     // SAK:0x88
40         NEAR_TAG_NFC_T2_MPCOS,                  // SAK:0x98
41         NEAR_TAG_NFC_SUBTYPE_UNKNOWN = 0xFF
42 };
43
44 enum near_tag_memory_layout {
45         NEAR_TAG_MEMORY_STATIC = 0,
46         NEAR_TAG_MEMORY_DYNAMIC,
47         NEAR_TAG_MEMORY_OTHER,
48         NEAR_TAG_MEMORY_UNKNOWN = 0xFF
49 };
50
51 typedef void (*near_tag_io_cb) (uint32_t adapter_idx, uint32_t target_idx,
52                                                                 int status);
53
54 struct near_ndef_message;
55
56 #define NEAR_TAG_PRIORITY_LOW      -100
57 #define NEAR_TAG_PRIORITY_DEFAULT     0
58 #define NEAR_TAG_PRIORITY_HIGH      100
59
60 struct near_tag_driver {
61         uint16_t type;
62         int priority;
63
64         int (*read_tag)(uint32_t adapter_idx, uint32_t target_idx,
65                                                 near_tag_io_cb cb);
66         int (*add_ndef)(uint32_t adapter_idx, uint32_t target_idx,
67                                         struct near_ndef_message *ndef,
68                                         near_tag_io_cb cb);
69         int (*check_presence)(uint32_t adapter_idx, uint32_t target_idx,
70                                                 near_tag_io_cb cb);
71 };
72
73 struct near_tag;
74
75 struct near_tag *near_tag_get_tag(uint32_t adapter_idx, uint32_t target_idx);
76 int near_tag_set_uid(struct near_tag *tag, uint8_t *uid, size_t uid_length);
77 int near_tag_set_ro(struct near_tag *tag, near_bool_t readonly);
78 near_bool_t near_tag_get_ro(struct near_tag *tag);
79 int near_tag_add_data(uint32_t adapter_idx, uint32_t target_idx,
80                         uint8_t *data, size_t data_length);
81 enum near_tag_sub_type near_tag_get_subtype(uint32_t adapter_idx,
82                                         uint32_t target_idx);
83 uint8_t *near_tag_get_nfcid(uint32_t adapter_idx, uint32_t target_idx,
84                                         uint8_t *nfcid_len);
85 uint8_t *near_tag_get_data(struct near_tag *tag, size_t *data_length);
86 uint32_t near_tag_get_adapter_idx(struct near_tag *tag);
87 uint32_t near_tag_get_target_idx(struct near_tag *tag);
88 int near_tag_add_ndef(struct near_tag *tag, uint8_t *ndef_data, size_t ndef_length);
89 int near_tag_driver_register(struct near_tag_driver *driver);
90 void near_tag_driver_unregister(struct near_tag_driver *driver);
91 void near_tag_set_memory_layout(struct near_tag *tag,
92                                         enum near_tag_memory_layout);
93 enum near_tag_memory_layout near_tag_get_memory_layout(struct near_tag *tag);
94 void near_tag_set_max_ndef_size(struct near_tag *tag, uint16_t size);
95 uint16_t near_tag_get_max_ndef_size(struct near_tag *tag);
96 void near_tag_set_c_apdu_max_size(struct near_tag *tag, uint16_t size);
97 uint16_t near_tag_get_c_apdu_max_size(struct near_tag *tag);
98 void near_tag_set_idm(struct near_tag *tag, uint8_t *idm, uint8_t len);
99 uint8_t *near_tag_get_idm(struct near_tag *tag, uint8_t *len);
100 void near_tag_set_attr_block(struct near_tag *tag, uint8_t *attr, uint8_t len);
101 uint8_t *near_tag_get_attr_block(struct near_tag *tag, uint8_t *len);
102
103 #endif