Ako vyriesit problem s programom, ktory nevracia DeviceName?


#1

Ahoj,

Mám problém s programom, ktorý od Fedora25 a vyšších nechce fungovať. Vedel by niekto, kto programuje veci do jadra, čo treba urobiť aby priložený kód po skompilovaní vyhodil názov sieťového adaptéru wifi?
Priložený program funguje s oficialnymi ovládačmi fy.Ralink/Mediatek stiahnutými z oficiálnej firemnej web stránky Mediatek, ktoré je potrebné fixnúť pre jadrá >= 3.x.
Pre jaderné ovládače nového API nl80211/cfg80211 nebude fungovať ak by to niekto chcel skúšať.

Na fedora24 to funguje a vyhodí DeviceName:
***************** Fedora 24 *****************
[uma@f24 ioctl]$ uname -a
Linux f24.local 4.10.10-100.fc24.x86_64 #1 SMP Thu Apr 13 01:12:25 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

[uma@f24 ioctl]$ gcc --version
gcc (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1)

[uma@f24 ioctl]$ make
gcc -O ioctl.c -o test

[uma@f24 ioctl]$ ./test ra0
PRIV_IOCTL: 0x00008be1
DeviceName: MT7610USTA

Na Fedora25 a vyšších to už nefunguje:
***************** Fedora 27 *****************
[uma@f27 ioctl]$ uname -a
Linux f27 4.15.9-300.fc27.x86_64 #1 SMP Mon Mar 12 17:07:55 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

[uma@f27 ioctl]$ gcc --version
gcc (GCC) 7.3.1 20180303 (Red Hat 7.3.1-5)

[uma@f27 ioctl]$ make
gcc -O ioctl.c -o test

[uma@f27 ioctl]$ ./test ra0
PRIV_IOCTL: 0x00008be1
Error: Device name not returned from PRIV_IOCTL for ra0

Priloha: zdrojovy kód programu pre ovládače wifi adaptérov Ralink/Mediatek požívajúcich API Wireless Extension


//  Test private ioctl for Wireless Extension

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/wireless.h>

#define PRIV_IOCTL                                  SIOCIWFIRSTPRIV + 0x01
#define RT_OID_DEVICE_NAME                          0x0607

int main(int argc, char** argv)
{
    int     socket_id, Status;
    struct  ifreq ifr;
    struct  iwreq wrq;
    char    DeviceName[IFNAMSIZ] = {0};
    char   *ptr = &DeviceName[0];
    char    iface[IFNAMSIZ] = {0};


    if (argc != 2) {
        printf("Usage: iotest interface\n");
        return 1;
    }

    if (strlen(argv[1]) < IFNAMSIZ) {
        memset(&ifr, 0, sizeof(ifr));
        strncpy(iface, argv[1], sizeof(argv[1]));
    } else {
        printf("interface name is too long\n");
        return 1;
    }

    socket_id = socket(AF_INET, SOCK_DGRAM, 0);
    if (socket_id == -1) {
        printf("Failed opening socket\n");
        return 1;
    }

    memset (&wrq, 0, sizeof (struct iwreq));

    // Copy the interface name in the iwreq structure
    strncpy(wrq.ifr_name, iface, sizeof(ifr.ifr_name));
    wrq.u.data.pointer = (caddr_t) ptr;                         // struct iwpoint   void __user	 *pointer; - Pointer to the data  (in user space)
    wrq.u.data.length  = (__u16)   255;                         // struct iwpoint   __u16	  length;  - number of fields or size in bytes
    wrq.u.data.flags   = (__u16)   RT_OID_DEVICE_NAME;          // struct iwpoint   __u16	  flags;   - Optional params

    printf("PRIV_IOCTL: 0x%08x\n", PRIV_IOCTL);

    // Get the WLAN device name
    Status = ioctl(socket_id, PRIV_IOCTL, &wrq);
    if (Status == -1) {
        printf("Error: Device name not returned from PRIV_IOCTL for %s\n", iface);
        return 1;
    } else {
        printf("DeviceName: %s\n", ptr);
    }
    close(socket_id);
    return 0;
}

Všetko čo sa týka Wireless Extension (WEXT) je v jadre f27 4.15.9-300.fc27 zapnuté
:konigurácia jadra pre wireless
CONFIG_WIRELESS=y
CONFIG_WIRELESS_EXT=y
CONFIG_WEXT_CORE=y
CONFIG_WEXT_PROC=y
CONFIG_WEXT_SPY=y
CONFIG_WEXT_PRIV=y
CONFIG_CFG80211=m

CONFIG_NL80211_TESTMODE is not set

CONFIG_CFG80211_DEVELOPER_WARNINGS is not set

CONFIG_CFG80211_REQUIRE_SIGNED_REGDB=y
CONFIG_CFG80211_USE_KERNEL_REGDB_KEYS=y
CONFIG_CFG80211_DEFAULT_PS=y
CONFIG_CFG80211_DEBUGFS=y
CONFIG_CFG80211_CRDA_SUPPORT=y
CONFIG_CFG80211_WEXT=y
CONFIG_CFG80211_WEXT_EXPORT=y
CONFIG_LIB80211=m
CONFIG_LIB80211_CRYPT_WEP=m
CONFIG_LIB80211_CRYPT_CCMP=m
CONFIG_LIB80211_CRYPT_TKIP=m

CONFIG_LIB80211_DEBUG is not set

CONFIG_MAC80211=m
CONFIG_MAC80211_HAS_RC=y
CONFIG_MAC80211_RC_MINSTREL=y
CONFIG_MAC80211_RC_MINSTREL_HT=y

CONFIG_MAC80211_RC_MINSTREL_VHT is not set

CONFIG_MAC80211_RC_DEFAULT_MINSTREL=y
CONFIG_MAC80211_RC_DEFAULT=“minstrel_ht”
CONFIG_MAC80211_MESH=y
CONFIG_MAC80211_LEDS=y
CONFIG_MAC80211_DEBUGFS=y

CONFIG_MAC80211_MESSAGE_TRACING is not set

CONFIG_MAC80211_DEBUG_MENU is not set

CONFIG_MAC80211_STA_HASH_MAX_SIZE=0

CONFIG_WIMAX is not set

CONFIG_RFKILL=m
CONFIG_RFKILL_LEDS=y
CONFIG_RFKILL_INPUT=y
CONFIG_RFKILL_GPIO=m

Za prínosné nápady vopred ďakujem.