2010-01-15 11:18:11 +01:00
|
|
|
/*-
|
2009-10-12 16:52:26 +02:00
|
|
|
* Public platform independent Near Field Communication (NFC) library
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009, Roel Verdult
|
2010-10-08 22:36:13 +02:00
|
|
|
* Copyright (C) 2010, Romuald Conty
|
2009-10-12 16:52:26 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2010-01-15 11:18:11 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-10-08 22:36:13 +02:00
|
|
|
* @file nfc-dep-initiator.c
|
2010-10-08 20:15:00 +02:00
|
|
|
* @brief Turns the NFC device into a D.E.P. initiator (see NFCIP-1)
|
2009-10-12 16:52:26 +02:00
|
|
|
*/
|
|
|
|
|
2010-01-15 11:18:11 +01:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2010-09-07 19:51:03 +02:00
|
|
|
# include "config.h"
|
2010-01-15 11:18:11 +01:00
|
|
|
#endif // HAVE_CONFIG_H
|
|
|
|
|
2009-09-03 15:47:26 +02:00
|
|
|
#include <stdio.h>
|
2010-10-08 20:15:00 +02:00
|
|
|
#include <stdlib.h>
|
2009-09-03 15:47:26 +02:00
|
|
|
#include <string.h>
|
2010-10-08 22:25:34 +02:00
|
|
|
|
2009-12-01 15:23:00 +01:00
|
|
|
#include <nfc/nfc.h>
|
2009-09-03 15:47:26 +02:00
|
|
|
|
2010-10-08 22:25:34 +02:00
|
|
|
#include "nfc-utils.h"
|
|
|
|
|
2009-11-10 10:47:59 +01:00
|
|
|
#define MAX_FRAME_LEN 264
|
|
|
|
|
2010-09-07 19:51:03 +02:00
|
|
|
int
|
|
|
|
main (int argc, const char *argv[])
|
2009-09-03 15:47:26 +02:00
|
|
|
{
|
2009-11-09 12:23:33 +01:00
|
|
|
nfc_device_t *pnd;
|
2010-10-08 22:25:34 +02:00
|
|
|
nfc_target_info_t nti;
|
2010-10-08 20:15:00 +02:00
|
|
|
byte_t abtRx[MAX_FRAME_LEN];
|
|
|
|
size_t szRx;
|
2010-10-08 22:25:34 +02:00
|
|
|
byte_t abtTx[] = "Hello World!";
|
2009-09-03 15:47:26 +02:00
|
|
|
|
2010-04-07 17:08:04 +02:00
|
|
|
if (argc > 1) {
|
2010-10-08 20:15:00 +02:00
|
|
|
printf ("Usage: %s\n", argv[0]);
|
|
|
|
return EXIT_FAILURE;
|
2010-04-07 17:08:04 +02:00
|
|
|
}
|
|
|
|
|
2010-09-07 19:51:03 +02:00
|
|
|
pnd = nfc_connect (NULL);
|
2010-10-08 20:15:00 +02:00
|
|
|
if (!pnd) {
|
|
|
|
printf("Unable to connect to NFC device.\n");
|
|
|
|
return EXIT_FAILURE;
|
2009-09-03 15:47:26 +02:00
|
|
|
}
|
|
|
|
|
2010-10-08 20:15:00 +02:00
|
|
|
if (!nfc_initiator_init (pnd)) {
|
|
|
|
nfc_perror(pnd, "nfc_initiator_init");
|
|
|
|
return EXIT_FAILURE;
|
2009-09-03 15:47:26 +02:00
|
|
|
}
|
|
|
|
|
2010-10-13 21:59:39 +02:00
|
|
|
if(!nfc_initiator_select_dep_target (pnd, NDM_PASSIVE, NULL, &nti)) {
|
2010-10-08 20:15:00 +02:00
|
|
|
nfc_perror(pnd, "nfc_initiator_select_dep_target");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
2010-10-08 22:25:34 +02:00
|
|
|
printf( "This D.E.P. target have been found:\n" );
|
|
|
|
print_nfc_dep_info (nti.ndi);
|
2010-10-08 20:15:00 +02:00
|
|
|
|
2010-10-08 22:25:34 +02:00
|
|
|
printf ("Sending: %s\n", abtTx);
|
|
|
|
if (!nfc_initiator_transceive_bytes (pnd, abtTx, sizeof(abtTx), abtRx, &szRx)) {
|
2010-10-08 20:15:00 +02:00
|
|
|
nfc_perror(pnd, "nfc_initiator_transceive_bytes");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
abtRx[szRx] = 0;
|
|
|
|
printf ("Received: %s\n", abtRx);
|
2009-09-03 15:47:26 +02:00
|
|
|
|
2010-09-07 19:51:03 +02:00
|
|
|
nfc_initiator_deselect_target (pnd);
|
|
|
|
nfc_disconnect (pnd);
|
2010-10-08 20:15:00 +02:00
|
|
|
return EXIT_SUCCESS;
|
2009-09-03 15:47:26 +02:00
|
|
|
}
|