@@ -446,6 +446,107 @@ async def handle_mctp_control(self, sock, src_addr, msg):
446
446
447
447
assert str (ex .value ) == "Request failed"
448
448
449
+ """ During a SetupEndpoint's Set Endpoint ID exchange, return a response
450
+ that indicates that the EID has been set, but report an invalid (0) EID
451
+ in the response."""
452
+ async def test_setup_endpoint_invalid_set_eid_response (dbus , mctpd ):
453
+ class InvalidEndpoint (Endpoint ):
454
+ async def handle_mctp_control (self , sock , src_addr , msg ):
455
+ flags , opcode = msg [0 :2 ]
456
+ if opcode != 1 :
457
+ return await super ().handle_mctp_control (sock , src_addr , msg )
458
+ dst_addr = MCTPSockAddr .for_ep_resp (self , src_addr , sock .addr_ext )
459
+ self .eid = msg [3 ]
460
+ msg = bytes ([
461
+ flags & 0x1f , # Rsp
462
+ 0x01 , # opcode: Set Endpoint ID
463
+ 0x00 , # cc: success
464
+ 0x00 , # assignment accepted, no pool
465
+ 0x00 , # set EID: invalid
466
+ 0x00 , # pool size: 0
467
+ ])
468
+ await sock .send (dst_addr , msg )
469
+
470
+ iface = mctpd .system .interfaces [0 ]
471
+ ep = InvalidEndpoint (iface , bytes ([0x1e ]), eid = 0 )
472
+ mctpd .network .add_endpoint (ep )
473
+ mctp = await mctpd_mctp_iface_obj (dbus , iface )
474
+
475
+ with pytest .raises (asyncdbus .errors .DBusError ) as ex :
476
+ rc = await mctp .call_setup_endpoint (ep .lladdr )
477
+
478
+ assert str (ex .value ) == "Endpoint returned failure to Set Endpoint ID"
479
+
480
+ """ During a SetupEndpoint's Set Endpoint ID exchange, return a response
481
+ that indicates that the EID has been set, but report a different set EID
482
+ in the response."""
483
+ async def test_setup_endpoint_vary_set_eid_response (dbus , mctpd ):
484
+ class VaryEndpoint (Endpoint ):
485
+ async def handle_mctp_control (self , sock , src_addr , msg ):
486
+ flags , opcode = msg [0 :2 ]
487
+ if opcode != 1 :
488
+ return await super ().handle_mctp_control (sock , src_addr , msg )
489
+ dst_addr = MCTPSockAddr .for_ep_resp (self , src_addr , sock .addr_ext )
490
+ self .eid = msg [3 ] + 1
491
+ msg = bytes ([
492
+ flags & 0x1f , # Rsp
493
+ 0x01 , # opcode: Set Endpoint ID
494
+ 0x00 , # cc: success
495
+ 0x00 , # assignment accepted, no pool
496
+ self .eid , # set EID: valid, but not what was assigned
497
+ 0x00 , # pool size: 0
498
+ ])
499
+ await sock .send (dst_addr , msg )
500
+
501
+ iface = mctpd .system .interfaces [0 ]
502
+ ep = VaryEndpoint (iface , bytes ([0x1e ]))
503
+ mctpd .network .add_endpoint (ep )
504
+ mctp = await mctpd_mctp_iface_obj (dbus , iface )
505
+
506
+ (eid , _ , _ , _ ) = await mctp .call_setup_endpoint (ep .lladdr )
507
+
508
+ assert eid == ep .eid
509
+
510
+ """ During a SetupEndpoint's Set Endpoint ID exchange, return a response
511
+ that indicates that the EID has been set, but report a different set EID
512
+ in the response, which conflicts with another endpoint"""
513
+ async def test_setup_endpoint_conflicting_set_eid_response (dbus , mctpd ):
514
+
515
+ class ConflictingEndpoint (Endpoint ):
516
+ def __init__ (self , iface , lladdr , conflict_eid ):
517
+ super ().__init__ (iface , lladdr )
518
+ self .conflict_eid = conflict_eid
519
+
520
+ async def handle_mctp_control (self , sock , src_addr , msg ):
521
+ flags , opcode = msg [0 :2 ]
522
+ if opcode != 1 :
523
+ return await super ().handle_mctp_control (sock , src_addr , msg )
524
+ dst_addr = MCTPSockAddr .for_ep_resp (self , src_addr , sock .addr_ext )
525
+ # reject reality, use a conflicting eid
526
+ self .eid = self .conflict_eid
527
+ msg = bytes ([
528
+ flags & 0x1f , # Rsp
529
+ 0x01 , # opcode: Set Endpoint ID
530
+ 0x00 , # cc: success
531
+ 0x00 , # assignment accepted, no pool
532
+ self .eid , # set EID: valid, but not what was assigned
533
+ 0x00 , # pool size: 0
534
+ ])
535
+ await sock .send (dst_addr , msg )
536
+
537
+ iface = mctpd .system .interfaces [0 ]
538
+ ep1 = mctpd .network .endpoints [0 ]
539
+ mctp = await mctpd_mctp_iface_obj (dbus , iface )
540
+ (eid1 , _ , _ , _ ) = await mctp .call_setup_endpoint (ep1 .lladdr )
541
+ assert eid1 == ep1 .eid
542
+
543
+ ep2 = ConflictingEndpoint (iface , bytes ([0x1f ]), ep1 .eid )
544
+ mctpd .network .add_endpoint (ep2 )
545
+ with pytest .raises (asyncdbus .errors .DBusError ) as ex :
546
+ await mctp .call_setup_endpoint (ep2 .lladdr )
547
+
548
+ assert "already used" in str (ex .value )
549
+
449
550
""" Ensure a response with an invalid IID is discarded """
450
551
async def test_learn_endpoint_invalid_response_iid (dbus , mctpd ):
451
552
class InvalidIIDEndpoint (Endpoint ):
0 commit comments