Ejemplo n.º 1
0
int ipmi_rsp_mv(uchar cmd, uchar netfn, uchar lun, uchar sa, uchar bus,
		uchar *pdata, int sdata, char fdebugcmd)
{
    struct ipmi_req       req;
    // struct ipmi_recv      rsp;
    struct ipmi_lan_addr  lan_addr;
    // int    i, done;
    int    rv;

    rv = ipmi_open_mv(fdebugcmd);
    if (rv != 0) return(rv);

    if (rsp_addrlen > 0) {
        /* rsp_addr was previously saved in getevent_mv */
	req.addr = (char *)&rsp_addr;
	req.addr_len = rsp_addrlen;
    } else {  /* try some defaults */
	lan_addr.adrtype = IPMI_LAN_ADDR_TYPE;
	lan_addr.channel = bus;   /* usu lan_ch == 1 */
        lan_addr.privilege = 0x04;  /*admin*/
	lan_addr.session_handle = 0x01; /*may vary*/
	lan_addr.remote_SWID = sa; /*usu 0x81*/
	lan_addr.local_SWID = 0x81;
	lan_addr.lun = lun;
	req.addr = (char *) &lan_addr;
	req.addr_len = sizeof(lan_addr);
    }
    req.msg.cmd = cmd;
    req.msg.netfn = (netfn | 0x01);
    req.msgid = curr_seq;
    req.msg.data = pdata;
    req.msg.data_len = sdata;
    rv = ioctl(ipmi_fd, IPMICTL_SEND_COMMAND, &req);
    curr_seq++;
    if (rv == -1) { 
        if (fdebugcmd) dbgmsg("mv IPMICTL_SEND_COMMAND errno %d\n",errno);
	rv = errno; 
    }
    return(rv);
}
Ejemplo n.º 2
0
int ipmicmd_mv(uchar cmd, uchar netfn, uchar lun, uchar *pdata, uchar sdata, 
		uchar *presp, int sresp, int *rlen)
{
    fd_set readfds;
    struct timeval tv;
    struct ipmi_recv      rsp;
    struct ipmi_addr      addr;
    struct ipmi_req                   req;
    struct ipmi_system_interface_addr bmc_addr;
    int    i;
    int    rv;

    rv = ipmi_open_mv();
    if (rv != 0) return(rv);

    i = 1;
    rv = ioctl(ipmi_fd, IPMICTL_SET_GETS_EVENTS_CMD, &i);
    if (rv) { return(errno); }

    FD_ZERO(&readfds);
    // FD_SET(0, &readfds);  /* dont watch stdin */
    FD_SET(ipmi_fd, &readfds);  /* only watch ipmi_fd for input */

    /* Send the IPMI command */ 
    bmc_addr.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
    bmc_addr.channel = IPMI_BMC_CHANNEL;
    bmc_addr.lun = lun;       // BMC_LUN = 0
    req.addr = (unsigned char *) &bmc_addr;
    req.addr_len = sizeof(bmc_addr);
    req.msg.cmd = cmd;
    req.msg.netfn = netfn;   
    req.msgid = curr_seq;
    req.msg.data = pdata;
    req.msg.data_len = sdata;
    rv = ioctl(ipmi_fd, IPMICTL_SEND_COMMAND, &req);
    curr_seq++;
    if (rv == -1) { rv = errno; }

    if (rv == 0) {
	tv.tv_sec=ipmi_timeout_mv;
	tv.tv_usec=0;
	rv = select(ipmi_fd+1, &readfds, NULL, NULL, &tv);
	/* expect select rv = 1 here */
	if (rv <= 0) { /* no data within 5 seconds */
	   if (fperr != NULL)
             fprintf(fperr,"drv select timeout, fd = %d, isset = %d, rv = %d, errno = %d\n",
		  ipmi_fd,FD_ISSET(ipmi_fd, &readfds),rv,errno);
	   if (rv == 0) rv = -3;
	   else rv = errno;
	} else {
	   /* receive the IPMI response */
	   rsp.addr = (unsigned char *) &addr;
	   rsp.addr_len = sizeof(addr);
	   rsp.msg.data = presp;
	   rsp.msg.data_len = sresp;
	   rv = ioctl(ipmi_fd, IPMICTL_RECEIVE_MSG_TRUNC, &rsp);
	   if (rv == -1) { 
	      if ((errno == EMSGSIZE) && (rsp.msg.data_len == sresp))
		 rv = 0;   /* errno 90 is ok */
	      else { 
		 rv = errno; 
		 if (fperr != NULL)
                   fprintf(fperr,"drv rcv_trunc errno = %d, len = %d\n",
			errno, rsp.msg.data_len);
	      }
	   } else rv = 0;
	   *rlen = rsp.msg.data_len;
	}
    }

    /* ipmi_close_mv();  * rely on the app calling ipmi_close */
    return(rv);
}
Ejemplo n.º 3
0
int ipmicmd_mv(uchar cmd, uchar netfn, uchar lun, uchar sa, uchar bus,
		uchar *pdata, int sdata, uchar *presp, int sresp, int *rlen)
{
    fd_set readfds;
    struct timeval tv;
    struct ipmi_req       req;
    struct ipmi_recv      rsp;
    struct ipmi_addr      addr;
    struct ipmi_ipmb_addr             ipmb_addr;
    struct ipmi_system_interface_addr bmc_addr;
    static int need_set_events = 1;
    int    i, done;
    int    rv;

    rv = ipmi_open_mv(fdebugmv);
    if (rv != 0) return(rv);

    if (need_set_events) {
	i = 1;
        rv = ioctl(ipmi_fd, IPMICTL_SET_GETS_EVENTS_CMD, &i);
	if (fdebugmv) 
	    dbgmsg("getevent_mv: set_gets_events rv=%d errno=%d, n=%d\n",
			rv,errno,i);
        if (rv) { return(errno); }
	need_set_events = 0;
    }

    FD_ZERO(&readfds);
    // FD_SET(0, &readfds);  /* dont watch stdin */
    FD_SET(ipmi_fd, &readfds);  /* only watch ipmi_fd for input */

    /* Special handling for ReadEventMsgBuffer, etc. */
#ifdef TEST_MSG
    recv.msg.data = data;
    recv.msg.data_len = sizeof(data);
    recv.addr = (unsigned char *) &addr;
    recv.addr_len = sizeof(addr);
    rv = ioctl(fd, IPMICTL_RECEIVE_MSG_TRUNC, &recv);
    if (rv == -1) {
        if (errno == EMSGSIZE) {
            /* The message was truncated, handle it as such. */
            data[0] = IPMI_REQUESTED_DATA_LENGTH_EXCEEDED_CC;
            rv = 0;
        } else
            goto out;
    }
#endif

    /* Send the IPMI command */ 
    if (sa == BMC_SA) {
	i = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
	bmc_addr.adrtype = i;
	bmc_addr.channel = IPMI_BMC_CHANNEL;
	bmc_addr.lun = lun;       /* usu BMC_LUN = 0 */
	req.addr = (char *) &bmc_addr;
	req.addr_len = sizeof(bmc_addr);
    } else {
	i = IPMI_IPMB_ADDR_TYPE;
	ipmb_addr.adrtype = i;
	ipmb_addr.channel = bus;   /* usu PUBLIC_BUS = 0 */
	ipmb_addr.slave_addr = sa;
	ipmb_addr.lun = lun;
	req.addr = (char *) &ipmb_addr;
	req.addr_len = sizeof(ipmb_addr);
    }
    if (fdebugmv) 
	dbgmsg("mv cmd=%02x netfn=%02x mc=%02x;%02x;%02x adrtype=%x\n",
			cmd,netfn,bus,sa,lun,i);
    req.msg.cmd = cmd;
    req.msg.netfn = netfn;   
    req.msgid = curr_seq;
    req.msg.data = pdata;
    req.msg.data_len = sdata;
    rv = ioctl(ipmi_fd, IPMICTL_SEND_COMMAND, &req);
    curr_seq++;
    if (rv == -1) { 
        if (fdebugmv) dbgmsg("mv IPMICTL_SEND_COMMAND errno %d\n",errno);
	rv = errno; 
	}

    if (netfn & 0x01) done = 1;  /*sending response only*/
    else done = 0;  /*normal request/response*/

    if (rv == 0) while (!done) {
        done = 1;
	tv.tv_sec=ipmi_timeout_mv;
	tv.tv_usec=0;
	rv = select(ipmi_fd+1, &readfds, NULL, NULL, &tv);
	/* expect select rv = 1 here */
	if (rv <= 0) { /* no data within 5 seconds */
	   if (fdebugmv) 
              fprintf(fperr,"mv select timeout, fd = %d, isset = %d, rv = %d, errno = %d\n",
		  ipmi_fd,FD_ISSET(ipmi_fd, &readfds),rv,errno);
	   if (rv == 0) rv = -3;
	   else rv = errno;
	} else {
	   /* receive the IPMI response */
	   rsp.addr = (char *) &addr;
	   rsp.addr_len = sizeof(addr);
	   rsp.msg.data = presp;
	   rsp.msg.data_len = sresp;
	   rv = ioctl(ipmi_fd, IPMICTL_RECEIVE_MSG_TRUNC, &rsp);
	   if (rv == -1) { 
	      if ((errno == EMSGSIZE) && (rsp.msg.data_len == sresp))
		 rv = 0;   /* errno 90 is ok */
	      else { 
		 rv = errno; 
                 fprintf(fperr,"mv rcv_trunc errno = %d, len = %d\n",
			errno, rsp.msg.data_len);
	      }
	   } else rv = 0;
	   /* Driver should ensure matching req.msgid and rsp.msgid */
           /* Skip & retry if async events, only listen for those in 
            * getevent_mv() below. */
           // if (rsp.recv_type == IPMI_ASYNC_EVENT_RECV_TYPE) 
	   if (rsp.recv_type != IPMI_RESPONSE_RECV_TYPE) {
		if (fdebugmv)
		   dbgmsg("mv cmd=%02x netfn=%02x, got recv_type %d\n",
				cmd,netfn,rsp.recv_type);
	       done = 0;
	   }
	   *rlen = rsp.msg.data_len;
	}
    } /*endif send ok, while select/recv*/

    /* ipmi_close_mv();  * rely on the app calling ipmi_close */
    return(rv);
}