Пример #1
0
size_t
read_hwaddr_aton(uint8_t **data, const char *path)
{
	FILE *fp;
	char *buf;
	size_t buf_len, len;
	ssize_t llen;

	if ((fp = fopen(path, "r")) == NULL)
		return 0;

	buf = NULL;
	buf_len = len = 0;
	*data = NULL;
	while ((llen = getline(&buf, &buf_len, fp)) != -1) {
		if ((len = hwaddr_aton(NULL, buf)) != 0) {
			if (buf_len >= len)
				*data = (uint8_t *)buf;
			else {
				if ((*data = malloc(len)) == NULL)
					len = 0;
			}
			if (len != 0)
				(void)hwaddr_aton(*data, buf);
			if (buf_len < len)
				free(buf);
			break;
		}
	}
	fclose(fp);
	return len;
}
Пример #2
0
/* Based on the implementation here 
http://www.thegeekstuff.com/2012/10/packet-sniffing-using-libpcap*/
void* read_virtual_interface(){
    //char *virtual_dev;
    char errbuf[PCAP_ERRBUF_SIZE];
    struct bpf_program fp;        /* to hold compiled program */
    bpf_u_int32 pMask;            /* subnet mask */
    bpf_u_int32 pNet;             /* ip address*/
    //pcap_if_t *alldevs, *d;
    //char dev_buff[64] = {0};

	printf("Malloc 1\n");
    ep1_mac_addr = (u_char *)malloc(ETHER_ADDR_LEN * sizeof(u_char));
    hwaddr_aton(ep1_hwaddr, ep1_mac_addr);

    printf("Malloc 2\n");
    wlan_mac_addr = (u_char *)malloc(ETHER_ADDR_LEN * sizeof(u_char));
    hwaddr_aton(wlan_hwaddr, wlan_mac_addr);

    printf("Malloc 3\n");
    gateway_mac_addr = (u_char *)malloc(ETHER_ADDR_LEN *sizeof(u_char));
    hwaddr_aton(gateway_hwaddr, gateway_mac_addr);

	ep1s_mac_addr = (u_char *)malloc(ETHER_ADDR_LEN * sizeof(u_char));
	hwaddr_aton(ep1s_hwaddr, ep1s_mac_addr);

    //virtual_dev = "ep1s";
    // fetch the network address and network mask
    pcap_lookupnet(virtual_dev, &pNet, &pMask, errbuf);

    // Now, open device for sniffing
    ep1s_descr = pcap_open_live(virtual_dev, BUFSIZ, 0,-1, errbuf);
    if(ep1s_descr == NULL)
    {
        printf("pcap_open_live() failed due to [%s]\n", errbuf);
		exit(1);
    }

    // Compile the filter expression
    if(pcap_compile(ep1s_descr, &fp, '\0', 0, pNet) == -1)
    {
        printf("\npcap_compile() failed\n");
        exit(1);
    }

    // Set the filter compiled above
    if(pcap_setfilter(ep1s_descr, &fp) == -1)
    {
        printf("\npcap_setfilter() failed\n");
        exit(1);
    }

    // For every packet received, call the callback function
    // For now, maximum limit on number of packets is specified
    // by user.
    pcap_loop(ep1s_descr, -1, callback, NULL);

	pcap_close(ep1s_descr);
    printf("\nDone with packet sniffing on ep1s!\n");
    return 0;
}
Пример #3
0
static int bgscan_learn_load(struct bgscan_learn_data *data)
{
	FILE *f;
	char buf[128];
	struct bgscan_learn_bss *bss;

	if (data->fname == NULL) {
		return 0;
	}

	f = fopen(data->fname, "r");
	if (f == NULL) {
		return 0;
	}

	wpa_printf(MSG_DEBUG, "bgscan learn: Loading data from %s", data->fname);

	if (fgets(buf, sizeof(buf), f) == NULL || os_strncmp(buf, "wpa_supplicant-bgscan-learn\n", 28) != 0) {
		wpa_printf(MSG_INFO, "bgscan learn: Invalid data file %s", data->fname);
		fclose(f);
		return -1;
	}

	while (fgets(buf, sizeof(buf), f)) {
		if (os_strncmp(buf, "BSS ", 4) == 0) {
			bss = os_zalloc(sizeof(*bss));
			if (!bss) {
				continue;
			}
			if (hwaddr_aton(buf + 4, bss->bssid) < 0) {
				bss_free(bss);
				continue;
			}
			bss->freq = atoi(buf + 4 + 18);
			dl_list_add(&data->bss, &bss->list);
			wpa_printf(MSG_DEBUG, "bgscan learn: Loaded BSS " "entry: " MACSTR " freq=%d", MAC2STR(bss->bssid), bss->freq);
		}

		if (os_strncmp(buf, "NEIGHBOR ", 9) == 0) {
			u8 addr[ETH_ALEN];

			if (hwaddr_aton(buf + 9, addr) < 0) {
				continue;
			}
			bss = bgscan_learn_get_bss(data, addr);
			if (bss == NULL) {
				continue;
			}
			if (hwaddr_aton(buf + 9 + 18, addr) < 0) {
				continue;
			}

			bgscan_learn_add_neighbor(bss, addr);
		}
	}

	fclose(f);
	return 0;
}
Пример #4
0
static int cmd_get_sta_counter(int s, int argc, char *argv[])
{
    u8 resp[WLANTEST_CTRL_MAX_RESP_LEN];
    u8 buf[100], *end, *pos;
    int rlen, i;
    size_t len;

    if (argc != 3) {
        printf("get_sta_counter needs at three arguments: "
               "counter name, BSSID, and STA address\n");
        return -1;
    }

    pos = buf;
    end = buf + sizeof(buf);
    WPA_PUT_BE32(pos, WLANTEST_CTRL_GET_STA_COUNTER);
    pos += 4;

    for (i = 0; sta_counters[i].name; i++) {
        if (os_strcasecmp(sta_counters[i].name, argv[0]) == 0)
            break;
    }
    if (sta_counters[i].name == NULL) {
        printf("Unknown STA counter '%s'\n", argv[0]);
        printf("Counters:");
        for (i = 0; sta_counters[i].name; i++)
            printf(" %s", sta_counters[i].name);
        printf("\n");
        return -1;
    }

    pos = attr_add_be32(pos, end, WLANTEST_ATTR_STA_COUNTER,
                        sta_counters[i].num);
    pos = attr_hdr_add(pos, end, WLANTEST_ATTR_BSSID, ETH_ALEN);
    if (hwaddr_aton(argv[1], pos) < 0) {
        printf("Invalid BSSID '%s'\n", argv[1]);
        return -1;
    }
    pos += ETH_ALEN;

    pos = attr_hdr_add(pos, end, WLANTEST_ATTR_STA_ADDR, ETH_ALEN);
    if (hwaddr_aton(argv[2], pos) < 0) {
        printf("Invalid STA address '%s'\n", argv[2]);
        return -1;
    }
    pos += ETH_ALEN;

    rlen = cmd_send_and_recv(s, buf, pos - buf, resp, sizeof(resp));
    if (rlen < 0)
        return -1;

    pos = attr_get(resp + 4, rlen - 4, WLANTEST_ATTR_COUNTER, &len);
    if (pos == NULL || len != 4)
        return -1;
    printf("%u\n", WPA_GET_BE32(pos));
    return 0;
}
static void
madwifi_wireless_event_wireless_custom(struct madwifi_driver_data *drv,
				       char *custom)
{
	wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);

	if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
		char *pos;
		u8 addr[ETH_ALEN];
		pos = strstr(custom, "addr=");
		if (pos == NULL) {
			wpa_printf(MSG_DEBUG,
				   "MLME-MICHAELMICFAILURE.indication "
				   "without sender address ignored");
			return;
		}
		pos += 5;
		if (hwaddr_aton(pos, addr) == 0) {
			union wpa_event_data data;
			os_memset(&data, 0, sizeof(data));
			data.michael_mic_failure.unicast = 1;
			data.michael_mic_failure.src = addr;
			wpa_supplicant_event(drv->hapd,
					     EVENT_MICHAEL_MIC_FAILURE, &data);
		} else {
			wpa_printf(MSG_DEBUG,
				   "MLME-MICHAELMICFAILURE.indication "
				   "with invalid MAC address");
		}
	} else if (strncmp(custom, "STA-TRAFFIC-STAT", 16) == 0) {
		char *key, *value;
		u32 val;
		key = custom;
		while ((key = strchr(key, '\n')) != NULL) {
			key++;
			value = strchr(key, '=');
			if (value == NULL)
				continue;
			*value++ = '\0';
			val = strtoul(value, NULL, 10);
			if (strcmp(key, "mac") == 0)
				hwaddr_aton(value, drv->acct_mac);
			else if (strcmp(key, "rx_packets") == 0)
				drv->acct_data.rx_packets = val;
			else if (strcmp(key, "tx_packets") == 0)
				drv->acct_data.tx_packets = val;
			else if (strcmp(key, "rx_bytes") == 0)
				drv->acct_data.rx_bytes = val;
			else if (strcmp(key, "tx_bytes") == 0)
				drv->acct_data.tx_bytes = val;
			key = value;
		}
	}
}
Пример #6
0
static void
wext_wireless_event_wireless_custom(struct wext_driver_data *drv,
				       char *custom)
{
	struct hostapd_data *hapd = drv->hapd;

	wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'\n",
		      custom);

	if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
		char *pos;
		u8 addr[ETH_ALEN];
		pos = strstr(custom, "addr=");
		if (pos == NULL) {
			wpa_printf(MSG_DEBUG,
				      "MLME-MICHAELMICFAILURE.indication "
				      "without sender address ignored\n");
			return;
		}
		pos += 5;
		if (hwaddr_aton(pos, addr) == 0) {
			ieee80211_michael_mic_failure(drv->hapd, addr, 1);
		} else {
			wpa_printf(MSG_DEBUG,
				      "MLME-MICHAELMICFAILURE.indication "
				      "with invalid MAC address");
		}
	} else if (strncmp(custom, "STA-TRAFFIC-STAT", 16) == 0) {
		char *key, *value;
		u32 val;
		key = custom;
		while ((key = strchr(key, '\n')) != NULL) {
			key++;
			value = strchr(key, '=');
			if (value == NULL)
				continue;
			*value++ = '\0';
			val = strtoul(value, NULL, 10);
			if (strcmp(key, "mac") == 0)
				hwaddr_aton(value, drv->acct_mac);
			else if (strcmp(key, "rx_packets") == 0)
				drv->acct_data.rx_packets = val;
			else if (strcmp(key, "tx_packets") == 0)
				drv->acct_data.tx_packets = val;
			else if (strcmp(key, "rx_bytes") == 0)
				drv->acct_data.rx_bytes = val;
			else if (strcmp(key, "tx_bytes") == 0)
				drv->acct_data.tx_bytes = val;
			key = value;
		}
	}
}
Пример #7
0
static int cmd_clear_tdls_counters(int s, int argc, char *argv[])
{
    u8 resp[WLANTEST_CTRL_MAX_RESP_LEN];
    u8 buf[100], *pos;
    int rlen;

    if (argc < 3) {
        printf("clear_tdls_counters needs three arguments: BSSID, "
               "STA1 address, STA2 address\n");
        return -1;
    }

    pos = buf;
    WPA_PUT_BE32(pos, WLANTEST_CTRL_CLEAR_TDLS_COUNTERS);
    pos += 4;
    WPA_PUT_BE32(pos, WLANTEST_ATTR_BSSID);
    pos += 4;
    WPA_PUT_BE32(pos, ETH_ALEN);
    pos += 4;
    if (hwaddr_aton(argv[0], pos) < 0) {
        printf("Invalid BSSID '%s'\n", argv[0]);
        return -1;
    }
    pos += ETH_ALEN;

    WPA_PUT_BE32(pos, WLANTEST_ATTR_STA_ADDR);
    pos += 4;
    WPA_PUT_BE32(pos, ETH_ALEN);
    pos += 4;
    if (hwaddr_aton(argv[1], pos) < 0) {
        printf("Invalid STA1 address '%s'\n", argv[1]);
        return -1;
    }
    pos += ETH_ALEN;

    WPA_PUT_BE32(pos, WLANTEST_ATTR_STA2_ADDR);
    pos += 4;
    WPA_PUT_BE32(pos, ETH_ALEN);
    pos += 4;
    if (hwaddr_aton(argv[2], pos) < 0) {
        printf("Invalid STA2 address '%s'\n", argv[2]);
        return -1;
    }
    pos += ETH_ALEN;

    rlen = cmd_send_and_recv(s, buf, pos - buf, resp, sizeof(resp));
    if (rlen < 0)
        return -1;
    printf("OK\n");
    return 0;
}
static int hostapd_ctrl_iface_new_sta(struct hostapd_data *hapd,
				      const char *txtaddr)
{
	u8 addr[ETH_ALEN];
	struct sta_info *sta;

	wpa_printf(MSG_DEBUG, "CTRL_IFACE NEW_STA %s", txtaddr);

	if (hwaddr_aton(txtaddr, addr))
		return -1;

	sta = ap_get_sta(hapd, addr);
	if (sta)
		return 0;

	wpa_printf(MSG_DEBUG, "Add new STA " MACSTR " based on ctrl_iface "
		   "notification", MAC2STR(addr));
	sta = ap_sta_add(hapd, addr);
	if (sta == NULL)
		return -1;

	hostapd_new_assoc_sta(hapd, sta, 0);
	accounting_sta_get_id(hapd, sta);
	return 0;
}
Пример #9
0
static void
hostapd_wireless_event_wireless_custom(struct hostap_driver_data *drv,
				       char *custom)
{
	wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);

	if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
		char *pos;
		u8 addr[ETH_ALEN];
		pos = strstr(custom, "addr=");
		if (pos == NULL) {
			wpa_printf(MSG_DEBUG,
				   "MLME-MICHAELMICFAILURE.indication "
				   "without sender address ignored");
			return;
		}
		pos += 5;
		if (hwaddr_aton(pos, addr) == 0) {
			union wpa_event_data data;
			os_memset(&data, 0, sizeof(data));
			data.michael_mic_failure.unicast = 1;
			data.michael_mic_failure.src = addr;
			wpa_supplicant_event(drv->hapd,
					     EVENT_MICHAEL_MIC_FAILURE, &data);
		} else {
			wpa_printf(MSG_DEBUG,
				   "MLME-MICHAELMICFAILURE.indication "
				   "with invalid MAC address");
		}
	}
}
/**
 * wpas_dbus_iface_wps_pbc - Request credentials using WPS PBC method
 * @message: Pointer to incoming dbus message
 * @wpa_s: %wpa_supplicant data structure
 * Returns: A dbus message containing a UINT32 indicating success (1) or
 *          failure (0)
 *
 * Handler function for "wpsPbc" method call
 */
