Skip to content

Commit 3b2ea45

Browse files
committed
Fix issue #8 and release 2.0.2.
B Fix error handling in (*Device).InitiatorSelectPassiveTarget() B Fix initData handling (ibid.), these fix issue #8 R Improve documentation (ibid.)
1 parent 9b35e8d commit 3b2ea45

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

2.0/nfc/initiator.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,21 +345,32 @@ func (d Device) InitiatorInitSecureElement() error {
345345
return Error(C.nfc_initiator_init_secure_element(*d.d))
346346
}
347347

348-
// Select a passive or emulated tag.
348+
// Select a passive or emulated tag. initData is used with different kind of
349+
// data depending on modulation type:
350+
// * for an ISO/IEC 14443 type A modulation, initData contains the UID you want to select;
351+
// * for an ISO/IEC 14443 type B modulation, initData contains Application Family Identifier (AFI) (see ISO/IEC 14443-3) and optionally a second byte = 0x01 if you want to use probabilistic approach instead of timeslot approach;
352+
// * for a FeliCa modulation, initData contains a 5-byte polling payload (see ISO/IEC 18092 11.2.2.5).
353+
// * for ISO14443B', ASK CTx and ST SRx, see corresponding standards
354+
// if nil, default values adequate for the chosen modulation will be used.
349355
func (d Device) InitiatorSelectPassiveTarget(m Modulation, initData []byte) (Target, error) {
350356
if *d.d == nil {
351357
return nil, errors.New("device closed")
352358
}
353359

354360
var pnt C.nfc_target
361+
var initDataPtr *C.uint8_t = nil
362+
var initDataLen C.size_t = 0
363+
364+
if (initData != nil) {
365+
initDataPtr = (*C.uint8_t)(&initData[0])
366+
initDataLen = C.size_t(len(initData))
367+
}
355368

356369
n := C.nfc_initiator_select_passive_target(
357370
*d.d,
358371
C.nfc_modulation{C.nfc_modulation_type(m.Type), C.nfc_baud_rate(m.BaudRate)},
359-
(*C.uint8_t)(&initData[0]),
360-
C.size_t(len(initData)),
361-
&pnt)
362-
if n != 0 {
372+
initDataPtr, initDataLen, &pnt)
373+
if n < 0 {
363374
return nil, Error(n)
364375
}
365376

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ Release 2.0 (2014-08-30)
3838
Release 2.0.1 (2015-09-28)
3939
B Set device pointer to nil after calling nfc_close(), not before.
4040

41+
Release 2.0.2 (2016-01-14)
42+
B Fix error handling in (*Device).InitiatorSelectPassiveTarget()
43+
B Fix initData handling (ibid.), these fix issue #8
44+
R Improve documentation (ibid.)
45+
4146
Upcoming release 2.1
4247
N Introduce a new function nfc.Device.SupportedBaudRatesTargetMode()
4348
wrapping the corresponding new function in the upcoming 1.7.2 release

README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ The code has not been thoroughly tested yet. Please report any errors to the
33
project. The API is considered stable as of version 2.0 and will probably not
44
change in incompatible ways in the near future.
55

6-
The current release of this wrapper is release 2.0.1. Successive minor releases
6+
The current release of this wrapper is release 2.0.2. Successive minor releases
77
will be placed in different subfolders as to not change the semantics of code
88
that links against a specific version of this wrapper. The patch level is not
99
reflected in this scheme as an increase in patch level does not lead to

dev/nfc/initiator.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,21 +351,32 @@ func (d Device) InitiatorInitSecureElement() error {
351351
return Error(C.nfc_initiator_init_secure_element(*d.d))
352352
}
353353

354-
// Select a passive or emulated tag.
354+
// Select a passive or emulated tag. initData is used with different kind of
355+
// data depending on modulation type:
356+
// * for an ISO/IEC 14443 type A modulation, initData contains the UID you want to select;
357+
// * for an ISO/IEC 14443 type B modulation, initData contains Application Family Identifier (AFI) (see ISO/IEC 14443-3) and optionally a second byte = 0x01 if you want to use probabilistic approach instead of timeslot approach;
358+
// * for a FeliCa modulation, initData contains a 5-byte polling payload (see ISO/IEC 18092 11.2.2.5).
359+
// * for ISO14443B', ASK CTx and ST SRx, see corresponding standards
360+
// if nil, default values adequate for the chosen modulation will be used.
355361
func (d Device) InitiatorSelectPassiveTarget(m Modulation, initData []byte) (Target, error) {
356362
if *d.d == nil {
357363
return nil, errors.New("device closed")
358364
}
359365

360366
var pnt C.nfc_target
367+
var initDataPtr *C.uint8_t = nil
368+
var initDataLen C.size_t = 0
369+
370+
if (initData != nil) {
371+
initDataPtr = (*C.uint8_t)(&initData[0])
372+
initDataLen = C.size_t(len(initData))
373+
}
361374

362375
n := C.nfc_initiator_select_passive_target(
363376
*d.d,
364377
C.nfc_modulation{C.nfc_modulation_type(m.Type), C.nfc_baud_rate(m.BaudRate)},
365-
(*C.uint8_t)(&initData[0]),
366-
C.size_t(len(initData)),
367-
&pnt)
368-
if n != 0 {
378+
initDataPtr, initDataLen, &pnt)
379+
if n < 0 {
369380
return nil, Error(n)
370381
}
371382

0 commit comments

Comments
 (0)