diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nfc/checksum_p.h | 68 | ||||
-rw-r--r-- | src/nfc/nfc.pro | 1 | ||||
-rw-r--r-- | src/nfc/qnearfieldtarget.cpp | 25 | ||||
-rw-r--r-- | src/nfc/targetemulator.cpp | 2 |
4 files changed, 24 insertions, 72 deletions
diff --git a/src/nfc/checksum_p.h b/src/nfc/checksum_p.h deleted file mode 100644 index 3b8304dd..00000000 --- a/src/nfc/checksum_p.h +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal -** -** This file is part of the QtNfc module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3.0 as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU General Public License version 3.0 requirements will be -** met: http://www.gnu.org/copyleft/gpl.html. -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef CHECKSUM_P_H -#define CHECKSUM_P_H - -// Copied from qbytearray.cpp -// Modified to initialise the crc with 0x6363 instead of 0xffff and to not invert the final result. -static const quint16 crc_tbl[16] = { - 0x0000, 0x1081, 0x2102, 0x3183, - 0x4204, 0x5285, 0x6306, 0x7387, - 0x8408, 0x9489, 0xa50a, 0xb58b, - 0xc60c, 0xd68d, 0xe70e, 0xf78f -}; - -quint16 qNfcChecksum(const char *data, uint len) -{ - register quint16 crc = 0x6363; - uchar c; - const uchar *p = reinterpret_cast<const uchar *>(data); - while (len--) { - c = *p++; - crc = ((crc >> 4) & 0x0fff) ^ crc_tbl[((crc ^ c) & 15)]; - c >>= 4; - crc = ((crc >> 4) & 0x0fff) ^ crc_tbl[((crc ^ c) & 15)]; - } - return crc; -} - -#endif // CHECKSUM_P_H diff --git a/src/nfc/nfc.pro b/src/nfc/nfc.pro index b0c261a8..fcc4e6a4 100644 --- a/src/nfc/nfc.pro +++ b/src/nfc/nfc.pro @@ -29,7 +29,6 @@ PRIVATE_HEADERS += \ qnearfieldtagtype3_p.h \ qnearfieldtagtype4_p.h \ qtlv_p.h \ - checksum_p.h \ qndefnfcsmartposterrecord_p.h SOURCES += \ diff --git a/src/nfc/qnearfieldtarget.cpp b/src/nfc/qnearfieldtarget.cpp index f95d2ee1..542b66fe 100644 --- a/src/nfc/qnearfieldtarget.cpp +++ b/src/nfc/qnearfieldtarget.cpp @@ -130,13 +130,34 @@ QT_BEGIN_NAMESPACE_NFC */ /*! - \fn qNfcChecksum(const char *data, uint len) + \fn quint16 qNfcChecksum(const char *data, uint len) \relates QNearFieldTarget Returns the NFC checksum of the first \a len bytes of \a data. */ -#include "checksum_p.h" +// Copied from qbytearray.cpp +// Modified to initialize the crc with 0x6363 instead of 0xffff and to not invert the final result. +static const quint16 crc_tbl[16] = { + 0x0000, 0x1081, 0x2102, 0x3183, + 0x4204, 0x5285, 0x6306, 0x7387, + 0x8408, 0x9489, 0xa50a, 0xb58b, + 0xc60c, 0xd68d, 0xe70e, 0xf78f +}; + +quint16 qNfcChecksum(const char *data, uint len) +{ + register quint16 crc = 0x6363; + uchar c; + const uchar *p = reinterpret_cast<const uchar *>(data); + while (len--) { + c = *p++; + crc = ((crc >> 4) & 0x0fff) ^ crc_tbl[((crc ^ c) & 15)]; + c >>= 4; + crc = ((crc >> 4) & 0x0fff) ^ crc_tbl[((crc ^ c) & 15)]; + } + return crc; +} /*! \fn void QNearFieldTarget::disconnected() diff --git a/src/nfc/targetemulator.cpp b/src/nfc/targetemulator.cpp index cfaaf28c..b607b760 100644 --- a/src/nfc/targetemulator.cpp +++ b/src/nfc/targetemulator.cpp @@ -47,7 +47,7 @@ #include <QtCore/QDebug> // Implementation of qNfcChecksum -#include "checksum_p.h" +#include "qnearfieldtarget.h" QT_BEGIN_NAMESPACE_NFC |