@@ -63,11 +63,6 @@ static mctp_eid_t eid_alloc_max = 0xfe;
63
63
// arbitrary sanity
64
64
static size_t MAX_PEER_SIZE = 1000000 ;
65
65
66
- static const uint8_t RQDI_REQ = 1 << 7 ;
67
- static const uint8_t RQDI_RESP = 0x0 ;
68
- static const uint8_t IID_MASK = 0x1f ;
69
- static const uint8_t RQDI_IID_MASK = 0x1f ;
70
-
71
66
struct dest_phys {
72
67
int ifindex ;
73
68
uint8_t hwaddr [MAX_ADDR_LEN ];
@@ -645,9 +640,7 @@ static int handle_control_set_endpoint_id(struct ctx *ctx, int sd,
645
640
}
646
641
req = (void * )buf ;
647
642
648
- resp -> ctrl_hdr .command_code = req -> ctrl_hdr .command_code ;
649
- resp -> ctrl_hdr .rq_dgram_inst =
650
- (req -> ctrl_hdr .rq_dgram_inst & IID_MASK ) | RQDI_RESP ;
643
+ mctp_ctrl_msg_hdr_init_resp (& respi .ctrl_hdr , req -> ctrl_hdr );
651
644
resp -> completion_code = MCTP_CTRL_CC_SUCCESS ;
652
645
resp -> status = 0x01 << 4 ; // Already assigned, TODO
653
646
resp -> eid_set = local_addr (ctx , addr -> smctp_ifindex );
@@ -668,7 +661,7 @@ handle_control_get_version_support(struct ctx *ctx, int sd,
668
661
struct mctp_ctrl_resp_get_mctp_ver_support * resp = NULL ;
669
662
uint32_t * versions = NULL ;
670
663
// space for 4 versions
671
- uint8_t respbuf [sizeof (* resp ) + 4 * sizeof (* versions )];
664
+ uint8_t respbuf [sizeof (* resp ) + 4 * sizeof (* versions )] = { 0 } ;
672
665
size_t resp_len ;
673
666
674
667
if (buf_size < sizeof (struct mctp_ctrl_cmd_get_mctp_ver_support )) {
@@ -678,7 +671,7 @@ handle_control_get_version_support(struct ctx *ctx, int sd,
678
671
679
672
req = (void * )buf ;
680
673
resp = (void * )respbuf ;
681
- memset ( resp , 0x0 , sizeof ( * resp ) );
674
+ mctp_ctrl_msg_hdr_init_resp ( & resp -> ctrl_hdr , req -> ctrl_hdr );
682
675
versions = (void * )(resp + 1 );
683
676
switch (req -> msg_type_number ) {
684
677
case 0xff : // Base Protocol
@@ -699,9 +692,6 @@ handle_control_get_version_support(struct ctx *ctx, int sd,
699
692
resp_len = sizeof (* resp );
700
693
}
701
694
702
- resp -> ctrl_hdr .command_code = req -> ctrl_hdr .command_code ;
703
- resp -> ctrl_hdr .rq_dgram_inst =
704
- (req -> ctrl_hdr .rq_dgram_inst & IID_MASK ) | RQDI_RESP ;
705
695
return reply_message (ctx , sd , resp , resp_len , addr );
706
696
}
707
697
@@ -719,9 +709,7 @@ static int handle_control_get_endpoint_id(struct ctx *ctx, int sd,
719
709
}
720
710
721
711
req = (void * )buf ;
722
- resp -> ctrl_hdr .command_code = req -> ctrl_hdr .command_code ;
723
- resp -> ctrl_hdr .rq_dgram_inst =
724
- (req -> ctrl_hdr .rq_dgram_inst & IID_MASK ) | RQDI_RESP ;
712
+ mctp_ctrl_msg_hdr_init_resp (& resp -> ctrl_hdr , req -> ctrl_hdr );
725
713
726
714
resp -> eid = local_addr (ctx , addr -> smctp_ifindex );
727
715
if (ctx -> default_role == ENDPOINT_ROLE_BUS_OWNER )
@@ -740,7 +728,6 @@ handle_control_get_endpoint_uuid(struct ctx *ctx, int sd,
740
728
const uint8_t * buf , const size_t buf_size )
741
729
{
742
730
struct mctp_ctrl_cmd_get_uuid * req = NULL ;
743
- ;
744
731
struct mctp_ctrl_resp_get_uuid respi = { 0 }, * resp = & respi ;
745
732
746
733
if (buf_size < sizeof (* req )) {
@@ -749,9 +736,7 @@ handle_control_get_endpoint_uuid(struct ctx *ctx, int sd,
749
736
}
750
737
751
738
req = (void * )buf ;
752
- resp -> ctrl_hdr .command_code = req -> ctrl_hdr .command_code ;
753
- resp -> ctrl_hdr .rq_dgram_inst =
754
- (req -> ctrl_hdr .rq_dgram_inst & IID_MASK ) | RQDI_RESP ;
739
+ mctp_ctrl_msg_hdr_init_resp (& resp -> ctrl_hdr , req -> ctrl_hdr );
755
740
memcpy (resp -> uuid , ctx -> uuid , sizeof (resp -> uuid ));
756
741
return reply_message (ctx , sd , resp , sizeof (* resp ), addr );
757
742
}
@@ -761,9 +746,8 @@ static int handle_control_get_message_type_support(
761
746
const uint8_t * buf , const size_t buf_size )
762
747
{
763
748
struct mctp_ctrl_cmd_get_msg_type_support * req = NULL ;
764
- ;
765
749
struct mctp_ctrl_resp_get_msg_type_support * resp = NULL ;
766
- uint8_t resp_buf [sizeof (* resp ) + 1 ];
750
+ uint8_t resp_buf [sizeof (* resp ) + 1 ] = { 0 } ;
767
751
size_t resp_len ;
768
752
769
753
if (buf_size < sizeof (* req )) {
@@ -773,9 +757,7 @@ static int handle_control_get_message_type_support(
773
757
774
758
req = (void * )buf ;
775
759
resp = (void * )resp_buf ;
776
- resp -> ctrl_hdr .command_code = req -> ctrl_hdr .command_code ;
777
- resp -> ctrl_hdr .rq_dgram_inst =
778
- (req -> ctrl_hdr .rq_dgram_inst & IID_MASK ) | RQDI_RESP ;
760
+ mctp_ctrl_msg_hdr_init_resp (& resp -> ctrl_hdr , req -> ctrl_hdr );
779
761
780
762
// Only control messages supported
781
763
resp -> msg_type_count = 1 ;
@@ -792,7 +774,7 @@ handle_control_resolve_endpoint_id(struct ctx *ctx, int sd,
792
774
{
793
775
struct mctp_ctrl_cmd_resolve_endpoint_id * req = NULL ;
794
776
struct mctp_ctrl_resp_resolve_endpoint_id * resp = NULL ;
795
- uint8_t resp_buf [sizeof (* resp ) + MAX_ADDR_LEN ];
777
+ uint8_t resp_buf [sizeof (* resp ) + MAX_ADDR_LEN ] = { 0 } ;
796
778
size_t resp_len ;
797
779
struct peer * peer = NULL ;
798
780
@@ -803,11 +785,7 @@ handle_control_resolve_endpoint_id(struct ctx *ctx, int sd,
803
785
804
786
req = (void * )buf ;
805
787
resp = (void * )resp_buf ;
806
- memset (resp , 0x0 , sizeof (* resp ));
807
- resp -> ctrl_hdr .command_code = req -> ctrl_hdr .command_code ;
808
- resp -> ctrl_hdr .rq_dgram_inst =
809
- (req -> ctrl_hdr .rq_dgram_inst & IID_MASK ) | RQDI_RESP ;
810
-
788
+ mctp_ctrl_msg_hdr_init_resp (& resp -> ctrl_hdr , req -> ctrl_hdr );
811
789
peer = find_peer_by_addr (ctx , req -> eid , addr -> smctp_base .smctp_network );
812
790
if (!peer ) {
813
791
resp -> completion_code = MCTP_CTRL_CC_ERROR ;
@@ -840,9 +818,7 @@ static int handle_control_unsupported(struct ctx *ctx, int sd,
840
818
}
841
819
842
820
req = (void * )buf ;
843
- resp -> ctrl_hdr .command_code = req -> command_code ;
844
- resp -> ctrl_hdr .rq_dgram_inst = (req -> rq_dgram_inst & IID_MASK ) |
845
- RQDI_RESP ;
821
+ mctp_ctrl_msg_hdr_init_resp (& resp -> ctrl_hdr , * req );
846
822
resp -> completion_code = MCTP_CTRL_CC_ERROR_UNSUPPORTED_CMD ;
847
823
return reply_message (ctx , sd , resp , sizeof (* resp ), addr );
848
824
}
@@ -1377,8 +1353,10 @@ static int endpoint_send_set_endpoint_id(const struct peer *peer,
1377
1353
rc = -1 ;
1378
1354
1379
1355
iid = mctp_next_iid (peer -> ctx );
1380
- req .ctrl_hdr .rq_dgram_inst = RQDI_REQ | iid ;
1381
- req .ctrl_hdr .command_code = MCTP_CTRL_CMD_SET_ENDPOINT_ID ;
1356
+
1357
+ mctp_ctrl_msg_hdr_init_req (& req .ctrl_hdr , iid ,
1358
+ MCTP_CTRL_CMD_SET_ENDPOINT_ID );
1359
+
1382
1360
req .operation =
1383
1361
mctp_ctrl_cmd_set_eid_set_eid ; // TODO: do we want Force?
1384
1362
req .eid = peer -> eid ;
@@ -1803,8 +1781,9 @@ static int query_get_endpoint_id(struct ctx *ctx, const dest_phys *dest,
1803
1781
1804
1782
iid = mctp_next_iid (ctx );
1805
1783
1806
- req .ctrl_hdr .rq_dgram_inst = RQDI_REQ | iid ;
1807
- req .ctrl_hdr .command_code = MCTP_CTRL_CMD_GET_ENDPOINT_ID ;
1784
+ mctp_ctrl_msg_hdr_init_req (& req .ctrl_hdr , iid ,
1785
+ MCTP_CTRL_CMD_GET_ENDPOINT_ID );
1786
+
1808
1787
rc = endpoint_query_phys (ctx , dest , MCTP_CTRL_HDR_MSG_TYPE , & req ,
1809
1788
sizeof (req ), & buf , & buf_size , & addr );
1810
1789
if (rc < 0 )
@@ -1907,8 +1886,8 @@ static int query_get_peer_msgtypes(struct peer *peer)
1907
1886
peer -> message_types = NULL ;
1908
1887
iid = mctp_next_iid (peer -> ctx );
1909
1888
1910
- req .ctrl_hdr . rq_dgram_inst = RQDI_REQ | iid ;
1911
- req . ctrl_hdr . command_code = MCTP_CTRL_CMD_GET_MESSAGE_TYPE_SUPPORT ;
1889
+ mctp_ctrl_msg_hdr_init_req ( & req .ctrl_hdr , iid ,
1890
+ MCTP_CTRL_CMD_GET_MESSAGE_TYPE_SUPPORT ) ;
1912
1891
1913
1892
rc = endpoint_query_peer (peer , MCTP_CTRL_HDR_MSG_TYPE , & req ,
1914
1893
sizeof (req ), & buf , & buf_size , & addr );
@@ -1967,8 +1946,9 @@ static int query_get_peer_uuid_by_phys(struct ctx *ctx, const dest_phys *dest,
1967
1946
int rc ;
1968
1947
1969
1948
iid = mctp_next_iid (ctx );
1970
- req .ctrl_hdr .rq_dgram_inst = RQDI_REQ | iid ;
1971
- req .ctrl_hdr .command_code = MCTP_CTRL_CMD_GET_ENDPOINT_UUID ;
1949
+
1950
+ mctp_ctrl_msg_hdr_init_req (& req .ctrl_hdr , iid ,
1951
+ MCTP_CTRL_CMD_GET_ENDPOINT_UUID );
1972
1952
1973
1953
rc = endpoint_query_phys (ctx , dest , MCTP_CTRL_HDR_MSG_TYPE , & req ,
1974
1954
sizeof (req ), & buf , & buf_size , & addr );
@@ -2006,8 +1986,9 @@ static int query_get_peer_uuid(struct peer *peer)
2006
1986
}
2007
1987
2008
1988
iid = mctp_next_iid (peer -> ctx );
2009
- req .ctrl_hdr .rq_dgram_inst = RQDI_REQ | iid ;
2010
- req .ctrl_hdr .command_code = MCTP_CTRL_CMD_GET_ENDPOINT_UUID ;
1989
+
1990
+ mctp_ctrl_msg_hdr_init_req (& req .ctrl_hdr , iid ,
1991
+ MCTP_CTRL_CMD_GET_ENDPOINT_UUID );
2011
1992
2012
1993
rc = endpoint_query_peer (peer , MCTP_CTRL_HDR_MSG_TYPE , & req ,
2013
1994
sizeof (req ), & buf , & buf_size , & addr );
0 commit comments