8 uint8_t ipmb_csum(unsigned char *buf
, int len
)
13 for(i
= 0; i
< len
; i
++) {
20 void ipmb_send(struct ipmb_resp
*resp
)
22 unsigned char buf
[24];
29 buf
[1] = ((resp
->netFn
)<<2) | (resp
->rqLUN
& 0x3);
30 buf
[2] = ipmb_csum(buf
, 2);
32 buf
[4] = ((resp
->rqSEQ
)<<2) | (resp
->rsLUN
& 0x3);
34 memcpy(buf
+6, resp
->data
, resp
->datalen
);
35 len
= resp
->datalen
+ 7;
36 buf
[len
-1] = ipmb_csum(buf
+3, len
- 4);
40 for(i
= 0; i
< len
; i
++) {
41 printf("0x%02x ", buf
[i
]);
51 void ipmb_dump_req(struct ipmb_req
*req
)
55 printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
56 printf("Connection Header:\n");
57 printf("\trs Slave Addr.: 0x%02x\n", req
->rsSA
);
58 printf("\tnetFn: 0x%02x, LUN: 0x%02x\n", req
->netFn
, req
->rsLUN
);
60 printf("\trq Slave Addr.: 0x%02x\n", req
->rqSA
);
61 printf("\trqSeq: 0x%02x, rqLUN: 0x%02x\n", req
->rqSEQ
, req
->rqLUN
);
62 printf("\tcmd: 0x%02x\n", req
->cmd
);
64 for(i
= 0; i
< req
->datalen
; i
++) {
65 printf("0x%02x ", req
->data
[i
]);
68 printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
72 void ipmb_invalid(struct ipmb_resp
*resp
)
75 static unsigned char cmd_invalid
[] = {0xc2};
77 resp
->data
= cmd_invalid
;
78 resp
->datalen
= sizeof(cmd_invalid
);
83 void ipmb_cmd(struct ipmb_req
*req
)
85 struct ipmb_resp resp
;
86 static unsigned char get_devid
[] =
87 {IPMB_CC_NORMALLY
, 0x42, 0x42, 0x01, 0x01, 0x51, 0xff /* Add. Dev. Supp */, 0x00, 0x00, 0x00, 0x00, 0x00 };
88 static unsigned char get_wd_timer
[] =
89 {IPMB_CC_NORMALLY
, 0x42, 0x00, 0x00, 0x04, 0xff, 0xff, 0xfe, 0xfe};
90 static unsigned char cc_normal
[] =
93 resp
.rqSA
= req
->rqSA
;
94 resp
.netFn
= req
->netFn
+1;
95 resp
.rqLUN
= req
->rqLUN
;
96 resp
.rsSA
= req
->rsSA
;
97 resp
.rqSEQ
= req
->rqSEQ
;
98 resp
.rsLUN
= req
->rsLUN
;
101 switch (req
->netFn
) {
102 case IPMB_NETFN_CHASSIS
:
104 case IPMB_CHASSIS_CONTROL
:
105 chassis_control(*(req
->data
));
106 resp
.data
= cc_normal
;
107 resp
.datalen
= sizeof(cc_normal
);
112 printf("Unknown chassis cmd 0x%02x\n", req
->cmd
);
120 case IPMB_NETFN_SENSOR_EVENT
:
122 case IPMB_SE_PLATFORM_EVENT
:
124 * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
126 * rs Slave Addr.: 0x24
127 * netFn: 0x04, LUN: 0x00
129 * rq Slave Addr.: 0x28
130 * rqSeq: 0x03, rqLUN: 0x00
132 * Data: 0x03 0xc8 0x00 0x6f 0x61 0x8f 0x03
133 * <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
134 * data[0] - EvMRev: 0x03
135 * data[1] - Sensor Type: 0xc8
136 * data[2] - Sensor #: 0x00
137 * data[3] - Event Dir(1)|Event Type(7): 0x6f: 0x0|0x6f (assert, discrete)
138 * data[4] - Event Data: 0x61
139 * data[5] - Event Data: 0x8f
140 * data[6] - Event Data: 0x03
142 resp
.data
= cc_normal
;
143 resp
.datalen
= sizeof(cc_normal
);
150 printf("Unknown sensor cmd 0x%02x\n", req
->cmd
);
160 case IPMB_APP_GET_DEVICE_ID
:
161 resp
.data
= get_devid
;
162 resp
.datalen
= sizeof(get_devid
);
166 case IPMB_APP_GET_WATCHDOG_TIMER
:
167 resp
.data
= get_wd_timer
;
168 resp
.datalen
= sizeof(get_wd_timer
);
174 printf("Unknown app cmd 0x%02x\n", req
->cmd
);
182 case IPMB_NETFN_STORAGE
:
186 printf("Unknown storage cmd 0x%02x\n", req
->cmd
);
196 printf("Unknown netFn 0x%02x\n", req
->netFn
);
204 void decode_ipmb_pkt(unsigned char *buf
, int len
)
208 if ((buf
[2] != ipmb_csum(buf
, 2)) ||
209 (buf
[len
-1] != ipmb_csum(buf
+3, len
-4)))
210 return; /* Checksum wrong */
213 req
.netFn
= (buf
[1]>>2)&0x3f;
214 req
.rsLUN
= (buf
[1] & 0x03);
216 req
.rqSEQ
= (buf
[4]>>2)&0x3f;
217 req
.rqLUN
= (buf
[4] & 0x03);
220 req
.datalen
= len
- 6 - 1;