TIM是什么?
TIM:Traffic Indication Map,流量指示图。
在80211协议节能模式中,AP会缓存下行数据,AP就是通过beacon帧中TIM来告知休眠中的STA有数据需要接收。
DTIM:Delivery Traffic Indication Map,是一种特殊的TIM,其除了缓存的单播信息,也同时指示AP缓存的组播信息。
TIM格式
TIM IE包含了四个域:DTIM Count, DTIM Period, Bitmap Control, and Partial Virtual
Bitmap。
Length:1byte,表示TIM的长度。
DTIM Count:1byte,表示下次DTIM之前还有多少个beacon帧(包括当前的beacon帧),如果DTIM Count为0表示当前的TIM就是DTIM。
DTIM Period:1byte,表示两个DTIM之间有多少个beacon帧。1表示所有的TIM都是DTIM。
Bitmap Control:1byte,bit0表示是否有组播/广播数据包缓存,1表示有组播/广播数据包缓存,0表示没有。bit1-7表示bitmap的偏移情况,即Partial Virtual Bitmap起始值是多少。
Partial virtual Bitmap:1-251byte,以Bitmap Control的起始值开始的bitmap。可以表示的范围0~2007。
TIM编码例子
第一个例子,AP没有缓存组播/广播的下行数据,只缓存了STA AID 2和AID 7的数据。其中Bitmap Control为0x00,Partial Virtual Bitmap为0x84。
运行结果:
第二个例子,AP缓存了组播/广播的下行数据,还缓存了STA AID 2, AID 7, AID 22和AID 24的数据。
运行结果:
第三个例子,AP缓存了组播/广播的下行数据,还缓存了STA AID 24的数据。
运行结果:
TIM C语言实现demo
#include <stdio.h>
#define ADD_TIM_BIT 0
#define REMOVE_TIM_BIT 1
#define TIM_ELEMENT_ID 5
#define TIM_BASE_SIZE 3 /* size of TIM fields */
#define AID_SIZE 2008 /* valid AIDs are 1 thru 2007 */
#define VBM_SIZE 251 /* size of VBM array = 2008/8 = 251 */
typedef unsigned char UINT8;
typedef unsigned short int UINT16;
struct _tim
{
UINT8 Element_id;
UINT8 IELength;
UINT8 DtimCount;
UINT8 DtimPeriod;
UINT8 BitMapControl;
UINT8 PartialVirtualBitMap[VBM_SIZE];
};
UINT8 virtualBitMap[VBM_SIZE];
UINT8 mcast_pending = 0