USB MSC BOT: Move CBW and CSW dissection to functions
Move CBW and CSW dissection to separate functions to make it possible to reuse the CBW/CSW dissecting code later. No functional changes.
This commit is contained in:
parent
9fca1acb40
commit
cd14ebf2df
|
@ -164,6 +164,135 @@ dissect_usbms_bot_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_
|
|||
return tvb_captured_length(tvb);
|
||||
}
|
||||
|
||||
static int
|
||||
dissect_usbms_bot_cbw(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, proto_tree *tree, usbms_bot_conv_info_t *usbms_bot_conv_info)
|
||||
{
|
||||
tvbuff_t *cdb_tvb;
|
||||
int offset=0;
|
||||
int cdbrlen, cdblen;
|
||||
guint8 lun, flags;
|
||||
guint32 datalen;
|
||||
itl_nexus_t *itl;
|
||||
itlq_nexus_t *itlq;
|
||||
|
||||
/* dCBWSignature */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCBWSignature, tvb, offset, 4, ENC_LITTLE_ENDIAN);
|
||||
offset+=4;
|
||||
|
||||
/* dCBWTag */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCBWTag, tvb, offset, 4, ENC_LITTLE_ENDIAN);
|
||||
offset+=4;
|
||||
|
||||
/* dCBWDataTransferLength */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCBWDataTransferLength, tvb, offset, 4, ENC_LITTLE_ENDIAN);
|
||||
datalen=tvb_get_letohl(tvb, offset);
|
||||
offset+=4;
|
||||
|
||||
/* dCBWFlags */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCBWFlags, tvb, offset, 1, ENC_LITTLE_ENDIAN);
|
||||
flags=tvb_get_guint8(tvb, offset);
|
||||
offset+=1;
|
||||
|
||||
/* dCBWLUN */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCBWTarget, tvb, offset, 1, ENC_LITTLE_ENDIAN);
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCBWLUN, tvb, offset, 1, ENC_LITTLE_ENDIAN);
|
||||
lun=tvb_get_guint8(tvb, offset)&0x0f;
|
||||
offset+=1;
|
||||
|
||||
/* make sure we have a ITL structure for this LUN */
|
||||
itl=(itl_nexus_t *)wmem_tree_lookup32(usbms_bot_conv_info->itl, lun);
|
||||
if(!itl){
|
||||
itl=wmem_new(wmem_file_scope(), itl_nexus_t);
|
||||
itl->cmdset=0xff;
|
||||
itl->conversation=NULL;
|
||||
wmem_tree_insert32(usbms_bot_conv_info->itl, lun, itl);
|
||||
}
|
||||
|
||||
/* make sure we have an ITLQ structure for this LUN/transaction */
|
||||
itlq=(itlq_nexus_t *)wmem_tree_lookup32(usbms_bot_conv_info->itlq, pinfo->num);
|
||||
if(!itlq){
|
||||
itlq=wmem_new(wmem_file_scope(), itlq_nexus_t);
|
||||
itlq->lun=lun;
|
||||
itlq->scsi_opcode=0xffff;
|
||||
itlq->task_flags=0;
|
||||
if(datalen){
|
||||
if(flags&0x80){
|
||||
itlq->task_flags|=SCSI_DATA_READ;
|
||||
} else {
|
||||
itlq->task_flags|=SCSI_DATA_WRITE;
|
||||
}
|
||||
}
|
||||
itlq->data_length=datalen;
|
||||
itlq->bidir_data_length=0;
|
||||
itlq->fc_time=pinfo->abs_ts;
|
||||
itlq->first_exchange_frame=pinfo->num;
|
||||
itlq->last_exchange_frame=0;
|
||||
itlq->flags=0;
|
||||
itlq->alloc_len=0;
|
||||
itlq->extra_data=NULL;
|
||||
wmem_tree_insert32(usbms_bot_conv_info->itlq, pinfo->num, itlq);
|
||||
}
|
||||
|
||||
/* dCBWCBLength */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCBWCBLength, tvb, offset, 1, ENC_LITTLE_ENDIAN);
|
||||
cdbrlen=tvb_get_guint8(tvb, offset)&0x1f;
|
||||
offset+=1;
|
||||
|
||||
cdblen=cdbrlen;
|
||||
if(cdblen>tvb_captured_length_remaining(tvb, offset)){
|
||||
cdblen=tvb_captured_length_remaining(tvb, offset);
|
||||
}
|
||||
if(cdblen){
|
||||
cdb_tvb=tvb_new_subset_length_caplen(tvb, offset, cdblen, cdbrlen);
|
||||
dissect_scsi_cdb(cdb_tvb, pinfo, parent_tree, SCSI_DEV_UNKNOWN, itlq, itl);
|
||||
}
|
||||
return tvb_captured_length(tvb);
|
||||
}
|
||||
|
||||
static int
|
||||
dissect_usbms_bot_csw(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, proto_tree *tree, usbms_bot_conv_info_t *usbms_bot_conv_info)
|
||||
{
|
||||
int offset=0;
|
||||
guint8 status;
|
||||
itl_nexus_t *itl;
|
||||
itlq_nexus_t *itlq;
|
||||
|
||||
/* dCSWSignature */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCSWSignature, tvb, offset, 4, ENC_LITTLE_ENDIAN);
|
||||
offset+=4;
|
||||
|
||||
/* dCSWTag */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCBWTag, tvb, offset, 4, ENC_LITTLE_ENDIAN);
|
||||
offset+=4;
|
||||
|
||||
/* dCSWDataResidue */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCSWDataResidue, tvb, offset, 4, ENC_LITTLE_ENDIAN);
|
||||
offset+=4;
|
||||
|
||||
/* dCSWStatus */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCSWStatus, tvb, offset, 1, ENC_LITTLE_ENDIAN);
|
||||
status=tvb_get_guint8(tvb, offset);
|
||||
/*offset+=1;*/
|
||||
|
||||
itlq=(itlq_nexus_t *)wmem_tree_lookup32_le(usbms_bot_conv_info->itlq, pinfo->num);
|
||||
if(!itlq){
|
||||
return tvb_captured_length(tvb);
|
||||
}
|
||||
itlq->last_exchange_frame=pinfo->num;
|
||||
|
||||
itl=(itl_nexus_t *)wmem_tree_lookup32(usbms_bot_conv_info->itl, itlq->lun);
|
||||
if(!itl){
|
||||
return tvb_captured_length(tvb);
|
||||
}
|
||||
|
||||
if(!status){
|
||||
dissect_scsi_rsp(tvb, pinfo, parent_tree, itlq, itl, 0);
|
||||
} else {
|
||||
/* just send "check condition" */
|
||||
dissect_scsi_rsp(tvb, pinfo, parent_tree, itlq, itl, 0x02);
|
||||
}
|
||||
return tvb_captured_length(tvb);
|
||||
}
|
||||
|
||||
/* dissector for mass storage bulk data */
|
||||
static int
|
||||
|
@ -214,83 +343,7 @@ dissect_usbms_bot_bulk(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tre
|
|||
* SCSI CDB inside CBW
|
||||
*/
|
||||
if(is_request&&(signature==0x43425355)&&(tvb_reported_length(tvb)==31)){
|
||||
tvbuff_t *cdb_tvb;
|
||||
int cdbrlen, cdblen;
|
||||
guint8 lun, flags;
|
||||
guint32 datalen;
|
||||
|
||||
/* dCBWSignature */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCBWSignature, tvb, offset, 4, ENC_LITTLE_ENDIAN);
|
||||
offset+=4;
|
||||
|
||||
/* dCBWTag */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCBWTag, tvb, offset, 4, ENC_LITTLE_ENDIAN);
|
||||
offset+=4;
|
||||
|
||||
/* dCBWDataTransferLength */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCBWDataTransferLength, tvb, offset, 4, ENC_LITTLE_ENDIAN);
|
||||
datalen=tvb_get_letohl(tvb, offset);
|
||||
offset+=4;
|
||||
|
||||
/* dCBWFlags */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCBWFlags, tvb, offset, 1, ENC_LITTLE_ENDIAN);
|
||||
flags=tvb_get_guint8(tvb, offset);
|
||||
offset+=1;
|
||||
|
||||
/* dCBWLUN */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCBWTarget, tvb, offset, 1, ENC_LITTLE_ENDIAN);
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCBWLUN, tvb, offset, 1, ENC_LITTLE_ENDIAN);
|
||||
lun=tvb_get_guint8(tvb, offset)&0x0f;
|
||||
offset+=1;
|
||||
|
||||
/* make sure we have a ITL structure for this LUN */
|
||||
itl=(itl_nexus_t *)wmem_tree_lookup32(usbms_bot_conv_info->itl, lun);
|
||||
if(!itl){
|
||||
itl=wmem_new(wmem_file_scope(), itl_nexus_t);
|
||||
itl->cmdset=0xff;
|
||||
itl->conversation=NULL;
|
||||
wmem_tree_insert32(usbms_bot_conv_info->itl, lun, itl);
|
||||
}
|
||||
|
||||
/* make sure we have an ITLQ structure for this LUN/transaction */
|
||||
itlq=(itlq_nexus_t *)wmem_tree_lookup32(usbms_bot_conv_info->itlq, pinfo->num);
|
||||
if(!itlq){
|
||||
itlq=wmem_new(wmem_file_scope(), itlq_nexus_t);
|
||||
itlq->lun=lun;
|
||||
itlq->scsi_opcode=0xffff;
|
||||
itlq->task_flags=0;
|
||||
if(datalen){
|
||||
if(flags&0x80){
|
||||
itlq->task_flags|=SCSI_DATA_READ;
|
||||
} else {
|
||||
itlq->task_flags|=SCSI_DATA_WRITE;
|
||||
}
|
||||
}
|
||||
itlq->data_length=datalen;
|
||||
itlq->bidir_data_length=0;
|
||||
itlq->fc_time=pinfo->abs_ts;
|
||||
itlq->first_exchange_frame=pinfo->num;
|
||||
itlq->last_exchange_frame=0;
|
||||
itlq->flags=0;
|
||||
itlq->alloc_len=0;
|
||||
itlq->extra_data=NULL;
|
||||
wmem_tree_insert32(usbms_bot_conv_info->itlq, pinfo->num, itlq);
|
||||
}
|
||||
|
||||
/* dCBWCBLength */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCBWCBLength, tvb, offset, 1, ENC_LITTLE_ENDIAN);
|
||||
cdbrlen=tvb_get_guint8(tvb, offset)&0x1f;
|
||||
offset+=1;
|
||||
|
||||
cdblen=cdbrlen;
|
||||
if(cdblen>tvb_captured_length_remaining(tvb, offset)){
|
||||
cdblen=tvb_captured_length_remaining(tvb, offset);
|
||||
}
|
||||
if(cdblen){
|
||||
cdb_tvb=tvb_new_subset_length_caplen(tvb, offset, cdblen, cdbrlen);
|
||||
dissect_scsi_cdb(cdb_tvb, pinfo, parent_tree, SCSI_DEV_UNKNOWN, itlq, itl);
|
||||
}
|
||||
return tvb_captured_length(tvb);
|
||||
return dissect_usbms_bot_cbw(tvb, pinfo, parent_tree, tree, usbms_bot_conv_info);
|
||||
}
|
||||
|
||||
|
||||
|
@ -298,43 +351,7 @@ dissect_usbms_bot_bulk(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tre
|
|||
* SCSI RESPONSE inside CSW
|
||||
*/
|
||||
if((!is_request)&&(signature==0x53425355)&&(tvb_reported_length(tvb)==13)){
|
||||
guint8 status;
|
||||
|
||||
/* dCSWSignature */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCSWSignature, tvb, offset, 4, ENC_LITTLE_ENDIAN);
|
||||
offset+=4;
|
||||
|
||||
/* dCSWTag */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCBWTag, tvb, offset, 4, ENC_LITTLE_ENDIAN);
|
||||
offset+=4;
|
||||
|
||||
/* dCSWDataResidue */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCSWDataResidue, tvb, offset, 4, ENC_LITTLE_ENDIAN);
|
||||
offset+=4;
|
||||
|
||||
/* dCSWStatus */
|
||||
proto_tree_add_item(tree, hf_usbms_bot_dCSWStatus, tvb, offset, 1, ENC_LITTLE_ENDIAN);
|
||||
status=tvb_get_guint8(tvb, offset);
|
||||
/*offset+=1;*/
|
||||
|
||||
itlq=(itlq_nexus_t *)wmem_tree_lookup32_le(usbms_bot_conv_info->itlq, pinfo->num);
|
||||
if(!itlq){
|
||||
return tvb_captured_length(tvb);
|
||||
}
|
||||
itlq->last_exchange_frame=pinfo->num;
|
||||
|
||||
itl=(itl_nexus_t *)wmem_tree_lookup32(usbms_bot_conv_info->itl, itlq->lun);
|
||||
if(!itl){
|
||||
return tvb_captured_length(tvb);
|
||||
}
|
||||
|
||||
if(!status){
|
||||
dissect_scsi_rsp(tvb, pinfo, parent_tree, itlq, itl, 0);
|
||||
} else {
|
||||
/* just send "check condition" */
|
||||
dissect_scsi_rsp(tvb, pinfo, parent_tree, itlq, itl, 0x02);
|
||||
}
|
||||
return tvb_captured_length(tvb);
|
||||
return dissect_usbms_bot_csw(tvb, pinfo, parent_tree, tree, usbms_bot_conv_info);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue