MCPcopy
hub / github.com/axi0mX/ipwndfu / ctrl_transfer

Method ctrl_transfer

usb/core.py:997–1051  ·  view source on GitHub ↗

r"""Do a control transfer on the endpoint 0. This method is used to issue a control transfer over the endpoint 0 (endpoint 0 is required to always be a control endpoint). The parameters bmRequestType, bRequest, wValue and wIndex are the same of the USB Standard Cont

(self, bmRequestType, bRequest, wValue=0, wIndex=0,
            data_or_wLength = None, timeout = None)

Source from the content-addressed store, hash-verified

995 return buff
996
997 def ctrl_transfer(self, bmRequestType, bRequest, wValue=0, wIndex=0,
998 data_or_wLength = None, timeout = None):
999 r"""Do a control transfer on the endpoint 0.
1000
1001 This method is used to issue a control transfer over the endpoint 0
1002 (endpoint 0 is required to always be a control endpoint).
1003
1004 The parameters bmRequestType, bRequest, wValue and wIndex are the same
1005 of the USB Standard Control Request format.
1006
1007 Control requests may or may not have a data payload to write/read.
1008 In cases which it has, the direction bit of the bmRequestType
1009 field is used to infer the desired request direction. For
1010 host to device requests (OUT), data_or_wLength parameter is
1011 the data payload to send, and it must be a sequence type convertible
1012 to an array object. In this case, the return value is the number
1013 of bytes written in the data payload. For device to host requests
1014 (IN), data_or_wLength is either the wLength parameter of the control
1015 request specifying the number of bytes to read in data payload, and
1016 the return value is an array object with data read, or an array
1017 object which the data will be read to, and the return value is the
1018 number of bytes read.
1019 """
1020 try:
1021 buff = util.create_buffer(data_or_wLength)
1022 except TypeError:
1023 buff = _interop.as_array(data_or_wLength)
1024
1025 self._ctx.managed_open()
1026
1027 # Thanks to Johannes Stezenbach to point me out that we need to
1028 # claim the recipient interface
1029 recipient = bmRequestType & 3
1030 rqtype = bmRequestType & (3 << 5)
1031 if recipient == util.CTRL_RECIPIENT_INTERFACE \
1032 and rqtype != util.CTRL_TYPE_VENDOR:
1033 interface_number = wIndex & 0xff
1034 self._ctx.managed_claim_interface(self, interface_number)
1035
1036 ret = self._ctx.backend.ctrl_transfer(
1037 self._ctx.handle,
1038 bmRequestType,
1039 bRequest,
1040 wValue,
1041 wIndex,
1042 buff,
1043 self.__get_timeout(timeout))
1044
1045 if isinstance(data_or_wLength, array.array) \
1046 or util.ctrl_direction(bmRequestType) == util.CTRL_OUT:
1047 return ret
1048 elif ret != len(buff) * buff.itemsize:
1049 return buff[:ret]
1050 else:
1051 return buff
1052
1053 def is_kernel_driver_active(self, interface):
1054 r"""Determine if there is kernel driver associated with the interface.

Callers 15

exploitFunction · 0.45
exploitFunction · 0.45
commandMethod · 0.45
send_commandFunction · 0.45
send_dataFunction · 0.45
reset_countersFunction · 0.45
send_dataFunction · 0.45
get_dataFunction · 0.45
request_image_validationFunction · 0.45
controlMsgMethod · 0.45
get_statusFunction · 0.45

Calls 3

__get_timeoutMethod · 0.95
managed_openMethod · 0.80

Tested by

no test coverage detected