QList<quint32> CWextHW::getSupportedChannels() const { QList<quint32> chans; for (qint32 freq: m_supportedFrequencies) { qint32 chan = frequencyToChannel(freq); if (chan > 0) chans.append(chan); } return chans; }
QList<quint32> CNL80211::getSupportedChannels() { QList<quint32> chans; qint32 chan; foreach(qint32 freq, m_supportedFrequencies) { chan = frequencyToChannel(freq); if (chan > 0) chans.append(chan); }
void CWextHW::readSignalQuality() { if ( (m_wextFd == -1) ) { return; } struct iw_range range; memset(&range,0,sizeof(struct iw_range)); int hasRange = 0; iwstats stats; memset(&stats,0,sizeof(iwstats)); WextRawScan res; /* workaround */ struct wireless_config wifiConfig; memset(&wifiConfig,0,sizeof(struct wireless_config)); /* Get basic information */ if(iw_get_basic_config(m_wextFd, m_ifname.toAscii().constData(), &wifiConfig) < 0) { /* If no wireless name : no wireless extensions */ /* But let's check if the interface exists at all */ struct ifreq ifr; memset(&ifr,0,sizeof(struct ifreq)); strncpy(ifr.ifr_name, m_ifname.toAscii().data(), IFNAMSIZ); if(ioctl(m_wextFd, SIOCGIFFLAGS, &ifr) < 0) qWarning() << tr("(Wireless Extension) No device present"); else qWarning() << tr("(Wireless Extension) device not supported"); return; } qDebug() << "Fetched basic config."; //We encode frequency in mhz; //kernel encodes as double; (hopefully always in hz) //But better test this: res.freq = -1; if (wifiConfig.has_freq) { if ( ( (wifiConfig.freq/1e9) < 10.0 ) && ( (wifiConfig.freq/1e9) > 0.0 ) ) { res.freq = (int) (wifiConfig.freq/1e6); } } struct iwreq wrq; memset(&wrq,0,sizeof(struct iwreq)); /* Get AP address */ if(iw_get_ext(m_wextFd, m_ifname.toAscii().data(), SIOCGIWAP, &wrq) >= 0) { //Add mac address of current ap; res.bssid = libnutcommon::MacAddress((ether_addr*)wrq.u.ap_addr.sa_data); qDebug() << "Got AP: " << res.bssid.toString(); } /* Get ssid */ quint8 * buffer = new quint8[IW_ESSID_MAX_SIZE]; memset(buffer, '\0', IW_ESSID_MAX_SIZE); wrq.u.essid.pointer = (void *)buffer; wrq.u.essid.length = IW_ESSID_MAX_SIZE; if(iw_get_ext(m_wextFd, m_ifname.toAscii().data(), SIOCGIWESSID, &wrq) >= 0) { if (wrq.u.essid.length > IW_ESSID_MAX_SIZE) wrq.u.essid.length = IW_ESSID_MAX_SIZE; if (wrq.u.essid.flags) { /* Does it have an ESSID index ? */ if ( wrq.u.essid.pointer && wrq.u.essid.length ) { if ( (wrq.u.essid.flags & IW_ENCODE_INDEX) > 1) { res.ssid = QString("%1 [%2]").arg(QString::fromAscii((char*) wrq.u.essid.pointer, wrq.u.essid.length), QString::number(wrq.u.essid.flags & IW_ENCODE_INDEX)); } else { res.ssid = QString::fromAscii((char*) wrq.u.essid.pointer, wrq.u.essid.length); } } else { res.ssid = "N/A"; } } qDebug() << "Got ssid: " << res.ssid; } delete[] buffer; /* Get bit rate */ if(iw_get_ext(m_wextFd, m_ifname.toAscii().data(), SIOCGIWRATE, &wrq) >= 0) { res.bitrates.append((qint32) wrq.u.bitrate.value); qDebug() << "Got bit rate: " << res.bitrates[0]; } /* Get Power Management settings */ wrq.u.power.flags = 0; if(iw_get_ext(m_wextFd, m_ifname.toAscii().data(), SIOCGIWPOWER, &wrq) >= 0) { qDebug() << "Got power"; } /* workaround */ /* Get range stuff */ qDebug() << QString("Getting range stuff for %1").arg(m_ifname.toAscii().data()); if (iw_get_range_info(m_wextFd, m_ifname.toAscii().data(), &range) >= 0) { hasRange = 1; qDebug() << "Success readWirelessInfo getrange" << strerror(errno); } else { //This is VERY strange: we always get the "operation not permitted" error, although iw_get_range() worked qDebug() << QString("Error \"hasRange == 0\" (%1)").arg(strerror(errno)); } res.hasRange = hasRange; if (errno == EAGAIN) { m_sqTimeOutCount++; qDebug() << QString("Getting range stuff failed (%1)").arg(strerror(errno)); if ( (m_sqTimeOutCount > 10) && m_sqPollrate < 1000) { setSignalQualityPollRate(10000); } else if (m_sqTimeOutCount > 10) { //Fast polling disabled, but still EAGAIN errors //Seems the kernel does not care about our calls killTimer(m_sqTimerId); m_sqTimerId = -1; } return; } qDebug() << "Got range stuff"; //Set supported Frequencies if the list is not empty; if (m_supportedFrequencies.isEmpty() && hasRange) { qDebug() << range.num_frequency; qDebug() << "Printing Frequency information"; quint32 m; quint16 e; quint32 freqinmhz; for (int i=0; i < range.num_channels; i++) { m = (quint32) range.freq[i].m; e = (quint16) range.freq[i].e; freqinmhz = m; for (int j=0; j < 9-e-3; j++) { freqinmhz = freqinmhz/10; } if (!m_supportedFrequencies.contains(freqinmhz)) { //Only add frequency that are not in our list m_supportedFrequencies.append(freqinmhz); } qDebug() << m << e << freqinmhz << frequencyToChannel(freqinmhz); } qDebug() << "Done printing"; } else { qDebug() << "m_supportedFrequencies not set"; } if (hasRange) { res.maxquality.level = (quint8) range.max_qual.level; res.maxquality.qual = (quint8) range.max_qual.qual; res.maxquality.noise = (quint8) range.max_qual.noise; res.maxquality.updated = (quint8) range.max_qual.updated; qDebug() << "RANGE: " << res.maxquality.level << res.maxquality.qual << res.maxquality.noise << res.maxquality.updated; } else { res.maxquality.level = 0; res.maxquality.qual = 0; res.maxquality.noise = 0; res.maxquality.updated = 0; qDebug() << "Range information are not available"; } if ( (hasRange) && (range.we_version_compiled > 11) ) { struct iwreq wrq; memset(&wrq,0,sizeof(struct iwreq)); wrq.u.data.pointer = (caddr_t) &stats; wrq.u.data.length = sizeof(struct iw_statistics); wrq.u.data.flags = 1; // Clear updated flag strncpy(wrq.ifr_name, m_ifname.toAscii().data(), IFNAMSIZ); qDebug() << "Getting wireless stats"; if(iw_get_ext(m_wextFd, m_ifname.toAscii().data(), SIOCGIWSTATS, &wrq) < 0) { qWarning() << tr("Error occured while fetching wireless info: ") << strerror(errno); } else { //Stats fetched qDebug() << "Stats fetched"; res.quality.level = (quint8) stats.qual.level; res.quality.qual = (quint8) stats.qual.qual; res.quality.noise = (quint8) stats.qual.noise; res.quality.updated = (quint8) stats.qual.updated; qDebug() << "STATS: " << res.quality.level << res.quality.qual << res.quality.noise << res.quality.updated; m_sq = convertValues(res); qDebug() << "Emittig m_signalQualityUpdated()"; if (m_sqPollrate < 1000) { setSignalQualityPollRate(10000); emit message(tr("Auto-resetting timer to 10 seconds")); } emit signalQualityUpdated(m_sq); } } else if (range.we_version_compiled <= 11) { emit message(tr("Cannot fetch wireless information as your wireless extension is too old")); emit message(tr("Think about updating your kernel (it's way too old)")); } else { qDebug() << "Error while trying to fetch wireless information" << strerror(errno); qDebug() << "Wireless Extension socket file descriptor was: " << m_wextFd; } }