如何在Linux下写无线网卡的驱动【转】

转自:http://www.crifan.com/files/doc/docbook/linux_wireless/release/html/linux_wireless.html

 

版本:v0.3

How to write wireless network card driver under Linux

Crifan Li

摘要

本文主要介绍了Linux下的无线网络相关的基础知识,从网络到无线网络再到802.11的无线网络,然后再介绍Linux无线网络的框架,最后介绍如何在Linux的框架下编写无线驱动

本文提供多种格式供:

在线阅读 HTML HTMLs PDF CHM TXT RTF WEBHELP
下载(7zip压缩包) HTML HTMLs PDF CHM TXT RTF WEBHELP

HTML版本的在线地址为:

http://www.crifan.com/files/doc/docbook/linux_wireless/release/html/linux_wireless.html

有任何意见,建议,提交bug等,都欢迎去讨论组发帖讨论:

http://www.crifan.com/bbs/categories/linux_wireless/

2012-08-09

修订历史
修订 0.2 2011-07-02 crl
  1. 基本写好了一些名词的解释

修订 0.3 2012-08-09 crl
  1. 通过Docbook发布

版权 2012 Crifan, http://crifan.com

本文章遵从:署名-非商业性使用 2.5 中国大陆(CC BY-NC 2.5)


目录

缩略词
正文之前
1. 目的
2. 前提
3. 声明
4. 本文内容组织的逻辑
1. Network
1.1. OSI
1.2. Ethernet
1.3. 802 Related Specifications
2. Wireless LAN
2.1. 802.11
2.2. Bluetooth
2.3. IR
3. 80211 Wireless LAN
3.1. BSS
3.2. ESS
3.3. IBSS
3.4. DSS
3.5. SSID
3.6. Frame Type
3.7. 802.11 Beacons Related
3.8. Use RTS/CTS to avoid hidden station problem
3.9. CSMA/CA working flow
4. Linux Network
5. Linux Wireless LAN & 80211
5.1. 无线网络的架构
5.1.1. Framework
5.1.2. CRDA
5.1.3. Wext/WE
5.1.4. cfg80211
5.1.5. nl80211
5.1.6. Radiotap
5.1.7. Frame Reception/ Injection
5.1.8. MLME
5.1.9. FullMAC
5.1.10. SoftMAC
6. 以iwmc3200wifi为例,分析具体如何实现
6.1. 系统已经实现了哪些
6.2. 自己需要实现哪些
参考书目

插图清单

1.1. OSI参考模型以及不同层所对应的协议
1.2. 802.11和OSI模型
5.1. 旧的Linux的网络架构
5.2. 新的Linux的网络架构
5.3. 计划的Linux的网络架构
5.4. CRDA的架构

缩略词

常用缩略词如下:

A

AP (AP)

Access Point

B

BPSK (BPSK)

Binary Phase Shift Keying

BSS (BSS)

Basic Service Set

C

CCK (CCK)

Complementary Code Keying

CRC (CRC)

Cyclic Redundancy Check

CRDA (CRDA)

Central Regulatory Domain Agent

CSMA/CA (CSMA/CA)

Carrier Sense Multiple Access with Collision Avoidance

CSMA/CD (CSMA/CD)

Carrier Sense Multiple Access with Collision Detection

CTS (CTS)

Clear To Send

D

DCF (DCF)

Distribution Coordination Function

DHCP (DHCP)

Dynamic Host Configuration Protocol

()

 

DS (DS)

Distribution System

DSSS (DSSS)

Direct Sequence Spread Spectrum

E

ESS (ESS)

Extended Service Set

ETSI (ETSI)

European Telecommunications Standards Institute

F

FCC (FCC)

Federal Communications Commission (USA)

FDDI (FDDI)

Fiber Distributed Data Interface

FHSS (FHSS)

Frequency Hopping Spread Spectrum

I

IBSS (IBSS)

