lib/sg_cmds_extra.c
int
sg_ll_send_diag(int sg_fd, int sf_code, int pf_bit, int sf_bit, int devofl_bit,
                int unitofl_bit, int long_duration, void * paramp,
                int param_len, int noisy, int verbose)
{
    int k, res, ret, sense_cat, tmout;
    unsigned char senddiagCmdBlk[SEND_DIAGNOSTIC_CMDLEN] =
        {SEND_DIAGNOSTIC_CMD, 0, 0, 0, 0, 0};
    unsigned char sense_b[SENSE_BUFF_LEN];
    struct sg_pt_base * ptvp;

    senddiagCmdBlk[1] = (unsigned char)((sf_code << 5) | (pf_bit << 4) |
                        (sf_bit << 2) | (devofl_bit << 1) | unitofl_bit);
    senddiagCmdBlk[3] = (unsigned char)((param_len >> 8) & 0xff);
    senddiagCmdBlk[4] = (unsigned char)(param_len & 0xff);

    if (verbose) {
        pr2ws("    Send diagnostic cmd: ");
        for (k = 0; k < SEND_DIAGNOSTIC_CMDLEN; ++k)
            pr2ws("%02x ", senddiagCmdBlk[k]);
        pr2ws("\n");
        if ((verbose > 1) && paramp && param_len) {
            pr2ws("    Send diagnostic parameter list:\n");
            dStrHexErr((const char *)paramp, param_len, -1);
        }
    }
    if (long_duration > LONG_PT_TIMEOUT)
        tmout = long_duration;
    else
        tmout = long_duration ? LONG_PT_TIMEOUT : DEF_PT_TIMEOUT;

    ptvp = construct_scsi_pt_obj();
    if (NULL == ptvp) {
        pr2ws("send diagnostic: out of memory\n");
        return -1;
    }
    set_scsi_pt_cdb(ptvp, senddiagCmdBlk, sizeof(senddiagCmdBlk));
    set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
    set_scsi_pt_data_out(ptvp, (unsigned char *)paramp, param_len);
    res = do_scsi_pt(ptvp, sg_fd, tmout, verbose);
    ret = sg_cmds_process_resp(ptvp, "send diagnostic", res, 0, sense_b,
                               noisy, verbose, &sense_cat);
    if (-1 == ret)
        ;
    else if (-2 == ret) {
        switch (sense_cat) {
        case SG_LIB_CAT_RECOVERED:
        case SG_LIB_CAT_NO_SENSE:
            ret = 0;
            break;
        default:
            ret = sense_cat;
            break;
        }
    } else
        ret = 0;

    destruct_scsi_pt_obj(ptvp);
    return ret;
}
/* Invokes a SCSI SEND DIAGNOSTIC command. Foreground, extended self tests can
 * take a long time, if so set long_duration flag in which case the timout
 * is set to 7200 seconds; if the value of long_duration is > 7200 then that
 * value is taken as the timeout value in seconds. Return of 0 -> success,
 * various SG_LIB_CAT_* positive values or -1 -> other errors */
