使用无线扩展配置网络设备

用户3258845

我需要在 Linux 主机上用 C 为应用程序配置网络设备。我阅读了通过 cfg80211 和 mac80211 的 netlink、libnl 和 nl80211。后来发现我用的设备的驱动不支持mac80211接口,所以无法使用netlink库来配置设备。我剩下的唯一选择是通过使用 ioctl 的无线扩展。所以我一直在阅读 iwconfig 的源代码(iw 使用 netlink 而 iwconfig 使用 wext)。

例如,假设我试图在 80211 适配器上设置通道。无线扩展 ioctl 命令是 SIOCSIWFREQ(根据 iwconfig 和我的设备驱动程序)。根据我的阅读,您打开一个套接字并使用带有“ifreq”结构的 ioctl 来配置网络适配器(请参阅“man netdevice”)。

问题是,iwconfigure 定义了它自己的名为 'iwreq' 的 'ifreq' 结构,它看起来完全不同(参见 iwconfig 源代码,有一条评论说这个 iwreq 结构与 ifreq 结构相同)。

ifreq 结构看起来甚至没有设置通道的字段。

所以我的问题是,在内核中接收和处理这个“ifreq”结构的位置。我在哪里可以找到有关接口的文档(结构中的字段)。

所有 IOCTLS 命令都在 /usr/inlcude/linux/wireless.h 中定义

谢谢!

这是 ifreq:

struct ifreq {
    char ifr_name[IFNAMSIZ]; /* Interface name */
    union {
        struct sockaddr ifr_addr;
        struct sockaddr ifr_dstaddr;
        struct sockaddr ifr_broadaddr;
        struct sockaddr ifr_netmask;
        struct sockaddr ifr_hwaddr;
        short           ifr_flags;
        int             ifr_ifindex;
        int             ifr_metric;
        int             ifr_mtu;
        struct ifmap    ifr_map;
        char            ifr_slave[IFNAMSIZ];
        char            ifr_newname[IFNAMSIZ];
        char           *ifr_data;
    };
};

这是 iwreq(来自 HP 无线工具中的 wireless.h)

union   iwreq_data
{   
    /* Config - generic */
    char        name[IFNAMSIZ];
    /* Name : used to verify the presence of  wireless extensions.
    * Name of the protocol/provider... */

    struct iw_point essid;      /* Extended network name */
    struct iw_param nwid;       /* network id (or domain - the cell) */
    struct iw_freq  freq;       /* frequency or channel :
                                 * 0-1000 = channel
                                 * > 1000 = frequency in Hz */

    struct iw_param sens;       /* signal level threshold */
    struct iw_param bitrate;    /* default bit rate */
    struct iw_param txpower;    /* default transmit power */
    struct iw_param rts;        /* RTS threshold threshold */
    struct iw_param frag;       /* Fragmentation threshold */
    __u32       mode;       /* Operation mode */
    struct iw_param retry;      /* Retry limits & lifetime */

    struct iw_point encoding;   /* Encoding stuff : tokens */
    struct iw_param power;      /* PM duration/timeout */
    struct iw_quality qual;     /* Quality part of statistics */

    struct sockaddr ap_addr;    /* Access point address */
    struct sockaddr addr;       /* Destination address (hw/mac) */

    struct iw_param param;      /* Other small parameters */
    struct iw_point data;       /* Other large parameters */
};

struct  iwreq
{
    union
    {
      char    ifrn_name[IFNAMSIZ];    /* if name, e.g. "eth0" */
    } ifr_ifrn;

    /* Data part (defined just above) */
    union   iwreq_data  u;
};

很容易说出如何使用 iwreq 来配置通道、freq 字段,但是 ifreq 结构中的标准在哪里?

用户3258845

结构 iwreq 位于 linux/wireless.h 中,您可以简单地包含它并使用“iwreq”结构。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章