diff --git a/src/USB_Component.ttcn b/src/USB_Component.ttcn index c38cba5..43cde1a 100644 --- a/src/USB_Component.ttcn +++ b/src/USB_Component.ttcn @@ -119,6 +119,25 @@ runs on USB_CT { g_USB_Tguard.stop; } +function f_usb_set_configuration(integer dev_hdl, integer bConfigurationValue) +runs on USB_CT { + var USB_result res; + var integer req_hdl := f_usb_get_req_hdl(); + g_USB_Tguard.start; + USB.send(ts_USB_set_configuration(dev_hdl, bConfigurationValue, req_hdl)); + USB.receive(USB_result:{req_hdl, dev_hdl, ?}) -> value res { log("Received ", res); } + g_USB_Tguard.stop; +} + +function f_usb_reset_device() +runs on USB_CT { + var USB_result res; + var integer req_hdl := f_usb_get_req_hdl(); + g_USB_Tguard.start; + USB.send(ts_USB_reset_device(g_dev_hdl, req_hdl)); + USB.receive(USB_result:{req_hdl, g_dev_hdl, ?}) -> value res { log("Received USB reset response", res); } + g_USB_Tguard.stop; +} /* Send a USB Device Request and wait for its completion to arrive */ function f_usb_dev_req(template (value) USB_DeviceRequest req) runs on USB_CT return USB_transfer_compl diff --git a/src/USB_PT.cc b/src/USB_PT.cc index bfe9a49..a534b67 100644 --- a/src/USB_PT.cc +++ b/src/USB_PT.cc @@ -432,6 +432,17 @@ void USB__PT_PROVIDER::outgoing_send(const USB__claim__interface& send_par) incoming_message(USB__result(send_par.req__hdl(), send_par.device__hdl(), rc)); } +void USB__PT_PROVIDER::outgoing_send(const USB__reset__device& send_par) +{ + USB_Device *dev = usbdev_by_hdl(send_par.device__hdl()); + int rc; + + rc = libusb_reset_device(dev->mHandle); + if (rc != 0) + log(TTCN_ERROR, "Cannot reset USB dev! \n"); + + incoming_message(USB__result(send_par.req__hdl(), send_par.device__hdl(), rc)); +} void USB__PT_PROVIDER::outgoing_send(const USB__release__interface& send_par) { USB_Device *dev = usbdev_by_hdl(send_par.device__hdl()); diff --git a/src/USB_PT.hh b/src/USB_PT.hh index f51118a..c2b1f93 100644 --- a/src/USB_PT.hh +++ b/src/USB_PT.hh @@ -93,6 +93,7 @@ protected: void user_start(); void user_stop(); + void outgoing_send(const USB__reset__device& send_par); void outgoing_send(const USB__open__vid__pid& send_par); void outgoing_send(const USB__open__path& send_par); void outgoing_send(const USB__transfer& send_par); diff --git a/src/USB_PortType.ttcn b/src/USB_PortType.ttcn index 735ec7d..b1f3407 100644 --- a/src/USB_PortType.ttcn +++ b/src/USB_PortType.ttcn @@ -2,6 +2,7 @@ module USB_PortType { import from USB_PortTypes all; type port USB_PT message { + out USB_reset_device; out USB_open_vid_pid; out USB_open_path; out USB_set_configuration; diff --git a/src/USB_PortTypes.ttcn b/src/USB_PortTypes.ttcn index 5e61943..dbbd539 100644 --- a/src/USB_PortTypes.ttcn +++ b/src/USB_PortTypes.ttcn @@ -130,6 +130,11 @@ module USB_PortTypes { octetstring data }; + type record USB_reset_device { + integer req_hdl, + integer device_hdl + }; + /* Response: USB_result */ template (value) USB_open_vid_pid ts_USB_open_vid_pid(USB_vendor_id vid, USB_product_id pid, integer device_hdl := -1, @@ -189,6 +194,21 @@ ts_USB_get_config_descriptor_by_value(integer device_hdl, integer cfg_val, integ config_value := cfg_val } +template (value) USB_set_configuration +ts_USB_set_configuration(integer device_hdl, integer config_num := 1, integer req_hdl := -1) := +{ + req_hdl := req_hdl, + device_hdl := device_hdl, + configuration := config_num +} + +template (value) USB_reset_device +ts_USB_reset_device(integer device_hdl, integer req_hdl := -1) := +{ + req_hdl := req_hdl, + device_hdl := device_hdl +} + template USB_descriptor tr_USB_descriptor(template integer device_hdl :=?, template integer req_hdl := ?, template integer result_code := ?, template octetstring data := ?) := {