static int get_driver_path(const char *mod, const char *path, char *buf) {
    DIR *dir;
    struct dirent *de;
    char modpath[SYSFS_PATH_MAX];
    int ret = 0;

    if ((dir = opendir(path))) {
        while ((de = readdir(dir))) {
            struct stat sb;
            if (de->d_name[0] == '.')
                continue;
            snprintf(modpath, SYSFS_PATH_MAX, "%s/%s", path, de->d_name);
            if (!strcmp(de->d_name, mod)) {
                strncpy(buf, modpath, SYSFS_PATH_MAX - 1);
                buf[SYSFS_PATH_MAX - 1] = '\0';
                ret = 1;
                break;
            }
            if (!stat(modpath, &sb) && (sb.st_mode & S_IFMT) == S_IFDIR)
                if ((ret = get_driver_path(mod, modpath, buf)))
                    break;
        }
        closedir(dir);
    }
    return ret;
}
int wifi_load_driver()
{
#ifdef WIFI_DRIVER_MODULE_PATH
    char driver_status[PROPERTY_VALUE_MAX];
    char modname[PROPERTY_VALUE_MAX];
    char modpath[SYSFS_PATH_MAX];
    int count = 100; /* wait at most 20 seconds for completion */

    if (is_wifi_driver_loaded()) {
        return 0;
    }

    if (!property_get(DRIVER_PATH_PROP, modpath, NULL)) {
        property_get(DRIVER_NAME_PROP, modname, NULL);
        strcat(modname, ".ko");
        if (!get_driver_path(modname, MODULE_DEFAULT_DIR, modpath))
            strcpy(modpath, WIFI_DRIVER_MODULE_PATH);
    }

    ALOGI("got module path %s", modpath);
    if (insmod(modpath, DRIVER_MODULE_ARG) < 0)
        return -1;

    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) {
                get_driver_info(modname);
                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
    property_set(DRIVER_PROP_NAME, "ok");
    return 0;
#endif
}
Exemplo n.º 3
0
/**
 * sysfs_open_driver: open driver by name, given its bus
 * @bus_name: Name of the bus
 * @drv_name: Name of the driver
 * Returns the sysfs_driver reference on success and NULL on failure
 */
struct sysfs_driver *sysfs_open_driver(const char *bus_name,
			const char *drv_name)
{
	char path[SYSFS_PATH_MAX];
	struct sysfs_driver *driver = NULL;

	if (!drv_name || !bus_name) {
		errno = EINVAL;
		return NULL;
	}

	memset(path, 0, SYSFS_PATH_MAX);
	if (get_driver_path(bus_name, drv_name, path, SYSFS_PATH_MAX)) {
		dprintf("Error getting to driver %s\n", drv_name);
		return NULL;
	}
	driver = sysfs_open_driver_path(path);
	if (!driver) {
		dprintf("Error opening driver at %s\n", path);
		return NULL;
	}
	return driver;
}