52 lines
1.3 KiB
C
52 lines
1.3 KiB
C
#include <cutter.h>
|
|
|
|
#include <nfc/nfc.h>
|
|
|
|
#define NTESTS 10
|
|
#define MAX_DEVICE_COUNT 8
|
|
#define MAX_TARGET_COUNT 8
|
|
|
|
/*
|
|
* This is basically a stress-test to ensure we don't left a device in an
|
|
* inconsistent state after use.
|
|
*/
|
|
void
|
|
test_access_storm (void)
|
|
{
|
|
int n = NTESTS;
|
|
nfc_connstring connstrings[MAX_DEVICE_COUNT];
|
|
int res = 0;
|
|
|
|
size_t ref_device_count = nfc_list_devices (connstrings, MAX_DEVICE_COUNT);
|
|
if (!ref_device_count)
|
|
cut_omit ("No NFC device found");
|
|
|
|
while (n) {
|
|
size_t i;
|
|
|
|
size_t device_count = nfc_list_devices (connstrings, MAX_DEVICE_COUNT);
|
|
cut_assert_equal_int (ref_device_count, device_count, cut_message ("device count"));
|
|
|
|
for (i = 0; i < device_count; i++) {
|
|
nfc_device *device;
|
|
nfc_target ant[MAX_TARGET_COUNT];
|
|
|
|
device = nfc_connect (connstrings[i]);
|
|
cut_assert_not_null (device, cut_message ("nfc_connect"));
|
|
|
|
res = nfc_initiator_init(device);
|
|
cut_assert_equal_int (0, res, cut_message ("nfc_initiator_init"));
|
|
|
|
const nfc_modulation nm = {
|
|
.nmt = NMT_ISO14443A,
|
|
.nbr = NBR_106,
|
|
};
|
|
res = nfc_initiator_list_passive_targets(device, nm, ant, MAX_TARGET_COUNT);
|
|
cut_assert_operator_int (res, >=, 0, cut_message ("nfc_initiator_list_passive_targets"));
|
|
|
|
nfc_close (device);
|
|
}
|
|
|
|
n--;
|
|
}
|
|
}
|