Wi-Fi源码分析之WifiService操作Wi-Fi(一)
分析Wifi.c中的wifi_load_driver()函数
int wifi_load_driver()
{
ALOGD("============wifi_load_driver================");
/* WIFI_DRIVER_MODULE_PATH定义wlan driver的文件路径名. 我这里并没有定义 */
#ifdef WIFI_DRIVER_MODULE_PATH
ALOGD("============wifi_load_driver:WIFI_DRIVER_MODULE_PATH================");
char driver_status[PROPERTY_VALUE_MAX];
int count = 100; /* wait at most 20 seconds for completion */
if (is_wifi_driver_loaded()) {
return 0;
}
/* DRIVER_MODULE_PATH里保存WIFI_DRIVER_MODULE_PATH宏定义的文件路径名; * 如果WIFI_DRIVER_MODULE_PATH定义了就在此处通过 insmod向内核添加wlan driver*/
if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0)
return -1;
/* FIRMWARE_LOADER 变量指向 WIFI_FIRMWARE_LOADER宏定义的 wlan 固件加载程序文件路径名 * DRIVER_PROP_NAME 的值为"wlan.driver.status"; * 如果没有指定 wlan 固件加载程序,则直接设置"wlan.driver.status"的属性为"ok" * 否则 通过"ctl.start"方式来启动 wlan 固件加载程序 * */
if (strcmp(FIRMWARE_LOADER,"") == 0) {
/* usleep(WIFI_DRIVER_LOADER_DELAY); */
property_set(DRIVER_PROP_NAME, "ok");
}
else {
property_set("ctl.start", FIRMWARE_LOADER);
}
sched_yield();
while (count-- > 0) {
if (property_get(DRIVER_PROP_NAME, driver_status, NULL)) {
if (strcmp(driver_status, "ok") == 0)
return 0;
else if (strcmp(DRIVER_PROP_NAME, "failed") == 0) {
wifi_unload_driver();
return -1;
}
}
usleep(200000);
}
property_set(DRIVER_PROP_NAME, "timeout");
wifi_unload_driver();
return -1;
#else
/*如果没有定义宏WIFI_DRIVER_MODULE_PATH,则直接设置"wlan.driver.status"的属性为"ok"*/
property_set(DRIVER_PROP_NAME, "ok");
return 0;
#endif
}