DBusMessage * wpas_dbus_iface_wps_pbc(DBusMessage *message,
				      struct wpa_supplicant *wpa_s)
{
	char *arg_bssid = NULL;
	u8 bssid[ETH_ALEN];
	int ret = 0;

	if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
				   DBUS_TYPE_INVALID))
		return wpas_dbus_new_invalid_opts_error(message, NULL);

	if (!os_strcmp(arg_bssid, "any"))
		ret = wpas_wps_start_pbc(wpa_s, NULL, 0);
	else if (!hwaddr_aton(arg_bssid, bssid))
		ret = wpas_wps_start_pbc(wpa_s, bssid, 0);
	else {
		return wpas_dbus_new_invalid_opts_error(message,
							"Invalid BSSID");
	}

	if (ret < 0) {
		return dbus_message_new_error(message,
					      WPAS_ERROR_WPS_PBC_ERROR,
					      "Could not start PBC "
					      "negotiation");
	}

	return wpas_dbus_new_success_reply(message);
}
Пример #11
0
static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
					   char *cmd)
{
	char *pos;
	int id;
	struct wpa_ssid *ssid;
	u8 bssid[ETH_ALEN];

	/* cmd: "<network id> <BSSID>" */
	pos = os_strchr(cmd, ' ');
	if (pos == NULL)
		return -1;
	*pos++ = '\0';
	id = atoi(cmd);
	wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
	if (hwaddr_aton(pos, bssid)) {
		wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
		return -1;
	}

	ssid = wpa_config_get_network(wpa_s->conf, id);
	if (ssid == NULL) {
		wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
			   "to update", id);
		return -1;
	}

	os_memcpy(ssid->bssid, bssid, ETH_ALEN);
	ssid->bssid_set =
		os_memcmp(bssid, "\x00\x00\x00\x00\x00\x00", ETH_ALEN) != 0;
		

	return 0;
}
Пример #12
0
static int cmd_clear_bss_counters(int s, int argc, char *argv[])
{
    u8 resp[WLANTEST_CTRL_MAX_RESP_LEN];
    u8 buf[100], *pos;
    int rlen;

    if (argc < 1) {
        printf("clear_bss_counters needs one argument: BSSID\n");
        return -1;
    }

    pos = buf;
    WPA_PUT_BE32(pos, WLANTEST_CTRL_CLEAR_BSS_COUNTERS);
    pos += 4;
    WPA_PUT_BE32(pos, WLANTEST_ATTR_BSSID);
    pos += 4;
    WPA_PUT_BE32(pos, ETH_ALEN);
    pos += 4;
    if (hwaddr_aton(argv[0], pos) < 0) {
        printf("Invalid BSSID '%s'\n", argv[0]);
        return -1;
    }
    pos += ETH_ALEN;

    rlen = cmd_send_and_recv(s, buf, pos - buf, resp, sizeof(resp));
    if (rlen < 0)
        return -1;
    printf("OK\n");
    return 0;
}
Пример #13
0
static void
hostapd_wireless_event_wireless_custom(struct hostap_driver_data *drv,
                                       char *custom)
{
    wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);

    if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
        char *pos;
        u8 addr[ETH_ALEN];
        pos = strstr(custom, "addr=");
        if (pos == NULL) {
            wpa_printf(MSG_DEBUG,
                       "MLME-MICHAELMICFAILURE.indication "
                       "without sender address ignored");
            return;
        }
        pos += 5;
        if (hwaddr_aton(pos, addr) == 0) {
            ieee80211_michael_mic_failure(drv->hapd, addr, 1);
        } else {
            wpa_printf(MSG_DEBUG,
                       "MLME-MICHAELMICFAILURE.indication "
                       "with invalid MAC address");
        }
    }
}
Пример #14
0
static int hostapd_config_read_maclist(const char *fname, macaddr **acl,
				       int *num)
{
	FILE *f;
	char buf[128], *pos;
	int line = 0;
	u8 addr[ETH_ALEN];
	macaddr *newacl;

	if (!fname)
		return 0;

	f = fopen(fname, "r");
	if (!f) {
		printf("MAC list file '%s' not found.\n", fname);
		return -1;
	}

	while (fgets(buf, sizeof(buf), f)) {
		line++;

		if (buf[0] == '#')
			continue;
		pos = buf;
		while (*pos != '\0') {
			if (*pos == '\n') {
				*pos = '\0';
				break;
			}
			pos++;
		}
		if (buf[0] == '\0')
			continue;

		if (hwaddr_aton(buf, addr)) {
			printf("Invalid MAC address '%s' at line %d in '%s'\n",
			       buf, line, fname);
			fclose(f);
			return -1;
		}

		newacl = (macaddr *) realloc(*acl, (*num + 1) * ETH_ALEN);
		if (newacl == NULL) {
			printf("MAC list reallocation failed\n");
			fclose(f);
			return -1;
		}

		*acl = newacl;
		memcpy((*acl)[*num], addr, ETH_ALEN);
		(*num)++;
	}

	fclose(f);

	qsort(*acl, *num, sizeof(macaddr), mac_comp);

	return 0;
}
Пример #15
0
int hostapd_ctrl_iface_disassociate(struct hostapd_data *hapd,
                                    const char *txtaddr)
{
    u8 addr[ETH_ALEN];
    struct sta_info *sta;
    const char *pos;
    u16 reason = WLAN_REASON_PREV_AUTH_NOT_VALID;

    wpa_dbg(hapd->msg_ctx, MSG_DEBUG, "CTRL_IFACE DISASSOCIATE %s",
            txtaddr);

    if (hwaddr_aton(txtaddr, addr))
        return -1;

    pos = os_strstr(txtaddr, " test=");
    if (pos) {
        struct ieee80211_mgmt mgmt;
        int encrypt;
        if (hapd->driver->send_frame == NULL)
            return -1;
        pos += 6;
        encrypt = atoi(pos);
        os_memset(&mgmt, 0, sizeof(mgmt));
        mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
                                          WLAN_FC_STYPE_DISASSOC);
        os_memcpy(mgmt.da, addr, ETH_ALEN);
        os_memcpy(mgmt.sa, hapd->own_addr, ETH_ALEN);
        os_memcpy(mgmt.bssid, hapd->own_addr, ETH_ALEN);
        mgmt.u.disassoc.reason_code =
            host_to_le16(WLAN_REASON_PREV_AUTH_NOT_VALID);
        if (hapd->driver->send_frame(hapd->drv_priv, (u8 *) &mgmt,
                                     IEEE80211_HDRLEN +
                                     sizeof(mgmt.u.deauth),
                                     encrypt) < 0)
            return -1;
        return 0;
    }

