libnfc  1.7.0-rc7
nfc-device.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  * Additional contributors of this file:
11  *
12  * This program is free software: you can redistribute it and/or modify it
13  * under the terms of the GNU Lesser General Public License as published by the
14  * Free Software Foundation, either version 3 of the License, or (at your
15  * option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful, but WITHOUT
18  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
20  * more details.
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>
24  */
25 
31 #include <stdlib.h>
32 #include <string.h>
33 
34 #ifdef HAVE_CONFIG_H
35 # include "config.h"
36 #endif // HAVE_CONFIG_H
37 
38 #include "nfc-internal.h"
39 
40 nfc_device *
41 nfc_device_new(const nfc_context *context, const nfc_connstring connstring)
42 {
43  nfc_device *res = malloc(sizeof(*res));
44 
45  if (!res) {
46  return NULL;
47  }
48 
49  // Store associated context
50  res->context = context;
51 
52  // Variables initiatialization
53  // Note: Actually, these initialization will be overwritten while the device
54  // will be setup. Putting them to _false_ while the default is _true_ ensure we
55  // send the command to the chip
56  res->bCrc = false;
57  res->bPar = false;
58  res->bEasyFraming = false;
59  res->bAutoIso14443_4 = false;
60  res->last_error = 0;
61  memcpy(res->connstring, connstring, sizeof(res->connstring));
62  res->driver_data = NULL;
63  res->chip_data = NULL;
64 
65  return res;
66 }
67 
68 void
69 nfc_device_free(nfc_device *dev)
70 {
71  if (dev) {
72  free(dev->driver_data);
73  free(dev);
74  }
75 }