Independent Basic Service Set

参见BSS.

IEEE (IEEE)

Institute of Electrical and Electronics Engineers

()

 

IETF (IETF)

Internet Engineering Task Force

IP (IP)

Internet Protocol

IPSec (IPSec)

Internet Protocol security

ISA (ISA)

Integrated Services Architecture

ISM (ISM)

Industry, Scientific, and Medical

ISO (ISO)

International Organization for Standardization

ITU-T (ITU-T)

International Telecommunication Union-Telecommunication

L

LLC (LLC)

Logical Link Control

M

MAC (MAC)

Media Access Control

MIB (MIB)

Management Information Base

MKK (MKK)

Radio Equipment Inspection and Certification Institute (Japan)

N

NIC (NIC)

Network Interface Card

NOS (NOS)

Network Operating System

O

OSI (OSI)

Open System Interconnection

P

PCF (PCF)

Point Coordination Function

PCI (PCI)

Peripheral Component Interconnect

PRNG (PRNG)

Pseudo Random Number Generator

Q

QPSK (QPSK)

Quadrature Phase Shift Keying

R

RC4 (RC4)

Rivest Cipher 4

RTS (RTS)

Request to Send

S

SNMP (SNMP)

Simple Network Management Protocol

T

TCP/IP (TCP/IP)

Transmission Control Protocol/Internet Protocol

W

WECA (WECA)

Wireless Ethernet Compatibility Alliance

WEP (WEP)

Wired Equivalent Privacy

Wext (Wext)

Wireless Extension

WLAN (WLAN)

Wireless Local Area Network

WLANA (WLANA)

Wireless LAN Alliance

正文之前

目录

1. 目的
2. 前提
3. 声明
4. 本文内容组织的逻辑

1. 目的

  1. 搞懂如何写Linux无线网卡的驱动
  2. 记录所学知识。把自己搞懂的东西,能写到让别人也能理解的程度,因为这样才是真正理解了。另外现在理解了,以后还是会忘,而好记性不如烂笔头,万一哪天再需要用到这些知识,也方便查看和温习。
  3. 无线网络相关基础知识介绍:此贴不仅仅是要搞懂如何写Linux无线网卡驱动,因为在写驱动之前,肯定也要了解对应的无线网络基础知识,所以此贴也可以用作学习无线网络基础知识之用。

当然,写无线网卡驱动之前,肯定是不仅有了对应的硬件,也还要有无线网卡的datasheet(数据手册)。

再当然,写代码之前,肯定也要搞清楚Linux无线网络驱动的整体架构,

2. 前提

  1. 有一定的网络基础知识。
  2. 对Linux系统的驱动的基本架构有一定了解
  3. 最好有写过其他Linux驱动的经验,这样对于文中所述内容,会有更好的了解

3. 声明

  1. 鉴于书写和理解的方便,文中对于常见的缩写,就不一定全部都写中文了。而且表述内容的时候,有可能会出现中英文混杂,而且暂定一些内容,尽量用英文的术语,个人觉得这样有时候更容易把问题说的更透彻。
  2. 由于笔者知识有限,错误在所难免,欢迎指正错误和切磋。
  3. 任何人可以任意拷贝转载此文,但请注明出处。即版权所有,但欢迎传播。

4. 本文内容组织的逻辑

对于本文的组织内容的逻辑,简单解释一下。

此处,首先要搞懂我们的目的/目标是,好像听到旁边有人喊“没有蛀牙!”恭喜这位同学,你都抢答了!只可惜答案不对,囧。此文目的前面已经说了,就是想要搞懂如何去实现Linux下对应的无线网卡驱动。

而实现驱动之前,肯定至少要知道两件事情:

  • 一是硬件上,有哪些东西,他们是如何放置的。
  • 二是软件上,通信协议上,是如何实现通信的。

而对于硬件,无线网卡,就要知道其相关的基本名词,基本工作原理等等,对应的还有无线网络的知识。

