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>On the right hand side 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>"
84 QVBoxLayout
*box
=new QVBoxLayout(this);
85 box
->setSpacing(KDialog::spacingHint());
87 m_view
=new View1394Widget(this);
89 for (int i=2; i<8; i++)
90 m_view->m_listview->setColumnAlignment(i, Qt::AlignHCenter);
91 m_view->m_listview->setColumnAlignment(8, Qt::AlignRight);
92 m_view->m_listview->setColumnAlignment(9, Qt::AlignRight);
94 box
->addWidget(m_view
);
95 m_view
->layout()->setMargin(0);
96 connect(m_view
->m_busResetPb
, SIGNAL(clicked()), this, SLOT(generateBusReset()));
97 connect(&m_rescanTimer
, SIGNAL(timeout()), this, SLOT(rescanBus()));
101 View1394::~View1394() {
102 foreach(QSocketNotifier
* notifier
, m_notifiers
) {
110 bool View1394::readConfigRom(raw1394handle_t handle
, nodeid_t nodeid
, quadlet_t
& firstQuad
, quadlet_t
& cap
, octlet_t
& guid
) {
115 nodeaddr_t addr
=CSR_REGISTER_BASE
+ CSR_CONFIG_ROM
+ CONFIGROM_BASE
;
116 for (int count
=0; count
<5; count
++) {
119 int res
=raw1394_read(handle
, nodeid
|0xffc0, addr
, sizeof(q
), &q
);
126 select(0, 0, 0, 0, &tv
);
131 addr
=CSR_REGISTER_BASE
+ CSR_CONFIG_ROM
+ CONFIGROM_CAP
;
132 if (raw1394_read(handle
, nodeid
|0xffc0, addr
, sizeof(q
), &q
)!=0)
137 addr
=CSR_REGISTER_BASE
+ CSR_CONFIG_ROM
+ CONFIGROM_GUID_HI
;
138 if (raw1394_read(handle
, nodeid
|0xffc0, addr
, sizeof(q
), &q
)!=0)
141 guid
=octlet_t(ntohl(q
))<<32;
143 addr
=CSR_REGISTER_BASE
+ CSR_CONFIG_ROM
+ CONFIGROM_GUID_LO
;
144 if (raw1394_read(handle
, nodeid
|0xffc0, addr
, sizeof(q
), &q
)!=0)
152 void View1394::callRaw1394EventLoop(int fd
) {
153 for (QList
<raw1394handle_t
>::iterator it
= m_handles
.begin(); it
!=m_handles
.end(); ++it
)
154 if (raw1394_get_fd(*it
)==fd
) {
155 raw1394_loop_iterate(*it
);
160 void View1394::rescanBus() {
161 if (m_insideRescanBus
) {
162 m_rescanTimer
.setSingleShot(true);
163 m_rescanTimer
.start(100);
166 m_insideRescanBus
=true;
167 // static int depth=0;
170 for (QList
<raw1394handle_t
>::iterator it
=m_handles
.begin(); it
!=m_handles
.end(); ++it
)
171 raw1394_destroy_handle(*it
);
173 m_view
->m_listview
->clear();
175 raw1394handle_t handle
=raw1394_new_handle();
177 m_insideRescanBus
=false;
180 //now search for new stuff
181 struct raw1394_portinfo p_info
[MAX_1394_PORTS
];
182 int num_of_cards
=raw1394_get_port_info(handle
, p_info
, MAX_1394_PORTS
);
183 raw1394_destroy_handle(handle
);
184 //iterate over all cards
185 for (int i
=0; i
<num_of_cards
; i
++) {
186 handle
=raw1394_new_handle();
187 if (raw1394_set_port(handle
, i
)!=0) {
188 raw1394_destroy_handle(handle
);
191 raw1394_set_userdata(handle
, this);
192 raw1394_set_bus_reset_handler(handle
, my_reset_handler
);
193 QSocketNotifier
*notif
=new QSocketNotifier(raw1394_get_fd(handle
),QSocketNotifier::Read
);
194 connect(notif
, SIGNAL(activated(int)), this, SLOT(callRaw1394EventLoop(int)));
195 m_notifiers
.append(notif
);
196 m_handles
.append(handle
);
198 QStringList cardContents
;
199 cardContents
<< i18n("Port %1:\"%2\"", i
, p_info
[i
].name
);
200 QTreeWidgetItem
* card
= new QTreeWidgetItem(m_view
->m_listview
, cardContents
);
202 int num_of_nodes
=raw1394_get_nodecount(handle
);
204 int localNodeId
=raw1394_get_local_id(handle
);
205 //iterate over all nodes connected to this card
206 for (int j
=0; j
<num_of_nodes
; j
++) {
207 //get the guid of the node
209 quadlet_t firstQuad
=0;
211 bool success
=readConfigRom(handle
, j
, firstQuad
, cap
, guid
);
213 QString nodeStr
=i18n("Node %1", j
);
215 QStringList notReadyList
;
216 notReadyList
<< nodeStr
<< i18n("Not ready");
217 new QTreeWidgetItem(card
, notReadyList
);
221 if (((firstQuad
>>24) & 0xff)==1) {
222 QString guidStr
=QString::number(firstQuad
, 16);
223 guidStr
="0x"+guidStr
.rightJustified(6, '0');
226 romList
<< nodeStr
<< guidStr
;
227 new QTreeWidgetItem(card
, romList
);
233 snprintf(buf
, 32, "%llX", guid
);
235 guidStr
="0x"+guidStr
.rightJustified(16, '0');
236 QString local
=((j
| 0xffc0) == localNodeId
) ? "X" : "";
237 QString irmStr
=(cap
& 0x80000000) ? "X" : "";
238 QString cmStr
=(cap
& 0x40000000) ? "X" : "";
239 QString isStr
=(cap
& 0x20000000) ? "X" : "";
240 QString bmStr
=(cap
& 0x10000000) ? "X" : "";
241 QString pmStr
=(cap
& 0x08000000) ? "X" : "";
242 QString accStr
=QString::number((cap
&0x00ff0000)>>16);
243 int speed
=(cap
& 0x00000007);
261 QStringList nodeContents
;
262 nodeContents
<< nodeStr
<< guidStr
<< local
<< irmStr
<< cmStr
<< isStr
<< bmStr
<< pmStr
<< accStr
<< speedStr
<< m_ouiDb
->vendor(guid
);
264 new QTreeWidgetItem(card
, nodeContents
);
267 card
->setExpanded(true);
270 m_insideRescanBus
=false;
273 void View1394::generateBusReset() {
274 for (QList
<raw1394handle_t
>::iterator it
=m_handles
.begin(); it
!=m_handles
.end(); ++it
)
275 raw1394_reset_bus(*it
);
279 QString filename
=KStandardDirs::locate("data", "kcmview1394/oui.db");
280 if (filename
.isEmpty())
283 if (!f
.open(QIODevice::ReadOnly
))
286 QByteArray ba
=f
.readAll();
287 int bytesLeft
=ba
.size();
288 char* data
=ba
.data();
289 while (bytesLeft
>8) {
290 char *eol
=(char*)memchr((const void*)data
, '\n', bytesLeft
);
297 m_vendorIds
.insert(QLatin1String(data
), QString::fromUtf8(data
+7));
298 bytesLeft
-=(eol
+1-data
);
305 QString
OuiDb::vendor(octlet_t guid
) {
306 guid
=(guid
& 0xffffff0000000000LL
)>>40;
307 QString key
=QString::number((unsigned int)(guid
), 16);
308 key
=key
.rightJustified(6, '0').toUpper();
309 QString v
=m_vendorIds
[key
];
315 // ------------------------------------------------------------------------
317 #include "view1394.moc"