]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/test_cfg80211.py
2 # Copyright (c) 2014, Jouni Malinen <j@w1.fi>
4 # This software may be distributed under the terms of the BSD license.
5 # See README for more details.
8 logger
= logging
.getLogger()
17 def nl80211_command(dev
, cmd
, attr
):
18 res
= dev
.request("VENDOR ffffffff {} {}".format(nl80211_cmd
[cmd
],
19 binascii
.hexlify(attr
)))
21 raise Exception("nl80211 command failed")
22 return binascii
.unhexlify(res
)
24 def test_cfg80211_disassociate(dev
, apdev
):
25 """cfg80211 disassociation command"""
26 hapd
= hostapd
.add_ap(apdev
[0]['ifname'], { "ssid": "open" })
27 dev
[0].connect("open", key_mgmt
="NONE", scan_freq
="2412")
28 ev
= hapd
.wait_event([ "AP-STA-CONNECTED" ], timeout
=5)
30 raise Exception("No connection event received from hostapd")
32 ifindex
= int(dev
[0].get_driver_status_field("ifindex"))
33 attrs
= build_nl80211_attr_u32('IFINDEX', ifindex
)
34 attrs
+= build_nl80211_attr_u16('REASON_CODE', 1)
35 attrs
+= build_nl80211_attr_mac('MAC', apdev
[0]['bssid'])
36 nl80211_command(dev
[0], 'DISASSOCIATE', attrs
)
38 ev
= hapd
.wait_event([ "AP-STA-DISCONNECTED" ], timeout
=5)
40 raise Exception("No disconnection event received from hostapd")
42 def nl80211_frame(dev
, ifindex
, frame
, freq
=None, duration
=None, offchannel_tx_ok
=False):
43 attrs
= build_nl80211_attr_u32('IFINDEX', ifindex
)
45 attrs
+= build_nl80211_attr_u32('WIPHY_FREQ', freq
)
46 if duration
is not None:
47 attrs
+= build_nl80211_attr_u32('DURATION', duration
)
49 attrs
+= build_nl80211_attr_flag('OFFCHANNEL_TX_OK')
50 attrs
+= build_nl80211_attr('FRAME', frame
)
51 return parse_nl80211_attrs(nl80211_command(dev
, 'FRAME', attrs
))
53 def nl80211_frame_wait_cancel(dev
, ifindex
, cookie
):
54 attrs
= build_nl80211_attr_u32('IFINDEX', ifindex
)
55 attrs
+= build_nl80211_attr('COOKIE', cookie
)
56 return nl80211_command(dev
, 'FRAME_WAIT_CANCEL', attrs
)
58 def nl80211_remain_on_channel(dev
, ifindex
, freq
, duration
):
59 attrs
= build_nl80211_attr_u32('IFINDEX', ifindex
)
60 attrs
+= build_nl80211_attr_u32('WIPHY_FREQ', freq
)
61 attrs
+= build_nl80211_attr_u32('DURATION', duration
)
62 return nl80211_command(dev
, 'REMAIN_ON_CHANNEL', attrs
)
64 def test_cfg80211_tx_frame(dev
, apdev
, params
):
65 """cfg80211 offchannel TX frame command"""
66 ifindex
= int(dev
[0].get_driver_status_field("ifindex"))
68 frame
= binascii
.unhexlify("d000000002000000010002000000000002000000010000000409506f9a090001dd5e506f9a0902020025080401001f0502006414060500585804510b0906000200000000000b1000585804510b0102030405060708090a0b0d1d000200000000000108000000000000000000101100084465766963652041110500585804510bdd190050f204104a0001101012000200011049000600372a000120")
70 dev
[0].request("P2P_GROUP_ADD freq=2412")
71 res
= nl80211_frame(dev
[0], ifindex
, frame
, freq
=2422, duration
=500,
72 offchannel_tx_ok
=True)
75 # note: Uncommenting this seems to remove the incorrect channel issue
76 #nl80211_frame_wait_cancel(dev[0], ifindex, res[nl80211_attr['COOKIE']])
78 # note: this Action frame ends up getting sent incorrectly on 2422 MHz
79 nl80211_frame(dev
[0], ifindex
, frame
, freq
=2412)
81 # note: also the Deauthenticate frame sent by the GO going down ends up
82 # being transmitted incorrectly on 2422 MHz.
86 "-r", os
.path
.join(params
['logdir'], "hwsim0.pcapng"),
87 "-R", "wlan.fc.type_subtype == 13",
88 "-Tfields", "-e", "radiotap.channel.freq" ]
89 cmd
= subprocess
.Popen(arg
, stdout
=subprocess
.PIPE
,
90 stderr
=open('/dev/null', 'w'))
92 logger
.info("Could run run tshark check: " + str(e
))
97 freq
= cmd
.stdout
.read().splitlines()
99 raise Exception("Unexpected number of Action frames (%d)" % len(freq
))
100 if freq
[0] != "2422":
101 raise Exception("First Action frame on unexpected channel: %s MHz" % freq
[0])
102 if freq
[1] != "2412":
103 raise Exception("Second Action frame on unexpected channel: %s MHz" % freq
[1])