802.11帧格式

  注1:本文STA为station简称,AP为access piont简称。
  注2:本文属于个人理解,存在错误望见谅和指正。

1.MAC帧格式

 

1.1 地址格式  

    addr1:接收地址(所有包都包含它)
    addr2:传输地址(除ACK和CTS包外的其他包都包含它)
    addr3:只用于管理包和数据包。
    addr4:无线分布系统模式下,FROM DS和TO DS都被置位时使用。
    下图中,占两个字节的Frame control ,其To DS和From Ds决定了这四个地址的使用。
   ;
    地址对应表如下:
    DS是分布式系统的简称,我们用它以区分不同类型帧中关于地址的解析方式。
        To DS=0,From DS=0:表示Station之间的AD Hoc类似的通信,或者控制侦、管理侦。
        To DS=0,From DS=1:Station接收的侦。
        To DS=1,From DS = 0:Station发送的侦。
        To DS=1,From DS = 1:无线桥接器上的数据侦。
     各地址的解释:
        SRC:源地址(SA),和以太网中的一样,就是发帧的最初地址,在以太网和wifi中帧格式转换的时候,互相可以直接复制。
        DST:目的地址(DA),和以太网中的一样,就是最终接受数据帧的地址,在以太网和wifi中帧格式转换的时候,互相可以直接复制。
        TX:也就是Transmiter(TA),表示无线网络中目前实际发送帧者的地址(可能是最初发帧的人,也可能是转发时候的路由)。
        RX:也就是Receiver(RA),表示无线网络中,目前实际接收帧者的地址(可能是最终的接收者,也可能是接收帧以便转发给接收者的ap)。
    注:无线网络中的 Station想要通信,必须经过AP来进行“转发”。其实,Tx和Rx是无线网络中的发和收,也就是Radio;而Src和Dst是真正的发送源和接收者

2 帧类型

    帧类型由frame control的type两位决定,目前有三种类型的帧:
    00,管理帧。IEEE80211_TYPE_MGMT 用于执行管理操作,如关联、身份验证,扫描等。
    01,控制帧。IEEE80211_TYPE_CTL 通常与数据包相关。如:PS-poll包用于从AP缓冲区取回数据包;另一个例子,STA若想数据传输,首先会发送RTS的控制数据包,如果介质空闲,目标客户端将发回一个名为允许发送(CTS)的控制数据包。
    10,数据帧。IEEE80211_TYPE_DATA 原始数据包。注:空数据包是特殊的数据帧,其用于电源管理。
    11,保留。

2.1 SubType

2.1.1 管理帧 type 00

    下表为管理帧的subType对应的类型(即type为00时,subType的取值)
    
Type   FrameType
00 0000 Association request (连接请求)
00 0001 Association response (连接响应)
00 0010 Reassociation request(重连接请求)
00 0011 Reassociation response(重连接联响应)
00 0100 Probe request(探测请求)
00 0101 Probe response(探测响应)
00 1000 Beacon(信标,被动扫描时AP 发出,notify)
00 1001 ATIM(通知传输指示消息)
00 1010 Disassociation(解除连接,notify)
00 1011 Authentication(身份验证)
00 1100 Deauthentication(解除认证,notify)
00 1101~1111 Reserved(保留,未使用)
 

2.1.1.1(Beacon(信标)帧)  subtype 1000

 
    抓包显示的结果:
 
 
    由于Beacon是广播包,因此DA为FF:FF:FF:FF:FF:FF。
    作用:向STA广播AP的存在。也就是我们平时能够搜到AP的原因,其包含了AP的相关信息。

 

2.1.1.2 (Probe Request(探测请求)帧) subtype 0100

    抓包显示的结果:
    作用:STA广播发出,与AP建立关联的必然步骤,后面会具体说明。

2.1.1.3 (Probe Response(探测响应)帧) subtype 0101

    作用:STA请求探测帧后,AP的相对应的回应帧。
 

2.1.1.4 (ATIM帧)  subtype  1001

2.1.1.5 (Disassociation(解除关联)与Deauthentication(解除认证)帧) subtype 1010

2.1.1.6 (Association Request(关联请求)帧) subtype 0000

