static void ctrl_version(struct wlantest *wt, int sock) { u8 buf[WLANTEST_CTRL_MAX_RESP_LEN], *pos; pos = buf; WPA_PUT_BE32(pos, WLANTEST_CTRL_SUCCESS); pos += 4; pos = attr_add_str(pos, buf + sizeof(buf), WLANTEST_ATTR_VERSION, VERSION_STR); ctrl_send(wt, sock, buf, pos - buf); }
static void ctrl_info_sta(struct wlantest *wt, int sock, u8 *cmd, size_t clen) { u8 *addr; size_t addr_len; struct wlantest_bss *bss; struct wlantest_sta *sta; enum wlantest_sta_info info; u8 buf[4 + 108], *end, *pos; char resp[100]; bss = ctrl_get_bss(wt, sock, cmd, clen); sta = ctrl_get_sta(wt, sock, cmd, clen, bss); if (sta == NULL) return; addr = attr_get(cmd, clen, WLANTEST_ATTR_STA_INFO, &addr_len); if (addr == NULL || addr_len != 4) { ctrl_send_simple(wt, sock, WLANTEST_CTRL_INVALID_CMD); return; } info = WPA_GET_BE32(addr); resp[0] = '\0'; switch (info) { case WLANTEST_STA_INFO_PROTO: info_print_proto(resp, sizeof(resp), sta->proto); break; case WLANTEST_STA_INFO_PAIRWISE: info_print_cipher(resp, sizeof(resp), sta->pairwise_cipher); break; case WLANTEST_STA_INFO_KEY_MGMT: info_print_key_mgmt(resp, sizeof(resp), sta->key_mgmt); break; case WLANTEST_STA_INFO_RSN_CAPAB: info_print_rsn_capab(resp, sizeof(resp), sta->rsn_capab); break; case WLANTEST_STA_INFO_STATE: info_print_state(resp, sizeof(resp), sta->state); break; case WLANTEST_STA_INFO_GTK: info_print_gtk(resp, sizeof(resp), sta); break; default: ctrl_send_simple(wt, sock, WLANTEST_CTRL_INVALID_CMD); return; } pos = buf; end = buf + sizeof(buf); WPA_PUT_BE32(pos, WLANTEST_CTRL_SUCCESS); pos += 4; pos = attr_add_str(pos, end, WLANTEST_ATTR_INFO, resp); ctrl_send(wt, sock, buf, pos - buf); }
static int cmd_add_wepkey(int s, int argc, char *argv[]) { u8 resp[WLANTEST_CTRL_MAX_RESP_LEN]; u8 buf[100], *pos, *end; int rlen; if (argc < 1) { printf("add_wepkey needs one argument: WEP key\n"); return -1; } pos = buf; end = buf + sizeof(buf); WPA_PUT_BE32(pos, WLANTEST_CTRL_ADD_PASSPHRASE); pos += 4; pos = attr_add_str(pos, end, WLANTEST_ATTR_WEPKEY, argv[0]); rlen = cmd_send_and_recv(s, buf, pos - buf, resp, sizeof(resp)); if (rlen < 0) return -1; return 0; }
static int cmd_add_passphrase(int s, int argc, char *argv[]) { u8 resp[WLANTEST_CTRL_MAX_RESP_LEN]; u8 buf[100], *pos, *end; size_t len; int rlen; if (argc < 1) { printf("add_passphrase needs one argument: passphrase\n"); return -1; } len = os_strlen(argv[0]); if (len < 8 || len > 63) { printf("Invalid passphrase '%s'\n", argv[0]); return -1; } pos = buf; end = buf + sizeof(buf); WPA_PUT_BE32(pos, WLANTEST_CTRL_ADD_PASSPHRASE); pos += 4; pos = attr_add_str(pos, end, WLANTEST_ATTR_PASSPHRASE, argv[0]); if (argc > 1) { pos = attr_hdr_add(pos, end, WLANTEST_ATTR_BSSID, ETH_ALEN); if (hwaddr_aton(argv[1], pos) < 0) { printf("Invalid BSSID '%s'\n", argv[3]); return -1; } pos += ETH_ALEN; } rlen = cmd_send_and_recv(s, buf, pos - buf, resp, sizeof(resp)); if (rlen < 0) return -1; return 0; }