Mistake on this page?
Report an issue in GitHub or email us
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  * @{
25  * \name Generic NDEF Tag
26  * @{
27  */
28 
29 #ifndef NDEF_H_
30 #define NDEF_H_
31 
32 #include "stack/nfc_common.h"
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 //Generic interface for NDEF messages
39 typedef struct __ndef_msg ndef_msg_t;
40 
41 /** Function called to generate the tag's content on read (target mode)
42  * \param pTag pointer to ndef_tag_t instance
43  * \param type pMem buffer in which to store the generated content
44  */
45 typedef nfc_err_t (*ndef_encode_fn_t)(ndef_msg_t *pTag, ac_buffer_builder_t *pBufferBldr, void *pUserData);
46 
47 /** Function called to decode the tag's content on write (target mode) or read (reader mode)
48  * \param pTag pointer to ndef_tag_t instance
49  * \param type pMem buffer containing the tag's content
50  */
51 typedef nfc_err_t (*ndef_decode_fn_t)(ndef_msg_t *pTag, ac_buffer_t *pBuffer, void *pUserData);
52 
53 struct __ndef_msg {
54  ndef_encode_fn_t encode;
55  ndef_decode_fn_t decode;
56  ac_buffer_builder_t bufferBldr;
57  void *pUserData;
58 };
59 
60 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);
61 
62 static inline nfc_err_t ndef_msg_encode(ndef_msg_t *pNdef)
63 {
64  if (pNdef->encode == NULL) {
65  return NFC_OK;
66  }
67  return pNdef->encode(pNdef, &pNdef->bufferBldr, pNdef->pUserData);
68 }
69 
70 static inline nfc_err_t ndef_msg_decode(ndef_msg_t *pNdef)
71 {
72  if (pNdef->decode == NULL) {
73  return NFC_OK;
74  }
75  return pNdef->decode(pNdef, ac_buffer_builder_buffer(&pNdef->bufferBldr), pNdef->pUserData);
76 }
77 
78 static inline ac_buffer_builder_t *ndef_msg_buffer_builder(ndef_msg_t *pNdef)
79 {
80  return &pNdef->bufferBldr;
81 }
82 
83 //void* ndef_tag_impl(ndef_tag_t* pNdefTag);
84 
85 #ifdef __cplusplus
86 }
87 #endif
88 
89 #endif /* NDEF_H_ */
90 
91 /**
92  * @}
93  * @}
94  * */
95 
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:45
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:51
#define NFC_OK
No error.
Definition: nfc_errors.h:33
static ac_buffer_t * ac_buffer_builder_buffer(ac_buffer_builder_t *pBuilder)
Get ac_buffer builder's underlying ac_buffer.
int nfc_err_t
Type for NFC errors.
Definition: nfc_errors.h:59
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.