From: Michael Gernoth Date: Sun, 22 Aug 2010 18:53:18 +0000 (+0200) Subject: decode packets X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/rsbs2/commitdiff_plain/20ef0f397c40ec362d25b6349b3e3383e80fc2af?hp=77ad1a84f7fa19a455a228d7b9679291e94550ea decode packets --- diff --git a/bmc/bmc.c b/bmc/bmc.c index 4a7f02f..4db28a6 100644 --- a/bmc/bmc.c +++ b/bmc/bmc.c @@ -6,15 +6,40 @@ #include "i2c.h" #include "bmc.h" -void decode_bmc_cmd(unsigned char *buf, int len) +uint8_t ipmb_csum(unsigned char *buf, int len) { + uint8_t csum = 0x00; int i; for(i = 0; i < len; i++) { - printf("0x%02x ", buf[i]); + csum += buf[i]; } + return -csum; +} + +void decode_bmc_cmd(unsigned char *buf, int len) +{ + int i; + + printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n"); + printf("Connection Header:\n"); + printf("\trs Slave Addr.: 0x%02x\n", buf[0]); + printf("\tnetFn: 0x%02x, LUN: 0x%02x\n", (buf[1]>>2)&0x3f, (buf[1] & 0x03)); + 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", buf[3]); + printf("\trqSeq: 0x%02x, rqLUN: 0x%02x\n", (buf[4]>>2)&0x3f, (buf[4] & 0x03)); + printf("\tcmd: 0x%02x\n", buf[5]); + printf("\tData: "); + for(i = 6; i < (len - 1); i++) { + printf("0x%02x ", buf[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"); } int main(void) diff --git a/bmc/bmc.h b/bmc/bmc.h new file mode 100644 index 0000000..99d5810 --- /dev/null +++ b/bmc/bmc.h @@ -0,0 +1 @@ +void decode_bmc_cmd(unsigned char *buf, int len); diff --git a/bmc/i2c.c b/bmc/i2c.c index 7104758..4ada02e 100644 --- a/bmc/i2c.c +++ b/bmc/i2c.c @@ -29,6 +29,8 @@ ISR (TWI_vect, ISR_BLOCK) printf("I2C: Slave 0x%02x adressed\n", TWDR); #endif pos = 0x00; + databuf[pos] = TWDR; + pos++; TWCR_ACK; break; @@ -50,13 +52,6 @@ ISR (TWI_vect, ISR_BLOCK) TWCR_RESET; break; - case TW_ST_SLA_ACK: - case TW_ST_DATA_ACK: - printf("I2C: Data requested\n"); - TWDR = 0x00; - TWCR_ACK; - break; - default: printf("I2C: Unimplemented status 0x%02x\n", TW_STATUS); TWCR_RESET;