2022-07-03 08:22:20 +00:00
|
|
|
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
import pytest
|
2022-09-30 13:04:35 +00:00
|
|
|
from common_test_methods import get_env_config_variable
|
2022-07-03 08:22:20 +00:00
|
|
|
from pytest_embedded import Dut
|
|
|
|
|
|
|
|
|
2022-09-30 13:04:35 +00:00
|
|
|
def _sniffer_packets_check(dut: Dut, channel: int, packet_num: int) -> None:
|
2022-07-03 08:22:20 +00:00
|
|
|
dut.write('pcap --open -f simple-sniffer')
|
|
|
|
dut.expect('cmd_pcap: open file successfully')
|
2022-09-30 13:04:35 +00:00
|
|
|
dut.write(f'sniffer -i wlan -c {channel} -n {packet_num}')
|
2022-07-20 05:02:55 +00:00
|
|
|
dut.expect(f'cmd_sniffer: {packet_num} packages will be captured')
|
2022-07-03 08:22:20 +00:00
|
|
|
dut.expect('cmd_sniffer: start WiFi promiscuous ok')
|
|
|
|
dut.expect('cmd_sniffer: stop promiscuous ok')
|
|
|
|
dut.write('pcap --summary -f simple-sniffer')
|
|
|
|
dut.expect('cmd_pcap: Memory is to be parsed')
|
|
|
|
dut.expect('Pcap packet Head:')
|
|
|
|
dut.expect('Magic Number: a1b2c3d4')
|
|
|
|
dut.expect(r'Major Version: [0-9]+')
|
|
|
|
dut.expect(r'Minor Version: [0-9]+')
|
|
|
|
dut.expect(r'SnapLen: [0-9]+')
|
|
|
|
dut.expect(r'LinkType: [0-9]+')
|
2022-07-20 05:02:55 +00:00
|
|
|
for i in range(0, packet_num):
|
2022-07-03 08:22:20 +00:00
|
|
|
dut.expect(f'Packet {i}:')
|
|
|
|
dut.expect(r'Timestamp \(Seconds\): [0-9]+')
|
|
|
|
dut.expect(r'Timestamp \(Microseconds\): [0-9]+')
|
|
|
|
dut.expect(r'Capture Length: [0-9]+')
|
|
|
|
dut.expect(r'Packet Length: [0-9]+')
|
|
|
|
dut.expect(r'Frame Type:\s+\w+')
|
|
|
|
dut.expect(r'Frame Subtype:\s+\w+')
|
|
|
|
dut.expect(r'Destination:\s+\w+')
|
|
|
|
dut.expect(r'Source:\s+\w+')
|
2022-07-20 05:02:55 +00:00
|
|
|
dut.expect(f'Pcap packet Number: {packet_num}')
|
2022-07-03 08:22:20 +00:00
|
|
|
dut.write('pcap --close -f simple-sniffer')
|
|
|
|
dut.expect('cmd_pcap: free memory successfully')
|
|
|
|
dut.expect('cmd_pcap: .pcap file close done')
|
|
|
|
|
2022-07-20 05:02:55 +00:00
|
|
|
|
|
|
|
@pytest.mark.esp32
|
2022-12-07 10:07:07 +00:00
|
|
|
@pytest.mark.esp32c3
|
|
|
|
@pytest.mark.esp32s3
|
2022-07-20 05:02:55 +00:00
|
|
|
@pytest.mark.wifi_ap
|
|
|
|
@pytest.mark.parametrize('config', [
|
|
|
|
'mem',
|
|
|
|
], indirect=True)
|
|
|
|
def test_examples_simple_sniffer(dut: Dut) -> None:
|
|
|
|
dut.expect('sniffer>')
|
2022-09-30 13:04:35 +00:00
|
|
|
channel = get_env_config_variable('wifi_ap', 'sniffer_channel', default=1)
|
2022-07-20 05:02:55 +00:00
|
|
|
# Sniffer multiple times with few packets
|
|
|
|
for _ in range(3):
|
2022-09-30 13:04:35 +00:00
|
|
|
_sniffer_packets_check(dut, channel, 5)
|
2022-07-03 08:22:20 +00:00
|
|
|
dut.write('')
|
|
|
|
dut.expect('sniffer>')
|