]>
Commit | Line | Data |
---|---|---|
5f3eddac JM |
1 | # P2P service discovery test cases |
2 | # Copyright (c) 2013, Jouni Malinen <j@w1.fi> | |
3 | # | |
4 | # This software may be distributed under the terms of the BSD license. | |
5 | # See README for more details. | |
6 | ||
7 | import logging | |
c9aa4308 | 8 | logger = logging.getLogger() |
34d35be4 | 9 | import uuid |
5f3eddac JM |
10 | |
11 | import hwsim_utils | |
12 | ||
13 | def add_bonjour_services(dev): | |
14 | dev.request("P2P_SERVICE_ADD bonjour 0b5f6166706f766572746370c00c000c01 074578616d706c65c027") | |
15 | dev.request("P2P_SERVICE_ADD bonjour 076578616d706c650b5f6166706f766572746370c00c001001 00") | |
16 | dev.request("P2P_SERVICE_ADD bonjour 045f697070c00c000c01 094d795072696e746572c027") | |
17 | dev.request("P2P_SERVICE_ADD bonjour 096d797072696e746572045f697070c00c001001 09747874766572733d311a70646c3d6170706c69636174696f6e2f706f7374736372797074") | |
18 | ||
19 | def add_upnp_services(dev): | |
20 | dev.request("P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::upnp:rootdevice") | |
21 | dev.request("P2P_SERVICE_ADD upnp 10 uuid:5566d33e-9774-09ab-4822-333456785632::upnp:rootdevice") | |
22 | dev.request("P2P_SERVICE_ADD upnp 10 uuid:1122de4e-8574-59ab-9322-333456789044::urn:schemas-upnp-org:service:ContentDirectory:2") | |
23 | dev.request("P2P_SERVICE_ADD upnp 10 uuid:5566d33e-9774-09ab-4822-333456785632::urn:schemas-upnp-org:service:ContentDirectory:2") | |
24 | dev.request("P2P_SERVICE_ADD upnp 10 uuid:6859dede-8574-59ab-9332-123456789012::urn:schemas-upnp-org:device:InternetGatewayDevice:1") | |
25 | ||
34d35be4 JM |
26 | def add_extra_services(dev): |
27 | for i in range(0, 100): | |
28 | dev.request("P2P_SERVICE_ADD upnp 10 uuid:" + str(uuid.uuid4()) + "::upnp:rootdevice") | |
29 | ||
66a63315 | 30 | def run_sd(dev, dst, query, exp_query=None, fragment=False, query2=None): |
5f3eddac JM |
31 | addr0 = dev[0].p2p_dev_addr() |
32 | addr1 = dev[1].p2p_dev_addr() | |
33 | add_bonjour_services(dev[0]) | |
34 | add_upnp_services(dev[0]) | |
34d35be4 JM |
35 | if fragment: |
36 | add_extra_services(dev[0]) | |
5f3eddac JM |
37 | dev[0].p2p_listen() |
38 | ||
39 | dev[1].request("P2P_FLUSH") | |
40 | dev[1].request("P2P_SERV_DISC_REQ " + dst + " " + query) | |
66a63315 JM |
41 | if query2: |
42 | dev[1].request("P2P_SERV_DISC_REQ " + dst + " " + query2) | |
d4b21766 | 43 | if not dev[1].discover_peer(addr0, social=True, force_find=True): |
5f3eddac JM |
44 | raise Exception("Peer " + addr0 + " not found") |
45 | ||
46 | ev = dev[0].wait_event(["P2P-SERV-DISC-REQ"], timeout=10) | |
47 | if ev is None: | |
48 | raise Exception("Service discovery timed out") | |
49 | if addr1 not in ev: | |
50 | raise Exception("Unexpected service discovery request source") | |
51 | if exp_query is None: | |
52 | exp_query = query | |
66a63315 | 53 | if exp_query not in ev and (query2 is None or query2 not in ev): |
5f3eddac JM |
54 | raise Exception("Unexpected service discovery request contents") |
55 | ||
66a63315 JM |
56 | if query2: |
57 | ev_list = [] | |
58 | for i in range(0, 4): | |
59 | ev = dev[1].wait_event(["P2P-SERV-DISC-RESP"], timeout=10) | |
60 | if ev is None: | |
61 | raise Exception("Service discovery timed out") | |
62 | if addr0 in ev: | |
63 | ev_list.append(ev) | |
64 | if len(ev_list) == 2: | |
65 | break | |
66 | return ev_list | |
67 | ||
68 | for i in range(0, 2): | |
69 | ev = dev[1].wait_event(["P2P-SERV-DISC-RESP"], timeout=10) | |
70 | if ev is None: | |
71 | raise Exception("Service discovery timed out") | |
72 | if addr0 in ev: | |
73 | break | |
5f3eddac JM |
74 | return ev |
75 | ||
76 | def test_p2p_service_discovery(dev): | |
77 | """P2P service discovery""" | |
474d2090 JM |
78 | for dst in [ "00:00:00:00:00:00", dev[0].p2p_dev_addr() ]: |
79 | ev = run_sd(dev, dst, "02000001") | |
34d35be4 JM |
80 | if "0b5f6166706f766572746370c00c000c01" not in ev: |
81 | raise Exception("Unexpected service discovery response contents (Bonjour)") | |
82 | if "496e7465726e6574" not in ev: | |
83 | raise Exception("Unexpected service discovery response contents (UPnP)") | |
84 | ||
66a63315 JM |
85 | def test_p2p_service_discovery2(dev): |
86 | """P2P service discovery with one peer having no services""" | |
87 | dev[2].p2p_listen() | |
88 | for dst in [ "00:00:00:00:00:00", dev[0].p2p_dev_addr() ]: | |
89 | ev = run_sd(dev, dst, "02000001") | |
90 | if "0b5f6166706f766572746370c00c000c01" not in ev: | |
91 | raise Exception("Unexpected service discovery response contents (Bonjour)") | |
92 | if "496e7465726e6574" not in ev: | |
93 | raise Exception("Unexpected service discovery response contents (UPnP)") | |
94 | ||
95 | def test_p2p_service_discovery_multiple_queries(dev): | |
96 | """P2P service discovery with multiple queries""" | |
97 | for dst in [ "00:00:00:00:00:00", dev[0].p2p_dev_addr() ]: | |
98 | ev = run_sd(dev, dst, "02000201", query2="02000101") | |
99 | if "0b5f6166706f766572746370c00c000c01" not in ev[0] + ev[1]: | |
100 | raise Exception("Unexpected service discovery response contents (Bonjour)") | |
101 | if "496e7465726e6574" not in ev[0] + ev[1]: | |
102 | raise Exception("Unexpected service discovery response contents (UPnP)") | |
103 | ||
104 | def test_p2p_service_discovery_multiple_queries2(dev): | |
105 | """P2P service discovery with multiple queries with one peer having no services""" | |
106 | dev[2].p2p_listen() | |
107 | for dst in [ "00:00:00:00:00:00", dev[0].p2p_dev_addr() ]: | |
108 | ev = run_sd(dev, dst, "02000201", query2="02000101") | |
109 | if "0b5f6166706f766572746370c00c000c01" not in ev[0] + ev[1]: | |
110 | raise Exception("Unexpected service discovery response contents (Bonjour)") | |
111 | if "496e7465726e6574" not in ev[0] + ev[1]: | |
112 | raise Exception("Unexpected service discovery response contents (UPnP)") | |
113 | ||
474d2090 JM |
114 | def test_p2p_service_discovery_fragmentation(dev): |
115 | """P2P service discovery with fragmentation""" | |
116 | for dst in [ "00:00:00:00:00:00", dev[0].p2p_dev_addr() ]: | |
117 | ev = run_sd(dev, dst, "02000001", fragment=True) | |
118 | if not "long response" in ev: | |
119 | if "0b5f6166706f766572746370c00c000c01" not in ev: | |
120 | raise Exception("Unexpected service discovery response contents (Bonjour)") | |
121 | if "496e7465726e6574" not in ev: | |
122 | raise Exception("Unexpected service discovery response contents (UPnP)") | |
123 | ||
5f3eddac JM |
124 | def test_p2p_service_discovery_bonjour(dev): |
125 | """P2P service discovery (Bonjour)""" | |
126 | ev = run_sd(dev, "00:00:00:00:00:00", "02000101") | |
127 | if "0b5f6166706f766572746370c00c000c01" not in ev: | |
128 | raise Exception("Unexpected service discovery response contents (Bonjour)") | |
129 | if "045f697070c00c000c01" not in ev: | |
130 | raise Exception("Unexpected service discovery response contents (Bonjour)") | |
131 | if "496e7465726e6574" in ev: | |
132 | raise Exception("Unexpected service discovery response contents (UPnP not expected)") | |
133 | ||
134 | def test_p2p_service_discovery_bonjour2(dev): | |
135 | """P2P service discovery (Bonjour AFS)""" | |
136 | ev = run_sd(dev, "00:00:00:00:00:00", "130001010b5f6166706f766572746370c00c000c01") | |
137 | if "0b5f6166706f766572746370c00c000c01" not in ev: | |
138 | raise Exception("Unexpected service discovery response contents (Bonjour)") | |
139 | if "045f697070c00c000c01" in ev: | |
140 | raise Exception("Unexpected service discovery response contents (Bonjour mismatching)") | |
141 | if "496e7465726e6574" in ev: | |
142 | raise Exception("Unexpected service discovery response contents (UPnP not expected)") | |
143 | ||
144 | def test_p2p_service_discovery_upnp(dev): | |
145 | """P2P service discovery (UPnP)""" | |
146 | ev = run_sd(dev, "00:00:00:00:00:00", "02000201") | |
147 | if "0b5f6166706f766572746370c00c000c01" in ev: | |
148 | raise Exception("Unexpected service discovery response contents (Bonjour not expected)") | |
149 | if "496e7465726e6574" not in ev: | |
150 | raise Exception("Unexpected service discovery response contents (UPnP)") | |
151 | ||
152 | def test_p2p_service_discovery_upnp2(dev): | |
153 | """P2P service discovery (UPnP using request helper)""" | |
154 | ev = run_sd(dev, "00:00:00:00:00:00", "upnp 10 ssdp:all", "0b00020110737364703a616c6c") | |
155 | if "0b5f6166706f766572746370c00c000c01" in ev: | |
156 | raise Exception("Unexpected service discovery response contents (Bonjour not expected)") | |
157 | if "496e7465726e6574" not in ev: | |
158 | raise Exception("Unexpected service discovery response contents (UPnP)") | |
159 | ||
160 | def test_p2p_service_discovery_ws(dev): | |
161 | """P2P service discovery (WS-Discovery)""" | |
162 | ev = run_sd(dev, "00:00:00:00:00:00", "02000301") | |
163 | if "0b5f6166706f766572746370c00c000c01" in ev: | |
164 | raise Exception("Unexpected service discovery response contents (Bonjour not expected)") | |
165 | if "496e7465726e6574" in ev: | |
166 | raise Exception("Unexpected service discovery response contents (UPnP not expected)") | |
167 | if "0300030101" not in ev: | |
168 | raise Exception("Unexpected service discovery response contents (WS)") | |
8fdcca34 JM |
169 | |
170 | def test_p2p_service_discovery_req_cancel(dev): | |
171 | """Cancel a P2P service discovery request""" | |
172 | if "FAIL" not in dev[0].request("P2P_SERV_DISC_CANCEL_REQ ab"): | |
173 | raise Exception("Unexpected SD cancel success") | |
174 | query = dev[0].request("P2P_SERV_DISC_REQ " + dev[1].p2p_dev_addr() + " 02000001") | |
175 | if "OK" not in dev[0].request("P2P_SERV_DISC_CANCEL_REQ " + query): | |
176 | raise Exception("Unexpected SD cancel failure") | |
177 | query1 = dev[0].request("P2P_SERV_DISC_REQ " + dev[1].p2p_dev_addr() + " 02000001") | |
178 | query2 = dev[0].request("P2P_SERV_DISC_REQ " + dev[1].p2p_dev_addr() + " 02000002") | |
179 | query3 = dev[0].request("P2P_SERV_DISC_REQ " + dev[1].p2p_dev_addr() + " 02000003") | |
180 | if "OK" not in dev[0].request("P2P_SERV_DISC_CANCEL_REQ " + query2): | |
181 | raise Exception("Unexpected SD cancel failure") | |
182 | if "OK" not in dev[0].request("P2P_SERV_DISC_CANCEL_REQ " + query1): | |
183 | raise Exception("Unexpected SD cancel failure") | |
184 | if "OK" not in dev[0].request("P2P_SERV_DISC_CANCEL_REQ " + query3): | |
185 | raise Exception("Unexpected SD cancel failure") |