+#include <stdio.h>
+
+#include "ipmb.h"
+
+uint8_t ipmb_csum(unsigned char *buf, int len)
+{
+ uint8_t csum = 0x00;
+ int i;
+
+ for(i = 0; i < len; i++) {
+ csum += buf[i];
+ }
+
+ return -csum;
+}
+
+void decode_ipmb_pkt(unsigned char *buf, int len)
+{
+ int i;
+ struct ipmb_req req;
+
+ req.rsSA = buf[0];
+ req.netFn = (buf[1]>>2)&0x3f;
+ req.rsLUN = (buf[1] & 0x03);
+ req.rqSA = buf[3];
+ req.rqSEQ = (buf[4]>>2)&0x3f;
+ req.rqLUN = (buf[4] & 0x03);
+ req.cmd = buf[5];
+ req.data = buf+6;
+ req.datalen = len - 6 - 1;
+
+ printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
+ printf("Connection Header:\n");
+ printf("\trs Slave Addr.: 0x%02x\n", req.rsSA);
+ printf("\tnetFn: 0x%02x, LUN: 0x%02x\n", req.netFn, req.rsLUN);
+ printf("\tChecksum: 0x%02x (%s)\n", buf[2],
+ (buf[2] == ipmb_csum(buf, 2)) ? "OK" : "Wrong");
+ printf("Data:\n");
+ printf("\trq Slave Addr.: 0x%02x\n", req.rqSA);
+ printf("\trqSeq: 0x%02x, rqLUN: 0x%02x\n", req.rqSEQ, req.rqLUN);
+ printf("\tcmd: 0x%02x\n", req.cmd);
+ printf("\tData: ");
+ for(i = 0; i < req.datalen; i++) {
+ printf("0x%02x ", req.data[i]);
+ }
+ printf("\n");
+ printf("\tChecksum: 0x%02x (%s)\n", buf[len-1],
+ (buf[len-1] == ipmb_csum(buf+3, len-4)) ? "OK" : "Wrong");
+ printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
+
+ if ((buf[2] != ipmb_csum(buf, 2)) ||
+ (buf[len-1] == ipmb_csum(buf+3, len-4)))
+ return; /* Checksum wrong */
+
+ //i2c_send((unsigned char*)"\x28\x00",1);
+}