2.1.1.7 (Reassociation Request(重新关联请求)帧) subtype 0010

                                                

2.1.1.8 (Authentication(身份认证)帧) subtype 1011

 

2.1.2 数据帧 type 10

Type Subtype Frametype
10 0000 Data(数据)
10 0001 Data+CF-ACK
10 0010 Data+CF-Poll
10 0011 Data+CF-ACK+CF-Poll
10 0100 Null data(无数据:未传送数据)
10 0101 CF-ACK(未传送数据)
10 0110 CF-Poll(未传送数据)
10 0111 Data+CF-ACK+CF-Poll
10 1000 Qos Data
10 1001 Qos Data + CF-ACK
10 1010 Qos Data + CF-Poll
10 1011 Qos Data + CF-ACK+ CF-Poll
10 1100 QoS Null(未传送数据)
10 1101 QoS CF-ACK(未传送数据)
10 1110 QoS CF-Poll(未传送数据)
10 1111 QoS CF-ACK+ CF-Poll(未传送数据)
   
 
 
 
 
 
 
 
 
 
2.1.2.1 IBSS subtype  (0000 Data,0100NULL)
 
 
 
2.1.2.2  From AP  subtype如图所示
 
2.1.2.3 To AP 
2.1.2.4 WDS帧 subtype null
 

2.1.3 控制帧 type 01

    主要用于数据传输前的控制,相关过程请看4.0 RTS/CTS。
 
Type Subtype Frametype
01 1010 Power Save(PS)- Poll(省电-轮询)
01 1011 RTS(请求发送,即: Request To Send ,预约信道,帧长20字节)
01 1100 CTS(清除发送,即:Clear To Send ,同意预约,帧长14字节)
01 1101 ACK(确认)
01 1110 CF-End(无竞争周期结束)
01 1111
CF-End(无竞争周期结束)+CF-ACK(无竞争周期确认)
 
2.1.3.1 RTS帧 subtype 1011
 
2.1.3.2 CTS帧  subtype 1100
 
 
2.1.3.3 ACK帧 subtype 1101
2.1.3.4 PS-Poll帧  subtype  1010
    作用:当sta从省电模式中苏醒,便发送一个PS-poll给基站。
 
 

3. Radiotap Header(monitor信息)

    在monitor模式时,内核在MAC帧前面提供额外的信息。称为Radiotap Header,其包含的信息有MAC时间戳,SSI信号强度,频道频率等。
   
 
    这里的it_len表明了radiotap_header的长度,按上面抓到的包,这里的值为26。
    因此,在monitor模式得到的RAW包,我们首先要偏移it_len个字节,以此得到MAC头。

4. RTS/CTS 帧 (数据发送原子性)

    这两个帧出现的原因是 无线收发器(STA)通常无法同时收发数据。使用这两个帧可以让STA处于收或发状态。
    这样比较好理解,正是因为如此,当STA开始发送RTS,说明STA发数据;AP开始发送RTS,说明RTS接收数据。
    当其他STA收到RTS时,将延后数据包的发送。而具体延迟多久,由正在传输的MAC头中的持续时间决定(Duration ID)。如:
    RTS(Request-to-Send):请求发送数据。
    CTS(Clear-to-Send):清空传送区域。
    两个帧的过程如图:
    ①为 STA  ②为AP 
    抓的两个包来看下,下面是STA作为请求方
    下面是STA作为接收方:
   上图的223.252.199.6(00:36:76:54:b4:a2)是ap,172.21.11.2(a4:d1:d2:60:bb:0d)是STA,其Qos数据数据如下:
    RTS和CTS帧会延长帧传输过程,RTS,CTS,数据帧,以及ACK视为同一原子操作的一部分。
    用户可以通过调整RTS阈值,来控制RTS/CTS交换过程。只要大于此阈值,RTS/CTS交换过程就会进行,小于该阈值就会直接传送帧。
    对应的SOCK字段如下:
 
  1. #define SIOCSIWRTS 0x8B22 /* set RTS/CTS threshold (bytes) */
  2. #define SIOCGIWRTS 0x8B23 /* get RTS/CTS threshold (bytes) */
    

