wifi设备名称顺序调换

1、设备名称是如何创建的

#define WIFI_DEV_NAME_PDEV    "wifi%d"

qdf_netdev_t wlan_create_pdev_netdevice(struct wlan_objmgr_psoc *psoc,
                        uint8_t id)
{
......

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
    
    dev = alloc_netdev(sizeof(struct ol_ath_softc_net80211),
            soc->is_sim ? "wifi-sim%d" : radio_if,
            0,
            ether_setup);

......

}

[   34.119604] wlan: [1328:I:ANY] __ol_ath_attach: 4320: pdev_netdev name wifi2

__ol_ath_attach(){

     dev_alloc_name(pdev_netdev, pdev_netdev->name);

}

/**
 *    dev_alloc_name - allocate a name for a device
 *    @dev: device
 *    @name: name format string
 *
 *    Passed a format string - eg "lt%d" it will try and find a suitable
 *    id. It scans list of devices to build up a free map, then chooses
 *    the first empty slot. The caller must hold the dev_base or rtnl lock
 *    while allocating the name and adding the device in order to avoid
 *    duplicates.
 *    Limited to bits_per_byte * page size devices (ie 32K on most platforms).
 *    Returns the number of the unit assigned or a negative errno code.
 */

int dev_alloc_name(struct net_device *dev, const char *name)
{
    char buf[IFNAMSIZ];
    struct net *net;
    int ret;

    BUG_ON(!dev_net(dev));
    net = dev_net(dev);
    ret = __dev_alloc_name(net, name, buf);
    if (ret >= 0)
        strlcpy(dev->name, buf, IFNAMSIZ);
    return ret;
}

/**
 *    __dev_alloc_name - allocate a name for a device
 *    @net: network namespace to allocate the device name in
 *    @name: name format string
 *    @buf:  scratch buffer and result name string
 *
 *    Passed a format string - eg "lt%d" it will try and find a suitable
 *    id. It scans list of devices to build up a free map, then chooses
 *    the first empty slot. The caller must hold the dev_base or rtnl lock
 *    while allocating the name and adding the device in order to avoid
 *    duplicates.
 *    Limited to bits_per_byte * page size devices (ie 32K on most platforms).
 *    Returns the number of the unit assigned or a negative errno code.
 */

static int __dev_alloc_name(struct net *net, const char *name, char *buf)
{
    int i = 0;
    const char *p;
    const int max_netdevices = 8*PAGE_SIZE;
    unsigned long *inuse;
    struct net_device *d;

    p = strnchr(name, IFNAMSIZ-1, '%');
    if (p) {
        /*
         * Verify the string as this thing may have come from
         * the user.  There must be either one "%d" and no other "%"
         * characters.
         */
        if (p[1] != 'd' || strchr(p + 2, '%'))
            return -EINVAL;

        /* Use one page as a bit array of possible slots */
        inuse = (unsigned long *) get_zeroed_page(GFP_ATOMIC);
        if (!inuse)
            return -ENOMEM;

        for_each_netdev(net, d) {
            if (!sscanf(d->name, name, &i))
                continue;
            if (i < 0 || i >= max_netdevices)
                continue;

            /*  avoid cases where sscanf is not exact inverse of printf */
            snprintf(buf, IFNAMSIZ, name, i);
            if (!strncmp(buf, d->name, IFNAMSIZ))
                set_bit(i, inuse);
        }

        i = find_first_zero_bit(inuse, max_netdevices);
        free_page((unsigned long) inuse);
    }

    if (buf != name)
        snprintf(buf, IFNAMSIZ, name, i);
    if (!__dev_get_by_name(net, buf))
        return i;

    /* It is possible to run out of possible slots
     * when the name is long and there isn't enough space left
     * for the digits, or if all bits are used.
     */
    return -ENFILE;
}

2、修改方法

/* Support to change radio interface id of offload radio */
#define WIFI_DEV_NUM_MAX    3
static unsigned int wifi_start_idx = 0;
module_param(wifi_start_idx, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
MODULE_PARM_DESC(wifi_start_idx,
        "Radio interface id for offload chips");

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)
    //switch wifi index .zk.20210118
    if(0 == wifi_start_idx){
        snprintf(radio_if, IFNAMSIZ, "%s%d", "wifi", 1);
        wifi_start_idx++;
    }else if(1 == wifi_start_idx){
        snprintf(radio_if, IFNAMSIZ, "%s%d", "wifi", 0);
        wifi_start_idx++;
    }else{
        snprintf(radio_if, IFNAMSIZ, "%s%d", "wifi", 2);
    }

    
    dev = alloc_netdev(sizeof(struct ol_ath_softc_net80211),
            soc->is_sim ? "wifi-sim%d" : radio_if,
            0,
            ether_setup);

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

huzk4409

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值