The source of embedded Wi-F and the difference with ordinary Wi-Fi
First let's take a look at the source of embedded Wi-F and the difference with ordinary Wi-Fi. We all know that notebooks, mobile phones, tablets and other products have powerful CPU and large-capacity memory for processing and storing network communication data, so no additional MCU is needed when using WIFI, completely relying on its high-speed processor and huge Software system. However, for smart home products such as home appliances, meters, and LED lights, because the main control chips of such products may be MCUs with low cost and simple functions, such products cannot support the functions of ordinary Wi-Fi. At the same time, another important reason is that the power consumption of ordinary Wi-F is relatively high, and the embedded WIFI has greatly improved the power consumption, and is more suitable for wireless home appliances with high power consumption requirements. Based on the above reasons, various wireless vendors have introduced embedded WIFI modules. The embedded WIFI module features high integration of software and hardware. The entire embedded WIFI module integrates RF transceiver, MAC, WIFI driver, all WIFI protocol, wireless security protocol, one-button connection and so on. In short, one sentence: embedded WIFI should be born in the Internet of Things! Below we compare the embedded WIFI with the ordinary WIFI. Through the comparison of the following table, we can basically understand what is embedded WIFI. Before analyzing the WIFI driver, share some of my understanding of the Linux driver. In fact, looking at Linux's numerous device drivers, almost all use the bus as the carrier. All data transmission is based on the bus, even if the device does not have a so-called bus. Interface, but Linux will still add a virtual bus to it, such as platform bus; the driver between WIFI is too large, and it is based on the more complicated USB bus, so I suggest you first understand the USB device driver and network. Device driver. We must understand the WIFI driver, we must first understand the working principle of WIFI. Drivers for WIFI chips that support the relatively wireless standards of 802.11n and 802.11ac will become more and more complex. So how do we get to understand and analyze it? Many people on the Internet analyze Linux device drivers from the module loading to analyze its driver source. With my years of experience in Linux device drivers, this is really a very intuitive and very good idea. However, this is limited to device drivers with fewer device functions, simpler interfaces, and fewer driver source code. For a device driver with complex functions and huge source code, according to this idea, many developers may go without patience or go to a dead end. Now we can look at it from the hardware level, the WIFI device communicates with the CPU through the USB interface, and the communication with other WIFI devices is through the radio frequency (RF). From the software level, the Linux operating system needs to manage the WIFI device, then the WIFI device must be mounted on the USB bus and managed through the USB subsystem. At the same time, in order to connect the network, the WIFI device is packaged into a network device. We analyze it with the WIFI module of USB interface: (1) From the perspective of the USB bus, it is a USB device; (2) From the classification of Linux devices, it is a network device; (3) From the perspective of WIFI itself, it has its own unique functions and attributes, so it is a private device; Through the above analysis, we only need to grasp these three clues to analyze its driver source code in depth, and the entire WIFI driver framework will come to you. 1. Now let's start with a USB device and write a USB device driver. The general steps are as follows: (1) A USB driver needs to be defined for the device, and a usb_driver structure variable is defined corresponding to the code. code show as below: Struct usb_driver xxx_usb_wifi_driver; (2) Fill the usb_driver structure member variable of the device. code show as below: Static struct usb_driver xxx_usb_wifi_driver = { .name = "XXX_USB_WIFI", .probe= xxx_probe, .disconnect= xxx_disconnect, .suspend= xxx_suspend, .resume= xxx_resume, .id_table= xxx_table, }; (3) Register the driver to the USB subsystem. code show as below: Usb_register(&xxx_usb_wifi_driver); The above steps are just a rough USB driver framework flow, and the biggest and most complicated task is to populate the usb_driver structure member variable. The main work of the above steps is to mount the WIFI device of the USB interface to the USB bus, so that the Linux system can find the device on the USB bus. 2. Next is the clue of the network device. The approximate steps of the network device driver are as follows: (1) Define a net_device structure variable ndev. code show as below: Struct net_device *ndev; (2) Initialize the ndev variable and allocate memory. code show as below: Ndev=alloc_etherdev(); (3) Fill the ndev -> netdev_ops structure member variable. code show as below: Static const struct net_device_ops xxx_netdev_ops= { .ndo_init= xxx_ndev_init, .ndo_uninit= xxx _ndev_uninit, .ndo_open= netdev_open, .ndo_stop= netdev_close, .ndo_start_xmit= xxx_xmit_entry, .ndo_set_mac_address= xxx_net_set_mac_address, .ndo_get_stats= xxx_net_get_stats, .ndo_do_ioctl= xxx_ioctl, }; (4) Fill the ndev->wireless_handlers structure member variable, which is a wireless extension function. code show as below: Ndev->wireless_handlers = (struct iw_handler_def *)&xxx_handlers_def; (5) Register the ndev device to the network subsystem. code show as below: Register_netdev(ndev); 3. The functions and attributes of the WIFI device itself, such as its own configuration and initialization, the establishment of interactive interfaces with user space, and the implementation of its own functions. (1) Its own configuration and initialization. code show as below: Xxx_read_chip_info(); Xxx_chip_configure(); Xxx_hal_init(); (2) Mainly to establish an interactive interface with user space on the proc and sys file systems. code show as below: Xxx_drv_proc_init(); Xxx_ndev_notifier_register(); (3) The realization of its own functions. In the previous chapters, we have explained the WIFI network and access principles, such as scanning. At the same time, because WIFI is relatively large in mobile devices, power consumption and power management are also reflected in the driver. Shenzhen Ousida Technology Co., Ltd , https://www.osdvape.com