src/plugins/serial/serial_terminal.c
static int
serial_term_get_message(struct ipmi_intf * intf,
		struct serial_term_request_ctx * req_ctx,
		uint8_t * msg, size_t __UNUSED__(max_len))
{
	uint8_t data[IPMI_SERIAL_MAX_RESPONSE];
	struct serial_term_request_ctx tmp_ctx;
	struct ipmi_get_message_rp * rp = (struct ipmi_get_message_rp *) data;
	struct serial_term_hdr hdr;
	clock_t start, tm;
	int rv, netFn, rqSeq;

	start = clock();

	do {
		/* fill-in request context */
		tmp_ctx.netFn = 0x18;
		tmp_ctx.seq = serial_term_alloc_seq() << 2;
		tmp_ctx.cmd = 0x33;

		/* fill-in request data */
		hdr.netFn = tmp_ctx.netFn;
		hdr.seq = tmp_ctx.seq;
		hdr.cmd = tmp_ctx.cmd;

		/* send request */
		serial_flush(intf);
		serial_term_send_msg(intf, (uint8_t *) &hdr, 3);

		/* wait for response */
		rv = serial_term_wait_response(intf, &tmp_ctx, data, sizeof (data));

		/* check for IO error or timeout */
		if (rv <= 0) {
			return rv;
		}

		netFn = (req_ctx->netFn & ~3)|(req_ctx->seq & 3)|4;
		rqSeq = req_ctx->seq & ~3;

		/* check completion code */
		if (rp->completion == 0) {
			/* check for the waited response */
			if (rp->netFn == netFn
					&& rp->rsSA == req_ctx->sa
					&& rp->rqSeq == rqSeq
					&& rp->cmd == req_ctx->cmd) {
				/* copy the rest of message */
				memcpy(msg, rp + 1, rv - sizeof (*rp) - 1);
				return rv - sizeof (*rp) - 1;
			}
		} else if (rp->completion != 0x80) {
			return 0;
		}

		tm = clock() - start;

		tm /= CLOCKS_PER_SEC;
	} while (tm < intf->ssn_params.timeout);

	return 0;
}
/*
 *	Get message from receive message queue
 *
 * Note: Kept max_len in case it's useful later.
 */
Get message from receive message queue
Note: Kept max_len in case it's useful later.
Get message from receive message queue Note : Kept max_len in case it ' s useful later .
static int
serial_term_get_message(struct ipmi_intf * intf,
		struct serial_term_request_ctx * req_ctx,
		uint8_t * msg, size_t __UNUSED__(max_len))
{
	uint8_t data[IPMI_SERIAL_MAX_RESPONSE];
	struct serial_term_request_ctx tmp_ctx;
	struct ipmi_get_message_rp * rp = (struct ipmi_get_message_rp *) data;
	struct serial_term_hdr hdr;
	clock_t start, tm;
	int rv, netFn, rqSeq;
	start = clock();
	do {
		tmp_ctx.netFn = 0x18;
		tmp_ctx.seq = serial_term_alloc_seq() << 2;
		tmp_ctx.cmd = 0x33;
		hdr.netFn = tmp_ctx.netFn;
		hdr.seq = tmp_ctx.seq;
		hdr.cmd = tmp_ctx.cmd;
		serial_flush(intf);
		serial_term_send_msg(intf, (uint8_t *) &hdr, 3);
		rv = serial_term_wait_response(intf, &tmp_ctx, data, sizeof (data));
		if (rv <= 0) {
			return rv;
		}
		netFn = (req_ctx->netFn & ~3)|(req_ctx->seq & 3)|4;
		rqSeq = req_ctx->seq & ~3;
		if (rp->completion == 0) {
			if (rp->netFn == netFn
					&& rp->rsSA == req_ctx->sa
					&& rp->rqSeq == rqSeq
					&& rp->cmd == req_ctx->cmd) {
				memcpy(msg, rp + 1, rv - sizeof (*rp) - 1);
				return rv - sizeof (*rp) - 1;
			}
		} else if (rp->completion != 0x80) {
			return 0;
		}
		tm = clock() - start;
		tm /= CLOCKS_PER_SEC;
	} while (tm < intf->ssn_params.timeout);
	return 0;
}
static int serial_term_get_message ( struct ipmi_intf * intf , struct serial_term_request_ctx * req_ctx , uint8_t * msg , size_t __UNUSED__ ( max_len ) ) { uint8_t data [ IPMI_SERIAL_MAX_RESPONSE ] ; struct serial_term_request_ctx tmp_ctx ; struct ipmi_get_message_rp * rp = ( struct ipmi_get_message_rp * ) data ; struct serial_term_hdr hdr ; clock_t start , tm ; int rv , netFn , rqSeq ; start = clock ( ) ; do { tmp_ctx . netFn = 0x18 ; tmp_ctx . seq = serial_term_alloc_seq ( ) << 2 ; tmp_ctx . cmd = 0x33 ; hdr . netFn = tmp_ctx . netFn ; hdr . seq = tmp_ctx . seq ; hdr . cmd = tmp_ctx . cmd ; serial_flush ( intf ) ; serial_term_send_msg ( intf , ( uint8_t * ) & hdr , 3 ) ; rv = serial_term_wait_response ( intf , & tmp_ctx , data , sizeof ( data ) ) ; if ( rv <= 0 ) { return rv ; } netFn = ( req_ctx -> netFn & ~ 3 ) | ( req_ctx -> seq & 3 ) | 4 ; rqSeq = req_ctx -> seq & ~ 3 ; if ( rp -> completion == 0 ) { if ( rp -> netFn == netFn && rp -> rsSA == req_ctx -> sa && rp -> rqSeq == rqSeq && rp -> cmd == req_ctx -> cmd ) { memcpy ( msg , rp + 1 , rv - sizeof ( * rp ) - 1 ) ; return rv - sizeof ( * rp ) - 1 ; } } else if ( rp -> completion != 0x80 ) { return 0 ; } tm = clock ( ) - start ; tm /= CLOCKS_PER_SEC ; } while ( tm < intf -> ssn_params . timeout ) ; return 0 ; }
Get message from receive message queue
 Note: Kept max_len in case it's useful later.
Get message from receive message queue Note : Kept max_len in case it ' s useful later .
/* fill-in request context */ /* fill-in request data */ /* send request */ /* wait for response */ /* check for IO error or timeout */ /* check completion code */ /* check for the waited response */ /* copy the rest of message */