1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
/****************************************************************************
**
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia 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.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef QNEARFIELDTARGET_MAEMO6_P_H
#define QNEARFIELDTARGET_MAEMO6_P_H
#include <qconnectivityglobal.h>
#include "qnearfieldmanager_maemo6_p.h"
#include <qnearfieldtarget.h>
#include <qnearfieldtarget_p.h>
#include <qnearfieldtagtype1.h>
#include <qnearfieldtagtype2.h>
#include <qnearfieldtagtype3.h>
#include <qnearfieldtagtype4.h>
#include <qndefmessage.h>
#include "maemo6/adapter_interface_p.h"
#include "maemo6/target_interface_p.h"
#include "maemo6/tag_interface_p.h"
#include "maemo6/device_interface_p.h"
#include <QtDBus/QDBusPendingReply>
using namespace com::nokia::nfc;
class PendingCallWatcher : public QObject
{
Q_OBJECT
public:
PendingCallWatcher(QObject *parent) : QObject(parent) { }
void addSendCommand(const QDBusPendingReply<QByteArray> &reply,
const QNearFieldTarget::RequestId &id);
void addReadNdefMessages(const QDBusPendingReply<QList<QByteArray> > &reply,
const QNearFieldTarget::RequestId &id);
void addWriteNdefMessages(const QDBusPendingReply<> &reply,
const QNearFieldTarget::RequestId &id);
private slots:
void sendCommandFinished(QDBusPendingCallWatcher *watcher);
void readNdefMessagesFinished(QDBusPendingCallWatcher *watcher);
void writeNdefMessages(QDBusPendingCallWatcher *watcher);
private:
QMap<QDBusPendingCallWatcher *, QNearFieldTarget::RequestId> m_pendingCommands;
QMap<QDBusPendingCallWatcher *, QNearFieldTarget::RequestId> m_pendingNdefReads;
QMap<QDBusPendingCallWatcher *, QNearFieldTarget::RequestId> m_pendingNdefWrites;
};
template <typename T>
class NearFieldTarget : public T
{
public:
NearFieldTarget(QNearFieldManagerPrivateImpl *manager, Target *target, Tag *tag)
: T(manager), m_manager(manager), m_target(target), m_tag(tag), m_device(0),
m_callWatcher(new PendingCallWatcher(this))
{
}
NearFieldTarget(QNearFieldManagerPrivateImpl *manager, Target *target, Device *device)
: T(manager), m_manager(manager), m_target(target), m_tag(0), m_device(device),
m_callWatcher(new PendingCallWatcher(this))
{
}
~NearFieldTarget()
{
delete m_device;
delete m_tag;
delete m_target;
}
QByteArray uid() const
{
QStringList fields;
if (m_tag)
fields = m_tag->uID().split(QLatin1Char(':'));
else if (m_device)
fields = m_device->uID().split(QLatin1Char(':'));
QByteArray id;
foreach (const QString &f, fields)
id.append(char(f.toUInt(0, 16)));
return id;
}
QNearFieldTarget::Type type() const
{
if (m_device)
return QNearFieldTarget::NfcForumDevice;
if (m_tag) {
const QString tagType = m_tag->technology();
if (tagType == QLatin1String("jewel"))
return QNearFieldTarget::NfcTagType1;
else if (tagType == QLatin1String("mifare-ul"))
return QNearFieldTarget::NfcTagType2;
else if (tagType == QLatin1String("felica"))
return QNearFieldTarget::NfcTagType3;
else if (tagType == QLatin1String("iso-4a"))
return QNearFieldTarget::NfcTagType4;
else if (tagType == QLatin1String("mifare-1k"))
return QNearFieldTarget::MifareTag;
else
return QNearFieldTarget::ProprietaryTag;
}
return QNearFieldTarget::ProprietaryTag;
}
QNearFieldTarget::AccessMethods accessMethods() const
{
QNearFieldTarget::AccessMethods result = QNearFieldTarget::NdefAccess;
#ifdef MAEMO6_TAG_TYPE_SEPECIFIC_ACCESS_SUPPORTED
if (m_tag)
result |= QNearFieldTarget::TagTypeSpecificAccess;
#endif
if (!m_tag)
result |= QNearFieldTarget::LlcpAccess;
return result;
}
bool hasNdefMessage()
{
return true;
}
QNearFieldTarget::RequestId readNdefMessages()
{
if (!m_tag)
return QNearFieldTarget::RequestId();
QNearFieldTarget::RequestId id(new QNearFieldTarget::RequestIdPrivate);
QDBusPendingReply<QList<QByteArray> > reply = m_tag->ReadNDEFData();
m_callWatcher->addReadNdefMessages(reply, id);
return id;
}
QNearFieldTarget::RequestId writeNdefMessages(const QList<QNdefMessage> &messages)
{
if (!m_tag)
return QNearFieldTarget::RequestId();
QNearFieldTarget::RequestId id(new QNearFieldTarget::RequestIdPrivate);
QList<QByteArray> rawMessages;
foreach (const QNdefMessage &message, messages)
rawMessages.append(message.toByteArray());
QDBusPendingReply<> reply = m_tag->WriteNDEFData(rawMessages);
m_callWatcher->addWriteNdefMessages(reply, id);
return id;
}
QNearFieldTarget::RequestId sendCommand(const QByteArray &command)
{
#if 0
quint16 crc = qNfcChecksum(command.constData(), command.length());
QNearFieldTarget::RequestId id(new QNearFieldTarget::RequestIdPrivate);
QDBusPendingReply<QByteArray> reply =
m_tag->RawRequest(command + char(crc & 0xff) + char(crc >> 8));
m_callWatcher->addSendCommand(reply, id);
return id;
#else
Q_UNUSED(command);
return QNearFieldTarget::RequestId();
#endif
}
QNearFieldTarget::RequestId sendCommands(const QList<QByteArray> &commands)
{
#if 0
for (int i = 0; i < commandCount; ++i) {
reply[i] = m_tag->RawRequest(commands.at(i));
}
QList<QByteArray> results;
for (int i = 0; i < commandCount; ++i) {
reply[i].waitForFinished();
results.append(reply[i].isError() ? QByteArray() : reply->value());
}
return results;
#else
Q_UNUSED(commands);
return QNearFieldTarget::RequestId();
#endif
}
protected:
QNearFieldManagerPrivateImpl *m_manager;
Target *m_target;
Tag *m_tag;
Device *m_device;
PendingCallWatcher *m_callWatcher;
};
class TagType1 : public NearFieldTarget<QNearFieldTagType1>
{
public:
TagType1(QNearFieldManagerPrivateImpl *manager, Target *target, Tag *tag)
: NearFieldTarget<QNearFieldTagType1>(manager, target, tag)
{
}
~TagType1()
{
}
int memorySize() const;
};
class TagType2 : public NearFieldTarget<QNearFieldTagType2>
{
public:
TagType2(QNearFieldManagerPrivateImpl *manager, Target *target, Tag *tag)
: NearFieldTarget<QNearFieldTagType2>(manager, target, tag)
{
}
~TagType2()
{
}
int memorySize() const;
};
class TagType3 : public NearFieldTarget<QNearFieldTagType3>
{
public:
TagType3(QNearFieldManagerPrivateImpl *manager, Target *target, Tag *tag)
: NearFieldTarget<QNearFieldTagType3>(manager, target, tag)
{
}
~TagType3()
{
}
int memorySize() const;
};
class TagType4 : public NearFieldTarget<QNearFieldTagType4>
{
public:
TagType4(QNearFieldManagerPrivateImpl *manager, Target *target, Tag *tag)
: NearFieldTarget<QNearFieldTagType4>(manager, target, tag)
{
}
~TagType4()
{
}
int memorySize() const;
};
#endif // QNEARFIELDTARGET_MAEMO6_P_H
|