Linux repetedly scanning for Wireless networks - linux

I am working on a Linux based IOT device that has a touch screen. I am using wpa_supplicant and then wpa_cli to manage the wireless network from my application.
What exactly happens during a wifi scan, technically?
What effects will the command scan_interval have on power usage, network link quality and performance?

Related

How to scan available WiFi access points while in master mode in Linux

In Linux, when the wifi interface (wlan0) is in "Managed" mode, we can run the following command to scan available WiFi access points:
$iwlist wlan0 scan
But this command stops to work when the interface is in "Master" mode:
$iwlist wlan0 scan
wlan0 No scan results
Is this a hard constraint of WiFi chip, or a limit in Linux software?
Is there a way to scan for available WiFi access points while the current interface itself is in "Master" mode, i.e. itself is an Access Point.
Very good question. Results of some minor research on the matter are as follows.
https://elixir.bootlin.com/linux/latest/source/net/mac80211/cfg.c#L2439
In ieee80211_scan() one can notice that the function tests NL80211_FEATURE_AP_SCAN flag in the set of features advertised by the underlying wireless device driver. That effectively means that, indeed, it's a constraint, but it's likely imposed by the specific vendor / driver / device rather than by Linux generic code.
https://elixir.bootlin.com/linux/latest/C/ident/NL80211_FEATURE_AP_SCAN
One may try to search for the said feature flag among the available wireless drivers. For example, my Wi-Fi card needs ath9k driver, and I don't see the latter in the list of drivers that advertise the said feature. Hence, my Wi-Fi card can't scan while in AP/master mode. Indeed, when I run (as root) iwlist dev_name scan or iw dev dev_name scan, I observe very similar output (Interface doesn't support scanning : Operation not supported and command failed: Operation not supported (-95) respectively).

How can I detect a USB port being used for charging in Linux?

I'm using a USB port on the Raspberry Pi 3 Model B to charge an accessory via a USB magnetic charging cable. I want to detect when the cable is plugged in and removed from the Pi.
I've been plugging in and removing this cable and looking for any traces of this being detected on Linux. So far, I've tried:
monitoring udev events by udevadm monitor.
tailing the system logs in /var/log etc.
running an inotify watch on the /dev directory for new devices
looking around in /sys/bus/usb/devices for any clues
Is it possible to detect my simple charging cable being inserted/removed? By intuition I would think no (since the cable is purely for charging, and doesn't have drivers), however I observe that the RPI flashes its builtin LED red when I insert the cable.
Without significant effort (hardware or hacks), No.
The red LED flash you observe is the power monitor for the Pi indicating a sudden voltage drop as current begins to flow to your accessory. This LED indicates voltage (electrical energy) has briefly dropped below stable levels, and system instability may result.
As the connection is purely charging (no USB data exchanged with the Pi) the operating system has no idea the device is connected. You could build an external current-measuring circuit to detect the peripheral drawing power, but such a question is better off in the electronics stack exchange.
I think that you cand do it with the lsusb tools:
lsusb -v
Or Filtering with:
lsusb -v |grep 'Bus\|MaxPower'
With this command I can see how much power each USB is usign and which device is connected.

Use a Linux Computer as a USB Coupler

I am on debian and:
I have a USB controller hooked up to a USB port on my PC (Device 1).
I have a male to male USB cord hooked up to another port on the PC that connects to Device 2. (it is a "bridging" usb cord, and has the chip for it)
I want to make them connect to each other as if they were one cord, so neither device knows that there is a computer in the middle.
This would be called a 'Coupler', except that I am using a PC as a coupler.
Here is a (really bad) diagram I made:
What I have done:
I have been able to connect the two devices independently of each other and sniff the results for when they fail to connect. The devices don't send a large volume of data back and forth.
Maybe there is some kind of command tool that I could use, for example (psudocode):
$ couple-usb-ports PORT1 PORT2
You're trying to reinvent the wheel here.
You might consider looking at this link instead.
http://dan3lmi.blogspot.com/2012/10/sniffing-usb-traffic-different.html
Specifically this.
Windows: You cannot directly capture raw USB traffic on Windows with Wireshark/WinPcap, but it is possible to capture and debug USB traffic on a virtual Windows machine under Oracle Virtual Box.
You cannot use a simple PC as transparent USB sniffer without extra (expensive) hardware. An USB bus has always one host (and one or more devices), and the PC can only be the host. This is a hardware limitation.
But you can capture USB data in a Windows machine using Wireshark and USBPcap, eliminating the need for the middle box in most cases.
As this post is tagged Linux, I suppose the controller PC is a Linux machine. Instead of connecting USB ports with a male-male connector, which is all kinds of bad (you are connecting the 5V lines of both machine with each other!), just run Wireshark in the controller PC.
There might be a little work to be done previously, as you have to enable Wireshark for USB monitoring (Particularly in Debian, this is disabled by default), and you might have to install a small driver to enable the monitoring. Have a look at this page for more information.
Once you get it working, Wireshark is an excellent tool for this!

airodump-ng is malfunctioning

I'm on Kali-linux 32 bits on Oracle VM VirtualBox, and I have this problem with airodump-ng,
I got my wireless card's interface name, put it into monitoring mode with airmon-ng command, but when I attempt to locate the available wireless networks nearby, the airodump-ng tool displays ZERO access points:
I just want to add that the wlan interface didn't show up at first, so I downloaded and installed compat wireless.
the virtual box cannot virtualize the Wifi card, so u need an externe network adapter able to be switched to monitoring mode, u can see at wiki-linux. or install it on your physical machine if your network adapter is compatible.
I suggest you to check if your wireless adapter is compatible with kali-linux. You can check here for suggested wireless adapter.
For my case i am using TP-link wn722n wireless adapter which work fine with kali linux. You can simply switch the wireless interface to monitor mode by using the command below without using airmon-ng command.
Iwconfig [Interface name] mode monitor

Tracing traffic in Linux-based usb gadget (CDC/NCM)

I have a linux platform* that is connected as a usb device to an automotive device which acts as the USB host. The two devices should communicate over CDC/NCM, but the linux platform is not recognised by the automotive device and therefore the connection is not established. Surprisingly a connection to my computer is established correctly.
I now need to create a trace of that USB connection in order to check if there is an error in the USB handshake that can't be handled by the automotive device. As I cannot access the USB host, I need to create the trace from the gadget side.
I tried using usbmon and tcpdump, but this seems to work only for USB controllers configured as hosts on the tracing platform, not for ones configured as devices.
How can I configure usbmon to work also on devices?
If that is not possible are there any other possibilities to achieve this? (preferrably without hacking any drivers...)
Or do I have to use a Hardware USB sniffer?
BTW, all required modules (esp. g_ncm) are correctly loaded.
Thank you for your help!
stefan
*custom distribution on a freescale iMX6 processor (ARM), Kernel Version 3.0.35

Resources