@@ -22,16 +22,20 @@ static const int DEFAULT_NET = 1;
22
22
static const mctp_eid_t DEFAULT_EID = 8 ;
23
23
static const size_t DEFAULT_LEN = 1 ;
24
24
25
+ // Code Construct allocation
26
+ static const uint8_t VENDOR_TYPE_ECHO [3 ] = { 0xcc , 0xde , 0xf0 };
27
+ static const uint8_t MCTP_TYPE_VENDOR_PCIE = 0x7e ;
28
+
25
29
/* lladdrlen != -1 to ignore ifindex/lladdr */
26
30
static int mctp_req (unsigned int net , mctp_eid_t eid ,
27
31
unsigned int ifindex , uint8_t * lladdr , int lladdrlen ,
28
32
uint8_t * data , size_t len )
29
33
{
30
34
struct sockaddr_mctp_ext addr ;
31
- unsigned char * buf , * rxbuf ;
35
+ unsigned char * payload , * buf ;
32
36
socklen_t addrlen ;
33
37
int rc , sd , val ;
34
- size_t i ;
38
+ size_t i , buf_len ;
35
39
36
40
sd = socket (AF_MCTP , SOCK_DGRAM , 0 );
37
41
if (sd < 0 )
@@ -42,20 +46,23 @@ static int mctp_req(unsigned int net, mctp_eid_t eid,
42
46
addr .smctp_base .smctp_family = AF_MCTP ;
43
47
addr .smctp_base .smctp_network = net ;
44
48
addr .smctp_base .smctp_addr .s_addr = eid ;
45
- addr .smctp_base .smctp_type = 1 ;
49
+ addr .smctp_base .smctp_type = MCTP_TYPE_VENDOR_PCIE ;
46
50
addr .smctp_base .smctp_tag = MCTP_TAG_OWNER ;
47
- printf ("req: sending to (net %d, eid %d), type %d \n" ,
51
+ printf ("req: sending to (net %d, eid %d), type 0x%x \n" ,
48
52
net , eid , addr .smctp_base .smctp_type );
49
53
50
- rxbuf = malloc (len );
51
- if (!rxbuf )
54
+ buf_len = len + sizeof (VENDOR_TYPE_ECHO );
55
+ buf = malloc (buf_len );
56
+ if (!buf )
52
57
err (EXIT_FAILURE , "malloc" );
58
+ memcpy (buf , VENDOR_TYPE_ECHO , sizeof (VENDOR_TYPE_ECHO ));
59
+ payload = & buf [sizeof (VENDOR_TYPE_ECHO )];
60
+
53
61
if (data ) {
54
- buf = data ;
62
+ memcpy ( payload , data , len ) ;
55
63
} else {
56
- buf = rxbuf ;
57
64
for (i = 0 ; i < len ; i ++ )
58
- buf [i ] = i & 0xff ;
65
+ payload [i ] = i & 0xff ;
59
66
}
60
67
61
68
/* extended addressing */
@@ -76,20 +83,20 @@ static int mctp_req(unsigned int net, mctp_eid_t eid,
76
83
77
84
78
85
/* send data */
79
- rc = sendto (sd , buf , len , 0 ,
86
+ rc = sendto (sd , buf , buf_len , 0 ,
80
87
(struct sockaddr * )& addr , addrlen );
81
88
if (rc != (int )len )
82
89
err (EXIT_FAILURE , "sendto(%zd)" , len );
83
90
84
91
/* receive response */
85
92
addrlen = sizeof (addr );
86
- rc = recvfrom (sd , rxbuf , len , MSG_TRUNC ,
93
+ rc = recvfrom (sd , buf , buf_len , MSG_TRUNC ,
87
94
(struct sockaddr * )& addr , & addrlen );
88
95
if (rc < 0 )
89
96
err (EXIT_FAILURE , "recvfrom" );
90
- else if ((size_t )rc != len )
97
+ else if ((size_t )rc != buf_len )
91
98
errx (EXIT_FAILURE , "unexpected length: got %d, exp %zd" ,
92
- rc , len );
99
+ rc , buf_len );
93
100
94
101
if (!(addrlen == sizeof (struct sockaddr_mctp_ext ) ||
95
102
addrlen == sizeof (struct sockaddr_mctp )))
@@ -98,24 +105,27 @@ static int mctp_req(unsigned int net, mctp_eid_t eid,
98
105
sizeof (struct sockaddr_mctp ));
99
106
100
107
101
- printf ("req: message from (net %d, eid %d) type %d len %zd: 0x%02x.. \n" ,
108
+ printf ("req: message from (net %d, eid %d) type 0x%x len %zd\n" ,
102
109
addr .smctp_base .smctp_network , addr .smctp_base .smctp_addr .s_addr ,
103
110
addr .smctp_base .smctp_type ,
104
- len ,
105
- rxbuf [0 ]);
111
+ len );
106
112
if (addrlen == sizeof (struct sockaddr_mctp_ext )) {
107
113
printf (" ext ifindex %d ha[0]=0x%02x len %hhu\n" ,
108
114
addr .smctp_ifindex ,
109
115
addr .smctp_haddr [0 ], addr .smctp_halen );
110
116
}
111
117
118
+ if (memcmp (buf , VENDOR_TYPE_ECHO , sizeof (VENDOR_TYPE_ECHO )) != 0 ) {
119
+ errx (EXIT_FAILURE , "unexpected vendor ID" );
120
+ }
121
+
112
122
for (i = 0 ; i < len ; i ++ ) {
113
123
uint8_t exp = data ? data [i ] : i & 0xff ;
114
- if (rxbuf [i ] != exp )
124
+ if (payload [i ] != exp )
115
125
errx (EXIT_FAILURE ,
116
126
"payload mismatch at byte 0x%zx; "
117
127
"sent 0x%02x, received 0x%02x" ,
118
- i , exp , rxbuf [i ]);
128
+ i , exp , buf [i ]);
119
129
}
120
130
121
131
return 0 ;
0 commit comments