blob: 040a07d8cb1376fa1a2ec7abf0006de51a72a6ad [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 {
Stewart Miles84d35492014-05-01 09:03:27 -070035 /**
36 * Common methods of the NFC tag module. This *must* be the first member of
37 * nfc_tag_module_t as users of this structure will cast a hw_module_t to
38 * nfc_tag_module_t pointer in contexts where it's known the hw_module_t references a
39 * nfc_tag_module_t.
40 */
Benoit Gobye44be612013-10-10 17:39:24 -070041 struct hw_module_t common;
42} nfc_tag_module_t;
43
44typedef struct nfc_tag_device {
Stewart Miles84d35492014-05-01 09:03:27 -070045 /**
46 * Common methods of the NFC tag device. This *must* be the first member of
47 * nfc_tag_device_t as users of this structure will cast a hw_device_t to
48 * nfc_tag_device_t pointer in contexts where it's known the hw_device_t references a
49 * nfc_tag_device_t.
50 */
Benoit Gobye44be612013-10-10 17:39:24 -070051 struct hw_device_t common;
52
53 /**
54 * Initialize the NFC tag.
55 *
56 * The driver must:
57 * * Set the static lock bytes to read only
58 * * Configure the Capability Container to disable write acess
59 * eg: 0xE1 0x10 <size> 0x0F
60 *
61 * This function is called once before any calls to setContent().
62 *
63 * Return 0 on success or -errno on error.
64 */
65 int (*init)(const struct nfc_tag_device *dev);
66
67 /**
68 * Set the NFC tag content.
69 *
70 * The driver must write <data> in the data area of the tag starting at
71 * byte 0 of block 4 and zero the rest of the data area.
72 *
73 * Returns 0 on success or -errno on error.
74 */
75 int (*setContent)(const struct nfc_tag_device *dev, const uint8_t *data, size_t len);
76
77 /**
78 * Returns the memory size of the data area.
79 */
80 int (*getMemorySize)(const struct nfc_tag_device *dev);
81} nfc_tag_device_t;
82
83static inline int nfc_tag_open(const struct hw_module_t* module,
84 nfc_tag_device_t** dev) {
85 return module->methods->open(module, NFC_TAG_ID,
86 (struct hw_device_t**)dev);
87}
88
89static inline int nfc_tag_close(nfc_tag_device_t* dev) {
90 return dev->common.close(&dev->common);
91}
92
93__END_DECLS
94
95#endif // ANDROID_NFC_TAG_HAL_INTERFACE_H