⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctrl_iface.c

📁 WLAN无线网络管理的最新程序
💻 C
📖 第 1 页 / 共 3 页
字号:
		if (ret < 0 || ret >= end - pos)			return pos;		pos += ret;	}	ret = os_snprintf(pos, end - pos, "]");	if (ret < 0 || ret >= end - pos)		return pos;	pos += ret;	return pos;}static int wpa_supplicant_ctrl_iface_scan_results(	struct wpa_supplicant *wpa_s, char *buf, size_t buflen){	char *pos, *end;	struct wpa_scan_result *res;	int i, ret;	if (wpa_s->scan_results == NULL &&	    wpa_supplicant_get_scan_results(wpa_s) < 0)		return 0;	if (wpa_s->scan_results == NULL)		return 0;	pos = buf;	end = buf + buflen;	ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "			  "flags / ssid\n");	if (ret < 0 || ret >= end - pos)		return pos - buf;	pos += ret;	for (i = 0; i < wpa_s->num_scan_results; i++) {		res = &wpa_s->scan_results[i];		ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",				  MAC2STR(res->bssid), res->freq, res->level);		if (ret < 0 || ret >= end - pos)			return pos - buf;		pos += ret;		if (res->wpa_ie_len) {			pos = wpa_supplicant_ie_txt(pos, end, "WPA",						    res->wpa_ie,						    res->wpa_ie_len);		}		if (res->rsn_ie_len) {			pos = wpa_supplicant_ie_txt(pos, end, "WPA2",						    res->rsn_ie,						    res->rsn_ie_len);		}		if (!res->wpa_ie_len && !res->rsn_ie_len &&		    res->caps & IEEE80211_CAP_PRIVACY) {			ret = os_snprintf(pos, end - pos, "[WEP]");			if (ret < 0 || ret >= end - pos)				return pos - buf;			pos += ret;		}		if (res->caps & IEEE80211_CAP_IBSS) {			ret = os_snprintf(pos, end - pos, "[IBSS]");			if (ret < 0 || ret >= end - pos)				return pos - buf;			pos += ret;		}		ret = os_snprintf(pos, end - pos, "\t%s",				  wpa_ssid_txt(res->ssid, res->ssid_len));		if (ret < 0 || ret >= end - pos)			return pos - buf;		pos += ret;		ret = os_snprintf(pos, end - pos, "\n");		if (ret < 0 || ret >= end - pos)			return pos - buf;		pos += ret;	}	return pos - buf;}static int wpa_supplicant_ctrl_iface_select_network(	struct wpa_supplicant *wpa_s, char *cmd){	int id;	struct wpa_ssid *ssid;	/* cmd: "<network id>" or "any" */	if (os_strcmp(cmd, "any") == 0) {		wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");		ssid = wpa_s->conf->ssid;		while (ssid) {			ssid->disabled = 0;			ssid = ssid->next;		}		wpa_s->reassociate = 1;		wpa_supplicant_req_scan(wpa_s, 0, 0);		return 0;	}	id = atoi(cmd);	wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);	ssid = wpa_config_get_network(wpa_s->conf, id);	if (ssid == NULL) {		wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "			   "id=%d", id);		return -1;	}	if (ssid != wpa_s->current_ssid && wpa_s->current_ssid)		wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);	/* Mark all other networks disabled and trigger reassociation */	ssid = wpa_s->conf->ssid;	while (ssid) {		ssid->disabled = id != ssid->id;		ssid = ssid->next;	}	wpa_s->reassociate = 1;	wpa_supplicant_req_scan(wpa_s, 0, 0);	return 0;}static int wpa_supplicant_ctrl_iface_enable_network(	struct wpa_supplicant *wpa_s, char *cmd){	int id;	struct wpa_ssid *ssid;	/* cmd: "<network id>" */	id = atoi(cmd);	wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);	ssid = wpa_config_get_network(wpa_s->conf, id);	if (ssid == NULL) {		wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "			   "id=%d", id);		return -1;	}	if (wpa_s->current_ssid == NULL && ssid->disabled) {		/*		 * Try to reassociate since there is no current configuration		 * and a new network was made available. */		wpa_s->reassociate = 1;		wpa_supplicant_req_scan(wpa_s, 0, 0);	}	ssid->disabled = 0;	return 0;}static int wpa_supplicant_ctrl_iface_disable_network(	struct wpa_supplicant *wpa_s, char *cmd){	int id;	struct wpa_ssid *ssid;	/* cmd: "<network id>" */	id = atoi(cmd);	wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);	ssid = wpa_config_get_network(wpa_s->conf, id);	if (ssid == NULL) {		wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "			   "id=%d", id);		return -1;	}	if (ssid == wpa_s->current_ssid)		wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);	ssid->disabled = 1;	return 0;}static int wpa_supplicant_ctrl_iface_add_network(	struct wpa_supplicant *wpa_s, char *buf, size_t buflen){	struct wpa_ssid *ssid;	int ret;	wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");	ssid = wpa_config_add_network(wpa_s->conf);	if (ssid == NULL)		return -1;	ssid->disabled = 1;	wpa_config_set_network_defaults(ssid);	ret = os_snprintf(buf, buflen, "%d\n", ssid->id);	if (ret < 0 || (size_t) ret >= buflen)		return -1;	return ret;}static int wpa_supplicant_ctrl_iface_remove_network(	struct wpa_supplicant *wpa_s, char *cmd){	int id;	struct wpa_ssid *ssid;	/* cmd: "<network id>" */	id = atoi(cmd);	wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);	ssid = wpa_config_get_network(wpa_s->conf, id);	if (ssid == NULL ||	    wpa_config_remove_network(wpa_s->conf, id) < 0) {		wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "			   "id=%d", id);		return -1;	}	if (ssid == wpa_s->current_ssid) {		/*		 * Invalidate the EAP session cache if the current network is		 * removed.		 */		eapol_sm_invalidate_cached_session(wpa_s->eapol);		wpa_supplicant_disassociate(wpa_s, REASON_DEAUTH_LEAVING);	}	return 0;}static int wpa_supplicant_ctrl_iface_set_network(	struct wpa_supplicant *wpa_s, char *cmd){	int id;	struct wpa_ssid *ssid;	char *name, *value;	/* cmd: "<network id> <variable name> <value>" */	name = os_strchr(cmd, ' ');	if (name == NULL)		return -1;	*name++ = '\0';	value = os_strchr(name, ' ');	if (value == NULL)		return -1;	*value++ = '\0';	id = atoi(cmd);	wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",		   id, name);	wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",			      (u8 *) value, os_strlen(value));	ssid = wpa_config_get_network(wpa_s->conf, id);	if (ssid == NULL) {		wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "			   "id=%d", id);		return -1;	}	if (wpa_config_set(ssid, name, value, 0) < 0) {		wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "			   "variable '%s'", name);		return -1;	}	if (wpa_s->current_ssid == ssid) {		/*		 * Invalidate the EAP session cache if anything in the current		 * configuration changes.		 */		eapol_sm_invalidate_cached_session(wpa_s->eapol);	}	if ((os_strcmp(name, "psk") == 0 &&	     value[0] == '"' && ssid->ssid_len) ||	    (os_strcmp(name, "ssid") == 0 && ssid->passphrase))		wpa_config_update_psk(ssid);	return 0;}static int wpa_supplicant_ctrl_iface_get_network(	struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen){	int id;	struct wpa_ssid *ssid;	char *name, *value;	/* cmd: "<network id> <variable name>" */	name = os_strchr(cmd, ' ');	if (name == NULL || buflen == 0)		return -1;	*name++ = '\0';	id = atoi(cmd);	wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",		   id, name);	ssid = wpa_config_get_network(wpa_s->conf, id);	if (ssid == NULL) {		wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "			   "id=%d", id);		return -1;	}	value = wpa_config_get_no_key(ssid, name);	if (value == NULL) {		wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "			   "variable '%s'", name);		return -1;	}	os_snprintf(buf, buflen, "%s", value);	buf[buflen - 1] = '\0';	os_free(value);	return os_strlen(buf);}static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s){	int ret;	if (!wpa_s->conf->update_config) {		wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "			   "to update configuration (update_config=0)");		return -1;	}	ret = wpa_config_write(wpa_s->confname, wpa_s->conf);	if (ret) {		wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "			   "update configuration");	} else {		wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"			   " updated");	}	return ret;}static int wpa_supplicant_ctrl_iface_get_capability(	struct wpa_supplicant *wpa_s, const char *_field, char *buf,	size_t buflen){	struct wpa_driver_capa capa;	int res, first = 1, ret;	char *pos, *end, *strict;	char field[30];	/* Determine whether or not strict checking was requested */	os_snprintf(field, sizeof(field), "%s", _field);	field[sizeof(field) - 1] = '\0';	strict = os_strchr(field, ' ');	if (strict != NULL) {		*strict++ = '\0';		if (os_strcmp(strict, "strict") != 0)			return -1;	}	wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",		field, strict ? strict : "");	if (os_strcmp(field, "eap") == 0) {		return eap_get_names(buf, buflen);	}	res = wpa_drv_get_capa(wpa_s, &capa);	pos = buf;	end = pos + buflen;	if (os_strcmp(field, "pairwise") == 0) {		if (res < 0) {			if (strict)				return 0;			ret = os_snprintf(buf, buflen, "CCMP TKIP NONE");			if (ret < 0 || (size_t) ret >= buflen)				return -1;			return ret;		}		if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {			ret = os_snprintf(pos, end - pos, "%sCCMP",					  first ? "" : " ");			if (ret < 0 || ret >= end - pos)				return pos - buf;			pos += ret;			first = 0;		}		if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {			ret = os_snprintf(pos, end - pos, "%sTKIP",					  first ? "" : " ");			if (ret < 0 || ret >= end - pos)				return pos - buf;			pos += ret;			first = 0;		}		if (capa.key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {			ret = os_snprintf(pos, end - pos, "%sNONE",					  first ? "" : " ");			if (ret < 0 || ret >= end - pos)				return pos - buf;			pos += ret;			first = 0;		}		return pos - buf;	}	if (os_strcmp(field, "group") == 0) {		if (res < 0) {			if (strict)				return 0;			ret = os_snprintf(buf, buflen,					  "CCMP TKIP WEP104 WEP40");			if (ret < 0 || (size_t) ret >= buflen)				return -1;			return ret;		}		if (capa.enc & WPA_DRIVER_CAPA_ENC_CCMP) {			ret = os_snprintf(pos, end - pos, "%sCCMP",					  first ? "" : " ");			if (ret < 0 || ret >= end - pos)				return pos - buf;			pos += ret;			first = 0;		}		if (capa.enc & WPA_DRIVER_CAPA_ENC_TKIP) {			ret = os_snprintf(pos, end - pos, "%sTKIP",					  first ? "" : " ");			if (ret < 0 || ret >= end - pos)				return pos - buf;			pos += ret;			first = 0;		}		if (capa.enc & WPA_DRIVER_CAPA_ENC_WEP104) {			ret = os_snprintf(pos, end - pos, "%sWEP104",					  first ? "" : " ");			if (ret < 0 || ret >= end - pos)				return pos - buf;			pos += ret;			first = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -