diff --git a/tests/hwsim/test_dscp.py b/tests/hwsim/test_dscp.py new file mode 100644 index 000000000..cc09dc475 --- /dev/null +++ b/tests/hwsim/test_dscp.py @@ -0,0 +1,335 @@ +# Test cases for dscp policy +# Copyright (c) 2021, Jouni Malinen +# Copyright (c) 2021, The Linux Foundation +# +# This software may be distributed under the terms of the BSD license. +# See README for more details. + +import struct +import time +import sys +import socket + +import hostapd +from wpasupplicant import WpaSupplicant +from utils import * + +def register_dscp_req(hapd): + type = 0x00d0 + match = "7e506f9a1a" + if "OK" not in hapd.request("REGISTER_FRAME %04x %s" % (type, match)): + raise Exception("Could not register frame reception for Vendor specific protected type") + +def send_dscp_req(hapd, da, oui_subtype, dialog_token, req_control, qos_ie): + type = 0 + subtype = 13 + category = 126 + oui_type = 0x506f9a1a + req = struct.pack('>BLBBB', category, oui_type, oui_subtype, + dialog_token, req_control) + if qos_ie: + req += qos_ie + + msg = {} + msg['fc'] = 0x00d0 + msg['sa'] = hapd.own_addr() + msg['da'] = da + msg['bssid'] = hapd.own_addr() + msg['type'] = type + msg['subtype'] = subtype + msg['payload'] = req + + hapd.mgmt_tx(msg) + ev = hapd.wait_event(["MGMT-TX-STATUS"], timeout=5) + if ev is None or "stype=13 ok=1" not in ev: + raise Exception("No DSCP Policy Request sent") + +def prepare_qos_ie(policy_id, req_type, dscp, start_port, end_port, + frame_classifier, frame_class_len, domain_name): + qos_elem_oui_type = 0x229a6f50 + qos_elem_id = 221 + + if policy_id: + qos_attr = struct.pack('BBBBB', 2, 3, policy_id, req_type, dscp) + qos_attr_len = 5 + else: + qos_attr = 0 + qos_attr_len = 0 + + if start_port and end_port: + port_range_attr = struct.pack('>BBHH', 1, 4, start_port, end_port) + if qos_attr: + qos_attr += port_range_attr + else: + qos_attr = port_range_attr + qos_attr_len += 6 + + if frame_classifier and frame_class_len: + tclas_attr = struct.pack('>BB%ds' % (len(frame_classifier),), 3, + len(frame_classifier), frame_classifier) + if qos_attr: + qos_attr += tclas_attr + else: + qos_attr = tclas_attr + qos_attr_len += 2 + len(frame_classifier) + + if domain_name: + s = bytes(domain_name, 'utf-8') + domain_name_attr = struct.pack('>BB%ds' % (len(s),), 4, len(s), s) + if qos_attr: + qos_attr += domain_name_attr + else: + qos_attr = domain_name_attr + qos_attr_len += 2 + len(s) + + qos_attr_len += 4 + qos_ie = struct.pack('