Signed-off-by: Masashi Honma <masashi.honma@xxxxxxxxx> --- tests/hwsim/test_ap_hs20.py | 189 ++++++++++++++++++------------------ 1 file changed, 95 insertions(+), 94 deletions(-) diff --git a/tests/hwsim/test_ap_hs20.py b/tests/hwsim/test_ap_hs20.py index 6aef83a8a..2c67b2bdf 100644 --- a/tests/hwsim/test_ap_hs20.py +++ b/tests/hwsim/test_ap_hs20.py @@ -351,13 +351,13 @@ def test_ap_nai_home_realm_query(dev, apdev): if len(nai1) >= len(nai2): raise Exception("Unexpected NAI Realm list response lengths") - if "example.com".encode('hex') not in nai1: + if binascii.hexlify(b"example.com").decode() not in nai1: raise Exception("Home realm not reported") - if "example.org".encode('hex') in nai1: + if binascii.hexlify(b"example.org").decode() in nai1: raise Exception("Non-home realm reported") - if "example.com".encode('hex') not in nai2: + if binascii.hexlify(b"example.com").decode() not in nai2: raise Exception("Home realm not reported in wildcard query") - if "example.org".encode('hex') not in nai2: + if binascii.hexlify(b"example.org").decode() not in nai2: raise Exception("Non-home realm not reported in wildcard query ") cmds = [ "foo", @@ -1586,7 +1586,7 @@ def test_ap_hs20_disallow_aps(dev, apdev): dev[0].scan_for_bss(bssid, freq="2412") logger.info("Verify disallow_aps bssid") - dev[0].request("SET disallow_aps bssid " + bssid.translate(None, ':')) + dev[0].request("SET disallow_aps bssid " + bssid.replace(':', '')) dev[0].request("INTERWORKING_SELECT auto") ev = dev[0].wait_event(["INTERWORKING-NO-MATCH"], timeout=15) if ev is None: @@ -1605,7 +1605,7 @@ def test_ap_hs20_disallow_aps(dev, apdev): dev[0].request("SET disallow_aps ") interworking_select(dev[0], bssid, "home", freq="2412") - dev[0].request("SET disallow_aps bssid " + bssid.translate(None, ':')) + dev[0].request("SET disallow_aps bssid " + bssid.replace(':', '')) ret = dev[0].request("INTERWORKING_CONNECT " + bssid) if "FAIL" not in ret: raise Exception("INTERWORKING_CONNECT to disallowed BSS not rejected") @@ -2923,8 +2923,8 @@ def test_ap_hs20_fetch_osu(dev, apdev): params['osu_server_uri'] = "https://example.org/osu/" hostapd.add_ap(apdev[1], params) - with open("w1fi_logo.png", "r") as f: - orig_logo = f.read() + with open("w1fi_logo.png", "rb") as f: + orig_logo = f.read(os.path.getsize("w1fi_logo.png")) dev[0].hs20_enable() dir = "/tmp/osu-fetch" if os.path.isdir(dir): @@ -2956,8 +2956,9 @@ def test_ap_hs20_fetch_osu(dev, apdev): if "OSU provider fetch completed" in ev: break if "RX-HS20-ANQP-ICON" in ev: - with open(ev.split(' ')[1], "r") as f: - logo = f.read() + file_path = ev.split(' ')[1] + with open(file_path, "rb") as f: + logo = f.read(os.path.getsize(file_path)) if logo == orig_logo: icons += 1 @@ -3011,7 +3012,7 @@ def test_ap_hs20_fetch_osu(dev, apdev): raise Exception("GET_HS20_ICON with too many output bytes to fit the buffer succeeded") if "FAIL" not in dev[2].request("GET_HS20_ICON " + bssid + " w1fi_logo 0 0"): raise Exception("GET_HS20_ICON 0..0 succeeded") - icon = "" + icon = bytes() pos = 0 while True: if pos > 100000: @@ -3022,10 +3023,10 @@ def test_ap_hs20_fetch_osu(dev, apdev): icon += base64.b64decode(res) pos += 1000 hex = binascii.hexlify(icon) - if not hex.startswith("0009696d6167652f706e677d1d"): + if not hex.startswith(b"0009696d6167652f706e677d1d"): raise Exception("Unexpected beacon binary header: " + hex) - with open('w1fi_logo.png', 'r') as f: - data = f.read() + with open('w1fi_logo.png', 'rb') as f: + data = f.read(os.path.getsize('w1fi_logo.png')) if icon[13:] != data: raise Exception("Unexpected icon data") if len(icon) != int(event_icon_len): @@ -3253,7 +3254,7 @@ def test_ap_hs20_fetch_osu_single_ssid2(dev, apdev): os.rmdir(dir) def get_icon(dev, bssid, iconname): - icon = "" + icon = bytes() pos = 0 while True: if pos > 100000: @@ -3304,13 +3305,13 @@ def run_req_hs20_icon(dev, bssid): hdr, data1 = get_icon(dev[0], bssid, "w1fi_logo") hdr, data2 = get_icon(dev[0], bssid, "test_logo") - with open('w1fi_logo.png', 'r') as f: - data = f.read() + with open('w1fi_logo.png', 'rb') as f: + data = f.read(os.path.getsize('w1fi_logo.png')) if data1 != data: raise Exception("Unexpected icon data (1)") - with open('auth_serv/sha512-server.pem', 'r') as f: - data = f.read() + with open('auth_serv/sha512-server.pem', 'rb') as f: + data = f.read(os.path.getsize('auth_serv/sha512-server.pem')) if data2 != data: raise Exception("Unexpected icon data (2)") @@ -3330,13 +3331,13 @@ def test_ap_hs20_req_operator_icon(dev, apdev): params['operator_icon'] = [ "w1fi_logo", "unknown_logo", "test_logo" ] hostapd.add_ap(apdev[0], params) - value = struct.pack('<HH', 128, 80) + "zxx" - value += struct.pack('B', 9) + "image/png" - value += struct.pack('B', 9) + "w1fi_logo" + value = struct.pack('<HH', 128, 80) + b"zxx" + value += struct.pack('B', 9) + b"image/png" + value += struct.pack('B', 9) + b"w1fi_logo" - value += struct.pack('<HH', 500, 300) + "fi\0" - value += struct.pack('B', 9) + "image/png" - value += struct.pack('B', 9) + "test_logo" + value += struct.pack('<HH', 500, 300) + b"fi\0" + value += struct.pack('B', 9) + b"image/png" + value += struct.pack('B', 9) + b"test_logo" dev[0].scan_for_bss(bssid, freq="2412") @@ -3364,8 +3365,8 @@ def test_ap_hs20_req_operator_icon(dev, apdev): bss = dev[0].get_bss(bssid) if "hs20_operator_icon_metadata" not in bss: raise Exception("hs20_operator_icon_metadata missing from BSS entry") - if bss["hs20_operator_icon_metadata"] != binascii.hexlify(value): - print(binascii.hexlify(value)) + if binascii.unhexlify(bss["hs20_operator_icon_metadata"]) != value: + print(binascii.hexlify(value).decode()) raise Exception("Unexpected hs20_operator_icon_metadata value: " + bss["hs20_operator_icon_metadata"]) @@ -3458,13 +3459,13 @@ def test_ap_hs20_req_hs20_icon_parallel(dev, apdev): hdr, data1 = get_icon(dev[0], bssid, "w1fi_logo") hdr, data2 = get_icon(dev[0], bssid, "test_logo") - with open('w1fi_logo.png', 'r') as f: - data = f.read() + with open('w1fi_logo.png', 'rb') as f: + data = f.read(os.path.getsize('w1fi_logo.png')) if data1 != data: raise Exception("Unexpected icon data (1)") - with open('auth_serv/sha512-server.pem', 'r') as f: - data = f.read() + with open('auth_serv/sha512-server.pem', 'rb') as f: + data = f.read(os.path.getsize('auth_serv/sha512-server.pem')) if data2 != data: raise Exception("Unexpected icon data (2)") @@ -3578,11 +3579,11 @@ def test_ap_hs20_fetch_osu_proto(dev, apdev): except: pass - tests = [ ( "Empty provider list (no OSU SSID field)", '' ), + tests = [ ( "Empty provider list (no OSU SSID field)", bytes() ), ( "HS 2.0: Not enough room for OSU SSID", binascii.unhexlify('01') ), ( "HS 2.0: Invalid OSU SSID Length 33", - binascii.unhexlify('21') + 33*'A' ), + binascii.unhexlify('21') + 33 * b'A' ), ( "HS 2.0: Not enough room for Number of OSU Providers", binascii.unhexlify('0130') ), ( "Truncated OSU Provider", @@ -4135,25 +4136,25 @@ def _test_ap_hs20_proxyarp(dev, apdev): addr0 = dev[0].p2p_interface_addr() addr1 = dev[1].p2p_interface_addr() - src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':','')) - src_ll_opt1 = "\x01\x01" + binascii.unhexlify(addr1.replace(':','')) + src_ll_opt0 = b"\x01\x01" + binascii.unhexlify(addr0.replace(':','')) + src_ll_opt1 = b"\x01\x01" + binascii.unhexlify(addr1.replace(':','')) pkt = build_ns(src_ll=addr0, ip_src="aaaa:bbbb:cccc::2", ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:cccc::2", opt=src_ll_opt0) - if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)): + if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") pkt = build_ns(src_ll=addr1, ip_src="aaaa:bbbb:dddd::2", ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:dddd::2", opt=src_ll_opt1) - if "OK" not in dev[1].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)): + if "OK" not in dev[1].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") pkt = build_ns(src_ll=addr1, ip_src="aaaa:bbbb:eeee::2", ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:eeee::2", opt=src_ll_opt1) - if "OK" not in dev[1].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)): + if "OK" not in dev[1].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") matches = get_permanent_neighbors("ap-br0") @@ -4258,34 +4259,34 @@ def _test_ap_hs20_proxyarp_dgaf(dev, apdev, disabled): addr0 = dev[0].p2p_interface_addr() - src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':','')) + src_ll_opt0 = b"\x01\x01" + binascii.unhexlify(addr0.replace(':','')) pkt = build_ns(src_ll=addr0, ip_src="aaaa:bbbb:cccc::2", ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:cccc::2", opt=src_ll_opt0) - if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)): + if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") pkt = build_ra(src_ll=apdev[0]['bssid'], ip_src="aaaa:bbbb:cccc::33", ip_dst="ff01::1") - if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): + if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") pkt = build_na(src_ll=apdev[0]['bssid'], ip_src="aaaa:bbbb:cccc::44", ip_dst="ff01::1", target="aaaa:bbbb:cccc::55") - if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): + if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") pkt = build_dhcp_ack(dst_ll="ff:ff:ff:ff:ff:ff", src_ll=bssid, ip_src="192.168.1.1", ip_dst="255.255.255.255", yiaddr="192.168.1.123", chaddr=addr0) - if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): + if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # another copy for additional code coverage pkt = build_dhcp_ack(dst_ll=addr0, src_ll=bssid, ip_src="192.168.1.1", ip_dst="255.255.255.255", yiaddr="192.168.1.123", chaddr=addr0) - if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): + if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") matches = get_permanent_neighbors("ap-br0") @@ -4329,7 +4330,7 @@ def test_ap_hs20_proxyarp_enable_dgaf(dev, apdev): def ip_checksum(buf): sum = 0 if len(buf) & 0x01: - buf += '\x00' + buf += b'\x00' for i in range(0, len(buf), 2): val, = struct.unpack('H', buf[i:i+2]) sum += val @@ -4353,7 +4354,7 @@ def ipv6_solicited_node_mcaddr(target): def build_icmpv6(ipv6_addrs, type, code, payload): start = struct.pack("BB", type, code) end = payload - icmp = start + '\x00\x00' + end + icmp = start + b'\x00\x00' + end pseudo = ipv6_addrs + struct.pack(">LBBBB", len(icmp), 0, 0, 0, 58) csum = ip_checksum(pseudo + icmp) return start + csum + end @@ -4362,7 +4363,7 @@ def build_ra(src_ll, ip_src, ip_dst, cur_hop_limit=0, router_lifetime=0, reachable_time=0, retrans_timer=0, opt=None): link_mc = binascii.unhexlify("3333ff000002") _src_ll = binascii.unhexlify(src_ll.replace(':','')) - proto = '\x86\xdd' + proto = b'\x86\xdd' ehdr = link_mc + _src_ll + proto _ip_src = socket.inet_pton(socket.AF_INET6, ip_src) _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst) @@ -4383,14 +4384,14 @@ def build_ra(src_ll, ip_src, ip_dst, cur_hop_limit=0, router_lifetime=0, def build_ns(src_ll, ip_src, ip_dst, target, opt=None): link_mc = binascii.unhexlify("3333ff000002") _src_ll = binascii.unhexlify(src_ll.replace(':','')) - proto = '\x86\xdd' + proto = b'\x86\xdd' ehdr = link_mc + _src_ll + proto _ip_src = socket.inet_pton(socket.AF_INET6, ip_src) if ip_dst is None: ip_dst = ipv6_solicited_node_mcaddr(target) _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst) - reserved = '\x00\x00\x00\x00' + reserved = b'\x00\x00\x00\x00' _target = socket.inet_pton(socket.AF_INET6, target) if opt: payload = reserved + _target + opt @@ -4415,17 +4416,17 @@ def send_ns(dev, src_ll=None, target=None, ip_src=None, ip_dst=None, opt=None, cmd = "DATA_TEST_FRAME " if opt is None: - opt = "\x01\x01" + binascii.unhexlify(src_ll.replace(':','')) + opt = b"\x01\x01" + binascii.unhexlify(src_ll.replace(':','')) pkt = build_ns(src_ll=src_ll, ip_src=ip_src, ip_dst=ip_dst, target=target, opt=opt) - if "OK" not in dev.request(cmd + binascii.hexlify(pkt)): + if "OK" not in dev.request(cmd + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") def build_na(src_ll, ip_src, ip_dst, target, opt=None, flags=0): link_mc = binascii.unhexlify("3333ff000002") _src_ll = binascii.unhexlify(src_ll.replace(':','')) - proto = '\x86\xdd' + proto = b'\x86\xdd' ehdr = link_mc + _src_ll + proto _ip_src = socket.inet_pton(socket.AF_INET6, ip_src) _ip_dst = socket.inet_pton(socket.AF_INET6, ip_dst) @@ -4455,7 +4456,7 @@ def send_na(dev, src_ll=None, target=None, ip_src=None, ip_dst=None, opt=None, pkt = build_na(src_ll=src_ll, ip_src=ip_src, ip_dst=ip_dst, target=target, opt=opt) - if "OK" not in dev.request(cmd + binascii.hexlify(pkt)): + if "OK" not in dev.request(cmd + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") def build_dhcp_ack(dst_ll, src_ll, ip_src, ip_dst, yiaddr, chaddr, @@ -4464,42 +4465,42 @@ def build_dhcp_ack(dst_ll, src_ll, ip_src, ip_dst, yiaddr, chaddr, udp_checksum=True): _dst_ll = binascii.unhexlify(dst_ll.replace(':','')) _src_ll = binascii.unhexlify(src_ll.replace(':','')) - proto = '\x08\x00' + proto = b'\x08\x00' ehdr = _dst_ll + _src_ll + proto _ip_src = socket.inet_pton(socket.AF_INET, ip_src) _ip_dst = socket.inet_pton(socket.AF_INET, ip_dst) _subnet_mask = socket.inet_pton(socket.AF_INET, subnet_mask) - _ciaddr = '\x00\x00\x00\x00' + _ciaddr = b'\x00\x00\x00\x00' _yiaddr = socket.inet_pton(socket.AF_INET, yiaddr) - _siaddr = '\x00\x00\x00\x00' - _giaddr = '\x00\x00\x00\x00' + _siaddr = b'\x00\x00\x00\x00' + _giaddr = b'\x00\x00\x00\x00' _chaddr = binascii.unhexlify(chaddr.replace(':','') + "00000000000000000000") payload = struct.pack('>BBBBL3BB', 2, 1, 6, 0, 12345, 0, 0, 0, 0) - payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + 192*'\x00' + payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + 192 * b'\x00' # magic if wrong_magic: - payload += '\x63\x82\x53\x00' + payload += b'\x63\x82\x53\x00' else: - payload += '\x63\x82\x53\x63' + payload += b'\x63\x82\x53\x63' if truncated_opt: - payload += '\x22\xff\x00' + payload += b'\x22\xff\x00' # Option: DHCP Message Type = ACK - payload += '\x35\x01\x05' + payload += b'\x35\x01\x05' # Pad Option - payload += '\x00' + payload += b'\x00' # Option: Subnet Mask - payload += '\x01\x04' + _subnet_mask + payload += b'\x01\x04' + _subnet_mask # Option: Time Offset payload += struct.pack('>BBL', 2, 4, 0) # End Option - payload += '\xff' + payload += b'\xff' # Pad Option - payload += '\x00\x00\x00\x00' + payload += b'\x00\x00\x00\x00' if no_dhcp: payload = struct.pack('>BBBBL3BB', 2, 1, 6, 0, 12345, 0, 0, 0, 0) - payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + 192*'\x00' + payload += _ciaddr + _yiaddr + _siaddr + _giaddr + _chaddr + 192 * b'\x00' if udp_checksum: pseudohdr = _ip_src + _ip_dst + struct.pack('>BBH', 0, 17, @@ -4515,7 +4516,7 @@ def build_dhcp_ack(dst_ll, src_ll, ip_src, ip_dst, yiaddr, chaddr, else: tot_len = 20 + len(udp) start = struct.pack('>BBHHBBBB', 0x45, 0, tot_len, 0, 0, 0, 128, 17) - ipv4 = start + '\x00\x00' + _ip_src + _ip_dst + ipv4 = start + b'\x00\x00' + _ip_src + _ip_dst csum = ip_checksum(ipv4) ipv4 = start + csum + _ip_src + _ip_dst @@ -4525,7 +4526,7 @@ def build_arp(dst_ll, src_ll, opcode, sender_mac, sender_ip, target_mac, target_ip): _dst_ll = binascii.unhexlify(dst_ll.replace(':','')) _src_ll = binascii.unhexlify(src_ll.replace(':','')) - proto = '\x08\x06' + proto = b'\x08\x06' ehdr = _dst_ll + _src_ll + proto _sender_mac = binascii.unhexlify(sender_mac.replace(':','')) @@ -4559,12 +4560,12 @@ def send_arp(dev, dst_ll="ff:ff:ff:ff:ff:ff", src_ll=None, opcode=1, pkt = build_arp(dst_ll=dst_ll, src_ll=src_ll, opcode=opcode, sender_mac=sender_mac, sender_ip=sender_ip, target_mac=target_mac, target_ip=target_ip) - if "OK" not in dev.request(cmd + binascii.hexlify(pkt)): + if "OK" not in dev.request(cmd + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") def get_permanent_neighbors(ifname): cmd = subprocess.Popen(['ip', 'nei'], stdout=subprocess.PIPE) - res = cmd.stdout.read() + res = cmd.stdout.read().decode() cmd.stdout.close() return [ line for line in res.splitlines() if "PERMANENT" in line and ifname in line ] @@ -4678,13 +4679,13 @@ def _test_proxyarp_open(dev, apdev, params, ebtables=False): time.sleep(0.1) brcmd = subprocess.Popen(['brctl', 'show'], stdout=subprocess.PIPE) - res = brcmd.stdout.read() + res = brcmd.stdout.read().decode() brcmd.stdout.close() logger.info("Bridge setup: " + res) brcmd = subprocess.Popen(['brctl', 'showstp', 'ap-br0'], stdout=subprocess.PIPE) - res = brcmd.stdout.read() + res = brcmd.stdout.read().decode() brcmd.stdout.close() logger.info("Bridge showstp: " + res) @@ -4695,28 +4696,28 @@ def _test_proxyarp_open(dev, apdev, params, ebtables=False): pkt = build_dhcp_ack(dst_ll="ff:ff:ff:ff:ff:ff", src_ll=bssid, ip_src="192.168.1.1", ip_dst="255.255.255.255", yiaddr="192.168.1.124", chaddr=addr0) - if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): + if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # Change address and verify unicast pkt = build_dhcp_ack(dst_ll=addr0, src_ll=bssid, ip_src="192.168.1.1", ip_dst="255.255.255.255", yiaddr="192.168.1.123", chaddr=addr0, udp_checksum=False) - if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): + if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # Not-associated client MAC address pkt = build_dhcp_ack(dst_ll="ff:ff:ff:ff:ff:ff", src_ll=bssid, ip_src="192.168.1.1", ip_dst="255.255.255.255", yiaddr="192.168.1.125", chaddr="22:33:44:55:66:77") - if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): + if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # No IP address pkt = build_dhcp_ack(dst_ll=addr1, src_ll=bssid, ip_src="192.168.1.1", ip_dst="255.255.255.255", yiaddr="0.0.0.0", chaddr=addr1) - if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): + if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # Zero subnet mask @@ -4724,7 +4725,7 @@ def _test_proxyarp_open(dev, apdev, params, ebtables=False): ip_src="192.168.1.1", ip_dst="255.255.255.255", yiaddr="192.168.1.126", chaddr=addr1, subnet_mask="0.0.0.0") - if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): + if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # Truncated option @@ -4732,7 +4733,7 @@ def _test_proxyarp_open(dev, apdev, params, ebtables=False): ip_src="192.168.1.1", ip_dst="255.255.255.255", yiaddr="192.168.1.127", chaddr=addr1, truncated_opt=True) - if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): + if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # Wrong magic @@ -4740,7 +4741,7 @@ def _test_proxyarp_open(dev, apdev, params, ebtables=False): ip_src="192.168.1.1", ip_dst="255.255.255.255", yiaddr="192.168.1.128", chaddr=addr1, wrong_magic=True) - if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): + if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # Wrong IPv4 total length @@ -4748,7 +4749,7 @@ def _test_proxyarp_open(dev, apdev, params, ebtables=False): ip_src="192.168.1.1", ip_dst="255.255.255.255", yiaddr="192.168.1.129", chaddr=addr1, force_tot_len=1000) - if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): + if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") # BOOTP @@ -4756,7 +4757,7 @@ def _test_proxyarp_open(dev, apdev, params, ebtables=False): ip_src="192.168.1.1", ip_dst="255.255.255.255", yiaddr="192.168.1.129", chaddr=addr1, no_dhcp=True) - if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): + if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") macs = get_bridge_macs("ap-br0") @@ -4873,7 +4874,7 @@ def _test_proxyarp_open(dev, apdev, params, ebtables=False): if ebtables: cmd = subprocess.Popen(['ebtables', '-L', '--Lc'], stdout=subprocess.PIPE) - res = cmd.stdout.read() + res = cmd.stdout.read().decode() cmd.stdout.close() logger.info("ebtables results:\n" + res) @@ -5024,13 +5025,13 @@ def _test_proxyarp_open_ipv6(dev, apdev, params, ebtables=False): time.sleep(0.1) brcmd = subprocess.Popen(['brctl', 'show'], stdout=subprocess.PIPE) - res = brcmd.stdout.read() + res = brcmd.stdout.read().decode() brcmd.stdout.close() logger.info("Bridge setup: " + res) brcmd = subprocess.Popen(['brctl', 'showstp', 'ap-br0'], stdout=subprocess.PIPE) - res = brcmd.stdout.read() + res = brcmd.stdout.read().decode() brcmd.stdout.close() logger.info("Bridge showstp: " + res) @@ -5038,8 +5039,8 @@ def _test_proxyarp_open_ipv6(dev, apdev, params, ebtables=False): addr1 = dev[1].p2p_interface_addr() addr2 = dev[2].p2p_interface_addr() - src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':','')) - src_ll_opt1 = "\x01\x01" + binascii.unhexlify(addr1.replace(':','')) + src_ll_opt0 = b"\x01\x01" + binascii.unhexlify(addr0.replace(':','')) + src_ll_opt1 = b"\x01\x01" + binascii.unhexlify(addr1.replace(':','')) # DAD NS send_ns(dev[0], ip_src="::", target="aaaa:bbbb:cccc::2") @@ -5050,13 +5051,13 @@ def _test_proxyarp_open_ipv6(dev, apdev, params, ebtables=False): opt='') # test frame with bogus option send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2", - opt="\x70\x01\x01\x02\x03\x04\x05\x05") + opt=b"\x70\x01\x01\x02\x03\x04\x05\x05") # test frame with truncated source link-layer address option send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2", - opt="\x01\x01\x01\x02\x03\x04") + opt=b"\x01\x01\x01\x02\x03\x04") # test frame with foreign source link-layer address option send_ns(dev[0], ip_src="aaaa:bbbb:cccc::2", target="aaaa:bbbb:cccc::2", - opt="\x01\x01\x01\x02\x03\x04\x05\x06") + opt=b"\x01\x01\x01\x02\x03\x04\x05\x06") send_ns(dev[1], ip_src="aaaa:bbbb:dddd::2", target="aaaa:bbbb:dddd::2") @@ -5130,7 +5131,7 @@ def _test_proxyarp_open_ipv6(dev, apdev, params, ebtables=False): if ebtables: cmd = subprocess.Popen(['ebtables', '-L', '--Lc'], stdout=subprocess.PIPE) - res = cmd.stdout.read() + res = cmd.stdout.read().decode() cmd.stdout.close() logger.info("ebtables results:\n" + res) @@ -5283,16 +5284,16 @@ def run_proxyarp_errors(dev, apdev, params): pkt = build_ra(src_ll=apdev[0]['bssid'], ip_src="aaaa:bbbb:cccc::33", ip_dst="ff01::1") with fail_test(hapd, 1, "x_snoop_mcast_to_ucast_convert_send"): - if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt)): + if "OK" not in hapd.request("DATA_TEST_FRAME ifname=ap-br0 " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") wait_fail_trigger(dev[0], "GET_FAIL") with alloc_fail(hapd, 1, "sta_ip6addr_add"): - src_ll_opt0 = "\x01\x01" + binascii.unhexlify(addr0.replace(':','')) + src_ll_opt0 = b"\x01\x01" + binascii.unhexlify(addr0.replace(':','')) pkt = build_ns(src_ll=addr0, ip_src="aaaa:bbbb:cccc::2", ip_dst="ff02::1:ff00:2", target="aaaa:bbbb:cccc::2", opt=src_ll_opt0) - if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt)): + if "OK" not in dev[0].request("DATA_TEST_FRAME " + binascii.hexlify(pkt).decode()): raise Exception("DATA_TEST_FRAME failed") wait_fail_trigger(dev[0], "GET_ALLOC_FAIL") -- 2.17.1 _______________________________________________ Hostap mailing list Hostap@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/hostap