Linux writing raw bytes on USB - linux

I've got usb cable plugged to my computer, which D+ and D- pins are connected to multimeter. I want to send some raw bytes to get some voltage.. is it possible at all?
I'm 99% sure that usb port I've plugged cable in is something like /dev/bus/usb/002
I know that there was possibility to do the same with LPT or RS232 ports.

RS232 and LPT are not bus ! USB devices need to be addressed in order to become reachable.
Maybe unloading and reloading usb driver that drive your usb host... or trying to make a reset on usb hub host...
For doing this kind of operation on usb port, you have to break usb kernel driver and whipe all addressing operation to address directly the chipset...
At all, due to USB concept, I'm not sure you may successfully hold some power state on outlet.
For playing with that kind of physical IO, two solution:
Install a low-cost RS-232 <-> USB adapter
or better
Buy an Arduino micro-controller for prototyping and development.

I'm nearly 100% sure that you can't send anything down your USB lead unless you actually have a device at the other end. If you still want to play with this, get a cheap memory stick, break the casing off it [not too roughly], and measure whilst doing a large file-transfer to the memory stick, or some such.
But I'm not sure your multimeter will show much, as they tend to be a bit slow, compared to USB rates.

USB uses pull-up / pull-down resistors on the data lines to detect whether or not a port is connected (1.5k pull-up to 3.3v on the device side, 15k pull-down on the host side IIRC). The exact connection depends on the device speed.
So if you connect an appropriate resistor, the host should attempt to start signalling. Because of the data-rate, you might not be able to see that on a multimeter; an oscilloscope would be more appropriate.
If you want to by-pass the normal USB protocol and just blindly send data, I think you'll need to get your hands dirty and write code to bypass the usual device drivers and access the USB hardware directly. Even then I'm not sure what's possible - the USB hardware is a lot smarter than good ol' LPT and RS232 ports, which might get in the way of doing this sort of low level stuff.

Related

Linux USB Disable USB Power Only

I've have been looking for a while and though a lot of Exchange Q&A's have helped, I haven't exactly received the answer I'm looking for.
Going off the question asked here: How can I detect a USB port being used for charging in Linux?
I felt as if it needed it's own question. I have a USB Powered Hub for charging smart phones and I wish to control the power (On/Off only) to each of the ports individually.
Using a USB charging cable, Linux cannot detect that a device is plugged in, so using a USB data cable might be more useful to this scenario.
Essentially, I want Linux to be able to detect when a device is plugged in, however I do not want any data transmission to occur between the device and Linux. Simply only power. By detecting the device being plugged in, I want to be able to control whether power will flow to the device or not, but no data transmission.
I'm currently testing with uhubctl, however when enabling/disabling the port, unfortunately it controls both power/data where I wish to cut off data entirely and only allow power to the device.
Is it possible to using a USB Data Cable detect a device plugged in, then essentially disable the phone talking to the computer entirely, but still allow power to flow to the device?
If not, the other option I was thinking is if there is a USB Power Hub out there that can tell Linux if a new device has been plugged in or not and I can tell it whether to charge or not?
Any input would be greatly appreciated.

Using CC2640 As USB Bluetooth Dongle