#ifdef CONFIG_P2P_MANAGER
    pos = os_strstr(txtaddr, " p2p=");
    if (pos) {
        return p2p_manager_disconnect(hapd, WLAN_FC_STYPE_DISASSOC,
                                      atoi(pos + 5), addr);
    }
#endif /* CONFIG_P2P_MANAGER */

    pos = os_strstr(txtaddr, " reason=");
    if (pos)
        reason = atoi(pos + 8);

    hostapd_drv_sta_disassoc(hapd, addr, reason);
    sta = ap_get_sta(hapd, addr);
    if (sta)
        ap_sta_disassociate(hapd, sta, reason);
    else if (addr[0] == 0xff)
        hostapd_free_stas(hapd);

    return 0;
}
Пример #16
0
size_t
get_duid(unsigned char *duid, const struct interface *ifp)
{
    FILE *f;
    int x = 0;
    size_t len = 0;
    char *line;

    /* If we already have a DUID then use it as it's never supposed
     * to change once we have one even if the interfaces do */
    if ((f = fopen(DUID, "r"))) {
        while ((line = get_line(f))) {
            len = hwaddr_aton(NULL, line);
            if (len && len <= DUID_LEN) {
                hwaddr_aton(duid, line);
                break;
            }
            len = 0;
        }
        fclose(f);
        if (len)
            return len;
    } else {
        if (errno != ENOENT) {
            syslog(LOG_ERR, "error reading DUID: %s: %m", DUID);
            return make_duid(duid, ifp, DUID_LL);
        }
    }

    /* No file? OK, lets make one based on our interface */
    if (!(f = fopen(DUID, "w"))) {
        syslog(LOG_ERR, "error writing DUID: %s: %m", DUID);
        return make_duid(duid, ifp, DUID_LL);
    }
    len = make_duid(duid, ifp, DUID_LLT);
    x = fprintf(f, "%s\n", hwaddr_ntoa(duid, len));
    fclose(f);
    /* Failed to write the duid? scrub it, we cannot use it */
    if (x < 1) {
        syslog(LOG_ERR, "error writing DUID: %s: %m", DUID);
        unlink(DUID);
        return make_duid(duid, ifp, DUID_LL);
    }
    return len;
}
Пример #17
0
static enum http_reply_code
web_process_put_wlan_response(struct upnp_wps_device_sm *sm, char *data,
			      struct wpabuf **reply, const char **replyname)
{
	struct wpabuf *msg;
	enum http_reply_code ret;
	u8 macaddr[ETH_ALEN];
	int ev_type;
	int type;
	char *val;

