Tizen 2.0 Release
[framework/connectivity/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 #define NFC_MAX_NFCID1_LEN 10
32
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
44 };
45
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
51 };
52
53 typedef void (*near_tag_io_cb) (uint32_t adapter_idx, uint32_t target_idx,
54                                                                 int status);
55
56 struct near_ndef_message;
57
58 #define NEAR_TAG_PRIORITY_LOW      -100
59 #define NEAR_TAG_PRIORITY_DEFAULT     0
60 #define NEAR_TAG_PRIORITY_HIGH      100
61
62 struct near_tag_driver {
63         uint16_t type;
64         int priority;
65
66         int (*read)(uint32_t adapter_idx, uint32_t target_idx,
67                                                 near_tag_io_cb cb);
68         int (*write)(uint32_t adapter_idx, uint32_t target_idx,
69                                         struct near_ndef_message *ndef,
70                                         near_tag_io_cb cb);
71         int (*check_presence)(uint32_t adapter_idx, uint32_t target_idx,
72                                                 near_tag_io_cb cb);
73         int (*format)(uint32_t adapter_idx, uint32_t target_idx,
74                                         near_tag_io_cb cb);
75 };
76
77 struct near_tag;
78
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,
88                                         uint32_t target_idx);
89 uint8_t *near_tag_get_nfcid(uint32_t adapter_idx, uint32_t target_idx,
90                                         uint8_t *nfcid_len);
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);
112
113 #endif