linux CS8900不能设置MAC地址的解决方法

来源:互联网 发布:丽新网络盒子 编辑:程序博客网 时间:2024/06/14 09:02

2440在linux系统下,设置MAC地址,提示siocsifhwaddr operation not supported,通过跟踪 dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)函数,发现调用了dev_set_mac_address函数去设置MAC地址,而在这个函数中需要先判断是否有在网卡初始化的时候,定义了设置的函数,

int dev_set_mac_address(struct net_device *dev, struct sockaddr *sa)
{
const struct net_device_ops *ops = dev->netdev_ops;
int err;


if (!ops->ndo_set_mac_address)//主要是这个返回为0,
return -EOPNOTSUPP;
if (sa->sa_family != dev->type)
return -EINVAL;
if (!netif_device_present(dev))
return -ENODEV;
err = ops->ndo_set_mac_address(dev, sa);
if (!err)
call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
return err;
}

根据查找到的原因,在CS8900的初始化函数中,加入函数就可以了,

static int __init cs8900_init (void)
{
struct net_device *ndev; 
ndev = alloc_etherdev(sizeof (cs8900_t)); 
const static struct net_device_ops new_netdev_ops ={ 
                 .ndo_init               = cs8900_probe, 
                 .ndo_open               = cs8900_start, 
                 .ndo_stop               = cs8900_stop, 
                 .ndo_start_xmit         = cs8900_send_start, 
                 .ndo_get_stats          = cs8900_get_stats, 
                 .ndo_set_multicast_list = cs8900_set_receive_mode, 
                 .ndo_tx_timeout         = cs8900_transmit_timeout, 
                 .ndo_change_mtu = eth_change_mtu,
.ndo_validate_addr= eth_validate_addr,
.ndo_set_mac_address= eth_mac_addr,//加入这句设置MAC地址的函数即可
};