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