1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-12-02 01:20:54 +00:00

- Battery tray icon is not displayed with more recent kdelibs releases

- Fix build on CURRENT by switching replacing 802.11 code using deprecated wi_req structures

Submitted by:	Peter Hofer <ph (at) desktopbsd.net>
Approved by:	miwi (mentor)
This commit is contained in:
Lars Engels 2007-09-07 20:02:13 +00:00
parent 1124bb0496
commit 8ebbe363ef
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=199042
7 changed files with 716 additions and 1 deletions

View File

@ -6,7 +6,7 @@
PORTNAME= desktopbsd-tools
PORTVERSION= 1.1
PORTREVISION= 1
PORTREVISION= 2
CATEGORIES= sysutils
MASTER_SITES= ftp://ftp.desktopbsd.net/

View File

@ -0,0 +1,144 @@
Index: Tray-BattInfo/batterytray.cpp
===================================================================
--- Tray-BattInfo/batterytray.cpp (Revision 454)
+++ Tray-BattInfo/batterytray.cpp (Revision 920)
@@ -1,7 +1,7 @@
/*
* This file is part of DesktopBSD, see the README file.
*
- * Author: Peter Hofer <hofer.p@gmail.com>
+ * Author: Peter Hofer <ph@desktopbsd.net>
* (C) 2004, 2005
*
* Copyright: BSD, see the COPYING file included in this distribution
@@ -26,14 +26,29 @@
#define _UPDATE_MAX 30
BatteryTray::BatteryTray() {
- contextMenu()->insertItem(DBSDGlobal::getIconLoader()->loadIcon("configure", DBSDIconLoader::Size16x16),
+ DBSDIconLoader *iloader = DBSDGlobal::getIconLoader();
+
+ contextMenu()->insertItem(iloader->loadIcon("configure", DBSDIconLoader::Size16x16),
tr("Configure..."), this, SLOT(openConfigDialog()));
+
+ imgBattery = iloader->loadIcon("dbsd-battinfo-battery", DBSDIconLoader::Size22x22)
+ .convertToImage();
+
+ imgRecharge = iloader->loadIcon("dbsd-battinfo-recharge", DBSDIconLoader::Size22x22)
+ .convertToImage();
+
+ pixPower = iloader->loadIcon("dbsd-battinfo-power", DBSDIconLoader::Size22x22);
+
+ previousRechargeLife = -1;
+ previousPowerSource = -1;
}
BatteryTray::~BatteryTray() {
}
-void BatteryTray::polish() {
+void BatteryTray::showEvent(QShowEvent *e) {
+ KSystemTray::showEvent(e);
+
uint updateTime = Battery::infoExpires();
/* Check for bad values and replace
@@ -44,7 +59,7 @@
else if(updateTime > _UPDATE_MAX)
updateTime = _UPDATE_MAX;
- updateTime = 2;
+ updateStatus();
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), SLOT(updateStatus()));
@@ -53,33 +68,30 @@
void BatteryTray::updateStatus() {
- DBSDIconLoader *iloader = DBSDGlobal::getIconLoader();
QImage image;
static bool lifeCriticalShown = false,
lifeLowShown = false;
- int acline = Battery::powerSource();
+ int powersrc = Battery::powerSource();
int time = Battery::getTime();
int life = Battery::getLife();
QString tipText = tr("Power Source: %1\n", "The power source of a mobile device");
- if(acline == Battery::PS_ACLine) {
+ if(powersrc == Battery::PS_ACLine) {
tipText = tipText.arg(tr("AC Line"));
if(life >= 0 && life <= 100)
- image = DBSDGlobal::getIconLoader()->loadIcon("dbsd-battinfo-recharge",
- DBSDIconLoader::Size22x22).convertToImage();
+ image = imgRecharge;
else
- setPixmap(iloader->loadIcon("dbsd-battinfo-power", DBSDIconLoader::Size22x22));
+ setPixmap(pixPower);
lifeCriticalShown = false;
lifeLowShown = false;
} else {
tipText = tipText.arg(tr("Battery"));
- image = DBSDGlobal::getIconLoader()->loadIcon("dbsd-battinfo-battery",
- DBSDIconLoader::Size22x22).convertToImage();
+ image = imgBattery;
if(!lifeCriticalShown) {
BatterySettings bs;
@@ -96,23 +108,36 @@
}
if(life >= 0 && life <= 100) {
- for(uint y = 0; y < (float) (image.height() - 9) / 100 * (100 - life) + 4; ++y)
- for(uint x = 0; x < image.width(); ++x) {
- uint rgba = image.pixel(x, y);
+ int rlife = (float) (image.height() - 9) / 100 * (101 - life) + 4;
+
+ if(rlife != previousRechargeLife || powersrc != previousPowerSource)
+ {
+ image.detach();
- /* Don't change transparent pixels */
- if(qAlpha(rgba) < 190)
- continue;
-
- QColor c;
- int h, s ,v;
- c.setRgb(rgba);
- c.getHsv(&h, &s, &v);
- c.setHsv(h, 0, ((v *= 1.1) > 255) ? 255 : v);
- image.setPixel(x, y, c.rgb());
+ for(uint y = 0; y < rlife; ++y)
+ {
+ for(uint x = 0; x < image.width(); ++x)
+ {
+ uint rgba = image.pixel(x, y);
+
+ /* Don't change transparent pixels */
+ if(qAlpha(rgba) < 190)
+ continue;
+
+ QColor c;
+ int h, s ,v;
+ c.setRgb(rgba);
+ c.getHsv(&h, &s, &v);
+ c.setHsv(h, 0, ((v *= 1.1) > 255) ? 255 : v);
+ image.setPixel(x, y, c.rgb());
+ }
}
- setPixmap(QPixmap(image));
+ previousPowerSource = powersrc;
+ previousRechargeLife = rlife;
+ pixPreviousRecharge = image;
+ setPixmap(pixPreviousRecharge);
+ }
tipText += tr("Battery Status: %1 %\n").arg(life);
}

