在介绍SDIO wifi Marvell8801/Marvell88w8801之前先附上模块链接:
代码工程的GITHUB连接:
https://github.com/sj15712795029/stm32f1_marvell88w8801_marvell8801_wifi
Marvell自己实现驱动系列文章分为几篇介绍:
每篇更新打开专栏可以看到:
首先来看下搜索的指令的介绍和命令格式
我们在普通搜索中只会用到channel list param set TLV
特定名称搜索会额外用到,这个留到特定SSID搜索部分来介绍
我们来看下channel list的TLV格式
整个格式如下
好了剩下的我们就是写代码了
/******************************************************************************
* 函数名: mrvl88w8801_process_packet
* 参数: channel(IN) -->channel数组,用于存储分别搜索什么通道
channel_num(IN) -->搜索的通道个数
max_time(IN) -->搜索的最大time
* 返回值: 返回执行结果
* 描述: 执行普通搜索动作
******************************************************************************/
uint8_t mrvl88w8801_scan(uint8_t *channel,uint8_t channel_num,uint16_t max_time)
{
uint8_t index = 0;
uint16_t scan_para_len = sizeof(MrvlIEtypesHeader_t) channel_num*sizeof(ChanScanParamSet_t);
uint8_t scan_para[scan_para_len];
MrvlIEtypes_ChanListParamSet_t *channel_list;
ChanScanParamSet_t *channel_list_para[channel_num];
COMP_DEBUG("mrvl88w8801_scan\n");
channel_list = (MrvlIEtypes_ChanListParamSet_t *)(scan_para);
channel_list->header.type = TLV_TYPE_CHANLIST;
channel_list->header.len = channel_num*sizeof(ChanScanParamSet_t);
/* 组合channel list的参数 */
for(index = 0; index < channel_num; index )
{
channel_list_para[index] = (ChanScanParamSet_t *)(scan_para sizeof(MrvlIEtypesHeader_t) index*sizeof(ChanScanParamSet_t));
channel_list_para[index]->radio_type = 0;
channel_list_para[index]->chan_number = channel[index];
channel_list_para[index]->chan_scan_mode = 0;
channel_list_para[index]->min_scan_time = 0;
channel_list_para[index]->max_scan_time = max_time;
}
mrvl88w8801_prepare_cmd(HostCmd_CMD_802_11_SCAN,HostCmd_ACT_GEN_GET,&scan_para,scan_para_len);
return COMP_ERR_OK;
}
/******************************************************************************
* 函数名: mrvl88w8801_scan_prepare
* 参数: tx(IN) -->tx buffer
data_buff(IN) -->搜索的cmd body,在这里就是channel list
data_len(IN) -->搜索的cmd body len,在这里就是channel list长度
* 返回值: 返回执行结果
* 描述: 组HostCmd_CMD_802_11_SCAN command的封包
******************************************************************************/
static uint8_t mrvl88w8801_scan_prepare(uint8_t* tx,void *data_buff,uint16_t data_len)
{
HostCmd_DS_COMMAND *cmd = (HostCmd_DS_COMMAND *)tx;
HostCmd_DS_802_11_SCAN *pscan = &cmd->params.scan;
uint16_t tx_packet_len = CMD_HDR_SIZE sizeof(HostCmd_DS_802_11_SCAN) data_len-sizeof(pscan->tlv_buffer);
cmd->pack_len = tx_packet_len;
cmd->pack_type = TYPE_CMD_CMDRSP;
cmd->command = HostCmd_CMD_802_11_SCAN;
cmd->size = tx_packet_len - CMD_SDIO_HDR_SIZE;
cmd->seq_num = 0;
cmd->bss = 0;
cmd->result = 0;
pscan->bss_mode = HostCmd_BSS_MODE_ANY;
comp_memset(pscan->bssid,0,MAC_ADDR_LENGTH);
comp_memcpy(pscan->tlv_buffer,data_buff,data_len);
return COMP_ERR_OK;
}
详细可以看下我的裸机代码,另外,为了便于你的理解,那么我用cmd的raw data来加深你的理解
Cmd的raw data为:
00000000h:79 00 01 00 06 00 75 00 00 00 00 00 03 00 00 00
00000010h:00 00 00 01 01 62 00 00 01 00 00 00 c8 00 00 02
00000020h:00 00 00 c8 00 00 03 00 00 00 c8 00 00 04 00 00
00000030h:00 c8 00 00 05 00 00 00 c8 00 00 06 00 00 00 c8
00000040h:00 00 07 00 00 00 c8 00 00 08 00 00 00 c8 00 00
00000050h:09 00 00 00 c8 00 00 0a 00 00 00 c8 00 00 0b 00
00000060h:00 00 c8 00 00 0c 00 00 00 c8 00 00 0d 00 00 00
00000070h:c8 00 00 0e 00 00 00 c8 00
一一分析下
79 00 -->SDIO packet len
01 00 -->SDIO packet type,此处01为cmd
06 00 -->cmd code,0x0006,也就是scan
75 00 -->cmd packet size
00 -->seq num
00 -->bss type,此处为STA
00 00–>result
03 --> bss type,此处设置为0x3是BSS ANY
00 00 00 00 00 00 --> bssid ,mac address,此处是这是过滤的,全0是代表不过滤
01 01 -->channel list para tlv id
62 00 -->channel list para tlv len
00 01 00 00 00 c8 00 -->2.4G 20M带宽,通道1
00 02 00 00 00 c8 00 -->2.4G 20M带宽,通道2
00 03 00 00 00 c8 00 -->2.4G 20M带宽,通道3
00 04 00 00 00 c8 00 -->2.4G 20M带宽,通道4
00 05 00 00 00 c8 00 -->2.4G 20M带宽,通道5
00 06 00 00 00 c8 00 -->2.4G 20M带宽,通道6
00 07 00 00 00 c8 00 -->2.4G 20M带宽,通道7
00 08 00 00 00 c8 00 -->2.4G 20M带宽,通道8
00 09 00 00 00 c8 00 -->2.4G 20M带宽,通道9
00 0a 00 00 00 c8 00 -->2.4G 20M带宽,通道10
00 0b 00 00 00 c8 00 -->2.4G 20M带宽,通道11
00 0c 00 00 00 c8 00 -->2.4G 20M带宽,通道12
00 0d 00 00 00 c8 00 -->2.4G 20M带宽,通道13
00 0e 00 00 00 c8 00 -->2.4G 20M带宽,通道14
整个cmd scan就组包完成
完成了搜索的cmd组包,后续会来一堆搜索响应的数据来,那么我们需要解析,此部分比较复杂,首先来看下scan cmd response
其中BssDescSet格式为
BssDescSet中的probe response/beacon payload格式为
IEParameters就是IEEE的TLV,还记得我们之前说过IEEE的TLV和Marvell的TLV的区别吗?
IEEE的TLV type,len各占1byte,Marvell TLV type,len各占2个byte,这部分解析的的时候会用到。
下面我们来看下cmd reponse的raw data来加深下理解
在开始raw data前,我们先贴下IEEE的TLV ID,至于是什么意思,内容众多,自己去看下
IEEE std 802.11,我看的是2012版
回到刚刚的话题,raw data
00000000h:dd 06 01 00 06 80 d9 06 00 00 00 00 94 06 05 82
00000010h:01 bc f6 85 be 07 dc 4a 5e fb 3e da 67 01 00 00
00000020h:64 00 31 04 00 03 31 30 32 01 08 82 84 8b 96 0c
00000030h:12 18 24 03 01 01 2a 01 00 32 04 30 48 60 6c 2d
00000040h:1a 6e 18 1e ff ff 00 00 00 00 00 00 00 00 00 00
00000050h:00 00 00 00 00 00 00 00 00 00 00 3d 16 01 05 00
00000060h:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000070h:00 00 00 dd 1a 00 50 f2 01 01 00 00 50 f2 02 02
00000080h:00 00 50 f2 02 00 50 f2 04 01 00 00 50 f2 02 30
00000090h:18 01 00 00 0f ac 02 02 00 00 0f ac 02 00 0f ac
000000a0h:04 01 00 00 0f ac 02 00 00 dd 18 00 50 f2 02 01
000000b0h:01 80 00 03 a4 00 00 27 a4 00 00 42 43 5e 00 62
000000c0h:32 2f 00 dd 8a 00 50 f2 04 10 4a 00 01 10 10 44
000000d0h:00 01 02 10 3b 00 01 03 10 47 00 10 63 04 12 53
000000e0h:10 19 20 06 12 28 bc f6 85 be 07 dc 10 21 00 0e
000000f0h:44 2d 4c 69 6e 6b 20 53 79 73 74 65 6d 73 10 23
00000100h:00 08 44 49 52 2d 36 30 35 4c 10 24 00 08 44 49
00000110h:52 2d 36 30 35 4c 10 42 00 0d 32 30 30 37 30 34
00000120h:31 33 2d 30 30 30 31 10 54 00 08 00 06 00 50 f2
00000130h:04 00 01 10 11 00 08 44 49 52 2d 36 30 35 4c 10
00000140h:08 00 02 26 88 10 49 00 06 00 37 2a 00 01 20 dd
00000150h:1e 00 90 4c 33 6e 18 1e ff ff 00 00 00 00 00 00
00000160h:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 dd
00000170h:1a 00 90 4c 34 01 05 00 00 00 00 00 00 00 00 00
00000180h:00 00 00 00 00 00 00 00 00 00 00 dd 06 00 e0 4c
00000190h:02 01 60 4e 01 62 38 3f 4a aa 19 53 28 0d 78 9d
000001a0h:00 00 00 00 64 00 11 14 00 0b 43 55 5f 69 54 56
000001b0h:5f 47 43 4e 4a 01 08 82 84 8b 96 24 30 48 6c 03
000001c0h:01 02 07 06 23 61 20 01 0e 1e 2a 01 00 32 04 0c
000001d0h:12 18 60 30 18 01 00 00 0f ac 02 02 00 00 0f ac
000001e0h:04 00 0f ac 02 01 00 00 0f ac 02 0c 00 0b 05 00
000001f0h:00 10 00 00 46 05 32 08 01 00 00 2d 1a bc 08 1b
00000200h:ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000210h:00 00 00 00 00 00 00 3d 16 02 08 00 00 00 00 00
00000220h:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 7f
00000230h:03 04 00 08 dd 6c 00 50 f2 04 10 4a 00 01 10 10
00000240h:44 00 01 02 10 3b 00 01 03 10 47 00 10 b8 67 f4
00000250h:32 4e 15 93 a2 19 80 3c c0 42 31 f9 1d 10 21 00
00000260h:03 5a 54 45 10 23 00 03 5a 54 45 10 24 00 06 31
00000270h:32 33 34 35 36 10 42 00 04 31 32 33 34 10 54 00
00000280h:08 00 06 00 50 f2 04 00 01 10 11 00 0a 5a 58 48
00000290h:4e 20 46 31 36 30 41 10 08 00 02 00 80 10 3c 00
000002a0h:01 01 dd 09 00 10 18 02 00 00 0c 00 00 dd 1a 00
000002b0h:50 f2 01 01 00 00 50 f2 02 02 00 00 50 f2 04 00
000002c0h:50 f2 02 01 00 00 50 f2 02 dd 18 00 50 f2 02 01
000002d0h:01 84 00 03 a4 00 00 27 a4 00 00 42 43 5e 00 62
000002e0h:32 2f 00 76 01 8c 21 0a 24 4f 70 3d 63 4a 3d ba
000002f0h:1c 01 00 00 64 00 31 04 00 06 77 61 6e 67 77 77
00000300h:01 08 82 84 8b 96 0c 12 18 24 03 01 06 07 06 55
00000310h:53 20 01 0d 14 2a 01 00 30 14 01 00 00 0f ac 04
00000320h:01 00 00 0f ac 04 01 00 00 0f ac 02 00 00 32 04
00000330h:30 48 60 6c 2d 1a 6e 10 03 ff ff 00 00 00 00 00
00000340h:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000350h:33 1a 6e 10 03 ff ff 00 00 00 00 00 00 00 00 00
00000360h:00 00 00 00 00 00 00 00 00 00 00 00 3d 16 06 0d
00000370h:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000380h:00 00 00 00 34 16 06 0d 00 00 00 00 00 00 00 00
00000390h:00 00 00 00 00 00 00 00 00 00 00 00 dd 16 00 50
000003a0h:f2 01 01 00 00 50 f2 04 01 00 00 50 f2 04 01 00
000003b0h:00 50 f2 02 dd 18 00 50 f2 02 01 01 03 00 03 a4
000003c0h:00 00 27 a4 00 00 42 43 5e 00 62 32 2f 00 dd 09
000003d0h:00 03 7f 01 01 00 00 ff 7f dd 80 00 50 f2 04 10
000003e0h:4a 00 01 10 10 44 00 01 02 10 3b 00 01 03 10 47
000003f0h:00 10 00 00 00 00 00 00 10 00 00 00 8c 21 0a 24
00000400h:4f 70 10 21 00 07 54 50 2d 4c 49 4e 4b 10 23 00
00000410h:09 54 4c 2d 57 52 38 34 30 4e 10 24 00 03 31 2e
00000420h:30 10 42 00 03 31 2e 30 10 54 00 08 00 06 00 50
00000430h:f2 04 00 01 10 11 00 18 57 69 72 65 6c 65 73 73
00000440h:20 4e 20 52 6f 75 74 65 72 20 57 52 38 34 30 4e
00000450h:10 08 00 02 00 86 10 3c 00 01 01 fa 00 14 75 90
00000460h:c9 0f 60 51 fd 53 1e f1 35 07 00 00 64 00 31 04
00000470h:00 0c 54 50 2d 4c 49 4e 4b 5f 30 46 36 30 01 08
00000480h:82 84 8b 96 0c 12 18 24 03 01 06 07 06 43 4e 20
00000490h:01 0d 20 2a 01 00 30 14 01 00 00 0f ac 04 01 00
000004a0h:00 0f ac 04 01 00 00 0f ac 02 00 00 32 04 30 48
000004b0h:60 6c 2d 1a 6e 10 1b ff ff ff 00 00 00 00 00 00
000004c0h:00 00 00 80 00 00 00 00 00 00 00 00 00 00 33 1a
000004d0h:6e 10 1b ff ff ff 00 00 00 00 00 00 00 00 00 80
000004e0h:00 00 00 00 00 00 00 00 00 00 3d 16 06 05 05 00
000004f0h:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00000500h:00 00 34 16 06 05 05 00 00 00 00 00 00 00 00 00
00000510h:00 00 00 00 00 00 00 00 00 00 dd 16 00 50 f2 01
00000520h:01 00 00 50 f2 04 01 00 00 50 f2 04 01 00 00 50
00000530h:f2 02 dd 18 00 50 f2 02 01 01 03 00 03 a4 00 00
00000540h:27 a4 00 00 42 43 5e 00 62 32 2f 00 dd 09 00 03
00000550h:7f 01 01 00 00 ff 7f 4a 01 88 25 93 46 71 d6 29
00000560h:17 82 70 14 e7 05 00 00 64 00 31 04 00 0c c4 e3
00000570h:b2 e9 d1 af b2 bb b5 bd ce d2 01 08 82 84 8b 96
00000580h:0c 12 18 24 03 01 0b 2a 01 00 32 04 30 48 60 6c
00000590h:2d 1a 6e 10 03 ff ff 00 00 00 00 00 00 00 00 00
000005a0h:00 00 00 00 00 00 00 00 00 00 00 00 3d 16 0b 07
000005b0h:02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
000005c0h:00 00 00 00 30 14 01 00 00 0f ac 04 01 00 00 0f
000005d0h:ac 04 01 00 00 0f ac 02 00 00 dd 16 00 50 f2 01
000005e0h:01 00 00 50 f2 04 01 00 00 50 f2 04 01 00 00 50
000005f0h:f2 02 dd 18 00 50 f2 02 01 01 00 00 03 a4 00 00
00000600h:27 a4 00 00 42 43 5e 00 62 32 2f 00 dd 05 00 0a
00000610h:eb 01 00 dd 8e 00 50 f2 04 10 4a 00 01 10 10 44
00000620h:00 01 02 10 3b 00 01 03 10 47 00 10 00 00 00 00
00000630h:00 00 10 00 00 00 88 25 93 46 71 d6 10 21 00 07
00000640h:54 50 2d 4c 49 4e 4b 10 23 00 09 54 4c 2d 57 52
00000650h:38 34 35 4e 10 24 00 03 34 2e 30 10 42 00 07 31
00000660h:2e 31 2e 31 2e 33 10 54 00 08 00 06 00 50 f2 04
00000670h:00 01 10 11 00 18 57 69 72 65 6c 65 73 73 20 4e
00000680h:20 52 6f 75 74 65 72 20 57 52 38 34 35 4e 10 08
00000690h:00 02 22 88 10 3c 00 01 01 10 49 00 06 00 37 2a
000006a0h:00 01 20 13 01 28 00 b8 a2 a8 00 00 00 00 00 de
000006b0h:48 ac 00 00 00 00 00 58 59 b8 00 00 00 00 00 53
000006c0h:6c b8 00 00 00 00 00 77 1b c8 00 00 00 00 00 2a
000006d0h:01 0a 00 80 01 80 02 80 06 80 06 80 0b
dd 06 --> sdio packet len,也就是0x6dd ->1757 byte
01 00 -->sdio packet type,此处为1,是cmd response
06 80 -->cmd code,0x8006
d9 06 -->cmd response packet len
00 -->seq num
00 -->bss,此处0代表STA
00 00 -->result
94 06–> buffer size,也就是搜索的结果size
05 -->num of set,也就是搜索到几个AP,此处为5个
下面就是第一个搜索的AP
82 01 -->total ie length
bc f6 85 be 07 dc -->mac address
4a -->RSSI(接收信号强度)
5e fb 3e da 67 01 00 00 -->time stamp时间戳
64 00 -->beacon interval
31 04 -->cap information,也就是ap有哪些功能
00 03 31 30 32 -->TLV type ID 0(SSID),len为3,value为 102
01 08 82 84 8b 96 0c 12 18 24 -->TLV type ID 8(Hopping Pattern Parameters)
03 01 01 -->TLV type ID 3(DSSS Parameter Set)
2a 01 00 -->TLV type ID 0x2a(ER )
32 04 30 48 60 6c -->TLV type ID 0x32(Extended Supported Rates
2d 1a 6e 18 1e ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
–>TLV type ID 0x2d(HT Capabilities )
3d 16 01 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
–>TLV type ID 0x3d(HT Operation)
dd 1a 00 50 f2 01 01 00 00 50 f2 02 02 00 00 50 f2 02 00 50 f2 04 01 00 00 50 f2 02
–>TLV type ID 0xdd(Vendor Specific )
30 18 01 00 00 0f ac 02 02 00 00 0f ac 02 00 0f ac 04 01 00 00 0f ac 02 00 00
–>TLV type ID 0x30(RSN)
dd 18 00 50 f2 02 01 01 80 00 03 a4 00 00 27 a4 00 00 42 43 5e 00 62 32 2f 00
–>TLV type ID 0xdd(Vendor Specific )
dd 8a 00 50 f2 04 10 4a 00 01 10 10 44 00 01 02 10 3b 00 01 03 10 47 00 10 63 04 12 53 10 19 20 06 12 28 bc f6 85 be 07 dc 10 21 00 0e 44 2d 4c 69 6e 6b 20 53 79 73 74 65 6d 73 10 23 00 08 44 49 52 2d 36 30 35 4c 10 24 00 08 44 49 52 2d 36 30 35 4c 10 42 00 0d 32 30 30 37 30 34 31 33 2d 30 30 30 31 10 54 00 08 00 06 00 50 f2 04 00 01 10 11 00 08 44 49 52 2d 36 30 35 4c 10 :08 00 02 26 88 10 49 00 06 00 37 2a 00 01 20
–>TLV type ID 0xdd(Vendor Specific )
dd 1e 00 90 4c 33 6e 18 1e ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
–>TLV type ID 0xdd(Vendor Specific )
dd 1a 00 90 4c 34 01 05 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
–>TLV type ID 0xdd(Vendor Specific )
dd 06 00 e0 4c 02 01 60
–>TLV type ID 0xdd(Vendor Specific )
到此为止第一个AP的所有信息已经完毕,剩下的和第一个分析一样
4e 01 -->第二个AP的长度
62 38 3f 4a aa 19 -->MAC
…
我们就不做重复动作,我们看下code,其实我们不需要解析所有TLV,只解析几个关键的就行,关于code请参照代码mrvl88w8801_ret_scan这个函数
Code打印如图
如果你看懂上面的,那么这个小节,其实我们可以不做介绍,就是在scan的cmd中加一个SSID的TLV,他就自动搜索此名称的SSID
给你看下raw data就好
00000000h:e3 00 01 00 06 80 df 00 00 00 00 00 c2 00 01 c0
00000010h:00 9e 0c df 24 7f 0b 12 37 a6 4c 00 00 00 00 00
00000020h:64 00 31 04 00 0b 5a 48 4f 4e 47 4a 55 4e 5f 41
00000030h:50 01 08 82 84 8b 96 8c 12 98 24 03 01 0a 32 04
00000040h:b0 48 60 6c 2a 01 00 2d 1a 31 01 03 ff 00 00 00
00000050h:00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
00000060h:00 00 00 3d 16 0a 00 00 00 00 00 00 00 00 00 00
00000070h:00 00 00 00 00 00 00 00 00 00 00 7f 01 00 dd 18
00000080h:00 50 f2 02 01 01 80 00 03 a4 00 00 27 a4 00 00
00000090h:42 43 5e 00 62 32 2f 00 30 14 01 00 00 0f ac 04
000000a0h:01 00 00 0f ac 04 01 00 00 0f ac 02 0c 00 dd 18
000000b0h:00 50 f2 04 10 4a 00 01 10 10 44 00 01 02 10 49
000000c0h:00 06 00 37 2a 00 01 20 dd 07 00 0c e7 08 00 00
000000d0h:00 13 01 08 00 96 3c c7 00 00 00 00 00 2a 01 02
000000e0h:00 80 0a
红色部分为SSID,ZHONGJUN_AP