	/*
	 * External UPnP-based Registrar is passing us a message to be proxied
	 * over to a Wi-Fi -based client of ours.
	 */

	wpa_printf(MSG_DEBUG, "WPS UPnP: PutWLANResponse");
	msg = xml_get_base64_item(data, "NewMessage", &ret);
	if (msg == NULL)
		return ret;
	val = xml_get_first_item(data, "NewWLANEventType");
	if (val == NULL) {
		wpabuf_free(msg);
		return UPNP_ARG_VALUE_INVALID;
	}
	ev_type = atol(val);
	os_free(val);
	val = xml_get_first_item(data, "NewWLANEventMAC");
	if (val == NULL || hwaddr_aton(val, macaddr)) {
		wpabuf_free(msg);
		os_free(val);
		return UPNP_ARG_VALUE_INVALID;
	}
	os_free(val);
	if (ev_type == UPNP_WPS_WLANEVENT_TYPE_EAP) {
		struct wps_parse_attr attr;
		if (wps_parse_msg(msg, &attr) < 0 ||
		    attr.msg_type == NULL)
			type = -1;
		else
			type = *attr.msg_type;
		wpa_printf(MSG_DEBUG, "WPS UPnP: Message Type %d", type);
	} else
		type = -1;
	if (!sm->ctx->rx_req_put_wlan_response ||
	    sm->ctx->rx_req_put_wlan_response(sm->priv, ev_type, macaddr, msg,
					      type)) {
		wpa_printf(MSG_INFO, "WPS UPnP: Fail: sm->ctx->"
			   "rx_req_put_wlan_response");
		wpabuf_free(msg);
		return HTTP_INTERNAL_SERVER_ERROR;
	}
	wpabuf_free(msg);
	*replyname = NULL;
	*reply = NULL;
	return HTTP_OK;
}
Пример #18
0
static int cmd_get_rx_tid(int s, int argc, char *argv[])
{
    u8 resp[WLANTEST_CTRL_MAX_RESP_LEN];
    u8 buf[100], *end, *pos;
    int rlen;
    size_t len;

    if (argc != 3) {
        printf("get_tx_tid needs three arguments: "
               "BSSID, STA address, and TID\n");
        return -1;
    }

    pos = buf;
    end = buf + sizeof(buf);
    WPA_PUT_BE32(pos, WLANTEST_CTRL_GET_RX_TID);
    pos += 4;

    pos = attr_hdr_add(pos, end, WLANTEST_ATTR_BSSID, ETH_ALEN);
    if (hwaddr_aton(argv[0], pos) < 0) {
        printf("Invalid BSSID '%s'\n", argv[0]);
        return -1;
    }
    pos += ETH_ALEN;

    pos = attr_hdr_add(pos, end, WLANTEST_ATTR_STA_ADDR, ETH_ALEN);
    if (hwaddr_aton(argv[1], pos) < 0) {
        printf("Invalid STA address '%s'\n", argv[1]);
        return -1;
    }
    pos += ETH_ALEN;

    pos = attr_add_be32(pos, end, WLANTEST_ATTR_TID, atoi(argv[2]));

    rlen = cmd_send_and_recv(s, buf, pos - buf, resp, sizeof(resp));
    if (rlen < 0)
        return -1;

    pos = attr_get(resp + 4, rlen - 4, WLANTEST_ATTR_COUNTER, &len);
    if (pos == NULL || len != 4)
        return -1;
    printf("%u\n", WPA_GET_BE32(pos));
    return 0;
}
Пример #19
0
void cli_txt_list_del_addr(struct dl_list *txt_list, const char *txt)
{
	u8 addr[ETH_ALEN];
	char buf[18];

	if (hwaddr_aton(txt, addr) < 0)
		return;
	os_snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
	cli_txt_list_del(txt_list, buf);
}
Пример #20
0
static int cmd_info_bss(int s, int argc, char *argv[])
{
    u8 resp[WLANTEST_CTRL_MAX_RESP_LEN];
    u8 buf[100], *end, *pos;
    int rlen, i;
    size_t len;
    char info[100];

    if (argc != 2) {
        printf("bss_info needs at two arguments: "
               "field name and BSSID\n");
        return -1;
    }

    pos = buf;
    end = buf + sizeof(buf);
    WPA_PUT_BE32(pos, WLANTEST_CTRL_INFO_BSS);
    pos += 4;

    for (i = 0; bss_infos[i].name; i++) {
        if (os_strcasecmp(bss_infos[i].name, argv[0]) == 0)
            break;
    }
    if (bss_infos[i].name == NULL) {
        printf("Unknown BSS info '%s'\n", argv[0]);
        printf("Info fields:");
        for (i = 0; bss_infos[i].name; i++)
            printf(" %s", bss_infos[i].name);
        printf("\n");
        return -1;
    }

    pos = attr_add_be32(pos, end, WLANTEST_ATTR_BSS_INFO,
                        bss_infos[i].num);
    pos = attr_hdr_add(pos, end, WLANTEST_ATTR_BSSID, ETH_ALEN);
    if (hwaddr_aton(argv[1], pos) < 0) {
        printf("Invalid BSSID '%s'\n", argv[1]);
        return -1;
    }
    pos += ETH_ALEN;

    rlen = cmd_send_and_recv(s, buf, pos - buf, resp, sizeof(resp));
    if (rlen < 0)
        return -1;

    pos = attr_get(resp + 4, rlen - 4, WLANTEST_ATTR_INFO, &len);
    if (pos == NULL)
        return -1;
    if (len >= sizeof(info))
        len = sizeof(info) - 1;
    os_memcpy(info, pos, len);
    info[len] = '\0';
    printf("%s\n", info);
    return 0;
}
Пример #21
0
static int hostapd_ctrl_iface_sta(struct hostapd_data *hapd,
				  const char *txtaddr,
				  char *buf, size_t buflen)
{
	u8 addr[ETH_ALEN];

	if (hwaddr_aton(txtaddr, addr))
		return snprintf(buf, buflen, "FAIL\n");
	return hostapd_ctrl_iface_sta_mib(hapd, ap_get_sta(hapd, addr),
					  buf, buflen);
}
Пример #22
0
static int wpa_config_parse_bssid(struct parse_data *data, int line,
				  const char *value)
{
	if (hwaddr_aton(value, data->ssid->bssid)) {
		wpa_printf(MSG_ERROR, "Line %d: Invalid BSSID '%s'.",
			   line, value);
		return -1;
	}
	data->ssid->bssid_set = 1;
	wpa_hexdump(MSG_MSGDUMP, "BSSID", data->ssid->bssid, ETH_ALEN);
	return 0;
}
Пример #23
0
static int wpa_supplicant_ctrl_iface_blacklist(
		struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
{
	struct wpa_ssid *ssid;
	u8 bssid[ETH_ALEN];
	struct wpa_blacklist *e;
	char *pos, *end;
	int ret;

	/* cmd: "BLACKLIST [<BSSID>]" */
	if (*cmd == '\0') {
		pos = buf;
		end = buf + buflen;

		e = wpa_s->blacklist;
		while (e) {
			ret = os_snprintf(pos, end-pos,
					  "%02x:%02x:%02x:%02x:%02x:%02x\n",
					  e->bssid[0],
					  e->bssid[1],
					  e->bssid[2],
					  e->bssid[3],
					  e->bssid[4],
					  e->bssid[5]);
			if (ret < 0 || ret >= end - pos)
				return pos - buf;
			pos += ret;
			e = e->next;
		}
		return pos - buf;
	}
	wpa_printf(MSG_DEBUG, "CTRL_IFACE: bssid='%s'", cmd);

	++cmd;
	if (os_strncmp(cmd, "clear", 5) == 0) {
		wpa_blacklist_clear(wpa_s);
		return 0;
	}

	if (hwaddr_aton(cmd, bssid)) {
		wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", cmd);
		return -1;
	}

	/*
	 * Add the BSSID twice, so its count will be 2, causing it to be
	 * skipped when processing scan results.
	 */
	ret = wpa_blacklist_add(wpa_s, bssid);
	if (ret != 0)
		return ret;
	return wpa_blacklist_add(wpa_s, bssid);
}
Пример #24
0
static int hostapd_ctrl_iface_sta_next(struct hostapd_data *hapd,
				       const char *txtaddr,
				       char *buf, size_t buflen)
{
	u8 addr[ETH_ALEN];
	struct sta_info *sta;

	if (hwaddr_aton(txtaddr, addr) ||
	    (sta = ap_get_sta(hapd, addr)) == NULL)
		return snprintf(buf, buflen, "FAIL\n");
	return hostapd_ctrl_iface_sta_mib(hapd, sta->next, buf, buflen);
}
/**
 * wpas_dbus_iface_wps_pin - Establish the PIN number of the enrollee
 * @message: Pointer to incoming dbus message
 * @wpa_s: %wpa_supplicant data structure
 * Returns: A dbus message containing a UINT32 indicating success (1) or
 *          failure (0)
 *
 * Handler function for "wpsPin" method call
 */
DBusMessage * wpas_dbus_iface_wps_pin(DBusMessage *message,
				      struct wpa_supplicant *wpa_s)
{
	DBusMessage *reply = NULL;
	char *arg_bssid;
	char *pin = NULL;
	u8 bssid[ETH_ALEN], *_bssid = NULL;
	int ret = 0;

	if (!dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg_bssid,
				   DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID))
		return wpas_dbus_new_invalid_opts_error(message, NULL);

	if (!os_strcmp(arg_bssid, "any"))
		_bssid = NULL;
	else if (!hwaddr_aton(arg_bssid, bssid))
		_bssid = bssid;
	else {
		return wpas_dbus_new_invalid_opts_error(message,
							"Invalid BSSID");
	}

	if (os_strlen(pin) > 0)
		ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
					 DEV_PW_DEFAULT);
	else
		ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0,
					 DEV_PW_DEFAULT);

	if (ret < 0) {
		return dbus_message_new_error(message,
					      WPAS_ERROR_WPS_PIN_ERROR,
					      "Could not init PIN");
	}

	reply = dbus_message_new_method_return(message);
	if (reply == NULL)
		return NULL;

	if (ret == 0) {
		dbus_message_append_args(reply, DBUS_TYPE_STRING, &pin,
					 DBUS_TYPE_INVALID);
	} else {
		char npin[9];
		os_snprintf(npin, sizeof(npin), "%08d", ret);
		dbus_message_append_args(reply, DBUS_TYPE_STRING, &npin,
					 DBUS_TYPE_INVALID);
	}
	return reply;
}
Пример #26
0
static int wpa_supplicant_ctrl_iface_ft_ds(
	struct wpa_supplicant *wpa_s, char *addr)
{
	u8 target_ap[ETH_ALEN];