View File

@ -0,0 +1,51 @@
Index: Tray-BattInfo/batterytray.h
===================================================================
--- Tray-BattInfo/batterytray.h (Revision 454)
+++ Tray-BattInfo/batterytray.h (Revision 920)
@@ -1,7 +1,7 @@
/*
* This file is part of DesktopBSD, see the README file.
*
- * Author: Peter Hofer <hofer.p@gmail.com>
+ * Author: Peter Hofer <ph@desktopbsd.net>
* (C) 2004, 2005
*
* Copyright: BSD, see the COPYING file included in this distribution
@@ -11,10 +11,13 @@
#ifndef __BATTERYTRAY_H
#define __BATTERYTRAY_H
-#include <qtimer.h>
#include <ksystemtray.h>
+
+#include <qpixmap.h>
#include <qimage.h>
+class QTimer;
+
class BatteryTray : public KSystemTray {
Q_OBJECT
@@ -23,11 +26,10 @@
virtual ~BatteryTray();
public slots:
- virtual void polish();
-
void updateStatus();
protected:
+ virtual void showEvent(QShowEvent *e);
virtual void mouseDoubleClickEvent(QMouseEvent *e);
protected slots:
@@ -35,6 +37,9 @@
private:
QTimer *timer;
+ QImage imgBattery, imgRecharge;
+ QPixmap pixPower, pixPreviousRecharge;
+ int previousRechargeLife, previousPowerSource;
};
#endif /* __BATTERYTRAY_H */

View File

