Priority-based automatic switching Wi-Fi access points using wpa_cli - linux

I am required to implement functionality for switching Wi-Fi access points based on priority i.e. if Linux device is connected to Wi-Fi "A" and another Wi-Fi access point "B" with higher priority appears the device should automatically switch to wi-fi "B". Can anyone help me out?
I have set different Wi-Fi access points priority using wpa_cli and if I restart my Linux device it switches network according to set priority but if the device is already connected to some network it won't switch.

Related

How to detect disconnection of usb0 device (USB gadget aka g_ether)?

Two Linux machines (embedded board and PC) are connected to each other via USB cable, and communication is established via USB gadget/Ethernet. Both sides have IP address, ping works, etc.
I need to find a way to detect USB cable disconnect on the board side, ideally with a single Bash command.
ifconfig usb0 still shows IP address and that device is "UP" and "RUNNING" even after unplugging the cable.
In my particular case it turned out to be HW+SW issue: driver (atmel_usba_udc) is using USB power (VBUS) to detect connection, since it's acting as a slave and power is provided by host. However in PCB power is provided unconditionally by the board itself for all USB ports at once.
Normally any standard method should work: ifconfig or sysfs.
One way to do this is to check the file:
/sys/class/net/usb0/operstate
If the file content is "up" then the link exists. If the content is "down", then there is no link.

Can a USB 3 Host machine be programmed as a USB 3 Peripheral (or a HID keyboard)?

What I want to do:
An AI program on a host machine, reading inputs from a camera sensing the screen of the target machine and outputting controls to the target machine via USB connection--programming the host machine's USB host as a USB peripheral connected to the target machine.
What I want to do step by step: (is it possible to implement the steps below?)
Have a host machine A and a target machine B.
Connect A and B with a USB 3.0 Type-A male-male cable.
The USB connection shows up as an HID keyboard device on B.
Write code to simulate key presses on A that sends to B.
(Eg. calling press('F') on a program running on A would type F to B's input)
It shouldn't require any program installed on B.
What I already searched:
USB 3.0 Host to host connection is possible:
https://superuser.com/questions/795053/how-do-i-connect-two-computers-using-usb-3-0
USB 2.0 Host to host connection is impossible:
https://superuser.com/questions/99274/how-to-connect-two-computers-with-usb
Similar questions asked without the assumption that USB 3.0 Host to Host connection is possible:
https://superuser.com/questions/1128365/simulate-usb-keyboard-from-machine
Setting up a computer to act as an HID device connected to another computer via ps/2,usb or another wired connection
https://superuser.com/questions/507921/computer-to-act-as-keyboard?rq=1
Suggestions in ascending order of feasibility:
USB Gadgets
You are using linux, so the default way would be to create/configure/load a gadget driver. Have a look at this tutorial, though for a raspberry, should work on your PC too. However, I could not find any information regarding the use of USB3 - the tutorial assumes your host is using one of it's OTG ports, which your PC most likely does not have. So whether this works with your USB3.1 Type-A-to-Type-A connection you'll need to test.
USBIP
The idea of sharing USB devices (not just keyboards) is not really new. With USBIP you can "export" any local USB device to the network, and your client will need the client-side USBIP driver to access the keyboard.
Dont bother with USB at all, just use Ethernet
I'd simply write two userland scripts/programs that send/receive+execute the keystrokes. Very easy to implement, you're probably familiar with python anyway.
If you absolutely cant have software installed on the client-PC and your Type-C-to-Type-C connection doesnt support USB Gadgets, there's another way. It basically involves the use of two USB-to-serial adapters (~15$) and a serial cable. While this wont be enumerated as a keyboard, but rather as serial port, it's the lowest-effort solution to transfer data without additional software on the client. Both computers will just do file I/O. If your computers still have COM-ports, you can even omit the serial converters!

Creating custom virtual usb device using usb-vhci

I am new to working on virtual USB device simulation in Linux. So far I have installed the virtual host control (vhci) libraries as per this tutorial (http://sourceforge.net/p/usb-vhci/wiki/Home/) and can see a virtual USB device being created which has some typical specifications that the library implements (Bus 05 in the image with the vendor and product IDs being "dead" and "beef" respectively).
However I want the created virtual device to have the specifications of a real device I have at hand (a mouse, for example).
So how to enumerate and initialize a virtual USB device with the same credentials as another device?
The kernel module (vhci-hcd) is only a (virtual) host controller that you can attach virtual devices to.
If you want to emulate eg a mouse you should get the libusb_vhci from the same source, and look into the examples. These are bare minimum starting points that does nothing except for the basic usb device handling. You'll have to extend this with all descriptors and protocol handling for a USB HID mouse or whatever you want to emulate.
http://www.usbmadesimple.co.uk/ums_5.htm should be a good starting point.
you can use lsusb and in particular lsusb -D to dump the descriptors of devices you have connected.

pcsc-lite : multiple ACR122T devices with no unique serial number - linux

I have multiple ACR122T smart card devices with no unique serial numbers (from ACS). I need to know which physical smart card I am connected to from within pcsc-lite. I know from using lsusb which USB Port a physical device is on, but how to map that USB port information with SCardGetAttribute(SCARD_ATTR_DEVICE_UNIT) ?
It seems the map should be at the OS level as I cant find a way to read USB Port info (lsusb results) from within the pscs-lite API.
This post mentions a method, Smartcard reader ACR122U has no unique serial number
but I dont understand the details behind "used that dev number to ensure I always used the right reader".
Any help appreciated.
Thanks, -Phil
Disclaimer: I'm working on Windows, not Linux.
The ACR122T (and ACR122U) devices not only have no serial number (other than the one printed on the back) but also have no USB serial number so that they can only be differentiated by the USB port they are plugged in. Additionally all the ACR122Ts and Us I have here (we bought a bunch) identify themselves as "ACS ACR122" to Windows. Using the proprietary API to get the firmware version both the ACR122T and the ACR122U identify themselves as a ACR122U (e.g. "ACR122U207" or "ACR122U214").
That means that the OS itself is not able to differentiate multiple devices in any other way then the USB port it's plugged in.
I also tried to make a connection between the pcsc device and the OS device, but apart from this function (which is only available starting Windows 8) I have not found anything, so it looks to me like there is no way to do that through pcsc calls.
The device unit is given out by the pcsc layer sequentially so you can differentiate between devices you are connected to but not identify a specific device.

Make your computer discoverable

my .net app on the computer needs to make the computer discoverable, start a service and then wait to accept incoming connections. my app/computer is the slave and connecting device is the master. So I change my local radio mode to discoverable programmatically,start my service and wait... But when the device is supposed to connect to my app/computer, nothing happens.
Windows help and support has this :
Control Panel ->search for bluetooth -> click on change bluetooth settings ->
To make your computer discoverable to Bluetooth enabled devices,
select the check box for Allow Bluetooth devices to find this computer.
When a Bluetooth enabled computer is in discovery mode, it broadcasts a
wireless signal that allows it to be detected by other computers or devices.
This is sometimes called pairing mode. If you check this box, your computer
will still be able to detect Bluetooth enabled devices that are in discovery mode,
but they will not be able to detect your computer.
I am not quite sure what's the context. If I leave that box checked, then other devices will be able to detect me (because I am set to discoverable), but won't be able to connect????? So my service just keeps listening, won't be able to detect any incoming requests? Am I right?

Resources