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
:
124 printf("Unknown sensor cmd 0x%02x\n", req
->cmd
);
134 case IPMB_APP_GET_DEVICE_ID
:
135 resp
.data
= get_devid
;
136 resp
.datalen
= sizeof(get_devid
);
140 case IPMB_APP_GET_WATCHDOG_TIMER
:
141 resp
.data
= get_wd_timer
;
142 resp
.datalen
= sizeof(get_wd_timer
);
148 printf("Unknown app cmd 0x%02x\n", req
->cmd
);
156 case IPMB_NETFN_STORAGE
:
160 printf("Unknown storage cmd 0x%02x\n", req
->cmd
);
170 printf("Unknown netFn 0x%02x\n", req
->netFn
);
178 void decode_ipmb_pkt(unsigned char *buf
, int len
)
182 if ((buf
[2] != ipmb_csum(buf
, 2)) ||
183 (buf
[len
-1] != ipmb_csum(buf
+3, len
-4)))
184 return; /* Checksum wrong */
187 req
.netFn
= (buf
[1]>>2)&0x3f;
188 req
.rsLUN
= (buf
[1] & 0x03);
190 req
.rqSEQ
= (buf
[4]>>2)&0x3f;
191 req
.rqLUN
= (buf
[4] & 0x03);
194 req
.datalen
= len
- 6 - 1;