KernelPanic KernelPanic - 2 months ago 25
Linux Question

iwlib trying to get access point name - u.addr.sa_data contains suspicious characters resulting empty QString

I have following simple method:

const QString& UeNetworkManager::ueAccessPointMACAddress(const QString& interfaceName) const
{
static QString ueMACAddress=QString();
iwreq wrq;
int result=0;
int kernelSocket=iw_sockets_open();

ueMACAddress.clear();

result=iw_get_ext(kernelSocket,
interfaceName.toLocal8Bit().constData(),
SIOCGIWAP,
&wrq);

ueMACAddress=result>=0?QString(wrq.u.addr.sa_data):"Invalid MAC address";

iw_sockets_close(kernelSocket);

return ueMACAddress;
} // ueAccessPointMACAddress


Now, I would like to extract Access Point MAC address using this method from
wrq
structure - its
u.addr.sa_data
member, which (I THINK SO, AM NOT SURE) containts MAC address of Access Point. Follownig debug screenshot shows value of
u.addr.sa_data
member:
QtCreatorDebugScenario
Why am I getting empty
QString
after
ueMACAddress=result>=0?QString(wrq.u.addr.sa_data):"Invalid MAC address";
line of code?

Answer

It seems I've used wrong command, here is working method:

const QStringList& UeNetworkManager::ueAccessPointMACAddresses(const QString& interfaceName)
{
    static QStringList ueMACAddresses=QStringList();
    iwrange rangeScan;
    wireless_scan_head scanResultHead;
    wireless_scan* scanResult=Q_NULLPTR;
    int kernelSocket=iw_sockets_open();

    ueMACAddresses.clear();

    if(iw_get_range_info(kernelSocket,
                         interfaceName.toLocal8Bit().constData(),
                         &rangeScan)>=0)
    {
        if(iw_scan(kernelSocket,
                   interfaceName.toLocal8Bit().data(),
                   rangeScan.we_version_compiled,
                   &scanResultHead)>=0)
        {
            scanResult=scanResultHead.result;

            while(scanResult!=Q_NULLPTR)
            {
                ueMACAddresses.append(QByteArray(scanResult->ap_addr.sa_data).toHex());

                scanResult=scanResult->next;
            }   // while
        }
        else
        {
            ueMACAddresses.append(tr("MAC scan failed."));
        }   // if
    }
    else
    {
            ueMACAddresses.append(interfaceName+
                                  " "+
                                  tr("range scan failed."));
    }   // if

    iw_sockets_close(kernelSocket);

    return ueMACAddresses;
}   // ueAccessPointMACAddress