]> cvs.zerfleddert.de Git - rsbs2/blame - bmc/ipmb.c
I2C master mode implemented and more decoding
[rsbs2] / bmc / ipmb.c
CommitLineData
d5193055
MG
1#include <stdio.h>
2
3#include "ipmb.h"
4
5uint8_t ipmb_csum(unsigned char *buf, int len)
6{
7 uint8_t csum = 0x00;
8 int i;
9
10 for(i = 0; i < len; i++) {
11 csum += buf[i];
12 }
13
14 return -csum;
15}
16
17void decode_ipmb_pkt(unsigned char *buf, int len)
18{
19 int i;
20 struct ipmb_req req;
21
22 req.rsSA = buf[0];
23 req.netFn = (buf[1]>>2)&0x3f;
24 req.rsLUN = (buf[1] & 0x03);
25 req.rqSA = buf[3];
26 req.rqSEQ = (buf[4]>>2)&0x3f;
27 req.rqLUN = (buf[4] & 0x03);
28 req.cmd = buf[5];
29 req.data = buf+6;
30 req.datalen = len - 6 - 1;
31
32 printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
33 printf("Connection Header:\n");
34 printf("\trs Slave Addr.: 0x%02x\n", req.rsSA);
35 printf("\tnetFn: 0x%02x, LUN: 0x%02x\n", req.netFn, req.rsLUN);
36 printf("\tChecksum: 0x%02x (%s)\n", buf[2],
37 (buf[2] == ipmb_csum(buf, 2)) ? "OK" : "Wrong");
38 printf("Data:\n");
39 printf("\trq Slave Addr.: 0x%02x\n", req.rqSA);
40 printf("\trqSeq: 0x%02x, rqLUN: 0x%02x\n", req.rqSEQ, req.rqLUN);
41 printf("\tcmd: 0x%02x\n", req.cmd);
42 printf("\tData: ");
43 for(i = 0; i < req.datalen; i++) {
44 printf("0x%02x ", req.data[i]);
45 }
46 printf("\n");
47 printf("\tChecksum: 0x%02x (%s)\n", buf[len-1],
48 (buf[len-1] == ipmb_csum(buf+3, len-4)) ? "OK" : "Wrong");
49 printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
50
51 if ((buf[2] != ipmb_csum(buf, 2)) ||
52 (buf[len-1] == ipmb_csum(buf+3, len-4)))
53 return; /* Checksum wrong */
54
55 //i2c_send((unsigned char*)"\x28\x00",1);
56}
Impressum, Datenschutz