FreeBSD/sys/cam/scsi/smp_all.c
/*
 * Decode a SMP request buffer into a string of hexadecimal numbers.
 *
 * smp_request:    SMP request
 * request_len:    length of the SMP request buffer, may be reduced if the
 *                 caller only wants part of the buffer printed
 * sb:             sbuf(9) buffer
 * line_prefix:    prefix for new lines, or an empty string ("")
 * first_line_len: length left on first line
 * line_len:       total length of subsequent lines, 0 for no additional lines
 *                 if there are no additional lines, first line will get ...
 *                 at the end if there is additional data
 */
Decode a SMP request buffer into a string of hexadecimal numbers.
Decode a SMP request buffer into a string of hexadecimal numbers .
void
smp_command_decode(uint8_t *smp_request, int request_len, struct sbuf *sb,
		   char *line_prefix, int first_line_len, int line_len)
{
	int i, cur_len;
	for (i = 0, cur_len = first_line_len; i < request_len; i++) {
		if ((cur_len < 6)
		 && (line_len < (strlen(line_prefix) + 3))) {
			sbuf_printf(sb, "...");
			return;
		}
		if (cur_len < 3) {
			sbuf_printf(sb, "\n%s", line_prefix);
			cur_len = line_len - strlen(line_prefix);
		}
		sbuf_printf(sb, "%02x ", smp_request[i]);
		cur_len = cur_len - 3;
	}
}
void smp_command_decode ( uint8_t * smp_request , int request_len , struct sbuf * sb , char * line_prefix , int first_line_len , int line_len ) { int i , cur_len ; for ( i = 0 , cur_len = first_line_len ; i < request_len ; i ++ ) { if ( ( cur_len < 6 ) && ( line_len < ( strlen ( line_prefix ) + 3 ) ) ) { sbuf_printf ( sb , " " ) ; return ; } if ( cur_len < 3 ) { sbuf_printf ( sb , " \n " , line_prefix ) ; cur_len = line_len - strlen ( line_prefix ) ; } sbuf_printf ( sb , " " , smp_request [ i ] ) ; cur_len = cur_len - 3 ; } }
Decode a SMP request buffer into a string of hexadecimal numbers.
Decode a SMP request buffer into a string of hexadecimal numbers .
/*
		 * Each byte takes 3 characters.  As soon as we go less
		 * than 6 (meaning we have at least 3 and at most 5
		 * characters left), check to see whether the subsequent
		 * line length (line_len) is long enough to bother with.
		 * If the user set it to 0, or some other length that isn't
		 * enough to hold at least the prefix and one byte, put ...
		 * on the first line to indicate that there is more data
		 * and bail out.
		 */