看了几天代码,有些关系终于有些眉目,可以串起来了。
由于wireless设备是pci设备,因此在insmod驱动以后,会调用.probe函数。
.probe = xxx_probe.
在xxx_probe的实现中有几个值得注意的地方。
void xxx_probe()
{
//ieee80211_alloc_hw会分配跟驱动以及硬件相关的数据,有空的话把分配的图贴上来
struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len, const struct ieee80211_ops *ops)
接着会有irq io 以及memory等资源的申请
dma等等
...
//硬件资源分配完成后会调用该函数向内核注册。
int ieee80211_register_hw(struct ieee80211_hw *hw)
{
...
//这个函数尤其值得注意,通过该函数创建了名为wlanX的net_ device的数据结构,并向全局的网络设备链表中插入该数据结构
result = ieee80211_if_add(local, "wlan%d", NULL,
NL80211_IFTYPE_STATION, NULL);
int ieee80211_if_add(struct ieee80211_local *local, const char *name,
struct net_device **new_dev, enum nl80211_iftype type,
struct vif_params *params)
{ndev = alloc_netdev_mq(sizeof(*sdata) + local->hw.vif_data_size,
name, ieee80211_if_setup, local->hw.queues);
}
...
}
}
net_device是网络中最重要的数据结构了。这个在linux设备驱动程序以及understanding linux network internals中都有描述。
现在来说ifconfig wlan0 up这个命令.
在linux设备驱动程序508页有详细描述,这里就不再说明了。
这些关系现在理解应该是这样,并且可以串起来了。如果以后觉得理解有偏差,再来补充。
:)