5. WIFI建立关联过程

    建立连接认证的过程主要由管理帧负责。
序号 SubType 说明
1 1000 Beacon,STA接受AP信标帧,感知到AP,获取SSID及AP参数
2 0100 STA主动发送Probe探测请求
3 0101 AP应答STA Prob Response
4 1011 STA发送Authentication请求认证
5   AP应答Authentication请求,指示STA认证成功或失败
6 0000 STA发送Association请求
7 0001 AP应答Association Response
    以上是连接过程,当需要断开连接时,STA发送 Disassociation
序号SubType说明81010断开连接
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
*********************************************************
××抓包类型总结××
 
 
 
Type value Type description Subtype value Subtype description
Wireshark display filter
00 Management 0000 Association Request wlan.fc.type_subtype == 0x00
00 Management 0001 Association Response wlan.fc.type_subtype == 0x01
00 Management 0010 Reassociation Request wlan.fc.type_subtype == 0x02
00 Management 0011 Reassociation Response wlan.fc.type_subtype == 0x03
00 Management 0100 Probe Request wlan.fc.type_subtype == 0x04
00 Management 0101 Probe Response wlan.fc.type_subtype == 0x05
00 Management 0110-0111 Reserved  
00 Management 1000 Beacon wlan.fc.type_subtype == 0x08
00 Management 1001 ATIM wlan.fc.type_subtype == 0x09
00 Management 1010 Disassociation wlan.fc.type_subtype == 0x0A
00 Management 1011 Authentication wlan.fc.type_subtype == 0x0B
00 Management 1100 Deauthentication wlan.fc.type_subtype == 0x0C
00 Management 1101 Action wlan.fc.type_subtype == 0x0D
00 Management 1110-1111 Reserved  
 
Type value Type description Subtype value Subtype description
Wireshark display filter
01 Control 0000-0111 Reserved  
01 Control 1000 Block Ack Request wlan.fc.type_subtype == 0x18
01 Control 1001 Block Ack wlan.fc.type_subtype == 0x19
01 Control 1010 PS-Poll wlan.fc.type_subtype == 0x1A
01 Control 1011 RTS wlan.fc.type_subtype == 0x1B
01 Control 1100 CTS wlan.fc.type_subtype == 0x1C
01 Control 1101 ACK wlan.fc.type_subtype == 0x1D
01 Control 1110 CF-end  wlan.fc.type_subtype == 0x1E
01 Control 1111 CF-end + CF-ack wlan.fc.type_subtype == 0x1F
           
 
Type value Type description Subtype value Subtype description
Wireshark display filter
10 Data 0000 Data wlan.fc.type_subtype == 0x20
10 Data 0001 Data + CF-ack wlan.fc.type_subtype == 0x21
10 Data 0010 Data + CF-poll wlan.fc.type_subtype == 0x22
10 Data 0011 Data +CF-ack +CF-poll wlan.fc.type_subtype == 0x23
10 Data 0100 Null wlan.fc.type_subtype == 0x24
10 Data 0101 CF-ack wlan.fc.type_subtype == 0x25
10 Data 0110 CF-poll wlan.fc.type_subtype == 0x26
10 Data 0111 CF-ack +CF-poll wlan.fc.type_subtype == 0x27
10 Data 1000 QoS data wlan.fc.type_subtype == 0x28
10 Data 1001 QoS data + CF-ack wlan.fc.type_subtype == 0x29
10 Data 1010 QoS data + CF-poll wlan.fc.type_subtype == 0x2A
10 Data 1011 QoS data + CF-ack + CF-poll wlan.fc.type_subtype == 0x2B
10 Data 1100 QoS Null wlan.fc.type_subtype == 0x2C
10 Data 1101 Reserved wlan.fc.type_subtype == 0x2D
10 Data 1110 QoS + CF-poll (no data) wlan.fc.type_subtype == 0x2E
10 Data 1111 Qos + CF-ack (no data) wlan.fc.type_subtype == 0x2F
11 Reserved 0000-1111 Reserved  
 
 
文参考《802.11无线网络 权威指南》

猜你喜欢

转载自www.cnblogs.com/shwang/p/12162692.html