Mbed OS Reference
Loading...
Searching...
No Matches
ndef.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-2018, ARM Limited, All Rights Reserved
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17/**
18 * \file ndef.h
19 * \copyright Copyright (c) ARM Ltd 2013
20 * \author Donatien Garnier
21 */
22
23/** \addtogroup NDEF
24 * \ingroup nfc
25 * @{
26 * \name Generic NDEF Tag
27 * @{
28 */
29
30#ifndef NDEF_H_
31#define NDEF_H_
32
33#include "stack/nfc_common.h"
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39//Generic interface for NDEF messages
40typedef struct __ndef_msg ndef_msg_t;
41
42/** Function called to generate the tag's content on read (target mode)
43 * \param pTag pointer to ndef_tag_t instance
44 * \param pBufferBldr buffer in which to store the generated content
45 * \param pUserData User data pointer passed to #ndef_msg_init
46 */
47typedef nfc_err_t (*ndef_encode_fn_t)(ndef_msg_t *pTag, ac_buffer_builder_t *pBufferBldr, void *pUserData);
48
49/** Function called to decode the tag's content on write (target mode) or read (reader mode)
50 * \param pTag pointer to ndef_tag_t instance
51 * \param pBuffer buffer containing the tag's content
52 * \param pUserData User data pointer passed to #ndef_msg_init
53 */
54typedef nfc_err_t (*ndef_decode_fn_t)(ndef_msg_t *pTag, ac_buffer_t *pBuffer, void *pUserData);
55
56struct __ndef_msg {
57 ndef_encode_fn_t encode;
58 ndef_decode_fn_t decode;
59 ac_buffer_builder_t bufferBldr;
60 void *pUserData;
61};
62
63/** Initialize NDEF tag abstraction
64 * \param pNdef pointer to ndef_tag_t structure to initialize
65 * \param encode function that will be called to generate the NDEF message before sending it to the other party
66 * \param decode function that will be called to parse the NDEF message after receiving it from the other party
67 * \param data underlying buffer to use (it should be big enough so that any NDEF message you might need could be stored inside)
68 * \param size size of the underlying buffer
69 * \param pUserData User data pointer to pass to callbacks.
70 */
71void ndef_msg_init(ndef_msg_t *pNdef, ndef_encode_fn_t encode, ndef_decode_fn_t decode, uint8_t *data, size_t size, void *pUserData);
72
73static inline nfc_err_t ndef_msg_encode(ndef_msg_t *pNdef)
74{
75 if (pNdef->encode == NULL) {
76 return NFC_OK;
77 }
78 return pNdef->encode(pNdef, &pNdef->bufferBldr, pNdef->pUserData);
79}
80
81static inline nfc_err_t ndef_msg_decode(ndef_msg_t *pNdef)
82{
83 if (pNdef->decode == NULL) {
84 return NFC_OK;
85 }
86 return pNdef->decode(pNdef, ac_buffer_builder_buffer(&pNdef->bufferBldr), pNdef->pUserData);
87}
88
89static inline ac_buffer_builder_t *ndef_msg_buffer_builder(ndef_msg_t *pNdef)
90{
91 return &pNdef->bufferBldr;
92}
93
94//void* ndef_tag_impl(ndef_tag_t* pNdefTag);
95
96#ifdef __cplusplus
97}
98#endif
99
100#endif /* NDEF_H_ */
101
102/**
103 * @}
104 * @}
105 * */
106
void ndef_msg_init(ndef_msg_t *pNdef, ndef_encode_fn_t encode, ndef_decode_fn_t decode, uint8_t *data, size_t size, void *pUserData)
Initialize NDEF tag abstraction.
nfc_err_t(* ndef_decode_fn_t)(ndef_msg_t *pTag, ac_buffer_t *pBuffer, void *pUserData)
Function called to decode the tag's content on write (target mode) or read (reader mode)
Definition: ndef.h:54
nfc_err_t(* ndef_encode_fn_t)(ndef_msg_t *pTag, ac_buffer_builder_t *pBufferBldr, void *pUserData)
Function called to generate the tag's content on read (target mode)
Definition: ndef.h:47
int nfc_err_t
Type for NFC errors.
Definition: nfc_errors.h:60
#define NFC_OK
No error.
Definition: nfc_errors.h:34