@@ -118,6 +118,7 @@ static const struct role roles[] = {
118
118
};
119
119
120
120
struct link {
121
+ bool discovered ;
121
122
bool published ;
122
123
int ifindex ;
123
124
enum endpoint_role role ;
@@ -768,6 +769,7 @@ static int handle_control_set_endpoint_id(struct ctx *ctx, int sd,
768
769
warnx ("ERR: cannot add bus owner to object lists" );
769
770
}
770
771
772
+ link_data -> discovered = true;
771
773
SET_MCTP_EID_ASSIGNMENT_STATUS (resp -> status ,
772
774
MCTP_SET_EID_ACCEPTED );
773
775
SET_MCTP_EID_ALLOCATION_STATUS (resp -> status ,
@@ -778,6 +780,15 @@ static int handle_control_set_endpoint_id(struct ctx *ctx, int sd,
778
780
return reply_message (ctx , sd , resp , resp_len , addr );
779
781
780
782
case MCTP_SET_EID_DISCOVERED :
783
+ link_data -> discovered = true;
784
+ SET_MCTP_EID_ASSIGNMENT_STATUS (resp -> status ,
785
+ MCTP_SET_EID_REJECTED );
786
+ SET_MCTP_EID_ALLOCATION_STATUS (resp -> status ,
787
+ MCTP_SET_EID_POOL_NONE );
788
+ resp -> eid_set = req -> eid ;
789
+ resp -> eid_pool_size = 0 ;
790
+ return reply_message (ctx , sd , resp , resp_len , addr );
791
+
781
792
case MCTP_SET_EID_RESET :
782
793
// unsupported
783
794
resp -> completion_code = MCTP_CTRL_CC_ERROR_INVALID_DATA ;
@@ -938,6 +949,77 @@ handle_control_resolve_endpoint_id(struct ctx *ctx, int sd,
938
949
return reply_message (ctx , sd , resp , resp_len , addr );
939
950
}
940
951
952
+ static int handle_control_prepare_endpoint_discovery (
953
+ struct ctx * ctx , int sd , const struct sockaddr_mctp_ext * addr ,
954
+ const uint8_t * buf , const size_t buf_size )
955
+ {
956
+ struct mctp_ctrl_msg_hdr * req = NULL ;
957
+ struct mctp_ctrl_resp_prepare_discovery respi = { 0 }, * resp = & respi ;
958
+ struct link * link_data ;
959
+
960
+ if (buf_size < sizeof (* req )) {
961
+ warnx ("short Prepare for Endpoint Discovery message" );
962
+ return - ENOMSG ;
963
+ }
964
+
965
+ link_data = mctp_nl_get_link_userdata (ctx -> nl , addr -> smctp_ifindex );
966
+ if (!link_data ) {
967
+ bug_warn ("unconfigured interface %d" , addr -> smctp_ifindex );
968
+ return - ENOENT ;
969
+ }
970
+
971
+ req = (void * )buf ;
972
+ resp = (void * )resp ;
973
+ mctp_ctrl_msg_hdr_init_resp (& resp -> ctrl_hdr , * req );
974
+
975
+ if (link_data -> discovered ) {
976
+ link_data -> discovered = false;
977
+ warnx ("clear discovered flag of interface %d" ,
978
+ addr -> smctp_ifindex );
979
+ }
980
+
981
+ // we need to send using physical addressing, no entry in routing table yet
982
+ return reply_message_phys (ctx , sd , resp , sizeof (* resp ), addr );
983
+ }
984
+
985
+ static int
986
+ handle_control_endpoint_discovery (struct ctx * ctx , int sd ,
987
+ const struct sockaddr_mctp_ext * addr ,
988
+ const uint8_t * buf , const size_t buf_size )
989
+ {
990
+ struct mctp_ctrl_msg_hdr * req = NULL ;
991
+ struct mctp_ctrl_resp_endpoint_discovery respi = { 0 }, * resp = & respi ;
992
+ struct link * link_data ;
993
+
994
+ if (buf_size < sizeof (* req )) {
995
+ warnx ("short Endpoint Discovery message" );
996
+ return - ENOMSG ;
997
+ }
998
+
999
+ link_data = mctp_nl_get_link_userdata (ctx -> nl , addr -> smctp_ifindex );
1000
+ if (!link_data ) {
1001
+ bug_warn ("unconfigured interface %d" , addr -> smctp_ifindex );
1002
+ return - ENOENT ;
1003
+ }
1004
+
1005
+ if (link_data -> role == ENDPOINT_ROLE_BUS_OWNER ) {
1006
+ // ignore message if we are bus owner
1007
+ return 0 ;
1008
+ }
1009
+
1010
+ if (link_data -> discovered ) {
1011
+ // if we are already discovered (i.e, assigned an EID), then no reply
1012
+ return 0 ;
1013
+ }
1014
+
1015
+ req = (void * )buf ;
1016
+ resp = (void * )resp ;
1017
+ mctp_ctrl_msg_hdr_init_resp (& resp -> ctrl_hdr , * req );
1018
+
1019
+ // we need to send using physical addressing, no entry in routing table yet
1020
+ return reply_message_phys (ctx , sd , resp , sizeof (* resp ), addr );
1021
+ }
1022
+
941
1023
static int handle_control_unsupported (struct ctx * ctx , int sd ,
942
1024
const struct sockaddr_mctp_ext * addr ,
943
1025
const uint8_t * buf , const size_t buf_size )
@@ -1020,6 +1102,14 @@ static int cb_listen_control_msg(sd_event_source *s, int sd, uint32_t revents,
1020
1102
rc = handle_control_resolve_endpoint_id (ctx , sd , & addr , buf ,
1021
1103
buf_size );
1022
1104
break ;
1105
+ case MCTP_CTRL_CMD_PREPARE_ENDPOINT_DISCOVERY :
1106
+ rc = handle_control_prepare_endpoint_discovery (ctx , sd , & addr ,
1107
+ buf , buf_size );
1108
+ break ;
1109
+ case MCTP_CTRL_CMD_ENDPOINT_DISCOVERY :
1110
+ rc = handle_control_endpoint_discovery (ctx , sd , & addr , buf ,
1111
+ buf_size );
1112
+ break ;
1023
1113
default :
1024
1114
if (ctx -> verbose ) {
1025
1115
warnx ("Ignoring unsupported command code 0x%02x" ,
@@ -3880,6 +3970,7 @@ static int add_interface(struct ctx *ctx, int ifindex)
3880
3970
if (!link )
3881
3971
return - ENOMEM ;
3882
3972
3973
+ link -> discovered = false;
3883
3974
link -> published = false;
3884
3975
link -> ifindex = ifindex ;
3885
3976
link -> ctx = ctx ;
0 commit comments