	if (hwaddr_aton(addr, target_ap)) {
		wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
			   "address '%s'", target_ap);
		return -1;
	}

	wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));

	return wpa_ft_start_over_ds(wpa_s->wpa, target_ap);
}
Пример #27
0
int hostapd_ctrl_iface_sta(struct hostapd_data *hapd, const char *txtaddr,
			   char *buf, size_t buflen)
{
	u8 addr[ETH_ALEN];
	int ret;

	if (hwaddr_aton(txtaddr, addr)) {
		ret = os_snprintf(buf, buflen, "FAIL\n");
		if (ret < 0 || (size_t) ret >= buflen)
			return 0;
		return ret;
	}
	return hostapd_ctrl_iface_sta_mib(hapd, ap_get_sta(hapd, addr),
					  buf, buflen);
}
Пример #28
0
/* MLME-STKSTART.request(peer) */
static int wpa_supplicant_ctrl_iface_stkstart(
	struct wpa_supplicant *wpa_s, char *addr)
{
	u8 peer[ETH_ALEN];

	if (hwaddr_aton(addr, peer)) {
		wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
			   "address '%s'", peer);
		return -1;
	}

	wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
		   MAC2STR(peer));

	return wpa_sm_stkstart(wpa_s->wpa, peer);
}
Пример #29
0
static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
					     char *cmd)
{
	u8 bssid[ETH_ALEN];

	if (cmd == NULL || os_strcmp(cmd, "any") == 0)
		return wpas_wps_start_pbc(wpa_s, NULL);

	if (hwaddr_aton(cmd, bssid)) {
		wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
			   cmd);
		return -1;
	}

	return wpas_wps_start_pbc(wpa_s, bssid);
}
static int hostapd_ctrl_iface_sa_query(struct hostapd_data *hapd,
				       const char *txtaddr)
{
	u8 addr[ETH_ALEN];
	u8 trans_id[WLAN_SA_QUERY_TR_ID_LEN];

	wpa_printf(MSG_DEBUG, "CTRL_IFACE SA_QUERY %s", txtaddr);

	if (hwaddr_aton(txtaddr, addr))
		return -1;

	os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN);
	ieee802_11_send_sa_query_req(hapd, addr, trans_id);

	return 0;
}