MAC layer protocols like WiFi/WLAN, Zigbee, Bluetooth, and Ethernet are of prime importance in IoT applications. WiFi/WLAN is one of the most commonly utilized wireless solutions in home automation, smart farming, office automation, and Industrial IoT. It is highly critical for controllers in IoT devices to identify and connect with available WiFi networks and effectively communicate data packets over a secure channel. WiFi, despite having a limited range, offers incredible bandwidth such that even applications like live streaming can be easily hosted over a WiFi network. WiFi-based IoT applications need to accomplish one thing, whether they require a large bandwidth or not: WiFi Sniffing.
In network engineering, a WiFi Sniffer is a network analyzer designed to capture packet data on the wireless network. In embedded applications, a dedicated WiFi Sniffer is rarely required to monitor a WiFi network. However, some functionalities of a WiFi Sniffer are often needed to be built within IoT devices. One such functionality is the identification of available WiFi networks and the ability to connect with an available WiFi channel. In this article, we will examine precisely what a WiFi Sniffer is? Why is it required in a wireless network? How is WiFi sniffing used in embedded applications? How can WiFi sniffing be implemented in MicroPython ports?
What is a WiFi Sniffer?
A WiFi Sniffer is a passive listening device that captures WiFi network frames of a particular WiFi channel in the air. A Sniffer only listens for WiFi network packets of a specific bandwidth within their range of listening capacity. Currently, WiFi networks use only two bandwidths – 2.4 GHz and 5 GHz. The latest WiFi version, i.e., WiFi 6E, uses an additional 6 GHz bandwidth.
A dedicated WiFi Sniffer specifically deployed to monitor the wireless network shares the same channel that acts as a communication medium between an access point and station devices and keeps capturing wireless frames to monitor and log information about wireless traffic into a file. A WiFi Sniffer captures all the frames communicated between a WiFi access point and a device acting as a WiFi station on the same channel but does not process frames or respond to the network. Dedicated WiFi Sniffers are only required in those IoT applications in which it is important to ensure wireless connectivity of the network or large bandwidth data is frequently communicated within the network, like in the case of video streaming or a highly active large-scale sensor network.
Applications of WiFi Sniffer
WiFi sniffing is used to scan devices within a wireless network. It also sets up connection procedures between station devices and WiFi access points. During network deployment, WiFi sniffing is often used to verify the frame’s correctness and ensure that frames are transmitted in the air. The protocol is also used to confirm the compatibility of devices with the WiFi network. WiFi sniffing is often used for network validation and pre-certification of WiFi-enabled devices. Last but not least, WiFi sniffing is also used for troubleshooting WiFi networks and station devices within the network.
Types of WiFi Sniffer
There are two types of WiFi Sniffers: software-based and dedicated. The software-based WiFi Sniffers are software applications or built-in features within an application designed for WiFi sniffing. The software driver needs to be installed on a WiFi adaptor to perform sniffing. WiFi sniffing software could often be incompatible with the intended hardware platform. A dedicated WiFi Sniffer is a WiFi adaptor with WiFi sniffing capability built into its software or firmware.
Use of WiFi Sniffer in embedded microcontrollers
Microcontrollers are often not much capable in terms of acting as full-fledged WiFi Sniffer. However, WiFi-enabled microcontrollers are often programmed to perform some of the functions of WiFi sniffing. This includes identifying WiFi access points and connecting other station devices on the same network once connected. The functionality to communicate with a WiFi network for data communication over the internet is also a WiFi sniffing function. The functionality to reset and reconnect with a WiFi network is another WiFi sniffing function.
WiFi sniffing in MicroPython ports
Most of the MicroPython ports have on-board or on-chip WiFi. These microcontrollers are already WiFi adaptors that can connect with a WiFi network as both a station device and an access point. Fortunately, the network module of MicroPython has been developed to connect and communicate with a WiFi network. The WLAN class from the network module can scan the MAC address of all the devices connected to the WiFi network. The same class configures the port as a WiFi access point or a station device.
MicroPython script for WiFi sniffing
You can upload the following MicroPython script to any WiFi-enabled MicroPython port. The script scans available WiFi networks and lists devices’ MAC addresses in the range.
The code begins with importing the WLAN class from the WiFi module. Next, the ubinascii module is imported to enable the conversion of binary data into ASCII form. A function scan_wifi is defined in which the MAC address, WiFi packet, and control bit of the packet is retrieved. The control bit is used to identify the type of MAC address. If the MAC address is valid, it is printed to the console. An object of the WLAN class is instantiated in the code, and the scan_wifi function is called a callback function as soon as a management packet is received in the promiscuous mode. The promiscuous mode of on-port WiFi is enabled by calling wlan.promiscuous() method. The promiscuous mode ensures that every transmitted data packet is received and read by the WiFi adaptor.
You may also like:
Filed Under: Featured, Featured Contributions, Tech Articles
Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.