而无线网络,是在有线网络之后才出现的,很多技术规范和设计等,也是参照和兼容有线网络而设计的,两者关系很紧密,所以也要知道有线网卡的一些知识。

最后,当然有线网络和无线网络,都属于网络,所以对于所涉及到的网络的基础知识,也要清楚。

正因此,才按照:

硬件:网络 + 有线网络 ⇒ 无线网络 ⇒ 80211无线网络

这样的顺序来介绍的。

而对于软件方面,无线网络驱动,是80211架构下的,而80211无线网络架构,也还是基于Linux的网络架构上的,所以要按照:

软件:Linux网络架构 ⇒ Linux下的80211 无线网络架构

来介绍的。

这样,将相关的硬件和软件的知识都介绍完了,也才能搞懂后面要介绍的,有哪些硬件,对应软件是如何工作的。

其中软件部分,知道Linux无线网络架构本身已经实现了哪些功能,剩下的部分,就是你要实现的驱动的细节部分,这样硬件和软件全部协同工作,才能让无线网卡正常工作。

第 1 章 Network

目录

1.1. OSI
1.2. Ethernet
1.3. 802 Related Specifications

摘要

1.1. OSI

OSI是一套规范的总称,包含了很多具体的协议标准,用于方便不同的系统之间互操作。OSI是ISO和ITU-U这两个组织定义的。

其中最有名的就是OSI参考模型,将网络分成不同Layer层次,并且为不同的Layer制定了相应的N多协议规范。

图示如下:

图 1.1. OSI参考模型以及不同层所对应的协议

对应的物理层和数据链路层,OSI所支持的介质访问协议包括:

  • IEEE 802.2 LLC
  • IEEE 802.3
  • Token Ring/IEEE 802.5
  • FDDI
  • X.25

而80211协议,只涉及最底层的,物理层和数据链路层。

下图是802.11和OSI模型的对应关系:

图 1.2. 802.11和OSI模型

对应的物理层方面,可能用到.FH/DS/IR/CCK/OFDM等技术,这部分后面会有详细解释。

1.2. Ethernet

NIC

 

 

1.3. 802 Related Specifications

 

 

第 2 章 Wireless LAN

目录

2.1. 802.11
2.2. Bluetooth
2.3. IR

摘要

无线信号传输方式有两种,窄带通信与扩频通信:

  • 窄带无线电通信(Narrow-Band Radio)

    这种技术类似于无线电台的广播,必须把发送器和接收器都调拨到同一频带。

    无线电信号可以穿越墙物,在一个很广的域内传播,所以不必把它调聚成束。

    然而,窄带射频发送有无线电波反射的问题,并受联邦通信委员会管制,它们必须准确地进行调谐,以防其它频率的干扰。

  • 扩展频谱通信(Spread Spectrum Communication)

    简称扩频通信,是一种信息传输方式,其信号所占有的频带宽度远大于所传信息必需的最小带宽。

    频带的扩展是通过一个独立的码序列(一般是伪随机码)来完成,用编码及调制的方法来实现的,与所传信息数据无关

    在接收端则用同样的码进行相关同步接收、解扩及恢复所传信息数据。

    这种技术是在一个很宽的频率范围内广播信号,避免在窄带无线电通信中遇到的问题。

    用一种编码来传播信号,接收站用同一编码来恢复信号。用这种方法,扩频无 线电信号能工作在其它信号所占据的频率范围内。

    扩频无线电信号不会干涉常规的无线电广播,这是因为它的能量十分微弱。

2.1. 802.11

 

 

 

2.2. Bluetooth

 

 

 

2.3. IR

 

 

 

第 3 章 80211 Wireless LAN

目录

3.1. BSS
3.2. ESS
3.3. IBSS
3.4. DSS
3.5. SSID
3.6. Frame Type
3.7. 802.11 Beacons Related
3.8. Use RTS/CTS to avoid hidden station problem
3.9. CSMA/CA working flow

