From bfe375ec77f2fa770400ddfcc4a5884b8a17c830 Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Thu, 26 Dec 2013 10:52:11 +0200 Subject: [PATCH] tests: Verify behavior on incorrect GAS response type Signed-hostap: Jouni Malinen --- tests/hwsim/hostapd.py | 35 ++++++++++++++++++++++++++++++ tests/hwsim/test_gas.py | 48 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/tests/hwsim/hostapd.py b/tests/hwsim/hostapd.py index 19b9fad2b..12e4a9f86 100644 --- a/tests/hwsim/hostapd.py +++ b/tests/hwsim/hostapd.py @@ -9,12 +9,17 @@ import os import time import logging +import binascii +import struct import wpaspy logger = logging.getLogger() hapd_ctrl = '/var/run/hostapd' hapd_global = '/var/run/hostapd-global' +def mac2tuple(mac): + return struct.unpack('6B', binascii.unhexlify(mac.replace(':',''))) + class HostapdGlobal: def __init__(self): self.ctrl = wpaspy.Ctrl(hapd_global) @@ -144,6 +149,36 @@ class Hostapd: return vals[field] return None + def mgmt_rx(self, timeout=5): + ev = self.wait_event(["MGMT-RX"], timeout=timeout) + if ev is None: + return None + msg = {} + frame = binascii.unhexlify(ev.split(' ')[1]) + msg['frame'] = frame + + hdr = struct.unpack('> 4) & 0xf + hdr = hdr[1:] + msg['duration'] = hdr[0] + hdr = hdr[1:] + msg['da'] = "%02x:%02x:%02x:%02x:%02x:%02x" % hdr[0:6] + hdr = hdr[6:] + msg['sa'] = "%02x:%02x:%02x:%02x:%02x:%02x" % hdr[0:6] + hdr = hdr[6:] + msg['bssid'] = "%02x:%02x:%02x:%02x:%02x:%02x" % hdr[0:6] + hdr = hdr[6:] + msg['seq_ctrl'] = hdr[0] + msg['payload'] = frame[24:] + + return msg + + def mgmt_tx(self, msg): + t = (msg['fc'], 0) + mac2tuple(msg['da']) + mac2tuple(msg['sa']) + mac2tuple(msg['bssid']) + (0,) + hdr = struct.pack('