I salvaged a CC2640 out of Bluetooth keyboard. I desoldered it in a attempt to reuse it. Can it be transformed to a USB Dongle adapter in any way? I'm doing this for knowledge, not for the outcome (It may be easier or cheaper to buy one, still want to do it)
you have to reprogram the flash (http://www.ti.com/lit/an/spraal3/spraal3.pdf). for this you can use SmartRF Flash Programmer and you need access to the pins of debug port (JTAG) or serial port (UART) and possibly there is a lock (fuse set). the OEMs often set locks to ensure that nobody reads out the code with what they programmed their devices ... if you get access to the flash of the CC2640 you can reuse it. as the CC2640 has no USB port you can only make an USB dongle of it with an external chip i.e. a FTDI chip (connect the serial port of the FTDI with the serial port of the CC2640...)

How to transfer data with high speed through USB?

I'm trying to find a way to send/receive data through USB port of an ARM processor on a zynq board (ZC706) running petalinux.
I searched on the net and I'm totally confused where to begin. I found solutions but those did not consider USB to be connected to ARM processor, high-speed data transfer or petalinux.
I know how to write simple linux kernel codes and I know how to work with zynq board.
To be specific, I want to know how to write a piece of code, better to say a library of functions, in petalinux to read and write to usb port connected to ARM as high-speed as possible.
Seems like you are trying to do some quite sophisticated thing.
First I would like to say that USB is not some kind of port which you can read data "byte after byte" like in case of serial or parallel ports.
I would recommend you to start with reading about USB 2.0 and EHCI documentation (it take some time). Additionally you need to know what kind of USB is your board - is it host or device USB type? In case of usb device type - probably you need to write your own driver for this board and connect it to some USB host (PC for example). Then you need to create some communication protocol over USB. Luckily on the PC side you would use the libusb library for this. I mean you need to write program which uses libusb library for communication with your board.
Quite a lot of work to do.

Ethernet + Serial port in Linux

I want to implement a driver in Linux, that has a Ethernet stack but the data going out on hardware will be a serial port. Basically, I want to register my serial port as a Ethernet driver. Does anyone have any idea if this is possible?
I want to be able to push IPv6 and/or UDP packets out of the serial port and in a similar way receive the packets via a serial port and pass it up the Ethernet stack.
I do not want to use the solution of serial-to-ethernet convertors(external hardware that convert a serial port to a ethernet port) but have that in my PC itself.
I tried PPP over the serial port and it works well. I am also told that I can do FTP, HTTP etc using the PPP. Reference to this - http://www.faqs.org/docs/Linux-HOWTO/Serial-Laplink-HOWTO.html
I have tried to hack the code from a RealTek Ethernet driver with a serial driver but not able to gain much success. Rather I do not know the stack of either to actually do anything meaningful. Any advice, guidance or tutorials would be helpful.
Thanks
Aditya
You need to get back to de basics on networking, the way I understand you question is: "I have a serial port and I want to use is an Ethernet link". Sorry to crush your dreams but you don't have the real hardware to do so, I'll elaborate on it.
A serial connection is a physical connection that requires 3 wires (at least) tx, rx and ground. On the logical side you have an IC that coverts binary data into signals that are represented by discrete voltage ranges.
Ethernet is a layer 2 protocol, the layer 1 is provided by the technology used to transmit the signals (coax, up, fiber etc.) As you might see by now, you need a different set of hardware to convert the logical Ethernet frames into a stream of digital numbers, in fact this is call framing.
Since Ethernet has been an easy to use protocol it has been implemented as e preferred protocol for many network operators, of course one of the biggest is PPPoE where you have a PPP session over an Ethernet link. Of course this won't work with your example neither since you're trying the opposite.
If you're just learning and have all the time in the world you can attempt to write your own Ethernet framer over serial lines. This means you need to implement IEEE802.3 into the driver and then you need to serialize the data to push it as a stream of bits over the serial line. Of course note the following drawbacks:
Your driver won't be able to fully support Ethernet, you need some support at hardware level to implement some signaling (example, auto negotiation, CSMA/CD, etc)
You driver will be pretty much useless unless you back in time where 115.2kbps is top speed in data transfers
IMHO there are more exciting projects that you can pick up in the networking field for device drivers. You can for example attempt to buy a NIC and develop the device driver for it from scratch and you can optimize certain areas. Finally, remember that most of the Ethernet implementations are now done in hardware so you don't have to do anything but filling a few registers on the MAC and voila!
SLIP and PPP do already what you want.

How to send keystrokes from one computer to another by USB?

Is there a way to use one computer to send keystrokes to another by usb ?
What i'm looking to do is to capture the usb signal used by a keyboard (with USBTrace for example) and use it with PC-1 to send it to PC-2.
So that PC-2 reconize it as a regular keyboard input.
Some leads to do this would be very appreciated.
What you essentially need is a USB port on PC-1 that will act as a USB device for PC-2.
That is not possible for the vast majority of PC systems because USB is an asymmetric bus, with a host/device (or master/slave, if you wish) architecture. USB controllers (and their ports) on most PCs can only work in host mode and cannot simulate a device.
That is the reason that you cannot network computers through USB without a special cable with specialised electronics.
The only exception is if you somehow have a PC that supports the USB On-The-Go standard that allows for a USB port to act in both host and device mode. USB-OTG devices do exist, but they are usually embedded devices (smartphones etc). I don't know if there is a way to add a USB-OTG port to a commodity PC.
EDIT:
If you do not need a keyboard before the OS on PC-2 boots, you might be able to use a pair of USB Bluetooth dongles - one on each PC. You'd have to use specialised software on PC-1, but it is definitely possible - I've already seen a possible implementation on Linux, and I am reasonably certain that there must be one for Windows. You will also need Bluetooth HID drivers on PC-2, if they are not already installed.
On a different note, have you considered a purely software/network solution such as TightVNC?
There is a solution:
https://github.com/Flowm/etherkey
This uses a network connection from your computer to the raspi which is connected to a teensy (usb developer board) to send the key strokes.
This solution is not an out-of-the-box product. The required skill is similar to programming some other devices like arduino. But it's a complete and working setup.
The cheapest options are commercial microcontrollers (eg arduino platform, pic, etc) or ready built usb keyboard controllers (eg i-pac, arcade controllers,etc)
SEARCH THIS PROGRAM:
TWedge: Keyboard Wedge Software (RS232, Serial, TCP, Bluetooth)
then, MAKE YOUR OWN CONNECTION CABLE WITH:
(usb <-> rs232) + (NULL MODEM) + (rs232 <-> usb)
Connect 2 computer, write your own program to send signal to your (usb <-> rs232) unit, then you can control another computer under the help of TWedge.
The above mentionned https://github.com/Flowm/etherkey is one way. The keyboard is emulated from an rPi, but the principle can be used from PC to PC (or Mac to Whatever). The core answer to your question is to use an OTG-capable chip, and then you control this chip via a USB-serial adapter.
https://euer.krebsco.de/a-software-kvm-switch.html
uses a very similar method, using an Arduino instead of the Teensy.
The generic answer is: you need an OTG capable, or slave capable device: Arduino, Teensy, Pi 0 (either from Rapberry or Orange brands, both work; only the ZERO models are OTG capable), or, an rPi-A with heavy customisation (since it does not include USB hub, it can theoretically be converted into a slave; never found any public tutorial to do it), or any smartphone (Samsung, Nokia, HTC, Oukitel ... most smartphones are OTG capable). If you go for a Pi or a phone, then, you want to dig around USB Gadget. Cheaper solutions (Arduino/Teensy) need custom firmware.

Resources