摘要

3.1. BSS

  1. BSS

    BSS stands for Basic Service Set. The coverage of an access point is called a BSS.
  2. STA

    STA indicates a wireless device acting in in BSS as a regular STAtion.

3.2. ESS

 

3.3. IBSS

  1. IBSS

    IBSS stands for Independent Basic Service Set. Its basically Ad-Hoc mode.

    详情参考:

3.4. DSS

 

3.5. SSID

  1. SSID

    SSID stands for Service Set IDentifier. The SSID is a code attached to all packets on a wireless network to identify each packet as part of that network. The code consists of a string of 1-32 octets (usually represented as case sensitive alphanumeric characters).

    http://en.wikipedia.org/wiki/SSID

3.6. Frame Type

Frame Types

http://www.wi-fiplanet.com/tutorials/article.php/1447501

 

Management Frames:

  • Authentication

    Authentication frame, Deauthentication frame
  • Association

    Association request frame, Association response frame, Disassociation frame
  • Reassociation

    Reassociation request frame, Reassociation response frame
  • Beacon Frame

    Authentication frame, Deauthentication frame
  • Probe

    Probe request frame, Probe response frame

 

Control Frames

  • Request to Send (RTS) frame
  • Clear to Send (CTS) frame
  • Acknowledgement (ACK) frame

Data Frames

 

PLME

On the other hand PLME stands for Physical Layer Management Entity.

3.7. 802.11 Beacons Related

http://www.wi-fiplanet.com/tutorials/article.php/1492071/80211-Beacons-Revealed.htm

3.8. Use RTS/CTS to avoid hidden station problem

http://www.pulsewan.com/data101/802_11_b_basics.htm

Another MAC-layer problem specific to wireless is the ?hidden node? issue, in which two stations on opposite sides of an access point can both ?hear? activity from an access point, but not from each other, usually due to distance or an obstruction. To solve this problem, 802.11 specifies an optional Request to Send/Clear to Send (RTS/CTS) protocol at the MAC layer. When this feature is in use, a sending station transmits an RTS and waits for the access point to reply with a CTS. Since all stations in the network can hear the access point, the CTS causes them to delay any intended transmissions, allowing the sending station to transmit and receive a packet acknowledgment without any chance of collision. Since RTS/CTS adds additional overhead to the network by temporarily reserving the medium, it is typically used only on the largest-sized packets, for which retransmission would be expensive from a bandwidth standpoint.

3.9. CSMA/CA working flow

http://www.pulsewan.com/data101/802_11_b_basics.htm

CSMA/CA (Carrier Sense Multiple Access with Collision Avoidance) works as follows.

A station wishing to transmit senses the air, and, if no activity is detected, the station waits an additional, randomly selected period of time and then transmits if the medium is still free. If the packet is received intact, the receiving station issues an ACK frame that, once successfully received by the sender, completes the process. If the ACK frame is not detected by the sending station, either because the original data packet was not received intact or the ACK was not received intact, a collision is assumed to have occurred and the data packet is transmitted again after waiting another random amount of time.

第 4 章 Linux Network

摘要

已经实现了哪些层,(简单描述)有线网络是如何工作的

第 5 章 Linux Wireless LAN & 80211

目录

5.1. 无线网络的架构
5.1.1. Framework
5.1.2. CRDA
5.1.3. Wext/WE
5.1.4. cfg80211
5.1.5. nl80211
5.1.6. Radiotap
5.1.7. Frame Reception/ Injection
5.1.8. MLME
5.1.9. FullMAC
5.1.10. SoftMAC

摘要

Linux: Generic 2.6 Wireless Driver

http://kerneltrap.org/node/3245

这个解释了,当时为何选Host AP作为wireless stack 的来龙去脉。

 

5.1. 无线网络的架构

5.1.1. Framework

