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,60 +164,16 @@ dissect_usbms_bot_control(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_
|
|||
return tvb_captured_length(tvb);
|
||||
}
|
||||
|
||||
|
||||
/* dissector for mass storage bulk data */
|
||||
static int
|
||||
dissect_usbms_bot_bulk(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* data)
|
||||
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)
|
||||
{
|
||||
usb_conv_info_t *usb_conv_info;
|
||||
usbms_bot_conv_info_t *usbms_bot_conv_info;
|
||||
proto_tree *tree;
|
||||
proto_item *ti;
|
||||
guint32 signature=0;
|
||||
int offset=0;
|
||||
gboolean is_request;
|
||||
itl_nexus_t *itl;
|
||||
itlq_nexus_t *itlq;
|
||||
|
||||
/* Reject the packet if data is NULL */
|
||||
if (data == NULL)
|
||||
return 0;
|
||||
usb_conv_info = (usb_conv_info_t *)data;
|
||||
|
||||
/* verify that we do have a usbms_bot_conv_info */
|
||||
usbms_bot_conv_info=(usbms_bot_conv_info_t *)usb_conv_info->class_data;
|
||||
if(!usbms_bot_conv_info){
|
||||
usbms_bot_conv_info=wmem_new(wmem_file_scope(), usbms_bot_conv_info_t);
|
||||
usbms_bot_conv_info->itl=wmem_tree_new(wmem_file_scope());
|
||||
usbms_bot_conv_info->itlq=wmem_tree_new(wmem_file_scope());
|
||||
usb_conv_info->class_data=usbms_bot_conv_info;
|
||||
usb_conv_info->class_data_type = USB_CONV_MASS_STORAGE_BOT;
|
||||
} else if (usb_conv_info->class_data_type != USB_CONV_MASS_STORAGE_BOT) {
|
||||
/* Don't dissect if another USB type is in the conversation */
|
||||
return 0;
|
||||
}
|
||||
|
||||
is_request=(pinfo->srcport==NO_ENDPOINT);
|
||||
|
||||
col_set_str(pinfo->cinfo, COL_PROTOCOL, "USBMS");
|
||||
|
||||
col_clear(pinfo->cinfo, COL_INFO);
|
||||
|
||||
|
||||
ti = proto_tree_add_protocol_format(parent_tree, proto_usbms_bot, tvb, 0, -1, "USB Mass Storage");
|
||||
tree = proto_item_add_subtree(ti, ett_usbms_bot);
|
||||
|
||||
signature=tvb_get_letohl(tvb, offset);
|
||||
|
||||
|
||||
/*
|
||||
* SCSI CDB inside CBW
|
||||
*/
|
||||
if(is_request&&(signature==0x43425355)&&(tvb_reported_length(tvb)==31)){
|
||||
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);
|
||||
|
@ -291,14 +247,15 @@ dissect_usbms_bot_bulk(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tre
|
|||
dissect_scsi_cdb(cdb_tvb, pinfo, parent_tree, SCSI_DEV_UNKNOWN, itlq, itl);
|
||||
}
|
||||
return tvb_captured_length(tvb);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* SCSI RESPONSE inside CSW
|
||||
*/
|
||||
if((!is_request)&&(signature==0x53425355)&&(tvb_reported_length(tvb)==13)){
|
||||
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);
|
||||
|
@ -335,6 +292,66 @@ dissect_usbms_bot_bulk(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tre
|
|||
dissect_scsi_rsp(tvb, pinfo, parent_tree, itlq, itl, 0x02);
|
||||
}
|
||||
return tvb_captured_length(tvb);
|
||||
}
|
||||
|
||||
/* dissector for mass storage bulk data */
|
||||
static int
|
||||
dissect_usbms_bot_bulk(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* data)
|
||||
{
|
||||
usb_conv_info_t *usb_conv_info;
|
||||
usbms_bot_conv_info_t *usbms_bot_conv_info;
|
||||
proto_tree *tree;
|
||||
proto_item *ti;
|
||||
guint32 signature=0;
|
||||
int offset=0;
|
||||
gboolean is_request;
|
||||
itl_nexus_t *itl;
|
||||
itlq_nexus_t *itlq;
|
||||
|
||||
/* Reject the packet if data is NULL */
|
||||
if (data == NULL)
|
||||
return 0;
|
||||
usb_conv_info = (usb_conv_info_t *)data;
|
||||
|
||||
/* verify that we do have a usbms_bot_conv_info */
|
||||
usbms_bot_conv_info=(usbms_bot_conv_info_t *)usb_conv_info->class_data;
|
||||
if(!usbms_bot_conv_info){
|
||||
usbms_bot_conv_info=wmem_new(wmem_file_scope(), usbms_bot_conv_info_t);
|
||||
usbms_bot_conv_info->itl=wmem_tree_new(wmem_file_scope());
|
||||
usbms_bot_conv_info->itlq=wmem_tree_new(wmem_file_scope());
|
||||
usb_conv_info->class_data=usbms_bot_conv_info;
|
||||
usb_conv_info->class_data_type = USB_CONV_MASS_STORAGE_BOT;
|
||||
} else if (usb_conv_info->class_data_type != USB_CONV_MASS_STORAGE_BOT) {
|
||||
/* Don't dissect if another USB type is in the conversation */
|
||||
return 0;
|
||||
}
|
||||
|
||||
is_request=(pinfo->srcport==NO_ENDPOINT);
|
||||
|
||||
col_set_str(pinfo->cinfo, COL_PROTOCOL, "USBMS");
|
||||
|
||||
col_clear(pinfo->cinfo, COL_INFO);
|
||||
|
||||
|
||||
ti = proto_tree_add_protocol_format(parent_tree, proto_usbms_bot, tvb, 0, -1, "USB Mass Storage");
|
||||
tree = proto_item_add_subtree(ti, ett_usbms_bot);
|
||||
|
||||
signature=tvb_get_letohl(tvb, offset);
|
||||
|
||||
|
||||
/*
|
||||
* SCSI CDB inside CBW
|
||||
*/
|
||||
if(is_request&&(signature==0x43425355)&&(tvb_reported_length(tvb)==31)){
|
||||
return dissect_usbms_bot_cbw(tvb, pinfo, parent_tree, tree, usbms_bot_conv_info);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* SCSI RESPONSE inside CSW
|
||||
*/
|
||||
if((!is_request)&&(signature==0x53425355)&&(tvb_reported_length(tvb)==13)){
|
||||
return dissect_usbms_bot_csw(tvb, pinfo, parent_tree, tree, usbms_bot_conv_info);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue