Пример #1
0
void * wpa_driver_wext_init(void *ctx, const char *ifname)
{
	int s, flags;
	struct sockaddr_nl local;
	struct wpa_driver_wext_data *drv;

	drv = malloc(sizeof(*drv));
	if (drv == NULL)
		return NULL;
	memset(drv, 0, sizeof(*drv));
	drv->ctx = ctx;
	strncpy(drv->ifname, ifname, sizeof(drv->ifname));

	drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
	if (drv->ioctl_sock < 0) {
		perror("socket(PF_INET,SOCK_DGRAM)");
		free(drv);
		return NULL;
	}

	s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
	if (s < 0) {
		perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
		close(drv->ioctl_sock);
		free(drv);
		return NULL;
	}

	memset(&local, 0, sizeof(local));
	local.nl_family = AF_NETLINK;
	local.nl_groups = RTMGRP_LINK;
	if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
		perror("bind(netlink)");
		close(s);
		close(drv->ioctl_sock);
		free(drv);
		return NULL;
	}

	eloop_register_read_sock(s, wpa_driver_wext_event_receive, drv, ctx);
	drv->event_sock = s;

	/*
	 * Make sure that the driver does not have any obsolete PMKID entries.
	 */
	wpa_driver_wext_flush_pmkid(drv);

	if (wpa_driver_wext_set_mode(drv, 0) < 0) {
		printf("Could not configure driver to use managed mode\n");
	}

	if (wpa_driver_wext_get_ifflags(drv, &flags) != 0 ||
	    wpa_driver_wext_set_ifflags(drv, flags | IFF_UP) != 0) {
		printf("Could not set interface '%s' UP\n", drv->ifname);
	}

	return drv;
}
Пример #2
0
void wpa_driver_wext_deinit(void *priv)
{
	struct wpa_driver_wext_data *drv = priv;
	int flags;

	eloop_unregister_read_sock(drv->event_sock);

	if (wpa_driver_wext_get_ifflags(drv, &flags) == 0)
		(void) wpa_driver_wext_set_ifflags(drv, flags & ~IFF_UP);

	close(drv->event_sock);
	close(drv->ioctl_sock);
	free(drv->assoc_req_ies);
	free(drv->assoc_resp_ies);
	free(drv);
}
Пример #3
0
/*-----------------------------------------------------------------------------
Routine Name: wpa_driver_tista_driver_cmd
Routine Description: executes driver-specific commands
Arguments:
   priv - pointer to private data structure
   cmd - command
   buf - return buffer
   buf_len - buffer length
Return Value: actual buffer length - success, -1 - failure
-----------------------------------------------------------------------------*/
static int wpa_driver_tista_driver_cmd( void *priv, char *cmd, char *buf, size_t buf_len )
{
    struct wpa_driver_ti_data *drv = (struct wpa_driver_ti_data *)priv;
    int ret = -1, prev_events, flags;

    wpa_printf(MSG_DEBUG, "%s %s", __func__, cmd);

    if( os_strcasecmp(cmd, "start") == 0 ) {
        wpa_printf(MSG_DEBUG,"Start command");
        scan_exit(drv); /* Clear scan cache */
        ret = wpa_driver_tista_driver_start(priv);
        if( ret == 0 ) {
            drv->driver_is_loaded = TRUE;
            wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "STARTED");
        }
        return( TI2WPA_STATUS(ret) );
    }

    TI_CHECK_DRIVER( drv->driver_is_loaded, -1 );

    if( os_strcasecmp(cmd, "stop") == 0 ) {
        wpa_printf(MSG_DEBUG,"Stop command");
        if ((wpa_driver_wext_get_ifflags(drv->wext, &flags) == 0) &&
                (flags & IFF_UP)) {
            wpa_printf(MSG_ERROR, "TI: %s when iface is UP", cmd);
            wpa_driver_wext_set_ifflags(drv->wext, flags & ~IFF_UP);
        }
        ret = wpa_driver_tista_driver_stop(priv);
        if( ret == 0 ) {
            scan_exit(drv); /* Clear scan cache */
            drv->driver_is_loaded = FALSE;
            wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "STOPPED");
        }
    }
    if( os_strcasecmp(cmd, "reload") == 0 ) {
        wpa_printf(MSG_DEBUG,"Reload command");
        ret = 0;
        wpa_msg(drv->ctx, MSG_INFO, WPA_EVENT_DRIVER_STATE "HANGED");
    }
    else if( os_strcasecmp(cmd, "macaddr") == 0 ) {
        wpa_driver_tista_get_mac_addr(priv);
        wpa_printf(MSG_DEBUG, "Macaddr command");
        ret = sprintf(buf, "Macaddr = " MACSTR "\n", MAC2STR(drv->own_addr));
        wpa_printf(MSG_DEBUG, "buf %s", buf);
    }
    else if( os_strcasecmp(cmd, "scan-passive") == 0 ) {
        wpa_printf(MSG_DEBUG,"Scan Passive command");
        drv->scan_type =  SCAN_TYPE_NORMAL_PASSIVE;
        ret = 0;
    }
    else if( os_strcasecmp(cmd, "scan-active") == 0 ) {
        wpa_printf(MSG_DEBUG,"Scan Active command");
        drv->scan_type =  SCAN_TYPE_NORMAL_ACTIVE;
        ret = 0;
    }
    else if( os_strcasecmp(cmd, "scan-mode") == 0 ) {
        wpa_printf(MSG_DEBUG,"Scan Mode command");
        ret = snprintf(buf, buf_len, "ScanMode = %u\n", drv->scan_type);
        if (ret < (int)buf_len) {
            return( ret );
        }
    }
    else if( os_strcasecmp(cmd, "linkspeed") == 0 ) {
        struct wpa_supplicant *wpa_s = (struct wpa_supplicant *)(drv->ctx);

        wpa_printf(MSG_DEBUG,"Link Speed command");
        drv->link_speed = wpa_s->link_speed / 1000000;
        ret = sprintf(buf,"LinkSpeed %u\n", drv->link_speed);
        wpa_printf(MSG_DEBUG, "buf %s", buf);
    }
    else if( os_strncasecmp(cmd, "scan-channels", 13) == 0 ) {
        int noOfChan;

        noOfChan = atoi(cmd + 13);
        wpa_printf(MSG_DEBUG,"Scan Channels command = %d", noOfChan);
        if( (noOfChan > 0) && (noOfChan <= MAX_NUMBER_OF_CHANNELS_PER_SCAN) )
            drv->scan_channels = noOfChan;
        ret = sprintf(buf,"Scan-Channels = %d\n", drv->scan_channels);
        wpa_printf(MSG_DEBUG, "buf %s", buf);
    }
    else if( os_strcasecmp(cmd, "rssi-approx") == 0 ) {
        scan_result_t *cur_res;
        struct wpa_supplicant *wpa_s = (struct wpa_supplicant *)(drv->ctx);
        scan_ssid_t *p_ssid;
        int rssi, len;

        wpa_printf(MSG_DEBUG,"rssi-approx command");

        if( !wpa_s )
            return( ret );
        cur_res = scan_get_by_bssid(drv, wpa_s->bssid);
        if( cur_res ) {
            p_ssid = scan_get_ssid(cur_res);
            if( p_ssid ) {
                len = (int)(p_ssid->ssid_len);
                rssi = cur_res->level;
                if( (len > 0) && (len <= MAX_SSID_LEN) && (len < (int)buf_len)) {
                    os_memcpy((void *)buf, (void *)(p_ssid->ssid), len);
                    ret = len;
                    ret += snprintf(&buf[ret], buf_len-len, " rssi %d\n", rssi);
                }
            }
        }
    }
    else if( os_strcasecmp(cmd, "rssi") == 0 ) {
        u8 ssid[MAX_SSID_LEN];
        scan_result_t *cur_res;
        struct wpa_supplicant *wpa_s = (struct wpa_supplicant *)(drv->ctx);
        int rssi_data, rssi_beacon, len;

        wpa_printf(MSG_DEBUG,"rssi command");

        ret = wpa_driver_tista_get_rssi(priv, &rssi_data, &rssi_beacon);
        if( ret == 0 ) {
            len = wpa_driver_tista_get_ssid(priv, (u8 *)ssid);
            wpa_printf(MSG_DEBUG,"rssi_data %d rssi_beacon %d", rssi_data, rssi_beacon);
            if( (len > 0) && (len <= MAX_SSID_LEN) ) {
                os_memcpy((void *)buf, (void *)ssid, len);
                ret = len;
                ret += sprintf(&buf[ret], " rssi %d\n", rssi_beacon);
                wpa_printf(MSG_DEBUG, "buf %s", buf);
                /* Update cached value */
                if( !wpa_s )
                    return( ret );
                cur_res = scan_get_by_bssid(drv, wpa_s->bssid);
                if( cur_res )
                    cur_res->level = rssi_beacon;
            }
            else
            {
                wpa_printf(MSG_DEBUG, "Fail to get ssid when reporting rssi");
                ret = -1;
            }
        }
    }
    else if( os_strncasecmp(cmd, "powermode", 9) == 0 ) {
        u32 mode;
        TPowerMgr_PowerMode tMode;

        mode = (u32)atoi(cmd + 9);
        wpa_printf(MSG_DEBUG,"Power Mode command = %u", mode);
        if( mode < POWER_MODE_MAX )
        {
            tMode.PowerMode = (PowerMgr_PowerMode_e)mode;
            tMode.PowerMngPriority = POWER_MANAGER_USER_PRIORITY;
            ret = wpa_driver_tista_config_power_management( priv, &tMode, 1 );
        }
    }
    else if (os_strncasecmp(cmd, "getpower", 8) == 0 ) {
        u32 mode;
        TPowerMgr_PowerMode tMode;

        os_memset(&tMode, 0, sizeof(TPowerMgr_PowerMode));
        ret = wpa_driver_tista_config_power_management( priv, &tMode, 0 );
        if( ret == 0 ) {
            ret = sprintf(buf, "powermode = %u\n", tMode.PowerMode);
            wpa_printf(MSG_DEBUG, "buf %s", buf);
        }
    }
    else if( os_strncasecmp(cmd, "btcoexmode", 10) == 0 ) {
        u32 mode;

        mode = (u32)atoi(cmd + 10);
        wpa_printf(MSG_DEBUG,"BtCoex Mode command = %u", mode);
        ret = wpa_driver_tista_enable_bt_coe( priv, mode );
        if( ret == 0 ) {
            drv->btcoex_mode = mode;
        }
    }
    else if( os_strcasecmp(cmd, "btcoexstat") == 0 ) {
        u32 status = drv->btcoex_mode;

        wpa_printf(MSG_DEBUG,"BtCoex Status");
        ret = wpa_driver_tista_get_bt_coe_status( priv, &status );
        if( ret == 0 ) {
            ret = sprintf(buf, "btcoexstatus = 0x%x\n", status);
            wpa_printf(MSG_DEBUG, "buf %s", buf);
        }
    }
    else if( os_strcasecmp(cmd, "rxfilter-start") == 0 ) {
        wpa_printf(MSG_DEBUG,"Rx Data Filter Start command");
        ret = wpa_driver_tista_driver_enable_rx_data_filter( priv );
    }
    else if( os_strcasecmp(cmd, "rxfilter-stop") == 0 ) {
        wpa_printf(MSG_DEBUG,"Rx Data Filter Stop command");
        ret = wpa_driver_tista_driver_disable_rx_data_filter( priv );
    }
    else if( os_strcasecmp(cmd, "rxfilter-statistics") == 0 ) {
        TCuCommon_RxDataFilteringStatistics stats;
        int len, i;

        os_memset(&stats, 0, sizeof(TCuCommon_RxDataFilteringStatistics));
        wpa_printf(MSG_DEBUG,"Rx Data Filter Statistics command");
        ret = wpa_driver_tista_driver_rx_data_filter_statistics( priv, &stats );
        if( ret == 0 ) {
            ret = snprintf(buf, buf_len, "RxFilterStat: %u", (u32)stats.unmatchedPacketsCount);
            for(i=0; ( i < MAX_DATA_FILTERS ); i++) {
                ret += snprintf(&buf[ret], buf_len-ret, " %u", (u32)stats.matchedPacketsCount[i]);
            }
            ret += snprintf(&buf[ret], buf_len-ret, "\n");
            if (ret >= (int)buf_len) {
                ret = -1;
            }
        }
    }
    else if( os_strncasecmp(cmd, "rxfilter-add", 12) == 0 ) {
        TRxDataFilterRequest dfreq;
        char *cp = cmd + 12;
        char *endp;
        int type;

        if (*cp != '\0') {
            type = (int)strtol(cp, &endp, 0);
            if (endp != cp) {
                wpa_printf(MSG_DEBUG,"Rx Data Filter Add [%d] command", type);
                ret = prepare_filter_struct( priv, type, &dfreq );
                if( ret == 0 ) {
                    ret = wpa_driver_tista_driver_rx_data_filter( priv, &dfreq, 1 );
                }
            }
        }
    }
    else if( os_strncasecmp(cmd, "rxfilter-remove",15) == 0 ) {
        TRxDataFilterRequest dfreq;
        char *cp = cmd + 15;
        char *endp;
        int type;

        if (*cp != '\0') {
            type = (int)strtol(cp, &endp, 0);
            if (endp != cp) {
                wpa_printf(MSG_DEBUG,"Rx Data Filter remove [%d] command", type);
                ret = prepare_filter_struct( priv, type, &dfreq );
                if( ret == 0 ) {
                    ret = wpa_driver_tista_driver_rx_data_filter( priv, &dfreq, 0 );
                }
            }
        }
    }
    else {
        wpa_printf(MSG_DEBUG,"Unsupported command");
    }
    return ret;
}
Пример #4
0
static int wpa_driver_tista_associate(void *priv,
                                      struct wpa_driver_associate_params *params)
{
    struct wpa_driver_ti_data *drv = priv;
    int allow_unencrypted_eapol;
    int value, flags, ret = 0;

    wpa_printf(MSG_DEBUG, "%s", __FUNCTION__);
    TI_CHECK_DRIVER( drv->driver_is_loaded, -1 );

#ifdef WPA_SUPPLICANT_VER_0_6_X
#ifdef ANDROID
    ((struct wpa_driver_wext_data *)(drv->wext))->skip_disconnect = 0;
#endif
#endif

    if (wpa_driver_wext_get_ifflags(drv->wext, &flags) == 0) {
        if (!(flags & IFF_UP)) {
            wpa_driver_wext_set_ifflags(drv->wext, flags | IFF_UP);
        }
    }

#if 0
    if (!params->bssid)
        wpa_driver_wext_set_bssid(drv->wext, NULL);
#endif

#ifdef WPA_SUPPLICANT_VER_0_5_X
    /* Set driver network mode (Adhoc/Infrastructure) according to supplied parameters */
    wpa_driver_wext_set_mode(drv->wext, params->mode);
#endif
    wpa_driver_tista_set_gen_ie(drv, params->wpa_ie, params->wpa_ie_len);

    if (params->wpa_ie == NULL || params->wpa_ie_len == 0)
        value = IW_AUTH_WPA_VERSION_DISABLED;
#ifdef WPA_SUPPLICANT_VER_0_6_X
    else if (params->wpa_ie[0] == WLAN_EID_RSN)
#else
    else if (params->wpa_ie[0] == RSN_INFO_ELEM)
#endif
        value = IW_AUTH_WPA_VERSION_WPA2;
#ifdef CONFIG_WPS
    else if (params->key_mgmt_suite == KEY_MGMT_WPS)
        value = IW_AUTH_WPA_VERSION_DISABLED;
#endif
    else
        value = IW_AUTH_WPA_VERSION_WPA;
    wpa_driver_tista_set_auth_param(drv, IW_AUTH_WPA_VERSION, value);
    value = wpa_driver_tista_cipher2wext(params->pairwise_suite);
    wpa_driver_tista_set_auth_param(drv, IW_AUTH_CIPHER_PAIRWISE, value);
    value = wpa_driver_tista_cipher2wext(params->group_suite);
    wpa_driver_tista_set_auth_param(drv, IW_AUTH_CIPHER_GROUP, value);
    value = wpa_driver_tista_keymgmt2wext(params->key_mgmt_suite);
    wpa_driver_tista_set_auth_param(drv, IW_AUTH_KEY_MGMT, value);
    value = params->key_mgmt_suite != KEY_MGMT_NONE ||
            params->pairwise_suite != CIPHER_NONE ||
            params->group_suite != CIPHER_NONE ||
#ifdef WPA_SUPPLICANT_VER_0_6_X
            (params->wpa_ie_len && (params->key_mgmt_suite != KEY_MGMT_WPS));
#else
            params->wpa_ie_len;
#endif
    wpa_driver_tista_set_auth_param(drv, IW_AUTH_PRIVACY_INVOKED, value);