From: Page 6/47 Johannes Berg's presentation

Old:

图 5.1. 旧的Linux的网络架构

From: page 4/47 Johannes Berg's presentation

New:

图 5.2. 新的Linux的网络架构

From: page 5/47 Johannes Berg's presentation

Planned:

图 5.3. 计划的Linux的网络架构

5.1.2. CRDA

图 5.4. CRDA的架构

5.1.3. Wext/WE

Wireless Extensions的缩写, 是旧的Linux无线网络的架构,其基于mac80211。现在已逐渐转移到新的架构上面了,新的架构使用cfg80211nl80211

 

WE

WE stands for Wireless-Extensions - the old driver API and user <–> kernel communication transport.

5.1.4. cfg80211

新的Linux无线网络架构中,为驱动提供配置接口/API。

5.1.5. nl80211

新的Linux无线网络架构中,为内核空间和用户空间之间,提供通讯转换接口。

5.1.6. Radiotap

用于802.11的 帧接收(frame reception)和帧注入(frame injection)

5.1.7. Frame Reception/ Injection

所谓的帧接收,就是硬件(网卡)用中断通知CPU,一个数据帧到了,要CPU去接收。一般是在将无线网卡设置为 ???模式的时候,底层接受到数据帧之后,不处理,而是直接传送给上层处理,一般用于分析无线网络数据传输的时候,分析网络问题到底出现在哪。

5.1.8. MLME

MLME Stands for Media Access Control (MAC) Sublayer Management Entity. MLME is the management entity where the Physical layer (PHY) MAC state machines reside. Examples of states an MLME may assist in reaching:

5.1.9. FullMAC

FullMAC is a term used to describe a type of wireless card where the MLME is managed in hardware. You would not use mac80211 to write a FullMAC wireless driver.

5.1.10. SoftMAC

SoftMAC is a term used to describe a type of wireless card where the MLME is expected to be managed in software. mac80211 is a driver API for SoftMAC wireless cards, for example.

第 6 章 以iwmc3200wifi为例,分析具体如何实现

目录

6.1. 系统已经实现了哪些
6.2. 自己需要实现哪些

摘要

6.1. 系统已经实现了哪些

 

6.2. 自己需要实现哪些

 

参考书目

[1] Network related training meterials

[2] Linux Wireless - Developer Documentation

[3] MLME

[4] Glossary - Linux Wireless

[5] Understanding Linux Network Internals: Frame Reception

[6] Service set (802.11 network)

[7] Wireless Tools for Linux

[8] About Wireless-Extensions

[9] A bit more about the technologies involved

[10] Replacing iwconfig with iw

[11] 802.11学习笔记

[12] OSI Basic

[13] 无线网络的通信技术(窄带通信、扩频通信、packet网络,蜂窝网络)

[14] 扩展频谱通信

时间: 2024-07-28 17:29:57

如何在Linux下写无线网卡的驱动【转】的相关文章

linux驱动-linux下写驱动控制gpio时的两种方法区别

问题描述 linux下写驱动控制gpio时的两种方法区别 linux下写驱动控制gpio时,见过两种方法: 用request_mem_region函数和ioremap等得到控制寄存器的地址,然后用iowrite32函数控制该gpio 用gpio_request 和 gpio_set_value函数来控制gpio引脚 请问:这两种方法有什么区别,分别适用什么场合? 解决方案 http://blog.csdn.net/mirkerson/article/details/8464290http://b

脚本-如何在Linux下批量改C语言的作业?

问题描述 如何在Linux下批量改C语言的作业? 最近接到导师给的一个任务帮本科生改C语言作业.大概的界面是这样的需要测试每种输入: LuYang:CISB110-Programming Practice 1-41826 luyang$ ./mainChoose the type of speed conversion:1. knots to km/h2. km/h to knotsEnter your choice (1 or 2): 0Invalid optionLuYang:CISB110

python-如何在linux下开启守护进程

