]>
git.ipfire.org Git - thirdparty/hostap.git/blob - tests/hwsim/wpasupplicant.py
1 # Python class for controlling wpa_supplicant
2 # Copyright (c) 2013-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.
16 logger
= logging
.getLogger()
17 wpas_ctrl
= '/var/run/wpa_supplicant'
20 def __init__(self
, ifname
=None, global_iface
=None):
21 self
.group_ifname
= None
23 self
.set_ifname(ifname
)
27 self
.global_iface
= global_iface
29 self
.global_ctrl
= wpaspy
.Ctrl(global_iface
)
30 self
.global_mon
= wpaspy
.Ctrl(global_iface
)
31 self
.global_mon
.attach()
33 def set_ifname(self
, ifname
):
35 self
.ctrl
= wpaspy
.Ctrl(os
.path
.join(wpas_ctrl
, ifname
))
36 self
.mon
= wpaspy
.Ctrl(os
.path
.join(wpas_ctrl
, ifname
))
39 def remove_ifname(self
):
46 def interface_add(self
, ifname
, driver
="nl80211", drv_params
=None):
48 groups
= subprocess
.check_output(["id"])
49 group
= "admin" if "(admin)" in groups
else "adm"
52 cmd
= "INTERFACE_ADD " + ifname
+ "\t\t" + driver
+ "\tDIR=/var/run/wpa_supplicant GROUP=" + group
54 cmd
= cmd
+ '\t' + drv_params
55 if "FAIL" in self
.global_request(cmd
):
56 raise Exception("Failed to add a dynamic wpa_supplicant interface")
57 self
.set_ifname(ifname
)
59 def interface_remove(self
, ifname
):
61 self
.global_request("INTERFACE_REMOVE " + ifname
)
63 def request(self
, cmd
):
64 logger
.debug(self
.ifname
+ ": CTRL: " + cmd
)
65 return self
.ctrl
.request(cmd
)
67 def global_request(self
, cmd
):
68 if self
.global_iface
is None:
71 ifname
= self
.ifname
or self
.global_iface
72 logger
.debug(ifname
+ ": CTRL: " + cmd
)
73 return self
.global_ctrl
.request(cmd
)
75 def group_request(self
, cmd
):
76 if self
.group_ifname
and self
.group_ifname
!= self
.ifname
:
77 logger
.debug(self
.group_ifname
+ ": CTRL: " + cmd
)
78 gctrl
= wpaspy
.Ctrl(os
.path
.join(wpas_ctrl
, self
.group_ifname
))
79 return gctrl
.request(cmd
)
80 return self
.request(cmd
)
83 return "PONG" in self
.request("PING")
86 res
= self
.request("FLUSH")
88 logger
.info("FLUSH to " + self
.ifname
+ " failed: " + res
)
89 self
.request("WPS_ER_STOP")
90 self
.request("SET pmf 0")
91 self
.request("SET external_sim 0")
92 self
.request("SET hessid 00:00:00:00:00:00")
93 self
.request("SET access_network_type 15")
94 self
.request("SET p2p_add_cli_chan 0")
95 self
.request("SET p2p_no_go_freq ")
96 self
.request("SET p2p_pref_chan ")
97 self
.request("SET p2p_no_group_iface 1")
98 self
.request("SET p2p_go_intent 7")
99 self
.group_ifname
= None
104 state
= self
.get_driver_status_field("scan_state")
105 if "SCAN_STARTED" in state
or "SCAN_REQUESTED" in state
:
106 logger
.info(self
.ifname
+ ": Waiting for scan operation to complete before continuing")
112 logger
.error(self
.ifname
+ ": Driver scan state did not clear")
113 print "Trying to clear cfg80211/mac80211 scan state"
115 cmd
= ["sudo", "ifconfig", self
.ifname
, "down"]
117 except subprocess
.CalledProcessError
, e
:
118 logger
.info("ifconfig failed: " + str(e
.returncode
))
119 logger
.info(e
.output
)
121 cmd
= ["sudo", "ifconfig", self
.ifname
, "up"]
123 except subprocess
.CalledProcessError
, e
:
124 logger
.info("ifconfig failed: " + str(e
.returncode
))
125 logger
.info(e
.output
)
127 # The ongoing scan could have discovered BSSes or P2P peers
128 logger
.info("Run FLUSH again since scan was in progress")
129 self
.request("FLUSH")
133 logger
.info("No PING response from " + self
.ifname
+ " after reset")
135 def add_network(self
):
136 id = self
.request("ADD_NETWORK")
138 raise Exception("ADD_NETWORK failed")
141 def remove_network(self
, id):
142 id = self
.request("REMOVE_NETWORK " + str(id))
144 raise Exception("REMOVE_NETWORK failed")
147 def get_network(self
, id, field
):
148 res
= self
.request("GET_NETWORK " + str(id) + " " + field
)
153 def set_network(self
, id, field
, value
):
154 res
= self
.request("SET_NETWORK " + str(id) + " " + field
+ " " + value
)
156 raise Exception("SET_NETWORK failed")
159 def set_network_quoted(self
, id, field
, value
):
160 res
= self
.request("SET_NETWORK " + str(id) + " " + field
+ ' "' + value
+ '"')
162 raise Exception("SET_NETWORK failed")
165 def list_networks(self
):
166 res
= self
.request("LIST_NETWORKS")
167 lines
= res
.splitlines()
170 if "network id" in l
:
172 [id,ssid
,bssid
,flags
] = l
.split('\t')
175 network
['ssid'] = ssid
176 network
['bssid'] = bssid
177 network
['flags'] = flags
178 networks
.append(network
)
181 def hs20_enable(self
):
182 self
.request("SET interworking 1")
183 self
.request("SET hs20 1")
186 id = self
.request("ADD_CRED")
188 raise Exception("ADD_CRED failed")
191 def remove_cred(self
, id):
192 id = self
.request("REMOVE_CRED " + str(id))
194 raise Exception("REMOVE_CRED failed")
197 def set_cred(self
, id, field
, value
):
198 res
= self
.request("SET_CRED " + str(id) + " " + field
+ " " + value
)
200 raise Exception("SET_CRED failed")
203 def set_cred_quoted(self
, id, field
, value
):
204 res
= self
.request("SET_CRED " + str(id) + " " + field
+ ' "' + value
+ '"')
206 raise Exception("SET_CRED failed")
209 def get_cred(self
, id, field
):
210 return self
.request("GET_CRED " + str(id) + " " + field
)
212 def add_cred_values(self
, params
):
215 quoted
= [ "realm", "username", "password", "domain", "imsi",
216 "excluded_ssid", "milenage", "ca_cert", "client_cert",
217 "private_key", "domain_suffix_match", "provisioning_sp",
218 "roaming_partner", "phase1", "phase2" ]
221 self
.set_cred_quoted(id, field
, params
[field
])
223 not_quoted
= [ "eap", "roaming_consortium", "priority",
224 "required_roaming_consortium", "sp_priority",
225 "max_bss_load", "update_identifier", "req_conn_capab",
226 "min_dl_bandwidth_home", "min_ul_bandwidth_home",
227 "min_dl_bandwidth_roaming", "min_ul_bandwidth_roaming" ]
228 for field
in not_quoted
:
230 self
.set_cred(id, field
, params
[field
])
234 def select_network(self
, id, freq
=None):
236 extra
= " freq=" + freq
239 id = self
.request("SELECT_NETWORK " + str(id) + extra
)
241 raise Exception("SELECT_NETWORK failed")
244 def connect_network(self
, id, timeout
=10):
246 self
.select_network(id)
247 ev
= self
.wait_event(["CTRL-EVENT-CONNECTED"], timeout
=timeout
)
249 raise Exception("Association with the AP timed out")
252 def get_status(self
, extra
=None):
257 res
= self
.request("STATUS" + extra
)
258 lines
= res
.splitlines()
262 [name
,value
] = l
.split('=', 1)
264 except ValueError, e
:
265 logger
.info(self
.ifname
+ ": Ignore unexpected STATUS line: " + l
)
268 def get_status_field(self
, field
, extra
=None):
269 vals
= self
.get_status(extra
)
274 def get_group_status(self
, extra
=None):
279 res
= self
.group_request("STATUS" + extra
)
280 lines
= res
.splitlines()
283 [name
,value
] = l
.split('=', 1)
287 def get_group_status_field(self
, field
, extra
=None):
288 vals
= self
.get_group_status(extra
)
293 def get_driver_status(self
):
294 res
= self
.request("STATUS-DRIVER")
295 lines
= res
.splitlines()
298 [name
,value
] = l
.split('=', 1)
302 def get_driver_status_field(self
, field
):
303 vals
= self
.get_driver_status()
309 res
= self
.request("MIB")
310 lines
= res
.splitlines()
314 [name
,value
] = l
.split('=', 1)
316 except ValueError, e
:
317 logger
.info(self
.ifname
+ ": Ignore unexpected MIB line: " + l
)
320 def p2p_dev_addr(self
):
321 return self
.get_status_field("p2p_device_address")
323 def p2p_interface_addr(self
):
324 return self
.get_group_status_field("address")
326 def p2p_listen(self
):
327 return self
.global_request("P2P_LISTEN")
329 def p2p_find(self
, social
=False, dev_id
=None, dev_type
=None):
332 cmd
= cmd
+ " type=social"
334 cmd
= cmd
+ " dev_id=" + dev_id
336 cmd
= cmd
+ " dev_type=" + dev_type
337 return self
.global_request(cmd
)
339 def p2p_stop_find(self
):
340 return self
.global_request("P2P_STOP_FIND")
342 def wps_read_pin(self
):
343 self
.pin
= self
.request("WPS_PIN get").rstrip("\n")
344 if "FAIL" in self
.pin
:
345 raise Exception("Could not generate PIN")
348 def peer_known(self
, peer
, full
=True):
349 res
= self
.global_request("P2P_PEER " + peer
)
350 if peer
.lower() not in res
.lower():
354 return "[PROBE_REQ_ONLY]" not in res
356 def discover_peer(self
, peer
, full
=True, timeout
=15, social
=True, force_find
=False):
357 logger
.info(self
.ifname
+ ": Trying to discover peer " + peer
)
358 if not force_find
and self
.peer_known(peer
, full
):
360 self
.p2p_find(social
)
362 while count
< timeout
:
365 if self
.peer_known(peer
, full
):
369 def get_peer(self
, peer
):
370 res
= self
.global_request("P2P_PEER " + peer
)
371 if peer
.lower() not in res
.lower():
372 raise Exception("Peer information not available")
373 lines
= res
.splitlines()
377 [name
,value
] = l
.split('=', 1)
381 def group_form_result(self
, ev
, expect_failure
=False, go_neg_res
=None):
383 if "P2P-GROUP-STARTED" in ev
:
384 raise Exception("Group formation succeeded when expecting failure")
385 exp
= r
'<.>(P2P-GO-NEG-FAILURE) status=([0-9]*)'
386 s
= re
.split(exp
, ev
)
390 res
['result'] = 'go-neg-failed'
391 res
['status'] = int(s
[2])
394 if "P2P-GROUP-STARTED" not in ev
:
395 raise Exception("No P2P-GROUP-STARTED event seen")
397 exp
= r
'<.>(P2P-GROUP-STARTED) ([^ ]*) ([^ ]*) ssid="(.*)" freq=([0-9]*) ((?:psk=.*)|(?:passphrase=".*")) go_dev_addr=([0-9a-f:]*) ip_addr=([0-9.]*) ip_mask=([0-9.]*) go_ip_addr=([0-9.]*)'
398 s
= re
.split(exp
, ev
)
400 exp
= r
'<.>(P2P-GROUP-STARTED) ([^ ]*) ([^ ]*) ssid="(.*)" freq=([0-9]*) ((?:psk=.*)|(?:passphrase=".*")) go_dev_addr=([0-9a-f:]*)'
401 s
= re
.split(exp
, ev
)
403 raise Exception("Could not parse P2P-GROUP-STARTED")
405 res
['result'] = 'success'
407 self
.group_ifname
= s
[2]
411 if "[PERSISTENT]" in ev
:
412 res
['persistent'] = True
414 res
['persistent'] = False
415 p
= re
.match(r
'psk=([0-9a-f]*)', s
[6])
417 res
['psk'] = p
.group(1)
418 p
= re
.match(r
'passphrase="(.*)"', s
[6])
420 res
['passphrase'] = p
.group(1)
421 res
['go_dev_addr'] = s
[7]
423 if len(s
) > 8 and len(s
[8]) > 0:
424 res
['ip_addr'] = s
[8]
426 res
['ip_mask'] = s
[9]
428 res
['go_ip_addr'] = s
[10]
431 exp
= r
'<.>(P2P-GO-NEG-SUCCESS) role=(GO|client) freq=([0-9]*)'
432 s
= re
.split(exp
, go_neg_res
)
434 raise Exception("Could not parse P2P-GO-NEG-SUCCESS")
435 res
['go_neg_role'] = s
[2]
436 res
['go_neg_freq'] = s
[3]
440 def p2p_go_neg_auth(self
, peer
, pin
, method
, go_intent
=None, persistent
=False, freq
=None):
441 if not self
.discover_peer(peer
):
442 raise Exception("Peer " + peer
+ " not found")
444 cmd
= "P2P_CONNECT " + peer
+ " " + pin
+ " " + method
+ " auth"
446 cmd
= cmd
+ ' go_intent=' + str(go_intent
)
448 cmd
= cmd
+ ' freq=' + str(freq
)
450 cmd
= cmd
+ " persistent"
451 if "OK" in self
.global_request(cmd
):
453 raise Exception("P2P_CONNECT (auth) failed")
455 def p2p_go_neg_auth_result(self
, timeout
=1, expect_failure
=False):
457 ev
= self
.wait_global_event(["P2P-GO-NEG-SUCCESS",
458 "P2P-GO-NEG-FAILURE"], timeout
);
462 raise Exception("Group formation timed out")
463 if "P2P-GO-NEG-SUCCESS" in ev
:
465 ev
= self
.wait_global_event(["P2P-GROUP-STARTED"], timeout
);
469 raise Exception("Group formation timed out")
471 return self
.group_form_result(ev
, expect_failure
, go_neg_res
)
473 def p2p_go_neg_init(self
, peer
, pin
, method
, timeout
=0, go_intent
=None, expect_failure
=False, persistent
=False, freq
=None, provdisc
=False):
474 if not self
.discover_peer(peer
):
475 raise Exception("Peer " + peer
+ " not found")
478 cmd
= "P2P_CONNECT " + peer
+ " " + pin
+ " " + method
480 cmd
= "P2P_CONNECT " + peer
+ " " + method
482 cmd
= cmd
+ ' go_intent=' + str(go_intent
)
484 cmd
= cmd
+ ' freq=' + str(freq
)
486 cmd
= cmd
+ " persistent"
488 cmd
= cmd
+ " provdisc"
489 if "OK" in self
.global_request(cmd
):
494 ev
= self
.wait_global_event(["P2P-GO-NEG-SUCCESS",
495 "P2P-GO-NEG-FAILURE"], timeout
)
499 raise Exception("Group formation timed out")
500 if "P2P-GO-NEG-SUCCESS" in ev
:
502 ev
= self
.wait_global_event(["P2P-GROUP-STARTED"], timeout
)
506 raise Exception("Group formation timed out")
508 return self
.group_form_result(ev
, expect_failure
, go_neg_res
)
509 raise Exception("P2P_CONNECT failed")
511 def wait_event(self
, events
, timeout
=10):
512 start
= os
.times()[4]
514 while self
.mon
.pending():
516 logger
.debug(self
.ifname
+ ": " + ev
)
521 remaining
= start
+ timeout
- now
524 if not self
.mon
.pending(timeout
=remaining
):
528 def wait_global_event(self
, events
, timeout
):
529 if self
.global_iface
is None:
530 self
.wait_event(events
, timeout
)
532 start
= os
.times()[4]
534 while self
.global_mon
.pending():
535 ev
= self
.global_mon
.recv()
536 logger
.debug(self
.ifname
+ "(global): " + ev
)
541 remaining
= start
+ timeout
- now
544 if not self
.global_mon
.pending(timeout
=remaining
):
548 def wait_go_ending_session(self
):
549 ev
= self
.wait_event(["P2P-GROUP-REMOVED"], timeout
=3)
551 raise Exception("Group removal event timed out")
552 if "reason=GO_ENDING_SESSION" not in ev
:
553 raise Exception("Unexpected group removal reason")
555 def dump_monitor(self
):
556 while self
.mon
.pending():
558 logger
.debug(self
.ifname
+ ": " + ev
)
559 while self
.global_mon
.pending():
560 ev
= self
.global_mon
.recv()
561 logger
.debug(self
.ifname
+ "(global): " + ev
)
563 def remove_group(self
, ifname
=None):
565 ifname
= self
.group_ifname
if self
.group_ifname
else self
.ifname
566 if "OK" not in self
.global_request("P2P_GROUP_REMOVE " + ifname
):
567 raise Exception("Group could not be removed")
568 self
.group_ifname
= None
570 def p2p_start_go(self
, persistent
=None, freq
=None):
572 cmd
= "P2P_GROUP_ADD"
573 if persistent
is None:
575 elif persistent
is True:
576 cmd
= cmd
+ " persistent"
578 cmd
= cmd
+ " persistent=" + str(persistent
)
580 cmd
= cmd
+ " freq=" + str(freq
)
581 if "OK" in self
.global_request(cmd
):
582 ev
= self
.wait_global_event(["P2P-GROUP-STARTED"], timeout
=5)
584 raise Exception("GO start up timed out")
586 return self
.group_form_result(ev
)
587 raise Exception("P2P_GROUP_ADD failed")
589 def p2p_go_authorize_client(self
, pin
):
590 cmd
= "WPS_PIN any " + pin
591 if "FAIL" in self
.group_request(cmd
):
592 raise Exception("Failed to authorize client connection on GO")
595 def p2p_go_authorize_client_pbc(self
):
597 if "FAIL" in self
.group_request(cmd
):
598 raise Exception("Failed to authorize client connection on GO")
601 def p2p_connect_group(self
, go_addr
, pin
, timeout
=0, social
=False):
603 if not self
.discover_peer(go_addr
, social
=social
):
604 raise Exception("GO " + go_addr
+ " not found")
606 cmd
= "P2P_CONNECT " + go_addr
+ " " + pin
+ " join"
607 if "OK" in self
.global_request(cmd
):
611 ev
= self
.wait_global_event(["P2P-GROUP-STARTED"], timeout
)
613 raise Exception("Joining the group timed out")
615 return self
.group_form_result(ev
)
616 raise Exception("P2P_CONNECT(join) failed")
618 def tdls_setup(self
, peer
):
619 cmd
= "TDLS_SETUP " + peer
620 if "FAIL" in self
.group_request(cmd
):
621 raise Exception("Failed to request TDLS setup")
624 def tdls_teardown(self
, peer
):
625 cmd
= "TDLS_TEARDOWN " + peer
626 if "FAIL" in self
.group_request(cmd
):
627 raise Exception("Failed to request TDLS teardown")
630 def connect(self
, ssid
=None, ssid2
=None, **kwargs
):
631 logger
.info("Connect STA " + self
.ifname
+ " to AP")
632 id = self
.add_network()
634 self
.set_network_quoted(id, "ssid", ssid
)
636 self
.set_network(id, "ssid", ssid2
)
638 quoted
= [ "psk", "identity", "anonymous_identity", "password",
639 "ca_cert", "client_cert", "private_key",
640 "private_key_passwd", "ca_cert2", "client_cert2",
641 "private_key2", "phase1", "phase2", "domain_suffix_match",
642 "altsubject_match", "subject_match", "pac_file", "dh_file" ]
644 if field
in kwargs
and kwargs
[field
]:
645 self
.set_network_quoted(id, field
, kwargs
[field
])
647 not_quoted
= [ "proto", "key_mgmt", "ieee80211w", "pairwise",
648 "group", "wep_key0", "scan_freq", "eap",
649 "eapol_flags", "fragment_size", "scan_ssid", "auth_alg",
650 "wpa_ptk_rekey", "disable_ht", "disable_vht", "bssid" ]
651 for field
in not_quoted
:
652 if field
in kwargs
and kwargs
[field
]:
653 self
.set_network(id, field
, kwargs
[field
])
655 if "raw_psk" in kwargs
and kwargs
['raw_psk']:
656 self
.set_network(id, "psk", kwargs
['raw_psk'])
657 if "password_hex" in kwargs
and kwargs
['password_hex']:
658 self
.set_network(id, "password", kwargs
['password_hex'])
659 if "peerkey" in kwargs
and kwargs
['peerkey']:
660 self
.set_network(id, "peerkey", "1")
661 if "okc" in kwargs
and kwargs
['okc']:
662 self
.set_network(id, "proactive_key_caching", "1")
663 if "ocsp" in kwargs
and kwargs
['ocsp']:
664 self
.set_network(id, "ocsp", str(kwargs
['ocsp']))
665 if "only_add_network" in kwargs
and kwargs
['only_add_network']:
667 if "wait_connect" not in kwargs
or kwargs
['wait_connect']:
669 self
.connect_network(id, timeout
=20)
671 self
.connect_network(id)
674 self
.select_network(id)
677 def scan(self
, type=None, freq
=None, no_wait
=False):
679 cmd
= "SCAN TYPE=" + type
683 cmd
= cmd
+ " freq=" + freq
686 if not "OK" in self
.request(cmd
):
687 raise Exception("Failed to trigger scan")
690 ev
= self
.wait_event(["CTRL-EVENT-SCAN-RESULTS"], 15)
692 raise Exception("Scan timed out")
694 def roam(self
, bssid
, fail_test
=False):
696 self
.request("ROAM " + bssid
)
698 ev
= self
.wait_event(["CTRL-EVENT-CONNECTED"], timeout
=1)
700 raise Exception("Unexpected connection")
703 ev
= self
.wait_event(["CTRL-EVENT-CONNECTED"], timeout
=10)
705 raise Exception("Roaming with the AP timed out")
708 def roam_over_ds(self
, bssid
, fail_test
=False):
710 self
.request("FT_DS " + bssid
)
712 ev
= self
.wait_event(["CTRL-EVENT-CONNECTED"], timeout
=1)
714 raise Exception("Unexpected connection")
717 ev
= self
.wait_event(["CTRL-EVENT-CONNECTED"], timeout
=10)
719 raise Exception("Roaming with the AP timed out")
722 def wps_reg(self
, bssid
, pin
, new_ssid
=None, key_mgmt
=None, cipher
=None,
723 new_passphrase
=None, no_wait
=False):
726 self
.request("WPS_REG " + bssid
+ " " + pin
+ " " +
727 new_ssid
.encode("hex") + " " + key_mgmt
+ " " +
728 cipher
+ " " + new_passphrase
.encode("hex"))
731 ev
= self
.wait_event(["WPS-SUCCESS"], timeout
=15)
733 self
.request("WPS_REG " + bssid
+ " " + pin
)
736 ev
= self
.wait_event(["WPS-CRED-RECEIVED"], timeout
=15)
738 raise Exception("WPS cred timed out")
739 ev
= self
.wait_event(["WPS-FAIL"], timeout
=15)
741 raise Exception("WPS timed out")
742 ev
= self
.wait_event(["CTRL-EVENT-CONNECTED"], timeout
=15)
744 raise Exception("Association with the AP timed out")
747 self
.request("RELOG")
749 def wait_completed(self
, timeout
=10):
750 for i
in range(0, timeout
* 2):
751 if self
.get_status_field("wpa_state") == "COMPLETED":
754 raise Exception("Timeout while waiting for COMPLETED state")
756 def get_capability(self
, field
):
757 res
= self
.request("GET_CAPABILITY " + field
)
760 return res
.split(' ')
762 def get_bss(self
, bssid
):
763 res
= self
.request("BSS " + bssid
)
764 lines
= res
.splitlines()
767 [name
,value
] = l
.split('=', 1)
771 def get_pmksa(self
, bssid
):
772 res
= self
.request("PMKSA")
773 lines
= res
.splitlines()
778 [index
,aa
,pmkid
,expiration
,opportunistic
] = l
.split(' ')
779 vals
['index'] = index
780 vals
['pmkid'] = pmkid
781 vals
['expiration'] = expiration
782 vals
['opportunistic'] = opportunistic
786 def get_sta(self
, addr
, info
=None, next
=False):
787 cmd
= "STA-NEXT " if next
else "STA "
789 res
= self
.request("STA-FIRST")
791 res
= self
.request(cmd
+ addr
+ " " + info
)
793 res
= self
.request(cmd
+ addr
)
794 lines
= res
.splitlines()
802 [name
,value
] = l
.split('=', 1)
806 def mgmt_rx(self
, timeout
=5):
807 ev
= self
.wait_event(["MGMT-RX"], timeout
=timeout
)
811 items
= ev
.split(' ')
812 field
,val
= items
[1].split('=')
814 raise Exception("Unexpected MGMT-RX event format: " + ev
)
816 frame
= binascii
.unhexlify(items
[4])
819 hdr
= struct
.unpack('<HH6B6B6BH', frame
[0:24])
821 msg
['subtype'] = (hdr
[0] >> 4) & 0xf
823 msg
['duration'] = hdr
[0]
825 msg
['da'] = "%02x:%02x:%02x:%02x:%02x:%02x" % hdr
[0:6]
827 msg
['sa'] = "%02x:%02x:%02x:%02x:%02x:%02x" % hdr
[0:6]
829 msg
['bssid'] = "%02x:%02x:%02x:%02x:%02x:%02x" % hdr
[0:6]
831 msg
['seq_ctrl'] = hdr
[0]
832 msg
['payload'] = frame
[24:]