Invokes a SCSI SEND DIAGNOSTIC command. Foreground, extended self tests can
take a long time, if so set long_duration flag in which case the timout
is set to 7200 seconds; if the value of long_duration is > 7200 then that
value is taken as the timeout value in seconds. Return of 0 -> success,
various SG_LIB_CAT_* positive values or -1 -> other errors
Invokes a SCSI SEND DIAGNOSTIC command . Foreground extended self tests can take a long time if so set long_duration flag in which case the timout is set to 7200 seconds ; if the value of long_duration is > 7200 then that value is taken as the timeout value in seconds . Return of 0 - > success various SG_LIB_CAT_ * positive values or - 1 - > other errors
int
sg_ll_send_diag(int sg_fd, int sf_code, int pf_bit, int sf_bit, int devofl_bit,
                int unitofl_bit, int long_duration, void * paramp,
                int param_len, int noisy, int verbose)
{
    int k, res, ret, sense_cat, tmout;
    unsigned char senddiagCmdBlk[SEND_DIAGNOSTIC_CMDLEN] =
        {SEND_DIAGNOSTIC_CMD, 0, 0, 0, 0, 0};
    unsigned char sense_b[SENSE_BUFF_LEN];
    struct sg_pt_base * ptvp;
    senddiagCmdBlk[1] = (unsigned char)((sf_code << 5) | (pf_bit << 4) |
                        (sf_bit << 2) | (devofl_bit << 1) | unitofl_bit);
    senddiagCmdBlk[3] = (unsigned char)((param_len >> 8) & 0xff);
    senddiagCmdBlk[4] = (unsigned char)(param_len & 0xff);
    if (verbose) {
        pr2ws("    Send diagnostic cmd: ");
        for (k = 0; k < SEND_DIAGNOSTIC_CMDLEN; ++k)
            pr2ws("%02x ", senddiagCmdBlk[k]);
        pr2ws("\n");
        if ((verbose > 1) && paramp && param_len) {
            pr2ws("    Send diagnostic parameter list:\n");
            dStrHexErr((const char *)paramp, param_len, -1);
        }
    }
    if (long_duration > LONG_PT_TIMEOUT)
        tmout = long_duration;
    else
        tmout = long_duration ? LONG_PT_TIMEOUT : DEF_PT_TIMEOUT;
    ptvp = construct_scsi_pt_obj();
    if (NULL == ptvp) {
        pr2ws("send diagnostic: out of memory\n");
        return -1;
    }
    set_scsi_pt_cdb(ptvp, senddiagCmdBlk, sizeof(senddiagCmdBlk));
    set_scsi_pt_sense(ptvp, sense_b, sizeof(sense_b));
    set_scsi_pt_data_out(ptvp, (unsigned char *)paramp, param_len);
    res = do_scsi_pt(ptvp, sg_fd, tmout, verbose);
    ret = sg_cmds_process_resp(ptvp, "send diagnostic", res, 0, sense_b,
                               noisy, verbose, &sense_cat);
    if (-1 == ret)
        ;
    else if (-2 == ret) {
        switch (sense_cat) {
        case SG_LIB_CAT_RECOVERED:
        case SG_LIB_CAT_NO_SENSE:
            ret = 0;
            break;
        default:
            ret = sense_cat;
            break;
        }
    } else
        ret = 0;
    destruct_scsi_pt_obj(ptvp);
    return ret;
}
int sg_ll_send_diag ( int sg_fd , int sf_code , int pf_bit , int sf_bit , int devofl_bit , int unitofl_bit , int long_duration , void * paramp , int param_len , int noisy , int verbose ) { int k , res , ret , sense_cat , tmout ; unsigned char senddiagCmdBlk [ SEND_DIAGNOSTIC_CMDLEN ] = { SEND_DIAGNOSTIC_CMD , 0 , 0 , 0 , 0 , 0 } ; unsigned char sense_b [ SENSE_BUFF_LEN ] ; struct sg_pt_base * ptvp ; senddiagCmdBlk [ 1 ] = ( unsigned char ) ( ( sf_code << 5 ) | ( pf_bit << 4 ) | ( sf_bit << 2 ) | ( devofl_bit << 1 ) | unitofl_bit ) ; senddiagCmdBlk [ 3 ] = ( unsigned char ) ( ( param_len >> 8 ) & 0xff ) ; senddiagCmdBlk [ 4 ] = ( unsigned char ) ( param_len & 0xff ) ; if ( verbose ) { pr2ws ( " " ) ; for ( k = 0 ; k < SEND_DIAGNOSTIC_CMDLEN ; ++ k ) pr2ws ( " " , senddiagCmdBlk [ k ] ) ; pr2ws ( " \n " ) ; if ( ( verbose > 1 ) && paramp && param_len ) { pr2ws ( " \n " ) ; dStrHexErr ( ( const char * ) paramp , param_len , -1 ) ; } } if ( long_duration > LONG_PT_TIMEOUT ) tmout = long_duration ; else tmout = long_duration ? LONG_PT_TIMEOUT : DEF_PT_TIMEOUT ; ptvp = construct_scsi_pt_obj ( ) ; if ( NULL == ptvp ) { pr2ws ( " \n " ) ; return -1 ; } set_scsi_pt_cdb ( ptvp , senddiagCmdBlk , sizeof ( senddiagCmdBlk ) ) ; set_scsi_pt_sense ( ptvp , sense_b , sizeof ( sense_b ) ) ; set_scsi_pt_data_out ( ptvp , ( unsigned char * ) paramp , param_len ) ; res = do_scsi_pt ( ptvp , sg_fd , tmout , verbose ) ; ret = sg_cmds_process_resp ( ptvp , " " , res , 0 , sense_b , noisy , verbose , & sense_cat ) ; if ( -1 == ret ) ; else if ( -2 == ret ) { switch ( sense_cat ) { case SG_LIB_CAT_RECOVERED : case SG_LIB_CAT_NO_SENSE : ret = 0 ; break ; default : ret = sense_cat ; break ; } } else ret = 0 ; destruct_scsi_pt_obj ( ptvp ) ; return ret ; }
Invokes a SCSI SEND DIAGNOSTIC command.
Invokes a SCSI SEND DIAGNOSTIC command .