@ -0,0 +1,181 @@
Index: libdesktopbsd/accesspoint.cpp
===================================================================
--- libdesktopbsd/accesspoint.cpp (Revision 454)
+++ libdesktopbsd/accesspoint.cpp (Revision 920)
@@ -1,47 +1,108 @@
/*
* This file is part of DesktopBSD, see the README file.
*
- * Author: Peter Hofer <hofer.p@gmail.com>
- * (C) 2004, 2005
+ * Author: Peter Hofer <ph@desktopbsd.net>
+ * (C) 2004-2007
*
* Copyright: BSD, see the COPYING file included in this distribution
*
*/
+
+ /*
+ * Copyright 2001 The Aerospace Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of The Aerospace Corporation may not be used to endorse or
+ * promote products derived from this software.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: /tmp/pcvs/ports/sysutils/desktopbsd-tools/files/Attic/patch-libdesktopbsd_accesspoint.cpp,v 1.1 2007-09-07 20:02:13 lme Exp $
+ */
+/*-
+ * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
#include "accesspoint.h"
-#include <qstring.h>
/** Initializes the access point with a wi_apinfo struct.
* This creates a deep copy of the given struct so you
* can safely delete it's wi_req struct afterwards.
*/
-AccessPoint::AccessPoint(const struct wi_apinfo& apinfo) {
+AccessPoint::AccessPoint(const struct ieee80211req_scan_result& apinfo, const QString & ssid) {
this->apinfo = apinfo;
+ this->ssid = ssid;
}
/** @return The station's SSID. */
QString AccessPoint::getSSID() const {
- return QString::fromAscii(apinfo.name, apinfo.namelen);
+ return ssid;
}
/** @returns The station's MAC address. */
QString AccessPoint::getBSSID() const {
- char bssid[18];
-
- snprintf(bssid, sizeof(bssid), "%02X:%02X:%02X:%02X:%02X:%02X",
- apinfo.bssid[0] & 0xFF,
- apinfo.bssid[1] & 0xFF,
- apinfo.bssid[2] & 0xFF,
- apinfo.bssid[3] & 0xFF,
- apinfo.bssid[4] & 0xFF,
- apinfo.bssid[5] & 0xFF);
-
- return bssid;
+ char *str = ether_ntoa((const struct ether_addr *) apinfo.isr_bssid);
+
+ if(str == NULL)
+ return "INVALID";
+
+ return QString(str).upper();
}
@@ -50,10 +111,10 @@
int AccessPoint::getCapInfo() const {
int capinfo = None;
- if(apinfo.capinfo & IEEE80211_CAPINFO_ESS)
+ if(apinfo.isr_capinfo & IEEE80211_CAPINFO_ESS)
capinfo |= ESS;
- if(apinfo.capinfo & IEEE80211_CAPINFO_PRIVACY)
+ if(apinfo.isr_capinfo & IEEE80211_CAPINFO_PRIVACY)
capinfo |= WEP;
return capinfo;
@@ -65,29 +126,14 @@
* is not 1, 2, 5.5 or 11 Mbps.
*/
double AccessPoint::getRate() const {
- double rate;
-
- switch(apinfo.rate) {
- case WI_APRATE_1:
- rate = 1;
- break;
-
- case WI_APRATE_2:
- rate = 2;
- break;
-
- case WI_APRATE_5:
- rate = 5.5;
- break;
-
- case WI_APRATE_11:
- rate = 11;
- break;
-
- default:
- rate = 0;
- break;
+ int maxrate = -1;
+
+ for (int i = 0; i < apinfo.isr_nrates; i++)
+ {
+ int rate = apinfo.isr_rates[i] & IEEE80211_RATE_VAL;
+ if (rate > maxrate)
+ maxrate = rate;
}
-
- return rate;
+
+ return (double) maxrate / 2;
}

View File

@ -0,0 +1,52 @@
Index: libdesktopbsd/accesspoint.h
===================================================================
--- libdesktopbsd/accesspoint.h (Revision 454)
+++ libdesktopbsd/accesspoint.h (Revision 920)
@@ -1,7 +1,7 @@
/*
* This file is part of DesktopBSD, see the README file.
*
- * Author: Peter Hofer <hofer.p@gmail.com>
+ * Author: Peter Hofer <ph@desktopbsd.net>
* (C) 2004, 2005
*
* Copyright: BSD, see the COPYING file included in this distribution
@@ -27,7 +27,7 @@
#include <dev/wi/if_wavelan_ieee.h>
#include <dev/wi/if_wireg.h>
-class QString;
+#include <qstring.h>
/** @brief Wireless Access-Point class.
*
@@ -45,23 +45,24 @@
};
- AccessPoint(const struct wi_apinfo&);
+ AccessPoint(const struct ieee80211req_scan_result &, const QString &);
QString getSSID() const;
/** @return Signal quality [dBm] */
- int getQuality() const { return apinfo.quality; }
+ int getQuality() const { return apinfo.isr_rssi / apinfo.isr_noise; }
/** @return Signal. */
- int getSignal() const { return apinfo.signal; }
+ int getSignal() const { return apinfo.isr_rssi; }
/** @return Signal noise */
- int getNoise() const { return apinfo.noise; }
+ int getNoise() const { return apinfo.isr_noise; }
QString getBSSID() const;
int getCapInfo() const;
double getRate() const;
private:
- struct wi_apinfo apinfo;
+ QString ssid;
+ struct ieee80211req_scan_result apinfo;
};
#endif /* __ACCESSPOINT_H */

View File

@ -0,0 +1,262 @@
Index: libdesktopbsd/wirelessinterface.cpp
===================================================================
--- libdesktopbsd/wirelessinterface.cpp (Revision 454)
+++ libdesktopbsd/wirelessinterface.cpp (Revision 920)
@@ -1,13 +1,79 @@
/*
* This file is part of DesktopBSD, see the README file.
*
- * Author: Peter Hofer <hofer.p@gmail.com>
- * (C) 2004, 2005
+ * Author: Peter Hofer <ph@desktopbsd.net>
+ * (C) 2004-2007
*
* Copyright: BSD, see the COPYING file included in this distribution
*
*/
+/*
+ * Copyright 2001 The Aerospace Corporation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. The name of The Aerospace Corporation may not be used to endorse or
+ * promote products derived from this software.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: /tmp/pcvs/ports/sysutils/desktopbsd-tools/files/Attic/patch-libdesktopbsd_wirelessinterface.cpp,v 1.1 2007-09-07 20:02:13 lme Exp $
+ */
+
+/*-
+ * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
#include "wirelessinterface.h"
#include <net/ethernet.h>
@@ -182,66 +248,40 @@
*
* @return QPtrList with the found access points.
*/
-QPtrList<AccessPoint> WirelessInterface::getAPs() {
- /* Status must be UP to be able to scan for ap's. */
+QPtrList<AccessPoint> WirelessInterface::getAPs()
+{
+ QPtrList<AccessPoint> list;
+
+ /* Some WiFi NICs need to be in link state UP to scan for networks */
+ up();
- if(up() < 0 && !isUp())
- /* up() failed and interface seems to be down,
- * so a scan would return nothing anyway.
- */
- return QPtrList<AccessPoint>();
+ uint8_t buffer[24 * 1024];
+ struct ieee80211req *ireq = getIReq(IEEE80211_IOC_SCAN_RESULTS, (uint8_t **) buffer, sizeof buffer, 0);
+ if(ireq == NULL)
+ return list;
- QPtrList<AccessPoint> list;
+ int length = ireq->i_len;
+ if (length < sizeof(struct ieee80211req_scan_result))
+ {
+ delete ireq;
+ return list;
+ }
- struct wi_req wreq;
- bzero(&wreq, sizeof(wreq));
- wreq.wi_len = WI_MAX_DATALEN;
- wreq.wi_type = WI_RID_READ_APS;
+ uint8_t *current = buffer;
+ do
+ {
+ struct ieee80211req_scan_result *sr = (struct ieee80211req_scan_result *) current;
+ list.append(new AccessPoint(*sr, copySSID((u_int8_t *) (sr + 1), (size_t) sr->isr_ssid_len)));
- if(wiGetVal(&wreq) < 0)
- return list;
-
- struct wi_apinfo *apinfos;
- apinfos = (struct wi_apinfo *) (((char *) &wreq.wi_val) + sizeof(int));
-
- int cnt = * (int *) wreq.wi_val;
- for(int i = cnt - 1; i >= 0; --i) {
- bool exists = false;
- for(int n = cnt - 1; n > i && !exists ; --n) {
- exists |= (bcmp(apinfos[n].bssid,
- apinfos[i].bssid,
- sizeof(apinfos[0].bssid)) == 0);
- }
-
- if(!exists)
- list.append(new AccessPoint(apinfos[i]));
+ current += sr->isr_len;
+ length -= sr->isr_len;
}
-
- return list;
+ while (length >= sizeof(struct ieee80211req_scan_result));
+
+ delete ireq;
+ return list;
}
-int WirelessInterface::wiGetVal(struct wi_req *wreq) const {
- if(wreq == NULL)
- return -1;
-
- struct ifreq ifr;
- int s, ret;
-
- bzero(&ifr, sizeof(ifr));
-
- strlcpy(ifr.ifr_name, getName(), sizeof(ifr.ifr_name));
- ifr.ifr_data = (caddr_t) wreq;
-
- s = socket(AF_INET, SOCK_DGRAM, 0);
- if(s == -1)
- return -1;
-
- ret = ioctl(s, SIOCGWAVELAN, &ifr);
- close(s);
-
- return ret;
-}
-
/** Returns a list with all wireless network interfaces. */
QPtrList<WirelessInterface> WirelessInterface::getWirelessIfs() {
QPtrList<WirelessInterface> lst;
@@ -285,9 +325,16 @@
}
+/** @param data pointer to a pointer to a uint8_t array with minimum size 32 */
+struct ieee80211req *WirelessInterface::getIReq(int type, uint8_t **data) const
+{
+ return getIReq(type, data, 0, -1);
+}
+
/** @param data pointer to a pointer to a uint8_t array with minimum size 32 */
-struct ieee80211req *WirelessInterface::getIReq(int type, uint8_t **data) const {
+struct ieee80211req *WirelessInterface::getIReq(int type, uint8_t **data, size_t len, int16_t val) const
+{
int s = newSocket();
if(s < 0)
return NULL;
@@ -297,7 +344,8 @@
strlcpy(ireq->i_name, getName(), sizeof ireq->i_name);
ireq->i_data = data;
ireq->i_type = type;
- ireq->i_val = -1;
+ ireq->i_len = len;
+ ireq->i_val = val;
if(ioctl(s, SIOCG80211, ireq) < 0) {
close(s);
@@ -309,3 +357,53 @@
return ireq;
}
+
+QString WirelessInterface::copySSID(const u_int8_t *essid, const size_t essid_len) const
+{
+ char buf[IEEE80211_NWID_LEN + 1];
+ int bufsize = sizeof(buf) - 1;
+ bzero(buf, sizeof(buf));
+
+ const u_int8_t *p;
+ size_t maxlen;
+ int i;
+
+ if (essid_len > bufsize)
+ maxlen = bufsize;
+ else
+ maxlen = essid_len;
+ /* determine printable or not */
+ for (i = 0, p = essid; i < maxlen; i++, p++) {
+ if (*p < ' ' || *p > 0x7e)
+ break;
+ }
+ if (i != maxlen) { /* not printable, print as hex */
+
+ /* Check for hidden SSIDs (filled with zeroes) */
+ for(i = 0; i < maxlen; ++i)
+ {
+ if(*p != 0)
+ break;
+ }
+ if(i == maxlen)
+ return QString();
+
+ if (bufsize < 3)
+ return "INVALID";
+ strlcpy(buf, "0x", bufsize);
+ bufsize -= 2;
+ p = essid;
+ for (i = 0; i < maxlen && bufsize >= 2; i++) {
+ sprintf(&buf[2+2*i], "%02x", p[i]);
+ bufsize -= 2;
+ }
+ if (i != essid_len)
+ memcpy(&buf[2+2*i-3], "...", 3);
+ } else { /* printable, truncate as needed */
+ memcpy(buf, essid, maxlen);
+ if (maxlen != essid_len)
+ memcpy(&buf[maxlen-3], "...", 3);
+ }
+
+ return QString(buf);
+}

View File

@ -0,0 +1,25 @@
Index: libdesktopbsd/wirelessinterface.h
===================================================================
--- libdesktopbsd/wirelessinterface.h (Revision 454)
+++ libdesktopbsd/wirelessinterface.h (Revision 920)
@@ -1,7 +1,7 @@
/*
* This file is part of DesktopBSD, see the README file.
*
- * Author: Peter Hofer <hofer.p@gmail.com>
+ * Author: Peter Hofer <ph@desktopbsd.net>
* (C) 2004, 2005
*
* Copyright: BSD, see the COPYING file included in this distribution
@@ -47,9 +47,10 @@
static QPtrList<WirelessInterface> getWirelessIfs();
private:
- int wiGetVal(struct wi_req *) const;
int set80211(int, int, int, uint8_t *) const;
struct ieee80211req *getIReq(int, uint8_t **) const;
+ struct ieee80211req *getIReq(int, uint8_t **, size_t, int16_t) const;
+ QString copySSID(const uint8_t *, const size_t) const;
int hexToNumber(char) const;
};