    /* Allow unencrypted EAPOL messages even if pairwise keys are set when
     * not using WPA. IEEE 802.1X specifies that these frames are not
     * encrypted, but WPA encrypts them when pairwise keys are in use. */
    if (params->key_mgmt_suite == KEY_MGMT_802_1X ||
            params->key_mgmt_suite == KEY_MGMT_PSK)
        allow_unencrypted_eapol = 0;
    else
        allow_unencrypted_eapol = 1;

    wpa_driver_tista_set_auth_param(drv,
                                    IW_AUTH_RX_UNENCRYPTED_EAPOL,
                                    allow_unencrypted_eapol);

    if (params->freq)
        wpa_driver_wext_set_freq(drv->wext, params->freq);

    if (params->bssid) {
        wpa_printf(MSG_DEBUG, "wpa_driver_tista_associate: BSSID=" MACSTR,
                   MAC2STR(params->bssid));
        /* if there is bssid -> set it */
        if (os_memcmp(params->bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) != 0) {
            wpa_driver_wext_set_bssid(drv->wext, params->bssid);
        }
    }
    ret = wpa_driver_wext_set_ssid(drv->wext, params->ssid, params->ssid_len);
    return ret;
}
Пример #5
0
int wpa_driver_awext_set_ifflags(struct wpa_driver_awext_data *drv, int flags)
{
	return wpa_driver_wext_set_ifflags(drv->wext, flags);
}