X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=client%2FUSBFtdi.py;h=abc5980a987e7c41323a69f8365fd67d8f1122c6;hp=065722dd235a76be637a2dfa0c53c3a42e7e776c;hb=HEAD;hpb=d74b45cbeb68caa15fd4d4fc1ae7df7b291affa6;ds=sidebyside diff --git a/client/USBFtdi.py b/client/USBFtdi.py index 065722d..abc5980 100644 --- a/client/USBFtdi.py +++ b/client/USBFtdi.py @@ -32,85 +32,84 @@ class USBFtdiVendor(USBVendor): if self.verbose > 0: print(self.name, "received reset request") - self.interface.configuration.device.maxusb_app.send_on_endpoint(0, b'') + self.device.maxusb_app.send_on_endpoint(0, b'') def handle_modem_ctrl_request(self, req): if self.verbose > 0: print(self.name, "received modem_ctrl request") - dtr = req.value[1] & 0x01 - rts = (req.value[1] & 0x02) >> 1 - dtren = req.value[0] & 0x01 - rtsen = (req.value[0] & 0x02) >> 1 + dtr = req.value & 0x0001 + rts = (req.value & 0x0002) >> 1 + dtren = (req.value & 0x0100) >> 8 + rtsen = (req.value & 0x0200) >> 9 if dtren: print("DTR is enabled, value", dtr) if rtsen: print("RTS is enabled, value", rts) - self.interface.configuration.device.maxusb_app.send_on_endpoint(0, b'') + self.device.maxusb_app.send_on_endpoint(0, b'') def handle_set_flow_ctrl_request(self, req): if self.verbose > 0: print(self.name, "received set_flow_ctrl request") - dtr = req.value[1] & 0x01 - if req.value[1] == 0: + if req.value == 0x000: print("SET_FLOW_CTRL to no handshaking") - if req.value[1] & 0x01: + if req.value & 0x0001: print("SET_FLOW_CTRL for RTS/CTS handshaking") - if req.value[1] & 0x02: + if req.value & 0x0002: print("SET_FLOW_CTRL for DTR/DSR handshaking") - if req.value[1] & 0x04: + if req.value & 0x0004: print("SET_FLOW_CTRL for XON/XOFF handshaking") - self.interface.configuration.device.maxusb_app.send_on_endpoint(0, b'') + self.device.maxusb_app.send_on_endpoint(0, b'') def handle_set_baud_rate_request(self, req): if self.verbose > 0: print(self.name, "received set_baud_rate request") - dtr = req.value[1] & 0x01 - print("baud rate set to", req.value[1]) + dtr = req.value & 0x0001 + print("baud rate set to", dtr) - self.interface.configuration.device.maxusb_app.send_on_endpoint(0, b'') + self.device.maxusb_app.send_on_endpoint(0, b'') def handle_set_data_request(self, req): if self.verbose > 0: print(self.name, "received set_data request") - self.interface.configuration.device.maxusb_app.send_on_endpoint(0, b'') + self.device.maxusb_app.send_on_endpoint(0, b'') def handle_get_status_request(self, req): if self.verbose > 0: print(self.name, "received get_status request") - self.interface.configuration.device.maxusb_app.send_on_endpoint(0, b'') + self.device.maxusb_app.send_on_endpoint(0, b'') def handle_set_event_char_request(self, req): if self.verbose > 0: print(self.name, "received set_event_char request") - self.interface.configuration.device.maxusb_app.send_on_endpoint(0, b'') + self.device.maxusb_app.send_on_endpoint(0, b'') def handle_set_error_char_request(self, req): if self.verbose > 0: print(self.name, "received set_error_char request") - self.interface.configuration.device.maxusb_app.send_on_endpoint(0, b'') + self.device.maxusb_app.send_on_endpoint(0, b'') def handle_set_latency_timer_request(self, req): if self.verbose > 0: print(self.name, "received set_latency_timer request") - self.interface.configuration.device.maxusb_app.send_on_endpoint(0, b'') + self.device.maxusb_app.send_on_endpoint(0, b'') def handle_get_latency_timer_request(self, req): if self.verbose > 0: print(self.name, "received get_latency_timer request") # bullshit value - self.interface.configuration.device.maxusb_app.send_on_endpoint(0, b'\x01') + self.device.maxusb_app.send_on_endpoint(0, b'\x01') class USBFtdiInterface(USBInterface): @@ -138,7 +137,7 @@ class USBFtdiInterface(USBInterface): USBEndpoint.usage_type_data, 16384, # max packet size 0, # polling interval, see USB 2.0 spec Table 9-13 - self.handle_buffer_available # handler function + None # handler function ) ] @@ -156,14 +155,16 @@ class USBFtdiInterface(USBInterface): descriptors ) - self.device_vendor = USBFtdiVendor() - self.device_vendor.set_interface(self) + def handle_data_available(self, data): + s = data[1:] + if self.verbose > 0: + print(self.name, "received string", s) - def handle_buffer_available(self): - pass + s = s.replace(b'\r', b'\r\n') - def handle_data_available(self, data): - pass + reply = b'\x01\x00' + s + + self.configuration.device.maxusb_app.send_on_endpoint(3, reply) class USBFtdiDevice(USBDevice): @@ -186,7 +187,7 @@ class USBFtdiDevice(USBDevice): 0, # protocol release number 64, # max packet size for endpoint 0 0x0403, # vendor id: FTDI - 0x8372, # product id: FT232 USB-Serial (UART) IC + 0x6001, # product id: FT232 USB-Serial (UART) IC 0x0001, # device revision "GoodFET", # manufacturer string "FTDI Emulator", # product string @@ -195,3 +196,6 @@ class USBFtdiDevice(USBDevice): verbose=verbose ) + self.device_vendor = USBFtdiVendor() + self.device_vendor.set_device(self) +