static int ipmi_lipmi_open(struct ipmi_intf * intf) { intf->fd = open(IPMI_LIPMI_DEV, O_RDWR); if (intf->fd < 0) { perror("Could not open lipmi device"); return -1; } intf->opened = 1; intf->manufacturer_id = ipmi_get_oem(intf); return intf->fd; }
static int ipmi_openipmi_open(struct ipmi_intf * intf) { int i = 0; char ipmi_dev[16]; char ipmi_devfs[16]; char ipmi_devfs2[16]; int devnum = 0; devnum = intf->devnum; sprintf(ipmi_dev, "/dev/ipmi%d", devnum); sprintf(ipmi_devfs, "/dev/ipmi/%d", devnum); sprintf(ipmi_devfs2, "/dev/ipmidev/%d", devnum); lprintf(LOG_DEBUG, "Using ipmi device %d", devnum); intf->fd = open(ipmi_dev, O_RDWR); if (intf->fd < 0) { intf->fd = open(ipmi_devfs, O_RDWR); if (intf->fd < 0) { intf->fd = open(ipmi_devfs2, O_RDWR); } if (intf->fd < 0) { lperror(LOG_ERR, "Could not open device at %s or %s or %s", ipmi_dev, ipmi_devfs , ipmi_devfs2); return -1; } } if (ioctl(intf->fd, IPMICTL_SET_GETS_EVENTS_CMD, &i) < 0) { lperror(LOG_ERR, "Could not enable event receiver"); return -1; } intf->opened = 1; /* This is never set to 0, the default is IPMI_BMC_SLAVE_ADDR */ if (intf->my_addr != 0) { if (intf->set_my_addr(intf, intf->my_addr) < 0) { lperror(LOG_ERR, "Could not set IPMB address"); return -1; } lprintf(LOG_DEBUG, "Set IPMB address to 0x%x", intf->my_addr ); } intf->manufacturer_id = ipmi_get_oem(intf); return intf->fd; }
static int ipmi_free_open(struct ipmi_intf * intf) { int kcs_ret = -1, ssif_ret = -1; if (getuid() != 0) { fprintf(stderr, "Permission denied, must be root\n"); return -1; } #if IPMI_INTF_FREE_0_3_0 if (!(dev = ipmi_open_inband (IPMI_DEVICE_KCS, 0, 0, 0, NULL, IPMI_FLAGS_DEFAULT))) { if (!(dev = ipmi_open_inband (IPMI_DEVICE_SSIF, 0, 0, 0, NULL, IPMI_FLAGS_DEFAULT))) { perror("ipmi_open_inband()"); goto cleanup; } } #elif IPMI_INTF_FREE_0_4_0 if (!(dev = ipmi_device_create())) { perror("ipmi_device_create"); goto cleanup; } if (ipmi_open_inband (dev, IPMI_DEVICE_KCS, 0, 0, 0, NULL, IPMI_FLAGS_DEFAULT) < 0) { if (ipmi_open_inband (dev, IPMI_DEVICE_SSIF, 0, 0, 0, NULL, IPMI_FLAGS_DEFAULT) < 0) { fprintf(stderr, "ipmi_open_inband(): %s\n", ipmi_device_strerror(ipmi_device_errnum(dev))); goto cleanup; } } #elif IPMI_INTF_FREE_0_5_0 if (!(dev = ipmi_device_create())) { perror("ipmi_device_create"); goto cleanup; } if (ipmi_open_inband (dev, IPMI_DEVICE_KCS, 0, 0, 0, NULL, 0, IPMI_FLAGS_DEFAULT) < 0) { if (ipmi_open_inband (dev, IPMI_DEVICE_SSIF, 0, 0, 0, NULL, 0, IPMI_FLAGS_DEFAULT) < 0) { fprintf(stderr, "ipmi_open_inband(): %s\n", ipmi_device_strerror(ipmi_device_errnum(dev))); goto cleanup; } } #elif IPMI_INTF_FREE_0_6_0 if (!(dev = ipmi_ctx_create())) { perror("ipmi_ctx_create"); goto cleanup; } if (ipmi_ctx_open_inband (dev, IPMI_DEVICE_KCS, 0, 0, 0, NULL, 0, IPMI_FLAGS_DEFAULT) < 0) { if (ipmi_ctx_open_inband (dev, IPMI_DEVICE_SSIF, 0, 0, 0, NULL, 0, IPMI_FLAGS_DEFAULT) < 0) { fprintf(stderr, "ipmi_open_inband(): %s\n", ipmi_ctx_strerror(ipmi_ctx_errnum(dev))); goto cleanup; } } #endif intf->opened = 1; intf->manufacturer_id = ipmi_get_oem(intf); return 0; cleanup: if (dev) { #if IPMI_INTF_FREE_0_3_0 ipmi_close_device(dev); #elif IPMI_INTF_FREE_0_4_0 || IPMI_INTF_FREE_0_5_0 ipmi_close_device(dev); ipmi_device_destroy(dev); #elif IPMI_INTF_FREE_0_6_0 ipmi_ctx_close(dev); ipmi_ctx_destroy(dev); #endif } return -1; }