问题描述 如何在linux下开启守护进程 问题是这样的:我用python写了两个模块:Store.py,Search.py,在这两个文件中,分别会开启Store线程和Search线程.这两个线程是需要一直开启的,如果发现这两个线程挂了,需要重新开启. 我之前的做法是:在linux的begin.sh脚本中写下如下内容: #!/bin/bash python Store.py python Search.py 然后执行./begin.sh. 然后出现下面的问题: 由于Store.py中开启了线程,程

如何在Linux下监控系统温度

大多数情况下,你无需担心你的电脑温度.除非制造上的缺陷,否则硬件设计一般不会使其超过最高工作温度.但即使没有任何硬件故障,各种各样的软件问题也会导致硬件过热,例如,显卡驱动的严重bug,风扇控制程序的错误配置,CPU调频守护进程的故障,等等. 严重的过热可能会对硬件造成永久性的伤害,所以应当时刻小心系统上的任何过热问题.因此,如果有合适的温度监控系统,能在系统温度突然急速上升时,第一时间向用户发出警报,岂不美哉? 本教程,我将描述如何在Linux下监控系统温度. 在Linux下有许多用户级工具可

openni opencv linux-如何在linux下建立一个着openni和opencv的工程?

问题描述 如何在linux下建立一个着openni和opencv的工程? 如何在linux下建立一个着openni和opencv的工程?麻烦大神们详细解说下,不胜感激!!!!

如何在Linux下使用rsync

如何在Linux下使用rsync 对于各种组织和公司,数据对他们是最重要的,即使对于电子商务,数据也是同样重要的.Rsync是一款通过网络备份重要数据的工具/软件.它同样是一个在类Unix和Window系统上通过网络在系统间同步文件夹和文件的网络协议.Rsync可以复制或者显示目录并复制文件.Rsync默认监听TCP 873端口,通过远程shell如rsh和ssh复制文件.Rsync必须在远程和本地系统上都安装. rsync的主要好处是: 速度:最初会在本地和远程之间拷贝所有内容.下次,只会传输

c++-linux下C++无线网卡模式转换socket的问题

问题描述 linux下C++无线网卡模式转换socket的问题 linux下C++编程,由网卡模式转换到AP模式,再由AP模式转换到网卡模式时,链接不上. 发现第二次连接的新建的SOCKET(其中socket数值有和第一次的相同的) 只能bind()不能connect().请问大神可能是什么问题? 解决方案 你是客户端为何要bind() 要是你是服务端,又为何用connect()呢?

Linux有问必答:如何在Linux下重命名多个文件

Linux有问必答:如何在Linux下重命名多个文件 提问:我知道我可以用mv命令重命名文件.但是当我想重命名很多文件怎么办?如果为每个文件都这么做将会是很乏味的.有没有办法一次性重命名多个文件? 在Linux中,当你想要改变一个文件名,使用mv命令就好了.然而mv不能使用通配符重命名多个文件.可以用sed.awk或者与xargs结合使用来处理多个文件的情况.然而,这些命令行即繁琐又不友好,并且如果不小心的话还很容易出错.你不会想要撤销1000个文件的错误名吧! 当你想要重命名多个文件的时候,r

如何在linux下做软raid实现方法_unix linux

如何在linux下做软raid?希望以下介绍能对朋友们有所帮助和启发! 在虚拟机系统中添加一块10g的硬盘为sdb,将硬盘分5个逻辑盘分别是sdb{5,6,7,8,9},每个盘的大小是1G. 首先利用其中三块硬盘sdb{5,6,7}建立raid5,sdb8为热备盘. 然后将sdb6作为故障盘下线,之后拔出sdb6,插入新的盘sdb9. 命令如下:mdadm -C /dev/md0 -l5 -n3 -x1 /dev/sdb{5,6,7,8} 通过上面命令建立了使用空间为2G的raid5.盘符为/d