4
* Copyright (C) 2003 Alexander Neundorf <neundorf@kde.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24
#include <QPushButton>
26
#include <QTextStream>
27
#include <QTreeWidgetItem>
28
#include <QTreeWidget>
29
#include <QVBoxLayout>
31
#include <kcomponentdata.h>
35
#include <kstandarddirs.h>
36
#include <kpluginfactory.h>
37
#include <kpluginloader.h>
40
#include <sys/types.h>
42
#include <netinet/in.h>
46
#include <libraw1394/csr.h>
48
#define CONFIGROM_BASE 0x00
49
#define CONFIGROM_CAP 0x08
50
#define CONFIGROM_GUID_HI 0x0c
51
#define CONFIGROM_GUID_LO 0x10
52
#define MAX_1394_PORTS 16
54
int my_reset_handler(raw1394handle_t handle, unsigned int) {
55
View1394* view1394=(View1394*)raw1394_get_userdata(handle);
57
view1394->rescanBus();
61
K_PLUGIN_FACTORY(View1394Factory, registerPlugin<View1394>();)
62
K_EXPORT_PLUGIN(View1394Factory("kcmview1394"))
64
View1394::View1394(QWidget *parent, const QVariantList &) :
65
KCModule(View1394Factory::componentData(), parent), m_insideRescanBus(false) {
66
setQuickHelp(i18n("<qt>Here you can see some information about "
67
"your IEEE 1394 configuration. "
68
"The meaning of the columns:"
70
"<li><b>Name</b>: port or node name, the number can change with each bus reset</li>"
71
"<li><b>GUID</b>: the 64 bit GUID of the node</li>"
72
"<li><b>Local</b>: checked if the node is an IEEE 1394 port of your computer</li>"
73
"<li><b>IRM</b>: checked if the node is isochronous resource manager capable</li>"
74
"<li><b>CRM</b>: checked if the node is cycle master capable</li>"
75
"<li><b>ISO</b>: checked if the node supports isochronous transfers</li>"
76
"<li><b>BM</b>: checked if the node is bus manager capable</li>"
77
"<li><b>PM</b>: checked if the node is power management capable</li>"
78
"<li><b>Acc</b>: the cycle clock accuracy of the node, valid from 0 to 100</li>"
79
"<li><b>Speed</b>: the speed of the node</li>"
80
"<li><b>Vendor</b>: the vendor of the device</li>"
85
QVBoxLayout *box=new QVBoxLayout(this);
86
box->setSpacing(KDialog::spacingHint());
88
m_view=new View1394Widget(this);
90
for (int i=2; i<8; i++)
91
m_view->m_listview->setColumnAlignment(i, Qt::AlignHCenter);
92
m_view->m_listview->setColumnAlignment(8, Qt::AlignRight);
93
m_view->m_listview->setColumnAlignment(9, Qt::AlignRight);
95
box->addWidget(m_view);
96
m_view->layout()->setMargin(0);
97
connect(m_view->m_busResetPb, SIGNAL(clicked()), this, SLOT(generateBusReset()));
98
connect(&m_rescanTimer, SIGNAL(timeout()), this, SLOT(rescanBus()));
102
View1394::~View1394() {
103
foreach(QSocketNotifier* notifier, m_notifiers) {
111
bool View1394::readConfigRom(raw1394handle_t handle, nodeid_t nodeid, quadlet_t& firstQuad, quadlet_t& cap, octlet_t& guid) {
116
nodeaddr_t addr=CSR_REGISTER_BASE + CSR_CONFIG_ROM + CONFIGROM_BASE;
117
for (int count=0; count<5; count++) {
120
int res=raw1394_read(handle, nodeid|0xffc0, addr, sizeof(q), &q);
127
select(0, 0, 0, 0, &tv);
132
addr=CSR_REGISTER_BASE + CSR_CONFIG_ROM + CONFIGROM_CAP;
133
if (raw1394_read(handle, nodeid|0xffc0, addr, sizeof(q), &q)!=0)
138
addr=CSR_REGISTER_BASE + CSR_CONFIG_ROM + CONFIGROM_GUID_HI;
139
if (raw1394_read(handle, nodeid|0xffc0, addr, sizeof(q), &q)!=0)
142
guid=octlet_t(ntohl(q))<<32;
144
addr=CSR_REGISTER_BASE + CSR_CONFIG_ROM + CONFIGROM_GUID_LO;
145
if (raw1394_read(handle, nodeid|0xffc0, addr, sizeof(q), &q)!=0)
153
void View1394::callRaw1394EventLoop(int fd) {
154
for (QList<raw1394handle_t>::iterator it= m_handles.begin(); it!=m_handles.end(); ++it)
155
if (raw1394_get_fd(*it)==fd) {
156
raw1394_loop_iterate(*it);
161
void View1394::rescanBus() {
162
if (m_insideRescanBus) {
163
m_rescanTimer.setSingleShot(true);
164
m_rescanTimer.start(100);
167
m_insideRescanBus=true;
168
// static int depth=0;
171
for (QList<raw1394handle_t>::iterator it=m_handles.begin(); it!=m_handles.end(); ++it)
172
raw1394_destroy_handle(*it);
174
m_view->m_listview->clear();
176
raw1394handle_t handle=raw1394_new_handle();
178
m_insideRescanBus=false;
181
//now search for new stuff
182
struct raw1394_portinfo p_info[MAX_1394_PORTS];
183
int num_of_cards=raw1394_get_port_info(handle, p_info, MAX_1394_PORTS);
184
raw1394_destroy_handle(handle);
185
//iterate over all cards
186
for (int i=0; i<num_of_cards; i++) {
187
handle=raw1394_new_handle();
188
if (raw1394_set_port(handle, i)!=0) {
189
raw1394_destroy_handle(handle);
192
raw1394_set_userdata(handle, this);
193
raw1394_set_bus_reset_handler(handle, my_reset_handler);
194
QSocketNotifier *notif=new QSocketNotifier(raw1394_get_fd(handle),QSocketNotifier::Read);
195
connect(notif, SIGNAL(activated(int)), this, SLOT(callRaw1394EventLoop(int)));
196
m_notifiers.append(notif);
197
m_handles.append(handle);
199
QStringList cardContents;
200
cardContents << i18n("Port %1:\"%2\"", i, p_info[i].name);
201
QTreeWidgetItem* card = new QTreeWidgetItem(m_view->m_listview, cardContents);
203
int num_of_nodes=raw1394_get_nodecount(handle);
205
int localNodeId=raw1394_get_local_id(handle);
206
//iterate over all nodes connected to this card
207
for (int j=0; j<num_of_nodes; j++) {
208
//get the guid of the node
210
quadlet_t firstQuad=0;
212
bool success=readConfigRom(handle, j, firstQuad, cap, guid);
214
QString nodeStr=i18n("Node %1", j);
216
QStringList notReadyList;
217
notReadyList << nodeStr << i18n("Not ready");
218
new QTreeWidgetItem(card, notReadyList);
222
if (((firstQuad>>24) & 0xff)==1) {
223
QString guidStr=QString::number(firstQuad, 16);
224
guidStr="0x"+guidStr.rightJustified(6, '0');
227
romList << nodeStr << guidStr;
228
new QTreeWidgetItem(card, romList);
234
snprintf(buf, 32, "%llX", guid);
236
guidStr="0x"+guidStr.rightJustified(16, '0');
237
QString local=((j | 0xffc0) == localNodeId) ? "X" : "";
238
QString irmStr=(cap & 0x80000000) ? "X" : "";
239
QString cmStr=(cap & 0x40000000) ? "X" : "";
240
QString isStr=(cap & 0x20000000) ? "X" : "";
241
QString bmStr=(cap & 0x10000000) ? "X" : "";
242
QString pmStr=(cap & 0x08000000) ? "X" : "";
243
QString accStr=QString::number((cap &0x00ff0000)>>16);
244
int speed=(cap & 0x00000007);
262
QStringList nodeContents;
263
nodeContents << nodeStr << guidStr << local << irmStr << cmStr << isStr << bmStr << pmStr << accStr << speedStr << m_ouiDb->vendor(guid);
265
new QTreeWidgetItem(card, nodeContents);
268
card->setExpanded(true);
271
m_insideRescanBus=false;
274
void View1394::generateBusReset() {
275
for (QList<raw1394handle_t>::iterator it=m_handles.begin(); it!=m_handles.end(); ++it)
276
raw1394_reset_bus(*it);
280
QString filename=KStandardDirs::locate("data", "kcmview1394/oui.db");
281
if (filename.isEmpty())
284
if (!f.open(QIODevice::ReadOnly))
287
QByteArray ba=f.readAll();
288
int bytesLeft=ba.size();
289
char* data=ba.data();
290
while (bytesLeft>8) {
291
char *eol=(char*)memchr((const void*)data, '\n', bytesLeft);
298
m_vendorIds.insert(QLatin1String(data), QString::fromUtf8(data+7));
299
bytesLeft-=(eol+1-data);
306
QString OuiDb::vendor(octlet_t guid) {
307
guid=(guid & 0xffffff0000000000LL)>>40;
308
QString key=QString::number((unsigned int)(guid), 16);
309
key=key.rightJustified(6, '0').toUpper();
310
QString v=m_vendorIds[key];
316
// ------------------------------------------------------------------------
318
#include "view1394.moc"