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
, unsigned char *data
, uint8_t datalen
)
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, data
, datalen
);
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
[] = {IPMB_CC_INVALID
};
77 ipmb_send(resp
, cmd_invalid
, sizeof(cmd_invalid
));
81 void ipmb_cmd(struct ipmb_req
*req
)
83 struct ipmb_resp resp
;
84 static unsigned char get_devid
[] =
85 {IPMB_CC_NORMALLY
, 0x42, 0x42, 0x01, 0x01, 0x51, 0xff /* Add. Dev. Supp */, 0x00, 0x00, 0x00, 0x00, 0x00 };
86 static unsigned char get_wd_timer
[] =
87 {IPMB_CC_NORMALLY
, 0x42, 0x00, 0x00, 0x04, 0xff, 0xff, 0xfe, 0xfe};
88 static unsigned char cc_normal
[] =
90 static unsigned char sel_info
[] =
91 {IPMB_CC_NORMALLY
, 0x51, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00};
92 static unsigned char sel_alloc_info
[] =
93 {IPMB_CC_NORMALLY
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
94 static unsigned char sel_entry
[] =
96 static unsigned char sel_timestamp
[] =
97 {IPMB_CC_NORMALLY
, 0x00, 0x00, 0x00, 0x00};
98 static unsigned char chassis_status
[] =
99 {IPMB_CC_NORMALLY
, 0x60, 0x10, 0x00, 0x00};
100 static unsigned char reserve_sdr
[] =
101 {IPMB_CC_NORMALLY
, 0x00, 0x00};
102 static unsigned char get_sdr
[] =
103 {IPMB_CC_NORMALLY
, 0xff, 0xff};
105 resp
.rqSA
= req
->rqSA
;
106 resp
.netFn
= req
->netFn
+1;
107 resp
.rqLUN
= req
->rqLUN
;
108 resp
.rsSA
= req
->rsSA
;
109 resp
.rqSEQ
= req
->rqSEQ
;
110 resp
.rsLUN
= req
->rsLUN
;
113 switch (req
->netFn
) {
114 case IPMB_NETFN_CHASSIS
:
116 case IPMB_CHASSIS_GET_STATUS
:
117 ipmb_send(&resp
, chassis_status
, sizeof(chassis_status
));
119 case IPMB_CHASSIS_CONTROL
:
120 chassis_control(*(req
->data
));
121 ipmb_send(&resp
, cc_normal
, sizeof(cc_normal
));
125 printf("Unknown chassis cmd 0x%02x\n", req
->cmd
);
133 case IPMB_NETFN_SENSOR_EVENT
:
135 case IPMB_SE_PLATFORM_EVENT
:
137 * >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
139 * rs Slave Addr.: 0x24
140 * netFn: 0x04, LUN: 0x00
142 * rq Slave Addr.: 0x28
143 * rqSeq: 0x03, rqLUN: 0x00
145 * Data: 0x03 0xc8 0x00 0x6f 0x61 0x8f 0x03
146 * <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
147 * data[0] - EvMRev: 0x03
148 * data[1] - Sensor Type: 0xc8
149 * data[2] - Sensor #: 0x00
150 * data[3] - Event Dir(1)|Event Type(7): 0x6f: 0x0|0x6f (assert, discrete)
151 * data[4] - Event Data: 0x61
152 * data[5] - Event Data: 0x8f
153 * data[6] - Event Data: 0x03
155 ipmb_send(&resp
, cc_normal
, sizeof(cc_normal
));
161 printf("Unknown sensor cmd 0x%02x\n", req
->cmd
);
171 case IPMB_APP_GET_DEVICE_ID
:
172 ipmb_send(&resp
, get_devid
, sizeof(get_devid
));
175 case IPMB_APP_GET_WATCHDOG_TIMER
:
176 ipmb_send(&resp
, get_wd_timer
, sizeof(get_wd_timer
));
181 printf("Unknown app cmd 0x%02x\n", req
->cmd
);
189 case IPMB_NETFN_STORAGE
:
191 case IPMB_STORAGE_RESERVE_SDR
:
192 ipmb_send(&resp
, reserve_sdr
, sizeof(reserve_sdr
));
194 case IPMB_STORAGE_GET_SDR
:
195 ipmb_send(&resp
, get_sdr
, sizeof(get_sdr
));
197 case IPMB_STORAGE_GET_SEL_INFO
:
198 ipmb_send(&resp
, sel_info
, sizeof(sel_info
));
200 case IPMB_STORAGE_GET_SEL_ALLOCATION
:
201 ipmb_send(&resp
, sel_alloc_info
, sizeof(sel_alloc_info
));
203 case IPMB_STORAGE_GET_SEL_ENTRY
:
204 ipmb_send(&resp
, sel_entry
, sizeof(sel_entry
));
206 case IPMB_STORAGE_GET_SEL_TIME
:
207 ipmb_send(&resp
, sel_timestamp
, sizeof(sel_timestamp
));
211 printf("Unknown storage cmd 0x%02x\n", req
->cmd
);
221 printf("Unknown netFn 0x%02x\n", req
->netFn
);
229 void decode_ipmb_pkt(unsigned char *buf
, int len
)
233 if ((buf
[2] != ipmb_csum(buf
, 2)) ||
234 (buf
[len
-1] != ipmb_csum(buf
+3, len
-4)))
235 return; /* Checksum wrong */
238 req
.netFn
= (buf
[1]>>2)&0x3f;
239 req
.rsLUN
= (buf
[1] & 0x03);
241 req
.rqSEQ
= (buf
[4]>>2)&0x3f;
242 req
.rqLUN
= (buf
[4] & 0x03);
245 req
.datalen
= len
- 6 - 1;