| 1 |
% Regression tests for Simulated ECUs and UDS Scanners |
| 2 |
~ scanner |
| 3 |
|
| 4 |
+ Configuration |
| 5 |
~ conf |
| 6 |
|
| 7 |
= Imports |
| 8 |
import io |
| 9 |
import pickle |
| 10 |
from scapy.contrib.isotp import ISOTPMessageBuilder |
| 11 |
from test.testsocket import TestSocket, cleanup_testsockets, UnstableSocket |
| 12 |
from scapy.automaton import ObjectPipe |
| 13 |
|
| 14 |
############ |
| 15 |
############ |
| 16 |
+ Load general modules |
| 17 |
|
| 18 |
= Load contribution layer |
| 19 |
|
| 20 |
|
| 21 |
from scapy.contrib.automotive.uds import * |
| 22 |
from scapy.contrib.automotive.uds_ecu_states import * |
| 23 |
from scapy.contrib.automotive.uds_scan import * |
| 24 |
from scapy.contrib.automotive.ecu import * |
| 25 |
|
| 26 |
load_layer("can") |
| 27 |
|
| 28 |
conf.debug_dissector = False |
| 29 |
|
| 30 |
|
| 31 |
= Define Testfunction |
| 32 |
|
| 33 |
def executeScannerInVirtualEnvironment(supported_responses, enumerators, unstable_socket=True, software_reset=False, **kwargs): |
| 34 |
tester_obj_pipe = ObjectPipe(name="TesterPipe") |
| 35 |
ecu_obj_pipe = ObjectPipe(name="ECUPipe") |
| 36 |
TesterSocket = UnstableSocket if unstable_socket else TestSocket |
| 37 |
tester = TesterSocket(UDS, tester_obj_pipe) |
| 38 |
ecu = TestSocket(UDS, ecu_obj_pipe) |
| 39 |
tester.pair(ecu) |
| 40 |
answering_machine = EcuAnsweringMachine( |
| 41 |
supported_responses=supported_responses, main_socket=ecu, |
| 42 |
basecls=UDS, verbose=False) |
| 43 |
def reset(): |
| 44 |
answering_machine.state.reset() |
| 45 |
answering_machine.state["session"] = 1 |
| 46 |
sniff(timeout=0.001, opened_socket=[ecu, tester]) |
| 47 |
def reconnect(): |
| 48 |
try: |
| 49 |
tester.close() |
| 50 |
except Exception: |
| 51 |
pass |
| 52 |
tester = TesterSocket(UDS, tester_obj_pipe) |
| 53 |
ecu.pair(tester) |
| 54 |
return tester |
| 55 |
def answering_machine_thread(): |
| 56 |
answering_machine( |
| 57 |
timeout=120, stop_filter=lambda x: bytes(x) == b"\xff\xff\xff") |
| 58 |
sim = threading.Thread(target=answering_machine_thread) |
| 59 |
try: |
| 60 |
sim.start() |
| 61 |
if software_reset: |
| 62 |
scanner = UDS_Scanner( |
| 63 |
tester, |
| 64 |
software_reset_handler=uds_software_reset, |
| 65 |
reconnect_handler=reconnect, |
| 66 |
test_cases=enumerators, |
| 67 |
timeout=0.1, |
| 68 |
retry_if_none_received=True, |
| 69 |
unittest=True, |
| 70 |
**kwargs) |
| 71 |
else: |
| 72 |
scanner = UDS_Scanner( |
| 73 |
tester, |
| 74 |
reset_handler=reset, |
| 75 |
reconnect_handler=reconnect, |
| 76 |
test_cases=enumerators, |
| 77 |
timeout=0.1, |
| 78 |
retry_if_none_received=True, |
| 79 |
unittest=True, |
| 80 |
**kwargs) |
| 81 |
for i in range(12): |
| 82 |
print("Starting scan") |
| 83 |
scanner.scan(timeout=10) |
| 84 |
if scanner.scan_completed: |
| 85 |
print("Scan completed after %d iterations" % i) |
| 86 |
break |
| 87 |
finally: |
| 88 |
ecu.ins.send(Raw(b"\xff\xff\xff")) |
| 89 |
sim.join(timeout=2) |
| 90 |
assert not sim.is_alive() |
| 91 |
cleanup_testsockets() |
| 92 |
tester_obj_pipe.close() |
| 93 |
ecu_obj_pipe.close() |
| 94 |
if LINUX: |
| 95 |
pickle_test(scanner) |
| 96 |
return scanner |
| 97 |
|
| 98 |
def pickle_test(scanner): |
| 99 |
f = io.BytesIO() |
| 100 |
pickle.dump(scanner, f) |
| 101 |
unp = pickle.loads(f.getvalue()) |
| 102 |
assert scanner.scan_completed == unp.scan_completed |
| 103 |
assert scanner.state_paths == unp.state_paths |
| 104 |
|
| 105 |
= Load packets from pcap |
| 106 |
|
| 107 |
conf.contribs['CAN']['swap-bytes'] = True |
| 108 |
pkts = rdpcap(scapy_path("test/pcaps/candump_uds_scanner.pcap.gz")) |
| 109 |
assert len(pkts) |
| 110 |
|
| 111 |
= Create UDS messages from packets |
| 112 |
|
| 113 |
builder = ISOTPMessageBuilder(basecls=UDS, use_ext_address=False, rx_id=[0x641, 0x651]) |
| 114 |
msgs = list() |
| 115 |
|
| 116 |
for p in pkts: |
| 117 |
if p.data == b"ECURESET": |
| 118 |
msgs.append(p) |
| 119 |
else: |
| 120 |
builder.feed(p) |
| 121 |
if len(builder): |
| 122 |
msgs.append(builder.pop()) |
| 123 |
|
| 124 |
assert len(msgs) |
| 125 |
|
| 126 |
= Create ECU-Clone from packets |
| 127 |
|
| 128 |
mEcu = Ecu(logging=False, verbose=False, store_supported_responses=True, lookahead=3) |
| 129 |
|
| 130 |
for p in msgs: |
| 131 |
if isinstance(p, CAN) and p.data == b"ECURESET": |
| 132 |
mEcu.reset() |
| 133 |
else: |
| 134 |
mEcu.update(p) |
| 135 |
|
| 136 |
assert len(mEcu.supported_responses) |
| 137 |
|
| 138 |
= Test UDS_SAEnumerator evaluate_response |
| 139 |
|
| 140 |
e = UDS_SAEnumerator() |
| 141 |
|
| 142 |
config = {} |
| 143 |
|
| 144 |
s = EcuState(session=1) |
| 145 |
|
| 146 |
assert False == e._evaluate_response(s, UDS(b"\x27\x01"), None, **config) |
| 147 |
config = {"exit_if_service_not_supported": True} |
| 148 |
assert not e._retry_pkt[s] |
| 149 |
assert True == e._evaluate_response(s, UDS(b"\x27\x01"), UDS(b"\x7f\x27\x11"), **config) |
| 150 |
assert not e._retry_pkt[s] |
| 151 |
assert True == e._evaluate_response(s, UDS(b"\x27\x01"), UDS(b"\x7f\x27\x24"), **config) |
| 152 |
assert e._retry_pkt[s] == UDS(b"\x27\x01") |
| 153 |
assert False == e._evaluate_response(s, UDS(b"\x27\x02"), UDS(b"\x7f\x27\x24"), **config) |
| 154 |
assert not e._retry_pkt[s] |
| 155 |
assert True == e._evaluate_response(s, UDS(b"\x27\x01"), UDS(b"\x7f\x27\x37"), **config) |
| 156 |
assert e._retry_pkt[s] == UDS(b"\x27\x01") |
| 157 |
assert False == e._evaluate_response(s, UDS(b"\x27\x01"), UDS(b"\x7f\x27\x37"), **config) |
| 158 |
assert not e._retry_pkt[s] |
| 159 |
assert True == e._evaluate_response(s, UDS(b"\x27\x01"), UDS(b"\x67\x01ab"), **config) |
| 160 |
assert not e._retry_pkt[s] |
| 161 |
assert False == e._evaluate_response(s, UDS(b"\x27\x01"), UDS(b"\x67\x02ab"), **config) |
| 162 |
assert not e._retry_pkt[s] |
| 163 |
|
| 164 |
|
| 165 |
= Test UDS_SA_XOR_Enumerator stand alone mode |
| 166 |
|
| 167 |
TesterSocket = TestSocket |
| 168 |
ecu_sock = TestSocket(UDS) |
| 169 |
mTester = TesterSocket(UDS) |
| 170 |
ecu_sock.pair(mTester) |
| 171 |
answering_machine = EcuAnsweringMachine(supported_responses=mEcu.supported_responses, main_socket=ecu_sock, basecls=UDS, verbose=False) |
| 172 |
sim = threading.Thread(target=answering_machine, kwargs={'timeout': 1000, "stop_filter": lambda x: bytes(x) == b"\xff\xff\xff"}) |
| 173 |
sim.start() |
| 174 |
try: |
| 175 |
resp = mTester.sr1(UDS()/UDS_TP(b"\x00"), verbose=False, timeout=1) |
| 176 |
print(repr(resp)) |
| 177 |
assert resp and resp.service != 0x7f |
| 178 |
resp = mTester.sr1(UDS()/UDS_DSC(diagnosticSessionType=3), verbose=False, timeout=1) |
| 179 |
print(repr(resp)) |
| 180 |
assert resp and resp.service != 0x7f |
| 181 |
assert UDS_SA_XOR_Enumerator().get_security_access(mTester, 1) |
| 182 |
finally: |
| 183 |
mTester.send(Raw(b"\xff\xff\xff")) |
| 184 |
sim.join(timeout=2) |
| 185 |
cleanup_testsockets() |
| 186 |
|
| 187 |
|
| 188 |
= Test configuration validation |
| 189 |
|
| 190 |
try: |
| 191 |
scanner = UDS_Scanner(TestSocket(UDS), |
| 192 |
test_cases=[UDS_SA_XOR_Enumerator, UDS_DSCEnumerator, UDS_ServiceEnumerator], |
| 193 |
UDS_DSCEnumerator_kwargs={"scan_range": range(0x1000), "delay_state_change": 0, |
| 194 |
"overwrite_timeout": False}) |
| 195 |
assert False |
| 196 |
except Scapy_Exception: |
| 197 |
pass |
| 198 |
|
| 199 |
= Simulate ECU and run Scanner |
| 200 |
|
| 201 |
scanner = executeScannerInVirtualEnvironment( |
| 202 |
mEcu.supported_responses, |
| 203 |
[UDS_SA_XOR_Enumerator, UDS_DSCEnumerator, UDS_ServiceEnumerator], |
| 204 |
UDS_DSCEnumerator_kwargs={"scan_range": range(5), "delay_state_change": 0, |
| 205 |
"overwrite_timeout": False}, |
| 206 |
UDS_SA_XOR_Enumerator_kwargs={"scan_range": range(5)}, |
| 207 |
UDS_ServiceEnumerator_kwargs={"scan_range": [0x10, 0x11, 0x14, 0x19, 0x22, |
| 208 |
0x23, 0x24, 0x27, 0x28, 0x29, |
| 209 |
0x2A, 0x2C, 0x2E, 0x2F, 0x31, |
| 210 |
0x34, 0x35, 0x36, 0x37, 0x38, |
| 211 |
0x3D, 0x3E, 0x83, 0x84, 0x85, |
| 212 |
0x87], |
| 213 |
"request_length": 1}) |
| 214 |
|
| 215 |
scanner.show_testcases() |
| 216 |
scanner.show_testcases_status() |
| 217 |
assert len(scanner.state_paths) == 5 |
| 218 |
assert scanner.scan_completed |
| 219 |
assert scanner.progress() > 0.95 |
| 220 |
|
| 221 |
assert EcuState(session=1) in scanner.final_states |
| 222 |
assert EcuState(session=2, tp=1) in scanner.final_states |
| 223 |
assert EcuState(session=3, tp=1) in scanner.final_states |
| 224 |
assert EcuState(session=2, tp=1, security_level=2) in scanner.final_states |
| 225 |
assert EcuState(session=3, tp=1, security_level=2) in scanner.final_states |
| 226 |
|
| 227 |
#################### UDS_SA_XOR_Enumerator ################ |
| 228 |
tc = scanner.configuration.test_cases[0] |
| 229 |
|
| 230 |
assert len(tc.results_without_response) < 10 |
| 231 |
if tc.results_without_response: |
| 232 |
tc.show() |
| 233 |
|
| 234 |
assert len(tc.results_with_negative_response) == 19 |
| 235 |
assert len(tc.results_with_positive_response) >= 6 |
| 236 |
assert len(tc.scanned_states) == 5 |
| 237 |
|
| 238 |
result = tc.show(dump=True) |
| 239 |
|
| 240 |
assert "serviceNotSupportedInActiveSession received 5 times" in result |
| 241 |
assert "incorrectMessageLengthOrInvalidFormat received 14 times" in result |
| 242 |
|
| 243 |
################# UDS_DSCEnumerator ##################### |
| 244 |
tc = scanner.configuration.test_cases[1] |
| 245 |
|
| 246 |
assert len(tc.results_without_response) < 10 |
| 247 |
if tc.results_without_response: |
| 248 |
tc.show() |
| 249 |
|
| 250 |
assert len(tc.results_with_negative_response) == 20 |
| 251 |
assert len(tc.results_with_positive_response) == 5 |
| 252 |
assert len(tc.scanned_states) == 5 |
| 253 |
|
| 254 |
result = tc.show(dump=True) |
| 255 |
|
| 256 |
assert "incorrectMessageLengthOrInvalidFormat received 20 times" in result |
| 257 |
|
| 258 |
###################### UDS_ServiceEnumerator ################### |
| 259 |
tc = scanner.configuration.test_cases[2] |
| 260 |
|
| 261 |
assert len(tc.results_without_response) < 10 |
| 262 |
if tc.results_without_response: |
| 263 |
tc.show() |
| 264 |
|
| 265 |
assert len(tc.results_with_negative_response) == 130 |
| 266 |
assert len(tc.results_with_positive_response) == 0 |
| 267 |
assert len(tc.scanned_states) == 5 |
| 268 |
|
| 269 |
result = tc.show(dump=True) |
| 270 |
|
| 271 |
assert "incorrectMessageLengthOrInvalidFormat received 34 times" in result |
| 272 |
assert "serviceNotSupported received 75 times" in result |
| 273 |
assert "serviceNotSupportedInActiveSession received 19 times" in result |
| 274 |
assert "securityAccessDenied received 2 times" in result |
| 275 |
|
| 276 |
= Simulate ECU and run Scanner with software resert |
| 277 |
|
| 278 |
responses = ([EcuResponse(None, [UDS()/UDS_DSCPR(b"\x01")])] |
| 279 |
+ mEcu.supported_responses) |
| 280 |
|
| 281 |
scanner = executeScannerInVirtualEnvironment( |
| 282 |
responses, |
| 283 |
[UDS_SA_XOR_Enumerator, UDS_DSCEnumerator, UDS_ServiceEnumerator], |
| 284 |
software_reset=True, |
| 285 |
UDS_DSCEnumerator_kwargs={"scan_range": range(5), "delay_state_change": 0, |
| 286 |
"overwrite_timeout": False}, |
| 287 |
UDS_SA_XOR_Enumerator_kwargs={"scan_range": range(5)}, |
| 288 |
UDS_ServiceEnumerator_kwargs={"scan_range": [0x10, 0x11, 0x14, 0x19, 0x22, |
| 289 |
0x23, 0x24, 0x27, 0x28, 0x29, |
| 290 |
0x2A, 0x2C, 0x2E, 0x2F, 0x31, |
| 291 |
0x34, 0x35, 0x36, 0x37, 0x38, |
| 292 |
0x3D, 0x3E, 0x83, 0x84, 0x85, |
| 293 |
0x87], |
| 294 |
"request_length": 1}) |
| 295 |
|
| 296 |
scanner.show_testcases() |
| 297 |
scanner.show_testcases_status() |
| 298 |
assert len(scanner.state_paths) == 6 |
| 299 |
assert scanner.scan_completed |
| 300 |
assert scanner.progress() > 0.95 |
| 301 |
|
| 302 |
assert EcuState(session=1) in scanner.final_states |
| 303 |
assert EcuState(session=2, tp=1) in scanner.final_states |
| 304 |
assert EcuState(session=1, tp=1) in scanner.final_states |
| 305 |
assert EcuState(session=3, tp=1) in scanner.final_states |
| 306 |
assert EcuState(session=2, tp=1, security_level=2) in scanner.final_states |
| 307 |
assert EcuState(session=3, tp=1, security_level=2) in scanner.final_states |
| 308 |
|
| 309 |
#################### UDS_SA_XOR_Enumerator ################ |
| 310 |
tc = scanner.configuration.test_cases[0] |
| 311 |
|
| 312 |
assert len(tc.results_without_response) < 10 |
| 313 |
if tc.results_without_response: |
| 314 |
tc.show() |
| 315 |
|
| 316 |
assert len(tc.results_with_negative_response) == 24 |
| 317 |
assert len(tc.results_with_positive_response) >= 6 |
| 318 |
assert len(tc.scanned_states) == 6 |
| 319 |
|
| 320 |
result = tc.show(dump=True) |
| 321 |
|
| 322 |
assert "serviceNotSupportedInActiveSession received 5 times" in result |
| 323 |
assert "incorrectMessageLengthOrInvalidFormat received 14 times" in result |
| 324 |
|
| 325 |
################# UDS_DSCEnumerator ##################### |
| 326 |
tc = scanner.configuration.test_cases[1] |
| 327 |
|
| 328 |
assert len(tc.results_without_response) < 10 |
| 329 |
if tc.results_without_response: |
| 330 |
tc.show() |
| 331 |
|
| 332 |
assert len(tc.results_with_negative_response) == 17 |
| 333 |
assert len(tc.results_with_positive_response) == 13 |
| 334 |
assert len(tc.scanned_states) == 6 |
| 335 |
|
| 336 |
result = tc.show(dump=True) |
| 337 |
|
| 338 |
assert "incorrectMessageLengthOrInvalidFormat received 14 times" in result |
| 339 |
|
| 340 |
###################### UDS_ServiceEnumerator ################### |
| 341 |
tc = scanner.configuration.test_cases[2] |
| 342 |
|
| 343 |
assert len(tc.results_without_response) < 10 |
| 344 |
if tc.results_without_response: |
| 345 |
tc.show() |
| 346 |
|
| 347 |
assert len(tc.results_with_negative_response) == 156 |
| 348 |
assert len(tc.results_with_positive_response) == 0 |
| 349 |
assert len(tc.scanned_states) == 6 |
| 350 |
|
| 351 |
result = tc.show(dump=True) |
| 352 |
|
| 353 |
assert "incorrectMessageLengthOrInvalidFormat received 34 times" in result |
| 354 |
assert "serviceNotSupported received 75 times" in result |
| 355 |
assert "serviceNotSupportedInActiveSession received 19 times" in result |
| 356 |
assert "securityAccessDenied received 2 times" in result |
| 357 |
|
| 358 |
= Simulate ECU and run Scanner with software resert 2 |
| 359 |
|
| 360 |
responses = ([EcuResponse(None, [UDS()/UDS_ERPR(b"\x01")])] |
| 361 |
+ mEcu.supported_responses) |
| 362 |
|
| 363 |
scanner = executeScannerInVirtualEnvironment( |
| 364 |
responses, |
| 365 |
[UDS_SA_XOR_Enumerator, UDS_DSCEnumerator, UDS_ServiceEnumerator], |
| 366 |
software_reset=True, |
| 367 |
UDS_DSCEnumerator_kwargs={"scan_range": range(5), "delay_state_change": 0, |
| 368 |
"overwrite_timeout": False}, |
| 369 |
UDS_SA_XOR_Enumerator_kwargs={"scan_range": range(5)}, |
| 370 |
UDS_ServiceEnumerator_kwargs={"scan_range": [0x10, 0x11, 0x14, 0x19, 0x22, |
| 371 |
0x23, 0x24, 0x27, 0x28, 0x29, |
| 372 |
0x2A, 0x2C, 0x2E, 0x2F, 0x31, |
| 373 |
0x34, 0x35, 0x36, 0x37, 0x38, |
| 374 |
0x3D, 0x3E, 0x83, 0x84, 0x85, |
| 375 |
0x87], |
| 376 |
"request_length": 1}) |
| 377 |
|
| 378 |
scanner.show_testcases() |
| 379 |
scanner.show_testcases_status() |
| 380 |
assert len(scanner.state_paths) == 5 |
| 381 |
assert scanner.scan_completed |
| 382 |
assert scanner.progress() > 0.95 |
| 383 |
|
| 384 |
assert EcuState(session=1) in scanner.final_states |
| 385 |
assert EcuState(session=2, tp=1) in scanner.final_states |
| 386 |
assert EcuState(session=3, tp=1) in scanner.final_states |
| 387 |
assert EcuState(session=2, tp=1, security_level=2) in scanner.final_states |
| 388 |
assert EcuState(session=3, tp=1, security_level=2) in scanner.final_states |
| 389 |
|
| 390 |
#################### UDS_SA_XOR_Enumerator ################ |
| 391 |
tc = scanner.configuration.test_cases[0] |
| 392 |
|
| 393 |
assert len(tc.results_without_response) < 10 |
| 394 |
if tc.results_without_response: |
| 395 |
tc.show() |
| 396 |
|
| 397 |
assert len(tc.results_with_negative_response) == 19 |
| 398 |
assert len(tc.results_with_positive_response) >= 6 |
| 399 |
assert len(tc.scanned_states) == 5 |
| 400 |
|
| 401 |
result = tc.show(dump=True) |
| 402 |
|
| 403 |
assert "serviceNotSupportedInActiveSession received 5 times" in result |
| 404 |
assert "incorrectMessageLengthOrInvalidFormat received 14 times" in result |
| 405 |
|
| 406 |
################# UDS_DSCEnumerator ##################### |
| 407 |
tc = scanner.configuration.test_cases[1] |
| 408 |
|
| 409 |
assert len(tc.results_without_response) < 10 |
| 410 |
if tc.results_without_response: |
| 411 |
tc.show() |
| 412 |
|
| 413 |
assert len(tc.results_with_negative_response) == 20 |
| 414 |
assert len(tc.results_with_positive_response) == 5 |
| 415 |
assert len(tc.scanned_states) == 5 |
| 416 |
|
| 417 |
result = tc.show(dump=True) |
| 418 |
|
| 419 |
assert "incorrectMessageLengthOrInvalidFormat received 20 times" in result |
| 420 |
|
| 421 |
###################### UDS_ServiceEnumerator ################### |
| 422 |
tc = scanner.configuration.test_cases[2] |
| 423 |
|
| 424 |
assert len(tc.results_without_response) < 10 |
| 425 |
if tc.results_without_response: |
| 426 |
tc.show() |
| 427 |
|
| 428 |
assert len(tc.results_with_negative_response) == 130 |
| 429 |
assert len(tc.results_with_positive_response) == 0 |
| 430 |
assert len(tc.scanned_states) == 5 |
| 431 |
|
| 432 |
result = tc.show(dump=True) |
| 433 |
|
| 434 |
assert "incorrectMessageLengthOrInvalidFormat received 34 times" in result |
| 435 |
assert "serviceNotSupported received 75 times" in result |
| 436 |
assert "serviceNotSupportedInActiveSession received 19 times" in result |
| 437 |
assert "securityAccessDenied received 2 times" in result |
| 438 |
|
| 439 |
|
| 440 |
= UDS_ServiceEnumerator |
| 441 |
|
| 442 |
def req_handler(resp, req): |
| 443 |
if req.service != 0x22: |
| 444 |
return False |
| 445 |
if len(req) == 1: |
| 446 |
resp.negativeResponseCode="generalReject" |
| 447 |
return True |
| 448 |
if len(req) == 2: |
| 449 |
resp.negativeResponseCode="incorrectMessageLengthOrInvalidFormat" |
| 450 |
return True |
| 451 |
if len(req) == 3: |
| 452 |
resp.negativeResponseCode="requestOutOfRange" |
| 453 |
return True |
| 454 |
return False |
| 455 |
|
| 456 |
resps = [EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId="ReadDataByIdentifier")], req_handler)] |
| 457 |
|
| 458 |
es = [UDS_ServiceEnumerator] |
| 459 |
|
| 460 |
debug_dissector_backup = conf.debug_dissector |
| 461 |
|
| 462 |
# This Enumerator is sending corrupted Packets, therefore we need to disable the debug_dissector |
| 463 |
conf.debug_dissector = False |
| 464 |
scanner = executeScannerInVirtualEnvironment( |
| 465 |
resps, es, UDS_ServiceEnumerator_kwargs={"request_length": 3}, unstable_socket=False) |
| 466 |
conf.debug_dissector = debug_dissector_backup |
| 467 |
|
| 468 |
assert scanner.scan_completed |
| 469 |
assert scanner.progress() > 0.95 |
| 470 |
tc = scanner.configuration.test_cases[0] |
| 471 |
|
| 472 |
assert len(tc.results_without_response) < 10 |
| 473 |
if tc.results_without_response: |
| 474 |
tc.show() |
| 475 |
|
| 476 |
tc.show() |
| 477 |
|
| 478 |
assert len(tc.results_with_negative_response) == 128 * 3 |
| 479 |
assert len(tc.results_with_positive_response) == 0 |
| 480 |
assert len(tc.scanned_states) == 1 |
| 481 |
|
| 482 |
result = tc.show(dump=True) |
| 483 |
|
| 484 |
assert "incorrectMessageLengthOrInvalidFormat" in result |
| 485 |
assert "requestOutOfRange" in result |
| 486 |
|
| 487 |
= UDS_RDBIEnumerator |
| 488 |
|
| 489 |
resps = [EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=1)/Raw(b"asdfbeef1")]), |
| 490 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=2)/Raw(b"beef2")]), |
| 491 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=3)/Raw(b"beef3")]), |
| 492 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0xff)/Raw(b"beefff")]), |
| 493 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId="ReadDataByIdentifier")])] |
| 494 |
|
| 495 |
es = [UDS_RDBIEnumerator] |
| 496 |
|
| 497 |
scanner = executeScannerInVirtualEnvironment( |
| 498 |
resps, es, UDS_RDBIEnumerator_kwargs={"scan_range": range(0x100)}) |
| 499 |
|
| 500 |
assert scanner.scan_completed |
| 501 |
assert scanner.progress() > 0.95 |
| 502 |
tc = scanner.configuration.test_cases[0] |
| 503 |
|
| 504 |
assert len(tc.results_without_response) < 10 |
| 505 |
if tc.results_without_response: |
| 506 |
tc.show() |
| 507 |
|
| 508 |
assert len(tc.results_with_negative_response) == 256 - 4 |
| 509 |
assert len(tc.results_with_positive_response) == 4 |
| 510 |
assert len(tc.scanned_states) == 1 |
| 511 |
|
| 512 |
result = tc.show(dump=True) |
| 513 |
|
| 514 |
assert "asdfbeef1" in result |
| 515 |
assert "beef2" in result |
| 516 |
assert "beef3" in result |
| 517 |
assert "beefff" in result |
| 518 |
assert "subFunctionNotSupported received" in result |
| 519 |
|
| 520 |
ids = [t.req.identifiers[0] for t in tc.results_with_positive_response] |
| 521 |
|
| 522 |
assert 1 in ids |
| 523 |
assert 2 in ids |
| 524 |
assert 3 in ids |
| 525 |
assert 0xff in ids |
| 526 |
|
| 527 |
= UDS_RDBISelectiveEnumerator |
| 528 |
~ not_pypy |
| 529 |
|
| 530 |
resps = [EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x101)/Raw(b"asdfbeef1")]), |
| 531 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x102)/Raw(b"beef2")]), |
| 532 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x103)/Raw(b"beef3")]), |
| 533 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x104)/Raw(b"beef3")]), |
| 534 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x105)/Raw(b"beef3")]), |
| 535 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x106)/Raw(b"beef3")]), |
| 536 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x107)/Raw(b"beef3")]), |
| 537 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x108)/Raw(b"beef3")]), |
| 538 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x109)/Raw(b"beef3")]), |
| 539 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x110)/Raw(b"beef3")]), |
| 540 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x111)/Raw(b"beef3")]), |
| 541 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x112)/Raw(b"beef3")]), |
| 542 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x113)/Raw(b"beef3")]), |
| 543 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x114)/Raw(b"beef3")]), |
| 544 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x115)/Raw(b"beef3")]), |
| 545 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x116)/Raw(b"beef3")]), |
| 546 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x117)/Raw(b"beef3")]), |
| 547 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x118)/Raw(b"beef3")]), |
| 548 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x119)/Raw(b"beef3")]), |
| 549 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x120)/Raw(b"beef3")]), |
| 550 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x121)/Raw(b"beef3")]), |
| 551 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x122)/Raw(b"beef3")]), |
| 552 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x123)/Raw(b"beef3")]), |
| 553 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x124)/Raw(b"beef3")]), |
| 554 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x125)/Raw(b"beef3")]), |
| 555 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x126)/Raw(b"beef3")]), |
| 556 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x127)/Raw(b"beef3")]), |
| 557 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x128)/Raw(b"beef3")]), |
| 558 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x129)/Raw(b"beef3")]), |
| 559 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x130)/Raw(b"beef3")]), |
| 560 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x131)/Raw(b"beef3")]), |
| 561 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x132)/Raw(b"beef3")]), |
| 562 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x133)/Raw(b"beef3")]), |
| 563 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x134)/Raw(b"beef3")]), |
| 564 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0x135)/Raw(b"beef35")]), |
| 565 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId="ReadDataByIdentifier")])] |
| 566 |
|
| 567 |
es = [UDS_RDBISelectiveEnumerator] |
| 568 |
|
| 569 |
scanner = executeScannerInVirtualEnvironment(resps, es, UDS_RDBIRandomEnumerator_kwargs={"probe_start": 0, "probe_end": 0x500}) |
| 570 |
|
| 571 |
assert scanner.scan_completed |
| 572 |
assert scanner.progress() > 0.95 |
| 573 |
|
| 574 |
tc = scanner.configuration.stages[0][0] |
| 575 |
|
| 576 |
tc.show() |
| 577 |
|
| 578 |
assert len(tc.results_without_response) < 10 |
| 579 |
if tc.results_without_response: |
| 580 |
tc.show() |
| 581 |
|
| 582 |
assert len(tc.results_with_negative_response) > 100 |
| 583 |
assert len(tc.results_with_positive_response) >= 1 |
| 584 |
assert len(tc.scanned_states) == 1 |
| 585 |
|
| 586 |
assert scanner.scan_completed |
| 587 |
assert scanner.progress() > 0.95 |
| 588 |
|
| 589 |
tc = scanner.configuration.stages[0][1] |
| 590 |
|
| 591 |
tc.show() |
| 592 |
|
| 593 |
assert len(tc.results_without_response) < 10 |
| 594 |
if tc.results_without_response: |
| 595 |
tc.show() |
| 596 |
|
| 597 |
assert len(tc.results_with_negative_response) == 29 |
| 598 |
assert len(tc.results_with_positive_response) == 35 |
| 599 |
assert len(tc.scanned_states) == 1 |
| 600 |
|
| 601 |
result = tc.show(dump=True) |
| 602 |
|
| 603 |
assert "asdfbeef1" in result |
| 604 |
assert "beef2" in result |
| 605 |
assert "beef3" in result |
| 606 |
assert "beef35" in result |
| 607 |
assert "subFunctionNotSupported received" in result |
| 608 |
|
| 609 |
ids = [t.req.identifiers[0] for t in tc.results_with_positive_response] |
| 610 |
|
| 611 |
assert 0x101 in ids |
| 612 |
assert 0x102 in ids |
| 613 |
assert 0x103 in ids |
| 614 |
assert 0x135 in ids |
| 615 |
|
| 616 |
= UDS_WDBIEnumerator |
| 617 |
|
| 618 |
def wdbi_handler(resp, req): |
| 619 |
if req.service != 0x2E: |
| 620 |
return False |
| 621 |
assert req.dataIdentifier in [1, 2, 3, 0xff] |
| 622 |
resp.dataIdentifier = req.dataIdentifier |
| 623 |
if req.dataIdentifier == 1: |
| 624 |
assert req.load == b'asdfbeef1' |
| 625 |
return True |
| 626 |
if req.dataIdentifier == 2: |
| 627 |
assert req.load == b'beef2' |
| 628 |
return True |
| 629 |
if req.dataIdentifier == 3: |
| 630 |
assert req.load == b"beef3" |
| 631 |
return True |
| 632 |
if req.dataIdentifier == 0xff: |
| 633 |
assert req.load == b"beefff" |
| 634 |
return True |
| 635 |
return False |
| 636 |
|
| 637 |
resps = [EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=1)/Raw(b"asdfbeef1")]), |
| 638 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=2)/Raw(b"beef2")]), |
| 639 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=3)/Raw(b"beef3")]), |
| 640 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0xff)/Raw(b"beefff")]), |
| 641 |
EcuResponse(None, [UDS()/UDS_WDBIPR()], answers=wdbi_handler), |
| 642 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId="ReadDataByIdentifier")])] |
| 643 |
|
| 644 |
es = [UDS_WDBISelectiveEnumerator()] |
| 645 |
|
| 646 |
scanner = executeScannerInVirtualEnvironment( |
| 647 |
resps, es, UDS_RDBIEnumerator_kwargs={"scan_range": range(0x100)}) |
| 648 |
|
| 649 |
assert scanner.scan_completed |
| 650 |
assert scanner.progress() > 0.95 |
| 651 |
|
| 652 |
tc = scanner.configuration.stages[0][0] |
| 653 |
|
| 654 |
assert len(tc.results_without_response) < 10 |
| 655 |
if tc.results_without_response: |
| 656 |
tc.show() |
| 657 |
|
| 658 |
assert len(tc.results_with_negative_response) == 256 - 4 |
| 659 |
assert len(tc.results_with_positive_response) == 4 |
| 660 |
assert len(tc.scanned_states) == 1 |
| 661 |
|
| 662 |
result = tc.show(dump=True) |
| 663 |
|
| 664 |
assert "asdfbeef1" in result |
| 665 |
assert "beef2" in result |
| 666 |
assert "beef3" in result |
| 667 |
assert "beefff" in result |
| 668 |
assert "subFunctionNotSupported received" in result |
| 669 |
|
| 670 |
ids = [t.req.identifiers[0] for t in tc.results_with_positive_response] |
| 671 |
|
| 672 |
assert 1 in ids |
| 673 |
assert 2 in ids |
| 674 |
assert 3 in ids |
| 675 |
assert 0xff in ids |
| 676 |
|
| 677 |
######################### WDBI ############################# |
| 678 |
tc = scanner.configuration.stages[0][1] |
| 679 |
|
| 680 |
assert len(tc.results_without_response) < 10 |
| 681 |
if tc.results_without_response: |
| 682 |
tc.show() |
| 683 |
|
| 684 |
assert len(tc.results_with_negative_response) == 0 |
| 685 |
assert len(tc.results_with_positive_response) == 4 |
| 686 |
assert len(tc.scanned_states) == 1 |
| 687 |
|
| 688 |
result = tc.show(dump=True) |
| 689 |
|
| 690 |
ids = [t.req.dataIdentifier for t in tc.results_with_positive_response] |
| 691 |
|
| 692 |
assert 1 in ids |
| 693 |
assert 2 in ids |
| 694 |
assert 3 in ids |
| 695 |
assert 0xff in ids |
| 696 |
|
| 697 |
= UDS_WDBIEnumerator 2 |
| 698 |
|
| 699 |
def wdbi_handler(resp, req): |
| 700 |
if req.service != 0x2E: |
| 701 |
return False |
| 702 |
assert req.dataIdentifier in [1, 2, 3, 0xff] |
| 703 |
resp.dataIdentifier = req.dataIdentifier |
| 704 |
if req.dataIdentifier == 1: |
| 705 |
assert req.load == b'asdfbeef1' |
| 706 |
return True |
| 707 |
if req.dataIdentifier == 2: |
| 708 |
assert req.load == b'beef2' |
| 709 |
return True |
| 710 |
if req.dataIdentifier == 3: |
| 711 |
assert req.load == b"beef3" |
| 712 |
return True |
| 713 |
if req.dataIdentifier == 0xff: |
| 714 |
assert req.load == b"beefff" |
| 715 |
return True |
| 716 |
return False |
| 717 |
|
| 718 |
resps = [EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=1)/Raw(b"asdfbeef1")]), |
| 719 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=2)/Raw(b"beef2")]), |
| 720 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=3)/Raw(b"beef3")]), |
| 721 |
EcuResponse(None, [UDS()/UDS_RDBIPR(dataIdentifier=0xff)/Raw(b"beefff")]), |
| 722 |
EcuResponse(None, [UDS()/UDS_WDBIPR()], answers=wdbi_handler), |
| 723 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId="ReadDataByIdentifier")])] |
| 724 |
|
| 725 |
es = [UDS_WDBISelectiveEnumerator] |
| 726 |
|
| 727 |
scanner = executeScannerInVirtualEnvironment( |
| 728 |
resps, es, UDS_RDBIEnumerator_kwargs={"scan_range": range(0x100)}) |
| 729 |
|
| 730 |
assert scanner.scan_completed |
| 731 |
assert scanner.progress() > 0.95 |
| 732 |
|
| 733 |
tc = scanner.configuration.test_cases[0][0] |
| 734 |
|
| 735 |
assert len(tc.results_without_response) < 10 |
| 736 |
if tc.results_without_response: |
| 737 |
tc.show() |
| 738 |
|
| 739 |
assert len(tc.results_with_negative_response) == 256 - 4 |
| 740 |
assert len(tc.results_with_positive_response) == 4 |
| 741 |
assert len(tc.scanned_states) == 1 |
| 742 |
|
| 743 |
result = tc.show(dump=True) |
| 744 |
|
| 745 |
assert "asdfbeef1" in result |
| 746 |
assert "beef2" in result |
| 747 |
assert "beef3" in result |
| 748 |
assert "beefff" in result |
| 749 |
assert "subFunctionNotSupported received" in result |
| 750 |
|
| 751 |
ids = [t.req.identifiers[0] for t in tc.results_with_positive_response] |
| 752 |
|
| 753 |
assert 1 in ids |
| 754 |
assert 2 in ids |
| 755 |
assert 3 in ids |
| 756 |
assert 0xff in ids |
| 757 |
|
| 758 |
######################### WDBI ############################# |
| 759 |
tc = scanner.configuration.test_cases[0][1] |
| 760 |
|
| 761 |
assert len(tc.results_without_response) < 10 |
| 762 |
if tc.results_without_response: |
| 763 |
tc.show() |
| 764 |
|
| 765 |
assert len(tc.results_with_negative_response) == 0 |
| 766 |
assert len(tc.results_with_positive_response) == 4 |
| 767 |
assert len(tc.scanned_states) == 1 |
| 768 |
|
| 769 |
result = tc.show(dump=True) |
| 770 |
|
| 771 |
ids = [t.req.dataIdentifier for t in tc.results_with_positive_response] |
| 772 |
|
| 773 |
assert 1 in ids |
| 774 |
assert 2 in ids |
| 775 |
assert 3 in ids |
| 776 |
assert 0xff in ids |
| 777 |
|
| 778 |
|
| 779 |
= UDS_TPEnumerator |
| 780 |
|
| 781 |
resps = [EcuResponse(None, [UDS()/UDS_TPPR()]), |
| 782 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="serviceNotSupported", requestServiceId="TesterPresent")])] |
| 783 |
|
| 784 |
es = [UDS_TPEnumerator] |
| 785 |
|
| 786 |
scanner = executeScannerInVirtualEnvironment(resps, es) |
| 787 |
|
| 788 |
assert scanner.scan_completed |
| 789 |
assert scanner.progress() > 0.95 |
| 790 |
|
| 791 |
tc = scanner.configuration.test_cases[0] |
| 792 |
|
| 793 |
assert len(tc.results_without_response) < 10 |
| 794 |
if tc.results_without_response: |
| 795 |
tc.show() |
| 796 |
|
| 797 |
assert len(tc.results_with_negative_response) == 0 |
| 798 |
assert len(tc.results_with_positive_response) == 2 |
| 799 |
assert len(tc.scanned_states) == 2 |
| 800 |
|
| 801 |
assert tc.show(dump=True) |
| 802 |
|
| 803 |
= UDS_EREnumerator |
| 804 |
|
| 805 |
resps = [EcuResponse(None, [UDS()/UDS_ERPR(resetType=1)]), |
| 806 |
EcuResponse(None, [UDS()/UDS_ERPR(resetType=3)]), |
| 807 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId="ECUReset")])] |
| 808 |
|
| 809 |
es = [UDS_EREnumerator] |
| 810 |
|
| 811 |
scanner = executeScannerInVirtualEnvironment(resps, es) |
| 812 |
|
| 813 |
assert scanner.scan_completed |
| 814 |
assert scanner.progress() > 0.95 |
| 815 |
|
| 816 |
tc = scanner.configuration.test_cases[0] |
| 817 |
|
| 818 |
assert len(tc.results_without_response) < 10 |
| 819 |
if tc.results_without_response: |
| 820 |
tc.show() |
| 821 |
|
| 822 |
assert len(tc.results_with_negative_response) == 256 - 2 |
| 823 |
assert len(tc.results_with_positive_response) == 2 |
| 824 |
assert len(tc.scanned_states) == 1 |
| 825 |
|
| 826 |
result = tc.show(dump=True) |
| 827 |
|
| 828 |
assert "hardReset" in result |
| 829 |
assert "softReset" in result |
| 830 |
assert "subFunctionNotSupported received" in result |
| 831 |
|
| 832 |
ids = [t.req.resetType for t in tc.results_with_positive_response] |
| 833 |
|
| 834 |
assert 1 in ids |
| 835 |
assert 3 in ids |
| 836 |
|
| 837 |
|
| 838 |
= UDS_CCEnumerator |
| 839 |
|
| 840 |
resps = [EcuResponse(None, [UDS()/UDS_CCPR(controlType=1)]), |
| 841 |
EcuResponse(None, [UDS()/UDS_CCPR(controlType=3)]), |
| 842 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId="CommunicationControl")])] |
| 843 |
|
| 844 |
es = [UDS_CCEnumerator] |
| 845 |
|
| 846 |
scanner = executeScannerInVirtualEnvironment(resps, es, inter=0.001) |
| 847 |
|
| 848 |
assert scanner.scan_completed |
| 849 |
assert scanner.progress() > 0.95 |
| 850 |
|
| 851 |
tc = scanner.configuration.test_cases[0] |
| 852 |
|
| 853 |
assert len(tc.results_without_response) < 10 |
| 854 |
if tc.results_without_response: |
| 855 |
tc.show() |
| 856 |
|
| 857 |
assert len(tc.results_with_negative_response) == 256 - 2 |
| 858 |
assert len(tc.results_with_positive_response) == 2 |
| 859 |
assert len(tc.scanned_states) == 1 |
| 860 |
|
| 861 |
result = tc.show(dump=True) |
| 862 |
|
| 863 |
assert "enableRxAndDisableTx" in result |
| 864 |
assert "disableRxAndTx" in result |
| 865 |
assert "subFunctionNotSupported received" in result |
| 866 |
|
| 867 |
ids = [t.req.controlType for t in tc.results_with_positive_response] |
| 868 |
|
| 869 |
assert 1 in ids |
| 870 |
assert 3 in ids |
| 871 |
|
| 872 |
= UDS_RDBPIEnumerator |
| 873 |
|
| 874 |
UDS_RDBPI.periodicDataIdentifiers[1] = "identifierElectric" |
| 875 |
UDS_RDBPI.periodicDataIdentifiers[3] = "identifierGas" |
| 876 |
|
| 877 |
resps = [EcuResponse(None, [UDS()/UDS_RDBPIPR(periodicDataIdentifier=1, dataRecord=b'electric')]), |
| 878 |
EcuResponse(None, [UDS()/UDS_RDBPIPR(periodicDataIdentifier=3, dataRecord=b'gas')]), |
| 879 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId="ReadDataPeriodicIdentifier")])] |
| 880 |
|
| 881 |
es = [UDS_RDBPIEnumerator] |
| 882 |
|
| 883 |
scanner = executeScannerInVirtualEnvironment(resps, es) |
| 884 |
|
| 885 |
assert scanner.scan_completed |
| 886 |
assert scanner.progress() > 0.95 |
| 887 |
|
| 888 |
tc = scanner.configuration.test_cases[0] |
| 889 |
|
| 890 |
assert len(tc.results_without_response) < 10 |
| 891 |
if tc.results_without_response: |
| 892 |
tc.show() |
| 893 |
|
| 894 |
assert len(tc.results_with_negative_response) == 256 - 2 |
| 895 |
assert len(tc.results_with_positive_response) == 2 |
| 896 |
assert len(tc.scanned_states) == 1 |
| 897 |
|
| 898 |
result = tc.show(dump=True) |
| 899 |
|
| 900 |
assert "electric" in result |
| 901 |
assert "gas" in result |
| 902 |
assert "0x01 identifierElectric" in result |
| 903 |
assert "0x03 identifierGas" in result |
| 904 |
assert "subFunctionNotSupported received" in result |
| 905 |
|
| 906 |
ids = [t.req.periodicDataIdentifier for t in tc.results_with_positive_response] |
| 907 |
|
| 908 |
assert 1 in ids |
| 909 |
assert 3 in ids |
| 910 |
|
| 911 |
|
| 912 |
= UDS_RCEnumerator |
| 913 |
|
| 914 |
resps = [EcuResponse(None, [UDS()/UDS_RCPR(routineControlType=1, routineIdentifier=1)/Raw(b"asdfbeef1")]), |
| 915 |
EcuResponse(None, [UDS()/UDS_RCPR(routineControlType=2, routineIdentifier=2)/Raw(b"beef2")]), |
| 916 |
EcuResponse(None, [UDS()/UDS_RCPR(routineControlType=3, routineIdentifier=3)/Raw(b"beef3")]), |
| 917 |
EcuResponse(None, [UDS()/UDS_RCPR(routineControlType=1, routineIdentifier=0x10)/Raw(b"beefff")]), |
| 918 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId="RoutineControl")])] |
| 919 |
|
| 920 |
es = [UDS_RCEnumerator] |
| 921 |
|
| 922 |
scanner = executeScannerInVirtualEnvironment(resps, es, UDS_RCEnumerator_kwargs={"scan_range": range(0x11)}) |
| 923 |
|
| 924 |
assert scanner.scan_completed |
| 925 |
assert scanner.progress() > 0.95 |
| 926 |
|
| 927 |
tc = scanner.configuration.test_cases[0] |
| 928 |
|
| 929 |
assert len(tc.results_without_response) < 10 |
| 930 |
if tc.results_without_response: |
| 931 |
tc.show() |
| 932 |
|
| 933 |
assert len(tc.results_with_negative_response) == 0x11 * 3 - 4 |
| 934 |
assert len(tc.results_with_positive_response) == 4 |
| 935 |
assert len(tc.scanned_states) == 1 |
| 936 |
|
| 937 |
result = tc.show(dump=True) |
| 938 |
|
| 939 |
assert "subFunctionNotSupported received" in result |
| 940 |
|
| 941 |
ids = [t.req.routineIdentifier for t in tc.results_with_positive_response] |
| 942 |
|
| 943 |
assert 1 in ids |
| 944 |
assert 2 in ids |
| 945 |
assert 3 in ids |
| 946 |
assert 0x10 in ids |
| 947 |
|
| 948 |
|
| 949 |
= UDS_RCSelectiveEnumerator |
| 950 |
|
| 951 |
resps = [EcuResponse(None, [UDS()/UDS_RCPR(routineControlType=1, routineIdentifier=1)/Raw(b"asdfbeef1")]), |
| 952 |
EcuResponse(None, [UDS()/UDS_RCPR(routineControlType=2, routineIdentifier=1)/Raw(b"beef2")]), |
| 953 |
EcuResponse(None, [UDS()/UDS_RCPR(routineControlType=3, routineIdentifier=1)/Raw(b"beef3")]), |
| 954 |
EcuResponse(None, [UDS()/UDS_RCPR(routineControlType=1, routineIdentifier=0x10)/Raw(b"beefff")]), |
| 955 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId="RoutineControl")])] |
| 956 |
|
| 957 |
es = [UDS_RCSelectiveEnumerator] |
| 958 |
|
| 959 |
scanner = executeScannerInVirtualEnvironment(resps, es, UDS_RCStartEnumerator_kwargs={"scan_range": range(0x11)}) |
| 960 |
|
| 961 |
assert scanner.scan_completed |
| 962 |
assert scanner.progress() > 0.95 |
| 963 |
|
| 964 |
tc = scanner.configuration.stages[0][0] |
| 965 |
|
| 966 |
assert len(tc.results_without_response) < 10 |
| 967 |
if tc.results_without_response: |
| 968 |
tc.show() |
| 969 |
|
| 970 |
assert len(tc.results_with_negative_response) == 0x11 - 2 |
| 971 |
assert len(tc.results_with_positive_response) == 2 |
| 972 |
assert len(tc.scanned_states) == 1 |
| 973 |
|
| 974 |
result = tc.show(dump=True) |
| 975 |
|
| 976 |
assert "subFunctionNotSupported received" in result |
| 977 |
|
| 978 |
ids = [t.req.routineIdentifier for t in tc.results_with_positive_response] |
| 979 |
|
| 980 |
assert 1 in ids |
| 981 |
assert 0x10 in ids |
| 982 |
|
| 983 |
tc = scanner.configuration.stages[0][1] |
| 984 |
|
| 985 |
assert len(tc.results_without_response) < 10 |
| 986 |
if tc.results_without_response: |
| 987 |
tc.show() |
| 988 |
|
| 989 |
assert len(tc.results_with_negative_response) == 538 |
| 990 |
assert len(tc.results_with_positive_response) == 2 |
| 991 |
assert len(tc.scanned_states) == 1 |
| 992 |
|
| 993 |
result = tc.show(dump=True) |
| 994 |
|
| 995 |
assert "subFunctionNotSupported received" in result |
| 996 |
|
| 997 |
ids = [t.req.routineIdentifier for t in tc.results_with_positive_response] |
| 998 |
|
| 999 |
assert 1 in ids |
| 1000 |
|
| 1001 |
= UDS_IOCBIEnumerator |
| 1002 |
|
| 1003 |
resps = [EcuResponse(None, [UDS()/UDS_IOCBIPR(dataIdentifier=1)/Raw(b"asdfbeef1")]), |
| 1004 |
EcuResponse(None, [UDS()/UDS_IOCBIPR(dataIdentifier=2)/Raw(b"beef2")]), |
| 1005 |
EcuResponse(None, [UDS()/UDS_IOCBIPR(dataIdentifier=3)/Raw(b"beef3")]), |
| 1006 |
EcuResponse(None, [UDS()/UDS_IOCBIPR(dataIdentifier=0xff)/Raw(b"beefff")]), |
| 1007 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId="InputOutputControlByIdentifier")])] |
| 1008 |
|
| 1009 |
es = [UDS_IOCBIEnumerator] |
| 1010 |
|
| 1011 |
scanner = executeScannerInVirtualEnvironment(resps, es, UDS_IOCBIEnumerator_kwargs={"scan_range": range(0x100)}) |
| 1012 |
|
| 1013 |
assert scanner.scan_completed |
| 1014 |
assert scanner.progress() > 0.95 |
| 1015 |
|
| 1016 |
tc = scanner.configuration.test_cases[0] |
| 1017 |
|
| 1018 |
assert len(tc.results_without_response) < 10 |
| 1019 |
if tc.results_without_response: |
| 1020 |
tc.show() |
| 1021 |
|
| 1022 |
assert len(tc.results_with_negative_response) == 0x100 - 4 |
| 1023 |
assert len(tc.results_with_positive_response) == 4 |
| 1024 |
assert len(tc.scanned_states) == 1 |
| 1025 |
|
| 1026 |
result = tc.show(dump=True) |
| 1027 |
|
| 1028 |
assert "asdfbeef1" in result |
| 1029 |
assert "beef2" in result |
| 1030 |
assert "beef3" in result |
| 1031 |
assert "beefff" in result |
| 1032 |
assert "subFunctionNotSupported received" in result |
| 1033 |
|
| 1034 |
ids = [t.req.dataIdentifier for t in tc.results_with_positive_response] |
| 1035 |
|
| 1036 |
assert 1 in ids |
| 1037 |
assert 2 in ids |
| 1038 |
assert 3 in ids |
| 1039 |
assert 0xff in ids |
| 1040 |
|
| 1041 |
|
| 1042 |
= UDS_RDEnumerator |
| 1043 |
|
| 1044 |
memory = dict() |
| 1045 |
|
| 1046 |
for addr in itertools.chain(range(0x1f00), range(0xd000, 0xfff2), range(0xa000, 0xcf00), range(0x2000, 0x5f00)): |
| 1047 |
memory[addr] = addr & 0xff |
| 1048 |
|
| 1049 |
def answers_rd(resp, req): |
| 1050 |
global memory |
| 1051 |
if req.service != 0x34: |
| 1052 |
return False |
| 1053 |
if req.memorySizeLen in [1, 3, 4]: |
| 1054 |
return False |
| 1055 |
if req.memoryAddressLen in [1, 3, 4]: |
| 1056 |
return False |
| 1057 |
addr = getattr(req, "memoryAddress%d" % req.memoryAddressLen) |
| 1058 |
if addr not in memory.keys(): |
| 1059 |
return False |
| 1060 |
resp.memorySizeLen = req.memorySizeLen |
| 1061 |
return True |
| 1062 |
|
| 1063 |
resps = [EcuResponse(None, [UDS()/UDS_RDPR()], answers=answers_rd), |
| 1064 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="requestOutOfRange", requestServiceId="RequestDownload")])] |
| 1065 |
|
| 1066 |
####################################################### |
| 1067 |
scanner = executeScannerInVirtualEnvironment( |
| 1068 |
resps, [UDS_RDEnumerator], unstable_socket=False, |
| 1069 |
UDS_RDEnumerator_kwargs={"unittest": True}) |
| 1070 |
|
| 1071 |
assert scanner.scan_completed |
| 1072 |
assert scanner.progress() > 0.95 |
| 1073 |
|
| 1074 |
tc1 = scanner.configuration.test_cases[0] |
| 1075 |
|
| 1076 |
assert len(tc1.results_without_response) < 10 |
| 1077 |
if len(tc1.results_without_response): |
| 1078 |
tc1.show() |
| 1079 |
|
| 1080 |
assert len(tc1.results_with_negative_response) > 400 |
| 1081 |
assert len(tc1.results_with_positive_response) > 40 |
| 1082 |
assert len(tc1.scanned_states) == 1 |
| 1083 |
|
| 1084 |
result = tc1.show(dump=True) |
| 1085 |
|
| 1086 |
assert "requestOutOfRange received " in result |
| 1087 |
|
| 1088 |
= UDS_RMBARandomEnumerator |
| 1089 |
|
| 1090 |
pkt = UDS_RMBARandomEnumerator._random_memory_addr_pkt(4, 4, 10) |
| 1091 |
|
| 1092 |
assert pkt.memorySizeLen == 4 |
| 1093 |
assert pkt.memoryAddressLen == 4 |
| 1094 |
assert pkt.memorySize4 == 10 |
| 1095 |
assert pkt.memoryAddress4 is not None |
| 1096 |
|
| 1097 |
pkt = UDS_RMBARandomEnumerator._random_memory_addr_pkt() |
| 1098 |
|
| 1099 |
assert pkt.memorySizeLen in [1, 2, 3, 4] |
| 1100 |
assert pkt.memoryAddressLen in [1, 2, 3, 4] |
| 1101 |
|
| 1102 |
pkt2 = UDS_RMBARandomEnumerator._random_memory_addr_pkt() |
| 1103 |
|
| 1104 |
assert pkt != pkt2 |
| 1105 |
|
| 1106 |
|
| 1107 |
= UDS_RMBAEnumerator |
| 1108 |
~ linux not_pypy |
| 1109 |
|
| 1110 |
memory = dict() |
| 1111 |
|
| 1112 |
mem_areas = [(0x100, 0x1f00), (0xd000, 0xff00), (0xa000, 0xc000), (0x3000, 0x5f00)] |
| 1113 |
|
| 1114 |
mem_ranges = [range(s, e) for s, e in mem_areas] |
| 1115 |
|
| 1116 |
mem_inner_borders = [s for s, _ in mem_areas] |
| 1117 |
mem_inner_borders += [e - 1 for _, e in mem_areas] |
| 1118 |
|
| 1119 |
mem_outer_borders = [s - 1 for s, _ in mem_areas] |
| 1120 |
mem_outer_borders += [e for _, e in mem_areas] |
| 1121 |
|
| 1122 |
mem_random_test_points = [] |
| 1123 |
for _ in range(100): |
| 1124 |
mem_random_test_points += [random.choice(list(itertools.chain(*mem_ranges)))] |
| 1125 |
|
| 1126 |
for addr in itertools.chain(*mem_ranges): |
| 1127 |
memory[addr] = addr & 0xff |
| 1128 |
|
| 1129 |
def answers_rmba(resp, req): |
| 1130 |
global memory |
| 1131 |
if req.service != 0x23: |
| 1132 |
return False |
| 1133 |
if req.memorySizeLen in [1, 3, 4]: |
| 1134 |
return False |
| 1135 |
if req.memoryAddressLen in [1, 3, 4]: |
| 1136 |
return False |
| 1137 |
addr = getattr(req, "memoryAddress%d" % req.memoryAddressLen) |
| 1138 |
if addr not in memory.keys(): |
| 1139 |
return False |
| 1140 |
out_mem = list() |
| 1141 |
size = getattr(req, "memorySize%d" % req.memorySizeLen) |
| 1142 |
for i in range(addr, addr + size): |
| 1143 |
try: |
| 1144 |
out_mem.append(memory[i]) |
| 1145 |
except KeyError: |
| 1146 |
pass |
| 1147 |
resp.dataRecord = bytes(out_mem) |
| 1148 |
return True |
| 1149 |
|
| 1150 |
resps = [EcuResponse(None, [UDS()/UDS_RMBAPR(dataRecord=b'')], answers=answers_rmba), |
| 1151 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="requestOutOfRange", requestServiceId="ReadMemoryByAddress")])] |
| 1152 |
|
| 1153 |
####################################################### |
| 1154 |
scanner = executeScannerInVirtualEnvironment( |
| 1155 |
resps, [UDS_RMBAEnumerator], unstable_socket=False, |
| 1156 |
UDS_RMBARandomEnumerator_kwargs={"unittest": True}) |
| 1157 |
|
| 1158 |
assert scanner.scan_completed |
| 1159 |
tc1 = scanner.configuration.stages[0][1] |
| 1160 |
|
| 1161 |
assert len(tc1.results_without_response) < 30 |
| 1162 |
if len(tc1.results_without_response): |
| 1163 |
tc1.show() |
| 1164 |
|
| 1165 |
assert len(tc1.results_with_negative_response) > 10 |
| 1166 |
assert len(tc1.results_with_positive_response) > 300 |
| 1167 |
assert len(tc1.scanned_states) == 1 |
| 1168 |
|
| 1169 |
result = tc1.show(dump=True) |
| 1170 |
|
| 1171 |
assert "requestOutOfRange received " in result |
| 1172 |
|
| 1173 |
############################################################ |
| 1174 |
|
| 1175 |
addrs = tc1._get_memory_addresses_from_results(tc1.results_with_positive_response) |
| 1176 |
|
| 1177 |
print(float([tp in addrs for tp in mem_inner_borders].count(True)) / len(mem_inner_borders)) |
| 1178 |
assert float([tp in addrs for tp in mem_inner_borders].count(True)) / len(mem_inner_borders) > 0.8 |
| 1179 |
print(float([tp in addrs for tp in mem_random_test_points].count(True)) / len(mem_random_test_points)) |
| 1180 |
assert float([tp in addrs for tp in mem_random_test_points].count(True)) / len(mem_random_test_points) > 0.8 |
| 1181 |
print(float([tp not in addrs for tp in mem_outer_borders].count(True)) / len(mem_outer_borders)) |
| 1182 |
assert float([tp not in addrs for tp in mem_outer_borders].count(True)) / len(mem_outer_borders) > 0.7 |
| 1183 |
|
| 1184 |
|
| 1185 |
= UDS_TDEnumerator |
| 1186 |
|
| 1187 |
resps = [EcuResponse(None, [UDS()/UDS_TDPR(blockSequenceCounter=1)]), |
| 1188 |
EcuResponse(None, [UDS()/UDS_TDPR(blockSequenceCounter=3)]), |
| 1189 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId="TransferData")])] |
| 1190 |
|
| 1191 |
es = [UDS_TDEnumerator] |
| 1192 |
|
| 1193 |
scanner = executeScannerInVirtualEnvironment(resps, es) |
| 1194 |
|
| 1195 |
assert scanner.scan_completed |
| 1196 |
assert scanner.progress() > 0.95 |
| 1197 |
|
| 1198 |
tc = scanner.configuration.test_cases[0] |
| 1199 |
|
| 1200 |
assert len(tc.results_without_response) < 10 |
| 1201 |
if tc.results_without_response: |
| 1202 |
tc.show() |
| 1203 |
|
| 1204 |
assert len(tc.results_with_negative_response) == 256 - 2 |
| 1205 |
assert len(tc.results_with_positive_response) == 2 |
| 1206 |
assert len(tc.scanned_states) == 1 |
| 1207 |
|
| 1208 |
result = tc.show(dump=True) |
| 1209 |
|
| 1210 |
assert "subFunctionNotSupported received" in result |
| 1211 |
|
| 1212 |
ids = [t.req.blockSequenceCounter for t in tc.results_with_positive_response] |
| 1213 |
|
| 1214 |
assert 1 in ids |
| 1215 |
assert 3 in ids |
| 1216 |
|
| 1217 |
= BMW_DevJobEnumerator |
| 1218 |
|
| 1219 |
load_contrib("automotive.bmw.definitions") |
| 1220 |
load_contrib("automotive.bmw.enumerator") |
| 1221 |
|
| 1222 |
resps = [EcuResponse(None, [UDS()/DEV_JOB_PR(identifier=0xff00)/Raw(b"asdfbeef1")]), |
| 1223 |
EcuResponse(None, [UDS()/DEV_JOB_PR(identifier=0xff02)/Raw(b"beef2")]), |
| 1224 |
EcuResponse(None, [UDS()/DEV_JOB_PR(identifier=0xff03)/Raw(b"beef3")]), |
| 1225 |
EcuResponse(None, [UDS()/DEV_JOB_PR(identifier=0xffff)/Raw(b"beefff")]), |
| 1226 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId="DevelopmentJob")])] |
| 1227 |
|
| 1228 |
es = [BMW_DevJobEnumerator] |
| 1229 |
|
| 1230 |
scanner = executeScannerInVirtualEnvironment(resps, es, BMW_DevJobEnumerator_kwargs={"scan_range": range(0xFF00, 0x10000)}) |
| 1231 |
|
| 1232 |
assert scanner.scan_completed |
| 1233 |
assert scanner.progress() > 0.95 |
| 1234 |
|
| 1235 |
tc = scanner.configuration.test_cases[0] |
| 1236 |
|
| 1237 |
assert len(tc.results_without_response) < 10 |
| 1238 |
if tc.results_without_response: |
| 1239 |
tc.show() |
| 1240 |
|
| 1241 |
assert len(tc.results_with_negative_response) == 0x100 - 4 |
| 1242 |
assert len(tc.results_with_positive_response) == 4 |
| 1243 |
assert len(tc.scanned_states) == 1 |
| 1244 |
|
| 1245 |
result = tc.show(dump=True) |
| 1246 |
|
| 1247 |
assert "ReadTransportMessageStatus" in result |
| 1248 |
assert "65282" in result |
| 1249 |
assert "65283" in result |
| 1250 |
assert "ReadMemory" in result |
| 1251 |
assert "subFunctionNotSupported received" in result |
| 1252 |
assert "PR: Supported" in result |
| 1253 |
|
| 1254 |
ids = [t.req.identifier for t in tc.results_with_positive_response] |
| 1255 |
|
| 1256 |
assert 0xff00 in ids |
| 1257 |
assert 0xff02 in ids |
| 1258 |
assert 0xff03 in ids |
| 1259 |
assert 0xffff in ids |
| 1260 |
|
| 1261 |
= UDS_ServiceEnumerator weird issue |
| 1262 |
|
| 1263 |
resps = [EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode=0x13, requestServiceId=0x40)]), |
| 1264 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId=0x41)]), |
| 1265 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId=0x11)]), |
| 1266 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId=0x42)]), |
| 1267 |
EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId=0x43)])] |
| 1268 |
|
| 1269 |
es = [UDS_ServiceEnumerator] |
| 1270 |
|
| 1271 |
scanner = executeScannerInVirtualEnvironment( |
| 1272 |
resps, es, UDS_ServiceEnumerator_kwargs={"scan_range": [0x11, 0x40, 0x41, 0x42]}) |
| 1273 |
|
| 1274 |
assert scanner.scan_completed |
| 1275 |
assert scanner.progress() > 0.95 |
| 1276 |
tc = scanner.configuration.test_cases[0] |
| 1277 |
tc.show() |
| 1278 |
|
| 1279 |
assert len(tc.results_with_negative_response) == 4 |
| 1280 |
|
| 1281 |
= UDS_ServiceEnumerator, all range |
| 1282 |
|
| 1283 |
def req_handler(resp, req): |
| 1284 |
if req.service != 0x22: |
| 1285 |
return False |
| 1286 |
if len(req) == 1: |
| 1287 |
resp.negativeResponseCode="generalReject" |
| 1288 |
return True |
| 1289 |
if len(req) == 2: |
| 1290 |
resp.negativeResponseCode="incorrectMessageLengthOrInvalidFormat" |
| 1291 |
return True |
| 1292 |
if len(req) == 3: |
| 1293 |
resp.negativeResponseCode="requestOutOfRange" |
| 1294 |
return True |
| 1295 |
return False |
| 1296 |
|
| 1297 |
resps = [EcuResponse(None, [UDS()/UDS_NR(negativeResponseCode="subFunctionNotSupported", requestServiceId="ReadDataByIdentifier")], req_handler)] |
| 1298 |
|
| 1299 |
es = [UDS_ServiceEnumerator] |
| 1300 |
|
| 1301 |
debug_dissector_backup = conf.debug_dissector |
| 1302 |
|
| 1303 |
# This Enumerator is sending corrupted Packets, therefore we need to disable the debug_dissector |
| 1304 |
conf.debug_dissector = False |
| 1305 |
scanner = executeScannerInVirtualEnvironment( |
| 1306 |
resps, es, UDS_ServiceEnumerator_kwargs={"request_length": 3, "scan_range": range(256)}, unstable_socket=False) |
| 1307 |
conf.debug_dissector = debug_dissector_backup |
| 1308 |
|
| 1309 |
assert scanner.scan_completed |
| 1310 |
assert scanner.progress() > 0.95 |
| 1311 |
tc = scanner.configuration.test_cases[0] |
| 1312 |
|
| 1313 |
assert len(tc.results_without_response) < 10 |
| 1314 |
if tc.results_without_response: |
| 1315 |
tc.show() |
| 1316 |
|
| 1317 |
tc.show() |
| 1318 |
|
| 1319 |
assert len(tc.scanned_states) == 1 |
| 1320 |
|
| 1321 |
result = tc.show(dump=True) |
| 1322 |
|
| 1323 |
assert "incorrectMessageLengthOrInvalidFormat" in result |
| 1324 |
assert "requestOutOfRange" in result |
| 1325 |
|
| 1326 |
+ Cleanup |
| 1327 |
|
| 1328 |
= Delete testsockets |
| 1329 |
|
| 1330 |
|
| 1331 |
cleanup_testsockets() |