1 /* 2 * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * Redistribution of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 11 * Redistribution in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 15 * Neither the name of Sun Microsystems, Inc. or the names of 16 * contributors may be used to endorse or promote products derived 17 * from this software without specific prior written permission. 18 * 19 * This software is provided "AS IS," without a warranty of any kind. 20 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, 21 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A 22 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. 23 * SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE 24 * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING 25 * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL 26 * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, 27 * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR 28 * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF 29 * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, 30 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 31 */ 32 33 #include <stdio.h> 34 #include <fcntl.h> 35 #include <unistd.h> 36 #include <sys/ioctl.h> 37 #include <errno.h> 38 #include <stdlib.h> 39 #include <string.h> 40 #include <sys/types.h> 41 #include <sys/stat.h> 42 43 #include <ipmitool/ipmi.h> 44 #include <ipmitool/ipmi_intf.h> 45 #include <ipmitool/helper.h> 46 47 #include "imbapi.h" 48 49 #define IPMI_IMB_TIMEOUT (1000 * 1000) 50 #define IPMI_IMB_MAX_RETRY 3 51 #define IPMI_IMB_DEV "/dev/imb" 52 #define IPMI_IMB_BUF_SIZE 64 53 54 extern int verbose; 55 56 static int ipmi_imb_open(struct ipmi_intf * intf) 57 { 58 struct stat stbuf; 59 60 if (stat(IPMI_IMB_DEV, &stbuf) < 0) { 61 printf("Error: no IMB driver found at %s!\n", IPMI_IMB_DEV); 62 return -1; 63 } 64 65 intf->opened = 1; 66 intf->manufacturer_id = ipmi_get_oem(intf); 67 68 return 0; 69 } 70 71 static void ipmi_imb_close(struct ipmi_intf * intf) 72 { 73 intf->opened = 0; 74 intf->manufacturer_id = IPMI_OEM_UNKNOWN; 75 } 76 77 static struct ipmi_rs * ipmi_imb_send_cmd(struct ipmi_intf * intf, struct ipmi_rq * req) 78 { 79 IMBPREQUESTDATA imbreq; 80 static struct ipmi_rs rsp; 81 int status, i; 82 unsigned char ccode; 83 84 imbreq.rsSa = IPMI_BMC_SLAVE_ADDR; 85 imbreq.rsLun = 0; 86 imbreq.busType = 0; 87 imbreq.netFn = req->msg.netfn; 88 imbreq.cmdType = req->msg.cmd; 89 90 imbreq.data = req->msg.data; 91 imbreq.dataLength = req->msg.data_len; 92 93 if (verbose > 1) { 94 printf("IMB rsSa : %x\n", imbreq.rsSa); 95 printf("IMB netFn : %x\n", imbreq.netFn); 96 printf("IMB cmdType : %x\n", imbreq.cmdType); 97 printf("IMB dataLength : %d\n", imbreq.dataLength); 98 } 99 100 rsp.data_len = IPMI_IMB_BUF_SIZE; 101 memset(rsp.data, 0, rsp.data_len); 102 103 for (i=0; i<IPMI_IMB_MAX_RETRY; i++) { 104 if (verbose > 2) 105 printbuf(imbreq.data, imbreq.dataLength, "ipmi_imb request"); 106 status = SendTimedImbpRequest(&imbreq, IPMI_IMB_TIMEOUT, 107 rsp.data, &rsp.data_len, &ccode); 108 if (status == 0) { 109 if (verbose > 2) 110 printbuf(rsp.data, rsp.data_len, "ipmi_imb response"); 111 break; 112 } 113 /* error */ 114 printf("Error sending IMB request, status=%x ccode=%x\n", 115 status, ccode); 116 } 117 118 rsp.ccode = ccode; 119 120 return &rsp; 121 } 122 123 struct ipmi_intf ipmi_imb_intf = { 124 .name = "imb", 125 .desc = "Intel IMB Interface", 126 .open = ipmi_imb_open, 127 .close = ipmi_imb_close, 128 .sendrecv = ipmi_imb_send_cmd, 129 .target_addr = IPMI_BMC_SLAVE_ADDR, 130 }; 131 132