Android WiFi driver development diary (2)

Source: Internet
Author: User

In this project, the WiFi module is controlled by the sdio bus. Therefore, the structure of the sdio part of the client driver is recorded first. The sdio part is divided into three layers: sdiodrv, sdioadapter, and sdiobusdrv. Sdiobusdrv is the interface between sdio and WiFi modules in the client driver, sdioadapter is the Adaptation Layer Between sdiodrv and sdiobusdrv, and sdiodrv is the client
The interfaces of sdio in driver and MMC sdio in Linux kernel. The three parts only need to focus on sdiodrv, and the other two layers only encapsulate it.

These functions are provided in sdiodrv:

(1) Static struct sdio_driver tiwlan_sdio_drv = {
. Probe = tiwlan_sdio_probe,
. Remove = tiwlan_sdio_remove,
. Name = "sdio_tiwlan ",
. Id_table = tiwl12xx_devices,
};

(2) int sdiodrv_enablefunction (unsigned int ufunc)

(3) int sdiodrv_enableinterrupt (unsigned int ufunc)

(4) Reading and Writing sdio actually calls the static int mmc_io_rw_direct_host () function in MMC \ core.

The sdio function is easy to understand. Generally, some chip manufacturers of the host will do well. My main task is the WiFi module.

First, we can see from the entry function wlandrvif_moduleinit () of the WiFi module. Here we call wlandrvif_create ().

Code body:

Static intWlandrvif_create(Void)
{
Twlandrvifobj * DRV; // This struct represents a device, including the Linux network device struct net_device.

Pdrvstatichandle = DRV;/* save for module destroy */

DRV-> pworkqueue = create_singlethread_workqueue (tiwlan_drv_name); // a work queue is created.

/* Setup driver network interface .*/
Rc =Wlandrvif_setupnetif(DRV); // This function is very important. For details, refer to the following section.

DRV-> wl_sock = netlink_kernel_create (netlink_usersock, 0, null, null, this_module );

// Create a socket interface that accepts wpa_supplicant

/* Create all driver modules and link their handles */
Rc =Drvmain_create(DRV,
& DRV-> tcommon. hdrvmain,
& DRV-> tcommon. hcmdhndlr,
& DRV-> tcommon. hcontext,
& DRV-> tcommon. htxdataq,
& DRV-> tcommon. htxmgmtq,
& DRV-> tcommon. htxctrl,
& DRV-> tcommon. htwd,
& DRV-> tcommon. hevhandler,
& DRV-> tcommon. hsf-dispatch,
& DRV-> tcommon. hreport,
& DRV-> tcommon. hpwrstate );

/*
* Initialize interrupts (or polling mode for Debug ):
*/

/* Normal Mode: interrupts (the default mode )*/
Rc =Hplatform_initinterrupt(DRV, (void *) wlandrvif_handleinterrupt );

Return 0;

}

After the wlandrvif_create () function is called, the initialization of the WiFi module is complete. The following describes how to initialize the function. First lookWlandrvif_setupnetif
(DRV) the main body of this function,

Static int wlandrvif_setupnetif (twlandrvifobj * DRV)
{
Struct net_device * dev;
Int res;

/* Allocate network interface structure for the driver */
Dev = alloc_etherdev (0); // apply for a Linux Network Device
If (Dev = NULL)

/* Setup the network interface */
Ether_setup (Dev); // creates network interfaces, both of which are standard functions driven by Linux network devices.

Dev-> netdev_ops = & wlan_netdev_ops;

/* Initialize wireless extensions interface (wext )*/
Wlandrvwext_init (Dev );

Res = register_netdev (Dev );

/* Setup power-management callbacks */
Hplatform_setuppm (wlandrvif_suspend, wlandrvif_resume, pdrvstatichandle );

}

Note that wlandrvwext_inti (Dev) is initialized here, which means that the direct connection between wpa_supplicant and driver is based on the wext path. That is to say, the event reception and processing should also be done in wext. Make sure that this reduces the remaining workload by 1/3, hahaha. The network device Dev is also registered later. The features defined in wlan_netdev_ops are as follows:

Static const struct net_device_ops wlan_netdev_ops = {
. Ndo_open = wlandrvif_open,
. Ndo_stop = wlandrvif_release,
. Ndo_do_ioctl = NULL,

. Ndo_start_xmit = wlandrvif_xmit,
. Ndo_get_stats = wlandrvif_netgetstat,
. Ndo_validate_addr = NULL,

};

The functions can be viewed by name. If you do not need to mention them, the corresponding commands are all available for Linux network device drivers. For details, see chapter 16th of Linux device driver development.

After that, Rc = is called again.Drvmain_createi.


The initialization of related modules is completed in this function. Not to mention it. The next step is to wait for the event sent by the android upper layer.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.