| // Copyright 2020 The Chromium OS Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| package wifi |
| |
| import ( |
| "context" |
| |
| "github.com/google/gopacket" |
| "github.com/google/gopacket/layers" |
| |
| "chromiumos/tast/remote/bundles/cros/wifi/wifiutil" |
| "chromiumos/tast/remote/network/ip" |
| "chromiumos/tast/remote/wificell" |
| "chromiumos/tast/remote/wificell/pcap" |
| "chromiumos/tast/testing" |
| ) |
| |
| func init() { |
| testing.AddTest(&testing.Test{ |
| Func: ProbeReqFormat, |
| Desc: "Verifies that the DUT does not send out malformed probe requests", |
| Contacts: []string{ |
| "yenlinlai@google.com", // Test author |
| "chromeos-wifi-champs@google.com", // WiFi oncall rotation; or http://b/new?component=893827 |
| }, |
| // This test is not in any group because it is for manual debugging |
| // a pcap problem that frame checksum might not be trust-worthy. |
| // See previous investigation in b/185378075. |
| Attr: []string{"group:wificell"}, |
| ServiceDeps: []string{wificell.TFServiceName}, |
| Fixture: "wificellFixtWithCapture", |
| }) |
| } |
| |
| func ProbeReqFormat(ctx context.Context, s *testing.State) { |
| // Trigger active scans and verify the format of probe requests in pcap. |
| tf := s.FixtValue().(*wificell.TestFixture) |
| |
| ctx, restore, err := tf.WifiClient().DisableMACRandomize(ctx) |
| if err != nil { |
| s.Fatal("Failed to disable MAC randomization: ", err) |
| } |
| defer func() { |
| if err := restore(); err != nil { |
| s.Error("Failed to restore MAC randomization: ", err) |
| } |
| }() |
| |
| // Get the MAC address of WiFi interface. |
| iface, err := tf.ClientInterface(ctx) |
| if err != nil { |
| s.Fatal("Failed to get WiFi interface of DUT: ", err) |
| } |
| ipr := ip.NewRemoteRunner(s.DUT().Conn()) |
| mac, err := ipr.MAC(ctx, iface) |
| if err != nil { |
| s.Fatal("Failed to get MAC of WiFi interface: ", err) |
| } |
| |
| // Collect probe requests on channel 1. |
| pcapPath, err := wifiutil.ScanAndCollectPcap(ctx, tf, "malfromed_probe", 10, 1) |
| if err != nil { |
| s.Fatal("Failed to collect packet: ", err) |
| } |
| |
| s.Log("Start analyzing pcap") |
| filters := []pcap.Filter{ |
| pcap.Dot11FCSValid(), |
| pcap.TransmitterAddress(mac), |
| pcap.TypeFilter(layers.LayerTypeDot11MgmtProbeReq, nil), |
| } |
| packets, err := pcap.ReadPackets(pcapPath, filters...) |
| if err != nil { |
| s.Fatal("Failed to read packets: ", err) |
| } |
| s.Logf("Total %d probe requests found", len(packets)) |
| if len(packets) == 0 { |
| s.Fatal("No probe request found") |
| } |
| |
| for _, p := range packets { |
| layer := p.Layer(layers.LayerTypeDot11MgmtProbeReq) |
| if layer == nil { |
| s.Fatal("Found packet without ProbeReq layer") |
| } |
| // Parse the frame body into IEs. |
| content := layer.LayerContents() |
| e := gopacket.NewPacket(content, layers.LayerTypeDot11InformationElement, gopacket.NoCopy) |
| if err := e.ErrorLayer(); err != nil { |
| s.Errorf("Malformed probe request %v: %v", layer, err.Error()) |
| } |
| } |
| } |