blob: 72028f48277eb1950a370ceed0c5970b89b3c0db [file] [log] [blame]
Benoit Gobye44be612013-10-10 17:39:24 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ANDROID_NFC_TAG_HAL_INTERFACE_H
18#define ANDROID_NFC_TAG_HAL_INTERFACE_H
19
20#include <stdint.h>
21
22#include <hardware/hardware.h>
23
24__BEGIN_DECLS
25
26/*
27 * HAL for programmable NFC tags.
28 *
29 */
30
31#define NFC_TAG_HARDWARE_MODULE_ID "nfc_tag"
32#define NFC_TAG_ID "tag"
33
34typedef struct nfc_tag_module_t {
35 struct hw_module_t common;
36} nfc_tag_module_t;
37
38typedef struct nfc_tag_device {
39 struct hw_device_t common;
40
41 /**
42 * Initialize the NFC tag.
43 *
44 * The driver must:
45 * * Set the static lock bytes to read only
46 * * Configure the Capability Container to disable write acess
47 * eg: 0xE1 0x10 <size> 0x0F
48 *
49 * This function is called once before any calls to setContent().
50 *
51 * Return 0 on success or -errno on error.
52 */
53 int (*init)(const struct nfc_tag_device *dev);
54
55 /**
56 * Set the NFC tag content.
57 *
58 * The driver must write <data> in the data area of the tag starting at
59 * byte 0 of block 4 and zero the rest of the data area.
60 *
61 * Returns 0 on success or -errno on error.
62 */
63 int (*setContent)(const struct nfc_tag_device *dev, const uint8_t *data, size_t len);
64
65 /**
66 * Returns the memory size of the data area.
67 */
68 int (*getMemorySize)(const struct nfc_tag_device *dev);
69} nfc_tag_device_t;
70
71static inline int nfc_tag_open(const struct hw_module_t* module,
72 nfc_tag_device_t** dev) {
73 return module->methods->open(module, NFC_TAG_ID,
74 (struct hw_device_t**)dev);
75}
76
77static inline int nfc_tag_close(nfc_tag_device_t* dev) {
78 return dev->common.close(&dev->common);
79}
80
81__END_DECLS
82
83#endif // ANDROID_NFC_TAG_HAL_INTERFACE_H