libnfc
1.7.1
utils
jewel.c
Go to the documentation of this file.
1
/*-
2
* Free/Libre Near Field Communication (NFC) library
3
*
4
* Libnfc historical contributors:
5
* Copyright (C) 2009 Roel Verdult
6
* Copyright (C) 2009-2013 Romuald Conty
7
* Copyright (C) 2010-2012 Romain Tartière
8
* Copyright (C) 2010-2013 Philippe Teuwen
9
* Copyright (C) 2012-2013 Ludovic Rousseau
10
* See AUTHORS file for a more comprehensive list of contributors.
11
* Additional contributors of this file:
12
* Copyright (C) 2014 Pim 't Hart
13
*
14
* Redistribution and use in source and binary forms, with or without
15
* modification, are permitted provided that the following conditions are met:
16
* 1) Redistributions of source code must retain the above copyright notice,
17
* this list of conditions and the following disclaimer.
18
* 2 )Redistributions in binary form must reproduce the above copyright
19
* notice, this list of conditions and the following disclaimer in the
20
* documentation and/or other materials provided with the distribution.
21
*
22
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
* POSSIBILITY OF SUCH DAMAGE.
33
*
34
* Note that this license only applies on the examples, NFC library itself is under LGPL
35
*
36
*/
41
#include "
jewel.h
"
42
43
#include <string.h>
44
45
#include <
nfc/nfc.h
>
46
55
bool
56
nfc_initiator_jewel_cmd
(
nfc_device
*pnd,
const
jewel_req req, jewel_res *pres)
57
{
58
size_t
nLenReq;
59
size_t
nLenRes;
60
61
switch
(req.rid.btCmd) {
62
case
TC_RID:
63
nLenReq =
sizeof
(jewel_req_rid);
64
nLenRes =
sizeof
(jewel_res_rid);
65
break
;
66
case
TC_RALL:
67
nLenReq =
sizeof
(jewel_req_rall);
68
nLenRes =
sizeof
(jewel_res_rall);
69
break
;
70
case
TC_READ:
71
nLenReq =
sizeof
(jewel_req_read);
72
nLenRes =
sizeof
(jewel_res_read);
73
break
;
74
case
TC_WRITEE:
75
nLenReq =
sizeof
(jewel_req_writee);
76
nLenRes =
sizeof
(jewel_res_writee);
77
break
;
78
case
TC_WRITENE:
79
nLenReq =
sizeof
(jewel_req_writene);
80
nLenRes =
sizeof
(jewel_res_writene);
81
break
;
82
case
TC_RSEG:
83
nLenReq =
sizeof
(jewel_req_rseg);
84
nLenRes =
sizeof
(jewel_res_rseg);
85
break
;
86
case
TC_READ8:
87
nLenReq =
sizeof
(jewel_req_read8);
88
nLenRes =
sizeof
(jewel_res_read8);
89
break
;
90
case
TC_WRITEE8:
91
nLenReq =
sizeof
(jewel_req_writee8);
92
nLenRes =
sizeof
(jewel_res_writee8);
93
break
;
94
case
TC_WRITENE8:
95
nLenReq =
sizeof
(jewel_req_writene8);
96
nLenRes =
sizeof
(jewel_res_writene8);
97
break
;
98
default
:
99
return
false
;
100
break
;
101
}
102
103
if
(
nfc_initiator_transceive_bytes
(pnd, (uint8_t *)&req, nLenReq, (uint8_t *)pres, nLenRes, -1) < 0) {
104
nfc_perror
(pnd,
"nfc_initiator_transceive_bytes"
);
105
return
false
;
106
}
107
108
return
true
;
109
}
nfc_device
NFC device information.
Definition:
nfc-internal.h:190
nfc_initiator_transceive_bytes
int nfc_initiator_transceive_bytes(nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, const size_t szRx, int timeout)
Send data to target then retrieve data from target.
Definition:
nfc.c:764
nfc_perror
void nfc_perror(const nfc_device *pnd, const char *pcString)
Display the last error occured on a nfc_device.
Definition:
nfc.c:1138
nfc_initiator_jewel_cmd
bool nfc_initiator_jewel_cmd(nfc_device *pnd, const jewel_req req, jewel_res *pres)
Execute a Jewel Topaz Command.
Definition:
jewel.c:56
jewel.h
provide samples structs and functions to manipulate Jewel Topaz tags using libnfc
nfc.h
libnfc interface
Generated by
1.8.17